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
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/CMakeLists.txt8
-rw-r--r--source/blender/CMakeLists.txt8
-rw-r--r--source/blender/alembic/CMakeLists.txt2
-rw-r--r--source/blender/alembic/intern/abc_camera.cc5
-rw-r--r--source/blender/alembic/intern/abc_camera.h3
-rw-r--r--source/blender/alembic/intern/abc_curves.cc5
-rw-r--r--source/blender/alembic/intern/abc_curves.h3
-rw-r--r--source/blender/alembic/intern/abc_exporter.cc138
-rw-r--r--source/blender/alembic/intern/abc_exporter.h24
-rw-r--r--source/blender/alembic/intern/abc_hair.cc11
-rw-r--r--source/blender/alembic/intern/abc_hair.h3
-rw-r--r--source/blender/alembic/intern/abc_mball.cc12
-rw-r--r--source/blender/alembic/intern/abc_mball.h1
-rw-r--r--source/blender/alembic/intern/abc_mesh.cc14
-rw-r--r--source/blender/alembic/intern/abc_mesh.h3
-rw-r--r--source/blender/alembic/intern/abc_nurbs.cc5
-rw-r--r--source/blender/alembic/intern/abc_nurbs.h3
-rw-r--r--source/blender/alembic/intern/abc_object.cc5
-rw-r--r--source/blender/alembic/intern/abc_object.h4
-rw-r--r--source/blender/alembic/intern/abc_points.cc6
-rw-r--r--source/blender/alembic/intern/abc_points.h3
-rw-r--r--source/blender/alembic/intern/abc_transform.cc5
-rw-r--r--source/blender/alembic/intern/abc_transform.h4
-rw-r--r--source/blender/alembic/intern/abc_util.cc36
-rw-r--r--source/blender/alembic/intern/abc_util.h4
-rw-r--r--source/blender/alembic/intern/alembic_capi.cc62
-rw-r--r--source/blender/blenfont/BLF_api.h41
-rw-r--r--source/blender/blenfont/intern/blf.c259
-rw-r--r--source/blender/blenfont/intern/blf_font.c260
-rw-r--r--source/blender/blenfont/intern/blf_glyph.c244
-rw-r--r--source/blender/blenfont/intern/blf_internal.h8
-rw-r--r--source/blender/blenfont/intern/blf_internal_types.h47
-rw-r--r--source/blender/blenkernel/BKE_DerivedMesh.h206
-rw-r--r--source/blender/blenkernel/BKE_action.h4
-rw-r--r--source/blender/blenkernel/BKE_anim.h11
-rw-r--r--source/blender/blenkernel/BKE_animsys.h14
-rw-r--r--source/blender/blenkernel/BKE_appdir.h1
-rw-r--r--source/blender/blenkernel/BKE_armature.h118
-rw-r--r--source/blender/blenkernel/BKE_blender_version.h4
-rw-r--r--source/blender/blenkernel/BKE_blendfile.h4
-rw-r--r--source/blender/blenkernel/BKE_bullet.h44
-rw-r--r--source/blender/blenkernel/BKE_cachefile.h2
-rw-r--r--source/blender/blenkernel/BKE_camera.h17
-rw-r--r--source/blender/blenkernel/BKE_cdderivedmesh.h4
-rw-r--r--source/blender/blenkernel/BKE_cloth.h6
-rw-r--r--source/blender/blenkernel/BKE_collection.h115
-rw-r--r--source/blender/blenkernel/BKE_collision.h2
-rw-r--r--source/blender/blenkernel/BKE_constraint.h12
-rw-r--r--source/blender/blenkernel/BKE_context.h32
-rw-r--r--source/blender/blenkernel/BKE_crazyspace.h9
-rw-r--r--source/blender/blenkernel/BKE_curve.h23
-rw-r--r--source/blender/blenkernel/BKE_customdata.h11
-rw-r--r--source/blender/blenkernel/BKE_data_transfer.h8
-rw-r--r--source/blender/blenkernel/BKE_depsgraph.h181
-rw-r--r--source/blender/blenkernel/BKE_displist.h31
-rw-r--r--source/blender/blenkernel/BKE_dynamicpaint.h7
-rw-r--r--source/blender/blenkernel/BKE_editmesh.h5
-rw-r--r--source/blender/blenkernel/BKE_editmesh_tangent.h40
-rw-r--r--source/blender/blenkernel/BKE_effect.h8
-rw-r--r--source/blender/blenkernel/BKE_fluidsim.h3
-rw-r--r--source/blender/blenkernel/BKE_freestyle.h2
-rw-r--r--source/blender/blenkernel/BKE_global.h16
-rw-r--r--source/blender/blenkernel/BKE_group.h36
-rw-r--r--source/blender/blenkernel/BKE_icons.h40
-rw-r--r--source/blender/blenkernel/BKE_idprop.h11
-rw-r--r--source/blender/blenkernel/BKE_lamp.h2
-rw-r--r--source/blender/blenkernel/BKE_lattice.h29
-rw-r--r--source/blender/blenkernel/BKE_layer.h420
-rw-r--r--source/blender/blenkernel/BKE_library.h10
-rw-r--r--source/blender/blenkernel/BKE_library_override.h87
-rw-r--r--source/blender/blenkernel/BKE_library_query.h3
-rw-r--r--source/blender/blenkernel/BKE_library_remap.h2
-rw-r--r--source/blender/blenkernel/BKE_lightprobe.h46
-rw-r--r--source/blender/blenkernel/BKE_linestyle.h3
-rw-r--r--source/blender/blenkernel/BKE_main.h7
-rw-r--r--source/blender/blenkernel/BKE_mask.h7
-rw-r--r--source/blender/blenkernel/BKE_material.h17
-rw-r--r--source/blender/blenkernel/BKE_mball.h12
-rw-r--r--source/blender/blenkernel/BKE_mball_tessellate.h4
-rw-r--r--source/blender/blenkernel/BKE_mesh.h63
-rw-r--r--source/blender/blenkernel/BKE_mesh_tangent.h61
-rw-r--r--source/blender/blenkernel/BKE_modifier.h213
-rw-r--r--source/blender/blenkernel/BKE_movieclip.h4
-rw-r--r--source/blender/blenkernel/BKE_multires.h13
-rw-r--r--source/blender/blenkernel/BKE_navmesh_conversion.h67
-rw-r--r--source/blender/blenkernel/BKE_node.h51
-rw-r--r--source/blender/blenkernel/BKE_object.h117
-rw-r--r--source/blender/blenkernel/BKE_object_facemap.h53
-rw-r--r--source/blender/blenkernel/BKE_outliner_treehash.h3
-rw-r--r--source/blender/blenkernel/BKE_paint.h13
-rw-r--r--source/blender/blenkernel/BKE_particle.h70
-rw-r--r--source/blender/blenkernel/BKE_pbvh.h11
-rw-r--r--source/blender/blenkernel/BKE_pointcache.h6
-rw-r--r--source/blender/blenkernel/BKE_property.h53
-rw-r--r--source/blender/blenkernel/BKE_rigidbody.h13
-rw-r--r--source/blender/blenkernel/BKE_sca.h92
-rw-r--r--source/blender/blenkernel/BKE_scene.h98
-rw-r--r--source/blender/blenkernel/BKE_screen.h57
-rw-r--r--source/blender/blenkernel/BKE_sequencer.h16
-rw-r--r--source/blender/blenkernel/BKE_sketch.h149
-rw-r--r--source/blender/blenkernel/BKE_smoke.h4
-rw-r--r--source/blender/blenkernel/BKE_softbody.h4
-rw-r--r--source/blender/blenkernel/BKE_sound.h8
-rw-r--r--source/blender/blenkernel/BKE_texture.h26
-rw-r--r--source/blender/blenkernel/BKE_workspace.h123
-rw-r--r--source/blender/blenkernel/BKE_world.h9
-rw-r--r--source/blender/blenkernel/CMakeLists.txt53
-rw-r--r--source/blender/blenkernel/depsgraph_private.h169
-rw-r--r--source/blender/blenkernel/intern/CCGSubSurf.c2
-rw-r--r--source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c9
-rw-r--r--source/blender/blenkernel/intern/DerivedMesh.c1301
-rw-r--r--source/blender/blenkernel/intern/action.c62
-rw-r--r--source/blender/blenkernel/intern/anim.c138
-rw-r--r--source/blender/blenkernel/intern/anim_sys.c276
-rw-r--r--source/blender/blenkernel/intern/armature.c71
-rw-r--r--source/blender/blenkernel/intern/armature_update.c77
-rw-r--r--source/blender/blenkernel/intern/blender.c10
-rw-r--r--source/blender/blenkernel/intern/blender_copybuffer.c17
-rw-r--r--source/blender/blenkernel/intern/blender_undo.c5
-rw-r--r--source/blender/blenkernel/intern/blendfile.c113
-rw-r--r--source/blender/blenkernel/intern/boids.c1
-rw-r--r--source/blender/blenkernel/intern/bpath.c8
-rw-r--r--source/blender/blenkernel/intern/bullet.c99
-rw-r--r--source/blender/blenkernel/intern/cachefile.c8
-rw-r--r--source/blender/blenkernel/intern/camera.c97
-rw-r--r--source/blender/blenkernel/intern/cdderivedmesh.c1504
-rw-r--r--source/blender/blenkernel/intern/cloth.c17
-rw-r--r--source/blender/blenkernel/intern/collection.c1014
-rw-r--r--source/blender/blenkernel/intern/collision.c46
-rw-r--r--source/blender/blenkernel/intern/constraint.c200
-rw-r--r--source/blender/blenkernel/intern/context.c159
-rw-r--r--source/blender/blenkernel/intern/crazyspace.c36
-rw-r--r--source/blender/blenkernel/intern/curve.c38
-rw-r--r--source/blender/blenkernel/intern/customdata.c112
-rw-r--r--source/blender/blenkernel/intern/data_transfer.c25
-rw-r--r--source/blender/blenkernel/intern/deform.c3
-rw-r--r--source/blender/blenkernel/intern/depsgraph.c3745
-rw-r--r--source/blender/blenkernel/intern/displist.c126
-rw-r--r--source/blender/blenkernel/intern/dynamicpaint.c275
-rw-r--r--source/blender/blenkernel/intern/editderivedmesh.c1433
-rw-r--r--source/blender/blenkernel/intern/editmesh.c22
-rw-r--r--source/blender/blenkernel/intern/editmesh_bvh.c2
-rw-r--r--source/blender/blenkernel/intern/editmesh_tangent.c431
-rw-r--r--source/blender/blenkernel/intern/effect.c91
-rw-r--r--source/blender/blenkernel/intern/fluidsim.c4
-rw-r--r--source/blender/blenkernel/intern/font.c4
-rw-r--r--source/blender/blenkernel/intern/freestyle.c10
-rw-r--r--source/blender/blenkernel/intern/group.c173
-rw-r--r--source/blender/blenkernel/intern/icons.c193
-rw-r--r--source/blender/blenkernel/intern/icons_rasterize.c146
-rw-r--r--source/blender/blenkernel/intern/idcode.c9
-rw-r--r--source/blender/blenkernel/intern/idprop.c46
-rw-r--r--source/blender/blenkernel/intern/image.c24
-rw-r--r--source/blender/blenkernel/intern/ipo.c32
-rw-r--r--source/blender/blenkernel/intern/lamp.c95
-rw-r--r--source/blender/blenkernel/intern/lattice.c65
-rw-r--r--source/blender/blenkernel/intern/layer.c2411
-rw-r--r--source/blender/blenkernel/intern/layer_utils.c125
-rw-r--r--source/blender/blenkernel/intern/library.c164
-rw-r--r--source/blender/blenkernel/intern/library_override.c771
-rw-r--r--source/blender/blenkernel/intern/library_query.c225
-rw-r--r--source/blender/blenkernel/intern/library_remap.c125
-rw-r--r--source/blender/blenkernel/intern/lightprobe.c101
-rw-r--r--source/blender/blenkernel/intern/linestyle.c15
-rw-r--r--source/blender/blenkernel/intern/mask.c18
-rw-r--r--source/blender/blenkernel/intern/mask_evaluate.c17
-rw-r--r--source/blender/blenkernel/intern/material.c1114
-rw-r--r--source/blender/blenkernel/intern/mball.c64
-rw-r--r--source/blender/blenkernel/intern/mball_tessellate.c21
-rw-r--r--source/blender/blenkernel/intern/mesh.c332
-rw-r--r--source/blender/blenkernel/intern/mesh_evaluate.c205
-rw-r--r--source/blender/blenkernel/intern/mesh_merge.c684
-rw-r--r--source/blender/blenkernel/intern/mesh_tangent.c691
-rw-r--r--source/blender/blenkernel/intern/mesh_validate.c84
-rw-r--r--source/blender/blenkernel/intern/modifier.c354
-rw-r--r--source/blender/blenkernel/intern/movieclip.c4
-rw-r--r--source/blender/blenkernel/intern/multires.c42
-rw-r--r--source/blender/blenkernel/intern/navmesh_conversion.c502
-rw-r--r--source/blender/blenkernel/intern/nla.c2
-rw-r--r--source/blender/blenkernel/intern/node.c181
-rw-r--r--source/blender/blenkernel/intern/object.c585
-rw-r--r--source/blender/blenkernel/intern/object_deform.c3
-rw-r--r--source/blender/blenkernel/intern/object_dupli.c213
-rw-r--r--source/blender/blenkernel/intern/object_facemap.c257
-rw-r--r--source/blender/blenkernel/intern/object_update.c259
-rw-r--r--source/blender/blenkernel/intern/outliner_treehash.c39
-rw-r--r--source/blender/blenkernel/intern/paint.c63
-rw-r--r--source/blender/blenkernel/intern/particle.c391
-rw-r--r--source/blender/blenkernel/intern/particle_child.c42
-rw-r--r--source/blender/blenkernel/intern/particle_distribute.c296
-rw-r--r--source/blender/blenkernel/intern/particle_system.c129
-rw-r--r--source/blender/blenkernel/intern/pbvh.c126
-rw-r--r--source/blender/blenkernel/intern/pointcache.c60
-rw-r--r--source/blender/blenkernel/intern/property.c267
-rw-r--r--source/blender/blenkernel/intern/rigidbody.c193
-rw-r--r--source/blender/blenkernel/intern/sca.c1179
-rw-r--r--source/blender/blenkernel/intern/scene.c1459
-rw-r--r--source/blender/blenkernel/intern/screen.c324
-rw-r--r--source/blender/blenkernel/intern/sequencer.c48
-rw-r--r--source/blender/blenkernel/intern/sketch.c555
-rw-r--r--source/blender/blenkernel/intern/smoke.c41
-rw-r--r--source/blender/blenkernel/intern/softbody.c132
-rw-r--r--source/blender/blenkernel/intern/sound.c168
-rw-r--r--source/blender/blenkernel/intern/subsurf_ccg.c2241
-rw-r--r--source/blender/blenkernel/intern/text.c3
-rw-r--r--source/blender/blenkernel/intern/texture.c439
-rw-r--r--source/blender/blenkernel/intern/tracking.c3
-rw-r--r--source/blender/blenkernel/intern/undo_system.c8
-rw-r--r--source/blender/blenkernel/intern/workspace.c470
-rw-r--r--source/blender/blenkernel/intern/world.c47
-rw-r--r--source/blender/blenkernel/intern/writeffmpeg.c15
-rw-r--r--source/blender/blenlib/BLI_callbacks.h4
-rw-r--r--source/blender/blenlib/BLI_graph.h185
-rw-r--r--source/blender/blenlib/BLI_iterator.h62
-rw-r--r--source/blender/blenlib/BLI_link_utils.h12
-rw-r--r--source/blender/blenlib/BLI_math_matrix.h255
-rw-r--r--source/blender/blenlib/BLI_math_vector.h2
-rw-r--r--source/blender/blenlib/BLI_memiter.h73
-rw-r--r--source/blender/blenlib/CMakeLists.txt5
-rw-r--r--source/blender/blenlib/intern/BLI_memiter.c357
-rw-r--r--source/blender/blenlib/intern/graph.c1016
-rw-r--r--source/blender/blenlib/intern/math_color.c191
-rw-r--r--source/blender/blenlib/intern/math_matrix.c347
-rw-r--r--source/blender/blenlib/intern/math_vector_inline.c2
-rw-r--r--source/blender/blenlib/intern/rand.c6
-rw-r--r--source/blender/blenlib/intern/scanfill_utils.c14
-rw-r--r--source/blender/blenloader/BLO_readfile.h25
-rw-r--r--source/blender/blenloader/CMakeLists.txt6
-rw-r--r--source/blender/blenloader/intern/readblenentry.c2
-rw-r--r--source/blender/blenloader/intern/readfile.c2639
-rw-r--r--source/blender/blenloader/intern/readfile.h4
-rw-r--r--source/blender/blenloader/intern/versioning_250.c560
-rw-r--r--source/blender/blenloader/intern/versioning_260.c231
-rw-r--r--source/blender/blenloader/intern/versioning_270.c88
-rw-r--r--source/blender/blenloader/intern/versioning_280.c1103
-rw-r--r--source/blender/blenloader/intern/versioning_defaults.c58
-rw-r--r--source/blender/blenloader/intern/versioning_legacy.c1002
-rw-r--r--source/blender/blenloader/intern/writefile.c999
-rw-r--r--source/blender/blentranslation/BLT_translation.h4
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh.c70
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh.h1
-rw-r--r--source/blender/bmesh/intern/bmesh_mesh_conv.c45
-rw-r--r--source/blender/bmesh/intern/bmesh_operators.h2
-rw-r--r--source/blender/bmesh/operators/bmo_similar.c64
-rw-r--r--source/blender/bmesh/tools/bmesh_intersect.c21
-rw-r--r--source/blender/collada/AnimationExporter.cpp25
-rw-r--r--source/blender/collada/AnimationExporter.h7
-rw-r--r--source/blender/collada/AnimationImporter.cpp6
-rw-r--r--source/blender/collada/ArmatureExporter.cpp19
-rw-r--r--source/blender/collada/ArmatureExporter.h4
-rw-r--r--source/blender/collada/ArmatureImporter.cpp14
-rw-r--r--source/blender/collada/ArmatureImporter.h3
-rw-r--r--source/blender/collada/CMakeLists.txt1
-rw-r--r--source/blender/collada/ControllerExporter.cpp16
-rw-r--r--source/blender/collada/ControllerExporter.h4
-rw-r--r--source/blender/collada/DocumentExporter.cpp24
-rw-r--r--source/blender/collada/DocumentExporter.h8
-rw-r--r--source/blender/collada/DocumentImporter.cpp195
-rw-r--r--source/blender/collada/DocumentImporter.h2
-rw-r--r--source/blender/collada/EffectExporter.cpp232
-rw-r--r--source/blender/collada/EffectExporter.h6
-rw-r--r--source/blender/collada/ExportSettings.h6
-rw-r--r--source/blender/collada/GeometryExporter.cpp312
-rw-r--r--source/blender/collada/GeometryExporter.h39
-rw-r--r--source/blender/collada/ImageExporter.cpp94
-rw-r--r--source/blender/collada/ImageExporter.h1
-rw-r--r--source/blender/collada/InstanceWriter.cpp58
-rw-r--r--source/blender/collada/InstanceWriter.h3
-rw-r--r--source/blender/collada/LightExporter.cpp26
-rw-r--r--source/blender/collada/MaterialExporter.cpp36
-rw-r--r--source/blender/collada/MeshImporter.cpp108
-rw-r--r--source/blender/collada/MeshImporter.h22
-rw-r--r--source/blender/collada/SceneExporter.cpp33
-rw-r--r--source/blender/collada/SceneExporter.h6
-rw-r--r--source/blender/collada/SkinInfo.cpp8
-rw-r--r--source/blender/collada/SkinInfo.h2
-rw-r--r--source/blender/collada/TransformWriter.cpp7
-rw-r--r--source/blender/collada/TransformWriter.h3
-rw-r--r--source/blender/collada/collada.cpp13
-rw-r--r--source/blender/collada/collada.h8
-rw-r--r--source/blender/collada/collada_internal.cpp8
-rw-r--r--source/blender/collada/collada_internal.h1
-rw-r--r--source/blender/collada/collada_utils.cpp191
-rw-r--r--source/blender/collada/collada_utils.h20
-rw-r--r--source/blender/compositor/CMakeLists.txt1
-rw-r--r--source/blender/compositor/nodes/COM_RenderLayersNode.cpp11
-rw-r--r--source/blender/compositor/operations/COM_RenderLayersProg.cpp12
-rw-r--r--source/blender/depsgraph/CMakeLists.txt11
-rw-r--r--source/blender/depsgraph/DEG_depsgraph.h174
-rw-r--r--source/blender/depsgraph/DEG_depsgraph_build.h37
-rw-r--r--source/blender/depsgraph/DEG_depsgraph_debug.h19
-rw-r--r--source/blender/depsgraph/DEG_depsgraph_query.h137
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder.cc130
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder.h7
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes.cc615
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes.h57
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc136
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc125
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc159
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations.cc509
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations.h23
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_impl.h4
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc2
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc20
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc125
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc131
-rw-r--r--source/blender/depsgraph/intern/builder/deg_builder_transitive.cc2
-rw-r--r--source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc45
-rw-r--r--source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc2
-rw-r--r--source/blender/depsgraph/intern/depsgraph.cc217
-rw-r--r--source/blender/depsgraph/intern/depsgraph.h37
-rw-r--r--source/blender/depsgraph/intern/depsgraph_build.cc134
-rw-r--r--source/blender/depsgraph/intern/depsgraph_debug.cc46
-rw-r--r--source/blender/depsgraph/intern/depsgraph_eval.cc96
-rw-r--r--source/blender/depsgraph/intern/depsgraph_intern.h29
-rw-r--r--source/blender/depsgraph/intern/depsgraph_query.cc111
-rw-r--r--source/blender/depsgraph/intern/depsgraph_query_foreach.cc16
-rw-r--r--source/blender/depsgraph/intern/depsgraph_query_iter.cc282
-rw-r--r--source/blender/depsgraph/intern/depsgraph_tag.cc719
-rw-r--r--source/blender/depsgraph/intern/depsgraph_type_defines.cc70
-rw-r--r--source/blender/depsgraph/intern/depsgraph_types.h61
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval.cc89
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval.h6
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc850
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h109
-rw-r--r--source/blender/depsgraph/intern/eval/deg_eval_flush.cc167
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node.cc7
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_component.cc59
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_component.h12
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_id.cc105
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_id.h14
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_operation.cc2
-rw-r--r--source/blender/depsgraph/intern/nodes/deg_node_time.cc3
-rw-r--r--source/blender/depsgraph/util/deg_util_foreach.h10
-rw-r--r--source/blender/depsgraph/util/deg_util_function.h61
-rw-r--r--source/blender/draw/CMakeLists.txt282
-rw-r--r--source/blender/draw/DRW_engine.h139
-rw-r--r--source/blender/draw/engines/basic/basic_engine.c253
-rw-r--r--source/blender/draw/engines/basic/basic_engine.h32
-rw-r--r--source/blender/draw/engines/clay/clay_engine.c1060
-rw-r--r--source/blender/draw/engines/clay/clay_engine.h36
-rw-r--r--source/blender/draw/engines/clay/shaders/clay_copy.glsl10
-rw-r--r--source/blender/draw/engines/clay/shaders/clay_frag.glsl252
-rw-r--r--source/blender/draw/engines/clay/shaders/clay_fxaa.glsl18
-rw-r--r--source/blender/draw/engines/clay/shaders/clay_particle_strand_frag.glsl144
-rw-r--r--source/blender/draw/engines/clay/shaders/clay_particle_vert.glsl34
-rw-r--r--source/blender/draw/engines/clay/shaders/clay_prepass_frag.glsl44
-rw-r--r--source/blender/draw/engines/clay/shaders/clay_vert.glsl17
-rw-r--r--source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl82
-rw-r--r--source/blender/draw/engines/clay/shaders/ssao_groundtruth.glsl122
-rw-r--r--source/blender/draw/engines/eevee/eevee_bloom.c334
-rw-r--r--source/blender/draw/engines/eevee/eevee_data.c183
-rw-r--r--source/blender/draw/engines/eevee/eevee_depth_of_field.c281
-rw-r--r--source/blender/draw/engines/eevee/eevee_effects.c544
-rw-r--r--source/blender/draw/engines/eevee/eevee_engine.c535
-rw-r--r--source/blender/draw/engines/eevee/eevee_engine.h31
-rw-r--r--source/blender/draw/engines/eevee/eevee_lightprobes.c1844
-rw-r--r--source/blender/draw/engines/eevee/eevee_lights.c1241
-rw-r--r--source/blender/draw/engines/eevee/eevee_lut.h16926
-rw-r--r--source/blender/draw/engines/eevee/eevee_materials.c1593
-rw-r--r--source/blender/draw/engines/eevee/eevee_mist.c139
-rw-r--r--source/blender/draw/engines/eevee/eevee_motion_blur.c214
-rw-r--r--source/blender/draw/engines/eevee/eevee_occlusion.c306
-rw-r--r--source/blender/draw/engines/eevee/eevee_private.h978
-rw-r--r--source/blender/draw/engines/eevee/eevee_render.c563
-rw-r--r--source/blender/draw/engines/eevee/eevee_screen_raytrace.c325
-rw-r--r--source/blender/draw/engines/eevee/eevee_subsurface.c339
-rw-r--r--source/blender/draw/engines/eevee/eevee_temporal_sampling.c386
-rw-r--r--source/blender/draw/engines/eevee/eevee_volumes.c599
-rw-r--r--source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl281
-rw-r--r--source/blender/draw/engines/eevee/shaders/background_vert.glsl20
-rw-r--r--source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl826
-rw-r--r--source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl156
-rw-r--r--source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl46
-rw-r--r--source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl107
-rw-r--r--source/blender/draw/engines/eevee/shaders/btdf_lut_frag.glsl59
-rw-r--r--source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl55
-rw-r--r--source/blender/draw/engines/eevee/shaders/concentric_samples_lib.glsl267
-rw-r--r--source/blender/draw/engines/eevee/shaders/default_frag.glsl19
-rw-r--r--source/blender/draw/engines/eevee/shaders/default_world_frag.glsl9
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl218
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl261
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_dof_geom.glsl55
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl99
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_downsample_cube_frag.glsl30
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_downsample_frag.glsl37
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl77
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl96
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_mist_frag.glsl31
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl65
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl517
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl99
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl111
-rw-r--r--source/blender/draw/engines/eevee/shaders/effect_velocity_resolve_frag.glsl22
-rw-r--r--source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl177
-rw-r--r--source/blender/draw/engines/eevee/shaders/lamps_lib.glsl453
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl15
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl26
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl198
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl87
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl88
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_geom.glsl34
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl11
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl32
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_grid_fill_frag.glsl20
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl259
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl14
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl15
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl40
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl24
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl10
-rw-r--r--source/blender/draw/engines/eevee/shaders/lightprobe_vert.glsl10
-rw-r--r--source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl486
-rw-r--r--source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl43
-rw-r--r--source/blender/draw/engines/eevee/shaders/ltc_lib.glsl322
-rw-r--r--source/blender/draw/engines/eevee/shaders/octahedron_lib.glsl38
-rw-r--r--source/blender/draw/engines/eevee/shaders/prepass_frag.glsl87
-rw-r--r--source/blender/draw/engines/eevee/shaders/prepass_vert.glsl20
-rw-r--r--source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl239
-rw-r--r--source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl208
-rw-r--r--source/blender/draw/engines/eevee/shaders/shadow_frag.glsl4
-rw-r--r--source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl243
-rw-r--r--source/blender/draw/engines/eevee/shaders/shadow_vert.glsl33
-rw-r--r--source/blender/draw/engines/eevee/shaders/ssr_lib.glsl72
-rw-r--r--source/blender/draw/engines/eevee/shaders/update_noise_frag.glsl18
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl63
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl52
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_integration_frag.glsl63
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl150
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_resolve_frag.glsl21
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl75
-rw-r--r--source/blender/draw/engines/eevee/shaders/volumetric_vert.glsl27
-rw-r--r--source/blender/draw/engines/external/external_engine.c234
-rw-r--r--source/blender/draw/engines/external/external_engine.h31
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl3
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl37
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl65
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl10
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_object_overlap_lib.glsl12
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl47
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl30
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl51
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl23
-rw-r--r--source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl9
-rw-r--r--source/blender/draw/engines/workbench/solid_mode.c96
-rw-r--r--source/blender/draw/engines/workbench/workbench_engine.c77
-rw-r--r--source/blender/draw/engines/workbench/workbench_engine.h32
-rw-r--r--source/blender/draw/engines/workbench/workbench_materials.c627
-rw-r--r--source/blender/draw/engines/workbench/workbench_private.h132
-rw-r--r--source/blender/draw/engines/workbench/workbench_studiolight.c138
-rw-r--r--source/blender/draw/intern/DRW_render.h528
-rw-r--r--source/blender/draw/intern/draw_armature.c1636
-rw-r--r--source/blender/draw/intern/draw_cache.c3032
-rw-r--r--source/blender/draw/intern/draw_cache.h175
-rw-r--r--source/blender/draw/intern/draw_cache_impl.h128
-rw-r--r--source/blender/draw/intern/draw_cache_impl_curve.c1118
-rw-r--r--source/blender/draw/intern/draw_cache_impl_displist.c398
-rw-r--r--source/blender/draw/intern/draw_cache_impl_lattice.c587
-rw-r--r--source/blender/draw/intern/draw_cache_impl_mesh.c4022
-rw-r--r--source/blender/draw/intern/draw_cache_impl_metaball.c144
-rw-r--r--source/blender/draw/intern/draw_cache_impl_particles.c554
-rw-r--r--source/blender/draw/intern/draw_common.c719
-rw-r--r--source/blender/draw/intern/draw_common.h150
-rw-r--r--source/blender/draw/intern/draw_instance_data.c469
-rw-r--r--source/blender/draw/intern/draw_instance_data.h60
-rw-r--r--source/blender/draw/intern/draw_manager.c2157
-rw-r--r--source/blender/draw/intern/draw_manager.h364
-rw-r--r--source/blender/draw/intern/draw_manager_data.c973
-rw-r--r--source/blender/draw/intern/draw_manager_exec.c1193
-rw-r--r--source/blender/draw/intern/draw_manager_profiling.c363
-rw-r--r--source/blender/draw/intern/draw_manager_profiling.h43
-rw-r--r--source/blender/draw/intern/draw_manager_shader.c385
-rw-r--r--source/blender/draw/intern/draw_manager_text.c199
-rw-r--r--source/blender/draw/intern/draw_manager_text.h54
-rw-r--r--source/blender/draw/intern/draw_manager_texture.c151
-rw-r--r--source/blender/draw/intern/draw_view.c712
-rw-r--r--source/blender/draw/intern/draw_view.h36
-rw-r--r--source/blender/draw/modes/draw_mode_engines.h45
-rw-r--r--source/blender/draw/modes/edit_armature_mode.c191
-rw-r--r--source/blender/draw/modes/edit_curve_mode.c358
-rw-r--r--source/blender/draw/modes/edit_lattice_mode.c298
-rw-r--r--source/blender/draw/modes/edit_mesh_mode.c587
-rw-r--r--source/blender/draw/modes/edit_mesh_mode_intern.h38
-rw-r--r--source/blender/draw/modes/edit_mesh_mode_text.c301
-rw-r--r--source/blender/draw/modes/edit_metaball_mode.c254
-rw-r--r--source/blender/draw/modes/edit_surface_mode.c270
-rw-r--r--source/blender/draw/modes/edit_text_mode.c311
-rw-r--r--source/blender/draw/modes/object_mode.c2265
-rw-r--r--source/blender/draw/modes/overlay_mode.c163
-rw-r--r--source/blender/draw/modes/paint_texture_mode.c418
-rw-r--r--source/blender/draw/modes/paint_vertex_mode.c199
-rw-r--r--source/blender/draw/modes/paint_weight_mode.c243
-rw-r--r--source/blender/draw/modes/particle_mode.c265
-rw-r--r--source/blender/draw/modes/pose_mode.c240
-rw-r--r--source/blender/draw/modes/sculpt_mode.c302
-rw-r--r--source/blender/draw/modes/shaders/armature_axes_vert.glsl30
-rw-r--r--source/blender/draw/modes/shaders/armature_envelope_distance_frag.glsl15
-rw-r--r--source/blender/draw/modes/shaders/armature_envelope_outline_vert.glsl156
-rw-r--r--source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl16
-rw-r--r--source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl55
-rw-r--r--source/blender/draw/modes/shaders/armature_shape_outline_geom.glsl95
-rw-r--r--source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl59
-rw-r--r--source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl9
-rw-r--r--source/blender/draw/modes/shaders/armature_shape_solid_vert.glsl37
-rw-r--r--source/blender/draw/modes/shaders/armature_sphere_outline_vert.glsl102
-rw-r--r--source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl81
-rw-r--r--source/blender/draw/modes/shaders/armature_sphere_solid_vert.glsl82
-rw-r--r--source/blender/draw/modes/shaders/common_fullscreen_vert.glsl10
-rw-r--r--source/blender/draw/modes/shaders/common_fxaa_lib.glsl678
-rw-r--r--source/blender/draw/modes/shaders/common_globals_lib.glsl69
-rw-r--r--source/blender/draw/modes/shaders/common_view_lib.glsl14
-rw-r--r--source/blender/draw/modes/shaders/edit_curve_overlay_frag.glsl22
-rw-r--r--source/blender/draw/modes/shaders/edit_curve_overlay_handle_geom.glsl79
-rw-r--r--source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl39
-rw-r--r--source/blender/draw/modes/shaders/edit_lattice_overlay_frag.glsl22
-rw-r--r--source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl39
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl19
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl31
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_frag.glsl29
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl29
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl212
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl154
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl307
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_loosevert_vert.glsl61
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_mix_frag.glsl22
-rw-r--r--source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl38
-rw-r--r--source/blender/draw/modes/shaders/edit_normals_geom.glsl15
-rw-r--r--source/blender/draw/modes/shaders/edit_normals_vert.glsl30
-rw-r--r--source/blender/draw/modes/shaders/object_empty_image_frag.glsl21
-rw-r--r--source/blender/draw/modes/shaders/object_empty_image_vert.glsl38
-rw-r--r--source/blender/draw/modes/shaders/object_grid_frag.glsl207
-rw-r--r--source/blender/draw/modes/shaders/object_grid_vert.glsl63
-rw-r--r--source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl35
-rw-r--r--source/blender/draw/modes/shaders/object_mball_handles_vert.glsl34
-rw-r--r--source/blender/draw/modes/shaders/object_outline_detect_frag.glsl82
-rw-r--r--source/blender/draw/modes/shaders/object_outline_expand_frag.glsl37
-rw-r--r--source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl10
-rw-r--r--source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl27
-rw-r--r--source/blender/draw/modes/shaders/object_particle_dot_frag.glsl52
-rw-r--r--source/blender/draw/modes/shaders/object_particle_dot_vert.glsl35
-rw-r--r--source/blender/draw/modes/shaders/object_particle_prim_vert.glsl56
-rw-r--r--source/blender/draw/modes/shaders/overlay_face_orientation_frag.glsl10
-rw-r--r--source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl7
-rw-r--r--source/blender/draw/modes/shaders/paint_texture_frag.glsl11
-rw-r--r--source/blender/draw/modes/shaders/paint_texture_vert.glsl15
-rw-r--r--source/blender/draw/modes/shaders/paint_vert_frag.glsl26
-rw-r--r--source/blender/draw/modes/shaders/paint_vertex_frag.glsl17
-rw-r--r--source/blender/draw/modes/shaders/paint_vertex_vert.glsl21
-rw-r--r--source/blender/draw/modes/shaders/paint_wire_frag.glsl24
-rw-r--r--source/blender/draw/modes/shaders/paint_wire_vert.glsl17
-rw-r--r--source/blender/editors/CMakeLists.txt7
-rw-r--r--source/blender/editors/animation/CMakeLists.txt1
-rw-r--r--source/blender/editors/animation/anim_channels_defines.c121
-rw-r--r--source/blender/editors/animation/anim_channels_edit.c31
-rw-r--r--source/blender/editors/animation/anim_deps.c9
-rw-r--r--source/blender/editors/animation/anim_draw.c153
-rw-r--r--source/blender/editors/animation/anim_filter.c114
-rw-r--r--source/blender/editors/animation/anim_markers.c230
-rw-r--r--source/blender/editors/animation/anim_ops.c117
-rw-r--r--source/blender/editors/animation/drivers.c12
-rw-r--r--source/blender/editors/animation/keyframes_draw.c258
-rw-r--r--source/blender/editors/animation/keyframing.c14
-rw-r--r--source/blender/editors/animation/keyingsets.c6
-rw-r--r--source/blender/editors/armature/BIF_generate.h49
-rw-r--r--source/blender/editors/armature/BIF_retarget.h171
-rw-r--r--source/blender/editors/armature/CMakeLists.txt9
-rw-r--r--source/blender/editors/armature/armature_add.c5
-rw-r--r--source/blender/editors/armature/armature_edit.c118
-rw-r--r--source/blender/editors/armature/armature_intern.h24
-rw-r--r--source/blender/editors/armature/armature_naming.c7
-rw-r--r--source/blender/editors/armature/armature_ops.c27
-rw-r--r--source/blender/editors/armature/armature_relations.c38
-rw-r--r--source/blender/editors/armature/armature_select.c355
-rw-r--r--source/blender/editors/armature/armature_skinning.c56
-rw-r--r--source/blender/editors/armature/armature_utils.c7
-rw-r--r--source/blender/editors/armature/editarmature_generate.c305
-rw-r--r--source/blender/editors/armature/editarmature_retarget.c2641
-rw-r--r--source/blender/editors/armature/editarmature_sketch.c2664
-rw-r--r--source/blender/editors/armature/editarmature_undo.c84
-rw-r--r--source/blender/editors/armature/meshlaplacian.c9
-rw-r--r--source/blender/editors/armature/meshlaplacian.h9
-rw-r--r--source/blender/editors/armature/pose_edit.c230
-rw-r--r--source/blender/editors/armature/pose_group.c25
-rw-r--r--source/blender/editors/armature/pose_lib.c15
-rw-r--r--source/blender/editors/armature/pose_select.c229
-rw-r--r--source/blender/editors/armature/pose_transform.c262
-rw-r--r--source/blender/editors/armature/pose_utils.c10
-rw-r--r--source/blender/editors/armature/reeb.c3435
-rw-r--r--source/blender/editors/armature/reeb.h207
-rw-r--r--source/blender/editors/curve/CMakeLists.txt2
-rw-r--r--source/blender/editors/curve/editcurve.c78
-rw-r--r--source/blender/editors/curve/editcurve_add.c7
-rw-r--r--source/blender/editors/curve/editcurve_paint.c101
-rw-r--r--source/blender/editors/curve/editcurve_select.c1
-rw-r--r--source/blender/editors/curve/editcurve_undo.c80
-rw-r--r--source/blender/editors/curve/editfont.c17
-rw-r--r--source/blender/editors/curve/editfont_undo.c5
-rw-r--r--source/blender/editors/datafiles/CMakeLists.txt87
-rw-r--r--source/blender/editors/gpencil/CMakeLists.txt1
-rw-r--r--source/blender/editors/gpencil/drawgpencil.c1172
-rw-r--r--source/blender/editors/gpencil/gpencil_brush.c32
-rw-r--r--source/blender/editors/gpencil/gpencil_convert.c28
-rw-r--r--source/blender/editors/gpencil/gpencil_edit.c5
-rw-r--r--source/blender/editors/gpencil/gpencil_paint.c112
-rw-r--r--source/blender/editors/gpencil/gpencil_utils.c17
-rw-r--r--source/blender/editors/include/BIF_gl.h53
-rw-r--r--source/blender/editors/include/BIF_glutil.h177
-rw-r--r--source/blender/editors/include/ED_anim_api.h19
-rw-r--r--source/blender/editors/include/ED_armature.h68
-rw-r--r--source/blender/editors/include/ED_buttons.h10
-rw-r--r--source/blender/editors/include/ED_gpencil.h13
-rw-r--r--source/blender/editors/include/ED_image.h3
-rw-r--r--source/blender/editors/include/ED_info.h4
-rw-r--r--source/blender/editors/include/ED_keyframes_draw.h6
-rw-r--r--source/blender/editors/include/ED_manipulator_library.h203
-rw-r--r--source/blender/editors/include/ED_mesh.h16
-rw-r--r--source/blender/editors/include/ED_node.h2
-rw-r--r--source/blender/editors/include/ED_object.h70
-rw-r--r--source/blender/editors/include/ED_particle.h11
-rw-r--r--source/blender/editors/include/ED_render.h12
-rw-r--r--source/blender/editors/include/ED_scene.h44
-rw-r--r--source/blender/editors/include/ED_screen.h138
-rw-r--r--source/blender/editors/include/ED_screen_types.h26
-rw-r--r--source/blender/editors/include/ED_sculpt.h3
-rw-r--r--source/blender/editors/include/ED_space_api.h2
-rw-r--r--source/blender/editors/include/ED_transform.h31
-rw-r--r--source/blender/editors/include/ED_transform_snap_object_context.h7
-rw-r--r--source/blender/editors/include/ED_undo.h15
-rw-r--r--source/blender/editors/include/ED_util.h5
-rw-r--r--source/blender/editors/include/ED_uvedit.h22
-rw-r--r--source/blender/editors/include/ED_view3d.h107
-rw-r--r--source/blender/editors/include/UI_icons.h18
-rw-r--r--source/blender/editors/include/UI_interface.h181
-rw-r--r--source/blender/editors/include/UI_interface_icons.h7
-rw-r--r--source/blender/editors/include/UI_resources.h35
-rw-r--r--source/blender/editors/include/UI_view2d.h11
-rw-r--r--source/blender/editors/interface/CMakeLists.txt3
-rw-r--r--source/blender/editors/interface/interface.c610
-rw-r--r--source/blender/editors/interface/interface_align.c51
-rw-r--r--source/blender/editors/interface/interface_anim.c5
-rw-r--r--source/blender/editors/interface/interface_draw.c1745
-rw-r--r--source/blender/editors/interface/interface_eyedropper.c10
-rw-r--r--source/blender/editors/interface/interface_eyedropper_color.c4
-rw-r--r--source/blender/editors/interface/interface_eyedropper_datablock.c4
-rw-r--r--source/blender/editors/interface/interface_eyedropper_depth.c12
-rw-r--r--source/blender/editors/interface/interface_eyedropper_driver.c8
-rw-r--r--source/blender/editors/interface/interface_handlers.c627
-rw-r--r--source/blender/editors/interface/interface_icons.c477
-rw-r--r--source/blender/editors/interface/interface_intern.h130
-rw-r--r--source/blender/editors/interface/interface_layout.c345
-rw-r--r--source/blender/editors/interface/interface_ops.c341
-rw-r--r--source/blender/editors/interface/interface_panel.c395
-rw-r--r--source/blender/editors/interface/interface_region_menu_pie.c3
-rw-r--r--source/blender/editors/interface/interface_region_menu_popup.c21
-rw-r--r--source/blender/editors/interface/interface_region_popover.c264
-rw-r--r--source/blender/editors/interface/interface_region_popup.c229
-rw-r--r--source/blender/editors/interface/interface_region_search.c5
-rw-r--r--source/blender/editors/interface/interface_region_tooltip.c228
-rw-r--r--source/blender/editors/interface/interface_regions.c3
-rw-r--r--source/blender/editors/interface/interface_style.c27
-rw-r--r--source/blender/editors/interface/interface_templates.c923
-rw-r--r--source/blender/editors/interface/interface_utils.c159
-rw-r--r--source/blender/editors/interface/interface_widgets.c1789
-rw-r--r--source/blender/editors/interface/resources.c332
-rw-r--r--source/blender/editors/interface/view2d.c382
-rw-r--r--source/blender/editors/interface/view2d_ops.c29
-rw-r--r--source/blender/editors/io/CMakeLists.txt1
-rw-r--r--source/blender/editors/io/io_alembic.c18
-rw-r--r--source/blender/editors/io/io_collada.c48
-rw-r--r--source/blender/editors/lattice/CMakeLists.txt2
-rw-r--r--source/blender/editors/lattice/editlattice_select.c69
-rw-r--r--source/blender/editors/lattice/editlattice_tools.c7
-rw-r--r--source/blender/editors/lattice/editlattice_undo.c80
-rw-r--r--source/blender/editors/manipulator_library/CMakeLists.txt60
-rw-r--r--source/blender/editors/manipulator_library/geometry/geom_arrow_manipulator.c141
-rw-r--r--source/blender/editors/manipulator_library/geometry/geom_cube_manipulator.c75
-rw-r--r--source/blender/editors/manipulator_library/geometry/geom_dial_manipulator.c813
-rw-r--r--source/blender/editors/manipulator_library/manipulator_draw_utils.c131
-rw-r--r--source/blender/editors/manipulator_library/manipulator_geometry.h54
-rw-r--r--source/blender/editors/manipulator_library/manipulator_library_intern.h108
-rw-r--r--source/blender/editors/manipulator_library/manipulator_library_presets.c151
-rw-r--r--source/blender/editors/manipulator_library/manipulator_library_utils.c221
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c224
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c478
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c263
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c1109
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/cage3d_manipulator.c735
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c482
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c374
-rw-r--r--source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c190
-rw-r--r--source/blender/editors/mask/CMakeLists.txt1
-rw-r--r--source/blender/editors/mask/mask_add.c5
-rw-r--r--source/blender/editors/mask/mask_draw.c470
-rw-r--r--source/blender/editors/mask/mask_ops.c25
-rw-r--r--source/blender/editors/mask/mask_relationships.c7
-rw-r--r--source/blender/editors/mask/mask_shapekey.c11
-rw-r--r--source/blender/editors/mesh/CMakeLists.txt15
-rw-r--r--source/blender/editors/mesh/editface.c10
-rw-r--r--source/blender/editors/mesh/editmesh_add.c111
-rw-r--r--source/blender/editors/mesh/editmesh_bevel.c8
-rw-r--r--source/blender/editors/mesh/editmesh_bisect.c356
-rw-r--r--source/blender/editors/mesh/editmesh_extrude.c236
-rw-r--r--source/blender/editors/mesh/editmesh_extrude_screw.c2
-rw-r--r--source/blender/editors/mesh/editmesh_extrude_spin.c400
-rw-r--r--source/blender/editors/mesh/editmesh_inset.c15
-rw-r--r--source/blender/editors/mesh/editmesh_knife.c179
-rw-r--r--source/blender/editors/mesh/editmesh_knife_project.c11
-rw-r--r--source/blender/editors/mesh/editmesh_loopcut.c188
-rw-r--r--source/blender/editors/mesh/editmesh_path.c37
-rw-r--r--source/blender/editors/mesh/editmesh_polybuild.c542
-rw-r--r--source/blender/editors/mesh/editmesh_select.c659
-rw-r--r--source/blender/editors/mesh/editmesh_tools.c1750
-rw-r--r--source/blender/editors/mesh/editmesh_undo.c150
-rw-r--r--source/blender/editors/mesh/editmesh_utils.c32
-rw-r--r--source/blender/editors/mesh/mesh_data.c80
-rw-r--r--source/blender/editors/mesh/mesh_intern.h15
-rw-r--r--source/blender/editors/mesh/mesh_mirror.c13
-rw-r--r--source/blender/editors/mesh/mesh_navmesh.c732
-rw-r--r--source/blender/editors/mesh/mesh_ops.c34
-rw-r--r--source/blender/editors/mesh/meshtools.c85
-rw-r--r--source/blender/editors/metaball/CMakeLists.txt2
-rw-r--r--source/blender/editors/metaball/editmball_undo.c80
-rw-r--r--source/blender/editors/metaball/mball_edit.c11
-rw-r--r--source/blender/editors/object/CMakeLists.txt7
-rw-r--r--source/blender/editors/object/object_add.c462
-rw-r--r--source/blender/editors/object/object_bake.c375
-rw-r--r--source/blender/editors/object/object_bake_api.c44
-rw-r--r--source/blender/editors/object/object_constraint.c85
-rw-r--r--source/blender/editors/object/object_data_transfer.c34
-rw-r--r--source/blender/editors/object/object_edit.c1250
-rw-r--r--source/blender/editors/object/object_facemap_ops.c498
-rw-r--r--source/blender/editors/object/object_group.c46
-rw-r--r--source/blender/editors/object/object_hook.c41
-rw-r--r--source/blender/editors/object/object_intern.h30
-rw-r--r--source/blender/editors/object/object_lod.c114
-rw-r--r--source/blender/editors/object/object_modes.c136
-rw-r--r--source/blender/editors/object/object_modifier.c146
-rw-r--r--source/blender/editors/object/object_ops.c55
-rw-r--r--source/blender/editors/object/object_relations.c822
-rw-r--r--source/blender/editors/object/object_select.c491
-rw-r--r--source/blender/editors/object/object_shapekey.c20
-rw-r--r--source/blender/editors/object/object_transform.c460
-rw-r--r--source/blender/editors/object/object_vgroup.c95
-rw-r--r--source/blender/editors/physics/CMakeLists.txt1
-rw-r--r--source/blender/editors/physics/dynamicpaint_ops.c18
-rw-r--r--source/blender/editors/physics/particle_boids.c20
-rw-r--r--source/blender/editors/physics/particle_edit.c257
-rw-r--r--source/blender/editors/physics/particle_edit_undo.c12
-rw-r--r--source/blender/editors/physics/particle_object.c90
-rw-r--r--source/blender/editors/physics/physics_fluid.c37
-rw-r--r--source/blender/editors/physics/physics_intern.h6
-rw-r--r--source/blender/editors/physics/physics_ops.c17
-rw-r--r--source/blender/editors/physics/physics_pointcache.c70
-rw-r--r--source/blender/editors/physics/rigidbody_constraint.c26
-rw-r--r--source/blender/editors/physics/rigidbody_object.c20
-rw-r--r--source/blender/editors/render/CMakeLists.txt2
-rw-r--r--source/blender/editors/render/render_intern.h9
-rw-r--r--source/blender/editors/render/render_internal.c761
-rw-r--r--source/blender/editors/render/render_opengl.c141
-rw-r--r--source/blender/editors/render/render_ops.c7
-rw-r--r--source/blender/editors/render/render_preview.c291
-rw-r--r--source/blender/editors/render/render_shading.c412
-rw-r--r--source/blender/editors/render/render_update.c367
-rw-r--r--source/blender/editors/render/render_view.c15
-rw-r--r--source/blender/editors/scene/CMakeLists.txt44
-rw-r--r--source/blender/editors/scene/scene_edit.c288
-rw-r--r--source/blender/editors/screen/CMakeLists.txt4
-rw-r--r--source/blender/editors/screen/area.c1678
-rw-r--r--source/blender/editors/screen/glutil.c773
-rw-r--r--source/blender/editors/screen/screen_context.c331
-rw-r--r--source/blender/editors/screen/screen_draw.c456
-rw-r--r--source/blender/editors/screen/screen_edit.c1068
-rw-r--r--source/blender/editors/screen/screen_intern.h29
-rw-r--r--source/blender/editors/screen/screen_ops.c598
-rw-r--r--source/blender/editors/screen/screendump.c33
-rw-r--r--source/blender/editors/screen/workspace_edit.c500
-rw-r--r--source/blender/editors/screen/workspace_layout_edit.c197
-rw-r--r--source/blender/editors/sculpt_paint/CMakeLists.txt1
-rw-r--r--source/blender/editors/sculpt_paint/paint_cursor.c410
-rw-r--r--source/blender/editors/sculpt_paint/paint_curve.c2
-rw-r--r--source/blender/editors/sculpt_paint/paint_hide.c9
-rw-r--r--source/blender/editors/sculpt_paint/paint_image.c80
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_2d.c5
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_proj.c221
-rw-r--r--source/blender/editors/sculpt_paint/paint_image_undo.c6
-rw-r--r--source/blender/editors/sculpt_paint/paint_intern.h8
-rw-r--r--source/blender/editors/sculpt_paint/paint_mask.c21
-rw-r--r--source/blender/editors/sculpt_paint/paint_ops.c1
-rw-r--r--source/blender/editors/sculpt_paint/paint_stroke.c59
-rw-r--r--source/blender/editors/sculpt_paint/paint_utils.c46
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex.c104
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_color_ops.c9
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_color_utils.c5
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_proj.c18
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c23
-rw-r--r--source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c6
-rw-r--r--source/blender/editors/sculpt_paint/sculpt.c104
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_intern.h3
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_undo.c23
-rw-r--r--source/blender/editors/sculpt_paint/sculpt_uv.c24
-rw-r--r--source/blender/editors/sound/CMakeLists.txt2
-rw-r--r--source/blender/editors/sound/sound_ops.c9
-rw-r--r--source/blender/editors/space_action/action_buttons.c1
-rw-r--r--source/blender/editors/space_action/action_draw.c243
-rw-r--r--source/blender/editors/space_action/action_intern.h5
-rw-r--r--source/blender/editors/space_action/space_action.c212
-rw-r--r--source/blender/editors/space_api/spacetypes.c35
-rw-r--r--source/blender/editors/space_buttons/buttons_context.c383
-rw-r--r--source/blender/editors/space_buttons/buttons_intern.h2
-rw-r--r--source/blender/editors/space_buttons/buttons_texture.c220
-rw-r--r--source/blender/editors/space_buttons/space_buttons.c55
-rw-r--r--source/blender/editors/space_clip/CMakeLists.txt1
-rw-r--r--source/blender/editors/space_clip/clip_buttons.c7
-rw-r--r--source/blender/editors/space_clip/clip_dopesheet_draw.c261
-rw-r--r--source/blender/editors/space_clip/clip_draw.c880
-rw-r--r--source/blender/editors/space_clip/clip_editor.c11
-rw-r--r--source/blender/editors/space_clip/clip_graph_draw.c150
-rw-r--r--source/blender/editors/space_clip/clip_graph_ops.c5
-rw-r--r--source/blender/editors/space_clip/clip_intern.h4
-rw-r--r--source/blender/editors/space_clip/clip_ops.c5
-rw-r--r--source/blender/editors/space_clip/clip_toolbar.c93
-rw-r--r--source/blender/editors/space_clip/clip_utils.c82
-rw-r--r--source/blender/editors/space_clip/space_clip.c110
-rw-r--r--source/blender/editors/space_clip/tracking_ops.c9
-rw-r--r--source/blender/editors/space_clip/tracking_ops_orient.c41
-rw-r--r--source/blender/editors/space_clip/tracking_ops_plane.c7
-rw-r--r--source/blender/editors/space_clip/tracking_ops_solve.c7
-rw-r--r--source/blender/editors/space_clip/tracking_ops_stabilize.c11
-rw-r--r--source/blender/editors/space_clip/tracking_ops_track.c3
-rw-r--r--source/blender/editors/space_console/console_draw.c22
-rw-r--r--source/blender/editors/space_console/space_console.c6
-rw-r--r--source/blender/editors/space_file/file_draw.c133
-rw-r--r--source/blender/editors/space_file/file_panels.c3
-rw-r--r--source/blender/editors/space_file/file_utils.c1
-rw-r--r--source/blender/editors/space_file/filesel.c5
-rw-r--r--source/blender/editors/space_file/space_file.c61
-rw-r--r--source/blender/editors/space_graph/CMakeLists.txt3
-rw-r--r--source/blender/editors/space_graph/graph_buttons.c4
-rw-r--r--source/blender/editors/space_graph/graph_draw.c748
-rw-r--r--source/blender/editors/space_graph/graph_edit.c9
-rw-r--r--source/blender/editors/space_graph/space_graph.c155
-rw-r--r--source/blender/editors/space_image/CMakeLists.txt1
-rw-r--r--source/blender/editors/space_image/image_draw.c570
-rw-r--r--source/blender/editors/space_image/image_edit.c15
-rw-r--r--source/blender/editors/space_image/image_intern.h2
-rw-r--r--source/blender/editors/space_image/image_ops.c55
-rw-r--r--source/blender/editors/space_image/space_image.c112
-rw-r--r--source/blender/editors/space_info/info_report.c3
-rw-r--r--source/blender/editors/space_info/info_stats.c133
-rw-r--r--source/blender/editors/space_info/space_info.c33
-rw-r--r--source/blender/editors/space_info/textview.c48
-rw-r--r--source/blender/editors/space_logic/CMakeLists.txt58
-rw-r--r--source/blender/editors/space_logic/logic_buttons.c166
-rw-r--r--source/blender/editors/space_logic/logic_intern.h55
-rw-r--r--source/blender/editors/space_logic/logic_ops.c753
-rw-r--r--source/blender/editors/space_logic/logic_window.c2601
-rw-r--r--source/blender/editors/space_logic/space_logic.c375
-rw-r--r--source/blender/editors/space_nla/nla_channels.c24
-rw-r--r--source/blender/editors/space_nla/nla_draw.c463
-rw-r--r--source/blender/editors/space_nla/space_nla.c88
-rw-r--r--source/blender/editors/space_node/CMakeLists.txt2
-rw-r--r--source/blender/editors/space_node/drawnode.c782
-rw-r--r--source/blender/editors/space_node/node_add.c14
-rw-r--r--source/blender/editors/space_node/node_draw.c505
-rw-r--r--source/blender/editors/space_node/node_edit.c114
-rw-r--r--source/blender/editors/space_node/node_intern.h18
-rw-r--r--source/blender/editors/space_node/node_manipulators.c616
-rw-r--r--source/blender/editors/space_node/node_ops.c6
-rw-r--r--source/blender/editors/space_node/node_templates.c5
-rw-r--r--source/blender/editors/space_node/space_node.c64
-rw-r--r--source/blender/editors/space_outliner/CMakeLists.txt3
-rw-r--r--source/blender/editors/space_outliner/outliner_collections.c1043
-rw-r--r--source/blender/editors/space_outliner/outliner_draw.c1285
-rw-r--r--source/blender/editors/space_outliner/outliner_edit.c359
-rw-r--r--source/blender/editors/space_outliner/outliner_intern.h157
-rw-r--r--source/blender/editors/space_outliner/outliner_ops.c453
-rw-r--r--source/blender/editors/space_outliner/outliner_select.c552
-rw-r--r--source/blender/editors/space_outliner/outliner_tools.c362
-rw-r--r--source/blender/editors/space_outliner/outliner_tree.c1097
-rw-r--r--source/blender/editors/space_outliner/outliner_utils.c233
-rw-r--r--source/blender/editors/space_outliner/space_outliner.c66
-rw-r--r--source/blender/editors/space_script/space_script.c6
-rw-r--r--source/blender/editors/space_sequencer/CMakeLists.txt2
-rw-r--r--source/blender/editors/space_sequencer/sequencer_add.c4
-rw-r--r--source/blender/editors/space_sequencer/sequencer_draw.c773
-rw-r--r--source/blender/editors/space_sequencer/sequencer_edit.c24
-rw-r--r--source/blender/editors/space_sequencer/sequencer_intern.h3
-rw-r--r--source/blender/editors/space_sequencer/space_sequencer.c70
-rw-r--r--source/blender/editors/space_text/space_text.c5
-rw-r--r--source/blender/editors/space_text/text_draw.c270
-rw-r--r--source/blender/editors/space_text/text_ops.c2
-rw-r--r--source/blender/editors/space_time/CMakeLists.txt46
-rw-r--r--source/blender/editors/space_time/space_time.c833
-rw-r--r--source/blender/editors/space_time/time_intern.h43
-rw-r--r--source/blender/editors/space_time/time_ops.c227
-rw-r--r--source/blender/editors/space_topbar/CMakeLists.txt45
-rw-r--r--source/blender/editors/space_topbar/space_topbar.c339
-rw-r--r--source/blender/editors/space_userpref/space_userpref.c10
-rw-r--r--source/blender/editors/space_view3d/CMakeLists.txt25
-rw-r--r--source/blender/editors/space_view3d/drawanimviz.c402
-rw-r--r--source/blender/editors/space_view3d/drawarmature.c2793
-rw-r--r--source/blender/editors/space_view3d/drawmesh.c1406
-rw-r--r--source/blender/editors/space_view3d/drawobject.c8417
-rw-r--r--source/blender/editors/space_view3d/drawsimdebug.c180
-rw-r--r--source/blender/editors/space_view3d/drawvolume.c5
-rw-r--r--source/blender/editors/space_view3d/space_view3d.c567
-rw-r--r--source/blender/editors/space_view3d/view3d_buttons.c29
-rw-r--r--source/blender/editors/space_view3d/view3d_camera_control.c15
-rw-r--r--source/blender/editors/space_view3d/view3d_draw.c4266
-rw-r--r--source/blender/editors/space_view3d/view3d_draw_legacy.c1071
-rw-r--r--source/blender/editors/space_view3d/view3d_edit.c323
-rw-r--r--source/blender/editors/space_view3d/view3d_fly.c60
-rw-r--r--source/blender/editors/space_view3d/view3d_header.c144
-rw-r--r--source/blender/editors/space_view3d/view3d_intern.h125
-rw-r--r--source/blender/editors/space_view3d/view3d_iterators.c19
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_armature.c220
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_camera.c464
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_empty.c196
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_forcefield.c118
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_lamp.c289
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_navigate.c360
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c309
-rw-r--r--source/blender/editors/space_view3d/view3d_manipulator_ruler.c1094
-rw-r--r--source/blender/editors/space_view3d/view3d_ops.c44
-rw-r--r--source/blender/editors/space_view3d/view3d_project.c43
-rw-r--r--source/blender/editors/space_view3d/view3d_ruler.c239
-rw-r--r--source/blender/editors/space_view3d/view3d_select.c641
-rw-r--r--source/blender/editors/space_view3d/view3d_snap.c17
-rw-r--r--source/blender/editors/space_view3d/view3d_toolbar.c77
-rw-r--r--source/blender/editors/space_view3d/view3d_utils.c188
-rw-r--r--source/blender/editors/space_view3d/view3d_view.c652
-rw-r--r--source/blender/editors/space_view3d/view3d_walk.c43
-rw-r--r--source/blender/editors/transform/CMakeLists.txt8
-rw-r--r--source/blender/editors/transform/transform.c2135
-rw-r--r--source/blender/editors/transform/transform.h196
-rw-r--r--source/blender/editors/transform/transform_constraints.c184
-rw-r--r--source/blender/editors/transform/transform_conversions.c3333
-rw-r--r--source/blender/editors/transform/transform_generics.c1186
-rw-r--r--source/blender/editors/transform/transform_input.c32
-rw-r--r--source/blender/editors/transform/transform_manipulator.c1981
-rw-r--r--source/blender/editors/transform/transform_manipulator_2d.c382
-rw-r--r--source/blender/editors/transform/transform_manipulator_3d.c1725
-rw-r--r--source/blender/editors/transform/transform_ops.c88
-rw-r--r--source/blender/editors/transform/transform_orientations.c117
-rw-r--r--source/blender/editors/transform/transform_snap.c410
-rw-r--r--source/blender/editors/transform/transform_snap_object.c49
-rw-r--r--source/blender/editors/undo/ed_undo.c68
-rw-r--r--source/blender/editors/undo/memfile_undo.c3
-rw-r--r--source/blender/editors/util/CMakeLists.txt3
-rw-r--r--source/blender/editors/util/ed_transverts.c5
-rw-r--r--source/blender/editors/util/ed_util.c105
-rw-r--r--source/blender/editors/uvedit/CMakeLists.txt1
-rw-r--r--source/blender/editors/uvedit/uvedit_buttons.c20
-rw-r--r--source/blender/editors/uvedit/uvedit_draw.c838
-rw-r--r--source/blender/editors/uvedit/uvedit_intern.h19
-rw-r--r--source/blender/editors/uvedit/uvedit_ops.c1137
-rw-r--r--source/blender/editors/uvedit/uvedit_smart_stitch.c153
-rw-r--r--source/blender/editors/uvedit/uvedit_unwrap_ops.c367
-rw-r--r--source/blender/freestyle/CMakeLists.txt5
-rw-r--r--source/blender/freestyle/FRS_freestyle.h7
-rw-r--r--source/blender/freestyle/intern/application/Controller.cpp8
-rw-r--r--source/blender/freestyle/intern/application/Controller.h2
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp370
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h19
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp199
-rw-r--r--source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h2
-rw-r--r--source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp42
-rw-r--r--source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp9
-rw-r--r--source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h15
-rw-r--r--source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp35
-rw-r--r--source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h66
-rw-r--r--source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp35
-rw-r--r--source/blender/freestyle/intern/scene_graph/NodeViewLayer.h66
-rw-r--r--source/blender/freestyle/intern/scene_graph/SceneHash.cpp4
-rw-r--r--source/blender/freestyle/intern/scene_graph/SceneHash.h4
-rw-r--r--source/blender/freestyle/intern/scene_graph/SceneVisitor.h4
-rw-r--r--source/blender/freestyle/intern/stroke/Stroke.h3
-rw-r--r--source/blender/gpu/CMakeLists.txt133
-rw-r--r--source/blender/gpu/GPU_basic_shader.h9
-rw-r--r--source/blender/gpu/GPU_batch.h74
-rw-r--r--source/blender/gpu/GPU_buffers.h194
-rw-r--r--source/blender/gpu/GPU_compositing.h106
-rw-r--r--source/blender/gpu/GPU_debug.h18
-rw-r--r--source/blender/gpu/GPU_draw.h85
-rw-r--r--source/blender/gpu/GPU_extensions.h9
-rw-r--r--source/blender/gpu/GPU_framebuffer.h151
-rw-r--r--source/blender/gpu/GPU_glew.h4
-rw-r--r--source/blender/gpu/GPU_immediate.h58
-rw-r--r--source/blender/gpu/GPU_immediate_util.h64
-rw-r--r--source/blender/gpu/GPU_legacy_stubs.h457
-rw-r--r--source/blender/gpu/GPU_material.h188
-rw-r--r--source/blender/gpu/GPU_matrix.h190
-rw-r--r--source/blender/gpu/GPU_select.h3
-rw-r--r--source/blender/gpu/GPU_shader.h125
-rw-r--r--source/blender/gpu/GPU_texture.h139
-rw-r--r--source/blender/gpu/GPU_uniformbuffer.h59
-rw-r--r--source/blender/gpu/GPU_viewport.h130
-rw-r--r--source/blender/gpu/intern/gpu_basic_shader.c413
-rw-r--r--source/blender/gpu/intern/gpu_batch.c281
-rw-r--r--source/blender/gpu/intern/gpu_batch_presets.c236
-rw-r--r--source/blender/gpu/intern/gpu_buffers.c1696
-rw-r--r--source/blender/gpu/intern/gpu_codegen.c792
-rw-r--r--source/blender/gpu/intern/gpu_codegen.h39
-rw-r--r--source/blender/gpu/intern/gpu_compositing.c1461
-rw-r--r--source/blender/gpu/intern/gpu_debug.c700
-rw-r--r--source/blender/gpu/intern/gpu_draw.c1586
-rw-r--r--source/blender/gpu/intern/gpu_extensions.c122
-rw-r--r--source/blender/gpu/intern/gpu_framebuffer.c943
-rw-r--r--source/blender/gpu/intern/gpu_immediate.c88
-rw-r--r--source/blender/gpu/intern/gpu_immediate_util.c424
-rw-r--r--source/blender/gpu/intern/gpu_init_exit.c18
-rw-r--r--source/blender/gpu/intern/gpu_material.c2951
-rw-r--r--source/blender/gpu/intern/gpu_matrix.c649
-rw-r--r--source/blender/gpu/intern/gpu_select.c33
-rw-r--r--source/blender/gpu/intern/gpu_select_pick.c10
-rw-r--r--source/blender/gpu/intern/gpu_select_sample_query.c20
-rw-r--r--source/blender/gpu/intern/gpu_shader.c822
-rw-r--r--source/blender/gpu/intern/gpu_shader_private.h42
-rw-r--r--source/blender/gpu/intern/gpu_texture.c1052
-rw-r--r--source/blender/gpu/intern/gpu_uniformbuffer.c378
-rw-r--r--source/blender/gpu/intern/gpu_viewport.c644
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl48
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl35
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl54
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl56
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl21
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl59
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl10
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl107
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl21
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl24
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl27
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl20
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_vert.glsl9
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl40
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl202
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl64
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl26
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl26
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl21
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl22
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl21
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl24
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_3D_vert.glsl9
-rw-r--r--source/blender/gpu/shaders/gpu_shader_basic_frag.glsl37
-rw-r--r--source/blender/gpu/shaders/gpu_shader_basic_geom.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_basic_vert.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_checker_frag.glsl20
-rw-r--r--source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl20
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl54
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl60
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl68
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl44
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl20
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl67
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl52
-rw-r--r--source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fire_frag.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl8
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl5
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl111
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl68
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_dof_hq_geo.glsl39
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_dof_hq_vert.glsl34
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl45
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_lib.glsl7
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl23
-rw-r--r--source/blender/gpu/shaders/gpu_shader_fx_vert.glsl9
-rw-r--r--source/blender/gpu/shaders/gpu_shader_geometry.glsl18
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_frag.glsl10
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl34
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl30
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl124
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl11
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl50
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl25
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl57
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl63
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl27
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl32
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl29
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl22
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl23
-rw-r--r--source/blender/gpu/shaders/gpu_shader_instance_vert.glsl13
-rw-r--r--source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl31
-rw-r--r--source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl34
-rw-r--r--source/blender/gpu/shaders/gpu_shader_material.glsl2367
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl24
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl17
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl36
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl31
-rw-r--r--source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl19
-rw-r--r--source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl12
-rw-r--r--source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl18
-rw-r--r--source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl14
-rw-r--r--source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl16
-rw-r--r--source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl19
-rw-r--r--source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl7
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_frag.glsl74
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_geom.glsl37
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl36
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl22
-rw-r--r--source/blender/gpu/shaders/gpu_shader_text_vert.glsl17
-rw-r--r--source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl21
-rw-r--r--source/blender/gpu/shaders/gpu_shader_vertex.glsl19
-rw-r--r--source/blender/gpu/shaders/gpu_shader_vertex_world.glsl9
-rw-r--r--source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl6
-rw-r--r--source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl7
-rw-r--r--source/blender/ikplugin/BIK_api.h5
-rw-r--r--source/blender/ikplugin/intern/ikplugin_api.c8
-rw-r--r--source/blender/ikplugin/intern/ikplugin_api.h7
-rw-r--r--source/blender/ikplugin/intern/iksolver_plugin.c14
-rw-r--r--source/blender/ikplugin/intern/iksolver_plugin.h7
-rw-r--r--source/blender/ikplugin/intern/itasc_plugin.cpp73
-rw-r--r--source/blender/ikplugin/intern/itasc_plugin.h4
-rw-r--r--source/blender/imbuf/intern/indexer.c2
-rw-r--r--source/blender/imbuf/intern/thumbs.c4
-rw-r--r--source/blender/imbuf/intern/thumbs_blend.c1
-rw-r--r--source/blender/makesdna/DNA_ID.h151
-rw-r--r--source/blender/makesdna/DNA_action_types.h37
-rw-r--r--source/blender/makesdna/DNA_actuator_types.h583
-rw-r--r--source/blender/makesdna/DNA_anim_types.h6
-rw-r--r--source/blender/makesdna/DNA_armature_types.h2
-rw-r--r--source/blender/makesdna/DNA_camera_types.h53
-rw-r--r--source/blender/makesdna/DNA_constraint_types.h8
-rw-r--r--source/blender/makesdna/DNA_controller_types.h95
-rw-r--r--source/blender/makesdna/DNA_curve_types.h1
-rw-r--r--source/blender/makesdna/DNA_customdata_types.h8
-rw-r--r--source/blender/makesdna/DNA_defs.h6
-rw-r--r--source/blender/makesdna/DNA_dynamicpaint_types.h3
-rw-r--r--source/blender/makesdna/DNA_fileglobal_types.h6
-rw-r--r--source/blender/makesdna/DNA_gpencil_types.h5
-rw-r--r--source/blender/makesdna/DNA_gpu_types.h2
-rw-r--r--source/blender/makesdna/DNA_group_types.h10
-rw-r--r--source/blender/makesdna/DNA_image_types.h27
-rw-r--r--source/blender/makesdna/DNA_lamp_types.h115
-rw-r--r--source/blender/makesdna/DNA_lattice_types.h1
-rw-r--r--source/blender/makesdna/DNA_layer_types.h149
-rw-r--r--source/blender/makesdna/DNA_lightprobe_types.h113
-rw-r--r--source/blender/makesdna/DNA_material_types.h376
-rw-r--r--source/blender/makesdna/DNA_mesh_types.h27
-rw-r--r--source/blender/makesdna/DNA_meshdata_types.h76
-rw-r--r--source/blender/makesdna/DNA_meta_types.h3
-rw-r--r--source/blender/makesdna/DNA_modifier_types.h12
-rw-r--r--source/blender/makesdna/DNA_node_types.h10
-rw-r--r--source/blender/makesdna/DNA_object_enums.h3
-rw-r--r--source/blender/makesdna/DNA_object_force_types.h59
-rw-r--r--source/blender/makesdna/DNA_object_types.h215
-rw-r--r--source/blender/makesdna/DNA_outliner_types.h22
-rw-r--r--source/blender/makesdna/DNA_particle_types.h19
-rw-r--r--source/blender/makesdna/DNA_property_types.h65
-rw-r--r--source/blender/makesdna/DNA_scene_types.h512
-rw-r--r--source/blender/makesdna/DNA_screen_types.h113
-rw-r--r--source/blender/makesdna/DNA_sensor_types.h334
-rw-r--r--source/blender/makesdna/DNA_space_types.h209
-rw-r--r--source/blender/makesdna/DNA_texture_types.h132
-rw-r--r--source/blender/makesdna/DNA_userdef_types.h74
-rw-r--r--source/blender/makesdna/DNA_view2d_types.h5
-rw-r--r--source/blender/makesdna/DNA_view3d_types.h190
-rw-r--r--source/blender/makesdna/DNA_windowmanager_types.h37
-rw-r--r--source/blender/makesdna/DNA_workspace_types.h163
-rw-r--r--source/blender/makesdna/DNA_world_types.h115
-rw-r--r--source/blender/makesdna/intern/dna_genfile.c78
-rw-r--r--source/blender/makesdna/intern/makesdna.c27
-rw-r--r--source/blender/makesrna/RNA_access.h133
-rw-r--r--source/blender/makesrna/RNA_define.h10
-rw-r--r--source/blender/makesrna/RNA_enum_types.h8
-rw-r--r--source/blender/makesrna/RNA_types.h24
-rw-r--r--source/blender/makesrna/intern/CMakeLists.txt19
-rw-r--r--source/blender/makesrna/intern/makesrna.c42
-rw-r--r--source/blender/makesrna/intern/rna_ID.c191
-rw-r--r--source/blender/makesrna/intern/rna_access.c1000
-rw-r--r--source/blender/makesrna/intern/rna_actuator.c2220
-rw-r--r--source/blender/makesrna/intern/rna_actuator_api.c77
-rw-r--r--source/blender/makesrna/intern/rna_animation.c39
-rw-r--r--source/blender/makesrna/intern/rna_armature.c24
-rw-r--r--source/blender/makesrna/intern/rna_boid.c14
-rw-r--r--source/blender/makesrna/intern/rna_brush.c40
-rw-r--r--source/blender/makesrna/intern/rna_cachefile.c5
-rw-r--r--source/blender/makesrna/intern/rna_camera.c211
-rw-r--r--source/blender/makesrna/intern/rna_cloth.c9
-rw-r--r--source/blender/makesrna/intern/rna_color.c42
-rw-r--r--source/blender/makesrna/intern/rna_constraint.c182
-rw-r--r--source/blender/makesrna/intern/rna_context.c94
-rw-r--r--source/blender/makesrna/intern/rna_controller.c327
-rw-r--r--source/blender/makesrna/intern/rna_controller_api.c86
-rw-r--r--source/blender/makesrna/intern/rna_curve.c12
-rw-r--r--source/blender/makesrna/intern/rna_curve_api.c10
-rw-r--r--source/blender/makesrna/intern/rna_define.c31
-rw-r--r--source/blender/makesrna/intern/rna_depsgraph.c325
-rw-r--r--source/blender/makesrna/intern/rna_dynamicpaint.c19
-rw-r--r--source/blender/makesrna/intern/rna_fcurve.c11
-rw-r--r--source/blender/makesrna/intern/rna_fluidsim.c5
-rw-r--r--source/blender/makesrna/intern/rna_group.c31
-rw-r--r--source/blender/makesrna/intern/rna_image.c101
-rw-r--r--source/blender/makesrna/intern/rna_image_api.c5
-rw-r--r--source/blender/makesrna/intern/rna_internal.h82
-rw-r--r--source/blender/makesrna/intern/rna_internal_types.h65
-rw-r--r--source/blender/makesrna/intern/rna_key.c7
-rw-r--r--source/blender/makesrna/intern/rna_lamp.c542
-rw-r--r--source/blender/makesrna/intern/rna_lattice.c7
-rw-r--r--source/blender/makesrna/intern/rna_lattice_api.c10
-rw-r--r--source/blender/makesrna/intern/rna_layer.c2036
-rw-r--r--source/blender/makesrna/intern/rna_lightprobe.c224
-rw-r--r--source/blender/makesrna/intern/rna_linestyle.c21
-rw-r--r--source/blender/makesrna/intern/rna_main.c14
-rw-r--r--source/blender/makesrna/intern/rna_main_api.c117
-rw-r--r--source/blender/makesrna/intern/rna_mask.c11
-rw-r--r--source/blender/makesrna/intern/rna_material.c1882
-rw-r--r--source/blender/makesrna/intern/rna_mesh.c549
-rw-r--r--source/blender/makesrna/intern/rna_mesh_api.c19
-rw-r--r--source/blender/makesrna/intern/rna_mesh_utils.h11
-rw-r--r--source/blender/makesrna/intern/rna_meta.c12
-rw-r--r--source/blender/makesrna/intern/rna_meta_api.c9
-rw-r--r--source/blender/makesrna/intern/rna_modifier.c48
-rw-r--r--source/blender/makesrna/intern/rna_movieclip.c4
-rw-r--r--source/blender/makesrna/intern/rna_nla.c1
-rw-r--r--source/blender/makesrna/intern/rna_nodetree.c162
-rw-r--r--source/blender/makesrna/intern/rna_object.c1323
-rw-r--r--source/blender/makesrna/intern/rna_object_api.c232
-rw-r--r--source/blender/makesrna/intern/rna_object_force.c229
-rw-r--r--source/blender/makesrna/intern/rna_particle.c175
-rw-r--r--source/blender/makesrna/intern/rna_pose.c83
-rw-r--r--source/blender/makesrna/intern/rna_property.c203
-rw-r--r--source/blender/makesrna/intern/rna_render.c81
-rw-r--r--source/blender/makesrna/intern/rna_rigidbody.c1
-rw-r--r--source/blender/makesrna/intern/rna_rna.c1238
-rw-r--r--source/blender/makesrna/intern/rna_scene.c2056
-rw-r--r--source/blender/makesrna/intern/rna_scene_api.c31
-rw-r--r--source/blender/makesrna/intern/rna_screen.c153
-rw-r--r--source/blender/makesrna/intern/rna_sculpt_paint.c99
-rw-r--r--source/blender/makesrna/intern/rna_sensor.c939
-rw-r--r--source/blender/makesrna/intern/rna_sensor_api.c79
-rw-r--r--source/blender/makesrna/intern/rna_smoke.c10
-rw-r--r--source/blender/makesrna/intern/rna_sound.c1
-rw-r--r--source/blender/makesrna/intern/rna_space.c1184
-rw-r--r--source/blender/makesrna/intern/rna_space_api.c26
-rw-r--r--source/blender/makesrna/intern/rna_speaker.c1
-rw-r--r--source/blender/makesrna/intern/rna_texture.c643
-rw-r--r--source/blender/makesrna/intern/rna_texture_api.c51
-rw-r--r--source/blender/makesrna/intern/rna_timeline.c2
-rw-r--r--source/blender/makesrna/intern/rna_tracking.c7
-rw-r--r--source/blender/makesrna/intern/rna_ui.c35
-rw-r--r--source/blender/makesrna/intern/rna_ui_api.c94
-rw-r--r--source/blender/makesrna/intern/rna_userdef.c337
-rw-r--r--source/blender/makesrna/intern/rna_vfont.c5
-rw-r--r--source/blender/makesrna/intern/rna_wm.c199
-rw-r--r--source/blender/makesrna/intern/rna_wm_api.c102
-rw-r--r--source/blender/makesrna/intern/rna_wm_manipulator.c1325
-rw-r--r--source/blender/makesrna/intern/rna_wm_manipulator_api.c290
-rw-r--r--source/blender/makesrna/intern/rna_workspace.c232
-rw-r--r--source/blender/makesrna/intern/rna_world.c320
-rw-r--r--source/blender/modifiers/CMakeLists.txt7
-rw-r--r--source/blender/modifiers/intern/MOD_armature.c83
-rw-r--r--source/blender/modifiers/intern/MOD_array.c220
-rw-r--r--source/blender/modifiers/intern/MOD_bevel.c37
-rw-r--r--source/blender/modifiers/intern/MOD_boolean.c41
-rw-r--r--source/blender/modifiers/intern/MOD_build.c94
-rw-r--r--source/blender/modifiers/intern/MOD_cast.c49
-rw-r--r--source/blender/modifiers/intern/MOD_cloth.c43
-rw-r--r--source/blender/modifiers/intern/MOD_collision.c18
-rw-r--r--source/blender/modifiers/intern/MOD_correctivesmooth.c28
-rw-r--r--source/blender/modifiers/intern/MOD_curve.c41
-rw-r--r--source/blender/modifiers/intern/MOD_datatransfer.c36
-rw-r--r--source/blender/modifiers/intern/MOD_decimate.c19
-rw-r--r--source/blender/modifiers/intern/MOD_displace.c51
-rw-r--r--source/blender/modifiers/intern/MOD_dynamicpaint.c62
-rw-r--r--source/blender/modifiers/intern/MOD_edgesplit.c49
-rw-r--r--source/blender/modifiers/intern/MOD_explode.c39
-rw-r--r--source/blender/modifiers/intern/MOD_fluidsim.c52
-rw-r--r--source/blender/modifiers/intern/MOD_hook.c49
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciandeform.c28
-rw-r--r--source/blender/modifiers/intern/MOD_laplaciansmooth.c28
-rw-r--r--source/blender/modifiers/intern/MOD_lattice.c55
-rw-r--r--source/blender/modifiers/intern/MOD_mask.c33
-rw-r--r--source/blender/modifiers/intern/MOD_meshcache.c25
-rw-r--r--source/blender/modifiers/intern/MOD_meshdeform.c52
-rw-r--r--source/blender/modifiers/intern/MOD_meshsequencecache.c83
-rw-r--r--source/blender/modifiers/intern/MOD_mirror.c145
-rw-r--r--source/blender/modifiers/intern/MOD_multires.c26
-rw-r--r--source/blender/modifiers/intern/MOD_none.c10
-rw-r--r--source/blender/modifiers/intern/MOD_normal_edit.c224
-rw-r--r--source/blender/modifiers/intern/MOD_ocean.c22
-rw-r--r--source/blender/modifiers/intern/MOD_particleinstance.c39
-rw-r--r--source/blender/modifiers/intern/MOD_particlesystem.c35
-rw-r--r--source/blender/modifiers/intern/MOD_remesh.c23
-rw-r--r--source/blender/modifiers/intern/MOD_screw.c36
-rw-r--r--source/blender/modifiers/intern/MOD_shapekey.c49
-rw-r--r--source/blender/modifiers/intern/MOD_shrinkwrap.c51
-rw-r--r--source/blender/modifiers/intern/MOD_simpledeform.c67
-rw-r--r--source/blender/modifiers/intern/MOD_skin.c115
-rw-r--r--source/blender/modifiers/intern/MOD_smoke.c44
-rw-r--r--source/blender/modifiers/intern/MOD_smooth.c28
-rw-r--r--source/blender/modifiers/intern/MOD_softbody.c38
-rw-r--r--source/blender/modifiers/intern/MOD_solidify.c139
-rw-r--r--source/blender/modifiers/intern/MOD_subsurf.c53
-rw-r--r--source/blender/modifiers/intern/MOD_surface.c23
-rw-r--r--source/blender/modifiers/intern/MOD_surfacedeform.c54
-rw-r--r--source/blender/modifiers/intern/MOD_triangulate.c17
-rw-r--r--source/blender/modifiers/intern/MOD_util.c31
-rw-r--r--source/blender/modifiers/intern/MOD_util.h5
-rw-r--r--source/blender/modifiers/intern/MOD_uvproject.c176
-rw-r--r--source/blender/modifiers/intern/MOD_uvwarp.c42
-rw-r--r--source/blender/modifiers/intern/MOD_warp.c46
-rw-r--r--source/blender/modifiers/intern/MOD_wave.c65
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgedit.c43
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgmix.c42
-rw-r--r--source/blender/modifiers/intern/MOD_weightvgproximity.c43
-rw-r--r--source/blender/modifiers/intern/MOD_wireframe.c37
-rw-r--r--source/blender/nodes/CMakeLists.txt7
-rw-r--r--source/blender/nodes/NOD_composite.h2
-rw-r--r--source/blender/nodes/NOD_shader.h9
-rw-r--r--source/blender/nodes/NOD_socket.h2
-rw-r--r--source/blender/nodes/NOD_static_types.h7
-rw-r--r--source/blender/nodes/composite/node_composite_tree.c4
-rw-r--r--source/blender/nodes/composite/nodes/node_composite_image.c15
-rw-r--r--source/blender/nodes/intern/node_exec.c2
-rw-r--r--source/blender/nodes/intern/node_socket.c2
-rw-r--r--source/blender/nodes/shader/node_shader_tree.c180
-rw-r--r--source/blender/nodes/shader/node_shader_util.c53
-rw-r--r--source/blender/nodes/shader/node_shader_util.h6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_add_shader.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_attribute.c24
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_background.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bevel.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_blackbody.c11
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_brightness.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c44
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_bump.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_camera.c23
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_curves.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_displacement.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_eevee_specular.c87
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_emission.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_fresnel.c33
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_gamma.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_geom.c163
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_geometry.c5
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_hueSatVal.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_invert.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_lamp.c91
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_layer_weight.c44
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_light_falloff.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_light_path.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mapping.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_material.c374
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_math.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mixRgb.c3
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_mix_shader.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_normal.c9
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_normal_map.c149
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_object_info.c11
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output.c97
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_material.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_output_world.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_particle_info.c9
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_rgb.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_squeeze.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c19
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tangent.c23
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_brick.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_checker.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_coord.c10
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_environment.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_gradient.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_image.c8
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_magic.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_noise.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_sky.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_tex_wave.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_texture.c166
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_uvmap.c2
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_valToRgb.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_value.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vectMath.c6
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vectTransform.c83
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_vector_displacement.c5
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_absorption.c4
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_principled.c84
-rw-r--r--source/blender/nodes/shader/nodes/node_shader_volume_scatter.c4
-rw-r--r--source/blender/nodes/texture/node_texture_tree.c42
-rw-r--r--source/blender/nodes/texture/node_texture_util.c1
-rw-r--r--source/blender/nodes/texture/node_texture_util.h2
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_proc.c2
-rw-r--r--source/blender/nodes/texture/nodes/node_texture_texture.c2
-rw-r--r--source/blender/physics/BPH_mass_spring.h2
-rw-r--r--source/blender/physics/intern/BPH_mass_spring.cpp21
-rw-r--r--source/blender/physics/intern/hair_volume.cpp53
-rw-r--r--source/blender/physics/intern/implicit.h2
-rw-r--r--source/blender/python/CMakeLists.txt1
-rw-r--r--source/blender/python/bmesh/CMakeLists.txt1
-rw-r--r--source/blender/python/bmesh/bmesh_py_api.c5
-rw-r--r--source/blender/python/bmesh/bmesh_py_types.c14
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_customdata.c21
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_meshdata.c91
-rw-r--r--source/blender/python/bmesh/bmesh_py_types_meshdata.h4
-rw-r--r--source/blender/python/gawain/CMakeLists.txt47
-rw-r--r--source/blender/python/gawain/gwn_py_api.c63
-rw-r--r--source/blender/python/gawain/gwn_py_api.h30
-rw-r--r--source/blender/python/gawain/gwn_py_types.c847
-rw-r--r--source/blender/python/gawain/gwn_py_types.h67
-rw-r--r--source/blender/python/generic/bgl.c1235
-rw-r--r--source/blender/python/generic/blf_py_api.c4
-rw-r--r--source/blender/python/generic/bpy_internal_import.c10
-rw-r--r--source/blender/python/generic/bpy_internal_import.h5
-rw-r--r--source/blender/python/generic/py_capi_utils.h2
-rw-r--r--source/blender/python/intern/CMakeLists.txt18
-rw-r--r--source/blender/python/intern/bpy.c8
-rw-r--r--source/blender/python/intern/bpy_app.c10
-rw-r--r--source/blender/python/intern/bpy_app_build_options.c14
-rw-r--r--source/blender/python/intern/bpy_app_handlers.c8
-rw-r--r--source/blender/python/intern/bpy_app_icons.c183
-rw-r--r--source/blender/python/intern/bpy_app_icons.h30
-rw-r--r--source/blender/python/intern/bpy_interface.c5
-rw-r--r--source/blender/python/intern/bpy_intern_string.c44
-rw-r--r--source/blender/python/intern/bpy_intern_string.h21
-rw-r--r--source/blender/python/intern/bpy_library_load.c11
-rw-r--r--source/blender/python/intern/bpy_manipulator_wrap.c236
-rw-r--r--source/blender/python/intern/bpy_manipulator_wrap.h36
-rw-r--r--source/blender/python/intern/bpy_msgbus.c400
-rw-r--r--source/blender/python/intern/bpy_msgbus.h30
-rw-r--r--source/blender/python/intern/bpy_props.h2
-rw-r--r--source/blender/python/intern/bpy_rna.c133
-rw-r--r--source/blender/python/intern/bpy_rna.h4
-rw-r--r--source/blender/python/intern/bpy_rna_callback.c2
-rw-r--r--source/blender/python/intern/bpy_rna_manipulator.c565
-rw-r--r--source/blender/python/intern/bpy_rna_manipulator.h32
-rw-r--r--source/blender/python/intern/gpu.c253
-rw-r--r--source/blender/python/intern/gpu.h2
-rw-r--r--source/blender/python/intern/gpu_offscreen.c33
-rw-r--r--source/blender/python/intern/gpu_py_matrix.c552
-rw-r--r--source/blender/python/intern/gpu_py_select.c92
-rw-r--r--source/blender/python/mathutils/mathutils.h2
-rw-r--r--source/blender/python/mathutils/mathutils_bvhtree.c7
-rw-r--r--source/blender/python/simple_enum_gen.py2
-rw-r--r--source/blender/render/CMakeLists.txt59
-rw-r--r--source/blender/render/extern/include/RE_bake.h6
-rw-r--r--source/blender/render/extern/include/RE_engine.h37
-rw-r--r--source/blender/render/extern/include/RE_multires_bake.h6
-rw-r--r--source/blender/render/extern/include/RE_pipeline.h68
-rw-r--r--source/blender/render/extern/include/RE_render_ext.h22
-rw-r--r--source/blender/render/extern/include/RE_shader_ext.h188
-rw-r--r--source/blender/render/intern/include/envmap.h54
-rw-r--r--source/blender/render/intern/include/initrender.h7
-rw-r--r--source/blender/render/intern/include/occlusion.h49
-rw-r--r--source/blender/render/intern/include/pixelblending.h65
-rw-r--r--source/blender/render/intern/include/pixelshading.h62
-rw-r--r--source/blender/render/intern/include/pointdensity.h51
-rw-r--r--source/blender/render/intern/include/raycounter.h74
-rw-r--r--source/blender/render/intern/include/rayintersection.h136
-rw-r--r--source/blender/render/intern/include/rayobject.h121
-rw-r--r--source/blender/render/intern/include/render_result.h25
-rw-r--r--source/blender/render/intern/include/render_types.h532
-rw-r--r--source/blender/render/intern/include/rendercore.h105
-rw-r--r--source/blender/render/intern/include/renderdatabase.h174
-rw-r--r--source/blender/render/intern/include/renderpipeline.h4
-rw-r--r--source/blender/render/intern/include/shadbuf.h112
-rw-r--r--source/blender/render/intern/include/shading.h105
-rw-r--r--source/blender/render/intern/include/sss.h67
-rw-r--r--source/blender/render/intern/include/strand.h99
-rw-r--r--source/blender/render/intern/include/sunsky.h81
-rw-r--r--source/blender/render/intern/include/texture.h17
-rw-r--r--source/blender/render/intern/include/texture_ocean.h35
-rw-r--r--source/blender/render/intern/include/volume_precache.h39
-rw-r--r--source/blender/render/intern/include/volumetric.h51
-rw-r--r--source/blender/render/intern/include/voxeldata.h47
-rw-r--r--source/blender/render/intern/include/zbuf.h101
-rw-r--r--source/blender/render/intern/raytrace/bvh.h407
-rw-r--r--source/blender/render/intern/raytrace/rayobject.cpp534
-rw-r--r--source/blender/render/intern/raytrace/rayobject_empty.cpp81
-rw-r--r--source/blender/render/intern/raytrace/rayobject_hint.h72
-rw-r--r--source/blender/render/intern/raytrace/rayobject_instance.cpp211
-rw-r--r--source/blender/render/intern/raytrace/rayobject_internal.h157
-rw-r--r--source/blender/render/intern/raytrace/rayobject_octree.cpp1101
-rw-r--r--source/blender/render/intern/raytrace/rayobject_qbvh.cpp160
-rw-r--r--source/blender/render/intern/raytrace/rayobject_raycounter.cpp91
-rw-r--r--source/blender/render/intern/raytrace/rayobject_rtbuild.cpp531
-rw-r--r--source/blender/render/intern/raytrace/rayobject_rtbuild.h125
-rw-r--r--source/blender/render/intern/raytrace/rayobject_svbvh.cpp192
-rw-r--r--source/blender/render/intern/raytrace/rayobject_vbvh.cpp206
-rw-r--r--source/blender/render/intern/raytrace/reorganize.h513
-rw-r--r--source/blender/render/intern/raytrace/svbvh.h317
-rw-r--r--source/blender/render/intern/raytrace/vbvh.h238
-rw-r--r--source/blender/render/intern/source/bake.c1342
-rw-r--r--source/blender/render/intern/source/bake_api.c70
-rw-r--r--source/blender/render/intern/source/convertblender.c6014
-rw-r--r--source/blender/render/intern/source/envmap.c822
-rw-r--r--source/blender/render/intern/source/external_engine.c243
-rw-r--r--source/blender/render/intern/source/imagetexture.c61
-rw-r--r--source/blender/render/intern/source/initrender.c338
-rw-r--r--source/blender/render/intern/source/multires_bake.c157
-rw-r--r--source/blender/render/intern/source/occlusion.c1533
-rw-r--r--source/blender/render/intern/source/pipeline.c1490
-rw-r--r--source/blender/render/intern/source/pixelblending.c400
-rw-r--r--source/blender/render/intern/source/pixelshading.c650
-rw-r--r--source/blender/render/intern/source/pointdensity.c191
-rw-r--r--source/blender/render/intern/source/rayshade.c2503
-rw-r--r--source/blender/render/intern/source/render_result.c128
-rw-r--r--source/blender/render/intern/source/render_texture.c2510
-rw-r--r--source/blender/render/intern/source/rendercore.c2030
-rw-r--r--source/blender/render/intern/source/renderdatabase.c1603
-rw-r--r--source/blender/render/intern/source/shadbuf.c2647
-rw-r--r--source/blender/render/intern/source/shadeinput.c1490
-rw-r--r--source/blender/render/intern/source/shadeoutput.c2182
-rw-r--r--source/blender/render/intern/source/sss.c1074
-rw-r--r--source/blender/render/intern/source/strand.c1069
-rw-r--r--source/blender/render/intern/source/sunsky.c506
-rw-r--r--source/blender/render/intern/source/texture_ocean.c160
-rw-r--r--source/blender/render/intern/source/volume_precache.c855
-rw-r--r--source/blender/render/intern/source/volumetric.c836
-rw-r--r--source/blender/render/intern/source/voxeldata.c571
-rw-r--r--source/blender/render/intern/source/zbuf.c3498
-rw-r--r--source/blender/windowmanager/CMakeLists.txt31
-rw-r--r--source/blender/windowmanager/WM_api.h92
-rw-r--r--source/blender/windowmanager/WM_message.h30
-rw-r--r--source/blender/windowmanager/WM_types.h28
-rw-r--r--source/blender/windowmanager/intern/wm.c53
-rw-r--r--source/blender/windowmanager/intern/wm_dragdrop.c18
-rw-r--r--source/blender/windowmanager/intern/wm_draw.c1117
-rw-r--r--source/blender/windowmanager/intern/wm_event_system.c524
-rw-r--r--source/blender/windowmanager/intern/wm_files.c319
-rw-r--r--source/blender/windowmanager/intern/wm_files_link.c99
-rw-r--r--source/blender/windowmanager/intern/wm_gesture.c305
-rw-r--r--source/blender/windowmanager/intern/wm_gesture_ops.c52
-rw-r--r--source/blender/windowmanager/intern/wm_init_exit.c208
-rw-r--r--source/blender/windowmanager/intern/wm_keymap.c20
-rw-r--r--source/blender/windowmanager/intern/wm_operators.c443
-rw-r--r--source/blender/windowmanager/intern/wm_playanim.c95
-rw-r--r--source/blender/windowmanager/intern/wm_stereo.c327
-rw-r--r--source/blender/windowmanager/intern/wm_subwindow.c349
-rw-r--r--source/blender/windowmanager/intern/wm_toolsystem.c161
-rw-r--r--source/blender/windowmanager/intern/wm_tooltip.c10
-rw-r--r--source/blender/windowmanager/intern/wm_window.c531
-rw-r--r--source/blender/windowmanager/manipulators/WM_manipulator_api.h336
-rw-r--r--source/blender/windowmanager/manipulators/WM_manipulator_types.h420
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator.c764
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c949
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_group_type.c198
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h142
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c1191
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c364
-rw-r--r--source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c212
-rw-r--r--source/blender/windowmanager/manipulators/wm_manipulator_fn.h88
-rw-r--r--source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h98
-rw-r--r--source/blender/windowmanager/message_bus/intern/wm_message_bus.c250
-rw-r--r--source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h55
-rw-r--r--source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c316
-rw-r--r--source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c136
-rw-r--r--source/blender/windowmanager/message_bus/wm_message_bus.h273
-rw-r--r--source/blender/windowmanager/wm.h11
-rw-r--r--source/blender/windowmanager/wm_draw.h30
-rw-r--r--source/blender/windowmanager/wm_event_system.h3
-rw-r--r--source/blender/windowmanager/wm_event_types.h2
-rw-r--r--source/blender/windowmanager/wm_files.h1
-rw-r--r--source/blender/windowmanager/wm_subwindow.h52
-rw-r--r--source/blender/windowmanager/wm_window.h15
-rw-r--r--source/blenderplayer/CMakeLists.txt265
-rw-r--r--source/blenderplayer/bad_level_call_stubs/CMakeLists.txt77
-rw-r--r--source/blenderplayer/bad_level_call_stubs/stubs.c765
-rw-r--r--source/creator/CMakeLists.txt80
-rw-r--r--source/creator/creator.c35
-rw-r--r--source/creator/creator_args.c164
-rw-r--r--source/creator/creator_intern.h2
-rw-r--r--source/creator/creator_signals.c7
-rw-r--r--source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp683
-rw-r--r--source/gameengine/BlenderRoutines/BL_System.cpp102
-rw-r--r--source/gameengine/BlenderRoutines/BL_System.h70
-rw-r--r--source/gameengine/BlenderRoutines/CMakeLists.txt78
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp353
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderCanvas.h222
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp33
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h80
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp169
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h62
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp192
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h58
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderSystem.cpp59
-rw-r--r--source/gameengine/BlenderRoutines/KX_BlenderSystem.h56
-rw-r--r--source/gameengine/CMakeLists.txt57
-rw-r--r--source/gameengine/Converter/BL_ActionActuator.cpp664
-rw-r--r--source/gameengine/Converter/BL_ActionActuator.h158
-rw-r--r--source/gameengine/Converter/BL_ArmatureActuator.cpp271
-rw-r--r--source/gameengine/Converter/BL_ArmatureActuator.h96
-rw-r--r--source/gameengine/Converter/BL_ArmatureChannel.cpp469
-rw-r--r--source/gameengine/Converter/BL_ArmatureChannel.h101
-rw-r--r--source/gameengine/Converter/BL_ArmatureConstraint.cpp456
-rw-r--r--source/gameengine/Converter/BL_ArmatureConstraint.h125
-rw-r--r--source/gameengine/Converter/BL_ArmatureObject.cpp687
-rw-r--r--source/gameengine/Converter/BL_ArmatureObject.h145
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.cpp2467
-rw-r--r--source/gameengine/Converter/BL_BlenderDataConversion.h56
-rw-r--r--source/gameengine/Converter/BL_DeformableGameObject.cpp116
-rw-r--r--source/gameengine/Converter/BL_DeformableGameObject.h107
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.cpp239
-rw-r--r--source/gameengine/Converter/BL_MeshDeformer.h98
-rw-r--r--source/gameengine/Converter/BL_ModifierDeformer.cpp219
-rw-r--r--source/gameengine/Converter/BL_ModifierDeformer.h115
-rw-r--r--source/gameengine/Converter/BL_ShapeActionActuator.cpp563
-rw-r--r--source/gameengine/Converter/BL_ShapeActionActuator.h144
-rw-r--r--source/gameengine/Converter/BL_ShapeDeformer.cpp237
-rw-r--r--source/gameengine/Converter/BL_ShapeDeformer.h86
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.cpp384
-rw-r--r--source/gameengine/Converter/BL_SkinDeformer.h125
-rw-r--r--source/gameengine/Converter/CMakeLists.txt123
-rw-r--r--source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp81
-rw-r--r--source/gameengine/Converter/KX_BlenderScalarInterpolator.h76
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.cpp1477
-rw-r--r--source/gameengine/Converter/KX_BlenderSceneConverter.h232
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.cpp1146
-rw-r--r--source/gameengine/Converter/KX_ConvertActuators.h45
-rw-r--r--source/gameengine/Converter/KX_ConvertControllers.cpp250
-rw-r--r--source/gameengine/Converter/KX_ConvertControllers.h47
-rw-r--r--source/gameengine/Converter/KX_ConvertProperties.cpp243
-rw-r--r--source/gameengine/Converter/KX_ConvertProperties.h41
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.cpp663
-rw-r--r--source/gameengine/Converter/KX_ConvertSensors.h45
-rw-r--r--source/gameengine/Converter/KX_LibLoadStatus.cpp255
-rw-r--r--source/gameengine/Converter/KX_LibLoadStatus.h93
-rw-r--r--source/gameengine/Converter/KX_SoftBodyDeformer.cpp121
-rw-r--r--source/gameengine/Converter/KX_SoftBodyDeformer.h102
-rw-r--r--source/gameengine/Expressions/CMakeLists.txt91
-rw-r--r--source/gameengine/Expressions/EXP_BoolValue.h65
-rw-r--r--source/gameengine/Expressions/EXP_ConstExpr.h54
-rw-r--r--source/gameengine/Expressions/EXP_EmptyValue.h49
-rw-r--r--source/gameengine/Expressions/EXP_ErrorValue.h47
-rw-r--r--source/gameengine/Expressions/EXP_Expression.h149
-rw-r--r--source/gameengine/Expressions/EXP_FloatValue.h58
-rw-r--r--source/gameengine/Expressions/EXP_HashedPtr.h59
-rw-r--r--source/gameengine/Expressions/EXP_IdentifierExpr.h59
-rw-r--r--source/gameengine/Expressions/EXP_IfExpr.h54
-rw-r--r--source/gameengine/Expressions/EXP_InputParser.h118
-rw-r--r--source/gameengine/Expressions/EXP_IntValue.h73
-rw-r--r--source/gameengine/Expressions/EXP_ListValue.h92
-rw-r--r--source/gameengine/Expressions/EXP_ListWrapper.h109
-rw-r--r--source/gameengine/Expressions/EXP_Operator1Expr.h59
-rw-r--r--source/gameengine/Expressions/EXP_Operator2Expr.h66
-rw-r--r--source/gameengine/Expressions/EXP_PyObjectPlus.h648
-rw-r--r--source/gameengine/Expressions/EXP_Python.h82
-rw-r--r--source/gameengine/Expressions/EXP_PythonCallBack.h40
-rw-r--r--source/gameengine/Expressions/EXP_StringValue.h61
-rw-r--r--source/gameengine/Expressions/EXP_Value.h432
-rw-r--r--source/gameengine/Expressions/EXP_VectorValue.h94
-rw-r--r--source/gameengine/Expressions/EXP_VoidValue.h81
-rw-r--r--source/gameengine/Expressions/intern/BoolValue.cpp216
-rw-r--r--source/gameengine/Expressions/intern/ConstExpr.cpp131
-rw-r--r--source/gameengine/Expressions/intern/EmptyValue.cpp133
-rw-r--r--source/gameengine/Expressions/intern/ErrorValue.cpp131
-rw-r--r--source/gameengine/Expressions/intern/Expression.cpp77
-rw-r--r--source/gameengine/Expressions/intern/FloatValue.cpp329
-rw-r--r--source/gameengine/Expressions/intern/HashedPtr.cpp57
-rw-r--r--source/gameengine/Expressions/intern/IdentifierExpr.cpp103
-rw-r--r--source/gameengine/Expressions/intern/IfExpr.cpp144
-rw-r--r--source/gameengine/Expressions/intern/InputParser.cpp669
-rw-r--r--source/gameengine/Expressions/intern/IntValue.cpp344
-rw-r--r--source/gameengine/Expressions/intern/ListValue.cpp702
-rw-r--r--source/gameengine/Expressions/intern/ListWrapper.cpp424
-rw-r--r--source/gameengine/Expressions/intern/Operator1Expr.cpp151
-rw-r--r--source/gameengine/Expressions/intern/Operator2Expr.cpp276
-rw-r--r--source/gameengine/Expressions/intern/PyObjectPlus.cpp1226
-rw-r--r--source/gameengine/Expressions/intern/PythonCallBack.cpp119
-rw-r--r--source/gameengine/Expressions/intern/StringValue.cpp147
-rw-r--r--source/gameengine/Expressions/intern/Value.cpp672
-rw-r--r--source/gameengine/Expressions/intern/VectorValue.cpp225
-rw-r--r--source/gameengine/GameLogic/CMakeLists.txt147
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp382
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_Joystick.h214
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h56
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp137
-rw-r--r--source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h52
-rw-r--r--source/gameengine/GameLogic/SCA_2DFilterActuator.cpp153
-rw-r--r--source/gameengine/GameLogic/SCA_2DFilterActuator.h71
-rw-r--r--source/gameengine/GameLogic/SCA_ANDController.cpp131
-rw-r--r--source/gameengine/GameLogic/SCA_ANDController.h51
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp68
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorEventManager.h56
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorSensor.cpp171
-rw-r--r--source/gameengine/GameLogic/SCA_ActuatorSensor.h70
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp59
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysEventManager.h50
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysSensor.cpp139
-rw-r--r--source/gameengine/GameLogic/SCA_AlwaysSensor.h53
-rw-r--r--source/gameengine/GameLogic/SCA_BasicEventManager.cpp61
-rw-r--r--source/gameengine/GameLogic/SCA_BasicEventManager.h57
-rw-r--r--source/gameengine/GameLogic/SCA_DelaySensor.cpp170
-rw-r--r--source/gameengine/GameLogic/SCA_DelaySensor.h66
-rw-r--r--source/gameengine/GameLogic/SCA_EventManager.cpp83
-rw-r--r--source/gameengine/GameLogic/SCA_EventManager.h91
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.cpp159
-rw-r--r--source/gameengine/GameLogic/SCA_ExpressionController.h66
-rw-r--r--source/gameengine/GameLogic/SCA_IActuator.cpp140
-rw-r--r--source/gameengine/GameLogic/SCA_IActuator.h168
-rw-r--r--source/gameengine/GameLogic/SCA_IController.cpp298
-rw-r--r--source/gameengine/GameLogic/SCA_IController.h112
-rw-r--r--source/gameengine/GameLogic/SCA_IInputDevice.cpp139
-rw-r--r--source/gameengine/GameLogic/SCA_IInputDevice.h334
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.cpp271
-rw-r--r--source/gameengine/GameLogic/SCA_ILogicBrick.h167
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.cpp349
-rw-r--r--source/gameengine/GameLogic/SCA_IObject.h229
-rw-r--r--source/gameengine/GameLogic/SCA_IScene.cpp145
-rw-r--r--source/gameengine/GameLogic/SCA_IScene.h87
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.cpp471
-rw-r--r--source/gameengine/GameLogic/SCA_ISensor.h220
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickManager.cpp92
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickManager.h59
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.cpp428
-rw-r--r--source/gameengine/GameLogic/SCA_JoystickSensor.h168
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardManager.cpp80
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardManager.h66
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.cpp668
-rw-r--r--source/gameengine/GameLogic/SCA_KeyboardSensor.h141
-rw-r--r--source/gameengine/GameLogic/SCA_LogicManager.cpp342
-rw-r--r--source/gameengine/GameLogic/SCA_LogicManager.h154
-rw-r--r--source/gameengine/GameLogic/SCA_MouseManager.cpp112
-rw-r--r--source/gameengine/GameLogic/SCA_MouseManager.h75
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.cpp317
-rw-r--r--source/gameengine/GameLogic/SCA_MouseSensor.h120
-rw-r--r--source/gameengine/GameLogic/SCA_NANDController.cpp133
-rw-r--r--source/gameengine/GameLogic/SCA_NANDController.h52
-rw-r--r--source/gameengine/GameLogic/SCA_NORController.cpp133
-rw-r--r--source/gameengine/GameLogic/SCA_NORController.h48
-rw-r--r--source/gameengine/GameLogic/SCA_ORController.cpp129
-rw-r--r--source/gameengine/GameLogic/SCA_ORController.h49
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyActuator.cpp293
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyActuator.h90
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyEventManager.cpp57
-rw-r--r--source/gameengine/GameLogic/SCA_PropertyEventManager.h55
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.cpp332
-rw-r--r--source/gameengine/GameLogic/SCA_PropertySensor.h98
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.cpp539
-rw-r--r--source/gameengine/GameLogic/SCA_PythonController.h118
-rw-r--r--source/gameengine/GameLogic/SCA_PythonJoystick.cpp188
-rw-r--r--source/gameengine/GameLogic/SCA_PythonJoystick.h56
-rw-r--r--source/gameengine/GameLogic/SCA_PythonKeyboard.cpp153
-rw-r--r--source/gameengine/GameLogic/SCA_PythonKeyboard.h50
-rw-r--r--source/gameengine/GameLogic/SCA_PythonMouse.cpp206
-rw-r--r--source/gameengine/GameLogic/SCA_PythonMouse.h59
-rw-r--r--source/gameengine/GameLogic/SCA_RandomActuator.cpp543
-rw-r--r--source/gameengine/GameLogic/SCA_RandomActuator.h120
-rw-r--r--source/gameengine/GameLogic/SCA_RandomEventManager.cpp58
-rw-r--r--source/gameengine/GameLogic/SCA_RandomEventManager.h54
-rw-r--r--source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp133
-rw-r--r--source/gameengine/GameLogic/SCA_RandomNumberGenerator.h85
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.cpp187
-rw-r--r--source/gameengine/GameLogic/SCA_RandomSensor.h71
-rw-r--r--source/gameengine/GameLogic/SCA_TimeEventManager.cpp120
-rw-r--r--source/gameengine/GameLogic/SCA_TimeEventManager.h62
-rw-r--r--source/gameengine/GameLogic/SCA_XNORController.cpp137
-rw-r--r--source/gameengine/GameLogic/SCA_XNORController.h53
-rw-r--r--source/gameengine/GameLogic/SCA_XORController.cpp136
-rw-r--r--source/gameengine/GameLogic/SCA_XORController.h48
-rw-r--r--source/gameengine/GamePlayer/CMakeLists.txt27
-rw-r--r--source/gameengine/GamePlayer/common/CMakeLists.txt75
-rw-r--r--source/gameengine/GamePlayer/common/GPC_Canvas.cpp168
-rw-r--r--source/gameengine/GamePlayer/common/GPC_Canvas.h147
-rw-r--r--source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp128
-rw-r--r--source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h90
-rw-r--r--source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp214
-rw-r--r--source/gameengine/GamePlayer/common/GPC_MouseDevice.h103
-rw-r--r--source/gameengine/GamePlayer/ghost/CMakeLists.txt111
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.cpp998
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Application.h181
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp177
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_Canvas.h76
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp165
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h56
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_System.cpp53
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_System.h54
-rw-r--r--source/gameengine/GamePlayer/ghost/GPG_ghost.cpp1227
-rw-r--r--source/gameengine/Ketsji/BL_Action.cpp534
-rw-r--r--source/gameengine/Ketsji/BL_Action.h151
-rw-r--r--source/gameengine/Ketsji/BL_ActionManager.cpp164
-rw-r--r--source/gameengine/Ketsji/BL_ActionManager.h132
-rw-r--r--source/gameengine/Ketsji/BL_BlenderShader.cpp188
-rw-r--r--source/gameengine/Ketsji/BL_BlenderShader.h96
-rw-r--r--source/gameengine/Ketsji/BL_Material.cpp124
-rw-r--r--source/gameengine/Ketsji/BL_Material.h183
-rw-r--r--source/gameengine/Ketsji/BL_Shader.cpp1478
-rw-r--r--source/gameengine/Ketsji/BL_Shader.h241
-rw-r--r--source/gameengine/Ketsji/BL_Texture.cpp759
-rw-r--r--source/gameengine/Ketsji/BL_Texture.h82
-rw-r--r--source/gameengine/Ketsji/CMakeLists.txt265
-rw-r--r--source/gameengine/Ketsji/KXNetwork/CMakeLists.txt56
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp77
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h55
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp139
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h72
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp224
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h90
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.cpp31
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.h32
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.cpp32
-rw-r--r--source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.h32
-rw-r--r--source/gameengine/Ketsji/KX_ArmatureSensor.cpp208
-rw-r--r--source/gameengine/Ketsji/KX_ArmatureSensor.h90
-rw-r--r--source/gameengine/Ketsji/KX_BlenderMaterial.cpp1345
-rw-r--r--source/gameengine/Ketsji/KX_BlenderMaterial.h201
-rw-r--r--source/gameengine/Ketsji/KX_Camera.cpp1167
-rw-r--r--source/gameengine/Ketsji/KX_Camera.h334
-rw-r--r--source/gameengine/Ketsji/KX_CameraActuator.cpp428
-rw-r--r--source/gameengine/Ketsji/KX_CameraActuator.h138
-rw-r--r--source/gameengine/Ketsji/KX_CameraIpoSGController.cpp126
-rw-r--r--source/gameengine/Ketsji/KX_CameraIpoSGController.h97
-rw-r--r--source/gameengine/Ketsji/KX_CharacterWrapper.cpp167
-rw-r--r--source/gameengine/Ketsji/KX_CharacterWrapper.h40
-rw-r--r--source/gameengine/Ketsji/KX_ClientObjectInfo.h84
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintActuator.cpp629
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintActuator.h152
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.cpp133
-rw-r--r--source/gameengine/Ketsji/KX_ConstraintWrapper.h61
-rw-r--r--source/gameengine/Ketsji/KX_Dome.cpp2051
-rw-r--r--source/gameengine/Ketsji/KX_Dome.h197
-rw-r--r--source/gameengine/Ketsji/KX_EmptyObject.cpp37
-rw-r--r--source/gameengine/Ketsji/KX_EmptyObject.h50
-rw-r--r--source/gameengine/Ketsji/KX_FontObject.cpp300
-rw-r--r--source/gameengine/Ketsji/KX_FontObject.h81
-rw-r--r--source/gameengine/Ketsji/KX_GameActuator.cpp267
-rw-r--r--source/gameengine/Ketsji/KX_GameActuator.h91
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.cpp4203
-rw-r--r--source/gameengine/Ketsji/KX_GameObject.h1142
-rw-r--r--source/gameengine/Ketsji/KX_IInterpolator.h56
-rw-r--r--source/gameengine/Ketsji/KX_IPOTransform.h87
-rw-r--r--source/gameengine/Ketsji/KX_IPO_SGController.cpp373
-rw-r--r--source/gameengine/Ketsji/KX_IPO_SGController.h124
-rw-r--r--source/gameengine/Ketsji/KX_IScalarInterpolator.h52
-rw-r--r--source/gameengine/Ketsji/KX_ISceneConverter.h103
-rw-r--r--source/gameengine/Ketsji/KX_ISystem.h63
-rw-r--r--source/gameengine/Ketsji/KX_IpoConvert.cpp441
-rw-r--r--source/gameengine/Ketsji/KX_IpoConvert.h69
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.cpp2081
-rw-r--r--source/gameengine/Ketsji/KX_KetsjiEngine.h553
-rw-r--r--source/gameengine/Ketsji/KX_Light.cpp488
-rw-r--r--source/gameengine/Ketsji/KX_Light.h101
-rw-r--r--source/gameengine/Ketsji/KX_LightIpoSGController.cpp122
-rw-r--r--source/gameengine/Ketsji/KX_LightIpoSGController.h105
-rw-r--r--source/gameengine/Ketsji/KX_MaterialIpoController.cpp105
-rw-r--r--source/gameengine/Ketsji/KX_MaterialIpoController.h65
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.cpp464
-rw-r--r--source/gameengine/Ketsji/KX_MeshProxy.h85
-rw-r--r--source/gameengine/Ketsji/KX_MotionState.cpp106
-rw-r--r--source/gameengine/Ketsji/KX_MotionState.h65
-rw-r--r--source/gameengine/Ketsji/KX_MouseActuator.cpp539
-rw-r--r--source/gameengine/Ketsji/KX_MouseActuator.h132
-rw-r--r--source/gameengine/Ketsji/KX_MouseFocusSensor.cpp520
-rw-r--r--source/gameengine/Ketsji/KX_MouseFocusSensor.h208
-rw-r--r--source/gameengine/Ketsji/KX_NavMeshObject.cpp743
-rw-r--r--source/gameengine/Ketsji/KX_NavMeshObject.h80
-rw-r--r--source/gameengine/Ketsji/KX_NearSensor.cpp292
-rw-r--r--source/gameengine/Ketsji/KX_NearSensor.h107
-rw-r--r--source/gameengine/Ketsji/KX_ObColorIpoSGController.cpp110
-rw-r--r--source/gameengine/Ketsji/KX_ObColorIpoSGController.h80
-rw-r--r--source/gameengine/Ketsji/KX_ObjectActuator.cpp709
-rw-r--r--source/gameengine/Ketsji/KX_ObjectActuator.h234
-rw-r--r--source/gameengine/Ketsji/KX_ObstacleSimulation.cpp832
-rw-r--r--source/gameengine/Ketsji/KX_ObstacleSimulation.h134
-rw-r--r--source/gameengine/Ketsji/KX_OrientationInterpolator.cpp56
-rw-r--r--source/gameengine/Ketsji/KX_OrientationInterpolator.h64
-rw-r--r--source/gameengine/Ketsji/KX_ParentActuator.cpp205
-rw-r--r--source/gameengine/Ketsji/KX_ParentActuator.h91
-rw-r--r--source/gameengine/Ketsji/KX_PhysicsEngineEnums.h42
-rw-r--r--source/gameengine/Ketsji/KX_PolyProxy.cpp266
-rw-r--r--source/gameengine/Ketsji/KX_PolyProxy.h85
-rw-r--r--source/gameengine/Ketsji/KX_PositionInterpolator.cpp42
-rw-r--r--source/gameengine/Ketsji/KX_PositionInterpolator.h64
-rw-r--r--source/gameengine/Ketsji/KX_PyConstraintBinding.cpp750
-rw-r--r--source/gameengine/Ketsji/KX_PyConstraintBinding.h45
-rw-r--r--source/gameengine/Ketsji/KX_PyMath.cpp215
-rw-r--r--source/gameengine/Ketsji/KX_PyMath.h281
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.cpp2953
-rw-r--r--source/gameengine/Ketsji/KX_PythonInit.h95
-rw-r--r--source/gameengine/Ketsji/KX_PythonInitTypes.cpp286
-rw-r--r--source/gameengine/Ketsji/KX_PythonInitTypes.h40
-rw-r--r--source/gameengine/Ketsji/KX_PythonMain.cpp71
-rw-r--r--source/gameengine/Ketsji/KX_PythonMain.h41
-rw-r--r--source/gameengine/Ketsji/KX_RadarSensor.cpp230
-rw-r--r--source/gameengine/Ketsji/KX_RadarSensor.h100
-rw-r--r--source/gameengine/Ketsji/KX_RayCast.cpp121
-rw-r--r--source/gameengine/Ketsji/KX_RayCast.h149
-rw-r--r--source/gameengine/Ketsji/KX_RayEventManager.cpp53
-rw-r--r--source/gameengine/Ketsji/KX_RayEventManager.h53
-rw-r--r--source/gameengine/Ketsji/KX_RaySensor.cpp383
-rw-r--r--source/gameengine/Ketsji/KX_RaySensor.h109
-rw-r--r--source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp284
-rw-r--r--source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h133
-rw-r--r--source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp160
-rw-r--r--source/gameengine/Ketsji/KX_SCA_DynamicActuator.h76
-rw-r--r--source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp125
-rw-r--r--source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h74
-rw-r--r--source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp182
-rw-r--r--source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h96
-rw-r--r--source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp155
-rw-r--r--source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h96
-rw-r--r--source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp298
-rw-r--r--source/gameengine/Ketsji/KX_SG_NodeRelationships.h231
-rw-r--r--source/gameengine/Ketsji/KX_ScalarInterpolator.cpp39
-rw-r--r--source/gameengine/Ketsji/KX_ScalarInterpolator.h69
-rw-r--r--source/gameengine/Ketsji/KX_ScalingInterpolator.cpp42
-rw-r--r--source/gameengine/Ketsji/KX_ScalingInterpolator.h64
-rw-r--r--source/gameengine/Ketsji/KX_Scene.cpp2644
-rw-r--r--source/gameengine/Ketsji/KX_Scene.h697
-rw-r--r--source/gameengine/Ketsji/KX_SceneActuator.cpp292
-rw-r--r--source/gameengine/Ketsji/KX_SceneActuator.h109
-rw-r--r--source/gameengine/Ketsji/KX_SoundActuator.cpp573
-rw-r--r--source/gameengine/Ketsji/KX_SoundActuator.h127
-rw-r--r--source/gameengine/Ketsji/KX_StateActuator.cpp171
-rw-r--r--source/gameengine/Ketsji/KX_StateActuator.h97
-rw-r--r--source/gameengine/Ketsji/KX_SteeringActuator.cpp639
-rw-r--r--source/gameengine/Ketsji/KX_SteeringActuator.h123
-rw-r--r--source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp141
-rw-r--r--source/gameengine/Ketsji/KX_TimeCategoryLogger.h136
-rw-r--r--source/gameengine/Ketsji/KX_TimeLogger.cpp117
-rw-r--r--source/gameengine/Ketsji/KX_TimeLogger.h114
-rw-r--r--source/gameengine/Ketsji/KX_TouchEventManager.cpp246
-rw-r--r--source/gameengine/Ketsji/KX_TouchEventManager.h109
-rw-r--r--source/gameengine/Ketsji/KX_TouchSensor.cpp362
-rw-r--r--source/gameengine/Ketsji/KX_TouchSensor.h138
-rw-r--r--source/gameengine/Ketsji/KX_TrackToActuator.cpp430
-rw-r--r--source/gameengine/Ketsji/KX_TrackToActuator.h98
-rw-r--r--source/gameengine/Ketsji/KX_VehicleWrapper.cpp380
-rw-r--r--source/gameengine/Ketsji/KX_VehicleWrapper.h61
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.cpp595
-rw-r--r--source/gameengine/Ketsji/KX_VertexProxy.h112
-rw-r--r--source/gameengine/Ketsji/KX_VisibilityActuator.cpp127
-rw-r--r--source/gameengine/Ketsji/KX_VisibilityActuator.h75
-rw-r--r--source/gameengine/Ketsji/KX_WorldInfo.cpp494
-rw-r--r--source/gameengine/Ketsji/KX_WorldInfo.h105
-rw-r--r--source/gameengine/Ketsji/KX_WorldIpoController.cpp125
-rw-r--r--source/gameengine/Ketsji/KX_WorldIpoController.h117
-rw-r--r--source/gameengine/Network/CMakeLists.txt48
-rw-r--r--source/gameengine/Network/LoopBackNetwork/CMakeLists.txt43
-rw-r--r--source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp112
-rw-r--r--source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.h63
-rw-r--r--source/gameengine/Network/NG_NetworkDeviceInterface.h82
-rw-r--r--source/gameengine/Network/NG_NetworkMessage.cpp55
-rw-r--r--source/gameengine/Network/NG_NetworkMessage.h138
-rw-r--r--source/gameengine/Network/NG_NetworkObject.cpp46
-rw-r--r--source/gameengine/Network/NG_NetworkObject.h55
-rw-r--r--source/gameengine/Network/NG_NetworkScene.cpp272
-rw-r--r--source/gameengine/Network/NG_NetworkScene.h118
-rw-r--r--source/gameengine/Physics/Bullet/CMakeLists.txt73
-rw-r--r--source/gameengine/Physics/Bullet/CcdGraphicController.cpp152
-rw-r--r--source/gameengine/Physics/Bullet/CcdGraphicController.h90
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.cpp2664
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsController.h832
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp3795
-rw-r--r--source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h345
-rw-r--r--source/gameengine/Physics/Dummy/CMakeLists.txt41
-rw-r--r--source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp121
-rw-r--r--source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h134
-rw-r--r--source/gameengine/Physics/common/PHY_DynamicTypes.h91
-rw-r--r--source/gameengine/Physics/common/PHY_ICharacter.h39
-rw-r--r--source/gameengine/Physics/common/PHY_IController.h63
-rw-r--r--source/gameengine/Physics/common/PHY_IGraphicController.h60
-rw-r--r--source/gameengine/Physics/common/PHY_IMotionState.h68
-rw-r--r--source/gameengine/Physics/common/PHY_IPhysicsController.h154
-rw-r--r--source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h226
-rw-r--r--source/gameengine/Physics/common/PHY_IVehicle.h69
-rw-r--r--source/gameengine/Physics/common/PHY_Pro.h68
-rw-r--r--source/gameengine/Rasterizer/CMakeLists.txt92
-rw-r--r--source/gameengine/Rasterizer/RAS_2DFilterManager.cpp562
-rw-r--r--source/gameengine/Rasterizer/RAS_2DFilterManager.h114
-rw-r--r--source/gameengine/Rasterizer/RAS_BucketManager.cpp380
-rw-r--r--source/gameengine/Rasterizer/RAS_BucketManager.h93
-rw-r--r--source/gameengine/Rasterizer/RAS_CameraData.h79
-rw-r--r--source/gameengine/Rasterizer/RAS_Deformer.h103
-rw-r--r--source/gameengine/Rasterizer/RAS_FramingManager.cpp425
-rw-r--r--source/gameengine/Rasterizer/RAS_FramingManager.h316
-rw-r--r--source/gameengine/Rasterizer/RAS_ICanvas.cpp128
-rw-r--r--source/gameengine/Rasterizer/RAS_ICanvas.h287
-rw-r--r--source/gameengine/Rasterizer/RAS_ILightObject.h95
-rw-r--r--source/gameengine/Rasterizer/RAS_IOffScreen.h84
-rw-r--r--source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp296
-rw-r--r--source/gameengine/Rasterizer/RAS_IPolygonMaterial.h208
-rw-r--r--source/gameengine/Rasterizer/RAS_IRasterizer.h506
-rw-r--r--source/gameengine/Rasterizer/RAS_ISync.h48
-rw-r--r--source/gameengine/Rasterizer/RAS_MaterialBucket.cpp679
-rw-r--r--source/gameengine/Rasterizer/RAS_MaterialBucket.h267
-rw-r--r--source/gameengine/Rasterizer/RAS_MeshObject.cpp573
-rw-r--r--source/gameengine/Rasterizer/RAS_MeshObject.h161
-rw-r--r--source/gameengine/Rasterizer/RAS_ObjectColor.h41
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h55
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h55
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h54
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h45
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h45
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h57
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h62
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h45
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h55
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h61
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt72
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_IStorage.h56
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp278
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h77
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp299
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.h56
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp347
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h65
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp1723
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h343
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp82
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h50
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp260
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h77
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp227
-rw-r--r--source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h100
-rw-r--r--source/gameengine/Rasterizer/RAS_Polygon.cpp123
-rw-r--r--source/gameengine/Rasterizer/RAS_Polygon.h101
-rw-r--r--source/gameengine/Rasterizer/RAS_Rect.h104
-rw-r--r--source/gameengine/Rasterizer/RAS_TexMatrix.h42
-rw-r--r--source/gameengine/Rasterizer/RAS_TexVert.cpp164
-rw-r--r--source/gameengine/Rasterizer/RAS_TexVert.h146
-rw-r--r--source/gameengine/Rasterizer/RAS_texmatrix.cpp131
-rw-r--r--source/gameengine/SceneGraph/CMakeLists.txt53
-rw-r--r--source/gameengine/SceneGraph/SG_BBox.cpp262
-rw-r--r--source/gameengine/SceneGraph/SG_BBox.h143
-rw-r--r--source/gameengine/SceneGraph/SG_Controller.cpp46
-rw-r--r--source/gameengine/SceneGraph/SG_Controller.h124
-rw-r--r--source/gameengine/SceneGraph/SG_DList.h251
-rw-r--r--source/gameengine/SceneGraph/SG_IObject.cpp111
-rw-r--r--source/gameengine/SceneGraph/SG_IObject.h374
-rw-r--r--source/gameengine/SceneGraph/SG_Node.cpp227
-rw-r--r--source/gameengine/SceneGraph/SG_Node.h278
-rw-r--r--source/gameengine/SceneGraph/SG_ParentRelation.h139
-rw-r--r--source/gameengine/SceneGraph/SG_QList.h164
-rw-r--r--source/gameengine/SceneGraph/SG_Spatial.cpp217
-rw-r--r--source/gameengine/SceneGraph/SG_Spatial.h294
-rw-r--r--source/gameengine/SceneGraph/SG_Tree.cpp422
-rw-r--r--source/gameengine/SceneGraph/SG_Tree.h163
-rw-r--r--source/gameengine/VideoTexture/BlendType.h86
-rw-r--r--source/gameengine/VideoTexture/CMakeLists.txt119
-rw-r--r--source/gameengine/VideoTexture/Common.h64
-rw-r--r--source/gameengine/VideoTexture/DeckLink.cpp813
-rw-r--r--source/gameengine/VideoTexture/DeckLink.h86
-rw-r--r--source/gameengine/VideoTexture/Exception.cpp241
-rw-r--r--source/gameengine/VideoTexture/Exception.h239
-rw-r--r--source/gameengine/VideoTexture/FilterBase.cpp160
-rw-r--r--source/gameengine/VideoTexture/FilterBase.h161
-rw-r--r--source/gameengine/VideoTexture/FilterBlueScreen.cpp190
-rw-r--r--source/gameengine/VideoTexture/FilterBlueScreen.h105
-rw-r--r--source/gameengine/VideoTexture/FilterColor.cpp354
-rw-r--r--source/gameengine/VideoTexture/FilterColor.h176
-rw-r--r--source/gameengine/VideoTexture/FilterNormal.cpp173
-rw-r--r--source/gameengine/VideoTexture/FilterNormal.h115
-rw-r--r--source/gameengine/VideoTexture/FilterSource.cpp176
-rw-r--r--source/gameengine/VideoTexture/FilterSource.h352
-rw-r--r--source/gameengine/VideoTexture/ImageBase.cpp834
-rw-r--r--source/gameengine/VideoTexture/ImageBase.h392
-rw-r--r--source/gameengine/VideoTexture/ImageBuff.cpp424
-rw-r--r--source/gameengine/VideoTexture/ImageBuff.h69
-rw-r--r--source/gameengine/VideoTexture/ImageMix.cpp216
-rw-r--r--source/gameengine/VideoTexture/ImageMix.h131
-rw-r--r--source/gameengine/VideoTexture/ImageRender.cpp946
-rw-r--r--source/gameengine/VideoTexture/ImageRender.h125
-rw-r--r--source/gameengine/VideoTexture/ImageViewport.cpp467
-rw-r--r--source/gameengine/VideoTexture/ImageViewport.h113
-rw-r--r--source/gameengine/VideoTexture/PyTypeList.cpp97
-rw-r--r--source/gameengine/VideoTexture/PyTypeList.h100
-rw-r--r--source/gameengine/VideoTexture/Texture.cpp533
-rw-r--r--source/gameengine/VideoTexture/Texture.h99
-rw-r--r--source/gameengine/VideoTexture/VideoBase.cpp254
-rw-r--r--source/gameengine/VideoTexture/VideoBase.h207
-rw-r--r--source/gameengine/VideoTexture/VideoDeckLink.cpp1228
-rw-r--r--source/gameengine/VideoTexture/VideoDeckLink.h256
-rw-r--r--source/gameengine/VideoTexture/VideoFFmpeg.cpp1392
-rw-r--r--source/gameengine/VideoTexture/VideoFFmpeg.h219
-rw-r--r--source/gameengine/VideoTexture/blendVideoTex.cpp266
m---------source/tools0
2113 files changed, 182103 insertions, 294947 deletions
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
index c696719e650..f9260ecebc5 100644
--- a/source/CMakeLists.txt
+++ b/source/CMakeLists.txt
@@ -23,9 +23,9 @@
#
# ***** END GPL LICENSE BLOCK *****
-add_subdirectory(blender)
-
-if(WITH_GAMEENGINE)
- add_subdirectory(gameengine)
+if(WITH_LEGACY_OPENGL)
+ add_definitions(-DWITH_LEGACY_OPENGL)
endif()
+add_subdirectory(blender)
+
diff --git a/source/blender/CMakeLists.txt b/source/blender/CMakeLists.txt
index 690e1bcf318..5709ac723f4 100644
--- a/source/blender/CMakeLists.txt
+++ b/source/blender/CMakeLists.txt
@@ -26,7 +26,6 @@
set(SRC_DNA_INC
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_ID.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_action_types.h
- ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_actuator_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_anim_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_armature_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_boid_types.h
@@ -36,7 +35,6 @@ set(SRC_DNA_INC
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_cloth_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_color_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_constraint_types.h
- ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_controller_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_curve_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_customdata_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_defs.h
@@ -54,6 +52,8 @@ set(SRC_DNA_INC
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_key_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_lamp_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_lattice_types.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_layer_types.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_lightprobe_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_linestyle_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_listBase.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_material_types.h
@@ -70,12 +70,10 @@ set(SRC_DNA_INC
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_outliner_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_packedFile_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_particle_types.h
- ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_property_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_rigidbody_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_scene_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_screen_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_sdna_types.h
- ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_sensor_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_sequence_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_smoke_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_sound_types.h
@@ -89,6 +87,7 @@ set(SRC_DNA_INC
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view2d_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_view3d_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_windowmanager_types.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_workspace_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_world_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_movieclip_types.h
${CMAKE_CURRENT_SOURCE_DIR}/makesdna/DNA_tracking_types.h
@@ -101,6 +100,7 @@ add_subdirectory(windowmanager)
add_subdirectory(blenkernel)
add_subdirectory(blenlib)
add_subdirectory(bmesh)
+add_subdirectory(draw)
add_subdirectory(render)
add_subdirectory(blenfont)
add_subdirectory(blentranslation)
diff --git a/source/blender/alembic/CMakeLists.txt b/source/blender/alembic/CMakeLists.txt
index fb08887c076..d3b5e189292 100644
--- a/source/blender/alembic/CMakeLists.txt
+++ b/source/blender/alembic/CMakeLists.txt
@@ -29,11 +29,11 @@ set(INC
../blenlib
../blenloader
../bmesh
+ ../depsgraph
../editors/include
../makesdna
../makesrna
../windowmanager
- ../depsgraph
../../../intern/guardedalloc
../../../intern/utfconv
)
diff --git a/source/blender/alembic/intern/abc_camera.cc b/source/blender/alembic/intern/abc_camera.cc
index 16416205983..4c91b9a6252 100644
--- a/source/blender/alembic/intern/abc_camera.cc
+++ b/source/blender/alembic/intern/abc_camera.cc
@@ -49,12 +49,13 @@ using Alembic::AbcGeom::kWrapExisting;
/* ************************************************************************** */
-AbcCameraWriter::AbcCameraWriter(Scene *scene,
+AbcCameraWriter::AbcCameraWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
ExportSettings &settings)
- : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent)
{
OCamera camera(parent->alembicXform(), m_name, m_time_sampling);
m_camera_schema = camera.getSchema();
diff --git a/source/blender/alembic/intern/abc_camera.h b/source/blender/alembic/intern/abc_camera.h
index 16c5cccd5ea..a839ca947ca 100644
--- a/source/blender/alembic/intern/abc_camera.h
+++ b/source/blender/alembic/intern/abc_camera.h
@@ -35,7 +35,8 @@ class AbcCameraWriter : public AbcObjectWriter {
Alembic::AbcGeom::OFloatProperty m_eye_separation;
public:
- AbcCameraWriter(Scene *scene,
+ AbcCameraWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
diff --git a/source/blender/alembic/intern/abc_curves.cc b/source/blender/alembic/intern/abc_curves.cc
index f73fe957fea..41c1dacabc0 100644
--- a/source/blender/alembic/intern/abc_curves.cc
+++ b/source/blender/alembic/intern/abc_curves.cc
@@ -71,12 +71,13 @@ using Alembic::AbcGeom::OV2fGeomParam;
/* ************************************************************************** */
-AbcCurveWriter::AbcCurveWriter(Scene *scene,
+AbcCurveWriter::AbcCurveWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
ExportSettings &settings)
- : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent)
{
OCurves curves(parent->alembicXform(), m_name, m_time_sampling);
m_schema = curves.getSchema();
diff --git a/source/blender/alembic/intern/abc_curves.h b/source/blender/alembic/intern/abc_curves.h
index a9231f947b2..1e7180bbb1f 100644
--- a/source/blender/alembic/intern/abc_curves.h
+++ b/source/blender/alembic/intern/abc_curves.h
@@ -36,7 +36,8 @@ class AbcCurveWriter : public AbcObjectWriter {
Alembic::AbcGeom::OCurvesSchema::Sample m_sample;
public:
- AbcCurveWriter(Scene *scene,
+ AbcCurveWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
diff --git a/source/blender/alembic/intern/abc_exporter.cc b/source/blender/alembic/intern/abc_exporter.cc
index 946b89213e6..f06959762d5 100644
--- a/source/blender/alembic/intern/abc_exporter.cc
+++ b/source/blender/alembic/intern/abc_exporter.cc
@@ -136,45 +136,48 @@ static bool object_type_is_exportable(Scene *scene, Object *ob)
/**
* Returns whether this object should be exported into the Alembic file.
*
- * \param settings: export settings, used for options like 'selected only'.
- * \param ob: the object in question.
+ * \param settings export settings, used for options like 'selected only'.
+ * \param ob the object's base in question.
* \param is_duplicated: Normally false; true when the object is instanced
* into the scene by a dupli-object (e.g. part of a dupligroup).
* This ignores selection and layer visibility,
* and assumes that the dupli-object itself (e.g. the group-instantiating empty) is exported.
*/
-static bool export_object(const ExportSettings * const settings, Object *ob,
+static bool export_object(const ExportSettings * const settings, const Base * const ob_base,
bool is_duplicated)
{
if (!is_duplicated) {
/* These two tests only make sense when the object isn't being instanced
* into the scene. When it is, its exportability is determined by
* its dupli-object and the DupliObject::no_draw property. */
- if (settings->selected_only && !parent_selected(ob)) {
+ if (settings->selected_only && !object_selected(ob_base)) {
return false;
}
-
- if (settings->visible_layers_only && !(settings->scene->lay & ob->lay)) {
+ // FIXME Sybren: handle these cleanly (maybe just remove code), now using active scene layer instead.
+ if (settings->visible_layers_only && (ob_base->flag & BASE_VISIBLED) == 0) {
return false;
}
}
- if (settings->renderable_only && (ob->restrictflag & OB_RESTRICT_RENDER)) {
- return false;
- }
+ // if (settings->renderable_only && (ob->restrictflag & OB_RESTRICT_RENDER)) {
+ // return false;
+ // }
return true;
}
/* ************************************************************************** */
-AbcExporter::AbcExporter(Main *bmain, Scene *scene, const char *filename, ExportSettings &settings)
+AbcExporter::AbcExporter(Main *bmain, Scene *scene,
+ Depsgraph *depsgraph,
+ const char *filename, ExportSettings &settings)
: m_bmain(bmain)
, m_settings(settings)
, m_filename(filename)
, m_trans_sampling_index(0)
, m_shape_sampling_index(0)
, m_scene(scene)
+ , m_depsgraph(depsgraph)
, m_writer(NULL)
{}
@@ -249,13 +252,13 @@ void AbcExporter::getFrameSet(unsigned int nr_of_samples,
}
}
-void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled)
+void AbcExporter::operator()(float &progress, bool &was_canceled)
{
std::string scene_name;
- if (bmain->name[0] != '\0') {
+ if (m_bmain->name[0] != '\0') {
char scene_file_name[FILE_MAX];
- BLI_strncpy(scene_file_name, bmain->name, FILE_MAX);
+ BLI_strncpy(scene_file_name, m_bmain->name, FILE_MAX);
scene_name = scene_file_name;
}
else {
@@ -294,8 +297,8 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled)
OBox3dProperty archive_bounds_prop = Alembic::AbcGeom::CreateOArchiveBounds(m_writer->archive(), m_trans_sampling_index);
- createTransformWritersHierarchy(bmain->eval_ctx);
- createShapeWriters(bmain->eval_ctx);
+ createTransformWritersHierarchy(m_depsgraph);
+ createShapeWriters(m_depsgraph);
/* Make a list of frames to export. */
@@ -328,7 +331,7 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled)
const double frame = *begin;
/* 'frame' is offset by start frame, so need to cancel the offset. */
- setCurrentFrame(bmain, frame);
+ setCurrentFrame(m_bmain, frame);
if (shape_frames.count(frame) != 0) {
for (int i = 0, e = m_shapes.size(); i != e; ++i) {
@@ -357,42 +360,45 @@ void AbcExporter::operator()(Main *bmain, float &progress, bool &was_canceled)
}
}
-void AbcExporter::createTransformWritersHierarchy(EvaluationContext *eval_ctx)
+void AbcExporter::createTransformWritersHierarchy(Depsgraph *depsgraph)
{
- Base *base = static_cast<Base *>(m_scene->base.first);
-
- while (base) {
+ for (Base *base = static_cast<Base *>(m_settings.view_layer->object_bases.first); base; base = base->next) {
Object *ob = base->object;
- switch (ob->type) {
- case OB_LAMP:
- case OB_LATTICE:
- case OB_SPEAKER:
- /* We do not export transforms for objects of these classes. */
- break;
- default:
- exploreTransform(eval_ctx, ob, ob->parent);
+ if (export_object(&m_settings, base, false)) {
+ switch (ob->type) {
+ case OB_LAMP:
+ case OB_LATTICE:
+ case OB_SPEAKER:
+ /* We do not export transforms for objects of these classes. */
+ break;
+ default:
+ exploreTransform(depsgraph, base, ob->parent, NULL);
+ }
}
-
- base = base->next;
}
}
-void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent)
+void AbcExporter::exploreTransform(Depsgraph *depsgraph, Base *ob_base, Object *parent, Object *dupliObParent)
{
+ Object *ob = ob_base->object;
+
/* If an object isn't exported itself, its duplilist shouldn't be
* exported either. */
- if (!export_object(&m_settings, ob, dupliObParent != NULL)) {
+ if (!export_object(&m_settings, ob_base, dupliObParent != NULL)) {
return;
}
if (object_type_is_exportable(m_scene, ob)) {
- createTransformWriter(ob, parent, dupliObParent);
+ createTransformWriter(depsgraph, ob, parent, dupliObParent);
}
- ListBase *lb = object_duplilist(eval_ctx, m_scene, ob);
+ ListBase *lb = object_duplilist(depsgraph, m_scene, ob);
if (lb) {
+ Base fake_base = *ob_base; // copy flags (like selection state) from the real object.
+ fake_base.next = fake_base.prev = NULL;
+
DupliObject *link = static_cast<DupliObject *>(lb->first);
Object *dupli_ob = NULL;
Object *dupli_parent = NULL;
@@ -407,7 +413,8 @@ void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Object *ob, Obje
dupli_ob = link->ob;
dupli_parent = (dupli_ob->parent) ? dupli_ob->parent : ob;
- exploreTransform(eval_ctx, dupli_ob, dupli_parent, ob);
+ fake_base.object = dupli_ob;
+ exploreTransform(depsgraph, &fake_base, dupli_parent, ob);
}
}
}
@@ -415,7 +422,7 @@ void AbcExporter::exploreTransform(EvaluationContext *eval_ctx, Object *ob, Obje
free_object_duplilist(lb);
}
-AbcTransformWriter * AbcExporter::createTransformWriter(Object *ob, Object *parent, Object *dupliObParent)
+AbcTransformWriter * AbcExporter::createTransformWriter(Depsgraph *depsgraph, Object *ob, Object *parent, Object *dupliObParent)
{
/* An object should not be its own parent, or we'll get infinite loops. */
BLI_assert(ob != parent);
@@ -450,29 +457,29 @@ AbcTransformWriter * AbcExporter::createTransformWriter(Object *ob, Object *pare
* return the parent's AbcTransformWriter pointer. */
if (parent->parent) {
if (parent == dupliObParent) {
- parent_writer = createTransformWriter(parent, parent->parent, NULL);
+ parent_writer = createTransformWriter(depsgraph, parent, parent->parent, NULL);
}
else {
- parent_writer = createTransformWriter(parent, parent->parent, dupliObParent);
+ parent_writer = createTransformWriter(depsgraph, parent, parent->parent, dupliObParent);
}
}
else if (parent == dupliObParent) {
if (dupliObParent->parent == NULL) {
- parent_writer = createTransformWriter(parent, NULL, NULL);
+ parent_writer = createTransformWriter(depsgraph, parent, NULL, NULL);
}
else {
- parent_writer = createTransformWriter(parent, dupliObParent->parent, dupliObParent->parent);
+ parent_writer = createTransformWriter(depsgraph, parent, dupliObParent->parent, dupliObParent->parent);
}
}
else {
- parent_writer = createTransformWriter(parent, dupliObParent, dupliObParent);
+ parent_writer = createTransformWriter(depsgraph, parent, dupliObParent, dupliObParent);
}
BLI_assert(parent_writer);
alembic_parent = parent_writer->alembicXform();
}
- my_writer = new AbcTransformWriter(ob, alembic_parent, parent_writer,
+ my_writer = new AbcTransformWriter(depsgraph, ob, alembic_parent, parent_writer,
m_trans_sampling_index, m_settings);
/* When flattening, the matrix of the dupliobject has to be added. */
@@ -484,31 +491,30 @@ AbcTransformWriter * AbcExporter::createTransformWriter(Object *ob, Object *pare
return my_writer;
}
-void AbcExporter::createShapeWriters(EvaluationContext *eval_ctx)
+void AbcExporter::createShapeWriters(Depsgraph *depsgraph)
{
- Base *base = static_cast<Base *>(m_scene->base.first);
-
- while (base) {
- Object *ob = base->object;
- exploreObject(eval_ctx, ob, NULL);
-
- base = base->next;
+ for (Base *base = static_cast<Base *>(m_settings.view_layer->object_bases.first); base; base = base->next) {
+ exploreObject(depsgraph, base, NULL);
}
}
-void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Object *ob, Object *dupliObParent)
+void AbcExporter::exploreObject(Depsgraph *depsgraph, Base *ob_base, Object *dupliObParent)
{
/* If an object isn't exported itself, its duplilist shouldn't be
* exported either. */
- if (!export_object(&m_settings, ob, dupliObParent != NULL)) {
+ if (!export_object(&m_settings, ob_base, dupliObParent != NULL)) {
return;
}
- createShapeWriter(ob, dupliObParent);
+ createShapeWriter(ob_base, dupliObParent);
- ListBase *lb = object_duplilist(eval_ctx, m_scene, ob);
+ Object *ob = ob_base->object;
+ ListBase *lb = object_duplilist(depsgraph, m_scene, ob);
if (lb) {
+ Base fake_base = *ob_base; // copy flags (like selection state) from the real object.
+ fake_base.next = fake_base.prev = NULL;
+
DupliObject *link = static_cast<DupliObject *>(lb->first);
for (; link; link = link->next) {
@@ -516,9 +522,9 @@ void AbcExporter::exploreObject(EvaluationContext *eval_ctx, Object *ob, Object
if (m_settings.renderable_only && link->no_draw) {
continue;
}
-
if (link->type == OB_DUPLIGROUP) {
- exploreObject(eval_ctx, link->ob, ob);
+ fake_base.object = link->ob;
+ exploreObject(depsgraph, &fake_base, ob);
}
}
}
@@ -541,16 +547,18 @@ void AbcExporter::createParticleSystemsWriters(Object *ob, AbcTransformWriter *x
if (m_settings.export_hair && psys->part->type == PART_HAIR) {
m_settings.export_child_hairs = true;
- m_shapes.push_back(new AbcHairWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings, psys));
+ m_shapes.push_back(new AbcHairWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings, psys));
}
else if (m_settings.export_particles && psys->part->type == PART_EMITTER) {
- m_shapes.push_back(new AbcPointsWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings, psys));
+ m_shapes.push_back(new AbcPointsWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings, psys));
}
}
}
-void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
+void AbcExporter::createShapeWriter(Base *ob_base, Object *dupliObParent)
{
+ Object *ob = ob_base->object;
+
if (!object_type_is_exportable(m_scene, ob)) {
return;
}
@@ -582,7 +590,7 @@ void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
return;
}
- m_shapes.push_back(new AbcMeshWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings));
+ m_shapes.push_back(new AbcMeshWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings));
break;
}
case OB_SURF:
@@ -593,7 +601,7 @@ void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
return;
}
- m_shapes.push_back(new AbcNurbsWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings));
+ m_shapes.push_back(new AbcNurbsWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings));
break;
}
case OB_CURVE:
@@ -604,7 +612,7 @@ void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
return;
}
- m_shapes.push_back(new AbcCurveWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings));
+ m_shapes.push_back(new AbcCurveWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings));
break;
}
case OB_CAMERA:
@@ -612,7 +620,7 @@ void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
Camera *cam = static_cast<Camera *>(ob->data);
if (cam->type == CAM_PERSP) {
- m_shapes.push_back(new AbcCameraWriter(m_scene, ob, xform, m_shape_sampling_index, m_settings));
+ m_shapes.push_back(new AbcCameraWriter(m_depsgraph, m_scene, ob, xform, m_shape_sampling_index, m_settings));
}
break;
@@ -625,7 +633,7 @@ void AbcExporter::createShapeWriter(Object *ob, Object *dupliObParent)
}
m_shapes.push_back(new AbcMBallWriter(
- m_bmain, m_scene, ob, xform,
+ m_bmain, m_depsgraph, m_scene, ob, xform,
m_shape_sampling_index, m_settings));
break;
}
@@ -647,5 +655,5 @@ void AbcExporter::setCurrentFrame(Main *bmain, double t)
{
m_scene->r.cfra = static_cast<int>(t);
m_scene->r.subframe = static_cast<float>(t) - m_scene->r.cfra;
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, m_scene, m_scene->lay);
+ BKE_scene_graph_update_for_newframe(m_depsgraph, bmain);
}
diff --git a/source/blender/alembic/intern/abc_exporter.h b/source/blender/alembic/intern/abc_exporter.h
index 280682b2896..c891824a114 100644
--- a/source/blender/alembic/intern/abc_exporter.h
+++ b/source/blender/alembic/intern/abc_exporter.h
@@ -34,15 +34,19 @@ class AbcObjectWriter;
class AbcTransformWriter;
class ArchiveWriter;
-struct EvaluationContext;
+struct Depsgraph;
struct Main;
struct Object;
struct Scene;
+struct ViewLayer;
+struct Base;
struct ExportSettings {
ExportSettings();
Scene *scene;
+ ViewLayer *view_layer; // Scene layer to export; all its objects will be exported, unless selected_only=true
+ Depsgraph *depsgraph;
SimpleLogger logger;
bool selected_only;
@@ -89,6 +93,7 @@ class AbcExporter {
unsigned int m_trans_sampling_index, m_shape_sampling_index;
Scene *m_scene;
+ Depsgraph *m_depsgraph;
ArchiveWriter *m_writer;
@@ -99,10 +104,11 @@ class AbcExporter {
std::vector<AbcObjectWriter *> m_shapes;
public:
- AbcExporter(Main *bmain, Scene *scene, const char *filename, ExportSettings &settings);
+ AbcExporter(Main *bmain, Scene *scene, Depsgraph *depsgraph,
+ const char *filename, ExportSettings &settings);
~AbcExporter();
- void operator()(Main *bmain, float &progress, bool &was_canceled);
+ void operator()(float &progress, bool &was_canceled);
protected:
void getShutterSamples(unsigned int nr_of_samples,
@@ -113,12 +119,12 @@ protected:
private:
Alembic::Abc::TimeSamplingPtr createTimeSampling(double step);
- void createTransformWritersHierarchy(EvaluationContext *eval_ctx);
- AbcTransformWriter * createTransformWriter(Object *ob, Object *parent, Object *dupliObParent);
- void exploreTransform(EvaluationContext *eval_ctx, Object *ob, Object *parent, Object *dupliObParent = NULL);
- void exploreObject(EvaluationContext *eval_ctx, Object *ob, Object *dupliObParent);
- void createShapeWriters(EvaluationContext *eval_ctx);
- void createShapeWriter(Object *ob, Object *dupliObParent);
+ void createTransformWritersHierarchy(Depsgraph *depsgraph);
+ AbcTransformWriter * createTransformWriter(Depsgraph *depsgraph, Object *ob, Object *parent, Object *dupliObParent);
+ void exploreTransform(Depsgraph *depsgraph, Base *ob_base, Object *parent, Object *dupliObParent);
+ void exploreObject(Depsgraph *depsgraph, Base *ob_base, Object *dupliObParent);
+ void createShapeWriters(Depsgraph *depsgraph);
+ void createShapeWriter(Base *ob_base, Object *dupliObParent);
void createParticleSystemsWriters(Object *ob, AbcTransformWriter *xform);
AbcTransformWriter *getXForm(const std::string &name);
diff --git a/source/blender/alembic/intern/abc_hair.cc b/source/blender/alembic/intern/abc_hair.cc
index 0208da8a6d7..b31a185e39b 100644
--- a/source/blender/alembic/intern/abc_hair.cc
+++ b/source/blender/alembic/intern/abc_hair.cc
@@ -49,13 +49,14 @@ using Alembic::AbcGeom::OV2fGeomParam;
/* ************************************************************************** */
-AbcHairWriter::AbcHairWriter(Scene *scene,
+AbcHairWriter::AbcHairWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
ExportSettings &settings,
ParticleSystem *psys)
- : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent)
, m_uv_warning_shown(false)
{
m_psys = psys;
@@ -76,7 +77,7 @@ void AbcHairWriter::do_write()
return;
}
- DerivedMesh *dm = mesh_create_derived_render(m_scene, m_object, CD_MASK_MESH);
+ DerivedMesh *dm = mesh_create_derived_render(m_depsgraph, m_scene, m_object, CD_MASK_MESH);
DM_ensure_tessface(dm);
std::vector<Imath::V3f> verts;
@@ -164,7 +165,7 @@ void AbcHairWriter::write_hair_sample(DerivedMesh *dm,
psys_interpolate_uvs(tface, face->v4, pa->fuv, r_uv);
uv_values.push_back(Imath::V2f(r_uv[0], r_uv[1]));
- psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, normal, NULL, NULL, NULL, NULL);
+ psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, normal, NULL, NULL, NULL);
copy_yup_from_zup(tmp_nor.getValue(), normal);
norm_values.push_back(tmp_nor);
@@ -272,7 +273,7 @@ void AbcHairWriter::write_hair_child_sample(DerivedMesh *dm,
psys_interpolate_uvs(tface, face->v4, pc->fuv, r_uv);
uv_values.push_back(Imath::V2f(r_uv[0], r_uv[1]));
- psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL, NULL);
+ psys_interpolate_face(mverts, face, tface, NULL, mapfw, vec, tmpnor, NULL, NULL, NULL);
/* Convert Z-up to Y-up. */
norm_values.push_back(Imath::V3f(tmpnor[0], tmpnor[2], -tmpnor[1]));
diff --git a/source/blender/alembic/intern/abc_hair.h b/source/blender/alembic/intern/abc_hair.h
index 61f5fe361f8..5627f7726e6 100644
--- a/source/blender/alembic/intern/abc_hair.h
+++ b/source/blender/alembic/intern/abc_hair.h
@@ -40,7 +40,8 @@ class AbcHairWriter : public AbcObjectWriter {
bool m_uv_warning_shown;
public:
- AbcHairWriter(Scene *scene,
+ AbcHairWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
diff --git a/source/blender/alembic/intern/abc_mball.cc b/source/blender/alembic/intern/abc_mball.cc
index 1ef7b757577..1df55712abe 100644
--- a/source/blender/alembic/intern/abc_mball.cc
+++ b/source/blender/alembic/intern/abc_mball.cc
@@ -30,7 +30,6 @@ extern "C" {
#include "DNA_object_types.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_displist.h"
#include "BKE_main.h"
#include "BKE_mball.h"
@@ -43,12 +42,13 @@ extern "C" {
AbcMBallWriter::AbcMBallWriter(
Main *bmain,
+ Depsgraph *depsgraph,
Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
ExportSettings &settings)
- : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent)
, m_bmain(bmain)
{
m_is_animated = isAnimated();
@@ -58,7 +58,7 @@ AbcMBallWriter::AbcMBallWriter(
sizeof(CurveCache),
"CurveCache for AbcMBallWriter");
- m_mesh_writer = new AbcMeshWriter(scene, m_mesh_ob, parent,
+ m_mesh_writer = new AbcMeshWriter(depsgraph, scene, m_mesh_ob, parent,
time_sampling, settings);
m_mesh_writer->setIsAnimated(m_is_animated);
}
@@ -97,13 +97,11 @@ void AbcMBallWriter::do_write()
id_us_min(&tmpmesh->id);
ListBase disp = {NULL, NULL};
- /* TODO(sergey): This is gonna to work for until EvaluationContext
+ /* TODO(sergey): This is gonna to work for until Depsgraph
* only contains for_render flag. As soon as CoW is
* implemented, this is to be rethinked.
*/
- EvaluationContext eval_ctx;
- DEG_evaluation_context_init(&eval_ctx, DAG_EVAL_RENDER);
- BKE_displist_make_mball_forRender(&eval_ctx, m_scene, m_object, &disp);
+ BKE_displist_make_mball_forRender(m_depsgraph, m_scene, m_object, &disp);
BKE_mesh_from_metaball(&disp, tmpmesh);
BKE_displist_free(&disp);
diff --git a/source/blender/alembic/intern/abc_mball.h b/source/blender/alembic/intern/abc_mball.h
index 9b943698416..19bf7dc054d 100644
--- a/source/blender/alembic/intern/abc_mball.h
+++ b/source/blender/alembic/intern/abc_mball.h
@@ -42,6 +42,7 @@ class AbcMBallWriter : public AbcObjectWriter {
public:
AbcMBallWriter(
Main *bmain,
+ Depsgraph *depsgraph,
Scene *scene,
Object *ob,
AbcTransformWriter *parent,
diff --git a/source/blender/alembic/intern/abc_mesh.cc b/source/blender/alembic/intern/abc_mesh.cc
index ef0a823ac3e..56fa0a93532 100644
--- a/source/blender/alembic/intern/abc_mesh.cc
+++ b/source/blender/alembic/intern/abc_mesh.cc
@@ -38,7 +38,6 @@ extern "C" {
#include "BLI_string.h"
#include "BKE_cdderivedmesh.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
@@ -287,12 +286,13 @@ static ModifierData *get_liquid_sim_modifier(Scene *scene, Object *ob)
/* ************************************************************************** */
-AbcMeshWriter::AbcMeshWriter(Scene *scene,
+AbcMeshWriter::AbcMeshWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
ExportSettings &settings)
- : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent)
{
m_is_animated = isAnimated();
m_subsurf_mod = NULL;
@@ -525,7 +525,7 @@ DerivedMesh *AbcMeshWriter::getFinalMesh()
m_subsurf_mod->mode |= eModifierMode_DisableTemporary;
}
- DerivedMesh *dm = mesh_create_derived_render(m_scene, m_object, CD_MASK_MESH);
+ DerivedMesh *dm = mesh_create_derived_render(m_depsgraph, m_scene, m_object, CD_MASK_MESH);
if (m_subsurf_mod) {
m_subsurf_mod->mode &= ~eModifierMode_DisableTemporary;
@@ -923,12 +923,6 @@ static void *add_customdata_cb(void *user_data, const char *name, int data_type)
numloops = dm->getNumLoops(dm);
cd_ptr = CustomData_add_layer_named(loopdata, cd_data_type, CD_DEFAULT,
NULL, numloops, name);
- if (cd_data_type == CD_MLOOPUV) {
- CustomData_add_layer_named(dm->getPolyDataLayout(dm),
- CD_MTEXPOLY, CD_DEFAULT,
- NULL, numloops, name);
- }
-
return cd_ptr;
}
diff --git a/source/blender/alembic/intern/abc_mesh.h b/source/blender/alembic/intern/abc_mesh.h
index 77c352d7cd3..c57123cda4c 100644
--- a/source/blender/alembic/intern/abc_mesh.h
+++ b/source/blender/alembic/intern/abc_mesh.h
@@ -50,7 +50,8 @@ class AbcMeshWriter : public AbcObjectWriter {
bool m_is_subd;
public:
- AbcMeshWriter(Scene *scene,
+ AbcMeshWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
diff --git a/source/blender/alembic/intern/abc_nurbs.cc b/source/blender/alembic/intern/abc_nurbs.cc
index eaef06fd6d1..1f042d0bafc 100644
--- a/source/blender/alembic/intern/abc_nurbs.cc
+++ b/source/blender/alembic/intern/abc_nurbs.cc
@@ -60,12 +60,13 @@ using Alembic::AbcGeom::ONuPatchSchema;
/* ************************************************************************** */
-AbcNurbsWriter::AbcNurbsWriter(Scene *scene,
+AbcNurbsWriter::AbcNurbsWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
ExportSettings &settings)
- : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent)
{
m_is_animated = isAnimated();
diff --git a/source/blender/alembic/intern/abc_nurbs.h b/source/blender/alembic/intern/abc_nurbs.h
index abe460a8988..d2422345c3f 100644
--- a/source/blender/alembic/intern/abc_nurbs.h
+++ b/source/blender/alembic/intern/abc_nurbs.h
@@ -32,7 +32,8 @@ class AbcNurbsWriter : public AbcObjectWriter {
bool m_is_animated;
public:
- AbcNurbsWriter(Scene *scene,
+ AbcNurbsWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
diff --git a/source/blender/alembic/intern/abc_object.cc b/source/blender/alembic/intern/abc_object.cc
index ddedcf6dcbc..85bda9aa8eb 100644
--- a/source/blender/alembic/intern/abc_object.cc
+++ b/source/blender/alembic/intern/abc_object.cc
@@ -32,7 +32,6 @@ extern "C" {
#include "DNA_space_types.h" /* for FILE_MAX */
#include "BKE_constraint.h"
-#include "BKE_depsgraph.h"
#include "BKE_idprop.h"
#include "BKE_library.h"
#include "BKE_modifier.h"
@@ -59,13 +58,15 @@ using Alembic::AbcGeom::OStringProperty;
/* ************************************************************************** */
-AbcObjectWriter::AbcObjectWriter(Scene *scene,
+AbcObjectWriter::AbcObjectWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
uint32_t time_sampling,
ExportSettings &settings,
AbcObjectWriter *parent)
: m_object(ob)
, m_settings(settings)
+ , m_depsgraph(depsgraph)
, m_scene(scene)
, m_time_sampling(time_sampling)
, m_first_frame(true)
diff --git a/source/blender/alembic/intern/abc_object.h b/source/blender/alembic/intern/abc_object.h
index 852ef451f23..d41088bdcad 100644
--- a/source/blender/alembic/intern/abc_object.h
+++ b/source/blender/alembic/intern/abc_object.h
@@ -44,6 +44,7 @@ protected:
Object *m_object;
ExportSettings &m_settings;
+ Depsgraph *m_depsgraph;
Scene *m_scene;
uint32_t m_time_sampling;
@@ -56,7 +57,8 @@ protected:
std::string m_name;
public:
- AbcObjectWriter(Scene *scene,
+ AbcObjectWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
uint32_t time_sampling,
ExportSettings &settings,
diff --git a/source/blender/alembic/intern/abc_points.cc b/source/blender/alembic/intern/abc_points.cc
index 80567cd6bf0..6f52ccec4a7 100644
--- a/source/blender/alembic/intern/abc_points.cc
+++ b/source/blender/alembic/intern/abc_points.cc
@@ -58,13 +58,14 @@ using Alembic::AbcGeom::OPointsSchema;
/* ************************************************************************** */
-AbcPointsWriter::AbcPointsWriter(Scene *scene,
+AbcPointsWriter::AbcPointsWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
ExportSettings &settings,
ParticleSystem *psys)
- : AbcObjectWriter(scene, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, scene, ob, time_sampling, settings, parent)
{
m_psys = psys;
@@ -86,6 +87,7 @@ void AbcPointsWriter::do_write()
ParticleKey state;
ParticleSimulationData sim;
+ sim.depsgraph = m_depsgraph;
sim.scene = m_scene;
sim.ob = m_object;
sim.psys = m_psys;
diff --git a/source/blender/alembic/intern/abc_points.h b/source/blender/alembic/intern/abc_points.h
index 369a802d763..1ac8792ede1 100644
--- a/source/blender/alembic/intern/abc_points.h
+++ b/source/blender/alembic/intern/abc_points.h
@@ -38,7 +38,8 @@ class AbcPointsWriter : public AbcObjectWriter {
ParticleSystem *m_psys;
public:
- AbcPointsWriter(Scene *scene,
+ AbcPointsWriter(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
AbcTransformWriter *parent,
uint32_t time_sampling,
diff --git a/source/blender/alembic/intern/abc_transform.cc b/source/blender/alembic/intern/abc_transform.cc
index 5392387663f..e5da367b9a9 100644
--- a/source/blender/alembic/intern/abc_transform.cc
+++ b/source/blender/alembic/intern/abc_transform.cc
@@ -57,12 +57,13 @@ static bool has_parent_camera(Object *ob)
/* ************************************************************************** */
-AbcTransformWriter::AbcTransformWriter(Object *ob,
+AbcTransformWriter::AbcTransformWriter(Depsgraph *depsgraph,
+ Object *ob,
const OObject &abc_parent,
AbcTransformWriter *parent,
unsigned int time_sampling,
ExportSettings &settings)
- : AbcObjectWriter(NULL, ob, time_sampling, settings, parent)
+ : AbcObjectWriter(depsgraph, NULL, ob, time_sampling, settings, parent)
, m_proxy_from(NULL)
{
m_is_animated = hasAnimation(m_object);
diff --git a/source/blender/alembic/intern/abc_transform.h b/source/blender/alembic/intern/abc_transform.h
index 753a4247e9f..91420b28f93 100644
--- a/source/blender/alembic/intern/abc_transform.h
+++ b/source/blender/alembic/intern/abc_transform.h
@@ -37,14 +37,14 @@ class AbcTransformWriter : public AbcObjectWriter {
Alembic::Abc::M44d m_matrix;
bool m_is_animated;
- bool m_visible;
bool m_inherits_xform;
public:
Object *m_proxy_from;
public:
- AbcTransformWriter(Object *ob,
+ AbcTransformWriter(Depsgraph *depsgraph,
+ Object *ob,
const Alembic::AbcGeom::OObject &abc_parent,
AbcTransformWriter *parent,
unsigned int time_sampling,
diff --git a/source/blender/alembic/intern/abc_util.cc b/source/blender/alembic/intern/abc_util.cc
index 24a508e8292..8bdc7ae3455 100644
--- a/source/blender/alembic/intern/abc_util.cc
+++ b/source/blender/alembic/intern/abc_util.cc
@@ -35,6 +35,7 @@
extern "C" {
#include "DNA_object_types.h"
+#include "DNA_layer_types.h"
#include "BLI_math.h"
@@ -60,6 +61,15 @@ std::string get_id_name(const ID * const id)
return name;
}
+/**
+ * @brief get_object_dag_path_name returns the name under which the object
+ * will be exported in the Alembic file. It is of the form
+ * "[../grandparent/]parent/object" if dupli_parent is NULL, or
+ * "dupli_parent/[../grandparent/]parent/object" otherwise.
+ * @param ob
+ * @param dupli_parent
+ * @return
+ */
std::string get_object_dag_path_name(const Object * const ob, Object *dupli_parent)
{
std::string name = get_id_name(ob);
@@ -78,31 +88,9 @@ std::string get_object_dag_path_name(const Object * const ob, Object *dupli_pare
return name;
}
-bool object_selected(Object *ob)
-{
- return ob->flag & SELECT;
-}
-
-bool parent_selected(Object *ob)
+bool object_selected(const Base * const ob_base)
{
- if (object_selected(ob)) {
- return true;
- }
-
- bool do_export = false;
-
- Object *parent = ob->parent;
-
- while (parent != NULL) {
- if (object_selected(parent)) {
- do_export = true;
- break;
- }
-
- parent = parent->parent;
- }
-
- return do_export;
+ return ob_base->flag & SELECT;
}
Imath::M44d convert_matrix(float mat[4][4])
diff --git a/source/blender/alembic/intern/abc_util.h b/source/blender/alembic/intern/abc_util.h
index 2526958111a..fcc3b19c48b 100644
--- a/source/blender/alembic/intern/abc_util.h
+++ b/source/blender/alembic/intern/abc_util.h
@@ -48,13 +48,13 @@ struct ImportSettings;
struct ID;
struct Object;
+struct Base;
std::string get_id_name(const ID * const id);
std::string get_id_name(const Object * const ob);
std::string get_object_dag_path_name(const Object * const ob, Object *dupli_parent);
-bool object_selected(Object *ob);
-bool parent_selected(Object *ob);
+bool object_selected(const Base * const ob_base);
Imath::M44d convert_matrix(float mat[4][4]);
diff --git a/source/blender/alembic/intern/alembic_capi.cc b/source/blender/alembic/intern/alembic_capi.cc
index 0d2316ce7d9..35877f9f5a8 100644
--- a/source/blender/alembic/intern/alembic_capi.cc
+++ b/source/blender/alembic/intern/alembic_capi.cc
@@ -48,12 +48,15 @@ extern "C" {
#include "BKE_cdderivedmesh.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
/* SpaceType struct has a member called 'new' which obviously conflicts with C++
* so temporarily redefining the new keyword to make it compile. */
#define new extern_new
@@ -228,6 +231,8 @@ static void find_iobject(const IObject &object, IObject &ret,
struct ExportJobData {
Scene *scene;
+ ViewLayer *view_layer;
+ Depsgraph *depsgraph;
Main *bmain;
char filename[1024];
@@ -259,18 +264,17 @@ static void export_startjob(void *customdata, short *stop, short *do_update, flo
try {
Scene *scene = data->scene;
- AbcExporter exporter(data->bmain, scene, data->filename, data->settings);
+ AbcExporter exporter(data->bmain, scene, data->depsgraph, data->filename, data->settings);
const int orig_frame = CFRA;
data->was_canceled = false;
- exporter(data->bmain, *data->progress, data->was_canceled);
+ exporter(*data->progress, data->was_canceled);
if (CFRA != orig_frame) {
CFRA = orig_frame;
- BKE_scene_update_for_newframe(data->bmain->eval_ctx, data->bmain,
- scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(data->depsgraph, data->bmain);
}
data->export_ok = !data->was_canceled;
@@ -308,7 +312,10 @@ bool ABC_export(
bool as_background_job)
{
ExportJobData *job = static_cast<ExportJobData *>(MEM_mallocN(sizeof(ExportJobData), "ExportJobData"));
+
job->scene = scene;
+ job->view_layer = CTX_data_view_layer(C);
+ job->depsgraph = CTX_data_depsgraph(C);
job->bmain = CTX_data_main(C);
job->export_ok = false;
BLI_strncpy(job->filename, filepath, 1024);
@@ -330,13 +337,25 @@ bool ABC_export(
* hardcore refactoring. */
new (&job->settings) ExportSettings();
job->settings.scene = job->scene;
+ job->settings.depsgraph = job->depsgraph;
+
+ /* Sybren: for now we only export the active scene layer.
+ * Later in the 2.8 development process this may be replaced by using
+ * a specific collection for Alembic I/O, which can then be toggled
+ * between "real" objects and cached Alembic files. */
+ job->settings.view_layer = CTX_data_view_layer(C);
+
job->settings.frame_start = params->frame_start;
job->settings.frame_end = params->frame_end;
job->settings.frame_samples_xform = params->frame_samples_xform;
job->settings.frame_samples_shape = params->frame_samples_shape;
job->settings.shutter_open = params->shutter_open;
job->settings.shutter_close = params->shutter_close;
+
+ /* Sybren: For now this is ignored, until we can get selection
+ * detection working through Base pointers (instead of ob->flags). */
job->settings.selected_only = params->selected_only;
+
job->settings.export_face_sets = params->face_sets;
job->settings.export_normals = params->normals;
job->settings.export_uvs = params->uvs;
@@ -345,8 +364,13 @@ bool ABC_export(
job->settings.export_particles = params->export_particles;
job->settings.apply_subdiv = params->apply_subdiv;
job->settings.flatten_hierarchy = params->flatten_hierarchy;
+
+ /* Sybren: visible_layer & renderable only is ignored for now,
+ * to be replaced with collections later in the 2.8 dev process
+ * (also see note above). */
job->settings.visible_layers_only = params->visible_layers_only;
job->settings.renderable_only = params->renderable_only;
+
job->settings.use_subdiv_schema = params->use_subdiv_schema;
job->settings.export_ogawa = (params->compression_type == ABC_ARCHIVE_OGAWA);
job->settings.pack_uv = params->packuv;
@@ -606,6 +630,7 @@ enum {
struct ImportJobData {
Main *bmain;
Scene *scene;
+ ViewLayer *view_layer;
char filename[1024];
ImportSettings settings;
@@ -621,6 +646,7 @@ struct ImportJobData {
bool import_ok;
};
+#if 0
ABC_INLINE bool is_mesh_and_strands(const IObject &object)
{
bool has_mesh = false;
@@ -651,6 +677,7 @@ ABC_INLINE bool is_mesh_and_strands(const IObject &object)
return has_mesh && has_curve;
}
+#endif
static void import_startjob(void *user_data, short *stop, short *do_update, float *progress)
{
@@ -807,20 +834,34 @@ static void import_endjob(void *user_data)
else {
/* Add object to scene. */
Base *base;
+ LayerCollection *lc;
+ ViewLayer *view_layer = data->view_layer;
- BKE_scene_base_deselect_all(data->scene);
+ BKE_view_layer_base_deselect_all(view_layer);
+
+ lc = BKE_layer_collection_get_active(view_layer);
+ if (lc == NULL) {
+ BLI_assert(BLI_listbase_count_at_most(&view_layer->layer_collections, 1) == 0);
+ /* when there is no collection linked to this ViewLayer, create one */
+ SceneCollection *sc = BKE_collection_add(&data->scene->id, NULL, COLLECTION_TYPE_NONE, NULL);
+ lc = BKE_collection_link(view_layer, sc);
+ }
for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
Object *ob = (*iter)->object();
ob->lay = data->scene->lay;
- base = BKE_scene_base_add(data->scene, ob);
- BKE_scene_base_select(data->scene, base);
+ BKE_collection_object_add(&data->scene->id, lc->scene_collection, ob);
+
+ base = BKE_view_layer_base_find(view_layer, ob);
+ BKE_view_layer_base_select(view_layer, base);
- DAG_id_tag_update_ex(data->bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update_ex(data->bmain, &ob->id,
+ OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME | DEG_TAG_BASE_FLAGS_UPDATE);
}
- DAG_relations_tag_update(data->bmain);
+ DEG_id_tag_update(&data->scene->id, DEG_TAG_BASE_FLAGS_UPDATE);
+ DEG_relations_tag_update(data->bmain);
}
for (iter = data->readers.begin(); iter != data->readers.end(); ++iter) {
@@ -863,6 +904,7 @@ bool ABC_import(bContext *C, const char *filepath, float scale, bool is_sequence
ImportJobData *job = new ImportJobData();
job->bmain = CTX_data_main(C);
job->scene = CTX_data_scene(C);
+ job->view_layer = CTX_data_view_layer(C);
job->import_ok = false;
BLI_strncpy(job->filename, filepath, 1024);
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h
index f31c132c973..668588435b4 100644
--- a/source/blender/blenfont/BLF_api.h
+++ b/source/blender/blenfont/BLF_api.h
@@ -35,6 +35,9 @@
#include "BLI_compiler_attrs.h"
#include "BLI_sys_types.h"
+/* enable this only if needed (unused circa 2016) */
+#define BLF_BLUR_ENABLE 0
+
struct rctf;
struct ColorManagedDisplay;
struct ResultBLF;
@@ -43,6 +46,8 @@ int BLF_init(void);
void BLF_exit(void);
void BLF_default_dpi(int dpi);
void BLF_default_set(int fontid);
+int BLF_default(void); /* get default font ID so we can pass it to other functions */
+void BLF_batch_reset(void); /* call when changing opengl context. */
void BLF_antialias_set(bool enabled);
bool BLF_antialias_get(void);
@@ -65,6 +70,17 @@ void BLF_aspect(int fontid, float x, float y, float z);
void BLF_position(int fontid, float x, float y, float z);
void BLF_size(int fontid, int size, int dpi);
+/* goal: small but useful color API */
+void BLF_color4ubv(int fontid, const unsigned char rgba[4]);
+void BLF_color3ubv(int fontid, const unsigned char rgb[3]);
+void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha);
+void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b);
+void BLF_color4f(int fontid, float r, float g, float b, float a);
+void BLF_color4fv(int fontid, const float rgba[4]);
+void BLF_color3f(int fontid, float r, float g, float b);
+void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha);
+/* also available: UI_FontThemeColor(fontid, colorid) */
+
/* Set a 4x4 matrix to be multiplied before draw the text.
* Remember that you need call BLF_enable(BLF_MATRIX)
* to enable this.
@@ -79,6 +95,12 @@ void BLF_size(int fontid, int size, int dpi);
*/
void BLF_matrix(int fontid, const float m[16]);
+/* Batch drawcalls together as long as
+ * the modelview matrix and the font remain unchanged. */
+void BLF_batch_draw_begin(void);
+void BLF_batch_draw_flush(void);
+void BLF_batch_draw_end(void);
+
/* Draw the string using the default font, size and dpi. */
void BLF_draw_default(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
@@ -126,29 +148,16 @@ void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_widt
*/
float BLF_fixed_width(int fontid) ATTR_WARN_UNUSED_RESULT;
-/* and this two function return the width and height
- * of the string, using the default font and both value
- * are multiplied by the aspect of the font.
- */
-void BLF_width_and_height_default(const char *str, size_t len, float *r_width, float *r_height) ATTR_NONNULL();
-float BLF_width_default(const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
-float BLF_height_default(const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
-
-/* Set rotation for default font. */
-void BLF_rotation_default(float angle);
-
-/* Enable/disable options to the default font. */
-void BLF_enable_default(int option);
-void BLF_disable_default(int option);
-
/* By default, rotation and clipping are disable and
* have to be enable/disable using BLF_enable/disable.
*/
void BLF_rotation(int fontid, float angle);
void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax);
-void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax);
void BLF_wordwrap(int fontid, int wrap_width);
+
+#if BLF_BLUR_ENABLE
void BLF_blur(int fontid, int size);
+#endif
void BLF_enable(int fontid, int option);
void BLF_disable(int fontid, int option);
diff --git a/source/blender/blenfont/intern/blf.c b/source/blender/blenfont/intern/blf.c
index 38c1498d76b..fafee125264 100644
--- a/source/blender/blenfont/intern/blf.c
+++ b/source/blender/blenfont/intern/blf.c
@@ -50,13 +50,14 @@
#include "BLI_math.h"
#include "BLI_threads.h"
-#include "BIF_gl.h"
#include "BLF_api.h"
#include "IMB_colormanagement.h"
#ifndef BLF_STANDALONE
-#include "GPU_basic_shader.h"
+#include "GPU_shader.h"
+#include "GPU_matrix.h"
+#include "GPU_immediate.h"
#endif
#include "blf_internal_types.h"
@@ -131,6 +132,11 @@ void BLF_exit(void)
blf_font_exit();
}
+void BLF_batch_reset(void)
+{
+ blf_batch_draw_vao_clear();
+}
+
void BLF_cache_clear(void)
{
FontBLF *font;
@@ -138,8 +144,10 @@ void BLF_cache_clear(void)
for (i = 0; i < BLF_MAX_FONT; i++) {
font = global_font[i];
- if (font)
+ if (font) {
blf_glyph_cache_clear(font);
+ blf_kerning_cache_clear(font);
+ }
}
}
@@ -176,6 +184,12 @@ void BLF_default_set(int fontid)
}
}
+int BLF_default(void)
+{
+ ASSERT_DEFAULT_SET;
+ return global_font_default;
+}
+
void BLF_antialias_set(bool enabled)
{
global_use_antialias = enabled;
@@ -369,24 +383,6 @@ void BLF_disable(int fontid, int option)
}
}
-void BLF_enable_default(int option)
-{
- FontBLF *font = blf_get(global_font_default);
-
- if (font) {
- font->flags |= option;
- }
-}
-
-void BLF_disable_default(int option)
-{
- FontBLF *font = blf_get(global_font_default);
-
- if (font) {
- font->flags &= ~option;
- }
-}
-
void BLF_aspect(int fontid, float x, float y, float z)
{
FontBLF *font = blf_get(fontid);
@@ -465,6 +461,7 @@ void BLF_size(int fontid, int size, int dpi)
}
}
+#if BLF_BLUR_ENABLE
void BLF_blur(int fontid, int size)
{
FontBLF *font = blf_get(fontid);
@@ -473,6 +470,97 @@ void BLF_blur(int fontid, int size)
font->blur = size;
}
}
+#endif
+
+void BLF_color4ubv(int fontid, const unsigned char rgba[4])
+{
+ FontBLF *font = blf_get(fontid);
+
+ if (font) {
+ font->color[0] = rgba[0];
+ font->color[1] = rgba[1];
+ font->color[2] = rgba[2];
+ font->color[3] = rgba[3];
+ }
+}
+
+void BLF_color3ubv_alpha(int fontid, const unsigned char rgb[3], unsigned char alpha)
+{
+ FontBLF *font = blf_get(fontid);
+
+ if (font) {
+ font->color[0] = rgb[0];
+ font->color[1] = rgb[1];
+ font->color[2] = rgb[2];
+ font->color[3] = alpha;
+ }
+}
+
+void BLF_color3ubv(int fontid, const unsigned char rgb[3])
+{
+ BLF_color3ubv_alpha(fontid, rgb, 255);
+}
+
+void BLF_color3ub(int fontid, unsigned char r, unsigned char g, unsigned char b)
+{
+ FontBLF *font = blf_get(fontid);
+
+ if (font) {
+ font->color[0] = r;
+ font->color[1] = g;
+ font->color[2] = b;
+ font->color[3] = 255;
+ }
+}
+
+void BLF_color4fv(int fontid, const float rgba[4])
+{
+ FontBLF *font = blf_get(fontid);
+
+ if (font) {
+ rgba_float_to_uchar(font->color, rgba);
+ }
+}
+
+void BLF_color4f(int fontid, float r, float g, float b, float a)
+{
+ float rgba[4] = { r, g, b, a };
+ BLF_color4fv(fontid, rgba);
+}
+
+void BLF_color3fv_alpha(int fontid, const float rgb[3], float alpha)
+{
+ float rgba[4];
+ copy_v3_v3(rgba, rgb);
+ rgba[3] = alpha;
+ BLF_color4fv(fontid, rgba);
+}
+
+void BLF_color3f(int fontid, float r, float g, float b)
+{
+ float rgba[4] = { r, g, b, 1.0f };
+ BLF_color4fv(fontid, rgba);
+}
+
+void BLF_batch_draw_begin(void)
+{
+ BLI_assert(g_batch.enabled == false);
+ g_batch.enabled = true;
+}
+
+void BLF_batch_draw_flush(void)
+{
+ if (g_batch.enabled) {
+ blf_batch_draw();
+ }
+}
+
+void BLF_batch_draw_end(void)
+{
+ BLI_assert(g_batch.enabled == true);
+ blf_batch_draw(); /* Draw remaining glyphs */
+ g_batch.enabled = false;
+}
void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
{
@@ -493,72 +581,37 @@ void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t l
BLF_draw_ascii(global_font_default, str, len); /* XXX, use real length */
}
-void BLF_rotation_default(float angle)
-{
- FontBLF *font = blf_get(global_font_default);
-
- if (font) {
- font->angle = angle;
- }
-}
-
-static void blf_draw_gl__start(FontBLF *font, GLint *mode)
+static void blf_draw_gl__start(FontBLF *font)
{
/*
* The pixmap alignment hack is handle
* in BLF_position (old ui_rasterpos_safe).
*/
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
-#ifndef BLF_STANDALONE
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
-#endif
-
- /* Save the current matrix mode. */
- glGetIntegerv(GL_MATRIX_MODE, mode);
+ /* always bind the texture for the first glyph */
+ font->tex_bind_state = 0;
- glMatrixMode(GL_TEXTURE);
- glPushMatrix();
- glLoadIdentity();
+ if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0)
+ return; /* glyphs will be translated individually and batched. */
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
+ gpuPushMatrix();
if (font->flags & BLF_MATRIX)
- glMultMatrixf(font->m);
+ gpuMultMatrix(font->m);
- glTranslate3fv(font->pos);
+ gpuTranslate3fv(font->pos);
if (font->flags & BLF_ASPECT)
- glScalef(font->aspect[0], font->aspect[1], font->aspect[2]);
-
- if (font->flags & BLF_ROTATION) /* radians -> degrees */
- glRotatef(font->angle * (float)(180.0 / M_PI), 0.0f, 0.0f, 1.0f);
+ gpuScale3fv(font->aspect);
- if (font->shadow || font->blur)
- glGetFloatv(GL_CURRENT_COLOR, font->orig_col);
-
- /* always bind the texture for the first glyph */
- font->tex_bind_state = -1;
+ if (font->flags & BLF_ROTATION)
+ gpuRotate2D(RAD2DEG(font->angle));
}
-static void blf_draw_gl__end(GLint mode)
+static void blf_draw_gl__end(FontBLF *font)
{
- glMatrixMode(GL_TEXTURE);
- glPopMatrix();
-
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-
- if (mode != GL_MODELVIEW)
- glMatrixMode(mode);
-
-#ifndef BLF_STANDALONE
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-#endif
- glDisable(GL_BLEND);
+ if ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) != 0)
+ gpuPopMatrix();
}
void BLF_draw_ex(
@@ -566,23 +619,26 @@ void BLF_draw_ex(
struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
- GLint mode;
BLF_RESULT_CHECK_INIT(r_info);
if (font && font->glyph_cache) {
- blf_draw_gl__start(font, &mode);
+ blf_draw_gl__start(font);
if (font->flags & BLF_WORD_WRAP) {
blf_font_draw__wrap(font, str, len, r_info);
}
else {
blf_font_draw(font, str, len, r_info);
}
- blf_draw_gl__end(mode);
+ blf_draw_gl__end(font);
}
}
void BLF_draw(int fontid, const char *str, size_t len)
{
+ if (len == 0 || str[0] == '\0') {
+ return;
+ }
+
BLF_draw_ex(fontid, str, len, NULL);
}
@@ -591,12 +647,11 @@ void BLF_draw_ascii_ex(
struct ResultBLF *r_info)
{
FontBLF *font = blf_get(fontid);
- GLint mode;
BLF_RESULT_CHECK_INIT(r_info);
if (font && font->glyph_cache) {
- blf_draw_gl__start(font, &mode);
+ blf_draw_gl__start(font);
if (font->flags & BLF_WORD_WRAP) {
/* use non-ascii draw function for word-wrap */
blf_font_draw__wrap(font, str, len, r_info);
@@ -604,24 +659,31 @@ void BLF_draw_ascii_ex(
else {
blf_font_draw_ascii(font, str, len, r_info);
}
- blf_draw_gl__end(mode);
+ blf_draw_gl__end(font);
}
}
void BLF_draw_ascii(int fontid, const char *str, size_t len)
{
+ if (len == 0 || str[0] == '\0') {
+ return;
+ }
+
BLF_draw_ascii_ex(fontid, str, len, NULL);
}
int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
{
+ if (len == 0 || str[0] == '\0') {
+ return 0;
+ }
+
FontBLF *font = blf_get(fontid);
- GLint mode;
int columns = 0;
if (font && font->glyph_cache) {
- blf_draw_gl__start(font, &mode);
+ blf_draw_gl__start(font);
columns = blf_font_draw_mono(font, str, len, cwidth);
- blf_draw_gl__end(mode);
+ blf_draw_gl__end(font);
}
return columns;
@@ -701,14 +763,6 @@ void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_widt
}
}
-void BLF_width_and_height_default(const char *str, size_t len, float *r_width, float *r_height)
-{
- ASSERT_DEFAULT_SET;
-
- BLF_size(global_font_default, global_font_points, global_font_dpi);
- BLF_width_and_height(global_font_default, str, len, r_width, r_height);
-}
-
float BLF_width_ex(
int fontid, const char *str, size_t len,
struct ResultBLF *r_info)
@@ -739,14 +793,6 @@ float BLF_fixed_width(int fontid)
return 0.0f;
}
-float BLF_width_default(const char *str, size_t len)
-{
- ASSERT_DEFAULT_SET;
-
- BLF_size(global_font_default, global_font_points, global_font_dpi);
- return BLF_width(global_font_default, str, len);
-}
-
float BLF_height_ex(
int fontid, const char *str, size_t len,
struct ResultBLF *r_info)
@@ -810,15 +856,6 @@ float BLF_ascender(int fontid)
return 0.0f;
}
-float BLF_height_default(const char *str, size_t len)
-{
- ASSERT_DEFAULT_SET;
-
- BLF_size(global_font_default, global_font_points, global_font_dpi);
-
- return BLF_height(global_font_default, str, len);
-}
-
void BLF_rotation(int fontid, float angle)
{
FontBLF *font = blf_get(fontid);
@@ -840,18 +877,6 @@ void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax)
}
}
-void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax)
-{
- FontBLF *font = blf_get(global_font_default);
-
- if (font) {
- font->clip_rec.xmin = xmin;
- font->clip_rec.ymin = ymin;
- font->clip_rec.xmax = xmax;
- font->clip_rec.ymax = ymax;
- }
-}
-
void BLF_wordwrap(int fontid, int wrap_width)
{
FontBLF *font = blf_get(fontid);
@@ -867,7 +892,7 @@ void BLF_shadow(int fontid, int level, const float rgba[4])
if (font) {
font->shadow = level;
- copy_v4_v4(font->shadow_col, rgba);
+ rgba_float_to_uchar(font->shadow_color, rgba);
}
}
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c
index af0c2fab7dd..c12303dcfc0 100644
--- a/source/blender/blenfont/intern/blf_font.c
+++ b/source/blender/blenfont/intern/blf_font.c
@@ -58,6 +58,12 @@
#include "BIF_gl.h"
#include "BLF_api.h"
+#include "UI_interface.h"
+
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+#include "GPU_batch.h"
+
#include "blf_internal_types.h"
#include "blf_internal.h"
@@ -67,12 +73,157 @@
# define FT_New_Face FT_New_Face__win32_compat
#endif
+/* Batching buffer for drawing. */
+BatchBLF g_batch;
+
/* freetype2 handle ONLY for this file!. */
static FT_Library ft_lib;
static SpinLock ft_lib_mutex;
+/* -------------------------------------------------------------------- */
+/** \name Glyph Batching
+ * \{ */
+/**
+ * Drawcalls are precious! make them count!
+ * Since most of the Text elems are not covered by other UI elements, we can
+ * group some strings together and render them in one drawcall. This behaviour
+ * is on demand only, between BLF_batch_start() and BLF_batch_end().
+ **/
+static void blf_batch_draw_init(void)
+{
+ Gwn_VertFormat format = {0};
+ g_batch.pos_loc = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ g_batch.tex_loc = GWN_vertformat_attr_add(&format, "tex", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ g_batch.col_loc = GWN_vertformat_attr_add(&format, "col", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ g_batch.verts = GWN_vertbuf_create_with_format_ex(&format, GWN_USAGE_STREAM);
+ GWN_vertbuf_data_alloc(g_batch.verts, BLF_BATCH_DRAW_LEN_MAX);
+
+ GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.tex_loc, &g_batch.tex_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step);
+ g_batch.glyph_len = 0;
+
+ g_batch.batch = GWN_batch_create_ex(GWN_PRIM_POINTS, g_batch.verts, NULL, GWN_BATCH_OWNS_VBO);
+}
+
+static void blf_batch_draw_exit(void)
+{
+ GWN_BATCH_DISCARD_SAFE(g_batch.batch);
+}
+
+void blf_batch_draw_vao_clear(void)
+{
+ if (g_batch.batch) {
+ gwn_batch_vao_cache_clear(g_batch.batch);
+ }
+}
+
+void blf_batch_draw_begin(FontBLF *font)
+{
+ if (g_batch.batch == NULL) {
+ blf_batch_draw_init();
+ }
+
+ const bool font_changed = (g_batch.font != font);
+ const bool simple_shader = ((font->flags & (BLF_ROTATION | BLF_MATRIX | BLF_ASPECT)) == 0);
+ const bool shader_changed = (simple_shader != g_batch.simple_shader);
+
+ g_batch.active = g_batch.enabled && simple_shader;
+
+ if (simple_shader) {
+ /* Offset is applied to each glyph. */
+ copy_v2_v2(g_batch.ofs, font->pos);
+ }
+ else {
+ /* Offset is baked in modelview mat. */
+ zero_v2(g_batch.ofs);
+ }
+
+ if (g_batch.active) {
+ float gpumat[4][4];
+ gpuGetModelViewMatrix(gpumat);
+
+ bool mat_changed = (memcmp(gpumat, g_batch.mat, sizeof(g_batch.mat)) != 0);
+
+ if (mat_changed) {
+ /* Modelviewmat is no longer the same.
+ * Flush cache but with the previous mat. */
+ gpuPushMatrix();
+ gpuLoadMatrix(g_batch.mat);
+ }
+
+ /* flush cache if config is not the same. */
+ if (mat_changed || font_changed || shader_changed) {
+ blf_batch_draw();
+ g_batch.simple_shader = simple_shader;
+ g_batch.font = font;
+ }
+ else {
+ /* Nothing changed continue batching. */
+ return;
+ }
+
+ if (mat_changed) {
+ gpuPopMatrix();
+ /* Save for next memcmp. */
+ memcpy(g_batch.mat, gpumat, sizeof(g_batch.mat));
+ }
+ }
+ else {
+ /* flush cache */
+ blf_batch_draw();
+ g_batch.font = font;
+ g_batch.simple_shader = simple_shader;
+ }
+}
+
+void blf_batch_draw(void)
+{
+ if (g_batch.glyph_len == 0)
+ return;
+
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ /* We need to flush widget base first to ensure correct ordering. */
+ UI_widgetbase_draw_cache_flush();
+
+ BLI_assert(g_batch.tex_bind_state != 0); /* must still be valid */
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, g_batch.tex_bind_state);
+
+ GWN_vertbuf_vertex_count_set(g_batch.verts, g_batch.glyph_len);
+ GWN_vertbuf_use(g_batch.verts); /* send data */
+
+ GPUBuiltinShader shader = (g_batch.simple_shader) ? GPU_SHADER_TEXT_SIMPLE : GPU_SHADER_TEXT;
+ GWN_batch_program_set_builtin(g_batch.batch, shader);
+ GWN_batch_uniform_1i(g_batch.batch, "glyph", 0);
+ GWN_batch_draw(g_batch.batch);
+
+ glDisable(GL_BLEND);
+
+ /* restart to 1st vertex data pointers */
+ GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.pos_loc, &g_batch.pos_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.tex_loc, &g_batch.tex_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch.verts, g_batch.col_loc, &g_batch.col_step);
+ g_batch.glyph_len = 0;
+}
+
+static void blf_batch_draw_end(void)
+{
+ if (!g_batch.active) {
+ blf_batch_draw();
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
int blf_font_init(void)
{
+ memset(&g_batch, 0, sizeof(g_batch));
BLI_spin_init(&ft_lib_mutex);
return FT_Init_FreeType(&ft_lib);
}
@@ -81,6 +232,7 @@ void blf_font_exit(void)
{
FT_Done_FreeType(ft_lib);
BLI_spin_end(&ft_lib_mutex);
+ blf_batch_draw_exit();
}
void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
@@ -88,6 +240,14 @@ void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
GlyphCacheBLF *gc;
FT_Error err;
+ gc = blf_glyph_cache_find(font, size, dpi);
+ if (gc) {
+ font->glyph_cache = gc;
+ /* Optimization: do not call FT_Set_Char_Size if size did not change. */
+ if (font->size == size && font->dpi == dpi)
+ return;
+ }
+
err = FT_Set_Char_Size(font->face, 0, (FT_F26Dot6)(size * 64), dpi, dpi);
if (err) {
/* FIXME: here we can go through the fixed size and choice a close one */
@@ -98,10 +258,7 @@ void blf_font_size(FontBLF *font, unsigned int size, unsigned int dpi)
font->size = size;
font->dpi = dpi;
- gc = blf_glyph_cache_find(font, size, dpi);
- if (gc)
- font->glyph_cache = gc;
- else {
+ if (!gc) {
gc = blf_glyph_cache_new(font);
if (gc)
font->glyph_cache = gc;
@@ -129,6 +286,20 @@ static void blf_font_ensure_ascii_table(FontBLF *font)
}
}
+static void blf_font_ensure_ascii_kerning(FontBLF *font, const FT_UInt kern_mode)
+{
+ KerningCacheBLF *kc = font->kerning_cache;
+
+ font->kerning_mode = kern_mode;
+
+ if (!kc || kc->mode != kern_mode) {
+ font->kerning_cache = kc = blf_kerning_cache_find(font);
+ if (!kc) {
+ font->kerning_cache = kc = blf_kerning_cache_new(font);
+ }
+ }
+}
+
/* Fast path for runs of ASCII characters. Given that common UTF-8
* input will consist of an overwhelming majority of ASCII
* characters.
@@ -156,6 +327,26 @@ static void blf_font_ensure_ascii_table(FontBLF *font)
(((_font)->flags & BLF_KERNING_DEFAULT) ? \
ft_kerning_default : (FT_UInt)FT_KERNING_UNFITTED) \
+/* Note,
+ * blf_font_ensure_ascii_kerning(font, kern_mode); must be called before this macro */
+
+#define BLF_KERNING_STEP_FAST(_font, _kern_mode, _g_prev, _g, _c_prev, _c, _pen_x) \
+{ \
+ if (_g_prev) { \
+ FT_Vector _delta; \
+ if (_c_prev < 0x80 && _c < 0x80) { \
+ _pen_x += (_font)->kerning_cache->table[_c][_c_prev]; \
+ } \
+ else if (FT_Get_Kerning((_font)->face, \
+ (_g_prev)->idx, \
+ (_g)->idx, \
+ _kern_mode, \
+ &(_delta)) == 0) \
+ { \
+ _pen_x += (int)_delta.x >> 6; \
+ } \
+ } \
+} (void)0
#define BLF_KERNING_STEP(_font, _kern_mode, _g_prev, _g, _delta, _pen_x) \
{ \
@@ -176,16 +367,23 @@ static void blf_font_draw_ex(
FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info,
int pen_y)
{
- unsigned int c;
+ unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev = NULL;
- FT_Vector delta;
int pen_x = 0;
size_t i = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
+ if (len == 0) {
+ /* early output, don't do any IMM OpenGL. */
+ return;
+ }
+
BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
+ blf_font_ensure_ascii_kerning(font, kern_mode);
+
+ blf_batch_draw_begin(font);
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
@@ -195,15 +393,18 @@ static void blf_font_draw_ex(
if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
- BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+ BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
pen_x += g->advance_i;
g_prev = g;
+ c_prev = c;
}
+ blf_batch_draw_end();
+
if (r_info) {
r_info->lines = 1;
r_info->width = pen_x;
@@ -219,30 +420,35 @@ static void blf_font_draw_ascii_ex(
FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info,
int pen_y)
{
- unsigned char c;
+ unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev = NULL;
- FT_Vector delta;
int pen_x = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
+ blf_font_ensure_ascii_kerning(font, kern_mode);
+
+ blf_batch_draw_begin(font);
while ((c = *(str++)) && len--) {
BLI_assert(c < 128);
if ((g = glyph_ascii_table[c]) == NULL)
continue;
if (has_kerning)
- BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+ BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
/* do not return this loop if clipped, we want every character tested */
blf_glyph_render(font, g, (float)pen_x, (float)pen_y);
pen_x += g->advance_i;
g_prev = g;
+ c_prev = c;
}
+ blf_batch_draw_end();
+
if (r_info) {
r_info->lines = 1;
r_info->width = pen_x;
@@ -265,6 +471,8 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
blf_font_ensure_ascii_table(font);
+ blf_batch_draw_begin(font);
+
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
@@ -284,6 +492,8 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
pen_x += cwidth * col;
}
+ blf_batch_draw_end();
+
return columns;
}
@@ -292,9 +502,8 @@ static void blf_font_draw_buffer_ex(
FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info,
int pen_y)
{
- unsigned int c;
+ unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev = NULL;
- FT_Vector delta;
int pen_x = (int)font->pos[0];
int pen_y_basis = (int)font->pos[1] + pen_y;
size_t i = 0;
@@ -310,6 +519,7 @@ static void blf_font_draw_buffer_ex(
BLF_KERNING_VARS(font, has_kerning, kern_mode);
blf_font_ensure_ascii_table(font);
+ blf_font_ensure_ascii_kerning(font, kern_mode);
/* another buffer specific call for color conversion */
@@ -321,7 +531,7 @@ static void blf_font_draw_buffer_ex(
if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
- BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+ BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
chx = pen_x + ((int)g->pos_x);
chy = pen_y_basis + g->height;
@@ -423,6 +633,7 @@ static void blf_font_draw_buffer_ex(
pen_x += g->advance_i;
g_prev = g;
+ c_prev = c;
}
if (r_info) {
@@ -570,9 +781,8 @@ static void blf_font_boundbox_ex(
FontBLF *font, const char *str, size_t len, rctf *box, struct ResultBLF *r_info,
int pen_y)
{
- unsigned int c;
+ unsigned int c, c_prev = BLI_UTF8_ERR;
GlyphBLF *g, *g_prev = NULL;
- FT_Vector delta;
int pen_x = 0;
size_t i = 0;
GlyphBLF **glyph_ascii_table = font->glyph_cache->glyph_ascii_table;
@@ -587,6 +797,7 @@ static void blf_font_boundbox_ex(
box->ymax = -32000.0f;
blf_font_ensure_ascii_table(font);
+ blf_font_ensure_ascii_kerning(font, kern_mode);
while ((i < len) && str[i]) {
BLF_UTF8_NEXT_FAST(font, g, str, i, c, glyph_ascii_table);
@@ -596,7 +807,7 @@ static void blf_font_boundbox_ex(
if (UNLIKELY(g == NULL))
continue;
if (has_kerning)
- BLF_KERNING_STEP(font, kern_mode, g_prev, g, delta, pen_x);
+ BLF_KERNING_STEP_FAST(font, kern_mode, g_prev, g, c_prev, c, pen_x);
gbox.xmin = (float)pen_x;
gbox.xmax = (float)pen_x + g->advance;
@@ -611,6 +822,7 @@ static void blf_font_boundbox_ex(
pen_x += g->advance_i;
g_prev = g;
+ c_prev = c;
}
if (box->xmin > box->xmax) {
@@ -891,6 +1103,8 @@ void blf_font_free(FontBLF *font)
blf_glyph_cache_free(gc);
}
+ blf_kerning_cache_clear(font);
+
FT_Done_Face(font->face);
if (font->filename)
MEM_freeN(font->filename);
@@ -901,8 +1115,6 @@ void blf_font_free(FontBLF *font)
static void blf_font_fill(FontBLF *font)
{
- unsigned int i;
-
font->aspect[0] = 1.0f;
font->aspect[1] = 1.0f;
font->aspect[2] = 1.0f;
@@ -910,9 +1122,15 @@ static void blf_font_fill(FontBLF *font)
font->pos[1] = 0.0f;
font->angle = 0.0f;
- for (i = 0; i < 16; i++)
+ for (int i = 0; i < 16; i++)
font->m[i] = 0;
+ /* annoying bright color so we can see where to add BLF_color calls */
+ font->color[0] = 255;
+ font->color[1] = 255;
+ font->color[2] = 0;
+ font->color[3] = 255;
+
font->clip_rec.xmin = 0.0f;
font->clip_rec.xmax = 0.0f;
font->clip_rec.ymin = 0.0f;
@@ -921,8 +1139,12 @@ static void blf_font_fill(FontBLF *font)
font->dpi = 0;
font->size = 0;
BLI_listbase_clear(&font->cache);
+ BLI_listbase_clear(&font->kerning_caches);
font->glyph_cache = NULL;
+ font->kerning_cache = NULL;
+#if BLF_BLUR_ENABLE
font->blur = 0;
+#endif
font->tex_size_max = -1;
font->buf_info.fbuf = NULL;
diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c
index 60dfdae519b..9baa586eef5 100644
--- a/source/blender/blenfont/intern/blf_glyph.c
+++ b/source/blender/blenfont/intern/blf_glyph.c
@@ -56,13 +56,68 @@
#include "BLF_api.h"
#ifndef BLF_STANDALONE
-# include "GPU_basic_shader.h"
+# include "GPU_immediate.h"
#endif
#include "blf_internal_types.h"
#include "blf_internal.h"
#include "BLI_strict_flags.h"
+#include "BLI_math_vector.h"
+
+KerningCacheBLF *blf_kerning_cache_find(FontBLF *font)
+{
+ KerningCacheBLF *p;
+
+ p = (KerningCacheBLF *)font->kerning_caches.first;
+ while (p) {
+ if (p->mode == font->kerning_mode)
+ return p;
+ p = p->next;
+ }
+ return NULL;
+}
+
+/* Create a new glyph cache for the current kerning mode. */
+KerningCacheBLF *blf_kerning_cache_new(FontBLF *font)
+{
+ KerningCacheBLF *kc;
+
+ kc = (KerningCacheBLF *)MEM_callocN(sizeof(KerningCacheBLF), "blf_kerning_cache_new");
+ kc->next = NULL;
+ kc->prev = NULL;
+ kc->mode = font->kerning_mode;
+
+ unsigned int i, j;
+ for (i = 0; i < 0x80; i++) {
+ for (j = 0; j < 0x80; j++) {
+ GlyphBLF *g = blf_glyph_search(font->glyph_cache, i);
+ if (!g) {
+ FT_UInt glyph_index = FT_Get_Char_Index(font->face, i);
+ g = blf_glyph_add(font, glyph_index, i);
+ }
+ /* Cannot fail since it has been added just before. */
+ GlyphBLF *g_prev = blf_glyph_search(font->glyph_cache, j);
+
+ FT_Vector delta = {.x = 0, .y = 0};
+ if (FT_Get_Kerning(font->face, g_prev->idx, g->idx, kc->mode, &delta) == 0) {
+ kc->table[i][j] = (int)delta.x >> 6;
+ }
+ else {
+ kc->table[i][j] = 0;
+ }
+ }
+ }
+
+ BLI_addhead(&font->kerning_caches, kc);
+ return kc;
+}
+
+void blf_kerning_cache_clear(FontBLF *font)
+{
+ font->kerning_cache = NULL;
+ BLI_freelistN(&font->kerning_caches);
+}
GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, unsigned int size, unsigned int dpi)
{
@@ -94,9 +149,9 @@ GlyphCacheBLF *blf_glyph_cache_new(FontBLF *font)
gc->textures = (GLuint *)MEM_mallocN(sizeof(GLuint) * 256, __func__);
gc->textures_len = 256;
gc->texture_current = BLF_TEXTURE_UNSET;
- gc->offset_x = 0;
- gc->offset_y = 0;
- gc->pad = 3;
+ gc->offset_x = 3; /* enough padding for blur */
+ gc->offset_y = 3; /* enough padding for blur */
+ gc->pad = 6;
gc->glyphs_len_max = (int)font->face->num_glyphs;
gc->glyphs_len_free = (int)font->face->num_glyphs;
@@ -174,7 +229,7 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc)
}
i = (int)((gc->p2_width - (gc->pad * 2)) / gc->glyph_width_max);
- gc->p2_height = (int)blf_next_p2((unsigned int)(((gc->glyphs_len_max / i) + 1) * gc->glyph_height_max));
+ gc->p2_height = (int)blf_next_p2((unsigned int)(((gc->glyphs_len_max / i) + 1) * gc->glyph_height_max + (gc->pad * 2)));
if (gc->p2_height > font->tex_size_max) {
gc->p2_height = font->tex_size_max;
@@ -184,20 +239,12 @@ static void blf_glyph_cache_texture(FontBLF *font, GlyphCacheBLF *gc)
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = gc->textures[gc->texture_current]));
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-#ifndef BLF_STANDALONE
- /* needed since basic shader doesn't support alpha-only textures,
- * while we could add support this is only used in a few places
- * (an alternative could be to have a simple shader for BLF). */
- if (GLEW_ARB_texture_swizzle && GPU_basic_shader_use_glsl_get()) {
- GLint swizzle_mask[] = {GL_ONE, GL_ONE, GL_ONE, GL_ALPHA};
- glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzle_mask);
- }
-#endif
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, gc->p2_width, gc->p2_height, 0, GL_ALPHA, GL_UNSIGNED_BYTE, NULL);
+ unsigned char *pixels = MEM_callocN((size_t)gc->p2_width * (size_t)gc->p2_height, "BLF texture init");
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, gc->p2_width, gc->p2_height, 0, GL_RED, GL_UNSIGNED_BYTE, pixels);
+ MEM_freeN(pixels);
}
GlyphBLF *blf_glyph_search(GlyphCacheBLF *gc, unsigned int c)
@@ -296,8 +343,8 @@ GlyphBLF *blf_glyph_add(FontBLF *font, unsigned int index, unsigned int c)
}
}
- g->bitmap = (unsigned char *)MEM_mallocN((size_t)(g->width * g->height), "glyph bitmap");
- memcpy((void *)g->bitmap, (void *)bitmap.buffer, (size_t)(g->width * g->height));
+ g->bitmap = (unsigned char *)MEM_mallocN((size_t)g->width * (size_t)g->height, "glyph bitmap");
+ memcpy((void *)g->bitmap, (void *)bitmap.buffer, (size_t)g->width * (size_t)g->height);
}
g->advance = ((float)slot->advance.x) / 64.0f;
@@ -325,79 +372,54 @@ void blf_glyph_free(GlyphBLF *g)
/* don't need free the texture, the GlyphCache already
* have a list of all the texture and free it.
*/
- if (g->bitmap) {
+ if (g->bitmap)
MEM_freeN(g->bitmap);
- }
MEM_freeN(g);
}
-static void blf_texture_draw(float uv[2][2], float dx, float y1, float dx1, float y2)
+static void blf_texture_draw(const unsigned char color[4], const float uv[2][2], float x1, float y1, float x2, float y2)
{
- glBegin(GL_QUADS);
- glTexCoord2f(uv[0][0], uv[0][1]);
- glVertex2f(dx, y1);
-
- glTexCoord2f(uv[0][0], uv[1][1]);
- glVertex2f(dx, y2);
-
- glTexCoord2f(uv[1][0], uv[1][1]);
- glVertex2f(dx1, y2);
-
- glTexCoord2f(uv[1][0], uv[0][1]);
- glVertex2f(dx1, y1);
- glEnd();
+ /* Only one vertex per glyph, geometry shader expand it into a quad. */
+ /* TODO Get rid of Geom Shader because it's not optimal AT ALL for the GPU */
+ copy_v4_fl4(GWN_vertbuf_raw_step(&g_batch.pos_step), x1 + g_batch.ofs[0], y1 + g_batch.ofs[1],
+ x2 + g_batch.ofs[0], y2 + g_batch.ofs[1]);
+ copy_v4_v4(GWN_vertbuf_raw_step(&g_batch.tex_step), (float *)uv);
+ copy_v4_v4_uchar(GWN_vertbuf_raw_step(&g_batch.col_step), color);
+ g_batch.glyph_len++;
+ /* Flush cache if it's full. */
+ if (g_batch.glyph_len == BLF_BATCH_DRAW_LEN_MAX) {
+ blf_batch_draw();
+ }
}
-static void blf_texture5_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2)
+static void blf_texture5_draw(const unsigned char color_in[4], int tex_w, int tex_h, const float uv[2][2],
+ float x1, float y1, float x2, float y2)
{
- const float soft[25] = {1 / 60.0f, 1 / 60.0f, 2 / 60.0f, 1 / 60.0f, 1 / 60.0f,
- 1 / 60.0f, 3 / 60.0f, 5 / 60.0f, 3 / 60.0f, 1 / 60.0f,
- 2 / 60.0f, 5 / 60.0f, 8 / 60.0f, 5 / 60.0f, 2 / 60.0f,
- 1 / 60.0f, 3 / 60.0f, 5 / 60.0f, 3 / 60.0f, 1 / 60.0f,
- 1 / 60.0f, 1 / 60.0f, 2 / 60.0f, 1 / 60.0f, 1 / 60.0f};
-
- const float *fp = soft;
- float color[4];
- float dx, dy;
-
- color[0] = shadow_col[0];
- color[1] = shadow_col[1];
- color[2] = shadow_col[2];
-
- for (dx = -2; dx < 3; dx++) {
- for (dy = -2; dy < 3; dy++, fp++) {
- color[3] = *(fp) * shadow_col[3];
- glColor4fv(color);
- blf_texture_draw(uv, x1 + dx, y1 + dy, x2 + dx, y2 + dy);
- }
- }
-
- glColor4fv(color);
+ float ofs[2] = { 2 / (float)tex_w, 2 / (float)tex_h };
+ float uv_flag[2][2];
+ copy_v4_v4((float *)uv_flag, (float *)uv);
+ /* flag the x and y component signs for 5x5 bluring */
+ uv_flag[0][0] = -(uv_flag[0][0] - ofs[0]);
+ uv_flag[0][1] = -(uv_flag[0][1] - ofs[1]);
+ uv_flag[1][0] = -(uv_flag[1][0] + ofs[0]);
+ uv_flag[1][1] = -(uv_flag[1][1] + ofs[1]);
+
+ blf_texture_draw(color_in, uv_flag, x1 - 2, y1 + 2, x2 + 2, y2 - 2);
}
-static void blf_texture3_draw(const float shadow_col[4], float uv[2][2], float x1, float y1, float x2, float y2)
+static void blf_texture3_draw(const unsigned char color_in[4], int tex_w, int tex_h, const float uv[2][2],
+ float x1, float y1, float x2, float y2)
{
- const float soft[9] = {1 / 16.0f, 2 / 16.0f, 1 / 16.0f,
- 2 / 16.0f, 4 / 16.0f, 2 / 16.0f,
- 1 / 16.0f, 2 / 16.0f, 1 / 16.0f};
-
- const float *fp = soft;
- float color[4];
- float dx, dy;
-
- color[0] = shadow_col[0];
- color[1] = shadow_col[1];
- color[2] = shadow_col[2];
-
- for (dx = -1; dx < 2; dx++) {
- for (dy = -1; dy < 2; dy++, fp++) {
- color[3] = *(fp) * shadow_col[3];
- glColor4fv(color);
- blf_texture_draw(uv, x1 + dx, y1 + dy, x2 + dx, y2 + dy);
- }
- }
-
- glColor4fv(color);
+ float ofs[2] = { 1 / (float)tex_w, 1 / (float)tex_h };
+ float uv_flag[2][2];
+ copy_v4_v4((float *)uv_flag, (float *)uv);
+ /* flag the x component sign for 3x3 bluring */
+ uv_flag[0][0] = -(uv_flag[0][0] - ofs[0]);
+ uv_flag[0][1] = (uv_flag[0][1] - ofs[1]);
+ uv_flag[1][0] = -(uv_flag[1][0] + ofs[0]);
+ uv_flag[1][1] = (uv_flag[1][1] + ofs[1]);
+
+ blf_texture_draw(color_in, uv_flag, x1 - 1, y1 + 1, x2 + 1, y2 - 1);
}
static void blf_glyph_calc_rect(rctf *rect, GlyphBLF *g, float x, float y)
@@ -415,6 +437,8 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
if ((!g->width) || (!g->height))
return;
+ glActiveTexture(GL_TEXTURE0);
+
if (g->build_tex == 0) {
GlyphCacheBLF *gc = font->glyph_cache;
@@ -424,7 +448,7 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
if (gc->texture_current == BLF_TEXTURE_UNSET) {
blf_glyph_cache_texture(font, gc);
gc->offset_x = gc->pad;
- gc->offset_y = 0;
+ gc->offset_y = 3; /* enough padding for blur */
}
if (gc->offset_x > (gc->p2_width - gc->glyph_width_max)) {
@@ -432,7 +456,7 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
gc->offset_y += gc->glyph_height_max;
if (gc->offset_y > (gc->p2_height - gc->glyph_height_max)) {
- gc->offset_y = 0;
+ gc->offset_y = 3; /* enough padding for blur */
blf_glyph_cache_texture(font, gc);
}
}
@@ -454,14 +478,21 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
}
- glPushClientAttrib(GL_CLIENT_PIXEL_STORE_BIT);
+ GLint lsb_first, row_length, alignment;
+ glGetIntegerv(GL_UNPACK_LSB_FIRST, &lsb_first);
+ glGetIntegerv(GL_UNPACK_ROW_LENGTH, &row_length);
+ glGetIntegerv(GL_UNPACK_ALIGNMENT, &alignment);
+
glPixelStorei(GL_UNPACK_LSB_FIRST, GL_FALSE);
glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glBindTexture(GL_TEXTURE_2D, g->tex);
- glTexSubImage2D(GL_TEXTURE_2D, 0, g->offset_x, g->offset_y, g->width, g->height, GL_ALPHA, GL_UNSIGNED_BYTE, g->bitmap);
- glPopClientAttrib();
+ glTexSubImage2D(GL_TEXTURE_2D, 0, g->offset_x, g->offset_y, g->width, g->height, GL_RED, GL_UNSIGNED_BYTE, g->bitmap);
+
+ glPixelStorei(GL_UNPACK_LSB_FIRST, lsb_first);
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, alignment);
g->uv[0][0] = ((float)g->offset_x) / ((float)gc->p2_width);
g->uv[0][1] = ((float)g->offset_y) / ((float)gc->p2_height);
@@ -488,42 +519,45 @@ void blf_glyph_render(FontBLF *font, GlyphBLF *g, float x, float y)
}
if (font->tex_bind_state != g->tex) {
+ blf_batch_draw();
glBindTexture(GL_TEXTURE_2D, (font->tex_bind_state = g->tex));
}
+ g_batch.tex_bind_state = g->tex;
+
if (font->flags & BLF_SHADOW) {
rctf rect_ofs;
blf_glyph_calc_rect(&rect_ofs, g,
x + (float)font->shadow_x,
y + (float)font->shadow_y);
- switch (font->shadow) {
- case 3:
- blf_texture3_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
- break;
- case 5:
- blf_texture5_draw(font->shadow_col, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
- break;
- default:
- glColor4fv(font->shadow_col);
- blf_texture_draw(g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
- break;
+ if (font->shadow == 0) {
+ blf_texture_draw(font->shadow_color, g->uv, rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
+ }
+ else if (font->shadow <= 4) {
+ blf_texture3_draw(font->shadow_color, font->glyph_cache->p2_width, font->glyph_cache->p2_height, g->uv,
+ rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
+ }
+ else {
+ blf_texture5_draw(font->shadow_color, font->glyph_cache->p2_width, font->glyph_cache->p2_height, g->uv,
+ rect_ofs.xmin, rect_ofs.ymin, rect_ofs.xmax, rect_ofs.ymax);
}
-
- glColor4fv(font->orig_col);
}
+#if BLF_BLUR_ENABLE
switch (font->blur) {
case 3:
- blf_texture3_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+ blf_texture3_draw(font->color, font->glyph_cache->p2_width, font->glyph_cache->p2_height, g->uv,
+ rect.xmin, rect.ymin, rect.xmax, rect.ymax);
break;
case 5:
- blf_texture5_draw(font->orig_col, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+ blf_texture5_draw(font->color, font->glyph_cache->p2_width, font->glyph_cache->p2_height, g->uv,
+ rect.xmin, rect.ymin, rect.xmax, rect.ymax);
break;
default:
- blf_texture_draw(g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
- break;
+ blf_texture_draw(font->color, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
}
-
- return;
+#else
+ blf_texture_draw(font->color, g->uv, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+#endif
}
diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h
index d9d758ce548..b48bd2fbae7 100644
--- a/source/blender/blenfont/intern/blf_internal.h
+++ b/source/blender/blenfont/intern/blf_internal.h
@@ -37,6 +37,10 @@ struct GlyphBLF;
struct GlyphCacheBLF;
struct rctf;
+void blf_batch_draw_vao_clear(void);
+void blf_batch_draw_begin(struct FontBLF *font);
+void blf_batch_draw(void);
+
unsigned int blf_next_p2(unsigned int x);
unsigned int blf_hash(unsigned int val);
@@ -74,6 +78,10 @@ int blf_font_count_missing_chars(struct FontBLF *font, const char *str, const si
void blf_font_free(struct FontBLF *font);
+struct KerningCacheBLF *blf_kerning_cache_find(struct FontBLF *font);
+struct KerningCacheBLF *blf_kerning_cache_new(struct FontBLF *font);
+void blf_kerning_cache_clear(struct FontBLF *font);
+
struct GlyphCacheBLF *blf_glyph_cache_find(struct FontBLF *font, unsigned int size, unsigned int dpi);
struct GlyphCacheBLF *blf_glyph_cache_new(struct FontBLF *font);
void blf_glyph_cache_clear(struct FontBLF *font);
diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h
index ced8064302b..c80b5422061 100644
--- a/source/blender/blenfont/intern/blf_internal_types.h
+++ b/source/blender/blenfont/intern/blf_internal_types.h
@@ -31,6 +31,36 @@
#ifndef __BLF_INTERNAL_TYPES_H__
#define __BLF_INTERNAL_TYPES_H__
+#include "../../../intern/gawain/gawain/gwn_vertex_buffer.h"
+
+#define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */
+
+typedef struct BatchBLF {
+ struct FontBLF *font; /* can only batch glyph from the same font */
+ struct Gwn_Batch *batch;
+ struct Gwn_VertBuf *verts;
+ struct Gwn_VertBufRaw pos_step, tex_step, col_step;
+ unsigned int pos_loc, tex_loc, col_loc;
+ unsigned int glyph_len;
+ float ofs[2]; /* copy of font->pos */
+ float mat[4][4]; /* previous call modelmatrix. */
+ bool enabled, active, simple_shader;
+ unsigned int tex_bind_state;
+} BatchBLF;
+
+extern BatchBLF g_batch;
+
+typedef struct KerningCacheBLF {
+ struct KerningCacheBLF *next, *prev;
+
+ /* kerning mode. */
+ FT_UInt mode;
+
+ /* only cache a ascii glyph pairs. Only store the x
+ * offset we are interested in, instead of the full FT_Vector. */
+ int table[0x80][0x80];
+} KerningCacheBLF;
+
typedef struct GlyphCacheBLF {
struct GlyphCacheBLF *next;
struct GlyphCacheBLF *prev;
@@ -175,8 +205,10 @@ typedef struct FontBLF {
/* angle in radians. */
float angle;
+#if 0 /* BLF_BLUR_ENABLE */
/* blur: 3 or 5 large kernel */
int blur;
+#endif
/* shadow level. */
int shadow;
@@ -186,10 +218,10 @@ typedef struct FontBLF {
int shadow_y;
/* shadow color. */
- float shadow_col[4];
+ unsigned char shadow_color[4];
- /* store color here when drawing shadow or blur. */
- float orig_col[4];
+ /* main text color. */
+ unsigned char color[4];
/* Multiplied this matrix with the current one before
* draw the text! see blf_draw__start.
@@ -223,6 +255,12 @@ typedef struct FontBLF {
/* current glyph cache, size and dpi. */
GlyphCacheBLF *glyph_cache;
+ /* list of kerning cache for this font. */
+ ListBase kerning_caches;
+
+ /* current kerning cache for this font and kerning mode. */
+ KerningCacheBLF *kerning_cache;
+
/* freetype2 lib handle. */
FT_Library ft_lib;
@@ -232,6 +270,9 @@ typedef struct FontBLF {
/* freetype2 face. */
FT_Face face;
+ /* freetype kerning */
+ FT_UInt kerning_mode;
+
/* data for buffer usage (drawing into a texture buffer) */
FontBufInfoBLF buf_info;
} FontBLF;
diff --git a/source/blender/blenkernel/BKE_DerivedMesh.h b/source/blender/blenkernel/BKE_DerivedMesh.h
index 4d2e9ef8b3c..74416bcd18f 100644
--- a/source/blender/blenkernel/BKE_DerivedMesh.h
+++ b/source/blender/blenkernel/BKE_DerivedMesh.h
@@ -95,8 +95,8 @@ struct KeyBlock;
struct ModifierData;
struct MCol;
struct ColorBand;
+struct Depsgraph;
struct GPUVertexAttribs;
-struct GPUDrawObject;
struct PBVH;
/* number of sub-elements each mesh element has (for interpolation) */
@@ -126,36 +126,6 @@ typedef enum DerivedMeshType {
DM_TYPE_CCGDM
} DerivedMeshType;
-typedef enum DMDrawOption {
- /* the element is hidden or otherwise non-drawable */
- DM_DRAW_OPTION_SKIP = 0,
- /* normal drawing */
- DM_DRAW_OPTION_NORMAL = 1,
- /* draw, but don't set the color from mcol */
- DM_DRAW_OPTION_NO_MCOL = 2,
- /* used in drawMappedFaces, use GL stipple for the face */
- DM_DRAW_OPTION_STIPPLE = 3,
-} DMDrawOption;
-
-/* Drawing callback types */
-typedef int (*DMSetMaterial)(int mat_nr, void *attribs);
-typedef int (*DMCompareDrawOptions)(void *userData, int cur_index, int next_index);
-typedef void (*DMSetDrawInterpOptions)(void *userData, int index, float t);
-typedef DMDrawOption (*DMSetDrawOptions)(void *userData, int index);
-typedef DMDrawOption (*DMSetDrawOptionsMappedTex)(void *userData, int origindex, int mat_nr);
-typedef DMDrawOption (*DMSetDrawOptionsTex)(struct MTexPoly *mtexpoly, const bool has_vcol, int matnr);
-
-typedef enum DMDrawFlag {
- DM_DRAW_USE_COLORS = (1 << 0),
- DM_DRAW_ALWAYS_SMOOTH = (1 << 1),
- DM_DRAW_USE_ACTIVE_UV = (1 << 2),
- DM_DRAW_USE_TEXPAINT_UV = (1 << 3),
- DM_DRAW_SKIP_HIDDEN = (1 << 4),
- DM_DRAW_SKIP_SELECT = (1 << 5),
- DM_DRAW_SELECT_USE_EDITMODE = (1 << 6),
- DM_DRAW_NEED_NORMALS = (1 << 7)
-} DMDrawFlag;
-
typedef enum DMForeachFlag {
DM_FOREACH_NOP = 0,
DM_FOREACH_USE_NORMAL = (1 << 0), /* foreachMappedVert, foreachMappedLoop, foreachMappedFaceCenter */
@@ -164,14 +134,9 @@ typedef enum DMForeachFlag {
typedef enum DMDirtyFlag {
/* dm has valid tessellated faces, but tessellated CDDATA need to be updated. */
DM_DIRTY_TESS_CDLAYERS = 1 << 0,
- /* One of the MCOL layers have been updated, force updating of GPUDrawObject's colors buffer.
- * This is necessary with modern, VBO draw code, as e.g. in vpaint mode me->mcol may be updated
- * without actually rebuilding dm (hence by default keeping same GPUDrawObject, and same colors
- * buffer, which prevents update during a stroke!). */
- DM_DIRTY_MCOL_UPDATE_DRAW = 1 << 1,
/* check this with modifier dependsOnNormals callback to see if normals need recalculation */
- DM_DIRTY_NORMALS = 1 << 2,
+ DM_DIRTY_NORMALS = 1 << 1,
} DMDirtyFlag;
typedef struct DerivedMesh DerivedMesh;
@@ -182,9 +147,7 @@ struct DerivedMesh {
int needsFree; /* checked on ->release, is set to 0 for cached results */
int deformedOnly; /* set by modifier stack if only deformed from original */
BVHCache *bvhCache;
- struct GPUDrawObject *drawObject;
DerivedMeshType type;
- float auto_bump_scale;
DMDirtyFlag dirty;
int totmat; /* total materials. Will be valid only before object drawing. */
struct Material **mat; /* material array. Will be valid only before object drawing */
@@ -384,117 +347,6 @@ struct DerivedMesh {
*/
struct PBVH *(*getPBVH)(struct Object *ob, DerivedMesh *dm);
- /* Drawing Operations */
-
- /** Draw all vertices as bgl points (no options) */
- void (*drawVerts)(DerivedMesh *dm);
-
- /** Draw edges in the UV mesh (if exists) */
- void (*drawUVEdges)(DerivedMesh *dm);
-
- /** Draw all edges as lines (no options)
- *
- * Also called for *final* editmode DerivedMeshes
- */
- void (*drawEdges)(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEdges);
-
- /** Draw all loose edges (edges w/ no adjoining faces) */
- void (*drawLooseEdges)(DerivedMesh *dm);
-
- /** Draw all faces
- * o Set face normal or vertex normal based on inherited face flag
- * o Use inherited face material index to call setMaterial
- * o Only if setMaterial returns true
- *
- * Also called for *final* editmode DerivedMeshes
- */
- void (*drawFacesSolid)(DerivedMesh *dm, float (*partial_redraw_planes)[4],
- bool fast, DMSetMaterial setMaterial);
-
- /** Draw all faces using MTFace
- * - Drawing options too complicated to enumerate, look at code.
- */
- void (*drawFacesTex)(DerivedMesh *dm,
- DMSetDrawOptionsTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag);
-
- /** Draw all faces with GLSL materials
- * o setMaterial is called for every different material nr
- * o Only if setMaterial returns true
- */
- void (*drawFacesGLSL)(DerivedMesh *dm, DMSetMaterial setMaterial);
-
- /** Draw mapped faces (no color, or texture)
- * - Only if !setDrawOptions or
- * setDrawOptions(userData, mapped-face-index, r_drawSmooth)
- * returns true
- *
- * If drawSmooth is set to true then vertex normals should be set and
- * glShadeModel called with GL_SMOOTH. Otherwise the face normal should
- * be set and glShadeModel called with GL_FLAT.
- *
- * The setDrawOptions is allowed to not set drawSmooth (for example, when
- * lighting is disabled), in which case the implementation should draw as
- * smooth shaded.
- */
- void (*drawMappedFaces)(DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetMaterial setMaterial,
- DMCompareDrawOptions compareDrawOptions,
- void *userData,
- DMDrawFlag flag);
-
- /** Draw mapped faces using MTFace
- * - Drawing options too complicated to enumerate, look at code.
- */
- void (*drawMappedFacesTex)(DerivedMesh *dm,
- DMSetDrawOptionsMappedTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag);
-
- /** Draw mapped faces with GLSL materials
- * - setMaterial is called for every different material nr
- * - setDrawOptions is called for every face
- * - Only if setMaterial and setDrawOptions return true
- */
- void (*drawMappedFacesGLSL)(DerivedMesh *dm,
- DMSetMaterial setMaterial,
- DMSetDrawOptions setDrawOptions,
- void *userData);
-
- /** Draw mapped edges as lines
- * - Only if !setDrawOptions or setDrawOptions(userData, mapped-edge)
- * returns true
- */
- void (*drawMappedEdges)(DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- void *userData);
-
- /** Draw mapped edges as lines with interpolation values
- * - Only if !setDrawOptions or
- * setDrawOptions(userData, mapped-edge, mapped-v0, mapped-v1, t)
- * returns true
- *
- * NOTE: This routine is optional!
- */
- void (*drawMappedEdgesInterp)(DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetDrawInterpOptions setDrawInterpOptions,
- void *userData);
-
- /** Draw all faces with materials
- * - setMaterial is called for every different material nr
- * - setFace is called to verify if a face must be hidden
- */
- void (*drawMappedFacesMat)(DerivedMesh *dm,
- void (*setMaterial)(void *userData, int matnr, void *attribs),
- bool (*setFace)(void *userData, int index), void *userData);
-
- struct GPUDrawObject *(*gpuObjectNew)(DerivedMesh *dm);
- void (*copy_gpu_data)(DerivedMesh *dm, int type, void *varray_p,
- const int *mat_orig_to_new, const void *user_data);
-
/** Release reference to the DerivedMesh. This function decides internally
* if the DerivedMesh will be freed, or cached for later use. */
void (*release)(DerivedMesh *dm);
@@ -680,56 +532,49 @@ void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int
/* */
DerivedMesh *mesh_get_derived_final(
- struct Scene *scene, struct Object *ob,
- CustomDataMask dataMask);
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, CustomDataMask dataMask);
DerivedMesh *mesh_get_derived_deform(
- struct Scene *scene, struct Object *ob,
- CustomDataMask dataMask);
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, CustomDataMask dataMask);
DerivedMesh *mesh_create_derived_for_modifier(
- struct Scene *scene, struct Object *ob,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
struct ModifierData *md, int build_shapekey_layers);
DerivedMesh *mesh_create_derived_render(
- struct Scene *scene, struct Object *ob,
- CustomDataMask dataMask);
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, CustomDataMask dataMask);
DerivedMesh *getEditDerivedBMesh(
struct BMEditMesh *em, struct Object *ob, CustomDataMask data_mask,
float (*vertexCos)[3]);
DerivedMesh *mesh_create_derived_index_render(
- struct Scene *scene, struct Object *ob,
- CustomDataMask dataMask, int index);
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, CustomDataMask dataMask, int index);
/* same as above but wont use render settings */
DerivedMesh *mesh_create_derived(struct Mesh *me, float (*vertCos)[3]);
DerivedMesh *mesh_create_derived_view(
- struct Scene *scene, struct Object *ob,
- CustomDataMask dataMask);
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, CustomDataMask dataMask);
DerivedMesh *mesh_create_derived_no_deform(
- struct Scene *scene, struct Object *ob,
- float (*vertCos)[3],
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, float (*vertCos)[3],
CustomDataMask dataMask);
DerivedMesh *mesh_create_derived_no_deform_render(
- struct Scene *scene, struct Object *ob,
- float (*vertCos)[3],
- CustomDataMask dataMask);
-/* for gameengine */
-DerivedMesh *mesh_create_derived_no_virtual(
- struct Scene *scene, struct Object *ob, float (*vertCos)[3],
- CustomDataMask dataMask);
-DerivedMesh *mesh_create_derived_physics(
- struct Scene *scene, struct Object *ob, float (*vertCos)[3],
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, float (*vertCos)[3],
CustomDataMask dataMask);
DerivedMesh *editbmesh_get_derived_base(
struct Object *ob, struct BMEditMesh *em, CustomDataMask data_mask);
DerivedMesh *editbmesh_get_derived_cage(
- struct Scene *scene, struct Object *,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *,
struct BMEditMesh *em, CustomDataMask dataMask);
DerivedMesh *editbmesh_get_derived_cage_and_final(
- struct Scene *scene, struct Object *,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *,
struct BMEditMesh *em, CustomDataMask dataMask,
DerivedMesh **r_final);
@@ -738,7 +583,7 @@ DerivedMesh *object_get_derived_final(struct Object *ob, const bool for_render);
float (*editbmesh_get_vertex_cos(struct BMEditMesh *em, int *r_numVerts))[3];
bool editbmesh_modifier_is_enabled(struct Scene *scene, struct ModifierData *md, DerivedMesh *dm);
void makeDerivedMesh(
- struct Scene *scene, struct Object *ob, struct BMEditMesh *em,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct BMEditMesh *em,
CustomDataMask dataMask, const bool build_shapekey_layers);
void weight_to_rgb(float r_rgb[3], const float weight);
@@ -783,25 +628,18 @@ void DM_vertex_attributes_from_gpu(
DerivedMesh *dm,
struct GPUVertexAttribs *gattribs, DMVertexAttribs *attribs);
-void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert, int loop);
-void DM_draw_attrib_vertex_uniforms(const DMVertexAttribs *attribs);
-
void DM_calc_tangents_names_from_gpu(
const struct GPUVertexAttribs *gattribs,
char (*tangent_names)[MAX_NAME], int *tangent_names_count);
+
void DM_add_named_tangent_layer_for_uv(
CustomData *uv_data, CustomData *tan_data, int numLoopData,
const char *layer_name);
-#define DM_TANGENT_MASK_ORCO (1 << 9)
-void DM_calc_loop_tangents_step_0(
- const CustomData *loopData, bool calc_active_tangent,
- const char (*tangent_names)[MAX_NAME], int tangent_names_count,
- bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
- char *ract_uv_name, char *rren_uv_name, short *rtangent_mask);
void DM_calc_loop_tangents(
DerivedMesh *dm, bool calc_active_tangent, const char (*tangent_names)[MAX_NAME],
int tangent_names_count);
+
void DM_calc_auto_bump_scale(DerivedMesh *dm);
/** Set object's bounding box based on DerivedMesh min/max data */
diff --git a/source/blender/blenkernel/BKE_action.h b/source/blender/blenkernel/BKE_action.h
index 1fda7f07343..8ec75bda538 100644
--- a/source/blender/blenkernel/BKE_action.h
+++ b/source/blender/blenkernel/BKE_action.h
@@ -163,9 +163,6 @@ struct bPoseChannel *BKE_pose_channel_get_mirrored(const struct bPose *pose, con
bool BKE_pose_channels_is_valid(const struct bPose *pose);
#endif
-/* Copy the data from the action-pose (src) into the pose */
-void extract_pose_from_pose(struct bPose *pose, const struct bPose *src);
-
/* sets constraint flags */
void BKE_pose_update_constraint_flags(struct bPose *pose);
@@ -211,6 +208,7 @@ void BKE_pose_rest(struct bPose *pose);
/* Tag pose for recalc. Also tag all related data to be recalc. */
void BKE_pose_tag_recalc(struct Main *bmain, struct bPose *pose);
+
#ifdef __cplusplus
};
#endif
diff --git a/source/blender/blenkernel/BKE_anim.h b/source/blender/blenkernel/BKE_anim.h
index 584f0da323a..0fb83162459 100644
--- a/source/blender/blenkernel/BKE_anim.h
+++ b/source/blender/blenkernel/BKE_anim.h
@@ -32,7 +32,7 @@
* \author nzc
* \since March 2001
*/
-struct EvaluationContext;
+struct Depsgraph;
struct Path;
struct Object;
struct Scene;
@@ -41,6 +41,7 @@ struct bAnimVizSettings;
struct bMotionPath;
struct bPoseChannel;
struct ReportList;
+struct Main;
/* ---------------------------------------------------- */
/* Animation Visualization */
@@ -53,7 +54,7 @@ void animviz_free_motionpath(struct bMotionPath *mpath);
struct bMotionPath *animviz_verify_motionpaths(struct ReportList *reports, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan);
void animviz_get_object_motionpaths(struct Object *ob, ListBase *targets);
-void animviz_calc_motionpaths(struct Scene *scene, ListBase *targets);
+void animviz_calc_motionpaths(struct Depsgraph *depsgraph, struct Main *bmain, struct Scene *scene, ListBase *targets);
/* ---------------------------------------------------- */
/* Curve Paths */
@@ -65,8 +66,8 @@ int where_on_path(struct Object *ob, float ctime, float vec[4], float dir[3], fl
/* ---------------------------------------------------- */
/* Dupli-Geometry */
-struct ListBase *object_duplilist_ex(struct EvaluationContext *eval_ctx, struct Scene *sce, struct Object *ob, bool update);
-struct ListBase *object_duplilist(struct EvaluationContext *eval_ctx, struct Scene *sce, struct Object *ob);
+struct ListBase *object_duplilist_ex(struct Depsgraph *depsgraph, struct Scene *sce, struct Object *ob, bool update);
+struct ListBase *object_duplilist(struct Depsgraph *depsgraph, struct Scene *sce, struct Object *ob);
void free_object_duplilist(struct ListBase *lb);
int count_duplilist(struct Object *ob);
@@ -80,7 +81,7 @@ typedef struct DupliApplyData {
DupliExtraData *extra;
} DupliApplyData;
-DupliApplyData *duplilist_apply(struct Object *ob, struct Scene *scene, struct ListBase *duplilist);
+DupliApplyData *duplilist_apply(struct Depsgraph *depsgraph, struct Object *ob, struct Scene *scene, struct ListBase *duplilist);
void duplilist_restore(struct ListBase *duplilist, DupliApplyData *apply_data);
void duplilist_free_apply_data(DupliApplyData *apply_data);
diff --git a/source/blender/blenkernel/BKE_animsys.h b/source/blender/blenkernel/BKE_animsys.h
index a70690d4029..71c63df7bf3 100644
--- a/source/blender/blenkernel/BKE_animsys.h
+++ b/source/blender/blenkernel/BKE_animsys.h
@@ -47,6 +47,7 @@ struct ReportList;
struct bAction;
struct bActionGroup;
struct AnimMapper;
+struct FCurve;
/* ************************************* */
/* AnimData API */
@@ -68,10 +69,10 @@ bool BKE_animdata_set_action(struct ReportList *reports, struct ID *id, struct b
void BKE_animdata_free(struct ID *id, const bool do_id_user);
/* Copy AnimData */
-struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const bool do_action);
+struct AnimData *BKE_animdata_copy(struct Main *bmain, struct AnimData *adt, const bool do_action, const bool do_id_user);
/* Copy AnimData */
-bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, const bool do_action);
+bool BKE_animdata_copy_id(struct Main *bmain, struct ID *id_to, struct ID *id_from, const bool do_action, const bool do_id_user);
/* Copy AnimData Actions */
void BKE_animdata_copy_id_action(struct ID *id, const bool set_newid);
@@ -148,7 +149,7 @@ char *BKE_animdata_driver_path_hack(struct bContext *C, struct PointerRNA *ptr,
char *base_path);
/* ************************************* */
-/* Batch AnimData API */
+/* Gwn_Batch AnimData API */
/* Define for callback looper used in BKE_animdata_main_cb */
typedef void (*ID_AnimData_Edit_Callback)(struct ID *id, struct AnimData *adt, void *user_data);
@@ -179,7 +180,6 @@ void BKE_animsys_evaluate_animdata(struct Scene *scene, struct ID *id, struct An
void BKE_animsys_evaluate_all_animation(struct Main *main, struct Scene *scene, float ctime);
/* TODO(sergey): This is mainly a temp public function. */
-struct FCurve;
bool BKE_animsys_execute_fcurve(struct PointerRNA *ptr, struct AnimMapper *remap, struct FCurve *fcu, float curval);
/* ------------ Specialized API --------------- */
@@ -200,10 +200,10 @@ void animsys_evaluate_action_group(struct PointerRNA *ptr, struct bAction *act,
/* ------------ Evaluation API --------------- */
-struct EvaluationContext;
+struct Depsgraph;
-void BKE_animsys_eval_animdata(struct EvaluationContext *eval_ctx, struct ID *id);
-void BKE_animsys_eval_driver(struct EvaluationContext *eval_ctx, struct ID *id, struct FCurve *fcurve);
+void BKE_animsys_eval_animdata(struct Depsgraph *depsgraph, struct ID *id);
+void BKE_animsys_eval_driver(struct Depsgraph *depsgraph, struct ID *id, struct FCurve *fcurve);
/* ************************************* */
diff --git a/source/blender/blenkernel/BKE_appdir.h b/source/blender/blenkernel/BKE_appdir.h
index ac8f861fa56..ffbdc6972f4 100644
--- a/source/blender/blenkernel/BKE_appdir.h
+++ b/source/blender/blenkernel/BKE_appdir.h
@@ -82,6 +82,7 @@ enum {
#define BLENDER_STARTUP_FILE "startup.blend"
#define BLENDER_USERPREF_FILE "userpref.blend"
+#define BLENDER_WORKSPACES_FILE "workspaces.blend"
#define BLENDER_QUIT_FILE "quit.blend"
#define BLENDER_BOOKMARK_FILE "bookmarks.txt"
#define BLENDER_HISTORY_FILE "recent-files.txt"
diff --git a/source/blender/blenkernel/BKE_armature.h b/source/blender/blenkernel/BKE_armature.h
index f6de39c897e..b8d9e5a9af9 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -33,7 +33,9 @@
* \author nzc
*/
+struct bPose;
struct Bone;
+struct Depsgraph;
struct GHash;
struct Main;
struct bArmature;
@@ -97,10 +99,10 @@ float distfactor_to_bone(const float vec[3], const float b1[3], const float b2[3
void BKE_armature_where_is(struct bArmature *arm);
void BKE_armature_where_is_bone(struct Bone *bone, struct Bone *prevbone, const bool use_recursion);
void BKE_pose_clear_pointers(struct bPose *pose);
+void BKE_pose_remap_bone_pointers(struct bArmature *armature, struct bPose *pose);
void BKE_pose_rebuild(struct Object *ob, struct bArmature *arm);
-void BKE_pose_rebuild_ex(struct Object *ob, struct bArmature *arm, const bool sort_bones);
-void BKE_pose_where_is(struct Scene *scene, struct Object *ob);
-void BKE_pose_where_is_bone(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, bool do_extra);
+void BKE_pose_where_is(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
+void BKE_pose_where_is_bone(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime, bool do_extra);
void BKE_pose_where_is_bone_tail(struct bPoseChannel *pchan);
/* get_objectspace_bone_matrix has to be removed still */
@@ -117,7 +119,7 @@ void BKE_armature_loc_pose_to_bone(struct bPoseChannel *pchan, const float inloc
void BKE_armature_mat_bone_to_pose(struct bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]);
void BKE_armature_mat_pose_to_delta(float delta_mat[4][4], float pose_mat[4][4], float arm_mat[4][4]);
-void BKE_armature_mat_pose_to_bone_ex(struct Object *ob, struct bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]);
+void BKE_armature_mat_pose_to_bone_ex(struct Depsgraph *depsgraph, struct Object *ob, struct bPoseChannel *pchan, float inmat[4][4], float outmat[4][4]);
void BKE_pchan_mat3_to_rot(struct bPoseChannel *pchan, float mat[3][3], bool use_compat);
void BKE_pchan_apply_mat4(struct bPoseChannel *pchan, float mat[4][4], bool use_comat);
@@ -151,60 +153,78 @@ void b_bone_spline_setup(struct bPoseChannel *pchan, int rest, Mat4 result_array
#define PBONE_SELECTABLE(arm, bone) \
(PBONE_VISIBLE(arm, bone) && !((bone)->flag & BONE_UNSELECTABLE))
+
+/* context.selected_pose_bones */
+#define FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN(_ob, _pchan) \
+ for (bPoseChannel *_pchan = (_ob)->pose->chanbase.first; _pchan; _pchan = _pchan->next) { \
+ if (PBONE_VISIBLE(((bArmature *)(_ob)->data), (_pchan)->bone) && ((_pchan)->bone->flag & BONE_SELECTED)) {
+#define FOREACH_PCHAN_SELECTED_IN_OBJECT_END \
+ } \
+ } ((void)0)
+/* context.visible_pose_bones */
+#define FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN(_ob, _pchan) \
+ for (bPoseChannel *_pchan = (_ob)->pose->chanbase.first; _pchan; _pchan = _pchan->next) { \
+ if (PBONE_VISIBLE(((bArmature *)(_ob)->data), (_pchan)->bone)) {
+#define FOREACH_PCHAN_VISIBLE_IN_OBJECT_END \
+ } \
+ } ((void)0)
+
+
/* Evaluation helpers */
struct bKinematicConstraint;
struct bPose;
struct bSplineIKConstraint;
-struct EvaluationContext;
struct bPoseChannel *BKE_armature_ik_solver_find_root(
- struct bPoseChannel *pchan,
- struct bKinematicConstraint *data);
+ struct bPoseChannel *pchan,
+ struct bKinematicConstraint *data);
struct bPoseChannel *BKE_armature_splineik_solver_find_root(
- struct bPoseChannel *pchan,
- struct bSplineIKConstraint *data);
+ struct bPoseChannel *pchan,
+ struct bSplineIKConstraint *data);
void BKE_pose_splineik_init_tree(struct Scene *scene, struct Object *ob, float ctime);
-void BKE_splineik_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime);
-
-void BKE_pose_eval_init(struct EvaluationContext *eval_ctx,
- struct Scene *scene,
- struct Object *ob);
-
-void BKE_pose_eval_init_ik(struct EvaluationContext *eval_ctx,
- struct Scene *scene,
- struct Object *ob);
-
-void BKE_pose_eval_bone(struct EvaluationContext *eval_ctx,
- struct Scene *scene,
- struct Object *ob,
- int pchan_index);
-
-void BKE_pose_constraints_evaluate(struct EvaluationContext *eval_ctx,
- struct Scene *scene,
- struct Object *ob,
- int pchan_index);
-
-void BKE_pose_bone_done(struct EvaluationContext *eval_ctx,
- struct Object *ob,
- int pchan_index);
-
-void BKE_pose_iktree_evaluate(struct EvaluationContext *eval_ctx,
- struct Scene *scene,
- struct Object *ob,
- int rootchan_index);
-
-void BKE_pose_splineik_evaluate(struct EvaluationContext *eval_ctx,
- struct Scene *scene,
- struct Object *ob,
- int rootchan_index);
-
-void BKE_pose_eval_flush(struct EvaluationContext *eval_ctx,
- struct Scene *scene,
- struct Object *ob);
-
-void BKE_pose_eval_proxy_copy(struct EvaluationContext *eval_ctx,
- struct Object *ob);
+void BKE_splineik_execute_tree(
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, struct bPoseChannel *pchan_root, float ctime);
+
+void BKE_pose_eval_init(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob);
+
+void BKE_pose_eval_init_ik(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob);
+
+void BKE_pose_eval_bone(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob,
+ int pchan_index);
+
+void BKE_pose_constraints_evaluate(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob,
+ int pchan_index);
+
+void BKE_pose_bone_done(struct Depsgraph *depsgraph,
+ struct Object *ob,
+ int pchan_index);
+
+void BKE_pose_iktree_evaluate(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob,
+ int rootchan_index);
+
+void BKE_pose_splineik_evaluate(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob,
+ int rootchan_index);
+
+void BKE_pose_eval_flush(struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob);
+
+void BKE_pose_eval_proxy_copy(struct Depsgraph *depsgraph,
+ struct Object *ob);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_blender_version.h b/source/blender/blenkernel/BKE_blender_version.h
index b5d906b2968..a49753d331f 100644
--- a/source/blender/blenkernel/BKE_blender_version.h
+++ b/source/blender/blenkernel/BKE_blender_version.h
@@ -27,8 +27,8 @@
/* these lines are grep'd, watch out for our not-so-awesome regex
* and keep comment above the defines.
* Use STRINGIFY() rather than defining with quotes */
-#define BLENDER_VERSION 279
-#define BLENDER_SUBVERSION 4
+#define BLENDER_VERSION 280
+#define BLENDER_SUBVERSION 13
/* Several breakages with 270, e.g. constraint deg vs rad */
#define BLENDER_MINVERSION 270
#define BLENDER_MINSUBVERSION 6
diff --git a/source/blender/blenkernel/BKE_blendfile.h b/source/blender/blenkernel/BKE_blendfile.h
index 9ff164f60be..a9a7e2045f0 100644
--- a/source/blender/blenkernel/BKE_blendfile.h
+++ b/source/blender/blenkernel/BKE_blendfile.h
@@ -61,6 +61,10 @@ struct UserDef *BKE_blendfile_userdef_read_from_memory(
bool BKE_blendfile_userdef_write(const char *filepath, struct ReportList *reports);
bool BKE_blendfile_userdef_write_app_template(const char *filepath, struct ReportList *reports);
+struct WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath, struct ReportList *reports);
+bool BKE_blendfile_workspace_config_write(struct Main *bmain, const char *filepath, struct ReportList *reports);
+void BKE_blendfile_workspace_config_data_free(struct WorkspaceConfigFileData *workspace_config);
+
/* partial blend file writing */
void BKE_blendfile_write_partial_tag_ID(struct ID *id, bool set);
void BKE_blendfile_write_partial_begin(struct Main *bmain_src);
diff --git a/source/blender/blenkernel/BKE_bullet.h b/source/blender/blenkernel/BKE_bullet.h
deleted file mode 100644
index dc522d1b22c..00000000000
--- a/source/blender/blenkernel/BKE_bullet.h
+++ /dev/null
@@ -1,44 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#ifndef __BKE_BULLET_H__
-#define __BKE_BULLET_H__
-
-/** \file BKE_bullet.h
- * \ingroup bke
- */
-
-struct BulletSoftBody;
-
-
-/* allocates and initializes general main data */
-extern struct BulletSoftBody *bsbNew(void);
-
-/* frees internal data and softbody itself */
-extern void bsbFree(struct BulletSoftBody *sb);
-
-#endif
-
diff --git a/source/blender/blenkernel/BKE_cachefile.h b/source/blender/blenkernel/BKE_cachefile.h
index e9712681090..e0419d0e749 100644
--- a/source/blender/blenkernel/BKE_cachefile.h
+++ b/source/blender/blenkernel/BKE_cachefile.h
@@ -65,7 +65,7 @@ bool BKE_cachefile_filepath_get(
float BKE_cachefile_time_offset(struct CacheFile *cache_file, const float time, const float fps);
-void BKE_cachefile_clean(struct Scene *scene, struct CacheFile *cache_file);
+void BKE_cachefile_clean(struct Main *bmain, struct CacheFile *cache_file);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_camera.h b/source/blender/blenkernel/BKE_camera.h
index 04dee70faa6..c647dd3cc0f 100644
--- a/source/blender/blenkernel/BKE_camera.h
+++ b/source/blender/blenkernel/BKE_camera.h
@@ -39,11 +39,13 @@ extern "C" {
#include "DNA_vec_types.h"
struct Camera;
+struct Depsgraph;
struct Main;
struct Object;
struct RegionView3D;
struct RenderData;
struct Scene;
+struct ViewLayer;
struct rctf;
struct View3D;
struct GPUFXSettings;
@@ -91,11 +93,6 @@ typedef struct CameraParams {
float clipsta;
float clipend;
- /* fields */
- int use_fields;
- int field_second;
- int field_odd;
-
/* computed viewplane */
float ycor;
float viewdx;
@@ -112,7 +109,7 @@ typedef struct CameraParams {
void BKE_camera_params_init(CameraParams *params);
void BKE_camera_params_from_object(CameraParams *params, const struct Object *camera);
-void BKE_camera_params_from_view3d(CameraParams *params, const struct View3D *v3d, const struct RegionView3D *rv3d);
+void BKE_camera_params_from_view3d(CameraParams *params, struct Depsgraph *depsgraph, const struct View3D *v3d, const struct RegionView3D *rv3d);
void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int winy, float aspx, float aspy);
void BKE_camera_params_compute_matrix(CameraParams *params);
@@ -128,7 +125,8 @@ void BKE_camera_view_frame(
float r_vec[4][3]);
bool BKE_camera_view_frame_fit_to_scene(
- struct Scene *scene, struct View3D *v3d, struct Object *camera_ob,
+ struct Depsgraph *depsgraph,
+ struct Scene *scene, struct ViewLayer *view_layer, struct Object *camera_ob,
float r_co[3], float *r_scale);
bool BKE_camera_view_frame_fit_to_coords(
const struct Scene *scene,
@@ -147,6 +145,11 @@ float BKE_camera_multiview_shift_x(struct RenderData *rd, struct Object
void BKE_camera_multiview_params(struct RenderData *rd, struct CameraParams *params, struct Object *camera, const char *viewname);
bool BKE_camera_multiview_spherical_stereo(struct RenderData *rd, struct Object *camera);
+/* Camera background image API */
+struct CameraBGImage *BKE_camera_background_image_new(struct Camera *cam);
+void BKE_camera_background_image_remove(struct Camera *cam, struct CameraBGImage *bgpic);
+void BKE_camera_background_image_clear(struct Camera *cam);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_cdderivedmesh.h b/source/blender/blenkernel/BKE_cdderivedmesh.h
index 4876461bfe0..61810a5f029 100644
--- a/source/blender/blenkernel/BKE_cdderivedmesh.h
+++ b/source/blender/blenkernel/BKE_cdderivedmesh.h
@@ -53,6 +53,10 @@ struct DerivedMesh *CDDM_new(int numVerts, int numEdges, int numFaces,
* data to not overwrite the original */
struct DerivedMesh *CDDM_from_mesh(struct Mesh *mesh);
+/* creates a CDDerivedMesh from the given Mesh with custom allocation type. */
+struct DerivedMesh *CDDM_from_mesh_ex(struct Mesh *mesh, int alloctype);
+
+
struct DerivedMesh *CDDM_from_bmesh(struct BMesh *bm, const bool use_mdisps);
/* creates a CDDerivedMesh from the given BMEditMesh */
diff --git a/source/blender/blenkernel/BKE_cloth.h b/source/blender/blenkernel/BKE_cloth.h
index 6c517bd02df..94daf615054 100644
--- a/source/blender/blenkernel/BKE_cloth.h
+++ b/source/blender/blenkernel/BKE_cloth.h
@@ -41,6 +41,7 @@ struct MFace;
struct DerivedMesh;
struct ClothModifierData;
struct CollisionModifierData;
+struct Depsgraph;
#define DO_INLINE MALWAYS_INLINE
@@ -226,7 +227,7 @@ void cloth_free_contacts(ColliderContacts *collider_contacts, int totcolliders);
void cloth_free_modifier_extern (struct ClothModifierData *clmd );
void cloth_free_modifier (struct ClothModifierData *clmd );
void cloth_init (struct ClothModifierData *clmd );
-void clothModifier_do (struct ClothModifierData *clmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]);
+void clothModifier_do(struct ClothModifierData *clmd, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm, float (*vertexCos)[3]);
int cloth_uses_vgroup(struct ClothModifierData *clmd);
@@ -235,7 +236,8 @@ void bvhtree_update_from_cloth(struct ClothModifierData *clmd, bool moving);
void bvhselftree_update_from_cloth(struct ClothModifierData *clmd, bool moving);
// needed for button_object.c
-void cloth_clear_cache (struct Object *ob, struct ClothModifierData *clmd, float framenr );
+void cloth_clear_cache(
+ struct Object *ob, struct ClothModifierData *clmd, float framenr );
void cloth_parallel_transport_hair_frame(float mat[3][3], const float dir_old[3], const float dir_new[3]);
diff --git a/source/blender/blenkernel/BKE_collection.h b/source/blender/blenkernel/BKE_collection.h
new file mode 100644
index 00000000000..d3a4d2b8d5b
--- /dev/null
+++ b/source/blender/blenkernel/BKE_collection.h
@@ -0,0 +1,115 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_COLLECTION_H__
+#define __BKE_COLLECTION_H__
+
+/** \file blender/blenkernel/BKE_collection.h
+ * \ingroup bke
+ */
+
+#include "BLI_ghash.h"
+#include "BLI_iterator.h"
+#include "DNA_listBase.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Base;
+struct BLI_Iterator;
+struct Group;
+struct ID;
+struct LayerCollection;
+struct Main;
+struct Object;
+struct Scene;
+struct SceneCollection;
+struct ViewLayer;
+
+struct SceneCollection *BKE_collection_add(
+ struct ID *owner_id, struct SceneCollection *sc_parent, const int type, const char *name);
+bool BKE_collection_remove(struct ID *owner_id, struct SceneCollection *sc);
+void BKE_collection_copy_data(struct SceneCollection *sc_dst, struct SceneCollection *sc_src, const int flag);
+struct SceneCollection *BKE_collection_duplicate(struct ID *owner_id, struct SceneCollection *scene_collection);
+struct SceneCollection *BKE_collection_master(const struct ID *owner_id);
+void BKE_collection_rename(const struct ID *owner_id, struct SceneCollection *sc, const char *name);
+void BKE_collection_master_free(struct ID *owner_id, const bool do_id_user);
+bool BKE_collection_object_add(const struct ID *owner_id, struct SceneCollection *sc, struct Object *object);
+void BKE_collection_object_add_from(struct Scene *scene, struct Object *ob_src, struct Object *ob_dst);
+bool BKE_collection_object_remove(struct Main *bmain, struct ID *owner_id, struct SceneCollection *sc, struct Object *object, const bool free_us);
+bool BKE_collections_object_remove(struct Main *bmain, struct ID *owner_id, struct Object *object, const bool free_us);
+void BKE_collection_object_move(struct ID *owner_id, struct SceneCollection *sc_dst, struct SceneCollection *sc_src, struct Object *ob);
+bool BKE_collection_object_exists(struct SceneCollection *scene_collection, struct Object *ob);
+struct SceneCollection *BKE_collection_from_index(struct Scene *scene, const int index);
+
+void BKE_collection_new_name_get(struct ID *owner_id, struct SceneCollection *sc_parent, char *rname);
+
+bool BKE_collection_objects_select(struct ViewLayer *view_layer, struct SceneCollection *scene_collection);
+
+struct Group *BKE_collection_group_create(struct Main *bmain, struct Scene *scene, struct LayerCollection *lc);
+
+void BKE_collection_reinsert_after(const struct Scene *scene, struct SceneCollection *sc_reinsert, struct SceneCollection *sc_after);
+void BKE_collection_reinsert_into(struct SceneCollection *sc_reinsert, struct SceneCollection *sc_into);
+
+bool BKE_collection_move_above(const struct ID *owner_id, struct SceneCollection *sc_dst, struct SceneCollection *sc_src);
+bool BKE_collection_move_below(const struct ID *owner_id, struct SceneCollection *sc_dst, struct SceneCollection *sc_src);
+bool BKE_collection_move_into(const struct ID *owner_id, struct SceneCollection *sc_dst, struct SceneCollection *sc_src);
+
+typedef void (*BKE_scene_objects_Cb)(struct Object *ob, void *data);
+typedef void (*BKE_scene_collections_Cb)(struct SceneCollection *ob, void *data);
+
+void BKE_scene_collections_callback(struct Scene *scene, BKE_scene_collections_Cb callback, void *data);
+void BKE_scene_objects_callback(struct Scene *scene, BKE_scene_objects_Cb callback, void *data);
+
+/* iterators */
+void BKE_scene_collections_iterator_begin(struct BLI_Iterator *iter, void *data_in);
+void BKE_scene_collections_iterator_next(struct BLI_Iterator *iter);
+void BKE_scene_collections_iterator_end(struct BLI_Iterator *iter);
+
+void BKE_scene_objects_iterator_begin(struct BLI_Iterator *iter, void *data_in);
+void BKE_scene_objects_iterator_next(struct BLI_Iterator *iter);
+void BKE_scene_objects_iterator_end(struct BLI_Iterator *iter);
+
+#define FOREACH_SCENE_COLLECTION_BEGIN(_id, _instance) \
+ ITER_BEGIN(BKE_scene_collections_iterator_begin, \
+ BKE_scene_collections_iterator_next, \
+ BKE_scene_collections_iterator_end, \
+ _id, SceneCollection *, _instance)
+
+#define FOREACH_SCENE_COLLECTION_END \
+ ITER_END
+
+#define FOREACH_SCENE_OBJECT_BEGIN(scene, _instance) \
+ ITER_BEGIN(BKE_scene_objects_iterator_begin, \
+ BKE_scene_objects_iterator_next, \
+ BKE_scene_objects_iterator_end, \
+ scene, Object *, _instance)
+
+#define FOREACH_SCENE_OBJECT_END \
+ ITER_END
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_COLLECTION_H__ */
diff --git a/source/blender/blenkernel/BKE_collision.h b/source/blender/blenkernel/BKE_collision.h
index 8fedcd4ab06..0bf7f657f70 100644
--- a/source/blender/blenkernel/BKE_collision.h
+++ b/source/blender/blenkernel/BKE_collision.h
@@ -148,7 +148,7 @@ void collision_get_collider_velocity(float vel_old[3], float vel_new[3], struct
/////////////////////////////////////////////////
/* explicit control over layer mask and dupli recursion */
-struct Object **get_collisionobjects_ext(struct Scene *scene, struct Object *self, struct Group *group, int layer, unsigned int *numcollobj, unsigned int modifier_type, bool dupli);
+struct Object **get_collisionobjects_ext(struct Scene *scene, struct Object *self, struct Group *group, unsigned int *numcollobj, unsigned int modifier_type, bool dupli);
struct Object **get_collisionobjects(struct Scene *scene, struct Object *self, struct Group *group, unsigned int *numcollobj, unsigned int modifier_type);
diff --git a/source/blender/blenkernel/BKE_constraint.h b/source/blender/blenkernel/BKE_constraint.h
index 4e0eb5c65ac..18f6301953c 100644
--- a/source/blender/blenkernel/BKE_constraint.h
+++ b/source/blender/blenkernel/BKE_constraint.h
@@ -40,6 +40,7 @@ struct ListBase;
struct Object;
struct Scene;
struct bPoseChannel;
+struct Depsgraph;
/* ---------------------------------------------------------------------------- */
#ifdef __cplusplus
@@ -102,7 +103,7 @@ typedef struct bConstraintTypeInfo {
/* evaluation */
/* set the ct->matrix for the given constraint target (at the given ctime) */
- void (*get_target_matrix)(struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime);
+ void (*get_target_matrix)(struct Depsgraph *depsgraph, struct bConstraint *con, struct bConstraintOb *cob, struct bConstraintTarget *ct, float ctime);
/* evaluate the constraint for the given time */
void (*evaluate_constraint)(struct bConstraint *con, struct bConstraintOb *cob, struct ListBase *targets);
} bConstraintTypeInfo;
@@ -117,6 +118,8 @@ const bConstraintTypeInfo *BKE_constraint_typeinfo_from_type(int type);
/* Constraint function prototypes */
void BKE_constraint_unique_name(struct bConstraint *con, struct ListBase *list);
+struct bConstraint *BKE_constraint_duplicate_ex(struct bConstraint *src, const int flag, const bool do_extern);
+
void BKE_constraints_free(struct ListBase *list);
void BKE_constraints_free_ex(struct ListBase *list, bool do_id_user);
void BKE_constraints_copy(struct ListBase *dst, const struct ListBase *src, bool do_extern);
@@ -147,9 +150,10 @@ void BKE_constraints_clear_evalob(struct bConstraintOb *cob);
void BKE_constraint_mat_convertspace(
struct Object *ob, struct bPoseChannel *pchan, float mat[4][4], short from, short to, const bool keep_scale);
-void BKE_constraint_target_matrix_get(struct Scene *scene, struct bConstraint *con, int n, short ownertype, void *ownerdata, float mat[4][4], float ctime);
-void BKE_constraint_targets_for_solving_get(struct bConstraint *con, struct bConstraintOb *ob, struct ListBase *targets, float ctime);
-void BKE_constraints_solve(struct ListBase *conlist, struct bConstraintOb *cob, float ctime);
+void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, struct Scene *scene, struct bConstraint *con,
+ int n, short ownertype, void *ownerdata, float mat[4][4], float ctime);
+void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, struct bConstraint *con, struct bConstraintOb *ob, struct ListBase *targets, float ctime);
+void BKE_constraints_solve(struct Depsgraph *depsgraph, struct ListBase *conlist, struct bConstraintOb *cob, float ctime);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_context.h b/source/blender/blenkernel/BKE_context.h
index 6de323258bd..12525fe9a50 100644
--- a/source/blender/blenkernel/BKE_context.h
+++ b/source/blender/blenkernel/BKE_context.h
@@ -40,15 +40,21 @@ extern "C" {
struct ARegion;
struct bScreen;
struct CacheFile;
+struct Depsgraph;
+struct LayerCollection;
struct ListBase;
struct Main;
struct Object;
+struct Base;
struct PointerRNA;
struct ReportList;
struct Scene;
+struct SceneCollection;
+struct ViewLayer;
struct ScrArea;
struct SpaceLink;
struct View3D;
+struct ViewRender;
struct RegionView3D;
struct StructRNA;
struct ToolSettings;
@@ -64,11 +70,14 @@ struct bGPDpalettecolor;
struct bGPDbrush;
struct wmWindow;
struct wmWindowManager;
+struct RenderEngineType;
struct SpaceText;
struct SpaceImage;
struct SpaceClip;
struct ID;
+#include "DNA_object_enums.h"
+
/* Structs */
struct bContext;
@@ -110,7 +119,8 @@ enum {
CTX_MODE_PAINT_VERTEX,
CTX_MODE_PAINT_TEXTURE,
CTX_MODE_PARTICLE,
- CTX_MODE_OBJECT
+ CTX_MODE_OBJECT,
+ CTX_MODE_NUM /* must be last */
};
/* Context */
@@ -140,12 +150,15 @@ void CTX_py_dict_set(bContext *C, void *value);
struct wmWindowManager *CTX_wm_manager(const bContext *C);
struct wmWindow *CTX_wm_window(const bContext *C);
+struct WorkSpace *CTX_wm_workspace(const bContext *C);
struct bScreen *CTX_wm_screen(const bContext *C);
struct ScrArea *CTX_wm_area(const bContext *C);
struct SpaceLink *CTX_wm_space_data(const bContext *C);
struct ARegion *CTX_wm_region(const bContext *C);
void *CTX_wm_region_data(const bContext *C);
struct ARegion *CTX_wm_menu(const bContext *C);
+struct wmManipulatorGroup *CTX_wm_manipulator_group(const bContext *C);
+struct wmMsgBus *CTX_wm_message_bus(const bContext *C);
struct ReportList *CTX_wm_reports(const bContext *C);
struct View3D *CTX_wm_view3d(const bContext *C);
@@ -158,14 +171,13 @@ struct SpaceFile *CTX_wm_space_file(const bContext *C);
struct SpaceSeq *CTX_wm_space_seq(const bContext *C);
struct SpaceOops *CTX_wm_space_outliner(const bContext *C);
struct SpaceNla *CTX_wm_space_nla(const bContext *C);
-struct SpaceTime *CTX_wm_space_time(const bContext *C);
struct SpaceNode *CTX_wm_space_node(const bContext *C);
-struct SpaceLogic *CTX_wm_space_logic(const bContext *C);
struct SpaceIpo *CTX_wm_space_graph(const bContext *C);
struct SpaceAction *CTX_wm_space_action(const bContext *C);
struct SpaceInfo *CTX_wm_space_info(const bContext *C);
struct SpaceUserPref *CTX_wm_space_userpref(const bContext *C);
struct SpaceClip *CTX_wm_space_clip(const bContext *C);
+struct SpaceTopBar *CTX_wm_space_topbar(const bContext *C);
void CTX_wm_manager_set(bContext *C, struct wmWindowManager *wm);
void CTX_wm_window_set(bContext *C, struct wmWindow *win);
@@ -173,6 +185,7 @@ void CTX_wm_screen_set(bContext *C, struct bScreen *screen); /* to be removed */
void CTX_wm_area_set(bContext *C, struct ScrArea *sa);
void CTX_wm_region_set(bContext *C, struct ARegion *region);
void CTX_wm_menu_set(bContext *C, struct ARegion *menu);
+void CTX_wm_manipulator_group_set(bContext *C, struct wmManipulatorGroup *mgroup);
const char *CTX_wm_operator_poll_msg_get(struct bContext *C);
void CTX_wm_operator_poll_msg_set(struct bContext *C, const char *msg);
@@ -243,9 +256,16 @@ int ctx_data_list_count(const bContext *C, int (*func)(const bContext *, ListBas
struct Main *CTX_data_main(const bContext *C);
struct Scene *CTX_data_scene(const bContext *C);
+struct LayerCollection *CTX_data_layer_collection(const bContext *C);
+struct SceneCollection *CTX_data_scene_collection(const bContext *C);
+struct ViewLayer *CTX_data_view_layer(const bContext *C);
+struct RenderEngineType *CTX_data_engine_type(const bContext *C);
struct ToolSettings *CTX_data_tool_settings(const bContext *C);
const char *CTX_data_mode_string(const bContext *C);
+int CTX_data_mode_enum_ex(
+ const struct Object *obedit, const struct Object *ob,
+ const eObjectMode object_mode);
int CTX_data_mode_enum(const bContext *C);
void CTX_data_main_set(bContext *C, struct Main *bmain);
@@ -300,6 +320,12 @@ int CTX_data_visible_gpencil_layers(const bContext *C, ListBase *list);
int CTX_data_editable_gpencil_layers(const bContext *C, ListBase *list);
int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list);
+struct Depsgraph *CTX_data_depsgraph(const bContext *C);
+
+/* Will Return NULL if depsgraph is not allocated yet.
+ * Only used by handful of operators which are run on file load.
+ */
+struct Depsgraph *CTX_data_depsgraph_on_load(const bContext *C);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_crazyspace.h b/source/blender/blenkernel/BKE_crazyspace.h
index ee6c5c57678..e9745ed50fa 100644
--- a/source/blender/blenkernel/BKE_crazyspace.h
+++ b/source/blender/blenkernel/BKE_crazyspace.h
@@ -38,23 +38,24 @@ struct Scene;
struct Object;
struct BMEditMesh;
struct Mesh;
+struct Depsgraph;
/* crazyspace.c */
float (*BKE_crazyspace_get_mapped_editverts(
- struct Scene *scene, struct Object *obedit))[3];
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *obedit))[3];
void BKE_crazyspace_set_quats_editmesh(
struct BMEditMesh *em, float (*origcos)[3], float (*mappedcos)[3], float (*quats)[4],
const bool use_select);
void BKE_crazyspace_set_quats_mesh(
struct Mesh *me, float (*origcos)[3], float (*mappedcos)[3], float (*quats)[4]);
int BKE_crazyspace_get_first_deform_matrices_editbmesh(
- struct Scene *, struct Object *, struct BMEditMesh *em,
+ struct Depsgraph *depsgraph, struct Scene *, struct Object *, struct BMEditMesh *em,
float (**deformmats)[3][3], float (**deformcos)[3]);
int BKE_sculpt_get_first_deform_matrices(
- struct Scene *scene, struct Object *ob,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
float (**deformmats)[3][3], float (**deformcos)[3]);
void BKE_crazyspace_build_sculpt(
- struct Scene *scene, struct Object *ob,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
float (**deformmats)[3][3], float (**deformcos)[3]);
#ifdef __cplusplus
diff --git a/source/blender/blenkernel/BKE_curve.h b/source/blender/blenkernel/BKE_curve.h
index 175fa1dad79..975cea7364d 100644
--- a/source/blender/blenkernel/BKE_curve.h
+++ b/source/blender/blenkernel/BKE_curve.h
@@ -36,6 +36,7 @@
struct BezTriple;
struct Curve;
struct EditNurb;
+struct Depsgraph;
struct GHash;
struct ListBase;
struct Main;
@@ -122,13 +123,14 @@ void BKE_curve_editNurb_keyIndex_free(struct GHash **keyindex);
void BKE_curve_editNurb_free(struct Curve *cu);
struct ListBase *BKE_curve_editNurbs_get(struct Curve *cu);
-float *BKE_curve_make_orco(struct Scene *scene, struct Object *ob, int *r_numVerts);
+float *BKE_curve_make_orco(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, int *r_numVerts);
float *BKE_curve_surf_make_orco(struct Object *ob);
void BKE_curve_bevelList_free(struct ListBase *bev);
void BKE_curve_bevelList_make(struct Object *ob, struct ListBase *nurbs, bool for_render);
-void BKE_curve_bevel_make(struct Scene *scene, struct Object *ob, struct ListBase *disp,
- const bool for_render, const bool use_render_resolution);
+void BKE_curve_bevel_make(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *disp,
+ const bool for_render, const bool use_render_resolution);
void BKE_curve_forward_diff_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride);
void BKE_curve_forward_diff_tangent_bezier(float q0, float q1, float q2, float q3, float *p, int it, int stride);
@@ -215,10 +217,17 @@ void BKE_nurb_handles_test(struct Nurb *nu, const bool use_handles);
/* **** Depsgraph evaluation **** */
-struct EvaluationContext;
-
-void BKE_curve_eval_geometry(struct EvaluationContext *eval_ctx,
- struct Curve *curve);
+void BKE_curve_eval_geometry(
+ struct Depsgraph *depsgraph,
+ struct Curve *curve);
+
+/* Draw Cache */
+enum {
+ BKE_CURVE_BATCH_DIRTY_ALL = 0,
+ BKE_CURVE_BATCH_DIRTY_SELECT,
+};
+void BKE_curve_batch_cache_dirty(struct Curve *cu, int mode);
+void BKE_curve_batch_cache_free(struct Curve *cu);
/* curve_decimate.c */
unsigned int BKE_curve_decimate_bezt_array(
diff --git a/source/blender/blenkernel/BKE_customdata.h b/source/blender/blenkernel/BKE_customdata.h
index 2cdda34b9b5..51cd4da183a 100644
--- a/source/blender/blenkernel/BKE_customdata.h
+++ b/source/blender/blenkernel/BKE_customdata.h
@@ -376,15 +376,14 @@ void CustomData_validate_layer_name(const struct CustomData *data, int type, con
bool CustomData_verify_versions(struct CustomData *data, int index);
/*BMesh specific customdata stuff*/
-void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata,
- struct CustomData *ldata, int totloop, int totpoly);
-void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata, int total);
-void CustomData_bmesh_update_active_layers(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata);
-void CustomData_bmesh_do_versions_update_active_layers(struct CustomData *fdata, struct CustomData *pdata, struct CustomData *ldata);
+void CustomData_to_bmeshpoly(struct CustomData *fdata, struct CustomData *ldata, int totloop);
+void CustomData_from_bmeshpoly(struct CustomData *fdata, struct CustomData *ldata, int total);
+void CustomData_bmesh_update_active_layers(struct CustomData *fdata, struct CustomData *ldata);
+void CustomData_bmesh_do_versions_update_active_layers(struct CustomData *fdata, struct CustomData *ldata);
void CustomData_bmesh_init_pool(struct CustomData *data, int totelem, const char htype);
#ifndef NDEBUG
-bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *pdata, CustomData *ldata, bool fallback);
+bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *ldata, bool fallback);
#endif
/* External file storage */
diff --git a/source/blender/blenkernel/BKE_data_transfer.h b/source/blender/blenkernel/BKE_data_transfer.h
index 2ee9d8d2408..6559f9a954f 100644
--- a/source/blender/blenkernel/BKE_data_transfer.h
+++ b/source/blender/blenkernel/BKE_data_transfer.h
@@ -38,6 +38,7 @@ extern "C" {
#include "BKE_customdata.h"
+struct Depsgraph;
struct Object;
struct Scene;
struct SpaceTransform;
@@ -129,11 +130,12 @@ enum {
};
void BKE_object_data_transfer_layout(
- struct Scene *scene, struct Object *ob_src, struct Object *ob_dst, const int data_types, const bool use_delete,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_src,
+ struct Object *ob_dst, const int data_types, const bool use_delete,
const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX]);
bool BKE_object_data_transfer_mesh(
- struct Scene *scene,
+ struct Depsgraph *depsgraph, struct Scene *scene,
struct Object *ob_src, struct Object *ob_dst, const int data_types, const bool use_create,
const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode,
struct SpaceTransform *space_transform, const bool auto_transform,
@@ -142,7 +144,7 @@ bool BKE_object_data_transfer_mesh(
const int mix_mode, const float mix_factor, const char *vgroup_name, const bool invert_vgroup,
struct ReportList *reports);
bool BKE_object_data_transfer_dm(
- struct Scene *scene,
+ struct Depsgraph *depsgraph, struct Scene *scene,
struct Object *ob_src, struct Object *ob_dst, struct DerivedMesh *dm_dst,
const int data_types, bool use_create,
const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode,
diff --git a/source/blender/blenkernel/BKE_depsgraph.h b/source/blender/blenkernel/BKE_depsgraph.h
deleted file mode 100644
index 40564aeabe9..00000000000
--- a/source/blender/blenkernel/BKE_depsgraph.h
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2004 Blender Foundation.
- * All rights reserved.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __BKE_DEPSGRAPH_H__
-#define __BKE_DEPSGRAPH_H__
-
-/** \file BKE_depsgraph.h
- * \ingroup bke
- */
-
-/* Dependency Graph
- *
- * The dependency graph tracks relations between datablocks, and is used to
- * determine which datablocks need to be update based on dependencies and
- * visibility.
- *
- * It does not itself execute changes in objects, but rather sorts the objects
- * in the appropriate order and sets flags indicating they should be updated.
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct ID;
-struct Main;
-struct Object;
-struct Scene;
-
-/* Dependency graph evaluation context
- *
- * This structure stores all the local dependency graph data,
- * which is needed for it's evaluation,
- */
-typedef struct EvaluationContext {
- int mode; /* evaluation mode */
- float ctime; /* evaluation time */
-} EvaluationContext;
-
-typedef enum eEvaluationMode {
- DAG_EVAL_VIEWPORT = 0, /* evaluate for OpenGL viewport */
- DAG_EVAL_PREVIEW = 1, /* evaluate for render with preview settings */
- DAG_EVAL_RENDER = 2, /* evaluate for render purposes */
-} eEvaluationMode;
-
-/* DagNode->eval_flags */
-enum {
- /* Regardless to curve->path animation flag path is to be evaluated anyway,
- * to meet dependencies with such a things as curve modifier and other guys
- * who're using curve deform, where_on_path and so.
- */
- DAG_EVAL_NEED_CURVE_PATH = 1,
- /* Scene evaluation would need to have object's data on CPU,
- * meaning no GPU shortcuts is allowed.
- */
- DAG_EVAL_NEED_CPU = 2,
-};
-
-/* Global initialization/deinitialization */
-void DAG_init(void);
-void DAG_exit(void);
-
-/* Build and Update
- *
- * DAG_scene_relations_update will rebuild the dependency graph for a given
- * scene if needed, and sort objects in the scene.
- *
- * DAG_relations_tag_update will clear all dependency graphs and mark them to
- * be rebuilt later. The graph is not rebuilt immediately to avoid slowdowns
- * when this function is call multiple times from different operators.
- *
- * DAG_scene_relations_rebuild forces an immediaterebuild of the dependency
- * graph, this is only needed in rare cases
- */
-
-void DAG_scene_relations_update(struct Main *bmain, struct Scene *sce);
-void DAG_scene_relations_validate(struct Main *bmain, struct Scene *sce);
-void DAG_relations_tag_update(struct Main *bmain);
-void DAG_scene_relations_rebuild(struct Main *bmain, struct Scene *scene);
-void DAG_scene_free(struct Scene *sce);
-
-/* Update Tagging
- *
- * DAG_scene_update_flags will mark all objects that depend on time (animation,
- * physics, ..) to be recalculated, used when changing the current frame.
- *
- * DAG_on_visible_update will mark all objects that are visible for the first
- * time to be updated, for example on file load or changing layer visibility.
- *
- * DAG_id_tag_update will mark a given datablock to be updated. The flag indicates
- * a specific subset to be update (only object transform and data for now).
- *
- * DAG_id_type_tag marks a particular datablock type as having changing. This does
- * not cause any updates but is used by external render engines to detect if for
- * example a datablock was removed. */
-
-void DAG_scene_update_flags(struct Main *bmain, struct Scene *sce, unsigned int lay, const bool do_time, const bool do_invisible_flush);
-void DAG_on_visible_update(struct Main *bmain, const bool do_time);
-
-void DAG_id_tag_update(struct ID *id, short flag);
-void DAG_id_tag_update_ex(struct Main *bmain, struct ID *id, short flag);
-void DAG_id_type_tag(struct Main *bmain, short idtype);
-int DAG_id_type_tagged(struct Main *bmain, short idtype);
-
-/* Flushing Tags
- *
- * DAG_scene_flush_update flushes object recalculation flags immediately to other
- * dependencies. Do not use outside of depsgraph.c, this will be removed.
- *
- * DAG_ids_flush_tagged will flush datablock update flags flags to dependencies,
- * use this right before updating to mark all the needed datablocks for update.
- *
- * DAG_ids_check_recalc and DAG_ids_clear_recalc are used for external render
- * engines to detect changes. */
-
-void DAG_scene_flush_update(struct Main *bmain, struct Scene *sce, unsigned int lay, const short do_time);
-void DAG_ids_flush_tagged(struct Main *bmain);
-void DAG_ids_check_recalc(struct Main *bmain, struct Scene *scene, bool time);
-void DAG_ids_clear_recalc(struct Main *bmain);
-
-/* Armature: sorts the bones according to dependencies between them */
-
-void DAG_pose_sort(struct Object *ob);
-
-/* Editors: callbacks to notify editors of datablock changes */
-
-void DAG_editors_update_cb(void (*id_func)(struct Main *bmain, struct ID *id),
- void (*scene_func)(struct Main *bmain, struct Scene *scene, int updated),
- void (*scene_pre_func)(struct Main *bmain, struct Scene *scene, bool time));
-
-void DAG_editors_update_pre(struct Main *bmain, struct Scene *scene, bool time);
-
-/* ** Threaded update ** */
-
-/* Initialize the DAG for threaded update. */
-void DAG_threaded_update_begin(struct Scene *scene,
- void (*func)(void *node, void *user_data),
- void *user_data);
-
-void DAG_threaded_update_handle_node_updated(void *node_v,
- void (*func)(void *node, void *user_data),
- void *user_data);
-
-/* Debugging: print dependency graph for scene or armature object to console */
-
-void DAG_print_dependencies(struct Main *bmain, struct Scene *scene, struct Object *ob);
-
-/* ************************ DAG querying ********************* */
-
-struct Object *DAG_get_node_object(void *node_v);
-const char *DAG_get_node_name(struct Scene *scene, void *node_v);
-short DAG_get_eval_flags_for_object(struct Scene *scene, void *object);
-bool DAG_is_acyclic(struct Scene *scene);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/source/blender/blenkernel/BKE_displist.h b/source/blender/blenkernel/BKE_displist.h
index 9625f05192a..09e9b667369 100644
--- a/source/blender/blenkernel/BKE_displist.h
+++ b/source/blender/blenkernel/BKE_displist.h
@@ -60,8 +60,8 @@ enum {
struct Scene;
struct Object;
struct ListBase;
+struct Depsgraph;
struct DerivedMesh;
-struct EvaluationContext;
/* used for curves, nurbs, mball, importing */
typedef struct DispList {
@@ -86,23 +86,30 @@ void BKE_displist_count(struct ListBase *lb, int *totvert, int *totface, int *to
void BKE_displist_free(struct ListBase *lb);
bool BKE_displist_has_faces(struct ListBase *lb);
-void BKE_displist_make_surf(struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **r_dm_final,
- const bool for_render, const bool for_orco, const bool use_render_resolution);
-void BKE_displist_make_curveTypes(struct Scene *scene, struct Object *ob, const bool for_orco);
-void BKE_displist_make_curveTypes_forRender(struct Scene *scene, struct Object *ob, struct ListBase *dispbase, struct DerivedMesh **r_dm_final,
- const bool for_orco, const bool use_render_resolution);
-void BKE_displist_make_curveTypes_forOrco(struct Scene *scene, struct Object *ob, struct ListBase *dispbase);
-void BKE_displist_make_mball(struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob);
-void BKE_displist_make_mball_forRender(struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob, struct ListBase *dispbase);
+void BKE_displist_make_surf(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase,
+ struct DerivedMesh **r_dm_final, const bool for_render, const bool for_orco, const bool use_render_resolution);
+void BKE_displist_make_curveTypes(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, const bool for_orco);
+void BKE_displist_make_curveTypes_forRender(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase,
+ struct DerivedMesh **r_dm_final, const bool for_orco, const bool use_render_resolution);
+void BKE_displist_make_curveTypes_forOrco(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase);
+void BKE_displist_make_mball(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
+void BKE_displist_make_mball_forRender(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ListBase *dispbase);
bool BKE_displist_surfindex_get(DispList *dl, int a, int *b, int *p1, int *p2, int *p3, int *p4);
void BKE_displist_fill(struct ListBase *dispbase, struct ListBase *to, const float normal_proj[3], const bool flipnormal);
-float BKE_displist_calc_taper(struct Scene *scene, struct Object *taperobj, int cur, int tot);
+float BKE_displist_calc_taper(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *taperobj, int cur, int tot);
/* add Orco layer to the displist object which has got derived mesh and return orco */
-float *BKE_displist_make_orco(struct Scene *scene, struct Object *ob, struct DerivedMesh *dm_final,
- const bool for_render, const bool use_render_resolution);
+float *BKE_displist_make_orco(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm_final,
+ const bool for_render, const bool use_render_resolution);
void BKE_displist_minmax(struct ListBase *dispbase, float min[3], float max[3]);
diff --git a/source/blender/blenkernel/BKE_dynamicpaint.h b/source/blender/blenkernel/BKE_dynamicpaint.h
index 5abb53d4c52..8f795bc7535 100644
--- a/source/blender/blenkernel/BKE_dynamicpaint.h
+++ b/source/blender/blenkernel/BKE_dynamicpaint.h
@@ -27,7 +27,9 @@
* \ingroup bke
*/
+struct Depsgraph;
struct Scene;
+struct ViewLayer;
/* Actual surface point */
typedef struct PaintSurfaceData {
@@ -60,7 +62,8 @@ typedef struct PaintWavePoint {
short state;
} PaintWavePoint;
-struct DerivedMesh *dynamicPaint_Modifier_do(struct DynamicPaintModifierData *pmd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm);
+struct DerivedMesh *dynamicPaint_Modifier_do(struct DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, struct DerivedMesh *dm);
void dynamicPaint_Modifier_free(struct DynamicPaintModifierData *pmd);
void dynamicPaint_Modifier_copy(struct DynamicPaintModifierData *pmd, struct DynamicPaintModifierData *tsmd);
@@ -83,7 +86,7 @@ struct DynamicPaintSurface *get_activeSurface(struct DynamicPaintCanvasSettings
/* image sequence baking */
int dynamicPaint_createUVSurface(struct Scene *scene, struct DynamicPaintSurface *surface, float *progress, short *do_update);
-int dynamicPaint_calculateFrame(struct DynamicPaintSurface *surface, struct Scene *scene, struct Object *cObject, int frame);
+int dynamicPaint_calculateFrame(struct DynamicPaintSurface *surface, struct Depsgraph *depsgraph, struct Scene *scene, struct Object *cObject, int frame);
void dynamicPaint_outputSurfaceImage(struct DynamicPaintSurface *surface, char *filename, short output_layer);
/* PaintPoint state */
diff --git a/source/blender/blenkernel/BKE_editmesh.h b/source/blender/blenkernel/BKE_editmesh.h
index 55a9db9b1e5..5e456fea64f 100644
--- a/source/blender/blenkernel/BKE_editmesh.h
+++ b/source/blender/blenkernel/BKE_editmesh.h
@@ -40,6 +40,7 @@ struct Mesh;
struct Scene;
struct DerivedMesh;
struct MeshStatVis;
+struct Depsgraph;
/**
* This structure is used for mesh edit-mode.
@@ -88,7 +89,6 @@ BMEditMesh *BKE_editmesh_copy(BMEditMesh *em);
BMEditMesh *BKE_editmesh_from_object(struct Object *ob);
void BKE_editmesh_free_derivedmesh(BMEditMesh *em);
void BKE_editmesh_free(BMEditMesh *em);
-void BKE_editmesh_update_linked_customdata(BMEditMesh *em);
void BKE_editmesh_color_free(BMEditMesh *em);
void BKE_editmesh_color_ensure(BMEditMesh *em, const char htype);
@@ -99,6 +99,7 @@ float (*BKE_editmesh_vertexCos_get_orco(BMEditMesh *em, int *r_numVerts))[3]
void BKE_editmesh_statvis_calc(BMEditMesh *em, struct DerivedMesh *dm,
const struct MeshStatVis *statvis);
-float (*BKE_editmesh_vertexCos_get(struct BMEditMesh *em, struct Scene *scene, int *r_numVerts))[3];
+float (*BKE_editmesh_vertexCos_get(
+ struct Depsgraph *depsgraph, struct BMEditMesh *em, struct Scene *scene, int *r_numVerts))[3];
#endif /* __BKE_EDITMESH_H__ */
diff --git a/source/blender/blenkernel/BKE_editmesh_tangent.h b/source/blender/blenkernel/BKE_editmesh_tangent.h
new file mode 100644
index 00000000000..9553fbc1a5c
--- /dev/null
+++ b/source/blender/blenkernel/BKE_editmesh_tangent.h
@@ -0,0 +1,40 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Joseph Eagar.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_EDITMESH_TANGENT_H__
+#define __BKE_EDITMESH_TANGENT_H__
+
+/** \file BKE_editmesh_tangent.h
+ * \ingroup bke
+ */
+
+void BKE_editmesh_loop_tangent_calc(
+ BMEditMesh *em, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_len,
+ const float (*poly_normals)[3],
+ const float (*loop_normals)[3],
+ const float (*vert_orco)[3],
+ CustomData *dm_loopdata_out,
+ const uint dm_loopdata_out_len,
+ short *tangent_mask_curr_p);
+
+#endif /* __BKE_EDITMESH_TANGENT_H__ */
diff --git a/source/blender/blenkernel/BKE_effect.h b/source/blender/blenkernel/BKE_effect.h
index aa45132cbe9..914dd650493 100644
--- a/source/blender/blenkernel/BKE_effect.h
+++ b/source/blender/blenkernel/BKE_effect.h
@@ -44,6 +44,7 @@ struct Group;
struct ParticleSimulationData;
struct ParticleData;
struct ParticleKey;
+struct Depsgraph;
struct EffectorWeights *BKE_add_effector_weights(struct Group *group);
struct PartDeflect *object_add_collision_fields(int type);
@@ -93,6 +94,7 @@ typedef struct EffectorData {
typedef struct EffectorCache {
struct EffectorCache *next, *prev;
+ struct Depsgraph *depsgraph;
struct Scene *scene;
struct Object *ob;
struct ParticleSystem *psys;
@@ -110,9 +112,11 @@ typedef struct EffectorCache {
} EffectorCache;
void free_partdeflect(struct PartDeflect *pd);
-struct ListBase *pdInitEffectors(struct Scene *scene, struct Object *ob_src, struct ParticleSystem *psys_src, struct EffectorWeights *weights, bool for_simulation);
+struct ListBase *pdInitEffectors(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob_src, struct ParticleSystem *psys_src,
+ struct EffectorWeights *weights, bool for_simulation);
void pdEndEffectors(struct ListBase **effectors);
-void pdPrecalculateEffectors(struct ListBase *effectors);
+void pdPrecalculateEffectors(struct Depsgraph *depsgraph, struct ListBase *effectors);
void pdDoEffectors(struct ListBase *effectors, struct ListBase *colliders, struct EffectorWeights *weights, struct EffectedPoint *point, float *force, float *impulse);
void pd_point_from_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, struct EffectedPoint *point);
diff --git a/source/blender/blenkernel/BKE_fluidsim.h b/source/blender/blenkernel/BKE_fluidsim.h
index 6501c968abc..8e04fe2c23a 100644
--- a/source/blender/blenkernel/BKE_fluidsim.h
+++ b/source/blender/blenkernel/BKE_fluidsim.h
@@ -36,10 +36,11 @@ struct Object;
struct Scene;
struct FluidsimSettings;
struct MVert;
+struct Depsgraph;
/* old interface */
-void initElbeemMesh(struct Scene *scene, struct Object *ob,
+void initElbeemMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
int *numVertices, float **vertices,
int *numTriangles, int **triangles,
int useGlobalCoords, int modifierIndex);
diff --git a/source/blender/blenkernel/BKE_freestyle.h b/source/blender/blenkernel/BKE_freestyle.h
index 1045fde0039..f7368683d93 100644
--- a/source/blender/blenkernel/BKE_freestyle.h
+++ b/source/blender/blenkernel/BKE_freestyle.h
@@ -49,7 +49,7 @@ typedef struct FreestyleModuleSettings FreestyleModuleSettings;
/* FreestyleConfig */
void BKE_freestyle_config_init(FreestyleConfig *config);
-void BKE_freestyle_config_free(FreestyleConfig *config);
+void BKE_freestyle_config_free(FreestyleConfig *config, const bool do_id_user);
void BKE_freestyle_config_copy(FreestyleConfig *new_config, FreestyleConfig *config, const int flag);
/* FreestyleConfig.modules */
diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index ce8de456697..e184fd3796b 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -102,7 +102,6 @@ typedef struct Global {
/* G.f */
#define G_RENDER_OGL (1 << 0)
#define G_SWAP_EXCHANGE (1 << 1)
-/* also uses G_FILE_AUTOPLAY */
/* #define G_RENDER_SHADOW (1 << 3) */ /* temp flag, removed */
#define G_BACKBUFSEL (1 << 4)
#define G_PICKSEL (1 << 5)
@@ -141,28 +140,19 @@ enum {
G_DEBUG_DEPSGRAPH_TIME),
G_DEBUG_SIMDATA = (1 << 14), /* sim debug data display */
G_DEBUG_GPU_MEM = (1 << 15), /* gpu memory in status bar */
- G_DEBUG_GPU = (1 << 16), /* gpu debug */
+ G_DEBUG_GPU = (1 << 16), /* gpu debug */
G_DEBUG_IO = (1 << 17), /* IO Debugging (for Collada, ...)*/
+ G_DEBUG_GPU_SHADERS = (1 << 18), /* GLSL shaders */
};
#define G_DEBUG_ALL (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM | G_DEBUG_JOBS | \
- G_DEBUG_FREESTYLE | G_DEBUG_DEPSGRAPH | G_DEBUG_GPU_MEM | G_DEBUG_IO)
+ G_DEBUG_FREESTYLE | G_DEBUG_DEPSGRAPH | G_DEBUG_GPU_MEM | G_DEBUG_IO | G_DEBUG_GPU_SHADERS)
/* G.fileflags */
#define G_AUTOPACK (1 << 0)
#define G_FILE_COMPRESS (1 << 1)
-#define G_FILE_AUTOPLAY (1 << 2)
-
-#ifdef DNA_DEPRECATED_ALLOW
-#define G_FILE_ENABLE_ALL_FRAMES (1 << 3) /* deprecated */
-#define G_FILE_SHOW_DEBUG_PROPS (1 << 4) /* deprecated */
-#define G_FILE_SHOW_FRAMERATE (1 << 5) /* deprecated */
-/* #define G_FILE_SHOW_PROFILE (1 << 6) */ /* deprecated */
-/* #define G_FILE_LOCK (1 << 7) */ /* deprecated */
-/* #define G_FILE_SIGN (1 << 8) */ /* deprecated */
-#endif /* DNA_DEPRECATED_ALLOW */
#define G_FILE_USERPREFS (1 << 9)
#define G_FILE_NO_UI (1 << 10)
diff --git a/source/blender/blenkernel/BKE_group.h b/source/blender/blenkernel/BKE_group.h
index e07dd259970..0195d1f1243 100644
--- a/source/blender/blenkernel/BKE_group.h
+++ b/source/blender/blenkernel/BKE_group.h
@@ -34,24 +34,52 @@
*/
struct Base;
-struct EvaluationContext;
+struct Depsgraph;
struct Group;
struct Main;
struct Object;
struct Scene;
void BKE_group_free(struct Group *group);
+void BKE_group_init(struct Group *group);
struct Group *BKE_group_add(struct Main *bmain, const char *name);
void BKE_group_copy_data(struct Main *bmain, struct Group *group_dst, const struct Group *group_src, const int flag);
struct Group *BKE_group_copy(struct Main *bmain, const struct Group *group);
void BKE_group_make_local(struct Main *bmain, struct Group *group, const bool lib_local);
-bool BKE_group_object_add(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base);
-bool BKE_group_object_unlink(struct Group *group, struct Object *ob, struct Scene *scene, struct Base *base);
+bool BKE_group_object_add(struct Group *group, struct Object *ob);
+bool BKE_group_object_unlink(struct Group *group, struct Object *ob);
struct Group *BKE_group_object_find(struct Group *group, struct Object *ob);
bool BKE_group_object_exists(struct Group *group, struct Object *ob);
bool BKE_group_object_cyclic_check(struct Main *bmain, struct Object *object, struct Group *group);
bool BKE_group_is_animated(struct Group *group, struct Object *parent);
-void BKE_group_handle_recalc_and_update(struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *parent, struct Group *group);
+void BKE_group_handle_recalc_and_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *parent, struct Group *group);
+
+/* Dependency graph evaluation. */
+
+void BKE_group_eval_view_layers(struct Depsgraph *depsgraph,
+ struct Group *group);
+
+/* Helper macros. */
+
+#define FOREACH_GROUP_BASE_BEGIN(_group, _base) \
+ for (Base *_base = (Base *)(_group)->view_layer->object_bases.first; \
+ _base; \
+ _base = _base->next) \
+ {
+
+#define FOREACH_GROUP_BASE_END \
+ }
+
+#define FOREACH_GROUP_OBJECT_BEGIN(_group, _object) \
+ for (Base *_base = (Base *)(_group)->view_layer->object_bases.first; \
+ _base; \
+ _base = _base->next) \
+ { \
+ Object *_object = _base->object; \
+ BLI_assert(_object != NULL);
+
+#define FOREACH_GROUP_OBJECT_END \
+ } ((void)0)
#endif /* __BKE_GROUP_H__ */
diff --git a/source/blender/blenkernel/BKE_icons.h b/source/blender/blenkernel/BKE_icons.h
index 686dba21283..766704b8f9c 100644
--- a/source/blender/blenkernel/BKE_icons.h
+++ b/source/blender/blenkernel/BKE_icons.h
@@ -36,16 +36,45 @@
typedef void (*DrawInfoFreeFP)(void *drawinfo);
+enum {
+ /** ID preview: obj is #ID. */
+ ICON_DATA_ID = 0,
+ /** Preview: obj is #PreviewImage */
+ ICON_DATA_PREVIEW,
+ /** 2D triangles: obj is #Icon_Geom */
+ ICON_DATA_GEOM,
+};
+
struct Icon {
void *drawinfo;
+ /**
+ * Data defined by #obj_type
+ * \note for #ICON_DATA_GEOM the memory is owned by the icon,
+ * could be made into a flag if we want that to be optional.
+ */
void *obj;
+ char obj_type;
+ /** Internal use only. */
+ char flag;
/** #ID_Type or 0 when not used for ID preview. */
short id_type;
DrawInfoFreeFP drawinfo_free;
};
+/** Used for #ICON_DATA_GEOM, assigned to #Icon.obj. */
+struct Icon_Geom {
+ int icon_id;
+ int coords_len;
+ int coords_range[2];
+ const unsigned char (*coords)[2];
+ const unsigned char (*colors)[4];
+ /* when not NULL, the memory of coords and colors is a sub-region of this pointer. */
+ const void *mem;
+};
+
typedef struct Icon Icon;
+struct ImBuf;
struct PreviewImage;
struct ID;
@@ -68,7 +97,8 @@ void BKE_icon_set(const int icon_id, struct Icon *icon);
/* remove icon and free data if library object becomes invalid */
void BKE_icon_id_delete(struct ID *id);
-void BKE_icon_delete(const int icon_id);
+bool BKE_icon_delete(const int icon_id);
+bool BKE_icon_delete_unmanaged(const int icon_id);
/* report changes - icon needs to be recalculated */
void BKE_icon_changed(const int icon_id);
@@ -120,6 +150,14 @@ struct PreviewImage *BKE_previewimg_cached_thumbnail_read(
void BKE_previewimg_cached_release(const char *name);
void BKE_previewimg_cached_release_pointer(struct PreviewImage *prv);
+int BKE_icon_geom_ensure(struct Icon_Geom *geom);
+struct Icon_Geom *BKE_icon_geom_from_memory(const uchar *data, size_t data_len);
+struct Icon_Geom *BKE_icon_geom_from_file(const char *filename);
+
+struct ImBuf *BKE_icon_geom_rasterize(
+ const struct Icon_Geom *geom,
+ const unsigned int size_x, const unsigned int size_y);
+
#define ICON_RENDER_DEFAULT_HEIGHT 32
#endif /* __BKE_ICONS_H__ */
diff --git a/source/blender/blenkernel/BKE_idprop.h b/source/blender/blenkernel/BKE_idprop.h
index 8a2cdd7b37c..94630eaa7b0 100644
--- a/source/blender/blenkernel/BKE_idprop.h
+++ b/source/blender/blenkernel/BKE_idprop.h
@@ -32,6 +32,10 @@
#include "BLI_compiler_attrs.h"
+#ifdef __cplusplus
+extern "C" {
+#endif
+
struct IDProperty;
struct ID;
@@ -91,6 +95,7 @@ void IDP_ReplaceGroupInGroup(struct IDProperty *dest, const struct IDProperty *s
void IDP_ReplaceInGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
void IDP_ReplaceInGroup_ex(struct IDProperty *group, struct IDProperty *prop, struct IDProperty *prop_exist);
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite) ATTR_NONNULL();
+void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, const bool do_overwrite, const int flag) ATTR_NONNULL();
bool IDP_AddToGroup(struct IDProperty *group, struct IDProperty *prop) ATTR_NONNULL();
bool IDP_InsertToGroup(struct IDProperty *group, struct IDProperty *previous,
struct IDProperty *pnew) ATTR_NONNULL(1 /* group */, 3 /* pnew */);
@@ -118,6 +123,8 @@ void IDP_ClearProperty(IDProperty *prop);
void IDP_RelinkProperty(struct IDProperty *prop);
+void IDP_Reset(IDProperty *prop, const IDProperty *reference);
+
#define IDP_Int(prop) ((prop)->data.val)
#define IDP_Array(prop) ((prop)->data.pointer)
/* C11 const correctness for casts */
@@ -154,4 +161,8 @@ void IDP_repr_fn(
void *user_data);
void IDP_print(const struct IDProperty *prop);
+#ifdef __cplusplus
+}
+#endif
+
#endif /* __BKE_IDPROP_H__ */
diff --git a/source/blender/blenkernel/BKE_lamp.h b/source/blender/blenkernel/BKE_lamp.h
index 3673e657b33..aa655c66477 100644
--- a/source/blender/blenkernel/BKE_lamp.h
+++ b/source/blender/blenkernel/BKE_lamp.h
@@ -50,8 +50,6 @@ struct Lamp *BKE_lamp_localize(struct Lamp *la) ATTR_WARN_UNUSED_RESULT;
void BKE_lamp_make_local(struct Main *bmain, struct Lamp *la, const bool lib_local);
void BKE_lamp_free(struct Lamp *la);
-void lamp_drivers_update(struct Scene *scene, struct Lamp *la, float ctime);
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_lattice.h b/source/blender/blenkernel/BKE_lattice.h
index f7d006785d2..6e9f83cf8a9 100644
--- a/source/blender/blenkernel/BKE_lattice.h
+++ b/source/blender/blenkernel/BKE_lattice.h
@@ -38,11 +38,13 @@
struct Lattice;
struct Main;
+struct Mesh;
struct Object;
struct Scene;
struct DerivedMesh;
struct BPoint;
struct MDeformVert;
+struct Depsgraph;
void BKE_lattice_resize(struct Lattice *lt, int u, int v, int w, struct Object *ltOb);
void BKE_lattice_init(struct Lattice *lt);
@@ -61,23 +63,24 @@ void end_latt_deform(struct LatticeDeformData *lattice_deform_data);
bool object_deform_mball(struct Object *ob, struct ListBase *dispbase);
void outside_lattice(struct Lattice *lt);
-void curve_deform_verts(struct Scene *scene, struct Object *cuOb, struct Object *target,
- struct DerivedMesh *dm, float (*vertexCos)[3],
- int numVerts, const char *vgroup, short defaxis);
-void curve_deform_vector(struct Scene *scene, struct Object *cuOb, struct Object *target,
+void curve_deform_verts(
+ struct Object *cuOb, struct Object *target,
+ struct DerivedMesh *dm, float (*vertexCos)[3],
+ int numVerts, const char *vgroup, short defaxis);
+void curve_deform_vector(struct Object *cuOb, struct Object *target,
float orco[3], float vec[3], float mat[3][3], int no_rot_axis);
void lattice_deform_verts(struct Object *laOb, struct Object *target,
- struct DerivedMesh *dm, float (*vertexCos)[3],
+ struct Mesh *mesh, float (*vertexCos)[3],
int numVerts, const char *vgroup, float influence);
void armature_deform_verts(struct Object *armOb, struct Object *target,
- struct DerivedMesh *dm, float (*vertexCos)[3],
+ const struct Mesh *mesh, float (*vertexCos)[3],
float (*defMats)[3][3], int numVerts, int deformflag,
float (*prevCos)[3], const char *defgrp_name);
float (*BKE_lattice_vertexcos_get(struct Object *ob, int *r_numVerts))[3];
void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3]);
-void BKE_lattice_modifiers_calc(struct Scene *scene, struct Object *ob);
+void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
struct MDeformVert *BKE_lattice_deform_verts_get(struct Object *lattice);
struct BPoint *BKE_lattice_active_point_get(struct Lattice *lt);
@@ -99,9 +102,17 @@ void BKE_lattice_bitmap_from_flag(struct Lattice *lt, unsigned int *bitmap, cons
/* **** Depsgraph evaluation **** */
-struct EvaluationContext;
+struct Depsgraph;
-void BKE_lattice_eval_geometry(struct EvaluationContext *eval_ctx,
+void BKE_lattice_eval_geometry(struct Depsgraph *depsgraph,
struct Lattice *latt);
+/* Draw Cache */
+enum {
+ BKE_LATTICE_BATCH_DIRTY_ALL = 0,
+ BKE_LATTICE_BATCH_DIRTY_SELECT,
+};
+void BKE_lattice_batch_cache_dirty(struct Lattice *lt, int mode);
+void BKE_lattice_batch_cache_free(struct Lattice *lt);
+
#endif /* __BKE_LATTICE_H__ */
diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
new file mode 100644
index 00000000000..5c84dbf160e
--- /dev/null
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -0,0 +1,420 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation, Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_LAYER_H__
+#define __BKE_LAYER_H__
+
+/** \file blender/blenkernel/BKE_layer.h
+ * \ingroup bke
+ */
+
+#include "BKE_collection.h"
+
+#include "DNA_scene_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#define TODO_LAYER_OVERRIDE /* CollectionOverride */
+#define TODO_LAYER_OPERATORS /* collection mamanger and property panel operators */
+#define TODO_LAYER /* generic todo */
+
+#define ROOT_PROP "root"
+
+struct Base;
+struct Depsgraph;
+struct Group;
+struct ID;
+struct IDProperty;
+struct LayerCollection;
+struct ListBase;
+struct Main;
+struct Object;
+struct RenderEngine;
+struct Scene;
+struct SceneCollection;
+struct ViewLayer;
+struct WorkSpace;
+
+void BKE_layer_exit(void);
+
+struct ViewLayer *BKE_view_layer_default_view(const struct Scene *scene);
+struct ViewLayer *BKE_view_layer_default_render(const struct Scene *scene);
+struct ViewLayer *BKE_view_layer_from_workspace_get(const struct Scene *scene, const struct WorkSpace *workspace);
+struct ViewLayer *BKE_view_layer_add(struct Scene *scene, const char *name);
+struct ViewLayer *BKE_view_layer_group_add(struct Group *group);
+
+/* DEPRECATED */
+struct ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const struct Scene *scene);
+
+void BKE_view_layer_free(struct ViewLayer *view_layer);
+void BKE_view_layer_free_ex(struct ViewLayer *view_layer, const bool do_id_user);
+
+void BKE_view_layer_selected_objects_tag(struct ViewLayer *view_layer, const int tag);
+
+struct Object *BKE_view_layer_camera_find(struct ViewLayer *view_layer);
+struct ViewLayer *BKE_view_layer_first_from_id(const struct ID *owner_id);
+struct ViewLayer *BKE_view_layer_find_from_collection(const struct ID *owner_id, struct LayerCollection *lc);
+struct Base *BKE_view_layer_base_find(struct ViewLayer *view_layer, struct Object *ob);
+void BKE_view_layer_base_deselect_all(struct ViewLayer *view_layer);
+void BKE_view_layer_base_select(struct ViewLayer *view_layer, struct Base *selbase);
+
+void BKE_layer_collection_sync_flags(
+ struct ID *owner_id,
+ struct SceneCollection *scene_collection_dst,
+ struct SceneCollection *scene_collection_src);
+
+void BKE_view_layer_copy_data(
+ struct ViewLayer *view_layer_dst, struct ViewLayer *view_layer_src,
+ struct SceneCollection *mc_dst, struct SceneCollection *mc_src,
+ const int flag);
+
+struct LayerCollection *BKE_layer_collection_duplicate(struct ID *owner_id, struct LayerCollection *layer_collection);
+
+void BKE_layer_collection_free(struct ViewLayer *view_layer, struct LayerCollection *lc);
+
+struct LayerCollection *BKE_layer_collection_get_active(struct ViewLayer *view_layer);
+struct LayerCollection *BKE_layer_collection_get_active_ensure(struct Scene *scene, struct ViewLayer *view_layer);
+
+int BKE_layer_collection_count(struct ViewLayer *view_layer);
+
+struct LayerCollection *BKE_layer_collection_from_index(struct ViewLayer *view_layer, const int index);
+int BKE_layer_collection_findindex(struct ViewLayer *view_layer, const struct LayerCollection *lc);
+
+bool BKE_layer_collection_move_above(const struct ID *owner_id, struct LayerCollection *lc_dst, struct LayerCollection *lc_src);
+bool BKE_layer_collection_move_below(const struct ID *owner_id, struct LayerCollection *lc_dst, struct LayerCollection *lc_src);
+bool BKE_layer_collection_move_into(const struct ID *owner_id, struct LayerCollection *lc_dst, struct LayerCollection *lc_src);
+
+void BKE_layer_collection_resync(const struct ID *owner_id, const struct SceneCollection *sc);
+
+struct LayerCollection *BKE_collection_link(struct ViewLayer *view_layer, struct SceneCollection *sc);
+
+void BKE_collection_unlink(struct ViewLayer *view_layer, struct LayerCollection *lc);
+
+void BKE_collection_enable(struct ViewLayer *view_layer, struct LayerCollection *lc);
+
+struct LayerCollection *BKE_layer_collection_first_from_scene_collection(struct ViewLayer *view_layer, const struct SceneCollection *scene_collection);
+bool BKE_view_layer_has_collection(struct ViewLayer *view_layer, const struct SceneCollection *sc);
+bool BKE_scene_has_object(struct Scene *scene, struct Object *ob);
+
+void BKE_layer_collection_objects_select(struct LayerCollection *layer_collection);
+
+/* syncing */
+
+void BKE_layer_sync_new_scene_collection(struct ID *owner_id, const struct SceneCollection *sc_parent, struct SceneCollection *sc);
+void BKE_layer_sync_object_link(const struct ID *owner_id, struct SceneCollection *sc, struct Object *ob);
+void BKE_layer_sync_object_unlink(const struct ID *owner_id, struct SceneCollection *sc, struct Object *ob);
+
+/* override */
+
+void BKE_override_view_layer_datablock_add(struct ViewLayer *view_layer, int id_type, const char *data_path, const struct ID *owner_id);
+void BKE_override_view_layer_int_add(struct ViewLayer *view_layer, int id_type, const char *data_path, const int value);
+
+void BKE_override_layer_collection_boolean_add(struct LayerCollection *layer_collection, int id_type, const char *data_path, const bool value);
+
+/* engine settings */
+typedef void (*EngineSettingsCB)(struct RenderEngine *engine, struct IDProperty *props);
+
+struct IDProperty *BKE_layer_collection_engine_evaluated_get(struct Object *ob, const char *engine_name);
+struct IDProperty *BKE_layer_collection_engine_collection_get(struct LayerCollection *lc, const char *engine_name);
+struct IDProperty *BKE_layer_collection_engine_scene_get(struct Scene *scene, const char *engine_name);
+void BKE_layer_collection_engine_settings_callback_register(struct Main *bmain, const char *engine_name, EngineSettingsCB func);
+void BKE_layer_collection_engine_settings_callback_free(void);
+void BKE_layer_collection_engine_settings_create(struct IDProperty *root);
+void BKE_layer_collection_engine_settings_validate_scene(struct Scene *scene);
+void BKE_layer_collection_engine_settings_validate_collection(struct LayerCollection *lc);
+
+struct IDProperty *BKE_view_layer_engine_evaluated_get(struct ViewLayer *view_layer, const char *engine_name);
+struct IDProperty *BKE_view_layer_engine_layer_get(struct ViewLayer *view_layer, const char *engine_name);
+struct IDProperty *BKE_view_layer_engine_scene_get(struct Scene *scene, const char *engine_name);
+void BKE_view_layer_engine_settings_callback_register(struct Main *bmain, const char *engine_name, EngineSettingsCB func);
+void BKE_view_layer_engine_settings_callback_free(void);
+void BKE_view_layer_engine_settings_validate_scene(struct Scene *scene);
+void BKE_view_layer_engine_settings_validate_layer(struct ViewLayer *view_layer);
+void BKE_view_layer_engine_settings_create(struct IDProperty *root);
+
+void BKE_collection_engine_property_add_float(struct IDProperty *props, const char *name, float value);
+void BKE_collection_engine_property_add_float_array(
+ struct IDProperty *props, const char *name, const float *values, const int array_length);
+void BKE_collection_engine_property_add_int(struct IDProperty *props, const char *name, int value);
+void BKE_collection_engine_property_add_bool(struct IDProperty *props, const char *name, bool value);
+
+int BKE_collection_engine_property_value_get_int(struct IDProperty *props, const char *name);
+float BKE_collection_engine_property_value_get_float(struct IDProperty *props, const char *name);
+const float *BKE_collection_engine_property_value_get_float_array(struct IDProperty *props, const char *name);
+bool BKE_collection_engine_property_value_get_bool(struct IDProperty *props, const char *name);
+void BKE_collection_engine_property_value_set_int(struct IDProperty *props, const char *name, int value);
+void BKE_collection_engine_property_value_set_float(struct IDProperty *props, const char *name, float value);
+void BKE_collection_engine_property_value_set_float_array(struct IDProperty *props, const char *name, const float *values);
+void BKE_collection_engine_property_value_set_bool(struct IDProperty *props, const char *name, bool value);
+
+/* evaluation */
+
+void BKE_layer_eval_view_layer(
+ struct Depsgraph *depsgraph,
+ struct ID *owner_id,
+ struct ViewLayer *view_layer);
+
+void BKE_layer_eval_view_layer_indexed(
+ struct Depsgraph *depsgraph,
+ struct ID *owner_id,
+ int view_layer_index);
+
+/* iterators */
+
+void BKE_view_layer_selected_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
+void BKE_view_layer_selected_objects_iterator_next(BLI_Iterator *iter);
+void BKE_view_layer_selected_objects_iterator_end(BLI_Iterator *iter);
+
+void BKE_view_layer_visible_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
+void BKE_view_layer_visible_objects_iterator_next(BLI_Iterator *iter);
+void BKE_view_layer_visible_objects_iterator_end(BLI_Iterator *iter);
+
+struct ObjectsInModeIteratorData {
+ int object_mode;
+ struct ViewLayer *view_layer;
+ struct Base *base_active;
+};
+
+void BKE_view_layer_renderable_objects_iterator_begin(BLI_Iterator *iter, void *data_in);
+void BKE_view_layer_renderable_objects_iterator_next(BLI_Iterator *iter);
+void BKE_view_layer_renderable_objects_iterator_end(BLI_Iterator *iter);
+
+void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in);
+void BKE_view_layer_bases_in_mode_iterator_next(BLI_Iterator *iter);
+void BKE_view_layer_bases_in_mode_iterator_end(BLI_Iterator *iter);
+
+void BKE_view_layer_selected_bases_iterator_begin(BLI_Iterator *iter, void *data_in);
+void BKE_view_layer_selected_bases_iterator_next(BLI_Iterator *iter);
+void BKE_view_layer_selected_bases_iterator_end(BLI_Iterator *iter);
+
+void BKE_view_layer_visible_bases_iterator_begin(BLI_Iterator *iter, void *data_in);
+void BKE_view_layer_visible_bases_iterator_next(BLI_Iterator *iter);
+void BKE_view_layer_visible_bases_iterator_end(BLI_Iterator *iter);
+
+#define FOREACH_SELECTED_OBJECT_BEGIN(view_layer, _instance) \
+ ITER_BEGIN(BKE_view_layer_selected_objects_iterator_begin, \
+ BKE_view_layer_selected_objects_iterator_next, \
+ BKE_view_layer_selected_objects_iterator_end, \
+ view_layer, Object *, _instance)
+
+#define FOREACH_SELECTED_OBJECT_END \
+ ITER_END
+
+#define FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, _instance) \
+ ITER_BEGIN(BKE_view_layer_visible_objects_iterator_begin, \
+ BKE_view_layer_visible_objects_iterator_next, \
+ BKE_view_layer_visible_objects_iterator_end, \
+ view_layer, Object *, _instance)
+
+#define FOREACH_VISIBLE_OBJECT_END \
+ ITER_END
+
+
+#define FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _object_mode, _instance) \
+{ \
+ struct ObjectsInModeIteratorData data_ = { \
+ .object_mode = _object_mode, \
+ .view_layer = _view_layer, \
+ .base_active = _view_layer->basact, \
+ }; \
+ ITER_BEGIN(BKE_view_layer_bases_in_mode_iterator_begin, \
+ BKE_view_layer_bases_in_mode_iterator_next, \
+ BKE_view_layer_bases_in_mode_iterator_end, \
+ &data_, Base *, _instance)
+
+#define FOREACH_BASE_IN_MODE_END \
+ ITER_END; \
+} ((void)0)
+
+#define FOREACH_BASE_IN_EDIT_MODE_BEGIN(_view_layer, _instance) \
+ FOREACH_BASE_IN_MODE_BEGIN(_view_layer, OB_MODE_EDIT, _instance)
+
+#define FOREACH_BASE_IN_EDIT_MODE_END \
+ FOREACH_BASE_IN_MODE_END
+
+#define FOREACH_OBJECT_IN_MODE_BEGIN(_view_layer, _object_mode, _instance) \
+ FOREACH_BASE_IN_MODE_BEGIN(_view_layer, _object_mode, _base) { \
+ Object *_instance = _base->object;
+
+#define FOREACH_OBJECT_IN_MODE_END \
+ } FOREACH_BASE_IN_MODE_END
+
+#define FOREACH_OBJECT_IN_EDIT_MODE_BEGIN(_view_layer, _instance) \
+ FOREACH_BASE_IN_EDIT_MODE_BEGIN(_view_layer, _base) { \
+ Object *_instance = _base->object;
+
+#define FOREACH_OBJECT_IN_EDIT_MODE_END \
+ } FOREACH_BASE_IN_EDIT_MODE_END
+
+#define FOREACH_SELECTED_BASE_BEGIN(view_layer, _instance) \
+ ITER_BEGIN(BKE_view_layer_selected_bases_iterator_begin, \
+ BKE_view_layer_selected_bases_iterator_next, \
+ BKE_view_layer_selected_bases_iterator_end, \
+ view_layer, Base *, _instance)
+
+#define FOREACH_SELECTED_BASE_END \
+ ITER_END
+
+#define FOREACH_VISIBLE_BASE_BEGIN(view_layer, _instance) \
+ ITER_BEGIN(BKE_view_layer_visible_bases_iterator_begin, \
+ BKE_view_layer_visible_bases_iterator_next, \
+ BKE_view_layer_visible_bases_iterator_end, \
+ view_layer, Base *, _instance)
+
+#define FOREACH_VISIBLE_BASE_END \
+ ITER_END
+
+
+#define FOREACH_OBJECT_BEGIN(view_layer, _instance) \
+{ \
+ Object *_instance; \
+ Base *_base; \
+ for (_base = (view_layer)->object_bases.first; _base; _base = _base->next) { \
+ _instance = _base->object;
+
+#define FOREACH_OBJECT_END \
+ } \
+} ((void)0)
+
+#define FOREACH_OBJECT_FLAG_BEGIN(scene, view_layer, flag, _instance) \
+{ \
+ IteratorBeginCb func_begin; \
+ IteratorCb func_next, func_end; \
+ void *data_in; \
+ \
+ if (flag == SELECT) { \
+ func_begin = &BKE_view_layer_selected_objects_iterator_begin; \
+ func_next = &BKE_view_layer_selected_objects_iterator_next; \
+ func_end = &BKE_view_layer_selected_objects_iterator_end; \
+ data_in = (view_layer); \
+ } \
+ else { \
+ func_begin = BKE_scene_objects_iterator_begin; \
+ func_next = BKE_scene_objects_iterator_next; \
+ func_end = BKE_scene_objects_iterator_end; \
+ data_in = (scene); \
+ } \
+ ITER_BEGIN(func_begin, func_next, func_end, data_in, Object *, _instance)
+
+
+#define FOREACH_OBJECT_FLAG_END \
+ ITER_END; \
+} ((void)0)
+
+struct ObjectsRenderableIteratorData {
+ struct Scene *scene;
+ struct Base base_temp;
+ struct Scene scene_temp;
+
+ struct {
+ struct ViewLayer *view_layer;
+ struct Base *base;
+ struct Scene *set;
+ } iter;
+};
+
+#define FOREACH_OBJECT_RENDERABLE_BEGIN(scene_, _instance) \
+{ \
+ struct ObjectsRenderableIteratorData data_ = { \
+ .scene = (scene_), \
+ }; \
+ ITER_BEGIN(BKE_view_layer_renderable_objects_iterator_begin, \
+ BKE_view_layer_renderable_objects_iterator_next, \
+ BKE_view_layer_renderable_objects_iterator_end, \
+ &data_, Object *, _instance)
+
+
+#define FOREACH_OBJECT_RENDERABLE_END \
+ ITER_END; \
+} ((void)0)
+
+
+/* layer_utils.c */
+
+struct ObjectsInModeParams {
+ int object_mode;
+ uint no_dup_data : 1;
+
+ bool (*filter_fn)(struct Object *ob, void *user_data);
+ void *filter_userdata;
+};
+
+Base **BKE_view_layer_array_from_bases_in_mode_params(
+ struct ViewLayer *view_layer, uint *r_len,
+ const struct ObjectsInModeParams *params);
+
+struct Object **BKE_view_layer_array_from_objects_in_mode_params(
+ struct ViewLayer *view_layer, uint *len,
+ const struct ObjectsInModeParams *params);
+
+#define BKE_view_layer_array_from_objects_in_mode(view_layer, r_len, ...) \
+ BKE_view_layer_array_from_objects_in_mode_params( \
+ view_layer, r_len, \
+ &(const struct ObjectsInModeParams)__VA_ARGS__)
+
+#define BKE_view_layer_array_from_bases_in_mode(view_layer, r_len, ...) \
+ BKE_view_layer_array_from_bases_in_mode_params( \
+ view_layer, r_len, \
+ &(const struct ObjectsInModeParams)__VA_ARGS__)
+
+bool BKE_view_layer_filter_edit_mesh_has_uvs(struct Object *ob, void *user_data);
+bool BKE_view_layer_filter_edit_mesh_has_edges(struct Object *ob, void *user_data);
+
+/* Utility macros that wrap common args (add more as needed). */
+
+#define BKE_view_layer_array_from_objects_in_edit_mode(view_layer, r_len) \
+ BKE_view_layer_array_from_objects_in_mode( \
+ view_layer, r_len, { \
+ .object_mode = OB_MODE_EDIT});
+
+#define BKE_view_layer_array_from_bases_in_edit_mode(view_layer, r_len) \
+ BKE_view_layer_array_from_bases_in_mode( \
+ view_layer, r_len, { \
+ .object_mode = OB_MODE_EDIT});
+
+#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, r_len) \
+ BKE_view_layer_array_from_objects_in_mode( \
+ view_layer, r_len, { \
+ .object_mode = OB_MODE_EDIT, \
+ .no_dup_data = true});
+
+#define BKE_view_layer_array_from_bases_in_edit_mode_unique_data(view_layer, r_len) \
+ BKE_view_layer_array_from_bases_in_mode( \
+ view_layer, r_len, { \
+ .object_mode = OB_MODE_EDIT, \
+ .no_dup_data = true});
+
+#define BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, r_len) \
+ BKE_view_layer_array_from_objects_in_mode( \
+ view_layer, r_len, { \
+ .object_mode = OB_MODE_EDIT, \
+ .no_dup_data = true, \
+ .filter_fn = BKE_view_layer_filter_edit_mesh_has_uvs});
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_LAYER_H__ */
diff --git a/source/blender/blenkernel/BKE_library.h b/source/blender/blenkernel/BKE_library.h
index 9e1bc2611fb..0cd5e032f68 100644
--- a/source/blender/blenkernel/BKE_library.h
+++ b/source/blender/blenkernel/BKE_library.h
@@ -52,9 +52,13 @@ struct PropertyRNA;
size_t BKE_libblock_get_alloc_info(short type, const char **name);
void *BKE_libblock_alloc_notest(short type) ATTR_WARN_UNUSED_RESULT;
-void *BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const int flag) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+void *BKE_libblock_alloc(struct Main *bmain, short type, const char *name, const int flag) ATTR_WARN_UNUSED_RESULT;
void BKE_libblock_init_empty(struct ID *id) ATTR_NONNULL(1);
+void *BKE_id_new(struct Main *bmain, const short type, const char *name);
+void *BKE_id_new_nomain(const short type, const char *name);
+
+
/**
* New ID creation/copying options.
*/
@@ -78,6 +82,7 @@ enum {
/* XXX TODO Do we want to keep that? would rather try to get rid of it... */
LIB_ID_COPY_ACTIONS = 1 << 19, /* EXCEPTION! Deep-copy actions used by animdata of copied ID. */
LIB_ID_COPY_KEEP_LIB = 1 << 20, /* Keep the library pointer when copying datablock outside of bmain. */
+ LIB_ID_COPY_NO_ANIMDATA = 1 << 21, /* Don't copy id->adt, used by ID datablock localization routines. */
};
void BKE_libblock_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag);
@@ -148,6 +153,7 @@ bool id_make_local(struct Main *bmain, struct ID *id, const bool test, const boo
bool id_single_user(struct bContext *C, struct ID *id, struct PointerRNA *ptr, struct PropertyRNA *prop);
bool id_copy(struct Main *bmain, const struct ID *id, struct ID **newid, bool test);
bool BKE_id_copy_ex(struct Main *bmain, const struct ID *id, struct ID **r_newid, const int flag, const bool test);
+void BKE_id_swap(struct Main *bmain, struct ID *id_a, struct ID *id_b);
void id_sort_by_name(struct ListBase *lb, struct ID *id);
void BKE_id_expand_local(struct Main *bmain, struct ID *id);
void BKE_id_copy_ensure_local(struct Main *bmain, const struct ID *old_id, struct ID *new_id);
@@ -158,7 +164,7 @@ void id_clear_lib_data_ex(struct Main *bmain, struct ID *id, const bool id_in_ma
struct ListBase *which_libbase(struct Main *mainlib, short type);
-#define MAX_LIBARRAY 35
+#define MAX_LIBARRAY 37
int set_listbasepointers(struct Main *main, struct ListBase *lb[MAX_LIBARRAY]);
/* Main API */
diff --git a/source/blender/blenkernel/BKE_library_override.h b/source/blender/blenkernel/BKE_library_override.h
new file mode 100644
index 00000000000..6f32d565562
--- /dev/null
+++ b/source/blender/blenkernel/BKE_library_override.h
@@ -0,0 +1,87 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Bastien Montagne.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_LIBRARY_OVERRIDE_H__
+#define __BKE_LIBRARY_OVERRIDE_H__
+
+/** \file BKE_library_override.h
+ * \ingroup bke
+ * \since December 2016
+ * \author mont29
+ */
+
+struct ID;
+struct IDOverrideStatic;
+struct IDOverrideStaticProperty;
+struct IDOverrideStaticPropertyOperation;
+struct Main;
+
+struct IDOverrideStatic *BKE_override_static_init(struct ID *local_id, struct ID *reference_id);
+void BKE_override_static_copy(struct ID *dst_id, const struct ID *src_id);
+void BKE_override_static_clear(struct IDOverrideStatic *override);
+void BKE_override_static_free(struct IDOverrideStatic **override);
+
+struct ID *BKE_override_static_create_from_id(struct Main *bmain, struct ID *reference_id);
+bool BKE_override_static_create_from_tag(struct Main *bmain);
+
+struct IDOverrideStaticProperty *BKE_override_static_property_find(struct IDOverrideStatic *override, const char *rna_path);
+struct IDOverrideStaticProperty *BKE_override_static_property_get(struct IDOverrideStatic *override, const char *rna_path, bool *r_created);
+void BKE_override_static_property_delete(struct IDOverrideStatic *override, struct IDOverrideStaticProperty *override_property);
+
+struct IDOverrideStaticPropertyOperation *BKE_override_static_property_operation_find(
+ struct IDOverrideStaticProperty *override_property,
+ const char *subitem_refname, const char *subitem_locname,
+ const int subitem_refindex, const int subitem_locindex, const bool strict, bool *r_strict);
+struct IDOverrideStaticPropertyOperation *BKE_override_static_property_operation_get(
+ struct IDOverrideStaticProperty *override_property, const short operation,
+ const char *subitem_refname, const char *subitem_locname,
+ const int subitem_refindex, const int subitem_locindex,
+ const bool strict, bool *r_strict, bool *r_created);
+void BKE_override_static_property_operation_delete(
+ struct IDOverrideStaticProperty *override_property, struct IDOverrideStaticPropertyOperation *override_property_operation);
+
+bool BKE_override_static_status_check_local(struct ID *local);
+bool BKE_override_static_status_check_reference(struct ID *local);
+
+bool BKE_override_static_operations_create(struct ID *local, const bool force_auto);
+void BKE_main_override_static_operations_create(struct Main *bmain, const bool force_auto);
+
+void BKE_override_static_update(struct Main *bmain, struct ID *local);
+void BKE_main_override_static_update(struct Main *bmain);
+
+
+/* Storage (.blend file writing) part. */
+
+/* For now, we just use a temp main list. */
+typedef struct Main OverrideStaticStorage;
+
+OverrideStaticStorage *BKE_override_static_operations_store_initialize(void);
+struct ID *BKE_override_static_operations_store_start(OverrideStaticStorage *override_storage, struct ID *local);
+void BKE_override_static_operations_store_end(OverrideStaticStorage *override_storage, struct ID *local);
+void BKE_override_static_operations_store_finalize(OverrideStaticStorage *override_storage);
+
+
+
+#endif /* __BKE_LIBRARY_OVERRIDE_H__ */
diff --git a/source/blender/blenkernel/BKE_library_query.h b/source/blender/blenkernel/BKE_library_query.h
index d6e7d98f371..b66fc0aab16 100644
--- a/source/blender/blenkernel/BKE_library_query.h
+++ b/source/blender/blenkernel/BKE_library_query.h
@@ -56,6 +56,9 @@ enum {
* How to handle that kind of cases totally depends on what caller code is doing... */
IDWALK_CB_LOOPBACK = (1 << 4),
+ /** That ID is used as static override's reference by its owner. */
+ IDWALK_CB_STATIC_OVERRIDE_REFERENCE = (1 << 5),
+
/**
* Adjusts #ID.us reference-count.
* \note keep in sync with 'newlibadr_us' use in readfile.c
diff --git a/source/blender/blenkernel/BKE_library_remap.h b/source/blender/blenkernel/BKE_library_remap.h
index fd37fd762f4..3425ca011b7 100644
--- a/source/blender/blenkernel/BKE_library_remap.h
+++ b/source/blender/blenkernel/BKE_library_remap.h
@@ -51,6 +51,8 @@ enum {
* This is needed e.g. in reload scenario, since we have to ensure remapping of Armature data of local proxy
* is also performed. Usual nightmare... */
ID_REMAP_NO_INDIRECT_PROXY_DATA_USAGE = 1 << 4,
+ /* Do not remap static override pointers. */
+ ID_REMAP_SKIP_STATIC_OVERRIDE = 1 << 5,
};
/* Note: Requiring new_id to be non-null, this *may* not be the case ultimately, but makes things simpler for now. */
diff --git a/source/blender/blenkernel/BKE_lightprobe.h b/source/blender/blenkernel/BKE_lightprobe.h
new file mode 100644
index 00000000000..a769b6653d7
--- /dev/null
+++ b/source/blender/blenkernel/BKE_lightprobe.h
@@ -0,0 +1,46 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_LIGHTPROBE_H__
+#define __BKE_LIGHTPROBE_H__
+
+/** \file BKE_lightprobe.h
+ * \ingroup bke
+ * \brief General operations for probes.
+ */
+
+struct Main;
+struct LightProbe;
+
+void BKE_lightprobe_init(struct LightProbe *probe);
+void *BKE_lightprobe_add(struct Main *bmain, const char *name);
+void BKE_lightprobe_copy_data(struct Main *bmain, struct LightProbe *probe_dst, const struct LightProbe *probe_src, const int flag);
+struct LightProbe *BKE_lightprobe_copy(struct Main *bmain, const struct LightProbe *probe);
+void BKE_lightprobe_make_local(struct Main *bmain, struct LightProbe *probe, const bool lib_local);
+void BKE_lightprobe_free(struct LightProbe *probe);
+
+#endif /* __BKE_LIGHTPROBE_H__ */
diff --git a/source/blender/blenkernel/BKE_linestyle.h b/source/blender/blenkernel/BKE_linestyle.h
index 3ba4fbe0338..376a324d25c 100644
--- a/source/blender/blenkernel/BKE_linestyle.h
+++ b/source/blender/blenkernel/BKE_linestyle.h
@@ -48,6 +48,7 @@ struct Main;
struct Object;
struct ColorBand;
struct bContext;
+struct ViewLayer;
void BKE_linestyle_init(struct FreestyleLineStyle *linestyle);
FreestyleLineStyle *BKE_linestyle_new(struct Main *bmain, const char *name);
@@ -59,7 +60,7 @@ FreestyleLineStyle *BKE_linestyle_copy(struct Main *bmain, const FreestyleLineSt
void BKE_linestyle_make_local(struct Main *bmain, struct FreestyleLineStyle *linestyle, const bool lib_local);
-FreestyleLineStyle *BKE_linestyle_active_from_scene(struct Scene *scene);
+FreestyleLineStyle *BKE_linestyle_active_from_view_layer(struct ViewLayer *view_layer);
LineStyleModifier *BKE_linestyle_color_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type);
LineStyleModifier *BKE_linestyle_alpha_modifier_add(FreestyleLineStyle *linestyle, const char *name, int type);
diff --git a/source/blender/blenkernel/BKE_main.h b/source/blender/blenkernel/BKE_main.h
index e224155726f..647af88d980 100644
--- a/source/blender/blenkernel/BKE_main.h
+++ b/source/blender/blenkernel/BKE_main.h
@@ -48,7 +48,7 @@
extern "C" {
#endif
-struct EvaluationContext;
+struct Depsgraph;
struct Library;
struct MainLock;
struct GHash;
@@ -110,6 +110,7 @@ typedef struct Main {
ListBase vfont;
ListBase text;
ListBase speaker;
+ ListBase lightprobe;
ListBase sound;
ListBase group;
ListBase armature;
@@ -125,12 +126,10 @@ typedef struct Main {
ListBase mask;
ListBase linestyle;
ListBase cachefiles;
+ ListBase workspaces;
char id_tag_update[MAX_LIBARRAY];
- /* Evaluation context used by viewport */
- struct EvaluationContext *eval_ctx;
-
/* Must be generated, used and freed by same code - never assume this is valid data unless you know
* when, who and how it was created.
* Used by code doing a lot of remapping etc. at once to speed things up. */
diff --git a/source/blender/blenkernel/BKE_mask.h b/source/blender/blenkernel/BKE_mask.h
index 5598f0dc473..976ee5b2691 100644
--- a/source/blender/blenkernel/BKE_mask.h
+++ b/source/blender/blenkernel/BKE_mask.h
@@ -32,7 +32,7 @@
* \ingroup bke
*/
-struct EvaluationContext;
+struct Depsgraph;
struct ImageUser;
struct Image;
struct ListBase;
@@ -145,7 +145,6 @@ void BKE_mask_update_display(struct Mask *mask, float ctime);
void BKE_mask_evaluate_all_masks(struct Main *bmain, float ctime, const bool do_newframe);
void BKE_mask_evaluate(struct Mask *mask, const float ctime, const bool do_newframe);
void BKE_mask_layer_evaluate(struct MaskLayer *masklay, const float ctime, const bool do_newframe);
-void BKE_mask_update_scene(struct Main *bmain, struct Scene *scene);
void BKE_mask_parent_init(struct MaskParent *parent);
void BKE_mask_calc_handle_adjacent_interp(struct MaskSpline *spline, struct MaskSplinePoint *point, const float u);
void BKE_mask_calc_tangent_polyline(struct MaskSpline *spline, struct MaskSplinePoint *point, float t[2]);
@@ -237,8 +236,8 @@ float *BKE_mask_point_segment_feather_diff(struct MaskSpline *spline, struct Mas
void BKE_mask_layer_evaluate_animation(struct MaskLayer *masklay, const float ctime);
void BKE_mask_layer_evaluate_deform(struct MaskLayer *masklay, const float ctime);
-void BKE_mask_eval_animation(struct EvaluationContext *eval_ctx, struct Mask *mask);
-void BKE_mask_eval_update(struct EvaluationContext *eval_ctx, struct Mask *mask);
+void BKE_mask_eval_animation(struct Depsgraph *depsgraph, struct Mask *mask);
+void BKE_mask_eval_update(struct Depsgraph *depsgraph, struct Mask *mask);
/* mask_rasterize.c */
struct MaskRasterHandle;
diff --git a/source/blender/blenkernel/BKE_material.h b/source/blender/blenkernel/BKE_material.h
index f7850913014..43f36618c19 100644
--- a/source/blender/blenkernel/BKE_material.h
+++ b/source/blender/blenkernel/BKE_material.h
@@ -97,26 +97,19 @@ struct Material *BKE_material_pop_id(struct Main *bmain, struct ID *id, int inde
void BKE_material_clear_id(struct Main *bmain, struct ID *id, bool update_data);
/* rendering */
-void init_render_material(struct Material *, int, float *);
-void init_render_materials(struct Main *, int r_mode, float *amd, bool do_default_material);
-void end_render_material(struct Material *);
-void end_render_materials(struct Main *);
-
-bool material_in_material(struct Material *parmat, struct Material *mat);
-
void ramp_blend(int type, float r_col[3], const float fac, const float col[3]);
-/* driver update hacks */
-void material_drivers_update(struct Scene *scene, struct Material *mat, float ctime);
-
/* copy/paste */
void clear_matcopybuf(void);
void free_matcopybuf(void);
void copy_matcopybuf(struct Material *ma);
void paste_matcopybuf(struct Material *ma);
-/* handle backward compatibility for tface/materials called from doversion */
-int do_version_tface(struct Main *main);
+/* Evaluation. */
+
+struct Depsgraph;
+
+void BKE_material_eval(struct Depsgraph *depsgraph, struct Material *material);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_mball.h b/source/blender/blenkernel/BKE_mball.h
index f02704ba903..a486e8319c6 100644
--- a/source/blender/blenkernel/BKE_mball.h
+++ b/source/blender/blenkernel/BKE_mball.h
@@ -32,6 +32,7 @@
* \since March 2001
* \author nzc
*/
+struct Depsgraph;
struct Main;
struct MetaBall;
struct Object;
@@ -71,9 +72,16 @@ void BKE_mball_select_swap(struct MetaBall *mb);
/* **** Depsgraph evaluation **** */
-struct EvaluationContext;
+struct Depsgraph;
-void BKE_mball_eval_geometry(struct EvaluationContext *eval_ctx,
+void BKE_mball_eval_geometry(struct Depsgraph *depsgraph,
struct MetaBall *mball);
+/* Draw Cache */
+
+enum {
+ BKE_MBALL_BATCH_DIRTY_ALL = 0,
+};
+void BKE_mball_batch_cache_dirty(struct MetaBall *mb, int mode);
+void BKE_mball_batch_cache_free(struct MetaBall *mb);
#endif
diff --git a/source/blender/blenkernel/BKE_mball_tessellate.h b/source/blender/blenkernel/BKE_mball_tessellate.h
index 361f31b704c..df652df177d 100644
--- a/source/blender/blenkernel/BKE_mball_tessellate.h
+++ b/source/blender/blenkernel/BKE_mball_tessellate.h
@@ -23,12 +23,12 @@
/** \file BKE_mball_tessellate.h
* \ingroup bke
*/
-struct EvaluationContext;
+struct Depsgraph;
struct Object;
struct Scene;
void BKE_mball_polygonize(
- struct EvaluationContext *eval_ctx, struct Scene *scene,
+ struct Depsgraph *depsgraph, struct Scene *scene,
struct Object *ob, struct ListBase *dispbase);
void BKE_mball_cubeTable_free(void);
diff --git a/source/blender/blenkernel/BKE_mesh.h b/source/blender/blenkernel/BKE_mesh.h
index bf135254941..afb087ed822 100644
--- a/source/blender/blenkernel/BKE_mesh.h
+++ b/source/blender/blenkernel/BKE_mesh.h
@@ -33,7 +33,10 @@
struct ID;
struct BMeshCreateParams;
+struct BMeshFromMeshParams;
+struct BMeshToMeshParams;
struct BoundBox;
+struct Depsgraph;
struct EdgeHash;
struct ListBase;
struct LinkNode;
@@ -70,10 +73,16 @@ extern "C" {
/* *** mesh.c *** */
+struct BMesh *BKE_mesh_to_bmesh_ex(
+ struct Mesh *me,
+ const struct BMeshCreateParams *create_params,
+ const struct BMeshFromMeshParams *convert_params);
struct BMesh *BKE_mesh_to_bmesh(
struct Mesh *me, struct Object *ob,
const bool add_key_index, const struct BMeshCreateParams *params);
+struct Mesh *BKE_bmesh_to_mesh(struct BMesh *bm, const struct BMeshToMeshParams *params);
+
int poly_find_loop_from_vert(
const struct MPoly *poly,
const struct MLoop *loopstart, unsigned vert);
@@ -92,6 +101,17 @@ struct Mesh *BKE_mesh_copy(struct Main *bmain, const struct Mesh *me);
void BKE_mesh_update_customdata_pointers(struct Mesh *me, const bool do_ensure_tess_cd);
void BKE_mesh_ensure_skin_customdata(struct Mesh *me);
+struct Mesh * BKE_mesh_from_template(
+ const struct Mesh *me_src,
+ int numVerts, int numEdges, int numTessFaces,
+ int numLoops, int numPolys);
+
+bool BKE_mesh_ensure_edit_data(struct Mesh *me);
+bool BKE_mesh_clear_edit_data(struct Mesh *me);
+
+bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me);
+bool BKE_mesh_clear_facemap_customdata(struct Mesh *me);
+
void BKE_mesh_make_local(struct Main *bmain, struct Mesh *me, const bool lib_local);
void BKE_mesh_boundbox_calc(struct Mesh *me, float r_loc[3], float r_size[3]);
void BKE_mesh_texspace_calc(struct Mesh *me);
@@ -115,7 +135,7 @@ void BKE_mesh_from_nurbs_displist(
struct Object *ob, struct ListBase *dispbase, const bool use_orco_uv, const char *obdata_name);
void BKE_mesh_from_nurbs(struct Object *ob);
void BKE_mesh_to_curve_nurblist(struct DerivedMesh *dm, struct ListBase *nurblist, const int edge_users_test);
-void BKE_mesh_to_curve(struct Scene *scene, struct Object *ob);
+void BKE_mesh_to_curve(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
void BKE_mesh_material_index_remove(struct Mesh *me, short index);
void BKE_mesh_material_index_clear(struct Mesh *me);
void BKE_mesh_material_remap(struct Mesh *me, const unsigned int *remap, unsigned int remap_len);
@@ -125,18 +145,20 @@ const char *BKE_mesh_cmp(struct Mesh *me1, struct Mesh *me2, float thresh);
struct BoundBox *BKE_mesh_boundbox_get(struct Object *ob);
void BKE_mesh_texspace_get(struct Mesh *me, float r_loc[3], float r_rot[3], float r_size[3]);
+void BKE_mesh_texspace_get_reference(struct Mesh *me, short **r_texflag, float **r_loc, float **r_rot, float **r_size);
void BKE_mesh_texspace_copy_from_object(struct Mesh *me, struct Object *ob);
-bool BKE_mesh_uv_cdlayer_rename_index(struct Mesh *me, const int poly_index, const int loop_index, const int face_index,
- const char *new_name, const bool do_tessface);
+bool BKE_mesh_uv_cdlayer_rename_index(
+ struct Mesh *me, const int loop_index, const int face_index,
+ const char *new_name, const bool do_tessface);
bool BKE_mesh_uv_cdlayer_rename(struct Mesh *me, const char *old_name, const char *new_name, bool do_tessface);
float (*BKE_mesh_vertexCos_get(const struct Mesh *me, int *r_numVerts))[3];
void BKE_mesh_split_faces(struct Mesh *mesh, bool free_loop_normals);
-struct Mesh *BKE_mesh_new_from_object(struct Main *bmain, struct Scene *sce, struct Object *ob,
- int apply_modifiers, int settings, int calc_tessface, int calc_undeformed);
+struct Mesh *BKE_mesh_new_from_object(struct Depsgraph *depsgraph, struct Main *bmain, struct Scene *sce, struct Object *ob,
+ int apply_modifiers, int calc_tessface, int calc_undeformed);
/* vertex level transformations & checks (no derived mesh) */
@@ -330,7 +352,7 @@ void BKE_mesh_loops_to_mface_corners(
const int numTex, const int numCol,
const bool hasPCol, const bool hasOrigSpace, const bool hasLNor);
void BKE_mesh_loops_to_tessdata(
- struct CustomData *fdata, struct CustomData *ldata, struct CustomData *pdata, struct MFace *mface,
+ struct CustomData *fdata, struct CustomData *ldata, struct MFace *mface,
int *polyindices, unsigned int (*loopindices)[4], const int num_faces);
void BKE_mesh_tangent_loops_to_tessdata(
struct CustomData *fdata, struct CustomData *ldata, struct MFace *mface,
@@ -366,6 +388,19 @@ void BKE_mesh_polygon_flip_ex(
void BKE_mesh_polygon_flip(struct MPoly *mpoly, struct MLoop *mloop, struct CustomData *ldata);
void BKE_mesh_polygons_flip(struct MPoly *mpoly, struct MLoop *mloop, struct CustomData *ldata, int totpoly);
+/* merge verts */
+/* Enum for merge_mode of CDDM_merge_verts.
+ * Refer to mesh.c for details. */
+enum {
+ MESH_MERGE_VERTS_DUMP_IF_MAPPED,
+ MESH_MERGE_VERTS_DUMP_IF_EQUAL,
+};
+struct Mesh *BKE_mesh_merge_verts(
+ struct Mesh *mesh,
+ const int *vtargetmap, const int tot_vtargetmap,
+ const int merge_mode);
+
+
/* flush flags */
void BKE_mesh_flush_hidden_from_verts_ex(
const struct MVert *mvert,
@@ -408,7 +443,6 @@ void BKE_mesh_calc_relative_deform(
/* *** mesh_validate.c *** */
int BKE_mesh_validate(struct Mesh *me, const int do_verbose, const int cddata_check_mask);
-void BKE_mesh_cd_validate(struct Mesh *me);
int BKE_mesh_validate_material_indices(struct Mesh *me);
bool BKE_mesh_validate_arrays(
@@ -438,11 +472,20 @@ void BKE_mesh_calc_edges(struct Mesh *mesh, bool update, const bool select);
/* **** Depsgraph evaluation **** */
-struct EvaluationContext;
-
-void BKE_mesh_eval_geometry(struct EvaluationContext *eval_ctx,
+void BKE_mesh_eval_geometry(struct Depsgraph *depsgraph,
struct Mesh *mesh);
+/* Draw Cache */
+enum {
+ BKE_MESH_BATCH_DIRTY_ALL = 0,
+ BKE_MESH_BATCH_DIRTY_MAYBE_ALL,
+ BKE_MESH_BATCH_DIRTY_SELECT,
+ BKE_MESH_BATCH_DIRTY_SHADING,
+ BKE_MESH_BATCH_DIRTY_SCULPT_COORDS,
+};
+void BKE_mesh_batch_cache_dirty(struct Mesh *me, int mode);
+void BKE_mesh_batch_cache_free(struct Mesh *me);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_mesh_tangent.h b/source/blender/blenkernel/BKE_mesh_tangent.h
new file mode 100644
index 00000000000..cb3100c1c2f
--- /dev/null
+++ b/source/blender/blenkernel/BKE_mesh_tangent.h
@@ -0,0 +1,61 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+#ifndef __BKE_MESH_TANGENT_H__
+#define __BKE_MESH_TANGENT_H__
+
+void BKE_mesh_calc_loop_tangent_single_ex(
+ const struct MVert *mverts, const int numVerts, const struct MLoop *mloops,
+ float (*r_looptangent)[4], float (*loopnors)[3], const struct MLoopUV *loopuv,
+ const int numLoops, const struct MPoly *mpolys, const int numPolys,
+ struct ReportList *reports);
+void BKE_mesh_calc_loop_tangent_single(
+ struct Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], struct ReportList *reports);
+
+void BKE_mesh_calc_loop_tangent_ex(
+ const struct MVert *mvert,
+ const struct MPoly *mpoly, const uint mpoly_len,
+ const struct MLoop *mloop,
+ const struct MLoopTri *looptri, const uint looptri_len,
+
+ struct CustomData *loopdata,
+ bool calc_active_tangent,
+ const char (*tangent_names)[64], int tangent_names_len,
+ const float (*poly_normals)[3],
+ const float (*loop_normals)[3],
+ const float (*vert_orco)[3],
+ /* result */
+ struct CustomData *loopdata_out,
+ const uint loopdata_out_len,
+ short *tangent_mask_curr_p);
+
+/* Helpers */
+void BKE_mesh_add_loop_tangent_named_layer_for_uv(
+ struct CustomData *uv_data, struct CustomData *tan_data, int numLoopData,
+ const char *layer_name);
+
+#define DM_TANGENT_MASK_ORCO (1 << 9)
+void BKE_mesh_calc_loop_tangent_step_0(
+ const struct CustomData *loopData, bool calc_active_tangent,
+ const char (*tangent_names)[64], int tangent_names_count,
+ bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
+ char *ract_uv_name, char *rren_uv_name, short *rtangent_mask);
+
+#endif /* __BKE_MESH_TANGENT_H__ */
+
diff --git a/source/blender/blenkernel/BKE_modifier.h b/source/blender/blenkernel/BKE_modifier.h
index 18cde156f5e..02337110289 100644
--- a/source/blender/blenkernel/BKE_modifier.h
+++ b/source/blender/blenkernel/BKE_modifier.h
@@ -33,11 +33,12 @@
#include "BKE_customdata.h"
struct ID;
+struct Depsgraph;
struct DerivedMesh;
-struct DagForest;
-struct DagNode;
+struct Mesh;
struct Object;
struct Scene;
+struct ViewLayer;
struct ListBase;
struct bArmature;
struct Main;
@@ -126,19 +127,21 @@ typedef enum ModifierApplyFlag {
*/
} ModifierApplyFlag;
-
typedef struct ModifierUpdateDepsgraphContext {
struct Scene *scene;
struct Object *object;
-
- /* Old depsgraph node handle. */
- struct DagForest *forest;
- struct DagNode *obNode;
-
- /* new depsgraph node handle. */
struct DepsNodeHandle *node;
} ModifierUpdateDepsgraphContext;
+/* Contains the information for deformXXX and applyXXX functions below that
+ * doesn't change between consecutive modifiers. */
+typedef struct ModifierEvalContext {
+ struct Depsgraph *depsgraph;
+ struct Object *object;
+ ModifierApplyFlag flag;
+} ModifierEvalContext;
+
+
typedef struct ModifierTypeInfo {
/* The user visible name for this modifier */
char name[32];
@@ -162,35 +165,37 @@ typedef struct ModifierTypeInfo {
*/
void (*copyData)(struct ModifierData *md, struct ModifierData *target);
- /********************* Deform modifier functions *********************/
+
+ /********************* Deform modifier functions *********************/ /* DEPRECATED */
/* Only for deform types, should apply the deformation
* to the given vertex array. If the deformer requires information from
* the object it can obtain it from the derivedData argument if non-NULL,
* and otherwise the ob argument.
*/
- void (*deformVerts)(struct ModifierData *md, struct Object *ob,
- struct DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts,
- ModifierApplyFlag flag);
+ void (*deformVerts_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts);
/* Like deformMatricesEM but called from object mode (for supporting modifiers in sculpt mode) */
- void (*deformMatrices)(struct ModifierData *md, struct Object *ob,
- struct DerivedMesh *derivedData,
- float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+ void (*deformMatrices_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct DerivedMesh *derivedData,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
/* Like deformVerts but called during editmode (for supporting modifiers)
*/
- void (*deformVertsEM)(struct ModifierData *md, struct Object *ob,
- struct BMEditMesh *editData, struct DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts);
+ void (*deformVertsEM_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts);
/* Set deform matrix per vertex for crazyspace correction */
- void (*deformMatricesEM)(struct ModifierData *md, struct Object *ob,
- struct BMEditMesh *editData, struct DerivedMesh *derivedData,
+ void (*deformMatricesEM_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct DerivedMesh *derivedData,
float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
- /********************* Non-deform modifier functions *********************/
+ /********************* Non-deform modifier functions *********************/ /* DEPRECATED */
/* For non-deform types: apply the modifier and return a derived
* data object (type is dependent on object type).
@@ -199,21 +204,11 @@ typedef struct ModifierTypeInfo {
* should read the object data from the derived object instead of the
* actual object data.
*
- * The useRenderParams argument indicates if the modifier is being
- * applied in the service of the renderer which may alter quality
- * settings.
- *
- * The isFinalCalc parameter indicates if the modifier is being
- * calculated for a final result or for something temporary
- * (like orcos). This is a hack at the moment, it is meant so subsurf
- * can know if it is safe to reuse its internal cache.
- *
* The modifier may reuse the derivedData argument (i.e. return it in
* modified form), but must not release it.
*/
- struct DerivedMesh *(*applyModifier)(struct ModifierData *md, struct Object *ob,
- struct DerivedMesh *derivedData,
- ModifierApplyFlag flag);
+ struct DerivedMesh *(*applyModifier_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct DerivedMesh *derivedData);
/* Like applyModifier but called during editmode (for supporting
* modifiers).
@@ -222,10 +217,60 @@ typedef struct ModifierTypeInfo {
* are expected from editmode objects. The same qualifications regarding
* derivedData apply as for applyModifier.
*/
- struct DerivedMesh *(*applyModifierEM)(struct ModifierData *md, struct Object *ob,
- struct BMEditMesh *editData,
- struct DerivedMesh *derivedData,
- ModifierApplyFlag flag);
+ struct DerivedMesh *(*applyModifierEM_DM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct DerivedMesh *derivedData);
+
+
+ /********************* Deform modifier functions *********************/
+
+ /* Only for deform types, should apply the deformation
+ * to the given vertex array. If the deformer requires information from
+ * the object it can obtain it from the mesh argument if non-NULL,
+ * and otherwise the ob argument.
+ */
+ void (*deformVerts)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct Mesh *mesh, float (*vertexCos)[3], int numVerts);
+
+ /* Like deformMatricesEM but called from object mode (for supporting modifiers in sculpt mode) */
+ void (*deformMatrices)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct Mesh *mesh, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+
+ /* Like deformVerts but called during editmode (for supporting modifiers)
+ */
+ void (*deformVertsEM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct Mesh *mesh, float (*vertexCos)[3], int numVerts);
+
+ /* Set deform matrix per vertex for crazyspace correction */
+ void (*deformMatricesEM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct Mesh *mesh, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+
+ /********************* Non-deform modifier functions *********************/
+
+ /* For non-deform types: apply the modifier and return a mesh object.
+ *
+ * The mesh argument should always be non-NULL; the modifier
+ * should read the object data from the mesh object instead of the
+ * actual object data.
+ *
+ * The modifier may reuse the mesh argument (i.e. return it in
+ * modified form), but must not release it.
+ */
+ struct Mesh *(*applyModifier)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct Mesh *mesh);
+
+ /* Like applyModifier but called during editmode (for supporting
+ * modifiers).
+ *
+ * The mesh object that is returned must support the operations that
+ * are expected from editmode objects. The same qualifications regarding
+ * mesh apply as for applyModifier.
+ */
+ struct Mesh *(*applyModifierEM)(struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct Mesh *mesh);
/********************* Optional functions *********************/
@@ -272,22 +317,13 @@ typedef struct ModifierTypeInfo {
*/
bool (*isDisabled)(struct ModifierData *md, int userRenderParams);
- /* Add the appropriate relations to the DEP graph depending on the
- * modifier data.
- *
- * This function is optional.
- */
- void (*updateDepgraph)(struct ModifierData *md,
- const ModifierUpdateDepsgraphContext *ctx);
-
/* Add the appropriate relations to the dependency graph.
*
* This function is optional.
*/
- /* TODO(sergey): Remove once we finally switched to the new depsgraph. */
void (*updateDepsgraph)(struct ModifierData *md,
const ModifierUpdateDepsgraphContext *ctx);
-
+
/* Should return true if the modifier needs to be recalculated on time
* changes.
*
@@ -433,29 +469,84 @@ void modifier_path_init(char *path, int path_maxlen, const char *name);
const char *modifier_path_relbase(struct Object *ob);
-/* wrappers for modifier callbacks */
+/* wrappers for modifier callbacks that ensure valid normals */
struct DerivedMesh *modwrap_applyModifier(
- ModifierData *md, struct Object *ob,
- struct DerivedMesh *dm,
- ModifierApplyFlag flag);
+ ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct DerivedMesh *dm);
struct DerivedMesh *modwrap_applyModifierEM(
- ModifierData *md, struct Object *ob,
- struct BMEditMesh *em,
- struct DerivedMesh *dm,
- ModifierApplyFlag flag);
+ ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *em, struct DerivedMesh *dm);
void modwrap_deformVerts(
- ModifierData *md, struct Object *ob,
+ ModifierData *md, const struct ModifierEvalContext *ctx,
struct DerivedMesh *dm,
- float (*vertexCos)[3], int numVerts,
- ModifierApplyFlag flag);
+ float (*vertexCos)[3], int numVerts);
void modwrap_deformVertsEM(
- ModifierData *md, struct Object *ob,
+ ModifierData *md, const struct ModifierEvalContext *ctx,
struct BMEditMesh *em, struct DerivedMesh *dm,
float (*vertexCos)[3], int numVerts);
+/* wrappers for modifier callbacks that accept Mesh and select the proper implementation
+ * depending on if the modifier has been ported to Mesh or is still using DerivedMesh
+ */
+
+void modifier_deformVerts(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct Mesh *mesh, float (*vertexCos)[3], int numVerts);
+
+void modifier_deformMatrices(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct Mesh *mesh, float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+
+void modifier_deformVertsEM(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct Mesh *mesh,
+ float (*vertexCos)[3], int numVerts);
+
+void modifier_deformMatricesEM(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct Mesh *mesh,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+
+struct Mesh *modifier_applyModifier(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct Mesh *mesh);
+
+struct Mesh *modifier_applyModifierEM(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct Mesh *mesh);
+
+/* depricated variants of above that accept DerivedMesh */
+
+void modifier_deformVerts_DM_deprecated(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct DerivedMesh *dm, float (*vertexCos)[3], int numVerts);
+
+void modifier_deformMatrices_DM_deprecated(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct DerivedMesh *dm,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+
+void modifier_deformVertsEM_DM_deprecated(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct DerivedMesh *dm,
+ float (*vertexCos)[3], int numVerts);
+
+void modifier_deformMatricesEM_DM_deprecated(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct DerivedMesh *dm,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts);
+
+struct DerivedMesh *modifier_applyModifier_DM_deprecated(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct DerivedMesh *dm);
+
+struct DerivedMesh *modifier_applyModifierEM_DM_deprecated(
+ struct ModifierData *md, const struct ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct DerivedMesh *dm);
+
#endif
diff --git a/source/blender/blenkernel/BKE_movieclip.h b/source/blender/blenkernel/BKE_movieclip.h
index 818f79ad8ac..5b5ebbf035c 100644
--- a/source/blender/blenkernel/BKE_movieclip.h
+++ b/source/blender/blenkernel/BKE_movieclip.h
@@ -32,7 +32,7 @@
* \author Sergey Sharybin
*/
-struct EvaluationContext;
+struct Depsgraph;
struct ImBuf;
struct Main;
struct MovieClip;
@@ -85,7 +85,7 @@ bool BKE_movieclip_has_cached_frame(struct MovieClip *clip, struct MovieClipUser
bool BKE_movieclip_put_frame_if_possible(struct MovieClip *clip, struct MovieClipUser *user, struct ImBuf *ibuf);
/* Evaluaiton. */
-void BKE_movieclip_eval_update(struct EvaluationContext *eval_ctx, struct MovieClip *clip);
+void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, struct MovieClip *clip);
/* cacheing flags */
#define MOVIECLIP_CACHE_SKIP (1 << 0)
diff --git a/source/blender/blenkernel/BKE_multires.h b/source/blender/blenkernel/BKE_multires.h
index 178751d1640..10bc367e909 100644
--- a/source/blender/blenkernel/BKE_multires.h
+++ b/source/blender/blenkernel/BKE_multires.h
@@ -33,6 +33,7 @@
*/
enum MultiresModifiedFlags;
+struct Depsgraph;
struct DerivedMesh;
struct MDisps;
struct Mesh;
@@ -80,18 +81,18 @@ struct DerivedMesh *multires_make_derived_from_derived(struct DerivedMesh *dm,
struct MultiresModifierData *find_multires_modifier_before(struct Scene *scene,
struct ModifierData *lastmd);
struct MultiresModifierData *get_multires_modifier(struct Scene *scene, struct Object *ob, bool use_first);
-struct DerivedMesh *get_multires_dm(struct Scene *scene, struct MultiresModifierData *mmd,
+struct DerivedMesh *get_multires_dm(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd,
struct Object *ob);
void multiresModifier_del_levels(struct MultiresModifierData *, struct Object *, int direction);
void multiresModifier_base_apply(struct MultiresModifierData *mmd, struct Object *ob);
void multiresModifier_subdivide(struct MultiresModifierData *mmd, struct Object *ob, int updateblock, int simple);
void multiresModifier_sync_levels_ex(
struct Object *ob_dst, struct MultiresModifierData *mmd_src, struct MultiresModifierData *mmd_dst);
-int multiresModifier_reshape(struct Scene *scene, struct MultiresModifierData *mmd,
+int multiresModifier_reshape(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd,
struct Object *dst, struct Object *src);
-int multiresModifier_reshapeFromDM(struct Scene *scene, struct MultiresModifierData *mmd,
+int multiresModifier_reshapeFromDM(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd,
struct Object *ob, struct DerivedMesh *srcdm);
-int multiresModifier_reshapeFromDeformMod(struct Scene *scene, struct MultiresModifierData *mmd,
+int multiresModifier_reshapeFromDeformMod(struct Depsgraph *depsgraph, struct Scene *scene, struct MultiresModifierData *mmd,
struct Object *ob, struct ModifierData *md);
void multires_stitch_grids(struct Object *);
@@ -109,8 +110,8 @@ void multires_free(struct Multires *mr);
void multires_load_old(struct Object *ob, struct Mesh *me);
void multires_load_old_250(struct Mesh *);
-void multiresModifier_scale_disp(struct Scene *scene, struct Object *ob);
-void multiresModifier_prepare_join(struct Scene *scene, struct Object *ob, struct Object *to_ob);
+void multiresModifier_scale_disp(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
+void multiresModifier_prepare_join(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *to_ob);
int multires_mdisp_corners(struct MDisps *s);
diff --git a/source/blender/blenkernel/BKE_navmesh_conversion.h b/source/blender/blenkernel/BKE_navmesh_conversion.h
deleted file mode 100644
index 3be363f4d7b..00000000000
--- a/source/blender/blenkernel/BKE_navmesh_conversion.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __BKE_NAVMESH_CONVERSION_H__
-#define __BKE_NAVMESH_CONVERSION_H__
-
-/** \file BKE_navmesh_conversion.h
- * \ingroup bke
- */
-
-struct DerivedMesh;
-
-/* navmesh_conversion.c */
-int buildNavMeshDataByDerivedMesh(struct DerivedMesh *dm, int *vertsPerPoly,
- int *nverts, float **verts,
- int *ndtris, unsigned short **dtris,
- int *npolys, unsigned short **dmeshes,
- unsigned short **polys, int **dtrisToPolysMap,
- int **dtrisToTrisMap, int **trisToFacesMap);
-
-int buildRawVertIndicesData(struct DerivedMesh *dm, int *nverts, float **verts,
- int *ntris, unsigned short **tris, int **trisToFacesMap,
- int **recastData);
-
-int buildNavMeshData(const int nverts, const float *verts,
- const int ntris, const unsigned short *tris,
- const int *recastData, const int *trisToFacesMap,
- int *ndtris, unsigned short **dtris,
- int *npolys, unsigned short **dmeshes, unsigned short **polys,
- int *vertsPerPoly, int **dtrisToPolysMap, int **dtrisToTrisMap);
-
-int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys,
- unsigned short *polys, const unsigned short *dmeshes,
- const float *verts, const unsigned short *dtris,
- const int *dtrisToPolysMap);
-
-int polyNumVerts(const unsigned short *p, const int vertsPerPoly);
-int polyIsConvex(const unsigned short *p, const int vertsPerPoly, const float *verts);
-int polyFindVertex(const unsigned short *p, const int vertsPerPoly, unsigned short vertexIdx);
-float distPointToSegmentSq(const float *point, const float *a, const float *b);
-
-
-#endif /* NAVMESH_CONVERSION_H */
diff --git a/source/blender/blenkernel/BKE_node.h b/source/blender/blenkernel/BKE_node.h
index efad8e48e3d..d85f4095eb9 100644
--- a/source/blender/blenkernel/BKE_node.h
+++ b/source/blender/blenkernel/BKE_node.h
@@ -74,6 +74,7 @@ struct PointerRNA;
struct RenderData;
struct Scene;
struct Tex;
+struct ViewRender;
struct SpaceNode;
struct ARegion;
struct ColorManagedViewSettings;
@@ -251,8 +252,9 @@ typedef struct bNodeType {
#define NODE_CLASS_LAYOUT 100
/* nodetype->compatibility */
-#define NODE_OLD_SHADING 1
-#define NODE_NEW_SHADING 2
+#define NODE_OLD_SHADING (1 << 0)
+#define NODE_NEW_SHADING (1 << 1)
+#define NODE_NEWER_SHADING (1 << 2)
/* node resize directions */
#define NODE_RESIZE_TOP 1
@@ -496,7 +498,6 @@ struct bNode *nodeGetActiveTexture(struct bNodeTree *ntree);
void nodeUpdate(struct bNodeTree *ntree, struct bNode *node);
bool nodeUpdateID(struct bNodeTree *ntree, struct ID *id);
void nodeUpdateInternalLinks(struct bNodeTree *ntree, struct bNode *node);
-void nodeSynchronizeID(struct bNode *node, bool copy_to_id);
int nodeSocketIsHidden(struct bNodeSocket *sock);
void ntreeTagUsedSockets(struct bNodeTree *ntree);
@@ -690,27 +691,32 @@ bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter,
}
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Node Tree
+ */
+
+void BKE_nodetree_remove_layer_n(struct bNodeTree *ntree, struct Scene *scene, const int layer_index);
+
/* -------------------------------------------------------------------- */
/** \name Shader Nodes
* \{ */
-struct ShadeInput;
-struct ShadeResult;
/* note: types are needed to restore callbacks, don't change values */
/* range 1 - 100 is reserved for common nodes */
/* using toolbox, we add node groups by assuming the values below don't exceed NODE_GROUP_MENU for now */
-#define SH_NODE_OUTPUT 1
+//#define SH_NODE_OUTPUT 1
-#define SH_NODE_MATERIAL 100
+//#define SH_NODE_MATERIAL 100
#define SH_NODE_RGB 101
#define SH_NODE_VALUE 102
#define SH_NODE_MIX_RGB 103
#define SH_NODE_VALTORGB 104
#define SH_NODE_RGBTOBW 105
-#define SH_NODE_TEXTURE 106
+//#define SH_NODE_TEXTURE 106
#define SH_NODE_NORMAL 107
-#define SH_NODE_GEOMETRY 108
+//#define SH_NODE_GEOMETRY 108
#define SH_NODE_MAPPING 109
#define SH_NODE_CURVE_VEC 110
#define SH_NODE_CURVE_RGB 111
@@ -718,7 +724,7 @@ struct ShadeResult;
#define SH_NODE_MATH 115
#define SH_NODE_VECT_MATH 116
#define SH_NODE_SQUEEZE 117
-#define SH_NODE_MATERIAL_EXT 118
+//#define SH_NODE_MATERIAL_EXT 118
#define SH_NODE_INVERT 119
#define SH_NODE_SEPRGB 120
#define SH_NODE_COMBRGB 121
@@ -789,6 +795,7 @@ struct ShadeResult;
#define SH_NODE_UVALONGSTROKE 191
#define SH_NODE_TEX_POINTDENSITY 192
#define SH_NODE_BSDF_PRINCIPLED 193
+#define SH_NODE_EEVEE_SPECULAR 195
#define SH_NODE_BEVEL 197
#define SH_NODE_DISPLACEMENT 198
#define SH_NODE_VECTOR_DISPLACEMENT 199
@@ -803,14 +810,10 @@ struct ShadeResult;
struct bNodeTreeExec *ntreeShaderBeginExecTree(struct bNodeTree *ntree);
void ntreeShaderEndExecTree(struct bNodeTreeExec *exec);
-bool ntreeShaderExecTree(struct bNodeTree *ntree, struct ShadeInput *shi, struct ShadeResult *shr);
-void ntreeShaderGetTexcoMode(struct bNodeTree *ntree, int osa, short *texco, int *mode);
-
-/* switch material render loop */
-extern void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *);
-void set_node_shader_lamp_loop(void (*lamp_loop_func)(struct ShadeInput *, struct ShadeResult *));
+bool ntreeShaderExecTree(struct bNodeTree *ntree, int thread);
void ntreeGPUMaterialNodes(struct bNodeTree *ntree, struct GPUMaterial *mat, short compatibility);
+void ntreeGPUMaterialDomain(struct bNodeTree *ntree, bool *has_surface_output, bool *has_volume_output);
/** \} */
@@ -981,7 +984,7 @@ void ntreeCompositTagRender(struct Scene *sce);
int ntreeCompositTagAnimated(struct bNodeTree *ntree);
void ntreeCompositTagGenerators(struct bNodeTree *ntree);
void ntreeCompositUpdateRLayers(struct bNodeTree *ntree);
-void ntreeCompositRegisterPass(struct bNodeTree *ntree, struct Scene *scene, struct SceneRenderLayer *srl, const char *name, int type);
+void ntreeCompositRegisterPass(struct bNodeTree *ntree, struct Scene *scene, struct ViewLayer *view_layer, const char *name, int type);
void ntreeCompositClearTags(struct bNodeTree *ntree);
struct bNodeSocket *ntreeCompositOutputFileAddSocket(struct bNodeTree *ntree, struct bNode *node,
@@ -1040,10 +1043,22 @@ struct bNodeTreeExec *ntreeTexBeginExecTree(struct bNodeTree *ntree);
void ntreeTexEndExecTree(struct bNodeTreeExec *exec);
int ntreeTexExecTree(struct bNodeTree *ntree, struct TexResult *target,
float coord[3], float dxt[3], float dyt[3], int osatex, const short thread,
- struct Tex *tex, short which_output, int cfra, int preview, struct ShadeInput *shi, struct MTex *mtex);
+ struct Tex *tex, short which_output, int cfra, int preview, struct MTex *mtex);
/** \} */
void init_nodesystem(void);
void free_nodesystem(void);
+/* -------------------------------------------------------------------- */
+/* evaluation support, */
+
+struct Depsgraph;
+
+void BKE_nodetree_copy_default_values(struct bNodeTree *ntree_dst,
+ const struct bNodeTree *ntree_src);
+
+void BKE_nodetree_shading_params_eval(struct Depsgraph *depsgraph,
+ struct bNodeTree *ntree_dst,
+ const struct bNodeTree *ntree_src);
+
#endif /* __BKE_NODE_H__ */
diff --git a/source/blender/blenkernel/BKE_object.h b/source/blender/blenkernel/BKE_object.h
index 7cc43f33e3a..1d28d7f52c7 100644
--- a/source/blender/blenkernel/BKE_object.h
+++ b/source/blender/blenkernel/BKE_object.h
@@ -36,33 +36,32 @@ extern "C" {
#include "BLI_compiler_attrs.h"
struct Base;
-struct EvaluationContext;
+struct Depsgraph;
struct Scene;
+struct ViewLayer;
struct Object;
struct BoundBox;
struct View3D;
struct SoftBody;
-struct BulletSoftBody;
struct MovieClip;
struct Main;
struct RigidBodyWorld;
struct HookModifierData;
struct ModifierData;
+#include "DNA_object_enums.h"
+
void BKE_object_workob_clear(struct Object *workob);
-void BKE_object_workob_calc_parent(struct Scene *scene, struct Object *ob, struct Object *workob);
+void BKE_object_workob_calc_parent(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct Object *workob);
void BKE_object_transform_copy(struct Object *ob_tar, const struct Object *ob_src);
struct SoftBody *copy_softbody(const struct SoftBody *sb, const int flag);
-struct BulletSoftBody *copy_bulletsoftbody(const struct BulletSoftBody *sb, const int flag);
struct ParticleSystem *BKE_object_copy_particlesystem(struct ParticleSystem *psys, const int flag);
void BKE_object_copy_particlesystems(struct Object *ob_dst, const struct Object *ob_src, const int flag);
void BKE_object_copy_softbody(struct Object *ob_dst, const struct Object *ob_src);
void BKE_object_free_particlesystems(struct Object *ob);
void BKE_object_free_softbody(struct Object *ob);
-void BKE_object_free_bulletsoftbody(struct Object *ob);
void BKE_object_free_curve_cache(struct Object *ob);
-void BKE_object_update_base_layer(struct Scene *scene, struct Object *ob);
void BKE_object_free(struct Object *ob);
void BKE_object_free_derived_caches(struct Object *ob);
@@ -81,7 +80,17 @@ void BKE_object_copy_proxy_drivers(struct Object *ob, struct Object *target);
bool BKE_object_exists_check(const struct Object *obtest);
bool BKE_object_is_in_editmode(const struct Object *ob);
bool BKE_object_is_in_editmode_vgroup(const struct Object *ob);
+bool BKE_object_is_in_editmode_and_selected(const struct Object *ob);
bool BKE_object_is_in_wpaint_select_vert(const struct Object *ob);
+bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode);
+
+typedef enum eObjectVisibilityCheck {
+ OB_VISIBILITY_CHECK_FOR_VIEWPORT,
+ OB_VISIBILITY_CHECK_FOR_RENDER,
+ OB_VISIBILITY_CHECK_UNKNOWN_RENDER_MODE,
+} eObjectVisibilityCheck;
+
+bool BKE_object_is_visible(struct Object *ob, const eObjectVisibilityCheck mode);
void BKE_object_init(struct Object *ob);
struct Object *BKE_object_add_only_object(
@@ -89,22 +98,18 @@ struct Object *BKE_object_add_only_object(
int type, const char *name)
ATTR_NONNULL(1) ATTR_RETURNS_NONNULL;
struct Object *BKE_object_add(
- struct Main *bmain, struct Scene *scene,
+ struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer,
int type, const char *name)
- ATTR_NONNULL(1, 2) ATTR_RETURNS_NONNULL;
+ ATTR_NONNULL(1, 2, 3) ATTR_RETURNS_NONNULL;
+struct Object *BKE_object_add_from(
+ struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer,
+ int type, const char *name, struct Object *ob_src)
+ ATTR_NONNULL(1, 2, 3, 6) ATTR_RETURNS_NONNULL;
void *BKE_object_obdata_add_from_type(
struct Main *bmain,
int type, const char *name)
ATTR_NONNULL(1);
-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);
-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);
-
void BKE_object_copy_data(struct Main *bmain, struct Object *ob_dst, const struct Object *ob_src, const int flag);
struct Object *BKE_object_copy(struct Main *bmain, const struct Object *ob);
void BKE_object_make_local(struct Main *bmain, struct Object *ob, const bool lib_local);
@@ -124,14 +129,28 @@ void BKE_object_matrix_local_get(struct Object *ob, float mat[4][4]);
bool BKE_object_pose_context_check(const struct Object *ob);
struct Object *BKE_object_pose_armature_get(struct Object *ob);
+struct Object *BKE_object_pose_armature_get_visible(struct Object *ob, struct ViewLayer *view_layer);
+
+struct Object **BKE_object_pose_array_get_ex(struct ViewLayer *view_layer, unsigned int *r_objects_len, bool unique);
+struct Object **BKE_object_pose_array_get_unique(struct ViewLayer *view_layer, unsigned int *r_objects_len);
+struct Object **BKE_object_pose_array_get(struct ViewLayer *view_layer, unsigned int *r_objects_len);
+
+struct Base **BKE_object_pose_base_array_get_ex(struct ViewLayer *view_layer, unsigned int *r_bases_len, bool unique);
+struct Base **BKE_object_pose_base_array_get_unique(struct ViewLayer *view_layer, unsigned int *r_bases_len);
+struct Base **BKE_object_pose_base_array_get(struct ViewLayer *view_layer, unsigned int *r_bases_len);
-void BKE_object_get_parent_matrix(struct Scene *scene, struct Object *ob, struct Object *par, float parentmat[4][4]);
-void BKE_object_where_is_calc(struct Scene *scene, struct Object *ob);
+void BKE_object_get_parent_matrix(
+ struct Scene *scene, struct Object *ob,
+ struct Object *par, float parentmat[4][4]);
+void BKE_object_where_is_calc(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
void BKE_object_where_is_calc_ex(
- struct Scene *scene, struct RigidBodyWorld *rbw, struct Object *ob, float r_originmat[3][3]);
-void BKE_object_where_is_calc_time(struct Scene *scene, struct Object *ob, float ctime);
+ struct Depsgraph *depsgraph, struct Scene *scene, struct RigidBodyWorld *rbw,
+ struct Object *ob, float r_originmat[3][3]);
+void BKE_object_where_is_calc_time(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime);
void BKE_object_where_is_calc_time_ex(
- struct Scene *scene, struct Object *ob, float ctime,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime,
struct RigidBodyWorld *rbw, float r_originmat[3][3]);
void BKE_object_where_is_calc_mat4(struct Scene *scene, struct Object *ob, float obmat[4][4]);
@@ -149,16 +168,17 @@ void BKE_object_empty_draw_type_set(struct Object *ob, const int value);
void BKE_object_boundbox_flag(struct Object *ob, int flag, const bool set);
void BKE_object_minmax(struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
bool BKE_object_minmax_dupli(
- struct Scene *scene, struct Object *ob, float r_min[3], float r_max[3], const bool use_hidden);
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
+ float r_min[3], float r_max[3], const bool use_hidden);
/* sometimes min-max isn't enough, we need to loop over each point */
void BKE_object_foreach_display_point(
struct Object *ob, float obmat[4][4],
void (*func_cb)(const float[3], void *), void *user_data);
void BKE_scene_foreach_display_point(
+ struct Depsgraph *depsgraph,
struct Scene *scene,
- struct View3D *v3d,
- const short flag,
+ struct ViewLayer *view_layer,
void (*func_cb)(const float[3], void *), void *user_data);
bool BKE_object_parent_loop_check(const struct Object *parent, const struct Object *ob);
@@ -186,47 +206,61 @@ void BKE_object_tfm_protected_restore(
/* Dependency graph evaluation callbacks. */
void BKE_object_eval_local_transform(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Object *ob);
void BKE_object_eval_parent(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *ob);
void BKE_object_eval_constraints(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *ob);
-void BKE_object_eval_done(struct EvaluationContext *eval_ctx, struct Object *ob);
+void BKE_object_eval_done(struct Depsgraph *depsgraph, struct Object *ob);
bool BKE_object_eval_proxy_copy(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Object *object);
void BKE_object_eval_uber_transform(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Object *ob);
void BKE_object_eval_uber_data(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *ob);
void BKE_object_eval_cloth(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *object);
-
void BKE_object_eval_transform_all(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *object);
+void BKE_object_eval_update_shading(
+ struct Depsgraph *depsgraph,
+ struct Object *object);
+void BKE_object_data_select_update(
+ struct Depsgraph *depsgraph,
+ struct ID *object_data);
+
+void BKE_object_eval_flush_base_flags(
+ struct Depsgraph *depsgraph,
+ struct Scene *scene, const int view_layer_index,
+ struct Object *object, int base_index,
+ const bool is_from_set);
+
void BKE_object_handle_data_update(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *ob);
-void BKE_object_handle_update(struct EvaluationContext *eval_ctx, struct Scene *scene, struct Object *ob);
+void BKE_object_handle_update(
+ struct Depsgraph *depsgraph,
+ struct Scene *scene, struct Object *ob);
void BKE_object_handle_update_ex(
- struct EvaluationContext *eval_ctx,
+ struct Depsgraph *depsgraph,
struct Scene *scene, struct Object *ob,
struct RigidBodyWorld *rbw,
const bool do_proxy_update);
@@ -273,18 +307,17 @@ typedef enum eObjectSet {
} eObjectSet;
struct LinkNode *BKE_object_relational_superset(
- struct Scene *scene, eObjectSet objectSet, eObRelationTypes includeFilter);
+ struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter);
struct LinkNode *BKE_object_groups(struct Object *ob);
-void BKE_object_groups_clear(struct Scene *scene, struct Base *base, struct Object *object);
+void BKE_object_groups_clear(struct Object *object);
struct KDTree *BKE_object_as_kdtree(struct Object *ob, int *r_tot);
bool BKE_object_modifier_use_time(struct Object *ob, struct ModifierData *md);
bool BKE_object_modifier_update_subframe(
- struct Scene *scene, struct Object *ob, bool update_mesh,
- int parent_recursion, float frame,
- int type);
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
+ bool update_mesh, int parent_recursion, float frame, int type);
#ifdef __cplusplus
}
diff --git a/source/blender/blenkernel/BKE_object_facemap.h b/source/blender/blenkernel/BKE_object_facemap.h
new file mode 100644
index 00000000000..2607e5aa2dd
--- /dev/null
+++ b/source/blender/blenkernel/BKE_object_facemap.h
@@ -0,0 +1,53 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Antony Riakiotakis
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BKE_OBJECT_FACEMAP_H__
+#define __BKE_OBJECT_FACEMAP_H__
+
+/** \file BKE_object_facemap.h
+ * \ingroup bke
+ * \brief Functions for dealing with object face-maps.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct bFaceMap;
+struct ListBase;
+struct Object;
+
+struct bFaceMap *BKE_object_facemap_add(struct Object *ob);
+struct bFaceMap *BKE_object_facemap_add_name(struct Object *ob, const char *name);
+void BKE_object_facemap_remove(struct Object *ob, struct bFaceMap *fmap);
+void BKE_object_facemap_clear(struct Object *ob);
+
+int BKE_object_facemap_name_index(struct Object *ob, const char *name);
+void BKE_object_facemap_unique_name(struct Object *ob, struct bFaceMap *fmap);
+struct bFaceMap *BKE_object_facemap_find_name(struct Object *ob, const char *name);
+void BKE_object_facemap_copy_list(struct ListBase *outbase, const struct ListBase *inbase);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BKE_OBJECT_FACEMAP_H__ */
diff --git a/source/blender/blenkernel/BKE_outliner_treehash.h b/source/blender/blenkernel/BKE_outliner_treehash.h
index 454edb40c4e..b82bc692402 100644
--- a/source/blender/blenkernel/BKE_outliner_treehash.h
+++ b/source/blender/blenkernel/BKE_outliner_treehash.h
@@ -36,8 +36,9 @@ void *BKE_outliner_treehash_create_from_treestore(struct BLI_mempool *treestore)
/* full rebuild for already allocated hashtable */
void *BKE_outliner_treehash_rebuild_from_treestore(void *treehash, struct BLI_mempool *treestore);
-/* full rebuild for already allocated hashtable */
+/* Add/remove hashtable elements */
void BKE_outliner_treehash_add_element(void *treehash, struct TreeStoreElem *elem);
+void BKE_outliner_treehash_remove_element(void *treehash, struct TreeStoreElem *elem);
/* find first unused element with specific type, nr and id */
struct TreeStoreElem *BKE_outliner_treehash_lookup_unused(void *treehash, short type, short nr, struct ID *id);
diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h
index 285b9b3f99f..717f4c4f6e8 100644
--- a/source/blender/blenkernel/BKE_paint.h
+++ b/source/blender/blenkernel/BKE_paint.h
@@ -52,11 +52,13 @@ struct PaletteColor;
struct PBVH;
struct ReportList;
struct Scene;
+struct ViewLayer;
struct Sculpt;
struct StrokeCache;
struct Tex;
struct ImagePool;
struct UnifiedPaintSettings;
+struct Depsgraph;
enum eOverlayFlags;
@@ -91,8 +93,8 @@ typedef enum eOverlayControlFlags {
PAINT_OVERLAY_OVERRIDE_PRIMARY | \
PAINT_OVERLAY_OVERRIDE_CURSOR)
-void BKE_paint_invalidate_overlay_tex(struct Scene *scene, const struct Tex *tex);
-void BKE_paint_invalidate_cursor_overlay(struct Scene *scene, struct CurveMapping *curve);
+void BKE_paint_invalidate_overlay_tex(struct Scene *scene, struct ViewLayer *view_layer, const struct Tex *tex);
+void BKE_paint_invalidate_cursor_overlay(struct Scene *scene, struct ViewLayer *view_layer, struct CurveMapping *curve);
void BKE_paint_invalidate_overlay_all(void);
eOverlayControlFlags BKE_paint_get_overlay_flags(void);
void BKE_paint_reset_overlay_invalid(eOverlayControlFlags flag);
@@ -126,7 +128,7 @@ void BKE_paint_cavity_curve_preset(struct Paint *p, int preset);
eObjectMode BKE_paint_object_mode_from_paint_mode(ePaintMode mode);
struct Paint *BKE_paint_get_active_from_paintmode(struct Scene *sce, ePaintMode mode);
-struct Paint *BKE_paint_get_active(struct Scene *sce);
+struct Paint *BKE_paint_get_active(struct Scene *sce, struct ViewLayer *view_layer);
struct Paint *BKE_paint_get_active_from_context(const struct bContext *C);
ePaintMode BKE_paintmode_get_active_from_context(const struct bContext *C);
struct Brush *BKE_paint_brush(struct Paint *paint);
@@ -248,8 +250,9 @@ void BKE_sculptsession_free_deformMats(struct SculptSession *ss);
void BKE_sculptsession_free_vwpaint_data(struct SculptSession *ss);
void BKE_sculptsession_bm_to_me(struct Object *ob, bool reorder);
void BKE_sculptsession_bm_to_me_for_render(struct Object *object);
-void BKE_sculpt_update_mesh_elements(struct Scene *scene, struct Sculpt *sd, struct Object *ob,
- bool need_pmap, bool need_mask);
+void BKE_sculpt_update_mesh_elements(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Sculpt *sd, struct Object *ob,
+ bool need_pmap, bool need_mask);
struct MultiresModifierData *BKE_sculpt_multires_active(struct Scene *scene, struct Object *ob);
int BKE_sculpt_mask_layers_ensure(struct Object *ob,
struct MultiresModifierData *mmd);
diff --git a/source/blender/blenkernel/BKE_particle.h b/source/blender/blenkernel/BKE_particle.h
index 0cda7dceb33..0c8d00e16a3 100644
--- a/source/blender/blenkernel/BKE_particle.h
+++ b/source/blender/blenkernel/BKE_particle.h
@@ -49,6 +49,7 @@ struct ParticleSettings;
struct Main;
struct Object;
struct Scene;
+struct Depsgraph;
struct DerivedMesh;
struct ModifierData;
struct MTFace;
@@ -62,6 +63,8 @@ struct RNG;
struct BVHTreeRay;
struct BVHTreeRayHit;
struct EdgeHash;
+struct Depsgraph;
+struct ViewLayer;
#define PARTICLE_COLLISION_MAX_COLLISIONS 10
@@ -77,6 +80,7 @@ struct EdgeHash;
/* common stuff that many particle functions need */
typedef struct ParticleSimulationData {
+ struct Depsgraph *depsgraph;
struct Scene *scene;
struct Object *ob;
struct ParticleSystem *psys;
@@ -144,7 +148,7 @@ typedef struct ParticleThreadContext {
float *jit, *jitoff, *weight;
float maxweight;
- int *index, *skip, jitlevel;
+ int *index, jitlevel;
int cfrom, distr;
@@ -286,8 +290,8 @@ BLI_INLINE void psys_frand_vec(ParticleSystem *psys, unsigned int seed, float ve
int count_particles(struct ParticleSystem *psys);
int count_particles_mod(struct ParticleSystem *psys, int totgr, int cur);
-int psys_get_child_number(struct Scene *scene, struct ParticleSystem *psys);
-int psys_get_tot_child(struct Scene *scene, struct ParticleSystem *psys);
+int psys_get_child_number(struct Scene *scene, struct ParticleSystem *psys, const bool use_render_params);
+int psys_get_tot_child(struct Scene *scene, struct ParticleSystem *psys, const bool use_render_params);
struct ParticleSystem *psys_get_current(struct Object *ob);
/* for rna */
@@ -298,7 +302,7 @@ void psys_set_current_num(Object *ob, int index);
struct LatticeDeformData *psys_create_lattice_deform_data(struct ParticleSimulationData *sim);
-bool psys_in_edit_mode(struct Scene *scene, struct ParticleSystem *psys);
+bool psys_in_edit_mode(struct Depsgraph *depsgraph, struct ParticleSystem *psys);
bool psys_check_enabled(struct Object *ob, struct ParticleSystem *psys, const bool use_render_params);
bool psys_check_edited(struct ParticleSystem *psys);
@@ -310,8 +314,6 @@ void BKE_particlesettings_free(struct ParticleSettings *part);
void psys_free_path_cache(struct ParticleSystem *psys, struct PTCacheEdit *edit);
void psys_free(struct Object *ob, struct ParticleSystem *psys);
-void psys_render_set(struct Object *ob, struct ParticleSystem *psys, float viewmat[4][4], float winmat[4][4], int winx, int winy, int timeoffset);
-void psys_render_restore(struct Object *ob, struct ParticleSystem *psys);
bool psys_render_simplify_params(struct ParticleSystem *psys, struct ChildParticle *cpa, float *params);
void psys_interpolate_uvs(const struct MTFace *tface, int quad, const float w[4], float uvco[2]);
@@ -322,7 +324,7 @@ void copy_particle_key(struct ParticleKey *to, struct ParticleKey *from, int tim
CustomDataMask psys_emitter_customdata_mask(struct ParticleSystem *psys);
void psys_particle_on_emitter(struct ParticleSystemModifierData *psmd, int distr, int index, int index_dmcache,
float fuv[4], float foffset, float vec[3], float nor[3],
- float utan[3], float vtan[3], float orco[3], float ornor[3]);
+ float utan[3], float vtan[3], float orco[3]);
struct ParticleSystemModifierData *psys_get_modifier(struct Object *ob, struct ParticleSystem *psys);
struct ModifierData *object_add_particle_system(struct Scene *scene, struct Object *ob, const char *name);
@@ -339,9 +341,9 @@ void psys_reset(struct ParticleSystem *psys, int mode);
void psys_find_parents(struct ParticleSimulationData *sim, const bool use_render_params);
void psys_cache_paths(struct ParticleSimulationData *sim, float cfra, const bool use_render_params);
-void psys_cache_edit_paths(struct Scene *scene, struct Object *ob, struct PTCacheEdit *edit, float cfra, const bool use_render_params);
+void psys_cache_edit_paths(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct PTCacheEdit *edit, float cfra, const bool use_render_params);
void psys_cache_child_paths(struct ParticleSimulationData *sim, float cfra, const bool editupdate, const bool use_render_params);
-int do_guides(struct ParticleSettings *part, struct ListBase *effectors, ParticleKey *state, int pa_num, float time);
+int do_guides(struct Depsgraph *depsgraph, struct ParticleSettings *part, struct ListBase *effectors, ParticleKey *state, int pa_num, float time);
void precalc_guides(struct ParticleSimulationData *sim, struct ListBase *effectors);
float psys_get_timestep(struct ParticleSimulationData *sim);
float psys_get_child_time(struct ParticleSystem *psys, struct ChildParticle *cpa, float cfra, float *birthtime, float *dietime);
@@ -354,7 +356,7 @@ void BKE_particlesettings_clump_curve_init(struct ParticleSettings *part);
void BKE_particlesettings_rough_curve_init(struct ParticleSettings *part);
void BKE_particlesettings_twist_curve_init(struct ParticleSettings *part);
void psys_apply_child_modifiers(struct ParticleThreadContext *ctx, struct ListBase *modifiers,
- struct ChildParticle *cpa, struct ParticleTexture *ptex, const float orco[3], const float ornor[3], float hairmat[4][4],
+ struct ChildParticle *cpa, struct ParticleTexture *ptex, const float orco[3], float hairmat[4][4],
struct ParticleCacheKey *keys, struct ParticleCacheKey *parent_keys, const float parent_orco[3]);
void psys_sph_init(struct ParticleSimulationData *sim, struct SPHData *sphdata);
@@ -374,7 +376,7 @@ void psys_tasks_create(struct ParticleThreadContext *ctx, int startpart, int end
void psys_tasks_free(struct ParticleTask *tasks, int numtasks);
void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3], float zvec[3], float center[3]);
-void psys_apply_hair_lattice(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
+void psys_apply_hair_lattice(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys);
/* particle_system.c */
struct ParticleSystem *psys_get_target_system(struct Object *ob, struct ParticleTarget *pt);
@@ -389,7 +391,7 @@ void psys_check_boid_data(struct ParticleSystem *psys);
void psys_get_birth_coords(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleKey *state, float dtime, float cfra);
-void particle_system_update(struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, const bool use_render_params);
+void particle_system_update(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct ParticleSystem *psys, const bool use_render_params);
/* Callback format for performing operations on ID-pointers for particle systems */
typedef void (*ParticleSystemIDFunc)(struct ParticleSystem *psys, struct ID **idpoin, void *userdata, int cb_flag);
@@ -420,7 +422,7 @@ float *psys_cache_vgroup(struct DerivedMesh *dm, struct ParticleSystem *psys, in
void psys_get_texture(struct ParticleSimulationData *sim, struct ParticleData *pa, struct ParticleTexture *ptex, int event, float cfra);
void psys_interpolate_face(struct MVert *mvert, struct MFace *mface, struct MTFace *tface,
float (*orcodata)[3], float w[4], float vec[3], float nor[3], float utan[3], float vtan[3],
- float orco[3], float ornor[3]);
+ float orco[3]);
float psys_particle_value_from_verts(struct DerivedMesh *dm, short from, struct ParticleData *pa, float *values);
void psys_get_from_key(struct ParticleKey *key, float loc[3], float vel[3], float rot[4], float *time);
@@ -428,7 +430,7 @@ void psys_get_from_key(struct ParticleKey *key, float loc[3], float vel[3], floa
void BKE_psys_collision_neartest_cb(void *userdata, int index, const struct BVHTreeRay *ray, struct BVHTreeRayHit *hit);
void psys_particle_on_dm(struct DerivedMesh *dm_final, int from, int index, int index_dmcache,
const float fw[4], float foffset, float vec[3], float nor[3], float utan[3], float vtan[3],
- float orco[3], float ornor[3]);
+ float orco[3]);
/* particle_system.c */
void distribute_particles(struct ParticleSimulationData *sim, int from);
@@ -438,34 +440,7 @@ int psys_particle_dm_face_lookup(struct DerivedMesh *dm_final, struct DerivedMes
void reset_particle(struct ParticleSimulationData *sim, struct ParticleData *pa, float dtime, float cfra);
-float psys_get_current_display_percentage(struct ParticleSystem *psys);
-
-typedef struct ParticleRenderElem {
- int curchild, totchild, reduce;
- float lambda, t, scalemin, scalemax;
-} ParticleRenderElem;
-
-typedef struct ParticleRenderData {
- ChildParticle *child;
- ParticleCacheKey **pathcache;
- ParticleCacheKey **childcache;
- ListBase pathcachebufs, childcachebufs;
- int totchild, totcached, totchildcache;
- struct DerivedMesh *dm;
- int totdmvert, totdmedge, totdmface;
-
- float mat[4][4];
- float viewmat[4][4], winmat[4][4];
- int winx, winy;
-
- int do_simplify;
- int timeoffset;
- ParticleRenderElem *elems;
-
- /* ORIGINDEX */
- const int *index_mf_to_mpoly;
- const int *index_mp_to_orig;
-} ParticleRenderData;
+float psys_get_current_display_percentage(struct ParticleSystem *psys, const bool use_render_params);
/* psys_reset */
#define PSYS_RESET_ALL 1
@@ -479,10 +454,17 @@ typedef struct ParticleRenderData {
/* **** Depsgraph evaluation **** */
-struct EvaluationContext;
+struct Depsgraph;
-void BKE_particle_system_eval_init(struct EvaluationContext *eval_ctx,
+void BKE_particle_system_eval_init(struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *ob);
#endif
+
+/* Draw Cache */
+enum {
+ BKE_PARTICLE_BATCH_DIRTY_ALL = 0,
+};
+void BKE_particle_batch_cache_dirty(struct ParticleSystem *psys, int mode);
+void BKE_particle_batch_cache_free(struct ParticleSystem *psys);
diff --git a/source/blender/blenkernel/BKE_pbvh.h b/source/blender/blenkernel/BKE_pbvh.h
index f619133ee4b..c18288de1bc 100644
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@ -30,6 +30,7 @@
#include "BLI_ghash.h"
#include "BLI_utildefines.h"
+struct Gwn_Batch;
struct CCGElem;
struct CCGKey;
struct CCGDerivedMesh;
@@ -128,10 +129,9 @@ bool BKE_pbvh_node_find_nearest_to_ray(
/* Drawing */
-void BKE_pbvh_node_draw(PBVHNode *node, void *data);
-void BKE_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*face_nors)[3],
- int (*setMaterial)(int matnr, void *attribs), bool wireframe, bool fast);
-void BKE_pbvh_draw_BB(PBVH *bvh);
+void BKE_pbvh_draw_cb(
+ PBVH *bvh, float (*planes)[4], float (*fnors)[3], bool fast,
+ void (*draw_fn)(void *user_data, struct Gwn_Batch *batch), void *user_data);
/* PBVH Access */
typedef enum {
@@ -221,7 +221,7 @@ struct GSet *BKE_pbvh_bmesh_node_faces(PBVHNode *node);
void BKE_pbvh_bmesh_node_save_orig(PBVHNode *node);
void BKE_pbvh_bmesh_after_stroke(PBVH *bvh);
-/* Update Normals/Bounding Box/Draw Buffers/Redraw and clear flags */
+/* Update Normals/Bounding Box/Redraw and clear flags */
void BKE_pbvh_update(PBVH *bvh, int flags, float (*face_nors)[3]);
void BKE_pbvh_redraw_BB(PBVH *bvh, float bb_min[3], float bb_max[3]);
@@ -369,6 +369,7 @@ bool BKE_pbvh_node_vert_update_check_any(PBVH *bvh, PBVHNode *node);
//void BKE_pbvh_node_BB_reset(PBVHNode *node);
//void BKE_pbvh_node_BB_expand(PBVHNode *node, float co[3]);
+bool pbvh_has_mask(PBVH *bvh);
void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color);
void pbvh_show_mask_set(PBVH *bvh, bool show_mask);
diff --git a/source/blender/blenkernel/BKE_pointcache.h b/source/blender/blenkernel/BKE_pointcache.h
index cc60df1b2d6..89f1aa5eadd 100644
--- a/source/blender/blenkernel/BKE_pointcache.h
+++ b/source/blender/blenkernel/BKE_pointcache.h
@@ -90,6 +90,7 @@ struct ParticleKey;
struct ParticleSystem;
struct PointCache;
struct Scene;
+struct ViewLayer;
struct SmokeModifierData;
struct SoftBody;
struct RigidBodyWorld;
@@ -186,6 +187,8 @@ typedef struct PTCacheID {
typedef struct PTCacheBaker {
struct Main *main;
struct Scene *scene;
+ struct ViewLayer *view_layer;
+ struct Depsgraph *depsgraph;
int bake;
int render;
int anim_init;
@@ -274,6 +277,7 @@ void BKE_ptcache_id_from_smoke(PTCacheID *pid, struct Object *ob, struct SmokeMo
void BKE_ptcache_id_from_dynamicpaint(PTCacheID *pid, struct Object *ob, struct DynamicPaintSurface *surface);
void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, struct Object *ob, struct RigidBodyWorld *rbw);
+PTCacheID BKE_ptcache_id_find(struct Object *ob, struct Scene *scene, struct PointCache *cache);
void BKE_ptcache_ids_from_object(struct ListBase *lb, struct Object *ob, struct Scene *scene, int duplis);
/***************** Global funcs ****************************/
@@ -317,7 +321,7 @@ struct PointCache *BKE_ptcache_copy_list(struct ListBase *ptcaches_new, const st
/********************** Baking *********************/
/* Bakes cache with cache_step sized jumps in time, not accurate but very fast. */
-void BKE_ptcache_quick_cache_all(struct Main *bmain, struct Scene *scene);
+void BKE_ptcache_quick_cache_all(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer);
/* Bake cache or simulate to current frame with settings defined in the baker. */
void BKE_ptcache_bake(struct PTCacheBaker *baker);
diff --git a/source/blender/blenkernel/BKE_property.h b/source/blender/blenkernel/BKE_property.h
deleted file mode 100644
index c787e8e8ed1..00000000000
--- a/source/blender/blenkernel/BKE_property.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#ifndef __BKE_PROPERTY_H__
-#define __BKE_PROPERTY_H__
-
-/** \file BKE_property.h
- * \ingroup bke
- */
-
-struct bProperty;
-struct ListBase;
-struct Object;
-
-void BKE_bproperty_free(struct bProperty *prop);
-void BKE_bproperty_free_list(struct ListBase *lb);
-struct bProperty *BKE_bproperty_copy(const struct bProperty *prop);
-void BKE_bproperty_copy_list(struct ListBase *lbn, const struct ListBase *lbo);
-void BKE_bproperty_init(struct bProperty *prop);
-struct bProperty *BKE_bproperty_new(int type);
-void BKE_bproperty_unique(struct bProperty *first, struct bProperty *prop, int force);
-struct bProperty *BKE_bproperty_object_get(struct Object *ob, const char *name);
-void BKE_bproperty_object_set(struct Object *ob, struct bProperty *propc);
-// int BKE_bproperty_cmp(struct bProperty *prop, const char *str);
-void BKE_bproperty_set(struct bProperty *prop, const char *str);
-void BKE_bproperty_add(struct bProperty *prop, const char *str);
-/* should really be called '_get_valstr()' or '_as_string()' */
-void BKE_bproperty_set_valstr(struct bProperty *prop, char str[MAX_PROPSTRING]);
-
-#endif
diff --git a/source/blender/blenkernel/BKE_rigidbody.h b/source/blender/blenkernel/BKE_rigidbody.h
index 3c7274ca3c5..016a531db95 100644
--- a/source/blender/blenkernel/BKE_rigidbody.h
+++ b/source/blender/blenkernel/BKE_rigidbody.h
@@ -37,6 +37,7 @@
struct RigidBodyWorld;
struct RigidBodyOb;
+struct Depsgraph;
struct Scene;
struct Object;
@@ -99,21 +100,19 @@ void BKE_rigidbody_aftertrans_update(struct Object *ob, float loc[3], float rot[
void BKE_rigidbody_sync_transforms(struct RigidBodyWorld *rbw, struct Object *ob, float ctime);
bool BKE_rigidbody_check_sim_running(struct RigidBodyWorld *rbw, float ctime);
void BKE_rigidbody_cache_reset(struct RigidBodyWorld *rbw);
-void BKE_rigidbody_rebuild_world(struct Scene *scene, float ctime);
-void BKE_rigidbody_do_simulation(struct Scene *scene, float ctime);
+void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, struct Scene *scene, float ctime);
+void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, struct Scene *scene, float ctime);
/* -------------------- */
/* Depsgraph evaluation */
-struct EvaluationContext;
-
-void BKE_rigidbody_rebuild_sim(struct EvaluationContext *eval_ctx,
+void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph,
struct Scene *scene);
-void BKE_rigidbody_eval_simulation(struct EvaluationContext *eval_ctx,
+void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph,
struct Scene *scene);
-void BKE_rigidbody_object_sync_transforms(struct EvaluationContext *eval_ctx,
+void BKE_rigidbody_object_sync_transforms(struct Depsgraph *depsgraph,
struct Scene *scene,
struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_sca.h b/source/blender/blenkernel/BKE_sca.h
deleted file mode 100644
index 35bcd91a9b1..00000000000
--- a/source/blender/blenkernel/BKE_sca.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#ifndef __BKE_SCA_H__
-#define __BKE_SCA_H__
-
-/** \file BKE_sca.h
- * \ingroup bke
- */
-
-struct Main;
-struct Object;
-struct bSensor;
-struct bController;
-struct bActuator;
-
-void link_logicbricks(void **poin, void ***ppoin, short *tot, short size);
-void unlink_logicbricks(void **poin, void ***ppoin, short *tot);
-
-void unlink_controller(struct bController *cont);
-void unlink_controllers(struct ListBase *lb);
-void free_controller(struct bController *cont);
-void free_controllers(struct ListBase *lb);
-
-void unlink_actuator(struct bActuator *act);
-void unlink_actuators(struct ListBase *lb);
-void free_actuator(struct bActuator *act);
-void free_actuators(struct ListBase *lb);
-
-void free_sensor(struct bSensor *sens);
-void free_sensors(struct ListBase *lb);
-struct bSensor *copy_sensor(struct bSensor *sens, const int flag);
-void copy_sensors(struct ListBase *lbn, const struct ListBase *lbo, const int flag);
-void init_sensor(struct bSensor *sens);
-struct bSensor *new_sensor(int type);
-struct bController *copy_controller(struct bController *cont, const int flag);
-void copy_controllers(struct ListBase *lbn, const struct ListBase *lbo, const int flag);
-void init_controller(struct bController *cont);
-struct bController *new_controller(int type);
-struct bActuator *copy_actuator(struct bActuator *act, const int flag);
-void copy_actuators(struct ListBase *lbn, const struct ListBase *lbo, const int flag);
-void init_actuator(struct bActuator *act);
-struct bActuator *new_actuator(int type);
-void clear_sca_new_poins_ob(struct Object *ob);
-void clear_sca_new_poins(void);
-void set_sca_new_poins_ob(struct Object *ob);
-void set_sca_new_poins(void);
-
-void BKE_sca_logic_links_remap(struct Main *bmain, struct Object *ob_old, struct Object *ob_new);
-void BKE_sca_logic_copy(struct Object *ob_new, const struct Object *ob, const int flag);
-
-void sca_move_sensor(struct bSensor *sens_to_move, struct Object *ob, int move_up);
-void sca_move_controller(struct bController *cont_to_move, struct Object *ob, int move_up);
-void sca_move_actuator(struct bActuator *act_to_move, struct Object *ob, int move_up);
-
-/* Callback format for performing operations on ID-pointers for sensors/controllers/actuators. */
-typedef void (*SCASensorIDFunc)(struct bSensor *sensor, struct ID **idpoin, void *userdata, int cb_flag);
-typedef void (*SCAControllerIDFunc)(struct bController *controller, struct ID **idpoin, void *userdata, int cb_flag);
-typedef void (*SCAActuatorIDFunc)(struct bActuator *actuator, struct ID **idpoin, void *userdata, int cb_flag);
-
-void BKE_sca_sensors_id_loop(struct ListBase *senslist, SCASensorIDFunc func, void *userdata);
-void BKE_sca_controllers_id_loop(struct ListBase *contlist, SCAControllerIDFunc func, void *userdata);
-void BKE_sca_actuators_id_loop(struct ListBase *atclist, SCAActuatorIDFunc func, void *userdata);
-
-
-const char *sca_state_name_get(Object *ob, short bit);
-
-#endif
-
diff --git a/source/blender/blenkernel/BKE_scene.h b/source/blender/blenkernel/BKE_scene.h
index 0e1472b7062..44aa1b04569 100644
--- a/source/blender/blenkernel/BKE_scene.h
+++ b/source/blender/blenkernel/BKE_scene.h
@@ -38,43 +38,55 @@ extern "C" {
#endif
struct AviCodecData;
-struct Base;
-struct EvaluationContext;
+struct Depsgraph;
struct Main;
struct Object;
struct RenderData;
-struct SceneRenderLayer;
struct Scene;
+struct SceneCollection;
+struct ViewLayer;
struct UnitSettings;
-struct Main;
-
-#define SCE_COPY_NEW 0
-#define SCE_COPY_EMPTY 1
-#define SCE_COPY_LINK_OB 2
-#define SCE_COPY_LINK_DATA 3
-#define SCE_COPY_FULL 4
+struct ViewRender;
+struct WorkSpace;
+struct TransformOrientation;
+
+typedef enum eSceneCopyMethod {
+ SCE_COPY_NEW = 0,
+ SCE_COPY_EMPTY = 1,
+ SCE_COPY_LINK_OB = 2,
+ SCE_COPY_LINK_DATA = 3,
+ SCE_COPY_FULL = 4,
+} eSceneCopyMethod;
/* Use as the contents of a 'for' loop: for (SETLOOPER(...)) { ... */
#define SETLOOPER(_sce_basis, _sce_iter, _base) \
- _sce_iter = _sce_basis, _base = _setlooper_base_step(&_sce_iter, NULL); \
+ _sce_iter = _sce_basis, _base = _setlooper_base_step(&_sce_iter, BKE_view_layer_context_active_PLACEHOLDER(_sce_basis), NULL); \
_base; \
- _base = _setlooper_base_step(&_sce_iter, _base)
+ _base = _setlooper_base_step(&_sce_iter, NULL, _base)
-struct Base *_setlooper_base_step(struct Scene **sce_iter, struct Base *base);
+#define SETLOOPER_VIEW_LAYER(_sce_basis, _view_layer, _sce_iter, _base) \
+ _sce_iter = _sce_basis, _base = _setlooper_base_step(&_sce_iter, _view_layer, NULL); \
+ _base; \
+ _base = _setlooper_base_step(&_sce_iter, NULL, _base)
+
+#define SETLOOPER_SET_ONLY(_sce_basis, _sce_iter, _base) \
+ _sce_iter = _sce_basis, _base = _setlooper_base_step(&_sce_iter, NULL, NULL); \
+ _base; \
+ _base = _setlooper_base_step(&_sce_iter, NULL, _base)
+
+struct Base *_setlooper_base_step(struct Scene **sce_iter, struct ViewLayer *view_layer, struct Base *base);
void free_avicodecdata(struct AviCodecData *acd);
+void BKE_scene_free_ex(struct Scene *sce, const bool do_id_user);
void BKE_scene_free(struct Scene *sce);
void BKE_scene_init(struct Scene *sce);
struct Scene *BKE_scene_add(struct Main *bmain, const char *name);
-/* base functions */
-struct Base *BKE_scene_base_find_by_name(struct Scene *scene, const char *name);
-struct Base *BKE_scene_base_find(struct Scene *scene, struct Object *ob);
-struct Base *BKE_scene_base_add(struct Scene *sce, struct Object *ob);
-void BKE_scene_base_unlink(struct Scene *sce, struct Base *base);
-void BKE_scene_base_deselect_all(struct Scene *sce);
-void BKE_scene_base_select(struct Scene *sce, struct Base *selbase);
+void BKE_scene_remove_rigidbody_object(struct Scene *scene, struct Object *ob);
+
+bool BKE_scene_object_find(struct Scene *scene, struct Object *ob);
+struct Object *BKE_scene_object_find_by_name(struct Scene *scene, const char *name);
/* Scene base iteration function.
* Define struct here, so no need to bother with alloc/free it.
@@ -87,11 +99,14 @@ typedef struct SceneBaseIter {
int phase;
} SceneBaseIter;
-int BKE_scene_base_iter_next(struct EvaluationContext *eval_ctx, struct SceneBaseIter *iter,
- struct Scene **scene, int val, struct Base **base, struct Object **ob);
+int BKE_scene_base_iter_next(
+ struct Depsgraph *depsgraph, struct SceneBaseIter *iter,
+ struct Scene **scene, int val, struct Base **base, struct Object **ob);
-void BKE_scene_base_flag_to_objects(struct Scene *scene);
+void BKE_scene_base_flag_to_objects(struct ViewLayer *view_layer);
void BKE_scene_base_flag_from_objects(struct Scene *scene);
+void BKE_scene_object_base_flag_sync_from_base(struct Base *base);
+void BKE_scene_object_base_flag_sync_from_object(struct Base *base);
void BKE_scene_set_background(struct Main *bmain, struct Scene *sce);
struct Scene *BKE_scene_set_name(struct Main *bmain, const char *name);
@@ -105,7 +120,8 @@ void BKE_scene_groups_relink(struct Scene *sce);
void BKE_scene_make_local(struct Main *bmain, struct Scene *sce, const bool lib_local);
-struct Object *BKE_scene_camera_find(struct Scene *sc);
+struct Scene *BKE_scene_find_from_collection(const struct Main *bmain, const struct SceneCollection *scene_collection);
+
#ifdef DURIAN_CAMERA_SWITCH
struct Object *BKE_scene_camera_switch_find(struct Scene *scene); // DURIAN_CAMERA_SWITCH
#endif
@@ -122,12 +138,12 @@ float BKE_scene_frame_get_from_ctime(const struct Scene *scene, const float fram
void BKE_scene_frame_set(struct Scene *scene, double cfra);
/* ** Scene evaluation ** */
-void BKE_scene_update_tagged(struct EvaluationContext *eval_ctx, struct Main *bmain, struct Scene *sce);
-void BKE_scene_update_for_newframe(struct EvaluationContext *eval_ctx, struct Main *bmain, struct Scene *sce, unsigned int lay);
-void BKE_scene_update_for_newframe_ex(struct EvaluationContext *eval_ctx, struct Main *bmain, struct Scene *sce, unsigned int lay, bool do_invisible_flush);
-struct SceneRenderLayer *BKE_scene_add_render_layer(struct Scene *sce, const char *name);
-bool BKE_scene_remove_render_layer(struct Main *main, struct Scene *scene, struct SceneRenderLayer *srl);
+void BKE_scene_graph_update_tagged(struct Depsgraph *depsgraph,
+ struct Main *bmain);
+
+void BKE_scene_graph_update_for_newframe(struct Depsgraph *depsgraph,
+ struct Main *bmain);
struct SceneRenderView *BKE_scene_add_render_view(struct Scene *sce, const char *name);
bool BKE_scene_remove_render_view(struct Scene *scene, struct SceneRenderView *srv);
@@ -135,16 +151,12 @@ bool BKE_scene_remove_render_view(struct Scene *scene, struct SceneRenderView *s
/* render profile */
int get_render_subsurf_level(const struct RenderData *r, int level, bool for_render);
int get_render_child_particle_number(const struct RenderData *r, int num, bool for_render);
-int get_render_shadow_samples(const struct RenderData *r, int samples);
-float get_render_aosss_error(const struct RenderData *r, float error);
-bool BKE_scene_use_new_shading_nodes(const struct Scene *scene);
bool BKE_scene_use_shading_nodes_custom(struct Scene *scene);
-bool BKE_scene_use_world_space_shading(struct Scene *scene);
bool BKE_scene_use_spherical_stereo(struct Scene *scene);
-bool BKE_scene_uses_blender_internal(const struct Scene *scene);
-bool BKE_scene_uses_blender_game(const struct Scene *scene);
+bool BKE_scene_uses_blender_eevee(const struct Scene *scene);
+bool BKE_scene_uses_cycles(const struct Scene *scene);
void BKE_scene_disable_color_management(struct Scene *scene);
bool BKE_scene_check_color_management_enabled(const struct Scene *scene);
@@ -155,6 +167,8 @@ int BKE_render_num_threads(const struct RenderData *r);
int BKE_render_preview_pixel_size(const struct RenderData *r);
+/**********************************/
+
double BKE_scene_unit_scale(const struct UnitSettings *unit, const int unit_type, double value);
/* multiview */
@@ -174,6 +188,20 @@ void BKE_scene_multiview_view_prefix_get(struct Scene *scene, const char
void BKE_scene_multiview_videos_dimensions_get(const struct RenderData *rd, const size_t width, const size_t height, size_t *r_width, size_t *r_height);
int BKE_scene_multiview_num_videos_get(const struct RenderData *rd);
+/* depsgraph */
+void BKE_scene_allocate_depsgraph_hash(struct Scene *scene);
+void BKE_scene_ensure_depsgraph_hash(struct Scene *scene);
+void BKE_scene_free_depsgraph_hash(struct Scene *scene);
+
+struct Depsgraph *BKE_scene_get_depsgraph(struct Scene *scene, struct ViewLayer *view_layer, bool allocate);
+
+void BKE_scene_transform_orientation_remove(
+ struct Scene *scene, struct TransformOrientation *orientation);
+struct TransformOrientation *BKE_scene_transform_orientation_find(
+ const struct Scene *scene, const int index);
+int BKE_scene_transform_orientation_get_index(
+ const struct Scene *scene, const struct TransformOrientation *orientation);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/blenkernel/BKE_screen.h b/source/blender/blenkernel/BKE_screen.h
index 14e978b23f2..36708cb11a4 100644
--- a/source/blender/blenkernel/BKE_screen.h
+++ b/source/blender/blenkernel/BKE_screen.h
@@ -41,7 +41,9 @@ struct Menu;
struct Panel;
struct Scene;
struct ScrArea;
+struct ScrVert;
struct SpaceType;
+struct TransformOrientation;
struct View3D;
struct bContext;
struct bContextDataResult;
@@ -49,10 +51,14 @@ struct bScreen;
struct uiLayout;
struct uiList;
struct wmKeyConfig;
+struct wmManipulatorMap;
struct wmNotifier;
struct wmWindow;
struct wmWindowManager;
+struct WorkSpace;
struct GPUFXSettings;
+struct wmMsgBus;
+struct ScrAreaMap;
#include "BLI_compiler_attrs.h"
@@ -71,8 +77,9 @@ typedef struct SpaceType {
int spaceid; /* unique space identifier */
int iconid; /* icon lookup for menus */
- /* initial allocation, after this WM will call init() too */
- struct SpaceLink *(*new)(const struct bContext *C);
+ /* Initial allocation, after this WM will call init() too. Some editors need
+ * area and scene data (e.g. frame range) to set their initial scrolling. */
+ struct SpaceLink *(*new)(const struct ScrArea *, const struct Scene *);
/* not free spacelink itself */
void (*free)(struct SpaceLink *);
@@ -81,7 +88,9 @@ typedef struct SpaceType {
/* exit is called when the area is hidden or removed */
void (*exit)(struct wmWindowManager *, struct ScrArea *);
/* Listeners can react to bContext changes */
- void (*listener)(struct bScreen *sc, struct ScrArea *, struct wmNotifier *);
+ void (*listener)(struct bScreen *sc, struct ScrArea *,
+ struct wmNotifier *, struct Scene *scene,
+ struct WorkSpace *workspace);
/* refresh context, called after filereads, ED_area_tag_refresh() */
void (*refresh)(const struct bContext *, struct ScrArea *);
@@ -96,6 +105,9 @@ typedef struct SpaceType {
/* on startup, define dropboxes for spacetype+regions */
void (*dropboxes)(void);
+ /* initialize manipulator-map-types and manipulator-group-types with the region */
+ void (*manipulators)(void);
+
/* return context data */
int (*context)(const struct bContext *, const char *, struct bContextDataResult *);
@@ -128,9 +140,20 @@ typedef struct ARegionType {
void (*exit)(struct wmWindowManager *, struct ARegion *);
/* draw entirely, view changes should be handled here */
void (*draw)(const struct bContext *, struct ARegion *);
+ /* optional, compute button layout before drawing for dynamic size */
+ void (*layout)(const struct bContext *, struct ARegion *);
+ /* snap the size of the region (can be NULL for no snapping). */
+ int (*snap_size)(const struct ARegion *ar, int size, int axis);
/* contextual changes should be handled here */
- void (*listener)(struct bScreen *sc, struct ScrArea *, struct ARegion *, struct wmNotifier *);
-
+ void (*listener)(struct bScreen *, struct ScrArea *, struct ARegion *,
+ struct wmNotifier *, const struct Scene *scene);
+ /* Optional callback to generate subscriptions. */
+ void (*message_subscribe)(
+ const struct bContext *C,
+ struct WorkSpace *workspace, struct Scene *scene,
+ struct bScreen *sc, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus);
+
void (*free)(struct ARegion *);
/* split region, copy data optionally */
@@ -178,6 +201,7 @@ typedef struct PanelType {
char translation_context[BKE_ST_MAXNAME];
char context[BKE_ST_MAXNAME]; /* for buttons window */
char category[BKE_ST_MAXNAME]; /* for category tabs */
+ char owner_id[BKE_ST_MAXNAME]; /* for work-spaces to selectively show. */
int space_type;
int region_type;
@@ -226,6 +250,7 @@ typedef struct HeaderType {
char idname[BKE_ST_MAXNAME]; /* unique name */
int space_type;
+ int region_type;
/* draw entirely, view changes should be handled here */
void (*draw)(const struct bContext *, struct Header *);
@@ -248,6 +273,7 @@ typedef struct MenuType {
char idname[BKE_ST_MAXNAME]; /* unique name */
char label[BKE_ST_MAXNAME]; /* for button text */
char translation_context[BKE_ST_MAXNAME];
+ char owner_id[BKE_ST_MAXNAME]; /* optional, see: #wmOwnerID */
const char *description;
/* verify if the menu should draw or not */
@@ -284,6 +310,9 @@ void BKE_spacedata_id_unref(struct ScrArea *sa, struct SpaceLink *sl, struct ID
struct ARegion *BKE_area_region_copy(struct SpaceType *st, struct ARegion *ar);
void BKE_area_region_free(struct SpaceType *st, struct ARegion *ar);
void BKE_screen_area_free(struct ScrArea *sa);
+/* Manipulator-maps of a region need to be freed with the region. Uses callback to avoid low-level call. */
+void BKE_region_callback_free_manipulatormap_set(void (*callback)(struct wmManipulatorMap *));
+void BKE_region_callback_refresh_tag_manipulatormap_set(void (*callback)(struct wmManipulatorMap *));
struct ARegion *BKE_area_find_region_type(struct ScrArea *sa, int type);
struct ARegion *BKE_area_find_region_active_win(struct ScrArea *sa);
@@ -299,12 +328,12 @@ unsigned int BKE_screen_view3d_layer_active(
unsigned int BKE_screen_view3d_layer_all(const struct bScreen *sc) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+void BKE_screen_manipulator_tag_refresh(struct bScreen *sc);
+
void BKE_screen_view3d_sync(struct View3D *v3d, struct Scene *scene);
-void BKE_screen_view3d_scene_sync(struct bScreen *sc);
-void BKE_screen_view3d_main_sync(ListBase *screen_lb, struct Scene *scene);
-void BKE_screen_view3d_twmode_remove(struct View3D *v3d, const int i);
-void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, struct Scene *scene, const int i);
-void BKE_screen_gpu_fx_validate(struct GPUFXSettings *fx_settings);
+void BKE_screen_view3d_scene_sync(struct bScreen *sc, struct Scene *scene);
+bool BKE_screen_is_fullscreen_area(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+bool BKE_screen_is_used(const struct bScreen *screen) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
/* zoom factor conversion */
float BKE_screen_view3d_zoom_to_fac(float camzoom);
@@ -312,7 +341,15 @@ float BKE_screen_view3d_zoom_from_fac(float zoomfac);
/* screen */
void BKE_screen_free(struct bScreen *sc);
+void BKE_screen_area_map_free(struct ScrAreaMap *area_map) ATTR_NONNULL();
unsigned int BKE_screen_visible_layers(struct bScreen *screen, struct Scene *scene);
+struct ScrEdge *BKE_screen_find_edge(struct bScreen *sc, struct ScrVert *v1, struct ScrVert *v2);
+void BKE_screen_sort_scrvert(struct ScrVert **v1, struct ScrVert **v2);
+void BKE_screen_remove_double_scrverts(struct bScreen *sc);
+void BKE_screen_remove_double_scredges(struct bScreen *sc);
+void BKE_screen_remove_unused_scredges(struct bScreen *sc);
+void BKE_screen_remove_unused_scrverts(struct bScreen *sc);
+
#endif
diff --git a/source/blender/blenkernel/BKE_sequencer.h b/source/blender/blenkernel/BKE_sequencer.h
index 3c2cebce3cf..cd173ef33ce 100644
--- a/source/blender/blenkernel/BKE_sequencer.h
+++ b/source/blender/blenkernel/BKE_sequencer.h
@@ -31,7 +31,7 @@
*/
struct bContext;
-struct EvaluationContext;
+struct Depsgraph;
struct StripColorBalance;
struct Editing;
struct GSet;
@@ -40,6 +40,7 @@ struct GPUFX;
struct ImBuf;
struct Main;
struct Mask;
+struct RenderEngineType;
struct Scene;
struct Sequence;
struct SequenceModifierData;
@@ -92,12 +93,12 @@ void BKE_sequence_iterator_end(SeqIterator *iter);
}
typedef struct SeqRenderData {
- struct EvaluationContext *eval_ctx;
struct Main *bmain;
struct Scene *scene;
int rectx;
int recty;
int preview_render_size;
+ int for_render;
int motion_blur_samples;
float motion_blur_shutter;
bool skip_cache;
@@ -112,8 +113,9 @@ typedef struct SeqRenderData {
} SeqRenderData;
void BKE_sequencer_new_render_data(
- struct EvaluationContext *eval_ctx, struct Main *bmain, struct Scene *scene,
+ struct Main *bmain, struct Scene *scene,
int rectx, int recty, int preview_render_size,
+ int for_render,
SeqRenderData *r_context);
int BKE_sequencer_cmp_time_startdisp(const void *a, const void *b);
@@ -434,10 +436,12 @@ enum {
};
typedef struct ImBuf *(*SequencerDrawView)(
- struct Scene *scene, struct Object *camera, int width, int height,
- unsigned int flag, unsigned int draw_flags, int drawtype, int alpha_mode,
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ int drawtype,
+ struct Object *camera, int width, int height,
+ unsigned int flag, unsigned int draw_flags, int alpha_mode,
int samples, const char *viewname,
- struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
+ struct GPUOffScreen *ofs, char err_out[256]);
extern SequencerDrawView sequencer_view3d_cb;
/* copy/paste */
diff --git a/source/blender/blenkernel/BKE_sketch.h b/source/blender/blenkernel/BKE_sketch.h
deleted file mode 100644
index 9b9c125fbe6..00000000000
--- a/source/blender/blenkernel/BKE_sketch.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#ifndef __BKE_SKETCH_H__
-#define __BKE_SKETCH_H__
-
-/** \file BKE_sketch.h
- * \ingroup bke
- */
-
-typedef enum SK_PType {
- PT_CONTINUOUS,
- PT_EXACT,
-} SK_PType;
-
-typedef enum SK_PMode {
- PT_SNAP,
- PT_PROJECT,
-} SK_PMode;
-
-typedef struct SK_Point {
- float p[3];
- short p2d[2];
- float no[3];
- float size;
- SK_PType type;
- SK_PMode mode;
-} SK_Point;
-
-typedef struct SK_Stroke {
- struct SK_Stroke *next, *prev;
-
- SK_Point *points;
- int nb_points;
- int buf_size;
- int selected;
-} SK_Stroke;
-
-#define SK_OVERDRAW_LIMIT 5
-
-typedef struct SK_Overdraw {
- SK_Stroke *target;
- int start, end;
- int count;
-} SK_Overdraw;
-
-#define SK_Stroke_BUFFER_INIT_SIZE 20
-
-typedef struct SK_DrawData {
- int mval[2];
- int previous_mval[2];
- SK_PType type;
-} SK_DrawData;
-
-typedef struct SK_Intersection {
- struct SK_Intersection *next, *prev;
- SK_Stroke *stroke;
- int before;
- int after;
- int gesture_index;
- float p[3];
- float lambda; /* used for sorting intersection points */
-} SK_Intersection;
-
-typedef struct SK_Sketch {
- ListBase strokes;
- SK_Stroke *active_stroke;
- SK_Stroke *gesture;
- SK_Point next_point;
- SK_Overdraw over;
-} SK_Sketch;
-
-
-typedef struct SK_Gesture {
- SK_Stroke *stk;
- SK_Stroke *segments;
-
- ListBase intersections;
- ListBase self_intersections;
-
- int nb_self_intersections;
- int nb_intersections;
- int nb_segments;
-} SK_Gesture;
-
-
-/************************************************/
-
-void freeSketch(SK_Sketch *sketch);
-SK_Sketch *createSketch(void);
-
-void sk_removeStroke(SK_Sketch *sketch, SK_Stroke *stk);
-
-void sk_freeStroke(SK_Stroke *stk);
-SK_Stroke *sk_createStroke(void);
-
-SK_Point *sk_lastStrokePoint(SK_Stroke *stk);
-
-void sk_allocStrokeBuffer(SK_Stroke *stk);
-void sk_shrinkStrokeBuffer(SK_Stroke *stk);
-void sk_growStrokeBuffer(SK_Stroke *stk);
-void sk_growStrokeBufferN(SK_Stroke *stk, int n);
-
-void sk_replaceStrokePoint(SK_Stroke *stk, SK_Point *pt, int n);
-void sk_insertStrokePoint(SK_Stroke *stk, SK_Point *pt, int n);
-void sk_appendStrokePoint(SK_Stroke *stk, SK_Point *pt);
-void sk_insertStrokePoints(SK_Stroke *stk, SK_Point *pts, int len, int start, int end);
-
-void sk_trimStroke(SK_Stroke *stk, int start, int end);
-void sk_straightenStroke(SK_Stroke *stk, int start, int end, float p_start[3], float p_end[3]);
-void sk_polygonizeStroke(SK_Stroke *stk, int start, int end);
-void sk_flattenStroke(SK_Stroke *stk, int start, int end);
-void sk_reverseStroke(SK_Stroke *stk);
-
-void sk_filterLastContinuousStroke(SK_Stroke *stk);
-void sk_filterStroke(SK_Stroke *stk, int start, int end);
-
-void sk_initPoint(SK_Point *pt, SK_DrawData *dd, const float no[3]);
-void sk_copyPoint(SK_Point *dst, SK_Point *src);
-
-int sk_stroke_filtermval(SK_DrawData *dd);
-void sk_endContinuousStroke(SK_Stroke *stk);
-
-void sk_updateNextPoint(SK_Sketch *sketch, SK_Stroke *stk);
-
-void sk_initDrawData(SK_DrawData *dd, const int mval[2]);
-
-void sk_deleteSelectedStrokes(SK_Sketch *sketch);
-void sk_selectAllSketch(SK_Sketch *sketch, int mode);
-
-#endif
diff --git a/source/blender/blenkernel/BKE_smoke.h b/source/blender/blenkernel/BKE_smoke.h
index 20366f00df6..82bfe56b0ab 100644
--- a/source/blender/blenkernel/BKE_smoke.h
+++ b/source/blender/blenkernel/BKE_smoke.h
@@ -35,7 +35,9 @@
typedef float (*bresenham_callback)(float *result, float *input, int res[3], int *pixel, float *tRay, float correct);
-struct DerivedMesh *smokeModifier_do(struct SmokeModifierData *smd, struct Scene *scene, struct Object *ob, struct DerivedMesh *dm);
+struct DerivedMesh *smokeModifier_do(struct SmokeModifierData *smd, struct Depsgraph *depsgraph,
+ struct Scene *scene,
+ struct Object *ob, struct DerivedMesh *dm);
void smoke_reallocate_fluid(struct SmokeDomainSettings *sds, float dx, int res[3], int free_old);
void smoke_reallocate_highres_fluid(struct SmokeDomainSettings *sds, float dx, int res[3], int free_old);
diff --git a/source/blender/blenkernel/BKE_softbody.h b/source/blender/blenkernel/BKE_softbody.h
index 486fe8ed5a8..c7bf876a414 100644
--- a/source/blender/blenkernel/BKE_softbody.h
+++ b/source/blender/blenkernel/BKE_softbody.h
@@ -31,6 +31,7 @@
* \ingroup bke
*/
+struct Depsgraph;
struct Object;
struct Scene;
struct SoftBody;
@@ -59,7 +60,8 @@ extern void sbFree(struct SoftBody *sb);
extern void sbFreeSimulation(struct SoftBody *sb);
/* do one simul step, reading and writing vertex locs from given array */
-extern void sbObjectStep(struct Scene *scene, struct Object *ob, float framnr, float (*vertexCos)[3], int numVerts);
+extern void sbObjectStep(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
+ float framnr, float (*vertexCos)[3], int numVerts);
/* makes totally fresh start situation, resets time */
extern void sbObjectToSoftbody(struct Object *ob);
diff --git a/source/blender/blenkernel/BKE_sound.h b/source/blender/blenkernel/BKE_sound.h
index 6f8274fabc8..98fb4f47339 100644
--- a/source/blender/blenkernel/BKE_sound.h
+++ b/source/blender/blenkernel/BKE_sound.h
@@ -35,8 +35,8 @@
#define SOUND_WAVE_SAMPLES_PER_SECOND 250
-#ifdef WITH_SYSTEM_AUDASPACE
-# include AUD_DEVICE_H
+#if defined(WITH_AUDASPACE)
+# include <AUD_Device.h>
#endif
struct bSound;
@@ -84,7 +84,7 @@ void BKE_sound_copy_data(struct Main *bmain, struct bSound *sound_dst, const str
void BKE_sound_make_local(struct Main *bmain, struct bSound *sound, const bool lib_local);
-#if defined(__AUD_C_API_H__) || defined(WITH_SYSTEM_AUDASPACE)
+#if defined(WITH_AUDASPACE)
AUD_Device *BKE_sound_mixdown(struct Scene *scene, AUD_DeviceSpecs specs, int start, float volume);
#endif
@@ -149,6 +149,4 @@ float BKE_sound_get_length(struct bSound *sound);
char **BKE_sound_get_device_names(void);
-bool BKE_sound_is_jack_supported(void);
-
#endif /* __BKE_SOUND_H__ */
diff --git a/source/blender/blenkernel/BKE_texture.h b/source/blender/blenkernel/BKE_texture.h
index 4e98852c995..ed6aa3f6af9 100644
--- a/source/blender/blenkernel/BKE_texture.h
+++ b/source/blender/blenkernel/BKE_texture.h
@@ -40,7 +40,6 @@ extern "C" {
struct bNode;
struct Brush;
struct ColorBand;
-struct EnvMap;
struct FreestyleLineStyle;
struct ImagePool;
struct Lamp;
@@ -53,7 +52,6 @@ struct PointDensity;
struct Tex;
struct TexMapping;
struct TexResult;
-struct VoxelData;
struct World;
/* in ColorBand struct */
@@ -76,27 +74,17 @@ struct MTex *BKE_texture_mtex_add_id(struct ID *id, int slot);
// void autotexname(struct Tex *tex);
struct Tex *give_current_object_texture(struct Object *ob);
-struct Tex *give_current_material_texture(struct Material *ma);
-struct Tex *give_current_lamp_texture(struct Lamp *la);
struct Tex *give_current_linestyle_texture(struct FreestyleLineStyle *linestyle);
-struct Tex *give_current_world_texture(struct World *world);
struct Tex *give_current_brush_texture(struct Brush *br);
struct Tex *give_current_particle_texture(struct ParticleSettings *part);
-struct bNode *give_current_material_texture_node(struct Material *ma);
-
bool give_active_mtex(struct ID *id, struct MTex ***mtex_ar, short *act);
void set_active_mtex(struct ID *id, short act);
void set_current_brush_texture(struct Brush *br, struct Tex *tex);
-void set_current_world_texture(struct World *wo, struct Tex *tex);
-void set_current_material_texture(struct Material *ma, struct Tex *tex);
-void set_current_lamp_texture(struct Lamp *la, struct Tex *tex);
void set_current_linestyle_texture(struct FreestyleLineStyle *linestyle, struct Tex *tex);
void set_current_particle_texture(struct ParticleSettings *part, struct Tex *tex);
-bool has_current_material_texture(struct Material *ma);
-
struct TexMapping *BKE_texture_mapping_add(int type);
void BKE_texture_mapping_default(struct TexMapping *texmap, int type);
void BKE_texture_mapping_init(struct TexMapping *texmap);
@@ -104,26 +92,12 @@ void BKE_texture_mapping_init(struct TexMapping *texmap);
struct ColorMapping *BKE_texture_colormapping_add(void);
void BKE_texture_colormapping_default(struct ColorMapping *colormap);
-void BKE_texture_envmap_free_data(struct EnvMap *env);
-void BKE_texture_envmap_free(struct EnvMap *env);
-struct EnvMap *BKE_texture_envmap_add(void);
-struct EnvMap *BKE_texture_envmap_copy(const struct EnvMap *env, const int flag);
-
void BKE_texture_pointdensity_init_data(struct PointDensity *pd);
void BKE_texture_pointdensity_free_data(struct PointDensity *pd);
void BKE_texture_pointdensity_free(struct PointDensity *pd);
struct PointDensity *BKE_texture_pointdensity_add(void);
struct PointDensity *BKE_texture_pointdensity_copy(const struct PointDensity *pd, const int flag);
-void BKE_texture_voxeldata_free_data(struct VoxelData *vd);
-void BKE_texture_voxeldata_free(struct VoxelData *vd);
-struct VoxelData *BKE_texture_voxeldata_add(void);
-struct VoxelData *BKE_texture_voxeldata_copy(struct VoxelData *vd);
-
-void BKE_texture_ocean_free(struct OceanTex *ot);
-struct OceanTex *BKE_texture_ocean_add(void);
-struct OceanTex *BKE_texture_ocean_copy(const struct OceanTex *ot, const int flag);
-
bool BKE_texture_dependsOnTime(const struct Tex *texture);
bool BKE_texture_is_image_user(const struct Tex *tex);
diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
new file mode 100644
index 00000000000..5ee15a08f9b
--- /dev/null
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -0,0 +1,123 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file BKE_workspace.h
+ * \ingroup bke
+ */
+
+#ifndef __BKE_WORKSPACE_H__
+#define __BKE_WORKSPACE_H__
+
+#include "BLI_compiler_attrs.h"
+
+struct bScreen;
+struct Main;
+struct Scene;
+struct TransformOrientation;
+struct ViewLayer;
+
+/* -------------------------------------------------------------------- */
+/* Create, delete, init */
+
+struct WorkSpace *BKE_workspace_add(struct Main *bmain, const char *name);
+void BKE_workspace_free(struct WorkSpace *workspace);
+void BKE_workspace_remove(struct Main *bmain, struct WorkSpace *workspace);
+
+struct WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(const struct Main *bmain);
+void BKE_workspace_instance_hook_free(const struct Main *bmain, struct WorkSpaceInstanceHook *hook);
+
+struct WorkSpaceLayout *BKE_workspace_layout_add(
+ struct WorkSpace *workspace,
+ struct bScreen *screen,
+ const char *name) ATTR_NONNULL();
+void BKE_workspace_layout_remove(
+ struct Main *bmain,
+ struct WorkSpace *workspace, struct WorkSpaceLayout *layout) ATTR_NONNULL();
+
+void BKE_workspace_relations_free(
+ ListBase *relation_list);
+
+
+/* -------------------------------------------------------------------- */
+/* General Utils */
+
+void BKE_workspace_view_layer_remove_references(
+ const struct Main *bmain,
+ const struct ViewLayer *view_layer) ATTR_NONNULL();
+
+struct WorkSpaceLayout *BKE_workspace_layout_find(
+ const struct WorkSpace *workspace, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+struct WorkSpaceLayout *BKE_workspace_layout_find_global(
+ const struct Main *bmain, const struct bScreen *screen,
+ struct WorkSpace **r_workspace) ATTR_NONNULL(1, 2);
+
+struct WorkSpaceLayout *BKE_workspace_layout_iter_circular(
+ const struct WorkSpace *workspace, struct WorkSpaceLayout *start,
+ bool (*callback)(const struct WorkSpaceLayout *layout, void *arg),
+ void *arg, const bool iter_backward);
+
+
+/* -------------------------------------------------------------------- */
+/* Getters/Setters */
+
+#define GETTER_ATTRS ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT
+#define SETTER_ATTRS ATTR_NONNULL(1)
+
+struct WorkSpace *BKE_workspace_active_get(struct WorkSpaceInstanceHook *hook) GETTER_ATTRS;
+void BKE_workspace_active_set(struct WorkSpaceInstanceHook *hook, struct WorkSpace *workspace) SETTER_ATTRS;
+struct WorkSpaceLayout *BKE_workspace_active_layout_get(const struct WorkSpaceInstanceHook *hook) GETTER_ATTRS;
+void BKE_workspace_active_layout_set(struct WorkSpaceInstanceHook *hook, struct WorkSpaceLayout *layout) SETTER_ATTRS;
+struct bScreen *BKE_workspace_active_screen_get(const struct WorkSpaceInstanceHook *hook) GETTER_ATTRS;
+void BKE_workspace_active_screen_set(
+ struct WorkSpaceInstanceHook *hook, struct WorkSpace *workspace, struct bScreen *screen) SETTER_ATTRS;
+
+struct Base *BKE_workspace_active_base_get(const struct WorkSpace *workspace, const struct Scene *scene);
+struct ViewLayer *BKE_workspace_view_layer_get(
+ const struct WorkSpace *workspace,
+ const struct Scene *scene) GETTER_ATTRS;
+void BKE_workspace_view_layer_set(
+ struct WorkSpace *workspace,
+ struct ViewLayer *layer,
+ struct Scene *scene) SETTER_ATTRS;
+struct ListBase *BKE_workspace_layouts_get(struct WorkSpace *workspace) GETTER_ATTRS;
+
+const char *BKE_workspace_layout_name_get(const struct WorkSpaceLayout *layout) GETTER_ATTRS;
+void BKE_workspace_layout_name_set(
+ struct WorkSpace *workspace, struct WorkSpaceLayout *layout, const char *new_name) ATTR_NONNULL();
+struct bScreen *BKE_workspace_layout_screen_get(const struct WorkSpaceLayout *layout) GETTER_ATTRS;
+void BKE_workspace_layout_screen_set(struct WorkSpaceLayout *layout, struct bScreen *screen) SETTER_ATTRS;
+
+struct WorkSpaceLayout *BKE_workspace_hook_layout_for_workspace_get(
+ const struct WorkSpaceInstanceHook *hook, const struct WorkSpace *workspace) GETTER_ATTRS;
+void BKE_workspace_hook_layout_for_workspace_set(
+ struct WorkSpaceInstanceHook *hook, struct WorkSpace *workspace, struct WorkSpaceLayout *layout) ATTR_NONNULL();
+
+/* Update / evaluate */
+void BKE_workspace_update_tagged(struct Main *bmain,
+ struct WorkSpace *workspace,
+ struct Scene *scene);
+
+bool BKE_workspace_owner_id_check(
+ const struct WorkSpace *workspace, const char *owner_id) ATTR_NONNULL();
+
+#undef GETTER_ATTRS
+#undef SETTER_ATTRS
+
+#endif /* __BKE_WORKSPACE_H__ */
diff --git a/source/blender/blenkernel/BKE_world.h b/source/blender/blenkernel/BKE_world.h
index b28bac08727..fe8aa8694af 100644
--- a/source/blender/blenkernel/BKE_world.h
+++ b/source/blender/blenkernel/BKE_world.h
@@ -44,4 +44,11 @@ struct World *BKE_world_copy(struct Main *bmain, const struct World *wrld);
struct World *BKE_world_localize(struct World *wrld);
void BKE_world_make_local(struct Main *bmain, struct World *wrld, const bool lib_local);
-#endif /* __BKE_WORLD_H__ */
+/* Evaluation. */
+
+struct Depsgraph;
+
+void BKE_world_eval(struct Depsgraph *depsgraph, struct World *world);
+
+#endif
+
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index 723ba347dfb..9e241b7fa81 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -30,6 +30,7 @@ set(INC
../blenloader
../blentranslation
../depsgraph
+ ../draw
../gpu
../ikplugin
../imbuf
@@ -81,12 +82,12 @@ set(SRC
intern/boids.c
intern/bpath.c
intern/brush.c
- intern/bullet.c
intern/bvhutils.c
intern/cachefile.c
intern/camera.c
intern/cdderivedmesh.c
intern/cloth.c
+ intern/collection.c
intern/collision.c
intern/colorband.c
intern/colortools.c
@@ -99,13 +100,13 @@ set(SRC
intern/customdata_file.c
intern/data_transfer.c
intern/deform.c
- intern/depsgraph.c
intern/displist.c
intern/dynamicpaint.c
intern/editderivedmesh.c
intern/editlattice.c
intern/editmesh.c
intern/editmesh_bvh.c
+ intern/editmesh_tangent.c
intern/effect.c
intern/fcurve.c
intern/fluidsim.c
@@ -115,6 +116,7 @@ set(SRC
intern/gpencil.c
intern/group.c
intern/icons.c
+ intern/icons_rasterize.c
intern/idcode.c
intern/idprop.c
intern/idprop_utils.c
@@ -126,6 +128,7 @@ set(SRC
intern/lattice.c
intern/library.c
intern/library_idmap.c
+ intern/library_override.c
intern/library_query.c
intern/library_remap.c
intern/linestyle.c
@@ -138,7 +141,9 @@ set(SRC
intern/mesh.c
intern/mesh_evaluate.c
intern/mesh_mapping.c
+ intern/mesh_merge.c
intern/mesh_remap.c
+ intern/mesh_tangent.c
intern/mesh_validate.c
intern/modifier.c
intern/modifiers_bmesh.c
@@ -147,6 +152,7 @@ set(SRC
intern/nla.c
intern/node.c
intern/object.c
+ intern/object_facemap.c
intern/object_deform.c
intern/object_dupli.c
intern/object_update.c
@@ -161,10 +167,11 @@ set(SRC
intern/pbvh.c
intern/pbvh_bmesh.c
intern/pointcache.c
- intern/property.c
+ intern/layer.c
+ intern/layer_utils.c
+ intern/lightprobe.c
intern/report.c
intern/rigidbody.c
- intern/sca.c
intern/scene.c
intern/screen.c
intern/seqcache.c
@@ -172,7 +179,6 @@ set(SRC
intern/seqmodifier.c
intern/sequencer.c
intern/shrinkwrap.c
- intern/sketch.c
intern/smoke.c
intern/softbody.c
intern/sound.c
@@ -191,6 +197,7 @@ set(SRC
intern/tracking_util.c
intern/undo_system.c
intern/unit.c
+ intern/workspace.c
intern/world.c
intern/writeavi.c
intern/writeframeserver.c
@@ -213,13 +220,13 @@ set(SRC
BKE_boids.h
BKE_bpath.h
BKE_brush.h
- BKE_bullet.h
BKE_bvhutils.h
BKE_cachefile.h
BKE_camera.h
BKE_ccg.h
BKE_cdderivedmesh.h
BKE_cloth.h
+ BKE_collection.h
BKE_collision.h
BKE_colorband.h
BKE_colortools.h
@@ -231,12 +238,12 @@ set(SRC
BKE_customdata_file.h
BKE_data_transfer.h
BKE_deform.h
- BKE_depsgraph.h
BKE_displist.h
BKE_dynamicpaint.h
BKE_editlattice.h
BKE_editmesh.h
BKE_editmesh_bvh.h
+ BKE_editmesh_tangent.h
BKE_effect.h
BKE_fcurve.h
BKE_fluidsim.h
@@ -255,6 +262,7 @@ set(SRC
BKE_lattice.h
BKE_library.h
BKE_library_idmap.h
+ BKE_library_override.h
BKE_library_query.h
BKE_library_remap.h
BKE_linestyle.h
@@ -266,12 +274,14 @@ set(SRC
BKE_mesh.h
BKE_mesh_mapping.h
BKE_mesh_remap.h
+ BKE_mesh_tangent.h
BKE_modifier.h
BKE_movieclip.h
BKE_multires.h
BKE_nla.h
BKE_node.h
BKE_object.h
+ BKE_object_facemap.h
BKE_object_deform.h
BKE_ocean.h
BKE_outliner_treehash.h
@@ -280,15 +290,14 @@ set(SRC
BKE_particle.h
BKE_pbvh.h
BKE_pointcache.h
- BKE_property.h
+ BKE_layer.h
+ BKE_lightprobe.h
BKE_report.h
BKE_rigidbody.h
- BKE_sca.h
BKE_scene.h
BKE_screen.h
BKE_sequencer.h
BKE_shrinkwrap.h
- BKE_sketch.h
BKE_smoke.h
BKE_softbody.h
BKE_sound.h
@@ -300,11 +309,11 @@ set(SRC
BKE_tracking.h
BKE_undo_system.h
BKE_unit.h
+ BKE_workspace.h
BKE_world.h
BKE_writeavi.h
BKE_writeframeserver.h
- depsgraph_private.h
nla_private.h
tracking_private.h
particle_private.h
@@ -331,7 +340,7 @@ if(WIN32)
endif()
if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
+ add_definitions(-DWITH_AUDASPACE)
list(APPEND INC_SYS
${AUDASPACE_C_INCLUDE_DIRS}
@@ -419,6 +428,10 @@ if(WITH_PYTHON)
)
add_definitions(-DWITH_PYTHON)
+ if(WITH_PYTHON_SAFETY)
+ add_definitions(-DWITH_PYTHON_SAFETY)
+ endif()
+
if(WITH_PYTHON_SECURITY)
add_definitions(-DWITH_PYTHON_SECURITY)
endif()
@@ -471,18 +484,6 @@ if(WITH_LZMA)
add_definitions(-DWITH_LZMA)
endif()
-if(WITH_GAMEENGINE)
- list(APPEND INC_SYS
- ../../../extern/recastnavigation
- )
- list(APPEND SRC
- intern/navmesh_conversion.c
- BKE_navmesh_conversion.h
- )
-
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
if(WITH_LIBMV)
add_definitions(-DWITH_LIBMV)
endif()
@@ -535,8 +536,4 @@ endif()
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /WX")
#endif()
-if(WITH_LEGACY_DEPSGRAPH)
- add_definitions(-DWITH_LEGACY_DEPSGRAPH)
-endif()
-
blender_add_lib(bf_blenkernel "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/blenkernel/depsgraph_private.h b/source/blender/blenkernel/depsgraph_private.h
deleted file mode 100644
index 69ca75836d9..00000000000
--- a/source/blender/blenkernel/depsgraph_private.h
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2004 Blender Foundation.
- * All rights reserved.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenkernel/depsgraph_private.h
- * \ingroup bke
- */
-
-#ifndef __DEPSGRAPH_PRIVATE_H__
-#define __DEPSGRAPH_PRIVATE_H__
-
-#include "BKE_depsgraph.h"
-#include "DNA_constraint_types.h"
-#include "BKE_constraint.h"
-
-struct Scene;
-struct Group;
-struct EffectorWeights;
-struct ModifierData;
-
-/* **** DAG relation types *** */
-
-/* scene link to object */
-#define DAG_RL_SCENE (1 << 0)
-/* object link to data */
-#define DAG_RL_DATA (1 << 1)
-
-/* object changes object (parent, track, constraints) */
-#define DAG_RL_OB_OB (1 << 2)
-/* object changes obdata (hooks, constraints) */
-#define DAG_RL_OB_DATA (1 << 3)
-/* data changes object (vertex parent) */
-#define DAG_RL_DATA_OB (1 << 4)
-/* data changes data (deformers) */
-#define DAG_RL_DATA_DATA (1 << 5)
-
-#define DAG_NO_RELATION (1 << 6)
-
-#define DAG_RL_ALL_BUT_DATA (DAG_RL_SCENE | DAG_RL_OB_OB | DAG_RL_OB_DATA | DAG_RL_DATA_OB | DAG_RL_DATA_DATA)
-#define DAG_RL_ALL (DAG_RL_ALL_BUT_DATA | DAG_RL_DATA)
-
-
-#define DAGQUEUEALLOC 50
-
-enum {
- DAG_WHITE = 0,
- DAG_GRAY = 1,
- DAG_BLACK = 2
-};
-
-typedef struct DagAdjList {
- struct DagNode *node;
- short type;
- int count; /* number of identical arcs */
- unsigned int lay; // for flushing redraw/rebuild events
- const char *name;
- struct DagAdjList *next;
-} DagAdjList;
-
-
-typedef struct DagNode {
- int color;
- short type;
- float x, y, k;
- void *ob;
- void *first_ancestor;
- int ancestor_count;
- unsigned int lay; /* accumulated layers of its relations + itself */
- unsigned int scelay; /* layers due to being in scene */
- uint64_t customdata_mask; /* customdata mask */
- int lasttime; /* if lasttime != DagForest->time, this node was not evaluated yet for flushing */
- int BFS_dist; /* BFS distance */
- int DFS_dist; /* DFS distance */
- int DFS_dvtm; /* DFS discovery time */
- int DFS_fntm; /* DFS Finishing time */
- struct DagAdjList *child;
- struct DagAdjList *parent;
- struct DagNode *next;
-
- /* Threaded evaluation routines */
- uint32_t num_pending_parents; /* number of parents which are not updated yet
- * this node has got.
- * Used by threaded update for faster detect whether node could be
- * updated aready.
- */
- bool scheduled;
-
- /* Runtime flags mainly used to determine which extra data is to be evaluated
- * during object_handle_update(). Such an extra data is what depends on the
- * DAG topology, meaning this flags indicates the data evaluation of which
- * depends on the node dependencies.
- */
- short eval_flags;
-} DagNode;
-
-typedef struct DagNodeQueueElem {
- struct DagNode *node;
- struct DagNodeQueueElem *next;
-} DagNodeQueueElem;
-
-typedef struct DagNodeQueue {
- DagNodeQueueElem *first;
- DagNodeQueueElem *last;
- int count;
- int maxlevel;
- struct DagNodeQueue *freenodes;
-} DagNodeQueue;
-
-/* forest as we may have more than one DAG unconnected */
-typedef struct DagForest {
- ListBase DagNode;
- struct GHash *nodeHash;
- int numNodes;
- bool is_acyclic;
- int time; /* for flushing/tagging, compare with node->lasttime */
- bool ugly_hack_sorry; /* prevent type check */
- bool need_update;
-} DagForest;
-
-// queue operations
-DagNodeQueue *queue_create(int slots);
-void queue_raz(DagNodeQueue *queue);
-void push_queue(DagNodeQueue *queue, DagNode *node);
-void push_stack(DagNodeQueue *queue, DagNode *node);
-DagNode *pop_queue(DagNodeQueue *queue);
-DagNode *get_top_node_queue(DagNodeQueue *queue);
-void queue_delete(DagNodeQueue *queue);
-
-// Dag management
-DagForest *dag_init(void);
-DagForest *build_dag(struct Main *bmain, struct Scene *sce, short mask);
-void free_forest(struct DagForest *Dag);
-DagNode *dag_find_node(DagForest *forest, void *fob);
-DagNode *dag_add_node(DagForest *forest, void *fob);
-DagNode *dag_get_node(DagForest *forest, void *fob);
-DagNode *dag_get_sub_node(DagForest *forest, void *fob);
-void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, const char *name);
-
-typedef bool (*DagCollobjFilterFunction)(struct Object *obj, struct ModifierData *md);
-
-void dag_add_collision_relations(DagForest *dag, struct Scene *scene, Object *ob, DagNode *node, struct Group *group, int layer, unsigned int modifier_type, DagCollobjFilterFunction fn, bool dupli, const char *name);
-void dag_add_forcefield_relations(DagForest *dag, struct Scene *scene, Object *ob, DagNode *node, struct EffectorWeights *eff, bool add_absorption, int skip_forcefield, const char *name);
-
-void graph_print_queue(DagNodeQueue *nqueue);
-void graph_print_queue_dist(DagNodeQueue *nqueue);
-void graph_print_adj_list(DagForest *dag);
-
-#endif /* __DEPSGRAPH_PRIVATE_H__ */
diff --git a/source/blender/blenkernel/intern/CCGSubSurf.c b/source/blender/blenkernel/intern/CCGSubSurf.c
index 792e9195f12..68bcfa878ac 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf.c
@@ -42,7 +42,7 @@
# include "opensubdiv_converter_capi.h"
#endif
-#include "GL/glew.h"
+#include "GPU_glew.h"
/***/
diff --git a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
index f568bb94ac5..c1a4f8dba53 100644
--- a/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
+++ b/source/blender/blenkernel/intern/CCGSubSurf_opensubdiv.c
@@ -43,7 +43,7 @@
#include "opensubdiv_capi.h"
#include "opensubdiv_converter_capi.h"
-#include "GL/glew.h"
+#include "GPU_glew.h"
#include "GPU_extensions.h"
#define OSD_LOG if (false) printf
@@ -232,6 +232,9 @@ bool ccgSubSurf_prepareGLMesh(CCGSubSurf *ss,
CHECK_COMPUTE_TYPE(CUDA)
CHECK_COMPUTE_TYPE(GLSL_TRANSFORM_FEEDBACK)
CHECK_COMPUTE_TYPE(GLSL_COMPUTE)
+ default:
+ compute_type = OPENSUBDIV_EVALUATOR_CPU;
+ break;
#undef CHECK_COMPUTE_TYPE
}
@@ -739,7 +742,7 @@ static void opensubdiv_evaluateNGonFaceGrids(CCGSubSurf *ss,
/* Evaluate edges. */
for (S = 0; S < face->numVerts; S++) {
CCGEdge *edge = FACE_getEdges(face)[S];
- int x, S0, S1;
+ int x, S0 = 0, S1 = 0;
bool flip;
for (x = 0; x < face->numVerts; ++x) {
@@ -995,7 +998,7 @@ void ccgSubSurf__sync_subdivUvs(CCGSubSurf *ss, bool subdiv_uvs)
void BKE_subsurf_osd_init(void)
{
- openSubdiv_init(GPU_legacy_support());
+ openSubdiv_init();
BLI_spin_init(&delete_spin);
}
diff --git a/source/blender/blenkernel/intern/DerivedMesh.c b/source/blender/blenkernel/intern/DerivedMesh.c
index 15469e3ae4b..dacc0c35e0f 100644
--- a/source/blender/blenkernel/intern/DerivedMesh.c
+++ b/source/blender/blenkernel/intern/DerivedMesh.c
@@ -55,11 +55,13 @@
#include "BKE_colorband.h"
#include "BKE_editmesh.h"
#include "BKE_key.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_material.h"
#include "BKE_modifier.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
+#include "BKE_mesh_tangent.h"
#include "BKE_object.h"
#include "BKE_object_deform.h"
#include "BKE_paint.h"
@@ -68,19 +70,12 @@
#include "BKE_deform.h"
#include "BKE_global.h" /* For debug flag, DM_update_tessface_data() func. */
-#ifdef WITH_GAMEENGINE
-#include "BKE_navmesh_conversion.h"
-static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm);
-#endif
-
#include "BLI_sys_types.h" /* for intptr_t support */
-#include "GPU_buffers.h"
-#include "GPU_glew.h"
-#include "GPU_shader.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#ifdef WITH_OPENSUBDIV
-# include "BKE_depsgraph.h"
# include "DNA_userdef_types.h"
#endif
@@ -349,7 +344,6 @@ void DM_init(
DM_init_funcs(dm);
dm->needsFree = 1;
- dm->auto_bump_scale = -1.0f;
dm->dirty = 0;
/* don't use CustomData_reset(...); because we dont want to touch customdata */
@@ -406,7 +400,6 @@ int DM_release(DerivedMesh *dm)
{
if (dm->needsFree) {
bvhcache_free(&dm->bvhCache);
- GPU_drawobject_free(dm);
CustomData_free(&dm->vertData, dm->numVertData);
CustomData_free(&dm->edgeData, dm->numEdgeData);
CustomData_free(&dm->faceData, dm->numTessFaceData);
@@ -552,7 +545,6 @@ void DM_update_tessface_data(DerivedMesh *dm)
MLoop *ml = dm->getLoopArray(dm);
CustomData *fdata = dm->getTessFaceDataLayout(dm);
- CustomData *pdata = dm->getPolyDataLayout(dm);
CustomData *ldata = dm->getLoopDataLayout(dm);
const int totface = dm->getNumTessFaces(dm);
@@ -565,7 +557,7 @@ void DM_update_tessface_data(DerivedMesh *dm)
if (!polyindex)
return;
- CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
+ CustomData_from_bmeshpoly(fdata, ldata, totface);
if (CustomData_has_layer(fdata, CD_MTFACE) ||
CustomData_has_layer(fdata, CD_MCOL) ||
@@ -597,7 +589,7 @@ void DM_update_tessface_data(DerivedMesh *dm)
* 0 for quads (because our quads may have been rotated compared to their org poly, see tessellation code).
* So we pass the MFace's, and BKE_mesh_loops_to_tessdata will use MFace->v4 index as quad test.
*/
- BKE_mesh_loops_to_tessdata(fdata, ldata, pdata, mface, polyindex, loopindex, totface);
+ BKE_mesh_loops_to_tessdata(fdata, ldata, mface, polyindex, loopindex, totface);
MEM_freeN(loopindex);
}
@@ -615,7 +607,6 @@ void DM_generate_tangent_tessface_data(DerivedMesh *dm, bool generate)
MLoop *ml = dm->getLoopArray(dm);
CustomData *fdata = dm->getTessFaceDataLayout(dm);
- CustomData *pdata = dm->getPolyDataLayout(dm);
CustomData *ldata = dm->getLoopDataLayout(dm);
const int totface = dm->getNumTessFaces(dm);
@@ -632,7 +623,7 @@ void DM_generate_tangent_tessface_data(DerivedMesh *dm, bool generate)
for (int j = 0; j < ldata->totlayer; j++) {
if (ldata->layers[j].type == CD_TANGENT) {
CustomData_add_layer_named(fdata, CD_TANGENT, CD_CALLOC, NULL, totface, ldata->layers[j].name);
- CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
+ CustomData_bmesh_update_active_layers(fdata, ldata);
if (!loopindex) {
loopindex = MEM_malloc_arrayN(totface, sizeof(*loopindex), __func__);
@@ -662,7 +653,7 @@ void DM_generate_tangent_tessface_data(DerivedMesh *dm, bool generate)
}
if (loopindex)
MEM_freeN(loopindex);
- BLI_assert(CustomData_from_bmeshpoly_test(fdata, pdata, ldata, true));
+ BLI_assert(CustomData_from_bmeshpoly_test(fdata, ldata, true));
}
if (G.debug & G_DEBUG)
@@ -1147,13 +1138,14 @@ DerivedMesh *mesh_create_derived(Mesh *me, float (*vertCos)[3])
}
DerivedMesh *mesh_create_derived_for_modifier(
- Scene *scene, Object *ob,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob,
ModifierData *md, int build_shapekey_layers)
{
Mesh *me = ob->data;
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
DerivedMesh *dm;
KeyBlock *kb;
+ ModifierEvalContext mectx = {depsgraph, ob, 0};
md->scene = scene;
@@ -1171,9 +1163,12 @@ DerivedMesh *mesh_create_derived_for_modifier(
if (mti->type == eModifierTypeType_OnlyDeform) {
int numVerts;
- float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(me, &numVerts);
+ /* Always get the vertex coordinates from the original mesh. Otherwise
+ * there is the risk of deforming already-deformed coordinates. */
+ Mesh *mesh_orig_id = (Mesh *)DEG_get_original_id(&me->id);
+ float (*deformedVerts)[3] = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
- modwrap_deformVerts(md, ob, NULL, deformedVerts, numVerts, 0);
+ modwrap_deformVerts(md, &mectx, NULL, deformedVerts, numVerts);
dm = mesh_create_derived(me, deformedVerts);
if (build_shapekey_layers)
@@ -1187,7 +1182,7 @@ DerivedMesh *mesh_create_derived_for_modifier(
if (build_shapekey_layers)
add_shapekey_layers(tdm, me, ob);
- dm = modwrap_applyModifier(md, ob, tdm, 0);
+ dm = modwrap_applyModifier(md, &mectx, tdm);
ASSERT_IS_VALID_DM(dm);
if (tdm != dm) tdm->release(tdm);
@@ -1288,8 +1283,11 @@ static void add_orco_dm(
else
dm->getVertCos(dm, orco);
}
- else
+ else {
+ /* TODO(sybren): totvert should potentially change here, as ob->data
+ * or em may have a different number of vertices than dm. */
orco = get_orco_coords_dm(ob, em, layer, &free);
+ }
if (orco) {
if (layer == CD_ORCO)
@@ -1744,15 +1742,8 @@ static void dm_ensure_display_normals(DerivedMesh *dm)
}
}
-/**
- * new value for useDeform -1 (hack for the gameengine):
- *
- * - apply only the modifier stack of the object, skipping the virtual modifiers,
- * - don't apply the key
- * - apply deform modifiers and input vertexco
- */
static void mesh_calc_modifiers(
- Scene *scene, Object *ob, float (*inputVertexCos)[3],
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (*inputVertexCos)[3],
const bool useRenderParams, int useDeform,
const bool need_mapping, CustomDataMask dataMask,
const int index, const bool useCache, const bool build_shapekey_layers,
@@ -1761,6 +1752,9 @@ static void mesh_calc_modifiers(
DerivedMesh **r_deform, DerivedMesh **r_final)
{
Mesh *me = ob->data;
+ /* Always get the vertex coordinates from the original mesh. Otherwise
+ * there is the risk of deforming already-deformed coordinates. */
+ Mesh *mesh_orig_id = (Mesh *)DEG_get_original_id(&me->id);
ModifierData *firstmd, *md, *previewmd = NULL;
CDMaskLink *datamasks, *curr;
/* XXX Always copying POLYINDEX, else tessellated data are no more valid! */
@@ -1770,7 +1764,6 @@ static void mesh_calc_modifiers(
int numVerts = me->totvert;
const int required_mode = useRenderParams ? eModifierMode_Render : eModifierMode_Realtime;
bool isPrevDeform = false;
- const bool skipVirtualArmature = (useDeform < 0);
MultiresModifierData *mmd = get_multires_modifier(scene, ob, 0);
const bool has_multires = (mmd && mmd->sculptlvl != 0);
bool multires_applied = false;
@@ -1804,17 +1797,13 @@ static void mesh_calc_modifiers(
if (useDeform)
deform_app_flags |= MOD_APPLY_USECACHE;
- if (!skipVirtualArmature) {
- firstmd = modifiers_getVirtualModifierList(ob, &virtualModifierData);
- }
- else {
- /* game engine exception */
- firstmd = ob->modifiers.first;
- if (firstmd && firstmd->type == eModifierType_Armature)
- firstmd = firstmd->next;
- }
+ /* TODO(sybren): do we really need three context objects? Or do we modify
+ * them on the fly to change the flags where needed? */
+ const ModifierEvalContext mectx_deform = {depsgraph, ob, deform_app_flags};
+ const ModifierEvalContext mectx_apply = {depsgraph, ob, app_flags};
+ const ModifierEvalContext mectx_orco = {depsgraph, ob, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO};
- md = firstmd;
+ md = firstmd = modifiers_getVirtualModifierList(ob, &virtualModifierData);
modifiers_clearErrors(ob);
@@ -1861,9 +1850,9 @@ static void mesh_calc_modifiers(
if (mti->type == eModifierTypeType_OnlyDeform && !sculpt_dyntopo) {
if (!deformedVerts)
- deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
+ deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
- modwrap_deformVerts(md, ob, NULL, deformedVerts, numVerts, deform_app_flags);
+ modwrap_deformVerts(md, &mectx_deform, NULL, deformedVerts, numVerts);
}
else {
break;
@@ -1894,7 +1883,7 @@ static void mesh_calc_modifiers(
if (inputVertexCos)
deformedVerts = inputVertexCos;
else
- deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
+ deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
}
@@ -1991,7 +1980,7 @@ static void mesh_calc_modifiers(
dm->getVertCos(dm, deformedVerts);
}
else {
- deformedVerts = BKE_mesh_vertexCos_get(me, &numVerts);
+ deformedVerts = BKE_mesh_vertexCos_get(mesh_orig_id, &numVerts);
}
}
@@ -2004,7 +1993,7 @@ static void mesh_calc_modifiers(
}
}
- modwrap_deformVerts(md, ob, dm, deformedVerts, numVerts, deform_app_flags);
+ modwrap_deformVerts(md, &mectx_deform, dm, deformedVerts, numVerts);
}
else {
DerivedMesh *ndm;
@@ -2079,7 +2068,7 @@ static void mesh_calc_modifiers(
}
}
- ndm = modwrap_applyModifier(md, ob, dm, app_flags);
+ ndm = modwrap_applyModifier(md, &mectx_apply, dm);
ASSERT_IS_VALID_DM(ndm);
if (ndm) {
@@ -2106,7 +2095,7 @@ static void mesh_calc_modifiers(
(mti->requiredDataMask ?
mti->requiredDataMask(ob, md) : 0));
- ndm = modwrap_applyModifier(md, ob, orcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
+ ndm = modwrap_applyModifier(md, &mectx_orco, orcodm);
ASSERT_IS_VALID_DM(ndm);
if (ndm) {
@@ -2124,7 +2113,7 @@ static void mesh_calc_modifiers(
nextmask &= ~CD_MASK_CLOTH_ORCO;
DM_set_only_copy(clothorcodm, nextmask | CD_MASK_ORIGINDEX);
- ndm = modwrap_applyModifier(md, ob, clothorcodm, (app_flags & ~MOD_APPLY_USECACHE) | MOD_APPLY_ORCO);
+ ndm = modwrap_applyModifier(md, &mectx_orco, clothorcodm);
ASSERT_IS_VALID_DM(ndm);
if (ndm) {
@@ -2244,20 +2233,6 @@ static void mesh_calc_modifiers(
CustomData_free_layers(&finaldm->loopData, CD_NORMAL, finaldm->numLoopData);
}
-#ifdef WITH_GAMEENGINE
- /* NavMesh - this is a hack but saves having a NavMesh modifier */
- if ((ob->gameflag & OB_NAVMESH) && (finaldm->type == DM_TYPE_CDDM)) {
- DerivedMesh *tdm;
- tdm = navmesh_dm_createNavMeshForVisualization(finaldm);
- if (finaldm != tdm) {
- finaldm->release(finaldm);
- finaldm = tdm;
- }
-
- DM_ensure_tessface(finaldm);
- }
-#endif /* WITH_GAMEENGINE */
-
*r_final = finaldm;
if (orcodm)
@@ -2307,8 +2282,8 @@ bool editbmesh_modifier_is_enabled(Scene *scene, ModifierData *md, DerivedMesh *
}
static void editbmesh_calc_modifiers(
- Scene *scene, Object *ob, BMEditMesh *em,
- CustomDataMask dataMask,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob,
+ BMEditMesh *em, CustomDataMask dataMask,
/* return args */
DerivedMesh **r_cage, DerivedMesh **r_final)
{
@@ -2332,6 +2307,11 @@ static void editbmesh_calc_modifiers(
const bool do_mod_wmcol = do_init_wmcol;
VirtualModifierData virtualModifierData;
+ /* TODO(sybren): do we really need multiple objects, or shall we change the flags where needed? */
+ const ModifierEvalContext mectx = {depsgraph, ob, 0};
+ const ModifierEvalContext mectx_orco = {depsgraph, ob, MOD_APPLY_ORCO};
+ const ModifierEvalContext mectx_cache_gpu = {depsgraph, ob, MOD_APPLY_USECACHE | MOD_APPLY_ALLOW_GPU};
+
const bool do_loop_normals = (((Mesh *)(ob->data))->flag & ME_AUTOSMOOTH) != 0;
const float loop_normals_split_angle = ((Mesh *)(ob->data))->smoothresh;
@@ -2394,10 +2374,10 @@ static void editbmesh_calc_modifiers(
}
}
- if (mti->deformVertsEM)
- modwrap_deformVertsEM(md, ob, em, dm, deformedVerts, numVerts);
+ if (mti->deformVertsEM || mti->deformVertsEM_DM)
+ modwrap_deformVertsEM(md, &mectx, em, dm, deformedVerts, numVerts);
else
- modwrap_deformVerts(md, ob, dm, deformedVerts, numVerts, 0);
+ modwrap_deformVerts(md, &mectx, dm, deformedVerts, numVerts);
}
else {
DerivedMesh *ndm;
@@ -2441,11 +2421,11 @@ static void editbmesh_calc_modifiers(
mask &= ~CD_MASK_ORCO;
DM_set_only_copy(orcodm, mask | CD_MASK_ORIGINDEX);
- if (mti->applyModifierEM) {
- ndm = modwrap_applyModifierEM(md, ob, em, orcodm, MOD_APPLY_ORCO);
+ if (mti->applyModifierEM || mti->applyModifierEM_DM) {
+ ndm = modwrap_applyModifierEM(md, &mectx_orco, em, orcodm);
}
else {
- ndm = modwrap_applyModifier(md, ob, orcodm, MOD_APPLY_ORCO);
+ ndm = modwrap_applyModifier(md, &mectx_orco, orcodm);
}
ASSERT_IS_VALID_DM(ndm);
@@ -2469,10 +2449,10 @@ static void editbmesh_calc_modifiers(
}
}
- if (mti->applyModifierEM)
- ndm = modwrap_applyModifierEM(md, ob, em, dm, MOD_APPLY_USECACHE | MOD_APPLY_ALLOW_GPU);
+ if (mti->applyModifierEM || mti->applyModifierEM_DM)
+ ndm = modwrap_applyModifierEM(md, &mectx_cache_gpu, em, dm);
else
- ndm = modwrap_applyModifier(md, ob, dm, MOD_APPLY_USECACHE | MOD_APPLY_ALLOW_GPU);
+ ndm = modwrap_applyModifier(md, &mectx_cache_gpu, dm);
ASSERT_IS_VALID_DM(ndm);
if (ndm) {
@@ -2505,6 +2485,11 @@ static void editbmesh_calc_modifiers(
*r_cage = dm;
}
else {
+ struct Mesh *mesh = ob->data;
+ if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) {
+ BKE_mesh_ensure_edit_data(mesh);
+ mesh->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts);
+ }
*r_cage = getEditDerivedBMesh(
em, ob, mask,
deformedVerts ? MEM_dupallocN(deformedVerts) : NULL);
@@ -2542,6 +2527,13 @@ static void editbmesh_calc_modifiers(
}
else {
/* this is just a copy of the editmesh, no need to calc normals */
+ struct Mesh *mesh = ob->data;
+ if (mesh->id.tag & LIB_TAG_COPY_ON_WRITE) {
+ BKE_mesh_ensure_edit_data(mesh);
+ if (mesh->runtime.edit_data->vertexCos != NULL)
+ MEM_freeN((void *)mesh->runtime.edit_data->vertexCos);
+ mesh->runtime.edit_data->vertexCos = MEM_dupallocN(deformedVerts);
+ }
*r_final = getEditDerivedBMesh(em, ob, dataMask, deformedVerts);
deformedVerts = NULL;
@@ -2608,7 +2600,8 @@ static void editbmesh_calc_modifiers(
* we'll be using GPU backend of OpenSubdiv. This is so
* playback performance is kept as high as possible.
*/
-static bool calc_modifiers_skip_orco(Scene *scene,
+static bool calc_modifiers_skip_orco(Depsgraph *depsgraph,
+ Scene *scene,
Object *ob,
bool use_render_params)
{
@@ -2624,7 +2617,7 @@ static bool calc_modifiers_skip_orco(Scene *scene,
else if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) {
return false;
}
- else if ((DAG_get_eval_flags_for_object(scene, ob) & DAG_EVAL_NEED_CPU) != 0) {
+ else if ((DEG_get_eval_flags_for_id(depsgraph, &ob->id) & DAG_EVAL_NEED_CPU) != 0) {
return false;
}
SubsurfModifierData *smd = (SubsurfModifierData *)last_md;
@@ -2636,7 +2629,7 @@ static bool calc_modifiers_skip_orco(Scene *scene,
#endif
static void mesh_build_data(
- Scene *scene, Object *ob, CustomDataMask dataMask,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask,
const bool build_shapekey_layers, const bool need_mapping)
{
BLI_assert(ob->type == OB_MESH);
@@ -2645,13 +2638,13 @@ static void mesh_build_data(
BKE_object_sculpt_modifiers_changed(ob);
#ifdef WITH_OPENSUBDIV
- if (calc_modifiers_skip_orco(scene, ob, false)) {
+ if (calc_modifiers_skip_orco(depsgraph, scene, ob, false)) {
dataMask &= ~(CD_MASK_ORCO | CD_MASK_PREVIEW_MCOL);
}
#endif
mesh_calc_modifiers(
- scene, ob, NULL, false, 1, need_mapping, dataMask, -1, true, build_shapekey_layers,
+ depsgraph, scene, ob, NULL, false, 1, need_mapping, dataMask, -1, true, build_shapekey_layers,
true,
&ob->derivedDeform, &ob->derivedFinal);
@@ -2666,13 +2659,15 @@ static void mesh_build_data(
/* create PBVH immediately (would be created on the fly too,
* but this avoids waiting on first stroke) */
- BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, false, false);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, false, false);
}
BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS));
}
-static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
+static void editbmesh_build_data(
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
{
BKE_object_free_derived_caches(obedit);
BKE_object_sculpt_modifiers_changed(obedit);
@@ -2680,13 +2675,13 @@ static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, C
BKE_editmesh_free_derivedmesh(em);
#ifdef WITH_OPENSUBDIV
- if (calc_modifiers_skip_orco(scene, obedit, false)) {
+ if (calc_modifiers_skip_orco(depsgraph, scene, obedit, false)) {
dataMask &= ~(CD_MASK_ORCO | CD_MASK_PREVIEW_MCOL);
}
#endif
editbmesh_calc_modifiers(
- scene, obedit, em, dataMask,
+ depsgraph, scene, obedit, em, dataMask,
&em->derivedCage, &em->derivedFinal);
DM_set_object_boundbox(obedit, em->derivedFinal);
@@ -2698,9 +2693,10 @@ static void editbmesh_build_data(Scene *scene, Object *obedit, BMEditMesh *em, C
BLI_assert(!(em->derivedFinal->dirty & DM_DIRTY_NORMALS));
}
-static CustomDataMask object_get_datamask(const Scene *scene, Object *ob, bool *r_need_mapping)
+static CustomDataMask object_get_datamask(const Depsgraph *depsgraph, Object *ob, bool *r_need_mapping)
{
- Object *actob = scene->basact ? scene->basact->object : NULL;
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ Object *actob = view_layer->basact ? view_layer->basact->object : NULL;
CustomDataMask mask = ob->customdata_mask;
if (r_need_mapping) {
@@ -2737,85 +2733,86 @@ static CustomDataMask object_get_datamask(const Scene *scene, Object *ob, bool *
}
void makeDerivedMesh(
- Scene *scene, Object *ob, BMEditMesh *em,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em,
CustomDataMask dataMask, const bool build_shapekey_layers)
{
bool need_mapping;
- dataMask |= object_get_datamask(scene, ob, &need_mapping);
+ dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
if (em) {
- editbmesh_build_data(scene, ob, em, dataMask);
+ editbmesh_build_data(depsgraph, scene, ob, em, dataMask);
}
else {
- mesh_build_data(scene, ob, dataMask, build_shapekey_layers, need_mapping);
+ mesh_build_data(depsgraph, scene, ob, dataMask, build_shapekey_layers, need_mapping);
}
}
/***/
-DerivedMesh *mesh_get_derived_final(Scene *scene, Object *ob, CustomDataMask dataMask)
+DerivedMesh *mesh_get_derived_final(
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
{
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
bool need_mapping;
- dataMask |= object_get_datamask(scene, ob, &need_mapping);
+ dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
if (!ob->derivedFinal ||
((dataMask & ob->lastDataMask) != dataMask) ||
(need_mapping != ob->lastNeedMapping))
{
- mesh_build_data(scene, ob, dataMask, false, need_mapping);
+ mesh_build_data(depsgraph, scene, ob, dataMask, false, need_mapping);
}
if (ob->derivedFinal) { BLI_assert(!(ob->derivedFinal->dirty & DM_DIRTY_NORMALS)); }
return ob->derivedFinal;
}
-DerivedMesh *mesh_get_derived_deform(Scene *scene, Object *ob, CustomDataMask dataMask)
+DerivedMesh *mesh_get_derived_deform(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
{
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
bool need_mapping;
- dataMask |= object_get_datamask(scene, ob, &need_mapping);
+ dataMask |= object_get_datamask(depsgraph, ob, &need_mapping);
if (!ob->derivedDeform ||
((dataMask & ob->lastDataMask) != dataMask) ||
(need_mapping != ob->lastNeedMapping))
{
- mesh_build_data(scene, ob, dataMask, false, need_mapping);
+ mesh_build_data(depsgraph, scene, ob, dataMask, false, need_mapping);
}
return ob->derivedDeform;
}
-DerivedMesh *mesh_create_derived_render(Scene *scene, Object *ob, CustomDataMask dataMask)
+DerivedMesh *mesh_create_derived_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask)
{
DerivedMesh *final;
mesh_calc_modifiers(
- scene, ob, NULL, true, 1, false, dataMask, -1, false, false, false,
+ depsgraph, scene, ob, NULL, true, 1, false, dataMask, -1, false, false, false,
NULL, &final);
return final;
}
-DerivedMesh *mesh_create_derived_index_render(Scene *scene, Object *ob, CustomDataMask dataMask, int index)
+DerivedMesh *mesh_create_derived_index_render(struct Depsgraph *depsgraph, Scene *scene, Object *ob, CustomDataMask dataMask, int index)
{
DerivedMesh *final;
mesh_calc_modifiers(
- scene, ob, NULL, true, 1, false, dataMask, index, false, false, false,
+ depsgraph, scene, ob, NULL, true, 1, false, dataMask, index, false, false, false,
NULL, &final);
return final;
}
DerivedMesh *mesh_create_derived_view(
- Scene *scene, Object *ob,
- CustomDataMask dataMask)
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, CustomDataMask dataMask)
{
DerivedMesh *final;
@@ -2826,7 +2823,7 @@ DerivedMesh *mesh_create_derived_view(
ob->transflag |= OB_NO_PSYS_UPDATE;
mesh_calc_modifiers(
- scene, ob, NULL, false, 1, false, dataMask, -1, false, false, false,
+ depsgraph, scene, ob, NULL, false, 1, false, dataMask, -1, false, false, false,
NULL, &final);
ob->transflag &= ~OB_NO_PSYS_UPDATE;
@@ -2835,53 +2832,27 @@ DerivedMesh *mesh_create_derived_view(
}
DerivedMesh *mesh_create_derived_no_deform(
- Scene *scene, Object *ob, float (*vertCos)[3],
- CustomDataMask dataMask)
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob,
+ float (*vertCos)[3], CustomDataMask dataMask)
{
DerivedMesh *final;
mesh_calc_modifiers(
- scene, ob, vertCos, false, 0, false, dataMask, -1, false, false, false,
- NULL, &final);
-
- return final;
-}
-
-DerivedMesh *mesh_create_derived_no_virtual(
- Scene *scene, Object *ob, float (*vertCos)[3],
- CustomDataMask dataMask)
-{
- DerivedMesh *final;
-
- mesh_calc_modifiers(
- scene, ob, vertCos, false, -1, false, dataMask, -1, false, false, false,
- NULL, &final);
-
- return final;
-}
-
-DerivedMesh *mesh_create_derived_physics(
- Scene *scene, Object *ob, float (*vertCos)[3],
- CustomDataMask dataMask)
-{
- DerivedMesh *final;
-
- mesh_calc_modifiers(
- scene, ob, vertCos, false, -1, true, dataMask, -1, false, false, false,
+ depsgraph, scene, ob, vertCos, false, 0, false, dataMask, -1, false, false, false,
NULL, &final);
return final;
}
DerivedMesh *mesh_create_derived_no_deform_render(
- Scene *scene, Object *ob,
- float (*vertCos)[3],
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, float (*vertCos)[3],
CustomDataMask dataMask)
{
DerivedMesh *final;
mesh_calc_modifiers(
- scene, ob, vertCos, true, 0, false, dataMask, -1, false, false, false,
+ depsgraph, scene, ob, vertCos, true, 0, false, dataMask, -1, false, false, false,
NULL, &final);
return final;
@@ -2890,7 +2861,7 @@ DerivedMesh *mesh_create_derived_no_deform_render(
/***/
DerivedMesh *editbmesh_get_derived_cage_and_final(
- Scene *scene, Object *obedit, BMEditMesh *em,
+ struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em,
CustomDataMask dataMask,
/* return args */
DerivedMesh **r_final)
@@ -2898,12 +2869,12 @@ DerivedMesh *editbmesh_get_derived_cage_and_final(
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
- dataMask |= object_get_datamask(scene, obedit, NULL);
+ dataMask |= object_get_datamask(depsgraph, obedit, NULL);
if (!em->derivedCage ||
(em->lastDataMask & dataMask) != dataMask)
{
- editbmesh_build_data(scene, obedit, em, dataMask);
+ editbmesh_build_data(depsgraph, scene, obedit, em, dataMask);
}
*r_final = em->derivedFinal;
@@ -2911,17 +2882,19 @@ DerivedMesh *editbmesh_get_derived_cage_and_final(
return em->derivedCage;
}
-DerivedMesh *editbmesh_get_derived_cage(Scene *scene, Object *obedit, BMEditMesh *em, CustomDataMask dataMask)
+DerivedMesh *editbmesh_get_derived_cage(
+ struct Depsgraph *depsgraph, Scene *scene, Object *obedit, BMEditMesh *em,
+ CustomDataMask dataMask)
{
/* if there's no derived mesh or the last data mask used doesn't include
* the data we need, rebuild the derived mesh
*/
- dataMask |= object_get_datamask(scene, obedit, NULL);
+ dataMask |= object_get_datamask(depsgraph, obedit, NULL);
if (!em->derivedCage ||
(em->lastDataMask & dataMask) != dataMask)
{
- editbmesh_build_data(scene, obedit, em, dataMask);
+ editbmesh_build_data(depsgraph, scene, obedit, em, dataMask);
}
return em->derivedCage;
@@ -3056,271 +3029,6 @@ void mesh_get_mapped_verts_coords(DerivedMesh *dm, float (*r_cos)[3], const int
}
}
-/* ******************* GLSL ******************** */
-
-/** \name Tangent Space Calculation
- * \{ */
-
-/* Necessary complexity to handle looptri's as quads for correct tangents */
-#define USE_LOOPTRI_DETECT_QUADS
-
-typedef struct {
- float (*precomputedFaceNormals)[3];
- float (*precomputedLoopNormals)[3];
- const MLoopTri *looptri;
- MLoopUV *mloopuv; /* texture coordinates */
- MPoly *mpoly; /* indices */
- MLoop *mloop; /* indices */
- MVert *mvert; /* vertices & normals */
- float (*orco)[3];
- float (*tangent)[4]; /* destination */
- int numTessFaces;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- /* map from 'fake' face index to looptri,
- * quads will point to the first looptri of the quad */
- const int *face_as_quad_map;
- int num_face_as_quad_map;
-#endif
-
-} SGLSLMeshToTangent;
-
-/* interface */
-#include "mikktspace.h"
-
-static int dm_ts_GetNumFaces(const SMikkTSpaceContext *pContext)
-{
- SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- return pMesh->num_face_as_quad_map;
-#else
- return pMesh->numTessFaces;
-#endif
-}
-
-static int dm_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
-{
-#ifdef USE_LOOPTRI_DETECT_QUADS
- SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
- if (pMesh->face_as_quad_map) {
- const MLoopTri *lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
- const MPoly *mp = &pMesh->mpoly[lt->poly];
- if (mp->totloop == 4) {
- return 4;
- }
- }
- return 3;
-#else
- UNUSED_VARS(pContext, face_num);
- return 3;
-#endif
-}
-
-static void dm_ts_GetPosition(
- const SMikkTSpaceContext *pContext, float r_co[3],
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
- const MLoopTri *lt;
- int loop_index;
- const float *co;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
- const MPoly *mp = &pMesh->mpoly[lt->poly];
- if (mp->totloop == 4) {
- loop_index = mp->loopstart + vert_index;
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = &pMesh->looptri[face_num];
- }
-#else
- lt = &pMesh->looptri[face_num];
-#endif
- loop_index = lt->tri[vert_index];
-
-finally:
- co = pMesh->mvert[pMesh->mloop[loop_index].v].co;
- copy_v3_v3(r_co, co);
-}
-
-static void dm_ts_GetTextureCoordinate(
- const SMikkTSpaceContext *pContext, float r_uv[2],
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
- const MLoopTri *lt;
- int loop_index;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
- const MPoly *mp = &pMesh->mpoly[lt->poly];
- if (mp->totloop == 4) {
- loop_index = mp->loopstart + vert_index;
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = &pMesh->looptri[face_num];
- }
-#else
- lt = &pMesh->looptri[face_num];
-#endif
- loop_index = lt->tri[vert_index];
-
-finally:
- if (pMesh->mloopuv != NULL) {
- const float *uv = pMesh->mloopuv[loop_index].uv;
- copy_v2_v2(r_uv, uv);
- }
- else {
- const float *orco = pMesh->orco[pMesh->mloop[loop_index].v];
- map_to_sphere(&r_uv[0], &r_uv[1], orco[0], orco[1], orco[2]);
- }
-}
-
-static void dm_ts_GetNormal(
- const SMikkTSpaceContext *pContext, float r_no[3],
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
- const MLoopTri *lt;
- int loop_index;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
- const MPoly *mp = &pMesh->mpoly[lt->poly];
- if (mp->totloop == 4) {
- loop_index = mp->loopstart + vert_index;
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = &pMesh->looptri[face_num];
- }
-#else
- lt = &pMesh->looptri[face_num];
-#endif
- loop_index = lt->tri[vert_index];
-
-finally:
- if (pMesh->precomputedLoopNormals) {
- copy_v3_v3(r_no, pMesh->precomputedLoopNormals[loop_index]);
- }
- else if ((pMesh->mpoly[lt->poly].flag & ME_SMOOTH) == 0) { /* flat */
- if (pMesh->precomputedFaceNormals) {
- copy_v3_v3(r_no, pMesh->precomputedFaceNormals[lt->poly]);
- }
- else {
-#ifdef USE_LOOPTRI_DETECT_QUADS
- const MPoly *mp = &pMesh->mpoly[lt->poly];
- if (mp->totloop == 4) {
- normal_quad_v3(
- r_no,
- pMesh->mvert[pMesh->mloop[mp->loopstart + 0].v].co,
- pMesh->mvert[pMesh->mloop[mp->loopstart + 1].v].co,
- pMesh->mvert[pMesh->mloop[mp->loopstart + 2].v].co,
- pMesh->mvert[pMesh->mloop[mp->loopstart + 3].v].co);
- }
- else
-#endif
- {
- normal_tri_v3(
- r_no,
- pMesh->mvert[pMesh->mloop[lt->tri[0]].v].co,
- pMesh->mvert[pMesh->mloop[lt->tri[1]].v].co,
- pMesh->mvert[pMesh->mloop[lt->tri[2]].v].co);
- }
- }
- }
- else {
- const short *no = pMesh->mvert[pMesh->mloop[loop_index].v].no;
- normal_short_to_float_v3(r_no, no);
- }
-}
-
-static void dm_ts_SetTSpace(
- const SMikkTSpaceContext *pContext, const float fvTangent[3], const float fSign,
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
- const MLoopTri *lt;
- int loop_index;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
- const MPoly *mp = &pMesh->mpoly[lt->poly];
- if (mp->totloop == 4) {
- loop_index = mp->loopstart + vert_index;
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = &pMesh->looptri[face_num];
- }
-#else
- lt = &pMesh->looptri[face_num];
-#endif
- loop_index = lt->tri[vert_index];
-
- float *pRes;
-
-finally:
- pRes = pMesh->tangent[loop_index];
- copy_v3_v3(pRes, fvTangent);
- pRes[3] = fSign;
-}
-
-void DM_calc_tangents_names_from_gpu(
- const GPUVertexAttribs *gattribs,
- char (*tangent_names)[MAX_NAME], int *r_tangent_names_count)
-{
- int count = 0;
- for (int b = 0; b < gattribs->totlayer; b++) {
- if (gattribs->layer[b].type == CD_TANGENT) {
- strcpy(tangent_names[count++], gattribs->layer[b].name);
- }
- }
- *r_tangent_names_count = count;
-}
-
-static void DM_calc_loop_tangents_thread(TaskPool * __restrict UNUSED(pool), void *taskdata, int UNUSED(threadid))
-{
- struct SGLSLMeshToTangent *mesh2tangent = taskdata;
- /* new computation method */
- {
- SMikkTSpaceContext sContext = {NULL};
- SMikkTSpaceInterface sInterface = {NULL};
-
- sContext.m_pUserData = mesh2tangent;
- sContext.m_pInterface = &sInterface;
- sInterface.m_getNumFaces = dm_ts_GetNumFaces;
- sInterface.m_getNumVerticesOfFace = dm_ts_GetNumVertsOfFace;
- sInterface.m_getPosition = dm_ts_GetPosition;
- sInterface.m_getTexCoord = dm_ts_GetTextureCoordinate;
- sInterface.m_getNormal = dm_ts_GetNormal;
- sInterface.m_setTSpaceBasic = dm_ts_SetTSpace;
-
- /* 0 if failed */
- genTangSpaceDefault(&sContext);
- }
-}
-
void DM_add_named_tangent_layer_for_uv(
CustomData *uv_data, CustomData *tan_data, int numLoopData,
const char *layer_name)
@@ -3334,602 +3042,24 @@ void DM_add_named_tangent_layer_for_uv(
}
}
-/**
- * Here we get some useful information such as active uv layer name and search if it is already in tangent_names.
- * Also, we calculate tangent_mask that works as a descriptor of tangents state.
- * If tangent_mask has changed, then recalculate tangents.
- */
-void DM_calc_loop_tangents_step_0(
- const CustomData *loopData, bool calc_active_tangent,
- const char (*tangent_names)[MAX_NAME], int tangent_names_count,
- bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
- char *ract_uv_name, char *rren_uv_name, short *rtangent_mask)
-{
- /* Active uv in viewport */
- int layer_index = CustomData_get_layer_index(loopData, CD_MLOOPUV);
- *ract_uv_n = CustomData_get_active_layer(loopData, CD_MLOOPUV);
- ract_uv_name[0] = 0;
- if (*ract_uv_n != -1) {
- strcpy(ract_uv_name, loopData->layers[*ract_uv_n + layer_index].name);
- }
-
- /* Active tangent in render */
- *rren_uv_n = CustomData_get_render_layer(loopData, CD_MLOOPUV);
- rren_uv_name[0] = 0;
- if (*rren_uv_n != -1) {
- strcpy(rren_uv_name, loopData->layers[*rren_uv_n + layer_index].name);
- }
-
- /* If active tangent not in tangent_names we take it into account */
- *rcalc_act = false;
- *rcalc_ren = false;
- for (int i = 0; i < tangent_names_count; i++) {
- if (tangent_names[i][0] == 0) {
- calc_active_tangent = true;
- }
- }
- if (calc_active_tangent) {
- *rcalc_act = true;
- *rcalc_ren = true;
- for (int i = 0; i < tangent_names_count; i++) {
- if (STREQ(ract_uv_name, tangent_names[i]))
- *rcalc_act = false;
- if (STREQ(rren_uv_name, tangent_names[i]))
- *rcalc_ren = false;
- }
- }
- *rtangent_mask = 0;
-
- const int uv_layer_num = CustomData_number_of_layers(loopData, CD_MLOOPUV);
- for (int n = 0; n < uv_layer_num; n++) {
- const char *name = CustomData_get_layer_name(loopData, CD_MLOOPUV, n);
- bool add = false;
- for (int i = 0; i < tangent_names_count; i++) {
- if (tangent_names[i][0] && STREQ(tangent_names[i], name)) {
- add = true;
- break;
- }
- }
- if ((*rcalc_act && ract_uv_name[0] && STREQ(ract_uv_name, name)) ||
- (*rcalc_ren && rren_uv_name[0] && STREQ(rren_uv_name, name)))
- {
- add = true;
- }
- if (add)
- *rtangent_mask |= 1 << n;
- }
-
- if (uv_layer_num == 0)
- *rtangent_mask |= DM_TANGENT_MASK_ORCO;
-}
-
void DM_calc_loop_tangents(
DerivedMesh *dm, bool calc_active_tangent,
- const char (*tangent_names)[MAX_NAME], int tangent_names_count)
-{
- int act_uv_n = -1;
- int ren_uv_n = -1;
- bool calc_act = false;
- bool calc_ren = false;
- char act_uv_name[MAX_NAME];
- char ren_uv_name[MAX_NAME];
- short tangent_mask = 0;
- DM_calc_loop_tangents_step_0(
- &dm->loopData, calc_active_tangent, tangent_names, tangent_names_count,
- &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
- if ((dm->tangent_mask | tangent_mask) != dm->tangent_mask) {
- /* Check we have all the needed layers */
- MPoly *mpoly = dm->getPolyArray(dm);
- const MLoopTri *looptri = dm->getLoopTriArray(dm);
- int totface = dm->getNumLoopTri(dm);
- /* Allocate needed tangent layers */
- for (int i = 0; i < tangent_names_count; i++)
- if (tangent_names[i][0])
- DM_add_named_tangent_layer_for_uv(&dm->loopData, &dm->loopData, dm->numLoopData, tangent_names[i]);
- if ((tangent_mask & DM_TANGENT_MASK_ORCO) && CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, "") == -1)
- CustomData_add_layer_named(&dm->loopData, CD_TANGENT, CD_CALLOC, NULL, dm->numLoopData, "");
- if (calc_act && act_uv_name[0])
- DM_add_named_tangent_layer_for_uv(&dm->loopData, &dm->loopData, dm->numLoopData, act_uv_name);
- if (calc_ren && ren_uv_name[0])
- DM_add_named_tangent_layer_for_uv(&dm->loopData, &dm->loopData, dm->numLoopData, ren_uv_name);
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- int num_face_as_quad_map;
- int *face_as_quad_map = NULL;
-
- /* map faces to quads */
- if (totface != dm->getNumPolys(dm)) {
- /* over alloc, since we dont know how many ngon or quads we have */
-
- /* map fake face index to looptri */
- face_as_quad_map = MEM_malloc_arrayN(totface, sizeof(int), __func__);
- int k, j;
- for (k = 0, j = 0; j < totface; k++, j++) {
- face_as_quad_map[k] = j;
- /* step over all quads */
- if (mpoly[looptri[j].poly].totloop == 4) {
- j++; /* skips the nest looptri */
- }
- }
- num_face_as_quad_map = k;
- }
- else {
- num_face_as_quad_map = totface;
- }
-#endif
-
- /* Calculation */
- {
- TaskScheduler *scheduler = BLI_task_scheduler_get();
- TaskPool *task_pool;
- task_pool = BLI_task_pool_create(scheduler, NULL);
-
- dm->tangent_mask = 0;
- /* Calculate tangent layers */
- SGLSLMeshToTangent data_array[MAX_MTFACE];
- const int tangent_layer_num = CustomData_number_of_layers(&dm->loopData, CD_TANGENT);
- for (int n = 0; n < tangent_layer_num; n++) {
- int index = CustomData_get_layer_index_n(&dm->loopData, CD_TANGENT, n);
- BLI_assert(n < MAX_MTFACE);
- SGLSLMeshToTangent *mesh2tangent = &data_array[n];
- mesh2tangent->numTessFaces = totface;
-#ifdef USE_LOOPTRI_DETECT_QUADS
- mesh2tangent->face_as_quad_map = face_as_quad_map;
- mesh2tangent->num_face_as_quad_map = num_face_as_quad_map;
-#endif
- mesh2tangent->mvert = dm->getVertArray(dm);
- mesh2tangent->mpoly = dm->getPolyArray(dm);
- mesh2tangent->mloop = dm->getLoopArray(dm);
- mesh2tangent->looptri = dm->getLoopTriArray(dm);
- /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
- * have to check this is valid...
- */
- mesh2tangent->precomputedLoopNormals = dm->getLoopDataArray(dm, CD_NORMAL);
- mesh2tangent->precomputedFaceNormals = CustomData_get_layer(&dm->polyData, CD_NORMAL);
-
- mesh2tangent->orco = NULL;
- mesh2tangent->mloopuv = CustomData_get_layer_named(&dm->loopData, CD_MLOOPUV, dm->loopData.layers[index].name);
-
- /* Fill the resulting tangent_mask */
- if (!mesh2tangent->mloopuv) {
- mesh2tangent->orco = dm->getVertDataArray(dm, CD_ORCO);
- if (!mesh2tangent->orco)
- continue;
-
- dm->tangent_mask |= DM_TANGENT_MASK_ORCO;
- }
- else {
- int uv_ind = CustomData_get_named_layer_index(&dm->loopData, CD_MLOOPUV, dm->loopData.layers[index].name);
- int uv_start = CustomData_get_layer_index(&dm->loopData, CD_MLOOPUV);
- BLI_assert(uv_ind != -1 && uv_start != -1);
- BLI_assert(uv_ind - uv_start < MAX_MTFACE);
- dm->tangent_mask |= 1 << (uv_ind - uv_start);
- }
-
- mesh2tangent->tangent = dm->loopData.layers[index].data;
- BLI_task_pool_push(task_pool, DM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW);
- }
-
- BLI_assert(dm->tangent_mask == tangent_mask);
- BLI_task_pool_work_and_wait(task_pool);
- BLI_task_pool_free(task_pool);
- }
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (face_as_quad_map) {
- MEM_freeN(face_as_quad_map);
- }
-#undef USE_LOOPTRI_DETECT_QUADS
-
-#endif
-
- /* Update active layer index */
- int act_uv_index = CustomData_get_layer_index_n(&dm->loopData, CD_MLOOPUV, act_uv_n);
- if (act_uv_index != -1) {
- int tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, dm->loopData.layers[act_uv_index].name);
- CustomData_set_layer_active_index(&dm->loopData, CD_TANGENT, tan_index);
- } /* else tangent has been built from orco */
-
- /* Update render layer index */
- int ren_uv_index = CustomData_get_layer_index_n(&dm->loopData, CD_MLOOPUV, ren_uv_n);
- if (ren_uv_index != -1) {
- int tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, dm->loopData.layers[ren_uv_index].name);
- CustomData_set_layer_render_index(&dm->loopData, CD_TANGENT, tan_index);
- } /* else tangent has been built from orco */
- }
-}
-
-/** \} */
-
-
-void DM_calc_auto_bump_scale(DerivedMesh *dm)
+ const char (*tangent_names)[MAX_NAME], int tangent_names_len)
{
- /* int totvert = dm->getNumVerts(dm); */ /* UNUSED */
- int totface = dm->getNumTessFaces(dm);
-
- MVert *mvert = dm->getVertArray(dm);
- MFace *mface = dm->getTessFaceArray(dm);
- MTFace *mtface = dm->getTessFaceDataArray(dm, CD_MTFACE);
-
- if (mtface) {
- double dsum = 0.0;
- int nr_accumulated = 0;
- int f;
-
- for (f = 0; f < totface; f++) {
- {
- float *verts[4], *tex_coords[4];
- const int nr_verts = mface[f].v4 != 0 ? 4 : 3;
- bool is_degenerate;
- int i;
-
- verts[0] = mvert[mface[f].v1].co; verts[1] = mvert[mface[f].v2].co; verts[2] = mvert[mface[f].v3].co;
- tex_coords[0] = mtface[f].uv[0]; tex_coords[1] = mtface[f].uv[1]; tex_coords[2] = mtface[f].uv[2];
- if (nr_verts == 4) {
- verts[3] = mvert[mface[f].v4].co;
- tex_coords[3] = mtface[f].uv[3];
- }
-
- /* discard degenerate faces */
- is_degenerate = 0;
- if (equals_v3v3(verts[0], verts[1]) ||
- equals_v3v3(verts[0], verts[2]) ||
- equals_v3v3(verts[1], verts[2]) ||
- equals_v2v2(tex_coords[0], tex_coords[1]) ||
- equals_v2v2(tex_coords[0], tex_coords[2]) ||
- equals_v2v2(tex_coords[1], tex_coords[2]))
- {
- is_degenerate = 1;
- }
-
- /* verify last vertex as well if this is a quad */
- if (is_degenerate == 0 && nr_verts == 4) {
- if (equals_v3v3(verts[3], verts[0]) ||
- equals_v3v3(verts[3], verts[1]) ||
- equals_v3v3(verts[3], verts[2]) ||
- equals_v2v2(tex_coords[3], tex_coords[0]) ||
- equals_v2v2(tex_coords[3], tex_coords[1]) ||
- equals_v2v2(tex_coords[3], tex_coords[2]))
- {
- is_degenerate = 1;
- }
-
- /* verify the winding is consistent */
- if (is_degenerate == 0) {
- float prev_edge[2];
- bool is_signed = 0;
- sub_v2_v2v2(prev_edge, tex_coords[0], tex_coords[3]);
-
- i = 0;
- while (is_degenerate == 0 && i < 4) {
- float cur_edge[2], signed_area;
- sub_v2_v2v2(cur_edge, tex_coords[(i + 1) & 0x3], tex_coords[i]);
- signed_area = cross_v2v2(prev_edge, cur_edge);
-
- if (i == 0) {
- is_signed = (signed_area < 0.0f) ? 1 : 0;
- }
- else if ((is_signed != 0) != (signed_area < 0.0f)) {
- is_degenerate = 1;
- }
-
- if (is_degenerate == 0) {
- copy_v2_v2(prev_edge, cur_edge);
- i++;
- }
- }
- }
- }
-
- /* proceed if not a degenerate face */
- if (is_degenerate == 0) {
- int nr_tris_to_pile = 0;
- /* quads split at shortest diagonal */
- int offs = 0; /* initial triangulation is 0,1,2 and 0, 2, 3 */
- if (nr_verts == 4) {
- float pos_len_diag0, pos_len_diag1;
-
- pos_len_diag0 = len_squared_v3v3(verts[2], verts[0]);
- pos_len_diag1 = len_squared_v3v3(verts[3], verts[1]);
-
- if (pos_len_diag1 < pos_len_diag0) {
- offs = 1; // alter split
- }
- else if (pos_len_diag0 == pos_len_diag1) { /* do UV check instead */
- float tex_len_diag0, tex_len_diag1;
-
- tex_len_diag0 = len_squared_v2v2(tex_coords[2], tex_coords[0]);
- tex_len_diag1 = len_squared_v2v2(tex_coords[3], tex_coords[1]);
-
- if (tex_len_diag1 < tex_len_diag0) {
- offs = 1; /* alter split */
- }
- }
- }
- nr_tris_to_pile = nr_verts - 2;
- if (nr_tris_to_pile == 1 || nr_tris_to_pile == 2) {
- const int indices[6] = {offs + 0, offs + 1, offs + 2, offs + 0, offs + 2, (offs + 3) & 0x3 };
- int t;
- for (t = 0; t < nr_tris_to_pile; t++) {
- float f2x_area_uv;
- const float *p0 = verts[indices[t * 3 + 0]];
- const float *p1 = verts[indices[t * 3 + 1]];
- const float *p2 = verts[indices[t * 3 + 2]];
-
- float edge_t0[2], edge_t1[2];
- sub_v2_v2v2(edge_t0, tex_coords[indices[t * 3 + 1]], tex_coords[indices[t * 3 + 0]]);
- sub_v2_v2v2(edge_t1, tex_coords[indices[t * 3 + 2]], tex_coords[indices[t * 3 + 0]]);
-
- f2x_area_uv = fabsf(cross_v2v2(edge_t0, edge_t1));
- if (f2x_area_uv > FLT_EPSILON) {
- float norm[3], v0[3], v1[3], f2x_surf_area, fsurf_ratio;
- sub_v3_v3v3(v0, p1, p0);
- sub_v3_v3v3(v1, p2, p0);
- cross_v3_v3v3(norm, v0, v1);
-
- f2x_surf_area = len_v3(norm);
- fsurf_ratio = f2x_surf_area / f2x_area_uv; /* tri area divided by texture area */
-
- nr_accumulated++;
- dsum += (double)(fsurf_ratio);
- }
- }
- }
- }
- }
- }
-
- /* finalize */
- {
- const float avg_area_ratio = (nr_accumulated > 0) ? ((float)(dsum / nr_accumulated)) : 1.0f;
- const float use_as_render_bump_scale = sqrtf(avg_area_ratio); // use width of average surface ratio as your bump scale
- dm->auto_bump_scale = use_as_render_bump_scale;
- }
- }
- else {
- dm->auto_bump_scale = 1.0f;
- }
-}
-
-void DM_vertex_attributes_from_gpu(DerivedMesh *dm, GPUVertexAttribs *gattribs, DMVertexAttribs *attribs)
-{
- CustomData *vdata, *ldata;
- int a, b, layer;
- const bool is_editmesh = (dm->type == DM_TYPE_EDITBMESH);
-
- /* From the layers requested by the GLSL shader, figure out which ones are
- * actually available for this derivedmesh, and retrieve the pointers */
-
- memset(attribs, 0, sizeof(DMVertexAttribs));
-
- vdata = &dm->vertData;
- ldata = dm->getLoopDataLayout(dm);
-
- /* calc auto bump scale if necessary */
- if (dm->auto_bump_scale <= 0.0f)
- DM_calc_auto_bump_scale(dm);
-
- char tangent_names[MAX_MTFACE][MAX_NAME];
- int tangent_names_count;
- /* Add a tangent layer/layers. */
- DM_calc_tangents_names_from_gpu(gattribs, tangent_names, &tangent_names_count);
-
- if (tangent_names_count)
- dm->calcLoopTangents(dm, false, (const char (*)[MAX_NAME])tangent_names, tangent_names_count);
-
- for (b = 0; b < gattribs->totlayer; b++) {
- int type = gattribs->layer[b].type;
- layer = -1;
- if (type == CD_AUTO_FROM_NAME) {
- /* We need to deduct what exact layer is used.
- *
- * We do it based on the specified name.
- */
- if (gattribs->layer[b].name[0]) {
- layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV, gattribs->layer[b].name);
- type = CD_MTFACE;
- if (layer == -1) {
- layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, gattribs->layer[b].name);
- type = CD_MCOL;
- }
- if (layer == -1) {
- layer = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, gattribs->layer[b].name);
- type = CD_TANGENT;
- }
- if (layer == -1) {
- continue;
- }
- }
- else {
- /* Fall back to the UV layer, which matches old behavior. */
- type = CD_MTFACE;
- }
- }
- if (type == CD_MTFACE) {
- /* uv coordinates */
- if (layer == -1) {
- if (gattribs->layer[b].name[0])
- layer = CustomData_get_named_layer_index(ldata, CD_MLOOPUV, gattribs->layer[b].name);
- else
- layer = CustomData_get_active_layer_index(ldata, CD_MLOOPUV);
- }
-
- a = attribs->tottface++;
-
- if (layer != -1) {
- attribs->tface[a].array = is_editmesh ? NULL : ldata->layers[layer].data;
- attribs->tface[a].em_offset = ldata->layers[layer].offset;
- }
- else {
- attribs->tface[a].array = NULL;
- attribs->tface[a].em_offset = -1;
- }
-
- attribs->tface[a].gl_index = gattribs->layer[b].glindex;
- attribs->tface[a].gl_info_index = gattribs->layer[b].glinfoindoex;
- attribs->tface[a].gl_texco = gattribs->layer[b].gltexco;
- }
- else if (type == CD_MCOL) {
- if (layer == -1) {
- if (gattribs->layer[b].name[0])
- layer = CustomData_get_named_layer_index(ldata, CD_MLOOPCOL, gattribs->layer[b].name);
- else
- layer = CustomData_get_active_layer_index(ldata, CD_MLOOPCOL);
- }
-
- a = attribs->totmcol++;
-
- if (layer != -1) {
- attribs->mcol[a].array = is_editmesh ? NULL : ldata->layers[layer].data;
- /* odd, store the offset for a different layer type here, but editmode draw code expects it */
- attribs->mcol[a].em_offset = ldata->layers[layer].offset;
- }
- else {
- attribs->mcol[a].array = NULL;
- attribs->mcol[a].em_offset = -1;
- }
-
- attribs->mcol[a].gl_index = gattribs->layer[b].glindex;
- attribs->mcol[a].gl_info_index = gattribs->layer[b].glinfoindoex;
- }
- else if (type == CD_TANGENT) {
- /* note, even with 'is_editmesh' this uses the derived-meshes loop data */
- if (layer == -1) {
- if (gattribs->layer[b].name[0])
- layer = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, gattribs->layer[b].name);
- else
- layer = CustomData_get_active_layer_index(&dm->loopData, CD_TANGENT);
- }
-
- a = attribs->tottang++;
-
- if (layer != -1) {
- attribs->tang[a].array = dm->loopData.layers[layer].data;
- attribs->tang[a].em_offset = dm->loopData.layers[layer].offset;
- }
- else {
- attribs->tang[a].array = NULL;
- attribs->tang[a].em_offset = -1;
- }
-
- attribs->tang[a].gl_index = gattribs->layer[b].glindex;
- attribs->tang[a].gl_info_index = gattribs->layer[b].glinfoindoex;
- }
- else if (type == CD_ORCO) {
- /* original coordinates */
- if (layer == -1) {
- layer = CustomData_get_layer_index(vdata, CD_ORCO);
- }
- attribs->totorco = 1;
-
- if (layer != -1) {
- attribs->orco.array = vdata->layers[layer].data;
- attribs->orco.em_offset = vdata->layers[layer].offset;
- }
- else {
- attribs->orco.array = NULL;
- attribs->orco.em_offset = -1;
- }
-
- attribs->orco.gl_index = gattribs->layer[b].glindex;
- attribs->orco.gl_texco = gattribs->layer[b].gltexco;
- attribs->orco.gl_info_index = gattribs->layer[b].glinfoindoex;
- }
- }
-}
-
-/**
- * Set vertex shader attribute inputs for a particular tessface vert
- *
- * \param a: tessface index
- * \param index: vertex index
- * \param vert: corner index (0, 1, 2, 3)
- * \param loop: absolute loop corner index
- */
-void DM_draw_attrib_vertex(DMVertexAttribs *attribs, int a, int index, int vert, int loop)
-{
- const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
- int b;
-
- UNUSED_VARS(a, vert);
-
- /* orco texture coordinates */
- if (attribs->totorco) {
- /*const*/ float (*array)[3] = attribs->orco.array;
- const float *orco = (array) ? array[index] : zero;
-
- if (attribs->orco.gl_texco)
- glTexCoord3fv(orco);
- else
- glVertexAttrib3fv(attribs->orco.gl_index, orco);
- }
-
- /* uv texture coordinates */
- for (b = 0; b < attribs->tottface; b++) {
- const float *uv;
-
- if (attribs->tface[b].array) {
- const MLoopUV *mloopuv = &attribs->tface[b].array[loop];
- uv = mloopuv->uv;
- }
- else {
- uv = zero;
- }
-
- if (attribs->tface[b].gl_texco)
- glTexCoord2fv(uv);
- else
- glVertexAttrib2fv(attribs->tface[b].gl_index, uv);
- }
-
- /* vertex colors */
- for (b = 0; b < attribs->totmcol; b++) {
- GLfloat col[4];
-
- if (attribs->mcol[b].array) {
- const MLoopCol *cp = &attribs->mcol[b].array[loop];
- rgba_uchar_to_float(col, &cp->r);
- }
- else {
- zero_v4(col);
- }
-
- glVertexAttrib4fv(attribs->mcol[b].gl_index, col);
- }
-
- /* tangent for normal mapping */
- for (b = 0; b < attribs->tottang; b++) {
- if (attribs->tang[b].array) {
- /*const*/ float (*array)[4] = attribs->tang[b].array;
- const float *tang = (array) ? array[loop] : zero;
- glVertexAttrib4fv(attribs->tang[b].gl_index, tang);
- }
- }
-}
-
-void DM_draw_attrib_vertex_uniforms(const DMVertexAttribs *attribs)
-{
- int i;
- if (attribs->totorco) {
- if (attribs->orco.gl_info_index != -1) {
- glUniform1i(attribs->orco.gl_info_index, 0);
- }
- }
- for (i = 0; i < attribs->tottface; i++) {
- if (attribs->tface[i].gl_info_index != -1) {
- glUniform1i(attribs->tface[i].gl_info_index, 0);
- }
- }
- for (i = 0; i < attribs->totmcol; i++) {
- if (attribs->mcol[i].gl_info_index != -1) {
- glUniform1i(attribs->mcol[i].gl_info_index, GPU_ATTR_INFO_SRGB);
- }
- }
-
- for (i = 0; i < attribs->tottang; i++) {
- if (attribs->tang[i].gl_info_index != -1) {
- glUniform1i(attribs->tang[i].gl_info_index, 0);
- }
- }
+ BKE_mesh_calc_loop_tangent_ex(
+ dm->getVertArray(dm),
+ dm->getPolyArray(dm), dm->getNumPolys(dm),
+ dm->getLoopArray(dm),
+ dm->getLoopTriArray(dm), dm->getNumLoopTri(dm),
+ &dm->loopData,
+ calc_active_tangent,
+ tangent_names, tangent_names_len,
+ CustomData_get_layer(&dm->polyData, CD_NORMAL),
+ dm->getLoopDataArray(dm, CD_NORMAL),
+ dm->getVertDataArray(dm, CD_ORCO), /* may be NULL */
+ /* result */
+ &dm->loopData, dm->getNumLoops(dm),
+ &dm->tangent_mask);
}
/* Set object's bounding box based on DerivedMesh min/max data */
@@ -3948,181 +3078,6 @@ void DM_set_object_boundbox(Object *ob, DerivedMesh *dm)
ob->bb->flag &= ~BOUNDBOX_DIRTY;
}
-/* --- NAVMESH (begin) --- */
-#ifdef WITH_GAMEENGINE
-
-/* BMESH_TODO, navmesh is not working right currently
- * All tools set this as MPoly data, but derived mesh currently draws from MFace (tessface)
- *
- * Proposed solution, rather then copy CD_RECAST into the MFace array,
- * use ORIGINDEX to get the original poly index and then get the CD_RECAST
- * data from the original me->mpoly layer. - campbell
- */
-
-
-BLI_INLINE int navmesh_bit(int a, int b)
-{
- return (a & (1 << b)) >> b;
-}
-
-BLI_INLINE void navmesh_intToCol(int i, float col[3])
-{
- int r = navmesh_bit(i, 0) + navmesh_bit(i, 3) * 2 + 1;
- int g = navmesh_bit(i, 1) + navmesh_bit(i, 4) * 2 + 1;
- int b = navmesh_bit(i, 2) + navmesh_bit(i, 5) * 2 + 1;
- col[0] = 1 - r * 63.0f / 255.0f;
- col[1] = 1 - g * 63.0f / 255.0f;
- col[2] = 1 - b * 63.0f / 255.0f;
-}
-
-static void navmesh_drawColored(DerivedMesh *dm)
-{
- int a, glmode;
- MVert *mvert = (MVert *)CustomData_get_layer(&dm->vertData, CD_MVERT);
- MFace *mface = (MFace *)CustomData_get_layer(&dm->faceData, CD_MFACE);
- int *polygonIdx = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST);
- float col[3];
-
- if (!polygonIdx)
- return;
-
-#if 0
- //UI_ThemeColor(TH_WIRE);
- glLineWidth(2.0);
- dm->drawEdges(dm, 0, 1);
-#endif
-
- /* if (GPU_buffer_legacy(dm) ) */ /* TODO - VBO draw code, not high priority - campbell */
- {
- DEBUG_VBO("Using legacy code. drawNavMeshColored\n");
- glBegin(glmode = GL_QUADS);
- for (a = 0; a < dm->numTessFaceData; a++, mface++) {
- int new_glmode = mface->v4 ? GL_QUADS : GL_TRIANGLES;
- int pi = polygonIdx[a];
- if (pi <= 0) {
- zero_v3(col);
- }
- else {
- navmesh_intToCol(pi, col);
- }
-
- if (new_glmode != glmode) {
- glEnd();
- glBegin(glmode = new_glmode);
- }
- glColor3fv(col);
- glVertex3fv(mvert[mface->v1].co);
- glVertex3fv(mvert[mface->v2].co);
- glVertex3fv(mvert[mface->v3].co);
- if (mface->v4) {
- glVertex3fv(mvert[mface->v4].co);
- }
- }
- glEnd();
- }
-}
-
-static void navmesh_DM_drawFacesTex(
- DerivedMesh *dm,
- DMSetDrawOptionsTex UNUSED(setDrawOptions),
- DMCompareDrawOptions UNUSED(compareDrawOptions),
- void *UNUSED(userData), DMDrawFlag UNUSED(flag))
-{
- navmesh_drawColored(dm);
-}
-
-static void navmesh_DM_drawFacesSolid(
- DerivedMesh *dm,
- float (*partial_redraw_planes)[4],
- bool UNUSED(fast), DMSetMaterial UNUSED(setMaterial))
-{
- UNUSED_VARS(partial_redraw_planes);
-
- //drawFacesSolid_original(dm, partial_redraw_planes, fast, setMaterial);
- navmesh_drawColored(dm);
-}
-
-static DerivedMesh *navmesh_dm_createNavMeshForVisualization(DerivedMesh *dm)
-{
- DerivedMesh *result;
- int maxFaces = dm->getNumPolys(dm);
- int *recastData;
- int vertsPerPoly = 0, nverts = 0, ndtris = 0, npolys = 0;
- float *verts = NULL;
- unsigned short *dtris = NULL, *dmeshes = NULL, *polys = NULL;
- int *dtrisToPolysMap = NULL, *dtrisToTrisMap = NULL, *trisToFacesMap = NULL;
- int res;
-
- result = CDDM_copy(dm);
- if (!CustomData_has_layer(&result->polyData, CD_RECAST)) {
- int *sourceRecastData = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST);
- if (sourceRecastData) {
- CustomData_add_layer_named(&result->polyData, CD_RECAST, CD_DUPLICATE,
- sourceRecastData, maxFaces, "recastData");
- }
- }
- recastData = (int *)CustomData_get_layer(&result->polyData, CD_RECAST);
-
- /* note: This is not good design! - really should not be doing this */
- result->drawFacesTex = navmesh_DM_drawFacesTex;
- result->drawFacesSolid = navmesh_DM_drawFacesSolid;
-
-
- /* process mesh */
- res = buildNavMeshDataByDerivedMesh(dm, &vertsPerPoly, &nverts, &verts, &ndtris, &dtris,
- &npolys, &dmeshes, &polys, &dtrisToPolysMap, &dtrisToTrisMap,
- &trisToFacesMap);
- if (res) {
- size_t polyIdx;
-
- /* invalidate concave polygon */
- for (polyIdx = 0; polyIdx < (size_t)npolys; polyIdx++) {
- unsigned short *poly = &polys[polyIdx * 2 * vertsPerPoly];
- if (!polyIsConvex(poly, vertsPerPoly, verts)) {
- /* set negative polygon idx to all faces */
- unsigned short *dmesh = &dmeshes[4 * polyIdx];
- unsigned short tbase = dmesh[2];
- unsigned short tnum = dmesh[3];
- unsigned short ti;
-
- for (ti = 0; ti < tnum; ti++) {
- unsigned short triidx = dtrisToTrisMap[tbase + ti];
- unsigned short faceidx = trisToFacesMap[triidx];
- if (recastData[faceidx] > 0) {
- recastData[faceidx] = -recastData[faceidx];
- }
- }
- }
- }
- }
- else {
- printf("Navmesh: Unable to generate valid Navmesh");
- }
-
- /* clean up */
- if (verts != NULL)
- MEM_freeN(verts);
- if (dtris != NULL)
- MEM_freeN(dtris);
- if (dmeshes != NULL)
- MEM_freeN(dmeshes);
- if (polys != NULL)
- MEM_freeN(polys);
- if (dtrisToPolysMap != NULL)
- MEM_freeN(dtrisToPolysMap);
- if (dtrisToTrisMap != NULL)
- MEM_freeN(dtrisToTrisMap);
- if (trisToFacesMap != NULL)
- MEM_freeN(trisToFacesMap);
-
- return result;
-}
-
-#endif /* WITH_GAMEENGINE */
-
-/* --- NAVMESH (end) --- */
-
-
void DM_init_origspace(DerivedMesh *dm)
{
const float default_osf[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
diff --git a/source/blender/blenkernel/intern/action.c b/source/blender/blenkernel/intern/action.c
index 9823a501092..dd3e8c0afdb 100644
--- a/source/blender/blenkernel/intern/action.c
+++ b/source/blender/blenkernel/intern/action.c
@@ -55,7 +55,6 @@
#include "BKE_animsys.h"
#include "BKE_constraint.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
@@ -65,6 +64,8 @@
#include "BKE_main.h"
#include "BKE_object.h"
+#include "DEG_depsgraph_build.h"
+
#include "BIK_api.h"
#include "RNA_access.h"
@@ -587,6 +588,8 @@ void BKE_pose_copy_data_ex(bPose **dst, const bPose *src, const int flag, const
if (pchan->prop) {
pchan->prop = IDP_CopyProperty_ex(pchan->prop, flag);
}
+
+ pchan->draw_data = NULL; /* Drawing cache, no need to copy. */
}
/* for now, duplicate Bone Groups too when doing this */
@@ -780,6 +783,9 @@ void BKE_pose_channel_free_ex(bPoseChannel *pchan, bool do_id_user)
IDP_FreeProperty(pchan->prop);
MEM_freeN(pchan->prop);
}
+
+ /* Cached data, for new draw manager rendering code. */
+ MEM_SAFE_FREE(pchan->draw_data);
}
void BKE_pose_channel_free(bPoseChannel *pchan)
@@ -849,39 +855,6 @@ void BKE_pose_free(bPose *pose)
BKE_pose_free_ex(pose, true);
}
-static void copy_pose_channel_data(bPoseChannel *pchan, const bPoseChannel *chan)
-{
- bConstraint *pcon, *con;
-
- copy_v3_v3(pchan->loc, chan->loc);
- copy_v3_v3(pchan->size, chan->size);
- copy_v3_v3(pchan->eul, chan->eul);
- copy_v3_v3(pchan->rotAxis, chan->rotAxis);
- pchan->rotAngle = chan->rotAngle;
- copy_qt_qt(pchan->quat, chan->quat);
- pchan->rotmode = chan->rotmode;
- copy_m4_m4(pchan->chan_mat, (float(*)[4])chan->chan_mat);
- copy_m4_m4(pchan->pose_mat, (float(*)[4])chan->pose_mat);
- pchan->flag = chan->flag;
-
- pchan->roll1 = chan->roll1;
- pchan->roll2 = chan->roll2;
- pchan->curveInX = chan->curveInX;
- pchan->curveInY = chan->curveInY;
- pchan->curveOutX = chan->curveOutX;
- pchan->curveOutY = chan->curveOutY;
- pchan->ease1 = chan->ease1;
- pchan->ease2 = chan->ease2;
- pchan->scaleIn = chan->scaleIn;
- pchan->scaleOut = chan->scaleOut;
-
- con = chan->constraints.first;
- for (pcon = pchan->constraints.first; pcon && con; pcon = pcon->next, con = con->next) {
- pcon->enforce = con->enforce;
- pcon->headtail = con->headtail;
- }
-}
-
/**
* Copy the internal members of each pose channel including constraints
* and ID-Props, used when duplicating bones in editmode.
@@ -1323,25 +1296,6 @@ short action_get_item_transforms(bAction *act, Object *ob, bPoseChannel *pchan,
/* ************** Pose Management Tools ****************** */
-/* Copy the data from the action-pose (src) into the pose */
-/* both args are assumed to be valid */
-/* exported to game engine */
-/* Note! this assumes both poses are aligned, this isn't always true when dealing with user poses */
-void extract_pose_from_pose(bPose *pose, const bPose *src)
-{
- const bPoseChannel *schan;
- bPoseChannel *pchan = pose->chanbase.first;
-
- if (pose == src) {
- printf("extract_pose_from_pose source and target are the same\n");
- return;
- }
-
- for (schan = src->chanbase.first; (schan && pchan); schan = schan->next, pchan = pchan->next) {
- copy_pose_channel_data(pchan, schan);
- }
-}
-
/* for do_all_pose_actions, clears the pose. Now also exported for proxy and tools */
void BKE_pose_rest(bPose *pose)
{
@@ -1428,7 +1382,7 @@ void BKE_pose_tag_recalc(Main *bmain, bPose *pose)
/* Depsgraph components depends on actual pose state,
* if pose was changed depsgraph is to be updated as well.
*/
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
/* For the calculation of the effects of an Action at the given frame on an object
diff --git a/source/blender/blenkernel/intern/anim.c b/source/blender/blenkernel/intern/anim.c
index 2f65e71c6d2..cff9fd4a7c8 100644
--- a/source/blender/blenkernel/intern/anim.c
+++ b/source/blender/blenkernel/intern/anim.c
@@ -43,17 +43,22 @@
#include "DNA_key_types.h"
#include "DNA_scene_types.h"
+#include "BKE_anim.h"
+#include "BKE_action.h"
+#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_scene.h"
-#include "BKE_anim.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+#include "DEG_depsgraph_build.h"
+
// XXX bad level call...
/* --------------------- */
@@ -228,8 +233,15 @@ typedef struct MPathTarget {
bMotionPath *mpath; /* motion path in question */
+ /* Original (Source Objects) */
Object *ob; /* source object */
bPoseChannel *pchan; /* source posechannel (if applicable) */
+
+ /* "Evaluated" Copies (these come from the background COW copie
+ * that provide all the coordinates we want to save off)
+ */
+ Object *ob_eval; /* evaluated object */
+ bPoseChannel *pchan_eval; /* evaluated posechannel (if applicable) */
} MPathTarget;
/* ........ */
@@ -273,88 +285,21 @@ void animviz_get_object_motionpaths(Object *ob, ListBase *targets)
/* ........ */
-/* Note on evaluation optimizations:
- * Optimization's currently used here play tricks with the depsgraph in order to try and
- * evaluate as few objects as strictly necessary to get nicer performance under standard
- * production conditions. For those people who really need the accurate version,
- * disable the ifdef (i.e. 1 -> 0) and comment out the call to motionpaths_calc_optimise_depsgraph()
- */
-
-/* tweak the object ordering to trick depsgraph into making MotionPath calculations run faster */
-static void motionpaths_calc_optimise_depsgraph(Scene *scene, ListBase *targets)
-{
- Base *base, *baseNext;
- MPathTarget *mpt;
-
- /* make sure our temp-tag isn't already in use */
- for (base = scene->base.first; base; base = base->next)
- base->object->flag &= ~BA_TEMP_TAG;
-
- /* for each target, dump its object to the start of the list if it wasn't moved already */
- for (mpt = targets->first; mpt; mpt = mpt->next) {
- for (base = scene->base.first; base; base = baseNext) {
- baseNext = base->next;
-
- if ((base->object == mpt->ob) && !(mpt->ob->flag & BA_TEMP_TAG)) {
- BLI_remlink(&scene->base, base);
- BLI_addhead(&scene->base, base);
-
- mpt->ob->flag |= BA_TEMP_TAG;
-
- /* we really don't need to continue anymore once this happens, but this line might really 'break' */
- break;
- }
- }
- }
-
- /* "brew me a list that's sorted a bit faster now depsy" */
- DAG_scene_relations_rebuild(G.main, scene);
-}
-
/* update scene for current frame */
-static void motionpaths_calc_update_scene(Scene *scene)
+static void motionpaths_calc_update_scene(Main *bmain,
+ struct Depsgraph *depsgraph)
{
-#if 1 // 'production' optimizations always on
- /* rigid body simulation needs complete update to work correctly for now */
- /* RB_TODO investigate if we could avoid updating everything */
- if (BKE_scene_check_rigidbody_active(scene)) {
- BKE_scene_update_for_newframe(G.main->eval_ctx, G.main, scene, scene->lay);
- }
- else { /* otherwise we can optimize by restricting updates */
- Base *base, *last = NULL;
-
- /* only stuff that moves or needs display still */
- DAG_scene_update_flags(G.main, scene, scene->lay, true, false);
-
- /* find the last object with the tag
- * - all those afterwards are assumed to not be relevant for our calculations
- */
- /* optimize further by moving out... */
- for (base = scene->base.first; base; base = base->next) {
- if (base->object->flag & BA_TEMP_TAG)
- last = base;
- }
-
- /* perform updates for tagged objects */
- /* XXX: this will break if rigs depend on scene or other data that
- * is animated but not attached to/updatable from objects */
- for (base = scene->base.first; base; base = base->next) {
- /* update this object */
- BKE_object_handle_update(G.main->eval_ctx, scene, base->object);
-
- /* if this is the last one we need to update, let's stop to save some time */
- if (base == last)
- break;
- }
- }
-#else // original, 'always correct' version
- /* do all updates
+ /* Do all updates
* - if this is too slow, resort to using a more efficient way
* that doesn't force complete update, but for now, this is the
* most accurate way!
+ *
+ * TODO(segey): Bring back partial updates, which became impossible
+ * with the new depsgraph due to unsorted nature of bases.
+ *
+ * TODO(sergey): Use evaluation context dedicated to motion paths.
*/
- BKE_scene_update_for_newframe(G.main->eval_ctx, G.main, scene, scene->lay); /* XXX this is the best way we can get anything moving */
-#endif
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
}
/* ........ */
@@ -369,31 +314,35 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
bMotionPath *mpath = mpt->mpath;
bMotionPathVert *mpv;
+ Object *ob_eval = mpt->ob_eval;
+ bPoseChannel *pchan_eval = mpt->pchan_eval;
+
/* current frame must be within the range the cache works for
* - is inclusive of the first frame, but not the last otherwise we get buffer overruns
*/
- if ((CFRA < mpath->start_frame) || (CFRA >= mpath->end_frame))
+ if ((CFRA < mpath->start_frame) || (CFRA >= mpath->end_frame)) {
continue;
+ }
/* get the relevant cache vert to write to */
mpv = mpath->points + (CFRA - mpath->start_frame);
/* pose-channel or object path baking? */
- if (mpt->pchan) {
+ if (mpt->pchan_eval) {
/* heads or tails */
if (mpath->flag & MOTIONPATH_FLAG_BHEAD) {
- copy_v3_v3(mpv->co, mpt->pchan->pose_head);
+ copy_v3_v3(mpv->co, pchan_eval->pose_head);
}
else {
- copy_v3_v3(mpv->co, mpt->pchan->pose_tail);
+ copy_v3_v3(mpv->co, pchan_eval->pose_tail);
}
/* result must be in worldspace */
- mul_m4_v3(mpt->ob->obmat, mpv->co);
+ mul_m4_v3(ob_eval->obmat, mpv->co);
}
else {
/* worldspace object location */
- copy_v3_v3(mpv->co, mpt->ob->obmat[3]);
+ copy_v3_v3(mpv->co, ob_eval->obmat[3]);
}
}
}
@@ -404,7 +353,7 @@ static void motionpaths_calc_bake_targets(Scene *scene, ListBase *targets)
* - recalc: whether we need to
*/
/* TODO: include reports pointer? */
-void animviz_calc_motionpaths(Scene *scene, ListBase *targets)
+ void animviz_calc_motionpaths(Depsgraph *depsgraph, Main *bmain, Scene *scene, ListBase *targets)
{
MPathTarget *mpt;
int sfra, efra;
@@ -428,22 +377,31 @@ void animviz_calc_motionpaths(Scene *scene, ListBase *targets)
}
if (efra <= sfra) return;
- /* optimize the depsgraph for faster updates */
- /* TODO: whether this is used should depend on some setting for the level of optimizations used */
- motionpaths_calc_optimise_depsgraph(scene, targets);
+
+ /* get copies of objects/bones to get the calculated results from
+ * (for copy-on-write evaluation), so that we actually get some results
+ */
+ // TODO: Create a copy of background depsgraph that only contain these entities, and only evaluates them..
+ for (mpt = targets->first; mpt; mpt = mpt->next) {
+ mpt->ob_eval = DEG_get_evaluated_object(depsgraph, mpt->ob);
+ if (mpt->pchan) {
+ mpt->pchan_eval = BKE_pose_channel_find_name(mpt->ob_eval->pose, mpt->pchan->name);
+ }
+ }
/* calculate path over requested range */
for (CFRA = sfra; CFRA <= efra; CFRA++) {
/* update relevant data for new frame */
- motionpaths_calc_update_scene(scene);
+ motionpaths_calc_update_scene(bmain, depsgraph);
/* perform baking for targets */
motionpaths_calc_bake_targets(scene, targets);
}
/* reset original environment */
+ // XXX: Soon to be obsolete
CFRA = cfra;
- motionpaths_calc_update_scene(scene);
+ motionpaths_calc_update_scene(bmain, depsgraph);
/* clear recalc flags from targets */
for (mpt = targets->first; mpt; mpt = mpt->next) {
diff --git a/source/blender/blenkernel/intern/anim_sys.c b/source/blender/blenkernel/intern/anim_sys.c
index e2c371348e5..4eeabd7a4da 100644
--- a/source/blender/blenkernel/intern/anim_sys.c
+++ b/source/blender/blenkernel/intern/anim_sys.c
@@ -60,7 +60,6 @@
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_nla.h"
#include "BKE_global.h"
@@ -70,14 +69,15 @@
#include "BKE_report.h"
#include "BKE_texture.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "RNA_access.h"
#include "nla_private.h"
#include "atomic_ops.h"
-#include "DEG_depsgraph.h"
-
/* ***************************************** */
/* AnimData API */
@@ -97,6 +97,7 @@ bool id_type_can_have_animdata(const short id_type)
case ID_MA: case ID_TE: case ID_NT:
case ID_LA: case ID_CA: case ID_WO:
case ID_LS:
+ case ID_LP:
case ID_SPK:
case ID_SCE:
case ID_MC:
@@ -263,7 +264,7 @@ void BKE_animdata_free(ID *id, const bool do_id_user)
/* Copying -------------------------------------------- */
/* Make a copy of the given AnimData - to be used when copying datablocks */
-AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action)
+AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action, const bool do_id_user)
{
AnimData *dadt;
@@ -278,7 +279,7 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action)
BKE_id_copy_ex(bmain, (ID *)dadt->action, (ID **)&dadt->action, 0, false);
BKE_id_copy_ex(bmain, (ID *)dadt->tmpact, (ID **)&dadt->tmpact, 0, false);
}
- else {
+ else if (do_id_user) {
id_us_plus((ID *)dadt->action);
id_us_plus((ID *)dadt->tmpact);
}
@@ -296,19 +297,19 @@ AnimData *BKE_animdata_copy(Main *bmain, AnimData *adt, const bool do_action)
return dadt;
}
-bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const bool do_action)
+bool BKE_animdata_copy_id(Main *bmain, ID *id_to, ID *id_from, const bool do_action, const bool do_id_user)
{
AnimData *adt;
if ((id_to && id_from) && (GS(id_to->name) != GS(id_from->name)))
return false;
- BKE_animdata_free(id_to, true);
+ BKE_animdata_free(id_to, do_id_user);
adt = BKE_animdata_from_id(id_from);
if (adt) {
IdAdtTemplate *iat = (IdAdtTemplate *)id_to;
- iat->adt = BKE_animdata_copy(bmain, adt, do_action);
+ iat->adt = BKE_animdata_copy(bmain, adt, do_action, do_id_user);
}
return true;
@@ -601,36 +602,8 @@ char *BKE_animdata_driver_path_hack(bContext *C, PointerRNA *ptr, PropertyRNA *p
Object *ob = CTX_data_active_object(C);
if (ob && id) {
- /* only id-types which can be remapped to go through objects should be considered */
- switch (GS(id->name)) {
- case ID_TE: /* textures */
- {
- Material *ma = give_current_material(ob, ob->actcol);
- Tex *tex = give_current_material_texture(ma);
-
- /* assumes: texture will only be shown if it is active material's active texture it's ok */
- if ((ID *)tex == id) {
- char name_esc_ma[(sizeof(ma->id.name) - 2) * 2];
- char name_esc_tex[(sizeof(tex->id.name) - 2) * 2];
-
- BLI_strescape(name_esc_ma, ma->id.name + 2, sizeof(name_esc_ma));
- BLI_strescape(name_esc_tex, tex->id.name + 2, sizeof(name_esc_tex));
-
- /* create new path */
- // TODO: use RNA path functions to construct step by step instead?
- // FIXME: maybe this isn't even needed anymore...
- path = BLI_sprintfN("material_slots[\"%s\"].material.texture_slots[\"%s\"].texture.%s",
- name_esc_ma, name_esc_tex, basepath);
-
- /* free old one */
- if (basepath != base_path)
- MEM_freeN(basepath);
- }
- break;
- }
- default:
- break;
- }
+ /* TODO: after material textures were removed, this function serves
+ * no purpose anymore, but could be used again so was not removed. */
/* fix RNA pointer, as we've now changed the ID root by changing the paths */
if (basepath != path) {
@@ -1555,37 +1528,100 @@ static bool animsys_store_rna_setting(
/* less than 1.0 evaluates to false, use epsilon to avoid float error */
#define ANIMSYS_FLOAT_AS_BOOL(value) ((value) > ((1.0f - FLT_EPSILON)))
+static bool animsys_read_rna_setting(PathResolvedRNA *anim_rna, float *r_value)
+{
+ PropertyRNA *prop = anim_rna->prop;
+ PointerRNA *ptr = &anim_rna->ptr;
+ int array_index = anim_rna->prop_index;
+ float orig_value;
+
+ /* caller must ensure this is animatable */
+ BLI_assert(RNA_property_animateable(ptr, prop) || ptr->id.data == NULL);
+
+ switch (RNA_property_type(prop)) {
+ case PROP_BOOLEAN:
+ {
+ if (array_index != -1) {
+ const int orig_value_coerce = RNA_property_boolean_get_index(ptr, prop, array_index);
+ orig_value = (float)orig_value_coerce;
+ }
+ else {
+ const int orig_value_coerce = RNA_property_boolean_get(ptr, prop);
+ orig_value = (float)orig_value_coerce;
+ }
+ break;
+ }
+ case PROP_INT:
+ {
+ if (array_index != -1) {
+ const int orig_value_coerce = RNA_property_int_get_index(ptr, prop, array_index);
+ orig_value = (float)orig_value_coerce;
+ }
+ else {
+ const int orig_value_coerce = RNA_property_int_get(ptr, prop);
+ orig_value = (float)orig_value_coerce;
+ }
+ break;
+ }
+ case PROP_FLOAT:
+ {
+ if (array_index != -1) {
+ const float orig_value_coerce = RNA_property_float_get_index(ptr, prop, array_index);
+ orig_value = (float)orig_value_coerce;
+ }
+ else {
+ const float orig_value_coerce = RNA_property_float_get(ptr, prop);
+ orig_value = (float)orig_value_coerce;
+ }
+ break;
+ }
+ case PROP_ENUM:
+ {
+ const int orig_value_coerce = RNA_property_enum_get(ptr, prop);
+ orig_value = (float)orig_value_coerce;
+ break;
+ }
+ default:
+ /* nothing can be done here... so it is unsuccessful? */
+ return false;
+ }
+
+ if (r_value != NULL) {
+ *r_value = orig_value;
+ }
+
+ /* successful */
+ return true;
+}
+
/* Write the given value to a setting using RNA, and return success */
static bool animsys_write_rna_setting(PathResolvedRNA *anim_rna, const float value)
{
PropertyRNA *prop = anim_rna->prop;
PointerRNA *ptr = &anim_rna->ptr;
int array_index = anim_rna->prop_index;
-
+
/* caller must ensure this is animatable */
BLI_assert(RNA_property_animateable(ptr, prop) || ptr->id.data == NULL);
- /* set value for animatable numerical values only
- * HACK: some local F-Curves (e.g. those on NLA Strips) are evaluated
- * without an ID provided, which causes the animateable test to fail!
- */
- bool written = false;
+ /* Check whether value is new. Otherwise we skip all the updates. */
+ float old_value;
+ if (!animsys_read_rna_setting(anim_rna, &old_value)) {
+ return false;
+ }
+ if (old_value == value) {
+ return true;
+ }
switch (RNA_property_type(prop)) {
case PROP_BOOLEAN:
{
const int value_coerce = ANIMSYS_FLOAT_AS_BOOL(value);
if (array_index != -1) {
- if (RNA_property_boolean_get_index(ptr, prop, array_index) != value_coerce) {
- RNA_property_boolean_set_index(ptr, prop, array_index, value_coerce);
- written = true;
- }
+ RNA_property_boolean_set_index(ptr, prop, array_index, value_coerce);
}
else {
- if (RNA_property_boolean_get(ptr, prop) != value_coerce) {
- RNA_property_boolean_set(ptr, prop, value_coerce);
- written = true;
- }
+ RNA_property_boolean_set(ptr, prop, value_coerce);
}
break;
}
@@ -1594,16 +1630,10 @@ static bool animsys_write_rna_setting(PathResolvedRNA *anim_rna, const float val
int value_coerce = (int)value;
RNA_property_int_clamp(ptr, prop, &value_coerce);
if (array_index != -1) {
- if (RNA_property_int_get_index(ptr, prop, array_index) != value_coerce) {
- RNA_property_int_set_index(ptr, prop, array_index, value_coerce);
- written = true;
- }
+ RNA_property_int_set_index(ptr, prop, array_index, value_coerce);
}
else {
- if (RNA_property_int_get(ptr, prop) != value_coerce) {
- RNA_property_int_set(ptr, prop, value_coerce);
- written = true;
- }
+ RNA_property_int_set(ptr, prop, value_coerce);
}
break;
}
@@ -1612,26 +1642,17 @@ static bool animsys_write_rna_setting(PathResolvedRNA *anim_rna, const float val
float value_coerce = value;
RNA_property_float_clamp(ptr, prop, &value_coerce);
if (array_index != -1) {
- if (RNA_property_float_get_index(ptr, prop, array_index) != value_coerce) {
- RNA_property_float_set_index(ptr, prop, array_index, value_coerce);
- written = true;
- }
+ RNA_property_float_set_index(ptr, prop, array_index, value_coerce);
}
else {
- if (RNA_property_float_get(ptr, prop) != value_coerce) {
- RNA_property_float_set(ptr, prop, value_coerce);
- written = true;
- }
+ RNA_property_float_set(ptr, prop, value_coerce);
}
break;
}
case PROP_ENUM:
{
const int value_coerce = (int)value;
- if (RNA_property_enum_get(ptr, prop) != value_coerce) {
- RNA_property_enum_set(ptr, prop, value_coerce);
- written = true;
- }
+ RNA_property_enum_set(ptr, prop, value_coerce);
break;
}
default:
@@ -1659,23 +1680,6 @@ static bool animsys_write_rna_setting(PathResolvedRNA *anim_rna, const float val
}
#endif
- /* as long as we don't do property update, we still tag datablock
- * as having been updated. this flag does not cause any updates to
- * be run, it's for e.g. render engines to synchronize data */
- if (written && ptr->id.data) {
- ID *id = ptr->id.data;
-
- /* for cases like duplifarmes it's only a temporary so don't
- * notify anyone of updates */
- if (!(id->recalc & ID_RECALC_SKIP_ANIM_TAG)) {
- /* NOTE: This is a bit annoying to use atomic API here, but this
- * code is at it's EOL and removed already in 2.8 branch.
- */
- atomic_fetch_and_or_int32(&id->recalc, ID_RECALC);
- DAG_id_type_tag(G.main, GS(id->name));
- }
- }
-
/* successful */
return true;
}
@@ -1697,10 +1701,15 @@ bool BKE_animsys_execute_fcurve(PointerRNA *ptr, AnimMapper *remap, FCurve *fcu,
/* Evaluate all the F-Curves in the given list
* This performs a set of standard checks. If extra checks are required, separate code should be used
*/
-static void animsys_evaluate_fcurves(PointerRNA *ptr, ListBase *list, AnimMapper *remap, float ctime)
+static void animsys_evaluate_fcurves(PointerRNA *ptr, ListBase *list, AnimMapper *remap, float ctime, short recalc)
{
FCurve *fcu;
-
+
+ /* Pointer is expected to be an ID pointer, if it's not -- we are doomed. */
+ PointerRNA orig_ptr = *ptr;
+ orig_ptr.id.data = ((ID *)orig_ptr.id.data)->orig_id;
+ orig_ptr.data = orig_ptr.id.data;
+
/* calculate then execute each curve */
for (fcu = list->first; fcu; fcu = fcu->next) {
/* check if this F-Curve doesn't belong to a muted group */
@@ -1708,9 +1717,28 @@ static void animsys_evaluate_fcurves(PointerRNA *ptr, ListBase *list, AnimMapper
/* check if this curve should be skipped */
if ((fcu->flag & (FCURVE_MUTED | FCURVE_DISABLED)) == 0) {
PathResolvedRNA anim_rna;
+ /* Read current value from original datablock. */
+ float dna_val;
+ if (animsys_store_rna_setting(&orig_ptr, remap, fcu->rna_path, fcu->array_index, &anim_rna)) {
+ if (!animsys_read_rna_setting(&anim_rna, &dna_val)) {
+ continue;
+ }
+ }
+ else {
+ continue;
+ }
if (animsys_store_rna_setting(ptr, remap, fcu->rna_path, fcu->array_index, &anim_rna)) {
+ const bool check_orig_dna = ((recalc & ADT_RECALC_CHECK_ORIG_DNA) != 0);
+ /* If we are tweaking DNA without changing frame, we don't write f-curves,
+ * since otherwise we will not be able to change properties which has animation.
+ */
+ if (check_orig_dna && fcu->orig_dna_val != dna_val) {
+ continue;
+ }
const float curval = calculate_fcurve(&anim_rna, fcu, ctime);
animsys_write_rna_setting(&anim_rna, curval);
+ /* Store original DNA value f-curve was written for. */
+ fcu->orig_dna_val = dna_val;
}
}
}
@@ -1823,7 +1851,7 @@ void animsys_evaluate_action_group(PointerRNA *ptr, bAction *act, bActionGroup *
}
/* Evaluate Action (F-Curve Bag) */
-void animsys_evaluate_action(PointerRNA *ptr, bAction *act, AnimMapper *remap, float ctime)
+static void animsys_evaluate_action_ex(PointerRNA *ptr, bAction *act, AnimMapper *remap, float ctime, short recalc)
{
/* check if mapper is appropriate for use here (we set to NULL if it's inappropriate) */
if (act == NULL) return;
@@ -1832,7 +1860,12 @@ void animsys_evaluate_action(PointerRNA *ptr, bAction *act, AnimMapper *remap, f
action_idcode_patch_check(ptr->id.data, act);
/* calculate then execute each curve */
- animsys_evaluate_fcurves(ptr, &act->curves, remap, ctime);
+ animsys_evaluate_fcurves(ptr, &act->curves, remap, ctime, recalc);
+}
+
+void animsys_evaluate_action(PointerRNA *ptr, bAction *act, AnimMapper *remap, float ctime)
+{
+ animsys_evaluate_action_ex(ptr, act, remap, ctime, 0);
}
/* ***************************************** */
@@ -1871,7 +1904,7 @@ static void nlastrip_evaluate_controls(NlaStrip *strip, float ctime)
RNA_pointer_create(NULL, &RNA_NlaStrip, strip, &strip_ptr);
/* execute these settings as per normal */
- animsys_evaluate_fcurves(&strip_ptr, &strip->fcurves, NULL, ctime);
+ animsys_evaluate_fcurves(&strip_ptr, &strip->fcurves, NULL, ctime, 0);
}
/* analytically generate values for influence and time (if applicable)
@@ -2619,17 +2652,6 @@ static void animsys_evaluate_nla(ListBase *echannels, PointerRNA *ptr, AnimData
/* 3. free temporary evaluation data that's not used elsewhere */
BLI_freelistN(&estrips);
-
- /* Tag ID as updated so render engines will recognize changes in data
- * which is animated but doesn't have actions.
- */
- if (ptr->id.data != NULL) {
- ID *id = ptr->id.data;
- if (!(id->recalc & ID_RECALC_SKIP_ANIM_TAG)) {
- id->recalc |= ID_RECALC;
- DAG_id_type_tag(G.main, GS(id->name));
- }
- }
}
/* NLA Evaluation function (mostly for use through do_animdata)
@@ -2749,7 +2771,7 @@ void BKE_animsys_evaluate_animdata(Scene *scene, ID *id, AnimData *adt, float ct
}
/* evaluate Active Action only */
else if (adt->action)
- animsys_evaluate_action(&id_ptr, adt->action, adt->remap, ctime);
+ animsys_evaluate_action_ex(&id_ptr, adt->action, adt->remap, ctime, recalc);
/* reset tag */
adt->recalc &= ~ADT_RECALC_ANIM;
@@ -2920,17 +2942,44 @@ void BKE_animsys_evaluate_all_animation(Main *main, Scene *scene, float ctime)
/* ************** */
/* Evaluation API */
-void BKE_animsys_eval_animdata(EvaluationContext *eval_ctx, ID *id)
+void BKE_animsys_eval_animdata(Depsgraph *depsgraph, ID *id)
{
+ float ctime = DEG_get_ctime(depsgraph);
AnimData *adt = BKE_animdata_from_id(id);
Scene *scene = NULL; /* XXX: this is only needed for flushing RNA updates,
* which should get handled as part of the dependency graph instead...
*/
- DEG_debug_print_eval_time(__func__, id->name, id, eval_ctx->ctime);
- BKE_animsys_evaluate_animdata(scene, id, adt, eval_ctx->ctime, ADT_RECALC_ANIM);
+ DEG_debug_print_eval_time(depsgraph, __func__, id->name, id, ctime);
+ short recalc = ADT_RECALC_ANIM;
+ const Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
+ /* If animation component is directly tagged for update, we always apply f-curves. */
+ if (((scene_eval->id.recalc & ID_RECALC_TIME) == 0) &&
+ (id->recalc & ID_RECALC_TIME) == 0)
+ {
+ recalc |= ADT_RECALC_CHECK_ORIG_DNA;
+ }
+ BKE_animsys_evaluate_animdata(scene, id, adt, ctime, recalc);
+}
+
+/* TODO(sergey): This is slow lookup of driver from CoW datablock.
+ * Keep this for until we've got something smarter for depsgraph
+ * building.\
+ */
+static FCurve *find_driver_from_evaluated_id(ID *id, FCurve *fcu)
+{
+ /* We've got non-CoW datablock, can use f-curve as-is. */
+ if (id->orig_id == NULL) {
+ return fcu;
+ }
+ /*const*/ ID *id_orig = id->orig_id;
+ const AnimData *adt_orig = BKE_animdata_from_id(id_orig);
+ const AnimData *adt_cow = BKE_animdata_from_id(id);
+ const int fcu_index = BLI_findindex(&adt_orig->drivers, fcu);
+ BLI_assert(fcu_index != -1);
+ return BLI_findlink(&adt_cow->drivers, fcu_index);
}
-void BKE_animsys_eval_driver(EvaluationContext *eval_ctx,
+void BKE_animsys_eval_driver(Depsgraph *depsgraph,
ID *id,
FCurve *fcu)
{
@@ -2939,8 +2988,10 @@ void BKE_animsys_eval_driver(EvaluationContext *eval_ctx,
PointerRNA id_ptr;
bool ok = false;
+ fcu = find_driver_from_evaluated_id(id, fcu);
+
DEG_debug_print_eval_subdata_index(
- __func__, id->name, id, "fcu", fcu->rna_path, fcu, fcu->array_index);
+ depsgraph, __func__, id->name, id, "fcu", fcu->rna_path, fcu, fcu->array_index);
RNA_id_pointer_create(id, &id_ptr);
@@ -2956,7 +3007,8 @@ void BKE_animsys_eval_driver(EvaluationContext *eval_ctx,
PathResolvedRNA anim_rna;
if (animsys_store_rna_setting(&id_ptr, NULL, fcu->rna_path, fcu->array_index, &anim_rna)) {
- const float curval = calculate_fcurve(&anim_rna, fcu, eval_ctx->ctime);
+ const float ctime = DEG_get_ctime(depsgraph);
+ const float curval = calculate_fcurve(&anim_rna, fcu, ctime);
ok = animsys_write_rna_setting(&anim_rna, curval);
}
diff --git a/source/blender/blenkernel/intern/armature.c b/source/blender/blenkernel/intern/armature.c
index 70a3772f388..63846b31c33 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -60,7 +60,6 @@
#include "BKE_anim.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_deform.h"
#include "BKE_displist.h"
@@ -74,7 +73,6 @@
#include "BKE_scene.h"
#include "BIK_api.h"
-#include "BKE_sketch.h"
/* **************** Generic Functions, data level *************** */
@@ -136,12 +134,6 @@ void BKE_armature_free(bArmature *arm)
MEM_freeN(arm->edbo);
arm->edbo = NULL;
}
-
- /* free sketch */
- if (arm->sketch) {
- freeSketch(arm->sketch);
- arm->sketch = NULL;
- }
}
void BKE_armature_make_local(Main *bmain, bArmature *arm, const bool lib_local)
@@ -205,7 +197,6 @@ void BKE_armature_copy_data(Main *UNUSED(bmain), bArmature *arm_dst, const bArma
arm_dst->edbo = NULL;
arm_dst->act_edbone = NULL;
- arm_dst->sketch = NULL;
}
bArmature *BKE_armature_copy(Main *bmain, const bArmature *arm)
@@ -972,7 +963,7 @@ static void armature_bbone_defmats_cb(void *userdata, Link *iter, int index)
}
}
-void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3],
+void armature_deform_verts(Object *armOb, Object *target, const Mesh * mesh, float (*vertexCos)[3],
float (*defMats)[3][3], int numVerts, int deformflag,
float (*prevCos)[3], const char *defgrp_name)
{
@@ -1048,9 +1039,9 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float
/* get a vertex-deform-index to posechannel array */
if (deformflag & ARM_DEF_VGROUP) {
if (ELEM(target->type, OB_MESH, OB_LATTICE)) {
- /* if we have a DerivedMesh, only use dverts if it has them */
- if (dm) {
- use_dverts = (dm->getVertDataArray(dm, CD_MDEFORMVERT) != NULL);
+ /* if we have a Mesh, only use dverts if it has them */
+ if (mesh) {
+ use_dverts = (mesh->dvert != NULL);
}
else if (dverts) {
use_dverts = true;
@@ -1112,8 +1103,10 @@ void armature_deform_verts(Object *armOb, Object *target, DerivedMesh *dm, float
}
if (use_dverts || armature_def_nr != -1) {
- if (dm)
- dvert = dm->getVertData(dm, i, CD_MDEFORMVERT);
+ if (mesh) {
+ BLI_assert(i < mesh->totvert);
+ dvert = mesh->dvert + i;
+ }
else if (dverts && i < target_totvert)
dvert = dverts + i;
else
@@ -1463,13 +1456,13 @@ void BKE_armature_loc_pose_to_bone(bPoseChannel *pchan, const float inloc[3], fl
copy_v3_v3(outloc, nLocMat[3]);
}
-void BKE_armature_mat_pose_to_bone_ex(Object *ob, bPoseChannel *pchan, float inmat[4][4], float outmat[4][4])
+void BKE_armature_mat_pose_to_bone_ex(struct Depsgraph *depsgraph, Object *ob, bPoseChannel *pchan, float inmat[4][4], float outmat[4][4])
{
bPoseChannel work_pchan = *pchan;
/* recalculate pose matrix with only parent transformations,
* bone loc/sca/rot is ignored, scene and frame are not used. */
- BKE_pose_where_is_bone(NULL, ob, &work_pchan, 0.0f, false);
+ BKE_pose_where_is_bone(depsgraph, NULL, ob, &work_pchan, 0.0f, false);
/* find the matrix, need to remove the bone transforms first so this is
* calculated as a matrix to set rather then a difference ontop of whats
@@ -1950,9 +1943,18 @@ void BKE_pose_clear_pointers(bPose *pose)
}
}
+void BKE_pose_remap_bone_pointers(bArmature *armature, bPose *pose)
+{
+ GHash *bone_hash = BKE_armature_bone_from_name_map(armature);
+ for (bPoseChannel *pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
+ pchan->bone = BLI_ghash_lookup(bone_hash, pchan->name);
+ }
+ BLI_ghash_free(bone_hash, NULL, NULL);
+}
+
/* only after leave editmode, duplicating, validating older files, library syncing */
/* NOTE: pose->flag is set for it */
-void BKE_pose_rebuild_ex(Object *ob, bArmature *arm, const bool sort_bones)
+void BKE_pose_rebuild(Object *ob, bArmature *arm)
{
Bone *bone;
bPose *pose;
@@ -1996,27 +1998,12 @@ void BKE_pose_rebuild_ex(Object *ob, bArmature *arm, const bool sort_bones)
BKE_pose_update_constraint_flags(ob->pose); /* for IK detection for example */
-#ifdef WITH_LEGACY_DEPSGRAPH
- /* the sorting */
- /* Sorting for new dependnecy graph is done on the scene graph level. */
- if (counter > 1 && sort_bones) {
- DAG_pose_sort(ob);
- }
-#else
- UNUSED_VARS(sort_bones);
-#endif
-
ob->pose->flag &= ~POSE_RECALC;
ob->pose->flag |= POSE_WAS_REBUILT;
BKE_pose_channels_hash_make(ob->pose);
}
-void BKE_pose_rebuild(Object *ob, bArmature *arm)
-{
- BKE_pose_rebuild_ex(ob, arm, true);
-}
-
/* ********************** THE POSE SOLVER ******************* */
/* loc/rot/size to given mat4 */
@@ -2127,7 +2114,7 @@ static void do_strip_modifiers(Scene *scene, Object *armob, Bone *bone, bPoseCha
if (STREQ(pchan->name, amod->channel)) {
float mat4[4][4], mat3[3][3];
- curve_deform_vector(scene, amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis);
+ curve_deform_vector(amod->ob, armob, bone->arm_mat[3], pchan->pose_mat[3], mat3, amod->no_rot_axis);
copy_m4_m4(mat4, pchan->pose_mat);
mul_m4_m3m4(pchan->pose_mat, mat3, mat4);
@@ -2211,7 +2198,9 @@ void BKE_pose_where_is_bone_tail(bPoseChannel *pchan)
/* pchan is validated, as having bone and parent pointer
* 'do_extra': when zero skips loc/size/rot, constraints and strip modifiers.
*/
-void BKE_pose_where_is_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
+void BKE_pose_where_is_bone(
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, bPoseChannel *pchan, float ctime, bool do_extra)
{
/* This gives a chan_mat with actions (ipos) results. */
if (do_extra)
@@ -2250,7 +2239,7 @@ void BKE_pose_where_is_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float
cob = BKE_constraints_make_evalob(scene, ob, pchan, CONSTRAINT_OBTYPE_BONE);
/* Solve PoseChannel's Constraints */
- BKE_constraints_solve(&pchan->constraints, cob, ctime); /* ctime doesnt alter objects */
+ BKE_constraints_solve(depsgraph, &pchan->constraints, cob, ctime); /* ctime doesnt alter objects */
/* cleanup after Constraint Solving
* - applies matrix back to pchan, and frees temporary struct used
@@ -2272,7 +2261,7 @@ void BKE_pose_where_is_bone(Scene *scene, Object *ob, bPoseChannel *pchan, float
/* This only reads anim data from channels, and writes to channels */
/* This is the only function adding poses */
-void BKE_pose_where_is(Scene *scene, Object *ob)
+void BKE_pose_where_is(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
{
bArmature *arm;
Bone *bone;
@@ -2311,7 +2300,7 @@ void BKE_pose_where_is(Scene *scene, Object *ob)
}
/* 2a. construct the IK tree (standard IK) */
- BIK_initialize_tree(scene, ob, ctime);
+ BIK_initialize_tree(depsgraph, scene, ob, ctime);
/* 2b. construct the Spline IK trees
* - this is not integrated as an IK plugin, since it should be able
@@ -2323,15 +2312,15 @@ void BKE_pose_where_is(Scene *scene, Object *ob)
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
/* 4a. if we find an IK root, we handle it separated */
if (pchan->flag & POSE_IKTREE) {
- BIK_execute_tree(scene, ob, pchan, ctime);
+ BIK_execute_tree(depsgraph, scene, ob, pchan, ctime);
}
/* 4b. if we find a Spline IK root, we handle it separated too */
else if (pchan->flag & POSE_IKSPLINE) {
- BKE_splineik_execute_tree(scene, ob, pchan, ctime);
+ BKE_splineik_execute_tree(depsgraph, scene, ob, pchan, ctime);
}
/* 5. otherwise just call the normal solver */
else if (!(pchan->flag & POSE_DONE)) {
- BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1);
}
}
/* 6. release the IK tree */
diff --git a/source/blender/blenkernel/intern/armature_update.c b/source/blender/blenkernel/intern/armature_update.c
index ee63e618b18..bf21019a948 100644
--- a/source/blender/blenkernel/intern/armature_update.c
+++ b/source/blender/blenkernel/intern/armature_update.c
@@ -41,7 +41,6 @@
#include "BKE_anim.h"
#include "BKE_armature.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_displist.h"
#include "BKE_fcurve.h"
#include "BKE_scene.h"
@@ -113,9 +112,11 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos
* currently for paths to work it needs to go through the bevlist/displist system (ton)
*/
+ /* TODO: Make sure this doesn't crash. */
+#if 0
/* only happens on reload file, but violates depsgraph still... fix! */
if (ELEM(NULL, ikData->tar->curve_cache, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) {
- BKE_displist_make_curveTypes(scene, ikData->tar, 0);
+ BKE_displist_make_curveTypes(depsgraph, scene, ikData->tar, 0);
/* path building may fail in EditMode after removing verts [#33268]*/
if (ELEM(NULL, ikData->tar->curve_cache->path, ikData->tar->curve_cache->path->data)) {
@@ -123,6 +124,9 @@ static void splineik_init_tree_from_pchan(Scene *scene, Object *UNUSED(ob), bPos
return;
}
}
+#else
+ (void) scene;
+#endif
}
/* find the root bone and the chain of bones from the root to the tip
@@ -261,15 +265,16 @@ static void splineik_init_tree(Scene *scene, Object *ob, float UNUSED(ctime))
/* ----------- */
/* Evaluate spline IK for a given bone */
-static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *ob, bPoseChannel *pchan,
- int index, float ctime)
+static void splineik_evaluate_bone(
+ struct Depsgraph *depsgraph, tSplineIK_Tree *tree, Scene *scene, Object *ob, bPoseChannel *pchan,
+ int index, float ctime)
{
bSplineIKConstraint *ikData = tree->ikData;
float poseHead[3], poseTail[3], poseMat[4][4];
float splineVec[3], scaleFac, radius = 1.0f;
/* firstly, calculate the bone matrix the standard way, since this is needed for roll control */
- BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1);
copy_v3_v3(poseHead, pchan->pose_head);
copy_v3_v3(poseTail, pchan->pose_tail);
@@ -511,7 +516,7 @@ static void splineik_evaluate_bone(tSplineIK_Tree *tree, Scene *scene, Object *o
}
/* Evaluate the chain starting from the nominated bone */
-static void splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
+static void splineik_execute_tree(struct Depsgraph *depsgraph, Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
{
tSplineIK_Tree *tree;
@@ -525,7 +530,7 @@ static void splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_
*/
for (i = tree->chainlen - 1; i >= 0; i--) {
bPoseChannel *pchan = tree->chain[i];
- splineik_evaluate_bone(tree, scene, ob, pchan, i, ctime);
+ splineik_evaluate_bone(depsgraph, tree, scene, ob, pchan, i, ctime);
}
/* free the tree info specific to SplineIK trees now */
@@ -544,9 +549,11 @@ void BKE_pose_splineik_init_tree(Scene *scene, Object *ob, float ctime)
splineik_init_tree(scene, ob, ctime);
}
-void BKE_splineik_execute_tree(Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
+void BKE_splineik_execute_tree(
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, bPoseChannel *pchan_root, float ctime)
{
- splineik_execute_tree(scene, ob, pchan_root, ctime);
+ splineik_execute_tree(depsgraph, scene, ob, pchan_root, ctime);
}
/* *************** Depsgraph evaluation callbacks ************ */
@@ -560,14 +567,14 @@ BLI_INLINE bPoseChannel *pose_pchan_get_indexed(Object *ob, int pchan_index)
return pose->chan_array[pchan_index];
}
-void BKE_pose_eval_init(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_eval_init(struct Depsgraph *depsgraph,
Scene *UNUSED(scene),
Object *ob)
{
bPose *pose = ob->pose;
BLI_assert(pose != NULL);
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
BLI_assert(ob->type == OB_ARMATURE);
@@ -590,11 +597,11 @@ void BKE_pose_eval_init(EvaluationContext *UNUSED(eval_ctx),
}
}
-void BKE_pose_eval_init_ik(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_eval_init_ik(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob)
{
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
BLI_assert(ob->type == OB_ARMATURE);
const float ctime = BKE_scene_frame_get(scene); /* not accurate... */
bArmature *arm = (bArmature *)ob->data;
@@ -602,7 +609,7 @@ void BKE_pose_eval_init_ik(EvaluationContext *UNUSED(eval_ctx),
return;
}
/* construct the IK tree (standard IK) */
- BIK_initialize_tree(scene, ob, ctime);
+ BIK_initialize_tree(depsgraph, scene, ob, ctime);
/* construct the Spline IK trees
* - this is not integrated as an IK plugin, since it should be able
* to function in conjunction with standard IK
@@ -610,14 +617,14 @@ void BKE_pose_eval_init_ik(EvaluationContext *UNUSED(eval_ctx),
BKE_pose_splineik_init_tree(scene, ob, ctime);
}
-void BKE_pose_eval_bone(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_eval_bone(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob,
int pchan_index)
{
bPoseChannel *pchan = pose_pchan_get_indexed(ob, pchan_index);
DEG_debug_print_eval_subdata(
- __func__, ob->id.name, ob, "pchan", pchan->name, pchan);
+ depsgraph, __func__, ob->id.name, ob, "pchan", pchan->name, pchan);
BLI_assert(ob->type == OB_ARMATURE);
bArmature *arm = (bArmature *)ob->data;
if (arm->edbo || (arm->flag & ARM_RESTPOS)) {
@@ -640,21 +647,21 @@ void BKE_pose_eval_bone(EvaluationContext *UNUSED(eval_ctx),
if ((pchan->flag & POSE_DONE) == 0) {
/* TODO(sergey): Use time source node for time. */
float ctime = BKE_scene_frame_get(scene); /* not accurate... */
- BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1);
}
}
}
}
}
-void BKE_pose_constraints_evaluate(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_constraints_evaluate(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob,
int pchan_index)
{
bPoseChannel *pchan = pose_pchan_get_indexed(ob, pchan_index);
DEG_debug_print_eval_subdata(
- __func__, ob->id.name, ob, "pchan", pchan->name, pchan);
+ depsgraph, __func__, ob->id.name, ob, "pchan", pchan->name, pchan);
bArmature *arm = (bArmature *)ob->data;
if (arm->flag & ARM_RESTPOS) {
return;
@@ -665,42 +672,42 @@ void BKE_pose_constraints_evaluate(EvaluationContext *UNUSED(eval_ctx),
else {
if ((pchan->flag & POSE_DONE) == 0) {
float ctime = BKE_scene_frame_get(scene); /* not accurate... */
- BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1);
}
}
}
-void BKE_pose_bone_done(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_bone_done(struct Depsgraph *depsgraph,
struct Object *ob,
int pchan_index)
{
bPoseChannel *pchan = pose_pchan_get_indexed(ob, pchan_index);
float imat[4][4];
- DEG_debug_print_eval(__func__, pchan->name, pchan);
+ DEG_debug_print_eval(depsgraph, __func__, pchan->name, pchan);
if (pchan->bone) {
invert_m4_m4(imat, pchan->bone->arm_mat);
mul_m4_m4m4(pchan->chan_mat, pchan->pose_mat, imat);
}
}
-void BKE_pose_iktree_evaluate(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_iktree_evaluate(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob,
int rootchan_index)
{
bPoseChannel *rootchan = pose_pchan_get_indexed(ob, rootchan_index);
DEG_debug_print_eval_subdata(
- __func__, ob->id.name, ob, "rootchan", rootchan->name, rootchan);
+ depsgraph, __func__, ob->id.name, ob, "rootchan", rootchan->name, rootchan);
BLI_assert(ob->type == OB_ARMATURE);
const float ctime = BKE_scene_frame_get(scene); /* not accurate... */
bArmature *arm = (bArmature *)ob->data;
if (arm->flag & ARM_RESTPOS) {
return;
}
- BIK_execute_tree(scene, ob, rootchan, ctime);
+ BIK_execute_tree(depsgraph, scene, ob, rootchan, ctime);
}
-void BKE_pose_splineik_evaluate(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_splineik_evaluate(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob,
int rootchan_index)
@@ -708,17 +715,17 @@ void BKE_pose_splineik_evaluate(EvaluationContext *UNUSED(eval_ctx),
{
bPoseChannel *rootchan = pose_pchan_get_indexed(ob, rootchan_index);
DEG_debug_print_eval_subdata(
- __func__, ob->id.name, ob, "rootchan", rootchan->name, rootchan);
+ depsgraph, __func__, ob->id.name, ob, "rootchan", rootchan->name, rootchan);
BLI_assert(ob->type == OB_ARMATURE);
const float ctime = BKE_scene_frame_get(scene); /* not accurate... */
bArmature *arm = (bArmature *)ob->data;
if (arm->flag & ARM_RESTPOS) {
return;
}
- BKE_splineik_execute_tree(scene, ob, rootchan, ctime);
+ BKE_splineik_execute_tree(depsgraph, scene, ob, rootchan, ctime);
}
-void BKE_pose_eval_flush(EvaluationContext *UNUSED(eval_ctx),
+void BKE_pose_eval_flush(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob)
{
@@ -726,29 +733,23 @@ void BKE_pose_eval_flush(EvaluationContext *UNUSED(eval_ctx),
BLI_assert(pose != NULL);
float ctime = BKE_scene_frame_get(scene); /* not accurate... */
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
BLI_assert(ob->type == OB_ARMATURE);
/* release the IK tree */
BIK_release_tree(scene, ob, ctime);
- ob->recalc &= ~OB_RECALC_ALL;
-
BLI_assert(pose->chan_array != NULL);
MEM_freeN(pose->chan_array);
pose->chan_array = NULL;
}
-void BKE_pose_eval_proxy_copy(EvaluationContext *UNUSED(eval_ctx), Object *ob)
+void BKE_pose_eval_proxy_copy(struct Depsgraph *depsgraph, Object *ob)
{
BLI_assert(ID_IS_LINKED(ob) && ob->proxy_from != NULL);
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
if (BKE_pose_copy_result(ob->pose, ob->proxy_from->pose) == false) {
printf("Proxy copy error, lib Object: %s proxy Object: %s\n",
ob->id.name + 2, ob->proxy_from->id.name + 2);
}
- /* Rest of operations are NO-OP in depsgraph, so can clear
- * flag now.
- */
- ob->recalc &= ~OB_RECALC_ALL;
}
diff --git a/source/blender/blenkernel/intern/blender.c b/source/blender/blenkernel/intern/blender.c
index 55b2d5b9c0d..236b965ec34 100644
--- a/source/blender/blenkernel/intern/blender.c
+++ b/source/blender/blenkernel/intern/blender.c
@@ -52,10 +52,10 @@
#include "BKE_brush.h"
#include "BKE_cachefile.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_node.h"
#include "BKE_report.h"
@@ -63,6 +63,8 @@
#include "BKE_screen.h"
#include "BKE_sequencer.h"
+#include "DEG_depsgraph.h"
+
#include "RE_pipeline.h"
#include "RE_render_ext.h"
@@ -92,7 +94,7 @@ void BKE_blender_free(void)
IMB_exit();
BKE_cachefiles_exit();
BKE_images_exit();
- DAG_exit();
+ DEG_free_node_types();
BKE_brush_system_exit();
RE_texture_rng_exit();
@@ -101,6 +103,8 @@ void BKE_blender_free(void)
BKE_sequencer_cache_destruct();
IMB_moviecache_destruct();
+
+ BKE_layer_exit();
free_nodesystem();
}
@@ -283,11 +287,13 @@ void BKE_blender_userdef_app_template_data_swap(UserDef *userdef_a, UserDef *use
DATA_SWAP(font_path_ui_mono);
DATA_SWAP(keyconfigstr);
+ DATA_SWAP(manipulator_flag);
DATA_SWAP(app_flag);
/* We could add others. */
FLAG_SWAP(uiflag, int, USER_QUIT_PROMPT);
+#undef SWAP_TYPELESS
#undef DATA_SWAP
#undef LIST_SWAP
#undef FLAG_SWAP
diff --git a/source/blender/blenkernel/intern/blender_copybuffer.c b/source/blender/blenkernel/intern/blender_copybuffer.c
index e57524af546..b0c571bf159 100644
--- a/source/blender/blenkernel/intern/blender_copybuffer.c
+++ b/source/blender/blenkernel/intern/blender_copybuffer.c
@@ -44,12 +44,15 @@
#include "BKE_blender_copybuffer.h" /* own include */
#include "BKE_blendfile.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "BLO_readfile.h"
#include "BLO_writefile.h"
@@ -117,7 +120,7 @@ bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, Re
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Main *mainl = NULL;
Library *lib;
BlendHandle *bh;
@@ -129,7 +132,7 @@ bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, Re
return false;
}
- BKE_scene_base_deselect_all(scene);
+ BKE_view_layer_base_deselect_all(view_layer);
/* tag everything, all untagged data can be made local
* its also generally useful to know what is new
@@ -142,7 +145,7 @@ bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, Re
BLO_library_link_copypaste(mainl, bh);
- BLO_library_link_end(mainl, &bh, flag, scene, v3d);
+ BLO_library_link_end(mainl, &bh, flag, scene, view_layer);
/* mark all library linked objects to be updated */
BKE_main_lib_objects_recalc_all(bmain);
@@ -157,7 +160,11 @@ bool BKE_copybuffer_paste(bContext *C, const char *libname, const short flag, Re
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
/* recreate dependency graph to include new objects */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
+
+ /* Tag update the scene to flush base collection settings, since the new object is added to a
+ * new (active) collection, not its original collection, thus need recalculation. */
+ DEG_id_tag_update(&scene->id, 0);
BLO_blendhandle_close(bh);
/* remove library... */
diff --git a/source/blender/blenkernel/intern/blender_undo.c b/source/blender/blenkernel/intern/blender_undo.c
index 6b31c8c96f9..98482bcc8b1 100644
--- a/source/blender/blenkernel/intern/blender_undo.c
+++ b/source/blender/blenkernel/intern/blender_undo.c
@@ -50,13 +50,14 @@
#include "BKE_blendfile.h"
#include "BKE_appdir.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BLO_undofile.h"
#include "BLO_writefile.h"
+#include "DEG_depsgraph.h"
+
/* -------------------------------------------------------------------- */
/** \name Global Undo
@@ -87,7 +88,7 @@ bool BKE_memfile_undo_decode(MemFileUndoData *mfu, bContext *C)
if (success) {
/* important not to update time here, else non keyed tranforms are lost */
- DAG_on_visible_update(G.main, false);
+ DEG_on_visible_update(G.main, false);
}
return success;
diff --git a/source/blender/blenkernel/intern/blendfile.c b/source/blender/blenkernel/intern/blendfile.c
index cc992a4a520..34079d778f7 100644
--- a/source/blender/blenkernel/intern/blendfile.c
+++ b/source/blender/blenkernel/intern/blendfile.c
@@ -32,6 +32,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
@@ -48,11 +49,13 @@
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_ipo.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
+#include "BKE_workspace.h"
#include "BLO_readfile.h"
#include "BLO_writefile.h"
@@ -93,7 +96,7 @@ static bool wm_scene_is_visible(wmWindowManager *wm, Scene *scene)
{
wmWindow *win;
for (win = wm->windows.first; win; win = win->next) {
- if (win->screen->scene == scene) {
+ if (win->scene == scene) {
return true;
}
}
@@ -163,17 +166,22 @@ static void setup_app_data(
* (otherwise we'd be undoing on an off-screen scene which isn't acceptable).
* see: T43424
*/
+ wmWindow *win;
bScreen *curscreen = NULL;
+ ViewLayer *cur_view_layer;
bool track_undo_scene;
/* comes from readfile.c */
SWAP(ListBase, G.main->wm, bfd->main->wm);
+ SWAP(ListBase, G.main->workspaces, bfd->main->workspaces);
SWAP(ListBase, G.main->screen, bfd->main->screen);
- /* we re-use current screen */
+ /* we re-use current window and screen */
+ win = CTX_wm_window(C);
curscreen = CTX_wm_screen(C);
- /* but use new Scene pointer */
+ /* but use Scene pointer from new file */
curscene = bfd->curscene;
+ cur_view_layer = bfd->cur_view_layer;
track_undo_scene = (mode == LOAD_UNDO && curscreen && curscene && bfd->main->wm.first);
@@ -184,34 +192,41 @@ static void setup_app_data(
if (curscene == NULL) {
curscene = BKE_scene_add(bfd->main, "Empty");
}
+ if (cur_view_layer == NULL) {
+ /* fallback to scene layer */
+ cur_view_layer = BKE_view_layer_default_view(curscene);
+ }
if (track_undo_scene) {
/* keep the old (free'd) scene, let 'blo_lib_link_screen_restore'
* replace it with 'curscene' if its needed */
}
- else {
- /* and we enforce curscene to be in current screen */
- if (curscreen) {
- /* can run in bgmode */
- curscreen->scene = curscene;
- }
+ /* and we enforce curscene to be in current screen */
+ else if (win) { /* can run in bgmode */
+ win->scene = curscene;
}
/* BKE_blender_globals_clear will free G.main, here we can still restore pointers */
- blo_lib_link_screen_restore(bfd->main, curscreen, curscene);
- /* curscreen might not be set when loading without ui (see T44217) so only re-assign if available */
- if (curscreen) {
- curscene = curscreen->scene;
+ blo_lib_link_restore(bfd->main, CTX_wm_manager(C), curscene, cur_view_layer);
+ if (win) {
+ curscene = win->scene;
}
if (track_undo_scene) {
wmWindowManager *wm = bfd->main->wm.first;
if (wm_scene_is_visible(wm, bfd->curscene) == false) {
curscene = bfd->curscene;
- curscreen->scene = curscene;
- BKE_screen_view3d_scene_sync(curscreen);
+ win->scene = curscene;
+ BKE_screen_view3d_scene_sync(curscreen, curscene);
}
}
+
+ /* We need to tag this here because events may be handled immediately after.
+ * only the current screen is important because we wont have to handle
+ * events from multiple screens at once.*/
+ {
+ BKE_screen_manipulator_tag_refresh(curscreen);
+ }
}
/* free G.main Main database */
@@ -226,6 +241,7 @@ static void setup_app_data(
CTX_data_main_set(C, G.main);
if (bfd->user) {
+
/* only here free userdef themes... */
BKE_blender_userdef_data_set_and_free(bfd->user);
bfd->user = NULL;
@@ -261,12 +277,14 @@ static void setup_app_data(
/* this can happen when active scene was lib-linked, and doesn't exist anymore */
if (CTX_data_scene(C) == NULL) {
+ wmWindow *win = CTX_wm_window(C);
+
/* in case we don't even have a local scene, add one */
if (!G.main->scene.first)
BKE_scene_add(G.main, "Empty");
CTX_data_scene_set(C, G.main->scene.first);
- CTX_wm_screen(C)->scene = CTX_data_scene(C);
+ win->scene = CTX_data_scene(C);
curscene = CTX_data_scene(C);
}
@@ -315,20 +333,27 @@ static void setup_app_data(
wmWindowManager *wm = G.main->wm.first;
if (wm) {
- wmWindow *win;
-
- for (win = wm->windows.first; win; win = win->next) {
- if (win->screen && win->screen->scene) /* zealous check... */
- if (win->screen->scene != curscene)
- BKE_scene_set_background(G.main, win->screen->scene);
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ if (win->scene && win->scene != curscene) {
+ BKE_scene_set_background(G.main, win->scene);
+ }
}
}
}
+
+ /* Setting scene might require having a dependency graph, with copy on write
+ * we need to make sure we ensure scene has correct color management before
+ * constructing dependency graph.
+ */
+ if (mode != LOAD_UNDO) {
+ IMB_colormanagement_check_file_config(G.main);
+ }
+
BKE_scene_set_background(G.main, curscene);
if (mode != LOAD_UNDO) {
+ /* TODO(sergey): Can this be also move above? */
RE_FreeAllPersistentData();
- IMB_colormanagement_check_file_config(G.main);
}
MEM_freeN(bfd);
@@ -534,6 +559,48 @@ bool BKE_blendfile_userdef_write_app_template(const char *filepath, ReportList *
return ok;
}
+WorkspaceConfigFileData *BKE_blendfile_workspace_config_read(const char *filepath, ReportList *reports)
+{
+ BlendFileData *bfd;
+ WorkspaceConfigFileData *workspace_config = NULL;
+
+ bfd = BLO_read_from_file(filepath, reports, BLO_READ_SKIP_USERDEF);
+ if (bfd) {
+ workspace_config = MEM_mallocN(sizeof(*workspace_config), __func__);
+ workspace_config->main = bfd->main;
+ workspace_config->workspaces = bfd->main->workspaces;
+
+ MEM_freeN(bfd);
+ }
+
+ return workspace_config;
+}
+
+bool BKE_blendfile_workspace_config_write(Main *bmain, const char *filepath, ReportList *reports)
+{
+ int fileflags = G.fileflags & ~(G_FILE_NO_UI | G_FILE_HISTORY);
+ bool retval = false;
+
+ BKE_blendfile_write_partial_begin(bmain);
+
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ BKE_blendfile_write_partial_tag_ID(&workspace->id, true);
+ }
+
+ if (BKE_blendfile_write_partial(bmain, filepath, fileflags, reports)) {
+ retval = true;
+ }
+
+ BKE_blendfile_write_partial_end(bmain);
+
+ return retval;
+}
+
+void BKE_blendfile_workspace_config_data_free(WorkspaceConfigFileData *workspace_config)
+{
+ BKE_main_free(workspace_config->main);
+ MEM_freeN(workspace_config);
+}
/** \} */
diff --git a/source/blender/blenkernel/intern/boids.c b/source/blender/blenkernel/intern/boids.c
index 024c0aeb23f..eb5cdd02fe5 100644
--- a/source/blender/blenkernel/intern/boids.c
+++ b/source/blender/blenkernel/intern/boids.c
@@ -132,6 +132,7 @@ static int rule_goal_avoid(BoidRule *rule, BoidBrainData *bbd, BoidValues *val,
if (eff == NULL && gabr->ob) {
memset(&temp_eff, 0, sizeof(EffectorCache));
temp_eff.ob = gabr->ob;
+ temp_eff.depsgraph = bbd->sim->depsgraph;
temp_eff.scene = bbd->sim->scene;
eff = &temp_eff;
get_effector_data(eff, &efd, &epoint, 0);
diff --git a/source/blender/blenkernel/intern/bpath.c b/source/blender/blenkernel/intern/bpath.c
index e9a8de4469d..259c5189896 100644
--- a/source/blender/blenkernel/intern/bpath.c
+++ b/source/blender/blenkernel/intern/bpath.c
@@ -580,14 +580,6 @@ void BKE_bpath_traverse_id(Main *bmain, ID *id, BPathVisitor visit_cb, const int
}
break;
}
- case ID_TE:
- {
- Tex *tex = (Tex *)id;
- if (tex->type == TEX_VOXELDATA && TEX_VD_IS_SOURCE_PATH(tex->vd->file_format)) {
- rewrite_path_fixed(tex->vd->source_path, visit_cb, absbase, bpath_user_data);
- }
- break;
- }
case ID_SCE:
{
Scene *scene = (Scene *)id;
diff --git a/source/blender/blenkernel/intern/bullet.c b/source/blender/blenkernel/intern/bullet.c
deleted file mode 100644
index c16c0f7af31..00000000000
--- a/source/blender/blenkernel/intern/bullet.c
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenkernel/intern/bullet.c
- * \ingroup bke
- */
-
-
-#include "MEM_guardedalloc.h"
-
-/* types */
-#include "DNA_object_force_types.h" /* here is the softbody struct */
-
-#include "BKE_bullet.h"
-
-
-/* ************ Object level, exported functions *************** */
-
-/* allocates and initializes general main data */
-BulletSoftBody *bsbNew(void)
-{
- BulletSoftBody *bsb;
-
- bsb = MEM_callocN(sizeof(BulletSoftBody), "bulletsoftbody");
-
- bsb->flag = OB_BSB_BENDING_CONSTRAINTS | OB_BSB_SHAPE_MATCHING | OB_BSB_AERO_VPOINT;
- bsb->linStiff = 0.5f;
- bsb->angStiff = 1.0f;
- bsb->volume = 1.0f;
-
-
- bsb->viterations = 0;
- bsb->piterations = 2;
- bsb->diterations = 0;
- bsb->citerations = 4;
-
- bsb->kSRHR_CL = 0.1f;
- bsb->kSKHR_CL = 1.f;
- bsb->kSSHR_CL = 0.5f;
- bsb->kSR_SPLT_CL = 0.5f;
-
- bsb->kSK_SPLT_CL = 0.5f;
- bsb->kSS_SPLT_CL = 0.5f;
- bsb->kVCF = 1;
- bsb->kDP = 0;
-
- bsb->kDG = 0;
- bsb->kLF = 0;
- bsb->kPR = 0;
- bsb->kVC = 0;
-
- bsb->kDF = 0.2f;
- bsb->kMT = 0.05;
- bsb->kCHR = 1.0f;
- bsb->kKHR = 0.1f;
-
- bsb->kSHR = 1.0f;
- bsb->kAHR = 0.7f;
-
- bsb->collisionflags = 0;
- //bsb->collisionflags = OB_BSB_COL_CL_RS + OB_BSB_COL_CL_SS;
- bsb->numclusteriterations = 64;
- bsb->welding = 0.f;
-
- return bsb;
-}
-
-/* frees all */
-void bsbFree(BulletSoftBody *bsb)
-{
- /* no internal data yet */
- MEM_freeN(bsb);
-}
-
-
diff --git a/source/blender/blenkernel/intern/cachefile.c b/source/blender/blenkernel/intern/cachefile.c
index 058394fc1b1..8f156e8f267 100644
--- a/source/blender/blenkernel/intern/cachefile.c
+++ b/source/blender/blenkernel/intern/cachefile.c
@@ -175,7 +175,7 @@ void BKE_cachefile_update_frame(Main *bmain, Scene *scene, const float ctime, co
const float time = BKE_cachefile_time_offset(cache_file, ctime, fps);
if (BKE_cachefile_filepath_get(bmain, cache_file, time, filename)) {
- BKE_cachefile_clean(scene, cache_file);
+ BKE_cachefile_clean(bmain, cache_file);
#ifdef WITH_ALEMBIC
ABC_free_handle(cache_file->handle);
cache_file->handle = ABC_create_handle(filename, NULL);
@@ -215,11 +215,9 @@ float BKE_cachefile_time_offset(CacheFile *cache_file, const float time, const f
}
/* TODO(kevin): replace this with some depsgraph mechanism, or something similar. */
-void BKE_cachefile_clean(Scene *scene, CacheFile *cache_file)
+void BKE_cachefile_clean(struct Main *bmain, CacheFile *cache_file)
{
- for (Base *base = scene->base.first; base; base = base->next) {
- Object *ob = base->object;
-
+ for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
ModifierData *md = modifiers_findByType(ob, eModifierType_MeshSequenceCache);
if (md) {
diff --git a/source/blender/blenkernel/intern/camera.c b/source/blender/blenkernel/intern/camera.c
index 132cbd07ac3..2c5cdc39ebc 100644
--- a/source/blender/blenkernel/intern/camera.c
+++ b/source/blender/blenkernel/intern/camera.c
@@ -40,6 +40,7 @@
#include "DNA_ID.h"
#include "BLI_math.h"
+#include "BLI_listbase.h"
#include "BLI_rect.h"
#include "BLI_string.h"
#include "BLI_utildefines.h"
@@ -47,6 +48,7 @@
#include "BKE_animsys.h"
#include "BKE_camera.h"
#include "BKE_object.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
@@ -54,7 +56,9 @@
#include "BKE_scene.h"
#include "BKE_screen.h"
-#include "GPU_compositing.h"
+#include "DEG_depsgraph_query.h"
+
+#include "MEM_guardedalloc.h"
/****************************** Camera Datablock *****************************/
@@ -72,8 +76,6 @@ void BKE_camera_init(Camera *cam)
cam->flag |= CAM_SHOWPASSEPARTOUT;
cam->passepartalpha = 0.5f;
- GPU_fx_compositor_init_dof_settings(&cam->gpu_dof);
-
/* stereoscopy 3d */
cam->stereo.interocular_distance = 0.065f;
cam->stereo.convergence_distance = 30.f * 0.065f;
@@ -100,9 +102,19 @@ void *BKE_camera_add(Main *bmain, const char *name)
*
* \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
*/
-void BKE_camera_copy_data(Main *UNUSED(bmain), Camera *UNUSED(cam_dst), const Camera *UNUSED(cam_src), const int UNUSED(flag))
+void BKE_camera_copy_data(Main *UNUSED(bmain), Camera *cam_dst, const Camera *cam_src, const int flag)
{
- /* Nothing to do! */
+ BLI_duplicatelist(&cam_dst->bg_images, &cam_src->bg_images);
+ if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
+ for (CameraBGImage *bgpic = cam_dst->bg_images.first; bgpic; bgpic = bgpic->next) {
+ if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
+ id_us_plus((ID *)bgpic->ima);
+ }
+ else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
+ id_us_plus((ID *)bgpic->clip);
+ }
+ }
+ }
}
Camera *BKE_camera_copy(Main *bmain, const Camera *cam)
@@ -120,6 +132,16 @@ void BKE_camera_make_local(Main *bmain, Camera *cam, const bool lib_local)
/** Free (or release) any data used by this camera (does not free the camera itself). */
void BKE_camera_free(Camera *ca)
{
+ for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) {
+ if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
+ id_us_min((ID *)bgpic->ima);
+ }
+ else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
+ id_us_min((ID *)bgpic->clip);
+ }
+ }
+ BLI_freelistN(&ca->bg_images);
+
BKE_animdata_free((ID *)ca, false);
}
@@ -237,7 +259,7 @@ void BKE_camera_params_from_object(CameraParams *params, const Object *ob)
}
}
-void BKE_camera_params_from_view3d(CameraParams *params, const View3D *v3d, const RegionView3D *rv3d)
+void BKE_camera_params_from_view3d(CameraParams *params, Depsgraph *depsgraph, const View3D *v3d, const RegionView3D *rv3d)
{
/* common */
params->lens = v3d->lens;
@@ -246,7 +268,8 @@ void BKE_camera_params_from_view3d(CameraParams *params, const View3D *v3d, cons
if (rv3d->persp == RV3D_CAMOB) {
/* camera view */
- BKE_camera_params_from_object(params, v3d->camera);
+ Object *camera_object = DEG_get_evaluated_object(depsgraph, v3d->camera);
+ BKE_camera_params_from_object(params, camera_object);
params->zoom = BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
@@ -281,10 +304,7 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win
float pixsize, viewfac, sensor_size, dx, dy;
int sensor_fit;
- /* fields rendering */
params->ycor = yasp / xasp;
- if (params->use_fields)
- params->ycor *= 2.0f;
if (params->is_ortho) {
/* orthographic camera */
@@ -326,18 +346,6 @@ void BKE_camera_params_compute_viewplane(CameraParams *params, int winx, int win
viewplane.xmax += dx;
viewplane.ymax += dy;
- /* fields offset */
- if (params->field_second) {
- if (params->field_odd) {
- viewplane.ymin -= 0.5f * params->ycor;
- viewplane.ymax -= 0.5f * params->ycor;
- }
- else {
- viewplane.ymin += 0.5f * params->ycor;
- viewplane.ymax += 0.5f * params->ycor;
- }
- }
-
/* the window matrix is used for clipping, and not changed during OSA steps */
/* using an offset of +0.5 here would give clip errors on edges */
viewplane.xmin *= pixsize;
@@ -641,7 +649,7 @@ static bool camera_frame_fit_calc_from_data(
/* don't move the camera, just yield the fit location */
/* r_scale only valid/useful for ortho cameras */
bool BKE_camera_view_frame_fit_to_scene(
- Scene *scene, struct View3D *v3d, Object *camera_ob, float r_co[3], float *r_scale)
+ Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer, Object *camera_ob, float r_co[3], float *r_scale)
{
CameraParams params;
CameraViewFrameData data_cb;
@@ -652,7 +660,7 @@ bool BKE_camera_view_frame_fit_to_scene(
camera_frame_fit_data_init(scene, camera_ob, &params, &data_cb);
/* run callback on all visible points */
- BKE_scene_foreach_display_point(scene, v3d, BA_SELECT, camera_to_frame_view_cb, &data_cb);
+ BKE_scene_foreach_display_point(depsgraph, scene, view_layer, camera_to_frame_view_cb, &data_cb);
return camera_frame_fit_calc_from_data(&params, &data_cb, r_co, r_scale);
}
@@ -861,9 +869,9 @@ static Object *camera_multiview_advanced(Scene *scene, Object *camera, const cha
}
if (name[0] != '\0') {
- Base *base = BKE_scene_base_find_by_name(scene, name);
- if (base) {
- return base->object;
+ Object *ob = BKE_scene_object_find_by_name(scene, name);
+ if (ob != NULL) {
+ return ob;
}
}
@@ -960,3 +968,38 @@ void BKE_camera_to_gpu_dof(struct Object *camera, struct GPUFXSettings *r_fx_set
r_fx_settings->dof->focus_distance = BKE_camera_object_dof_distance(camera);
}
}
+
+CameraBGImage *BKE_camera_background_image_new(Camera *cam)
+{
+ CameraBGImage *bgpic = MEM_callocN(sizeof(CameraBGImage), "Background Image");
+
+ bgpic->scale = 1.0f;
+ bgpic->alpha = 0.5f;
+ bgpic->iuser.fie_ima = 2;
+ bgpic->iuser.ok = 1;
+ bgpic->flag |= CAM_BGIMG_FLAG_EXPANDED;
+
+ BLI_addtail(&cam->bg_images, bgpic);
+
+ return bgpic;
+}
+
+void BKE_camera_background_image_remove(Camera *cam, CameraBGImage *bgpic)
+{
+ BLI_remlink(&cam->bg_images, bgpic);
+
+ MEM_freeN(bgpic);
+}
+
+void BKE_camera_background_image_clear(Camera *cam)
+{
+ CameraBGImage *bgpic = cam->bg_images.first;
+
+ while (bgpic) {
+ CameraBGImage *next_bgpic = bgpic->next;
+
+ BKE_camera_background_image_remove(cam, bgpic);
+
+ bgpic = next_bgpic;
+ }
+}
diff --git a/source/blender/blenkernel/intern/cdderivedmesh.c b/source/blender/blenkernel/intern/cdderivedmesh.c
index 1a34b71643f..46dd376e065 100644
--- a/source/blender/blenkernel/intern/cdderivedmesh.c
+++ b/source/blender/blenkernel/intern/cdderivedmesh.c
@@ -57,12 +57,6 @@
#include "MEM_guardedalloc.h"
-#include "GPU_buffers.h"
-#include "GPU_draw.h"
-#include "GPU_glew.h"
-#include "GPU_shader.h"
-#include "GPU_basic_shader.h"
-
#include <string.h>
#include <limits.h>
#include <math.h>
@@ -338,1450 +332,6 @@ static PBVH *cdDM_getPBVH(Object *ob, DerivedMesh *dm)
return cddm->pbvh;
}
-/* update vertex normals so that drawing smooth faces works during sculpt
- * TODO: proper fix is to support the pbvh in all drawing modes */
-static void cdDM_update_normals_from_pbvh(DerivedMesh *dm)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- float (*face_nors)[3];
-
- /* Some callbacks do not use optimal PBVH draw, so needs all the
- * possible data (like normals) to be copied from PBVH back to DM.
- *
- * This is safe to do if PBVH and DM are representing the same mesh,
- * which could be wrong when modifiers are enabled for sculpt.
- * So here we only doing update when there's no modifiers applied
- * during sculpt.
- *
- * It's safe to do nothing if there are modifiers, because in this
- * case modifier stack is re-constructed from scratch on every
- * update.
- */
- if (!cddm->pbvh_draw) {
- return;
- }
-
- face_nors = CustomData_get_layer(&dm->polyData, CD_NORMAL);
-
- BKE_pbvh_update(cddm->pbvh, PBVH_UpdateNormals, face_nors);
-}
-
-static void cdDM_drawVerts(DerivedMesh *dm)
-{
- GPU_vertex_setup(dm);
- if (dm->drawObject->tot_loop_verts)
- glDrawArrays(GL_POINTS, 0, dm->drawObject->tot_loop_verts);
- else
- glDrawArrays(GL_POINTS, 0, dm->drawObject->tot_loose_point);
- GPU_buffers_unbind();
-}
-
-static void cdDM_drawUVEdges(DerivedMesh *dm)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- const MPoly *mpoly = cddm->mpoly;
- int totpoly = dm->getNumPolys(dm);
- int prevstart = 0;
- bool prevdraw = true;
- int curpos = 0;
- int i;
-
- GPU_uvedge_setup(dm);
- for (i = 0; i < totpoly; i++, mpoly++) {
- const bool draw = (mpoly->flag & ME_HIDE) == 0;
-
- if (prevdraw != draw) {
- if (prevdraw && (curpos != prevstart)) {
- glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
- }
- prevstart = curpos;
- }
-
- curpos += 2 * mpoly->totloop;
- prevdraw = draw;
- }
- if (prevdraw && (curpos != prevstart)) {
- glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
- }
- GPU_buffers_unbind();
-}
-
-static void cdDM_drawEdges(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEdges)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- GPUDrawObject *gdo;
- if (cddm->pbvh && cddm->pbvh_draw &&
- BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH)
- {
- BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, true, false);
-
- return;
- }
-
- GPU_edge_setup(dm);
- gdo = dm->drawObject;
- if (gdo->edges && gdo->points) {
- if (drawAllEdges && drawLooseEdges) {
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->totedge * 2);
- }
- else if (drawAllEdges) {
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->loose_edge_offset * 2);
- }
- else {
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->tot_edge_drawn * 2);
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, gdo->loose_edge_offset * 2, dm->drawObject->tot_loose_edge_drawn * 2);
- }
- }
- GPU_buffers_unbind();
-}
-
-static void cdDM_drawLooseEdges(DerivedMesh *dm)
-{
- int start;
- int count;
-
- GPU_edge_setup(dm);
-
- start = (dm->drawObject->loose_edge_offset * 2);
- count = (dm->drawObject->totedge - dm->drawObject->loose_edge_offset) * 2;
-
- if (count) {
- GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, start, count);
- }
-
- GPU_buffers_unbind();
-}
-
-static void cdDM_drawFacesSolid(
- DerivedMesh *dm,
- float (*partial_redraw_planes)[4],
- bool UNUSED(fast), DMSetMaterial setMaterial)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- int a;
-
- if (cddm->pbvh) {
- if (cddm->pbvh_draw && BKE_pbvh_has_faces(cddm->pbvh)) {
- float (*face_nors)[3] = CustomData_get_layer(&dm->polyData, CD_NORMAL);
-
- BKE_pbvh_draw(cddm->pbvh, partial_redraw_planes, face_nors,
- setMaterial, false, false);
- return;
- }
- }
-
- GPU_vertex_setup(dm);
- GPU_normal_setup(dm);
- GPU_triangle_setup(dm);
- for (a = 0; a < dm->drawObject->totmaterial; a++) {
- if (!setMaterial || setMaterial(dm->drawObject->materials[a].mat_nr + 1, NULL)) {
- GPU_buffer_draw_elements(
- dm->drawObject->triangles, GL_TRIANGLES,
- dm->drawObject->materials[a].start, dm->drawObject->materials[a].totelements);
- }
- }
- GPU_buffers_unbind();
-}
-
-static void cdDM_drawFacesTex_common(
- DerivedMesh *dm,
- DMSetDrawOptionsTex drawParams,
- DMSetDrawOptionsMappedTex drawParamsMapped,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- const MPoly *mpoly = cddm->mpoly;
- MTexPoly *mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY);
- const MLoopCol *mloopcol = NULL;
- int i;
- int colType, start_element, tot_drawn;
- const bool use_hide = (flag & DM_DRAW_SKIP_HIDDEN) != 0;
- const bool use_tface = (flag & DM_DRAW_USE_ACTIVE_UV) != 0;
- const bool use_colors = (flag & DM_DRAW_USE_COLORS) != 0;
- int totpoly;
- int next_actualFace;
- int mat_index;
- int tot_element;
-
- /* double lookup */
- const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
-
- /* TODO: not entirely correct, but currently dynamic topology will
- * destroy UVs anyway, so textured display wouldn't work anyway
- *
- * this will do more like solid view with lights set up for
- * textured view, but object itself will be displayed gray
- * (the same as it'll display without UV maps in textured view)
- */
- if (cddm->pbvh) {
- if (cddm->pbvh_draw &&
- BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH &&
- BKE_pbvh_has_faces(cddm->pbvh))
- {
- GPU_set_tpage(NULL, false, false);
- BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
- return;
- }
- else {
- cdDM_update_normals_from_pbvh(dm);
- }
- }
-
- if (use_colors) {
- colType = CD_TEXTURE_MLOOPCOL;
- mloopcol = dm->getLoopDataArray(dm, colType);
- if (!mloopcol) {
- colType = CD_PREVIEW_MLOOPCOL;
- mloopcol = dm->getLoopDataArray(dm, colType);
- }
- if (!mloopcol) {
- colType = CD_MLOOPCOL;
- mloopcol = dm->getLoopDataArray(dm, colType);
- }
- }
-
- GPU_vertex_setup(dm);
- GPU_normal_setup(dm);
- GPU_triangle_setup(dm);
- if (flag & DM_DRAW_USE_TEXPAINT_UV)
- GPU_texpaint_uv_setup(dm);
- else
- GPU_uv_setup(dm);
- if (mloopcol) {
- GPU_color_setup(dm, colType);
- }
-
- /* lastFlag = 0; */ /* UNUSED */
- for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
- GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index;
- next_actualFace = bufmat->polys[0];
- totpoly = bufmat->totpolys;
-
- tot_element = 0;
- tot_drawn = 0;
- start_element = 0;
-
- for (i = 0; i < totpoly; i++) {
- int actualFace = bufmat->polys[i];
- DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
- int flush = 0;
- int tot_tri_verts;
-
- if (i != totpoly - 1)
- next_actualFace = bufmat->polys[i + 1];
-
- if (use_hide && (mpoly[actualFace].flag & ME_HIDE)) {
- draw_option = DM_DRAW_OPTION_SKIP;
- }
- else if (drawParams) {
- MTexPoly *tp = use_tface && mtexpoly ? &mtexpoly[actualFace] : NULL;
- draw_option = drawParams(tp, (mloopcol != NULL), mpoly[actualFace].mat_nr);
- }
- else {
- if (index_mp_to_orig) {
- const int orig = index_mp_to_orig[actualFace];
- if (orig == ORIGINDEX_NONE) {
- /* XXX, this is not really correct
- * it will draw the previous faces context for this one when we don't know its settings.
- * but better then skipping it altogether. - campbell */
- draw_option = DM_DRAW_OPTION_NORMAL;
- }
- else if (drawParamsMapped) {
- draw_option = drawParamsMapped(userData, orig, mpoly[actualFace].mat_nr);
- }
- }
- else if (drawParamsMapped) {
- draw_option = drawParamsMapped(userData, actualFace, mpoly[actualFace].mat_nr);
- }
- }
-
- /* flush buffer if current triangle isn't drawable or it's last triangle */
- flush = (draw_option == DM_DRAW_OPTION_SKIP) || (i == totpoly - 1);
-
- if (!flush && compareDrawOptions) {
- /* also compare draw options and flush buffer if they're different
- * need for face selection highlight in edit mode */
- flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
- }
-
- tot_tri_verts = ME_POLY_TRI_TOT(&mpoly[actualFace]) * 3;
- tot_element += tot_tri_verts;
-
- if (flush) {
- if (draw_option != DM_DRAW_OPTION_SKIP)
- tot_drawn += tot_tri_verts;
-
- if (tot_drawn) {
- if (mloopcol && draw_option != DM_DRAW_OPTION_NO_MCOL)
- GPU_color_switch(1);
- else
- GPU_color_switch(0);
-
- GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, bufmat->start + start_element, tot_drawn);
- tot_drawn = 0;
- }
- start_element = tot_element;
- }
- else {
- tot_drawn += tot_tri_verts;
- }
- }
- }
-
- GPU_buffers_unbind();
-
-}
-
-static void cdDM_drawFacesTex(
- DerivedMesh *dm,
- DMSetDrawOptionsTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- cdDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData, flag);
-}
-
-static void cdDM_drawMappedFaces(
- DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetMaterial setMaterial,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- const MPoly *mpoly = cddm->mpoly;
- const MLoopCol *mloopcol = NULL;
- const bool use_colors = (flag & DM_DRAW_USE_COLORS) != 0;
- const bool use_hide = (flag & DM_DRAW_SKIP_HIDDEN) != 0;
- int colType;
- int i, j;
- int start_element = 0, tot_element, tot_drawn;
- int totpoly;
- int tot_tri_elem;
- int mat_index;
- GPUBuffer *findex_buffer = NULL;
-
- const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
-
- if (cddm->pbvh) {
- if (G.debug_value == 14)
- BKE_pbvh_draw_BB(cddm->pbvh);
- }
-
- /* fist, setup common buffers */
- GPU_vertex_setup(dm);
- GPU_triangle_setup(dm);
-
- totpoly = dm->getNumPolys(dm);
-
- /* if we do selection, fill the selection buffer color */
- if (G.f & G_BACKBUFSEL) {
- if (!(flag & DM_DRAW_SKIP_SELECT)) {
- Mesh *me = NULL;
- BMesh *bm = NULL;
- unsigned int *fi_map;
-
- if (flag & DM_DRAW_SELECT_USE_EDITMODE)
- bm = userData;
- else
- me = userData;
-
- findex_buffer = GPU_buffer_alloc(dm->drawObject->tot_loop_verts * sizeof(int));
- fi_map = GPU_buffer_lock(findex_buffer, GPU_BINDING_ARRAY);
-
- if (fi_map) {
- for (i = 0; i < totpoly; i++, mpoly++) {
- int selcol = 0xFFFFFFFF;
- const int orig = (index_mp_to_orig) ? index_mp_to_orig[i] : i;
- bool is_hidden;
-
- if (orig != ORIGINDEX_NONE) {
- if (use_hide) {
- if (flag & DM_DRAW_SELECT_USE_EDITMODE) {
- BMFace *efa = BM_face_at_index(bm, orig);
- is_hidden = BM_elem_flag_test(efa, BM_ELEM_HIDDEN) != 0;
- }
- else {
- is_hidden = (me->mpoly[orig].flag & ME_HIDE) != 0;
- }
-
- if (!is_hidden) {
- GPU_select_index_get(orig + 1, &selcol);
- }
- }
- else {
- GPU_select_index_get(orig + 1, &selcol);
- }
- }
-
- for (j = 0; j < mpoly->totloop; j++)
- fi_map[start_element++] = selcol;
- }
-
- start_element = 0;
- mpoly = cddm->mpoly;
-
- GPU_buffer_unlock(findex_buffer, GPU_BINDING_ARRAY);
- GPU_buffer_bind_as_color(findex_buffer);
- }
- }
- }
- else {
- GPU_normal_setup(dm);
-
- if (use_colors) {
- colType = CD_TEXTURE_MLOOPCOL;
- mloopcol = DM_get_loop_data_layer(dm, colType);
- if (!mloopcol) {
- colType = CD_PREVIEW_MLOOPCOL;
- mloopcol = DM_get_loop_data_layer(dm, colType);
- }
- if (!mloopcol) {
- colType = CD_MLOOPCOL;
- mloopcol = DM_get_loop_data_layer(dm, colType);
- }
-
- if (use_colors && mloopcol) {
- GPU_color_setup(dm, colType);
- }
- }
- }
-
- tot_tri_elem = dm->drawObject->tot_triangle_point;
-
- if (tot_tri_elem == 0) {
- /* avoid buffer problems in following code */
- }
- else if (setDrawOptions == NULL) {
- /* just draw the entire face array */
- GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, 0, tot_tri_elem);
- }
- else {
- for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
- GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index;
- DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
- int next_actualFace = bufmat->polys[0];
- totpoly = use_hide ? bufmat->totvisiblepolys : bufmat->totpolys;
-
- tot_element = 0;
- start_element = 0;
- tot_drawn = 0;
-
- if (setMaterial)
- draw_option = setMaterial(bufmat->mat_nr + 1, NULL);
-
- if (draw_option != DM_DRAW_OPTION_SKIP) {
- DMDrawOption last_draw_option = DM_DRAW_OPTION_NORMAL;
-
- for (i = 0; i < totpoly; i++) {
- int actualFace = next_actualFace;
- int flush = 0;
- int tot_tri_verts;
-
- draw_option = DM_DRAW_OPTION_NORMAL;
-
- if (i != totpoly - 1)
- next_actualFace = bufmat->polys[i + 1];
-
- if (setDrawOptions) {
- const int orig = (index_mp_to_orig) ? index_mp_to_orig[actualFace] : actualFace;
-
- if (orig != ORIGINDEX_NONE) {
- draw_option = setDrawOptions(userData, orig);
- }
- }
-
- /* Goal is to draw as long of a contiguous triangle
- * array as possible, so draw when we hit either an
- * invisible triangle or at the end of the array */
-
- /* flush buffer if current triangle isn't drawable or it's last triangle... */
- flush = (draw_option != last_draw_option) || (i == totpoly - 1);
-
- if (!flush && compareDrawOptions) {
- flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
- }
-
- tot_tri_verts = ME_POLY_TRI_TOT(&mpoly[actualFace]) * 3;
- tot_element += tot_tri_verts;
-
- if (flush) {
- if (draw_option != DM_DRAW_OPTION_SKIP) {
- tot_drawn += tot_tri_verts;
-
- if (last_draw_option != draw_option) {
- if (draw_option == DM_DRAW_OPTION_STIPPLE) {
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
- }
- else {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
- }
- }
-
- if (tot_drawn) {
- GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, bufmat->start + start_element, tot_drawn);
- tot_drawn = 0;
- }
-
- last_draw_option = draw_option;
- start_element = tot_element;
- }
- else {
- if (draw_option != DM_DRAW_OPTION_SKIP) {
- tot_drawn += tot_tri_verts;
- }
- else {
- start_element = tot_element;
- }
- }
- }
- }
- }
- }
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
- GPU_buffers_unbind();
-
- if (findex_buffer)
- GPU_buffer_free(findex_buffer);
-
-}
-
-static void cdDM_drawMappedFacesTex(
- DerivedMesh *dm,
- DMSetDrawOptionsMappedTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- cdDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData, flag);
-}
-
-static void cddm_draw_attrib_vertex(
- DMVertexAttribs *attribs, const MVert *mvert, int a, int index, int loop, int vert,
- const float *lnor, const bool smoothnormal)
-{
- DM_draw_attrib_vertex(attribs, a, index, vert, loop);
-
- /* vertex normal */
- if (lnor) {
- glNormal3fv(lnor);
- }
- else if (smoothnormal) {
- glNormal3sv(mvert[index].no);
- }
-
- /* vertex coordinate */
- glVertex3fv(mvert[index].co);
-}
-
-typedef struct {
- DMVertexAttribs attribs;
- int numdata;
-
- GPUAttrib datatypes[GPU_MAX_ATTRIB]; /* TODO, messing up when switching materials many times - [#21056]*/
-} GPUMaterialConv;
-
-static void cdDM_drawMappedFacesGLSL(
- DerivedMesh *dm,
- DMSetMaterial setMaterial,
- DMSetDrawOptions setDrawOptions,
- void *userData)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- GPUVertexAttribs gattribs;
- const MVert *mvert = cddm->mvert;
- const MPoly *mpoly = cddm->mpoly;
- const MLoop *mloop = cddm->mloop;
- const MLoopTri *lt = dm->getLoopTriArray(dm);
- const int tottri = dm->getNumLoopTri(dm);
- /* MTFace *tf = dm->getTessFaceDataArray(dm, CD_MTFACE); */ /* UNUSED */
- const float (*nors)[3] = dm->getPolyDataArray(dm, CD_NORMAL);
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- const int totpoly = dm->getNumPolys(dm);
- const short dm_totmat = dm->totmat;
- int a, b, matnr, new_matnr;
- bool do_draw;
- int orig;
-
- const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
-
- /* TODO: same as for solid draw, not entirely correct, but works fine for now,
- * will skip using textures (dyntopo currently destroys UV anyway) and
- * works fine for matcap
- */
- if (cddm->pbvh) {
- if (cddm->pbvh_draw &&
- BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH &&
- BKE_pbvh_has_faces(cddm->pbvh))
- {
- setMaterial(1, &gattribs);
- BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
- return;
- }
- else {
- cdDM_update_normals_from_pbvh(dm);
- }
- }
-
- matnr = -1;
- do_draw = false;
-
- if (setDrawOptions != NULL) {
- DMVertexAttribs attribs;
- DEBUG_VBO("Using legacy code. cdDM_drawMappedFacesGLSL\n");
- memset(&attribs, 0, sizeof(attribs));
-
- glBegin(GL_TRIANGLES);
-
- for (a = 0; a < tottri; a++, lt++) {
- const MPoly *mp = &mpoly[lt->poly];
- const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v};
- const unsigned int *ltri = lt->tri;
- const float *ln1 = NULL, *ln2 = NULL, *ln3 = NULL;
- const bool smoothnormal = lnors || (mp->flag & ME_SMOOTH);
- new_matnr = mp->mat_nr;
-
- if (new_matnr != matnr) {
- glEnd();
-
- matnr = new_matnr;
- do_draw = setMaterial(matnr + 1, &gattribs);
- if (do_draw) {
- DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
- DM_draw_attrib_vertex_uniforms(&attribs);
- }
-
- glBegin(GL_TRIANGLES);
- }
-
- if (!do_draw) {
- continue;
- }
- else /* if (setDrawOptions) */ {
- orig = (index_mp_to_orig) ? index_mp_to_orig[lt->poly] : lt->poly;
-
- if (orig == ORIGINDEX_NONE) {
- /* since the material is set by setMaterial(), faces with no
- * origin can be assumed to be generated by a modifier */
-
- /* continue */
- }
- else if (setDrawOptions(userData, orig) == DM_DRAW_OPTION_SKIP)
- continue;
- }
-
- if (!smoothnormal) {
- if (nors) {
- glNormal3fv(nors[lt->poly]);
- }
- else {
- /* TODO ideally a normal layer should always be available */
- float nor[3];
- normal_tri_v3(nor, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co);
- glNormal3fv(nor);
- }
- }
- else if (lnors) {
- ln1 = lnors[ltri[0]];
- ln2 = lnors[ltri[1]];
- ln3 = lnors[ltri[2]];
- }
-
- cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[0], ltri[0], 0, ln1, smoothnormal);
- cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[1], ltri[1], 1, ln2, smoothnormal);
- cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal);
- }
- glEnd();
- }
- else {
- GPUMaterialConv *matconv;
- int offset;
- int *mat_orig_to_new;
- int tot_active_mat;
- GPUBuffer *buffer = NULL;
- unsigned char *varray;
- size_t max_element_size = 0;
- int tot_loops = 0;
-
- GPU_vertex_setup(dm);
- GPU_normal_setup(dm);
- GPU_triangle_setup(dm);
-
- tot_active_mat = dm->drawObject->totmaterial;
-
- matconv = MEM_calloc_arrayN(tot_active_mat, sizeof(*matconv),
- "cdDM_drawMappedFacesGLSL.matconv");
- mat_orig_to_new = MEM_malloc_arrayN(dm->totmat, sizeof(*mat_orig_to_new),
- "cdDM_drawMappedFacesGLSL.mat_orig_to_new");
-
- /* part one, check what attributes are needed per material */
- for (a = 0; a < tot_active_mat; a++) {
- new_matnr = dm->drawObject->materials[a].mat_nr;
-
- /* map from original material index to new
- * GPUBufferMaterial index */
- mat_orig_to_new[new_matnr] = a;
- do_draw = setMaterial(new_matnr + 1, &gattribs);
-
- if (do_draw) {
- int numdata = 0;
- DM_vertex_attributes_from_gpu(dm, &gattribs, &matconv[a].attribs);
-
- if (matconv[a].attribs.totorco && matconv[a].attribs.orco.array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.orco.gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.orco.gl_info_index;
- matconv[a].datatypes[numdata].size = 3;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
- }
- for (b = 0; b < matconv[a].attribs.tottface; b++) {
- if (matconv[a].attribs.tface[b].array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.tface[b].gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.tface[b].gl_info_index;
- matconv[a].datatypes[numdata].size = 2;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
- }
- }
- for (b = 0; b < matconv[a].attribs.totmcol; b++) {
- if (matconv[a].attribs.mcol[b].array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.mcol[b].gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.mcol[b].gl_info_index;
- matconv[a].datatypes[numdata].size = 4;
- matconv[a].datatypes[numdata].type = GL_UNSIGNED_BYTE;
- numdata++;
- }
- }
- for (b = 0; b < matconv[a].attribs.tottang; b++) {
- if (matconv[a].attribs.tang[b].array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.tang[b].gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.tang[b].gl_info_index;
- matconv[a].datatypes[numdata].size = 4;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
- }
- }
- if (numdata != 0) {
- matconv[a].numdata = numdata;
- max_element_size = max_ii(GPU_attrib_element_size(matconv[a].datatypes, numdata), max_element_size);
- }
- }
- }
-
- /* part two, generate and fill the arrays with the data */
- if (max_element_size > 0) {
- buffer = GPU_buffer_alloc(max_element_size * dm->drawObject->tot_loop_verts);
-
- varray = GPU_buffer_lock_stream(buffer, GPU_BINDING_ARRAY);
- if (varray == NULL) {
- GPU_buffers_unbind();
- GPU_buffer_free(buffer);
- MEM_freeN(mat_orig_to_new);
- MEM_freeN(matconv);
- fprintf(stderr, "Out of memory, can't draw object\n");
- return;
- }
-
- for (a = 0; a < totpoly; a++, mpoly++) {
- const short mat_nr = ME_MAT_NR_TEST(mpoly->mat_nr, dm_totmat);
- int j;
- int i = mat_orig_to_new[mat_nr];
- offset = tot_loops * max_element_size;
-
- if (matconv[i].numdata != 0) {
- if (matconv[i].attribs.totorco && matconv[i].attribs.orco.array) {
- for (j = 0; j < mpoly->totloop; j++)
- copy_v3_v3((float *)&varray[offset + j * max_element_size],
- (float *)matconv[i].attribs.orco.array[mloop[mpoly->loopstart + j].v]);
- offset += sizeof(float) * 3;
- }
- for (b = 0; b < matconv[i].attribs.tottface; b++) {
- if (matconv[i].attribs.tface[b].array) {
- const MLoopUV *mloopuv = matconv[i].attribs.tface[b].array;
- for (j = 0; j < mpoly->totloop; j++)
- copy_v2_v2((float *)&varray[offset + j * max_element_size], mloopuv[mpoly->loopstart + j].uv);
- offset += sizeof(float) * 2;
- }
- }
- for (b = 0; b < matconv[i].attribs.totmcol; b++) {
- if (matconv[i].attribs.mcol[b].array) {
- const MLoopCol *mloopcol = matconv[i].attribs.mcol[b].array;
- for (j = 0; j < mpoly->totloop; j++)
- copy_v4_v4_uchar(&varray[offset + j * max_element_size], &mloopcol[mpoly->loopstart + j].r);
- offset += sizeof(unsigned char) * 4;
- }
- }
- for (b = 0; b < matconv[i].attribs.tottang; b++) {
- if (matconv[i].attribs.tottang && matconv[i].attribs.tang[b].array) {
- const float (*looptang)[4] = (const float (*)[4])matconv[i].attribs.tang[b].array;
- for (j = 0; j < mpoly->totloop; j++)
- copy_v4_v4((float *)&varray[offset + j * max_element_size], looptang[mpoly->loopstart + j]);
- offset += sizeof(float) * 4;
- }
- }
- }
-
- tot_loops += mpoly->totloop;
- }
- GPU_buffer_unlock(buffer, GPU_BINDING_ARRAY);
- }
-
- for (a = 0; a < tot_active_mat; a++) {
- new_matnr = dm->drawObject->materials[a].mat_nr;
-
- do_draw = setMaterial(new_matnr + 1, &gattribs);
-
- if (do_draw) {
- if (matconv[a].numdata) {
- GPU_interleaved_attrib_setup(buffer, matconv[a].datatypes, matconv[a].numdata, max_element_size);
- }
- GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES,
- dm->drawObject->materials[a].start, dm->drawObject->materials[a].totelements);
- if (matconv[a].numdata) {
- GPU_interleaved_attrib_unbind();
- }
- }
- }
-
- GPU_buffers_unbind();
- if (buffer)
- GPU_buffer_free(buffer);
-
- MEM_freeN(mat_orig_to_new);
- MEM_freeN(matconv);
- }
-}
-
-static void cdDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
-{
- dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
-}
-
-static void cdDM_drawMappedFacesMat(
- DerivedMesh *dm,
- void (*setMaterial)(void *userData, int matnr, void *attribs),
- bool (*setFace)(void *userData, int index), void *userData)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- GPUVertexAttribs gattribs;
- DMVertexAttribs attribs;
- MVert *mvert = cddm->mvert;
- const MPoly *mpoly = cddm->mpoly;
- const MLoop *mloop = cddm->mloop;
- const MLoopTri *lt = dm->getLoopTriArray(dm);
- const int tottri = dm->getNumLoopTri(dm);
- const float (*nors)[3] = dm->getPolyDataArray(dm, CD_NORMAL);
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- int a, matnr, new_matnr;
- int orig;
-
- const int *index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
-
- /* TODO: same as for solid draw, not entirely correct, but works fine for now,
- * will skip using textures (dyntopo currently destroys UV anyway) and
- * works fine for matcap
- */
-
- if (cddm->pbvh) {
- if (cddm->pbvh_draw &&
- BKE_pbvh_type(cddm->pbvh) == PBVH_BMESH &&
- BKE_pbvh_has_faces(cddm->pbvh))
- {
- setMaterial(userData, 1, &gattribs);
- BKE_pbvh_draw(cddm->pbvh, NULL, NULL, NULL, false, false);
- return;
- }
- else {
- cdDM_update_normals_from_pbvh(dm);
- }
- }
-
- matnr = -1;
-
- memset(&attribs, 0, sizeof(attribs));
-
- glBegin(GL_TRIANGLES);
-
- for (a = 0; a < tottri; a++, lt++) {
- const MPoly *mp = &mpoly[lt->poly];
- const unsigned int vtri[3] = {mloop[lt->tri[0]].v, mloop[lt->tri[1]].v, mloop[lt->tri[2]].v};
- const unsigned int *ltri = lt->tri;
- const bool smoothnormal = lnors || (mp->flag & ME_SMOOTH);
- const float *ln1 = NULL, *ln2 = NULL, *ln3 = NULL;
-
- /* material */
- new_matnr = mp->mat_nr + 1;
-
- if (new_matnr != matnr) {
- glEnd();
-
- setMaterial(userData, matnr = new_matnr, &gattribs);
- DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
- DM_draw_attrib_vertex_uniforms(&attribs);
-
- glBegin(GL_TRIANGLES);
- }
-
- /* skipping faces */
- if (setFace) {
- orig = (index_mp_to_orig) ? index_mp_to_orig[lt->poly] : lt->poly;
-
- if (orig != ORIGINDEX_NONE && !setFace(userData, orig))
- continue;
- }
-
- /* smooth normal */
- if (!smoothnormal) {
- if (nors) {
- glNormal3fv(nors[lt->poly]);
- }
- else {
- /* TODO ideally a normal layer should always be available */
- float nor[3];
- normal_tri_v3(nor, mvert[vtri[0]].co, mvert[vtri[1]].co, mvert[vtri[2]].co);
- glNormal3fv(nor);
- }
- }
- else if (lnors) {
- ln1 = lnors[ltri[0]];
- ln2 = lnors[ltri[1]];
- ln3 = lnors[ltri[2]];
- }
-
- /* vertices */
- cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[0], ltri[0], 0, ln1, smoothnormal);
- cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[1], ltri[1], 1, ln2, smoothnormal);
- cddm_draw_attrib_vertex(&attribs, mvert, a, vtri[2], ltri[2], 2, ln3, smoothnormal);
- }
- glEnd();
-}
-
-static void cdDM_drawMappedEdges(DerivedMesh *dm, DMSetDrawOptions setDrawOptions, void *userData)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *) dm;
- MVert *vert = cddm->mvert;
- MEdge *edge = cddm->medge;
- int i, orig, *index = DM_get_edge_data_layer(dm, CD_ORIGINDEX);
-
- glBegin(GL_LINES);
- for (i = 0; i < dm->numEdgeData; i++, edge++) {
- if (index) {
- orig = *index++;
- if (setDrawOptions && orig == ORIGINDEX_NONE) continue;
- }
- else
- orig = i;
-
- if (!setDrawOptions || (setDrawOptions(userData, orig) != DM_DRAW_OPTION_SKIP)) {
- glVertex3fv(vert[edge->v1].co);
- glVertex3fv(vert[edge->v2].co);
- }
- }
- glEnd();
-}
-
-typedef struct FaceCount {
- unsigned int i_visible;
- unsigned int i_hidden;
- unsigned int i_tri_visible;
- unsigned int i_tri_hidden;
-} FaceCount;
-
-static void cdDM_buffer_copy_triangles(
- DerivedMesh *dm, unsigned int *varray,
- const int *mat_orig_to_new)
-{
- GPUBufferMaterial *gpumat, *gpumaterials = dm->drawObject->materials;
- int i, j, start;
-
- const int gpu_totmat = dm->drawObject->totmaterial;
- const short dm_totmat = dm->totmat;
- const MPoly *mpoly = dm->getPolyArray(dm);
- const MLoopTri *lt = dm->getLoopTriArray(dm);
- const int totpoly = dm->getNumPolys(dm);
-
- FaceCount *fc = MEM_malloc_arrayN(gpu_totmat, sizeof(*fc), "gpumaterial.facecount");
-
- for (i = 0; i < gpu_totmat; i++) {
- fc[i].i_visible = 0;
- fc[i].i_tri_visible = 0;
- fc[i].i_hidden = gpumaterials[i].totpolys - 1;
- fc[i].i_tri_hidden = gpumaterials[i].totelements - 1;
- }
-
- for (i = 0; i < totpoly; i++) {
- const short mat_nr = ME_MAT_NR_TEST(mpoly[i].mat_nr, dm_totmat);
- int tottri = ME_POLY_TRI_TOT(&mpoly[i]);
- int mati = mat_orig_to_new[mat_nr];
- gpumat = gpumaterials + mati;
-
- if (mpoly[i].flag & ME_HIDE) {
- for (j = 0; j < tottri; j++, lt++) {
- start = gpumat->start + fc[mati].i_tri_hidden;
- /* v1 v2 v3 */
- varray[start--] = lt->tri[2];
- varray[start--] = lt->tri[1];
- varray[start--] = lt->tri[0];
- fc[mati].i_tri_hidden -= 3;
- }
- gpumat->polys[fc[mati].i_hidden--] = i;
- }
- else {
- for (j = 0; j < tottri; j++, lt++) {
- start = gpumat->start + fc[mati].i_tri_visible;
- /* v1 v2 v3 */
- varray[start++] = lt->tri[0];
- varray[start++] = lt->tri[1];
- varray[start++] = lt->tri[2];
- fc[mati].i_tri_visible += 3;
- }
- gpumat->polys[fc[mati].i_visible++] = i;
- }
- }
-
- /* set the visible polygons */
- for (i = 0; i < gpu_totmat; i++) {
- gpumaterials[i].totvisiblepolys = fc[i].i_visible;
- }
-
- MEM_freeN(fc);
-}
-
-static void cdDM_buffer_copy_vertex(
- DerivedMesh *dm, float *varray)
-{
- const MVert *mvert;
- const MPoly *mpoly;
- const MLoop *mloop;
-
- int i, j, start, totpoly;
-
- mvert = dm->getVertArray(dm);
- mpoly = dm->getPolyArray(dm);
- mloop = dm->getLoopArray(dm);
- totpoly = dm->getNumPolys(dm);
-
- start = 0;
-
- for (i = 0; i < totpoly; i++, mpoly++) {
- for (j = 0; j < mpoly->totloop; j++) {
- copy_v3_v3(&varray[start], mvert[mloop[mpoly->loopstart + j].v].co);
- start += 3;
- }
- }
-
- /* copy loose points */
- j = dm->drawObject->tot_loop_verts * 3;
- for (i = 0; i < dm->drawObject->totvert; i++) {
- if (dm->drawObject->vert_points[i].point_index >= dm->drawObject->tot_loop_verts) {
- copy_v3_v3(&varray[j], mvert[i].co);
- j += 3;
- }
- }
-}
-
-static void cdDM_buffer_copy_normal(
- DerivedMesh *dm, short *varray)
-{
- CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
- int i, j, totpoly;
- int start;
-
- const float (*nors)[3] = dm->getPolyDataArray(dm, CD_NORMAL);
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
-
- const MVert *mvert;
- const MPoly *mpoly;
- const MLoop *mloop;
-
- mvert = dm->getVertArray(dm);
- mpoly = dm->getPolyArray(dm);
- mloop = dm->getLoopArray(dm);
- totpoly = dm->getNumPolys(dm);
-
- /* we are in sculpt mode, disable loop normals (since they won't get updated) */
- if (cddm->pbvh)
- lnors = NULL;
-
- start = 0;
- for (i = 0; i < totpoly; i++, mpoly++) {
- const bool smoothnormal = (mpoly->flag & ME_SMOOTH) != 0;
-
- if (lnors) {
- /* Copy loop normals */
- for (j = 0; j < mpoly->totloop; j++, start += 4) {
- normal_float_to_short_v3(&varray[start], lnors[mpoly->loopstart + j]);
- }
- }
- else if (smoothnormal) {
- /* Copy vertex normal */
- for (j = 0; j < mpoly->totloop; j++, start += 4) {
- copy_v3_v3_short(&varray[start], mvert[mloop[mpoly->loopstart + j].v].no);
- }
- }
- else {
- /* Copy cached OR calculated face normal */
- short f_no_s[3];
-
- if (nors) {
- normal_float_to_short_v3(f_no_s, nors[i]);
- }
- else {
- float f_no[3];
- BKE_mesh_calc_poly_normal(mpoly, &mloop[mpoly->loopstart], mvert, f_no);
- normal_float_to_short_v3(f_no_s, f_no);
- }
-
- for (j = 0; j < mpoly->totloop; j++, start += 4) {
- copy_v3_v3_short(&varray[start], f_no_s);
- }
- }
- }
-}
-
-static void cdDM_buffer_copy_uv(
- DerivedMesh *dm, float *varray)
-{
- int i, j, totpoly;
- int start;
-
- const MPoly *mpoly;
- const MLoopUV *mloopuv;
-
- if ((mloopuv = DM_get_loop_data_layer(dm, CD_MLOOPUV)) == NULL) {
- return;
- }
-
- mpoly = dm->getPolyArray(dm);
- totpoly = dm->getNumPolys(dm);
-
- start = 0;
- for (i = 0; i < totpoly; i++, mpoly++) {
- for (j = 0; j < mpoly->totloop; j++) {
- copy_v2_v2(&varray[start], mloopuv[mpoly->loopstart + j].uv);
- start += 2;
- }
- }
-}
-
-static void cdDM_buffer_copy_uv_texpaint(
- DerivedMesh *dm, float *varray)
-{
- int i, j, totpoly;
- int start;
-
- const MPoly *mpoly;
-
- int totmaterial = dm->totmat;
- const MLoopUV **uv_base;
- const MLoopUV *uv_stencil_base;
- int stencil;
-
- totpoly = dm->getNumPolys(dm);
-
- /* should have been checked for before, reassert */
- BLI_assert(DM_get_loop_data_layer(dm, CD_MLOOPUV));
- uv_base = MEM_malloc_arrayN(totmaterial, sizeof(*uv_base), "texslots");
-
- for (i = 0; i < totmaterial; i++) {
- uv_base[i] = DM_paint_uvlayer_active_get(dm, i);
- }
-
- stencil = CustomData_get_stencil_layer(&dm->loopData, CD_MLOOPUV);
- uv_stencil_base = CustomData_get_layer_n(&dm->loopData, CD_MLOOPUV, stencil);
-
- mpoly = dm->getPolyArray(dm);
- start = 0;
-
- for (i = 0; i < totpoly; i++, mpoly++) {
- int mat_i = mpoly->mat_nr;
-
- for (j = 0; j < mpoly->totloop; j++) {
- copy_v2_v2(&varray[start], uv_base[mat_i][mpoly->loopstart + j].uv);
- copy_v2_v2(&varray[start + 2], uv_stencil_base[mpoly->loopstart + j].uv);
- start += 4;
- }
- }
-
- MEM_freeN((void *)uv_base);
-}
-
-/* treat varray_ as an array of MCol, four MCol's per face */
-static void cdDM_buffer_copy_mcol(
- DerivedMesh *dm, unsigned char *varray,
- const void *user_data)
-{
- int i, j, totpoly;
- int start;
-
- const MLoopCol *mloopcol = user_data;
- const MPoly *mpoly = dm->getPolyArray(dm);
-
- totpoly = dm->getNumPolys(dm);
-
- start = 0;
-
- for (i = 0; i < totpoly; i++, mpoly++) {
- for (j = 0; j < mpoly->totloop; j++) {
- copy_v4_v4_uchar(&varray[start], &mloopcol[mpoly->loopstart + j].r);
- start += 4;
- }
- }
-}
-
-static void cdDM_buffer_copy_edge(
- DerivedMesh *dm, unsigned int *varray)
-{
- MEdge *medge, *medge_base;
- int i, totedge, iloose, inorm, iloosehidden, inormhidden;
- int tot_loose_hidden = 0, tot_loose = 0;
- int tot_hidden = 0, tot = 0;
-
- medge_base = medge = dm->getEdgeArray(dm);
- totedge = dm->getNumEdges(dm);
-
- for (i = 0; i < totedge; i++, medge++) {
- if (medge->flag & ME_EDGEDRAW) {
- if (medge->flag & ME_LOOSEEDGE) tot_loose++;
- else tot++;
- }
- else {
- if (medge->flag & ME_LOOSEEDGE) tot_loose_hidden++;
- else tot_hidden++;
- }
- }
-
- inorm = 0;
- inormhidden = tot;
- iloose = tot + tot_hidden;
- iloosehidden = iloose + tot_loose;
-
- medge = medge_base;
- for (i = 0; i < totedge; i++, medge++) {
- if (medge->flag & ME_EDGEDRAW) {
- if (medge->flag & ME_LOOSEEDGE) {
- varray[iloose * 2] = dm->drawObject->vert_points[medge->v1].point_index;
- varray[iloose * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index;
- iloose++;
- }
- else {
- varray[inorm * 2] = dm->drawObject->vert_points[medge->v1].point_index;
- varray[inorm * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index;
- inorm++;
- }
- }
- else {
- if (medge->flag & ME_LOOSEEDGE) {
- varray[iloosehidden * 2] = dm->drawObject->vert_points[medge->v1].point_index;
- varray[iloosehidden * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index;
- iloosehidden++;
- }
- else {
- varray[inormhidden * 2] = dm->drawObject->vert_points[medge->v1].point_index;
- varray[inormhidden * 2 + 1] = dm->drawObject->vert_points[medge->v2].point_index;
- inormhidden++;
- }
- }
- }
-
- dm->drawObject->tot_loose_edge_drawn = tot_loose;
- dm->drawObject->loose_edge_offset = tot + tot_hidden;
- dm->drawObject->tot_edge_drawn = tot;
-}
-
-static void cdDM_buffer_copy_uvedge(
- DerivedMesh *dm, float *varray)
-{
- int i, j, totpoly;
- int start;
- const MLoopUV *mloopuv;
- const MPoly *mpoly = dm->getPolyArray(dm);
-
- if ((mloopuv = DM_get_loop_data_layer(dm, CD_MLOOPUV)) == NULL) {
- return;
- }
-
- totpoly = dm->getNumPolys(dm);
- start = 0;
-
- for (i = 0; i < totpoly; i++, mpoly++) {
- for (j = 0; j < mpoly->totloop; j++) {
- copy_v2_v2(&varray[start], mloopuv[mpoly->loopstart + j].uv);
- copy_v2_v2(&varray[start + 2], mloopuv[mpoly->loopstart + (j + 1) % mpoly->totloop].uv);
- start += 4;
- }
- }
-}
-
-static void cdDM_copy_gpu_data(
- DerivedMesh *dm, int type, void *varray_p,
- const int *mat_orig_to_new, const void *user_data)
-{
- /* 'varray_p' cast is redundant but include for self-documentation */
- switch (type) {
- case GPU_BUFFER_VERTEX:
- cdDM_buffer_copy_vertex(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_NORMAL:
- cdDM_buffer_copy_normal(dm, (short *)varray_p);
- break;
- case GPU_BUFFER_COLOR:
- cdDM_buffer_copy_mcol(dm, (unsigned char *)varray_p, user_data);
- break;
- case GPU_BUFFER_UV:
- cdDM_buffer_copy_uv(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_UV_TEXPAINT:
- cdDM_buffer_copy_uv_texpaint(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_EDGE:
- cdDM_buffer_copy_edge(dm, (unsigned int *)varray_p);
- break;
- case GPU_BUFFER_UVEDGE:
- cdDM_buffer_copy_uvedge(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_TRIANGLES:
- cdDM_buffer_copy_triangles(dm, (unsigned int *)varray_p, mat_orig_to_new);
- break;
- default:
- break;
- }
-}
-
-/* add a new point to the list of points related to a particular
- * vertex */
-#ifdef USE_GPU_POINT_LINK
-
-static void cdDM_drawobject_add_vert_point(GPUDrawObject *gdo, int vert_index, int point_index)
-{
- GPUVertPointLink *lnk;
-
- lnk = &gdo->vert_points[vert_index];
-
- /* if first link is in use, add a new link at the end */
- if (lnk->point_index != -1) {
- /* get last link */
- for (; lnk->next; lnk = lnk->next) ;
-
- /* add a new link from the pool */
- lnk = lnk->next = &gdo->vert_points_mem[gdo->vert_points_usage];
- gdo->vert_points_usage++;
- }
-
- lnk->point_index = point_index;
-}
-
-#else
-
-static void cdDM_drawobject_add_vert_point(GPUDrawObject *gdo, int vert_index, int point_index)
-{
- GPUVertPointLink *lnk;
- lnk = &gdo->vert_points[vert_index];
- if (lnk->point_index == -1) {
- lnk->point_index = point_index;
- }
-}
-
-#endif /* USE_GPU_POINT_LINK */
-
-/* for each vertex, build a list of points related to it; these lists
- * are stored in an array sized to the number of vertices */
-static void cdDM_drawobject_init_vert_points(
- GPUDrawObject *gdo,
- const MPoly *mpoly, const MLoop *mloop,
- int tot_poly)
-{
- int i;
- int tot_loops = 0;
-
- /* allocate the array and space for links */
- gdo->vert_points = MEM_malloc_arrayN(gdo->totvert, sizeof(GPUVertPointLink),
- "GPUDrawObject.vert_points");
-#ifdef USE_GPU_POINT_LINK
- gdo->vert_points_mem = MEM_calloc_arrayN(gdo->totvert, sizeof(GPUVertPointLink),
- "GPUDrawObject.vert_points_mem");
- gdo->vert_points_usage = 0;
-#endif
-
- /* -1 indicates the link is not yet used */
- for (i = 0; i < gdo->totvert; i++) {
-#ifdef USE_GPU_POINT_LINK
- gdo->vert_points[i].link = NULL;
-#endif
- gdo->vert_points[i].point_index = -1;
- }
-
- for (i = 0; i < tot_poly; i++) {
- int j;
- const MPoly *mp = &mpoly[i];
-
- /* assign unique indices to vertices of the mesh */
- for (j = 0; j < mp->totloop; j++) {
- cdDM_drawobject_add_vert_point(gdo, mloop[mp->loopstart + j].v, tot_loops + j);
- }
- tot_loops += mp->totloop;
- }
-
- /* map any unused vertices to loose points */
- for (i = 0; i < gdo->totvert; i++) {
- if (gdo->vert_points[i].point_index == -1) {
- gdo->vert_points[i].point_index = gdo->tot_loop_verts + gdo->tot_loose_point;
- gdo->tot_loose_point++;
- }
- }
-}
-
-/* see GPUDrawObject's structure definition for a description of the
- * data being initialized here */
-static GPUDrawObject *cdDM_GPUobject_new(DerivedMesh *dm)
-{
- GPUDrawObject *gdo;
- const MPoly *mpoly;
- const MLoop *mloop;
- const short dm_totmat = dm->totmat;
- GPUBufferMaterial *mat_info;
- int i, totloops, totpolys;
-
- /* object contains at least one material (default included) so zero means uninitialized dm */
- BLI_assert(dm_totmat != 0);
-
- mpoly = dm->getPolyArray(dm);
- mloop = dm->getLoopArray(dm);
-
- totpolys = dm->getNumPolys(dm);
- totloops = dm->getNumLoops(dm);
-
- /* get the number of points used by each material, treating
- * each quad as two triangles */
- mat_info = MEM_calloc_arrayN(dm_totmat, sizeof(*mat_info), "GPU_drawobject_new.mat_orig_to_new");
-
- for (i = 0; i < totpolys; i++) {
- const short mat_nr = ME_MAT_NR_TEST(mpoly[i].mat_nr, dm_totmat);
- mat_info[mat_nr].totpolys++;
- mat_info[mat_nr].totelements += 3 * ME_POLY_TRI_TOT(&mpoly[i]);
- mat_info[mat_nr].totloops += mpoly[i].totloop;
- }
- /* create the GPUDrawObject */
- gdo = MEM_callocN(sizeof(GPUDrawObject), "GPUDrawObject");
- gdo->totvert = dm->getNumVerts(dm);
- gdo->totedge = dm->getNumEdges(dm);
-
- GPU_buffer_material_finalize(gdo, mat_info, dm_totmat);
-
- gdo->tot_loop_verts = totloops;
-
- /* store total number of points used for triangles */
- gdo->tot_triangle_point = poly_to_tri_count(totpolys, totloops) * 3;
-
- cdDM_drawobject_init_vert_points(gdo, mpoly, mloop, totpolys);
-
- return gdo;
-}
-
static void cdDM_foreachMappedVert(
DerivedMesh *dm,
void (*func)(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3]),
@@ -1913,7 +463,7 @@ void CDDM_recalc_tessellation_ex(DerivedMesh *dm, const bool do_face_nor_cpy)
/* Tessellation recreated faceData, and the active layer indices need to get re-propagated
* from loops and polys to faces */
- CustomData_bmesh_update_active_layers(&dm->faceData, &dm->polyData, &dm->loopData);
+ CustomData_bmesh_update_active_layers(&dm->faceData, &dm->loopData);
}
void CDDM_recalc_tessellation(DerivedMesh *dm)
@@ -2005,24 +555,6 @@ static CDDerivedMesh *cdDM_create(const char *desc)
dm->getPBVH = cdDM_getPBVH;
dm->getPolyMap = cdDM_getPolyMap;
- dm->drawVerts = cdDM_drawVerts;
-
- dm->drawUVEdges = cdDM_drawUVEdges;
- dm->drawEdges = cdDM_drawEdges;
- dm->drawLooseEdges = cdDM_drawLooseEdges;
- dm->drawMappedEdges = cdDM_drawMappedEdges;
-
- dm->drawFacesSolid = cdDM_drawFacesSolid;
- dm->drawFacesTex = cdDM_drawFacesTex;
- dm->drawFacesGLSL = cdDM_drawFacesGLSL;
- dm->drawMappedFaces = cdDM_drawMappedFaces;
- dm->drawMappedFacesTex = cdDM_drawMappedFacesTex;
- dm->drawMappedFacesGLSL = cdDM_drawMappedFacesGLSL;
- dm->drawMappedFacesMat = cdDM_drawMappedFacesMat;
-
- dm->gpuObjectNew = cdDM_GPUobject_new;
- dm->copy_gpu_data = cdDM_copy_gpu_data;
-
dm->foreachMappedVert = cdDM_foreachMappedVert;
dm->foreachMappedEdge = cdDM_foreachMappedEdge;
dm->foreachMappedLoop = cdDM_foreachMappedLoop;
@@ -2062,10 +594,14 @@ DerivedMesh *CDDM_new(int numVerts, int numEdges, int numTessFaces, int numLoops
DerivedMesh *CDDM_from_mesh(Mesh *mesh)
{
+ return CDDM_from_mesh_ex(mesh, CD_REFERENCE);
+}
+
+DerivedMesh *CDDM_from_mesh_ex(Mesh *mesh, int alloctype)
+{
CDDerivedMesh *cddm = cdDM_create(__func__);
DerivedMesh *dm = &cddm->dm;
CustomDataMask mask = CD_MASK_MESH & (~CD_MASK_MDISPS);
- int alloctype;
/* this does a referenced copy, with an exception for fluidsim */
@@ -2075,7 +611,10 @@ DerivedMesh *CDDM_from_mesh(Mesh *mesh)
dm->deformedOnly = 1;
dm->cd_flag = mesh->cd_flag;
- alloctype = CD_REFERENCE;
+ if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) {
+ dm->dirty |= DM_DIRTY_NORMALS;
+ }
+ /* TODO DM_DIRTY_TESS_CDLAYERS ? Maybe not though, since we probably want to switch to looptris ? */
CustomData_merge(&mesh->vdata, &dm->vertData, mask, alloctype,
mesh->totvert);
@@ -2153,7 +692,6 @@ DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase)
if (alluv) {
const char *uvname = "Orco";
- CustomData_add_layer_named(&cddm->dm.polyData, CD_MTEXPOLY, CD_DEFAULT, NULL, totpoly, uvname);
CustomData_add_layer_named(&cddm->dm.loopData, CD_MLOOPUV, CD_ASSIGN, alluv, totloop, uvname);
}
@@ -2168,22 +706,18 @@ DerivedMesh *CDDM_from_curve_displist(Object *ob, ListBase *dispbase)
static void loops_to_customdata_corners(
BMesh *bm, CustomData *facedata,
int cdindex, const BMLoop *l3[3],
- int numCol, int numTex)
+ int numCol, int numUV)
{
const BMLoop *l;
- BMFace *f = l3[0]->f;
+// BMFace *f = l3[0]->f;
MTFace *texface;
- MTexPoly *texpoly;
MCol *mcol;
MLoopCol *mloopcol;
MLoopUV *mloopuv;
int i, j, hasPCol = CustomData_has_layer(&bm->ldata, CD_PREVIEW_MLOOPCOL);
- for (i = 0; i < numTex; i++) {
+ for (i = 0; i < numUV; i++) {
texface = CustomData_get_n(facedata, CD_MTFACE, cdindex, i);
- texpoly = CustomData_bmesh_get_n(&bm->pdata, f->head.data, CD_MTEXPOLY, i);
-
- ME_MTEXFACE_CPY(texface, texpoly);
for (j = 0; j < 3; j++) {
l = l3[j];
@@ -2237,7 +771,7 @@ static DerivedMesh *cddm_from_bmesh_ex(
MLoop *mloop = cddm->mloop;
MPoly *mpoly = cddm->mpoly;
int numCol = CustomData_number_of_layers(&bm->ldata, CD_MLOOPCOL);
- int numTex = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
+ int numUV = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV);
int *index, add_orig;
CustomDataMask mask;
unsigned int i, j;
@@ -2267,7 +801,7 @@ static DerivedMesh *cddm_from_bmesh_ex(
/* add tessellation mface layers */
if (use_tessface) {
- CustomData_from_bmeshpoly(&dm->faceData, &dm->polyData, &dm->loopData, em_tottri);
+ CustomData_from_bmeshpoly(&dm->faceData, &dm->loopData, em_tottri);
}
index = dm->getVertDataArray(dm, CD_ORIGINDEX);
@@ -2339,7 +873,7 @@ static DerivedMesh *cddm_from_bmesh_ex(
/* map mfaces to polygons in the same cddm intentionally */
*index++ = BM_elem_index_get(efa);
- loops_to_customdata_corners(bm, &dm->faceData, i, l, numCol, numTex);
+ loops_to_customdata_corners(bm, &dm->faceData, i, l, numCol, numUV);
test_index_face(mf, &dm->faceData, i, 3);
}
}
@@ -2772,7 +1306,8 @@ void CDDM_calc_normals_tessface(DerivedMesh *dm)
}
#if 1
-
+/* TODO(sybren): Delete everything in this #if block after we have ported the modifiers
+ * to use Mesh instead of DerivedMesh. The code has been copied to mesh_merge.c and ported. */
/**
* Poly compare with vtargetmap
* Function used by #CDDM_merge_verts.
@@ -2950,7 +1485,7 @@ static bool poly_gset_compare_fn(const void *k1, const void *k2)
* \param vtargetmap The table that maps vertices to target vertices. a value of -1
* indicates a vertex is a target, and is to be kept.
* This array is aligned with 'dm->numVertData'
- * \warning \a vtergatmap must **not** contain any chained mapping (v1 -> v2 -> v3 etc.), this is not supported
+ * \warning \a vtargetmap must **not** contain any chained mapping (v1 -> v2 -> v3 etc.), this is not supported
* and will likely generate corrupted geometry.
*
* \param tot_vtargetmap The number of non '-1' values in vtargetmap. (not the size)
@@ -2974,6 +1509,7 @@ static bool poly_gset_compare_fn(const void *k1, const void *k2)
*/
DerivedMesh *CDDM_merge_verts(DerivedMesh *dm, const int *vtargetmap, const int tot_vtargetmap, const int merge_mode)
{
+// This was commented out back in 2013, see commit f45d8827bafe6b9eaf9de42f4054e9d84a21955d.
// #define USE_LOOPS
CDDerivedMesh *cddm = (CDDerivedMesh *)dm;
CDDerivedMesh *cddm2 = NULL;
diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c
index 9ae295e2e3b..976b8965fa2 100644
--- a/source/blender/blenkernel/intern/cloth.c
+++ b/source/blender/blenkernel/intern/cloth.c
@@ -40,6 +40,8 @@
#include "BLI_edgehash.h"
#include "BLI_linklist.h"
+#include "DEG_depsgraph.h"
+
#include "BKE_cdderivedmesh.h"
#include "BKE_cloth.h"
#include "BKE_effect.h"
@@ -345,7 +347,7 @@ static int do_init_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
return 1;
}
-static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr)
+static int do_step_cloth(struct Depsgraph *depsgraph, Object *ob, ClothModifierData *clmd, DerivedMesh *result, int framenr)
{
ClothVertex *verts = NULL;
Cloth *cloth;
@@ -370,7 +372,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
mul_m4_v3(ob->obmat, verts->xconst);
}
- effectors = pdInitEffectors(clmd->scene, ob, NULL, clmd->sim_parms->effector_weights, true);
+ effectors = pdInitEffectors(depsgraph, clmd->scene, ob, NULL, clmd->sim_parms->effector_weights, true);
if (clmd->sim_parms->flags & CLOTH_SIMSETTINGS_FLAG_DYNAMIC_BASEMESH )
cloth_update_verts ( ob, clmd, result );
@@ -400,7 +402,7 @@ static int do_step_cloth(Object *ob, ClothModifierData *clmd, DerivedMesh *resul
/************************************************
* clothModifier_do - main simulation function
************************************************/
-void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3])
+void clothModifier_do(ClothModifierData *clmd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm, float (*vertexCos)[3])
{
PointCache *cache;
PTCacheID pid;
@@ -479,9 +481,6 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
return;
}
- if (!can_simulate)
- return;
-
/* if on second frame, write cache for first frame */
if (cache->simframe == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact==0))
BKE_ptcache_write(&pid, startframe);
@@ -491,7 +490,7 @@ void clothModifier_do(ClothModifierData *clmd, Scene *scene, Object *ob, Derived
/* do simulation */
BKE_ptcache_validate(cache, framenr);
- if (!do_step_cloth(ob, clmd, dm, framenr)) {
+ if (!do_step_cloth(depsgraph, ob, clmd, dm, framenr)) {
BKE_ptcache_invalidate(cache);
}
else
@@ -923,7 +922,7 @@ static void cloth_from_mesh ( ClothModifierData *clmd, DerivedMesh *dm )
}
/***************************************************************************************
- * SPRING NETWORK BUILDING IMPLEMENTATION BEGIN
+ * SPRING NETWORK GWN_BATCH_BUILDING IMPLEMENTATION BEGIN
***************************************************************************************/
BLI_INLINE void spring_verts_ordered_set(ClothSpring *spring, int v0, int v1)
@@ -1505,6 +1504,6 @@ static int cloth_build_springs ( ClothModifierData *clmd, DerivedMesh *dm )
} /* cloth_build_springs */
/***************************************************************************************
- * SPRING NETWORK BUILDING IMPLEMENTATION END
+ * SPRING NETWORK GWN_BATCH_BUILDING IMPLEMENTATION END
***************************************************************************************/
diff --git a/source/blender/blenkernel/intern/collection.c b/source/blender/blenkernel/intern/collection.c
new file mode 100644
index 00000000000..15fda8a9786
--- /dev/null
+++ b/source/blender/blenkernel/intern/collection.c
@@ -0,0 +1,1014 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/collection.c
+ * \ingroup bke
+ */
+
+#include <string.h>
+
+#include "BLI_blenlib.h"
+#include "BLI_ghash.h"
+#include "BLI_iterator.h"
+#include "BLI_listbase.h"
+#include "BLI_math_base.h"
+#include "BLT_translation.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_collection.h"
+#include "BKE_group.h"
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+
+#include "DNA_group_types.h"
+#include "DNA_ID.h"
+#include "DNA_layer_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+/* Prototypes. */
+static SceneCollection *find_collection_parent(const struct SceneCollection *sc_child, struct SceneCollection *sc_parent);
+static bool is_collection_in_tree(const struct SceneCollection *sc_reference, struct SceneCollection *sc_parent);
+
+static SceneCollection *collection_master_from_id(const ID *owner_id)
+{
+ switch (GS(owner_id->name)) {
+ case ID_SCE:
+ return ((Scene *)owner_id)->collection;
+ case ID_GR:
+ return ((Group *)owner_id)->collection;
+ default:
+ BLI_assert(!"ID doesn't support collections");
+ return NULL;
+ }
+}
+
+/**
+ * The automatic/fallback name of a new collection.
+ */
+void BKE_collection_new_name_get(ID *owner_id, SceneCollection *sc_parent, char *rname)
+{
+ SceneCollection *sc_master = collection_master_from_id(owner_id);
+ char *name;
+
+ if (sc_parent == sc_master) {
+ name = BLI_sprintfN("Collection %d", BLI_listbase_count(&sc_master->scene_collections) + 1);
+ }
+ else {
+ const int number = BLI_listbase_count(&sc_parent->scene_collections) + 1;
+ const int digits = integer_digits_i(number);
+ const int max_len = sizeof(sc_parent->name) - 1 /* NULL terminator */ - (1 + digits) /* " %d" */;
+ name = BLI_sprintfN("%.*s %d", max_len, sc_parent->name, number);
+ }
+
+ BLI_strncpy(rname, name, MAX_NAME);
+ MEM_freeN(name);
+}
+
+/**
+ * Add a new collection, but don't handle syncing with layer collections
+ */
+static SceneCollection *collection_add(ID *owner_id, SceneCollection *sc_parent, const int type, const char *name_custom)
+{
+ SceneCollection *sc_master = collection_master_from_id(owner_id);
+ SceneCollection *sc = MEM_callocN(sizeof(SceneCollection), "New Collection");
+ sc->type = type;
+ char name[MAX_NAME];
+
+ if (!sc_parent) {
+ sc_parent = sc_master;
+ }
+
+ if (name_custom != NULL) {
+ BLI_strncpy(name, name_custom, MAX_NAME);
+ }
+ else {
+ BKE_collection_new_name_get(owner_id, sc_parent, name);
+ }
+
+ BLI_addtail(&sc_parent->scene_collections, sc);
+ BKE_collection_rename(owner_id, sc, name);
+
+ return sc;
+}
+
+/**
+ * Add a collection to a collection ListBase and syncronize all render layers
+ * The ListBase is NULL when the collection is to be added to the master collection
+ */
+SceneCollection *BKE_collection_add(ID *owner_id, SceneCollection *sc_parent, const int type, const char *name_custom)
+{
+ if (sc_parent == NULL) {
+ sc_parent = BKE_collection_master(owner_id);
+ }
+
+ SceneCollection *scene_collection = collection_add(owner_id, sc_parent, type, name_custom);
+ BKE_layer_sync_new_scene_collection(owner_id, sc_parent, scene_collection);
+ return scene_collection;
+}
+
+/**
+ * Free the collection items recursively
+ */
+static void collection_free(SceneCollection *sc, const bool do_id_user)
+{
+ if (do_id_user) {
+ for (LinkData *link = sc->objects.first; link; link = link->next) {
+ id_us_min(link->data);
+ }
+ }
+
+ BLI_freelistN(&sc->objects);
+
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ collection_free(nsc, do_id_user);
+ }
+ BLI_freelistN(&sc->scene_collections);
+}
+
+/**
+ * Unlink the collection recursively
+ * \return true if unlinked.
+ */
+static bool collection_remlink(SceneCollection *sc_parent, SceneCollection *sc_gone)
+{
+ for (SceneCollection *sc = sc_parent->scene_collections.first; sc; sc = sc->next) {
+ if (sc == sc_gone) {
+ BLI_remlink(&sc_parent->scene_collections, sc_gone);
+ return true;
+ }
+
+ if (collection_remlink(sc, sc_gone)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Recursively remove any instance of this SceneCollection
+ */
+static void layer_collection_remove(ViewLayer *view_layer, ListBase *lb, const SceneCollection *sc)
+{
+ LayerCollection *lc = lb->first;
+ while (lc) {
+ if (lc->scene_collection == sc) {
+ BKE_layer_collection_free(view_layer, lc);
+ BLI_remlink(lb, lc);
+
+ LayerCollection *lc_next = lc->next;
+ MEM_freeN(lc);
+ lc = lc_next;
+
+ /* only the "top-level" layer collections may have the
+ * same SceneCollection in a sibling tree.
+ */
+ if (lb != &view_layer->layer_collections) {
+ return;
+ }
+ }
+
+ else {
+ layer_collection_remove(view_layer, &lc->layer_collections, sc);
+ lc = lc->next;
+ }
+ }
+}
+
+/**
+ * Remove a collection from the scene, and syncronize all render layers
+ *
+ * If an object is in any other collection, link the object to the master collection.
+ */
+bool BKE_collection_remove(ID *owner_id, SceneCollection *sc)
+{
+ SceneCollection *sc_master = collection_master_from_id(owner_id);
+
+ /* The master collection cannot be removed. */
+ if (sc == sc_master) {
+ return false;
+ }
+
+ /* We need to do bottom up removal, otherwise we get a crash when we remove a collection that
+ * has one of its nested collections linked to a view layer. */
+ SceneCollection *scene_collection_nested = sc->scene_collections.first;
+ while (scene_collection_nested != NULL) {
+ SceneCollection *scene_collection_next = scene_collection_nested->next;
+ BKE_collection_remove(owner_id, scene_collection_nested);
+ scene_collection_nested = scene_collection_next;
+ }
+
+ /* Unlink from the respective collection tree. */
+ if (!collection_remlink(sc_master, sc)) {
+ BLI_assert(false);
+ }
+
+ /* If an object is no longer in any collection, we add it to the master collection. */
+ ListBase collection_objects;
+ BLI_duplicatelist(&collection_objects, &sc->objects);
+
+ FOREACH_SCENE_COLLECTION_BEGIN(owner_id, scene_collection_iter)
+ {
+ if (scene_collection_iter == sc) {
+ continue;
+ }
+
+ LinkData *link_next, *link = collection_objects.first;
+ while (link) {
+ link_next = link->next;
+
+ if (BLI_findptr(&scene_collection_iter->objects, link->data, offsetof(LinkData, data))) {
+ BLI_remlink(&collection_objects, link);
+ MEM_freeN(link);
+ }
+
+ link = link_next;
+ }
+ }
+ FOREACH_SCENE_COLLECTION_END;
+
+ for (LinkData *link = collection_objects.first; link; link = link->next) {
+ BKE_collection_object_add(owner_id, sc_master, link->data);
+ }
+
+ BLI_freelistN(&collection_objects);
+
+ /* Clear the collection items. */
+ collection_free(sc, true);
+
+ /* check all layers that use this collection and clear them */
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ layer_collection_remove(view_layer, &view_layer->layer_collections, sc);
+ view_layer->active_collection = 0;
+ }
+
+ MEM_freeN(sc);
+ return true;
+}
+
+/**
+ * Copy SceneCollection tree but keep pointing to the same objects
+ *
+ * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_collection_copy_data(SceneCollection *sc_dst, SceneCollection *sc_src, const int flag)
+{
+ BLI_duplicatelist(&sc_dst->objects, &sc_src->objects);
+ if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
+ for (LinkData *link = sc_dst->objects.first; link; link = link->next) {
+ id_us_plus(link->data);
+ }
+ }
+
+ BLI_duplicatelist(&sc_dst->scene_collections, &sc_src->scene_collections);
+ for (SceneCollection *nsc_src = sc_src->scene_collections.first, *nsc_dst = sc_dst->scene_collections.first;
+ nsc_src;
+ nsc_src = nsc_src->next, nsc_dst = nsc_dst->next)
+ {
+ BKE_collection_copy_data(nsc_dst, nsc_src, flag);
+ }
+}
+
+/**
+ * Makes a shallow copy of a SceneCollection
+ *
+ * Add a new collection in the same level as the old one, copy any nested collections
+ * but link the objects to the new collection (as oppose to copy them).
+ */
+SceneCollection *BKE_collection_duplicate(ID *owner_id, SceneCollection *scene_collection)
+{
+ SceneCollection *scene_collection_master = BKE_collection_master(owner_id);
+ SceneCollection *scene_collection_parent = find_collection_parent(scene_collection, scene_collection_master);
+
+ /* It's not allowed to copy the master collection. */
+ if (scene_collection_master == scene_collection) {
+ return NULL;
+ }
+
+ SceneCollection *scene_collection_new = collection_add(
+ owner_id,
+ scene_collection_parent,
+ scene_collection->type,
+ scene_collection->name);
+
+ if (scene_collection_new != scene_collection->next) {
+ BLI_remlink(&scene_collection_parent->scene_collections, scene_collection_new);
+ BLI_insertlinkafter(&scene_collection_parent->scene_collections, scene_collection, scene_collection_new);
+ }
+
+ BKE_collection_copy_data(scene_collection_new, scene_collection, 0);
+ BKE_layer_sync_new_scene_collection(owner_id, scene_collection_parent, scene_collection_new);
+
+ /* Make sure every linked instance of the new collection has the same values (flags, overrides, ...) as the
+ * corresponding original collection. */
+ BKE_layer_collection_sync_flags(owner_id, scene_collection_new, scene_collection);
+
+ return scene_collection_new;
+}
+
+static SceneCollection *master_collection_from_id(const ID *owner_id)
+{
+ switch (GS(owner_id->name)) {
+ case ID_SCE:
+ return ((const Scene *)owner_id)->collection;
+ case ID_GR:
+ return ((const Group *)owner_id)->collection;
+ default:
+ BLI_assert(!"ID doesn't support scene collection");
+ return NULL;
+ }
+}
+
+/**
+ * Returns the master collection of the scene or group
+ */
+SceneCollection *BKE_collection_master(const ID *owner_id)
+{
+ return master_collection_from_id(owner_id);
+}
+
+static void collection_rename(const ID *owner_id, SceneCollection *sc, const char *name)
+{
+ SceneCollection *sc_parent = find_collection_parent(sc, collection_master_from_id(owner_id));
+ BLI_strncpy(sc->name, name, sizeof(sc->name));
+ BLI_uniquename(&sc_parent->scene_collections, sc, DATA_("Collection"), '.', offsetof(SceneCollection, name), sizeof(sc->name));
+}
+
+void BKE_collection_rename(const ID *owner_id, SceneCollection *sc, const char *name)
+{
+ collection_rename(owner_id, sc, name);
+}
+
+/**
+ * Make sure the collection name is still unique within its siblings.
+ */
+static void collection_name_check(const ID *owner_id, SceneCollection *sc)
+{
+ /* It's a bit of a hack, we simply try to make sure the collection name is valid. */
+ collection_rename(owner_id, sc, sc->name);
+}
+
+/**
+ * Free (or release) any data used by the master collection (does not free the master collection itself).
+ * Used only to clear the entire scene or group data since it's not doing re-syncing of the LayerCollection tree
+ */
+void BKE_collection_master_free(ID *owner_id, const bool do_id_user)
+{
+ collection_free(BKE_collection_master(owner_id), do_id_user);
+}
+
+static void collection_object_add(const ID *owner_id, SceneCollection *sc, Object *ob)
+{
+ BLI_addtail(&sc->objects, BLI_genericNodeN(ob));
+
+ if (GS(owner_id->name) == ID_SCE) {
+ id_us_plus((ID *)ob);
+ }
+ else {
+ BLI_assert(GS(owner_id->name) == ID_GR);
+ if ((ob->flag & OB_FROMGROUP) == 0) {
+ ob->flag |= OB_FROMGROUP;
+ }
+ }
+
+ BKE_layer_sync_object_link(owner_id, sc, ob);
+}
+
+/**
+ * Add object to collection
+ */
+bool BKE_collection_object_add(const ID *owner_id, SceneCollection *sc, Object *ob)
+{
+ if (BKE_collection_object_exists(sc, ob)) {
+ /* don't add the same object twice */
+ return false;
+ }
+
+ collection_object_add(owner_id, sc, ob);
+ return true;
+}
+
+/**
+ * Add object to all collections that reference objects is in
+ * (used to copy objects)
+ */
+void BKE_collection_object_add_from(Scene *scene, Object *ob_src, Object *ob_dst)
+{
+ FOREACH_SCENE_COLLECTION_BEGIN(scene, sc)
+ {
+ if (BLI_findptr(&sc->objects, ob_src, offsetof(LinkData, data))) {
+ collection_object_add(&scene->id, sc, ob_dst);
+ }
+ }
+ FOREACH_SCENE_COLLECTION_END;
+
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ Base *base_src = BKE_view_layer_base_find(view_layer, ob_src);
+ if (base_src != NULL) {
+ if (base_src->collection_properties == NULL) {
+ continue;
+ }
+ Base *base_dst = BKE_view_layer_base_find(view_layer, ob_dst);
+ IDP_MergeGroup(base_dst->collection_properties, base_src->collection_properties, true);
+ }
+ }
+}
+
+/**
+ * Remove object from collection.
+ * \param bmain: Can be NULL if free_us is false.
+ */
+bool BKE_collection_object_remove(Main *bmain, ID *owner_id, SceneCollection *sc, Object *ob, const bool free_us)
+{
+ LinkData *link = BLI_findptr(&sc->objects, ob, offsetof(LinkData, data));
+
+ if (link == NULL) {
+ return false;
+ }
+
+ BLI_remlink(&sc->objects, link);
+ MEM_freeN(link);
+
+ BKE_layer_sync_object_unlink(owner_id, sc, ob);
+
+ if (GS(owner_id->name) == ID_SCE) {
+ if (free_us) {
+ BKE_libblock_free_us(bmain, ob);
+ }
+ else {
+ id_us_min(&ob->id);
+ }
+ }
+ else {
+ BLI_assert(GS(owner_id->name) == ID_GR);
+ }
+
+ return true;
+}
+
+/**
+ * Remove object from all collections of scene
+ * \param scene_collection_skip: Don't remove base from this collection.
+ */
+static bool collections_object_remove_ex(Main *bmain, ID *owner_id, Object *ob, const bool free_us,
+ SceneCollection *scene_collection_skip)
+{
+ bool removed = false;
+ if (GS(owner_id->name) == ID_SCE) {
+ BKE_scene_remove_rigidbody_object((Scene *)owner_id, ob);
+ }
+ else {
+ BLI_assert(GS(owner_id->name) == ID_GR);
+ }
+
+ FOREACH_SCENE_COLLECTION_BEGIN(owner_id, sc)
+ {
+ if (sc != scene_collection_skip) {
+ removed |= BKE_collection_object_remove(bmain, owner_id, sc, ob, free_us);
+ }
+ }
+ FOREACH_SCENE_COLLECTION_END;
+ return removed;
+}
+
+/**
+ * Remove object from all collections of scene
+ */
+bool BKE_collections_object_remove(Main *bmain, ID *owner_id, Object *ob, const bool free_us)
+{
+ return collections_object_remove_ex(bmain, owner_id, ob, free_us, NULL);
+}
+
+/**
+ * Move object from a collection into another
+ *
+ * If source collection is NULL move it from all the existing collections.
+ */
+void BKE_collection_object_move(ID *owner_id, SceneCollection *sc_dst, SceneCollection *sc_src, Object *ob)
+{
+ /* In both cases we first add the object, then remove it from the other collections.
+ * Otherwise we lose the original base and whether it was active and selected. */
+ if (sc_src != NULL) {
+ if (BKE_collection_object_add(owner_id, sc_dst, ob)) {
+ BKE_collection_object_remove(NULL, owner_id, sc_src, ob, false);
+ }
+ }
+ else {
+ /* Adding will fail if object is already in collection.
+ * However we still need to remove it from the other collections. */
+ BKE_collection_object_add(owner_id, sc_dst, ob);
+ collections_object_remove_ex(NULL, owner_id, ob, false, sc_dst);
+ }
+}
+
+/**
+ * Whether the object is directly inside the collection.
+ */
+bool BKE_collection_object_exists(struct SceneCollection *scene_collection, struct Object *ob)
+{
+ if (BLI_findptr(&scene_collection->objects, ob, offsetof(LinkData, data))) {
+ return true;
+ }
+ return false;
+}
+
+static SceneCollection *scene_collection_from_index_recursive(SceneCollection *scene_collection, const int index, int *index_current)
+{
+ if (index == (*index_current)) {
+ return scene_collection;
+ }
+
+ (*index_current)++;
+
+ for (SceneCollection *scene_collection_iter = scene_collection->scene_collections.first;
+ scene_collection_iter != NULL;
+ scene_collection_iter = scene_collection_iter->next)
+ {
+ SceneCollection *nested = scene_collection_from_index_recursive(scene_collection_iter, index, index_current);
+ if (nested != NULL) {
+ return nested;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Return Scene Collection for a given index.
+ *
+ * The index is calculated from top to bottom counting the children before the siblings.
+ */
+SceneCollection *BKE_collection_from_index(Scene *scene, const int index)
+{
+ int index_current = 0;
+ SceneCollection *master_collection = BKE_collection_master(&scene->id);
+ return scene_collection_from_index_recursive(master_collection, index, &index_current);
+}
+
+static void layer_collection_sync(LayerCollection *lc_dst, LayerCollection *lc_src)
+{
+ lc_dst->flag = lc_src->flag;
+
+ /* Pending: sync overrides. */
+ IDP_MergeGroup(lc_dst->properties, lc_src->properties, true);
+
+ /* Continue recursively. */
+ LayerCollection *lc_dst_nested, *lc_src_nested;
+ lc_src_nested = lc_src->layer_collections.first;
+ for (lc_dst_nested = lc_dst->layer_collections.first;
+ lc_dst_nested && lc_src_nested;
+ lc_dst_nested = lc_dst_nested->next, lc_src_nested = lc_src_nested->next)
+ {
+ layer_collection_sync(lc_dst_nested, lc_src_nested);
+ }
+}
+
+/**
+ * Select all the objects in this SceneCollection (and its nested collections) for this ViewLayer.
+ * Return true if any object was selected.
+ */
+bool BKE_collection_objects_select(ViewLayer *view_layer, SceneCollection *scene_collection)
+{
+ LayerCollection *layer_collection = BKE_layer_collection_first_from_scene_collection(view_layer, scene_collection);
+ if (layer_collection != NULL) {
+ BKE_layer_collection_objects_select(layer_collection);
+ return true;
+ }
+ else {
+ /* Slower approach, we need to iterate over all the objects and for each one we see if there is a base. */
+ bool changed = false;
+ for (LinkData *link = scene_collection->objects.first; link; link = link->next) {
+ Base *base = BKE_view_layer_base_find(view_layer, link->data);
+ if (base != NULL) {
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+ base->flag |= BASE_SELECTED;
+ changed = true;
+ }
+ }
+ }
+ return changed;
+ }
+}
+
+/**
+ * Leave only the master collection in, remove everything else.
+ * @param group
+ */
+static void collection_group_cleanup(Group *group)
+{
+ /* Unlink all the LayerCollections. */
+ while (group->view_layer->layer_collections.last != NULL) {
+ BKE_collection_unlink(group->view_layer, group->view_layer->layer_collections.last);
+ }
+
+ /* Remove all the SceneCollections but the master. */
+ collection_free(group->collection, false);
+}
+
+/**
+ * Create a group from a collection
+ *
+ * Any ViewLayer that may have this the related SceneCollection linked is converted
+ * to a Group Collection.
+ */
+Group *BKE_collection_group_create(Main *bmain, Scene *scene, LayerCollection *lc_src)
+{
+ SceneCollection *sc_dst, *sc_src = lc_src->scene_collection;
+ LayerCollection *lc_dst;
+
+ /* The master collection can't be converted. */
+ if (sc_src == BKE_collection_master(&scene->id)) {
+ return NULL;
+ }
+
+ /* If a sub-collection of sc_dst is directly linked into a ViewLayer we can't convert. */
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (LayerCollection *lc_child = view_layer->layer_collections.first; lc_child; lc_child = lc_child->next) {
+ if (is_collection_in_tree(lc_child->scene_collection, sc_src)) {
+ return NULL;
+ }
+ }
+ }
+
+ /* Create new group with the same data as the original collection. */
+ Group *group = BKE_group_add(bmain, sc_src->name);
+ collection_group_cleanup(group);
+
+ sc_dst = BKE_collection_add(&group->id, NULL, COLLECTION_TYPE_GROUP_INTERNAL, sc_src->name);
+ BKE_collection_copy_data(sc_dst, sc_src, 0);
+ FOREACH_SCENE_COLLECTION_BEGIN(&group->id, sc_group)
+ {
+ sc_group->type = COLLECTION_TYPE_GROUP_INTERNAL;
+ }
+ FOREACH_SCENE_COLLECTION_END;
+
+ lc_dst = BKE_collection_link(group->view_layer, sc_dst);
+ layer_collection_sync(lc_dst, lc_src);
+
+ return group;
+}
+
+/* ---------------------------------------------------------------------- */
+/* Outliner drag and drop */
+
+/**
+ * Find and return the SceneCollection that has \a sc_child as one of its directly
+ * nested SceneCollection.
+ *
+ * \param sc_parent Initial SceneCollection to look into recursively, usually the master collection
+ */
+static SceneCollection *find_collection_parent(const SceneCollection *sc_child, SceneCollection *sc_parent)
+{
+ for (SceneCollection *sc_nested = sc_parent->scene_collections.first; sc_nested; sc_nested = sc_nested->next) {
+ if (sc_nested == sc_child) {
+ return sc_parent;
+ }
+
+ SceneCollection *found = find_collection_parent(sc_child, sc_nested);
+ if (found) {
+ return found;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Check if \a sc_reference is nested to \a sc_parent SceneCollection
+ */
+static bool is_collection_in_tree(const SceneCollection *sc_reference, SceneCollection *sc_parent)
+{
+ return find_collection_parent(sc_reference, sc_parent) != NULL;
+}
+
+bool BKE_collection_move_above(const ID *owner_id, SceneCollection *sc_dst, SceneCollection *sc_src)
+{
+ /* Find the SceneCollection the sc_src belongs to */
+ SceneCollection *sc_master = master_collection_from_id(owner_id);
+
+ /* Master Layer can't be moved around*/
+ if (ELEM(sc_master, sc_src, sc_dst)) {
+ return false;
+ }
+
+ /* collection is already where we wanted it to be */
+ if (sc_dst->prev == sc_src) {
+ return false;
+ }
+
+ /* We can't move a collection fs the destiny collection
+ * is nested to the source collection */
+ if (is_collection_in_tree(sc_dst, sc_src)) {
+ return false;
+ }
+
+ SceneCollection *sc_src_parent = find_collection_parent(sc_src, sc_master);
+ SceneCollection *sc_dst_parent = find_collection_parent(sc_dst, sc_master);
+ BLI_assert(sc_src_parent);
+ BLI_assert(sc_dst_parent);
+
+ /* Remove sc_src from its parent */
+ BLI_remlink(&sc_src_parent->scene_collections, sc_src);
+
+ /* Re-insert it where it belongs */
+ BLI_insertlinkbefore(&sc_dst_parent->scene_collections, sc_dst, sc_src);
+
+ /* Update the tree */
+ BKE_layer_collection_resync(owner_id, sc_src_parent);
+ BKE_layer_collection_resync(owner_id, sc_dst_parent);
+
+ /* Keep names unique. */
+ collection_name_check(owner_id, sc_src);
+
+ return true;
+}
+
+bool BKE_collection_move_below(const ID *owner_id, SceneCollection *sc_dst, SceneCollection *sc_src)
+{
+ /* Find the SceneCollection the sc_src belongs to */
+ SceneCollection *sc_master = master_collection_from_id(owner_id);
+
+ /* Master Layer can't be moved around*/
+ if (ELEM(sc_master, sc_src, sc_dst)) {
+ return false;
+ }
+
+ /* Collection is already where we wanted it to be */
+ if (sc_dst->next == sc_src) {
+ return false;
+ }
+
+ /* We can't move a collection if the destiny collection
+ * is nested to the source collection */
+ if (is_collection_in_tree(sc_dst, sc_src)) {
+ return false;
+ }
+
+ SceneCollection *sc_src_parent = find_collection_parent(sc_src, sc_master);
+ SceneCollection *sc_dst_parent = find_collection_parent(sc_dst, sc_master);
+ BLI_assert(sc_src_parent);
+ BLI_assert(sc_dst_parent);
+
+ /* Remove sc_src from its parent */
+ BLI_remlink(&sc_src_parent->scene_collections, sc_src);
+
+ /* Re-insert it where it belongs */
+ BLI_insertlinkafter(&sc_dst_parent->scene_collections, sc_dst, sc_src);
+
+ /* Update the tree */
+ BKE_layer_collection_resync(owner_id, sc_src_parent);
+ BKE_layer_collection_resync(owner_id, sc_dst_parent);
+
+ /* Keep names unique. */
+ collection_name_check(owner_id, sc_src);
+
+ return true;
+}
+
+bool BKE_collection_move_into(const ID *owner_id, SceneCollection *sc_dst, SceneCollection *sc_src)
+{
+ /* Find the SceneCollection the sc_src belongs to */
+ SceneCollection *sc_master = master_collection_from_id(owner_id);
+ if (sc_src == sc_master) {
+ return false;
+ }
+
+ /* We can't move a collection if the destiny collection
+ * is nested to the source collection */
+ if (is_collection_in_tree(sc_dst, sc_src)) {
+ return false;
+ }
+
+ SceneCollection *sc_src_parent = find_collection_parent(sc_src, sc_master);
+ BLI_assert(sc_src_parent);
+
+ /* collection is already where we wanted it to be */
+ if (sc_dst->scene_collections.last == sc_src) {
+ return false;
+ }
+
+ /* Remove sc_src from it */
+ BLI_remlink(&sc_src_parent->scene_collections, sc_src);
+
+ /* Insert sc_src into sc_dst */
+ BLI_addtail(&sc_dst->scene_collections, sc_src);
+
+ /* Update the tree */
+ BKE_layer_collection_resync(owner_id, sc_src_parent);
+ BKE_layer_collection_resync(owner_id, sc_dst);
+
+ /* Keep names unique. */
+ collection_name_check(owner_id, sc_src);
+
+ return true;
+}
+
+/* ---------------------------------------------------------------------- */
+/* Iteractors */
+/* scene collection iteractor */
+
+typedef struct SceneCollectionsIteratorData {
+ ID *owner_id;
+ void **array;
+ int tot, cur;
+} SceneCollectionsIteratorData;
+
+static void scene_collection_callback(SceneCollection *sc, BKE_scene_collections_Cb callback, void *data)
+{
+ callback(sc, data);
+
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ scene_collection_callback(nsc, callback, data);
+ }
+}
+
+static void scene_collections_count(SceneCollection *UNUSED(sc), void *data)
+{
+ int *tot = data;
+ (*tot)++;
+}
+
+static void scene_collections_build_array(SceneCollection *sc, void *data)
+{
+ SceneCollection ***array = data;
+ **array = sc;
+ (*array)++;
+}
+
+static void scene_collections_array(ID *owner_id, SceneCollection ***collections_array, int *tot)
+{
+ SceneCollection *sc;
+ SceneCollection **array;
+
+ *collections_array = NULL;
+ *tot = 0;
+
+ if (owner_id == NULL) {
+ return;
+ }
+
+ sc = master_collection_from_id(owner_id);
+ BLI_assert(sc != NULL);
+ scene_collection_callback(sc, scene_collections_count, tot);
+
+ if (*tot == 0)
+ return;
+
+ *collections_array = array = MEM_mallocN(sizeof(SceneCollection *) * (*tot), "SceneCollectionArray");
+ scene_collection_callback(sc, scene_collections_build_array, &array);
+}
+
+/**
+ * Only use this in non-performance critical situations
+ * (it iterates over all scene collections twice)
+ */
+void BKE_scene_collections_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ ID *owner_id = data_in;
+ SceneCollectionsIteratorData *data = MEM_callocN(sizeof(SceneCollectionsIteratorData), __func__);
+
+ data->owner_id = owner_id;
+ iter->data = data;
+ iter->valid = true;
+
+ scene_collections_array(owner_id, (SceneCollection ***)&data->array, &data->tot);
+ BLI_assert(data->tot != 0);
+
+ data->cur = 0;
+ iter->current = data->array[data->cur];
+}
+
+void BKE_scene_collections_iterator_next(struct BLI_Iterator *iter)
+{
+ SceneCollectionsIteratorData *data = iter->data;
+
+ if (++data->cur < data->tot) {
+ iter->current = data->array[data->cur];
+ }
+ else {
+ iter->valid = false;
+ }
+}
+
+void BKE_scene_collections_iterator_end(struct BLI_Iterator *iter)
+{
+ SceneCollectionsIteratorData *data = iter->data;
+
+ if (data) {
+ if (data->array) {
+ MEM_freeN(data->array);
+ }
+ MEM_freeN(data);
+ }
+ iter->valid = false;
+}
+
+
+/* scene objects iteractor */
+
+typedef struct SceneObjectsIteratorData {
+ GSet *visited;
+ LinkData *link_next;
+ BLI_Iterator scene_collection_iter;
+} SceneObjectsIteratorData;
+
+void BKE_scene_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ Scene *scene = data_in;
+ SceneObjectsIteratorData *data = MEM_callocN(sizeof(SceneObjectsIteratorData), __func__);
+ iter->data = data;
+
+ /* lookup list ot make sure each object is object called once */
+ data->visited = BLI_gset_ptr_new(__func__);
+
+ /* we wrap the scenecollection iterator here to go over the scene collections */
+ BKE_scene_collections_iterator_begin(&data->scene_collection_iter, scene);
+
+ SceneCollection *sc = data->scene_collection_iter.current;
+ if (sc->objects.first != NULL) {
+ iter->current = ((LinkData *)sc->objects.first)->data;
+ }
+ else {
+ BKE_scene_objects_iterator_next(iter);
+ }
+}
+
+/**
+ * Gets the first unique object in the sequence
+ */
+static LinkData *object_base_unique(GSet *gs, LinkData *link)
+{
+ for (; link != NULL; link = link->next) {
+ Object *ob = link->data;
+ void **ob_key_p;
+ if (!BLI_gset_ensure_p_ex(gs, ob, &ob_key_p)) {
+ *ob_key_p = ob;
+ return link;
+ }
+ }
+ return NULL;
+}
+
+void BKE_scene_objects_iterator_next(BLI_Iterator *iter)
+{
+ SceneObjectsIteratorData *data = iter->data;
+ LinkData *link = data->link_next ? object_base_unique(data->visited, data->link_next) : NULL;
+
+ if (link) {
+ data->link_next = link->next;
+ iter->current = link->data;
+ }
+ else {
+ /* if this is the last object of this ListBase look at the next SceneCollection */
+ SceneCollection *sc;
+ BKE_scene_collections_iterator_next(&data->scene_collection_iter);
+ do {
+ sc = data->scene_collection_iter.current;
+ /* get the first unique object of this collection */
+ LinkData *new_link = object_base_unique(data->visited, sc->objects.first);
+ if (new_link) {
+ data->link_next = new_link->next;
+ iter->current = new_link->data;
+ return;
+ }
+ BKE_scene_collections_iterator_next(&data->scene_collection_iter);
+ } while (data->scene_collection_iter.valid);
+
+ if (!data->scene_collection_iter.valid) {
+ iter->valid = false;
+ }
+ }
+}
+
+void BKE_scene_objects_iterator_end(BLI_Iterator *iter)
+{
+ SceneObjectsIteratorData *data = iter->data;
+ if (data) {
+ BKE_scene_collections_iterator_end(&data->scene_collection_iter);
+ BLI_gset_free(data->visited, NULL);
+ MEM_freeN(data);
+ }
+}
diff --git a/source/blender/blenkernel/intern/collision.c b/source/blender/blenkernel/intern/collision.c
index 65742df754e..ee3c38b9282 100644
--- a/source/blender/blenkernel/intern/collision.c
+++ b/source/blender/blenkernel/intern/collision.c
@@ -47,6 +47,8 @@
#include "BKE_cloth.h"
#include "BKE_effect.h"
+#include "BKE_group.h"
+#include "BKE_layer.h"
#include "BKE_modifier.h"
#include "BKE_scene.h"
@@ -501,22 +503,22 @@ static void add_collision_object(Object ***objs, unsigned int *numobj, unsigned
/* objects in dupli groups, one level only for now */
if (ob->dup_group && level == 0) {
- GroupObject *go;
Group *group= ob->dup_group;
/* add objects */
- for (go= group->gobject.first; go; go= go->next)
- add_collision_object(objs, numobj, maxobj, go->ob, self, level+1, modifier_type);
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ add_collision_object(objs, numobj, maxobj, object, self, level+1, modifier_type);
+ }
+ FOREACH_GROUP_OBJECT_END;
}
}
// return all collision objects in scene
// collision object will exclude self
-Object **get_collisionobjects_ext(Scene *scene, Object *self, Group *group, int layer, unsigned int *numcollobj, unsigned int modifier_type, bool dupli)
+Object **get_collisionobjects_ext(Scene *scene, Object *self, Group *group, unsigned int *numcollobj, unsigned int modifier_type, bool dupli)
{
- Base *base;
Object **objs;
- GroupObject *go;
unsigned int numobj= 0, maxobj= 100;
int level = dupli ? 0 : 1;
@@ -525,16 +527,20 @@ Object **get_collisionobjects_ext(Scene *scene, Object *self, Group *group, int
/* gather all collision objects */
if (group) {
/* use specified group */
- for (go= group->gobject.first; go; go= go->next)
- add_collision_object(&objs, &numobj, &maxobj, go->ob, self, level, modifier_type);
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ add_collision_object(&objs, &numobj, &maxobj, object, self, level, modifier_type);
+ }
+ FOREACH_GROUP_OBJECT_END;
}
else {
Scene *sce_iter;
+ Base *base;
/* add objects in same layer in scene */
for (SETLOOPER(scene, sce_iter, base)) {
- if ( base->lay & layer )
+ if ((base->flag & BASE_VISIBLED) != 0) {
add_collision_object(&objs, &numobj, &maxobj, base->object, self, level, modifier_type);
-
+ }
}
}
@@ -547,7 +553,7 @@ Object **get_collisionobjects(Scene *scene, Object *self, Group *group, unsigned
{
/* Need to check for active layers, too.
Otherwise this check fails if the objects are not on the same layer - DG */
- return get_collisionobjects_ext(scene, self, group, self->lay | scene->lay, numcollobj, modifier_type, true);
+ return get_collisionobjects_ext(scene, self, group, numcollobj, modifier_type, true);
}
static void add_collider_cache_object(ListBase **objs, Object *ob, Object *self, int level)
@@ -575,24 +581,28 @@ static void add_collider_cache_object(ListBase **objs, Object *ob, Object *self,
/* objects in dupli groups, one level only for now */
if (ob->dup_group && level == 0) {
- GroupObject *go;
Group *group= ob->dup_group;
/* add objects */
- for (go= group->gobject.first; go; go= go->next)
- add_collider_cache_object(objs, go->ob, self, level+1);
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ add_collider_cache_object(objs, object, self, level+1);
+ }
+ FOREACH_GROUP_OBJECT_END;
}
}
ListBase *get_collider_cache(Scene *scene, Object *self, Group *group)
{
- GroupObject *go;
ListBase *objs= NULL;
/* add object in same layer in scene */
if (group) {
- for (go= group->gobject.first; go; go= go->next)
- add_collider_cache_object(&objs, go->ob, self, 0);
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ add_collider_cache_object(&objs, object, self, 0);
+ }
+ FOREACH_GROUP_OBJECT_END;
}
else {
Scene *sce_iter;
@@ -600,7 +610,7 @@ ListBase *get_collider_cache(Scene *scene, Object *self, Group *group)
/* add objects in same layer in scene */
for (SETLOOPER(scene, sce_iter, base)) {
- if (!self || (base->lay & self->lay))
+ if (!self || ((base->flag & BASE_VISIBLED) != 0))
add_collider_cache_object(&objs, base->object, self, 0);
}
diff --git a/source/blender/blenkernel/intern/constraint.c b/source/blender/blenkernel/intern/constraint.c
index 13358311f92..6a477c9c06e 100644
--- a/source/blender/blenkernel/intern/constraint.c
+++ b/source/blender/blenkernel/intern/constraint.c
@@ -98,11 +98,6 @@
/* Constraint Target Macros */
#define VALID_CONS_TARGET(ct) ((ct) && (ct->tar))
-/* Workaround for cyclic depenndnecy with curves.
- * In such case curve_cache might not be ready yet,
- */
-#define CYCLIC_DEPENDENCY_WORKAROUND
-
/* ************************ Constraints - General Utilities *************************** */
/* These functions here don't act on any specific constraints, and are therefore should/will
* not require any of the special function-pointers afforded by the relevant constraint
@@ -689,7 +684,7 @@ static bConstraintTypeInfo CTI_CONSTRNAME = {
/* This function should be used for the get_target_matrix member of all
* constraints that are not picky about what happens to their target matrix.
*/
-static void default_get_tarmat(bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime))
+static void default_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *UNUSED(cob), bConstraintTarget *ct, float UNUSED(ctime))
{
if (VALID_CONS_TARGET(ct))
constraint_target_to_mat4(ct->tar, ct->subtarget, ct->matrix, CONSTRAINT_SPACE_WORLD, ct->space, con->flag, con->headtail);
@@ -1158,7 +1153,7 @@ static void kinematic_flush_tars(bConstraint *con, ListBase *list, bool no_copy)
}
}
-static void kinematic_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
+static void kinematic_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
{
bKinematicConstraint *data = con->data;
@@ -1245,7 +1240,9 @@ static void followpath_flush_tars(bConstraint *con, ListBase *list, bool no_copy
}
}
-static void followpath_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
+static void followpath_get_tarmat(struct Depsgraph *UNUSED(depsgraph),
+ bConstraint *con, bConstraintOb *UNUSED(cob),
+ bConstraintTarget *ct, float UNUSED(ctime))
{
bFollowPathConstraint *data = con->data;
@@ -1260,13 +1257,7 @@ static void followpath_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstra
* currently for paths to work it needs to go through the bevlist/displist system (ton)
*/
-#ifdef CYCLIC_DEPENDENCY_WORKAROUND
- if (ct->tar->curve_cache == NULL) {
- BKE_displist_make_curveTypes(cob->scene, ct->tar, false);
- }
-#endif
-
- if (ct->tar->curve_cache->path && ct->tar->curve_cache->path->data) {
+ if (ct->tar->curve_cache && ct->tar->curve_cache->path && ct->tar->curve_cache->path->data) {
float quat[4];
if ((data->followflag & FOLLOWPATH_STATIC) == 0) {
/* animated position along curve depending on time */
@@ -2028,21 +2019,19 @@ static void pycon_id_looper(bConstraint *con, ConstraintIDFunc func, void *userd
}
/* Whether this approach is maintained remains to be seen (aligorith) */
-static void pycon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
+static void pycon_get_tarmat(struct Depsgraph *UNUSED(depsgraph),
+ bConstraint *con, bConstraintOb *UNUSED(cob),
+ bConstraintTarget *ct, float UNUSED(ctime))
{
#ifdef WITH_PYTHON
bPythonConstraint *data = con->data;
#endif
if (VALID_CONS_TARGET(ct)) {
-#ifdef CYCLIC_DEPENDENCY_WORKAROUND
- /* special exception for curves - depsgraph issues */
- if (ct->tar->type == OB_CURVE) {
- if (ct->tar->curve_cache == NULL) {
- BKE_displist_make_curveTypes(cob->scene, ct->tar, false);
- }
+ if (ct->tar->type == OB_CURVE && ct->tar->curve_cache == NULL) {
+ unit_m4(ct->matrix);
+ return;
}
-#endif
/* firstly calculate the matrix the normal way, then let the py-function override
* this matrix if it needs to do so
@@ -2146,7 +2135,7 @@ static void actcon_flush_tars(bConstraint *con, ListBase *list, bool no_copy)
}
}
-static void actcon_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
+static void actcon_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
{
bActionConstraint *data = con->data;
@@ -3039,66 +3028,6 @@ static bConstraintTypeInfo CTI_MINMAX = {
minmax_evaluate /* evaluate */
};
-/* ------- RigidBody Joint ---------- */
-
-static void rbj_new_data(void *cdata)
-{
- bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint *)cdata;
-
- /* removed code which set target of this constraint */
- data->type = 1;
-}
-
-static void rbj_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
-{
- bRigidBodyJointConstraint *data = con->data;
-
- /* target only */
- func(con, (ID **)&data->tar, false, userdata);
- func(con, (ID **)&data->child, false, userdata);
-}
-
-static int rbj_get_tars(bConstraint *con, ListBase *list)
-{
- if (con && list) {
- bRigidBodyJointConstraint *data = con->data;
- bConstraintTarget *ct;
-
- /* standard target-getting macro for single-target constraints without subtargets */
- SINGLETARGETNS_GET_TARS(con, data->tar, ct, list);
-
- return 1;
- }
-
- return 0;
-}
-
-static void rbj_flush_tars(bConstraint *con, ListBase *list, bool no_copy)
-{
- if (con && list) {
- bRigidBodyJointConstraint *data = con->data;
- bConstraintTarget *ct = list->first;
-
- /* the following macro is used for all standard single-target constraints */
- SINGLETARGETNS_FLUSH_TARS(con, data->tar, ct, list, no_copy);
- }
-}
-
-static bConstraintTypeInfo CTI_RIGIDBODYJOINT = {
- CONSTRAINT_TYPE_RIGIDBODYJOINT, /* type */
- sizeof(bRigidBodyJointConstraint), /* size */
- "Rigid Body Joint", /* name */
- "bRigidBodyJointConstraint", /* struct name */
- NULL, /* free data */
- rbj_id_looper, /* id looper */
- NULL, /* copy data */
- rbj_new_data, /* new data */
- rbj_get_tars, /* get constraint targets */
- rbj_flush_tars, /* flush constraint targets */
- default_get_tarmat, /* get target matrix */
- NULL /* evaluate - this is not solved here... is just an interface for game-engine */
-};
-
/* -------- Clamp To ---------- */
static void clampto_id_looper(bConstraint *con, ConstraintIDFunc func, void *userdata)
@@ -3135,16 +3064,10 @@ static void clampto_flush_tars(bConstraint *con, ListBase *list, bool no_copy)
}
}
-static void clampto_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
+static void clampto_get_tarmat(struct Depsgraph *UNUSED(depsgraph),
+ bConstraint *UNUSED(con), bConstraintOb *UNUSED(cob),
+ bConstraintTarget *ct, float UNUSED(ctime))
{
-#ifdef CYCLIC_DEPENDENCY_WORKAROUND
- if (VALID_CONS_TARGET(ct)) {
- if (ct->tar->curve_cache == NULL) {
- BKE_displist_make_curveTypes(cob->scene, ct->tar, false);
- }
- }
-#endif
-
/* technically, this isn't really needed for evaluation, but we don't know what else
* might end up calling this...
*/
@@ -3478,7 +3401,7 @@ static void shrinkwrap_flush_tars(bConstraint *con, ListBase *list, bool no_copy
}
-static void shrinkwrap_get_tarmat(bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
+static void shrinkwrap_get_tarmat(struct Depsgraph *UNUSED(depsgraph), bConstraint *con, bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
{
bShrinkwrapConstraint *scon = (bShrinkwrapConstraint *) con->data;
@@ -3809,16 +3732,10 @@ static void splineik_flush_tars(bConstraint *con, ListBase *list, bool no_copy)
}
}
-static void splineik_get_tarmat(bConstraint *UNUSED(con), bConstraintOb *cob, bConstraintTarget *ct, float UNUSED(ctime))
+static void splineik_get_tarmat(struct Depsgraph *UNUSED(depsgraph),
+ bConstraint *UNUSED(con), bConstraintOb *UNUSED(cob),
+ bConstraintTarget *ct, float UNUSED(ctime))
{
-#ifdef CYCLIC_DEPENDENCY_WORKAROUND
- if (VALID_CONS_TARGET(ct)) {
- if (ct->tar->curve_cache == NULL) {
- BKE_displist_make_curveTypes(cob->scene, ct->tar, false);
- }
- }
-#endif
-
/* technically, this isn't really needed for evaluation, but we don't know what else
* might end up calling this...
*/
@@ -4460,7 +4377,7 @@ static void constraints_init_typeinfo(void)
constraintsTypeInfo[14] = &CTI_DISTLIMIT; /* Limit Distance Constraint */
constraintsTypeInfo[15] = &CTI_STRETCHTO; /* StretchTo Constaint */
constraintsTypeInfo[16] = &CTI_MINMAX; /* Floor Constraint */
- constraintsTypeInfo[17] = &CTI_RIGIDBODYJOINT; /* RigidBody Constraint */
+ /* constraintsTypeInfo[17] = &CTI_RIGIDBODYJOINT; */ /* RigidBody Constraint - Deprecated */
constraintsTypeInfo[18] = &CTI_CLAMPTO; /* ClampTo Constraint */
constraintsTypeInfo[19] = &CTI_TRANSFORM; /* Transformation Constraint */
constraintsTypeInfo[20] = &CTI_SHRINKWRAP; /* Shrinkwrap Constraint */
@@ -4612,7 +4529,7 @@ static bConstraint *add_new_constraint_internal(const char *name, short type)
/* Set up a generic constraint datablock */
con->type = type;
- con->flag |= CONSTRAINT_EXPAND;
+ con->flag |= CONSTRAINT_EXPAND | CONSTRAINT_STATICOVERRIDE_LOCAL;
con->enforce = 1.0f;
/* Determine a basic name, and info */
@@ -4739,6 +4656,43 @@ static void con_fix_copied_refs_cb(bConstraint *UNUSED(con), ID **idpoin, bool i
id_us_plus(*idpoin);
}
+/** Copies a single constraint's data (\a dst must already be a shallow copy of \a src). */
+static void constraint_copy_data_ex(bConstraint *dst, bConstraint *src, const int flag, const bool do_extern)
+{
+ const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(src);
+
+ /* make a new copy of the constraint's data */
+ dst->data = MEM_dupallocN(dst->data);
+
+ /* only do specific constraints if required */
+ if (cti) {
+ /* perform custom copying operations if needed */
+ if (cti->copy_data)
+ cti->copy_data(dst, src);
+
+ /* Fix usercounts for all referenced data that need it. */
+ if (cti->id_looper && (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
+ cti->id_looper(dst, con_fix_copied_refs_cb, NULL);
+ }
+
+ /* for proxies we don't want to make extern */
+ if (do_extern) {
+ /* go over used ID-links for this constraint to ensure that they are valid for proxies */
+ if (cti->id_looper)
+ cti->id_looper(dst, con_extern_cb, NULL);
+ }
+ }
+}
+
+/** Allocate and duplicate a single constraint, ouside of any object/pose context. */
+bConstraint *BKE_constraint_duplicate_ex(bConstraint *src, const int flag, const bool do_extern)
+{
+ bConstraint *dst = MEM_dupallocN(src);
+ constraint_copy_data_ex(dst, src, flag, do_extern);
+ dst->next = dst->prev = NULL;
+ return dst;
+}
+
/* duplicate all of the constraints in a constraint stack */
void BKE_constraints_copy_ex(ListBase *dst, const ListBase *src, const int flag, bool do_extern)
{
@@ -4748,29 +4702,7 @@ void BKE_constraints_copy_ex(ListBase *dst, const ListBase *src, const int flag,
BLI_duplicatelist(dst, src);
for (con = dst->first, srccon = src->first; con && srccon; srccon = srccon->next, con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
-
- /* make a new copy of the constraint's data */
- con->data = MEM_dupallocN(con->data);
-
- /* only do specific constraints if required */
- if (cti) {
- /* perform custom copying operations if needed */
- if (cti->copy_data)
- cti->copy_data(con, srccon);
-
- /* Fix usercounts for all referenced data that need it. */
- if (cti->id_looper && (flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
- cti->id_looper(con, con_fix_copied_refs_cb, NULL);
- }
-
- /* for proxies we don't want to make extern */
- if (do_extern) {
- /* go over used ID-links for this constraint to ensure that they are valid for proxies */
- if (cti->id_looper)
- cti->id_looper(con, con_extern_cb, NULL);
- }
- }
+ constraint_copy_data_ex(con, srccon, flag, do_extern);
}
}
@@ -4867,7 +4799,7 @@ bool BKE_constraints_proxylocked_owner(Object *ob, bPoseChannel *pchan)
* None of the actual calculations of the matrices should be done here! Also, this function is
* not to be used by any new constraints, particularly any that have multiple targets.
*/
-void BKE_constraint_target_matrix_get(Scene *scene, bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime)
+void BKE_constraint_target_matrix_get(struct Depsgraph *depsgraph, Scene *scene, bConstraint *con, int index, short ownertype, void *ownerdata, float mat[4][4], float ctime)
{
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
ListBase targets = {NULL, NULL};
@@ -4918,7 +4850,7 @@ void BKE_constraint_target_matrix_get(Scene *scene, bConstraint *con, int index,
if (ct) {
if (cti->get_target_matrix)
- cti->get_target_matrix(con, cob, ct, ctime);
+ cti->get_target_matrix(depsgraph, con, cob, ct, ctime);
copy_m4_m4(mat, ct->matrix);
}
@@ -4934,7 +4866,7 @@ void BKE_constraint_target_matrix_get(Scene *scene, bConstraint *con, int index,
}
/* Get the list of targets required for solving a constraint */
-void BKE_constraint_targets_for_solving_get(bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime)
+void BKE_constraint_targets_for_solving_get(struct Depsgraph *depsgraph, bConstraint *con, bConstraintOb *cob, ListBase *targets, float ctime)
{
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
@@ -4952,7 +4884,7 @@ void BKE_constraint_targets_for_solving_get(bConstraint *con, bConstraintOb *cob
*/
if (cti->get_target_matrix) {
for (ct = targets->first; ct; ct = ct->next)
- cti->get_target_matrix(con, cob, ct, ctime);
+ cti->get_target_matrix(depsgraph, con, cob, ct, ctime);
}
else {
for (ct = targets->first; ct; ct = ct->next)
@@ -4969,7 +4901,7 @@ void BKE_constraint_targets_for_solving_get(bConstraint *con, bConstraintOb *cob
* BKE_constraints_make_evalob and BKE_constraints_clear_evalob should be called before and
* after running this function, to sort out cob
*/
-void BKE_constraints_solve(ListBase *conlist, bConstraintOb *cob, float ctime)
+void BKE_constraints_solve(struct Depsgraph *depsgraph, ListBase *conlist, bConstraintOb *cob, float ctime)
{
bConstraint *con;
float oldmat[4][4];
@@ -5004,7 +4936,7 @@ void BKE_constraints_solve(ListBase *conlist, bConstraintOb *cob, float ctime)
BKE_constraint_mat_convertspace(cob->ob, cob->pchan, cob->matrix, CONSTRAINT_SPACE_WORLD, con->ownspace, false);
/* prepare targets for constraint solving */
- BKE_constraint_targets_for_solving_get(con, cob, &targets, ctime);
+ BKE_constraint_targets_for_solving_get(depsgraph, con, cob, &targets, ctime);
/* Solve the constraint and put result in cob->matrix */
cti->evaluate_constraint(con, cob, &targets);
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index 4c01bfd35f2..f420fd974cd 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -38,6 +38,9 @@
#include "DNA_object_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_gpencil_types.h"
+#include "DNA_workspace_types.h"
+
+#include "DEG_depsgraph.h"
#include "BLI_listbase.h"
#include "BLI_string.h"
@@ -47,9 +50,14 @@
#include "BLT_translation.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
+#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sound.h"
+#include "BKE_workspace.h"
+
+#include "RE_engine.h"
#include "RNA_access.h"
@@ -66,10 +74,12 @@ struct bContext {
struct {
struct wmWindowManager *manager;
struct wmWindow *window;
+ struct WorkSpace *workspace;
struct bScreen *screen;
struct ScrArea *area;
struct ARegion *region;
struct ARegion *menu;
+ struct wmManipulatorGroup *manipulator_group;
struct bContextStore *store;
const char *operator_poll_msg; /* reason for poll failing */
} wm;
@@ -627,6 +637,11 @@ wmWindow *CTX_wm_window(const bContext *C)
return ctx_wm_python_context_get(C, "window", &RNA_Window, C->wm.window);
}
+WorkSpace *CTX_wm_workspace(const bContext *C)
+{
+ return ctx_wm_python_context_get(C, "workspace", &RNA_WorkSpace, C->wm.workspace);
+}
+
bScreen *CTX_wm_screen(const bContext *C)
{
return ctx_wm_python_context_get(C, "screen", &RNA_Screen, C->wm.screen);
@@ -659,6 +674,16 @@ struct ARegion *CTX_wm_menu(const bContext *C)
return C->wm.menu;
}
+struct wmManipulatorGroup *CTX_wm_manipulator_group(const bContext *C)
+{
+ return C->wm.manipulator_group;
+}
+
+struct wmMsgBus *CTX_wm_message_bus(const bContext *C)
+{
+ return C->wm.manager ? C->wm.manager->message_bus : NULL;
+}
+
struct ReportList *CTX_wm_reports(const bContext *C)
{
if (C->wm.manager)
@@ -750,14 +775,6 @@ struct SpaceNla *CTX_wm_space_nla(const bContext *C)
return NULL;
}
-struct SpaceTime *CTX_wm_space_time(const bContext *C)
-{
- ScrArea *sa = CTX_wm_area(C);
- if (sa && sa->spacetype == SPACE_TIME)
- return sa->spacedata.first;
- return NULL;
-}
-
struct SpaceNode *CTX_wm_space_node(const bContext *C)
{
ScrArea *sa = CTX_wm_area(C);
@@ -766,14 +783,6 @@ struct SpaceNode *CTX_wm_space_node(const bContext *C)
return NULL;
}
-struct SpaceLogic *CTX_wm_space_logic(const bContext *C)
-{
- ScrArea *sa = CTX_wm_area(C);
- if (sa && sa->spacetype == SPACE_LOGIC)
- return sa->spacedata.first;
- return NULL;
-}
-
struct SpaceIpo *CTX_wm_space_graph(const bContext *C)
{
ScrArea *sa = CTX_wm_area(C);
@@ -814,6 +823,14 @@ struct SpaceClip *CTX_wm_space_clip(const bContext *C)
return NULL;
}
+struct SpaceTopBar *CTX_wm_space_topbar(const bContext *C)
+{
+ ScrArea *sa = CTX_wm_area(C);
+ if (sa && sa->spacetype == SPACE_TOPBAR)
+ return sa->spacedata.first;
+ return NULL;
+}
+
void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
{
C->wm.manager = wm;
@@ -826,9 +843,11 @@ void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
void CTX_wm_window_set(bContext *C, wmWindow *win)
{
C->wm.window = win;
- C->wm.screen = (win) ? win->screen : NULL;
- if (C->wm.screen)
- C->data.scene = C->wm.screen->scene;
+ if (win) {
+ C->data.scene = win->scene;
+ }
+ C->wm.workspace = (win) ? BKE_workspace_active_get(win->workspace_hook) : NULL;
+ C->wm.screen = (win) ? BKE_workspace_active_screen_get(win->workspace_hook) : NULL;
C->wm.area = NULL;
C->wm.region = NULL;
}
@@ -836,8 +855,6 @@ void CTX_wm_window_set(bContext *C, wmWindow *win)
void CTX_wm_screen_set(bContext *C, bScreen *screen)
{
C->wm.screen = screen;
- if (C->wm.screen)
- C->data.scene = C->wm.screen->scene;
C->wm.area = NULL;
C->wm.region = NULL;
}
@@ -858,6 +875,11 @@ void CTX_wm_menu_set(bContext *C, ARegion *menu)
C->wm.menu = menu;
}
+void CTX_wm_manipulator_group_set(bContext *C, struct wmManipulatorGroup *mgroup)
+{
+ C->wm.manipulator_group = mgroup;
+}
+
void CTX_wm_operator_poll_msg_set(bContext *C, const char *msg)
{
C->wm.operator_poll_msg = msg;
@@ -896,10 +918,66 @@ Scene *CTX_data_scene(const bContext *C)
return C->data.scene;
}
-int CTX_data_mode_enum(const bContext *C)
+ViewLayer *CTX_data_view_layer(const bContext *C)
{
- Object *obedit = CTX_data_edit_object(C);
+ ViewLayer *view_layer;
+ if (ctx_data_pointer_verify(C, "view_layer", (void *)&view_layer)) {
+ return view_layer;
+ }
+ else {
+ return BKE_view_layer_from_workspace_get(CTX_data_scene(C), CTX_wm_workspace(C));
+ }
+}
+
+RenderEngineType *CTX_data_engine_type(const bContext *C)
+{
+ Scene *scene = CTX_data_scene(C);
+ return RE_engines_find(scene->r.engine);
+}
+
+/**
+ * This is tricky. Sometimes the user overrides the render_layer
+ * but not the scene_collection. In this case what to do?
+ *
+ * If the scene_collection is linked to the ViewLayer we use it.
+ * Otherwise we fallback to the active one of the ViewLayer.
+ */
+LayerCollection *CTX_data_layer_collection(const bContext *C)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ LayerCollection *layer_collection;
+
+ if (ctx_data_pointer_verify(C, "layer_collection", (void *)&layer_collection)) {
+ if (BKE_view_layer_has_collection(view_layer, layer_collection->scene_collection)) {
+ return layer_collection;
+ }
+ }
+
+ /* fallback */
+ return BKE_layer_collection_get_active(view_layer);
+}
+
+SceneCollection *CTX_data_scene_collection(const bContext *C)
+{
+ SceneCollection *scene_collection;
+ if (ctx_data_pointer_verify(C, "scene_collection", (void *)&scene_collection)) {
+ return scene_collection;
+ }
+
+ LayerCollection *layer_collection = CTX_data_layer_collection(C);
+ if (layer_collection) {
+ return layer_collection->scene_collection;
+ }
+
+ /* fallback */
+ Scene *scene = CTX_data_scene(C);
+ return BKE_collection_master(&scene->id);
+}
+
+int CTX_data_mode_enum_ex(const Object *obedit, const Object *ob, const eObjectMode object_mode)
+{
+ // Object *obedit = CTX_data_edit_object(C);
if (obedit) {
switch (obedit->type) {
case OB_MESH:
@@ -919,21 +997,26 @@ int CTX_data_mode_enum(const bContext *C)
}
}
else {
- Object *ob = CTX_data_active_object(C);
-
+ // Object *ob = CTX_data_active_object(C);
if (ob) {
- if (ob->mode & OB_MODE_POSE) return CTX_MODE_POSE;
- else if (ob->mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT;
- else if (ob->mode & OB_MODE_WEIGHT_PAINT) return CTX_MODE_PAINT_WEIGHT;
- else if (ob->mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX;
- else if (ob->mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE;
- else if (ob->mode & OB_MODE_PARTICLE_EDIT) return CTX_MODE_PARTICLE;
+ if (object_mode & OB_MODE_POSE) return CTX_MODE_POSE;
+ else if (object_mode & OB_MODE_SCULPT) return CTX_MODE_SCULPT;
+ else if (object_mode & OB_MODE_WEIGHT_PAINT) return CTX_MODE_PAINT_WEIGHT;
+ else if (object_mode & OB_MODE_VERTEX_PAINT) return CTX_MODE_PAINT_VERTEX;
+ else if (object_mode & OB_MODE_TEXTURE_PAINT) return CTX_MODE_PAINT_TEXTURE;
+ else if (object_mode & OB_MODE_PARTICLE_EDIT) return CTX_MODE_PARTICLE;
}
}
return CTX_MODE_OBJECT;
}
+int CTX_data_mode_enum(const bContext *C)
+{
+ Object *obedit = CTX_data_edit_object(C);
+ Object *obact = obedit ? NULL : CTX_data_active_object(C);
+ return CTX_data_mode_enum_ex(obedit, obact, obact ? obact->mode : OB_MODE_OBJECT);
+}
/* would prefer if we can use the enum version below over this one - Campbell */
/* must be aligned with above enum */
@@ -954,6 +1037,7 @@ static const char *data_mode_strings[] = {
"objectmode",
NULL
};
+BLI_STATIC_ASSERT(ARRAY_SIZE(data_mode_strings) == CTX_MODE_NUM + 1, "Must have a string for each context mode")
const char *CTX_data_mode_string(const bContext *C)
{
return data_mode_strings[CTX_data_mode_enum(C)];
@@ -1154,3 +1238,16 @@ int CTX_data_editable_gpencil_strokes(const bContext *C, ListBase *list)
return ctx_data_collection_get(C, "editable_gpencil_strokes", list);
}
+Depsgraph *CTX_data_depsgraph(const bContext *C)
+{
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ return BKE_scene_get_depsgraph(scene, view_layer, true);
+}
+
+Depsgraph *CTX_data_depsgraph_on_load(const bContext *C)
+{
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ return BKE_scene_get_depsgraph(scene, view_layer, false);
+}
diff --git a/source/blender/blenkernel/intern/crazyspace.c b/source/blender/blenkernel/intern/crazyspace.c
index 56df8e51eba..0a31411d638 100644
--- a/source/blender/blenkernel/intern/crazyspace.c
+++ b/source/blender/blenkernel/intern/crazyspace.c
@@ -99,7 +99,8 @@ static int modifiers_disable_subsurf_temporary(Object *ob)
}
/* disable subsurf temporal, get mapped cos, and enable it */
-float (*BKE_crazyspace_get_mapped_editverts(Scene *scene, Object *obedit))[3]
+float (*BKE_crazyspace_get_mapped_editverts(
+ struct Depsgraph *depsgraph, Scene *scene, Object *obedit))[3]
{
Mesh *me = obedit->data;
DerivedMesh *dm;
@@ -109,13 +110,13 @@ float (*BKE_crazyspace_get_mapped_editverts(Scene *scene, Object *obedit))[3]
/* disable subsurf temporal, get mapped cos, and enable it */
if (modifiers_disable_subsurf_temporary(obedit)) {
/* need to make new derivemesh */
- makeDerivedMesh(scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH, false);
+ makeDerivedMesh(depsgraph, scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH, false);
}
/* now get the cage */
vertexcos = MEM_mallocN(sizeof(*vertexcos) * nverts, "vertexcos map");
- dm = editbmesh_get_derived_cage(scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH);
+ dm = editbmesh_get_derived_cage(depsgraph, scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH);
mesh_get_mapped_verts_coords(dm, vertexcos, nverts);
@@ -250,8 +251,9 @@ void BKE_crazyspace_set_quats_mesh(Mesh *me, float (*origcos)[3], float (*mapped
/** returns an array of deform matrices for crazyspace correction, and the
* number of modifiers left */
-int BKE_crazyspace_get_first_deform_matrices_editbmesh(Scene *scene, Object *ob, BMEditMesh *em,
- float (**deformmats)[3][3], float (**deformcos)[3])
+int BKE_crazyspace_get_first_deform_matrices_editbmesh(
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob, BMEditMesh *em,
+ float (**deformmats)[3][3], float (**deformcos)[3])
{
ModifierData *md;
DerivedMesh *dm;
@@ -259,6 +261,7 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(Scene *scene, Object *ob,
int cageIndex = modifiers_getCageIndex(scene, ob, NULL, 1);
float (*defmats)[3][3] = NULL, (*deformedVerts)[3] = NULL;
VirtualModifierData virtualModifierData;
+ ModifierEvalContext mectx = {depsgraph, ob, 0};
modifiers_clearErrors(ob);
@@ -274,7 +277,7 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(Scene *scene, Object *ob,
if (!editbmesh_modifier_is_enabled(scene, md, dm))
continue;
- if (mti->type == eModifierTypeType_OnlyDeform && mti->deformMatricesEM) {
+ if (mti->type == eModifierTypeType_OnlyDeform && (mti->deformMatricesEM || mti->deformMatricesEM_DM)) {
if (!defmats) {
const int required_mode = eModifierMode_Realtime | eModifierMode_Editmode;
CustomDataMask data_mask = CD_MASK_BAREMESH;
@@ -290,8 +293,7 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(Scene *scene, Object *ob,
unit_m3(defmats[a]);
}
- mti->deformMatricesEM(md, ob, em, dm, deformedVerts, defmats,
- numVerts);
+ modifier_deformMatricesEM_DM_deprecated(md, &mectx, em, dm, deformedVerts, defmats, numVerts);
}
else
break;
@@ -310,7 +312,9 @@ int BKE_crazyspace_get_first_deform_matrices_editbmesh(Scene *scene, Object *ob,
return numleft;
}
-int BKE_sculpt_get_first_deform_matrices(Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3])
+int BKE_sculpt_get_first_deform_matrices(
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, float (**deformmats)[3][3], float (**deformcos)[3])
{
ModifierData *md;
DerivedMesh *dm;
@@ -320,6 +324,7 @@ int BKE_sculpt_get_first_deform_matrices(Scene *scene, Object *ob, float (**defo
const bool has_multires = mmd != NULL && mmd->sculptlvl > 0;
int numleft = 0;
VirtualModifierData virtualModifierData;
+ ModifierEvalContext mectx = {depsgraph, ob, 0};
if (has_multires) {
*deformmats = NULL;
@@ -346,7 +351,9 @@ int BKE_sculpt_get_first_deform_matrices(Scene *scene, Object *ob, float (**defo
unit_m3(defmats[a]);
}
- if (mti->deformMatrices) mti->deformMatrices(md, ob, dm, deformedVerts, defmats, numVerts);
+ if (mti->deformMatrices || mti->deformMatrices_DM) {
+ modifier_deformMatrices_DM_deprecated(md, &mectx, dm, deformedVerts, defmats, numVerts);
+ }
else break;
}
}
@@ -369,9 +376,9 @@ int BKE_sculpt_get_first_deform_matrices(Scene *scene, Object *ob, float (**defo
return numleft;
}
-void BKE_crazyspace_build_sculpt(Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3])
+void BKE_crazyspace_build_sculpt(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float (**deformmats)[3][3], float (**deformcos)[3])
{
- int totleft = BKE_sculpt_get_first_deform_matrices(scene, ob, deformmats, deformcos);
+ int totleft = BKE_sculpt_get_first_deform_matrices(depsgraph, scene, ob, deformmats, deformcos);
if (totleft) {
/* there are deformation modifier which doesn't support deformation matrices
@@ -383,6 +390,7 @@ void BKE_crazyspace_build_sculpt(Scene *scene, Object *ob, float (**deformmats)[
int i, deformed = 0;
VirtualModifierData virtualModifierData;
ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
+ ModifierEvalContext mectx = {depsgraph, ob, 0};
Mesh *me = (Mesh *)ob->data;
for (; md; md = md->next) {
@@ -393,10 +401,10 @@ void BKE_crazyspace_build_sculpt(Scene *scene, Object *ob, float (**deformmats)[
if (mti->type == eModifierTypeType_OnlyDeform) {
/* skip leading modifiers which have been already
* handled in sculpt_get_first_deform_matrices */
- if (mti->deformMatrices && !deformed)
+ if ((mti->deformMatrices || mti->deformMatrices_DM) && !deformed)
continue;
- mti->deformVerts(md, ob, NULL, deformedVerts, me->totvert, 0);
+ modifier_deformVerts_DM_deprecated(md, &mectx, NULL, deformedVerts, me->totvert);
deformed = 1;
}
}
diff --git a/source/blender/blenkernel/intern/curve.c b/source/blender/blenkernel/intern/curve.c
index 943cab0a9fc..cea5685a7a1 100644
--- a/source/blender/blenkernel/intern/curve.c
+++ b/source/blender/blenkernel/intern/curve.c
@@ -53,7 +53,6 @@
#include "BKE_animsys.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_displist.h"
#include "BKE_font.h"
#include "BKE_global.h"
@@ -129,6 +128,8 @@ void BKE_curve_free(Curve *cu)
{
BKE_animdata_free((ID *)cu, false);
+ BKE_curve_batch_cache_free(cu);
+
BKE_nurbList_free(&cu->nurb);
BKE_curve_editfont_free(cu);
@@ -209,6 +210,7 @@ void BKE_curve_copy_data(Main *bmain, Curve *cu_dst, const Curve *cu_src, const
cu_dst->strinfo = MEM_dupallocN(cu_src->strinfo);
cu_dst->tb = MEM_dupallocN(cu_src->tb);
cu_dst->bb = MEM_dupallocN(cu_src->bb);
+ cu_dst->batch_cache = NULL;
if (cu_src->key) {
BKE_id_copy_ex(bmain, &cu_src->key->id, (ID **)&cu_dst->key, flag, false);
@@ -1622,7 +1624,7 @@ float *BKE_curve_surf_make_orco(Object *ob)
/* NOTE: This routine is tied to the order of vertex
* built by displist and as passed to the renderer.
*/
-float *BKE_curve_make_orco(Scene *scene, Object *ob, int *r_numVerts)
+float *BKE_curve_make_orco(Depsgraph *depsgraph, Scene *scene, Object *ob, int *r_numVerts)
{
Curve *cu = ob->data;
DispList *dl;
@@ -1630,7 +1632,7 @@ float *BKE_curve_make_orco(Scene *scene, Object *ob, int *r_numVerts)
float *fp, *coord_array;
ListBase disp = {NULL, NULL};
- BKE_displist_make_curveTypes_forOrco(scene, ob, &disp);
+ BKE_displist_make_curveTypes_forOrco(depsgraph, scene, ob, &disp);
numVerts = 0;
for (dl = disp.first; dl; dl = dl->next) {
@@ -1721,8 +1723,9 @@ float *BKE_curve_make_orco(Scene *scene, Object *ob, int *r_numVerts)
/* ***************** BEVEL ****************** */
-void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp,
- const bool for_render, const bool use_render_resolution)
+void BKE_curve_bevel_make(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *disp,
+ const bool for_render, const bool use_render_resolution)
{
DispList *dl, *dlnew;
Curve *bevcu, *cu;
@@ -1746,7 +1749,7 @@ void BKE_curve_bevel_make(Scene *scene, Object *ob, ListBase *disp,
facy = cu->bevobj->size[1];
if (for_render) {
- BKE_displist_make_curveTypes_forRender(scene, cu->bevobj, &bevdisp, NULL, false, use_render_resolution);
+ BKE_displist_make_curveTypes_forRender(depsgraph, scene, cu->bevobj, &bevdisp, NULL, false, use_render_resolution);
dl = bevdisp.first;
}
else if (cu->bevobj->curve_cache) {
@@ -5185,7 +5188,7 @@ int BKE_curve_material_index_validate(Curve *cu)
}
if (!is_valid) {
- DAG_id_tag_update(&cu->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&cu->id, OB_RECALC_DATA);
return true;
}
else {
@@ -5252,11 +5255,28 @@ void BKE_curve_rect_from_textbox(const struct Curve *cu, const struct TextBox *t
/* **** Depsgraph evaluation **** */
-void BKE_curve_eval_geometry(EvaluationContext *UNUSED(eval_ctx),
+void BKE_curve_eval_geometry(Depsgraph *depsgraph,
Curve *curve)
{
- DEG_debug_print_eval(__func__, curve->id.name, curve);
+ DEG_debug_print_eval(depsgraph, __func__, curve->id.name, curve);
if (curve->bb == NULL || (curve->bb->flag & BOUNDBOX_DIRTY)) {
BKE_curve_texspace_calc(curve);
}
}
+
+/* Draw Engine */
+void (*BKE_curve_batch_cache_dirty_cb)(Curve *cu, int mode) = NULL;
+void (*BKE_curve_batch_cache_free_cb)(Curve *cu) = NULL;
+
+void BKE_curve_batch_cache_dirty(Curve *cu, int mode)
+{
+ if (cu->batch_cache) {
+ BKE_curve_batch_cache_dirty_cb(cu, mode);
+ }
+}
+void BKE_curve_batch_cache_free(Curve *cu)
+{
+ if (cu->batch_cache) {
+ BKE_curve_batch_cache_free_cb(cu);
+ }
+}
diff --git a/source/blender/blenkernel/intern/customdata.c b/source/blender/blenkernel/intern/customdata.c
index cf86963cf60..9c0ace2f654 100644
--- a/source/blender/blenkernel/intern/customdata.c
+++ b/source/blender/blenkernel/intern/customdata.c
@@ -390,37 +390,19 @@ static void layerSwap_tface(void *data, const int *corner_indices)
{
MTFace *tf = data;
float uv[4][2];
- static const short pin_flags[4] = { TF_PIN1, TF_PIN2, TF_PIN3, TF_PIN4 };
- static const char sel_flags[4] = { TF_SEL1, TF_SEL2, TF_SEL3, TF_SEL4 };
- short unwrap = tf->unwrap & ~(TF_PIN1 | TF_PIN2 | TF_PIN3 | TF_PIN4);
- char flag = tf->flag & ~(TF_SEL1 | TF_SEL2 | TF_SEL3 | TF_SEL4);
int j;
for (j = 0; j < 4; ++j) {
const int source_index = corner_indices[j];
-
copy_v2_v2(uv[j], tf->uv[source_index]);
-
- /* swap pinning flags around */
- if (tf->unwrap & pin_flags[source_index]) {
- unwrap |= pin_flags[j];
- }
-
- /* swap selection flags around */
- if (tf->flag & sel_flags[source_index]) {
- flag |= sel_flags[j];
- }
}
memcpy(tf->uv, uv, sizeof(tf->uv));
- tf->unwrap = unwrap;
- tf->flag = flag;
}
static void layerDefault_tface(void *data, int count)
{
- static MTFace default_tf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, NULL,
- 0, 0, TF_DYNAMIC | TF_CONVERTED, 0, 0};
+ static MTFace default_tf = {{{0, 0}, {1, 0}, {1, 1}, {0, 1}}};
MTFace *tf = (MTFace *)data;
int i;
@@ -1190,6 +1172,15 @@ static void layerSwap_flnor(void *data, const int *corner_indices)
memcpy(flnors, nors, sizeof(nors));
}
+static void layerDefault_fmap(void *data, int count)
+{
+ int *fmap_num = (int *)data;
+ int i;
+ for (i = 0; i < count; i++) {
+ *fmap_num = -1;
+ }
+}
+
static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 0: CD_MVERT */
{sizeof(MVert), "MVert", 1, NULL, NULL, NULL, NULL, NULL, NULL},
@@ -1215,8 +1206,8 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
/* 3 floats per normal vector */
{sizeof(float) * 3, "vec3f", 1, NULL, NULL, NULL, layerInterp_normal, NULL, NULL,
NULL, NULL, NULL, NULL, NULL, layerCopyValue_normal},
- /* 9: CD_POLYINDEX */ /* DEPRECATED */
- {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
+ /* 9: CD_FACEMAP */
+ {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, layerDefault_fmap, NULL},
/* 10: CD_PROP_FLT */
{sizeof(MFloatProperty), "MFloatProperty", 1, N_("Float"), layerCopy_propFloat, NULL, NULL, NULL},
/* 11: CD_PROP_INT */
@@ -1228,10 +1219,9 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
layerInterp_origspace_face, layerSwap_origspace_face, layerDefault_origspace_face},
/* 14: CD_ORCO */
{sizeof(float) * 3, "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
- /* 15: CD_MTEXPOLY */
+ /* 15: CD_MTEXPOLY */ /* DEPRECATED */
/* note, when we expose the UV Map / TexFace split to the user, change this back to face Texture */
- {sizeof(MTexPoly), "MTexPoly", 1, N_("UVMap") /* "Face Texture" */, NULL, NULL, NULL, NULL, NULL,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, layerMaxNum_tface},
+ {sizeof(int), "", 0, NULL, NULL, NULL, NULL, NULL, NULL},
/* 16: CD_MLOOPUV */
{sizeof(MLoopUV), "MLoopUV", 1, N_("UVMap"), NULL, NULL, layerInterp_mloopuv, NULL, NULL,
layerEqual_mloopuv, layerMultiply_mloopuv, layerInitMinMax_mloopuv,
@@ -1310,7 +1300,7 @@ static const LayerTypeInfo LAYERTYPEINFO[CD_NUMTYPES] = {
static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
/* 0-4 */ "CDMVert", "CDMSticky", "CDMDeformVert", "CDMEdge", "CDMFace",
- /* 5-9 */ "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFlags",
+ /* 5-9 */ "CDMTFace", "CDMCol", "CDOrigIndex", "CDNormal", "CDFaceMap",
/* 10-14 */ "CDMFloatProperty", "CDMIntProperty", "CDMStringProperty", "CDOrigSpace", "CDOrco",
/* 15-19 */ "CDMTexPoly", "CDMLoopUV", "CDMloopCol", "CDTangent", "CDMDisps",
/* 20-24 */ "CDPreviewMCol", "CDIDMCol", "CDTextureMCol", "CDClothOrco", "CDMRecast",
@@ -1325,41 +1315,41 @@ static const char *LAYERTYPENAMES[CD_NUMTYPES] = {
const CustomDataMask CD_MASK_BAREMESH =
- CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MLOOP | CD_MASK_MPOLY | CD_MASK_BWEIGHT;
+ CD_MASK_MVERT | CD_MASK_MEDGE | CD_MASK_MLOOP | CD_MASK_MPOLY | CD_MASK_BWEIGHT | CD_MASK_FACEMAP;
const CustomDataMask CD_MASK_MESH =
CD_MASK_MVERT | CD_MASK_MEDGE |
CD_MASK_MDEFORMVERT |
CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_MDISPS |
CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MPOLY | CD_MASK_MLOOP |
- CD_MASK_MTEXPOLY | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
+ CD_MASK_RECAST | CD_MASK_PAINT_MASK |
CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
- CD_MASK_CUSTOMLOOPNORMAL;
+ CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_FACEMAP;
const CustomDataMask CD_MASK_EDITMESH =
CD_MASK_MDEFORMVERT | CD_MASK_MLOOPUV |
- CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_SHAPE_KEYINDEX |
+ CD_MASK_MLOOPCOL | CD_MASK_SHAPE_KEYINDEX |
CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_PROP_STR |
CD_MASK_MDISPS | CD_MASK_SHAPEKEY | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
- CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_CUSTOMLOOPNORMAL;
+ CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_FACEMAP;
const CustomDataMask CD_MASK_DERIVEDMESH =
CD_MASK_MDEFORMVERT |
CD_MASK_PROP_FLT | CD_MASK_PROP_INT | CD_MASK_CLOTH_ORCO |
- CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY | CD_MASK_PREVIEW_MLOOPCOL |
+ CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_PREVIEW_MLOOPCOL |
CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP | CD_MASK_ORCO | CD_MASK_TANGENT |
CD_MASK_PREVIEW_MCOL | CD_MASK_SHAPEKEY | CD_MASK_RECAST |
CD_MASK_ORIGINDEX | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
- CD_MASK_CUSTOMLOOPNORMAL;
+ CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_FACEMAP;
const CustomDataMask CD_MASK_BMESH =
- CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL | CD_MASK_MTEXPOLY |
+ CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL |
CD_MASK_MDEFORMVERT | CD_MASK_PROP_FLT | CD_MASK_PROP_INT |
CD_MASK_PROP_STR | CD_MASK_SHAPEKEY | CD_MASK_SHAPE_KEYINDEX | CD_MASK_MDISPS |
CD_MASK_CREASE | CD_MASK_BWEIGHT | CD_MASK_RECAST | CD_MASK_PAINT_MASK |
CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
- CD_MASK_CUSTOMLOOPNORMAL;
+ CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_FACEMAP;
/**
* cover values copied by #BKE_mesh_loops_to_tessdata
*/
const CustomDataMask CD_MASK_FACECORNERS =
- CD_MASK_MTFACE | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV |
+ CD_MASK_MTFACE | CD_MASK_MLOOPUV |
CD_MASK_MCOL | CD_MASK_MLOOPCOL |
CD_MASK_PREVIEW_MCOL | CD_MASK_PREVIEW_MLOOPCOL |
CD_MASK_ORIGSPACE | CD_MASK_ORIGSPACE_MLOOP |
@@ -1368,7 +1358,7 @@ const CustomDataMask CD_MASK_FACECORNERS =
const CustomDataMask CD_MASK_EVERYTHING =
CD_MASK_MVERT | CD_MASK_MDEFORMVERT | CD_MASK_MEDGE | CD_MASK_MFACE |
CD_MASK_MTFACE | CD_MASK_MCOL | CD_MASK_ORIGINDEX | CD_MASK_NORMAL /* | CD_MASK_POLYINDEX */ | CD_MASK_PROP_FLT |
- CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV |
+ CD_MASK_PROP_INT | CD_MASK_PROP_STR | CD_MASK_ORIGSPACE | CD_MASK_ORCO | CD_MASK_MLOOPUV |
CD_MASK_MLOOPCOL | CD_MASK_TANGENT | CD_MASK_MDISPS | CD_MASK_PREVIEW_MCOL | CD_MASK_CLOTH_ORCO | CD_MASK_RECAST |
/* BMESH ONLY START */
CD_MASK_MPOLY | CD_MASK_MLOOP | CD_MASK_SHAPE_KEYINDEX | CD_MASK_SHAPEKEY | CD_MASK_BWEIGHT | CD_MASK_CREASE |
@@ -1376,7 +1366,7 @@ const CustomDataMask CD_MASK_EVERYTHING =
/* BMESH ONLY END */
CD_MASK_PAINT_MASK | CD_MASK_GRID_PAINT_MASK | CD_MASK_MVERT_SKIN |
CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE |
- CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_CUSTOMLOOPNORMAL;
+ CD_MASK_MLOOPTANGENT | CD_MASK_TESSLOOPNORMAL | CD_MASK_CUSTOMLOOPNORMAL | CD_MASK_FACEMAP;
static const LayerTypeInfo *layerType_getInfo(int type)
{
@@ -2501,13 +2491,10 @@ void CustomData_set(const CustomData *data, int index, int type, const void *sou
/* BMesh functions */
/* needed to convert to/from different face reps */
-void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *ldata,
- int totloop, int totpoly)
+void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *ldata, int totloop)
{
- int i;
- for (i = 0; i < fdata->totlayer; i++) {
+ for (int i = 0; i < fdata->totlayer; i++) {
if (fdata->layers[i].type == CD_MTFACE) {
- CustomData_add_layer_named(pdata, CD_MTEXPOLY, CD_CALLOC, NULL, totpoly, fdata->layers[i].name);
CustomData_add_layer_named(ldata, CD_MLOOPUV, CD_CALLOC, NULL, totloop, fdata->layers[i].name);
}
else if (fdata->layers[i].type == CD_MCOL) {
@@ -2522,19 +2509,18 @@ void CustomData_to_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *l
}
}
-void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData *ldata, int total)
+void CustomData_from_bmeshpoly(
+ CustomData *fdata, CustomData *ldata, int total)
{
int i;
/* avoid accumulating extra layers */
- BLI_assert(!CustomData_from_bmeshpoly_test(fdata, pdata, ldata, false));
+ BLI_assert(!CustomData_from_bmeshpoly_test(fdata, ldata, false));
- for (i = 0; i < pdata->totlayer; i++) {
- if (pdata->layers[i].type == CD_MTEXPOLY) {
- CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, pdata->layers[i].name);
- }
- }
for (i = 0; i < ldata->totlayer; i++) {
+ if (ldata->layers[i].type == CD_MLOOPUV) {
+ CustomData_add_layer_named(fdata, CD_MTFACE, CD_CALLOC, NULL, total, ldata->layers[i].name);
+ }
if (ldata->layers[i].type == CD_MLOOPCOL) {
CustomData_add_layer_named(fdata, CD_MCOL, CD_CALLOC, NULL, total, ldata->layers[i].name);
}
@@ -2552,7 +2538,7 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
}
}
- CustomData_bmesh_update_active_layers(fdata, pdata, ldata);
+ CustomData_bmesh_update_active_layers(fdata, ldata);
}
#ifndef NDEBUG
@@ -2562,13 +2548,13 @@ void CustomData_from_bmeshpoly(CustomData *fdata, CustomData *pdata, CustomData
* \param fallback: Use when there are no layers to handle,
* since callers may expect success or failure.
*/
-bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *pdata, CustomData *ldata, bool fallback)
+bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *ldata, bool fallback)
{
int a_num = 0, b_num = 0;
#define LAYER_CMP(l_a, t_a, l_b, t_b) \
((a_num += CustomData_number_of_layers(l_a, t_a)) == (b_num += CustomData_number_of_layers(l_b, t_b)))
- if (!LAYER_CMP(pdata, CD_MTEXPOLY, fdata, CD_MTFACE))
+ if (!LAYER_CMP(ldata, CD_MLOOPUV, fdata, CD_MTFACE))
return false;
if (!LAYER_CMP(ldata, CD_MLOOPCOL, fdata, CD_MCOL))
return false;
@@ -2590,25 +2576,21 @@ bool CustomData_from_bmeshpoly_test(CustomData *fdata, CustomData *pdata, Custom
#endif
-void CustomData_bmesh_update_active_layers(CustomData *fdata, CustomData *pdata, CustomData *ldata)
+void CustomData_bmesh_update_active_layers(CustomData *fdata, CustomData *ldata)
{
int act;
- if (CustomData_has_layer(pdata, CD_MTEXPOLY)) {
- act = CustomData_get_active_layer(pdata, CD_MTEXPOLY);
- CustomData_set_layer_active(ldata, CD_MLOOPUV, act);
+ if (CustomData_has_layer(ldata, CD_MLOOPUV)) {
+ act = CustomData_get_active_layer(ldata, CD_MLOOPUV);
CustomData_set_layer_active(fdata, CD_MTFACE, act);
- act = CustomData_get_render_layer(pdata, CD_MTEXPOLY);
- CustomData_set_layer_render(ldata, CD_MLOOPUV, act);
+ act = CustomData_get_render_layer(ldata, CD_MLOOPUV);
CustomData_set_layer_render(fdata, CD_MTFACE, act);
- act = CustomData_get_clone_layer(pdata, CD_MTEXPOLY);
- CustomData_set_layer_clone(ldata, CD_MLOOPUV, act);
+ act = CustomData_get_clone_layer(ldata, CD_MLOOPUV);
CustomData_set_layer_clone(fdata, CD_MTFACE, act);
- act = CustomData_get_stencil_layer(pdata, CD_MTEXPOLY);
- CustomData_set_layer_stencil(ldata, CD_MLOOPUV, act);
+ act = CustomData_get_stencil_layer(ldata, CD_MLOOPUV);
CustomData_set_layer_stencil(fdata, CD_MTFACE, act);
}
@@ -2632,25 +2614,21 @@ void CustomData_bmesh_update_active_layers(CustomData *fdata, CustomData *pdata,
* used by do_versions in readfile.c when creating pdata and ldata for pre-bmesh
* meshes and needed to preserve active/render/clone/stencil flags set in pre-bmesh files
*/
-void CustomData_bmesh_do_versions_update_active_layers(CustomData *fdata, CustomData *pdata, CustomData *ldata)
+void CustomData_bmesh_do_versions_update_active_layers(CustomData *fdata, CustomData *ldata)
{
int act;
if (CustomData_has_layer(fdata, CD_MTFACE)) {
act = CustomData_get_active_layer(fdata, CD_MTFACE);
- CustomData_set_layer_active(pdata, CD_MTEXPOLY, act);
CustomData_set_layer_active(ldata, CD_MLOOPUV, act);
act = CustomData_get_render_layer(fdata, CD_MTFACE);
- CustomData_set_layer_render(pdata, CD_MTEXPOLY, act);
CustomData_set_layer_render(ldata, CD_MLOOPUV, act);
act = CustomData_get_clone_layer(fdata, CD_MTFACE);
- CustomData_set_layer_clone(pdata, CD_MTEXPOLY, act);
CustomData_set_layer_clone(ldata, CD_MLOOPUV, act);
act = CustomData_get_stencil_layer(fdata, CD_MTFACE);
- CustomData_set_layer_stencil(pdata, CD_MTEXPOLY, act);
CustomData_set_layer_stencil(ldata, CD_MLOOPUV, act);
}
diff --git a/source/blender/blenkernel/intern/data_transfer.c b/source/blender/blenkernel/intern/data_transfer.c
index 38340575e74..0451031c5b8 100644
--- a/source/blender/blenkernel/intern/data_transfer.c
+++ b/source/blender/blenkernel/intern/data_transfer.c
@@ -79,7 +79,7 @@ CustomDataMask BKE_object_data_transfer_dttypes_to_cdmask(const int dtdata_types
cddata_mask |= CD_MASK_MDEFORMVERT; /* Exception for vgroups :/ */
}
else if (cddata_type == CD_FAKE_UV) {
- cddata_mask |= CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV;
+ cddata_mask |= CD_MASK_MLOOPUV;
}
else if (cddata_type == CD_FAKE_LNOR) {
cddata_mask |= CD_MASK_NORMAL | CD_MASK_CUSTOMLOOPNORMAL;
@@ -962,7 +962,7 @@ static bool data_transfer_layersmapping_generate(
}
else if (elem_type == ME_POLY) {
if (cddata_type == CD_FAKE_UV) {
- cddata_type = CD_MTEXPOLY;
+ cddata_type = CD_MLOOPUV;
}
if (!(cddata_type & CD_FAKE)) {
@@ -1010,7 +1010,8 @@ static bool data_transfer_layersmapping_generate(
* to get (as much as possible) exact copy of source data layout.
*/
void BKE_object_data_transfer_layout(
- Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, const bool use_delete,
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob_src, Object *ob_dst, const int data_types, const bool use_delete,
const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX])
{
DerivedMesh *dm_src;
@@ -1027,7 +1028,7 @@ void BKE_object_data_transfer_layout(
/* Get source DM.*/
dm_src_mask |= BKE_object_data_transfer_dttypes_to_cdmask(data_types);
- dm_src = mesh_get_derived_final(scene, ob_src, dm_src_mask);
+ dm_src = mesh_get_derived_final(depsgraph, scene, ob_src, dm_src_mask);
if (!dm_src) {
return;
}
@@ -1085,9 +1086,9 @@ void BKE_object_data_transfer_layout(
}
bool BKE_object_data_transfer_dm(
- Scene *scene, Object *ob_src, Object *ob_dst, DerivedMesh *dm_dst, const int data_types, bool use_create,
- const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode,
- SpaceTransform *space_transform, const bool auto_transform,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, DerivedMesh *dm_dst,
+ const int data_types, bool use_create, const int map_vert_mode, const int map_edge_mode,
+ const int map_loop_mode, const int map_poly_mode, SpaceTransform *space_transform, const bool auto_transform,
const float max_distance, const float ray_radius, const float islands_handling_precision,
const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX],
const int mix_mode, const float mix_factor, const char *vgroup_name, const bool invert_vgroup,
@@ -1149,7 +1150,7 @@ bool BKE_object_data_transfer_dm(
* Also, we need to make a local copy of dm_src, otherwise we may end with concurrent creation
* of data in it (multi-threaded evaluation of the modifier stack, see T46672).
*/
- dm_src = dm_dst ? ob_src->derivedFinal : mesh_get_derived_final(scene, ob_src, dm_src_mask);
+ dm_src = dm_dst ? ob_src->derivedFinal : mesh_get_derived_final(depsgraph, scene, ob_src, dm_src_mask);
if (!dm_src) {
return changed;
}
@@ -1457,16 +1458,16 @@ bool BKE_object_data_transfer_dm(
}
bool BKE_object_data_transfer_mesh(
- Scene *scene, Object *ob_src, Object *ob_dst, const int data_types, const bool use_create,
- const int map_vert_mode, const int map_edge_mode, const int map_loop_mode, const int map_poly_mode,
- SpaceTransform *space_transform, const bool auto_transform,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, Object *ob_dst, const int data_types,
+ const bool use_create, const int map_vert_mode, const int map_edge_mode, const int map_loop_mode,
+ const int map_poly_mode, SpaceTransform *space_transform, const bool auto_transform,
const float max_distance, const float ray_radius, const float islands_handling_precision,
const int fromlayers_select[DT_MULTILAYER_INDEX_MAX], const int tolayers_select[DT_MULTILAYER_INDEX_MAX],
const int mix_mode, const float mix_factor, const char *vgroup_name, const bool invert_vgroup,
ReportList *reports)
{
return BKE_object_data_transfer_dm(
- scene, ob_src, ob_dst, NULL, data_types, use_create,
+ depsgraph, scene, ob_src, ob_dst, NULL, data_types, use_create,
map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode,
space_transform, auto_transform,
max_distance, ray_radius, islands_handling_precision,
diff --git a/source/blender/blenkernel/intern/deform.c b/source/blender/blenkernel/intern/deform.c
index 22ff8bf4bb7..d4ff9bd5c0c 100644
--- a/source/blender/blenkernel/intern/deform.c
+++ b/source/blender/blenkernel/intern/deform.c
@@ -54,6 +54,7 @@
#include "BKE_customdata.h"
#include "BKE_data_transfer.h"
#include "BKE_deform.h" /* own include */
+#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_object_deform.h"
@@ -73,6 +74,8 @@ bDeformGroup *BKE_defgroup_new(Object *ob, const char *name)
BLI_addtail(&ob->defbase, defgroup);
defgroup_unique_name(defgroup, ob);
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
+
return defgroup;
}
diff --git a/source/blender/blenkernel/intern/depsgraph.c b/source/blender/blenkernel/intern/depsgraph.c
deleted file mode 100644
index c29dc6c9311..00000000000
--- a/source/blender/blenkernel/intern/depsgraph.c
+++ /dev/null
@@ -1,3745 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2004 Blender Foundation.
- * All rights reserved.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenkernel/intern/depsgraph.c
- * \ingroup bke
- */
-
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#ifdef WIN32
-# include "BLI_winstuff.h"
-#endif
-
-#include "BLI_utildefines.h"
-#include "BLI_listbase.h"
-#include "BLI_ghash.h"
-#include "BLI_threads.h"
-
-#include "DNA_anim_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_cachefile_types.h"
-#include "DNA_group_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_lattice_types.h"
-#include "DNA_key_types.h"
-#include "DNA_material_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_node_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_windowmanager_types.h"
-#include "DNA_movieclip_types.h"
-#include "DNA_mask_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_rigidbody_types.h"
-
-#include "BKE_anim.h"
-#include "BKE_animsys.h"
-#include "BKE_action.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_collision.h"
-#include "BKE_curve.h"
-#include "BKE_effect.h"
-#include "BKE_fcurve.h"
-#include "BKE_global.h"
-#include "BKE_idcode.h"
-#include "BKE_image.h"
-#include "BKE_key.h"
-#include "BKE_library.h"
-#include "BKE_main.h"
-#include "BKE_node.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_pointcache.h"
-#include "BKE_scene.h"
-#include "BKE_screen.h"
-#include "BKE_tracking.h"
-
-#include "GPU_buffers.h"
-
-#include "atomic_ops.h"
-
-#include "depsgraph_private.h"
-
-#include "DEG_depsgraph.h"
-#include "DEG_depsgraph_build.h"
-#include "DEG_depsgraph_debug.h"
-#include "DEG_depsgraph_query.h"
-
-#ifdef WITH_LEGACY_DEPSGRAPH
-
-static SpinLock threaded_update_lock;
-
-void DAG_init(void)
-{
- BLI_spin_init(&threaded_update_lock);
- DEG_register_node_types();
-}
-
-void DAG_exit(void)
-{
- BLI_spin_end(&threaded_update_lock);
- DEG_free_node_types();
-}
-
-/* Queue and stack operations for dag traversal
- *
- * the queue store a list of freenodes to avoid successive alloc/dealloc
- */
-
-DagNodeQueue *queue_create(int slots)
-{
- DagNodeQueue *queue;
- DagNodeQueueElem *elem;
- int i;
-
- queue = MEM_mallocN(sizeof(DagNodeQueue), "DAG queue");
- queue->freenodes = MEM_mallocN(sizeof(DagNodeQueue), "DAG queue");
- queue->count = 0;
- queue->maxlevel = 0;
- queue->first = queue->last = NULL;
- elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem3");
- elem->node = NULL;
- elem->next = NULL;
- queue->freenodes->first = queue->freenodes->last = elem;
-
- for (i = 1; i < slots; i++) {
- elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem4");
- elem->node = NULL;
- elem->next = NULL;
- queue->freenodes->last->next = elem;
- queue->freenodes->last = elem;
- }
- queue->freenodes->count = slots;
- return queue;
-}
-
-void queue_raz(DagNodeQueue *queue)
-{
- DagNodeQueueElem *elem;
-
- elem = queue->first;
- if (queue->freenodes->last)
- queue->freenodes->last->next = elem;
- else
- queue->freenodes->first = queue->freenodes->last = elem;
-
- elem->node = NULL;
- queue->freenodes->count++;
- while (elem->next) {
- elem = elem->next;
- elem->node = NULL;
- queue->freenodes->count++;
- }
- queue->freenodes->last = elem;
- queue->count = 0;
-}
-
-void queue_delete(DagNodeQueue *queue)
-{
- DagNodeQueueElem *elem;
- DagNodeQueueElem *temp;
-
- elem = queue->first;
- while (elem) {
- temp = elem;
- elem = elem->next;
- MEM_freeN(temp);
- }
-
- elem = queue->freenodes->first;
- while (elem) {
- temp = elem;
- elem = elem->next;
- MEM_freeN(temp);
- }
-
- MEM_freeN(queue->freenodes);
- MEM_freeN(queue);
-}
-
-/* insert in queue, remove in front */
-void push_queue(DagNodeQueue *queue, DagNode *node)
-{
- DagNodeQueueElem *elem;
- int i;
-
- if (node == NULL) {
- fprintf(stderr, "pushing null node\n");
- return;
- }
- /*fprintf(stderr, "BFS push : %s %d\n", ((ID *) node->ob)->name, queue->count);*/
-
- elem = queue->freenodes->first;
- if (elem != NULL) {
- queue->freenodes->first = elem->next;
- if (queue->freenodes->last == elem) {
- queue->freenodes->last = NULL;
- queue->freenodes->first = NULL;
- }
- queue->freenodes->count--;
- }
- else { /* alllocating more */
- elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem1");
- elem->node = NULL;
- elem->next = NULL;
- queue->freenodes->first = queue->freenodes->last = elem;
-
- for (i = 1; i < DAGQUEUEALLOC; i++) {
- elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2");
- elem->node = NULL;
- elem->next = NULL;
- queue->freenodes->last->next = elem;
- queue->freenodes->last = elem;
- }
- queue->freenodes->count = DAGQUEUEALLOC;
-
- elem = queue->freenodes->first;
- queue->freenodes->first = elem->next;
- }
- elem->next = NULL;
- elem->node = node;
- if (queue->last != NULL)
- queue->last->next = elem;
- queue->last = elem;
- if (queue->first == NULL) {
- queue->first = elem;
- }
- queue->count++;
-}
-
-
-/* insert in front, remove in front */
-void push_stack(DagNodeQueue *queue, DagNode *node)
-{
- DagNodeQueueElem *elem;
- int i;
-
- elem = queue->freenodes->first;
- if (elem != NULL) {
- queue->freenodes->first = elem->next;
- if (queue->freenodes->last == elem) {
- queue->freenodes->last = NULL;
- queue->freenodes->first = NULL;
- }
- queue->freenodes->count--;
- }
- else { /* alllocating more */
- elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem1");
- elem->node = NULL;
- elem->next = NULL;
- queue->freenodes->first = queue->freenodes->last = elem;
-
- for (i = 1; i < DAGQUEUEALLOC; i++) {
- elem = MEM_mallocN(sizeof(DagNodeQueueElem), "DAG queue elem2");
- elem->node = NULL;
- elem->next = NULL;
- queue->freenodes->last->next = elem;
- queue->freenodes->last = elem;
- }
- queue->freenodes->count = DAGQUEUEALLOC;
-
- elem = queue->freenodes->first;
- queue->freenodes->first = elem->next;
- }
- elem->next = queue->first;
- elem->node = node;
- queue->first = elem;
- if (queue->last == NULL)
- queue->last = elem;
- queue->count++;
-}
-
-
-DagNode *pop_queue(DagNodeQueue *queue)
-{
- DagNodeQueueElem *elem;
- DagNode *node;
-
- elem = queue->first;
- if (elem) {
- queue->first = elem->next;
- if (queue->last == elem) {
- queue->last = NULL;
- queue->first = NULL;
- }
- queue->count--;
- if (queue->freenodes->last)
- queue->freenodes->last->next = elem;
- queue->freenodes->last = elem;
- if (queue->freenodes->first == NULL)
- queue->freenodes->first = elem;
- node = elem->node;
- elem->node = NULL;
- elem->next = NULL;
- queue->freenodes->count++;
- return node;
- }
- else {
- fprintf(stderr, "return null\n");
- return NULL;
- }
-}
-
-DagNode *get_top_node_queue(DagNodeQueue *queue)
-{
- return queue->first->node;
-}
-
-DagForest *dag_init(void)
-{
- DagForest *forest;
- /* use callocN to init all zero */
- forest = MEM_callocN(sizeof(DagForest), "DAG root");
- forest->ugly_hack_sorry = true;
- return forest;
-}
-
-/* isdata = object data... */
-/* XXX this needs to be extended to be more flexible (so that not only objects are evaluated via depsgraph)... */
-static void dag_add_driver_relation(AnimData *adt, DagForest *dag, DagNode *node, int isdata)
-{
- FCurve *fcu;
- DagNode *node1;
-
- for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
- ChannelDriver *driver = fcu->driver;
- DriverVar *dvar;
- int isdata_fcu = (isdata) || (fcu->rna_path && strstr(fcu->rna_path, "modifiers["));
-
- /* loop over variables to get the target relationships */
- for (dvar = driver->variables.first; dvar; dvar = dvar->next) {
- /* only used targets */
- DRIVER_TARGETS_USED_LOOPER(dvar)
- {
- if (dtar->id) {
- /* FIXME: other data types need to be added here so that they can work! */
- if (GS(dtar->id->name) == ID_OB) {
- Object *ob = (Object *)dtar->id;
-
- /* normal channel-drives-channel */
- node1 = dag_get_node(dag, dtar->id);
-
- /* check if bone... */
- if ((ob->type == OB_ARMATURE) &&
- ( ((dtar->rna_path) && strstr(dtar->rna_path, "pose.bones[")) ||
- ((dtar->flag & DTAR_FLAG_STRUCT_REF) && (dtar->pchan_name[0])) ))
- {
- dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver");
- }
- /* check if ob data */
- else if (dtar->rna_path && strstr(dtar->rna_path, "data."))
- dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_DATA_DATA : DAG_RL_DATA_OB, "Driver");
- /* normal */
- else
- dag_add_relation(dag, node1, node, isdata_fcu ? DAG_RL_OB_DATA : DAG_RL_OB_OB, "Driver");
- }
- }
- }
- DRIVER_TARGETS_LOOPER_END
- }
- }
-}
-
-/* XXX: forward def for material driver handling... */
-static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma);
-
-/* recursive handling for shader nodetree drivers */
-static void dag_add_shader_nodetree_driver_relations(DagForest *dag, DagNode *node, bNodeTree *ntree)
-{
- bNode *n;
-
- /* nodetree itself */
- if (ntree->adt) {
- dag_add_driver_relation(ntree->adt, dag, node, 1);
- }
-
- /* nodetree's nodes... */
- for (n = ntree->nodes.first; n; n = n->next) {
- if (n->id) {
- if (GS(n->id->name) == ID_MA) {
- dag_add_material_driver_relations(dag, node, (Material *)n->id);
- }
- else if (n->type == NODE_GROUP) {
- dag_add_shader_nodetree_driver_relations(dag, node, (bNodeTree *)n->id);
- }
- }
- }
-}
-
-/* recursive handling for material drivers */
-static void dag_add_material_driver_relations(DagForest *dag, DagNode *node, Material *ma)
-{
- /* Prevent infinite recursion by checking (and tagging the material) as having been visited
- * already (see build_dag()). This assumes ma->id.tag & LIB_TAG_DOIT isn't set by anything else
- * in the meantime... [#32017]
- */
- if (ma->id.tag & LIB_TAG_DOIT)
- return;
-
- ma->id.tag |= LIB_TAG_DOIT;
-
- /* material itself */
- if (ma->adt)
- dag_add_driver_relation(ma->adt, dag, node, 1);
-
- /* textures */
- // TODO...
- //dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
-
- /* material's nodetree */
- if (ma->nodetree)
- dag_add_shader_nodetree_driver_relations(dag, node, ma->nodetree);
-
- ma->id.tag &= ~LIB_TAG_DOIT;
-}
-
-/* recursive handling for lamp drivers */
-static void dag_add_lamp_driver_relations(DagForest *dag, DagNode *node, Lamp *la)
-{
- /* Prevent infinite recursion by checking (and tagging the lamp) as having been visited
- * already (see build_dag()). This assumes la->id.tag & LIB_TAG_DOIT isn't set by anything else
- * in the meantime... [#32017]
- */
- if (la->id.tag & LIB_TAG_DOIT)
- return;
-
- la->id.tag |= LIB_TAG_DOIT;
-
- /* lamp itself */
- if (la->adt)
- dag_add_driver_relation(la->adt, dag, node, 1);
-
- /* textures */
- // TODO...
- //dag_add_texture_driver_relations(DagForest *dag, DagNode *node, ID *id);
-
- /* lamp's nodetree */
- if (la->nodetree)
- dag_add_shader_nodetree_driver_relations(dag, node, la->nodetree);
-
- la->id.tag &= ~LIB_TAG_DOIT;
-}
-
-static void create_collision_relation(DagForest *dag, DagNode *node, Object *ob1, const char *name)
-{
- DagNode *node2 = dag_get_node(dag, ob1);
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, name);
-}
-
-void dag_add_collision_relations(DagForest *dag, Scene *scene, Object *ob, DagNode *node, Group *group, int layer, unsigned int modifier_type, DagCollobjFilterFunction fn, bool dupli, const char *name)
-{
- unsigned int numcollobj;
- Object **collobjs = get_collisionobjects_ext(scene, ob, group, layer, &numcollobj, modifier_type, dupli);
-
- for (unsigned int i = 0; i < numcollobj; i++) {
- Object *ob1 = collobjs[i];
-
- if (!fn || fn(ob1, modifiers_findByType(ob1, modifier_type))) {
- create_collision_relation(dag, node, ob1, name);
- }
- }
-
- if (collobjs)
- MEM_freeN(collobjs);
-}
-
-void dag_add_forcefield_relations(DagForest *dag, Scene *scene, Object *ob, DagNode *node, EffectorWeights *effector_weights, bool add_absorption, int skip_forcefield, const char *name)
-{
- ListBase *effectors = pdInitEffectors(scene, ob, NULL, effector_weights, false);
-
- if (effectors) {
- for (EffectorCache *eff = effectors->first; eff; eff = eff->next) {
- if (eff->ob != ob && eff->pd->forcefield != skip_forcefield) {
- create_collision_relation(dag, node, eff->ob, name);
-
- if (eff->pd->forcefield == PFIELD_SMOKEFLOW && eff->pd->f_source) {
- create_collision_relation(dag, node, eff->pd->f_source, "Smoke Force Domain");
- }
-
- if (add_absorption && (eff->pd->flag & PFIELD_VISIBILITY)) {
- /* Actual code uses get_collider_cache */
- dag_add_collision_relations(dag, scene, ob, node, NULL, eff->ob->lay, eModifierType_Collision, NULL, true, "Force Absorption");
- }
- }
- }
- }
-
- pdEndEffectors(&effectors);
-}
-
-static bool build_deg_tracking_constraints(DagForest *dag,
- Scene *scene,
- DagNode *scenenode,
- bConstraint *con,
- const bConstraintTypeInfo *cti,
- DagNode *node,
- bool is_data)
-{
- if (!ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK,
- CONSTRAINT_TYPE_CAMERASOLVER,
- CONSTRAINT_TYPE_OBJECTSOLVER))
- {
- return false;
- }
- bool depends_on_camera = false;
- if (cti->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
- bFollowTrackConstraint *data = (bFollowTrackConstraint *)con->data;
- if ((data->clip || data->flag & FOLLOWTRACK_ACTIVECLIP) && data->track[0]) {
- depends_on_camera = true;
- }
- if (data->depth_ob != NULL) {
- DagNode *node2 = dag_get_node(dag, data->depth_ob);
- dag_add_relation(dag,
- node2, node,
- (is_data) ? (DAG_RL_DATA_DATA | DAG_RL_OB_DATA)
- : (DAG_RL_DATA_OB | DAG_RL_OB_OB),
- cti->name);
- }
- }
- else if (cti->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
- depends_on_camera = true;
- }
- if (depends_on_camera && scene->camera != NULL) {
- DagNode *node2 = dag_get_node(dag, scene->camera);
- dag_add_relation(dag,
- node2, node,
- (is_data) ? (DAG_RL_DATA_DATA | DAG_RL_OB_DATA)
- : (DAG_RL_DATA_OB | DAG_RL_OB_OB),
- cti->name);
- }
- dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
- return true;
-}
-
-static void build_dag_object(DagForest *dag, DagNode *scenenode, Scene *scene, Object *ob, int mask)
-{
- bConstraint *con;
- DagNode *node;
- DagNode *node2;
- DagNode *node3;
- Key *key;
- ParticleSystem *psys;
- int addtoroot = 1;
-
- node = dag_get_node(dag, ob);
-
- if ((ob->data) && (mask & DAG_RL_DATA)) {
- node2 = dag_get_node(dag, ob->data);
- dag_add_relation(dag, node, node2, DAG_RL_DATA, "Object-Data Relation");
- node2->first_ancestor = ob;
- node2->ancestor_count += 1;
- }
-
- /* also build a custom data mask for dependencies that need certain layers */
-
- if (ob->type == OB_ARMATURE) {
- if (ob->pose) {
- bPoseChannel *pchan;
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- for (con = pchan->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
- bConstraintTarget *ct;
-
- if (!cti) {
- continue;
- }
-
- if (build_deg_tracking_constraints(dag, scene, scenenode, con, cti, node, true)) {
- /* pass */
- }
- else if (cti->get_constraint_targets) {
- cti->get_constraint_targets(con, &targets);
-
- for (ct = targets.first; ct; ct = ct->next) {
- if (ct->tar && ct->tar != ob) {
- // fprintf(stderr, "armature %s target :%s\n", ob->id.name, target->id.name);
- node3 = dag_get_node(dag, ct->tar);
-
- if (ct->subtarget[0]) {
- dag_add_relation(dag, node3, node, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, cti->name);
- if (ct->tar->type == OB_MESH)
- node3->customdata_mask |= CD_MASK_MDEFORMVERT;
- }
- else if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH,
- CONSTRAINT_TYPE_CLAMPTO,
- CONSTRAINT_TYPE_SPLINEIK,
- CONSTRAINT_TYPE_SHRINKWRAP))
- {
- dag_add_relation(dag, node3, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, cti->name);
- }
- else {
- dag_add_relation(dag, node3, node, DAG_RL_OB_DATA, cti->name);
- }
- }
- }
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 1);
- }
-
- }
- }
- }
- }
-
- /* driver dependencies, nla modifiers */
-#if 0 // XXX old animation system
- if (ob->nlastrips.first) {
- bActionStrip *strip;
- bActionChannel *chan;
- for (strip = ob->nlastrips.first; strip; strip = strip->next) {
- if (strip->modifiers.first) {
- bActionModifier *amod;
- for (amod = strip->modifiers.first; amod; amod = amod->next) {
- if (amod->ob) {
- node2 = dag_get_node(dag, amod->ob);
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "NLA Strip Modifier");
- }
- }
- }
- }
- }
-#endif // XXX old animation system
- if (ob->adt)
- dag_add_driver_relation(ob->adt, dag, node, (ob->type == OB_ARMATURE)); // XXX isdata arg here doesn't give an accurate picture of situation
-
- key = BKE_key_from_object(ob);
- if (key && key->adt)
- dag_add_driver_relation(key->adt, dag, node, 1);
-
- if (ob->modifiers.first) {
- ModifierData *md;
- ModifierUpdateDepsgraphContext ctx = {
- .scene = scene,
- .object = ob,
-
- .forest = dag,
- .obNode = node,
- };
- for (md = ob->modifiers.first; md; md = md->next) {
- const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
-
- if (mti->updateDepgraph) mti->updateDepgraph(md, &ctx);
- }
- }
- if (ob->parent) {
- node2 = dag_get_node(dag, ob->parent);
-
- switch (ob->partype) {
- case PARSKEL:
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Parent");
- break;
- case PARVERT1: case PARVERT3:
- dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Vertex Parent");
- node2->customdata_mask |= CD_MASK_ORIGINDEX;
- break;
- case PARBONE:
- dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Bone Parent");
- break;
- default:
- if (ob->parent->type == OB_LATTICE)
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Lattice Parent");
- else if (ob->parent->type == OB_CURVE) {
- Curve *cu = ob->parent->data;
- if (cu->flag & CU_PATH)
- dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, "Curve Parent");
- else
- dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Curve Parent");
- }
- else
- dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Parent");
- break;
- }
- /* exception case: parent is duplivert */
- if (ob->type == OB_MBALL && (ob->parent->transflag & OB_DUPLIVERTS)) {
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Duplivert");
- }
-
- addtoroot = 0;
- }
- if (ob->proxy) {
- node2 = dag_get_node(dag, ob->proxy);
- dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_OB, "Proxy");
- /* inverted relation, so addtoroot shouldn't be set to zero */
- }
-
- if (ob->transflag & OB_DUPLI) {
- if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) {
- GroupObject *go;
- for (go = ob->dup_group->gobject.first; go; go = go->next) {
- if (go->ob) {
- node2 = dag_get_node(dag, go->ob);
- /* node2 changes node1, this keeps animations updated in groups?? not logical? */
- dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Dupligroup");
- }
- }
- }
- }
-
- /* rigidbody force fields */
- if ((ob->type == OB_MESH) || (ob->type == OB_CURVE) || (ob->type == OB_LATTICE)) {
- if (ob->rigidbody_object && scene->rigidbody_world) {
- dag_add_forcefield_relations(dag, scene, ob, node, scene->rigidbody_world->effector_weights, true, 0, "Force Field");
- }
- }
-
- /* object data drivers */
- if (ob->data) {
- AnimData *adt = BKE_animdata_from_id((ID *)ob->data);
- if (adt)
- dag_add_driver_relation(adt, dag, node, 1);
- }
-
- /* object type/data relationships */
- switch (ob->type) {
- case OB_CAMERA:
- {
- Camera *cam = (Camera *)ob->data;
-
- if (cam->dof_ob) {
- node2 = dag_get_node(dag, cam->dof_ob);
- dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Camera DoF");
- }
- break;
- }
- case OB_MBALL:
- {
- Object *mom = BKE_mball_basis_find(scene, ob);
-
- if (mom != ob) {
- node2 = dag_get_node(dag, mom);
- dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Metaball"); /* mom depends on children! */
- }
- break;
- }
- case OB_CURVE:
- case OB_FONT:
- {
- Curve *cu = ob->data;
-
- if (cu->bevobj) {
- node2 = dag_get_node(dag, cu->bevobj);
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Bevel");
- }
- if (cu->taperobj) {
- node2 = dag_get_node(dag, cu->taperobj);
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Taper");
- }
- if (ob->type == OB_FONT) {
- /* Really rather dirty hack. needs to support font family to work
- * reliably on render export.
- *
- * This totally mimics behavior of regular verts duplication with
- * parenting. The only tricky thing here is to get list of objects
- * used for the custom "font".
- *
- * This shouldn't harm so much because this code only runs on DAG
- * rebuild and this feature is not that commonly used.
- *
- * - sergey -
- */
- if (cu->family[0] != '\n') {
- ListBase *duplilist;
- DupliObject *dob;
- duplilist = object_duplilist(G.main->eval_ctx, scene, ob);
- for (dob = duplilist->first; dob; dob = dob->next) {
- node2 = dag_get_node(dag, dob->ob);
- dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Object Font");
- }
- free_object_duplilist(duplilist);
- }
-
- if (cu->textoncurve) {
- node2 = dag_get_node(dag, cu->textoncurve);
- /* Text on curve requires path to be evaluated for the target curve. */
- node2->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Texture On Curve");
- }
- }
- break;
- }
- }
-
- /* material drivers */
- if (ob->totcol) {
- int a;
-
- for (a = 1; a <= ob->totcol; a++) {
- Material *ma = give_current_material(ob, a);
-
- if (ma) {
- /* recursively figure out if there are drivers, and hook these up to this object */
- dag_add_material_driver_relations(dag, node, ma);
- }
- }
- }
- else if (ob->type == OB_LAMP) {
- dag_add_lamp_driver_relations(dag, node, ob->data);
- }
-
- /* particles */
- psys = ob->particlesystem.first;
- if (psys) {
- GroupObject *go;
-
- for (; psys; psys = psys->next) {
- BoidRule *rule = NULL;
- BoidState *state = NULL;
- ParticleSettings *part = psys->part;
-
- if (part->adt) {
- dag_add_driver_relation(part->adt, dag, node, 1);
- }
-
- dag_add_relation(dag, node, node, DAG_RL_OB_DATA, "Particle-Object Relation");
-
- if (!psys_check_enabled(ob, psys, G.is_rendering))
- continue;
-
- if (ELEM(part->phystype, PART_PHYS_KEYED, PART_PHYS_BOIDS)) {
- ParticleTarget *pt = psys->targets.first;
-
- for (; pt; pt = pt->next) {
- if (pt->ob && BLI_findlink(&pt->ob->particlesystem, pt->psys - 1)) {
- node2 = dag_get_node(dag, pt->ob);
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Particle Targets");
- }
- }
- }
-
- if (part->ren_as == PART_DRAW_OB && part->dup_ob) {
- node2 = dag_get_node(dag, part->dup_ob);
- /* note that this relation actually runs in the wrong direction, the problem
- * is that dupli system all have this (due to parenting), and the render
- * engine instancing assumes particular ordering of objects in list */
- dag_add_relation(dag, node, node2, DAG_RL_OB_OB, "Particle Object Visualization");
- if (part->dup_ob->type == OB_MBALL)
- dag_add_relation(dag, node, node2, DAG_RL_DATA_DATA, "Particle Object Visualization");
- }
-
- if (part->ren_as == PART_DRAW_GR && part->dup_group) {
- for (go = part->dup_group->gobject.first; go; go = go->next) {
- node2 = dag_get_node(dag, go->ob);
- dag_add_relation(dag, node2, node, DAG_RL_OB_OB, "Particle Group Visualization");
- }
- }
-
- if (part->type != PART_HAIR) {
- /* Actual code uses get_collider_cache */
- dag_add_collision_relations(dag, scene, ob, node, part->collision_group, ob->lay, eModifierType_Collision, NULL, true, "Particle Collision");
- }
- else if ((psys->flag & PSYS_HAIR_DYNAMICS) && psys->clmd && psys->clmd->coll_parms) {
- /* Hair uses cloth simulation, i.e. get_collision_objects */
- dag_add_collision_relations(dag, scene, ob, node, psys->clmd->coll_parms->group, ob->lay | scene->lay, eModifierType_Collision, NULL, true, "Hair Collision");
- }
-
- dag_add_forcefield_relations(dag, scene, ob, node, part->effector_weights, part->type == PART_HAIR, 0, "Particle Force Field");
-
- if (part->boids) {
- for (state = part->boids->states.first; state; state = state->next) {
- for (rule = state->rules.first; rule; rule = rule->next) {
- Object *ruleob = NULL;
- if (rule->type == eBoidRuleType_Avoid)
- ruleob = ((BoidRuleGoalAvoid *)rule)->ob;
- else if (rule->type == eBoidRuleType_FollowLeader)
- ruleob = ((BoidRuleFollowLeader *)rule)->ob;
-
- if (ruleob) {
- node2 = dag_get_node(dag, ruleob);
- dag_add_relation(dag, node2, node, DAG_RL_OB_DATA, "Boid Rule");
- }
- }
- }
- }
- }
- }
-
- /* object constraints */
- for (con = ob->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
- bConstraintTarget *ct;
-
- if (!cti)
- continue;
-
- /* special case for camera tracking -- it doesn't use targets to define relations */
- if (build_deg_tracking_constraints(dag, scene, scenenode, con, cti, node, false)) {
- addtoroot = 0;
- }
- else if (cti->get_constraint_targets) {
- cti->get_constraint_targets(con, &targets);
-
- for (ct = targets.first; ct; ct = ct->next) {
- Object *obt;
-
- if (ct->tar)
- obt = ct->tar;
- else
- continue;
-
- node2 = dag_get_node(dag, obt);
- if (ELEM(con->type, CONSTRAINT_TYPE_FOLLOWPATH, CONSTRAINT_TYPE_CLAMPTO))
- dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
- else {
- if (ELEM(obt->type, OB_ARMATURE, OB_MESH, OB_LATTICE) && (ct->subtarget[0])) {
- dag_add_relation(dag, node2, node, DAG_RL_DATA_OB | DAG_RL_OB_OB, cti->name);
- if (obt->type == OB_MESH)
- node2->customdata_mask |= CD_MASK_MDEFORMVERT;
- }
- else if (cti->type == CONSTRAINT_TYPE_SHRINKWRAP) {
- dag_add_relation(dag, node2, node, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, cti->name);
- }
- else {
- dag_add_relation(dag, node2, node, DAG_RL_OB_OB, cti->name);
- }
- }
- addtoroot = 0;
- }
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 1);
- }
- }
-
- if (addtoroot == 1)
- dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
-}
-
-static void build_dag_group(DagForest *dag, DagNode *scenenode, Main *bmain, Scene *scene, Group *group, short mask)
-{
- GroupObject *go;
-
- if (group->id.tag & LIB_TAG_DOIT)
- return;
-
- group->id.tag |= LIB_TAG_DOIT;
-
- for (go = group->gobject.first; go; go = go->next) {
- build_dag_object(dag, scenenode, scene, go->ob, mask);
- if (go->ob->dup_group)
- build_dag_group(dag, scenenode, bmain, scene, go->ob->dup_group, mask);
- }
-}
-
-DagForest *build_dag(Main *bmain, Scene *sce, short mask)
-{
- Base *base;
- Object *ob;
- DagNode *node;
- DagNode *scenenode;
- DagForest *dag;
- DagAdjList *itA;
-
- dag = sce->theDag;
- if (dag)
- free_forest(dag);
- else {
- dag = dag_init();
- sce->theDag = dag;
- }
- dag->need_update = false;
-
- BKE_main_id_tag_idcode(bmain, ID_OB, LIB_TAG_DOIT, false);
-
- /* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later [#32017] */
- BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
- BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
- BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
-
- /* add base node for scene. scene is always the first node in DAG */
- scenenode = dag_add_node(dag, sce);
-
- /* add current scene objects */
- for (base = sce->base.first; base; base = base->next) {
- ob = base->object;
- ob->id.tag |= LIB_TAG_DOIT;
- build_dag_object(dag, scenenode, sce, ob, mask);
- if (ob->proxy)
- build_dag_object(dag, scenenode, sce, ob->proxy, mask);
- if (ob->dup_group)
- build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
- }
-
- /* There might be situations when object from current scene depends on
- * objects form other scene AND objects from other scene has own
- * dependencies on objects from other scene.
- *
- * This is really important to include such indirect dependencies in order
- * to keep threaded update safe but since we don't really know if object is
- * coming from current scene or another scene we do rather stupid tag-based
- * check here: all the objects for which build_dag_object() was called are
- * getting tagged with LIB_TAG_DOIT. This way if some node has untagged
- * object we know it's an object from other scene.
- *
- * It should be enough to to it once, because if there's longer chain of
- * indirect dependencies, all the new nodes will be added to the end of the
- * list, meaning we'll keep covering them in this for loop.
- */
- for (node = sce->theDag->DagNode.first; node != NULL; node = node->next) {
- if (node->type == ID_OB) {
- ob = node->ob;
- if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
- ob->id.tag |= LIB_TAG_DOIT;
- build_dag_object(dag, scenenode, sce, ob, mask);
- if (ob->proxy)
- build_dag_object(dag, scenenode, sce, ob->proxy, mask);
- if (ob->dup_group)
- build_dag_group(dag, scenenode, bmain, sce, ob->dup_group, mask);
- }
- }
- }
-
- BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
-
- /* Now all relations were built, but we need to solve 1 exceptional case;
- * When objects have multiple "parents" (for example parent + constraint working on same object)
- * the relation type has to be synced. One of the parents can change, and should give same event to child */
-
- /* nodes were callocced, so we can use node->color for temporal storage */
- for (node = sce->theDag->DagNode.first; node; node = node->next) {
- if (node->type == ID_OB) {
- for (itA = node->child; itA; itA = itA->next) {
- if (itA->node->type == ID_OB) {
- itA->node->color |= itA->type;
- }
- }
-
- /* also flush custom data mask */
- ((Object *)node->ob)->customdata_mask = node->customdata_mask;
-
- if (node->parent == NULL) {
- dag_add_relation(dag, scenenode, node, DAG_RL_SCENE, "Scene Relation");
- }
- }
- }
- /* now set relations equal, so that when only one parent changes, the correct recalcs are found */
- for (node = sce->theDag->DagNode.first; node; node = node->next) {
- if (node->type == ID_OB) {
- for (itA = node->child; itA; itA = itA->next) {
- if (itA->node->type == ID_OB) {
- itA->type |= itA->node->color;
- }
- }
- }
- }
-
- /* cycle detection and solving */
- // solve_cycles(dag);
-
- return dag;
-}
-
-
-void free_forest(DagForest *Dag)
-{ /* remove all nodes and deps */
- DagNode *tempN;
- DagAdjList *tempA;
- DagAdjList *itA;
- DagNode *itN = Dag->DagNode.first;
-
- while (itN) {
- itA = itN->child;
- while (itA) {
- tempA = itA;
- itA = itA->next;
- MEM_freeN(tempA);
- }
-
- itA = itN->parent;
- while (itA) {
- tempA = itA;
- itA = itA->next;
- MEM_freeN(tempA);
- }
-
- tempN = itN;
- itN = itN->next;
- MEM_freeN(tempN);
- }
-
- BLI_ghash_free(Dag->nodeHash, NULL, NULL);
- Dag->nodeHash = NULL;
- Dag->DagNode.first = NULL;
- Dag->DagNode.last = NULL;
- Dag->numNodes = 0;
-
-}
-
-DagNode *dag_find_node(DagForest *forest, void *fob)
-{
- if (forest->nodeHash)
- return BLI_ghash_lookup(forest->nodeHash, fob);
-
- return NULL;
-}
-
-static int dag_print_dependencies = 0; /* debugging */
-
-/* no checking of existence, use dag_find_node first or dag_get_node */
-DagNode *dag_add_node(DagForest *forest, void *fob)
-{
- DagNode *node;
-
- node = MEM_callocN(sizeof(DagNode), "DAG node");
- if (node) {
- node->ob = fob;
- node->color = DAG_WHITE;
-
- if (forest->ugly_hack_sorry) node->type = GS(((ID *) fob)->name); /* sorry, done for pose sorting */
- if (forest->numNodes) {
- ((DagNode *) forest->DagNode.last)->next = node;
- forest->DagNode.last = node;
- forest->numNodes++;
- }
- else {
- forest->DagNode.last = node;
- forest->DagNode.first = node;
- forest->numNodes = 1;
- }
-
- if (!forest->nodeHash)
- forest->nodeHash = BLI_ghash_ptr_new("dag_add_node gh");
- BLI_ghash_insert(forest->nodeHash, fob, node);
- }
-
- return node;
-}
-
-DagNode *dag_get_node(DagForest *forest, void *fob)
-{
- DagNode *node;
-
- node = dag_find_node(forest, fob);
- if (!node)
- node = dag_add_node(forest, fob);
- return node;
-}
-
-
-
-DagNode *dag_get_sub_node(DagForest *forest, void *fob)
-{
- DagNode *node;
- DagAdjList *mainchild, *prev = NULL;
-
- mainchild = ((DagNode *) forest->DagNode.first)->child;
- /* remove from first node (scene) adj list if present */
- while (mainchild) {
- if (mainchild->node == fob) {
- if (prev) {
- prev->next = mainchild->next;
- MEM_freeN(mainchild);
- break;
- }
- else {
- ((DagNode *) forest->DagNode.first)->child = mainchild->next;
- MEM_freeN(mainchild);
- break;
- }
- }
- prev = mainchild;
- mainchild = mainchild->next;
- }
- node = dag_find_node(forest, fob);
- if (!node)
- node = dag_add_node(forest, fob);
- return node;
-}
-
-static void dag_add_parent_relation(DagForest *UNUSED(forest), DagNode *fob1, DagNode *fob2, short rel, const char *name)
-{
- DagAdjList *itA = fob2->parent;
-
- while (itA) { /* search if relation exist already */
- if (itA->node == fob1) {
- itA->type |= rel;
- itA->count += 1;
- return;
- }
- itA = itA->next;
- }
- /* create new relation and insert at head. MALLOC alert! */
- itA = MEM_mallocN(sizeof(DagAdjList), "DAG adj list");
- itA->node = fob1;
- itA->type = rel;
- itA->count = 1;
- itA->next = fob2->parent;
- itA->name = name;
- fob2->parent = itA;
-}
-
-void dag_add_relation(DagForest *forest, DagNode *fob1, DagNode *fob2, short rel, const char *name)
-{
- DagAdjList *itA = fob1->child;
-
- /* parent relation is for cycle checking */
- dag_add_parent_relation(forest, fob1, fob2, rel, name);
-
- /* TODO(sergey): Find a better place for this. */
-#ifdef WITH_OPENSUBDIV
- if ((rel & (DAG_RL_DATA_DATA | DAG_RL_DATA_OB)) != 0) {
- if (fob1->type == ID_OB) {
- if ((fob1->eval_flags & DAG_EVAL_NEED_CPU) == 0) {
- Object *ob2 = fob2->ob;
- if (ob2->recalc & OB_RECALC_ALL) {
- /* Make sure object has all the data on CPU. */
- Object *ob1 = fob1->ob;
- ob1->recalc |= OB_RECALC_DATA;
- }
- fob1->eval_flags |= DAG_EVAL_NEED_CPU;
- }
- }
- }
-#endif
-
- while (itA) { /* search if relation exist already */
- if (itA->node == fob2) {
- itA->type |= rel;
- itA->count += 1;
- return;
- }
- itA = itA->next;
- }
- /* create new relation and insert at head. MALLOC alert! */
- itA = MEM_mallocN(sizeof(DagAdjList), "DAG adj list");
- itA->node = fob2;
- itA->type = rel;
- itA->count = 1;
- itA->next = fob1->child;
- itA->name = name;
- fob1->child = itA;
-}
-
-static const char *dag_node_name(DagForest *dag, DagNode *node)
-{
- if (node->ob == NULL)
- return "null";
- else if (dag->ugly_hack_sorry)
- return ((ID *)(node->ob))->name + 2;
- else
- return ((bPoseChannel *)(node->ob))->name;
-}
-
-static void dag_node_print_dependencies(DagForest *dag, DagNode *node)
-{
- DagAdjList *itA;
-
- printf("%s depends on:\n", dag_node_name(dag, node));
-
- for (itA = node->parent; itA; itA = itA->next)
- printf(" %s through %s\n", dag_node_name(dag, itA->node), itA->name);
- printf("\n");
-}
-
-static int dag_node_print_dependency_recurs(DagForest *dag, DagNode *node, DagNode *endnode)
-{
- DagAdjList *itA;
-
- if (node->color == DAG_BLACK)
- return 0;
-
- node->color = DAG_BLACK;
-
- if (node == endnode)
- return 1;
-
- for (itA = node->parent; itA; itA = itA->next) {
- if (dag_node_print_dependency_recurs(dag, itA->node, endnode)) {
- printf(" %s depends on %s through %s.\n", dag_node_name(dag, node), dag_node_name(dag, itA->node), itA->name);
- return 1;
- }
- }
-
- return 0;
-}
-
-static void dag_node_print_dependency_cycle(DagForest *dag, DagNode *startnode, DagNode *endnode, const char *name)
-{
- DagNode *node;
-
- for (node = dag->DagNode.first; node; node = node->next)
- node->color = DAG_WHITE;
-
- printf(" %s depends on %s through %s.\n", dag_node_name(dag, endnode), dag_node_name(dag, startnode), name);
- dag_node_print_dependency_recurs(dag, startnode, endnode);
- printf("\n");
-}
-
-static int dag_node_recurs_level(DagNode *node, int level)
-{
- DagAdjList *itA;
- int newlevel;
-
- node->color = DAG_BLACK; /* done */
- newlevel = ++level;
-
- for (itA = node->parent; itA; itA = itA->next) {
- if (itA->node->color == DAG_WHITE) {
- itA->node->ancestor_count = dag_node_recurs_level(itA->node, level);
- newlevel = MAX2(newlevel, level + itA->node->ancestor_count);
- }
- else
- newlevel = MAX2(newlevel, level + itA->node->ancestor_count);
- }
-
- return newlevel;
-}
-
-static void dag_check_cycle(DagForest *dag)
-{
- DagNode *node;
- DagAdjList *itA;
-
- dag->is_acyclic = true;
-
- /* debugging print */
- if (dag_print_dependencies)
- for (node = dag->DagNode.first; node; node = node->next)
- dag_node_print_dependencies(dag, node);
-
- /* tag nodes unchecked */
- for (node = dag->DagNode.first; node; node = node->next)
- node->color = DAG_WHITE;
-
- for (node = dag->DagNode.first; node; node = node->next) {
- if (node->color == DAG_WHITE) {
- node->ancestor_count = dag_node_recurs_level(node, 0);
- }
- }
-
- /* check relations, and print errors */
- for (node = dag->DagNode.first; node; node = node->next) {
- for (itA = node->parent; itA; itA = itA->next) {
- if (itA->node->ancestor_count > node->ancestor_count) {
- if (node->ob && itA->node->ob) {
- dag->is_acyclic = false;
- printf("Dependency cycle detected:\n");
- dag_node_print_dependency_cycle(dag, itA->node, node, itA->name);
- }
- }
- }
- }
-
- /* parent relations are only needed for cycle checking, so free now */
- for (node = dag->DagNode.first; node; node = node->next) {
- while (node->parent) {
- itA = node->parent->next;
- MEM_freeN(node->parent);
- node->parent = itA;
- }
- }
-}
-
-/* debug test functions */
-
-void graph_print_queue(DagNodeQueue *nqueue)
-{
- DagNodeQueueElem *queueElem;
-
- queueElem = nqueue->first;
- while (queueElem) {
- fprintf(stderr, "** %s %i %i-%i ", ((ID *) queueElem->node->ob)->name, queueElem->node->color, queueElem->node->DFS_dvtm, queueElem->node->DFS_fntm);
- queueElem = queueElem->next;
- }
- fprintf(stderr, "\n");
-}
-
-void graph_print_queue_dist(DagNodeQueue *nqueue)
-{
- DagNodeQueueElem *queueElem;
- int count;
-
- queueElem = nqueue->first;
- count = 0;
- while (queueElem) {
- fprintf(stderr, "** %25s %2.2i-%2.2i ", ((ID *) queueElem->node->ob)->name, queueElem->node->DFS_dvtm, queueElem->node->DFS_fntm);
- while (count < queueElem->node->DFS_dvtm - 1) { fputc(' ', stderr); count++; }
- fputc('|', stderr);
- while (count < queueElem->node->DFS_fntm - 2) { fputc('-', stderr); count++; }
- fputc('|', stderr);
- fputc('\n', stderr);
- count = 0;
- queueElem = queueElem->next;
- }
- fprintf(stderr, "\n");
-}
-
-void graph_print_adj_list(DagForest *dag)
-{
- DagNode *node;
- DagAdjList *itA;
-
- node = dag->DagNode.first;
- while (node) {
- fprintf(stderr, "node : %s col: %i", ((ID *) node->ob)->name, node->color);
- itA = node->child;
- while (itA) {
- fprintf(stderr, "-- %s ", ((ID *) itA->node->ob)->name);
-
- itA = itA->next;
- }
- fprintf(stderr, "\n");
- node = node->next;
- }
-}
-
-/* ************************ API *********************** */
-
-/* mechanism to allow editors to be informed of depsgraph updates,
- * to do their own updates based on changes... */
-static void (*EditorsUpdateIDCb)(Main *bmain, ID *id) = NULL;
-static void (*EditorsUpdateSceneCb)(Main *bmain, Scene *scene, int updated) = NULL;
-static void (*EditorsUpdateScenePreCb)(Main *bmain, Scene *scene, bool time) = NULL;
-
-void DAG_editors_update_cb(void (*id_func)(Main *bmain, ID *id),
- void (*scene_func)(Main *bmain, Scene *scene, int updated),
- void (*scene_pre_func)(Main *bmain, Scene *scene, bool time))
-{
- if (DEG_depsgraph_use_legacy()) {
- EditorsUpdateIDCb = id_func;
- EditorsUpdateSceneCb = scene_func;
- EditorsUpdateScenePreCb = scene_pre_func;
- }
- else {
- /* New dependency graph. */
- DEG_editors_set_update_cb(id_func, scene_func, scene_pre_func);
- }
-}
-
-void DAG_editors_update_pre(Main *bmain, Scene *scene, bool time)
-{
- if (DEG_depsgraph_use_legacy()) {
- if (EditorsUpdateScenePreCb != NULL) {
- EditorsUpdateScenePreCb(bmain, scene, time);
- }
- }
- else {
- DEG_editors_update_pre(bmain, scene, time);
- }
-}
-
-static void dag_editors_id_update(Main *bmain, ID *id)
-{
- if (EditorsUpdateIDCb)
- EditorsUpdateIDCb(bmain, id);
-}
-
-static void dag_editors_scene_update(Main *bmain, Scene *scene, int updated)
-{
- if (EditorsUpdateSceneCb)
- EditorsUpdateSceneCb(bmain, scene, updated);
-}
-
-/* groups with objects in this scene need to be put in the right order as well */
-static void scene_sort_groups(Main *bmain, Scene *sce)
-{
- Base *base;
- Group *group;
- GroupObject *go;
- Object *ob;
-
- /* test; are group objects all in this scene? */
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- ob->id.tag &= ~LIB_TAG_DOIT;
- }
- for (base = sce->base.first; base; base = base->next)
- base->object->id.tag |= LIB_TAG_DOIT;
-
- for (group = bmain->group.first; group; group = group->id.next) {
- for (go = group->gobject.first; go; go = go->next) {
- if ((go->ob->id.tag & LIB_TAG_DOIT) == 0)
- break;
- }
- /* this group is entirely in this scene */
- if (go == NULL) {
- ListBase listb = {NULL, NULL};
-
- for (go = group->gobject.first; go; go = go->next)
- go->ob->id.newid = (ID *)go;
-
- /* in order of sorted bases we reinsert group objects */
- for (base = sce->base.first; base; base = base->next) {
-
- if (base->object->id.newid) {
- go = (GroupObject *)base->object->id.newid;
- base->object->id.newid = NULL;
- BLI_remlink(&group->gobject, go);
- BLI_addtail(&listb, go);
- }
- }
- /* copy the newly sorted listbase */
- group->gobject = listb;
- }
- }
-
- /* newid abused for GroupObject, cleanup. */
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- ob->id.newid = NULL;
- }
-}
-
-static void dag_scene_tag_rebuild(Scene *sce)
-{
- if (sce->theDag) {
- sce->theDag->need_update = true;
- }
-}
-
-/* free the depency graph */
-static void dag_scene_free(Scene *sce)
-{
- if (sce->theDag) {
- free_forest(sce->theDag);
- MEM_freeN(sce->theDag);
- sce->theDag = NULL;
- }
-}
-
-/* Check whether object data needs to be evaluated before it
- * might be used by others.
- *
- * Means that mesh object needs to have proper derivedFinal,
- * curves-typed objects are to have proper curve cache.
- *
- * Other objects or objects which are tagged for data update are
- * not considered to be in need of evaluation.
- */
-static bool check_object_needs_evaluation(Object *object)
-{
- if (object->recalc & OB_RECALC_ALL) {
- /* Object is tagged for update anyway, no need to re-tag it. */
- return false;
- }
-
- if (object->type == OB_MESH) {
- return object->derivedFinal == NULL;
- }
- else if (ELEM(object->type, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
- return object->curve_cache == NULL;
- }
-
- return false;
-}
-
-/* Check whether object data is tagged for update. */
-static bool check_object_tagged_for_update(Object *object)
-{
- if (object->recalc & OB_RECALC_ALL) {
- return true;
- }
-
- if (ELEM(object->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
- ID *data_id = object->data;
- return (data_id->recalc & ID_RECALC_ALL) != 0;
- }
-
- return false;
-}
-
-/* Flush changes from tagged objects in the scene to their
- * dependencies which are not evaluated yet.
- *
- * This is needed to ensure all the dependencies are met
- * before objects gets handled by object_handle_update(),
- *
- * This is needed when visible layers are changed or changing
- * scene graph layout which involved usage of objects which
- * aren't in the scene or weren't visible yet.
- */
-static void dag_invisible_dependencies_flush(Scene *scene)
-{
- DagNode *root_node = scene->theDag->DagNode.first, *node;
- DagNodeQueue *queue;
-
- for (node = root_node; node != NULL; node = node->next) {
- node->color = DAG_WHITE;
- }
-
- queue = queue_create(DAGQUEUEALLOC);
-
- for (node = root_node; node != NULL; node = node->next) {
- if (node->color == DAG_WHITE) {
- push_stack(queue, node);
- node->color = DAG_GRAY;
-
- while (queue->count) {
- DagNode *current_node = get_top_node_queue(queue);
- DagAdjList *itA;
- bool skip = false;
-
- for (itA = current_node->child; itA; itA = itA->next) {
- if (itA->node->color == DAG_WHITE) {
- itA->node->color = DAG_GRAY;
- push_stack(queue, itA->node);
- skip = true;
- break;
- }
- }
-
- if (!skip) {
- current_node = pop_queue(queue);
-
- if (current_node->type == ID_OB) {
- Object *current_object = current_node->ob;
- if (check_object_needs_evaluation(current_object)) {
- for (itA = current_node->child; itA; itA = itA->next) {
- if (itA->node->type == ID_OB) {
- Object *object = itA->node->ob;
- if (check_object_tagged_for_update(object)) {
- current_object->recalc |= OB_RECALC_OB | OB_RECALC_DATA;
- }
- }
- }
- }
- }
- node->color = DAG_BLACK;
- }
- }
- }
- }
-
- queue_delete(queue);
-}
-
-static void dag_invisible_dependencies_check_flush(Main *bmain, Scene *scene)
-{
- if (DAG_id_type_tagged(bmain, ID_OB) ||
- DAG_id_type_tagged(bmain, ID_ME) || /* Mesh */
- DAG_id_type_tagged(bmain, ID_CU) || /* Curve */
- DAG_id_type_tagged(bmain, ID_MB) || /* MetaBall */
- DAG_id_type_tagged(bmain, ID_LT)) /* Lattice */
- {
- dag_invisible_dependencies_flush(scene);
- }
-}
-
-/* sort the base list on dependency order */
-static void dag_scene_build(Main *bmain, Scene *sce)
-{
- DagNode *node, *rootnode;
- DagNodeQueue *nqueue;
- DagAdjList *itA;
- int time;
- int skip = 0;
- ListBase tempbase;
- Base *base;
-
- BLI_listbase_clear(&tempbase);
-
- build_dag(bmain, sce, DAG_RL_ALL_BUT_DATA);
-
- dag_check_cycle(sce->theDag);
-
- nqueue = queue_create(DAGQUEUEALLOC);
-
- for (node = sce->theDag->DagNode.first; node; node = node->next) {
- node->color = DAG_WHITE;
- }
-
- time = 1;
-
- rootnode = sce->theDag->DagNode.first;
- rootnode->color = DAG_GRAY;
- time++;
- push_stack(nqueue, rootnode);
-
- while (nqueue->count) {
-
- skip = 0;
- node = get_top_node_queue(nqueue);
-
- itA = node->child;
- while (itA != NULL) {
- if (itA->node->color == DAG_WHITE) {
- itA->node->DFS_dvtm = time;
- itA->node->color = DAG_GRAY;
-
- time++;
- push_stack(nqueue, itA->node);
- skip = 1;
- break;
- }
- itA = itA->next;
- }
-
- if (!skip) {
- if (node) {
- node = pop_queue(nqueue);
- if (node->ob == sce) /* we are done */
- break;
- node->color = DAG_BLACK;
-
- time++;
- base = sce->base.first;
- while (base && base->object != node->ob)
- base = base->next;
- if (base) {
- BLI_remlink(&sce->base, base);
- BLI_addhead(&tempbase, base);
- }
- }
- }
- }
-
- /* temporal correction for circular dependencies */
- base = sce->base.first;
- while (base) {
- BLI_remlink(&sce->base, base);
- BLI_addhead(&tempbase, base);
- //if (G.debug & G_DEBUG)
- printf("cyclic %s\n", base->object->id.name);
- base = sce->base.first;
- }
-
- sce->base = tempbase;
- queue_delete(nqueue);
-
- /* all groups with objects in this scene gets resorted too */
- scene_sort_groups(bmain, sce);
-
- if (G.debug & G_DEBUG) {
- printf("\nordered\n");
- for (base = sce->base.first; base; base = base->next) {
- printf(" %s\n", base->object->id.name);
- }
- }
-
- /* Make sure that new dependencies which came from invisible layers
- * are tagged for update (if they're needed for objects which were
- * tagged for update).
- */
- dag_invisible_dependencies_check_flush(bmain, sce);
-}
-
-/* clear all dependency graphs */
-void DAG_relations_tag_update(Main *bmain)
-{
- if (DEG_depsgraph_use_legacy()) {
- Scene *sce;
- for (sce = bmain->scene.first; sce; sce = sce->id.next) {
- dag_scene_tag_rebuild(sce);
- }
- }
- else {
- /* New dependency graph. */
- DEG_relations_tag_update(bmain);
- }
-}
-
-/* rebuild dependency graph only for a given scene */
-void DAG_scene_relations_rebuild(Main *bmain, Scene *sce)
-{
- if (DEG_depsgraph_use_legacy()) {
- dag_scene_free(sce);
- DAG_scene_relations_update(bmain, sce);
- }
- else {
- /* New dependency graph. */
- DEG_scene_relations_rebuild(bmain, sce);
- }
-}
-
-/* create dependency graph if it was cleared or didn't exist yet */
-void DAG_scene_relations_update(Main *bmain, Scene *sce)
-{
- if (DEG_depsgraph_use_legacy()) {
- if (!sce->theDag || sce->theDag->need_update)
- dag_scene_build(bmain, sce);
- }
- else {
- /* New dependency graph. */
- DEG_scene_relations_update(bmain, sce);
- }
-}
-
-void DAG_scene_relations_validate(Main *bmain, Scene *sce)
-{
- if (!DEG_depsgraph_use_legacy()) {
- DEG_debug_scene_relations_validate(bmain, sce);
- }
-}
-
-void DAG_scene_free(Scene *sce)
-{
- if (DEG_depsgraph_use_legacy()) {
- if (sce->theDag) {
- free_forest(sce->theDag);
- MEM_freeN(sce->theDag);
- sce->theDag = NULL;
- }
- }
- else {
- if (sce->depsgraph) {
- DEG_graph_free(sce->depsgraph);
- sce->depsgraph = NULL;
- }
- }
-}
-
-static void lib_id_recalc_tag(Main *bmain, ID *id)
-{
- id->recalc |= ID_RECALC;
- DAG_id_type_tag(bmain, GS(id->name));
-}
-
-static void lib_id_recalc_data_tag(Main *bmain, ID *id)
-{
- id->recalc |= ID_RECALC_DATA;
- DAG_id_type_tag(bmain, GS(id->name));
-}
-
-/* node was checked to have lasttime != curtime and is if type ID_OB */
-static void flush_update_node(Main *bmain, DagNode *node, unsigned int layer, int curtime)
-{
- DagAdjList *itA;
- Object *ob, *obc;
- int oldflag;
- bool changed = false;
- unsigned int all_layer;
-
- node->lasttime = curtime;
-
- ob = node->ob;
- if (ob && (ob->recalc & OB_RECALC_ALL)) {
- all_layer = node->scelay;
-
- /* got an object node that changes, now check relations */
- for (itA = node->child; itA; itA = itA->next) {
- all_layer |= itA->lay;
- /* the relationship is visible */
- if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit)
- if (itA->node->type == ID_OB) {
- obc = itA->node->ob;
- oldflag = obc->recalc;
-
- /* got a ob->obc relation, now check if flag needs flush */
- if (ob->recalc & OB_RECALC_OB) {
- if (itA->type & DAG_RL_OB_OB) {
- //printf("ob %s changes ob %s\n", ob->id.name, obc->id.name);
- obc->recalc |= OB_RECALC_OB;
- lib_id_recalc_tag(bmain, &obc->id);
- }
- if (itA->type & DAG_RL_OB_DATA) {
- //printf("ob %s changes obdata %s\n", ob->id.name, obc->id.name);
- obc->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &obc->id);
- }
- }
- if (ob->recalc & OB_RECALC_DATA) {
- if (itA->type & DAG_RL_DATA_OB) {
- //printf("obdata %s changes ob %s\n", ob->id.name, obc->id.name);
- obc->recalc |= OB_RECALC_OB;
- lib_id_recalc_tag(bmain, &obc->id);
- }
- if (itA->type & DAG_RL_DATA_DATA) {
- //printf("obdata %s changes obdata %s\n", ob->id.name, obc->id.name);
- obc->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &obc->id);
- }
- }
- if (oldflag != obc->recalc) changed = 1;
- }
- }
- }
- /* even nicer, we can clear recalc flags... */
- if ((all_layer & layer) == 0) { // XXX && (ob != obedit)) {
- /* but existing displaylists or derivedmesh should be freed */
- if (ob->recalc & OB_RECALC_DATA)
- BKE_object_free_derived_caches(ob);
-
- ob->recalc &= ~OB_RECALC_ALL;
- }
- }
-
- /* check case where child changes and parent forcing obdata to change */
- /* should be done regardless if this ob has recalc set */
- /* could merge this in with loop above...? (ton) */
- for (itA = node->child; itA; itA = itA->next) {
- /* the relationship is visible */
- if ((itA->lay & layer)) { // XXX || (itA->node->ob == obedit)
- if (itA->node->type == ID_OB) {
- obc = itA->node->ob;
- /* child moves */
- if ((obc->recalc & OB_RECALC_ALL) == OB_RECALC_OB) {
- /* parent has deforming info */
- if (itA->type & (DAG_RL_OB_DATA | DAG_RL_DATA_DATA)) {
- // printf("parent %s changes ob %s\n", ob->id.name, obc->id.name);
- obc->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &obc->id);
- }
- }
- }
- }
- }
-
- /* we only go deeper if node not checked or something changed */
- for (itA = node->child; itA; itA = itA->next) {
- if (changed || itA->node->lasttime != curtime)
- flush_update_node(bmain, itA->node, layer, curtime);
- }
-
-}
-
-/* node was checked to have lasttime != curtime, and is of type ID_OB */
-static unsigned int flush_layer_node(Scene *sce, DagNode *node, int curtime)
-{
- DagAdjList *itA;
-
- node->lasttime = curtime;
- node->lay = node->scelay;
-
- for (itA = node->child; itA; itA = itA->next) {
- if (itA->node->type == ID_OB) {
- if (itA->node->lasttime != curtime) {
- itA->lay = flush_layer_node(sce, itA->node, curtime); /* lay is only set once for each relation */
- }
- else {
- itA->lay = itA->node->lay;
- }
-
- node->lay |= itA->lay;
- }
- }
-
- return node->lay;
-}
-
-/* node was checked to have lasttime != curtime, and is of type ID_OB */
-static void flush_pointcache_reset(Main *bmain, Scene *scene, DagNode *node,
- int curtime, unsigned int lay, bool reset)
-{
- DagAdjList *itA;
- Object *ob;
-
- node->lasttime = curtime;
-
- for (itA = node->child; itA; itA = itA->next) {
- if (itA->node->type == ID_OB) {
- if (itA->node->lasttime != curtime) {
- ob = (Object *)(itA->node->ob);
-
- if (reset || (ob->recalc & OB_RECALC_ALL)) {
- if (BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH)) {
- /* Don't tag nodes which are on invisible layer. */
- if (itA->node->lay & lay) {
- ob->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &ob->id);
- }
- }
-
- flush_pointcache_reset(bmain, scene, itA->node, curtime, lay, true);
- }
- else
- flush_pointcache_reset(bmain, scene, itA->node, curtime, lay, false);
- }
- }
- }
-}
-
-/* flush layer flags to dependencies */
-static void dag_scene_flush_layers(Scene *sce, int lay)
-{
- DagNode *node, *firstnode;
- DagAdjList *itA;
- Base *base;
- int lasttime;
-
- firstnode = sce->theDag->DagNode.first; /* always scene node */
-
- for (itA = firstnode->child; itA; itA = itA->next)
- itA->lay = 0;
-
- sce->theDag->time++; /* so we know which nodes were accessed */
- lasttime = sce->theDag->time;
-
- /* update layer flags in nodes */
- for (base = sce->base.first; base; base = base->next) {
- node = dag_get_node(sce->theDag, base->object);
- node->scelay = base->object->lay;
- }
-
- /* ensure cameras are set as if they are on a visible layer, because
- * they ared still used for rendering or setting the camera view
- *
- * XXX, this wont work for local view / unlocked camera's */
- if (sce->camera) {
- node = dag_get_node(sce->theDag, sce->camera);
- node->scelay |= lay;
- }
-
-#ifdef DURIAN_CAMERA_SWITCH
- {
- TimeMarker *m;
-
- for (m = sce->markers.first; m; m = m->next) {
- if (m->camera) {
- node = dag_get_node(sce->theDag, m->camera);
- node->scelay |= lay;
- }
- }
- }
-#endif
-
- /* flush layer nodes to dependencies */
- for (itA = firstnode->child; itA; itA = itA->next)
- if (itA->node->lasttime != lasttime && itA->node->type == ID_OB)
- flush_layer_node(sce, itA->node, lasttime);
-}
-
-static void dag_tag_renderlayers(Scene *sce, unsigned int lay)
-{
- if (sce->nodetree) {
- bNode *node;
- Base *base;
- unsigned int lay_changed = 0;
-
- for (base = sce->base.first; base; base = base->next)
- if (base->lay & lay)
- if (base->object->recalc)
- lay_changed |= base->lay;
-
- for (node = sce->nodetree->nodes.first; node; node = node->next) {
- if (node->id == (ID *)sce) {
- SceneRenderLayer *srl = BLI_findlink(&sce->r.layers, node->custom1);
- if (srl && (srl->lay & lay_changed))
- nodeUpdate(sce->nodetree, node);
- }
- }
- }
-}
-
-/* flushes all recalc flags in objects down the dependency tree */
-void DAG_scene_flush_update(Main *bmain, Scene *sce, unsigned int lay, const short time)
-{
- DagNode *firstnode;
- DagAdjList *itA;
- Object *ob;
- int lasttime;
-
- if (!DEG_depsgraph_use_legacy()) {
- DEG_scene_flush_update(bmain, sce);
- return;
- }
-
- if (sce->theDag == NULL || sce->theDag->need_update) {
- printf("DAG zero... not allowed to happen!\n");
- DAG_scene_relations_update(bmain, sce);
- }
-
- firstnode = sce->theDag->DagNode.first; /* always scene node */
-
- /* first we flush the layer flags */
- dag_scene_flush_layers(sce, lay);
-
- /* then we use the relationships + layer info to flush update events */
- sce->theDag->time++; /* so we know which nodes were accessed */
- lasttime = sce->theDag->time;
- for (itA = firstnode->child; itA; itA = itA->next)
- if (itA->node->lasttime != lasttime && itA->node->type == ID_OB)
- flush_update_node(bmain, itA->node, lay, lasttime);
-
- /* if update is not due to time change, do pointcache clears */
- if (!time) {
- sce->theDag->time++; /* so we know which nodes were accessed */
- lasttime = sce->theDag->time;
- for (itA = firstnode->child; itA; itA = itA->next) {
- if (itA->node->lasttime != lasttime && itA->node->type == ID_OB) {
- ob = (Object *)(itA->node->ob);
-
- if (ob->recalc & OB_RECALC_ALL) {
- if (BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH)) {
- ob->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &ob->id);
- }
-
- flush_pointcache_reset(bmain, sce, itA->node, lasttime,
- lay, true);
- }
- else
- flush_pointcache_reset(bmain, sce, itA->node, lasttime,
- lay, false);
- }
- }
- }
-
- dag_tag_renderlayers(sce, lay);
-}
-
-static bool modifier_nlastrips_use_time(ListBase *strips)
-{
- NlaStrip *strip;
-
- if (strips) {
- for (strip = strips->first; strip; strip = strip->next) {
- if (modifier_nlastrips_use_time(&strip->strips)) {
- return true;
- }
- else if (strip->act) {
- FCurve *fcu;
-
- for (fcu = strip->act->curves.first; fcu; fcu = fcu->next) {
- if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
-static bool object_modifiers_use_time(Object *ob)
-{
- ModifierData *md;
-
- /* check if a modifier in modifier stack needs time input */
- for (md = ob->modifiers.first; md; md = md->next) {
- if (modifier_dependsOnTime(md))
- return true;
- }
-
- /* check whether any modifiers are animated */
- if (ob->adt) {
- AnimData *adt = ob->adt;
- NlaTrack *nlt;
- FCurve *fcu;
-
- /* action - check for F-Curves with paths containing 'modifiers[' */
- if (adt->action) {
- for (fcu = adt->action->curves.first; fcu; fcu = fcu->next) {
- if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
- return true;
- }
- }
-
- /* This here allows modifier properties to get driven and still update properly
- *
- * Workaround to get [#26764] (e.g. subsurf levels not updating when animated/driven)
- * working, without the updating problems ([#28525] [#28690] [#28774] [#28777]) caused
- * by the RNA updates cache introduced in r.38649
- */
- for (fcu = adt->drivers.first; fcu; fcu = fcu->next) {
- if (fcu->rna_path && strstr(fcu->rna_path, "modifiers["))
- return true;
- }
-
- /* Also check NLA Strips... [#T45938] */
- for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
- if (modifier_nlastrips_use_time(&nlt->strips))
- return true;
- }
- }
-
- return false;
-}
-
-static short animdata_use_time(AnimData *adt)
-{
- NlaTrack *nlt;
-
- if (adt == NULL) return 0;
-
- /* check action - only if assigned, and it has anim curves */
- if (adt->action && adt->action->curves.first)
- return 1;
-
- /* check NLA tracks + strips */
- for (nlt = adt->nla_tracks.first; nlt; nlt = nlt->next) {
- if (nlt->strips.first)
- return 1;
- }
-
- /* If we have drivers, more likely than not, on a frame change
- * they'll need updating because their owner changed
- *
- * This is kindof a hack to get around a whole host of problems
- * involving drivers using non-object datablock data (which the
- * depsgraph currently has no way of representing let alone correctly
- * dependency sort+tagging). By doing this, at least we ensure that
- * some commonly attempted drivers (such as scene -> current frame;
- * see "Driver updates fail" thread on Bf-committers dated July 2)
- * will work correctly, and that other non-object datablocks will have
- * their drivers update at least on frame change.
- *
- * -- Aligorith, July 4 2011
- */
- if (adt->drivers.first)
- return 1;
-
- return 0;
-}
-
-static void dag_object_time_update_flags(Main *bmain, Scene *scene, Object *ob)
-{
- if (ob->constraints.first) {
- bConstraint *con;
- for (con = ob->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
- bConstraintTarget *ct;
-
- if (cti) {
- /* special case for camera tracking -- it doesn't use targets to define relations */
- if (ELEM(cti->type,
- CONSTRAINT_TYPE_FOLLOWTRACK,
- CONSTRAINT_TYPE_CAMERASOLVER,
- CONSTRAINT_TYPE_OBJECTSOLVER,
- CONSTRAINT_TYPE_TRANSFORM_CACHE))
- {
- ob->recalc |= OB_RECALC_OB;
- }
- else if (cti->get_constraint_targets) {
- cti->get_constraint_targets(con, &targets);
-
- for (ct = targets.first; ct; ct = ct->next) {
- if (ct->tar) {
- ob->recalc |= OB_RECALC_OB;
- break;
- }
- }
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 1);
- }
-
- }
- }
- }
-
- if (ob->parent) {
- /* motion path or bone child */
- if (ob->parent->type == OB_CURVE || ob->parent->type == OB_ARMATURE) ob->recalc |= OB_RECALC_OB;
- }
-
-#if 0 // XXX old animation system
- if (ob->nlastrips.first) {
- if (ob->dup_group) {
- bActionStrip *strip;
- /* this case is for groups with nla, whilst nla target has no action or nla */
- for (strip = ob->nlastrips.first; strip; strip = strip->next) {
- if (strip->object)
- strip->object->recalc |= OB_RECALC_ALL;
- }
- }
- }
-#endif // XXX old animation system
-
- if (animdata_use_time(ob->adt)) {
- ob->recalc |= OB_RECALC_OB;
- ob->adt->recalc |= ADT_RECALC_ANIM;
- }
-
- if ((ob->adt) && (ob->type == OB_ARMATURE)) ob->recalc |= OB_RECALC_DATA;
-
- if (object_modifiers_use_time(ob)) ob->recalc |= OB_RECALC_DATA;
- if ((ob->pose) && (ob->pose->flag & POSE_CONSTRAINTS_TIMEDEPEND)) ob->recalc |= OB_RECALC_DATA;
-
- // XXX: scene here may not be the scene that contains the rigidbody world affecting this!
- if (ob->rigidbody_object && BKE_scene_check_rigidbody_active(scene))
- ob->recalc |= OB_RECALC_OB;
-
- {
- AnimData *adt = BKE_animdata_from_id((ID *)ob->data);
- Mesh *me;
- Curve *cu;
- Lattice *lt;
-
- switch (ob->type) {
- case OB_MESH:
- me = ob->data;
- if (me->key) {
- if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
- ob->recalc |= OB_RECALC_DATA;
- }
- }
- if (ob->particlesystem.first)
- ob->recalc |= OB_RECALC_DATA;
- break;
- case OB_CURVE:
- case OB_SURF:
- cu = ob->data;
- if (cu->key) {
- if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
- ob->recalc |= OB_RECALC_DATA;
- }
- }
- break;
- case OB_FONT:
- cu = ob->data;
- if (cu->str && cu->vfont) {
- /* Can be in the curve-cache or the curve. */
- if (ob->curve_cache && !BLI_listbase_is_empty(&ob->curve_cache->disp)) {
- /* pass */
- }
- else if (!BLI_listbase_is_empty(&cu->nurb)) {
- /* pass */
- }
- else {
- ob->recalc |= OB_RECALC_DATA;
- }
- }
- break;
- case OB_LATTICE:
- lt = ob->data;
- if (lt->key) {
- if (!(ob->shapeflag & OB_SHAPE_LOCK)) {
- ob->recalc |= OB_RECALC_DATA;
- }
- }
- break;
- case OB_MBALL:
- if (ob->transflag & OB_DUPLI) ob->recalc |= OB_RECALC_DATA;
- break;
- case OB_EMPTY:
- /* update animated images */
- if (ob->empty_drawtype == OB_EMPTY_IMAGE && ob->data)
- if (BKE_image_is_animated(ob->data))
- ob->recalc |= OB_RECALC_DATA;
- break;
- }
-
- if (animdata_use_time(adt)) {
- ob->recalc |= OB_RECALC_DATA;
- adt->recalc |= ADT_RECALC_ANIM;
- }
-
- if (ob->particlesystem.first) {
- ParticleSystem *psys = ob->particlesystem.first;
-
- for (; psys; psys = psys->next) {
- if (psys_check_enabled(ob, psys, G.is_rendering)) {
- ob->recalc |= OB_RECALC_DATA;
- break;
- }
- }
- }
- }
-
- if (ob->recalc & OB_RECALC_OB)
- lib_id_recalc_tag(bmain, &ob->id);
- if (ob->recalc & OB_RECALC_DATA)
- lib_id_recalc_data_tag(bmain, &ob->id);
-
-}
-
-/* recursively update objects in groups, each group is done at most once */
-static void dag_group_update_flags(Main *bmain, Scene *scene, Group *group, const bool do_time)
-{
- GroupObject *go;
-
- if (group->id.tag & LIB_TAG_DOIT)
- return;
-
- group->id.tag |= LIB_TAG_DOIT;
-
- for (go = group->gobject.first; go; go = go->next) {
- if (do_time)
- dag_object_time_update_flags(bmain, scene, go->ob);
- if (go->ob->dup_group)
- dag_group_update_flags(bmain, scene, go->ob->dup_group, do_time);
- }
-}
-
-/* flag all objects that need recalc, for changes in time for example */
-/* do_time: make this optional because undo resets objects to their animated locations without this */
-void DAG_scene_update_flags(Main *bmain, Scene *scene, unsigned int lay, const bool do_time, const bool do_invisible_flush)
-{
- Base *base;
- Object *ob;
- Group *group;
- GroupObject *go;
- Scene *sce_iter;
-
- BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
-
- /* set ob flags where animated systems are */
- for (SETLOOPER(scene, sce_iter, base)) {
- ob = base->object;
-
- if (do_time) {
- /* now if DagNode were part of base, the node->lay could be checked... */
- /* we do all now, since the scene_flush checks layers and clears recalc flags even */
-
- /* NOTE: "sce_iter" not "scene" so that rigidbodies in background scenes work
- * (i.e. muting + rbw availability can be checked and tagged properly) [#33970]
- */
- dag_object_time_update_flags(bmain, sce_iter, ob);
- }
-
- /* recursively tag groups with LIB_TAG_DOIT, and update flags for objects */
- if (ob->dup_group)
- dag_group_update_flags(bmain, scene, ob->dup_group, do_time);
- }
-
- for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set)
- DAG_scene_flush_update(bmain, sce_iter, lay, 1);
-
- if (do_time) {
- /* test: set time flag, to disable baked systems to update */
- for (SETLOOPER(scene, sce_iter, base)) {
- ob = base->object;
- if (ob->recalc & OB_RECALC_ALL)
- ob->recalc |= OB_RECALC_TIME;
- }
-
- /* hrmf... an exception to look at once, for invisible camera object we do it over */
- if (scene->camera)
- dag_object_time_update_flags(bmain, scene, scene->camera);
- }
-
- /* and store the info in groupobject */
- for (group = bmain->group.first; group; group = group->id.next) {
- if (group->id.tag & LIB_TAG_DOIT) {
- for (go = group->gobject.first; go; go = go->next) {
- go->recalc = go->ob->recalc;
- // printf("ob %s recalc %d\n", go->ob->id.name, go->recalc);
- }
- group->id.tag &= ~LIB_TAG_DOIT;
- }
- }
-
- if (do_invisible_flush) {
- dag_invisible_dependencies_check_flush(bmain, scene);
- }
-}
-
-/* struct returned by DagSceneLayer */
-typedef struct DagSceneLayer {
- struct DagSceneLayer *next, *prev;
- Scene *scene;
- unsigned int layer;
-} DagSceneLayer;
-
-/* returns visible scenes with valid DAG */
-static void dag_current_scene_layers(Main *bmain, ListBase *lb)
-{
- wmWindowManager *wm;
- wmWindow *win;
-
- BLI_listbase_clear(lb);
-
- /* if we have a windowmanager, look into windows */
- if ((wm = bmain->wm.first)) {
-
- BKE_main_id_flag_listbase(&bmain->scene, LIB_TAG_DOIT, 1);
-
- for (win = wm->windows.first; win; win = win->next) {
- if (win->screen && win->screen->scene->theDag) {
- Scene *scene = win->screen->scene;
- DagSceneLayer *dsl;
-
- if (scene->id.tag & LIB_TAG_DOIT) {
- dsl = MEM_mallocN(sizeof(DagSceneLayer), "dag scene layer");
-
- BLI_addtail(lb, dsl);
-
- dsl->scene = scene;
- dsl->layer = BKE_screen_visible_layers(win->screen, scene);
-
- scene->id.tag &= ~LIB_TAG_DOIT;
- }
- else {
- /* It is possible that multiple windows shares the same scene
- * and have different layers visible.
- *
- * Here we deal with such cases by squashing layers bits from
- * multiple windoew to the DagSceneLayer.
- *
- * TODO(sergey): Such a lookup could be optimized perhaps,
- * however should be fine for now since we usually have only
- * few open windows.
- */
- for (dsl = lb->first; dsl; dsl = dsl->next) {
- if (dsl->scene == scene) {
- dsl->layer |= BKE_screen_visible_layers(win->screen, scene);
- break;
- }
- }
- }
- }
- }
- }
- else {
- /* if not, use the first sce */
- DagSceneLayer *dsl = MEM_mallocN(sizeof(DagSceneLayer), "dag scene layer");
-
- BLI_addtail(lb, dsl);
-
- dsl->scene = bmain->scene.first;
- dsl->layer = dsl->scene->lay;
-
- /* XXX for background mode, we should get the scene
- * from somewhere, for the -S option, but it's in
- * the context, how to get it here? */
- }
-}
-
-static void dag_group_on_visible_update(Scene *scene, Group *group)
-{
- GroupObject *go;
-
- if (group->id.tag & LIB_TAG_DOIT)
- return;
-
- group->id.tag |= LIB_TAG_DOIT;
-
- for (go = group->gobject.first; go; go = go->next) {
- if (ELEM(go->ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE)) {
- go->ob->recalc |= OB_RECALC_DATA;
- go->ob->id.tag |= LIB_TAG_DOIT;
- lib_id_recalc_tag(G.main, &go->ob->id);
- }
- if (go->ob->proxy_from) {
- go->ob->recalc |= OB_RECALC_OB;
- go->ob->id.tag |= LIB_TAG_DOIT;
- lib_id_recalc_tag(G.main, &go->ob->id);
- }
-
- if (go->ob->dup_group)
- dag_group_on_visible_update(scene, go->ob->dup_group);
- }
-}
-
-void DAG_on_visible_update(Main *bmain, const bool do_time)
-{
- ListBase listbase;
- DagSceneLayer *dsl;
-
- if (!DEG_depsgraph_use_legacy()) {
- /* Inform new dependnecy graphs about visibility changes. */
- DEG_on_visible_update(bmain, do_time);
- return;
- }
-
- /* get list of visible scenes and layers */
- dag_current_scene_layers(bmain, &listbase);
-
- for (dsl = listbase.first; dsl; dsl = dsl->next) {
- Scene *scene = dsl->scene;
- Scene *sce_iter;
- Base *base;
- Object *ob;
- DagNode *node;
- unsigned int lay = dsl->layer, oblay;
-
- /* derivedmeshes and displists are not saved to file so need to be
- * remade, tag them so they get remade in the scene update loop,
- * note armature poses or object matrices are preserved and do not
- * require updates, so we skip those */
- for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set)
- dag_scene_flush_layers(sce_iter, lay);
-
- BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
-
- for (SETLOOPER(scene, sce_iter, base)) {
- ob = base->object;
- node = (sce_iter->theDag) ? dag_get_node(sce_iter->theDag, ob) : NULL;
- oblay = (node) ? node->lay : ob->lay;
-
- if ((oblay & lay) & ~scene->lay_updated) {
- /* TODO(sergey): Why do we need armature here now but didn't need before? */
- if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE, OB_ARMATURE)) {
- ob->recalc |= OB_RECALC_DATA;
- lib_id_recalc_tag(bmain, &ob->id);
- }
- /* This should not be needed here, but in some cases, like after a redo, we can end up with
- * a wrong final matrix (see T42472).
- * Quoting Sergey, this comes from BKE_object_handle_update_ex, which is calling
- * BKE_object_where_is_calc_ex when it shouldn't, but that issue is not easily fixable.
- */
- else {
- ob->recalc |= OB_RECALC_OB;
- lib_id_recalc_tag(bmain, &ob->id);
- }
- if (ob->proxy && (ob->proxy_group == NULL)) {
- ob->proxy->recalc |= OB_RECALC_DATA;
- lib_id_recalc_tag(bmain, &ob->id);
- }
- if (ob->dup_group)
- dag_group_on_visible_update(scene, ob->dup_group);
- }
- }
-
- BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
-
- /* now tag update flags, to ensure deformers get calculated on redraw */
- DAG_scene_update_flags(bmain, scene, lay, do_time, true);
- scene->lay_updated |= lay;
- }
-
- BLI_freelistN(&listbase);
-
- /* hack to get objects updating on layer changes */
- DAG_id_type_tag(bmain, ID_OB);
-
- /* so masks update on load */
- if (bmain->mask.first) {
- Mask *mask;
-
- for (mask = bmain->mask.first; mask; mask = mask->id.next) {
- DAG_id_tag_update(&mask->id, 0);
- }
- }
-}
-
-static void dag_id_flush_update__isDependentTexture(
- void *userData, Object *UNUSED(ob), ID **idpoin, int UNUSED(cb_flag))
-{
- struct { ID *id; bool is_dependent; } *data = userData;
-
- if (*idpoin && GS((*idpoin)->name) == ID_TE) {
- if (data->id == (*idpoin))
- data->is_dependent = 1;
- }
-}
-
-static void dag_id_flush_update(Main *bmain, Scene *sce, ID *id)
-{
- Object *obt, *ob = NULL;
- short idtype;
-
- /* here we flush a few things before actual scene wide flush, mostly
- * due to only objects and not other datablocks being in the depsgraph */
-
- /* set flags & pointcache for object */
- if (GS(id->name) == ID_OB) {
- ob = (Object *)id;
- BKE_ptcache_object_reset(sce, ob, PTCACHE_RESET_DEPSGRAPH);
-
- /* So if someone tagged object recalc directly,
- * id_tag_update bit-field stays relevant
- */
- if (ob->recalc & OB_RECALC_ALL) {
- DAG_id_type_tag(bmain, GS(id->name));
- }
-
- if (ob->recalc & OB_RECALC_DATA) {
- /* all users of this ob->data should be checked */
- id = ob->data;
-
- /* no point in trying in this cases */
- if (id && id->us <= 1) {
- dag_editors_id_update(bmain, id);
- id = NULL;
- }
- }
- }
-
- /* set flags & pointcache for object data */
- if (id) {
- idtype = GS(id->name);
-
-
- if (OB_DATA_SUPPORT_ID(idtype)) {
- for (obt = bmain->object.first; obt; obt = obt->id.next) {
- if (!(ob && obt == ob) && obt->data == id) {
- obt->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &obt->id);
- BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
- }
- }
- }
- else if (idtype == ID_VF) {
- for (obt = bmain->object.first; obt; obt = obt->id.next) {
- if (obt->type == OB_FONT) {
- Curve *cu = obt->data;
- if (ELEM((struct VFont *)id, CURVE_VFONT_ANY(cu))) {
- obt->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &obt->id);
- }
- }
- }
- }
-
- /* set flags based on textures - can influence depgraph via modifiers */
- if (idtype == ID_TE) {
- for (obt = bmain->object.first; obt; obt = obt->id.next) {
- struct { ID *id; bool is_dependent; } data;
- data.id = id;
- data.is_dependent = 0;
-
- modifiers_foreachIDLink(obt, dag_id_flush_update__isDependentTexture, &data);
- if (data.is_dependent) {
- obt->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &obt->id);
- }
-
- /* particle settings can use the texture as well */
- if (obt->particlesystem.first) {
- ParticleSystem *psys = obt->particlesystem.first;
- MTex **mtexp, *mtex;
- int a;
- for (; psys; psys = psys->next) {
- mtexp = psys->part->mtex;
- for (a = 0; a < MAX_MTEX; a++, mtexp++) {
- mtex = *mtexp;
- if (mtex && mtex->tex == (Tex *)id) {
- obt->recalc |= OB_RECALC_DATA;
- lib_id_recalc_data_tag(bmain, &obt->id);
-
- if (mtex->mapto & PAMAP_INIT)
- psys->recalc |= PSYS_RECALC_RESET;
- if (mtex->mapto & PAMAP_CHILD)
- psys->recalc |= PSYS_RECALC_CHILD;
-
- BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
- }
- }
- }
- }
- }
- }
-
- /* set flags based on ShapeKey */
- if (idtype == ID_KE) {
- for (obt = bmain->object.first; obt; obt = obt->id.next) {
- Key *key = BKE_key_from_object(obt);
- if (!(ob && obt == ob) && ((ID *)key == id)) {
- obt->flag |= (OB_RECALC_OB | OB_RECALC_DATA);
- lib_id_recalc_tag(bmain, &obt->id);
- lib_id_recalc_data_tag(bmain, &obt->id);
- BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
- }
- }
- }
-
- /* set flags based on particle settings */
- if (idtype == ID_PA) {
- ParticleSystem *psys;
- for (obt = bmain->object.first; obt; obt = obt->id.next)
- for (psys = obt->particlesystem.first; psys; psys = psys->next)
- if (&psys->part->id == id)
- BKE_ptcache_object_reset(sce, obt, PTCACHE_RESET_DEPSGRAPH);
- }
-
- if (ELEM(idtype, ID_MA, ID_TE)) {
- obt = sce->basact ? sce->basact->object : NULL;
- if (obt && obt->mode & OB_MODE_TEXTURE_PAINT) {
- BKE_texpaint_slots_refresh_object(sce, obt);
- BKE_paint_proj_mesh_data_check(sce, obt, NULL, NULL, NULL, NULL);
- GPU_drawobject_free(obt->derivedFinal);
- }
- }
-
- if (idtype == ID_MC) {
- MovieClip *clip = (MovieClip *) id;
-
- BKE_tracking_dopesheet_tag_update(&clip->tracking);
-
- for (obt = bmain->object.first; obt; obt = obt->id.next) {
- bConstraint *con;
- for (con = obt->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- if (ELEM(cti->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_CAMERASOLVER,
- CONSTRAINT_TYPE_OBJECTSOLVER))
- {
- obt->recalc |= OB_RECALC_OB;
- lib_id_recalc_tag(bmain, &obt->id);
- break;
- }
- }
- }
-
- if (sce->nodetree) {
- bNode *node;
-
- for (node = sce->nodetree->nodes.first; node; node = node->next) {
- if (node->id == id) {
- nodeUpdate(sce->nodetree, node);
- }
- }
- }
- }
-
- /* Not pretty to iterate all the nodes here, but it's as good as it
- * could be with the current depsgraph design/
- */
- if (idtype == ID_IM) {
- FOREACH_NODETREE(bmain, ntree, parent_id) {
- if (ntree->type == NTREE_SHADER) {
- bNode *node;
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->id == id) {
- lib_id_recalc_tag(bmain, &ntree->id);
- break;
- }
- }
- }
- } FOREACH_NODETREE_END
- }
-
- if (idtype == ID_MSK) {
- if (sce->nodetree) {
- bNode *node;
-
- for (node = sce->nodetree->nodes.first; node; node = node->next) {
- if (node->id == id) {
- nodeUpdate(sce->nodetree, node);
- }
- }
- }
- }
-
- /* camera's matrix is used to orient reconstructed stuff,
- * so it should happen tracking-related constraints recalculation
- * when camera is changing (sergey) */
- if (sce->camera && &sce->camera->id == id) {
- MovieClip *clip = BKE_object_movieclip_get(sce, sce->camera, true);
-
- if (clip)
- dag_id_flush_update(bmain, sce, &clip->id);
- }
-
- /* update editors */
- dag_editors_id_update(bmain, id);
- }
-}
-
-void DAG_ids_flush_tagged(Main *bmain)
-{
- ListBase listbase;
- DagSceneLayer *dsl;
- ListBase *lbarray[MAX_LIBARRAY];
- int a;
- bool do_flush = false;
-
- if (!DEG_depsgraph_use_legacy()) {
- DEG_ids_flush_tagged(bmain);
- return;
- }
-
- /* get list of visible scenes and layers */
- dag_current_scene_layers(bmain, &listbase);
-
- if (BLI_listbase_is_empty(&listbase))
- return;
-
- /* loop over all ID types */
- a = set_listbasepointers(bmain, lbarray);
-
- while (a--) {
- ListBase *lb = lbarray[a];
- ID *id = lb->first;
-
- if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
- for (; id; id = id->next) {
- if (id->recalc & ID_RECALC_ALL) {
- for (dsl = listbase.first; dsl; dsl = dsl->next)
- dag_id_flush_update(bmain, dsl->scene, id);
-
- do_flush = true;
- }
- }
- }
- }
-
- /* flush changes to other objects */
- if (do_flush) {
- for (dsl = listbase.first; dsl; dsl = dsl->next)
- DAG_scene_flush_update(bmain, dsl->scene, dsl->layer, 0);
- }
-
- BLI_freelistN(&listbase);
-}
-
-void DAG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
-{
- ListBase *lbarray[MAX_LIBARRAY];
- int a;
- bool updated = false;
-
- if (!DEG_depsgraph_use_legacy()) {
- DEG_ids_check_recalc(bmain, scene, time);
- return;
- }
-
- /* loop over all ID types */
- a = set_listbasepointers(bmain, lbarray);
-
- while (a--) {
- ListBase *lb = lbarray[a];
- ID *id = lb->first;
-
- if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
- updated = true;
- break;
- }
- }
-
- dag_editors_scene_update(bmain, scene, (updated || time));
-}
-
-/* It is possible that scene_update_post and frame_update_post handlers
- * will modify objects. The issue is that DAG_ids_clear_recalc is called
- * just after callbacks, which leaves objects with recalc flags but no
- * corresponding bit in ID recalc bitfield. This leads to some kind of
- * regression when using ID type tag fields to check whether there objects
- * to be updated internally comparing threaded DAG with legacy one.
- *
- * For now let's have a workaround which will preserve tag for ID_OB
- * if there're objects with OB_RECALC_ALL bits. This keeps behavior
- * unchanged comparing with 2.69 release.
- *
- * TODO(sergey): Need to get rid of such a workaround.
- *
- * - sergey -
- */
-
-#define POST_UPDATE_HANDLER_WORKAROUND
-
-void DAG_ids_clear_recalc(Main *bmain)
-{
- ListBase *lbarray[MAX_LIBARRAY];
- bNodeTree *ntree;
- int a;
-
-#ifdef POST_UPDATE_HANDLER_WORKAROUND
- bool have_updated_objects = false;
-
- if (DAG_id_type_tagged(bmain, ID_OB)) {
- ListBase listbase;
- DagSceneLayer *dsl;
-
- /* We need to check all visible scenes, otherwise resetting
- * OB_ID changed flag will only work fine for first scene of
- * multiple visible and all the rest will skip update.
- *
- * This could also lead to wrong behavior scene update handlers
- * because of missing ID datablock changed flags.
- *
- * This is a bit of a bummer to allocate list here, but likely
- * it wouldn't become too much bad because it only happens when
- * objects were actually changed.
- */
- dag_current_scene_layers(bmain, &listbase);
-
- for (dsl = listbase.first; dsl; dsl = dsl->next) {
- Scene *scene = dsl->scene;
- DagNode *node;
- for (node = scene->theDag->DagNode.first;
- node != NULL && have_updated_objects == false;
- node = node->next)
- {
- if (node->type == ID_OB) {
- Object *object = (Object *) node->ob;
- if (object->recalc & OB_RECALC_ALL) {
- have_updated_objects = true;
- break;
- }
- }
- }
- }
-
- BLI_freelistN(&listbase);
- }
-#endif
-
- /* loop over all ID types */
- a = set_listbasepointers(bmain, lbarray);
-
- while (a--) {
- ListBase *lb = lbarray[a];
- ID *id = lb->first;
-
- if (id && bmain->id_tag_update[BKE_idcode_to_index(GS(id->name))]) {
- for (; id; id = id->next) {
- id->recalc &= ~ID_RECALC_ALL;
-
- /* some ID's contain semi-datablock nodetree */
- ntree = ntreeFromID(id);
- if (ntree)
- ntree->id.recalc &= ~ID_RECALC_ALL;
- }
- }
- }
-
- memset(bmain->id_tag_update, 0, sizeof(bmain->id_tag_update));
-
-#ifdef POST_UPDATE_HANDLER_WORKAROUND
- if (have_updated_objects) {
- DAG_id_type_tag(bmain, ID_OB);
- }
-#endif
-}
-
-void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
-{
- if (!DEG_depsgraph_use_legacy()) {
- DEG_id_tag_update_ex(bmain, id, flag);
- return;
- }
-
- if (id == NULL) return;
-
- if (G.debug & G_DEBUG_DEPSGRAPH_TAG) {
- printf("%s: id=%s flag=%d\n", __func__, id->name, flag);
- }
-
- /* tag ID for update */
- if (flag) {
- if (flag & OB_RECALC_OB)
- lib_id_recalc_tag(bmain, id);
- if (flag & (OB_RECALC_DATA | PSYS_RECALC))
- lib_id_recalc_data_tag(bmain, id);
- }
- else
- lib_id_recalc_tag(bmain, id);
-
- /* flag is for objects and particle systems */
- if (flag) {
- Object *ob;
- short idtype = GS(id->name);
-
- if (idtype == ID_OB) {
- /* only quick tag */
- ob = (Object *)id;
- ob->recalc |= (flag & OB_RECALC_ALL);
- }
- else if (idtype == ID_PA) {
- ParticleSystem *psys;
- /* this is weak still, should be done delayed as well */
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- for (psys = ob->particlesystem.first; psys; psys = psys->next) {
- if (&psys->part->id == id) {
- ob->recalc |= (flag & OB_RECALC_ALL);
- psys->recalc |= (flag & PSYS_RECALC);
- lib_id_recalc_tag(bmain, &ob->id);
- lib_id_recalc_data_tag(bmain, &ob->id);
- }
- }
- }
- }
- else {
- /* disable because this is called on various ID types automatically.
- * where printing warning is not useful. for now just ignore */
- /* BLI_assert(!"invalid flag for this 'idtype'"); */
- }
- }
- else if (GS(id->name) == ID_CF) {
- for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
- ModifierData *md = modifiers_findByType(ob, eModifierType_MeshSequenceCache);
-
- if (md) {
- MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
-
- if (mcmd->cache_file && (&mcmd->cache_file->id == id)) {
- ob->recalc |= OB_RECALC_ALL;
- continue;
- }
- }
-
- for (bConstraint *con = ob->constraints.first; con; con = con->next) {
- if (con->type != CONSTRAINT_TYPE_TRANSFORM_CACHE) {
- continue;
- }
-
- bTransformCacheConstraint *data = con->data;
-
- if (data->cache_file && (&data->cache_file->id == id)) {
- ob->recalc |= OB_RECALC_ALL;
- break;
- }
- }
- }
- }
-}
-
-void DAG_id_tag_update(ID *id, short flag)
-{
- DAG_id_tag_update_ex(G.main, id, flag);
-}
-
-void DAG_id_type_tag(Main *bmain, short idtype)
-{
- if (idtype == ID_NT) {
- /* stupid workaround so parent datablocks of nested nodetree get looped
- * over when we loop over tagged datablock types */
- DAG_id_type_tag(bmain, ID_MA);
- DAG_id_type_tag(bmain, ID_TE);
- DAG_id_type_tag(bmain, ID_LA);
- DAG_id_type_tag(bmain, ID_WO);
- DAG_id_type_tag(bmain, ID_SCE);
- }
-
- atomic_fetch_and_or_uint8((uint8_t *)&bmain->id_tag_update[BKE_idcode_to_index(idtype)], 1);
-}
-
-int DAG_id_type_tagged(Main *bmain, short idtype)
-{
- return bmain->id_tag_update[BKE_idcode_to_index(idtype)];
-}
-
-#if 0 // UNUSED
-/* recursively descends tree, each node only checked once */
-/* node is checked to be of type object */
-static int parent_check_node(DagNode *node, int curtime)
-{
- DagAdjList *itA;
-
- node->lasttime = curtime;
-
- if (node->color == DAG_GRAY)
- return DAG_GRAY;
-
- for (itA = node->child; itA; itA = itA->next) {
- if (itA->node->type == ID_OB) {
-
- if (itA->node->color == DAG_GRAY)
- return DAG_GRAY;
-
- /* descend if not done */
- if (itA->node->lasttime != curtime) {
- itA->node->color = parent_check_node(itA->node, curtime);
-
- if (itA->node->color == DAG_GRAY)
- return DAG_GRAY;
- }
- }
- }
-
- return DAG_WHITE;
-}
-#endif
-
-/* ******************* DAG FOR ARMATURE POSE ***************** */
-
-/* we assume its an armature with pose */
-void DAG_pose_sort(Object *ob)
-{
- bPose *pose = ob->pose;
- bPoseChannel *pchan;
- bConstraint *con;
- DagNode *node;
- DagNode *node2, *node3;
- DagNode *rootnode;
- DagForest *dag;
- DagNodeQueue *nqueue;
- DagAdjList *itA;
- ListBase tempbase;
- int skip = 0;
-
- dag = dag_init();
- dag->ugly_hack_sorry = false; /* no ID structs */
-
- rootnode = dag_add_node(dag, NULL); /* node->ob becomes NULL */
-
- /* we add the hierarchy and the constraints */
- for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
- int addtoroot = 1;
-
- node = dag_get_node(dag, pchan);
-
- if (pchan->parent) {
- node2 = dag_get_node(dag, pchan->parent);
- dag_add_relation(dag, node2, node, 0, "Parent Relation");
- addtoroot = 0;
- }
- for (con = pchan->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
- bConstraintTarget *ct;
-
- if (cti && cti->get_constraint_targets) {
- cti->get_constraint_targets(con, &targets);
-
- for (ct = targets.first; ct; ct = ct->next) {
- if (ct->tar == ob && ct->subtarget[0]) {
- bPoseChannel *target = BKE_pose_channel_find_name(ob->pose, ct->subtarget);
- if (target) {
- node2 = dag_get_node(dag, target);
- dag_add_relation(dag, node2, node, 0, "Pose Constraint");
-
- if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
- bKinematicConstraint *data = (bKinematicConstraint *)con->data;
- bPoseChannel *parchan;
- int segcount = 0;
-
- /* exclude tip from chain? */
- if (!(data->flag & CONSTRAINT_IK_TIP))
- parchan = pchan->parent;
- else
- parchan = pchan;
-
- /* Walk to the chain's root */
- while (parchan) {
- node3 = dag_get_node(dag, parchan);
- dag_add_relation(dag, node2, node3, 0, "IK Constraint");
-
- segcount++;
- if (segcount == data->rootbone || segcount > 255) break; /* 255 is weak */
- parchan = parchan->parent;
- }
- }
- }
- }
- }
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 1);
- }
- }
- if (addtoroot == 1) {
- dag_add_relation(dag, rootnode, node, 0, "Root Bone Relation");
- }
- }
-
- dag_check_cycle(dag);
-
- /* now we try to sort... */
- BLI_listbase_clear(&tempbase);
-
- nqueue = queue_create(DAGQUEUEALLOC);
-
- /* tag nodes unchecked */
- for (node = dag->DagNode.first; node; node = node->next)
- node->color = DAG_WHITE;
-
- rootnode->color = DAG_GRAY;
- push_stack(nqueue, rootnode);
-
- while (nqueue->count) {
-
- skip = 0;
- node = get_top_node_queue(nqueue);
-
- itA = node->child;
- while (itA != NULL) {
- if (itA->node->color == DAG_WHITE) {
- itA->node->color = DAG_GRAY;
- push_stack(nqueue, itA->node);
- skip = 1;
- break;
- }
- itA = itA->next;
- }
-
- if (!skip) {
- if (node) {
- node = pop_queue(nqueue);
- if (node->ob == NULL) /* we are done */
- break;
- node->color = DAG_BLACK;
-
- /* put node in new list */
- BLI_remlink(&pose->chanbase, node->ob);
- BLI_addhead(&tempbase, node->ob);
- }
- }
- }
-
- /* temporal correction for circular dependencies */
- while (pose->chanbase.first) {
- pchan = pose->chanbase.first;
- BLI_remlink(&pose->chanbase, pchan);
- BLI_addhead(&tempbase, pchan);
-
- printf("cyclic %s\n", pchan->name);
- }
-
- pose->chanbase = tempbase;
- queue_delete(nqueue);
-
-// printf("\nordered\n");
-// for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
-// printf(" %s\n", pchan->name);
-// }
-
- free_forest(dag);
- MEM_freeN(dag);
-}
-
-/* ************************ DAG FOR THREADED UPDATE ********************* */
-
-/* Initialize run-time data in the graph needed for traversing it
- * from multiple threads and start threaded tree traversal by adding
- * the root node to the queue.
- *
- * This will mark DAG nodes as object/non-object and will calculate
- * num_pending_parents of nodes (which is how many non-updated parents node
- * have, which helps a lot checking whether node could be scheduled
- * already or not).
- */
-void DAG_threaded_update_begin(Scene *scene,
- void (*func)(void *node, void *user_data),
- void *user_data)
-{
- DagNode *node;
-
- /* We reset num_pending_parents to zero first and tag node as not scheduled yet... */
- for (node = scene->theDag->DagNode.first; node; node = node->next) {
- node->num_pending_parents = 0;
- node->scheduled = false;
- }
-
- /* ... and then iterate over all the nodes and
- * increase num_pending_parents for node childs.
- */
- for (node = scene->theDag->DagNode.first; node; node = node->next) {
- DagAdjList *itA;
-
- for (itA = node->child; itA; itA = itA->next) {
- if (itA->node != node) {
- itA->node->num_pending_parents++;
- }
- }
- }
-
- /* Add root nodes to the queue. */
- BLI_spin_lock(&threaded_update_lock);
- for (node = scene->theDag->DagNode.first; node; node = node->next) {
- if (node->num_pending_parents == 0) {
- node->scheduled = true;
- func(node, user_data);
- }
- }
- BLI_spin_unlock(&threaded_update_lock);
-}
-
-/* This function is called when handling node is done.
- *
- * This function updates num_pending_parents for all childs and
- * schedules them if they're ready.
- */
-void DAG_threaded_update_handle_node_updated(void *node_v,
- void (*func)(void *node, void *user_data),
- void *user_data)
-{
- DagNode *node = node_v;
- DagAdjList *itA;
-
- for (itA = node->child; itA; itA = itA->next) {
- DagNode *child_node = itA->node;
- if (child_node != node) {
- atomic_sub_and_fetch_uint32(&child_node->num_pending_parents, 1);
-
- if (child_node->num_pending_parents == 0) {
- bool need_schedule;
-
- BLI_spin_lock(&threaded_update_lock);
- need_schedule = child_node->scheduled == false;
- child_node->scheduled = true;
- BLI_spin_unlock(&threaded_update_lock);
-
- if (need_schedule) {
- func(child_node, user_data);
- }
- }
- }
- }
-}
-
-/* ************************ DAG DEBUGGING ********************* */
-
-void DAG_print_dependencies(Main *bmain, Scene *scene, Object *ob)
-{
- /* utility for debugging dependencies */
- dag_print_dependencies = 1;
-
- if (ob && (ob->mode & OB_MODE_POSE)) {
- printf("\nDEPENDENCY RELATIONS for %s\n\n", ob->id.name + 2);
- DAG_pose_sort(ob);
- }
- else {
- printf("\nDEPENDENCY RELATIONS for %s\n\n", scene->id.name + 2);
- DAG_scene_relations_rebuild(bmain, scene);
- }
-
- dag_print_dependencies = 0;
-}
-
-/* ************************ DAG querying ********************* */
-
-/* Will return Object ID if node represents Object,
- * and will return NULL otherwise.
- */
-Object *DAG_get_node_object(void *node_v)
-{
- DagNode *node = node_v;
-
- if (node->type == ID_OB) {
- return node->ob;
- }
-
- return NULL;
-}
-
-/* Returns node name, used for debug output only, atm. */
-const char *DAG_get_node_name(Scene *scene, void *node_v)
-{
- DagNode *node = node_v;
-
- return dag_node_name(scene->theDag, node);
-}
-
-short DAG_get_eval_flags_for_object(Scene *scene, void *object)
-{
- DagNode *node;
-
- if (!DEG_depsgraph_use_legacy()) {
- return DEG_get_eval_flags_for_id(scene->depsgraph, (ID *)object);
- }
-
- if (scene->theDag == NULL) {
- /* Happens when converting objects to mesh from a python script
- * after modifying scene graph.
- *
- * Currently harmless because it's only called for temporary
- * objects which are out of the DAG anyway.
- */
- return 0;
- }
-
- node = dag_find_node(scene->theDag, object);
-
- if (node) {
- return node->eval_flags;
- }
- else {
- /* Happens when external render engine exports temporary objects
- * which are not in the DAG.
- */
-
- /* TODO(sergey): Doublecheck objects with Curve Deform exports all fine. */
-
- /* TODO(sergey): Weak but currently we can't really access proper DAG from
- * the modifiers stack. This is because in most cases modifier is to use
- * the foreground scene, but to access evaluation flags we need to know
- * active background scene, which we don't know.
- */
- if (scene->set) {
- return DAG_get_eval_flags_for_object(scene->set, object);
- }
- return 0;
- }
-}
-
-bool DAG_is_acyclic(Scene *scene)
-{
- return scene->theDag->is_acyclic;
-}
-
-#else
-
-/* *********************************************************************
- * Stubs to avoid linking issues and make sure legacy crap is not used *
- * *********************************************************************
- */
-
-DagNodeQueue *queue_create(int UNUSED(slots))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-void queue_raz(DagNodeQueue *UNUSED(queue))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-void queue_delete(DagNodeQueue *UNUSED(queue))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-void push_queue(DagNodeQueue *UNUSED(queue), DagNode *UNUSED(node))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-void push_stack(DagNodeQueue *UNUSED(queue), DagNode *UNUSED(node))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-DagNode *pop_queue(DagNodeQueue *UNUSED(queue))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-DagNode *get_top_node_queue(DagNodeQueue *UNUSED(queue))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-DagForest *dag_init(void)
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-DagForest *build_dag(Main *UNUSED(bmain),
- Scene *UNUSED(sce),
- short UNUSED(mask))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-void free_forest(DagForest *UNUSED(Dag))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-DagNode *dag_find_node(DagForest *UNUSED(forest), void *UNUSED(fob))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-DagNode *dag_add_node(DagForest *UNUSED(forest), void *UNUSED(fob))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-DagNode *dag_get_node(DagForest *UNUSED(forest), void *UNUSED(fob))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-DagNode *dag_get_sub_node(DagForest *UNUSED(forest), void *UNUSED(fob))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-void dag_add_relation(DagForest *UNUSED(forest),
- DagNode *UNUSED(fob1),
- DagNode *UNUSED(fob2),
- short UNUSED(rel),
- const char *UNUSED(name))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-/* debug test functions */
-
-void graph_print_queue(DagNodeQueue *UNUSED(nqueue))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-void graph_print_queue_dist(DagNodeQueue *UNUSED(nqueue))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-void graph_print_adj_list(DagForest *UNUSED(dag))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-void DAG_scene_flush_update(Main *UNUSED(bmain),
- Scene *UNUSED(sce),
- unsigned int UNUSED(lay),
- const short UNUSED(time))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-void DAG_scene_update_flags(Main *UNUSED(bmain),
- Scene *UNUSED(scene),
- unsigned int UNUSED(lay),
- const bool UNUSED(do_time),
- const bool UNUSED(do_invisible_flush))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-/* ******************* DAG FOR ARMATURE POSE ***************** */
-
-void DAG_pose_sort(Object *UNUSED(ob))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
-}
-
-/* ************************ DAG FOR THREADED UPDATE ********************* */
-
-void DAG_threaded_update_begin(Scene *UNUSED(scene),
- void (*func)(void *node, void *user_data),
- void *UNUSED(user_data))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- (void)func;
-}
-
-void DAG_threaded_update_handle_node_updated(void *UNUSED(node_v),
- void (*func)(void *node, void *user_data),
- void *UNUSED(user_data))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- (void)func;
-}
-
-/* ************************ DAG querying ********************* */
-
-Object *DAG_get_node_object(void *UNUSED(node_v))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return NULL;
-}
-
-const char *DAG_get_node_name(Scene *UNUSED(scene), void *UNUSED(node_v))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return "INVALID";
-}
-
-bool DAG_is_acyclic(Scene *UNUSED(scene))
-{
- BLI_assert(!"Should not be used with new dependnecy graph");
- return false;
-}
-
-/* ************************************
- * This functions are to be supported *
- * ************************************
- */
-
-void DAG_init(void)
-{
- DEG_register_node_types();
-}
-
-void DAG_exit(void)
-{
- DEG_free_node_types();
-}
-
-/* ************************ API *********************** */
-
-void DAG_editors_update_cb(DEG_EditorUpdateIDCb id_func,
- DEG_EditorUpdateSceneCb scene_func,
- DEG_EditorUpdateScenePreCb scene_func_pre)
-{
- DEG_editors_set_update_cb(id_func, scene_func, scene_func_pre);
-}
-
-void DAG_editors_update_pre(Main *bmain, Scene *scene, bool time)
-{
- DEG_editors_update_pre(bmain, scene, time);
-}
-
-/* Tag all relations for update. */
-void DAG_relations_tag_update(Main *bmain)
-{
- DEG_relations_tag_update(bmain);
-}
-
-/* Rebuild dependency graph only for a given scene. */
-void DAG_scene_relations_rebuild(Main *bmain, Scene *scene)
-{
- DEG_scene_relations_rebuild(bmain, scene);
-}
-
-/* Create dependency graph if it was cleared or didn't exist yet. */
-void DAG_scene_relations_update(Main *bmain, Scene *scene)
-{
- DEG_scene_relations_update(bmain, scene);
-}
-
-void DAG_scene_relations_validate(Main *bmain, Scene *scene)
-{
- DEG_debug_scene_relations_validate(bmain, scene);
-}
-
-void DAG_scene_free(Scene *scene)
-{
- DEG_scene_graph_free(scene);
-}
-
-void DAG_on_visible_update(Main *bmain, const bool do_time)
-{
- DEG_on_visible_update(bmain, do_time);
-}
-
-void DAG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
-{
- DEG_ids_check_recalc(bmain, scene, time);
-}
-
-void DAG_id_tag_update(ID *id, short flag)
-{
- DEG_id_tag_update_ex(G.main, id, flag);
-}
-
-void DAG_id_tag_update_ex(Main *bmain, ID *id, short flag)
-{
- DEG_id_tag_update_ex(bmain, id, flag);
-}
-
-void DAG_id_type_tag(Main *bmain, short idtype)
-{
- DEG_id_type_tag(bmain, idtype);
-}
-
-int DAG_id_type_tagged(Main *bmain, short idtype)
-{
- return DEG_id_type_tagged(bmain, idtype);
-}
-
-void DAG_ids_clear_recalc(Main *bmain)
-{
- DEG_ids_clear_recalc(bmain);
-}
-
-short DAG_get_eval_flags_for_object(Scene *scene, void *object)
-{
- return DEG_get_eval_flags_for_id(scene->depsgraph, (ID *)object);
-}
-
-void DAG_ids_flush_tagged(Main *bmain)
-{
- DEG_ids_flush_tagged(bmain);
-}
-
-/* ************************ DAG DEBUGGING ********************* */
-
-void DAG_print_dependencies(Main *UNUSED(bmain),
- Scene *scene,
- Object *UNUSED(ob))
-{
- DEG_debug_relations_graphviz(scene->depsgraph, stdout, "Depsgraph");
-}
-
-#endif
diff --git a/source/blender/blenkernel/intern/displist.c b/source/blender/blenkernel/intern/displist.c
index 8433634f749..fa996b8f73e 100644
--- a/source/blender/blenkernel/intern/displist.c
+++ b/source/blender/blenkernel/intern/displist.c
@@ -48,7 +48,6 @@
#include "BLI_utildefines.h"
#include "BKE_global.h"
-#include "BKE_depsgraph.h"
#include "BKE_displist.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_object.h"
@@ -63,6 +62,9 @@
#include "BLI_sys_types.h" // for intptr_t support
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
static void boundbox_displist_object(Object *ob);
void BKE_displist_elem_free(DispList *dl)
@@ -679,7 +681,7 @@ static void curve_to_filledpoly(Curve *cu, ListBase *UNUSED(nurb), ListBase *dis
* - first point left, last point right
* - based on subdivided points in original curve, not on points in taper curve (still)
*/
-static float displist_calc_taper(Scene *scene, Object *taperobj, float fac)
+static float displist_calc_taper(Depsgraph *depsgraph, Scene *scene, Object *taperobj, float fac)
{
DispList *dl;
@@ -688,7 +690,7 @@ static float displist_calc_taper(Scene *scene, Object *taperobj, float fac)
dl = taperobj->curve_cache ? taperobj->curve_cache->disp.first : NULL;
if (dl == NULL) {
- BKE_displist_make_curveTypes(scene, taperobj, 0);
+ BKE_displist_make_curveTypes(depsgraph, scene, taperobj, 0);
dl = taperobj->curve_cache->disp.first;
}
if (dl) {
@@ -719,14 +721,14 @@ static float displist_calc_taper(Scene *scene, Object *taperobj, float fac)
return 1.0;
}
-float BKE_displist_calc_taper(Scene *scene, Object *taperobj, int cur, int tot)
+float BKE_displist_calc_taper(Depsgraph *depsgraph, Scene *scene, Object *taperobj, int cur, int tot)
{
float fac = ((float)cur) / (float)(tot - 1);
- return displist_calc_taper(scene, taperobj, fac);
+ return displist_calc_taper(depsgraph, scene, taperobj, fac);
}
-void BKE_displist_make_mball(EvaluationContext *eval_ctx, Scene *scene, Object *ob)
+void BKE_displist_make_mball(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
if (!ob || ob->type != OB_MBALL)
return;
@@ -739,7 +741,7 @@ void BKE_displist_make_mball(EvaluationContext *eval_ctx, Scene *scene, Object *
ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for MBall");
}
- BKE_mball_polygonize(eval_ctx, scene, ob, &ob->curve_cache->disp);
+ BKE_mball_polygonize(depsgraph, scene, ob, &ob->curve_cache->disp);
BKE_mball_texspace_calc(ob);
object_deform_mball(ob, &ob->curve_cache->disp);
@@ -749,9 +751,9 @@ void BKE_displist_make_mball(EvaluationContext *eval_ctx, Scene *scene, Object *
}
}
-void BKE_displist_make_mball_forRender(EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase)
+void BKE_displist_make_mball_forRender(Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase)
{
- BKE_mball_polygonize(eval_ctx, scene, ob, dispbase);
+ BKE_mball_polygonize(depsgraph, scene, ob, dispbase);
BKE_mball_texspace_calc(ob);
object_deform_mball(ob, dispbase);
@@ -799,8 +801,9 @@ static ModifierData *curve_get_tessellate_point(Scene *scene, Object *ob,
return pretessellatePoint;
}
-static void curve_calc_modifiers_pre(Scene *scene, Object *ob, ListBase *nurb,
- const bool for_render, const bool use_render_resolution)
+static void curve_calc_modifiers_pre(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *nurb,
+ const bool for_render, const bool use_render_resolution)
{
VirtualModifierData virtualModifierData;
ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
@@ -824,6 +827,8 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, ListBase *nurb,
else
required_mode = eModifierMode_Realtime;
+ const ModifierEvalContext mectx = {depsgraph, ob, app_flag};
+
pretessellatePoint = curve_get_tessellate_point(scene, ob, use_render_resolution, editmode);
if (editmode)
@@ -857,7 +862,7 @@ static void curve_calc_modifiers_pre(Scene *scene, Object *ob, ListBase *nurb,
deformedVerts = BKE_curve_nurbs_vertexCos_get(nurb, &numVerts);
}
- mti->deformVerts(md, ob, NULL, deformedVerts, numVerts, app_flag);
+ modifier_deformVerts_DM_deprecated(md, &mectx, NULL, deformedVerts, numVerts);
if (md == pretessellatePoint)
break;
@@ -909,9 +914,10 @@ static void displist_apply_allverts(ListBase *dispbase, float (*allverts)[3])
}
}
-static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *nurb,
- ListBase *dispbase, DerivedMesh **r_dm_final,
- const bool for_render, const bool use_render_resolution)
+static void curve_calc_modifiers_post(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *nurb,
+ ListBase *dispbase, DerivedMesh **r_dm_final,
+ const bool for_render, const bool use_render_resolution)
{
VirtualModifierData virtualModifierData;
ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
@@ -931,6 +937,11 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *nurb,
else
required_mode = eModifierMode_Realtime;
+ const ModifierEvalContext mectx_deform = {depsgraph, ob,
+ editmode ? app_flag | MOD_APPLY_USECACHE : app_flag};
+ const ModifierEvalContext mectx_apply = {depsgraph, ob,
+ useCache ? app_flag | MOD_APPLY_USECACHE : app_flag};
+
pretessellatePoint = curve_get_tessellate_point(scene, ob, use_render_resolution, editmode);
if (editmode)
@@ -946,8 +957,6 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *nurb,
for (; md; md = md->next) {
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
- ModifierApplyFlag appf = app_flag;
-
md->scene = scene;
if (!modifier_isEnabled(scene, md, required_mode))
@@ -956,8 +965,6 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *nurb,
if (mti->type == eModifierTypeType_OnlyDeform ||
(mti->type == eModifierTypeType_DeformOrConstruct && !dm))
{
- if (editmode)
- appf |= MOD_APPLY_USECACHE;
if (dm) {
if (!vertCos) {
totvert = dm->getNumVerts(dm);
@@ -965,14 +972,14 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *nurb,
dm->getVertCos(dm, vertCos);
}
- mti->deformVerts(md, ob, dm, vertCos, totvert, appf);
+ modifier_deformVerts_DM_deprecated(md, &mectx_deform, dm, vertCos, totvert);
}
else {
if (!vertCos) {
vertCos = displist_get_allverts(dispbase, &totvert);
}
- mti->deformVerts(md, ob, NULL, vertCos, totvert, appf);
+ modifier_deformVerts_DM_deprecated(md, &mectx_deform, NULL, vertCos, totvert);
}
}
else {
@@ -1011,10 +1018,7 @@ static void curve_calc_modifiers_post(Scene *scene, Object *ob, ListBase *nurb,
vertCos = NULL;
}
- if (useCache)
- appf |= MOD_APPLY_USECACHE;
-
- ndm = modwrap_applyModifier(md, ob, dm, appf);
+ ndm = modwrap_applyModifier(md, &mectx_apply, dm);
if (ndm) {
/* Modifier returned a new derived mesh */
@@ -1091,13 +1095,13 @@ static void displist_surf_indices(DispList *dl)
}
}
-static DerivedMesh *create_orco_dm(Scene *scene, Object *ob)
+static DerivedMesh *create_orco_dm(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
DerivedMesh *dm;
ListBase disp = {NULL, NULL};
/* OrcoDM should be created from underformed disp lists */
- BKE_displist_make_curveTypes_forOrco(scene, ob, &disp);
+ BKE_displist_make_curveTypes_forOrco(depsgraph, scene, ob, &disp);
dm = CDDM_from_curve_displist(ob, &disp);
BKE_displist_free(&disp);
@@ -1135,8 +1139,9 @@ static void add_orco_dm(Object *ob, DerivedMesh *dm, DerivedMesh *orcodm)
DM_add_vert_layer(dm, CD_ORCO, CD_ASSIGN, orco);
}
-static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *dm_final,
- const bool for_render, const bool use_render_resolution)
+static void curve_calc_orcodm(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm_final,
+ const bool for_render, const bool use_render_resolution)
{
/* this function represents logic of mesh's orcodm calculation
* for displist-based objects
@@ -1157,6 +1162,8 @@ static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *dm_final,
else
required_mode = eModifierMode_Realtime;
+ const ModifierEvalContext mectx = {depsgraph, ob, app_flag};
+
pretessellatePoint = curve_get_tessellate_point(scene, ob, use_render_resolution, editmode);
if (editmode)
@@ -1173,7 +1180,7 @@ static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *dm_final,
* This means we can create ORCO DM in advance and assume it's
* never NULL.
*/
- orcodm = create_orco_dm(scene, ob);
+ orcodm = create_orco_dm(depsgraph, scene, ob);
for (; md; md = md->next) {
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
@@ -1185,7 +1192,7 @@ static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *dm_final,
if (mti->type != eModifierTypeType_Constructive)
continue;
- ndm = modwrap_applyModifier(md, ob, orcodm, app_flag);
+ ndm = modwrap_applyModifier(md, &mectx, orcodm);
if (ndm) {
/* if the modifier returned a new dm, release the old one */
@@ -1202,9 +1209,10 @@ static void curve_calc_orcodm(Scene *scene, Object *ob, DerivedMesh *dm_final,
orcodm->release(orcodm);
}
-void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
- DerivedMesh **r_dm_final,
- const bool for_render, const bool for_orco, const bool use_render_resolution)
+void BKE_displist_make_surf(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase,
+ DerivedMesh **r_dm_final,
+ const bool for_render, const bool for_orco, const bool use_render_resolution)
{
ListBase nubase = {NULL, NULL};
Nurb *nu;
@@ -1221,7 +1229,7 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
}
if (!for_orco)
- curve_calc_modifiers_pre(scene, ob, &nubase, for_render, use_render_resolution);
+ curve_calc_modifiers_pre(depsgraph, scene, ob, &nubase, for_render, use_render_resolution);
for (nu = nubase.first; nu; nu = nu->next) {
if ((for_render || nu->hide == 0) && BKE_nurb_check_valid_uv(nu)) {
@@ -1288,7 +1296,7 @@ void BKE_displist_make_surf(Scene *scene, Object *ob, ListBase *dispbase,
if (!for_orco) {
BKE_nurbList_duplicate(&ob->curve_cache->deformed_nurbs, &nubase);
- curve_calc_modifiers_post(scene, ob, &nubase, dispbase, r_dm_final,
+ curve_calc_modifiers_post(depsgraph, scene, ob, &nubase, dispbase, r_dm_final,
for_render, use_render_resolution);
}
@@ -1514,9 +1522,10 @@ static void calc_bevfac_mapping(Curve *cu, BevList *bl, Nurb *nu,
}
}
-static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispbase,
- DerivedMesh **r_dm_final,
- const bool for_render, const bool for_orco, const bool use_render_resolution)
+static void do_makeDispListCurveTypes(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase,
+ DerivedMesh **r_dm_final,
+ const bool for_render, const bool for_orco, const bool use_render_resolution)
{
Curve *cu = ob->data;
@@ -1524,7 +1533,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
if (!ELEM(ob->type, OB_SURF, OB_CURVE, OB_FONT)) return;
if (ob->type == OB_SURF) {
- BKE_displist_make_surf(scene, ob, dispbase, r_dm_final, for_render, for_orco, use_render_resolution);
+ BKE_displist_make_surf(depsgraph, scene, ob, dispbase, r_dm_final, for_render, for_orco, use_render_resolution);
}
else if (ELEM(ob->type, OB_CURVE, OB_FONT)) {
ListBase dlbev;
@@ -1549,12 +1558,12 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
}
if (!for_orco)
- curve_calc_modifiers_pre(scene, ob, &nubase, for_render, use_render_resolution);
+ curve_calc_modifiers_pre(depsgraph, scene, ob, &nubase, for_render, use_render_resolution);
BKE_curve_bevelList_make(ob, &nubase, for_render != false);
/* If curve has no bevel will return nothing */
- BKE_curve_bevel_make(scene, ob, &dlbev, for_render, use_render_resolution);
+ BKE_curve_bevel_make(depsgraph, scene, ob, &dlbev, for_render, use_render_resolution);
/* no bevel or extrude, and no width correction? */
if (!dlbev.first && cu->width == 1.0f) {
@@ -1689,7 +1698,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
taper_fac -= (1.0f - lastblend) / len;
}
- fac = displist_calc_taper(scene, cu->taperobj, taper_fac);
+ fac = displist_calc_taper(depsgraph, scene, cu->taperobj, taper_fac);
}
if (bevp->split_tag) {
@@ -1742,7 +1751,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
if (!for_orco) {
if ((cu->flag & CU_PATH) ||
- DAG_get_eval_flags_for_object(scene, ob) & DAG_EVAL_NEED_CURVE_PATH)
+ DEG_get_eval_flags_for_id(depsgraph, &ob->id) & DAG_EVAL_NEED_CURVE_PATH)
{
calc_curvepath(ob, &nubase);
}
@@ -1750,7 +1759,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
if (!for_orco) {
BKE_nurbList_duplicate(&ob->curve_cache->deformed_nurbs, &nubase);
- curve_calc_modifiers_post(scene, ob, &nubase, dispbase, r_dm_final, for_render, use_render_resolution);
+ curve_calc_modifiers_post(depsgraph, scene, ob, &nubase, dispbase, r_dm_final, for_render, use_render_resolution);
}
if (cu->flag & CU_DEFORM_FILL && !ob->derivedFinal) {
@@ -1761,7 +1770,7 @@ static void do_makeDispListCurveTypes(Scene *scene, Object *ob, ListBase *dispba
}
}
-void BKE_displist_make_curveTypes(Scene *scene, Object *ob, const bool for_orco)
+void BKE_displist_make_curveTypes(Depsgraph *depsgraph, Scene *scene, Object *ob, const bool for_orco)
{
ListBase *dispbase;
@@ -1779,35 +1788,38 @@ void BKE_displist_make_curveTypes(Scene *scene, Object *ob, const bool for_orco)
dispbase = &(ob->curve_cache->disp);
- do_makeDispListCurveTypes(scene, ob, dispbase, &ob->derivedFinal, 0, for_orco, 0);
+ do_makeDispListCurveTypes(depsgraph, scene, ob, dispbase, &ob->derivedFinal, 0, for_orco, 0);
boundbox_displist_object(ob);
}
-void BKE_displist_make_curveTypes_forRender(Scene *scene, Object *ob, ListBase *dispbase,
- DerivedMesh **r_dm_final, const bool for_orco,
- const bool use_render_resolution)
+void BKE_displist_make_curveTypes_forRender(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase,
+ DerivedMesh **r_dm_final, const bool for_orco,
+ const bool use_render_resolution)
{
if (ob->curve_cache == NULL) {
ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve");
}
- do_makeDispListCurveTypes(scene, ob, dispbase, r_dm_final, true, for_orco, use_render_resolution);
+ do_makeDispListCurveTypes(depsgraph, scene, ob, dispbase, r_dm_final, true, for_orco, use_render_resolution);
}
-void BKE_displist_make_curveTypes_forOrco(struct Scene *scene, struct Object *ob, struct ListBase *dispbase)
+void BKE_displist_make_curveTypes_forOrco(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase)
{
if (ob->curve_cache == NULL) {
ob->curve_cache = MEM_callocN(sizeof(CurveCache), "CurveCache for Curve");
}
- do_makeDispListCurveTypes(scene, ob, dispbase, NULL, 1, 1, 1);
+ do_makeDispListCurveTypes(depsgraph, scene, ob, dispbase, NULL, 1, 1, 1);
}
/* add Orco layer to the displist object which has got derived mesh and return orco */
-float *BKE_displist_make_orco(Scene *scene, Object *ob, DerivedMesh *dm_final,
- const bool for_render,
- const bool use_render_resolution)
+float *BKE_displist_make_orco(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm_final,
+ const bool for_render,
+ const bool use_render_resolution)
{
float *orco;
@@ -1815,7 +1827,7 @@ float *BKE_displist_make_orco(Scene *scene, Object *ob, DerivedMesh *dm_final,
dm_final = ob->derivedFinal;
if (!dm_final->getVertDataArray(dm_final, CD_ORCO)) {
- curve_calc_orcodm(scene, ob, dm_final, for_render, use_render_resolution);
+ curve_calc_orcodm(depsgraph, scene, ob, dm_final, for_render, use_render_resolution);
}
orco = dm_final->getVertDataArray(dm_final, CD_ORCO);
diff --git a/source/blender/blenkernel/intern/dynamicpaint.c b/source/blender/blenkernel/intern/dynamicpaint.c
index c34bd2493eb..0135abc7edb 100644
--- a/source/blender/blenkernel/intern/dynamicpaint.c
+++ b/source/blender/blenkernel/intern/dynamicpaint.c
@@ -74,6 +74,9 @@
#include "BKE_pointcache.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
/* for image output */
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -486,36 +489,27 @@ static void scene_setSubframe(Scene *scene, float subframe)
scene->r.subframe = subframe;
}
-static int surface_getBrushFlags(DynamicPaintSurface *surface, const Scene *scene)
+static int surface_getBrushFlags(DynamicPaintSurface *surface, const ViewLayer *view_layer)
{
Base *base = NULL;
- GroupObject *go = NULL;
Object *brushObj = NULL;
ModifierData *md = NULL;
int flags = 0;
if (surface->brush_group)
- go = surface->brush_group->gobject.first;
+ base = FIRSTBASE(surface->brush_group->view_layer);
else
- base = scene->base.first;
+ base = FIRSTBASE(view_layer);
- while (base || go) {
+ while (base) {
brushObj = NULL;
/* select object */
- if (surface->brush_group) {
- if (go->ob)
- brushObj = go->ob;
- }
- else {
- brushObj = base->object;
- }
+ brushObj = base->object;
- if (surface->brush_group)
- go = go->next;
- else
- base = base->next;
+ /* next item */
+ base = base->next;
if (!brushObj) {
continue;
@@ -537,11 +531,6 @@ static int surface_getBrushFlags(DynamicPaintSurface *surface, const Scene *scen
return flags;
}
-static int brush_usesMaterial(const DynamicPaintBrushSettings *brush, const Scene *scene)
-{
- return ((brush->flags & MOD_DPAINT_USE_MATERIAL) && (!BKE_scene_use_new_shading_nodes(scene)));
-}
-
/* check whether two bounds intersect */
static bool boundsIntersect(Bounds3D *b1, Bounds3D *b2)
{
@@ -1102,7 +1091,6 @@ bool dynamicPaint_createType(struct DynamicPaintModifierData *pmd, int type, str
brush->flags = MOD_DPAINT_ABS_ALPHA | MOD_DPAINT_RAMP_ALPHA;
brush->collision = MOD_DPAINT_COL_VOLUME;
- brush->mat = NULL;
brush->r = 0.15f;
brush->g = 0.4f;
brush->b = 0.8f;
@@ -1242,7 +1230,6 @@ void dynamicPaint_Modifier_copy(struct DynamicPaintModifierData *pmd, struct Dyn
t_brush->flags = brush->flags;
t_brush->collision = brush->collision;
- t_brush->mat = brush->mat;
t_brush->r = brush->r;
t_brush->g = brush->g;
t_brush->b = brush->b;
@@ -2071,7 +2058,9 @@ static void canvas_copyDerivedMesh(DynamicPaintCanvasSettings *canvas, DerivedMe
/*
* Updates derived mesh copy and processes dynamic paint step / caches.
*/
-static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm)
+static void dynamicPaint_frameUpdate(
+ DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, DerivedMesh *dm)
{
if (pmd->canvas) {
DynamicPaintCanvasSettings *canvas = pmd->canvas;
@@ -2134,7 +2123,7 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene
else if (can_simulate) {
/* calculate surface frame */
canvas->flags |= MOD_DPAINT_BAKING;
- dynamicPaint_calculateFrame(surface, scene, ob, current_frame);
+ dynamicPaint_calculateFrame(surface, depsgraph, scene, ob, current_frame);
canvas->flags &= ~MOD_DPAINT_BAKING;
/* restore canvas derivedmesh if required */
@@ -2153,13 +2142,15 @@ static void dynamicPaint_frameUpdate(DynamicPaintModifierData *pmd, Scene *scene
}
/* Modifier call. Processes dynamic paint modifier step. */
-DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scene *scene, Object *ob, DerivedMesh *dm)
+DerivedMesh *dynamicPaint_Modifier_do(
+ DynamicPaintModifierData *pmd, struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, DerivedMesh *dm)
{
if (pmd->canvas) {
DerivedMesh *ret;
/* Update canvas data for a new frame */
- dynamicPaint_frameUpdate(pmd, scene, ob, dm);
+ dynamicPaint_frameUpdate(pmd, depsgraph, scene, ob, dm);
/* Return output mesh */
ret = dynamicPaint_Modifier_apply(pmd, ob, dm);
@@ -2168,7 +2159,7 @@ DerivedMesh *dynamicPaint_Modifier_do(DynamicPaintModifierData *pmd, Scene *scen
}
else {
/* Update canvas data for a new frame */
- dynamicPaint_frameUpdate(pmd, scene, ob, dm);
+ dynamicPaint_frameUpdate(pmd, depsgraph, scene, ob, dm);
/* Return output mesh */
return dynamicPaint_Modifier_apply(pmd, ob, dm);
@@ -3338,91 +3329,6 @@ void dynamicPaint_outputSurfaceImage(DynamicPaintSurface *surface, char *filenam
}
-/***************************** Material / Texture Sampling ******************************/
-
-/* stores a copy of required materials to allow doing adjustments
- * without interfering the render/preview */
-typedef struct BrushMaterials {
- Material *mat;
- Material **ob_mats;
- int tot;
-} BrushMaterials;
-
-/* Initialize materials for brush object:
- * Calculates inverse matrices for linked objects, updates
- * volume caches etc. */
-static void dynamicPaint_updateBrushMaterials(Object *brushOb, Material *ui_mat, Scene *scene, BrushMaterials *bMats)
-{
- /* Calculate inverse transformation matrix
- * for this object */
- invert_m4_m4(brushOb->imat, brushOb->obmat);
- copy_m4_m4(brushOb->imat_ren, brushOb->imat);
-
- /* Now process every material linked to this brush object */
- if ((ui_mat == NULL) && brushOb->mat && brushOb->totcol) {
- int i, tot = (*give_totcolp(brushOb));
-
- /* allocate material pointer array */
- if (tot) {
- bMats->ob_mats = MEM_callocN(sizeof(Material *) * (tot), "BrushMaterials");
- for (i = 0; i < tot; i++) {
- bMats->ob_mats[i] = RE_sample_material_init(give_current_material(brushOb, (i + 1)), scene);
- }
- }
- bMats->tot = tot;
- }
- else {
- bMats->mat = RE_sample_material_init(ui_mat, scene);
- }
-}
-
-/* free all data allocated by dynamicPaint_updateBrushMaterials() */
-static void dynamicPaint_freeBrushMaterials(BrushMaterials *bMats)
-{
- /* Now process every material linked to this brush object */
- if (bMats->ob_mats) {
- int i;
- for (i = 0; i < bMats->tot; i++) {
- RE_sample_material_free(bMats->ob_mats[i]);
- }
- MEM_freeN(bMats->ob_mats);
- }
- else if (bMats->mat) {
- RE_sample_material_free(bMats->mat);
- }
-}
-
-/*
- * Get material diffuse color and alpha (including linked textures) in given coordinates
- */
-static void dynamicPaint_doMaterialTex(
- const BrushMaterials *bMats, float color[3], float *alpha, Object *brushOb,
- const float volume_co[3], const float surface_co[3],
- int triIndex, DerivedMesh *orcoDm)
-{
- Material *mat = bMats->mat;
-
- const MLoopTri *mlooptri = orcoDm->getLoopTriArray(orcoDm);
- const MPoly *mpoly = orcoDm->getPolyArray(orcoDm);
-
- /* If no material defined, use the one assigned to the mesh face */
- if (mat == NULL) {
- if (bMats->ob_mats) {
- int mat_nr = mpoly[mlooptri[triIndex].poly].mat_nr;
- if (mat_nr >= (*give_totcolp(brushOb)))
- return;
- mat = bMats->ob_mats[mat_nr];
- if (mat == NULL)
- return; /* No material assigned */
- }
- else {
- return;
- }
- }
- RE_sample_material_color(mat, color, alpha, volume_co, surface_co, triIndex, orcoDm, brushOb);
-}
-
-
/***************************** Ray / Nearest Point Utils ******************************/
@@ -3743,7 +3649,8 @@ static void dynamic_paint_brush_velocity_compute_cb(
}
static void dynamicPaint_brushMeshCalculateVelocity(
- Scene *scene, Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale)
+ struct Depsgraph *depsgraph, Scene *scene,
+ Object *ob, DynamicPaintBrushSettings *brush, Vec3f **brushVel, float timescale)
{
float prev_obmat[4][4];
DerivedMesh *dm_p, *dm_c;
@@ -3765,7 +3672,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(
scene->r.subframe = prev_sfra;
BKE_object_modifier_update_subframe(
- scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
+ depsgraph, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
dm_p = CDDM_copy(brush->dm);
numOfVerts_p = dm_p->getNumVerts(dm_p);
mvert_p = dm_p->getVertArray(dm_p);
@@ -3776,7 +3683,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(
scene->r.subframe = cur_sfra;
BKE_object_modifier_update_subframe(
- scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
+ depsgraph, scene, ob, true, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
dm_c = brush->dm;
numOfVerts_c = dm_c->getNumVerts(dm_c);
mvert_c = dm_p->getVertArray(dm_c);
@@ -3807,7 +3714,7 @@ static void dynamicPaint_brushMeshCalculateVelocity(
}
/* calculate velocity for object center point */
-static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob, Vec3f *brushVel, float timescale)
+static void dynamicPaint_brushObjectCalculateVelocity(struct Depsgraph *depsgraph, Scene *scene, Object *ob, Vec3f *brushVel, float timescale)
{
float prev_obmat[4][4];
float cur_loc[3] = {0.0f}, prev_loc[3] = {0.0f};
@@ -3826,14 +3733,14 @@ static void dynamicPaint_brushObjectCalculateVelocity(Scene *scene, Object *ob,
scene->r.cfra = prev_fra;
scene->r.subframe = prev_sfra;
BKE_object_modifier_update_subframe(
- scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
+ depsgraph, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
copy_m4_m4(prev_obmat, ob->obmat);
/* current frame dm */
scene->r.cfra = cur_fra;
scene->r.subframe = cur_sfra;
BKE_object_modifier_update_subframe(
- scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
+ depsgraph, scene, ob, false, SUBFRAME_RECURSION, BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
/* calculate speed */
mul_m4_v3(prev_obmat, prev_loc);
@@ -3847,7 +3754,6 @@ typedef struct DynamicPaintPaintData {
const DynamicPaintSurface *surface;
const DynamicPaintBrushSettings *brush;
Object *brushOb;
- const BrushMaterials *bMats;
const Scene *scene;
const float timescale;
const int c_index;
@@ -3884,14 +3790,10 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(
VolumeGrid *grid = bData->grid;
const DynamicPaintBrushSettings *brush = data->brush;
- Object *brushOb = data->brushOb;
- const BrushMaterials *bMats = data->bMats;
- const Scene *scene = data->scene;
const float timescale = data->timescale;
const int c_index = data->c_index;
- DerivedMesh *dm = data->dm;
const MVert *mvert = data->mvert;
const MLoop *mloop = data->mloop;
const MLoopTri *mlooptri = data->mlooptri;
@@ -4151,13 +4053,6 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(
sampleColor[1] = brush->g;
sampleColor[2] = brush->b;
- /* Get material+textures color on hit point if required */
- if (brush_usesMaterial(brush, scene)) {
- dynamicPaint_doMaterialTex(bMats, sampleColor, &alpha_factor, brushOb,
- bData->realCoord[bData->s_pos[index] + ss].v,
- hitCoord, hitTri, dm);
- }
-
/* Sample proximity colorband if required */
if ((hit_found == HIT_PROXIMITY) &&
(brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP))
@@ -4205,10 +4100,9 @@ static void dynamic_paint_paint_mesh_cell_point_cb_ex(
}
}
-static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
+static int dynamicPaint_paintMesh(struct Depsgraph *depsgraph, DynamicPaintSurface *surface,
DynamicPaintBrushSettings *brush,
Object *brushOb,
- BrushMaterials *bMats,
Scene *scene,
float timescale)
{
@@ -4221,7 +4115,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
const MLoop *mloop = NULL;
if (brush->flags & MOD_DPAINT_USES_VELOCITY)
- dynamicPaint_brushMeshCalculateVelocity(scene, brushOb, brush, &brushVelocity, timescale);
+ dynamicPaint_brushMeshCalculateVelocity(depsgraph, scene, brushOb, brush, &brushVelocity, timescale);
if (!brush->dm)
return 0;
@@ -4286,7 +4180,7 @@ static int dynamicPaint_paintMesh(DynamicPaintSurface *surface,
/* loop through cell points and process brush */
DynamicPaintPaintData data = {
.surface = surface,
- .brush = brush, .brushOb = brushOb, .bMats = bMats,
+ .brush = brush, .brushOb = brushOb,
.scene = scene, .timescale = timescale, .c_index = c_index,
.dm = dm, .mvert = mvert, .mloop = mloop, .mlooptri = mlooptri,
.brush_radius = brush_radius, .avg_brushNor = avg_brushNor, .brushVelocity = brushVelocity,
@@ -4611,13 +4505,9 @@ static void dynamic_paint_paint_single_point_cb_ex(
const PaintBakeData *bData = sData->bData;
const DynamicPaintBrushSettings *brush = data->brush;
- Object *brushOb = data->brushOb;
- const BrushMaterials *bMats = data->bMats;
- const Scene *scene = data->scene;
const float timescale = data->timescale;
- const MVert *mvert = data->mvert;
const float brush_radius = data->brush_radius;
const Vec3f *brushVelocity = data->brushVelocity;
@@ -4646,17 +4536,6 @@ static void dynamic_paint_paint_single_point_cb_ex(
float depth = 0.0f;
float velocity_val = 0.0f;
- /* material */
- if (brush_usesMaterial(brush, scene)) {
- float alpha_factor = 1.0f;
- float hit_coord[3];
- /* use dummy coord of first vertex */
- mul_v3_m4v3(hit_coord, brushOb->obmat, mvert[0].co);
-
- dynamicPaint_doMaterialTex(bMats, paintColor, &alpha_factor, brushOb,
- bData->realCoord[bData->s_pos[index]].v, hit_coord, 0, brush->dm);
- }
-
/* color ramp */
if (brush->proximity_falloff == MOD_DPAINT_PRFALL_RAMP &&
BKE_colorband_evaluate(brush->paint_ramp, (1.0f - strength), colorband))
@@ -4694,11 +4573,9 @@ static void dynamic_paint_paint_single_point_cb_ex(
paintColor[2] = colorband[2];
}
else {
- if (!brush_usesMaterial(brush, scene)) {
- paintColor[0] = brush->r;
- paintColor[1] = brush->g;
- paintColor[2] = brush->b;
- }
+ paintColor[0] = brush->r;
+ paintColor[1] = brush->g;
+ paintColor[2] = brush->b;
}
}
else if (ELEM(surface->type, MOD_DPAINT_SURFACE_T_DISPLACE, MOD_DPAINT_SURFACE_T_WAVE)) {
@@ -4711,15 +4588,15 @@ static void dynamic_paint_paint_single_point_cb_ex(
}
static int dynamicPaint_paintSinglePoint(
- DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush,
- Object *brushOb, BrushMaterials *bMats, Scene *scene, float timescale)
+ struct Depsgraph *depsgraph, DynamicPaintSurface *surface, float *pointCoord, DynamicPaintBrushSettings *brush,
+ Object *brushOb, Scene *scene, float timescale)
{
PaintSurfaceData *sData = surface->data;
float brush_radius = brush->paint_distance * surface->radius_scale;
Vec3f brushVel;
if (brush->flags & MOD_DPAINT_USES_VELOCITY)
- dynamicPaint_brushObjectCalculateVelocity(scene, brushOb, &brushVel, timescale);
+ dynamicPaint_brushObjectCalculateVelocity(depsgraph, scene, brushOb, &brushVel, timescale);
const MVert *mvert = brush->dm->getVertArray(brush->dm);
@@ -4728,7 +4605,7 @@ static int dynamicPaint_paintSinglePoint(
*/
DynamicPaintPaintData data = {
.surface = surface,
- .brush = brush, .brushOb = brushOb, .bMats = bMats,
+ .brush = brush, .brushOb = brushOb,
.scene = scene, .timescale = timescale,
.mvert = mvert,
.brush_radius = brush_radius, .brushVelocity = &brushVel,
@@ -5041,7 +4918,7 @@ static void dynamic_paint_prepare_effect_cb(
}
static int dynamicPaint_prepareEffectStep(
- DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale)
+ struct Depsgraph *depsgraph, DynamicPaintSurface *surface, Scene *scene, Object *ob, float **force, float timescale)
{
double average_force = 0.0f;
float shrink_speed = 0.0f, spread_speed = 0.0f;
@@ -5052,7 +4929,7 @@ static int dynamicPaint_prepareEffectStep(
/* Init force data if required */
if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) {
- ListBase *effectors = pdInitEffectors(scene, ob, NULL, surface->effector_weights, true);
+ ListBase *effectors = pdInitEffectors(depsgraph, scene, ob, NULL, surface->effector_weights, true);
/* allocate memory for force data (dir vector + strength) */
*force = MEM_mallocN(sData->total_points * 4 * sizeof(float), "PaintEffectForces");
@@ -5884,7 +5761,7 @@ static void dynamic_paint_generate_bake_data_cb(
}
}
-static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Scene *scene, Object *ob)
+static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const ViewLayer *view_layer, Object *ob)
{
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
@@ -5892,7 +5769,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce
int index;
bool new_bdata = false;
const bool do_velocity_data = ((surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) ||
- (surface_getBrushFlags(surface, scene) & BRUSH_USES_VELOCITY));
+ (surface_getBrushFlags(surface, view_layer) & BRUSH_USES_VELOCITY));
const bool do_accel_data = (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) != 0;
int canvasNumOfVerts = dm->getNumVerts(dm);
@@ -6009,7 +5886,7 @@ static int dynamicPaint_generateBakeData(DynamicPaintSurface *surface, const Sce
/*
* Do Dynamic Paint step. Paints scene brush objects of current state/frame to the surface.
*/
-static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *surface, float timescale, float subframe)
+static int dynamicPaint_doStep(struct Depsgraph *depsgraph, Scene *scene, Object *ob, DynamicPaintSurface *surface, float timescale, float subframe)
{
PaintSurfaceData *sData = surface->data;
PaintBakeData *bData = sData->bData;
@@ -6035,9 +5912,9 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
*/
{
Base *base = NULL;
- GroupObject *go = NULL;
Object *brushObj = NULL;
ModifierData *md = NULL;
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
/* backup current scene frame */
int scene_frame = scene->r.cfra;
@@ -6045,25 +5922,17 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
/* either from group or from all objects */
if (surface->brush_group)
- go = surface->brush_group->gobject.first;
+ base = FIRSTBASE(surface->brush_group->view_layer);
else
- base = scene->base.first;
+ base = FIRSTBASE(view_layer);
- while (base || go) {
+ while (base) {
brushObj = NULL;
/* select object */
- if (surface->brush_group) {
- if (go->ob)
- brushObj = go->ob;
- }
- else
- brushObj = base->object;
+ brushObj = base->object;
/* next item */
- if (surface->brush_group)
- go = go->next;
- else
- base = base->next;
+ base = base->next;
if (!brushObj) {
/* skip item */
@@ -6077,7 +5946,6 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
/* make sure we're dealing with a brush */
if (pmd2->brush) {
DynamicPaintBrushSettings *brush = pmd2->brush;
- BrushMaterials bMats = {NULL};
/* calculate brush speed vectors if required */
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT && brush->flags & MOD_DPAINT_DO_SMUDGE) {
@@ -6092,43 +5960,35 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
/* update object data on this subframe */
if (subframe) {
scene_setSubframe(scene, subframe);
- BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION,
+ BKE_object_modifier_update_subframe(depsgraph, scene, brushObj, true, SUBFRAME_RECURSION,
BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
}
- /* Prepare materials if required */
- if (brush_usesMaterial(brush, scene))
- dynamicPaint_updateBrushMaterials(brushObj, brush->mat, scene, &bMats);
+
/* Apply brush on the surface depending on it's collision type */
- /* Particle brush: */
- if (brush->collision == MOD_DPAINT_COL_PSYS) {
- if (brush->psys && brush->psys->part &&
- ELEM(brush->psys->part->type, PART_EMITTER, PART_FLUID) &&
- psys_check_enabled(brushObj, brush->psys, G.is_rendering))
- {
- /* Paint a particle system */
- BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt,
- BKE_scene_frame_get(scene), ADT_RECALC_ANIM);
- dynamicPaint_paintParticles(surface, brush->psys, brush, timescale);
- }
+ if (brush->psys && brush->psys->part &&
+ ELEM(brush->psys->part->type, PART_EMITTER, PART_FLUID) &&
+ psys_check_enabled(brushObj, brush->psys, G.is_rendering))
+ {
+ /* Paint a particle system */
+ BKE_animsys_evaluate_animdata(scene, &brush->psys->part->id, brush->psys->part->adt,
+ BKE_scene_frame_get(scene), ADT_RECALC_ANIM);
+ dynamicPaint_paintParticles(surface, brush->psys, brush, timescale);
}
/* Object center distance: */
- else if (brush->collision == MOD_DPAINT_COL_POINT && brushObj != ob) {
- dynamicPaint_paintSinglePoint(surface, brushObj->loc, brush, brushObj, &bMats, scene, timescale);
+ if (brush->collision == MOD_DPAINT_COL_POINT && brushObj != ob) {
+ dynamicPaint_paintSinglePoint(depsgraph, surface, brushObj->loc, brush, brushObj, scene, timescale);
}
/* Mesh volume/proximity: */
else if (brushObj != ob) {
- dynamicPaint_paintMesh(surface, brush, brushObj, &bMats, scene, timescale);
+ dynamicPaint_paintMesh(depsgraph, surface, brush, brushObj, scene, timescale);
}
- /* free temp material data */
- if (brush_usesMaterial(brush, scene))
- dynamicPaint_freeBrushMaterials(&bMats);
/* reset object to it's original state */
if (subframe) {
scene->r.cfra = scene_frame;
scene->r.subframe = scene_subframe;
- BKE_object_modifier_update_subframe(scene, brushObj, true, SUBFRAME_RECURSION,
+ BKE_object_modifier_update_subframe(depsgraph, scene, brushObj, true, SUBFRAME_RECURSION,
BKE_scene_frame_get(scene), eModifierType_DynamicPaint);
}
@@ -6163,7 +6023,7 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
return setError(canvas, N_("Not enough free memory"));
/* Prepare effects and get number of required steps */
- steps = dynamicPaint_prepareEffectStep(surface, scene, ob, &force, timescale);
+ steps = dynamicPaint_prepareEffectStep(depsgraph, surface, scene, ob, &force, timescale);
for (s = 0; s < steps; s++) {
dynamicPaint_doEffectStep(surface, force, prevPoint, timescale, (float)steps);
}
@@ -6187,7 +6047,9 @@ static int dynamicPaint_doStep(Scene *scene, Object *ob, DynamicPaintSurface *su
/*
* Calculate a single frame and included subframes for surface
*/
-int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Object *cObject, int frame)
+int dynamicPaint_calculateFrame(
+ DynamicPaintSurface *surface, struct Depsgraph *depsgraph,
+ Scene *scene, Object *cObject, int frame)
{
float timescale = 1.0f;
@@ -6196,7 +6058,8 @@ int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Obje
dynamicPaint_applySurfaceDisplace(surface, surface->canvas->dm);
/* update bake data */
- dynamicPaint_generateBakeData(surface, scene, cObject);
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ dynamicPaint_generateBakeData(surface, view_layer, cObject);
/* don't do substeps for first frame */
if (surface->substeps && (frame != surface->start_frame)) {
@@ -6205,10 +6068,10 @@ int dynamicPaint_calculateFrame(DynamicPaintSurface *surface, Scene *scene, Obje
for (st = 1; st <= surface->substeps; st++) {
float subframe = ((float) st) / (surface->substeps + 1);
- if (!dynamicPaint_doStep(scene, cObject, surface, timescale, subframe))
+ if (!dynamicPaint_doStep(depsgraph, scene, cObject, surface, timescale, subframe))
return 0;
}
}
- return dynamicPaint_doStep(scene, cObject, surface, timescale, 0.0f);
+ return dynamicPaint_doStep(depsgraph, scene, cObject, surface, timescale, 0.0f);
}
diff --git a/source/blender/blenkernel/intern/editderivedmesh.c b/source/blender/blenkernel/intern/editderivedmesh.c
index ffa7fdc3ec9..f5e5a37c7d7 100644
--- a/source/blender/blenkernel/intern/editderivedmesh.c
+++ b/source/blender/blenkernel/intern/editderivedmesh.c
@@ -52,32 +52,20 @@
#include "BKE_mesh.h"
#include "BKE_editmesh.h"
#include "BKE_editmesh_bvh.h"
+#include "BKE_editmesh_tangent.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
#include "MEM_guardedalloc.h"
-#include "GPU_glew.h"
-#include "GPU_buffers.h"
-#include "GPU_shader.h"
-#include "GPU_basic_shader.h"
-
-static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4]);
-
typedef struct EditDerivedBMesh {
DerivedMesh dm;
BMEditMesh *em;
- /** when set, \a vertexNos, polyNos are lazy initialized */
- const float (*vertexCos)[3];
-
- /** lazy initialize (when \a vertexCos is set) */
- float const (*vertexNos)[3];
- float const (*polyNos)[3];
- /** also lazy init but dont depend on \a vertexCos */
- const float (*polyCos)[3];
+ EditMeshData emd;
} EditDerivedBMesh;
/* -------------------------------------------------------------------- */
@@ -87,7 +75,7 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm);
static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm)
{
- if (bmdm->vertexCos && (bmdm->vertexNos == NULL)) {
+ if (bmdm->emd.vertexCos && (bmdm->emd.vertexNos == NULL)) {
BMesh *bm = bmdm->em->bm;
const float (*vertexCos)[3], (*polyNos)[3];
@@ -98,19 +86,19 @@ static void emDM_ensureVertNormals(EditDerivedBMesh *bmdm)
BM_mesh_elem_index_ensure(bm, BM_FACE);
- polyNos = bmdm->polyNos;
- vertexCos = bmdm->vertexCos;
+ polyNos = bmdm->emd.polyNos;
+ vertexCos = bmdm->emd.vertexCos;
vertexNos = MEM_callocN(sizeof(*vertexNos) * bm->totvert, __func__);
BM_verts_calc_normal_vcos(bm, polyNos, vertexCos, vertexNos);
- bmdm->vertexNos = (const float (*)[3])vertexNos;
+ bmdm->emd.vertexNos = (const float (*)[3])vertexNos;
}
}
static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
{
- if (bmdm->vertexCos && (bmdm->polyNos == NULL)) {
+ if (bmdm->emd.vertexCos && (bmdm->emd.polyNos == NULL)) {
BMesh *bm = bmdm->em->bm;
const float (*vertexCos)[3];
float (*polyNos)[3];
@@ -123,7 +111,7 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
polyNos = MEM_mallocN(sizeof(*polyNos) * bm->totface, __func__);
- vertexCos = bmdm->vertexCos;
+ vertexCos = bmdm->emd.vertexCos;
BM_ITER_MESH_INDEX (efa, &fiter, bm, BM_FACES_OF_MESH, i) {
BM_elem_index_set(efa, i); /* set_inline */
@@ -131,13 +119,13 @@ static void emDM_ensurePolyNormals(EditDerivedBMesh *bmdm)
}
bm->elem_index_dirty &= ~BM_FACE;
- bmdm->polyNos = (const float (*)[3])polyNos;
+ bmdm->emd.polyNos = (const float (*)[3])polyNos;
}
}
static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
{
- if (bmdm->polyCos == NULL) {
+ if (bmdm->emd.polyCos == NULL) {
BMesh *bm = bmdm->em->bm;
float (*polyCos)[3];
@@ -147,9 +135,9 @@ static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
polyCos = MEM_mallocN(sizeof(*polyCos) * bm->totface, __func__);
- if (bmdm->vertexCos) {
+ if (bmdm->emd.vertexCos) {
const float (*vertexCos)[3];
- vertexCos = bmdm->vertexCos;
+ vertexCos = bmdm->emd.vertexCos;
BM_mesh_elem_index_ensure(bm, BM_VERT);
@@ -163,7 +151,7 @@ static void emDM_ensurePolyCenters(EditDerivedBMesh *bmdm)
}
}
- bmdm->polyCos = (const float (*)[3])polyCos;
+ bmdm->emd.polyCos = (const float (*)[3])polyCos;
}
}
@@ -199,9 +187,9 @@ static void emDM_calcLoopNormalsSpaceArray(
emDM_ensurePolyNormals(bmdm);
dm->dirty &= ~DM_DIRTY_NORMALS;
- vertexCos = bmdm->vertexCos;
- vertexNos = bmdm->vertexNos;
- polyNos = bmdm->polyNos;
+ vertexCos = bmdm->emd.vertexCos;
+ vertexNos = bmdm->emd.vertexNos;
+ polyNos = bmdm->emd.polyNos;
loopNos = dm->getLoopDataArray(dm, CD_NORMAL);
if (!loopNos) {
@@ -242,392 +230,29 @@ static void emDM_calcLoopNormalsSpaceArray(
#endif
}
-
-/** \name Tangent Space Calculation
- * \{ */
-
-/* Necessary complexity to handle looptri's as quads for correct tangents */
-#define USE_LOOPTRI_DETECT_QUADS
-
-typedef struct {
- const float (*precomputedFaceNormals)[3];
- const float (*precomputedLoopNormals)[3];
- const BMLoop *(*looptris)[3];
- int cd_loop_uv_offset; /* texture coordinates */
- const float (*orco)[3];
- float (*tangent)[4]; /* destination */
- int numTessFaces;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- /* map from 'fake' face index to looptri,
- * quads will point to the first looptri of the quad */
- const int *face_as_quad_map;
- int num_face_as_quad_map;
-#endif
-
-} SGLSLEditMeshToTangent;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
-/* seems weak but only used on quads */
-static const BMLoop *bm_loop_at_face_index(const BMFace *f, int vert_index)
-{
- const BMLoop *l = BM_FACE_FIRST_LOOP(f);
- while (vert_index--) {
- l = l->next;
- }
- return l;
-}
-#endif
-
-/* interface */
-#include "mikktspace.h"
-
-static int emdm_ts_GetNumFaces(const SMikkTSpaceContext *pContext)
-{
- SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- return pMesh->num_face_as_quad_map;
-#else
- return pMesh->numTessFaces;
-#endif
-}
-
-static int emdm_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
-{
-#ifdef USE_LOOPTRI_DETECT_QUADS
- SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
- if (pMesh->face_as_quad_map) {
- const BMLoop **lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
- if (lt[0]->f->len == 4) {
- return 4;
- }
- }
- return 3;
-#else
- UNUSED_VARS(pContext, face_num);
- return 3;
-#endif
-}
-
-static void emdm_ts_GetPosition(
- const SMikkTSpaceContext *pContext, float r_co[3],
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
- const BMLoop **lt;
- const BMLoop *l;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
- if (lt[0]->f->len == 4) {
- l = bm_loop_at_face_index(lt[0]->f, vert_index);
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = pMesh->looptris[face_num];
- }
-#else
- lt = pMesh->looptris[face_num];
-#endif
- l = lt[vert_index];
-
- const float *co;
-
-finally:
- co = l->v->co;
- copy_v3_v3(r_co, co);
-}
-
-static void emdm_ts_GetTextureCoordinate(
- const SMikkTSpaceContext *pContext, float r_uv[2],
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
- const BMLoop **lt;
- const BMLoop *l;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
- if (lt[0]->f->len == 4) {
- l = bm_loop_at_face_index(lt[0]->f, vert_index);
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = pMesh->looptris[face_num];
- }
-#else
- lt = pMesh->looptris[face_num];
-#endif
- l = lt[vert_index];
-
-finally:
- if (pMesh->cd_loop_uv_offset != -1) {
- const float *uv = BM_ELEM_CD_GET_VOID_P(l, pMesh->cd_loop_uv_offset);
- copy_v2_v2(r_uv, uv);
- }
- else {
- const float *orco = pMesh->orco[BM_elem_index_get(l->v)];
- map_to_sphere(&r_uv[0], &r_uv[1], orco[0], orco[1], orco[2]);
- }
-}
-
-static void emdm_ts_GetNormal(
- const SMikkTSpaceContext *pContext, float r_no[3],
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
- const BMLoop **lt;
- const BMLoop *l;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
- if (lt[0]->f->len == 4) {
- l = bm_loop_at_face_index(lt[0]->f, vert_index);
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = pMesh->looptris[face_num];
- }
-#else
- lt = pMesh->looptris[face_num];
-#endif
- l = lt[vert_index];
-
-finally:
- if (pMesh->precomputedLoopNormals) {
- copy_v3_v3(r_no, pMesh->precomputedLoopNormals[BM_elem_index_get(l)]);
- }
- else if (BM_elem_flag_test(l->f, BM_ELEM_SMOOTH) == 0) { /* flat */
- if (pMesh->precomputedFaceNormals) {
- copy_v3_v3(r_no, pMesh->precomputedFaceNormals[BM_elem_index_get(l->f)]);
- }
- else {
- copy_v3_v3(r_no, l->f->no);
- }
- }
- else {
- copy_v3_v3(r_no, l->v->no);
- }
-}
-
-static void emdm_ts_SetTSpace(
- const SMikkTSpaceContext *pContext, const float fvTangent[3], const float fSign,
- const int face_num, const int vert_index)
-{
- //assert(vert_index >= 0 && vert_index < 4);
- SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
- const BMLoop **lt;
- const BMLoop *l;
-
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (pMesh->face_as_quad_map) {
- lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
- if (lt[0]->f->len == 4) {
- l = bm_loop_at_face_index(lt[0]->f, vert_index);
- goto finally;
- }
- /* fall through to regular triangle */
- }
- else {
- lt = pMesh->looptris[face_num];
- }
-#else
- lt = pMesh->looptris[face_num];
-#endif
- l = lt[vert_index];
-
- float *pRes;
-
-finally:
- pRes = pMesh->tangent[BM_elem_index_get(l)];
- copy_v3_v3(pRes, fvTangent);
- pRes[3] = fSign;
-}
-
-static void emDM_calc_loop_tangents_thread(TaskPool * __restrict UNUSED(pool), void *taskdata, int UNUSED(threadid))
-{
- struct SGLSLEditMeshToTangent *mesh2tangent = taskdata;
- /* new computation method */
- {
- SMikkTSpaceContext sContext = {NULL};
- SMikkTSpaceInterface sInterface = {NULL};
- sContext.m_pUserData = mesh2tangent;
- sContext.m_pInterface = &sInterface;
- sInterface.m_getNumFaces = emdm_ts_GetNumFaces;
- sInterface.m_getNumVerticesOfFace = emdm_ts_GetNumVertsOfFace;
- sInterface.m_getPosition = emdm_ts_GetPosition;
- sInterface.m_getTexCoord = emdm_ts_GetTextureCoordinate;
- sInterface.m_getNormal = emdm_ts_GetNormal;
- sInterface.m_setTSpaceBasic = emdm_ts_SetTSpace;
- /* 0 if failed */
- genTangSpaceDefault(&sContext);
- }
-}
-
-/**
- * \see #DM_calc_loop_tangents, same logic but used arrays instead of #BMesh data.
- *
- * \note This function is not so normal, its using `bm->ldata` as input, but output's to `dm->loopData`.
- * This is done because #CD_TANGENT is cache data used only for drawing.
- */
-
static void emDM_calc_loop_tangents(
DerivedMesh *dm, bool calc_active_tangent,
- const char (*tangent_names)[MAX_NAME], int tangent_names_count)
+ const char (*tangent_names)[MAX_NAME], int tangent_names_len)
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
BMEditMesh *em = bmdm->em;
- BMesh *bm = bmdm->em->bm;
- int act_uv_n = -1;
- int ren_uv_n = -1;
- bool calc_act = false;
- bool calc_ren = false;
- char act_uv_name[MAX_NAME];
- char ren_uv_name[MAX_NAME];
- short tangent_mask = 0;
-
- DM_calc_loop_tangents_step_0(
- &bm->ldata, calc_active_tangent, tangent_names, tangent_names_count,
- &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
-
- if ((dm->tangent_mask | tangent_mask) != dm->tangent_mask) {
- for (int i = 0; i < tangent_names_count; i++)
- if (tangent_names[i][0])
- DM_add_named_tangent_layer_for_uv(&bm->ldata, &dm->loopData, dm->numLoopData, tangent_names[i]);
- if ((tangent_mask & DM_TANGENT_MASK_ORCO) && CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, "") == -1)
- CustomData_add_layer_named(&dm->loopData, CD_TANGENT, CD_CALLOC, NULL, dm->numLoopData, "");
- if (calc_act && act_uv_name[0])
- DM_add_named_tangent_layer_for_uv(&bm->ldata, &dm->loopData, dm->numLoopData, act_uv_name);
- if (calc_ren && ren_uv_name[0])
- DM_add_named_tangent_layer_for_uv(&bm->ldata, &dm->loopData, dm->numLoopData, ren_uv_name);
- int totface = em->tottri;
-#ifdef USE_LOOPTRI_DETECT_QUADS
- int num_face_as_quad_map;
- int *face_as_quad_map = NULL;
-
- /* map faces to quads */
- if (bmdm->em->tottri != bm->totface) {
- /* over alloc, since we dont know how many ngon or quads we have */
-
- /* map fake face index to looptri */
- face_as_quad_map = MEM_mallocN(sizeof(int) * totface, __func__);
- int i, j;
- for (i = 0, j = 0; j < totface; i++, j++) {
- face_as_quad_map[i] = j;
- /* step over all quads */
- if (em->looptris[j][0]->f->len == 4) {
- j++; /* skips the nest looptri */
- }
- }
- num_face_as_quad_map = i;
- }
- else {
- num_face_as_quad_map = totface;
- }
-#endif
- /* Calculation */
- {
- TaskScheduler *scheduler = BLI_task_scheduler_get();
- TaskPool *task_pool;
- task_pool = BLI_task_pool_create(scheduler, NULL);
-
- dm->tangent_mask = 0;
- /* Calculate tangent layers */
- SGLSLEditMeshToTangent data_array[MAX_MTFACE];
- int index = 0;
- int n = 0;
- CustomData_update_typemap(&dm->loopData);
- const int tangent_layer_num = CustomData_number_of_layers(&dm->loopData, CD_TANGENT);
- for (n = 0; n < tangent_layer_num; n++) {
- index = CustomData_get_layer_index_n(&dm->loopData, CD_TANGENT, n);
- BLI_assert(n < MAX_MTFACE);
- SGLSLEditMeshToTangent *mesh2tangent = &data_array[n];
- mesh2tangent->numTessFaces = em->tottri;
-#ifdef USE_LOOPTRI_DETECT_QUADS
- mesh2tangent->face_as_quad_map = face_as_quad_map;
- mesh2tangent->num_face_as_quad_map = num_face_as_quad_map;
-#endif
- mesh2tangent->precomputedFaceNormals = bmdm->polyNos; /* dm->getPolyDataArray(dm, CD_NORMAL) */
- /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
- * have to check this is valid...
- */
- mesh2tangent->precomputedLoopNormals = CustomData_get_layer(&dm->loopData, CD_NORMAL);
- mesh2tangent->cd_loop_uv_offset = CustomData_get_n_offset(&bm->ldata, CD_MLOOPUV, n);
-
- /* needed for indexing loop-tangents */
- int htype_index = BM_LOOP;
- if (mesh2tangent->cd_loop_uv_offset == -1) {
- mesh2tangent->orco = dm->getVertDataArray(dm, CD_ORCO);
- if (!mesh2tangent->orco)
- continue;
- /* needed for orco lookups */
- htype_index |= BM_VERT;
- dm->tangent_mask |= DM_TANGENT_MASK_ORCO;
- }
- else {
- /* Fill the resulting tangent_mask */
- int uv_ind = CustomData_get_named_layer_index(&bm->ldata, CD_MLOOPUV, dm->loopData.layers[index].name);
- int uv_start = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV);
- BLI_assert(uv_ind != -1 && uv_start != -1);
- BLI_assert(uv_ind - uv_start < MAX_MTFACE);
- dm->tangent_mask |= 1 << (uv_ind - uv_start);
- }
-
- if (mesh2tangent->precomputedFaceNormals) {
- /* needed for face normal lookups */
- htype_index |= BM_FACE;
- }
- BM_mesh_elem_index_ensure(bm, htype_index);
-
- mesh2tangent->looptris = (const BMLoop *(*)[3])em->looptris;
- mesh2tangent->tangent = dm->loopData.layers[index].data;
-
- BLI_task_pool_push(task_pool, emDM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW);
- }
-
- BLI_assert(dm->tangent_mask == tangent_mask);
- BLI_task_pool_work_and_wait(task_pool);
- BLI_task_pool_free(task_pool);
- }
-#ifdef USE_LOOPTRI_DETECT_QUADS
- if (face_as_quad_map) {
- MEM_freeN(face_as_quad_map);
- }
-#undef USE_LOOPTRI_DETECT_QUADS
-#endif
+ if (CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV) == 0) {
+ return;
}
- /* Update active layer index */
- int act_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, act_uv_n);
- if (act_uv_index >= 0) {
- int tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, bm->ldata.layers[act_uv_index].name);
- CustomData_set_layer_active_index(&dm->loopData, CD_TANGENT, tan_index);
- } /* else tangent has been built from orco */
-
- /* Update render layer index */
- int ren_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, ren_uv_n);
- if (ren_uv_index >= 0) {
- int tan_index = CustomData_get_named_layer_index(&dm->loopData, CD_TANGENT, bm->ldata.layers[ren_uv_index].name);
- CustomData_set_layer_render_index(&dm->loopData, CD_TANGENT, tan_index);
- } /* else tangent has been built from orco */
+ const float (*poly_normals)[3] = bmdm->emd.polyNos;
+ const float (*loop_normals)[3] = CustomData_get_layer(&dm->loopData, CD_NORMAL);
+ const float (*vert_orco)[3] = dm->getVertDataArray(dm, CD_ORCO); /* can be NULL */
+ BKE_editmesh_loop_tangent_calc(
+ em, calc_active_tangent,
+ tangent_names, tangent_names_len,
+ poly_normals, loop_normals,
+ vert_orco,
+ &dm->loopData, dm->numLoopData,
+ &dm->tangent_mask);
}
-/** \} */
-
static void emDM_recalcTessellation(DerivedMesh *UNUSED(dm))
{
@@ -680,13 +305,13 @@ static void emDM_foreachMappedVert(
BMIter iter;
int i;
- if (bmdm->vertexCos) {
- const float (*vertexCos)[3] = bmdm->vertexCos;
+ if (bmdm->emd.vertexCos) {
+ const float (*vertexCos)[3] = bmdm->emd.vertexCos;
const float (*vertexNos)[3];
if (flag & DM_FOREACH_USE_NORMAL) {
emDM_ensureVertNormals(bmdm);
- vertexNos = bmdm->vertexNos;
+ vertexNos = bmdm->emd.vertexNos;
}
else {
vertexNos = NULL;
@@ -715,14 +340,14 @@ static void emDM_foreachMappedEdge(
BMIter iter;
int i;
- if (bmdm->vertexCos) {
+ if (bmdm->emd.vertexCos) {
BM_mesh_elem_index_ensure(bm, BM_VERT);
BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
func(userData, i,
- bmdm->vertexCos[BM_elem_index_get(eed->v1)],
- bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
+ bmdm->emd.vertexCos[BM_elem_index_get(eed->v1)],
+ bmdm->emd.vertexCos[BM_elem_index_get(eed->v2)]);
}
}
else {
@@ -732,123 +357,6 @@ static void emDM_foreachMappedEdge(
}
}
-static void emDM_drawMappedEdges(
- DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- void *userData)
-{
- EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
- BMesh *bm = bmdm->em->bm;
- BMEdge *eed;
- BMIter iter;
- int i;
-
- if (bmdm->vertexCos) {
-
- BM_mesh_elem_index_ensure(bm, BM_VERT);
-
- glBegin(GL_LINES);
- BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
- if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
- }
- }
- glEnd();
- }
- else {
- glBegin(GL_LINES);
- BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
- if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
- glVertex3fv(eed->v1->co);
- glVertex3fv(eed->v2->co);
- }
- }
- glEnd();
- }
-}
-static void emDM_drawEdges(
- DerivedMesh *dm,
- bool UNUSED(drawLooseEdges),
- bool UNUSED(drawAllEdges))
-{
- emDM_drawMappedEdges(dm, NULL, NULL);
-}
-
-static void emDM_drawMappedEdgesInterp(
- DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetDrawInterpOptions setDrawInterpOptions,
- void *userData)
-{
- EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
- BMesh *bm = bmdm->em->bm;
- BMEdge *eed;
- BMIter iter;
- int i;
-
- if (bmdm->vertexCos) {
-
- BM_mesh_elem_index_ensure(bm, BM_VERT);
-
- glBegin(GL_LINES);
- BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
- if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
- setDrawInterpOptions(userData, i, 0.0);
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v1)]);
- setDrawInterpOptions(userData, i, 1.0);
- glVertex3fv(bmdm->vertexCos[BM_elem_index_get(eed->v2)]);
- }
- }
- glEnd();
- }
- else {
- glBegin(GL_LINES);
- BM_ITER_MESH_INDEX (eed, &iter, bm, BM_EDGES_OF_MESH, i) {
- if (!setDrawOptions || (setDrawOptions(userData, i) != DM_DRAW_OPTION_SKIP)) {
- setDrawInterpOptions(userData, i, 0.0);
- glVertex3fv(eed->v1->co);
- setDrawInterpOptions(userData, i, 1.0);
- glVertex3fv(eed->v2->co);
- }
- }
- glEnd();
- }
-}
-
-static void emDM_drawUVEdges(DerivedMesh *dm)
-{
- EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
- BMesh *bm = bmdm->em->bm;
- BMFace *efa;
- BMIter iter;
-
- const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
-
- if (UNLIKELY(cd_loop_uv_offset == -1)) {
- return;
- }
-
- glBegin(GL_LINES);
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- BMLoop *l_iter, *l_first;
- const float *uv, *uv_prev;
-
- if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN))
- continue;
-
- l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
- uv_prev = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter->prev, cd_loop_uv_offset))->uv;
- do {
- uv = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_uv_offset))->uv;
- glVertex2fv(uv);
- glVertex2fv(uv_prev);
- uv_prev = uv;
- } while ((l_iter = l_iter->next) != l_first);
- }
- glEnd();
-}
-
static void emDM_foreachMappedLoop(
DerivedMesh *dm,
void (*func)(void *userData, int vertex_index, int face_index, const float co[3], const float no[3]),
@@ -864,7 +372,7 @@ static void emDM_foreachMappedLoop(
BMFace *efa;
BMIter iter;
- const float (*vertexCos)[3] = bmdm->vertexCos;
+ const float (*vertexCos)[3] = bmdm->emd.vertexCos;
int f_idx;
BM_mesh_elem_index_ensure(bm, BM_VERT);
@@ -897,11 +405,11 @@ static void emDM_foreachMappedFaceCenter(
int i;
emDM_ensurePolyCenters(bmdm);
- polyCos = bmdm->polyCos; /* always set */
+ polyCos = bmdm->emd.polyCos; /* always set */
if (flag & DM_FOREACH_USE_NORMAL) {
emDM_ensurePolyNormals(bmdm);
- polyNos = bmdm->polyNos; /* maybe NULL */
+ polyNos = bmdm->emd.polyNos; /* maybe NULL */
}
else {
polyNos = NULL;
@@ -921,783 +429,6 @@ static void emDM_foreachMappedFaceCenter(
}
}
-static void emDM_drawMappedFaces(
- DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetMaterial setMaterial,
- /* currently unused -- each original face is handled separately */
- DMCompareDrawOptions UNUSED(compareDrawOptions),
- void *userData,
- DMDrawFlag flag)
-{
- EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
- BMEditMesh *em = bmdm->em;
- BMesh *bm = em->bm;
- BMFace *efa;
- struct BMLoop *(*looptris)[3] = bmdm->em->looptris;
- const int tottri = bmdm->em->tottri;
- DMDrawOption draw_option;
- int i;
- const int skip_normals = !(flag & DM_DRAW_NEED_NORMALS);
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- MLoopCol *lcol[3] = {NULL} /* , dummylcol = {0} */;
- unsigned char(*color_vert_array)[4] = em->derivedVertColor;
- unsigned char(*color_face_array)[4] = em->derivedFaceColor;
- bool has_vcol_preview = (color_vert_array != NULL) && !skip_normals;
- bool has_fcol_preview = (color_face_array != NULL) && !skip_normals;
- bool has_vcol_any = has_vcol_preview;
-
- /* GL_ZERO is used to detect if drawing has started or not */
- GLenum poly_prev = GL_ZERO;
- GLenum shade_prev = GL_ZERO;
- DMDrawOption draw_option_prev = DM_DRAW_OPTION_SKIP;
-
- /* call again below is ok */
- if (has_vcol_preview) {
- BM_mesh_elem_index_ensure(bm, BM_VERT);
- }
- if (has_fcol_preview) {
- BM_mesh_elem_index_ensure(bm, BM_FACE);
- }
- if (has_vcol_preview || has_fcol_preview) {
- flag |= DM_DRAW_ALWAYS_SMOOTH;
- /* weak, this logic should really be moved higher up */
- setMaterial = NULL;
- }
-
- if (bmdm->vertexCos) {
- short prev_mat_nr = -1;
-
- /* add direct access */
- const float (*vertexCos)[3] = bmdm->vertexCos;
- const float (*vertexNos)[3];
- const float (*polyNos)[3];
-
- if (skip_normals) {
- vertexNos = NULL;
- polyNos = NULL;
- }
- else {
- emDM_ensureVertNormals(bmdm);
- emDM_ensurePolyNormals(bmdm);
- vertexNos = bmdm->vertexNos;
- polyNos = bmdm->polyNos;
- }
-
- BM_mesh_elem_index_ensure(bm, lnors ? BM_VERT | BM_FACE | BM_LOOP : BM_VERT | BM_FACE);
-
- for (i = 0; i < tottri; i++) {
- BMLoop **ltri = looptris[i];
- int drawSmooth;
-
- efa = ltri[0]->f;
- drawSmooth = lnors || ((flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH));
-
- draw_option = (!setDrawOptions ?
- DM_DRAW_OPTION_NORMAL :
- setDrawOptions(userData, BM_elem_index_get(efa)));
- if (draw_option != DM_DRAW_OPTION_SKIP) {
- const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
-
- if (draw_option_prev != draw_option) {
- if (draw_option_prev == DM_DRAW_OPTION_STIPPLE) {
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
- draw_option_prev = draw_option;
- }
-
-
- if (efa->mat_nr != prev_mat_nr) {
- if (setMaterial) {
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
-
- setMaterial(efa->mat_nr + 1, NULL);
- }
- prev_mat_nr = efa->mat_nr;
- }
-
- if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */
-
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
-
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
- }
-
- if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
- else if (has_fcol_preview) glColor3ubv((const GLubyte *)&(color_face_array[BM_elem_index_get(efa)]));
- if (skip_normals) {
- if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
- }
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
- }
- else {
- const GLenum shade_type = drawSmooth ? GL_SMOOTH : GL_FLAT;
- if (shade_type != shade_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glShadeModel((shade_prev = shade_type)); /* same as below but switch shading */
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
- }
- if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
- }
-
- if (!drawSmooth) {
- glNormal3fv(polyNos[BM_elem_index_get(efa)]);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
- }
- else {
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[0])]);
- else glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[1])]);
- else glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[2])]);
- else glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
- }
- }
- }
- }
- }
- else {
- short prev_mat_nr = -1;
-
- BM_mesh_elem_index_ensure(bm, lnors ? BM_FACE | BM_LOOP : BM_FACE);
-
- for (i = 0; i < tottri; i++) {
- BMLoop **ltri = looptris[i];
- int drawSmooth;
-
- efa = ltri[0]->f;
- drawSmooth = lnors || ((flag & DM_DRAW_ALWAYS_SMOOTH) ? 1 : BM_elem_flag_test(efa, BM_ELEM_SMOOTH));
-
- draw_option = (setDrawOptions ?
- setDrawOptions(userData, BM_elem_index_get(efa)) :
- DM_DRAW_OPTION_NORMAL);
-
- if (draw_option != DM_DRAW_OPTION_SKIP) {
- const GLenum poly_type = GL_TRIANGLES; /* BMESH NOTE, this is odd but keep it for now to match trunk */
-
- if (draw_option_prev != draw_option) {
- if (draw_option_prev == DM_DRAW_OPTION_STIPPLE) {
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
- draw_option_prev = draw_option;
- }
-
- if (efa->mat_nr != prev_mat_nr) {
- if (setMaterial) {
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
-
- setMaterial(efa->mat_nr + 1, NULL);
- }
- prev_mat_nr = efa->mat_nr;
- }
-
- if (draw_option == DM_DRAW_OPTION_STIPPLE) { /* enabled with stipple */
-
- if (poly_prev != GL_ZERO) glEnd();
- poly_prev = GL_ZERO; /* force glBegin */
-
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
- }
-
- if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
- else if (has_fcol_preview) glColor3ubv((const GLubyte *)&(color_face_array[BM_elem_index_get(efa)]));
-
- if (skip_normals) {
- if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
- }
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(ltri[0]->v->co);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(ltri[1]->v->co);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(ltri[2]->v->co);
- }
- else {
- const GLenum shade_type = drawSmooth ? GL_SMOOTH : GL_FLAT;
- if (shade_type != shade_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glShadeModel((shade_prev = shade_type)); /* same as below but switch shading */
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
- }
- if (poly_type != poly_prev) {
- if (poly_prev != GL_ZERO) glEnd();
- glBegin((poly_prev = poly_type)); /* BMesh: will always be GL_TRIANGLES */
- }
-
- if (!drawSmooth) {
- glNormal3fv(efa->no);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(ltri[0]->v->co);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(ltri[1]->v->co);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(ltri[2]->v->co);
- }
- else {
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[0])]);
- else glNormal3fv(ltri[0]->v->no);
- glVertex3fv(ltri[0]->v->co);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[1])]);
- else glNormal3fv(ltri[1]->v->no);
- glVertex3fv(ltri[1]->v->co);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[2])]);
- else glNormal3fv(ltri[2]->v->no);
- glVertex3fv(ltri[2]->v->co);
- }
- }
- }
- }
- }
-
- /* if non zero we know a face was rendered */
- if (poly_prev != GL_ZERO) glEnd();
-
- if (draw_option_prev == DM_DRAW_OPTION_STIPPLE) {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
-
- if (shade_prev == GL_FLAT) {
- glShadeModel(GL_SMOOTH);
- }
-}
-
-static void bmdm_get_tri_uv(BMLoop *ltri[3], MLoopUV *luv[3], const int cd_loop_uv_offset)
-{
- luv[0] = BM_ELEM_CD_GET_VOID_P(ltri[0], cd_loop_uv_offset);
- luv[1] = BM_ELEM_CD_GET_VOID_P(ltri[1], cd_loop_uv_offset);
- luv[2] = BM_ELEM_CD_GET_VOID_P(ltri[2], cd_loop_uv_offset);
-}
-
-static void bmdm_get_tri_col(BMLoop *ltri[3], MLoopCol *lcol[3], const int cd_loop_color_offset)
-{
- lcol[0] = BM_ELEM_CD_GET_VOID_P(ltri[0], cd_loop_color_offset);
- lcol[1] = BM_ELEM_CD_GET_VOID_P(ltri[1], cd_loop_color_offset);
- lcol[2] = BM_ELEM_CD_GET_VOID_P(ltri[2], cd_loop_color_offset);
-}
-
-static void bmdm_get_tri_colpreview(BMLoop *ls[3], MLoopCol *lcol[3], unsigned char(*color_vert_array)[4])
-{
- lcol[0] = (MLoopCol *)color_vert_array[BM_elem_index_get(ls[0]->v)];
- lcol[1] = (MLoopCol *)color_vert_array[BM_elem_index_get(ls[1]->v)];
- lcol[2] = (MLoopCol *)color_vert_array[BM_elem_index_get(ls[2]->v)];
-}
-
-static void emDM_drawFacesTex_common(
- DerivedMesh *dm,
- DMSetDrawOptionsTex drawParams,
- DMSetDrawOptionsMappedTex drawParamsMapped,
- DMCompareDrawOptions compareDrawOptions,
- void *userData)
-{
- EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
- BMEditMesh *em = bmdm->em;
- BMesh *bm = em->bm;
- struct BMLoop *(*looptris)[3] = em->looptris;
- BMFace *efa;
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- MLoopUV *luv[3], dummyluv = {{0}};
- MLoopCol *lcol[3] = {NULL} /* , dummylcol = {0} */;
- const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- const int cd_loop_color_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPCOL);
- const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
- unsigned char(*color_vert_array)[4] = em->derivedVertColor;
- bool has_uv = (cd_loop_uv_offset != -1);
- bool has_vcol_preview = (color_vert_array != NULL);
- bool has_vcol = (cd_loop_color_offset != -1) && (has_vcol_preview == false);
- bool has_vcol_any = (has_vcol_preview || has_vcol);
- int i;
-
- (void) compareDrawOptions;
-
- luv[0] = luv[1] = luv[2] = &dummyluv;
-
- // dummylcol.r = dummylcol.g = dummylcol.b = dummylcol.a = 255; /* UNUSED */
-
- /* always use smooth shading even for flat faces, else vertex colors wont interpolate */
- BM_mesh_elem_index_ensure(bm, BM_FACE);
-
- /* call again below is ok */
- if (has_vcol_preview) {
- BM_mesh_elem_index_ensure(bm, BM_VERT);
- }
-
- if (bmdm->vertexCos) {
- /* add direct access */
- const float (*vertexCos)[3] = bmdm->vertexCos;
- const float (*vertexNos)[3];
- const float (*polyNos)[3];
-
- emDM_ensureVertNormals(bmdm);
- emDM_ensurePolyNormals(bmdm);
- vertexNos = bmdm->vertexNos;
- polyNos = bmdm->polyNos;
-
- BM_mesh_elem_index_ensure(bm, lnors ? BM_LOOP | BM_VERT : BM_VERT);
-
- for (i = 0; i < em->tottri; i++) {
- BMLoop **ltri = looptris[i];
- MTexPoly *tp = (cd_poly_tex_offset != -1) ? BM_ELEM_CD_GET_VOID_P(ltri[0]->f, cd_poly_tex_offset) : NULL;
- /*unsigned char *cp = NULL;*/ /*UNUSED*/
- int drawSmooth = lnors || BM_elem_flag_test(ltri[0]->f, BM_ELEM_SMOOTH);
- DMDrawOption draw_option;
-
- efa = ltri[0]->f;
-
- if (drawParams) {
- draw_option = drawParams(tp, has_vcol, efa->mat_nr);
- }
- else if (drawParamsMapped)
- draw_option = drawParamsMapped(userData, BM_elem_index_get(efa), efa->mat_nr);
- else
- draw_option = DM_DRAW_OPTION_NORMAL;
-
- if (draw_option != DM_DRAW_OPTION_SKIP) {
-
- if (has_uv) bmdm_get_tri_uv(ltri, luv, cd_loop_uv_offset);
- if (has_vcol) bmdm_get_tri_col(ltri, lcol, cd_loop_color_offset);
- else if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
-
- glBegin(GL_TRIANGLES);
- if (!drawSmooth) {
- glNormal3fv(polyNos[BM_elem_index_get(efa)]);
-
- glTexCoord2fv(luv[0]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
-
- glTexCoord2fv(luv[1]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
-
- glTexCoord2fv(luv[2]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
- }
- else {
- glTexCoord2fv(luv[0]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[0])]);
- else glNormal3fv(vertexNos[BM_elem_index_get(ltri[0]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[0]->v)]);
-
- glTexCoord2fv(luv[1]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[1])]);
- else glNormal3fv(vertexNos[BM_elem_index_get(ltri[1]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[1]->v)]);
-
- glTexCoord2fv(luv[2]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[2])]);
- else glNormal3fv(vertexNos[BM_elem_index_get(ltri[2]->v)]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[2]->v)]);
- }
- glEnd();
- }
- }
- }
- else {
- BM_mesh_elem_index_ensure(bm, lnors ? BM_LOOP | BM_VERT : BM_VERT);
-
- for (i = 0; i < em->tottri; i++) {
- BMLoop **ltri = looptris[i];
- MTexPoly *tp = (cd_poly_tex_offset != -1) ? BM_ELEM_CD_GET_VOID_P(ltri[0]->f, cd_poly_tex_offset) : NULL;
- /*unsigned char *cp = NULL;*/ /*UNUSED*/
- int drawSmooth = lnors || BM_elem_flag_test(ltri[0]->f, BM_ELEM_SMOOTH);
- DMDrawOption draw_option;
-
- efa = ltri[0]->f;
-
- if (drawParams)
- draw_option = drawParams(tp, has_vcol, efa->mat_nr);
- else if (drawParamsMapped)
- draw_option = drawParamsMapped(userData, BM_elem_index_get(efa), efa->mat_nr);
- else
- draw_option = DM_DRAW_OPTION_NORMAL;
-
- if (draw_option != DM_DRAW_OPTION_SKIP) {
-
- if (has_uv) bmdm_get_tri_uv(ltri, luv, cd_loop_uv_offset);
- if (has_vcol) bmdm_get_tri_col(ltri, lcol, cd_loop_color_offset);
- else if (has_vcol_preview) bmdm_get_tri_colpreview(ltri, lcol, color_vert_array);
-
- glBegin(GL_TRIANGLES);
- if (!drawSmooth) {
- glNormal3fv(efa->no);
-
- glTexCoord2fv(luv[0]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- glVertex3fv(ltri[0]->v->co);
-
- glTexCoord2fv(luv[1]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- glVertex3fv(ltri[1]->v->co);
-
- glTexCoord2fv(luv[2]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- glVertex3fv(ltri[2]->v->co);
- }
- else {
- glTexCoord2fv(luv[0]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[0]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[0])]);
- else glNormal3fv(ltri[0]->v->no);
- glVertex3fv(ltri[0]->v->co);
-
- glTexCoord2fv(luv[1]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[1]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[1])]);
- else glNormal3fv(ltri[1]->v->no);
- glVertex3fv(ltri[1]->v->co);
-
- glTexCoord2fv(luv[2]->uv);
- if (has_vcol_any) glColor4ubv((const GLubyte *)&(lcol[2]->r));
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[2])]);
- else glNormal3fv(ltri[2]->v->no);
- glVertex3fv(ltri[2]->v->co);
- }
- glEnd();
- }
- }
- }
-}
-
-static void emDM_drawFacesTex(
- DerivedMesh *dm,
- DMSetDrawOptionsTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag UNUSED(flag))
-{
- emDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData);
-}
-
-static void emDM_drawMappedFacesTex(
- DerivedMesh *dm,
- DMSetDrawOptionsMappedTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag UNUSED(flag))
-{
- emDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData);
-}
-
-/**
- * \note
- *
- * For UV's:
- * const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
- *
- * This is intentionally different to calling:
- * CustomData_bmesh_get_n(&bm->ldata, loop->head.data, CD_MLOOPUV, i);
- *
- * ... because the material may use layer names to select different UV's
- * see: [#34378]
- */
-static void emdm_pass_attrib_vertex_glsl(const DMVertexAttribs *attribs, const BMLoop *loop)
-{
- BMVert *eve = loop->v;
- int i;
- const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-
- if (attribs->totorco) {
- int index = BM_elem_index_get(eve);
- const float *orco = (attribs->orco.array) ? attribs->orco.array[index] : zero;
-
- if (attribs->orco.gl_texco)
- glTexCoord3fv(orco);
- else
- glVertexAttrib3fv(attribs->orco.gl_index, orco);
- }
- for (i = 0; i < attribs->tottface; i++) {
- const float *uv;
-
- if (attribs->tface[i].em_offset != -1) {
- const MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(loop, attribs->tface[i].em_offset);
- uv = luv->uv;
- }
- else {
- uv = zero;
- }
-
- if (attribs->tface[i].gl_texco)
- glTexCoord2fv(uv);
- else
- glVertexAttrib2fv(attribs->tface[i].gl_index, uv);
- }
- for (i = 0; i < attribs->totmcol; i++) {
- float col[4];
- if (attribs->mcol[i].em_offset != -1) {
- const MLoopCol *cp = BM_ELEM_CD_GET_VOID_P(loop, attribs->mcol[i].em_offset);
- rgba_uchar_to_float(col, &cp->r);
- }
- else {
- col[0] = 0.0f; col[1] = 0.0f; col[2] = 0.0f; col[3] = 0.0f;
- }
- glVertexAttrib4fv(attribs->mcol[i].gl_index, col);
- }
-
- for (i = 0; i < attribs->tottang; i++) {
- const float *tang;
- if (attribs->tang[i].em_offset != -1) {
- tang = attribs->tang[i].array[BM_elem_index_get(loop)];
- }
- else {
- tang = zero;
- }
- glVertexAttrib4fv(attribs->tang[i].gl_index, tang);
- }
-}
-
-static void emDM_drawMappedFacesGLSL(
- DerivedMesh *dm,
- DMSetMaterial setMaterial,
- DMSetDrawOptions setDrawOptions,
- void *userData)
-{
- EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
- BMEditMesh *em = bmdm->em;
- BMesh *bm = em->bm;
- struct BMLoop *(*looptris)[3] = em->looptris;
- /* add direct access */
- const float (*vertexCos)[3] = bmdm->vertexCos;
- const float (*vertexNos)[3];
- const float (*polyNos)[3];
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
-
- BMFace *efa;
- DMVertexAttribs attribs;
- GPUVertexAttribs gattribs;
-
- int i, matnr, new_matnr, fi;
- bool do_draw;
-
- do_draw = false;
- matnr = -1;
-
- memset(&attribs, 0, sizeof(attribs));
-
- emDM_ensureVertNormals(bmdm);
- emDM_ensurePolyNormals(bmdm);
- vertexNos = bmdm->vertexNos;
- polyNos = bmdm->polyNos;
-
- BM_mesh_elem_index_ensure(bm, (BM_VERT | BM_FACE) | (lnors ? BM_LOOP : 0));
-
- for (i = 0; i < em->tottri; i++) {
- BMLoop **ltri = looptris[i];
- int drawSmooth;
-
- efa = ltri[0]->f;
-
- if (setDrawOptions && (setDrawOptions(userData, BM_elem_index_get(efa)) == DM_DRAW_OPTION_SKIP))
- continue;
-
- /* material */
- new_matnr = efa->mat_nr + 1;
- if (new_matnr != matnr) {
- if (matnr != -1)
- glEnd();
-
- do_draw = setMaterial(matnr = new_matnr, &gattribs);
- if (do_draw) {
- DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
- DM_draw_attrib_vertex_uniforms(&attribs);
- if (UNLIKELY(attribs.tottang && bm->elem_index_dirty & BM_LOOP)) {
- BM_mesh_elem_index_ensure(bm, BM_LOOP);
- }
- }
-
- glBegin(GL_TRIANGLES);
- }
-
- if (do_draw) {
-
- /* draw face */
- drawSmooth = lnors || BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
-
- if (!drawSmooth) {
- if (vertexCos) {
- glNormal3fv(polyNos[BM_elem_index_get(efa)]);
- for (fi = 0; fi < 3; fi++) {
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[fi]->v)]);
- }
- }
- else {
- glNormal3fv(efa->no);
- for (fi = 0; fi < 3; fi++) {
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- glVertex3fv(ltri[fi]->v->co);
- }
- }
- }
- else {
- if (vertexCos) {
- for (fi = 0; fi < 3; fi++) {
- const int j = BM_elem_index_get(ltri[fi]->v);
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[fi])]);
- else glNormal3fv(vertexNos[j]);
- glVertex3fv(vertexCos[j]);
- }
- }
- else {
- for (fi = 0; fi < 3; fi++) {
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[fi])]);
- else glNormal3fv(ltri[fi]->v->no);
- glVertex3fv(ltri[fi]->v->co);
- }
- }
- }
- }
- }
-
- if (matnr != -1) {
- glEnd();
- }
-}
-
-static void emDM_drawFacesGLSL(
- DerivedMesh *dm,
- int (*setMaterial)(int matnr, void *attribs))
-{
- dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
-}
-
-static void emDM_drawMappedFacesMat(
- DerivedMesh *dm,
- void (*setMaterial)(void *userData, int matnr, void *attribs),
- bool (*setFace)(void *userData, int index), void *userData)
-{
- EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
- BMEditMesh *em = bmdm->em;
- BMesh *bm = em->bm;
- struct BMLoop *(*looptris)[3] = em->looptris;
- const float (*vertexCos)[3] = bmdm->vertexCos;
- const float (*vertexNos)[3];
- const float (*polyNos)[3];
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- BMFace *efa;
- DMVertexAttribs attribs = {{{NULL}}};
- GPUVertexAttribs gattribs;
- int i, matnr, new_matnr, fi;
-
- matnr = -1;
-
- emDM_ensureVertNormals(bmdm);
- emDM_ensurePolyNormals(bmdm);
-
- vertexNos = bmdm->vertexNos;
- polyNos = bmdm->polyNos;
-
- BM_mesh_elem_index_ensure(bm, (BM_VERT | BM_FACE) | (lnors ? BM_LOOP : 0));
-
- for (i = 0; i < em->tottri; i++) {
- BMLoop **ltri = looptris[i];
- int drawSmooth;
-
- efa = ltri[0]->f;
-
- /* face hiding */
- if (setFace && !setFace(userData, BM_elem_index_get(efa)))
- continue;
-
- /* material */
- new_matnr = efa->mat_nr + 1;
- if (new_matnr != matnr) {
- if (matnr != -1)
- glEnd();
-
- setMaterial(userData, matnr = new_matnr, &gattribs);
- DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
- if (UNLIKELY(attribs.tottang && bm->elem_index_dirty & BM_LOOP)) {
- BM_mesh_elem_index_ensure(bm, BM_LOOP);
- }
-
- glBegin(GL_TRIANGLES);
- }
-
- /* draw face */
- drawSmooth = lnors || BM_elem_flag_test(efa, BM_ELEM_SMOOTH);
-
- if (!drawSmooth) {
- if (vertexCos) {
- glNormal3fv(polyNos[BM_elem_index_get(efa)]);
- for (fi = 0; fi < 3; fi++) {
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- glVertex3fv(vertexCos[BM_elem_index_get(ltri[fi]->v)]);
- }
- }
- else {
- glNormal3fv(efa->no);
- for (fi = 0; fi < 3; fi++) {
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- glVertex3fv(ltri[fi]->v->co);
- }
- }
- }
- else {
- if (vertexCos) {
- for (fi = 0; fi < 3; fi++) {
- const int j = BM_elem_index_get(ltri[fi]->v);
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[fi])]);
- else glNormal3fv(vertexNos[j]);
- glVertex3fv(vertexCos[j]);
- }
- }
- else {
- for (fi = 0; fi < 3; fi++) {
- emdm_pass_attrib_vertex_glsl(&attribs, ltri[fi]);
- if (lnors) glNormal3fv(lnors[BM_elem_index_get(ltri[fi])]);
- else glNormal3fv(ltri[fi]->v->no);
- glVertex3fv(ltri[fi]->v->co);
- }
- }
- }
- }
-
- if (matnr != -1) {
- glEnd();
- }
-}
-
static void emDM_getMinMax(DerivedMesh *dm, float r_min[3], float r_max[3])
{
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
@@ -1707,9 +438,9 @@ static void emDM_getMinMax(DerivedMesh *dm, float r_min[3], float r_max[3])
int i;
if (bm->totvert) {
- if (bmdm->vertexCos) {
+ if (bmdm->emd.vertexCos) {
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
- minmax_v3v3_v3(r_min, r_max, bmdm->vertexCos[i]);
+ minmax_v3v3_v3(r_min, r_max, bmdm->emd.vertexCos[i]);
}
}
else {
@@ -1789,8 +520,8 @@ static void emDM_getVert(DerivedMesh *dm, int index, MVert *r_vert)
// ev = BM_vert_at_index(bm, index); /* warning, does list loop, _not_ ideal */
bmvert_to_mvert(bm, ev, r_vert);
- if (bmdm->vertexCos)
- copy_v3_v3(r_vert->co, bmdm->vertexCos[index]);
+ if (bmdm->emd.vertexCos)
+ copy_v3_v3(r_vert->co, bmdm->emd.vertexCos[index]);
}
static void emDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
@@ -1803,8 +534,8 @@ static void emDM_getVertCo(DerivedMesh *dm, int index, float r_co[3])
return;
}
- if (bmdm->vertexCos) {
- copy_v3_v3(r_co, bmdm->vertexCos[index]);
+ if (bmdm->emd.vertexCos) {
+ copy_v3_v3(r_co, bmdm->emd.vertexCos[index]);
}
else {
BMVert *ev;
@@ -1827,9 +558,9 @@ static void emDM_getVertNo(DerivedMesh *dm, int index, float r_no[3])
}
- if (bmdm->vertexCos) {
+ if (bmdm->emd.vertexCos) {
emDM_ensureVertNormals(bmdm);
- copy_v3_v3(r_no, bmdm->vertexNos[index]);
+ copy_v3_v3(r_no, bmdm->emd.vertexNos[index]);
}
else {
BMVert *ev;
@@ -1851,9 +582,9 @@ static void emDM_getPolyNo(DerivedMesh *dm, int index, float r_no[3])
return;
}
- if (bmdm->vertexCos) {
+ if (bmdm->emd.vertexCos) {
emDM_ensurePolyNormals(bmdm);
- copy_v3_v3(r_no, bmdm->polyNos[index]);
+ copy_v3_v3(r_no, bmdm->emd.polyNos[index]);
}
else {
BMFace *efa;
@@ -1928,11 +659,11 @@ static void emDM_copyVertArray(DerivedMesh *dm, MVert *r_vert)
BMIter iter;
const int cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
- if (bmdm->vertexCos) {
+ if (bmdm->emd.vertexCos) {
int i;
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
- copy_v3_v3(r_vert->co, bmdm->vertexCos[i]);
+ copy_v3_v3(r_vert->co, bmdm->emd.vertexCos[i]);
normal_float_to_short_v3(r_vert->no, eve->no);
r_vert->flag = BM_vert_flag_to_mflag(eve);
@@ -2061,14 +792,8 @@ static void *emDM_getTessFaceDataArray(DerivedMesh *dm, int type)
if (type == CD_MTFACE || type == CD_MCOL) {
const char *bmdata;
char *data;
- bool has_type_source = false;
- if (type == CD_MTFACE) {
- has_type_source = CustomData_has_layer(&bm->pdata, CD_MTEXPOLY);
- }
- else {
- has_type_source = CustomData_has_layer(&bm->ldata, CD_MLOOPCOL);
- }
+ bool has_type_source = CustomData_has_layer(&bm->ldata, (type == CD_MTFACE) ? CD_MLOOPUV : CD_MLOOPCOL);
if (has_type_source) {
/* offset = bm->pdata.layers[index].offset; */ /* UNUSED */
@@ -2084,15 +809,8 @@ static void *emDM_getTessFaceDataArray(DerivedMesh *dm, int type)
if (type == CD_MTFACE) {
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
for (i = 0; i < bmdm->em->tottri; i++, data += size) {
- BMFace *efa = looptris[i][0]->f;
-
- // bmdata = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
- bmdata = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- ME_MTEXFACE_CPY(((MTFace *)data), ((const MTexPoly *)bmdata));
for (j = 0; j < 3; j++) {
// bmdata = CustomData_bmesh_get(&bm->ldata, looptris[i][j]->head.data, CD_MLOOPUV);
bmdata = BM_ELEM_CD_GET_VOID_P(looptris[i][j], cd_loop_uv_offset);
@@ -2149,9 +867,9 @@ static void emDM_getVertCos(DerivedMesh *dm, float (*r_cos)[3])
BMIter iter;
int i;
- if (bmdm->vertexCos) {
+ if (bmdm->emd.vertexCos) {
BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
- copy_v3_v3(r_cos[i], bmdm->vertexCos[i]);
+ copy_v3_v3(r_cos[i], bmdm->emd.vertexCos[i]);
}
}
else {
@@ -2166,18 +884,18 @@ static void emDM_release(DerivedMesh *dm)
EditDerivedBMesh *bmdm = (EditDerivedBMesh *)dm;
if (DM_release(dm)) {
- if (bmdm->vertexCos) {
- MEM_freeN((void *)bmdm->vertexCos);
- if (bmdm->vertexNos) {
- MEM_freeN((void *)bmdm->vertexNos);
+ if (bmdm->emd.vertexCos) {
+ MEM_freeN((void *)bmdm->emd.vertexCos);
+ if (bmdm->emd.vertexNos) {
+ MEM_freeN((void *)bmdm->emd.vertexNos);
}
- if (bmdm->polyNos) {
- MEM_freeN((void *)bmdm->polyNos);
+ if (bmdm->emd.polyNos) {
+ MEM_freeN((void *)bmdm->emd.polyNos);
}
}
- if (bmdm->polyCos) {
- MEM_freeN((void *)bmdm->polyCos);
+ if (bmdm->emd.polyCos) {
+ MEM_freeN((void *)bmdm->emd.polyCos);
}
MEM_freeN(bmdm);
@@ -2280,20 +998,9 @@ DerivedMesh *getEditDerivedBMesh(
bmdm->dm.foreachMappedEdge = emDM_foreachMappedEdge;
bmdm->dm.foreachMappedFaceCenter = emDM_foreachMappedFaceCenter;
- bmdm->dm.drawEdges = emDM_drawEdges;
- bmdm->dm.drawMappedEdges = emDM_drawMappedEdges;
- bmdm->dm.drawMappedEdgesInterp = emDM_drawMappedEdgesInterp;
- bmdm->dm.drawMappedFaces = emDM_drawMappedFaces;
- bmdm->dm.drawMappedFacesTex = emDM_drawMappedFacesTex;
- bmdm->dm.drawMappedFacesGLSL = emDM_drawMappedFacesGLSL;
- bmdm->dm.drawMappedFacesMat = emDM_drawMappedFacesMat;
- bmdm->dm.drawFacesTex = emDM_drawFacesTex;
- bmdm->dm.drawFacesGLSL = emDM_drawFacesGLSL;
- bmdm->dm.drawUVEdges = emDM_drawUVEdges;
-
bmdm->dm.release = emDM_release;
- bmdm->vertexCos = (const float (*)[3])vertexCos;
+ bmdm->emd.vertexCos = (const float (*)[3])vertexCos;
bmdm->dm.deformedOnly = (vertexCos != NULL);
const int cd_dvert_offset = (data_mask & CD_MASK_MDEFORMVERT) ?
@@ -2721,7 +1428,7 @@ void BKE_editmesh_statvis_calc(
{
BKE_editmesh_color_ensure(em, BM_FACE);
statvis_calc_overhang(
- em, bmdm ? bmdm->polyNos : NULL,
+ em, bmdm ? bmdm->emd.polyNos : NULL,
statvis->overhang_min / (float)M_PI,
statvis->overhang_max / (float)M_PI,
statvis->overhang_axis,
@@ -2733,7 +1440,7 @@ void BKE_editmesh_statvis_calc(
const float scale = 1.0f / mat4_to_scale(em->ob->obmat);
BKE_editmesh_color_ensure(em, BM_FACE);
statvis_calc_thickness(
- em, bmdm ? bmdm->vertexCos : NULL,
+ em, bmdm ? bmdm->emd.vertexCos : NULL,
statvis->thickness_min * scale,
statvis->thickness_max * scale,
statvis->thickness_samples,
@@ -2744,7 +1451,7 @@ void BKE_editmesh_statvis_calc(
{
BKE_editmesh_color_ensure(em, BM_FACE);
statvis_calc_intersect(
- em, bmdm ? bmdm->vertexCos : NULL,
+ em, bmdm ? bmdm->emd.vertexCos : NULL,
em->derivedFaceColor);
break;
}
@@ -2756,7 +1463,7 @@ void BKE_editmesh_statvis_calc(
emDM_ensurePolyNormals(bmdm);
statvis_calc_distort(
- em, bmdm ? bmdm->vertexCos : NULL, bmdm ? bmdm->polyNos : NULL,
+ em, bmdm ? bmdm->emd.vertexCos : NULL, bmdm ? bmdm->emd.polyNos : NULL,
statvis->distort_min,
statvis->distort_max,
em->derivedFaceColor);
@@ -2766,7 +1473,7 @@ void BKE_editmesh_statvis_calc(
{
BKE_editmesh_color_ensure(em, BM_VERT);
statvis_calc_sharp(
- em, bmdm ? bmdm->vertexCos : NULL,
+ em, bmdm ? bmdm->emd.vertexCos : NULL,
statvis->sharp_min,
statvis->sharp_max,
/* in this case they are vertex colors */
@@ -2799,14 +1506,14 @@ static void cage_mapped_verts_callback(
}
}
-float (*BKE_editmesh_vertexCos_get(BMEditMesh *em, Scene *scene, int *r_numVerts))[3]
+float (*BKE_editmesh_vertexCos_get(struct Depsgraph *depsgraph, BMEditMesh *em, Scene *scene, int *r_numVerts))[3]
{
DerivedMesh *cage, *final;
BLI_bitmap *visit_bitmap;
struct CageUserData data;
float (*cos_cage)[3];
- cage = editbmesh_get_derived_cage_and_final(scene, em->ob, em, CD_MASK_BAREMESH, &final);
+ cage = editbmesh_get_derived_cage_and_final(depsgraph, scene, em->ob, em, CD_MASK_BAREMESH, &final);
cos_cage = MEM_callocN(sizeof(*cos_cage) * em->bm->totvert, "bmbvh cos_cage");
/* when initializing cage verts, we only want the first cage coordinate for each vertex,
diff --git a/source/blender/blenkernel/intern/editmesh.c b/source/blender/blenkernel/intern/editmesh.c
index fea3c24d322..b63ab276b14 100644
--- a/source/blender/blenkernel/intern/editmesh.c
+++ b/source/blender/blenkernel/intern/editmesh.c
@@ -89,11 +89,13 @@ BMEditMesh *BKE_editmesh_from_object(Object *ob)
{
BLI_assert(ob->type == OB_MESH);
/* sanity check */
+#if 0 /* disable in mutlti-object edit. */
#ifndef NDEBUG
if (((Mesh *)ob->data)->edit_btmesh) {
BLI_assert(((Mesh *)ob->data)->edit_btmesh->ob == ob);
}
#endif
+#endif
return ((Mesh *)ob->data)->edit_btmesh;
}
@@ -165,26 +167,6 @@ void BKE_editmesh_tessface_calc(BMEditMesh *em)
#endif
}
-void BKE_editmesh_update_linked_customdata(BMEditMesh *em)
-{
- BMesh *bm = em->bm;
- int act;
-
- if (CustomData_has_layer(&bm->pdata, CD_MTEXPOLY)) {
- act = CustomData_get_active_layer(&bm->pdata, CD_MTEXPOLY);
- CustomData_set_layer_active(&bm->ldata, CD_MLOOPUV, act);
-
- act = CustomData_get_render_layer(&bm->pdata, CD_MTEXPOLY);
- CustomData_set_layer_render(&bm->ldata, CD_MLOOPUV, act);
-
- act = CustomData_get_clone_layer(&bm->pdata, CD_MTEXPOLY);
- CustomData_set_layer_clone(&bm->ldata, CD_MLOOPUV, act);
-
- act = CustomData_get_stencil_layer(&bm->pdata, CD_MTEXPOLY);
- CustomData_set_layer_stencil(&bm->ldata, CD_MLOOPUV, act);
- }
-}
-
void BKE_editmesh_free_derivedmesh(BMEditMesh *em)
{
if (em->derivedCage) {
diff --git a/source/blender/blenkernel/intern/editmesh_bvh.c b/source/blender/blenkernel/intern/editmesh_bvh.c
index 2927354241c..e68f11f6274 100644
--- a/source/blender/blenkernel/intern/editmesh_bvh.c
+++ b/source/blender/blenkernel/intern/editmesh_bvh.c
@@ -547,4 +547,4 @@ BVHTreeOverlap *BKE_bmbvh_overlap(const BMBVHTree *bmtree_a, const BMBVHTree *bm
data.epsilon = max_ff(BLI_bvhtree_get_epsilon(bmtree_a->tree), BLI_bvhtree_get_epsilon(bmtree_b->tree));
return BLI_bvhtree_overlap(bmtree_a->tree, bmtree_b->tree, r_overlap_tot, bmbvh_overlap_cb, &data);
-} \ No newline at end of file
+}
diff --git a/source/blender/blenkernel/intern/editmesh_tangent.c b/source/blender/blenkernel/intern/editmesh_tangent.c
new file mode 100644
index 00000000000..9e8b4fa8782
--- /dev/null
+++ b/source/blender/blenkernel/intern/editmesh_tangent.c
@@ -0,0 +1,431 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/editmesh_tangent.c
+ * \ingroup bke
+ */
+
+#include "BLI_math.h"
+#include "BLI_task.h"
+
+#include "BKE_DerivedMesh.h"
+
+#include "BKE_mesh.h"
+#include "BKE_mesh_tangent.h" /* for utility functions */
+#include "BKE_editmesh.h"
+#include "BKE_editmesh_tangent.h"
+
+#include "MEM_guardedalloc.h"
+
+/* interface */
+#include "mikktspace.h"
+
+/** \name Tangent Space Calculation
+ * \{ */
+
+/* Necessary complexity to handle looptri's as quads for correct tangents */
+#define USE_LOOPTRI_DETECT_QUADS
+
+typedef struct {
+ const float (*precomputedFaceNormals)[3];
+ const float (*precomputedLoopNormals)[3];
+ const BMLoop *(*looptris)[3];
+ int cd_loop_uv_offset; /* texture coordinates */
+ const float (*orco)[3];
+ float (*tangent)[4]; /* destination */
+ int numTessFaces;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ /* map from 'fake' face index to looptri,
+ * quads will point to the first looptri of the quad */
+ const int *face_as_quad_map;
+ int num_face_as_quad_map;
+#endif
+
+} SGLSLEditMeshToTangent;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+/* seems weak but only used on quads */
+static const BMLoop *bm_loop_at_face_index(const BMFace *f, int vert_index)
+{
+ const BMLoop *l = BM_FACE_FIRST_LOOP(f);
+ while (vert_index--) {
+ l = l->next;
+ }
+ return l;
+}
+#endif
+
+static int emdm_ts_GetNumFaces(const SMikkTSpaceContext *pContext)
+{
+ SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ return pMesh->num_face_as_quad_map;
+#else
+ return pMesh->numTessFaces;
+#endif
+}
+
+static int emdm_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
+{
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+ if (pMesh->face_as_quad_map) {
+ const BMLoop **lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
+ if (lt[0]->f->len == 4) {
+ return 4;
+ }
+ }
+ return 3;
+#else
+ UNUSED_VARS(pContext, face_num);
+ return 3;
+#endif
+}
+
+static void emdm_ts_GetPosition(
+ const SMikkTSpaceContext *pContext, float r_co[3],
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+ const BMLoop **lt;
+ const BMLoop *l;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
+ if (lt[0]->f->len == 4) {
+ l = bm_loop_at_face_index(lt[0]->f, vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = pMesh->looptris[face_num];
+ }
+#else
+ lt = pMesh->looptris[face_num];
+#endif
+ l = lt[vert_index];
+
+ const float *co;
+
+finally:
+ co = l->v->co;
+ copy_v3_v3(r_co, co);
+}
+
+static void emdm_ts_GetTextureCoordinate(
+ const SMikkTSpaceContext *pContext, float r_uv[2],
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+ const BMLoop **lt;
+ const BMLoop *l;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
+ if (lt[0]->f->len == 4) {
+ l = bm_loop_at_face_index(lt[0]->f, vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = pMesh->looptris[face_num];
+ }
+#else
+ lt = pMesh->looptris[face_num];
+#endif
+ l = lt[vert_index];
+
+finally:
+ if (pMesh->cd_loop_uv_offset != -1) {
+ const float *uv = BM_ELEM_CD_GET_VOID_P(l, pMesh->cd_loop_uv_offset);
+ copy_v2_v2(r_uv, uv);
+ }
+ else {
+ const float *orco = pMesh->orco[BM_elem_index_get(l->v)];
+ map_to_sphere(&r_uv[0], &r_uv[1], orco[0], orco[1], orco[2]);
+ }
+}
+
+static void emdm_ts_GetNormal(
+ const SMikkTSpaceContext *pContext, float r_no[3],
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+ const BMLoop **lt;
+ const BMLoop *l;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
+ if (lt[0]->f->len == 4) {
+ l = bm_loop_at_face_index(lt[0]->f, vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = pMesh->looptris[face_num];
+ }
+#else
+ lt = pMesh->looptris[face_num];
+#endif
+ l = lt[vert_index];
+
+finally:
+ if (pMesh->precomputedLoopNormals) {
+ copy_v3_v3(r_no, pMesh->precomputedLoopNormals[BM_elem_index_get(l)]);
+ }
+ else if (BM_elem_flag_test(l->f, BM_ELEM_SMOOTH) == 0) { /* flat */
+ if (pMesh->precomputedFaceNormals) {
+ copy_v3_v3(r_no, pMesh->precomputedFaceNormals[BM_elem_index_get(l->f)]);
+ }
+ else {
+ copy_v3_v3(r_no, l->f->no);
+ }
+ }
+ else {
+ copy_v3_v3(r_no, l->v->no);
+ }
+}
+
+static void emdm_ts_SetTSpace(
+ const SMikkTSpaceContext *pContext, const float fvTangent[3], const float fSign,
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLEditMeshToTangent *pMesh = pContext->m_pUserData;
+ const BMLoop **lt;
+ const BMLoop *l;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = pMesh->looptris[pMesh->face_as_quad_map[face_num]];
+ if (lt[0]->f->len == 4) {
+ l = bm_loop_at_face_index(lt[0]->f, vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = pMesh->looptris[face_num];
+ }
+#else
+ lt = pMesh->looptris[face_num];
+#endif
+ l = lt[vert_index];
+
+ float *pRes;
+
+finally:
+ pRes = pMesh->tangent[BM_elem_index_get(l)];
+ copy_v3_v3(pRes, fvTangent);
+ pRes[3] = fSign;
+}
+
+static void emDM_calc_loop_tangents_thread(TaskPool * __restrict UNUSED(pool), void *taskdata, int UNUSED(threadid))
+{
+ struct SGLSLEditMeshToTangent *mesh2tangent = taskdata;
+ /* new computation method */
+ {
+ SMikkTSpaceContext sContext = {NULL};
+ SMikkTSpaceInterface sInterface = {NULL};
+ sContext.m_pUserData = mesh2tangent;
+ sContext.m_pInterface = &sInterface;
+ sInterface.m_getNumFaces = emdm_ts_GetNumFaces;
+ sInterface.m_getNumVerticesOfFace = emdm_ts_GetNumVertsOfFace;
+ sInterface.m_getPosition = emdm_ts_GetPosition;
+ sInterface.m_getTexCoord = emdm_ts_GetTextureCoordinate;
+ sInterface.m_getNormal = emdm_ts_GetNormal;
+ sInterface.m_setTSpaceBasic = emdm_ts_SetTSpace;
+ /* 0 if failed */
+ genTangSpaceDefault(&sContext);
+ }
+}
+
+/**
+ * \see #BKE_mesh_calc_loop_tangent, same logic but used arrays instead of #BMesh data.
+ *
+ * \note This function is not so normal, its using `bm->ldata` as input, but output's to `dm->loopData`.
+ * This is done because #CD_TANGENT is cache data used only for drawing.
+ */
+void BKE_editmesh_loop_tangent_calc(
+ BMEditMesh *em, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_len,
+ const float (*poly_normals)[3],
+ const float (*loop_normals)[3],
+ const float (*vert_orco)[3],
+ /* result */
+ CustomData *loopdata_out,
+ const uint loopdata_out_len,
+ short *tangent_mask_curr_p)
+{
+ BMesh *bm = em->bm;
+
+ int act_uv_n = -1;
+ int ren_uv_n = -1;
+ bool calc_act = false;
+ bool calc_ren = false;
+ char act_uv_name[MAX_NAME];
+ char ren_uv_name[MAX_NAME];
+ short tangent_mask = 0;
+ short tangent_mask_curr = *tangent_mask_curr_p;
+
+ BKE_mesh_calc_loop_tangent_step_0(
+ &bm->ldata, calc_active_tangent, tangent_names, tangent_names_len,
+ &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
+
+ if ((tangent_mask_curr | tangent_mask) != tangent_mask_curr) {
+ for (int i = 0; i < tangent_names_len; i++) {
+ if (tangent_names[i][0]) {
+ BKE_mesh_add_loop_tangent_named_layer_for_uv(
+ &bm->ldata, loopdata_out, (int)loopdata_out_len, tangent_names[i]);
+ }
+ }
+ if ((tangent_mask & DM_TANGENT_MASK_ORCO) && CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, "") == -1)
+ CustomData_add_layer_named(loopdata_out, CD_TANGENT, CD_CALLOC, NULL, (int)loopdata_out_len, "");
+ if (calc_act && act_uv_name[0])
+ BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, (int)loopdata_out_len, act_uv_name);
+ if (calc_ren && ren_uv_name[0])
+ BKE_mesh_add_loop_tangent_named_layer_for_uv(&bm->ldata, loopdata_out, (int)loopdata_out_len, ren_uv_name);
+ int totface = em->tottri;
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ int num_face_as_quad_map;
+ int *face_as_quad_map = NULL;
+
+ /* map faces to quads */
+ if (em->tottri != bm->totface) {
+ /* over alloc, since we dont know how many ngon or quads we have */
+
+ /* map fake face index to looptri */
+ face_as_quad_map = MEM_mallocN(sizeof(int) * totface, __func__);
+ int i, j;
+ for (i = 0, j = 0; j < totface; i++, j++) {
+ face_as_quad_map[i] = j;
+ /* step over all quads */
+ if (em->looptris[j][0]->f->len == 4) {
+ j++; /* skips the nest looptri */
+ }
+ }
+ num_face_as_quad_map = i;
+ }
+ else {
+ num_face_as_quad_map = totface;
+ }
+#endif
+ /* Calculation */
+ if (em->tottri != 0) {
+ TaskScheduler *scheduler = BLI_task_scheduler_get();
+ TaskPool *task_pool;
+ task_pool = BLI_task_pool_create(scheduler, NULL);
+
+ tangent_mask_curr = 0;
+ /* Calculate tangent layers */
+ SGLSLEditMeshToTangent data_array[MAX_MTFACE];
+ int index = 0;
+ int n = 0;
+ CustomData_update_typemap(loopdata_out);
+ const int tangent_layer_num = CustomData_number_of_layers(loopdata_out, CD_TANGENT);
+ for (n = 0; n < tangent_layer_num; n++) {
+ index = CustomData_get_layer_index_n(loopdata_out, CD_TANGENT, n);
+ BLI_assert(n < MAX_MTFACE);
+ SGLSLEditMeshToTangent *mesh2tangent = &data_array[n];
+ mesh2tangent->numTessFaces = em->tottri;
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ mesh2tangent->face_as_quad_map = face_as_quad_map;
+ mesh2tangent->num_face_as_quad_map = num_face_as_quad_map;
+#endif
+ mesh2tangent->precomputedFaceNormals = poly_normals; /* dm->getPolyDataArray(dm, CD_NORMAL) */
+ /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
+ * have to check this is valid...
+ */
+ mesh2tangent->precomputedLoopNormals = loop_normals;
+ mesh2tangent->cd_loop_uv_offset = CustomData_get_n_offset(&bm->ldata, CD_MLOOPUV, n);
+
+ /* needed for indexing loop-tangents */
+ int htype_index = BM_LOOP;
+ if (mesh2tangent->cd_loop_uv_offset == -1) {
+ mesh2tangent->orco = vert_orco;
+ if (!mesh2tangent->orco)
+ continue;
+ /* needed for orco lookups */
+ htype_index |= BM_VERT;
+ tangent_mask_curr |= DM_TANGENT_MASK_ORCO;
+ }
+ else {
+ /* Fill the resulting tangent_mask */
+ int uv_ind = CustomData_get_named_layer_index(&bm->ldata, CD_MLOOPUV, loopdata_out->layers[index].name);
+ int uv_start = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV);
+ BLI_assert(uv_ind != -1 && uv_start != -1);
+ BLI_assert(uv_ind - uv_start < MAX_MTFACE);
+ tangent_mask_curr |= 1 << (uv_ind - uv_start);
+ }
+ if (mesh2tangent->precomputedFaceNormals) {
+ /* needed for face normal lookups */
+ htype_index |= BM_FACE;
+ }
+ BM_mesh_elem_index_ensure(bm, htype_index);
+
+ mesh2tangent->looptris = (const BMLoop *(*)[3])em->looptris;
+ mesh2tangent->tangent = loopdata_out->layers[index].data;
+
+ BLI_task_pool_push(task_pool, emDM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW);
+ }
+
+ BLI_assert(tangent_mask_curr == tangent_mask);
+ BLI_task_pool_work_and_wait(task_pool);
+ BLI_task_pool_free(task_pool);
+ }
+ else {
+ tangent_mask_curr = tangent_mask;
+ }
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (face_as_quad_map) {
+ MEM_freeN(face_as_quad_map);
+ }
+#undef USE_LOOPTRI_DETECT_QUADS
+#endif
+ }
+
+ *tangent_mask_curr_p = tangent_mask_curr;
+
+ int act_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, act_uv_n);
+ if (act_uv_index >= 0) {
+ int tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, bm->ldata.layers[act_uv_index].name);
+ CustomData_set_layer_active_index(loopdata_out, CD_TANGENT, tan_index);
+ } /* else tangent has been built from orco */
+
+ /* Update render layer index */
+ int ren_uv_index = CustomData_get_layer_index_n(&bm->ldata, CD_MLOOPUV, ren_uv_n);
+ if (ren_uv_index >= 0) {
+ int tan_index = CustomData_get_named_layer_index(loopdata_out, CD_TANGENT, bm->ldata.layers[ren_uv_index].name);
+ CustomData_set_layer_render_index(loopdata_out, CD_TANGENT, tan_index);
+ } /* else tangent has been built from orco */
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/effect.c b/source/blender/blenkernel/intern/effect.c
index e47af83e00e..8bdc74edffd 100644
--- a/source/blender/blenkernel/intern/effect.c
+++ b/source/blender/blenkernel/intern/effect.c
@@ -64,6 +64,8 @@
#include "BKE_cdderivedmesh.h"
#include "BKE_effect.h"
#include "BKE_global.h"
+#include "BKE_group.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
@@ -71,6 +73,8 @@
#include "BKE_scene.h"
#include "BKE_smoke.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "RE_render_ext.h"
#include "RE_shader_ext.h"
@@ -145,9 +149,10 @@ void free_partdeflect(PartDeflect *pd)
MEM_freeN(pd);
}
-static EffectorCache *new_effector_cache(Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd)
+static EffectorCache *new_effector_cache(struct Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, PartDeflect *pd)
{
EffectorCache *eff = MEM_callocN(sizeof(EffectorCache), "EffectorCache");
+ eff->depsgraph = depsgraph;
eff->scene = scene;
eff->ob = ob;
eff->psys = psys;
@@ -155,7 +160,7 @@ static EffectorCache *new_effector_cache(Scene *scene, Object *ob, ParticleSyste
eff->frame = -1;
return eff;
}
-static void add_object_to_effectors(ListBase **effectors, Scene *scene, EffectorWeights *weights, Object *ob, Object *ob_src, bool for_simulation)
+static void add_object_to_effectors(ListBase **effectors, struct Depsgraph *depsgraph, Scene *scene, EffectorWeights *weights, Object *ob, Object *ob_src, bool for_simulation)
{
EffectorCache *eff = NULL;
@@ -173,14 +178,14 @@ static void add_object_to_effectors(ListBase **effectors, Scene *scene, Effector
if (*effectors == NULL)
*effectors = MEM_callocN(sizeof(ListBase), "effectors list");
- eff = new_effector_cache(scene, ob, NULL, ob->pd);
+ eff = new_effector_cache(depsgraph, scene, ob, NULL, ob->pd);
/* make sure imat is up to date */
invert_m4_m4(ob->imat, ob->obmat);
BLI_addtail(*effectors, eff);
}
-static void add_particles_to_effectors(ListBase **effectors, Scene *scene, EffectorWeights *weights, Object *ob, ParticleSystem *psys, ParticleSystem *psys_src, bool for_simulation)
+static void add_particles_to_effectors(ListBase **effectors, struct Depsgraph *depsgraph, Scene *scene, EffectorWeights *weights, Object *ob, ParticleSystem *psys, ParticleSystem *psys_src, bool for_simulation)
{
ParticleSettings *part= psys->part;
@@ -194,61 +199,60 @@ static void add_particles_to_effectors(ListBase **effectors, Scene *scene, Effec
if (*effectors == NULL)
*effectors = MEM_callocN(sizeof(ListBase), "effectors list");
- BLI_addtail(*effectors, new_effector_cache(scene, ob, psys, part->pd));
+ BLI_addtail(*effectors, new_effector_cache(depsgraph, scene, ob, psys, part->pd));
}
if (part->pd2 && part->pd2->forcefield && (!for_simulation || weights->weight[part->pd2->forcefield] != 0.0f)) {
if (*effectors == NULL)
*effectors = MEM_callocN(sizeof(ListBase), "effectors list");
- BLI_addtail(*effectors, new_effector_cache(scene, ob, psys, part->pd2));
+ BLI_addtail(*effectors, new_effector_cache(depsgraph, scene, ob, psys, part->pd2));
}
}
/* returns ListBase handle with objects taking part in the effecting */
-ListBase *pdInitEffectors(Scene *scene, Object *ob_src, ParticleSystem *psys_src,
- EffectorWeights *weights, bool for_simulation)
+ListBase *pdInitEffectors(
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob_src, ParticleSystem *psys_src,
+ EffectorWeights *weights, bool for_simulation)
{
+ ViewLayer *view_layer;
Base *base;
- unsigned int layer= ob_src->lay;
ListBase *effectors = NULL;
-
+
if (weights->group) {
- GroupObject *go;
-
- for (go= weights->group->gobject.first; go; go= go->next) {
- if ( (go->ob->lay & layer) ) {
- if ( go->ob->pd && go->ob->pd->forcefield )
- add_object_to_effectors(&effectors, scene, weights, go->ob, ob_src, for_simulation);
+ view_layer = weights->group->view_layer;
+ }
+ /* TODO(mai): the check for view_layer shouldnt be needed, remove when render engine api is updated for this */
+ else if (depsgraph && DEG_get_evaluated_view_layer(depsgraph)) {
+ view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ }
+ else {
+ /* depsgraph is NULL during deg build */
+ view_layer = BKE_view_layer_context_active_PLACEHOLDER(scene);
+ }
- if ( go->ob->particlesystem.first ) {
- ParticleSystem *psys= go->ob->particlesystem.first;
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ if ((base->flag & BASE_VISIBLED) == 0) {
+ continue;
+ }
- for ( ; psys; psys=psys->next )
- add_particles_to_effectors(&effectors, scene, weights, go->ob, psys, psys_src, for_simulation);
- }
- }
+ if (base->object->pd && base->object->pd->forcefield) {
+ add_object_to_effectors(&effectors, depsgraph, scene, weights, base->object, ob_src, for_simulation);
}
- }
- else {
- for (base = scene->base.first; base; base= base->next) {
- if ( (base->lay & layer) ) {
- if ( base->object->pd && base->object->pd->forcefield )
- add_object_to_effectors(&effectors, scene, weights, base->object, ob_src, for_simulation);
- if ( base->object->particlesystem.first ) {
- ParticleSystem *psys= base->object->particlesystem.first;
+ if (base->object->particlesystem.first) {
+ ParticleSystem *psys= base->object->particlesystem.first;
- for ( ; psys; psys=psys->next )
- add_particles_to_effectors(&effectors, scene, weights, base->object, psys, psys_src, for_simulation);
- }
+ for (; psys; psys=psys->next) {
+ add_particles_to_effectors(&effectors, depsgraph, scene, weights, base->object, psys, psys_src, for_simulation);
}
}
}
-
- if (for_simulation)
- pdPrecalculateEffectors(effectors);
-
+
+ if (for_simulation) {
+ pdPrecalculateEffectors(depsgraph, effectors);
+ }
+
return effectors;
}
@@ -268,7 +272,7 @@ void pdEndEffectors(ListBase **effectors)
}
}
-static void precalculate_effector(EffectorCache *eff)
+static void precalculate_effector(struct Depsgraph *depsgraph, EffectorCache *eff)
{
unsigned int cfra = (unsigned int)(eff->scene->r.cfra >= 0 ? eff->scene->r.cfra : -eff->scene->r.cfra);
if (!eff->pd->rng)
@@ -280,7 +284,7 @@ static void precalculate_effector(EffectorCache *eff)
Curve *cu= eff->ob->data;
if (cu->flag & CU_PATH) {
if (eff->ob->curve_cache == NULL || eff->ob->curve_cache->path==NULL || eff->ob->curve_cache->path->data==NULL)
- BKE_displist_make_curveTypes(eff->scene, eff->ob, 0);
+ BKE_displist_make_curveTypes(depsgraph, eff->scene, eff->ob, 0);
if (eff->ob->curve_cache->path && eff->ob->curve_cache->path->data) {
where_on_path(eff->ob, 0.0, eff->guide_loc, eff->guide_dir, NULL, &eff->guide_radius, NULL);
@@ -301,19 +305,19 @@ static void precalculate_effector(EffectorCache *eff)
if (eff->ob) {
float old_vel[3];
- BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra - 1.0f);
+ BKE_object_where_is_calc_time(depsgraph, eff->scene, eff->ob, cfra - 1.0f);
copy_v3_v3(old_vel, eff->ob->obmat[3]);
- BKE_object_where_is_calc_time(eff->scene, eff->ob, cfra);
+ BKE_object_where_is_calc_time(depsgraph, eff->scene, eff->ob, cfra);
sub_v3_v3v3(eff->velocity, eff->ob->obmat[3], old_vel);
}
}
-void pdPrecalculateEffectors(ListBase *effectors)
+void pdPrecalculateEffectors(struct Depsgraph *depsgraph, ListBase *effectors)
{
if (effectors) {
EffectorCache *eff = effectors->first;
for (; eff; eff=eff->next)
- precalculate_effector(eff);
+ precalculate_effector(depsgraph, eff);
}
}
@@ -612,6 +616,7 @@ int get_effector_data(EffectorCache *eff, EffectorData *efd, EffectedPoint *poin
}
else {
ParticleSimulationData sim= {NULL};
+ sim.depsgraph = eff->depsgraph;
sim.scene= eff->scene;
sim.ob= eff->ob;
sim.psys= eff->psys;
diff --git a/source/blender/blenkernel/intern/fluidsim.c b/source/blender/blenkernel/intern/fluidsim.c
index 7dc6e3575b2..c79b2bb4aee 100644
--- a/source/blender/blenkernel/intern/fluidsim.c
+++ b/source/blender/blenkernel/intern/fluidsim.c
@@ -64,7 +64,7 @@
// file handling
//-------------------------------------------------------------------------------
-void initElbeemMesh(struct Scene *scene, struct Object *ob,
+void initElbeemMesh(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
int *numVertices, float **vertices,
int *numTriangles, int **triangles,
int useGlobalCoords, int modifierIndex)
@@ -77,7 +77,7 @@ void initElbeemMesh(struct Scene *scene, struct Object *ob,
float *verts;
int *tris;
- dm = mesh_create_derived_index_render(scene, ob, CD_MASK_BAREMESH, modifierIndex);
+ dm = mesh_create_derived_index_render(depsgraph, scene, ob, CD_MASK_BAREMESH, modifierIndex);
mvert = dm->getVertArray(dm);
mloop = dm->getLoopArray(dm);
diff --git a/source/blender/blenkernel/intern/font.c b/source/blender/blenkernel/intern/font.c
index 5545eba8764..34b185417e3 100644
--- a/source/blender/blenkernel/intern/font.c
+++ b/source/blender/blenkernel/intern/font.c
@@ -1022,7 +1022,7 @@ makebreak:
/* top and top-baseline are the same when text-boxes are used */
if (cu->align_y != CU_ALIGN_Y_TOP && i_textbox < slen) {
/* all previous textboxes are 'full', only align the last used text-box */
- float yoff;
+ float yoff = 0.0f;
int lines;
struct CharTrans *ct_last, *ct_textbox;
@@ -1051,7 +1051,7 @@ makebreak:
else {
/* non text-box case handled separately */
ct = chartransdata;
- float yoff;
+ float yoff = 0.0f;
if (cu->align_y == CU_ALIGN_Y_TOP) {
yoff = -linedist;
diff --git a/source/blender/blenkernel/intern/freestyle.c b/source/blender/blenkernel/intern/freestyle.c
index 686fe3bda93..b656d2cf7c0 100644
--- a/source/blender/blenkernel/intern/freestyle.c
+++ b/source/blender/blenkernel/intern/freestyle.c
@@ -61,17 +61,21 @@ void BKE_freestyle_config_init(FreestyleConfig *config)
BLI_listbase_clear(&config->linesets);
}
-void BKE_freestyle_config_free(FreestyleConfig *config)
+void BKE_freestyle_config_free(FreestyleConfig *config, const bool do_id_user)
{
FreestyleLineSet *lineset;
for (lineset = (FreestyleLineSet *)config->linesets.first; lineset; lineset = lineset->next) {
if (lineset->group) {
- id_us_min(&lineset->group->id);
+ if (do_id_user) {
+ id_us_min(&lineset->group->id);
+ }
lineset->group = NULL;
}
if (lineset->linestyle) {
- id_us_min(&lineset->linestyle->id);
+ if (do_id_user) {
+ id_us_min(&lineset->linestyle->id);
+ }
lineset->linestyle = NULL;
}
}
diff --git a/source/blender/blenkernel/intern/group.c b/source/blender/blenkernel/intern/group.c
index 6dc8cc5aff1..f2c9bfdd974 100644
--- a/source/blender/blenkernel/intern/group.c
+++ b/source/blender/blenkernel/intern/group.c
@@ -45,34 +45,51 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
-
-#include "BKE_depsgraph.h"
+#include "BKE_collection.h"
#include "BKE_global.h"
#include "BKE_group.h"
#include "BKE_icons.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_object.h"
-#include "BKE_scene.h" /* BKE_scene_base_find */
+#include "BKE_scene.h"
-static void free_group_object(GroupObject *go)
-{
- MEM_freeN(go);
-}
+#include "DEG_depsgraph.h"
/** Free (or release) any data used by this group (does not free the group itself). */
void BKE_group_free(Group *group)
{
- /* don't free group itself */
- GroupObject *go;
-
/* No animdata here. */
+ BKE_previewimg_free(&group->preview);
- while ((go = BLI_pophead(&group->gobject))) {
- free_group_object(go);
+ if (group->view_layer != NULL) {
+ BKE_view_layer_free(group->view_layer);
+ group->view_layer = NULL;
}
- BKE_previewimg_free(&group->preview);
+ if (group->collection != NULL) {
+ BKE_collection_master_free(&group->id, false);
+ MEM_freeN(group->collection);
+ group->collection = NULL;
+ }
+}
+
+/**
+ * Run when adding new groups or during doversion.
+ */
+void BKE_group_init(Group *group)
+{
+ group->collection = MEM_callocN(sizeof(SceneCollection), __func__);
+ BLI_strncpy(group->collection->name, "Master Collection", sizeof(group->collection->name));
+ group->view_layer = BKE_view_layer_group_add(group);
+
+ /* Unlink the master collection. */
+ BKE_collection_unlink(group->view_layer, group->view_layer->layer_collections.first);
+
+ /* Create and link a new default collection. */
+ SceneCollection *defaut_collection = BKE_collection_add(&group->id, NULL, COLLECTION_TYPE_GROUP_INTERNAL, NULL);
+ BKE_collection_link(group->view_layer, defaut_collection);
}
Group *BKE_group_add(Main *bmain, const char *name)
@@ -85,7 +102,7 @@ Group *BKE_group_add(Main *bmain, const char *name)
group->layer = (1 << 20) - 1;
group->preview = NULL;
-
+ BKE_group_init(group);
return group;
}
@@ -99,7 +116,8 @@ Group *BKE_group_add(Main *bmain, const char *name)
*/
void BKE_group_copy_data(Main *UNUSED(bmain), Group *group_dst, const Group *group_src, const int flag)
{
- BLI_duplicatelist(&group_dst->gobject, &group_src->gobject);
+ /* We never handle usercount here for own data. */
+ const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
/* Do not copy group's preview (same behavior as for objects). */
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0 && false) { /* XXX TODO temp hack */
@@ -108,6 +126,19 @@ void BKE_group_copy_data(Main *UNUSED(bmain), Group *group_dst, const Group *gro
else {
group_dst->preview = NULL;
}
+
+ group_dst->collection = MEM_dupallocN(group_src->collection);
+ SceneCollection *master_collection_src = BKE_collection_master(&group_src->id);
+ SceneCollection *master_collection_dst = BKE_collection_master(&group_dst->id);
+
+ /* Recursively creates a new SceneCollection tree. */
+ BKE_collection_copy_data(master_collection_dst, master_collection_src,
+ flag_subdata);
+
+ group_dst->view_layer = MEM_dupallocN(group_src->view_layer);
+ BKE_view_layer_copy_data(group_dst->view_layer, group_src->view_layer,
+ master_collection_dst, master_collection_src,
+ flag_subdata);
}
Group *BKE_group_copy(Main *bmain, const Group *group)
@@ -125,38 +156,27 @@ void BKE_group_make_local(Main *bmain, Group *group, const bool lib_local)
/* external */
static bool group_object_add_internal(Group *group, Object *ob)
{
- GroupObject *go;
-
if (group == NULL || ob == NULL) {
return false;
}
-
- /* check if the object has been added already */
- if (BLI_findptr(&group->gobject, ob, offsetof(GroupObject, ob))) {
+
+ /* For now always add to master collection of the group. */
+ SceneCollection *scene_collection = GROUP_MASTER_COLLECTION(group);
+
+ /* If the object has been added already it returns false. */
+ if (BKE_collection_object_add(&group->id, scene_collection, ob) == false) {
return false;
}
-
- go = MEM_callocN(sizeof(GroupObject), "groupobject");
- BLI_addtail(&group->gobject, go);
-
- go->ob = ob;
- id_us_ensure_real(&go->ob->id);
-
+
+ id_us_ensure_real(&ob->id);
return true;
}
-bool BKE_group_object_add(Group *group, Object *object, Scene *scene, Base *base)
+bool BKE_group_object_add(Group *group, Object *object)
{
if (group_object_add_internal(group, object)) {
if ((object->flag & OB_FROMGROUP) == 0) {
-
- if (scene && base == NULL)
- base = BKE_scene_base_find(scene, object);
-
object->flag |= OB_FROMGROUP;
-
- if (base)
- base->flag |= OB_FROMGROUP;
}
return true;
}
@@ -166,24 +186,17 @@ bool BKE_group_object_add(Group *group, Object *object, Scene *scene, Base *base
}
/* also used for (ob == NULL) */
-static int group_object_unlink_internal(Group *group, Object *ob)
+static bool group_object_unlink_internal(Group *group, Object *ob)
{
- GroupObject *go, *gon;
- int removed = 0;
- if (group == NULL) return 0;
-
- go = group->gobject.first;
- while (go) {
- gon = go->next;
- if (go->ob == ob) {
- BLI_remlink(&group->gobject, go);
- free_group_object(go);
- removed = 1;
- /* should break here since an object being in a group twice cant happen? */
- }
- go = gon;
+ if (group == NULL) {
+ return false;
}
- return removed;
+
+ if (BKE_collections_object_remove(NULL, &group->id, ob, false)) {
+ return true;
+ }
+
+ return false;
}
static bool group_object_cyclic_check_internal(Object *object, Group *group)
@@ -200,12 +213,13 @@ static bool group_object_cyclic_check_internal(Object *object, Group *group)
if (dup_group == group)
return true;
else {
- GroupObject *gob;
- for (gob = dup_group->gobject.first; gob; gob = gob->next) {
- if (group_object_cyclic_check_internal(gob->ob, group)) {
+ FOREACH_GROUP_OBJECT_BEGIN(dup_group, group_object)
+ {
+ if (group_object_cyclic_check_internal(group_object, dup_group)) {
return true;
}
}
+ FOREACH_GROUP_OBJECT_END;
}
/* un-flag the object, it's allowed to have the same group multiple times in parallel */
@@ -223,18 +237,12 @@ bool BKE_group_object_cyclic_check(Main *bmain, Object *object, Group *group)
return group_object_cyclic_check_internal(object, group);
}
-bool BKE_group_object_unlink(Group *group, Object *object, Scene *scene, Base *base)
+bool BKE_group_object_unlink(Group *group, Object *object)
{
if (group_object_unlink_internal(group, object)) {
/* object can be NULL */
if (object && BKE_group_object_find(NULL, object) == NULL) {
- if (scene && base == NULL)
- base = BKE_scene_base_find(scene, object);
-
object->flag &= ~OB_FROMGROUP;
-
- if (base)
- base->flag &= ~OB_FROMGROUP;
}
return true;
}
@@ -249,7 +257,7 @@ bool BKE_group_object_exists(Group *group, Object *ob)
return false;
}
else {
- return (BLI_findptr(&group->gobject, ob, offsetof(GroupObject, ob)) != NULL);
+ return (BLI_findptr(&group->view_layer->object_bases, ob, offsetof(Base, object)));
}
}
@@ -270,17 +278,13 @@ Group *BKE_group_object_find(Group *group, Object *ob)
bool BKE_group_is_animated(Group *group, Object *UNUSED(parent))
{
- GroupObject *go;
-
-#if 0 /* XXX OLD ANIMSYS, NLASTRIPS ARE NO LONGER USED */
- if (parent->nlastrips.first)
- return 1;
-#endif
-
- for (go = group->gobject.first; go; go = go->next)
- if (go->ob && go->ob->proxy)
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ if (object->proxy) {
return true;
-
+ }
+ }
+ FOREACH_GROUP_OBJECT_END;
return false;
}
@@ -330,10 +334,8 @@ static void group_replaces_nla(Object *parent, Object *target, char mode)
* you can draw everything, leaves tags in objects to signal it needs further updating */
/* note: does not work for derivedmesh and render... it recreates all again in convertblender.c */
-void BKE_group_handle_recalc_and_update(EvaluationContext *eval_ctx, Scene *scene, Object *UNUSED(parent), Group *group)
+void BKE_group_handle_recalc_and_update(struct Depsgraph *depsgraph, Scene *scene, Object *UNUSED(parent), Group *group)
{
- GroupObject *go;
-
#if 0 /* warning, isn't clearing the recalc flag on the object which causes it to run all the time,
* not just on frame change.
* This isn't working because the animation data is only re-evaluated on frame change so commenting for now
@@ -352,7 +354,7 @@ void BKE_group_handle_recalc_and_update(EvaluationContext *eval_ctx, Scene *scen
go->ob->recalc = go->recalc;
group_replaces_nla(parent, go->ob, 's');
- BKE_object_handle_update(eval_ctx, scene, go->ob);
+ BKE_object_handle_update(depsgraph, scene, go->ob);
group_replaces_nla(parent, go->ob, 'e');
/* leave recalc tags in case group members are in normal scene */
@@ -367,12 +369,21 @@ void BKE_group_handle_recalc_and_update(EvaluationContext *eval_ctx, Scene *scen
#endif
{
/* only do existing tags, as set by regular depsgraph */
- for (go = group->gobject.first; go; go = go->next) {
- if (go->ob) {
- if (go->ob->recalc) {
- BKE_object_handle_update(eval_ctx, scene, go->ob);
- }
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ if (object->id.recalc & ID_RECALC_ALL) {
+ BKE_object_handle_update(depsgraph, scene, object);
}
}
+ FOREACH_GROUP_OBJECT_END;
}
}
+
+/* ******** Dependency graph evaluation ******** */
+
+void BKE_group_eval_view_layers(struct Depsgraph *depsgraph,
+ Group *group)
+{
+ DEG_debug_print_eval(depsgraph, __func__, group->id.name, group);
+ BKE_layer_eval_view_layer(depsgraph, &group->id, group->view_layer);
+}
diff --git a/source/blender/blenkernel/intern/icons.c b/source/blender/blenkernel/intern/icons.c
index 3ac8abd55f6..e1d1211f6e5 100644
--- a/source/blender/blenkernel/intern/icons.c
+++ b/source/blender/blenkernel/intern/icons.c
@@ -42,6 +42,7 @@
#include "DNA_material_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
#include "DNA_texture_types.h"
#include "DNA_world_types.h"
#include "DNA_brush_types.h"
@@ -50,6 +51,7 @@
#include "BLI_ghash.h"
#include "BLI_linklist_lockfree.h"
#include "BLI_string.h"
+#include "BLI_fileops.h"
#include "BLI_threads.h"
#include "BKE_icons.h"
@@ -63,6 +65,14 @@
#include "IMB_imbuf_types.h"
#include "IMB_thumbs.h"
+/**
+ * Only allow non-managed icons to be removed (by Python for eg).
+ * Previews & ID's have their own functions to remove icons.
+ */
+enum {
+ ICON_FLAG_MANAGED = (1 << 0),
+};
+
/* GLOBALS */
static GHash *gIcons = NULL;
@@ -85,6 +95,19 @@ static void icon_free(void *val)
Icon *icon = val;
if (icon) {
+ if (icon->obj_type == ICON_DATA_GEOM) {
+ struct Icon_Geom *obj = icon->obj;
+ if (obj->mem) {
+ /* coords & colors are part of this memory. */
+ MEM_freeN((void *)obj->mem);
+ }
+ else {
+ MEM_freeN((void *)obj->coords);
+ MEM_freeN((void *)obj->colors);
+ }
+ MEM_freeN(icon->obj);
+ }
+
if (icon->drawinfo_free) {
icon->drawinfo_free(icon->drawinfo);
}
@@ -95,6 +118,22 @@ static void icon_free(void *val)
}
}
+static void icon_free_data(Icon *icon)
+{
+ if (icon->obj_type == ICON_DATA_ID) {
+ ((ID *)(icon->obj))->icon_id = 0;
+ }
+ else if (icon->obj_type == ICON_DATA_PREVIEW) {
+ ((PreviewImage *)(icon->obj))->icon_id = 0;
+ }
+ else if (icon->obj_type == ICON_DATA_GEOM) {
+ ((struct Icon_Geom *)(icon->obj))->icon_id = 0;
+ }
+ else {
+ BLI_assert(0);
+ }
+}
+
/* create an id for a new icon and make sure that ids from deleted icons get reused
* after the integer number range is used up */
static int get_next_free_id(void)
@@ -284,6 +323,7 @@ PreviewImage **BKE_previewimg_id_get_p(const ID *id)
ID_PRV_CASE(ID_OB, Object);
ID_PRV_CASE(ID_GR, Group);
ID_PRV_CASE(ID_SCE, Scene);
+ ID_PRV_CASE(ID_SCR, bScreen);
#undef ID_PRV_CASE
default:
break;
@@ -476,6 +516,7 @@ void BKE_icon_changed(const int icon_id)
if (icon) {
/* We *only* expect ID-tied icons here, not non-ID icon/preview! */
BLI_assert(icon->id_type != 0);
+ BLI_assert(icon->obj_type == ICON_DATA_ID);
/* Do not enforce creation of previews for valid ID types using BKE_previewimg_id_ensure() here ,
* we only want to ensure *existing* preview images are properly tagged as changed/invalid, that's all. */
@@ -492,22 +533,31 @@ void BKE_icon_changed(const int icon_id)
}
}
-static int icon_id_ensure_create_icon(struct ID *id)
+static Icon *icon_create(int icon_id, int obj_type, void *obj)
{
- BLI_assert(BLI_thread_is_main());
-
- Icon *new_icon = NULL;
+ Icon *new_icon = MEM_mallocN(sizeof(Icon), __func__);
- new_icon = MEM_mallocN(sizeof(Icon), __func__);
-
- new_icon->obj = id;
- new_icon->id_type = GS(id->name);
+ new_icon->obj_type = obj_type;
+ new_icon->obj = obj;
+ new_icon->id_type = 0;
+ new_icon->flag = 0;
/* next two lines make sure image gets created */
new_icon->drawinfo = NULL;
new_icon->drawinfo_free = NULL;
- BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(id->icon_id), new_icon);
+ BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(icon_id), new_icon);
+
+ return new_icon;
+}
+
+static int icon_id_ensure_create_icon(struct ID *id)
+{
+ BLI_assert(BLI_thread_is_main());
+
+ Icon *icon = icon_create(id->icon_id, ICON_DATA_ID, id);
+ icon->id_type = GS(id->name);
+ icon->flag = ICON_FLAG_MANAGED;
return id->icon_id;
}
@@ -542,8 +592,6 @@ int BKE_icon_id_ensure(struct ID *id)
*/
int BKE_icon_preview_ensure(ID *id, PreviewImage *preview)
{
- Icon *new_icon = NULL;
-
if (!preview || G.background)
return 0;
@@ -574,16 +622,8 @@ int BKE_icon_preview_ensure(ID *id, PreviewImage *preview)
return icon_id_ensure_create_icon(id);
}
- new_icon = MEM_mallocN(sizeof(Icon), __func__);
-
- new_icon->obj = preview;
- new_icon->id_type = 0; /* Special, tags as non-ID icon/preview. */
-
- /* next two lines make sure image gets created */
- new_icon->drawinfo = NULL;
- new_icon->drawinfo_free = NULL;
-
- BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(preview->icon_id), new_icon);
+ Icon *icon = icon_create(preview->icon_id, ICON_DATA_PREVIEW, preview);
+ icon->flag = ICON_FLAG_MANAGED;
return preview->icon_id;
}
@@ -645,21 +685,116 @@ void BKE_icon_id_delete(struct ID *id)
/**
* Remove icon and free data.
*/
-void BKE_icon_delete(const int icon_id)
+bool BKE_icon_delete(const int icon_id)
{
- Icon *icon;
+ if (icon_id == 0) {
+ /* no icon defined for library object */
+ return false;
+ }
- if (!icon_id) return; /* no icon defined for library object */
+ Icon *icon = BLI_ghash_popkey(gIcons, SET_INT_IN_POINTER(icon_id), NULL);
+ if (icon) {
+ icon_free_data(icon);
+ icon_free(icon);
+ return true;
+ }
+ else {
+ return false;
+ }
+}
- icon = BLI_ghash_popkey(gIcons, SET_INT_IN_POINTER(icon_id), NULL);
+bool BKE_icon_delete_unmanaged(const int icon_id)
+{
+ if (icon_id == 0) {
+ /* no icon defined for library object */
+ return false;
+ }
+ Icon *icon = BLI_ghash_popkey(gIcons, SET_INT_IN_POINTER(icon_id), NULL);
if (icon) {
- if (icon->id_type != 0) {
- ((ID *)(icon->obj))->icon_id = 0;
+ if (UNLIKELY(icon->flag & ICON_FLAG_MANAGED)) {
+ BLI_ghash_insert(gIcons, SET_INT_IN_POINTER(icon_id), icon);
+ return false;
}
else {
- ((PreviewImage *)(icon->obj))->icon_id = 0;
+ icon_free_data(icon);
+ icon_free(icon);
+ return true;
}
- icon_free(icon);
}
+ else {
+ return false;
+ }
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Geometry Icon
+ * \{ */
+
+int BKE_icon_geom_ensure(struct Icon_Geom *geom)
+{
+ BLI_assert(BLI_thread_is_main());
+
+ if (geom->icon_id) {
+ return geom->icon_id;
+ }
+
+ geom->icon_id = get_next_free_id();
+
+ icon_create(geom->icon_id, ICON_DATA_GEOM, geom);
+ /* Not managed for now, we may want this to be configurable per icon). */
+
+ return geom->icon_id;
+}
+
+struct Icon_Geom *BKE_icon_geom_from_memory(const uchar *data, size_t data_len)
+{
+ BLI_assert(BLI_thread_is_main());
+ if (data_len <= 8) {
+ goto fail;
+ }
+ /* Skip the header. */
+ data_len -= 8;
+ const int div = 3 * 2 * 3;
+ const int coords_len = data_len / div;
+ if (coords_len * div != data_len) {
+ goto fail;
+ }
+
+ const uchar header[4] = {'V', 'C', 'O', 0};
+ const uchar *p = data;
+ if (memcmp(p, header, ARRAY_SIZE(header)) != 0) {
+ goto fail;
+ }
+ p += 4;
+
+ struct Icon_Geom *geom = MEM_mallocN(sizeof(*geom), __func__);
+ geom->coords_range[0] = (int)*p++;
+ geom->coords_range[1] = (int)*p++;
+ /* x, y ignored for now */
+ p += 2;
+
+ geom->coords_len = coords_len;
+ geom->coords = (const void *)p;
+ geom->colors = (const void *)(p + (data_len / 3));
+ geom->icon_id = 0;
+ geom->mem = data;
+ return geom;
+
+fail:
+ MEM_freeN((void *)data);
+ return NULL;
+}
+
+struct Icon_Geom *BKE_icon_geom_from_file(const char *filename)
+{
+ BLI_assert(BLI_thread_is_main());
+ size_t data_len;
+ uchar *data = BLI_file_read_binary_as_mem(filename, 0, &data_len);
+ if (data == NULL) {
+ return NULL;
+ }
+ return BKE_icon_geom_from_memory(data, data_len);
}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/icons_rasterize.c b/source/blender/blenkernel/intern/icons_rasterize.c
new file mode 100644
index 00000000000..24576c24953
--- /dev/null
+++ b/source/blender/blenkernel/intern/icons_rasterize.c
@@ -0,0 +1,146 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/blenkernel/intern/icons_rasterize.c
+ * \ingroup bke
+ */
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_bitmap_draw_2d.h"
+#include "BLI_math_geom.h"
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
+#include "BKE_icons.h"
+
+#include "BLI_strict_flags.h"
+
+struct UserRasterInfo {
+ int pt[3][2];
+ const uint *color;
+ /* only for smooth shading */
+ struct {
+ float pt_fl[3][2];
+ uint color_u[3][4];
+ } smooth;
+ int rect_size[2];
+ uint *rect;
+};
+
+static void tri_fill_flat(int x, int x_end, int y, void *user_data)
+{
+ struct UserRasterInfo *data = user_data;
+ uint *p = &data->rect[(y * data->rect_size[1]) + x];
+ uint col = data->color[0];
+ while (x++ != x_end) {
+ *p++ = col;
+ }
+}
+
+static void tri_fill_smooth(int x, int x_end, int y, void *user_data)
+{
+ struct UserRasterInfo *data = user_data;
+ uint *p = &data->rect[(y * data->rect_size[1]) + x];
+ float pt_step_fl[2] = {(float)x, (float)y};
+ while (x++ != x_end) {
+ float w[3];
+ barycentric_weights_v2_clamped(UNPACK3(data->smooth.pt_fl), pt_step_fl, w);
+
+ uint col_u[4] = {0, 0, 0, 0};
+ for (uint corner = 0; corner < 3; corner++) {
+ for (uint chan = 0; chan < 4; chan++) {
+ col_u[chan] += data->smooth.color_u[corner][chan] * (uint)(w[corner] * 255.0f);
+ }
+ }
+ union {
+ uint as_u32;
+ uchar as_bytes[4];
+ } col;
+ col.as_bytes[0] = (uchar)(col_u[0] / 255);
+ col.as_bytes[1] = (uchar)(col_u[1] / 255);
+ col.as_bytes[2] = (uchar)(col_u[2] / 255);
+ col.as_bytes[3] = (uchar)(col_u[3] / 255);
+ *p++ = col.as_u32;
+
+ pt_step_fl[0] += 1.0f;
+ }
+}
+
+ImBuf *BKE_icon_geom_rasterize(
+ const struct Icon_Geom *geom,
+ const unsigned int size_x, const unsigned int size_y)
+{
+ const int coords_len = geom->coords_len;
+
+ const uchar (*pos)[2] = geom->coords;
+ const uint *col = (void *)geom->colors;
+
+ /* TODO(campbell): Currently rasterizes to fixed size, then scales.
+ * Should rasterize to double size for eg instead. */
+ const int rect_size[2] = {max_ii(256, (int)size_x * 2), max_ii(256, (int)size_y * 2)};
+
+ ImBuf *ibuf = IMB_allocImBuf((uint)rect_size[0], (uint)rect_size[1], 32, IB_rect);
+
+ struct UserRasterInfo data;
+
+ data.rect_size[0] = rect_size[0];
+ data.rect_size[1] = rect_size[1];
+
+ data.rect = ibuf->rect;
+
+ float scale[2];
+ const bool use_scale = (rect_size[0] != 256) || (rect_size[1] != 256);
+
+ if (use_scale) {
+ scale[0] = ((float)rect_size[0] / 256.0f);
+ scale[1] = ((float)rect_size[1] / 256.0f);
+ }
+
+ for (int t = 0; t < coords_len; t += 1, pos += 3, col += 3) {
+ if (use_scale) {
+ ARRAY_SET_ITEMS(data.pt[0], (int)(pos[0][0] * scale[0]), (int)(pos[0][1] * scale[1]));
+ ARRAY_SET_ITEMS(data.pt[1], (int)(pos[1][0] * scale[0]), (int)(pos[1][1] * scale[1]));
+ ARRAY_SET_ITEMS(data.pt[2], (int)(pos[2][0] * scale[0]), (int)(pos[2][1] * scale[1]));
+ }
+ else {
+ ARRAY_SET_ITEMS(data.pt[0], UNPACK2(pos[0]));
+ ARRAY_SET_ITEMS(data.pt[1], UNPACK2(pos[1]));
+ ARRAY_SET_ITEMS(data.pt[2], UNPACK2(pos[2]));
+ }
+ data.color = col;
+ if ((col[0] == col[1]) && (col[0] == col[2])) {
+ BLI_bitmap_draw_2d_tri_v2i(UNPACK3(data.pt), tri_fill_flat, &data);
+ }
+ else {
+ ARRAY_SET_ITEMS(data.smooth.pt_fl[0], UNPACK2_EX((float), data.pt[0], ));
+ ARRAY_SET_ITEMS(data.smooth.pt_fl[1], UNPACK2_EX((float), data.pt[1], ));
+ ARRAY_SET_ITEMS(data.smooth.pt_fl[2], UNPACK2_EX((float), data.pt[2], ));
+ ARRAY_SET_ITEMS(data.smooth.color_u[0], UNPACK4_EX((uint), ((uchar *)(col + 0)), ));
+ ARRAY_SET_ITEMS(data.smooth.color_u[1], UNPACK4_EX((uint), ((uchar *)(col + 1)), ));
+ ARRAY_SET_ITEMS(data.smooth.color_u[2], UNPACK4_EX((uint), ((uchar *)(col + 2)), ));
+ BLI_bitmap_draw_2d_tri_v2i(UNPACK3(data.pt), tri_fill_smooth, &data);
+ }
+ }
+ IMB_scaleImBuf(ibuf, size_x, size_y);
+ return ibuf;
+}
diff --git a/source/blender/blenkernel/intern/idcode.c b/source/blender/blenkernel/intern/idcode.c
index 70d037d85f3..487635f06ad 100644
--- a/source/blender/blenkernel/intern/idcode.c
+++ b/source/blender/blenkernel/intern/idcode.c
@@ -81,8 +81,9 @@ static IDType idtypes[] = {
{ ID_PA, "ParticleSettings", "particles", BLT_I18NCONTEXT_ID_PARTICLESETTINGS, IDTYPE_FLAGS_ISLINKABLE },
{ ID_PAL, "Palettes", "palettes", BLT_I18NCONTEXT_ID_PALETTE, IDTYPE_FLAGS_ISLINKABLE },
{ ID_PC, "PaintCurve", "paint_curves", BLT_I18NCONTEXT_ID_PAINTCURVE, IDTYPE_FLAGS_ISLINKABLE },
+ { ID_LP, "LightProbe", "light_probes", BLT_I18NCONTEXT_ID_LIGHTPROBE, IDTYPE_FLAGS_ISLINKABLE },
{ ID_SCE, "Scene", "scenes", BLT_I18NCONTEXT_ID_SCENE, IDTYPE_FLAGS_ISLINKABLE },
- { ID_SCR, "Screen", "screens", BLT_I18NCONTEXT_ID_SCREEN, 0 },
+ { ID_SCR, "Screen", "screens", BLT_I18NCONTEXT_ID_SCREEN, IDTYPE_FLAGS_ISLINKABLE },
{ ID_SEQ, "Sequence", "sequences", BLT_I18NCONTEXT_ID_SEQUENCE, 0 }, /* not actually ID data */
{ ID_SPK, "Speaker", "speakers", BLT_I18NCONTEXT_ID_SPEAKER, IDTYPE_FLAGS_ISLINKABLE },
{ ID_SO, "Sound", "sounds", BLT_I18NCONTEXT_ID_SOUND, IDTYPE_FLAGS_ISLINKABLE },
@@ -91,6 +92,7 @@ static IDType idtypes[] = {
{ ID_VF, "VFont", "fonts", BLT_I18NCONTEXT_ID_VFONT, IDTYPE_FLAGS_ISLINKABLE },
{ ID_WO, "World", "worlds", BLT_I18NCONTEXT_ID_WORLD, IDTYPE_FLAGS_ISLINKABLE },
{ ID_WM, "WindowManager", "window_managers", BLT_I18NCONTEXT_ID_WINDOWMANAGER, 0 },
+ { ID_WS, "WorkSpace", "workspaces", BLT_I18NCONTEXT_ID_WORKSPACE, IDTYPE_FLAGS_ISLINKABLE },
/** Keep last, not an ID exactly, only include for completeness */
{ ID_ID, "ID", "ids", BLT_I18NCONTEXT_ID_ID, 0 }, /* plural is fake */
@@ -203,6 +205,7 @@ int BKE_idcode_to_idfilter(const short idcode)
CASE_IDFILTER(PA);
CASE_IDFILTER(PAL);
CASE_IDFILTER(PC);
+ CASE_IDFILTER(LP);
CASE_IDFILTER(SCE);
CASE_IDFILTER(SPK);
CASE_IDFILTER(SO);
@@ -210,6 +213,7 @@ int BKE_idcode_to_idfilter(const short idcode)
CASE_IDFILTER(TXT);
CASE_IDFILTER(VF);
CASE_IDFILTER(WO);
+ CASE_IDFILTER(WS);
default:
return 0;
}
@@ -247,6 +251,7 @@ short BKE_idcode_from_idfilter(const int idfilter)
CASE_IDFILTER(PA);
CASE_IDFILTER(PAL);
CASE_IDFILTER(PC);
+ CASE_IDFILTER(LP);
CASE_IDFILTER(SCE);
CASE_IDFILTER(SPK);
CASE_IDFILTER(SO);
@@ -294,6 +299,7 @@ int BKE_idcode_to_index(const short idcode)
CASE_IDINDEX(PA);
CASE_IDINDEX(PAL);
CASE_IDINDEX(PC);
+ CASE_IDINDEX(LP);
CASE_IDINDEX(SCE);
CASE_IDINDEX(SCR);
CASE_IDINDEX(SPK);
@@ -303,6 +309,7 @@ int BKE_idcode_to_index(const short idcode)
CASE_IDINDEX(VF);
CASE_IDINDEX(WM);
CASE_IDINDEX(WO);
+ CASE_IDINDEX(WS);
}
BLI_assert(0);
diff --git a/source/blender/blenkernel/intern/idprop.c b/source/blender/blenkernel/intern/idprop.c
index fe00d68b4ea..0c5078e3e36 100644
--- a/source/blender/blenkernel/intern/idprop.c
+++ b/source/blender/blenkernel/intern/idprop.c
@@ -476,6 +476,7 @@ static IDProperty *IDP_CopyGroup(const IDProperty *prop, const int flag)
BLI_assert(prop->type == IDP_GROUP);
newp = idp_generic_copy(prop, flag);
newp->len = prop->len;
+ newp->subtype = prop->subtype;
for (link = prop->data.group.first; link; link = link->next) {
BLI_addtail(&newp->data.group, IDP_CopyProperty_ex(link, flag));
@@ -601,8 +602,9 @@ void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop)
/**
* If a property is missing in \a dest, add it.
+ * Do it recursively.
*/
-void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite)
+void IDP_MergeGroup_ex(IDProperty *dest, const IDProperty *src, const bool do_overwrite, const int flag)
{
IDProperty *prop;
@@ -611,14 +613,30 @@ void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overw
if (do_overwrite) {
for (prop = src->data.group.first; prop; prop = prop->next) {
- IDProperty *copy = IDP_CopyProperty(prop);
+ if (prop->type == IDP_GROUP) {
+ IDProperty *prop_exist = IDP_GetPropertyFromGroup(dest, prop->name);
+
+ if (prop_exist != NULL) {
+ IDP_MergeGroup_ex(prop_exist, prop, do_overwrite, flag);
+ continue;
+ }
+ }
+
+ IDProperty *copy = IDP_CopyProperty_ex(prop, flag);
IDP_ReplaceInGroup(dest, copy);
}
}
else {
for (prop = src->data.group.first; prop; prop = prop->next) {
- if (IDP_GetPropertyFromGroup(dest, prop->name) == NULL) {
- IDProperty *copy = IDP_CopyProperty(prop);
+ IDProperty *prop_exist = IDP_GetPropertyFromGroup(dest, prop->name);
+ if (prop_exist != NULL) {
+ if (prop->type == IDP_GROUP) {
+ IDP_MergeGroup_ex(prop_exist, prop, do_overwrite, flag);
+ continue;
+ }
+ }
+ else {
+ IDProperty *copy = IDP_CopyProperty_ex(prop, flag);
dest->len++;
BLI_addtail(&dest->data.group, copy);
}
@@ -627,6 +645,15 @@ void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overw
}
/**
+ * If a property is missing in \a dest, add it.
+ * Do it recursively.
+ */
+void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, const bool do_overwrite)
+{
+ IDP_MergeGroup_ex(dest, src, do_overwrite, 0);
+}
+
+/**
* This function has a sanity check to make sure ID properties with the same name don't
* get added to the group.
*
@@ -1067,5 +1094,16 @@ void IDP_ClearProperty(IDProperty *prop)
prop->len = prop->totallen = 0;
}
+void IDP_Reset(IDProperty *prop, const IDProperty *reference)
+{
+ if (prop == NULL) {
+ return;
+ }
+ IDP_ClearProperty(prop);
+ if (reference != NULL) {
+ IDP_MergeGroup(prop, reference, true);
+ }
+}
+
/** \} */
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index e8b5ce77613..50b1756ff87 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -82,6 +82,7 @@
#include "BKE_scene.h"
#include "BKE_node.h"
#include "BKE_sequencer.h" /* seq_foreground_frame_get() */
+#include "BKE_workspace.h"
#include "BLF_api.h"
@@ -369,7 +370,6 @@ static void image_init(Image *ima, short source, short type)
ima->ok = IMA_OK;
- ima->xrep = ima->yrep = 1;
ima->aspx = ima->aspy = 1.0;
ima->gen_x = 1024; ima->gen_y = 1024;
ima->gen_type = IMA_GENTYPE_GRID;
@@ -472,12 +472,10 @@ void BKE_image_copy_data(Main *UNUSED(bmain), Image *ima_dst, const Image *ima_s
BLI_listbase_clear(&ima_dst->anims);
- ima_dst->totbind = 0;
for (int i = 0; i < TEXTARGET_COUNT; i++) {
ima_dst->bindcode[i] = 0;
ima_dst->gputexture[i] = NULL;
}
- ima_dst->repbind = NULL;
if ((flag & LIB_ID_COPY_NO_PREVIEW) == 0) {
BKE_previewimg_id_copy(&ima_dst->id, &ima_src->id);
@@ -2653,19 +2651,19 @@ void BKE_image_walk_all_users(const Main *mainp, void *customdata,
}
}
+ for (Camera *cam = mainp->camera.first; cam; cam = cam->id.next) {
+ for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+ callback(bgpic->ima, &bgpic->iuser, customdata);
+ }
+ }
+
/* image window, compo node users */
for (wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
for (win = wm->windows.first; win; win = win->next) {
- ScrArea *sa;
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
- if (sa->spacetype == SPACE_VIEW3D) {
- View3D *v3d = sa->spacedata.first;
- BGpic *bgpic;
- for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- callback(bgpic->ima, &bgpic->iuser, customdata);
- }
- }
- else if (sa->spacetype == SPACE_IMAGE) {
+ const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ if (sa->spacetype == SPACE_IMAGE) {
SpaceImage *sima = sa->spacedata.first;
callback(sima->image, &sima->iuser, customdata);
}
diff --git a/source/blender/blenkernel/intern/ipo.c b/source/blender/blenkernel/intern/ipo.c
index fcbc25ebad5..941c7eb2a87 100644
--- a/source/blender/blenkernel/intern/ipo.c
+++ b/source/blender/blenkernel/intern/ipo.c
@@ -46,7 +46,6 @@
/* since we have versioning code here */
#define DNA_DEPRECATED_ALLOW
-#include "DNA_actuator_types.h"
#include "DNA_anim_types.h"
#include "DNA_constraint_types.h"
#include "DNA_camera_types.h"
@@ -146,17 +145,6 @@ static AdrBit2Path ob_layer_bits[] = {
{(1 << 19), "layers", 19}
};
-/* Material mode */
-static AdrBit2Path ma_mode_bits[] = {
-// {MA_TRACEBLE, "traceable", 0},
-// {MA_SHADOW, "shadow", 0},
-// {MA_SHLESS, "shadeless", 0},
-// ...
- {MA_RAYTRANSP, "transparency", 0},
- {MA_RAYMIRROR, "raytrace_mirror.enabled", 0},
-// {MA_HALO, "type", MA_TYPE_HALO}
-};
-
/* ----------------- */
/* quick macro for returning the appropriate array for adrcode_bitmaps_to_paths() */
@@ -173,9 +161,6 @@ static AdrBit2Path *adrcode_bitmaps_to_paths(int blocktype, int adrcode, int *to
if ((blocktype == ID_OB) && (adrcode == OB_LAY)) {
RET_ABP(ob_layer_bits);
}
- else if ((blocktype == ID_MA) && (adrcode == MA_MODE)) {
- RET_ABP(ma_mode_bits);
- }
// XXX TODO: add other types...
/* Normal curve */
@@ -1768,23 +1753,6 @@ void do_versions_ipos_to_animato(Main *main)
ipo_to_animdata(id, ob->ipo, NULL, NULL, NULL);
id_us_min(&ob->ipo->id);
ob->ipo = NULL;
-
- {
- /* If we have any empty action actuators, assume they were
- * converted IPO Actuators using the object IPO */
- bActuator *act;
- bActionActuator *aa;
-
- for (act = ob->actuators.first; act; act = act->next) {
- /* Any actuators set to ACT_IPO at this point are actually Action Actuators that
- * need this converted IPO to finish converting the actuator. */
- if (act->type == ACT_IPO) {
- aa = (bActionActuator *)act->data;
- aa->act = ob->adt->action;
- act->type = ACT_ACTION;
- }
- }
- }
}
}
diff --git a/source/blender/blenkernel/intern/lamp.c b/source/blender/blenkernel/intern/lamp.c
index 2714c4f43a1..195280aad5a 100644
--- a/source/blender/blenkernel/intern/lamp.c
+++ b/source/blender/blenkernel/intern/lamp.c
@@ -64,42 +64,30 @@ void BKE_lamp_init(Lamp *la)
la->spotsize = DEG2RADF(45.0f);
la->spotblend = 0.15f;
la->att2 = 1.0f;
- la->mode = LA_SHAD_BUF;
+ la->mode = LA_SHADOW;
la->bufsize = 512;
la->clipsta = 0.5f;
la->clipend = 40.0f;
+ la->bleedexp = 2.5f;
la->samp = 3;
la->bias = 1.0f;
la->soft = 3.0f;
- la->compressthresh = 0.05f;
- la->ray_samp = la->ray_sampy = la->ray_sampz = 1;
la->area_size = la->area_sizey = la->area_sizez = 0.1f;
la->buffers = 1;
- la->buftype = LA_SHADBUF_HALFWAY;
- la->ray_samp_method = LA_SAMP_HALTON;
- la->adapt_thresh = 0.001f;
la->preview = NULL;
la->falloff_type = LA_FALLOFF_INVSQUARE;
la->coeff_const = 1.0f;
la->coeff_lin = 0.0f;
la->coeff_quad = 0.0f;
la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
- la->sun_effect_type = 0;
- la->horizon_brightness = 1.0;
- la->spread = 1.0;
- la->sun_brightness = 1.0;
- la->sun_size = 1.0;
- la->backscattered_light = 1.0f;
- la->atm_turbidity = 2.0f;
- la->atm_inscattering_factor = 1.0f;
- la->atm_extinction_factor = 1.0f;
- la->atm_distance_factor = 1.0f;
- la->sun_intensity = 1.0f;
- la->skyblendtype = MA_RAMP_ADD;
- la->skyblendfac = 1.0f;
- la->sky_colorspace = BLI_XYZ_CIE;
- la->sky_exposure = 1.0f;
- la->shadow_frustum_size = 10.0f;
+ la->cascade_max_dist = 1000.0f;
+ la->cascade_count = 4;
+ la->cascade_exponent = 0.8f;
+ la->cascade_fade = 0.1f;
+ la->contact_dist = 1.0f;
+ la->contact_bias = 0.03f;
+ la->contact_spread = 0.2f;
+ la->contact_thickness = 0.5f;
curvemapping_initialize(la->curfalloff);
}
@@ -125,13 +113,6 @@ Lamp *BKE_lamp_add(Main *bmain, const char *name)
*/
void BKE_lamp_copy_data(Main *bmain, Lamp *la_dst, const Lamp *la_src, const int flag)
{
- for (int a = 0; a < MAX_MTEX; a++) {
- if (la_dst->mtex[a]) {
- la_dst->mtex[a] = MEM_mallocN(sizeof(*la_dst->mtex[a]), __func__);
- *la_dst->mtex[a] = *la_src->mtex[a];
- }
- }
-
la_dst->curfalloff = curvemapping_copy(la_src->curfalloff);
if (la_src->nodetree) {
@@ -164,18 +145,8 @@ Lamp *BKE_lamp_localize(Lamp *la)
*
* ... Once f*** nodes are fully converted to that too :( */
- Lamp *lan;
- int a;
-
- lan = BKE_libblock_copy_nolib(&la->id, false);
+ Lamp *lan = BKE_libblock_copy_nolib(&la->id, false);
- for (a = 0; a < MAX_MTEX; a++) {
- if (lan->mtex[a]) {
- lan->mtex[a] = MEM_mallocN(sizeof(MTex), __func__);
- memcpy(lan->mtex[a], la->mtex[a], sizeof(MTex));
- }
- }
-
lan->curfalloff = curvemapping_copy(la->curfalloff);
if (la->nodetree)
@@ -193,12 +164,6 @@ void BKE_lamp_make_local(Main *bmain, Lamp *la, const bool lib_local)
void BKE_lamp_free(Lamp *la)
{
- int a;
-
- for (a = 0; a < MAX_MTEX; a++) {
- MEM_SAFE_FREE(la->mtex[a]);
- }
-
BKE_animdata_free((ID *)la, false);
curvemapping_free(la->curfalloff);
@@ -214,41 +179,3 @@ void BKE_lamp_free(Lamp *la)
BKE_icon_id_delete(&la->id);
la->id.icon_id = 0;
}
-
-/* Calculate all drivers for lamps, see material_drivers_update for why this is a bad hack */
-
-static void lamp_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime)
-{
- bNode *node;
-
- /* nodetree itself */
- if (ntree->adt && ntree->adt->drivers.first)
- BKE_animsys_evaluate_animdata(scene, &ntree->id, ntree->adt, ctime, ADT_RECALC_DRIVERS);
-
- /* nodes */
- for (node = ntree->nodes.first; node; node = node->next)
- if (node->id && node->type == NODE_GROUP)
- lamp_node_drivers_update(scene, (bNodeTree *)node->id, ctime);
-}
-
-void lamp_drivers_update(Scene *scene, Lamp *la, float ctime)
-{
- /* Prevent infinite recursion by checking (and tagging the lamp) as having been visited already
- * (see BKE_scene_update_tagged()). This assumes la->id.tag & LIB_TAG_DOIT isn't set by anything else
- * in the meantime... [#32017] */
- if (la->id.tag & LIB_TAG_DOIT)
- return;
-
- la->id.tag |= LIB_TAG_DOIT;
-
- /* lamp itself */
- if (la->adt && la->adt->drivers.first)
- BKE_animsys_evaluate_animdata(scene, &la->id, la->adt, ctime, ADT_RECALC_DRIVERS);
-
- /* nodes */
- if (la->nodetree)
- lamp_node_drivers_update(scene, la->nodetree, ctime);
-
- la->id.tag &= ~LIB_TAG_DOIT;
-}
-
diff --git a/source/blender/blenkernel/intern/lattice.c b/source/blender/blenkernel/intern/lattice.c
index 4b9748133d7..609c4b95dab 100644
--- a/source/blender/blenkernel/intern/lattice.c
+++ b/source/blender/blenkernel/intern/lattice.c
@@ -53,7 +53,6 @@
#include "BKE_anim.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_displist.h"
#include "BKE_key.h"
#include "BKE_lattice.h"
@@ -66,11 +65,6 @@
#include "BKE_deform.h"
-/* Workaround for cyclic dependency with curves.
- * In such case curve_cache might not be ready yet,
- */
-#define CYCLIC_DEPENDENCY_WORKAROUND
-
int BKE_lattice_index_from_uvw(Lattice *lt,
const int u, const int v, const int w)
{
@@ -313,6 +307,8 @@ void BKE_lattice_free(Lattice *lt)
{
BKE_animdata_free(&lt->id, false);
+ BKE_lattice_batch_cache_free(lt);
+
MEM_SAFE_FREE(lt->def);
if (lt->dvert) {
BKE_defvert_array_free(lt->dvert, lt->pntsu * lt->pntsv * lt->pntsw);
@@ -601,7 +597,7 @@ static bool where_on_path_deform(Object *ob, float ctime, float vec[4], float di
/* co: local coord, result local too */
/* returns quaternion for rotation, using cd->no_rot_axis */
/* axis is using another define!!! */
-static bool calc_curve_deform(Scene *scene, Object *par, float co[3],
+static bool calc_curve_deform(Object *par, float co[3],
const short axis, CurveDeform *cd, float r_quat[4])
{
Curve *cu = par->data;
@@ -609,12 +605,10 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3],
short index;
const bool is_neg_axis = (axis > 2);
- /* to be sure, mostly after file load, also cyclic dependencies */
-#ifdef CYCLIC_DEPENDENCY_WORKAROUND
if (par->curve_cache == NULL) {
- BKE_displist_make_curveTypes(scene, par, false);
+ /* Happens with a cyclic dependencies. */
+ return false;
}
-#endif
if (par->curve_cache->path == NULL) {
return false; /* happens on append, cyclic dependencies and empty curves */
@@ -705,7 +699,7 @@ static bool calc_curve_deform(Scene *scene, Object *par, float co[3],
}
void curve_deform_verts(
- Scene *scene, Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3],
+ Object *cuOb, Object *target, DerivedMesh *dm, float (*vertexCos)[3],
int numVerts, const char *vgroup, short defaxis)
{
Curve *cu;
@@ -764,7 +758,7 @@ void curve_deform_verts(
if (weight > 0.0f) {
mul_m4_v3(cd.curvespace, vertexCos[a]);
copy_v3_v3(vec, vertexCos[a]);
- calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
+ calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
@@ -787,7 +781,7 @@ void curve_deform_verts(
if (weight > 0.0f) {
/* already in 'cd.curvespace', prev for loop */
copy_v3_v3(vec, vertexCos[a]);
- calc_curve_deform(scene, cuOb, vec, defaxis, &cd, NULL);
+ calc_curve_deform(cuOb, vec, defaxis, &cd, NULL);
interp_v3_v3v3(vertexCos[a], vertexCos[a], vec, weight);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
@@ -798,7 +792,7 @@ void curve_deform_verts(
if (cu->flag & CU_DEFORM_BOUNDS_OFF) {
for (a = 0; a < numVerts; a++) {
mul_m4_v3(cd.curvespace, vertexCos[a]);
- calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
+ calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
}
@@ -813,7 +807,7 @@ void curve_deform_verts(
for (a = 0; a < numVerts; a++) {
/* already in 'cd.curvespace', prev for loop */
- calc_curve_deform(scene, cuOb, vertexCos[a], defaxis, &cd, NULL);
+ calc_curve_deform(cuOb, vertexCos[a], defaxis, &cd, NULL);
mul_m4_v3(cd.objectspace, vertexCos[a]);
}
}
@@ -823,7 +817,7 @@ void curve_deform_verts(
/* input vec and orco = local coord in armature space */
/* orco is original not-animated or deformed reference point */
/* result written in vec and mat */
-void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
+void curve_deform_vector(Object *cuOb, Object *target,
float orco[3], float vec[3], float mat[3][3], int no_rot_axis)
{
CurveDeform cd;
@@ -842,7 +836,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
mul_m4_v3(cd.curvespace, vec);
- if (calc_curve_deform(scene, cuOb, vec, target->trackflag, &cd, quat)) {
+ if (calc_curve_deform(cuOb, vec, target->trackflag, &cd, quat)) {
float qmat[3][3];
quat_to_mat3(qmat, quat);
@@ -855,7 +849,7 @@ void curve_deform_vector(Scene *scene, Object *cuOb, Object *target,
}
-void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
+void lattice_deform_verts(Object *laOb, Object *target, Mesh *mesh,
float (*vertexCos)[3], int numVerts, const char *vgroup, float fac)
{
LatticeDeformData *lattice_deform_data;
@@ -873,8 +867,8 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
*/
if (target && target->type == OB_MESH) {
/* if there's derived data without deformverts, don't use vgroups */
- if (dm) {
- use_vgroups = (dm->getVertDataArray(dm, CD_MDEFORMVERT) != NULL);
+ if (mesh) {
+ use_vgroups = (mesh->dvert != NULL);
}
else {
Mesh *me = target->data;
@@ -890,12 +884,10 @@ void lattice_deform_verts(Object *laOb, Object *target, DerivedMesh *dm,
const int defgrp_index = defgroup_name_index(target, vgroup);
float weight;
- if (defgrp_index >= 0 && (me->dvert || dm)) {
- MDeformVert *dvert = me->dvert;
+ if (defgrp_index >= 0 && (me->dvert || mesh)) {
+ MDeformVert *dvert = mesh ? mesh->dvert : me->dvert;
for (a = 0; a < numVerts; a++, dvert++) {
- if (dm) dvert = dm->getVertData(dm, a, CD_MDEFORMVERT);
-
weight = defvert_find_weight(dvert, defgrp_index);
if (weight > 0.0f)
@@ -1032,13 +1024,14 @@ void BKE_lattice_vertexcos_apply(struct Object *ob, float (*vertexCos)[3])
}
}
-void BKE_lattice_modifiers_calc(Scene *scene, Object *ob)
+void BKE_lattice_modifiers_calc(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
{
Lattice *lt = ob->data;
VirtualModifierData virtualModifierData;
ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
float (*vertexCos)[3] = NULL;
int numVerts, editmode = (lt->editlatt != NULL);
+ const ModifierEvalContext mectx = {depsgraph, ob, 0};
if (ob->curve_cache) {
BKE_displist_free(&ob->curve_cache->disp);
@@ -1059,7 +1052,7 @@ void BKE_lattice_modifiers_calc(Scene *scene, Object *ob)
if (mti->type != eModifierTypeType_OnlyDeform) continue;
if (!vertexCos) vertexCos = BKE_lattice_vertexcos_get(ob, &numVerts);
- mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0);
+ modifier_deformVerts_DM_deprecated(md, &mectx, NULL, vertexCos, numVerts);
}
/* always displist to make this work like derivedmesh */
@@ -1233,8 +1226,24 @@ void BKE_lattice_translate(Lattice *lt, float offset[3], bool do_keys)
/* **** Depsgraph evaluation **** */
-void BKE_lattice_eval_geometry(EvaluationContext *UNUSED(eval_ctx),
+void BKE_lattice_eval_geometry(struct Depsgraph *UNUSED(depsgraph),
Lattice *UNUSED(latt))
{
}
+/* Draw Engine */
+void (*BKE_lattice_batch_cache_dirty_cb)(Lattice *lt, int mode) = NULL;
+void (*BKE_lattice_batch_cache_free_cb)(Lattice *lt) = NULL;
+
+void BKE_lattice_batch_cache_dirty(Lattice *lt, int mode)
+{
+ if (lt->batch_cache) {
+ BKE_lattice_batch_cache_dirty_cb(lt, mode);
+ }
+}
+void BKE_lattice_batch_cache_free(Lattice *lt)
+{
+ if (lt->batch_cache) {
+ BKE_lattice_batch_cache_free_cb(lt);
+ }
+}
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
new file mode 100644
index 00000000000..fda14657f3b
--- /dev/null
+++ b/source/blender/blenkernel/intern/layer.c
@@ -0,0 +1,2411 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/layer.c
+ * \ingroup bke
+ */
+
+#include <string.h>
+
+#include "BLI_array.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
+#include "BLT_translation.h"
+
+#include "BKE_collection.h"
+#include "BKE_freestyle.h"
+#include "BKE_global.h"
+#include "BKE_group.h"
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_workspace.h"
+#include "BKE_object.h"
+
+#include "DNA_group_types.h"
+#include "DNA_ID.h"
+#include "DNA_layer_types.h"
+#include "DNA_object_types.h"
+#include "DNA_node_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_debug.h"
+#include "DEG_depsgraph_query.h"
+
+#include "DRW_engine.h"
+
+#include "MEM_guardedalloc.h"
+
+/* prototype */
+struct EngineSettingsCB_Type;
+static void layer_collections_sync_flags(ListBase *layer_collections_dst, const ListBase *layer_collections_src);
+static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc);
+static void layer_collection_objects_populate(ViewLayer *view_layer, LayerCollection *lc, ListBase *objects);
+static LayerCollection *layer_collection_add(ViewLayer *view_layer, LayerCollection *parent, SceneCollection *sc);
+static LayerCollection *find_layer_collection_by_scene_collection(LayerCollection *lc, const SceneCollection *sc);
+static IDProperty *collection_engine_settings_create(struct EngineSettingsCB_Type *ces_type, const bool populate);
+static IDProperty *collection_engine_get(IDProperty *root, const char *engine_name);
+static void collection_engine_settings_init(IDProperty *root, const bool populate);
+static void layer_engine_settings_init(IDProperty *root, const bool populate);
+static void object_bases_iterator_next(BLI_Iterator *iter, const int flag);
+
+/* RenderLayer */
+
+/* Returns the default view layer to view in workspaces if there is
+ * none linked to the workspace yet. */
+ViewLayer *BKE_view_layer_default_view(const Scene *scene)
+{
+ /* TODO: it makes more sense to have the Viewport layer as the default,
+ * but this breaks view layer tests so change it later. */
+#if 0
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ if (!(view_layer->flag & VIEW_LAYER_RENDER)) {
+ return view_layer;
+ }
+ }
+
+ BLI_assert(scene->view_layers.first);
+ return scene->view_layers.first;
+#else
+ return BKE_view_layer_default_render(scene);
+#endif
+}
+
+/* Returns the default view layer to render if we need to render just one. */
+ViewLayer *BKE_view_layer_default_render(const Scene *scene)
+{
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ if (view_layer->flag & VIEW_LAYER_RENDER) {
+ return view_layer;
+ }
+ }
+
+ BLI_assert(scene->view_layers.first);
+ return scene->view_layers.first;
+}
+
+/**
+ * Returns the ViewLayer to be used for drawing, outliner, and other context related areas.
+ */
+ViewLayer *BKE_view_layer_from_workspace_get(const struct Scene *scene, const struct WorkSpace *workspace)
+{
+ return BKE_workspace_view_layer_get(workspace, scene);
+}
+
+/**
+ * This is a placeholder to know which areas of the code need to be addressed for the Workspace changes.
+ * Never use this, you should either use BKE_view_layer_from_workspace_get or get ViewLayer explicitly.
+ */
+ViewLayer *BKE_view_layer_context_active_PLACEHOLDER(const Scene *scene)
+{
+ BLI_assert(scene->view_layers.first);
+ return scene->view_layers.first;
+}
+
+static ViewLayer *view_layer_add(const char *name, SceneCollection *master_scene_collection)
+{
+ if (!name) {
+ name = DATA_("View Layer");
+ }
+
+ IDPropertyTemplate val = {0};
+ ViewLayer *view_layer = MEM_callocN(sizeof(ViewLayer), "View Layer");
+ view_layer->flag = VIEW_LAYER_RENDER | VIEW_LAYER_FREESTYLE;
+
+ view_layer->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ layer_engine_settings_init(view_layer->properties, false);
+ BLI_strncpy_utf8(view_layer->name, name, sizeof(view_layer->name));
+
+ /* Link the master collection by default. */
+ layer_collection_add(view_layer, NULL, master_scene_collection);
+
+ /* Pure rendering pipeline settings. */
+ view_layer->layflag = 0x7FFF; /* solid ztra halo edge strand */
+ view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
+ view_layer->pass_alpha_threshold = 0.5f;
+ BKE_freestyle_config_init(&view_layer->freestyle_config);
+
+ return view_layer;
+}
+
+/**
+ * Add a new view layer
+ * by default, a view layer has the master collection
+ */
+ViewLayer *BKE_view_layer_add(Scene *scene, const char *name)
+{
+ SceneCollection *sc = BKE_collection_master(&scene->id);
+ ViewLayer *view_layer = view_layer_add(name, sc);
+
+ BLI_addtail(&scene->view_layers, view_layer);
+
+ /* unique name */
+ BLI_uniquename(
+ &scene->view_layers, view_layer, DATA_("ViewLayer"), '.',
+ offsetof(ViewLayer, name), sizeof(view_layer->name));
+
+ return view_layer;
+}
+
+/**
+ * Add a ViewLayer for a Group
+ * It should be added only once
+ */
+ViewLayer *BKE_view_layer_group_add(Group *group)
+{
+ BLI_assert(group->view_layer == NULL);
+ SceneCollection *sc = BKE_collection_master(&group->id);
+ ViewLayer *view_layer = view_layer_add(group->id.name + 2, sc);
+ return view_layer;
+}
+
+void BKE_view_layer_free(ViewLayer *view_layer)
+{
+ BKE_view_layer_free_ex(view_layer, true);
+}
+
+/**
+ * Free (or release) any data used by this ViewLayer.
+ */
+void BKE_view_layer_free_ex(ViewLayer *view_layer, const bool do_id_user)
+{
+ view_layer->basact = NULL;
+
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (base->collection_properties) {
+ IDP_FreeProperty(base->collection_properties);
+ MEM_freeN(base->collection_properties);
+ }
+ }
+ BLI_freelistN(&view_layer->object_bases);
+
+ for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) {
+ layer_collection_free(NULL, lc);
+ }
+ BLI_freelistN(&view_layer->layer_collections);
+
+ if (view_layer->properties) {
+ IDP_FreeProperty(view_layer->properties);
+ MEM_freeN(view_layer->properties);
+ }
+
+ if (view_layer->properties_evaluated) {
+ IDP_FreeProperty(view_layer->properties_evaluated);
+ MEM_freeN(view_layer->properties_evaluated);
+ }
+
+ for (ViewLayerEngineData *sled = view_layer->drawdata.first; sled; sled = sled->next) {
+ if (sled->storage) {
+ if (sled->free) {
+ sled->free(sled->storage);
+ }
+ MEM_freeN(sled->storage);
+ }
+ }
+ BLI_freelistN(&view_layer->drawdata);
+
+ MEM_SAFE_FREE(view_layer->stats);
+
+ BKE_freestyle_config_free(&view_layer->freestyle_config, do_id_user);
+
+ if (view_layer->id_properties) {
+ IDP_FreeProperty(view_layer->id_properties);
+ MEM_freeN(view_layer->id_properties);
+ }
+
+ MEM_SAFE_FREE(view_layer->object_bases_array);
+
+ MEM_freeN(view_layer);
+}
+
+/**
+ * Tag all the selected objects of a renderlayer
+ */
+void BKE_view_layer_selected_objects_tag(ViewLayer *view_layer, const int tag)
+{
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if ((base->flag & BASE_SELECTED) != 0) {
+ base->object->flag |= tag;
+ }
+ else {
+ base->object->flag &= ~tag;
+ }
+ }
+}
+
+/**
+ * Return the first ViewLayer for a given id
+ */
+ViewLayer *BKE_view_layer_first_from_id(const ID *owner_id)
+{
+ switch (GS(owner_id->name)) {
+ case ID_SCE:
+ return ((Scene *)owner_id)->view_layers.first;
+ case ID_GR:
+ return ((Group *)owner_id)->view_layer;
+ default:
+ BLI_assert(!"ID doesn't support view layers");
+ return NULL;
+ }
+}
+
+static bool find_scene_collection_in_scene_collections(ListBase *lb, const LayerCollection *lc)
+{
+ for (LayerCollection *lcn = lb->first; lcn; lcn = lcn->next) {
+ if (lcn == lc) {
+ return true;
+ }
+ if (find_scene_collection_in_scene_collections(&lcn->layer_collections, lc)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Fallback for when a Scene has no camera to use
+ *
+ * \param view_layer: in general you want to use the same ViewLayer that is used
+ * for depsgraph. If rendering you pass the scene active layer, when viewing in the viewport
+ * you want to get ViewLayer from context.
+ */
+Object *BKE_view_layer_camera_find(ViewLayer *view_layer)
+{
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (base->object->type == OB_CAMERA) {
+ return base->object;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Find the ViewLayer a LayerCollection belongs to
+ */
+ViewLayer *BKE_view_layer_find_from_collection(const ID *owner_id, LayerCollection *lc)
+{
+ switch (GS(owner_id->name)) {
+ case ID_GR:
+ return ((Group *)owner_id)->view_layer;
+ case ID_SCE:
+ {
+ Scene *scene = (Scene *)owner_id;
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ if (find_scene_collection_in_scene_collections(&view_layer->layer_collections, lc)) {
+ return view_layer;
+ }
+ }
+ return NULL;
+ }
+ default:
+ BLI_assert(!"ID doesn't support scene layers");
+ return NULL;
+ }
+}
+
+/* Base */
+
+Base *BKE_view_layer_base_find(ViewLayer *view_layer, Object *ob)
+{
+ return BLI_findptr(&view_layer->object_bases, ob, offsetof(Base, object));
+}
+
+void BKE_view_layer_base_deselect_all(ViewLayer *view_layer)
+{
+ Base *base;
+
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ base->flag &= ~BASE_SELECTED;
+ }
+}
+
+void BKE_view_layer_base_select(struct ViewLayer *view_layer, Base *selbase)
+{
+ view_layer->basact = selbase;
+ if ((selbase->flag & BASE_SELECTABLED) != 0) {
+ selbase->flag |= BASE_SELECTED;
+ }
+}
+
+/****************************************************************************/
+/* Copying functions for datablocks that use ViewLayer/SceneCollection */
+
+/* Find the equivalent SceneCollection in the new tree */
+static SceneCollection *scene_collection_from_new_tree(
+ SceneCollection *sc_reference, SceneCollection *sc_dst, SceneCollection *sc_src)
+{
+ if (sc_src == sc_reference) {
+ return sc_dst;
+ }
+
+ for (SceneCollection *nsc_src = sc_src->scene_collections.first, *nsc_dst = sc_dst->scene_collections.first;
+ nsc_src;
+ nsc_src = nsc_src->next, nsc_dst = nsc_dst->next)
+ {
+ SceneCollection *found = scene_collection_from_new_tree(sc_reference, nsc_dst, nsc_src);
+ if (found != NULL) {
+ return found;
+ }
+ }
+ return NULL;
+}
+
+static void layer_collection_sync_flags(
+ LayerCollection *layer_collection_dst,
+ const LayerCollection *layer_collection_src)
+{
+ layer_collection_dst->flag = layer_collection_src->flag;
+
+ if (layer_collection_dst->properties != NULL) {
+ IDP_FreeProperty(layer_collection_dst->properties);
+ MEM_SAFE_FREE(layer_collection_dst->properties);
+ }
+
+ if (layer_collection_src->properties != NULL) {
+ layer_collection_dst->properties = IDP_CopyProperty(layer_collection_src->properties);
+ }
+
+ layer_collections_sync_flags(&layer_collection_dst->layer_collections,
+ &layer_collection_src->layer_collections);
+}
+
+static void layer_collections_sync_flags(ListBase *layer_collections_dst, const ListBase *layer_collections_src)
+{
+ BLI_assert(BLI_listbase_count(layer_collections_dst) == BLI_listbase_count(layer_collections_src));
+ LayerCollection *layer_collection_dst = (LayerCollection *)layer_collections_dst->first;
+ const LayerCollection *layer_collection_src = (const LayerCollection *)layer_collections_src->first;
+ while (layer_collection_dst != NULL) {
+ layer_collection_sync_flags(layer_collection_dst, layer_collection_src);
+ layer_collection_dst = layer_collection_dst->next;
+ layer_collection_src = layer_collection_src->next;
+ }
+}
+
+static bool layer_collection_sync_if_match(
+ ListBase *lb,
+ const SceneCollection *scene_collection_dst,
+ const SceneCollection *scene_collection_src)
+{
+ for (LayerCollection *layer_collection = lb->first;
+ layer_collection;
+ layer_collection = layer_collection->next)
+ {
+ if (layer_collection->scene_collection == scene_collection_src) {
+ LayerCollection *layer_collection_dst =
+ BLI_findptr(
+ lb,
+ scene_collection_dst,
+ offsetof(LayerCollection, scene_collection));
+
+ if (layer_collection_dst != NULL) {
+ layer_collection_sync_flags(layer_collection_dst, layer_collection);
+ }
+ return true;
+ }
+ else {
+ if (layer_collection_sync_if_match(
+ &layer_collection->layer_collections,
+ scene_collection_dst,
+ scene_collection_src))
+ {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+/**
+ * Sync sibling collections across all view layers
+ *
+ * Make sure every linked instance of \a scene_collection_dst has the same values
+ * (flags, overrides, ...) as the corresponding scene_collection_src.
+ *
+ * \note expect scene_collection_dst to be scene_collection_src->next, and it also
+ * expects both collections to have the same ammount of sub-collections.
+ */
+void BKE_layer_collection_sync_flags(
+ ID *owner_id,
+ SceneCollection *scene_collection_dst,
+ SceneCollection *scene_collection_src)
+{
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ for (LayerCollection *layer_collection = view_layer->layer_collections.first;
+ layer_collection;
+ layer_collection = layer_collection->next)
+ {
+ layer_collection_sync_if_match(
+ &layer_collection->layer_collections,
+ scene_collection_dst,
+ scene_collection_src);
+ }
+ }
+}
+
+/* recreate the LayerCollection tree */
+static void layer_collections_recreate(
+ ViewLayer *view_layer_dst, ListBase *lb_src, SceneCollection *mc_dst, SceneCollection *mc_src)
+{
+ for (LayerCollection *lc_src = lb_src->first; lc_src; lc_src = lc_src->next) {
+ SceneCollection *sc_dst = scene_collection_from_new_tree(lc_src->scene_collection, mc_dst, mc_src);
+ BLI_assert(sc_dst);
+
+ /* instead of synchronizing both trees we simply re-create it */
+ BKE_collection_link(view_layer_dst, sc_dst);
+ }
+}
+
+/**
+ * Only copy internal data of ViewLayer from source to already allocated/initialized destination.
+ *
+ * \param mc_src Master Collection the source ViewLayer links in.
+ * \param mc_dst Master Collection the destination ViewLayer links in.
+ * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_view_layer_copy_data(
+ ViewLayer *view_layer_dst, ViewLayer *view_layer_src, SceneCollection *mc_dst, SceneCollection *mc_src,
+ const int flag)
+{
+ IDPropertyTemplate val = {0};
+
+ if (view_layer_dst->id_properties != NULL) {
+ view_layer_dst->id_properties = IDP_CopyProperty_ex(view_layer_dst->id_properties, flag);
+ }
+ BKE_freestyle_config_copy(&view_layer_dst->freestyle_config, &view_layer_src->freestyle_config, flag);
+
+ view_layer_dst->stats = NULL;
+ view_layer_dst->properties_evaluated = NULL;
+ view_layer_dst->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ IDP_MergeGroup_ex(view_layer_dst->properties, view_layer_src->properties, true, flag);
+
+ /* we start fresh with no overrides and no visibility flags set
+ * instead of syncing both trees we simply unlink and relink the scene collection */
+ BLI_listbase_clear(&view_layer_dst->layer_collections);
+ BLI_listbase_clear(&view_layer_dst->object_bases);
+ BLI_listbase_clear(&view_layer_dst->drawdata);
+
+ layer_collections_recreate(view_layer_dst, &view_layer_src->layer_collections, mc_dst, mc_src);
+
+ /* Now we handle the syncing for visibility, selectability, ... */
+ layer_collections_sync_flags(&view_layer_dst->layer_collections, &view_layer_src->layer_collections);
+
+ Object *active_ob = OBACT(view_layer_src);
+ for (Base *base_src = view_layer_src->object_bases.first, *base_dst = view_layer_dst->object_bases.first;
+ base_src;
+ base_src = base_src->next, base_dst = base_dst->next)
+ {
+ base_dst->flag = base_src->flag;
+ base_dst->flag_legacy = base_src->flag_legacy;
+
+ if (base_dst->object == active_ob) {
+ view_layer_dst->basact = base_dst;
+ }
+ }
+
+ view_layer_dst->object_bases_array = NULL;
+}
+
+/**
+ * Find and return the ListBase of LayerCollection that has \a lc_child as one of its directly
+ * nested LayerCollection.
+ *
+ * \param lb_parent Initial ListBase of LayerCollection to look into recursively
+ * usually the view layer's collection list
+ */
+static ListBase *find_layer_collection_parent_list_base(ListBase *lb_parent, const LayerCollection *lc_child)
+{
+ for (LayerCollection *lc_nested = lb_parent->first; lc_nested; lc_nested = lc_nested->next) {
+ if (lc_nested == lc_child) {
+ return lb_parent;
+ }
+
+ ListBase *found = find_layer_collection_parent_list_base(&lc_nested->layer_collections, lc_child);
+ if (found != NULL) {
+ return found;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Makes a shallow copy of a LayerCollection
+ *
+ * Add a new collection in the same level as the old one (linking if necessary),
+ * and copy all the collection data across them.
+ */
+struct LayerCollection *BKE_layer_collection_duplicate(struct ID *owner_id, struct LayerCollection *layer_collection)
+{
+ SceneCollection *scene_collection, *scene_collection_new;
+
+ scene_collection = layer_collection->scene_collection;
+ scene_collection_new = BKE_collection_duplicate(owner_id, scene_collection);
+
+ LayerCollection *layer_collection_new = NULL;
+
+ /* If the original layer_collection was directly linked to the view layer
+ we need to link the new scene collection here as well. */
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ if (BLI_findindex(&view_layer->layer_collections, layer_collection) != -1) {
+ layer_collection_new = BKE_collection_link(view_layer, scene_collection_new);
+ layer_collection_sync_flags(layer_collection_new, layer_collection);
+
+ if (layer_collection_new != layer_collection->next) {
+ BLI_remlink(&view_layer->layer_collections, layer_collection_new);
+ BLI_insertlinkafter(&view_layer->layer_collections, layer_collection, layer_collection_new);
+ }
+ break;
+ }
+ }
+
+ /* Otherwise just try to find the corresponding layer collection to return it back. */
+ if (layer_collection_new == NULL) {
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ ListBase *layer_collections_parent;
+ layer_collections_parent = find_layer_collection_parent_list_base(
+ &view_layer->layer_collections,
+ layer_collection);
+ if (layer_collections_parent != NULL) {
+ layer_collection_new = BLI_findptr(
+ layer_collections_parent,
+ scene_collection_new,
+ offsetof(LayerCollection, scene_collection));
+ break;
+ }
+ }
+ }
+ return layer_collection_new;
+}
+
+static void view_layer_object_base_unref(ViewLayer *view_layer, Base *base)
+{
+ base->refcount--;
+
+ /* It only exists in the RenderLayer */
+ if (base->refcount == 0) {
+ if (view_layer->basact == base) {
+ view_layer->basact = NULL;
+ }
+
+ if (base->collection_properties) {
+ IDP_FreeProperty(base->collection_properties);
+ MEM_freeN(base->collection_properties);
+ }
+
+ BLI_remlink(&view_layer->object_bases, base);
+ MEM_freeN(base);
+ }
+}
+
+/**
+ * Return the base if existent, or create it if necessary
+ * Always bump the refcount
+ */
+static Base *object_base_add(ViewLayer *view_layer, Object *ob)
+{
+ Base *base;
+ base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (base == NULL) {
+ base = MEM_callocN(sizeof(Base), "Object Base");
+
+ /* Do not bump user count, leave it for SceneCollections. */
+ base->object = ob;
+ BLI_addtail(&view_layer->object_bases, base);
+
+ IDPropertyTemplate val = {0};
+ base->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ }
+
+ base->refcount++;
+ return base;
+}
+
+/* LayerCollection */
+
+static void layer_collection_objects_unpopulate(ViewLayer *view_layer, LayerCollection *lc)
+{
+ if (view_layer) {
+ for (LinkData *link = lc->object_bases.first; link; link = link->next) {
+ view_layer_object_base_unref(view_layer, link->data);
+ }
+ }
+
+ BLI_freelistN(&lc->object_bases);
+}
+
+/**
+ * When freeing the entire ViewLayer at once we don't bother with unref
+ * otherwise ViewLayer is passed to keep the syncing of the LayerCollection tree
+ */
+static void layer_collection_free(ViewLayer *view_layer, LayerCollection *lc)
+{
+ layer_collection_objects_unpopulate(view_layer, lc);
+ BLI_freelistN(&lc->overrides);
+
+ if (lc->properties) {
+ IDP_FreeProperty(lc->properties);
+ MEM_freeN(lc->properties);
+ }
+
+ if (lc->properties_evaluated) {
+ IDP_FreeProperty(lc->properties_evaluated);
+ MEM_freeN(lc->properties_evaluated);
+ }
+
+ for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
+ layer_collection_free(view_layer, nlc);
+ }
+
+ BLI_freelistN(&lc->layer_collections);
+}
+
+/**
+ * Free (or release) LayerCollection from ViewLayer
+ * (does not free the LayerCollection itself).
+ */
+void BKE_layer_collection_free(ViewLayer *view_layer, LayerCollection *lc)
+{
+ layer_collection_free(view_layer, lc);
+}
+
+/* LayerCollection */
+
+/**
+ * Recursively get the collection for a given index
+ */
+static LayerCollection *collection_from_index(ListBase *lb, const int number, int *i)
+{
+ for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+ if (*i == number) {
+ return lc;
+ }
+
+ (*i)++;
+
+ LayerCollection *lc_nested = collection_from_index(&lc->layer_collections, number, i);
+ if (lc_nested) {
+ return lc_nested;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Get the collection for a given index
+ */
+LayerCollection *BKE_layer_collection_from_index(ViewLayer *view_layer, const int index)
+{
+ int i = 0;
+ return collection_from_index(&view_layer->layer_collections, index, &i);
+}
+
+/**
+ * Get the active collection
+ */
+LayerCollection *BKE_layer_collection_get_active(ViewLayer *view_layer)
+{
+ int i = 0;
+ return collection_from_index(&view_layer->layer_collections, view_layer->active_collection, &i);
+}
+
+
+/**
+ * Return layer collection to add new object(s).
+ * Create one if none exists.
+ */
+LayerCollection *BKE_layer_collection_get_active_ensure(Scene *scene, ViewLayer *view_layer)
+{
+ LayerCollection *lc = BKE_layer_collection_get_active(view_layer);
+
+ if (lc == NULL) {
+ BLI_assert(BLI_listbase_is_empty(&view_layer->layer_collections));
+ /* When there is no collection linked to this ViewLayer, create one. */
+ SceneCollection *sc = BKE_collection_add(&scene->id, NULL, COLLECTION_TYPE_NONE, NULL);
+ lc = BKE_collection_link(view_layer, sc);
+ /* New collection has to be the active one. */
+ BLI_assert(lc == BKE_layer_collection_get_active(view_layer));
+ }
+
+ return lc;
+}
+
+/**
+ * Recursively get the count of collections
+ */
+static int collection_count(ListBase *lb)
+{
+ int i = 0;
+ for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+ i += collection_count(&lc->layer_collections) + 1;
+ }
+ return i;
+}
+
+/**
+ * Get the total number of collections
+ * (including all the nested collections)
+ */
+int BKE_layer_collection_count(ViewLayer *view_layer)
+{
+ return collection_count(&view_layer->layer_collections);
+}
+
+/**
+ * Recursively get the index for a given collection
+ */
+static int index_from_collection(ListBase *lb, const LayerCollection *lc, int *i)
+{
+ for (LayerCollection *lcol = lb->first; lcol; lcol = lcol->next) {
+ if (lcol == lc) {
+ return *i;
+ }
+
+ (*i)++;
+
+ int i_nested = index_from_collection(&lcol->layer_collections, lc, i);
+ if (i_nested != -1) {
+ return i_nested;
+ }
+ }
+ return -1;
+}
+
+/**
+ * Return -1 if not found
+ */
+int BKE_layer_collection_findindex(ViewLayer *view_layer, const LayerCollection *lc)
+{
+ int i = 0;
+ return index_from_collection(&view_layer->layer_collections, lc, &i);
+}
+
+/**
+ * Lookup the listbase that contains \a lc.
+ */
+static ListBase *layer_collection_listbase_find(ListBase *lb, LayerCollection *lc)
+{
+ for (LayerCollection *lc_iter = lb->first; lc_iter; lc_iter = lc_iter->next) {
+ if (lc_iter == lc) {
+ return lb;
+ }
+
+ ListBase *lb_child_result;
+ if ((lb_child_result = layer_collection_listbase_find(&lc_iter->layer_collections, lc))) {
+ return lb_child_result;
+ }
+ }
+
+ return NULL;
+}
+
+#if 0
+/**
+ * Lookup the listbase that contains \a sc.
+ */
+static ListBase *scene_collection_listbase_find(ListBase *lb, SceneCollection *sc)
+{
+ for (SceneCollection *sc_iter = lb->first; sc_iter; sc_iter = sc_iter->next) {
+ if (sc_iter == sc) {
+ return lb;
+ }
+
+ ListBase *lb_child_result;
+ if ((lb_child_result = scene_collection_listbase_find(&sc_iter->scene_collections, sc))) {
+ return lb_child_result;
+ }
+ }
+
+ return NULL;
+}
+#endif
+
+/* ---------------------------------------------------------------------- */
+/* Outliner drag and drop */
+
+/**
+ * Nest a LayerCollection into another one
+ * Both collections must be from the same ViewLayer, return true if succeded.
+ *
+ * The LayerCollection will effectively be moved into the
+ * new (nested) position. So all the settings, overrides, ... go with it, and
+ * if the collection was directly linked to the ViewLayer it's then unlinked.
+ *
+ * For the other ViewLayers we simply resync the tree, without changing directly
+ * linked collections (even if they link to the same SceneCollection)
+ *
+ * \param lc_src LayerCollection to nest into \a lc_dst
+ * \param lc_dst LayerCollection to have \a lc_src inserted into
+ */
+
+static void layer_collection_swap(
+ ViewLayer *view_layer, ListBase *lb_a, ListBase *lb_b,
+ LayerCollection *lc_a, LayerCollection *lc_b)
+{
+ if (lb_a == NULL) {
+ lb_a = layer_collection_listbase_find(&view_layer->layer_collections, lc_a);
+ }
+
+ if (lb_b == NULL) {
+ lb_b = layer_collection_listbase_find(&view_layer->layer_collections, lc_b);
+ }
+
+ BLI_assert(lb_a);
+ BLI_assert(lb_b);
+
+ BLI_listbases_swaplinks(lb_a, lb_b, lc_a, lc_b);
+}
+
+/**
+ * Move \a lc_src into \a lc_dst. Both have to be stored in \a view_layer.
+ * If \a lc_src is directly linked to the ViewLayer it's unlinked
+ */
+bool BKE_layer_collection_move_into(const ID *owner_id, LayerCollection *lc_dst, LayerCollection *lc_src)
+{
+ ViewLayer *view_layer = BKE_view_layer_find_from_collection(owner_id, lc_src);
+ bool is_directly_linked = false;
+
+ if ((!view_layer) || (view_layer != BKE_view_layer_find_from_collection(owner_id, lc_dst))) {
+ return false;
+ }
+
+ /* We can't nest the collection into itself */
+ if (lc_src->scene_collection == lc_dst->scene_collection) {
+ return false;
+ }
+
+ /* Collection is already where we wanted it to be */
+ if (lc_dst->layer_collections.last == lc_src) {
+ return false;
+ }
+
+ /* Collection is already where we want it to be in the scene tree
+ * but we want to swap it in the layer tree still */
+ if (lc_dst->scene_collection->scene_collections.last == lc_src->scene_collection) {
+ LayerCollection *lc_swap = lc_dst->layer_collections.last;
+ layer_collection_swap(view_layer, &lc_dst->layer_collections, NULL, lc_dst->layer_collections.last, lc_src);
+
+ if (BLI_findindex(&view_layer->layer_collections, lc_swap) != -1) {
+ BKE_collection_unlink(view_layer, lc_swap);
+ }
+ return true;
+ }
+ else {
+ LayerCollection *lc_temp;
+ is_directly_linked = BLI_findindex(&view_layer->layer_collections, lc_src) != -1;
+
+ if (!is_directly_linked) {
+ /* lc_src will be invalid after BKE_collection_move_into!
+ * so we swap it with lc_temp to preserve its settings */
+ lc_temp = BKE_collection_link(view_layer, lc_src->scene_collection);
+ layer_collection_swap(view_layer, &view_layer->layer_collections, NULL, lc_temp, lc_src);
+ }
+
+ if (!BKE_collection_move_into(owner_id, lc_dst->scene_collection, lc_src->scene_collection)) {
+ if (!is_directly_linked) {
+ /* Swap back and remove */
+ layer_collection_swap(view_layer, NULL, NULL, lc_temp, lc_src);
+ BKE_collection_unlink(view_layer, lc_temp);
+ }
+ return false;
+ }
+ }
+
+ LayerCollection *lc_new = BLI_findptr(
+ &lc_dst->layer_collections, lc_src->scene_collection, offsetof(LayerCollection, scene_collection));
+ BLI_assert(lc_new);
+ layer_collection_swap(view_layer, &lc_dst->layer_collections, NULL, lc_new, lc_src);
+
+ /* If it's directly linked, unlink it after the swap */
+ if (BLI_findindex(&view_layer->layer_collections, lc_new) != -1) {
+ BKE_collection_unlink(view_layer, lc_new);
+ }
+
+ return true;
+}
+
+/**
+ * Move \a lc_src above \a lc_dst. Both have to be stored in \a view_layer.
+ * If \a lc_src is directly linked to the ViewLayer it's unlinked
+ */
+bool BKE_layer_collection_move_above(const ID *owner_id, LayerCollection *lc_dst, LayerCollection *lc_src)
+{
+ ViewLayer *view_layer = BKE_view_layer_find_from_collection(owner_id, lc_src);
+ const bool is_directly_linked_src = BLI_findindex(&view_layer->layer_collections, lc_src) != -1;
+ const bool is_directly_linked_dst = BLI_findindex(&view_layer->layer_collections, lc_dst) != -1;
+
+ if ((!view_layer) || (view_layer != BKE_view_layer_find_from_collection(owner_id, lc_dst))) {
+ return false;
+ }
+
+ /* Collection is already where we wanted it to be */
+ if (lc_dst->prev == lc_src) {
+ return false;
+ }
+
+ /* Collection is already where we want it to be in the scene tree
+ * but we want to swap it in the layer tree still */
+ if (lc_dst->prev && lc_dst->prev->scene_collection == lc_src->scene_collection) {
+ LayerCollection *lc_swap = lc_dst->prev;
+ layer_collection_swap(view_layer, NULL, NULL, lc_dst->prev, lc_src);
+
+ if (BLI_findindex(&view_layer->layer_collections, lc_swap) != -1) {
+ BKE_collection_unlink(view_layer, lc_swap);
+ }
+ return true;
+ }
+ /* We don't allow to move above/below a directly linked collection
+ * unless the source collection is also directly linked */
+ else if (is_directly_linked_dst) {
+ /* Both directly linked to the ViewLayer, just need to swap */
+ if (is_directly_linked_src) {
+ BLI_remlink(&view_layer->layer_collections, lc_src);
+ BLI_insertlinkbefore(&view_layer->layer_collections, lc_dst, lc_src);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ else {
+ LayerCollection *lc_temp;
+
+ if (!is_directly_linked_src) {
+ /* lc_src will be invalid after BKE_collection_move_into!
+ * so we swap it with lc_temp to preserve its settings */
+ lc_temp = BKE_collection_link(view_layer, lc_src->scene_collection);
+ layer_collection_swap(view_layer, &view_layer->layer_collections, NULL, lc_temp, lc_src);
+ }
+
+ if (!BKE_collection_move_above(owner_id, lc_dst->scene_collection, lc_src->scene_collection)) {
+ if (!is_directly_linked_src) {
+ /* Swap back and remove */
+ layer_collection_swap(view_layer, NULL, NULL, lc_temp, lc_src);
+ BKE_collection_unlink(view_layer, lc_temp);
+ }
+ return false;
+ }
+ }
+
+ LayerCollection *lc_new = lc_dst->prev;
+ BLI_assert(lc_new);
+ layer_collection_swap(view_layer, NULL, NULL, lc_new, lc_src);
+
+ /* If it's directly linked, unlink it after the swap */
+ if (BLI_findindex(&view_layer->layer_collections, lc_new) != -1) {
+ BKE_collection_unlink(view_layer, lc_new);
+ }
+
+ return true;
+}
+
+/**
+ * Move \a lc_src below \a lc_dst. Both have to be stored in \a view_layer.
+ * If \a lc_src is directly linked to the ViewLayer it's unlinked
+ */
+bool BKE_layer_collection_move_below(const ID *owner_id, LayerCollection *lc_dst, LayerCollection *lc_src)
+{
+ ViewLayer *view_layer = BKE_view_layer_find_from_collection(owner_id, lc_src);
+ const bool is_directly_linked_src = BLI_findindex(&view_layer->layer_collections, lc_src) != -1;
+ const bool is_directly_linked_dst = BLI_findindex(&view_layer->layer_collections, lc_dst) != -1;
+
+ if ((!view_layer) || (view_layer != BKE_view_layer_find_from_collection(owner_id, lc_dst))) {
+ return false;
+ }
+
+ /* Collection is already where we wanted it to be */
+ if (lc_dst->next == lc_src) {
+ return false;
+ }
+
+ /* Collection is already where we want it to be in the scene tree
+ * but we want to swap it in the layer tree still */
+ if (lc_dst->next && lc_dst->next->scene_collection == lc_src->scene_collection) {
+ LayerCollection *lc_swap = lc_dst->next;
+ layer_collection_swap(view_layer, NULL, NULL, lc_dst->next, lc_src);
+
+ if (BLI_findindex(&view_layer->layer_collections, lc_swap) != -1) {
+ BKE_collection_unlink(view_layer, lc_swap);
+ }
+ return true;
+ }
+ /* We don't allow to move above/below a directly linked collection
+ * unless the source collection is also directly linked */
+ else if (is_directly_linked_dst) {
+ /* Both directly linked to the ViewLayer, just need to swap */
+ if (is_directly_linked_src) {
+ BLI_remlink(&view_layer->layer_collections, lc_src);
+ BLI_insertlinkafter(&view_layer->layer_collections, lc_dst, lc_src);
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ else {
+ LayerCollection *lc_temp;
+
+ if (!is_directly_linked_src) {
+ /* lc_src will be invalid after BKE_collection_move_into!
+ * so we swap it with lc_temp to preserve its settings */
+ lc_temp = BKE_collection_link(view_layer, lc_src->scene_collection);
+ layer_collection_swap(view_layer, &view_layer->layer_collections, NULL, lc_temp, lc_src);
+ }
+
+ if (!BKE_collection_move_below(owner_id, lc_dst->scene_collection, lc_src->scene_collection)) {
+ if (!is_directly_linked_src) {
+ /* Swap back and remove */
+ layer_collection_swap(view_layer, NULL, NULL, lc_temp, lc_src);
+ BKE_collection_unlink(view_layer, lc_temp);
+ }
+ return false;
+ }
+ }
+
+ LayerCollection *lc_new = lc_dst->next;
+ BLI_assert(lc_new);
+ layer_collection_swap(view_layer, NULL, NULL, lc_new, lc_src);
+
+ /* If it's directly linked, unlink it after the swap */
+ if (BLI_findindex(&view_layer->layer_collections, lc_new) != -1) {
+ BKE_collection_unlink(view_layer, lc_new);
+ }
+
+ return true;
+}
+
+static bool layer_collection_resync(ViewLayer *view_layer, LayerCollection *lc, const SceneCollection *sc)
+{
+ if (lc->scene_collection == sc) {
+ ListBase collections = {NULL};
+ BLI_movelisttolist(&collections, &lc->layer_collections);
+
+ for (SceneCollection *sc_nested = sc->scene_collections.first; sc_nested; sc_nested = sc_nested->next) {
+ LayerCollection *lc_nested = BLI_findptr(&collections, sc_nested, offsetof(LayerCollection, scene_collection));
+ if (lc_nested) {
+ BLI_remlink(&collections, lc_nested);
+ BLI_addtail(&lc->layer_collections, lc_nested);
+ }
+ else {
+ layer_collection_add(view_layer, lc, sc_nested);
+ }
+ }
+
+ for (LayerCollection *lc_nested = collections.first; lc_nested; lc_nested = lc_nested->next) {
+ layer_collection_free(view_layer, lc_nested);
+ }
+ BLI_freelistN(&collections);
+
+ BLI_assert(BLI_listbase_count(&lc->layer_collections) ==
+ BLI_listbase_count(&sc->scene_collections));
+
+ return true;
+ }
+
+ for (LayerCollection *lc_nested = lc->layer_collections.first; lc_nested; lc_nested = lc_nested->next) {
+ if (layer_collection_resync(view_layer, lc_nested, sc)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/**
+ * Update the scene layers so that any LayerCollection that points
+ * to \a sc is re-synced again
+ */
+void BKE_layer_collection_resync(const ID *owner_id, const SceneCollection *sc)
+{
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) {
+ layer_collection_resync(view_layer, lc, sc);
+ }
+ }
+}
+
+/* ---------------------------------------------------------------------- */
+
+/**
+ * Select all the objects of this layer collection
+ *
+ * It also select the objects that are in nested collections.
+ * \note Recursive
+ */
+void BKE_layer_collection_objects_select(struct LayerCollection *layer_collection)
+{
+ if ((layer_collection->flag & COLLECTION_DISABLED) ||
+ ((layer_collection->flag & COLLECTION_SELECTABLE) == 0))
+ {
+ return;
+ }
+
+ for (LinkData *link = layer_collection->object_bases.first; link; link = link->next) {
+ Base *base = link->data;
+ if (base->flag & BASE_SELECTABLED) {
+ base->flag |= BASE_SELECTED;
+ }
+ }
+
+ for (LayerCollection *iter = layer_collection->layer_collections.first; iter; iter = iter->next) {
+ BKE_layer_collection_objects_select(iter);
+ }
+}
+
+/* ---------------------------------------------------------------------- */
+
+/**
+ * Link a collection to a renderlayer
+ * The collection needs to be created separately
+ */
+LayerCollection *BKE_collection_link(ViewLayer *view_layer, SceneCollection *sc)
+{
+ LayerCollection *lc = layer_collection_add(view_layer, NULL, sc);
+ view_layer->active_collection = BKE_layer_collection_findindex(view_layer, lc);
+ return lc;
+}
+
+/**
+ * Unlink a collection base from a renderlayer
+ * The corresponding collection is not removed from the master collection
+ */
+void BKE_collection_unlink(ViewLayer *view_layer, LayerCollection *lc)
+{
+ BKE_layer_collection_free(view_layer, lc);
+ BLI_remlink(&view_layer->layer_collections, lc);
+ MEM_freeN(lc);
+ view_layer->active_collection = 0;
+}
+
+/**
+ * Recursively enable nested collections
+ */
+static void layer_collection_enable(ViewLayer *view_layer, LayerCollection *lc)
+{
+ layer_collection_objects_populate(view_layer, lc, &lc->scene_collection->objects);
+
+ for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
+ layer_collection_enable(view_layer, nlc);
+ }
+}
+
+/**
+ * Enable collection
+ * Add its objects bases to ViewLayer
+ *
+ * Only around for doversion.
+ */
+void BKE_collection_enable(ViewLayer *view_layer, LayerCollection *lc)
+{
+ if ((lc->flag & COLLECTION_DISABLED) == 0) {
+ return;
+ }
+
+ lc->flag &= ~COLLECTION_DISABLED;
+ layer_collection_enable(view_layer, lc);
+}
+
+static void layer_collection_object_add(ViewLayer *view_layer, LayerCollection *lc, Object *ob)
+{
+ Base *base = object_base_add(view_layer, ob);
+
+ /* Only add an object once. */
+ if (BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data))) {
+ return;
+ }
+
+ bool is_visible = ((lc->flag & COLLECTION_VIEWPORT) != 0) && ((lc->flag & COLLECTION_DISABLED) == 0);
+ bool is_selectable = is_visible && ((lc->flag & COLLECTION_SELECTABLE) != 0);
+
+ if (is_visible) {
+ base->flag |= BASE_VISIBLED;
+ }
+
+ if (is_selectable) {
+ base->flag |= BASE_SELECTABLED;
+ }
+
+ BLI_addtail(&lc->object_bases, BLI_genericNodeN(base));
+}
+
+static void layer_collection_object_remove(ViewLayer *view_layer, LayerCollection *lc, Object *ob)
+{
+ Base *base;
+ base = BKE_view_layer_base_find(view_layer, ob);
+
+ LinkData *link = BLI_findptr(&lc->object_bases, base, offsetof(LinkData, data));
+ BLI_remlink(&lc->object_bases, link);
+ MEM_freeN(link);
+
+ view_layer_object_base_unref(view_layer, base);
+}
+
+static void layer_collection_objects_populate(ViewLayer *view_layer, LayerCollection *lc, ListBase *objects)
+{
+ for (LinkData *link = objects->first; link; link = link->next) {
+ layer_collection_object_add(view_layer, lc, link->data);
+ }
+}
+
+static void layer_collection_populate(ViewLayer *view_layer, LayerCollection *lc, SceneCollection *sc)
+{
+ layer_collection_objects_populate(view_layer, lc, &sc->objects);
+
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ layer_collection_add(view_layer, lc, nsc);
+ }
+}
+
+static LayerCollection *layer_collection_add(ViewLayer *view_layer, LayerCollection *parent, SceneCollection *sc)
+{
+ IDPropertyTemplate val = {0};
+ LayerCollection *lc = MEM_callocN(sizeof(LayerCollection), "Collection Base");
+
+ lc->scene_collection = sc;
+ lc->flag = COLLECTION_SELECTABLE | COLLECTION_VIEWPORT | COLLECTION_RENDER;
+
+ lc->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ collection_engine_settings_init(lc->properties, false);
+
+ if (parent != NULL) {
+ BLI_addtail(&parent->layer_collections, lc);
+ }
+ else {
+ BLI_addtail(&view_layer->layer_collections, lc);
+ }
+
+ layer_collection_populate(view_layer, lc, sc);
+
+ return lc;
+}
+
+/* ---------------------------------------------------------------------- */
+
+/**
+ * Return the first matching LayerCollection in the ViewLayer for the SceneCollection.
+ */
+LayerCollection *BKE_layer_collection_first_from_scene_collection(ViewLayer *view_layer, const SceneCollection *scene_collection)
+{
+ for (LayerCollection *layer_collection = view_layer->layer_collections.first;
+ layer_collection != NULL;
+ layer_collection = layer_collection->next)
+ {
+ LayerCollection *found = find_layer_collection_by_scene_collection(layer_collection, scene_collection);
+
+ if (found != NULL) {
+ return found;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * See if view layer has the scene collection linked directly, or indirectly (nested)
+ */
+bool BKE_view_layer_has_collection(ViewLayer *view_layer, const SceneCollection *scene_collection)
+{
+ return BKE_layer_collection_first_from_scene_collection(view_layer, scene_collection) != NULL;
+}
+
+/**
+ * See if the object is in any of the scene layers of the scene
+ */
+bool BKE_scene_has_object(Scene *scene, Object *ob)
+{
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+ if (base) {
+ return true;
+ }
+ }
+ return false;
+}
+
+
+/* ---------------------------------------------------------------------- */
+/* Syncing */
+
+static LayerCollection *find_layer_collection_by_scene_collection(LayerCollection *lc, const SceneCollection *sc)
+{
+ if (lc->scene_collection == sc) {
+ return lc;
+ }
+
+ for (LayerCollection *nlc = lc->layer_collections.first; nlc; nlc = nlc->next) {
+ LayerCollection *found = find_layer_collection_by_scene_collection(nlc, sc);
+ if (found) {
+ return found;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Add a new LayerCollection for all the ViewLayers that have sc_parent
+ */
+void BKE_layer_sync_new_scene_collection(ID *owner_id, const SceneCollection *sc_parent, SceneCollection *sc)
+{
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) {
+ LayerCollection *lc_parent = find_layer_collection_by_scene_collection(lc, sc_parent);
+ if (lc_parent) {
+ layer_collection_add(view_layer, lc_parent, sc);
+ }
+ }
+ }
+}
+
+/**
+ * Add a corresponding ObjectBase to all the equivalent LayerCollection
+ */
+void BKE_layer_sync_object_link(const ID *owner_id, SceneCollection *sc, Object *ob)
+{
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) {
+ LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc);
+ if (found) {
+ layer_collection_object_add(view_layer, found, ob);
+ }
+ }
+ }
+}
+
+/**
+ * Remove the equivalent object base to all layers that have this collection
+ */
+void BKE_layer_sync_object_unlink(const ID *owner_id, SceneCollection *sc, Object *ob)
+{
+ for (ViewLayer *view_layer = BKE_view_layer_first_from_id(owner_id); view_layer; view_layer = view_layer->next) {
+ for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) {
+ LayerCollection *found = find_layer_collection_by_scene_collection(lc, sc);
+ if (found) {
+ layer_collection_object_remove(view_layer, found, ob);
+ }
+ }
+ }
+}
+
+/* ---------------------------------------------------------------------- */
+/* Override */
+
+/**
+ * Add a new datablock override
+ */
+void BKE_override_view_layer_datablock_add(ViewLayer *view_layer, int id_type, const char *data_path, const ID *owner_id)
+{
+ UNUSED_VARS(view_layer, id_type, data_path, owner_id);
+ TODO_LAYER_OVERRIDE;
+}
+
+/**
+ * Add a new int override
+ */
+void BKE_override_view_layer_int_add(ViewLayer *view_layer, int id_type, const char *data_path, const int value)
+{
+ UNUSED_VARS(view_layer, id_type, data_path, value);
+ TODO_LAYER_OVERRIDE;
+}
+
+/**
+ * Add a new boolean override
+ */
+void BKE_override_layer_collection_boolean_add(struct LayerCollection *layer_collection, int id_type, const char *data_path, const bool value)
+{
+ UNUSED_VARS(layer_collection, id_type, data_path, value);
+ TODO_LAYER_OVERRIDE;
+}
+
+/* ---------------------------------------------------------------------- */
+/* Engine Settings */
+
+ListBase R_layer_collection_engines_settings_callbacks = {NULL, NULL};
+ListBase R_view_layer_engines_settings_callbacks = {NULL, NULL};
+
+typedef struct EngineSettingsCB_Type {
+ struct EngineSettingsCB_Type *next, *prev;
+
+ char name[MAX_NAME]; /* engine name */
+
+ EngineSettingsCB callback;
+
+} EngineSettingsCB_Type;
+
+static void create_engine_settings_scene(IDProperty *root, EngineSettingsCB_Type *es_type)
+{
+ if (collection_engine_get(root, es_type->name)) {
+ return;
+ }
+
+ IDProperty *props = collection_engine_settings_create(es_type, true);
+ IDP_AddToGroup(root, props);
+}
+
+static void create_layer_collection_engine_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type)
+{
+ create_engine_settings_scene(scene->collection_properties, es_type);
+}
+
+static void create_view_layer_engine_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type)
+{
+ create_engine_settings_scene(scene->layer_properties, es_type);
+}
+
+static void create_layer_collection_engine_settings_collection(LayerCollection *lc, EngineSettingsCB_Type *es_type)
+{
+ if (BKE_layer_collection_engine_collection_get(lc, es_type->name)) {
+ return;
+ }
+
+ IDProperty *props = collection_engine_settings_create(es_type, false);
+ IDP_AddToGroup(lc->properties, props);
+
+ for (LayerCollection *lcn = lc->layer_collections.first; lcn; lcn = lcn->next) {
+ create_layer_collection_engine_settings_collection(lcn, es_type);
+ }
+}
+
+static void create_layer_collection_engines_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type)
+{
+ /* Populate the scene with the new settings. */
+ create_layer_collection_engine_settings_scene(scene, es_type);
+
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (LayerCollection *lc = view_layer->layer_collections.first; lc; lc = lc->next) {
+ create_layer_collection_engine_settings_collection(lc, es_type);
+ }
+ }
+}
+
+static void create_view_layer_engines_settings_scene(Scene *scene, EngineSettingsCB_Type *es_type)
+{
+ /* Populate the scene with the new settings. */
+ create_view_layer_engine_settings_scene(scene, es_type);
+}
+
+static void create_view_layer_engines_settings_layer(ViewLayer *view_layer, EngineSettingsCB_Type *es_type)
+{
+ if (BKE_view_layer_engine_layer_get(view_layer, es_type->name)) {
+ return;
+ }
+
+ IDProperty *props = collection_engine_settings_create(es_type, false);
+ IDP_AddToGroup(view_layer->properties, props);
+}
+
+static EngineSettingsCB_Type *engine_settings_callback_register(const char *engine_name, EngineSettingsCB func, ListBase *lb)
+{
+ EngineSettingsCB_Type *es_type;
+
+ /* Cleanup in case it existed. */
+ es_type = BLI_findstring(lb, engine_name, offsetof(EngineSettingsCB_Type, name));
+
+ if (es_type) {
+ BLI_remlink(lb, es_type);
+ MEM_freeN(es_type);
+ }
+
+ es_type = MEM_callocN(sizeof(EngineSettingsCB_Type), __func__);
+ BLI_strncpy_utf8(es_type->name, engine_name, sizeof(es_type->name));
+ es_type->callback = func;
+ BLI_addtail(lb, es_type);
+
+ return es_type;
+}
+
+void BKE_layer_collection_engine_settings_callback_register(
+ Main *bmain, const char *engine_name, EngineSettingsCB func)
+{
+ EngineSettingsCB_Type *es_type =
+ engine_settings_callback_register(engine_name, func, &R_layer_collection_engines_settings_callbacks);
+
+ if (bmain) {
+ /* Populate all of the collections of the scene with those settings. */
+ for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
+ create_layer_collection_engines_settings_scene(scene, es_type);
+ }
+ }
+}
+
+void BKE_view_layer_engine_settings_callback_register(
+ Main *bmain, const char *engine_name, EngineSettingsCB func)
+{
+ EngineSettingsCB_Type *es_type =
+ engine_settings_callback_register(engine_name, func, &R_view_layer_engines_settings_callbacks);
+
+ if (bmain) {
+ /* Populate all of the collections of the scene with those settings. */
+ for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
+ create_view_layer_engines_settings_scene(scene, es_type);
+
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ create_view_layer_engines_settings_layer(view_layer, es_type);
+ }
+ }
+ }
+}
+
+void BKE_layer_collection_engine_settings_callback_free(void)
+{
+ BLI_freelistN(&R_layer_collection_engines_settings_callbacks);
+}
+
+void BKE_view_layer_engine_settings_callback_free(void)
+{
+ BLI_freelistN(&R_view_layer_engines_settings_callbacks);
+}
+
+/**
+ * Create a root IDProperty for this engine
+ *
+ * \param populate whether we want to pre-fill the collection with the default properties
+ */
+static IDProperty *collection_engine_settings_create(EngineSettingsCB_Type *es_type, const bool populate)
+{
+ IDProperty *props;
+ IDPropertyTemplate val = {0};
+
+ props = IDP_New(IDP_GROUP, &val, es_type->name);
+ props->subtype = IDP_GROUP_SUB_ENGINE_RENDER;
+
+ /* properties */
+ if (populate) {
+ es_type->callback(NULL, props);
+ }
+
+ return props;
+}
+
+static void layer_collection_create_render_settings(IDProperty *root, const bool populate)
+{
+ EngineSettingsCB_Type *es_type;
+ for (es_type = R_layer_collection_engines_settings_callbacks.first; es_type; es_type = es_type->next) {
+ IDProperty *props = collection_engine_settings_create(es_type, populate);
+ IDP_AddToGroup(root, props);
+ }
+}
+
+static void view_layer_create_render_settings(IDProperty *root, const bool populate)
+{
+ EngineSettingsCB_Type *es_type;
+ for (es_type = R_view_layer_engines_settings_callbacks.first; es_type; es_type = es_type->next) {
+ IDProperty *props = collection_engine_settings_create(es_type, populate);
+ IDP_AddToGroup(root, props);
+ }
+}
+
+/**
+ * Return collection enginne settings for either Object s of LayerCollection s
+ */
+static IDProperty *collection_engine_get(IDProperty *root, const char *engine_name)
+{
+ return IDP_GetPropertyFromGroup(root, engine_name);
+}
+
+/**
+ * Return collection engine settings from Object for specified engine of mode
+ */
+IDProperty *BKE_layer_collection_engine_evaluated_get(Object *ob, const char *engine_name)
+{
+ return collection_engine_get(ob->base_collection_properties, engine_name);
+}
+/**
+ * Return layer collection engine settings for specified engine
+ */
+IDProperty *BKE_layer_collection_engine_collection_get(LayerCollection *lc, const char *engine_name)
+{
+ return collection_engine_get(lc->properties, engine_name);
+}
+
+/**
+ * Return layer collection engine settings for specified engine in the scene
+ */
+IDProperty *BKE_layer_collection_engine_scene_get(Scene *scene, const char *engine_name)
+{
+ return collection_engine_get(scene->collection_properties, engine_name);
+}
+
+/**
+ * Return scene layer engine settings for specified engine in the scene
+ */
+IDProperty *BKE_view_layer_engine_scene_get(Scene *scene, const char *engine_name)
+{
+ return collection_engine_get(scene->layer_properties, engine_name);
+}
+
+/**
+ * Return scene layer engine settings for specified engine
+ */
+IDProperty *BKE_view_layer_engine_layer_get(ViewLayer *view_layer, const char *engine_name)
+{
+ return collection_engine_get(view_layer->properties, engine_name);
+}
+
+/**
+ * Return scene layer evaluated engine settings for specified engine
+ */
+IDProperty *BKE_view_layer_engine_evaluated_get(ViewLayer *view_layer, const char *engine_name)
+{
+ return collection_engine_get(view_layer->properties_evaluated, engine_name);
+}
+
+/* ---------------------------------------------------------------------- */
+/* Engine Settings Properties */
+
+void BKE_collection_engine_property_add_float(IDProperty *props, const char *name, float value)
+{
+ IDPropertyTemplate val = {0};
+ val.f = value;
+ IDP_AddToGroup(props, IDP_New(IDP_FLOAT, &val, name));
+}
+
+void BKE_collection_engine_property_add_float_array(
+ IDProperty *props, const char *name, const float *values, const int array_length)
+{
+ IDPropertyTemplate val = {0};
+ val.array.len = array_length;
+ val.array.type = IDP_FLOAT;
+
+ IDProperty *idprop = IDP_New(IDP_ARRAY, &val, name);
+ memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
+ IDP_AddToGroup(props, idprop);
+}
+
+void BKE_collection_engine_property_add_int(IDProperty *props, const char *name, int value)
+{
+ IDPropertyTemplate val = {0};
+ val.i = value;
+ IDP_AddToGroup(props, IDP_New(IDP_INT, &val, name));
+}
+
+void BKE_collection_engine_property_add_bool(IDProperty *props, const char *name, bool value)
+{
+ IDPropertyTemplate val = {0};
+ val.i = value;
+ IDP_AddToGroup(props, IDP_New(IDP_INT, &val, name));
+}
+
+int BKE_collection_engine_property_value_get_int(IDProperty *props, const char *name)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ return idprop ? IDP_Int(idprop) : 0;
+}
+
+float BKE_collection_engine_property_value_get_float(IDProperty *props, const char *name)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ return idprop ? IDP_Float(idprop) : 0.0f;
+}
+
+const float *BKE_collection_engine_property_value_get_float_array(IDProperty *props, const char *name)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ return idprop ? IDP_Array(idprop) : NULL;
+}
+
+bool BKE_collection_engine_property_value_get_bool(IDProperty *props, const char *name)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ return idprop ? IDP_Int(idprop) : 0;
+}
+
+void BKE_collection_engine_property_value_set_int(IDProperty *props, const char *name, int value)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ IDP_Int(idprop) = value;
+}
+
+void BKE_collection_engine_property_value_set_float(IDProperty *props, const char *name, float value)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ IDP_Float(idprop) = value;
+}
+
+void BKE_collection_engine_property_value_set_float_array(IDProperty *props, const char *name, const float *values)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ memcpy(IDP_Array(idprop), values, sizeof(float) * idprop->len);
+}
+
+void BKE_collection_engine_property_value_set_bool(IDProperty *props, const char *name, bool value)
+{
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, name);
+ IDP_Int(idprop) = value;
+}
+
+/* Engine Settings recalculate */
+
+/* get all the default settings defined in scene and merge them here */
+static void collection_engine_settings_init(IDProperty *root, const bool populate)
+{
+ /* render engines */
+ layer_collection_create_render_settings(root, populate);
+}
+
+/* get all the default settings defined in scene and merge them here */
+static void layer_engine_settings_init(IDProperty *root, const bool populate)
+{
+ /* render engines */
+ view_layer_create_render_settings(root, populate);
+}
+
+/**
+ * Initialize the layer collection render setings
+ * It's used mainly for scenes
+ */
+void BKE_layer_collection_engine_settings_create(IDProperty *root)
+{
+ collection_engine_settings_init(root, true);
+}
+
+/**
+ * Initialize the render setings
+ * It's used mainly for scenes
+ */
+void BKE_view_layer_engine_settings_create(IDProperty *root)
+{
+ layer_engine_settings_init(root, true);
+}
+
+/**
+ * Reference of IDProperty group scene collection settings
+ * Used when reading blendfiles, to see if there is any missing settings.
+ */
+static struct {
+ struct {
+ IDProperty *collection_properties;
+ IDProperty *render_settings;
+ } scene;
+ IDProperty *view_layer;
+ IDProperty *layer_collection;
+} root_reference = {
+ .scene = {NULL, NULL},
+ .view_layer = NULL,
+ .layer_collection = NULL,
+};
+
+/**
+ * Free the reference scene collection settings IDProperty group.
+ */
+static void engine_settings_validate_init(void)
+{
+ IDPropertyTemplate val = {0};
+
+ /* LayerCollection engine settings. */
+ if (root_reference.scene.collection_properties == NULL) {
+ root_reference.scene.collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ collection_engine_settings_init(root_reference.scene.collection_properties, true);
+ }
+
+ if (root_reference.layer_collection == NULL) {
+ root_reference.layer_collection = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ collection_engine_settings_init(root_reference.layer_collection, false);
+ }
+
+ /* Render engine setting. */
+ if (root_reference.scene.render_settings == NULL) {
+ root_reference.scene.render_settings = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ layer_engine_settings_init(root_reference.scene.render_settings, true);
+ }
+
+ if (root_reference.view_layer == NULL) {
+ root_reference.view_layer = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ layer_engine_settings_init(root_reference.view_layer, false);
+ }
+}
+
+/**
+ * Free the reference scene collection settings IDProperty group.
+ */
+static void layer_collection_engine_settings_validate_free(void)
+{
+ IDProperty *idprops[] = {
+ root_reference.scene.render_settings,
+ root_reference.scene.collection_properties,
+ root_reference.view_layer,
+ root_reference.layer_collection,
+ NULL,
+ };
+
+ IDProperty **idprop = &idprops[0];
+ while (*idprop) {
+ if (*idprop) {
+ IDP_FreeProperty(*idprop);
+ MEM_freeN(*idprop);
+ *idprop = NULL;
+ idprop++;
+ }
+ }
+}
+
+/**
+ * Make sure Scene has all required collection settings.
+ */
+void BKE_layer_collection_engine_settings_validate_scene(Scene *scene)
+{
+ if (root_reference.scene.collection_properties == NULL) {
+ engine_settings_validate_init();
+ }
+
+ if (scene->collection_properties == NULL) {
+ IDPropertyTemplate val = {0};
+ scene->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ BKE_layer_collection_engine_settings_create(scene->collection_properties);
+ }
+ else {
+ IDP_MergeGroup(scene->collection_properties, root_reference.scene.collection_properties, false);
+ }
+}
+
+/**
+ * Maker sure LayerCollection has all required collection settings.
+ */
+void BKE_layer_collection_engine_settings_validate_collection(LayerCollection *lc)
+{
+ if (root_reference.layer_collection == NULL) {
+ engine_settings_validate_init();
+ }
+
+ BLI_assert(lc->properties != NULL);
+ IDP_MergeGroup(lc->properties, root_reference.layer_collection, false);
+}
+
+/**
+ * Make sure Scene has all required collection settings.
+ */
+void BKE_view_layer_engine_settings_validate_scene(Scene *scene)
+{
+ if (root_reference.scene.render_settings == NULL) {
+ engine_settings_validate_init();
+ }
+
+ if (scene->layer_properties == NULL) {
+ IDPropertyTemplate val = {0};
+ scene->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ BKE_view_layer_engine_settings_create(scene->layer_properties);
+ }
+ else {
+ IDP_MergeGroup(scene->layer_properties, root_reference.scene.render_settings, false);
+ }
+}
+
+/**
+ * Make sure Scene has all required collection settings.
+ */
+void BKE_view_layer_engine_settings_validate_layer(ViewLayer *view_layer)
+{
+ if (root_reference.view_layer == NULL) {
+ engine_settings_validate_init();
+ }
+
+ IDP_MergeGroup(view_layer->properties, root_reference.view_layer, false);
+}
+
+/** \} */
+
+/* Iterators */
+
+/* -------------------------------------------------------------------- */
+/** \name Private Iterator Helpers
+ * \{ */
+
+static void object_bases_iterator_begin(BLI_Iterator *iter, void *data_in, const int flag)
+{
+ ViewLayer *view_layer = data_in;
+ Base *base = view_layer->object_bases.first;
+
+ /* when there are no objects */
+ if (base == NULL) {
+ iter->valid = false;
+ return;
+ }
+
+ iter->data = base;
+
+ if ((base->flag & flag) == 0) {
+ object_bases_iterator_next(iter, flag);
+ }
+ else {
+ iter->current = base;
+ }
+}
+
+static void object_bases_iterator_next(BLI_Iterator *iter, const int flag)
+{
+ Base *base = ((Base *)iter->data)->next;
+
+ while (base) {
+ if ((base->flag & flag) != 0) {
+ iter->current = base;
+ iter->data = base;
+ return;
+ }
+ base = base->next;
+ }
+
+ iter->valid = false;
+}
+
+static void objects_iterator_begin(BLI_Iterator *iter, void *data_in, const int flag)
+{
+ object_bases_iterator_begin(iter, data_in, flag);
+
+ if (iter->valid) {
+ iter->current = ((Base *)iter->current)->object;
+ }
+}
+
+static void objects_iterator_next(BLI_Iterator *iter, const int flag)
+{
+ object_bases_iterator_next(iter, flag);
+
+ if (iter->valid) {
+ iter->current = ((Base *)iter->current)->object;
+ }
+}
+
+/* -------------------------------------------------------------------- */
+/** \name BKE_view_layer_selected_objects_iterator
+ * See: #FOREACH_SELECTED_OBJECT_BEGIN
+ * \{ */
+
+void BKE_view_layer_selected_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ objects_iterator_begin(iter, data_in, BASE_SELECTED);
+}
+
+void BKE_view_layer_selected_objects_iterator_next(BLI_Iterator *iter)
+{
+ objects_iterator_next(iter, BASE_SELECTED);
+}
+
+void BKE_view_layer_selected_objects_iterator_end(BLI_Iterator *UNUSED(iter))
+{
+ /* do nothing */
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name BKE_view_layer_selected_objects_iterator
+ * \{ */
+
+void BKE_view_layer_visible_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ objects_iterator_begin(iter, data_in, BASE_VISIBLED);
+}
+
+void BKE_view_layer_visible_objects_iterator_next(BLI_Iterator *iter)
+{
+ objects_iterator_next(iter, BASE_VISIBLED);
+}
+
+void BKE_view_layer_visible_objects_iterator_end(BLI_Iterator *UNUSED(iter))
+{
+ /* do nothing */
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name BKE_view_layer_selected_bases_iterator
+ * \{ */
+
+void BKE_view_layer_selected_bases_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ object_bases_iterator_begin(iter, data_in, BASE_SELECTED);
+}
+
+void BKE_view_layer_selected_bases_iterator_next(BLI_Iterator *iter)
+{
+ object_bases_iterator_next(iter, BASE_SELECTED);
+}
+
+void BKE_view_layer_selected_bases_iterator_end(BLI_Iterator *UNUSED(iter))
+{
+ /* do nothing */
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name BKE_view_layer_visible_bases_iterator
+ * \{ */
+
+void BKE_view_layer_visible_bases_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ object_bases_iterator_begin(iter, data_in, BASE_VISIBLED);
+}
+
+void BKE_view_layer_visible_bases_iterator_next(BLI_Iterator *iter)
+{
+ object_bases_iterator_next(iter, BASE_VISIBLED);
+}
+
+void BKE_view_layer_visible_bases_iterator_end(BLI_Iterator *UNUSED(iter))
+{
+ /* do nothing */
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name BKE_view_layer_renderable_objects_iterator
+ * \{ */
+
+void BKE_view_layer_renderable_objects_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ struct ObjectsRenderableIteratorData *data = data_in;
+
+ /* Tag objects to prevent going over the same object twice. */
+ for (Scene *scene = data->scene; scene; scene = scene->set) {
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ base->object->id.flag |= LIB_TAG_DOIT;
+ }
+ }
+ }
+
+ ViewLayer *view_layer = data->scene->view_layers.first;
+ data->iter.view_layer = view_layer;
+
+ data->base_temp.next = view_layer->object_bases.first;
+ data->iter.base = &data->base_temp;
+
+ data->iter.set = NULL;
+
+ iter->data = data_in;
+ BKE_view_layer_renderable_objects_iterator_next(iter);
+}
+
+void BKE_view_layer_renderable_objects_iterator_next(BLI_Iterator *iter)
+{
+ /* Set it early in case we need to exit and we are running from within a loop. */
+ iter->skip = true;
+
+ struct ObjectsRenderableIteratorData *data = iter->data;
+ Base *base = data->iter.base->next;
+
+ /* There is still a base in the current scene layer. */
+ if (base != NULL) {
+ Object *ob = base->object;
+
+ /* We need to set the iter.base even if the rest fail otherwise
+ * we keep checking the exactly same base over and over again. */
+ data->iter.base = base;
+
+ if (ob->id.flag & LIB_TAG_DOIT) {
+ ob->id.flag &= ~LIB_TAG_DOIT;
+
+ if ((base->flag & BASE_VISIBLED) != 0) {
+ iter->skip = false;
+ iter->current = ob;
+ }
+ }
+ return;
+ }
+
+ /* Time to go to the next scene layer. */
+ if (data->iter.set == NULL) {
+ while ((data->iter.view_layer = data->iter.view_layer->next)) {
+ ViewLayer *view_layer = data->iter.view_layer;
+ if (view_layer->flag & VIEW_LAYER_RENDER) {
+ data->base_temp.next = view_layer->object_bases.first;
+ data->iter.base = &data->base_temp;
+ return;
+ }
+ }
+
+ /* Setup the "set" for the next iteration. */
+ data->scene_temp.set = data->scene;
+ data->iter.set = &data->scene_temp;
+ return;
+ }
+
+ /* Look for an object in the next set. */
+ while ((data->iter.set = data->iter.set->set)) {
+ ViewLayer *view_layer = BKE_view_layer_default_render(data->iter.set);
+ data->base_temp.next = view_layer->object_bases.first;
+ data->iter.base = &data->base_temp;
+ return;
+ }
+
+ iter->valid = false;
+}
+
+void BKE_view_layer_renderable_objects_iterator_end(BLI_Iterator *UNUSED(iter))
+{
+ /* Do nothing - iter->data was static allocated, we can't free it. */
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name BKE_view_layer_bases_in_mode_iterator
+ * \{ */
+
+void BKE_view_layer_bases_in_mode_iterator_begin(BLI_Iterator *iter, void *data_in)
+{
+ struct ObjectsInModeIteratorData *data = data_in;
+ Base *base = data->base_active;
+
+ /* when there are no objects */
+ if (base == NULL) {
+ iter->valid = false;
+ return;
+ }
+ iter->data = data_in;
+ iter->current = base;
+}
+
+void BKE_view_layer_bases_in_mode_iterator_next(BLI_Iterator *iter)
+{
+ struct ObjectsInModeIteratorData *data = iter->data;
+ Base *base = iter->current;
+
+ if (base == data->base_active) {
+ /* first step */
+ base = data->view_layer->object_bases.first;
+ if (base == data->base_active) {
+ base = base->next;
+ }
+ }
+ else {
+ base = base->next;
+ }
+
+ while (base) {
+ if ((base->flag & BASE_SELECTED) != 0 &&
+ (base->object->type == data->base_active->object->type) &&
+ (base != data->base_active) &&
+ (base->object->mode & data->object_mode))
+ {
+ iter->current = base;
+ return;
+ }
+ base = base->next;
+ }
+ iter->valid = false;
+}
+
+void BKE_view_layer_bases_in_mode_iterator_end(BLI_Iterator *UNUSED(iter))
+{
+ /* do nothing */
+}
+
+/** \} */
+
+/* Evaluation */
+
+/**
+ * Reset props
+ *
+ * If props_ref is pasted, copy props from it
+ */
+static void idproperty_reset(IDProperty **props, IDProperty *props_ref)
+{
+ IDPropertyTemplate val = {0};
+
+ if (*props) {
+ IDP_FreeProperty(*props);
+ MEM_freeN(*props);
+ }
+ *props = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+
+ if (props_ref) {
+ IDP_MergeGroup(*props, props_ref, true);
+ }
+}
+
+static void layer_eval_layer_collection_pre(Depsgraph *depsgraph, ID *owner_id, ViewLayer *view_layer)
+{
+ DEG_debug_print_eval(depsgraph, __func__, view_layer->name, view_layer);
+ Scene *scene = (GS(owner_id->name) == ID_SCE) ? (Scene *)owner_id : NULL;
+
+ for (Base *base = view_layer->object_bases.first; base != NULL; base = base->next) {
+ base->flag &= ~(BASE_VISIBLED | BASE_SELECTABLED);
+ idproperty_reset(&base->collection_properties, scene ? scene->collection_properties : NULL);
+ }
+
+ /* Sync properties from scene to scene layer. */
+ idproperty_reset(&view_layer->properties_evaluated, scene ? scene->layer_properties : NULL);
+ IDP_MergeGroup(view_layer->properties_evaluated, view_layer->properties, true);
+
+ /* TODO(sergey): Is it always required? */
+ view_layer->flag |= VIEW_LAYER_ENGINE_DIRTY;
+}
+
+static const char *collection_type_lookup[] =
+{
+ "None", /* COLLECTION_TYPE_NONE */
+ "Group Internal", /* COLLECTION_TYPE_GROUP_INTERNAL */
+};
+
+/**
+ * \note We can't use layer_collection->flag because of 3 level nesting (where parent is visible, but not grand-parent)
+ * So layer_collection->flag_evaluated is expected to be up to date with layer_collection->flag.
+ */
+static bool layer_collection_visible_get(Depsgraph *depsgraph, LayerCollection *layer_collection)
+{
+ if (layer_collection->flag_evaluated & COLLECTION_DISABLED) {
+ return false;
+ }
+
+ if (DEG_get_mode(depsgraph) == DAG_EVAL_VIEWPORT) {
+ return (layer_collection->flag_evaluated & COLLECTION_VIEWPORT) != 0;
+ }
+ else {
+ return (layer_collection->flag_evaluated & COLLECTION_RENDER) != 0;
+ }
+}
+
+static void layer_eval_layer_collection(Depsgraph *depsgraph,
+ LayerCollection *layer_collection,
+ LayerCollection *parent_layer_collection)
+{
+ DEG_debug_print_eval_parent_typed(
+ depsgraph,
+ __func__,
+ layer_collection->scene_collection->name,
+ layer_collection->scene_collection,
+ collection_type_lookup[layer_collection->scene_collection->type],
+ "parent",
+ (parent_layer_collection != NULL) ? parent_layer_collection->scene_collection->name : "NONE",
+ (parent_layer_collection != NULL) ? parent_layer_collection->scene_collection : NULL,
+ (parent_layer_collection != NULL) ? collection_type_lookup[parent_layer_collection->scene_collection->type] : "");
+ BLI_assert(layer_collection != parent_layer_collection);
+
+ /* visibility */
+ layer_collection->flag_evaluated = layer_collection->flag;
+
+ if (parent_layer_collection != NULL) {
+ if (layer_collection_visible_get(depsgraph, parent_layer_collection) == false) {
+ layer_collection->flag_evaluated |= COLLECTION_DISABLED;
+ }
+
+ if ((parent_layer_collection->flag_evaluated & COLLECTION_DISABLED) ||
+ (parent_layer_collection->flag_evaluated & COLLECTION_SELECTABLE) == 0)
+ {
+ layer_collection->flag_evaluated &= ~COLLECTION_SELECTABLE;
+ }
+ }
+
+ const bool is_visible = layer_collection_visible_get(depsgraph, layer_collection);
+ const bool is_selectable = is_visible && ((layer_collection->flag_evaluated & COLLECTION_SELECTABLE) != 0);
+
+ /* overrides */
+ if (is_visible) {
+ if (parent_layer_collection == NULL) {
+ idproperty_reset(&layer_collection->properties_evaluated, layer_collection->properties);
+ }
+ else {
+ idproperty_reset(&layer_collection->properties_evaluated, parent_layer_collection->properties_evaluated);
+ IDP_MergeGroup(layer_collection->properties_evaluated, layer_collection->properties, true);
+ }
+ }
+
+ for (LinkData *link = layer_collection->object_bases.first; link != NULL; link = link->next) {
+ Base *base = link->data;
+
+ if (is_visible) {
+ IDP_MergeGroup(base->collection_properties, layer_collection->properties_evaluated, true);
+ base->flag |= BASE_VISIBLED;
+ }
+
+ if (is_selectable) {
+ base->flag |= BASE_SELECTABLED;
+ }
+ }
+}
+
+static void layer_eval_layer_collection_post(Depsgraph *depsgraph, ViewLayer *view_layer)
+{
+ DEG_debug_print_eval(depsgraph, __func__, view_layer->name, view_layer);
+ /* Create array of bases, for fast index-based lookup. */
+ const int num_object_bases = BLI_listbase_count(&view_layer->object_bases);
+ MEM_SAFE_FREE(view_layer->object_bases_array);
+ view_layer->object_bases_array = MEM_malloc_arrayN(
+ num_object_bases, sizeof(Base *), "view_layer->object_bases_array");
+ int base_index = 0;
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ /* if base is not selectabled, clear select. */
+ if ((base->flag & BASE_SELECTABLED) == 0) {
+ base->flag &= ~BASE_SELECTED;
+ }
+ /* Store base in the array. */
+ view_layer->object_bases_array[base_index++] = base;
+ }
+}
+
+static void layer_eval_collections_recurse(Depsgraph *depsgraph,
+ ListBase *layer_collections,
+ LayerCollection *parent_layer_collection)
+{
+ for (LayerCollection *layer_collection = layer_collections->first;
+ layer_collection != NULL;
+ layer_collection = layer_collection->next)
+ {
+ layer_eval_layer_collection(depsgraph,
+ layer_collection,
+ parent_layer_collection);
+ layer_eval_collections_recurse(depsgraph,
+ &layer_collection->layer_collections,
+ layer_collection);
+ }
+}
+
+void BKE_layer_eval_view_layer(struct Depsgraph *depsgraph,
+ struct ID *owner_id,
+ ViewLayer *view_layer)
+{
+ layer_eval_layer_collection_pre(depsgraph, owner_id, view_layer);
+ layer_eval_collections_recurse(depsgraph,
+ &view_layer->layer_collections,
+ NULL);
+ layer_eval_layer_collection_post(depsgraph, view_layer);
+}
+
+void BKE_layer_eval_view_layer_indexed(struct Depsgraph *depsgraph,
+ struct ID *owner_id,
+ int view_layer_index)
+{
+ BLI_assert(GS(owner_id->name) == ID_SCE);
+ BLI_assert(view_layer_index >= 0);
+ Scene *scene = (Scene *)owner_id;
+ ViewLayer *view_layer = BLI_findlink(&scene->view_layers, view_layer_index);
+ BLI_assert(view_layer != NULL);
+ BKE_layer_eval_view_layer(depsgraph, owner_id, view_layer);
+}
+
+/**
+ * Free any static allocated memory.
+ */
+void BKE_layer_exit(void)
+{
+ layer_collection_engine_settings_validate_free();
+}
diff --git a/source/blender/blenkernel/intern/layer_utils.c b/source/blender/blenkernel/intern/layer_utils.c
new file mode 100644
index 00000000000..94bac8a33d6
--- /dev/null
+++ b/source/blender/blenkernel/intern/layer_utils.c
@@ -0,0 +1,125 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/layer_utils.c
+ * \ingroup bke
+ */
+
+#include <string.h>
+
+#include "BLI_array.h"
+#include "BLI_listbase.h"
+
+#include "BKE_collection.h"
+#include "BKE_editmesh.h"
+#include "BKE_layer.h"
+
+#include "DNA_ID.h"
+#include "DNA_layer_types.h"
+#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_scene_types.h"
+
+#include "MEM_guardedalloc.h"
+
+Base **BKE_view_layer_array_from_bases_in_mode_params(
+ ViewLayer *view_layer, uint *r_len,
+ const struct ObjectsInModeParams *params)
+{
+ if (params->no_dup_data) {
+ FOREACH_BASE_IN_MODE_BEGIN(view_layer, params->object_mode, base_iter) {
+ ID *id = base_iter->object->data;
+ if (id) {
+ id->tag |= LIB_TAG_DOIT;
+ }
+ } FOREACH_BASE_IN_MODE_END;
+ }
+
+ Base **base_array = NULL;
+ BLI_array_declare(base_array);
+
+ FOREACH_BASE_IN_MODE_BEGIN(view_layer, params->object_mode, base_iter) {
+ if (params->filter_fn) {
+ if (!params->filter_fn(base_iter->object, params->filter_userdata)) {
+ continue;
+ }
+ }
+ if (params->no_dup_data) {
+ ID *id = base_iter->object->data;
+ if (id) {
+ if (id->tag & LIB_TAG_DOIT) {
+ id->tag &= ~LIB_TAG_DOIT;
+ }
+ else {
+ continue;
+ }
+ }
+ }
+ BLI_array_append(base_array, base_iter);
+ } FOREACH_BASE_IN_MODE_END;
+
+ if (base_array != NULL) {
+ base_array = MEM_reallocN(base_array, sizeof(*base_array) * BLI_array_len(base_array));
+ }
+ *r_len = BLI_array_len(base_array);
+ return base_array;
+}
+
+Object **BKE_view_layer_array_from_objects_in_mode_params(
+ ViewLayer *view_layer, uint *r_len,
+ const struct ObjectsInModeParams *params)
+{
+ Base **base_array = BKE_view_layer_array_from_bases_in_mode_params(
+ view_layer, r_len, params);
+ if (base_array != NULL) {
+ for (uint i = 0; i < *r_len; i++) {
+ ((Object **)base_array)[i] = base_array[i]->object;
+ }
+ }
+ return (Object **)base_array;
+}
+
+bool BKE_view_layer_filter_edit_mesh_has_uvs(Object *ob, void *UNUSED(user_data))
+{
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+ BMEditMesh *em = me->edit_btmesh;
+ if (em != NULL) {
+ if (CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV) != -1) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+bool BKE_view_layer_filter_edit_mesh_has_edges(Object *ob, void *UNUSED(user_data))
+{
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+ BMEditMesh *em = me->edit_btmesh;
+ if (em != NULL) {
+ if (em->bm->totedge != 0) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
diff --git a/source/blender/blenkernel/intern/library.c b/source/blender/blenkernel/intern/library.c
index 292f37b5ce9..2e56ed9d247 100644
--- a/source/blender/blenkernel/intern/library.c
+++ b/source/blender/blenkernel/intern/library.c
@@ -62,6 +62,7 @@
#include "DNA_mask_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_speaker_types.h"
@@ -70,6 +71,7 @@
#include "DNA_vfont_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_world_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
@@ -78,8 +80,8 @@
#include "BLI_memarena.h"
#include "BLI_mempool.h"
#include "BLI_string_utils.h"
-
#include "BLI_threads.h"
+
#include "BLT_translation.h"
#include "BKE_action.h"
@@ -91,7 +93,6 @@
#include "BKE_cachefile.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_font.h"
#include "BKE_global.h"
#include "BKE_group.h"
@@ -103,6 +104,7 @@
#include "BKE_lamp.h"
#include "BKE_lattice.h"
#include "BKE_library.h"
+#include "BKE_library_override.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
#include "BKE_linestyle.h"
@@ -117,6 +119,7 @@
#include "BKE_paint.h"
#include "BKE_particle.h"
#include "BKE_packedFile.h"
+#include "BKE_lightprobe.h"
#include "BKE_sound.h"
#include "BKE_speaker.h"
#include "BKE_scene.h"
@@ -418,6 +421,9 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local)
case ID_SPK:
if (!test) BKE_speaker_make_local(bmain, (Speaker *)id, lib_local);
return true;
+ case ID_LP:
+ if (!test) BKE_lightprobe_make_local(bmain, (LightProbe *)id, lib_local);
+ return true;
case ID_WO:
if (!test) BKE_world_make_local(bmain, (World *)id, lib_local);
return true;
@@ -469,7 +475,11 @@ bool id_make_local(Main *bmain, ID *id, const bool test, const bool lib_local)
case ID_CF:
if (!test) BKE_cachefile_make_local(bmain, (CacheFile *)id, lib_local);
return true;
+ case ID_WS:
case ID_SCR:
+ /* A bit special: can be appended but not linked. Return false
+ * since supporting make-local doesn't make much sense. */
+ return false;
case ID_LI:
case ID_KE:
case ID_WM:
@@ -589,6 +599,9 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
case ID_SPK:
BKE_speaker_copy_data(bmain, (Speaker *)*r_newid, (Speaker *)id, flag);
break;
+ case ID_LP:
+ BKE_lightprobe_copy_data(bmain, (LightProbe *)*r_newid, (LightProbe *)id, flag);
+ break;
case ID_CA:
BKE_camera_copy_data(bmain, (Camera *)*r_newid, (Camera *)id, flag);
break;
@@ -649,6 +662,7 @@ bool BKE_id_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int flag, con
case ID_LI:
case ID_SCR:
case ID_WM:
+ case ID_WS:
case ID_IP:
BLI_assert(0); /* Should have been rejected at start of function! */
break;
@@ -680,6 +694,75 @@ bool id_copy(Main *bmain, const ID *id, ID **newid, bool test)
return BKE_id_copy_ex(bmain, id, newid, 0, test);
}
+/** Does a mere memory swap over the whole IDs data (including type-specific memory).
+ * \note Most internal ID data itself is not swapped (only IDProperties are). */
+void BKE_id_swap(Main *bmain, ID *id_a, ID *id_b)
+{
+ BLI_assert(GS(id_a->name) == GS(id_b->name));
+
+ const ID id_a_back = *id_a;
+ const ID id_b_back = *id_b;
+
+#define CASE_SWAP(_gs, _type) \
+ case _gs: \
+ SWAP(_type, *(_type *)id_a, *(_type *)id_b); \
+ break
+
+ switch ((ID_Type)GS(id_a->name)) {
+ CASE_SWAP(ID_SCE, Scene);
+ CASE_SWAP(ID_LI, Library);
+ CASE_SWAP(ID_OB, Object);
+ CASE_SWAP(ID_ME, Mesh);
+ CASE_SWAP(ID_CU, Curve);
+ CASE_SWAP(ID_MB, MetaBall);
+ CASE_SWAP(ID_MA, Material);
+ CASE_SWAP(ID_TE, Tex);
+ CASE_SWAP(ID_IM, Image);
+ CASE_SWAP(ID_LT, Lattice);
+ CASE_SWAP(ID_LA, Lamp);
+ CASE_SWAP(ID_LP, LightProbe);
+ CASE_SWAP(ID_CA, Camera);
+ CASE_SWAP(ID_KE, Key);
+ CASE_SWAP(ID_WO, World);
+ CASE_SWAP(ID_SCR, bScreen);
+ CASE_SWAP(ID_VF, VFont);
+ CASE_SWAP(ID_TXT, Text);
+ CASE_SWAP(ID_SPK, Speaker);
+ CASE_SWAP(ID_SO, bSound);
+ CASE_SWAP(ID_GR, Group);
+ CASE_SWAP(ID_AR, bArmature);
+ CASE_SWAP(ID_AC, bAction);
+ CASE_SWAP(ID_NT, bNodeTree);
+ CASE_SWAP(ID_BR, Brush);
+ CASE_SWAP(ID_PA, ParticleSettings);
+ CASE_SWAP(ID_WM, wmWindowManager);
+ CASE_SWAP(ID_WS, WorkSpace);
+ CASE_SWAP(ID_GD, bGPdata);
+ CASE_SWAP(ID_MC, MovieClip);
+ CASE_SWAP(ID_MSK, Mask);
+ CASE_SWAP(ID_LS, FreestyleLineStyle);
+ CASE_SWAP(ID_PAL, Palette);
+ CASE_SWAP(ID_PC, PaintCurve);
+ CASE_SWAP(ID_CF, CacheFile);
+ case ID_IP:
+ break; /* Deprecated. */
+ }
+
+#undef CASE_SWAP
+
+ /* Restore original ID's internal data. */
+ *id_a = id_a_back;
+ *id_b = id_b_back;
+
+ /* Exception: IDProperties. */
+ id_a->properties = id_b_back.properties;
+ id_b->properties = id_a_back.properties;
+
+ /* Swap will have broken internal references to itself, restore them. */
+ BKE_libblock_relink_ex(bmain, id_a, id_b, id_a, false);
+ BKE_libblock_relink_ex(bmain, id_b, id_a, id_b, false);
+}
+
/** Does *not* set ID->newid pointer. */
bool id_single_user(bContext *C, ID *id, PointerRNA *ptr, PropertyRNA *prop)
{
@@ -847,6 +930,8 @@ ListBase *which_libbase(Main *mainlib, short type)
return &(mainlib->text);
case ID_SPK:
return &(mainlib->speaker);
+ case ID_LP:
+ return &(mainlib->lightprobe);
case ID_SO:
return &(mainlib->sound);
case ID_GR:
@@ -877,6 +962,8 @@ ListBase *which_libbase(Main *mainlib, short type)
return &(mainlib->paintcurves);
case ID_CF:
return &(mainlib->cachefiles);
+ case ID_WS:
+ return &(mainlib->workspaces);
}
return NULL;
}
@@ -962,11 +1049,11 @@ void BKE_main_lib_objects_recalc_all(Main *bmain)
/* flag for full recalc */
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (ID_IS_LINKED(ob)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
}
}
- DAG_id_type_tag(bmain, ID_OB);
+ DEG_id_type_tag(bmain, ID_OB);
}
/**
@@ -1015,6 +1102,7 @@ int set_listbasepointers(Main *main, ListBase **lb)
lb[INDEX_ID_BR] = &(main->brush);
lb[INDEX_ID_PA] = &(main->particle);
lb[INDEX_ID_SPK] = &(main->speaker);
+ lb[INDEX_ID_LP] = &(main->lightprobe);
lb[INDEX_ID_WO] = &(main->world);
lb[INDEX_ID_MC] = &(main->movieclip);
@@ -1022,6 +1110,7 @@ int set_listbasepointers(Main *main, ListBase **lb)
lb[INDEX_ID_OB] = &(main->object);
lb[INDEX_ID_LS] = &(main->linestyle); /* referenced by scenes */
lb[INDEX_ID_SCE] = &(main->scene);
+ lb[INDEX_ID_WS] = &(main->workspaces); /* before wm, so it's freed after it! */
lb[INDEX_ID_WM] = &(main->wm);
lb[INDEX_ID_MSK] = &(main->mask);
@@ -1074,6 +1163,7 @@ size_t BKE_libblock_get_alloc_info(short type, const char **name)
CASE_RETURN(ID_VF, VFont);
CASE_RETURN(ID_TXT, Text);
CASE_RETURN(ID_SPK, Speaker);
+ CASE_RETURN(ID_LP, LightProbe);
CASE_RETURN(ID_SO, bSound);
CASE_RETURN(ID_GR, Group);
CASE_RETURN(ID_AR, bArmature);
@@ -1089,6 +1179,7 @@ size_t BKE_libblock_get_alloc_info(short type, const char **name)
CASE_RETURN(ID_PAL, Palette);
CASE_RETURN(ID_PC, PaintCurve);
CASE_RETURN(ID_CF, CacheFile);
+ CASE_RETURN(ID_WS, WorkSpace);
}
return 0;
#undef CASE_RETURN
@@ -1146,7 +1237,7 @@ void *BKE_libblock_alloc(Main *bmain, short type, const char *name, const int fl
/* TODO to be removed from here! */
if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0) {
- DAG_id_type_tag(bmain, type);
+ DEG_id_type_tag(bmain, type);
}
}
else {
@@ -1205,6 +1296,9 @@ void BKE_libblock_init_empty(ID *id)
case ID_SPK:
BKE_speaker_init((Speaker *)id);
break;
+ case ID_LP:
+ BKE_lightprobe_init((LightProbe *)id);
+ break;
case ID_CA:
BKE_camera_init((Camera *)id);
break;
@@ -1274,6 +1368,41 @@ void BKE_libblock_init_empty(ID *id)
}
}
+/** Generic helper to create a new empty datablock of given type in given \a bmain database.
+ *
+ * \param name can be NULL, in which case we get default name for this ID type. */
+void *BKE_id_new(Main *bmain, const short type, const char *name)
+{
+ BLI_assert(bmain != NULL);
+
+ if (name == NULL) {
+ name = DATA_(BKE_idcode_to_name(type));
+ }
+
+ ID *id = BKE_libblock_alloc(bmain, type, name, 0);
+ BKE_libblock_init_empty(id);
+
+ return id;
+}
+
+/** Generic helper to create a new temporary empty datablock of given type, *outside* of any Main database.
+ *
+ * \param name can be NULL, in which case we get default name for this ID type. */
+void *BKE_id_new_nomain(const short type, const char *name)
+{
+ if (name == NULL) {
+ name = DATA_(BKE_idcode_to_name(type));
+ }
+
+ ID *id = BKE_libblock_alloc(NULL, type, name,
+ LIB_ID_CREATE_NO_MAIN |
+ LIB_ID_CREATE_NO_USER_REFCOUNT |
+ LIB_ID_CREATE_NO_DEG_TAG);
+ BKE_libblock_init_empty(id);
+
+ return id;
+}
+
/* by spec, animdata is first item after ID */
/* and, trust that BKE_animdata_from_id() will only find AnimData for valid ID-types */
static void id_copy_animdata(Main *bmain, ID *id, const bool do_action)
@@ -1282,7 +1411,7 @@ static void id_copy_animdata(Main *bmain, ID *id, const bool do_action)
if (adt) {
IdAdtTemplate *iat = (IdAdtTemplate *)id;
- iat->adt = BKE_animdata_copy(bmain, iat->adt, do_action); /* could be set to false, need to investigate */
+ iat->adt = BKE_animdata_copy(bmain, iat->adt, do_action, true); /* could be set to false, need to investigate */
}
}
@@ -1325,12 +1454,27 @@ void BKE_libblock_copy_ex(Main *bmain, const ID *id, ID **r_newid, const int fla
new_id->properties = IDP_CopyProperty_ex(id->properties, flag);
}
+ /* XXX Again... We need a way to control what we copy in a much more refined way.
+ * We cannot always copy this, some internal copying will die on it! */
+ /* For now, upper level code will have to do that itself when required. */
+#if 0
+ if (id->override != NULL) {
+ BKE_override_copy(new_id, id);
+ }
+#endif
+
/* the duplicate should get a copy of the animdata */
- BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0);
- id_copy_animdata(bmain, new_id, (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0);
+ if ((flag & LIB_ID_COPY_NO_ANIMDATA) == 0) {
+ BLI_assert((flag & LIB_ID_COPY_ACTIONS) == 0 || (flag & LIB_ID_CREATE_NO_MAIN) == 0);
+ id_copy_animdata(bmain, new_id, (flag & LIB_ID_COPY_ACTIONS) != 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0);
+ }
+ else if (id_can_have_animdata(new_id)) {
+ IdAdtTemplate *iat = (IdAdtTemplate *)new_id;
+ iat->adt = NULL;
+ }
if ((flag & LIB_ID_CREATE_NO_DEG_TAG) == 0 && (flag & LIB_ID_CREATE_NO_MAIN) == 0) {
- DAG_id_type_tag(bmain, GS(new_id->name));
+ DEG_id_type_tag(bmain, GS(new_id->name));
}
*r_newid = new_id;
@@ -1364,7 +1508,6 @@ void BKE_library_free(Library *lib)
Main *BKE_main_new(void)
{
Main *bmain = MEM_callocN(sizeof(Main), "new main");
- bmain->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_VIEWPORT);
bmain->lock = MEM_mallocN(sizeof(SpinLock), "main lock");
BLI_spin_init((SpinLock *)bmain->lock);
return bmain;
@@ -1439,7 +1582,6 @@ void BKE_main_free(Main *mainvar)
BLI_spin_end((SpinLock *)mainvar->lock);
MEM_freeN(mainvar->lock);
- DEG_evaluation_context_free(mainvar->eval_ctx);
MEM_freeN(mainvar);
}
diff --git a/source/blender/blenkernel/intern/library_override.c b/source/blender/blenkernel/intern/library_override.c
new file mode 100644
index 00000000000..31e621b236f
--- /dev/null
+++ b/source/blender/blenkernel/intern/library_override.c
@@ -0,0 +1,771 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Bastien Montagne.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/library_override.c
+ * \ingroup bke
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_ID.h"
+#include "DNA_object_types.h"
+
+#include "DEG_depsgraph.h"
+#include "BKE_library.h"
+#include "BKE_library_override.h"
+#include "BKE_library_remap.h"
+#include "BKE_main.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+
+#include "RNA_access.h"
+#include "RNA_types.h"
+
+#include "PIL_time.h"
+#include "PIL_time_utildefines.h"
+
+#define OVERRIDE_AUTO_CHECK_DELAY 0.2 /* 200ms between auto-override checks. */
+
+static void bke_override_property_copy(IDOverrideStaticProperty *op_dst, IDOverrideStaticProperty *op_src);
+static void bke_override_property_operation_copy(IDOverrideStaticPropertyOperation *opop_dst, IDOverrideStaticPropertyOperation *opop_src);
+
+static void bke_override_property_clear(IDOverrideStaticProperty *op);
+static void bke_override_property_operation_clear(IDOverrideStaticPropertyOperation *opop);
+
+/** Initialize empty overriding of \a reference_id by \a local_id. */
+IDOverrideStatic *BKE_override_static_init(ID *local_id, ID *reference_id)
+{
+ /* If reference_id is NULL, we are creating an override template for purely local data.
+ * Else, reference *must* be linked data. */
+ BLI_assert(reference_id == NULL || reference_id->lib != NULL);
+ BLI_assert(local_id->override_static == NULL);
+
+ ID *ancestor_id;
+ for (ancestor_id = reference_id;
+ ancestor_id != NULL && ancestor_id->override_static != NULL && ancestor_id->override_static->reference != NULL;
+ ancestor_id = ancestor_id->override_static->reference);
+
+ if (ancestor_id != NULL && ancestor_id->override_static != NULL) {
+ /* Original ID has a template, use it! */
+ BKE_override_static_copy(local_id, ancestor_id);
+ if (local_id->override_static->reference != reference_id) {
+ id_us_min(local_id->override_static->reference);
+ local_id->override_static->reference = reference_id;
+ id_us_plus(local_id->override_static->reference);
+ }
+ return local_id->override_static;
+ }
+
+ /* Else, generate new empty override. */
+ local_id->override_static = MEM_callocN(sizeof(*local_id->override_static), __func__);
+ local_id->override_static->reference = reference_id;
+ id_us_plus(local_id->override_static->reference);
+ local_id->tag &= ~LIB_TAG_OVERRIDESTATIC_REFOK;
+ /* TODO do we want to add tag or flag to referee to mark it as such? */
+ return local_id->override_static;
+}
+
+/** Deep copy of a whole override from \a src_id to \a dst_id. */
+void BKE_override_static_copy(ID *dst_id, const ID *src_id)
+{
+ BLI_assert(src_id->override_static != NULL);
+
+ if (dst_id->override_static != NULL) {
+ if (src_id->override_static == NULL) {
+ BKE_override_static_free(&dst_id->override_static);
+ return;
+ }
+ else {
+ BKE_override_static_clear(dst_id->override_static);
+ }
+ }
+ else if (src_id->override_static == NULL) {
+ return;
+ }
+ else {
+ BKE_override_static_init(dst_id, NULL);
+ }
+
+ /* Source is already overriding data, we copy it but reuse its reference for dest ID.
+ * otherwise, source is only an override template, it then becomes reference of dest ID. */
+ dst_id->override_static->reference = src_id->override_static->reference ? src_id->override_static->reference : (ID *)src_id;
+ id_us_plus(dst_id->override_static->reference);
+
+ BLI_duplicatelist(&dst_id->override_static->properties, &src_id->override_static->properties);
+ for (IDOverrideStaticProperty *op_dst = dst_id->override_static->properties.first, *op_src = src_id->override_static->properties.first;
+ op_dst;
+ op_dst = op_dst->next, op_src = op_src->next)
+ {
+ bke_override_property_copy(op_dst, op_src);
+ }
+
+ dst_id->tag &= ~LIB_TAG_OVERRIDESTATIC_REFOK;
+}
+
+/** Clear any overriding data from given \a override. */
+void BKE_override_static_clear(IDOverrideStatic *override)
+{
+ BLI_assert(override != NULL);
+
+ for (IDOverrideStaticProperty *op = override->properties.first; op; op = op->next) {
+ bke_override_property_clear(op);
+ }
+ BLI_freelistN(&override->properties);
+
+ id_us_min(override->reference);
+ /* override->storage should never be refcounted... */
+}
+
+/** Free given \a override. */
+void BKE_override_static_free(struct IDOverrideStatic **override)
+{
+ BLI_assert(*override != NULL);
+
+ BKE_override_static_clear(*override);
+ MEM_freeN(*override);
+ *override = NULL;
+}
+
+static ID *override_static_create_from(Main *bmain, ID *reference_id)
+{
+ ID *local_id;
+
+ if (!id_copy(bmain, reference_id, (ID **)&local_id, false)) {
+ return NULL;
+ }
+ id_us_min(local_id);
+
+ BKE_override_static_init(local_id, reference_id);
+ local_id->override_static->flag |= STATICOVERRIDE_AUTO;
+
+ return local_id;
+}
+
+
+/** Create an overriden local copy of linked reference. */
+ID *BKE_override_static_create_from_id(Main *bmain, ID *reference_id)
+{
+ BLI_assert(reference_id != NULL);
+ BLI_assert(reference_id->lib != NULL);
+
+ ID *local_id = override_static_create_from(bmain, reference_id);
+
+ /* Remapping, we obviously only want to affect local data (and not our own reference pointer to overriden ID). */
+ BKE_libblock_remap(bmain, reference_id, local_id, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE);
+
+ return local_id;
+}
+
+/** Create overriden local copies of all tagged data-blocks in given Main.
+ *
+ * \note Set id->newid of overridden libs with newly created overrides, caller is responsible to clean those pointers
+ * before/after usage as needed.
+ *
+ * \return \a true on success, \a false otherwise.
+ */
+bool BKE_override_static_create_from_tag(Main *bmain)
+{
+ ListBase *lbarray[MAX_LIBARRAY];
+ int a;
+ bool ret = true;
+
+ const int num_types = a = set_listbasepointers(bmain, lbarray);
+ while (a--) {
+ for (ID *reference_id = lbarray[a]->first; reference_id != NULL; reference_id = reference_id->next) {
+ if ((reference_id->tag & LIB_TAG_DOIT) != 0 && reference_id->lib != NULL) {
+ if ((reference_id->newid = override_static_create_from(bmain, reference_id)) == NULL) {
+ ret = false;
+ }
+ }
+ }
+ }
+
+ /* Remapping, we obviously only want to affect local data (and not our own reference pointer to overriden ID). */
+ a = num_types;
+ while (a--) {
+ for (ID *reference_id = lbarray[a]->first; reference_id != NULL; reference_id = reference_id->next) {
+ if ((reference_id->tag & LIB_TAG_DOIT) != 0 && reference_id->lib != NULL && reference_id->newid != NULL) {
+ ID *local_id = reference_id->newid;
+ BKE_libblock_remap(bmain, reference_id, local_id,
+ ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_STATIC_OVERRIDE);
+ }
+ }
+ }
+
+ return ret;
+}
+
+/**
+ * Find override property from given RNA path, if it exists.
+ */
+IDOverrideStaticProperty *BKE_override_static_property_find(IDOverrideStatic *override, const char *rna_path)
+{
+ /* XXX TODO we'll most likely want a runtime ghash to store that mapping at some point. */
+ return BLI_findstring_ptr(&override->properties, rna_path, offsetof(IDOverrideStaticProperty, rna_path));
+}
+
+/**
+ * Find override property from given RNA path, or create it if it does not exist.
+ */
+IDOverrideStaticProperty *BKE_override_static_property_get(IDOverrideStatic *override, const char *rna_path, bool *r_created)
+{
+ /* XXX TODO we'll most likely want a runtime ghash to store taht mapping at some point. */
+ IDOverrideStaticProperty *op = BKE_override_static_property_find(override, rna_path);
+
+ if (op == NULL) {
+ op = MEM_callocN(sizeof(IDOverrideStaticProperty), __func__);
+ op->rna_path = BLI_strdup(rna_path);
+ BLI_addtail(&override->properties, op);
+
+ if (r_created) {
+ *r_created = true;
+ }
+ }
+ else if (r_created) {
+ *r_created = false;
+ }
+
+ return op;
+}
+
+void bke_override_property_copy(IDOverrideStaticProperty *op_dst, IDOverrideStaticProperty *op_src)
+{
+ op_dst->rna_path = BLI_strdup(op_src->rna_path);
+ BLI_duplicatelist(&op_dst->operations, &op_src->operations);
+
+ for (IDOverrideStaticPropertyOperation *opop_dst = op_dst->operations.first, *opop_src = op_src->operations.first;
+ opop_dst;
+ opop_dst = opop_dst->next, opop_src = opop_src->next)
+ {
+ bke_override_property_operation_copy(opop_dst, opop_src);
+ }
+}
+
+void bke_override_property_clear(IDOverrideStaticProperty *op)
+{
+ BLI_assert(op->rna_path != NULL);
+
+ MEM_freeN(op->rna_path);
+
+ for (IDOverrideStaticPropertyOperation *opop = op->operations.first; opop; opop = opop->next) {
+ bke_override_property_operation_clear(opop);
+ }
+ BLI_freelistN(&op->operations);
+}
+
+/**
+ * Remove and free given \a override_property from given ID \a override.
+ */
+void BKE_override_static_property_delete(IDOverrideStatic *override, IDOverrideStaticProperty *override_property)
+{
+ bke_override_property_clear(override_property);
+ BLI_freelinkN(&override->properties, override_property);
+}
+
+/**
+ * Find override property operation from given sub-item(s), if it exists.
+ */
+IDOverrideStaticPropertyOperation *BKE_override_static_property_operation_find(
+ IDOverrideStaticProperty *override_property,
+ const char *subitem_refname, const char *subitem_locname,
+ const int subitem_refindex, const int subitem_locindex, const bool strict, bool *r_strict)
+{
+ IDOverrideStaticPropertyOperation *opop;
+ const int subitem_defindex = -1;
+
+ if (r_strict) {
+ *r_strict = true;
+ }
+
+ if (subitem_locname != NULL) {
+ opop = BLI_findstring_ptr(&override_property->operations, subitem_locname,
+ offsetof(IDOverrideStaticPropertyOperation, subitem_local_name));
+
+ if (opop == NULL) {
+ return NULL;
+ }
+
+ if (subitem_refname == NULL || opop->subitem_reference_name == NULL) {
+ return subitem_refname == opop->subitem_reference_name ? opop : NULL;
+ }
+ return (subitem_refname != NULL && opop->subitem_reference_name != NULL &&
+ STREQ(subitem_refname, opop->subitem_reference_name)) ? opop : NULL;
+ }
+
+ if (subitem_refname != NULL) {
+ opop = BLI_findstring_ptr(&override_property->operations, subitem_refname,
+ offsetof(IDOverrideStaticPropertyOperation, subitem_reference_name));
+
+ if (opop == NULL) {
+ return NULL;
+ }
+
+ if (subitem_locname == NULL || opop->subitem_local_name == NULL) {
+ return subitem_locname == opop->subitem_local_name ? opop : NULL;
+ }
+ return (subitem_locname != NULL && opop->subitem_local_name != NULL &&
+ STREQ(subitem_locname, opop->subitem_local_name)) ? opop : NULL;
+ }
+
+ if ((opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_locindex, sizeof(subitem_locindex),
+ offsetof(IDOverrideStaticPropertyOperation, subitem_local_index))))
+ {
+ return ELEM(subitem_refindex, -1, opop->subitem_reference_index) ? opop : NULL;
+ }
+
+ if ((opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_refindex, sizeof(subitem_refindex),
+ offsetof(IDOverrideStaticPropertyOperation, subitem_reference_index))))
+ {
+ return ELEM(subitem_locindex, -1, opop->subitem_local_index) ? opop : NULL;
+ }
+
+ /* index == -1 means all indices, that is valid fallback in case we requested specific index. */
+ if (!strict && (subitem_locindex != subitem_defindex) &&
+ (opop = BLI_listbase_bytes_find(&override_property->operations, &subitem_defindex, sizeof(subitem_defindex),
+ offsetof(IDOverrideStaticPropertyOperation, subitem_local_index))))
+ {
+ if (r_strict) {
+ *r_strict = false;
+ }
+ return opop;
+ }
+
+ return NULL;
+}
+
+/**
+ * Find override property operation from given sub-item(s), or create it if it does not exist.
+ */
+IDOverrideStaticPropertyOperation *BKE_override_static_property_operation_get(
+ IDOverrideStaticProperty *override_property, const short operation,
+ const char *subitem_refname, const char *subitem_locname,
+ const int subitem_refindex, const int subitem_locindex,
+ const bool strict, bool *r_strict, bool *r_created)
+{
+ IDOverrideStaticPropertyOperation *opop = BKE_override_static_property_operation_find(override_property,
+ subitem_refname, subitem_locname,
+ subitem_refindex, subitem_locindex,
+ strict, r_strict);
+
+ if (opop == NULL) {
+ opop = MEM_callocN(sizeof(IDOverrideStaticPropertyOperation), __func__);
+ opop->operation = operation;
+ if (subitem_locname) {
+ opop->subitem_local_name = BLI_strdup(subitem_locname);
+ }
+ if (subitem_refname) {
+ opop->subitem_reference_name = BLI_strdup(subitem_refname);
+ }
+ opop->subitem_local_index = subitem_locindex;
+ opop->subitem_reference_index = subitem_refindex;
+
+ BLI_addtail(&override_property->operations, opop);
+
+ if (r_created) {
+ *r_created = true;
+ }
+ }
+ else if (r_created) {
+ *r_created = false;
+ }
+
+ return opop;
+}
+
+void bke_override_property_operation_copy(IDOverrideStaticPropertyOperation *opop_dst, IDOverrideStaticPropertyOperation *opop_src)
+{
+ if (opop_src->subitem_reference_name) {
+ opop_dst->subitem_reference_name = BLI_strdup(opop_src->subitem_reference_name);
+ }
+ if (opop_src->subitem_local_name) {
+ opop_dst->subitem_local_name = BLI_strdup(opop_src->subitem_local_name);
+ }
+}
+
+void bke_override_property_operation_clear(IDOverrideStaticPropertyOperation *opop)
+{
+ if (opop->subitem_reference_name) {
+ MEM_freeN(opop->subitem_reference_name);
+ }
+ if (opop->subitem_local_name) {
+ MEM_freeN(opop->subitem_local_name);
+ }
+}
+
+/**
+ * Remove and free given \a override_property_operation from given ID \a override_property.
+ */
+void BKE_override_static_property_operation_delete(
+ IDOverrideStaticProperty *override_property, IDOverrideStaticPropertyOperation *override_property_operation)
+{
+ bke_override_property_operation_clear(override_property_operation);
+ BLI_freelinkN(&override_property->operations, override_property_operation);
+}
+
+/**
+ * Check that status of local data-block is still valid against current reference one.
+ *
+ * It means that all overridable, but not overridden, properties' local values must be equal to reference ones.
+ * Clears LIB_TAG_OVERRIDE_OK if they do not.
+ *
+ * This is typically used to detect whether some property has been changed in local and a new IDOverrideProperty
+ * (of IDOverridePropertyOperation) has to be added.
+ *
+ * \return true if status is OK, false otherwise. */
+bool BKE_override_static_status_check_local(ID *local)
+{
+ BLI_assert(local->override_static != NULL);
+
+ ID *reference = local->override_static->reference;
+
+ if (reference == NULL) {
+ /* This is an override template, local status is always OK! */
+ return true;
+ }
+
+ BLI_assert(GS(local->name) == GS(reference->name));
+
+ /* Note that reference is assumed always valid, caller has to ensure that itself. */
+
+ PointerRNA rnaptr_local, rnaptr_reference;
+ RNA_id_pointer_create(local, &rnaptr_local);
+ RNA_id_pointer_create(reference, &rnaptr_reference);
+
+ if (!RNA_struct_override_matches(
+ &rnaptr_local, &rnaptr_reference, NULL, local->override_static,
+ RNA_OVERRIDE_COMPARE_IGNORE_NON_OVERRIDABLE | RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN, NULL))
+ {
+ local->tag &= ~LIB_TAG_OVERRIDESTATIC_REFOK;
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Check that status of reference data-block is still valid against current local one.
+ *
+ * It means that all non-overridden properties' local values must be equal to reference ones.
+ * Clears LIB_TAG_OVERRIDE_OK if they do not.
+ *
+ * This is typically used to detect whether some reference has changed and local needs to be updated against it.
+ *
+ * \return true if status is OK, false otherwise. */
+bool BKE_override_static_status_check_reference(ID *local)
+{
+ BLI_assert(local->override_static != NULL);
+
+ ID *reference = local->override_static->reference;
+
+ if (reference == NULL) {
+ /* This is an override template, reference is virtual, so its status is always OK! */
+ return true;
+ }
+
+ BLI_assert(GS(local->name) == GS(reference->name));
+
+ if (reference->override_static && (reference->tag & LIB_TAG_OVERRIDESTATIC_REFOK) == 0) {
+ if (!BKE_override_static_status_check_reference(reference)) {
+ /* If reference is also override of another data-block, and its status is not OK,
+ * then this override is not OK either.
+ * Note that this should only happen when reloading libraries... */
+ local->tag &= ~LIB_TAG_OVERRIDESTATIC_REFOK;
+ return false;
+ }
+ }
+
+ PointerRNA rnaptr_local, rnaptr_reference;
+ RNA_id_pointer_create(local, &rnaptr_local);
+ RNA_id_pointer_create(reference, &rnaptr_reference);
+
+ if (!RNA_struct_override_matches(
+ &rnaptr_local, &rnaptr_reference, NULL, local->override_static,
+ RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN, NULL))
+ {
+ local->tag &= ~LIB_TAG_OVERRIDESTATIC_REFOK;
+ return false;
+ }
+
+ return true;
+}
+
+/**
+ * Compares local and reference data-blocks and create new override operations as needed,
+ * or reset to reference values if overriding is not allowed.
+ *
+ * \note Defining override operations is only mandatory before saving a .blend file on disk (not for undo!).
+ * Knowing that info at runtime is only useful for UI/UX feedback.
+ *
+ * \note This is by far the biggest operation (the more time-consuming) of the three so far, since it has to go over
+ * all properties in depth (all overridable ones at least). Generating diff values and applying overrides
+ * are much cheaper.
+ *
+ * \return true if new overriding op was created, or some local data was reset. */
+bool BKE_override_static_operations_create(ID *local, const bool force_auto)
+{
+ BLI_assert(local->override_static != NULL);
+ const bool is_template = (local->override_static->reference == NULL);
+ bool ret = false;
+
+ if (!is_template && (force_auto || local->override_static->flag & STATICOVERRIDE_AUTO)) {
+ PointerRNA rnaptr_local, rnaptr_reference;
+ RNA_id_pointer_create(local, &rnaptr_local);
+ RNA_id_pointer_create(local->override_static->reference, &rnaptr_reference);
+
+ eRNAOverrideMatchResult report_flags = 0;
+ RNA_struct_override_matches(
+ &rnaptr_local, &rnaptr_reference, NULL, local->override_static,
+ RNA_OVERRIDE_COMPARE_CREATE | RNA_OVERRIDE_COMPARE_RESTORE, &report_flags);
+ if (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) {
+ ret = true;
+ }
+#ifndef NDEBUG
+ if (report_flags & RNA_OVERRIDE_MATCH_RESULT_RESTORED) {
+ printf("We did restore some properties of %s from its reference.\n", local->name);
+ }
+ if (ret) {
+ printf("We did generate static override rules for %s\n", local->name);
+ }
+ else {
+ printf("No new static override rules for %s\n", local->name);
+ }
+#endif
+ }
+ return ret;
+}
+
+/** Check all overrides from given \a bmain and create/update overriding operations as needed. */
+void BKE_main_override_static_operations_create(Main *bmain, const bool force_auto)
+{
+ ListBase *lbarray[MAX_LIBARRAY];
+ int base_count, i;
+
+ base_count = set_listbasepointers(bmain, lbarray);
+
+ for (i = 0; i < base_count; i++) {
+ ListBase *lb = lbarray[i];
+ ID *id;
+
+ for (id = lb->first; id; id = id->next) {
+ if (force_auto ||
+ (ID_IS_STATIC_OVERRIDE_AUTO(id) && (id->tag & LIB_TAG_OVERRIDESTATIC_AUTOREFRESH)))
+ {
+ BKE_override_static_operations_create(id, force_auto);
+ id->tag &= ~LIB_TAG_OVERRIDESTATIC_AUTOREFRESH;
+ }
+ }
+ }
+}
+
+/** Update given override from its reference (re-applying overriden properties). */
+void BKE_override_static_update(Main *bmain, ID *local)
+{
+ if (local->override_static == NULL || local->override_static->reference == NULL) {
+ return;
+ }
+
+ /* Recursively do 'ancestors' overrides first, if any. */
+ if (local->override_static->reference->override_static && (local->override_static->reference->tag & LIB_TAG_OVERRIDESTATIC_REFOK) == 0) {
+ BKE_override_static_update(bmain, local->override_static->reference);
+ }
+
+ /* We want to avoid having to remap here, however creating up-to-date override is much simpler if based
+ * on reference than on current override.
+ * So we work on temp copy of reference, and 'swap' its content with local. */
+
+ /* XXX We need a way to get off-Main copies of IDs (similar to localized mats/texts/ etc.)!
+ * However, this is whole bunch of code work in itself, so for now plain stupid ID copy will do,
+ * as innefficient as it is. :/
+ * Actually, maybe not! Since we are swapping with original ID's local content, we want to keep
+ * usercount in correct state when freeing tmp_id (and that usercounts of IDs used by 'new' local data
+ * also remain correct). */
+ /* This would imply change in handling of usercout all over RNA (and possibly all over Blender code).
+ * Not impossible to do, but would rather see first if extra useless usual user handling is actually
+ * a (performances) issue here. */
+
+ ID *tmp_id;
+ id_copy(bmain, local->override_static->reference, &tmp_id, false);
+
+ if (tmp_id == NULL) {
+ return;
+ }
+
+ PointerRNA rnaptr_src, rnaptr_dst, rnaptr_storage_stack, *rnaptr_storage = NULL;
+ RNA_id_pointer_create(local, &rnaptr_src);
+ RNA_id_pointer_create(tmp_id, &rnaptr_dst);
+ if (local->override_static->storage) {
+ rnaptr_storage = &rnaptr_storage_stack;
+ RNA_id_pointer_create(local->override_static->storage, rnaptr_storage);
+ }
+
+ RNA_struct_override_apply(&rnaptr_dst, &rnaptr_src, rnaptr_storage, local->override_static);
+
+ /* This also transfers all pointers (memory) owned by local to tmp_id, and vice-versa. So when we'll free tmp_id,
+ * we'll actually free old, outdated data from local. */
+ BKE_id_swap(bmain, local, tmp_id);
+
+ /* Again, horribly innefficient in our case, we need something off-Main (aka moar generic nolib copy/free stuff)! */
+ /* XXX And crashing in complex cases (e.g. because depsgraph uses same data...). */
+ BKE_libblock_free_ex(bmain, tmp_id, true, false);
+
+ if (local->override_static->storage) {
+ /* We know this datablock is not used anywhere besides local->override->storage. */
+ /* XXX For until we get fully shadow copies, we still need to ensure storage releases
+ * its usage of any ID pointers it may have. */
+ BKE_libblock_free_ex(bmain, local->override_static->storage, true, false);
+ local->override_static->storage = NULL;
+ }
+
+ local->tag |= LIB_TAG_OVERRIDESTATIC_REFOK;
+
+ /* Full rebuild of Depsgraph! */
+ DEG_on_visible_update(bmain, true); /* XXX Is this actual valid replacement for old DAG_relations_tag_update(bmain) ? */
+}
+
+/** Update all overrides from given \a bmain. */
+void BKE_main_override_static_update(Main *bmain)
+{
+ ListBase *lbarray[MAX_LIBARRAY];
+ int base_count, i;
+
+ base_count = set_listbasepointers(bmain, lbarray);
+
+ for (i = 0; i < base_count; i++) {
+ ListBase *lb = lbarray[i];
+ ID *id;
+
+ for (id = lb->first; id; id = id->next) {
+ if (id->override_static != NULL && id->lib == NULL) {
+ BKE_override_static_update(bmain, id);
+ }
+ }
+ }
+}
+
+/***********************************************************************************************************************
+ * Storage (how to wtore overriding data into .blend files).
+ *
+ * Basically:
+ * I) Only 'differential' storage needs special handling here. All others (replacing values or
+ * inserting/removing items from a collection) can be handled with simply storing current content of local data-block.
+ * II) We store the differential value into a second 'ghost' data-block, which is an empty ID of same type as local one,
+ * where we only define values that need differential data.
+ *
+ * This avoids us having to modify 'real' data-block at write time (and retoring it afterwards), which is inneficient,
+ * and potentially dangerous (in case of concurrent access...), while not using much extra memory in typical cases.
+ * It also ensures stored data-block always contains exact same data as "desired" ones (kind of "baked" data-blocks).
+ */
+
+/** Initialize an override storage. */
+OverrideStaticStorage *BKE_override_static_operations_store_initialize(void)
+{
+ return BKE_main_new();
+}
+
+/**
+ * Generate suitable 'write' data (this only affects differential override operations).
+ *
+ * Note that \a local ID is no more modified by this call, all extra data are stored in its temp \a storage_id copy. */
+ID *BKE_override_static_operations_store_start(OverrideStaticStorage *override_storage, ID *local)
+{
+ BLI_assert(local->override_static != NULL);
+ BLI_assert(override_storage != NULL);
+ const bool is_template = (local->override_static->reference == NULL);
+
+ if (is_template) {
+ /* This is actually purely local data with an override template, nothing to do here! */
+ return NULL;
+ }
+
+ /* Forcefully ensure we know about all needed override operations. */
+ BKE_override_static_operations_create(local, false);
+
+ ID *storage_id;
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ TIMEIT_START_AVERAGED(BKE_override_operations_store_start);
+#endif
+
+ /* XXX TODO We may also want a specialized handling of things here too, to avoid copying heavy never-overridable
+ * data (like Mesh geometry etc.)? And also maybe avoid lib refcounting completely (shallow copy...). */
+ /* This would imply change in handling of usercout all over RNA (and possibly all over Blender code).
+ * Not impossible to do, but would rather see first is extra useless usual user handling is actually
+ * a (performances) issue here, before doing it. */
+ id_copy((Main *)override_storage, local, &storage_id, false);
+
+ if (storage_id != NULL) {
+ PointerRNA rnaptr_reference, rnaptr_final, rnaptr_storage;
+ RNA_id_pointer_create(local->override_static->reference, &rnaptr_reference);
+ RNA_id_pointer_create(local, &rnaptr_final);
+ RNA_id_pointer_create(storage_id, &rnaptr_storage);
+
+ if (!RNA_struct_override_store(&rnaptr_final, &rnaptr_reference, &rnaptr_storage, local->override_static)) {
+ BKE_libblock_free_ex(override_storage, storage_id, true, false);
+ storage_id = NULL;
+ }
+ }
+
+ local->override_static->storage = storage_id;
+
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ TIMEIT_END_AVERAGED(BKE_override_operations_store_start);
+#endif
+ return storage_id;
+}
+
+/** Restore given ID modified by \a BKE_override_operations_store_start, to its original state. */
+void BKE_override_static_operations_store_end(OverrideStaticStorage *UNUSED(override_storage), ID *local)
+{
+ BLI_assert(local->override_static != NULL);
+
+ /* Nothing else to do here really, we need to keep all temp override storage data-blocks in memory until
+ * whole file is written anyway (otherwise we'd get mem pointers overlap...). */
+ local->override_static->storage = NULL;
+}
+
+void BKE_override_static_operations_store_finalize(OverrideStaticStorage *override_storage)
+{
+ /* We cannot just call BKE_main_free(override_storage), not until we have option to make 'ghost' copies of IDs
+ * without increasing usercount of used data-blocks... */
+ ListBase *lbarray[MAX_LIBARRAY];
+ int base_count, i;
+
+ base_count = set_listbasepointers(override_storage, lbarray);
+
+ for (i = 0; i < base_count; i++) {
+ ListBase *lb = lbarray[i];
+ ID *id;
+
+ while ((id = lb->first)) {
+ BKE_libblock_free_ex(override_storage, id, true, false);
+ }
+ }
+
+ BKE_main_free(override_storage);
+}
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index d59658a2a07..efc550ac64c 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -31,13 +31,11 @@
#include "MEM_guardedalloc.h"
-#include "DNA_actuator_types.h"
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
#include "DNA_brush_types.h"
#include "DNA_camera_types.h"
#include "DNA_constraint_types.h"
-#include "DNA_controller_types.h"
#include "DNA_group_types.h"
#include "DNA_gpencil_types.h"
#include "DNA_key_types.h"
@@ -52,15 +50,17 @@
#include "DNA_mask_types.h"
#include "DNA_node_types.h"
#include "DNA_object_force_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
-#include "DNA_sensor_types.h"
#include "DNA_sequence_types.h"
#include "DNA_screen_types.h"
#include "DNA_speaker_types.h"
#include "DNA_sound_types.h"
#include "DNA_text_types.h"
#include "DNA_vfont_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_world_types.h"
#include "BLI_utildefines.h"
@@ -69,8 +69,10 @@
#include "BLI_linklist_stack.h"
#include "BKE_animsys.h"
+#include "BKE_collection.h"
#include "BKE_constraint.h"
#include "BKE_fcurve.h"
+#include "BKE_group.h"
#include "BKE_idprop.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
@@ -79,9 +81,9 @@
#include "BKE_node.h"
#include "BKE_particle.h"
#include "BKE_rigidbody.h"
-#include "BKE_sca.h"
#include "BKE_sequencer.h"
#include "BKE_tracking.h"
+#include "BKE_workspace.h"
#define FOREACH_FINALIZE _finalize
@@ -213,33 +215,6 @@ static void library_foreach_particlesystemsObjectLooper(
FOREACH_FINALIZE_VOID;
}
-static void library_foreach_sensorsObjectLooper(
- bSensor *UNUSED(sensor), ID **id_pointer, void *user_data, int cb_flag)
-{
- LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
- FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
-
- FOREACH_FINALIZE_VOID;
-}
-
-static void library_foreach_controllersObjectLooper(
- bController *UNUSED(controller), ID **id_pointer, void *user_data, int cb_flag)
-{
- LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
- FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
-
- FOREACH_FINALIZE_VOID;
-}
-
-static void library_foreach_actuatorsObjectLooper(
- bActuator *UNUSED(actuator), ID **id_pointer, void *user_data, int cb_flag)
-{
- LibraryForeachIDData *data = (LibraryForeachIDData *) user_data;
- FOREACH_CALLBACK_INVOKE_ID_PP(data, id_pointer, cb_flag);
-
- FOREACH_FINALIZE_VOID;
-}
-
static void library_foreach_nla_strip(LibraryForeachIDData *data, NlaStrip *strip)
{
NlaStrip *substrip;
@@ -368,6 +343,10 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
#define CALLBACK_INVOKE(check_id_super, cb_flag) \
FOREACH_CALLBACK_INVOKE(&data, check_id_super, cb_flag)
+ if (id->override_static != NULL) {
+ CALLBACK_INVOKE_ID(id->override_static->reference, IDWALK_CB_USER | IDWALK_CB_STATIC_OVERRIDE_REFERENCE);
+ }
+
for (; id != NULL; id = (flag & IDWALK_RECURSE) ? BLI_LINKSTACK_POP(data.ids_todo) : NULL) {
data.self_id = id;
data.cb_flag = ID_IS_LINKED(id) ? IDWALK_CB_INDIRECT_USAGE : 0;
@@ -402,8 +381,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
{
Scene *scene = (Scene *) id;
ToolSettings *toolsett = scene->toolsettings;
- SceneRenderLayer *srl;
- Base *base;
CALLBACK_INVOKE(scene->camera, IDWALK_CB_NOP);
CALLBACK_INVOKE(scene->world, IDWALK_CB_USER);
@@ -413,35 +390,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
library_foreach_ID_as_subdata_link((ID **)&scene->nodetree, callback, user_data, flag, &data);
}
- /* DO NOT handle scene->basact here, it's doubling with the loop over whole scene->base later,
- * since basact is just a pointer to one of those items. */
- CALLBACK_INVOKE(scene->obedit, IDWALK_CB_NOP);
-
- for (srl = scene->r.layers.first; srl; srl = srl->next) {
- FreestyleModuleConfig *fmc;
- FreestyleLineSet *fls;
-
- if (srl->mat_override) {
- CALLBACK_INVOKE(srl->mat_override, IDWALK_CB_USER);
- }
- if (srl->light_override) {
- CALLBACK_INVOKE(srl->light_override, IDWALK_CB_USER);
- }
- for (fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
- if (fmc->script) {
- CALLBACK_INVOKE(fmc->script, IDWALK_CB_NOP);
- }
- }
- for (fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
- if (fls->group) {
- CALLBACK_INVOKE(fls->group, IDWALK_CB_USER);
- }
- if (fls->linestyle) {
- CALLBACK_INVOKE(fls->linestyle, IDWALK_CB_USER);
- }
- }
- }
-
if (scene->ed) {
Sequence *seq;
SEQP_BEGIN(scene->ed, seq)
@@ -461,8 +409,35 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
CALLBACK_INVOKE(scene->gpd, IDWALK_CB_USER);
- for (base = scene->base.first; base; base = base->next) {
- CALLBACK_INVOKE(base->object, IDWALK_CB_USER);
+ FOREACH_SCENE_COLLECTION_BEGIN(scene, sc)
+ {
+ for (LinkData *link = sc->objects.first; link; link = link->next) {
+ CALLBACK_INVOKE_ID(link->data, IDWALK_CB_USER);
+ }
+ }
+ FOREACH_SCENE_COLLECTION_END;
+
+ ViewLayer *view_layer;
+ for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ CALLBACK_INVOKE(base->object, IDWALK_NOP);
+ }
+
+ for (FreestyleModuleConfig *fmc = view_layer->freestyle_config.modules.first; fmc; fmc = fmc->next) {
+ if (fmc->script) {
+ CALLBACK_INVOKE(fmc->script, IDWALK_CB_NOP);
+ }
+ }
+
+ for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; fls = fls->next) {
+ if (fls->group) {
+ CALLBACK_INVOKE(fls->group, IDWALK_CB_USER);
+ }
+
+ if (fls->linestyle) {
+ CALLBACK_INVOKE(fls->linestyle, IDWALK_CB_USER);
+ }
+ }
}
for (TimeMarker *marker = scene->markers.first; marker; marker = marker->next) {
@@ -470,8 +445,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
}
if (toolsett) {
- CALLBACK_INVOKE(toolsett->skgen_template, IDWALK_CB_NOP);
-
CALLBACK_INVOKE(toolsett->particle.scene, IDWALK_CB_NOP);
CALLBACK_INVOKE(toolsett->particle.object, IDWALK_CB_NOP);
CALLBACK_INVOKE(toolsett->particle.shape_object, IDWALK_CB_NOP);
@@ -500,8 +473,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
BKE_rigidbody_world_id_loop(scene->rigidbody_world, library_foreach_rigidbodyworldSceneLooper, &data);
}
- CALLBACK_INVOKE(scene->gm.dome.warptext, IDWALK_CB_NOP);
-
break;
}
@@ -599,10 +570,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
CALLBACK_INVOKE(object->soft->effector_weights->group, IDWALK_CB_NOP);
}
}
-
- BKE_sca_sensors_id_loop(&object->sensors, library_foreach_sensorsObjectLooper, &data);
- BKE_sca_controllers_id_loop(&object->controllers, library_foreach_controllersObjectLooper, &data);
- BKE_sca_actuators_id_loop(&object->actuators, library_foreach_actuatorsObjectLooper, &data);
break;
}
@@ -624,31 +591,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
for (i = 0; i < mesh->totcol; i++) {
CALLBACK_INVOKE(mesh->mat[i], IDWALK_CB_USER);
}
-
- /* XXX Really not happy with this - probably texface should rather use some kind of
- * 'texture slots' and just set indices in each poly/face item - would also save some memory.
- * Maybe a nice TODO for blender2.8? */
- if (mesh->mtface || mesh->mtpoly) {
- for (i = 0; i < mesh->pdata.totlayer; i++) {
- if (mesh->pdata.layers[i].type == CD_MTEXPOLY) {
- MTexPoly *txface = (MTexPoly *)mesh->pdata.layers[i].data;
-
- for (int j = 0; j < mesh->totpoly; j++, txface++) {
- CALLBACK_INVOKE(txface->tpage, IDWALK_CB_USER_ONE);
- }
- }
- }
-
- for (i = 0; i < mesh->fdata.totlayer; i++) {
- if (mesh->fdata.layers[i].type == CD_MTFACE) {
- MTFace *tface = (MTFace *)mesh->fdata.layers[i].data;
-
- for (int j = 0; j < mesh->totface; j++, tface++) {
- CALLBACK_INVOKE(tface->tpage, IDWALK_CB_USER_ONE);
- }
- }
- }
- }
break;
}
@@ -681,16 +623,10 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
case ID_MA:
{
Material *material = (Material *) id;
- for (i = 0; i < MAX_MTEX; i++) {
- if (material->mtex[i]) {
- library_foreach_mtex(&data, material->mtex[i]);
- }
- }
if (material->nodetree) {
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
library_foreach_ID_as_subdata_link((ID **)&material->nodetree, callback, user_data, flag, &data);
}
- CALLBACK_INVOKE(material->group, IDWALK_CB_USER);
if (material->texpaintslot != NULL) {
CALLBACK_INVOKE(material->texpaintslot->ima, IDWALK_CB_NOP);
}
@@ -705,16 +641,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
library_foreach_ID_as_subdata_link((ID **)&texture->nodetree, callback, user_data, flag, &data);
}
CALLBACK_INVOKE(texture->ima, IDWALK_CB_USER);
- if (texture->env) {
- CALLBACK_INVOKE(texture->env->object, IDWALK_CB_NOP);
- CALLBACK_INVOKE(texture->env->ima, IDWALK_CB_USER);
- }
- if (texture->pd)
- CALLBACK_INVOKE(texture->pd->object, IDWALK_CB_NOP);
- if (texture->vd)
- CALLBACK_INVOKE(texture->vd->object, IDWALK_CB_NOP);
- if (texture->ot)
- CALLBACK_INVOKE(texture->ot->object, IDWALK_CB_NOP);
break;
}
@@ -728,11 +654,6 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
case ID_LA:
{
Lamp *lamp = (Lamp *) id;
- for (i = 0; i < MAX_MTEX; i++) {
- if (lamp->mtex[i]) {
- library_foreach_mtex(&data, lamp->mtex[i]);
- }
- }
if (lamp->nodetree) {
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
library_foreach_ID_as_subdata_link((ID **)&lamp->nodetree, callback, user_data, flag, &data);
@@ -754,21 +675,9 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
break;
}
- case ID_SCR:
- {
- bScreen *screen = (bScreen *) id;
- CALLBACK_INVOKE(screen->scene, IDWALK_CB_USER_ONE);
- break;
- }
-
case ID_WO:
{
World *world = (World *) id;
- for (i = 0; i < MAX_MTEX; i++) {
- if (world->mtex[i]) {
- library_foreach_mtex(&data, world->mtex[i]);
- }
- }
if (world->nodetree) {
/* nodetree **are owned by IDs**, treat them as mere sub-data and not real ID! */
library_foreach_ID_as_subdata_link((ID **)&world->nodetree, callback, user_data, flag, &data);
@@ -783,13 +692,22 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
break;
}
+ case ID_LP:
+ {
+ LightProbe *probe = (LightProbe *) id;
+ CALLBACK_INVOKE(probe->image, IDWALK_CB_USER);
+ CALLBACK_INVOKE(probe->visibility_grp, IDWALK_CB_NOP);
+ break;
+ }
+
case ID_GR:
{
Group *group = (Group *) id;
- GroupObject *gob;
- for (gob = group->gobject.first; gob; gob = gob->next) {
- CALLBACK_INVOKE(gob->ob, IDWALK_CB_USER_ONE);
+ FOREACH_GROUP_BASE_BEGIN(group, base)
+ {
+ CALLBACK_INVOKE(base->object, IDWALK_CB_USER_ONE);
}
+ FOREACH_GROUP_BASE_END
break;
}
@@ -971,6 +889,40 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
}
break;
}
+
+ case ID_WM:
+ {
+ wmWindowManager *wm = (wmWindowManager *)id;
+
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ ID *workspace = (ID *)BKE_workspace_active_get(win->workspace_hook);
+
+ CALLBACK_INVOKE(win->scene, IDWALK_CB_USER_ONE);
+
+ CALLBACK_INVOKE_ID(workspace, IDWALK_CB_NOP);
+ /* allow callback to set a different workspace */
+ BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace);
+ }
+ break;
+ }
+
+ case ID_WS:
+ {
+ WorkSpace *workspace = (WorkSpace *)id;
+ ListBase *layouts = BKE_workspace_layouts_get(workspace);
+
+ for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) {
+ bScreen *screen = BKE_workspace_layout_screen_get(layout);
+
+ /* CALLBACK_INVOKE expects an actual pointer, not a variable holding the pointer.
+ * However we can't acess layout->screen here since we are outside the workspace project. */
+ CALLBACK_INVOKE(screen, IDWALK_CB_NOP);
+ /* allow callback to set a different screen */
+ BKE_workspace_layout_screen_set(layout, screen);
+ }
+
+ break;
+ }
case ID_GD:
{
bGPdata *gpencil = (bGPdata *) id;
@@ -982,11 +934,11 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
}
/* Nothing needed for those... */
+ case ID_SCR:
case ID_IM:
case ID_VF:
case ID_TXT:
case ID_SO:
- case ID_WM:
case ID_PAL:
case ID_PC:
case ID_CF:
@@ -1067,7 +1019,7 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
#if 0
return ELEM(id_type_used, ID_ME, ID_CU, ID_MB, ID_LT, ID_SPK, ID_AR, ID_LA, ID_CA, /* obdata */
ID_OB, ID_MA, ID_GD, ID_GR, ID_TE, ID_PA, ID_TXT, ID_SO, ID_MC, ID_IM, ID_AC
- /* + constraints, modifiers and game logic ID types... */);
+ /* + constraints and modifiers ... */);
#else
return true;
#endif
@@ -1114,6 +1066,9 @@ bool BKE_library_id_can_use_idtype(ID *id_owner, const short id_type_used)
return ELEM(id_type_used, ID_MC); /* WARNING! mask->parent.id, not typed. */
case ID_LS:
return (ELEM(id_type_used, ID_TE, ID_OB));
+ case ID_LP:
+ return ELEM(id_type_used, ID_IM);
+ case ID_WS:
case ID_IM:
case ID_VF:
case ID_TXT:
diff --git a/source/blender/blenkernel/intern/library_remap.c b/source/blender/blenkernel/intern/library_remap.c
index 31dc46a55f0..f6e03fec380 100644
--- a/source/blender/blenkernel/intern/library_remap.c
+++ b/source/blender/blenkernel/intern/library_remap.c
@@ -53,6 +53,7 @@
#include "DNA_mask_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_speaker_types.h"
@@ -60,6 +61,7 @@
#include "DNA_text_types.h"
#include "DNA_vfont_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_world_types.h"
#include "BLI_blenlib.h"
@@ -71,8 +73,8 @@
#include "BKE_brush.h"
#include "BKE_camera.h"
#include "BKE_cachefile.h"
+#include "BKE_collection.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_font.h"
#include "BKE_group.h"
@@ -83,7 +85,9 @@
#include "BKE_key.h"
#include "BKE_lamp.h"
#include "BKE_lattice.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
+#include "BKE_library_override.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
#include "BKE_linestyle.h"
@@ -99,15 +103,19 @@
#include "BKE_object.h"
#include "BKE_paint.h"
#include "BKE_particle.h"
-#include "BKE_sca.h"
+#include "BKE_lightprobe.h"
#include "BKE_speaker.h"
#include "BKE_sound.h"
#include "BKE_screen.h"
#include "BKE_scene.h"
#include "BKE_text.h"
#include "BKE_texture.h"
+#include "BKE_workspace.h"
#include "BKE_world.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#ifdef WITH_PYTHON
#include "BPY_extern.h"
#endif
@@ -173,6 +181,7 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
}
if (*id_p && (*id_p == old_id)) {
+ const bool is_reference = (cb_flag & IDWALK_CB_STATIC_OVERRIDE_REFERENCE) != 0;
const bool is_indirect = (cb_flag & IDWALK_CB_INDIRECT_USAGE) != 0;
const bool skip_indirect = (id_remap_data->flag & ID_REMAP_SKIP_INDIRECT_USAGE) != 0;
/* Note: proxy usage implies LIB_TAG_EXTERN, so on this aspect it is direct,
@@ -183,6 +192,7 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
const bool is_obj_editmode = (is_obj && BKE_object_is_in_editmode((Object *)id));
const bool is_never_null = ((cb_flag & IDWALK_CB_NEVER_NULL) && (new_id == NULL) &&
(id_remap_data->flag & ID_REMAP_FORCE_NEVER_NULL_USAGE) == 0);
+ const bool skip_reference = (id_remap_data->flag & ID_REMAP_SKIP_STATIC_OVERRIDE) != 0;
const bool skip_never_null = (id_remap_data->flag & ID_REMAP_SKIP_NEVER_NULL_USAGE) != 0;
#ifdef DEBUG_PRINT
@@ -199,7 +209,8 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
* (skipped_indirect too). */
if ((is_never_null && skip_never_null) ||
(is_obj_editmode && (((Object *)id)->data == *id_p) && new_id != NULL) ||
- (skip_indirect && is_indirect))
+ (skip_indirect && is_indirect) ||
+ (is_reference && skip_reference))
{
if (is_indirect) {
id_remap_data->skipped_indirect++;
@@ -212,7 +223,7 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
}
}
}
- else if (is_never_null || is_obj_editmode) {
+ else if (is_never_null || is_obj_editmode || is_reference) {
id_remap_data->skipped_direct++;
}
else {
@@ -229,7 +240,7 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
else {
if (!is_never_null) {
*id_p = new_id;
- DAG_id_tag_update_ex(id_remap_data->bmain, id_self, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update_ex(id_remap_data->bmain, id_self, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
}
if (cb_flag & IDWALK_CB_USER) {
id_us_min(old_id);
@@ -252,23 +263,41 @@ static int foreach_libblock_remap_callback(void *user_data, ID *id_self, ID **id
}
/* Some remapping unfortunately require extra and/or specific handling, tackle those here. */
-static void libblock_remap_data_preprocess_scene_base_unlink(
- IDRemap *r_id_remap_data, Scene *sce, Base *base, const bool skip_indirect, const bool is_indirect)
+static void libblock_remap_data_preprocess_scene_object_unlink(
+ IDRemap *r_id_remap_data, Scene *sce, Object *ob, const bool skip_indirect, const bool is_indirect)
{
if (skip_indirect && is_indirect) {
r_id_remap_data->skipped_indirect++;
r_id_remap_data->skipped_refcounted++;
}
else {
- id_us_min((ID *)base->object);
- BKE_scene_base_unlink(sce, base);
- MEM_freeN(base);
+ BKE_collections_object_remove(r_id_remap_data->bmain, &sce->id, ob, false);
if (!is_indirect) {
r_id_remap_data->status |= ID_REMAP_IS_LINKED_DIRECT;
}
}
}
+static void libblock_remap_data_preprocess_group_unlink(
+ IDRemap *r_id_remap_data, Object *ob, const bool skip_indirect, const bool is_indirect)
+{
+ Main *bmain = r_id_remap_data->bmain;
+ for (Group *group = bmain->group.first; group; group = group->id.next) {
+ if (BKE_group_object_exists(group, ob)) {
+ if (skip_indirect && is_indirect) {
+ r_id_remap_data->skipped_indirect++;
+ r_id_remap_data->skipped_refcounted++;
+ }
+ else {
+ BKE_collections_object_remove(bmain, &group->id, ob, false);
+ if (!is_indirect) {
+ r_id_remap_data->status |= ID_REMAP_IS_LINKED_DIRECT;
+ }
+ }
+ }
+ }
+}
+
static void libblock_remap_data_preprocess(IDRemap *r_id_remap_data)
{
switch (GS(r_id_remap_data->id->name)) {
@@ -283,23 +312,24 @@ static void libblock_remap_data_preprocess(IDRemap *r_id_remap_data)
/* In case we are unlinking... */
if (!r_id_remap_data->old_id) {
/* ... everything from scene. */
- Base *base, *base_next;
- for (base = sce->base.first; base; base = base_next) {
- base_next = base->next;
- libblock_remap_data_preprocess_scene_base_unlink(
- r_id_remap_data, sce, base, skip_indirect, is_indirect);
+ FOREACH_SCENE_OBJECT_BEGIN(sce, ob_iter)
+ {
+ libblock_remap_data_preprocess_scene_object_unlink(
+ r_id_remap_data, sce, ob_iter, skip_indirect, is_indirect);
+ libblock_remap_data_preprocess_group_unlink(
+ r_id_remap_data, ob_iter, skip_indirect, is_indirect);
}
+ FOREACH_SCENE_OBJECT_END;
}
else if (GS(r_id_remap_data->old_id->name) == ID_OB) {
/* ... a specific object from scene. */
Object *old_ob = (Object *)r_id_remap_data->old_id;
- Base *base = BKE_scene_base_find(sce, old_ob);
-
- if (base) {
- libblock_remap_data_preprocess_scene_base_unlink(
- r_id_remap_data, sce, base, skip_indirect, is_indirect);
- }
+ libblock_remap_data_preprocess_scene_object_unlink(
+ r_id_remap_data, sce, old_ob, skip_indirect, is_indirect);
+ libblock_remap_data_preprocess_group_unlink(
+ r_id_remap_data, old_ob, skip_indirect, is_indirect);
}
+
}
break;
}
@@ -340,7 +370,7 @@ static void libblock_remap_data_postprocess_object_update(Main *bmain, Object *o
}
if (new_ob == NULL) { /* We need to remove NULL-ified groupobjects... */
for (Group *group = bmain->group.first; group; group = group->id.next) {
- BKE_group_object_unlink(group, NULL, NULL, NULL);
+ BKE_group_object_unlink(group, NULL);
}
}
else {
@@ -350,7 +380,7 @@ static void libblock_remap_data_postprocess_object_update(Main *bmain, Object *o
if (old_ob->type == OB_MBALL) {
for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
if (ob->type == OB_MBALL && BKE_mball_is_basis_for(ob, old_ob)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
}
@@ -360,26 +390,21 @@ static void libblock_remap_data_postprocess_group_scene_unlink(Main *UNUSED(bmai
{
/* Note that here we assume no object has no base (i.e. all objects are assumed instanced
* in one scene...). */
- for (Base *base = sce->base.first; base; base = base->next) {
- if (base->flag & OB_FROMGROUP) {
- Object *ob = base->object;
-
- if (ob->flag & OB_FROMGROUP) {
- Group *grp = BKE_group_object_find(NULL, ob);
-
- /* Unlinked group (old_id) is still in bmain... */
- if (grp && (&grp->id == old_id || grp->id.us == 0)) {
- grp = BKE_group_object_find(grp, ob);
- }
- if (!grp) {
- ob->flag &= ~OB_FROMGROUP;
- }
+ FOREACH_SCENE_OBJECT_BEGIN(sce, ob)
+ {
+ if (ob->flag & OB_FROMGROUP) {
+ Group *grp = BKE_group_object_find(NULL, ob);
+
+ /* Unlinked group (old_id) is still in bmain... */
+ if (grp && (&grp->id == old_id || grp->id.us == 0)) {
+ grp = BKE_group_object_find(grp, ob);
}
- if (!(ob->flag & OB_FROMGROUP)) {
- base->flag &= ~OB_FROMGROUP;
+ if (!grp) {
+ ob->flag &= ~OB_FROMGROUP;
}
}
}
+ FOREACH_SCENE_OBJECT_END;
}
static void libblock_remap_data_postprocess_obdata_relink(Main *UNUSED(bmain), Object *ob, ID *new_id)
@@ -480,10 +505,6 @@ ATTR_NONNULL(1) static void libblock_remap_data(
}
}
- if (old_id && GS(old_id->name) == ID_OB) {
- BKE_sca_logic_links_remap(bmain, (Object *)old_id, (Object *)new_id);
- }
-
/* XXX We may not want to always 'transfer' fakeuser from old to new id... Think for now it's desired behavior
* though, we can always add an option (flag) to control this later if needed. */
if (old_id && (old_id->flag & LIB_FAKEUSER)) {
@@ -594,8 +615,8 @@ void BKE_libblock_remap_locked(
libblock_remap_data_postprocess_nodetree_update(bmain, new_id);
BKE_main_lock(bmain);
- /* Full rebuild of DAG! */
- DAG_relations_tag_update(bmain);
+ /* Full rebuild of DEG! */
+ DEG_relations_tag_update(bmain);
}
void BKE_libblock_remap(Main *bmain, void *old_idv, void *new_idv, const short remap_flags)
@@ -747,6 +768,10 @@ void BKE_libblock_free_data(ID *id, const bool do_id_user)
MEM_freeN(id->properties);
}
+ if (id->override_static) {
+ BKE_override_static_free(&id->override_static);
+ }
+
/* XXX TODO remove animdata handling from each type's freeing func, and do it here, like for copy! */
}
@@ -811,6 +836,9 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
case ID_SPK:
BKE_speaker_free((Speaker *)id);
break;
+ case ID_LP:
+ BKE_lightprobe_free((LightProbe *)id);
+ break;
case ID_SO:
BKE_sound_free((bSound *)id);
break;
@@ -857,6 +885,9 @@ void BKE_libblock_free_datablock(ID *id, const int UNUSED(flag))
case ID_CF:
BKE_cachefile_free((CacheFile *)id);
break;
+ case ID_WS:
+ BKE_workspace_free((WorkSpace *)id);
+ break;
}
}
@@ -895,7 +926,7 @@ void BKE_id_free_ex(Main *bmain, void *idv, int flag, const bool use_flag_from_i
const short type = GS(id->name);
if (bmain && (flag & LIB_ID_FREE_NO_DEG_TAG) == 0) {
- DAG_id_type_tag(bmain, type);
+ DEG_id_type_tag(bmain, type);
}
#ifdef WITH_PYTHON
@@ -958,7 +989,7 @@ void BKE_libblock_free_ex(Main *bmain, void *idv, const bool do_id_user, const b
short type = GS(id->name);
ListBase *lb = which_libbase(bmain, type);
- DAG_id_type_tag(bmain, type);
+ DEG_id_type_tag(bmain, type);
#ifdef WITH_PYTHON
#ifdef WITH_PYTHON_SAFETY
diff --git a/source/blender/blenkernel/intern/lightprobe.c b/source/blender/blenkernel/intern/lightprobe.c
new file mode 100644
index 00000000000..057b6aaaf65
--- /dev/null
+++ b/source/blender/blenkernel/intern/lightprobe.c
@@ -0,0 +1,101 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/lightprobe.c
+ * \ingroup bke
+ */
+
+#include "DNA_object_types.h"
+#include "DNA_lightprobe_types.h"
+
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_animsys.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_lightprobe.h"
+
+void BKE_lightprobe_init(LightProbe *probe)
+{
+ BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(probe, id));
+
+ probe->grid_resolution_x = probe->grid_resolution_y = probe->grid_resolution_z = 4;
+ probe->distinf = 2.5f;
+ probe->distpar = 2.5f;
+ probe->falloff = 0.2f;
+ probe->clipsta = 0.8f;
+ probe->clipend = 40.0f;
+ probe->vis_bias = 1.0f;
+ probe->vis_blur = 0.2f;
+ probe->intensity = 1.0f;
+ probe->data_draw_size = 1.0f;
+
+ probe->flag = LIGHTPROBE_FLAG_SHOW_INFLUENCE | LIGHTPROBE_FLAG_SHOW_DATA;
+}
+
+void *BKE_lightprobe_add(Main *bmain, const char *name)
+{
+ LightProbe *probe;
+
+ probe = BKE_libblock_alloc(bmain, ID_LP, name, 0);
+
+ BKE_lightprobe_init(probe);
+
+ return probe;
+}
+
+/**
+ * Only copy internal data of LightProbe ID from source to already allocated/initialized destination.
+ * You probably nerver want to use that directly, use id_copy or BKE_id_copy_ex for typical needs.
+ *
+ * WARNING! This function will not handle ID user count!
+ *
+ * \param flag Copying options (see BKE_library.h's LIB_ID_COPY_... flags for more).
+ */
+void BKE_lightprobe_copy_data(
+ Main *UNUSED(bmain), LightProbe *UNUSED(probe_dst), const LightProbe *UNUSED(probe_src), const int UNUSED(flag))
+{
+ /* Nothing to do here. */
+}
+
+LightProbe *BKE_lightprobe_copy(Main *bmain, const LightProbe *probe)
+{
+ LightProbe *probe_copy;
+ BKE_id_copy_ex(bmain, &probe->id, (ID **)&probe_copy, 0, false);
+ return probe_copy;
+}
+
+void BKE_lightprobe_make_local(Main *bmain, LightProbe *probe, const bool lib_local)
+{
+ BKE_id_make_local_generic(bmain, &probe->id, true, lib_local);
+}
+
+void BKE_lightprobe_free(LightProbe *probe)
+{
+ BKE_animdata_free((ID *)probe, false);
+}
diff --git a/source/blender/blenkernel/intern/linestyle.c b/source/blender/blenkernel/intern/linestyle.c
index e00884c8a9d..5757ae7480b 100644
--- a/source/blender/blenkernel/intern/linestyle.c
+++ b/source/blender/blenkernel/intern/linestyle.c
@@ -212,20 +212,11 @@ void BKE_linestyle_make_local(struct Main *bmain, FreestyleLineStyle *linestyle,
BKE_id_make_local_generic(bmain, &linestyle->id, true, lib_local);
}
-FreestyleLineStyle *BKE_linestyle_active_from_scene(Scene *scene)
+FreestyleLineStyle *BKE_linestyle_active_from_view_layer(ViewLayer *view_layer)
{
- SceneRenderLayer *actsrl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- if (!actsrl) {
- return NULL;
- }
-
- FreestyleConfig *config = &actsrl->freestyleConfig;
+ FreestyleConfig *config = &view_layer->freestyle_config;
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
-
- if (lineset) {
- return lineset->linestyle;
- }
- return NULL;
+ return (lineset) ? lineset->linestyle : NULL;
}
static LineStyleModifier *new_modifier(const char *name, int type, size_t size)
diff --git a/source/blender/blenkernel/intern/mask.c b/source/blender/blenkernel/intern/mask.c
index b5742dbdbb7..ba5a6a25048 100644
--- a/source/blender/blenkernel/intern/mask.c
+++ b/source/blender/blenkernel/intern/mask.c
@@ -51,7 +51,7 @@
#include "BKE_animsys.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
+
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_mask.h"
@@ -61,6 +61,8 @@
#include "BKE_movieclip.h"
#include "BKE_image.h"
+#include "DEG_depsgraph_build.h"
+
static struct {
ListBase splines;
struct GHash *id_hash;
@@ -817,7 +819,7 @@ Mask *BKE_mask_new(Main *bmain, const char *name)
mask->sfra = 1;
mask->efra = 100;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
return mask;
}
@@ -1457,18 +1459,6 @@ void BKE_mask_evaluate_all_masks(Main *bmain, float ctime, const bool do_newfram
}
}
-void BKE_mask_update_scene(Main *bmain, Scene *scene)
-{
- Mask *mask;
-
- for (mask = bmain->mask.first; mask; mask = mask->id.next) {
- if (mask->id.recalc & ID_RECALC_ALL) {
- bool do_new_frame = (mask->id.recalc & ID_RECALC_DATA) != 0;
- BKE_mask_evaluate_all_masks(bmain, CFRA, do_new_frame);
- }
- }
-}
-
void BKE_mask_parent_init(MaskParent *parent)
{
parent->id_type = ID_MC;
diff --git a/source/blender/blenkernel/intern/mask_evaluate.c b/source/blender/blenkernel/intern/mask_evaluate.c
index e2a9691e577..55939f8eadf 100644
--- a/source/blender/blenkernel/intern/mask_evaluate.c
+++ b/source/blender/blenkernel/intern/mask_evaluate.c
@@ -40,12 +40,13 @@
#include "BLI_math.h"
#include "DNA_mask_types.h"
+#include "DNA_object_types.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_mask.h"
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
unsigned int BKE_mask_spline_resolution(MaskSpline *spline, int width, int height)
{
@@ -897,24 +898,26 @@ void BKE_mask_layer_evaluate_deform(MaskLayer *masklay, const float ctime)
}
}
-void BKE_mask_eval_animation(struct EvaluationContext *eval_ctx, Mask *mask)
+void BKE_mask_eval_animation(struct Depsgraph *depsgraph, Mask *mask)
{
- DEG_debug_print_eval(__func__, mask->id.name, mask);
+ float ctime = DEG_get_ctime(depsgraph);
+ DEG_debug_print_eval(depsgraph, __func__, mask->id.name, mask);
for (MaskLayer *mask_layer = mask->masklayers.first;
mask_layer != NULL;
mask_layer = mask_layer->next)
{
- BKE_mask_layer_evaluate_animation(mask_layer, eval_ctx->ctime);
+ BKE_mask_layer_evaluate_animation(mask_layer, ctime);
}
}
-void BKE_mask_eval_update(struct EvaluationContext *eval_ctx, Mask *mask)
+void BKE_mask_eval_update(struct Depsgraph *depsgraph, Mask *mask)
{
- DEG_debug_print_eval(__func__, mask->id.name, mask);
+ float ctime = DEG_get_ctime(depsgraph);
+ DEG_debug_print_eval(depsgraph, __func__, mask->id.name, mask);
for (MaskLayer *mask_layer = mask->masklayers.first;
mask_layer != NULL;
mask_layer = mask_layer->next)
{
- BKE_mask_layer_evaluate_deform(mask_layer, eval_ctx->ctime);
+ BKE_mask_layer_evaluate_deform(mask_layer, ctime);
}
}
diff --git a/source/blender/blenkernel/intern/material.c b/source/blender/blenkernel/intern/material.c
index 01f16625386..131d79c249f 100644
--- a/source/blender/blenkernel/intern/material.c
+++ b/source/blender/blenkernel/intern/material.c
@@ -58,7 +58,6 @@
#include "BKE_animsys.h"
#include "BKE_displist.h"
#include "BKE_global.h"
-#include "BKE_depsgraph.h"
#include "BKE_icons.h"
#include "BKE_image.h"
#include "BKE_library.h"
@@ -73,6 +72,9 @@
#include "BKE_editmesh.h"
#include "BKE_font.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "GPU_material.h"
/* used in UI and render */
@@ -87,16 +89,10 @@ void init_def_material(void)
/** Free (or release) any data used by this material (does not free the material itself). */
void BKE_material_free(Material *ma)
{
- int a;
-
BKE_animdata_free((ID *)ma, false);
- for (a = 0; a < MAX_MTEX; a++) {
- MEM_SAFE_FREE(ma->mtex[a]);
- }
-
- MEM_SAFE_FREE(ma->ramp_col);
- MEM_SAFE_FREE(ma->ramp_spec);
+ /* Free gpu material before the ntree */
+ GPU_material_free(&ma->gpumaterial);
/* is no lib link block, but material extension */
if (ma->nodetree) {
@@ -107,8 +103,6 @@ void BKE_material_free(Material *ma)
MEM_SAFE_FREE(ma->texpaintslot);
- GPU_material_free(&ma->gpumaterial);
-
BKE_icon_id_delete((ID *)ma);
BKE_previewimg_free(&ma->preview);
}
@@ -117,95 +111,19 @@ void BKE_material_init(Material *ma)
{
BLI_assert(MEMCMP_STRUCT_OFS_IS_ZERO(ma, id));
- ma->r = ma->g = ma->b = ma->ref = 0.8;
+ ma->r = ma->g = ma->b = 0.8;
ma->specr = ma->specg = ma->specb = 1.0;
- ma->mirr = ma->mirg = ma->mirb = 1.0;
- ma->spectra = 1.0;
- ma->amb = 1.0;
ma->alpha = 1.0;
- ma->spec = ma->hasize = 0.5;
- ma->har = 50;
- ma->starc = ma->ringc = 4;
- ma->linec = 12;
- ma->flarec = 1;
- ma->flaresize = ma->subsize = 1.0;
- ma->flareboost = 1;
- ma->seed2 = 6;
- ma->friction = 0.5;
- ma->refrac = 4.0;
- ma->roughness = 0.5;
- ma->param[0] = 0.5;
- ma->param[1] = 0.1;
- ma->param[2] = 0.5;
- ma->param[3] = 0.1;
- ma->rms = 0.1;
- ma->darkness = 1.0;
-
- ma->strand_sta = ma->strand_end = 1.0f;
-
- ma->ang = 1.0;
- ma->ray_depth = 2;
- ma->ray_depth_tra = 2;
- ma->fresnel_mir = 0.0;
- ma->fresnel_tra = 0.0;
- ma->fresnel_tra_i = 1.25;
- ma->fresnel_mir_i = 1.25;
- ma->tx_limit = 0.0;
- ma->tx_falloff = 1.0;
- ma->shad_alpha = 1.0f;
- ma->vcol_alpha = 0;
-
- ma->gloss_mir = ma->gloss_tra = 1.0;
- ma->samp_gloss_mir = ma->samp_gloss_tra = 18;
- ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005;
- ma->dist_mir = 0.0;
- ma->fadeto_mir = MA_RAYMIR_FADETOSKY;
+ ma->spec = 0.5;
+
+ ma->gloss_mir = 1.0;
- ma->rampfac_col = 1.0;
- ma->rampfac_spec = 1.0;
ma->pr_lamp = 3; /* two lamps, is bits */
ma->pr_type = MA_SPHERE;
- ma->sss_radius[0] = 1.0f;
- ma->sss_radius[1] = 1.0f;
- ma->sss_radius[2] = 1.0f;
- ma->sss_col[0] = 1.0f;
- ma->sss_col[1] = 1.0f;
- ma->sss_col[2] = 1.0f;
- ma->sss_error = 0.05f;
- ma->sss_scale = 0.1f;
- ma->sss_ior = 1.3f;
- ma->sss_colfac = 1.0f;
- ma->sss_texfac = 0.0f;
- ma->sss_front = 1.0f;
- ma->sss_back = 1.0f;
-
- ma->vol.density = 1.0f;
- ma->vol.emission = 0.0f;
- ma->vol.scattering = 1.0f;
- ma->vol.reflection = 1.0f;
- ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f;
- ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f;
- ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
- ma->vol.density_scale = 1.0f;
- ma->vol.depth_cutoff = 0.01f;
- ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
- ma->vol.stepsize = 0.2f;
- ma->vol.shade_type = MA_VOL_SHADE_SHADED;
- ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
- ma->vol.precache_resolution = 50;
- ma->vol.ms_spread = 0.2f;
- ma->vol.ms_diff = 1.f;
- ma->vol.ms_intensity = 1.f;
-
- ma->game.flag = GEMAT_BACKCULL;
- ma->game.alpha_blend = 0;
- ma->game.face_orientation = 0;
-
- ma->mode = MA_TRACEBLE | MA_SHADBUF | MA_SHADOW | MA_RAYBIAS | MA_TANGENT_STR | MA_ZTRANSP;
- ma->mode2 = MA_CASTSHADOW;
- ma->shade_flag = MA_APPROX_OCCLUSION;
ma->preview = NULL;
+
+ ma->alpha_threshold = 0.5f;
}
Material *BKE_material_add(Main *bmain, const char *name)
@@ -229,20 +147,6 @@ Material *BKE_material_add(Main *bmain, const char *name)
*/
void BKE_material_copy_data(Main *bmain, Material *ma_dst, const Material *ma_src, const int flag)
{
- for (int a = 0; a < MAX_MTEX; a++) {
- if (ma_src->mtex[a]) {
- ma_dst->mtex[a] = MEM_mallocN(sizeof(*ma_dst->mtex[a]), __func__);
- *ma_dst->mtex[a] = *ma_src->mtex[a];
- }
- }
-
- if (ma_src->ramp_col) {
- ma_dst->ramp_col = MEM_dupallocN(ma_src->ramp_col);
- }
- if (ma_src->ramp_spec) {
- ma_dst->ramp_spec = MEM_dupallocN(ma_src->ramp_spec);
- }
-
if (ma_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */
@@ -261,6 +165,8 @@ void BKE_material_copy_data(Main *bmain, Material *ma_dst, const Material *ma_sr
}
BLI_listbase_clear(&ma_dst->gpumaterial);
+
+ /* TODO Duplicate Engine Settings and set runtime to NULL */
}
Material *BKE_material_copy(Main *bmain, const Material *ma)
@@ -281,29 +187,24 @@ Material *BKE_material_localize(Material *ma)
* ... Once f*** nodes are fully converted to that too :( */
Material *man;
- int a;
-
- man = BKE_libblock_copy_nolib(&ma->id, false);
- /* no increment for texture ID users, in previewrender.c it prevents decrement */
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) {
- man->mtex[a] = MEM_mallocN(sizeof(MTex), "copymaterial");
- memcpy(man->mtex[a], ma->mtex[a], sizeof(MTex));
- }
- }
-
- if (ma->ramp_col) man->ramp_col = MEM_dupallocN(ma->ramp_col);
- if (ma->ramp_spec) man->ramp_spec = MEM_dupallocN(ma->ramp_spec);
+ BKE_id_copy_ex(
+ NULL, &ma->id, (ID **)&man,
+ (LIB_ID_CREATE_NO_MAIN |
+ LIB_ID_CREATE_NO_USER_REFCOUNT |
+ LIB_ID_COPY_NO_PREVIEW |
+ LIB_ID_COPY_NO_ANIMDATA),
+ false);
man->texpaintslot = NULL;
man->preview = NULL;
-
- if (ma->nodetree)
- man->nodetree = ntreeLocalize(ma->nodetree);
-
+
BLI_listbase_clear(&man->gpumaterial);
-
+
+ /* TODO Duplicate Engine Settings and set runtime to NULL */
+
+ man->id.tag |= LIB_TAG_LOCALIZED;
+
return man;
}
@@ -458,7 +359,7 @@ void BKE_material_resize_id(Main *bmain, ID *id, short totcol, bool do_id_user)
}
*totcolp = totcol;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
void BKE_material_append_id(Main *bmain, ID *id, Material *ma)
@@ -475,7 +376,7 @@ void BKE_material_append_id(Main *bmain, ID *id, Material *ma)
id_us_plus((ID *)ma);
test_all_objects_materials(bmain, id);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
}
@@ -509,7 +410,7 @@ Material *BKE_material_pop_id(Main *bmain, ID *id, int index_i, bool update_data
material_data_index_remove_id(id, index);
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
}
@@ -536,7 +437,7 @@ void BKE_material_clear_id(Main *bmain, ID *id, bool update_data)
material_data_index_clear_id(id);
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
}
@@ -631,7 +532,7 @@ void BKE_material_resize_object(Main *bmain, Object *ob, const short totcol, boo
if (ob->totcol && ob->actcol == 0) ob->actcol = 1;
if (ob->actcol > ob->totcol) ob->actcol = ob->totcol;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
void test_object_materials(Object *ob, ID *id)
@@ -936,278 +837,8 @@ bool BKE_object_material_slot_add(Object *ob)
return true;
}
-static void do_init_render_material(Material *ma, int r_mode, float *amb)
-{
- MTex *mtex;
- int a, needuv = 0, needtang = 0;
-
- if (ma->flarec == 0) ma->flarec = 1;
-
- /* add all texcoflags from mtex, texco and mapto were cleared in advance */
- for (a = 0; a < MAX_MTEX; a++) {
-
- /* separate tex switching */
- if (ma->septex & (1 << a)) continue;
-
- mtex = ma->mtex[a];
- if (mtex && mtex->tex && (mtex->tex->type | (mtex->tex->use_nodes && mtex->tex->nodetree) )) {
-
- ma->texco |= mtex->texco;
- ma->mapto |= mtex->mapto;
-
- /* always get derivatives for these textures */
- if (ELEM(mtex->tex->type, TEX_IMAGE, TEX_ENVMAP)) ma->texco |= TEXCO_OSA;
- else if (mtex->texflag & (MTEX_COMPAT_BUMP | MTEX_3TAP_BUMP | MTEX_5TAP_BUMP | MTEX_BICUBIC_BUMP)) ma->texco |= TEXCO_OSA;
-
- if (ma->texco & (TEXCO_ORCO | TEXCO_REFL | TEXCO_NORM | TEXCO_STRAND | TEXCO_STRESS)) needuv = 1;
- else if (ma->texco & (TEXCO_GLOB | TEXCO_UV | TEXCO_OBJECT | TEXCO_SPEED)) needuv = 1;
- else if (ma->texco & (TEXCO_LAVECTOR | TEXCO_VIEW)) needuv = 1;
-
- if ((ma->mapto & MAP_NORM) && (mtex->normapspace == MTEX_NSPACE_TANGENT))
- needtang = 1;
- }
- }
-
- if (needtang) ma->mode |= MA_NORMAP_TANG;
- else ma->mode &= ~MA_NORMAP_TANG;
-
- if (ma->mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) {
- needuv = 1;
- if (r_mode & R_OSA) ma->texco |= TEXCO_OSA; /* for texfaces */
- }
- if (needuv) ma->texco |= NEED_UV;
-
- /* since the raytracer doesnt recalc O structs for each ray, we have to preset them all */
- if (r_mode & R_RAYTRACE) {
- if ((ma->mode & (MA_RAYMIRROR | MA_SHADOW_TRA)) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_RAYTRANSP))) {
- ma->texco |= NEED_UV | TEXCO_ORCO | TEXCO_REFL | TEXCO_NORM;
- if (r_mode & R_OSA) ma->texco |= TEXCO_OSA;
- }
- }
-
- if (amb) {
- ma->ambr = ma->amb * amb[0];
- ma->ambg = ma->amb * amb[1];
- ma->ambb = ma->amb * amb[2];
- }
-
- /* local group override */
- if ((ma->shade_flag & MA_GROUP_LOCAL) && ma->id.lib && ma->group && ma->group->id.lib) {
- Group *group;
-
- for (group = G.main->group.first; group; group = group->id.next) {
- if (!ID_IS_LINKED(group) && STREQ(group->id.name, ma->group->id.name)) {
- ma->group = group;
- }
- }
- }
-}
-
-static void init_render_nodetree(bNodeTree *ntree, Material *basemat, int r_mode, float *amb)
-{
- bNode *node;
-
- /* parses the geom+tex nodes */
- ntreeShaderGetTexcoMode(ntree, r_mode, &basemat->texco, &basemat->mode_l);
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->id) {
- if (GS(node->id->name) == ID_MA) {
- Material *ma = (Material *)node->id;
- if (ma != basemat) {
- do_init_render_material(ma, r_mode, amb);
- basemat->texco |= ma->texco;
- }
-
- basemat->mode_l |= ma->mode & ~(MA_MODE_PIPELINE | MA_SHLESS);
- basemat->mode2_l |= ma->mode2 & ~MA_MODE2_PIPELINE;
- /* basemat only considered shadeless if all node materials are too */
- if (!(ma->mode & MA_SHLESS))
- basemat->mode_l &= ~MA_SHLESS;
-
- if (ma->strand_surfnor > 0.0f)
- basemat->mode_l |= MA_STR_SURFDIFF;
- }
- else if (node->type == NODE_GROUP)
- init_render_nodetree((bNodeTree *)node->id, basemat, r_mode, amb);
- }
- else if (node->typeinfo->type == SH_NODE_NORMAL_MAP) {
- basemat->mode2_l |= MA_TANGENT_CONCRETE;
- NodeShaderNormalMap *nm = node->storage;
- bool taken_into_account = false;
- for (int i = 0; i < basemat->nmap_tangent_names_count; i++) {
- if (STREQ(basemat->nmap_tangent_names[i], nm->uv_map)) {
- taken_into_account = true;
- break;
- }
- }
- if (!taken_into_account) {
- BLI_assert(basemat->nmap_tangent_names_count < MAX_MTFACE + 1);
- strcpy(basemat->nmap_tangent_names[basemat->nmap_tangent_names_count++], nm->uv_map);
- }
- }
- }
-}
-
-void init_render_material(Material *mat, int r_mode, float *amb)
-{
-
- do_init_render_material(mat, r_mode, amb);
-
- if (mat->nodetree && mat->use_nodes) {
- /* mode_l will take the pipeline options from the main material, and the or-ed
- * result of non-pipeline options from the nodes. shadeless is an exception,
- * mode_l will have it set when all node materials are shadeless. */
- mat->mode_l = (mat->mode & MA_MODE_PIPELINE) | MA_SHLESS;
- mat->mode2_l = mat->mode2 & MA_MODE2_PIPELINE;
- mat->nmap_tangent_names_count = 0;
- init_render_nodetree(mat->nodetree, mat, r_mode, amb);
-
- if (!mat->nodetree->execdata)
- mat->nodetree->execdata = ntreeShaderBeginExecTree(mat->nodetree);
- }
- else {
- mat->mode_l = mat->mode;
- mat->mode2_l = mat->mode2;
-
- if (mat->strand_surfnor > 0.0f)
- mat->mode_l |= MA_STR_SURFDIFF;
- }
-}
-
-void init_render_materials(Main *bmain, int r_mode, float *amb, bool do_default_material)
-{
- Material *ma;
-
- /* clear these flags before going over materials, to make sure they
- * are cleared only once, otherwise node materials contained in other
- * node materials can go wrong */
- for (ma = bmain->mat.first; ma; ma = ma->id.next) {
- if (ma->id.us) {
- ma->texco = 0;
- ma->mapto = 0;
- }
- }
-
- /* two steps, first initialize, then or the flags for layers */
- for (ma = bmain->mat.first; ma; ma = ma->id.next) {
- /* is_used flag comes back in convertblender.c */
- ma->flag &= ~MA_IS_USED;
- if (ma->id.us)
- init_render_material(ma, r_mode, amb);
- }
-
- if (do_default_material) {
- init_render_material(&defmaterial, r_mode, amb);
- }
-}
-
-/* only needed for nodes now */
-void end_render_material(Material *mat)
-{
- if (mat && mat->nodetree && mat->use_nodes) {
- if (mat->nodetree->execdata)
- ntreeShaderEndExecTree(mat->nodetree->execdata);
- }
-}
-
-void end_render_materials(Main *bmain)
-{
- Material *ma;
- for (ma = bmain->mat.first; ma; ma = ma->id.next)
- if (ma->id.us)
- end_render_material(ma);
-}
-
-static bool material_in_nodetree(bNodeTree *ntree, Material *mat)
-{
- bNode *node;
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->id) {
- if (GS(node->id->name) == ID_MA) {
- if (node->id == (ID *)mat) {
- return true;
- }
- }
- else if (node->type == NODE_GROUP) {
- if (material_in_nodetree((bNodeTree *)node->id, mat)) {
- return true;
- }
- }
- }
- }
-
- return false;
-}
-
-bool material_in_material(Material *parmat, Material *mat)
-{
- if (parmat == mat)
- return true;
- else if (parmat->nodetree && parmat->use_nodes)
- return material_in_nodetree(parmat->nodetree, mat);
- else
- return false;
-}
-
-
/* ****************** */
-/* Update drivers for materials in a nodetree */
-static void material_node_drivers_update(Scene *scene, bNodeTree *ntree, float ctime)
-{
- bNode *node;
-
- /* nodetree itself */
- if (ntree->adt && ntree->adt->drivers.first) {
- BKE_animsys_evaluate_animdata(scene, &ntree->id, ntree->adt, ctime, ADT_RECALC_DRIVERS);
- }
-
- /* nodes */
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->id) {
- if (GS(node->id->name) == ID_MA) {
- material_drivers_update(scene, (Material *)node->id, ctime);
- }
- else if (node->type == NODE_GROUP) {
- material_node_drivers_update(scene, (bNodeTree *)node->id, ctime);
- }
- }
- }
-}
-
-/* Calculate all drivers for materials
- * FIXME: this is really a terrible method which may result in some things being calculated
- * multiple times. However, without proper despgraph support for these things, we are forced
- * into this sort of thing...
- */
-void material_drivers_update(Scene *scene, Material *ma, float ctime)
-{
- //if (G.f & G_DEBUG)
- // printf("material_drivers_update(%s, %s)\n", scene->id.name, ma->id.name);
-
- /* Prevent infinite recursion by checking (and tagging the material) as having been visited already
- * (see BKE_scene_update_tagged()). This assumes ma->id.tag & LIB_TAG_DOIT isn't set by anything else
- * in the meantime... [#32017]
- */
- if (ma->id.tag & LIB_TAG_DOIT)
- return;
-
- ma->id.tag |= LIB_TAG_DOIT;
-
- /* material itself */
- if (ma->adt && ma->adt->drivers.first) {
- BKE_animsys_evaluate_animdata(scene, &ma->id, ma->adt, ctime, ADT_RECALC_DRIVERS);
- }
-
- /* nodes */
- if (ma->nodetree) {
- material_node_drivers_update(scene, ma->nodetree, ctime);
- }
-
- ma->id.tag &= ~LIB_TAG_DOIT;
-}
-
bool BKE_object_material_slot_remove(Object *ob)
{
Material *mao, ***matarar;
@@ -1297,13 +928,6 @@ bool BKE_object_material_slot_remove(Object *ob)
return true;
}
-static bool get_mtex_slot_valid_texpaint(struct MTex *mtex)
-{
- return (mtex && (mtex->texco == TEXCO_UV) &&
- mtex->tex && (mtex->tex->type == TEX_IMAGE) &&
- mtex->tex->ima);
-}
-
static bNode *nodetree_uv_node_recursive(bNode *node)
{
bNode *inode;
@@ -1326,13 +950,9 @@ static bNode *nodetree_uv_node_recursive(bNode *node)
void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma)
{
- MTex **mtex;
short count = 0;
- short index = 0, i;
+ short index = 0;
- bool use_nodes = BKE_scene_use_new_shading_nodes(scene);
- bool is_bi = BKE_scene_uses_blender_internal(scene) || BKE_scene_uses_blender_game(scene);
-
if (!ma)
return;
@@ -1348,88 +968,50 @@ void BKE_texpaint_slot_refresh_cache(Scene *scene, Material *ma)
return;
}
- if (use_nodes || ma->use_nodes) {
- bNode *node, *active_node;
-
- if (!(ma->nodetree)) {
- ma->paint_active_slot = 0;
- ma->paint_clone_slot = 0;
- return;
- }
+ bNode *node, *active_node;
- for (node = ma->nodetree->nodes.first; node; node = node->next) {
- if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id)
- count++;
- }
+ if (!(ma->nodetree)) {
+ ma->paint_active_slot = 0;
+ ma->paint_clone_slot = 0;
+ return;
+ }
- if (count == 0) {
- ma->paint_active_slot = 0;
- ma->paint_clone_slot = 0;
- return;
- }
- ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
-
- active_node = nodeGetActiveTexture(ma->nodetree);
-
- for (node = ma->nodetree->nodes.first; node; node = node->next) {
- if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
- if (active_node == node)
- ma->paint_active_slot = index;
- ma->texpaintslot[index].ima = (Image *)node->id;
-
- /* for new renderer, we need to traverse the treeback in search of a UV node */
- if (use_nodes) {
- bNode *uvnode = nodetree_uv_node_recursive(node);
-
- if (uvnode) {
- NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage;
- ma->texpaintslot[index].uvname = storage->uv_map;
- /* set a value to index so UI knows that we have a valid pointer for the mesh */
- ma->texpaintslot[index].index = 0;
- }
- else {
- /* just invalidate the index here so UV map does not get displayed on the UI */
- ma->texpaintslot[index].index = -1;
- }
- }
- else {
- ma->texpaintslot[index].index = -1;
- }
- index++;
- }
- }
+ for (node = ma->nodetree->nodes.first; node; node = node->next) {
+ if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id)
+ count++;
}
- else if (is_bi) {
- for (mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
- if (get_mtex_slot_valid_texpaint(*mtex)) {
- count++;
- }
- }
- if (count == 0) {
- ma->paint_active_slot = 0;
- ma->paint_clone_slot = 0;
- return;
- }
+ if (count == 0) {
+ ma->paint_active_slot = 0;
+ ma->paint_clone_slot = 0;
+ return;
+ }
+ ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
- ma->texpaintslot = MEM_callocN(sizeof(*ma->texpaintslot) * count, "texpaint_slots");
+ active_node = nodeGetActiveTexture(ma->nodetree);
- for (mtex = ma->mtex, i = 0; i < MAX_MTEX; i++, mtex++) {
- if (get_mtex_slot_valid_texpaint(*mtex)) {
- ma->texpaintslot[index].ima = (*mtex)->tex->ima;
- ma->texpaintslot[index].uvname = (*mtex)->uvname;
- ma->texpaintslot[index].index = i;
-
- index++;
+ for (node = ma->nodetree->nodes.first; node; node = node->next) {
+ if (node->typeinfo->nclass == NODE_CLASS_TEXTURE && node->typeinfo->type == SH_NODE_TEX_IMAGE && node->id) {
+ if (active_node == node)
+ ma->paint_active_slot = index;
+ ma->texpaintslot[index].ima = (Image *)node->id;
+
+ /* for new renderer, we need to traverse the treeback in search of a UV node */
+ bNode *uvnode = nodetree_uv_node_recursive(node);
+
+ if (uvnode) {
+ NodeShaderUVMap *storage = (NodeShaderUVMap *)uvnode->storage;
+ ma->texpaintslot[index].uvname = storage->uv_map;
+ /* set a value to index so UI knows that we have a valid pointer for the mesh */
+ ma->texpaintslot[index].valid = true;
+ }
+ else {
+ /* just invalidate the index here so UV map does not get displayed on the UI */
+ ma->texpaintslot[index].valid = false;
}
+ index++;
}
}
- else {
- ma->paint_active_slot = 0;
- ma->paint_clone_slot = 0;
- return;
- }
-
ma->tot_slots = count;
@@ -1685,21 +1267,6 @@ void clear_matcopybuf(void)
void free_matcopybuf(void)
{
- int a;
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (matcopybuf.mtex[a]) {
- MEM_freeN(matcopybuf.mtex[a]);
- matcopybuf.mtex[a] = NULL;
- }
- }
-
- if (matcopybuf.ramp_col) MEM_freeN(matcopybuf.ramp_col);
- if (matcopybuf.ramp_spec) MEM_freeN(matcopybuf.ramp_spec);
-
- matcopybuf.ramp_col = NULL;
- matcopybuf.ramp_spec = NULL;
-
if (matcopybuf.nodetree) {
ntreeFreeTree(matcopybuf.nodetree);
MEM_freeN(matcopybuf.nodetree);
@@ -1711,575 +1278,44 @@ void free_matcopybuf(void)
void copy_matcopybuf(Material *ma)
{
- int a;
- MTex *mtex;
-
if (matcopied)
free_matcopybuf();
memcpy(&matcopybuf, ma, sizeof(Material));
- if (matcopybuf.ramp_col) matcopybuf.ramp_col = MEM_dupallocN(matcopybuf.ramp_col);
- if (matcopybuf.ramp_spec) matcopybuf.ramp_spec = MEM_dupallocN(matcopybuf.ramp_spec);
- for (a = 0; a < MAX_MTEX; a++) {
- mtex = matcopybuf.mtex[a];
- if (mtex) {
- matcopybuf.mtex[a] = MEM_dupallocN(mtex);
- }
- }
matcopybuf.nodetree = ntreeCopyTree_ex(ma->nodetree, G.main, false);
matcopybuf.preview = NULL;
BLI_listbase_clear(&matcopybuf.gpumaterial);
+ /* TODO Duplicate Engine Settings and set runtime to NULL */
matcopied = 1;
}
void paste_matcopybuf(Material *ma)
{
- int a;
- MTex *mtex;
ID id;
if (matcopied == 0)
return;
- /* free current mat */
- if (ma->ramp_col) MEM_freeN(ma->ramp_col);
- if (ma->ramp_spec) MEM_freeN(ma->ramp_spec);
- for (a = 0; a < MAX_MTEX; a++) {
- mtex = ma->mtex[a];
- if (mtex && mtex->tex)
- id_us_min(&mtex->tex->id);
- if (mtex)
- MEM_freeN(mtex);
- }
+
+ /* Free gpu material before the ntree */
+ GPU_material_free(&ma->gpumaterial);
if (ma->nodetree) {
ntreeFreeTree(ma->nodetree);
MEM_freeN(ma->nodetree);
}
- GPU_material_free(&ma->gpumaterial);
-
id = (ma->id);
memcpy(ma, &matcopybuf, sizeof(Material));
(ma->id) = id;
- if (matcopybuf.ramp_col) ma->ramp_col = MEM_dupallocN(matcopybuf.ramp_col);
- if (matcopybuf.ramp_spec) ma->ramp_spec = MEM_dupallocN(matcopybuf.ramp_spec);
-
- for (a = 0; a < MAX_MTEX; a++) {
- mtex = ma->mtex[a];
- if (mtex) {
- ma->mtex[a] = MEM_dupallocN(mtex);
- if (mtex->tex) {
- /* first check this is in main (we may have loaded another file) [#35500] */
- if (BLI_findindex(&G.main->tex, mtex->tex) != -1) {
- id_us_plus((ID *)mtex->tex);
- }
- else {
- ma->mtex[a]->tex = NULL;
- }
- }
- }
- }
-
ma->nodetree = ntreeCopyTree_ex(matcopybuf.nodetree, G.main, false);
}
-
-/*********************** texface to material convert functions **********************/
-/* encode all the TF information into a single int */
-static int encode_tfaceflag(MTFace *tf, int convertall)
-{
- /* calculate the flag */
- int flag = tf->mode;
-
- /* options that change the material offline render */
- if (!convertall) {
- flag &= ~TF_OBCOL;
- }
-
- /* clean flags that are not being converted */
- flag &= ~TF_TEX;
- flag &= ~TF_SHAREDVERT;
- flag &= ~TF_SHAREDCOL;
- flag &= ~TF_CONVERTED;
-
- /* light tface flag is ignored in GLSL mode */
- flag &= ~TF_LIGHT;
-
- /* 15 is how big the flag can be - hardcoded here and in decode_tfaceflag() */
- flag |= tf->transp << 15;
-
- /* increase 1 so flag 0 is different than no flag yet */
- return flag + 1;
-}
-
-/* set the material options based in the tface flag */
-static void decode_tfaceflag(Material *ma, int flag, int convertall)
-{
- int alphablend;
- GameSettings *game = &ma->game;
-
- /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */
- flag -= 1;
-
- alphablend = flag >> 15; /* encoded in the encode_tfaceflag function */
- (*game).flag = 0;
-
- /* General Material Options */
- if ((flag & TF_DYNAMIC) == 0) (*game).flag |= GEMAT_NOPHYSICS;
-
- /* Material Offline Rendering Properties */
- if (convertall) {
- if (flag & TF_OBCOL) ma->shade_flag |= MA_OBCOLOR;
- }
-
- /* Special Face Properties */
- if ((flag & TF_TWOSIDE) == 0) (*game).flag |= GEMAT_BACKCULL;
- if (flag & TF_INVISIBLE) (*game).flag |= GEMAT_INVISIBLE;
- if (flag & TF_BMFONT) (*game).flag |= GEMAT_TEXT;
-
- /* Face Orientation */
- if (flag & TF_BILLBOARD) (*game).face_orientation |= GEMAT_HALO;
- else if (flag & TF_BILLBOARD2) (*game).face_orientation |= GEMAT_BILLBOARD;
- else if (flag & TF_SHADOW) (*game).face_orientation |= GEMAT_SHADOW;
-
- /* Alpha Blend */
- if (flag & TF_ALPHASORT && ELEM(alphablend, TF_ALPHA, TF_ADD)) (*game).alpha_blend = GEMAT_ALPHA_SORT;
- else if (alphablend & TF_ALPHA) (*game).alpha_blend = GEMAT_ALPHA;
- else if (alphablend & TF_ADD) (*game).alpha_blend = GEMAT_ADD;
- else if (alphablend & TF_CLIP) (*game).alpha_blend = GEMAT_CLIP;
-}
-
-/* boolean check to see if the mesh needs a material */
-static int check_tfaceneedmaterial(int flag)
-{
- /* check if the flags we have are not deprecated != than default material options
- * also if only flags are visible and collision see if all objects using this mesh have this option in physics */
-
- /* flag is shifted in 1 to make 0 != no flag yet (see encode_tfaceflag) */
- flag -= 1;
-
- /* deprecated flags */
- flag &= ~TF_OBCOL;
- flag &= ~TF_SHAREDVERT;
- flag &= ~TF_SHAREDCOL;
-
- /* light tface flag is ignored in GLSL mode */
- flag &= ~TF_LIGHT;
-
- /* automatic detected if tex image has alpha */
- flag &= ~(TF_ALPHA << 15);
- /* automatic detected if using texture */
- flag &= ~TF_TEX;
-
- /* settings for the default NoMaterial */
- if (flag == TF_DYNAMIC)
- return 0;
-
- else
- return 1;
-}
-
-/* return number of digits of an integer */
-/* XXX to be optmized or replaced by an equivalent blender internal function */
-static int integer_getdigits(int number)
+void BKE_material_eval(struct Depsgraph *depsgraph, Material *material)
{
- int i = 0;
- if (number == 0) return 1;
-
- while (number != 0) {
- number = (int)(number / 10);
- i++;
+ DEG_debug_print_eval(depsgraph, __func__, material->id.name, material);
+ if ((BLI_listbase_is_empty(&material->gpumaterial) == false)) {
+ GPU_material_uniform_buffer_tag_dirty(&material->gpumaterial);
}
- return i;
}
-
-static void calculate_tface_materialname(char *matname, char *newname, int flag)
-{
- /* if flag has only light and collision and material matches those values
- * you can do strcpy(name, mat_name);
- * otherwise do: */
- int digits = integer_getdigits(flag);
- /* clamp the old name, remove the MA prefix and add the .TF.flag suffix
- * e.g. matname = "MALoooooooooooooongName"; newname = "Loooooooooooooon.TF.2" */
- BLI_snprintf(newname, MAX_ID_NAME, "%.*s.TF.%0*d", MAX_ID_NAME - (digits + 5), matname, digits, flag);
-}
-
-/* returns -1 if no match */
-static short mesh_getmaterialnumber(Mesh *me, Material *ma)
-{
- short a;
-
- for (a = 0; a < me->totcol; a++) {
- if (me->mat[a] == ma) {
- return a;
- }
- }
-
- return -1;
-}
-
-/* append material */
-static short mesh_addmaterial(Mesh *me, Material *ma)
-{
- BKE_material_append_id(G.main, &me->id, NULL);
- me->mat[me->totcol - 1] = ma;
-
- id_us_plus(&ma->id);
-
- return me->totcol - 1;
-}
-
-static void set_facetexture_flags(Material *ma, Image *image)
-{
- if (image) {
- ma->mode |= MA_FACETEXTURE;
- /* we could check if the texture has alpha, but then more meshes sharing the same
- * material may need it. Let's make it simple. */
- if (BKE_image_has_alpha(image))
- ma->mode |= MA_FACETEXTURE_ALPHA;
- }
-}
-
-/* returns material number */
-static short convert_tfacenomaterial(Main *main, Mesh *me, MTFace *tf, int flag)
-{
- Material *ma;
- char idname[MAX_ID_NAME];
- short mat_nr = -1;
-
- /* new material, the name uses the flag*/
- BLI_snprintf(idname, sizeof(idname), "MAMaterial.TF.%0*d", integer_getdigits(flag), flag);
-
- if ((ma = BLI_findstring(&main->mat, idname + 2, offsetof(ID, name) + 2))) {
- mat_nr = mesh_getmaterialnumber(me, ma);
- /* assign the material to the mesh */
- if (mat_nr == -1) mat_nr = mesh_addmaterial(me, ma);
-
- /* if needed set "Face Textures [Alpha]" Material options */
- set_facetexture_flags(ma, tf->tpage);
- }
- /* create a new material */
- else {
- ma = BKE_material_add(main, idname + 2);
-
- if (ma) {
- printf("TexFace Convert: Material \"%s\" created.\n", idname + 2);
- mat_nr = mesh_addmaterial(me, ma);
-
- /* if needed set "Face Textures [Alpha]" Material options */
- set_facetexture_flags(ma, tf->tpage);
-
- decode_tfaceflag(ma, flag, 1);
- /* the final decoding will happen after, outside the main loop
- * for now store the flag into the material and change light/tex/collision
- * store the flag as a negative number */
- ma->game.flag = -flag;
- id_us_min((ID *)ma);
- }
- else {
- printf("Error: Unable to create Material \"%s\" for Mesh \"%s\".", idname + 2, me->id.name + 2);
- }
- }
-
- /* set as converted, no need to go bad to this face */
- tf->mode |= TF_CONVERTED;
- return mat_nr;
-}
-
-/* Function to fully convert materials */
-static void convert_tfacematerial(Main *main, Material *ma)
-{
- Mesh *me;
- Material *mat_new;
- MFace *mf;
- MTFace *tf;
- int flag, index;
- int a;
- short mat_nr;
- CustomDataLayer *cdl;
- char idname[MAX_ID_NAME];
-
- for (me = main->mesh.first; me; me = me->id.next) {
- /* check if this mesh uses this material */
- for (a = 0; a < me->totcol; a++)
- if (me->mat[a] == ma) break;
-
- /* no material found */
- if (a == me->totcol) continue;
-
- /* get the active tface layer */
- index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
- cdl = (index == -1) ? NULL : &me->fdata.layers[index];
- if (!cdl) continue;
-
- /* loop over all the faces and stop at the ones that use the material*/
- for (a = 0, mf = me->mface; a < me->totface; a++, mf++) {
- if (me->mat[mf->mat_nr] != ma) continue;
-
- /* texface data for this face */
- tf = ((MTFace *)cdl->data) + a;
- flag = encode_tfaceflag(tf, 1);
-
- /* the name of the new material */
- calculate_tface_materialname(ma->id.name, (char *)&idname, flag);
-
- if ((mat_new = BLI_findstring(&main->mat, idname + 2, offsetof(ID, name) + 2))) {
- /* material already existent, see if the mesh has it */
- mat_nr = mesh_getmaterialnumber(me, mat_new);
- /* material is not in the mesh, add it */
- if (mat_nr == -1) mat_nr = mesh_addmaterial(me, mat_new);
- }
- /* create a new material */
- else {
- mat_new = BKE_material_copy(main, ma);
- if (mat_new) {
- /* rename the material*/
- BLI_strncpy(mat_new->id.name, idname, sizeof(mat_new->id.name));
- id_us_min((ID *)mat_new);
-
- mat_nr = mesh_addmaterial(me, mat_new);
- decode_tfaceflag(mat_new, flag, 1);
- }
- else {
- printf("Error: Unable to create Material \"%s\" for Mesh \"%s.", idname + 2, me->id.name + 2);
- mat_nr = mf->mat_nr;
- continue;
- }
- }
-
- /* if the material has a texture but no texture channel
- * set "Face Textures [Alpha]" Material options
- * actually we need to run it always, because of old behavior
- * of using face texture if any texture channel was present (multitex) */
- //if ((!mat_new->mtex[0]) && (!mat_new->mtex[0]->tex))
- set_facetexture_flags(mat_new, tf->tpage);
-
- /* set the material number to the face*/
- mf->mat_nr = mat_nr;
- }
- /* remove material from mesh */
- for (a = 0; a < me->totcol; ) {
- if (me->mat[a] == ma) {
- BKE_material_pop_id(main, &me->id, a, true);
- }
- else {
- a++;
- }
- }
- }
-}
-
-
-#define MAT_BGE_DISPUTED -99999
-
-int do_version_tface(Main *main)
-{
- Mesh *me;
- Material *ma;
- MFace *mf;
- MTFace *tf;
- CustomDataLayer *cdl;
- int a;
- int flag;
- int index;
-
- /* Operator in help menu has been removed for 2.7x */
- int fileload = 1;
-
- /* sometimes mesh has no materials but will need a new one. In those
- * cases we need to ignore the mf->mat_nr and only look at the face
- * mode because it can be zero as uninitialized or the 1st created material
- */
- int nomaterialslots;
-
- /* alert to user to check the console */
- int nowarning = 1;
-
- /* mark all the materials to conversion with a flag
- * if there is tface create a complete flag for that storing in flag
- * if there is tface and flag > 0: creates a new flag based on this face
- * if flags are different set flag to -1
- */
-
- /* 1st part: marking mesh materials to update */
- for (me = main->mesh.first; me; me = me->id.next) {
- if (ID_IS_LINKED(me)) continue;
-
- /* get the active tface layer */
- index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
- cdl = (index == -1) ? NULL : &me->fdata.layers[index];
- if (!cdl) continue;
-
- nomaterialslots = (me->totcol == 0 ? 1 : 0);
-
- /* loop over all the faces*/
- for (a = 0, mf = me->mface; a < me->totface; a++, mf++) {
- /* texface data for this face */
- tf = ((MTFace *)cdl->data) + a;
-
- /* conversion should happen only once */
- if (fileload)
- tf->mode &= ~TF_CONVERTED;
- else {
- if ((tf->mode & TF_CONVERTED)) continue;
- else tf->mode |= TF_CONVERTED;
- }
-
- /* no material slots */
- if (nomaterialslots) {
- flag = encode_tfaceflag(tf, 1);
-
- /* create/find a new material and assign to the face */
- if (check_tfaceneedmaterial(flag)) {
- mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag);
- }
- /* else mark them as no-material to be reverted to 0 later */
- else {
- mf->mat_nr = -1;
- }
- }
- else if (mf->mat_nr < me->totcol) {
- ma = me->mat[mf->mat_nr];
-
- /* no material create one if necessary */
- if (!ma) {
- /* find a new material and assign to the face */
- flag = encode_tfaceflag(tf, 1);
-
- /* create/find a new material and assign to the face */
- if (check_tfaceneedmaterial(flag))
- mf->mat_nr = convert_tfacenomaterial(main, me, tf, flag);
-
- continue;
- }
-
- /* we can't read from this if it comes from a library,
- * at doversion time: direct_link might not have happened on it,
- * so ma->mtex is not pointing to valid memory yet.
- * later we could, but it's better not */
- else if (ID_IS_LINKED(ma))
- continue;
-
- /* material already marked as disputed */
- else if (ma->game.flag == MAT_BGE_DISPUTED)
- continue;
-
- /* found a material */
- else {
- flag = encode_tfaceflag(tf, ((fileload) ? 0 : 1));
-
- /* first time changing this material */
- if (ma->game.flag == 0)
- ma->game.flag = -flag;
-
- /* mark material as disputed */
- else if (ma->game.flag != -flag) {
- ma->game.flag = MAT_BGE_DISPUTED;
- continue;
- }
-
- /* material ok so far */
- else {
- ma->game.flag = -flag;
-
- /* some people uses multitexture with TexFace by creating a texture
- * channel which not necessarily the tf->tpage image. But the game engine
- * was enabling it. Now it's required to set "Face Texture [Alpha] in the
- * material settings. */
- if (!fileload)
- set_facetexture_flags(ma, tf->tpage);
- }
- }
- }
- else {
- continue;
- }
- }
-
- /* if we didn't have material slot and now we do, we need to
- * make sure the materials are correct */
- if (nomaterialslots) {
- if (me->totcol > 0) {
- for (a = 0, mf = me->mface; a < me->totface; a++, mf++) {
- if (mf->mat_nr == -1) {
- /* texface data for this face */
- tf = ((MTFace *)cdl->data) + a;
- mf->mat_nr = convert_tfacenomaterial(main, me, tf, encode_tfaceflag(tf, 1));
- }
- }
- }
- else {
- for (a = 0, mf = me->mface; a < me->totface; a++, mf++) {
- mf->mat_nr = 0;
- }
- }
- }
-
- }
-
- /* 2nd part - conversion */
- /* skip library files */
-
- /* we shouldn't loop through the materials created in the loop. make the loop stop at its original length) */
- for (ma = main->mat.first, a = 0; ma; ma = ma->id.next, a++) {
- if (ID_IS_LINKED(ma)) continue;
-
- /* disputed material */
- if (ma->game.flag == MAT_BGE_DISPUTED) {
- ma->game.flag = 0;
- if (fileload) {
- printf("Warning: material \"%s\" skipped.\n", ma->id.name + 2);
- nowarning = 0;
- }
- else {
- convert_tfacematerial(main, ma);
- }
- continue;
- }
-
- /* no conflicts in this material - 90% of cases
- * convert from tface system to material */
- else if (ma->game.flag < 0) {
- decode_tfaceflag(ma, -(ma->game.flag), 1);
-
- /* material is good make sure all faces using
- * this material are set to converted */
- if (fileload) {
- for (me = main->mesh.first; me; me = me->id.next) {
- /* check if this mesh uses this material */
- for (a = 0; a < me->totcol; a++)
- if (me->mat[a] == ma) break;
-
- /* no material found */
- if (a == me->totcol) continue;
-
- /* get the active tface layer */
- index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE);
- cdl = (index == -1) ? NULL : &me->fdata.layers[index];
- if (!cdl) continue;
-
- /* loop over all the faces and stop at the ones that use the material*/
- for (a = 0, mf = me->mface; a < me->totface; a++, mf++) {
- if (me->mat[mf->mat_nr] == ma) {
- /* texface data for this face */
- tf = ((MTFace *)cdl->data) + a;
- tf->mode |= TF_CONVERTED;
- }
- }
- }
- }
- }
- /* material is not used by faces with texface
- * set the default flag - do it only once */
- else {
- if (fileload) {
- ma->game.flag = GEMAT_BACKCULL;
- }
- }
- }
-
- return nowarning;
-}
-
diff --git a/source/blender/blenkernel/intern/mball.c b/source/blender/blenkernel/intern/mball.c
index dfc49c996b1..d7fb2d0a17b 100644
--- a/source/blender/blenkernel/intern/mball.c
+++ b/source/blender/blenkernel/intern/mball.c
@@ -57,7 +57,6 @@
#include "BKE_animsys.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_scene.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
@@ -67,6 +66,8 @@
#include "BKE_object.h"
#include "BKE_material.h"
+//#include "DEG_depsgraph.h"
+
/* Functions */
/** Free (or release) any data used by this mball (does not free the mball itself). */
@@ -74,6 +75,8 @@ void BKE_mball_free(MetaBall *mb)
{
BKE_animdata_free((ID *)mb, false);
+ BKE_mball_batch_cache_free(mb);
+
MEM_SAFE_FREE(mb->mat);
BLI_freelistN(&mb->elems);
@@ -119,6 +122,7 @@ void BKE_mball_copy_data(Main *UNUSED(bmain), MetaBall *mb_dst, const MetaBall *
mb_dst->editelems = NULL;
mb_dst->lastelem = NULL;
+ mb_dst->batch_cache = NULL;
}
MetaBall *BKE_mball_copy(Main *bmain, const MetaBall *mb)
@@ -325,12 +329,14 @@ void BKE_mball_properties_copy(Scene *scene, Object *active_object)
int basisnr, obnr;
char basisname[MAX_ID_NAME], obname[MAX_ID_NAME];
SceneBaseIter iter;
- EvaluationContext *eval_ctx = G.main->eval_ctx;
BLI_split_name_num(basisname, &basisnr, active_object->id.name + 2, '.');
- BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 0, NULL, NULL);
- while (BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 1, &base, &ob)) {
+ /* Pass depsgraph as NULL, which means we will not expand into
+ * duplis unlike when we generate the mball. Expanding duplis
+ * would not be compatible when editing multiple view layers. */
+ BKE_scene_base_iter_next(NULL, &iter, &sce_iter, 0, NULL, NULL);
+ while (BKE_scene_base_iter_next(NULL, &iter, &sce_iter, 1, &base, &ob)) {
if (ob->type == OB_MBALL) {
if (ob != active_object) {
BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.');
@@ -362,27 +368,25 @@ void BKE_mball_properties_copy(Scene *scene, Object *active_object)
*/
Object *BKE_mball_basis_find(Scene *scene, Object *basis)
{
- Scene *sce_iter = scene;
- Base *base;
- Object *ob, *bob = basis;
+ Object *bob = basis;
int basisnr, obnr;
char basisname[MAX_ID_NAME], obname[MAX_ID_NAME];
- SceneBaseIter iter;
- EvaluationContext *eval_ctx = G.main->eval_ctx;
BLI_split_name_num(basisname, &basisnr, basis->id.name + 2, '.');
- BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 0, NULL, NULL);
- while (BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 1, &base, &ob)) {
- if ((ob->type == OB_MBALL) && !(base->flag & OB_FROMDUPLI)) {
- if (ob != bob) {
- BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.');
-
- /* object ob has to be in same "group" ... it means, that it has to have same base of its name */
- if (STREQ(obname, basisname)) {
- if (obnr < basisnr) {
- basis = ob;
- basisnr = obnr;
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ Object *ob = base->object;
+ if ((ob->type == OB_MBALL) && !(base->flag & OB_FROMDUPLI)) {
+ if (ob != bob) {
+ BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.');
+
+ /* object ob has to be in same "group" ... it means, that it has to have same base of its name */
+ if (STREQ(obname, basisname)) {
+ if (obnr < basisnr) {
+ basis = ob;
+ basisnr = obnr;
+ }
}
}
}
@@ -539,7 +543,25 @@ void BKE_mball_select_swap(struct MetaBall *mb)
/* **** Depsgraph evaluation **** */
-void BKE_mball_eval_geometry(EvaluationContext *UNUSED(eval_ctx),
+void BKE_mball_eval_geometry(struct Depsgraph *UNUSED(depsgraph),
MetaBall *UNUSED(mball))
{
}
+
+/* Draw Engine */
+
+void (*BKE_mball_batch_cache_dirty_cb)(MetaBall *mb, int mode) = NULL;
+void (*BKE_mball_batch_cache_free_cb)(MetaBall *mb) = NULL;
+
+void BKE_mball_batch_cache_dirty(MetaBall *mb, int mode)
+{
+ if (mb->batch_cache) {
+ BKE_mball_batch_cache_dirty_cb(mb, mode);
+ }
+}
+void BKE_mball_batch_cache_free(MetaBall *mb)
+{
+ if (mb->batch_cache) {
+ BKE_mball_batch_cache_free_cb(mb);
+ }
+}
diff --git a/source/blender/blenkernel/intern/mball_tessellate.c b/source/blender/blenkernel/intern/mball_tessellate.c
index a1ae3a7f572..0f13618c76a 100644
--- a/source/blender/blenkernel/intern/mball_tessellate.c
+++ b/source/blender/blenkernel/intern/mball_tessellate.c
@@ -48,11 +48,13 @@
#include "BKE_global.h"
-#include "BKE_depsgraph.h"
#include "BKE_scene.h"
#include "BKE_displist.h"
#include "BKE_mball_tessellate.h" /* own include */
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "BLI_strict_flags.h"
/* experimental (faster) normal calculation */
@@ -1055,7 +1057,7 @@ static void polygonize(PROCESS *process)
* Iterates over ALL objects in the scene and all of its sets, including
* making all duplis(not only metas). Copies metas to mainb array.
* Computes bounding boxes for building BVH. */
-static void init_meta(EvaluationContext *eval_ctx, PROCESS *process, Scene *scene, Object *ob)
+static void init_meta(Depsgraph *depsgraph, PROCESS *process, Scene *scene, Object *ob)
{
Scene *sce_iter = scene;
Base *base;
@@ -1074,13 +1076,13 @@ static void init_meta(EvaluationContext *eval_ctx, PROCESS *process, Scene *scen
BLI_split_name_num(obname, &obnr, ob->id.name + 2, '.');
/* make main array */
- BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 0, NULL, NULL);
- while (BKE_scene_base_iter_next(eval_ctx, &iter, &sce_iter, 1, &base, &bob)) {
+ BKE_scene_base_iter_next(depsgraph, &iter, &sce_iter, 0, NULL, NULL);
+ while (BKE_scene_base_iter_next(depsgraph, &iter, &sce_iter, 1, &base, &bob)) {
if (bob->type == OB_MBALL) {
zero_size = 0;
ml = NULL;
- if (bob == ob && (base->flag & OB_FROMDUPLI) == 0) {
+ if (bob == ob && (base->flag_legacy & OB_FROMDUPLI) == 0) {
mb = ob->data;
if (mb->editelems) ml = mb->editelems->first;
@@ -1232,12 +1234,13 @@ static void init_meta(EvaluationContext *eval_ctx, PROCESS *process, Scene *scen
}
}
-void BKE_mball_polygonize(EvaluationContext *eval_ctx, Scene *scene, Object *ob, ListBase *dispbase)
+void BKE_mball_polygonize(Depsgraph *depsgraph, Scene *scene, Object *ob, ListBase *dispbase)
{
MetaBall *mb;
DispList *dl;
unsigned int a;
PROCESS process = {0};
+ bool is_render = DEG_get_mode(depsgraph) == DAG_EVAL_RENDER;
mb = ob->data;
@@ -1248,10 +1251,10 @@ void BKE_mball_polygonize(EvaluationContext *eval_ctx, Scene *scene, Object *ob,
else if (process.thresh < 0.1f) process.converge_res = 4;
else process.converge_res = 2;
- if ((eval_ctx->mode != DAG_EVAL_RENDER) && (mb->flag == MB_UPDATE_NEVER)) return;
+ if (is_render && (mb->flag == MB_UPDATE_NEVER)) return;
if ((G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT)) && mb->flag == MB_UPDATE_FAST) return;
- if (eval_ctx->mode == DAG_EVAL_RENDER) {
+ if (is_render) {
process.size = mb->rendersize;
}
else {
@@ -1266,7 +1269,7 @@ void BKE_mball_polygonize(EvaluationContext *eval_ctx, Scene *scene, Object *ob,
process.pgn_elements = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "Metaball memarena");
/* initialize all mainb (MetaElems) */
- init_meta(eval_ctx, &process, scene, ob);
+ init_meta(depsgraph, &process, scene, ob);
if (process.totelem > 0) {
build_bvh_spatial(&process, &process.metaball_bvh, 0, process.totelem, &process.allbb);
diff --git a/source/blender/blenkernel/intern/mesh.c b/source/blender/blenkernel/intern/mesh.c
index fd56534146d..3163ea6551e 100644
--- a/source/blender/blenkernel/intern/mesh.c
+++ b/source/blender/blenkernel/intern/mesh.c
@@ -44,12 +44,15 @@
#include "BLI_memarena.h"
#include "BLI_edgehash.h"
#include "BLI_string.h"
+#include "BLI_utildefines_stack.h"
#include "BKE_animsys.h"
+#include "BKE_idcode.h"
#include "BKE_main.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
#include "BKE_displist.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
@@ -59,7 +62,6 @@
#include "BKE_multires.h"
#include "BKE_key.h"
#include "BKE_mball.h"
-#include "BKE_depsgraph.h"
/* these 2 are only used by conversion functions */
#include "BKE_curve.h"
/* -- */
@@ -67,6 +69,7 @@
#include "BKE_editmesh.h"
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
/* Define for cases when you want extra validation of mesh
* after certain modifications.
@@ -127,7 +130,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2
for (i = 0; i < c1->totlayer; i++) {
if (ELEM(c1->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY,
- CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
+ CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT))
{
i1++;
}
@@ -135,7 +138,7 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2
for (i = 0; i < c2->totlayer; i++) {
if (ELEM(c2->layers[i].type, CD_MVERT, CD_MEDGE, CD_MPOLY,
- CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
+ CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT))
{
i2++;
}
@@ -149,14 +152,14 @@ static int customdata_compare(CustomData *c1, CustomData *c2, Mesh *m1, Mesh *m2
i1 = 0; i2 = 0;
for (i = 0; i < tot; i++) {
while (i1 < c1->totlayer && !ELEM(l1->type, CD_MVERT, CD_MEDGE, CD_MPOLY,
- CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
+ CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT))
{
i1++;
l1++;
}
while (i2 < c2->totlayer && !ELEM(l2->type, CD_MVERT, CD_MEDGE, CD_MPOLY,
- CD_MLOOPUV, CD_MLOOPCOL, CD_MTEXPOLY, CD_MDEFORMVERT))
+ CD_MLOOPUV, CD_MLOOPCOL, CD_MDEFORMVERT))
{
i2++;
l2++;
@@ -324,7 +327,7 @@ static void mesh_ensure_tessellation_customdata(Mesh *me)
* Callers could also check but safer to do here - campbell */
}
else {
- const int tottex_original = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+ const int tottex_original = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
const int totcol_original = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
const int tottex_tessface = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
@@ -335,7 +338,7 @@ static void mesh_ensure_tessellation_customdata(Mesh *me)
{
BKE_mesh_tessface_clear(me);
- CustomData_from_bmeshpoly(&me->fdata, &me->pdata, &me->ldata, me->totface);
+ CustomData_from_bmeshpoly(&me->fdata, &me->ldata, me->totface);
/* TODO - add some --debug-mesh option */
if (G.debug & G_DEBUG) {
@@ -344,7 +347,7 @@ static void mesh_ensure_tessellation_customdata(Mesh *me)
* and check if there was any data to begin with, for now just print the warning with
* some info to help troubleshoot whats going on - campbell */
printf("%s: warning! Tessellation uvs or vcol data got out of sync, "
- "had to reset!\n CD_MTFACE: %d != CD_MTEXPOLY: %d || CD_MCOL: %d != CD_MLOOPCOL: %d\n",
+ "had to reset!\n CD_MTFACE: %d != CD_MLOOPUV: %d || CD_MCOL: %d != CD_MLOOPCOL: %d\n",
__func__, tottex_tessface, tottex_original, totcol_tessface, totcol_original);
}
}
@@ -388,6 +391,78 @@ void BKE_mesh_ensure_skin_customdata(Mesh *me)
}
}
+bool BKE_mesh_ensure_edit_data(struct Mesh *me)
+{
+ if (me->runtime.edit_data != NULL) {
+ return false;
+ }
+
+ me->runtime.edit_data = MEM_callocN(sizeof(EditMeshData), "EditMeshData");
+ return true;
+}
+
+bool BKE_mesh_clear_edit_data(struct Mesh *me)
+{
+ if (me->runtime.edit_data == NULL) {
+ return false;
+ }
+
+ if (me->runtime.edit_data->polyCos != NULL)
+ MEM_freeN((void *)me->runtime.edit_data->polyCos);
+ if (me->runtime.edit_data->polyNos != NULL)
+ MEM_freeN((void *)me->runtime.edit_data->polyNos);
+ if (me->runtime.edit_data->vertexCos != NULL)
+ MEM_freeN((void *)me->runtime.edit_data->vertexCos);
+ if (me->runtime.edit_data->vertexNos != NULL)
+ MEM_freeN((void *)me->runtime.edit_data->vertexNos);
+
+ MEM_SAFE_FREE(me->runtime.edit_data);
+ return true;
+}
+
+
+bool BKE_mesh_ensure_facemap_customdata(struct Mesh *me)
+{
+ BMesh *bm = me->edit_btmesh ? me->edit_btmesh->bm : NULL;
+ bool changed = false;
+ if (bm) {
+ if (!CustomData_has_layer(&bm->pdata, CD_FACEMAP)) {
+ BM_data_layer_add(bm, &bm->pdata, CD_FACEMAP);
+ changed = true;
+ }
+ }
+ else {
+ if (!CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
+ CustomData_add_layer(&me->pdata,
+ CD_FACEMAP,
+ CD_DEFAULT,
+ NULL,
+ me->totpoly);
+ changed = true;
+ }
+ }
+ return changed;
+}
+
+bool BKE_mesh_clear_facemap_customdata(struct Mesh *me)
+{
+ BMesh *bm = me->edit_btmesh ? me->edit_btmesh->bm : NULL;
+ bool changed = false;
+ if (bm) {
+ if (CustomData_has_layer(&bm->pdata, CD_FACEMAP)) {
+ BM_data_layer_free(bm, &bm->pdata, CD_FACEMAP);
+ changed = true;
+ }
+ }
+ else {
+ if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
+ CustomData_free_layers(&me->pdata, CD_FACEMAP, me->totpoly);
+ changed = true;
+ }
+ }
+ return changed;
+}
+
/* this ensures grouped customdata (e.g. mtexpoly and mloopuv and mtface, or
* mloopcol and mcol) have the same relative active/render/clone/mask indices.
*
@@ -396,14 +471,11 @@ void BKE_mesh_ensure_skin_customdata(Mesh *me)
* versions of the mesh. - campbell*/
static void mesh_update_linked_customdata(Mesh *me, const bool do_ensure_tess_cd)
{
- if (me->edit_btmesh)
- BKE_editmesh_update_linked_customdata(me->edit_btmesh);
-
if (do_ensure_tess_cd) {
mesh_ensure_tessellation_customdata(me);
}
- CustomData_bmesh_update_active_layers(&me->fdata, &me->pdata, &me->ldata);
+ CustomData_bmesh_update_active_layers(&me->fdata, &me->ldata);
}
void BKE_mesh_update_customdata_pointers(Mesh *me, const bool do_ensure_tess_cd)
@@ -422,7 +494,6 @@ void BKE_mesh_update_customdata_pointers(Mesh *me, const bool do_ensure_tess_cd)
me->mpoly = CustomData_get_layer(&me->pdata, CD_MPOLY);
me->mloop = CustomData_get_layer(&me->ldata, CD_MLOOP);
- me->mtpoly = CustomData_get_layer(&me->pdata, CD_MTEXPOLY);
me->mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL);
me->mloopuv = CustomData_get_layer(&me->ldata, CD_MLOOPUV);
}
@@ -442,6 +513,9 @@ void BKE_mesh_free(Mesh *me)
{
BKE_animdata_free(&me->id, false);
+ BKE_mesh_batch_cache_free(me);
+ BKE_mesh_clear_edit_data(me);
+
CustomData_free(&me->vdata, me->totvert);
CustomData_free(&me->edata, me->totedge);
CustomData_free(&me->fdata, me->totface);
@@ -529,6 +603,7 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int
BKE_mesh_update_customdata_pointers(me_dst, do_tessface);
me_dst->edit_btmesh = NULL;
+ me_dst->runtime.batch_cache = NULL;
me_dst->mselect = MEM_dupallocN(me_dst->mselect);
me_dst->bb = MEM_dupallocN(me_dst->bb);
@@ -539,6 +614,58 @@ void BKE_mesh_copy_data(Main *bmain, Mesh *me_dst, const Mesh *me_src, const int
}
}
+static Mesh *mesh_from_template_ex(
+ const Mesh *me_src,
+ int numVerts, int numEdges, int numTessFaces,
+ int numLoops, int numPolys,
+ CustomDataMask mask)
+{
+ const bool do_tessface = ((me_src->totface != 0) && (me_src->totpoly == 0)); /* only do tessface if we have no polys */
+
+ Mesh *me_dst = BKE_id_new_nomain(ID_ME, NULL);
+
+ me_dst->mat = MEM_dupallocN(me_src->mat);
+ me_dst->mselect = MEM_dupallocN(me_dst->mselect);
+
+ me_dst->totvert = numVerts;
+ me_dst->totedge = numEdges;
+ me_dst->totloop = numLoops;
+ me_dst->totpoly = numPolys;
+
+ CustomData_copy(&me_src->vdata, &me_dst->vdata, mask, CD_CALLOC, numVerts);
+ CustomData_copy(&me_src->edata, &me_dst->edata, mask, CD_CALLOC, numEdges);
+ CustomData_copy(&me_src->ldata, &me_dst->ldata, mask, CD_CALLOC, numLoops);
+ CustomData_copy(&me_src->pdata, &me_dst->pdata, mask, CD_CALLOC, numPolys);
+ if (do_tessface) {
+ CustomData_copy(&me_src->fdata, &me_dst->fdata, mask, CD_CALLOC, numTessFaces);
+ }
+ else {
+ mesh_tessface_clear_intern(me_dst, false);
+ }
+
+ BKE_mesh_update_customdata_pointers(me_dst, false);
+
+ if (!CustomData_get_layer(&me_dst->vdata, CD_ORIGINDEX))
+ CustomData_add_layer(&me_dst->vdata, CD_ORIGINDEX, CD_CALLOC, NULL, numVerts);
+ if (!CustomData_get_layer(&me_dst->edata, CD_ORIGINDEX))
+ CustomData_add_layer(&me_dst->edata, CD_ORIGINDEX, CD_CALLOC, NULL, numEdges);
+ if (!CustomData_get_layer(&me_dst->pdata, CD_ORIGINDEX))
+ CustomData_add_layer(&me_dst->pdata, CD_ORIGINDEX, CD_CALLOC, NULL, numPolys);
+
+ return me_dst;
+}
+
+Mesh * BKE_mesh_from_template(const Mesh *me_src,
+ int numVerts, int numEdges, int numTessFaces,
+ int numLoops, int numPolys)
+{
+ return mesh_from_template_ex(
+ me_src,
+ numVerts, numEdges, numTessFaces,
+ numLoops, numPolys,
+ CD_MASK_EVERYTHING);
+}
+
Mesh *BKE_mesh_copy(Main *bmain, const Mesh *me)
{
Mesh *me_copy;
@@ -546,143 +673,123 @@ Mesh *BKE_mesh_copy(Main *bmain, const Mesh *me)
return me_copy;
}
-BMesh *BKE_mesh_to_bmesh(
- Mesh *me, Object *ob,
- const bool add_key_index, const struct BMeshCreateParams *params)
+BMesh *BKE_mesh_to_bmesh_ex(
+ Mesh *me,
+ const struct BMeshCreateParams *create_params,
+ const struct BMeshFromMeshParams *convert_params)
{
BMesh *bm;
const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_ME(me);
- bm = BM_mesh_create(&allocsize, params);
-
- BM_mesh_bm_from_me(
- bm, me, (&(struct BMeshFromMeshParams){
- .add_key_index = add_key_index, .use_shapekey = true, .active_shapekey = ob->shapenr,
- }));
+ bm = BM_mesh_create(&allocsize, create_params);
+ BM_mesh_bm_from_me(bm, me, convert_params);
return bm;
}
+BMesh *BKE_mesh_to_bmesh(
+ Mesh *me, Object *ob,
+ const bool add_key_index, const struct BMeshCreateParams *params)
+{
+ return BKE_mesh_to_bmesh_ex(
+ me, params,
+ &(struct BMeshFromMeshParams){
+ .calc_face_normal = false,
+ .add_key_index = add_key_index,
+ .use_shapekey = true,
+ .active_shapekey = ob->shapenr,
+ });
+}
+
+Mesh *BKE_bmesh_to_mesh(BMesh *bm, const struct BMeshToMeshParams *params)
+{
+ Mesh *mesh = BKE_id_new_nomain(ID_ME, NULL);
+ BM_mesh_bm_to_me(bm, mesh, params);
+ return mesh;
+}
+
void BKE_mesh_make_local(Main *bmain, Mesh *me, const bool lib_local)
{
BKE_id_make_local_generic(bmain, &me->id, true, lib_local);
}
-bool BKE_mesh_uv_cdlayer_rename_index(Mesh *me, const int poly_index, const int loop_index, const int face_index,
- const char *new_name, const bool do_tessface)
+bool BKE_mesh_uv_cdlayer_rename_index(
+ Mesh *me, const int loop_index, const int face_index,
+ const char *new_name, const bool do_tessface)
{
- CustomData *pdata, *ldata, *fdata;
- CustomDataLayer *cdlp, *cdlu, *cdlf;
- const int step = do_tessface ? 3 : 2;
- int i;
+ CustomData *ldata, *fdata;
+ CustomDataLayer *cdlu, *cdlf;
if (me->edit_btmesh) {
- pdata = &me->edit_btmesh->bm->pdata;
ldata = &me->edit_btmesh->bm->ldata;
fdata = NULL; /* No tessellated data in BMesh! */
}
else {
- pdata = &me->pdata;
ldata = &me->ldata;
fdata = &me->fdata;
}
- cdlp = &pdata->layers[poly_index];
+
cdlu = &ldata->layers[loop_index];
- cdlf = fdata && do_tessface ? &fdata->layers[face_index] : NULL;
+ cdlf = (face_index != -1) && fdata && do_tessface ? &fdata->layers[face_index] : NULL;
- if (cdlp->name != new_name) {
+ if (cdlu->name != new_name) {
/* Mesh validate passes a name from the CD layer as the new name,
* Avoid memcpy from self to self in this case.
*/
- BLI_strncpy(cdlp->name, new_name, sizeof(cdlp->name));
- CustomData_set_layer_unique_name(pdata, cdlp - pdata->layers);
+ BLI_strncpy(cdlu->name, new_name, sizeof(cdlu->name));
+ CustomData_set_layer_unique_name(ldata, loop_index);
}
- /* Loop until we do have exactly the same name for all layers! */
- for (i = 1; !STREQ(cdlp->name, cdlu->name) || (cdlf && !STREQ(cdlp->name, cdlf->name)); i++) {
- switch (i % step) {
- case 0:
- BLI_strncpy(cdlp->name, cdlu->name, sizeof(cdlp->name));
- CustomData_set_layer_unique_name(pdata, cdlp - pdata->layers);
- break;
- case 1:
- BLI_strncpy(cdlu->name, cdlp->name, sizeof(cdlu->name));
- CustomData_set_layer_unique_name(ldata, cdlu - ldata->layers);
- break;
- case 2:
- if (cdlf) {
- BLI_strncpy(cdlf->name, cdlp->name, sizeof(cdlf->name));
- CustomData_set_layer_unique_name(fdata, cdlf - fdata->layers);
- }
- break;
- }
+ if (cdlf == NULL) {
+ return false;
}
+ BLI_strncpy(cdlf->name, cdlu->name, sizeof(cdlf->name));
+ CustomData_set_layer_unique_name(fdata, face_index);
+
return true;
}
bool BKE_mesh_uv_cdlayer_rename(Mesh *me, const char *old_name, const char *new_name, bool do_tessface)
{
- CustomData *pdata, *ldata, *fdata;
+ CustomData *ldata, *fdata;
if (me->edit_btmesh) {
- pdata = &me->edit_btmesh->bm->pdata;
ldata = &me->edit_btmesh->bm->ldata;
/* No tessellated data in BMesh! */
fdata = NULL;
do_tessface = false;
}
else {
- pdata = &me->pdata;
ldata = &me->ldata;
fdata = &me->fdata;
do_tessface = (do_tessface && fdata->totlayer);
}
{
- const int pidx_start = CustomData_get_layer_index(pdata, CD_MTEXPOLY);
const int lidx_start = CustomData_get_layer_index(ldata, CD_MLOOPUV);
const int fidx_start = do_tessface ? CustomData_get_layer_index(fdata, CD_MTFACE) : -1;
- int pidx = CustomData_get_named_layer(pdata, CD_MTEXPOLY, old_name);
int lidx = CustomData_get_named_layer(ldata, CD_MLOOPUV, old_name);
int fidx = do_tessface ? CustomData_get_named_layer(fdata, CD_MTFACE, old_name) : -1;
/* None of those cases should happen, in theory!
* Note this assume we have the same number of mtexpoly, mloopuv and mtface layers!
*/
- if (pidx == -1) {
- if (lidx == -1) {
- if (fidx == -1) {
- /* No layer found with this name! */
- return false;
- }
- else {
- lidx = fidx;
- }
+ if (lidx == -1) {
+ if (fidx == -1) {
+ /* No layer found with this name! */
+ return false;
}
- pidx = lidx;
- }
- else {
- if (lidx == -1) {
- lidx = pidx;
- }
- if (fidx == -1 && do_tessface) {
- fidx = pidx;
+ else {
+ lidx = fidx;
}
}
-#if 0
- /* For now, we do not consider mismatch in indices (i.e. same name leading to (relative) different indices). */
- else if (pidx != lidx) {
- lidx = pidx;
- }
-#endif
/* Go back to absolute indices! */
- pidx += pidx_start;
lidx += lidx_start;
if (fidx != -1)
fidx += fidx_start;
- return BKE_mesh_uv_cdlayer_rename_index(me, pidx, lidx, fidx, new_name, do_tessface);
+ return BKE_mesh_uv_cdlayer_rename_index(me, lidx, fidx, new_name, do_tessface);
}
}
@@ -760,6 +867,18 @@ void BKE_mesh_texspace_get(Mesh *me, float r_loc[3], float r_rot[3], float r_siz
if (r_size) copy_v3_v3(r_size, me->size);
}
+void BKE_mesh_texspace_get_reference(Mesh *me, short **r_texflag, float **r_loc, float **r_rot, float **r_size)
+{
+ if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
+ BKE_mesh_texspace_calc(me);
+ }
+
+ if (r_texflag != NULL) *r_texflag = &me->texflag;
+ if (r_loc != NULL) *r_loc = me->loc;
+ if (r_rot != NULL) *r_rot = me->rot;
+ if (r_size != NULL) *r_size = me->size;
+}
+
void BKE_mesh_texspace_copy_from_object(Mesh *me, Object *ob)
{
float *texloc, *texrot, *texsize;
@@ -1383,7 +1502,6 @@ void BKE_mesh_from_nurbs_displist(Object *ob, ListBase *dispbase, const bool use
if (alluv) {
const char *uvname = "Orco";
- me->mtpoly = CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, uvname);
me->mloopuv = CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_ASSIGN, alluv, me->totloop, uvname);
}
@@ -1603,10 +1721,10 @@ void BKE_mesh_to_curve_nurblist(DerivedMesh *dm, ListBase *nurblist, const int e
}
}
-void BKE_mesh_to_curve(Scene *scene, Object *ob)
+void BKE_mesh_to_curve(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
/* make new mesh data from the original copy */
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_MESH);
+ DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_MESH);
ListBase nurblist = {NULL, NULL};
bool needsFree = false;
@@ -2388,13 +2506,13 @@ void BKE_mesh_split_faces(Mesh *mesh, bool free_loop_normals)
/* settings: 1 - preview, 2 - render */
Mesh *BKE_mesh_new_from_object(
- Main *bmain, Scene *sce, Object *ob,
- int apply_modifiers, int settings, int calc_tessface, int calc_undeformed)
+ Depsgraph *depsgraph, Main *bmain, Scene *sce, Object *ob,
+ int apply_modifiers, int calc_tessface, int calc_undeformed)
{
Mesh *tmpmesh;
Curve *tmpcu = NULL, *copycu;
int i;
- const bool render = (settings == eModifierMode_Render);
+ const bool render = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
const bool cage = !apply_modifiers;
bool do_mat_id_data_us = true;
@@ -2447,7 +2565,7 @@ Mesh *BKE_mesh_new_from_object(
copycu->editnurb = tmpcu->editnurb;
/* get updated display list, and convert to a mesh */
- BKE_displist_make_curveTypes_forRender(sce, tmpobj, &dispbase, &derivedFinal, false, render);
+ BKE_displist_make_curveTypes_forRender(depsgraph, sce, tmpobj, &dispbase, &derivedFinal, false, render);
copycu->editfont = NULL;
copycu->editnurb = NULL;
@@ -2496,13 +2614,7 @@ Mesh *BKE_mesh_new_from_object(
if (render) {
ListBase disp = {NULL, NULL};
- /* TODO(sergey): This is gonna to work for until EvaluationContext
- * only contains for_render flag. As soon as CoW is
- * implemented, this is to be rethought.
- */
- EvaluationContext eval_ctx;
- DEG_evaluation_context_init(&eval_ctx, DAG_EVAL_RENDER);
- BKE_displist_make_mball_forRender(&eval_ctx, sce, ob, &disp);
+ BKE_displist_make_mball_forRender(depsgraph, sce, ob, &disp);
BKE_mesh_from_metaball(&disp, tmpmesh);
BKE_displist_free(&disp);
}
@@ -2541,9 +2653,9 @@ Mesh *BKE_mesh_new_from_object(
/* Write the display mesh into the dummy mesh */
if (render)
- dm = mesh_create_derived_render(sce, ob, mask);
+ dm = mesh_create_derived_render(depsgraph, sce, ob, mask);
else
- dm = mesh_create_derived_view(sce, ob, mask);
+ dm = mesh_create_derived_view(depsgraph, sce, ob, mask);
tmpmesh = BKE_mesh_add(bmain, ((ID *)ob->data)->name + 2);
DM_to_mesh(dm, tmpmesh, ob, mask, true);
@@ -2632,13 +2744,31 @@ Mesh *BKE_mesh_new_from_object(
return tmpmesh;
}
+
/* **** Depsgraph evaluation **** */
-void BKE_mesh_eval_geometry(EvaluationContext *UNUSED(eval_ctx),
+void BKE_mesh_eval_geometry(Depsgraph *depsgraph,
Mesh *mesh)
{
- DEG_debug_print_eval(__func__, mesh->id.name, mesh);
+ DEG_debug_print_eval(depsgraph, __func__, mesh->id.name, mesh);
if (mesh->bb == NULL || (mesh->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(mesh);
}
}
+
+/* Draw Engine */
+void (*BKE_mesh_batch_cache_dirty_cb)(Mesh *me, int mode) = NULL;
+void (*BKE_mesh_batch_cache_free_cb)(Mesh *me) = NULL;
+
+void BKE_mesh_batch_cache_dirty(Mesh *me, int mode)
+{
+ if (me->runtime.batch_cache) {
+ BKE_mesh_batch_cache_dirty_cb(me, mode);
+ }
+}
+void BKE_mesh_batch_cache_free(Mesh *me)
+{
+ if (me->runtime.batch_cache) {
+ BKE_mesh_batch_cache_free_cb(me);
+ }
+}
diff --git a/source/blender/blenkernel/intern/mesh_evaluate.c b/source/blender/blenkernel/intern/mesh_evaluate.c
index a67c9de6deb..7c71eeaf069 100644
--- a/source/blender/blenkernel/intern/mesh_evaluate.c
+++ b/source/blender/blenkernel/intern/mesh_evaluate.c
@@ -343,6 +343,7 @@ void BKE_mesh_calc_normals(Mesh *mesh)
#ifdef DEBUG_TIME
TIMEIT_END_AVERAGED(BKE_mesh_calc_normals);
#endif
+ mesh->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
}
void BKE_mesh_calc_normals_tessface(
@@ -1828,152 +1829,6 @@ void BKE_mesh_normals_loop_to_vertex(
/* -------------------------------------------------------------------- */
-/** \name Mesh Tangent Calculations
- * \{ */
-
-/* Tangent space utils. */
-
-/* User data. */
-typedef struct {
- const MPoly *mpolys; /* faces */
- const MLoop *mloops; /* faces's vertices */
- const MVert *mverts; /* vertices */
- const MLoopUV *luvs; /* texture coordinates */
- float (*lnors)[3]; /* loops' normals */
- float (*tangents)[4]; /* output tangents */
- int num_polys; /* number of polygons */
-} BKEMeshToTangent;
-
-/* Mikktspace's API */
-static int get_num_faces(const SMikkTSpaceContext *pContext)
-{
- BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
- return p_mesh->num_polys;
-}
-
-static int get_num_verts_of_face(const SMikkTSpaceContext *pContext, const int face_idx)
-{
- BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
- return p_mesh->mpolys[face_idx].totloop;
-}
-
-static void get_position(const SMikkTSpaceContext *pContext, float r_co[3], const int face_idx, const int vert_idx)
-{
- BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
- const int loop_idx = p_mesh->mpolys[face_idx].loopstart + vert_idx;
- copy_v3_v3(r_co, p_mesh->mverts[p_mesh->mloops[loop_idx].v].co);
-}
-
-static void get_texture_coordinate(const SMikkTSpaceContext *pContext, float r_uv[2], const int face_idx,
- const int vert_idx)
-{
- BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
- copy_v2_v2(r_uv, p_mesh->luvs[p_mesh->mpolys[face_idx].loopstart + vert_idx].uv);
-}
-
-static void get_normal(const SMikkTSpaceContext *pContext, float r_no[3], const int face_idx, const int vert_idx)
-{
- BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
- copy_v3_v3(r_no, p_mesh->lnors[p_mesh->mpolys[face_idx].loopstart + vert_idx]);
-}
-
-static void set_tspace(const SMikkTSpaceContext *pContext, const float fv_tangent[3], const float face_sign,
- const int face_idx, const int vert_idx)
-{
- BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
- float *p_res = p_mesh->tangents[p_mesh->mpolys[face_idx].loopstart + vert_idx];
- copy_v3_v3(p_res, fv_tangent);
- p_res[3] = face_sign;
-}
-
-/**
- * Compute simplified tangent space normals, i.e. tangent vector + sign of bi-tangent one, which combined with
- * split normals can be used to recreate the full tangent space.
- * Note: * The mesh should be made of only tris and quads!
- */
-void BKE_mesh_loop_tangents_ex(
- const MVert *mverts, const int UNUSED(numVerts), const MLoop *mloops,
- float (*r_looptangent)[4], float (*loopnors)[3], const MLoopUV *loopuvs,
- const int UNUSED(numLoops), const MPoly *mpolys, const int numPolys,
- ReportList *reports)
-{
- BKEMeshToTangent mesh_to_tangent = {NULL};
- SMikkTSpaceContext s_context = {NULL};
- SMikkTSpaceInterface s_interface = {NULL};
-
- const MPoly *mp;
- int mp_index;
-
- /* First check we do have a tris/quads only mesh. */
- for (mp = mpolys, mp_index = 0; mp_index < numPolys; mp++, mp_index++) {
- if (mp->totloop > 4) {
- BKE_report(reports, RPT_ERROR, "Tangent space can only be computed for tris/quads, aborting");
- return;
- }
- }
-
- /* Compute Mikktspace's tangent normals. */
- mesh_to_tangent.mpolys = mpolys;
- mesh_to_tangent.mloops = mloops;
- mesh_to_tangent.mverts = mverts;
- mesh_to_tangent.luvs = loopuvs;
- mesh_to_tangent.lnors = loopnors;
- mesh_to_tangent.tangents = r_looptangent;
- mesh_to_tangent.num_polys = numPolys;
-
- s_context.m_pUserData = &mesh_to_tangent;
- s_context.m_pInterface = &s_interface;
- s_interface.m_getNumFaces = get_num_faces;
- s_interface.m_getNumVerticesOfFace = get_num_verts_of_face;
- s_interface.m_getPosition = get_position;
- s_interface.m_getTexCoord = get_texture_coordinate;
- s_interface.m_getNormal = get_normal;
- s_interface.m_setTSpaceBasic = set_tspace;
-
- /* 0 if failed */
- if (genTangSpaceDefault(&s_context) == false) {
- BKE_report(reports, RPT_ERROR, "Mikktspace failed to generate tangents for this mesh!");
- }
-}
-
-/**
- * Wrapper around BKE_mesh_loop_tangents_ex, which takes care of most boiling code.
- * \note
- * - There must be a valid loop's CD_NORMALS available.
- * - The mesh should be made of only tris and quads!
- */
-void BKE_mesh_loop_tangents(Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], ReportList *reports)
-{
- MLoopUV *loopuvs;
- float (*loopnors)[3];
-
- /* Check we have valid texture coordinates first! */
- if (uvmap) {
- loopuvs = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvmap);
- }
- else {
- loopuvs = CustomData_get_layer(&mesh->ldata, CD_MLOOPUV);
- }
- if (!loopuvs) {
- BKE_reportf(reports, RPT_ERROR, "Tangent space computation needs an UVMap, \"%s\" not found, aborting", uvmap);
- return;
- }
-
- loopnors = CustomData_get_layer(&mesh->ldata, CD_NORMAL);
- if (!loopnors) {
- BKE_report(reports, RPT_ERROR, "Tangent space computation needs loop normals, none found, aborting");
- return;
- }
-
- BKE_mesh_loop_tangents_ex(mesh->mvert, mesh->totvert, mesh->mloop, r_looptangents,
- loopnors, loopuvs, mesh->totloop, mesh->mpoly, mesh->totpoly, reports);
-}
-
-/** \} */
-
-
-/* -------------------------------------------------------------------- */
-
/** \name Polygon Calculations
* \{ */
@@ -2545,12 +2400,12 @@ void BKE_mesh_calc_volume(
*/
void BKE_mesh_loops_to_mface_corners(
CustomData *fdata, CustomData *ldata,
- CustomData *pdata, unsigned int lindex[4], int findex,
- const int polyindex,
+ CustomData *UNUSED(pdata), unsigned int lindex[4], int findex,
+ const int UNUSED(polyindex),
const int mf_len, /* 3 or 4 */
/* cache values to avoid lookups every time */
- const int numTex, /* CustomData_number_of_layers(pdata, CD_MTEXPOLY) */
+ const int numUV, /* CustomData_number_of_layers(ldata, CD_MLOOPUV) */
const int numCol, /* CustomData_number_of_layers(ldata, CD_MLOOPCOL) */
const bool hasPCol, /* CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL) */
const bool hasOrigSpace, /* CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP) */
@@ -2558,17 +2413,13 @@ void BKE_mesh_loops_to_mface_corners(
)
{
MTFace *texface;
- MTexPoly *texpoly;
MCol *mcol;
MLoopCol *mloopcol;
MLoopUV *mloopuv;
int i, j;
- for (i = 0; i < numTex; i++) {
+ for (i = 0; i < numUV; i++) {
texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
- texpoly = CustomData_get_n(pdata, CD_MTEXPOLY, polyindex, i);
-
- ME_MTEXFACE_CPY(texface, texpoly);
for (j = 0; j < mf_len; j++) {
mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, (int)lindex[j], i);
@@ -2620,14 +2471,14 @@ void BKE_mesh_loops_to_mface_corners(
*
* \note when mface is not NULL, mface[face_index].v4 is used to test quads, else, loopindices[face_index][3] is used.
*/
-void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData *pdata, MFace *mface,
+void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, MFace *mface,
int *polyindices, unsigned int (*loopindices)[4], const int num_faces)
{
/* Note: performances are sub-optimal when we get a NULL mface, we could be ~25% quicker with dedicated code...
* Issue is, unless having two different functions with nearly the same code, there's not much ways to solve
* this. Better imho to live with it for now. :/ --mont29
*/
- const int numTex = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
+ const int numUV = CustomData_number_of_layers(ldata, CD_MLOOPUV);
const int numCol = CustomData_number_of_layers(ldata, CD_MLOOPCOL);
const bool hasPCol = CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL);
const bool hasOrigSpace = CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP);
@@ -2637,17 +2488,14 @@ void BKE_mesh_loops_to_tessdata(CustomData *fdata, CustomData *ldata, CustomData
const int *pidx;
unsigned int (*lidx)[4];
- for (i = 0; i < numTex; i++) {
+ for (i = 0; i < numUV; i++) {
MTFace *texface = CustomData_get_layer_n(fdata, CD_MTFACE, i);
- MTexPoly *texpoly = CustomData_get_layer_n(pdata, CD_MTEXPOLY, i);
MLoopUV *mloopuv = CustomData_get_layer_n(ldata, CD_MLOOPUV, i);
for (findex = 0, pidx = polyindices, lidx = loopindices;
findex < num_faces;
pidx++, lidx++, findex++, texface++)
{
- ME_MTEXFACE_CPY(texface, &texpoly[*pidx]);
-
for (j = (mface ? mface[findex].v4 : (*lidx)[3]) ? 4 : 3; j--;) {
copy_v2_v2(texface->uv[j], mloopuv[(*lidx)[j]].uv);
}
@@ -2970,7 +2818,7 @@ int BKE_mesh_recalc_tessellation(
/* CD_ORIGINDEX will contain an array of indices from tessfaces to the polygons
* they are directly tessellated from */
CustomData_add_layer(fdata, CD_ORIGINDEX, CD_ASSIGN, mface_to_poly_map, totface);
- CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
+ CustomData_from_bmeshpoly(fdata, ldata, totface);
if (do_face_nor_copy) {
/* If polys have a normals layer, copying that to faces can help
@@ -2991,7 +2839,7 @@ int BKE_mesh_recalc_tessellation(
* So we pass NULL as MFace pointer, and BKE_mesh_loops_to_tessdata will use the fourth loop index as quad test.
* ...
*/
- BKE_mesh_loops_to_tessdata(fdata, ldata, pdata, NULL, mface_to_poly_map, lindices, totface);
+ BKE_mesh_loops_to_tessdata(fdata, ldata, NULL, mface_to_poly_map, lindices, totface);
/* NOTE: quad detection issue - fourth vertidx vs fourth loopidx:
* ...However, most TFace code uses 'MFace->v4 == 0' test to check whether it is a tri or quad.
@@ -3183,7 +3031,7 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
MPoly *mp, *mpoly;
MFace *mface, *mf;
- const int numTex = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
+ const int numUV = CustomData_number_of_layers(ldata, CD_MLOOPUV);
const int numCol = CustomData_number_of_layers(ldata, CD_MLOOPCOL);
const bool hasPCol = CustomData_has_layer(ldata, CD_PREVIEW_MLOOPCOL);
const bool hasOrigSpace = CustomData_has_layer(ldata, CD_ORIGSPACE_MLOOP);
@@ -3223,7 +3071,7 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
CustomData_add_layer(fdata, CD_MFACE, CD_ASSIGN, mface, totface);
- CustomData_from_bmeshpoly(fdata, pdata, ldata, totface);
+ CustomData_from_bmeshpoly(fdata, ldata, totface);
mp = mpoly;
k = 0;
@@ -3245,9 +3093,10 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
mf->v2 = mloop[mf->v2].v;
mf->v3 = mloop[mf->v3].v;
- BKE_mesh_loops_to_mface_corners(fdata, ldata, pdata,
- lindex, k, i, 3,
- numTex, numCol, hasPCol, hasOrigSpace, hasLNor);
+ BKE_mesh_loops_to_mface_corners(
+ fdata, ldata, pdata,
+ lindex, k, i, 3,
+ numUV, numCol, hasPCol, hasOrigSpace, hasLNor);
test_index_face(mf, fdata, k, 3);
}
else {
@@ -3265,9 +3114,10 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
mf->v3 = mloop[mf->v3].v;
mf->v4 = mloop[mf->v4].v;
- BKE_mesh_loops_to_mface_corners(fdata, ldata, pdata,
- lindex, k, i, 4,
- numTex, numCol, hasPCol, hasOrigSpace, hasLNor);
+ BKE_mesh_loops_to_mface_corners(
+ fdata, ldata, pdata,
+ lindex, k, i, 4,
+ numUV, numCol, hasPCol, hasOrigSpace, hasLNor);
test_index_face(mf, fdata, k, 4);
}
@@ -3282,11 +3132,11 @@ int BKE_mesh_mpoly_to_mface(struct CustomData *fdata, struct CustomData *ldata,
#endif /* USE_BMESH_SAVE_AS_COMPAT */
-static void bm_corners_to_loops_ex(ID *id, CustomData *fdata, CustomData *ldata, CustomData *pdata,
- MFace *mface, int totloop, int findex, int loopstart, int numTex, int numCol)
+static void bm_corners_to_loops_ex(
+ ID *id, CustomData *fdata, CustomData *ldata,
+ MFace *mface, int totloop, int findex, int loopstart, int numTex, int numCol)
{
MTFace *texface;
- MTexPoly *texpoly;
MCol *mcol;
MLoopCol *mloopcol;
MLoopUV *mloopuv;
@@ -3297,9 +3147,6 @@ static void bm_corners_to_loops_ex(ID *id, CustomData *fdata, CustomData *ldata,
for (i = 0; i < numTex; i++) {
texface = CustomData_get_n(fdata, CD_MTFACE, findex, i);
- texpoly = CustomData_get_n(pdata, CD_MTEXPOLY, findex, i);
-
- ME_MTEXFACE_CPY(texpoly, texface);
mloopuv = CustomData_get_n(ldata, CD_MLOOPUV, loopstart, i);
copy_v2_v2(mloopuv->uv, texface->uv[0]); mloopuv++;
@@ -3406,7 +3253,7 @@ void BKE_mesh_do_versions_convert_mfaces_to_mpolys(Mesh *mesh)
mesh->medge, mesh->mface,
&mesh->totloop, &mesh->totpoly, &mesh->mloop, &mesh->mpoly);
- CustomData_bmesh_do_versions_update_active_layers(&mesh->fdata, &mesh->pdata, &mesh->ldata);
+ CustomData_bmesh_do_versions_update_active_layers(&mesh->fdata, &mesh->ldata);
BKE_mesh_update_customdata_pointers(mesh, true);
}
@@ -3449,7 +3296,7 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id, CustomData *fdata, CustomData
CustomData_add_layer(ldata, CD_MLOOP, CD_ASSIGN, mloop, totloop);
- CustomData_to_bmeshpoly(fdata, pdata, ldata, totloop, totpoly);
+ CustomData_to_bmeshpoly(fdata, ldata, totloop);
if (id) {
/* ensure external data is transferred */
@@ -3499,7 +3346,7 @@ void BKE_mesh_convert_mfaces_to_mpolys_ex(ID *id, CustomData *fdata, CustomData
# undef ML
- bm_corners_to_loops_ex(id, fdata, ldata, pdata, mface, totloop, i, mp->loopstart, numTex, numCol);
+ bm_corners_to_loops_ex(id, fdata, ldata, mface, totloop, i, mp->loopstart, numTex, numCol);
if (polyindex) {
*polyindex = i;
diff --git a/source/blender/blenkernel/intern/mesh_merge.c b/source/blender/blenkernel/intern/mesh_merge.c
new file mode 100644
index 00000000000..899de970fdd
--- /dev/null
+++ b/source/blender/blenkernel/intern/mesh_merge.c
@@ -0,0 +1,684 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/mesh_merge.c
+ * \ingroup bke
+ */
+#include <string.h> // for memcpy
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_utildefines_stack.h"
+#include "BLI_edgehash.h"
+#include "BLI_ghash.h"
+
+#include "BKE_customdata.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_mapping.h"
+
+
+/**
+ * Poly compare with vtargetmap
+ * Function used by #BKE_mesh_merge_verts.
+ * The function compares poly_source after applying vtargetmap, with poly_target.
+ * The two polys are identical if they share the same vertices in the same order, or in reverse order,
+ * but starting position loopstart may be different.
+ * The function is called with direct_reverse=1 for same order (i.e. same normal),
+ * and may be called again with direct_reverse=-1 for reverse order.
+ * \return 1 if polys are identical, 0 if polys are different.
+ */
+static int cddm_poly_compare(
+ MLoop *mloop_array,
+ MPoly *mpoly_source, MPoly *mpoly_target,
+ const int *vtargetmap, const int direct_reverse)
+{
+ int vert_source, first_vert_source, vert_target;
+ int i_loop_source;
+ int i_loop_target, i_loop_target_start, i_loop_target_offset, i_loop_target_adjusted;
+ bool compare_completed = false;
+ bool same_loops = false;
+
+ MLoop *mloop_source, *mloop_target;
+
+ BLI_assert(direct_reverse == 1 || direct_reverse == -1);
+
+ i_loop_source = 0;
+ mloop_source = mloop_array + mpoly_source->loopstart;
+ vert_source = mloop_source->v;
+
+ if (vtargetmap[vert_source] != -1) {
+ vert_source = vtargetmap[vert_source];
+ }
+ else {
+ /* All source loop vertices should be mapped */
+ BLI_assert(false);
+ }
+
+ /* Find same vertex within mpoly_target's loops */
+ mloop_target = mloop_array + mpoly_target->loopstart;
+ for (i_loop_target = 0; i_loop_target < mpoly_target->totloop; i_loop_target++, mloop_target++) {
+ if (mloop_target->v == vert_source) {
+ break;
+ }
+ }
+
+ /* If same vertex not found, then polys cannot be equal */
+ if (i_loop_target >= mpoly_target->totloop) {
+ return false;
+ }
+
+ /* Now mloop_source and m_loop_target have one identical vertex */
+ /* mloop_source is at position 0, while m_loop_target has advanced to find identical vertex */
+ /* Go around the loop and check that all vertices match in same order */
+ /* Skipping source loops when consecutive source vertices are mapped to same target vertex */
+
+ i_loop_target_start = i_loop_target;
+ i_loop_target_offset = 0;
+ first_vert_source = vert_source;
+
+ compare_completed = false;
+ same_loops = false;
+
+ while (!compare_completed) {
+
+ vert_target = mloop_target->v;
+
+ /* First advance i_loop_source, until it points to different vertex, after mapping applied */
+ do {
+ i_loop_source++;
+
+ if (i_loop_source == mpoly_source->totloop) {
+ /* End of loops for source, must match end of loop for target. */
+ if (i_loop_target_offset == mpoly_target->totloop - 1) {
+ compare_completed = true;
+ same_loops = true;
+ break; /* Polys are identical */
+ }
+ else {
+ compare_completed = true;
+ same_loops = false;
+ break; /* Polys are different */
+ }
+ }
+
+ mloop_source++;
+ vert_source = mloop_source->v;
+
+ if (vtargetmap[vert_source] != -1) {
+ vert_source = vtargetmap[vert_source];
+ }
+ else {
+ /* All source loop vertices should be mapped */
+ BLI_assert(false);
+ }
+
+ } while (vert_source == vert_target);
+
+ if (compare_completed) {
+ break;
+ }
+
+ /* Now advance i_loop_target as well */
+ i_loop_target_offset++;
+
+ if (i_loop_target_offset == mpoly_target->totloop) {
+ /* End of loops for target only, that means no match */
+ /* except if all remaining source vertices are mapped to first target */
+ for (; i_loop_source < mpoly_source->totloop; i_loop_source++, mloop_source++) {
+ vert_source = vtargetmap[mloop_source->v];
+ if (vert_source != first_vert_source) {
+ compare_completed = true;
+ same_loops = false;
+ break;
+ }
+ }
+ if (!compare_completed) {
+ same_loops = true;
+ }
+ break;
+ }
+
+ /* Adjust i_loop_target for cycling around and for direct/reverse order defined by delta = +1 or -1 */
+ i_loop_target_adjusted = (i_loop_target_start + direct_reverse * i_loop_target_offset) % mpoly_target->totloop;
+ if (i_loop_target_adjusted < 0) {
+ i_loop_target_adjusted += mpoly_target->totloop;
+ }
+ mloop_target = mloop_array + mpoly_target->loopstart + i_loop_target_adjusted;
+ vert_target = mloop_target->v;
+
+ if (vert_target != vert_source) {
+ same_loops = false; /* Polys are different */
+ break;
+ }
+ }
+ return same_loops;
+}
+
+
+/* Utility stuff for using GHash with polys, used by vertex merging. */
+
+typedef struct PolyKey {
+ int poly_index; /* index of the MPoly within the derived mesh */
+ int totloops; /* number of loops in the poly */
+ unsigned int hash_sum; /* Sum of all vertices indices */
+ unsigned int hash_xor; /* Xor of all vertices indices */
+} PolyKey;
+
+
+static unsigned int poly_gset_hash_fn(const void *key)
+{
+ const PolyKey *pk = key;
+ return pk->hash_sum;
+}
+
+static bool poly_gset_compare_fn(const void *k1, const void *k2)
+{
+ const PolyKey *pk1 = k1;
+ const PolyKey *pk2 = k2;
+ if ((pk1->hash_sum == pk2->hash_sum) &&
+ (pk1->hash_xor == pk2->hash_xor) &&
+ (pk1->totloops == pk2->totloops))
+ {
+ /* Equality - note that this does not mean equality of polys */
+ return false;
+ }
+ else {
+ return true;
+ }
+}
+
+/**
+ * Merge Verts
+ *
+ * This frees the given mesh and returns a new mesh.
+ *
+ * \param vtargetmap The table that maps vertices to target vertices. a value of -1
+ * indicates a vertex is a target, and is to be kept.
+ * This array is aligned with 'mesh->totvert'
+ * \warning \a vtargetmap must **not** contain any chained mapping (v1 -> v2 -> v3 etc.), this is not supported
+ * and will likely generate corrupted geometry.
+ *
+ * \param tot_vtargetmap The number of non '-1' values in vtargetmap. (not the size)
+ *
+ * \param merge_mode enum with two modes.
+ * - #MESH_MERGE_VERTS_DUMP_IF_MAPPED
+ * When called by the Mirror Modifier,
+ * In this mode it skips any faces that have all vertices merged (to avoid creating pairs
+ * of faces sharing the same set of vertices)
+ * - #MESH_MERGE_VERTS_DUMP_IF_EQUAL
+ * When called by the Array Modifier,
+ * In this mode, faces where all vertices are merged are double-checked,
+ * to see whether all target vertices actually make up a poly already.
+ * Indeed it could be that all of a poly's vertices are merged,
+ * but merged to vertices that do not make up a single poly,
+ * in which case the original poly should not be dumped.
+ * Actually this later behavior could apply to the Mirror Modifier as well, but the additional checks are
+ * costly and not necessary in the case of mirror, because each vertex is only merged to its own mirror.
+ *
+ * \note #BKE_mesh_recalc_tessellation has to run on the returned DM if you want to access tessfaces.
+ */
+Mesh *BKE_mesh_merge_verts(Mesh *mesh, const int *vtargetmap, const int tot_vtargetmap, const int merge_mode)
+{
+ /* This was commented out back in 2013, see commit f45d8827bafe6b9eaf9de42f4054e9d84a21955d. */
+// #define USE_LOOPS
+
+ Mesh *result = NULL;
+
+ const int totvert = mesh->totvert;
+ const int totedge = mesh->totedge;
+ const int totloop = mesh->totloop;
+ const int totpoly = mesh->totpoly;
+
+ const int totvert_final = totvert - tot_vtargetmap;
+
+ MVert *mv, *mvert = MEM_malloc_arrayN(totvert_final, sizeof(*mvert), __func__);
+ int *oldv = MEM_malloc_arrayN(totvert_final, sizeof(*oldv), __func__);
+ int *newv = MEM_malloc_arrayN(totvert, sizeof(*newv), __func__);
+ STACK_DECLARE(mvert);
+ STACK_DECLARE(oldv);
+
+ /* Note: create (totedge + totloop) elements because partially invalid polys due to merge may require
+ * generating new edges, and while in 99% cases we'll still end with less final edges than totedge,
+ * cases can be forged that would end requiring more... */
+ MEdge *med, *medge = MEM_malloc_arrayN((totedge + totloop), sizeof(*medge), __func__);
+ int *olde = MEM_malloc_arrayN((totedge + totloop), sizeof(*olde), __func__);
+ int *newe = MEM_malloc_arrayN((totedge + totloop), sizeof(*newe), __func__);
+ STACK_DECLARE(medge);
+ STACK_DECLARE(olde);
+
+ MLoop *ml, *mloop = MEM_malloc_arrayN(totloop, sizeof(*mloop), __func__);
+ int *oldl = MEM_malloc_arrayN(totloop, sizeof(*oldl), __func__);
+#ifdef USE_LOOPS
+ int *newl = MEM_malloc_arrayN(totloop, sizeof(*newl), __func__);
+#endif
+ STACK_DECLARE(mloop);
+ STACK_DECLARE(oldl);
+
+ MPoly *mp, *mpoly = MEM_malloc_arrayN(totpoly, sizeof(*medge), __func__);
+ int *oldp = MEM_malloc_arrayN(totpoly, sizeof(*oldp), __func__);
+ STACK_DECLARE(mpoly);
+ STACK_DECLARE(oldp);
+
+ EdgeHash *ehash = BLI_edgehash_new_ex(__func__, totedge);
+
+ int i, j, c;
+
+ PolyKey *poly_keys;
+ GSet *poly_gset = NULL;
+ MeshElemMap *poly_map = NULL;
+ int *poly_map_mem = NULL;
+
+ STACK_INIT(oldv, totvert_final);
+ STACK_INIT(olde, totedge);
+ STACK_INIT(oldl, totloop);
+ STACK_INIT(oldp, totpoly);
+
+ STACK_INIT(mvert, totvert_final);
+ STACK_INIT(medge, totedge);
+ STACK_INIT(mloop, totloop);
+ STACK_INIT(mpoly, totpoly);
+
+ /* fill newv with destination vertex indices */
+ mv = mesh->mvert;
+ c = 0;
+ for (i = 0; i < totvert; i++, mv++) {
+ if (vtargetmap[i] == -1) {
+ STACK_PUSH(oldv, i);
+ STACK_PUSH(mvert, *mv);
+ newv[i] = c++;
+ }
+ else {
+ /* dummy value */
+ newv[i] = 0;
+ }
+ }
+
+ /* now link target vertices to destination indices */
+ for (i = 0; i < totvert; i++) {
+ if (vtargetmap[i] != -1) {
+ newv[i] = newv[vtargetmap[i]];
+ }
+ }
+
+ /* Don't remap vertices in cddm->mloop, because we need to know the original
+ * indices in order to skip faces with all vertices merged.
+ * The "update loop indices..." section further down remaps vertices in mloop.
+ */
+
+ /* now go through and fix edges and faces */
+ med = mesh->medge;
+ c = 0;
+ for (i = 0; i < totedge; i++, med++) {
+ const unsigned int v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1;
+ const unsigned int v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2;
+ if (LIKELY(v1 != v2)) {
+ void **val_p;
+
+ if (BLI_edgehash_ensure_p(ehash, v1, v2, &val_p)) {
+ newe[i] = GET_INT_FROM_POINTER(*val_p);
+ }
+ else {
+ STACK_PUSH(olde, i);
+ STACK_PUSH(medge, *med);
+ newe[i] = c;
+ *val_p = SET_INT_IN_POINTER(c);
+ c++;
+ }
+ }
+ else {
+ newe[i] = -1;
+ }
+ }
+
+ if (merge_mode == MESH_MERGE_VERTS_DUMP_IF_EQUAL) {
+ /* In this mode, we need to determine, whenever a poly' vertices are all mapped */
+ /* if the targets already make up a poly, in which case the new poly is dropped */
+ /* This poly equality check is rather complex. We use a BLI_ghash to speed it up with a first level check */
+ PolyKey *mpgh;
+ poly_keys = MEM_malloc_arrayN(totpoly, sizeof(PolyKey), __func__);
+ poly_gset = BLI_gset_new_ex(poly_gset_hash_fn, poly_gset_compare_fn, __func__, totpoly);
+ /* Duplicates allowed because our compare function is not pure equality */
+ BLI_gset_flag_set(poly_gset, GHASH_FLAG_ALLOW_DUPES);
+
+ mp = mesh->mpoly;
+ mpgh = poly_keys;
+ for (i = 0; i < totpoly; i++, mp++, mpgh++) {
+ mpgh->poly_index = i;
+ mpgh->totloops = mp->totloop;
+ ml = mesh->mloop + mp->loopstart;
+ mpgh->hash_sum = mpgh->hash_xor = 0;
+ for (j = 0; j < mp->totloop; j++, ml++) {
+ mpgh->hash_sum += ml->v;
+ mpgh->hash_xor ^= ml->v;
+ }
+ BLI_gset_insert(poly_gset, mpgh);
+ }
+
+ /* Can we optimise by reusing an old pmap ? How do we know an old pmap is stale ? */
+ /* When called by MOD_array.c, the cddm has just been created, so it has no valid pmap. */
+ BKE_mesh_vert_poly_map_create(&poly_map, &poly_map_mem,
+ mesh->mpoly, mesh->mloop,
+ totvert, totpoly, totloop);
+ } /* done preparing for fast poly compare */
+
+
+ mp = mesh->mpoly;
+ mv = mesh->mvert;
+ for (i = 0; i < totpoly; i++, mp++) {
+ MPoly *mp_new;
+
+ ml = mesh->mloop + mp->loopstart;
+
+ /* check faces with all vertices merged */
+ bool all_vertices_merged = true;
+
+ for (j = 0; j < mp->totloop; j++, ml++) {
+ if (vtargetmap[ml->v] == -1) {
+ all_vertices_merged = false;
+ /* This will be used to check for poly using several time the same vert. */
+ mv[ml->v].flag &= ~ME_VERT_TMP_TAG;
+ }
+ else {
+ /* This will be used to check for poly using several time the same vert. */
+ mv[vtargetmap[ml->v]].flag &= ~ME_VERT_TMP_TAG;
+ }
+ }
+
+ if (UNLIKELY(all_vertices_merged)) {
+ if (merge_mode == MESH_MERGE_VERTS_DUMP_IF_MAPPED) {
+ /* In this mode, all vertices merged is enough to dump face */
+ continue;
+ }
+ else if (merge_mode == MESH_MERGE_VERTS_DUMP_IF_EQUAL) {
+ /* Additional condition for face dump: target vertices must make up an identical face */
+ /* The test has 2 steps: (1) first step is fast ghash lookup, but not failproof */
+ /* (2) second step is thorough but more costly poly compare */
+ int i_poly, v_target;
+ bool found = false;
+ PolyKey pkey;
+
+ /* Use poly_gset for fast (although not 100% certain) identification of same poly */
+ /* First, make up a poly_summary structure */
+ ml = mesh->mloop + mp->loopstart;
+ pkey.hash_sum = pkey.hash_xor = 0;
+ pkey.totloops = 0;
+ for (j = 0; j < mp->totloop; j++, ml++) {
+ v_target = vtargetmap[ml->v]; /* Cannot be -1, they are all mapped */
+ pkey.hash_sum += v_target;
+ pkey.hash_xor ^= v_target;
+ pkey.totloops++;
+ }
+ if (BLI_gset_haskey(poly_gset, &pkey)) {
+
+ /* There might be a poly that matches this one.
+ * We could just leave it there and say there is, and do a "continue".
+ * ... but we are checking whether there is an exact poly match.
+ * It's not so costly in terms of CPU since it's very rare, just a lot of complex code.
+ */
+
+ /* Consider current loop again */
+ ml = mesh->mloop + mp->loopstart;
+ /* Consider the target of the loop's first vert */
+ v_target = vtargetmap[ml->v];
+ /* Now see if v_target belongs to a poly that shares all vertices with source poly,
+ * in same order, or reverse order */
+
+ for (i_poly = 0; i_poly < poly_map[v_target].count; i_poly++) {
+ MPoly *target_poly = mesh->mpoly + *(poly_map[v_target].indices + i_poly);
+
+ if (cddm_poly_compare(mesh->mloop, mp, target_poly, vtargetmap, +1) ||
+ cddm_poly_compare(mesh->mloop, mp, target_poly, vtargetmap, -1))
+ {
+ found = true;
+ break;
+ }
+ }
+ if (found) {
+ /* Current poly's vertices are mapped to a poly that is strictly identical */
+ /* Current poly is dumped */
+ continue;
+ }
+ }
+ }
+ }
+
+
+ /* Here either the poly's vertices were not all merged
+ * or they were all merged, but targets do not make up an identical poly,
+ * the poly is retained.
+ */
+ ml = mesh->mloop + mp->loopstart;
+
+ c = 0;
+ MLoop *last_valid_ml = NULL;
+ MLoop *first_valid_ml = NULL;
+ bool need_edge_from_last_valid_ml = false;
+ bool need_edge_to_first_valid_ml = false;
+ int created_edges = 0;
+ for (j = 0; j < mp->totloop; j++, ml++) {
+ const uint mlv = (vtargetmap[ml->v] != -1) ? vtargetmap[ml->v] : ml->v;
+#ifndef NDEBUG
+ {
+ MLoop *next_ml = mesh->mloop + mp->loopstart + ((j + 1) % mp->totloop);
+ uint next_mlv = (vtargetmap[next_ml->v] != -1) ? vtargetmap[next_ml->v] : next_ml->v;
+ med = mesh->medge + ml->e;
+ uint v1 = (vtargetmap[med->v1] != -1) ? vtargetmap[med->v1] : med->v1;
+ uint v2 = (vtargetmap[med->v2] != -1) ? vtargetmap[med->v2] : med->v2;
+ BLI_assert((mlv == v1 && next_mlv == v2) || (mlv == v2 && next_mlv == v1));
+ }
+#endif
+ /* A loop is only valid if its matching edge is, and it's not reusing a vertex already used by this poly. */
+ if (LIKELY((newe[ml->e] != -1) && ((mv[mlv].flag & ME_VERT_TMP_TAG) == 0))) {
+ mv[mlv].flag |= ME_VERT_TMP_TAG;
+
+ if (UNLIKELY(last_valid_ml != NULL && need_edge_from_last_valid_ml)) {
+ /* We need to create a new edge between last valid loop and this one! */
+ void **val_p;
+
+ uint v1 = (vtargetmap[last_valid_ml->v] != -1) ? vtargetmap[last_valid_ml->v] : last_valid_ml->v;
+ uint v2 = mlv;
+ BLI_assert(v1 != v2);
+ if (BLI_edgehash_ensure_p(ehash, v1, v2, &val_p)) {
+ last_valid_ml->e = GET_INT_FROM_POINTER(*val_p);
+ }
+ else {
+ const int new_eidx = STACK_SIZE(medge);
+ STACK_PUSH(olde, olde[last_valid_ml->e]);
+ STACK_PUSH(medge, mesh->medge[last_valid_ml->e]);
+ medge[new_eidx].v1 = last_valid_ml->v;
+ medge[new_eidx].v2 = ml->v;
+ /* DO NOT change newe mapping, could break actual values due to some deleted original edges. */
+ *val_p = SET_INT_IN_POINTER(new_eidx);
+ created_edges++;
+
+ last_valid_ml->e = new_eidx;
+ }
+ need_edge_from_last_valid_ml = false;
+ }
+
+#ifdef USE_LOOPS
+ newl[j + mp->loopstart] = STACK_SIZE(mloop);
+#endif
+ STACK_PUSH(oldl, j + mp->loopstart);
+ last_valid_ml = STACK_PUSH_RET_PTR(mloop);
+ *last_valid_ml = *ml;
+ if (first_valid_ml == NULL) {
+ first_valid_ml = last_valid_ml;
+ }
+ c++;
+
+ /* We absolutely HAVE to handle edge index remapping here, otherwise potential newly created edges
+ * in that part of code make remapping later totally unreliable. */
+ BLI_assert(newe[ml->e] != -1);
+ last_valid_ml->e = newe[ml->e];
+ }
+ else {
+ if (last_valid_ml != NULL) {
+ need_edge_from_last_valid_ml = true;
+ }
+ else {
+ need_edge_to_first_valid_ml = true;
+ }
+ }
+ }
+ if (UNLIKELY(last_valid_ml != NULL && !ELEM(first_valid_ml, NULL, last_valid_ml) &&
+ (need_edge_to_first_valid_ml || need_edge_from_last_valid_ml)))
+ {
+ /* We need to create a new edge between last valid loop and first valid one! */
+ void **val_p;
+
+ uint v1 = (vtargetmap[last_valid_ml->v] != -1) ? vtargetmap[last_valid_ml->v] : last_valid_ml->v;
+ uint v2 = (vtargetmap[first_valid_ml->v] != -1) ? vtargetmap[first_valid_ml->v] : first_valid_ml->v;
+ BLI_assert(v1 != v2);
+ if (BLI_edgehash_ensure_p(ehash, v1, v2, &val_p)) {
+ last_valid_ml->e = GET_INT_FROM_POINTER(*val_p);
+ }
+ else {
+ const int new_eidx = STACK_SIZE(medge);
+ STACK_PUSH(olde, olde[last_valid_ml->e]);
+ STACK_PUSH(medge, mesh->medge[last_valid_ml->e]);
+ medge[new_eidx].v1 = last_valid_ml->v;
+ medge[new_eidx].v2 = first_valid_ml->v;
+ /* DO NOT change newe mapping, could break actual values due to some deleted original edges. */
+ *val_p = SET_INT_IN_POINTER(new_eidx);
+ created_edges++;
+
+ last_valid_ml->e = new_eidx;
+ }
+ need_edge_to_first_valid_ml = need_edge_from_last_valid_ml = false;
+ }
+
+ if (UNLIKELY(c == 0)) {
+ BLI_assert(created_edges == 0);
+ continue;
+ }
+ else if (UNLIKELY(c < 3)) {
+ STACK_DISCARD(oldl, c);
+ STACK_DISCARD(mloop, c);
+ if (created_edges > 0) {
+ for (j = STACK_SIZE(medge) - created_edges; j < STACK_SIZE(medge); j++) {
+ BLI_edgehash_remove(ehash, medge[j].v1, medge[j].v2, NULL);
+ }
+ STACK_DISCARD(olde, created_edges);
+ STACK_DISCARD(medge, created_edges);
+ }
+ continue;
+ }
+
+ mp_new = STACK_PUSH_RET_PTR(mpoly);
+ *mp_new = *mp;
+ mp_new->totloop = c;
+ BLI_assert(mp_new->totloop >= 3);
+ mp_new->loopstart = STACK_SIZE(mloop) - c;
+
+ STACK_PUSH(oldp, i);
+ } /* end of the loop that tests polys */
+
+
+ if (poly_gset) {
+ // printf("hash quality %.6f\n", BLI_gset_calc_quality(poly_gset));
+
+ BLI_gset_free(poly_gset, NULL);
+ MEM_freeN(poly_keys);
+ }
+
+ /*create new cddm*/
+ result = BKE_mesh_from_template(
+ mesh, STACK_SIZE(mvert), STACK_SIZE(medge), 0, STACK_SIZE(mloop), STACK_SIZE(mpoly));
+
+ /*update edge indices and copy customdata*/
+ med = medge;
+ for (i = 0; i < result->totedge; i++, med++) {
+ BLI_assert(newv[med->v1] != -1);
+ med->v1 = newv[med->v1];
+ BLI_assert(newv[med->v2] != -1);
+ med->v2 = newv[med->v2];
+
+ /* Can happen in case vtargetmap contains some double chains, we do not support that. */
+ BLI_assert(med->v1 != med->v2);
+
+ CustomData_copy_data(&mesh->edata, &result->edata, olde[i], i, 1);
+ }
+
+ /*update loop indices and copy customdata*/
+ ml = mloop;
+ for (i = 0; i < result->totloop; i++, ml++) {
+ /* Edge remapping has already be done in main loop handling part above. */
+ BLI_assert(newv[ml->v] != -1);
+ ml->v = newv[ml->v];
+
+ CustomData_copy_data(&mesh->ldata, &result->ldata, oldl[i], i, 1);
+ }
+
+ /*copy vertex customdata*/
+ mv = mvert;
+ for (i = 0; i < result->totvert; i++, mv++) {
+ CustomData_copy_data(&mesh->vdata, &result->vdata, oldv[i], i, 1);
+ }
+
+ /*copy poly customdata*/
+ mp = mpoly;
+ for (i = 0; i < result->totpoly; i++, mp++) {
+ CustomData_copy_data(&mesh->pdata, &result->pdata, oldp[i], i, 1);
+ }
+
+ /*copy over data. CustomData_add_layer can do this, need to look it up.*/
+ memcpy(result->mvert, mvert, sizeof(MVert) * STACK_SIZE(mvert));
+ memcpy(result->medge, medge, sizeof(MEdge) * STACK_SIZE(medge));
+ memcpy(result->mloop, mloop, sizeof(MLoop) * STACK_SIZE(mloop));
+ memcpy(result->mpoly, mpoly, sizeof(MPoly) * STACK_SIZE(mpoly));
+
+ MEM_freeN(mvert);
+ MEM_freeN(medge);
+ MEM_freeN(mloop);
+ MEM_freeN(mpoly);
+
+ MEM_freeN(newv);
+ MEM_freeN(newe);
+#ifdef USE_LOOPS
+ MEM_freeN(newl);
+#endif
+
+ MEM_freeN(oldv);
+ MEM_freeN(olde);
+ MEM_freeN(oldl);
+ MEM_freeN(oldp);
+
+ BLI_edgehash_free(ehash, NULL);
+
+ if (poly_map != NULL)
+ MEM_freeN(poly_map);
+ if (poly_map_mem != NULL)
+ MEM_freeN(poly_map_mem);
+
+ BKE_id_free(NULL, mesh);
+
+ return result;
+}
diff --git a/source/blender/blenkernel/intern/mesh_tangent.c b/source/blender/blenkernel/intern/mesh_tangent.c
new file mode 100644
index 00000000000..05a5a5e8703
--- /dev/null
+++ b/source/blender/blenkernel/intern/mesh_tangent.c
@@ -0,0 +1,691 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/mesh_tangent.c
+ * \ingroup bke
+ *
+ * Functions to evaluate mesh tangents.
+ */
+
+#include <limits.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+#include "BLI_stack.h"
+#include "BLI_task.h"
+
+#include "BKE_customdata.h"
+#include "BKE_global.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_tangent.h"
+#include "BKE_report.h"
+
+#include "BLI_strict_flags.h"
+
+#include "atomic_ops.h"
+#include "mikktspace.h"
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Mesh Tangent Calculations (Single Layer)
+ * \{ */
+
+/* Tangent space utils. */
+
+/* User data. */
+typedef struct {
+ const MPoly *mpolys; /* faces */
+ const MLoop *mloops; /* faces's vertices */
+ const MVert *mverts; /* vertices */
+ const MLoopUV *luvs; /* texture coordinates */
+ float (*lnors)[3]; /* loops' normals */
+ float (*tangents)[4]; /* output tangents */
+ int num_polys; /* number of polygons */
+} BKEMeshToTangent;
+
+/* Mikktspace's API */
+static int get_num_faces(const SMikkTSpaceContext *pContext)
+{
+ BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
+ return p_mesh->num_polys;
+}
+
+static int get_num_verts_of_face(const SMikkTSpaceContext *pContext, const int face_idx)
+{
+ BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
+ return p_mesh->mpolys[face_idx].totloop;
+}
+
+static void get_position(const SMikkTSpaceContext *pContext, float r_co[3], const int face_idx, const int vert_idx)
+{
+ BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
+ const int loop_idx = p_mesh->mpolys[face_idx].loopstart + vert_idx;
+ copy_v3_v3(r_co, p_mesh->mverts[p_mesh->mloops[loop_idx].v].co);
+}
+
+static void get_texture_coordinate(const SMikkTSpaceContext *pContext, float r_uv[2], const int face_idx,
+ const int vert_idx)
+{
+ BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
+ copy_v2_v2(r_uv, p_mesh->luvs[p_mesh->mpolys[face_idx].loopstart + vert_idx].uv);
+}
+
+static void get_normal(const SMikkTSpaceContext *pContext, float r_no[3], const int face_idx, const int vert_idx)
+{
+ BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
+ copy_v3_v3(r_no, p_mesh->lnors[p_mesh->mpolys[face_idx].loopstart + vert_idx]);
+}
+
+static void set_tspace(const SMikkTSpaceContext *pContext, const float fv_tangent[3], const float face_sign,
+ const int face_idx, const int vert_idx)
+{
+ BKEMeshToTangent *p_mesh = (BKEMeshToTangent *)pContext->m_pUserData;
+ float *p_res = p_mesh->tangents[p_mesh->mpolys[face_idx].loopstart + vert_idx];
+ copy_v3_v3(p_res, fv_tangent);
+ p_res[3] = face_sign;
+}
+
+/**
+ * Compute simplified tangent space normals, i.e. tangent vector + sign of bi-tangent one, which combined with
+ * split normals can be used to recreate the full tangent space.
+ * Note: * The mesh should be made of only tris and quads!
+ */
+void BKE_mesh_calc_loop_tangent_single_ex(
+ const MVert *mverts, const int UNUSED(numVerts), const MLoop *mloops,
+ float (*r_looptangent)[4], float (*loopnors)[3], const MLoopUV *loopuvs,
+ const int UNUSED(numLoops), const MPoly *mpolys, const int numPolys,
+ ReportList *reports)
+{
+ BKEMeshToTangent mesh_to_tangent = {NULL};
+ SMikkTSpaceContext s_context = {NULL};
+ SMikkTSpaceInterface s_interface = {NULL};
+
+ const MPoly *mp;
+ int mp_index;
+
+ /* First check we do have a tris/quads only mesh. */
+ for (mp = mpolys, mp_index = 0; mp_index < numPolys; mp++, mp_index++) {
+ if (mp->totloop > 4) {
+ BKE_report(reports, RPT_ERROR, "Tangent space can only be computed for tris/quads, aborting");
+ return;
+ }
+ }
+
+ /* Compute Mikktspace's tangent normals. */
+ mesh_to_tangent.mpolys = mpolys;
+ mesh_to_tangent.mloops = mloops;
+ mesh_to_tangent.mverts = mverts;
+ mesh_to_tangent.luvs = loopuvs;
+ mesh_to_tangent.lnors = loopnors;
+ mesh_to_tangent.tangents = r_looptangent;
+ mesh_to_tangent.num_polys = numPolys;
+
+ s_context.m_pUserData = &mesh_to_tangent;
+ s_context.m_pInterface = &s_interface;
+ s_interface.m_getNumFaces = get_num_faces;
+ s_interface.m_getNumVerticesOfFace = get_num_verts_of_face;
+ s_interface.m_getPosition = get_position;
+ s_interface.m_getTexCoord = get_texture_coordinate;
+ s_interface.m_getNormal = get_normal;
+ s_interface.m_setTSpaceBasic = set_tspace;
+
+ /* 0 if failed */
+ if (genTangSpaceDefault(&s_context) == false) {
+ BKE_report(reports, RPT_ERROR, "Mikktspace failed to generate tangents for this mesh!");
+ }
+}
+
+/**
+ * Wrapper around BKE_mesh_calc_loop_tangent_single_ex, which takes care of most boiling code.
+ * \note
+ * - There must be a valid loop's CD_NORMALS available.
+ * - The mesh should be made of only tris and quads!
+ */
+void BKE_mesh_calc_loop_tangent_single(Mesh *mesh, const char *uvmap, float (*r_looptangents)[4], ReportList *reports)
+{
+ MLoopUV *loopuvs;
+ float (*loopnors)[3];
+
+ /* Check we have valid texture coordinates first! */
+ if (uvmap) {
+ loopuvs = CustomData_get_layer_named(&mesh->ldata, CD_MLOOPUV, uvmap);
+ }
+ else {
+ loopuvs = CustomData_get_layer(&mesh->ldata, CD_MLOOPUV);
+ }
+ if (!loopuvs) {
+ BKE_reportf(reports, RPT_ERROR, "Tangent space computation needs an UVMap, \"%s\" not found, aborting", uvmap);
+ return;
+ }
+
+ loopnors = CustomData_get_layer(&mesh->ldata, CD_NORMAL);
+ if (!loopnors) {
+ BKE_report(reports, RPT_ERROR, "Tangent space computation needs loop normals, none found, aborting");
+ return;
+ }
+
+ BKE_mesh_calc_loop_tangent_single_ex(mesh->mvert, mesh->totvert, mesh->mloop, r_looptangents,
+ loopnors, loopuvs, mesh->totloop, mesh->mpoly, mesh->totpoly, reports);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Mesh Tangent Calculations (All Layers)
+ * \{ */
+
+
+/* Necessary complexity to handle looptri's as quads for correct tangents */
+#define USE_LOOPTRI_DETECT_QUADS
+
+typedef struct {
+ const float (*precomputedFaceNormals)[3];
+ const float (*precomputedLoopNormals)[3];
+ const MLoopTri *looptri;
+ MLoopUV *mloopuv; /* texture coordinates */
+ const MPoly *mpoly; /* indices */
+ const MLoop *mloop; /* indices */
+ const MVert *mvert; /* vertices & normals */
+ const float (*orco)[3];
+ float (*tangent)[4]; /* destination */
+ int numTessFaces;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ /* map from 'fake' face index to looptri,
+ * quads will point to the first looptri of the quad */
+ const int *face_as_quad_map;
+ int num_face_as_quad_map;
+#endif
+
+} SGLSLMeshToTangent;
+
+/* interface */
+static int dm_ts_GetNumFaces(const SMikkTSpaceContext *pContext)
+{
+ SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ return pMesh->num_face_as_quad_map;
+#else
+ return pMesh->numTessFaces;
+#endif
+}
+
+static int dm_ts_GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
+{
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
+ if (pMesh->face_as_quad_map) {
+ const MLoopTri *lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
+ const MPoly *mp = &pMesh->mpoly[lt->poly];
+ if (mp->totloop == 4) {
+ return 4;
+ }
+ }
+ return 3;
+#else
+ UNUSED_VARS(pContext, face_num);
+ return 3;
+#endif
+}
+
+static void dm_ts_GetPosition(
+ const SMikkTSpaceContext *pContext, float r_co[3],
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
+ const MLoopTri *lt;
+ uint loop_index;
+ const float *co;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
+ const MPoly *mp = &pMesh->mpoly[lt->poly];
+ if (mp->totloop == 4) {
+ loop_index = (uint)(mp->loopstart + vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = &pMesh->looptri[face_num];
+ }
+#else
+ lt = &pMesh->looptri[face_num];
+#endif
+ loop_index = lt->tri[vert_index];
+
+finally:
+ co = pMesh->mvert[pMesh->mloop[loop_index].v].co;
+ copy_v3_v3(r_co, co);
+}
+
+static void dm_ts_GetTextureCoordinate(
+ const SMikkTSpaceContext *pContext, float r_uv[2],
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLMeshToTangent *pMesh = pContext->m_pUserData;
+ const MLoopTri *lt;
+ uint loop_index;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
+ const MPoly *mp = &pMesh->mpoly[lt->poly];
+ if (mp->totloop == 4) {
+ loop_index = (uint)(mp->loopstart + vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = &pMesh->looptri[face_num];
+ }
+#else
+ lt = &pMesh->looptri[face_num];
+#endif
+ loop_index = lt->tri[vert_index];
+
+finally:
+ if (pMesh->mloopuv != NULL) {
+ const float *uv = pMesh->mloopuv[loop_index].uv;
+ copy_v2_v2(r_uv, uv);
+ }
+ else {
+ const float *orco = pMesh->orco[pMesh->mloop[loop_index].v];
+ map_to_sphere(&r_uv[0], &r_uv[1], orco[0], orco[1], orco[2]);
+ }
+}
+
+static void dm_ts_GetNormal(
+ const SMikkTSpaceContext *pContext, float r_no[3],
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
+ const MLoopTri *lt;
+ uint loop_index;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
+ const MPoly *mp = &pMesh->mpoly[lt->poly];
+ if (mp->totloop == 4) {
+ loop_index = (uint)(mp->loopstart + vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = &pMesh->looptri[face_num];
+ }
+#else
+ lt = &pMesh->looptri[face_num];
+#endif
+ loop_index = lt->tri[vert_index];
+
+finally:
+ if (pMesh->precomputedLoopNormals) {
+ copy_v3_v3(r_no, pMesh->precomputedLoopNormals[loop_index]);
+ }
+ else if ((pMesh->mpoly[lt->poly].flag & ME_SMOOTH) == 0) { /* flat */
+ if (pMesh->precomputedFaceNormals) {
+ copy_v3_v3(r_no, pMesh->precomputedFaceNormals[lt->poly]);
+ }
+ else {
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ const MPoly *mp = &pMesh->mpoly[lt->poly];
+ if (mp->totloop == 4) {
+ normal_quad_v3(
+ r_no,
+ pMesh->mvert[pMesh->mloop[mp->loopstart + 0].v].co,
+ pMesh->mvert[pMesh->mloop[mp->loopstart + 1].v].co,
+ pMesh->mvert[pMesh->mloop[mp->loopstart + 2].v].co,
+ pMesh->mvert[pMesh->mloop[mp->loopstart + 3].v].co);
+ }
+ else
+#endif
+ {
+ normal_tri_v3(
+ r_no,
+ pMesh->mvert[pMesh->mloop[lt->tri[0]].v].co,
+ pMesh->mvert[pMesh->mloop[lt->tri[1]].v].co,
+ pMesh->mvert[pMesh->mloop[lt->tri[2]].v].co);
+ }
+ }
+ }
+ else {
+ const short *no = pMesh->mvert[pMesh->mloop[loop_index].v].no;
+ normal_short_to_float_v3(r_no, no);
+ }
+}
+
+static void dm_ts_SetTSpace(
+ const SMikkTSpaceContext *pContext, const float fvTangent[3], const float fSign,
+ const int face_num, const int vert_index)
+{
+ //assert(vert_index >= 0 && vert_index < 4);
+ SGLSLMeshToTangent *pMesh = (SGLSLMeshToTangent *) pContext->m_pUserData;
+ const MLoopTri *lt;
+ uint loop_index;
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (pMesh->face_as_quad_map) {
+ lt = &pMesh->looptri[pMesh->face_as_quad_map[face_num]];
+ const MPoly *mp = &pMesh->mpoly[lt->poly];
+ if (mp->totloop == 4) {
+ loop_index = (uint)(mp->loopstart + vert_index);
+ goto finally;
+ }
+ /* fall through to regular triangle */
+ }
+ else {
+ lt = &pMesh->looptri[face_num];
+ }
+#else
+ lt = &pMesh->looptri[face_num];
+#endif
+ loop_index = lt->tri[vert_index];
+
+ float *pRes;
+
+finally:
+ pRes = pMesh->tangent[loop_index];
+ copy_v3_v3(pRes, fvTangent);
+ pRes[3] = fSign;
+}
+
+static void DM_calc_loop_tangents_thread(TaskPool * __restrict UNUSED(pool), void *taskdata, int UNUSED(threadid))
+{
+ struct SGLSLMeshToTangent *mesh2tangent = taskdata;
+ /* new computation method */
+ {
+ SMikkTSpaceContext sContext = {NULL};
+ SMikkTSpaceInterface sInterface = {NULL};
+
+ sContext.m_pUserData = mesh2tangent;
+ sContext.m_pInterface = &sInterface;
+ sInterface.m_getNumFaces = dm_ts_GetNumFaces;
+ sInterface.m_getNumVerticesOfFace = dm_ts_GetNumVertsOfFace;
+ sInterface.m_getPosition = dm_ts_GetPosition;
+ sInterface.m_getTexCoord = dm_ts_GetTextureCoordinate;
+ sInterface.m_getNormal = dm_ts_GetNormal;
+ sInterface.m_setTSpaceBasic = dm_ts_SetTSpace;
+
+ /* 0 if failed */
+ genTangSpaceDefault(&sContext);
+ }
+}
+
+void BKE_mesh_add_loop_tangent_named_layer_for_uv(
+ CustomData *uv_data, CustomData *tan_data, int numLoopData,
+ const char *layer_name)
+{
+ if (CustomData_get_named_layer_index(tan_data, CD_TANGENT, layer_name) == -1 &&
+ CustomData_get_named_layer_index(uv_data, CD_MLOOPUV, layer_name) != -1)
+ {
+ CustomData_add_layer_named(
+ tan_data, CD_TANGENT, CD_CALLOC, NULL,
+ numLoopData, layer_name);
+ }
+}
+
+/**
+ * Here we get some useful information such as active uv layer name and search if it is already in tangent_names.
+ * Also, we calculate tangent_mask that works as a descriptor of tangents state.
+ * If tangent_mask has changed, then recalculate tangents.
+ */
+void BKE_mesh_calc_loop_tangent_step_0(
+ const CustomData *loopData, bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_count,
+ bool *rcalc_act, bool *rcalc_ren, int *ract_uv_n, int *rren_uv_n,
+ char *ract_uv_name, char *rren_uv_name, short *rtangent_mask)
+{
+ /* Active uv in viewport */
+ int layer_index = CustomData_get_layer_index(loopData, CD_MLOOPUV);
+ *ract_uv_n = CustomData_get_active_layer(loopData, CD_MLOOPUV);
+ ract_uv_name[0] = 0;
+ if (*ract_uv_n != -1) {
+ strcpy(ract_uv_name, loopData->layers[*ract_uv_n + layer_index].name);
+ }
+
+ /* Active tangent in render */
+ *rren_uv_n = CustomData_get_render_layer(loopData, CD_MLOOPUV);
+ rren_uv_name[0] = 0;
+ if (*rren_uv_n != -1) {
+ strcpy(rren_uv_name, loopData->layers[*rren_uv_n + layer_index].name);
+ }
+
+ /* If active tangent not in tangent_names we take it into account */
+ *rcalc_act = false;
+ *rcalc_ren = false;
+ for (int i = 0; i < tangent_names_count; i++) {
+ if (tangent_names[i][0] == 0) {
+ calc_active_tangent = true;
+ }
+ }
+ if (calc_active_tangent) {
+ *rcalc_act = true;
+ *rcalc_ren = true;
+ for (int i = 0; i < tangent_names_count; i++) {
+ if (STREQ(ract_uv_name, tangent_names[i]))
+ *rcalc_act = false;
+ if (STREQ(rren_uv_name, tangent_names[i]))
+ *rcalc_ren = false;
+ }
+ }
+ *rtangent_mask = 0;
+
+ const int uv_layer_num = CustomData_number_of_layers(loopData, CD_MLOOPUV);
+ for (int n = 0; n < uv_layer_num; n++) {
+ const char *name = CustomData_get_layer_name(loopData, CD_MLOOPUV, n);
+ bool add = false;
+ for (int i = 0; i < tangent_names_count; i++) {
+ if (tangent_names[i][0] && STREQ(tangent_names[i], name)) {
+ add = true;
+ break;
+ }
+ }
+ if (!add && ((*rcalc_act && ract_uv_name[0] && STREQ(ract_uv_name, name)) ||
+ (*rcalc_ren && rren_uv_name[0] && STREQ(rren_uv_name, name))))
+ {
+ add = true;
+ }
+ if (add)
+ *rtangent_mask |= (short)(1 << n);
+ }
+
+ if (uv_layer_num == 0)
+ *rtangent_mask |= DM_TANGENT_MASK_ORCO;
+}
+
+/**
+ * See: #BKE_editmesh_loop_tangent_calc (matching logic).
+ */
+void BKE_mesh_calc_loop_tangent_ex(
+ const MVert *mvert,
+ const MPoly *mpoly, const uint mpoly_len,
+ const MLoop *mloop,
+ const MLoopTri *looptri,
+ const uint looptri_len,
+
+ CustomData *loopdata,
+ bool calc_active_tangent,
+ const char (*tangent_names)[MAX_NAME], int tangent_names_len,
+ const float (*poly_normals)[3],
+ const float (*loop_normals)[3],
+ const float (*vert_orco)[3],
+ /* result */
+ CustomData *loopdata_out,
+ const uint loopdata_out_len,
+ short *tangent_mask_curr_p)
+{
+ int act_uv_n = -1;
+ int ren_uv_n = -1;
+ bool calc_act = false;
+ bool calc_ren = false;
+ char act_uv_name[MAX_NAME];
+ char ren_uv_name[MAX_NAME];
+ short tangent_mask = 0;
+ short tangent_mask_curr = *tangent_mask_curr_p;
+
+ BKE_mesh_calc_loop_tangent_step_0(
+ loopdata, calc_active_tangent, tangent_names, tangent_names_len,
+ &calc_act, &calc_ren, &act_uv_n, &ren_uv_n, act_uv_name, ren_uv_name, &tangent_mask);
+ if ((tangent_mask_curr | tangent_mask) != tangent_mask_curr) {
+ /* Check we have all the needed layers */
+ /* Allocate needed tangent layers */
+ for (int i = 0; i < tangent_names_len; i++)
+ if (tangent_names[i][0])
+ BKE_mesh_add_loop_tangent_named_layer_for_uv(loopdata, loopdata_out, (int)loopdata_out_len, tangent_names[i]);
+ if ((tangent_mask & DM_TANGENT_MASK_ORCO) && CustomData_get_named_layer_index(loopdata, CD_TANGENT, "") == -1)
+ CustomData_add_layer_named(loopdata_out, CD_TANGENT, CD_CALLOC, NULL, (int)loopdata_out_len, "");
+ if (calc_act && act_uv_name[0])
+ BKE_mesh_add_loop_tangent_named_layer_for_uv(loopdata, loopdata_out, (int)loopdata_out_len, act_uv_name);
+ if (calc_ren && ren_uv_name[0])
+ BKE_mesh_add_loop_tangent_named_layer_for_uv(loopdata, loopdata_out, (int)loopdata_out_len, ren_uv_name);
+
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ int num_face_as_quad_map;
+ int *face_as_quad_map = NULL;
+
+ /* map faces to quads */
+ if (looptri_len != mpoly_len) {
+ /* over alloc, since we dont know how many ngon or quads we have */
+
+ /* map fake face index to looptri */
+ face_as_quad_map = MEM_mallocN(sizeof(int) * looptri_len, __func__);
+ int k, j;
+ for (k = 0, j = 0; j < (int)looptri_len; k++, j++) {
+ face_as_quad_map[k] = j;
+ /* step over all quads */
+ if (mpoly[looptri[j].poly].totloop == 4) {
+ j++; /* skips the nest looptri */
+ }
+ }
+ num_face_as_quad_map = k;
+ }
+ else {
+ num_face_as_quad_map = (int)looptri_len;
+ }
+#endif
+
+ /* Calculation */
+ if (looptri_len != 0) {
+ TaskScheduler *scheduler = BLI_task_scheduler_get();
+ TaskPool *task_pool;
+ task_pool = BLI_task_pool_create(scheduler, NULL);
+
+ tangent_mask_curr = 0;
+ /* Calculate tangent layers */
+ SGLSLMeshToTangent data_array[MAX_MTFACE];
+ const int tangent_layer_num = CustomData_number_of_layers(loopdata_out, CD_TANGENT);
+ for (int n = 0; n < tangent_layer_num; n++) {
+ int index = CustomData_get_layer_index_n(loopdata_out, CD_TANGENT, n);
+ BLI_assert(n < MAX_MTFACE);
+ SGLSLMeshToTangent *mesh2tangent = &data_array[n];
+ mesh2tangent->numTessFaces = (int)looptri_len;
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ mesh2tangent->face_as_quad_map = face_as_quad_map;
+ mesh2tangent->num_face_as_quad_map = num_face_as_quad_map;
+#endif
+ mesh2tangent->mvert = mvert;
+ mesh2tangent->mpoly = mpoly;
+ mesh2tangent->mloop = mloop;
+ mesh2tangent->looptri = looptri;
+ /* Note, we assume we do have tessellated loop normals at this point (in case it is object-enabled),
+ * have to check this is valid...
+ */
+ mesh2tangent->precomputedLoopNormals = loop_normals;
+ mesh2tangent->precomputedFaceNormals = poly_normals;
+
+ mesh2tangent->orco = NULL;
+ mesh2tangent->mloopuv = CustomData_get_layer_named(loopdata, CD_MLOOPUV, loopdata_out->layers[index].name);
+
+ /* Fill the resulting tangent_mask */
+ if (!mesh2tangent->mloopuv) {
+ mesh2tangent->orco = vert_orco;
+ if (!mesh2tangent->orco)
+ continue;
+
+ tangent_mask_curr |= DM_TANGENT_MASK_ORCO;
+ }
+ else {
+ int uv_ind = CustomData_get_named_layer_index(loopdata, CD_MLOOPUV, loopdata_out->layers[index].name);
+ int uv_start = CustomData_get_layer_index(loopdata, CD_MLOOPUV);
+ BLI_assert(uv_ind != -1 && uv_start != -1);
+ BLI_assert(uv_ind - uv_start < MAX_MTFACE);
+ tangent_mask_curr |= (short)(1 << (uv_ind - uv_start));
+ }
+
+ mesh2tangent->tangent = loopdata_out->layers[index].data;
+ BLI_task_pool_push(task_pool, DM_calc_loop_tangents_thread, mesh2tangent, false, TASK_PRIORITY_LOW);
+ }
+
+ BLI_assert(tangent_mask_curr == tangent_mask);
+ BLI_task_pool_work_and_wait(task_pool);
+ BLI_task_pool_free(task_pool);
+ }
+ else {
+ tangent_mask_curr = tangent_mask;
+ }
+#ifdef USE_LOOPTRI_DETECT_QUADS
+ if (face_as_quad_map) {
+ MEM_freeN(face_as_quad_map);
+ }
+#undef USE_LOOPTRI_DETECT_QUADS
+
+#endif
+
+ *tangent_mask_curr_p = tangent_mask_curr;
+
+ /* Update active layer index */
+ int act_uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, act_uv_n);
+ if (act_uv_index != -1) {
+ int tan_index = CustomData_get_named_layer_index(loopdata, CD_TANGENT, loopdata->layers[act_uv_index].name);
+ CustomData_set_layer_active_index(loopdata, CD_TANGENT, tan_index);
+ }/* else tangent has been built from orco */
+
+ /* Update render layer index */
+ int ren_uv_index = CustomData_get_layer_index_n(loopdata, CD_MLOOPUV, ren_uv_n);
+ if (ren_uv_index != -1) {
+ int tan_index = CustomData_get_named_layer_index(loopdata, CD_TANGENT, loopdata->layers[ren_uv_index].name);
+ CustomData_set_layer_render_index(loopdata, CD_TANGENT, tan_index);
+ }/* else tangent has been built from orco */
+ }
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/mesh_validate.c b/source/blender/blenkernel/intern/mesh_validate.c
index b0577fdd50d..8301b6a42b1 100644
--- a/source/blender/blenkernel/intern/mesh_validate.c
+++ b/source/blender/blenkernel/intern/mesh_validate.c
@@ -43,10 +43,11 @@
#include "BLI_math_vector.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_mesh.h"
+#include "DEG_depsgraph.h"
+
#include "MEM_guardedalloc.h"
/* loop v/e are unsigned, so using max uint_32 value as invalid marker... */
@@ -936,7 +937,7 @@ bool BKE_mesh_validate_all_customdata(CustomData *vdata, CustomData *edata,
{
bool is_valid = true;
bool is_change_v, is_change_e, is_change_l, is_change_p;
- int tot_texpoly, tot_uvloop, tot_vcolloop;
+ int tot_uvloop, tot_vcolloop;
CustomDataMask mask = check_meshmask ? CD_MASK_MESH : 0;
is_valid &= mesh_validate_customdata(vdata, mask, do_verbose, do_fixes, &is_change_v);
@@ -944,17 +945,8 @@ bool BKE_mesh_validate_all_customdata(CustomData *vdata, CustomData *edata,
is_valid &= mesh_validate_customdata(ldata, mask, do_verbose, do_fixes, &is_change_l);
is_valid &= mesh_validate_customdata(pdata, mask, do_verbose, do_fixes, &is_change_p);
- tot_texpoly = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
tot_uvloop = CustomData_number_of_layers(ldata, CD_MLOOPUV);
tot_vcolloop = CustomData_number_of_layers(ldata, CD_MLOOPCOL);
- if (tot_texpoly != tot_uvloop) {
- PRINT_ERR("\tCustomDataLayer mismatch, tot_texpoly(%d), tot_uvloop(%d)\n",
- tot_texpoly, tot_uvloop);
- }
- if (tot_texpoly > MAX_MTFACE) {
- PRINT_ERR("\tMore UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n",
- MAX_MTFACE, tot_texpoly - MAX_MTFACE);
- }
if (tot_uvloop > MAX_MTFACE) {
PRINT_ERR("\tMore UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n",
MAX_MTFACE, tot_uvloop - MAX_MTFACE);
@@ -965,18 +957,10 @@ bool BKE_mesh_validate_all_customdata(CustomData *vdata, CustomData *edata,
}
/* check indices of clone/stencil */
- if (do_fixes && CustomData_get_clone_layer(pdata, CD_MTEXPOLY) >= tot_texpoly) {
- CustomData_set_layer_clone(pdata, CD_MTEXPOLY, 0);
- is_change_p = true;
- }
if (do_fixes && CustomData_get_clone_layer(ldata, CD_MLOOPUV) >= tot_uvloop) {
CustomData_set_layer_clone(ldata, CD_MLOOPUV, 0);
is_change_l = true;
}
- if (do_fixes && CustomData_get_stencil_layer(pdata, CD_MTEXPOLY) >= tot_texpoly) {
- CustomData_set_layer_stencil(pdata, CD_MTEXPOLY, 0);
- is_change_p = true;
- }
if (do_fixes && CustomData_get_stencil_layer(ldata, CD_MLOOPUV) >= tot_uvloop) {
CustomData_set_layer_stencil(ldata, CD_MLOOPUV, 0);
is_change_l = true;
@@ -1019,7 +1003,7 @@ int BKE_mesh_validate(Mesh *me, const int do_verbose, const int cddata_check_mas
&changed);
if (changed) {
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&me->id, OB_RECALC_DATA);
return true;
}
else {
@@ -1028,64 +1012,6 @@ int BKE_mesh_validate(Mesh *me, const int do_verbose, const int cddata_check_mas
}
/**
- * Duplicate of BM_mesh_cd_validate() for Mesh data.
- */
-void BKE_mesh_cd_validate(Mesh *me)
-{
- int totlayer_mtex = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
- int totlayer_uv = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
- int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
- int mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY);
- int uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV);
- int i;
-
- /* XXX For now, do not delete those, just warn they are not really usable. */
- if (UNLIKELY(totlayer_mtex > MAX_MTFACE)) {
- printf("WARNING! More UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n",
- MAX_MTFACE, totlayer_mtex - MAX_MTFACE);
- }
- if (UNLIKELY(totlayer_uv > MAX_MTFACE)) {
- printf("WARNING! More UV layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n",
- MAX_MTFACE, totlayer_uv - MAX_MTFACE);
- }
- if (UNLIKELY(totlayer_mcol > MAX_MCOL)) {
- printf("WARNING! More VCol layers than %d allowed, %d last ones won't be available for render, shaders, etc.\n",
- MAX_MCOL, totlayer_mcol - MAX_MCOL);
- }
-
- if (LIKELY(totlayer_mtex == totlayer_uv)) {
- /* pass */
- }
- else if (totlayer_mtex < totlayer_uv) {
- do {
- const char *from_name = me->ldata.layers[uv_index + totlayer_mtex].name;
- CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, from_name);
- CustomData_set_layer_unique_name(&me->pdata, totlayer_mtex);
- } while (totlayer_uv != ++totlayer_mtex);
- mtex_index = CustomData_get_layer_index(&me->pdata, CD_MTEXPOLY);
- }
- else if (totlayer_uv < totlayer_mtex) {
- do {
- const char *from_name = me->pdata.layers[mtex_index + totlayer_uv].name;
- CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, from_name);
- CustomData_set_layer_unique_name(&me->ldata, totlayer_uv);
- } while (totlayer_mtex != ++totlayer_uv);
- uv_index = CustomData_get_layer_index(&me->ldata, CD_MLOOPUV);
- }
-
- BLI_assert(totlayer_mtex == totlayer_uv);
-
- /* Check uv/tex names match as well!!! */
- for (i = 0; i < totlayer_mtex; i++, mtex_index++, uv_index++) {
- const char *name_src = me->pdata.layers[mtex_index].name;
- const char *name_dst = me->ldata.layers[uv_index].name;
- if (!STREQ(name_src, name_dst)) {
- BKE_mesh_uv_cdlayer_rename_index(me, mtex_index, uv_index, -1, name_src, false);
- }
- }
-}
-
-/**
* Check all material indices of polygons are valid, invalid ones are set to 0.
* \returns is_valid.
*/
@@ -1105,7 +1031,7 @@ int BKE_mesh_validate_material_indices(Mesh *me)
}
if (!is_valid) {
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&me->id, OB_RECALC_DATA);
return true;
}
else {
diff --git a/source/blender/blenkernel/intern/modifier.c b/source/blender/blenkernel/intern/modifier.c
index ce04f3c31e2..29a4fcbb9c7 100644
--- a/source/blender/blenkernel/intern/modifier.c
+++ b/source/blender/blenkernel/intern/modifier.c
@@ -46,6 +46,7 @@
#include "MEM_guardedalloc.h"
#include "DNA_armature_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "BLI_utildefines.h"
@@ -58,9 +59,12 @@
#include "BLT_translation.h"
#include "BKE_appdir.h"
+#include "BKE_cdderivedmesh.h"
+#include "BKE_idcode.h"
#include "BKE_key.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_mesh.h"
#include "BKE_multires.h"
#include "BKE_DerivedMesh.h"
@@ -69,6 +73,8 @@
#include "BKE_main.h"
/* end */
+#include "DEG_depsgraph.h"
+
#include "MOD_modifiertypes.h"
static ModifierTypeInfo *modifier_types[NUM_MODIFIER_TYPES] = {NULL};
@@ -127,6 +133,7 @@ ModifierData *modifier_new(int type)
md->type = type;
md->mode = eModifierMode_Realtime | eModifierMode_Render | eModifierMode_Expanded;
+ md->flag = eModifierFlag_StaticOverride_Local;
if (mti->flags & eModifierTypeFlag_EnableInEditmode)
md->mode |= eModifierMode_Editmode;
@@ -306,6 +313,7 @@ void modifier_copyData_ex(ModifierData *md, ModifierData *target, const int flag
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
target->mode = md->mode;
+ target->flag = md->flag;
if (mti->copyData) {
mti->copyData(md, target);
@@ -679,7 +687,7 @@ bool modifiers_usesArmature(Object *ob, bArmature *arm)
bool modifier_isCorrectableDeformed(ModifierData *md)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
- return (mti->deformMatricesEM != NULL);
+ return (mti->deformMatricesEM != NULL) || (mti->deformMatricesEM_DM != NULL);
}
bool modifiers_isCorrectableDeformed(struct Scene *scene, Object *ob)
@@ -688,9 +696,9 @@ bool modifiers_isCorrectableDeformed(struct Scene *scene, Object *ob)
ModifierData *md = modifiers_getVirtualModifierList(ob, &virtualModifierData);
int required_mode = eModifierMode_Realtime;
- if (ob->mode == OB_MODE_EDIT)
+ if (ob->mode == OB_MODE_EDIT) {
required_mode |= eModifierMode_Editmode;
-
+ }
for (; md; md = md->next) {
if (!modifier_isEnabled(scene, md, required_mode)) {
/* pass */
@@ -784,9 +792,8 @@ void modifier_path_init(char *path, int path_maxlen, const char *name)
/* wrapper around ModifierTypeInfo.applyModifier that ensures valid normals */
struct DerivedMesh *modwrap_applyModifier(
- ModifierData *md, Object *ob,
- struct DerivedMesh *dm,
- ModifierApplyFlag flag)
+ ModifierData *md, const ModifierEvalContext *ctx,
+ struct DerivedMesh *dm)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
@@ -794,14 +801,12 @@ struct DerivedMesh *modwrap_applyModifier(
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
- return mti->applyModifier(md, ob, dm, flag);
+ return modifier_applyModifier_DM_deprecated(md, ctx, dm);
}
struct DerivedMesh *modwrap_applyModifierEM(
- ModifierData *md, Object *ob,
- struct BMEditMesh *em,
- DerivedMesh *dm,
- ModifierApplyFlag flag)
+ ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *em, DerivedMesh *dm)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
@@ -809,14 +814,12 @@ struct DerivedMesh *modwrap_applyModifierEM(
if (mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
- return mti->applyModifierEM(md, ob, em, dm, flag);
+ return modifier_applyModifierEM_DM_deprecated(md, ctx, em, dm);
}
void modwrap_deformVerts(
- ModifierData *md, Object *ob,
- DerivedMesh *dm,
- float (*vertexCos)[3], int numVerts,
- ModifierApplyFlag flag)
+ ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm, float (*vertexCos)[3], int numVerts)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
BLI_assert(!dm || CustomData_has_layer(&dm->polyData, CD_NORMAL) == false);
@@ -824,11 +827,11 @@ void modwrap_deformVerts(
if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
- mti->deformVerts(md, ob, dm, vertexCos, numVerts, flag);
+ modifier_deformVerts_DM_deprecated(md, ctx, dm, vertexCos, numVerts);
}
void modwrap_deformVertsEM(
- ModifierData *md, Object *ob,
+ ModifierData *md, const ModifierEvalContext *ctx,
struct BMEditMesh *em, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
@@ -838,6 +841,319 @@ void modwrap_deformVertsEM(
if (dm && mti->dependsOnNormals && mti->dependsOnNormals(md)) {
DM_ensure_normals(dm);
}
- mti->deformVertsEM(md, ob, em, dm, vertexCos, numVerts);
+ modifier_deformVertsEM_DM_deprecated(md, ctx, em, dm, vertexCos, numVerts);
}
/* end modifier callback wrappers */
+
+
+/* wrappers for modifier callbacks that accept Mesh and select the proper implementation
+ * depending on if the modifier has been ported to Mesh or is still using DerivedMesh
+ */
+
+void modifier_deformVerts(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct Mesh *mesh,
+ float (*vertexCos)[3], int numVerts)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformVerts) {
+ mti->deformVerts(md, ctx, mesh, vertexCos, numVerts);
+ }
+ else {
+ DerivedMesh *dm = NULL;
+ if (mesh) {
+ dm = CDDM_from_mesh(mesh);
+ }
+
+ mti->deformVerts_DM(md, ctx, dm, vertexCos, numVerts);
+
+ if (dm) {
+ dm->release(dm);
+ }
+ }
+}
+
+void modifier_deformMatrices(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct Mesh *mesh,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformMatrices) {
+ mti->deformMatrices(md, ctx, mesh, vertexCos, defMats, numVerts);
+ }
+ else {
+ DerivedMesh *dm = NULL;
+ if (mesh) {
+ dm = CDDM_from_mesh(mesh);
+ }
+
+ mti->deformMatrices_DM(md, ctx, dm, vertexCos, defMats, numVerts);
+
+ if (dm) {
+ dm->release(dm);
+ }
+ }
+}
+
+void modifier_deformVertsEM(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct Mesh *mesh,
+ float (*vertexCos)[3], int numVerts)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformVertsEM) {
+ mti->deformVertsEM(md, ctx, editData, mesh, vertexCos, numVerts);
+ }
+ else {
+ DerivedMesh *dm = NULL;
+ if (mesh) {
+ dm = CDDM_from_mesh(mesh);
+ }
+
+ mti->deformVertsEM_DM(md, ctx, editData, dm, vertexCos, numVerts);
+
+ if (dm) {
+ dm->release(dm);
+ }
+ }
+}
+
+void modifier_deformMatricesEM(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct Mesh *mesh,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformMatricesEM) {
+ mti->deformMatricesEM(md, ctx, editData, mesh, vertexCos, defMats, numVerts);
+ }
+ else {
+ DerivedMesh *dm = NULL;
+ if (mesh) {
+ dm = CDDM_from_mesh(mesh);
+ }
+
+ mti->deformMatricesEM_DM(md, ctx, editData, dm, vertexCos, defMats, numVerts);
+
+ if (dm) {
+ dm->release(dm);
+ }
+ }
+}
+
+struct Mesh *modifier_applyModifier(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct Mesh *mesh)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->applyModifier) {
+ return mti->applyModifier(md, ctx, mesh);
+ }
+ else {
+ DerivedMesh *dm = CDDM_from_mesh(mesh);
+
+ DerivedMesh *ndm = mti->applyModifier_DM(md, ctx, dm);
+
+ if(ndm != dm) {
+ dm->release(dm);
+ }
+
+ DM_to_mesh(ndm, mesh, ctx->object, CD_MASK_EVERYTHING, true);
+
+ return mesh;
+ }
+}
+
+struct Mesh *modifier_applyModifierEM(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct Mesh *mesh)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->applyModifierEM) {
+ return mti->applyModifierEM(md, ctx, editData, mesh);
+ }
+ else {
+ DerivedMesh *dm = CDDM_from_mesh(mesh);
+
+ DerivedMesh *ndm = mti->applyModifierEM_DM(md, ctx, editData, dm);
+
+ if(ndm != dm) {
+ dm->release(dm);
+ }
+
+ DM_to_mesh(ndm, mesh, ctx->object, CD_MASK_EVERYTHING, true);
+
+ return mesh;
+ }
+}
+
+/* depricated variants of above that accept DerivedMesh */
+
+void modifier_deformVerts_DM_deprecated(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct DerivedMesh *dm,
+ float (*vertexCos)[3], int numVerts)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformVerts_DM) {
+ mti->deformVerts_DM(md, ctx, dm, vertexCos, numVerts);
+ }
+ else {
+ /* TODO(sybren): deduplicate all the copies of this code in this file. */
+ Mesh *mesh = NULL;
+ if (dm != NULL) {
+ mesh = BKE_id_new_nomain(ID_ME, NULL);
+ DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
+ }
+
+ mti->deformVerts(md, ctx, mesh, vertexCos, numVerts);
+
+ if (mesh != NULL) {
+ BKE_id_free(NULL, mesh);
+ }
+ }
+}
+
+void modifier_deformMatrices_DM_deprecated(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct DerivedMesh *dm,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
+{
+
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformMatrices_DM) {
+ mti->deformMatrices_DM(md, ctx, dm, vertexCos, defMats, numVerts);
+ }
+ else {
+ /* TODO(sybren): deduplicate all the copies of this code in this file. */
+ Mesh *mesh = NULL;
+ if (dm != NULL) {
+ mesh = BKE_id_new_nomain(ID_ME, NULL);
+ DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
+ }
+
+ mti->deformMatrices(md, ctx, mesh, vertexCos, defMats, numVerts);
+
+ if (mesh != NULL) {
+ BKE_id_free(NULL, mesh);
+ }
+ }
+}
+
+void modifier_deformVertsEM_DM_deprecated(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct DerivedMesh *dm,
+ float (*vertexCos)[3], int numVerts)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformVertsEM_DM) {
+ mti->deformVertsEM_DM(md, ctx, editData, dm, vertexCos, numVerts);
+ }
+ else {
+ /* TODO(sybren): deduplicate all the copies of this code in this file. */
+ Mesh *mesh = NULL;
+ if (dm != NULL) {
+ mesh = BKE_id_new_nomain(ID_ME, NULL);
+ DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
+ }
+
+ mti->deformVertsEM(md, ctx, editData, mesh, vertexCos, numVerts);
+
+ if (mesh != NULL) {
+ BKE_id_free(NULL, mesh);
+ }
+ }
+}
+
+void modifier_deformMatricesEM_DM_deprecated(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, struct DerivedMesh *dm,
+ float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->deformMatricesEM_DM) {
+ mti->deformMatricesEM_DM(md, ctx, editData, dm, vertexCos, defMats, numVerts);
+ }
+ else {
+ /* TODO(sybren): deduplicate all the copies of this code in this file. */
+ Mesh *mesh = NULL;
+ if (dm != NULL) {
+ mesh = BKE_id_new_nomain(ID_ME, NULL);
+ DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
+ }
+
+ mti->deformMatricesEM(md, ctx, editData, mesh, vertexCos, defMats, numVerts);
+
+ if (mesh != NULL) {
+ BKE_id_free(NULL, mesh);
+ }
+ }
+}
+
+struct DerivedMesh *modifier_applyModifier_DM_deprecated(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct DerivedMesh *dm)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->applyModifier_DM) {
+ return mti->applyModifier_DM(md, ctx, dm);
+ }
+ else {
+ /* TODO(sybren): deduplicate all the copies of this code in this file. */
+ Mesh *mesh = NULL;
+ if (dm != NULL) {
+ mesh = BKE_id_new_nomain(ID_ME, NULL);
+ DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
+ }
+
+ struct Mesh *new_mesh = mti->applyModifier(md, ctx, mesh);
+
+ /* Make a DM that doesn't reference new_mesh so we can free the latter. */
+ DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE);
+
+ if(new_mesh != mesh) {
+ BKE_id_free(NULL, new_mesh);
+ }
+ if (mesh != NULL) {
+ BKE_id_free(NULL, mesh);
+ }
+
+ return ndm;
+ }
+}
+
+struct DerivedMesh *modifier_applyModifierEM_DM_deprecated(struct ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
+ struct DerivedMesh *dm)
+{
+ const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
+
+ if (mti->applyModifierEM_DM) {
+ return mti->applyModifierEM_DM(md, ctx, editData, dm);
+ }
+ else {
+ /* TODO(sybren): deduplicate all the copies of this code in this file. */
+ Mesh *mesh = NULL;
+ if (dm != NULL) {
+ mesh = BKE_id_new_nomain(ID_ME, NULL);
+ DM_to_mesh(dm, mesh, ctx->object, CD_MASK_EVERYTHING, false);
+ }
+
+ struct Mesh *new_mesh = mti->applyModifierEM(md, ctx, editData, mesh);
+
+ /* Make a DM that doesn't reference new_mesh so we can free the latter. */
+ DerivedMesh *ndm = CDDM_from_mesh_ex(new_mesh, CD_DUPLICATE);
+
+ if(new_mesh != mesh) {
+ BKE_id_free(NULL, new_mesh);
+ }
+ if (mesh != NULL) {
+ BKE_id_free(NULL, mesh);
+ }
+
+ return ndm;
+ }
+}
+
diff --git a/source/blender/blenkernel/intern/movieclip.c b/source/blender/blenkernel/intern/movieclip.c
index 9ed715d7591..d742bcea69d 100644
--- a/source/blender/blenkernel/intern/movieclip.c
+++ b/source/blender/blenkernel/intern/movieclip.c
@@ -1609,8 +1609,8 @@ bool BKE_movieclip_put_frame_if_possible(MovieClip *clip,
return result;
}
-void BKE_movieclip_eval_update(struct EvaluationContext *UNUSED(eval_ctx), MovieClip *clip)
+void BKE_movieclip_eval_update(struct Depsgraph *depsgraph, MovieClip *clip)
{
- DEG_debug_print_eval(__func__, clip->id.name, clip);
+ DEG_debug_print_eval(depsgraph, __func__, clip->id.name, clip);
BKE_tracking_dopesheet_tag_update(&clip->tracking);
}
diff --git a/source/blender/blenkernel/intern/multires.c b/source/blender/blenkernel/intern/multires.c
index 9c8fc9bfd0c..ee32c2398b2 100644
--- a/source/blender/blenkernel/intern/multires.c
+++ b/source/blender/blenkernel/intern/multires.c
@@ -277,14 +277,14 @@ static MDisps *multires_mdisps_initialize_hidden(Mesh *me, int level)
return mdisps;
}
-DerivedMesh *get_multires_dm(Scene *scene, MultiresModifierData *mmd, Object *ob)
+DerivedMesh *get_multires_dm(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd, Object *ob)
{
ModifierData *md = (ModifierData *)mmd;
- const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
- DerivedMesh *tdm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
+ DerivedMesh *tdm = mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH);
DerivedMesh *dm;
+ ModifierEvalContext mectx = {depsgraph, ob, MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY};
- dm = mti->applyModifier(md, ob, tdm, MOD_APPLY_USECACHE | MOD_APPLY_IGNORE_SIMPLIFY);
+ dm = modifier_applyModifier_DM_deprecated(md, &mectx, tdm);
if (dm == tdm) {
dm = CDDM_copy(tdm);
}
@@ -398,10 +398,10 @@ void multires_force_render_update(Object *ob)
multires_force_update(ob);
}
-int multiresModifier_reshapeFromDM(Scene *scene, MultiresModifierData *mmd,
+int multiresModifier_reshapeFromDM(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd,
Object *ob, DerivedMesh *srcdm)
{
- DerivedMesh *mrdm = get_multires_dm(scene, mmd, ob);
+ DerivedMesh *mrdm = get_multires_dm(depsgraph, scene, mmd, ob);
if (mrdm && srcdm && mrdm->getNumVerts(mrdm) == srcdm->getNumVerts(srcdm)) {
multires_mvert_to_ss(mrdm, srcdm->getVertArray(srcdm));
@@ -420,30 +420,30 @@ int multiresModifier_reshapeFromDM(Scene *scene, MultiresModifierData *mmd,
}
/* Returns 1 on success, 0 if the src's totvert doesn't match */
-int multiresModifier_reshape(Scene *scene, MultiresModifierData *mmd, Object *dst, Object *src)
+int multiresModifier_reshape(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd, Object *dst, Object *src)
{
- DerivedMesh *srcdm = mesh_get_derived_final(scene, src, CD_MASK_BAREMESH);
- return multiresModifier_reshapeFromDM(scene, mmd, dst, srcdm);
+ DerivedMesh *srcdm = mesh_get_derived_final(depsgraph, scene, src, CD_MASK_BAREMESH);
+ return multiresModifier_reshapeFromDM(depsgraph, scene, mmd, dst, srcdm);
}
-int multiresModifier_reshapeFromDeformMod(Scene *scene, MultiresModifierData *mmd,
+int multiresModifier_reshapeFromDeformMod(struct Depsgraph *depsgraph, Scene *scene, MultiresModifierData *mmd,
Object *ob, ModifierData *md)
{
- const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
DerivedMesh *dm, *ndm;
int numVerts, result;
float (*deformedVerts)[3];
+ const ModifierEvalContext mectx = {depsgraph, ob, 0};
if (multires_get_level(ob, mmd, false, true) == 0)
return 0;
/* Create DerivedMesh for deformation modifier */
- dm = get_multires_dm(scene, mmd, ob);
+ dm = get_multires_dm(depsgraph, scene, mmd, ob);
numVerts = dm->getNumVerts(dm);
deformedVerts = MEM_malloc_arrayN(numVerts, sizeof(float[3]), "multiresReshape_deformVerts");
dm->getVertCos(dm, deformedVerts);
- mti->deformVerts(md, ob, dm, deformedVerts, numVerts, 0);
+ modifier_deformVerts_DM_deprecated(md, &mectx, dm, deformedVerts, numVerts);
ndm = CDDM_copy(dm);
CDDM_apply_vert_coords(ndm, deformedVerts);
@@ -452,7 +452,7 @@ int multiresModifier_reshapeFromDeformMod(Scene *scene, MultiresModifierData *mm
dm->release(dm);
/* Reshaping */
- result = multiresModifier_reshapeFromDM(scene, mmd, ob, ndm);
+ result = multiresModifier_reshapeFromDM(depsgraph, scene, mmd, ob, ndm);
/* Cleanup */
ndm->release(ndm);
@@ -2275,7 +2275,7 @@ static void multires_apply_smat_cb(
}
}
-static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3])
+static void multires_apply_smat(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float smat[3][3])
{
DerivedMesh *dm = NULL, *cddm = NULL, *subdm = NULL;
CCGElem **gridData, **subGridData;
@@ -2300,10 +2300,10 @@ static void multires_apply_smat(Scene *scene, Object *ob, float smat[3][3])
high_mmd.lvl = high_mmd.totlvl;
/* unscaled multires with applied displacement */
- subdm = get_multires_dm(scene, &high_mmd, ob);
+ subdm = get_multires_dm(depsgraph, scene, &high_mmd, ob);
/* prepare scaled CDDM to create ccgDN */
- cddm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
+ cddm = mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH);
totvert = cddm->getNumVerts(cddm);
vertCos = MEM_malloc_arrayN(totvert, sizeof(*vertCos), "multiresScale vertCos");
@@ -2364,17 +2364,17 @@ int multires_mdisp_corners(MDisps *s)
return 0;
}
-void multiresModifier_scale_disp(Scene *scene, Object *ob)
+void multiresModifier_scale_disp(struct Depsgraph *depsgraph, Scene *scene, Object *ob)
{
float smat[3][3];
/* object's scale matrix */
BKE_object_scale_to_mat3(ob, smat);
- multires_apply_smat(scene, ob, smat);
+ multires_apply_smat(depsgraph, scene, ob, smat);
}
-void multiresModifier_prepare_join(Scene *scene, Object *ob, Object *to_ob)
+void multiresModifier_prepare_join(struct Depsgraph *depsgraph, Scene *scene, Object *ob, Object *to_ob)
{
float smat[3][3], tmat[3][3], mat[3][3];
multires_sync_levels(scene, to_ob, ob);
@@ -2385,7 +2385,7 @@ void multiresModifier_prepare_join(Scene *scene, Object *ob, Object *to_ob)
BKE_object_scale_to_mat3(ob, smat);
mul_m3_m3m3(mat, smat, tmat);
- multires_apply_smat(scene, ob, mat);
+ multires_apply_smat(depsgraph, scene, ob, mat);
}
/* update multires data after topology changing */
diff --git a/source/blender/blenkernel/intern/navmesh_conversion.c b/source/blender/blenkernel/intern/navmesh_conversion.c
deleted file mode 100644
index 35bcca52f63..00000000000
--- a/source/blender/blenkernel/intern/navmesh_conversion.c
+++ /dev/null
@@ -1,502 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenkernel/intern/navmesh_conversion.c
- * \ingroup bke
- */
-
-#include <math.h>
-#include <stdlib.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_meshdata_types.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_math.h"
-#include "BLI_sort.h"
-
-#include "BKE_navmesh_conversion.h"
-#include "BKE_cdderivedmesh.h"
-
-#include "recast-capi.h"
-
-BLI_INLINE float area2(const float *a, const float *b, const float *c)
-{
- return (b[0] - a[0]) * (c[2] - a[2]) - (c[0] - a[0]) * (b[2] - a[2]);
-}
-
-BLI_INLINE int left(const float *a, const float *b, const float *c)
-{
- return area2(a, b, c) < 0;
-}
-
-int polyNumVerts(const unsigned short *p, const int vertsPerPoly)
-{
- int i, nv = 0;
- for (i = 0; i < vertsPerPoly; i++) {
- if (p[i] == 0xffff)
- break;
- nv++;
- }
- return nv;
-}
-
-int polyIsConvex(const unsigned short *p, const int vertsPerPoly, const float *verts)
-{
- int j, nv = polyNumVerts(p, vertsPerPoly);
- if (nv < 3)
- return 0;
- for (j = 0; j < nv; j++) {
- const float *v = &verts[3 * p[j]];
- const float *v_next = &verts[3 * p[(j + 1) % nv]];
- const float *v_prev = &verts[3 * p[(nv + j - 1) % nv]];
- if (!left(v_prev, v, v_next))
- return 0;
-
- }
- return 1;
-}
-
-/* XXX, could replace with #dist_to_line_segment_v3(), or add a squared version */
-float distPointToSegmentSq(const float point[3], const float a[3], const float b[3])
-{
- float abx[3], dx[3];
- float d, t;
-
- sub_v3_v3v3(abx, b, a);
- sub_v3_v3v3(dx, point, a);
-
- d = abx[0] * abx[0] + abx[2] * abx[2];
- t = abx[0] * dx[0] + abx[2] * dx[2];
-
- if (d > 0.0f)
- t /= d;
- if (t < 0.0f)
- t = 0.0f;
- else if (t > 1.0f)
- t = 1.0f;
- dx[0] = a[0] + t * abx[0] - point[0];
- dx[2] = a[2] + t * abx[2] - point[2];
-
- return dx[0] * dx[0] + dx[2] * dx[2];
-}
-
-int buildRawVertIndicesData(DerivedMesh *dm, int *nverts_r, float **verts_r,
- int *ntris_r, unsigned short **tris_r, int **trisToFacesMap_r,
- int **recastData)
-{
- int vi, fi, triIdx;
- int nverts, ntris;
- int *trisToFacesMap;
- float *verts;
- unsigned short *tris, *tri;
- int nfaces;
- MFace *faces;
-
- nverts = dm->getNumVerts(dm);
- if (nverts >= 0xffff) {
- printf("Converting navmesh: Error! Too many vertices. Max number of vertices %d\n", 0xffff);
- return 0;
- }
- if (nverts == 0) {
- printf("Converting navmesh: Error! There are no vertices!\n");
- return 0;
- }
-
- verts = MEM_mallocN(sizeof(float[3]) * nverts, "buildRawVertIndicesData verts");
- dm->getVertCos(dm, (float(*)[3])verts);
-
- /* flip coordinates */
- for (vi = 0; vi < nverts; vi++) {
- SWAP(float, verts[3 * vi + 1], verts[3 * vi + 2]);
- }
-
- /* calculate number of tris */
- dm->recalcTessellation(dm);
- nfaces = dm->getNumTessFaces(dm);
- if (nfaces == 0) {
- printf("Converting navmesh: Error! There are %i vertices, but no faces!\n", nverts);
- return 0;
- }
-
- faces = dm->getTessFaceArray(dm);
- ntris = nfaces;
- for (fi = 0; fi < nfaces; fi++) {
- MFace *face = &faces[fi];
- if (face->v4)
- ntris++;
- }
-
- /* copy and transform to triangles (reorder on the run) */
- trisToFacesMap = MEM_callocN(sizeof(int) * ntris, "buildRawVertIndicesData trisToFacesMap");
- tris = MEM_callocN(sizeof(unsigned short) * 3 * ntris, "buildRawVertIndicesData tris");
- tri = tris;
- triIdx = 0;
- for (fi = 0; fi < nfaces; fi++) {
- MFace *face = &faces[fi];
- tri[3 * triIdx + 0] = (unsigned short) face->v1;
- tri[3 * triIdx + 1] = (unsigned short) face->v3;
- tri[3 * triIdx + 2] = (unsigned short) face->v2;
- trisToFacesMap[triIdx++] = fi;
- if (face->v4) {
- tri[3 * triIdx + 0] = (unsigned short) face->v1;
- tri[3 * triIdx + 1] = (unsigned short) face->v4;
- tri[3 * triIdx + 2] = (unsigned short) face->v3;
- trisToFacesMap[triIdx++] = fi;
- }
- }
-
- /* carefully, recast data is just reference to data in derived mesh */
- *recastData = (int *)CustomData_get_layer(&dm->polyData, CD_RECAST);
-
- *nverts_r = nverts;
- *verts_r = verts;
- *ntris_r = ntris;
- *tris_r = tris;
- *trisToFacesMap_r = trisToFacesMap;
-
- return 1;
-}
-
-int buildPolygonsByDetailedMeshes(const int vertsPerPoly, const int npolys,
- unsigned short *polys, const unsigned short *dmeshes,
- const float *verts, const unsigned short *dtris,
- const int *dtrisToPolysMap)
-{
- int polyidx;
- int capacity = vertsPerPoly;
- unsigned short *newPoly = MEM_callocN(sizeof(unsigned short) * capacity, "buildPolygonsByDetailedMeshes newPoly");
- memset(newPoly, 0xff, sizeof(unsigned short) * capacity);
-
- for (polyidx = 0; polyidx < npolys; polyidx++) {
- size_t i;
- int j, k;
- int nv = 0;
- /* search border */
- int tri, btri = -1;
- int edge, bedge = -1;
- int dtrisNum = dmeshes[polyidx * 4 + 3];
- int dtrisBase = dmeshes[polyidx * 4 + 2];
- unsigned char *traversedTris = MEM_callocN(sizeof(unsigned char) * dtrisNum, "buildPolygonsByDetailedMeshes traversedTris");
- unsigned short *adjustedPoly;
- int adjustedNv;
- int allBorderTraversed;
-
- for (j = 0; j < dtrisNum && btri == -1; j++) {
- int curpolytri = dtrisBase + j;
- for (k = 0; k < 3; k++) {
- unsigned short neighbortri = dtris[curpolytri * 3 * 2 + 3 + k];
- if (neighbortri == 0xffff || dtrisToPolysMap[neighbortri] != polyidx + 1) {
- btri = curpolytri;
- bedge = k;
- break;
- }
- }
- }
- if (btri == -1 || bedge == -1) {
- /* can't find triangle with border edge */
- MEM_freeN(traversedTris);
- MEM_freeN(newPoly);
-
- return 0;
- }
-
- newPoly[nv++] = dtris[btri * 3 * 2 + bedge];
- tri = btri;
- edge = (bedge + 1) % 3;
- traversedTris[tri - dtrisBase] = 1;
- while (tri != btri || edge != bedge) {
- int neighbortri = dtris[tri * 3 * 2 + 3 + edge];
- if (neighbortri == 0xffff || dtrisToPolysMap[neighbortri] != polyidx + 1) {
- if (nv == capacity) {
- unsigned short *newPolyBig;
- capacity += vertsPerPoly;
- newPolyBig = MEM_callocN(sizeof(unsigned short) * capacity, "buildPolygonsByDetailedMeshes newPolyBig");
- memset(newPolyBig, 0xff, sizeof(unsigned short) * capacity);
- memcpy(newPolyBig, newPoly, sizeof(unsigned short) * nv);
- MEM_freeN(newPoly);
- newPoly = newPolyBig;
- }
- newPoly[nv++] = dtris[tri * 3 * 2 + edge];
- /* move to next edge */
- edge = (edge + 1) % 3;
- }
- else {
- /* move to next tri */
- int twinedge = -1;
- for (k = 0; k < 3; k++) {
- if (dtris[neighbortri * 3 * 2 + 3 + k] == tri) {
- twinedge = k;
- break;
- }
- }
- if (twinedge == -1) {
- printf("Converting navmesh: Error! Can't find neighbor edge - invalid adjacency info\n");
- MEM_freeN(traversedTris);
- goto returnLabel;
- }
- tri = neighbortri;
- edge = (twinedge + 1) % 3;
- traversedTris[tri - dtrisBase] = 1;
- }
- }
-
- adjustedPoly = MEM_callocN(sizeof(unsigned short) * nv, "buildPolygonsByDetailedMeshes adjustedPoly");
- adjustedNv = 0;
- for (i = 0; i < nv; i++) {
- unsigned short prev = newPoly[(nv + i - 1) % nv];
- unsigned short cur = newPoly[i];
- unsigned short next = newPoly[(i + 1) % nv];
- float distSq = distPointToSegmentSq(&verts[3 * cur], &verts[3 * prev], &verts[3 * next]);
- static const float tolerance = 0.001f;
- if (distSq > tolerance)
- adjustedPoly[adjustedNv++] = cur;
- }
- memcpy(newPoly, adjustedPoly, adjustedNv * sizeof(unsigned short));
- MEM_freeN(adjustedPoly);
- nv = adjustedNv;
-
- allBorderTraversed = 1;
- for (i = 0; i < dtrisNum; i++) {
- if (traversedTris[i] == 0) {
- /* check whether it has border edges */
- int curpolytri = dtrisBase + i;
- for (k = 0; k < 3; k++) {
- unsigned short neighbortri = dtris[curpolytri * 3 * 2 + 3 + k];
- if (neighbortri == 0xffff || dtrisToPolysMap[neighbortri] != polyidx + 1) {
- allBorderTraversed = 0;
- break;
- }
- }
- }
- }
-
- if (nv <= vertsPerPoly && allBorderTraversed) {
- for (i = 0; i < nv; i++) {
- polys[polyidx * vertsPerPoly * 2 + i] = newPoly[i];
- }
- }
-
- MEM_freeN(traversedTris);
- }
-
-returnLabel:
- MEM_freeN(newPoly);
-
- return 1;
-}
-
-struct SortContext {
- const int *recastData;
- const int *trisToFacesMap;
-};
-
-static int compareByData(const void *a, const void *b, void *ctx)
-{
- return (((struct SortContext *)ctx)->recastData[((struct SortContext *)ctx)->trisToFacesMap[*(int *)a]] -
- ((struct SortContext *)ctx)->recastData[((struct SortContext *)ctx)->trisToFacesMap[*(int *)b]]);
-}
-
-int buildNavMeshData(const int nverts, const float *verts,
- const int ntris, const unsigned short *tris,
- const int *recastData, const int *trisToFacesMap,
- int *ndtris_r, unsigned short **dtris_r,
- int *npolys_r, unsigned short **dmeshes_r, unsigned short **polys_r,
- int *vertsPerPoly_r, int **dtrisToPolysMap_r, int **dtrisToTrisMap_r)
-
-{
- int *trisMapping;
- int i;
- struct SortContext context;
- int validTriStart, prevPolyIdx, curPolyIdx, newPolyIdx, prevpolyidx;
- unsigned short *dmesh;
-
- int ndtris, npolys, vertsPerPoly;
- unsigned short *dtris, *dmeshes, *polys;
- int *dtrisToPolysMap, *dtrisToTrisMap;
-
- if (!recastData) {
- printf("Converting navmesh: Error! Can't find recast custom data\n");
- return 0;
- }
-
- trisMapping = MEM_callocN(sizeof(int) * ntris, "buildNavMeshData trisMapping");
-
- /* sort the triangles by polygon idx */
- for (i = 0; i < ntris; i++)
- trisMapping[i] = i;
- context.recastData = recastData;
- context.trisToFacesMap = trisToFacesMap;
- BLI_qsort_r(trisMapping, ntris, sizeof(int), compareByData, &context);
-
- /* search first valid triangle - triangle of convex polygon */
- validTriStart = -1;
- for (i = 0; i < ntris; i++) {
- if (recastData[trisToFacesMap[trisMapping[i]]] > 0) {
- validTriStart = i;
- break;
- }
- }
-
- if (validTriStart < 0) {
- printf("Converting navmesh: Error! No valid polygons in mesh\n");
- MEM_freeN(trisMapping);
- return 0;
- }
-
- ndtris = ntris - validTriStart;
- /* fill dtris to faces mapping */
- dtrisToTrisMap = MEM_callocN(sizeof(int) * ndtris, "buildNavMeshData dtrisToTrisMap");
- memcpy(dtrisToTrisMap, &trisMapping[validTriStart], ndtris * sizeof(int));
- MEM_freeN(trisMapping);
-
- /* create detailed mesh triangles - copy only valid triangles
- * and reserve memory for adjacency info */
- dtris = MEM_callocN(sizeof(unsigned short) * 3 * 2 * ndtris, "buildNavMeshData dtris");
- memset(dtris, 0xff, sizeof(unsigned short) * 3 * 2 * ndtris);
- for (i = 0; i < ndtris; i++) {
- memcpy(dtris + 3 * 2 * i, tris + 3 * dtrisToTrisMap[i], sizeof(unsigned short) * 3);
- }
-
- /* create new recast data corresponded to dtris and renumber for continuous indices */
- prevPolyIdx = -1;
- newPolyIdx = 0;
- dtrisToPolysMap = MEM_callocN(sizeof(int) * ndtris, "buildNavMeshData dtrisToPolysMap");
- for (i = 0; i < ndtris; i++) {
- curPolyIdx = recastData[trisToFacesMap[dtrisToTrisMap[i]]];
- if (curPolyIdx != prevPolyIdx) {
- newPolyIdx++;
- prevPolyIdx = curPolyIdx;
- }
- dtrisToPolysMap[i] = newPolyIdx;
- }
-
-
- /* build adjacency info for detailed mesh triangles */
- if (!recast_buildMeshAdjacency(dtris, ndtris, nverts, 3)) {
- printf("Converting navmesh: Error! Unable to build mesh adjacency information\n");
- MEM_freeN(trisMapping);
- MEM_freeN(dtrisToPolysMap);
- return 0;
- }
-
- /* create detailed mesh description for each navigation polygon */
- npolys = dtrisToPolysMap[ndtris - 1];
- dmeshes = MEM_callocN(sizeof(unsigned short) * npolys * 4, "buildNavMeshData dmeshes");
- memset(dmeshes, 0, npolys * 4 * sizeof(unsigned short));
- dmesh = NULL;
- prevpolyidx = 0;
- for (i = 0; i < ndtris; i++) {
- int curpolyidx = dtrisToPolysMap[i];
- if (curpolyidx != prevpolyidx) {
- if (curpolyidx != prevpolyidx + 1) {
- printf("Converting navmesh: Error! Wrong order of detailed mesh faces\n");
- goto fail;
- }
- dmesh = dmesh == NULL ? dmeshes : dmesh + 4;
- dmesh[2] = (unsigned short)i; /* tbase */
- dmesh[3] = 0; /* tnum */
- prevpolyidx = curpolyidx;
- }
- dmesh[3]++;
- }
-
- /* create navigation polygons */
- vertsPerPoly = 6;
- polys = MEM_callocN(sizeof(unsigned short) * npolys * vertsPerPoly * 2, "buildNavMeshData polys");
- memset(polys, 0xff, sizeof(unsigned short) * vertsPerPoly * 2 * npolys);
-
- if (!buildPolygonsByDetailedMeshes(vertsPerPoly, npolys, polys, dmeshes, verts, dtris, dtrisToPolysMap)) {
- printf("Converting navmesh: Error! Unable to build polygons from detailed mesh\n");
- goto fail;
- }
-
- *ndtris_r = ndtris;
- *npolys_r = npolys;
- *vertsPerPoly_r = vertsPerPoly;
- *dtris_r = dtris;
- *dmeshes_r = dmeshes;
- *polys_r = polys;
- *dtrisToPolysMap_r = dtrisToPolysMap;
- *dtrisToTrisMap_r = dtrisToTrisMap;
-
- return 1;
-
-fail:
- MEM_freeN(dmeshes);
- MEM_freeN(dtrisToPolysMap);
- MEM_freeN(dtrisToTrisMap);
- return 0;
-}
-
-
-int buildNavMeshDataByDerivedMesh(DerivedMesh *dm, int *vertsPerPoly,
- int *nverts, float **verts,
- int *ndtris, unsigned short **dtris,
- int *npolys, unsigned short **dmeshes,
- unsigned short **polys, int **dtrisToPolysMap,
- int **dtrisToTrisMap, int **trisToFacesMap)
-{
- int res;
- int ntris = 0, *recastData = NULL;
- unsigned short *tris = NULL;
-
- res = buildRawVertIndicesData(dm, nverts, verts, &ntris, &tris, trisToFacesMap, &recastData);
- if (!res) {
- printf("Converting navmesh: Error! Can't get raw vertices and indices from mesh\n");
- goto exit;
- }
-
- res = buildNavMeshData(*nverts, *verts, ntris, tris, recastData, *trisToFacesMap,
- ndtris, dtris, npolys, dmeshes, polys, vertsPerPoly,
- dtrisToPolysMap, dtrisToTrisMap);
- if (!res) {
- printf("Converting navmesh: Error! Can't build navmesh data from mesh\n");
- goto exit;
- }
-
-exit:
- if (tris)
- MEM_freeN(tris);
-
- return res;
-}
-
-int polyFindVertex(const unsigned short *p, const int vertsPerPoly, unsigned short vertexIdx)
-{
- int i, res = -1;
- for (i = 0; i < vertsPerPoly; i++) {
- if (p[i] == 0xffff)
- break;
- if (p[i] == vertexIdx) {
- res = i;
- break;
- }
- }
- return res;
-}
diff --git a/source/blender/blenkernel/intern/nla.c b/source/blender/blenkernel/intern/nla.c
index e239037df70..777c2a580fd 100644
--- a/source/blender/blenkernel/intern/nla.c
+++ b/source/blender/blenkernel/intern/nla.c
@@ -59,7 +59,7 @@
#include "BKE_library.h"
#ifdef WITH_AUDASPACE
-# include AUD_SPECIAL_H
+# include <AUD_Special.h>
#endif
#include "RNA_access.h"
diff --git a/source/blender/blenkernel/intern/node.c b/source/blender/blenkernel/intern/node.c
index 5d4b1ae8170..3b51ce9366f 100644
--- a/source/blender/blenkernel/intern/node.c
+++ b/source/blender/blenkernel/intern/node.c
@@ -75,6 +75,8 @@
#include "NOD_shader.h"
#include "NOD_texture.h"
+#include "DEG_depsgraph.h"
+
#define NODE_DEFAULT_MAX_WIDTH 700
/* Fallback types for undefined tree, nodes, sockets */
@@ -1987,9 +1989,6 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
if (ntree) {
bNodeTree *ltree;
bNode *node;
- AnimData *adt;
-
- bAction *action_backup = NULL, *tmpact_backup = NULL;
BLI_spin_lock(&spin);
if (!ntree->duplilock) {
@@ -1999,23 +1998,16 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
BLI_mutex_lock(ntree->duplilock);
- /* Workaround for copying an action on each render!
- * set action to NULL so animdata actions don't get copied */
- adt = BKE_animdata_from_id(&ntree->id);
-
- if (adt) {
- action_backup = adt->action;
- tmpact_backup = adt->tmpact;
-
- adt->action = NULL;
- adt->tmpact = NULL;
- }
-
/* Make full copy outside of Main database.
* Note: previews are not copied here.
*/
- BKE_id_copy_ex(G.main, (ID *)ntree, (ID **)&ltree,
- LIB_ID_CREATE_NO_MAIN | LIB_ID_CREATE_NO_USER_REFCOUNT | LIB_ID_COPY_NO_PREVIEW, false);
+ BKE_id_copy_ex(
+ NULL, &ntree->id, (ID **)&ltree,
+ (LIB_ID_CREATE_NO_MAIN |
+ LIB_ID_CREATE_NO_USER_REFCOUNT |
+ LIB_ID_COPY_NO_PREVIEW |
+ LIB_ID_COPY_NO_ANIMDATA),
+ false);
ltree->flag |= NTREE_IS_LOCALIZED;
for (node = ltree->nodes.first; node; node = node->next) {
@@ -2024,31 +2016,19 @@ bNodeTree *ntreeLocalize(bNodeTree *ntree)
}
}
- if (adt) {
- AnimData *ladt = BKE_animdata_from_id(&ltree->id);
-
- adt->action = ladt->action = action_backup;
- adt->tmpact = ladt->tmpact = tmpact_backup;
-
- if (action_backup)
- id_us_plus(&action_backup->id);
- if (tmpact_backup)
- id_us_plus(&tmpact_backup->id);
-
- }
- /* end animdata uglyness */
-
/* ensures only a single output node is enabled */
ntreeSetOutput(ntree);
for (node = ntree->nodes.first; node; node = node->next) {
/* store new_node pointer to original */
- node->new_node->new_node = node;
+ node->new_node->original = node;
}
if (ntree->typeinfo->localize)
ntree->typeinfo->localize(ltree, ntree);
+ ltree->id.tag |= LIB_TAG_LOCALIZED;
+
BLI_mutex_unlock(ntree->duplilock);
return ltree;
@@ -3118,77 +3098,6 @@ void nodeUpdateInternalLinks(bNodeTree *ntree, bNode *node)
}
-/* nodes that use ID data get synced with local data */
-void nodeSynchronizeID(bNode *node, bool copy_to_id)
-{
- if (node->id == NULL) return;
-
- if (ELEM(node->type, SH_NODE_MATERIAL, SH_NODE_MATERIAL_EXT)) {
- bNodeSocket *sock;
- Material *ma = (Material *)node->id;
- int a;
- short check_flags = SOCK_UNAVAIL;
-
- if (!copy_to_id)
- check_flags |= SOCK_HIDDEN;
-
- /* hrmf, case in loop isn't super fast, but we don't edit 100s of material at same time either! */
- for (a = 0, sock = node->inputs.first; sock; sock = sock->next, a++) {
- if (!(sock->flag & check_flags)) {
- if (copy_to_id) {
- switch (a) {
- case MAT_IN_COLOR:
- copy_v3_v3(&ma->r, ((bNodeSocketValueRGBA *)sock->default_value)->value); break;
- case MAT_IN_SPEC:
- copy_v3_v3(&ma->specr, ((bNodeSocketValueRGBA *)sock->default_value)->value); break;
- case MAT_IN_REFL:
- ma->ref = ((bNodeSocketValueFloat *)sock->default_value)->value; break;
- case MAT_IN_MIR:
- copy_v3_v3(&ma->mirr, ((bNodeSocketValueRGBA *)sock->default_value)->value); break;
- case MAT_IN_AMB:
- ma->amb = ((bNodeSocketValueFloat *)sock->default_value)->value; break;
- case MAT_IN_EMIT:
- ma->emit = ((bNodeSocketValueFloat *)sock->default_value)->value; break;
- case MAT_IN_SPECTRA:
- ma->spectra = ((bNodeSocketValueFloat *)sock->default_value)->value; break;
- case MAT_IN_RAY_MIRROR:
- ma->ray_mirror = ((bNodeSocketValueFloat *)sock->default_value)->value; break;
- case MAT_IN_ALPHA:
- ma->alpha = ((bNodeSocketValueFloat *)sock->default_value)->value; break;
- case MAT_IN_TRANSLUCENCY:
- ma->translucency = ((bNodeSocketValueFloat *)sock->default_value)->value; break;
- }
- }
- else {
- switch (a) {
- case MAT_IN_COLOR:
- copy_v3_v3(((bNodeSocketValueRGBA *)sock->default_value)->value, &ma->r); break;
- case MAT_IN_SPEC:
- copy_v3_v3(((bNodeSocketValueRGBA *)sock->default_value)->value, &ma->specr); break;
- case MAT_IN_REFL:
- ((bNodeSocketValueFloat *)sock->default_value)->value = ma->ref; break;
- case MAT_IN_MIR:
- copy_v3_v3(((bNodeSocketValueRGBA *)sock->default_value)->value, &ma->mirr); break;
- case MAT_IN_AMB:
- ((bNodeSocketValueFloat *)sock->default_value)->value = ma->amb; break;
- case MAT_IN_EMIT:
- ((bNodeSocketValueFloat *)sock->default_value)->value = ma->emit; break;
- case MAT_IN_SPECTRA:
- ((bNodeSocketValueFloat *)sock->default_value)->value = ma->spectra; break;
- case MAT_IN_RAY_MIRROR:
- ((bNodeSocketValueFloat *)sock->default_value)->value = ma->ray_mirror; break;
- case MAT_IN_ALPHA:
- ((bNodeSocketValueFloat *)sock->default_value)->value = ma->alpha; break;
- case MAT_IN_TRANSLUCENCY:
- ((bNodeSocketValueFloat *)sock->default_value)->value = ma->translucency; break;
- }
- }
- }
- }
- }
-}
-
-
/* ************* node type access ********** */
void nodeLabel(bNodeTree *ntree, bNode *node, char *label, int maxlen)
@@ -3553,10 +3462,7 @@ static void registerShaderNodes(void)
{
register_node_type_sh_group();
- register_node_type_sh_output();
- register_node_type_sh_material();
register_node_type_sh_camera();
- register_node_type_sh_lamp();
register_node_type_sh_gamma();
register_node_type_sh_brightcontrast();
register_node_type_sh_value();
@@ -3567,9 +3473,7 @@ static void registerShaderNodes(void)
register_node_type_sh_mix_rgb();
register_node_type_sh_valtorgb();
register_node_type_sh_rgbtobw();
- register_node_type_sh_texture();
register_node_type_sh_normal();
- register_node_type_sh_geom();
register_node_type_sh_mapping();
register_node_type_sh_curve_vec();
register_node_type_sh_curve_rgb();
@@ -3577,7 +3481,6 @@ static void registerShaderNodes(void)
register_node_type_sh_vect_math();
register_node_type_sh_vect_transform();
register_node_type_sh_squeeze();
- register_node_type_sh_material_ext();
register_node_type_sh_invert();
register_node_type_sh_seprgb();
register_node_type_sh_combrgb();
@@ -3622,6 +3525,7 @@ static void registerShaderNodes(void)
register_node_type_sh_add_shader();
register_node_type_sh_uvmap();
register_node_type_sh_uvalongstroke();
+ register_node_type_sh_eevee_specular();
register_node_type_sh_output_lamp();
register_node_type_sh_output_material();
@@ -3814,3 +3718,62 @@ bool BKE_node_tree_iter_step(struct NodeTreeIterStore *ntreeiter,
return true;
}
+
+/* -------------------------------------------------------------------- */
+/* NodeTree kernel functions */
+
+void BKE_nodetree_remove_layer_n(bNodeTree *ntree, Scene *scene, const int layer_index)
+{
+ BLI_assert(layer_index != -1);
+ for (bNode *node = ntree->nodes.first; node; node = node->next) {
+ if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) {
+ if (node->custom1 == layer_index) {
+ node->custom1 = 0;
+ }
+ else if (node->custom1 > layer_index) {
+ node->custom1--;
+ }
+ }
+ }
+}
+
+static void node_copy_default_values_list(ListBase *sockets_dst,
+ const ListBase *sockets_src)
+{
+ bNodeSocket *sock_dst = sockets_dst->first;
+ const bNodeSocket *sock_src = sockets_src->first;
+ while (sock_dst != NULL) {
+ node_socket_copy_default_value(sock_dst, sock_src);
+ sock_dst = sock_dst->next;
+ sock_src = sock_src->next;
+ }
+}
+
+static void node_copy_default_values(bNode *node_dst, const bNode *node_src)
+{
+ node_copy_default_values_list(&node_dst->inputs, &node_src->inputs);
+ node_copy_default_values_list(&node_dst->outputs, &node_src->outputs);
+}
+
+void BKE_nodetree_copy_default_values(bNodeTree *ntree_dst,
+ const bNodeTree *ntree_src)
+{
+ if (ntree_dst == ntree_src) {
+ return;
+ }
+ bNode *node_dst = ntree_dst->nodes.first;
+ const bNode *node_src = ntree_src->nodes.first;
+ while (node_dst != NULL) {
+ node_copy_default_values(node_dst, node_src);
+ node_dst = node_dst->next;
+ node_src = node_src->next;
+ }
+}
+
+void BKE_nodetree_shading_params_eval(struct Depsgraph *depsgraph,
+ bNodeTree *ntree_dst,
+ const bNodeTree *ntree_src)
+{
+ DEG_debug_print_eval(depsgraph, __func__, ntree_src->id.name, ntree_dst);
+ BKE_nodetree_copy_default_values(ntree_dst, ntree_src);
+}
diff --git a/source/blender/blenkernel/intern/object.c b/source/blender/blenkernel/intern/object.c
index 22a4db94d07..1798515658d 100644
--- a/source/blender/blenkernel/intern/object.c
+++ b/source/blender/blenkernel/intern/object.c
@@ -58,7 +58,7 @@
#include "DNA_view3d_types.h"
#include "DNA_world_types.h"
#include "DNA_object_types.h"
-#include "DNA_property_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_rigidbody_types.h"
#include "BLI_blenlib.h"
@@ -76,9 +76,7 @@
#include "BKE_idprop.h"
#include "BKE_armature.h"
#include "BKE_action.h"
-#include "BKE_bullet.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_animsys.h"
#include "BKE_anim.h"
@@ -91,6 +89,7 @@
#include "BKE_icons.h"
#include "BKE_key.h"
#include "BKE_lamp.h"
+#include "BKE_layer.h"
#include "BKE_lattice.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
@@ -103,12 +102,12 @@
#include "BKE_multires.h"
#include "BKE_node.h"
#include "BKE_object.h"
+#include "BKE_object_facemap.h"
#include "BKE_paint.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
-#include "BKE_property.h"
+#include "BKE_lightprobe.h"
#include "BKE_rigidbody.h"
-#include "BKE_sca.h"
#include "BKE_scene.h"
#include "BKE_sequencer.h"
#include "BKE_speaker.h"
@@ -118,6 +117,10 @@
#include "BKE_camera.h"
#include "BKE_image.h"
+#include "DEG_depsgraph.h"
+
+#include "DRW_engine.h"
+
#ifdef WITH_MOD_FLUID
#include "LBM_fluidsim.h"
#endif
@@ -129,8 +132,6 @@
#include "CCGSubSurf.h"
#include "atomic_ops.h"
-#include "GPU_material.h"
-
/* Vertex parent modifies original BMesh which is not safe for threading.
* Ideally such a modification should be handled as a separate DAG update
* callback for mesh datablock, but for until it is actually supported use
@@ -152,16 +153,6 @@ void BKE_object_workob_clear(Object *workob)
workob->rotmode = ROT_MODE_EUL;
}
-void BKE_object_update_base_layer(struct Scene *scene, Object *ob)
-{
- Base *base = scene->base.first;
-
- while (base) {
- if (base->object == ob) base->lay = ob->lay;
- base = base->next;
- }
-}
-
void BKE_object_free_particlesystems(Object *ob)
{
ParticleSystem *psys;
@@ -179,14 +170,6 @@ void BKE_object_free_softbody(Object *ob)
}
}
-void BKE_object_free_bulletsoftbody(Object *ob)
-{
- if (ob->bsoft) {
- bsbFree(ob->bsoft);
- ob->bsoft = NULL;
- }
-}
-
void BKE_object_free_curve_cache(Object *ob)
{
if (ob->curve_cache) {
@@ -356,7 +339,18 @@ void BKE_object_free_derived_caches(Object *ob)
ob->derivedDeform->release(ob->derivedDeform);
ob->derivedDeform = NULL;
}
-
+
+ if (ob->mesh_evaluated != NULL) {
+ /* Restore initial pointer. */
+ ob->data = ob->mesh_evaluated->id.orig_id;
+ /* Evaluated mesh points to edit mesh, but does not own it. */
+ ob->mesh_evaluated->edit_btmesh = NULL;
+ BKE_mesh_free(ob->mesh_evaluated);
+ BKE_libblock_free_data(&ob->mesh_evaluated->id, false);
+ MEM_freeN(ob->mesh_evaluated);
+ ob->mesh_evaluated = NULL;
+ }
+
BKE_object_free_curve_cache(ob);
}
@@ -401,7 +395,7 @@ void BKE_object_free_caches(Object *object)
* guaranteed to be in a known state.
*/
if (update_flag != 0) {
- DAG_id_tag_update(&object->id, update_flag);
+ DEG_id_tag_update(&object->id, update_flag);
}
}
@@ -419,6 +413,7 @@ void BKE_object_free(Object *ob)
MEM_SAFE_FREE(ob->bb);
BLI_freelistN(&ob->defbase);
+ BLI_freelistN(&ob->fmaps);
if (ob->pose) {
BKE_pose_free_ex(ob->pose, false);
ob->pose = NULL;
@@ -427,11 +422,6 @@ void BKE_object_free(Object *ob)
animviz_free_motionpath(ob->mpath);
ob->mpath = NULL;
}
- BKE_bproperty_free_list(&ob->prop);
-
- free_sensors(&ob->sensors);
- free_controllers(&ob->controllers);
- free_actuators(&ob->actuators);
BKE_constraints_free_ex(&ob->constraints, false);
@@ -443,11 +433,13 @@ void BKE_object_free(Object *ob)
sbFree(ob->soft);
ob->soft = NULL;
}
- if (ob->bsoft) {
- bsbFree(ob->bsoft);
- ob->bsoft = NULL;
+
+ for (ObjectEngineData *oed = ob->drawdata.first; oed; oed = oed->next) {
+ if (oed->free != NULL) {
+ oed->free(oed);
+ }
}
- GPU_lamp_free(ob);
+ BLI_freelistN(&ob->drawdata);
BKE_sculptsession_free(ob);
@@ -465,6 +457,9 @@ void BKE_object_free(Object *ob)
}
BKE_previewimg_free(&ob->preview);
+
+ /* don't free, let the base free it */
+ ob->base_collection_properties = NULL;
}
/* actual check for internal data, not context or flags */
@@ -511,6 +506,15 @@ bool BKE_object_is_in_editmode(const Object *ob)
return false;
}
+bool BKE_object_is_in_editmode_and_selected(const Object *ob)
+{
+ if ((ob->base_flag & BASE_SELECTED) && (BKE_object_is_in_editmode(ob))) {
+ return true;
+ }
+ return false;
+}
+
+
bool BKE_object_is_in_editmode_vgroup(const Object *ob)
{
return (OB_TYPE_SUPPORT_VGROUP(ob->type) &&
@@ -529,6 +533,66 @@ bool BKE_object_is_in_wpaint_select_vert(const Object *ob)
return false;
}
+bool BKE_object_has_mode_data(const struct Object *ob, eObjectMode object_mode)
+{
+ if (object_mode & OB_MODE_EDIT) {
+ if (BKE_object_is_in_editmode(ob)) {
+ return true;
+ }
+ }
+ else if (object_mode & OB_MODE_VERTEX_PAINT) {
+ if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) {
+ return true;
+ }
+ }
+ else if (object_mode & OB_MODE_WEIGHT_PAINT) {
+ if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) {
+ return true;
+ }
+ }
+ else if (object_mode & OB_MODE_SCULPT) {
+ if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) {
+ return true;
+ }
+ }
+ else if (object_mode & OB_MODE_POSE) {
+ if (ob->pose != NULL) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/**
+ * Return if the object is visible, as evaluated by depsgraph
+ */
+bool BKE_object_is_visible(Object *ob, const eObjectVisibilityCheck mode)
+{
+ if ((ob->base_flag & BASE_VISIBLED) == 0) {
+ return false;
+ }
+
+ if (mode == OB_VISIBILITY_CHECK_UNKNOWN_RENDER_MODE) {
+ return true;
+ }
+
+ if (((ob->transflag & OB_DUPLI) == 0) &&
+ (ob->particlesystem.first == NULL))
+ {
+ return true;
+ }
+
+ switch (mode) {
+ case OB_VISIBILITY_CHECK_FOR_VIEWPORT:
+ return ((ob->duplicator_visibility_flag & OB_DUPLI_FLAG_VIEWPORT) != 0);
+ case OB_VISIBILITY_CHECK_FOR_RENDER:
+ return ((ob->duplicator_visibility_flag & OB_DUPLI_FLAG_RENDER) != 0);
+ default:
+ BLI_assert(!"Object visible test mode not supported.");
+ return false;
+ }
+}
+
bool BKE_object_exists_check(const Object *obtest)
{
Object *ob;
@@ -582,6 +646,7 @@ void *BKE_object_obdata_add_from_type(Main *bmain, int type, const char *name)
case OB_LATTICE: return BKE_lattice_add(bmain, name);
case OB_ARMATURE: return BKE_armature_add(bmain, name);
case OB_SPEAKER: return BKE_speaker_add(bmain, name);
+ case OB_LIGHTPROBE:return BKE_lightprobe_add(bmain, name);
case OB_EMPTY: return NULL;
default:
printf("%s: Internal error, bad type: %d\n", __func__, type);
@@ -633,26 +698,10 @@ void BKE_object_init(Object *ob)
ob->dupsta = 1; ob->dupend = 100;
ob->dupfacesca = 1.0;
- /* Game engine defaults*/
- ob->mass = ob->inertia = 1.0f;
- ob->formfactor = 0.4f;
- ob->damping = 0.04f;
- ob->rdamping = 0.1f;
- ob->anisotropicFriction[0] = 1.0f;
- ob->anisotropicFriction[1] = 1.0f;
- ob->anisotropicFriction[2] = 1.0f;
- ob->gameflag = OB_PROP | OB_COLLISION;
- ob->margin = 0.04f;
- ob->init_state = 1;
- ob->state = 1;
- ob->obstacleRad = 1.0f;
- ob->step_height = 0.15f;
- ob->jump_speed = 10.0f;
- ob->fall_speed = 55.0f;
- ob->max_jumps = 1;
ob->col_group = 0x01;
ob->col_mask = 0xffff;
ob->preview = NULL;
+ ob->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
/* NT fluid sim defaults */
ob->fluidsimSettings = NULL;
@@ -673,6 +722,9 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
ob = BKE_libblock_alloc(bmain, ID_OB, name, 0);
+ /* We increase object user count when linking to SceneCollections. */
+ id_us_min(&ob->id);
+
/* default object vars */
ob->type = type;
@@ -681,163 +733,66 @@ Object *BKE_object_add_only_object(Main *bmain, int type, const char *name)
return ob;
}
-/* general add: to scene, with layer from area and default name */
-/* creates minimum required data, but without vertices etc. */
-Object *BKE_object_add(
- Main *bmain, Scene *scene,
- int type, const char *name)
+
+static Object *object_add_common(Main *bmain, ViewLayer *view_layer, int type, const char *name)
{
Object *ob;
- Base *base;
ob = BKE_object_add_only_object(bmain, type, name);
-
ob->data = BKE_object_obdata_add_from_type(bmain, type, name);
+ BKE_view_layer_base_deselect_all(view_layer);
- ob->lay = scene->lay;
-
- base = BKE_scene_base_add(scene, ob);
- BKE_scene_base_deselect_all(scene);
- BKE_scene_base_select(scene, base);
- DAG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
-
+ DEG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
return ob;
}
-
-#ifdef WITH_GAMEENGINE
-
-void BKE_object_lod_add(Object *ob)
-{
- LodLevel *lod = MEM_callocN(sizeof(LodLevel), "LoD Level");
- LodLevel *last = ob->lodlevels.last;
-
- /* If the lod list is empty, initialize it with the base lod level */
- if (!last) {
- LodLevel *base = MEM_callocN(sizeof(LodLevel), "Base LoD Level");
- BLI_addtail(&ob->lodlevels, base);
- base->flags = OB_LOD_USE_MESH | OB_LOD_USE_MAT;
- base->source = ob;
- base->obhysteresis = 10;
- last = ob->currentlod = base;
- }
-
- lod->distance = last->distance + 25.0f;
- lod->obhysteresis = 10;
- lod->flags = OB_LOD_USE_MESH | OB_LOD_USE_MAT;
-
- BLI_addtail(&ob->lodlevels, lod);
-}
-
-static int lod_cmp(const void *a, const void *b)
-{
- const LodLevel *loda = a;
- const LodLevel *lodb = b;
-
- if (loda->distance < lodb->distance) return -1;
- return loda->distance > lodb->distance;
-}
-
-void BKE_object_lod_sort(Object *ob)
-{
- BLI_listbase_sort(&ob->lodlevels, lod_cmp);
-}
-
-bool BKE_object_lod_remove(Object *ob, int level)
-{
- LodLevel *rem;
-
- if (level < 1 || level > BLI_listbase_count(&ob->lodlevels) - 1)
- return false;
-
- rem = BLI_findlink(&ob->lodlevels, level);
-
- if (rem == ob->currentlod) {
- ob->currentlod = rem->prev;
- }
-
- BLI_remlink(&ob->lodlevels, rem);
- MEM_freeN(rem);
-
- /* If there are no user defined lods, remove the base lod as well */
- if (BLI_listbase_is_single(&ob->lodlevels)) {
- LodLevel *base = ob->lodlevels.first;
- BLI_remlink(&ob->lodlevels, base);
- MEM_freeN(base);
- ob->currentlod = NULL;
- }
-
- return true;
-}
-
-static LodLevel *lod_level_select(Object *ob, const float camera_position[3])
+/**
+ * General add: to scene, with layer from area and default name
+ *
+ * Object is added to the active SceneCollection.
+ * If there is no linked collection to the active ViewLayer we create a new one.
+ */
+/* creates minimum required data, but without vertices etc. */
+Object *BKE_object_add(
+ Main *bmain, Scene *scene, ViewLayer *view_layer,
+ int type, const char *name)
{
- LodLevel *current = ob->currentlod;
- float dist_sq;
-
- if (!current) return NULL;
-
- dist_sq = len_squared_v3v3(ob->obmat[3], camera_position);
-
- if (dist_sq < SQUARE(current->distance)) {
- /* check for higher LoD */
- while (current->prev && dist_sq < SQUARE(current->distance)) {
- current = current->prev;
- }
- }
- else {
- /* check for lower LoD */
- while (current->next && dist_sq > SQUARE(current->next->distance)) {
- current = current->next;
- }
- }
+ Object *ob;
+ Base *base;
+ LayerCollection *layer_collection;
- return current;
-}
+ ob = object_add_common(bmain, view_layer, type, name);
-bool BKE_object_lod_is_usable(Object *ob, Scene *scene)
-{
- bool active = (scene) ? ob == OBACT : false;
- return (ob->mode == OB_MODE_OBJECT || !active);
-}
+ layer_collection = BKE_layer_collection_get_active_ensure(scene, view_layer);
+ BKE_collection_object_add(&scene->id, layer_collection->scene_collection, ob);
-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);
+ base = BKE_view_layer_base_find(view_layer, ob);
+ BKE_view_layer_base_select(view_layer, base);
- if (new_level != cur_level) {
- ob->currentlod = new_level;
- }
+ return ob;
}
-static Object *lod_ob_get(Object *ob, Scene *scene, int flag)
+/**
+ * Add a new object, using another one as a reference
+ *
+ * /param ob_src object to use to determine the collections of the new object.
+ */
+Object *BKE_object_add_from(
+ Main *bmain, Scene *scene, ViewLayer *view_layer,
+ int type, const char *name, Object *ob_src)
{
- LodLevel *current = ob->currentlod;
-
- if (!current || !BKE_object_lod_is_usable(ob, scene))
- return ob;
-
- while (current->prev && (!(current->flags & flag) || !current->source || current->source->type != OB_MESH)) {
- current = current->prev;
- }
+ Object *ob;
+ Base *base;
- return current->source;
-}
+ ob = object_add_common(bmain, view_layer, type, name);
+ BKE_collection_object_add_from(scene, ob_src, ob);
-struct Object *BKE_object_lod_meshob_get(Object *ob, Scene *scene)
-{
- return lod_ob_get(ob, scene, OB_LOD_USE_MESH);
-}
+ base = BKE_view_layer_base_find(view_layer, ob);
+ BKE_view_layer_base_select(view_layer, base);
-struct Object *BKE_object_lod_matob_get(Object *ob, Scene *scene)
-{
- return lod_ob_get(ob, scene, OB_LOD_USE_MAT);
+ return ob;
}
-#endif /* WITH_GAMEENGINE */
-
-
SoftBody *copy_softbody(const SoftBody *sb, const int flag)
{
SoftBody *sbn;
@@ -883,17 +838,6 @@ SoftBody *copy_softbody(const SoftBody *sb, const int flag)
return sbn;
}
-BulletSoftBody *copy_bulletsoftbody(const BulletSoftBody *bsb, const int UNUSED(flag))
-{
- BulletSoftBody *bsbn;
-
- if (bsb == NULL)
- return NULL;
- bsbn = MEM_dupallocN(bsb);
- /* no pointer in this structure yet */
- return bsbn;
-}
-
ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys, const int flag)
{
ParticleSystem *psysn;
@@ -944,10 +888,10 @@ ParticleSystem *BKE_object_copy_particlesystem(ParticleSystem *psys, const int f
psysn->effectors = NULL;
psysn->tree = NULL;
psysn->bvhtree = NULL;
+ psysn->batch_cache = NULL;
BLI_listbase_clear(&psysn->pathcachebufs);
BLI_listbase_clear(&psysn->childcachebufs);
- psysn->renderdata = NULL;
/* XXX Never copy caches here? */
psysn->pointcache = BKE_ptcache_copy_list(&psysn->ptcaches, &psys->ptcaches, flag & ~LIB_ID_COPY_CACHES);
@@ -1084,12 +1028,103 @@ Object *BKE_object_pose_armature_get(Object *ob)
ob = modifiers_isDeformedByArmature(ob);
+ /* Only use selected check when non-active. */
if (BKE_object_pose_context_check(ob))
return ob;
return NULL;
}
+Object *BKE_object_pose_armature_get_visible(Object *ob, ViewLayer *view_layer)
+{
+ Object *ob_armature = BKE_object_pose_armature_get(ob);
+ if (ob_armature) {
+ Base *base = BKE_view_layer_base_find(view_layer, ob_armature);
+ if (base) {
+ if (BASE_VISIBLE(base)) {
+ return ob_armature;
+ }
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Access pose array with special check to get pose object when in weight paint mode.
+ */
+Object **BKE_object_pose_array_get_ex(ViewLayer *view_layer, uint *r_objects_len, bool unique)
+{
+ Object *ob_active = OBACT(view_layer);
+ Object *ob_pose = BKE_object_pose_armature_get(ob_active);
+ Object **objects = NULL;
+ if (ob_pose == ob_active) {
+ objects = BKE_view_layer_array_from_objects_in_mode(
+ view_layer, r_objects_len, {
+ .object_mode = OB_MODE_POSE,
+ .no_dup_data = unique});
+ }
+ else if (ob_pose != NULL) {
+ *r_objects_len = 1;
+ objects = MEM_mallocN(sizeof(*objects), __func__);
+ objects[0] = ob_pose;
+ }
+ else {
+ *r_objects_len = 0;
+ objects = MEM_mallocN(0, __func__);
+ }
+ return objects;
+}
+Object **BKE_object_pose_array_get_unique(ViewLayer *view_layer, uint *r_objects_len)
+{
+ return BKE_object_pose_array_get_ex(view_layer, r_objects_len, true);
+}
+Object **BKE_object_pose_array_get(ViewLayer *view_layer, uint *r_objects_len)
+{
+ return BKE_object_pose_array_get_ex(view_layer, r_objects_len, false);
+}
+
+Base **BKE_object_pose_base_array_get_ex(ViewLayer *view_layer, uint *r_bases_len, bool unique)
+{
+ Base *base_active = BASACT(view_layer);
+ Object *ob_pose = base_active ? BKE_object_pose_armature_get(base_active->object) : NULL;
+ Base *base_pose = NULL;
+ Base **bases = NULL;
+
+ if (base_active) {
+ if (ob_pose == base_active->object) {
+ base_pose = base_active;
+ }
+ else {
+ base_pose = BKE_view_layer_base_find(view_layer, ob_pose);
+ }
+ }
+
+ if (base_active && (base_pose == base_active)) {
+ bases = BKE_view_layer_array_from_bases_in_mode(
+ view_layer, r_bases_len, {
+ .object_mode = OB_MODE_POSE,
+ .no_dup_data = unique});
+ }
+ else if (base_pose != NULL) {
+ *r_bases_len = 1;
+ bases = MEM_mallocN(sizeof(*bases), __func__);
+ bases[0] = base_pose;
+ }
+ else {
+ *r_bases_len = 0;
+ bases = MEM_mallocN(0, __func__);
+ }
+ return bases;
+}
+Base **BKE_object_pose_base_array_get_unique(ViewLayer *view_layer, uint *r_bases_len)
+{
+ return BKE_object_pose_base_array_get_ex(view_layer, r_bases_len, true);
+}
+Base **BKE_object_pose_base_array_get(ViewLayer *view_layer, uint *r_bases_len)
+{
+ return BKE_object_pose_base_array_get_ex(view_layer, r_bases_len, false);
+}
+
void BKE_object_transform_copy(Object *ob_tar, const Object *ob_src)
{
copy_v3_v3(ob_tar->loc, ob_src->loc);
@@ -1136,11 +1171,6 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_
BLI_addtail(&ob_dst->modifiers, nmd);
}
- BLI_listbase_clear(&ob_dst->prop);
- BKE_bproperty_copy_list(&ob_dst->prop, &ob_src->prop);
-
- BKE_sca_logic_copy(ob_dst, ob_src, flag_subdata);
-
if (ob_src->pose) {
copy_object_pose(ob_dst, ob_src, flag_subdata);
/* backwards compat... non-armatures can get poses in older files? */
@@ -1148,6 +1178,7 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_
BKE_pose_rebuild(ob_dst, ob_dst->data);
}
defgroup_copy_list(&ob_dst->defbase, &ob_src->defbase);
+ BKE_object_facemap_copy_list(&ob_dst->fmaps, &ob_src->fmaps);
BKE_constraints_copy_ex(&ob_dst->constraints, &ob_src->constraints, flag_subdata, true);
ob_dst->mode = OB_MODE_OBJECT;
@@ -1160,7 +1191,6 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_
}
}
ob_dst->soft = copy_softbody(ob_src->soft, flag_subdata);
- ob_dst->bsoft = copy_bulletsoftbody(ob_src->bsoft, flag_subdata);
ob_dst->rigidbody_object = BKE_rigidbody_copy_object(ob_src, flag_subdata);
ob_dst->rigidbody_constraint = BKE_rigidbody_copy_constraint(ob_src, flag_subdata);
@@ -1170,6 +1200,7 @@ void BKE_object_copy_data(Main *UNUSED(bmain), Object *ob_dst, const Object *ob_
ob_dst->derivedFinal = NULL;
BLI_listbase_clear(&ob_dst->gpulamp);
+ BLI_listbase_clear(&ob_dst->drawdata);
BLI_listbase_clear(&ob_dst->pc_ids);
ob_dst->mpath = NULL;
@@ -1330,8 +1361,8 @@ void BKE_object_make_proxy(Object *ob, Object *target, Object *gob)
ob->proxy_group = gob;
id_lib_extern(&target->id);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
- DAG_id_tag_update(&target->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&target->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
/* copy transform
* - gob means this proxy comes from a group, just apply the matrix
@@ -1674,13 +1705,16 @@ static bool ob_parcurve(Scene *scene, Object *ob, Object *par, float mat[4][4])
Curve *cu = par->data;
float vec[4], dir[3], quat[4], radius, ctime;
+ /* TODO: Make sure this doesn't crash. */
+#if 0
/* only happens on reload file, but violates depsgraph still... fix! */
if (par->curve_cache == NULL) {
if (scene == NULL) {
return false;
}
- BKE_displist_make_curveTypes(scene, par, 0);
+ BKE_displist_make_curveTypes(depsgraph, scene, par, 0);
}
+#endif
if (par->curve_cache->path == NULL) {
return false;
@@ -2061,8 +2095,9 @@ static bool where_is_object_parslow(Object *ob, float obmat[4][4], float slowmat
}
/* note, scene is the active scene while actual_scene is the scene the object resides in */
-void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
- RigidBodyWorld *rbw, float r_originmat[3][3])
+void BKE_object_where_is_calc_time_ex(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime,
+ RigidBodyWorld *rbw, float r_originmat[3][3])
{
if (ob == NULL) return;
@@ -2097,7 +2132,7 @@ void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
if (ob->constraints.first && !(ob->transflag & OB_NO_CONSTRAINTS)) {
bConstraintOb *cob;
cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
- BKE_constraints_solve(&ob->constraints, cob, ctime);
+ BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime);
BKE_constraints_clear_evalob(cob);
}
@@ -2106,9 +2141,9 @@ void BKE_object_where_is_calc_time_ex(Scene *scene, Object *ob, float ctime,
else ob->transflag &= ~OB_NEG_SCALE;
}
-void BKE_object_where_is_calc_time(Scene *scene, Object *ob, float ctime)
+void BKE_object_where_is_calc_time(Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
{
- BKE_object_where_is_calc_time_ex(scene, ob, ctime, NULL, NULL);
+ BKE_object_where_is_calc_time_ex(depsgraph, scene, ob, ctime, NULL, NULL);
}
/* get object transformation matrix without recalculating dependencies and
@@ -2133,17 +2168,17 @@ void BKE_object_where_is_calc_mat4(Scene *scene, Object *ob, float obmat[4][4])
}
}
-void BKE_object_where_is_calc_ex(Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
+void BKE_object_where_is_calc_ex(Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, float r_originmat[3][3])
{
- BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), rbw, r_originmat);
+ BKE_object_where_is_calc_time_ex(depsgraph, scene, ob, BKE_scene_frame_get(scene), rbw, r_originmat);
}
-void BKE_object_where_is_calc(Scene *scene, Object *ob)
+void BKE_object_where_is_calc(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
- BKE_object_where_is_calc_time_ex(scene, ob, BKE_scene_frame_get(scene), NULL, NULL);
+ BKE_object_where_is_calc_time_ex(depsgraph, scene, ob, BKE_scene_frame_get(scene), NULL, NULL);
}
/* for calculation of the inverse parent transform, only used for editor */
-void BKE_object_workob_calc_parent(Scene *scene, Object *ob, Object *workob)
+void BKE_object_workob_calc_parent(Depsgraph *depsgraph, Scene *scene, Object *ob, Object *workob)
{
BKE_object_workob_clear(workob);
@@ -2165,7 +2200,7 @@ void BKE_object_workob_calc_parent(Scene *scene, Object *ob, Object *workob)
BLI_strncpy(workob->parsubstr, ob->parsubstr, sizeof(workob->parsubstr));
- BKE_object_where_is_calc(scene, workob);
+ BKE_object_where_is_calc(depsgraph, scene, workob);
}
/* see BKE_pchan_apply_mat4() for the equivalent 'pchan' function */
@@ -2203,7 +2238,7 @@ void BKE_object_apply_mat4(Object *ob, float mat[4][4], const bool use_compat, c
BoundBox *BKE_boundbox_alloc_unit(void)
{
BoundBox *bb;
- const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {-1.0f, -1.0f, -1.0f};
+ const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {1.0f, 1.0f, 1.0f};
bb = MEM_callocN(sizeof(BoundBox), "OB-BoundBox");
BKE_boundbox_init_from_minmax(bb, min, max);
@@ -2421,7 +2456,7 @@ void BKE_object_empty_draw_type_set(Object *ob, const int value)
}
}
-bool BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
+bool BKE_object_minmax_dupli(Depsgraph *depsgraph, Scene *scene, Object *ob, float r_min[3], float r_max[3], const bool use_hidden)
{
bool ok = false;
if ((ob->transflag & OB_DUPLI) == 0) {
@@ -2430,7 +2465,7 @@ bool BKE_object_minmax_dupli(Scene *scene, Object *ob, float r_min[3], float r_m
else {
ListBase *lb;
DupliObject *dob;
- lb = object_duplilist(G.main->eval_ctx, scene, ob);
+ lb = object_duplilist(depsgraph, scene, ob);
for (dob = lb->first; dob; dob = dob->next) {
if ((use_hidden == false) && (dob->no_draw != 0)) {
/* pass */
@@ -2490,14 +2525,14 @@ void BKE_object_foreach_display_point(
}
void BKE_scene_foreach_display_point(
- Scene *scene, View3D *v3d, const short flag,
+ Depsgraph *depsgraph, Scene *scene, ViewLayer *view_layer,
void (*func_cb)(const float[3], void *), void *user_data)
{
Base *base;
Object *ob;
- for (base = FIRSTBASE; base; base = base->next) {
- if (BASE_VISIBLE_BGMODE(v3d, scene, base) && (base->flag & flag) == flag) {
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ if (((base->flag & BASE_VISIBLED) != 0) && ((base->flag & BASE_SELECTED) != 0)) {
ob = base->object;
if ((ob->transflag & OB_DUPLI) == 0) {
@@ -2507,7 +2542,7 @@ void BKE_scene_foreach_display_point(
ListBase *lb;
DupliObject *dob;
- lb = object_duplilist(G.main->eval_ctx, scene, ob);
+ lb = object_duplilist(depsgraph, scene, ob);
for (dob = lb->first; dob; dob = dob->next) {
if (dob->no_draw == 0) {
BKE_object_foreach_display_point(dob->ob, dob->mat, func_cb, user_data);
@@ -2530,7 +2565,7 @@ typedef struct ObTfmBack {
float obmat[4][4]; /* final worldspace matrix with constraints & animsys applied */
float parentinv[4][4]; /* inverse result of parent, so that object doesn't 'stick' to parent */
float constinv[4][4]; /* inverse result of constraints. doesn't include effect of parent or object local transform */
- float imat[4][4]; /* inverse matrix of 'obmat' for during render, old game engine, temporally: ipokeys of transform */
+ float imat[4][4]; /* inverse matrix of 'obmat' for during render, temporally: ipokeys of transform */
} ObTfmBack;
void *BKE_object_tfm_backup(Object *ob)
@@ -2587,7 +2622,7 @@ bool BKE_object_parent_loop_check(const Object *par, const Object *ob)
return BKE_object_parent_loop_check(par->parent, ob);
}
-static void object_handle_update_proxy(EvaluationContext *eval_ctx,
+static void object_handle_update_proxy(Depsgraph *depsgraph,
Scene *scene,
Object *object,
const bool do_proxy_update)
@@ -2604,7 +2639,7 @@ static void object_handle_update_proxy(EvaluationContext *eval_ctx,
if (object->proxy_group == NULL) {
if (do_proxy_update) {
// printf("call update, lib ob %s proxy %s\n", ob->proxy->id.name, ob->id.name);
- BKE_object_handle_update(eval_ctx, scene, object->proxy);
+ BKE_object_handle_update(depsgraph, scene, object->proxy);
}
}
}
@@ -2617,13 +2652,18 @@ static void object_handle_update_proxy(EvaluationContext *eval_ctx,
/* the main object update call, for object matrix, constraints, keys and displist (modifiers) */
/* requires flags to be set! */
/* Ideally we shouldn't have to pass the rigid body world, but need bigger restructuring to avoid id */
-void BKE_object_handle_update_ex(EvaluationContext *eval_ctx,
+void BKE_object_handle_update_ex(Depsgraph *depsgraph,
Scene *scene, Object *ob,
RigidBodyWorld *rbw,
const bool do_proxy_update)
{
- if ((ob->recalc & OB_RECALC_ALL) == 0) {
- object_handle_update_proxy(eval_ctx, scene, ob, do_proxy_update);
+ const ID *object_data = ob->data;
+ const bool recalc_object = (ob->id.recalc & ID_RECALC) != 0;
+ const bool recalc_data =
+ (object_data != NULL) ? ((object_data->recalc & ID_RECALC_ALL) != 0)
+ : 0;
+ if (!recalc_object && ! recalc_data) {
+ object_handle_update_proxy(depsgraph, scene, ob, do_proxy_update);
return;
}
/* Speed optimization for animation lookups. */
@@ -2633,7 +2673,7 @@ void BKE_object_handle_update_ex(EvaluationContext *eval_ctx,
BKE_pose_update_constraint_flags(ob->pose);
}
}
- if (ob->recalc & OB_RECALC_DATA) {
+ if (recalc_data) {
if (ob->type == OB_ARMATURE) {
/* this happens for reading old files and to match library armatures
* with poses we do it ahead of BKE_object_where_is_calc to ensure animation
@@ -2646,23 +2686,23 @@ void BKE_object_handle_update_ex(EvaluationContext *eval_ctx,
/* XXX new animsys warning: depsgraph tag OB_RECALC_DATA should not skip drivers,
* which is only in BKE_object_where_is_calc now */
/* XXX: should this case be OB_RECALC_OB instead? */
- if (ob->recalc & OB_RECALC_ALL) {
+ if (recalc_object || recalc_data) {
if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
printf("recalcob %s\n", ob->id.name + 2);
}
/* Handle proxy copy for target. */
- if (!BKE_object_eval_proxy_copy(eval_ctx, ob)) {
- BKE_object_where_is_calc_ex(scene, rbw, ob, NULL);
+ if (!BKE_object_eval_proxy_copy(depsgraph, ob)) {
+ BKE_object_where_is_calc_ex(depsgraph, scene, rbw, ob, NULL);
}
}
- if (ob->recalc & OB_RECALC_DATA) {
- BKE_object_handle_data_update(eval_ctx, scene, ob);
+ if (recalc_data) {
+ BKE_object_handle_data_update(depsgraph, scene, ob);
}
- ob->recalc &= ~OB_RECALC_ALL;
+ ob->id.recalc &= ID_RECALC_ALL;
- object_handle_update_proxy(eval_ctx, scene, ob, do_proxy_update);
+ object_handle_update_proxy(depsgraph, scene, ob, do_proxy_update);
}
/* WARNING: "scene" here may not be the scene object actually resides in.
@@ -2670,9 +2710,9 @@ void BKE_object_handle_update_ex(EvaluationContext *eval_ctx,
* e.g. "scene" <-- set 1 <-- set 2 ("ob" lives here) <-- set 3 <-- ... <-- set n
* rigid bodies depend on their world so use BKE_object_handle_update_ex() to also pass along the corrent rigid body world
*/
-void BKE_object_handle_update(EvaluationContext *eval_ctx, Scene *scene, Object *ob)
+void BKE_object_handle_update(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
- BKE_object_handle_update_ex(eval_ctx, scene, ob, NULL, true);
+ BKE_object_handle_update_ex(depsgraph, scene, ob, NULL, true);
}
void BKE_object_sculpt_modifiers_changed(Object *ob)
@@ -2717,14 +2757,7 @@ int BKE_object_obdata_texspace_get(Object *ob, short **r_texflag, float **r_loc,
switch (GS(((ID *)ob->data)->name)) {
case ID_ME:
{
- Mesh *me = ob->data;
- if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
- BKE_mesh_texspace_calc(me);
- }
- if (r_texflag) *r_texflag = &me->texflag;
- if (r_loc) *r_loc = me->loc;
- if (r_size) *r_size = me->size;
- if (r_rot) *r_rot = me->rot;
+ BKE_mesh_texspace_get_reference((Mesh *)ob->data, r_texflag, r_loc, r_rot, r_size);
break;
}
case ID_CU:
@@ -3291,33 +3324,33 @@ static void obrel_list_add(LinkNode **links, Object *ob)
}
/*
- * Iterates over all objects of the given scene.
+ * Iterates over all objects of the given scene layer.
* Depending on the eObjectSet flag:
* collect either OB_SET_ALL, OB_SET_VISIBLE or OB_SET_SELECTED objects.
* If OB_SET_VISIBLE or OB_SET_SELECTED are collected,
* then also add related objects according to the given includeFilters.
*/
-LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet objectSet, eObRelationTypes includeFilter)
+LinkNode *BKE_object_relational_superset(struct ViewLayer *view_layer, eObjectSet objectSet, eObRelationTypes includeFilter)
{
LinkNode *links = NULL;
Base *base;
/* Remove markers from all objects */
- for (base = scene->base.first; base; base = base->next) {
+ for (base = view_layer->object_bases.first; base; base = base->next) {
base->object->id.tag &= ~LIB_TAG_DOIT;
}
/* iterate over all selected and visible objects */
- for (base = scene->base.first; base; base = base->next) {
+ for (base = view_layer->object_bases.first; base; base = base->next) {
if (objectSet == OB_SET_ALL) {
/* as we get all anyways just add it */
Object *ob = base->object;
obrel_list_add(&links, ob);
}
else {
- if ((objectSet == OB_SET_SELECTED && TESTBASELIB_BGMODE(((View3D *)NULL), scene, base)) ||
- (objectSet == OB_SET_VISIBLE && BASE_EDITABLE_BGMODE(((View3D *)NULL), scene, base)))
+ if ((objectSet == OB_SET_SELECTED && TESTBASELIB_BGMODE(base)) ||
+ (objectSet == OB_SET_VISIBLE && BASE_EDITABLE_BGMODE(base)))
{
Object *ob = base->object;
@@ -3346,8 +3379,8 @@ LinkNode *BKE_object_relational_superset(struct Scene *scene, eObjectSet objectS
/* child relationship */
if (includeFilter & (OB_REL_CHILDREN | OB_REL_CHILDREN_RECURSIVE)) {
Base *local_base;
- for (local_base = scene->base.first; local_base; local_base = local_base->next) {
- if (BASE_EDITABLE_BGMODE(((View3D *)NULL), scene, local_base)) {
+ for (local_base = view_layer->object_bases.first; local_base; local_base = local_base->next) {
+ if (BASE_EDITABLE_BGMODE(local_base)) {
Object *child = local_base->object;
if (obrel_list_test(child)) {
@@ -3391,18 +3424,11 @@ struct LinkNode *BKE_object_groups(Object *ob)
return group_linknode;
}
-void BKE_object_groups_clear(Scene *scene, Base *base, Object *object)
+void BKE_object_groups_clear(Object *ob)
{
Group *group = NULL;
-
- BLI_assert((base == NULL) || (base->object == object));
-
- if (scene && base == NULL) {
- base = BKE_scene_base_find(scene, object);
- }
-
- while ((group = BKE_group_object_find(group, base->object))) {
- BKE_group_object_unlink(group, object, scene, base);
+ while ((group = BKE_group_object_find(group, ob))) {
+ BKE_group_object_unlink(group, ob);
}
}
@@ -3603,9 +3629,9 @@ static void object_cacheIgnoreClear(Object *ob, int state)
/* Note: this function should eventually be replaced by depsgraph functionality.
* Avoid calling this in new code unless there is a very good reason for it!
*/
-bool BKE_object_modifier_update_subframe(Scene *scene, Object *ob, bool update_mesh,
- int parent_recursion, float frame,
- int type)
+bool BKE_object_modifier_update_subframe(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, bool update_mesh,
+ int parent_recursion, float frame, int type)
{
ModifierData *md = modifiers_findByType(ob, (ModifierType)type);
bConstraint *con;
@@ -3628,8 +3654,8 @@ bool BKE_object_modifier_update_subframe(Scene *scene, Object *ob, bool update_m
if (parent_recursion) {
int recursion = parent_recursion - 1;
bool no_update = false;
- if (ob->parent) no_update |= BKE_object_modifier_update_subframe(scene, ob->parent, 0, recursion, frame, type);
- if (ob->track) no_update |= BKE_object_modifier_update_subframe(scene, ob->track, 0, recursion, frame, type);
+ if (ob->parent) no_update |= BKE_object_modifier_update_subframe(depsgraph, scene, ob->parent, 0, recursion, frame, type);
+ if (ob->track) no_update |= BKE_object_modifier_update_subframe(depsgraph, scene, ob->track, 0, recursion, frame, type);
/* skip subframe if object is parented
* to vertex of a dynamic paint canvas */
@@ -3646,7 +3672,7 @@ bool BKE_object_modifier_update_subframe(Scene *scene, Object *ob, bool update_m
cti->get_constraint_targets(con, &targets);
for (ct = targets.first; ct; ct = ct->next) {
if (ct->tar)
- BKE_object_modifier_update_subframe(scene, ct->tar, 0, recursion, frame, type);
+ BKE_object_modifier_update_subframe(depsgraph, scene, ct->tar, 0, recursion, frame, type);
}
/* free temp targets */
if (cti->flush_constraint_targets)
@@ -3656,17 +3682,18 @@ bool BKE_object_modifier_update_subframe(Scene *scene, Object *ob, bool update_m
}
/* was originally OB_RECALC_ALL - TODO - which flags are really needed??? */
- ob->recalc |= OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME;
+ /* TODO(sergey): What about animation? */
+ ob->id.recalc |= ID_RECALC_ALL;
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, frame, ADT_RECALC_ANIM);
if (update_mesh) {
/* ignore cache clear during subframe updates
* to not mess up cache validity */
object_cacheIgnoreClear(ob, 1);
- BKE_object_handle_update(G.main->eval_ctx, scene, ob);
+ BKE_object_handle_update(depsgraph, scene, ob);
object_cacheIgnoreClear(ob, 0);
}
else
- BKE_object_where_is_calc_time(scene, ob, frame);
+ BKE_object_where_is_calc_time(depsgraph, scene, ob, frame);
/* for curve following objects, parented curve has to be updated too */
if (ob->type == OB_CURVE) {
@@ -3677,7 +3704,7 @@ bool BKE_object_modifier_update_subframe(Scene *scene, Object *ob, bool update_m
if (ob->type == OB_ARMATURE) {
bArmature *arm = ob->data;
BKE_animsys_evaluate_animdata(scene, &arm->id, arm->adt, frame, ADT_RECALC_ANIM);
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
}
return false;
diff --git a/source/blender/blenkernel/intern/object_deform.c b/source/blender/blenkernel/intern/object_deform.c
index 61533e13d7a..fb2e824b299 100644
--- a/source/blender/blenkernel/intern/object_deform.c
+++ b/source/blender/blenkernel/intern/object_deform.c
@@ -51,6 +51,7 @@
#include "BKE_editmesh.h"
#include "BKE_object_deform.h" /* own include */
#include "BKE_object.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
/** \name Misc helpers
@@ -405,6 +406,8 @@ void BKE_object_defgroup_remove(Object *ob, bDeformGroup *defgroup)
object_defgroup_remove_edit_mode(ob, defgroup);
else
object_defgroup_remove_object_mode(ob, defgroup);
+
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
}
/**
diff --git a/source/blender/blenkernel/intern/object_dupli.c b/source/blender/blenkernel/intern/object_dupli.c
index 56d5cb609fc..eafd2d95cf1 100644
--- a/source/blender/blenkernel/intern/object_dupli.c
+++ b/source/blender/blenkernel/intern/object_dupli.c
@@ -49,10 +49,10 @@
#include "BKE_animsys.h"
#include "BKE_DerivedMesh.h"
-#include "BKE_depsgraph.h"
#include "BKE_font.h"
-#include "BKE_group.h"
#include "BKE_global.h"
+#include "BKE_group.h"
+#include "BKE_idprop.h"
#include "BKE_lattice.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
@@ -62,6 +62,8 @@
#include "BKE_editmesh.h"
#include "BKE_anim.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "BLI_strict_flags.h"
#include "BLI_hash.h"
@@ -69,15 +71,16 @@
/* Dupli-Geometry */
typedef struct DupliContext {
- EvaluationContext *eval_ctx;
+ Depsgraph *depsgraph;
bool do_update;
bool animated;
Group *group; /* XXX child objects are selected from this group if set, could be nicer */
+ Object *obedit; /* Only to check if the object is in edit-mode. */
Scene *scene;
+ ViewLayer *view_layer;
Object *object;
float space_mat[4][4];
- unsigned int lay;
int persistent_id[MAX_DUPLI_RECUR];
int level;
@@ -96,21 +99,22 @@ typedef struct DupliGenerator {
static const DupliGenerator *get_dupli_generator(const DupliContext *ctx);
/* create initial context for root object */
-static void init_context(DupliContext *r_ctx, EvaluationContext *eval_ctx, Scene *scene, Object *ob, float space_mat[4][4], bool update)
+static void init_context(DupliContext *r_ctx, Depsgraph *depsgraph, Scene *scene, Object *ob, float space_mat[4][4], bool update)
{
- r_ctx->eval_ctx = eval_ctx;
+ r_ctx->depsgraph = depsgraph;
r_ctx->scene = scene;
+ r_ctx->view_layer = DEG_get_evaluated_view_layer(depsgraph);
/* don't allow BKE_object_handle_update for viewport during render, can crash */
- r_ctx->do_update = update && !(G.is_rendering && eval_ctx->mode != DAG_EVAL_RENDER);
+ r_ctx->do_update = update && !(G.is_rendering && DEG_get_mode(depsgraph) != DAG_EVAL_RENDER);
r_ctx->animated = false;
r_ctx->group = NULL;
r_ctx->object = ob;
+ r_ctx->obedit = OBEDIT_FROM_OBACT(ob);
if (space_mat)
copy_m4_m4(r_ctx->space_mat, space_mat);
else
unit_m4(r_ctx->space_mat);
- r_ctx->lay = ob->lay;
r_ctx->level = 0;
r_ctx->gen = get_dupli_generator(r_ctx);
@@ -143,7 +147,8 @@ static void copy_dupli_context(DupliContext *r_ctx, const DupliContext *ctx, Obj
*/
static DupliObject *make_dupli(const DupliContext *ctx,
Object *ob, float mat[4][4], int index,
- bool animated, bool hide)
+ bool animated, bool hide,
+ IDProperty *collection_properties)
{
DupliObject *dob;
int i;
@@ -198,6 +203,10 @@ static DupliObject *make_dupli(const DupliContext *ctx,
dob->random_id ^= BLI_hash_int(BLI_hash_string(ctx->object->id.name + 2));
}
+ if (collection_properties) {
+ dob->collection_properties = IDP_CopyProperty(collection_properties);
+ }
+
return dob;
}
@@ -235,35 +244,32 @@ static bool is_child(const Object *ob, const Object *parent)
static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChildDuplisFunc make_child_duplis_cb)
{
Object *parent = ctx->object;
- Object *obedit = ctx->scene->obedit;
if (ctx->group) {
- unsigned int lay = ctx->group->layer;
int groupid = 0;
- GroupObject *go;
- for (go = ctx->group->gobject.first; go; go = go->next, groupid++) {
- Object *ob = go->ob;
-
- if ((ob->lay & lay) && ob != obedit && is_child(ob, parent)) {
+ FOREACH_GROUP_BASE_BEGIN(ctx->group, base)
+ {
+ Object *ob = base->object;
+ if ((base->flag & BASE_VISIBLED) && ob != ctx->obedit && is_child(ob, parent)) {
DupliContext pctx;
copy_dupli_context(&pctx, ctx, ctx->object, NULL, groupid, false);
/* mballs have a different dupli handling */
- if (ob->type != OB_MBALL)
+ if (ob->type != OB_MBALL) {
ob->flag |= OB_DONE; /* doesnt render */
-
+ }
make_child_duplis_cb(&pctx, userdata, ob);
}
+ groupid++;
}
+ FOREACH_GROUP_BASE_END
}
else {
- unsigned int lay = ctx->scene->lay;
int baseid = 0;
- Base *base;
- for (base = ctx->scene->base.first; base; base = base->next, baseid++) {
+ ViewLayer *view_layer = ctx->view_layer;
+ for (Base *base = view_layer->object_bases.first; base; base = base->next, baseid++) {
Object *ob = base->object;
-
- if ((base->lay & lay) && ob != obedit && is_child(ob, parent)) {
+ if ((ob != ctx->obedit) && is_child(ob, parent)) {
DupliContext pctx;
copy_dupli_context(&pctx, ctx, ctx->object, NULL, baseid, false);
@@ -283,13 +289,12 @@ static void make_child_duplis(const DupliContext *ctx, void *userdata, MakeChild
/* OB_DUPLIGROUP */
static void make_duplis_group(const DupliContext *ctx)
{
- bool for_render = (ctx->eval_ctx->mode == DAG_EVAL_RENDER);
Object *ob = ctx->object;
Group *group;
- GroupObject *go;
+ Base *base;
float group_mat[4][4];
int id;
- bool animated, hide;
+ bool animated;
if (ob->dup_group == NULL) return;
group = ob->dup_group;
@@ -306,39 +311,23 @@ static void make_duplis_group(const DupliContext *ctx)
if (ctx->do_update) {
/* note: update is optional because we don't always need object
* transformations to be correct. Also fixes bug [#29616]. */
- BKE_group_handle_recalc_and_update(ctx->eval_ctx, ctx->scene, ob, group);
+ BKE_group_handle_recalc_and_update(ctx->depsgraph, ctx->scene, ob, group);
}
animated = BKE_group_is_animated(group, ob);
- for (go = group->gobject.first, id = 0; go; go = go->next, id++) {
- /* note, if you check on layer here, render goes wrong... it still deforms verts and uses parent imat */
- if (go->ob != ob) {
+ for (base = group->view_layer->object_bases.first, id = 0; base; base = base->next, id++) {
+ if (base->object != ob && (base->flag & BASE_VISIBLED)) {
float mat[4][4];
- /* Special case for instancing dupli-groups, see: T40051
- * this object may be instanced via dupli-verts/faces, in this case we don't want to render
- * (blender convention), but _do_ show in the viewport.
- *
- * Regular objects work fine but not if we're instancing dupli-groups,
- * because the rules for rendering aren't applied to objects they instance.
- * We could recursively pass down the 'hide' flag instead, but that seems unnecessary.
- */
- if (for_render && go->ob->parent && go->ob->parent->transflag & (OB_DUPLIVERTS | OB_DUPLIFACES)) {
- continue;
- }
-
/* group dupli offset, should apply after everything else */
- mul_m4_m4m4(mat, group_mat, go->ob->obmat);
+ mul_m4_m4m4(mat, group_mat, base->object->obmat);
- /* check the group instance and object layers match, also that the object visible flags are ok. */
- hide = (go->ob->lay & group->layer) == 0 ||
- (for_render ? go->ob->restrictflag & OB_RESTRICT_RENDER : go->ob->restrictflag & OB_RESTRICT_VIEW);
-
- make_dupli(ctx, go->ob, mat, id, animated, hide);
+ BLI_assert(base->collection_properties != NULL);
+ make_dupli(ctx, base->object, mat, id, animated, false, base->collection_properties);
/* recursion */
- make_recursive_duplis(ctx, go->ob, group_mat, id, animated);
+ make_recursive_duplis(ctx, base->object, group_mat, id, animated);
}
}
}
@@ -377,10 +366,6 @@ static void make_duplis_frames(const DupliContext *ctx)
/* duplicate over the required range */
if (ob->transflag & OB_DUPLINOSPEED) enable_cu_speed = 0;
- /* special flag to avoid setting recalc flags to notify the depsgraph of
- * updates, as this is not a permanent change to the object */
- ob->id.recalc |= ID_RECALC_SKIP_ANIM_TAG;
-
for (scene->r.cfra = ob->dupsta; scene->r.cfra <= dupend; scene->r.cfra++) {
int ok = 1;
@@ -399,9 +384,9 @@ static void make_duplis_frames(const DupliContext *ctx)
* However, this has always been the way that this worked (i.e. pre 2.5), so I guess that it'll be fine!
*/
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */
- BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
+ BKE_object_where_is_calc_time(ctx->depsgraph, scene, ob, (float)scene->r.cfra);
- make_dupli(ctx, ob, ob->obmat, scene->r.cfra, false, false);
+ make_dupli(ctx, ob, ob->obmat, scene->r.cfra, false, false, NULL);
}
}
@@ -413,7 +398,7 @@ static void make_duplis_frames(const DupliContext *ctx)
scene->r.cfra = cfrao;
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, (float)scene->r.cfra, ADT_RECALC_ANIM); /* ob-eval will do drivers, so we don't need to do them */
- BKE_object_where_is_calc_time(scene, ob, (float)scene->r.cfra);
+ BKE_object_where_is_calc_time(ctx->depsgraph, scene, ob, (float)scene->r.cfra);
/* but, to make sure unkeyed object transforms are still sane,
* let's copy object's original data back over
@@ -486,7 +471,7 @@ static void vertex_dupli__mapFunc(void *userData, int index, const float co[3],
*/
mul_m4_m4m4(space_mat, obmat, inst_ob->imat);
- dob = make_dupli(vdd->ctx, vdd->inst_ob, obmat, index, false, false);
+ dob = make_dupli(vdd->ctx, vdd->inst_ob, obmat, index, false, false, NULL);
if (vdd->orco)
copy_v3_v3(dob->orco, vdd->orco[index]);
@@ -535,7 +520,7 @@ static void make_duplis_verts(const DupliContext *ctx)
{
Scene *scene = ctx->scene;
Object *parent = ctx->object;
- bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
+ bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
VertexDupliData vdd;
vdd.ctx = ctx;
@@ -547,14 +532,14 @@ static void make_duplis_verts(const DupliContext *ctx)
BMEditMesh *em = BKE_editmesh_from_object(parent);
CustomDataMask dm_mask = (use_texcoords ? CD_MASK_BAREMESH | CD_MASK_ORCO : CD_MASK_BAREMESH);
- if (ctx->eval_ctx->mode == DAG_EVAL_RENDER) {
- vdd.dm = mesh_create_derived_render(scene, parent, dm_mask);
+ if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER) {
+ vdd.dm = mesh_create_derived_render(ctx->depsgraph, scene, parent, dm_mask);
}
else if (em) {
- vdd.dm = editbmesh_get_derived_cage(scene, parent, em, dm_mask);
+ vdd.dm = editbmesh_get_derived_cage(ctx->depsgraph, scene, parent, em, dm_mask);
}
else {
- vdd.dm = mesh_get_derived_final(scene, parent, dm_mask);
+ vdd.dm = mesh_get_derived_final(ctx->depsgraph, scene, parent, dm_mask);
}
vdd.edit_btmesh = me->edit_btmesh;
@@ -671,7 +656,7 @@ static void make_duplis_font(const DupliContext *ctx)
copy_v3_v3(obmat[3], vec);
- make_dupli(ctx, ob, obmat, a, false, false);
+ make_dupli(ctx, ob, obmat, a, false, false, NULL);
}
}
@@ -739,7 +724,7 @@ static void make_child_duplis_faces(const DupliContext *ctx, void *userdata, Obj
float (*orco)[3] = fdd->orco;
MLoopUV *mloopuv = fdd->mloopuv;
int a, totface = fdd->totface;
- bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
+ bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
float child_imat[4][4];
DupliObject *dob;
@@ -777,7 +762,7 @@ static void make_child_duplis_faces(const DupliContext *ctx, void *userdata, Obj
*/
mul_m4_m4m4(space_mat, obmat, inst_ob->imat);
- dob = make_dupli(ctx, inst_ob, obmat, a, false, false);
+ dob = make_dupli(ctx, inst_ob, obmat, a, false, false, NULL);
if (use_texcoords) {
float w = 1.0f / (float)mp->totloop;
@@ -805,7 +790,7 @@ static void make_duplis_faces(const DupliContext *ctx)
{
Scene *scene = ctx->scene;
Object *parent = ctx->object;
- bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
+ bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
FaceDupliData fdd;
fdd.use_scale = ((parent->transflag & OB_DUPLIFACES_SCALE) != 0);
@@ -815,14 +800,14 @@ static void make_duplis_faces(const DupliContext *ctx)
BMEditMesh *em = BKE_editmesh_from_object(parent);
CustomDataMask dm_mask = (use_texcoords ? CD_MASK_BAREMESH | CD_MASK_ORCO | CD_MASK_MLOOPUV : CD_MASK_BAREMESH);
- if (ctx->eval_ctx->mode == DAG_EVAL_RENDER) {
- fdd.dm = mesh_create_derived_render(scene, parent, dm_mask);
+ if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER) {
+ fdd.dm = mesh_create_derived_render(ctx->depsgraph, scene, parent, dm_mask);
}
else if (em) {
- fdd.dm = editbmesh_get_derived_cage(scene, parent, em, dm_mask);
+ fdd.dm = editbmesh_get_derived_cage(ctx->depsgraph, scene, parent, em, dm_mask);
}
else {
- fdd.dm = mesh_get_derived_final(scene, parent, dm_mask);
+ fdd.dm = mesh_get_derived_final(ctx->depsgraph, scene, parent, dm_mask);
}
if (use_texcoords) {
@@ -857,10 +842,9 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
{
Scene *scene = ctx->scene;
Object *par = ctx->object;
- bool for_render = ctx->eval_ctx->mode == DAG_EVAL_RENDER;
- bool use_texcoords = ELEM(ctx->eval_ctx->mode, DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
+ bool for_render = DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER;
+ bool use_texcoords = ELEM(DEG_get_mode(ctx->depsgraph), DAG_EVAL_RENDER, DAG_EVAL_PREVIEW);
- GroupObject *go;
Object *ob = NULL, **oblist = NULL, obcopy, *obcopylist = NULL;
DupliObject *dob;
ParticleDupliWeight *dw;
@@ -874,7 +858,6 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
float (*obmat)[4];
int a, b, hair = 0;
int totpart, totchild, totgroup = 0 /*, pa_num */;
- const bool dupli_type_hack = !BKE_scene_use_new_shading_nodes(scene);
int no_draw_flag = PARS_UNEXIST;
@@ -885,7 +868,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
if (part == NULL)
return;
- if (!psys_check_enabled(par, psys, (ctx->eval_ctx->mode == DAG_EVAL_RENDER)))
+ if (!psys_check_enabled(par, psys, (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER)))
return;
if (!for_render)
@@ -898,8 +881,9 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
BLI_srandom((unsigned int)(31415926 + psys->seed));
- if ((psys->renderdata || part->draw_as == PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
+ if ((for_render || part->draw_as == PART_DRAW_REND) && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
ParticleSimulationData sim = {NULL};
+ sim.depsgraph = ctx->depsgraph;
sim.scene = scene;
sim.ob = par;
sim.psys = psys;
@@ -913,10 +897,10 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
return;
}
else { /*PART_DRAW_GR */
- if (part->dup_group == NULL || BLI_listbase_is_empty(&part->dup_group->gobject))
+ if (part->dup_group == NULL || BLI_listbase_is_empty(&part->dup_group->view_layer->object_bases))
return;
- if (BLI_findptr(&part->dup_group->gobject, par, offsetof(GroupObject, ob))) {
+ if (BLI_findptr(&part->dup_group->view_layer->object_bases, par, offsetof(Base, object))) {
return;
}
}
@@ -940,7 +924,7 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
/* gather list of objects or single object */
if (part->ren_as == PART_DRAW_GR) {
if (ctx->do_update) {
- BKE_group_handle_recalc_and_update(ctx->eval_ctx, scene, par, part->dup_group);
+ BKE_group_handle_recalc_and_update(ctx->depsgraph, scene, par, part->dup_group);
}
if (part->draw & PART_DRAW_COUNT_GR) {
@@ -948,8 +932,12 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
totgroup += dw->count;
}
else {
- for (go = part->dup_group->gobject.first; go; go = go->next)
+ FOREACH_GROUP_OBJECT_BEGIN(part->dup_group, object)
+ {
+ (void) object;
totgroup++;
+ }
+ FOREACH_GROUP_OBJECT_END;
}
/* we also copy the actual objects to restore afterwards, since
@@ -968,11 +956,18 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
}
}
else {
- go = part->dup_group->gobject.first;
- for (a = 0; a < totgroup; a++, go = go->next) {
- oblist[a] = go->ob;
- obcopylist[a] = *go->ob;
+ a = 0;
+ FOREACH_GROUP_OBJECT_BEGIN(part->dup_group, object)
+ {
+ oblist[a] = object;
+ obcopylist[a] = *object;
+ a++;
+
+ if (a >= totgroup) {
+ continue;
+ }
}
+ FOREACH_GROUP_OBJECT_END;
}
}
else {
@@ -1061,27 +1056,37 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
}
if (part->ren_as == PART_DRAW_GR && psys->part->draw & PART_DRAW_WHOLE_GR) {
- for (go = part->dup_group->gobject.first, b = 0; go; go = go->next, b++) {
-
+ b = 0;
+ FOREACH_GROUP_OBJECT_BEGIN(part->dup_group, object)
+ {
copy_m4_m4(tmat, oblist[b]->obmat);
+
/* apply particle scale */
mul_mat3_m4_fl(tmat, size * scale);
mul_v3_fl(tmat[3], size * scale);
+
/* group dupli offset, should apply after everything else */
- if (!is_zero_v3(part->dup_group->dupli_ofs))
+ if (!is_zero_v3(part->dup_group->dupli_ofs)) {
sub_v3_v3(tmat[3], part->dup_group->dupli_ofs);
+ }
+
/* individual particle transform */
mul_m4_m4m4(mat, pamat, tmat);
- dob = make_dupli(ctx, go->ob, mat, a, false, false);
+ dob = make_dupli(ctx, object, mat, a, false, false, NULL);
dob->particle_system = psys;
- if (use_texcoords)
+
+ if (use_texcoords) {
psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
+ }
+
+ b++;
}
+ FOREACH_GROUP_OBJECT_END;
}
else {
/* to give ipos in object correct offset */
- BKE_object_where_is_calc_time(scene, ob, ctime - pa_time);
+ BKE_object_where_is_calc_time(ctx->depsgraph, scene, ob, ctime - pa_time);
copy_v3_v3(vec, obmat[3]);
obmat[3][0] = obmat[3][1] = obmat[3][2] = 0.0f;
@@ -1122,14 +1127,10 @@ static void make_duplis_particle_system(const DupliContext *ctx, ParticleSystem
if (part->draw & PART_DRAW_GLOBAL_OB)
add_v3_v3v3(mat[3], mat[3], vec);
- dob = make_dupli(ctx, ob, mat, a, false, false);
+ dob = make_dupli(ctx, ob, mat, a, false, false, NULL);
dob->particle_system = psys;
if (use_texcoords)
psys_get_dupli_texture(psys, part, sim.psmd, pa, cpa, dob->uv, dob->orco);
- /* XXX blender internal needs this to be set to dupligroup to render
- * groups correctly, but we don't want this hack for cycles */
- if (dupli_type_hack && ctx->group)
- dob->type = OB_DUPLIGROUP;
}
}
@@ -1185,7 +1186,7 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx)
return NULL;
/* Should the dupli's be generated for this object? - Respect restrict flags */
- if (ctx->eval_ctx->mode == DAG_EVAL_RENDER ? (restrictflag & OB_RESTRICT_RENDER) : (restrictflag & OB_RESTRICT_VIEW))
+ if (DEG_get_mode(ctx->depsgraph) == DAG_EVAL_RENDER ? (restrictflag & OB_RESTRICT_RENDER) : (restrictflag & OB_RESTRICT_VIEW))
return NULL;
if (transflag & OB_DUPLIPARTS) {
@@ -1217,11 +1218,11 @@ static const DupliGenerator *get_dupli_generator(const DupliContext *ctx)
/* ---- ListBase dupli container implementation ---- */
/* Returns a list of DupliObject */
-ListBase *object_duplilist_ex(EvaluationContext *eval_ctx, Scene *scene, Object *ob, bool update)
+ListBase *object_duplilist_ex(Depsgraph *depsgraph, Scene *scene, Object *ob, bool update)
{
ListBase *duplilist = MEM_callocN(sizeof(ListBase), "duplilist");
DupliContext ctx;
- init_context(&ctx, eval_ctx, scene, ob, NULL, update);
+ init_context(&ctx, depsgraph, scene, ob, NULL, update);
if (ctx.gen) {
ctx.duplilist = duplilist;
ctx.gen->make_duplis(&ctx);
@@ -1232,13 +1233,21 @@ ListBase *object_duplilist_ex(EvaluationContext *eval_ctx, Scene *scene, Object
/* note: previously updating was always done, this is why it defaults to be on
* but there are likely places it can be called without updating */
-ListBase *object_duplilist(EvaluationContext *eval_ctx, Scene *sce, Object *ob)
+ListBase *object_duplilist(Depsgraph *depsgraph, Scene *sce, Object *ob)
{
- return object_duplilist_ex(eval_ctx, sce, ob, true);
+ return object_duplilist_ex(depsgraph, sce, ob, true);
}
void free_object_duplilist(ListBase *lb)
{
+
+ for (DupliObject *dob = lb->first; dob; dob = dob->next) {
+ if (dob->collection_properties) {
+ IDP_FreeProperty(dob->collection_properties);
+ MEM_freeN(dob->collection_properties);
+ }
+ }
+
BLI_freelistN(lb);
MEM_freeN(lb);
}
@@ -1273,7 +1282,7 @@ int count_duplilist(Object *ob)
return 1;
}
-DupliApplyData *duplilist_apply(Object *ob, Scene *scene, ListBase *duplilist)
+DupliApplyData *duplilist_apply(Depsgraph *depsgraph, Object *ob, Scene *scene, ListBase *duplilist)
{
DupliApplyData *apply_data = NULL;
int num_objects = BLI_listbase_count(duplilist);
@@ -1289,7 +1298,7 @@ DupliApplyData *duplilist_apply(Object *ob, Scene *scene, ListBase *duplilist)
for (dob = duplilist->first, i = 0; dob; dob = dob->next, ++i) {
/* make sure derivedmesh is calculated once, before drawing */
if (scene && !(dob->ob->transflag & OB_DUPLICALCDERIVED) && dob->ob->type == OB_MESH) {
- mesh_get_derived_final(scene, dob->ob, scene->customdata_mask);
+ mesh_get_derived_final(depsgraph, scene, dob->ob, scene->customdata_mask);
dob->ob->transflag |= OB_DUPLICALCDERIVED;
}
}
diff --git a/source/blender/blenkernel/intern/object_facemap.c b/source/blender/blenkernel/intern/object_facemap.c
new file mode 100644
index 00000000000..ef254864d2e
--- /dev/null
+++ b/source/blender/blenkernel/intern/object_facemap.c
@@ -0,0 +1,257 @@
+
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/object_facemap.c
+ * \ingroup bke
+ */
+
+#include <string.h>
+
+#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+#include "BLI_listbase.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_editmesh.h"
+#include "BKE_object.h"
+#include "BKE_object_facemap.h" /* own include */
+#include "BKE_object_deform.h"
+
+#include "BLT_translation.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_define.h"
+#include "RNA_access.h"
+
+static bool fmap_unique_check(void *arg, const char *name)
+{
+ struct {Object *ob; void *fm; } *data = arg;
+
+ bFaceMap *fmap;
+
+ for (fmap = data->ob->fmaps.first; fmap; fmap = fmap->next) {
+ if (data->fm != fmap) {
+ if (!strcmp(fmap->name, name)) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+static bFaceMap *fmap_duplicate(bFaceMap *infmap)
+{
+ bFaceMap *outfmap;
+
+ if (!infmap)
+ return NULL;
+
+ outfmap = MEM_callocN(sizeof(bFaceMap), "copy facemap");
+
+ /* For now, just copy everything over. */
+ memcpy(outfmap, infmap, sizeof(bFaceMap));
+
+ outfmap->next = outfmap->prev = NULL;
+
+ return outfmap;
+}
+
+void BKE_object_facemap_copy_list(ListBase *outbase, const ListBase *inbase)
+{
+ bFaceMap *fmap, *fmapn;
+
+ BLI_listbase_clear(outbase);
+
+ for (fmap = inbase->first; fmap; fmap = fmap->next) {
+ fmapn = fmap_duplicate(fmap);
+ BLI_addtail(outbase, fmapn);
+ }
+}
+
+void BKE_object_facemap_unique_name(Object *ob, bFaceMap *fmap)
+{
+ struct {Object *ob; void *fmap; } data;
+ data.ob = ob;
+ data.fmap = fmap;
+
+ BLI_uniquename_cb(fmap_unique_check, &data, DATA_("Group"), '.', fmap->name, sizeof(fmap->name));
+}
+
+bFaceMap *BKE_object_facemap_add_name(Object *ob, const char *name)
+{
+ bFaceMap *fmap;
+
+ if (!ob || ob->type != OB_MESH)
+ return NULL;
+
+ fmap = MEM_callocN(sizeof(bFaceMap), __func__);
+
+ BLI_strncpy(fmap->name, name, sizeof(fmap->name));
+
+ BLI_addtail(&ob->fmaps, fmap);
+
+ ob->actfmap = BLI_listbase_count(&ob->fmaps);
+
+ BKE_object_facemap_unique_name(ob, fmap);
+
+ return fmap;
+}
+
+bFaceMap *BKE_object_facemap_add(Object *ob)
+{
+ return BKE_object_facemap_add_name(ob, DATA_("FaceMap"));
+}
+
+
+static void object_fmap_remove_edit_mode(Object *ob, bFaceMap *fmap, bool do_selected, bool purge)
+{
+ const int fmap_nr = BLI_findindex(&ob->fmaps, fmap);
+
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+
+ if (me->edit_btmesh) {
+ BMEditMesh *em = me->edit_btmesh;
+ const int cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP);
+
+ if (cd_fmap_offset != -1) {
+ BMFace *efa;
+ BMIter iter;
+ int *map;
+
+ if (purge) {
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ map = BM_ELEM_CD_GET_VOID_P(efa, cd_fmap_offset);
+
+ if (map) {
+ if (*map == fmap_nr)
+ *map = -1;
+ else if (*map > fmap_nr)
+ *map -= 1;
+ }
+ }
+ }
+ else {
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ map = BM_ELEM_CD_GET_VOID_P(efa, cd_fmap_offset);
+
+ if (map && *map == fmap_nr && (!do_selected || BM_elem_flag_test(efa, BM_ELEM_SELECT))) {
+ *map = -1;
+ }
+ }
+ }
+ }
+
+ if (ob->actfmap == BLI_listbase_count(&ob->fmaps))
+ ob->actfmap--;
+
+ BLI_remlink(&ob->fmaps, fmap);
+ MEM_freeN(fmap);
+ }
+ }
+}
+
+static void object_fmap_remove_object_mode(Object *ob, bFaceMap *fmap, bool purge)
+{
+ const int fmap_nr = BLI_findindex(&ob->fmaps, fmap);
+
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+
+ if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
+ int *map = CustomData_get_layer(&me->pdata, CD_FACEMAP);
+ int i;
+
+ if (map) {
+ for (i = 0; i < me->totpoly; i++) {
+ if (map[i] == fmap_nr)
+ map[i] = -1;
+ else if (purge && map[i] > fmap_nr)
+ map[i]--;
+ }
+ }
+ }
+
+ if (ob->actfmap == BLI_listbase_count(&ob->fmaps))
+ ob->actfmap--;
+
+ BLI_remlink(&ob->fmaps, fmap);
+ MEM_freeN(fmap);
+ }
+}
+
+static void fmap_remove_exec(Object *ob, bFaceMap *fmap, const bool is_edit_mode, const bool purge)
+{
+ if (is_edit_mode)
+ object_fmap_remove_edit_mode(ob, fmap, false, purge);
+ else
+ object_fmap_remove_object_mode(ob, fmap, purge);
+}
+
+void BKE_object_facemap_remove(Object *ob, bFaceMap *fmap)
+{
+ fmap_remove_exec(ob, fmap, BKE_object_is_in_editmode(ob), true);
+}
+
+void BKE_object_facemap_clear(Object *ob)
+{
+ bFaceMap *fmap = (bFaceMap *)ob->fmaps.first;
+
+ if (fmap) {
+ const bool edit_mode = BKE_object_is_in_editmode_vgroup(ob);
+
+ while (fmap) {
+ bFaceMap *next_fmap = fmap->next;
+ fmap_remove_exec(ob, fmap, edit_mode, false);
+ fmap = next_fmap;
+ }
+ }
+ /* remove all face-maps */
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+ CustomData_free_layer(&me->pdata, CD_FACEMAP, me->totpoly, 0);
+ }
+ ob->actfmap = 0;
+}
+
+int BKE_object_facemap_name_index(Object *ob, const char *name)
+{
+ return (name) ? BLI_findstringindex(&ob->fmaps, name, offsetof(bFaceMap, name)) : -1;
+}
+
+bFaceMap *BKE_object_facemap_find_name(Object *ob, const char *name)
+{
+ return BLI_findstring(&ob->fmaps, name, offsetof(bFaceMap, name));
+}
diff --git a/source/blender/blenkernel/intern/object_update.c b/source/blender/blenkernel/intern/object_update.c
index e2e28d4b251..e3d42f3ad60 100644
--- a/source/blender/blenkernel/intern/object_update.c
+++ b/source/blender/blenkernel/intern/object_update.c
@@ -32,18 +32,18 @@
#include "DNA_group_types.h"
#include "DNA_key_types.h"
#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_scene_types.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BLI_math.h"
-#include "BLI_threads.h"
#include "BKE_global.h"
#include "BKE_armature.h"
#include "BKE_action.h"
#include "BKE_constraint.h"
-#include "BKE_depsgraph.h"
+#include "BKE_curve.h"
#include "BKE_DerivedMesh.h"
#include "BKE_animsys.h"
#include "BKE_displist.h"
@@ -51,22 +51,26 @@
#include "BKE_key.h"
#include "BKE_lamp.h"
#include "BKE_lattice.h"
+#include "BKE_library.h"
#include "BKE_editmesh.h"
#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_scene.h"
#include "BKE_material.h"
+#include "BKE_mball.h"
+#include "BKE_mesh.h"
#include "BKE_image.h"
+#include "MEM_guardedalloc.h"
+
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
-static ThreadMutex material_lock = BLI_MUTEX_INITIALIZER;
-void BKE_object_eval_local_transform(EvaluationContext *UNUSED(eval_ctx),
- Object *ob)
+void BKE_object_eval_local_transform(Depsgraph *depsgraph, Object *ob)
{
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
/* calculate local matrix */
BKE_object_to_mat4(ob, ob->obmat);
@@ -74,7 +78,7 @@ void BKE_object_eval_local_transform(EvaluationContext *UNUSED(eval_ctx),
/* Evaluate parent */
/* NOTE: based on solve_parenting(), but with the cruft stripped out */
-void BKE_object_eval_parent(EvaluationContext *UNUSED(eval_ctx),
+void BKE_object_eval_parent(Depsgraph *depsgraph,
Scene *scene,
Object *ob)
{
@@ -84,7 +88,7 @@ void BKE_object_eval_parent(EvaluationContext *UNUSED(eval_ctx),
float tmat[4][4];
float locmat[4][4];
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
/* get local matrix (but don't calculate it, as that was done already!) */
// XXX: redundant?
@@ -106,14 +110,14 @@ void BKE_object_eval_parent(EvaluationContext *UNUSED(eval_ctx),
}
}
-void BKE_object_eval_constraints(EvaluationContext *UNUSED(eval_ctx),
+void BKE_object_eval_constraints(Depsgraph *depsgraph,
Scene *scene,
Object *ob)
{
bConstraintOb *cob;
float ctime = BKE_scene_frame_get(scene);
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
/* evaluate constraints stack */
/* TODO: split this into:
@@ -125,22 +129,23 @@ void BKE_object_eval_constraints(EvaluationContext *UNUSED(eval_ctx),
*
*/
cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
- BKE_constraints_solve(&ob->constraints, cob, ctime);
+ BKE_constraints_solve(depsgraph, &ob->constraints, cob, ctime);
BKE_constraints_clear_evalob(cob);
}
-void BKE_object_eval_done(EvaluationContext *UNUSED(eval_ctx), Object *ob)
+void BKE_object_eval_done(Depsgraph *depsgraph, Object *ob)
{
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
/* Set negative scale flag in object. */
if (is_negative_m4(ob->obmat)) ob->transflag |= OB_NEG_SCALE;
else ob->transflag &= ~OB_NEG_SCALE;
}
-void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
- Scene *scene,
- Object *ob)
+void BKE_object_handle_data_update(
+ Depsgraph *depsgraph,
+ Scene *scene,
+ Object *ob)
{
ID *data_id = (ID *)ob->data;
AnimData *adt = BKE_animdata_from_id(data_id);
@@ -168,19 +173,27 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
switch (ob->type) {
case OB_MESH:
{
- BMEditMesh *em = (ob == scene->obedit) ? BKE_editmesh_from_object(ob) : NULL;
+#if 0
+ BMEditMesh *em = (ob->mode & OB_MODE_EDIT) ? BKE_editmesh_from_object(ob) : NULL;
+#else
+ BMEditMesh *em = (ob->mode & OB_MODE_EDIT) ? ((Mesh *)ob->data)->edit_btmesh : NULL;
+ if (em && em->ob != ob) {
+ em = NULL;
+ }
+#endif
+
uint64_t data_mask = scene->customdata_mask | CD_MASK_BAREMESH;
#ifdef WITH_FREESTYLE
/* make sure Freestyle edge/face marks appear in DM for render (see T40315) */
- if (eval_ctx->mode != DAG_EVAL_VIEWPORT) {
+ if (DEG_get_mode(depsgraph) != DAG_EVAL_VIEWPORT) {
data_mask |= CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
}
#endif
if (em) {
- makeDerivedMesh(scene, ob, em, data_mask, false); /* was CD_MASK_BAREMESH */
+ makeDerivedMesh(depsgraph, scene, ob, em, data_mask, false); /* was CD_MASK_BAREMESH */
}
else {
- makeDerivedMesh(scene, ob, NULL, data_mask, false);
+ makeDerivedMesh(depsgraph, scene, ob, NULL, data_mask, false);
}
break;
}
@@ -192,22 +205,22 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
}
}
else {
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
}
break;
case OB_MBALL:
- BKE_displist_make_mball(eval_ctx, scene, ob);
+ BKE_displist_make_mball(depsgraph, scene, ob);
break;
case OB_CURVE:
case OB_SURF:
case OB_FONT:
- BKE_displist_make_curveTypes(scene, ob, 0);
+ BKE_displist_make_curveTypes(depsgraph, scene, ob, 0);
break;
case OB_LATTICE:
- BKE_lattice_modifiers_calc(scene, ob);
+ BKE_lattice_modifiers_calc(depsgraph, scene, ob);
break;
case OB_EMPTY:
@@ -217,30 +230,9 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
break;
}
- /* related materials */
- /* XXX: without depsgraph tagging, this will always need to be run, which will be slow!
- * However, not doing anything (or trying to hack around this lack) is not an option
- * anymore, especially due to Cycles [#31834]
- */
- if (ob->totcol) {
- int a;
- if (ob->totcol != 0) {
- BLI_mutex_lock(&material_lock);
- for (a = 1; a <= ob->totcol; a++) {
- Material *ma = give_current_material(ob, a);
- if (ma) {
- /* recursively update drivers for this material */
- material_drivers_update(scene, ma, ctime);
- }
- }
- BLI_mutex_unlock(&material_lock);
- }
- }
- else if (ob->type == OB_LAMP)
- lamp_drivers_update(scene, ob->data, ctime);
-
/* particles */
- if (ob != scene->obedit && ob->particlesystem.first) {
+ if (!(ob->mode & OB_MODE_EDIT) && ob->particlesystem.first) {
+ const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
ParticleSystem *tpsys, *psys;
DerivedMesh *dm;
ob->transflag &= ~OB_DUPLIPARTS;
@@ -251,16 +243,16 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
psys_changed_type(ob, psys);
}
- if (psys_check_enabled(ob, psys, eval_ctx->mode == DAG_EVAL_RENDER)) {
+ if (psys_check_enabled(ob, psys, use_render_params)) {
/* check use of dupli objects here */
- if (psys->part && (psys->part->draw_as == PART_DRAW_REND || eval_ctx->mode == DAG_EVAL_RENDER) &&
+ if (psys->part && (psys->part->draw_as == PART_DRAW_REND || use_render_params) &&
((psys->part->ren_as == PART_DRAW_OB && psys->part->dup_ob) ||
(psys->part->ren_as == PART_DRAW_GR && psys->part->dup_group)))
{
ob->transflag |= OB_DUPLIPARTS;
}
- particle_system_update(scene, ob, psys, (eval_ctx->mode == DAG_EVAL_RENDER));
+ particle_system_update(depsgraph, scene, ob, psys, use_render_params);
psys = psys->next;
}
else if (psys->flag & PSYS_DELETE) {
@@ -273,12 +265,12 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
psys = psys->next;
}
- if (eval_ctx->mode == DAG_EVAL_RENDER && ob->transflag & OB_DUPLIPARTS) {
+ if (use_render_params && ob->transflag & OB_DUPLIPARTS) {
/* this is to make sure we get render level duplis in groups:
* the derivedmesh must be created before init_render_mesh,
* since object_duplilist does dupliparticles before that */
CustomDataMask data_mask = CD_MASK_BAREMESH | CD_MASK_MFACE | CD_MASK_MTFACE | CD_MASK_MCOL;
- dm = mesh_create_derived_render(scene, ob, data_mask);
+ dm = mesh_create_derived_render(depsgraph, scene, ob, data_mask);
dm->release(dm);
for (psys = ob->particlesystem.first; psys; psys = psys->next)
@@ -289,7 +281,7 @@ void BKE_object_handle_data_update(EvaluationContext *eval_ctx,
/* quick cache removed */
}
-bool BKE_object_eval_proxy_copy(EvaluationContext *UNUSED(eval_ctx),
+bool BKE_object_eval_proxy_copy(Depsgraph *UNUSED(depsgraph),
Object *object)
{
/* Handle proxy copy for target, */
@@ -313,46 +305,171 @@ bool BKE_object_eval_proxy_copy(EvaluationContext *UNUSED(eval_ctx),
return false;
}
-void BKE_object_eval_uber_transform(EvaluationContext *eval_ctx, Object *object)
+void BKE_object_eval_uber_transform(Depsgraph *depsgraph, Object *object)
{
- BKE_object_eval_proxy_copy(eval_ctx, object);
- object->recalc &= ~(OB_RECALC_OB | OB_RECALC_TIME);
- if (object->data == NULL) {
- object->recalc &= ~OB_RECALC_DATA;
- }
+ BKE_object_eval_proxy_copy(depsgraph, object);
}
-void BKE_object_eval_uber_data(EvaluationContext *eval_ctx,
+void BKE_object_eval_uber_data(Depsgraph *depsgraph,
Scene *scene,
Object *ob)
{
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
BLI_assert(ob->type != OB_ARMATURE);
- BKE_object_handle_data_update(eval_ctx, scene, ob);
+ BKE_object_handle_data_update(depsgraph, scene, ob);
+
+ switch (ob->type) {
+ case OB_MESH:
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
+ break;
+ case OB_LATTICE:
+ BKE_lattice_batch_cache_dirty(ob->data, BKE_LATTICE_BATCH_DIRTY_ALL);
+ break;
+ case OB_CURVE:
+ case OB_FONT:
+ case OB_SURF:
+ BKE_curve_batch_cache_dirty(ob->data, BKE_CURVE_BATCH_DIRTY_ALL);
+ break;
+ case OB_MBALL:
+ BKE_mball_batch_cache_dirty(ob->data, BKE_MBALL_BATCH_DIRTY_ALL);
+ break;
+ }
- ob->recalc &= ~(OB_RECALC_DATA | OB_RECALC_TIME);
+ if (DEG_depsgraph_use_copy_on_write()) {
+ if (ob->type == OB_MESH) {
+ /* Quick hack to convert evaluated derivedMesh to Mesh. */
+ DerivedMesh *dm = ob->derivedFinal;
+ if (dm != NULL) {
+ Mesh *mesh = (Mesh *)ob->data;
+ Mesh *new_mesh = BKE_libblock_alloc_notest(ID_ME);
+ BKE_mesh_init(new_mesh);
+ /* Copy ID name so GS(new_mesh->id) works correct later on. */
+ BLI_strncpy(new_mesh->id.name, mesh->id.name, sizeof(new_mesh->id.name));
+ /* Copy materials so render engines can access them. */
+ new_mesh->mat = MEM_dupallocN(mesh->mat);
+ new_mesh->totcol = mesh->totcol;
+ DM_to_mesh(dm, new_mesh, ob, CD_MASK_MESH, true);
+ new_mesh->edit_btmesh = mesh->edit_btmesh;
+ /* Store result mesh as derived_mesh of object. This way we have
+ * explicit way to query final object evaluated data and know for sure
+ * who owns the newly created mesh datablock.
+ */
+ ob->mesh_evaluated = new_mesh;
+ /* TODO(sergey): This is kind of compatibility thing, so all render
+ * engines can use object->data for mesh data for display. This is
+ * something what we might want to change in the future.
+ */
+ ob->data = new_mesh;
+ /* Special flags to help debugging. */
+ new_mesh->id.tag |= LIB_TAG_COPY_ON_WRITE_EVAL;
+ /* Save some memory by throwing DerivedMesh away. */
+ /* NOTE: Watch out, some tools might need it!
+ * So keep around for now..
+ */
+ /* Store original ID as a pointer in evaluated ID.
+ * This way we can restore original object data when we are freeing
+ * evaluated mesh.
+ */
+ new_mesh->id.orig_id = &mesh->id;
+ }
+#if 0
+ if (ob->derivedFinal != NULL) {
+ ob->derivedFinal->needsFree = 1;
+ ob->derivedFinal->release(ob->derivedFinal);
+ ob->derivedFinal = NULL;
+ }
+ if (ob->derivedDeform != NULL) {
+ ob->derivedDeform->needsFree = 1;
+ ob->derivedDeform->release(ob->derivedDeform);
+ ob->derivedDeform = NULL;
+ }
+#endif
+ }
+ }
}
-void BKE_object_eval_cloth(EvaluationContext *UNUSED(eval_ctx),
+void BKE_object_eval_cloth(Depsgraph *depsgraph,
Scene *scene,
Object *object)
{
- DEG_debug_print_eval(__func__, object->id.name, object);
+ DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
BKE_ptcache_object_reset(scene, object, PTCACHE_RESET_DEPSGRAPH);
}
-void BKE_object_eval_transform_all(EvaluationContext *eval_ctx,
+void BKE_object_eval_transform_all(Depsgraph *depsgraph,
Scene *scene,
Object *object)
{
/* This mimics full transform update chain from new depsgraph. */
- BKE_object_eval_local_transform(eval_ctx, object);
+ BKE_object_eval_local_transform(depsgraph, object);
if (object->parent != NULL) {
- BKE_object_eval_parent(eval_ctx, scene, object);
+ BKE_object_eval_parent(depsgraph, scene, object);
}
if (!BLI_listbase_is_empty(&object->constraints)) {
- BKE_object_eval_constraints(eval_ctx, scene, object);
+ BKE_object_eval_constraints(depsgraph, scene, object);
+ }
+ BKE_object_eval_uber_transform(depsgraph, object);
+ BKE_object_eval_done(depsgraph, object);
+}
+
+void BKE_object_eval_update_shading(Depsgraph *depsgraph, Object *object)
+{
+ DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
+ if (object->type == OB_MESH) {
+ BKE_mesh_batch_cache_dirty(object->data, BKE_MESH_BATCH_DIRTY_SHADING);
+ }
+}
+
+void BKE_object_data_select_update(Depsgraph *depsgraph, ID *object_data)
+{
+ DEG_debug_print_eval(depsgraph, __func__, object_data->name, object_data);
+ switch (GS(object_data->name)) {
+ case ID_ME:
+ BKE_mesh_batch_cache_dirty((Mesh *)object_data,
+ BKE_CURVE_BATCH_DIRTY_SELECT);
+ break;
+ case ID_CU:
+ BKE_curve_batch_cache_dirty((Curve *)object_data,
+ BKE_CURVE_BATCH_DIRTY_SELECT);
+ break;
+ case ID_LT:
+ BKE_lattice_batch_cache_dirty((struct Lattice *)object_data,
+ BKE_CURVE_BATCH_DIRTY_SELECT);
+ break;
+ default:
+ break;
+ }
+}
+
+void BKE_object_eval_flush_base_flags(Depsgraph *depsgraph,
+ Scene *scene, const int view_layer_index,
+ Object *object, int base_index,
+ const bool is_from_set)
+{
+ /* TODO(sergey): Avoid list lookup. */
+ BLI_assert(view_layer_index >= 0);
+ ViewLayer *view_layer = BLI_findlink(&scene->view_layers, view_layer_index);
+ BLI_assert(view_layer != NULL);
+ BLI_assert(view_layer->object_bases_array != NULL);
+ BLI_assert(base_index >= 0);
+ BLI_assert(base_index < MEM_allocN_len(view_layer->object_bases_array) / sizeof(Base *));
+ Base *base = view_layer->object_bases_array[base_index];
+ BLI_assert(base->object == object);
+
+ DEG_debug_print_eval(depsgraph, __func__, object->id.name, object);
+
+ /* Make sure we have the base collection settings is already populated.
+ * This will fail when BKE_layer_eval_layer_collection_pre hasn't run yet.
+ *
+ * Which usually means a missing call to DEG_id_tag_update(id, DEG_TAG_BASE_FLAGS_UPDATE).
+ * Either of the entire scene, or of the newly added objects.*/
+ BLI_assert(!BLI_listbase_is_empty(&base->collection_properties->data.group));
+
+ /* Copy flags and settings from base. */
+ object->base_flag = base->flag;
+ if (is_from_set) {
+ object->base_flag |= BASE_FROM_SET;
+ object->base_flag &= ~(BASE_SELECTED | BASE_SELECTABLED);
}
- BKE_object_eval_uber_transform(eval_ctx, object);
- BKE_object_eval_done(eval_ctx, object);
+ object->base_collection_properties = base->collection_properties;
}
diff --git a/source/blender/blenkernel/intern/outliner_treehash.c b/source/blender/blenkernel/intern/outliner_treehash.c
index 9db9b2ddf54..9bbde607b80 100644
--- a/source/blender/blenkernel/intern/outliner_treehash.c
+++ b/source/blender/blenkernel/intern/outliner_treehash.c
@@ -27,6 +27,7 @@
*/
#include <stdlib.h>
+#include <string.h>
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
@@ -56,7 +57,7 @@ static TseGroup *tse_group_create(void)
return tse_group;
}
-static void tse_group_add(TseGroup *tse_group, TreeStoreElem *elem)
+static void tse_group_add_element(TseGroup *tse_group, TreeStoreElem *elem)
{
if (UNLIKELY(tse_group->size == tse_group->allocated)) {
tse_group->allocated *= 2;
@@ -66,6 +67,26 @@ static void tse_group_add(TseGroup *tse_group, TreeStoreElem *elem)
tse_group->size++;
}
+static void tse_group_remove_element(TseGroup *tse_group, TreeStoreElem *elem)
+{
+ int min_allocated = MAX2(1, tse_group->allocated / 2);
+ BLI_assert(tse_group->allocated == 1 || (tse_group->allocated % 2) == 0);
+
+ tse_group->size--;
+ BLI_assert(tse_group->size >= 0);
+ for (int i = 0; i < tse_group->size; i++) {
+ if (tse_group->elems[i] == elem) {
+ memcpy(tse_group->elems[i], tse_group->elems[i + 1], (tse_group->size - (i + 1)) * sizeof(TreeStoreElem *));
+ break;
+ }
+ }
+
+ if (UNLIKELY(tse_group->size > 0 && tse_group->size <= min_allocated)) {
+ tse_group->allocated = min_allocated;
+ tse_group->elems = MEM_reallocN(tse_group->elems, sizeof(TreeStoreElem *) * tse_group->allocated);
+ }
+}
+
static void tse_group_free(TseGroup *tse_group)
{
MEM_freeN(tse_group->elems);
@@ -140,7 +161,21 @@ void BKE_outliner_treehash_add_element(void *treehash, TreeStoreElem *elem)
*val_p = tse_group_create();
}
group = *val_p;
- tse_group_add(group, elem);
+ tse_group_add_element(group, elem);
+}
+
+void BKE_outliner_treehash_remove_element(void *treehash, TreeStoreElem *elem)
+{
+ TseGroup *group = BLI_ghash_lookup(treehash, elem);
+
+ BLI_assert(group != NULL);
+ if (group->size <= 1) {
+ /* one element -> remove group completely */
+ BLI_ghash_remove(treehash, elem, NULL, free_treehash_group);
+ }
+ else {
+ tse_group_remove_element(group, elem);
+ }
}
static TseGroup *BKE_outliner_treehash_lookup_group(GHash *th, short type, short nr, struct ID *id)
diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c
index 144ec029db1..4056a15fe47 100644
--- a/source/blender/blenkernel/intern/paint.c
+++ b/source/blender/blenkernel/intern/paint.c
@@ -41,6 +41,7 @@
#include "DNA_scene_types.h"
#include "DNA_brush_types.h"
#include "DNA_space_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_bitmap.h"
#include "BLI_utildefines.h"
@@ -53,7 +54,6 @@
#include "BKE_main.h"
#include "BKE_context.h"
#include "BKE_crazyspace.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_key.h"
@@ -65,6 +65,8 @@
#include "BKE_pbvh.h"
#include "BKE_subsurf.h"
+#include "DEG_depsgraph.h"
+
#include "bmesh.h"
const char PAINT_CURSOR_SCULPT[3] = {255, 100, 100};
@@ -74,9 +76,9 @@ const char PAINT_CURSOR_TEXTURE_PAINT[3] = {255, 255, 255};
static eOverlayControlFlags overlay_flags = 0;
-void BKE_paint_invalidate_overlay_tex(Scene *scene, const Tex *tex)
+void BKE_paint_invalidate_overlay_tex(Scene *scene, ViewLayer *view_layer, const Tex *tex)
{
- Paint *p = BKE_paint_get_active(scene);
+ Paint *p = BKE_paint_get_active(scene, view_layer);
Brush *br = p->brush;
if (!br)
@@ -88,9 +90,9 @@ void BKE_paint_invalidate_overlay_tex(Scene *scene, const Tex *tex)
overlay_flags |= PAINT_INVALID_OVERLAY_TEXTURE_SECONDARY;
}
-void BKE_paint_invalidate_cursor_overlay(Scene *scene, CurveMapping *curve)
+void BKE_paint_invalidate_cursor_overlay(Scene *scene, ViewLayer *view_layer, CurveMapping *curve)
{
- Paint *p = BKE_paint_get_active(scene);
+ Paint *p = BKE_paint_get_active(scene, view_layer);
Brush *br = p->brush;
if (br && br->curve == curve)
@@ -156,13 +158,13 @@ Paint *BKE_paint_get_active_from_paintmode(Scene *sce, ePaintMode mode)
return NULL;
}
-Paint *BKE_paint_get_active(Scene *sce)
+Paint *BKE_paint_get_active(Scene *sce, ViewLayer *view_layer)
{
- if (sce) {
+ if (sce && view_layer) {
ToolSettings *ts = sce->toolsettings;
- if (sce->basact && sce->basact->object) {
- switch (sce->basact->object->mode) {
+ if (view_layer->basact && view_layer->basact->object) {
+ switch (view_layer->basact->object->mode) {
case OB_MODE_SCULPT:
return &ts->sculpt->paint;
case OB_MODE_VERTEX_PAINT:
@@ -175,6 +177,8 @@ Paint *BKE_paint_get_active(Scene *sce)
if (ts->use_uv_sculpt)
return &ts->uvsculpt->paint;
return &ts->imapaint.paint;
+ default:
+ break;
}
}
@@ -188,14 +192,15 @@ Paint *BKE_paint_get_active(Scene *sce)
Paint *BKE_paint_get_active_from_context(const bContext *C)
{
Scene *sce = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
SpaceImage *sima;
- if (sce) {
+ if (sce && view_layer) {
ToolSettings *ts = sce->toolsettings;
Object *obact = NULL;
- if (sce->basact && sce->basact->object)
- obact = sce->basact->object;
+ if (view_layer->basact && view_layer->basact->object)
+ obact = view_layer->basact->object;
if ((sima = CTX_wm_space_image(C)) != NULL) {
if (obact && obact->mode == OB_MODE_EDIT) {
@@ -209,7 +214,7 @@ Paint *BKE_paint_get_active_from_context(const bContext *C)
}
}
else {
- return BKE_paint_get_active(sce);
+ return BKE_paint_get_active(sce, view_layer);
}
}
@@ -219,14 +224,15 @@ Paint *BKE_paint_get_active_from_context(const bContext *C)
ePaintMode BKE_paintmode_get_active_from_context(const bContext *C)
{
Scene *sce = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
SpaceImage *sima;
- if (sce) {
+ if (sce && view_layer) {
ToolSettings *ts = sce->toolsettings;
Object *obact = NULL;
- if (sce->basact && sce->basact->object)
- obact = sce->basact->object;
+ if (view_layer->basact && view_layer->basact->object)
+ obact = view_layer->basact->object;
if ((sima = CTX_wm_space_image(C)) != NULL) {
if (obact && obact->mode == OB_MODE_EDIT) {
@@ -714,7 +720,7 @@ void BKE_sculptsession_bm_to_me(Object *ob, bool reorder)
sculptsession_bm_to_me_update_data_only(ob, reorder);
/* ensure the objects DerivedMesh mesh doesn't hold onto arrays now realloc'd in the mesh [#34473] */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
@@ -724,7 +730,7 @@ void BKE_sculptsession_bm_to_me_for_render(Object *object)
if (object->sculpt->bm) {
/* Ensure no points to old arrays are stored in DM
*
- * Apparently, we could not use DAG_id_tag_update
+ * Apparently, we could not use DEG_id_tag_update
* here because this will lead to the while object
* surface to disappear, so we'll release DM in place.
*/
@@ -855,9 +861,19 @@ static bool sculpt_modifiers_active(Scene *scene, Sculpt *sd, Object *ob)
/**
* \param need_mask So the DerivedMesh thats returned has mask data
*/
-void BKE_sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob,
- bool need_pmap, bool need_mask)
+void BKE_sculpt_update_mesh_elements(
+ Depsgraph *depsgraph, Scene *scene, Sculpt *sd, Object *ob,
+ bool need_pmap, bool need_mask)
{
+ if (depsgraph == NULL) {
+ /* Happens on file load.
+ *
+ * We do nothing in this case, it will be taken care about on depsgraph
+ * evaluation.
+ */
+ return;
+ }
+
DerivedMesh *dm;
SculptSession *ss = ob->sculpt;
Mesh *me = ob->data;
@@ -895,7 +911,7 @@ void BKE_sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob,
ss->kb = (mmd == NULL) ? BKE_keyblock_from_object(ob) : NULL;
- dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+ dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
/* VWPaint require mesh info for loop lookup, so require sculpt mode here */
if (mmd && ob->mode & OB_MODE_SCULPT) {
@@ -930,7 +946,7 @@ void BKE_sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob,
ss->orig_cos = (ss->kb) ? BKE_keyblock_convert_to_vertcos(ob, ss->kb) : BKE_mesh_vertexCos_get(me, NULL);
- BKE_crazyspace_build_sculpt(scene, ob, &ss->deform_imats, &ss->deform_cos);
+ BKE_crazyspace_build_sculpt(depsgraph, scene, ob, &ss->deform_imats, &ss->deform_cos);
BKE_pbvh_apply_vertCos(ss->pbvh, ss->deform_cos);
for (a = 0; a < me->totvert; ++a) {
@@ -966,6 +982,9 @@ void BKE_sculpt_update_mesh_elements(Scene *scene, Sculpt *sd, Object *ob,
}
}
}
+
+ /* 2.8x - avoid full mesh update! */
+ BKE_mesh_batch_cache_dirty(me, BKE_MESH_BATCH_DIRTY_SCULPT_COORDS);
}
int BKE_sculpt_mask_layers_ensure(Object *ob, MultiresModifierData *mmd)
diff --git a/source/blender/blenkernel/intern/particle.c b/source/blender/blenkernel/intern/particle.c
index 7602523b97c..ae6028c742a 100644
--- a/source/blender/blenkernel/intern/particle.c
+++ b/source/blender/blenkernel/intern/particle.c
@@ -78,7 +78,6 @@
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
-#include "BKE_depsgraph.h"
#include "BKE_modifier.h"
#include "BKE_mesh.h"
#include "BKE_cdderivedmesh.h"
@@ -86,6 +85,10 @@
#include "BKE_scene.h"
#include "BKE_deform.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
#include "RE_render_ext.h"
#include "particle_private.h"
@@ -249,7 +252,7 @@ struct LatticeDeformData *psys_create_lattice_deform_data(ParticleSimulationData
{
struct LatticeDeformData *lattice_deform_data = NULL;
- if (psys_in_edit_mode(sim->scene, sim->psys) == 0) {
+ if (psys_in_edit_mode(sim->depsgraph, sim->psys) == 0) {
Object *lattice = NULL;
ModifierData *md = (ModifierData *)psys_get_modifier(sim->ob, sim->psys);
int mode = G.is_rendering ? eModifierMode_Render : eModifierMode_Realtime;
@@ -285,10 +288,19 @@ void psys_enable_all(Object *ob)
for (; psys; psys = psys->next)
psys->flag &= ~PSYS_DISABLED;
}
-bool psys_in_edit_mode(Scene *scene, ParticleSystem *psys)
+
+bool psys_in_edit_mode(Depsgraph *depsgraph, ParticleSystem *psys)
{
- return (scene->basact && (scene->basact->object->mode & OB_MODE_PARTICLE_EDIT) && psys == psys_get_current((scene->basact)->object) && (psys->edit || psys->pointcache->edit) && !psys->renderdata);
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
+
+ return (view_layer->basact &&
+ (view_layer->basact->object->mode & OB_MODE_PARTICLE_EDIT) &&
+ psys == psys_get_current((view_layer->basact)->object) &&
+ (psys->edit || psys->pointcache->edit) &&
+ !use_render_params);
}
+
bool psys_check_enabled(Object *ob, ParticleSystem *psys, const bool use_render_params)
{
ParticleSystemModifierData *psmd;
@@ -297,7 +309,7 @@ bool psys_check_enabled(Object *ob, ParticleSystem *psys, const bool use_render_
return 0;
psmd = psys_get_modifier(ob, psys);
- if (psys->renderdata || use_render_params) {
+ if (use_render_params) {
if (!(psmd->modifier.mode & eModifierMode_Render))
return 0;
}
@@ -318,18 +330,17 @@ bool psys_check_edited(ParticleSystem *psys)
void psys_check_group_weights(ParticleSettings *part)
{
ParticleDupliWeight *dw, *tdw;
- GroupObject *go;
int current = 0;
- if (part->ren_as == PART_DRAW_GR && part->dup_group && part->dup_group->gobject.first) {
+ if (part->ren_as == PART_DRAW_GR && part->dup_group && part->dup_group->view_layer->object_bases.first) {
/* First try to find NULL objects from their index,
* and remove all weights that don't have an object in the group. */
dw = part->dupliweights.first;
while (dw) {
if (dw->ob == NULL || !BKE_group_object_exists(part->dup_group, dw->ob)) {
- go = (GroupObject *)BLI_findlink(&part->dup_group->gobject, dw->index);
- if (go) {
- dw->ob = go->ob;
+ Base *base = BLI_findlink(&part->dup_group->view_layer->object_bases, dw->index);
+ if (base != NULL) {
+ dw->ob = base->object;
}
else {
tdw = dw->next;
@@ -343,21 +354,21 @@ void psys_check_group_weights(ParticleSettings *part)
}
/* then add objects in the group to new list */
- go = part->dup_group->gobject.first;
- while (go) {
+ FOREACH_GROUP_OBJECT_BEGIN(part->dup_group, object)
+ {
dw = part->dupliweights.first;
- while (dw && dw->ob != go->ob)
+ while (dw && dw->ob != object) {
dw = dw->next;
-
+ }
+
if (!dw) {
dw = MEM_callocN(sizeof(ParticleDupliWeight), "ParticleDupliWeight");
- dw->ob = go->ob;
+ dw->ob = object;
dw->count = 1;
BLI_addtail(&part->dupliweights, dw);
}
-
- go = go->next;
}
+ FOREACH_GROUP_OBJECT_END;
dw = part->dupliweights.first;
for (; dw; dw = dw->next) {
@@ -608,206 +619,10 @@ void psys_free(Object *ob, ParticleSystem *psys)
MEM_freeN(psys->pdd);
}
- MEM_freeN(psys);
- }
-}
-
-/************************************************/
-/* Rendering */
-/************************************************/
-/* these functions move away particle data and bring it back after
- * rendering, to make different render settings possible without
- * removing the previous data. this should be solved properly once */
-
-void psys_render_set(Object *ob, ParticleSystem *psys, float viewmat[4][4], float winmat[4][4], int winx, int winy, int timeoffset)
-{
- ParticleRenderData *data;
- ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
-
- if (psys->renderdata)
- return;
-
- data = MEM_callocN(sizeof(ParticleRenderData), "ParticleRenderData");
-
- data->child = psys->child;
- data->totchild = psys->totchild;
- data->pathcache = psys->pathcache;
- data->pathcachebufs.first = psys->pathcachebufs.first;
- data->pathcachebufs.last = psys->pathcachebufs.last;
- data->totcached = psys->totcached;
- data->childcache = psys->childcache;
- data->childcachebufs.first = psys->childcachebufs.first;
- data->childcachebufs.last = psys->childcachebufs.last;
- data->totchildcache = psys->totchildcache;
-
- if (psmd->dm_final) {
- data->dm = CDDM_copy_with_tessface(psmd->dm_final);
- }
- data->totdmvert = psmd->totdmvert;
- data->totdmedge = psmd->totdmedge;
- data->totdmface = psmd->totdmface;
-
- psys->child = NULL;
- psys->pathcache = NULL;
- psys->childcache = NULL;
- psys->totchild = psys->totcached = psys->totchildcache = 0;
- BLI_listbase_clear(&psys->pathcachebufs);
- BLI_listbase_clear(&psys->childcachebufs);
-
- copy_m4_m4(data->winmat, winmat);
- mul_m4_m4m4(data->viewmat, viewmat, ob->obmat);
- mul_m4_m4m4(data->mat, winmat, data->viewmat);
- data->winx = winx;
- data->winy = winy;
-
- data->timeoffset = timeoffset;
-
- psys->renderdata = data;
-
- /* Hair can and has to be recalculated if everything isn't displayed. */
- if (psys->part->disp != 100 && ELEM(psys->part->type, PART_HAIR, PART_FLUID)) {
- psys->recalc |= PSYS_RECALC_RESET;
- }
-}
-
-void psys_render_restore(Object *ob, ParticleSystem *psys)
-{
- ParticleRenderData *data;
- ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
- float render_disp = psys_get_current_display_percentage(psys);
- float disp;
-
- data = psys->renderdata;
- if (!data)
- return;
-
- if (data->elems)
- MEM_freeN(data->elems);
-
- if (psmd->dm_final) {
- psmd->dm_final->needsFree = 1;
- psmd->dm_final->release(psmd->dm_final);
- }
- if (psmd->dm_deformed) {
- psmd->dm_deformed->needsFree = 1;
- psmd->dm_deformed->release(psmd->dm_deformed);
- psmd->dm_deformed = NULL;
- }
-
- psys_free_path_cache(psys, NULL);
-
- if (psys->child) {
- MEM_freeN(psys->child);
- psys->child = 0;
- psys->totchild = 0;
- }
-
- psys->child = data->child;
- psys->totchild = data->totchild;
- psys->pathcache = data->pathcache;
- psys->pathcachebufs.first = data->pathcachebufs.first;
- psys->pathcachebufs.last = data->pathcachebufs.last;
- psys->totcached = data->totcached;
- psys->childcache = data->childcache;
- psys->childcachebufs.first = data->childcachebufs.first;
- psys->childcachebufs.last = data->childcachebufs.last;
- psys->totchildcache = data->totchildcache;
-
- psmd->dm_final = data->dm;
- psmd->totdmvert = data->totdmvert;
- psmd->totdmedge = data->totdmedge;
- psmd->totdmface = data->totdmface;
- psmd->flag &= ~eParticleSystemFlag_psys_updated;
-
- if (psmd->dm_final) {
- if (!psmd->dm_final->deformedOnly) {
- if (ob->derivedDeform) {
- psmd->dm_deformed = CDDM_copy(ob->derivedDeform);
- }
- else {
- psmd->dm_deformed = CDDM_from_mesh((Mesh *)ob->data);
- }
- DM_ensure_tessface(psmd->dm_deformed);
- }
- psys_calc_dmcache(ob, psmd->dm_final, psmd->dm_deformed, psys);
- }
-
- MEM_freeN(data);
- psys->renderdata = NULL;
-
- /* restore particle display percentage */
- disp = psys_get_current_display_percentage(psys);
-
- if (disp != render_disp) {
- /* Hair can and has to be recalculated if everything isn't displayed. */
- if (ELEM(psys->part->type, PART_HAIR, PART_FLUID)) {
- psys->recalc |= PSYS_RECALC_RESET;
- }
- else {
- PARTICLE_P;
-
- LOOP_PARTICLES {
- if (psys_frand(psys, p) > disp)
- pa->flag |= PARS_NO_DISP;
- else
- pa->flag &= ~PARS_NO_DISP;
- }
- }
- }
-}
-
-bool psys_render_simplify_params(ParticleSystem *psys, ChildParticle *cpa, float *params)
-{
- ParticleRenderData *data;
- ParticleRenderElem *elem;
- float x, w, scale, alpha, lambda, t, scalemin, scalemax;
- int b;
-
- if (!(psys->renderdata && (psys->part->simplify_flag & PART_SIMPLIFY_ENABLE)))
- return false;
-
- data = psys->renderdata;
- if (!data->do_simplify)
- return false;
- b = (data->index_mf_to_mpoly) ? DM_origindex_mface_mpoly(data->index_mf_to_mpoly, data->index_mp_to_orig, cpa->num) : cpa->num;
- if (b == ORIGINDEX_NONE) {
- return false;
- }
+ BKE_particle_batch_cache_free(psys);
- elem = &data->elems[b];
-
- lambda = elem->lambda;
- t = elem->t;
- scalemin = elem->scalemin;
- scalemax = elem->scalemax;
-
- if (!elem->reduce) {
- scale = scalemin;
- alpha = 1.0f;
- }
- else {
- x = (elem->curchild + 0.5f) / elem->totchild;
- if (x < lambda - t) {
- scale = scalemax;
- alpha = 1.0f;
- }
- else if (x >= lambda + t) {
- scale = scalemin;
- alpha = 0.0f;
- }
- else {
- w = (lambda + t - x) / (2.0f * t);
- scale = scalemin + (scalemax - scalemin) * w;
- alpha = w;
- }
+ MEM_freeN(psys);
}
-
- params[0] = scale;
- params[1] = alpha;
-
- elem->curchild++;
-
- return 1;
}
/************************************************/
@@ -1216,7 +1031,7 @@ static void interpolate_pathcache(ParticleCacheKey *first, float t, ParticleCach
/* interpolate a location on a face based on face coordinates */
void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*orcodata)[3],
float w[4], float vec[3], float nor[3], float utan[3], float vtan[3],
- float orco[3], float ornor[3])
+ float orco[3])
{
float *v1 = 0, *v2 = 0, *v3 = 0, *v4 = 0;
float e1[3], e2[3], s1, s2, t1, t2;
@@ -1314,21 +1129,13 @@ void psys_interpolate_face(MVert *mvert, MFace *mface, MTFace *tface, float (*or
o4 = orcodata[mface->v4];
interp_v3_v3v3v3v3(orco, o1, o2, o3, o4, w);
-
- if (ornor)
- normal_quad_v3(ornor, o1, o2, o3, o4);
}
else {
interp_v3_v3v3v3(orco, o1, o2, o3, w);
-
- if (ornor)
- normal_tri_v3(ornor, o1, o2, o3);
}
}
else {
copy_v3_v3(orco, vec);
- if (ornor && nor)
- copy_v3_v3(ornor, nor);
}
}
}
@@ -1608,7 +1415,7 @@ static int psys_map_index_on_dm(DerivedMesh *dm, int from, int index, int index_
/* interprets particle data to get a point on a mesh in object space */
void psys_particle_on_dm(DerivedMesh *dm_final, int from, int index, int index_dmcache,
const float fw[4], float foffset, float vec[3], float nor[3], float utan[3], float vtan[3],
- float orco[3], float ornor[3])
+ float orco[3])
{
float tmpnor[3], mapfw[4];
float (*orcodata)[3];
@@ -1618,7 +1425,6 @@ void psys_particle_on_dm(DerivedMesh *dm_final, int from, int index, int index_d
if (vec) { vec[0] = vec[1] = vec[2] = 0.0; }
if (nor) { nor[0] = nor[1] = 0.0; nor[2] = 1.0; }
if (orco) { orco[0] = orco[1] = orco[2] = 0.0; }
- if (ornor) { ornor[0] = ornor[1] = 0.0; ornor[2] = 1.0; }
if (utan) { utan[0] = utan[1] = utan[2] = 0.0; }
if (vtan) { vtan[0] = vtan[1] = vtan[2] = 0.0; }
@@ -1644,11 +1450,6 @@ void psys_particle_on_dm(DerivedMesh *dm_final, int from, int index, int index_d
}
}
- if (ornor) {
- dm_final->getVertNo(dm_final, mapindex, ornor);
- normalize_v3(ornor);
- }
-
if (utan && vtan) {
utan[0] = utan[1] = utan[2] = 0.0f;
vtan[0] = vtan[1] = vtan[2] = 0.0f;
@@ -1667,7 +1468,7 @@ void psys_particle_on_dm(DerivedMesh *dm_final, int from, int index, int index_d
mtface += mapindex;
if (from == PART_FROM_VOLUME) {
- psys_interpolate_face(mvert, mface, mtface, orcodata, mapfw, vec, tmpnor, utan, vtan, orco, ornor);
+ psys_interpolate_face(mvert, mface, mtface, orcodata, mapfw, vec, tmpnor, utan, vtan, orco);
if (nor)
copy_v3_v3(nor, tmpnor);
@@ -1676,7 +1477,7 @@ void psys_particle_on_dm(DerivedMesh *dm_final, int from, int index, int index_d
add_v3_v3(vec, tmpnor);
}
else
- psys_interpolate_face(mvert, mface, mtface, orcodata, mapfw, vec, nor, utan, vtan, orco, ornor);
+ psys_interpolate_face(mvert, mface, mtface, orcodata, mapfw, vec, nor, utan, vtan, orco);
}
}
@@ -1712,7 +1513,7 @@ ParticleSystemModifierData *psys_get_modifier(Object *ob, ParticleSystem *psys)
/* ready for future use */
static void psys_particle_on_shape(int UNUSED(distr), int UNUSED(index),
float *UNUSED(fuv), float vec[3], float nor[3], float utan[3], float vtan[3],
- float orco[3], float ornor[3])
+ float orco[3])
{
/* TODO */
float zerovec[3] = {0.0f, 0.0f, 0.0f};
@@ -1731,9 +1532,6 @@ static void psys_particle_on_shape(int UNUSED(distr), int UNUSED(index),
if (orco) {
copy_v3_v3(orco, zerovec);
}
- if (ornor) {
- copy_v3_v3(ornor, zerovec);
- }
}
/************************************************/
/* Particles on emitter */
@@ -1776,7 +1574,7 @@ CustomDataMask psys_emitter_customdata_mask(ParticleSystem *psys)
void psys_particle_on_emitter(ParticleSystemModifierData *psmd, int from, int index, int index_dmcache,
float fuv[4], float foffset, float vec[3], float nor[3], float utan[3], float vtan[3],
- float orco[3], float ornor[3])
+ float orco[3])
{
if (psmd && psmd->dm_final) {
if (psmd->psys->part->distr == PART_DISTR_GRID && psmd->psys->part->from != PART_FROM_VERT) {
@@ -1788,10 +1586,10 @@ void psys_particle_on_emitter(ParticleSystemModifierData *psmd, int from, int in
return;
}
/* we cant use the num_dmcache */
- psys_particle_on_dm(psmd->dm_final, from, index, index_dmcache, fuv, foffset, vec, nor, utan, vtan, orco, ornor);
+ psys_particle_on_dm(psmd->dm_final, from, index, index_dmcache, fuv, foffset, vec, nor, utan, vtan, orco);
}
else
- psys_particle_on_shape(from, index, fuv, vec, nor, utan, vtan, orco, ornor);
+ psys_particle_on_shape(from, index, fuv, vec, nor, utan, vtan, orco);
}
/************************************************/
@@ -1813,7 +1611,7 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors)
return;
LOOP_PARTICLES {
- psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, state.co, 0, 0, 0, 0, 0);
+ psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, state.co, 0, 0, 0, 0);
mul_m4_v3(sim->ob->obmat, state.co);
mul_mat3_m4_v3(sim->ob->obmat, state.vel);
@@ -1839,7 +1637,7 @@ void precalc_guides(ParticleSimulationData *sim, ListBase *effectors)
}
}
-int do_guides(ParticleSettings *part, ListBase *effectors, ParticleKey *state, int index, float time)
+int do_guides(Depsgraph *depsgraph, ParticleSettings *part, ListBase *effectors, ParticleKey *state, int index, float time)
{
CurveMapping *clumpcurve = (part->child_flag & PART_CHILD_USE_CLUMP_CURVE) ? part->clumpcurve : NULL;
CurveMapping *roughcurve = (part->child_flag & PART_CHILD_USE_ROUGH_CURVE) ? part->roughcurve : NULL;
@@ -1902,7 +1700,7 @@ int do_guides(ParticleSettings *part, ListBase *effectors, ParticleKey *state, i
/* curve taper */
if (cu->taperobj)
- mul_v3_fl(vec_to_point, BKE_displist_calc_taper(eff->scene, cu->taperobj, (int)(data->strength * guidetime * 100.0f), 100));
+ mul_v3_fl(vec_to_point, BKE_displist_calc_taper(depsgraph, eff->scene, cu->taperobj, (int)(data->strength * guidetime * 100.0f), 100));
else { /* curve size*/
if (cu->flag & CU_PATH_RADIUS) {
@@ -2041,7 +1839,7 @@ void psys_find_parents(ParticleSimulationData *sim, const bool use_render_params
int from = PART_FROM_FACE;
totparent = (int)(totchild * part->parents * 0.3f);
- if ((sim->psys->renderdata || use_render_params) && part->child_nbr && part->ren_child_nbr)
+ if (use_render_params && part->child_nbr && part->ren_child_nbr)
totparent *= (float)part->child_nbr / (float)part->ren_child_nbr;
/* hard limit, workaround for it being ignored above */
@@ -2052,7 +1850,7 @@ void psys_find_parents(ParticleSimulationData *sim, const bool use_render_params
tree = BLI_kdtree_new(totparent);
for (p = 0, cpa = sim->psys->child; p < totparent; p++, cpa++) {
- psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0);
+ psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco);
/* Check if particle doesn't exist because of texture influence. Insert only existing particles into kdtree. */
get_cpa_texture(sim->psmd->dm_final, psys, part, psys->particles + cpa->pa[0], p, cpa->num, cpa->fuv, orco, &ptex, PAMAP_DENS | PAMAP_CHILD, psys->cfra);
@@ -2065,7 +1863,7 @@ void psys_find_parents(ParticleSimulationData *sim, const bool use_render_params
BLI_kdtree_balance(tree);
for (; p < totchild; p++, cpa++) {
- psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco, 0);
+ psys_particle_on_emitter(sim->psmd, from, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, co, 0, 0, 0, orco);
cpa->parent = BLI_kdtree_find_nearest(tree, orco, NULL);
}
@@ -2085,10 +1883,10 @@ static bool psys_thread_context_init_path(
psys_thread_context_init(ctx, sim);
/*---start figuring out what is actually wanted---*/
- if (psys_in_edit_mode(scene, psys)) {
+ if (psys_in_edit_mode(sim->depsgraph, psys)) {
ParticleEditSettings *pset = &scene->toolsettings->particle;
- if ((psys->renderdata == 0 && use_render_params == 0) && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0)
+ if ((use_render_params == 0) && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0)
totchild = 0;
segments = 1 << pset->draw_step;
@@ -2097,14 +1895,14 @@ static bool psys_thread_context_init_path(
if (totchild && part->childtype == PART_CHILD_FACES) {
totparent = (int)(totchild * part->parents * 0.3f);
- if ((psys->renderdata || use_render_params) && part->child_nbr && part->ren_child_nbr)
+ if (use_render_params && part->child_nbr && part->ren_child_nbr)
totparent *= (float)part->child_nbr / (float)part->ren_child_nbr;
/* part->parents could still be 0 so we can't test with totparent */
between = 1;
}
- if (psys->renderdata || use_render_params)
+ if (use_render_params)
segments = 1 << part->ren_step;
else {
totchild = (int)((float)totchild * (float)part->disp / 100.0f);
@@ -2182,11 +1980,11 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
ParticleSystem *psys = ctx->sim.psys;
ParticleSettings *part = psys->part;
ParticleCacheKey **cache = psys->childcache;
- ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.scene, psys) && psys->edit ? psys->edit->pathcache : psys->pathcache;
+ ParticleCacheKey **pcache = psys_in_edit_mode(ctx->sim.depsgraph, psys) && psys->edit ? psys->edit->pathcache : psys->pathcache;
ParticleCacheKey *child, *key[4];
ParticleTexture ptex;
float *cpa_fuv = 0, *par_rot = 0, rot[4];
- float orco[3], ornor[3], hairmat[4][4], dvec[3], off1[4][3], off2[4][3];
+ float orco[3], hairmat[4][4], dvec[3], off1[4][3], off2[4][3];
float eff_length, eff_vec[3], weight[4];
int k, cpa_num;
short cpa_from;
@@ -2282,7 +2080,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
cpa_fuv = cpa->fuv;
cpa_from = PART_FROM_FACE;
- psys_particle_on_emitter(ctx->sim.psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa->fuv, foffset, co, ornor, 0, 0, orco, 0);
+ psys_particle_on_emitter(ctx->sim.psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa->fuv, foffset, co, 0, 0, orco, 0);
mul_m4_v3(ob->obmat, co);
@@ -2324,7 +2122,7 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
cpa_num = 0;
cpa_fuv = pa->fuv;
- psys_particle_on_emitter(ctx->sim.psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa_fuv, pa->foffset, co, ornor, 0, 0, orco, 0);
+ psys_particle_on_emitter(ctx->sim.psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa_fuv, pa->foffset, co, 0, 0, orco, 0);
psys_mat_hair_to_global(ob, ctx->sim.psmd->dm_final, psys->part->from, pa, hairmat);
}
@@ -2432,9 +2230,9 @@ static void psys_thread_create_path(ParticleTask *task, struct ChildParticle *cp
BLI_listbase_clear(&modifiers);
psys_particle_on_emitter(ctx->sim.psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset,
- par_co, NULL, NULL, NULL, par_orco, NULL);
+ par_co, NULL, NULL, NULL, par_orco);
- psys_apply_child_modifiers(ctx, &modifiers, cpa, &ptex, orco, ornor, hairmat, child_keys, par, par_orco);
+ psys_apply_child_modifiers(ctx, &modifiers, cpa, &ptex, orco, hairmat, child_keys, par, par_orco);
}
else
zero_v3(par_orco);
@@ -2571,7 +2369,9 @@ static void cache_key_incremental_rotation(ParticleCacheKey *key0, ParticleCache
void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_render_params)
{
PARTICLE_PSMD;
+#if 0
ParticleEditSettings *pset = &sim->scene->toolsettings->particle;
+#endif
ParticleSystem *psys = sim->psys;
ParticleSettings *part = psys->part;
ParticleCacheKey *ca, **cache;
@@ -2592,7 +2392,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
float prev_tangent[3] = {0.0f, 0.0f, 0.0f}, hairmat[4][4];
float rotmat[3][3];
int k;
- int segments = (int)pow(2.0, (double)((psys->renderdata || use_render_params) ? part->ren_step : part->draw_step));
+ int segments = (int)pow(2.0, (double)((use_render_params) ? part->ren_step : part->draw_step));
int totpart = psys->totpart;
float length, vec[3];
float *vg_effector = NULL;
@@ -2603,9 +2403,11 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
if ((psys->flag & PSYS_HAIR_DONE || psys->flag & PSYS_KEYED || psys->pointcache) == 0)
return;
- if (psys_in_edit_mode(sim->scene, psys))
- if (psys->renderdata == 0 && (psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0)
+#if 0 /* TODO(mai): something is very wrong with these conditionals, they dont make sense and the cache isnt updating */
+ if (psys_in_edit_mode(sim->depsgraph, psys))
+ if ((psys->edit == NULL || pset->flag & PE_DRAW_PART) == 0)
return;
+#endif
keyed = psys->flag & PSYS_KEYED;
baked = psys->pointcache->mem_cache.first && psys->part->type != PART_HAIR;
@@ -2723,7 +2525,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
if (sim->psys->effectors && (psys->part->flag & PART_CHILD_EFFECT) == 0) {
for (k = 0, ca = cache[p]; k <= segments; k++, ca++)
/* ca is safe to cast, since only co and vel are used */
- do_guides(sim->psys->part, sim->psys->effectors, (ParticleKey *)ca, p, (float)k / (float)segments);
+ do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, (ParticleKey *)ca, p, (float)k / (float)segments);
}
/* lattices have to be calculated separately to avoid mixups between effector calculations */
@@ -2771,7 +2573,7 @@ void psys_cache_paths(ParticleSimulationData *sim, float cfra, const bool use_re
if (vg_length)
MEM_freeN(vg_length);
}
-void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cfra, const bool use_render_params)
+void psys_cache_edit_paths(Depsgraph *depsgraph, Scene *scene, Object *ob, PTCacheEdit *edit, float cfra, const bool use_render_params)
{
ParticleCacheKey *ca, **cache = edit->pathcache;
ParticleEditSettings *pset = &scene->toolsettings->particle;
@@ -2799,7 +2601,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
if (!cache || edit->totpoint != edit->totcached) {
/* clear out old and create new empty path cache */
- psys_free_path_cache(edit->psys, edit);
+ psys_free_path_cache(NULL, edit);
cache = edit->pathcache = psys_alloc_path_cache_buffers(&edit->pathcachebufs, totpart, segments + 1);
/* set flag for update (child particles check this too) */
@@ -2972,6 +2774,7 @@ void psys_cache_edit_paths(Scene *scene, Object *ob, PTCacheEdit *edit, float cf
if (psys) {
ParticleSimulationData sim = {0};
+ sim.depsgraph = depsgraph;
sim.scene = scene;
sim.ob = ob;
sim.psys = psys;
@@ -3108,7 +2911,7 @@ void psys_mat_hair_to_object(Object *UNUSED(ob), DerivedMesh *dm, short from, Pa
}
psys_face_mat(0, dm, pa, hairmat, 0);
- psys_particle_on_dm(dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, vec, 0, 0, 0, 0, 0);
+ psys_particle_on_dm(dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, vec, 0, 0, 0, 0);
copy_v3_v3(hairmat[3], vec);
}
@@ -3117,7 +2920,7 @@ void psys_mat_hair_to_orco(Object *ob, DerivedMesh *dm, short from, ParticleData
float vec[3], orco[3];
psys_face_mat(ob, dm, pa, hairmat, 1);
- psys_particle_on_dm(dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, vec, 0, 0, 0, orco, 0);
+ psys_particle_on_dm(dm, from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, vec, 0, 0, 0, orco);
/* see psys_face_mat for why this function is called */
if (DM_get_vert_data_layer(dm, CD_ORIGINDEX))
@@ -3186,8 +2989,8 @@ ModifierData *object_add_particle_system(Scene *scene, Object *ob, const char *n
psys->flag = PSYS_CURRENT;
psys->cfra = BKE_scene_frame_get_from_ctime(scene, CFRA + 1);
- DAG_relations_tag_update(G.main);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(G.main);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
return md;
}
@@ -3232,8 +3035,8 @@ void object_remove_particle_system(Scene *UNUSED(scene), Object *ob)
else
ob->mode &= ~OB_MODE_PARTICLE_EDIT;
- DAG_relations_tag_update(G.main);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(G.main);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
static void default_particle_settings(ParticleSettings *part)
@@ -3296,7 +3099,7 @@ static void default_particle_settings(ParticleSettings *part)
part->clength = 1.0f;
part->clength_thres = 0.0f;
- part->draw = PART_DRAW_EMITTER;
+ part->draw = 0;
part->draw_line[0] = 0.5;
part->path_start = 0.0f;
part->path_end = 1.0f;
@@ -3308,16 +3111,12 @@ static void default_particle_settings(ParticleSettings *part)
part->color_vec_max = 1.f;
part->draw_col = PART_DRAW_COL_MAT;
- part->simplify_refsize = 1920;
- part->simplify_rate = 1.0f;
- part->simplify_transition = 0.1f;
- part->simplify_viewport = 0.8;
-
if (!part->effector_weights)
part->effector_weights = BKE_add_effector_weights(NULL);
part->omat = 1;
part->use_modifier_stack = false;
+ part->draw_size = 0.1f;
}
@@ -3626,7 +3425,7 @@ void psys_get_texture(ParticleSimulationData *sim, ParticleData *pa, ParticleTex
/* no break, failed to get uv's, so let's try orco's */
ATTR_FALLTHROUGH;
case TEXCO_ORCO:
- psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, 0, 0, 0, texvec, 0);
+ psys_particle_on_emitter(sim->psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, 0, 0, 0, texvec);
if (me->bb == NULL || (me->bb->flag & BOUNDBOX_DIRTY)) {
BKE_mesh_texspace_calc(me);
@@ -3822,7 +3621,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
pind.bspline = (psys->part->flag & PART_HAIR_BSPLINE);
/* pind.dm disabled in editmode means we don't get effectors taken into
* account when subdividing for instance */
- pind.dm = psys_in_edit_mode(sim->scene, psys) ? NULL : psys->hair_out_dm;
+ pind.dm = psys_in_edit_mode(sim->depsgraph, psys) ? NULL : psys->hair_out_dm;
init_particle_interpolation(sim->ob, psys, pa, &pind);
do_particle_interpolation(psys, p, pa, t, &pind, state);
@@ -3837,7 +3636,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
mul_mat3_m4_v3(hairmat, state->vel);
if (sim->psys->effectors && (part->flag & PART_CHILD_GUIDE) == 0) {
- do_guides(sim->psys->part, sim->psys->effectors, state, p, state->time);
+ do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, state, p, state->time);
/* TODO: proper velocity handling */
}
@@ -3888,7 +3687,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
cpa_fuv = cpa->fuv;
cpa_from = PART_FROM_FACE;
- psys_particle_on_emitter(psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa->fuv, foffset, co, 0, 0, 0, orco, 0);
+ psys_particle_on_emitter(psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa->fuv, foffset, co, 0, 0, 0, orco);
/* we need to save the actual root position of the child for positioning it accurately to the surface of the emitter */
//copy_v3_v3(cpa_1st, co);
@@ -3897,7 +3696,7 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
pa = psys->particles + cpa->parent;
- psys_particle_on_emitter(psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, par_co, 0, 0, 0, par_orco, 0);
+ psys_particle_on_emitter(psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, par_co, 0, 0, 0, par_orco);
if (part->type == PART_HAIR)
psys_mat_hair_to_global(sim->ob, sim->psmd->dm_final, psys->part->from, pa, hairmat);
else
@@ -3917,9 +3716,9 @@ void psys_get_particle_on_path(ParticleSimulationData *sim, int p, ParticleKey *
cpa_num = pa->num;
cpa_fuv = pa->fuv;
- psys_particle_on_emitter(psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, par_co, 0, 0, 0, par_orco, 0);
+ psys_particle_on_emitter(psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, par_co, 0, 0, 0, par_orco);
if (part->type == PART_HAIR) {
- psys_particle_on_emitter(psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa_fuv, pa->foffset, co, 0, 0, 0, orco, 0);
+ psys_particle_on_emitter(psmd, cpa_from, cpa_num, DMCACHE_ISCHILD, cpa_fuv, pa->foffset, co, 0, 0, 0, orco);
psys_mat_hair_to_global(sim->ob, sim->psmd->dm_final, psys->part->from, pa, hairmat);
}
else {
@@ -4204,7 +4003,7 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part,
psys_interpolate_uvs(mtface, mface->v4, cpa->fuv, uv);
}
- psys_particle_on_emitter(psmd, PART_FROM_FACE, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, loc, 0, 0, 0, orco, 0);
+ psys_particle_on_emitter(psmd, PART_FROM_FACE, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, loc, 0, 0, 0, orco);
return;
}
else {
@@ -4235,7 +4034,7 @@ void psys_get_dupli_texture(ParticleSystem *psys, ParticleSettings *part,
}
}
- psys_particle_on_emitter(psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, 0, 0, 0, orco, 0);
+ psys_particle_on_emitter(psmd, part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, 0, 0, 0, orco);
}
void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa, ChildParticle *cpa, ParticleCacheKey *cache, float mat[4][4], float *scale)
@@ -4253,9 +4052,9 @@ void psys_get_dupli_path_transform(ParticleSimulationData *sim, ParticleData *pa
pa = psys->particles + cpa->pa[0];
if (pa)
- psys_particle_on_emitter(psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, nor, 0, 0, 0, 0);
+ psys_particle_on_emitter(psmd, sim->psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, loc, nor, 0, 0, 0);
else
- psys_particle_on_emitter(psmd, PART_FROM_FACE, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, loc, nor, 0, 0, 0, 0);
+ psys_particle_on_emitter(psmd, PART_FROM_FACE, cpa->num, DMCACHE_ISCHILD, cpa->fuv, cpa->foffset, loc, nor, 0, 0, 0);
if (psys->part->rotmode == PART_ROT_VEL) {
transpose_m3_m4(nmat, ob->imat);
@@ -4387,9 +4186,10 @@ void psys_make_billboard(ParticleBillboardData *bb, float xvec[3], float yvec[3]
madd_v3_v3fl(center, yvec, bb->offset[1]);
}
-void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys)
+void psys_apply_hair_lattice(Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys)
{
ParticleSimulationData sim = {0};
+ sim.depsgraph = depsgraph;
sim.scene = scene;
sim.ob = ob;
sim.psys = psys;
@@ -4422,3 +4222,22 @@ void psys_apply_hair_lattice(Scene *scene, Object *ob, ParticleSystem *psys)
psys->flag |= PSYS_EDITED;
}
}
+
+
+
+/* Draw Engine */
+void (*BKE_particle_batch_cache_dirty_cb)(ParticleSystem *psys, int mode) = NULL;
+void (*BKE_particle_batch_cache_free_cb)(ParticleSystem *psys) = NULL;
+
+void BKE_particle_batch_cache_dirty(ParticleSystem *psys, int mode)
+{
+ if (psys->batch_cache) {
+ BKE_particle_batch_cache_dirty_cb(psys, mode);
+ }
+}
+void BKE_particle_batch_cache_free(ParticleSystem *psys)
+{
+ if (psys->batch_cache) {
+ BKE_particle_batch_cache_free_cb(psys);
+ }
+}
diff --git a/source/blender/blenkernel/intern/particle_child.c b/source/blender/blenkernel/intern/particle_child.c
index c921e1ea107..7cfad93224d 100644
--- a/source/blender/blenkernel/intern/particle_child.c
+++ b/source/blender/blenkernel/intern/particle_child.c
@@ -39,40 +39,6 @@
#include "particle_private.h"
-struct Material;
-
-static void get_strand_normal(Material *ma, const float surfnor[3], float surfdist, float nor[3])
-{
- float cross[3], nstrand[3], vnor[3], blend;
-
- if (!((ma->mode & MA_STR_SURFDIFF) || (ma->strand_surfnor > 0.0f)))
- return;
-
- if (ma->mode & MA_STR_SURFDIFF) {
- cross_v3_v3v3(cross, surfnor, nor);
- cross_v3_v3v3(nstrand, nor, cross);
-
- blend = dot_v3v3(nstrand, surfnor);
- CLAMP(blend, 0.0f, 1.0f);
-
- interp_v3_v3v3(vnor, nstrand, surfnor, blend);
- normalize_v3(vnor);
- }
- else {
- copy_v3_v3(vnor, nor);
- }
-
- if (ma->strand_surfnor > 0.0f) {
- if (ma->strand_surfnor > surfdist) {
- blend = (ma->strand_surfnor - surfdist) / ma->strand_surfnor;
- interp_v3_v3v3(vnor, vnor, surfnor, blend);
- normalize_v3(vnor);
- }
- }
-
- copy_v3_v3(nor, vnor);
-}
-
/* ------------------------------------------------------------------------- */
typedef struct ParticlePathIterator {
@@ -320,7 +286,7 @@ static bool check_path_length(int k, ParticleCacheKey *keys, ParticleCacheKey *k
}
void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *modifiers,
- ChildParticle *cpa, ParticleTexture *ptex, const float orco[3], const float ornor[3], float hairmat[4][4],
+ ChildParticle *cpa, ParticleTexture *ptex, const float orco[3], float hairmat[4][4],
ParticleCacheKey *keys, ParticleCacheKey *parent_keys, const float parent_orco[3])
{
struct ParticleSettings *part = ctx->sim.psys->part;
@@ -389,9 +355,6 @@ void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *mod
if (k >= 2) {
sub_v3_v3v3((key-1)->vel, key->co, (key-2)->co);
mul_v3_fl((key-1)->vel, 0.5);
-
- if (ma && draw_col_ma)
- get_strand_normal(ma, ornor, cur_length, (key-1)->vel);
}
if (use_length_check && k > 0) {
@@ -413,7 +376,6 @@ void psys_apply_child_modifiers(ParticleThreadContext *ctx, struct ListBase *mod
if (ma && draw_col_ma) {
copy_v3_v3(key->col, &ma->r);
- get_strand_normal(ma, ornor, cur_length, key->vel);
}
}
}
@@ -816,7 +778,7 @@ void do_child_modifiers(const ParticleChildModifierContext *modifier_ctx,
if (part->flag & PART_CHILD_EFFECT)
/* state is safe to cast, since only co and vel are used */
- guided = do_guides(sim->psys->part, sim->psys->effectors, (ParticleKey *)state, cpa->parent, t);
+ guided = do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, (ParticleKey *)state, cpa->parent, t);
if (guided == 0) {
float orco_offset[3];
diff --git a/source/blender/blenkernel/intern/particle_distribute.c b/source/blender/blenkernel/intern/particle_distribute.c
index d1c6dbe421c..bf21e18f4b9 100644
--- a/source/blender/blenkernel/intern/particle_distribute.c
+++ b/source/blender/blenkernel/intern/particle_distribute.c
@@ -57,7 +57,7 @@
#include "BKE_object.h"
#include "BKE_particle.h"
-static int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot);
+#include "DEG_depsgraph_query.h"
static void alloc_child_particles(ParticleSystem *psys, int tot)
{
@@ -80,12 +80,12 @@ static void alloc_child_particles(ParticleSystem *psys, int tot)
}
}
-static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *finaldm, DerivedMesh *deformdm, ParticleSystem *psys)
+static void distribute_simple_children(Scene *scene, Object *ob, DerivedMesh *finaldm, DerivedMesh *deformdm, ParticleSystem *psys, const bool use_render_params)
{
ChildParticle *cpa = NULL;
int i, p;
- int child_nbr= psys_get_child_number(scene, psys);
- int totpart= psys_get_tot_child(scene, psys);
+ int child_nbr= psys_get_child_number(scene, psys, use_render_params);
+ int totpart= psys_get_tot_child(scene, psys, use_render_params);
alloc_child_particles(psys, totpart);
@@ -314,19 +314,16 @@ static void distribute_grid(DerivedMesh *dm, ParticleSystem *psys)
static void hammersley_create(float *out, int n, int seed, float amount)
{
RNG *rng;
- double p, t, offs[2];
- int k, kk;
+
+ double offs[2], t;
rng = BLI_rng_new(31415926 + n + seed);
offs[0] = BLI_rng_get_double(rng) + (double)amount;
offs[1] = BLI_rng_get_double(rng) + (double)amount;
BLI_rng_free(rng);
- for (k = 0; k < n; k++) {
- t = 0;
- for (p = 0.5, kk = k; kk; p *= 0.5, kk >>= 1)
- if (kk & 1) /* kk mod 2 = 1 */
- t += p;
+ for (int k = 0; k < n; k++) {
+ BLI_hammersley_1D(k, &t);
out[2*k + 0] = fmod((double)k/(double)n + offs[0], 1.0);
out[2*k + 1] = fmod(t + offs[1], 1.0);
@@ -577,7 +574,7 @@ static void distribute_from_volume_exec(ParticleTask *thread, ParticleData *pa,
/* experimental */
tot=dm->getNumTessFaces(dm);
- psys_interpolate_face(mvert,mface,0,0,pa->fuv,co,nor,0,0,0,0);
+ psys_interpolate_face(mvert,mface,0,0,pa->fuv,co,nor,0,0,0);
normalize_v3(nor);
negate_v3(nor);
@@ -664,7 +661,7 @@ static void distribute_children_exec(ParticleTask *thread, ChildParticle *cpa, i
int parent[10];
float pweight[10];
- psys_particle_on_dm(dm,cfrom,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,co1,nor1,NULL,NULL,orco1,NULL);
+ psys_particle_on_dm(dm,cfrom,cpa->num,DMCACHE_ISCHILD,cpa->fuv,cpa->foffset,co1,nor1,NULL,NULL,orco1);
BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco1, 1, 1);
maxw = BLI_kdtree_find_nearest_n(ctx->tree,orco1,ptn,3);
@@ -743,16 +740,10 @@ static void exec_distribute_child(TaskPool * __restrict UNUSED(pool), void *task
/* RNG skipping at the beginning */
cpa = psys->child;
for (p = 0; p < task->begin; ++p, ++cpa) {
- if (task->ctx->skip) /* simplification skip */
- BLI_rng_skip(task->rng, PSYS_RND_DIST_SKIP * task->ctx->skip[p]);
-
BLI_rng_skip(task->rng, PSYS_RND_DIST_SKIP);
}
for (; p < task->end; ++p, ++cpa) {
- if (task->ctx->skip) /* simplification skip */
- BLI_rng_skip(task->rng, PSYS_RND_DIST_SKIP * task->ctx->skip[p]);
-
distribute_children_exec(task, cpa, p);
}
}
@@ -779,11 +770,15 @@ static int distribute_compare_orig_index(const void *p1, const void *p2, void *u
return 1;
}
-static void distribute_invalid(Scene *scene, ParticleSystem *psys, int from)
+static void distribute_invalid(ParticleSimulationData *sim, int from)
{
+ Scene *scene = sim->scene;
+ ParticleSystem *psys = sim->psys;
+ const bool use_render_params = (DEG_get_mode(sim->depsgraph) == DAG_EVAL_RENDER);
+
if (from == PART_FROM_CHILD) {
ChildParticle *cpa;
- int p, totchild = psys_get_tot_child(scene, psys);
+ int p, totchild = psys_get_tot_child(scene, psys, use_render_params);
if (psys->child && totchild) {
for (p=0,cpa=psys->child; p<totchild; p++,cpa++) {
@@ -846,13 +841,15 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
*/
psys_thread_context_init(ctx, sim);
+
+ const bool use_render_params = (DEG_get_mode(sim->depsgraph) == DAG_EVAL_RENDER);
/* First handle special cases */
if (from == PART_FROM_CHILD) {
/* Simple children */
if (part->childtype != PART_CHILD_FACES) {
BLI_srandom(31415926 + psys->seed + psys->child_seed);
- distribute_simple_children(scene, ob, finaldm, sim->psmd->dm_deformed, psys);
+ distribute_simple_children(scene, ob, finaldm, sim->psmd->dm_deformed, psys, use_render_params);
return 0;
}
}
@@ -893,14 +890,14 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
tree=BLI_kdtree_new(totpart);
for (p=0,pa=psys->particles; p<totpart; p++,pa++) {
- psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco,NULL);
+ psys_particle_on_dm(dm,part->from,pa->num,pa->num_dmcache,pa->fuv,pa->foffset,co,nor,0,0,orco);
BKE_mesh_orco_verts_transform((Mesh*)ob->data, &orco, 1, 1);
BLI_kdtree_insert(tree, p, orco);
}
BLI_kdtree_balance(tree);
- totpart = psys_get_tot_child(scene, psys);
+ totpart = psys_get_tot_child(scene, psys, use_render_params);
cfrom = from = PART_FROM_FACE;
}
else {
@@ -943,7 +940,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
totelem = (from == PART_FROM_VERT) ? dm->getNumVerts(dm) : dm->getNumTessFaces(dm);
if (totelem == 0) {
- distribute_invalid(scene, psys, children ? PART_FROM_CHILD : 0);
+ distribute_invalid(sim, children ? PART_FROM_CHILD : 0);
if (G.debug & G_DEBUG)
fprintf(stderr,"Particle distribution error: Nothing to emit from!\n");
@@ -1087,7 +1084,7 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
totmapped = i_mapped;
/* Finally assign elements to particles */
- if ((part->flag & PART_TRAND) || (part->simplify_flag & PART_SIMPLIFY_ENABLE)) {
+ if (part->flag & PART_TRAND) {
for (p = 0; p < totpart; p++) {
/* In theory element_sum[totmapped - 1] should be 1.0,
* but due to float errors this is not necessarily always true, so scale pos accordingly. */
@@ -1181,7 +1178,6 @@ static int psys_thread_context_init_distribute(ParticleThreadContext *ctx, Parti
ctx->tpars= tpars;
if (children) {
- totpart= psys_render_simplify_distribution(ctx, totpart);
alloc_child_particles(psys, totpart);
}
@@ -1240,7 +1236,7 @@ static void distribute_particles_on_dm(ParticleSimulationData *sim, int from)
/* ready for future use, to emit particles without geometry */
static void distribute_particles_on_shape(ParticleSimulationData *sim, int UNUSED(from))
{
- distribute_invalid(sim->scene, sim->psys, 0);
+ distribute_invalid(sim, 0);
fprintf(stderr,"Shape emission not yet possible!\n");
}
@@ -1260,250 +1256,8 @@ void distribute_particles(ParticleSimulationData *sim, int from)
distribute_particles_on_shape(sim, from);
if (distr_error) {
- distribute_invalid(sim->scene, sim->psys, from);
+ distribute_invalid(sim, from);
fprintf(stderr,"Particle distribution error!\n");
}
}
-
-/* ======== Simplify ======== */
-
-static float psys_render_viewport_falloff(double rate, float dist, float width)
-{
- return pow(rate, dist / width);
-}
-
-static float psys_render_projected_area(ParticleSystem *psys, const float center[3], float area, double vprate, float *viewport)
-{
- ParticleRenderData *data = psys->renderdata;
- float co[4], view[3], ortho1[3], ortho2[3], w, dx, dy, radius;
-
- /* transform to view space */
- copy_v3_v3(co, center);
- co[3] = 1.0f;
- mul_m4_v4(data->viewmat, co);
-
- /* compute two vectors orthogonal to view vector */
- normalize_v3_v3(view, co);
- ortho_basis_v3v3_v3(ortho1, ortho2, view);
-
- /* compute on screen minification */
- w = co[2] * data->winmat[2][3] + data->winmat[3][3];
- dx = data->winx * ortho2[0] * data->winmat[0][0];
- dy = data->winy * ortho2[1] * data->winmat[1][1];
- w = sqrtf(dx * dx + dy * dy) / w;
-
- /* w squared because we are working with area */
- area = area * w * w;
-
- /* viewport of the screen test */
-
- /* project point on screen */
- mul_m4_v4(data->winmat, co);
- if (co[3] != 0.0f) {
- co[0] = 0.5f * data->winx * (1.0f + co[0] / co[3]);
- co[1] = 0.5f * data->winy * (1.0f + co[1] / co[3]);
- }
-
- /* screen space radius */
- radius = sqrtf(area / (float)M_PI);
-
- /* make smaller using fallof once over screen edge */
- *viewport = 1.0f;
-
- if (co[0] + radius < 0.0f)
- *viewport *= psys_render_viewport_falloff(vprate, -(co[0] + radius), data->winx);
- else if (co[0] - radius > data->winx)
- *viewport *= psys_render_viewport_falloff(vprate, (co[0] - radius) - data->winx, data->winx);
-
- if (co[1] + radius < 0.0f)
- *viewport *= psys_render_viewport_falloff(vprate, -(co[1] + radius), data->winy);
- else if (co[1] - radius > data->winy)
- *viewport *= psys_render_viewport_falloff(vprate, (co[1] - radius) - data->winy, data->winy);
-
- return area;
-}
-
-/* BMESH_TODO, for orig face data, we need to use MPoly */
-static int psys_render_simplify_distribution(ParticleThreadContext *ctx, int tot)
-{
- DerivedMesh *dm = ctx->dm;
- Mesh *me = (Mesh *)(ctx->sim.ob->data);
- MFace *mf, *mface;
- MVert *mvert;
- ParticleRenderData *data;
- ParticleRenderElem *elems, *elem;
- ParticleSettings *part = ctx->sim.psys->part;
- float *facearea, (*facecenter)[3], size[3], fac, powrate, scaleclamp;
- float co1[3], co2[3], co3[3], co4[3], lambda, arearatio, t, area, viewport;
- double vprate;
- int *facetotvert;
- int a, b, totorigface, totface, newtot, skipped;
-
- /* double lookup */
- const int *index_mf_to_mpoly;
- const int *index_mp_to_orig;
-
- if (part->ren_as != PART_DRAW_PATH || !(part->draw & PART_DRAW_REN_STRAND))
- return tot;
- if (!ctx->sim.psys->renderdata)
- return tot;
-
- data = ctx->sim.psys->renderdata;
- if (data->timeoffset)
- return 0;
- if (!(part->simplify_flag & PART_SIMPLIFY_ENABLE))
- return tot;
-
- mvert = dm->getVertArray(dm);
- mface = dm->getTessFaceArray(dm);
- totface = dm->getNumTessFaces(dm);
- totorigface = me->totpoly;
-
- if (totface == 0 || totorigface == 0)
- return tot;
-
- index_mf_to_mpoly = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
- index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
- if (index_mf_to_mpoly == NULL) {
- index_mp_to_orig = NULL;
- }
-
- facearea = MEM_callocN(sizeof(float) * totorigface, "SimplifyFaceArea");
- facecenter = MEM_callocN(sizeof(float[3]) * totorigface, "SimplifyFaceCenter");
- facetotvert = MEM_callocN(sizeof(int) * totorigface, "SimplifyFaceArea");
- elems = MEM_callocN(sizeof(ParticleRenderElem) * totorigface, "SimplifyFaceElem");
-
- if (data->elems)
- MEM_freeN(data->elems);
-
- data->do_simplify = true;
- data->elems = elems;
- data->index_mf_to_mpoly = index_mf_to_mpoly;
- data->index_mp_to_orig = index_mp_to_orig;
-
- /* compute number of children per original face */
- for (a = 0; a < tot; a++) {
- b = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, ctx->index[a]) : ctx->index[a];
- if (b != ORIGINDEX_NONE) {
- elems[b].totchild++;
- }
- }
-
- /* compute areas and centers of original faces */
- for (mf = mface, a = 0; a < totface; a++, mf++) {
- b = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a) : a;
-
- if (b != ORIGINDEX_NONE) {
- copy_v3_v3(co1, mvert[mf->v1].co);
- copy_v3_v3(co2, mvert[mf->v2].co);
- copy_v3_v3(co3, mvert[mf->v3].co);
-
- add_v3_v3(facecenter[b], co1);
- add_v3_v3(facecenter[b], co2);
- add_v3_v3(facecenter[b], co3);
-
- if (mf->v4) {
- copy_v3_v3(co4, mvert[mf->v4].co);
- add_v3_v3(facecenter[b], co4);
- facearea[b] += area_quad_v3(co1, co2, co3, co4);
- facetotvert[b] += 4;
- }
- else {
- facearea[b] += area_tri_v3(co1, co2, co3);
- facetotvert[b] += 3;
- }
- }
- }
-
- for (a = 0; a < totorigface; a++)
- if (facetotvert[a] > 0)
- mul_v3_fl(facecenter[a], 1.0f / facetotvert[a]);
-
- /* for conversion from BU area / pixel area to reference screen size */
- BKE_mesh_texspace_get(me, 0, 0, size);
- fac = ((size[0] + size[1] + size[2]) / 3.0f) / part->simplify_refsize;
- fac = fac * fac;
-
- powrate = log(0.5f) / log(part->simplify_rate * 0.5f);
- if (part->simplify_flag & PART_SIMPLIFY_VIEWPORT)
- vprate = pow(1.0f - part->simplify_viewport, 5.0);
- else
- vprate = 1.0;
-
- /* set simplification parameters per original face */
- for (a = 0, elem = elems; a < totorigface; a++, elem++) {
- area = psys_render_projected_area(ctx->sim.psys, facecenter[a], facearea[a], vprate, &viewport);
- arearatio = fac * area / facearea[a];
-
- if ((arearatio < 1.0f || viewport < 1.0f) && elem->totchild) {
- /* lambda is percentage of elements to keep */
- lambda = (arearatio < 1.0f) ? powf(arearatio, powrate) : 1.0f;
- lambda *= viewport;
-
- lambda = MAX2(lambda, 1.0f / elem->totchild);
-
- /* compute transition region */
- t = part->simplify_transition;
- elem->t = (lambda - t < 0.0f) ? lambda : (lambda + t > 1.0f) ? 1.0f - lambda : t;
- elem->reduce = 1;
-
- /* scale at end and beginning of the transition region */
- elem->scalemax = (lambda + t < 1.0f) ? 1.0f / lambda : 1.0f / (1.0f - elem->t * elem->t / t);
- elem->scalemin = (lambda + t < 1.0f) ? 0.0f : elem->scalemax * (1.0f - elem->t / t);
-
- elem->scalemin = sqrtf(elem->scalemin);
- elem->scalemax = sqrtf(elem->scalemax);
-
- /* clamp scaling */
- scaleclamp = (float)min_ii(elem->totchild, 10);
- elem->scalemin = MIN2(scaleclamp, elem->scalemin);
- elem->scalemax = MIN2(scaleclamp, elem->scalemax);
-
- /* extend lambda to include transition */
- lambda = lambda + elem->t;
- if (lambda > 1.0f)
- lambda = 1.0f;
- }
- else {
- lambda = arearatio;
-
- elem->scalemax = 1.0f; //sqrt(lambda);
- elem->scalemin = 1.0f; //sqrt(lambda);
- elem->reduce = 0;
- }
-
- elem->lambda = lambda;
- elem->scalemin = sqrtf(elem->scalemin);
- elem->scalemax = sqrtf(elem->scalemax);
- elem->curchild = 0;
- }
-
- MEM_freeN(facearea);
- MEM_freeN(facecenter);
- MEM_freeN(facetotvert);
-
- /* move indices and set random number skipping */
- ctx->skip = MEM_callocN(sizeof(int) * tot, "SimplificationSkip");
-
- skipped = 0;
- for (a = 0, newtot = 0; a < tot; a++) {
- b = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, ctx->index[a]) : ctx->index[a];
-
- if (b != ORIGINDEX_NONE) {
- if (elems[b].curchild++ < ceil(elems[b].lambda * elems[b].totchild)) {
- ctx->index[newtot] = ctx->index[a];
- ctx->skip[newtot] = skipped;
- skipped = 0;
- newtot++;
- }
- else skipped++;
- }
- else skipped++;
- }
-
- for (a = 0, elem = elems; a < totorigface; a++, elem++)
- elem->curchild = 0;
-
- return newtot;
-}
diff --git a/source/blender/blenkernel/intern/particle_system.c b/source/blender/blenkernel/intern/particle_system.c
index 94c1dd0c7c3..ab307ebdbe8 100644
--- a/source/blender/blenkernel/intern/particle_system.c
+++ b/source/blender/blenkernel/intern/particle_system.c
@@ -77,6 +77,7 @@
#include "BKE_library_query.h"
#include "BKE_particle.h"
+#include "BKE_collection.h"
#include "BKE_DerivedMesh.h"
#include "BKE_object.h"
#include "BKE_material.h"
@@ -87,12 +88,16 @@
#include "BKE_modifier.h"
#include "BKE_scene.h"
#include "BKE_bvhutils.h"
-#include "BKE_depsgraph.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "PIL_time.h"
#include "RE_shader_ext.h"
-#include "DEG_depsgraph.h"
+
+/* FIXME: BAD LEVEL CALL. */
+#include "../../editors/include/ED_particle.h"
/* fluid sim particle import */
#ifdef WITH_MOD_FLUID
@@ -120,11 +125,11 @@ static int particles_are_dynamic(ParticleSystem *psys)
return ELEM(psys->part->phystype, PART_PHYS_NEWTON, PART_PHYS_BOIDS, PART_PHYS_FLUID);
}
-float psys_get_current_display_percentage(ParticleSystem *psys)
+float psys_get_current_display_percentage(ParticleSystem *psys, const bool use_render_params)
{
ParticleSettings *part=psys->part;
- if ((psys->renderdata && !particles_are_dynamic(psys)) || /* non-dynamic particles can be rendered fully */
+ if ((use_render_params && !particles_are_dynamic(psys)) || /* non-dynamic particles can be rendered fully */
(part->child_nbr && part->childtype) || /* display percentage applies to children */
(psys->pointcache->flag & PTCACHE_BAKING)) /* baking is always done with full amount */
{
@@ -284,24 +289,24 @@ static void realloc_particles(ParticleSimulationData *sim, int new_totpart)
}
}
-int psys_get_child_number(Scene *scene, ParticleSystem *psys)
+int psys_get_child_number(Scene *scene, ParticleSystem *psys, const bool use_render_params)
{
int nbr;
if (!psys->part->childtype)
return 0;
- if (psys->renderdata)
+ if (use_render_params)
nbr= psys->part->ren_child_nbr;
else
nbr= psys->part->child_nbr;
- return get_render_child_particle_number(&scene->r, nbr, psys->renderdata != NULL);
+ return get_render_child_particle_number(&scene->r, nbr, use_render_params);
}
-int psys_get_tot_child(Scene *scene, ParticleSystem *psys)
+int psys_get_tot_child(Scene *scene, ParticleSystem *psys, const bool use_render_params)
{
- return psys->totpart*psys_get_child_number(scene, psys);
+ return psys->totpart*psys_get_child_number(scene, psys, use_render_params);
}
/************************************************/
@@ -510,7 +515,6 @@ void psys_thread_context_free(ParticleThreadContext *ctx)
if (ctx->jitoff) MEM_freeN(ctx->jitoff);
if (ctx->weight) MEM_freeN(ctx->weight);
if (ctx->index) MEM_freeN(ctx->index);
- if (ctx->skip) MEM_freeN(ctx->skip);
if (ctx->seams) MEM_freeN(ctx->seams);
//if (ctx->vertpart) MEM_freeN(ctx->vertpart);
BLI_kdtree_free(ctx->tree);
@@ -701,9 +705,9 @@ void psys_get_birth_coords(ParticleSimulationData *sim, ParticleData *pa, Partic
/* get birth location from object */
if (use_tangents)
- psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,utan,vtan,0,0);
+ psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,utan,vtan,0);
else
- psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,0,0,0,0);
+ psys_particle_on_emitter(sim->psmd, part->from,pa->num, pa->num_dmcache, pa->fuv,pa->foffset,loc,nor,0,0,0);
/* get possible textural influence */
psys_get_texture(sim, pa, &ptex, PAMAP_IVEL, cfra);
@@ -987,14 +991,14 @@ void psys_get_birth_coords(ParticleSimulationData *sim, ParticleData *pa, Partic
}
/* recursively evaluate emitter parent anim at cfra */
-static void evaluate_emitter_anim(Scene *scene, Object *ob, float cfra)
+static void evaluate_emitter_anim(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float cfra)
{
if (ob->parent)
- evaluate_emitter_anim(scene, ob->parent, cfra);
+ evaluate_emitter_anim(depsgraph, scene, ob->parent, cfra);
/* we have to force RECALC_ANIM here since where_is_objec_time only does drivers */
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, cfra, ADT_RECALC_ANIM);
- BKE_object_where_is_calc_time(scene, ob, cfra);
+ BKE_object_where_is_calc_time(depsgraph, scene, ob, cfra);
}
/* sets particle to the emitter surface with initial velocity & rotation */
@@ -1008,7 +1012,7 @@ void reset_particle(ParticleSimulationData *sim, ParticleData *pa, float dtime,
/* get precise emitter matrix if particle is born */
if (part->type != PART_HAIR && dtime > 0.f && pa->time < cfra && pa->time >= sim->psys->cfra) {
- evaluate_emitter_anim(sim->scene, sim->ob, pa->time);
+ evaluate_emitter_anim(sim->depsgraph, sim->scene, sim->ob, pa->time);
psys->flag |= PSYS_OB_ANIM_RESTORE;
}
@@ -1142,7 +1146,8 @@ static void set_keyed_keys(ParticleSimulationData *sim)
int totpart = psys->totpart, k, totkeys = psys->totkeyed;
int keyed_flag = 0;
- ksim.scene= sim->scene;
+ ksim.depsgraph = sim->depsgraph;
+ ksim.scene = sim->scene;
/* no proper targets so let's clear and bail out */
if (psys->totkeyed==0) {
@@ -1303,7 +1308,7 @@ void psys_update_particle_tree(ParticleSystem *psys, float cfra)
static void psys_update_effectors(ParticleSimulationData *sim)
{
pdEndEffectors(&sim->psys->effectors);
- sim->psys->effectors = pdInitEffectors(sim->scene, sim->ob, sim->psys,
+ sim->psys->effectors = pdInitEffectors(sim->depsgraph, sim->scene, sim->ob, sim->psys,
sim->psys->part->effector_weights, true);
precalc_guides(sim, sim->psys->effectors);
}
@@ -2124,7 +2129,7 @@ static void basic_integrate(ParticleSimulationData *sim, int p, float dfra, floa
tkey.time=pa->state.time;
if (part->type != PART_HAIR) {
- if (do_guides(sim->psys->part, sim->psys->effectors, &tkey, p, time)) {
+ if (do_guides(sim->depsgraph, sim->psys->part, sim->psys->effectors, &tkey, p, time)) {
copy_v3_v3(pa->state.co,tkey.co);
/* guides don't produce valid velocity */
sub_v3_v3v3(pa->state.vel, tkey.co, pa->prev_state.co);
@@ -2905,10 +2910,9 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra, cons
ParticleSystem *psys = sim->psys;
ParticleSettings *part = psys->part;
ParticleEditSettings *pset = &sim->scene->toolsettings->particle;
- Base *base;
int distr=0, alloc=0, skip=0;
- if ((psys->part->childtype && psys->totchild != psys_get_tot_child(sim->scene, psys)) || psys->recalc&PSYS_RECALC_RESET)
+ if ((psys->part->childtype && psys->totchild != psys_get_tot_child(sim->scene, psys, use_render_params)) || psys->recalc&PSYS_RECALC_RESET)
alloc=1;
if (alloc || psys->recalc&PSYS_RECALC_CHILD || (psys->vgroup[PSYS_VG_DENSITY] && (sim->ob && sim->ob->mode & OB_MODE_WEIGHT_PAINT)))
@@ -2918,7 +2922,7 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra, cons
if (alloc)
realloc_particles(sim, sim->psys->totpart);
- if (psys_get_tot_child(sim->scene, psys)) {
+ if (psys_get_tot_child(sim->scene, psys, use_render_params)) {
/* don't generate children while computing the hair keys */
if (!(psys->part->type == PART_HAIR) || (psys->flag & PSYS_HAIR_DONE)) {
distribute_particles(sim, PART_FROM_CHILD);
@@ -2935,23 +2939,27 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra, cons
skip = 1; /* only hair, keyed and baked stuff can have paths */
else if (part->ren_as != PART_DRAW_PATH && !(part->type==PART_HAIR && ELEM(part->ren_as, PART_DRAW_OB, PART_DRAW_GR)))
skip = 1; /* particle visualization must be set as path */
- else if (!psys->renderdata) {
+ else {
if (part->draw_as != PART_DRAW_REND)
skip = 1; /* draw visualization */
else if (psys->pointcache->flag & PTCACHE_BAKING)
skip = 1; /* no need to cache paths while baking dynamics */
- else if (psys_in_edit_mode(sim->scene, psys)) {
+
+ else if (psys_in_edit_mode(sim->depsgraph, psys)) {
if ((pset->flag & PE_DRAW_PART)==0)
skip = 1;
+#if 0 /* TODO(mai): something is very wrong with these conditionals, they dont make sense and the cache isnt updating */
else if (part->childtype==0 && (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED)==0)
skip = 1; /* in edit mode paths are needed for child particles and dynamic hair */
+#endif
}
}
/* particle instance modifier with "path" option need cached paths even if particle system doesn't */
- for (base = sim->scene->base.first; base; base= base->next) {
- ModifierData *md = modifiers_findByType(base->object, eModifierType_ParticleInstance);
+ FOREACH_SCENE_OBJECT_BEGIN(sim->scene, ob)
+ {
+ ModifierData *md = modifiers_findByType(ob, eModifierType_ParticleInstance);
if (md) {
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *)md;
if (pimd->flag & eParticleInstanceFlag_Path && pimd->ob == sim->ob && pimd->psys == (psys - (ParticleSystem*)sim->ob->particlesystem.first)) {
@@ -2960,6 +2968,7 @@ static void psys_update_path_cache(ParticleSimulationData *sim, float cfra, cons
}
}
}
+ FOREACH_SCENE_OBJECT_END;
if (!skip) {
psys_cache_paths(sim, cfra, use_render_params);
@@ -3205,7 +3214,7 @@ static void do_hair_dynamics(ParticleSimulationData *sim)
psys->hair_out_dm = CDDM_copy(psys->hair_in_dm);
psys->hair_out_dm->getVertCos(psys->hair_out_dm, deformedVerts);
- clothModifier_do(psys->clmd, sim->scene, sim->ob, psys->hair_in_dm, deformedVerts);
+ clothModifier_do(psys->clmd, sim->depsgraph, sim->scene, sim->ob, psys->hair_in_dm, deformedVerts);
CDDM_apply_vert_coords(psys->hair_out_dm, deformedVerts);
@@ -3219,7 +3228,7 @@ static void hair_step(ParticleSimulationData *sim, float cfra, const bool use_re
ParticleSystem *psys = sim->psys;
ParticleSettings *part = psys->part;
PARTICLE_P;
- float disp = psys_get_current_display_percentage(psys);
+ float disp = psys_get_current_display_percentage(psys, use_render_params);
LOOP_PARTICLES {
pa->size = part->size;
@@ -3735,13 +3744,13 @@ static void dynamics_step(ParticleSimulationData *sim, float cfra)
free_collider_cache(&sim->colliders);
BLI_rng_free(rng);
}
-static void update_children(ParticleSimulationData *sim)
+static void update_children(ParticleSimulationData *sim, const bool use_render_params)
{
if ((sim->psys->part->type == PART_HAIR) && (sim->psys->flag & PSYS_HAIR_DONE)==0)
/* don't generate children while growing hair - waste of time */
psys_free_children(sim->psys);
else if (sim->psys->part->childtype) {
- if (sim->psys->totchild != psys_get_tot_child(sim->scene, sim->psys))
+ if (sim->psys->totchild != psys_get_tot_child(sim->scene, sim->psys, use_render_params))
distribute_particles(sim, PART_FROM_CHILD);
else {
/* Children are up to date, nothing to do. */
@@ -3751,7 +3760,7 @@ static void update_children(ParticleSimulationData *sim)
psys_free_children(sim->psys);
}
/* updates cached particles' alive & other flags etc..*/
-static void cached_step(ParticleSimulationData *sim, float cfra)
+static void cached_step(ParticleSimulationData *sim, float cfra, const bool use_render_params)
{
ParticleSystem *psys = sim->psys;
ParticleSettings *part = psys->part;
@@ -3761,7 +3770,7 @@ static void cached_step(ParticleSimulationData *sim, float cfra)
psys_update_effectors(sim);
- disp= psys_get_current_display_percentage(psys);
+ disp= psys_get_current_display_percentage(psys, use_render_params);
LOOP_PARTICLES {
psys_get_texture(sim, pa, &ptex, PAMAP_SIZE, cfra);
@@ -3983,8 +3992,8 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
int cache_result = BKE_ptcache_read(pid, cache_cfra, true);
if (ELEM(cache_result, PTCACHE_READ_EXACT, PTCACHE_READ_INTERPOLATED)) {
- cached_step(sim, cfra);
- update_children(sim);
+ cached_step(sim, cfra, use_render_params);
+ update_children(sim, use_render_params);
psys_update_path_cache(sim, cfra, use_render_params);
BKE_ptcache_validate(cache, (int)cache_cfra);
@@ -4001,7 +4010,7 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
}
else if (cache_result == PTCACHE_READ_OLD) {
psys->cfra = (float)cache->simframe;
- cached_step(sim, psys->cfra);
+ cached_step(sim, psys->cfra, use_render_params);
}
/* if on second frame, write cache for first frame */
@@ -4013,7 +4022,7 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
/* 3. do dynamics */
/* set particles to be not calculated TODO: can't work with pointcache */
- disp= psys_get_current_display_percentage(psys);
+ disp= psys_get_current_display_percentage(psys, use_render_params);
LOOP_PARTICLES {
if (psys_frand(psys, p) > disp)
@@ -4069,7 +4078,7 @@ static void system_step(ParticleSimulationData *sim, float cfra, const bool use_
BKE_ptcache_write(pid, (int)cache_cfra);
}
- update_children(sim);
+ update_children(sim, use_render_params);
/* cleanup */
if (psys->lattice_deform_data) {
@@ -4205,7 +4214,7 @@ static int hair_needs_recalc(ParticleSystem *psys)
/* main particle update call, checks that things are ok on the large scale and
* then advances in to actual particle calculations depending on particle type */
-void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys, const bool use_render_params)
+void particle_system_update(struct Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys, const bool use_render_params)
{
ParticleSimulationData sim= {0};
ParticleSettings *part = psys->part;
@@ -4219,10 +4228,11 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys, cons
cfra= BKE_scene_frame_get(scene);
- sim.scene= scene;
- sim.ob= ob;
- sim.psys= psys;
- sim.psmd= psys_get_modifier(ob, psys);
+ sim.depsgraph = depsgraph;
+ sim.scene = scene;
+ sim.ob = ob;
+ sim.psys = psys;
+ sim.psmd = psys_get_modifier(ob, psys);
/* system was already updated from modifier stack */
if (sim.psmd->flag & eParticleSystemFlag_psys_updated) {
@@ -4311,7 +4321,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys, cons
case PART_PHYS_KEYED:
{
PARTICLE_P;
- float disp = psys_get_current_display_percentage(psys);
+ float disp = psys_get_current_display_percentage(psys, use_render_params);
bool free_unexisting = false;
/* Particles without dynamics haven't been reset yet because they don't use pointcache */
@@ -4365,7 +4375,7 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys, cons
/* make sure emitter is left at correct time (particle emission can change this) */
if (psys->flag & PSYS_OB_ANIM_RESTORE) {
- evaluate_emitter_anim(scene, ob, cfra);
+ evaluate_emitter_anim(depsgraph, scene, ob, cfra);
psys->flag &= ~PSYS_OB_ANIM_RESTORE;
}
@@ -4373,8 +4383,25 @@ void particle_system_update(Scene *scene, Object *ob, ParticleSystem *psys, cons
psys->recalc = 0;
/* save matrix for duplicators, at rendertime the actual dupliobject's matrix is used so don't update! */
- if (psys->renderdata==0)
- invert_m4_m4(psys->imat, ob->obmat);
+ invert_m4_m4(psys->imat, ob->obmat);
+
+ if (ob->mode & OB_MODE_PARTICLE_EDIT && ob == OBACT(DEG_get_evaluated_view_layer(depsgraph))) {
+ PTCacheEdit *edit = PE_create_current(depsgraph, scene, ob);
+
+ if (edit && edit->psys == psys) {
+ if (edit->psys && edit->psys->flag & PSYS_HAIR_UPDATED) {
+ PE_update_object(depsgraph, scene, ob, 0);
+ }
+
+ /* create path and child path cache if it doesn't exist already */
+ if (edit->pathcache == NULL) {
+ psys_cache_edit_paths(depsgraph, scene, ob, edit, DEG_get_ctime(depsgraph), DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
+
+ }
+ }
+ }
+
+ BKE_particle_batch_cache_dirty(psys, BKE_PARTICLE_BATCH_DIRTY_ALL);
}
/* ID looper */
@@ -4405,10 +4432,16 @@ void BKE_particlesystem_id_loop(ParticleSystem *psys, ParticleSystemIDFunc func,
/* **** Depsgraph evaluation **** */
-void BKE_particle_system_eval_init(EvaluationContext *UNUSED(eval_ctx),
+void BKE_particle_system_eval_init(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob)
{
- DEG_debug_print_eval(__func__, ob->id.name, ob);
+ DEG_debug_print_eval(depsgraph, __func__, ob->id.name, ob);
+ for (ParticleSystem *psys = ob->particlesystem.first;
+ psys != NULL;
+ psys = psys->next)
+ {
+ psys->recalc |= (psys->part->id.recalc & DEG_TAG_PSYS_ALL);
+ }
BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH);
}
diff --git a/source/blender/blenkernel/intern/pbvh.c b/source/blender/blenkernel/intern/pbvh.c
index 51d50b061de..7b53c5f8811 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -41,6 +41,7 @@
#include "BKE_paint.h"
#include "GPU_buffers.h"
+#include "GPU_immediate.h"
#include "bmesh.h"
@@ -1185,19 +1186,6 @@ static void pbvh_update_draw_buffers(PBVH *bvh, PBVHNode **nodes, int totnode)
}
}
-void BKE_pbvh_draw_BB(PBVH *bvh)
-{
- GPU_pbvh_BB_draw_init();
-
- for (int a = 0; a < bvh->totnode; a++) {
- PBVHNode *node = &bvh->nodes[a];
-
- GPU_pbvh_BB_draw(node->vb.bmin, node->vb.bmax, ((node->flag & PBVH_Leaf) != 0));
- }
-
- GPU_pbvh_BB_draw_end();
-}
-
static int pbvh_flush_bb(PBVH *bvh, PBVHNode *node, int flag)
{
int update = 0;
@@ -2006,42 +1994,6 @@ bool BKE_pbvh_node_find_nearest_to_ray(
return hit;
}
-typedef struct {
- DMSetMaterial setMaterial;
- bool wireframe;
- bool fast;
-} PBVHNodeDrawData;
-
-void BKE_pbvh_node_draw(PBVHNode *node, void *data_v)
-{
- PBVHNodeDrawData *data = data_v;
-
-#if 0
- /* XXX: Just some quick code to show leaf nodes in different colors */
- float col[3];
- float spec[3] = {0.0f, 0.0f, 0.0f};
-
- if (0) { //is_partial) {
- col[0] = (rand() / (float)RAND_MAX); col[1] = col[2] = 0.6;
- }
- else {
- srand((long long)node);
- for (int i = 0; i < 3; ++i)
- col[i] = (rand() / (float)RAND_MAX) * 0.3 + 0.7;
- }
-
- GPU_basic_shader_colors(col, spec, 0, 1.0f);
- glColor3f(1, 0, 0);
-#endif
-
- if (!(node->flag & PBVH_FullyHidden)) {
- GPU_pbvh_buffers_draw(node->draw_buffers,
- data->setMaterial,
- data->wireframe,
- data->fast);
- }
-}
-
typedef enum {
ISECT_INSIDE,
ISECT_OUTSIDE,
@@ -2110,6 +2062,8 @@ static void pbvh_node_check_diffuse_changed(PBVH *bvh, PBVHNode *node)
node->flag |= PBVH_UpdateDrawBuffers;
}
+/* TODO: not needed anymore in 2.8? */
+#if 0
static void pbvh_node_check_mask_changed(PBVH *bvh, PBVHNode *node)
{
if (!node->draw_buffers) {
@@ -2119,18 +2073,44 @@ static void pbvh_node_check_mask_changed(PBVH *bvh, PBVHNode *node)
node->flag |= PBVH_UpdateDrawBuffers;
}
}
+#endif
-void BKE_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*fnors)[3],
- DMSetMaterial setMaterial, bool wireframe, bool fast)
+struct PBVHNodeDrawCallbackData {
+
+ void (*draw_fn)(void *user_data, Gwn_Batch *batch);
+ void *user_data;
+ bool fast;
+};
+
+static void pbvh_node_draw_cb(PBVHNode *node, void *data_v)
{
- PBVHNodeDrawData draw_data = {setMaterial, wireframe, fast};
+ struct PBVHNodeDrawCallbackData *data = data_v;
+
+ if (!(node->flag & PBVH_FullyHidden)) {
+ Gwn_Batch *triangles = GPU_pbvh_buffers_batch_get(node->draw_buffers, data->fast);
+ if (triangles != NULL) {
+ data->draw_fn(data->user_data, triangles);
+ }
+ }
+}
+
+/**
+ * Version of #BKE_pbvh_draw that runs a callback.
+ */
+void BKE_pbvh_draw_cb(
+ PBVH *bvh, float (*planes)[4], float (*fnors)[3], bool fast,
+ void (*draw_fn)(void *user_data, Gwn_Batch *batch), void *user_data)
+{
+ struct PBVHNodeDrawCallbackData draw_data = {
+ .fast = fast,
+ .draw_fn = draw_fn,
+ .user_data = user_data,
+ };
PBVHNode **nodes;
int totnode;
- for (int a = 0; a < bvh->totnode; a++) {
+ for (int a = 0; a < bvh->totnode; a++)
pbvh_node_check_diffuse_changed(bvh, &bvh->nodes[a]);
- pbvh_node_check_mask_changed(bvh, &bvh->nodes[a]);
- }
BKE_pbvh_search_gather(bvh, update_search_cb, SET_INT_IN_POINTER(PBVH_UpdateNormals | PBVH_UpdateDrawBuffers),
&nodes, &totnode);
@@ -2141,15 +2121,19 @@ void BKE_pbvh_draw(PBVH *bvh, float (*planes)[4], float (*fnors)[3],
if (nodes) MEM_freeN(nodes);
if (planes) {
- BKE_pbvh_search_callback(bvh, BKE_pbvh_node_planes_contain_AABB,
- planes, BKE_pbvh_node_draw, &draw_data);
+ BKE_pbvh_search_callback(
+ bvh, BKE_pbvh_node_planes_contain_AABB,
+ planes, pbvh_node_draw_cb, &draw_data);
}
else {
- BKE_pbvh_search_callback(bvh, NULL, NULL, BKE_pbvh_node_draw, &draw_data);
+ BKE_pbvh_search_callback(
+ bvh, NULL,
+ NULL, pbvh_node_draw_cb, &draw_data);
}
-
+#if 0
if (G.debug_value == 14)
- BKE_pbvh_draw_BB(bvh);
+ pbvh_draw_BB(bvh);
+#endif
}
void BKE_pbvh_grids_update(PBVH *bvh, CCGElem **grids, void **gridfaces,
@@ -2361,24 +2345,24 @@ void pbvh_vertex_iter_init(PBVH *bvh, PBVHNode *node,
vi->vmask = CustomData_get_layer(bvh->vdata, CD_PAINT_MASK);
}
-void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color)
+bool pbvh_has_mask(PBVH *bvh)
{
- bool has_mask = false;
-
switch (bvh->type) {
case PBVH_GRIDS:
- has_mask = (bvh->gridkey.has_mask != 0);
- break;
+ return (bvh->gridkey.has_mask != 0);
case PBVH_FACES:
- has_mask = (bvh->vdata && CustomData_get_layer(bvh->vdata,
- CD_PAINT_MASK));
- break;
+ return (bvh->vdata && CustomData_get_layer(bvh->vdata,
+ CD_PAINT_MASK));
case PBVH_BMESH:
- has_mask = (bvh->bm && (CustomData_get_offset(&bvh->bm->vdata, CD_PAINT_MASK) != -1));
- break;
+ return (bvh->bm && (CustomData_get_offset(&bvh->bm->vdata, CD_PAINT_MASK) != -1));
}
- bvh->show_diffuse_color = !has_mask || show_diffuse_color;
+ return false;
+}
+
+void pbvh_show_diffuse_color_set(PBVH *bvh, bool show_diffuse_color)
+{
+ bvh->show_diffuse_color = !pbvh_has_mask(bvh) || show_diffuse_color;
}
void pbvh_show_mask_set(PBVH *bvh, bool show_mask)
diff --git a/source/blender/blenkernel/intern/pointcache.c b/source/blender/blenkernel/intern/pointcache.c
index 89885bdca26..3ab17b083db 100644
--- a/source/blender/blenkernel/intern/pointcache.c
+++ b/source/blender/blenkernel/intern/pointcache.c
@@ -38,6 +38,7 @@
#include "DNA_ID.h"
#include "DNA_dynamicpaint_types.h"
+#include "DNA_group_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force_types.h"
@@ -1647,6 +1648,25 @@ void BKE_ptcache_id_from_rigidbody(PTCacheID *pid, Object *ob, RigidBodyWorld *r
pid->file_type = PTCACHE_FILE_PTCACHE;
}
+PTCacheID BKE_ptcache_id_find(Object *ob, Scene *scene, PointCache *cache)
+{
+ PTCacheID result = {0};
+
+ ListBase pidlist;
+ BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
+
+ for (PTCacheID *pid = pidlist.first; pid; pid = pid->next) {
+ if (pid->cache == cache) {
+ result = *pid;
+ break;
+ }
+ }
+
+ BLI_freelistN(&pidlist);
+
+ return result;
+}
+
void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int duplis)
{
PTCacheID *pid;
@@ -1715,22 +1735,19 @@ void BKE_ptcache_ids_from_object(ListBase *lb, Object *ob, Scene *scene, int dup
BLI_addtail(lb, pid);
}
- if (scene && (duplis-- > 0) && (ob->transflag & OB_DUPLI)) {
- ListBase *lb_dupli_ob;
- /* don't update the dupli groups, we only want their pid's */
- if ((lb_dupli_ob = object_duplilist_ex(G.main->eval_ctx, scene, ob, false))) {
- DupliObject *dob;
- for (dob= lb_dupli_ob->first; dob; dob= dob->next) {
- if (dob->ob != ob) { /* avoids recursive loops with dupliframes: bug 22988 */
- ListBase lb_dupli_pid;
- BKE_ptcache_ids_from_object(&lb_dupli_pid, dob->ob, scene, duplis);
- BLI_movelisttolist(lb, &lb_dupli_pid);
- if (lb_dupli_pid.first)
- printf("Adding Dupli\n");
- }
- }
+ /* Consider all object in dupli groups to be part of the same object,
+ * for baking with linking dupligroups. Once we have better overrides
+ * this can be revisited so users select the local objects directly. */
+ if (scene && (duplis-- > 0) && (ob->dup_group)) {
+ Group *group = ob->dup_group;
+ Base *base = group->view_layer->object_bases.first;
- free_object_duplilist(lb_dupli_ob); /* does restore */
+ for (; base; base = base->next) {
+ if (base->object != ob) {
+ ListBase lb_dupli_pid;
+ BKE_ptcache_ids_from_object(&lb_dupli_pid, base->object, scene, duplis);
+ BLI_movelisttolist(lb, &lb_dupli_pid);
+ }
}
}
}
@@ -3510,13 +3527,14 @@ PointCache *BKE_ptcache_copy_list(ListBase *ptcaches_new, const ListBase *ptcach
* every user action changing stuff, and then it runs a complete bake??? (ton) */
/* Baking */
-void BKE_ptcache_quick_cache_all(Main *bmain, Scene *scene)
+void BKE_ptcache_quick_cache_all(Main *bmain, Scene *scene, ViewLayer *view_layer)
{
PTCacheBaker baker;
memset(&baker, 0, sizeof(baker));
baker.main = bmain;
baker.scene = scene;
+ baker.view_layer = view_layer;
baker.bake = 0;
baker.render = 0;
baker.anim_init = 0;
@@ -3542,6 +3560,8 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
{
Main *bmain = baker->main;
Scene *scene = baker->scene;
+ ViewLayer *view_layer = baker->view_layer;
+ struct Depsgraph *depsgraph = baker->depsgraph;
Scene *sce_iter; /* SETLOOPER macro only */
Base *base;
ListBase pidlist;
@@ -3604,7 +3624,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
}
}
else {
- for (SETLOOPER(scene, sce_iter, base)) {
+ for (SETLOOPER_VIEW_LAYER(scene, view_layer, sce_iter, base)) {
/* cache/bake everything in the scene */
BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR);
@@ -3660,7 +3680,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
stime = ptime = PIL_check_seconds_timer();
for (int fr = CFRA; fr <= endframe; fr += baker->quick_step, CFRA = fr) {
- BKE_scene_update_for_newframe(G.main->eval_ctx, bmain, scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
if (baker->update_progress) {
float progress = ((float)(CFRA - startframe)/(float)(endframe - startframe));
@@ -3715,7 +3735,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
}
}
else {
- for (SETLOOPER(scene, sce_iter, base)) {
+ for (SETLOOPER_VIEW_LAYER(scene, view_layer, sce_iter, base)) {
BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR);
for (pid=pidlist.first; pid; pid=pid->next) {
@@ -3746,7 +3766,7 @@ void BKE_ptcache_bake(PTCacheBaker *baker)
CFRA = cfrao;
if (bake) { /* already on cfra unless baking */
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
}
/* TODO: call redraw all windows somehow */
diff --git a/source/blender/blenkernel/intern/property.c b/source/blender/blenkernel/intern/property.c
deleted file mode 100644
index b163f623d21..00000000000
--- a/source/blender/blenkernel/intern/property.c
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): ton roosendaal
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenkernel/intern/property.c
- * \ingroup bke
- *
- * This module deals with bProperty only,
- * they are used on blender objects in the game engine
- * (where they get converted into C++ classes - CValue and subclasses)
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <string.h>
-#include <ctype.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_property_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_blenlib.h"
-
-#include "BKE_property.h"
-
-void BKE_bproperty_free(bProperty *prop)
-{
-
- if (prop->poin && prop->poin != &prop->data) MEM_freeN(prop->poin);
- MEM_freeN(prop);
-
-}
-
-void BKE_bproperty_free_list(ListBase *lb)
-{
- bProperty *prop;
-
- while ((prop = BLI_pophead(lb))) {
- BKE_bproperty_free(prop);
- }
-}
-
-bProperty *BKE_bproperty_copy(const bProperty *prop)
-{
- bProperty *propn;
-
- propn = MEM_dupallocN(prop);
- if (prop->poin && prop->poin != &prop->data) {
- propn->poin = MEM_dupallocN(prop->poin);
- }
- else {
- propn->poin = &propn->data;
- }
-
- return propn;
-}
-
-void BKE_bproperty_copy_list(ListBase *lbn, const ListBase *lbo)
-{
- bProperty *prop, *propn;
- BKE_bproperty_free_list(lbn); /* in case we are copying to an object with props */
- prop = lbo->first;
- while (prop) {
- propn = BKE_bproperty_copy(prop);
- BLI_addtail(lbn, propn);
- prop = prop->next;
- }
-
-
-}
-
-void BKE_bproperty_init(bProperty *prop)
-{
- /* also use when property changes type */
-
- if (prop->poin && prop->poin != &prop->data) MEM_freeN(prop->poin);
- prop->poin = NULL;
-
- prop->data = 0;
-
- switch (prop->type) {
- case GPROP_BOOL:
- case GPROP_INT:
- case GPROP_FLOAT:
- case GPROP_TIME:
- prop->poin = &prop->data;
- break;
- case GPROP_STRING:
- prop->poin = MEM_callocN(MAX_PROPSTRING, "property string");
- break;
- }
-}
-
-
-bProperty *BKE_bproperty_new(int type)
-{
- bProperty *prop;
-
- prop = MEM_callocN(sizeof(bProperty), "property");
- prop->type = type;
-
- BKE_bproperty_init(prop);
-
- strcpy(prop->name, "prop");
-
- return prop;
-}
-
-
-bProperty *BKE_bproperty_object_get(Object *ob, const char *name)
-{
- return BLI_findstring(&ob->prop, name, offsetof(bProperty, name));
-}
-
-void BKE_bproperty_object_set(Object *ob, bProperty *propc)
-{
- bProperty *prop;
- prop = BKE_bproperty_object_get(ob, propc->name);
- if (prop) {
- BLI_remlink(&ob->prop, prop);
- BKE_bproperty_free(prop);
- }
- BLI_addtail(&ob->prop, BKE_bproperty_copy(propc));
-}
-
-/* negative: prop is smaller
- * positive: prop is larger
- */
-#if 0 /* UNUSED */
-int BKE_bproperty_cmp(bProperty *prop, const char *str)
-{
-// extern int Gdfra; /* sector.c */
- float fvalue, ftest;
-
- switch (prop->type) {
- case GPROP_BOOL:
- if (BLI_strcasecmp(str, "true") == 0) {
- if (prop->data == 1) return 0;
- else return 1;
- }
- else if (BLI_strcasecmp(str, "false") == 0) {
- if (prop->data == 0) return 0;
- else return 1;
- }
- /* no break, do GPROP_int too! */
-
- case GPROP_INT:
- return prop->data - atoi(str);
-
- case GPROP_FLOAT:
- case GPROP_TIME:
- /* WARNING: untested for GPROP_TIME
- * function isn't used currently */
- fvalue = *((float *)&prop->data);
- ftest = (float)atof(str);
- if (fvalue > ftest) return 1;
- else if (fvalue < ftest) return -1;
- return 0;
-
- case GPROP_STRING:
- return strcmp(prop->poin, str);
- }
-
- return 0;
-}
-#endif
-
-void BKE_bproperty_set(bProperty *prop, const char *str)
-{
-// extern int Gdfra; /* sector.c */
-
- switch (prop->type) {
- case GPROP_BOOL:
- if (BLI_strcasecmp(str, "true") == 0) prop->data = 1;
- else if (BLI_strcasecmp(str, "false") == 0) prop->data = 0;
- else prop->data = (atoi(str) != 0);
- break;
- case GPROP_INT:
- prop->data = atoi(str);
- break;
- case GPROP_FLOAT:
- case GPROP_TIME:
- *((float *)&prop->data) = (float)atof(str);
- break;
- case GPROP_STRING:
- strcpy(prop->poin, str); /* TODO - check size? */
- break;
- }
-
-}
-
-void BKE_bproperty_add(bProperty *prop, const char *str)
-{
-// extern int Gdfra; /* sector.c */
-
- switch (prop->type) {
- case GPROP_BOOL:
- case GPROP_INT:
- prop->data += atoi(str);
- break;
- case GPROP_FLOAT:
- case GPROP_TIME:
- *((float *)&prop->data) += (float)atof(str);
- break;
- case GPROP_STRING:
- /* strcpy(prop->poin, str); */
- break;
- }
-}
-
-/* reads value of property, sets it in chars in str */
-void BKE_bproperty_set_valstr(bProperty *prop, char str[MAX_PROPSTRING])
-{
-// extern int Gdfra; /* sector.c */
-
- if (str == NULL) return;
-
- switch (prop->type) {
- case GPROP_BOOL:
- case GPROP_INT:
- sprintf(str, "%d", prop->data);
- break;
- case GPROP_FLOAT:
- case GPROP_TIME:
- sprintf(str, "%f", *((float *)&prop->data));
- break;
- case GPROP_STRING:
- BLI_strncpy(str, prop->poin, MAX_PROPSTRING);
- break;
- }
-}
-
-#if 0 /* UNUSED */
-void cp_property(bProperty *prop1, bProperty *prop2)
-{
- char str[128];
-
- BKE_bproperty_set_valstr(prop2, str);
-
- BKE_bproperty_set(prop1, str);
-}
-#endif
diff --git a/source/blender/blenkernel/intern/rigidbody.c b/source/blender/blenkernel/intern/rigidbody.c
index b8873cca0fb..1c16d57ab12 100644
--- a/source/blender/blenkernel/intern/rigidbody.c
+++ b/source/blender/blenkernel/intern/rigidbody.c
@@ -55,9 +55,9 @@
#include "DNA_scene_types.h"
#include "BKE_cdderivedmesh.h"
-#include "BKE_depsgraph.h"
#include "BKE_effect.h"
#include "BKE_global.h"
+#include "BKE_group.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_mesh.h"
@@ -93,26 +93,30 @@ void BKE_rigidbody_free_world(RigidBodyWorld *rbw)
if (rbw->physics_world) {
/* free physics references, we assume that all physics objects in will have been added to the world */
- GroupObject *go;
if (rbw->constraints) {
- for (go = rbw->constraints->gobject.first; go; go = go->next) {
- if (go->ob && go->ob->rigidbody_constraint) {
- RigidBodyCon *rbc = go->ob->rigidbody_constraint;
-
- if (rbc->physics_constraint)
+ FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, object)
+ {
+ if (object->rigidbody_constraint) {
+ RigidBodyCon *rbc = object->rigidbody_constraint;
+ if (rbc->physics_constraint) {
RB_dworld_remove_constraint(rbw->physics_world, rbc->physics_constraint);
+ }
}
}
+ FOREACH_GROUP_OBJECT_END;
}
- if (rbw->group) {
- for (go = rbw->group->gobject.first; go; go = go->next) {
- if (go->ob && go->ob->rigidbody_object) {
- RigidBodyOb *rbo = go->ob->rigidbody_object;
- if (rbo->physics_object)
+ if (rbw->group) {
+ FOREACH_GROUP_OBJECT_BEGIN(rbw->group, object)
+ {
+ if (object->rigidbody_object) {
+ RigidBodyOb *rbo = object->rigidbody_object;
+ if (rbo->physics_object) {
RB_dworld_remove_body(rbw->physics_world, rbo->physics_object);
+ }
}
}
+ FOREACH_GROUP_OBJECT_END;
}
/* free dynamics world */
RB_dworld_delete(rbw->physics_world);
@@ -1020,8 +1024,8 @@ RigidBodyOb *BKE_rigidbody_create_object(Scene *scene, Object *ob, short type)
rbo->lin_sleep_thresh = 0.4f; /* 0.4 is half of Bullet default */
rbo->ang_sleep_thresh = 0.5f; /* 0.5 is half of Bullet default */
- rbo->lin_damping = 0.04f; /* 0.04 is game engine default */
- rbo->ang_damping = 0.1f; /* 0.1 is game engine default */
+ rbo->lin_damping = 0.04f;
+ rbo->ang_damping = 0.1f;
rbo->col_groups = 1;
@@ -1133,7 +1137,6 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob)
RigidBodyWorld *rbw = scene->rigidbody_world;
RigidBodyOb *rbo = ob->rigidbody_object;
RigidBodyCon *rbc;
- GroupObject *go;
int i;
if (rbw) {
@@ -1153,8 +1156,8 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob)
/* remove object from rigid body constraints */
if (rbw->constraints) {
- for (go = rbw->constraints->gobject.first; go; go = go->next) {
- Object *obt = go->ob;
+ FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, obt)
+ {
if (obt && obt->rigidbody_constraint) {
rbc = obt->rigidbody_constraint;
if (ELEM(ob, rbc->ob1, rbc->ob2)) {
@@ -1162,6 +1165,7 @@ void BKE_rigidbody_remove_object(Scene *scene, Object *ob)
}
}
}
+ FOREACH_GROUP_OBJECT_END;
}
}
@@ -1195,20 +1199,22 @@ void BKE_rigidbody_remove_constraint(Scene *scene, Object *ob)
/* Update object array and rigid body count so they're in sync with the rigid body group */
static void rigidbody_update_ob_array(RigidBodyWorld *rbw)
{
- GroupObject *go;
int i, n;
- n = BLI_listbase_count(&rbw->group->gobject);
+ n = BLI_listbase_count(&rbw->group->view_layer->object_bases);
if (rbw->numbodies != n) {
rbw->numbodies = n;
rbw->objects = realloc(rbw->objects, sizeof(Object *) * rbw->numbodies);
}
- for (go = rbw->group->gobject.first, i = 0; go; go = go->next, i++) {
- Object *ob = go->ob;
- rbw->objects[i] = ob;
+ i = 0;
+ FOREACH_GROUP_OBJECT_BEGIN(rbw->group, object)
+ {
+ rbw->objects[i] = object;
+ i++;
}
+ FOREACH_GROUP_OBJECT_END;
}
static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw)
@@ -1231,7 +1237,7 @@ static void rigidbody_update_sim_world(Scene *scene, RigidBodyWorld *rbw)
rigidbody_update_ob_array(rbw);
}
-static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo)
+static void rigidbody_update_sim_ob(struct Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, Object *ob, RigidBodyOb *rbo)
{
float loc[3];
float rot[4];
@@ -1279,7 +1285,7 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
ListBase *effectors;
/* get effectors present in the group specified by effector_weights */
- effectors = pdInitEffectors(scene, ob, NULL, effector_weights, true);
+ effectors = pdInitEffectors(depsgraph, scene, ob, NULL, effector_weights, true);
if (effectors) {
float eff_force[3] = {0.0f, 0.0f, 0.0f};
float eff_loc[3], eff_vel[3];
@@ -1320,10 +1326,8 @@ static void rigidbody_update_sim_ob(Scene *scene, RigidBodyWorld *rbw, Object *o
*
* \param rebuild Rebuild entire simulation
*/
-static void rigidbody_update_simulation(Scene *scene, RigidBodyWorld *rbw, bool rebuild)
+static void rigidbody_update_simulation(struct Depsgraph *depsgraph, Scene *scene, RigidBodyWorld *rbw, bool rebuild)
{
- GroupObject *go;
-
/* update world */
if (rebuild)
BKE_rigidbody_validate_sim_world(scene, rbw, true);
@@ -1336,28 +1340,26 @@ static void rigidbody_update_simulation(Scene *scene, RigidBodyWorld *rbw, bool
* Memory management needs redesign here, this is just a dirty workaround.
*/
if (rebuild && rbw->constraints) {
- for (go = rbw->constraints->gobject.first; go; go = go->next) {
- Object *ob = go->ob;
- if (ob) {
- RigidBodyCon *rbc = ob->rigidbody_constraint;
- if (rbc && rbc->physics_constraint) {
- RB_dworld_remove_constraint(rbw->physics_world, rbc->physics_constraint);
- RB_constraint_delete(rbc->physics_constraint);
- rbc->physics_constraint = NULL;
- }
+ FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, ob)
+ {
+ RigidBodyCon *rbc = ob->rigidbody_constraint;
+ if (rbc && rbc->physics_constraint) {
+ RB_dworld_remove_constraint(rbw->physics_world, rbc->physics_constraint);
+ RB_constraint_delete(rbc->physics_constraint);
+ rbc->physics_constraint = NULL;
}
}
+ FOREACH_GROUP_OBJECT_END;
}
/* update objects */
- for (go = rbw->group->gobject.first; go; go = go->next) {
- Object *ob = go->ob;
-
- if (ob && ob->type == OB_MESH) {
+ FOREACH_GROUP_OBJECT_BEGIN(rbw->group, ob)
+ {
+ if (ob->type == OB_MESH) {
/* validate that we've got valid object set up here... */
RigidBodyOb *rbo = ob->rigidbody_object;
/* update transformation matrix of the object so we don't get a frame of lag for simple animations */
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(depsgraph, scene, ob);
if (rbo == NULL) {
/* Since this object is included in the sim group but doesn't have
@@ -1391,65 +1393,62 @@ static void rigidbody_update_simulation(Scene *scene, RigidBodyWorld *rbw, bool
}
/* update simulation object... */
- rigidbody_update_sim_ob(scene, rbw, ob, rbo);
+ rigidbody_update_sim_ob(depsgraph, scene, rbw, ob, rbo);
}
}
+ FOREACH_GROUP_OBJECT_END;
/* update constraints */
if (rbw->constraints == NULL) /* no constraints, move on */
return;
- for (go = rbw->constraints->gobject.first; go; go = go->next) {
- Object *ob = go->ob;
- if (ob) {
- /* validate that we've got valid object set up here... */
- RigidBodyCon *rbc = ob->rigidbody_constraint;
- /* update transformation matrix of the object so we don't get a frame of lag for simple animations */
- BKE_object_where_is_calc(scene, ob);
+ FOREACH_GROUP_OBJECT_BEGIN(rbw->constraints, ob)
+ {
+ /* validate that we've got valid object set up here... */
+ RigidBodyCon *rbc = ob->rigidbody_constraint;
+ /* update transformation matrix of the object so we don't get a frame of lag for simple animations */
+ BKE_object_where_is_calc(depsgraph, scene, ob);
- if (rbc == NULL) {
- /* Since this object is included in the group but doesn't have
- * constraint settings (perhaps it was added manually), add!
- */
- ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, RBC_TYPE_FIXED);
- rigidbody_validate_sim_constraint(rbw, ob, true);
+ if (rbc == NULL) {
+ /* Since this object is included in the group but doesn't have
+ * constraint settings (perhaps it was added manually), add!
+ */
+ ob->rigidbody_constraint = BKE_rigidbody_create_constraint(scene, ob, RBC_TYPE_FIXED);
+ rigidbody_validate_sim_constraint(rbw, ob, true);
- rbc = ob->rigidbody_constraint;
+ rbc = ob->rigidbody_constraint;
+ }
+ else {
+ /* perform simulation data updates as tagged */
+ if (rebuild) {
+ /* World has been rebuilt so rebuild constraint */
+ rigidbody_validate_sim_constraint(rbw, ob, true);
}
- else {
- /* perform simulation data updates as tagged */
- if (rebuild) {
- /* World has been rebuilt so rebuild constraint */
- rigidbody_validate_sim_constraint(rbw, ob, true);
- }
- else if (rbc->flag & RBC_FLAG_NEEDS_VALIDATE) {
- rigidbody_validate_sim_constraint(rbw, ob, false);
- }
- rbc->flag &= ~RBC_FLAG_NEEDS_VALIDATE;
+ else if (rbc->flag & RBC_FLAG_NEEDS_VALIDATE) {
+ rigidbody_validate_sim_constraint(rbw, ob, false);
}
+ rbc->flag &= ~RBC_FLAG_NEEDS_VALIDATE;
}
}
+ FOREACH_GROUP_OBJECT_END;
}
static void rigidbody_update_simulation_post_step(RigidBodyWorld *rbw)
{
- GroupObject *go;
-
- for (go = rbw->group->gobject.first; go; go = go->next) {
- Object *ob = go->ob;
-
- if (ob) {
- RigidBodyOb *rbo = ob->rigidbody_object;
- /* reset kinematic state for transformed objects */
- if (rbo && (ob->flag & SELECT) && (G.moving & G_TRANSFORM_OBJ)) {
- RB_body_set_kinematic_state(rbo->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
- RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
- /* deactivate passive objects so they don't interfere with deactivation of active objects */
- if (rbo->type == RBO_TYPE_PASSIVE)
- RB_body_deactivate(rbo->physics_object);
- }
+ FOREACH_GROUP_BASE_BEGIN(rbw->group, base)
+ {
+ Object *ob = base->object;
+ RigidBodyOb *rbo = ob->rigidbody_object;
+ /* Reset kinematic state for transformed objects. */
+ if (rbo && (base->flag & BASE_SELECTED) && (G.moving & G_TRANSFORM_OBJ)) {
+ RB_body_set_kinematic_state(rbo->physics_object, rbo->flag & RBO_FLAG_KINEMATIC || rbo->flag & RBO_FLAG_DISABLED);
+ RB_body_set_mass(rbo->physics_object, RBO_GET_MASS(rbo));
+ /* Deactivate passive objects so they don't interfere with deactivation of active objects. */
+ if (rbo->type == RBO_TYPE_PASSIVE)
+ RB_body_deactivate(rbo->physics_object);
}
}
+ FOREACH_GROUP_BASE_END
}
bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime)
@@ -1564,7 +1563,7 @@ void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw)
/* Rebuild rigid body world */
/* NOTE: this needs to be called before frame update to work correctly */
-void BKE_rigidbody_rebuild_world(Scene *scene, float ctime)
+void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime)
{
RigidBodyWorld *rbw = scene->rigidbody_world;
PointCache *cache;
@@ -1576,14 +1575,14 @@ void BKE_rigidbody_rebuild_world(Scene *scene, float ctime)
cache = rbw->pointcache;
/* flag cache as outdated if we don't have a world or number of objects in the simulation has changed */
- if (rbw->physics_world == NULL || rbw->numbodies != BLI_listbase_count(&rbw->group->gobject)) {
+ if (rbw->physics_world == NULL || rbw->numbodies != BLI_listbase_count(&rbw->group->view_layer->object_bases)) {
cache->flag |= PTCACHE_OUTDATED;
}
if (ctime == startframe + 1 && rbw->ltime == startframe) {
if (cache->flag & PTCACHE_OUTDATED) {
BKE_ptcache_id_reset(scene, &pid, PTCACHE_RESET_OUTDATED);
- rigidbody_update_simulation(scene, rbw, true);
+ rigidbody_update_simulation(depsgraph, scene, rbw, true);
BKE_ptcache_validate(cache, (int)ctime);
cache->last_exact = 0;
cache->flag &= ~PTCACHE_REDO_NEEDED;
@@ -1592,7 +1591,7 @@ void BKE_rigidbody_rebuild_world(Scene *scene, float ctime)
}
/* Run RigidBody simulation for the specified physics world */
-void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
+void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, float ctime)
{
float timestep;
RigidBodyWorld *rbw = scene->rigidbody_world;
@@ -1630,14 +1629,14 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime)
}
/* advance simulation, we can only step one frame forward */
- if (can_simulate) {
+ if (ctime == rbw->ltime + 1) {
/* write cache for first frame when on second frame */
if (rbw->ltime == startframe && (cache->flag & PTCACHE_OUTDATED || cache->last_exact == 0)) {
BKE_ptcache_write(&pid, startframe);
}
/* update and validate simulation */
- rigidbody_update_simulation(scene, rbw, false);
+ rigidbody_update_simulation(depsgraph, scene, rbw, false);
/* calculate how much time elapsed since last step in seconds */
timestep = 1.0f / (float)FPS * (ctime - rbw->ltime) * rbw->time_scale;
@@ -1681,8 +1680,8 @@ void BKE_rigidbody_sync_transforms(RigidBodyWorld *rbw, Object *ob, float ctime)
void BKE_rigidbody_aftertrans_update(Object *ob, float loc[3], float rot[3], float quat[4], float rotAxis[3], float rotAngle) {}
bool BKE_rigidbody_check_sim_running(RigidBodyWorld *rbw, float ctime) { return false; }
void BKE_rigidbody_cache_reset(RigidBodyWorld *rbw) {}
-void BKE_rigidbody_rebuild_world(Scene *scene, float ctime) {}
-void BKE_rigidbody_do_simulation(Scene *scene, float ctime) {}
+void BKE_rigidbody_rebuild_world(struct Depsgraph *depsgraph, Scene *scene, float ctime) {}
+void BKE_rigidbody_do_simulation(struct Depsgraph *depsgraph, Scene *scene, float ctime) {}
#ifdef __GNUC__
# pragma GCC diagnostic pop
@@ -1693,35 +1692,35 @@ void BKE_rigidbody_do_simulation(Scene *scene, float ctime) {}
/* -------------------- */
/* Depsgraph evaluation */
-void BKE_rigidbody_rebuild_sim(EvaluationContext *UNUSED(eval_ctx),
+void BKE_rigidbody_rebuild_sim(struct Depsgraph *depsgraph,
Scene *scene)
{
float ctime = BKE_scene_frame_get(scene);
- DEG_debug_print_eval_time(__func__, scene->id.name, scene, ctime);
+ DEG_debug_print_eval_time(depsgraph, __func__, scene->id.name, scene, ctime);
/* rebuild sim data (i.e. after resetting to start of timeline) */
if (BKE_scene_check_rigidbody_active(scene)) {
- BKE_rigidbody_rebuild_world(scene, ctime);
+ BKE_rigidbody_rebuild_world(depsgraph, scene, ctime);
}
}
-void BKE_rigidbody_eval_simulation(EvaluationContext *UNUSED(eval_ctx),
+void BKE_rigidbody_eval_simulation(struct Depsgraph *depsgraph,
Scene *scene)
{
float ctime = BKE_scene_frame_get(scene);
- DEG_debug_print_eval_time(__func__, scene->id.name, scene, ctime);
+ DEG_debug_print_eval_time(depsgraph, __func__, scene->id.name, scene, ctime);
/* evaluate rigidbody sim */
if (BKE_scene_check_rigidbody_active(scene)) {
- BKE_rigidbody_do_simulation(scene, ctime);
+ BKE_rigidbody_do_simulation(depsgraph, scene, ctime);
}
}
-void BKE_rigidbody_object_sync_transforms(EvaluationContext *UNUSED(eval_ctx),
+void BKE_rigidbody_object_sync_transforms(struct Depsgraph *depsgraph,
Scene *scene,
Object *ob)
{
RigidBodyWorld *rbw = scene->rigidbody_world;
float ctime = BKE_scene_frame_get(scene);
- DEG_debug_print_eval_time(__func__, ob->id.name, ob, ctime);
+ DEG_debug_print_eval_time(depsgraph, __func__, ob->id.name, ob, ctime);
/* read values pushed into RBO from sim/cache... */
BKE_rigidbody_sync_transforms(rbw, ob, ctime);
}
diff --git a/source/blender/blenkernel/intern/sca.c b/source/blender/blenkernel/intern/sca.c
deleted file mode 100644
index fb81ed4d47f..00000000000
--- a/source/blender/blenkernel/intern/sca.c
+++ /dev/null
@@ -1,1179 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * these all are linked to objects (listbase)
- * all data is 'direct data', not Blender lib data.
- */
-
-/** \file blender/blenkernel/intern/sca.c
- * \ingroup bke
- */
-
-
-#include <stdio.h>
-#include <string.h>
-#include <float.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_controller_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_ghash.h"
-#include "BLI_math.h"
-
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_library.h"
-#include "BKE_library_query.h"
-#include "BKE_sca.h"
-
-/* ******************* SENSORS ************************ */
-
-void free_sensor(bSensor *sens)
-{
- if (sens->links) MEM_freeN(sens->links);
- if (sens->data) MEM_freeN(sens->data);
- MEM_freeN(sens);
-
-}
-
-void free_sensors(ListBase *lb)
-{
- bSensor *sens;
-
- while ((sens = BLI_pophead(lb))) {
- free_sensor(sens);
- }
-}
-
-bSensor *copy_sensor(bSensor *sens, const int UNUSED(flag))
-{
- bSensor *sensn;
-
- sensn= MEM_dupallocN(sens);
- sensn->flag |= SENS_NEW;
- if (sens->data) {
- sensn->data= MEM_dupallocN(sens->data);
- }
-
- if (sens->links) sensn->links= MEM_dupallocN(sens->links);
-
- return sensn;
-}
-
-void copy_sensors(ListBase *lbn, const ListBase *lbo, const int flag)
-{
- bSensor *sens, *sensn;
-
- lbn->first= lbn->last= NULL;
- sens= lbo->first;
- while (sens) {
- sensn= copy_sensor(sens, flag);
- BLI_addtail(lbn, sensn);
- sens= sens->next;
- }
-}
-
-void init_sensor(bSensor *sens)
-{
- /* also use when sensor changes type */
- bNearSensor *ns;
- bMouseSensor *ms;
- bJoystickSensor *js;
- bRaySensor *rs;
-
- if (sens->data) MEM_freeN(sens->data);
- sens->data= NULL;
- sens->pulse = 0;
-
- switch (sens->type) {
- case SENS_ALWAYS:
- sens->pulse = 0;
- break;
- case SENS_NEAR:
- ns=sens->data= MEM_callocN(sizeof(bNearSensor), "nearsens");
- ns->dist= 1.0;
- ns->resetdist= 2.0;
- break;
- case SENS_KEYBOARD:
- sens->data= MEM_callocN(sizeof(bKeyboardSensor), "keysens");
- break;
- case SENS_PROPERTY:
- sens->data= MEM_callocN(sizeof(bPropertySensor), "propsens");
- break;
- case SENS_ARMATURE:
- sens->data= MEM_callocN(sizeof(bArmatureSensor), "armsens");
- break;
- case SENS_ACTUATOR:
- sens->data= MEM_callocN(sizeof(bActuatorSensor), "actsens");
- break;
- case SENS_DELAY:
- sens->data= MEM_callocN(sizeof(bDelaySensor), "delaysens");
- break;
- case SENS_MOUSE:
- ms=sens->data= MEM_callocN(sizeof(bMouseSensor), "mousesens");
- ms->type= 1; // LEFTMOUSE workaround because Mouse Sensor types enum starts in 1
- break;
- case SENS_COLLISION:
- sens->data= MEM_callocN(sizeof(bCollisionSensor), "colsens");
- break;
- case SENS_RADAR:
- sens->data= MEM_callocN(sizeof(bRadarSensor), "radarsens");
- break;
- case SENS_RANDOM:
- sens->data= MEM_callocN(sizeof(bRandomSensor), "randomsens");
- break;
- case SENS_RAY:
- sens->data= MEM_callocN(sizeof(bRaySensor), "raysens");
- rs = sens->data;
- rs->range = 0.01f;
- break;
- case SENS_MESSAGE:
- sens->data= MEM_callocN(sizeof(bMessageSensor), "messagesens");
- break;
- case SENS_JOYSTICK:
- sens->data= MEM_callocN(sizeof(bJoystickSensor), "joysticksens");
- js= sens->data;
- js->hatf = SENS_JOY_HAT_UP;
- js->axis = 1;
- js->hat = 1;
- break;
- default:
- ; /* this is very severe... I cannot make any memory for this */
- /* logic brick... */
- }
-}
-
-bSensor *new_sensor(int type)
-{
- bSensor *sens;
-
- sens= MEM_callocN(sizeof(bSensor), "Sensor");
- sens->type= type;
- sens->flag= SENS_SHOW;
-
- init_sensor(sens);
-
- strcpy(sens->name, "sensor");
-// XXX make_unique_prop_names(sens->name);
-
- return sens;
-}
-
-/* ******************* CONTROLLERS ************************ */
-
-void unlink_controller(bController *cont)
-{
- bSensor *sens;
- Object *ob;
-
- /* check for controller pointers in sensors */
- ob= G.main->object.first;
- while (ob) {
- sens= ob->sensors.first;
- while (sens) {
- unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
- sens= sens->next;
- }
- ob= ob->id.next;
- }
-}
-
-void unlink_controllers(ListBase *lb)
-{
- bController *cont;
-
- for (cont= lb->first; cont; cont= cont->next)
- unlink_controller(cont);
-}
-
-void free_controller(bController *cont)
-{
- if (cont->links) MEM_freeN(cont->links);
-
- /* the controller itself */
- if (cont->data) MEM_freeN(cont->data);
- MEM_freeN(cont);
-
-}
-
-void free_controllers(ListBase *lb)
-{
- bController *cont;
-
- while ((cont = BLI_pophead(lb))) {
- if (cont->slinks)
- MEM_freeN(cont->slinks);
- free_controller(cont);
- }
-}
-
-bController *copy_controller(bController *cont, const int UNUSED(flag))
-{
- bController *contn;
-
- cont->mynew=contn= MEM_dupallocN(cont);
- contn->flag |= CONT_NEW;
- if (cont->data) {
- contn->data= MEM_dupallocN(cont->data);
- }
-
- if (cont->links) contn->links= MEM_dupallocN(cont->links);
- contn->slinks= NULL;
- contn->totslinks= 0;
-
- return contn;
-}
-
-void copy_controllers(ListBase *lbn, const ListBase *lbo, const int flag)
-{
- bController *cont, *contn;
-
- lbn->first= lbn->last= NULL;
- cont= lbo->first;
- while (cont) {
- contn= copy_controller(cont, flag);
- BLI_addtail(lbn, contn);
- cont= cont->next;
- }
-}
-
-void init_controller(bController *cont)
-{
- /* also use when controller changes type, leave actuators... */
-
- if (cont->data) MEM_freeN(cont->data);
- cont->data= NULL;
-
- switch (cont->type) {
- case CONT_EXPRESSION:
- cont->data= MEM_callocN(sizeof(bExpressionCont), "expcont");
- break;
- case CONT_PYTHON:
- cont->data= MEM_callocN(sizeof(bPythonCont), "pycont");
- break;
- }
-}
-
-bController *new_controller(int type)
-{
- bController *cont;
-
- cont= MEM_callocN(sizeof(bController), "Controller");
- cont->type= type;
- cont->flag= CONT_SHOW;
-
- init_controller(cont);
-
- strcpy(cont->name, "cont");
-// XXX make_unique_prop_names(cont->name);
-
- return cont;
-}
-
-/* ******************* ACTUATORS ************************ */
-
-void unlink_actuator(bActuator *act)
-{
- bController *cont;
- Object *ob;
-
- /* check for actuator pointers in controllers */
- ob= G.main->object.first;
- while (ob) {
- cont= ob->controllers.first;
- while (cont) {
- unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
- cont= cont->next;
- }
- ob= ob->id.next;
- }
-}
-
-void unlink_actuators(ListBase *lb)
-{
- bActuator *act;
-
- for (act= lb->first; act; act= act->next)
- unlink_actuator(act);
-}
-
-void free_actuator(bActuator *act)
-{
- if (act->data) {
- switch (act->type) {
- case ACT_ACTION:
- case ACT_SHAPEACTION:
- {
- bActionActuator *aa = (bActionActuator *)act->data;
- if (aa->act)
- id_us_min((ID *)aa->act);
- break;
- }
- case ACT_SOUND:
- {
- bSoundActuator *sa = (bSoundActuator *) act->data;
- if (sa->sound)
- id_us_min((ID *)sa->sound);
- break;
- }
- }
-
- MEM_freeN(act->data);
- }
- MEM_freeN(act);
-}
-
-void free_actuators(ListBase *lb)
-{
- bActuator *act;
-
- while ((act = BLI_pophead(lb))) {
- free_actuator(act);
- }
-}
-
-bActuator *copy_actuator(bActuator *act, const int flag)
-{
- bActuator *actn;
-
- act->mynew=actn= MEM_dupallocN(act);
- actn->flag |= ACT_NEW;
- if (act->data) {
- actn->data= MEM_dupallocN(act->data);
- }
-
- switch (act->type) {
- case ACT_ACTION:
- case ACT_SHAPEACTION:
- {
- bActionActuator *aa = (bActionActuator *)act->data;
- if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
- id_us_plus((ID *)aa->act);
- }
- break;
- }
- case ACT_SOUND:
- {
- bSoundActuator *sa = (bSoundActuator *)act->data;
- if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
- id_us_plus((ID *)sa->sound);
- }
- break;
- }
- }
- return actn;
-}
-
-void copy_actuators(ListBase *lbn, const ListBase *lbo, const int flag)
-{
- bActuator *act, *actn;
-
- lbn->first= lbn->last= NULL;
- act= lbo->first;
- while (act) {
- actn= copy_actuator(act, flag);
- BLI_addtail(lbn, actn);
- act= act->next;
- }
-}
-
-void init_actuator(bActuator *act)
-{
- /* also use when actuator changes type */
- bCameraActuator *ca;
- bObjectActuator *oa;
- bRandomActuator *ra;
- bSoundActuator *sa;
- bSteeringActuator *sta;
- bArmatureActuator *arma;
- bMouseActuator *ma;
- bEditObjectActuator *eoa;
-
- if (act->data) MEM_freeN(act->data);
- act->data= NULL;
-
- switch (act->type) {
- case ACT_ACTION:
- case ACT_SHAPEACTION:
- act->data= MEM_callocN(sizeof(bActionActuator), "actionact");
- break;
- case ACT_SOUND:
- sa = act->data= MEM_callocN(sizeof(bSoundActuator), "soundact");
- sa->volume = 1.0f;
- sa->sound3D.rolloff_factor = 1.0f;
- sa->sound3D.reference_distance = 1.0f;
- sa->sound3D.max_gain = 1.0f;
- sa->sound3D.cone_inner_angle = DEG2RADF(360.0f);
- sa->sound3D.cone_outer_angle = DEG2RADF(360.0f);
- sa->sound3D.max_distance = FLT_MAX;
- break;
- case ACT_OBJECT:
- act->data= MEM_callocN(sizeof(bObjectActuator), "objectact");
- oa= act->data;
- oa->flag= 15;
- break;
- case ACT_PROPERTY:
- act->data= MEM_callocN(sizeof(bPropertyActuator), "propact");
- break;
- case ACT_CAMERA:
- act->data= MEM_callocN(sizeof(bCameraActuator), "camact");
- ca = act->data;
- ca->axis = OB_POSX;
- ca->damping = 1.0/32.0;
- break;
- case ACT_EDIT_OBJECT:
- act->data= MEM_callocN(sizeof(bEditObjectActuator), "editobact");
- eoa = act->data;
- eoa->upflag= ACT_TRACK_UP_Z;
- eoa->trackflag= ACT_TRACK_TRAXIS_Y;
- break;
- case ACT_CONSTRAINT:
- act->data= MEM_callocN(sizeof(bConstraintActuator), "cons act");
- break;
- case ACT_SCENE:
- act->data= MEM_callocN(sizeof(bSceneActuator), "scene act");
- break;
- case ACT_GROUP:
- act->data= MEM_callocN(sizeof(bGroupActuator), "group act");
- break;
- case ACT_RANDOM:
- act->data= MEM_callocN(sizeof(bRandomActuator), "random act");
- ra=act->data;
- ra->float_arg_1 = 0.1f;
- break;
- case ACT_MESSAGE:
- act->data= MEM_callocN(sizeof(bMessageActuator), "message act");
- break;
- case ACT_GAME:
- act->data= MEM_callocN(sizeof(bGameActuator), "game act");
- break;
- case ACT_VISIBILITY:
- act->data= MEM_callocN(sizeof(bVisibilityActuator), "visibility act");
- break;
- case ACT_2DFILTER:
- act->data = MEM_callocN(sizeof( bTwoDFilterActuator ), "2d filter act");
- break;
- case ACT_PARENT:
- act->data = MEM_callocN(sizeof( bParentActuator ), "parent act");
- break;
- case ACT_STATE:
- act->data = MEM_callocN(sizeof( bStateActuator ), "state act");
- break;
- case ACT_ARMATURE:
- act->data = MEM_callocN(sizeof( bArmatureActuator ), "armature act");
- arma = act->data;
- arma->influence = 1.f;
- break;
- case ACT_STEERING:
- act->data = MEM_callocN(sizeof( bSteeringActuator), "steering act");
- sta = act->data;
- sta->acceleration = 3.f;
- sta->turnspeed = 120.f;
- sta->dist = 1.f;
- sta->velocity= 3.f;
- sta->flag = ACT_STEERING_AUTOMATICFACING | ACT_STEERING_LOCKZVEL;
- sta->facingaxis = 1;
- break;
- case ACT_MOUSE:
- ma = act->data = MEM_callocN(sizeof( bMouseActuator ), "mouse act");
- ma->flag = ACT_MOUSE_VISIBLE|ACT_MOUSE_USE_AXIS_X|ACT_MOUSE_USE_AXIS_Y|ACT_MOUSE_RESET_X|ACT_MOUSE_RESET_Y|ACT_MOUSE_LOCAL_Y;
- ma->sensitivity[0] = ma->sensitivity[1] = 2.f;
- ma->object_axis[0] = ACT_MOUSE_OBJECT_AXIS_Z;
- ma->object_axis[1] = ACT_MOUSE_OBJECT_AXIS_X;
- ma->limit_y[0] = DEG2RADF(-90.0f);
- ma->limit_y[1] = DEG2RADF(90.0f);
- break;
- default:
- ; /* this is very severe... I cannot make any memory for this */
- /* logic brick... */
- }
-}
-
-bActuator *new_actuator(int type)
-{
- bActuator *act;
-
- act= MEM_callocN(sizeof(bActuator), "Actuator");
- act->type= type;
- act->flag= ACT_SHOW;
-
- init_actuator(act);
-
- strcpy(act->name, "act");
-// XXX make_unique_prop_names(act->name);
-
- return act;
-}
-
-/* ******************** GENERAL ******************* */
-void clear_sca_new_poins_ob(Object *ob)
-{
- bSensor *sens;
- bController *cont;
- bActuator *act;
-
- sens= ob->sensors.first;
- while (sens) {
- sens->flag &= ~SENS_NEW;
- sens= sens->next;
- }
- cont= ob->controllers.first;
- while (cont) {
- cont->mynew= NULL;
- cont->flag &= ~CONT_NEW;
- cont= cont->next;
- }
- act= ob->actuators.first;
- while (act) {
- act->mynew= NULL;
- act->flag &= ~ACT_NEW;
- act= act->next;
- }
-}
-
-void clear_sca_new_poins(void)
-{
- Object *ob;
-
- ob= G.main->object.first;
- while (ob) {
- clear_sca_new_poins_ob(ob);
- ob= ob->id.next;
- }
-}
-
-void set_sca_new_poins_ob(Object *ob)
-{
- bSensor *sens;
- bController *cont;
- bActuator *act;
- int a;
-
- sens= ob->sensors.first;
- while (sens) {
- if (sens->flag & SENS_NEW) {
- for (a=0; a<sens->totlinks; a++) {
- if (sens->links[a] && sens->links[a]->mynew)
- sens->links[a] = sens->links[a]->mynew;
- }
- }
- sens= sens->next;
- }
-
- cont= ob->controllers.first;
- while (cont) {
- if (cont->flag & CONT_NEW) {
- for (a=0; a<cont->totlinks; a++) {
- if ( cont->links[a] && cont->links[a]->mynew)
- cont->links[a] = cont->links[a]->mynew;
- }
- }
- cont= cont->next;
- }
-
-
- act= ob->actuators.first;
- while (act) {
- if (act->flag & ACT_NEW) {
- if (act->type==ACT_EDIT_OBJECT) {
- bEditObjectActuator *eoa= act->data;
- ID_NEW_REMAP(eoa->ob);
- }
- else if (act->type==ACT_SCENE) {
- bSceneActuator *sca= act->data;
- ID_NEW_REMAP(sca->camera);
- }
- else if (act->type==ACT_CAMERA) {
- bCameraActuator *ca= act->data;
- ID_NEW_REMAP(ca->ob);
- }
- else if (act->type==ACT_OBJECT) {
- bObjectActuator *oa= act->data;
- ID_NEW_REMAP(oa->reference);
- }
- else if (act->type==ACT_MESSAGE) {
- bMessageActuator *ma= act->data;
- ID_NEW_REMAP(ma->toObject);
- }
- else if (act->type==ACT_PARENT) {
- bParentActuator *para = act->data;
- ID_NEW_REMAP(para->ob);
- }
- else if (act->type==ACT_ARMATURE) {
- bArmatureActuator *aa = act->data;
- ID_NEW_REMAP(aa->target);
- ID_NEW_REMAP(aa->subtarget);
- }
- else if (act->type==ACT_PROPERTY) {
- bPropertyActuator *pa= act->data;
- ID_NEW_REMAP(pa->ob);
- }
- else if (act->type==ACT_STEERING) {
- bSteeringActuator *sta = act->data;
- ID_NEW_REMAP(sta->navmesh);
- ID_NEW_REMAP(sta->target);
- }
- }
- act= act->next;
- }
-}
-
-
-void set_sca_new_poins(void)
-{
- Object *ob;
-
- ob= G.main->object.first;
- while (ob) {
- set_sca_new_poins_ob(ob);
- ob= ob->id.next;
- }
-}
-
-/**
- * Try to remap logic links to new object... Very, *very* weak.
- */
-/* XXX Logick bricks... I don't have words to say what I think about this behavior.
- * They have silent hidden ugly inter-objects dependencies (a sensor can link into any other
- * object's controllers, and same between controllers and actuators, without *any* explicit reference
- * to data-block involved).
- * This is bad, bad, bad!!!
- * ...and forces us to add yet another very ugly hack to get remapping with logic bricks working. */
-void BKE_sca_logic_links_remap(Main *bmain, Object *ob_old, Object *ob_new)
-{
- if (ob_new == NULL || (ob_old->controllers.first == NULL && ob_old->actuators.first == NULL)) {
- /* Nothing to do here... */
- return;
- }
-
- GHash *controllers_map = ob_old->controllers.first ?
- BLI_ghash_ptr_new_ex(__func__, BLI_listbase_count(&ob_old->controllers)) : NULL;
- GHash *actuators_map = ob_old->actuators.first ?
- BLI_ghash_ptr_new_ex(__func__, BLI_listbase_count(&ob_old->actuators)) : NULL;
-
- /* We try to remap old controllers/actuators to new ones - in a very basic way. */
- for (bController *cont_old = ob_old->controllers.first, *cont_new = ob_new->controllers.first;
- cont_old;
- cont_old = cont_old->next)
- {
- bController *cont_new2 = cont_new;
-
- if (cont_old->mynew != NULL) {
- cont_new2 = cont_old->mynew;
- if (!(cont_new2 == cont_new || BLI_findindex(&ob_new->controllers, cont_new2) >= 0)) {
- cont_new2 = NULL;
- }
- }
- else if (cont_new && cont_old->type != cont_new->type) {
- cont_new2 = NULL;
- }
-
- BLI_ghash_insert(controllers_map, cont_old, cont_new2);
-
- if (cont_new) {
- cont_new = cont_new->next;
- }
- }
-
- for (bActuator *act_old = ob_old->actuators.first, *act_new = ob_new->actuators.first;
- act_old;
- act_old = act_old->next)
- {
- bActuator *act_new2 = act_new;
-
- if (act_old->mynew != NULL) {
- act_new2 = act_old->mynew;
- if (!(act_new2 == act_new || BLI_findindex(&ob_new->actuators, act_new2) >= 0)) {
- act_new2 = NULL;
- }
- }
- else if (act_new && act_old->type != act_new->type) {
- act_new2 = NULL;
- }
-
- BLI_ghash_insert(actuators_map, act_old, act_new2);
-
- if (act_new) {
- act_new = act_new->next;
- }
- }
-
- for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
- if (controllers_map != NULL) {
- for (bSensor *sens = ob->sensors.first; sens; sens = sens->next) {
- for (int a = 0; a < sens->totlinks; a++) {
- if (sens->links[a]) {
- bController *old_link = sens->links[a];
- bController **new_link_p = (bController **)BLI_ghash_lookup_p(controllers_map, old_link);
-
- if (new_link_p == NULL) {
- /* old_link is *not* in map's keys (i.e. not to any ob_old->controllers),
- * which means we ignore it totally here. */
- }
- else if (*new_link_p == NULL) {
- unlink_logicbricks((void **)&old_link, (void ***)&(sens->links), &sens->totlinks);
- a--;
- }
- else {
- sens->links[a] = *new_link_p;
- }
- }
- }
- }
- }
-
- if (actuators_map != NULL) {
- for (bController *cont = ob->controllers.first; cont; cont = cont->next) {
- for (int a = 0; a < cont->totlinks; a++) {
- if (cont->links[a]) {
- bActuator *old_link = cont->links[a];
- bActuator **new_link_p = (bActuator **)BLI_ghash_lookup_p(actuators_map, old_link);
-
- if (new_link_p == NULL) {
- /* old_link is *not* in map's keys (i.e. not to any ob_old->actuators),
- * which means we ignore it totally here. */
- }
- else if (*new_link_p == NULL) {
- unlink_logicbricks((void **)&old_link, (void ***)&(cont->links), &cont->totlinks);
- a--;
- }
- else {
- cont->links[a] = *new_link_p;
- }
- }
- }
- }
- }
- }
-
- if (controllers_map) {
- BLI_ghash_free(controllers_map, NULL, NULL);
- }
- if (actuators_map) {
- BLI_ghash_free(actuators_map, NULL, NULL);
- }
-}
-
-/**
- * Handle the copying of logic data into a new object, including internal logic links update.
- * External links (links between logic bricks of different objects) must be handled separately.
- */
-void BKE_sca_logic_copy(Object *ob_new, const Object *ob, const int flag)
-{
- copy_sensors(&ob_new->sensors, &ob->sensors, flag);
- copy_controllers(&ob_new->controllers, &ob->controllers, flag);
- copy_actuators(&ob_new->actuators, &ob->actuators, flag);
-
- for (bSensor *sens = ob_new->sensors.first; sens; sens = sens->next) {
- if (sens->flag & SENS_NEW) {
- for (int a = 0; a < sens->totlinks; a++) {
- if (sens->links[a] && sens->links[a]->mynew) {
- sens->links[a] = sens->links[a]->mynew;
- }
- }
- }
- }
-
- for (bController *cont = ob_new->controllers.first; cont; cont = cont->next) {
- if (cont->flag & CONT_NEW) {
- for (int a = 0; a < cont->totlinks; a++) {
- if (cont->links[a] && cont->links[a]->mynew) {
- cont->links[a] = cont->links[a]->mynew;
- }
- }
- }
- }
-}
-
-/* ******************** INTERFACE ******************* */
-void sca_move_sensor(bSensor *sens_to_move, Object *ob, int move_up)
-{
- bSensor *sens, *tmp;
-
- int val;
- val = move_up ? 1 : 2;
-
- /* make sure this sensor belongs to this object */
- sens= ob->sensors.first;
- while (sens) {
- if (sens == sens_to_move) break;
- sens= sens->next;
- }
- if (!sens) return;
-
- /* move up */
- if (val == 1 && sens->prev) {
- for (tmp=sens->prev; tmp; tmp=tmp->prev) {
- if (tmp->flag & SENS_VISIBLE)
- break;
- }
- if (tmp) {
- BLI_remlink(&ob->sensors, sens);
- BLI_insertlinkbefore(&ob->sensors, tmp, sens);
- }
- }
- /* move down */
- else if (val == 2 && sens->next) {
- for (tmp=sens->next; tmp; tmp=tmp->next) {
- if (tmp->flag & SENS_VISIBLE)
- break;
- }
- if (tmp) {
- BLI_remlink(&ob->sensors, sens);
- BLI_insertlinkafter(&ob->sensors, tmp, sens);
- }
- }
-}
-
-void sca_move_controller(bController *cont_to_move, Object *ob, int move_up)
-{
- bController *cont, *tmp;
-
- int val;
- val = move_up ? 1 : 2;
-
- /* make sure this controller belongs to this object */
- cont= ob->controllers.first;
- while (cont) {
- if (cont == cont_to_move) break;
- cont= cont->next;
- }
- if (!cont) return;
-
- /* move up */
- if (val == 1 && cont->prev) {
- /* locate the controller that has the same state mask but is earlier in the list */
- tmp = cont->prev;
- while (tmp) {
- if (tmp->state_mask & cont->state_mask)
- break;
- tmp = tmp->prev;
- }
- if (tmp) {
- BLI_remlink(&ob->controllers, cont);
- BLI_insertlinkbefore(&ob->controllers, tmp, cont);
- }
- }
-
- /* move down */
- else if (val == 2 && cont->next) {
- tmp = cont->next;
- while (tmp) {
- if (tmp->state_mask & cont->state_mask)
- break;
- tmp = tmp->next;
- }
- BLI_remlink(&ob->controllers, cont);
- BLI_insertlinkafter(&ob->controllers, tmp, cont);
- }
-}
-
-void sca_move_actuator(bActuator *act_to_move, Object *ob, int move_up)
-{
- bActuator *act, *tmp;
- int val;
-
- val = move_up ? 1 : 2;
-
- /* make sure this actuator belongs to this object */
- act= ob->actuators.first;
- while (act) {
- if (act == act_to_move) break;
- act= act->next;
- }
- if (!act) return;
-
- /* move up */
- if (val == 1 && act->prev) {
- /* locate the first visible actuators before this one */
- for (tmp = act->prev; tmp; tmp=tmp->prev) {
- if (tmp->flag & ACT_VISIBLE)
- break;
- }
- if (tmp) {
- BLI_remlink(&ob->actuators, act);
- BLI_insertlinkbefore(&ob->actuators, tmp, act);
- }
- }
- /* move down */
- else if (val == 2 && act->next) {
- /* locate the first visible actuators after this one */
- for (tmp=act->next; tmp; tmp=tmp->next) {
- if (tmp->flag & ACT_VISIBLE)
- break;
- }
- if (tmp) {
- BLI_remlink(&ob->actuators, act);
- BLI_insertlinkafter(&ob->actuators, tmp, act);
- }
- }
-}
-
-void link_logicbricks(void **poin, void ***ppoin, short *tot, short size)
-{
- void **old_links= NULL;
-
- int ibrick;
-
- /* check if the bricks are already linked */
- for (ibrick=0; ibrick < *tot; ibrick++) {
- if ((*ppoin)[ibrick] == *poin)
- return;
- }
-
- if (*ppoin) {
- old_links= *ppoin;
-
- (*tot) ++;
- *ppoin = MEM_callocN((*tot)*size, "new link");
-
- for (ibrick=0; ibrick < *(tot) - 1; ibrick++) {
- (*ppoin)[ibrick] = old_links[ibrick];
- }
- (*ppoin)[ibrick] = *poin;
-
- if (old_links) MEM_freeN(old_links);
- }
- else {
- (*tot) = 1;
- *ppoin = MEM_callocN((*tot)*size, "new link");
- (*ppoin)[0] = *poin;
- }
-}
-
-void unlink_logicbricks(void **poin, void ***ppoin, short *tot)
-{
- int ibrick, removed;
-
- removed= 0;
- for (ibrick=0; ibrick < *tot; ibrick++) {
- if (removed) (*ppoin)[ibrick - removed] = (*ppoin)[ibrick];
- else if ((*ppoin)[ibrick] == *poin) removed = 1;
- }
-
- if (removed) {
- (*tot) --;
-
- if (*tot == 0) {
- MEM_freeN(*ppoin);
- (*ppoin)= NULL;
- }
- return;
- }
-}
-
-void BKE_sca_sensors_id_loop(ListBase *senslist, SCASensorIDFunc func, void *userdata)
-{
- bSensor *sensor;
-
- for (sensor = senslist->first; sensor; sensor = sensor->next) {
- func(sensor, (ID **)&sensor->ob, userdata, IDWALK_CB_NOP);
-
- switch (sensor->type) {
- case SENS_TOUCH: /* DEPRECATED */
- {
- bTouchSensor *ts = sensor->data;
- func(sensor, (ID **)&ts->ma, userdata, IDWALK_CB_NOP);
- break;
- }
- case SENS_MESSAGE:
- {
- bMessageSensor *ms = sensor->data;
- func(sensor, (ID **)&ms->fromObject, userdata, IDWALK_CB_NOP);
- break;
- }
- case SENS_ALWAYS:
- case SENS_NEAR:
- case SENS_KEYBOARD:
- case SENS_PROPERTY:
- case SENS_MOUSE:
- case SENS_COLLISION:
- case SENS_RADAR:
- case SENS_RANDOM:
- case SENS_RAY:
- case SENS_JOYSTICK:
- case SENS_ACTUATOR:
- case SENS_DELAY:
- case SENS_ARMATURE:
- default:
- break;
- }
- }
-}
-
-void BKE_sca_controllers_id_loop(ListBase *contlist, SCAControllerIDFunc func, void *userdata)
-{
- bController *controller;
-
- for (controller = contlist->first; controller; controller = controller->next) {
- switch (controller->type) {
- case CONT_PYTHON:
- {
- bPythonCont *pc = controller->data;
- func(controller, (ID **)&pc->text, userdata, IDWALK_CB_NOP);
- break;
- }
- case CONT_LOGIC_AND:
- case CONT_LOGIC_OR:
- case CONT_EXPRESSION:
- case CONT_LOGIC_NAND:
- case CONT_LOGIC_NOR:
- case CONT_LOGIC_XOR:
- case CONT_LOGIC_XNOR:
- default:
- break;
- }
- }
-}
-
-void BKE_sca_actuators_id_loop(ListBase *actlist, SCAActuatorIDFunc func, void *userdata)
-{
- bActuator *actuator;
-
- for (actuator = actlist->first; actuator; actuator = actuator->next) {
- func(actuator, (ID **)&actuator->ob, userdata, IDWALK_CB_NOP);
-
- switch (actuator->type) {
- case ACT_ADD_OBJECT: /* DEPRECATED */
- {
- bAddObjectActuator *aoa = actuator->data;
- func(actuator, (ID **)&aoa->ob, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_ACTION:
- {
- bActionActuator *aa = actuator->data;
- func(actuator, (ID **)&aa->act, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_SOUND:
- {
- bSoundActuator *sa = actuator->data;
- func(actuator, (ID **)&sa->sound, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_EDIT_OBJECT:
- {
- bEditObjectActuator *eoa = actuator->data;
- func(actuator, (ID **)&eoa->ob, userdata, IDWALK_CB_NOP);
- func(actuator, (ID **)&eoa->me, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_SCENE:
- {
- bSceneActuator *sa = actuator->data;
- func(actuator, (ID **)&sa->scene, userdata, IDWALK_CB_NOP);
- func(actuator, (ID **)&sa->camera, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_PROPERTY:
- {
- bPropertyActuator *pa = actuator->data;
- func(actuator, (ID **)&pa->ob, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_OBJECT:
- {
- bObjectActuator *oa = actuator->data;
- func(actuator, (ID **)&oa->reference, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_CAMERA:
- {
- bCameraActuator *ca = actuator->data;
- func(actuator, (ID **)&ca->ob, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_MESSAGE:
- {
- bMessageActuator *ma = actuator->data;
- func(actuator, (ID **)&ma->toObject, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_2DFILTER:
- {
- bTwoDFilterActuator *tdfa = actuator->data;
- func(actuator, (ID **)&tdfa->text, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_PARENT:
- {
- bParentActuator *pa = actuator->data;
- func(actuator, (ID **)&pa->ob, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_ARMATURE:
- {
- bArmatureActuator *aa = actuator->data;
- func(actuator, (ID **)&aa->target, userdata, IDWALK_CB_NOP);
- func(actuator, (ID **)&aa->subtarget, userdata, IDWALK_CB_NOP);
- break;
- }
- case ACT_STEERING:
- {
- bSteeringActuator *sa = actuator->data;
- func(actuator, (ID **)&sa->target, userdata, IDWALK_CB_NOP);
- func(actuator, (ID **)&sa->navmesh, userdata, IDWALK_CB_NOP);
- break;
- }
- /* Note: some types seems to be non-implemented? ACT_LAMP, ACT_MATERIAL... */
- case ACT_LAMP:
- case ACT_MATERIAL:
- case ACT_END_OBJECT: /* DEPRECATED */
- case ACT_CONSTRAINT:
- case ACT_GROUP:
- case ACT_RANDOM:
- case ACT_GAME:
- case ACT_VISIBILITY:
- case ACT_SHAPEACTION:
- case ACT_STATE:
- case ACT_MOUSE:
- default:
- break;
- }
- }
-}
-
-const char *sca_state_name_get(Object *ob, short bit)
-{
- bController *cont;
- unsigned int mask;
-
- mask = (1<<bit);
- cont = ob->controllers.first;
- while (cont) {
- if (cont->state_mask & mask) {
- return cont->name;
- }
- cont = cont->next;
- }
- return NULL;
-}
-
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index 9b3299bdbc5..1c8d153d0d1 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -49,6 +49,7 @@
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_gpencil_types.h"
#include "BLI_math.h"
@@ -67,8 +68,8 @@
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_cachefile.h"
+#include "BKE_collection.h"
#include "BKE_colortools.h"
-#include "BKE_depsgraph.h"
#include "BKE_editmesh.h"
#include "BKE_fcurve.h"
#include "BKE_freestyle.h"
@@ -78,6 +79,7 @@
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
#include "BKE_linestyle.h"
@@ -92,9 +94,13 @@
#include "BKE_sequencer.h"
#include "BKE_sound.h"
#include "BKE_unit.h"
+#include "BKE_workspace.h"
#include "BKE_world.h"
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_debug.h"
+#include "DEG_depsgraph_query.h"
#include "RE_engine.h"
@@ -105,8 +111,9 @@
#include "bmesh.h"
-const char *RE_engine_id_BLENDER_RENDER = "BLENDER_RENDER";
-const char *RE_engine_id_BLENDER_GAME = "BLENDER_GAME";
+const char *RE_engine_id_BLENDER_CLAY = "BLENDER_CLAY";
+const char *RE_engine_id_BLENDER_EEVEE = "BLENDER_EEVEE";
+const char *RE_engine_id_BLENDER_WORKBENCH = "BLENDER_WORKBENCH";
const char *RE_engine_id_CYCLES = "CYCLES";
void free_avicodecdata(AviCodecData *acd)
@@ -234,25 +241,37 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
sce_dst->ed = NULL;
- sce_dst->theDag = NULL;
- sce_dst->depsgraph = NULL;
- sce_dst->obedit = NULL;
- sce_dst->stats = NULL;
+ sce_dst->depsgraph_hash = NULL;
sce_dst->fps_info = NULL;
- BLI_duplicatelist(&(sce_dst->base), &(sce_src->base));
- for (Base *base_dst = sce_dst->base.first, *base_src = sce_src->base.first;
- base_dst;
- base_dst = base_dst->next, base_src = base_src->next)
+ /* layers and collections */
+ sce_dst->collection = MEM_dupallocN(sce_src->collection);
+ SceneCollection *mc_src = BKE_collection_master(&sce_src->id);
+ SceneCollection *mc_dst = BKE_collection_master(&sce_dst->id);
+
+ /* Recursively creates a new SceneCollection tree. */
+ BKE_collection_copy_data(mc_dst, mc_src, flag_subdata);
+
+ IDPropertyTemplate val = {0};
+ BLI_duplicatelist(&sce_dst->view_layers, &sce_src->view_layers);
+ for (ViewLayer *view_layer_src = sce_src->view_layers.first, *view_layer_dst = sce_dst->view_layers.first;
+ view_layer_src;
+ view_layer_src = view_layer_src->next, view_layer_dst = view_layer_dst->next)
{
- if (base_src == sce_src->basact) {
- sce_dst->basact = base_dst;
- }
+ BKE_view_layer_copy_data(view_layer_dst, view_layer_src, mc_dst, mc_src, flag_subdata);
+ }
+
+ sce_dst->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ if (sce_src->collection_properties) {
+ IDP_MergeGroup_ex(sce_dst->collection_properties, sce_src->collection_properties, true, flag_subdata);
+ }
+ sce_dst->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ if (sce_src->layer_properties) {
+ IDP_MergeGroup_ex(sce_dst->layer_properties, sce_src->layer_properties, true, flag_subdata);
}
BLI_duplicatelist(&(sce_dst->markers), &(sce_src->markers));
BLI_duplicatelist(&(sce_dst->transform_spaces), &(sce_src->transform_spaces));
- BLI_duplicatelist(&(sce_dst->r.layers), &(sce_src->r.layers));
BLI_duplicatelist(&(sce_dst->r.views), &(sce_src->r.views));
BKE_keyingsets_copy(&(sce_dst->keyingsets), &(sce_src->keyingsets));
@@ -267,17 +286,6 @@ void BKE_scene_copy_data(Main *bmain, Scene *sce_dst, const Scene *sce_src, cons
sce_dst->rigidbody_world = BKE_rigidbody_world_copy(sce_src->rigidbody_world, flag_subdata);
}
- /* copy Freestyle settings */
- for (SceneRenderLayer *srl_dst = sce_dst->r.layers.first, *srl_src = sce_src->r.layers.first;
- srl_src;
- srl_dst = srl_dst->next, srl_src = srl_src->next)
- {
- if (srl_dst->prop != NULL) {
- srl_dst->prop = IDP_CopyProperty_ex(srl_dst->prop, flag_subdata);
- }
- BKE_freestyle_config_copy(&srl_dst->freestyleConfig, &srl_src->freestyleConfig, flag_subdata);
- }
-
/* copy color management settings */
BKE_color_managed_display_settings_copy(&sce_dst->display_settings, &sce_src->display_settings);
BKE_color_managed_view_settings_copy(&sce_dst->view_settings, &sce_src->view_settings);
@@ -331,20 +339,16 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
/* TODO this should/could most likely be replaced by call to more generic code at some point...
* But for now, let's keep it well isolated here. */
if (type == SCE_COPY_EMPTY) {
- ListBase rl, rv;
+ ListBase rv;
sce_copy = BKE_scene_add(bmain, sce->id.name + 2);
- rl = sce_copy->r.layers;
rv = sce_copy->r.views;
curvemapping_free_data(&sce_copy->r.mblur_shutter_curve);
sce_copy->r = sce->r;
- sce_copy->r.layers = rl;
- sce_copy->r.actlay = 0;
sce_copy->r.views = rv;
sce_copy->unit = sce->unit;
sce_copy->physics_settings = sce->physics_settings;
- sce_copy->gm = sce->gm;
sce_copy->audio = sce->audio;
if (sce->id.properties)
@@ -399,8 +403,8 @@ Scene *BKE_scene_copy(Main *bmain, Scene *sce, int type)
if (type == SCE_COPY_FULL) {
/* Copy Freestyle LineStyle datablocks. */
- for (SceneRenderLayer *srl_dst = sce_copy->r.layers.first; srl_dst; srl_dst = srl_dst->next) {
- for (FreestyleLineSet *lineset = srl_dst->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
+ for (ViewLayer *view_layer_dst = sce_copy->view_layers.first; view_layer_dst; view_layer_dst = view_layer_dst->next) {
+ for (FreestyleLineSet *lineset = view_layer_dst->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
if (lineset->linestyle) {
/* XXX Not copying anim/actions here? */
BKE_id_copy_ex(bmain, (ID *)lineset->linestyle, (ID **)&lineset->linestyle, 0, false);
@@ -452,17 +456,13 @@ void BKE_scene_make_local(Main *bmain, Scene *sce, const bool lib_local)
}
/** Free (or release) any data used by this scene (does not free the scene itself). */
-void BKE_scene_free(Scene *sce)
+void BKE_scene_free_ex(Scene *sce, const bool do_id_user)
{
- SceneRenderLayer *srl;
-
BKE_animdata_free((ID *)sce, false);
/* check all sequences */
BKE_sequencer_clear_scene_in_allseqs(G.main, sce);
- sce->basact = NULL;
- BLI_freelistN(&sce->base);
BKE_sequencer_editing_free(sce);
BKE_keyingsets_free(&sce->keyingsets);
@@ -490,27 +490,15 @@ void BKE_scene_free(Scene *sce)
sce->r.ffcodecdata.properties = NULL;
}
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
- if (srl->prop != NULL) {
- IDP_FreeProperty(srl->prop);
- MEM_freeN(srl->prop);
- }
- BKE_freestyle_config_free(&srl->freestyleConfig);
- }
-
BLI_freelistN(&sce->markers);
BLI_freelistN(&sce->transform_spaces);
- BLI_freelistN(&sce->r.layers);
BLI_freelistN(&sce->r.views);
BKE_toolsettings_free(sce->toolsettings);
sce->toolsettings = NULL;
- DAG_scene_free(sce);
- if (sce->depsgraph)
- DEG_graph_free(sce->depsgraph);
-
- MEM_SAFE_FREE(sce->stats);
+ BKE_scene_free_depsgraph_hash(sce);
+
MEM_SAFE_FREE(sce->fps_info);
BKE_sound_destroy_scene(sce);
@@ -519,6 +507,37 @@ void BKE_scene_free(Scene *sce)
BKE_previewimg_free(&sce->preview);
curvemapping_free_data(&sce->r.mblur_shutter_curve);
+
+ for (ViewLayer *view_layer = sce->view_layers.first, *view_layer_next; view_layer; view_layer = view_layer_next) {
+ view_layer_next = view_layer->next;
+
+ BLI_remlink(&sce->view_layers, view_layer);
+ BKE_view_layer_free_ex(view_layer, do_id_user);
+ }
+
+ /* Master Collection */
+ BKE_collection_master_free(&sce->id, do_id_user);
+ MEM_freeN(sce->collection);
+ sce->collection = NULL;
+
+ /* LayerCollection engine settings. */
+ if (sce->collection_properties) {
+ IDP_FreeProperty(sce->collection_properties);
+ MEM_freeN(sce->collection_properties);
+ sce->collection_properties = NULL;
+ }
+
+ /* Render engine setting. */
+ if (sce->layer_properties) {
+ IDP_FreeProperty(sce->layer_properties);
+ MEM_freeN(sce->layer_properties);
+ sce->layer_properties = NULL;
+ }
+}
+
+void BKE_scene_free(Scene *sce)
+{
+ BKE_scene_free_ex(sce, true);
}
void BKE_scene_init(Scene *sce)
@@ -533,7 +552,7 @@ void BKE_scene_init(Scene *sce)
sce->lay = sce->layact = 1;
- sce->r.mode = R_GAMMA | R_OSA | R_SHADOW | R_SSS | R_ENVMAP | R_RAYTRACE;
+ sce->r.mode = R_OSA;
sce->r.cfra = 1;
sce->r.sfra = 1;
sce->r.efra = 250;
@@ -544,8 +563,6 @@ void BKE_scene_init(Scene *sce)
sce->r.yasp = 1;
sce->r.tilex = 256;
sce->r.tiley = 256;
- sce->r.mblur_samples = 1;
- sce->r.filtertype = R_FILTER_MITCH;
sce->r.size = 50;
sce->r.im_format.planes = R_IMF_PLANES_RGBA;
@@ -561,8 +578,6 @@ void BKE_scene_init(Scene *sce)
sce->r.blurfac = 0.5;
sce->r.frs_sec = 24;
sce->r.frs_sec_base = 1;
- sce->r.edgeint = 10;
- sce->r.ocres = 128;
/* OCIO_TODO: for forwards compatibility only, so if no tonecurve are used,
* images would look in the same way as in current blender
@@ -571,18 +586,9 @@ void BKE_scene_init(Scene *sce)
*/
sce->r.color_mgt_flag |= R_COLOR_MANAGEMENT;
- sce->r.gauss = 1.0;
-
- /* deprecated but keep for upwards compat */
- sce->r.postgamma = 1.0;
- sce->r.posthue = 0.0;
- sce->r.postsat = 1.0;
-
- sce->r.bake_mode = 1; /* prevent to include render stuff here */
+ sce->r.bake_mode = 0;
sce->r.bake_filter = 16;
- sce->r.bake_osa = 5;
sce->r.bake_flag = R_BAKE_CLEAR;
- sce->r.bake_normal_space = R_BAKE_SPACE_TANGENT;
sce->r.bake_samples = 256;
sce->r.bake_biasdist = 0.001;
@@ -610,7 +616,6 @@ void BKE_scene_init(Scene *sce)
sce->r.fg_stamp[3] = 1.0f;
sce->r.bg_stamp[0] = sce->r.bg_stamp[1] = sce->r.bg_stamp[2] = 0.0f;
sce->r.bg_stamp[3] = 0.25f;
- sce->r.raytrace_options = R_RAYTRACE_USE_INSTANCES;
sce->r.seq_prev_type = OB_SOLID;
sce->r.seq_rend_type = OB_SOLID;
@@ -620,8 +625,6 @@ void BKE_scene_init(Scene *sce)
sce->r.simplify_subsurf = 6;
sce->r.simplify_particles = 1.0f;
- sce->r.simplify_shadowsamples = 16;
- sce->r.simplify_aosss = 1.0f;
sce->r.border.xmin = 0.0f;
sce->r.border.ymin = 0.0f;
@@ -650,26 +653,10 @@ void BKE_scene_init(Scene *sce)
sce->toolsettings->selectmode = SCE_SELECT_VERTEX;
sce->toolsettings->uv_selectmode = UV_SELECT_VERTEX;
- sce->toolsettings->normalsize = 0.1;
sce->toolsettings->autokey_mode = U.autokey_mode;
sce->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID;
- sce->toolsettings->skgen_resolution = 100;
- sce->toolsettings->skgen_threshold_internal = 0.01f;
- sce->toolsettings->skgen_threshold_external = 0.01f;
- sce->toolsettings->skgen_angle_limit = 45.0f;
- sce->toolsettings->skgen_length_ratio = 1.3f;
- sce->toolsettings->skgen_length_limit = 1.5f;
- sce->toolsettings->skgen_correlation_limit = 0.98f;
- sce->toolsettings->skgen_symmetry_limit = 0.1f;
- sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
- sce->toolsettings->skgen_postpro_passes = 1;
- sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL | SKGEN_FILTER_EXTERNAL | SKGEN_FILTER_SMART | SKGEN_HARMONIC | SKGEN_SUB_CORRELATION | SKGEN_STICK_TO_EMBEDDING;
- sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
- sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
- sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
-
sce->toolsettings->curve_paint_settings.curve_type = CU_BEZIER;
sce->toolsettings->curve_paint_settings.flag |= CURVE_PAINT_FLAG_CORNERS_DETECT;
sce->toolsettings->curve_paint_settings.error_threshold = 8;
@@ -723,12 +710,13 @@ void BKE_scene_init(Scene *sce)
sce->r.ffcodecdata.audio_bitrate = 192;
sce->r.ffcodecdata.audio_channels = 2;
- BLI_strncpy(sce->r.engine, RE_engine_id_BLENDER_RENDER, sizeof(sce->r.engine));
+ BLI_strncpy(sce->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(sce->r.engine));
sce->audio.distance_model = 2.0f;
sce->audio.doppler_factor = 1.0f;
sce->audio.speed_of_sound = 343.3f;
sce->audio.volume = 1.0f;
+ sce->audio.flag = AUDIO_SYNC;
BLI_strncpy(sce->r.pic, U.renderdir, sizeof(sce->r.pic));
@@ -736,7 +724,6 @@ void BKE_scene_init(Scene *sce)
sce->r.osa = 8;
/* note; in header_info.c the scene copy happens..., if you add more to renderdata it has to be checked there */
- BKE_scene_add_render_layer(sce, NULL);
/* multiview - stereo */
BKE_scene_add_render_view(sce, STEREO_LEFT_NAME);
@@ -747,59 +734,6 @@ void BKE_scene_init(Scene *sce)
srv = sce->r.views.last;
BLI_strncpy(srv->suffix, STEREO_RIGHT_SUFFIX, sizeof(srv->suffix));
- /* game data */
- sce->gm.stereoflag = STEREO_NOSTEREO;
- sce->gm.stereomode = STEREO_ANAGLYPH;
- sce->gm.eyeseparation = 0.10;
-
- sce->gm.dome.angle = 180;
- sce->gm.dome.mode = DOME_FISHEYE;
- sce->gm.dome.res = 4;
- sce->gm.dome.resbuf = 1.0f;
- sce->gm.dome.tilt = 0;
-
- sce->gm.xplay = 640;
- sce->gm.yplay = 480;
- sce->gm.freqplay = 60;
- sce->gm.depth = 32;
-
- sce->gm.gravity = 9.8f;
- sce->gm.physicsEngine = WOPHY_BULLET;
- sce->gm.mode = 32; //XXX ugly harcoding, still not sure we should drop mode. 32 == 1 << 5 == use_occlusion_culling
- sce->gm.occlusionRes = 128;
- sce->gm.ticrate = 60;
- sce->gm.maxlogicstep = 5;
- sce->gm.physubstep = 1;
- sce->gm.maxphystep = 5;
- sce->gm.lineardeactthreshold = 0.8f;
- sce->gm.angulardeactthreshold = 1.0f;
- sce->gm.deactivationtime = 0.0f;
-
- sce->gm.flag = GAME_DISPLAY_LISTS;
- sce->gm.matmode = GAME_MAT_MULTITEX;
-
- sce->gm.obstacleSimulation = OBSTSIMULATION_NONE;
- sce->gm.levelHeight = 2.f;
-
- sce->gm.recastData.cellsize = 0.3f;
- sce->gm.recastData.cellheight = 0.2f;
- sce->gm.recastData.agentmaxslope = M_PI_4;
- sce->gm.recastData.agentmaxclimb = 0.9f;
- sce->gm.recastData.agentheight = 2.0f;
- sce->gm.recastData.agentradius = 0.6f;
- sce->gm.recastData.edgemaxlen = 12.0f;
- sce->gm.recastData.edgemaxerror = 1.3f;
- sce->gm.recastData.regionminsize = 8.f;
- sce->gm.recastData.regionmergesize = 20.f;
- sce->gm.recastData.vertsperpoly = 6;
- sce->gm.recastData.detailsampledist = 6.0f;
- sce->gm.recastData.detailsamplemaxerror = 1.0f;
-
- sce->gm.lodflag = SCE_LOD_USE_HYST;
- sce->gm.scehysteresis = 10;
-
- sce->gm.exitkey = 218; // Blender key code for ESC
-
BKE_sound_create_scene(sce);
/* color management */
@@ -869,6 +803,22 @@ void BKE_scene_init(Scene *sce)
sce->toolsettings->gpencil_v2d_align = GP_PROJECT_VIEWSPACE;
sce->toolsettings->gpencil_seq_align = GP_PROJECT_VIEWSPACE;
sce->toolsettings->gpencil_ima_align = GP_PROJECT_VIEWSPACE;
+
+ sce->orientation_index_custom = -1;
+
+ /* Master Collection */
+ sce->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection");
+ BLI_strncpy(sce->collection->name, "Master Collection", sizeof(sce->collection->name));
+
+ /* Engine settings */
+ IDPropertyTemplate val = {0};
+ sce->collection_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ BKE_layer_collection_engine_settings_create(sce->collection_properties);
+
+ sce->layer_properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ BKE_view_layer_engine_settings_create(sce->layer_properties);
+
+ BKE_view_layer_add(sce, "View Layer");
}
Scene *BKE_scene_add(Main *bmain, const char *name)
@@ -884,75 +834,64 @@ Scene *BKE_scene_add(Main *bmain, const char *name)
return sce;
}
-Base *BKE_scene_base_find_by_name(struct Scene *scene, const char *name)
+/**
+ * Check if there is any intance of the object in the scene
+ */
+bool BKE_scene_object_find(Scene *scene, Object *ob)
{
- Base *base;
-
- for (base = scene->base.first; base; base = base->next) {
- if (STREQ(base->object->id.name + 2, name)) {
- break;
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ if (BLI_findptr(&view_layer->object_bases, ob, offsetof(Base, object))) {
+ return true;
}
}
-
- return base;
+ return false;
}
-Base *BKE_scene_base_find(Scene *scene, Object *ob)
+Object *BKE_scene_object_find_by_name(Scene *scene, const char *name)
{
- return BLI_findptr(&scene->base, ob, offsetof(Base, object));
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (STREQ(base->object->id.name + 2, name)) {
+ return base->object;
+ }
+ }
+ }
+ return NULL;
}
/**
* Sets the active scene, mainly used when running in background mode (``--scene`` command line argument).
* This is also called to set the scene directly, bypassing windowing code.
- * Otherwise #ED_screen_set_scene is used when changing scenes by the user.
+ * Otherwise #WM_window_change_active_scene is used when changing scenes by the user.
*/
void BKE_scene_set_background(Main *bmain, Scene *scene)
{
- Scene *sce;
- Base *base;
Object *ob;
Group *group;
- GroupObject *go;
- int flag;
/* check for cyclic sets, for reading old files but also for definite security (py?) */
BKE_scene_validate_setscene(bmain, scene);
- /* can happen when switching modes in other scenes */
- if (scene->obedit && !(scene->obedit->mode & OB_MODE_EDIT))
- scene->obedit = NULL;
-
/* deselect objects (for dataselect) */
for (ob = bmain->object.first; ob; ob = ob->id.next)
ob->flag &= ~(SELECT | OB_FROMGROUP);
/* group flags again */
for (group = bmain->group.first; group; group = group->id.next) {
- for (go = group->gobject.first; go; go = go->next) {
- if (go->ob) {
- go->ob->flag |= OB_FROMGROUP;
- }
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ object->flag |= OB_FROMGROUP;
}
+ FOREACH_GROUP_OBJECT_END;
}
- /* sort baselist for scene and sets */
- for (sce = scene; sce; sce = sce->set)
- DAG_scene_relations_rebuild(bmain, sce);
-
/* copy layers and flags from bases to objects */
- for (base = scene->base.first; base; base = base->next) {
- ob = base->object;
- ob->lay = base->lay;
-
- /* group patch... */
- base->flag &= ~(OB_FROMGROUP);
- flag = ob->flag & (OB_FROMGROUP);
- base->flag |= flag;
-
- /* not too nice... for recovering objects with lost data */
- //if (ob->pose == NULL) base->flag &= ~OB_POSEMODE;
- ob->flag = base->flag;
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ ob = base->object;
+ /* group patch... */
+ BKE_scene_object_base_flag_sync_from_base(base);
+ }
}
/* no full animation update, this to enable render code to work (render code calls own animation updates) */
}
@@ -972,8 +911,9 @@ Scene *BKE_scene_set_name(Main *bmain, const char *name)
}
/* Used by metaballs, return *all* objects (including duplis) existing in the scene (including scene's sets) */
-int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
- Scene **scene, int val, Base **base, Object **ob)
+int BKE_scene_base_iter_next(
+ Depsgraph *depsgraph, SceneBaseIter *iter,
+ Scene **scene, int val, Base **base, Object **ob)
{
bool run_again = true;
@@ -991,17 +931,21 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
/* the first base */
if (iter->phase == F_START) {
- *base = (*scene)->base.first;
+ ViewLayer *view_layer = (depsgraph) ?
+ DEG_get_evaluated_view_layer(depsgraph) :
+ BKE_view_layer_context_active_PLACEHOLDER(*scene);
+ *base = view_layer->object_bases.first;
if (*base) {
*ob = (*base)->object;
iter->phase = F_SCENE;
}
else {
- /* exception: empty scene */
+ /* exception: empty scene layer */
while ((*scene)->set) {
(*scene) = (*scene)->set;
- if ((*scene)->base.first) {
- *base = (*scene)->base.first;
+ ViewLayer *view_layer_set = BKE_view_layer_default_render((*scene));
+ if (view_layer_set->object_bases.first) {
+ *base = view_layer_set->object_bases.first;
*ob = (*base)->object;
iter->phase = F_SCENE;
break;
@@ -1020,8 +964,9 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
/* (*scene) is finished, now do the set */
while ((*scene)->set) {
(*scene) = (*scene)->set;
- if ((*scene)->base.first) {
- *base = (*scene)->base.first;
+ ViewLayer *view_layer_set = BKE_view_layer_default_render((*scene));
+ if (view_layer_set->object_bases.first) {
+ *base = view_layer_set->object_bases.first;
*ob = (*base)->object;
break;
}
@@ -1036,12 +981,12 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
}
else {
if (iter->phase != F_DUPLI) {
- if ( (*base)->object->transflag & OB_DUPLI) {
+ if (depsgraph && (*base)->object->transflag & OB_DUPLI) {
/* groups cannot be duplicated for mballs yet,
* this enters eternal loop because of
* makeDispListMBall getting called inside of group_duplilist */
if ((*base)->object->dup_group == NULL) {
- iter->duplilist = object_duplilist_ex(eval_ctx, (*scene), (*base)->object, false);
+ iter->duplilist = object_duplilist_ex(depsgraph, (*scene), (*base)->object, false);
iter->dupob = iter->duplilist->first;
@@ -1055,7 +1000,7 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
}
/* handle dupli's */
if (iter->dupob) {
- (*base)->flag |= OB_FROMDUPLI;
+ (*base)->flag_legacy |= OB_FROMDUPLI;
*ob = iter->dupob->ob;
iter->phase = F_DUPLI;
@@ -1074,7 +1019,7 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
}
else if (iter->phase == F_DUPLI) {
iter->phase = F_SCENE;
- (*base)->flag &= ~OB_FROMDUPLI;
+ (*base)->flag_legacy &= ~OB_FROMDUPLI;
if (iter->dupli_refob) {
/* Restore last object's real matrix. */
@@ -1099,13 +1044,15 @@ int BKE_scene_base_iter_next(EvaluationContext *eval_ctx, SceneBaseIter *iter,
return iter->phase;
}
-Object *BKE_scene_camera_find(Scene *sc)
+Scene *BKE_scene_find_from_collection(const Main *bmain, const SceneCollection *scene_collection)
{
- Base *base;
-
- for (base = sc->base.first; base; base = base->next)
- if (base->object->type == OB_CAMERA)
- return base->object;
+ for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
+ for (ViewLayer *layer = scene->view_layers.first; layer; layer = layer->next) {
+ if (BKE_view_layer_has_collection(layer, scene_collection)) {
+ return scene;
+ }
+ }
+ }
return NULL;
}
@@ -1207,49 +1154,14 @@ char *BKE_scene_find_last_marker_name(Scene *scene, int frame)
return best_marker ? best_marker->name : NULL;
}
-
-Base *BKE_scene_base_add(Scene *sce, Object *ob)
-{
- Base *b = MEM_callocN(sizeof(*b), __func__);
- BLI_addhead(&sce->base, b);
-
- b->object = ob;
- b->flag = ob->flag;
- b->lay = ob->lay;
-
- return b;
-}
-
-void BKE_scene_base_unlink(Scene *sce, Base *base)
+void BKE_scene_remove_rigidbody_object(Scene *scene, Object *ob)
{
/* remove rigid body constraint from world before removing object */
- if (base->object->rigidbody_constraint)
- BKE_rigidbody_remove_constraint(sce, base->object);
+ if (ob->rigidbody_constraint)
+ BKE_rigidbody_remove_constraint(scene, ob);
/* remove rigid body object from world before removing object */
- if (base->object->rigidbody_object)
- BKE_rigidbody_remove_object(sce, base->object);
-
- BLI_remlink(&sce->base, base);
- if (sce->basact == base)
- sce->basact = NULL;
-}
-
-void BKE_scene_base_deselect_all(Scene *sce)
-{
- Base *b;
-
- for (b = sce->base.first; b; b = b->next) {
- b->flag &= ~SELECT;
- b->object->flag = b->flag;
- }
-}
-
-void BKE_scene_base_select(Scene *sce, Base *selbase)
-{
- selbase->flag |= SELECT;
- selbase->object->flag = selbase->flag;
-
- sce->basact = selbase;
+ if (ob->rigidbody_object)
+ BKE_rigidbody_remove_object(scene, ob);
}
/* checks for cycle, returns 1 if it's all OK */
@@ -1301,109 +1213,6 @@ void BKE_scene_frame_set(struct Scene *scene, double cfra)
scene->r.cfra = (int)intpart;
}
-#ifdef WITH_LEGACY_DEPSGRAPH
-/* drivers support/hacks
- * - this method is called from scene_update_tagged_recursive(), so gets included in viewport + render
- * - these are always run since the depsgraph can't handle non-object data
- * - these happen after objects are all done so that we can read in their final transform values,
- * though this means that objects can't refer to scene info for guidance...
- */
-static void scene_update_drivers(Main *UNUSED(bmain), Scene *scene)
-{
- SceneRenderLayer *srl;
- float ctime = BKE_scene_frame_get(scene);
-
- /* scene itself */
- if (scene->adt && scene->adt->drivers.first) {
- BKE_animsys_evaluate_animdata(scene, &scene->id, scene->adt, ctime, ADT_RECALC_DRIVERS);
- }
-
- /* world */
- /* TODO: what about world textures? but then those have nodes too... */
- if (scene->world) {
- ID *wid = (ID *)scene->world;
- AnimData *adt = BKE_animdata_from_id(wid);
-
- if (adt && adt->drivers.first)
- BKE_animsys_evaluate_animdata(scene, wid, adt, ctime, ADT_RECALC_DRIVERS);
- }
-
- /* nodes */
- if (scene->nodetree) {
- ID *nid = (ID *)scene->nodetree;
- AnimData *adt = BKE_animdata_from_id(nid);
-
- if (adt && adt->drivers.first)
- BKE_animsys_evaluate_animdata(scene, nid, adt, ctime, ADT_RECALC_DRIVERS);
- }
-
- /* world nodes */
- if (scene->world && scene->world->nodetree) {
- ID *nid = (ID *)scene->world->nodetree;
- AnimData *adt = BKE_animdata_from_id(nid);
-
- if (adt && adt->drivers.first)
- BKE_animsys_evaluate_animdata(scene, nid, adt, ctime, ADT_RECALC_DRIVERS);
- }
-
- /* freestyle */
- for (srl = scene->r.layers.first; srl; srl = srl->next) {
- FreestyleConfig *config = &srl->freestyleConfig;
- FreestyleLineSet *lineset;
-
- for (lineset = config->linesets.first; lineset; lineset = lineset->next) {
- if (lineset->linestyle) {
- ID *lid = &lineset->linestyle->id;
- AnimData *adt = BKE_animdata_from_id(lid);
-
- if (adt && adt->drivers.first)
- BKE_animsys_evaluate_animdata(scene, lid, adt, ctime, ADT_RECALC_DRIVERS);
- }
- }
- }
-}
-
-/* deps hack - do extra recalcs at end */
-static void scene_depsgraph_hack(EvaluationContext *eval_ctx, Scene *scene, Scene *scene_parent)
-{
- Base *base;
-
- scene->customdata_mask = scene_parent->customdata_mask;
-
- /* sets first, we allow per definition current scene to have
- * dependencies on sets, but not the other way around. */
- if (scene->set)
- scene_depsgraph_hack(eval_ctx, scene->set, scene_parent);
-
- for (base = scene->base.first; base; base = base->next) {
- Object *ob = base->object;
-
- if (ob->depsflag) {
- int recalc = 0;
- // printf("depshack %s\n", ob->id.name + 2);
-
- if (ob->depsflag & OB_DEPS_EXTRA_OB_RECALC)
- recalc |= OB_RECALC_OB;
- if (ob->depsflag & OB_DEPS_EXTRA_DATA_RECALC)
- recalc |= OB_RECALC_DATA;
-
- ob->recalc |= recalc;
- BKE_object_handle_update(eval_ctx, scene_parent, ob);
-
- if (ob->dup_group && (ob->transflag & OB_DUPLIGROUP)) {
- GroupObject *go;
-
- for (go = ob->dup_group->gobject.first; go; go = go->next) {
- if (go->ob)
- go->ob->recalc |= recalc;
- }
- BKE_group_handle_recalc_and_update(eval_ctx, scene_parent, ob, ob->dup_group);
- }
- }
- }
-}
-#endif /* WITH_LEGACY_DEPSGRAPH */
-
/* That's like really a bummer, because currently animation data for armatures
* might want to use pose, and pose might be missing on the object.
* This happens when changing visible layers, which leads to situations when
@@ -1419,7 +1228,7 @@ static void scene_depsgraph_hack(EvaluationContext *eval_ctx, Scene *scene, Scen
static void scene_armature_depsgraph_workaround(Main *bmain)
{
Object *ob;
- if (BLI_listbase_is_empty(&bmain->armature) || !DAG_id_type_tagged(bmain, ID_OB)) {
+ if (BLI_listbase_is_empty(&bmain->armature) || !DEG_id_type_tagged(bmain, ID_OB)) {
return;
}
for (ob = bmain->object.first; ob; ob = ob->id.next) {
@@ -1432,368 +1241,20 @@ static void scene_armature_depsgraph_workaround(Main *bmain)
}
#endif
-#ifdef WITH_LEGACY_DEPSGRAPH
-static void scene_rebuild_rbw_recursive(Scene *scene, float ctime)
-{
- if (scene->set)
- scene_rebuild_rbw_recursive(scene->set, ctime);
-
- if (BKE_scene_check_rigidbody_active(scene))
- BKE_rigidbody_rebuild_world(scene, ctime);
-}
-
-static void scene_do_rb_simulation_recursive(Scene *scene, float ctime)
-{
- if (scene->set)
- scene_do_rb_simulation_recursive(scene->set, ctime);
-
- if (BKE_scene_check_rigidbody_active(scene))
- BKE_rigidbody_do_simulation(scene, ctime);
-}
-#endif
-
-/* Used to visualize CPU threads activity during threaded object update,
- * would pollute STDERR with whole bunch of timing information which then
- * could be parsed and nicely visualized.
- */
-#ifdef WITH_LEGACY_DEPSGRAPH
-# undef DETAILED_ANALYSIS_OUTPUT
-#else
-/* ALWAYS KEEY DISABLED! */
-# undef DETAILED_ANALYSIS_OUTPUT
-#endif
-
-/* Mballs evaluation uses BKE_scene_base_iter_next which calls
- * duplilist for all objects in the scene. This leads to conflict
- * accessing and writing same data from multiple threads.
- *
- * Ideally Mballs shouldn't do such an iteration and use DAG
- * queries instead. For the time being we've got new DAG
- * let's keep it simple and update mballs in a single thread.
- */
-#define MBALL_SINGLETHREAD_HACK
-
-#ifdef WITH_LEGACY_DEPSGRAPH
-typedef struct StatisicsEntry {
- struct StatisicsEntry *next, *prev;
- Object *object;
- double start_time;
- double duration;
-} StatisicsEntry;
-
-typedef struct ThreadedObjectUpdateState {
- /* TODO(sergey): We might want this to be per-thread object. */
- EvaluationContext *eval_ctx;
- Scene *scene;
- Scene *scene_parent;
- double base_time;
-
-#ifdef MBALL_SINGLETHREAD_HACK
- bool has_mballs;
-#endif
-
- int num_threads;
-
- /* Execution statistics */
- bool has_updated_objects;
- ListBase *statistics;
-} ThreadedObjectUpdateState;
-
-static void scene_update_object_add_task(void *node, void *user_data);
-
-static void scene_update_all_bases(EvaluationContext *eval_ctx, Scene *scene, Scene *scene_parent)
-{
- Base *base;
-
- for (base = scene->base.first; base; base = base->next) {
- Object *object = base->object;
-
- BKE_object_handle_update_ex(eval_ctx, scene_parent, object, scene->rigidbody_world, true);
-
- if (object->dup_group && (object->transflag & OB_DUPLIGROUP))
- BKE_group_handle_recalc_and_update(eval_ctx, scene_parent, object, object->dup_group);
-
- /* always update layer, so that animating layers works (joshua july 2010) */
- /* XXX commented out, this has depsgraph issues anyway - and this breaks setting scenes
- * (on scene-set, the base-lay is copied to ob-lay (ton nov 2012) */
- // base->lay = ob->lay;
- }
-}
-
-static void scene_update_object_func(TaskPool * __restrict pool, void *taskdata, int threadid)
-{
-/* Disable print for now in favor of summary statistics at the end of update. */
-#define PRINT if (false) printf
-
- ThreadedObjectUpdateState *state = (ThreadedObjectUpdateState *) BLI_task_pool_userdata(pool);
- void *node = taskdata;
- Object *object = DAG_get_node_object(node);
- EvaluationContext *eval_ctx = state->eval_ctx;
- Scene *scene = state->scene;
- Scene *scene_parent = state->scene_parent;
-
-#ifdef MBALL_SINGLETHREAD_HACK
- if (object && object->type == OB_MBALL) {
- state->has_mballs = true;
- }
- else
-#endif
- if (object) {
- double start_time = 0.0;
- bool add_to_stats = false;
-
- if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
- if (object->recalc & OB_RECALC_ALL) {
- printf("Thread %d: update object %s\n", threadid, object->id.name);
- }
-
- start_time = PIL_check_seconds_timer();
-
- if (object->recalc & OB_RECALC_ALL) {
- state->has_updated_objects = true;
- add_to_stats = true;
- }
- }
-
- /* We only update object itself here, dupli-group will be updated
- * separately from main thread because of we've got no idea about
- * dependencies inside the group.
- */
- BKE_object_handle_update_ex(eval_ctx, scene_parent, object, scene->rigidbody_world, false);
-
- /* Calculate statistics. */
- if (add_to_stats) {
- StatisicsEntry *entry;
-
- entry = MEM_mallocN(sizeof(StatisicsEntry), "update thread statistics");
- entry->object = object;
- entry->start_time = start_time;
- entry->duration = PIL_check_seconds_timer() - start_time;
-
- BLI_addtail(&state->statistics[threadid], entry);
- }
- }
- else {
- PRINT("Threda %d: update node %s\n", threadid,
- DAG_get_node_name(scene, node));
- }
-
- /* Update will decrease child's valency and schedule child with zero valency. */
- DAG_threaded_update_handle_node_updated(node, scene_update_object_add_task, pool);
-
-#undef PRINT
-}
-
-static void scene_update_object_add_task(void *node, void *user_data)
-{
- TaskPool *task_pool = user_data;
-
- BLI_task_pool_push(task_pool, scene_update_object_func, node, false, TASK_PRIORITY_LOW);
-}
-
-static void print_threads_statistics(ThreadedObjectUpdateState *state)
-{
- double finish_time;
-
- if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
- return;
- }
-
-#ifdef DETAILED_ANALYSIS_OUTPUT
- if (state->has_updated_objects) {
- tot_thread = BLI_system_thread_count();
-
- fprintf(stderr, "objects update base time %f\n", state->base_time);
-
- for (i = 0; i < tot_thread; i++) {
- StatisicsEntry *entry;
- for (entry = state->statistics[i].first;
- entry;
- entry = entry->next)
- {
- fprintf(stderr, "thread %d object %s start_time %f duration %f\n",
- i, entry->object->id.name + 2,
- entry->start_time, entry->duration);
- }
- BLI_freelistN(&state->statistics[i]);
- }
- }
-#else
- finish_time = PIL_check_seconds_timer();
- int total_objects = 0;
-
- for (int i = 0; i < state->num_threads; i++) {
- int thread_total_objects = 0;
- double thread_total_time = 0.0;
- StatisicsEntry *entry;
-
- if (state->has_updated_objects) {
- /* Don't pollute output if no objects were updated. */
- for (entry = state->statistics[i].first;
- entry;
- entry = entry->next)
- {
- thread_total_objects++;
- thread_total_time += entry->duration;
- }
-
- printf("Thread %d: total %d objects in %f sec.\n",
- i,
- thread_total_objects,
- thread_total_time);
-
- for (entry = state->statistics[i].first;
- entry;
- entry = entry->next)
- {
- printf(" %s in %f sec\n", entry->object->id.name + 2, entry->duration);
- }
-
- total_objects += thread_total_objects;
- }
-
- BLI_freelistN(&state->statistics[i]);
- }
- if (state->has_updated_objects) {
- printf("Scene updated %d objects in %f sec\n",
- total_objects,
- finish_time - state->base_time);
- }
-#endif
-}
-
-static bool scene_need_update_objects(Main *bmain)
-{
- return
- /* Object datablocks themselves (for OB_RECALC_OB) */
- DAG_id_type_tagged(bmain, ID_OB) ||
-
- /* Objects data datablocks (for OB_RECALC_DATA) */
- DAG_id_type_tagged(bmain, ID_ME) || /* Mesh */
- DAG_id_type_tagged(bmain, ID_CU) || /* Curve */
- DAG_id_type_tagged(bmain, ID_MB) || /* MetaBall */
- DAG_id_type_tagged(bmain, ID_LA) || /* Lamp */
- DAG_id_type_tagged(bmain, ID_LT) || /* Lattice */
- DAG_id_type_tagged(bmain, ID_CA) || /* Camera */
- DAG_id_type_tagged(bmain, ID_KE) || /* KE */
- DAG_id_type_tagged(bmain, ID_SPK) || /* Speaker */
- DAG_id_type_tagged(bmain, ID_AR); /* Armature */
-}
-
-static void scene_update_objects(EvaluationContext *eval_ctx, Main *bmain, Scene *scene, Scene *scene_parent)
-{
- TaskScheduler *task_scheduler;
- TaskPool *task_pool;
- ThreadedObjectUpdateState state;
- bool need_singlethread_pass;
- bool need_free_scheduler;
-
- /* Early check for whether we need to invoke all the task-based
- * things (spawn new ppol, traverse dependency graph and so on).
- *
- * Basically if there's no ID datablocks tagged for update which
- * corresponds to object->recalc flags (which are checked in
- * BKE_object_handle_update() then we do nothing here.
- */
- if (!scene_need_update_objects(bmain)) {
- return;
- }
-
- state.eval_ctx = eval_ctx;
- state.scene = scene;
- state.scene_parent = scene_parent;
-
- if (G.debug & G_DEBUG_DEPSGRAPH_NO_THREADS) {
- task_scheduler = BLI_task_scheduler_create(1);
- need_free_scheduler = true;
- }
- else {
- task_scheduler = BLI_task_scheduler_get();
- need_free_scheduler = false;
- }
-
- /* Those are only needed when blender is run with --debug argument. */
- if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
- const int tot_thread = BLI_task_scheduler_num_threads(task_scheduler);
- state.statistics = MEM_callocN(tot_thread * sizeof(*state.statistics),
- "scene update objects stats");
- state.has_updated_objects = false;
- state.base_time = PIL_check_seconds_timer();
- state.num_threads = tot_thread;
- }
-
-#ifdef MBALL_SINGLETHREAD_HACK
- state.has_mballs = false;
-#endif
-
- task_pool = BLI_task_pool_create(task_scheduler, &state);
-
- DAG_threaded_update_begin(scene, scene_update_object_add_task, task_pool);
- BLI_task_pool_work_and_wait(task_pool);
- BLI_task_pool_free(task_pool);
-
- if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
- print_threads_statistics(&state);
- MEM_freeN(state.statistics);
- }
-
- /* We do single thread pass to update all the objects which are in cyclic dependency.
- * Such objects can not be handled by a generic DAG traverse and it's really tricky
- * to detect whether cycle could be solved or not.
- *
- * In this situation we simply update all remaining objects in a single thread and
- * it'll happen in the same exact order as it was in single-threaded DAG.
- *
- * We couldn't use threaded update for objects which are in cycle because they might
- * access data of each other which is being re-evaluated.
- *
- * Also, as was explained above, for now we also update all the mballs in single thread.
- *
- * - sergey -
- */
- need_singlethread_pass = DAG_is_acyclic(scene) == false;
-#ifdef MBALL_SINGLETHREAD_HACK
- need_singlethread_pass |= state.has_mballs;
-#endif
-
- if (need_singlethread_pass) {
- scene_update_all_bases(eval_ctx, scene, scene_parent);
- }
-
- if (need_free_scheduler) {
- BLI_task_scheduler_free(task_scheduler);
- }
-}
-
-static void scene_update_tagged_recursive(EvaluationContext *eval_ctx, Main *bmain, Scene *scene, Scene *scene_parent)
-{
- scene->customdata_mask = scene_parent->customdata_mask;
-
- /* sets first, we allow per definition current scene to have
- * dependencies on sets, but not the other way around. */
- if (scene->set)
- scene_update_tagged_recursive(eval_ctx, bmain, scene->set, scene_parent);
-
- /* scene objects */
- scene_update_objects(eval_ctx, bmain, scene, scene_parent);
-
- /* scene drivers... */
- scene_update_drivers(bmain, scene);
-
- /* update masking curves */
- BKE_mask_update_scene(bmain, scene);
-
-}
-#endif /* WITH_LEGACY_DEPSGRAPH */
-
static bool check_rendered_viewport_visible(Main *bmain)
{
wmWindowManager *wm = bmain->wm.first;
wmWindow *window;
for (window = wm->windows.first; window != NULL; window = window->next) {
- bScreen *screen = window->screen;
- ScrArea *area;
- for (area = screen->areabase.first; area != NULL; area = area->next) {
+ const bScreen *screen = BKE_workspace_active_screen_get(window->workspace_hook);
+ Scene *scene = window->scene;
+ RenderEngineType *type = RE_engines_find(scene->r.engine);
+
+ if (type->draw_engine || !type->render_to_view) {
+ continue;
+ }
+
+ for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) {
View3D *v3d = area->spacedata.first;
if (area->spacetype != SPACE_VIEW3D) {
continue;
@@ -1806,7 +1267,10 @@ static bool check_rendered_viewport_visible(Main *bmain)
return false;
}
-static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
+/* TODO(campbell): shouldn't we be able to use 'DEG_get_view_layer' here?
+ * Currently this is NULL on load, so don't. */
+static void prepare_mesh_for_viewport_render(
+ Main *bmain, const ViewLayer *view_layer)
{
/* This is needed to prepare mesh to be used by the render
* engine from the viewport rendering. We do loading here
@@ -1817,7 +1281,7 @@ static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
* call loading of the edit data for the mesh objects.
*/
- Object *obedit = scene->obedit;
+ Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
if (obedit) {
Mesh *mesh = obedit->data;
if ((obedit->type == OB_MESH) &&
@@ -1831,318 +1295,84 @@ static void prepare_mesh_for_viewport_render(Main *bmain, Scene *scene)
(&(struct BMeshToMeshParams){
.calc_object_remap = true,
}));
- DAG_id_tag_update(&mesh->id, 0);
+ DEG_id_tag_update(&mesh->id, 0);
}
}
}
}
-void BKE_scene_update_tagged(EvaluationContext *eval_ctx, Main *bmain, Scene *scene)
+/* TODO(sergey): This actually should become view_layer_graph or so.
+ * Same applies to update_for_newframe.
+ */
+void BKE_scene_graph_update_tagged(Depsgraph *depsgraph,
+ Main *bmain)
{
- Scene *sce_iter;
-#ifdef WITH_LEGACY_DEPSGRAPH
- bool use_new_eval = !DEG_depsgraph_use_legacy();
-#endif
-
- /* keep this first */
- BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_PRE);
-
- /* (re-)build dependency graph if needed */
- for (sce_iter = scene; sce_iter; sce_iter = sce_iter->set) {
- DAG_scene_relations_update(bmain, sce_iter);
- /* Uncomment this to check if dependency graph was properly tagged for update. */
-#if 0
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (use_new_eval)
-#endif
- {
- DAG_scene_relations_validate(bmain, sce_iter);
- }
-#endif
- }
-
- /* flush editing data if needed */
- prepare_mesh_for_viewport_render(bmain, scene);
+ Scene *scene = DEG_get_input_scene(depsgraph);
+ ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
- /* flush recalc flags to dependencies */
- DAG_ids_flush_tagged(bmain);
-
- /* removed calls to quick_cache, see pointcache.c */
-
- /* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later
- * when trying to find materials with drivers that need evaluating [#32017]
+ /* TODO(sergey): Some functions here are changing global state,
+ * for example, clearing update tags from bmain.
*/
- BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
- BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
-
- /* update all objects: drivers, matrices, displists, etc. flags set
- * by depgraph or manual, no layer check here, gets correct flushed
- *
- * in the future this should handle updates for all datablocks, not
- * only objects and scenes. - brecht */
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!use_new_eval) {
- scene_update_tagged_recursive(eval_ctx, bmain, scene, scene);
- }
- else
-#endif
- {
- DEG_evaluate_on_refresh(eval_ctx, scene->depsgraph, scene);
- }
-
- /* update sound system animation (TODO, move to depsgraph) */
- BKE_sound_update_scene(bmain, scene);
-
- /* extra call here to recalc scene animation (for sequencer) */
- {
- AnimData *adt = BKE_animdata_from_id(&scene->id);
- float ctime = BKE_scene_frame_get(scene);
-
- if (adt && (adt->recalc & ADT_RECALC_ANIM))
- BKE_animsys_evaluate_animdata(scene, &scene->id, adt, ctime, 0);
- }
-
- /* Extra call here to recalc material animation.
- *
- * Need to do this so changing material settings from the graph/dopesheet
- * will update stuff in the viewport.
+ /* (Re-)build dependency graph if needed. */
+ DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
+ /* Uncomment this to check if graph was properly tagged for update. */
+ // DEG_debug_graph_relations_validate(depsgraph, bmain, scene);
+ /* Flush editing data if needed. */
+ prepare_mesh_for_viewport_render(bmain, view_layer);
+ /* Flush recalc flags to dependencies. */
+ DEG_graph_flush_update(bmain, depsgraph);
+ /* Update all objects: drivers, matrices, displists, etc. flags set
+ * by depgraph or manual, no layer check here, gets correct flushed.
*/
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!use_new_eval && DAG_id_type_tagged(bmain, ID_MA)) {
- Material *material;
- float ctime = BKE_scene_frame_get(scene);
-
- for (material = bmain->mat.first;
- material;
- material = material->id.next)
- {
- AnimData *adt = BKE_animdata_from_id(&material->id);
- if (adt && (adt->recalc & ADT_RECALC_ANIM))
- BKE_animsys_evaluate_animdata(scene, &material->id, adt, ctime, 0);
- }
- }
-
- /* Also do the same for node trees. */
- if (!use_new_eval && DAG_id_type_tagged(bmain, ID_NT)) {
- float ctime = BKE_scene_frame_get(scene);
-
- FOREACH_NODETREE(bmain, ntree, id)
- {
- AnimData *adt = BKE_animdata_from_id(&ntree->id);
- if (adt && (adt->recalc & ADT_RECALC_ANIM))
- BKE_animsys_evaluate_animdata(scene, &ntree->id, adt, ctime, 0);
- }
- FOREACH_NODETREE_END
- }
-#endif
-
- /* notify editors and python about recalc */
- BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_SCENE_UPDATE_POST);
-
+ DEG_evaluate_on_refresh(depsgraph);
+ /* Update sound system animation (TODO, move to depsgraph). */
+ BKE_sound_update_scene(bmain, scene);
/* Inform editors about possible changes. */
- DAG_ids_check_recalc(bmain, scene, false);
-
- /* clear recalc flags */
- DAG_ids_clear_recalc(bmain);
+ DEG_ids_check_recalc(bmain, depsgraph, scene, view_layer, false);
+ /* Clear recalc flags. */
+ DEG_ids_clear_recalc(bmain);
}
/* applies changes right away, does all sets too */
-void BKE_scene_update_for_newframe(EvaluationContext *eval_ctx, Main *bmain, Scene *sce, unsigned int lay)
+void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph,
+ Main *bmain)
{
- BKE_scene_update_for_newframe_ex(eval_ctx, bmain, sce, lay, false);
-}
-
-void BKE_scene_update_for_newframe_ex(EvaluationContext *eval_ctx, Main *bmain, Scene *sce, unsigned int lay, bool do_invisible_flush)
-{
- float ctime = BKE_scene_frame_get(sce);
- Scene *sce_iter;
-#ifdef DETAILED_ANALYSIS_OUTPUT
- double start_time = PIL_check_seconds_timer();
-#endif
-#ifdef WITH_LEGACY_DEPSGRAPH
- bool use_new_eval = !DEG_depsgraph_use_legacy();
-#else
- /* TODO(sergey): Pass to evaluation routines instead of storing layer in the dependency graph? */
- (void) do_invisible_flush;
-#endif
-
- DAG_editors_update_pre(bmain, sce, true);
+ Scene *scene = DEG_get_input_scene(depsgraph);
+ ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
- /* keep this first */
- BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_PRE);
- BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_SCENE_UPDATE_PRE);
-
- /* update animated image textures for particles, modifiers, gpu, etc,
- * call this at the start so modifiers with textures don't lag 1 frame */
- BKE_image_update_frame(bmain, sce->r.cfra);
-
-#ifdef WITH_LEGACY_DEPSGRAPH
- /* rebuild rigid body worlds before doing the actual frame update
- * this needs to be done on start frame but animation playback usually starts one frame later
- * we need to do it here to avoid rebuilding the world on every simulation change, which can be very expensive
+ /* TODO(sergey): Some functions here are changing global state,
+ * for example, clearing update tags from bmain.
*/
- if (!use_new_eval) {
- scene_rebuild_rbw_recursive(sce, ctime);
- }
-#endif
-
- BKE_sound_set_cfra(sce->r.cfra);
-
- /* clear animation overrides */
- /* XXX TODO... */
-
- for (sce_iter = sce; sce_iter; sce_iter = sce_iter->set)
- DAG_scene_relations_update(bmain, sce_iter);
-
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!use_new_eval) {
- /* flush recalc flags to dependencies, if we were only changing a frame
- * this would not be necessary, but if a user or a script has modified
- * some datablock before BKE_scene_update_tagged was called, we need the flush */
- DAG_ids_flush_tagged(bmain);
-
- /* Following 2 functions are recursive
- * so don't call within 'scene_update_tagged_recursive' */
- DAG_scene_update_flags(bmain, sce, lay, true, do_invisible_flush); // only stuff that moves or needs display still
- BKE_mask_evaluate_all_masks(bmain, ctime, true);
- }
-#endif
-
- /* Update animated cache files for modifiers. */
- BKE_cachefile_update_frame(bmain, sce, ctime, (((double)sce->r.frs_sec) / (double)sce->r.frs_sec_base));
-
+ const float ctime = BKE_scene_frame_get(scene);
+ /* Keep this first. */
+ BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_PRE);
+ /* Update animated image textures for particles, modifiers, gpu, etc,
+ * call this at the start so modifiers with textures don't lag 1 frame.
+ */
+ BKE_image_update_frame(bmain, scene->r.cfra);
+ BKE_sound_set_cfra(scene->r.cfra);
+ DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
+ /* Update animated cache files for modifiers.
+ *
+ * TODO(sergey): Make this a depsgraph node?
+ */
+ BKE_cachefile_update_frame(bmain, scene, ctime,
+ (((double)scene->r.frs_sec) / (double)scene->r.frs_sec_base));
#ifdef POSE_ANIMATION_WORKAROUND
scene_armature_depsgraph_workaround(bmain);
#endif
-
- /* All 'standard' (i.e. without any dependencies) animation is handled here,
- * with an 'local' to 'macro' order of evaluation. This should ensure that
- * settings stored nestled within a hierarchy (i.e. settings in a Texture block
- * can be overridden by settings from Scene, which owns the Texture through a hierarchy
- * such as Scene->World->MTex/Texture) can still get correctly overridden.
+ /* Update all objects: drivers, matrices, displists, etc. flags set
+ * by depgraph or manual, no layer check here, gets correct flushed.
*/
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!use_new_eval) {
- BKE_animsys_evaluate_all_animation(bmain, sce, ctime);
- /*...done with recursive funcs */
- }
-#endif
-
- /* clear "LIB_TAG_DOIT" flag from all materials, to prevent infinite recursion problems later
- * when trying to find materials with drivers that need evaluating [#32017]
- */
- BKE_main_id_tag_idcode(bmain, ID_MA, LIB_TAG_DOIT, false);
- BKE_main_id_tag_idcode(bmain, ID_LA, LIB_TAG_DOIT, false);
-
- /* run rigidbody sim */
- /* NOTE: current position is so that rigidbody sim affects other objects, might change in the future */
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!use_new_eval) {
- scene_do_rb_simulation_recursive(sce, ctime);
- }
-#endif
-
- /* BKE_object_handle_update() on all objects, groups and sets */
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (use_new_eval) {
- DEG_evaluate_on_framechange(eval_ctx, bmain, sce->depsgraph, ctime, lay);
- }
- else {
- scene_update_tagged_recursive(eval_ctx, bmain, sce, sce);
- }
-#else
- DEG_evaluate_on_framechange(eval_ctx, bmain, sce->depsgraph, ctime, lay);
-#endif
-
- /* update sound system animation (TODO, move to depsgraph) */
- BKE_sound_update_scene(bmain, sce);
-
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!use_new_eval) {
- scene_depsgraph_hack(eval_ctx, sce, sce);
- }
-#endif
-
- /* notify editors and python about recalc */
- BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_SCENE_UPDATE_POST);
- BLI_callback_exec(bmain, &sce->id, BLI_CB_EVT_FRAME_CHANGE_POST);
-
+ DEG_evaluate_on_framechange(bmain, depsgraph, ctime);
+ /* Update sound system animation (TODO, move to depsgraph). */
+ BKE_sound_update_scene(bmain, scene);
+ /* Notify editors and python about recalc. */
+ BLI_callback_exec(bmain, &scene->id, BLI_CB_EVT_FRAME_CHANGE_POST);
/* Inform editors about possible changes. */
- DAG_ids_check_recalc(bmain, sce, true);
-
+ DEG_ids_check_recalc(bmain, depsgraph, scene, view_layer, true);
/* clear recalc flags */
- DAG_ids_clear_recalc(bmain);
-
-#ifdef DETAILED_ANALYSIS_OUTPUT
- fprintf(stderr, "frame update start_time %f duration %f\n", start_time, PIL_check_seconds_timer() - start_time);
-#endif
-}
-
-/* return default layer, also used to patch old files */
-SceneRenderLayer *BKE_scene_add_render_layer(Scene *sce, const char *name)
-{
- SceneRenderLayer *srl;
-
- if (!name)
- name = DATA_("RenderLayer");
-
- srl = MEM_callocN(sizeof(SceneRenderLayer), "new render layer");
- BLI_strncpy(srl->name, name, sizeof(srl->name));
- BLI_uniquename(&sce->r.layers, srl, DATA_("RenderLayer"), '.', offsetof(SceneRenderLayer, name), sizeof(srl->name));
- BLI_addtail(&sce->r.layers, srl);
-
- /* note, this is also in render, pipeline.c, to make layer when scenedata doesnt have it */
- srl->lay = (1 << 20) - 1;
- srl->layflag = 0x7FFF; /* solid ztra halo edge strand */
- srl->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
- srl->pass_alpha_threshold = 0.5f;
- BKE_freestyle_config_init(&srl->freestyleConfig);
-
- return srl;
-}
-
-bool BKE_scene_remove_render_layer(Main *bmain, Scene *scene, SceneRenderLayer *srl)
-{
- const int act = BLI_findindex(&scene->r.layers, srl);
- Scene *sce;
-
- if (act == -1) {
- return false;
- }
- else if ( (scene->r.layers.first == scene->r.layers.last) &&
- (scene->r.layers.first == srl))
- {
- /* ensure 1 layer is kept */
- return false;
- }
-
- BKE_freestyle_config_free(&srl->freestyleConfig);
-
- if (srl->prop) {
- IDP_FreeProperty(srl->prop);
- MEM_freeN(srl->prop);
- }
-
- BLI_remlink(&scene->r.layers, srl);
- MEM_freeN(srl);
-
- scene->r.actlay = 0;
-
- for (sce = bmain->scene.first; sce; sce = sce->id.next) {
- if (sce->nodetree) {
- bNode *node;
- for (node = sce->nodetree->nodes.first; node; node = node->next) {
- if (node->type == CMP_NODE_R_LAYERS && (Scene *)node->id == scene) {
- if (node->custom1 == act)
- node->custom1 = 0;
- else if (node->custom1 > act)
- node->custom1--;
- }
- }
- }
- }
-
- return true;
+ DEG_ids_clear_recalc(bmain);
}
/* return default view */
@@ -2209,37 +1439,34 @@ int get_render_child_particle_number(const RenderData *r, int num, bool for_rend
}
}
-int get_render_shadow_samples(const RenderData *r, int samples)
-{
- if ((r->mode & R_SIMPLIFY) && samples > 0)
- return min_ii(r->simplify_shadowsamples, samples);
- else
- return samples;
-}
-
-float get_render_aosss_error(const RenderData *r, float error)
-{
- if (r->mode & R_SIMPLIFY)
- return ((1.0f - r->simplify_aosss) * 10.0f + 1.0f) * error;
- else
- return error;
-}
-
-/* helper function for the SETLOOPER macro */
-Base *_setlooper_base_step(Scene **sce_iter, Base *base)
+/**
+ * Helper function for the SETLOOPER and SETLOOPER_VIEW_LAYER macros
+ *
+ * It iterates over the bases of the active layer and then the bases
+ * of the active layer of the background (set) scenes recursively.
+ */
+Base *_setlooper_base_step(Scene **sce_iter, ViewLayer *view_layer, Base *base)
{
if (base && base->next) {
- /* common case, step to the next */
+ /* Common case, step to the next. */
return base->next;
}
- else if (base == NULL && (*sce_iter)->base.first) {
- /* first time looping, return the scenes first base */
- return (Base *)(*sce_iter)->base.first;
+ else if ((base == NULL) && (view_layer != NULL)) {
+ /* First time looping, return the scenes first base. */
+ /* For the first loop we should get the layer from workspace when available. */
+ if (view_layer->object_bases.first) {
+ return (Base *)view_layer->object_bases.first;
+ }
+ /* No base on this scene layer. */
+ goto next_set;
}
else {
- /* reached the end, get the next base in the set */
+next_set:
+ /* Reached the end, get the next base in the set. */
while ((*sce_iter = (*sce_iter)->set)) {
- base = (Base *)(*sce_iter)->base.first;
+ ViewLayer *view_layer_set = BKE_view_layer_default_render((*sce_iter));
+ base = (Base *)view_layer_set->object_bases.first;
+
if (base) {
return base;
}
@@ -2249,58 +1476,67 @@ Base *_setlooper_base_step(Scene **sce_iter, Base *base)
return NULL;
}
-bool BKE_scene_use_new_shading_nodes(const Scene *scene)
-{
- const RenderEngineType *type = RE_engines_find(scene->r.engine);
- return (type && type->flag & RE_USE_SHADING_NODES);
-}
-
bool BKE_scene_use_shading_nodes_custom(Scene *scene)
{
RenderEngineType *type = RE_engines_find(scene->r.engine);
return (type && type->flag & RE_USE_SHADING_NODES_CUSTOM);
}
-bool BKE_scene_use_world_space_shading(Scene *scene)
-{
- const RenderEngineType *type = RE_engines_find(scene->r.engine);
- return ((scene->r.mode & R_USE_WS_SHADING) ||
- (type && (type->flag & RE_USE_SHADING_NODES)));
-}
-
bool BKE_scene_use_spherical_stereo(Scene *scene)
{
RenderEngineType *type = RE_engines_find(scene->r.engine);
return (type && type->flag & RE_USE_SPHERICAL_STEREO);
}
-bool BKE_scene_uses_blender_internal(const Scene *scene)
+bool BKE_scene_uses_blender_eevee(const Scene *scene)
{
- return STREQ(scene->r.engine, RE_engine_id_BLENDER_RENDER);
+ return STREQ(scene->r.engine, RE_engine_id_BLENDER_EEVEE);
}
-bool BKE_scene_uses_blender_game(const Scene *scene)
+bool BKE_scene_uses_cycles(const Scene *scene)
{
- return STREQ(scene->r.engine, RE_engine_id_BLENDER_GAME);
+ return STREQ(scene->r.engine, RE_engine_id_CYCLES);
}
-void BKE_scene_base_flag_to_objects(struct Scene *scene)
+void BKE_scene_base_flag_to_objects(ViewLayer *view_layer)
{
- Base *base = scene->base.first;
+ Base *base = view_layer->object_bases.first;
while (base) {
- base->object->flag = base->flag;
+ BKE_scene_object_base_flag_sync_from_base(base);
base = base->next;
}
}
-void BKE_scene_base_flag_from_objects(struct Scene *scene)
+void BKE_scene_object_base_flag_sync_from_base(Base *base)
{
- Base *base = scene->base.first;
+ Object *ob = base->object;
- while (base) {
- base->flag = base->object->flag;
- base = base->next;
+ /* keep the object only flags untouched */
+ int flag = ob->flag & OB_FROMGROUP;
+
+ ob->flag = base->flag;
+ ob->flag |= flag;
+
+ if ((base->flag & BASE_SELECTED) != 0) {
+ ob->flag |= SELECT;
+ }
+ else {
+ ob->flag &= ~SELECT;
+ }
+}
+
+void BKE_scene_object_base_flag_sync_from_object(Base *base)
+{
+ Object *ob = base->object;
+ base->flag = ob->flag;
+
+ if ((ob->flag & SELECT) != 0) {
+ base->flag |= BASE_SELECTED;
+ BLI_assert((base->flag & BASE_SELECTABLED) != 0);
+ }
+ else {
+ base->flag &= ~BASE_SELECTED;
}
}
@@ -2669,3 +1905,146 @@ int BKE_scene_multiview_num_videos_get(const RenderData *rd)
return BKE_scene_multiview_num_views_get(rd);
}
}
+
+/* Manipulation of depsgraph storage. */
+
+/* This is a key which identifies depsgraph. */
+typedef struct DepsgraphKey {
+ ViewLayer *view_layer;
+ /* TODO(sergey): Need to include window somehow (same layer might be in a
+ * different states in different windows).
+ */
+} DepsgraphKey;
+
+static unsigned int depsgraph_key_hash(const void *key_v)
+{
+ const DepsgraphKey *key = key_v;
+ unsigned int hash = BLI_ghashutil_ptrhash(key->view_layer);
+ /* TODO(sergey): Include hash from other fields in the key. */
+ return hash;
+}
+
+static bool depsgraph_key_compare(const void *key_a_v, const void *key_b_v)
+{
+ const DepsgraphKey *key_a = key_a_v;
+ const DepsgraphKey *key_b = key_b_v;
+ /* TODO(sergey): Compare rest of */
+ return !(key_a->view_layer == key_b->view_layer);
+}
+
+static void depsgraph_key_free(void *key_v)
+{
+ DepsgraphKey *key = key_v;
+ MEM_freeN(key);
+}
+
+static void depsgraph_key_value_free(void *value)
+{
+ Depsgraph *depsgraph = value;
+ DEG_graph_free(depsgraph);
+}
+
+void BKE_scene_allocate_depsgraph_hash(Scene *scene)
+{
+ scene->depsgraph_hash = BLI_ghash_new(depsgraph_key_hash,
+ depsgraph_key_compare,
+ "Scene Depsgraph Hash");
+}
+
+void BKE_scene_ensure_depsgraph_hash(Scene *scene)
+{
+ if (scene->depsgraph_hash == NULL) {
+ BKE_scene_allocate_depsgraph_hash(scene);
+ }
+}
+
+void BKE_scene_free_depsgraph_hash(Scene *scene)
+{
+ if (scene->depsgraph_hash == NULL) {
+ return;
+ }
+ BLI_ghash_free(scene->depsgraph_hash,
+ depsgraph_key_free,
+ depsgraph_key_value_free);
+}
+
+/* Query depsgraph for a specific contexts. */
+
+Depsgraph *BKE_scene_get_depsgraph(Scene *scene,
+ ViewLayer *view_layer,
+ bool allocate)
+{
+ BLI_assert(scene != NULL);
+ BLI_assert(view_layer != NULL);
+ /* Make sure hash itself exists. */
+ if (allocate) {
+ BKE_scene_ensure_depsgraph_hash(scene);
+ }
+ if (scene->depsgraph_hash == NULL) {
+ return NULL;
+ }
+ /* Either ensure item is in the hash or simply return NULL if it's not,
+ * depending on whether caller wants us to create depsgraph or not.
+ */
+ DepsgraphKey key;
+ key.view_layer = view_layer;
+ Depsgraph *depsgraph;
+ if (allocate) {
+ DepsgraphKey **key_ptr;
+ Depsgraph **depsgraph_ptr;
+ if (!BLI_ghash_ensure_p_ex(scene->depsgraph_hash,
+ &key,
+ (void ***)&key_ptr,
+ (void ***)&depsgraph_ptr))
+ {
+ *key_ptr = MEM_mallocN(sizeof(DepsgraphKey), __func__);
+ **key_ptr = key;
+ *depsgraph_ptr = DEG_graph_new(scene, view_layer, DAG_EVAL_VIEWPORT);
+ /* TODO(sergey): Would be cool to avoid string format print,
+ * but is a bit tricky because we can't know in advance whether
+ * we will ever enable debug messages for this depsgraph.
+ */
+ char name[1024];
+ BLI_snprintf(name, sizeof(name), "%s :: %s", scene->id.name, view_layer->name);
+ DEG_debug_name_set(*depsgraph_ptr, name);
+ }
+ depsgraph = *depsgraph_ptr;
+ }
+ else {
+ depsgraph = BLI_ghash_lookup(scene->depsgraph_hash, &key);
+ }
+ return depsgraph;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Scene Orientation
+ * \{ */
+
+void BKE_scene_transform_orientation_remove(
+ Scene *scene, TransformOrientation *orientation)
+{
+ const int orientation_index = BKE_scene_transform_orientation_get_index(scene, orientation);
+ if (scene->orientation_index_custom == orientation_index) {
+ /* could also use orientation_index-- */
+ scene->orientation_type = V3D_MANIP_GLOBAL;
+ scene->orientation_index_custom = -1;
+ }
+ BLI_freelinkN(&scene->transform_spaces, orientation);
+}
+
+TransformOrientation *BKE_scene_transform_orientation_find(
+ const Scene *scene, const int index)
+{
+ return BLI_findlink(&scene->transform_spaces, index);
+}
+
+/**
+ * \return the index that \a orientation has within \a scene's transform-orientation list or -1 if not found.
+ */
+int BKE_scene_transform_orientation_get_index(
+ const Scene *scene, const TransformOrientation *orientation)
+{
+ return BLI_findindex(&scene->transform_spaces, orientation);
+}
+
+/** \} */
diff --git a/source/blender/blenkernel/intern/screen.c b/source/blender/blenkernel/intern/screen.c
index 2b1cf0a01df..ece68884f5c 100644
--- a/source/blender/blenkernel/intern/screen.c
+++ b/source/blender/blenkernel/intern/screen.c
@@ -39,19 +39,20 @@
#include "MEM_guardedalloc.h"
-#include "GPU_compositing.h"
-
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BLI_rect.h"
+#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_screen.h"
+#include "BKE_workspace.h"
/* ************ Spacetype/regiontype handling ************** */
@@ -179,9 +180,11 @@ ARegion *BKE_area_region_copy(SpaceType *st, ARegion *ar)
BLI_listbase_clear(&newar->panels_category);
BLI_listbase_clear(&newar->panels_category_active);
BLI_listbase_clear(&newar->ui_lists);
- newar->swinid = 0;
+ newar->visible = 0;
+ newar->manipulator_map = NULL;
newar->regiontimer = NULL;
newar->headerstr = NULL;
+ newar->draw_buffer = NULL;
/* use optional regiondata callback */
if (ar->regiondata) {
@@ -289,6 +292,43 @@ void BKE_spacedata_id_unref(struct ScrArea *sa, struct SpaceLink *sl, struct ID
}
}
+/**
+ * Avoid bad-level calls to #WM_manipulatormap_tag_refresh.
+ */
+static void (*region_refresh_tag_manipulatormap_callback)(struct wmManipulatorMap *) = NULL;
+
+void BKE_region_callback_refresh_tag_manipulatormap_set(void (*callback)(struct wmManipulatorMap *))
+{
+ region_refresh_tag_manipulatormap_callback = callback;
+}
+
+void BKE_screen_manipulator_tag_refresh(struct bScreen *sc)
+{
+ if (region_refresh_tag_manipulatormap_callback == NULL) {
+ return;
+ }
+
+ ScrArea *sa;
+ ARegion *ar;
+ for (sa = sc->areabase.first; sa; sa = sa->next) {
+ for (ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->manipulator_map != NULL) {
+ region_refresh_tag_manipulatormap_callback(ar->manipulator_map);
+ }
+ }
+ }
+}
+
+/**
+ * Avoid bad-level calls to #WM_manipulatormap_delete.
+ */
+static void (*region_free_manipulatormap_callback)(struct wmManipulatorMap *) = NULL;
+
+void BKE_region_callback_free_manipulatormap_set(void (*callback)(struct wmManipulatorMap *))
+{
+ region_free_manipulatormap_callback = callback;
+}
+
/* not region itself */
void BKE_area_region_free(SpaceType *st, ARegion *ar)
{
@@ -338,6 +378,11 @@ void BKE_area_region_free(SpaceType *st, ARegion *ar)
MEM_freeN(uilst->properties);
}
}
+
+ if (ar->manipulator_map != NULL) {
+ region_free_manipulatormap_callback(ar->manipulator_map);
+ }
+
BLI_freelistN(&ar->ui_lists);
BLI_freelistN(&ar->ui_previews);
BLI_freelistN(&ar->panels_category);
@@ -353,6 +398,7 @@ void BKE_screen_area_free(ScrArea *sa)
for (ar = sa->regionbase.first; ar; ar = ar->next)
BKE_area_region_free(st, ar);
+ MEM_SAFE_FREE(sa->global);
BLI_freelistN(&sa->regionbase);
BKE_spacedata_freelist(&sa->spacedata);
@@ -360,10 +406,21 @@ void BKE_screen_area_free(ScrArea *sa)
BLI_freelistN(&sa->actionzones);
}
+void BKE_screen_area_map_free(ScrAreaMap *area_map)
+{
+ for (ScrArea *area = area_map->areabase.first, *area_next; area; area = area_next) {
+ area_next = area->next;
+ BKE_screen_area_free(area);
+ }
+
+ BLI_freelistN(&area_map->vertbase);
+ BLI_freelistN(&area_map->edgebase);
+ BLI_freelistN(&area_map->areabase);
+}
+
/** Free (or release) any data used by this screen (does not free the screen itself). */
void BKE_screen_free(bScreen *sc)
{
- ScrArea *sa, *san;
ARegion *ar;
/* No animdata here. */
@@ -372,15 +429,10 @@ void BKE_screen_free(bScreen *sc)
BKE_area_region_free(NULL, ar);
BLI_freelistN(&sc->regionbase);
-
- for (sa = sc->areabase.first; sa; sa = san) {
- san = sa->next;
- BKE_screen_area_free(sa);
- }
-
- BLI_freelistN(&sc->vertbase);
- BLI_freelistN(&sc->edgebase);
- BLI_freelistN(&sc->areabase);
+
+ BKE_screen_area_map_free(AREAMAP_FROM_SCREEN(sc));
+
+ BKE_previewimg_free(&sc->preview);
/* Region and timer are freed by the window manager. */
MEM_SAFE_FREE(sc->tool_tip);
@@ -405,6 +457,174 @@ unsigned int BKE_screen_visible_layers(bScreen *screen, Scene *scene)
return layer;
}
+
+/* ***************** Screen edges & verts ***************** */
+
+ScrEdge *BKE_screen_find_edge(bScreen *sc, ScrVert *v1, ScrVert *v2)
+{
+ ScrEdge *se;
+
+ BKE_screen_sort_scrvert(&v1, &v2);
+ for (se = sc->edgebase.first; se; se = se->next) {
+ if (se->v1 == v1 && se->v2 == v2) {
+ return se;
+ }
+ }
+
+ return NULL;
+}
+
+void BKE_screen_sort_scrvert(ScrVert **v1, ScrVert **v2)
+{
+ ScrVert *tmp;
+
+ if (*v1 > *v2) {
+ tmp = *v1;
+ *v1 = *v2;
+ *v2 = tmp;
+ }
+}
+
+void BKE_screen_remove_double_scrverts(bScreen *sc)
+{
+ ScrVert *v1, *verg;
+ ScrEdge *se;
+ ScrArea *sa;
+
+ verg = sc->vertbase.first;
+ while (verg) {
+ if (verg->newv == NULL) { /* !!! */
+ v1 = verg->next;
+ while (v1) {
+ if (v1->newv == NULL) { /* !?! */
+ if (v1->vec.x == verg->vec.x && v1->vec.y == verg->vec.y) {
+ /* printf("doublevert\n"); */
+ v1->newv = verg;
+ }
+ }
+ v1 = v1->next;
+ }
+ }
+ verg = verg->next;
+ }
+
+ /* replace pointers in edges and faces */
+ se = sc->edgebase.first;
+ while (se) {
+ if (se->v1->newv) se->v1 = se->v1->newv;
+ if (se->v2->newv) se->v2 = se->v2->newv;
+ /* edges changed: so.... */
+ BKE_screen_sort_scrvert(&(se->v1), &(se->v2));
+ se = se->next;
+ }
+ sa = sc->areabase.first;
+ while (sa) {
+ if (sa->v1->newv) sa->v1 = sa->v1->newv;
+ if (sa->v2->newv) sa->v2 = sa->v2->newv;
+ if (sa->v3->newv) sa->v3 = sa->v3->newv;
+ if (sa->v4->newv) sa->v4 = sa->v4->newv;
+ sa = sa->next;
+ }
+
+ /* remove */
+ verg = sc->vertbase.first;
+ while (verg) {
+ v1 = verg->next;
+ if (verg->newv) {
+ BLI_remlink(&sc->vertbase, verg);
+ MEM_freeN(verg);
+ }
+ verg = v1;
+ }
+
+}
+
+void BKE_screen_remove_double_scredges(bScreen *sc)
+{
+ ScrEdge *verg, *se, *sn;
+
+ /* compare */
+ verg = sc->edgebase.first;
+ while (verg) {
+ se = verg->next;
+ while (se) {
+ sn = se->next;
+ if (verg->v1 == se->v1 && verg->v2 == se->v2) {
+ BLI_remlink(&sc->edgebase, se);
+ MEM_freeN(se);
+ }
+ se = sn;
+ }
+ verg = verg->next;
+ }
+}
+
+void BKE_screen_remove_unused_scredges(bScreen *sc)
+{
+ ScrEdge *se, *sen;
+ ScrArea *sa;
+ int a = 0;
+
+ /* sets flags when edge is used in area */
+ sa = sc->areabase.first;
+ while (sa) {
+ se = BKE_screen_find_edge(sc, sa->v1, sa->v2);
+ if (se == NULL) printf("error: area %d edge 1 doesn't exist\n", a);
+ else se->flag = 1;
+ se = BKE_screen_find_edge(sc, sa->v2, sa->v3);
+ if (se == NULL) printf("error: area %d edge 2 doesn't exist\n", a);
+ else se->flag = 1;
+ se = BKE_screen_find_edge(sc, sa->v3, sa->v4);
+ if (se == NULL) printf("error: area %d edge 3 doesn't exist\n", a);
+ else se->flag = 1;
+ se = BKE_screen_find_edge(sc, sa->v4, sa->v1);
+ if (se == NULL) printf("error: area %d edge 4 doesn't exist\n", a);
+ else se->flag = 1;
+ sa = sa->next;
+ a++;
+ }
+ se = sc->edgebase.first;
+ while (se) {
+ sen = se->next;
+ if (se->flag == 0) {
+ BLI_remlink(&sc->edgebase, se);
+ MEM_freeN(se);
+ }
+ else {
+ se->flag = 0;
+ }
+ se = sen;
+ }
+}
+
+void BKE_screen_remove_unused_scrverts(bScreen *sc)
+{
+ ScrVert *sv, *svn;
+ ScrEdge *se;
+
+ /* we assume edges are ok */
+
+ se = sc->edgebase.first;
+ while (se) {
+ se->v1->flag = 1;
+ se->v2->flag = 1;
+ se = se->next;
+ }
+
+ sv = sc->vertbase.first;
+ while (sv) {
+ svn = sv->next;
+ if (sv->flag == 0) {
+ BLI_remlink(&sc->vertbase, sv);
+ MEM_freeN(sv);
+ }
+ else {
+ sv->flag = 0;
+ }
+ sv = svn;
+ }
+}
+
/* ***************** Utilities ********************** */
/* Find a region of the specified type from the given area */
@@ -583,7 +803,7 @@ void BKE_screen_view3d_sync(View3D *v3d, struct Scene *scene)
}
}
-void BKE_screen_view3d_scene_sync(bScreen *sc)
+void BKE_screen_view3d_scene_sync(bScreen *sc, Scene *scene)
{
/* are there cameras in the views that are not in the scene? */
ScrArea *sa;
@@ -592,56 +812,7 @@ void BKE_screen_view3d_scene_sync(bScreen *sc)
for (sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *) sl;
- BKE_screen_view3d_sync(v3d, sc->scene);
- }
- }
- }
-}
-
-void BKE_screen_view3d_main_sync(ListBase *screen_lb, Scene *scene)
-{
- bScreen *sc;
- ScrArea *sa;
- SpaceLink *sl;
-
- /* from scene copy to the other views */
- for (sc = screen_lb->first; sc; sc = sc->id.next) {
- if (sc->scene != scene)
- continue;
-
- for (sa = sc->areabase.first; sa; sa = sa->next)
- for (sl = sa->spacedata.first; sl; sl = sl->next)
- if (sl->spacetype == SPACE_VIEW3D)
- BKE_screen_view3d_sync((View3D *)sl, scene);
- }
-}
-
-void BKE_screen_view3d_twmode_remove(View3D *v3d, const int i)
-{
- const int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
- if (selected_index == i) {
- v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
- }
- else if (selected_index > i) {
- v3d->twmode--;
- }
-}
-
-void BKE_screen_view3d_main_twmode_remove(ListBase *screen_lb, Scene *scene, const int i)
-{
- bScreen *sc;
-
- for (sc = screen_lb->first; sc; sc = sc->id.next) {
- if (sc->scene == scene) {
- ScrArea *sa;
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl;
- for (sl = sa->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_VIEW3D) {
- View3D *v3d = (View3D *)sl;
- BKE_screen_view3d_twmode_remove(v3d, i);
- }
- }
+ BKE_screen_view3d_sync(v3d, scene);
}
}
}
@@ -665,25 +836,12 @@ float BKE_screen_view3d_zoom_from_fac(float zoomfac)
return ((sqrtf(4.0f * zoomfac) - (float)M_SQRT2) * 50.0f);
}
-void BKE_screen_gpu_fx_validate(GPUFXSettings *fx_settings)
+bool BKE_screen_is_fullscreen_area(const bScreen *screen)
{
- /* currently we use DOF from the camera _only_,
- * so we never allocate this, only copy from the Camera */
-#if 0
- if ((fx_settings->dof == NULL) &&
- (fx_settings->fx_flag & GPU_FX_FLAG_DOF))
- {
- GPUDOFSettings *fx_dof;
- fx_dof = fx_settings->dof = MEM_callocN(sizeof(GPUDOFSettings), __func__);
- }
-#endif
-
- if ((fx_settings->ssao == NULL) &&
- (fx_settings->fx_flag & GPU_FX_FLAG_SSAO))
- {
- GPUSSAOSettings *fx_ssao;
- fx_ssao = fx_settings->ssao = MEM_callocN(sizeof(GPUSSAOSettings), __func__);
+ return ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL);
+}
- GPU_fx_compositor_init_ssao_settings(fx_ssao);
- }
+bool BKE_screen_is_used(const bScreen *screen)
+{
+ return (screen->winid != 0);
}
diff --git a/source/blender/blenkernel/intern/sequencer.c b/source/blender/blenkernel/intern/sequencer.c
index 0cc151c3645..a282f535df6 100644
--- a/source/blender/blenkernel/intern/sequencer.c
+++ b/source/blender/blenkernel/intern/sequencer.c
@@ -63,9 +63,9 @@
#include "BLT_translation.h"
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_sequencer.h"
#include "BKE_movieclip.h"
@@ -75,6 +75,9 @@
#include "BKE_library.h"
#include "BKE_idprop.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "RNA_access.h"
#include "RE_pipeline.h"
@@ -89,8 +92,10 @@
#include "BKE_context.h"
#include "BKE_sound.h"
+#include "RE_engine.h"
+
#ifdef WITH_AUDASPACE
-# include AUD_SPECIAL_H
+# include <AUD_Special.h>
#endif
/* mutable state for sequencer */
@@ -588,17 +593,16 @@ void BKE_sequencer_pixel_from_sequencer_space_v4(struct Scene *scene, float pixe
/*********************** sequencer pipeline functions *************************/
void BKE_sequencer_new_render_data(
- EvaluationContext *eval_ctx,
Main *bmain, Scene *scene, int rectx, int recty,
- int preview_render_size,
+ int preview_render_size, int for_render,
SeqRenderData *r_context)
{
- r_context->eval_ctx = eval_ctx;
r_context->bmain = bmain;
r_context->scene = scene;
r_context->rectx = rectx;
r_context->recty = recty;
r_context->preview_render_size = preview_render_size;
+ r_context->for_render = for_render;
r_context->motion_blur_samples = 0;
r_context->motion_blur_shutter = 0;
r_context->skip_cache = false;
@@ -2031,9 +2035,10 @@ void BKE_sequencer_proxy_rebuild(SeqIndexBuildContext *context, short *stop, sho
/* fail safe code */
BKE_sequencer_new_render_data(
- bmain->eval_ctx, bmain, context->scene,
+ bmain, context->scene,
(scene->r.size * (float) scene->r.xsch) / 100.0f + 0.5f,
(scene->r.size * (float) scene->r.ysch) / 100.0f + 0.5f, 100,
+ false,
&render_context);
render_context.skip_cache = true;
@@ -2753,17 +2758,12 @@ static ImBuf *seq_render_effect_strip_impl(
if (seq->flag & SEQ_USE_EFFECT_DEFAULT_FADE) {
sh.get_default_fac(seq, cfra, &fac, &facf);
-
- if ((scene->r.mode & R_FIELDS) == 0)
- facf = fac;
+ facf = fac;
}
else {
fcu = id_data_find_fcurve(&scene->id, seq, &RNA_Sequence, "effect_fader", 0, NULL);
if (fcu) {
fac = facf = evaluate_fcurve(fcu, cfra);
- if (scene->r.mode & R_FIELDS) {
- facf = evaluate_fcurve(fcu, cfra + 0.5f);
- }
}
else {
fac = facf = seq->effect_fader;
@@ -3268,6 +3268,11 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
// have_seq = (scene->r.scemode & R_DOSEQ) && scene->ed && scene->ed->seqbase.first); /* UNUSED */
have_comp = (scene->r.scemode & R_DOCOMP) && scene->use_nodes && scene->nodetree;
+ /* Get view layer for the strip. */
+ ViewLayer *view_layer = BKE_view_layer_default_render(scene);
+ /* Depsgraph will be NULL when doing rendering. */
+ Depsgraph *depsgraph = NULL;
+
orig_data.scemode = scene->r.scemode;
orig_data.cfra = scene->r.cfra;
orig_data.subframe = scene->r.subframe;
@@ -3323,12 +3328,16 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
context->scene->r.seq_prev_type = 3 /* == OB_SOLID */;
/* opengl offscreen render */
- BKE_scene_update_for_newframe(context->eval_ctx, context->bmain, scene, scene->lay);
+ depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+ BKE_scene_graph_update_for_newframe(depsgraph, context->bmain);
ibuf = sequencer_view3d_cb(
/* set for OpenGL render (NULL when scrubbing) */
- scene, camera, width, height, IB_rect, draw_flags, context->scene->r.seq_prev_type,
+ depsgraph, scene,
+ context->scene->r.seq_prev_type,
+ camera, width, height, IB_rect,
+ draw_flags,
scene->r.alphamode, context->gpu_samples, viewname,
- context->gpu_fx, context->gpu_offscreen, err_out);
+ context->gpu_offscreen, err_out);
if (ibuf == NULL) {
fprintf(stderr, "seq_render_scene_strip failed to get opengl buffer: %s\n", err_out);
}
@@ -3349,12 +3358,11 @@ static ImBuf *seq_render_scene_strip(const SeqRenderData *context, Sequence *seq
* When rendering from command line renderer is called from main thread, in this
* case it's always safe to render scene here
*/
- if (!is_thread_main || is_rendering == false || is_background || context->eval_ctx->mode == DAG_EVAL_RENDER) {
+ if (!is_thread_main || is_rendering == false || is_background || context->for_render) {
if (re == NULL)
re = RE_NewSceneRender(scene);
- BKE_scene_update_for_newframe(context->eval_ctx, context->bmain, scene, scene->lay);
- RE_BlenderFrame(re, context->bmain, scene, NULL, camera, scene->lay, frame, false);
+ RE_BlenderFrame(re, context->bmain, scene, view_layer, camera, scene->lay, frame, false);
/* restore previous state after it was toggled on & off by RE_BlenderFrame */
G.is_rendering = is_rendering;
@@ -3412,8 +3420,8 @@ finally:
scene->r.cfra = orig_data.cfra;
scene->r.subframe = orig_data.subframe;
- if (is_frame_update) {
- BKE_scene_update_for_newframe(context->eval_ctx, context->bmain, scene, scene->lay);
+ if (is_frame_update && (depsgraph != NULL)) {
+ BKE_scene_graph_update_for_newframe(depsgraph, context->bmain);
}
#ifdef DURIAN_CAMERA_SWITCH
diff --git a/source/blender/blenkernel/intern/sketch.c b/source/blender/blenkernel/intern/sketch.c
deleted file mode 100644
index 6f5c264f658..00000000000
--- a/source/blender/blenkernel/intern/sketch.c
+++ /dev/null
@@ -1,555 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/blenkernel/intern/sketch.c
- * \ingroup bke
- */
-
-
-#include <string.h>
-#include <math.h>
-#include <float.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_sketch.h"
-
-
-#include "DNA_userdef_types.h"
-
-void freeSketch(SK_Sketch *sketch)
-{
- SK_Stroke *stk, *next;
-
- for (stk = sketch->strokes.first; stk; stk = next) {
- next = stk->next;
-
- sk_freeStroke(stk);
- }
-
- MEM_freeN(sketch);
-}
-
-SK_Sketch *createSketch(void)
-{
- SK_Sketch *sketch;
-
- sketch = MEM_callocN(sizeof(SK_Sketch), "SK_Sketch");
-
- sketch->active_stroke = NULL;
- sketch->gesture = NULL;
-
- BLI_listbase_clear(&sketch->strokes);
-
- return sketch;
-}
-
-void sk_initPoint(SK_Point *pt, SK_DrawData *dd, const float no[3])
-{
- if (no) {
- normalize_v3_v3(pt->no, no);
- }
- else {
- pt->no[0] = 0.0f;
- pt->no[1] = 0.0f;
- pt->no[2] = 1.0f;
- }
- pt->p2d[0] = dd->mval[0];
- pt->p2d[1] = dd->mval[1];
-
- pt->size = 0.0f;
- pt->type = PT_CONTINUOUS;
- pt->mode = PT_SNAP;
- /* more init code here */
-}
-
-void sk_copyPoint(SK_Point *dst, SK_Point *src)
-{
- memcpy(dst, src, sizeof(SK_Point));
-}
-
-void sk_allocStrokeBuffer(SK_Stroke *stk)
-{
- stk->points = MEM_callocN(sizeof(SK_Point) * stk->buf_size, "SK_Point buffer");
-}
-
-void sk_freeStroke(SK_Stroke *stk)
-{
- MEM_freeN(stk->points);
- MEM_freeN(stk);
-}
-
-SK_Stroke *sk_createStroke(void)
-{
- SK_Stroke *stk;
-
- stk = MEM_callocN(sizeof(SK_Stroke), "SK_Stroke");
-
- stk->selected = 0;
- stk->nb_points = 0;
- stk->buf_size = SK_Stroke_BUFFER_INIT_SIZE;
-
- sk_allocStrokeBuffer(stk);
-
- return stk;
-}
-
-void sk_shrinkStrokeBuffer(SK_Stroke *stk)
-{
- if (stk->nb_points < stk->buf_size) {
- SK_Point *old_points = stk->points;
-
- stk->buf_size = stk->nb_points;
-
- sk_allocStrokeBuffer(stk);
-
- memcpy(stk->points, old_points, sizeof(SK_Point) * stk->nb_points);
-
- MEM_freeN(old_points);
- }
-}
-
-void sk_growStrokeBuffer(SK_Stroke *stk)
-{
- if (stk->nb_points == stk->buf_size) {
- SK_Point *old_points = stk->points;
-
- stk->buf_size *= 2;
-
- sk_allocStrokeBuffer(stk);
-
- memcpy(stk->points, old_points, sizeof(SK_Point) * stk->nb_points);
-
- MEM_freeN(old_points);
- }
-}
-
-void sk_growStrokeBufferN(SK_Stroke *stk, int n)
-{
- if (stk->nb_points + n > stk->buf_size) {
- SK_Point *old_points = stk->points;
-
- while (stk->nb_points + n > stk->buf_size) {
- stk->buf_size *= 2;
- }
-
- sk_allocStrokeBuffer(stk);
-
- memcpy(stk->points, old_points, sizeof(SK_Point) * stk->nb_points);
-
- MEM_freeN(old_points);
- }
-}
-
-
-void sk_replaceStrokePoint(SK_Stroke *stk, SK_Point *pt, int n)
-{
- memcpy(stk->points + n, pt, sizeof(SK_Point));
-}
-
-void sk_insertStrokePoint(SK_Stroke *stk, SK_Point *pt, int n)
-{
- int size = stk->nb_points - n;
-
- sk_growStrokeBuffer(stk);
-
- memmove(stk->points + n + 1, stk->points + n, size * sizeof(SK_Point));
-
- memcpy(stk->points + n, pt, sizeof(SK_Point));
-
- stk->nb_points++;
-}
-
-void sk_appendStrokePoint(SK_Stroke *stk, SK_Point *pt)
-{
- sk_growStrokeBuffer(stk);
-
- memcpy(stk->points + stk->nb_points, pt, sizeof(SK_Point));
-
- stk->nb_points++;
-}
-
-void sk_insertStrokePoints(SK_Stroke *stk, SK_Point *pts, int len, int start, int end)
-{
- int size = end - start;
-
- sk_growStrokeBufferN(stk, len - size);
-
- if (len != size) {
- int tail_size = stk->nb_points - end;
-
- memmove(stk->points + start + len, stk->points + end, tail_size * sizeof(SK_Point));
- }
-
- memcpy(stk->points + start, pts, len * sizeof(SK_Point));
-
- stk->nb_points += len - size;
-}
-
-void sk_trimStroke(SK_Stroke *stk, int start, int end)
-{
- int size = end - start + 1;
-
- if (start > 0) {
- memmove(stk->points, stk->points + start, size * sizeof(SK_Point));
- }
-
- stk->nb_points = size;
-}
-
-void sk_straightenStroke(SK_Stroke *stk, int start, int end, float p_start[3], float p_end[3])
-{
- SK_Point pt1, pt2;
- SK_Point *prev, *next;
- float delta_p[3];
- int i, total;
-
- total = end - start;
-
- sub_v3_v3v3(delta_p, p_end, p_start);
-
- prev = stk->points + start;
- next = stk->points + end;
-
- copy_v3_v3(pt1.p, p_start);
- copy_v3_v3(pt1.no, prev->no);
- pt1.mode = prev->mode;
- pt1.type = prev->type;
-
- copy_v3_v3(pt2.p, p_end);
- copy_v3_v3(pt2.no, next->no);
- pt2.mode = next->mode;
- pt2.type = next->type;
-
- sk_insertStrokePoint(stk, &pt1, start + 1); /* insert after start */
- sk_insertStrokePoint(stk, &pt2, end + 1); /* insert before end (since end was pushed back already) */
-
- for (i = 1; i < total; i++) {
- float delta = (float)i / (float)total;
- float *p = stk->points[start + 1 + i].p;
-
- mul_v3_v3fl(p, delta_p, delta);
- add_v3_v3(p, p_start);
- }
-}
-
-void sk_polygonizeStroke(SK_Stroke *stk, int start, int end)
-{
- int offset;
- int i;
-
- /* find first exact points outside of range */
- for (; start > 0; start--) {
- if (stk->points[start].type == PT_EXACT) {
- break;
- }
- }
-
- for (; end < stk->nb_points - 1; end++) {
- if (stk->points[end].type == PT_EXACT) {
- break;
- }
- }
-
- offset = start + 1;
-
- for (i = start + 1; i < end; i++) {
- if (stk->points[i].type == PT_EXACT) {
- if (offset != i) {
- memcpy(stk->points + offset, stk->points + i, sizeof(SK_Point));
- }
-
- offset++;
- }
- }
-
- /* some points were removes, move end of array */
- if (offset < end) {
- int size = stk->nb_points - end;
- memmove(stk->points + offset, stk->points + end, size * sizeof(SK_Point));
- stk->nb_points = offset + size;
- }
-}
-
-void sk_flattenStroke(SK_Stroke *stk, int start, int end)
-{
- float normal[3], distance[3];
- float limit;
- int i, total;
-
- total = end - start + 1;
-
- copy_v3_v3(normal, stk->points[start].no);
-
- sub_v3_v3v3(distance, stk->points[end].p, stk->points[start].p);
- project_v3_v3v3(normal, distance, normal);
- limit = normalize_v3(normal);
-
- for (i = 1; i < total - 1; i++) {
- float d = limit * i / total;
- float offset[3];
- float *p = stk->points[start + i].p;
-
- sub_v3_v3v3(distance, p, stk->points[start].p);
- project_v3_v3v3(distance, distance, normal);
-
- copy_v3_v3(offset, normal);
- mul_v3_fl(offset, d);
-
- sub_v3_v3(p, distance);
- add_v3_v3(p, offset);
- }
-}
-
-void sk_removeStroke(SK_Sketch *sketch, SK_Stroke *stk)
-{
- if (sketch->active_stroke == stk) {
- sketch->active_stroke = NULL;
- }
-
- BLI_remlink(&sketch->strokes, stk);
- sk_freeStroke(stk);
-}
-
-void sk_reverseStroke(SK_Stroke *stk)
-{
- SK_Point *old_points = stk->points;
- int i = 0;
-
- sk_allocStrokeBuffer(stk);
-
- for (i = 0; i < stk->nb_points; i++) {
- sk_copyPoint(stk->points + i, old_points + stk->nb_points - 1 - i);
- }
-
- MEM_freeN(old_points);
-}
-
-
-/* Ramer-Douglas-Peucker algorithm for line simplification */
-void sk_filterStroke(SK_Stroke *stk, int start, int end)
-{
- SK_Point *old_points = stk->points;
- int nb_points = stk->nb_points;
- char *marked = NULL;
- char work;
- int i;
-
- if (start == -1) {
- start = 0;
- end = stk->nb_points - 1;
- }
-
- sk_allocStrokeBuffer(stk);
- stk->nb_points = 0;
-
- /* adding points before range */
- for (i = 0; i < start; i++) {
- sk_appendStrokePoint(stk, old_points + i);
- }
-
- marked = MEM_callocN(nb_points, "marked array");
- marked[start] = 1;
- marked[end] = 1;
-
- work = 1;
-
- /* while still reducing */
- while (work) {
- int ls, le;
- work = 0;
-
- ls = start;
- le = start + 1;
-
- /* while not over interval */
- while (ls < end) {
- int max_i = 0;
- short v1[2];
- float max_dist = 16; /* more than 4 pixels */
-
- /* find the next marked point */
- while (marked[le] == 0) {
- le++;
- }
-
- /* perpendicular vector to ls-le */
- v1[1] = old_points[le].p2d[0] - old_points[ls].p2d[0];
- v1[0] = old_points[ls].p2d[1] - old_points[le].p2d[1];
-
-
- for (i = ls + 1; i < le; i++) {
- float mul;
- float dist;
- short v2[2];
-
- v2[0] = old_points[i].p2d[0] - old_points[ls].p2d[0];
- v2[1] = old_points[i].p2d[1] - old_points[ls].p2d[1];
-
- if (v2[0] == 0 && v2[1] == 0) {
- continue;
- }
-
- mul = (float)(v1[0] * v2[0] + v1[1] * v2[1]) / (float)(v2[0] * v2[0] + v2[1] * v2[1]);
-
- dist = mul * mul * (v2[0] * v2[0] + v2[1] * v2[1]);
-
- if (dist > max_dist) {
- max_dist = dist;
- max_i = i;
- }
- }
-
- if (max_i != 0) {
- work = 1;
- marked[max_i] = 1;
- }
-
- ls = le;
- le = ls + 1;
- }
- }
-
-
- /* adding points after range */
- for (i = start; i <= end; i++) {
- if (marked[i]) {
- sk_appendStrokePoint(stk, old_points + i);
- }
- }
-
- MEM_freeN(marked);
-
- /* adding points after range */
- for (i = end + 1; i < nb_points; i++) {
- sk_appendStrokePoint(stk, old_points + i);
- }
-
- MEM_freeN(old_points);
-
- sk_shrinkStrokeBuffer(stk);
-}
-
-
-void sk_filterLastContinuousStroke(SK_Stroke *stk)
-{
- int start, end;
-
- end = stk->nb_points - 1;
-
- for (start = end - 1; start > 0 && stk->points[start].type == PT_CONTINUOUS; start--) {
- /* nothing to do here*/
- }
-
- if (end - start > 1) {
- sk_filterStroke(stk, start, end);
- }
-}
-
-SK_Point *sk_lastStrokePoint(SK_Stroke *stk)
-{
- SK_Point *pt = NULL;
-
- if (stk->nb_points > 0) {
- pt = stk->points + (stk->nb_points - 1);
- }
-
- return pt;
-}
-
-void sk_endContinuousStroke(SK_Stroke *stk)
-{
- stk->points[stk->nb_points - 1].type = PT_EXACT;
-}
-
-void sk_updateNextPoint(SK_Sketch *sketch, SK_Stroke *stk)
-{
- if (stk) {
- memcpy(&(sketch->next_point), &(stk->points[stk->nb_points - 1]), sizeof(SK_Point));
- }
-}
-
-int sk_stroke_filtermval(SK_DrawData *dd)
-{
- int retval = 0;
- if (ABS(dd->mval[0] - dd->previous_mval[0]) + ABS(dd->mval[1] - dd->previous_mval[1]) > U.gp_manhattendist) {
- retval = 1;
- }
-
- return retval;
-}
-
-void sk_initDrawData(SK_DrawData *dd, const int mval[2])
-{
- dd->mval[0] = mval[0];
- dd->mval[1] = mval[1];
- dd->previous_mval[0] = -1;
- dd->previous_mval[1] = -1;
- dd->type = PT_EXACT;
-}
-
-
-void sk_deleteSelectedStrokes(SK_Sketch *sketch)
-{
- SK_Stroke *stk, *next;
-
- for (stk = sketch->strokes.first; stk; stk = next) {
- next = stk->next;
-
- if (stk->selected == 1) {
- sk_removeStroke(sketch, stk);
- }
- }
-}
-
-void sk_selectAllSketch(SK_Sketch *sketch, int mode)
-{
- SK_Stroke *stk = NULL;
-
- if (mode == -1) {
- for (stk = sketch->strokes.first; stk; stk = stk->next) {
- stk->selected = 0;
- }
- }
- else if (mode == 0) {
- for (stk = sketch->strokes.first; stk; stk = stk->next) {
- stk->selected = 1;
- }
- }
- else if (mode == 1) {
- int selected = 1;
-
- for (stk = sketch->strokes.first; stk; stk = stk->next) {
- selected &= stk->selected;
- }
-
- selected ^= 1;
-
- for (stk = sketch->strokes.first; stk; stk = stk->next) {
- stk->selected = selected;
- }
- }
-}
diff --git a/source/blender/blenkernel/intern/smoke.c b/source/blender/blenkernel/intern/smoke.c
index 699f546bbef..2c601e9429a 100644
--- a/source/blender/blenkernel/intern/smoke.c
+++ b/source/blender/blenkernel/intern/smoke.c
@@ -82,6 +82,9 @@
#include "BKE_smoke.h"
#include "BKE_texture.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "RE_shader_ext.h"
#include "GPU_glew.h"
@@ -125,7 +128,7 @@ void smoke_initWaveletBlenderRNA(struct WTURBULENCE *UNUSED(wt), float *UNUSED(s
void smoke_initBlenderRNA(struct FLUID_3D *UNUSED(fluid), float *UNUSED(alpha), float *UNUSED(beta), float *UNUSED(dt_factor), float *UNUSED(vorticity),
int *UNUSED(border_colli), float *UNUSED(burning_rate), float *UNUSED(flame_smoke), float *UNUSED(flame_smoke_color),
float *UNUSED(flame_vorticity), float *UNUSED(flame_ignition_temp), float *UNUSED(flame_max_temp)) {}
-struct DerivedMesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), Scene *UNUSED(scene), Object *UNUSED(ob), DerivedMesh *UNUSED(dm)) { return NULL; }
+struct DerivedMesh *smokeModifier_do(SmokeModifierData *UNUSED(smd), struct Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *UNUSED(ob), DerivedMesh *UNUSED(dm)) { return NULL; }
float smoke_get_velocity_at(struct Object *UNUSED(ob), float UNUSED(position[3]), float UNUSED(velocity[3])) { return 0.0f; }
#endif /* WITH_SMOKE */
@@ -694,16 +697,16 @@ void smokeModifier_copy(struct SmokeModifierData *smd, struct SmokeModifierData
#ifdef WITH_SMOKE
// forward decleration
-static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene);
+static void smoke_calc_transparency(SmokeDomainSettings *sds, ViewLayer *view_layer);
static float calc_voxel_transp(float *result, float *input, int res[3], int *pixel, float *tRay, float correct);
-static int get_lamp(Scene *scene, float *light)
+static int get_lamp(ViewLayer *view_layer, float *light)
{
Base *base_tmp = NULL;
int found_lamp = 0;
// try to find a lamp, preferably local
- for (base_tmp = scene->base.first; base_tmp; base_tmp = base_tmp->next) {
+ for (base_tmp = FIRSTBASE(view_layer); base_tmp; base_tmp = base_tmp->next) {
if (base_tmp->object->type == OB_LAMP) {
Lamp *la = base_tmp->object->data;
@@ -2104,7 +2107,7 @@ BLI_INLINE void apply_inflow_fields(SmokeFlowSettings *sfs, float emission_value
}
}
-static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt)
+static void update_flowsfluids(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float dt)
{
Object **flowobjs = NULL;
EmissionMap *emaps = NULL;
@@ -2211,7 +2214,7 @@ static void update_flowsfluids(Scene *scene, Object *ob, SmokeDomainSettings *sd
else { /* MOD_SMOKE_FLOW_SOURCE_MESH */
/* update flow object frame */
BLI_mutex_lock(&object_update_lock);
- BKE_object_modifier_update_subframe(scene, collob, true, 5, BKE_scene_frame_get(scene), eModifierType_Smoke);
+ BKE_object_modifier_update_subframe(depsgraph, scene, collob, true, 5, BKE_scene_frame_get(scene), eModifierType_Smoke);
BLI_mutex_unlock(&object_update_lock);
/* apply flow */
@@ -2523,12 +2526,12 @@ static void update_effectors_task_cb(
}
}
-static void update_effectors(Scene *scene, Object *ob, SmokeDomainSettings *sds, float UNUSED(dt))
+static void update_effectors(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeDomainSettings *sds, float UNUSED(dt))
{
ListBase *effectors;
/* make sure smoke flow influence is 0.0f */
sds->effector_weights->weight[PFIELD_SMOKEFLOW] = 0.0f;
- effectors = pdInitEffectors(scene, ob, NULL, sds->effector_weights, true);
+ effectors = pdInitEffectors(depsgraph, scene, ob, NULL, sds->effector_weights, true);
if (effectors) {
// precalculate wind forces
@@ -2558,7 +2561,7 @@ static void update_effectors(Scene *scene, Object *ob, SmokeDomainSettings *sds,
pdEndEffectors(&effectors);
}
-static void step(Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh *domain_dm, float fps)
+static void step(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh *domain_dm, float fps)
{
SmokeDomainSettings *sds = smd->domain;
/* stability values copied from wturbulence.cpp */
@@ -2628,11 +2631,11 @@ static void step(Scene *scene, Object *ob, SmokeModifierData *smd, DerivedMesh *
for (substep = 0; substep < totalSubsteps; substep++)
{
// calc animated obstacle velocities
- update_flowsfluids(scene, ob, sds, dtSubdiv);
+ update_flowsfluids(depsgraph, scene, ob, sds, dtSubdiv);
update_obstacles(scene, ob, sds, dtSubdiv, substep, totalSubsteps);
if (sds->total_cells > 1) {
- update_effectors(scene, ob, sds, dtSubdiv); // DG TODO? problem --> uses forces instead of velocity, need to check how they need to be changed with variable dt
+ update_effectors(depsgraph, scene, ob, sds, dtSubdiv); // DG TODO? problem --> uses forces instead of velocity, need to check how they need to be changed with variable dt
smoke_step(sds->fluid, gravity, dtSubdiv);
}
}
@@ -2725,7 +2728,8 @@ static DerivedMesh *createDomainGeometry(SmokeDomainSettings *sds, Object *ob)
return result;
}
-static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm)
+static void smokeModifier_process(
+ SmokeModifierData *smd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm)
{
if ((smd->type & MOD_SMOKE_TYPE_FLOW))
{
@@ -2846,11 +2850,11 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
}
- step(scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base);
+ step(depsgraph, scene, ob, smd, dm, scene->r.frs_sec / scene->r.frs_sec_base);
}
// create shadows before writing cache so they get stored
- smoke_calc_transparency(sds, scene);
+ smoke_calc_transparency(sds, DEG_get_evaluated_view_layer(depsgraph));
if (sds->wt && sds->total_cells > 1) {
smoke_turbulence_step(sds->wt, sds->fluid);
@@ -2867,13 +2871,14 @@ static void smokeModifier_process(SmokeModifierData *smd, Scene *scene, Object *
}
}
-struct DerivedMesh *smokeModifier_do(SmokeModifierData *smd, Scene *scene, Object *ob, DerivedMesh *dm)
+struct DerivedMesh *smokeModifier_do(
+ SmokeModifierData *smd, struct Depsgraph *depsgraph, Scene *scene, Object *ob, DerivedMesh *dm)
{
/* lock so preview render does not read smoke data while it gets modified */
if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
BLI_rw_mutex_lock(smd->domain->fluid_mutex, THREAD_LOCK_WRITE);
- smokeModifier_process(smd, scene, ob, dm);
+ smokeModifier_process(smd, depsgraph, scene, ob, dm);
if ((smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain)
BLI_rw_mutex_unlock(smd->domain->fluid_mutex);
@@ -2988,7 +2993,7 @@ static void bresenham_linie_3D(int x1, int y1, int z1, int x2, int y2, int z2, f
cb(result, input, res, pixel, tRay, correct);
}
-static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene)
+static void smoke_calc_transparency(SmokeDomainSettings *sds, ViewLayer *view_layer)
{
float bv[6] = {0};
float light[3];
@@ -2996,7 +3001,7 @@ static void smoke_calc_transparency(SmokeDomainSettings *sds, Scene *scene)
float *density = smoke_get_density(sds->fluid);
float correct = -7.0f * sds->dx;
- if (!get_lamp(scene, light)) return;
+ if (!get_lamp(view_layer, light)) return;
/* convert light pos to sim cell space */
mul_m4_v3(sds->imat, light);
diff --git a/source/blender/blenkernel/intern/softbody.c b/source/blender/blenkernel/intern/softbody.c
index c3527af90ca..0af400796a4 100644
--- a/source/blender/blenkernel/intern/softbody.c
+++ b/source/blender/blenkernel/intern/softbody.c
@@ -74,6 +74,7 @@ variables on the UI for now
#include "BKE_curve.h"
#include "BKE_effect.h"
#include "BKE_global.h"
+#include "BKE_group.h"
#include "BKE_modifier.h"
#include "BKE_softbody.h"
#include "BKE_pointcache.h"
@@ -81,6 +82,9 @@ variables on the UI for now
#include "BKE_mesh.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "PIL_time.h"
/* callbacks for errors and interrupts and some goo */
@@ -512,35 +516,26 @@ static void ccd_build_deflector_hash_single(GHash *hash, Object *ob)
/**
* \note group overrides scene when not NULL.
*/
-static void ccd_build_deflector_hash(Scene *scene, Group *group, Object *vertexowner, GHash *hash)
+static void ccd_build_deflector_hash(ViewLayer *view_layer, Group *group, Object *vertexowner, GHash *hash)
{
Object *ob;
if (!hash) return;
+ /* Explicit collision group. */
if (group) {
- /* Explicit collision group */
- for (GroupObject *go = group->gobject.first; go; go = go->next) {
- ob = go->ob;
-
- if (ob == vertexowner || ob->type != OB_MESH)
- continue;
-
- ccd_build_deflector_hash_single(hash, ob);
- }
+ view_layer = group->view_layer;
}
- else {
- for (Base *base = scene->base.first; base; base = base->next) {
- /*Only proceed for mesh object in same layer */
- if (base->object->type == OB_MESH && (base->lay & vertexowner->lay)) {
- ob= base->object;
- if ((vertexowner) && (ob == vertexowner)) {
- /* if vertexowner is given we don't want to check collision with owner object */
- continue;
- }
- ccd_build_deflector_hash_single(hash, ob);
+ for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
+ /* Only proceed for mesh object in same layer. */
+ if (base->object->type == OB_MESH) {
+ ob = base->object;
+ if (ob == vertexowner) {
+ /* If vertexowner is given we don't want to check collision with owner object. */
+ continue;
}
+ ccd_build_deflector_hash_single(hash, ob);
}
}
}
@@ -558,37 +553,29 @@ static void ccd_update_deflector_hash_single(GHash *hash, Object *ob)
/**
* \note group overrides scene when not NULL.
*/
-static void ccd_update_deflector_hash(Scene *scene, Group *group, Object *vertexowner, GHash *hash)
+static void ccd_update_deflector_hash(ViewLayer *view_layer, Group *group, Object *vertexowner, GHash *hash)
{
Object *ob;
if ((!hash) || (!vertexowner)) return;
+ /* Explicit collision group. */
if (group) {
- /* Explicit collision group */
- for (GroupObject *go = group->gobject.first; go; go = go->next) {
- ob = go->ob;
+ view_layer = group->view_layer;
+ }
- if (ob == vertexowner || ob->type != OB_MESH)
+ for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
+ /* Only proceed for mesh object in same layer. */
+ if (base->object->type == OB_MESH) {
+ ob = base->object;
+ if (ob == vertexowner) {
+ /* If vertexowner is given we don't want to check collision with owner object. */
continue;
+ }
ccd_update_deflector_hash_single(hash, ob);
}
}
- else {
- for (Base *base = scene->base.first; base; base = base->next) {
- /*Only proceed for mesh object in same layer */
- if (base->object->type == OB_MESH && (base->lay & vertexowner->lay)) {
- ob= base->object;
- if (ob == vertexowner) {
- /* if vertexowner is given we don't want to check collision with owner object */
- continue;
- }
-
- ccd_update_deflector_hash_single(hash, ob);
- }
- }
- }
}
@@ -979,29 +966,21 @@ static void free_softbody_intern(SoftBody *sb)
/**
* \note group overrides scene when not NULL.
*/
-static bool are_there_deflectors(Scene *scene, Group *group, unsigned int layer)
+static bool are_there_deflectors(ViewLayer *view_layer)
{
- if (group) {
- for (GroupObject *go = group->gobject.first; go; go = go->next) {
- if (go->ob->pd && go->ob->pd->deflect)
+ for (Base *base = FIRSTBASE(view_layer); base; base = base->next) {
+ if (base->object->pd) {
+ if (base->object->pd->deflect)
return 1;
}
}
- else {
- for (Base *base = scene->base.first; base; base= base->next) {
- if ( (base->lay & layer) && base->object->pd) {
- if (base->object->pd->deflect)
- return 1;
- }
- }
- }
return 0;
}
-static int query_external_colliders(Scene *scene, Group *group, Object *me)
+static int query_external_colliders(ViewLayer *view_layer, Group *group)
{
- return(are_there_deflectors(scene, group, me->lay));
+ return(are_there_deflectors(group != NULL ? group->view_layer : view_layer));
}
/* --- dependency information functions*/
@@ -1546,12 +1525,12 @@ static void _scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow,
}
-static void scan_for_ext_spring_forces(Scene *scene, Object *ob, float timenow)
+static void scan_for_ext_spring_forces(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float timenow)
{
SoftBody *sb = ob->soft;
ListBase *do_effector = NULL;
- do_effector = pdInitEffectors(scene, ob, NULL, sb->effector_weights, true);
+ do_effector = pdInitEffectors(depsgraph, scene, ob, NULL, sb->effector_weights, true);
_scan_for_ext_spring_forces(scene, ob, timenow, 0, sb->totspring, do_effector);
pdEndEffectors(&do_effector);
}
@@ -1563,7 +1542,7 @@ static void *exec_scan_for_ext_spring_forces(void *data)
return NULL;
}
-static void sb_sfesf_threads_run(Scene *scene, struct Object *ob, float timenow, int totsprings, int *UNUSED(ptr_to_break_func(void)))
+static void sb_sfesf_threads_run(struct Depsgraph *depsgraph, Scene *scene, struct Object *ob, float timenow, int totsprings, int *UNUSED(ptr_to_break_func(void)))
{
ListBase *do_effector = NULL;
ListBase threads;
@@ -1571,7 +1550,7 @@ static void sb_sfesf_threads_run(Scene *scene, struct Object *ob, float timenow,
int i, totthread, left, dec;
int lowsprings =100; /* wild guess .. may increase with better thread management 'above' or even be UI option sb->spawn_cf_threads_nopts */
- do_effector= pdInitEffectors(scene, ob, NULL, ob->soft->effector_weights, true);
+ do_effector= pdInitEffectors(depsgraph, scene, ob, NULL, ob->soft->effector_weights, true);
/* figure the number of threads while preventing pretty pointless threading overhead */
totthread= BKE_scene_num_threads(scene);
@@ -2229,7 +2208,7 @@ static void sb_cf_threads_run(Scene *scene, Object *ob, float forcetime, float t
MEM_freeN(sb_threads);
}
-static void softbody_calc_forcesEx(Scene *scene, Object *ob, float forcetime, float timenow)
+static void softbody_calc_forcesEx(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow)
{
/* rule we never alter free variables :bp->vec bp->pos in here !
* this will ruin adaptive stepsize AKA heun! (BM)
@@ -2245,7 +2224,7 @@ static void softbody_calc_forcesEx(Scene *scene, Object *ob, float forcetime, fl
/* gravity = sb->grav * sb_grav_force_scale(ob); */ /* UNUSED */
/* check conditions for various options */
- do_deflector= query_external_colliders(scene, sb->collision_group, ob);
+ do_deflector= query_external_colliders(DEG_get_evaluated_view_layer(depsgraph), sb->collision_group);
/* do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF)); */ /* UNUSED */
do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL);
do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES));
@@ -2254,10 +2233,10 @@ static void softbody_calc_forcesEx(Scene *scene, Object *ob, float forcetime, fl
/* bproot= sb->bpoint; */ /* need this for proper spring addressing */ /* UNUSED */
if (do_springcollision || do_aero)
- sb_sfesf_threads_run(scene, ob, timenow, sb->totspring, NULL);
+ sb_sfesf_threads_run(depsgraph, scene, ob, timenow, sb->totspring, NULL);
/* after spring scan because it uses Effoctors too */
- do_effector= pdInitEffectors(scene, ob, NULL, sb->effector_weights, true);
+ do_effector= pdInitEffectors(depsgraph, scene, ob, NULL, sb->effector_weights, true);
if (do_deflector) {
float defforce[3];
@@ -2274,11 +2253,11 @@ static void softbody_calc_forcesEx(Scene *scene, Object *ob, float forcetime, fl
}
-static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, float timenow)
+static void softbody_calc_forces(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float forcetime, float timenow)
{
/* redirection to the new threaded Version */
if (!(G.debug_value & 0x10)) { // 16
- softbody_calc_forcesEx(scene, ob, forcetime, timenow);
+ softbody_calc_forcesEx(depsgraph, scene, ob, forcetime, timenow);
return;
}
else {
@@ -2309,7 +2288,7 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa
}
/* check conditions for various options */
- do_deflector= query_external_colliders(scene, sb->collision_group, ob);
+ do_deflector= query_external_colliders(DEG_get_evaluated_view_layer(depsgraph), sb->collision_group);
do_selfcollision=((ob->softflag & OB_SB_EDGES) && (sb->bspring)&& (ob->softflag & OB_SB_SELF));
do_springcollision=do_deflector && (ob->softflag & OB_SB_EDGES) &&(ob->softflag & OB_SB_EDGECOLL);
do_aero=((sb->aeroedge)&& (ob->softflag & OB_SB_EDGES));
@@ -2317,9 +2296,9 @@ static void softbody_calc_forces(Scene *scene, Object *ob, float forcetime, floa
iks = 1.0f/(1.0f-sb->inspring)-1.0f ;/* inner spring constants function */
/* bproot= sb->bpoint; */ /* need this for proper spring addressing */ /* UNUSED */
- if (do_springcollision || do_aero) scan_for_ext_spring_forces(scene, ob, timenow);
+ if (do_springcollision || do_aero) scan_for_ext_spring_forces(depsgraph, scene, ob, timenow);
/* after spring scan because it uses Effoctors too */
- do_effector= pdInitEffectors(scene, ob, NULL, ob->soft->effector_weights, true);
+ do_effector= pdInitEffectors(depsgraph, scene, ob, NULL, ob->soft->effector_weights, true);
if (do_deflector) {
float defforce[3];
@@ -3506,7 +3485,7 @@ static void softbody_reset(Object *ob, SoftBody *sb, float (*vertexCos)[3], int
}
}
-static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime)
+static void softbody_step(struct Depsgraph *depsgraph, Scene *scene, Object *ob, SoftBody *sb, float dtime)
{
/* the simulator */
float forcetime;
@@ -3520,11 +3499,13 @@ static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime)
*/
if (dtime < 0 || dtime > 10.5f) return;
- ccd_update_deflector_hash(scene, sb->collision_group, ob, sb->scratch->colliderhash);
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+
+ ccd_update_deflector_hash(view_layer, sb->collision_group, ob, sb->scratch->colliderhash);
if (sb->scratch->needstobuildcollider) {
- if (query_external_colliders(scene, sb->collision_group, ob)) {
- ccd_build_deflector_hash(scene, sb->collision_group, ob, sb->scratch->colliderhash);
+ if (query_external_colliders(view_layer, sb->collision_group)) {
+ ccd_build_deflector_hash(view_layer, sb->collision_group, ob, sb->scratch->colliderhash);
}
sb->scratch->needstobuildcollider=0;
}
@@ -3554,12 +3535,12 @@ static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime)
sb->scratch->flag &= ~SBF_DOFUZZY;
/* do predictive euler step */
- softbody_calc_forces(scene, ob, forcetime, timedone/dtime);
+ softbody_calc_forces(depsgraph, scene, ob, forcetime, timedone/dtime);
softbody_apply_forces(ob, forcetime, 1, NULL, mid_flags);
/* crop new slope values to do averaged slope step */
- softbody_calc_forces(scene, ob, forcetime, timedone/dtime);
+ softbody_calc_forces(depsgraph, scene, ob, forcetime, timedone/dtime);
softbody_apply_forces(ob, forcetime, 2, &err, mid_flags);
softbody_apply_goalsnap(ob);
@@ -3640,7 +3621,7 @@ static void softbody_step(Scene *scene, Object *ob, SoftBody *sb, float dtime)
}
/* simulates one step. framenr is in frames */
-void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], int numVerts)
+void sbObjectStep(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], int numVerts)
{
SoftBody *sb= ob->soft;
PointCache *cache;
@@ -3648,7 +3629,6 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
float dtime, timescale;
int framedelta, framenr, startframe, endframe;
int cache_result;
-
cache= sb->pointcache;
framenr= (int)cfra;
@@ -3717,7 +3697,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
}
/* try to read from cache */
- bool can_simulate = (framenr == sb->last_frame+1) && !(cache->flag & PTCACHE_BAKED);
+ bool can_simulate = (framenr == sb->last_frame + 1) && !(cache->flag & PTCACHE_BAKED);
cache_result = BKE_ptcache_read(&pid, (float)framenr+scene->r.subframe, can_simulate);
@@ -3757,7 +3737,7 @@ void sbObjectStep(Scene *scene, Object *ob, float cfra, float (*vertexCos)[3], i
dtime = framedelta*timescale;
/* do simulation */
- softbody_step(scene, ob, sb, dtime);
+ softbody_step(depsgraph, scene, ob, sb, dtime);
softbody_to_object(ob, vertexCos, numVerts, 0);
diff --git a/source/blender/blenkernel/intern/sound.c b/source/blender/blenkernel/intern/sound.c
index 45d1f969d64..747ffdafe8b 100644
--- a/source/blender/blenkernel/intern/sound.c
+++ b/source/blender/blenkernel/intern/sound.c
@@ -48,13 +48,11 @@
#include "DNA_speaker_types.h"
#ifdef WITH_AUDASPACE
-# include AUD_SOUND_H
-# include AUD_SEQUENCE_H
-# include AUD_HANDLE_H
-# include AUD_SPECIAL_H
-# ifdef WITH_SYSTEM_AUDASPACE
-# include "../../../intern/audaspace/intern/AUD_Set.h"
-# endif
+# include <AUD_Sound.h>
+# include <AUD_Sequence.h>
+# include <AUD_Handle.h>
+# include <AUD_Special.h>
+# include "../../../intern/audaspace/intern/AUD_Set.h"
#endif
#include "BKE_global.h"
@@ -228,7 +226,7 @@ void BKE_sound_init_once(void)
atexit(BKE_sound_exit_once);
}
-static AUD_Device *sound_device;
+static AUD_Device *sound_device = NULL;
void *BKE_sound_get_device(void)
{
@@ -237,6 +235,9 @@ void *BKE_sound_get_device(void)
void BKE_sound_init(struct Main *bmain)
{
+ /* Make sure no instance of the sound system is running, otherwise we get leaks. */
+ BKE_sound_exit();
+
AUD_DeviceSpecs specs;
int device, buffersize;
const char *device_name;
@@ -302,7 +303,6 @@ void BKE_sound_exit_once(void)
sound_device = NULL;
AUD_exitOnce();
-#ifdef WITH_SYSTEM_AUDASPACE
if (audio_device_names != NULL) {
int i;
for (i = 0; audio_device_names[i]; i++) {
@@ -311,7 +311,6 @@ void BKE_sound_exit_once(void)
free(audio_device_names);
audio_device_names = NULL;
}
-#endif
}
/* XXX unused currently */
@@ -807,13 +806,76 @@ void BKE_sound_read_waveform(bSound *sound, short *stop)
BLI_spin_unlock(sound->spinlock);
}
-void BKE_sound_update_scene(Main *bmain, struct Scene *scene)
+static void sound_update_base(Scene *scene, Base *base, void *new_set)
{
- Object *ob;
- Base *base;
+ Object *ob = base->object;
NlaTrack *track;
NlaStrip *strip;
Speaker *speaker;
+ float quat[4];
+
+ if ((ob->id.tag & LIB_TAG_DOIT) == 0) {
+ return;
+ }
+
+ ob->id.tag &= ~LIB_TAG_DOIT;
+
+ if ((ob->type != OB_SPEAKER) || !ob->adt) {
+ return;
+ }
+
+ for (track = ob->adt->nla_tracks.first; track; track = track->next) {
+ for (strip = track->strips.first; strip; strip = strip->next) {
+ if (strip->type != NLASTRIP_TYPE_SOUND) {
+ continue;
+ }
+ speaker = (Speaker *)ob->data;
+
+ if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) {
+ if (speaker->sound) {
+ AUD_SequenceEntry_move(strip->speaker_handle, (double)strip->start / FPS, FLT_MAX, 0);
+ }
+ else {
+ AUD_Sequence_remove(scene->sound_scene, strip->speaker_handle);
+ strip->speaker_handle = NULL;
+ }
+ }
+ else {
+ if (speaker->sound) {
+ strip->speaker_handle = AUD_Sequence_add(scene->sound_scene,
+ speaker->sound->playback_handle,
+ (double)strip->start / FPS, FLT_MAX, 0);
+ AUD_SequenceEntry_setRelative(strip->speaker_handle, 0);
+ }
+ }
+
+ if (strip->speaker_handle) {
+ const bool mute = ((strip->flag & NLASTRIP_FLAG_MUTED) || (speaker->flag & SPK_MUTED));
+ AUD_addSet(new_set, strip->speaker_handle);
+ AUD_SequenceEntry_setVolumeMaximum(strip->speaker_handle, speaker->volume_max);
+ AUD_SequenceEntry_setVolumeMinimum(strip->speaker_handle, speaker->volume_min);
+ AUD_SequenceEntry_setDistanceMaximum(strip->speaker_handle, speaker->distance_max);
+ AUD_SequenceEntry_setDistanceReference(strip->speaker_handle, speaker->distance_reference);
+ AUD_SequenceEntry_setAttenuation(strip->speaker_handle, speaker->attenuation);
+ AUD_SequenceEntry_setConeAngleOuter(strip->speaker_handle, speaker->cone_angle_outer);
+ AUD_SequenceEntry_setConeAngleInner(strip->speaker_handle, speaker->cone_angle_inner);
+ AUD_SequenceEntry_setConeVolumeOuter(strip->speaker_handle, speaker->cone_volume_outer);
+
+ mat4_to_quat(quat, ob->obmat);
+ AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1);
+ AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1);
+ AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1);
+ AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1);
+ AUD_SequenceEntry_setSound(strip->speaker_handle, speaker->sound->playback_handle);
+ AUD_SequenceEntry_setMuted(strip->speaker_handle, mute);
+ }
+ }
+ }
+}
+
+void BKE_sound_update_scene(Main *bmain, Scene *scene)
+{
+ Base *base;
Scene *sce_it;
void *new_set = AUD_createSet();
@@ -822,59 +884,18 @@ void BKE_sound_update_scene(Main *bmain, struct Scene *scene)
/* cheap test to skip looping over all objects (no speakers is a common case) */
if (!BLI_listbase_is_empty(&bmain->speaker)) {
- for (SETLOOPER(scene, sce_it, base)) {
- ob = base->object;
- if ((ob->type != OB_SPEAKER) || !ob->adt) {
- continue;
- }
- for (track = ob->adt->nla_tracks.first; track; track = track->next) {
- for (strip = track->strips.first; strip; strip = strip->next) {
- if (strip->type != NLASTRIP_TYPE_SOUND) {
- continue;
- }
- speaker = (Speaker *)ob->data;
-
- if (AUD_removeSet(scene->speaker_handles, strip->speaker_handle)) {
- if (speaker->sound) {
- AUD_SequenceEntry_move(strip->speaker_handle, (double)strip->start / FPS, FLT_MAX, 0);
- }
- else {
- AUD_Sequence_remove(scene->sound_scene, strip->speaker_handle);
- strip->speaker_handle = NULL;
- }
- }
- else {
- if (speaker->sound) {
- strip->speaker_handle = AUD_Sequence_add(scene->sound_scene,
- speaker->sound->playback_handle,
- (double)strip->start / FPS, FLT_MAX, 0);
- AUD_SequenceEntry_setRelative(strip->speaker_handle, 0);
- }
- }
-
- if (strip->speaker_handle) {
- const bool mute = ((strip->flag & NLASTRIP_FLAG_MUTED) || (speaker->flag & SPK_MUTED));
- AUD_addSet(new_set, strip->speaker_handle);
- AUD_SequenceEntry_setVolumeMaximum(strip->speaker_handle, speaker->volume_max);
- AUD_SequenceEntry_setVolumeMinimum(strip->speaker_handle, speaker->volume_min);
- AUD_SequenceEntry_setDistanceMaximum(strip->speaker_handle, speaker->distance_max);
- AUD_SequenceEntry_setDistanceReference(strip->speaker_handle, speaker->distance_reference);
- AUD_SequenceEntry_setAttenuation(strip->speaker_handle, speaker->attenuation);
- AUD_SequenceEntry_setConeAngleOuter(strip->speaker_handle, speaker->cone_angle_outer);
- AUD_SequenceEntry_setConeAngleInner(strip->speaker_handle, speaker->cone_angle_inner);
- AUD_SequenceEntry_setConeVolumeOuter(strip->speaker_handle, speaker->cone_volume_outer);
-
- mat4_to_quat(quat, ob->obmat);
- AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_LOCATION, CFRA, ob->obmat[3], 1);
- AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_ORIENTATION, CFRA, quat, 1);
- AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_VOLUME, CFRA, &speaker->volume, 1);
- AUD_SequenceEntry_setAnimationData(strip->speaker_handle, AUD_AP_PITCH, CFRA, &speaker->pitch, 1);
- AUD_SequenceEntry_setSound(strip->speaker_handle, speaker->sound->playback_handle);
- AUD_SequenceEntry_setMuted(strip->speaker_handle, mute);
- }
- }
+ BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, true);
+
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ sound_update_base(scene, base, new_set);
}
}
+
+ for (SETLOOPER_SET_ONLY(scene, sce_it, base)) {
+ sound_update_base(scene, base, new_set);
+ }
+
}
while ((handle = AUD_getSet(scene->speaker_handles))) {
@@ -907,28 +928,12 @@ float BKE_sound_get_length(bSound *sound)
char **BKE_sound_get_device_names(void)
{
if (audio_device_names == NULL) {
-#ifdef WITH_SYSTEM_AUDASPACE
audio_device_names = AUD_getDeviceNames();
-#else
- static const char *names[] = {
- "Null", "SDL", "OpenAL", "JACK", NULL
- };
- audio_device_names = (char **)names;
-#endif
}
return audio_device_names;
}
-bool BKE_sound_is_jack_supported(void)
-{
-#ifdef WITH_SYSTEM_AUDASPACE
- return 1;
-#else
- return (bool)AUD_isJackSupported();
-#endif
-}
-
#else /* WITH_AUDASPACE */
#include "BLI_utildefines.h"
@@ -975,5 +980,6 @@ void BKE_sound_set_scene_sound_pan(void *UNUSED(handle), float UNUSED(pan), char
void BKE_sound_set_scene_volume(struct Scene *UNUSED(scene), float UNUSED(volume)) {}
void BKE_sound_set_scene_sound_pitch(void *UNUSED(handle), float UNUSED(pitch), char UNUSED(animated)) {}
float BKE_sound_get_length(struct bSound *UNUSED(sound)) { return 0; }
-bool BKE_sound_is_jack_supported(void) { return false; }
+char **BKE_sound_get_device_names(void) { static char *names[1] = {NULL}; return names; }
+
#endif /* WITH_AUDASPACE */
diff --git a/source/blender/blenkernel/intern/subsurf_ccg.c b/source/blender/blenkernel/intern/subsurf_ccg.c
index 8e46cabff02..ed23078a9d8 100644
--- a/source/blender/blenkernel/intern/subsurf_ccg.c
+++ b/source/blender/blenkernel/intern/subsurf_ccg.c
@@ -77,12 +77,6 @@
# include "BLI_array.h"
#endif
-#include "GPU_draw.h"
-#include "GPU_glew.h"
-#include "GPU_buffers.h"
-#include "GPU_shader.h"
-#include "GPU_basic_shader.h"
-
#include "CCGSubSurf.h"
#ifdef WITH_OPENSUBDIV
@@ -1775,47 +1769,7 @@ static void ccgDM_foreachMappedLoop(
}
}
-static void ccgDM_drawVerts(DerivedMesh *dm)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- int edgeSize = ccgSubSurf_getEdgeSize(ss);
- int gridSize = ccgSubSurf_getGridSize(ss);
- CCGVertIterator vi;
- CCGEdgeIterator ei;
- CCGFaceIterator fi;
-
- glBegin(GL_POINTS);
- for (ccgSubSurf_initVertIterator(ss, &vi); !ccgVertIterator_isStopped(&vi); ccgVertIterator_next(&vi)) {
- CCGVert *v = ccgVertIterator_getCurrent(&vi);
- glVertex3fv(ccgSubSurf_getVertData(ss, v));
- }
-
- for (ccgSubSurf_initEdgeIterator(ss, &ei); !ccgEdgeIterator_isStopped(&ei); ccgEdgeIterator_next(&ei)) {
- CCGEdge *e = ccgEdgeIterator_getCurrent(&ei);
- int x;
-
- for (x = 1; x < edgeSize - 1; x++)
- glVertex3fv(ccgSubSurf_getEdgeData(ss, e, x));
- }
-
- for (ccgSubSurf_initFaceIterator(ss, &fi); !ccgFaceIterator_isStopped(&fi); ccgFaceIterator_next(&fi)) {
- CCGFace *f = ccgFaceIterator_getCurrent(&fi);
- int x, y, S, numVerts = ccgSubSurf_getFaceNumVerts(f);
-
- glVertex3fv(ccgSubSurf_getFaceCenterData(f));
- for (S = 0; S < numVerts; S++)
- for (x = 1; x < gridSize - 1; x++)
- glVertex3fv(ccgSubSurf_getFaceGridEdgeData(ss, f, S, x));
- for (S = 0; S < numVerts; S++)
- for (y = 1; y < gridSize - 1; y++)
- for (x = 1; x < gridSize - 1; x++)
- glVertex3fv(ccgSubSurf_getFaceGridData(ss, f, S, x, y));
- }
- glEnd();
-}
-
-static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm)
+static void UNUSED_FUNCTION(ccgdm_pbvh_update)(CCGDerivedMesh *ccgdm)
{
if (ccgdm->pbvh && ccgDM_use_grid_pbvh(ccgdm)) {
CCGFace **faces;
@@ -1830,2179 +1784,6 @@ static void ccgdm_pbvh_update(CCGDerivedMesh *ccgdm)
}
}
-static void ccgDM_drawEdges(DerivedMesh *dm, bool drawLooseEdges, bool drawAllEdges)
-{
- GPUDrawObject *gdo;
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- /* TODO(sergey): We currently only support all edges drawing. */
- if (ccgSubSurf_prepareGLMesh(ccgdm->ss, true, -1)) {
- ccgSubSurf_drawGLMesh(ccgdm->ss, false, -1, -1);
- }
- return;
- }
-#endif
-
- ccgdm_pbvh_update(ccgdm);
-
-/* old debug feature for edges, unsupported for now */
-#if 0
- int useAging = 0;
-
- if (!(G.f & G_BACKBUFSEL)) {
- CCGSubSurf *ss = ccgdm->ss;
- ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL);
-
- /* it needs some way to upload this to VBO now */
- if (useAging) {
- int ageCol = 255 - ccgSubSurf_getEdgeAge(ss, e) * 4;
- glColor3ub(0, ageCol > 0 ? ageCol : 0, 0);
- }
- }
-#endif
-
- GPU_edge_setup(dm);
- gdo = dm->drawObject;
- if (gdo->edges && gdo->points) {
- if (drawAllEdges && drawLooseEdges) {
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, (gdo->totedge - gdo->totinterior) * 2);
- }
- else if (drawAllEdges) {
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->loose_edge_offset * 2);
- }
- else {
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, 0, gdo->tot_edge_drawn * 2);
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, gdo->loose_edge_offset * 2, gdo->tot_loose_edge_drawn * 2);
- }
- }
-
- if (gdo->edges && ccgdm->drawInteriorEdges) {
- GPU_buffer_draw_elements(gdo->edges, GL_LINES, gdo->interior_offset * 2, gdo->totinterior * 2);
- }
- GPU_buffers_unbind();
-}
-
-static void ccgDM_drawLooseEdges(DerivedMesh *dm)
-{
- int start;
- int count;
-
-#ifdef WITH_OPENSUBDIV
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- if (ccgdm->useGpuBackend) {
- /* TODO(sergey): Needs implementation. */
- return;
- }
-#endif
-
- GPU_edge_setup(dm);
-
- start = (dm->drawObject->loose_edge_offset * 2);
- count = (dm->drawObject->interior_offset - dm->drawObject->loose_edge_offset) * 2;
-
- if (count) {
- GPU_buffer_draw_elements(dm->drawObject->edges, GL_LINES, start, count);
- }
-
- GPU_buffers_unbind();
-}
-
-static void ccgDM_NormalFast(float *a, float *b, float *c, float *d, float no[3])
-{
- float a_cX = c[0] - a[0], a_cY = c[1] - a[1], a_cZ = c[2] - a[2];
- float b_dX = d[0] - b[0], b_dY = d[1] - b[1], b_dZ = d[2] - b[2];
-
- no[0] = b_dY * a_cZ - b_dZ * a_cY;
- no[1] = b_dZ * a_cX - b_dX * a_cZ;
- no[2] = b_dX * a_cY - b_dY * a_cX;
-
- normalize_v3(no);
-}
-
-
-static void ccgDM_glNormalFast(float *a, float *b, float *c, float *d)
-{
- float a_cX = c[0] - a[0], a_cY = c[1] - a[1], a_cZ = c[2] - a[2];
- float b_dX = d[0] - b[0], b_dY = d[1] - b[1], b_dZ = d[2] - b[2];
- float no[3];
-
- no[0] = b_dY * a_cZ - b_dZ * a_cY;
- no[1] = b_dZ * a_cX - b_dX * a_cZ;
- no[2] = b_dX * a_cY - b_dY * a_cX;
-
- /* don't normalize, GL_NORMALIZE is enabled */
- glNormal3fv(no);
-}
-
-/* Only used by non-editmesh types */
-static void ccgDM_buffer_copy_normal(
- DerivedMesh *dm, short *varray)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- DMFlagMat *faceFlags = ccgdm->faceFlags;
- int i, totface = ccgSubSurf_getNumFaces(ss);
- int shademodel;
- int start = 0;
-
- /* we are in sculpt mode, disable loop normals (since they won't get updated) */
- if (ccgdm->pbvh)
- lnors = NULL;
-
- CCG_key_top_level(&key, ss);
-
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
- int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- const float (*ln)[3] = NULL;
-
- if (faceFlags) {
- shademodel = (lnors || (faceFlags[index].flag & ME_SMOOTH)) ? GL_SMOOTH : GL_FLAT;
- }
- else {
- shademodel = GL_SMOOTH;
- }
-
- if (lnors) {
- ln = lnors;
- lnors += gridFaces * gridFaces * numVerts * 4;
- }
-
- for (S = 0; S < numVerts; S++) {
- CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
-
- if (ln) {
- /* Can't use quad strips here... */
- for (y = 0; y < gridFaces; y ++) {
- for (x = 0; x < gridFaces; x ++) {
- normal_float_to_short_v3(&varray[start + 0], ln[0]);
- normal_float_to_short_v3(&varray[start + 4], ln[3]);
- normal_float_to_short_v3(&varray[start + 8], ln[2]);
- normal_float_to_short_v3(&varray[start + 12], ln[1]);
-
- start += 16;
- ln += 4;
- }
- }
- }
- else if (shademodel == GL_SMOOTH) {
- for (y = 0; y < gridFaces; y ++) {
- for (x = 0; x < gridFaces; x ++) {
- float *a = CCG_grid_elem_no(&key, faceGridData, x, y );
- float *b = CCG_grid_elem_no(&key, faceGridData, x + 1, y);
- float *c = CCG_grid_elem_no(&key, faceGridData, x + 1, y + 1);
- float *d = CCG_grid_elem_no(&key, faceGridData, x, y + 1);
-
- normal_float_to_short_v3(&varray[start], a);
- normal_float_to_short_v3(&varray[start + 4], b);
- normal_float_to_short_v3(&varray[start + 8], c);
- normal_float_to_short_v3(&varray[start + 12], d);
-
- start += 16;
- }
- }
- }
- else {
- for (y = 0; y < gridFaces; y ++) {
- for (x = 0; x < gridFaces; x ++) {
- float f_no[3];
- short f_no_s[3];
-
- float *a = CCG_grid_elem_co(&key, faceGridData, x, y );
- float *b = CCG_grid_elem_co(&key, faceGridData, x + 1, y );
- float *c = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *d = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- ccgDM_NormalFast(a, b, c, d, f_no);
- normal_float_to_short_v3(f_no_s, f_no);
-
- copy_v3_v3_short(&varray[start], f_no_s);
- copy_v3_v3_short(&varray[start + 4], f_no_s);
- copy_v3_v3_short(&varray[start + 8], f_no_s);
- copy_v3_v3_short(&varray[start + 12], f_no_s);
-
- start += 16;
- }
- }
- }
- }
- }
-}
-
-typedef struct FaceCount {
- unsigned int i_visible;
- unsigned int i_hidden;
- unsigned int i_tri_visible;
- unsigned int i_tri_hidden;
-} FaceCount;
-
-
-/* Only used by non-editmesh types */
-static void ccgDM_buffer_copy_triangles(
- DerivedMesh *dm, unsigned int *varray,
- const int *mat_orig_to_new)
-{
- GPUBufferMaterial *gpumat, *gpumaterials = dm->drawObject->materials;
- const int gpu_totmat = dm->drawObject->totmaterial;
- const short dm_totmat = dm->totmat;
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- DMFlagMat *faceFlags = ccgdm->faceFlags;
- int i, totface = ccgSubSurf_getNumFaces(ss);
- short mat_nr = -1;
- int start;
- int totloops = 0;
- FaceCount *fc = MEM_mallocN(sizeof(*fc) * gpu_totmat, "gpumaterial.facecount");
-
- CCG_key_top_level(&key, ss);
-
- for (i = 0; i < gpu_totmat; i++) {
- fc[i].i_visible = 0;
- fc[i].i_tri_visible = 0;
- fc[i].i_hidden = gpumaterials[i].totpolys - 1;
- fc[i].i_tri_hidden = gpumaterials[i].totelements - 1;
- }
-
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
- int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- bool is_hidden;
- int mati;
-
- if (faceFlags) {
- mat_nr = ME_MAT_NR_TEST(faceFlags[index].mat_nr, dm_totmat);
- is_hidden = (faceFlags[index].flag & ME_HIDE) != 0;
- }
- else {
- mat_nr = 0;
- is_hidden = false;
- }
- mati = mat_orig_to_new[mat_nr];
- gpumat = dm->drawObject->materials + mati;
-
- if (is_hidden) {
- for (S = 0; S < numVerts; S++) {
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- start = gpumat->start + fc[mati].i_tri_hidden;
-
- varray[start--] = totloops;
- varray[start--] = totloops + 2;
- varray[start--] = totloops + 3;
-
- varray[start--] = totloops;
- varray[start--] = totloops + 1;
- varray[start--] = totloops + 2;
-
- fc[mati].i_tri_hidden -= 6;
-
- totloops += 4;
- }
- }
- }
- gpumat->polys[fc[mati].i_hidden--] = i;
- }
- else {
- for (S = 0; S < numVerts; S++) {
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- start = gpumat->start + fc[mati].i_tri_visible;
-
- varray[start++] = totloops + 3;
- varray[start++] = totloops + 2;
- varray[start++] = totloops;
-
- varray[start++] = totloops + 2;
- varray[start++] = totloops + 1;
- varray[start++] = totloops;
-
- fc[mati].i_tri_visible += 6;
-
- totloops += 4;
- }
- }
- }
- gpumat->polys[fc[mati].i_visible++] = i;
- }
- }
-
- /* set the visible polygons */
- for (i = 0; i < gpu_totmat; i++) {
- gpumaterials[i].totvisiblepolys = fc[i].i_visible;
- }
-
- MEM_freeN(fc);
-}
-
-
-/* Only used by non-editmesh types */
-static void ccgDM_buffer_copy_vertex(
- DerivedMesh *dm, void *varray_p)
-{
- float *varray = varray_p;
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- int i, totface = ccgSubSurf_getNumFaces(ss);
- int totedge = ccgSubSurf_getNumEdges(ss);
- int start = 0;
- int edgeSize = ccgSubSurf_getEdgeSize(ss);
-
- CCG_key_top_level(&key, ss);
-
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
-
- for (S = 0; S < numVerts; S++) {
- CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- float *a = CCG_grid_elem_co(&key, faceGridData, x, y);
- float *b = CCG_grid_elem_co(&key, faceGridData, x + 1, y);
- float *c = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *d = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- copy_v3_v3(&varray[start], a);
- copy_v3_v3(&varray[start + 3], b);
- copy_v3_v3(&varray[start + 6], c);
- copy_v3_v3(&varray[start + 9], d);
-
- start += 12;
- }
- }
- }
- }
-
- /* upload loose points */
- for (i = 0; i < totedge; i++) {
- CCGEdge *e = ccgdm->edgeMap[i].edge;
- CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
-
- if (!ccgSubSurf_getEdgeNumFaces(e)) {
- int j = 0;
- for (j = 0; j < edgeSize; j++) {
- copy_v3_v3(&varray[start], CCG_elem_offset_co(&key, edgeData, j));
- start += 3;
- }
- }
- }
-}
-
-/* Only used by non-editmesh types */
-static void ccgDM_buffer_copy_color(
- DerivedMesh *dm, unsigned char *varray,
- const void *user_data)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- const unsigned char *mloopcol = user_data;
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- int i, totface = ccgSubSurf_getNumFaces(ss);
- int start = 0;
- int iface = 0;
-
- CCG_key_top_level(&key, ss);
-
-
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
-
- for (S = 0; S < numVerts; S++) {
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- copy_v4_v4_uchar(&varray[start + 0], &mloopcol[iface * 16 + 0]);
- copy_v4_v4_uchar(&varray[start + 4], &mloopcol[iface * 16 + 12]);
- copy_v4_v4_uchar(&varray[start + 8], &mloopcol[iface * 16 + 8]);
- copy_v4_v4_uchar(&varray[start + 12], &mloopcol[iface * 16 + 4]);
-
- start += 16;
- iface++;
- }
- }
- }
- }
-}
-
-static void ccgDM_buffer_copy_uv(
- DerivedMesh *dm, void *varray_p)
-{
- float *varray = varray_p;
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- MLoopUV *mloopuv = DM_get_loop_data_layer(dm, CD_MLOOPUV);
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- int i, totface = ccgSubSurf_getNumFaces(ss);
- int start = 0;
-
- CCG_key_top_level(&key, ss);
-
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
-
- for (S = 0; S < numVerts; S++) {
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- copy_v2_v2(&varray[start + 0], mloopuv[0].uv);
- copy_v2_v2(&varray[start + 2], mloopuv[3].uv);
- copy_v2_v2(&varray[start + 4], mloopuv[2].uv);
- copy_v2_v2(&varray[start + 6], mloopuv[1].uv);
-
- mloopuv += 4;
- start += 8;
- }
- }
- }
- }
-}
-
-static void ccgDM_buffer_copy_uv_texpaint(
- DerivedMesh *dm, float *varray)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- int i, totface = ccgSubSurf_getNumFaces(ss);
- int start = 0;
- DMFlagMat *faceFlags = ccgdm->faceFlags;
- int dm_totmat = dm->totmat;
- MLoopUV **mloopuv_base;
- MLoopUV *stencil_base;
- int stencil;
-
- CCG_key_top_level(&key, ss);
-
- /* should have been checked for before, reassert */
- BLI_assert(DM_get_loop_data_layer(dm, CD_MLOOPUV));
- mloopuv_base = MEM_mallocN(dm_totmat * sizeof(*mloopuv_base), "texslots");
-
- for (i = 0; i < dm_totmat; i++) {
- mloopuv_base[i] = DM_paint_uvlayer_active_get(dm, i);
- }
-
- stencil = CustomData_get_stencil_layer(&dm->loopData, CD_MLOOPUV);
- stencil_base = CustomData_get_layer_n(&dm->loopData, CD_MLOOPUV, stencil);
-
- start = 0;
-
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
- int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- int matnr;
-
- if (faceFlags) {
- matnr = faceFlags[index].mat_nr;
- }
- else {
- matnr = 0;
- }
-
- for (S = 0; S < numVerts; S++) {
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- /* divide by 4, gives us current loop-index */
- unsigned int i_ml = start / 4;
- copy_v2_v2(&varray[start + 0], mloopuv_base[matnr][i_ml + 0].uv);
- copy_v2_v2(&varray[start + 2], stencil_base[i_ml + 0].uv);
- copy_v2_v2(&varray[start + 4], mloopuv_base[matnr][i_ml + 3].uv);
- copy_v2_v2(&varray[start + 6], stencil_base[i_ml + 3].uv);
- copy_v2_v2(&varray[start + 8], mloopuv_base[matnr][i_ml + 2].uv);
- copy_v2_v2(&varray[start + 10], stencil_base[i_ml + 2].uv);
- copy_v2_v2(&varray[start + 12], mloopuv_base[matnr][i_ml + 1].uv);
- copy_v2_v2(&varray[start + 14], stencil_base[i_ml + 1].uv);
- start += 16;
- }
- }
- }
- }
-
- MEM_freeN(mloopuv_base);
-}
-
-static void ccgDM_buffer_copy_uvedge(
- DerivedMesh *dm, float *varray)
-{
- int i, totpoly;
- int start;
- const MLoopUV *mloopuv;
-#ifndef USE_LOOP_LAYOUT_FAST
- const MPoly *mpoly = dm->getPolyArray(dm);
-#endif
-
- if ((mloopuv = DM_get_loop_data_layer(dm, CD_MLOOPUV)) == NULL) {
- return;
- }
-
- totpoly = dm->getNumPolys(dm);
- start = 0;
-
-#ifndef USE_LOOP_LAYOUT_FAST
- for (i = 0; i < totpoly; i++, mpoly++) {
- for (j = 0; j < mpoly->totloop; j++) {
- copy_v2_v2(&varray[start], mloopuv[mpoly->loopstart + j].uv);
- copy_v2_v2(&varray[start + 2], mloopuv[mpoly->loopstart + (j + 1) % mpoly->totloop].uv);
- start += 4;
- }
- }
-#else
- for (i = 0; i < totpoly; i++) {
- copy_v2_v2(&varray[start + 0], mloopuv[(i * 4) + 0].uv);
- copy_v2_v2(&varray[start + 2], mloopuv[(i * 4) + 1].uv);
-
- copy_v2_v2(&varray[start + 4], mloopuv[(i * 4) + 1].uv);
- copy_v2_v2(&varray[start + 6], mloopuv[(i * 4) + 2].uv);
-
- copy_v2_v2(&varray[start + 8], mloopuv[(i * 4) + 2].uv);
- copy_v2_v2(&varray[start + 10], mloopuv[(i * 4) + 3].uv);
-
- copy_v2_v2(&varray[start + 12], mloopuv[(i * 4) + 3].uv);
- copy_v2_v2(&varray[start + 14], mloopuv[(i * 4) + 0].uv);
-
- start += 16;
- }
-#endif
-}
-
-static void ccgDM_buffer_copy_edge(
- DerivedMesh *dm, unsigned int *varray)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- /* getEdgeSuze returns num of verts, edges is one less */
- int i, j, edgeSize = ccgSubSurf_getEdgeSize(ss) - 1;
- int totedge = ccgSubSurf_getNumEdges(ss);
- int grid_face_side = ccgSubSurf_getGridSize(ss) - 1;
- int totface = ccgSubSurf_getNumFaces(ss);
- unsigned int index_start;
- unsigned int tot_interior = 0;
- unsigned int grid_tot_face = grid_face_side * grid_face_side;
-
- unsigned int iloose, inorm, iloosehidden, inormhidden;
- unsigned int tot_loose_hidden = 0, tot_loose = 0;
- unsigned int tot_hidden = 0, tot = 0;
- unsigned int iloosevert;
- /* int tot_interior = 0; */
-
- /* first, handle hidden/loose existing edges, then interior edges */
- for (j = 0; j < totedge; j++) {
- CCGEdge *e = ccgdm->edgeMap[j].edge;
-
- if (ccgdm->edgeFlags && !(ccgdm->edgeFlags[j] & ME_EDGEDRAW)) {
- if (!ccgSubSurf_getEdgeNumFaces(e)) tot_loose_hidden++;
- else tot_hidden++;
- }
- else {
- if (!ccgSubSurf_getEdgeNumFaces(e)) tot_loose++;
- else tot++;
- }
- }
-
- inorm = 0;
- inormhidden = tot * edgeSize;
- iloose = (tot + tot_hidden) * edgeSize;
- iloosehidden = (tot + tot_hidden + tot_loose) * edgeSize;
- iloosevert = dm->drawObject->tot_loop_verts;
-
- /* part one, handle all normal edges */
- for (j = 0; j < totedge; j++) {
- CCGFace *f;
- int fhandle = 0;
- int totvert = 0;
- unsigned int S = 0;
- CCGEdge *e = ccgdm->edgeMap[j].edge;
- bool isloose = !ccgSubSurf_getEdgeNumFaces(e);
-
- if (!isloose) {
- CCGVert *v1, *v2;
- CCGVert *ev1 = ccgSubSurf_getEdgeVert0(e);
- CCGVert *ev2 = ccgSubSurf_getEdgeVert1(e);
-
- f = ccgSubSurf_getEdgeFace(e, 0);
- fhandle = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- totvert = ccgSubSurf_getFaceNumVerts(f);
-
- /* find the index of vertices in the face */
- for (i = 0; i < totvert; i++) {
- v1 = ccgSubSurf_getFaceVert(f, i);
- v2 = ccgSubSurf_getFaceVert(f, (i + 1) % totvert);
-
- if ((ev1 == v1 && ev2 == v2) || (ev1 == v2 && ev2 == v1)) {
- S = i;
- break;
- }
- }
- }
-
- if (ccgdm->edgeFlags && !(ccgdm->edgeFlags[j] & ME_EDGEDRAW)) {
- if (isloose) {
- for (i = 0; i < edgeSize; i++) {
- varray[iloosehidden * 2] = iloosevert;
- varray[iloosehidden * 2 + 1] = iloosevert + 1;
- iloosehidden++;
- iloosevert++;
- }
- /* we are through with this loose edge and moving to the next, so increase by one */
- iloosevert++;
- }
- else {
- index_start = ccgdm->faceMap[fhandle].startFace;
-
- for (i = 0; i < grid_face_side; i++) {
- varray[inormhidden * 2] = (index_start + S * grid_tot_face + i * grid_face_side + grid_face_side - 1) * 4 + 1;
- varray[inormhidden * 2 + 1] = (index_start + S * grid_tot_face + i * grid_face_side + grid_face_side - 1) * 4 + 2;
- varray[inormhidden * 2 + 2] = (index_start + ((S + 1) % totvert) * grid_tot_face + grid_face_side * (grid_face_side - 1) + i) * 4 + 2;
- varray[inormhidden * 2 + 3] = (index_start + ((S + 1) % totvert) * grid_tot_face + grid_face_side * (grid_face_side - 1) + i) * 4 + 3;
- inormhidden += 2;
- }
- }
- }
- else {
- if (isloose) {
- for (i = 0; i < edgeSize; i++) {
- varray[iloose * 2] = iloosevert;
- varray[iloose * 2 + 1] = iloosevert + 1;
- iloose++;
- iloosevert++;
- }
- /* we are through with this loose edge and moving to the next, so increase by one */
- iloosevert++;
- }
- else {
- index_start = ccgdm->faceMap[fhandle].startFace;
-
- for (i = 0; i < grid_face_side; i++) {
- varray[inorm * 2] = (index_start + S * grid_tot_face + i * grid_face_side + grid_face_side - 1) * 4 + 1;
- varray[inorm * 2 + 1] = (index_start + S * grid_tot_face + i * grid_face_side + grid_face_side - 1) * 4 + 2;
- varray[inorm * 2 + 2] = (index_start + ((S + 1) % totvert) * grid_tot_face + grid_face_side * (grid_face_side - 1) + i) * 4 + 2;
- varray[inorm * 2 + 3] = (index_start + ((S + 1) % totvert) * grid_tot_face + grid_face_side * (grid_face_side - 1) + i) * 4 + 3;
- inorm += 2;
- }
- }
- }
- }
-
- /* part two, handle interior edges */
- inorm = totedge * grid_face_side * 2;
-
- index_start = 0;
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- unsigned int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
-
- for (S = 0; S < numVerts; S++) {
- for (x = 1; x < grid_face_side; x++) {
- for (y = 0; y < grid_face_side; y++) {
- unsigned int tmp = (index_start + x * grid_face_side + y) * 4;
- varray[inorm * 2] = tmp;
- varray[inorm * 2 + 1] = tmp + 1;
- inorm++;
- }
- }
- for (x = 0; x < grid_face_side; x++) {
- for (y = 0; y < grid_face_side; y++) {
- unsigned int tmp = (index_start + x * grid_face_side + y) * 4;
- varray[inorm * 2] = tmp + 3;
- varray[inorm * 2 + 1] = tmp;
- inorm++;
- }
- }
-
- tot_interior += grid_face_side * (2 * grid_face_side - 1);
- index_start += grid_tot_face;
- }
- }
-
- dm->drawObject->tot_loose_edge_drawn = tot_loose * edgeSize;
- dm->drawObject->loose_edge_offset = (tot + tot_hidden) * edgeSize;
- dm->drawObject->tot_edge_drawn = tot * edgeSize;
-
- dm->drawObject->interior_offset = totedge * edgeSize;
- dm->drawObject->totinterior = tot_interior;
-}
-
-static void ccgDM_copy_gpu_data(
- DerivedMesh *dm, int type, void *varray_p,
- const int *mat_orig_to_new, const void *user_data)
-{
- /* 'varray_p' cast is redundant but include for self-documentation */
- switch (type) {
- case GPU_BUFFER_VERTEX:
- ccgDM_buffer_copy_vertex(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_NORMAL:
- ccgDM_buffer_copy_normal(dm, (short *)varray_p);
- break;
- case GPU_BUFFER_UV:
- ccgDM_buffer_copy_uv(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_UV_TEXPAINT:
- ccgDM_buffer_copy_uv_texpaint(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_COLOR:
- ccgDM_buffer_copy_color(dm, (unsigned char *)varray_p, user_data);
- break;
- case GPU_BUFFER_UVEDGE:
- ccgDM_buffer_copy_uvedge(dm, (float *)varray_p);
- break;
- case GPU_BUFFER_EDGE:
- ccgDM_buffer_copy_edge(dm, (unsigned int *)varray_p);
- break;
- case GPU_BUFFER_TRIANGLES:
- ccgDM_buffer_copy_triangles(dm, (unsigned int *)varray_p, mat_orig_to_new);
- break;
- default:
- break;
- }
-}
-
-static GPUDrawObject *ccgDM_GPUObjectNew(DerivedMesh *dm)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- GPUDrawObject *gdo;
- DMFlagMat *faceFlags = ccgdm->faceFlags;
- int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
- const short dm_totmat = (faceFlags) ? dm->totmat : 1;
- GPUBufferMaterial *matinfo;
- int i;
- unsigned int tot_internal_edges = 0;
- int edgeVerts = ccgSubSurf_getEdgeSize(ss);
- int edgeSize = edgeVerts - 1;
-
- int totedge = ccgSubSurf_getNumEdges(ss);
- int totface = ccgSubSurf_getNumFaces(ss);
-
- /* object contains at least one material (default included) so zero means uninitialized dm */
- BLI_assert(dm_totmat != 0);
-
- matinfo = MEM_callocN(sizeof(*matinfo) * dm_totmat, "GPU_drawobject_new.mat_orig_to_new");
-
- if (faceFlags) {
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int numVerts = ccgSubSurf_getFaceNumVerts(f);
- int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- const short new_matnr = ME_MAT_NR_TEST(faceFlags[index].mat_nr, dm_totmat);
- matinfo[new_matnr].totelements += numVerts * gridFaces * gridFaces * 6;
- matinfo[new_matnr].totloops += numVerts * gridFaces * gridFaces * 4;
- matinfo[new_matnr].totpolys++;
- tot_internal_edges += numVerts * gridFaces * (2 * gridFaces - 1);
- }
- }
- else {
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int numVerts = ccgSubSurf_getFaceNumVerts(f);
- matinfo[0].totelements += numVerts * gridFaces * gridFaces * 6;
- matinfo[0].totloops += numVerts * gridFaces * gridFaces * 4;
- matinfo[0].totpolys++;
- tot_internal_edges += numVerts * gridFaces * (2 * gridFaces - 1);
- }
- }
-
- /* create the GPUDrawObject */
- gdo = MEM_callocN(sizeof(GPUDrawObject), "GPUDrawObject");
- gdo->totvert = 0; /* used to count indices, doesn't really matter for ccgsubsurf */
- gdo->totedge = (totedge * edgeSize + tot_internal_edges);
-
- GPU_buffer_material_finalize(gdo, matinfo, dm_totmat);
-
- /* store total number of points used for triangles */
- gdo->tot_triangle_point = ccgSubSurf_getNumFinalFaces(ss) * 6;
- gdo->tot_loop_verts = ccgSubSurf_getNumFinalFaces(ss) * 4;
-
- /* finally, count loose points */
- for (i = 0; i < totedge; i++) {
- CCGEdge *e = ccgdm->edgeMap[i].edge;
-
- if (!ccgSubSurf_getEdgeNumFaces(e))
- gdo->tot_loose_point += edgeVerts;
- }
-
- return gdo;
-}
-
-/* Only used by non-editmesh types */
-static void ccgDM_drawFacesSolid(DerivedMesh *dm, float (*partial_redraw_planes)[4], bool fast, DMSetMaterial setMaterial)
-{
- int a;
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
-
- ccgdm_pbvh_update(ccgdm);
-
- if (ccgdm->pbvh && ccgdm->multires.mmd) {
- if (BKE_pbvh_has_faces(ccgdm->pbvh)) {
- BKE_pbvh_draw(ccgdm->pbvh, partial_redraw_planes, NULL,
- setMaterial, false, fast);
- }
-
- return;
- }
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- CCGSubSurf *ss = ccgdm->ss;
- const DMFlagMat *faceFlags = ccgdm->faceFlags;
- const int level = ccgSubSurf_getSubdivisionLevels(ss);
- const int face_side = 1 << level;
- const int grid_side = 1 << (level - 1);
- const int face_patches = face_side * face_side;
- const int grid_patches = grid_side * grid_side;
- const int num_base_faces = ccgSubSurf_getNumGLMeshBaseFaces(ss);
- int i, current_patch = 0;
- int mat_nr = -1;
- bool draw_smooth = false;
- int start_draw_patch = -1, num_draw_patches = 0;
- if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, setMaterial != NULL, -1) == false)) {
- return;
- }
- if (setMaterial == NULL) {
- ccgSubSurf_drawGLMesh(ss,
- true,
- -1,
- -1);
- return;
- }
- for (i = 0; i < num_base_faces; ++i) {
- const int num_face_verts = ccgSubSurf_getNumGLMeshBaseFaceVerts(ss, i);
- const int num_patches = (num_face_verts == 4) ? face_patches
- : num_face_verts * grid_patches;
- int new_matnr;
- bool new_draw_smooth;
- if (faceFlags) {
- new_draw_smooth = (faceFlags[i].flag & ME_SMOOTH);
- new_matnr = (faceFlags[i].mat_nr + 1);
- }
- else {
- new_draw_smooth = true;
- new_matnr = 1;
- }
- if (new_draw_smooth != draw_smooth || new_matnr != mat_nr) {
- if (num_draw_patches != 0) {
- bool do_draw = setMaterial(mat_nr, NULL);
- if (do_draw) {
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss,
- true,
- start_draw_patch,
- num_draw_patches);
- }
- }
- start_draw_patch = current_patch;
- num_draw_patches = num_patches;
- mat_nr = new_matnr;
- draw_smooth = new_draw_smooth;
- }
- else {
- num_draw_patches += num_patches;
- }
- current_patch += num_patches;
- }
- if (num_draw_patches != 0) {
- bool do_draw = setMaterial(mat_nr, NULL);
- if (do_draw) {
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss,
- true,
- start_draw_patch,
- num_draw_patches);
- }
- }
- glShadeModel(GL_SMOOTH);
- return;
- }
-#endif
-
- GPU_vertex_setup(dm);
- GPU_normal_setup(dm);
- GPU_triangle_setup(dm);
- for (a = 0; a < dm->drawObject->totmaterial; a++) {
- if (!setMaterial || setMaterial(dm->drawObject->materials[a].mat_nr + 1, NULL)) {
- GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, dm->drawObject->materials[a].start,
- dm->drawObject->materials[a].totelements);
- }
- }
- GPU_buffers_unbind();
-}
-
-typedef struct {
- DMVertexAttribs attribs;
- int numdata;
-
- GPUAttrib datatypes[GPU_MAX_ATTRIB]; /* TODO, messing up when switching materials many times - [#21056]*/
-} GPUMaterialConv;
-
-/* Only used by non-editmesh types */
-static void ccgDM_drawMappedFacesGLSL(DerivedMesh *dm,
- DMSetMaterial setMaterial,
- DMSetDrawOptions setDrawOptions,
- void *userData)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- GPUVertexAttribs gattribs;
- int a, b;
- const DMFlagMat *faceFlags = ccgdm->faceFlags;
- unsigned char *varray;
- size_t max_element_size = 0;
- int tot_loops = 0;
- int totpoly = ccgSubSurf_getNumFaces(ss);
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- int edgeSize = ccgSubSurf_getEdgeSize(ss);
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- const int level = ccgSubSurf_getSubdivisionLevels(ss);
- const int face_side = 1 << level;
- const int grid_side = 1 << (level - 1);
- const int face_patches = face_side * face_side;
- const int grid_patches = grid_side * grid_side;
- const int num_base_faces = ccgSubSurf_getNumGLMeshBaseFaces(ss);
- int i, current_patch = 0;
- int mat_nr = -1;
- bool draw_smooth = false;
- int start_draw_patch = -1, num_draw_patches = 0;
- GPU_draw_update_fvar_offset(dm);
- if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, false, -1) == false)) {
- return;
- }
- for (i = 0; i < num_base_faces; ++i) {
- const int num_face_verts = ccgSubSurf_getNumGLMeshBaseFaceVerts(ss, i);
- const int num_patches = (num_face_verts == 4) ? face_patches
- : num_face_verts * grid_patches;
- int new_matnr;
- bool new_draw_smooth;
-
- if (faceFlags) {
- new_draw_smooth = (faceFlags[i].flag & ME_SMOOTH);
- new_matnr = (faceFlags[i].mat_nr + 1);
- }
- else {
- new_draw_smooth = true;
- new_matnr = 1;
- }
- if (new_draw_smooth != draw_smooth || new_matnr != mat_nr) {
- if (num_draw_patches != 0) {
- bool do_draw = setMaterial(mat_nr, &gattribs);
- if (do_draw) {
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss,
- true,
- start_draw_patch,
- num_draw_patches);
- }
- }
- start_draw_patch = current_patch;
- num_draw_patches = num_patches;
- mat_nr = new_matnr;
- draw_smooth = new_draw_smooth;
- }
- else {
- num_draw_patches += num_patches;
- }
- current_patch += num_patches;
- }
- if (num_draw_patches != 0) {
- bool do_draw = setMaterial(mat_nr, &gattribs);
- if (do_draw) {
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss,
- true,
- start_draw_patch,
- num_draw_patches);
- }
- }
- glShadeModel(GL_SMOOTH);
- return;
- }
-#endif
-
- CCG_key_top_level(&key, ss);
- ccgdm_pbvh_update(ccgdm);
-
- if (setDrawOptions != NULL) {
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- DMVertexAttribs attribs = {{{NULL}}};
- int i;
- int matnr = -1;
- int do_draw = 0;
-
-#define PASSATTRIB(dx, dy, vert) { \
- if (attribs.totorco) \
- index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
- else \
- index = 0; \
- DM_draw_attrib_vertex(&attribs, a, index, vert, ((a) * 4) + vert); \
- DM_draw_attrib_vertex_uniforms(&attribs); \
-} (void)0
-
- totpoly = ccgSubSurf_getNumFaces(ss);
- for (a = 0, i = 0; i < totpoly; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- const float (*ln)[3] = NULL;
- int S, x, y, drawSmooth;
- int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- int origIndex = ccgDM_getFaceMapIndex(ss, f);
-
- int numVerts = ccgSubSurf_getFaceNumVerts(f);
- int new_matnr;
-
- if (faceFlags) {
- drawSmooth = (lnors || (faceFlags[index].flag & ME_SMOOTH));
- new_matnr = faceFlags[index].mat_nr + 1;
- }
- else {
- drawSmooth = 1;
- new_matnr = 1;
- }
-
- if (lnors) {
- ln = lnors;
- lnors += (gridFaces * gridFaces * numVerts) * 4;
- }
-
- if (new_matnr != matnr) {
- do_draw = setMaterial(matnr = new_matnr, &gattribs);
- if (do_draw)
- DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
- }
-
- if (!do_draw || (setDrawOptions && (origIndex != ORIGINDEX_NONE) &&
- (setDrawOptions(userData, origIndex) == DM_DRAW_OPTION_SKIP)))
- {
- a += gridFaces * gridFaces * numVerts;
- continue;
- }
-
- glShadeModel(drawSmooth ? GL_SMOOTH : GL_FLAT);
- for (S = 0; S < numVerts; S++) {
- CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
- CCGElem *vda, *vdb;
-
- if (ln) {
- glBegin(GL_QUADS);
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- float *aco = CCG_grid_elem_co(&key, faceGridData, x, y);
- float *bco = CCG_grid_elem_co(&key, faceGridData, x + 1, y);
- float *cco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *dco = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- PASSATTRIB(0, 1, 1);
- glNormal3fv(ln[1]);
- glVertex3fv(dco);
- PASSATTRIB(1, 1, 2);
- glNormal3fv(ln[2]);
- glVertex3fv(cco);
- PASSATTRIB(1, 0, 3);
- glNormal3fv(ln[3]);
- glVertex3fv(bco);
- PASSATTRIB(0, 0, 0);
- glNormal3fv(ln[0]);
- glVertex3fv(aco);
-
- ln += 4;
- a++;
- }
- }
- glEnd();
- }
- else if (drawSmooth) {
- for (y = 0; y < gridFaces; y++) {
- glBegin(GL_QUAD_STRIP);
- for (x = 0; x < gridFaces; x++) {
- vda = CCG_grid_elem(&key, faceGridData, x, y + 0);
- vdb = CCG_grid_elem(&key, faceGridData, x, y + 1);
-
- PASSATTRIB(0, 0, 0);
- glNormal3fv(CCG_elem_no(&key, vda));
- glVertex3fv(CCG_elem_co(&key, vda));
-
- PASSATTRIB(0, 1, 1);
- glNormal3fv(CCG_elem_no(&key, vdb));
- glVertex3fv(CCG_elem_co(&key, vdb));
-
- if (x != gridFaces - 1)
- a++;
- }
-
- vda = CCG_grid_elem(&key, faceGridData, x, y + 0);
- vdb = CCG_grid_elem(&key, faceGridData, x, y + 1);
-
- PASSATTRIB(0, 0, 3);
- glNormal3fv(CCG_elem_no(&key, vda));
- glVertex3fv(CCG_elem_co(&key, vda));
-
- PASSATTRIB(0, 1, 2);
- glNormal3fv(CCG_elem_no(&key, vdb));
- glVertex3fv(CCG_elem_co(&key, vdb));
-
- glEnd();
-
- a++;
- }
- }
- else {
- glBegin(GL_QUADS);
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- float *aco = CCG_grid_elem_co(&key, faceGridData, x, y);
- float *bco = CCG_grid_elem_co(&key, faceGridData, x + 1, y);
- float *cco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *dco = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- ccgDM_glNormalFast(aco, bco, cco, dco);
-
- PASSATTRIB(0, 1, 1);
- glVertex3fv(dco);
- PASSATTRIB(1, 1, 2);
- glVertex3fv(cco);
- PASSATTRIB(1, 0, 3);
- glVertex3fv(bco);
- PASSATTRIB(0, 0, 0);
- glVertex3fv(aco);
-
- a++;
- }
- }
- glEnd();
- }
- }
- }
-
- glShadeModel(GL_SMOOTH);
-#undef PASSATTRIB
- }
- else {
- GPUMaterialConv *matconv;
- size_t offset;
- int *mat_orig_to_new;
- int tot_active_mat;
- GPUBuffer *buffer = NULL;
-
- GPU_vertex_setup(dm);
- GPU_normal_setup(dm);
- GPU_triangle_setup(dm);
-
- tot_active_mat = dm->drawObject->totmaterial;
-
- matconv = MEM_callocN(sizeof(*matconv) * tot_active_mat,
- "cdDM_drawMappedFacesGLSL.matconv");
- mat_orig_to_new = MEM_mallocN(sizeof(*mat_orig_to_new) * dm->totmat,
- "cdDM_drawMappedFacesGLSL.mat_orig_to_new");
-
- /* part one, check what attributes are needed per material */
- for (a = 0; a < tot_active_mat; a++) {
- int new_matnr;
- int do_draw;
-
- new_matnr = dm->drawObject->materials[a].mat_nr;
-
- /* map from original material index to new
- * GPUBufferMaterial index */
- mat_orig_to_new[new_matnr] = a;
- do_draw = setMaterial(new_matnr + 1, &gattribs);
-
- if (do_draw) {
- int numdata = 0;
- DM_vertex_attributes_from_gpu(dm, &gattribs, &matconv[a].attribs);
-
- if (matconv[a].attribs.totorco && matconv[a].attribs.orco.array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.orco.gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.orco.gl_info_index;
- matconv[a].datatypes[numdata].size = 3;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
- }
- for (b = 0; b < matconv[a].attribs.tottface; b++) {
- if (matconv[a].attribs.tface[b].array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.tface[b].gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.tface[b].gl_info_index;
- matconv[a].datatypes[numdata].size = 2;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
- }
- }
- for (b = 0; b < matconv[a].attribs.totmcol; b++) {
- if (matconv[a].attribs.mcol[b].array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.mcol[b].gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.mcol[b].gl_info_index;
- matconv[a].datatypes[numdata].size = 4;
- matconv[a].datatypes[numdata].type = GL_UNSIGNED_BYTE;
- numdata++;
- }
- }
- for (b = 0; b < matconv[a].attribs.tottang; b++) {
- if (matconv[a].attribs.tottang && matconv[a].attribs.tang[b].array) {
- matconv[a].datatypes[numdata].index = matconv[a].attribs.tang[b].gl_index;
- matconv[a].datatypes[numdata].info_index = matconv[a].attribs.tang[b].gl_info_index;
- matconv[a].datatypes[numdata].size = 4;
- matconv[a].datatypes[numdata].type = GL_FLOAT;
- numdata++;
- }
- }
- if (numdata != 0) {
- matconv[a].numdata = numdata;
- max_element_size = max_ii(GPU_attrib_element_size(matconv[a].datatypes, numdata), max_element_size);
- }
- }
- }
-
- /* part two, generate and fill the arrays with the data */
- if (max_element_size > 0) {
- buffer = GPU_buffer_alloc(max_element_size * dm->drawObject->tot_loop_verts);
-
- varray = GPU_buffer_lock_stream(buffer, GPU_BINDING_ARRAY);
- if (varray == NULL) {
- GPU_buffers_unbind();
- GPU_buffer_free(buffer);
- MEM_freeN(mat_orig_to_new);
- MEM_freeN(matconv);
- fprintf(stderr, "Out of memory, can't draw object\n");
- return;
- }
-
- for (a = 0; a < totpoly; a++) {
- CCGFace *f = ccgdm->faceMap[a].face;
- int orig_index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
- int i;
-
- if (faceFlags) {
- i = mat_orig_to_new[faceFlags[orig_index].mat_nr];
- }
- else {
- i = mat_orig_to_new[0];
- }
-
- if (matconv[i].numdata != 0) {
- for (S = 0; S < numVerts; S++) {
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
-
- offset = tot_loops * max_element_size;
-
- if (matconv[i].attribs.totorco && matconv[i].attribs.orco.array) {
- int index;
-
- index = getFaceIndex(ss, f, S, x, y, edgeSize, gridSize);
- copy_v3_v3((float *)&varray[offset],
- (float *)matconv[i].attribs.orco.array[index]);
- index = getFaceIndex(ss, f, S, x + 1, y, edgeSize, gridSize);
- copy_v3_v3((float *)&varray[offset + max_element_size],
- (float *)matconv[i].attribs.orco.array[index]);
- index = getFaceIndex(ss, f, S, x + 1, y + 1, edgeSize, gridSize);
- copy_v3_v3((float *)&varray[offset + 2 * max_element_size],
- (float *)matconv[i].attribs.orco.array[index]);
- index = getFaceIndex(ss, f, S, x, y + 1, edgeSize, gridSize);
- copy_v3_v3((float *)&varray[offset + 3 * max_element_size],
- (float *)matconv[i].attribs.orco.array[index]);
-
- offset += sizeof(float) * 3;
- }
- for (b = 0; b < matconv[i].attribs.tottface; b++) {
- if (matconv[i].attribs.tface[b].array) {
- const MLoopUV *mloopuv = matconv[i].attribs.tface[b].array + tot_loops;
-
- copy_v2_v2((float *)&varray[offset], mloopuv[0].uv);
- copy_v2_v2((float *)&varray[offset + max_element_size], mloopuv[3].uv);
- copy_v2_v2((float *)&varray[offset + 2 * max_element_size], mloopuv[2].uv);
- copy_v2_v2((float *)&varray[offset + 3 * max_element_size], mloopuv[1].uv);
-
- offset += sizeof(float) * 2;
- }
- }
- for (b = 0; b < matconv[i].attribs.totmcol; b++) {
- if (matconv[i].attribs.mcol[b].array) {
- const MLoopCol *mloopcol = matconv[i].attribs.mcol[b].array + tot_loops;
-
- copy_v4_v4_uchar(&varray[offset], &mloopcol[0].r);
- copy_v4_v4_uchar(&varray[offset + max_element_size], &mloopcol[3].r);
- copy_v4_v4_uchar(&varray[offset + 2 * max_element_size], &mloopcol[2].r);
- copy_v4_v4_uchar(&varray[offset + 3 * max_element_size], &mloopcol[1].r);
-
- offset += sizeof(unsigned char) * 4;
- }
- }
- for (b = 0; b < matconv[i].attribs.tottang; b++) {
- if (matconv[i].attribs.tottang && matconv[i].attribs.tang[b].array) {
- const float (*looptang)[4] = (const float (*)[4])matconv[i].attribs.tang[b].array + tot_loops;
-
- copy_v4_v4((float *)&varray[offset], looptang[0]);
- copy_v4_v4((float *)&varray[offset + max_element_size], looptang[3]);
- copy_v4_v4((float *)&varray[offset + 2 * max_element_size], looptang[2]);
- copy_v4_v4((float *)&varray[offset + 3 * max_element_size], looptang[1]);
-
- offset += sizeof(float) * 4;
- }
- }
-
- tot_loops += 4;
- }
- }
- }
- }
- else {
- tot_loops += 4 * numVerts * gridFaces * gridFaces;
- }
- }
- GPU_buffer_unlock(buffer, GPU_BINDING_ARRAY);
- }
-
- for (a = 0; a < tot_active_mat; a++) {
- int new_matnr;
- int do_draw;
-
- new_matnr = dm->drawObject->materials[a].mat_nr;
-
- do_draw = setMaterial(new_matnr + 1, &gattribs);
-
- if (do_draw) {
- if (matconv[a].numdata) {
- GPU_interleaved_attrib_setup(buffer, matconv[a].datatypes, matconv[a].numdata, max_element_size);
- }
- GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES,
- dm->drawObject->materials[a].start, dm->drawObject->materials[a].totelements);
- if (matconv[a].numdata) {
- GPU_interleaved_attrib_unbind();
- }
- }
- }
-
- GPU_buffers_unbind();
- if (buffer)
- GPU_buffer_free(buffer);
-
- MEM_freeN(mat_orig_to_new);
- MEM_freeN(matconv);
- }
-}
-
-static void ccgDM_drawFacesGLSL(DerivedMesh *dm, DMSetMaterial setMaterial)
-{
- dm->drawMappedFacesGLSL(dm, setMaterial, NULL, NULL);
-}
-
-/* Only used by non-editmesh types */
-static void ccgDM_drawMappedFacesMat(DerivedMesh *dm,
- void (*setMaterial)(void *userData, int matnr, void *attribs),
- bool (*setFace)(void *userData, int index), void *userData)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- GPUVertexAttribs gattribs;
- DMVertexAttribs attribs = {{{NULL}}};
- int gridSize = ccgSubSurf_getGridSize(ss);
- int gridFaces = gridSize - 1;
- int edgeSize = ccgSubSurf_getEdgeSize(ss);
- DMFlagMat *faceFlags = ccgdm->faceFlags;
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- int a, i, numVerts, matnr, totface;
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- const int level = ccgSubSurf_getSubdivisionLevels(ss);
- const int face_side = 1 << level;
- const int grid_side = 1 << (level - 1);
- const int face_patches = face_side * face_side;
- const int grid_patches = grid_side * grid_side;
- const int num_base_faces = ccgSubSurf_getNumGLMeshBaseFaces(ss);
- int current_patch = 0;
- int mat_nr = -1;
- bool draw_smooth = false;
- int start_draw_patch = -1, num_draw_patches = 0;
- GPU_draw_update_fvar_offset(dm);
- if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, true, -1) == false)) {
- return;
- }
- for (i = 0; i < num_base_faces; ++i) {
- const int num_face_verts = ccgSubSurf_getNumGLMeshBaseFaceVerts(ss, i);
- const int num_patches = (num_face_verts == 4) ? face_patches
- : num_face_verts * grid_patches;
- int new_matnr;
- bool new_draw_smooth;
-
- if (faceFlags) {
- new_draw_smooth = (faceFlags[i].flag & ME_SMOOTH);
- new_matnr = (faceFlags[i].mat_nr + 1);
- }
- else {
- new_draw_smooth = true;
- new_matnr = 1;
- }
- if (new_draw_smooth != draw_smooth || new_matnr != mat_nr) {
- if (num_draw_patches != 0) {
- setMaterial(userData, mat_nr, &gattribs);
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss,
- true,
- start_draw_patch,
- num_draw_patches);
- }
- start_draw_patch = current_patch;
- num_draw_patches = num_patches;
- mat_nr = new_matnr;
- draw_smooth = new_draw_smooth;
- }
- else {
- num_draw_patches += num_patches;
- }
- current_patch += num_patches;
- }
- if (num_draw_patches != 0) {
- setMaterial(userData, mat_nr, &gattribs);
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss,
- true,
- start_draw_patch,
- num_draw_patches);
- }
- glShadeModel(GL_SMOOTH);
- return;
- }
-#endif
-
- CCG_key_top_level(&key, ss);
- ccgdm_pbvh_update(ccgdm);
-
- matnr = -1;
-
-#define PASSATTRIB(dx, dy, vert) { \
- if (attribs.totorco) \
- index = getFaceIndex(ss, f, S, x + dx, y + dy, edgeSize, gridSize); \
- else \
- index = 0; \
- DM_draw_attrib_vertex(&attribs, a, index, vert, ((a) * 4) + vert); \
- DM_draw_attrib_vertex_uniforms(&attribs); \
-} (void)0
-
- totface = ccgSubSurf_getNumFaces(ss);
- for (a = 0, i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- const float (*ln)[3] = NULL;
- int S, x, y, drawSmooth;
- int index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- int origIndex = ccgDM_getFaceMapIndex(ss, f);
- int new_matnr;
-
- numVerts = ccgSubSurf_getFaceNumVerts(f);
-
- /* get flags */
- if (faceFlags) {
- drawSmooth = (lnors || (faceFlags[index].flag & ME_SMOOTH));
- new_matnr = faceFlags[index].mat_nr + 1;
- }
- else {
- drawSmooth = 1;
- new_matnr = 1;
- }
-
- if (lnors) {
- ln = lnors;
- lnors += (gridFaces * gridFaces * numVerts) * 4;
- }
-
- /* material */
- if (new_matnr != matnr) {
- setMaterial(userData, matnr = new_matnr, &gattribs);
- DM_vertex_attributes_from_gpu(dm, &gattribs, &attribs);
- }
-
- /* face hiding */
- if ((setFace && (origIndex != ORIGINDEX_NONE) && !setFace(userData, origIndex))) {
- a += gridFaces * gridFaces * numVerts;
- continue;
- }
-
- /* draw face*/
- glShadeModel(drawSmooth ? GL_SMOOTH : GL_FLAT);
- for (S = 0; S < numVerts; S++) {
- CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
- CCGElem *vda, *vdb;
-
- if (ln) {
- glBegin(GL_QUADS);
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- float *aco = CCG_grid_elem_co(&key, faceGridData, x, y + 0);
- float *bco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 0);
- float *cco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *dco = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- PASSATTRIB(0, 1, 1);
- glNormal3fv(ln[1]);
- glVertex3fv(dco);
- PASSATTRIB(1, 1, 2);
- glNormal3fv(ln[2]);
- glVertex3fv(cco);
- PASSATTRIB(1, 0, 3);
- glNormal3fv(ln[3]);
- glVertex3fv(bco);
- PASSATTRIB(0, 0, 0);
- glNormal3fv(ln[0]);
- glVertex3fv(aco);
-
- ln += 4;
- a++;
- }
- }
- glEnd();
- }
- else if (drawSmooth) {
- for (y = 0; y < gridFaces; y++) {
- glBegin(GL_QUAD_STRIP);
- for (x = 0; x < gridFaces; x++) {
- vda = CCG_grid_elem(&key, faceGridData, x, y);
- vdb = CCG_grid_elem(&key, faceGridData, x, y + 1);
-
- PASSATTRIB(0, 0, 0);
- glNormal3fv(CCG_elem_no(&key, vda));
- glVertex3fv(CCG_elem_co(&key, vda));
-
- PASSATTRIB(0, 1, 1);
- glNormal3fv(CCG_elem_no(&key, vdb));
- glVertex3fv(CCG_elem_co(&key, vdb));
-
- if (x != gridFaces - 1)
- a++;
- }
-
- vda = CCG_grid_elem(&key, faceGridData, x, y + 0);
- vdb = CCG_grid_elem(&key, faceGridData, x, y + 1);
-
- PASSATTRIB(0, 0, 3);
- glNormal3fv(CCG_elem_no(&key, vda));
- glVertex3fv(CCG_elem_co(&key, vda));
-
- PASSATTRIB(0, 1, 2);
- glNormal3fv(CCG_elem_no(&key, vdb));
- glVertex3fv(CCG_elem_co(&key, vdb));
-
- glEnd();
-
- a++;
- }
- }
- else {
- glBegin(GL_QUADS);
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- float *aco = CCG_grid_elem_co(&key, faceGridData, x, y + 0);
- float *bco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 0);
- float *cco = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *dco = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- ccgDM_glNormalFast(aco, bco, cco, dco);
-
- PASSATTRIB(0, 1, 1);
- glVertex3fv(dco);
- PASSATTRIB(1, 1, 2);
- glVertex3fv(cco);
- PASSATTRIB(1, 0, 3);
- glVertex3fv(bco);
- PASSATTRIB(0, 0, 0);
- glVertex3fv(aco);
-
- a++;
- }
- }
- glEnd();
- }
- }
- }
-
- glShadeModel(GL_SMOOTH);
-#undef PASSATTRIB
-}
-
-static void ccgDM_drawFacesTex_common(DerivedMesh *dm,
- DMSetDrawOptionsTex drawParams,
- DMSetDrawOptionsMappedTex drawParamsMapped,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- int colType;
- const MLoopCol *mloopcol = NULL;
- MTexPoly *mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY);
- DMFlagMat *faceFlags = ccgdm->faceFlags;
- DMDrawOption draw_option;
- int i, totpoly;
- bool flush;
- const bool use_tface = (flag & DM_DRAW_USE_ACTIVE_UV) != 0;
- const bool use_colors = (flag & DM_DRAW_USE_COLORS) != 0;
- unsigned int next_actualFace;
- unsigned int gridFaces = ccgSubSurf_getGridSize(ss) - 1;
- int mat_index;
- int tot_element, start_element, tot_drawn;
-
- if (use_colors) {
- colType = CD_TEXTURE_MLOOPCOL;
- mloopcol = dm->getLoopDataArray(dm, colType);
- if (!mloopcol) {
- colType = CD_PREVIEW_MLOOPCOL;
- mloopcol = dm->getLoopDataArray(dm, colType);
- }
- if (!mloopcol) {
- colType = CD_MLOOPCOL;
- mloopcol = dm->getLoopDataArray(dm, colType);
- }
- }
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- const int active_uv_layer = CustomData_get_active_layer_index(&dm->loopData, CD_MLOOPUV);
- if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, true, active_uv_layer) == false)) {
- return;
- }
- if (drawParams == NULL) {
- ccgSubSurf_drawGLMesh(ss, true, -1, -1);
- return;
- }
- const int level = ccgSubSurf_getSubdivisionLevels(ss);
- const int face_side = 1 << level;
- const int grid_side = 1 << (level - 1);
- const int face_patches = face_side * face_side;
- const int grid_patches = grid_side * grid_side;
- const int num_base_faces = ccgSubSurf_getNumGLMeshBaseFaces(ss);
- int current_patch = 0;
- int mat_nr = -1;
- int start_draw_patch = 0, num_draw_patches = 0;
- bool draw_smooth = false;
- for (i = 0; i < num_base_faces; ++i) {
- const int num_face_verts = ccgSubSurf_getNumGLMeshBaseFaceVerts(ss, i);
- const int num_patches = (num_face_verts == 4) ? face_patches
- : num_face_verts * grid_patches;
- if (faceFlags) {
- mat_nr = faceFlags[i].mat_nr;
- draw_smooth = (faceFlags[i].flag & ME_SMOOTH);
- }
- else {
- mat_nr = 0;
- draw_smooth = false;
- }
-
- if (drawParams != NULL) {
- MTexPoly *tp = (use_tface && mtexpoly) ? &mtexpoly[i] : NULL;
- draw_option = drawParams(tp, (mloopcol != NULL), mat_nr);
- }
- else {
- draw_option = (drawParamsMapped)
- ? drawParamsMapped(userData, i, mat_nr)
- : DM_DRAW_OPTION_NORMAL;
- }
-
- flush = (draw_option == DM_DRAW_OPTION_SKIP) || (i == num_base_faces - 1);
-
- const int next_face = min_ii(i + 1, num_base_faces - 1);
- if (!flush && compareDrawOptions) {
- flush |= compareDrawOptions(userData, i, next_face) == 0;
- }
- if (!flush && faceFlags) {
- bool new_draw_smooth = (faceFlags[next_face].flag & ME_SMOOTH);
- flush |= (new_draw_smooth != draw_smooth);
- }
-
- current_patch += num_patches;
-
- if (flush) {
- if (draw_option != DM_DRAW_OPTION_SKIP) {
- num_draw_patches += num_patches;
- }
- if (num_draw_patches != 0) {
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss,
- true,
- start_draw_patch,
- num_draw_patches);
- }
- start_draw_patch = current_patch;
- num_draw_patches = 0;
- }
- else {
- num_draw_patches += num_patches;
- }
- }
- glShadeModel(GL_SMOOTH);
- return;
- }
-#endif
-
- CCG_key_top_level(&key, ss);
- ccgdm_pbvh_update(ccgdm);
-
- GPU_vertex_setup(dm);
- GPU_normal_setup(dm);
- GPU_triangle_setup(dm);
- if (flag & DM_DRAW_USE_TEXPAINT_UV)
- GPU_texpaint_uv_setup(dm);
- else
- GPU_uv_setup(dm);
- if (mloopcol) {
- GPU_color_setup(dm, colType);
- }
-
- next_actualFace = 0;
-
- /* lastFlag = 0; */ /* UNUSED */
- for (mat_index = 0; mat_index < dm->drawObject->totmaterial; mat_index++) {
- GPUBufferMaterial *bufmat = dm->drawObject->materials + mat_index;
- next_actualFace = bufmat->polys[0];
- totpoly = bufmat->totpolys;
-
- tot_element = 0;
- tot_drawn = 0;
- start_element = 0;
-
- for (i = 0; i < totpoly; i++) {
- int polyindex = bufmat->polys[i];
- CCGFace *f = ccgdm->faceMap[polyindex].face;
- int numVerts = ccgSubSurf_getFaceNumVerts(f);
- int index = ccgDM_getFaceMapIndex(ss, f);
- int orig_index = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
- int mat_nr;
- int facequads = numVerts * gridFaces * gridFaces;
- int actualFace = ccgdm->faceMap[polyindex].startFace;
-
- if (i != totpoly - 1) {
- polyindex = bufmat->polys[i + 1];
- next_actualFace = ccgdm->faceMap[polyindex].startFace;
- }
-
- if (faceFlags) {
- mat_nr = faceFlags[orig_index].mat_nr;
- }
- else {
- mat_nr = 0;
- }
-
- if (drawParams) {
- MTexPoly *tp = (use_tface && mtexpoly) ? &mtexpoly[actualFace] : NULL;
- draw_option = drawParams(tp, (mloopcol != NULL), mat_nr);
- }
- else if (index != ORIGINDEX_NONE)
- draw_option = (drawParamsMapped) ? drawParamsMapped(userData, index, mat_nr) : DM_DRAW_OPTION_NORMAL;
- else
- draw_option = DM_DRAW_OPTION_NORMAL;
-
- /* flush buffer if current triangle isn't drawable or it's last triangle */
- flush = (draw_option == DM_DRAW_OPTION_SKIP) || (i == totpoly - 1);
-
- if (!flush && compareDrawOptions) {
- /* also compare draw options and flush buffer if they're different
- * need for face selection highlight in edit mode */
- flush |= compareDrawOptions(userData, actualFace, next_actualFace) == 0;
- }
-
- tot_element += facequads * 6;
-
- if (flush) {
- if (draw_option != DM_DRAW_OPTION_SKIP)
- tot_drawn += facequads * 6;
-
- if (tot_drawn) {
- if (mloopcol && draw_option != DM_DRAW_OPTION_NO_MCOL)
- GPU_color_switch(1);
- else
- GPU_color_switch(0);
-
- GPU_buffer_draw_elements(dm->drawObject->triangles, GL_TRIANGLES, bufmat->start + start_element, tot_drawn);
- tot_drawn = 0;
- }
-
- start_element = tot_element;
- }
- else {
- tot_drawn += facequads * 6;
- }
- }
- }
-
-
- GPU_buffers_unbind();
-}
-
-static void ccgDM_drawFacesTex(DerivedMesh *dm,
- DMSetDrawOptionsTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- ccgDM_drawFacesTex_common(dm, setDrawOptions, NULL, compareDrawOptions, userData, flag);
-}
-
-static void ccgDM_drawMappedFacesTex(DerivedMesh *dm,
- DMSetDrawOptionsMappedTex setDrawOptions,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- ccgDM_drawFacesTex_common(dm, NULL, setDrawOptions, compareDrawOptions, userData, flag);
-}
-
-/* same as cdDM_drawUVEdges */
-static void ccgDM_drawUVEdges(DerivedMesh *dm)
-{
- MPoly *mpoly = dm->getPolyArray(dm);
- int totpoly = dm->getNumPolys(dm);
- int prevstart = 0;
- bool prevdraw = true;
- int curpos = 0;
- int i;
-
- GPU_uvedge_setup(dm);
- for (i = 0; i < totpoly; i++, mpoly++) {
- const bool draw = (mpoly->flag & ME_HIDE) == 0;
-
- if (prevdraw != draw) {
- if (prevdraw && (curpos != prevstart)) {
- glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
- }
- prevstart = curpos;
- }
-
- curpos += 2 * mpoly->totloop;
- prevdraw = draw;
- }
- if (prevdraw && (curpos != prevstart)) {
- glDrawArrays(GL_LINES, prevstart, curpos - prevstart);
- }
- GPU_buffers_unbind();
-}
-
-static void ccgDM_drawMappedFaces(DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetMaterial setMaterial,
- DMCompareDrawOptions compareDrawOptions,
- void *userData, DMDrawFlag flag)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- MLoopCol *mloopcol = NULL;
- const float (*lnors)[3] = dm->getLoopDataArray(dm, CD_NORMAL);
- int i, gridSize = ccgSubSurf_getGridSize(ss);
- DMFlagMat *faceFlags = ccgdm->faceFlags;
- int useColors = flag & DM_DRAW_USE_COLORS;
- int gridFaces = gridSize - 1, totface;
- int prev_mat_nr = -1;
-
- if (ccgdm->pbvh) {
- if (G.debug_value == 14)
- BKE_pbvh_draw_BB(ccgdm->pbvh);
- }
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- int new_matnr;
- bool draw_smooth, do_draw = true;
- if (setDrawOptions == NULL) {
- /* TODO(sergey): This is for cases when vertex colors or weights
- * are visualising. Currently we don't have CD layers for this data
- * and here we only make it so there's no garbage displayed.
- *
- * In the future we'll either need to have CD for this data or pass
- * this data as face-varying or vertex-varying data in OSD mesh.
- */
- glColor3f(0.8f, 0.8f, 0.8f);
- }
- if (UNLIKELY(ccgSubSurf_prepareGLMesh(ss, true, -1) == false)) {
- return;
- }
- if (faceFlags) {
- draw_smooth = (faceFlags[0].flag & ME_SMOOTH);
- new_matnr = (faceFlags[0].mat_nr + 1);
- }
- else {
- draw_smooth = true;
- new_matnr = 1;
- }
- if (setMaterial) {
- setMaterial(new_matnr, NULL);
- }
- if (setDrawOptions) {
- if (setDrawOptions(userData, 0) == DM_DRAW_OPTION_SKIP) {
- do_draw = false;
- }
- }
- if (do_draw) {
- glShadeModel(draw_smooth ? GL_SMOOTH : GL_FLAT);
- ccgSubSurf_drawGLMesh(ss, true, -1, -1);
- glShadeModel(GL_SMOOTH);
- }
- return;
- }
-#endif
-
- CCG_key_top_level(&key, ss);
-
- /* currently unused -- each original face is handled separately */
- (void)compareDrawOptions;
-
- if (useColors) {
- mloopcol = dm->getLoopDataArray(dm, CD_PREVIEW_MLOOPCOL);
- if (!mloopcol)
- mloopcol = dm->getLoopDataArray(dm, CD_MLOOPCOL);
- }
-
- totface = ccgSubSurf_getNumFaces(ss);
- for (i = 0; i < totface; i++) {
- CCGFace *f = ccgdm->faceMap[i].face;
- int S, x, y, numVerts = ccgSubSurf_getFaceNumVerts(f);
- int drawSmooth, index = ccgDM_getFaceMapIndex(ss, f);
- int origIndex;
- unsigned char *cp = NULL;
- const float (*ln)[3] = NULL;
-
- origIndex = GET_INT_FROM_POINTER(ccgSubSurf_getFaceFaceHandle(f));
-
- if (flag & DM_DRAW_ALWAYS_SMOOTH) drawSmooth = 1;
- else if (faceFlags) drawSmooth = (lnors || (faceFlags[origIndex].flag & ME_SMOOTH));
- else drawSmooth = 1;
-
- if (mloopcol) {
- cp = (unsigned char *)mloopcol;
- mloopcol += gridFaces * gridFaces * numVerts * 4;
- }
-
- if (lnors) {
- ln = lnors;
- lnors += (gridFaces * gridFaces * numVerts) * 4;
- }
-
- {
- DMDrawOption draw_option = DM_DRAW_OPTION_NORMAL;
-
- if (setMaterial) {
- int mat_nr = faceFlags ? faceFlags[origIndex].mat_nr + 1 : 1;
-
- if (mat_nr != prev_mat_nr) {
- setMaterial(mat_nr, NULL); /* XXX, no faceFlags no material */
- prev_mat_nr = mat_nr;
- }
- }
-
- if (setDrawOptions && (index != ORIGINDEX_NONE))
- draw_option = setDrawOptions(userData, index);
-
- if (draw_option != DM_DRAW_OPTION_SKIP) {
- if (draw_option == DM_DRAW_OPTION_STIPPLE) {
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
- }
-
- for (S = 0; S < numVerts; S++) {
- CCGElem *faceGridData = ccgSubSurf_getFaceGridDataArray(ss, f, S);
- if (ln) {
- glBegin(GL_QUADS);
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- float *a = CCG_grid_elem_co(&key, faceGridData, x, y + 0);
- float *b = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 0);
- float *c = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *d = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- if (cp) glColor4ubv(&cp[4]);
- glNormal3fv(ln[1]);
- glVertex3fv(d);
- if (cp) glColor4ubv(&cp[8]);
- glNormal3fv(ln[2]);
- glVertex3fv(c);
- if (cp) glColor4ubv(&cp[12]);
- glNormal3fv(ln[3]);
- glVertex3fv(b);
- if (cp) glColor4ubv(&cp[0]);
- glNormal3fv(ln[0]);
- glVertex3fv(a);
-
- if (cp) cp += 16;
- ln += 4;
- }
- }
- glEnd();
- }
- else if (drawSmooth) {
- for (y = 0; y < gridFaces; y++) {
- CCGElem *a, *b;
- glBegin(GL_QUAD_STRIP);
- for (x = 0; x < gridFaces; x++) {
- a = CCG_grid_elem(&key, faceGridData, x, y + 0);
- b = CCG_grid_elem(&key, faceGridData, x, y + 1);
-
- if (cp) glColor4ubv(&cp[0]);
- glNormal3fv(CCG_elem_no(&key, a));
- glVertex3fv(CCG_elem_co(&key, a));
- if (cp) glColor4ubv(&cp[4]);
- glNormal3fv(CCG_elem_no(&key, b));
- glVertex3fv(CCG_elem_co(&key, b));
-
- if (x != gridFaces - 1) {
- if (cp) cp += 16;
- }
- }
-
- a = CCG_grid_elem(&key, faceGridData, x, y + 0);
- b = CCG_grid_elem(&key, faceGridData, x, y + 1);
-
- if (cp) glColor4ubv(&cp[12]);
- glNormal3fv(CCG_elem_no(&key, a));
- glVertex3fv(CCG_elem_co(&key, a));
- if (cp) glColor4ubv(&cp[8]);
- glNormal3fv(CCG_elem_no(&key, b));
- glVertex3fv(CCG_elem_co(&key, b));
-
- if (cp) cp += 16;
-
- glEnd();
- }
- }
- else {
- glBegin(GL_QUADS);
- for (y = 0; y < gridFaces; y++) {
- for (x = 0; x < gridFaces; x++) {
- float *a = CCG_grid_elem_co(&key, faceGridData, x, y + 0);
- float *b = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 0);
- float *c = CCG_grid_elem_co(&key, faceGridData, x + 1, y + 1);
- float *d = CCG_grid_elem_co(&key, faceGridData, x, y + 1);
-
- ccgDM_glNormalFast(a, b, c, d);
-
- if (cp) glColor4ubv(&cp[4]);
- glVertex3fv(d);
- if (cp) glColor4ubv(&cp[8]);
- glVertex3fv(c);
- if (cp) glColor4ubv(&cp[12]);
- glVertex3fv(b);
- if (cp) glColor4ubv(&cp[0]);
- glVertex3fv(a);
-
- if (cp) cp += 16;
- }
- }
- glEnd();
- }
- }
- if (draw_option == DM_DRAW_OPTION_STIPPLE)
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
- }
- }
-}
-
-static void ccgDM_drawMappedEdges(DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- void *userData)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGEdgeIterator ei;
- CCGKey key;
- int i, useAging, edgeSize = ccgSubSurf_getEdgeSize(ss);
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- /* TODO(sergey): Only draw edges from base mesh. */
- if (ccgSubSurf_prepareGLMesh(ccgdm->ss, true, -1)) {
- if (!setDrawOptions || (setDrawOptions(userData, 0) != DM_DRAW_OPTION_SKIP)) {
- ccgSubSurf_drawGLMesh(ccgdm->ss, false, -1, -1);
- }
- }
- return;
- }
-#endif
-
- CCG_key_top_level(&key, ss);
- ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL);
-
- for (ccgSubSurf_initEdgeIterator(ss, &ei); !ccgEdgeIterator_isStopped(&ei); ccgEdgeIterator_next(&ei)) {
- CCGEdge *e = ccgEdgeIterator_getCurrent(&ei);
- CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
- int index = ccgDM_getEdgeMapIndex(ss, e);
-
- glBegin(GL_LINE_STRIP);
- if (index != -1 && (!setDrawOptions || (setDrawOptions(userData, index) != DM_DRAW_OPTION_SKIP))) {
- if (useAging && !(G.f & G_BACKBUFSEL)) {
- int ageCol = 255 - ccgSubSurf_getEdgeAge(ss, e) * 4;
- glColor3ub(0, ageCol > 0 ? ageCol : 0, 0);
- }
-
- for (i = 0; i < edgeSize - 1; i++) {
- glVertex3fv(CCG_elem_offset_co(&key, edgeData, i));
- glVertex3fv(CCG_elem_offset_co(&key, edgeData, i + 1));
- }
- }
- glEnd();
- }
-}
-
-static void ccgDM_drawMappedEdgesInterp(DerivedMesh *dm,
- DMSetDrawOptions setDrawOptions,
- DMSetDrawInterpOptions setDrawInterpOptions,
- void *userData)
-{
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) dm;
- CCGSubSurf *ss = ccgdm->ss;
- CCGKey key;
- CCGEdgeIterator ei;
- int i, useAging, edgeSize = ccgSubSurf_getEdgeSize(ss);
-
-#ifdef WITH_OPENSUBDIV
- if (ccgdm->useGpuBackend) {
- BLI_assert(!"Not currently supported");
- return;
- }
-#endif
-
- CCG_key_top_level(&key, ss);
- ccgSubSurf_getUseAgeCounts(ss, &useAging, NULL, NULL, NULL);
-
- for (ccgSubSurf_initEdgeIterator(ss, &ei); !ccgEdgeIterator_isStopped(&ei); ccgEdgeIterator_next(&ei)) {
- CCGEdge *e = ccgEdgeIterator_getCurrent(&ei);
- CCGElem *edgeData = ccgSubSurf_getEdgeDataArray(ss, e);
- int index = ccgDM_getEdgeMapIndex(ss, e);
-
- glBegin(GL_LINE_STRIP);
- if (index != -1 && (!setDrawOptions || (setDrawOptions(userData, index) != DM_DRAW_OPTION_SKIP))) {
- for (i = 0; i < edgeSize; i++) {
- setDrawInterpOptions(userData, index, (float) i / (edgeSize - 1));
-
- if (useAging && !(G.f & G_BACKBUFSEL)) {
- int ageCol = 255 - ccgSubSurf_getEdgeAge(ss, e) * 4;
- glColor3ub(0, ageCol > 0 ? ageCol : 0, 0);
- }
-
- glVertex3fv(CCG_elem_offset_co(&key, edgeData, i));
- }
- }
- glEnd();
- }
-}
-
static void ccgDM_foreachMappedFaceCenter(
DerivedMesh *dm,
void (*func)(void *userData, int index, const float co[3], const float no[3]),
@@ -4687,23 +2468,6 @@ static void set_default_ccgdm_callbacks(CCGDerivedMesh *ccgdm)
ccgdm->dm.foreachMappedLoop = ccgDM_foreachMappedLoop;
ccgdm->dm.foreachMappedFaceCenter = ccgDM_foreachMappedFaceCenter;
- ccgdm->dm.drawVerts = ccgDM_drawVerts;
- ccgdm->dm.drawEdges = ccgDM_drawEdges;
- ccgdm->dm.drawLooseEdges = ccgDM_drawLooseEdges;
- ccgdm->dm.drawFacesSolid = ccgDM_drawFacesSolid;
- ccgdm->dm.drawFacesTex = ccgDM_drawFacesTex;
- ccgdm->dm.drawFacesGLSL = ccgDM_drawFacesGLSL;
- ccgdm->dm.drawMappedFaces = ccgDM_drawMappedFaces;
- ccgdm->dm.drawMappedFacesTex = ccgDM_drawMappedFacesTex;
- ccgdm->dm.drawMappedFacesGLSL = ccgDM_drawMappedFacesGLSL;
- ccgdm->dm.drawMappedFacesMat = ccgDM_drawMappedFacesMat;
- ccgdm->dm.drawUVEdges = ccgDM_drawUVEdges;
-
- ccgdm->dm.drawMappedEdgesInterp = ccgDM_drawMappedEdgesInterp;
- ccgdm->dm.drawMappedEdges = ccgDM_drawMappedEdges;
- ccgdm->dm.gpuObjectNew = ccgDM_GPUObjectNew;
- ccgdm->dm.copy_gpu_data = ccgDM_copy_gpu_data;
-
ccgdm->dm.release = ccgDM_release;
}
@@ -5155,8 +2919,7 @@ static bool subsurf_use_gpu_backend(SubsurfFlags flags)
*/
return
(flags & SUBSURF_USE_GPU_BACKEND) != 0 &&
- (U.opensubdiv_compute_type != USER_OPENSUBDIV_COMPUTE_NONE) &&
- (openSubdiv_supportGPUDisplay());
+ (U.opensubdiv_compute_type != USER_OPENSUBDIV_COMPUTE_NONE);
#else
(void)flags;
return false;
diff --git a/source/blender/blenkernel/intern/text.c b/source/blender/blenkernel/intern/text.c
index b650b6e9fb8..3892b2f0546 100644
--- a/source/blender/blenkernel/intern/text.c
+++ b/source/blender/blenkernel/intern/text.c
@@ -47,8 +47,6 @@
#include "BLI_fileops.h"
#include "DNA_constraint_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
@@ -58,7 +56,6 @@
#include "DNA_node_types.h"
#include "DNA_material_types.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
diff --git a/source/blender/blenkernel/intern/texture.c b/source/blender/blenkernel/intern/texture.c
index 250408642bb..2bf2fa7807b 100644
--- a/source/blender/blenkernel/intern/texture.c
+++ b/source/blender/blenkernel/intern/texture.c
@@ -44,9 +44,7 @@
#include "DNA_key_types.h"
#include "DNA_object_types.h"
-#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
-#include "DNA_world_types.h"
#include "DNA_brush_types.h"
#include "DNA_node_types.h"
#include "DNA_color_types.h"
@@ -213,22 +211,6 @@ void BKE_texture_free(Tex *tex)
}
MEM_SAFE_FREE(tex->coba);
- if (tex->env) {
- BKE_texture_envmap_free(tex->env);
- tex->env = NULL;
- }
- if (tex->pd) {
- BKE_texture_pointdensity_free(tex->pd);
- tex->pd = NULL;
- }
- if (tex->vd) {
- BKE_texture_voxeldata_free(tex->vd);
- tex->vd = NULL;
- }
- if (tex->ot) {
- BKE_texture_ocean_free(tex->ot);
- tex->ot = NULL;
- }
BKE_icon_id_delete((ID *)tex);
BKE_previewimg_free(&tex->preview);
@@ -285,30 +267,6 @@ void BKE_texture_default(Tex *tex)
tex->vn_distm = 0;
tex->vn_coltype = 0;
- if (tex->env) {
- tex->env->stype = ENV_ANIM;
- tex->env->clipsta = 0.1;
- tex->env->clipend = 100;
- tex->env->cuberes = 512;
- tex->env->depth = 0;
- }
-
- if (tex->pd) {
- tex->pd->radius = 0.3f;
- tex->pd->falloff_type = TEX_PD_FALLOFF_STD;
- }
-
- if (tex->vd) {
- tex->vd->resol[0] = tex->vd->resol[1] = tex->vd->resol[2] = 0;
- tex->vd->interp_type = TEX_VD_LINEAR;
- tex->vd->file_format = TEX_VD_SMOKE;
- }
-
- if (tex->ot) {
- tex->ot->output = TEX_OCN_DISPLACEMENT;
- tex->ot->object = NULL;
- }
-
tex->iuser.fie_ima = 2;
tex->iuser.ok = 1;
tex->iuser.frames = 100;
@@ -319,26 +277,6 @@ void BKE_texture_default(Tex *tex)
void BKE_texture_type_set(Tex *tex, int type)
{
- switch (type) {
-
- case TEX_VOXELDATA:
- if (tex->vd == NULL)
- tex->vd = BKE_texture_voxeldata_add();
- break;
- case TEX_POINTDENSITY:
- if (tex->pd == NULL)
- tex->pd = BKE_texture_pointdensity_add();
- break;
- case TEX_ENVMAP:
- if (tex->env == NULL)
- tex->env = BKE_texture_envmap_add();
- break;
- case TEX_OCEAN:
- if (tex->ot == NULL)
- tex->ot = BKE_texture_ocean_add();
- break;
- }
-
tex->type = type;
}
@@ -476,10 +414,6 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot)
MEM_freeN(mtex_ar[slot]);
mtex_ar[slot] = NULL;
}
- else if (GS(id->name) == ID_MA) {
- /* Reset this slot's ON/OFF toggle, for materials, when slot was empty. */
- ((Material *)id)->septex &= ~(1 << slot);
- }
mtex_ar[slot] = BKE_texture_mtex_add();
@@ -498,9 +432,6 @@ MTex *BKE_texture_mtex_add_id(ID *id, int slot)
*/
void BKE_texture_copy_data(Main *bmain, Tex *tex_dst, const Tex *tex_src, const int flag)
{
- /* We never handle usercount here for own data. */
- const int flag_subdata = flag | LIB_ID_CREATE_NO_USER_REFCOUNT;
-
if (!BKE_texture_is_image_user(tex_src)) {
tex_dst->ima = NULL;
}
@@ -508,19 +439,6 @@ void BKE_texture_copy_data(Main *bmain, Tex *tex_dst, const Tex *tex_src, const
if (tex_dst->coba) {
tex_dst->coba = MEM_dupallocN(tex_dst->coba);
}
- if (tex_dst->env) {
- tex_dst->env = BKE_texture_envmap_copy(tex_dst->env, flag_subdata);
- }
- if (tex_dst->pd) {
- tex_dst->pd = BKE_texture_pointdensity_copy(tex_dst->pd, flag_subdata);
- }
- if (tex_dst->vd) {
- tex_dst->vd = MEM_dupallocN(tex_dst->vd);
- }
- if (tex_dst->ot) {
- tex_dst->ot = BKE_texture_ocean_copy(tex_dst->ot, flag_subdata);
- }
-
if (tex_src->nodetree) {
if (tex_src->nodetree->execdata) {
ntreeTexEndExecTree(tex_src->nodetree->execdata);
@@ -562,19 +480,6 @@ Tex *BKE_texture_localize(Tex *tex)
/* image texture: BKE_texture_free also doesn't decrease */
if (texn->coba) texn->coba = MEM_dupallocN(texn->coba);
- if (texn->env) {
- texn->env = BKE_texture_envmap_copy(texn->env, LIB_ID_CREATE_NO_USER_REFCOUNT);
- id_us_min(&texn->env->ima->id);
- }
- if (texn->pd) texn->pd = BKE_texture_pointdensity_copy(texn->pd, LIB_ID_CREATE_NO_USER_REFCOUNT);
- if (texn->vd) {
- texn->vd = MEM_dupallocN(texn->vd);
- if (texn->vd->dataset)
- texn->vd->dataset = MEM_dupallocN(texn->vd->dataset);
- }
- if (texn->ot) {
- texn->ot = BKE_texture_ocean_copy(tex->ot, LIB_ID_CREATE_NO_USER_REFCOUNT);
- }
texn->preview = NULL;
@@ -593,64 +498,6 @@ void BKE_texture_make_local(Main *bmain, Tex *tex, const bool lib_local)
BKE_id_make_local_generic(bmain, &tex->id, true, lib_local);
}
-Tex *give_current_object_texture(Object *ob)
-{
- Material *ma, *node_ma;
- Tex *tex = NULL;
-
- if (ob == NULL) return NULL;
- if (ob->totcol == 0 && !(ob->type == OB_LAMP)) return NULL;
-
- if (ob->type == OB_LAMP) {
- tex = give_current_lamp_texture(ob->data);
- }
- else {
- ma = give_current_material(ob, ob->actcol);
-
- if ((node_ma = give_node_material(ma)))
- ma = node_ma;
-
- tex = give_current_material_texture(ma);
- }
-
- return tex;
-}
-
-Tex *give_current_lamp_texture(Lamp *la)
-{
- MTex *mtex = NULL;
- Tex *tex = NULL;
-
- if (la) {
- mtex = la->mtex[(int)(la->texact)];
- if (mtex) tex = mtex->tex;
- }
-
- return tex;
-}
-
-void set_current_lamp_texture(Lamp *la, Tex *newtex)
-{
- int act = la->texact;
-
- if (la->mtex[act] && la->mtex[act]->tex)
- id_us_min(&la->mtex[act]->tex->id);
-
- if (newtex) {
- if (!la->mtex[act]) {
- la->mtex[act] = BKE_texture_mtex_add();
- la->mtex[act]->texco = TEXCO_GLOB;
- }
-
- la->mtex[act]->tex = newtex;
- id_us_plus(&newtex->id);
- }
- else if (la->mtex[act]) {
- MEM_freeN(la->mtex[act]);
- la->mtex[act] = NULL;
- }
-}
-
Tex *give_current_linestyle_texture(FreestyleLineStyle *linestyle)
{
MTex *mtex = NULL;
@@ -686,55 +533,9 @@ void set_current_linestyle_texture(FreestyleLineStyle *linestyle, Tex *newtex)
}
}
-bNode *give_current_material_texture_node(Material *ma)
-{
- if (ma && ma->use_nodes && ma->nodetree)
- return nodeGetActiveID(ma->nodetree, ID_TE);
-
- return NULL;
-}
-
-Tex *give_current_material_texture(Material *ma)
-{
- MTex *mtex = NULL;
- Tex *tex = NULL;
- bNode *node;
-
- if (ma && ma->use_nodes && ma->nodetree) {
- /* first check texture, then material, this works together
- * with a hack that clears the active ID flag for textures on
- * making a material node active */
- node = nodeGetActiveID(ma->nodetree, ID_TE);
-
- if (node) {
- tex = (Tex *)node->id;
- ma = NULL;
- }
- }
-
- if (ma) {
- mtex = ma->mtex[(int)(ma->texact)];
- if (mtex) tex = mtex->tex;
- }
-
- return tex;
-}
-
bool give_active_mtex(ID *id, MTex ***mtex_ar, short *act)
{
switch (GS(id->name)) {
- case ID_MA:
- *mtex_ar = ((Material *)id)->mtex;
- if (act) *act = (((Material *)id)->texact);
- break;
- case ID_WO:
- *mtex_ar = ((World *)id)->mtex;
- if (act) *act = (((World *)id)->texact);
- break;
- case ID_LA:
- *mtex_ar = ((Lamp *)id)->mtex;
- if (act) *act = (((Lamp *)id)->texact);
- break;
case ID_LS:
*mtex_ar = ((FreestyleLineStyle *)id)->mtex;
if (act) *act = (((FreestyleLineStyle *)id)->texact);
@@ -758,15 +559,6 @@ void set_active_mtex(ID *id, short act)
else if (act >= MAX_MTEX) act = MAX_MTEX - 1;
switch (GS(id->name)) {
- case ID_MA:
- ((Material *)id)->texact = act;
- break;
- case ID_WO:
- ((World *)id)->texact = act;
- break;
- case ID_LA:
- ((Lamp *)id)->texact = act;
- break;
case ID_LS:
((FreestyleLineStyle *)id)->texact = act;
break;
@@ -778,100 +570,6 @@ void set_active_mtex(ID *id, short act)
}
}
-void set_current_material_texture(Material *ma, Tex *newtex)
-{
- Tex *tex = NULL;
- bNode *node;
-
- if ((ma->use_nodes && ma->nodetree) &&
- (node = nodeGetActiveID(ma->nodetree, ID_TE)))
- {
- tex = (Tex *)node->id;
- id_us_min(&tex->id);
- if (newtex) {
- node->id = &newtex->id;
- id_us_plus(&newtex->id);
- }
- else {
- node->id = NULL;
- }
- }
- else {
- int act = (int)ma->texact;
-
- tex = (ma->mtex[act]) ? ma->mtex[act]->tex : NULL;
- id_us_min(&tex->id);
-
- if (newtex) {
- if (!ma->mtex[act]) {
- ma->mtex[act] = BKE_texture_mtex_add();
- /* Reset this slot's ON/OFF toggle, for materials, when slot was empty. */
- ma->septex &= ~(1 << act);
- /* For volumes the default UV texture coordinates are not available. */
- if (ma->material_type == MA_TYPE_VOLUME) {
- ma->mtex[act]->texco = TEXCO_ORCO;
- }
- }
-
- ma->mtex[act]->tex = newtex;
- id_us_plus(&newtex->id);
- }
- else if (ma->mtex[act]) {
- MEM_freeN(ma->mtex[act]);
- ma->mtex[act] = NULL;
- }
- }
-}
-
-bool has_current_material_texture(Material *ma)
-{
- bNode *node;
-
- if (ma && ma->use_nodes && ma->nodetree) {
- node = nodeGetActiveID(ma->nodetree, ID_TE);
-
- if (node)
- return true;
- }
-
- return (ma != NULL);
-}
-
-Tex *give_current_world_texture(World *world)
-{
- MTex *mtex = NULL;
- Tex *tex = NULL;
-
- if (!world) return NULL;
-
- mtex = world->mtex[(int)(world->texact)];
- if (mtex) tex = mtex->tex;
-
- return tex;
-}
-
-void set_current_world_texture(World *wo, Tex *newtex)
-{
- int act = wo->texact;
-
- if (wo->mtex[act] && wo->mtex[act]->tex)
- id_us_min(&wo->mtex[act]->tex->id);
-
- if (newtex) {
- if (!wo->mtex[act]) {
- wo->mtex[act] = BKE_texture_mtex_add();
- wo->mtex[act]->texco = TEXCO_VIEW;
- }
-
- wo->mtex[act]->tex = newtex;
- id_us_plus(&newtex->id);
- }
- else if (wo->mtex[act]) {
- MEM_freeN(wo->mtex[act]);
- wo->mtex[act] = NULL;
- }
-}
-
Tex *give_current_brush_texture(Brush *br)
{
return br->mtex.tex;
@@ -926,65 +624,6 @@ void set_current_particle_texture(ParticleSettings *part, Tex *newtex)
/* ------------------------------------------------------------------------- */
-EnvMap *BKE_texture_envmap_add(void)
-{
- EnvMap *env;
-
- env = MEM_callocN(sizeof(EnvMap), "envmap");
- env->type = ENV_CUBE;
- env->stype = ENV_ANIM;
- env->clipsta = 0.1;
- env->clipend = 100.0;
- env->cuberes = 512;
- env->viewscale = 0.5;
-
- return env;
-}
-
-/* ------------------------------------------------------------------------- */
-
-EnvMap *BKE_texture_envmap_copy(const EnvMap *env, const int flag)
-{
- EnvMap *envn;
- int a;
-
- envn = MEM_dupallocN(env);
- envn->ok = 0;
- for (a = 0; a < 6; a++) {
- envn->cube[a] = NULL;
- }
- if ((flag & LIB_ID_CREATE_NO_USER_REFCOUNT) == 0) {
- id_us_plus((ID *)envn->ima);
- }
-
- return envn;
-}
-
-/* ------------------------------------------------------------------------- */
-
-void BKE_texture_envmap_free_data(EnvMap *env)
-{
- unsigned int part;
-
- for (part = 0; part < 6; part++) {
- if (env->cube[part])
- IMB_freeImBuf(env->cube[part]);
- env->cube[part] = NULL;
- }
- env->ok = 0;
-}
-
-/* ------------------------------------------------------------------------- */
-
-void BKE_texture_envmap_free(EnvMap *env)
-{
-
- BKE_texture_envmap_free_data(env);
- MEM_freeN(env);
-
-}
-
-/* ------------------------------------------------------------------------- */
void BKE_texture_pointdensity_init_data(PointDensity *pd)
{
@@ -1057,77 +696,8 @@ void BKE_texture_pointdensity_free(PointDensity *pd)
BKE_texture_pointdensity_free_data(pd);
MEM_freeN(pd);
}
-
/* ------------------------------------------------------------------------- */
-void BKE_texture_voxeldata_free_data(VoxelData *vd)
-{
- if (vd->dataset) {
- MEM_freeN(vd->dataset);
- vd->dataset = NULL;
- }
-
-}
-
-void BKE_texture_voxeldata_free(VoxelData *vd)
-{
- BKE_texture_voxeldata_free_data(vd);
- MEM_freeN(vd);
-}
-
-VoxelData *BKE_texture_voxeldata_add(void)
-{
- VoxelData *vd;
-
- vd = MEM_callocN(sizeof(VoxelData), "voxeldata");
- vd->dataset = NULL;
- vd->resol[0] = vd->resol[1] = vd->resol[2] = 1;
- vd->interp_type = TEX_VD_LINEAR;
- vd->file_format = TEX_VD_SMOKE;
- vd->int_multiplier = 1.0;
- vd->extend = TEX_CLIP;
- vd->object = NULL;
- vd->cachedframe = -1;
- vd->ok = 0;
-
- return vd;
-}
-
-VoxelData *BKE_texture_voxeldata_copy(VoxelData *vd)
-{
- VoxelData *vdn;
-
- vdn = MEM_dupallocN(vd);
- vdn->dataset = NULL;
-
- return vdn;
-}
-
-/* ------------------------------------------------------------------------- */
-
-OceanTex *BKE_texture_ocean_add(void)
-{
- OceanTex *ot;
-
- ot = MEM_callocN(sizeof(struct OceanTex), "ocean texture");
- ot->output = TEX_OCN_DISPLACEMENT;
- ot->object = NULL;
-
- return ot;
-}
-
-OceanTex *BKE_texture_ocean_copy(const OceanTex *ot, const int UNUSED(flag))
-{
- OceanTex *otn = MEM_dupallocN(ot);
-
- return otn;
-}
-
-void BKE_texture_ocean_free(struct OceanTex *ot)
-{
- MEM_freeN(ot);
-}
-
/**
* \returns true if this texture can use its #Texture.ima (even if its NULL)
*/
@@ -1138,15 +708,6 @@ bool BKE_texture_is_image_user(const struct Tex *tex)
{
return true;
}
- case TEX_ENVMAP:
- {
- if (tex->env) {
- if (tex->env->stype == ENV_LOAD) {
- return true;
- }
- }
- break;
- }
}
return false;
diff --git a/source/blender/blenkernel/intern/tracking.c b/source/blender/blenkernel/intern/tracking.c
index f9d34534a45..3314e8d01b6 100644
--- a/source/blender/blenkernel/intern/tracking.c
+++ b/source/blender/blenkernel/intern/tracking.c
@@ -61,6 +61,7 @@
#include "BKE_movieclip.h"
#include "BKE_object.h"
#include "BKE_scene.h"
+#include "BKE_layer.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -400,7 +401,7 @@ void BKE_tracking_get_camera_object_matrix(Scene *scene, Object *ob, float mat[4
if (scene->camera)
ob = scene->camera;
else
- ob = BKE_scene_camera_find(scene);
+ ob = BKE_view_layer_camera_find(BKE_view_layer_context_active_PLACEHOLDER(scene));
}
if (ob)
diff --git a/source/blender/blenkernel/intern/undo_system.c b/source/blender/blenkernel/intern/undo_system.c
index 5a0081bff16..62710240109 100644
--- a/source/blender/blenkernel/intern/undo_system.c
+++ b/source/blender/blenkernel/intern/undo_system.c
@@ -39,6 +39,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
+#include "BKE_library_override.h"
#include "BKE_main.h"
#include "BKE_undo_system.h"
@@ -386,12 +387,19 @@ UndoStep *BKE_undosys_step_push_init(UndoStack *ustack, bContext *C, const char
return BKE_undosys_step_push_init_with_type(ustack, C, name, ut);
}
+/**
+ * \param C: Can be NULL from some callers if their encoding function doesn't need it
+ */
bool BKE_undosys_step_push_with_type(UndoStack *ustack, bContext *C, const char *name, const UndoType *ut)
{
UNDO_NESTED_ASSERT(false);
undosys_stack_validate(ustack, false);
bool is_not_empty = ustack->step_active != NULL;
+ /* Might not be final place for this to be called - probably only want to call it from some
+ * undo handlers, not all of them? */
+ BKE_main_override_static_operations_create(G.main, false);
+
/* Remove all undos after (also when 'ustack->step_active == NULL'). */
while (ustack->steps.last != ustack->step_active) {
UndoStep *us_iter = ustack->steps.last;
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
new file mode 100644
index 00000000000..38378f66584
--- /dev/null
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -0,0 +1,470 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/workspace.c
+ * \ingroup bke
+ */
+
+/* allow accessing private members of DNA_workspace_types.h */
+#define DNA_PRIVATE_WORKSPACE_ALLOW
+
+#include <stdlib.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
+#include "BLI_string_utils.h"
+#include "BLI_listbase.h"
+
+#include "BKE_global.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_object.h"
+#include "BKE_workspace.h"
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_workspace_types.h"
+
+#include "DEG_depsgraph.h"
+
+#include "MEM_guardedalloc.h"
+
+
+/* -------------------------------------------------------------------- */
+/* Internal utils */
+
+static void workspace_layout_name_set(
+ WorkSpace *workspace, WorkSpaceLayout *layout, const char *new_name)
+{
+ BLI_strncpy(layout->name, new_name, sizeof(layout->name));
+ BLI_uniquename(&workspace->layouts, layout, "Layout", '.', offsetof(WorkSpaceLayout, name), sizeof(layout->name));
+}
+
+/**
+ * This should only be used directly when it is to be expected that there isn't
+ * a layout within \a workspace that wraps \a screen. Usually - especially outside
+ * of BKE_workspace - #BKE_workspace_layout_find should be used!
+ */
+static WorkSpaceLayout *workspace_layout_find_exec(
+ const WorkSpace *workspace, const bScreen *screen)
+{
+ return BLI_findptr(&workspace->layouts, screen, offsetof(WorkSpaceLayout, screen));
+}
+
+static void workspace_relation_add(
+ ListBase *relation_list, void *parent, void *data)
+{
+ WorkSpaceDataRelation *relation = MEM_callocN(sizeof(*relation), __func__);
+ relation->parent = parent;
+ relation->value = data;
+ /* add to head, if we switch back to it soon we find it faster. */
+ BLI_addhead(relation_list, relation);
+}
+static void workspace_relation_remove(
+ ListBase *relation_list, WorkSpaceDataRelation *relation)
+{
+ BLI_remlink(relation_list, relation);
+ MEM_freeN(relation);
+}
+
+static void workspace_relation_ensure_updated(
+ ListBase *relation_list, void *parent, void *data)
+{
+ WorkSpaceDataRelation *relation = BLI_findptr(relation_list, parent, offsetof(WorkSpaceDataRelation, parent));
+ if (relation != NULL) {
+ relation->value = data;
+ /* reinsert at the head of the list, so that more commonly used relations are found faster. */
+ BLI_remlink(relation_list, relation);
+ BLI_addhead(relation_list, relation);
+ }
+ else {
+ /* no matching relation found, add new one */
+ workspace_relation_add(relation_list, parent, data);
+ }
+}
+
+static void *workspace_relation_get_data_matching_parent(
+ const ListBase *relation_list, const void *parent)
+{
+ WorkSpaceDataRelation *relation = BLI_findptr(relation_list, parent, offsetof(WorkSpaceDataRelation, parent));
+ if (relation != NULL) {
+ return relation->value;
+ }
+ else {
+ return NULL;
+ }
+}
+
+static void workspace_relation_remove_from_value(
+ ListBase *relation_list, const void *value)
+{
+ for (WorkSpaceDataRelation *relation = relation_list->first, *relation_next; relation; relation = relation_next) {
+ relation_next = relation->next;
+
+ if (relation->value == value) {
+ workspace_relation_remove(relation_list, relation);
+ }
+ }
+}
+
+/**
+ * Checks if \a screen is already used within any workspace. A screen should never be assigned to multiple
+ * WorkSpaceLayouts, but that should be ensured outside of the BKE_workspace module and without such checks.
+ * Hence, this should only be used as assert check before assigining a screen to a workspace.
+ */
+#ifndef NDEBUG
+static bool workspaces_is_screen_used
+#else
+static bool UNUSED_FUNCTION(workspaces_is_screen_used)
+#endif
+ (const Main *bmain, bScreen *screen)
+{
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ if (workspace_layout_find_exec(workspace, screen)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/* -------------------------------------------------------------------- */
+/* Create, delete, init */
+
+WorkSpace *BKE_workspace_add(Main *bmain, const char *name)
+{
+ WorkSpace *new_workspace = BKE_libblock_alloc(bmain, ID_WS, name, 0);
+ return new_workspace;
+}
+
+/**
+ * The function that actually frees the workspace data (not workspace itself). It shouldn't be called
+ * directly, instead #BKE_workspace_remove should be, which calls this through #BKE_libblock_free then.
+ *
+ * Should something like a bke_internal.h be added, this should go there!
+ */
+void BKE_workspace_free(WorkSpace *workspace)
+{
+ BKE_workspace_relations_free(&workspace->hook_layout_relations);
+ BKE_workspace_relations_free(&workspace->scene_viewlayer_relations);
+
+ BLI_freelistN(&workspace->owner_ids);
+ BLI_freelistN(&workspace->layouts);
+}
+
+/**
+ * Remove \a workspace by freeing itself and its data. This is a higher-level wrapper that
+ * calls #BKE_workspace_free (through #BKE_libblock_free) to free the workspace data, and frees
+ * other data-blocks owned by \a workspace and its layouts (currently that is screens only).
+ *
+ * Always use this to remove (and free) workspaces. Don't free non-ID workspace members here.
+ */
+void BKE_workspace_remove(Main *bmain, WorkSpace *workspace)
+{
+ for (WorkSpaceLayout *layout = workspace->layouts.first, *layout_next; layout; layout = layout_next) {
+ layout_next = layout->next;
+ BKE_workspace_layout_remove(bmain, workspace, layout);
+ }
+ BKE_libblock_free(bmain, workspace);
+}
+
+WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(const Main *bmain)
+{
+ WorkSpaceInstanceHook *hook = MEM_callocN(sizeof(WorkSpaceInstanceHook), __func__);
+
+ /* set an active screen-layout for each possible window/workspace combination */
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ BKE_workspace_hook_layout_for_workspace_set(hook, workspace, workspace->layouts.first);
+ }
+
+ return hook;
+}
+void BKE_workspace_instance_hook_free(const Main *bmain, WorkSpaceInstanceHook *hook)
+{
+ /* workspaces should never be freed before wm (during which we call this function) */
+ BLI_assert(!BLI_listbase_is_empty(&bmain->workspaces));
+
+ /* Free relations for this hook */
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ for (WorkSpaceDataRelation *relation = workspace->hook_layout_relations.first, *relation_next;
+ relation;
+ relation = relation_next)
+ {
+ relation_next = relation->next;
+ if (relation->parent == hook) {
+ workspace_relation_remove(&workspace->hook_layout_relations, relation);
+ }
+ }
+ }
+
+ MEM_freeN(hook);
+}
+
+/**
+ * Add a new layout to \a workspace for \a screen.
+ */
+WorkSpaceLayout *BKE_workspace_layout_add(
+ WorkSpace *workspace,
+ bScreen *screen,
+ const char *name)
+{
+ WorkSpaceLayout *layout = MEM_callocN(sizeof(*layout), __func__);
+
+ BLI_assert(!workspaces_is_screen_used(G.main, screen));
+ layout->screen = screen;
+ workspace_layout_name_set(workspace, layout, name);
+ BLI_addtail(&workspace->layouts, layout);
+
+ return layout;
+}
+
+void BKE_workspace_layout_remove(
+ Main *bmain,
+ WorkSpace *workspace, WorkSpaceLayout *layout)
+{
+ BKE_libblock_free(bmain, BKE_workspace_layout_screen_get(layout));
+ BLI_freelinkN(&workspace->layouts, layout);
+}
+
+void BKE_workspace_relations_free(
+ ListBase *relation_list)
+{
+ for (WorkSpaceDataRelation *relation = relation_list->first, *relation_next; relation; relation = relation_next) {
+ relation_next = relation->next;
+ workspace_relation_remove(relation_list, relation);
+ }
+}
+
+
+/* -------------------------------------------------------------------- */
+/* General Utils */
+
+void BKE_workspace_view_layer_remove_references(
+ const Main *bmain,
+ const ViewLayer *view_layer)
+{
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ workspace_relation_remove_from_value(&workspace->scene_viewlayer_relations, view_layer);
+ }
+}
+
+WorkSpaceLayout *BKE_workspace_layout_find(
+ const WorkSpace *workspace, const bScreen *screen)
+{
+ WorkSpaceLayout *layout = workspace_layout_find_exec(workspace, screen);
+ if (layout) {
+ return layout;
+ }
+
+ printf("%s: Couldn't find layout in this workspace: '%s' screen: '%s'. "
+ "This should not happen!\n",
+ __func__, workspace->id.name + 2, screen->id.name + 2);
+
+ return NULL;
+}
+
+/**
+ * Find the layout for \a screen without knowing which workspace to look in.
+ * Can also be used to find the workspace that contains \a screen.
+ *
+ * \param r_workspace: Optionally return the workspace that contains the looked up layout (if found).
+ */
+WorkSpaceLayout *BKE_workspace_layout_find_global(
+ const Main *bmain, const bScreen *screen,
+ WorkSpace **r_workspace)
+{
+ WorkSpaceLayout *layout;
+
+ if (r_workspace) {
+ *r_workspace = NULL;
+ }
+
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ if ((layout = workspace_layout_find_exec(workspace, screen))) {
+ if (r_workspace) {
+ *r_workspace = workspace;
+ }
+
+ return layout;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Circular workspace layout iterator.
+ *
+ * \param callback: Custom function which gets executed for each layout. Can return false to stop iterating.
+ * \param arg: Custom data passed to each \a callback call.
+ *
+ * \return the layout at which \a callback returned false.
+ */
+WorkSpaceLayout *BKE_workspace_layout_iter_circular(
+ const WorkSpace *workspace, WorkSpaceLayout *start,
+ bool (*callback)(const WorkSpaceLayout *layout, void *arg),
+ void *arg, const bool iter_backward)
+{
+ WorkSpaceLayout *iter_layout;
+
+ if (iter_backward) {
+ LISTBASE_CIRCULAR_BACKWARD_BEGIN(&workspace->layouts, iter_layout, start)
+ {
+ if (!callback(iter_layout, arg)) {
+ return iter_layout;
+ }
+ }
+ LISTBASE_CIRCULAR_BACKWARD_END(&workspace->layouts, iter_layout, start);
+ }
+ else {
+ LISTBASE_CIRCULAR_FORWARD_BEGIN(&workspace->layouts, iter_layout, start)
+ {
+ if (!callback(iter_layout, arg)) {
+ return iter_layout;
+ }
+ }
+ LISTBASE_CIRCULAR_FORWARD_END(&workspace->layouts, iter_layout, start)
+ }
+
+ return NULL;
+}
+
+
+/* -------------------------------------------------------------------- */
+/* Getters/Setters */
+
+WorkSpace *BKE_workspace_active_get(WorkSpaceInstanceHook *hook)
+{
+ return hook->active;
+}
+void BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace)
+{
+ hook->active = workspace;
+ if (workspace) {
+ WorkSpaceLayout *layout = workspace_relation_get_data_matching_parent(&workspace->hook_layout_relations, hook);
+ if (layout) {
+ hook->act_layout = layout;
+ }
+ }
+}
+
+WorkSpaceLayout *BKE_workspace_active_layout_get(const WorkSpaceInstanceHook *hook)
+{
+ return hook->act_layout;
+}
+void BKE_workspace_active_layout_set(WorkSpaceInstanceHook *hook, WorkSpaceLayout *layout)
+{
+ hook->act_layout = layout;
+}
+
+bScreen *BKE_workspace_active_screen_get(const WorkSpaceInstanceHook *hook)
+{
+ return hook->act_layout->screen;
+}
+void BKE_workspace_active_screen_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace, bScreen *screen)
+{
+ /* we need to find the WorkspaceLayout that wraps this screen */
+ WorkSpaceLayout *layout = BKE_workspace_layout_find(hook->active, screen);
+ BKE_workspace_hook_layout_for_workspace_set(hook, workspace, layout);
+}
+
+Base *BKE_workspace_active_base_get(const WorkSpace *workspace, const Scene *scene)
+{
+ ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
+ return view_layer->basact;
+}
+
+ViewLayer *BKE_workspace_view_layer_get(const WorkSpace *workspace, const Scene *scene)
+{
+ return workspace_relation_get_data_matching_parent(&workspace->scene_viewlayer_relations, scene);
+}
+void BKE_workspace_view_layer_set(WorkSpace *workspace, ViewLayer *layer, Scene *scene)
+{
+ workspace_relation_ensure_updated(&workspace->scene_viewlayer_relations, scene, layer);
+}
+
+ListBase *BKE_workspace_layouts_get(WorkSpace *workspace)
+{
+ return &workspace->layouts;
+}
+
+
+const char *BKE_workspace_layout_name_get(const WorkSpaceLayout *layout)
+{
+ return layout->name;
+}
+void BKE_workspace_layout_name_set(WorkSpace *workspace, WorkSpaceLayout *layout, const char *new_name)
+{
+ workspace_layout_name_set(workspace, layout, new_name);
+}
+
+bScreen *BKE_workspace_layout_screen_get(const WorkSpaceLayout *layout)
+{
+ return layout->screen;
+}
+void BKE_workspace_layout_screen_set(WorkSpaceLayout *layout, bScreen *screen)
+{
+ layout->screen = screen;
+}
+
+WorkSpaceLayout *BKE_workspace_hook_layout_for_workspace_get(
+ const WorkSpaceInstanceHook *hook, const WorkSpace *workspace)
+{
+ return workspace_relation_get_data_matching_parent(&workspace->hook_layout_relations, hook);
+}
+void BKE_workspace_hook_layout_for_workspace_set(
+ WorkSpaceInstanceHook *hook, WorkSpace *workspace, WorkSpaceLayout *layout)
+{
+ hook->act_layout = layout;
+ workspace_relation_ensure_updated(&workspace->hook_layout_relations, hook, layout);
+}
+
+/* Update / evaluate */
+
+void BKE_workspace_update_tagged(Main *bmain,
+ WorkSpace *workspace,
+ Scene *scene)
+{
+ ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
+ struct Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene,
+ view_layer,
+ true);
+ BKE_scene_graph_update_tagged(depsgraph, bmain);
+}
+
+
+bool BKE_workspace_owner_id_check(
+ const WorkSpace *workspace, const char *owner_id)
+{
+ if ((*owner_id == '\0') ||
+ ((workspace->flags & WORKSPACE_USE_FILTER_BY_ORIGIN) == 0))
+ {
+ return true;
+ }
+ else {
+ /* we could use hash lookup, for now this list is highly under < ~16 items. */
+ return BLI_findstring(&workspace->owner_ids, owner_id, offsetof(wmOwnerID, name)) != NULL;
+ }
+}
+
diff --git a/source/blender/blenkernel/intern/world.c b/source/blender/blenkernel/intern/world.c
index 5736c9331bf..15bf01d2049 100644
--- a/source/blender/blenkernel/intern/world.c
+++ b/source/blender/blenkernel/intern/world.c
@@ -33,6 +33,7 @@
#include <string.h>
#include <stdlib.h>
#include <math.h>
+
#include "MEM_guardedalloc.h"
#include "DNA_world_types.h"
@@ -43,6 +44,7 @@
#include "BLI_listbase.h"
#include "BKE_animsys.h"
+#include "BKE_global.h"
#include "BKE_icons.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
@@ -56,14 +58,8 @@
/** Free (or release) any data used by this world (does not free the world itself). */
void BKE_world_free(World *wrld)
{
- int a;
-
BKE_animdata_free((ID *)wrld, false);
- for (a = 0; a < MAX_MTEX; a++) {
- MEM_SAFE_FREE(wrld->mtex[a]);
- }
-
/* is no lib link block, but world extension */
if (wrld->nodetree) {
ntreeFreeTree(wrld->nodetree);
@@ -84,23 +80,9 @@ void BKE_world_init(World *wrld)
wrld->horr = 0.05f;
wrld->horg = 0.05f;
wrld->horb = 0.05f;
- wrld->zenr = 0.01f;
- wrld->zeng = 0.01f;
- wrld->zenb = 0.01f;
- wrld->skytype = 0;
-
- wrld->exp = 0.0f;
- wrld->exposure = wrld->range = 1.0f;
wrld->aodist = 10.0f;
- wrld->aosamp = 5;
wrld->aoenergy = 1.0f;
- wrld->ao_env_energy = 1.0f;
- wrld->ao_indirect_energy = 1.0f;
- wrld->ao_indirect_bounces = 1;
- wrld->aobias = 0.05f;
- wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY;
- wrld->ao_approx_error = 0.25f;
wrld->preview = NULL;
wrld->miststa = 5.0f;
@@ -128,12 +110,6 @@ World *BKE_world_add(Main *bmain, const char *name)
*/
void BKE_world_copy_data(Main *bmain, World *wrld_dst, const World *wrld_src, const int flag)
{
- for (int a = 0; a < MAX_MTEX; a++) {
- if (wrld_src->mtex[a]) {
- wrld_dst->mtex[a] = MEM_dupallocN(wrld_src->mtex[a]);
- }
- }
-
if (wrld_src->nodetree) {
/* Note: nodetree is *not* in bmain, however this specific case is handled at lower level
* (see BKE_libblock_copy_ex()). */
@@ -167,17 +143,9 @@ World *BKE_world_localize(World *wrld)
* ... Once f*** nodes are fully converted to that too :( */
World *wrldn;
- int a;
wrldn = BKE_libblock_copy_nolib(&wrld->id, false);
- for (a = 0; a < MAX_MTEX; a++) {
- if (wrld->mtex[a]) {
- wrldn->mtex[a] = MEM_mallocN(sizeof(MTex), __func__);
- memcpy(wrldn->mtex[a], wrld->mtex[a], sizeof(MTex));
- }
- }
-
if (wrld->nodetree)
wrldn->nodetree = ntreeLocalize(wrld->nodetree);
@@ -192,3 +160,14 @@ void BKE_world_make_local(Main *bmain, World *wrld, const bool lib_local)
{
BKE_id_make_local_generic(bmain, &wrld->id, true, lib_local);
}
+
+void BKE_world_eval(struct Depsgraph *UNUSED(depsgraph), World *world)
+{
+ if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) {
+ printf("%s on %s (%p)\n", __func__, world->id.name, world);
+ }
+ if (!BLI_listbase_is_empty(&world->gpumaterial)) {
+ world->update_flag = 1;
+ GPU_material_uniform_buffer_tag_dirty(&world->gpumaterial);
+ }
+}
diff --git a/source/blender/blenkernel/intern/writeffmpeg.c b/source/blender/blenkernel/intern/writeffmpeg.c
index d7fcd896e11..39174620961 100644
--- a/source/blender/blenkernel/intern/writeffmpeg.c
+++ b/source/blender/blenkernel/intern/writeffmpeg.c
@@ -45,8 +45,8 @@
#include "BLI_blenlib.h"
#ifdef WITH_AUDASPACE
-# include AUD_DEVICE_H
-# include AUD_SPECIAL_H
+# include <AUD_Device.h>
+# include <AUD_Special.h>
#endif
#include "BLI_utildefines.h"
@@ -326,10 +326,6 @@ static int write_video_frame(FFMpegContext *context, RenderData *rd, int cfra, A
frame->pts = cfra;
- if (rd->mode & R_FIELDS) {
- frame->top_field_first = ((rd->mode & R_ODDFIELD) != 0);
- }
-
ret = avcodec_encode_video2(c, &packet, frame, &got_output);
if (ret >= 0 && got_output) {
@@ -685,13 +681,6 @@ static AVStream *alloc_video_stream(FFMpegContext *context, RenderData *rd, int
c->flags |= CODEC_FLAG_GLOBAL_HEADER;
}
- /* Determine whether we are encoding interlaced material or not */
- if (rd->mode & R_FIELDS) {
- PRINT("Encoding interlaced video\n");
- c->flags |= CODEC_FLAG_INTERLACED_DCT;
- c->flags |= CODEC_FLAG_INTERLACED_ME;
- }
-
/* xasp & yasp got float lately... */
st->sample_aspect_ratio = c->sample_aspect_ratio = av_d2q(((double) rd->xasp / (double) rd->yasp), 255);
diff --git a/source/blender/blenlib/BLI_callbacks.h b/source/blender/blenlib/BLI_callbacks.h
index fdffbeb4c8d..adc7bf5af6b 100644
--- a/source/blender/blenlib/BLI_callbacks.h
+++ b/source/blender/blenlib/BLI_callbacks.h
@@ -49,10 +49,6 @@ typedef enum {
BLI_CB_EVT_LOAD_POST,
BLI_CB_EVT_SAVE_PRE,
BLI_CB_EVT_SAVE_POST,
- BLI_CB_EVT_SCENE_UPDATE_PRE,
- BLI_CB_EVT_SCENE_UPDATE_POST,
- BLI_CB_EVT_GAME_PRE,
- BLI_CB_EVT_GAME_POST,
BLI_CB_EVT_VERSION_UPDATE,
BLI_CB_EVT_TOT
} eCbEvent;
diff --git a/source/blender/blenlib/BLI_graph.h b/source/blender/blenlib/BLI_graph.h
deleted file mode 100644
index 7936f5a6fab..00000000000
--- a/source/blender/blenlib/BLI_graph.h
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- * Contributor(s): Joshua Leung
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#ifndef __BLI_GRAPH_H__
-#define __BLI_GRAPH_H__
-
-/** \file BLI_graph.h
- * \ingroup bli
- */
-
-#include "DNA_listBase.h"
-
-struct BGraph;
-struct BNode;
-struct BArc;
-
-struct RadialArc;
-
-typedef void (*FreeArc)(struct BArc *);
-typedef void (*FreeNode)(struct BNode *);
-typedef void (*RadialSymmetry)(struct BNode *root_node, struct RadialArc *ring, int total);
-typedef void (*AxialSymmetry)(struct BNode *root_node, struct BNode *node1, struct BNode *node2, struct BArc *arc1, struct BArc *arc2);
-
-/* IF YOU MODIFY THOSE TYPES, YOU NEED TO UPDATE ALL THOSE THAT "INHERIT" FROM THEM
- *
- * RigGraph, ReebGraph
- *
- * */
-
-typedef struct BGraph {
- ListBase arcs;
- ListBase nodes;
-
- float length;
-
- /* function pointer to deal with custom fonctionnality */
- FreeArc free_arc;
- FreeNode free_node;
- RadialSymmetry radial_symmetry;
- AxialSymmetry axial_symmetry;
-} BGraph;
-
-typedef struct BNode {
- void *next, *prev;
- float p[3];
- int flag;
-
- int degree;
- struct BArc **arcs;
-
- int subgraph_index;
-
- int symmetry_level;
- int symmetry_flag;
- float symmetry_axis[3];
-} BNode;
-
-typedef struct BArc {
- void *next, *prev;
- struct BNode *head, *tail;
- int flag;
-
- float length;
-
- int symmetry_level;
- int symmetry_group;
- int symmetry_flag;
-} BArc;
-
-struct BArcIterator;
-
-void *IT_head(void *iter);
-void *IT_tail(void *iter);
-void *IT_peek(void *iter, int n);
-void *IT_next(void *iter);
-void *IT_nextN(void *iter, int n);
-void *IT_previous(void *iter);
-int IT_stopped(void *iter);
-
-typedef void * (*HeadFct)(void *iter);
-typedef void * (*TailFct)(void *iter);
-typedef void * (*PeekFct)(void *iter, int n);
-typedef void * (*NextFct)(void *iter);
-typedef void * (*NextNFct)(void *iter, int n);
-typedef void * (*PreviousFct)(void *iter);
-typedef int (*StoppedFct)(void *iter);
-
-typedef struct BArcIterator {
- HeadFct head;
- TailFct tail;
- PeekFct peek;
- NextFct next;
- NextNFct nextN;
- PreviousFct previous;
- StoppedFct stopped;
-
- float *p, *no;
- float size;
-
- int length;
- int index;
-} BArcIterator;
-
-/* Helper structure for radial symmetry */
-typedef struct RadialArc {
- struct BArc *arc;
- float n[3]; /* normalized vector joining the nodes of the arc */
-} RadialArc;
-
-BNode *BLI_otherNode(BArc *arc, BNode *node);
-
-void BLI_freeNode(BGraph *graph, BNode *node);
-void BLI_removeNode(BGraph *graph, BNode *node);
-
-void BLI_removeArc(BGraph *graph, BArc *arc);
-
-void BLI_flagNodes(BGraph *graph, int flag);
-void BLI_flagArcs(BGraph *graph, int flag);
-
-bool BLI_hasAdjacencyList(BGraph *rg);
-void BLI_buildAdjacencyList(BGraph *rg);
-void BLI_rebuildAdjacencyListForNode(BGraph *rg, BNode *node);
-void BLI_freeAdjacencyList(BGraph *rg);
-
-int BLI_FlagSubgraphs(BGraph *graph);
-void BLI_ReflagSubgraph(BGraph *graph, int old_subgraph, int new_subgraph);
-
-#define SHAPE_RADIX 10 /* each shape level is encoded this base */
-
-int BLI_subtreeShape(BGraph *graph, BNode *node, BArc *rootArc, int include_root);
-float BLI_subtreeLength(BNode *node);
-void BLI_calcGraphLength(BGraph *graph);
-
-void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced);
-void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced);
-void BLI_removeDoubleNodes(BGraph *graph, float limit);
-BNode *BLI_FindNodeByPosition(BGraph *graph, const float p[3], const float limit);
-
-BArc *BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v);
-
-bool BLI_isGraphCyclic(BGraph *graph);
-
-/*------------ Symmetry handling ------------*/
-void BLI_markdownSymmetry(BGraph *graph, BNode *root_node, float limit);
-
-void BLI_mirrorAlongAxis(float v[3], float center[3], float axis[3]);
-
-/* BNode symmetry flags */
-#define SYM_TOPOLOGICAL 1
-#define SYM_PHYSICAL 2
-
-/* the following two are exclusive */
-#define SYM_AXIAL 4
-#define SYM_RADIAL 8
-
-/* BArc symmetry flags
- *
- * axial symmetry sides */
-#define SYM_SIDE_POSITIVE 1
-#define SYM_SIDE_NEGATIVE 2
-/* Anything higher is the order in radial symmetry */
-#define SYM_SIDE_RADIAL 3
-
-#endif /*__BLI_GRAPH_H__*/
diff --git a/source/blender/blenlib/BLI_iterator.h b/source/blender/blenlib/BLI_iterator.h
new file mode 100644
index 00000000000..d3d375122a1
--- /dev/null
+++ b/source/blender/blenlib/BLI_iterator.h
@@ -0,0 +1,62 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_ITERATOR_H__
+#define __BLI_ITERATOR_H__
+
+/** \file BLI_iterator.h
+ * \ingroup bli
+ */
+
+typedef struct BLI_Iterator {
+ void *current; /* current pointer we iterate over */
+ void *data; /* stored data required for this iterator */
+ bool skip;
+ bool valid;
+} BLI_Iterator;
+
+typedef void (*IteratorCb)(BLI_Iterator *iter);
+typedef void (*IteratorBeginCb)(BLI_Iterator *iter, void *data_in);
+
+#define ITER_BEGIN(callback_begin, callback_next, callback_end, _data_in, _type, _instance) \
+{ \
+ _type _instance; \
+ IteratorCb callback_end_func = callback_end; \
+ BLI_Iterator iter_macro; \
+ iter_macro.skip = false; \
+ iter_macro.valid = true; \
+ for (callback_begin(&iter_macro, (_data_in)); \
+ iter_macro.valid; \
+ callback_next(&iter_macro)) \
+ { \
+ if (iter_macro.skip) { \
+ iter_macro.skip = false; \
+ continue; \
+ } \
+ _instance = (_type ) iter_macro.current;
+
+#define ITER_END \
+ } \
+ callback_end_func(&iter_macro); \
+} ((void)0)
+
+#endif /* __BLI_ITERATOR_H__ */
diff --git a/source/blender/blenlib/BLI_link_utils.h b/source/blender/blenlib/BLI_link_utils.h
index d469b105f93..5322547ac08 100644
--- a/source/blender/blenlib/BLI_link_utils.h
+++ b/source/blender/blenlib/BLI_link_utils.h
@@ -35,6 +35,18 @@
list = link; \
} (void)0
+/* Use for append (single linked list, storing the last element). */
+#define BLI_LINKS_APPEND(list, link) { \
+ (link)->next = NULL; \
+ if ((list)->first) { \
+ (list)->last->next = link; \
+ } \
+ else { \
+ (list)->first = link; \
+ } \
+ (list)->last = link; \
+} (void)0
+
#define BLI_LINKS_FREE(list) { \
while (list) { \
void *next = list->next; \
diff --git a/source/blender/blenlib/BLI_math_matrix.h b/source/blender/blenlib/BLI_math_matrix.h
index 173ef6861e6..a6f8f9a54e9 100644
--- a/source/blender/blenlib/BLI_math_matrix.h
+++ b/source/blender/blenlib/BLI_math_matrix.h
@@ -46,81 +46,112 @@ void unit_m2(float R[2][2]);
void unit_m3(float R[3][3]);
void unit_m4(float R[4][4]);
-void copy_m2_m2(float R[2][2], float A[2][2]);
-void copy_m3_m3(float R[3][3], float A[3][3]);
-void copy_m4_m4(float R[4][4], float A[4][4]);
-void copy_m3_m4(float R[3][3], float A[4][4]);
-void copy_m4_m3(float R[4][4], float A[3][3]);
+void copy_m2_m2(float R[2][2], const float A[2][2]);
+void copy_m3_m3(float R[3][3], const float A[3][3]);
+void copy_m4_m4(float R[4][4], const float A[4][4]);
+void copy_m3_m4(float R[3][3], const float A[4][4]);
+void copy_m4_m3(float R[4][4], const float A[3][3]);
/* double->float */
-void copy_m3_m3d(float R[3][3], double A[3][3]);
+void copy_m3_m3d(float R[3][3], const double A[3][3]);
void swap_m3m3(float A[3][3], float B[3][3]);
void swap_m4m4(float A[4][4], float B[4][4]);
/******************************** Arithmetic *********************************/
-void add_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
-void add_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
+void add_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3]);
+void add_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4]);
-void sub_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
-void sub_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
+void sub_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3]);
+void sub_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4]);
-void mul_m3_m3m3(float R[3][3], float A[3][3], float B[3][3]);
-void mul_m4_m3m4(float R[4][4], float A[3][3], float B[4][4]);
-void mul_m4_m4m3(float R[4][4], float A[4][4], float B[3][3]);
-void mul_m4_m4m4(float R[4][4], float A[4][4], float B[4][4]);
-void mul_m3_m3m4(float R[3][3], float A[4][4], float B[3][3]);
+void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3]);
+void mul_m4_m3m4(float R[4][4], const float A[3][3], const float B[4][4]);
+void mul_m4_m4m3(float R[4][4], const float A[4][4], const float B[3][3]);
+void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4]);
+void mul_m3_m3m4(float R[3][3], const float A[4][4], const float B[3][3]);
+
+/* special matrix multiplies
+ * uniq: R <-- AB, R is neither A nor B
+ * pre: R <-- AR
+ * post: R <-- RB
+ */
+void mul_m3_m3m3_uniq(float R[3][3], const float A[3][3], const float B[3][3]);
+void mul_m3_m3_pre(float R[3][3], const float A[3][3]);
+void mul_m3_m3_post(float R[3][3], const float B[3][3]);
+void mul_m4_m4m4_uniq(float R[4][4], const float A[4][4], const float B[4][4]);
+void mul_m4_m4_pre(float R[4][4], const float A[4][4]);
+void mul_m4_m4_post(float R[4][4], const float B[4][4]);
/* mul_m3_series */
-void _va_mul_m3_series_3(float R[3][3], float M1[3][3], float M2[3][3]) ATTR_NONNULL();
-void _va_mul_m3_series_4(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3]) ATTR_NONNULL();
-void _va_mul_m3_series_5(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3]) ATTR_NONNULL();
-void _va_mul_m3_series_6(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3],
- float M5[3][3]) ATTR_NONNULL();
-void _va_mul_m3_series_7(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3],
- float M5[3][3], float M6[3][3]) ATTR_NONNULL();
-void _va_mul_m3_series_8(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3],
- float M5[3][3], float M6[3][3], float M7[3][3]) ATTR_NONNULL();
-void _va_mul_m3_series_9(float R[3][3], float M1[3][3], float M2[3][3], float M3[3][3], float M4[3][3],
- float M5[3][3], float M6[3][3], float M7[3][3], float M8[3][3]) ATTR_NONNULL();
+void _va_mul_m3_series_3(
+ float R[3][3], const float M1[3][3], const float M2[3][3]) ATTR_NONNULL();
+void _va_mul_m3_series_4(
+ float R[3][3], const float M1[3][3], const float M2[3][3], const float M3[3][3]) ATTR_NONNULL();
+void _va_mul_m3_series_5(
+ float R[3][3], const float M1[3][3], const float M2[3][3], const float M3[3][3],
+ const float M4[3][3]) ATTR_NONNULL();
+void _va_mul_m3_series_6(
+ float R[3][3], const float M1[3][3], const float M2[3][3], const float M3[3][3],
+ const float M4[3][3], const float M5[3][3]) ATTR_NONNULL();
+void _va_mul_m3_series_7(
+ float R[3][3], const float M1[3][3], const float M2[3][3], const float M3[3][3],
+ const float M4[3][3], const float M5[3][3], const float M6[3][3]) ATTR_NONNULL();
+void _va_mul_m3_series_8(
+ float R[3][3], const float M1[3][3], const float M2[3][3], const float M3[3][3],
+ const float M4[3][3], const float M5[3][3], const float M6[3][3], const float M7[3][3]) ATTR_NONNULL();
+void _va_mul_m3_series_9(
+ float R[3][3], const float M1[3][3], const float M2[3][3], const float M3[3][3],
+ const float M4[3][3], const float M5[3][3], const float M6[3][3], const float M7[3][3],
+ const float M8[3][3]) ATTR_NONNULL();
/* mul_m4_series */
-void _va_mul_m4_series_3(float R[4][4], float M1[4][4], float M2[4][4]) ATTR_NONNULL();
-void _va_mul_m4_series_4(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4]) ATTR_NONNULL();
-void _va_mul_m4_series_5(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4]) ATTR_NONNULL();
-void _va_mul_m4_series_6(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4],
- float M5[4][4]) ATTR_NONNULL();
-void _va_mul_m4_series_7(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4],
- float M5[4][4], float M6[4][4]) ATTR_NONNULL();
-void _va_mul_m4_series_8(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4],
- float M5[4][4], float M6[4][4], float M7[4][4]) ATTR_NONNULL();
-void _va_mul_m4_series_9(float R[4][4], float M1[4][4], float M2[4][4], float M3[4][4], float M4[4][4],
- float M5[4][4], float M6[4][4], float M7[4][4], float M8[4][4]) ATTR_NONNULL();
+void _va_mul_m4_series_3(
+ float R[4][4], const float M1[4][4], const float M2[4][4]) ATTR_NONNULL();
+void _va_mul_m4_series_4(
+ float R[4][4], const float M1[4][4], const float M2[4][4], const float M3[4][4]) ATTR_NONNULL();
+void _va_mul_m4_series_5(
+ float R[4][4], const float M1[4][4], const float M2[4][4], const float M3[4][4],
+ const float M4[4][4]) ATTR_NONNULL();
+void _va_mul_m4_series_6(
+ float R[4][4], const float M1[4][4], const float M2[4][4], const float M3[4][4],
+ const float M4[4][4], const float M5[4][4]) ATTR_NONNULL();
+void _va_mul_m4_series_7(
+ float R[4][4], const float M1[4][4], const float M2[4][4], const float M3[4][4],
+ const float M4[4][4], const float M5[4][4], const float M6[4][4]) ATTR_NONNULL();
+void _va_mul_m4_series_8(
+ float R[4][4], const float M1[4][4], const float M2[4][4], const float M3[4][4],
+ const float M4[4][4], const float M5[4][4], const float M6[4][4], const float M7[4][4]) ATTR_NONNULL();
+void _va_mul_m4_series_9(
+ float R[4][4], const float M1[4][4], const float M2[4][4], const float M3[4][4],
+ const float M4[4][4], const float M5[4][4], const float M6[4][4], const float M7[4][4],
+ const float M8[4][4]) ATTR_NONNULL();
#define mul_m3_series(...) VA_NARGS_CALL_OVERLOAD(_va_mul_m3_series_, __VA_ARGS__)
#define mul_m4_series(...) VA_NARGS_CALL_OVERLOAD(_va_mul_m4_series_, __VA_ARGS__)
-void mul_m4_v3(float M[4][4], float r[3]);
-void mul_v3_m4v3(float r[3], float M[4][4], const float v[3]);
-void mul_v2_m4v3(float r[2], float M[4][4], const float v[3]);
-void mul_v2_m2v2(float r[2], float M[2][2], const float v[2]);
-void mul_m2v2(float M[2][2], float v[2]);
-void mul_mat3_m4_v3(float M[4][4], float r[3]);
-void mul_v3_mat3_m4v3(float r[3], float M[4][4], const float v[3]);
-void mul_m4_v4(float M[4][4], float r[4]);
-void mul_v4_m4v4(float r[4], float M[4][4], const float v[4]);
-void mul_project_m4_v3(float M[4][4], float vec[3]);
-void mul_v3_project_m4_v3(float r[3], float mat[4][4], const float vec[3]);
-void mul_v2_project_m4_v3(float r[2], float M[4][4], const float vec[3]);
-
-void mul_m3_v2(float m[3][3], float r[2]);
-void mul_v2_m3v2(float r[2], float m[3][3], float v[2]);
-void mul_m3_v3(float M[3][3], float r[3]);
-void mul_v3_m3v3(float r[3], float M[3][3], const float a[3]);
-void mul_v2_m3v3(float r[2], float M[3][3], const float a[3]);
-void mul_transposed_m3_v3(float M[3][3], float r[3]);
-void mul_transposed_mat3_m4_v3(float M[4][4], float r[3]);
-void mul_m3_v3_double(float M[3][3], double r[3]);
+void mul_m4_v3(const float M[4][4], float r[3]);
+void mul_v3_m4v3(float r[3], const float M[4][4], const float v[3]);
+void mul_v2_m4v3(float r[2], const float M[4][4], const float v[3]);
+void mul_v2_m2v2(float r[2], const float M[2][2], const float v[2]);
+void mul_m2v2(const float M[2][2], float v[2]);
+void mul_mat3_m4_v3(const float M[4][4], float r[3]);
+void mul_v3_mat3_m4v3(float r[3], const float M[4][4], const float v[3]);
+void mul_m4_v4(const float M[4][4], float r[4]);
+void mul_v4_m4v4(float r[4], const float M[4][4], const float v[4]);
+void mul_v4_m4v3(float r[4], const float M[4][4], const float v[3]); /* v has implicit w = 1.0f */
+void mul_project_m4_v3(const float M[4][4], float vec[3]);
+void mul_v3_project_m4_v3(float r[3], const float mat[4][4], const float vec[3]);
+void mul_v2_project_m4_v3(float r[2], const float M[4][4], const float vec[3]);
+
+void mul_m3_v2(const float m[3][3], float r[2]);
+void mul_v2_m3v2(float r[2], const float m[3][3], const float v[2]);
+void mul_m3_v3(const float M[3][3], float r[3]);
+void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3]);
+void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3]);
+void mul_transposed_m3_v3(const float M[3][3], float r[3]);
+void mul_transposed_mat3_m4_v3(const float M[4][4], float r[3]);
+void mul_m3_v3_double(const float M[3][3], double r[3]);
void mul_m3_fl(float R[3][3], float f);
void mul_m4_fl(float R[4][4], float f);
@@ -131,103 +162,103 @@ void negate_mat3_m4(float R[4][4]);
void negate_m4(float R[4][4]);
bool invert_m3_ex(float m[3][3], const float epsilon);
-bool invert_m3_m3_ex(float m1[3][3], float m2[3][3], const float epsilon);
+bool invert_m3_m3_ex(float m1[3][3], const float m2[3][3], const float epsilon);
bool invert_m3(float R[3][3]);
-bool invert_m3_m3(float R[3][3], float A[3][3]);
+bool invert_m3_m3(float R[3][3], const float A[3][3]);
bool invert_m4(float R[4][4]);
-bool invert_m4_m4(float R[4][4], float A[4][4]);
+bool invert_m4_m4(float R[4][4], const float A[4][4]);
/* double arithmetic (mixed float/double) */
-void mul_m4_v4d(float M[4][4], double r[4]);
-void mul_v4d_m4v4d(double r[4], float M[4][4], double v[4]);
+void mul_m4_v4d(const float M[4][4], double r[4]);
+void mul_v4d_m4v4d(double r[4], const float M[4][4], const double v[4]);
/* double matrix functions (no mixing types) */
-void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3]);
-void mul_m3_v3_db(double M[3][3], double r[3]);
+void mul_v3_m3v3_db(double r[3], const double M[3][3], const double a[3]);
+void mul_m3_v3_db(const double M[3][3], double r[3]);
/****************************** Linear Algebra *******************************/
void transpose_m3(float R[3][3]);
-void transpose_m3_m3(float R[3][3], float A[3][3]);
-void transpose_m3_m4(float R[3][3], float A[4][4]);
+void transpose_m3_m3(float R[3][3], const float A[3][3]);
+void transpose_m3_m4(float R[3][3], const float A[4][4]);
void transpose_m4(float R[4][4]);
-void transpose_m4_m4(float R[4][4], float A[4][4]);
+void transpose_m4_m4(float R[4][4], const float A[4][4]);
-int compare_m4m4(float mat1[4][4], float mat2[4][4], float limit);
+int compare_m4m4(const float mat1[4][4], const float mat2[4][4], float limit);
void normalize_m3_ex(float R[3][3], float r_scale[3]) ATTR_NONNULL();
void normalize_m3(float R[3][3]) ATTR_NONNULL();
-void normalize_m3_m3_ex(float R[3][3], float A[3][3], float r_scale[3]) ATTR_NONNULL();
-void normalize_m3_m3(float R[3][3], float A[3][3]) ATTR_NONNULL();
+void normalize_m3_m3_ex(float R[3][3], const float A[3][3], float r_scale[3]) ATTR_NONNULL();
+void normalize_m3_m3(float R[3][3], const float A[3][3]) ATTR_NONNULL();
void normalize_m4_ex(float R[4][4], float r_scale[3]) ATTR_NONNULL();
void normalize_m4(float R[4][4]) ATTR_NONNULL();
-void normalize_m4_m4_ex(float R[4][4], float A[4][4], float r_scale[3]) ATTR_NONNULL();
-void normalize_m4_m4(float R[4][4], float A[4][4]) ATTR_NONNULL();
+void normalize_m4_m4_ex(float R[4][4], const float A[4][4], float r_scale[3]) ATTR_NONNULL();
+void normalize_m4_m4(float R[4][4], const float A[4][4]) ATTR_NONNULL();
void orthogonalize_m3(float R[3][3], int axis);
void orthogonalize_m4(float R[4][4], int axis);
-bool is_orthogonal_m3(float mat[3][3]);
-bool is_orthogonal_m4(float mat[4][4]);
-bool is_orthonormal_m3(float mat[3][3]);
-bool is_orthonormal_m4(float mat[4][4]);
+bool is_orthogonal_m3(const float mat[3][3]);
+bool is_orthogonal_m4(const float mat[4][4]);
+bool is_orthonormal_m3(const float mat[3][3]);
+bool is_orthonormal_m4(const float mat[4][4]);
-bool is_uniform_scaled_m3(float mat[3][3]);
-bool is_uniform_scaled_m4(float m[4][4]);
+bool is_uniform_scaled_m3(const float mat[3][3]);
+bool is_uniform_scaled_m4(const float m[4][4]);
/* Note: 'adjoint' here means the adjugate (adjunct, "classical adjoint") matrix!
* Nowadays 'adjoint' usually refers to the conjugate transpose,
* which for real-valued matrices is simply the transpose.
*/
-void adjoint_m2_m2(float R[2][2], float A[2][2]);
-void adjoint_m3_m3(float R[3][3], float A[3][3]);
-void adjoint_m4_m4(float R[4][4], float A[4][4]);
+void adjoint_m2_m2(float R[2][2], const float A[2][2]);
+void adjoint_m3_m3(float R[3][3], const float A[3][3]);
+void adjoint_m4_m4(float R[4][4], const float A[4][4]);
float determinant_m2(float a, float b,
float c, float d);
float determinant_m3(float a, float b, float c,
float d, float e, float f,
float g, float h, float i);
-float determinant_m3_array(float m[3][3]);
-float determinant_m4(float A[4][4]);
+float determinant_m3_array(const float m[3][3]);
+float determinant_m4(const float A[4][4]);
#define PSEUDOINVERSE_EPSILON 1e-8f
void svd_m4(float U[4][4], float s[4], float V[4][4], float A[4][4]);
-void pseudoinverse_m4_m4(float Ainv[4][4], float A[4][4], float epsilon);
-void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon);
+void pseudoinverse_m4_m4(float Ainv[4][4], const float A[4][4], float epsilon);
+void pseudoinverse_m3_m3(float Ainv[3][3], const float A[3][3], float epsilon);
-bool has_zero_axis_m4(float matrix[4][4]);
+bool has_zero_axis_m4(const float matrix[4][4]);
-void invert_m4_m4_safe(float Ainv[4][4], float A[4][4]);
+void invert_m4_m4_safe(float Ainv[4][4], const float A[4][4]);
/****************************** Transformations ******************************/
void scale_m3_fl(float R[3][3], float scale);
void scale_m4_fl(float R[4][4], float scale);
-float mat3_to_scale(float M[3][3]);
-float mat4_to_scale(float M[4][4]);
-float mat4_to_xy_scale(float M[4][4]);
+float mat3_to_scale(const float M[3][3]);
+float mat4_to_scale(const float M[4][4]);
+float mat4_to_xy_scale(const float M[4][4]);
void size_to_mat3(float R[3][3], const float size[3]);
void size_to_mat4(float R[4][4], const float size[3]);
-void mat3_to_size(float r[3], float M[3][3]);
-void mat4_to_size(float r[3], float M[4][4]);
+void mat3_to_size(float r[3], const float M[3][3]);
+void mat4_to_size(float r[3], const float M[4][4]);
void translate_m4(float mat[4][4], float tx, float ty, float tz);
void rotate_m4(float mat[4][4], const char axis, const float angle);
void transform_pivot_set_m4(float mat[4][4], const float pivot[3]);
-void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3]);
-void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[4][4]);
-void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4]);
-void mat4_decompose(float loc[3], float quat[4], float size[3], float wmat[4][4]);
+void mat3_to_rot_size(float rot[3][3], float size[3], const float mat3[3][3]);
+void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4]);
+void mat4_to_loc_quat(float loc[3], float quat[4], const float wmat[4][4]);
+void mat4_decompose(float loc[3], float quat[4], float size[3], const float wmat[4][4]);
-void mat3_polar_decompose(float mat3[3][3], float r_U[3][3], float r_P[3][3]);
+void mat3_polar_decompose(const float mat3[3][3], float r_U[3][3], float r_P[3][3]);
void loc_eul_size_to_mat4(float R[4][4],
const float loc[3], const float eul[3], const float size[3]);
@@ -238,20 +269,20 @@ void loc_quat_size_to_mat4(float R[4][4],
void loc_axisangle_size_to_mat4(float R[4][4],
const float loc[3], const float axis[4], const float angle, const float size[3]);
-void blend_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t);
-void blend_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t);
+void blend_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3], const float t);
+void blend_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4], const float t);
-void interp_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t);
-void interp_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t);
+void interp_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3], const float t);
+void interp_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4], const float t);
-bool is_negative_m3(float mat[3][3]);
-bool is_negative_m4(float mat[4][4]);
+bool is_negative_m3(const float mat[3][3]);
+bool is_negative_m4(const float mat[4][4]);
-bool is_zero_m3(float mat[3][3]);
-bool is_zero_m4(float mat[4][4]);
+bool is_zero_m3(const float mat[3][3]);
+bool is_zero_m4(const float mat[4][4]);
-bool equals_m3m3(float mat1[3][3], float mat2[3][3]);
-bool equals_m4m4(float mat1[4][4], float mat2[4][4]);
+bool equals_m3m3(const float mat1[3][3], const float mat2[3][3]);
+bool equals_m4m4(const float mat1[4][4], const float mat2[4][4]);
/* SpaceTransform helper */
typedef struct SpaceTransform {
@@ -260,8 +291,8 @@ typedef struct SpaceTransform {
} SpaceTransform;
-void BLI_space_transform_from_matrices(struct SpaceTransform *data, float local[4][4], float target[4][4]);
-void BLI_space_transform_global_from_matrices(struct SpaceTransform *data, float local[4][4], float target[4][4]);
+void BLI_space_transform_from_matrices(struct SpaceTransform *data, const float local[4][4], const float target[4][4]);
+void BLI_space_transform_global_from_matrices(struct SpaceTransform *data, const float local[4][4], const float target[4][4]);
void BLI_space_transform_apply(const struct SpaceTransform *data, float co[3]);
void BLI_space_transform_invert(const struct SpaceTransform *data, float co[3]);
void BLI_space_transform_apply_normal(const struct SpaceTransform *data, float no[3]);
@@ -272,8 +303,8 @@ void BLI_space_transform_invert_normal(const struct SpaceTransform *data, float
/*********************************** Other ***********************************/
-void print_m3(const char *str, float M[3][3]);
-void print_m4(const char *str, float M[4][4]);
+void print_m3(const char *str, const float M[3][3]);
+void print_m4(const char *str, const float M[4][4]);
#define print_m3_id(M) print_m3(STRINGIFY(M), M)
#define print_m4_id(M) print_m4(STRINGIFY(M), M)
diff --git a/source/blender/blenlib/BLI_math_vector.h b/source/blender/blenlib/BLI_math_vector.h
index 3f603311530..e4e0bf22de0 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -123,7 +123,7 @@ MINLINE void mul_v4_fl(float r[4], float f);
MINLINE void mul_v4_v4fl(float r[3], const float a[3], float f);
MINLINE void mul_v2_v2_cw(float r[2], const float mat[2], const float vec[2]);
MINLINE void mul_v2_v2_ccw(float r[2], const float mat[2], const float vec[2]);
-MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3]) ATTR_WARN_UNUSED_RESULT;
+MINLINE float mul_project_m4_v3_zfac(const float mat[4][4], const float co[3]) ATTR_WARN_UNUSED_RESULT;
MINLINE float dot_m3_v3_row_x(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT;
MINLINE float dot_m3_v3_row_y(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT;
MINLINE float dot_m3_v3_row_z(float M[3][3], const float a[3]) ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/blenlib/BLI_memiter.h b/source/blender/blenlib/BLI_memiter.h
new file mode 100644
index 00000000000..55eb023313d
--- /dev/null
+++ b/source/blender/blenlib/BLI_memiter.h
@@ -0,0 +1,73 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __BLI_MEMITER_H__
+#define __BLI_MEMITER_H__
+
+/** \file BLI_memiter.h
+ * \ingroup bli
+ */
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include "BLI_sys_types.h"
+#include "BLI_compiler_attrs.h"
+#include "BLI_compiler_compat.h"
+
+/* 512kb, good default for small elems. */
+#define BLI_MEMITER_DEFAULT_SIZE (1 << 19)
+
+struct BLI_memiter;
+struct BLI_memiter_chunk;
+
+typedef struct BLI_memiter BLI_memiter;
+
+/* warning, ATTR_MALLOC flag on BLI_memiter_alloc causes crash, see: D2756 */
+BLI_memiter *BLI_memiter_create(unsigned int chunk_size) ATTR_MALLOC ATTR_WARN_UNUSED_RESULT;
+void *BLI_memiter_alloc(BLI_memiter *mi, unsigned int size) ATTR_RETURNS_NONNULL ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+void BLI_memiter_alloc_from(BLI_memiter *mi, uint elem_size, const void *data_from) ATTR_NONNULL(1, 3);
+void *BLI_memiter_calloc(BLI_memiter *mi, unsigned int size) ATTR_RETURNS_NONNULL ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+void BLI_memiter_destroy(BLI_memiter *mi) ATTR_NONNULL(1);
+void BLI_memiter_clear(BLI_memiter *mi) ATTR_NONNULL(1);
+unsigned int BLI_memiter_count(const BLI_memiter *mi) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+
+/* utils */
+void *BLI_memiter_elem_first(BLI_memiter *mi);
+void *BLI_memiter_elem_first_size(BLI_memiter *mi, unsigned int *r_size);
+
+/* private structure */
+typedef struct BLI_memiter_handle {
+ struct BLI_memiter_elem *elem;
+ uint elem_left;
+} BLI_memiter_handle;
+
+void BLI_memiter_iter_init(BLI_memiter *mi, BLI_memiter_handle *iter) ATTR_NONNULL();
+bool BLI_memiter_iter_done(const BLI_memiter_handle *iter) ATTR_NONNULL();
+void *BLI_memiter_iter_step(BLI_memiter_handle *iter) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+void *BLI_memiter_iter_step_size(BLI_memiter_handle *iter, uint *r_size) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BLI_MEMITER_H__ */
diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt
index f8fc2bfdcff..31abf258d0f 100644
--- a/source/blender/blenlib/CMakeLists.txt
+++ b/source/blender/blenlib/CMakeLists.txt
@@ -52,6 +52,7 @@ set(SRC
intern/BLI_linklist.c
intern/BLI_linklist_lockfree.c
intern/BLI_memarena.c
+ intern/BLI_memiter.c
intern/BLI_mempool.c
intern/DLRB_tree.c
intern/array_store.c
@@ -70,7 +71,6 @@ set(SRC
intern/fileops.c
intern/fnmatch.c
intern/freetypefont.c
- intern/graph.c
intern/gsqueue.c
intern/hash_md5.c
intern/hash_mm2a.c
@@ -153,12 +153,12 @@ set(SRC
BLI_fileops_types.h
BLI_fnmatch.h
BLI_ghash.h
- BLI_graph.h
BLI_gsqueue.h
BLI_hash.h
BLI_hash_md5.h
BLI_hash_mm2a.h
BLI_heap.h
+ BLI_iterator.h
BLI_jitter_2d.h
BLI_kdopbvh.h
BLI_kdtree.h
@@ -181,6 +181,7 @@ set(SRC
BLI_math_statistics.h
BLI_math_vector.h
BLI_memarena.h
+ BLI_memiter.h
BLI_memory_utils.h
BLI_mempool.h
BLI_noise.h
diff --git a/source/blender/blenlib/intern/BLI_memiter.c b/source/blender/blenlib/intern/BLI_memiter.c
new file mode 100644
index 00000000000..9c5f026f836
--- /dev/null
+++ b/source/blender/blenlib/intern/BLI_memiter.c
@@ -0,0 +1,357 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenlib/intern/BLI_memiter.c
+ * \ingroup bli
+ *
+ * Simple, fast memory allocator for allocating many small elements of different sizes
+ * in fixed size memory chunks,
+ * although allocations bigger than the chunk size are supported.
+ * They will reduce the efficiency of this data-structure.
+ * Elements are pointer aligned.
+ *
+ * Supports:
+ *
+ * - Allocation of mixed sizes.
+ * - Iterating over allocations in-order.
+ * - Clearing for re-use.
+ *
+ * Unsupported:
+ *
+ * - Freeing individual elements.
+ *
+ * \note We could inline iteration stepping,
+ * but tests show this doesn't give noticeable speedup.
+ */
+
+#include <string.h>
+#include <stdlib.h>
+
+#include "BLI_utildefines.h"
+
+#include "BLI_memiter.h" /* own include */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_strict_flags.h" /* keep last */
+
+typedef uintptr_t data_t;
+typedef intptr_t offset_t;
+
+/* Write the chunk terminator on adding each element.
+ * typically we rely on the 'count' to avoid iterating past the end. */
+// #define USE_TERMINATE_PARANOID
+
+/* Currently totalloc isnt used. */
+ // #define USE_TOTALLOC
+
+/* pad must be power of two */
+#define PADUP(num, pad) (((num) + ((pad) - 1)) & ~((pad) - 1))
+
+typedef struct BLI_memiter_elem {
+ offset_t size;
+ data_t data[0];
+} BLI_memiter_elem;
+
+typedef struct BLI_memiter_chunk {
+ struct BLI_memiter_chunk *next;
+ /**
+ * internal format is:
+ * ``[next_pointer, size:data, size:data, ..., negative_offset]``
+ *
+ * Where negative offset rewinds to the start.
+ */
+ data_t data[0];
+} BLI_memiter_chunk;
+
+typedef struct BLI_memiter {
+ /* A pointer to 'head' is needed so we can iterate in the order allocated. */
+ struct BLI_memiter_chunk *head, *tail;
+ data_t *data_curr;
+ data_t *data_last;
+ /* Used unless a large element is requested.
+ * (which should be very rare!). */
+ uint chunk_size_in_bytes_min;
+ uint count;
+#ifdef USE_TOTALLOC
+ uint totalloc;
+#endif
+} BLI_memiter;
+
+
+BLI_INLINE uint data_offset_from_size(uint size)
+{
+ return (PADUP(size, (uint)sizeof(data_t))) / (uint)sizeof(data_t);
+}
+
+static void memiter_set_rewind_offset(BLI_memiter *mi)
+{
+ BLI_memiter_elem *elem = (BLI_memiter_elem *)mi->data_curr;
+ elem->size = (offset_t)(((data_t *)mi->tail) - mi->data_curr);
+ BLI_assert(elem->size < 0);
+}
+
+static void memiter_init(BLI_memiter *mi)
+{
+ mi->head = NULL;
+ mi->tail = NULL;
+ mi->data_curr = NULL;
+ mi->data_last = NULL;
+ mi->count = 0;
+#ifdef USE_TOTALLOC
+ mi->totalloc = 0;
+#endif
+}
+
+/* -------------------------------------------------------------------- */
+
+/** \name Public API's
+ * \{ */
+
+/**
+ * \param chunk_size_min: Should be a power of two and
+ * significantly larger than the average element size used.
+ *
+ * While allocations of any size are supported, they won't be efficient
+ * (effectively becoming a single-linked list).
+ *
+ * Its intended that many elements can be stored per chunk.
+ */
+BLI_memiter *BLI_memiter_create(uint chunk_size_min)
+{
+ BLI_memiter *mi = MEM_mallocN(sizeof(BLI_memiter), "BLI_memiter");
+ memiter_init(mi);
+
+ /* Small values are used for tests to check for correctness,
+ * but otherwise not that useful. */
+ const uint slop_space = (sizeof(BLI_memiter_chunk) + MEM_SIZE_OVERHEAD);
+ if (chunk_size_min >= 1024) {
+ /* As long as the input is a power of 2, this will give efficient sizes. */
+ chunk_size_min -= slop_space;
+ }
+
+ mi->chunk_size_in_bytes_min = chunk_size_min;
+ return mi;
+}
+
+void *BLI_memiter_alloc(BLI_memiter *mi, uint elem_size)
+{
+ const uint data_offset = data_offset_from_size(elem_size);
+ data_t *data_curr_next = mi->data_curr + (1 + data_offset);
+
+ if (UNLIKELY(mi->data_curr == NULL) || (data_curr_next > mi->data_last)) {
+
+#ifndef USE_TERMINATE_PARANOID
+ if (mi->data_curr != NULL) {
+ memiter_set_rewind_offset(mi);
+ }
+#endif
+
+ uint chunk_size_in_bytes = mi->chunk_size_in_bytes_min;
+ if (UNLIKELY(chunk_size_in_bytes < elem_size + (uint)sizeof(data_t[2]))) {
+ chunk_size_in_bytes = elem_size + (uint)sizeof(data_t[2]);
+ }
+ uint chunk_size = data_offset_from_size(chunk_size_in_bytes);
+ BLI_memiter_chunk *chunk = MEM_mallocN(
+ sizeof(BLI_memiter_chunk) +
+ (chunk_size * sizeof(data_t)),
+ "BLI_memiter_chunk");
+
+ if (mi->head == NULL) {
+ BLI_assert(mi->tail == NULL);
+ mi->head = chunk;
+ }
+ else {
+ mi->tail->next = chunk;
+ }
+ mi->tail = chunk;
+ chunk->next = NULL;
+
+ mi->data_curr = chunk->data;
+ mi->data_last = chunk->data + (chunk_size - 1);
+ data_curr_next = mi->data_curr + (1 + data_offset);
+ }
+
+ BLI_assert(data_curr_next <= mi->data_last);
+
+ BLI_memiter_elem *elem = (BLI_memiter_elem *)mi->data_curr;
+ elem->size = (offset_t)elem_size;
+ mi->data_curr = data_curr_next;
+
+#ifdef USE_TERMINATE_PARANOID
+ memiter_set_rewind_offset(mi);
+#endif
+
+ mi->count += 1;
+
+#ifdef USE_TOTALLOC
+ mi->totalloc += elem_size;
+#endif
+
+ return elem->data;
+}
+
+void *BLI_memiter_calloc(BLI_memiter *mi, uint elem_size)
+{
+ void *data = BLI_memiter_alloc(mi, elem_size);
+ memset(data, 0, elem_size);
+ return data;
+}
+
+void BLI_memiter_alloc_from(BLI_memiter *mi, uint elem_size, const void *data_from)
+{
+ void *data = BLI_memiter_alloc(mi, elem_size);
+ memcpy(data, data_from, elem_size);
+}
+
+static void memiter_free_data(BLI_memiter *mi)
+{
+ BLI_memiter_chunk *chunk = mi->head;
+ while (chunk) {
+ BLI_memiter_chunk *chunk_next = chunk->next;
+ MEM_freeN(chunk);
+ chunk = chunk_next;
+ }
+}
+
+void BLI_memiter_destroy(BLI_memiter *mi)
+{
+ memiter_free_data(mi);
+ MEM_freeN(mi);
+}
+
+void BLI_memiter_clear(BLI_memiter *mi)
+{
+ memiter_free_data(mi);
+ memiter_init(mi);
+}
+
+uint BLI_memiter_count(const BLI_memiter *mi)
+{
+ return mi->count;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Helper API's
+ * \{ */
+
+/* Support direct lookup for first. */
+void *BLI_memiter_elem_first(BLI_memiter *mi)
+{
+ if (mi->head != NULL) {
+ BLI_memiter_chunk *chunk = mi->head;
+ BLI_memiter_elem *elem = (BLI_memiter_elem *)chunk->data;
+ return elem->data;
+ }
+ else {
+ return NULL;
+ }
+}
+
+void *BLI_memiter_elem_first_size(BLI_memiter *mi, uint *r_size)
+{
+ if (mi->head != NULL) {
+ BLI_memiter_chunk *chunk = mi->head;
+ BLI_memiter_elem *elem = (BLI_memiter_elem *)chunk->data;
+ *r_size = (uint)elem->size;
+ return elem->data;
+ }
+ else {
+ return NULL;
+ }
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Iterator API's
+ *
+ * \note We could loop over elements until a NULL chunk is found,
+ * however this means every allocation needs to preemptively run
+ * #memiter_set_rewind_offset (see #USE_TERMINATE_PARANOID).
+ * Unless we have a call to finalize allocation (which complicates usage).
+ * So use a counter instead.
+ *
+ * \{ */
+
+void BLI_memiter_iter_init(BLI_memiter *mi, BLI_memiter_handle *iter)
+{
+ iter->elem = mi->head ? (BLI_memiter_elem *)mi->head->data : NULL;
+ iter->elem_left = mi->count;
+}
+
+bool BLI_memiter_iter_done(const BLI_memiter_handle *iter)
+{
+ return iter->elem_left != 0;
+}
+
+BLI_INLINE void memiter_chunk_step(BLI_memiter_handle *iter)
+{
+ BLI_assert(iter->elem->size < 0);
+ BLI_memiter_chunk *chunk = (BLI_memiter_chunk *)(((data_t *)iter->elem) + iter->elem->size);
+ chunk = chunk->next;
+ iter->elem = chunk ? (BLI_memiter_elem *)chunk->data : NULL;
+ BLI_assert(iter->elem == NULL || iter->elem->size >= 0);
+}
+
+void *BLI_memiter_iter_step_size(BLI_memiter_handle *iter, uint *r_size)
+{
+ if (iter->elem_left != 0) {
+ iter->elem_left -= 1;
+ if (UNLIKELY(iter->elem->size < 0)) {
+ memiter_chunk_step(iter);
+ }
+ BLI_assert(iter->elem->size >= 0);
+ uint size = (uint)iter->elem->size;
+ *r_size = size; /* <-- only difference */
+ data_t *data = iter->elem->data;
+ iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)];
+ return (void *)data;
+ }
+ else {
+ return NULL;
+ }
+}
+
+void *BLI_memiter_iter_step(BLI_memiter_handle *iter)
+{
+ if (iter->elem_left != 0) {
+ iter->elem_left -= 1;
+ if (UNLIKELY(iter->elem->size < 0)) {
+ memiter_chunk_step(iter);
+ }
+ BLI_assert(iter->elem->size >= 0);
+ uint size = (uint)iter->elem->size;
+ data_t *data = iter->elem->data;
+ iter->elem = (BLI_memiter_elem *)&data[data_offset_from_size(size)];
+ return (void *)data;
+ }
+ else {
+ return NULL;
+ }
+}
+
+/** \} */
diff --git a/source/blender/blenlib/intern/graph.c b/source/blender/blenlib/intern/graph.c
deleted file mode 100644
index 911e8aae340..00000000000
--- a/source/blender/blenlib/intern/graph.c
+++ /dev/null
@@ -1,1016 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Martin Poirier
- *
- * ***** END GPL LICENSE BLOCK *****
- * graph.c: Common graph interface and methods
- */
-
-/** \file blender/blenlib/intern/graph.c
- * \ingroup bli
- */
-
-#include <float.h>
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_listbase.h"
-#include "BLI_graph.h"
-#include "BLI_math.h"
-
-
-static void testRadialSymmetry(BGraph *graph, BNode *root_node, RadialArc *ring, int total, float axis[3], float limit, int group);
-
-static void handleAxialSymmetry(BGraph *graph, BNode *root_node, int depth, float axis[3], float limit);
-static void testAxialSymmetry(BGraph *graph, BNode *root_node, BNode *node1, BNode *node2, BArc *arc1, BArc *arc2, float axis[3], float limit, int group);
-static void flagAxialSymmetry(BNode *root_node, BNode *end_node, BArc *arc, int group);
-
-void BLI_freeNode(BGraph *graph, BNode *node)
-{
- if (node->arcs) {
- MEM_freeN(node->arcs);
- }
-
- if (graph->free_node) {
- graph->free_node(node);
- }
-}
-
-void BLI_removeNode(BGraph *graph, BNode *node)
-{
- BLI_freeNode(graph, node);
- BLI_freelinkN(&graph->nodes, node);
-}
-
-BNode *BLI_otherNode(BArc *arc, BNode *node)
-{
- return (arc->head == node) ? arc->tail : arc->head;
-}
-
-void BLI_removeArc(BGraph *graph, BArc *arc)
-{
- if (graph->free_arc) {
- graph->free_arc(arc);
- }
-
- BLI_freelinkN(&graph->arcs, arc);
-}
-
-void BLI_flagNodes(BGraph *graph, int flag)
-{
- BNode *node;
-
- for (node = graph->nodes.first; node; node = node->next) {
- node->flag = flag;
- }
-}
-
-void BLI_flagArcs(BGraph *graph, int flag)
-{
- BArc *arc;
-
- for (arc = graph->arcs.first; arc; arc = arc->next) {
- arc->flag = flag;
- }
-}
-
-static void addArcToNodeAdjacencyList(BNode *node, BArc *arc)
-{
- node->arcs[node->flag] = arc;
- node->flag++;
-}
-
-void BLI_buildAdjacencyList(BGraph *graph)
-{
- BNode *node;
- BArc *arc;
-
- for (node = graph->nodes.first; node; node = node->next) {
- if (node->arcs != NULL) {
- MEM_freeN(node->arcs);
- }
-
- node->arcs = MEM_callocN((node->degree) * sizeof(BArc *), "adjacency list");
-
- /* temporary use to indicate the first index available in the lists */
- node->flag = 0;
- }
-
- for (arc = graph->arcs.first; arc; arc = arc->next) {
- addArcToNodeAdjacencyList(arc->head, arc);
- addArcToNodeAdjacencyList(arc->tail, arc);
- }
-
- for (node = graph->nodes.first; node; node = node->next) {
- if (node->degree != node->flag) {
- printf("error in node [%p]. Added only %i arcs out of %i\n", (void *)node, node->flag, node->degree);
- }
- }
-}
-
-void BLI_rebuildAdjacencyListForNode(BGraph *graph, BNode *node)
-{
- BArc *arc;
-
- if (node->arcs != NULL) {
- MEM_freeN(node->arcs);
- }
-
- node->arcs = MEM_callocN((node->degree) * sizeof(BArc *), "adjacency list");
-
- /* temporary use to indicate the first index available in the lists */
- node->flag = 0;
-
- for (arc = graph->arcs.first; arc; arc = arc->next) {
- if (arc->head == node) {
- addArcToNodeAdjacencyList(arc->head, arc);
- }
- else if (arc->tail == node) {
- addArcToNodeAdjacencyList(arc->tail, arc);
- }
- }
-
- if (node->degree != node->flag) {
- printf("error in node [%p]. Added only %i arcs out of %i\n", (void *)node, node->flag, node->degree);
- }
-}
-
-void BLI_freeAdjacencyList(BGraph *graph)
-{
- BNode *node;
-
- for (node = graph->nodes.first; node; node = node->next) {
- if (node->arcs != NULL) {
- MEM_freeN(node->arcs);
- node->arcs = NULL;
- }
- }
-}
-
-bool BLI_hasAdjacencyList(BGraph *graph)
-{
- BNode *node;
-
- for (node = graph->nodes.first; node; node = node->next) {
- if (node->arcs == NULL) {
- return false;
- }
- }
-
- return true;
-}
-
-void BLI_replaceNodeInArc(BGraph *graph, BArc *arc, BNode *node_src, BNode *node_replaced)
-{
- if (arc->head == node_replaced) {
- arc->head = node_src;
- node_src->degree++;
- }
-
- if (arc->tail == node_replaced) {
- arc->tail = node_src;
- node_src->degree++;
- }
-
- if (arc->head == arc->tail) {
- node_src->degree -= 2;
-
- graph->free_arc(arc);
- BLI_freelinkN(&graph->arcs, arc);
- }
-
- if (node_replaced->degree == 0) {
- BLI_removeNode(graph, node_replaced);
- }
-}
-
-void BLI_replaceNode(BGraph *graph, BNode *node_src, BNode *node_replaced)
-{
- BArc *arc, *next_arc;
-
- for (arc = graph->arcs.first; arc; arc = next_arc) {
- next_arc = arc->next;
-
- if (arc->head == node_replaced) {
- arc->head = node_src;
- node_replaced->degree--;
- node_src->degree++;
- }
-
- if (arc->tail == node_replaced) {
- arc->tail = node_src;
- node_replaced->degree--;
- node_src->degree++;
- }
-
- if (arc->head == arc->tail) {
- node_src->degree -= 2;
-
- graph->free_arc(arc);
- BLI_freelinkN(&graph->arcs, arc);
- }
- }
-
- if (node_replaced->degree == 0) {
- BLI_removeNode(graph, node_replaced);
- }
-}
-
-void BLI_removeDoubleNodes(BGraph *graph, float limit)
-{
- const float limit_sq = limit * limit;
- BNode *node_src, *node_replaced;
-
- for (node_src = graph->nodes.first; node_src; node_src = node_src->next) {
- for (node_replaced = graph->nodes.first; node_replaced; node_replaced = node_replaced->next) {
- if (node_replaced != node_src && len_squared_v3v3(node_replaced->p, node_src->p) <= limit_sq) {
- BLI_replaceNode(graph, node_src, node_replaced);
- }
- }
- }
-
-}
-
-BNode *BLI_FindNodeByPosition(BGraph *graph, const float p[3], const float limit)
-{
- const float limit_sq = limit * limit;
- BNode *closest_node = NULL, *node;
- float min_distance = 0.0f;
-
- for (node = graph->nodes.first; node; node = node->next) {
- float distance = len_squared_v3v3(p, node->p);
- if (distance <= limit_sq && (closest_node == NULL || distance < min_distance)) {
- closest_node = node;
- min_distance = distance;
- }
- }
-
- return closest_node;
-}
-/************************************* SUBGRAPH DETECTION **********************************************/
-
-static void flagSubgraph(BNode *node, int subgraph)
-{
- if (node->subgraph_index == 0) {
- BArc *arc;
- int i;
-
- node->subgraph_index = subgraph;
-
- for (i = 0; i < node->degree; i++) {
- arc = node->arcs[i];
- flagSubgraph(BLI_otherNode(arc, node), subgraph);
- }
- }
-}
-
-int BLI_FlagSubgraphs(BGraph *graph)
-{
- BNode *node;
- int subgraph = 0;
-
- if (BLI_hasAdjacencyList(graph) == 0) {
- BLI_buildAdjacencyList(graph);
- }
-
- for (node = graph->nodes.first; node; node = node->next) {
- node->subgraph_index = 0;
- }
-
- for (node = graph->nodes.first; node; node = node->next) {
- if (node->subgraph_index == 0) {
- subgraph++;
- flagSubgraph(node, subgraph);
- }
- }
-
- return subgraph;
-}
-
-void BLI_ReflagSubgraph(BGraph *graph, int old_subgraph, int new_subgraph)
-{
- BNode *node;
-
- for (node = graph->nodes.first; node; node = node->next) {
- if (node->flag == old_subgraph) {
- node->flag = new_subgraph;
- }
- }
-}
-
-/*************************************** CYCLE DETECTION ***********************************************/
-
-static bool detectCycle(BNode *node, BArc *src_arc)
-{
- bool value = false;
-
- if (node->flag == 0) {
- int i;
-
- /* mark node as visited */
- node->flag = 1;
-
- for (i = 0; i < node->degree && value == 0; i++) {
- BArc *arc = node->arcs[i];
-
- /* don't go back on the source arc */
- if (arc != src_arc) {
- value = detectCycle(BLI_otherNode(arc, node), arc);
- }
- }
- }
- else {
- value = true;
- }
-
- return value;
-}
-
-bool BLI_isGraphCyclic(BGraph *graph)
-{
- BNode *node;
- bool value = false;
-
- /* NEED TO CHECK IF ADJACENCY LIST EXIST */
-
- /* Mark all nodes as not visited */
- BLI_flagNodes(graph, 0);
-
- /* detectCycles in subgraphs */
- for (node = graph->nodes.first; node && value == false; node = node->next) {
- /* only for nodes in subgraphs that haven't been visited yet */
- if (node->flag == 0) {
- value = value || detectCycle(node, NULL);
- }
- }
-
- return value;
-}
-
-BArc *BLI_findConnectedArc(BGraph *graph, BArc *arc, BNode *v)
-{
- BArc *nextArc;
-
- for (nextArc = graph->arcs.first; nextArc; nextArc = nextArc->next) {
- if (arc != nextArc && (nextArc->head == v || nextArc->tail == v)) {
- break;
- }
- }
-
- return nextArc;
-}
-
-/*********************************** GRAPH AS TREE FUNCTIONS *******************************************/
-
-static int subtreeShape(BNode *node, BArc *rootArc, int include_root)
-{
- int depth = 0;
-
- node->flag = 1;
-
- if (include_root) {
- BNode *newNode = BLI_otherNode(rootArc, node);
- return subtreeShape(newNode, rootArc, 0);
- }
- else {
- /* Base case, no arcs leading away */
- if (node->arcs == NULL || *(node->arcs) == NULL) {
- return 0;
- }
- else {
- int i;
-
- for (i = 0; i < node->degree; i++) {
- BArc *arc = node->arcs[i];
- BNode *newNode = BLI_otherNode(arc, node);
-
- /* stop immediate and cyclic backtracking */
- if (arc != rootArc && newNode->flag == 0) {
- depth += subtreeShape(newNode, arc, 0);
- }
- }
- }
-
- return SHAPE_RADIX * depth + 1;
- }
-}
-
-int BLI_subtreeShape(BGraph *graph, BNode *node, BArc *rootArc, int include_root)
-{
- BLI_flagNodes(graph, 0);
- return subtreeShape(node, rootArc, include_root);
-}
-
-float BLI_subtreeLength(BNode *node)
-{
- float length = 0;
- int i;
-
- node->flag = 0; /* flag node as visited */
-
- for (i = 0; i < node->degree; i++) {
- BArc *arc = node->arcs[i];
- BNode *other_node = BLI_otherNode(arc, node);
-
- if (other_node->flag != 0) {
- float subgraph_length = arc->length + BLI_subtreeLength(other_node);
- length = MAX2(length, subgraph_length);
- }
- }
-
- return length;
-}
-
-void BLI_calcGraphLength(BGraph *graph)
-{
- float length = 0;
- int nb_subgraphs;
- int i;
-
- nb_subgraphs = BLI_FlagSubgraphs(graph);
-
- for (i = 1; i <= nb_subgraphs; i++) {
- BNode *node;
-
- for (node = graph->nodes.first; node; node = node->next) {
- /* start on an external node of the subgraph */
- if (node->subgraph_index == i && node->degree == 1) {
- float subgraph_length = BLI_subtreeLength(node);
- length = MAX2(length, subgraph_length);
- break;
- }
- }
- }
-
- graph->length = length;
-}
-
-/********************************* SYMMETRY DETECTION **************************************************/
-
-static void markdownSymmetryArc(BGraph *graph, BArc *arc, BNode *node, int level, float limit);
-
-void BLI_mirrorAlongAxis(float v[3], float center[3], float axis[3])
-{
- float dv[3], pv[3];
-
- sub_v3_v3v3(dv, v, center);
- project_v3_v3v3(pv, dv, axis);
- mul_v3_fl(pv, -2);
- add_v3_v3(v, pv);
-}
-
-static void testRadialSymmetry(BGraph *graph, BNode *root_node, RadialArc *ring, int total, float axis[3], float limit, int group)
-{
- const float limit_sq = limit * limit;
- int symmetric = 1;
- int i;
-
- /* sort ring by angle */
- for (i = 0; i < total - 1; i++) {
- float minAngle = FLT_MAX;
- int minIndex = -1;
- int j;
-
- for (j = i + 1; j < total; j++) {
- float angle = dot_v3v3(ring[i].n, ring[j].n);
-
- /* map negative values to 1..2 */
- if (angle < 0) {
- angle = 1 - angle;
- }
-
- if (angle < minAngle) {
- minIndex = j;
- minAngle = angle;
- }
- }
-
- /* swap if needed */
- if (minIndex != i + 1) {
- RadialArc tmp;
- tmp = ring[i + 1];
- ring[i + 1] = ring[minIndex];
- ring[minIndex] = tmp;
- }
- }
-
- for (i = 0; i < total && symmetric; i++) {
- BNode *node1, *node2;
- float tangent[3];
- float normal[3];
- float p[3];
- int j = (i + 1) % total; /* next arc in the circular list */
-
- add_v3_v3v3(tangent, ring[i].n, ring[j].n);
- cross_v3_v3v3(normal, tangent, axis);
-
- node1 = BLI_otherNode(ring[i].arc, root_node);
- node2 = BLI_otherNode(ring[j].arc, root_node);
-
- copy_v3_v3(p, node2->p);
- BLI_mirrorAlongAxis(p, root_node->p, normal);
-
- /* check if it's within limit before continuing */
- if (len_squared_v3v3(node1->p, p) > limit_sq) {
- symmetric = 0;
- }
-
- }
-
- if (symmetric) {
- /* mark node as symmetric physically */
- copy_v3_v3(root_node->symmetry_axis, axis);
- root_node->symmetry_flag |= SYM_PHYSICAL;
- root_node->symmetry_flag |= SYM_RADIAL;
-
- /* FLAG SYMMETRY GROUP */
- for (i = 0; i < total; i++) {
- ring[i].arc->symmetry_group = group;
- ring[i].arc->symmetry_flag = SYM_SIDE_RADIAL + i;
- }
-
- if (graph->radial_symmetry) {
- graph->radial_symmetry(root_node, ring, total);
- }
- }
-}
-
-static void handleRadialSymmetry(BGraph *graph, BNode *root_node, int depth, float axis[3], float limit)
-{
- RadialArc *ring = NULL;
- RadialArc *unit;
- int total = 0;
- int group;
- int first;
- int i;
-
- /* mark topological symmetry */
- root_node->symmetry_flag |= SYM_TOPOLOGICAL;
-
- /* total the number of arcs in the symmetry ring */
- for (i = 0; i < root_node->degree; i++) {
- BArc *connectedArc = root_node->arcs[i];
-
- /* depth is store as a negative in flag. symmetry level is positive */
- if (connectedArc->symmetry_level == -depth) {
- total++;
- }
- }
-
- ring = MEM_callocN(sizeof(RadialArc) * total, "radial symmetry ring");
- unit = ring;
-
- /* fill in the ring */
- for (i = 0; i < root_node->degree; i++) {
- BArc *connectedArc = root_node->arcs[i];
-
- /* depth is store as a negative in flag. symmetry level is positive */
- if (connectedArc->symmetry_level == -depth) {
- BNode *otherNode = BLI_otherNode(connectedArc, root_node);
- float vec[3];
-
- unit->arc = connectedArc;
-
- /* project the node to node vector on the symmetry plane */
- sub_v3_v3v3(unit->n, otherNode->p, root_node->p);
- project_v3_v3v3(vec, unit->n, axis);
- sub_v3_v3v3(unit->n, unit->n, vec);
-
- normalize_v3(unit->n);
-
- unit++;
- }
- }
-
- /* sort ring by arc length
- * using a rather bogus insertion sort
- * but rings will never get too big to matter
- * */
- for (i = 0; i < total; i++) {
- int j;
-
- for (j = i - 1; j >= 0; j--) {
- BArc *arc1, *arc2;
-
- arc1 = ring[j].arc;
- arc2 = ring[j + 1].arc;
-
- if (arc1->length > arc2->length) {
- /* swap with smaller */
- RadialArc tmp;
-
- tmp = ring[j + 1];
- ring[j + 1] = ring[j];
- ring[j] = tmp;
- }
- else {
- break;
- }
- }
- }
-
- /* Dispatch to specific symmetry tests */
- first = 0;
- group = 0;
-
- for (i = 1; i < total; i++) {
- int dispatch = 0;
- int last = i - 1;
-
- if (fabsf(ring[first].arc->length - ring[i].arc->length) > limit) {
- dispatch = 1;
- }
-
- /* if not dispatching already and on last arc
- * Dispatch using current arc as last
- */
- if (dispatch == 0 && i == total - 1) {
- last = i;
- dispatch = 1;
- }
-
- if (dispatch) {
- int sub_total = last - first + 1;
-
- group += 1;
-
- if (sub_total == 1) {
- group -= 1; /* not really a group so decrement */
- /* NOTHING TO DO */
- }
- else if (sub_total == 2) {
- BArc *arc1, *arc2;
- BNode *node1, *node2;
-
- arc1 = ring[first].arc;
- arc2 = ring[last].arc;
-
- node1 = BLI_otherNode(arc1, root_node);
- node2 = BLI_otherNode(arc2, root_node);
-
- testAxialSymmetry(graph, root_node, node1, node2, arc1, arc2, axis, limit, group);
- }
- else if (sub_total != total) /* allocate a new sub ring if needed */ {
- RadialArc *sub_ring = MEM_callocN(sizeof(RadialArc) * sub_total, "radial symmetry ring");
- int sub_i;
-
- /* fill in the sub ring */
- for (sub_i = 0; sub_i < sub_total; sub_i++) {
- sub_ring[sub_i] = ring[first + sub_i];
- }
-
- testRadialSymmetry(graph, root_node, sub_ring, sub_total, axis, limit, group);
-
- MEM_freeN(sub_ring);
- }
- else if (sub_total == total) {
- testRadialSymmetry(graph, root_node, ring, total, axis, limit, group);
- }
-
- first = i;
- }
- }
-
-
- MEM_freeN(ring);
-}
-
-static void flagAxialSymmetry(BNode *root_node, BNode *end_node, BArc *arc, int group)
-{
- float vec[3];
-
- arc->symmetry_group = group;
-
- sub_v3_v3v3(vec, end_node->p, root_node->p);
-
- if (dot_v3v3(vec, root_node->symmetry_axis) < 0) {
- arc->symmetry_flag |= SYM_SIDE_NEGATIVE;
- }
- else {
- arc->symmetry_flag |= SYM_SIDE_POSITIVE;
- }
-}
-
-static void testAxialSymmetry(BGraph *graph, BNode *root_node, BNode *node1, BNode *node2, BArc *arc1, BArc *arc2, float axis[3], float limit, int group)
-{
- const float limit_sq = limit * limit;
- float nor[3], vec[3], p[3];
-
- sub_v3_v3v3(p, node1->p, root_node->p);
- cross_v3_v3v3(nor, p, axis);
-
- sub_v3_v3v3(p, root_node->p, node2->p);
- cross_v3_v3v3(vec, p, axis);
- add_v3_v3(vec, nor);
-
- cross_v3_v3v3(nor, vec, axis);
-
- if (fabsf(nor[0]) > fabsf(nor[1]) && fabsf(nor[0]) > fabsf(nor[2]) && nor[0] < 0) {
- negate_v3(nor);
- }
- else if (fabsf(nor[1]) > fabsf(nor[0]) && fabsf(nor[1]) > fabsf(nor[2]) && nor[1] < 0) {
- negate_v3(nor);
- }
- else if (fabsf(nor[2]) > fabsf(nor[1]) && fabsf(nor[2]) > fabsf(nor[0]) && nor[2] < 0) {
- negate_v3(nor);
- }
-
- /* mirror node2 along axis */
- copy_v3_v3(p, node2->p);
- BLI_mirrorAlongAxis(p, root_node->p, nor);
-
- /* check if it's within limit before continuing */
- if (len_squared_v3v3(node1->p, p) <= limit_sq) {
- /* mark node as symmetric physically */
- copy_v3_v3(root_node->symmetry_axis, nor);
- root_node->symmetry_flag |= SYM_PHYSICAL;
- root_node->symmetry_flag |= SYM_AXIAL;
-
- /* flag side on arcs */
- flagAxialSymmetry(root_node, node1, arc1, group);
- flagAxialSymmetry(root_node, node2, arc2, group);
-
- if (graph->axial_symmetry) {
- graph->axial_symmetry(root_node, node1, node2, arc1, arc2);
- }
- }
- else {
- /* NOT SYMMETRIC */
- }
-}
-
-static void handleAxialSymmetry(BGraph *graph, BNode *root_node, int depth, float axis[3], float limit)
-{
- BArc *arc1 = NULL, *arc2 = NULL;
- BNode *node1 = NULL, *node2 = NULL;
- int i;
-
- /* mark topological symmetry */
- root_node->symmetry_flag |= SYM_TOPOLOGICAL;
-
- for (i = 0; i < root_node->degree; i++) {
- BArc *connectedArc = root_node->arcs[i];
-
- /* depth is store as a negative in flag. symmetry level is positive */
- if (connectedArc->symmetry_level == -depth) {
- if (arc1 == NULL) {
- arc1 = connectedArc;
- node1 = BLI_otherNode(arc1, root_node);
- }
- else {
- arc2 = connectedArc;
- node2 = BLI_otherNode(arc2, root_node);
- break; /* Can stop now, the two arcs have been found */
- }
- }
- }
-
- /* shouldn't happen, but just to be sure */
- if (node1 == NULL || node2 == NULL) {
- return;
- }
-
- testAxialSymmetry(graph, root_node, node1, node2, arc1, arc2, axis, limit, 1);
-}
-
-static void markdownSecondarySymmetry(BGraph *graph, BNode *node, int depth, int level, float limit)
-{
- float axis[3] = {0, 0, 0};
- int count = 0;
- int i;
-
- /* count the number of branches in this symmetry group
- * and determinate the axis of symmetry
- */
- for (i = 0; i < node->degree; i++) {
- BArc *connectedArc = node->arcs[i];
-
- /* depth is store as a negative in flag. symmetry level is positive */
- if (connectedArc->symmetry_level == -depth) {
- count++;
- }
- /* If arc is on the axis */
- else if (connectedArc->symmetry_level == level) {
- add_v3_v3(axis, connectedArc->head->p);
- sub_v3_v3v3(axis, axis, connectedArc->tail->p);
- }
- }
-
- normalize_v3(axis);
-
- /* Split between axial and radial symmetry */
- if (count == 2) {
- handleAxialSymmetry(graph, node, depth, axis, limit);
- }
- else {
- handleRadialSymmetry(graph, node, depth, axis, limit);
- }
-
- /* markdown secondary symetries */
- for (i = 0; i < node->degree; i++) {
- BArc *connectedArc = node->arcs[i];
-
- if (connectedArc->symmetry_level == -depth) {
- /* markdown symmetry for branches corresponding to the depth */
- markdownSymmetryArc(graph, connectedArc, node, level + 1, limit);
- }
- }
-}
-
-static void markdownSymmetryArc(BGraph *graph, BArc *arc, BNode *node, int level, float limit)
-{
- int i;
-
- /* if arc is null, we start straight from a node */
- if (arc) {
- arc->symmetry_level = level;
-
- node = BLI_otherNode(arc, node);
- }
-
- for (i = 0; i < node->degree; i++) {
- BArc *connectedArc = node->arcs[i];
-
- if (connectedArc != arc) {
- BNode *connectedNode = BLI_otherNode(connectedArc, node);
-
- /* symmetry level is positive value, negative values is subtree depth */
- connectedArc->symmetry_level = -BLI_subtreeShape(graph, connectedNode, connectedArc, 0);
- }
- }
-
- arc = NULL;
-
- for (i = 0; i < node->degree; i++) {
- int issymmetryAxis = 0;
- BArc *connectedArc = node->arcs[i];
-
- /* only arcs not already marked as symetric */
- if (connectedArc->symmetry_level < 0) {
- int j;
-
- /* true by default */
- issymmetryAxis = 1;
-
- for (j = 0; j < node->degree; j++) {
- BArc *otherArc = node->arcs[j];
-
- /* different arc, same depth */
- if (otherArc != connectedArc && otherArc->symmetry_level == connectedArc->symmetry_level) {
- /* not on the symmetry axis */
- issymmetryAxis = 0;
- break;
- }
- }
- }
-
- /* arc could be on the symmetry axis */
- if (issymmetryAxis == 1) {
- /* no arc as been marked previously, keep this one */
- if (arc == NULL) {
- arc = connectedArc;
- }
- else if (connectedArc->symmetry_level < arc->symmetry_level) {
- /* go with more complex subtree as symmetry arc */
- arc = connectedArc;
- }
- }
- }
-
- /* go down the arc continuing the symmetry axis */
- if (arc) {
- markdownSymmetryArc(graph, arc, node, level, limit);
- }
-
-
- /* secondary symmetry */
- for (i = 0; i < node->degree; i++) {
- BArc *connectedArc = node->arcs[i];
-
- /* only arcs not already marked as symetric and is not the next arc on the symmetry axis */
- if (connectedArc->symmetry_level < 0) {
- /* subtree depth is store as a negative value in the symmetry */
- markdownSecondarySymmetry(graph, node, -connectedArc->symmetry_level, level, limit);
- }
- }
-}
-
-void BLI_markdownSymmetry(BGraph *graph, BNode *root_node, float limit)
-{
- BNode *node;
- BArc *arc;
-
- if (root_node == NULL) {
- return;
- }
-
- if (BLI_isGraphCyclic(graph)) {
- return;
- }
-
- /* mark down all arcs as non-symetric */
- BLI_flagArcs(graph, 0);
-
- /* mark down all nodes as not on the symmetry axis */
- BLI_flagNodes(graph, 0);
-
- node = root_node;
-
- /* sanity check REMOVE ME */
- if (node->degree > 0) {
- arc = node->arcs[0];
-
- if (node->degree == 1) {
- markdownSymmetryArc(graph, arc, node, 1, limit);
- }
- else {
- markdownSymmetryArc(graph, NULL, node, 1, limit);
- }
-
-
-
- /* mark down non-symetric arcs */
- for (arc = graph->arcs.first; arc; arc = arc->next) {
- if (arc->symmetry_level < 0) {
- arc->symmetry_level = 0;
- }
- else {
- /* mark down nodes with the lowest level symmetry axis */
- if (arc->head->symmetry_level == 0 || arc->head->symmetry_level > arc->symmetry_level) {
- arc->head->symmetry_level = arc->symmetry_level;
- }
- if (arc->tail->symmetry_level == 0 || arc->tail->symmetry_level > arc->symmetry_level) {
- arc->tail->symmetry_level = arc->symmetry_level;
- }
- }
- }
- }
-}
-
-void *IT_head(void *arg)
-{
- BArcIterator *iter = (BArcIterator *)arg;
- return iter->head(iter);
-}
-
-void *IT_tail(void *arg)
-{
- BArcIterator *iter = (BArcIterator *)arg;
- return iter->tail(iter);
-}
-
-void *IT_peek(void *arg, int n)
-{
- BArcIterator *iter = (BArcIterator *)arg;
-
- if (iter->index + n < 0) {
- return iter->head(iter);
- }
- else if (iter->index + n >= iter->length) {
- return iter->tail(iter);
- }
- else {
- return iter->peek(iter, n);
- }
-}
-
-void *IT_next(void *arg)
-{
- BArcIterator *iter = (BArcIterator *)arg;
- return iter->next(iter);
-}
-
-void *IT_nextN(void *arg, int n)
-{
- BArcIterator *iter = (BArcIterator *)arg;
- return iter->nextN(iter, n);
-}
-
-void *IT_previous(void *arg)
-{
- BArcIterator *iter = (BArcIterator *)arg;
- return iter->previous(iter);
-}
-
-int IT_stopped(void *arg)
-{
- BArcIterator *iter = (BArcIterator *)arg;
- return iter->stopped(iter);
-}
diff --git a/source/blender/blenlib/intern/math_color.c b/source/blender/blenlib/intern/math_color.c
index ef9e46fc62d..9399646bedf 100644
--- a/source/blender/blenlib/intern/math_color.c
+++ b/source/blender/blenlib/intern/math_color.c
@@ -380,8 +380,10 @@ void xyz_to_rgb(float xc, float yc, float zc, float *r, float *g, float *b, int
}
}
-/* we define a 'cpack' here as a (3 byte color code) number that can be expressed like 0xFFAA66 or so.
- * for that reason it is sensitive for endianness... with this function it works correctly
+/**
+ * We define a 'cpack' here as a (3 byte color code) number that can be expressed like 0xFFAA66 or so.
+ * for that reason it is sensitive for endianness... with this function it works correctly.
+ * \see #imm_cpack
*/
unsigned int hsv_to_cpack(float h, float s, float v)
@@ -675,135 +677,80 @@ void rgb_to_lab(float r, float g, float b, float *ll, float *la, float *lb)
xyz_to_lab(x, y, z, ll, la, lb);
}
-static void xyz_to_lms(float x, float y, float z, float *l, float *m, float *s)
-{
- *l = 0.3897f * x + 0.6890f * y - 0.0787f * z;
- *m = -0.2298f * x + 1.1834f * y + 0.0464f * z;
- *s = z;
-}
-
-static void lms_to_xyz(float l, float m, float s, float *x, float *y, float *z)
-{
- *x = 1.9102f * l - 1.1121f * m + 0.2019f * s;
- *y = 0.3709f * l + 0.6290f * m + 0.0000f * s;
- *z = s;
-}
-
-static void normalize_rgb(float rgb[3])
-{
- const float max = max_fff(rgb[0], rgb[1], rgb[2]);
-
- if (max > 0.0f) {
- mul_v3_fl(rgb, 1.0f / max);
- }
-}
+/* ****************************** blackbody ******************************** */
-/* Color rendering of spectra, adapted from public domain code by John Walker,
- * http://www.fourmilab.ch/
+/* Calculate color in range 800..12000 using an approximation
+ * a/x+bx+c for R and G and ((at + b)t + c)t + d) for B
+ * Max absolute error for RGB is (0.00095, 0.00077, 0.00057),
+ * which is enough to get the same 8 bit/channel color.
*/
-static void spectrum_to_xyz(float temperature, float xyz[3])
-{
- int i;
- float lambda, x = 0.0f, y = 0.0f, z = 0.0f, xyz_sum;
-
- /* CIE colour matching functions xBar, yBar, and zBar for wavelengths from
- * 380 through 780 nanometers, every 5 nanometers.
- * For a wavelength lambda in this range:
- *
- * cie_colour_match[(lambda - 380) / 5][0] = xBar
- * cie_colour_match[(lambda - 380) / 5][1] = yBar
- * cie_colour_match[(lambda - 380) / 5][2] = zBar
- */
-
- const float cie_colour_match[81][3] = {
- {0.0014f, 0.0000f, 0.0065f}, {0.0022f, 0.0001f, 0.0105f}, {0.0042f, 0.0001f, 0.0201f},
- {0.0076f, 0.0002f, 0.0362f}, {0.0143f, 0.0004f, 0.0679f}, {0.0232f, 0.0006f, 0.1102f},
- {0.0435f, 0.0012f, 0.2074f}, {0.0776f, 0.0022f, 0.3713f}, {0.1344f, 0.0040f, 0.6456f},
- {0.2148f, 0.0073f, 1.0391f}, {0.2839f, 0.0116f, 1.3856f}, {0.3285f, 0.0168f, 1.6230f},
- {0.3483f, 0.0230f, 1.7471f}, {0.3481f, 0.0298f, 1.7826f}, {0.3362f, 0.0380f, 1.7721f},
- {0.3187f, 0.0480f, 1.7441f}, {0.2908f, 0.0600f, 1.6692f}, {0.2511f, 0.0739f, 1.5281f},
- {0.1954f, 0.0910f, 1.2876f}, {0.1421f, 0.1126f, 1.0419f}, {0.0956f, 0.1390f, 0.8130f},
- {0.0580f, 0.1693f, 0.6162f}, {0.0320f, 0.2080f, 0.4652f}, {0.0147f, 0.2586f, 0.3533f},
- {0.0049f, 0.3230f, 0.2720f}, {0.0024f, 0.4073f, 0.2123f}, {0.0093f, 0.5030f, 0.1582f},
- {0.0291f, 0.6082f, 0.1117f}, {0.0633f, 0.7100f, 0.0782f}, {0.1096f, 0.7932f, 0.0573f},
- {0.1655f, 0.8620f, 0.0422f}, {0.2257f, 0.9149f, 0.0298f}, {0.2904f, 0.9540f, 0.0203f},
- {0.3597f, 0.9803f, 0.0134f}, {0.4334f, 0.9950f, 0.0087f}, {0.5121f, 1.0000f, 0.0057f},
- {0.5945f, 0.9950f, 0.0039f}, {0.6784f, 0.9786f, 0.0027f}, {0.7621f, 0.9520f, 0.0021f},
- {0.8425f, 0.9154f, 0.0018f}, {0.9163f, 0.8700f, 0.0017f}, {0.9786f, 0.8163f, 0.0014f},
- {1.0263f, 0.7570f, 0.0011f}, {1.0567f, 0.6949f, 0.0010f}, {1.0622f, 0.6310f, 0.0008f},
- {1.0456f, 0.5668f, 0.0006f}, {1.0026f, 0.5030f, 0.0003f}, {0.9384f, 0.4412f, 0.0002f},
- {0.8544f, 0.3810f, 0.0002f}, {0.7514f, 0.3210f, 0.0001f}, {0.6424f, 0.2650f, 0.0000f},
- {0.5419f, 0.2170f, 0.0000f}, {0.4479f, 0.1750f, 0.0000f}, {0.3608f, 0.1382f, 0.0000f},
- {0.2835f, 0.1070f, 0.0000f}, {0.2187f, 0.0816f, 0.0000f}, {0.1649f, 0.0610f, 0.0000f},
- {0.1212f, 0.0446f, 0.0000f}, {0.0874f, 0.0320f, 0.0000f}, {0.0636f, 0.0232f, 0.0000f},
- {0.0468f, 0.0170f, 0.0000f}, {0.0329f, 0.0119f, 0.0000f}, {0.0227f, 0.0082f, 0.0000f},
- {0.0158f, 0.0057f, 0.0000f}, {0.0114f, 0.0041f, 0.0000f}, {0.0081f, 0.0029f, 0.0000f},
- {0.0058f, 0.0021f, 0.0000f}, {0.0041f, 0.0015f, 0.0000f}, {0.0029f, 0.0010f, 0.0000f},
- {0.0020f, 0.0007f, 0.0000f}, {0.0014f, 0.0005f, 0.0000f}, {0.0010f, 0.0004f, 0.0000f},
- {0.0007f, 0.0002f, 0.0000f}, {0.0005f, 0.0002f, 0.0000f}, {0.0003f, 0.0001f, 0.0000f},
- {0.0002f, 0.0001f, 0.0000f}, {0.0002f, 0.0001f, 0.0000f}, {0.0001f, 0.0000f, 0.0000f},
- {0.0001f, 0.0000f, 0.0000f}, {0.0001f, 0.0000f, 0.0000f}, {0.0000f, 0.0000f, 0.0000f}
- };
-
- for (i = 0, lambda = 380.0f; lambda < 780.1f; i++, lambda += 5.0f) {
- /* wavelength in meter */
- const float wlm = lambda * 1e-9f;
- const float Me = (3.74183e-16f * powf(wlm, -5.0f)) / (expf(1.4388e-2f / (wlm * temperature)) - 1.0f);
-
- x += Me * cie_colour_match[i][0];
- y += Me * cie_colour_match[i][1];
- z += Me * cie_colour_match[i][2];
+static const float blackbody_table_r[6][3] = {
+ { 2.52432244e+03f, -1.06185848e-03f, 3.11067539e+00f },
+ { 3.37763626e+03f, -4.34581697e-04f, 1.64843306e+00f },
+ { 4.10671449e+03f, -8.61949938e-05f, 6.41423749e-01f },
+ { 4.66849800e+03f, 2.85655028e-05f, 1.29075375e-01f },
+ { 4.60124770e+03f, 2.89727618e-05f, 1.48001316e-01f },
+ { 3.78765709e+03f, 9.36026367e-06f, 3.98995841e-01f },
+};
+
+static const float blackbody_table_g[6][3] = {
+ { -7.50343014e+02f, 3.15679613e-04f, 4.73464526e-01f },
+ { -1.00402363e+03f, 1.29189794e-04f, 9.08181524e-01f },
+ { -1.22075471e+03f, 2.56245413e-05f, 1.20753416e+00f },
+ { -1.42546105e+03f, -4.01730887e-05f, 1.44002695e+00f },
+ { -1.18134453e+03f, -2.18913373e-05f, 1.30656109e+00f },
+ { -5.00279505e+02f, -4.59745390e-06f, 1.09090465e+00f },
+};
+
+static const float blackbody_table_b[6][4] = {
+ { 0.0f, 0.0f, 0.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f, 0.0f },
+ { 0.0f, 0.0f, 0.0f, 0.0f },
+ { -2.02524603e-11f, 1.79435860e-07f, -2.60561875e-04f, -1.41761141e-02f },
+ { -2.22463426e-13f, -1.55078698e-08f, 3.81675160e-04f, -7.30646033e-01f },
+ { 6.72595954e-13f, -2.73059993e-08f, 4.24068546e-04f, -7.52204323e-01f },
+};
+
+static void blackbody_temperature_to_rgb(float rgb[3], float t)
+{
+ if (t >= 12000.0f) {
+ rgb[0] = 0.826270103f;
+ rgb[1] = 0.994478524f;
+ rgb[2] = 1.56626022f;
+ }
+ else if (t < 965.0f) {
+ rgb[0] = 4.70366907f;
+ rgb[1] = 0.0f;
+ rgb[2] = 0.0f;
+ }
+ else {
+ int i = (t >= 6365.0f) ? 5 :
+ (t >= 3315.0f) ? 4 :
+ (t >= 1902.0f) ? 3 :
+ (t >= 1449.0f) ? 2 :
+ (t >= 1167.0f) ? 1 : 0;
+
+ const float *r = blackbody_table_r[i];
+ const float *g = blackbody_table_g[i];
+ const float *b = blackbody_table_b[i];
+
+ const float t_inv = 1.0f / t;
+ rgb[0] = r[0] * t_inv + r[1] * t + r[2];
+ rgb[1] = g[0] * t_inv + g[1] * t + g[2];
+ rgb[2] = ((b[0] * t + b[1]) * t + b[2]) * t + b[3];
}
-
- xyz_sum = (x + y + z);
-
- xyz[0] = x / xyz_sum;
- xyz[1] = y / xyz_sum;
- xyz[2] = z / xyz_sum;
}
void blackbody_temperature_to_rgb_table(float *r_table, int width, float min, float max)
{
- int i, j = 0, dj = 1;
- float rgb[3], xyz[3], lms[3], lms_w[3];
- float bb_temp;
-
- if (min < max) {
- SWAP(float, min, max);
- j = width - 1;
- dj = -1;
- }
+ for (int i = 0; i < width; i++) {
+ float temperature = min + (max - min) / (float)width * (float)i;
- for (i = 0; i < width; i++, j += dj) {
- bb_temp = min + (max - min) / (float)width * (float)i;
+ float rgb[3];
+ blackbody_temperature_to_rgb(rgb, temperature);
- /* integrate blackbody radiation spectrum to XYZ */
- spectrum_to_xyz(bb_temp, xyz);
-
- /* normalize highest temperature to white (in LMS system) */
- xyz_to_lms(xyz[0], xyz[1], xyz[2], &lms[0], &lms[1], &lms[2]);
-
- if (i == 0) {
- lms_w[0] = 1.0f / lms[0];
- lms_w[1] = 1.0f / lms[1];
- lms_w[2] = 1.0f / lms[2];
- }
-
- mul_v3_v3(lms, lms_w);
-
- lms_to_xyz(lms[0], lms[1], lms[2], &xyz[0], &xyz[1], &xyz[2]);
-
- /* convert to RGB */
- xyz_to_rgb(xyz[0], xyz[1], xyz[2], &rgb[0], &rgb[1], &rgb[2], BLI_XYZ_CIE);
- constrain_rgb(&rgb[0], &rgb[1], &rgb[2]);
- normalize_rgb(rgb);
-
- copy_v3_v3(&r_table[(j << 2)], rgb);
-
- if (rgb[2] > 0.1f)
- r_table[(j << 2) + 3] = rgb[2];
- else
- r_table[(j << 2) + 3] = 0.0f;
+ copy_v3_v3(&r_table[i * 4], rgb);
+ r_table[i * 4 + 3] = 0.0f;
}
}
diff --git a/source/blender/blenlib/intern/math_matrix.c b/source/blender/blenlib/intern/math_matrix.c
index 311d963f64d..3559500bf63 100644
--- a/source/blender/blenlib/intern/math_matrix.c
+++ b/source/blender/blenlib/intern/math_matrix.c
@@ -74,23 +74,23 @@ void unit_m4(float m[4][4])
m[3][0] = m[3][1] = m[3][2] = 0.0f;
}
-void copy_m2_m2(float m1[2][2], float m2[2][2])
+void copy_m2_m2(float m1[2][2], const float m2[2][2])
{
memcpy(m1, m2, sizeof(float[2][2]));
}
-void copy_m3_m3(float m1[3][3], float m2[3][3])
+void copy_m3_m3(float m1[3][3], const float m2[3][3])
{
/* destination comes first: */
memcpy(m1, m2, sizeof(float[3][3]));
}
-void copy_m4_m4(float m1[4][4], float m2[4][4])
+void copy_m4_m4(float m1[4][4], const float m2[4][4])
{
memcpy(m1, m2, sizeof(float[4][4]));
}
-void copy_m3_m4(float m1[3][3], float m2[4][4])
+void copy_m3_m4(float m1[3][3], const float m2[4][4])
{
m1[0][0] = m2[0][0];
m1[0][1] = m2[0][1];
@@ -105,7 +105,7 @@ void copy_m3_m4(float m1[3][3], float m2[4][4])
m1[2][2] = m2[2][2];
}
-void copy_m4_m3(float m1[4][4], float m2[3][3]) /* no clear */
+void copy_m4_m3(float m1[4][4], const float m2[3][3]) /* no clear */
{
m1[0][0] = m2[0][0];
m1[0][1] = m2[0][1];
@@ -131,7 +131,7 @@ void copy_m4_m3(float m1[4][4], float m2[3][3]) /* no clear */
}
-void copy_m3_m3d(float R[3][3], double A[3][3])
+void copy_m3_m3d(float R[3][3], const double A[3][3])
{
/* Keep it stupid simple for better data flow in CPU. */
R[0][0] = (float)A[0][0];
@@ -177,64 +177,107 @@ void swap_m4m4(float m1[4][4], float m2[4][4])
/******************************** Arithmetic *********************************/
-void mul_m4_m4m4(float m1[4][4], float m3_[4][4], float m2_[4][4])
+void mul_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4])
{
- float m2[4][4], m3[4][4];
+ if (A == R)
+ mul_m4_m4_post(R, B);
+ else if (B == R)
+ mul_m4_m4_pre(R, A);
+ else
+ mul_m4_m4m4_uniq(R, A, B);
+}
- /* copy so it works when m1 is the same pointer as m2 or m3 */
- copy_m4_m4(m2, m2_);
- copy_m4_m4(m3, m3_);
+void mul_m4_m4m4_uniq(float R[4][4], const float A[4][4], const float B[4][4])
+{
+ BLI_assert(R != A && R != B);
- /* matrix product: m1[j][k] = m2[j][i].m3[i][k] */
- m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0] + m2[0][3] * m3[3][0];
- m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1] + m2[0][3] * m3[3][1];
- m1[0][2] = m2[0][0] * m3[0][2] + m2[0][1] * m3[1][2] + m2[0][2] * m3[2][2] + m2[0][3] * m3[3][2];
- m1[0][3] = m2[0][0] * m3[0][3] + m2[0][1] * m3[1][3] + m2[0][2] * m3[2][3] + m2[0][3] * m3[3][3];
+ /* matrix product: R[j][k] = A[j][i] . B[i][k] */
+ R[0][0] = B[0][0] * A[0][0] + B[0][1] * A[1][0] + B[0][2] * A[2][0] + B[0][3] * A[3][0];
+ R[0][1] = B[0][0] * A[0][1] + B[0][1] * A[1][1] + B[0][2] * A[2][1] + B[0][3] * A[3][1];
+ R[0][2] = B[0][0] * A[0][2] + B[0][1] * A[1][2] + B[0][2] * A[2][2] + B[0][3] * A[3][2];
+ R[0][3] = B[0][0] * A[0][3] + B[0][1] * A[1][3] + B[0][2] * A[2][3] + B[0][3] * A[3][3];
- m1[1][0] = m2[1][0] * m3[0][0] + m2[1][1] * m3[1][0] + m2[1][2] * m3[2][0] + m2[1][3] * m3[3][0];
- m1[1][1] = m2[1][0] * m3[0][1] + m2[1][1] * m3[1][1] + m2[1][2] * m3[2][1] + m2[1][3] * m3[3][1];
- m1[1][2] = m2[1][0] * m3[0][2] + m2[1][1] * m3[1][2] + m2[1][2] * m3[2][2] + m2[1][3] * m3[3][2];
- m1[1][3] = m2[1][0] * m3[0][3] + m2[1][1] * m3[1][3] + m2[1][2] * m3[2][3] + m2[1][3] * m3[3][3];
+ R[1][0] = B[1][0] * A[0][0] + B[1][1] * A[1][0] + B[1][2] * A[2][0] + B[1][3] * A[3][0];
+ R[1][1] = B[1][0] * A[0][1] + B[1][1] * A[1][1] + B[1][2] * A[2][1] + B[1][3] * A[3][1];
+ R[1][2] = B[1][0] * A[0][2] + B[1][1] * A[1][2] + B[1][2] * A[2][2] + B[1][3] * A[3][2];
+ R[1][3] = B[1][0] * A[0][3] + B[1][1] * A[1][3] + B[1][2] * A[2][3] + B[1][3] * A[3][3];
- m1[2][0] = m2[2][0] * m3[0][0] + m2[2][1] * m3[1][0] + m2[2][2] * m3[2][0] + m2[2][3] * m3[3][0];
- m1[2][1] = m2[2][0] * m3[0][1] + m2[2][1] * m3[1][1] + m2[2][2] * m3[2][1] + m2[2][3] * m3[3][1];
- m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2] + m2[2][3] * m3[3][2];
- m1[2][3] = m2[2][0] * m3[0][3] + m2[2][1] * m3[1][3] + m2[2][2] * m3[2][3] + m2[2][3] * m3[3][3];
+ R[2][0] = B[2][0] * A[0][0] + B[2][1] * A[1][0] + B[2][2] * A[2][0] + B[2][3] * A[3][0];
+ R[2][1] = B[2][0] * A[0][1] + B[2][1] * A[1][1] + B[2][2] * A[2][1] + B[2][3] * A[3][1];
+ R[2][2] = B[2][0] * A[0][2] + B[2][1] * A[1][2] + B[2][2] * A[2][2] + B[2][3] * A[3][2];
+ R[2][3] = B[2][0] * A[0][3] + B[2][1] * A[1][3] + B[2][2] * A[2][3] + B[2][3] * A[3][3];
- m1[3][0] = m2[3][0] * m3[0][0] + m2[3][1] * m3[1][0] + m2[3][2] * m3[2][0] + m2[3][3] * m3[3][0];
- m1[3][1] = m2[3][0] * m3[0][1] + m2[3][1] * m3[1][1] + m2[3][2] * m3[2][1] + m2[3][3] * m3[3][1];
- m1[3][2] = m2[3][0] * m3[0][2] + m2[3][1] * m3[1][2] + m2[3][2] * m3[2][2] + m2[3][3] * m3[3][2];
- m1[3][3] = m2[3][0] * m3[0][3] + m2[3][1] * m3[1][3] + m2[3][2] * m3[2][3] + m2[3][3] * m3[3][3];
+ R[3][0] = B[3][0] * A[0][0] + B[3][1] * A[1][0] + B[3][2] * A[2][0] + B[3][3] * A[3][0];
+ R[3][1] = B[3][0] * A[0][1] + B[3][1] * A[1][1] + B[3][2] * A[2][1] + B[3][3] * A[3][1];
+ R[3][2] = B[3][0] * A[0][2] + B[3][1] * A[1][2] + B[3][2] * A[2][2] + B[3][3] * A[3][2];
+ R[3][3] = B[3][0] * A[0][3] + B[3][1] * A[1][3] + B[3][2] * A[2][3] + B[3][3] * A[3][3];
+}
+void mul_m4_m4_pre(float R[4][4], const float A[4][4])
+{
+ BLI_assert(A != R);
+ float B[4][4];
+ copy_m4_m4(B, R);
+ mul_m4_m4m4_uniq(R, A, B);
}
-void mul_m3_m3m3(float m1[3][3], float m3_[3][3], float m2_[3][3])
+void mul_m4_m4_post(float R[4][4], const float B[4][4])
{
- float m2[3][3], m3[3][3];
+ BLI_assert(B != R);
+ float A[4][4];
+ copy_m4_m4(A, R);
+ mul_m4_m4m4_uniq(R, A, B);
+}
- /* copy so it works when m1 is the same pointer as m2 or m3 */
- copy_m3_m3(m2, m2_);
- copy_m3_m3(m3, m3_);
+void mul_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3])
+{
+ if (A == R)
+ mul_m3_m3_post(R, B);
+ else if (B == R)
+ mul_m3_m3_pre(R, A);
+ else
+ mul_m3_m3m3_uniq(R, A, B);
+}
- /* m1[i][j] = m2[i][k] * m3[k][j], args are flipped! */
- m1[0][0] = m2[0][0] * m3[0][0] + m2[0][1] * m3[1][0] + m2[0][2] * m3[2][0];
- m1[0][1] = m2[0][0] * m3[0][1] + m2[0][1] * m3[1][1] + m2[0][2] * m3[2][1];
- m1[0][2] = m2[0][0] * m3[0][2] + m2[0][1] * m3[1][2] + m2[0][2] * m3[2][2];
+void mul_m3_m3_pre(float R[3][3], const float A[3][3])
+{
+ BLI_assert(A != R);
+ float B[3][3];
+ copy_m3_m3(B, R);
+ mul_m3_m3m3_uniq(R, A, B);
+}
- m1[1][0] = m2[1][0] * m3[0][0] + m2[1][1] * m3[1][0] + m2[1][2] * m3[2][0];
- m1[1][1] = m2[1][0] * m3[0][1] + m2[1][1] * m3[1][1] + m2[1][2] * m3[2][1];
- m1[1][2] = m2[1][0] * m3[0][2] + m2[1][1] * m3[1][2] + m2[1][2] * m3[2][2];
+void mul_m3_m3_post(float R[3][3], const float B[3][3])
+{
+ BLI_assert(B != R);
+ float A[3][3];
+ copy_m3_m3(A, R);
+ mul_m3_m3m3_uniq(R, A, B);
+}
- m1[2][0] = m2[2][0] * m3[0][0] + m2[2][1] * m3[1][0] + m2[2][2] * m3[2][0];
- m1[2][1] = m2[2][0] * m3[0][1] + m2[2][1] * m3[1][1] + m2[2][2] * m3[2][1];
- m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2];
+void mul_m3_m3m3_uniq(float R[3][3], const float A[3][3], const float B[3][3])
+{
+ BLI_assert(R != A && R != B);
+
+ R[0][0] = B[0][0] * A[0][0] + B[0][1] * A[1][0] + B[0][2] * A[2][0];
+ R[0][1] = B[0][0] * A[0][1] + B[0][1] * A[1][1] + B[0][2] * A[2][1];
+ R[0][2] = B[0][0] * A[0][2] + B[0][1] * A[1][2] + B[0][2] * A[2][2];
+
+ R[1][0] = B[1][0] * A[0][0] + B[1][1] * A[1][0] + B[1][2] * A[2][0];
+ R[1][1] = B[1][0] * A[0][1] + B[1][1] * A[1][1] + B[1][2] * A[2][1];
+ R[1][2] = B[1][0] * A[0][2] + B[1][1] * A[1][2] + B[1][2] * A[2][2];
+
+ R[2][0] = B[2][0] * A[0][0] + B[2][1] * A[1][0] + B[2][2] * A[2][0];
+ R[2][1] = B[2][0] * A[0][1] + B[2][1] * A[1][1] + B[2][2] * A[2][1];
+ R[2][2] = B[2][0] * A[0][2] + B[2][1] * A[1][2] + B[2][2] * A[2][2];
}
-void mul_m4_m4m3(float m1[4][4], float m3_[4][4], float m2_[3][3])
+void mul_m4_m4m3(float m1[4][4], const float m3_[4][4], const float m2_[3][3])
{
float m2[3][3], m3[4][4];
/* copy so it works when m1 is the same pointer as m2 or m3 */
+ /* TODO: avoid copying when matrices are different */
copy_m3_m3(m2, m2_);
copy_m4_m4(m3, m3_);
@@ -250,11 +293,12 @@ void mul_m4_m4m3(float m1[4][4], float m3_[4][4], float m2_[3][3])
}
/* m1 = m2 * m3, ignore the elements on the 4th row/column of m3 */
-void mul_m3_m3m4(float m1[3][3], float m3_[4][4], float m2_[3][3])
+void mul_m3_m3m4(float m1[3][3], const float m3_[4][4], const float m2_[3][3])
{
float m2[3][3], m3[4][4];
/* copy so it works when m1 is the same pointer as m2 or m3 */
+ /* TODO: avoid copying when matrices are different */
copy_m3_m3(m2, m2_);
copy_m4_m4(m3, m3_);
@@ -272,11 +316,12 @@ void mul_m3_m3m4(float m1[3][3], float m3_[4][4], float m2_[3][3])
m1[2][2] = m2[2][0] * m3[0][2] + m2[2][1] * m3[1][2] + m2[2][2] * m3[2][2];
}
-void mul_m4_m3m4(float m1[4][4], float m3_[3][3], float m2_[4][4])
+void mul_m4_m3m4(float m1[4][4], const float m3_[3][3], const float m2_[4][4])
{
float m2[4][4], m3[3][3];
/* copy so it works when m1 is the same pointer as m2 or m3 */
+ /* TODO: avoid copying when matrices are different */
copy_m4_m4(m2, m2_);
copy_m3_m3(m3, m3_);
@@ -296,20 +341,20 @@ void mul_m4_m3m4(float m1[4][4], float m3_[3][3], float m2_[4][4])
* \{ */
void _va_mul_m3_series_3(
float r[3][3],
- float m1[3][3], float m2[3][3])
+ const float m1[3][3], const float m2[3][3])
{
mul_m3_m3m3(r, m1, m2);
}
void _va_mul_m3_series_4(
float r[3][3],
- float m1[3][3], float m2[3][3], float m3[3][3])
+ const float m1[3][3], const float m2[3][3], const float m3[3][3])
{
mul_m3_m3m3(r, m1, m2);
mul_m3_m3m3(r, r, m3);
}
void _va_mul_m3_series_5(
float r[3][3],
- float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3])
+ const float m1[3][3], const float m2[3][3], const float m3[3][3], const float m4[3][3])
{
mul_m3_m3m3(r, m1, m2);
mul_m3_m3m3(r, r, m3);
@@ -317,8 +362,8 @@ void _va_mul_m3_series_5(
}
void _va_mul_m3_series_6(
float r[3][3],
- float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3],
- float m5[3][3])
+ const float m1[3][3], const float m2[3][3], const float m3[3][3], const float m4[3][3],
+ const float m5[3][3])
{
mul_m3_m3m3(r, m1, m2);
mul_m3_m3m3(r, r, m3);
@@ -327,8 +372,8 @@ void _va_mul_m3_series_6(
}
void _va_mul_m3_series_7(
float r[3][3],
- float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3],
- float m5[3][3], float m6[3][3])
+ const float m1[3][3], const float m2[3][3], const float m3[3][3], const float m4[3][3],
+ const float m5[3][3], const float m6[3][3])
{
mul_m3_m3m3(r, m1, m2);
mul_m3_m3m3(r, r, m3);
@@ -338,8 +383,8 @@ void _va_mul_m3_series_7(
}
void _va_mul_m3_series_8(
float r[3][3],
- float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3],
- float m5[3][3], float m6[3][3], float m7[3][3])
+ const float m1[3][3], const float m2[3][3], const float m3[3][3], const float m4[3][3],
+ const float m5[3][3], const float m6[3][3], const float m7[3][3])
{
mul_m3_m3m3(r, m1, m2);
mul_m3_m3m3(r, r, m3);
@@ -350,8 +395,8 @@ void _va_mul_m3_series_8(
}
void _va_mul_m3_series_9(
float r[3][3],
- float m1[3][3], float m2[3][3], float m3[3][3], float m4[3][3],
- float m5[3][3], float m6[3][3], float m7[3][3], float m8[3][3])
+ const float m1[3][3], const float m2[3][3], const float m3[3][3], const float m4[3][3],
+ const float m5[3][3], const float m6[3][3], const float m7[3][3], const float m8[3][3])
{
mul_m3_m3m3(r, m1, m2);
mul_m3_m3m3(r, r, m3);
@@ -367,20 +412,20 @@ void _va_mul_m3_series_9(
* \{ */
void _va_mul_m4_series_3(
float r[4][4],
- float m1[4][4], float m2[4][4])
+ const float m1[4][4], const float m2[4][4])
{
mul_m4_m4m4(r, m1, m2);
}
void _va_mul_m4_series_4(
float r[4][4],
- float m1[4][4], float m2[4][4], float m3[4][4])
+ const float m1[4][4], const float m2[4][4], const float m3[4][4])
{
mul_m4_m4m4(r, m1, m2);
mul_m4_m4m4(r, r, m3);
}
void _va_mul_m4_series_5(
float r[4][4],
- float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4])
+ const float m1[4][4], const float m2[4][4], const float m3[4][4], const float m4[4][4])
{
mul_m4_m4m4(r, m1, m2);
mul_m4_m4m4(r, r, m3);
@@ -388,8 +433,8 @@ void _va_mul_m4_series_5(
}
void _va_mul_m4_series_6(
float r[4][4],
- float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4],
- float m5[4][4])
+ const float m1[4][4], const float m2[4][4], const float m3[4][4], const float m4[4][4],
+ const float m5[4][4])
{
mul_m4_m4m4(r, m1, m2);
mul_m4_m4m4(r, r, m3);
@@ -398,8 +443,8 @@ void _va_mul_m4_series_6(
}
void _va_mul_m4_series_7(
float r[4][4],
- float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4],
- float m5[4][4], float m6[4][4])
+ const float m1[4][4], const float m2[4][4], const float m3[4][4], const float m4[4][4],
+ const float m5[4][4], const float m6[4][4])
{
mul_m4_m4m4(r, m1, m2);
mul_m4_m4m4(r, r, m3);
@@ -409,8 +454,8 @@ void _va_mul_m4_series_7(
}
void _va_mul_m4_series_8(
float r[4][4],
- float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4],
- float m5[4][4], float m6[4][4], float m7[4][4])
+ const float m1[4][4], const float m2[4][4], const float m3[4][4], const float m4[4][4],
+ const float m5[4][4], const float m6[4][4], const float m7[4][4])
{
mul_m4_m4m4(r, m1, m2);
mul_m4_m4m4(r, r, m3);
@@ -421,8 +466,8 @@ void _va_mul_m4_series_8(
}
void _va_mul_m4_series_9(
float r[4][4],
- float m1[4][4], float m2[4][4], float m3[4][4], float m4[4][4],
- float m5[4][4], float m6[4][4], float m7[4][4], float m8[4][4])
+ const float m1[4][4], const float m2[4][4], const float m3[4][4], const float m4[4][4],
+ const float m5[4][4], const float m6[4][4], const float m7[4][4], const float m8[4][4])
{
mul_m4_m4m4(r, m1, m2);
mul_m4_m4m4(r, r, m3);
@@ -434,7 +479,7 @@ void _va_mul_m4_series_9(
}
/** \} */
-void mul_v2_m3v2(float r[2], float m[3][3], float v[2])
+void mul_v2_m3v2(float r[2], const float m[3][3], const float v[2])
{
float temp[3], warped[3];
@@ -447,12 +492,12 @@ void mul_v2_m3v2(float r[2], float m[3][3], float v[2])
r[1] = warped[1] / warped[2];
}
-void mul_m3_v2(float m[3][3], float r[2])
+void mul_m3_v2(const float m[3][3], float r[2])
{
mul_v2_m3v2(r, m, r);
}
-void mul_m4_v3(float mat[4][4], float vec[3])
+void mul_m4_v3(const float mat[4][4], float vec[3])
{
const float x = vec[0];
const float y = vec[1];
@@ -462,7 +507,7 @@ void mul_m4_v3(float mat[4][4], float vec[3])
vec[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2];
}
-void mul_v3_m4v3(float r[3], float mat[4][4], const float vec[3])
+void mul_v3_m4v3(float r[3], const float mat[4][4], const float vec[3])
{
const float x = vec[0];
const float y = vec[1];
@@ -472,7 +517,7 @@ void mul_v3_m4v3(float r[3], float mat[4][4], const float vec[3])
r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2] + mat[3][2];
}
-void mul_v2_m4v3(float r[2], float mat[4][4], const float vec[3])
+void mul_v2_m4v3(float r[2], const float mat[4][4], const float vec[3])
{
const float x = vec[0];
@@ -480,7 +525,7 @@ void mul_v2_m4v3(float r[2], float mat[4][4], const float vec[3])
r[1] = x * mat[0][1] + vec[1] * mat[1][1] + mat[2][1] * vec[2] + mat[3][1];
}
-void mul_v2_m2v2(float r[2], float mat[2][2], const float vec[2])
+void mul_v2_m2v2(float r[2], const float mat[2][2], const float vec[2])
{
const float x = vec[0];
@@ -488,13 +533,13 @@ void mul_v2_m2v2(float r[2], float mat[2][2], const float vec[2])
r[1] = mat[0][1] * x + mat[1][1] * vec[1];
}
-void mul_m2v2(float mat[2][2], float vec[2])
+void mul_m2v2(const float mat[2][2], float vec[2])
{
mul_v2_m2v2(vec, mat, vec);
}
/* same as mul_m4_v3() but doesnt apply translation component */
-void mul_mat3_m4_v3(float mat[4][4], float vec[3])
+void mul_mat3_m4_v3(const float mat[4][4], float vec[3])
{
const float x = vec[0];
const float y = vec[1];
@@ -504,7 +549,7 @@ void mul_mat3_m4_v3(float mat[4][4], float vec[3])
vec[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2];
}
-void mul_v3_mat3_m4v3(float r[3], float mat[4][4], const float vec[3])
+void mul_v3_mat3_m4v3(float r[3], const float mat[4][4], const float vec[3])
{
const float x = vec[0];
const float y = vec[1];
@@ -514,7 +559,7 @@ void mul_v3_mat3_m4v3(float r[3], float mat[4][4], const float vec[3])
r[2] = x * mat[0][2] + y * mat[1][2] + mat[2][2] * vec[2];
}
-void mul_project_m4_v3(float mat[4][4], float vec[3])
+void mul_project_m4_v3(const float mat[4][4], float vec[3])
{
/* absolute value to not flip the frustum upside down behind the camera */
const float w = fabsf(mul_project_m4_v3_zfac(mat, vec));
@@ -525,7 +570,7 @@ void mul_project_m4_v3(float mat[4][4], float vec[3])
vec[2] /= w;
}
-void mul_v3_project_m4_v3(float r[3], float mat[4][4], const float vec[3])
+void mul_v3_project_m4_v3(float r[3], const float mat[4][4], const float vec[3])
{
const float w = fabsf(mul_project_m4_v3_zfac(mat, vec));
mul_v3_m4v3(r, mat, vec);
@@ -535,7 +580,7 @@ void mul_v3_project_m4_v3(float r[3], float mat[4][4], const float vec[3])
r[2] /= w;
}
-void mul_v2_project_m4_v3(float r[2], float mat[4][4], const float vec[3])
+void mul_v2_project_m4_v3(float r[2], const float mat[4][4], const float vec[3])
{
const float w = fabsf(mul_project_m4_v3_zfac(mat, vec));
mul_v2_m4v3(r, mat, vec);
@@ -544,7 +589,7 @@ void mul_v2_project_m4_v3(float r[2], float mat[4][4], const float vec[3])
r[1] /= w;
}
-void mul_v4_m4v4(float r[4], float mat[4][4], const float v[4])
+void mul_v4_m4v4(float r[4], const float mat[4][4], const float v[4])
{
const float x = v[0];
const float y = v[1];
@@ -556,12 +601,12 @@ void mul_v4_m4v4(float r[4], float mat[4][4], const float v[4])
r[3] = x * mat[0][3] + y * mat[1][3] + z * mat[2][3] + mat[3][3] * v[3];
}
-void mul_m4_v4(float mat[4][4], float r[4])
+void mul_m4_v4(const float mat[4][4], float r[4])
{
mul_v4_m4v4(r, mat, r);
}
-void mul_v4d_m4v4d(double r[4], float mat[4][4], double v[4])
+void mul_v4d_m4v4d(double r[4], const float mat[4][4], const double v[4])
{
const double x = v[0];
const double y = v[1];
@@ -573,12 +618,21 @@ void mul_v4d_m4v4d(double r[4], float mat[4][4], double v[4])
r[3] = x * (double)mat[0][3] + y * (double)mat[1][3] + z * (double)mat[2][3] + (double)mat[3][3] * v[3];
}
-void mul_m4_v4d(float mat[4][4], double r[4])
+void mul_m4_v4d(const float mat[4][4], double r[4])
{
mul_v4d_m4v4d(r, mat, r);
}
-void mul_v3_m3v3(float r[3], float M[3][3], const float a[3])
+void mul_v4_m4v3(float r[4], const float M[4][4], const float v[3])
+{
+ /* v has implicit w = 1.0f */
+ r[0] = v[0] * M[0][0] + v[1] * M[1][0] + M[2][0] * v[2] + M[3][0];
+ r[1] = v[0] * M[0][1] + v[1] * M[1][1] + M[2][1] * v[2] + M[3][1];
+ r[2] = v[0] * M[0][2] + v[1] * M[1][2] + M[2][2] * v[2] + M[3][2];
+ r[3] = v[0] * M[0][3] + v[1] * M[1][3] + M[2][3] * v[2] + M[3][3];
+}
+
+void mul_v3_m3v3(float r[3], const float M[3][3], const float a[3])
{
BLI_assert(r != a);
@@ -587,7 +641,7 @@ void mul_v3_m3v3(float r[3], float M[3][3], const float a[3])
r[2] = M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
}
-void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3])
+void mul_v3_m3v3_db(double r[3], const double M[3][3], const double a[3])
{
BLI_assert(r != a);
@@ -596,7 +650,7 @@ void mul_v3_m3v3_db(double r[3], double M[3][3], const double a[3])
r[2] = M[0][2] * a[0] + M[1][2] * a[1] + M[2][2] * a[2];
}
-void mul_v2_m3v3(float r[2], float M[3][3], const float a[3])
+void mul_v2_m3v3(float r[2], const float M[3][3], const float a[3])
{
BLI_assert(r != a);
@@ -604,17 +658,17 @@ void mul_v2_m3v3(float r[2], float M[3][3], const float a[3])
r[1] = M[0][1] * a[0] + M[1][1] * a[1] + M[2][1] * a[2];
}
-void mul_m3_v3(float M[3][3], float r[3])
+void mul_m3_v3(const float M[3][3], float r[3])
{
mul_v3_m3v3(r, M, (const float[3]){UNPACK3(r)});
}
-void mul_m3_v3_db(double M[3][3], double r[3])
+void mul_m3_v3_db(const double M[3][3], double r[3])
{
mul_v3_m3v3_db(r, M, (const double[3]){UNPACK3(r)});
}
-void mul_transposed_m3_v3(float mat[3][3], float vec[3])
+void mul_transposed_m3_v3(const float mat[3][3], float vec[3])
{
const float x = vec[0];
const float y = vec[1];
@@ -624,7 +678,7 @@ void mul_transposed_m3_v3(float mat[3][3], float vec[3])
vec[2] = x * mat[2][0] + y * mat[2][1] + mat[2][2] * vec[2];
}
-void mul_transposed_mat3_m4_v3(float mat[4][4], float vec[3])
+void mul_transposed_mat3_m4_v3(const float mat[4][4], float vec[3])
{
const float x = vec[0];
const float y = vec[1];
@@ -688,7 +742,7 @@ void negate_m4(float m[4][4])
m[i][j] *= -1.0f;
}
-void mul_m3_v3_double(float mat[3][3], double vec[3])
+void mul_m3_v3_double(const float mat[3][3], double vec[3])
{
const double x = vec[0];
const double y = vec[1];
@@ -698,7 +752,7 @@ void mul_m3_v3_double(float mat[3][3], double vec[3])
vec[2] = x * (double)mat[0][2] + y * (double)mat[1][2] + (double)mat[2][2] * vec[2];
}
-void add_m3_m3m3(float m1[3][3], float m2[3][3], float m3[3][3])
+void add_m3_m3m3(float m1[3][3], const float m2[3][3], const float m3[3][3])
{
int i, j;
@@ -707,7 +761,7 @@ void add_m3_m3m3(float m1[3][3], float m2[3][3], float m3[3][3])
m1[i][j] = m2[i][j] + m3[i][j];
}
-void add_m4_m4m4(float m1[4][4], float m2[4][4], float m3[4][4])
+void add_m4_m4m4(float m1[4][4], const float m2[4][4], const float m3[4][4])
{
int i, j;
@@ -716,7 +770,7 @@ void add_m4_m4m4(float m1[4][4], float m2[4][4], float m3[4][4])
m1[i][j] = m2[i][j] + m3[i][j];
}
-void sub_m3_m3m3(float m1[3][3], float m2[3][3], float m3[3][3])
+void sub_m3_m3m3(float m1[3][3], const float m2[3][3], const float m3[3][3])
{
int i, j;
@@ -725,7 +779,7 @@ void sub_m3_m3m3(float m1[3][3], float m2[3][3], float m3[3][3])
m1[i][j] = m2[i][j] - m3[i][j];
}
-void sub_m4_m4m4(float m1[4][4], float m2[4][4], float m3[4][4])
+void sub_m4_m4m4(float m1[4][4], const float m2[4][4], const float m3[4][4])
{
int i, j;
@@ -734,7 +788,7 @@ void sub_m4_m4m4(float m1[4][4], float m2[4][4], float m3[4][4])
m1[i][j] = m2[i][j] - m3[i][j];
}
-float determinant_m3_array(float m[3][3])
+float determinant_m3_array(const float m[3][3])
{
return (m[0][0] * (m[1][1] * m[2][2] - m[1][2] * m[2][1]) -
m[1][0] * (m[0][1] * m[2][2] - m[0][2] * m[2][1]) +
@@ -750,7 +804,7 @@ bool invert_m3_ex(float m[3][3], const float epsilon)
return success;
}
-bool invert_m3_m3_ex(float m1[3][3], float m2[3][3], const float epsilon)
+bool invert_m3_m3_ex(float m1[3][3], const float m2[3][3], const float epsilon)
{
float det;
int a, b;
@@ -786,7 +840,7 @@ bool invert_m3(float m[3][3])
return success;
}
-bool invert_m3_m3(float m1[3][3], float m2[3][3])
+bool invert_m3_m3(float m1[3][3], const float m2[3][3])
{
float det;
int a, b;
@@ -830,7 +884,7 @@ bool invert_m4(float m[4][4])
* Mark Segal - 1992
*/
-bool invert_m4_m4(float inverse[4][4], float mat[4][4])
+bool invert_m4_m4(float inverse[4][4], const float mat[4][4])
{
int i, j, k;
double temp;
@@ -908,7 +962,7 @@ void transpose_m3(float mat[3][3])
mat[2][1] = t;
}
-void transpose_m3_m3(float rmat[3][3], float mat[3][3])
+void transpose_m3_m3(float rmat[3][3], const float mat[3][3])
{
BLI_assert(rmat != mat);
@@ -924,7 +978,7 @@ void transpose_m3_m3(float rmat[3][3], float mat[3][3])
}
/* seems obscure but in-fact a common operation */
-void transpose_m3_m4(float rmat[3][3], float mat[4][4])
+void transpose_m3_m4(float rmat[3][3], const float mat[4][4])
{
BLI_assert(&rmat[0][0] != &mat[0][0]);
@@ -965,7 +1019,7 @@ void transpose_m4(float mat[4][4])
mat[3][2] = t;
}
-void transpose_m4_m4(float rmat[4][4], float mat[4][4])
+void transpose_m4_m4(float rmat[4][4], const float mat[4][4])
{
BLI_assert(rmat != mat);
@@ -987,7 +1041,8 @@ void transpose_m4_m4(float rmat[4][4], float mat[4][4])
rmat[3][3] = mat[3][3];
}
-int compare_m4m4(float mat1[4][4], float mat2[4][4], float limit)
+/* TODO: return bool */
+int compare_m4m4(const float mat1[4][4], const float mat2[4][4], float limit)
{
if (compare_v4v4(mat1[0], mat2[0], limit))
if (compare_v4v4(mat1[1], mat2[1], limit))
@@ -1165,7 +1220,7 @@ void orthogonalize_m4(float mat[4][4], int axis)
mul_v3_fl(mat[2], size[2]);
}
-bool is_orthogonal_m3(float m[3][3])
+bool is_orthogonal_m3(const float m[3][3])
{
int i, j;
@@ -1179,7 +1234,7 @@ bool is_orthogonal_m3(float m[3][3])
return true;
}
-bool is_orthogonal_m4(float m[4][4])
+bool is_orthogonal_m4(const float m[4][4])
{
int i, j;
@@ -1194,7 +1249,7 @@ bool is_orthogonal_m4(float m[4][4])
return true;
}
-bool is_orthonormal_m3(float m[3][3])
+bool is_orthonormal_m3(const float m[3][3])
{
if (is_orthogonal_m3(m)) {
int i;
@@ -1209,7 +1264,7 @@ bool is_orthonormal_m3(float m[3][3])
return false;
}
-bool is_orthonormal_m4(float m[4][4])
+bool is_orthonormal_m4(const float m[4][4])
{
if (is_orthogonal_m4(m)) {
int i;
@@ -1224,7 +1279,7 @@ bool is_orthonormal_m4(float m[4][4])
return false;
}
-bool is_uniform_scaled_m3(float m[3][3])
+bool is_uniform_scaled_m3(const float m[3][3])
{
const float eps = 1e-7f;
float t[3][3];
@@ -1252,7 +1307,7 @@ bool is_uniform_scaled_m3(float m[3][3])
return false;
}
-bool is_uniform_scaled_m4(float m[4][4])
+bool is_uniform_scaled_m4(const float m[4][4])
{
float t[3][3];
copy_m3_m4(t, m);
@@ -1274,14 +1329,14 @@ void normalize_m3(float mat[3][3])
}
}
-void normalize_m3_m3_ex(float rmat[3][3], float mat[3][3], float r_scale[3])
+void normalize_m3_m3_ex(float rmat[3][3], const float mat[3][3], float r_scale[3])
{
int i;
for (i = 0; i < 3; i++) {
r_scale[i] = normalize_v3_v3(rmat[i], mat[i]);
}
}
-void normalize_m3_m3(float rmat[3][3], float mat[3][3])
+void normalize_m3_m3(float rmat[3][3], const float mat[3][3])
{
int i;
for (i = 0; i < 3; i++) {
@@ -1310,7 +1365,7 @@ void normalize_m4(float mat[4][4])
}
}
-void normalize_m4_m4_ex(float rmat[4][4], float mat[4][4], float r_scale[3])
+void normalize_m4_m4_ex(float rmat[4][4], const float mat[4][4], float r_scale[3])
{
int i;
for (i = 0; i < 3; i++) {
@@ -1319,7 +1374,7 @@ void normalize_m4_m4_ex(float rmat[4][4], float mat[4][4], float r_scale[3])
}
copy_v4_v4(rmat[3], mat[3]);
}
-void normalize_m4_m4(float rmat[4][4], float mat[4][4])
+void normalize_m4_m4(float rmat[4][4], const float mat[4][4])
{
int i;
for (i = 0; i < 3; i++) {
@@ -1329,7 +1384,7 @@ void normalize_m4_m4(float rmat[4][4], float mat[4][4])
copy_v4_v4(rmat[3], mat[3]);
}
-void adjoint_m2_m2(float m1[2][2], float m[2][2])
+void adjoint_m2_m2(float m1[2][2], const float m[2][2])
{
BLI_assert(m1 != m);
m1[0][0] = m[1][1];
@@ -1338,7 +1393,7 @@ void adjoint_m2_m2(float m1[2][2], float m[2][2])
m1[1][1] = m[0][0];
}
-void adjoint_m3_m3(float m1[3][3], float m[3][3])
+void adjoint_m3_m3(float m1[3][3], const float m[3][3])
{
BLI_assert(m1 != m);
m1[0][0] = m[1][1] * m[2][2] - m[1][2] * m[2][1];
@@ -1354,7 +1409,7 @@ void adjoint_m3_m3(float m1[3][3], float m[3][3])
m1[2][2] = m[0][0] * m[1][1] - m[0][1] * m[1][0];
}
-void adjoint_m4_m4(float out[4][4], float in[4][4]) /* out = ADJ(in) */
+void adjoint_m4_m4(float out[4][4], const float in[4][4]) /* out = ADJ(in) */
{
float a1, a2, a3, a4, b1, b2, b3, b4;
float c1, c2, c3, c4, d1, d2, d3, d4;
@@ -1420,7 +1475,7 @@ float determinant_m3(float a1, float a2, float a3,
return ans;
}
-float determinant_m4(float m[4][4])
+float determinant_m4(const float m[4][4])
{
float ans;
float a1, a2, a3, a4, b1, b2, b3, b4, c1, c2, c3, c4, d1, d2, d3, d4;
@@ -1488,14 +1543,14 @@ void size_to_mat4(float mat[4][4], const float size[3])
mat[3][3] = 1.0f;
}
-void mat3_to_size(float size[3], float mat[3][3])
+void mat3_to_size(float size[3], const float mat[3][3])
{
size[0] = len_v3(mat[0]);
size[1] = len_v3(mat[1]);
size[2] = len_v3(mat[2]);
}
-void mat4_to_size(float size[3], float mat[4][4])
+void mat4_to_size(float size[3], const float mat[4][4])
{
size[0] = len_v3(mat[0]);
size[1] = len_v3(mat[1]);
@@ -1505,7 +1560,7 @@ void mat4_to_size(float size[3], float mat[4][4])
/* this gets the average scale of a matrix, only use when your scaling
* data that has no idea of scale axis, examples are bone-envelope-radius
* and curve radius */
-float mat3_to_scale(float mat[3][3])
+float mat3_to_scale(const float mat[3][3])
{
/* unit length vector */
float unit_vec[3];
@@ -1514,7 +1569,7 @@ float mat3_to_scale(float mat[3][3])
return len_v3(unit_vec);
}
-float mat4_to_scale(float mat[4][4])
+float mat4_to_scale(const float mat[4][4])
{
/* unit length vector */
float unit_vec[3];
@@ -1524,7 +1579,7 @@ float mat4_to_scale(float mat[4][4])
}
/** Return 2D scale (in XY plane) of given mat4. */
-float mat4_to_xy_scale(float M[4][4])
+float mat4_to_xy_scale(const float M[4][4])
{
/* unit length vector in xy plane */
float unit_vec[3] = {(float)M_SQRT1_2, (float)M_SQRT1_2, 0.0f};
@@ -1532,7 +1587,7 @@ float mat4_to_xy_scale(float M[4][4])
return len_v3(unit_vec);
}
-void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3])
+void mat3_to_rot_size(float rot[3][3], float size[3], const float mat3[3][3])
{
/* keep rot as a 3x3 matrix, the caller can convert into a quat or euler */
size[0] = normalize_v3_v3(rot[0], mat3[0]);
@@ -1544,7 +1599,7 @@ void mat3_to_rot_size(float rot[3][3], float size[3], float mat3[3][3])
}
}
-void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wmat[4][4])
+void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], const float wmat[4][4])
{
float mat3[3][3]; /* wmat -> 3x3 */
@@ -1555,7 +1610,7 @@ void mat4_to_loc_rot_size(float loc[3], float rot[3][3], float size[3], float wm
copy_v3_v3(loc, wmat[3]);
}
-void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4])
+void mat4_to_loc_quat(float loc[3], float quat[4], const float wmat[4][4])
{
float mat3[3][3];
float mat3_n[3][3]; /* normalized mat3 */
@@ -1573,7 +1628,7 @@ void mat4_to_loc_quat(float loc[3], float quat[4], float wmat[4][4])
copy_v3_v3(loc, wmat[3]);
}
-void mat4_decompose(float loc[3], float quat[4], float size[3], float wmat[4][4])
+void mat4_decompose(float loc[3], float quat[4], float size[3], const float wmat[4][4])
{
float rot[3][3];
mat4_to_loc_rot_size(loc, rot, size, wmat);
@@ -1590,7 +1645,7 @@ void mat4_decompose(float loc[3], float quat[4], float size[3], float wmat[4][4]
* See https://en.wikipedia.org/wiki/Polar_decomposition for more.
*/
#ifndef MATH_STANDALONE
-void mat3_polar_decompose(float mat3[3][3], float r_U[3][3], float r_P[3][3])
+void mat3_polar_decompose(const float mat3[3][3], float r_U[3][3], float r_P[3][3])
{
/* From svd decomposition (M = WSV*), we have:
* U = WV*
@@ -1701,7 +1756,7 @@ void transform_pivot_set_m4(float mat[4][4], const float pivot[3])
mul_m4_m4m4(mat, mat, tmat);
}
-void blend_m3_m3m3(float out[3][3], float dst[3][3], float src[3][3], const float srcweight)
+void blend_m3_m3m3(float out[3][3], const float dst[3][3], const float src[3][3], const float srcweight)
{
float srot[3][3], drot[3][3];
float squat[4], dquat[4], fquat[4];
@@ -1724,7 +1779,7 @@ void blend_m3_m3m3(float out[3][3], float dst[3][3], float src[3][3], const floa
mul_m3_m3m3(out, rmat, smat);
}
-void blend_m4_m4m4(float out[4][4], float dst[4][4], float src[4][4], const float srcweight)
+void blend_m4_m4m4(float out[4][4], const float dst[4][4], const float src[4][4], const float srcweight)
{
float sloc[3], dloc[3], floc[3];
float srot[3][3], drot[3][3];
@@ -1762,7 +1817,7 @@ void blend_m4_m4m4(float out[4][4], float dst[4][4], float src[4][4], const floa
* \param B: Input matrix which is totally effective with `t = 1.0`.
* \param t: Interpolation factor.
*/
-void interp_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t)
+void interp_m3_m3m3(float R[3][3], const float A[3][3], const float B[3][3], const float t)
{
/* 'Rotation' component ('U' part of polar decomposition, the closest orthogonal matrix to M3 rot/scale
* transformation matrix), spherically interpolated. */
@@ -1797,7 +1852,7 @@ void interp_m3_m3m3(float R[3][3], float A[3][3], float B[3][3], const float t)
* \param B: Input matrix which is totally effective with `t = 1.0`.
* \param t: Interpolation factor.
*/
-void interp_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t)
+void interp_m4_m4m4(float R[4][4], const float A[4][4], const float B[4][4], const float t)
{
float A3[3][3], B3[3][3], R3[3][3];
@@ -1818,27 +1873,27 @@ void interp_m4_m4m4(float R[4][4], float A[4][4], float B[4][4], const float t)
}
#endif /* MATH_STANDALONE */
-bool is_negative_m3(float mat[3][3])
+bool is_negative_m3(const float mat[3][3])
{
float vec[3];
cross_v3_v3v3(vec, mat[0], mat[1]);
return (dot_v3v3(vec, mat[2]) < 0.0f);
}
-bool is_negative_m4(float mat[4][4])
+bool is_negative_m4(const float mat[4][4])
{
float vec[3];
cross_v3_v3v3(vec, mat[0], mat[1]);
return (dot_v3v3(vec, mat[2]) < 0.0f);
}
-bool is_zero_m3(float mat[3][3])
+bool is_zero_m3(const float mat[3][3])
{
return (is_zero_v3(mat[0]) &&
is_zero_v3(mat[1]) &&
is_zero_v3(mat[2]));
}
-bool is_zero_m4(float mat[4][4])
+bool is_zero_m4(const float mat[4][4])
{
return (is_zero_v4(mat[0]) &&
is_zero_v4(mat[1]) &&
@@ -1846,14 +1901,14 @@ bool is_zero_m4(float mat[4][4])
is_zero_v4(mat[3]));
}
-bool equals_m3m3(float mat1[3][3], float mat2[3][3])
+bool equals_m3m3(const float mat1[3][3], const float mat2[3][3])
{
return (equals_v3v3(mat1[0], mat2[0]) &&
equals_v3v3(mat1[1], mat2[1]) &&
equals_v3v3(mat1[2], mat2[2]));
}
-bool equals_m4m4(float mat1[4][4], float mat2[4][4])
+bool equals_m4m4(const float mat1[4][4], const float mat2[4][4])
{
return (equals_v4v4(mat1[0], mat2[0]) &&
equals_v4v4(mat1[1], mat2[1]) &&
@@ -1944,7 +1999,7 @@ void loc_axisangle_size_to_mat4(float mat[4][4], const float loc[3], const float
/*********************************** Other ***********************************/
-void print_m3(const char *str, float m[3][3])
+void print_m3(const char *str, const float m[3][3])
{
printf("%s\n", str);
printf("%f %f %f\n", m[0][0], m[1][0], m[2][0]);
@@ -1953,7 +2008,7 @@ void print_m3(const char *str, float m[3][3])
printf("\n");
}
-void print_m4(const char *str, float m[4][4])
+void print_m4(const char *str, const float m[4][4])
{
printf("%s\n", str);
printf("%f %f %f %f\n", m[0][0], m[1][0], m[2][0], m[3][0]);
@@ -2407,7 +2462,7 @@ void svd_m4(float U[4][4], float s[4], float V[4][4], float A_[4][4])
}
}
-void pseudoinverse_m4_m4(float Ainv[4][4], float A_[4][4], float epsilon)
+void pseudoinverse_m4_m4(float Ainv[4][4], const float A_[4][4], float epsilon)
{
/* compute Moore-Penrose pseudo inverse of matrix, singular values
* below epsilon are ignored for stability (truncated SVD) */
@@ -2428,7 +2483,7 @@ void pseudoinverse_m4_m4(float Ainv[4][4], float A_[4][4], float epsilon)
mul_m4_series(Ainv, U, Wm, V);
}
-void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon)
+void pseudoinverse_m3_m3(float Ainv[3][3], const float A[3][3], float epsilon)
{
/* try regular inverse when possible, otherwise fall back to slow svd */
if (!invert_m3_m3(Ainv, A)) {
@@ -2440,14 +2495,14 @@ void pseudoinverse_m3_m3(float Ainv[3][3], float A[3][3], float epsilon)
}
}
-bool has_zero_axis_m4(float matrix[4][4])
+bool has_zero_axis_m4(const float matrix[4][4])
{
return len_squared_v3(matrix[0]) < FLT_EPSILON ||
len_squared_v3(matrix[1]) < FLT_EPSILON ||
len_squared_v3(matrix[2]) < FLT_EPSILON;
}
-void invert_m4_m4_safe(float Ainv[4][4], float A[4][4])
+void invert_m4_m4_safe(float Ainv[4][4], const float A[4][4])
{
if (!invert_m4_m4(Ainv, A)) {
float Atemp[4][4];
@@ -2495,7 +2550,7 @@ void invert_m4_m4_safe(float Ainv[4][4], float A[4][4])
* this defines a transform matrix TM such that (x', y', z') = TM * (x, y, z)
* where (x', y', z') are the coordinates of P' in target space such that it keeps (X, Y, Z) coordinates in global space.
*/
-void BLI_space_transform_from_matrices(SpaceTransform *data, float local[4][4], float target[4][4])
+void BLI_space_transform_from_matrices(SpaceTransform *data, const float local[4][4], const float target[4][4])
{
float itarget[4][4];
invert_m4_m4(itarget, target);
@@ -2513,7 +2568,7 @@ void BLI_space_transform_from_matrices(SpaceTransform *data, float local[4][4],
* this defines a transform matrix TM such that (X', Y', Z') = TM * (X, Y, Z)
* where (X', Y', Z') are the coordinates of p' in global space such that it keeps (x, y, z) coordinates in target space.
*/
-void BLI_space_transform_global_from_matrices(SpaceTransform *data, float local[4][4], float target[4][4])
+void BLI_space_transform_global_from_matrices(SpaceTransform *data, const float local[4][4], const float target[4][4])
{
float ilocal[4][4];
invert_m4_m4(ilocal, local);
diff --git a/source/blender/blenlib/intern/math_vector_inline.c b/source/blender/blenlib/intern/math_vector_inline.c
index 08687a1ab47..4f658ef015f 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -491,7 +491,7 @@ MINLINE void mul_v2_v2_ccw(float r[2], const float mat[2], const float vec[2])
* return co_4d[3];
* \endcode
*/
-MINLINE float mul_project_m4_v3_zfac(float mat[4][4], const float co[3])
+MINLINE float mul_project_m4_v3_zfac(const float mat[4][4], const float co[3])
{
return (mat[0][3] * co[0]) +
(mat[1][3] * co[1]) +
diff --git a/source/blender/blenlib/intern/rand.c b/source/blender/blenlib/intern/rand.c
index 1a178db1413..700524965f0 100644
--- a/source/blender/blenlib/intern/rand.c
+++ b/source/blender/blenlib/intern/rand.c
@@ -386,6 +386,8 @@ void BLI_halton_1D(unsigned int prime, double offset, int n, double *r)
{
const double invprime = 1.0 / (double)prime;
+ *r = 0.0;
+
for (int s = 0; s < n; s++) {
*r = halton_ex(invprime, &offset);
}
@@ -395,6 +397,8 @@ void BLI_halton_2D(unsigned int prime[2], double offset[2], int n, double *r)
{
const double invprimes[2] = {1.0 / (double)prime[0], 1.0 / (double)prime[1]};
+ r[0] = r[1] = 0.0;
+
for (int s = 0; s < n; s++) {
for (int i = 0; i < 2; i++) {
r[i] = halton_ex(invprimes[i], &offset[i]);
@@ -406,6 +410,8 @@ void BLI_halton_3D(unsigned int prime[3], double offset[3], int n, double *r)
{
const double invprimes[3] = {1.0 / (double)prime[0], 1.0 / (double)prime[1], 1.0 / (double)prime[2]};
+ r[0] = r[1] = r[2] = 0.0;
+
for (int s = 0; s < n; s++) {
for (int i = 0; i < 3; i++) {
r[i] = halton_ex(invprimes[i], &offset[i]);
diff --git a/source/blender/blenlib/intern/scanfill_utils.c b/source/blender/blenlib/intern/scanfill_utils.c
index 3b6ab99ae86..ef1df479f13 100644
--- a/source/blender/blenlib/intern/scanfill_utils.c
+++ b/source/blender/blenlib/intern/scanfill_utils.c
@@ -95,20 +95,6 @@ void BLI_scanfill_obj_dump(ScanFillContext *sf_ctx)
}
#endif
-#if 0
-void BLI_scanfill_view3d_dump(ScanFillContext *sf_ctx)
-{
- ScanFillEdge *eed;
-
- bl_debug_draw_quad_clear();
- bl_debug_color_set(0x0000ff);
-
- for (eed = sf_ctx->filledgebase.first; eed; eed = eed->next) {
- bl_debug_draw_edge_add(eed->v1->co, eed->v2->co);
- }
-}
-#endif
-
static ListBase *edge_isect_ls_ensure(GHash *isect_hash, ScanFillEdge *eed)
{
ListBase *e_ls;
diff --git a/source/blender/blenloader/BLO_readfile.h b/source/blender/blenloader/BLO_readfile.h
index 0b4ff13c7bd..7b31415ddcf 100644
--- a/source/blender/blenloader/BLO_readfile.h
+++ b/source/blender/blenloader/BLO_readfile.h
@@ -39,15 +39,18 @@ extern "C" {
struct BlendThumbnail;
struct bScreen;
struct LinkNode;
+struct ListBase;
struct Main;
struct MemFile;
struct ReportList;
struct Scene;
+struct ViewLayer;
struct UserDef;
struct View3D;
struct bContext;
struct BHead;
struct FileData;
+struct wmWindowManager;
typedef struct BlendHandle BlendHandle;
@@ -64,13 +67,20 @@ typedef struct BlendFileData {
int fileflags;
int globalf;
char filename[1024]; /* 1024 = FILE_MAX */
-
- struct bScreen *curscreen;
+
+ struct bScreen *curscreen; /* TODO think this isn't needed anymore? */
struct Scene *curscene;
-
+ struct ViewLayer *cur_view_layer; /* layer to activate in workspaces when reading without UI */
+
eBlenFileType type;
} BlendFileData;
+typedef struct WorkspaceConfigFileData {
+ struct Main *main; /* has to be freed when done reading file data */
+
+ struct ListBase workspaces;
+} WorkspaceConfigFileData;
+
/* skip reading some data-block types (may want to skip screen data too). */
typedef enum eBLOReadSkip {
@@ -124,8 +134,9 @@ struct ID *BLO_library_link_named_part(struct Main *mainl, BlendHandle **bh, con
struct ID *BLO_library_link_named_part_ex(
struct Main *mainl, BlendHandle **bh,
const short idcode, const char *name, const int flag,
- struct Scene *scene, struct View3D *v3d);
-void BLO_library_link_end(struct Main *mainl, BlendHandle **bh, short flag, struct Scene *scene, struct View3D *v3d);
+ struct Scene *scene, struct ViewLayer *view_layer);
+void BLO_library_link_end(
+ struct Main *mainl, BlendHandle **bh, int flag, struct Scene *scene, struct ViewLayer *view_layer);
void BLO_library_link_copypaste(struct Main *mainl, BlendHandle *bh);
@@ -134,7 +145,9 @@ void *BLO_library_read_struct(struct FileData *fd, struct BHead *bh, const char
BlendFileData *blo_read_blendafterruntime(int file, const char *name, int actualsize, struct ReportList *reports);
/* internal function but we need to expose it */
-void blo_lib_link_screen_restore(struct Main *newmain, struct bScreen *curscreen, struct Scene *curscene);
+void blo_lib_link_restore(
+ struct Main *newmain, struct wmWindowManager *curwm,
+ struct Scene *curscene, struct ViewLayer *cur_render_layer);
typedef void (*BLOExpandDoitCallback) (void *fdhandle, struct Main *mainvar, void *idv);
diff --git a/source/blender/blenloader/CMakeLists.txt b/source/blender/blenloader/CMakeLists.txt
index 420f651ee7f..f42336a2c7a 100644
--- a/source/blender/blenloader/CMakeLists.txt
+++ b/source/blender/blenloader/CMakeLists.txt
@@ -29,6 +29,7 @@ set(INC
../blenkernel
../blenlib
../blentranslation
+ ../depsgraph
../imbuf
../makesdna
../makesrna
@@ -54,6 +55,7 @@ set(SRC
intern/versioning_250.c
intern/versioning_260.c
intern/versioning_270.c
+ intern/versioning_280.c
intern/versioning_defaults.c
intern/versioning_legacy.c
intern/writefile.c
@@ -80,6 +82,10 @@ if(WITH_INTERNATIONAL)
add_definitions(-DWITH_INTERNATIONAL)
endif()
+if(WITH_CLAY_ENGINE)
+ add_definitions(-DWITH_CLAY_ENGINE)
+endif()
+
if(WITH_CODEC_FFMPEG)
add_definitions(-DWITH_FFMPEG)
endif()
diff --git a/source/blender/blenloader/intern/readblenentry.c b/source/blender/blenloader/intern/readblenentry.c
index 73109413271..8d90a11f5d9 100644
--- a/source/blender/blenloader/intern/readblenentry.c
+++ b/source/blender/blenloader/intern/readblenentry.c
@@ -282,7 +282,7 @@ LinkNode *BLO_blendhandle_get_linkable_groups(BlendHandle *bh)
else if (BKE_idcode_is_valid(bhead->code)) {
if (BKE_idcode_is_linkable(bhead->code)) {
const char *str = BKE_idcode_to_name(bhead->code);
-
+
if (BLI_gset_add(gathered, (void *)str)) {
BLI_linklist_prepend(&names, strdup(str));
}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 7d73b3050a6..96e3f4704d9 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -54,15 +54,17 @@
/* allow readfile to use deprecated functionality */
#define DNA_DEPRECATED_ALLOW
+/* Allow using DNA struct members that are marked as private for read/write.
+ * Note: Each header that uses this needs to define its own way of handling
+ * it. There's no generic implementation, direct use does nothing. */
+#define DNA_PRIVATE_READ_WRITE_ALLOW
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_brush_types.h"
#include "DNA_camera_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_cloth_types.h"
-#include "DNA_controller_types.h"
#include "DNA_constraint_types.h"
#include "DNA_dynamicpaint_types.h"
#include "DNA_effect_types.h"
@@ -73,6 +75,7 @@
#include "DNA_ipo_types.h"
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
+#include "DNA_layer_types.h"
#include "DNA_lamp_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_meta_types.h"
@@ -85,12 +88,11 @@
#include "DNA_object_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_particle_types.h"
-#include "DNA_property_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_text_types.h"
#include "DNA_view3d_types.h"
#include "DNA_screen_types.h"
-#include "DNA_sensor_types.h"
#include "DNA_sdna_types.h"
#include "DNA_scene_types.h"
#include "DNA_sequence_types.h"
@@ -99,10 +101,13 @@
#include "DNA_sound_types.h"
#include "DNA_space_types.h"
#include "DNA_vfont_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_world_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_mask_types.h"
+#include "RNA_access.h"
+
#include "MEM_guardedalloc.h"
#include "BLI_endian_switch.h"
@@ -121,13 +126,14 @@
#include "BKE_constraint.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_effect.h"
#include "BKE_fcurve.h"
#include "BKE_global.h" // for G
#include "BKE_group.h"
+#include "BKE_layer.h"
#include "BKE_library.h" // for which_libbase
#include "BKE_library_idmap.h"
+#include "BKE_library_override.h"
#include "BKE_library_query.h"
#include "BKE_idcode.h"
#include "BKE_idprop.h"
@@ -142,13 +148,15 @@
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_report.h"
-#include "BKE_sca.h" // for init_actuator
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
#include "BKE_outliner_treehash.h"
#include "BKE_sound.h"
#include "BKE_colortools.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
#include "NOD_common.h"
#include "NOD_socket.h"
@@ -248,9 +256,11 @@ typedef struct OldNewMap {
/* local prototypes */
static void *read_struct(FileData *fd, BHead *bh, const char *blockname);
static void direct_link_modifiers(FileData *fd, ListBase *lb);
-static void convert_tface_mt(FileData *fd, Main *main);
static BHead *find_bhead_from_code_name(FileData *fd, const short idcode, const char *name);
static BHead *find_bhead_from_idname(FileData *fd, const char *idname);
+static void expand_scene_collection(FileData *fd, Main *mainvar, SceneCollection *sc);
+static SceneCollection *get_scene_collection_active_or_create(
+ struct Scene *scene, struct ViewLayer *view_layer, const int flag);
/* this function ensures that reports are printed,
* in the case of libraray linking errors this is important!
@@ -2230,6 +2240,42 @@ static PreviewImage *direct_link_preview_image(FileData *fd, PreviewImage *old_p
/* ************ READ ID *************** */
+static void lib_link_id(FileData *fd, Main *main)
+{
+ ListBase *lbarray[MAX_LIBARRAY];
+ int base_count, i;
+
+ base_count = set_listbasepointers(main, lbarray);
+
+ for (i = 0; i < base_count; i++) {
+ ListBase *lb = lbarray[i];
+ ID *id;
+
+ for (id = lb->first; id; id = id->next) {
+ if (id->override_static) {
+ id->override_static->reference = newlibadr_us(fd, id->lib, id->override_static->reference);
+ id->override_static->storage = newlibadr_us(fd, id->lib, id->override_static->storage);
+ }
+ }
+ }
+}
+
+static void direct_link_id_override_property_operation_cb(FileData *fd, void *data)
+{
+ IDOverrideStaticPropertyOperation *opop = data;
+
+ opop->subitem_reference_name = newdataadr(fd, opop->subitem_reference_name);
+ opop->subitem_local_name = newdataadr(fd, opop->subitem_local_name);
+}
+
+static void direct_link_id_override_property_cb(FileData *fd, void *data)
+{
+ IDOverrideStaticProperty *op = data;
+
+ op->rna_path = newdataadr(fd, op->rna_path);
+ link_list_ex(fd, &op->operations, direct_link_id_override_property_operation_cb);
+}
+
static void direct_link_id(FileData *fd, ID *id)
{
/*link direct data of ID properties*/
@@ -2243,6 +2289,12 @@ static void direct_link_id(FileData *fd, ID *id)
/* That way datablock reading not going through main read_libblock() function are still in a clear tag state.
* (glowering at certain nodetree fake datablock here...). */
id->tag = 0;
+
+ /* Link direct data of overrides. */
+ if (id->override_static) {
+ id->override_static = newdataadr(fd, id->override_static);
+ link_list_ex(fd, &id->override_static->properties, direct_link_id_override_property_cb);
+ }
}
/* ************ READ CurveMapping *************** */
@@ -2806,6 +2858,89 @@ static void direct_link_cachefile(FileData *fd, CacheFile *cache_file)
direct_link_animdata(fd, cache_file->adt);
}
+/* ************ READ WORKSPACES *************** */
+
+static void lib_link_workspaces(FileData *fd, Main *bmain)
+{
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ ListBase *layouts = BKE_workspace_layouts_get(workspace);
+ ID *id = (ID *)workspace;
+
+ if ((id->tag & LIB_TAG_NEED_LINK) == 0) {
+ continue;
+ }
+ IDP_LibLinkProperty(id->properties, fd);
+ id_us_ensure_real(id);
+
+ for (WorkSpaceDataRelation *relation = workspace->scene_viewlayer_relations.first;
+ relation != NULL;
+ relation = relation->next)
+ {
+ relation->parent = newlibadr(fd, id->lib, relation->parent);
+ /* relation->value is set in direct_link_workspace_link_scene_data */
+ }
+
+ for (WorkSpaceLayout *layout = layouts->first, *layout_next; layout; layout = layout_next) {
+ bScreen *screen = newlibadr(fd, id->lib, BKE_workspace_layout_screen_get(layout));
+
+ layout_next = layout->next;
+ if (screen) {
+ BKE_workspace_layout_screen_set(layout, screen);
+
+ if (ID_IS_LINKED(id)) {
+ screen->winid = 0;
+ if (screen->temp) {
+ /* delete temp layouts when appending */
+ BKE_workspace_layout_remove(bmain, workspace, layout);
+ }
+ }
+ }
+ }
+
+ id->tag &= ~LIB_TAG_NEED_LINK;
+ }
+}
+
+static void direct_link_workspace(FileData *fd, WorkSpace *workspace, const Main *main)
+{
+ link_list(fd, BKE_workspace_layouts_get(workspace));
+ link_list(fd, &workspace->hook_layout_relations);
+ link_list(fd, &workspace->scene_viewlayer_relations);
+ link_list(fd, &workspace->owner_ids);
+
+ for (WorkSpaceDataRelation *relation = workspace->hook_layout_relations.first;
+ relation;
+ relation = relation->next)
+ {
+ relation->parent = newglobadr(fd, relation->parent); /* data from window - need to access through global oldnew-map */
+ relation->value = newdataadr(fd, relation->value);
+ }
+
+ if (ID_IS_LINKED(&workspace->id)) {
+ /* Appending workspace so render layer is likely from a different scene. Unset
+ * now, when activating workspace later we set a valid one from current scene. */
+ BKE_workspace_relations_free(&workspace->scene_viewlayer_relations);
+ }
+
+ /* Same issue/fix as in direct_link_workspace_link_scene_data: Can't read workspace data
+ * when reading windows, so have to update windows after/when reading workspaces. */
+ for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) {
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ WorkSpaceLayout *act_layout = newdataadr(fd, BKE_workspace_active_layout_get(win->workspace_hook));
+ if (act_layout) {
+ BKE_workspace_active_layout_set(win->workspace_hook, act_layout);
+ }
+ }
+ }
+}
+
+static void lib_link_workspace_instance_hook(FileData *fd, WorkSpaceInstanceHook *hook, ID *id)
+{
+ WorkSpace *workspace = BKE_workspace_active_get(hook);
+ BKE_workspace_active_set(hook, newlibadr(fd, id->lib, workspace));
+}
+
+
/* ************ READ MOTION PATHS *************** */
/* direct data for cache */
@@ -3256,6 +3391,11 @@ static void lib_link_constraints(FileData *fd, ID *id, ListBase *conlist)
}
/* own ipo, all constraints have it */
con->ipo = newlibadr_us(fd, id->lib, con->ipo); // XXX deprecated - old animation system
+
+ /* If linking from a library, clear 'local' static override flag. */
+ if (id->lib != NULL) {
+ con->flag &= ~CONSTRAINT_STATICOVERRIDE_LOCAL;
+ }
}
/* relink all ID-blocks used by the constraints */
@@ -3373,7 +3513,7 @@ static void lib_link_pose(FileData *fd, Main *bmain, Object *ob, bPose *pose)
if (rebuild) {
- DAG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update_ex(bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
BKE_pose_tag_recalc(bmain, pose);
}
}
@@ -3425,7 +3565,6 @@ static void direct_link_armature(FileData *fd, bArmature *arm)
link_list(fd, &arm->bonebase);
arm->edbo = NULL;
- arm->sketch = NULL;
arm->adt = newdataadr(fd, arm->adt);
direct_link_animdata(fd, arm->adt);
@@ -3451,6 +3590,11 @@ static void lib_link_camera(FileData *fd, Main *main)
ca->dof_ob = newlibadr(fd, ca->id.lib, ca->dof_ob);
+ for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) {
+ bgpic->ima = newlibadr_us(fd, ca->id.lib, bgpic->ima);
+ bgpic->clip = newlibadr_us(fd, ca->id.lib, bgpic->clip);
+ }
+
ca->id.tag &= ~LIB_TAG_NEED_LINK;
}
}
@@ -3460,6 +3604,12 @@ static void direct_link_camera(FileData *fd, Camera *ca)
{
ca->adt = newdataadr(fd, ca->adt);
direct_link_animdata(fd, ca->adt);
+
+ link_list(fd, &ca->bg_images);
+
+ for (CameraBGImage *bgpic = ca->bg_images.first; bgpic; bgpic = bgpic->next) {
+ bgpic->iuser.ok = 1;
+ }
}
@@ -3472,14 +3622,6 @@ static void lib_link_lamp(FileData *fd, Main *main)
IDP_LibLinkProperty(la->id.properties, fd);
lib_link_animdata(fd, &la->id, la->adt);
- for (int a = 0; a < MAX_MTEX; a++) {
- MTex *mtex = la->mtex[a];
- if (mtex) {
- mtex->tex = newlibadr_us(fd, la->id.lib, mtex->tex);
- mtex->object = newlibadr(fd, la->id.lib, mtex->object);
- }
- }
-
la->ipo = newlibadr_us(fd, la->id.lib, la->ipo); // XXX deprecated - old animation system
if (la->nodetree) {
@@ -3494,15 +3636,9 @@ static void lib_link_lamp(FileData *fd, Main *main)
static void direct_link_lamp(FileData *fd, Lamp *la)
{
- int a;
-
la->adt = newdataadr(fd, la->adt);
direct_link_animdata(fd, la->adt);
- for (a=0; a<MAX_MTEX; a++) {
- la->mtex[a] = newdataadr(fd, la->mtex[a]);
- }
-
la->curfalloff = newdataadr(fd, la->curfalloff);
if (la->curfalloff)
direct_link_curvemapping(fd, la->curfalloff);
@@ -3627,6 +3763,7 @@ static void direct_link_mball(FileData *fd, MetaBall *mb)
mb->editelems = NULL;
/* mb->edit_elems.first= mb->edit_elems.last= NULL;*/
mb->lastelem = NULL;
+ mb->batch_cache = NULL;
}
/* ************ READ WORLD ***************** */
@@ -3640,14 +3777,6 @@ static void lib_link_world(FileData *fd, Main *main)
wrld->ipo = newlibadr_us(fd, wrld->id.lib, wrld->ipo); // XXX deprecated - old animation system
- for (int a = 0; a < MAX_MTEX; a++) {
- MTex *mtex = wrld->mtex[a];
- if (mtex) {
- mtex->tex = newlibadr_us(fd, wrld->id.lib, mtex->tex);
- mtex->object = newlibadr(fd, wrld->id.lib, mtex->object);
- }
- }
-
if (wrld->nodetree) {
lib_link_ntree(fd, &wrld->id, wrld->nodetree);
wrld->nodetree->id.lib = wrld->id.lib;
@@ -3660,15 +3789,9 @@ static void lib_link_world(FileData *fd, Main *main)
static void direct_link_world(FileData *fd, World *wrld)
{
- int a;
-
wrld->adt = newdataadr(fd, wrld->adt);
direct_link_animdata(fd, wrld->adt);
- for (a = 0; a < MAX_MTEX; a++) {
- wrld->mtex[a] = newdataadr(fd, wrld->mtex[a]);
- }
-
wrld->nodetree = newdataadr(fd, wrld->nodetree);
if (wrld->nodetree) {
direct_link_id(fd, &wrld->nodetree->id);
@@ -3780,8 +3903,6 @@ static void direct_link_image(FileData *fd, Image *ima)
}
ima->rr = NULL;
}
-
- ima->repbind = NULL;
/* undo system, try to restore render buffers */
if (fd->imamap) {
@@ -3895,6 +4016,7 @@ static void direct_link_curve(FileData *fd, Curve *cu)
cu->editnurb = NULL;
cu->editfont = NULL;
+ cu->batch_cache = NULL;
for (nu = cu->nurb.first; nu; nu = nu->next) {
nu->bezt = newdataadr(fd, nu->bezt);
@@ -3921,14 +4043,6 @@ static void lib_link_texture(FileData *fd, Main *main)
tex->ima = newlibadr_us(fd, tex->id.lib, tex->ima);
tex->ipo = newlibadr_us(fd, tex->id.lib, tex->ipo); // XXX deprecated - old animation system
- if (tex->env)
- tex->env->object = newlibadr(fd, tex->id.lib, tex->env->object);
- if (tex->pd)
- tex->pd->object = newlibadr(fd, tex->id.lib, tex->pd->object);
- if (tex->vd)
- tex->vd->object = newlibadr(fd, tex->id.lib, tex->vd->object);
- if (tex->ot)
- tex->ot->object = newlibadr(fd, tex->id.lib, tex->ot->object);
if (tex->nodetree) {
lib_link_ntree(fd, &tex->id, tex->nodetree);
@@ -3946,35 +4060,7 @@ static void direct_link_texture(FileData *fd, Tex *tex)
direct_link_animdata(fd, tex->adt);
tex->coba = newdataadr(fd, tex->coba);
- tex->env = newdataadr(fd, tex->env);
- if (tex->env) {
- tex->env->ima = NULL;
- memset(tex->env->cube, 0, 6 * sizeof(void *));
- tex->env->ok= 0;
- }
- tex->pd = newdataadr(fd, tex->pd);
- if (tex->pd) {
- tex->pd->point_tree = NULL;
- tex->pd->coba = newdataadr(fd, tex->pd->coba);
- tex->pd->falloff_curve = newdataadr(fd, tex->pd->falloff_curve);
- if (tex->pd->falloff_curve) {
- direct_link_curvemapping(fd, tex->pd->falloff_curve);
- }
- tex->pd->point_data = NULL; /* runtime data */
- }
-
- tex->vd = newdataadr(fd, tex->vd);
- if (tex->vd) {
- tex->vd->dataset = NULL;
- tex->vd->ok = 0;
- }
- else {
- if (tex->type == TEX_VOXELDATA)
- tex->vd = MEM_callocN(sizeof(VoxelData), "direct_link_texture VoxelData");
- }
-
- tex->ot = newdataadr(fd, tex->ot);
-
+
tex->nodetree = newdataadr(fd, tex->nodetree);
if (tex->nodetree) {
direct_link_id(fd, &tex->nodetree->id);
@@ -3998,15 +4084,6 @@ static void lib_link_material(FileData *fd, Main *main)
lib_link_animdata(fd, &ma->id, ma->adt);
ma->ipo = newlibadr_us(fd, ma->id.lib, ma->ipo); // XXX deprecated - old animation system
- ma->group = newlibadr_us(fd, ma->id.lib, ma->group);
-
- for (int a = 0; a < MAX_MTEX; a++) {
- MTex *mtex = ma->mtex[a];
- if (mtex) {
- mtex->tex = newlibadr_us(fd, ma->id.lib, mtex->tex);
- mtex->object = newlibadr(fd, ma->id.lib, mtex->object);
- }
- }
if (ma->nodetree) {
lib_link_ntree(fd, &ma->id, ma->nodetree);
@@ -4020,18 +4097,10 @@ static void lib_link_material(FileData *fd, Main *main)
static void direct_link_material(FileData *fd, Material *ma)
{
- int a;
-
ma->adt = newdataadr(fd, ma->adt);
direct_link_animdata(fd, ma->adt);
- for (a = 0; a < MAX_MTEX; a++) {
- ma->mtex[a] = newdataadr(fd, ma->mtex[a]);
- }
ma->texpaintslot = NULL;
-
- ma->ramp_col = newdataadr(fd, ma->ramp_col);
- ma->ramp_spec = newdataadr(fd, ma->ramp_spec);
ma->nodetree = newdataadr(fd, ma->nodetree);
if (ma->nodetree) {
@@ -4376,7 +4445,6 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
BLI_listbase_clear(&psys->pathcachebufs);
BLI_listbase_clear(&psys->childcachebufs);
psys->pdd = NULL;
- psys->renderdata = NULL;
if (psys->clmd) {
psys->clmd = newdataadr(fd, psys->clmd);
@@ -4403,55 +4471,14 @@ static void direct_link_particlesystems(FileData *fd, ListBase *particles)
psys->tree = NULL;
psys->bvhtree = NULL;
+
+ psys->batch_cache = NULL;
}
return;
}
/* ************ READ MESH ***************** */
-static void lib_link_mtface(FileData *fd, Mesh *me, MTFace *mtface, int totface)
-{
- MTFace *tf= mtface;
- int i;
-
- /* Add pseudo-references (not fake users!) to images used by texface. A
- * little bogus; it would be better if each mesh consistently added one ref
- * to each image it used. - z0r */
- for (i = 0; i < totface; i++, tf++) {
- tf->tpage = newlibadr_real_us(fd, me->id.lib, tf->tpage);
- }
-}
-
-static void lib_link_customdata_mtface(FileData *fd, Mesh *me, CustomData *fdata, int totface)
-{
- int i;
- for (i = 0; i < fdata->totlayer; i++) {
- CustomDataLayer *layer = &fdata->layers[i];
-
- if (layer->type == CD_MTFACE)
- lib_link_mtface(fd, me, layer->data, totface);
- }
-
-}
-
-static void lib_link_customdata_mtpoly(FileData *fd, Mesh *me, CustomData *pdata, int totface)
-{
- int i;
-
- for (i=0; i < pdata->totlayer; i++) {
- CustomDataLayer *layer = &pdata->layers[i];
-
- if (layer->type == CD_MTEXPOLY) {
- MTexPoly *tf= layer->data;
- int j;
-
- for (j = 0; j < totface; j++, tf++) {
- tf->tpage = newlibadr_real_us(fd, me->id.lib, tf->tpage);
- }
- }
- }
-}
-
static void lib_link_mesh(FileData *fd, Main *main)
{
Mesh *me;
@@ -4478,19 +4505,9 @@ static void lib_link_mesh(FileData *fd, Main *main)
me->ipo = newlibadr_us(fd, me->id.lib, me->ipo); // XXX: deprecated: old anim sys
me->key = newlibadr_us(fd, me->id.lib, me->key);
me->texcomesh = newlibadr_us(fd, me->id.lib, me->texcomesh);
-
- lib_link_customdata_mtface(fd, me, &me->fdata, me->totface);
- lib_link_customdata_mtpoly(fd, me, &me->pdata, me->totpoly);
- if (me->mr && me->mr->levels.first) {
- lib_link_customdata_mtface(fd, me, &me->mr->fdata,
- ((MultiresLevel*)me->mr->levels.first)->totface);
- }
}
}
- /* convert texface options to material */
- convert_tface_mt(fd, main);
-
for (me = main->mesh.first; me; me = me->id.next) {
if (me->id.tag & LIB_TAG_NEED_LINK) {
/*check if we need to convert mfaces to mpolys*/
@@ -4646,7 +4663,6 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
mesh->dvert = newdataadr(fd, mesh->dvert);
mesh->mloopcol = newdataadr(fd, mesh->mloopcol);
mesh->mloopuv = newdataadr(fd, mesh->mloopuv);
- mesh->mtpoly = newdataadr(fd, mesh->mtpoly);
mesh->mselect = newdataadr(fd, mesh->mselect);
/* animdata */
@@ -4665,18 +4681,13 @@ static void direct_link_mesh(FileData *fd, Mesh *mesh)
mesh->bb = NULL;
mesh->edit_btmesh = NULL;
+ mesh->runtime.batch_cache = NULL;
/* happens with old files */
if (mesh->mselect == NULL) {
mesh->totselect = 0;
}
- if (mesh->mloopuv || mesh->mtpoly) {
- /* for now we have to ensure texpoly and mloopuv layers are aligned
- * in the future we may allow non-aligned layers */
- BKE_mesh_cd_validate(mesh);
- }
-
/* Multires data */
mesh->mr= newdataadr(fd, mesh->mr);
if (mesh->mr) {
@@ -4756,6 +4767,7 @@ static void direct_link_latt(FileData *fd, Lattice *lt)
direct_link_dverts(fd, lt->pntsu*lt->pntsv*lt->pntsw, lt->dvert);
lt->editlatt = NULL;
+ lt->batch_cache = NULL;
lt->adt = newdataadr(fd, lt->adt);
direct_link_animdata(fd, lt->adt);
@@ -4777,6 +4789,14 @@ static void lib_link_modifiers__linkModifiers(
static void lib_link_modifiers(FileData *fd, Object *ob)
{
modifiers_foreachIDLink(ob, lib_link_modifiers__linkModifiers, fd);
+
+ /* If linking from a library, clear 'local' static override flag. */
+ if (ob->id.lib != NULL) {
+ for (ModifierData *mod = ob->modifiers.first; mod != NULL; mod = mod->next) {
+ mod->flag &= ~eModifierFlag_StaticOverride_Local;
+ }
+ }
+
}
static void lib_link_object(FileData *fd, Main *main)
@@ -4798,7 +4818,15 @@ static void lib_link_object(FileData *fd, Main *main)
ob->parent = newlibadr(fd, ob->id.lib, ob->parent);
ob->track = newlibadr(fd, ob->id.lib, ob->track);
ob->poselib = newlibadr_us(fd, ob->id.lib, ob->poselib);
- ob->dup_group = newlibadr_us(fd, ob->id.lib, ob->dup_group);
+
+ /* 2.8x drops support for non-empty dupli instances. */
+ if (ob->type == OB_EMPTY) {
+ ob->dup_group = newlibadr_us(fd, ob->id.lib, ob->dup_group);
+ }
+ else {
+ ob->dup_group = NULL;
+ ob->transflag &= ~OB_DUPLIGROUP;
+ }
ob->proxy = newlibadr_us(fd, ob->id.lib, ob->proxy);
if (ob->proxy) {
@@ -4861,7 +4889,6 @@ static void lib_link_object(FileData *fd, Main *main)
}
ob->gpd = newlibadr_us(fd, ob->id.lib, ob->gpd);
- ob->duplilist = NULL;
ob->id.tag &= ~LIB_TAG_NEED_LINK;
/* if id.us==0 a new base will be created later on */
@@ -4880,144 +4907,7 @@ static void lib_link_object(FileData *fd, Main *main)
paf->group = newlibadr_us(fd, ob->id.lib, paf->group);
}
}
-
- for (bSensor *sens = ob->sensors.first; sens; sens = sens->next) {
- for (a = 0; a < sens->totlinks; a++)
- sens->links[a] = newglobadr(fd, sens->links[a]);
- if (sens->type == SENS_MESSAGE) {
- bMessageSensor *ms = sens->data;
- ms->fromObject =
- newlibadr(fd, ob->id.lib, ms->fromObject);
- }
- }
-
- for (bController *cont = ob->controllers.first; cont; cont = cont->next) {
- for (a=0; a < cont->totlinks; a++)
- cont->links[a] = newglobadr(fd, cont->links[a]);
-
- if (cont->type == CONT_PYTHON) {
- bPythonCont *pc = cont->data;
- pc->text = newlibadr(fd, ob->id.lib, pc->text);
- }
- cont->slinks = NULL;
- cont->totslinks = 0;
- }
-
- for (bActuator *act = ob->actuators.first; act; act = act->next) {
- switch (act->type) {
- case ACT_SOUND:
- {
- bSoundActuator *sa = act->data;
- sa->sound = newlibadr_us(fd, ob->id.lib, sa->sound);
- break;
- }
- case ACT_GAME:
- /* bGameActuator *ga= act->data; */
- break;
- case ACT_CAMERA:
- {
- bCameraActuator *ca = act->data;
- ca->ob = newlibadr(fd, ob->id.lib, ca->ob);
- break;
- }
- /* leave this one, it's obsolete but necessary to read for conversion */
- case ACT_ADD_OBJECT:
- {
- bAddObjectActuator *eoa = act->data;
- if (eoa)
- eoa->ob = newlibadr(fd, ob->id.lib, eoa->ob);
- break;
- }
- case ACT_OBJECT:
- {
- bObjectActuator *oa = act->data;
- if (oa == NULL) {
- init_actuator(act);
- }
- else {
- oa->reference = newlibadr(fd, ob->id.lib, oa->reference);
- }
- break;
- }
- case ACT_EDIT_OBJECT:
- {
- bEditObjectActuator *eoa = act->data;
- if (eoa == NULL) {
- init_actuator(act);
- }
- else {
- eoa->ob = newlibadr(fd, ob->id.lib, eoa->ob);
- eoa->me = newlibadr(fd, ob->id.lib, eoa->me);
- }
- break;
- }
- case ACT_SCENE:
- {
- bSceneActuator *sa = act->data;
- sa->camera = newlibadr(fd, ob->id.lib, sa->camera);
- sa->scene = newlibadr(fd, ob->id.lib, sa->scene);
- break;
- }
- case ACT_ACTION:
- {
- bActionActuator *aa = act->data;
- aa->act = newlibadr_us(fd, ob->id.lib, aa->act);
- break;
- }
- case ACT_SHAPEACTION:
- {
- bActionActuator *aa = act->data;
- aa->act = newlibadr_us(fd, ob->id.lib, aa->act);
- break;
- }
- case ACT_PROPERTY:
- {
- bPropertyActuator *pa = act->data;
- pa->ob = newlibadr(fd, ob->id.lib, pa->ob);
- break;
- }
- case ACT_MESSAGE:
- {
- bMessageActuator *ma = act->data;
- ma->toObject = newlibadr(fd, ob->id.lib, ma->toObject);
- break;
- }
- case ACT_2DFILTER:
- {
- bTwoDFilterActuator *_2dfa = act->data;
- _2dfa->text = newlibadr(fd, ob->id.lib, _2dfa->text);
- break;
- }
- case ACT_PARENT:
- {
- bParentActuator *parenta = act->data;
- parenta->ob = newlibadr(fd, ob->id.lib, parenta->ob);
- break;
- }
- case ACT_STATE:
- /* bStateActuator *statea = act->data; */
- break;
- case ACT_ARMATURE:
- {
- bArmatureActuator *arma= act->data;
- arma->target = newlibadr(fd, ob->id.lib, arma->target);
- arma->subtarget = newlibadr(fd, ob->id.lib, arma->subtarget);
- break;
- }
- case ACT_STEERING:
- {
- bSteeringActuator *steeringa = act->data;
- steeringa->target = newlibadr(fd, ob->id.lib, steeringa->target);
- steeringa->navmesh = newlibadr(fd, ob->id.lib, steeringa->navmesh);
- break;
- }
- case ACT_MOUSE:
- /* bMouseActuator *moa = act->data; */
- break;
- }
- }
-
{
FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
@@ -5105,6 +4995,8 @@ static void direct_link_pose(FileData *fd, bPose *pose)
/* in case this value changes in future, clamp else we get undefined behavior */
CLAMP(pchan->rotmode, ROT_MODE_MIN, ROT_MODE_MAX);
+
+ pchan->draw_data = NULL;
}
pose->ikdata = NULL;
if (pose->ikparam != NULL) {
@@ -5186,6 +5078,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
smd->domain->shadow = NULL;
smd->domain->tex = NULL;
smd->domain->tex_shadow = NULL;
+ smd->domain->tex_flame = NULL;
smd->domain->tex_wt = NULL;
smd->domain->coba = newdataadr(fd, smd->domain->coba);
@@ -5439,19 +5332,10 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
static void direct_link_object(FileData *fd, Object *ob)
{
PartEff *paf;
- bProperty *prop;
- bSensor *sens;
- bController *cont;
- bActuator *act;
/* weak weak... this was only meant as draw flag, now is used in give_base_to_objects too */
ob->flag &= ~OB_FROMGROUP;
- /* This is a transient flag; clear in order to avoid unneeded object update pending from
- * time when file was saved.
- */
- ob->recalc = 0;
-
/* XXX This should not be needed - but seems like it can happen in some cases, so for now play safe... */
ob->proxy_from = NULL;
@@ -5479,6 +5363,7 @@ static void direct_link_object(FileData *fd, Object *ob)
direct_link_motionpath(fd, ob->mpath);
link_list(fd, &ob->defbase);
+ link_list(fd, &ob->fmaps);
// XXX deprecated - old animation system <<<
direct_link_nlastrips(fd, &ob->nlastrips);
link_list(fd, &ob->constraintChannels);
@@ -5568,7 +5453,6 @@ static void direct_link_object(FileData *fd, Object *ob)
direct_link_pointcache_list(fd, &sb->ptcaches, &sb->pointcache, 0);
}
- ob->bsoft = newdataadr(fd, ob->bsoft);
ob->fluidsimSettings= newdataadr(fd, ob->fluidsimSettings); /* NT */
ob->rigidbody_object = newdataadr(fd, ob->rigidbody_object);
@@ -5587,44 +5471,9 @@ static void direct_link_object(FileData *fd, Object *ob)
link_list(fd, &ob->particlesystem);
direct_link_particlesystems(fd, &ob->particlesystem);
-
- link_list(fd, &ob->prop);
- for (prop = ob->prop.first; prop; prop = prop->next) {
- prop->poin = newdataadr(fd, prop->poin);
- if (prop->poin == NULL)
- prop->poin = &prop->data;
- }
-
- link_list(fd, &ob->sensors);
- for (sens = ob->sensors.first; sens; sens = sens->next) {
- sens->data = newdataadr(fd, sens->data);
- sens->links = newdataadr(fd, sens->links);
- test_pointer_array(fd, (void **)&sens->links);
- }
direct_link_constraints(fd, &ob->constraints);
- link_glob_list(fd, &ob->controllers);
- if (ob->init_state) {
- /* if a known first state is specified, set it so that the game will start ok */
- ob->state = ob->init_state;
- }
- else if (!ob->state) {
- ob->state = 1;
- }
- for (cont = ob->controllers.first; cont; cont = cont->next) {
- cont->data = newdataadr(fd, cont->data);
- cont->links = newdataadr(fd, cont->links);
- test_pointer_array(fd, (void **)&cont->links);
- if (cont->state_mask == 0)
- cont->state_mask = 1;
- }
-
- link_glob_list(fd, &ob->actuators);
- for (act = ob->actuators.first; act; act = act->next) {
- act->data = newdataadr(fd, act->data);
- }
-
link_list(fd, &ob->hooks);
while (ob->hooks.first) {
ObHook *hook = ob->hooks.first;
@@ -5665,6 +5514,7 @@ static void direct_link_object(FileData *fd, Object *ob)
ob->derivedDeform = NULL;
ob->derivedFinal = NULL;
BLI_listbase_clear(&ob->gpulamp);
+ BLI_listbase_clear(&ob->drawdata);
link_list(fd, &ob->pc_ids);
/* Runtime curve data */
@@ -5681,6 +5531,8 @@ static void direct_link_object(FileData *fd, Object *ob)
ob->currentlod = ob->lodlevels.first;
ob->preview = direct_link_preview_image(fd, ob->preview);
+
+ ob->base_collection_properties = NULL;
}
/* ************ READ SCENE ***************** */
@@ -5745,6 +5597,62 @@ static bool scene_validate_setscene__liblink(Scene *sce, const int totscene)
}
#endif
+static void lib_link_scene_collection(FileData *fd, Library *lib, SceneCollection *sc)
+{
+ for (LinkData *link = sc->objects.first; link; link = link->next) {
+ link->data = newlibadr_us(fd, lib, link->data);
+ BLI_assert(link->data);
+ }
+
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ lib_link_scene_collection(fd, lib, nsc);
+ }
+}
+
+static void lib_link_layer_collection(FileData *fd, LayerCollection *layer_collection)
+{
+ IDP_LibLinkProperty(layer_collection->properties, fd);
+
+ for (LayerCollection *layer_collection_nested = layer_collection->layer_collections.first;
+ layer_collection_nested != NULL;
+ layer_collection_nested = layer_collection_nested->next)
+ {
+ lib_link_layer_collection(fd, layer_collection_nested);
+ }
+}
+
+static void lib_link_view_layer(FileData *fd, Library *lib, ViewLayer *view_layer)
+{
+ /* tag scene layer to update for collection tree evaluation */
+ view_layer->flag |= VIEW_LAYER_ENGINE_DIRTY;
+
+ for (FreestyleModuleConfig *fmc = view_layer->freestyle_config.modules.first; fmc; fmc = fmc->next) {
+ fmc->script = newlibadr(fd, lib, fmc->script);
+ }
+
+ for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; fls = fls->next) {
+ fls->linestyle = newlibadr_us(fd, lib, fls->linestyle);
+ fls->group = newlibadr_us(fd, lib, fls->group);
+ }
+
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ /* we only bump the use count for the collection objects */
+ base->object = newlibadr(fd, lib, base->object);
+ base->flag |= BASE_DIRTY_ENGINE_SETTINGS;
+ base->collection_properties = NULL;
+ }
+
+ for (LayerCollection *layer_collection = view_layer->layer_collections.first;
+ layer_collection != NULL;
+ layer_collection = layer_collection->next)
+ {
+ lib_link_layer_collection(fd, layer_collection);
+ }
+
+ IDP_LibLinkProperty(view_layer->properties, fd);
+ IDP_LibLinkProperty(view_layer->id_properties, fd);
+}
+
static void lib_link_scene(FileData *fd, Main *main)
{
#ifdef USE_SETSCENE_CHECK
@@ -5788,21 +5696,19 @@ static void lib_link_scene(FileData *fd, Main *main)
sce->toolsettings->imapaint.canvas =
newlibadr_us(fd, sce->id.lib, sce->toolsettings->imapaint.canvas);
- sce->toolsettings->skgen_template = newlibadr(fd, sce->id.lib, sce->toolsettings->skgen_template);
-
sce->toolsettings->particle.shape_object = newlibadr(fd, sce->id.lib, sce->toolsettings->particle.shape_object);
- for (Base *next, *base = sce->base.first; base; base = next) {
- next = base->next;
+ for (Base *base_legacy_next, *base_legacy = sce->base.first; base_legacy; base_legacy = base_legacy_next) {
+ base_legacy_next = base_legacy->next;
- base->object = newlibadr_us(fd, sce->id.lib, base->object);
+ base_legacy->object = newlibadr_us(fd, sce->id.lib, base_legacy->object);
- if (base->object == NULL) {
+ if (base_legacy->object == NULL) {
blo_reportf_wrap(fd->reports, RPT_WARNING, TIP_("LIB: object lost from scene: '%s'"),
sce->id.name + 2);
- BLI_remlink(&sce->base, base);
- if (base == sce->basact) sce->basact = NULL;
- MEM_freeN(base);
+ BLI_remlink(&sce->base, base_legacy);
+ if (base_legacy == sce->basact) sce->basact = NULL;
+ MEM_freeN(base_legacy);
}
}
@@ -5876,7 +5782,6 @@ static void lib_link_scene(FileData *fd, Main *main)
for (SceneRenderLayer *srl = sce->r.layers.first; srl; srl = srl->next) {
srl->mat_override = newlibadr_us(fd, sce->id.lib, srl->mat_override);
- srl->light_override = newlibadr_us(fd, sce->id.lib, srl->light_override);
for (FreestyleModuleConfig *fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
fmc->script = newlibadr(fd, sce->id.lib, fmc->script);
}
@@ -5885,12 +5790,15 @@ static void lib_link_scene(FileData *fd, Main *main)
fls->group = newlibadr_us(fd, sce->id.lib, fls->group);
}
}
- /*Game Settings: Dome Warp Text*/
- sce->gm.dome.warptext = newlibadr(fd, sce->id.lib, sce->gm.dome.warptext);
-
/* Motion Tracking */
sce->clip = newlibadr_us(fd, sce->id.lib, sce->clip);
+ lib_link_scene_collection(fd, sce->id.lib, sce->collection);
+
+ for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ lib_link_view_layer(fd, sce->id.lib, view_layer);
+ }
+
#ifdef USE_SETSCENE_CHECK
if (sce->set != NULL) {
/* link flag for scenes with set would be reset later,
@@ -5994,18 +5902,106 @@ static void direct_link_view_settings(FileData *fd, ColorManagedViewSettings *vi
direct_link_curvemapping(fd, view_settings->curve_mapping);
}
-static void direct_link_scene(FileData *fd, Scene *sce)
+static void direct_link_scene_collection(FileData *fd, SceneCollection *sc)
+{
+ link_list(fd, &sc->objects);
+ link_list(fd, &sc->scene_collections);
+
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ direct_link_scene_collection(fd, nsc);
+ }
+}
+
+static void direct_link_layer_collections(FileData *fd, ListBase *lb)
+{
+ link_list(fd, lb);
+ for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+ lc->scene_collection = newdataadr(fd, lc->scene_collection);
+
+ link_list(fd, &lc->object_bases);
+
+ for (LinkData *link = lc->object_bases.first; link; link = link->next) {
+ link->data = newdataadr(fd, link->data);
+ }
+
+ link_list(fd, &lc->overrides);
+
+ if (lc->properties) {
+ lc->properties = newdataadr(fd, lc->properties);
+ IDP_DirectLinkGroup_OrFree(&lc->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+ BKE_layer_collection_engine_settings_validate_collection(lc);
+ }
+ lc->properties_evaluated = NULL;
+
+ direct_link_layer_collections(fd, &lc->layer_collections);
+ }
+}
+
+static void direct_link_view_layer(FileData *fd, ViewLayer *view_layer)
+{
+ view_layer->stats = NULL;
+ link_list(fd, &view_layer->object_bases);
+ view_layer->basact = newdataadr(fd, view_layer->basact);
+ direct_link_layer_collections(fd, &view_layer->layer_collections);
+
+ if (view_layer->properties != NULL) {
+ view_layer->properties = newdataadr(fd, view_layer->properties);
+ BLI_assert(view_layer->properties != NULL);
+ IDP_DirectLinkGroup_OrFree(&view_layer->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+ BKE_view_layer_engine_settings_validate_layer(view_layer);
+ }
+
+ view_layer->id_properties = newdataadr(fd, view_layer->id_properties);
+ IDP_DirectLinkGroup_OrFree(&view_layer->id_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+
+ link_list(fd, &(view_layer->freestyle_config.modules));
+ link_list(fd, &(view_layer->freestyle_config.linesets));
+
+ view_layer->properties_evaluated = NULL;
+
+ BLI_listbase_clear(&view_layer->drawdata);
+ view_layer->object_bases_array = NULL;
+}
+
+/**
+ * Workspaces store a render layer pointer which can only be read after scene is read.
+ */
+static void direct_link_workspace_link_scene_data(
+ FileData *fd, Scene *scene, const ListBase *workspaces)
+{
+ for (WorkSpace *workspace = workspaces->first; workspace; workspace = workspace->id.next) {
+ for (WorkSpaceDataRelation *relation = workspace->scene_viewlayer_relations.first;
+ relation != NULL;
+ relation = relation->next)
+ {
+ ViewLayer *layer = newdataadr(fd, relation->value);
+ if (layer) {
+ BLI_assert(BLI_findindex(&scene->view_layers, layer) != -1);
+ /* relation->parent is set in lib_link_workspaces */
+ relation->value = layer;
+ }
+ }
+
+ if (workspace->view_layer) { /* this was temporariliy used during 2.8 project. Keep files compatible */
+ ViewLayer *layer = newdataadr(fd, workspace->view_layer);
+ /* only set when layer is from the scene we read */
+ if (layer && (BLI_findindex(&scene->view_layers, layer) != -1)) {
+ workspace->view_layer = layer;
+ }
+ }
+ }
+}
+
+static void direct_link_scene(FileData *fd, Scene *sce, Main *bmain)
{
Editing *ed;
Sequence *seq;
MetaStack *ms;
RigidBodyWorld *rbw;
+ ViewLayer *view_layer;
SceneRenderLayer *srl;
- sce->theDag = NULL;
- sce->depsgraph = NULL;
- sce->obedit = NULL;
- sce->stats = NULL;
+ sce->depsgraph_hash = NULL;
sce->fps_info = NULL;
sce->customdata_mask_modal = 0;
sce->lay_updated = 0;
@@ -6182,12 +6178,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
}
}
}
-
-#ifdef DURIAN_CAMERA_SWITCH
- /* Runtime */
- sce->r.mode &= ~R_NO_CAMERA_SWITCH;
-#endif
-
+
sce->r.avicodecdata = newdataadr(fd, sce->r.avicodecdata);
if (sce->r.avicodecdata) {
sce->r.avicodecdata->lpFormat = newdataadr(fd, sce->r.avicodecdata->lpFormat);
@@ -6207,11 +6198,7 @@ static void direct_link_scene(FileData *fd, Scene *sce)
for (srl = sce->r.layers.first; srl; srl = srl->next) {
srl->prop = newdataadr(fd, srl->prop);
IDP_DirectLinkGroup_OrFree(&srl->prop, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
- }
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
link_list(fd, &(srl->freestyleConfig.modules));
- }
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
link_list(fd, &(srl->freestyleConfig.linesets));
}
@@ -6249,6 +6236,615 @@ static void direct_link_scene(FileData *fd, Scene *sce)
sce->preview = direct_link_preview_image(fd, sce->preview);
direct_link_curvemapping(fd, &sce->r.mblur_shutter_curve);
+
+ /* this runs before the very first doversion */
+ if (sce->collection) {
+ sce->collection = newdataadr(fd, sce->collection);
+ direct_link_scene_collection(fd, sce->collection);
+ }
+
+ /* insert into global old-new map for reading without UI (link_global accesses it again) */
+ link_glob_list(fd, &sce->view_layers);
+ for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ direct_link_view_layer(fd, view_layer);
+ }
+
+ sce->collection_properties = newdataadr(fd, sce->collection_properties);
+ IDP_DirectLinkGroup_OrFree(&sce->collection_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+
+ sce->layer_properties = newdataadr(fd, sce->layer_properties);
+ IDP_DirectLinkGroup_OrFree(&sce->layer_properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+
+ BKE_layer_collection_engine_settings_validate_scene(sce);
+ BKE_view_layer_engine_settings_validate_scene(sce);
+
+ direct_link_workspace_link_scene_data(fd, sce, &bmain->workspaces);
+}
+
+/* ****************** READ GREASE PENCIL ***************** */
+
+/* relink's grease pencil data's refs */
+static void lib_link_gpencil(FileData *fd, Main *main)
+{
+ for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
+ if (gpd->id.tag & LIB_TAG_NEED_LINK) {
+ IDP_LibLinkProperty(gpd->id.properties, fd);
+ lib_link_animdata(fd, &gpd->id, gpd->adt);
+
+ gpd->id.tag &= ~LIB_TAG_NEED_LINK;
+ }
+ }
+}
+
+/* relinks grease-pencil data - used for direct_link and old file linkage */
+static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
+{
+ bGPDlayer *gpl;
+ bGPDframe *gpf;
+ bGPDstroke *gps;
+ bGPDpalette *palette;
+
+ /* we must firstly have some grease-pencil data to link! */
+ if (gpd == NULL)
+ return;
+
+ /* relink animdata */
+ gpd->adt = newdataadr(fd, gpd->adt);
+ direct_link_animdata(fd, gpd->adt);
+
+ /* relink palettes */
+ link_list(fd, &gpd->palettes);
+ for (palette = gpd->palettes.first; palette; palette = palette->next) {
+ link_list(fd, &palette->colors);
+ }
+
+ /* relink layers */
+ link_list(fd, &gpd->layers);
+
+ for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+ /* parent */
+ gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent);
+ /* relink frames */
+ link_list(fd, &gpl->frames);
+ gpl->actframe = newdataadr(fd, gpl->actframe);
+
+ for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
+ /* relink strokes (and their points) */
+ link_list(fd, &gpf->strokes);
+
+ for (gps = gpf->strokes.first; gps; gps = gps->next) {
+ gps->points = newdataadr(fd, gps->points);
+
+ /* the triangulation is not saved, so need to be recalculated */
+ gps->triangles = NULL;
+ gps->tot_triangles = 0;
+ gps->flag |= GP_STROKE_RECALC_CACHES;
+ /* the color pointer is not saved, so need to be recalculated using the color name */
+ gps->palcolor = NULL;
+ gps->flag |= GP_STROKE_RECALC_COLOR;
+ }
+ }
+ }
+}
+
+/* *********** READ AREA **************** */
+
+static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
+{
+ Panel *pa;
+ uiList *ui_list;
+
+ link_list(fd, &ar->panels);
+
+ for (pa = ar->panels.first; pa; pa = pa->next) {
+ pa->paneltab = newdataadr(fd, pa->paneltab);
+ pa->runtime_flag = 0;
+ pa->activedata = NULL;
+ pa->type = NULL;
+ }
+
+ link_list(fd, &ar->panels_category_active);
+
+ link_list(fd, &ar->ui_lists);
+
+ for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
+ ui_list->type = NULL;
+ ui_list->dyn_data = NULL;
+ ui_list->properties = newdataadr(fd, ui_list->properties);
+ IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
+ }
+
+ link_list(fd, &ar->ui_previews);
+
+ if (spacetype == SPACE_EMPTY) {
+ /* unkown space type, don't leak regiondata */
+ ar->regiondata = NULL;
+ }
+ else {
+ ar->regiondata = newdataadr(fd, ar->regiondata);
+ if (ar->regiondata) {
+ if (spacetype == SPACE_VIEW3D) {
+ RegionView3D *rv3d = ar->regiondata;
+
+ rv3d->localvd = newdataadr(fd, rv3d->localvd);
+ rv3d->clipbb = newdataadr(fd, rv3d->clipbb);
+
+ rv3d->depths = NULL;
+ rv3d->gpuoffscreen = NULL;
+ rv3d->render_engine = NULL;
+ rv3d->sms = NULL;
+ rv3d->smooth_timer = NULL;
+ }
+ }
+ }
+
+ ar->v2d.tab_offset = NULL;
+ ar->v2d.tab_num = 0;
+ ar->v2d.tab_cur = 0;
+ ar->v2d.sms = NULL;
+ ar->v2d.alpha_hor = ar->v2d.alpha_vert = 0;
+ ar->v2d.size_hor = ar->v2d.size_vert = 0;
+ BLI_listbase_clear(&ar->panels_category);
+ BLI_listbase_clear(&ar->handlers);
+ BLI_listbase_clear(&ar->uiblocks);
+ ar->headerstr = NULL;
+ ar->visible = 0;
+ ar->type = NULL;
+ ar->do_draw = 0;
+ ar->manipulator_map = NULL;
+ ar->regiontimer = NULL;
+ ar->draw_buffer = NULL;
+ memset(&ar->drawrct, 0, sizeof(ar->drawrct));
+}
+
+static void direct_link_area(FileData *fd, ScrArea *area)
+{
+ SpaceLink *sl;
+ ARegion *ar;
+
+ link_list(fd, &(area->spacedata));
+ link_list(fd, &(area->regionbase));
+
+ BLI_listbase_clear(&area->handlers);
+ area->type = NULL; /* spacetype callbacks */
+ area->butspacetype = SPACE_EMPTY; /* Should always be unset so that rna_Area_type_get works correctly */
+ area->region_active_win = -1;
+
+ area->global = newdataadr(fd, area->global);
+
+ /* if we do not have the spacetype registered we cannot
+ * free it, so don't allocate any new memory for such spacetypes. */
+ if (!BKE_spacetype_exists(area->spacetype)) {
+ area->butspacetype = area->spacetype; /* Hint for versioning code to replace deprecated space types. */
+ area->spacetype = SPACE_EMPTY;
+ }
+
+ for (ar = area->regionbase.first; ar; ar = ar->next) {
+ direct_link_region(fd, ar, area->spacetype);
+ }
+
+ /* accident can happen when read/save new file with older version */
+ /* 2.50: we now always add spacedata for info */
+ if (area->spacedata.first == NULL) {
+ SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo");
+ area->spacetype= sinfo->spacetype= SPACE_INFO;
+ BLI_addtail(&area->spacedata, sinfo);
+ }
+ /* add local view3d too */
+ else if (area->spacetype == SPACE_VIEW3D) {
+ blo_do_versions_view3d_split_250(area->spacedata.first, &area->regionbase);
+ }
+
+ for (sl = area->spacedata.first; sl; sl = sl->next) {
+ link_list(fd, &(sl->regionbase));
+
+ /* if we do not have the spacetype registered we cannot
+ * free it, so don't allocate any new memory for such spacetypes. */
+ if (!BKE_spacetype_exists(sl->spacetype))
+ sl->spacetype = SPACE_EMPTY;
+
+ for (ar = sl->regionbase.first; ar; ar = ar->next)
+ direct_link_region(fd, ar, sl->spacetype);
+
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d= (View3D*) sl;
+
+ v3d->flag |= V3D_INVALID_BACKBUF;
+
+ if (v3d->gpd) {
+ v3d->gpd = newdataadr(fd, v3d->gpd);
+ direct_link_gpencil(fd, v3d->gpd);
+ }
+ v3d->localvd = newdataadr(fd, v3d->localvd);
+ v3d->properties_storage = NULL;
+
+ /* render can be quite heavy, set to solid on load */
+ if (v3d->drawtype == OB_RENDER)
+ v3d->drawtype = OB_SOLID;
+ v3d->prev_drawtype = OB_SOLID;
+
+ if (v3d->fx_settings.dof)
+ v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof);
+ if (v3d->fx_settings.ssao)
+ v3d->fx_settings.ssao = newdataadr(fd, v3d->fx_settings.ssao);
+
+ blo_do_versions_view3d_split_250(v3d, &sl->regionbase);
+ }
+ else if (sl->spacetype == SPACE_IPO) {
+ SpaceIpo *sipo = (SpaceIpo *)sl;
+
+ sipo->ads = newdataadr(fd, sipo->ads);
+ BLI_listbase_clear(&sipo->ghostCurves);
+ }
+ else if (sl->spacetype == SPACE_NLA) {
+ SpaceNla *snla = (SpaceNla *)sl;
+
+ snla->ads = newdataadr(fd, snla->ads);
+ }
+ else if (sl->spacetype == SPACE_OUTLINER) {
+ SpaceOops *soops = (SpaceOops *) sl;
+
+ /* use newdataadr_no_us and do not free old memory avoiding double
+ * frees and use of freed memory. this could happen because of a
+ * bug fixed in revision 58959 where the treestore memory address
+ * was not unique */
+ TreeStore *ts = newdataadr_no_us(fd, soops->treestore);
+ soops->treestore = NULL;
+ if (ts) {
+ TreeStoreElem *elems = newdataadr_no_us(fd, ts->data);
+
+ soops->treestore = BLI_mempool_create(sizeof(TreeStoreElem), ts->usedelem,
+ 512, BLI_MEMPOOL_ALLOW_ITER);
+ if (ts->usedelem && elems) {
+ int i;
+ for (i = 0; i < ts->usedelem; i++) {
+ TreeStoreElem *new_elem = BLI_mempool_alloc(soops->treestore);
+ *new_elem = elems[i];
+ }
+ }
+ /* we only saved what was used */
+ soops->storeflag |= SO_TREESTORE_CLEANUP; // at first draw
+ }
+ soops->treehash = NULL;
+ soops->tree.first = soops->tree.last= NULL;
+ }
+ else if (sl->spacetype == SPACE_IMAGE) {
+ SpaceImage *sima = (SpaceImage *)sl;
+
+ sima->iuser.scene = NULL;
+ sima->iuser.ok = 1;
+ sima->scopes.waveform_1 = NULL;
+ sima->scopes.waveform_2 = NULL;
+ sima->scopes.waveform_3 = NULL;
+ sima->scopes.vecscope = NULL;
+ sima->scopes.ok = 0;
+
+ /* WARNING: gpencil data is no longer stored directly in sima after 2.5
+ * so sacrifice a few old files for now to avoid crashes with new files!
+ * committed: r28002 */
+#if 0
+ sima->gpd = newdataadr(fd, sima->gpd);
+ if (sima->gpd)
+ direct_link_gpencil(fd, sima->gpd);
+#endif
+ }
+ else if (sl->spacetype == SPACE_NODE) {
+ SpaceNode *snode = (SpaceNode *)sl;
+
+ if (snode->gpd) {
+ snode->gpd = newdataadr(fd, snode->gpd);
+ direct_link_gpencil(fd, snode->gpd);
+ }
+
+ link_list(fd, &snode->treepath);
+ snode->edittree = NULL;
+ snode->iofsd = NULL;
+ BLI_listbase_clear(&snode->linkdrag);
+ }
+ else if (sl->spacetype == SPACE_TEXT) {
+ SpaceText *st= (SpaceText *)sl;
+
+ st->drawcache = NULL;
+ st->scroll_accum[0] = 0.0f;
+ st->scroll_accum[1] = 0.0f;
+ }
+ else if (sl->spacetype == SPACE_SEQ) {
+ SpaceSeq *sseq = (SpaceSeq *)sl;
+
+ /* grease pencil data is not a direct data and can't be linked from direct_link*
+ * functions, it should be linked from lib_link* functions instead
+ *
+ * otherwise it'll lead to lost grease data on open because it'll likely be
+ * read from file after all other users of grease pencil and newdataadr would
+ * simple return NULL here (sergey)
+ */
+#if 0
+ if (sseq->gpd) {
+ sseq->gpd = newdataadr(fd, sseq->gpd);
+ direct_link_gpencil(fd, sseq->gpd);
+ }
+#endif
+ sseq->scopes.reference_ibuf = NULL;
+ sseq->scopes.zebra_ibuf = NULL;
+ sseq->scopes.waveform_ibuf = NULL;
+ sseq->scopes.sep_waveform_ibuf = NULL;
+ sseq->scopes.vector_ibuf = NULL;
+ sseq->scopes.histogram_ibuf = NULL;
+ sseq->compositor = NULL;
+ }
+ else if (sl->spacetype == SPACE_BUTS) {
+ SpaceButs *sbuts = (SpaceButs *)sl;
+
+ sbuts->path= NULL;
+ sbuts->texuser= NULL;
+ sbuts->mainbo = sbuts->mainb;
+ sbuts->mainbuser = sbuts->mainb;
+ }
+ else if (sl->spacetype == SPACE_CONSOLE) {
+ SpaceConsole *sconsole = (SpaceConsole *)sl;
+ ConsoleLine *cl, *cl_next;
+
+ link_list(fd, &sconsole->scrollback);
+ link_list(fd, &sconsole->history);
+
+ //for (cl= sconsole->scrollback.first; cl; cl= cl->next)
+ // cl->line= newdataadr(fd, cl->line);
+
+ /* comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression,
+ * from left to right. the right-most expression sets the result of the comma
+ * expression as a whole*/
+ for (cl = sconsole->history.first; cl; cl = cl_next) {
+ cl_next = cl->next;
+ cl->line = newdataadr(fd, cl->line);
+ if (cl->line) {
+ /* the allocted length is not written, so reset here */
+ cl->len_alloc = cl->len + 1;
+ }
+ else {
+ BLI_remlink(&sconsole->history, cl);
+ MEM_freeN(cl);
+ }
+ }
+ }
+ else if (sl->spacetype == SPACE_FILE) {
+ SpaceFile *sfile = (SpaceFile *)sl;
+
+ /* this sort of info is probably irrelevant for reloading...
+ * plus, it isn't saved to files yet!
+ */
+ sfile->folders_prev = sfile->folders_next = NULL;
+ sfile->files = NULL;
+ sfile->layout = NULL;
+ sfile->op = NULL;
+ sfile->previews_timer = NULL;
+ sfile->params = newdataadr(fd, sfile->params);
+ }
+ else if (sl->spacetype == SPACE_CLIP) {
+ SpaceClip *sclip = (SpaceClip *)sl;
+
+ sclip->scopes.track_search = NULL;
+ sclip->scopes.track_preview = NULL;
+ sclip->scopes.ok = 0;
+ }
+ }
+
+ BLI_listbase_clear(&area->actionzones);
+
+ area->v1 = newdataadr(fd, area->v1);
+ area->v2 = newdataadr(fd, area->v2);
+ area->v3 = newdataadr(fd, area->v3);
+ area->v4 = newdataadr(fd, area->v4);
+}
+
+static void lib_link_area(FileData *fd, ID *parent_id, ScrArea *area)
+{
+ area->full = newlibadr(fd, parent_id->lib, area->full);
+
+ for (SpaceLink *sl = area->spacedata.first; sl; sl= sl->next) {
+ switch (sl->spacetype) {
+ case SPACE_VIEW3D:
+ {
+ View3D *v3d = (View3D*) sl;
+
+ v3d->camera= newlibadr(fd, parent_id->lib, v3d->camera);
+ v3d->ob_centre= newlibadr(fd, parent_id->lib, v3d->ob_centre);
+
+ if (v3d->localvd) {
+ v3d->localvd->camera = newlibadr(fd, parent_id->lib, v3d->localvd->camera);
+ }
+ break;
+ }
+ case SPACE_IPO:
+ {
+ SpaceIpo *sipo = (SpaceIpo *)sl;
+ bDopeSheet *ads = sipo->ads;
+
+ if (ads) {
+ ads->source = newlibadr(fd, parent_id->lib, ads->source);
+ ads->filter_grp = newlibadr(fd, parent_id->lib, ads->filter_grp);
+ }
+ break;
+ }
+ case SPACE_BUTS:
+ {
+ SpaceButs *sbuts = (SpaceButs *)sl;
+ sbuts->pinid = newlibadr(fd, parent_id->lib, sbuts->pinid);
+ if (sbuts->pinid == NULL) {
+ sbuts->flag &= ~SB_PIN_CONTEXT;
+ }
+ break;
+ }
+ case SPACE_FILE:
+ break;
+ case SPACE_ACTION:
+ {
+ SpaceAction *saction = (SpaceAction *)sl;
+ bDopeSheet *ads = &saction->ads;
+
+ if (ads) {
+ ads->source = newlibadr(fd, parent_id->lib, ads->source);
+ ads->filter_grp = newlibadr(fd, parent_id->lib, ads->filter_grp);
+ }
+
+ saction->action = newlibadr(fd, parent_id->lib, saction->action);
+ break;
+ }
+ case SPACE_IMAGE:
+ {
+ SpaceImage *sima = (SpaceImage *)sl;
+
+ sima->image = newlibadr_real_us(fd, parent_id->lib, sima->image);
+ sima->mask_info.mask = newlibadr_real_us(fd, parent_id->lib, sima->mask_info.mask);
+
+ /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
+ * so fingers crossed this works fine!
+ */
+ sima->gpd = newlibadr_us(fd, parent_id->lib, sima->gpd);
+ break;
+ }
+ case SPACE_SEQ:
+ {
+ SpaceSeq *sseq = (SpaceSeq *)sl;
+
+ /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
+ * so fingers crossed this works fine!
+ */
+ sseq->gpd = newlibadr_us(fd, parent_id->lib, sseq->gpd);
+ break;
+ }
+ case SPACE_NLA:
+ {
+ SpaceNla *snla= (SpaceNla *)sl;
+ bDopeSheet *ads= snla->ads;
+
+ if (ads) {
+ ads->source = newlibadr(fd, parent_id->lib, ads->source);
+ ads->filter_grp = newlibadr(fd, parent_id->lib, ads->filter_grp);
+ }
+ break;
+ }
+ case SPACE_TEXT:
+ {
+ SpaceText *st= (SpaceText *)sl;
+
+ st->text= newlibadr(fd, parent_id->lib, st->text);
+ break;
+ }
+ case SPACE_SCRIPT:
+ {
+ SpaceScript *scpt = (SpaceScript *)sl;
+ /*scpt->script = NULL; - 2.45 set to null, better re-run the script */
+ if (scpt->script) {
+ scpt->script = newlibadr(fd, parent_id->lib, scpt->script);
+ if (scpt->script) {
+ SCRIPT_SET_NULL(scpt->script);
+ }
+ }
+ break;
+ }
+ case SPACE_OUTLINER:
+ {
+ SpaceOops *so= (SpaceOops *)sl;
+ so->search_tse.id = newlibadr(fd, NULL, so->search_tse.id);
+
+ if (so->treestore) {
+ TreeStoreElem *tselem;
+ BLI_mempool_iter iter;
+
+ BLI_mempool_iternew(so->treestore, &iter);
+ while ((tselem = BLI_mempool_iterstep(&iter))) {
+ tselem->id = newlibadr(fd, NULL, tselem->id);
+ }
+ if (so->treehash) {
+ /* rebuild hash table, because it depends on ids too */
+ so->storeflag |= SO_TREESTORE_REBUILD;
+ }
+ }
+ break;
+ }
+ case SPACE_NODE:
+ {
+ SpaceNode *snode = (SpaceNode *)sl;
+ bNodeTreePath *path, *path_next;
+ bNodeTree *ntree;
+
+ /* node tree can be stored locally in id too, link this first */
+ snode->id = newlibadr(fd, parent_id->lib, snode->id);
+ snode->from = newlibadr(fd, parent_id->lib, snode->from);
+
+ ntree = snode->id ? ntreeFromID(snode->id) : NULL;
+ snode->nodetree = ntree ? ntree : newlibadr_us(fd, parent_id->lib, snode->nodetree);
+
+ for (path = snode->treepath.first; path; path = path->next) {
+ if (path == snode->treepath.first) {
+ /* first nodetree in path is same as snode->nodetree */
+ path->nodetree = snode->nodetree;
+ }
+ else
+ path->nodetree = newlibadr_us(fd, parent_id->lib, path->nodetree);
+
+ if (!path->nodetree)
+ break;
+ }
+
+ /* remaining path entries are invalid, remove */
+ for (; path; path = path_next) {
+ path_next = path->next;
+
+ BLI_remlink(&snode->treepath, path);
+ MEM_freeN(path);
+ }
+
+ /* edittree is just the last in the path,
+ * set this directly since the path may have been shortened above */
+ if (snode->treepath.last) {
+ path = snode->treepath.last;
+ snode->edittree = path->nodetree;
+ }
+ else {
+ snode->edittree = NULL;
+ }
+ break;
+ }
+ case SPACE_CLIP:
+ {
+ SpaceClip *sclip = (SpaceClip *)sl;
+ sclip->clip = newlibadr_real_us(fd, parent_id->lib, sclip->clip);
+ sclip->mask_info.mask = newlibadr_real_us(fd, parent_id->lib, sclip->mask_info.mask);
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+
+/**
+ * \return false on error.
+ */
+static bool direct_link_area_map(FileData *fd, ScrAreaMap *area_map)
+{
+ link_list(fd, &area_map->vertbase);
+ link_list(fd, &area_map->edgebase);
+ link_list(fd, &area_map->areabase);
+ for (ScrArea *area = area_map->areabase.first; area; area = area->next) {
+ direct_link_area(fd, area);
+ }
+
+ /* edges */
+ for (ScrEdge *se = area_map->edgebase.first; se; se = se->next) {
+ se->v1 = newdataadr(fd, se->v1);
+ se->v2 = newdataadr(fd, se->v2);
+ BKE_screen_sort_scrvert(&se->v1, &se->v2);
+
+ if (se->v1 == NULL) {
+ BLI_remlink(&area_map->edgebase, se);
+
+ return false;
+ }
+ }
+
+ return true;
}
/* ************ READ WM ***************** */
@@ -6261,9 +6857,17 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
link_list(fd, &wm->windows);
for (win = wm->windows.first; win; win = win->next) {
+ WorkSpaceInstanceHook *hook = win->workspace_hook;
+
+ win->workspace_hook = newdataadr(fd, hook);
+ /* we need to restore a pointer to this later when reading workspaces, so store in global oldnew-map */
+ oldnewmap_insert(fd->globmap, hook, win->workspace_hook, 0);
+
+ direct_link_area_map(fd, &win->global_areas);
+
win->ghostwin = NULL;
+ win->gwnctx = NULL;
win->eventstate = NULL;
- win->curswin = NULL;
win->tweak = NULL;
#ifdef WIN32
win->ime_data = NULL;
@@ -6272,12 +6876,8 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
BLI_listbase_clear(&win->queue);
BLI_listbase_clear(&win->handlers);
BLI_listbase_clear(&win->modalhandlers);
- BLI_listbase_clear(&win->subwindows);
BLI_listbase_clear(&win->gesture);
- BLI_listbase_clear(&win->drawdata);
- win->drawmethod = -1;
- win->drawfail = 0;
win->active = 0;
win->cursor = 0;
@@ -6285,7 +6885,6 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
win->modalcursor = 0;
win->grabcursor = 0;
win->addmousemove = true;
- win->multisamples = 0;
win->stereo3d_format = newdataadr(fd, win->stereo3d_format);
/* multiview always fallback to anaglyph at file opening
@@ -6307,6 +6906,8 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
wm->userconf = NULL;
wm->undo_stack = NULL;
+ wm->message_bus = NULL;
+
BLI_listbase_clear(&wm->jobs);
BLI_listbase_clear(&wm->drags);
@@ -6326,76 +6927,19 @@ static void lib_link_windowmanager(FileData *fd, Main *main)
if (wm->id.tag & LIB_TAG_NEED_LINK) {
/* Note: WM IDProperties are never written to file, hence no need to read/link them here. */
for (win = wm->windows.first; win; win = win->next) {
+ if (win->workspace_hook) { /* NULL for old files */
+ lib_link_workspace_instance_hook(fd, win->workspace_hook, &wm->id);
+ }
+ win->scene = newlibadr(fd, wm->id.lib, win->scene);
+ /* deprecated, but needed for versioning (will be NULL'ed then) */
win->screen = newlibadr(fd, NULL, win->screen);
- }
-
- wm->id.tag &= ~LIB_TAG_NEED_LINK;
- }
- }
-}
-
-/* ****************** READ GREASE PENCIL ***************** */
-
-/* relink's grease pencil data's refs */
-static void lib_link_gpencil(FileData *fd, Main *main)
-{
- for (bGPdata *gpd = main->gpencil.first; gpd; gpd = gpd->id.next) {
- if (gpd->id.tag & LIB_TAG_NEED_LINK) {
- IDP_LibLinkProperty(gpd->id.properties, fd);
- lib_link_animdata(fd, &gpd->id, gpd->adt);
-
- gpd->id.tag &= ~LIB_TAG_NEED_LINK;
- }
- }
-}
-
-/* relinks grease-pencil data - used for direct_link and old file linkage */
-static void direct_link_gpencil(FileData *fd, bGPdata *gpd)
-{
- bGPDlayer *gpl;
- bGPDframe *gpf;
- bGPDstroke *gps;
- bGPDpalette *palette;
-
- /* we must firstly have some grease-pencil data to link! */
- if (gpd == NULL)
- return;
- /* relink animdata */
- gpd->adt = newdataadr(fd, gpd->adt);
- direct_link_animdata(fd, gpd->adt);
-
- /* relink palettes */
- link_list(fd, &gpd->palettes);
- for (palette = gpd->palettes.first; palette; palette = palette->next) {
- link_list(fd, &palette->colors);
- }
-
- /* relink layers */
- link_list(fd, &gpd->layers);
-
- for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- /* parent */
- gpl->parent = newlibadr(fd, gpd->id.lib, gpl->parent);
- /* relink frames */
- link_list(fd, &gpl->frames);
- gpl->actframe = newdataadr(fd, gpl->actframe);
-
- for (gpf = gpl->frames.first; gpf; gpf = gpf->next) {
- /* relink strokes (and their points) */
- link_list(fd, &gpf->strokes);
-
- for (gps = gpf->strokes.first; gps; gps = gps->next) {
- gps->points = newdataadr(fd, gps->points);
-
- /* the triangulation is not saved, so need to be recalculated */
- gps->triangles = NULL;
- gps->tot_triangles = 0;
- gps->flag |= GP_STROKE_RECALC_CACHES;
- /* the color pointer is not saved, so need to be recalculated using the color name */
- gps->palcolor = NULL;
- gps->flag |= GP_STROKE_RECALC_COLOR;
+ for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) {
+ lib_link_area(fd, &wm->id, area);
+ }
}
+
+ wm->id.tag &= ~LIB_TAG_NEED_LINK;
}
}
}
@@ -6411,217 +6955,15 @@ static void lib_link_screen(FileData *fd, Main *main)
IDP_LibLinkProperty(sc->id.properties, fd);
id_us_ensure_real(&sc->id);
+ /* deprecated, but needed for versioning (will be NULL'ed then) */
sc->scene = newlibadr(fd, sc->id.lib, sc->scene);
- /* this should not happen, but apparently it does somehow. Until we figure out the cause,
- * just assign first available scene */
- if (!sc->scene)
- sc->scene = main->scene.first;
-
sc->animtimer = NULL; /* saved in rare cases */
sc->tool_tip = NULL;
sc->scrubbing = false;
- for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
- sa->full = newlibadr(fd, sc->id.lib, sa->full);
-
- for (SpaceLink *sl = sa->spacedata.first; sl; sl= sl->next) {
- switch (sl->spacetype) {
- case SPACE_VIEW3D:
- {
- View3D *v3d = (View3D*) sl;
- BGpic *bgpic = NULL;
-
- v3d->camera= newlibadr(fd, sc->id.lib, v3d->camera);
- v3d->ob_centre= newlibadr(fd, sc->id.lib, v3d->ob_centre);
-
- /* should be do_versions but not easy adding into the listbase */
- if (v3d->bgpic) {
- v3d->bgpic = newlibadr(fd, sc->id.lib, v3d->bgpic);
- BLI_addtail(&v3d->bgpicbase, bgpic);
- v3d->bgpic = NULL;
- }
-
- for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- bgpic->ima = newlibadr_us(fd, sc->id.lib, bgpic->ima);
- bgpic->clip = newlibadr_us(fd, sc->id.lib, bgpic->clip);
- }
- if (v3d->localvd) {
- v3d->localvd->camera = newlibadr(fd, sc->id.lib, v3d->localvd->camera);
- }
- break;
- }
- case SPACE_IPO:
- {
- SpaceIpo *sipo = (SpaceIpo *)sl;
- bDopeSheet *ads = sipo->ads;
-
- if (ads) {
- ads->source = newlibadr(fd, sc->id.lib, ads->source);
- ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp);
- }
- break;
- }
- case SPACE_BUTS:
- {
- SpaceButs *sbuts = (SpaceButs *)sl;
- sbuts->pinid = newlibadr(fd, sc->id.lib, sbuts->pinid);
- if (sbuts->pinid == NULL) {
- sbuts->flag &= ~SB_PIN_CONTEXT;
- }
- break;
- }
- case SPACE_FILE:
- break;
- case SPACE_ACTION:
- {
- SpaceAction *saction = (SpaceAction *)sl;
- bDopeSheet *ads = &saction->ads;
-
- if (ads) {
- ads->source = newlibadr(fd, sc->id.lib, ads->source);
- ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp);
- }
-
- saction->action = newlibadr(fd, sc->id.lib, saction->action);
- break;
- }
- case SPACE_IMAGE:
- {
- SpaceImage *sima = (SpaceImage *)sl;
-
- sima->image = newlibadr_real_us(fd, sc->id.lib, sima->image);
- sima->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sima->mask_info.mask);
-
- /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
- * so fingers crossed this works fine!
- */
- sima->gpd = newlibadr_us(fd, sc->id.lib, sima->gpd);
- break;
- }
- case SPACE_SEQ:
- {
- SpaceSeq *sseq = (SpaceSeq *)sl;
-
- /* NOTE: pre-2.5, this was local data not lib data, but now we need this as lib data
- * so fingers crossed this works fine!
- */
- sseq->gpd = newlibadr_us(fd, sc->id.lib, sseq->gpd);
- break;
- }
- case SPACE_NLA:
- {
- SpaceNla *snla= (SpaceNla *)sl;
- bDopeSheet *ads= snla->ads;
-
- if (ads) {
- ads->source = newlibadr(fd, sc->id.lib, ads->source);
- ads->filter_grp = newlibadr(fd, sc->id.lib, ads->filter_grp);
- }
- break;
- }
- case SPACE_TEXT:
- {
- SpaceText *st= (SpaceText *)sl;
-
- st->text= newlibadr(fd, sc->id.lib, st->text);
- break;
- }
- case SPACE_SCRIPT:
- {
- SpaceScript *scpt = (SpaceScript *)sl;
- /*scpt->script = NULL; - 2.45 set to null, better re-run the script */
- if (scpt->script) {
- scpt->script = newlibadr(fd, sc->id.lib, scpt->script);
- if (scpt->script) {
- SCRIPT_SET_NULL(scpt->script);
- }
- }
- break;
- }
- case SPACE_OUTLINER:
- {
- SpaceOops *so= (SpaceOops *)sl;
- so->search_tse.id = newlibadr(fd, NULL, so->search_tse.id);
-
- if (so->treestore) {
- TreeStoreElem *tselem;
- BLI_mempool_iter iter;
-
- BLI_mempool_iternew(so->treestore, &iter);
- while ((tselem = BLI_mempool_iterstep(&iter))) {
- tselem->id = newlibadr(fd, NULL, tselem->id);
- }
- if (so->treehash) {
- /* rebuild hash table, because it depends on ids too */
- so->storeflag |= SO_TREESTORE_REBUILD;
- }
- }
- break;
- }
- case SPACE_NODE:
- {
- SpaceNode *snode = (SpaceNode *)sl;
- bNodeTreePath *path, *path_next;
- bNodeTree *ntree;
-
- /* node tree can be stored locally in id too, link this first */
- snode->id = newlibadr(fd, sc->id.lib, snode->id);
- snode->from = newlibadr(fd, sc->id.lib, snode->from);
-
- ntree = snode->id ? ntreeFromID(snode->id) : NULL;
- snode->nodetree = ntree ? ntree : newlibadr_us(fd, sc->id.lib, snode->nodetree);
-
- for (path = snode->treepath.first; path; path = path->next) {
- if (path == snode->treepath.first) {
- /* first nodetree in path is same as snode->nodetree */
- path->nodetree = snode->nodetree;
- }
- else
- path->nodetree = newlibadr_us(fd, sc->id.lib, path->nodetree);
-
- if (!path->nodetree)
- break;
- }
-
- /* remaining path entries are invalid, remove */
- for (; path; path = path_next) {
- path_next = path->next;
-
- BLI_remlink(&snode->treepath, path);
- MEM_freeN(path);
- }
-
- /* edittree is just the last in the path,
- * set this directly since the path may have been shortened above */
- if (snode->treepath.last) {
- path = snode->treepath.last;
- snode->edittree = path->nodetree;
- }
- else {
- snode->edittree = NULL;
- }
- break;
- }
- case SPACE_CLIP:
- {
- SpaceClip *sclip = (SpaceClip *)sl;
-
- sclip->clip = newlibadr_real_us(fd, sc->id.lib, sclip->clip);
- sclip->mask_info.mask = newlibadr_real_us(fd, sc->id.lib, sclip->mask_info.mask);
- break;
- }
- case SPACE_LOGIC:
- {
- SpaceLogic *slogic = (SpaceLogic *)sl;
-
- slogic->gpd = newlibadr_us(fd, sc->id.lib, slogic->gpd);
- break;
- }
- default:
- break;
- }
- }
+ for (ScrArea *area = sc->areabase.first; area; area = area->next) {
+ lib_link_area(fd, &sc->id, area);
}
sc->id.tag &= ~LIB_TAG_NEED_LINK;
}
@@ -6726,88 +7068,60 @@ static void lib_link_clipboard_restore(struct IDNameLib_Map *id_map)
BKE_sequencer_base_recursive_apply(&seqbase_clipboard, lib_link_seq_clipboard_cb, id_map);
}
-/* called from kernel/blender.c */
-/* used to link a file (without UI) to the current UI */
-/* note that it assumes the old pointers in UI are still valid, so old Main is not freed */
-void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *curscene)
+static void lib_link_workspace_scene_data_restore(wmWindow *win, Scene *scene)
{
- wmWindow *win;
- wmWindowManager *wm;
- bScreen *sc;
- ScrArea *sa;
+ bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
- struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain);
+ for (ScrArea *area = screen->areabase.first; area; area = area->next) {
+ for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
- /* first windowmanager */
- for (wm = newmain->wm.first; wm; wm = wm->id.next) {
- for (win= wm->windows.first; win; win= win->next) {
- win->screen = restore_pointer_by_name(id_map, (ID *)win->screen, USER_REAL);
-
- if (win->screen == NULL)
- win->screen = curscreen;
-
- win->screen->winid = win->winid;
+ if (v3d->camera == NULL || v3d->scenelock) {
+ v3d->camera = scene->camera;
+ }
+
+ if (v3d->localvd) {
+ /*Base *base;*/
+
+ v3d->localvd->camera = scene->camera;
+
+ /* localview can become invalid during undo/redo steps, so we exit it when no could be found */
+#if 0 /* XXX regionlocalview ? */
+ for (base= sc->scene->base.first; base; base= base->next) {
+ if (base->lay & v3d->lay) break;
+ }
+ if (base==NULL) {
+ v3d->lay= v3d->localvd->lay;
+ v3d->layact= v3d->localvd->layact;
+ MEM_freeN(v3d->localvd);
+ v3d->localvd= NULL;
+ }
+#endif
+ }
+ else if (v3d->scenelock) {
+ v3d->lay = scene->lay;
+ }
+ }
}
}
-
-
- for (sc = newmain->screen.first; sc; sc = sc->id.next) {
- Scene *oldscene = sc->scene;
-
- sc->scene= restore_pointer_by_name(id_map, (ID *)sc->scene, USER_REAL);
- if (sc->scene == NULL)
- sc->scene = curscene;
-
- /* keep cursor location through undo */
- copy_v3_v3(sc->scene->cursor, oldscene->cursor);
-
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl;
-
- for (sl = sa->spacedata.first; sl; sl = sl->next) {
+}
+
+static void lib_link_workspace_layout_restore(struct IDNameLib_Map *id_map, Main *newmain, WorkSpaceLayout *layout)
+{
+ bScreen *screen = BKE_workspace_layout_screen_get(layout);
+
+ /* avoid conflicts with 2.8x branch */
+ {
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
- BGpic *bgpic;
ARegion *ar;
- if (v3d->scenelock)
- v3d->camera = NULL; /* always get from scene */
- else
- v3d->camera = restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL);
- if (v3d->camera == NULL)
- v3d->camera = sc->scene->camera;
+ v3d->camera = restore_pointer_by_name(id_map, (ID *)v3d->camera, USER_REAL);
v3d->ob_centre = restore_pointer_by_name(id_map, (ID *)v3d->ob_centre, USER_REAL);
-
- for (bgpic= v3d->bgpicbase.first; bgpic; bgpic= bgpic->next) {
- if ((bgpic->ima = restore_pointer_by_name(id_map, (ID *)bgpic->ima, USER_IGNORE))) {
- id_us_plus((ID *)bgpic->ima);
- }
- if ((bgpic->clip = restore_pointer_by_name(id_map, (ID *)bgpic->clip, USER_IGNORE))) {
- id_us_plus((ID *)bgpic->clip);
- }
- }
- if (v3d->localvd) {
- /*Base *base;*/
-
- v3d->localvd->camera = sc->scene->camera;
-
- /* localview can become invalid during undo/redo steps, so we exit it when no could be found */
-#if 0 /* XXX regionlocalview ? */
- for (base= sc->scene->base.first; base; base= base->next) {
- if (base->lay & v3d->lay) break;
- }
- if (base==NULL) {
- v3d->lay= v3d->localvd->lay;
- v3d->layact= v3d->localvd->layact;
- MEM_freeN(v3d->localvd);
- v3d->localvd= NULL;
- }
-#endif
- }
- else if (v3d->scenelock) {
- v3d->lay = sc->scene->lay;
- }
-
+
/* not very nice, but could help */
if ((v3d->layact & v3d->lay) == 0) v3d->layact = v3d->lay;
@@ -7001,85 +7315,52 @@ void blo_lib_link_screen_restore(Main *newmain, bScreen *curscreen, Scene *cursc
sclip->scopes.ok = 0;
}
- else if (sl->spacetype == SPACE_LOGIC) {
- SpaceLogic *slogic = (SpaceLogic *)sl;
-
- slogic->gpd = restore_pointer_by_name(id_map, (ID *)slogic->gpd, USER_REAL);
- }
}
}
}
-
- /* update IDs stored in all possible clipboards */
- lib_link_clipboard_restore(id_map);
-
- BKE_main_idmap_destroy(id_map);
}
-static void direct_link_region(FileData *fd, ARegion *ar, int spacetype)
+/**
+ * Used to link a file (without UI) to the current UI.
+ * Note that it assumes the old pointers in UI are still valid, so old Main is not freed.
+ */
+void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene, ViewLayer *cur_view_layer)
{
- Panel *pa;
- uiList *ui_list;
+ struct IDNameLib_Map *id_map = BKE_main_idmap_create(newmain);
- link_list(fd, &ar->panels);
+ for (WorkSpace *workspace = newmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ ListBase *layouts = BKE_workspace_layouts_get(workspace);
- for (pa = ar->panels.first; pa; pa = pa->next) {
- pa->paneltab = newdataadr(fd, pa->paneltab);
- pa->runtime_flag = 0;
- pa->activedata = NULL;
- pa->type = NULL;
+ for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) {
+ lib_link_workspace_layout_restore(id_map, newmain, layout);
+ }
+ BKE_workspace_view_layer_set(workspace, cur_view_layer, curscene);
}
- link_list(fd, &ar->panels_category_active);
-
- link_list(fd, &ar->ui_lists);
+ for (wmWindow *win = curwm->windows.first; win; win = win->next) {
+ WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+ ID *workspace_id = (ID *)workspace;
+ Scene *oldscene = win->scene;
- for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
- ui_list->type = NULL;
- ui_list->dyn_data = NULL;
- ui_list->properties = newdataadr(fd, ui_list->properties);
- IDP_DirectLinkGroup_OrFree(&ui_list->properties, (fd->flags & FD_FLAGS_SWITCH_ENDIAN), fd);
- }
+ workspace = restore_pointer_by_name(id_map, workspace_id, USER_REAL);
+ BKE_workspace_active_set(win->workspace_hook, workspace);
+ win->scene = restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL);
+ if (win->scene == NULL) {
+ win->scene = curscene;
+ }
+ BKE_workspace_active_set(win->workspace_hook, workspace);
- link_list(fd, &ar->ui_previews);
+ /* keep cursor location through undo */
+ copy_v3_v3(win->scene->cursor, oldscene->cursor);
+ lib_link_workspace_scene_data_restore(win, win->scene);
- if (spacetype == SPACE_EMPTY) {
- /* unkown space type, don't leak regiondata */
- ar->regiondata = NULL;
+ BLI_assert(win->screen == NULL);
}
- else {
- ar->regiondata = newdataadr(fd, ar->regiondata);
- if (ar->regiondata) {
- if (spacetype == SPACE_VIEW3D) {
- RegionView3D *rv3d = ar->regiondata;
- rv3d->localvd = newdataadr(fd, rv3d->localvd);
- rv3d->clipbb = newdataadr(fd, rv3d->clipbb);
+ /* update IDs stored in all possible clipboards */
+ lib_link_clipboard_restore(id_map);
- rv3d->depths = NULL;
- rv3d->gpuoffscreen = NULL;
- rv3d->render_engine = NULL;
- rv3d->sms = NULL;
- rv3d->smooth_timer = NULL;
- rv3d->compositor = NULL;
- }
- }
- }
-
- ar->v2d.tab_offset = NULL;
- ar->v2d.tab_num = 0;
- ar->v2d.tab_cur = 0;
- ar->v2d.sms = NULL;
- BLI_listbase_clear(&ar->panels_category);
- BLI_listbase_clear(&ar->handlers);
- BLI_listbase_clear(&ar->uiblocks);
- ar->headerstr = NULL;
- ar->swinid = 0;
- ar->type = NULL;
- ar->swap = 0;
- ar->do_draw = 0;
- ar->regiontimer = NULL;
- memset(&ar->drawrct, 0, sizeof(ar->drawrct));
+ BKE_main_idmap_destroy(id_map);
}
/* for the saved 2.50 files without regiondata */
@@ -7102,310 +7383,25 @@ void blo_do_versions_view3d_split_250(View3D *v3d, ListBase *regions)
}
/* this was not initialized correct always */
- if (v3d->twtype == 0)
- v3d->twtype = V3D_MANIP_TRANSLATE;
if (v3d->gridsubdiv == 0)
v3d->gridsubdiv = 10;
}
static bool direct_link_screen(FileData *fd, bScreen *sc)
{
- ScrArea *sa;
- ScrVert *sv;
- ScrEdge *se;
bool wrong_id = false;
- link_list(fd, &(sc->vertbase));
- link_list(fd, &(sc->edgebase));
- link_list(fd, &(sc->areabase));
sc->regionbase.first = sc->regionbase.last= NULL;
sc->context = NULL;
-
- sc->mainwin = sc->subwinactive= 0; /* indices */
- sc->swap = 0;
-
- /* edges */
- for (se = sc->edgebase.first; se; se = se->next) {
- se->v1 = newdataadr(fd, se->v1);
- se->v2 = newdataadr(fd, se->v2);
- if ((intptr_t)se->v1 > (intptr_t)se->v2) {
- sv = se->v1;
- se->v1 = se->v2;
- se->v2 = sv;
- }
-
- if (se->v1 == NULL) {
- printf("Error reading Screen %s... removing it.\n", sc->id.name+2);
- BLI_remlink(&sc->edgebase, se);
- wrong_id = true;
- }
- }
-
- /* areas */
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl;
- ARegion *ar;
-
- link_list(fd, &(sa->spacedata));
- link_list(fd, &(sa->regionbase));
-
- BLI_listbase_clear(&sa->handlers);
- sa->type = NULL; /* spacetype callbacks */
- sa->region_active_win = -1;
-
- /* if we do not have the spacetype registered (game player), we cannot
- * free it, so don't allocate any new memory for such spacetypes. */
- if (!BKE_spacetype_exists(sa->spacetype))
- sa->spacetype = SPACE_EMPTY;
-
- for (ar = sa->regionbase.first; ar; ar = ar->next)
- direct_link_region(fd, ar, sa->spacetype);
-
- /* accident can happen when read/save new file with older version */
- /* 2.50: we now always add spacedata for info */
- if (sa->spacedata.first==NULL) {
- SpaceInfo *sinfo= MEM_callocN(sizeof(SpaceInfo), "spaceinfo");
- sa->spacetype= sinfo->spacetype= SPACE_INFO;
- BLI_addtail(&sa->spacedata, sinfo);
- }
- /* add local view3d too */
- else if (sa->spacetype == SPACE_VIEW3D)
- blo_do_versions_view3d_split_250(sa->spacedata.first, &sa->regionbase);
-
- /* incase we set above */
- sa->butspacetype = sa->spacetype;
-
- for (sl = sa->spacedata.first; sl; sl = sl->next) {
- link_list(fd, &(sl->regionbase));
-
- /* if we do not have the spacetype registered (game player), we cannot
- * free it, so don't allocate any new memory for such spacetypes. */
- if (!BKE_spacetype_exists(sl->spacetype))
- sl->spacetype = SPACE_EMPTY;
+ sc->active_region = NULL;
- for (ar = sl->regionbase.first; ar; ar = ar->next)
- direct_link_region(fd, ar, sl->spacetype);
-
- if (sl->spacetype == SPACE_VIEW3D) {
- View3D *v3d= (View3D*) sl;
- BGpic *bgpic;
-
- v3d->flag |= V3D_INVALID_BACKBUF;
-
- link_list(fd, &v3d->bgpicbase);
-
- /* should be do_versions except this doesnt fit well there */
- if (v3d->bgpic) {
- bgpic = newdataadr(fd, v3d->bgpic);
- BLI_addtail(&v3d->bgpicbase, bgpic);
- v3d->bgpic = NULL;
- }
-
- for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next)
- bgpic->iuser.ok = 1;
-
- if (v3d->gpd) {
- v3d->gpd = newdataadr(fd, v3d->gpd);
- direct_link_gpencil(fd, v3d->gpd);
- }
- v3d->localvd = newdataadr(fd, v3d->localvd);
- BLI_listbase_clear(&v3d->afterdraw_transp);
- BLI_listbase_clear(&v3d->afterdraw_xray);
- BLI_listbase_clear(&v3d->afterdraw_xraytransp);
- v3d->properties_storage = NULL;
- v3d->defmaterial = NULL;
-
- /* render can be quite heavy, set to solid on load */
- if (v3d->drawtype == OB_RENDER)
- v3d->drawtype = OB_SOLID;
- v3d->prev_drawtype = OB_SOLID;
-
- if (v3d->fx_settings.dof)
- v3d->fx_settings.dof = newdataadr(fd, v3d->fx_settings.dof);
- if (v3d->fx_settings.ssao)
- v3d->fx_settings.ssao = newdataadr(fd, v3d->fx_settings.ssao);
-
- blo_do_versions_view3d_split_250(v3d, &sl->regionbase);
- }
- else if (sl->spacetype == SPACE_IPO) {
- SpaceIpo *sipo = (SpaceIpo *)sl;
-
- sipo->ads = newdataadr(fd, sipo->ads);
- BLI_listbase_clear(&sipo->ghostCurves);
- }
- else if (sl->spacetype == SPACE_NLA) {
- SpaceNla *snla = (SpaceNla *)sl;
-
- snla->ads = newdataadr(fd, snla->ads);
- }
- else if (sl->spacetype == SPACE_OUTLINER) {
- SpaceOops *soops = (SpaceOops *) sl;
-
- /* use newdataadr_no_us and do not free old memory avoiding double
- * frees and use of freed memory. this could happen because of a
- * bug fixed in revision 58959 where the treestore memory address
- * was not unique */
- TreeStore *ts = newdataadr_no_us(fd, soops->treestore);
- soops->treestore = NULL;
- if (ts) {
- TreeStoreElem *elems = newdataadr_no_us(fd, ts->data);
-
- soops->treestore = BLI_mempool_create(sizeof(TreeStoreElem), ts->usedelem,
- 512, BLI_MEMPOOL_ALLOW_ITER);
- if (ts->usedelem && elems) {
- int i;
- for (i = 0; i < ts->usedelem; i++) {
- TreeStoreElem *new_elem = BLI_mempool_alloc(soops->treestore);
- *new_elem = elems[i];
- }
- }
- /* we only saved what was used */
- soops->storeflag |= SO_TREESTORE_CLEANUP; // at first draw
- }
- soops->treehash = NULL;
- soops->tree.first = soops->tree.last= NULL;
- }
- else if (sl->spacetype == SPACE_IMAGE) {
- SpaceImage *sima = (SpaceImage *)sl;
+ sc->preview = direct_link_preview_image(fd, sc->preview);
- sima->iuser.scene = NULL;
- sima->iuser.ok = 1;
- sima->scopes.waveform_1 = NULL;
- sima->scopes.waveform_2 = NULL;
- sima->scopes.waveform_3 = NULL;
- sima->scopes.vecscope = NULL;
- sima->scopes.ok = 0;
-
- /* WARNING: gpencil data is no longer stored directly in sima after 2.5
- * so sacrifice a few old files for now to avoid crashes with new files!
- * committed: r28002 */
-#if 0
- sima->gpd = newdataadr(fd, sima->gpd);
- if (sima->gpd)
- direct_link_gpencil(fd, sima->gpd);
-#endif
- }
- else if (sl->spacetype == SPACE_NODE) {
- SpaceNode *snode = (SpaceNode *)sl;
-
- if (snode->gpd) {
- snode->gpd = newdataadr(fd, snode->gpd);
- direct_link_gpencil(fd, snode->gpd);
- }
-
- link_list(fd, &snode->treepath);
- snode->edittree = NULL;
- snode->iofsd = NULL;
- BLI_listbase_clear(&snode->linkdrag);
- }
- else if (sl->spacetype == SPACE_TEXT) {
- SpaceText *st= (SpaceText *)sl;
-
- st->drawcache = NULL;
- st->scroll_accum[0] = 0.0f;
- st->scroll_accum[1] = 0.0f;
- }
- else if (sl->spacetype == SPACE_TIME) {
- SpaceTime *stime = (SpaceTime *)sl;
- BLI_listbase_clear(&stime->caches);
- }
- else if (sl->spacetype == SPACE_LOGIC) {
- SpaceLogic *slogic = (SpaceLogic *)sl;
-
- /* XXX: this is new stuff, which shouldn't be directly linking to gpd... */
- if (slogic->gpd) {
- slogic->gpd = newdataadr(fd, slogic->gpd);
- direct_link_gpencil(fd, slogic->gpd);
- }
- }
- else if (sl->spacetype == SPACE_SEQ) {
- SpaceSeq *sseq = (SpaceSeq *)sl;
-
- /* grease pencil data is not a direct data and can't be linked from direct_link*
- * functions, it should be linked from lib_link* functions instead
- *
- * otherwise it'll lead to lost grease data on open because it'll likely be
- * read from file after all other users of grease pencil and newdataadr would
- * simple return NULL here (sergey)
- */
-#if 0
- if (sseq->gpd) {
- sseq->gpd = newdataadr(fd, sseq->gpd);
- direct_link_gpencil(fd, sseq->gpd);
- }
-#endif
- sseq->scopes.reference_ibuf = NULL;
- sseq->scopes.zebra_ibuf = NULL;
- sseq->scopes.waveform_ibuf = NULL;
- sseq->scopes.sep_waveform_ibuf = NULL;
- sseq->scopes.vector_ibuf = NULL;
- sseq->scopes.histogram_ibuf = NULL;
- sseq->compositor = NULL;
- }
- else if (sl->spacetype == SPACE_BUTS) {
- SpaceButs *sbuts = (SpaceButs *)sl;
-
- sbuts->path= NULL;
- sbuts->texuser= NULL;
- sbuts->mainbo = sbuts->mainb;
- sbuts->mainbuser = sbuts->mainb;
- }
- else if (sl->spacetype == SPACE_CONSOLE) {
- SpaceConsole *sconsole = (SpaceConsole *)sl;
- ConsoleLine *cl, *cl_next;
-
- link_list(fd, &sconsole->scrollback);
- link_list(fd, &sconsole->history);
-
- //for (cl= sconsole->scrollback.first; cl; cl= cl->next)
- // cl->line= newdataadr(fd, cl->line);
-
- /* comma expressions, (e.g. expr1, expr2, expr3) evaluate each expression,
- * from left to right. the right-most expression sets the result of the comma
- * expression as a whole*/
- for (cl = sconsole->history.first; cl; cl = cl_next) {
- cl_next = cl->next;
- cl->line = newdataadr(fd, cl->line);
- if (cl->line) {
- /* the allocted length is not written, so reset here */
- cl->len_alloc = cl->len + 1;
- }
- else {
- BLI_remlink(&sconsole->history, cl);
- MEM_freeN(cl);
- }
- }
- }
- else if (sl->spacetype == SPACE_FILE) {
- SpaceFile *sfile = (SpaceFile *)sl;
-
- /* this sort of info is probably irrelevant for reloading...
- * plus, it isn't saved to files yet!
- */
- sfile->folders_prev = sfile->folders_next = NULL;
- sfile->files = NULL;
- sfile->layout = NULL;
- sfile->op = NULL;
- sfile->previews_timer = NULL;
- sfile->params = newdataadr(fd, sfile->params);
- }
- else if (sl->spacetype == SPACE_CLIP) {
- SpaceClip *sclip = (SpaceClip *)sl;
-
- sclip->scopes.track_search = NULL;
- sclip->scopes.track_preview = NULL;
- sclip->scopes.ok = 0;
- }
- }
-
- BLI_listbase_clear(&sa->actionzones);
-
- sa->v1 = newdataadr(fd, sa->v1);
- sa->v2 = newdataadr(fd, sa->v2);
- sa->v3 = newdataadr(fd, sa->v3);
- sa->v4 = newdataadr(fd, sa->v4);
+ if (!direct_link_area_map(fd, AREAMAP_FROM_SCREEN(sc))) {
+ printf("Error reading Screen %s... removing it.\n", sc->id.name + 2);
+ wrong_id = true;
}
-
+
return wrong_id;
}
@@ -7497,6 +7493,28 @@ static void fix_relpaths_library(const char *basepath, Main *main)
}
}
+/* ************ READ PROBE ***************** */
+
+static void lib_link_lightprobe(FileData *fd, Main *main)
+{
+ for (LightProbe *prb = main->lightprobe.first; prb; prb = prb->id.next) {
+ if (prb->id.tag & LIB_TAG_NEED_LINK) {
+ IDP_LibLinkProperty(prb->id.properties, fd);
+ lib_link_animdata(fd, &prb->id, prb->adt);
+
+ prb->visibility_grp = newlibadr(fd, prb->id.lib, prb->visibility_grp);
+
+ prb->id.tag &= ~LIB_TAG_NEED_LINK;
+ }
+ }
+}
+
+static void direct_link_lightprobe(FileData *fd, LightProbe *prb)
+{
+ prb->adt = newdataadr(fd, prb->adt);
+ direct_link_animdata(fd, prb->adt);
+}
+
/* ************ READ SPEAKER ***************** */
static void lib_link_speaker(FileData *fd, Main *main)
@@ -7576,30 +7594,61 @@ static void direct_link_group(FileData *fd, Group *group)
link_list(fd, &group->gobject);
group->preview = direct_link_preview_image(fd, group->preview);
+
+ /* This runs before the very first doversion. */
+ if (group->collection != NULL) {
+ group->collection = newdataadr(fd, group->collection);
+ direct_link_scene_collection(fd, group->collection);
+ }
+
+ if (group->view_layer != NULL) {
+ group->view_layer = newdataadr(fd, group->view_layer);
+ direct_link_view_layer(fd, group->view_layer);
+ }
}
static void lib_link_group(FileData *fd, Main *main)
{
for (Group *group = main->group.first; group; group = group->id.next) {
if (group->id.tag & LIB_TAG_NEED_LINK) {
+ group->id.tag &= ~LIB_TAG_NEED_LINK;
IDP_LibLinkProperty(group->id.properties, fd);
-
- bool add_us = false;
-
- for (GroupObject *go = group->gobject.first; go; go = go->next) {
- go->ob = newlibadr_real_us(fd, group->id.lib, go->ob);
- if (go->ob) {
- go->ob->flag |= OB_FROMGROUP;
- /* if group has an object, it increments user... */
- add_us = true;
+
+ if (group->view_layer == NULL) {
+ /* Old file, this is required for doversion. */
+ bool add_us = false;
+
+ GroupObject *go, *gon;
+ go = group->gobject.first;
+ while (go) {
+ gon = go->next;
+ go->ob = newlibadr_real_us(fd, group->id.lib, go->ob);
+ if (go->ob != NULL) {
+ go->ob->flag |= OB_FROMGROUP;
+ /* If group has an object, it increments user... */
+ add_us = true;
+ }
+ else {
+ /* Remove NULL objects. */
+ BLI_remlink(&group->gobject, go);
+ MEM_freeN(go);
+ }
+ go = gon;
+ }
+
+ if (add_us) {
+ id_us_ensure_real(&group->id);
}
+ /* The rest of the read code is only for new files, skip it. */
+ continue;
}
- if (add_us) {
+
+ lib_link_scene_collection(fd, group->id.lib, group->collection);
+ lib_link_view_layer(fd, group->id.lib, group->view_layer);
+
+ if (!BLI_listbase_is_empty(&group->view_layer->object_bases)) {
id_us_ensure_real(&group->id);
}
- BKE_group_object_unlink(group, NULL, NULL, NULL); /* removes NULL entries */
-
- group->id.tag &= ~LIB_TAG_NEED_LINK;
}
}
}
@@ -8112,6 +8161,7 @@ static const char *dataname(short id_code)
case ID_VF: return "Data from VF";
case ID_TXT: return "Data from TXT";
case ID_SPK: return "Data from SPK";
+ case ID_LP: return "Data from LP";
case ID_SO: return "Data from SO";
case ID_NT: return "Data from NT";
case ID_BR: return "Data from BR";
@@ -8124,6 +8174,7 @@ static const char *dataname(short id_code)
case ID_MSK: return "Data from MSK";
case ID_LS: return "Data from LS";
case ID_CF: return "Data from CF";
+ case ID_WS: return "Data from WS";
}
return "Data from Lib Block";
@@ -8246,6 +8297,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
id->us = ID_FAKE_USERS(id);
id->icon_id = 0;
id->newid = NULL; /* Needed because .blend may have been saved with crap value here... */
+ id->orig_id = NULL;
id->recalc = 0;
/* this case cannot be direct_linked: it's just the ID part */
@@ -8277,7 +8329,7 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
wrong_id = direct_link_screen(fd, (bScreen *)id);
break;
case ID_SCE:
- direct_link_scene(fd, (Scene *)id);
+ direct_link_scene(fd, (Scene *)id, main);
break;
case ID_OB:
direct_link_object(fd, (Object *)id);
@@ -8333,6 +8385,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
case ID_SO:
direct_link_sound(fd, (bSound *)id);
break;
+ case ID_LP:
+ direct_link_lightprobe(fd, (LightProbe *)id);
+ break;
case ID_GR:
direct_link_group(fd, (Group *)id);
break;
@@ -8372,6 +8427,9 @@ static BHead *read_libblock(FileData *fd, Main *main, BHead *bhead, const short
case ID_CF:
direct_link_cachefile(fd, (CacheFile *)id);
break;
+ case ID_WS:
+ direct_link_workspace(fd, (WorkSpace *)id, main);
+ break;
}
oldnewmap_free_unused(fd->datamap);
@@ -8417,7 +8475,8 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)
bfd->curscreen = fg->curscreen;
bfd->curscene = fg->curscene;
-
+ bfd->cur_view_layer = fg->cur_view_layer;
+
MEM_freeN(fg);
fd->globalf = bfd->globalf;
@@ -8429,6 +8488,7 @@ static BHead *read_global(BlendFileData *bfd, FileData *fd, BHead *bhead)
/* note, this has to be kept for reading older files... */
static void link_global(FileData *fd, BlendFileData *bfd)
{
+ bfd->cur_view_layer = newglobadr(fd, bfd->cur_view_layer);
bfd->curscreen = newlibadr(fd, NULL, bfd->curscreen);
bfd->curscene = newlibadr(fd, NULL, bfd->curscene);
// this happens in files older than 2.35
@@ -8437,26 +8497,6 @@ static void link_global(FileData *fd, BlendFileData *bfd)
}
}
-static void convert_tface_mt(FileData *fd, Main *main)
-{
- Main *gmain;
-
- /* this is a delayed do_version (so it can create new materials) */
- if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 3)) {
- //XXX hack, material.c uses G.main all over the place, instead of main
- // temporarily set G.main to the current main
- gmain = G.main;
- G.main = main;
-
- if (!(do_version_tface(main))) {
- BKE_report(fd->reports, RPT_WARNING, "Texface conversion problem (see error in console)");
- }
-
- //XXX hack, material.c uses G.main allover the place, instead of main
- G.main = gmain;
- }
-}
-
/* initialize userdef with non-UI dependency stuff */
/* other initializers (such as theme color defaults) go to resources.c */
static void do_versions_userdef(FileData *fd, BlendFileData *bfd)
@@ -8510,6 +8550,7 @@ static void do_versions(FileData *fd, Library *lib, Main *main)
blo_do_versions_250(fd, lib, main);
blo_do_versions_260(fd, lib, main);
blo_do_versions_270(fd, lib, main);
+ blo_do_versions_280(fd, lib, main);
/* WATCH IT!!!: pointers from libdata have not been converted yet here! */
/* WATCH IT 2!: Userdef struct init see do_versions_userdef() above! */
@@ -8523,12 +8564,15 @@ static void do_versions_after_linking(Main *main)
// main->curlib ? "LIB" : "MAIN", main->versionfile, main->subversionfile);
do_versions_after_linking_270(main);
+ do_versions_after_linking_280(main);
}
static void lib_link_all(FileData *fd, Main *main)
{
oldnewmap_sort(fd);
+ lib_link_id(fd, main);
+
/* No load UI for undo memfiles */
if (fd->memfile == NULL) {
lib_link_windowmanager(fd, main);
@@ -8551,6 +8595,7 @@ static void lib_link_all(FileData *fd, Main *main)
lib_link_text(fd, main);
lib_link_camera(fd, main);
lib_link_speaker(fd, main);
+ lib_link_lightprobe(fd, main);
lib_link_sound(fd, main);
lib_link_group(fd, main);
lib_link_armature(fd, main);
@@ -8566,6 +8611,7 @@ static void lib_link_all(FileData *fd, Main *main)
lib_link_linestyle(fd, main);
lib_link_gpencil(fd, main);
lib_link_cachefiles(fd, main);
+ lib_link_workspaces(fd, main);
lib_link_library(fd, main); /* only init users */
}
@@ -8758,6 +8804,12 @@ BlendFileData *blo_read_file_internal(FileData *fd, const char *filepath)
BKE_main_id_tag_all(bfd->main, LIB_TAG_NEW, false);
+ /* Now that all our data-blocks are loaded, we can re-generate overrides from their references. */
+ if (fd->memfile == NULL) {
+ /* Do not apply in undo case! */
+ BKE_main_override_static_update(bfd->main);
+ }
+
lib_verify_nodetree(bfd->main, true);
fix_relpaths_library(fd->relabase, bfd->main); /* make all relative paths, relative to the open blend file */
@@ -8958,6 +9010,11 @@ static void expand_doit_library(void *fdhandle, Main *mainvar, void *old)
}
}
else {
+ /* in 2.50+ file identifier for screens is patched, forward compatibility */
+ if (bhead->code == ID_SCRN) {
+ bhead->code = ID_SCR;
+ }
+
id = is_yet_read(fd, mainvar, bhead);
if (id == NULL) {
read_libblock(fd, mainvar, bhead, LIB_TAG_TESTIND, NULL);
@@ -9191,6 +9248,11 @@ static void expand_group(FileData *fd, Main *mainvar, Group *group)
for (go = group->gobject.first; go; go = go->next) {
expand_doit(fd, mainvar, go->ob);
}
+
+ if (group->collection != NULL) {
+ expand_scene_collection(fd, mainvar, group->collection);
+ }
+
}
static void expand_key(FileData *fd, Main *mainvar, Key *key)
@@ -9253,15 +9315,6 @@ static void expand_brush(FileData *fd, Main *mainvar, Brush *brush)
static void expand_material(FileData *fd, Main *mainvar, Material *ma)
{
- int a;
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) {
- expand_doit(fd, mainvar, ma->mtex[a]->tex);
- expand_doit(fd, mainvar, ma->mtex[a]->object);
- }
- }
-
expand_doit(fd, mainvar, ma->ipo); // XXX deprecated - old animation system
if (ma->adt)
@@ -9269,22 +9322,10 @@ static void expand_material(FileData *fd, Main *mainvar, Material *ma)
if (ma->nodetree)
expand_nodetree(fd, mainvar, ma->nodetree);
-
- if (ma->group)
- expand_doit(fd, mainvar, ma->group);
}
static void expand_lamp(FileData *fd, Main *mainvar, Lamp *la)
{
- int a;
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (la->mtex[a]) {
- expand_doit(fd, mainvar, la->mtex[a]->tex);
- expand_doit(fd, mainvar, la->mtex[a]->object);
- }
- }
-
expand_doit(fd, mainvar, la->ipo); // XXX deprecated - old animation system
if (la->adt)
@@ -9306,15 +9347,6 @@ static void expand_lattice(FileData *fd, Main *mainvar, Lattice *lt)
static void expand_world(FileData *fd, Main *mainvar, World *wrld)
{
- int a;
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (wrld->mtex[a]) {
- expand_doit(fd, mainvar, wrld->mtex[a]->tex);
- expand_doit(fd, mainvar, wrld->mtex[a]->object);
- }
- }
-
expand_doit(fd, mainvar, wrld->ipo); // XXX deprecated - old animation system
if (wrld->adt)
@@ -9361,9 +9393,7 @@ static void expand_curve(FileData *fd, Main *mainvar, Curve *cu)
static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me)
{
- CustomDataLayer *layer;
- TFace *tf;
- int a, i;
+ int a;
if (me->adt)
expand_animdata(fd, mainvar, me->adt);
@@ -9374,46 +9404,6 @@ static void expand_mesh(FileData *fd, Main *mainvar, Mesh *me)
expand_doit(fd, mainvar, me->key);
expand_doit(fd, mainvar, me->texcomesh);
-
- if (me->tface) {
- tf = me->tface;
- for (i=0; i<me->totface; i++, tf++) {
- if (tf->tpage)
- expand_doit(fd, mainvar, tf->tpage);
- }
- }
-
- if (me->mface && !me->mpoly) {
- MTFace *mtf;
-
- for (a = 0; a < me->fdata.totlayer; a++) {
- layer = &me->fdata.layers[a];
-
- if (layer->type == CD_MTFACE) {
- mtf = (MTFace *) layer->data;
- for (i = 0; i < me->totface; i++, mtf++) {
- if (mtf->tpage)
- expand_doit(fd, mainvar, mtf->tpage);
- }
- }
- }
- }
- else {
- MTexPoly *mtp;
-
- for (a = 0; a < me->pdata.totlayer; a++) {
- layer = &me->pdata.layers[a];
-
- if (layer->type == CD_MTEXPOLY) {
- mtp = (MTexPoly *) layer->data;
-
- for (i = 0; i < me->totpoly; i++, mtp++) {
- if (mtp->tpage)
- expand_doit(fd, mainvar, mtp->tpage);
- }
- }
- }
- }
}
/* temp struct used to transport needed info to expand_constraint_cb() */
@@ -9493,9 +9483,6 @@ static void expand_object_expandModifiers(
static void expand_object(FileData *fd, Main *mainvar, Object *ob)
{
ParticleSystem *psys;
- bSensor *sens;
- bController *cont;
- bActuator *act;
bActionStrip *strip;
PartEff *paf;
int a;
@@ -9552,84 +9539,6 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
for (psys = ob->particlesystem.first; psys; psys = psys->next)
expand_doit(fd, mainvar, psys->part);
- for (sens = ob->sensors.first; sens; sens = sens->next) {
- if (sens->type == SENS_MESSAGE) {
- bMessageSensor *ms = sens->data;
- expand_doit(fd, mainvar, ms->fromObject);
- }
- }
-
- for (cont = ob->controllers.first; cont; cont = cont->next) {
- if (cont->type == CONT_PYTHON) {
- bPythonCont *pc = cont->data;
- expand_doit(fd, mainvar, pc->text);
- }
- }
-
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_SOUND) {
- bSoundActuator *sa = act->data;
- expand_doit(fd, mainvar, sa->sound);
- }
- else if (act->type == ACT_CAMERA) {
- bCameraActuator *ca = act->data;
- expand_doit(fd, mainvar, ca->ob);
- }
- else if (act->type == ACT_EDIT_OBJECT) {
- bEditObjectActuator *eoa = act->data;
- if (eoa) {
- expand_doit(fd, mainvar, eoa->ob);
- expand_doit(fd, mainvar, eoa->me);
- }
- }
- else if (act->type == ACT_OBJECT) {
- bObjectActuator *oa = act->data;
- expand_doit(fd, mainvar, oa->reference);
- }
- else if (act->type == ACT_ADD_OBJECT) {
- bAddObjectActuator *aoa = act->data;
- expand_doit(fd, mainvar, aoa->ob);
- }
- else if (act->type == ACT_SCENE) {
- bSceneActuator *sa = act->data;
- expand_doit(fd, mainvar, sa->camera);
- expand_doit(fd, mainvar, sa->scene);
- }
- else if (act->type == ACT_2DFILTER) {
- bTwoDFilterActuator *tdfa = act->data;
- expand_doit(fd, mainvar, tdfa->text);
- }
- else if (act->type == ACT_ACTION) {
- bActionActuator *aa = act->data;
- expand_doit(fd, mainvar, aa->act);
- }
- else if (act->type == ACT_SHAPEACTION) {
- bActionActuator *aa = act->data;
- expand_doit(fd, mainvar, aa->act);
- }
- else if (act->type == ACT_PROPERTY) {
- bPropertyActuator *pa = act->data;
- expand_doit(fd, mainvar, pa->ob);
- }
- else if (act->type == ACT_MESSAGE) {
- bMessageActuator *ma = act->data;
- expand_doit(fd, mainvar, ma->toObject);
- }
- else if (act->type==ACT_PARENT) {
- bParentActuator *pa = act->data;
- expand_doit(fd, mainvar, pa->ob);
- }
- else if (act->type == ACT_ARMATURE) {
- bArmatureActuator *arma = act->data;
- expand_doit(fd, mainvar, arma->target);
- }
- else if (act->type == ACT_STEERING) {
- bSteeringActuator *sta = act->data;
- expand_doit(fd, mainvar, sta->target);
- expand_doit(fd, mainvar, sta->navmesh);
- }
- }
-
if (ob->pd) {
expand_doit(fd, mainvar, ob->pd->tex);
expand_doit(fd, mainvar, ob->pd->f_source);
@@ -9656,15 +9565,37 @@ static void expand_object(FileData *fd, Main *mainvar, Object *ob)
}
}
+static void expand_scene_collection(FileData *fd, Main *mainvar, SceneCollection *sc)
+{
+ for (LinkData *link = sc->objects.first; link; link = link->next) {
+ expand_doit(fd, mainvar, link->data);
+ }
+
+ for (SceneCollection *nsc= sc->scene_collections.first; nsc; nsc = nsc->next) {
+ expand_scene_collection(fd, mainvar, nsc);
+ }
+}
+
+static void expand_layer_collection(FileData *fd, Main *mainvar, LayerCollection *layer_collection)
+{
+ expand_idprops(fd, mainvar, layer_collection->properties);
+
+ for (LayerCollection *layer_collection_nested = layer_collection->layer_collections.first;
+ layer_collection_nested != NULL;
+ layer_collection_nested = layer_collection_nested->next)
+ {
+ expand_layer_collection(fd, mainvar, layer_collection_nested);
+ }
+}
+
static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
{
- Base *base;
SceneRenderLayer *srl;
FreestyleModuleConfig *module;
FreestyleLineSet *lineset;
- for (base = sce->base.first; base; base = base->next) {
- expand_doit(fd, mainvar, base->object);
+ for (Base *base_legacy = sce->base.first; base_legacy; base_legacy = base_legacy->next) {
+ expand_doit(fd, mainvar, base_legacy->object);
}
expand_doit(fd, mainvar, sce->camera);
expand_doit(fd, mainvar, sce->world);
@@ -9681,7 +9612,6 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
for (srl = sce->r.layers.first; srl; srl = srl->next) {
expand_doit(fd, mainvar, srl->mat_override);
- expand_doit(fd, mainvar, srl->light_override);
for (module = srl->freestyleConfig.modules.first; module; module = module->next) {
if (module->script)
expand_doit(fd, mainvar, module->script);
@@ -9692,10 +9622,32 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
expand_doit(fd, mainvar, lineset->linestyle);
}
}
-
- if (sce->r.dometext)
- expand_doit(fd, mainvar, sce->gm.dome.warptext);
-
+
+ for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ expand_idprops(fd, mainvar, view_layer->properties);
+ expand_idprops(fd, mainvar, view_layer->id_properties);
+
+ for (module = view_layer->freestyle_config.modules.first; module; module = module->next) {
+ if (module->script) {
+ expand_doit(fd, mainvar, module->script);
+ }
+ }
+
+ for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
+ if (lineset->group) {
+ expand_doit(fd, mainvar, lineset->group);
+ }
+ expand_doit(fd, mainvar, lineset->linestyle);
+ }
+
+ for (LayerCollection *layer_collection = view_layer->layer_collections.first;
+ layer_collection != NULL;
+ layer_collection = layer_collection->next)
+ {
+ expand_layer_collection(fd, mainvar, layer_collection);
+ }
+ }
+
if (sce->gpd)
expand_doit(fd, mainvar, sce->gpd);
@@ -9727,6 +9679,8 @@ static void expand_scene(FileData *fd, Main *mainvar, Scene *sce)
}
expand_doit(fd, mainvar, sce->clip);
+
+ expand_scene_collection(fd, mainvar, sce->collection);
}
static void expand_camera(FileData *fd, Main *mainvar, Camera *ca)
@@ -9757,6 +9711,12 @@ static void expand_sound(FileData *fd, Main *mainvar, bSound *snd)
expand_doit(fd, mainvar, snd->ipo); // XXX deprecated - old animation system
}
+static void expand_lightprobe(FileData *fd, Main *mainvar, LightProbe *prb)
+{
+ if (prb->adt)
+ expand_animdata(fd, mainvar, prb->adt);
+}
+
static void expand_movieclip(FileData *fd, Main *mainvar, MovieClip *clip)
{
if (clip->adt)
@@ -9830,6 +9790,15 @@ static void expand_gpencil(FileData *fd, Main *mainvar, bGPdata *gpd)
expand_animdata(fd, mainvar, gpd->adt);
}
+static void expand_workspace(FileData *fd, Main *mainvar, WorkSpace *workspace)
+{
+ ListBase *layouts = BKE_workspace_layouts_get(workspace);
+
+ for (WorkSpaceLayout *layout = layouts->first; layout; layout = layout->next) {
+ expand_doit(fd, mainvar, BKE_workspace_layout_screen_get(layout));
+ }
+}
+
/**
* Set the callback func used over all ID data found by \a BLO_expand_main func.
*
@@ -9908,6 +9877,9 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_SO:
expand_sound(fd, mainvar, (bSound *)id);
break;
+ case ID_LP:
+ expand_lightprobe(fd, mainvar, (LightProbe *)id);
+ break;
case ID_AR:
expand_armature(fd, mainvar, (bArmature *)id);
break;
@@ -9944,6 +9916,8 @@ void BLO_expand_main(void *fdhandle, Main *mainvar)
case ID_CF:
expand_cachefile(fd, mainvar, (CacheFile *)id);
break;
+ case ID_WS:
+ expand_workspace(fd, mainvar, (WorkSpace *)id);
default:
break;
}
@@ -9966,7 +9940,7 @@ static bool object_in_any_scene(Main *mainvar, Object *ob)
Scene *sce;
for (sce = mainvar->scene.first; sce; sce = sce->id.next) {
- if (BKE_scene_base_find(sce, ob)) {
+ if (BKE_scene_object_find(sce, ob)) {
return true;
}
}
@@ -9974,16 +9948,17 @@ static bool object_in_any_scene(Main *mainvar, Object *ob)
return false;
}
-static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Library *lib, const short flag)
+static void give_base_to_objects(
+ Main *mainvar, Scene *scene, ViewLayer *view_layer, Library *lib, const short flag)
{
Object *ob;
Base *base;
- const unsigned int active_lay = (flag & FILE_ACTIVELAY) ? BKE_screen_view3d_layer_active(v3d, scene) : 0;
+ SceneCollection *scene_collection = NULL;
const bool is_link = (flag & FILE_LINK) != 0;
BLI_assert(scene);
- /* give all objects which are LIB_TAG_INDIRECT a base, or for a group when *lib has been set */
+ /* Give all objects which are LIB_TAG_INDIRECT a base, or for a group when *lib has been set. */
for (ob = mainvar->object.first; ob; ob = ob->id.next) {
if ((ob->id.tag & LIB_TAG_INDIRECT) && (ob->id.tag & LIB_TAG_PRE_EXISTING) == 0) {
bool do_it = false;
@@ -9998,26 +9973,26 @@ static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Libra
}
if (do_it) {
- base = MEM_callocN(sizeof(Base), __func__);
- BLI_addtail(&scene->base, base);
+ CLAMP_MIN(ob->id.us, 0);
- if (active_lay) {
- ob->lay = active_lay;
+ if (scene_collection == NULL) {
+ scene_collection = get_scene_collection_active_or_create(scene, view_layer, FILE_ACTIVE_COLLECTION);
}
+
+ BKE_collection_object_add(&scene->id, scene_collection, ob);
+ base = BKE_view_layer_base_find(view_layer, ob);
+ BKE_scene_object_base_flag_sync_from_base(base);
+
if (flag & FILE_AUTOSELECT) {
/* Note that link_object_postprocess() already checks for FILE_AUTOSELECT flag,
* but it will miss objects from non-instantiated groups... */
- ob->flag |= SELECT;
- /* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
+ if (base->flag & BASE_SELECTABLED) {
+ base->flag |= BASE_SELECTED;
+ BKE_scene_object_base_flag_sync_from_base(base);
+ }
+ /* Do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level. */
}
- base->object = ob;
- base->lay = ob->lay;
- base->flag = ob->flag;
-
- CLAMP_MIN(ob->id.us, 0);
- id_us_plus_no_lib((ID *)ob);
-
ob->id.tag &= ~LIB_TAG_INDIRECT;
ob->id.tag |= LIB_TAG_EXTERN;
}
@@ -10026,32 +10001,38 @@ static void give_base_to_objects(Main *mainvar, Scene *scene, View3D *v3d, Libra
}
static void give_base_to_groups(
- Main *mainvar, Scene *scene, View3D *v3d, Library *UNUSED(lib), const short UNUSED(flag))
+ Main *mainvar, Scene *scene, ViewLayer *view_layer, Library *UNUSED(lib), const short UNUSED(flag))
{
Group *group;
Base *base;
Object *ob;
- const unsigned int active_lay = BKE_screen_view3d_layer_active(v3d, scene);
+ SceneCollection *scene_collection;
- /* give all objects which are tagged a base */
+ /* If the group is empty this function is not even called, so it's safe to ensure a collection at this point. */
+ scene_collection = get_scene_collection_active_or_create(scene, view_layer, FILE_ACTIVE_COLLECTION);
+
+ /* Give all objects which are tagged a base. */
for (group = mainvar->group.first; group; group = group->id.next) {
if (group->id.tag & LIB_TAG_DOIT) {
- /* any indirect group should not have been tagged */
+ /* Any indirect group should not have been tagged. */
BLI_assert((group->id.tag & LIB_TAG_INDIRECT) == 0);
- /* BKE_object_add(...) messes with the selection */
+ /* BKE_object_add(...) messes with the selection. */
ob = BKE_object_add_only_object(mainvar, OB_EMPTY, group->id.name + 2);
ob->type = OB_EMPTY;
- ob->lay = active_lay;
- /* assign the base */
- base = BKE_scene_base_add(scene, ob);
- base->flag |= SELECT;
- base->object->flag = base->flag;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
- scene->basact = base;
+ BKE_collection_object_add(&scene->id, scene_collection, ob);
+ base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (base->flag & BASE_SELECTABLED) {
+ base->flag |= BASE_SELECTED;
+ }
+
+ BKE_scene_object_base_flag_sync_from_base(base);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ view_layer->basact = base;
- /* assign the group */
+ /* Assign the group. */
ob->dup_group = group;
ob->transflag |= OB_DUPLIGROUP;
copy_v3_v3(ob->loc, scene->cursor);
@@ -10128,31 +10109,43 @@ static ID *link_named_part(
return id;
}
-static void link_object_postprocess(ID *id, Scene *scene, View3D *v3d, const int flag)
+static SceneCollection *get_scene_collection_active_or_create(
+ struct Scene *scene, struct ViewLayer *view_layer, const int flag)
+{
+ LayerCollection *lc = NULL;
+
+ if (flag & FILE_ACTIVE_COLLECTION) {
+ lc = BKE_layer_collection_get_active_ensure(scene, view_layer);
+ }
+ else {
+ SceneCollection *sc = BKE_collection_add(&scene->id, NULL, COLLECTION_TYPE_NONE, NULL);
+ lc = BKE_collection_link(view_layer, sc);
+ }
+
+ return lc->scene_collection;
+}
+
+static void link_object_postprocess(ID *id, Scene *scene, ViewLayer *view_layer, const int flag)
{
if (scene) {
+ /* link to scene */
Base *base;
Object *ob;
-
- base = MEM_callocN(sizeof(Base), "app_nam_part");
- BLI_addtail(&scene->base, base);
+ SceneCollection *sc;
ob = (Object *)id;
-
- /* link at active layer (view3d if available in context, else scene one */
- if (flag & FILE_ACTIVELAY) {
- ob->lay = BKE_screen_view3d_layer_active(v3d, scene);
- }
-
ob->mode = OB_MODE_OBJECT;
- base->lay = ob->lay;
- base->object = ob;
- base->flag = ob->flag;
- id_us_plus_no_lib((ID *)ob);
+
+ sc = get_scene_collection_active_or_create(scene, view_layer, flag);
+ BKE_collection_object_add(&scene->id, sc, ob);
+ base = BKE_view_layer_base_find(view_layer, ob);
+ BKE_scene_object_base_flag_sync_from_base(base);
if (flag & FILE_AUTOSELECT) {
- base->flag |= SELECT;
- base->object->flag = base->flag;
+ if (base->flag & BASE_SELECTABLED) {
+ base->flag |= BASE_SELECTED;
+ BKE_scene_object_base_flag_sync_from_base(base);
+ }
/* do NOT make base active here! screws up GUI stuff, if you want it do it on src/ level */
}
}
@@ -10195,12 +10188,12 @@ void BLO_library_link_copypaste(Main *mainl, BlendHandle *bh)
static ID *link_named_part_ex(
Main *mainl, FileData *fd, const short idcode, const char *name, const int flag,
- Scene *scene, View3D *v3d)
+ Scene *scene, ViewLayer *view_layer)
{
ID *id = link_named_part(mainl, fd, idcode, name, flag);
if (id && (GS(id->name) == ID_OB)) { /* loose object: give a base */
- link_object_postprocess(id, scene, v3d, flag);
+ link_object_postprocess(id, scene, view_layer, flag);
}
else if (id && (GS(id->name) == ID_GR)) {
/* tag as needing to be instantiated */
@@ -10242,10 +10235,10 @@ ID *BLO_library_link_named_part(Main *mainl, BlendHandle **bh, const short idcod
ID *BLO_library_link_named_part_ex(
Main *mainl, BlendHandle **bh,
const short idcode, const char *name, const int flag,
- Scene *scene, View3D *v3d)
+ Scene *scene, ViewLayer *view_layer)
{
FileData *fd = (FileData*)(*bh);
- return link_named_part_ex(mainl, fd, idcode, name, flag, scene, v3d);
+ return link_named_part_ex(mainl, fd, idcode, name, flag, scene, view_layer);
}
static void link_id_part(ReportList *reports, FileData *fd, Main *mainvar, ID *id, ID **r_id)
@@ -10358,7 +10351,7 @@ static void split_main_newid(Main *mainptr, Main *main_newid)
}
/* scene and v3d may be NULL. */
-static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene *scene, View3D *v3d)
+static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene *scene, ViewLayer *view_layer)
{
Main *mainvar;
Library *curlib;
@@ -10414,10 +10407,10 @@ static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene
* Only directly linked objects & groups are instantiated by `BLO_library_link_named_part_ex()` & co,
* here we handle indirect ones and other possible edge-cases. */
if (scene) {
- give_base_to_objects(mainvar, scene, v3d, curlib, flag);
+ give_base_to_objects(mainvar, scene, view_layer, curlib, flag);
if (flag & FILE_GROUP_INSTANCE) {
- give_base_to_groups(mainvar, scene, v3d, curlib, flag);
+ give_base_to_groups(mainvar, scene, view_layer, curlib, flag);
}
}
else {
@@ -10443,12 +10436,12 @@ static void library_link_end(Main *mainl, FileData **fd, const short flag, Scene
* \param bh The blender file handle (WARNING! may be freed by this function!).
* \param flag Options for linking, used for instantiating.
* \param scene The scene in which to instantiate objects/groups (if NULL, no instantiation is done).
- * \param v3d The active View3D (only to define active layers for instantiated objects & groups, can be NULL).
+ * \param view_layer The scene layer in which to instantiate objects/groups (if NULL, no instantiation is done).
*/
-void BLO_library_link_end(Main *mainl, BlendHandle **bh, short flag, Scene *scene, View3D *v3d)
+void BLO_library_link_end(Main *mainl, BlendHandle **bh, int flag, Scene *scene, ViewLayer *view_layer)
{
FileData *fd = (FileData*)(*bh);
- library_link_end(mainl, &fd, flag, scene, v3d);
+ library_link_end(mainl, &fd, flag, scene, view_layer);
*bh = (BlendHandle*)fd;
}
diff --git a/source/blender/blenloader/intern/readfile.h b/source/blender/blenloader/intern/readfile.h
index 62ce15a640e..299c66f2bbb 100644
--- a/source/blender/blenloader/intern/readfile.h
+++ b/source/blender/blenloader/intern/readfile.h
@@ -34,6 +34,8 @@
#define __READFILE_H__
#include "zlib.h"
+#include "DNA_sdna_types.h"
+#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h" /* for ReportType */
struct OldNewMap;
@@ -171,8 +173,10 @@ void blo_do_versions_pre250(struct FileData *fd, struct Library *lib, struct Mai
void blo_do_versions_250(struct FileData *fd, struct Library *lib, struct Main *main);
void blo_do_versions_260(struct FileData *fd, struct Library *lib, struct Main *main);
void blo_do_versions_270(struct FileData *fd, struct Library *lib, struct Main *main);
+void blo_do_versions_280(struct FileData *fd, struct Library *lib, struct Main *main);
void do_versions_after_linking_270(struct Main *main);
+void do_versions_after_linking_280(struct Main *main);
#endif
diff --git a/source/blender/blenloader/intern/versioning_250.c b/source/blender/blenloader/intern/versioning_250.c
index d308bd54da3..3f85011db0b 100644
--- a/source/blender/blenloader/intern/versioning_250.c
+++ b/source/blender/blenloader/intern/versioning_250.c
@@ -39,7 +39,6 @@
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_brush_types.h"
#include "DNA_camera_types.h"
#include "DNA_cloth_types.h"
@@ -84,7 +83,6 @@
#include "BKE_sequencer.h"
#include "BKE_texture.h"
#include "BKE_sound.h"
-#include "BKE_sca.h"
#include "NOD_socket.h"
@@ -101,7 +99,7 @@ static void area_add_header_region(ScrArea *sa, ListBase *lb)
BLI_addtail(lb, ar);
ar->regiontype = RGN_TYPE_HEADER;
- if (sa->headertype == HEADERDOWN)
+ if (sa->headertype == 1)
ar->alignment = RGN_ALIGN_BOTTOM;
else
ar->alignment = RGN_ALIGN_TOP;
@@ -287,19 +285,6 @@ static void area_add_window_regions(ScrArea *sa, SpaceLink *sl, ListBase *lb)
//ar->v2d.flag |= V2D_IS_INITIALISED;
}
break;
- case SPACE_TIME:
- {
- SpaceTime *stime = (SpaceTime *)sl;
- memcpy(&ar->v2d, &stime->v2d, sizeof(View2D));
-
- ar->v2d.scroll |= (V2D_SCROLL_BOTTOM|V2D_SCROLL_SCALE_HORIZONTAL);
- ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
- ar->v2d.keepofs |= V2D_LOCKOFS_Y;
- ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
- ar->v2d.tot.ymin = ar->v2d.cur.ymin = -10.0;
- ar->v2d.min[1] = ar->v2d.max[1] = 20.0;
- }
- break;
case SPACE_IPO:
{
SpaceIpo *sipo = (SpaceIpo *)sl;
@@ -444,9 +429,6 @@ static void do_versions_windowmanager_2_50(bScreen *screen)
sl->spacetype = SPACE_EMPTY; /* spacedata then matches */
}
- /* it seems to be possible in 2.5 to have this saved, filewindow probably */
- sa->butspacetype = sa->spacetype;
-
/* pushed back spaces also need regions! */
if (sa->spacedata.first) {
sl = sa->spacedata.first;
@@ -517,70 +499,6 @@ static void do_versions_gpencil_2_50(Main *main, bScreen *screen)
}
}
-static void do_version_mtex_factor_2_50(MTex **mtex_array, short idtype)
-{
- MTex *mtex;
- float varfac, colfac;
- int a, neg;
-
- if (!mtex_array)
- return;
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (mtex_array[a]) {
- mtex = mtex_array[a];
-
- neg = mtex->maptoneg;
- varfac = mtex->varfac;
- colfac = mtex->colfac;
-
- if (neg & MAP_DISP) mtex->dispfac = -mtex->dispfac;
- if (neg & MAP_NORM) mtex->norfac = -mtex->norfac;
- if (neg & MAP_WARP) mtex->warpfac = -mtex->warpfac;
-
- mtex->colspecfac = (neg & MAP_COLSPEC)? -colfac: colfac;
- mtex->mirrfac = (neg & MAP_COLMIR)? -colfac: colfac;
- mtex->alphafac = (neg & MAP_ALPHA)? -varfac: varfac;
- mtex->difffac = (neg & MAP_REF)? -varfac: varfac;
- mtex->specfac = (neg & MAP_SPEC)? -varfac: varfac;
- mtex->emitfac = (neg & MAP_EMIT)? -varfac: varfac;
- mtex->hardfac = (neg & MAP_HAR)? -varfac: varfac;
- mtex->raymirrfac = (neg & MAP_RAYMIRR)? -varfac: varfac;
- mtex->translfac = (neg & MAP_TRANSLU)? -varfac: varfac;
- mtex->ambfac = (neg & MAP_AMB)? -varfac: varfac;
- mtex->colemitfac = (neg & MAP_EMISSION_COL)? -colfac: colfac;
- mtex->colreflfac = (neg & MAP_REFLECTION_COL)? -colfac: colfac;
- mtex->coltransfac = (neg & MAP_TRANSMISSION_COL)? -colfac: colfac;
- mtex->densfac = (neg & MAP_DENSITY)? -varfac: varfac;
- mtex->scatterfac = (neg & MAP_SCATTERING)? -varfac: varfac;
- mtex->reflfac = (neg & MAP_REFLECTION)? -varfac: varfac;
-
- mtex->timefac = (neg & MAP_PA_TIME)? -varfac: varfac;
- mtex->lengthfac = (neg & MAP_PA_LENGTH)? -varfac: varfac;
- mtex->clumpfac = (neg & MAP_PA_CLUMP)? -varfac: varfac;
- mtex->kinkfac = (neg & MAP_PA_KINK)? -varfac: varfac;
- mtex->roughfac = (neg & MAP_PA_ROUGH)? -varfac: varfac;
- mtex->padensfac = (neg & MAP_PA_DENS)? -varfac: varfac;
- mtex->lifefac = (neg & MAP_PA_LIFE)? -varfac: varfac;
- mtex->sizefac = (neg & MAP_PA_SIZE)? -varfac: varfac;
- mtex->ivelfac = (neg & MAP_PA_IVEL)? -varfac: varfac;
-
- mtex->shadowfac = (neg & LAMAP_SHAD)? -colfac: colfac;
-
- mtex->zenupfac = (neg & WOMAP_ZENUP)? -colfac: colfac;
- mtex->zendownfac = (neg & WOMAP_ZENDOWN)? -colfac: colfac;
- mtex->blendfac = (neg & WOMAP_BLEND)? -varfac: varfac;
-
- if (idtype == ID_MA)
- mtex->colfac = (neg & MAP_COL)? -colfac: colfac;
- else if (idtype == ID_LA)
- mtex->colfac = (neg & LAMAP_COL)? -colfac: colfac;
- else if (idtype == ID_WO)
- mtex->colfac = (neg & WOMAP_HORIZ)? -colfac: colfac;
- }
- }
-}
-
static void do_version_mdef_250(Main *main)
{
Object *ob;
@@ -610,13 +528,7 @@ static void do_version_constraints_radians_degrees_250(ListBase *lb)
bConstraint *con;
for (con = lb->first; con; con = con->next) {
- if (con->type == CONSTRAINT_TYPE_RIGIDBODYJOINT) {
- bRigidBodyJointConstraint *data = con->data;
- data->axX *= (float)(M_PI / 180.0);
- data->axY *= (float)(M_PI / 180.0);
- data->axZ *= (float)(M_PI / 180.0);
- }
- else if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
+ if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
bKinematicConstraint *data = con->data;
data->poleangle *= (float)(M_PI / 180.0);
}
@@ -750,8 +662,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
bSound *sound;
Sequence *seq;
- bActuator *act;
- int a;
for (sound = main->sound.first; sound; sound = sound->id.next) {
if (sound->newpackedfile) {
@@ -760,33 +670,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
}
- for (ob = main->object.first; ob; ob = ob->id.next) {
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_SOUND) {
- bSoundActuator *sAct = (bSoundActuator*) act->data;
- if (sAct->sound) {
- sound = blo_do_versions_newlibadr(fd, lib, sAct->sound);
- sAct->flag = (sound->flags & SOUND_FLAGS_3D) ? ACT_SND_3D_SOUND : 0;
- sAct->pitch = sound->pitch;
- sAct->volume = sound->volume;
- sAct->sound3D.reference_distance = sound->distance;
- sAct->sound3D.max_gain = sound->max_gain;
- sAct->sound3D.min_gain = sound->min_gain;
- sAct->sound3D.rolloff_factor = sound->attenuation;
- }
- else {
- sAct->sound3D.reference_distance = 1.0f;
- sAct->volume = 1.0f;
- sAct->sound3D.max_gain = 1.0f;
- sAct->sound3D.rolloff_factor = 1.0f;
- }
- sAct->sound3D.cone_inner_angle = 360.0f;
- sAct->sound3D.cone_outer_angle = 360.0f;
- sAct->sound3D.max_distance = FLT_MAX;
- }
- }
- }
-
for (scene = main->scene.first; scene; scene = scene->id.next) {
if (scene->ed && scene->ed->seqbasep) {
SEQ_BEGIN (scene->ed, seq)
@@ -823,15 +706,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
for (ma = main->mat.first; ma; ma = ma->id.next) {
if (ma->nodetree && ma->nodetree->id.name[0] == '\0')
strcpy(ma->nodetree->id.name, "NTShader Nodetree");
-
- /* which_output 0 is now "not specified" */
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) {
- tx = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
- if (tx && tx->use_nodes)
- ma->mtex[a]->which_output++;
- }
- }
}
/* and composite trees */
@@ -917,7 +791,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 1)) {
Object *ob;
- Material *ma;
Tex *tex;
Scene *sce;
ToolSettings *ts;
@@ -963,65 +836,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
tex->afmax = 8;
}
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- int a;
-
- if (ma->mode & MA_WIRE) {
- ma->material_type = MA_TYPE_WIRE;
- ma->mode &= ~MA_WIRE;
- }
-
- if (ma->mode & MA_HALO) {
- ma->material_type = MA_TYPE_HALO;
- ma->mode &= ~MA_HALO;
- }
-
- if (ma->mode & (MA_ZTRANSP|MA_RAYTRANSP)) {
- ma->mode |= MA_TRANSP;
- }
- else {
- /* ma->mode |= MA_ZTRANSP; */ /* leave ztransp as is even if its not used [#28113] */
- ma->mode &= ~MA_TRANSP;
- }
-
- /* set new bump for unused slots */
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) {
- tex = ma->mtex[a]->tex;
- if (!tex) {
- ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
- ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
- }
- else {
- tex = (Tex*) blo_do_versions_newlibadr(fd, ma->id.lib, tex);
- if (tex && tex->type == 0) { /* invalid type */
- ma->mtex[a]->texflag |= MTEX_3TAP_BUMP;
- ma->mtex[a]->texflag |= MTEX_BUMP_OBJECTSPACE;
- }
- }
- }
- }
-
- /* volume rendering settings */
- if (ma->vol.stepsize < 0.0001f) {
- ma->vol.density = 1.0f;
- ma->vol.emission = 0.0f;
- ma->vol.scattering = 1.0f;
- ma->vol.emission_col[0] = ma->vol.emission_col[1] = ma->vol.emission_col[2] = 1.0f;
- ma->vol.density_scale = 1.0f;
- ma->vol.depth_cutoff = 0.01f;
- ma->vol.stepsize_type = MA_VOL_STEP_RANDOMIZED;
- ma->vol.stepsize = 0.2f;
- ma->vol.shade_type = MA_VOL_SHADE_SHADED;
- ma->vol.shadeflag |= MA_VOL_PRECACHESHADING;
- ma->vol.precache_resolution = 50;
- }
- }
-
for (sce = main->scene.first; sce; sce = sce->id.next) {
ts = sce->toolsettings;
- if (ts->normalsize == 0.0f || !ts->uv_selectmode || ts->vgroup_weight == 0.0f) {
- ts->normalsize = 0.1f;
+ if (!ts->uv_selectmode || ts->vgroup_weight == 0.0f) {
ts->selectmode = SCE_SELECT_VERTEX;
/* autokeying - setting should be taken from the user-prefs
@@ -1034,95 +851,12 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
ts->uv_selectmode = UV_SELECT_VERTEX;
ts->vgroup_weight = 1.0f;
}
-
- /* Game Settings */
- /* Dome */
- sce->gm.dome.angle = sce->r.domeangle;
- sce->gm.dome.mode = sce->r.domemode;
- sce->gm.dome.res = sce->r.domeres;
- sce->gm.dome.resbuf = sce->r.domeresbuf;
- sce->gm.dome.tilt = sce->r.dometilt;
- sce->gm.dome.warptext = sce->r.dometext;
-
- /* Stand Alone */
- sce->gm.playerflag |= (sce->r.fullscreen ? GAME_PLAYER_FULLSCREEN : 0);
- sce->gm.xplay = sce->r.xplay;
- sce->gm.yplay = sce->r.yplay;
- sce->gm.freqplay = sce->r.freqplay;
- sce->gm.depth = sce->r.depth;
- sce->gm.attrib = sce->r.attrib;
-
- /* Stereo */
- sce->gm.stereomode = sce->r.stereomode;
- /* reassigning stereomode NO_STEREO and DOME to a separeted flag*/
- if (sce->gm.stereomode == 1) { // 1 = STEREO_NOSTEREO
- sce->gm.stereoflag = STEREO_NOSTEREO;
- sce->gm.stereomode = STEREO_ANAGLYPH;
- }
- else if (sce->gm.stereomode == 8) { // 8 = STEREO_DOME
- sce->gm.stereoflag = STEREO_DOME;
- sce->gm.stereomode = STEREO_ANAGLYPH;
- }
- else
- sce->gm.stereoflag = STEREO_ENABLED;
-
- /* Framing */
- sce->gm.framing = sce->framing;
- sce->gm.xplay = sce->r.xplay;
- sce->gm.yplay = sce->r.yplay;
- sce->gm.freqplay = sce->r.freqplay;
- sce->gm.depth = sce->r.depth;
-
- /* Physic (previously stored in world) */
- sce->gm.gravity =9.8f;
- sce->gm.physicsEngine = WOPHY_BULLET; /* Bullet by default */
- sce->gm.mode = WO_DBVT_CULLING; /* DBVT culling by default */
- sce->gm.occlusionRes = 128;
- sce->gm.ticrate = 60;
- sce->gm.maxlogicstep = 5;
- sce->gm.physubstep = 1;
- sce->gm.maxphystep = 5;
}
}
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 2)) {
- Scene *sce;
Object *ob;
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- if (fd->fileflags & G_FILE_ENABLE_ALL_FRAMES)
- sce->gm.flag |= GAME_ENABLE_ALL_FRAMES;
- if (fd->fileflags & G_FILE_SHOW_DEBUG_PROPS)
- sce->gm.flag |= GAME_SHOW_DEBUG_PROPS;
- if (fd->fileflags & G_FILE_SHOW_FRAMERATE)
- sce->gm.flag |= GAME_SHOW_FRAMERATE;
- if (fd->fileflags & G_FILE_SHOW_PHYSICS)
- sce->gm.flag |= GAME_SHOW_PHYSICS;
- if (fd->fileflags & G_FILE_GLSL_NO_SHADOWS)
- sce->gm.flag |= GAME_GLSL_NO_SHADOWS;
- if (fd->fileflags & G_FILE_GLSL_NO_SHADERS)
- sce->gm.flag |= GAME_GLSL_NO_SHADERS;
- if (fd->fileflags & G_FILE_GLSL_NO_RAMPS)
- sce->gm.flag |= GAME_GLSL_NO_RAMPS;
- if (fd->fileflags & G_FILE_GLSL_NO_NODES)
- sce->gm.flag |= GAME_GLSL_NO_NODES;
- if (fd->fileflags & G_FILE_GLSL_NO_EXTRA_TEX)
- sce->gm.flag |= GAME_GLSL_NO_EXTRA_TEX;
- if (fd->fileflags & G_FILE_GLSL_NO_ENV_LIGHTING)
- sce->gm.flag |= GAME_GLSL_NO_ENV_LIGHTING;
- if (fd->fileflags & G_FILE_IGNORE_DEPRECATION_WARNINGS)
- sce->gm.flag |= GAME_IGNORE_DEPRECATION_WARNINGS;
-
- if (fd->fileflags & G_FILE_GAME_MAT_GLSL)
- sce->gm.matmode = GAME_MAT_GLSL;
- else if (fd->fileflags & G_FILE_GAME_MAT)
- sce->gm.matmode = GAME_MAT_MULTITEX;
- else
- sce->gm.matmode = GAME_MAT_TEXFACE;
-
- sce->gm.flag |= GAME_DISPLAY_LISTS;
- }
-
for (ob = main->object.first; ob; ob = ob->id.next) {
if (ob->flag & 8192) // OB_POSEMODE = 8192
ob->mode |= OB_MODE_POSE;
@@ -1132,10 +866,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 4)) {
Scene *sce;
Object *ob;
- Material *ma;
- Lamp *la;
- World *wo;
- Tex *tex;
ParticleSettings *part;
bool do_gravity = false;
@@ -1153,27 +883,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
ob->rotmode = ROT_MODE_EUL;
}
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- if (ma->vol.reflection == 0.f) {
- ma->vol.reflection = 1.f;
- ma->vol.transmission_col[0] = ma->vol.transmission_col[1] = ma->vol.transmission_col[2] = 1.0f;
- ma->vol.reflection_col[0] = ma->vol.reflection_col[1] = ma->vol.reflection_col[2] = 1.0f;
- }
-
- do_version_mtex_factor_2_50(ma->mtex, ID_MA);
- }
-
- for (la = main->lamp.first; la; la = la->id.next)
- do_version_mtex_factor_2_50(la->mtex, ID_LA);
-
- for (wo = main->world.first; wo; wo = wo->id.next)
- do_version_mtex_factor_2_50(wo->mtex, ID_WO);
-
- for (tex = main->tex.first; tex; tex = tex->id.next)
- if (tex->vd)
- if (tex->vd->extend == 0)
- tex->vd->extend = TEX_CLIP;
-
for (sce = main->scene.first; sce; sce = sce->id.next) {
if (sce->audio.main == 0.0f)
sce->audio.main = 1.0f;
@@ -1234,7 +943,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 6)) {
Object *ob;
- Lamp *la;
/* New variables for axis-angle rotations and/or quaternion rotations were added, and need proper initialization */
for (ob = main->object.first; ob; ob = ob->id.next) {
@@ -1252,9 +960,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
}
}
-
- for (la = main->lamp.first; la; la = la->id.next)
- la->compressthresh = 0.05f;
}
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 7)) {
@@ -1323,8 +1028,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
while (sce) {
if (sce->r.frame_step == 0)
sce->r.frame_step = 1;
- if (sce->r.mblur_samples == 0)
- sce->r.mblur_samples = sce->r.osa;
if (sce->ed && sce->ed->seqbase.first) {
do_versions_seq_unique_name_all_strips(sce, &sce->ed->seqbase);
@@ -1381,7 +1084,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
if (main->versionfile == 250) {
Scene *sce = main->scene.first;
Material *ma = main->mat.first;
- World *wo = main->world.first;
Tex *tex = main->tex.first;
int i, convert = 0;
@@ -1399,26 +1101,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
if (convert) {
while (ma) {
- if (ma->ramp_col) {
- ColorBand *band = (ColorBand *)ma->ramp_col;
- for (i = 0; i < band->tot; i++) {
- CBData *data = band->data + i;
- srgb_to_linearrgb_v3_v3(&data->r, &data->r);
- }
- }
-
- if (ma->ramp_spec) {
- ColorBand *band = (ColorBand *)ma->ramp_spec;
- for (i = 0; i < band->tot; i++) {
- CBData *data = band->data + i;
- srgb_to_linearrgb_v3_v3(&data->r, &data->r);
- }
- }
-
srgb_to_linearrgb_v3_v3(&ma->r, &ma->r);
srgb_to_linearrgb_v3_v3(&ma->specr, &ma->specr);
- srgb_to_linearrgb_v3_v3(&ma->mirr, &ma->mirr);
- srgb_to_linearrgb_v3_v3(ma->sss_col, ma->sss_col);
ma = ma->id.next;
}
@@ -1432,13 +1116,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
tex = tex->id.next;
}
-
- while (wo) {
- srgb_to_linearrgb_v3_v3(&wo->ambr, &wo->ambr);
- srgb_to_linearrgb_v3_v3(&wo->horr, &wo->horr);
- srgb_to_linearrgb_v3_v3(&wo->zenr, &wo->zenr);
- wo = wo->id.next;
- }
}
}
}
@@ -1567,15 +1244,8 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 12)) {
- Scene *sce;
Object *ob;
Brush *brush;
- Material *ma;
-
- /* game engine changes */
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- sce->gm.eyeseparation = 0.10f;
- }
/* anim viz changes */
for (ob = main->object.first; ob; ob = ob->id.next) {
@@ -1657,14 +1327,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
BKE_texture_mtex_default(&brush->mtex);
BKE_texture_mtex_default(&brush->mask_mtex);
}
-
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- if (ma->vol.ms_spread < 0.0001f) {
- ma->vol.ms_spread = 0.2f;
- ma->vol.ms_diff = 1.f;
- ma->vol.ms_intensity = 1.f;
- }
- }
}
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 13)) {
@@ -1723,41 +1385,9 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 15)) {
- World *wo;
- Material *ma;
-
- /* ambient default from 0.5f to 1.0f */
- for (ma = main->mat.first; ma; ma = ma->id.next)
- ma->amb *= 2.0f;
-
- for (wo = main->world.first; wo; wo = wo->id.next) {
- /* ao splitting into ao/env/indirect */
- wo->ao_env_energy = wo->aoenergy;
- wo->aoenergy = 1.0f;
-
- if (wo->ao_indirect_bounces == 0)
- wo->ao_indirect_bounces = 1;
- else
- wo->mode |= WO_INDIRECT_LIGHT;
-
- if (wo->aomix == WO_AOSUB)
- wo->ao_env_energy = -wo->ao_env_energy;
- else if (wo->aomix == WO_AOADDSUB)
- wo->mode |= WO_AMB_OCC;
-
- wo->aomix = WO_AOMUL;
-
- /* ambient default from 0.5f to 1.0f */
- mul_v3_fl(&wo->ambr, 0.5f);
- wo->ao_env_energy *= 0.5f;
- }
- }
-
if (main->versionfile < 250 || (main->versionfile == 250 && main->subversionfile < 17)) {
Scene *sce;
Sequence *seq;
- Material *ma;
/* initialize to sane default so toggling on border shows something */
for (sce = main->scene.first; sce; sce = sce->id.next) {
@@ -1789,10 +1419,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
pset->brush[a].strength /= 100.0f;
}
- for (ma = main->mat.first; ma; ma = ma->id.next)
- if (ma->mode & MA_TRACEBLE)
- ma->shade_flag |= MA_APPROX_OCCLUSION;
-
/* sequencer changes */
{
bScreen *screen;
@@ -1970,14 +1596,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
}
}
- else if (sl->spacetype == SPACE_TIME) {
- SpaceTime *stime = (SpaceTime *) sl;
-
- /* enable all cache display */
- stime->cache_display |= TIME_CACHE_DISPLAY;
- stime->cache_display |= (TIME_CACHE_SOFTBODY|TIME_CACHE_PARTICLES);
- stime->cache_display |= (TIME_CACHE_CLOTH|TIME_CACHE_SMOKE|TIME_CACHE_DYNAMICPAINT);
- }
}
}
}
@@ -2197,7 +1815,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
Brush *br;
ParticleSettings *part;
bScreen *sc;
- Object *ob;
for (br = main->brush.first; br; br = br->id.next) {
if (br->ob_mode == 0)
@@ -2237,41 +1854,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
}
}
-
- /* fix rotation actuators for objects so they use real angles (radians)
- * since before blender went opensource this strange scalar was used: (1 / 0.02) * 2 * math.pi/360 */
- for (ob = main->object.first; ob; ob = ob->id.next) {
- bActuator *act = ob->actuators.first;
- while (act) {
- if (act->type == ACT_OBJECT) {
- /* multiply velocity with 50 in old files */
- bObjectActuator *oa = act->data;
- mul_v3_fl(oa->drot, 0.8726646259971648f);
- }
- act = act->next;
- }
- }
- }
-
- /* init facing axis property of steering actuators */
- {
- Object *ob;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- bActuator *act;
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_STEERING) {
- bSteeringActuator *stact = act->data;
- if (stact == NULL) {//HG1
- init_actuator(act);
- }
- else {
- if (stact->facingaxis == 0) {
- stact->facingaxis = 1;
- }
- }
- }
- }
- }
}
if (main->versionfile < 255 || (main->versionfile == 255 && main->subversionfile < 3)) {
@@ -2430,27 +2012,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
Brush *brush;
Object *ob;
ParticleSettings *part;
- Material *mat;
- int tex_nr, transp_tex;
-
- for (mat = main->mat.first; mat; mat = mat->id.next) {
- if (!(mat->mode & MA_TRANSP) && !(mat->material_type & MA_TYPE_VOLUME)) {
- transp_tex = 0;
-
- for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) {
- if (!mat->mtex[tex_nr])
- continue;
- if (mat->mtex[tex_nr]->mapto & MAP_ALPHA)
- transp_tex = 1;
- }
-
- /* weak! material alpha could be animated */
- if (mat->alpha < 1.0f || mat->fresnel_tra > 0.0f || transp_tex) {
- mat->mode |= MA_TRANSP;
- mat->mode &= ~(MA_ZTRANSP|MA_RAYTRANSP);
- }
- }
- }
/* redraws flag in SpaceTime has been moved to Screen level */
for (sc = main->screen.first; sc; sc = sc->id.next) {
@@ -2544,41 +2105,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
{
- /* Initialize texture point density curve falloff */
- Tex *tex;
- for (tex = main->tex.first; tex; tex = tex->id.next) {
- if (tex->pd) {
- if (tex->pd->falloff_speed_scale == 0.0f)
- tex->pd->falloff_speed_scale = 100.0f;
-
- if (!tex->pd->falloff_curve) {
- tex->pd->falloff_curve = curvemapping_add(1, 0, 0, 1, 1);
-
- tex->pd->falloff_curve->preset = CURVE_PRESET_LINE;
- tex->pd->falloff_curve->cm->flag &= ~CUMA_EXTEND_EXTRAPOLATE;
- curvemap_reset(tex->pd->falloff_curve->cm, &tex->pd->falloff_curve->clipr, tex->pd->falloff_curve->preset, CURVEMAP_SLOPE_POSITIVE);
- curvemapping_changed(tex->pd->falloff_curve, false);
- }
- }
- }
- }
-
- {
- /* add default value for behind strength of camera actuator */
- Object *ob;
- bActuator *act;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_CAMERA) {
- bCameraActuator *ba = act->data;
-
- ba->damping = 1.0/32.0;
- }
- }
- }
- }
-
- {
ParticleSettings *part;
for (part = main->particle.first; part; part = part->id.next) {
/* Initialize particle billboard scale */
@@ -2669,50 +2195,6 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
}
}
}
-
- {
- /* convert fcurve and shape action actuators to action actuators */
- Object *ob;
- bActuator *act;
- bIpoActuator *ia;
- bActionActuator *aa;
-
- for (ob = main->object.first; ob; ob = ob->id.next) {
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_IPO) {
- /* Create the new actuator */
- ia = act->data;
- aa = MEM_callocN(sizeof(bActionActuator), "fcurve -> action actuator do_version");
-
- /* Copy values */
- aa->type = ia->type;
- aa->flag = ia->flag;
- aa->sta = ia->sta;
- aa->end = ia->end;
- BLI_strncpy(aa->name, ia->name, sizeof(aa->name));
- BLI_strncpy(aa->frameProp, ia->frameProp, sizeof(aa->frameProp));
- if (ob->adt)
- aa->act = ob->adt->action;
-
- /* Get rid of the old actuator */
- MEM_freeN(ia);
-
- /* Assign the new actuator */
- act->data = aa;
- act->type = act->otype = ACT_ACTION;
-
- /* Fix for converting 2.4x files: if we don't have an action, but we have an
- * object IPO, then leave the actuator as an IPO actuator for now and let the
- * IPO conversion code handle it */
- if (ob->ipo && !aa->act)
- act->type = ACT_IPO;
- }
- else if (act->type == ACT_SHAPEACTION) {
- act->type = act->otype = ACT_ACTION;
- }
- }
- }
- }
}
if (main->versionfile < 259 || (main->versionfile == 259 && main->subversionfile < 2)) {
@@ -2760,41 +2242,5 @@ void blo_do_versions_250(FileData *fd, Library *lib, Main *main)
part->time_flag &= ~PART_TIME_AUTOSF;
}
}
-
- {
- /* set defaults for obstacle avoidance, recast data */
- Scene *sce;
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- if (sce->gm.levelHeight == 0.f)
- sce->gm.levelHeight = 2.f;
-
- if (sce->gm.recastData.cellsize == 0.0f)
- sce->gm.recastData.cellsize = 0.3f;
- if (sce->gm.recastData.cellheight == 0.0f)
- sce->gm.recastData.cellheight = 0.2f;
- if (sce->gm.recastData.agentmaxslope == 0.0f)
- sce->gm.recastData.agentmaxslope = (float)M_PI/4;
- if (sce->gm.recastData.agentmaxclimb == 0.0f)
- sce->gm.recastData.agentmaxclimb = 0.9f;
- if (sce->gm.recastData.agentheight == 0.0f)
- sce->gm.recastData.agentheight = 2.0f;
- if (sce->gm.recastData.agentradius == 0.0f)
- sce->gm.recastData.agentradius = 0.6f;
- if (sce->gm.recastData.edgemaxlen == 0.0f)
- sce->gm.recastData.edgemaxlen = 12.0f;
- if (sce->gm.recastData.edgemaxerror == 0.0f)
- sce->gm.recastData.edgemaxerror = 1.3f;
- if (sce->gm.recastData.regionminsize == 0.0f)
- sce->gm.recastData.regionminsize = 8.f;
- if (sce->gm.recastData.regionmergesize == 0.0f)
- sce->gm.recastData.regionmergesize = 20.f;
- if (sce->gm.recastData.vertsperpoly<3)
- sce->gm.recastData.vertsperpoly = 6;
- if (sce->gm.recastData.detailsampledist == 0.0f)
- sce->gm.recastData.detailsampledist = 6.0f;
- if (sce->gm.recastData.detailsamplemaxerror == 0.0f)
- sce->gm.recastData.detailsamplemaxerror = 1.0f;
- }
- }
}
}
diff --git a/source/blender/blenloader/intern/versioning_260.c b/source/blender/blenloader/intern/versioning_260.c
index 79dfd572dbb..4049912b586 100644
--- a/source/blender/blenloader/intern/versioning_260.c
+++ b/source/blender/blenloader/intern/versioning_260.c
@@ -31,7 +31,6 @@
#define DNA_DEPRECATED_ALLOW
#include "DNA_anim_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_brush_types.h"
#include "DNA_camera_types.h"
#include "DNA_cloth_types.h"
@@ -43,11 +42,9 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_fluidsim_types.h"
#include "DNA_object_types.h"
-#include "DNA_property_types.h"
#include "DNA_text_types.h"
#include "DNA_view3d_types.h"
#include "DNA_screen_types.h"
-#include "DNA_sensor_types.h"
#include "DNA_sdna_types.h"
#include "DNA_smoke_types.h"
#include "DNA_space_types.h"
@@ -67,7 +64,6 @@
#include "BKE_modifier.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
-#include "BKE_property.h" // for BKE_bproperty_object_get
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
@@ -432,25 +428,6 @@ static void do_versions_nodetree_frame_2_64_6(bNodeTree *ntree)
}
}
-static void do_version_logic_264(ListBase *regionbase)
-{
- ARegion *ar;
-
- /* view settings for logic changed */
- for (ar = regionbase->first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- if (ar->v2d.keeptot == 0) {
- ar->v2d.maxzoom = 1.5f;
-
- ar->v2d.keepzoom = V2D_KEEPZOOM | V2D_LIMITZOOM | V2D_KEEPASPECT;
- ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
- ar->v2d.align = V2D_ALIGN_NO_POS_Y | V2D_ALIGN_NO_NEG_X;
- ar->v2d.keepofs = V2D_KEEPOFS_Y;
- }
- }
- }
-}
-
static void do_versions_affine_tracker_track(MovieTrackingTrack *track)
{
int i;
@@ -900,14 +877,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
{
- /* Initialize BGE exit key to esc key */
- Scene *scene;
- for (scene = main->scene.first; scene; scene = scene->id.next) {
- if (!scene->gm.exitkey)
- scene->gm.exitkey = 218; // Blender key code for ESC
- }
- }
- {
MovieClip *clip;
Object *ob;
@@ -943,45 +912,10 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
- {
- /* Warn the user if he is using ["Text"] properties for Font objects */
- Object *ob;
- bProperty *prop;
-
- for (ob = main->object.first; ob; ob = ob->id.next) {
- if (ob->type == OB_FONT) {
- prop = BKE_bproperty_object_get(ob, "Text");
- if (prop) {
- blo_reportf_wrap(fd->reports, RPT_WARNING,
- TIP_("Game property name conflict in object '%s': text objects reserve the "
- "['Text'] game property to change their content through logic bricks"),
- ob->id.name + 2);
- }
- }
- }
- }
}
if (main->versionfile < 261 || (main->versionfile == 261 && main->subversionfile < 2)) {
{
- /* convert Camera Actuator values to defines */
- Object *ob;
- bActuator *act;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_CAMERA) {
- bCameraActuator *ba = act->data;
-
- if (ba->axis == (float) 'x') ba->axis = OB_POSX;
- else if (ba->axis == (float)'y') ba->axis = OB_POSY;
- /* don't do an if/else to avoid imediate subversion bump*/
-// ba->axis=((ba->axis == (float)'x') ? OB_POSX_X : OB_POSY);
- }
- }
- }
- }
-
- {
/* convert deprecated sculpt_paint_unified_* fields to
* UnifiedPaintSettings */
Scene *scene;
@@ -1222,15 +1156,9 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 4)) {
- Lamp *la;
Camera *cam;
Curve *cu;
- for (la = main->lamp.first; la; la = la->id.next) {
- if (la->shadow_frustum_size == 0.0f)
- la->shadow_frustum_size = 10.0f;
- }
-
for (cam = main->camera.first; cam; cam = cam->id.next) {
if (cam->flag & CAM_PANORAMA) {
cam->type = CAM_PANO;
@@ -1316,19 +1244,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
-
- if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 8)) {
- /* set new deactivation values for game settings */
- Scene *sce;
-
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- /* Game Settings */
- sce->gm.lineardeactthreshold = 0.8f;
- sce->gm.angulardeactthreshold = 1.0f;
- sce->gm.deactivationtime = 2.0f;
- }
- }
-
if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 9)) {
FOREACH_NODETREE(main, ntree, id) {
if (ntree->type == NTREE_SHADER) {
@@ -1420,14 +1335,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
- if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 12)) {
- Material *ma;
-
- for (ma = main->mat.first; ma; ma = ma->id.next)
- if (ma->strand_widthfade == 2.0f)
- ma->strand_widthfade = 0.0f;
- }
-
if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 13)) {
FOREACH_NODETREE(main, ntree, id) {
if (ntree->type == NTREE_COMPOSIT) {
@@ -1574,20 +1481,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
- /* remove texco */
if (main->versionfile < 263 || (main->versionfile == 263 && main->subversionfile < 21)) {
- Material *ma;
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- int a;
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) {
- if (ma->mtex[a]->texco == TEXCO_STICKY_) {
- ma->mtex[a]->texco = TEXCO_UV;
- }
- }
- }
- }
-
{
Mesh *me;
for (me = main->mesh.first; me; me = me->id.next) {
@@ -1738,24 +1632,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
} FOREACH_NODETREE_END
}
- if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 6)) {
- bScreen *sc;
-
- for (sc = main->screen.first; sc; sc = sc->id.next) {
- ScrArea *sa;
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl;
- if ( sa->spacetype == SPACE_LOGIC)
- do_version_logic_264(&sa->regionbase);
-
- for (sl = sa->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_LOGIC)
- do_version_logic_264(&sl->regionbase);
- }
- }
- }
- }
-
if (main->versionfile < 264 || (main->versionfile == 264 && main->subversionfile < 7)) {
/* convert tiles size from resolution and number of tiles */
{
@@ -1763,17 +1639,7 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
for (scene = main->scene.first; scene; scene = scene->id.next) {
if (scene->r.tilex == 0 || scene->r.tiley == 1) {
- if (scene->r.xparts && scene->r.yparts) {
- /* scene could be set for panoramic rendering, so clamp with the
- * lowest possible tile size value
- */
- scene->r.tilex = max_ii(scene->r.xsch * scene->r.size / scene->r.xparts / 100, 8);
- scene->r.tiley = max_ii(scene->r.ysch * scene->r.size / scene->r.yparts / 100, 8);
- }
- else {
- /* happens when mixing using current trunk and previous release */
- scene->r.tilex = scene->r.tiley = 64;
- }
+ scene->r.tilex = scene->r.tiley = 64;
}
}
}
@@ -1809,17 +1675,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
- if (main->versionfile < 265) {
- Object *ob;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- if (ob->step_height == 0.0f) {
- ob->step_height = 0.15f;
- ob->jump_speed = 10.0f;
- ob->fall_speed = 55.0f;
- }
- }
- }
-
if (main->versionfile < 265 || (main->versionfile == 265 && main->subversionfile < 3)) {
bScreen *sc;
for (sc = main->screen.first; sc; sc = sc->id.next) {
@@ -1870,7 +1725,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
for (scene = main->scene.first; scene; scene = scene->id.next) {
Sequence *seq;
- bool set_premul = false;
SEQ_BEGIN (scene->ed, seq)
{
@@ -1885,24 +1739,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
if (scene->r.bake_samples == 0)
scene->r.bake_samples = 256;
-
- if (scene->world) {
- World *world = blo_do_versions_newlibadr(fd, scene->id.lib, scene->world);
-
- if (world && is_zero_v3(&world->horr)) {
- if ((world->skytype & WO_SKYBLEND) == 0 || is_zero_v3(&world->zenr)) {
- set_premul = true;
- }
- }
- }
- else
- set_premul = true;
-
- if (set_premul) {
- printf("2.66 versioning fix: replacing black sky with premultiplied alpha for scene %s\n",
- scene->id.name + 2);
- scene->r.alphamode = R_ALPHAPREMUL;
- }
}
for (Image *image = main->image.first; image; image = image->id.next) {
@@ -2335,32 +2171,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
-
- for (ob = main->object.first; ob; ob = ob->id.next) {
- bSensor *sens;
- bTouchSensor *ts;
- bCollisionSensor *cs;
- Material *ma;
-
- for (sens = ob->sensors.first; sens; sens = sens->next) {
- if (sens->type == SENS_TOUCH) {
- ts = sens->data;
- cs = MEM_callocN(sizeof(bCollisionSensor), "touch -> collision sensor do_version");
-
- if (ts->ma) {
- ma = blo_do_versions_newlibadr(fd, ob->id.lib, ts->ma);
- BLI_strncpy(cs->materialName, ma->id.name + 2, sizeof(cs->materialName));
- }
-
- cs->mode = SENS_COLLISION_MATERIAL;
-
- MEM_freeN(ts);
-
- sens->data = cs;
- sens->type = sens->otype = SENS_COLLISION;
- }
- }
- }
}
if (!MAIN_VERSION_ATLEAST(main, 268, 5)) {
@@ -2453,11 +2263,14 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
if (sl->spacetype == SPACE_OUTLINER) {
SpaceOops *so = (SpaceOops *)sl;
- if (!ELEM(so->outlinevis, SO_ALL_SCENES, SO_CUR_SCENE, SO_VISIBLE, SO_SELECTED, SO_ACTIVE,
- SO_SAME_TYPE, SO_GROUPS, SO_LIBRARIES, SO_SEQUENCE, SO_DATABLOCKS,
- SO_USERDEF))
+ if (!ELEM(so->outlinevis,
+ SO_SCENES,
+ SO_GROUPS,
+ SO_LIBRARIES,
+ SO_SEQUENCE,
+ SO_DATABLOCKS))
{
- so->outlinevis = SO_ALL_SCENES;
+ so->outlinevis = SO_SCENES;
}
}
}
@@ -2511,10 +2324,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
if (ts->sculpt)
ts->sculpt->flags |= SCULPT_DYNTOPO_SUBDIVIDE;
- /* single texture mode removed from game engine */
- if (scene->gm.matmode == GAME_MAT_TEXFACE)
- scene->gm.matmode = GAME_MAT_MULTITEX;
-
/* 'Increment' mode disabled for nodes, use true grid snapping instead */
if (scene->toolsettings->snap_node_mode == SCE_SNAP_MODE_INCREMENT)
scene->toolsettings->snap_node_mode = SCE_SNAP_MODE_GRID;
@@ -2541,8 +2350,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
for (ob = main->object.first; ob; ob = ob->id.next) {
ModifierData *md;
- bSensor *bs;
- bActuator *ba;
for (md = ob->modifiers.first; md; md = md->next) {
if (md->type == eModifierType_EdgeSplit) {
@@ -2554,28 +2361,6 @@ void blo_do_versions_260(FileData *fd, Library *UNUSED(lib), Main *main)
bmd->bevel_angle = DEG2RADF(bmd->bevel_angle);
}
}
-
- for (bs = ob->sensors.first; bs; bs = bs->next) {
- if (bs->type == SENS_RADAR) {
- bRadarSensor *brs = bs->data;
- brs->angle = DEG2RADF(brs->angle);
- }
- }
-
- for (ba = ob->actuators.first; ba; ba = ba->next) {
- if (ba->type == ACT_CONSTRAINT) {
- bConstraintActuator *bca = ba->data;
- if (bca->type == ACT_CONST_TYPE_ORI) {
- bca->minloc[0] = DEG2RADF(bca->minloc[0]);
- bca->maxloc[0] = DEG2RADF(bca->maxloc[0]);
- }
- }
- else if (ba->type == ACT_SOUND) {
- bSoundActuator *bsa = ba->data;
- bsa->sound3D.cone_outer_angle = DEG2RADF(bsa->sound3D.cone_outer_angle);
- bsa->sound3D.cone_inner_angle = DEG2RADF(bsa->sound3D.cone_inner_angle);
- }
- }
}
for (scene = main->scene.first; scene; scene = scene->id.next) {
diff --git a/source/blender/blenloader/intern/versioning_270.c b/source/blender/blenloader/intern/versioning_270.c
index 86e6071180e..ee589e511c6 100644
--- a/source/blender/blenloader/intern/versioning_270.c
+++ b/source/blender/blenloader/intern/versioning_270.c
@@ -52,7 +52,6 @@
#include "DNA_modifier_types.h"
#include "DNA_particle_types.h"
#include "DNA_linestyle_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_view3d_types.h"
#include "DNA_smoke_types.h"
#include "DNA_rigidbody_types.h"
@@ -406,7 +405,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
if (!MAIN_VERSION_ATLEAST(main, 270, 1)) {
- Scene *sce;
Object *ob;
/* Update Transform constraint (another deg -> rad stuff). */
@@ -421,12 +419,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
-
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- if (sce->r.raytrace_structure == R_RAYSTRUCTURE_BLIBVH) {
- sce->r.raytrace_structure = R_RAYSTRUCTURE_AUTO;
- }
- }
}
if (!MAIN_VERSION_ATLEAST(main, 270, 2)) {
@@ -489,13 +481,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
if (!MAIN_VERSION_ATLEAST(main, 271, 0)) {
- if (!DNA_struct_elem_find(fd->filesdna, "Material", "int", "mode2")) {
- Material *ma;
-
- for (ma = main->mat.first; ma; ma = ma->id.next)
- ma->mode2 = MA_CASTSHADOW;
- }
-
if (!DNA_struct_elem_find(fd->filesdna, "RenderData", "BakeData", "bake")) {
Scene *sce;
@@ -554,29 +539,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
- if (!MAIN_VERSION_ATLEAST(main, 271, 2)) {
- /* init up & track axis property of trackto actuators */
- Object *ob;
-
- for (ob = main->object.first; ob; ob = ob->id.next) {
- bActuator *act;
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_EDIT_OBJECT) {
- bEditObjectActuator *eoact = act->data;
- eoact->trackflag = ob->trackflag;
- /* if trackflag is pointing +-Z axis then upflag should point Y axis.
- * Rest of trackflag cases, upflag should be point z axis */
- if ((ob->trackflag == OB_POSZ) || (ob->trackflag == OB_NEGZ)) {
- eoact->upflag = 1;
- }
- else {
- eoact->upflag = 2;
- }
- }
- }
- }
- }
-
if (!MAIN_VERSION_ATLEAST(main, 271, 3)) {
Brush *br;
@@ -857,40 +819,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
}
}
-
- if (!DNA_struct_elem_find(fd->filesdna, "GameData", "int", "scehysteresis")) {
- Scene *scene;
- for (scene = main->scene.first; scene; scene = scene->id.next) {
- scene->gm.scehysteresis = 10;
- }
- }
- }
-
- if (!MAIN_VERSION_ATLEAST(main, 274, 2)) {
- FOREACH_NODETREE(main, ntree, id) {
- bNode *node;
- bNodeSocket *sock;
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->type == SH_NODE_MATERIAL) {
- for (sock = node->inputs.first; sock; sock = sock->next) {
- if (STREQ(sock->name, "Refl")) {
- BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
- }
- }
- }
- else if (node->type == SH_NODE_MATERIAL_EXT) {
- for (sock = node->outputs.first; sock; sock = sock->next) {
- if (STREQ(sock->name, "Refl")) {
- BLI_strncpy(sock->name, "DiffuseIntensity", sizeof(sock->name));
- }
- else if (STREQ(sock->name, "Ray Mirror")) {
- BLI_strncpy(sock->name, "Reflectivity", sizeof(sock->name));
- }
- }
- }
- }
- } FOREACH_NODETREE_END
}
if (!MAIN_VERSION_ATLEAST(main, 274, 4)) {
@@ -1092,16 +1020,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
}
#undef LA_YF_PHOTON
}
-
- {
- Object *ob;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- if (ob->body_type == OB_BODY_TYPE_CHARACTER && (ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
- ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
- }
- }
- }
-
}
if (!MAIN_VERSION_ATLEAST(main, 276, 3)) {
@@ -1212,12 +1130,6 @@ void blo_do_versions_270(FileData *fd, Library *UNUSED(lib), Main *main)
else
gpd->flag &= ~GP_DATA_SHOW_ONIONSKINS;
}
-
- if (!DNA_struct_elem_find(fd->filesdna, "Object", "unsigned char", "max_jumps")) {
- for (Object *ob = main->object.first; ob; ob = ob->id.next) {
- ob->max_jumps = 1;
- }
- }
}
if (!MAIN_VERSION_ATLEAST(main, 276, 5)) {
ListBase *lbarray[MAX_LIBARRAY];
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
new file mode 100644
index 00000000000..55bc314d6b4
--- /dev/null
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -0,0 +1,1103 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file blender/blenloader/intern/versioning_280.c
+ * \ingroup blenloader
+ */
+
+/* allow readfile to use deprecated functionality */
+#define DNA_DEPRECATED_ALLOW
+
+#include <string.h>
+#include <float.h>
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_mempool.h"
+#include "BLI_string.h"
+#include "BLI_string_utf8.h"
+#include "BLI_utildefines.h"
+
+#include "DNA_object_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_gpu_types.h"
+#include "DNA_group_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_layer_types.h"
+#include "DNA_lightprobe_types.h"
+#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_genfile.h"
+#include "DNA_workspace_types.h"
+
+#include "BKE_collection.h"
+#include "BKE_constraint.h"
+#include "BKE_customdata.h"
+#include "BKE_freestyle.h"
+#include "BKE_group.h"
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
+#include "BKE_main.h"
+#include "BKE_mesh.h"
+#include "BKE_node.h"
+#include "BKE_report.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_workspace.h"
+
+#include "BLO_readfile.h"
+#include "readfile.h"
+
+#include "MEM_guardedalloc.h"
+
+
+static bScreen *screen_parent_find(const bScreen *screen)
+{
+ /* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
+ if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
+ for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ if (sa->full && sa->full != screen) {
+ BLI_assert(sa->full->state == screen->state);
+ return sa->full;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+static void do_version_workspaces_create_from_screens(Main *bmain)
+{
+ for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+ const bScreen *screen_parent = screen_parent_find(screen);
+ Scene *scene = screen->scene;
+ WorkSpace *workspace;
+ ViewLayer *layer = BLI_findlink(&scene->view_layers, scene->r.actlay);
+ if (!layer) {
+ layer = BKE_view_layer_default_view(scene);
+ }
+
+ if (screen_parent) {
+ /* fullscreen with "Back to Previous" option, don't create
+ * a new workspace, add layout workspace containing parent */
+ workspace = BLI_findstring(
+ &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
+ }
+ else {
+ workspace = BKE_workspace_add(bmain, screen->id.name + 2);
+ }
+ BKE_workspace_layout_add(workspace, screen, screen->id.name + 2);
+ BKE_workspace_view_layer_set(workspace, layer, scene);
+ }
+}
+
+static void do_version_area_change_space_to_space_action(ScrArea *area, const Scene *scene)
+{
+ SpaceType *stype = BKE_spacetype_from_id(SPACE_ACTION);
+ SpaceAction *saction = (SpaceAction *)stype->new(area, scene);
+ ARegion *region_channels;
+
+ /* Properly free current regions */
+ for (ARegion *region = area->regionbase.first; region; region = region->next) {
+ BKE_area_region_free(area->type, region);
+ }
+ BLI_freelistN(&area->regionbase);
+
+ area->type = stype;
+ area->spacetype = stype->spaceid;
+
+ BLI_addhead(&area->spacedata, saction);
+ area->regionbase = saction->regionbase;
+ BLI_listbase_clear(&saction->regionbase);
+
+ /* Different defaults for timeline */
+ region_channels = BKE_area_find_region_type(area, RGN_TYPE_CHANNELS);
+ region_channels->flag |= RGN_FLAG_HIDDEN;
+
+ saction->mode = SACTCONT_TIMELINE;
+ saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
+}
+
+/**
+ * \brief After lib-link versioning for new workspace design.
+ *
+ * * Adds a workspace for (almost) each screen of the old file
+ * and adds the needed workspace-layout to wrap the screen.
+ * * Active screen isn't stored directly in window anymore, but in the active workspace.
+ * * Active scene isn't stored in screen anymore, but in window.
+ * * Create workspace instance hook for each window.
+ *
+ * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
+ */
+static void do_version_workspaces_after_lib_link(Main *bmain)
+{
+ BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
+
+ do_version_workspaces_create_from_screens(bmain);
+
+ for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ bScreen *screen_parent = screen_parent_find(win->screen);
+ bScreen *screen = screen_parent ? screen_parent : win->screen;
+ WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
+ ListBase *layouts = BKE_workspace_layouts_get(workspace);
+
+ win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
+
+ BKE_workspace_active_set(win->workspace_hook, workspace);
+ BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
+
+ win->scene = screen->scene;
+ /* Deprecated from now on! */
+ win->screen = NULL;
+ }
+ }
+
+ for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+ /* Deprecated from now on! */
+ BLI_freelistN(&screen->scene->transform_spaces);
+ screen->scene = NULL;
+ }
+}
+
+enum {
+ DO_VERSION_COLLECTION_VISIBLE = 0,
+ DO_VERSION_COLLECTION_HIDE = 1,
+ DO_VERSION_COLLECTION_HIDE_RENDER = 2,
+ DO_VERSION_COLLECTION_HIDE_ALL = 3,
+};
+
+void do_versions_after_linking_280(Main *main)
+{
+ if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ /* since we don't have access to FileData we check the (always valid) first render layer instead */
+ if (scene->view_layers.first == NULL) {
+ SceneCollection *sc_master = BKE_collection_master(&scene->id);
+ BLI_strncpy(sc_master->name, "Master Collection", sizeof(sc_master->name));
+
+ struct DoVersionSceneCollections {
+ SceneCollection *collections[20];
+ int created;
+ const char *suffix;
+ int flag_viewport;
+ int flag_render;
+ } collections[] =
+ {
+ {
+ .collections = {NULL},
+ .created = 0,
+ .suffix = "",
+ .flag_viewport = COLLECTION_SELECTABLE,
+ .flag_render = COLLECTION_SELECTABLE
+ },
+ {
+ .collections = {NULL},
+ .created = 0,
+ .suffix = " - Hide Viewport",
+ .flag_viewport = COLLECTION_SELECTABLE,
+ .flag_render = COLLECTION_SELECTABLE
+ },
+ {
+ .collections = {NULL},
+ .created = 0,
+ .suffix = " - Hide Render",
+ .flag_viewport = COLLECTION_SELECTABLE,
+ .flag_render = COLLECTION_SELECTABLE | COLLECTION_DISABLED
+ },
+ {
+ .collections = {NULL},
+ .created = 0,
+ .suffix = " - Hide Render All",
+ .flag_viewport = COLLECTION_SELECTABLE | COLLECTION_DISABLED,
+ .flag_render = COLLECTION_SELECTABLE | COLLECTION_DISABLED
+ }
+ };
+
+ for (int layer = 0; layer < 20; layer++) {
+ for (Base *base = scene->base.first; base; base = base->next) {
+ if (base->lay & (1 << layer)) {
+ int collection_index = -1;
+ if ((base->object->restrictflag & OB_RESTRICT_VIEW) &&
+ (base->object->restrictflag & OB_RESTRICT_RENDER))
+ {
+ collection_index = DO_VERSION_COLLECTION_HIDE_ALL;
+ }
+ else if (base->object->restrictflag & OB_RESTRICT_VIEW) {
+ collection_index = DO_VERSION_COLLECTION_HIDE;
+ }
+ else if (base->object->restrictflag & OB_RESTRICT_RENDER) {
+ collection_index = DO_VERSION_COLLECTION_HIDE_RENDER;
+ }
+ else {
+ collection_index = DO_VERSION_COLLECTION_VISIBLE;
+ }
+
+ /* Create collections when needed only. */
+ if ((collections[collection_index].created & (1 << layer)) == 0) {
+ char name[MAX_NAME];
+
+ if ((collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) == 0) {
+ BLI_snprintf(name,
+ sizeof(sc_master->name),
+ "Collection %d%s",
+ layer + 1,
+ collections[DO_VERSION_COLLECTION_VISIBLE].suffix);
+ collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer] =
+ BKE_collection_add(&scene->id, sc_master, COLLECTION_TYPE_NONE, name);
+ collections[DO_VERSION_COLLECTION_VISIBLE].created |= (1 << layer);
+ }
+
+ if (collection_index != DO_VERSION_COLLECTION_VISIBLE) {
+ SceneCollection *sc_parent;
+ sc_parent = collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer];
+ BLI_snprintf(name,
+ sizeof(sc_master->name),
+ "Collection %d%s",
+ layer + 1,
+ collections[collection_index].suffix);
+ collections[collection_index].collections[layer] = BKE_collection_add(
+ &scene->id,
+ sc_parent,
+ COLLECTION_TYPE_NONE,
+ name);
+ collections[collection_index].created |= (1 << layer);
+ }
+ }
+
+ BKE_collection_object_add(
+ &scene->id, collections[collection_index].collections[layer], base->object);
+ }
+
+ if (base->flag & SELECT) {
+ base->object->flag |= SELECT;
+ }
+ else {
+ base->object->flag &= ~SELECT;
+ }
+ }
+ }
+
+ /* Re-order the nested hidden collections. */
+ SceneCollection *scene_collection_parent = sc_master->scene_collections.first;
+
+ for (int layer = 0; layer < 20; layer++) {
+ if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
+
+ if ((collections[DO_VERSION_COLLECTION_HIDE].created & (1 << layer)) &&
+ (collections[DO_VERSION_COLLECTION_HIDE].collections[layer] !=
+ scene_collection_parent->scene_collections.first))
+ {
+ BLI_listbase_swaplinks(
+ &scene_collection_parent->scene_collections,
+ collections[DO_VERSION_COLLECTION_HIDE].collections[layer],
+ scene_collection_parent->scene_collections.first);
+ }
+
+ if ((collections[DO_VERSION_COLLECTION_HIDE_ALL].created & (1 << layer)) &&
+ (collections[DO_VERSION_COLLECTION_HIDE_ALL].collections[layer] !=
+ scene_collection_parent->scene_collections.last))
+ {
+ BLI_listbase_swaplinks(
+ &scene_collection_parent->scene_collections,
+ collections[DO_VERSION_COLLECTION_HIDE_ALL].collections[layer],
+ scene_collection_parent->scene_collections.last);
+ }
+
+ scene_collection_parent = scene_collection_parent->next;
+ }
+ }
+ BLI_assert(scene_collection_parent == NULL);
+
+ /* Handle legacy render layers. */
+ {
+ for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
+
+ ViewLayer *view_layer = BKE_view_layer_add(scene, srl->name);
+
+ if (srl->samples != 0) {
+ /* It is up to the external engine to handle
+ * its own doversion in this case. */
+ BKE_override_view_layer_int_add(
+ view_layer,
+ ID_SCE,
+ "samples",
+ srl->samples);
+ }
+
+ if (srl->mat_override) {
+ BKE_override_view_layer_datablock_add(
+ view_layer,
+ ID_MA,
+ "self",
+ (ID *)srl->mat_override);
+ }
+
+ if (srl->layflag & SCE_LAY_DISABLE) {
+ view_layer->flag &= ~VIEW_LAYER_RENDER;
+ }
+
+ if ((srl->layflag & SCE_LAY_FRS) == 0) {
+ view_layer->flag &= ~VIEW_LAYER_FREESTYLE;
+ }
+
+ /* XXX If we are to keep layflag it should be merged with flag (dfelinto). */
+ view_layer->layflag = srl->layflag;
+ /* XXX Not sure if we should keep the passes (dfelinto). */
+ view_layer->passflag = srl->passflag;
+ view_layer->pass_xor = srl->pass_xor;
+ view_layer->pass_alpha_threshold = srl->pass_alpha_threshold;
+
+ BKE_freestyle_config_free(&view_layer->freestyle_config, true);
+ view_layer->freestyle_config = srl->freestyleConfig;
+ view_layer->id_properties = srl->prop;
+
+ /* unlink master collection */
+ BKE_collection_unlink(view_layer, view_layer->layer_collections.first);
+
+ /* Add new collection bases. */
+ for (int layer = 0; layer < 20; layer++) {
+ if ((scene->lay & srl->lay & ~(srl->lay_exclude) & (1 << layer)) ||
+ (srl->lay_zmask & (scene->lay | srl->lay_exclude) & (1 << layer)))
+ {
+ if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
+
+ LayerCollection *layer_collection_parent;
+ layer_collection_parent = BKE_collection_link(
+ view_layer,
+ collections[DO_VERSION_COLLECTION_VISIBLE].collections[layer]);
+
+ if (srl->lay_zmask & (1 << layer)) {
+ BKE_override_layer_collection_boolean_add(
+ layer_collection_parent,
+ ID_OB,
+ "cycles.is_holdout",
+ true);
+ }
+
+ if ((srl->lay & (1 << layer)) == 0) {
+ BKE_override_layer_collection_boolean_add(
+ layer_collection_parent,
+ ID_OB,
+ "cycles_visibility.camera",
+ false);
+ }
+
+ LayerCollection *layer_collection_child;
+ layer_collection_child = layer_collection_parent->layer_collections.first;
+
+ for (int j = 1; j < 4; j++) {
+ if (collections[j].created & (1 << layer)) {
+ layer_collection_child->flag = COLLECTION_VIEWPORT |
+ COLLECTION_RENDER |
+ collections[j].flag_render;
+ layer_collection_child = layer_collection_child->next;
+ }
+ }
+ BLI_assert(layer_collection_child == NULL);
+ }
+ }
+ }
+
+ /* for convenience set the same active object in all the layers */
+ if (scene->basact) {
+ view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
+ }
+
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
+ base->flag |= BASE_SELECTED;
+ }
+ }
+ }
+ }
+ BLI_freelistN(&scene->r.layers);
+
+ ViewLayer *view_layer = BKE_view_layer_add(scene, "Viewport");
+ /* If we ported all the original render layers, we don't need to make the viewport layer renderable. */
+ if (!BLI_listbase_is_single(&scene->view_layers)) {
+ view_layer->flag &= ~VIEW_LAYER_RENDER;
+ }
+
+ /* If layer was not set, disable it. */
+ LayerCollection *layer_collection_parent;
+ layer_collection_parent =
+ ((LayerCollection *)view_layer->layer_collections.first)->layer_collections.first;
+
+ for (int layer = 0; layer < 20; layer++) {
+ if (collections[DO_VERSION_COLLECTION_VISIBLE].created & (1 << layer)) {
+ const bool is_disabled = (scene->lay & (1 << layer)) == 0;
+
+ /* We only need to disable the parent collection. */
+ if (is_disabled) {
+ layer_collection_parent->flag |= COLLECTION_DISABLED;
+ }
+
+ LayerCollection *layer_collection_child;
+ layer_collection_child = layer_collection_parent->layer_collections.first;
+
+ for (int j = 1; j < 4; j++) {
+ if (collections[j].created & (1 << layer)) {
+ layer_collection_child->flag = COLLECTION_VIEWPORT |
+ COLLECTION_RENDER |
+ collections[j].flag_viewport;
+ layer_collection_child = layer_collection_child->next;
+ }
+ }
+ BLI_assert(layer_collection_child == NULL);
+ layer_collection_parent = layer_collection_parent->next;
+ }
+ }
+ BLI_assert(layer_collection_parent == NULL);
+
+ /* convert active base */
+ if (scene->basact) {
+ view_layer->basact = BKE_view_layer_base_find(view_layer, scene->basact->object);
+ }
+
+ /* convert selected bases */
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if ((base->flag & BASE_SELECTABLED) && (base->object->flag & SELECT)) {
+ base->flag |= BASE_SELECTED;
+ }
+
+ /* keep lay around for forward compatibility (open those files in 2.79) */
+ base->lay = base->object->lay;
+ }
+
+ /* remove bases once and for all */
+ for (Base *base = scene->base.first; base; base = base->next) {
+ id_us_min(&base->object->id);
+ }
+ BLI_freelistN(&scene->base);
+ scene->basact = NULL;
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
+ for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+ /* same render-layer as do_version_workspaces_after_lib_link will activate,
+ * so same layer as BKE_view_layer_from_workspace_get would return */
+ ViewLayer *layer = screen->scene->view_layers.first;
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *view_layer = sa->spacedata.first; view_layer; view_layer = view_layer->next) {
+ if (view_layer->spacetype == SPACE_OUTLINER) {
+ SpaceOops *soutliner = (SpaceOops *)view_layer;
+
+ soutliner->outlinevis = SO_COLLECTIONS;
+
+ if (BLI_listbase_count_at_most(&layer->layer_collections, 2) == 1) {
+ if (soutliner->treestore == NULL) {
+ soutliner->treestore = BLI_mempool_create(
+ sizeof(TreeStoreElem), 1, 512, BLI_MEMPOOL_ALLOW_ITER);
+ }
+
+ /* Create a tree store element for the collection. This is normally
+ * done in check_persistent (outliner_tree.c), but we need to access
+ * it here :/ (expand element if it's the only one) */
+ TreeStoreElem *tselem = BLI_mempool_calloc(soutliner->treestore);
+ tselem->type = TSE_LAYER_COLLECTION;
+ tselem->id = layer->layer_collections.first;
+ tselem->nr = tselem->used = 0;
+ tselem->flag &= ~TSE_CLOSED;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* New workspace design */
+ if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
+ do_version_workspaces_after_lib_link(main);
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 2)) {
+ /* Cleanup any remaining SceneRenderLayer data for files that were created
+ * with Blender 2.8 before the SceneRenderLayer > RenderLayer refactor. */
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
+ if (srl->prop) {
+ IDP_FreeProperty(srl->prop);
+ MEM_freeN(srl->prop);
+ }
+ BKE_freestyle_config_free(&srl->freestyleConfig, true);
+ }
+ BLI_freelistN(&scene->r.layers);
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 3)) {
+ /* Due to several changes to particle RNA and draw code particles from older files may no longer
+ * be visible. Here we correct this by setting a default draw size for those files. */
+ for (Object *object = main->object.first; object; object = object->id.next) {
+ for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
+ if (psys->part->draw_size == 0.0f) {
+ psys->part->draw_size = 0.1f;
+ }
+ }
+ }
+ }
+
+ {
+ for (WorkSpace *workspace = main->workspaces.first; workspace; workspace = workspace->id.next) {
+ if (workspace->view_layer) {
+ /* During 2.8 work we temporarly stored view-layer in the
+ * workspace directly, but should be stored there per-scene. */
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ if (BLI_findindex(&scene->view_layers, workspace->view_layer) != -1) {
+ BKE_workspace_view_layer_set(workspace, workspace->view_layer, scene);
+ workspace->view_layer = NULL;
+ }
+ }
+ }
+ /* While this should apply to most cases, it fails when reading workspaces.blend
+ * to get its list of workspaces without actually appending any of them. */
+// BLI_assert(workspace->view_layer == NULL);
+ }
+ }
+
+ {
+ /* Since we don't have access to FileData we check the (always valid) master collection of the group. */
+ for (Group *group = main->group.first; group; group = group->id.next) {
+ if (group->collection == NULL) {
+ BKE_group_init(group);
+ SceneCollection *sc = GROUP_MASTER_COLLECTION(group);
+ SceneCollection *sc_hidden = NULL;
+
+ for (GroupObject *go = group->gobject.first; go; go = go->next) {
+ if (go->ob->lay & group->layer) {
+ BKE_collection_object_add(&group->id, sc, go->ob);
+ }
+ else {
+ if (sc_hidden == NULL) {
+ sc_hidden = BKE_collection_add(&group->id, sc, COLLECTION_TYPE_GROUP_INTERNAL, "Hidden");
+ }
+ BKE_collection_object_add(&group->id, sc_hidden, go->ob);
+ }
+ }
+
+ if (sc_hidden != NULL) {
+ LayerCollection *layer_collection_master, *layer_collection_hidden;
+ layer_collection_master = group->view_layer->layer_collections.first;
+ layer_collection_hidden = layer_collection_master->layer_collections.first;
+ layer_collection_hidden->flag |= COLLECTION_DISABLED;
+ }
+ }
+
+ GroupObject *go;
+ while ((go = BLI_pophead(&group->gobject))) {
+ MEM_freeN(go);
+ }
+ }
+ }
+
+ {
+ for (Object *object = main->object.first; object; object = object->id.next) {
+#ifndef VERSION_280_SUBVERSION_4
+ /* If any object already has an initialized value for
+ * duplicator_visibility_flag it means we've already doversioned it.
+ * TODO(all) remove the VERSION_280_SUBVERSION_4 code once the subversion was bumped. */
+ if (object->duplicator_visibility_flag != 0) {
+ break;
+ }
+#endif
+ if (object->particlesystem.first) {
+ object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
+ for (ParticleSystem *psys = object->particlesystem.first; psys; psys = psys->next) {
+ if (psys->part->draw & PART_DRAW_EMITTER) {
+ object->duplicator_visibility_flag |= OB_DUPLI_FLAG_RENDER;
+#ifndef VERSION_280_SUBVERSION_4
+ psys->part->draw &= ~PART_DRAW_EMITTER;
+#else
+ break;
+#endif
+ }
+ }
+ }
+ else if (object->transflag & OB_DUPLI) {
+ object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT;
+ }
+ else {
+ object->duplicator_visibility_flag = OB_DUPLI_FLAG_VIEWPORT | OB_DUPLI_FLAG_RENDER;
+ }
+ }
+ }
+
+ /* SpaceTime & SpaceLogic removal/replacing */
+ if (!MAIN_VERSION_ATLEAST(main, 280, 9)) {
+ const wmWindowManager *wm = main->wm.first;
+ const Scene *scene = main->scene.first;
+
+ if (wm != NULL) {
+ /* Action editors need a scene for creation. First, update active
+ * screens using the active scene of the window they're displayed in.
+ * Next, update remaining screens using first scene in main listbase. */
+
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
+ for (ScrArea *area = screen->areabase.first; area; area = area->next) {
+ if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
+ do_version_area_change_space_to_space_action(area, win->scene);
+
+ /* Don't forget to unset! */
+ area->butspacetype = SPACE_EMPTY;
+ }
+ }
+ }
+ }
+ if (scene != NULL) {
+ for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+ for (ScrArea *area = screen->areabase.first; area; area = area->next) {
+ if (ELEM(area->butspacetype, SPACE_TIME, SPACE_LOGIC)) {
+ /* Areas that were already handled won't be handled again */
+ do_version_area_change_space_to_space_action(area, scene);
+
+ /* Don't forget to unset! */
+ area->butspacetype = SPACE_EMPTY;
+ }
+ }
+ }
+ }
+ }
+}
+
+static void do_version_layer_collections_idproperties(ListBase *lb)
+{
+ IDPropertyTemplate val = {0};
+ for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+ lc->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ BKE_layer_collection_engine_settings_create(lc->properties);
+
+ /* No overrides at first */
+ for (IDProperty *prop = lc->properties->data.group.first; prop; prop = prop->next) {
+ while (prop->data.group.first) {
+ IDP_FreeFromGroup(prop, prop->data.group.first);
+ }
+ }
+
+ /* Do it recursively */
+ do_version_layer_collections_idproperties(&lc->layer_collections);
+ }
+}
+
+static void do_version_view_layer_visibility(ViewLayer *view_layer)
+{
+ LayerCollection *layer_collection;
+ for (layer_collection = view_layer->layer_collections.first;
+ layer_collection;
+ layer_collection = layer_collection->next)
+ {
+ if (layer_collection->flag & COLLECTION_DISABLED) {
+ BKE_collection_enable(view_layer, layer_collection);
+ layer_collection->flag &= ~COLLECTION_DISABLED;
+ }
+
+ if ((layer_collection->flag & (1 << 0)) == 0) { /* !COLLECTION_VISIBLE */
+ layer_collection->flag |= COLLECTION_DISABLED;
+ }
+ layer_collection->flag |= COLLECTION_VIEWPORT | COLLECTION_RENDER;
+ }
+}
+
+void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
+{
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 0)) {
+ if (!DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers")) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ /* Master Collection */
+ scene->collection = MEM_callocN(sizeof(SceneCollection), "Master Collection");
+ BLI_strncpy(scene->collection->name, "Master Collection", sizeof(scene->collection->name));
+ }
+ }
+
+ if (DNA_struct_elem_find(fd->filesdna, "LayerCollection", "ListBase", "engine_settings") &&
+ !DNA_struct_elem_find(fd->filesdna, "LayerCollection", "IDProperty", "properties"))
+ {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ do_version_layer_collections_idproperties(&view_layer->layer_collections);
+ }
+ }
+ }
+
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ scene->r.gauss = 1.5f;
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 1)) {
+ if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "bleedexp")) {
+ for (Lamp *la = main->lamp.first; la; la = la->id.next) {
+ la->bleedexp = 2.5f;
+ }
+ }
+
+ if (!DNA_struct_elem_find(fd->filesdna, "GPUDOFSettings", "float", "ratio")) {
+ for (Camera *ca = main->camera.first; ca; ca = ca->id.next) {
+ ca->gpu_dof.ratio = 1.0f;
+ }
+ }
+
+ if (!DNA_struct_elem_find(fd->filesdna, "ViewLayer", "IDProperty", "*properties")) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ IDPropertyTemplate val = {0};
+ view_layer->properties = IDP_New(IDP_GROUP, &val, ROOT_PROP);
+ BKE_view_layer_engine_settings_create(view_layer->properties);
+ }
+ }
+ }
+
+ /* MTexPoly now removed. */
+ if (DNA_struct_find(fd->filesdna, "MTexPoly")) {
+ const int cd_mtexpoly = 15; /* CD_MTEXPOLY, deprecated */
+ for (Mesh *me = main->mesh.first; me; me = me->id.next) {
+ /* If we have UV's, so this file will have MTexPoly layers too! */
+ if (me->mloopuv != NULL) {
+ CustomData_update_typemap(&me->pdata);
+ CustomData_free_layers(&me->pdata, cd_mtexpoly, me->totpoly);
+ BKE_mesh_update_customdata_pointers(me, false);
+ }
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 2)) {
+ if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "cascade_max_dist")) {
+ for (Lamp *la = main->lamp.first; la; la = la->id.next) {
+ la->cascade_max_dist = 1000.0f;
+ la->cascade_count = 4;
+ la->cascade_exponent = 0.8f;
+ la->cascade_fade = 0.1f;
+ }
+ }
+
+ if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "contact_dist")) {
+ for (Lamp *la = main->lamp.first; la; la = la->id.next) {
+ la->contact_dist = 1.0f;
+ la->contact_bias = 0.03f;
+ la->contact_spread = 0.2f;
+ la->contact_thickness = 0.5f;
+ }
+ }
+
+ if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "vis_bias")) {
+ for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
+ probe->vis_bias = 1.0f;
+ probe->vis_blur = 0.2f;
+ }
+ }
+
+ typedef enum eNTreeDoVersionErrors {
+ NTREE_DOVERSION_NO_ERROR = 0,
+ NTREE_DOVERSION_NEED_OUTPUT = (1 << 0),
+ NTREE_DOVERSION_TRANSPARENCY_EMISSION = (1 << 1),
+ } eNTreeDoVersionErrors;
+
+ /* Eevee shader nodes renamed because of the output node system.
+ * Note that a new output node is not being added here, because it would be overkill
+ * to handle this case in lib_verify_nodetree.
+ *
+ * Also, metallic node is now unified into the principled node. */
+ eNTreeDoVersionErrors error = NTREE_DOVERSION_NO_ERROR;
+
+ FOREACH_NODETREE(main, ntree, id) {
+ if (ntree->type == NTREE_SHADER) {
+ for (bNode *node = ntree->nodes.first; node; node = node->next) {
+ if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
+ STREQ(node->idname, "ShaderNodeOutputMetallic"))
+ {
+ BLI_strncpy(node->idname, "ShaderNodeEeveeMetallic", sizeof(node->idname));
+ error |= NTREE_DOVERSION_NEED_OUTPUT;
+ }
+
+ else if (node->type == SH_NODE_EEVEE_SPECULAR && STREQ(node->idname, "ShaderNodeOutputSpecular")) {
+ BLI_strncpy(node->idname, "ShaderNodeEeveeSpecular", sizeof(node->idname));
+ error |= NTREE_DOVERSION_NEED_OUTPUT;
+ }
+
+ else if (node->type == 196 /* SH_NODE_OUTPUT_EEVEE_MATERIAL */ &&
+ STREQ(node->idname, "ShaderNodeOutputEeveeMaterial"))
+ {
+ node->type = SH_NODE_OUTPUT_MATERIAL;
+ BLI_strncpy(node->idname, "ShaderNodeOutputMaterial", sizeof(node->idname));
+ }
+
+ else if (node->type == 194 /* SH_NODE_EEVEE_METALLIC */ &&
+ STREQ(node->idname, "ShaderNodeEeveeMetallic"))
+ {
+ node->type = SH_NODE_BSDF_PRINCIPLED;
+ BLI_strncpy(node->idname, "ShaderNodeBsdfPrincipled", sizeof(node->idname));
+ node->custom1 = SHD_GLOSSY_MULTI_GGX;
+ error |= NTREE_DOVERSION_TRANSPARENCY_EMISSION;
+ }
+ }
+ }
+ } FOREACH_NODETREE_END
+
+ if (error & NTREE_DOVERSION_NEED_OUTPUT) {
+ BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
+ printf("You need to connect Principled and Eevee Specular shader nodes to new material output nodes.\n");
+ }
+
+ if (error & NTREE_DOVERSION_TRANSPARENCY_EMISSION) {
+ BKE_report(fd->reports, RPT_ERROR, "Eevee material conversion problem. Error in console");
+ printf("You need to combine transparency and emission shaders to the converted Principled shader nodes.\n");
+ }
+
+ if ((DNA_struct_elem_find(fd->filesdna, "ViewLayer", "FreestyleConfig", "freestyle_config") == false) &&
+ DNA_struct_elem_find(fd->filesdna, "Scene", "ListBase", "view_layers"))
+ {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ ViewLayer *view_layer;
+ for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ view_layer->flag |= VIEW_LAYER_FREESTYLE;
+ view_layer->layflag = 0x7FFF; /* solid ztra halo edge strand */
+ view_layer->passflag = SCE_PASS_COMBINED | SCE_PASS_Z;
+ view_layer->pass_alpha_threshold = 0.5f;
+ BKE_freestyle_config_init(&view_layer->freestyle_config);
+ }
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 3)) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ ViewLayer *view_layer;
+ for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ do_version_view_layer_visibility(view_layer);
+ }
+ }
+
+ for (Group *group = main->group.first; group; group = group->id.next) {
+ if (group->view_layer != NULL) {
+ do_version_view_layer_visibility(group->view_layer);
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 6)) {
+ if (DNA_struct_elem_find(fd->filesdna, "SpaceOops", "int", "filter") == false) {
+ bScreen *sc;
+ ScrArea *sa;
+ SpaceLink *sl;
+
+ /* Update files using invalid (outdated) outlinevis Outliner values. */
+ for (sc = main->screen.first; sc; sc = sc->id.next) {
+ for (sa = sc->areabase.first; sa; sa = sa->next) {
+ for (sl = sa->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_OUTLINER) {
+ SpaceOops *so = (SpaceOops *)sl;
+
+ if (!ELEM(so->outlinevis,
+ SO_SCENES,
+ SO_GROUPS,
+ SO_LIBRARIES,
+ SO_SEQUENCE,
+ SO_DATABLOCKS,
+ SO_ID_ORPHANS,
+ SO_COLLECTIONS))
+ {
+ so->outlinevis = SO_COLLECTIONS;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (!DNA_struct_elem_find(fd->filesdna, "LightProbe", "float", "intensity")) {
+ for (LightProbe *probe = main->lightprobe.first; probe; probe = probe->id.next) {
+ probe->intensity = 1.0f;
+ }
+ }
+
+ for (Object *ob = main->object.first; ob; ob = ob->id.next) {
+ bConstraint *con, *con_next;
+ con = ob->constraints.first;
+ while (con) {
+ con_next = con->next;
+ if (con->type == 17) { /* CONSTRAINT_TYPE_RIGIDBODYJOINT */
+ BLI_remlink(&ob->constraints, con);
+ BKE_constraint_free_data(con);
+ MEM_freeN(con);
+ }
+ con = con_next;
+ }
+ }
+
+ if (!DNA_struct_elem_find(fd->filesdna, "Scene", "int", "orientation_index_custom")) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ scene->orientation_index_custom = -1;
+ }
+ }
+
+ for (bScreen *sc = main->screen.first; sc; sc = sc->id.next) {
+ for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
+ v3d->shading.light = V3D_LIGHTING_STUDIO;
+
+ /* Assume (demo) files written with 2.8 want to show
+ * Eevee renders in the viewport. */
+ if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
+ v3d->drawtype = OB_MATERIAL;
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 7)) {
+ /* Render engine storage moved elsewhere and back during 2.8
+ * development, we assume any files saved in 2.8 had Eevee set
+ * as scene render engine. */
+ if (MAIN_VERSION_ATLEAST(main, 280, 0)) {
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 8)) {
+ /* Blender Internal removal */
+ for (Scene *scene = main->scene.first; scene; scene = scene->id.next) {
+ if (STREQ(scene->r.engine, "BLENDER_RENDER") ||
+ STREQ(scene->r.engine, "BLENDER_GAME"))
+ {
+ BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
+ }
+
+ scene->r.bake_mode = 0;
+ }
+
+ for (Tex *tex = main->tex.first; tex; tex = tex->id.next) {
+ /* Removed envmap, pointdensity, voxeldata, ocean textures. */
+ if (ELEM(tex->type, 10, 14, 15, 16)) {
+ tex->type = 0;
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
+
+ /* Remove info editor, but only if at the top of the window. */
+ for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+ /* Calculate window width/height from screen vertices */
+ int win_width = 0, win_height = 0;
+ for (ScrVert *vert = screen->vertbase.first; vert; vert = vert->next) {
+ win_width = MAX2(win_width, vert->vec.x);
+ win_height = MAX2(win_height, vert->vec.y);
+ }
+
+ for (ScrArea *area = screen->areabase.first, *area_next; area; area = area_next) {
+ area_next = area->next;
+
+ if (area->spacetype == SPACE_INFO) {
+ if ((area->v2->vec.y == win_height) && (area->v1->vec.x == 0) && (area->v4->vec.x == win_width)) {
+ BKE_screen_area_free(area);
+
+ BLI_remlink(&screen->areabase, area);
+
+ BKE_screen_remove_double_scredges(screen);
+ BKE_screen_remove_unused_scredges(screen);
+ BKE_screen_remove_unused_scrverts(screen);
+
+ MEM_freeN(area);
+ }
+ }
+ /* AREA_TEMP_INFO is deprecated from now on, it should only be set for info areas
+ * which are deleted above, so don't need to unset it. Its slot/bit can be reused */
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 11)) {
+ for (Lamp *lamp = main->lamp.first; lamp; lamp = lamp->id.next) {
+ if (lamp->mode & (1 << 13)) { /* LA_SHAD_RAY */
+ lamp->mode |= LA_SHADOW;
+ lamp->mode &= ~(1 << 13);
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 12)) {
+ /* Remove tool property regions. */
+ for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+ if (ELEM(sl->spacetype, SPACE_VIEW3D, SPACE_CLIP)) {
+ ListBase *regionbase = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
+
+ for (ARegion *region = regionbase->first, *region_next; region; region = region_next) {
+ region_next = region->next;
+
+ if (region->regiontype == RGN_TYPE_TOOL_PROPS) {
+ BKE_area_region_free(NULL, region);
+ BLI_freelinkN(regionbase, region);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ if (!MAIN_VERSION_ATLEAST(main, 280, 13)) {
+ /* Initialize specular factor. */
+ if (!DNA_struct_elem_find(fd->filesdna, "Lamp", "float", "spec_fac")) {
+ for (Lamp *la = main->lamp.first; la; la = la->id.next) {
+ la->spec_fac = 1.0f;
+ }
+ }
+
+ /* Initialize new view3D options. */
+ for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
+ v3d->shading.light = V3D_LIGHTING_STUDIO;
+ v3d->shading.color_type = V3D_SHADING_MATERIAL_COLOR;
+ copy_v3_fl(v3d->shading.single_color, 0.8f);
+ v3d->shading.shadow_intensity = 0.5;
+
+ v3d->overlay.backwire_opacity = 0.5f;
+ v3d->overlay.normals_length = 0.1f;
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/source/blender/blenloader/intern/versioning_defaults.c b/source/blender/blenloader/intern/versioning_defaults.c
index 7e05ba1f529..3211ed4fc11 100644
--- a/source/blender/blenloader/intern/versioning_defaults.c
+++ b/source/blender/blenloader/intern/versioning_defaults.c
@@ -28,6 +28,7 @@
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_math.h"
+#include "BLI_string.h"
#include "DNA_brush_types.h"
#include "DNA_freestyle_types.h"
@@ -39,10 +40,13 @@
#include "DNA_mesh_types.h"
#include "DNA_material_types.h"
#include "DNA_object_types.h"
+#include "DNA_workspace_types.h"
#include "BKE_brush.h"
#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_scene.h"
+#include "BKE_workspace.h"
#include "BLO_readfile.h"
@@ -86,17 +90,45 @@ void BLO_update_defaults_userpref_blend(void)
}
/**
+ * New workspace design: Remove all screens/workspaces except of "Default" one and rename the workspace to "General".
+ * For compatibility, a new workspace has been created for each screen of old files,
+ * we only want one workspace and one screen in the default startup file however.
+ */
+static void update_defaults_startup_workspaces(Main *bmain)
+{
+ WorkSpace *workspace_default = NULL;
+
+ for (WorkSpace *workspace = bmain->workspaces.first, *workspace_next; workspace; workspace = workspace_next) {
+ workspace_next = workspace->id.next;
+
+ if (STREQ(workspace->id.name + 2, "Default")) {
+ /* don't rename within iterator, renaming causes listbase to be re-sorted */
+ workspace_default = workspace;
+ }
+ else {
+ BKE_workspace_remove(bmain, workspace);
+ }
+ }
+
+ /* rename "Default" workspace to "General" */
+ BKE_libblock_rename(bmain, (ID *)workspace_default, "General");
+ BLI_assert(BLI_listbase_count(BKE_workspace_layouts_get(workspace_default)) == 1);
+}
+
+/**
* Update defaults in startup.blend, without having to save and embed the file.
* This function can be emptied each time the startup.blend is updated. */
void BLO_update_defaults_startup_blend(Main *bmain)
{
for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
+ BLI_strncpy(scene->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(scene->r.engine));
+
scene->r.im_format.planes = R_IMF_PLANES_RGBA;
scene->r.im_format.compress = 15;
- for (SceneRenderLayer *srl = scene->r.layers.first; srl; srl = srl->next) {
- srl->freestyleConfig.sphere_radius = 0.1f;
- srl->pass_alpha_threshold = 0.5f;
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ view_layer->freestyle_config.sphere_radius = 0.1f;
+ view_layer->pass_alpha_threshold = 0.5f;
}
if (scene->toolsettings) {
@@ -177,10 +209,12 @@ void BLO_update_defaults_startup_blend(Main *bmain)
pset->brush[PE_BRUSH_CUT].strength = 1.0f;
}
- scene->gm.lodflag |= SCE_LOD_USE_HYST;
- scene->gm.scehysteresis = 10;
-
scene->r.ffcodecdata.audio_mixrate = 48000;
+
+ /* set av sync by default */
+ printf("setting new default audio\n");
+ scene->audio.flag |= AUDIO_SYNC;
+ scene->flag &= ~SCE_FRAME_DROP;
}
for (FreestyleLineStyle *linestyle = bmain->linestyle.first; linestyle; linestyle = linestyle->id.next) {
@@ -191,20 +225,18 @@ void BLO_update_defaults_startup_blend(Main *bmain)
linestyle->chain_count = 10;
}
- for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
- ScrArea *area;
- for (area = screen->areabase.first; area; area = area->next) {
- SpaceLink *space_link;
- ARegion *ar;
+ update_defaults_startup_workspaces(bmain);
- for (space_link = area->spacedata.first; space_link; space_link = space_link->next) {
+ for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+ for (ScrArea *area = screen->areabase.first; area; area = area->next) {
+ for (SpaceLink *space_link = area->spacedata.first; space_link; space_link = space_link->next) {
if (space_link->spacetype == SPACE_CLIP) {
SpaceClip *space_clip = (SpaceClip *) space_link;
space_clip->flag &= ~SC_MANUAL_CALIBRATION;
}
}
- for (ar = area->regionbase.first; ar; ar = ar->next) {
+ for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
/* Remove all stored panels, we want to use defaults (order, open/closed) as defined by UI code here! */
BLI_freelistN(&ar->panels);
diff --git a/source/blender/blenloader/intern/versioning_legacy.c b/source/blender/blenloader/intern/versioning_legacy.c
index 80490081337..57530c6a004 100644
--- a/source/blender/blenloader/intern/versioning_legacy.c
+++ b/source/blender/blenloader/intern/versioning_legacy.c
@@ -45,7 +45,6 @@
#define DNA_DEPRECATED_ALLOW
#include "DNA_armature_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_camera_types.h"
#include "DNA_constraint_types.h"
#include "DNA_effect_types.h"
@@ -60,10 +59,8 @@
#include "DNA_node_types.h"
#include "DNA_object_fluidsim_types.h"
#include "DNA_object_types.h"
-#include "DNA_property_types.h"
#include "DNA_view3d_types.h"
#include "DNA_screen_types.h"
-#include "DNA_sensor_types.h"
#include "DNA_sdna_types.h"
#include "DNA_sequence_types.h"
#include "DNA_sound_types.h"
@@ -90,7 +87,6 @@
#include "BKE_modifier.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
-#include "BKE_property.h" // for BKE_bproperty_object_get
#include "BKE_scene.h"
#include "BKE_sequencer.h"
@@ -128,38 +124,6 @@ static void vcol_to_fcol(Mesh *me)
me->mcol = (MCol *)mcolmain;
}
-static int map_223_keybd_code_to_224_keybd_code(int code)
-{
- switch (code) {
- case 312:
- return 311; /* F12KEY */
- case 159:
- return 161; /* PADSLASHKEY */
- case 161:
- return 150; /* PAD0 */
- case 154:
- return 151; /* PAD1 */
- case 150:
- return 152; /* PAD2 */
- case 155:
- return 153; /* PAD3 */
- case 151:
- return 154; /* PAD4 */
- case 156:
- return 155; /* PAD5 */
- case 152:
- return 156; /* PAD6 */
- case 157:
- return 157; /* PAD7 */
- case 153:
- return 158; /* PAD8 */
- case 158:
- return 159; /* PAD9 */
- default:
- return code;
- }
-}
-
static void do_version_bone_head_tail_237(Bone *bone)
{
Bone *child;
@@ -248,12 +212,6 @@ static void ntree_version_242(bNodeTree *ntree)
}
}
}
- else if (ntree->type == NTREE_SHADER) {
- for (node = ntree->nodes.first; node; node = node->next)
- if (node->type == SH_NODE_GEOMETRY && node->storage == NULL)
- node->storage = MEM_callocN(sizeof(NodeGeometry), "NodeGeometry");
- }
-
}
static void ntree_version_245(FileData *fd, Library *lib, bNodeTree *ntree)
@@ -319,55 +277,6 @@ static void idproperties_fix_group_lengths(ListBase idlist)
}
}
-static void alphasort_version_246(FileData *fd, Library *lib, Mesh *me)
-{
- Material *ma;
- MFace *mf;
- MTFace *tf;
- int a, b, texalpha;
-
- /* verify we have a tface layer */
- for (b = 0; b < me->fdata.totlayer; b++)
- if (me->fdata.layers[b].type == CD_MTFACE)
- break;
-
- if (b == me->fdata.totlayer)
- return;
-
- /* if we do, set alpha sort if the game engine did it before */
- for (a = 0, mf = me->mface; a < me->totface; a++, mf++) {
- if (mf->mat_nr < me->totcol) {
- ma = blo_do_versions_newlibadr(fd, lib, me->mat[mf->mat_nr]);
- texalpha = 0;
-
- /* we can't read from this if it comes from a library,
- * because direct_link might not have happened on it,
- * so ma->mtex is not pointing to valid memory yet */
- if (ma && ma->id.lib)
- ma = NULL;
-
- for (b = 0; ma && b < MAX_MTEX; b++)
- if (ma->mtex[b] && ma->mtex[b]->mapto & MAP_ALPHA)
- texalpha = 1;
- }
- else {
- ma = NULL;
- texalpha = 0;
- }
-
- for (b = 0; b < me->fdata.totlayer; b++) {
- if (me->fdata.layers[b].type == CD_MTFACE) {
- tf = ((MTFace*)me->fdata.layers[b].data) + a;
-
- tf->mode &= ~TF_ALPHASORT;
- if (ma && (ma->mode & MA_ZTRANSP))
- if (ELEM(tf->transp, TF_ALPHA, TF_ADD) || (texalpha && (tf->transp != TF_CLIP)))
- tf->mode |= TF_ALPHASORT;
- }
- }
- }
-}
-
static void customdata_version_242(Mesh *me)
{
CustomDataLayer *layer;
@@ -403,13 +312,6 @@ static void customdata_version_242(Mesh *me)
for (a = 0; a < me->totface; a++, mtf++, tf++, mcol += 4) {
memcpy(mcol, tf->col, sizeof(tf->col));
memcpy(mtf->uv, tf->uv, sizeof(tf->uv));
-
- mtf->flag = tf->flag;
- mtf->unwrap = tf->unwrap;
- mtf->mode = tf->mode;
- mtf->tile = tf->tile;
- mtf->tpage = tf->tpage;
- mtf->transp = tf->transp;
}
MEM_freeN(me->tface);
@@ -617,15 +519,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile <= 102) {
- /* init halo's at 1.0 */
- Material *ma = main->mat.first;
- while (ma) {
- ma->add = 1.0;
- ma = ma->id.next;
- }
- }
-
if (main->versionfile <= 103) {
/* new variable in object: colbits */
Object *ob = main->object.first;
@@ -677,11 +570,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
if (main->versionfile <= 107) {
Object *ob;
- Scene *sce = main->scene.first;
- while (sce) {
- sce->r.mode |= R_GAMMA;
- sce = sce->id.next;
- }
ob = main->object.first;
while (ob) {
if (ob->dt == 0)
@@ -713,17 +601,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile <= 113) {
- Material *ma = main->mat.first;
- while (ma) {
- if (ma->flaresize == 0.0f)
- ma->flaresize = 1.0f;
- ma->subsize = 1.0f;
- ma->flareboost = 1.0f;
- ma = ma->id.next;
- }
- }
-
if (main->versionfile <= 134) {
Tex *tex = main->tex.first;
while (tex) {
@@ -888,148 +765,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile <= 191) {
- Object *ob = main->object.first;
- Material *ma = main->mat.first;
-
- /* let faces have default add factor of 0.0 */
- while (ma) {
- if (!(ma->mode & MA_HALO))
- ma->add = 0.0;
- ma = ma->id.next;
- }
-
- while (ob) {
- ob->mass = 1.0f;
- ob->damping = 0.1f;
- /*ob->quat[1] = 1.0f;*/ /* quats arnt used yet */
- ob = ob->id.next;
- }
- }
-
- if (main->versionfile <= 193) {
- Object *ob = main->object.first;
- while (ob) {
- ob->inertia = 1.0f;
- ob->rdamping = 0.1f;
- ob = ob->id.next;
- }
- }
-
- if (main->versionfile <= 196) {
- Mesh *me = main->mesh.first;
- int a, b;
- while (me) {
- if (me->tface) {
- TFace *tface = me->tface;
- for (a = 0; a < me->totface; a++, tface++) {
- for (b = 0; b < 4; b++) {
- tface->mode |= TF_DYNAMIC;
- tface->mode &= ~TF_INVISIBLE;
- }
- }
- }
- me = me->id.next;
- }
- }
-
- if (main->versionfile <= 200) {
- Object *ob = main->object.first;
- while (ob) {
- ob->scaflag = ob->gameflag & (OB_DO_FH|OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
- /* 64 is do_fh */
- ob->gameflag &= ~(OB_ROT_FH|OB_ANISOTROPIC_FRICTION|OB_GHOST|OB_RIGID_BODY|OB_BOUNDS);
- ob = ob->id.next;
- }
- }
-
- if (main->versionfile <= 201) {
- /* add-object + end-object are joined to edit-object actuator */
- Object *ob = main->object.first;
- bProperty *prop;
- bActuator *act;
- bIpoActuator *ia;
- bEditObjectActuator *eoa;
- bAddObjectActuator *aoa;
- while (ob) {
- act = ob->actuators.first;
- while (act) {
- if (act->type == ACT_IPO) {
- ia = act->data;
- prop = BKE_bproperty_object_get(ob, ia->name);
- if (prop) {
- ia->type = ACT_IPO_FROM_PROP;
- }
- }
- else if (act->type == ACT_ADD_OBJECT) {
- aoa = act->data;
- eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
- eoa->type = ACT_EDOB_ADD_OBJECT;
- eoa->ob = aoa->ob;
- eoa->time = aoa->time;
- MEM_freeN(aoa);
- act->data = eoa;
- act->type = act->otype = ACT_EDIT_OBJECT;
- }
- else if (act->type == ACT_END_OBJECT) {
- eoa = MEM_callocN(sizeof(bEditObjectActuator), "edit ob act");
- eoa->type = ACT_EDOB_END_OBJECT;
- act->data = eoa;
- act->type = act->otype = ACT_EDIT_OBJECT;
- }
- act = act->next;
- }
- ob = ob->id.next;
- }
- }
-
- if (main->versionfile <= 202) {
- /* add-object and end-object are joined to edit-object
- * actuator */
- Object *ob = main->object.first;
- bActuator *act;
- bObjectActuator *oa;
- while (ob) {
- act = ob->actuators.first;
- while (act) {
- if (act->type == ACT_OBJECT) {
- oa = act->data;
- oa->flag &= ~(ACT_TORQUE_LOCAL|ACT_DROT_LOCAL); /* this actuator didn't do local/glob rot before */
- }
- act = act->next;
- }
- ob = ob->id.next;
- }
- }
-
if (main->versionfile <= 204) {
- /* patches for new physics */
- Object *ob = main->object.first;
- bActuator *act;
- bObjectActuator *oa;
bSound *sound;
- while (ob) {
-
- /* please check this for demo20 files like
- * original Egypt levels etc. converted
- * rotation factor of 50 is not workable */
- act = ob->actuators.first;
- while (act) {
- if (act->type == ACT_OBJECT) {
- oa = act->data;
-
- oa->forceloc[0] *= 25.0f;
- oa->forceloc[1] *= 25.0f;
- oa->forceloc[2] *= 25.0f;
-
- oa->forcerot[0] *= 10.0f;
- oa->forcerot[1] *= 10.0f;
- oa->forcerot[2] *= 10.0f;
- }
- act = act->next;
- }
- ob = ob->id.next;
- }
sound = main->sound.first;
while (sound) {
@@ -1040,120 +777,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile <= 205) {
- /* patches for new physics */
- Object *ob = main->object.first;
- bActuator *act;
- bSensor *sens;
- bEditObjectActuator *oa;
- bRaySensor *rs;
- bCollisionSensor *cs;
- while (ob) {
- /* Set anisotropic friction off for old objects,
- * values to 1.0. */
- ob->gameflag &= ~OB_ANISOTROPIC_FRICTION;
- ob->anisotropicFriction[0] = 1.0;
- ob->anisotropicFriction[1] = 1.0;
- ob->anisotropicFriction[2] = 1.0;
-
- act = ob->actuators.first;
- while (act) {
- if (act->type == ACT_EDIT_OBJECT) {
- /* Zero initial velocity for newly
- * added objects */
- oa = act->data;
- oa->linVelocity[0] = 0.0;
- oa->linVelocity[1] = 0.0;
- oa->linVelocity[2] = 0.0;
- oa->localflag = 0;
- }
- act = act->next;
- }
-
- sens = ob->sensors.first;
- while (sens) {
- /* Extra fields for radar sensors. */
- if (sens->type == SENS_RADAR) {
- bRadarSensor *s = sens->data;
- s->range = 10000.0;
- }
-
- /* Pulsing: defaults for new sensors. */
- if (sens->type != SENS_ALWAYS) {
- sens->pulse = 0;
- sens->freq = 0;
- }
- else {
- sens->pulse = 1;
- }
-
- /* Invert: off. */
- sens->invert = 0;
-
- /* Collision and ray: default = trigger
- * on property. The material field can
- * remain empty. */
- if (sens->type == SENS_COLLISION) {
- cs = (bCollisionSensor*) sens->data;
- cs->mode = 0;
- }
- if (sens->type == SENS_RAY) {
- rs = (bRaySensor*) sens->data;
- rs->mode = 0;
- }
- sens = sens->next;
- }
- ob = ob->id.next;
- }
- /* have to check the exact multiplier */
- }
-
- if (main->versionfile <= 211) {
- /* Render setting: per scene, the applicable gamma value
- * can be set. Default is 1.0, which means no
- * correction. */
- bActuator *act;
- bObjectActuator *oa;
- Object *ob;
-
- /* added alpha in obcolor */
- ob = main->object.first;
- while (ob) {
- ob->col[3] = 1.0;
- ob = ob->id.next;
- }
-
- /* added alpha in obcolor */
- ob = main->object.first;
- while (ob) {
- act = ob->actuators.first;
- while (act) {
- if (act->type == ACT_OBJECT) {
- /* multiply velocity with 50 in old files */
- oa = act->data;
- if (fabsf(oa->linearvelocity[0]) >= 0.01f)
- oa->linearvelocity[0] *= 50.0f;
- if (fabsf(oa->linearvelocity[1]) >= 0.01f)
- oa->linearvelocity[1] *= 50.0f;
- if (fabsf(oa->linearvelocity[2]) >= 0.01f)
- oa->linearvelocity[2] *= 50.0f;
- if (fabsf(oa->angularvelocity[0]) >= 0.01f)
- oa->angularvelocity[0] *= 50.0f;
- if (fabsf(oa->angularvelocity[1]) >= 0.01f)
- oa->angularvelocity[1] *= 50.0f;
- if (fabsf(oa->angularvelocity[2]) >= 0.01f)
- oa->angularvelocity[2] *= 50.0f;
- }
- act = act->next;
- }
- ob = ob->id.next;
- }
- }
-
if (main->versionfile <= 212) {
bSound *sound;
- bProperty *prop;
- Object *ob;
Mesh *me;
sound = main->sound.first;
@@ -1170,21 +795,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
sound = sound->id.next;
}
- ob = main->object.first;
-
- while (ob) {
- prop = ob->prop.first;
- while (prop) {
- if (prop->type == GPROP_TIME) {
- // convert old GPROP_TIME values from int to float
- *((float *)&prop->data) = (float) prop->data;
- }
-
- prop = prop->next;
- }
- ob = ob->id.next;
- }
-
/* me->subdiv changed to reflect the actual reparametization
* better, and smeshes were removed - if it was a smesh make
* it a subsurf, and reset the subdiv level because subsurf
@@ -1207,29 +817,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
if (main->versionfile <= 220) {
- Object *ob;
Mesh *me;
- ob = main->object.first;
-
- /* adapt form factor in order to get the 'old' physics
- * behavior back...
- */
-
- while (ob) {
- /* in future, distinguish between different
- * object bounding shapes
- */
- ob->formfactor = 0.4f;
- /* patch form factor, note that inertia equiv radius
- * of a rotation symmetrical obj
- */
- if (ob->inertia != 1.0f) {
- ob->formfactor /= ob->inertia * ob->inertia;
- }
- ob = ob->id.next;
- }
-
/* Began using alpha component of vertex colors, but
* old file vertex colors are undefined, reset them
* to be fully opaque. -zr
@@ -1259,61 +848,13 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile <= 221) {
- Scene *sce = main->scene.first;
-
- /* new variables for std-alone player and runtime */
- while (sce) {
- sce->r.xplay = 640;
- sce->r.yplay = 480;
- sce->r.freqplay = 60;
-
- sce = sce->id.next;
- }
-
- }
-
- if (main->versionfile <= 222) {
- Scene *sce = main->scene.first;
-
- /* new variables for std-alone player and runtime */
- while (sce) {
- sce->r.depth = 32;
-
- sce = sce->id.next;
- }
- }
-
if (main->versionfile <= 223) {
VFont *vf;
- Image *ima;
- Object *ob;
-
for (vf = main->vfont.first; vf; vf = vf->id.next) {
if (STREQ(vf->name + strlen(vf->name) - 6, ".Bfont")) {
strcpy(vf->name, FO_BUILTIN_NAME);
}
}
-
- /* Old textures animate at 25 FPS */
- for (ima = main->image.first; ima; ima = ima->id.next) {
- ima->animspeed = 25;
- }
-
- /* Zr remapped some keyboard codes to be linear (stupid zr) */
- for (ob = main->object.first; ob; ob = ob->id.next) {
- bSensor *sens;
-
- for (sens = ob->sensors.first; sens; sens = sens->next) {
- if (sens->type == SENS_KEYBOARD) {
- bKeyboardSensor *ks = sens->data;
-
- ks->key = map_223_keybd_code_to_224_keybd_code(ks->key);
- ks->qual = map_223_keybd_code_to_224_keybd_code(ks->qual);
- ks->qual2 = map_223_keybd_code_to_224_keybd_code(ks->qual2);
- }
- }
- }
}
if (main->versionfile <= 224) {
@@ -1357,17 +898,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile <= 225) {
- World *wo;
- /* Use Sumo for old games */
- for (wo = main->world.first; wo; wo = wo->id.next) {
- wo->physicsEngine = 2;
- }
- }
-
if (main->versionfile <= 227) {
Scene *sce;
- Material *ma;
bScreen *sc;
Object *ob;
@@ -1420,17 +952,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
for (sce = main->scene.first; sce; sce = sce->id.next) {
sce->audio.mixrate = 48000;
sce->audio.flag |= AUDIO_SCRUB;
- sce->r.mode |= R_ENVMAP;
- }
-
- /* init new shader vars */
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- ma->refrac = 4.0f;
- ma->roughness = 0.5f;
- ma->param[0] = 0.5f;
- ma->param[1] = 0.1f;
- ma->param[2] = 0.1f;
- ma->param[3] = 0.05f;
}
/* patch for old wrong max view2d settings, allows zooming out more */
@@ -1455,7 +976,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
if (main->versionfile <= 228) {
- Scene *sce;
bScreen *sc;
Object *ob;
@@ -1501,10 +1021,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
ob = ob->id.next;
}
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- sce->r.mode |= R_ENVMAP;
- }
-
/* convert old mainb values for new button panels */
for (sc = main->screen.first; sc; sc = sc->id.next) {
ScrArea *sa;
@@ -1542,9 +1058,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
sbuts->mainb = CONTEXT_SCENE;
//sbuts->tab[CONTEXT_SCENE] = TAB_SCENE_RENDER;
}
- else if (sbuts->mainb == BUTS_GAME) {
- sbuts->mainb = CONTEXT_LOGIC;
- }
else if (sbuts->mainb == BUTS_FPAINT) {
sbuts->mainb = CONTEXT_EDITING;
}
@@ -1627,57 +1140,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
if (main->versionfile <= 231) {
- Material *ma = main->mat.first;
bScreen *sc = main->screen.first;
- Scene *sce;
- Lamp *la;
- World *wrld;
-
- /* introduction of raytrace */
- while (ma) {
- if (ma->fresnel_tra_i == 0.0f)
- ma->fresnel_tra_i = 1.25f;
- if (ma->fresnel_mir_i == 0.0f)
- ma->fresnel_mir_i = 1.25f;
-
- ma->ang = 1.0;
- ma->ray_depth = 2;
- ma->ray_depth_tra = 2;
- ma->fresnel_tra = 0.0;
- ma->fresnel_mir = 0.0;
-
- ma = ma->id.next;
- }
- sce = main->scene.first;
- while (sce) {
- if (sce->r.gauss == 0.0f)
- sce->r.gauss = 1.0f;
- sce = sce->id.next;
- }
- la = main->lamp.first;
- while (la) {
- if (la->k == 0.0f) la->k = 1.0;
- if (la->ray_samp == 0)
- la->ray_samp = 1;
- if (la->ray_sampy == 0)
- la->ray_sampy = 1;
- if (la->ray_sampz == 0)
- la->ray_sampz = 1;
- if (la->area_size == 0.0f)
- la->area_size = 1.0f;
- if (la->area_sizey == 0.0f)
- la->area_sizey = 1.0f;
- if (la->area_sizez == 0.0f)
- la->area_sizez = 1.0f;
- la = la->id.next;
- }
- wrld = main->world.first;
- while (wrld) {
- if (wrld->range == 0.0f) {
- wrld->range = 1.0f / wrld->exposure;
- }
- wrld = wrld->id.next;
- }
/* new bit flags for showing/hiding grid floor and axes */
@@ -1708,7 +1171,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
Tex *tex = main->tex.first;
World *wrld = main->world.first;
bScreen *sc;
- Scene *sce;
while (tex) {
if ((tex->flag & (TEX_CHECKER_ODD+TEX_CHECKER_EVEN))==0) {
@@ -1735,10 +1197,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
while (wrld) {
if (wrld->aodist == 0.0f) {
wrld->aodist = 10.0f;
- wrld->aobias = 0.05f;
}
- if (wrld->aosamp == 0)
- wrld->aosamp = 5;
if (wrld->aoenergy == 0.0f)
wrld->aoenergy = 1.0f;
wrld = wrld->id.next;
@@ -1763,13 +1222,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
}
- sce = main->scene.first;
- while (sce) {
- if (sce->r.ocres == 0)
- sce->r.ocres = 64;
- sce = sce->id.next;
- }
-
}
if (main->versionfile <= 233) {
@@ -1778,10 +1230,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
/* Object *ob = main->object.first; */
while (ma) {
- if (ma->rampfac_col == 0.0f)
- ma->rampfac_col = 1.0;
- if (ma->rampfac_spec == 0.0f)
- ma->rampfac_spec = 1.0;
if (ma->pr_lamp == 0)
ma->pr_lamp = 3;
ma = ma->id.next;
@@ -1802,15 +1250,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
if (main->versionfile <= 234) {
- World *wo;
bScreen *sc;
- /* force sumo engine to be active */
- for (wo = main->world.first; wo; wo = wo->id.next) {
- if (wo->physicsEngine == 0)
- wo->physicsEngine = 2;
- }
-
for (sc = main->screen.first; sc; sc = sc->id.next) {
ScrArea *sa;
for (sa = sc->areabase.first; sa; sa = sa->next) {
@@ -1859,8 +1300,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
if (main->versionfile <= 236) {
Object *ob;
Camera *cam = main->camera.first;
- Material *ma;
- bScreen *sc;
while (cam) {
if (cam->ortho_scale == 0.0f) {
@@ -1870,29 +1309,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
cam = cam->id.next;
}
- /* set manipulator type */
/* force oops draw if depgraph was set*/
/* set time line var */
- for (sc = main->screen.first; sc; sc = sc->id.next) {
- ScrArea *sa;
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl;
- for (sl = sa->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_VIEW3D) {
- View3D *v3d = (View3D *) sl;
- if (v3d->twtype == 0)
- v3d->twtype = V3D_MANIP_TRANSLATE;
- }
- }
- }
- }
- /* init new shader vars */
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- if (ma->darkness == 0.0f) {
- ma->rms = 0.1f;
- ma->darkness = 1.0f;
- }
- }
/* softbody init new vars */
for (ob = main->object.first; ob; ob = ob->id.next) {
@@ -1944,7 +1362,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
BKE_pose_tag_recalc(main, ob->pose);
/* cannot call stuff now (pointers!), done in setup_app_data */
- ob->recalc |= OB_RECALC_OB|OB_RECALC_DATA|OB_RECALC_TIME;
+ ob->id.recalc |= ID_RECALC_ALL;
/* new generic xray option */
arm = blo_do_versions_newlibadr(fd, lib, ob->data);
@@ -2121,7 +1539,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
Object *ob;
Scene *sce = main->scene.first;
Camera *cam = main->camera.first;
- Material *ma = main->mat.first;
int set_passepartout = 0;
/* deformflag is local in modifier now */
@@ -2154,11 +1571,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
set_passepartout = 1;
sce->r.scemode &= ~R_PASSEPARTOUT;
}
- /* gauss is filter variable now */
- if (sce->r.mode & R_GAUSS) {
- sce->r.filtertype = R_FILTER_GAUSS;
- sce->r.mode &= ~R_GAUSS;
- }
}
for (; cam; cam = cam->id.next) {
@@ -2173,36 +1585,15 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
if (!(cam->passepartalpha))
cam->passepartalpha = 0.2f;
}
-
- for (; ma; ma = ma->id.next) {
- if (ma->strand_sta == 0.0f) {
- ma->strand_sta = ma->strand_end = 1.0f;
- ma->mode |= MA_TANGENT_STR;
- }
- if (ma->mode & MA_TRACEBLE)
- ma->mode |= MA_SHADBUF;
- }
}
if (main->versionfile <= 241) {
Object *ob;
- Tex *tex;
Scene *sce;
- World *wo;
Lamp *la;
- Material *ma;
bArmature *arm;
bNodeTree *ntree;
- for (wo = main->world.first; wo; wo = wo->id.next) {
- /* Migrate to Bullet for games, except for the NaN versions */
- /* People can still explicitly choose for Sumo (after 2.42 is out) */
- if (main->versionfile > 225)
- wo->physicsEngine = WOPHY_BULLET;
- if (WO_AODIST == wo->aomode)
- wo->aocolor = WO_AOPLAIN;
- }
-
/* updating layers still */
for (arm = main->armature.first; arm; arm = arm->id.next) {
bone_version_239(&arm->bonebase);
@@ -2213,23 +1604,16 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
if (sce->audio.mixrate == 0)
sce->audio.mixrate = 48000;
- if (sce->r.xparts <2 )
- sce->r.xparts = 4;
- if (sce->r.yparts < 2)
- sce->r.yparts = 4;
-
- /* adds default layer */
- if (BLI_listbase_is_empty(&sce->r.layers)) {
- BKE_scene_add_render_layer(sce, NULL);
- }
- else {
- SceneRenderLayer *srl;
- /* new layer flag for sky, was default for solid */
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
- if (srl->layflag & SCE_LAY_SOLID)
- srl->layflag |= SCE_LAY_SKY;
- srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR);
- }
+ /* We don't add default layer since blender2.8 because the layers
+ * are now in Scene->view_layers and a default layer is created in
+ * the doversion later on.
+ */
+ SceneRenderLayer *srl;
+ /* new layer flag for sky, was default for solid */
+ for (srl = sce->r.layers.first; srl; srl = srl->next) {
+ if (srl->layflag & SCE_LAY_SOLID)
+ srl->layflag |= SCE_LAY_SKY;
+ srl->passflag &= (SCE_PASS_COMBINED|SCE_PASS_Z|SCE_PASS_NORMAL|SCE_PASS_VECTOR);
}
/* node version changes */
@@ -2241,20 +1625,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
sce->toolsettings->uvcalc_flag = UVCALC_FILLHOLES;
sce->toolsettings->unwrapper = 1;
}
-
- if (sce->r.mode & R_PANORAMA) {
- /* all these checks to ensure saved files between released versions keep working... */
- if (sce->r.xsch < sce->r.ysch) {
- Object *obc = blo_do_versions_newlibadr(fd, lib, sce->camera);
- if (obc && obc->type == OB_CAMERA) {
- Camera *cam = blo_do_versions_newlibadr(fd, lib, obc->data);
- if (cam->lens >= 10.0f) {
- sce->r.xsch *= sce->r.xparts;
- cam->lens *= (float)sce->r.ysch / (float)sce->r.xsch;
- }
- }
- }
- }
}
for (ntree = main->nodetree.first; ntree; ntree = ntree->id.next)
@@ -2264,12 +1634,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
if (la->buffers == 0)
la->buffers = 1;
- for (tex = main->tex.first; tex; tex = tex->id.next) {
- if (tex->env && tex->env->viewscale == 0.0f)
- tex->env->viewscale = 1.0f;
- //tex->imaflag |= TEX_GAUSS_MIP;
- }
-
/* for empty drawsize and drawtype */
for (ob = main->object.first; ob; ob = ob->id.next) {
if (ob->empty_drawsize == 0.0f) {
@@ -2278,21 +1642,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- /* stucci returns intensity from now on */
- int a;
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a] && ma->mtex[a]->tex) {
- tex = blo_do_versions_newlibadr(fd, lib, ma->mtex[a]->tex);
- if (tex && tex->type == TEX_STUCCI)
- ma->mtex[a]->mapto &= ~(MAP_COL|MAP_SPEC|MAP_REF);
- }
- }
- /* transmissivity defaults */
- if (ma->tx_falloff == 0.0f)
- ma->tx_falloff = 1.0f;
- }
-
/* during 2.41 images with this name were used for viewer node output, lets fix that */
if (main->versionfile == 241) {
Image *ima;
@@ -2462,8 +1811,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
for (ma = main->mat.first; ma; ma = ma->id.next) {
- if (ma->shad_alpha == 0.0f)
- ma->shad_alpha = 1.0f;
if (ma->nodetree)
ntree_version_242(ma->nodetree);
}
@@ -2529,13 +1876,8 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
for (sa = sc->areabase.first; sa; sa = sa->next) {
SpaceLink *sl;
for (sl = sa->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_IMAGE)
+ if (sl->spacetype == SPACE_IMAGE) {
((SpaceImage *)sl)->iuser.fie_ima = 2;
- else if (sl->spacetype == SPACE_VIEW3D) {
- View3D *v3d = (View3D *)sl;
- BGpic *bgpic;
- for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next)
- bgpic->iuser.fie_ima = 2;
}
}
}
@@ -2546,7 +1888,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
for (sce = main->scene.first; sce; sce = sce->id.next) {
sce->r.bake_mode = 1; /* prevent to include render stuff here */
sce->r.bake_filter = 16;
- sce->r.bake_osa = 5;
sce->r.bake_flag = R_BAKE_CLEAR;
}
}
@@ -2554,32 +1895,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
if (main->versionfile <= 243) {
Object *ob = main->object.first;
- Material *ma;
-
- for (ma = main->mat.first; ma; ma = ma->id.next) {
- if (ma->sss_scale == 0.0f) {
- ma->sss_radius[0] = 1.0f;
- ma->sss_radius[1] = 1.0f;
- ma->sss_radius[2] = 1.0f;
- ma->sss_col[0] = 0.8f;
- ma->sss_col[1] = 0.8f;
- ma->sss_col[2] = 0.8f;
- ma->sss_error = 0.05f;
- ma->sss_scale = 0.1f;
- ma->sss_ior = 1.3f;
- ma->sss_colfac = 1.0f;
- ma->sss_texfac = 0.0f;
- }
- if (ma->sss_front == 0 && ma->sss_back == 0) {
- ma->sss_front = 1.0f;
- ma->sss_back = 1.0f;
- }
- if (ma->sss_col[0] == 0 && ma->sss_col[1] == 0 && ma->sss_col[2] == 0) {
- ma->sss_col[0] = ma->r;
- ma->sss_col[1] = ma->g;
- ma->sss_col[2] = ma->b;
- }
- }
for (; ob; ob = ob->id.next) {
bDeformGroup *curdef;
@@ -2627,15 +1942,9 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
if (main->versionfile <= 244) {
- Scene *sce;
bScreen *sc;
- Lamp *la;
- World *wrld;
if (main->versionfile != 244 || main->subversionfile < 2) {
- for (sce = main->scene.first; sce; sce = sce->id.next)
- sce->r.mode |= R_SSS;
-
/* correct older action editors - incorrect scrolling */
for (sc = main->screen.first; sc; sc = sc->id.next) {
ScrArea *sa;
@@ -2658,28 +1967,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
}
-
- if (main->versionfile != 244 || main->subversionfile < 3) {
- /* constraints recode version patch used to be here. Moved to 245 now... */
-
- for (wrld = main->world.first; wrld; wrld = wrld->id.next) {
- if (wrld->mode & WO_AMB_OCC)
- wrld->ao_samp_method = WO_AOSAMP_CONSTANT;
- else
- wrld->ao_samp_method = WO_AOSAMP_HAMMERSLEY;
-
- wrld->ao_adapt_thresh = 0.005f;
- }
-
- for (la = main->lamp.first; la; la = la->id.next) {
- if (la->type == LA_AREA)
- la->ray_samp_method = LA_SAMP_CONSTANT;
- else
- la->ray_samp_method = LA_SAMP_HALTON;
-
- la->adapt_thresh = 0.001f;
- }
- }
}
if (main->versionfile <= 245) {
@@ -2689,7 +1976,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
Lamp *la;
Material *ma;
ParticleSettings *part;
- World *wrld;
Mesh *me;
bNodeTree *ntree;
Tex *tex;
@@ -2821,10 +2107,7 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
if (main->versionfile != 245 || main->subversionfile < 1) {
for (la = main->lamp.first; la; la = la->id.next) {
- if (la->mode & LA_QUAD)
- la->falloff_type = LA_FALLOFF_SLIDERS;
- else
- la->falloff_type = LA_FALLOFF_INVLINEAR;
+ la->falloff_type = LA_FALLOFF_INVLINEAR;
if (la->curfalloff == NULL) {
la->curfalloff = curvemapping_add(1, 0.0f, 1.0f, 1.0f, 0.0f);
@@ -2834,51 +2117,23 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
for (ma = main->mat.first; ma; ma = ma->id.next) {
- if (ma->samp_gloss_mir == 0) {
- ma->gloss_mir = ma->gloss_tra = 1.0f;
- ma->aniso_gloss_mir = 1.0f;
- ma->samp_gloss_mir = ma->samp_gloss_tra = 18;
- ma->adapt_thresh_mir = ma->adapt_thresh_tra = 0.005f;
- ma->dist_mir = 0.0f;
- ma->fadeto_mir = MA_RAYMIR_FADETOSKY;
+ if (ma->gloss_mir == 0.0f) {
+ ma->gloss_mir = 1.0f;
}
-
- if (ma->strand_min == 0.0f)
- ma->strand_min = 1.0f;
}
for (part = main->particle.first; part; part = part->id.next) {
if (part->ren_child_nbr == 0)
part->ren_child_nbr = part->child_nbr;
-
- if (part->simplify_refsize == 0) {
- part->simplify_refsize = 1920;
- part->simplify_rate = 1.0f;
- part->simplify_transition = 0.1f;
- part->simplify_viewport = 0.8f;
- }
- }
-
- for (wrld = main->world.first; wrld; wrld = wrld->id.next) {
- if (wrld->ao_approx_error == 0.0f)
- wrld->ao_approx_error = 0.25f;
}
for (sce = main->scene.first; sce; sce = sce->id.next) {
if (sce->nodetree)
ntree_version_245(fd, lib, sce->nodetree);
- if (sce->r.simplify_shadowsamples == 0) {
+ if (sce->r.simplify_subsurf == 0) {
sce->r.simplify_subsurf = 6;
sce->r.simplify_particles = 1.0f;
- sce->r.simplify_shadowsamples = 16;
- sce->r.simplify_aosss = 1.0f;
- }
-
- if (sce->r.cineongamma == 0) {
- sce->r.cineonblack = 95;
- sce->r.cineonwhite = 685;
- sce->r.cineongamma = 1.7f;
}
}
@@ -2906,22 +2161,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- /* sanity check for skgen */
- {
- Scene *sce;
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- if (sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[1] ||
- sce->toolsettings->skgen_subdivisions[0] == sce->toolsettings->skgen_subdivisions[2] ||
- sce->toolsettings->skgen_subdivisions[1] == sce->toolsettings->skgen_subdivisions[2])
- {
- sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
- sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
- sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
- }
- }
- }
-
-
if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 2)) {
Image *ima;
@@ -3158,16 +2397,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
}
- if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 9)) {
- Material *ma;
- int a;
-
- for (ma = main->mat.first; ma; ma = ma->id.next)
- if (ma->mode & MA_NORMAP_TANG)
- for (a = 0; a < MAX_MTEX; a++)
- if (ma->mtex[a] && ma->mtex[a]->tex)
- ma->mtex[a]->normapspace = MTEX_NSPACE_TANGENT;
- }
if ((main->versionfile < 245) || (main->versionfile == 245 && main->subversionfile < 10)) {
Object *ob;
@@ -3250,25 +2479,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
idproperties_fix_group_lengths(main->particle);
}
- /* sun/sky */
- if (main->versionfile < 246) {
- Object *ob;
- bActuator *act;
-
- /* dRot actuator change direction in 2.46 */
- for (ob = main->object.first; ob; ob = ob->id.next) {
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_OBJECT) {
- bObjectActuator *ba = act->data;
-
- ba->drot[0] = -ba->drot[0];
- ba->drot[1] = -ba->drot[1];
- ba->drot[2] = -ba->drot[2];
- }
- }
- }
- }
-
/* convert fluids to modifier */
if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
Object *ob;
@@ -3290,14 +2500,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
-
- if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
- Mesh *me;
-
- for (me = main->mesh.first; me; me = me->id.next)
- alphasort_version_246(fd, lib, me);
- }
-
if (main->versionfile < 246 || (main->versionfile == 246 && main->subversionfile < 1)) {
Object *ob;
for (ob = main->object.first; ob; ob = ob->id.next) {
@@ -3306,33 +2508,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 2)) {
- Object *ob;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- ob->gameflag |= OB_COLLISION;
- ob->margin = 0.06f;
- }
- }
-
- if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 3)) {
- Object *ob;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- /* Starting from subversion 3, ACTOR is a separate feature.
- * Before it was conditioning all the other dynamic flags */
- if (!(ob->gameflag & OB_ACTOR))
- ob->gameflag &= ~(OB_GHOST|OB_DYNAMIC|OB_RIGID_BODY|OB_SOFT_BODY|OB_COLLISION_RESPONSE);
- /* suitable default for older files */
- }
- }
-
- if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 5)) {
- Lamp *la = main->lamp.first;
- for (; la; la = la->id.next) {
- la->skyblendtype = MA_RAMP_ADD;
- la->skyblendfac = 1.0f;
- }
- }
-
/* set the curve radius interpolation to 2.47 default - easy */
if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 6)) {
Curve *cu;
@@ -3356,72 +2531,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- /* direction constraint actuators were always local in previous version */
- if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 7)) {
- bActuator *act;
- Object *ob;
-
- for (ob = main->object.first; ob; ob = ob->id.next) {
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_CONSTRAINT) {
- bConstraintActuator *coa = act->data;
- if (coa->type == ACT_CONST_TYPE_DIST) {
- coa->flag |= ACT_CONST_LOCAL;
- }
- }
- }
- }
- }
-
- if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 9)) {
- Lamp *la = main->lamp.first;
- for (; la; la = la->id.next) {
- la->sky_exposure = 1.0f;
- }
- }
-
- /* BGE message actuators needed OB prefix, very confusing */
- if (main->versionfile < 247 || (main->versionfile == 247 && main->subversionfile < 10)) {
- bActuator *act;
- Object *ob;
-
- for (ob = main->object.first; ob; ob = ob->id.next) {
- for (act = ob->actuators.first; act; act = act->next) {
- if (act->type == ACT_MESSAGE) {
- bMessageActuator *msgAct = (bMessageActuator *) act->data;
-
- if (BLI_strnlen(msgAct->toPropName, 3) > 2) {
- /* strip first 2 chars, would have only worked if these were OB anyway */
- memmove(msgAct->toPropName, msgAct->toPropName + 2, sizeof(msgAct->toPropName) - 2);
- }
- else {
- msgAct->toPropName[0] = '\0';
- }
- }
- }
- }
- }
-
- if (main->versionfile < 248) {
- Lamp *la;
-
- for (la = main->lamp.first; la; la = la->id.next) {
- if (la->atm_turbidity == 0.0f) {
- la->sun_effect_type = 0;
- la->horizon_brightness = 1.0f;
- la->spread = 1.0f;
- la->sun_brightness = 1.0f;
- la->sun_size = 1.0f;
- la->backscattered_light = 1.0f;
- la->atm_turbidity = 2.0f;
- la->atm_inscattering_factor = 1.0f;
- la->atm_extinction_factor = 1.0f;
- la->atm_distance_factor = 1.0f;
- la->sun_intensity = 1.0f;
- }
- }
- }
-
if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 2)) {
Scene *sce;
@@ -3429,31 +2538,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
for (sce = main->scene.first; sce; sce = sce->id.next) {
sce->toolsettings->imapaint.seam_bleed = 2;
sce->toolsettings->imapaint.normal_angle = 80;
-
- /* initialize skeleton generation toolsettings */
- sce->toolsettings->skgen_resolution = 250;
- sce->toolsettings->skgen_threshold_internal = 0.1f;
- sce->toolsettings->skgen_threshold_external = 0.1f;
- sce->toolsettings->skgen_angle_limit = 30.0f;
- sce->toolsettings->skgen_length_ratio = 1.3f;
- sce->toolsettings->skgen_length_limit = 1.5f;
- sce->toolsettings->skgen_correlation_limit = 0.98f;
- sce->toolsettings->skgen_symmetry_limit = 0.1f;
- sce->toolsettings->skgen_postpro = SKGEN_SMOOTH;
- sce->toolsettings->skgen_postpro_passes = 3;
- sce->toolsettings->skgen_options = SKGEN_FILTER_INTERNAL|SKGEN_FILTER_EXTERNAL|SKGEN_FILTER_SMART|SKGEN_SUB_CORRELATION|SKGEN_HARMONIC;
- sce->toolsettings->skgen_subdivisions[0] = SKGEN_SUB_CORRELATION;
- sce->toolsettings->skgen_subdivisions[1] = SKGEN_SUB_LENGTH;
- sce->toolsettings->skgen_subdivisions[2] = SKGEN_SUB_ANGLE;
-
-
- sce->toolsettings->skgen_retarget_angle_weight = 1.0f;
- sce->toolsettings->skgen_retarget_length_weight = 1.0f;
- sce->toolsettings->skgen_retarget_distance_weight = 1.0f;
-
- /* Skeleton Sketching */
- sce->toolsettings->bone_sketching = 0;
- sce->toolsettings->skgen_retarget_roll = SK_RETARGET_ROLL_VIEW;
}
}
@@ -3495,60 +2579,6 @@ void blo_do_versions_pre250(FileData *fd, Library *lib, Main *main)
}
}
- if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 3)) {
- Object *ob;
-
- /* Adjustments needed after Bullets update */
- for (ob = main->object.first; ob; ob = ob->id.next) {
- ob->damping *= 0.635f;
- ob->rdamping = 0.1f + (0.8f * ob->rdamping);
- }
- }
-
- if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 4)) {
- Scene *sce;
- World *wrld;
-
- /* Dome (Fisheye) default parameters */
- for (sce = main->scene.first; sce; sce = sce->id.next) {
- sce->r.domeangle = 180;
- sce->r.domemode = 1;
- sce->r.domeres = 4;
- sce->r.domeresbuf = 1.0f;
- sce->r.dometilt = 0;
- }
- /* DBVT culling by default */
- for (wrld = main->world.first; wrld; wrld = wrld->id.next) {
- wrld->mode |= WO_DBVT_CULLING;
- wrld->occlusionRes = 128;
- }
- }
-
- if (main->versionfile < 248 || (main->versionfile == 248 && main->subversionfile < 5)) {
- Object *ob;
- World *wrld;
- for (ob = main->object.first; ob; ob = ob->id.next) {
- if (ob->parent) {
- /* check if top parent has compound shape set and if yes, set this object
- * to compound shaper as well (was the behavior before, now it's optional) */
- Object *parent = blo_do_versions_newlibadr(fd, lib, ob->parent);
- while (parent && parent != ob && parent->parent != NULL) {
- parent = blo_do_versions_newlibadr(fd, lib, parent->parent);
- }
- if (parent) {
- if (parent->gameflag & OB_CHILD)
- ob->gameflag |= OB_CHILD;
- }
- }
- }
- for (wrld = main->world.first; wrld; wrld = wrld->id.next) {
- wrld->ticrate = 60;
- wrld->maxlogicstep = 5;
- wrld->physubstep = 1;
- wrld->maxphystep = 5;
- }
- }
-
/* correct introduce of seed for wind force */
if (main->versionfile < 249 && main->subversionfile < 1) {
Object *ob;
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 549800ae02b..60aa719c459 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -102,16 +102,18 @@
/* allow writefile to use deprecated functionality (for forward compatibility code) */
#define DNA_DEPRECATED_ALLOW
+/* Allow using DNA struct members that are marked as private for read/write.
+ * Note: Each header that uses this needs to define its own way of handling
+ * it. There's no generic implementation, direct use does nothing. */
+#define DNA_PRIVATE_READ_WRITE_ALLOW
#include "DNA_anim_types.h"
#include "DNA_armature_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_brush_types.h"
#include "DNA_cachefile_types.h"
#include "DNA_camera_types.h"
#include "DNA_cloth_types.h"
#include "DNA_constraint_types.h"
-#include "DNA_controller_types.h"
#include "DNA_dynamicpaint_types.h"
#include "DNA_genfile.h"
#include "DNA_group_types.h"
@@ -120,6 +122,7 @@
#include "DNA_key_types.h"
#include "DNA_lattice_types.h"
#include "DNA_lamp_types.h"
+#include "DNA_layer_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_meta_types.h"
#include "DNA_mesh_types.h"
@@ -130,12 +133,11 @@
#include "DNA_object_force_types.h"
#include "DNA_packedFile_types.h"
#include "DNA_particle_types.h"
-#include "DNA_property_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
#include "DNA_sdna_types.h"
#include "DNA_sequence_types.h"
-#include "DNA_sensor_types.h"
#include "DNA_smoke_types.h"
#include "DNA_space_types.h"
#include "DNA_screen_types.h"
@@ -146,6 +148,7 @@
#include "DNA_vfont_types.h"
#include "DNA_world_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_mask_types.h"
@@ -161,8 +164,10 @@
#include "BKE_curve.h"
#include "BKE_constraint.h"
#include "BKE_global.h" // for G
+#include "BKE_group.h"
#include "BKE_idcode.h"
#include "BKE_library.h" // for set_listbasepointers
+#include "BKE_library_override.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_report.h"
@@ -172,6 +177,7 @@
#include "BKE_fcurve.h"
#include "BKE_pointcache.h"
#include "BKE_mesh.h"
+#include "BKE_workspace.h"
#ifdef USE_NODE_COMPAT_CUSTOMNODES
#include "NOD_socket.h" /* for sock->default_value data */
@@ -713,6 +719,25 @@ static void write_iddata(void *wd, const ID *id)
if (id->properties && !ELEM(GS(id->name), ID_WM)) {
IDP_WriteProperty(id->properties, wd);
}
+
+ if (id->override_static) {
+ writestruct(wd, DATA, IDOverrideStatic, 1, id->override_static);
+
+ writelist(wd, DATA, IDOverrideStaticProperty, &id->override_static->properties);
+ for (IDOverrideStaticProperty *op = id->override_static->properties.first; op; op = op->next) {
+ writedata(wd, DATA, strlen(op->rna_path) + 1, op->rna_path);
+
+ writelist(wd, DATA, IDOverrideStaticPropertyOperation, &op->operations);
+ for (IDOverrideStaticPropertyOperation *opop = op->operations.first; opop; opop = opop->next) {
+ if (opop->subitem_reference_name) {
+ writedata(wd, DATA, strlen(opop->subitem_reference_name) + 1, opop->subitem_reference_name);
+ }
+ if (opop->subitem_local_name) {
+ writedata(wd, DATA, strlen(opop->subitem_local_name) + 1, opop->subitem_local_name);
+ }
+ }
+ }
+ }
}
static void write_previews(WriteData *wd, const PreviewImage *prv_orig)
@@ -1116,10 +1141,13 @@ static void write_nodetree_nolib(WriteData *wd, bNodeTree *ntree)
* Take care using 'use_active_win', since we wont want the currently active window
* to change which scene renders (currently only used for undo).
*/
-static void current_screen_compat(Main *mainvar, bScreen **r_screen, bool use_active_win)
+static void current_screen_compat(
+ Main *mainvar, bool use_active_win,
+ bScreen **r_screen, Scene **r_scene, ViewLayer **r_render_layer)
{
wmWindowManager *wm;
wmWindow *window = NULL;
+ WorkSpace *workspace;
/* find a global current screen in the first open window, to have
* a reasonable default for reading in older versions */
@@ -1143,8 +1171,11 @@ static void current_screen_compat(Main *mainvar, bScreen **r_screen, bool use_ac
window = wm->windows.first;
}
}
+ workspace = (window) ? BKE_workspace_active_get(window->workspace_hook) : NULL;
- *r_screen = (window) ? window->screen : NULL;
+ *r_screen = (window) ? BKE_workspace_active_screen_get(window->workspace_hook) : NULL;
+ *r_scene = (window) ? window->scene : NULL;
+ *r_render_layer = (window) ? BKE_workspace_view_layer_get(workspace, *r_scene) : NULL;
}
typedef struct RenderInfo {
@@ -1160,13 +1191,11 @@ static void write_renderinfo(WriteData *wd, Main *mainvar)
{
bScreen *curscreen;
Scene *sce, *curscene = NULL;
+ ViewLayer *render_layer;
RenderInfo data;
/* XXX in future, handle multiple windows with multiple screens? */
- current_screen_compat(mainvar, &curscreen, false);
- if (curscreen) {
- curscene = curscreen->scene;
- }
+ current_screen_compat(mainvar, false, &curscreen, &curscene, &render_layer);
for (sce = mainvar->scene.first; sce; sce = sce->id.next) {
if (sce->id.lib == NULL && (sce == curscene || (sce->r.scemode & R_BG_RENDER))) {
@@ -1351,9 +1380,13 @@ static void write_particlesettings(WriteData *wd, ParticleSettings *part)
if (dw->ob != NULL) {
dw->index = 0;
if (part->dup_group) { /* can be NULL if lining fails or set to None */
- for (GroupObject *go = part->dup_group->gobject.first;
- go && go->ob != dw->ob;
- go = go->next, dw->index++);
+ FOREACH_GROUP_OBJECT_BEGIN(part->dup_group, object)
+ {
+ if (object != dw->ob) {
+ dw->index++;
+ }
+ }
+ FOREACH_GROUP_OBJECT_END;
}
}
writestruct(wd, DATA, ParticleDupliWeight, 1, dw);
@@ -1430,180 +1463,6 @@ static void write_particlesystems(WriteData *wd, ListBase *particles)
}
}
-static void write_properties(WriteData *wd, ListBase *lb)
-{
- bProperty *prop;
-
- prop = lb->first;
- while (prop) {
- writestruct(wd, DATA, bProperty, 1, prop);
-
- if (prop->poin && prop->poin != &prop->data) {
- writedata(wd, DATA, MEM_allocN_len(prop->poin), prop->poin);
- }
-
- prop = prop->next;
- }
-}
-
-static void write_sensors(WriteData *wd, ListBase *lb)
-{
- bSensor *sens;
-
- sens = lb->first;
- while (sens) {
- writestruct(wd, DATA, bSensor, 1, sens);
-
- writedata(wd, DATA, sizeof(void *) * sens->totlinks, sens->links);
-
- switch (sens->type) {
- case SENS_NEAR:
- writestruct(wd, DATA, bNearSensor, 1, sens->data);
- break;
- case SENS_MOUSE:
- writestruct(wd, DATA, bMouseSensor, 1, sens->data);
- break;
- case SENS_KEYBOARD:
- writestruct(wd, DATA, bKeyboardSensor, 1, sens->data);
- break;
- case SENS_PROPERTY:
- writestruct(wd, DATA, bPropertySensor, 1, sens->data);
- break;
- case SENS_ARMATURE:
- writestruct(wd, DATA, bArmatureSensor, 1, sens->data);
- break;
- case SENS_ACTUATOR:
- writestruct(wd, DATA, bActuatorSensor, 1, sens->data);
- break;
- case SENS_DELAY:
- writestruct(wd, DATA, bDelaySensor, 1, sens->data);
- break;
- case SENS_COLLISION:
- writestruct(wd, DATA, bCollisionSensor, 1, sens->data);
- break;
- case SENS_RADAR:
- writestruct(wd, DATA, bRadarSensor, 1, sens->data);
- break;
- case SENS_RANDOM:
- writestruct(wd, DATA, bRandomSensor, 1, sens->data);
- break;
- case SENS_RAY:
- writestruct(wd, DATA, bRaySensor, 1, sens->data);
- break;
- case SENS_MESSAGE:
- writestruct(wd, DATA, bMessageSensor, 1, sens->data);
- break;
- case SENS_JOYSTICK:
- writestruct(wd, DATA, bJoystickSensor, 1, sens->data);
- break;
- default:
- ; /* error: don't know how to write this file */
- }
-
- sens = sens->next;
- }
-}
-
-static void write_controllers(WriteData *wd, ListBase *lb)
-{
- bController *cont;
-
- cont = lb->first;
- while (cont) {
- writestruct(wd, DATA, bController, 1, cont);
-
- writedata(wd, DATA, sizeof(void *) * cont->totlinks, cont->links);
-
- switch (cont->type) {
- case CONT_EXPRESSION:
- writestruct(wd, DATA, bExpressionCont, 1, cont->data);
- break;
- case CONT_PYTHON:
- writestruct(wd, DATA, bPythonCont, 1, cont->data);
- break;
- default:
- ; /* error: don't know how to write this file */
- }
-
- cont = cont->next;
- }
-}
-
-static void write_actuators(WriteData *wd, ListBase *lb)
-{
- bActuator *act;
-
- act = lb->first;
- while (act) {
- writestruct(wd, DATA, bActuator, 1, act);
-
- switch (act->type) {
- case ACT_ACTION:
- case ACT_SHAPEACTION:
- writestruct(wd, DATA, bActionActuator, 1, act->data);
- break;
- case ACT_SOUND:
- writestruct(wd, DATA, bSoundActuator, 1, act->data);
- break;
- case ACT_OBJECT:
- writestruct(wd, DATA, bObjectActuator, 1, act->data);
- break;
- case ACT_PROPERTY:
- writestruct(wd, DATA, bPropertyActuator, 1, act->data);
- break;
- case ACT_CAMERA:
- writestruct(wd, DATA, bCameraActuator, 1, act->data);
- break;
- case ACT_CONSTRAINT:
- writestruct(wd, DATA, bConstraintActuator, 1, act->data);
- break;
- case ACT_EDIT_OBJECT:
- writestruct(wd, DATA, bEditObjectActuator, 1, act->data);
- break;
- case ACT_SCENE:
- writestruct(wd, DATA, bSceneActuator, 1, act->data);
- break;
- case ACT_GROUP:
- writestruct(wd, DATA, bGroupActuator, 1, act->data);
- break;
- case ACT_RANDOM:
- writestruct(wd, DATA, bRandomActuator, 1, act->data);
- break;
- case ACT_MESSAGE:
- writestruct(wd, DATA, bMessageActuator, 1, act->data);
- break;
- case ACT_GAME:
- writestruct(wd, DATA, bGameActuator, 1, act->data);
- break;
- case ACT_VISIBILITY:
- writestruct(wd, DATA, bVisibilityActuator, 1, act->data);
- break;
- case ACT_2DFILTER:
- writestruct(wd, DATA, bTwoDFilterActuator, 1, act->data);
- break;
- case ACT_PARENT:
- writestruct(wd, DATA, bParentActuator, 1, act->data);
- break;
- case ACT_STATE:
- writestruct(wd, DATA, bStateActuator, 1, act->data);
- break;
- case ACT_ARMATURE:
- writestruct(wd, DATA, bArmatureActuator, 1, act->data);
- break;
- case ACT_STEERING:
- writestruct(wd, DATA, bSteeringActuator, 1, act->data);
- break;
- case ACT_MOUSE:
- writestruct(wd, DATA, bMouseActuator, 1, act->data);
- break;
- default:
- ; /* error: don't know how to write this file */
- }
-
- act = act->next;
- }
-}
-
static void write_motionpath(WriteData *wd, bMotionPath *mpath)
{
/* sanity checks */
@@ -1722,6 +1581,13 @@ static void write_defgroups(WriteData *wd, ListBase *defbase)
}
}
+static void write_fmaps(WriteData *wd, ListBase *fbase)
+{
+ for (bFaceMap *fmap = fbase->first; fmap; fmap = fmap->next) {
+ writestruct(wd, DATA, bFaceMap, 1, fmap);
+ }
+}
+
static void write_modifiers(WriteData *wd, ListBase *modbase)
{
ModifierData *md;
@@ -1759,6 +1625,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
SmokeModifierData *smd = (SmokeModifierData *)md;
if (smd->type & MOD_SMOKE_TYPE_DOMAIN) {
+ writestruct(wd, DATA, SmokeDomainSettings, 1, smd->domain);
+
if (smd->domain) {
write_pointcaches(wd, &(smd->domain->ptcaches[0]));
@@ -1772,11 +1640,8 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
if (smd->domain->coba) {
writestruct(wd, DATA, ColorBand, 1, smd->domain->coba);
}
- }
- writestruct(wd, DATA, SmokeDomainSettings, 1, smd->domain);
- if (smd->domain) {
/* cleanup the fake pointcache */
BKE_ptcache_free_list(&smd->domain->ptcaches[1]);
smd->domain->point_cache[1] = NULL;
@@ -1912,10 +1777,6 @@ static void write_object(WriteData *wd, Object *ob)
writedata(wd, DATA, sizeof(void *) * ob->totcol, ob->mat);
writedata(wd, DATA, sizeof(char) * ob->totcol, ob->matbits);
/* write_effects(wd, &ob->effect); */ /* not used anymore */
- write_properties(wd, &ob->prop);
- write_sensors(wd, &ob->sensors);
- write_controllers(wd, &ob->controllers);
- write_actuators(wd, &ob->actuators);
if (ob->type == OB_ARMATURE) {
bArmature *arm = ob->data;
@@ -1926,6 +1787,7 @@ static void write_object(WriteData *wd, Object *ob)
write_pose(wd, ob->pose);
write_defgroups(wd, &ob->defbase);
+ write_fmaps(wd, &ob->fmaps);
write_constraints(wd, &ob->constraints);
write_motionpath(wd, ob->mpath);
@@ -1935,7 +1797,6 @@ static void write_object(WriteData *wd, Object *ob)
write_pointcaches(wd, &ob->soft->ptcaches);
writestruct(wd, DATA, EffectorWeights, 1, ob->soft->effector_weights);
}
- writestruct(wd, DATA, BulletSoftBody, 1, ob->bsoft);
if (ob->rigidbody_object) {
/* TODO: if any extra data is added to handle duplis, will need separate function then */
@@ -2008,6 +1869,10 @@ static void write_camera(WriteData *wd, Camera *cam)
if (cam->adt) {
write_animdata(wd, cam->adt);
}
+
+ for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+ writestruct(wd, DATA, CameraBGImage, 1, bgpic);
+ }
}
}
@@ -2158,6 +2023,10 @@ static void write_customdata(
else if (layer->type == CD_GRID_PAINT_MASK) {
write_grid_paint_mask(wd, count, layer->data);
}
+ else if (layer->type == CD_FACEMAP) {
+ const int *layer_data = layer->data;
+ writedata(wd, DATA, sizeof(*layer_data) * count, layer_data);
+ }
else {
CustomData_file_write_info(layer->type, &structname, &structnum);
if (structnum) {
@@ -2409,24 +2278,6 @@ static void write_texture(WriteData *wd, Tex *tex)
if (tex->coba) {
writestruct(wd, DATA, ColorBand, 1, tex->coba);
}
- if (tex->type == TEX_ENVMAP && tex->env) {
- writestruct(wd, DATA, EnvMap, 1, tex->env);
- }
- if (tex->type == TEX_POINTDENSITY && tex->pd) {
- writestruct(wd, DATA, PointDensity, 1, tex->pd);
- if (tex->pd->coba) {
- writestruct(wd, DATA, ColorBand, 1, tex->pd->coba);
- }
- if (tex->pd->falloff_curve) {
- write_curvemapping(wd, tex->pd->falloff_curve);
- }
- }
- if (tex->type == TEX_VOXELDATA) {
- writestruct(wd, DATA, VoxelData, 1, tex->vd);
- }
- if (tex->type == TEX_OCEAN && tex->ot) {
- writestruct(wd, DATA, OceanTex, 1, tex->ot);
- }
/* nodetree is integral part of texture, no libdata */
if (tex->nodetree) {
@@ -2449,19 +2300,6 @@ static void write_material(WriteData *wd, Material *ma)
write_animdata(wd, ma->adt);
}
- for (int a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) {
- writestruct(wd, DATA, MTex, 1, ma->mtex[a]);
- }
- }
-
- if (ma->ramp_col) {
- writestruct(wd, DATA, ColorBand, 1, ma->ramp_col);
- }
- if (ma->ramp_spec) {
- writestruct(wd, DATA, ColorBand, 1, ma->ramp_spec);
- }
-
/* nodetree is integral part of material, no libdata */
if (ma->nodetree) {
writestruct(wd, DATA, bNodeTree, 1, ma->nodetree);
@@ -2483,12 +2321,6 @@ static void write_world(WriteData *wd, World *wrld)
write_animdata(wd, wrld->adt);
}
- for (int a = 0; a < MAX_MTEX; a++) {
- if (wrld->mtex[a]) {
- writestruct(wd, DATA, MTex, 1, wrld->mtex[a]);
- }
- }
-
/* nodetree is integral part of world, no libdata */
if (wrld->nodetree) {
writestruct(wd, DATA, bNodeTree, 1, wrld->nodetree);
@@ -2510,13 +2342,6 @@ static void write_lamp(WriteData *wd, Lamp *la)
write_animdata(wd, la->adt);
}
- /* direct data */
- for (int a = 0; a < MAX_MTEX; a++) {
- if (la->mtex[a]) {
- writestruct(wd, DATA, MTex, 1, la->mtex[a]);
- }
- }
-
if (la->curfalloff) {
write_curvemapping(wd, la->curfalloff);
}
@@ -2572,6 +2397,55 @@ static void write_paint(WriteData *wd, Paint *p)
}
}
+static void write_scene_collection(WriteData *wd, SceneCollection *sc)
+{
+ writestruct(wd, DATA, SceneCollection, 1, sc);
+
+ writelist(wd, DATA, LinkData, &sc->objects);
+
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ write_scene_collection(wd, nsc);
+ }
+}
+
+static void write_layer_collections(WriteData *wd, ListBase *lb)
+{
+ for (LayerCollection *lc = lb->first; lc; lc = lc->next) {
+ writestruct(wd, DATA, LayerCollection, 1, lc);
+
+ writelist(wd, DATA, LinkData, &lc->object_bases);
+ writelist(wd, DATA, CollectionOverride, &lc->overrides);
+
+ if (lc->properties) {
+ IDP_WriteProperty(lc->properties, wd);
+ }
+
+ write_layer_collections(wd, &lc->layer_collections);
+ }
+}
+
+static void write_view_layer(WriteData *wd, ViewLayer *view_layer)
+{
+ writestruct(wd, DATA, ViewLayer, 1, view_layer);
+ writelist(wd, DATA, Base, &view_layer->object_bases);
+ if (view_layer->properties) {
+ IDP_WriteProperty(view_layer->properties, wd);
+ }
+
+ if (view_layer->id_properties) {
+ IDP_WriteProperty(view_layer->id_properties, wd);
+ }
+
+ for (FreestyleModuleConfig *fmc = view_layer->freestyle_config.modules.first; fmc; fmc = fmc->next) {
+ writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc);
+ }
+
+ for (FreestyleLineSet *fls = view_layer->freestyle_config.linesets.first; fls; fls = fls->next) {
+ writestruct(wd, DATA, FreestyleLineSet, 1, fls);
+ }
+ write_layer_collections(wd, &view_layer->layer_collections);
+}
+
static void write_scene(WriteData *wd, Scene *sce)
{
/* write LibData */
@@ -2584,10 +2458,6 @@ static void write_scene(WriteData *wd, Scene *sce)
write_keyingsets(wd, &sce->keyingsets);
/* direct data */
- for (Base *base = sce->base.first; base; base = base->next) {
- writestruct(wd, DATA, Base, 1, base);
- }
-
ToolSettings *tos = sce->toolsettings;
writestruct(wd, DATA, ToolSettings, 1, tos);
if (tos->vpaint) {
@@ -2740,19 +2610,6 @@ static void write_scene(WriteData *wd, Scene *sce)
writestruct(wd, DATA, TransformOrientation, 1, ts);
}
- for (SceneRenderLayer *srl = sce->r.layers.first; srl; srl = srl->next) {
- writestruct(wd, DATA, SceneRenderLayer, 1, srl);
- if (srl->prop) {
- IDP_WriteProperty(srl->prop, wd);
- }
- for (FreestyleModuleConfig *fmc = srl->freestyleConfig.modules.first; fmc; fmc = fmc->next) {
- writestruct(wd, DATA, FreestyleModuleConfig, 1, fmc);
- }
- for (FreestyleLineSet *fls = srl->freestyleConfig.linesets.first; fls; fls = fls->next) {
- writestruct(wd, DATA, FreestyleLineSet, 1, fls);
- }
- }
-
/* writing MultiView to the blend file */
for (SceneRenderView *srv = sce->r.views.first; srv; srv = srv->next) {
writestruct(wd, DATA, SceneRenderView, 1, srv);
@@ -2774,6 +2631,19 @@ static void write_scene(WriteData *wd, Scene *sce)
write_previews(wd, sce->preview);
write_curvemapping_curves(wd, &sce->r.mblur_shutter_curve);
+ write_scene_collection(wd, sce->collection);
+
+ for (ViewLayer *view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ write_view_layer(wd, view_layer);
+ }
+
+ if (sce->layer_properties) {
+ IDP_WriteProperty(sce->layer_properties, wd);
+ }
+
+ if (sce->collection_properties) {
+ IDP_WriteProperty(sce->collection_properties, wd);
+ }
}
static void write_gpencil(WriteData *wd, bGPdata *gpd)
@@ -2809,17 +2679,6 @@ static void write_gpencil(WriteData *wd, bGPdata *gpd)
}
}
-static void write_windowmanager(WriteData *wd, wmWindowManager *wm)
-{
- writestruct(wd, ID_WM, wmWindowManager, 1, wm);
- write_iddata(wd, &wm->id);
-
- for (wmWindow *win = wm->windows.first; win; win = win->next) {
- writestruct(wd, DATA, wmWindow, 1, win);
- writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format);
- }
-}
-
static void write_region(WriteData *wd, ARegion *ar, int spacetype)
{
writestruct(wd, DATA, ARegion, 1, ar);
@@ -2900,170 +2759,202 @@ static void write_soops(WriteData *wd, SpaceOops *so)
}
}
-static void write_screen(WriteData *wd, bScreen *sc)
+static void write_area_regions(WriteData *wd, ScrArea *area)
{
- /* write LibData */
- /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
- writestruct(wd, ID_SCRN, bScreen, 1, sc);
- write_iddata(wd, &sc->id);
+ for (ARegion *region = area->regionbase.first; region; region = region->next) {
+ write_region(wd, region, area->spacetype);
- /* direct data */
- for (ScrVert *sv = sc->vertbase.first; sv; sv = sv->next) {
- writestruct(wd, DATA, ScrVert, 1, sv);
- }
+ for (Panel *pa = region->panels.first; pa; pa = pa->next) {
+ writestruct(wd, DATA, Panel, 1, pa);
+ }
- for (ScrEdge *se = sc->edgebase.first; se; se = se->next) {
- writestruct(wd, DATA, ScrEdge, 1, se);
- }
+ for (PanelCategoryStack *pc_act = region->panels_category_active.first; pc_act; pc_act = pc_act->next) {
+ writestruct(wd, DATA, PanelCategoryStack, 1, pc_act);
+ }
- for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl;
- Panel *pa;
- uiList *ui_list;
- uiPreview *ui_preview;
- PanelCategoryStack *pc_act;
- ARegion *ar;
+ for (uiList *ui_list = region->ui_lists.first; ui_list; ui_list = ui_list->next) {
+ write_uilist(wd, ui_list);
+ }
+
+ for (uiPreview *ui_preview = region->ui_previews.first; ui_preview; ui_preview = ui_preview->next) {
+ writestruct(wd, DATA, uiPreview, 1, ui_preview);
+ }
+ }
- writestruct(wd, DATA, ScrArea, 1, sa);
+ for (SpaceLink *sl = area->spacedata.first; sl; sl = sl->next) {
+ for (ARegion *region = sl->regionbase.first; region; region = region->next) {
+ write_region(wd, region, sl->spacetype);
+ }
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- write_region(wd, ar, sa->spacetype);
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
+ writestruct(wd, DATA, View3D, 1, v3d);
- for (pa = ar->panels.first; pa; pa = pa->next) {
- writestruct(wd, DATA, Panel, 1, pa);
+ if (v3d->localvd) {
+ writestruct(wd, DATA, View3D, 1, v3d->localvd);
}
- for (pc_act = ar->panels_category_active.first; pc_act; pc_act = pc_act->next) {
- writestruct(wd, DATA, PanelCategoryStack, 1, pc_act);
+ if (v3d->fx_settings.ssao) {
+ writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao);
+ }
+ if (v3d->fx_settings.dof) {
+ writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof);
}
+ }
+ else if (sl->spacetype == SPACE_IPO) {
+ SpaceIpo *sipo = (SpaceIpo *)sl;
+ ListBase tmpGhosts = sipo->ghostCurves;
+
+ /* temporarily disable ghost curves when saving */
+ sipo->ghostCurves.first = sipo->ghostCurves.last = NULL;
- for (ui_list = ar->ui_lists.first; ui_list; ui_list = ui_list->next) {
- write_uilist(wd, ui_list);
+ writestruct(wd, DATA, SpaceIpo, 1, sl);
+ if (sipo->ads) {
+ writestruct(wd, DATA, bDopeSheet, 1, sipo->ads);
}
- for (ui_preview = ar->ui_previews.first; ui_preview; ui_preview = ui_preview->next) {
- writestruct(wd, DATA, uiPreview, 1, ui_preview);
+ /* reenable ghost curves */
+ sipo->ghostCurves = tmpGhosts;
+ }
+ else if (sl->spacetype == SPACE_BUTS) {
+ writestruct(wd, DATA, SpaceButs, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_FILE) {
+ SpaceFile *sfile = (SpaceFile *)sl;
+
+ writestruct(wd, DATA, SpaceFile, 1, sl);
+ if (sfile->params) {
+ writestruct(wd, DATA, FileSelectParams, 1, sfile->params);
}
}
+ else if (sl->spacetype == SPACE_SEQ) {
+ writestruct(wd, DATA, SpaceSeq, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_OUTLINER) {
+ SpaceOops *so = (SpaceOops *)sl;
+ write_soops(wd, so);
+ }
+ else if (sl->spacetype == SPACE_IMAGE) {
+ writestruct(wd, DATA, SpaceImage, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_TEXT) {
+ writestruct(wd, DATA, SpaceText, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_SCRIPT) {
+ SpaceScript *scr = (SpaceScript *)sl;
+ scr->but_refs = NULL;
+ writestruct(wd, DATA, SpaceScript, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_ACTION) {
+ writestruct(wd, DATA, SpaceAction, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_NLA) {
+ SpaceNla *snla = (SpaceNla *)sl;
- for (sl = sa->spacedata.first; sl; sl = sl->next) {
- for (ar = sl->regionbase.first; ar; ar = ar->next) {
- write_region(wd, ar, sl->spacetype);
+ writestruct(wd, DATA, SpaceNla, 1, snla);
+ if (snla->ads) {
+ writestruct(wd, DATA, bDopeSheet, 1, snla->ads);
}
+ }
+ else if (sl->spacetype == SPACE_NODE) {
+ SpaceNode *snode = (SpaceNode *)sl;
+ bNodeTreePath *path;
+ writestruct(wd, DATA, SpaceNode, 1, snode);
- if (sl->spacetype == SPACE_VIEW3D) {
- View3D *v3d = (View3D *)sl;
- BGpic *bgpic;
- writestruct(wd, DATA, View3D, 1, v3d);
- for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- writestruct(wd, DATA, BGpic, 1, bgpic);
- }
- if (v3d->localvd) {
- writestruct(wd, DATA, View3D, 1, v3d->localvd);
- }
+ for (path = snode->treepath.first; path; path = path->next) {
+ writestruct(wd, DATA, bNodeTreePath, 1, path);
+ }
+ }
+ else if (sl->spacetype == SPACE_CONSOLE) {
+ SpaceConsole *con = (SpaceConsole *)sl;
+ ConsoleLine *cl;
- if (v3d->fx_settings.ssao) {
- writestruct(wd, DATA, GPUSSAOSettings, 1, v3d->fx_settings.ssao);
- }
- if (v3d->fx_settings.dof) {
- writestruct(wd, DATA, GPUDOFSettings, 1, v3d->fx_settings.dof);
- }
+ for (cl = con->history.first; cl; cl = cl->next) {
+ /* 'len_alloc' is invalid on write, set from 'len' on read */
+ writestruct(wd, DATA, ConsoleLine, 1, cl);
+ writedata(wd, DATA, cl->len + 1, cl->line);
}
- else if (sl->spacetype == SPACE_IPO) {
- SpaceIpo *sipo = (SpaceIpo *)sl;
- ListBase tmpGhosts = sipo->ghostCurves;
+ writestruct(wd, DATA, SpaceConsole, 1, sl);
+ }
+#ifdef WITH_TOPBAR_WRITING
+ else if (sl->spacetype == SPACE_TOPBAR) {
+ writestruct(wd, DATA, SpaceTopBar, 1, sl);
+ }
+#endif
+ else if (sl->spacetype == SPACE_USERPREF) {
+ writestruct(wd, DATA, SpaceUserPref, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_CLIP) {
+ writestruct(wd, DATA, SpaceClip, 1, sl);
+ }
+ else if (sl->spacetype == SPACE_INFO) {
+ writestruct(wd, DATA, SpaceInfo, 1, sl);
+ }
+ }
+}
- /* temporarily disable ghost curves when saving */
- sipo->ghostCurves.first = sipo->ghostCurves.last = NULL;
+static void write_area_map(WriteData *wd, ScrAreaMap *area_map)
+{
+ writelist(wd, DATA, ScrVert, &area_map->vertbase);
+ writelist(wd, DATA, ScrEdge, &area_map->edgebase);
+ for (ScrArea *area = area_map->areabase.first; area; area = area->next) {
+ area->butspacetype = area->spacetype; /* Just for compatibility, will be reset below. */
- writestruct(wd, DATA, SpaceIpo, 1, sl);
- if (sipo->ads) {
- writestruct(wd, DATA, bDopeSheet, 1, sipo->ads);
- }
+ writestruct(wd, DATA, ScrArea, 1, area);
- /* reenable ghost curves */
- sipo->ghostCurves = tmpGhosts;
- }
- else if (sl->spacetype == SPACE_BUTS) {
- writestruct(wd, DATA, SpaceButs, 1, sl);
- }
- else if (sl->spacetype == SPACE_FILE) {
- SpaceFile *sfile = (SpaceFile *)sl;
+#ifdef WITH_TOPBAR_WRITING
+ writestruct(wd, DATA, ScrGlobalAreaData, 1, area->global);
+#endif
- writestruct(wd, DATA, SpaceFile, 1, sl);
- if (sfile->params) {
- writestruct(wd, DATA, FileSelectParams, 1, sfile->params);
- }
- }
- else if (sl->spacetype == SPACE_SEQ) {
- writestruct(wd, DATA, SpaceSeq, 1, sl);
- }
- else if (sl->spacetype == SPACE_OUTLINER) {
- SpaceOops *so = (SpaceOops *)sl;
- write_soops(wd, so);
- }
- else if (sl->spacetype == SPACE_IMAGE) {
- writestruct(wd, DATA, SpaceImage, 1, sl);
- }
- else if (sl->spacetype == SPACE_TEXT) {
- writestruct(wd, DATA, SpaceText, 1, sl);
- }
- else if (sl->spacetype == SPACE_SCRIPT) {
- SpaceScript *scr = (SpaceScript *)sl;
- scr->but_refs = NULL;
- writestruct(wd, DATA, SpaceScript, 1, sl);
- }
- else if (sl->spacetype == SPACE_ACTION) {
- writestruct(wd, DATA, SpaceAction, 1, sl);
- }
- else if (sl->spacetype == SPACE_NLA) {
- SpaceNla *snla = (SpaceNla *)sl;
+ write_area_regions(wd, area);
- writestruct(wd, DATA, SpaceNla, 1, snla);
- if (snla->ads) {
- writestruct(wd, DATA, bDopeSheet, 1, snla->ads);
- }
- }
- else if (sl->spacetype == SPACE_TIME) {
- writestruct(wd, DATA, SpaceTime, 1, sl);
- }
- else if (sl->spacetype == SPACE_NODE) {
- SpaceNode *snode = (SpaceNode *)sl;
- bNodeTreePath *path;
- writestruct(wd, DATA, SpaceNode, 1, snode);
+ area->butspacetype = SPACE_EMPTY; /* Unset again, was changed above. */
+ }
+}
- for (path = snode->treepath.first; path; path = path->next) {
- writestruct(wd, DATA, bNodeTreePath, 1, path);
- }
- }
- else if (sl->spacetype == SPACE_LOGIC) {
- writestruct(wd, DATA, SpaceLogic, 1, sl);
- }
- else if (sl->spacetype == SPACE_CONSOLE) {
- SpaceConsole *con = (SpaceConsole *)sl;
- ConsoleLine *cl;
-
- for (cl = con->history.first; cl; cl = cl->next) {
- /* 'len_alloc' is invalid on write, set from 'len' on read */
- writestruct(wd, DATA, ConsoleLine, 1, cl);
- writedata(wd, DATA, cl->len + 1, cl->line);
- }
- writestruct(wd, DATA, SpaceConsole, 1, sl);
+static void write_windowmanager(WriteData *wd, wmWindowManager *wm)
+{
+ writestruct(wd, ID_WM, wmWindowManager, 1, wm);
+ write_iddata(wd, &wm->id);
- }
- else if (sl->spacetype == SPACE_USERPREF) {
- writestruct(wd, DATA, SpaceUserPref, 1, sl);
- }
- else if (sl->spacetype == SPACE_CLIP) {
- writestruct(wd, DATA, SpaceClip, 1, sl);
- }
- else if (sl->spacetype == SPACE_INFO) {
- writestruct(wd, DATA, SpaceInfo, 1, sl);
- }
- }
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+#ifndef WITH_TOPBAR_WRITING
+ /* Don't write global areas yet, while we make changes to them. */
+ ScrAreaMap global_areas = win->global_areas;
+ memset(&win->global_areas, 0, sizeof(win->global_areas));
+#endif
+
+ /* update deprecated screen member (for so loading in 2.7x uses the correct screen) */
+ win->screen = BKE_workspace_active_screen_get(win->workspace_hook);
+
+ writestruct(wd, DATA, wmWindow, 1, win);
+ writestruct(wd, DATA, WorkSpaceInstanceHook, 1, win->workspace_hook);
+ writestruct(wd, DATA, Stereo3dFormat, 1, win->stereo3d_format);
+
+#ifdef WITH_TOPBAR_WRITING
+ write_area_map(wd, &win->global_areas);
+#else
+ win->global_areas = global_areas;
+#endif
+
+ /* data is written, clear deprecated data again */
+ win->screen = NULL;
}
}
+static void write_screen(WriteData *wd, bScreen *sc)
+{
+ /* write LibData */
+ /* in 2.50+ files, the file identifier for screens is patched, forward compatibility */
+ writestruct(wd, ID_SCRN, bScreen, 1, sc);
+ write_iddata(wd, &sc->id);
+
+ write_previews(wd, sc->preview);
+
+ /* direct data */
+ write_area_map(wd, AREAMAP_FROM_SCREEN(sc));
+}
+
static void write_bone(WriteData *wd, Bone *bone)
{
/* PATCH for upward compatibility after 2.37+ armature recode */
@@ -3155,6 +3046,19 @@ static void write_sound(WriteData *wd, bSound *sound)
}
}
+static void write_probe(WriteData *wd, LightProbe *prb)
+{
+ if (prb->id.us > 0 || wd->use_memfile) {
+ /* write LibData */
+ writestruct(wd, ID_LP, LightProbe, 1, prb);
+ write_iddata(wd, &prb->id);
+
+ if (prb->adt) {
+ write_animdata(wd, prb->adt);
+ }
+ }
+}
+
static void write_group(WriteData *wd, Group *group)
{
if (group->id.us > 0 || wd->use_memfile) {
@@ -3163,10 +3067,8 @@ static void write_group(WriteData *wd, Group *group)
write_iddata(wd, &group->id);
write_previews(wd, group->preview);
-
- for (GroupObject *go = group->gobject.first; go; go = go->next) {
- writestruct(wd, DATA, GroupObject, 1, go);
- }
+ write_scene_collection(wd, group->collection);
+ write_view_layer(wd, group->view_layer);
}
}
@@ -3700,6 +3602,17 @@ static void write_cachefile(WriteData *wd, CacheFile *cache_file)
}
}
+static void write_workspace(WriteData *wd, WorkSpace *workspace)
+{
+ ListBase *layouts = BKE_workspace_layouts_get(workspace);
+
+ writestruct(wd, ID_WS, WorkSpace, 1, workspace);
+ writelist(wd, DATA, WorkSpaceLayout, layouts);
+ writelist(wd, DATA, WorkSpaceDataRelation, &workspace->hook_layout_relations);
+ writelist(wd, DATA, WorkSpaceDataRelation, &workspace->scene_viewlayer_relations);
+ writelist(wd, DATA, wmOwnerID, &workspace->owner_ids);
+}
+
/* Keep it last of write_foodata functions. */
static void write_libraries(WriteData *wd, Main *main)
{
@@ -3731,6 +3644,8 @@ static void write_libraries(WriteData *wd, Main *main)
/* XXX needs rethink, just like save UI in undo files now - would be nice to append things only for the]
* quit.blend and temp saves */
if (found_one) {
+ /* Not overridable. */
+
writestruct(wd, ID_LI, Library, 1, main->curlib);
write_iddata(wd, &main->curlib->id);
@@ -3769,18 +3684,22 @@ static void write_global(WriteData *wd, int fileflags, Main *mainvar)
const bool is_undo = wd->use_memfile;
FileGlobal fg;
bScreen *screen;
+ Scene *scene;
+ ViewLayer *render_layer;
char subvstr[8];
/* prevent mem checkers from complaining */
memset(fg.pad, 0, sizeof(fg.pad));
memset(fg.filename, 0, sizeof(fg.filename));
memset(fg.build_hash, 0, sizeof(fg.build_hash));
+ fg.pad1 = NULL;
- current_screen_compat(mainvar, &screen, is_undo);
+ current_screen_compat(mainvar, is_undo, &screen, &scene, &render_layer);
/* XXX still remap G */
fg.curscreen = screen;
- fg.curscene = screen ? screen->scene : NULL;
+ fg.curscene = scene;
+ fg.cur_view_layer = render_layer;
/* prevent to save this, is not good convention, and feature with concerns... */
fg.fileflags = (fileflags & ~G_FILE_FLAGS_RUNTIME);
@@ -3868,131 +3787,159 @@ static bool write_file_handle(
* avoid thumbnail detecting changes because of this. */
mywrite_flush(wd);
- ListBase *lbarray[MAX_LIBARRAY];
- int a = set_listbasepointers(mainvar, lbarray);
- while (a--) {
- ID *id = lbarray[a]->first;
+ OverrideStaticStorage *override_storage = wd->use_memfile ? NULL : BKE_override_static_operations_store_initialize();
- if (id && GS(id->name) == ID_LI) {
- continue; /* Libraries are handled separately below. */
- }
+ /* This outer loop allows to save first datablocks from real mainvar, then the temp ones from override process,
+ * if needed, without duplicating whole code. */
+ Main *bmain = mainvar;
+ do {
+ ListBase *lbarray[MAX_LIBARRAY];
+ int a = set_listbasepointers(bmain, lbarray);
+ while (a--) {
+ ID *id = lbarray[a]->first;
- for (; id; id = id->next) {
- /* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */
- BLI_assert((id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
+ if (id && GS(id->name) == ID_LI) {
+ continue; /* Libraries are handled separately below. */
+ }
- switch ((ID_Type)GS(id->name)) {
- case ID_WM:
- write_windowmanager(wd, (wmWindowManager *)id);
- break;
- case ID_SCR:
- write_screen(wd, (bScreen *)id);
- break;
- case ID_MC:
- write_movieclip(wd, (MovieClip *)id);
- break;
- case ID_MSK:
- write_mask(wd, (Mask *)id);
- break;
- case ID_SCE:
- write_scene(wd, (Scene *)id);
- break;
- case ID_CU:
- write_curve(wd, (Curve *)id);
- break;
- case ID_MB:
- write_mball(wd, (MetaBall *)id);
- break;
- case ID_IM:
- write_image(wd, (Image *)id);
- break;
- case ID_CA:
- write_camera(wd, (Camera *)id);
- break;
- case ID_LA:
- write_lamp(wd, (Lamp *)id);
- break;
- case ID_LT:
- write_lattice(wd, (Lattice *)id);
- break;
- case ID_VF:
- write_vfont(wd, (VFont *)id);
- break;
- case ID_KE:
- write_key(wd, (Key *)id);
- break;
- case ID_WO:
- write_world(wd, (World *)id);
- break;
- case ID_TXT:
- write_text(wd, (Text *)id);
- break;
- case ID_SPK:
- write_speaker(wd, (Speaker *)id);
- break;
- case ID_SO:
- write_sound(wd, (bSound *)id);
- break;
- case ID_GR:
- write_group(wd, (Group *)id);
- break;
- case ID_AR:
- write_armature(wd, (bArmature *)id);
- break;
- case ID_AC:
- write_action(wd, (bAction *)id);
- break;
- case ID_OB:
- write_object(wd, (Object *)id);
- break;
- case ID_MA:
- write_material(wd, (Material *)id);
- break;
- case ID_TE:
- write_texture(wd, (Tex *)id);
- break;
- case ID_ME:
- write_mesh(wd, (Mesh *)id);
- break;
- case ID_PA:
- write_particlesettings(wd, (ParticleSettings *)id);
- break;
- case ID_NT:
- write_nodetree(wd, (bNodeTree *)id);
- break;
- case ID_BR:
- write_brush(wd, (Brush *)id);
- break;
- case ID_PAL:
- write_palette(wd, (Palette *)id);
- break;
- case ID_PC:
- write_paintcurve(wd, (PaintCurve *)id);
- break;
- case ID_GD:
- write_gpencil(wd, (bGPdata *)id);
- break;
- case ID_LS:
- write_linestyle(wd, (FreestyleLineStyle *)id);
- break;
- case ID_CF:
- write_cachefile(wd, (CacheFile *)id);
- break;
- case ID_LI:
- /* Do nothing, handled below - and should never be reached. */
- BLI_assert(0);
- break;
- case ID_IP:
- /* Do nothing, deprecated. */
- break;
- default:
- /* Should never be reached. */
- BLI_assert(0);
- break;
+ for (; id; id = id->next) {
+ /* We should never attempt to write non-regular IDs (i.e. all kind of temp/runtime ones). */
+ BLI_assert((id->tag & (LIB_TAG_NO_MAIN | LIB_TAG_NO_USER_REFCOUNT | LIB_TAG_NOT_ALLOCATED)) == 0);
+
+ const bool do_override = !ELEM(override_storage, NULL, bmain) && id->override_static;
+
+ if (do_override) {
+ BKE_override_static_operations_store_start(override_storage, id);
+ }
+
+ switch ((ID_Type)GS(id->name)) {
+ case ID_WM:
+ write_windowmanager(wd, (wmWindowManager *)id);
+ break;
+ case ID_WS:
+ write_workspace(wd, (WorkSpace *)id);
+ break;
+ case ID_SCR:
+ write_screen(wd, (bScreen *)id);
+ break;
+ case ID_MC:
+ write_movieclip(wd, (MovieClip *)id);
+ break;
+ case ID_MSK:
+ write_mask(wd, (Mask *)id);
+ break;
+ case ID_SCE:
+ write_scene(wd, (Scene *)id);
+ break;
+ case ID_CU:
+ write_curve(wd, (Curve *)id);
+ break;
+ case ID_MB:
+ write_mball(wd, (MetaBall *)id);
+ break;
+ case ID_IM:
+ write_image(wd, (Image *)id);
+ break;
+ case ID_CA:
+ write_camera(wd, (Camera *)id);
+ break;
+ case ID_LA:
+ write_lamp(wd, (Lamp *)id);
+ break;
+ case ID_LT:
+ write_lattice(wd, (Lattice *)id);
+ break;
+ case ID_VF:
+ write_vfont(wd, (VFont *)id);
+ break;
+ case ID_KE:
+ write_key(wd, (Key *)id);
+ break;
+ case ID_WO:
+ write_world(wd, (World *)id);
+ break;
+ case ID_TXT:
+ write_text(wd, (Text *)id);
+ break;
+ case ID_SPK:
+ write_speaker(wd, (Speaker *)id);
+ break;
+ case ID_LP:
+ write_probe(wd, (LightProbe *)id);
+ break;
+ case ID_SO:
+ write_sound(wd, (bSound *)id);
+ break;
+ case ID_GR:
+ write_group(wd, (Group *)id);
+ break;
+ case ID_AR:
+ write_armature(wd, (bArmature *)id);
+ break;
+ case ID_AC:
+ write_action(wd, (bAction *)id);
+ break;
+ case ID_OB:
+ write_object(wd, (Object *)id);
+ break;
+ case ID_MA:
+ write_material(wd, (Material *)id);
+ break;
+ case ID_TE:
+ write_texture(wd, (Tex *)id);
+ break;
+ case ID_ME:
+ write_mesh(wd, (Mesh *)id);
+ break;
+ case ID_PA:
+ write_particlesettings(wd, (ParticleSettings *)id);
+ break;
+ case ID_NT:
+ write_nodetree(wd, (bNodeTree *)id);
+ break;
+ case ID_BR:
+ write_brush(wd, (Brush *)id);
+ break;
+ case ID_PAL:
+ write_palette(wd, (Palette *)id);
+ break;
+ case ID_PC:
+ write_paintcurve(wd, (PaintCurve *)id);
+ break;
+ case ID_GD:
+ write_gpencil(wd, (bGPdata *)id);
+ break;
+ case ID_LS:
+ write_linestyle(wd, (FreestyleLineStyle *)id);
+ break;
+ case ID_CF:
+ write_cachefile(wd, (CacheFile *)id);
+ break;
+ case ID_LI:
+ /* Do nothing, handled below - and should never be reached. */
+ BLI_assert(0);
+ break;
+ case ID_IP:
+ /* Do nothing, deprecated. */
+ break;
+ default:
+ /* Should never be reached. */
+ BLI_assert(0);
+ break;
+ }
+
+ if (do_override) {
+ BKE_override_static_operations_store_end(override_storage, id);
+ }
}
+
+ mywrite_flush(wd);
}
+ } while ((bmain != override_storage) && (bmain = override_storage));
- mywrite_flush(wd);
+ if (override_storage) {
+ BKE_override_static_operations_store_finalize(override_storage);
+ override_storage = NULL;
}
/* Special handling, operating over split Mains... */
diff --git a/source/blender/blentranslation/BLT_translation.h b/source/blender/blentranslation/BLT_translation.h
index 1d76077c9f1..ed1993015f6 100644
--- a/source/blender/blentranslation/BLT_translation.h
+++ b/source/blender/blentranslation/BLT_translation.h
@@ -140,6 +140,7 @@ bool BLT_lang_is_ime_supported(void);
#define BLT_I18NCONTEXT_ID_PAINTCURVE "PaintCurve"
#define BLT_I18NCONTEXT_ID_PALETTE "Palette"
#define BLT_I18NCONTEXT_ID_PARTICLESETTINGS "ParticleSettings"
+#define BLT_I18NCONTEXT_ID_LIGHTPROBE "LightProbe"
#define BLT_I18NCONTEXT_ID_SCENE "Scene"
#define BLT_I18NCONTEXT_ID_SCREEN "Screen"
#define BLT_I18NCONTEXT_ID_SEQUENCE "Sequence"
@@ -149,6 +150,7 @@ bool BLT_lang_is_ime_supported(void);
#define BLT_I18NCONTEXT_ID_TEXT "Text"
#define BLT_I18NCONTEXT_ID_VFONT "VFont"
#define BLT_I18NCONTEXT_ID_WORLD "World"
+#define BLT_I18NCONTEXT_ID_WORKSPACE "WorkSpace"
#define BLT_I18NCONTEXT_ID_WINDOWMANAGER "WindowManager"
#define BLT_I18NCONTEXT_ID_MOVIECLIP "MovieClip"
#define BLT_I18NCONTEXT_ID_MASK "Mask"
@@ -194,6 +196,7 @@ typedef struct {
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PAINTCURVE, "id_paintcurve"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PALETTE, "id_palette"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_PARTICLESETTINGS, "id_particlesettings"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_LIGHTPROBE, "id_lightprobe"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SCENE, "id_scene"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SCREEN, "id_screen"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_SEQUENCE, "id_sequence"), \
@@ -203,6 +206,7 @@ typedef struct {
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_TEXT, "id_text"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_VFONT, "id_vfont"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WORLD, "id_world"), \
+ BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WORKSPACE, "id_workspace"), \
BLT_I18NCONTEXTS_ITEM(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "id_windowmanager"), \
{NULL, NULL, NULL} \
}
diff --git a/source/blender/bmesh/intern/bmesh_mesh.c b/source/blender/bmesh/intern/bmesh_mesh.c
index 7f7f48e37bd..8071637d95e 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.c
+++ b/source/blender/bmesh/intern/bmesh_mesh.c
@@ -1041,7 +1041,8 @@ void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle)
bm_mesh_edges_sharp_tag(bm, NULL, NULL, NULL, split_angle, true);
}
-static void UNUSED_FUNCTION(bm_mdisps_space_set)(Object *ob, BMesh *bm, int from, int to)
+static void UNUSED_FUNCTION(bm_mdisps_space_set)(
+ Object *ob, BMesh *bm, int from, int to)
{
/* switch multires data out of tangent space */
if (CustomData_has_layer(&bm->ldata, CD_MDISPS)) {
@@ -1159,7 +1160,7 @@ void bmesh_edit_end(BMesh *bm, BMOpTypeFlag type_flag)
}
}
-void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
+void BM_mesh_elem_index_ensure_ex(BMesh *bm, const char htype, int elem_offset[4])
{
const char htype_needed = bm->elem_index_dirty & htype;
@@ -1172,15 +1173,15 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
}
if (htype & BM_VERT) {
- if (bm->elem_index_dirty & BM_VERT) {
+ if ((bm->elem_index_dirty & BM_VERT) || (elem_offset && elem_offset[0])) {
BMIter iter;
BMElem *ele;
- int index;
- BM_ITER_MESH_INDEX (ele, &iter, bm, BM_VERTS_OF_MESH, index) {
- BM_elem_index_set(ele, index); /* set_ok */
+ int index = elem_offset ? elem_offset[0] : 0;
+ BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
+ BM_elem_index_set(ele, index++); /* set_ok */
}
- BLI_assert(index == bm->totvert);
+ BLI_assert(elem_offset || index == bm->totvert);
}
else {
// printf("%s: skipping vert index calc!\n", __func__);
@@ -1188,15 +1189,15 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
}
if (htype & BM_EDGE) {
- if (bm->elem_index_dirty & BM_EDGE) {
+ if ((bm->elem_index_dirty & BM_EDGE) || (elem_offset && elem_offset[1])) {
BMIter iter;
BMElem *ele;
- int index;
- BM_ITER_MESH_INDEX (ele, &iter, bm, BM_EDGES_OF_MESH, index) {
- BM_elem_index_set(ele, index); /* set_ok */
+ int index = elem_offset ? elem_offset[1] : 0;
+ BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
+ BM_elem_index_set(ele, index++); /* set_ok */
}
- BLI_assert(index == bm->totedge);
+ BLI_assert(elem_offset || index == bm->totedge);
}
else {
// printf("%s: skipping edge index calc!\n", __func__);
@@ -1204,19 +1205,19 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
}
if (htype & (BM_FACE | BM_LOOP)) {
- if (bm->elem_index_dirty & (BM_FACE | BM_LOOP)) {
+ if ((bm->elem_index_dirty & (BM_FACE | BM_LOOP)) || (elem_offset && (elem_offset[2] || elem_offset[3]))) {
BMIter iter;
BMElem *ele;
const bool update_face = (htype & BM_FACE) && (bm->elem_index_dirty & BM_FACE);
const bool update_loop = (htype & BM_LOOP) && (bm->elem_index_dirty & BM_LOOP);
- int index;
- int index_loop = 0;
+ int index_loop = elem_offset ? elem_offset[2] : 0;
+ int index = elem_offset ? elem_offset[3] : 0;
- BM_ITER_MESH_INDEX (ele, &iter, bm, BM_FACES_OF_MESH, index) {
+ BM_ITER_MESH (ele, &iter, bm, BM_FACES_OF_MESH) {
if (update_face) {
- BM_elem_index_set(ele, index); /* set_ok */
+ BM_elem_index_set(ele, index++); /* set_ok */
}
if (update_loop) {
@@ -1229,9 +1230,9 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
}
}
- BLI_assert(index == bm->totface);
+ BLI_assert(elem_offset || !update_face || index == bm->totface);
if (update_loop) {
- BLI_assert(index_loop == bm->totloop);
+ BLI_assert(elem_offset || !update_loop || index_loop == bm->totloop);
}
}
else {
@@ -1241,6 +1242,37 @@ void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
finally:
bm->elem_index_dirty &= ~htype;
+ if (elem_offset) {
+ if (htype & BM_VERT) {
+ elem_offset[0] += bm->totvert;
+ if (elem_offset[0] != bm->totvert) {
+ bm->elem_index_dirty |= BM_VERT;
+ }
+ }
+ if (htype & BM_EDGE) {
+ elem_offset[1] += bm->totedge;
+ if (elem_offset[1] != bm->totedge) {
+ bm->elem_index_dirty |= BM_EDGE;
+ }
+ }
+ if (htype & BM_LOOP) {
+ elem_offset[2] += bm->totloop;
+ if (elem_offset[2] != bm->totloop) {
+ bm->elem_index_dirty |= BM_LOOP;
+ }
+ }
+ if (htype & BM_FACE) {
+ elem_offset[3] += bm->totface;
+ if (elem_offset[3] != bm->totface) {
+ bm->elem_index_dirty |= BM_FACE;
+ }
+ }
+ }
+}
+
+void BM_mesh_elem_index_ensure(BMesh *bm, const char htype)
+{
+ BM_mesh_elem_index_ensure_ex(bm, htype, NULL);
}
diff --git a/source/blender/bmesh/intern/bmesh_mesh.h b/source/blender/bmesh/intern/bmesh_mesh.h
index d449aac04f5..3ebe6535a8b 100644
--- a/source/blender/bmesh/intern/bmesh_mesh.h
+++ b/source/blender/bmesh/intern/bmesh_mesh.h
@@ -60,6 +60,7 @@ void BM_edges_sharp_from_angle_set(BMesh *bm, const float split_angle);
void bmesh_edit_begin(BMesh *bm, const BMOpTypeFlag type_flag);
void bmesh_edit_end(BMesh *bm, const BMOpTypeFlag type_flag);
+void BM_mesh_elem_index_ensure_ex(BMesh *bm, const char htype, int elem_offset[4]);
void BM_mesh_elem_index_ensure(BMesh *bm, const char hflag);
void BM_mesh_elem_index_validate(
BMesh *bm, const char *location, const char *func,
diff --git a/source/blender/bmesh/intern/bmesh_mesh_conv.c b/source/blender/bmesh/intern/bmesh_mesh_conv.c
index 474b4656a68..fd32119cb5f 100644
--- a/source/blender/bmesh/intern/bmesh_mesh_conv.c
+++ b/source/blender/bmesh/intern/bmesh_mesh_conv.c
@@ -98,42 +98,6 @@
#include "bmesh.h"
#include "intern/bmesh_private.h" /* for element checking */
-/**
- * Currently this is only used for Python scripts
- * which may fail to keep matching UV/TexFace layers.
- *
- * \note This should only perform any changes in exceptional cases,
- * if we need this to be faster we could inline #BM_data_layer_add and only
- * call #update_data_blocks once at the end.
- */
-void BM_mesh_cd_validate(BMesh *bm)
-{
- int totlayer_mtex = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
- int totlayer_uv = CustomData_number_of_layers(&bm->ldata, CD_MLOOPUV);
-
- if (LIKELY(totlayer_mtex == totlayer_uv)) {
- /* pass */
- }
- else if (totlayer_mtex < totlayer_uv) {
- const int uv_index_first = CustomData_get_layer_index(&bm->ldata, CD_MLOOPUV);
- do {
- const char *from_name = bm->ldata.layers[uv_index_first + totlayer_mtex].name;
- BM_data_layer_add_named(bm, &bm->pdata, CD_MTEXPOLY, from_name);
- CustomData_set_layer_unique_name(&bm->pdata, totlayer_mtex);
- } while (totlayer_uv != ++totlayer_mtex);
- }
- else if (totlayer_uv < totlayer_mtex) {
- const int mtex_index_first = CustomData_get_layer_index(&bm->pdata, CD_MTEXPOLY);
- do {
- const char *from_name = bm->pdata.layers[mtex_index_first + totlayer_uv].name;
- BM_data_layer_add_named(bm, &bm->ldata, CD_MLOOPUV, from_name);
- CustomData_set_layer_unique_name(&bm->ldata, totlayer_uv);
- } while (totlayer_mtex != ++totlayer_uv);
- }
-
- BLI_assert(totlayer_mtex == totlayer_uv);
-}
-
void BM_mesh_cd_flag_ensure(BMesh *bm, Mesh *mesh, const char cd_flag)
{
const char cd_flag_all = BM_mesh_cd_flag_from_bmesh(bm) | cd_flag;
@@ -243,7 +207,7 @@ void BM_mesh_bm_from_me(
BMEdge *e, **etable = NULL;
BMFace *f, **ftable = NULL;
float (*keyco)[3] = NULL;
- int totuv, totloops, i;
+ int totloops, i;
if (!me || !me->totvert) {
if (me && is_new) { /*no verts? still copy customdata layout*/
@@ -265,13 +229,6 @@ void BM_mesh_bm_from_me(
CustomData_copy(&me->edata, &bm->edata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&me->ldata, &bm->ldata, CD_MASK_BMESH, CD_CALLOC, 0);
CustomData_copy(&me->pdata, &bm->pdata, CD_MASK_BMESH, CD_CALLOC, 0);
-
- /* make sure uv layer names are consisten */
- totuv = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
- for (i = 0; i < totuv; i++) {
- int li = CustomData_get_layer_index_n(&bm->pdata, CD_MTEXPOLY, i);
- CustomData_set_layer_name(&bm->ldata, CD_MLOOPUV, i, bm->pdata.layers[li].name);
- }
}
/* -------------------------------------------------------------------- */
diff --git a/source/blender/bmesh/intern/bmesh_operators.h b/source/blender/bmesh/intern/bmesh_operators.h
index b670f31ad9f..80b57eb3565 100644
--- a/source/blender/bmesh/intern/bmesh_operators.h
+++ b/source/blender/bmesh/intern/bmesh_operators.h
@@ -77,13 +77,13 @@ enum {
/* similar face selection slot values */
enum {
SIMFACE_MATERIAL = 201,
- SIMFACE_IMAGE,
SIMFACE_AREA,
SIMFACE_SIDES,
SIMFACE_PERIMETER,
SIMFACE_NORMAL,
SIMFACE_COPLANAR,
SIMFACE_SMOOTH,
+ SIMFACE_FACEMAP,
#ifdef WITH_FREESTYLE
SIMFACE_FREESTYLE
#endif
diff --git a/source/blender/bmesh/operators/bmo_similar.c b/source/blender/bmesh/operators/bmo_similar.c
index 454d6d8c6c8..0cd17258834 100644
--- a/source/blender/bmesh/operators/bmo_similar.c
+++ b/source/blender/bmesh/operators/bmo_similar.c
@@ -106,11 +106,28 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op)
const float thresh = BMO_slot_float_get(op->slots_in, "thresh");
const float thresh_radians = thresh * (float)M_PI;
const int compare = BMO_slot_int_get(op->slots_in, "compare");
+ /* for comparison types that use custom-data */
+ int cd_offset = -1;
/* initial_elem - other_elem */
float delta_fl;
int delta_i;
+ if (type == SIMFACE_FACEMAP) {
+ cd_offset = CustomData_get_offset(&bm->pdata, CD_FACEMAP);
+ if (cd_offset == -1) {
+ return;
+ }
+ }
+#ifdef WITH_FREESTYLE
+ else if (type == SIMFACE_FREESTYLE) {
+ cd_offset = CustomData_get_offset(&bm->pdata, CD_FREESTYLE_FACE);
+ if (cd_offset == -1) {
+ return;
+ }
+ }
+#endif
+
num_total = BM_mesh_elem_count(bm, BM_FACE);
/*
@@ -145,7 +162,7 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op)
* Save us some computation burden: In case of perimeter/area/coplanar selection we compute
* only once.
*/
- if (type == SIMFACE_PERIMETER || type == SIMFACE_AREA || type == SIMFACE_COPLANAR || type == SIMFACE_IMAGE) {
+ if (type == SIMFACE_PERIMETER || type == SIMFACE_AREA || type == SIMFACE_COPLANAR) {
for (i = 0; i < num_total; i++) {
switch (type) {
case SIMFACE_PERIMETER:
@@ -164,14 +181,6 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op)
case SIMFACE_AREA:
f_ext[i].area = BM_face_calc_area(f_ext[i].f);
break;
-
- case SIMFACE_IMAGE:
- f_ext[i].t = NULL;
- if (CustomData_has_layer(&(bm->pdata), CD_MTEXPOLY)) {
- MTexPoly *mtpoly = CustomData_bmesh_get(&bm->pdata, f_ext[i].f->head.data, CD_MTEXPOLY);
- f_ext[i].t = mtpoly->tpage;
- }
- break;
}
}
}
@@ -190,14 +199,6 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op)
cont = false;
}
break;
-
- case SIMFACE_IMAGE:
- if (f_ext[i].t == f_ext[indices[idx]].t) {
- BMO_face_flag_enable(bm, fm, FACE_MARK);
- cont = false;
- }
- break;
-
case SIMFACE_NORMAL:
angle = angle_normalized_v3v3(fs->no, fm->no); /* if the angle between the normals -> 0 */
if (angle <= thresh_radians) {
@@ -254,20 +255,29 @@ void bmo_similar_faces_exec(BMesh *bm, BMOperator *op)
cont = false;
}
break;
+ case SIMFACE_FACEMAP:
+ {
+ BLI_assert(cd_offset != -1);
+ const int *fmap1 = BM_ELEM_CD_GET_VOID_P(fs, cd_offset);
+ const int *fmap2 = BM_ELEM_CD_GET_VOID_P(fm, cd_offset);
+ if (*fmap1 == *fmap2) {
+ BMO_face_flag_enable(bm, fm, FACE_MARK);
+ cont = false;
+ }
+ break;
+ }
#ifdef WITH_FREESTYLE
case SIMFACE_FREESTYLE:
- if (CustomData_has_layer(&bm->pdata, CD_FREESTYLE_FACE)) {
- FreestyleEdge *ffa1, *ffa2;
-
- ffa1 = CustomData_bmesh_get(&bm->pdata, fs->head.data, CD_FREESTYLE_FACE);
- ffa2 = CustomData_bmesh_get(&bm->pdata, fm->head.data, CD_FREESTYLE_FACE);
-
- if (ffa1 && ffa2 && (ffa1->flag & FREESTYLE_FACE_MARK) == (ffa2->flag & FREESTYLE_FACE_MARK)) {
- BMO_face_flag_enable(bm, fm, FACE_MARK);
- cont = false;
- }
+ {
+ BLI_assert(cd_offset != -1);
+ const FreestyleEdge *ffa1 = BM_ELEM_CD_GET_VOID_P(fs, cd_offset);
+ const FreestyleEdge *ffa2 = BM_ELEM_CD_GET_VOID_P(fm, cd_offset);
+ if ((ffa1->flag & FREESTYLE_FACE_MARK) == (ffa2->flag & FREESTYLE_FACE_MARK)) {
+ BMO_face_flag_enable(bm, fm, FACE_MARK);
+ cont = false;
}
break;
+ }
#endif
default:
BLI_assert(0);
diff --git a/source/blender/bmesh/tools/bmesh_intersect.c b/source/blender/bmesh/tools/bmesh_intersect.c
index acadb663810..cc8511c65f1 100644
--- a/source/blender/bmesh/tools/bmesh_intersect.c
+++ b/source/blender/bmesh/tools/bmesh_intersect.c
@@ -81,12 +81,6 @@
/* use accelerated overlap check */
#define USE_BVH
-// #define USE_BOOLEAN_RAYCAST_DRAW
-
-#ifdef USE_BOOLEAN_RAYCAST_DRAW
-/* insert bl_debug_draw_quad_clear... here */
-#endif
-
// #define USE_DUMP
static void tri_v3_scale(
@@ -1006,10 +1000,6 @@ bool BM_mesh_intersect(
int i_a, i_b;
#endif
-#ifdef USE_BOOLEAN_RAYCAST_DRAW
- bl_debug_draw_quad_clear();
-#endif
-
s.bm = bm;
s.edgetri_cache = BLI_ghash_new(BLI_ghashutil_inthash_v4_p, BLI_ghashutil_inthash_v4_cmp, __func__);
@@ -1607,17 +1597,6 @@ bool BM_mesh_intersect(
do_flip = (side == 0);
break;
}
-
-#ifdef USE_BOOLEAN_RAYCAST_DRAW
- {
- uint colors[4] = {0x00000000, 0xffffffff, 0xff000000, 0x0000ff};
- float co_other[3] = {UNPACK3(co)};
- co_other[0] += 1000.0f;
- bl_debug_color_set(colors[(hits & 1) == 1]);
- bl_debug_draw_edge_add(co, co_other);
- }
-#endif
-
}
if (do_remove) {
diff --git a/source/blender/collada/AnimationExporter.cpp b/source/blender/collada/AnimationExporter.cpp
index a59665f897f..a3e26451a38 100644
--- a/source/blender/collada/AnimationExporter.cpp
+++ b/source/blender/collada/AnimationExporter.cpp
@@ -214,7 +214,7 @@ void AnimationExporter::export_sampled_matrix_animation(Object *ob, std::vector<
for (std::vector<float>::iterator ctime = ctimes.begin(); ctime != ctimes.end(); ++ctime) {
float fmat[4][4];
- bc_update_scene(scene, *ctime);
+ bc_update_scene(depsgraph, scene, *ctime);
BKE_object_matrix_local_get(ob, fmat);
if (this->export_settings->limit_precision)
bc_sanitize_mat(fmat, 6);
@@ -246,7 +246,7 @@ void AnimationExporter::export_sampled_transrotloc_animation(Object *ob, std::ve
float fsize[3];
float feul[3];
- bc_update_scene(scene, *ctime);
+ bc_update_scene(depsgraph, scene, *ctime);
BKE_object_matrix_local_get(ob, fmat);
mat4_decompose(floc, fquat, fsize, fmat);
quat_to_eul(feul, fquat);
@@ -721,7 +721,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B
if (flag & ARM_RESTPOS) {
arm->flag &= ~ARM_RESTPOS;
- BKE_pose_where_is(scene, ob_arm);
+ BKE_pose_where_is(depsgraph, scene, ob_arm);
}
if (fra.size()) {
@@ -730,7 +730,7 @@ void AnimationExporter::sample_and_write_bone_animation_matrix(Object *ob_arm, B
if (flag & ARM_RESTPOS)
arm->flag = flag;
- BKE_pose_where_is(scene, ob_arm);
+ BKE_pose_where_is(depsgraph, scene, ob_arm);
}
void AnimationExporter::dae_baked_animation(std::vector<float> &fra, Object *ob_arm, Bone *bone)
@@ -1021,7 +1021,7 @@ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime)
if (obtar) {
BKE_animsys_evaluate_animdata(scene, &obtar->id, obtar->adt, ctime, ADT_RECALC_ANIM);
- BKE_object_where_is_calc_time(scene, obtar, ctime);
+ BKE_object_where_is_calc_time(this->depsgraph, scene, obtar, ctime);
}
}
@@ -1029,7 +1029,7 @@ void AnimationExporter::evaluate_anim_with_constraints(Object *ob, float ctime)
cti->flush_constraint_targets(con, &targets, 1);
}
}
- BKE_object_where_is_calc_time(scene, ob, ctime);
+ BKE_object_where_is_calc_time(this->depsgraph, scene, ob, ctime);
}
/*
@@ -1315,15 +1315,16 @@ std::string AnimationExporter::create_4x4_source(std::vector<float> &frames, Obj
float frame = *it;
float ctime = BKE_scene_frame_get_from_ctime(scene, frame);
- bc_update_scene(scene, ctime);
+ bc_update_scene(depsgraph, scene, ctime);
if (is_bone_animation) {
+
if (pchan->flag & POSE_CHAIN) {
enable_fcurves(ob->adt->action, NULL);
BKE_animsys_evaluate_animdata(scene, &ob->id, ob->adt, ctime, ADT_RECALC_ALL);
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
}
else {
- BKE_pose_where_is_bone(scene, ob, pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, scene, ob, pchan, ctime, 1);
}
// compute bone local mat
@@ -1841,7 +1842,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo
// exit rest position
if (flag & ARM_RESTPOS) {
arm->flag &= ~ARM_RESTPOS;
- BKE_pose_where_is(scene, ob_arm);
+ BKE_pose_where_is(depsgraph, scene, ob_arm);
}
//v array will hold all values which will be exported.
if (fra.size()) {
@@ -1871,7 +1872,7 @@ void AnimationExporter::sample_and_write_bone_animation(Object *ob_arm, Bone *bo
// restore restpos
if (flag & ARM_RESTPOS)
arm->flag = flag;
- BKE_pose_where_is(scene, ob_arm);
+ BKE_pose_where_is(depsgraph, scene, ob_arm);
}
void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, int type, Bone *bone, Object *ob_arm, bPoseChannel *pchan)
@@ -1896,7 +1897,7 @@ void AnimationExporter::sample_animation(float *v, std::vector<float> &frames, i
BKE_animsys_evaluate_animdata(scene, &ob_arm->id, ob_arm->adt, ctime, ADT_RECALC_ANIM);
- BKE_pose_where_is_bone(scene, ob_arm, pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, scene, ob_arm, pchan, ctime, 1);
// compute bone local mat
if (bone->parent) {
diff --git a/source/blender/collada/AnimationExporter.h b/source/blender/collada/AnimationExporter.h
index a739b2b6cbe..2ed0a92d89c 100644
--- a/source/blender/collada/AnimationExporter.h
+++ b/source/blender/collada/AnimationExporter.h
@@ -79,25 +79,26 @@ extern "C"
#include <vector>
#include <algorithm> // std::find
-
+struct Depsgraph;
class AnimationExporter: COLLADASW::LibraryAnimations
{
private:
Scene *scene;
+ Depsgraph *depsgraph;
COLLADASW::StreamWriter *sw;
public:
- AnimationExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings):
+ AnimationExporter(Depsgraph *depsgraph, COLLADASW::StreamWriter *sw, const ExportSettings *export_settings):
COLLADASW::LibraryAnimations(sw),
+ depsgraph(depsgraph),
export_settings(export_settings)
{
this->sw = sw;
}
bool exportAnimations(Scene *sce);
-
// called for each exported object
void operator() (Object *ob);
diff --git a/source/blender/collada/AnimationImporter.cpp b/source/blender/collada/AnimationImporter.cpp
index 75017ce32b4..f37b0ee1319 100644
--- a/source/blender/collada/AnimationImporter.cpp
+++ b/source/blender/collada/AnimationImporter.cpp
@@ -1939,7 +1939,7 @@ Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root, COLLADAFW::No
job->lay = BKE_scene_base_find(scene, job)->lay = 2;
mul_v3_fl(job->size, 0.5f);
- DAG_id_tag_update(&job->id, OB_RECALC_OB);
+ DEG_id_tag_update(&job->id, OB_RECALC_OB);
verify_adt_action((ID *)&job->id, 1);
@@ -1960,14 +1960,14 @@ Object *AnimationImporter::get_joint_object(COLLADAFW::Node *root, COLLADAFW::No
if (par_job) {
job->parent = par_job;
- DAG_id_tag_update(&par_job->id, OB_RECALC_OB);
+ DEG_id_tag_update(&par_job->id, OB_RECALC_OB);
job->parsubstr[0] = 0;
}
BKE_object_where_is_calc(scene, job);
// after parenting and layer change
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
joint_objects[node->getUniqueId()] = job;
}
diff --git a/source/blender/collada/ArmatureExporter.cpp b/source/blender/collada/ArmatureExporter.cpp
index 92ec8b470a8..5e349535610 100644
--- a/source/blender/collada/ArmatureExporter.cpp
+++ b/source/blender/collada/ArmatureExporter.cpp
@@ -62,8 +62,8 @@ ArmatureExporter::ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSett
}
// write bone nodes
-void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce,
- SceneExporter *se,
+void ArmatureExporter::add_armature_bones(Depsgraph *depsgraph, Object *ob_arm,
+ Scene *sce, SceneExporter *se,
std::list<Object *>& child_objects)
{
// write bone nodes
@@ -77,7 +77,7 @@ void ArmatureExporter::add_armature_bones(Object *ob_arm, Scene *sce,
for (Bone *bone = (Bone *)armature->bonebase.first; bone; bone = bone->next) {
// start from root bones
if (!bone->parent)
- add_bone_node(bone, ob_arm, sce, se, child_objects);
+ add_bone_node(depsgraph, bone, ob_arm, sce, se, child_objects);
}
if (!is_edited) {
@@ -116,10 +116,7 @@ bool ArmatureExporter::add_instance_controller(Object *ob)
write_bone_URLs(ins, ob_arm, bone);
}
- InstanceWriter::add_material_bindings(ins.getBindMaterial(),
- ob,
- this->export_settings->active_uv_only,
- this->export_settings->export_texture_type);
+ InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only);
ins.add();
return true;
@@ -160,7 +157,7 @@ void ArmatureExporter::find_objects_using_armature(Object *ob_arm, std::vector<O
#endif
// parent_mat is armature-space
-void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce,
+void ArmatureExporter::add_bone_node(Depsgraph *depsgraph, Bone *bone, Object *ob_arm, Scene *sce,
SceneExporter *se,
std::list<Object *>& child_objects)
{
@@ -234,7 +231,7 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce,
mul_m4_m4m4((*i)->parentinv, temp, (*i)->parentinv);
}
- se->writeNodes(*i, sce);
+ se->writeNodes(depsgraph, *i, sce);
copy_m4_m4((*i)->parentinv, backup_parinv);
child_objects.erase(i++);
@@ -243,13 +240,13 @@ void ArmatureExporter::add_bone_node(Bone *bone, Object *ob_arm, Scene *sce,
}
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
- add_bone_node(child, ob_arm, sce, se, child_objects);
+ add_bone_node(depsgraph, child, ob_arm, sce, se, child_objects);
}
node.end();
}
else {
for (Bone *child = (Bone *)bone->childbase.first; child; child = child->next) {
- add_bone_node(child, ob_arm, sce, se, child_objects);
+ add_bone_node(depsgraph, child, ob_arm, sce, se, child_objects);
}
}
}
diff --git a/source/blender/collada/ArmatureExporter.h b/source/blender/collada/ArmatureExporter.h
index d271b505aa9..17c02d637e8 100644
--- a/source/blender/collada/ArmatureExporter.h
+++ b/source/blender/collada/ArmatureExporter.h
@@ -60,7 +60,7 @@ public:
ArmatureExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
// write bone nodes
- void add_armature_bones(Object *ob_arm, Scene *sce, SceneExporter *se,
+ void add_armature_bones(struct Depsgraph *depsgraph, Object *ob_arm, Scene *sce, SceneExporter *se,
std::list<Object *>& child_objects);
bool add_instance_controller(Object *ob);
@@ -85,7 +85,7 @@ private:
// Scene, SceneExporter and the list of child_objects
// are required for writing bone parented objects
- void add_bone_node(Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se,
+ void add_bone_node(struct Depsgraph *depsgraph, Bone *bone, Object *ob_arm, Scene *sce, SceneExporter *se,
std::list<Object *>& child_objects);
void add_bone_transform(Object *ob_arm, Bone *bone, COLLADASW::Node& node);
diff --git a/source/blender/collada/ArmatureImporter.cpp b/source/blender/collada/ArmatureImporter.cpp
index c32a2a7034e..f24688479af 100644
--- a/source/blender/collada/ArmatureImporter.cpp
+++ b/source/blender/collada/ArmatureImporter.cpp
@@ -34,7 +34,6 @@
extern "C" {
#include "BKE_action.h"
-#include "BKE_depsgraph.h"
#include "BKE_object.h"
#include "BKE_armature.h"
#include "BLI_string.h"
@@ -42,6 +41,8 @@ extern "C" {
#include "ED_armature.h"
}
+#include "DEG_depsgraph.h"
+
#include "collada_utils.h"
#include "ArmatureImporter.h"
@@ -54,9 +55,10 @@ static const char *bc_get_joint_name(T *node)
}
-ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, const ImportSettings *import_settings) :
+ArmatureImporter::ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, ViewLayer *view_layer, const ImportSettings *import_settings) :
TransformReader(conv),
scene(sce),
+ view_layer(view_layer),
unit_converter(conv),
import_settings(import_settings),
empty(NULL),
@@ -409,7 +411,7 @@ Object *ArmatureImporter::get_empty_for_leaves()
{
if (empty) return empty;
- empty = bc_add_object(scene, OB_EMPTY, NULL);
+ empty = bc_add_object(scene, view_layer, OB_EMPTY, NULL);
empty->empty_drawtype = OB_EMPTY_SPHERE;
return empty;
@@ -495,7 +497,7 @@ void ArmatureImporter::create_armature_bones(std::vector<Object *> &ob_arms)
ob_arms.push_back(ob_arm);
}
- DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
}
}
@@ -584,7 +586,7 @@ Object *ArmatureImporter::create_armature_bones(SkinInfo& skin)
ob_arm = skin.set_armature(shared);
}
else {
- ob_arm = skin.create_armature(scene); //once for every armature
+ ob_arm = skin.create_armature(scene, view_layer); //once for every armature
}
// enter armature edit mode
@@ -628,7 +630,7 @@ Object *ArmatureImporter::create_armature_bones(SkinInfo& skin)
ED_armature_from_edit(armature);
ED_armature_edit_free(armature);
- DAG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_arm->id, OB_RECALC_OB | OB_RECALC_DATA);
return ob_arm;
}
diff --git a/source/blender/collada/ArmatureImporter.h b/source/blender/collada/ArmatureImporter.h
index 17173f157e5..f260bb2307c 100644
--- a/source/blender/collada/ArmatureImporter.h
+++ b/source/blender/collada/ArmatureImporter.h
@@ -63,6 +63,7 @@ class ArmatureImporter : private TransformReader
{
private:
Scene *scene;
+ ViewLayer *view_layer;
UnitConverter *unit_converter;
const ImportSettings *import_settings;
@@ -137,7 +138,7 @@ private:
TagsMap uid_tags_map;
public:
- ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, const ImportSettings *import_settings);
+ ArmatureImporter(UnitConverter *conv, MeshImporterBase *mesh, Scene *sce, ViewLayer *view_layer, const ImportSettings *import_settings);
~ArmatureImporter();
void add_root_joint(COLLADAFW::Node *node, Object *parent);
diff --git a/source/blender/collada/CMakeLists.txt b/source/blender/collada/CMakeLists.txt
index 293049a1a05..8642bbee698 100644
--- a/source/blender/collada/CMakeLists.txt
+++ b/source/blender/collada/CMakeLists.txt
@@ -30,6 +30,7 @@ set(INC
../blenkernel
../blenlib
../blentranslation
+ ../depsgraph
../editors/include
../makesdna
../makesrna
diff --git a/source/blender/collada/ControllerExporter.cpp b/source/blender/collada/ControllerExporter.cpp
index 14e8e0323a8..f6dbc965b42 100644
--- a/source/blender/collada/ControllerExporter.cpp
+++ b/source/blender/collada/ControllerExporter.cpp
@@ -98,17 +98,15 @@ bool ControllerExporter::add_instance_controller(Object *ob)
write_bone_URLs(ins, ob_arm, bone);
}
- InstanceWriter::add_material_bindings(ins.getBindMaterial(),
- ob,
- this->export_settings->active_uv_only,
- this->export_settings->export_texture_type);
+ InstanceWriter::add_material_bindings(ins.getBindMaterial(), ob, this->export_settings->active_uv_only);
ins.add();
return true;
}
-void ControllerExporter::export_controllers(Scene *sce)
+void ControllerExporter::export_controllers(struct Depsgraph *depsgraph, Scene *sce)
{
+ this->depsgraph = depsgraph;
scene = sce;
openLibrary();
@@ -200,7 +198,7 @@ void ControllerExporter::export_skin_controller(Object *ob, Object *ob_arm)
bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me;
- me = bc_get_mesh_copy(scene,
+ me = bc_get_mesh_copy(depsgraph, scene,
ob,
this->export_settings->export_mesh_type,
this->export_settings->apply_modifiers,
@@ -302,7 +300,7 @@ void ControllerExporter::export_morph_controller(Object *ob, Key *key)
bool use_instantiation = this->export_settings->use_object_instantiation;
Mesh *me;
- me = bc_get_mesh_copy(scene,
+ me = bc_get_mesh_copy(depsgraph, scene,
ob,
this->export_settings->export_mesh_type,
this->export_settings->apply_modifiers,
@@ -497,7 +495,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas
// put armature in rest position
if (!(arm->flag & ARM_RESTPOS)) {
arm->flag |= ARM_RESTPOS;
- BKE_pose_where_is(scene, ob_arm);
+ BKE_pose_where_is(depsgraph, scene, ob_arm);
}
for (bDeformGroup *def = (bDeformGroup *)defbase->first; def; def = def->next) {
@@ -545,7 +543,7 @@ std::string ControllerExporter::add_inv_bind_mats_source(Object *ob_arm, ListBas
// back from rest positon
if (!(flag & ARM_RESTPOS)) {
arm->flag = flag;
- BKE_pose_where_is(scene, ob_arm);
+ BKE_pose_where_is(depsgraph, scene, ob_arm);
}
source.finish();
diff --git a/source/blender/collada/ControllerExporter.h b/source/blender/collada/ControllerExporter.h
index 80b858ca6dd..e13d7c7ebea 100644
--- a/source/blender/collada/ControllerExporter.h
+++ b/source/blender/collada/ControllerExporter.h
@@ -54,6 +54,7 @@
#include "BKE_key.h"
+struct Depsgraph;
class SceneExporter;
class ControllerExporter : public COLLADASW::LibraryControllers, protected TransformWriter, protected InstanceWriter
@@ -65,11 +66,12 @@ public:
bool add_instance_controller(Object *ob);
- void export_controllers(Scene *sce);
+ void export_controllers(struct Depsgraph *depsgraph, Scene *sce);
void operator()(Object *ob);
private:
+ struct Depsgraph *depsgraph;
Scene *scene;
UnitConverter converter;
const ExportSettings *export_settings;
diff --git a/source/blender/collada/DocumentExporter.cpp b/source/blender/collada/DocumentExporter.cpp
index d4eb6b477db..a66c4db7b4d 100644
--- a/source/blender/collada/DocumentExporter.cpp
+++ b/source/blender/collada/DocumentExporter.cpp
@@ -71,7 +71,6 @@ extern "C"
#include "DNA_mesh_types.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
-#include "DNA_texture_types.h"
#include "DNA_anim_types.h"
#include "DNA_action_types.h"
#include "DNA_curve_types.h"
@@ -138,8 +137,7 @@ extern bool bc_has_object_type(LinkNode *export_set, short obtype);
char *bc_CustomData_get_layer_name(const struct CustomData *data, int type, int n)
{
int layer_index = CustomData_get_layer_index(data, type);
- if (layer_index < 0)
- return NULL;
+ if (layer_index < 0) return NULL;
return data->layers[layer_index + n].name;
}
@@ -148,13 +146,14 @@ char *bc_CustomData_get_active_layer_name(const CustomData *data, int type)
{
/* get the layer index of the active layer of type */
int layer_index = CustomData_get_active_layer_index(data, type);
- if (layer_index < 1)
- return NULL;
+ if (layer_index < 0) return NULL;
- return bc_CustomData_get_layer_name(data, type, layer_index-1);
+ return data->layers[layer_index].name;
}
-DocumentExporter::DocumentExporter(const ExportSettings *export_settings) : export_settings(export_settings) {
+DocumentExporter::DocumentExporter(Depsgraph *depsgraph, const ExportSettings *export_settings) :
+ depsgraph(depsgraph),
+ export_settings(export_settings) {
}
static COLLADABU::NativeString make_temp_filepath(const char *name, const char *extension)
@@ -181,7 +180,8 @@ static COLLADABU::NativeString make_temp_filepath(const char *name, const char *
// COLLADA allows this through multiple <channel>s in <animation>.
// For this to work, we need to know objects that use a certain action.
-int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scene *sce)
+
+int DocumentExporter::exportCurrentScene(Scene *sce)
{
PointerRNA sceneptr, unit_settings;
PropertyRNA *system; /* unused , *scale; */
@@ -287,7 +287,7 @@ int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scen
// <library_geometries>
if (bc_has_object_type(export_set, OB_MESH)) {
GeometryExporter ge(writer, this->export_settings);
- ge.exportGeom(sce);
+ ge.exportGeom(depsgraph, sce);
}
// <library_controllers>
@@ -295,7 +295,7 @@ int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scen
ControllerExporter controller_exporter(writer, this->export_settings);
if (bc_has_object_type(export_set, OB_ARMATURE) || this->export_settings->include_shapekeys)
{
- controller_exporter.export_controllers(sce);
+ controller_exporter.export_controllers(depsgraph, sce);
}
// <library_visual_scenes>
@@ -304,10 +304,10 @@ int DocumentExporter::exportCurrentScene(const EvaluationContext *eval_ctx, Scen
if (this->export_settings->include_animations) {
// <library_animations>
- AnimationExporter ae(writer, this->export_settings);
+ AnimationExporter ae(depsgraph, writer, this->export_settings);
ae.exportAnimations(sce);
}
- se.exportScene(sce);
+ se.exportScene(depsgraph, sce);
// <scene>
std::string scene_name(translate_id(id_name(sce)));
diff --git a/source/blender/collada/DocumentExporter.h b/source/blender/collada/DocumentExporter.h
index 60e5deb0e31..c98f82e68b4 100644
--- a/source/blender/collada/DocumentExporter.h
+++ b/source/blender/collada/DocumentExporter.h
@@ -31,7 +31,7 @@
extern "C" {
#include "DNA_customdata_types.h"
-#include "BKE_depsgraph.h"
+
}
struct Scene;
@@ -39,10 +39,12 @@ struct Scene;
class DocumentExporter
{
public:
- DocumentExporter(const ExportSettings *export_settings);
- int exportCurrentScene(const EvaluationContext *eval_ctx, Scene *sce);
+ DocumentExporter(Depsgraph *depsgraph, const ExportSettings *export_settings);
+ int exportCurrentScene(Scene *sce);
+
void exportScenes(const char *filename);
private:
+ Depsgraph *depsgraph;
const ExportSettings *export_settings;
};
diff --git a/source/blender/collada/DocumentImporter.cpp b/source/blender/collada/DocumentImporter.cpp
index ce0d296843b..d50c4bb23c4 100644
--- a/source/blender/collada/DocumentImporter.cpp
+++ b/source/blender/collada/DocumentImporter.cpp
@@ -57,12 +57,12 @@ extern "C" {
#include "BLI_fileops.h"
#include "BKE_camera.h"
+#include "BKE_collection.h"
#include "BKE_main.h"
+#include "BKE_layer.h"
#include "BKE_lamp.h"
#include "BKE_library.h"
-#include "BKE_texture.h"
#include "BKE_fcurve.h"
-#include "BKE_depsgraph.h"
#include "BKE_scene.h"
#include "BKE_global.h"
#include "BKE_material.h"
@@ -82,6 +82,9 @@ extern "C" {
}
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ExtraHandler.h"
#include "ErrorHandler.h"
#include "DocumentImporter.h"
@@ -104,8 +107,9 @@ DocumentImporter::DocumentImporter(bContext *C, const ImportSettings *import_set
import_settings(import_settings),
mImportStage(General),
mContext(C),
- armature_importer(&unit_converter, &mesh_importer, CTX_data_scene(C), import_settings),
- mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C)),
+ view_layer(CTX_data_view_layer(mContext)),
+ armature_importer(&unit_converter, &mesh_importer, CTX_data_scene(C), view_layer, import_settings),
+ mesh_importer(&unit_converter, &armature_importer, CTX_data_scene(C), view_layer),
anim_importer(&unit_converter, &armature_importer, CTX_data_scene(C))
{
}
@@ -130,7 +134,7 @@ bool DocumentImporter::import()
loader.registerExtraDataCallbackHandler(ehandler);
// deselect all to select new objects
- BKE_scene_base_deselect_all(CTX_data_scene(mContext));
+ BKE_view_layer_base_deselect_all(view_layer);
std::string mFilename = std::string(this->import_settings->filepath);
const std::string encodedFilename = bc_url_encode(mFilename);
@@ -230,7 +234,7 @@ void DocumentImporter::finish()
}
// update scene
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(mContext, NC_OBJECT | ND_TRANSFORM, NULL);
}
@@ -241,7 +245,7 @@ void DocumentImporter::finish()
armature_importer.set_tags_map(this->uid_tags_map);
armature_importer.make_armatures(mContext, *objects_to_scale);
armature_importer.make_shape_keys();
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
#if 0
armature_importer.fix_animation();
@@ -259,22 +263,14 @@ void DocumentImporter::finish()
fprintf(stderr, "got %d library nodes to free\n", (int)libnode_ob.size());
// free all library_nodes
- std::vector<Object *>::iterator lit;
- for (lit = libnode_ob.begin(); lit != libnode_ob.end(); lit++) {
- Object *ob = *lit;
-
- Base *base = BKE_scene_base_find(sce, ob);
- if (base) {
- BLI_remlink(&sce->base, base);
- BKE_libblock_free_us(G.main, base->object);
- if (sce->basact == base)
- sce->basact = NULL;
- MEM_freeN(base);
- }
+ std::vector<Object *>::iterator it;
+ for (it = libnode_ob.begin(); it != libnode_ob.end(); it++) {
+ Object *ob = *it;
+ BKE_collections_object_remove(G.main, &sce->id, ob, true);
}
libnode_ob.clear();
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
bc_match_scale(objects_to_scale, unit_converter, !this->import_settings->import_units);
@@ -383,7 +379,7 @@ Object *DocumentImporter::create_camera_object(COLLADAFW::InstanceCamera *camera
return NULL;
}
- Object *ob = bc_add_object(sce, OB_CAMERA, NULL);
+ Object *ob = bc_add_object(sce, view_layer, OB_CAMERA, NULL);
Camera *cam = uid_camera_map[cam_uid];
Camera *old_cam = (Camera *)ob->data;
ob->data = cam;
@@ -399,7 +395,7 @@ Object *DocumentImporter::create_lamp_object(COLLADAFW::InstanceLight *lamp, Sce
return NULL;
}
- Object *ob = bc_add_object(sce, OB_LAMP, NULL);
+ Object *ob = bc_add_object(sce, view_layer, OB_LAMP, NULL);
Lamp *la = uid_lamp_map[lamp_uid];
Lamp *old_lamp = (Lamp *)ob->data;
ob->data = la;
@@ -412,8 +408,8 @@ Object *DocumentImporter::create_instance_node(Object *source_ob, COLLADAFW::Nod
fprintf(stderr, "create <instance_node> under node id=%s from node id=%s\n", instance_node ? instance_node->getOriginalId().c_str() : NULL, source_node ? source_node->getOriginalId().c_str() : NULL);
Object *obn = BKE_object_copy(G.main, source_ob);
- DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
- BKE_scene_base_add(sce, obn);
+ DEG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ BKE_collection_object_add_from(sce, source_ob, obn);
if (instance_node) {
anim_importer.read_node_transform(instance_node, obn);
@@ -515,7 +511,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
if (parent_node == NULL && !is_library_node) {
// A Joint on root level is a skeleton without root node.
// Here we add the armature "on the fly":
- par = bc_add_object(sce, OB_ARMATURE, std::string("Armature").c_str());
+ par = bc_add_object(sce, view_layer, OB_ARMATURE, std::string("Armature").c_str());
objects_done->push_back(par);
root_objects->push_back(par);
object_map.insert(std::pair<COLLADAFW::UniqueId, Object *>(node->getUniqueId(), par));
@@ -547,8 +543,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
// maybe join multiple <instance_...> meshes into 1, and link object with it? not sure...
// <instance_geometry>
while (geom_done < geom.getCount()) {
- ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map,
- material_texture_mapping_map);
+ ob = mesh_importer.create_mesh_object(node, geom[geom_done], false, uid_material_map);
if (ob == NULL) {
report_unknown_reference(*node, "instance_mesh");
}
@@ -588,7 +583,7 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
}
while (controller_done < controller.getCount()) {
COLLADAFW::InstanceGeometry *geometry = (COLLADAFW::InstanceGeometry *)controller[controller_done];
- ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map, material_texture_mapping_map);
+ ob = mesh_importer.create_mesh_object(node, geometry, true, uid_material_map);
if (ob == NULL) {
report_unknown_reference(*node, "instance_controller");
}
@@ -629,10 +624,10 @@ std::vector<Object *> *DocumentImporter::write_node(COLLADAFW::Node *node, COLLA
if ( (geom_done + camera_done + lamp_done + controller_done + inst_done) < 1) {
//Check if Object is armature, by checking if immediate child is a JOINT node.
if (is_armature(node)) {
- ob = bc_add_object(sce, OB_ARMATURE, name.c_str());
+ ob = bc_add_object(sce, view_layer, OB_ARMATURE, name.c_str());
}
else {
- ob = bc_add_object(sce, OB_EMPTY, NULL);
+ ob = bc_add_object(sce, view_layer, OB_EMPTY, NULL);
}
objects_done->push_back(ob);
if (parent_node == NULL) {
@@ -768,102 +763,74 @@ bool DocumentImporter::writeMaterial(const COLLADAFW::Material *cmat)
return true;
}
-// create mtex, create texture, set texture image
-MTex *DocumentImporter::create_texture(COLLADAFW::EffectCommon *ef, COLLADAFW::Texture &ctex, Material *ma,
- int i, TexIndexTextureArrayMap &texindex_texarray_map)
-{
- COLLADAFW::SamplerPointerArray& samp_array = ef->getSamplerPointerArray();
- COLLADAFW::Sampler *sampler = samp_array[ctex.getSamplerId()];
-
- const COLLADAFW::UniqueId& ima_uid = sampler->getSourceImage();
-
- if (uid_image_map.find(ima_uid) == uid_image_map.end()) {
- fprintf(stderr, "Couldn't find an image by UID.\n");
- return NULL;
- }
-
- ma->mtex[i] = BKE_texture_mtex_add();
- ma->mtex[i]->texco = TEXCO_UV;
- ma->mtex[i]->tex = BKE_texture_add(G.main, "Texture");
- ma->mtex[i]->tex->type = TEX_IMAGE;
- ma->mtex[i]->tex->ima = uid_image_map[ima_uid];
-
- texindex_texarray_map[ctex.getTextureMapId()].push_back(ma->mtex[i]);
-
- return ma->mtex[i];
-}
-
void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Material *ma)
{
COLLADAFW::EffectCommon::ShaderType shader = ef->getShaderType();
+
+ // TODO: add back texture and extended material parameter support
// blinn
if (shader == COLLADAFW::EffectCommon::SHADER_BLINN) {
+#if 0
ma->spec_shader = MA_SPEC_BLINN;
ma->spec = ef->getShininess().getFloatValue();
+#endif
}
// phong
else if (shader == COLLADAFW::EffectCommon::SHADER_PHONG) {
+#if 0
ma->spec_shader = MA_SPEC_PHONG;
ma->har = ef->getShininess().getFloatValue();
+#endif
}
// lambert
else if (shader == COLLADAFW::EffectCommon::SHADER_LAMBERT) {
+#if 0
ma->diff_shader = MA_DIFF_LAMBERT;
+#endif
}
// default - lambert
else {
+#if 0
ma->diff_shader = MA_DIFF_LAMBERT;
fprintf(stderr, "Current shader type is not supported, default to lambert.\n");
+#endif
}
// reflectivity
ma->ray_mirror = ef->getReflectivity().getFloatValue();
// index of refraction
+#if 0
ma->ang = ef->getIndexOfRefraction().getFloatValue();
+#endif
- int i = 0;
COLLADAFW::Color col;
- MTex *mtex = NULL;
- TexIndexTextureArrayMap texindex_texarray_map;
// DIFFUSE
// color
if (ef->getDiffuse().isColor()) {
- /* too high intensity can create artefacts (fireflies)
- So here we take care that intensity is set to 0.8 wherever possible
- */
col = ef->getDiffuse().getColor();
- ma->ref = max_ffff(col.getRed(), col.getGreen(), col.getBlue(), 0.8);
- ma->r = col.getRed() / ma->ref;
- ma->g = col.getGreen() / ma->ref;
- ma->b = col.getBlue() / ma->ref;
+ ma->r = col.getRed();
+ ma->g = col.getGreen();
+ ma->b = col.getBlue();
}
// texture
else if (ef->getDiffuse().isTexture()) {
+#if 0
COLLADAFW::Texture ctex = ef->getDiffuse().getTexture();
- mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
- if (mtex != NULL) {
- mtex->mapto = MAP_COL;
- ma->texact = (int)i;
- i++;
- }
+#endif
}
// AMBIENT
// color
if (ef->getAmbient().isColor()) {
+#if 0
col = ef->getAmbient().getColor();
- ma->ambr = col.getRed();
- ma->ambg = col.getGreen();
- ma->ambb = col.getBlue();
+#endif
}
// texture
else if (ef->getAmbient().isTexture()) {
+#if 0
COLLADAFW::Texture ctex = ef->getAmbient().getTexture();
- mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
- if (mtex != NULL) {
- mtex->mapto = MAP_AMB;
- i++;
- }
+#endif
}
// SPECULAR
// color
@@ -875,29 +842,22 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia
}
// texture
else if (ef->getSpecular().isTexture()) {
+#if 0
COLLADAFW::Texture ctex = ef->getSpecular().getTexture();
- mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
- if (mtex != NULL) {
- mtex->mapto = MAP_SPEC;
- i++;
- }
+#endif
}
// REFLECTIVE
// color
if (ef->getReflective().isColor()) {
+#if 0
col = ef->getReflective().getColor();
- ma->mirr = col.getRed();
- ma->mirg = col.getGreen();
- ma->mirb = col.getBlue();
+#endif
}
// texture
else if (ef->getReflective().isTexture()) {
+#if 0
COLLADAFW::Texture ctex = ef->getReflective().getTexture();
- mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
- if (mtex != NULL) {
- mtex->mapto = MAP_REF;
- i++;
- }
+#endif
}
// EMISSION
@@ -908,40 +868,31 @@ void DocumentImporter::write_profile_COMMON(COLLADAFW::EffectCommon *ef, Materia
}
// texture
else if (ef->getEmission().isTexture()) {
+#if 0
COLLADAFW::Texture ctex = ef->getEmission().getTexture();
- mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
- if (mtex != NULL) {
- mtex->mapto = MAP_EMIT;
- i++;
- }
+#endif
}
// TRANSPARENT
// color
if (ef->getOpacity().isColor()) {
+#if 0
col = ef->getTransparent().getColor();
float alpha = ef->getTransparency().getFloatValue();
if (col.isValid()) {
alpha *= col.getAlpha(); // Assuming A_ONE opaque mode
}
if (col.isValid() || alpha < 1.0) {
- ma->alpha = alpha;
- ma->mode |= MA_ZTRANSP | MA_TRANSP;
+ ...
}
+#endif
}
// texture
else if (ef->getOpacity().isTexture()) {
+#if 0
COLLADAFW::Texture ctex = ef->getOpacity().getTexture();
- mtex = create_texture(ef, ctex, ma, i, texindex_texarray_map);
- if (mtex != NULL) {
- mtex->mapto = MAP_ALPHA;
- i++;
- ma->spectra = ma->alpha = 0;
- ma->mode |= MA_ZTRANSP | MA_TRANSP;
- }
+#endif
}
-
- material_texture_mapping_map[ma] = texindex_texarray_map;
}
/** When this method is called, the writer must write the effect.
@@ -1188,7 +1139,6 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
et->setData("spotsize", &(lamp->spotsize));
lamp->spotsize = DEG2RADF(lamp->spotsize);
et->setData("spotblend", &(lamp->spotblend));
- et->setData("halo_intensity", &(lamp->haint));
et->setData("att1", &(lamp->att1));
et->setData("att2", &(lamp->att2));
et->setData("falloff_type", &(lamp->falloff_type));
@@ -1196,38 +1146,12 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
et->setData("clipend", &(lamp->clipend));
et->setData("bias", &(lamp->bias));
et->setData("soft", &(lamp->soft));
- et->setData("compressthresh", &(lamp->compressthresh));
et->setData("bufsize", &(lamp->bufsize));
- et->setData("samp", &(lamp->samp));
et->setData("buffers", &(lamp->buffers));
- et->setData("filtertype", &(lamp->filtertype));
- et->setData("bufflag", &(lamp->bufflag));
- et->setData("buftype", &(lamp->buftype));
- et->setData("ray_samp", &(lamp->ray_samp));
- et->setData("ray_sampy", &(lamp->ray_sampy));
- et->setData("ray_sampz", &(lamp->ray_sampz));
- et->setData("ray_samp_type", &(lamp->ray_samp_type));
et->setData("area_shape", &(lamp->area_shape));
et->setData("area_size", &(lamp->area_size));
et->setData("area_sizey", &(lamp->area_sizey));
et->setData("area_sizez", &(lamp->area_sizez));
- et->setData("adapt_thresh", &(lamp->adapt_thresh));
- et->setData("ray_samp_method", &(lamp->ray_samp_method));
- et->setData("shadhalostep", &(lamp->shadhalostep));
- et->setData("sun_effect_type", &(lamp->shadhalostep));
- et->setData("skyblendtype", &(lamp->skyblendtype));
- et->setData("horizon_brightness", &(lamp->horizon_brightness));
- et->setData("spread", &(lamp->spread));
- et->setData("sun_brightness", &(lamp->sun_brightness));
- et->setData("sun_size", &(lamp->sun_size));
- et->setData("backscattered_light", &(lamp->backscattered_light));
- et->setData("sun_intensity", &(lamp->sun_intensity));
- et->setData("atm_turbidity", &(lamp->atm_turbidity));
- et->setData("atm_extinction_factor", &(lamp->atm_extinction_factor));
- et->setData("atm_distance_factor", &(lamp->atm_distance_factor));
- et->setData("skyblendfac", &(lamp->skyblendfac));
- et->setData("sky_exposure", &(lamp->sky_exposure));
- et->setData("sky_colorspace", &(lamp->sky_colorspace));
}
else {
float constatt = light->getConstantAttenuation().getValue();
@@ -1291,7 +1215,6 @@ bool DocumentImporter::writeLight(const COLLADAFW::Light *light)
{
/* our sun is very strong, so pick a smaller energy level */
lamp->type = LA_SUN;
- lamp->mode |= LA_NO_SPEC;
}
break;
case COLLADAFW::Light::POINT_LIGHT:
diff --git a/source/blender/collada/DocumentImporter.h b/source/blender/collada/DocumentImporter.h
index 62f76dbc022..758caef7e60 100644
--- a/source/blender/collada/DocumentImporter.h
+++ b/source/blender/collada/DocumentImporter.h
@@ -77,7 +77,6 @@ public:
Object* create_instance_node(Object*, COLLADAFW::Node*, COLLADAFW::Node*, Scene*, bool);
void create_constraints(ExtraTags *et, Object *ob);
std::vector<Object *> *write_node(COLLADAFW::Node*, COLLADAFW::Node*, Scene*, Object*, bool);
- MTex* create_texture(COLLADAFW::EffectCommon*, COLLADAFW::Texture&, Material*, int, TexIndexTextureArrayMap&);
void write_profile_COMMON(COLLADAFW::EffectCommon*, Material*);
void translate_anim_recursive(COLLADAFW::Node*, COLLADAFW::Node*, Object*);
@@ -144,6 +143,7 @@ private:
ImportStage mImportStage;
bContext *mContext;
+ ViewLayer *view_layer;
UnitConverter unit_converter;
ArmatureImporter armature_importer;
diff --git a/source/blender/collada/EffectExporter.cpp b/source/blender/collada/EffectExporter.cpp
index a4764cab67e..dbcdfd01a9c 100644
--- a/source/blender/collada/EffectExporter.cpp
+++ b/source/blender/collada/EffectExporter.cpp
@@ -27,6 +27,7 @@
#include <map>
+#include <set>
#include "COLLADASWEffectProfile.h"
#include "COLLADAFWColorOrTexture.h"
@@ -40,24 +41,33 @@
extern "C" {
#include "DNA_mesh_types.h"
- #include "DNA_texture_types.h"
#include "DNA_world_types.h"
+ #include "BKE_collection.h"
#include "BKE_customdata.h"
#include "BKE_mesh.h"
#include "BKE_material.h"
}
-EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryEffects(sw), export_settings(export_settings) {
+// OB_MESH is assumed
+static std::string getActiveUVLayerName(Object *ob)
+{
+ Mesh *me = (Mesh *)ob->data;
+
+ int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
+ if (num_layers)
+ return std::string(bc_CustomData_get_active_layer_name(&me->fdata, CD_MTFACE));
+
+ return "";
}
+EffectsExporter::EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryEffects(sw), export_settings(export_settings) {
+}
bool EffectsExporter::hasEffects(Scene *sce)
{
- Base *base = (Base *)sce->base.first;
-
- while (base) {
- Object *ob = base->object;
+ FOREACH_SCENE_OBJECT_BEGIN(sce, ob)
+ {
int a;
for (a = 0; a < ob->totcol; a++) {
Material *ma = give_current_material(ob, a + 1);
@@ -67,69 +77,21 @@ bool EffectsExporter::hasEffects(Scene *sce)
return true;
}
- base = base->next;
}
+ FOREACH_SCENE_OBJECT_END;
return false;
}
void EffectsExporter::exportEffects(Scene *sce)
{
- this->scene = sce;
-
- if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
- if (hasEffects(sce)) {
- MaterialFunctor mf;
- openLibrary();
- mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
- closeLibrary();
- }
- }
- else {
- std::set<Object *> uv_textured_obs = bc_getUVTexturedObjects(sce, !this->export_settings->active_uv_only);
- std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
- if (uv_images.size() > 0) {
- openLibrary();
- std::set<Image *>::iterator uv_images_iter;
- for (uv_images_iter = uv_images.begin();
- uv_images_iter != uv_images.end();
- uv_images_iter++)
- {
-
- Image *ima = *uv_images_iter;
- std::string key(id_name(ima));
- key = translate_id(key);
- COLLADASW::Sampler sampler(COLLADASW::Sampler::SAMPLER_TYPE_2D,
- key + COLLADASW::Sampler::SAMPLER_SID_SUFFIX,
- key + COLLADASW::Sampler::SURFACE_SID_SUFFIX);
- sampler.setImageId(key);
-
- openEffect(key + "-effect");
- COLLADASW::EffectProfile ep(mSW);
- ep.setProfileType(COLLADASW::EffectProfile::COMMON);
- ep.setShaderType(COLLADASW::EffectProfile::PHONG);
- ep.setDiffuse(createTexture(ima, key, &sampler), false, "diffuse");
- COLLADASW::ColorOrTexture cot = getcol(0, 0, 0, 1.0f);
- ep.setSpecular(cot, false, "specular");
- ep.openProfile();
- ep.addProfileElements();
- ep.addExtraTechniques(mSW);
- ep.closeProfile();
- closeEffect();
- }
- closeLibrary();
- }
- }
-}
+ if (hasEffects(sce)) {
+ this->scene = sce;
+ openLibrary();
+ MaterialFunctor mf;
+ mf.forEachMaterialInExportSet<EffectsExporter>(sce, *this, this->export_settings->export_set);
-void EffectsExporter::writeBlinn(COLLADASW::EffectProfile &ep, Material *ma)
-{
- COLLADASW::ColorOrTexture cot;
- ep.setShaderType(COLLADASW::EffectProfile::BLINN);
- // shininess
- ep.setShininess(ma->har, false, "shininess");
- // specular
- cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
- ep.setSpecular(cot, false, "specular");
+ closeLibrary();
+ }
}
void EffectsExporter::writeLambert(COLLADASW::EffectProfile &ep, Material *ma)
@@ -138,110 +100,21 @@ void EffectsExporter::writeLambert(COLLADASW::EffectProfile &ep, Material *ma)
ep.setShaderType(COLLADASW::EffectProfile::LAMBERT);
}
-void EffectsExporter::writePhong(COLLADASW::EffectProfile &ep, Material *ma)
-{
- COLLADASW::ColorOrTexture cot;
- ep.setShaderType(COLLADASW::EffectProfile::PHONG);
- // shininess
- ep.setShininess(ma->har, false, "shininess");
- // specular
- cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
- ep.setSpecular(cot, false, "specular");
-}
-
-void EffectsExporter::writeTextures(
- COLLADASW::EffectProfile &ep,
- std::string &key,
- COLLADASW::Sampler *sampler,
- MTex *t, Image *ima,
- std::string &uvname )
-{
- // Image not set for texture
- if (!ima) return;
-
- // color
- if (t->mapto & MAP_COL) {
- ep.setDiffuse(createTexture(ima, uvname, sampler), false, "diffuse");
- }
- // ambient
- if (t->mapto & MAP_AMB) {
- ep.setAmbient(createTexture(ima, uvname, sampler), false, "ambient");
- }
- // specular
- if (t->mapto & (MAP_SPEC | MAP_COLSPEC)) {
- ep.setSpecular(createTexture(ima, uvname, sampler), false, "specular");
- }
- // emission
- if (t->mapto & MAP_EMIT) {
- ep.setEmission(createTexture(ima, uvname, sampler), false, "emission");
- }
- // reflective
- if (t->mapto & MAP_REF) {
- ep.setReflective(createTexture(ima, uvname, sampler));
- }
- // alpha
- if (t->mapto & MAP_ALPHA) {
- ep.setTransparent(createTexture(ima, uvname, sampler));
- }
- // extension:
- // Normal map --> Must be stored with <extra> tag as different technique,
- // since COLLADA doesn't support normal maps, even in current COLLADA 1.5.
- if (t->mapto & MAP_NORM) {
- COLLADASW::Texture texture(key);
- texture.setTexcoord(uvname);
- texture.setSampler(*sampler);
- // technique FCOLLADA, with the <bump> tag, is most likely the best understood,
- // most widespread de-facto standard.
- texture.setProfileName("FCOLLADA");
- texture.setChildElementName("bump");
- ep.addExtraTechniqueColorOrTexture(COLLADASW::ColorOrTexture(texture));
- }
-}
-
void EffectsExporter::operator()(Material *ma, Object *ob)
{
- // create a list of indices to textures of type TEX_IMAGE
- std::vector<int> tex_indices;
- createTextureIndices(ma, tex_indices);
+ // TODO: add back texture and extended material parameter support
openEffect(translate_id(id_name(ma)) + "-effect");
COLLADASW::EffectProfile ep(mSW);
ep.setProfileType(COLLADASW::EffectProfile::COMMON);
ep.openProfile();
- // set shader type - one of three blinn, phong or lambert
- if (ma->spec > 0.0f) {
- if (ma->spec_shader == MA_SPEC_BLINN) {
- writeBlinn(ep, ma);
- }
- else {
- // \todo figure out handling of all spec+diff shader combos blender has, for now write phong
- // for now set phong in case spec shader is not blinn
- writePhong(ep, ma);
- }
- }
- else {
- if (ma->diff_shader == MA_DIFF_LAMBERT) {
- writeLambert(ep, ma);
- }
- else {
- // \todo figure out handling of all spec+diff shader combos blender has, for now write phong
- writePhong(ep, ma);
- }
- }
+ writeLambert(ep, ma);
- // index of refraction
- if (ma->mode & MA_RAYTRANSP) {
- ep.setIndexOfRefraction(ma->ang, false, "index_of_refraction");
- }
- else {
- ep.setIndexOfRefraction(1.0f, false, "index_of_refraction");
- }
-
COLLADASW::ColorOrTexture cot;
// transparency
- if (ma->mode & MA_TRANSP) {
+ if (ma->alpha != 1.0f) {
// Tod: because we are in A_ONE mode transparency is calculated like this:
cot = getcol(1.0f, 1.0f, 1.0f, ma->alpha);
ep.setTransparent(cot);
@@ -249,34 +122,14 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
}
// emission
+#if 0
cot = getcol(ma->emit, ma->emit, ma->emit, 1.0f);
- ep.setEmission(cot, false, "emission");
+#endif
- // diffuse multiplied by diffuse intensity
- cot = getcol(ma->r * ma->ref, ma->g * ma->ref, ma->b * ma->ref, 1.0f);
+ // diffuse
+ cot = getcol(ma->r, ma->g, ma->b, 1.0f);
ep.setDiffuse(cot, false, "diffuse");
- // ambient
- /* ma->ambX is calculated only on render, so lets do it here manually and not rely on ma->ambX. */
- if (this->scene->world)
- cot = getcol(this->scene->world->ambr * ma->amb, this->scene->world->ambg * ma->amb, this->scene->world->ambb * ma->amb, 1.0f);
- else
- cot = getcol(ma->amb, ma->amb, ma->amb, 1.0f);
-
- ep.setAmbient(cot, false, "ambient");
-
- // reflective, reflectivity
- if (ma->mode & MA_RAYMIRROR) {
- cot = getcol(ma->mirr, ma->mirg, ma->mirb, 1.0f);
- ep.setReflective(cot);
- ep.setReflectivity(ma->ray_mirror);
- }
- // else {
- // cot = getcol(ma->specr, ma->specg, ma->specb, 1.0f);
- // ep.setReflective(cot);
- // ep.setReflectivity(ma->spec);
- // }
-
// specular
if (ep.getShaderType() != COLLADASW::EffectProfile::LAMBERT) {
cot = getcol(ma->specr * ma->spec, ma->specg * ma->spec, ma->specb * ma->spec, 1.0f);
@@ -285,6 +138,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
// XXX make this more readable if possible
+#if 0
// create <sampler> and <surface> for each image
COLLADASW::Sampler samplers[MAX_MTEX];
//COLLADASW::Surface surfaces[MAX_MTEX];
@@ -335,13 +189,15 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
b++;
}
}
+#endif
// used as fallback when MTex->uvname is "" (this is pretty common)
// it is indeed the correct value to use in that case
- std::string active_uv(bc_get_active_uvlayer_name(ob));
+ std::string active_uv(getActiveUVLayerName(ob));
// write textures
// XXX very slow
+#if 0
for (a = 0; a < tex_indices.size(); a++) {
MTex *t = ma->mtex[tex_indices[a]];
Image *ima = t->tex->ima;
@@ -357,6 +213,7 @@ void EffectsExporter::operator()(Material *ma, Object *ob)
COLLADASW::Sampler *sampler = (COLLADASW::Sampler *)samp_surf[i];
writeTextures(ep, key, sampler, t, ima, uvname);
}
+#endif
// performs the actual writing
ep.addProfileElements();
@@ -397,20 +254,3 @@ COLLADASW::ColorOrTexture EffectsExporter::getcol(float r, float g, float b, flo
COLLADASW::ColorOrTexture cot(color);
return cot;
}
-
-//returns the array of mtex indices which have image
-//need this for exporting textures
-void EffectsExporter::createTextureIndices(Material *ma, std::vector<int> &indices)
-{
- indices.clear();
-
- for (int a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a] &&
- ma->mtex[a]->tex &&
- ma->mtex[a]->tex->type == TEX_IMAGE &&
- ma->mtex[a]->texco == TEXCO_UV)
- {
- indices.push_back(a);
- }
- }
-}
diff --git a/source/blender/collada/EffectExporter.h b/source/blender/collada/EffectExporter.h
index 7d45a085777..eac428ae330 100644
--- a/source/blender/collada/EffectExporter.h
+++ b/source/blender/collada/EffectExporter.h
@@ -48,6 +48,7 @@ class EffectsExporter: COLLADASW::LibraryEffects
public:
EffectsExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
void exportEffects(Scene *sce);
+
void operator()(Material *ma, Object *ob);
COLLADASW::ColorOrTexture createTexture(Image *ima,
@@ -57,12 +58,7 @@ public:
COLLADASW::ColorOrTexture getcol(float r, float g, float b, float a);
private:
- /** Fills the array of mtex indices which have image. Used for exporting images. */
- void createTextureIndices(Material *ma, std::vector<int> &indices);
-
- void writeBlinn(COLLADASW::EffectProfile &ep, Material *ma);
void writeLambert(COLLADASW::EffectProfile &ep, Material *ma);
- void writePhong(COLLADASW::EffectProfile &ep, Material *ma);
void writeTextures(COLLADASW::EffectProfile &ep,
std::string &key,
COLLADASW::Sampler *sampler,
diff --git a/source/blender/collada/ExportSettings.h b/source/blender/collada/ExportSettings.h
index fa6751bef60..b6a7c1f1b4e 100644
--- a/source/blender/collada/ExportSettings.h
+++ b/source/blender/collada/ExportSettings.h
@@ -43,10 +43,6 @@ typedef enum BC_export_transformation_type {
BC_TRANSFORMATION_TYPE_TRANSROTLOC
} BC_export_transformation_type;
-typedef enum BC_export_texture_type {
- BC_TEXTURE_TYPE_MAT,
- BC_TEXTURE_TYPE_UV
-} BC_export_texture_type;
typedef struct ExportSettings {
bool apply_modifiers;
@@ -61,7 +57,7 @@ typedef struct ExportSettings {
int sampling_rate;
bool active_uv_only;
- BC_export_texture_type export_texture_type;
+ bool include_material_textures;
bool use_texture_copies;
bool triangulate;
diff --git a/source/blender/collada/GeometryExporter.cpp b/source/blender/collada/GeometryExporter.cpp
index 8406426a366..87b47353596 100644
--- a/source/blender/collada/GeometryExporter.cpp
+++ b/source/blender/collada/GeometryExporter.cpp
@@ -52,16 +52,16 @@ extern "C" {
#include "collada_internal.h"
#include "collada_utils.h"
-
// TODO: optimize UV sets by making indexed list with duplicates removed
GeometryExporter::GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings) : COLLADASW::LibraryGeometries(sw), export_settings(export_settings)
{
}
-void GeometryExporter::exportGeom(Scene *sce)
+void GeometryExporter::exportGeom(struct Depsgraph *depsgraph, Scene *sce)
{
openLibrary();
+ mDepsgraph = depsgraph;
mScene = sce;
GeometryFunctor gf;
gf.forEachMeshObjectInExportSet<GeometryExporter>(sce, *this, this->export_settings->export_set);
@@ -77,7 +77,7 @@ void GeometryExporter::operator()(Object *ob)
#endif
bool use_instantiation = this->export_settings->use_object_instantiation;
- Mesh *me = bc_get_mesh_copy( mScene,
+ Mesh *me = bc_get_mesh_copy(mDepsgraph, mScene,
ob,
this->export_settings->export_mesh_type,
this->export_settings->apply_modifiers,
@@ -135,22 +135,13 @@ void GeometryExporter::operator()(Object *ob)
// Only create Polylists if number of faces > 0
if (me->totface > 0) {
// XXX slow
- std::set<Image *> uv_images = bc_getUVImages(ob, !this->export_settings->active_uv_only);
- if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT || uv_images.size() == 0) {
- if (ob->totcol) {
- for (int a = 0; a < ob->totcol; a++) {
- createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind);
- }
- }
- else {
- int i = 0;
- createPolylist(i, has_uvs, has_color, ob, me, geom_id, norind);
+ if (ob->totcol) {
+ for (int a = 0; a < ob->totcol; a++) {
+ createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind);
}
}
else {
- bool all_uv_layers = !this->export_settings->active_uv_only;
- std::set<Image *> uv_image_set = bc_getUVImages(ob, all_uv_layers);
- createPolylists(uv_image_set, has_uvs, has_color, ob, me, geom_id, norind);
+ createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind);
}
}
@@ -230,15 +221,13 @@ void GeometryExporter::export_key_mesh(Object *ob, Mesh *me, KeyBlock *kb)
//createLooseEdgeList(ob, me, geom_id, norind);
// XXX slow
- if (ob->totcol && this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
+ if (ob->totcol) {
for (int a = 0; a < ob->totcol; a++) {
createPolylist(a, has_uvs, has_color, ob, me, geom_id, norind);
}
}
else {
- bool all_uv_layers = !this->export_settings->active_uv_only;
- std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers);
- createPolylists(uv_images, has_uvs, has_color, ob, me, geom_id, norind);
+ createPolylist(0, has_uvs, has_color, ob, me, geom_id, norind);
}
closeMesh();
@@ -307,44 +296,7 @@ std::string GeometryExporter::makeVertexColorSourceId(std::string& geom_id, char
return result;
}
-static void prepareToAppendValues(bool is_triangulated, COLLADASW::PrimitivesBase *facelist, std::vector<unsigned long> &vcount_list)
-{
- // performs the actual writing
- if (is_triangulated) {
- ((COLLADASW::Triangles *)facelist)->prepareToAppendValues();
- }
- else {
- // sets <vcount>
- facelist->setVCountList(vcount_list);
- ((COLLADASW::Polylist *)facelist)-> prepareToAppendValues();
- }
-}
-
-static void finishList(bool is_triangulated, COLLADASW::PrimitivesBase *facelist)
-{
- if (is_triangulated) {
- ((COLLADASW::Triangles *)facelist)->finish();
- }
- else {
- ((COLLADASW::Polylist *)facelist)->finish();
- }
-}
-
-COLLADASW::PrimitivesBase *getFacelist(bool is_triangulated, COLLADASW::StreamWriter *mSW)
-{
- COLLADASW::PrimitivesBase *facelist;
-
- if (is_triangulated)
- {
- facelist = new COLLADASW::Triangles(mSW);
- }
- else {
- facelist = new COLLADASW::Polylist(mSW);
- }
- return facelist;
-}
-
-// Export meshes with Materials
+// powerful because it handles both cases when there is material and when there's not
void GeometryExporter::createPolylist(short material_index,
bool has_uvs,
bool has_color,
@@ -362,7 +314,7 @@ void GeometryExporter::createPolylist(short material_index,
int i;
int faces_in_polylist = 0;
std::vector<unsigned long> vcount_list;
- bool is_triangulated = true;
+
// count faces with this material
for (i = 0; i < totpolys; i++) {
MPoly *p = &mpolys[i];
@@ -370,9 +322,6 @@ void GeometryExporter::createPolylist(short material_index,
if (p->mat_nr == material_index) {
faces_in_polylist++;
vcount_list.push_back(p->totloop);
- if (p->totloop != 3) {
- is_triangulated = false;
- }
}
}
@@ -383,21 +332,20 @@ void GeometryExporter::createPolylist(short material_index,
}
Material *ma = ob->totcol ? give_current_material(ob, material_index + 1) : NULL;
- COLLADASW::PrimitivesBase *facelist = getFacelist(is_triangulated, mSW);
-
+ COLLADASW::Polylist polylist(mSW);
// sets count attribute in <polylist>
- facelist->setCount(faces_in_polylist);
+ polylist.setCount(faces_in_polylist);
// sets material name
if (ma) {
std::string material_id = get_material_id(ma);
std::ostringstream ostr;
ostr << translate_id(material_id);
- facelist->setMaterial(ostr.str());
+ polylist.setMaterial(ostr.str());
}
-
- COLLADASW::InputList &til = facelist->getInputList();
+
+ COLLADASW::InputList &til = polylist.getInputList();
// creates <input> in <polylist> for vertices
COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0);
@@ -413,21 +361,13 @@ void GeometryExporter::createPolylist(short material_index,
int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE)-1;
for (i = 0; i < num_layers; i++) {
if (!this->export_settings->active_uv_only || i == active_uv_index) {
-
- std::string uv_name(bc_get_uvlayer_name(me, i));
- std::string effective_id = geom_id; // (uv_name == "") ? geom_id : uv_name;
- std::string layer_id = makeTexcoordSourceId(
- effective_id,
- i, this->export_settings->active_uv_only);
-
- /* Note: the third parameter denotes the offset of TEXCOORD in polylist elements
- For now this is always 2 (This may change sometime/maybe)
- */
+
+ // char *name = CustomData_get_layer_name(&me->fdata, CD_MTFACE, i);
COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
- makeUrl(layer_id),
- 2, // this is only until we have optimized UV sets
- (this->export_settings->active_uv_only) ? 0 : i // only_active_uv exported -> we have only one set
- );
+ makeUrl(makeTexcoordSourceId(geom_id, i, this->export_settings->active_uv_only)),
+ 2, // this is only until we have optimized UV sets
+ (this->export_settings->active_uv_only) ? 0 : i // only_active_uv exported -> we have only one set
+ );
til.push_back(input3);
}
}
@@ -448,10 +388,12 @@ void GeometryExporter::createPolylist(short material_index,
}
}
+ // sets <vcount>
+ polylist.setVCountList(vcount_list);
// performs the actual writing
- prepareToAppendValues(is_triangulated, facelist, vcount_list);
-
+ polylist.prepareToAppendValues();
+
// <p>
int texindex = 0;
for (i = 0; i < totpolys; i++) {
@@ -463,202 +405,20 @@ void GeometryExporter::createPolylist(short material_index,
BCPolygonNormalsIndices normal_indices = norind[i];
for (int j = 0; j < loop_count; j++) {
- facelist->appendValues(l[j].v);
- facelist->appendValues(normal_indices[j]);
- if (has_uvs)
- facelist->appendValues(texindex + j);
-
- if (has_color)
- facelist->appendValues(texindex + j);
- }
- }
-
- texindex += loop_count;
- }
-
- finishList(is_triangulated, facelist);
- delete facelist;
-}
-
-void GeometryExporter::createPolylists(std::set<Image *> uv_images,
- bool has_uvs,
- bool has_color,
- Object *ob,
- Mesh *me,
- std::string& geom_id,
- std::vector<BCPolygonNormalsIndices>& norind)
-{
- std::set<Image *>::iterator uv_images_iter;
- for (uv_images_iter = uv_images.begin();
- uv_images_iter != uv_images.end();
- uv_images_iter++)
- {
-
- Image *ima = *uv_images_iter;
- std::string imageid(id_name(ima));
- createPolylist(imageid, has_uvs,
- has_color,
- ob,
- me,
- geom_id,
- norind);
- }
-
- /* We msut add an additional collector for the case when
- * some parts of the object are not textured at all.
- * The next call creates a polylist for all untextured polygons
- */
-
- createPolylist("", has_uvs,
- has_color,
- ob,
- me,
- geom_id,
- norind);
-
-}
-
-/* ===========================================================================
- * Export Meshes with UV Textures (export as materials, see also in
- * effectExporter and MaterialExporter)
- *
- * If imageid is the empty string, then collect only untextured polygons
- * =========================================================================== */
-void GeometryExporter::createPolylist(std::string imageid,
- bool has_uvs,
- bool has_color,
- Object *ob,
- Mesh *me,
- std::string& geom_id,
- std::vector<BCPolygonNormalsIndices>& norind)
-{
-
- MPoly *mpolys = me->mpoly;
- MLoop *mloops = me->mloop;
- MTexPoly *mtpolys = me->mtpoly;
-
- int totpolys = me->totpoly;
-
- // <vcount>
- int i;
- int faces_in_polylist = 0;
- std::vector<unsigned long> vcount_list;
- bool is_triangulated = true;
- // count faces with this material
- for (i = 0; i < totpolys; i++) {
- MTexPoly *tp = &mtpolys[i];
- MPoly *p = &mpolys[i];
-
- std::string tpageid = (mtpolys && tp->tpage) ? id_name(tp->tpage) : "";
- if (tpageid == imageid) {
- faces_in_polylist++;
- vcount_list.push_back(p->totloop);
- if (p->totloop != 3) {
- is_triangulated = false;
- }
- }
- }
-
- // no faces using this imageid
- if (faces_in_polylist == 0) {
- if (imageid != "")
- fprintf(stderr, "%s: Image %s is not used.\n", id_name(ob).c_str(), imageid.c_str());
- return;
- }
-
- COLLADASW::PrimitivesBase *facelist = getFacelist(is_triangulated, mSW);
-
- // sets count attribute in <polylist>
- facelist->setCount(faces_in_polylist);
-
- if (imageid != "") {
- // sets material name
- std::string material_id = get_material_id_from_id(imageid);
- std::ostringstream ostr;
- ostr << translate_id(material_id);
- facelist->setMaterial(ostr.str());
- }
- COLLADASW::InputList &til = facelist->getInputList();
-
- // creates <input> in <polylist> for vertices
- COLLADASW::Input input1(COLLADASW::InputSemantic::VERTEX, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::VERTEX), 0);
-
- // creates <input> in <polylist> for normals
- COLLADASW::Input input2(COLLADASW::InputSemantic::NORMAL, getUrlBySemantics(geom_id, COLLADASW::InputSemantic::NORMAL), 1);
-
- til.push_back(input1);
- til.push_back(input2);
-
- // if mesh has uv coords writes <input> for TEXCOORD
- int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
- int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1;
- for (i = 0; i < num_layers; i++) {
- if (!this->export_settings->active_uv_only || i == active_uv_index) {
-
- std::string uv_name(bc_get_uvlayer_name(me, i));
- std::string effective_id = geom_id; // (uv_name == "") ? geom_id : uv_name;
- std::string layer_id = makeTexcoordSourceId(
- effective_id,
- i, this->export_settings->active_uv_only);
-
- /* Note: the third parameter denotes the offset of TEXCOORD in polylist elements
- For now this is always 2 (This may change sometime/maybe)
- */
- COLLADASW::Input input3(COLLADASW::InputSemantic::TEXCOORD,
- makeUrl(layer_id),
- 2, // this is only until we have optimized UV sets
- (this->export_settings->active_uv_only) ? 0 : i // only_active_uv exported -> we have only one set
- );
- til.push_back(input3);
- }
- }
-
- int totlayer_mcol = CustomData_number_of_layers(&me->ldata, CD_MLOOPCOL);
- if (totlayer_mcol > 0) {
- int map_index = 0;
-
- for (int a = 0; a < totlayer_mcol; a++) {
- char *layer_name = bc_CustomData_get_layer_name(&me->ldata, CD_MLOOPCOL, a);
- COLLADASW::Input input4(COLLADASW::InputSemantic::COLOR,
- makeUrl(makeVertexColorSourceId(geom_id, layer_name)),
- (has_uvs) ? 3 : 2, // all color layers have same index order
- map_index // set number equals color map index
- );
- til.push_back(input4);
- map_index++;
- }
- }
-
- // performs the actual writing
- prepareToAppendValues(is_triangulated, facelist, vcount_list);
-
- // <p>
- int texindex = 0;
- for (i = 0; i < totpolys; i++) {
- MTexPoly *tp = &mtpolys[i];
- MPoly *p = &mpolys[i];
- int loop_count = p->totloop;
- std::string tpageid = (mtpolys && tp->tpage) ? id_name(tp->tpage) : "";
- if (tpageid == imageid) {
- MLoop *l = &mloops[p->loopstart];
- BCPolygonNormalsIndices normal_indices = norind[i];
-
- for (int j = 0; j < loop_count; j++) {
- facelist->appendValues(l[j].v);
- facelist->appendValues(normal_indices[j]);
+ polylist.appendValues(l[j].v);
+ polylist.appendValues(normal_indices[j]);
if (has_uvs)
- facelist->appendValues(texindex + j);
+ polylist.appendValues(texindex + j);
if (has_color)
- facelist->appendValues(texindex + j);
+ polylist.appendValues(texindex + j);
}
}
texindex += loop_count;
}
-
- finishList(is_triangulated, facelist);
- delete facelist;
+
+ polylist.finish();
}
// creates <source> for positions
@@ -779,13 +539,7 @@ void GeometryExporter::createTexcoordsSource(std::string geom_id, Mesh *me)
MLoopUV *mloops = (MLoopUV *)CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, a);
COLLADASW::FloatSourceF source(mSW);
- std::string active_uv_name(bc_get_active_uvlayer_name(me));
- std::string effective_id = geom_id; // (active_uv_name == "") ? geom_id : active_uv_name;
- std::string layer_id = makeTexcoordSourceId(
- effective_id,
- a,
- this->export_settings->active_uv_only );
-
+ std::string layer_id = makeTexcoordSourceId(geom_id, a, this->export_settings->active_uv_only);
source.setId(layer_id);
source.setArrayId(layer_id + ARRAY_ID_SUFFIX);
diff --git a/source/blender/collada/GeometryExporter.h b/source/blender/collada/GeometryExporter.h
index 890304f4568..88420b4ad2f 100644
--- a/source/blender/collada/GeometryExporter.h
+++ b/source/blender/collada/GeometryExporter.h
@@ -46,6 +46,8 @@
#include "BKE_key.h"
+struct Depsgraph;
+
extern Object *bc_get_highest_selected_ancestor_or_self(Object *ob);
class Normal
@@ -72,12 +74,13 @@ class GeometryExporter : COLLADASW::LibraryGeometries
Normal n;
+ struct Depsgraph *mDepsgraph;
Scene *mScene;
public:
GeometryExporter(COLLADASW::StreamWriter *sw, const ExportSettings *export_settings);
- void exportGeom(Scene *sce);
+ void exportGeom(struct Depsgraph *depsgraph, Scene *sce);
void operator()(Object *ob);
@@ -85,33 +88,15 @@ public:
Mesh *me,
std::string& geom_id);
- // Create polylists for meshes with Materials
+ // powerful because it handles both cases when there is material and when there's not
void createPolylist(short material_index,
- bool has_uvs,
- bool has_color,
- Object *ob,
- Mesh *me,
- std::string& geom_id,
- std::vector<BCPolygonNormalsIndices>& norind);
-
- // Create polylists for meshes with UV Textures
- void createPolylists(std::set<Image *> uv_images,
- bool has_uvs,
- bool has_color,
- Object *ob,
- Mesh *me,
- std::string& geom_id,
- std::vector<BCPolygonNormalsIndices>& norind);
-
- // Create polylists for meshes with UV Textures
- void createPolylist(std::string imageid,
- bool has_uvs,
- bool has_color,
- Object *ob,
- Mesh *me,
- std::string& geom_id,
- std::vector<BCPolygonNormalsIndices>& norind);
-
+ bool has_uvs,
+ bool has_color,
+ Object *ob,
+ Mesh *me,
+ std::string& geom_id,
+ std::vector<BCPolygonNormalsIndices>& norind);
+
// creates <source> for positions
void createVertsSource(std::string geom_id, Mesh *me);
diff --git a/source/blender/collada/ImageExporter.cpp b/source/blender/collada/ImageExporter.cpp
index 99547551a12..657037a869a 100644
--- a/source/blender/collada/ImageExporter.cpp
+++ b/source/blender/collada/ImageExporter.cpp
@@ -55,9 +55,9 @@ ImagesExporter::ImagesExporter(COLLADASW::StreamWriter *sw, const ExportSettings
void ImagesExporter::export_UV_Image(Image *image, bool use_copies)
{
- std::string id(id_name(image));
- std::string translated_id(translate_id(id));
- bool not_yet_exported = find(mImages.begin(), mImages.end(), translated_id) == mImages.end();
+ std::string name(id_name(image));
+ std::string translated_name(translate_id(name));
+ bool not_yet_exported = find(mImages.begin(), mImages.end(), translated_name) == mImages.end();
if (not_yet_exported) {
@@ -88,7 +88,7 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies)
// make absolute destination path
- BLI_strncpy(export_file, id.c_str(), sizeof(export_file));
+ BLI_strncpy(export_file, name.c_str(), sizeof(export_file));
BKE_image_path_ensure_ext_from_imformat(export_file, &imageFormat);
BLI_join_dirfile(export_path, sizeof(export_path), export_dir, export_file);
@@ -143,60 +143,15 @@ void ImagesExporter::export_UV_Image(Image *image, bool use_copies)
}
}
- /* set name also to mNameNC. This helps other viewers import files exported from Blender better */
- COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(export_path)), translated_id, translated_id);
+ COLLADASW::Image img(COLLADABU::URI(COLLADABU::URI::nativePathToUri(export_path)), translated_name, translated_name); /* set name also to mNameNC. This helps other viewers import files exported from Blender better */
img.add(mSW);
fprintf(stdout, "Collada export: Added image: %s\n", export_file);
- mImages.push_back(translated_id);
+ mImages.push_back(translated_name);
BKE_image_release_ibuf(image, imbuf, NULL);
}
}
-void ImagesExporter::export_UV_Images()
-{
- std::set<Image *> uv_textures;
- LinkNode *node;
- bool use_texture_copies = this->export_settings->use_texture_copies;
- bool active_uv_only = this->export_settings->active_uv_only;
-
- for (node = this->export_settings->export_set; node; node = node->next) {
- Object *ob = (Object *)node->link;
- if (ob->type == OB_MESH) {
- Mesh *me = (Mesh *) ob->data;
- BKE_mesh_tessface_ensure(me);
- int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
- for (int i = 0; i < me->pdata.totlayer; i++) {
- if (me->pdata.layers[i].type == CD_MTEXPOLY) {
- if (!active_uv_only || active_uv_layer == i)
- {
- MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
- for (int j = 0; j < me->totpoly; j++, txface++) {
-
- Image *ima = txface->tpage;
- if (ima == NULL)
- continue;
-
- bool not_in_list = uv_textures.find(ima) == uv_textures.end();
- if (not_in_list) {
- uv_textures.insert(ima);
- export_UV_Image(ima, use_texture_copies);
- }
- }
- }
- }
- }
- }
- }
-}
-
-/* ============================================================
- * Check if there are any images to be exported
- * Returns true as soon as an object is detected that
- * either has an UV Texture assigned, or has a material
- * assigned that uses an Image Texture.
- * ============================================================
- */
bool ImagesExporter::hasImages(Scene *sce)
{
LinkNode *node;
@@ -209,27 +164,8 @@ bool ImagesExporter::hasImages(Scene *sce)
// no material, but check all of the slots
if (!ma) continue;
- int b;
- for (b = 0; b < MAX_MTEX; b++) {
- MTex *mtex = ma->mtex[b];
- if (mtex && mtex->tex && mtex->tex->ima) return true;
- }
-
+ // TODO: find image textures in shader nodes
}
- if (ob->type == OB_MESH) {
- Mesh *me = (Mesh *) ob->data;
- BKE_mesh_tessface_ensure(me);
- bool has_uvs = (bool)CustomData_has_layer(&me->fdata, CD_MTFACE);
- if (has_uvs) {
- int num_layers = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
- for (int a = 0; a < num_layers; a++) {
- MTFace *tface = (MTFace *)CustomData_get_layer_n(&me->fdata, CD_MTFACE, a);
- Image *img = tface->tpage;
- if (img) return true;
- }
- }
- }
-
}
return false;
}
@@ -239,12 +175,9 @@ void ImagesExporter::exportImages(Scene *sce)
openLibrary();
MaterialFunctor mf;
- if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT) {
+ if (this->export_settings->include_material_textures) {
mf.forEachMaterialInExportSet<ImagesExporter>(sce, *this, this->export_settings->export_set);
}
- else {
- export_UV_Images();
- }
closeLibrary();
}
@@ -253,13 +186,6 @@ void ImagesExporter::exportImages(Scene *sce)
void ImagesExporter::operator()(Material *ma, Object *ob)
{
- int a;
- bool use_texture_copies = this->export_settings->use_texture_copies;
- for (a = 0; a < MAX_MTEX; a++) {
- MTex *mtex = ma->mtex[a];
- if (mtex && mtex->tex && mtex->tex->ima) {
- Image *image = mtex->tex->ima;
- export_UV_Image(image, use_texture_copies);
- }
- }
+ // bool use_texture_copies = this->export_settings->use_texture_copies;
+ // TODO call export_UV_Image for every image in shader nodes
}
diff --git a/source/blender/collada/ImageExporter.h b/source/blender/collada/ImageExporter.h
index 0eaebdd5cdd..f3dd2b336e4 100644
--- a/source/blender/collada/ImageExporter.h
+++ b/source/blender/collada/ImageExporter.h
@@ -51,7 +51,6 @@ public:
private:
std::vector<std::string> mImages; // contains list of written images, to avoid duplicates
- void export_UV_Images();
void export_UV_Image(Image *image, bool use_texture_copies);
bool hasImages(Scene *sce);
const ExportSettings *export_settings;
diff --git a/source/blender/collada/InstanceWriter.cpp b/source/blender/collada/InstanceWriter.cpp
index 4d846693e50..d96d590597a 100644
--- a/source/blender/collada/InstanceWriter.cpp
+++ b/source/blender/collada/InstanceWriter.cpp
@@ -41,68 +41,34 @@ extern "C" {
#include "collada_internal.h"
#include "collada_utils.h"
-void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only, BC_export_texture_type export_texture_type)
+void InstanceWriter::add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only)
{
- bool all_uv_layers = !active_uv_only;
- COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList();
+ for (int a = 0; a < ob->totcol; a++) {
+ Material *ma = give_current_material(ob, a + 1);
+
+ COLLADASW::InstanceMaterialList& iml = bind_material.getInstanceMaterialList();
- if (export_texture_type == BC_TEXTURE_TYPE_UV)
- {
- std::set<Image *> uv_images = bc_getUVImages(ob, all_uv_layers);
- std::set<Image *>::iterator uv_images_iter;
- for (uv_images_iter = uv_images.begin();
- uv_images_iter != uv_images.end();
- uv_images_iter++)
- {
- Image *ima = *uv_images_iter;
- std::string matid(id_name(ima));
- matid = get_material_id_from_id(matid);
+ if (ma) {
+ std::string matid(get_material_id(ma));
+ matid = translate_id(matid);
std::ostringstream ostr;
ostr << matid;
COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
-
+
// create <bind_vertex_input> for each uv map
Mesh *me = (Mesh *)ob->data;
int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
-
+
int map_index = 0;
- int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1;
+ int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) -1;
for (int b = 0; b < totlayer; b++) {
if (!active_uv_only || b == active_uv_index) {
char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b);
im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++));
}
}
-
+
iml.push_back(im);
}
}
-
- else {
- for (int a = 0; a < ob->totcol; a++) {
- Material *ma = give_current_material(ob, a + 1);
- if (ma) {
- std::string matid(get_material_id(ma));
- matid = translate_id(matid);
- std::ostringstream ostr;
- ostr << matid;
- COLLADASW::InstanceMaterial im(ostr.str(), COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, matid));
-
- // create <bind_vertex_input> for each uv map
- Mesh *me = (Mesh *)ob->data;
- int totlayer = CustomData_number_of_layers(&me->fdata, CD_MTFACE);
-
- int map_index = 0;
- int active_uv_index = CustomData_get_active_layer_index(&me->fdata, CD_MTFACE) - 1;
- for (int b = 0; b < totlayer; b++) {
- if (!active_uv_only || b == active_uv_index) {
- char *name = bc_CustomData_get_layer_name(&me->fdata, CD_MTFACE, b);
- im.push_back(COLLADASW::BindVertexInput(name, "TEXCOORD", map_index++));
- }
- }
-
- iml.push_back(im);
- }
- }
- }
}
diff --git a/source/blender/collada/InstanceWriter.h b/source/blender/collada/InstanceWriter.h
index a46027325a2..49ddf091b1c 100644
--- a/source/blender/collada/InstanceWriter.h
+++ b/source/blender/collada/InstanceWriter.h
@@ -31,12 +31,11 @@
#include "COLLADASWBindMaterial.h"
#include "DNA_object_types.h"
-#include "collada.h"
class InstanceWriter
{
protected:
- void add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only, BC_export_texture_type export_texture_type);
+ void add_material_bindings(COLLADASW::BindMaterial& bind_material, Object *ob, bool active_uv_only);
};
#endif
diff --git a/source/blender/collada/LightExporter.cpp b/source/blender/collada/LightExporter.cpp
index ff50abfedae..d17941574d7 100644
--- a/source/blender/collada/LightExporter.cpp
+++ b/source/blender/collada/LightExporter.cpp
@@ -149,7 +149,6 @@ bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Lamp *la)
cla.addExtraTechniqueParameter("blender", "dist", la->dist, "blender_dist");
cla.addExtraTechniqueParameter("blender", "spotsize", RAD2DEGF(la->spotsize));
cla.addExtraTechniqueParameter("blender", "spotblend", la->spotblend);
- cla.addExtraTechniqueParameter("blender", "halo_intensity", la->haint, "blnder_halo_intensity");
cla.addExtraTechniqueParameter("blender", "att1", la->att1);
cla.addExtraTechniqueParameter("blender", "att2", la->att2);
// \todo figure out how we can have falloff curve supported here
@@ -158,38 +157,13 @@ bool LightsExporter::exportBlenderProfile(COLLADASW::Light &cla, Lamp *la)
cla.addExtraTechniqueParameter("blender", "clipend", la->clipend);
cla.addExtraTechniqueParameter("blender", "bias", la->bias);
cla.addExtraTechniqueParameter("blender", "soft", la->soft);
- cla.addExtraTechniqueParameter("blender", "compressthresh", la->compressthresh);
cla.addExtraTechniqueParameter("blender", "bufsize", la->bufsize);
cla.addExtraTechniqueParameter("blender", "samp", la->samp);
cla.addExtraTechniqueParameter("blender", "buffers", la->buffers);
- cla.addExtraTechniqueParameter("blender", "filtertype", la->filtertype);
- cla.addExtraTechniqueParameter("blender", "bufflag", la->bufflag);
- cla.addExtraTechniqueParameter("blender", "buftype", la->buftype);
- cla.addExtraTechniqueParameter("blender", "ray_samp", la->ray_samp);
- cla.addExtraTechniqueParameter("blender", "ray_sampy", la->ray_sampy);
- cla.addExtraTechniqueParameter("blender", "ray_sampz", la->ray_sampz);
- cla.addExtraTechniqueParameter("blender", "ray_samp_type", la->ray_samp_type);
cla.addExtraTechniqueParameter("blender", "area_shape", la->area_shape);
cla.addExtraTechniqueParameter("blender", "area_size", la->area_size);
cla.addExtraTechniqueParameter("blender", "area_sizey", la->area_sizey);
cla.addExtraTechniqueParameter("blender", "area_sizez", la->area_sizez);
- cla.addExtraTechniqueParameter("blender", "adapt_thresh", la->adapt_thresh);
- cla.addExtraTechniqueParameter("blender", "ray_samp_method", la->ray_samp_method);
- cla.addExtraTechniqueParameter("blender", "shadhalostep", la->shadhalostep);
- cla.addExtraTechniqueParameter("blender", "sun_effect_type", la->shadhalostep);
- cla.addExtraTechniqueParameter("blender", "skyblendtype", la->skyblendtype);
- cla.addExtraTechniqueParameter("blender", "horizon_brightness", la->horizon_brightness);
- cla.addExtraTechniqueParameter("blender", "spread", la->spread);
- cla.addExtraTechniqueParameter("blender", "sun_brightness", la->sun_brightness);
- cla.addExtraTechniqueParameter("blender", "sun_size", la->sun_size);
- cla.addExtraTechniqueParameter("blender", "backscattered_light", la->backscattered_light);
- cla.addExtraTechniqueParameter("blender", "sun_intensity", la->sun_intensity);
- cla.addExtraTechniqueParameter("blender", "atm_turbidity", la->atm_turbidity);
- cla.addExtraTechniqueParameter("blender", "atm_extinction_factor", la->atm_extinction_factor);
- cla.addExtraTechniqueParameter("blender", "atm_distance_factor", la->atm_distance_factor);
- cla.addExtraTechniqueParameter("blender", "skyblendfac", la->skyblendfac);
- cla.addExtraTechniqueParameter("blender", "sky_exposure", la->sky_exposure);
- cla.addExtraTechniqueParameter("blender", "sky_colorspace", la->sky_colorspace);
return true;
}
diff --git a/source/blender/collada/MaterialExporter.cpp b/source/blender/collada/MaterialExporter.cpp
index 0c0395f2a21..4aece997f72 100644
--- a/source/blender/collada/MaterialExporter.cpp
+++ b/source/blender/collada/MaterialExporter.cpp
@@ -38,40 +38,14 @@ MaterialsExporter::MaterialsExporter(COLLADASW::StreamWriter *sw, const ExportSe
void MaterialsExporter::exportMaterials(Scene *sce)
{
- if (this->export_settings->export_texture_type == BC_TEXTURE_TYPE_MAT)
- {
- if (hasMaterials(sce)) {
- openLibrary();
+ if (hasMaterials(sce)) {
+ openLibrary();
- MaterialFunctor mf;
- mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set);
+ MaterialFunctor mf;
+ mf.forEachMaterialInExportSet<MaterialsExporter>(sce, *this, this->export_settings->export_set);
- closeLibrary();
- }
+ closeLibrary();
}
-
- else {
- std::set<Image *> uv_images = bc_getUVImages(sce, !this->export_settings->active_uv_only);
- if (uv_images.size() > 0) {
- openLibrary();
- std::set<Image *>::iterator uv_images_iter;
- for (uv_images_iter = uv_images.begin();
- uv_images_iter != uv_images.end();
- uv_images_iter++)
- {
-
- Image *ima = *uv_images_iter;
- std::string matid(id_name(ima));
-
- openMaterial(get_material_id_from_id(matid), translate_id(matid));
- std::string efid = translate_id(matid) + "-effect";
- addInstanceEffect(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, efid));
- closeMaterial();
- }
- closeLibrary();
- }
- }
-
}
bool MaterialsExporter::hasMaterials(Scene *sce)
diff --git a/source/blender/collada/MeshImporter.cpp b/source/blender/collada/MeshImporter.cpp
index da85038bf90..4c6d00a79cb 100644
--- a/source/blender/collada/MeshImporter.cpp
+++ b/source/blender/collada/MeshImporter.cpp
@@ -207,7 +207,11 @@ void VCOLDataWrapper::get_vcol(int v_index, MLoopCol *mloopcol)
}
-MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce) : unitconverter(unitconv), scene(sce), armature_importer(arm) {
+MeshImporter::MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce, ViewLayer *view_layer):
+ unitconverter(unitconv),
+ scene(sce),
+ view_layer(view_layer),
+ armature_importer(arm) {
}
bool MeshImporter::set_poly_indices(MPoly *mpoly, MLoop *mloop, int loop_index, unsigned int *indices, int loop_count)
@@ -472,11 +476,9 @@ void MeshImporter::allocate_poly_data(COLLADAFW::Mesh *collada_mesh, Mesh *me)
COLLADAFW::MeshVertexData::InputInfos *info = collada_mesh->getUVCoords().getInputInfosArray()[i];
COLLADAFW::String &uvname = info->mName;
// Allocate space for UV_data
- CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, uvname.c_str());
CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, uvname.c_str());
}
// activate the first uv map
- me->mtpoly = (MTexPoly *)CustomData_get_layer_n(&me->pdata, CD_MTEXPOLY, 0);
me->mloopuv = (MLoopUV *) CustomData_get_layer_n(&me->ldata, CD_MLOOPUV, 0);
}
@@ -877,48 +879,6 @@ std::string *MeshImporter::get_geometry_name(const std::string &mesh_name)
return NULL;
}
-MTex *MeshImporter::assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture,
- Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map,
- MTex *color_texture)
-{
- const COLLADAFW::TextureMapId texture_index = ctexture.getTextureMapId();
- size_t setindex = ctexture.getSetIndex();
- std::string uvname = ctexture.getSemantic();
-
- if (setindex == -1) return NULL;
-
- const CustomData *data = &me->fdata;
- int layer_index = CustomData_get_layer_index(data, CD_MTFACE);
-
- if (layer_index == -1) return NULL;
-
- CustomDataLayer *cdl = &data->layers[layer_index + setindex];
-
- /* set uvname to bind_vertex_input semantic */
- BLI_strncpy(cdl->name, uvname.c_str(), sizeof(cdl->name));
-
- if (texindex_texarray_map.find(texture_index) == texindex_texarray_map.end()) {
-
- fprintf(stderr, "Cannot find texture array by texture index.\n");
- return color_texture;
- }
-
- std::vector<MTex *> textures = texindex_texarray_map[texture_index];
-
- std::vector<MTex *>::iterator it;
-
- for (it = textures.begin(); it != textures.end(); it++) {
-
- MTex *texture = *it;
-
- if (texture) {
- BLI_strncpy(texture->uvname, uvname.c_str(), sizeof(texture->uvname));
- if (texture->mapto == MAP_COL) color_texture = texture;
- }
- }
- return color_texture;
-}
-
/**
* this function checks if both objects have the same
* materials assigned to Object (in the same order)
@@ -1052,21 +1012,19 @@ void MeshImporter::optimize_material_assignements()
* which materials shall be moved to the created geometries. Also see
* optimize_material_assignements() above.
*/
-MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
- std::map<COLLADAFW::UniqueId, Material *>& uid_material_map,
- Object *ob, const COLLADAFW::UniqueId *geom_uid,
- char *layername, MTFace *texture_face,
- std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index)
+void MeshImporter::assign_material_to_geom(
+ COLLADAFW::MaterialBinding cmaterial,
+ std::map<COLLADAFW::UniqueId, Material *>& uid_material_map,
+ Object *ob, const COLLADAFW::UniqueId *geom_uid,
+ short mat_index)
{
- MTex *color_texture = NULL;
- Mesh *me = (Mesh *)ob->data;
const COLLADAFW::UniqueId& ma_uid = cmaterial.getReferencedMaterial();
// do we know this material?
if (uid_material_map.find(ma_uid) == uid_material_map.end()) {
fprintf(stderr, "Cannot find material by UID.\n");
- return NULL;
+ return;
}
// first time we get geom_uid, ma_uid pair. Save for later check.
@@ -1079,27 +1037,6 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
ob->actcol=0;
assign_material(ob, ma, mat_index + 1, BKE_MAT_ASSIGN_OBJECT);
- COLLADAFW::TextureCoordinateBindingArray& tex_array =
- cmaterial.getTextureCoordinateBindingArray();
- TexIndexTextureArrayMap texindex_texarray_map = material_texture_mapping_map[ma];
- unsigned int i;
- // loop through <bind_vertex_inputs>
- for (i = 0; i < tex_array.getCount(); i++) {
-
- color_texture = assign_textures_to_uvlayer(tex_array[i], me, texindex_texarray_map,
- color_texture);
- }
-
- // set texture face
- if (color_texture &&
- strlen((color_texture)->uvname) &&
- !STREQ(layername, color_texture->uvname))
- {
- texture_face = (MTFace *)CustomData_get_layer_named(&me->fdata, CD_MTFACE,
- color_texture->uvname);
- strcpy(layername, color_texture->uvname);
- }
-
MaterialIdPrimitiveArrayMap& mat_prim_map = geom_uid_mat_mapping_map[*geom_uid];
COLLADAFW::MaterialId mat_id = cmaterial.getMaterialId();
@@ -1114,23 +1051,16 @@ MTFace *MeshImporter::assign_material_to_geom(COLLADAFW::MaterialBinding cmateri
Primitive& prim = *it;
MPoly *mpoly = prim.mpoly;
- for (i = 0; i < prim.totpoly; i++, mpoly++) {
+ for (int i = 0; i < prim.totpoly; i++, mpoly++) {
mpoly->mat_nr = mat_index;
- // bind texture images to faces
- if (texture_face && color_texture) {
- texture_face->tpage = (Image *)color_texture->tex->ima;
- texture_face++;
- }
}
}
}
- return texture_face;
}
Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom,
bool isController,
- std::map<COLLADAFW::UniqueId, Material *>& uid_material_map,
- std::map<Material *, TexIndexTextureArrayMap>& material_texture_mapping_map)
+ std::map<COLLADAFW::UniqueId, Material *>& uid_material_map)
{
const COLLADAFW::UniqueId *geom_uid = &geom->getInstanciatedObjectId();
@@ -1160,7 +1090,7 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
const char *name = (id.length()) ? id.c_str() : NULL;
// add object
- Object *ob = bc_add_object(scene, OB_MESH, name);
+ Object *ob = bc_add_object(scene, view_layer, OB_MESH, name);
bc_set_mark(ob); // used later for material assignement optimization
@@ -1178,10 +1108,6 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
id_us_plus(&old_mesh->id); /* Because BKE_mesh_assign_object would have already decreased it... */
BKE_libblock_free_us(G.main, old_mesh);
- char layername[100];
- layername[0] = '\0';
- MTFace *texture_face = NULL;
-
COLLADAFW::MaterialBindingArray& mat_array =
geom->getMaterialBindings();
@@ -1189,9 +1115,9 @@ Object *MeshImporter::create_mesh_object(COLLADAFW::Node *node, COLLADAFW::Insta
for (unsigned int i = 0; i < mat_array.getCount(); i++) {
if (mat_array[i].getReferencedMaterial().isValid()) {
- texture_face = assign_material_to_geom(mat_array[i], uid_material_map, ob, geom_uid,
- layername, texture_face,
- material_texture_mapping_map, i);
+ assign_material_to_geom(
+ mat_array[i], uid_material_map, ob, geom_uid,
+ i);
}
else {
fprintf(stderr, "invalid referenced material for %s\n", mat_array[i].getName().c_str());
diff --git a/source/blender/collada/MeshImporter.h b/source/blender/collada/MeshImporter.h
index d6426fbaf56..09b3005d795 100644
--- a/source/blender/collada/MeshImporter.h
+++ b/source/blender/collada/MeshImporter.h
@@ -51,7 +51,6 @@ extern "C" {
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "DNA_texture_types.h"
}
@@ -92,6 +91,8 @@ private:
UnitConverter *unitconverter;
Scene *scene;
+ ViewLayer *view_layer;
+
ArmatureImporter *armature_importer;
std::map<std::string, std::string> mesh_geom_map; // needed for correct shape key naming
@@ -159,29 +160,24 @@ private:
public:
- MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce);
+ MeshImporter(UnitConverter *unitconv, ArmatureImporter *arm, Scene *sce, ViewLayer *view_layer);
virtual Object *get_object_by_geom_uid(const COLLADAFW::UniqueId& geom_uid);
virtual Mesh *get_mesh_by_geom_uid(const COLLADAFW::UniqueId& geom_uid);
- MTex *assign_textures_to_uvlayer(COLLADAFW::TextureCoordinateBinding &ctexture,
- Mesh *me, TexIndexTextureArrayMap& texindex_texarray_map,
- MTex *color_texture);
-
void optimize_material_assignements();
- MTFace *assign_material_to_geom(COLLADAFW::MaterialBinding cmaterial,
- std::map<COLLADAFW::UniqueId, Material*>& uid_material_map,
- Object *ob, const COLLADAFW::UniqueId *geom_uid,
- char *layername, MTFace *texture_face,
- std::map<Material*, TexIndexTextureArrayMap>& material_texture_mapping_map, short mat_index);
+ void assign_material_to_geom(
+ COLLADAFW::MaterialBinding cmaterial,
+ std::map<COLLADAFW::UniqueId, Material*>& uid_material_map,
+ Object *ob, const COLLADAFW::UniqueId *geom_uid,
+ short mat_index);
Object *create_mesh_object(COLLADAFW::Node *node, COLLADAFW::InstanceGeometry *geom,
bool isController,
- std::map<COLLADAFW::UniqueId, Material*>& uid_material_map,
- std::map<Material*, TexIndexTextureArrayMap>& material_texture_mapping_map);
+ std::map<COLLADAFW::UniqueId, Material*>& uid_material_map);
// create a mesh storing a pointer in a map so it can be retrieved later by geometry UID
bool write_geometry(const COLLADAFW::Geometry* geom);
diff --git a/source/blender/collada/SceneExporter.cpp b/source/blender/collada/SceneExporter.cpp
index 5a0badf8d3a..a1d542daa14 100644
--- a/source/blender/collada/SceneExporter.cpp
+++ b/source/blender/collada/SceneExporter.cpp
@@ -26,6 +26,7 @@
extern "C" {
#include "BLI_utildefines.h"
+ #include "BKE_group.h"
#include "BKE_object.h"
#include "BLI_listbase.h"
}
@@ -38,17 +39,17 @@ SceneExporter::SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm,
{
}
-void SceneExporter::exportScene(Scene *sce)
+void SceneExporter::exportScene(Depsgraph *depsgraph, Scene *sce)
{
// <library_visual_scenes> <visual_scene>
std::string id_naming = id_name(sce);
openVisualScene(translate_id(id_naming), id_naming);
- exportHierarchy(sce);
+ exportHierarchy(depsgraph, sce);
closeVisualScene();
closeLibrary();
}
-void SceneExporter::exportHierarchy(Scene *sce)
+void SceneExporter::exportHierarchy(Depsgraph *depsgraph, Scene *sce)
{
LinkNode *node;
std::vector<Object *> base_objects;
@@ -80,13 +81,13 @@ void SceneExporter::exportHierarchy(Scene *sce)
Object *ob = base_objects[index];
if (bc_is_marked(ob)) {
bc_remove_mark(ob);
- writeNodes(ob, sce);
+ writeNodes(depsgraph, ob, sce);
}
}
}
-void SceneExporter::writeNodes(Object *ob, Scene *sce)
+void SceneExporter::writeNodes(Depsgraph *depsgraph, Object *ob, Scene *sce)
{
// Add associated armature first if available
bool armature_exported = false;
@@ -95,7 +96,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
armature_exported = bc_is_in_Export_set(this->export_settings->export_set, ob_arm);
if (armature_exported && bc_is_marked(ob_arm)) {
bc_remove_mark(ob_arm);
- writeNodes(ob_arm, sce);
+ writeNodes(depsgraph, ob_arm, sce);
armature_exported = true;
}
}
@@ -146,10 +147,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
COLLADASW::InstanceGeometry instGeom(mSW);
instGeom.setUrl(COLLADASW::URI(COLLADABU::Utils::EMPTY_STRING, get_geometry_id(ob, this->export_settings->use_object_instantiation)));
instGeom.setName(translate_id(id_name(ob)));
- InstanceWriter::add_material_bindings(instGeom.getBindMaterial(),
- ob,
- this->export_settings->active_uv_only,
- this->export_settings->export_texture_type);
+ InstanceWriter::add_material_bindings(instGeom.getBindMaterial(), ob, this->export_settings->active_uv_only);
instGeom.add();
}
@@ -157,7 +155,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
// <instance_controller>
else if (ob->type == OB_ARMATURE) {
- arm_exporter->add_armature_bones(ob, sce, this, child_objects);
+ arm_exporter->add_armature_bones(depsgraph, ob, sce, this, child_objects);
}
// <instance_camera>
@@ -175,12 +173,13 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
// empty object
else if (ob->type == OB_EMPTY) { // TODO: handle groups (OB_DUPLIGROUP
if ((ob->transflag & OB_DUPLIGROUP) == OB_DUPLIGROUP && ob->dup_group) {
- GroupObject *go = NULL;
- Group *gr = ob->dup_group;
- /* printf("group detected '%s'\n", gr->id.name + 2); */
- for (go = (GroupObject *)(gr->gobject.first); go; go = go->next) {
- printf("\t%s\n", go->ob->id.name);
+ Group *group = ob->dup_group;
+ /* printf("group detected '%s'\n", group->id.name + 2); */
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ printf("\t%s\n", object->id.name);
}
+ FOREACH_GROUP_OBJECT_END;
}
}
@@ -235,7 +234,7 @@ void SceneExporter::writeNodes(Object *ob, Scene *sce)
for (std::list<Object *>::iterator i = child_objects.begin(); i != child_objects.end(); ++i) {
if (bc_is_marked(*i)) {
bc_remove_mark(*i);
- writeNodes(*i, sce);
+ writeNodes(depsgraph, *i, sce);
}
}
diff --git a/source/blender/collada/SceneExporter.h b/source/blender/collada/SceneExporter.h
index b896b9abd8d..c330aa81e91 100644
--- a/source/blender/collada/SceneExporter.h
+++ b/source/blender/collada/SceneExporter.h
@@ -96,12 +96,12 @@ class SceneExporter: COLLADASW::LibraryVisualScenes, protected TransformWriter,
{
public:
SceneExporter(COLLADASW::StreamWriter *sw, ArmatureExporter *arm, const ExportSettings *export_settings);
- void exportScene(Scene *sce);
+ void exportScene(Depsgraph *depsgraph, Scene *sce);
private:
friend class ArmatureExporter;
- void exportHierarchy(Scene *sce);
- void writeNodes(Object *ob, Scene *sce);
+ void exportHierarchy(struct Depsgraph *depsgraph, Scene *sce);
+ void writeNodes(struct Depsgraph *depsgraph, Object *ob, Scene *sce);
ArmatureExporter *arm_exporter;
const ExportSettings *export_settings;
diff --git a/source/blender/collada/SkinInfo.cpp b/source/blender/collada/SkinInfo.cpp
index c48c060dc95..a2cb8237d08 100644
--- a/source/blender/collada/SkinInfo.cpp
+++ b/source/blender/collada/SkinInfo.cpp
@@ -159,9 +159,9 @@ void SkinInfo::set_controller(const COLLADAFW::SkinController *co)
}
// called from write_controller
-Object *SkinInfo::create_armature(Scene *scene)
+Object *SkinInfo::create_armature(Scene *scene, ViewLayer *view_layer)
{
- ob_arm = bc_add_object(scene, OB_ARMATURE, NULL);
+ ob_arm = bc_add_object(scene, view_layer, OB_ARMATURE, NULL);
return ob_arm;
}
@@ -241,9 +241,9 @@ void SkinInfo::link_armature(bContext *C, Object *ob, std::map<COLLADAFW::Unique
BKE_object_workob_calc_parent(scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
- DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
#endif
copy_m4_m4(ob->obmat, bind_shape_matrix);
diff --git a/source/blender/collada/SkinInfo.h b/source/blender/collada/SkinInfo.h
index e074f59cffc..a399bff9e3c 100644
--- a/source/blender/collada/SkinInfo.h
+++ b/source/blender/collada/SkinInfo.h
@@ -99,7 +99,7 @@ public:
void set_controller(const COLLADAFW::SkinController* co);
// called from write_controller
- Object *create_armature(Scene *scene);
+ Object *create_armature(Scene *scene, ViewLayer *view_layer);
Object* set_armature(Object *ob_arm);
diff --git a/source/blender/collada/TransformWriter.cpp b/source/blender/collada/TransformWriter.cpp
index b7eeff3b074..1fb54e99147 100644
--- a/source/blender/collada/TransformWriter.cpp
+++ b/source/blender/collada/TransformWriter.cpp
@@ -26,8 +26,10 @@
*/
-#include "BKE_object.h"
#include "BLI_math.h"
+#include "BLI_sys_types.h"
+
+#include "BKE_object.h"
#include "TransformWriter.h"
@@ -61,7 +63,8 @@ void TransformWriter::add_node_transform(COLLADASW::Node& node, float mat[4][4],
}
}
-void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type)
+void TransformWriter::add_node_transform_ob(COLLADASW::Node& node, Object *ob,
+ BC_export_transformation_type transformation_type)
{
#if 0
float rot[3], loc[3], scale[3];
diff --git a/source/blender/collada/TransformWriter.h b/source/blender/collada/TransformWriter.h
index 5bb13d4aac9..580430911f7 100644
--- a/source/blender/collada/TransformWriter.h
+++ b/source/blender/collada/TransformWriter.h
@@ -41,7 +41,8 @@ class TransformWriter
protected:
void add_node_transform(COLLADASW::Node& node, float mat[4][4], float parent_mat[4][4]);
- void add_node_transform_ob(COLLADASW::Node& node, Object *ob, BC_export_transformation_type transformation_type);
+ void add_node_transform_ob(COLLADASW::Node& node, Object *ob,
+ BC_export_transformation_type transformation_type);
void add_node_transform_identity(COLLADASW::Node& node);
diff --git a/source/blender/collada/collada.cpp b/source/blender/collada/collada.cpp
index 3794b6aefac..5def6638df6 100644
--- a/source/blender/collada/collada.cpp
+++ b/source/blender/collada/collada.cpp
@@ -32,11 +32,14 @@
#include "DocumentImporter.h"
#include "ExportSettings.h"
#include "ImportSettings.h"
+#include "collada.h"
extern "C"
{
#include "BKE_scene.h"
#include "BKE_context.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
/* make dummy file */
#include "BLI_fileops.h"
@@ -48,17 +51,19 @@ int collada_import(bContext *C, ImportSettings *import_settings)
return (imp.import())? 1:0;
}
-int collada_export(EvaluationContext *eval_ctx,
+int collada_export(Depsgraph *depsgraph,
Scene *sce,
ExportSettings *export_settings)
{
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
int includeFilter = OB_REL_NONE;
if (export_settings->include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
if (export_settings->include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
eObjectSet objectSet = (export_settings->selected) ? OB_SET_SELECTED : OB_SET_ALL;
- export_settings->export_set = BKE_object_relational_superset(sce, objectSet, (eObRelationTypes)includeFilter);
+ export_settings->export_set = BKE_object_relational_superset(view_layer, objectSet, (eObRelationTypes)includeFilter);
+
int export_count = BLI_linklist_count(export_settings->export_set);
if (export_count == 0) {
@@ -74,8 +79,8 @@ int collada_export(EvaluationContext *eval_ctx,
bc_bubble_sort_by_Object_name(export_settings->export_set);
}
- DocumentExporter exporter(export_settings);
- int status = exporter.exportCurrentScene(eval_ctx, sce);
+ DocumentExporter exporter(depsgraph, export_settings);
+ int status = exporter.exportCurrentScene(sce);
BLI_linklist_free(export_settings->export_set, NULL);
diff --git a/source/blender/collada/collada.h b/source/blender/collada/collada.h
index 312f11d4ba9..5cf526af1f2 100644
--- a/source/blender/collada/collada.h
+++ b/source/blender/collada/collada.h
@@ -36,15 +36,14 @@
extern "C" {
#endif
-#include "BKE_depsgraph.h"
#include "BLI_linklist.h"
#include "BLI_path_util.h"
#include "RNA_types.h"
-
-struct EvaluationContext;
struct bContext;
+struct Depsgraph;
struct Scene;
+struct ViewLayer;
/*
* both return 1 on success, 0 on error
@@ -52,7 +51,8 @@ struct Scene;
int collada_import(struct bContext *C,
ImportSettings *import_settings);
-int collada_export(struct EvaluationContext *eval_ctx,
+
+int collada_export(struct Depsgraph *depsgraph,
struct Scene *sce,
ExportSettings *export_settings);
diff --git a/source/blender/collada/collada_internal.cpp b/source/blender/collada/collada_internal.cpp
index f2cc56777d8..cf4dcb5eb42 100644
--- a/source/blender/collada/collada_internal.cpp
+++ b/source/blender/collada/collada_internal.cpp
@@ -344,13 +344,7 @@ std::string get_camera_id(Object *ob)
std::string get_material_id(Material *mat)
{
- std::string id = id_name(mat);
- return get_material_id_from_id(id);
-}
-
-std::string get_material_id_from_id(std::string id)
-{
- return translate_id(id) + "-material";
+ return translate_id(id_name(mat)) + "-material";
}
std::string get_morph_id(Object *ob)
diff --git a/source/blender/collada/collada_internal.h b/source/blender/collada/collada_internal.h
index fc848100b79..299e13326ce 100644
--- a/source/blender/collada/collada_internal.h
+++ b/source/blender/collada/collada_internal.h
@@ -103,7 +103,6 @@ extern std::string get_joint_sid(Bone *bone);
extern std::string get_camera_id(Object *ob);
extern std::string get_material_id(Material *mat);
-extern std::string get_material_id_from_id(std::string id);
extern std::string get_morph_id(Object *ob);
diff --git a/source/blender/collada/collada_utils.cpp b/source/blender/collada/collada_utils.cpp
index 8c4ddd67d07..778ead55c8d 100644
--- a/source/blender/collada/collada_utils.cpp
+++ b/source/blender/collada/collada_utils.cpp
@@ -47,9 +47,9 @@ extern "C" {
#include "BKE_context.h"
#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
#include "BKE_object.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_mesh.h"
#include "BKE_scene.h"
#include "BKE_DerivedMesh.h"
@@ -64,6 +64,9 @@ extern "C" {
#include "bmesh_tools.h"
}
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "collada_utils.h"
#include "ExportSettings.h"
@@ -94,8 +97,9 @@ int bc_test_parent_loop(Object *par, Object *ob)
int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
{
Object workob;
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *sce = CTX_data_scene(C);
-
+
if (!par || bc_test_parent_loop(par, ob))
return false;
@@ -107,7 +111,7 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
if (is_parent_space) {
float mat[4][4];
// calc par->obmat
- BKE_object_where_is_calc(sce, par);
+ BKE_object_where_is_calc(depsgraph, sce, par);
// move child obmat into world space
mul_m4_m4m4(mat, par->obmat, ob->obmat);
@@ -118,54 +122,57 @@ int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space)
BKE_object_apply_mat4(ob, ob->obmat, 0, 0);
// compute parentinv
- BKE_object_workob_calc_parent(sce, ob, &workob);
+ BKE_object_workob_calc_parent(depsgraph, sce, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
- DAG_id_tag_update(&par->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&par->id, OB_RECALC_OB);
/** done once after import */
#if 0
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
#endif
return true;
}
-Main *bc_get_main()
+Scene *bc_get_scene(bContext *C)
{
- return G.main;
+ return CTX_data_scene(C);
}
-EvaluationContext *bc_get_evaluation_context()
+Main *bc_get_main()
{
- Main *bmain = G.main;
- return bmain->eval_ctx;
+ return G.main;
}
-void bc_update_scene(Scene *scene, float ctime)
+
+void bc_update_scene(Depsgraph *depsgraph, Scene *scene, float ctime)
{
BKE_scene_frame_set(scene, ctime);
Main *bmain = bc_get_main();
- EvaluationContext *ev_context = bc_get_evaluation_context();
- BKE_scene_update_for_newframe(ev_context, bmain, scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
}
-Object *bc_add_object(Scene *scene, int type, const char *name)
+Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name)
{
Object *ob = BKE_object_add_only_object(G.main, type, name);
ob->data = BKE_object_obdata_add_from_type(G.main, type, name);
ob->lay = scene->lay;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+
+ LayerCollection *layer_collection = BKE_layer_collection_get_active_ensure(scene, view_layer);
+ BKE_collection_object_add(&scene->id, layer_collection->scene_collection, ob);
- BKE_scene_base_select(scene, BKE_scene_base_add(scene, ob));
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+ BKE_view_layer_base_select(view_layer, base);
return ob;
}
-Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate)
+Mesh *bc_get_mesh_copy(struct Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate)
{
Mesh *tmpmesh;
CustomDataMask mask = CD_MASK_MESH;
@@ -175,12 +182,12 @@ Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh
switch (export_mesh_type) {
case BC_MESH_TYPE_VIEW:
{
- dm = mesh_create_derived_view(scene, ob, mask);
+ dm = mesh_create_derived_view(depsgraph, scene, ob, mask);
break;
}
case BC_MESH_TYPE_RENDER:
{
- dm = mesh_create_derived_render(scene, ob, mask);
+ dm = mesh_create_derived_render(depsgraph, scene, ob, mask);
break;
}
}
@@ -907,16 +914,6 @@ void bc_copy_farray_m4(float *r, float a[4][4])
}
/*
-* Returns name of Active UV Layer or empty String if no active UV Layer defined.
-* Assuming the Object is of type MESH
-*/
-std::string bc_get_active_uvlayer_name(Object *ob)
-{
- Mesh *me = (Mesh *)ob->data;
- return bc_get_active_uvlayer_name(me);
-}
-
-/*
* Returns name of Active UV Layer or empty String if no active UV Layer defined
*/
std::string bc_get_active_uvlayer_name(Mesh *me)
@@ -932,6 +929,16 @@ std::string bc_get_active_uvlayer_name(Mesh *me)
}
/*
+* Returns name of Active UV Layer or empty String if no active UV Layer defined.
+* Assuming the Object is of type MESH
+*/
+std::string bc_get_active_uvlayer_name(Object *ob)
+{
+ Mesh *me = (Mesh *)ob->data;
+ return bc_get_active_uvlayer_name(me);
+}
+
+/*
* Returns UV Layer name or empty string if layer index is out of range
*/
std::string bc_get_uvlayer_name(Mesh *me, int layer)
@@ -945,125 +952,3 @@ std::string bc_get_uvlayer_name(Mesh *me, int layer)
}
return "";
}
-
-/**********************************************************************
-*
-* Return the list of Mesh objects with assigned UVtextures and Images
-* Note: We need to create artificaial materials for each of them
-*
-***********************************************************************/
-std::set<Object *> bc_getUVTexturedObjects(Scene *sce, bool all_uv_layers)
-{
- std::set <Object *> UVObjects;
- Base *base = (Base *)sce->base.first;
-
- while (base) {
- Object *ob = base->object;
- bool has_uvimage = false;
- if (ob->type == OB_MESH) {
- Mesh *me = (Mesh *)ob->data;
- int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
-
- for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) {
- if (all_uv_layers || active_uv_layer == i)
- {
- if (me->pdata.layers[i].type == CD_MTEXPOLY) {
- MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
- MPoly *mpoly = me->mpoly;
- for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) {
-
- Image *ima = txface->tpage;
- if (ima != NULL) {
- has_uvimage = true;
- break;
- }
- }
- }
- }
- }
-
- if (has_uvimage) {
- UVObjects.insert(ob);
- }
- }
- base = base->next;
- }
- return UVObjects;
-}
-
-/**********************************************************************
-*
-* Return the list of UV Texture images from all exported Mesh Items
-* Note: We need to create one artificial material for each Image.
-*
-***********************************************************************/
-std::set<Image *> bc_getUVImages(Scene *sce, bool all_uv_layers)
-{
- std::set <Image *> UVImages;
- Base *base = (Base *)sce->base.first;
-
- while (base) {
- Object *ob = base->object;
- bool has_uvimage = false;
- if (ob->type == OB_MESH) {
- Mesh *me = (Mesh *)ob->data;
- int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
-
- for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) {
- if (all_uv_layers || active_uv_layer == i)
- {
- if (me->pdata.layers[i].type == CD_MTEXPOLY) {
- MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
- MPoly *mpoly = me->mpoly;
- for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) {
-
- Image *ima = txface->tpage;
- if (ima != NULL) {
- if (UVImages.find(ima) == UVImages.end())
- UVImages.insert(ima);
- }
- }
- }
- }
- }
- }
- base = base->next;
- }
- return UVImages;
-}
-
-/**********************************************************************
-*
-* Return the list of UV Texture images for the given Object
-* Note: We need to create one artificial material for each Image.
-*
-***********************************************************************/
-std::set<Image *> bc_getUVImages(Object *ob, bool all_uv_layers)
-{
- std::set <Image *> UVImages;
-
- bool has_uvimage = false;
- if (ob->type == OB_MESH) {
- Mesh *me = (Mesh *)ob->data;
- int active_uv_layer = CustomData_get_active_layer_index(&me->pdata, CD_MTEXPOLY);
-
- for (int i = 0; i < me->pdata.totlayer && !has_uvimage; i++) {
- if (all_uv_layers || active_uv_layer == i)
- {
- if (me->pdata.layers[i].type == CD_MTEXPOLY) {
- MTexPoly *txface = (MTexPoly *)me->pdata.layers[i].data;
- MPoly *mpoly = me->mpoly;
- for (int j = 0; j < me->totpoly; j++, mpoly++, txface++) {
-
- Image *ima = txface->tpage;
- if (ima != NULL) {
- if (UVImages.find(ima) == UVImages.end())
- UVImages.insert(ima);
- }
- }
- }
- }
- }
- }
- return UVImages;
-}
diff --git a/source/blender/collada/collada_utils.h b/source/blender/collada/collada_utils.h
index 0069b4d4871..89765375afb 100644
--- a/source/blender/collada/collada_utils.h
+++ b/source/blender/collada/collada_utils.h
@@ -34,7 +34,6 @@
#include <vector>
#include <map>
-#include <set>
#include <algorithm>
extern "C" {
@@ -61,17 +60,20 @@ extern "C" {
#include "ExportSettings.h"
#include "collada_internal.h"
+struct Depsgraph;
+
typedef std::map<COLLADAFW::TextureMapId, std::vector<MTex *> > TexIndexTextureArrayMap;
+extern Scene *bc_get_scene(bContext *C);
extern Main *bc_get_main();
-extern EvaluationContext *bc_get_evaluation_context();
-extern void bc_update_scene(Scene *scene, float ctime);
+extern Depsgraph *bc_get_depsgraph();
+extern void bc_update_scene(Depsgraph *depsgraph, Scene *scene, float ctime);
extern float bc_get_float_value(const COLLADAFW::FloatOrDoubleArray& array, unsigned int index);
extern int bc_test_parent_loop(Object *par, Object *ob);
extern int bc_set_parent(Object *ob, Object *par, bContext *C, bool is_parent_space = true);
-extern Object *bc_add_object(Scene *scene, int type, const char *name);
-extern Mesh *bc_get_mesh_copy(Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate);
+extern Object *bc_add_object(Scene *scene, ViewLayer *view_layer, int type, const char *name);
+extern Mesh *bc_get_mesh_copy(struct Depsgraph *depsgraph, Scene *scene, Object *ob, BC_export_mesh_type export_mesh_type, bool apply_modifiers, bool triangulate);
extern Object *bc_get_assigned_armature(Object *ob);
extern Object *bc_get_highest_selected_ancestor_or_self(LinkNode *export_set, Object *ob);
@@ -123,14 +125,6 @@ extern bool bc_get_property_matrix(Bone *bone, std::string key, float mat[4][4])
extern void bc_create_restpose_mat(const ExportSettings *export_settings, Bone *bone, float to_mat[4][4], float world[4][4], bool use_local_space);
-extern std::string bc_get_active_uvlayer_name(Object *ob);
-extern std::string bc_get_active_uvlayer_name(Mesh *me);
-extern std::string bc_get_uvlayer_name(Mesh *me, int layer);
-
-extern std::set<Image *> bc_getUVImages(Scene *sce, bool all_uv_layers);
-extern std::set<Image *> bc_getUVImages(Object *ob, bool all_uv_layers);
-extern std::set<Object *> bc_getUVTexturedObjects(Scene *sce, bool all_uv_layers);
-
class BCPolygonNormalsIndices
{
std::vector<unsigned int> normal_indices;
diff --git a/source/blender/compositor/CMakeLists.txt b/source/blender/compositor/CMakeLists.txt
index 3e1dd83112a..a141495e5ae 100644
--- a/source/blender/compositor/CMakeLists.txt
+++ b/source/blender/compositor/CMakeLists.txt
@@ -31,6 +31,7 @@ set(INC
../blenkernel
../blenlib
../blentranslation
+ ../depsgraph
../imbuf
../makesdna
../makesrna
diff --git a/source/blender/compositor/nodes/COM_RenderLayersNode.cpp b/source/blender/compositor/nodes/COM_RenderLayersNode.cpp
index 2286db81860..4b52c0469aa 100644
--- a/source/blender/compositor/nodes/COM_RenderLayersNode.cpp
+++ b/source/blender/compositor/nodes/COM_RenderLayersNode.cpp
@@ -65,12 +65,12 @@ void RenderLayersNode::testRenderLink(NodeConverter &converter,
missingRenderLink(converter);
return;
}
- SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&scene->r.layers, layerId);
- if (srl == NULL) {
+ ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, layerId);
+ if (view_layer == NULL) {
missingRenderLink(converter);
return;
}
- RenderLayer *rl = RE_GetRenderLayer(rr, srl->name);
+ RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
if (rl == NULL) {
missingRenderLink(converter);
return;
@@ -157,6 +157,11 @@ void RenderLayersNode::missingSocketLink(NodeConverter &converter,
operation = value_operation;
break;
}
+ default:
+ {
+ BLI_assert("!Unexpected data type");
+ return;
+ }
}
converter.mapOutputSocket(output, operation->getOutputSocket());
diff --git a/source/blender/compositor/operations/COM_RenderLayersProg.cpp b/source/blender/compositor/operations/COM_RenderLayersProg.cpp
index d1c654ddb6c..a5e2d275e4f 100644
--- a/source/blender/compositor/operations/COM_RenderLayersProg.cpp
+++ b/source/blender/compositor/operations/COM_RenderLayersProg.cpp
@@ -55,10 +55,10 @@ void RenderLayersProg::initExecution()
rr = RE_AcquireResultRead(re);
if (rr) {
- SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&scene->r.layers, getLayerId());
- if (srl) {
+ ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&scene->view_layers, getLayerId());
+ if (view_layer) {
- RenderLayer *rl = RE_GetRenderLayer(rr, srl->name);
+ RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
if (rl) {
this->m_inputBuffer = RE_RenderLayerGetPass(rl, this->m_passName.c_str(), this->m_viewName);
}
@@ -189,9 +189,9 @@ void RenderLayersProg::determineResolution(unsigned int resolution[2], unsigned
rr = RE_AcquireResultRead(re);
if (rr) {
- SceneRenderLayer *srl = (SceneRenderLayer *)BLI_findlink(&sce->r.layers, getLayerId());
- if (srl) {
- RenderLayer *rl = RE_GetRenderLayer(rr, srl->name);
+ ViewLayer *view_layer = (ViewLayer *)BLI_findlink(&sce->view_layers, getLayerId());
+ if (view_layer) {
+ RenderLayer *rl = RE_GetRenderLayer(rr, view_layer->name);
if (rl) {
resolution[0] = rl->rectx;
resolution[1] = rl->recty;
diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt
index 50c0910ef02..8f6eee244f7 100644
--- a/source/blender/depsgraph/CMakeLists.txt
+++ b/source/blender/depsgraph/CMakeLists.txt
@@ -45,16 +45,17 @@ set(SRC
intern/builder/deg_builder_map.cc
intern/builder/deg_builder_nodes.cc
intern/builder/deg_builder_nodes_rig.cc
- intern/builder/deg_builder_nodes_scene.cc
+ intern/builder/deg_builder_nodes_view_layer.cc
intern/builder/deg_builder_pchanmap.cc
intern/builder/deg_builder_relations.cc
intern/builder/deg_builder_relations_keys.cc
intern/builder/deg_builder_relations_rig.cc
- intern/builder/deg_builder_relations_scene.cc
+ intern/builder/deg_builder_relations_view_layer.cc
intern/builder/deg_builder_transitive.cc
intern/debug/deg_debug_relations_graphviz.cc
intern/debug/deg_debug_stats_gnuplot.cc
intern/eval/deg_eval.cc
+ intern/eval/deg_eval_copy_on_write.cc
intern/eval/deg_eval_flush.cc
intern/eval/deg_eval_stats.cc
intern/nodes/deg_node.cc
@@ -68,6 +69,7 @@ set(SRC
intern/depsgraph_eval.cc
intern/depsgraph_query.cc
intern/depsgraph_query_foreach.cc
+ intern/depsgraph_query_iter.cc
intern/depsgraph_tag.cc
intern/depsgraph_type_defines.cc
@@ -85,6 +87,7 @@ set(SRC
intern/builder/deg_builder_relations_impl.h
intern/builder/deg_builder_transitive.h
intern/eval/deg_eval.h
+ intern/eval/deg_eval_copy_on_write.h
intern/eval/deg_eval_flush.h
intern/eval/deg_eval_stats.h
intern/nodes/deg_node.h
@@ -122,10 +125,6 @@ else()
endif()
endif()
-if(WITH_LEGACY_DEPSGRAPH)
- add_definitions(-DWITH_LEGACY_DEPSGRAPH)
-endif()
-
if(WITH_BOOST)
list(APPEND INC_SYS
${BOOST_INCLUDE_DIR}
diff --git a/source/blender/depsgraph/DEG_depsgraph.h b/source/blender/depsgraph/DEG_depsgraph.h
index 72e90f49748..604034bb0a7 100644
--- a/source/blender/depsgraph/DEG_depsgraph.h
+++ b/source/blender/depsgraph/DEG_depsgraph.h
@@ -60,19 +60,39 @@ typedef struct Depsgraph Depsgraph;
/* ------------------------------------------------ */
-struct EvaluationContext;
struct Main;
struct PointerRNA;
struct PropertyRNA;
+struct RenderEngineType;
+struct Scene;
+struct ViewLayer;
+
+typedef enum eEvaluationMode {
+ DAG_EVAL_VIEWPORT = 0, /* evaluate for OpenGL viewport */
+ DAG_EVAL_PREVIEW = 1, /* evaluate for render with preview settings */
+ DAG_EVAL_RENDER = 2, /* evaluate for render purposes */
+} eEvaluationMode;
+
+/* DagNode->eval_flags */
+enum {
+ /* Regardless to curve->path animation flag path is to be evaluated anyway,
+ * to meet dependencies with such a things as curve modifier and other guys
+ * who're using curve deform, where_on_path and so.
+ */
+ DAG_EVAL_NEED_CURVE_PATH = 1,
+ /* Scene evaluation would need to have object's data on CPU,
+ * meaning no GPU shortcuts is allowed.
+ */
+ DAG_EVAL_NEED_CPU = 2,
+};
#ifdef __cplusplus
extern "C" {
#endif
-bool DEG_depsgraph_use_legacy(void);
-void DEG_depsgraph_switch_to_legacy(void);
-void DEG_depsgraph_switch_to_new(void);
+bool DEG_depsgraph_use_copy_on_write(void);
+void DEG_depsgraph_enable_copy_on_write(void);
/* ************************************************ */
/* Depsgraph API */
@@ -83,7 +103,9 @@ void DEG_depsgraph_switch_to_new(void);
/* Create new Depsgraph instance */
// TODO: what args are needed here? What's the building-graph entry point?
-Depsgraph *DEG_graph_new(void);
+Depsgraph *DEG_graph_new(struct Scene *scene,
+ struct ViewLayer *view_layer,
+ eEvaluationMode mode);
/* Free Depsgraph itself and all its data */
void DEG_graph_free(Depsgraph *graph);
@@ -98,92 +120,92 @@ void DEG_free_node_types(void);
/* Update Tagging -------------------------------- */
-/* Tag node(s) associated with states such as time and visibility */
-void DEG_scene_update_flags(Depsgraph *graph, const bool do_time);
-
/* Update dependency graph when visible scenes/layers changes. */
-void DEG_graph_on_visible_update(struct Main *bmain, struct Scene *scene);
+void DEG_graph_on_visible_update(struct Main *bmain, Depsgraph *depsgraph);
/* Update all dependency graphs when visible scenes/layers changes. */
void DEG_on_visible_update(struct Main *bmain, const bool do_time);
-/* Tag node(s) associated with changed data for later updates */
-void DEG_graph_id_tag_update(struct Main *bmain,
- Depsgraph *graph,
- struct ID *id);
-
/* Tag given ID for an update in all the dependency graphs. */
-void DEG_id_tag_update(struct ID *id, short flag);
-void DEG_id_tag_update_ex(struct Main *bmain,
- struct ID *id,
- short flag);
+typedef enum eDepsgraph_Tag {
+ /* Object transformation changed, corresponds to OB_RECALC_OB. */
+ DEG_TAG_TRANSFORM = (1 << 0),
+ /* Object geometry changed, corresponds to OB_RECALC_DATA. */
+ DEG_TAG_GEOMETRY = (1 << 1),
+ /* Time changed and animation is to be re-evaluated, OB_RECALC_TIME. */
+ DEG_TAG_TIME = (1 << 2),
+ /* Particle system changed. */
+ DEG_TAG_PSYS_REDO = (1 << 3),
+ DEG_TAG_PSYS_RESET = (1 << 4),
+ DEG_TAG_PSYS_TYPE = (1 << 5),
+ DEG_TAG_PSYS_CHILD = (1 << 6),
+ DEG_TAG_PSYS_PHYS = (1 << 7),
+ DEG_TAG_PSYS_ALL = (DEG_TAG_PSYS_REDO |
+ DEG_TAG_PSYS_RESET |
+ DEG_TAG_PSYS_TYPE |
+ DEG_TAG_PSYS_CHILD |
+ DEG_TAG_PSYS_PHYS),
+ /* Update copy on write component without flushing down the road. */
+ DEG_TAG_COPY_ON_WRITE = (1 << 8),
+ /* Tag shading components for update.
+ * Only parameters of material changed).
+ */
+ DEG_TAG_SHADING_UPDATE = (1 << 9),
+ DEG_TAG_SELECT_UPDATE = (1 << 10),
+ DEG_TAG_BASE_FLAGS_UPDATE = (1 << 11),
+ /* Only inform editors about the change. Don't modify datablock itself. */
+ DEG_TAG_EDITORS_UPDATE = (1 << 12),
+} eDepsgraph_Tag;
+
+const char *DEG_update_tag_as_string(eDepsgraph_Tag flag);
+
+void DEG_id_tag_update(struct ID *id, int flag);
+void DEG_id_tag_update_ex(struct Main *bmain, struct ID *id, int flag);
+
+void DEG_graph_id_tag_update(struct Main *bmain,
+ struct Depsgraph *depsgraph,
+ struct ID *id,
+ int flag);
/* Mark a particular datablock type as having changing. This does
* not cause any updates but is used by external render engines to detect if for
* example a datablock was removed.
*/
-void DEG_id_type_tag(struct Main *bmain, short idtype);
+void DEG_id_type_tag(struct Main *bmain, short id_type);
void DEG_ids_clear_recalc(struct Main *bmain);
/* Update Flushing ------------------------------- */
-/* Flush updates for all IDs */
-void DEG_ids_flush_tagged(struct Main *bmain);
-
/* Flush updates for IDs in a single scene. */
-void DEG_scene_flush_update(struct Main *bmain, struct Scene *scene);
+void DEG_graph_flush_update(struct Main *bmain, Depsgraph *depsgraph);
/* Check if something was changed in the database and inform
* editors about this.
*/
void DEG_ids_check_recalc(struct Main *bmain,
+ struct Depsgraph *depsgraph,
struct Scene *scene,
+ struct ViewLayer *view_layer,
bool time);
/* ************************************************ */
/* Evaluation Engine API */
-/* Evaluation Context ---------------------------- */
-
-/* Create new evaluation context. */
-struct EvaluationContext *DEG_evaluation_context_new(int mode);
-
-/* Initialize evaluation context.
- * Used by the areas which currently overrides the context or doesn't have
- * access to a proper one.
- */
-void DEG_evaluation_context_init(struct EvaluationContext *eval_ctx, int mode);
-
-/* Free evaluation context. */
-void DEG_evaluation_context_free(struct EvaluationContext *eval_ctx);
-
/* Graph Evaluation ----------------------------- */
/* Frame changed recalculation entry point
* < context_type: context to perform evaluation for
* < ctime: (frame) new frame to evaluate values on
*/
-void DEG_evaluate_on_framechange(struct EvaluationContext *eval_ctx,
- struct Main *bmain,
+void DEG_evaluate_on_framechange(struct Main *bmain,
Depsgraph *graph,
- float ctime,
- const unsigned int layer);
+ float ctime);
/* Data changed recalculation entry point.
* < context_type: context to perform evaluation for
- * < layers: visible layers bitmask to update the graph for
*/
-void DEG_evaluate_on_refresh_ex(struct EvaluationContext *eval_ctx,
- Depsgraph *graph,
- const unsigned int layers);
-
-/* Data changed recalculation entry point.
- * < context_type: context to perform evaluation for
- */
-void DEG_evaluate_on_refresh(struct EvaluationContext *eval_ctx,
- Depsgraph *graph,
- struct Scene *scene);
+void DEG_evaluate_on_refresh(Depsgraph *graph);
bool DEG_needs_eval(Depsgraph *graph);
@@ -193,35 +215,42 @@ bool DEG_needs_eval(Depsgraph *graph);
* to do their own updates based on changes.
*/
-typedef void (*DEG_EditorUpdateIDCb)(struct Main *bmain, struct ID *id);
-typedef void (*DEG_EditorUpdateSceneCb)(struct Main *bmain,
- struct Scene *scene,
- int updated);
-typedef void (*DEG_EditorUpdateScenePreCb)(struct Main *bmain,
- struct Scene *scene,
- bool time);
+typedef struct DEGEditorUpdateContext {
+ struct Main *bmain;
+ struct Depsgraph *depsgraph;
+ struct Scene *scene;
+ struct ViewLayer *view_layer;
+} DEGEditorUpdateContext;
+
+typedef void (*DEG_EditorUpdateIDCb)(
+ const DEGEditorUpdateContext *update_ctx,
+ struct ID *id);
+typedef void (*DEG_EditorUpdateSceneCb)(
+ const DEGEditorUpdateContext *update_ctx, int updated);
/* Set callbacks which are being called when depsgraph changes. */
void DEG_editors_set_update_cb(DEG_EditorUpdateIDCb id_func,
- DEG_EditorUpdateSceneCb scene_func,
- DEG_EditorUpdateScenePreCb scene_pre_func);
-
-void DEG_editors_update_pre(struct Main *bmain, struct Scene *scene, bool time);
+ DEG_EditorUpdateSceneCb scene_func);
/* Evaluation Debug ------------------------------ */
-void DEG_debug_print_eval(const char* function_name,
+void DEG_debug_print_begin(struct Depsgraph *depsgraph);
+
+void DEG_debug_print_eval(struct Depsgraph *depsgraph,
+ const char* function_name,
const char* object_name,
const void* object_address);
-void DEG_debug_print_eval_subdata(const char *function_name,
+void DEG_debug_print_eval_subdata(struct Depsgraph *depsgraph,
+ const char *function_name,
const char *object_name,
const void *object_address,
const char *subdata_comment,
const char *subdata_name,
const void *subdata_address);
-void DEG_debug_print_eval_subdata_index(const char *function_name,
+void DEG_debug_print_eval_subdata_index(struct Depsgraph *depsgraph,
+ const char *function_name,
const char *object_name,
const void *object_address,
const char *subdata_comment,
@@ -229,7 +258,18 @@ void DEG_debug_print_eval_subdata_index(const char *function_name,
const void *subdata_address,
const int subdata_index);
-void DEG_debug_print_eval_time(const char* function_name,
+void DEG_debug_print_eval_parent_typed(struct Depsgraph *depsgraph,
+ const char *function_name,
+ const char *object_name,
+ const void *object_address,
+ const char *object_type,
+ const char *parent_comment,
+ const char *parent_name,
+ const void *parent_address,
+ const char *parent_type);
+
+void DEG_debug_print_eval_time(struct Depsgraph *depsgraph,
+ const char* function_name,
const char* object_name,
const void* object_address,
float time);
diff --git a/source/blender/depsgraph/DEG_depsgraph_build.h b/source/blender/depsgraph/DEG_depsgraph_build.h
index b268822f659..3460cbf7c91 100644
--- a/source/blender/depsgraph/DEG_depsgraph_build.h
+++ b/source/blender/depsgraph/DEG_depsgraph_build.h
@@ -40,12 +40,14 @@ struct Depsgraph;
/* ------------------------------------------------ */
-struct Main;
-struct Scene;
-struct Group;
+struct CacheFile;
struct EffectorWeights;
+struct Group;
+struct Main;
struct ModifierData;
struct Object;
+struct Scene;
+struct ViewLayer;
#ifdef __cplusplus
extern "C" {
@@ -56,28 +58,23 @@ extern "C" {
/* Build depsgraph for the given scene, and dump results in given
* graph container.
*/
-void DEG_graph_build_from_scene(struct Depsgraph *graph,
- struct Main *bmain,
- struct Scene *scene);
+void DEG_graph_build_from_view_layer(struct Depsgraph *graph,
+ struct Main *bmain,
+ struct Scene *scene,
+ struct ViewLayer *view_layer);
/* Tag relations from the given graph for update. */
void DEG_graph_tag_relations_update(struct Depsgraph *graph);
+/* Create or update relations in the specified graph. */
+void DEG_graph_relations_update(struct Depsgraph *graph,
+ struct Main *bmain,
+ struct Scene *scene,
+ struct ViewLayer *view_layer);
+
/* Tag all relations in the database for update.*/
void DEG_relations_tag_update(struct Main *bmain);
-/* Create new graph if didn't exist yet,
- * or update relations if graph was tagged for update.
- */
-void DEG_scene_relations_update(struct Main *bmain, struct Scene *scene);
-
-/* Rebuild dependency graph only for a given scene. */
-void DEG_scene_relations_rebuild(struct Main *bmain,
- struct Scene *scene);
-
-/* Delete scene graph. */
-void DEG_scene_graph_free(struct Scene *scene);
-
/* Add Dependencies ----------------------------- */
/* Handle for components to define their dependencies from callbacks.
@@ -87,9 +84,6 @@ void DEG_scene_graph_free(struct Scene *scene);
*/
struct DepsNodeHandle;
-struct CacheFile;
-struct Object;
-
typedef enum eDepsSceneComponentType {
/* Parameters Component - Default when nothing else fits
* (i.e. just SDNA property setting).
@@ -166,7 +160,6 @@ void DEG_add_collision_relations(struct DepsNodeHandle *handle,
struct Scene *scene,
struct Object *object,
struct Group *group,
- int layer,
unsigned int modifier_type,
DEG_CollobjFilterFunction fn,
bool dupli,
diff --git a/source/blender/depsgraph/DEG_depsgraph_debug.h b/source/blender/depsgraph/DEG_depsgraph_debug.h
index bc93fcc94cb..7c0f9ef3121 100644
--- a/source/blender/depsgraph/DEG_depsgraph_debug.h
+++ b/source/blender/depsgraph/DEG_depsgraph_debug.h
@@ -40,6 +40,18 @@ extern "C" {
#endif
struct Depsgraph;
+struct Scene;
+struct ViewLayer;
+
+/* ------------------------------------------------ */
+
+/* NOTE: Those flags are same bitmask as G.debug_flags */
+
+void DEG_debug_flags_set(struct Depsgraph *depsgraph, int flags);
+int DEG_debug_flags_get(const struct Depsgraph *depsgraph);
+
+void DEG_debug_name_set(struct Depsgraph *depsgraph, const char *name);
+const char *DEG_debug_name_get(struct Depsgraph *depsgraph);
/* ------------------------------------------------ */
@@ -67,9 +79,10 @@ bool DEG_debug_compare(const struct Depsgraph *graph1,
const struct Depsgraph *graph2);
/* Check that dependnecies in the graph are really up to date. */
-bool DEG_debug_scene_relations_validate(struct Main *bmain,
- struct Scene *scene);
-
+bool DEG_debug_graph_relations_validate(struct Depsgraph *graph,
+ struct Main *bmain,
+ struct Scene *scene,
+ struct ViewLayer *view_layer);
/* Perform consistency check on the graph. */
bool DEG_debug_consistency_check(struct Depsgraph *graph);
diff --git a/source/blender/depsgraph/DEG_depsgraph_query.h b/source/blender/depsgraph/DEG_depsgraph_query.h
index f8cfb407831..6d21c143877 100644
--- a/source/blender/depsgraph/DEG_depsgraph_query.h
+++ b/source/blender/depsgraph/DEG_depsgraph_query.h
@@ -33,19 +33,149 @@
#ifndef __DEG_DEPSGRAPH_QUERY_H__
#define __DEG_DEPSGRAPH_QUERY_H__
+#include "DEG_depsgraph.h"
+
struct ID;
+struct Base;
+struct BLI_Iterator;
struct Depsgraph;
+struct DupliObject;
+struct ListBase;
+struct Scene;
+struct ViewLayer;
#ifdef __cplusplus
extern "C" {
#endif
+/* *********************** DEG input data ********************* */
+
+/* Get scene that depsgraph was built for. */
+struct Scene *DEG_get_input_scene(const Depsgraph *graph);
+
+/* Get view layer that depsgraph was built for. */
+struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph);
+
+/* Get evaluation mode that depsgraph was built for. */
+eEvaluationMode DEG_get_mode(const Depsgraph *graph);
+
+/* Get time that depsgraph is being evaluated or was last evaluated at. */
+float DEG_get_ctime(const Depsgraph *graph);
+
+/* ********************* DEG evaluated data ******************* */
+
/* Check if given ID type was tagged for update. */
-bool DEG_id_type_tagged(struct Main *bmain, short idtype);
+bool DEG_id_type_tagged(struct Main *bmain, short id_type);
/* Get additional evaluation flags for the given ID. */
-short DEG_get_eval_flags_for_id(struct Depsgraph *graph, struct ID *id);
+short DEG_get_eval_flags_for_id(const struct Depsgraph *graph, struct ID *id);
+
+/* Get scene the despgraph is created for. */
+struct Scene *DEG_get_evaluated_scene(const struct Depsgraph *graph);
+
+/* Get scene layer the despgraph is created for. */
+struct ViewLayer *DEG_get_evaluated_view_layer(const struct Depsgraph *graph);
+
+/* Get evaluated version of object for given original one. */
+struct Object *DEG_get_evaluated_object(const struct Depsgraph *depsgraph,
+ struct Object *object);
+
+/* Get evaluated version of given ID datablock. */
+struct ID *DEG_get_evaluated_id(const struct Depsgraph *depsgraph,
+ struct ID *id);
+
+
+/* Get original version of object for given evaluated one. */
+struct Object *DEG_get_original_object(struct Object *object);
+
+/* Get original version of given evaluated ID datablock. */
+struct ID *DEG_get_original_id(struct ID *id);
+
+/* ************************ DEG iterators ********************* */
+
+enum {
+ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY = (1 << 0),
+ DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY = (1 << 1),
+ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET = (1 << 2),
+ DEG_ITER_OBJECT_FLAG_VISIBLE = (1 << 3),
+ DEG_ITER_OBJECT_FLAG_DUPLI = (1 << 4),
+};
+
+typedef enum eDepsObjectIteratorMode {
+ DEG_ITER_OBJECT_MODE_VIEWPORT = 0,
+ DEG_ITER_OBJECT_MODE_RENDER = 1,
+} eDepsObjectIteratorMode;
+
+typedef struct DEGObjectIterData {
+ struct Depsgraph *graph;
+ eDepsObjectIteratorMode mode;
+ int flag;
+
+ struct Scene *scene;
+
+ int visibility_check; /* eObjectVisibilityCheck. */
+
+ /* **** Iteration over dupli-list. *** */
+
+ /* Object which created the dupli-list. */
+ struct Object *dupli_parent;
+ /* List of duplicated objects. */
+ struct ListBase *dupli_list;
+ /* Next duplicated object to step into. */
+ struct DupliObject *dupli_object_next;
+ /* Corresponds to current object: current iterator object is evaluated from
+ * this duplicated object.
+ */
+ struct DupliObject *dupli_object_current;
+ /* Temporary storage to report fully populated DNA to the render engine or
+ * other users of the iterator.
+ */
+ struct Object temp_dupli_object;
+
+ /* **** Iteration ober ID nodes **** */
+ size_t id_node_index;
+ size_t num_id_nodes;
+} DEGObjectIterData;
+
+void DEG_iterator_objects_begin(struct BLI_Iterator *iter, DEGObjectIterData *data);
+void DEG_iterator_objects_next(struct BLI_Iterator *iter);
+void DEG_iterator_objects_end(struct BLI_Iterator *iter);
+
+/**
+ * Note: Be careful with DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY objects.
+ * Although they are available they have no overrides (collection_properties)
+ * and will crash if you try to access it.
+ */
+#define DEG_OBJECT_ITER_BEGIN(graph_, instance_, mode_, flag_) \
+ { \
+ DEGObjectIterData data_ = { \
+ graph_, \
+ mode_, \
+ flag_ \
+ }; \
+ \
+ ITER_BEGIN(DEG_iterator_objects_begin, \
+ DEG_iterator_objects_next, \
+ DEG_iterator_objects_end, \
+ &data_, Object *, instance_)
+
+#define DEG_OBJECT_ITER_END \
+ ITER_END; \
+ }
+
+/**
+ * Depsgraph objects iterator for draw manager and final render
+ */
+#define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(graph_, instance_, mode_) \
+ DEG_OBJECT_ITER_BEGIN(graph_, instance_, mode_, \
+ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY | \
+ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET | \
+ DEG_ITER_OBJECT_FLAG_VISIBLE | \
+ DEG_ITER_OBJECT_FLAG_DUPLI)
+
+#define DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END \
+ DEG_OBJECT_ITER_END
/* ************************ DEG traversal ********************* */
@@ -58,6 +188,9 @@ void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
const ID *id,
DEGForeachIDCallback callback, void *user_data);
+void DEG_foreach_ID(const Depsgraph *depsgraph,
+ DEGForeachIDCallback callback, void *user_data);
+
#ifdef __cplusplus
} /* extern "C" */
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.cc b/source/blender/depsgraph/intern/builder/deg_builder.cc
index 5713297d658..2fcad233044 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder.cc
@@ -30,142 +30,38 @@
#include "intern/builder/deg_builder.h"
-#include "DNA_anim_types.h"
#include "DNA_object_types.h"
#include "DNA_ID.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BLI_stack.h"
-
#include "intern/depsgraph.h"
#include "intern/depsgraph_types.h"
#include "intern/nodes/deg_node.h"
-#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_id.h"
-#include "intern/nodes/deg_node_operation.h"
#include "util/deg_util_foreach.h"
-#include <cstdio>
+#include "DEG_depsgraph.h"
namespace DEG {
-static bool check_object_needs_evaluation(Object *object)
+void deg_graph_build_finalize(Main *bmain, Depsgraph *graph)
{
- if (object->recalc & OB_RECALC_ALL) {
- /* Object is tagged for update anyway, no need to re-tag it. */
- return false;
- }
- if (object->type == OB_MESH) {
- return object->derivedFinal == NULL;
- }
- else if (ELEM(object->type,
- OB_CURVE, OB_SURF, OB_FONT, OB_MBALL, OB_LATTICE))
- {
- return object->curve_cache == NULL;
- }
- return false;
-}
-
-void deg_graph_build_flush_layers(Depsgraph *graph)
-{
- BLI_Stack *stack = BLI_stack_new(sizeof(OperationDepsNode *),
- "DEG flush layers stack");
- foreach (OperationDepsNode *node, graph->operations) {
- IDDepsNode *id_node = node->owner->owner;
- node->done = 0;
- node->num_links_pending = 0;
- foreach (DepsRelation *rel, node->outlinks) {
- if ((rel->from->type == DEG_NODE_TYPE_OPERATION) &&
- (rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
- {
- ++node->num_links_pending;
- }
- }
- if (node->num_links_pending == 0) {
- BLI_stack_push(stack, &node);
- node->done = 1;
- }
- node->owner->layers = id_node->layers;
- id_node->id->tag |= LIB_TAG_DOIT;
- }
- while (!BLI_stack_is_empty(stack)) {
- OperationDepsNode *node;
- BLI_stack_pop(stack, &node);
- /* Flush layers to parents. */
- foreach (DepsRelation *rel, node->inlinks) {
- if (rel->from->type == DEG_NODE_TYPE_OPERATION) {
- OperationDepsNode *from = (OperationDepsNode *)rel->from;
- from->owner->layers |= node->owner->layers;
- }
- }
- /* Schedule parent nodes. */
- foreach (DepsRelation *rel, node->inlinks) {
- if (rel->from->type == DEG_NODE_TYPE_OPERATION) {
- OperationDepsNode *from = (OperationDepsNode *)rel->from;
- if ((rel->flag & DEPSREL_FLAG_CYCLIC) == 0) {
- BLI_assert(from->num_links_pending > 0);
- --from->num_links_pending;
- }
- if (from->num_links_pending == 0 && from->done == 0) {
- BLI_stack_push(stack, &from);
- from->done = 1;
- }
- }
- }
- }
- BLI_stack_free(stack);
-}
-
-void deg_graph_build_finalize(Depsgraph *graph)
-{
- /* STEP 1: Make sure new invisible dependencies are ready for use.
- *
- * TODO(sergey): This might do a bit of extra tagging, but it's kinda nice
- * to do it ahead of a time and don't spend time on flushing updates on
- * every frame change.
- */
- foreach (IDDepsNode *id_node, graph->id_nodes) {
- if (id_node->layers == 0) {
- ID *id = id_node->id;
- if (GS(id->name) == ID_OB) {
- Object *object = (Object *)id;
- if (check_object_needs_evaluation(object)) {
- id_node->tag_update(graph);
- }
- }
- }
- }
- /* STEP 2: Flush visibility layers from children to parent. */
- deg_graph_build_flush_layers(graph);
- /* STEP 3: Re-tag IDs for update if it was tagged before the relations
+ const bool use_copy_on_write = DEG_depsgraph_use_copy_on_write();
+ /* Re-tag IDs for update if it was tagged before the relations
* update tag.
*/
foreach (IDDepsNode *id_node, graph->id_nodes) {
- GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp, id_node->components)
- {
- id_node->layers |= comp->layers;
+ ID *id = id_node->id_orig;
+ id_node->finalize_build(graph);
+ if ((id->recalc & ID_RECALC_ALL)) {
+ id_node->tag_update(graph);
}
- GHASH_FOREACH_END();
-
- if ((id_node->layers & graph->layers) != 0 || graph->layers == 0) {
- ID *id = id_node->id;
- if ((id->recalc & ID_RECALC_ALL) &&
- (id->tag & LIB_TAG_DOIT))
- {
- id_node->tag_update(graph);
- id->tag &= ~LIB_TAG_DOIT;
- }
- else if (GS(id->name) == ID_OB) {
- Object *object = (Object *)id;
- if (object->recalc & OB_RECALC_ALL) {
- id_node->tag_update(graph);
- id->tag &= ~LIB_TAG_DOIT;
- }
- }
+ /* TODO(sergey): This is not ideal at all, since this forces
+ * re-evaluaiton of the whole tree.
+ */
+ if (use_copy_on_write) {
+ DEG_id_tag_update_ex(bmain, id_node->id_orig, DEG_TAG_COPY_ON_WRITE);
}
- id_node->finalize_build();
}
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder.h b/source/blender/depsgraph/intern/builder/deg_builder.h
index b8ea8c8e599..c7ff668504c 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder.h
@@ -30,15 +30,12 @@
#pragma once
-#include "intern/depsgraph_types.h"
-
-struct FCurve;
+struct Main;
namespace DEG {
struct Depsgraph;
-void deg_graph_build_finalize(struct Depsgraph *graph);
-void deg_graph_build_flush_layers(struct Depsgraph *graph);
+void deg_graph_build_finalize(struct Main *bmain, struct Depsgraph *graph);
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
index 3a4ca7515a3..0545dd33a29 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.cc
@@ -62,6 +62,7 @@ extern "C" {
#include "DNA_node_types.h"
#include "DNA_particle_types.h"
#include "DNA_object_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
#include "DNA_texture_types.h"
@@ -72,7 +73,6 @@ extern "C" {
#include "BKE_animsys.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_effect.h"
#include "BKE_fcurve.h"
#include "BKE_idcode.h"
@@ -90,6 +90,7 @@ extern "C" {
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_particle.h"
+#include "BKE_pointcache.h"
#include "BKE_rigidbody.h"
#include "BKE_sound.h"
#include "BKE_tracking.h"
@@ -103,6 +104,7 @@ extern "C" {
#include "DEG_depsgraph_build.h"
#include "intern/builder/deg_builder.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_id.h"
@@ -114,6 +116,17 @@ extern "C" {
namespace DEG {
+namespace {
+
+void free_copy_on_write_datablock(void *id_v)
+{
+ ID *id = (ID *)id_v;
+ deg_free_copy_on_write_datablock(id);
+ MEM_freeN(id);
+}
+
+} /* namespace */
+
/* ************ */
/* Node Builder */
@@ -122,17 +135,52 @@ namespace DEG {
DepsgraphNodeBuilder::DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph)
: bmain_(bmain),
graph_(graph),
- scene_(NULL)
+ scene_(NULL),
+ view_layer_(NULL),
+ cow_id_hash_(NULL)
{
}
DepsgraphNodeBuilder::~DepsgraphNodeBuilder()
{
+ if (cow_id_hash_ != NULL) {
+ BLI_ghash_free(cow_id_hash_, NULL, free_copy_on_write_datablock);
+ }
}
IDDepsNode *DepsgraphNodeBuilder::add_id_node(ID *id)
{
- return graph_->add_id_node(id, id->name);
+ if (!DEG_depsgraph_use_copy_on_write()) {
+ return graph_->add_id_node(id);
+ }
+ IDDepsNode *id_node = NULL;
+ ID *id_cow = (ID *)BLI_ghash_lookup(cow_id_hash_, id);
+ if (id_cow != NULL) {
+ /* TODO(sergey): Is it possible to lookup and pop element from GHash
+ * at the same time?
+ */
+ BLI_ghash_remove(cow_id_hash_, id, NULL, NULL);
+ }
+ id_node = graph_->add_id_node(id, id_cow);
+ /* Currently all ID nodes are supposed to have copy-on-write logic.
+ *
+ * NOTE: Zero number of components indicates that ID node was just created.
+ */
+ if (BLI_ghash_len(id_node->components) == 0) {
+ ComponentDepsNode *comp_cow =
+ id_node->add_component(DEG_NODE_TYPE_COPY_ON_WRITE);
+ OperationDepsNode *op_cow = comp_cow->add_operation(
+ function_bind(deg_evaluate_copy_on_write, _1, id_node),
+ DEG_OPCODE_COPY_ON_WRITE,
+ "", -1);
+ graph_->operations.push_back(op_cow);
+ }
+ return id_node;
+}
+
+IDDepsNode *DepsgraphNodeBuilder::find_id_node(ID *id)
+{
+ return graph_->find_id_node(id);
}
TimeSourceDepsNode *DepsgraphNodeBuilder::add_time_source()
@@ -259,9 +307,79 @@ OperationDepsNode *DepsgraphNodeBuilder::find_operation_node(
return find_operation_node(id, comp_type, "", opcode, name, name_tag);
}
+ID *DepsgraphNodeBuilder::get_cow_id(const ID *id_orig) const
+{
+ return graph_->get_cow_id(id_orig);
+}
+
+ID *DepsgraphNodeBuilder::ensure_cow_id(ID *id_orig)
+{
+ if (id_orig->tag & LIB_TAG_COPY_ON_WRITE) {
+ /* ID is already remapped to copy-on-write. */
+ return id_orig;
+ }
+ IDDepsNode *id_node = add_id_node(id_orig);
+ return id_node->id_cow;
+}
+
/* **** Build functions for entity nodes **** */
void DepsgraphNodeBuilder::begin_build() {
+ if (DEG_depsgraph_use_copy_on_write()) {
+ /* Store existing copy-on-write versions of datablock, so we can re-use
+ * them for new ID nodes.
+ */
+ cow_id_hash_ = BLI_ghash_ptr_new("Depsgraph id hash");
+ foreach (IDDepsNode *id_node, graph_->id_nodes) {
+ if (deg_copy_on_write_is_expanded(id_node->id_cow)) {
+ if (id_node->id_orig == id_node->id_cow) {
+ continue;
+ }
+ BLI_ghash_insert(cow_id_hash_,
+ id_node->id_orig,
+ id_node->id_cow);
+ id_node->id_cow = NULL;
+ }
+ }
+ }
+
+ GSET_FOREACH_BEGIN(OperationDepsNode *, op_node, graph_->entry_tags)
+ {
+ ComponentDepsNode *comp_node = op_node->owner;
+ IDDepsNode *id_node = comp_node->owner;
+
+ SavedEntryTag entry_tag;
+ entry_tag.id = id_node->id_orig;
+ entry_tag.component_type = comp_node->type;
+ entry_tag.opcode = op_node->opcode;
+ saved_entry_tags_.push_back(entry_tag);
+ };
+ GSET_FOREACH_END();
+
+ /* Make sure graph has no nodes left from previous state. */
+ graph_->clear_all_nodes();
+ graph_->operations.clear();
+ BLI_gset_clear(graph_->entry_tags, NULL);
+}
+
+void DepsgraphNodeBuilder::end_build()
+{
+ foreach (const SavedEntryTag& entry_tag, saved_entry_tags_) {
+ IDDepsNode *id_node = find_id_node(entry_tag.id);
+ if (id_node == NULL) {
+ continue;
+ }
+ ComponentDepsNode *comp_node =
+ id_node->find_component(entry_tag.component_type);
+ if (comp_node == NULL) {
+ continue;
+ }
+ OperationDepsNode *op_node = comp_node->find_operation(entry_tag.opcode);
+ if (op_node == NULL) {
+ continue;
+ }
+ op_node->tag_update(graph_);
+ }
}
void DepsgraphNodeBuilder::build_id(ID* id) {
@@ -269,14 +387,11 @@ void DepsgraphNodeBuilder::build_id(ID* id) {
return;
}
switch (GS(id->name)) {
- case ID_SCE:
- build_scene((Scene *)id);
- break;
case ID_GR:
- build_group(NULL, (Group *)id);
+ build_group((Group *)id);
break;
case ID_OB:
- build_object(NULL, (Object *)id);
+ build_object(-1, (Object *)id, DEG_ID_LINKED_INDIRECTLY);
break;
case ID_NT:
build_nodetree((bNodeTree *)id);
@@ -300,51 +415,63 @@ void DepsgraphNodeBuilder::build_id(ID* id) {
build_movieclip((MovieClip *)id);
break;
default:
- /* fprintf(stderr, "Unhandled ID %s\n", id->name); */
- break;
+ fprintf(stderr, "Unhandled ID %s\n", id->name);
}
}
-void DepsgraphNodeBuilder::build_group(Base *base, Group *group)
+void DepsgraphNodeBuilder::build_group(Group *group)
{
if (built_map_.checkIsBuiltAndTag(group)) {
return;
}
- LISTBASE_FOREACH (GroupObject *, go, &group->gobject) {
- build_object(base, go->ob);
+ /* Build group objects. */
+ LISTBASE_FOREACH (Base *, base, &group->view_layer->object_bases) {
+ build_object(-1, base->object, DEG_ID_LINKED_INDIRECTLY);
}
+ /* Operation to evaluate the whole view layer.
+ *
+ * NOTE: We re-use DONE opcode even though the function does everything.
+ * This way we wouldn't need to worry about possible relations from DONE,
+ * regardless whether it's a group or scene or something else.
+ */
+ add_id_node(&group->id);
+ Group *group_cow = get_cow_datablock(group);
+ add_operation_node(&group->id,
+ DEG_NODE_TYPE_LAYER_COLLECTIONS,
+ function_bind(BKE_group_eval_view_layers,
+ _1,
+ group_cow),
+ DEG_OPCODE_VIEW_LAYER_EVAL);
}
-void DepsgraphNodeBuilder::build_object(Base *base, Object *object)
+void DepsgraphNodeBuilder::build_object(int base_index,
+ Object *object,
+ eDepsNode_LinkedState_Type linked_state)
{
const bool has_object = built_map_.checkIsBuiltAndTag(object);
- IDDepsNode *id_node = (has_object)
- ? graph_->find_id_node(&object->id)
- : add_id_node(&object->id);
- /* Update node layers.
- * Do it for both new and existing ID nodes. This is so because several
- * bases might be sharing same object.
- */
- if (base != NULL) {
- id_node->layers |= base->lay;
- }
- if (object->type == OB_CAMERA) {
- /* Camera should always be updated, it used directly by viewport.
- *
- * TODO(sergey): Make it only for active scene camera.
- */
- id_node->layers |= (unsigned int)(-1);
- }
/* Skip rest of components if the ID node was already there. */
if (has_object) {
+ IDDepsNode *id_node = find_id_node(&object->id);
+ /* We need to build some extra stuff if object becomes linked
+ * directly.
+ */
+ if (id_node->linked_state == DEG_ID_LINKED_INDIRECTLY) {
+ build_object_flags(base_index, object, linked_state);
+ }
+ id_node->linked_state = max(id_node->linked_state, linked_state);
return;
}
+ /* Create ID node for object and begin init. */
+ IDDepsNode *id_node = add_id_node(&object->id);
+ id_node->linked_state = linked_state;
object->customdata_mask = 0;
+ /* Various flags, flushing from bases/collections. */
+ build_object_flags(base_index, object, linked_state);
/* Transform. */
build_object_transform(object);
/* Parent. */
if (object->parent != NULL) {
- build_object(NULL, object->parent);
+ build_object(-1, object->parent, DEG_ID_LINKED_INDIRECTLY);
}
/* Modifiers. */
if (object->modifiers.first != NULL) {
@@ -383,23 +510,46 @@ void DepsgraphNodeBuilder::build_object(Base *base, Object *object)
/* Object that this is a proxy for. */
if (object->proxy) {
object->proxy->proxy_from = object;
- build_object(base, object->proxy);
+ build_object(-1, object->proxy, DEG_ID_LINKED_INDIRECTLY);
}
/* Object dupligroup. */
if (object->dup_group != NULL) {
- build_group(base, object->dup_group);
+ build_group(object->dup_group);
}
}
+void DepsgraphNodeBuilder::build_object_flags(
+ int base_index,
+ Object *object,
+ eDepsNode_LinkedState_Type linked_state)
+{
+ if (base_index == -1) {
+ return;
+ }
+ Scene *scene_cow = get_cow_datablock(scene_);
+ Object *object_cow = get_cow_datablock(object);
+ const bool is_from_set = (linked_state == DEG_ID_LINKED_VIA_SET);
+ /* TODO(sergey): Is this really best component to be used? */
+ add_operation_node(&object->id,
+ DEG_NODE_TYPE_LAYER_COLLECTIONS,
+ function_bind(BKE_object_eval_flush_base_flags,
+ _1,
+ scene_cow,
+ view_layer_index_,
+ object_cow, base_index,
+ is_from_set),
+ DEG_OPCODE_OBJECT_BASE_FLAGS);
+}
+
void DepsgraphNodeBuilder::build_object_data(Object *object)
{
if (object->data == NULL) {
return;
}
IDDepsNode *id_node = graph_->find_id_node(&object->id);
- /* type-specific data... */
+ /* type-specific data. */
switch (object->type) {
- case OB_MESH: /* Geometry */
+ case OB_MESH:
case OB_CURVE:
case OB_FONT:
case OB_SURF:
@@ -430,6 +580,9 @@ void DepsgraphNodeBuilder::build_object_data(Object *object)
case OB_CAMERA:
build_camera(object);
break;
+ case OB_LIGHTPROBE:
+ build_lightprobe(object);
+ break;
default:
{
ID *obdata = (ID *)object->data;
@@ -444,39 +597,44 @@ void DepsgraphNodeBuilder::build_object_data(Object *object)
void DepsgraphNodeBuilder::build_object_transform(Object *object)
{
OperationDepsNode *op_node;
+ Scene *scene_cow = get_cow_datablock(scene_);
+ Object *ob_cow = get_cow_datablock(object);
/* local transforms (from transform channels - loc/rot/scale + deltas) */
op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_local_transform, _1, object),
+ function_bind(BKE_object_eval_local_transform,
+ _1,
+ ob_cow),
DEG_OPCODE_TRANSFORM_LOCAL);
op_node->set_as_entry();
/* object parent */
- if (object->parent) {
+ if (object->parent != NULL) {
add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_parent, _1, scene_, object),
+ function_bind(BKE_object_eval_parent,
+ _1,
+ scene_cow,
+ ob_cow),
DEG_OPCODE_TRANSFORM_PARENT);
}
/* object constraints */
- if (object->constraints.first) {
+ if (object->constraints.first != NULL) {
build_object_constraints(object);
}
- /* Temporary uber-update node, which does everything.
- * It is for the being we're porting old dependencies into the new system.
- * We'll get rid of this node as soon as all the granular update functions
- * are filled in.
- *
- * TODO(sergey): Get rid of this node.
- */
+ /* Rest of transformation update. */
add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_uber_transform, _1, object),
+ function_bind(BKE_object_eval_uber_transform,
+ _1,
+ ob_cow),
DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
/* object transform is done */
op_node = add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_done, _1, object),
+ function_bind(BKE_object_eval_done,
+ _1,
+ ob_cow),
DEG_OPCODE_TRANSFORM_FINAL);
op_node->set_as_exit();
}
@@ -502,7 +660,10 @@ void DepsgraphNodeBuilder::build_object_constraints(Object *object)
{
/* create node for constraint stack */
add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_object_eval_constraints, _1, scene_, object),
+ function_bind(BKE_object_eval_constraints,
+ _1,
+ get_cow_datablock(scene_),
+ get_cow_datablock(object)),
DEG_OPCODE_TRANSFORM_CONSTRAINTS);
}
@@ -513,23 +674,39 @@ void DepsgraphNodeBuilder::build_object_constraints(Object *object)
void DepsgraphNodeBuilder::build_animdata(ID *id)
{
AnimData *adt = BKE_animdata_from_id(id);
-
- if (adt == NULL)
+ if (adt == NULL) {
return;
-
+ }
/* animation */
if (adt->action || adt->nla_tracks.first || adt->drivers.first) {
- // XXX: Hook up specific update callbacks for special properties which may need it...
+ (void) add_id_node(id);
+ ID *id_cow = get_cow_id(id);
+
+ if (adt->action != NULL) {
+ add_operation_node(&adt->action->id, DEG_NODE_TYPE_ANIMATION,
+ NULL,
+ DEG_OPCODE_ANIMATION);
+ }
- /* actions and NLA - as a single unit for now, as it gets complicated to schedule otherwise */
+ // XXX: Hook up specific update callbacks for special properties which
+ // may need it...
+
+ /* actions and NLA - as a single unit for now, as it gets complicated to
+ * schedule otherwise.
+ */
if ((adt->action) || (adt->nla_tracks.first)) {
/* create the node */
add_operation_node(id, DEG_NODE_TYPE_ANIMATION,
- function_bind(BKE_animsys_eval_animdata, _1, id),
- DEG_OPCODE_ANIMATION, id->name);
-
- // TODO: for each channel affected, we might also want to add some support for running RNA update callbacks on them
- // (which will be needed for proper handling of drivers later)
+ function_bind(BKE_animsys_eval_animdata,
+ _1,
+ id_cow),
+ DEG_OPCODE_ANIMATION,
+ id->name);
+
+ /* TODO: for each channel affected, we might also want to add some
+ * support for running RNA update callbacks on them
+ * (which will be needed for proper handling of drivers later)
+ */
}
/* drivers */
@@ -547,10 +724,13 @@ void DepsgraphNodeBuilder::build_animdata(ID *id)
*/
void DepsgraphNodeBuilder::build_driver(ID *id, FCurve *fcurve)
{
+ ID *id_cow = get_cow_id(id);
+
/* Create data node for this driver */
+ /* TODO(sergey): Shall we use COW of fcu itself here? */
ensure_operation_node(id,
DEG_NODE_TYPE_PARAMETERS,
- function_bind(BKE_animsys_eval_driver, _1, id, fcurve),
+ function_bind(BKE_animsys_eval_driver, _1, id_cow, fcurve),
DEG_OPCODE_DRIVER,
fcurve->rna_path ? fcurve->rna_path : "",
fcurve->array_index);
@@ -602,17 +782,17 @@ void DepsgraphNodeBuilder::build_world(World *world)
if (built_map_.checkIsBuiltAndTag(world)) {
return;
}
- ID *world_id = &world->id;
- build_animdata(world_id);
+ /* Animation. */
+ build_animdata(&world->id);
/* world itself */
- add_operation_node(world_id,
- DEG_NODE_TYPE_PARAMETERS,
- NULL,
- DEG_OPCODE_PARAMETERS_EVAL);
- /* textures */
- build_texture_stack(world->mtex);
+ add_operation_node(&world->id,
+ DEG_NODE_TYPE_SHADING,
+ function_bind(BKE_world_eval,
+ _1,
+ get_cow_datablock(world)),
+ DEG_OPCODE_WORLD_UPDATE);
/* world's nodetree */
- if (world->nodetree) {
+ if (world->nodetree != NULL) {
build_nodetree(world->nodetree);
}
}
@@ -621,55 +801,66 @@ void DepsgraphNodeBuilder::build_world(World *world)
void DepsgraphNodeBuilder::build_rigidbody(Scene *scene)
{
RigidBodyWorld *rbw = scene->rigidbody_world;
+ Scene *scene_cow = get_cow_datablock(scene);
/**
* Rigidbody Simulation Nodes
* ==========================
*
* There are 3 nodes related to Rigidbody Simulation:
- * 1) "Initialize/Rebuild World" - this is called sparingly, only when the simulation
- * needs to be rebuilt (mainly after file reload, or moving back to start frame)
- * 2) "Do Simulation" - perform a simulation step - interleaved between the evaluation
- * steps for clusters of objects (i.e. between those affected and/or not affected by
- * the sim for instance)
+ * 1) "Initialize/Rebuild World" - this is called sparingly, only when the
+ * simulation needs to be rebuilt (mainly after file reload, or moving
+ * back to start frame)
+ * 2) "Do Simulation" - perform a simulation step - interleaved between the
+ * evaluation steps for clusters of objects (i.e. between those affected
+ * and/or not affected by the sim for instance).
*
- * 3) "Pull Results" - grab the specific transforms applied for a specific object -
- * performed as part of object's transform-stack building
+ * 3) "Pull Results" - grab the specific transforms applied for a specific
+ * object - performed as part of object's transform-stack building.
*/
- /* create nodes ------------------------------------------------------------------------ */
- /* XXX: is this the right component, or do we want to use another one instead? */
+ /* Create nodes --------------------------------------------------------- */
+
+ /* XXX: is this the right component, or do we want to use another one
+ * instead?
+ */
/* init/rebuild operation */
- /*OperationDepsNode *init_node =*/ add_operation_node(&scene->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_rigidbody_rebuild_sim, _1, scene),
- DEG_OPCODE_RIGIDBODY_REBUILD);
+ /*OperationDepsNode *init_node =*/ add_operation_node(
+ &scene->id, DEG_NODE_TYPE_TRANSFORM,
+ function_bind(BKE_rigidbody_rebuild_sim, _1, scene_cow),
+ DEG_OPCODE_RIGIDBODY_REBUILD);
/* do-sim operation */
// XXX: what happens if we need to split into several groups?
- OperationDepsNode *sim_node = add_operation_node(&scene->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_rigidbody_eval_simulation, _1, scene),
- DEG_OPCODE_RIGIDBODY_SIM);
+ OperationDepsNode *sim_node = add_operation_node(
+ &scene->id, DEG_NODE_TYPE_TRANSFORM,
+ function_bind(BKE_rigidbody_eval_simulation, _1, scene_cow),
+ DEG_OPCODE_RIGIDBODY_SIM);
- /* XXX: For now, the sim node is the only one that really matters here. If any other
- * sims get added later, we may have to remove these hacks...
+ /* XXX: For now, the sim node is the only one that really matters here.
+ * If any other sims get added later, we may have to remove these hacks...
*/
sim_node->owner->entry_operation = sim_node;
sim_node->owner->exit_operation = sim_node;
-
/* objects - simulation participants */
if (rbw->group) {
- LISTBASE_FOREACH (GroupObject *, go, &rbw->group->gobject) {
- Object *object = go->ob;
+ LISTBASE_FOREACH (Base *, base, &rbw->group->view_layer->object_bases) {
+ Object *object = base->object;
if (!object || (object->type != OB_MESH))
continue;
/* 2) create operation for flushing results */
- /* object's transform component - where the rigidbody operation lives */
+ /* object's transform component - where the rigidbody operation
+ * lives. */
add_operation_node(&object->id, DEG_NODE_TYPE_TRANSFORM,
- function_bind(BKE_rigidbody_object_sync_transforms, _1, scene, object),
+ function_bind(
+ BKE_rigidbody_object_sync_transforms,
+ _1,
+ scene_cow,
+ get_cow_datablock(object)),
DEG_OPCODE_RIGIDBODY_TRANSFORM_COPY);
}
}
@@ -694,20 +885,26 @@ void DepsgraphNodeBuilder::build_particles(Object *object)
/* Component for all particle systems. */
ComponentDepsNode *psys_comp =
add_component_node(&object->id, DEG_NODE_TYPE_EVAL_PARTICLES);
+
+ /* TODO(sergey): Need to get COW of PSYS. */
+ Scene *scene_cow = get_cow_datablock(scene_);
+ Object *ob_cow = get_cow_datablock(object);
+
add_operation_node(psys_comp,
function_bind(BKE_particle_system_eval_init,
_1,
- scene_,
- object),
+ scene_cow,
+ ob_cow),
DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT);
/* Build all particle systems. */
LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
ParticleSettings *part = psys->part;
- /* Particle settings. */
- // XXX: what if this is used more than once!
- build_animdata(&part->id);
- /* This particle system evaluation. */
- // TODO: for now, this will just be a placeholder "ubereval" node
+ /* Build particle settings operations.
+ *
+ * NOTE: The call itself ensures settings are only build once.
+ */
+ build_particle_settings(part);
+ /* Particle system evaluation. */
add_operation_node(psys_comp,
NULL,
DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
@@ -716,29 +913,52 @@ void DepsgraphNodeBuilder::build_particles(Object *object)
switch (part->ren_as) {
case PART_DRAW_OB:
if (part->dup_ob != NULL) {
- build_object(NULL, part->dup_ob);
+ build_object(-1,
+ part->dup_ob,
+ DEG_ID_LINKED_INDIRECTLY);
}
break;
case PART_DRAW_GR:
if (part->dup_group != NULL) {
- build_group(NULL, part->dup_group);
+ build_group(part->dup_group);
}
break;
}
}
- /* pointcache */
- // TODO...
+ /* TODO(sergey): Do we need a point cache operations here? */
+ add_operation_node(&object->id,
+ DEG_NODE_TYPE_CACHE,
+ function_bind(BKE_ptcache_object_reset,
+ scene_cow,
+ ob_cow,
+ PTCACHE_RESET_DEPSGRAPH),
+ DEG_OPCODE_POINT_CACHE_RESET);
+}
+
+void DepsgraphNodeBuilder::build_particle_settings(ParticleSettings *part) {
+ if (built_map_.checkIsBuiltAndTag(part)) {
+ return;
+ }
+ /* Animation data. */
+ build_animdata(&part->id);
+ /* Parameters change. */
+ add_operation_node(&part->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
}
void DepsgraphNodeBuilder::build_cloth(Object *object)
{
+ Scene *scene_cow = get_cow_datablock(scene_);
+ Object *object_cow = get_cow_datablock(object);
add_operation_node(&object->id,
DEG_NODE_TYPE_CACHE,
function_bind(BKE_object_eval_cloth,
_1,
- scene_,
- object),
+ scene_cow,
+ object_cow),
DEG_OPCODE_GEOMETRY_CLOTH_MODIFIER);
}
@@ -756,8 +976,9 @@ void DepsgraphNodeBuilder::build_shapekeys(Key *key)
// XXX: what happens if the datablock is shared!
void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
{
- ID *obdata = (ID *)object->data;
OperationDepsNode *op_node;
+ Scene *scene_cow = get_cow_datablock(scene_);
+ Object *object_cow = get_cow_datablock(object);
/* Temporary uber-update node, which does everything.
* It is for the being we're porting old dependencies into the new system.
@@ -770,8 +991,8 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_object_eval_uber_data,
_1,
- scene_,
- object),
+ scene_cow,
+ object_cow),
DEG_OPCODE_GEOMETRY_UBEREVAL);
op_node->set_as_exit();
@@ -792,10 +1013,21 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
}
/* materials */
- for (int a = 1; a <= object->totcol; a++) {
- Material *ma = give_current_material(object, a);
- if (ma != NULL) {
- build_material(ma);
+ if (object->totcol != 0) {
+ if (object->type == OB_MESH) {
+ add_operation_node(&object->id,
+ DEG_NODE_TYPE_SHADING,
+ function_bind(BKE_object_eval_update_shading,
+ _1,
+ object_cow),
+ DEG_OPCODE_SHADING);
+ }
+
+ for (int a = 1; a <= object->totcol; a++) {
+ Material *ma = give_current_material(object, a);
+ if (ma != NULL) {
+ build_material(ma);
+ }
}
}
@@ -804,9 +1036,13 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
// add geometry collider relations
}
+ ID *obdata = (ID *)object->data;
if (built_map_.checkIsBuiltAndTag(obdata)) {
return;
}
+ /* Make sure we've got an ID node before requesting CoW pointer. */
+ (void) add_id_node((ID *)obdata);
+ ID *obdata_cow = get_cow_id(obdata);
/* ShapeKeys */
Key *key = BKE_key_from_object(object);
@@ -829,7 +1065,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_mesh_eval_geometry,
_1,
- (Mesh *)obdata),
+ (Mesh *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
op_node->set_as_entry();
@@ -846,9 +1082,10 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
/* metaball evaluation operations */
op_node = add_operation_node(obdata,
DEG_NODE_TYPE_GEOMETRY,
- function_bind(BKE_mball_eval_geometry,
- _1,
- (MetaBall *)obdata),
+ function_bind(
+ BKE_mball_eval_geometry,
+ _1,
+ (MetaBall *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
}
@@ -873,23 +1110,22 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_curve_eval_geometry,
_1,
- (Curve *)obdata),
+ (Curve *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
op_node->set_as_entry();
-
/* Make sure objects used for bevel.taper are in the graph.
* NOTE: This objects might be not linked to the scene.
*/
Curve *cu = (Curve *)obdata;
if (cu->bevobj != NULL) {
- build_object(NULL, cu->bevobj);
+ build_object(-1, cu->bevobj, DEG_ID_LINKED_INDIRECTLY);
}
if (cu->taperobj != NULL) {
- build_object(NULL, cu->taperobj);
+ build_object(-1, cu->taperobj, DEG_ID_LINKED_INDIRECTLY);
}
if (object->type == OB_FONT && cu->textoncurve != NULL) {
- build_object(NULL, cu->textoncurve);
+ build_object(-1, cu->textoncurve, DEG_ID_LINKED_INDIRECTLY);
}
break;
}
@@ -901,7 +1137,7 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
DEG_NODE_TYPE_GEOMETRY,
function_bind(BKE_lattice_eval_geometry,
_1,
- (Lattice *)obdata),
+ (Lattice *)obdata_cow),
DEG_OPCODE_PLACEHOLDER,
"Geometry Eval");
op_node->set_as_entry();
@@ -918,11 +1154,20 @@ void DepsgraphNodeBuilder::build_obdata_geom(Object *object)
DEG_NODE_TYPE_PARAMETERS,
NULL,
DEG_OPCODE_PARAMETERS_EVAL);
+
+ /* Batch cache. */
+ add_operation_node(obdata,
+ DEG_NODE_TYPE_BATCH_CACHE,
+ function_bind(BKE_object_data_select_update,
+ _1,
+ obdata_cow),
+ DEG_OPCODE_GEOMETRY_SELECT_UPDATE);
}
/* Cameras */
void DepsgraphNodeBuilder::build_camera(Object *object)
{
+ /* Object data. */
/* TODO: Link scene-camera links in somehow... */
Camera *camera = (Camera *)object->data;
if (built_map_.checkIsBuiltAndTag(camera)) {
@@ -933,30 +1178,23 @@ void DepsgraphNodeBuilder::build_camera(Object *object)
DEG_NODE_TYPE_PARAMETERS,
NULL,
DEG_OPCODE_PARAMETERS_EVAL);
- if (camera->dof_ob != NULL) {
- /* TODO(sergey): For now parametrs are on object level. */
- add_operation_node(&object->id, DEG_NODE_TYPE_PARAMETERS, NULL,
- DEG_OPCODE_PLACEHOLDER, "Camera DOF");
- }
}
/* Lamps */
void DepsgraphNodeBuilder::build_lamp(Object *object)
{
+ /* Object data. */
Lamp *lamp = (Lamp *)object->data;
if (built_map_.checkIsBuiltAndTag(lamp)) {
return;
}
build_animdata(&lamp->id);
- /* TODO(sergey): Is it really how we're supposed to work with drivers? */
add_operation_node(&lamp->id,
DEG_NODE_TYPE_PARAMETERS,
NULL,
DEG_OPCODE_PARAMETERS_EVAL);
/* lamp's nodetree */
build_nodetree(lamp->nodetree);
- /* textures */
- build_texture_stack(lamp->mtex);
}
void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
@@ -967,16 +1205,26 @@ void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
if (built_map_.checkIsBuiltAndTag(ntree)) {
return;
}
-
/* nodetree itself */
- OperationDepsNode *op_node;
+ add_id_node(&ntree->id);
+ bNodeTree *ntree_cow = get_cow_datablock(ntree);
+ /* Animation, */
build_animdata(&ntree->id);
- /* Parameters for drivers. */
- op_node = add_operation_node(&ntree->id,
- DEG_NODE_TYPE_PARAMETERS,
- NULL,
- DEG_OPCODE_PARAMETERS_EVAL);
- op_node->set_as_exit();
+ /* Shading update. */
+ add_operation_node(&ntree->id,
+ DEG_NODE_TYPE_SHADING,
+ NULL,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ /* NOTE: We really pass original and CoW node trees here, this is how the
+ * callback works. Ideally we need to find a better way for that.
+ */
+ add_operation_node(&ntree->id,
+ DEG_NODE_TYPE_SHADING_PARAMETERS,
+ function_bind(BKE_nodetree_shading_params_eval,
+ _1,
+ ntree_cow,
+ ntree),
+ DEG_OPCODE_MATERIAL_UPDATE);
/* nodetree's nodes... */
LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) {
ID *id = bnode->id;
@@ -994,7 +1242,7 @@ void DepsgraphNodeBuilder::build_nodetree(bNodeTree *ntree)
build_image((Image *)id);
}
else if (id_type == ID_OB) {
- build_object(NULL, (Object *)id);
+ build_object(-1, (Object *)id, DEG_ID_LINKED_INDIRECTLY);
}
else if (id_type == ID_SCE) {
/* Scenes are used by compositor trees, and handled by render
@@ -1022,30 +1270,22 @@ void DepsgraphNodeBuilder::build_material(Material *material)
if (built_map_.checkIsBuiltAndTag(material)) {
return;
}
- add_operation_node(&material->id, DEG_NODE_TYPE_SHADING, NULL,
- DEG_OPCODE_PLACEHOLDER, "Material Update");
-
- /* material animation */
+ /* Material itself. */
+ add_id_node(&material->id);
+ Material *material_cow = get_cow_datablock(material);
+ /* Shading update. */
+ add_operation_node(&material->id,
+ DEG_NODE_TYPE_SHADING,
+ function_bind(BKE_material_eval,
+ _1,
+ material_cow),
+ DEG_OPCODE_MATERIAL_UPDATE);
+ /* Material animation. */
build_animdata(&material->id);
- /* textures */
- build_texture_stack(material->mtex);
- /* material's nodetree */
+ /* Material's nodetree. */
build_nodetree(material->nodetree);
}
-/* Texture-stack attached to some shading datablock */
-void DepsgraphNodeBuilder::build_texture_stack(MTex **texture_stack)
-{
- int i;
-
- /* for now assume that all texture-stacks have same number of max items */
- for (i = 0; i < MAX_MTEX; i++) {
- MTex *mtex = texture_stack[i];
- if (mtex && mtex->tex)
- build_texture(mtex->tex);
- }
-}
-
/* Recursively build graph for texture */
void DepsgraphNodeBuilder::build_texture(Tex *texture)
{
@@ -1088,13 +1328,18 @@ void DepsgraphNodeBuilder::build_compositor(Scene *scene)
// XXX: component type undefined!
//graph->get_node(&scene->id, NULL, DEG_NODE_TYPE_COMPOSITING, NULL);
- /* for now, nodetrees are just parameters; compositing occurs in internals of renderer... */
+ /* for now, nodetrees are just parameters; compositing occurs in internals
+ * of renderer...
+ */
add_component_node(&scene->id, DEG_NODE_TYPE_PARAMETERS);
build_nodetree(scene->nodetree);
}
void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd)
{
+ if (built_map_.checkIsBuiltAndTag(gpd)) {
+ return;
+ }
ID *gpd_id = &gpd->id;
/* TODO(sergey): what about multiple users of same datablock? This should
@@ -1109,6 +1354,9 @@ void DepsgraphNodeBuilder::build_gpencil(bGPdata *gpd)
void DepsgraphNodeBuilder::build_cachefile(CacheFile *cache_file)
{
+ if (built_map_.checkIsBuiltAndTag(cache_file)) {
+ return;
+ }
ID *cache_file_id = &cache_file->id;
/* Animation, */
build_animdata(cache_file_id);
@@ -1119,32 +1367,62 @@ void DepsgraphNodeBuilder::build_cachefile(CacheFile *cache_file)
void DepsgraphNodeBuilder::build_mask(Mask *mask)
{
+ if (built_map_.checkIsBuiltAndTag(mask)) {
+ return;
+ }
ID *mask_id = &mask->id;
+ Mask *mask_cow = get_cow_datablock(mask);
/* F-Curve based animation. */
build_animdata(mask_id);
/* Animation based on mask's shapes. */
add_operation_node(mask_id,
DEG_NODE_TYPE_ANIMATION,
- function_bind(BKE_mask_eval_animation, _1, mask),
+ function_bind(BKE_mask_eval_animation, _1, mask_cow),
DEG_OPCODE_MASK_ANIMATION);
/* Final mask evaluation. */
add_operation_node(mask_id,
DEG_NODE_TYPE_PARAMETERS,
- function_bind(BKE_mask_eval_update, _1, mask),
+ function_bind(BKE_mask_eval_update, _1, mask_cow),
DEG_OPCODE_MASK_EVAL);
}
-void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip) {
+void DepsgraphNodeBuilder::build_movieclip(MovieClip *clip)
+{
+ if (built_map_.checkIsBuiltAndTag(clip)) {
+ return;
+ }
ID *clip_id = &clip->id;
+ MovieClip *clip_cow = get_cow_datablock(clip);
/* Animation. */
build_animdata(clip_id);
/* Movie clip evaluation. */
add_operation_node(clip_id,
DEG_NODE_TYPE_PARAMETERS,
- function_bind(BKE_movieclip_eval_update, _1, clip),
+ function_bind(BKE_movieclip_eval_update, _1, clip_cow),
DEG_OPCODE_MOVIECLIP_EVAL);
}
+void DepsgraphNodeBuilder::build_lightprobe(Object *object)
+{
+ LightProbe *probe = (LightProbe *)object->data;
+ if (built_map_.checkIsBuiltAndTag(probe)) {
+ return;
+ }
+ /* Placeholder so we can add relations and tag ID node for update. */
+ add_operation_node(&probe->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PLACEHOLDER,
+ "LightProbe Eval");
+ add_operation_node(&object->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PLACEHOLDER,
+ "LightProbe Eval");
+
+ build_animdata(&probe->id);
+}
+
/* **** ID traversal callbacks functions **** */
void DepsgraphNodeBuilder::modifier_walk(void *user_data,
@@ -1159,7 +1437,9 @@ void DepsgraphNodeBuilder::modifier_walk(void *user_data,
}
switch (GS(id->name)) {
case ID_OB:
- data->builder->build_object(NULL, (Object *)id);
+ data->builder->build_object(-1,
+ (Object *)id,
+ DEG_ID_LINKED_INDIRECTLY);
break;
case ID_TE:
data->builder->build_texture((Tex *)id);
@@ -1182,7 +1462,9 @@ void DepsgraphNodeBuilder::constraint_walk(bConstraint * /*con*/,
}
switch (GS(id->name)) {
case ID_OB:
- data->builder->build_object(NULL, (Object *)id);
+ data->builder->build_object(-1,
+ (Object *)id,
+ DEG_ID_LINKED_INDIRECTLY);
break;
default:
/* pass */
@@ -1190,5 +1472,4 @@ void DepsgraphNodeBuilder::constraint_walk(bConstraint * /*con*/,
}
}
-
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
index f2154e58703..0ed3f5e334f 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes.h
@@ -33,6 +33,8 @@
#include "intern/builder/deg_builder_map.h"
#include "intern/depsgraph_types.h"
+#include "DEG_depsgraph.h" /* used for DEG_depsgraph_use_copy_on_write() */
+
struct Base;
struct CacheFile;
struct bGPdata;
@@ -43,6 +45,7 @@ struct Image;
struct FCurve;
struct Group;
struct Key;
+struct LayerCollection;
struct Main;
struct Material;
struct Mask;
@@ -50,6 +53,8 @@ struct MTex;
struct MovieClip;
struct bNodeTree;
struct Object;
+struct ParticleSettings;
+struct Probe;
struct bPoseChannel;
struct bConstraint;
struct Scene;
@@ -71,9 +76,35 @@ struct DepsgraphNodeBuilder {
DepsgraphNodeBuilder(Main *bmain, Depsgraph *graph);
~DepsgraphNodeBuilder();
+ /* For given original ID get ID which is created by CoW system. */
+ ID *get_cow_id(const ID *id_orig) const;
+ /* Similar to above, but for the cases when there is no ID node we create
+ * one.
+ */
+ ID *ensure_cow_id(ID *id_orig);
+
+ /* Helper wrapper function which wraps get_cow_id with a needed type cast. */
+ template<typename T>
+ T *get_cow_datablock(const T *orig) const {
+ return (T *)get_cow_id(&orig->id);
+ }
+
+ /* For a given COW datablock get corresponding original one. */
+ template<typename T>
+ T *get_orig_datablock(const T *cow) const {
+ if (DEG_depsgraph_use_copy_on_write()) {
+ return (T *)cow->id.orig_id;
+ }
+ else {
+ return (T *)cow;
+ }
+ }
+
void begin_build();
+ void end_build();
IDDepsNode *add_id_node(ID *id);
+ IDDepsNode *find_id_node(ID *id);
TimeSourceDepsNode *add_time_source();
ComponentDepsNode *add_component_node(ID *id,
@@ -127,15 +158,23 @@ struct DepsgraphNodeBuilder {
int name_tag = -1);
void build_id(ID* id);
- void build_scene(Scene *scene);
- void build_group(Base *base, Group *group);
- void build_object(Base *base, Object *object);
+ void build_view_layer(Scene *scene,
+ ViewLayer *view_layer,
+ eDepsNode_LinkedState_Type linked_state);
+ void build_group(Group *group);
+ void build_object(int base_index,
+ Object *object,
+ eDepsNode_LinkedState_Type linked_state);
+ void build_object_flags(int base_index,
+ Object *object,
+ eDepsNode_LinkedState_Type linked_state);
void build_object_data(Object *object);
void build_object_transform(Object *object);
void build_object_constraints(Object *object);
void build_pose_constraints(Object *object, bPoseChannel *pchan, int pchan_index);
void build_rigidbody(Scene *scene);
void build_particles(Object *object);
+ void build_particle_settings(ParticleSettings *part);
void build_cloth(Object *object);
void build_animdata(ID *id);
void build_driver(ID *id, FCurve *fcurve);
@@ -156,7 +195,6 @@ struct DepsgraphNodeBuilder {
void build_nodetree(bNodeTree *ntree);
void build_material(Material *ma);
void build_texture(Tex *tex);
- void build_texture_stack(MTex **texture_stack);
void build_image(Image *image);
void build_world(World *world);
void build_compositor(Scene *scene);
@@ -164,8 +202,16 @@ struct DepsgraphNodeBuilder {
void build_cachefile(CacheFile *cache_file);
void build_mask(Mask *mask);
void build_movieclip(MovieClip *clip);
+ void build_lightprobe(Object *object);
protected:
+ struct SavedEntryTag {
+ ID *id;
+ eDepsNode_Type component_type;
+ eDepsOperation_Code opcode;
+ };
+ vector<SavedEntryTag> saved_entry_tags_;
+
struct BuilderWalkUserData {
DepsgraphNodeBuilder *builder;
};
@@ -186,7 +232,10 @@ protected:
/* State which demotes currently built entities. */
Scene *scene_;
+ ViewLayer *view_layer_;
+ int view_layer_index_;
+ GHash *cow_id_hash_;
BuilderMap built_map_;
};
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
index 5824858d7ed..c48381481f5 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_rig.cc
@@ -46,6 +46,7 @@ extern "C" {
#include "DNA_armature_types.h"
#include "DNA_constraint_types.h"
#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "BKE_action.h"
#include "BKE_armature.h"
@@ -56,6 +57,7 @@ extern "C" {
#include "DEG_depsgraph_build.h"
#include "intern/builder/deg_builder.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_operation.h"
@@ -77,8 +79,8 @@ void DepsgraphNodeBuilder::build_pose_constraints(Object *object,
add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
function_bind(BKE_pose_constraints_evaluate,
_1,
- scene_,
- object,
+ get_cow_datablock(scene_),
+ get_cow_datablock(object),
pchan_index),
DEG_OPCODE_BONE_CONSTRAINTS);
}
@@ -108,8 +110,8 @@ void DepsgraphNodeBuilder::build_ik_pose(Object *object,
add_operation_node(&object->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name,
function_bind(BKE_pose_iktree_evaluate,
_1,
- scene_,
- object,
+ get_cow_datablock(scene_),
+ get_cow_datablock(object),
rootchan_index),
DEG_OPCODE_POSE_IK_SOLVER);
}
@@ -125,15 +127,16 @@ void DepsgraphNodeBuilder::build_splineik_pose(Object *object,
bPoseChannel *rootchan = BKE_armature_splineik_solver_find_root(pchan, data);
/* Operation node for evaluating/running Spline IK Solver.
- * Store the "root bone" of this chain in the solver, so it knows where to start.
+ * Store the "root bone" of this chain in the solver, so it knows where to
+ * start.
*/
int rootchan_index = BLI_findindex(&object->pose->chanbase, rootchan);
BLI_assert(rootchan_index != -1);
add_operation_node(&object->id, DEG_NODE_TYPE_EVAL_POSE, rootchan->name,
function_bind(BKE_pose_splineik_evaluate,
_1,
- scene_,
- object,
+ get_cow_datablock(scene_),
+ get_cow_datablock(object),
rootchan_index),
DEG_OPCODE_POSE_SPLINE_IK_SOLVER);
}
@@ -141,19 +144,32 @@ void DepsgraphNodeBuilder::build_splineik_pose(Object *object,
/* Pose/Armature Bones Graph */
void DepsgraphNodeBuilder::build_rig(Object *object)
{
- bArmature *arm = (bArmature *)object->data;
+ bArmature *armature = (bArmature *)object->data;
+ Scene *scene_cow;
+ Object *object_cow;
+ if (DEG_depsgraph_use_copy_on_write()) {
+ scene_cow = get_cow_datablock(scene_);
+ object_cow = get_cow_datablock(object);
+ }
+ else {
+ scene_cow = scene_;
+ object_cow = object;
+ }
OperationDepsNode *op_node;
- /* animation and/or drivers linking posebones to base-armature used to define them
+ /* Animation and/or drivers linking posebones to base-armature used to
+ * define them.
+ *
* NOTE: AnimData here is really used to control animated deform properties,
- * which ideally should be able to be unique across different instances.
- * Eventually, we need some type of proxy/isolation mechanism in-between here
- * to ensure that we can use same rig multiple times in same scene...
+ * which ideally should be able to be unique across different
+ * instances. Eventually, we need some type of proxy/isolation
+ * mechanism in-between here to ensure that we can use same rig
+ * multiple times in same scene.
*/
- if (!built_map_.checkIsBuiltAndTag(arm)) {
- build_animdata(&arm->id);
+ if (!built_map_.checkIsBuiltAndTag(armature)) {
+ build_animdata(&armature->id);
/* Make sure pose is up-to-date with armature updates. */
- add_operation_node(&arm->id,
+ add_operation_node(&armature->id,
DEG_NODE_TYPE_PARAMETERS,
NULL,
DEG_OPCODE_PLACEHOLDER,
@@ -162,7 +178,7 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
/* Rebuild pose if not up to date. */
if (object->pose == NULL || (object->pose->flag & POSE_RECALC)) {
- BKE_pose_rebuild_ex(object, arm, false);
+ BKE_pose_rebuild(object, armature);
/* XXX: Without this animation gets lost in certain circumstances
* after loading file. Need to investigate further since it does
* not happen with simple scenes..
@@ -173,7 +189,7 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
}
/* speed optimization for animation lookups */
- if (object->pose) {
+ if (object->pose != NULL) {
BKE_pose_channels_hash_make(object->pose);
if (object->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
BKE_pose_update_constraint_flags(object->pose);
@@ -197,8 +213,8 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
* - Used for representing each bone within the rig
* - Acts to encapsulate the evaluation operations (base matrix + parenting,
* and constraint stack) so that they can be easily found.
- * - Everything else which depends on bone-results hook up to the component only
- * so that we can redirect those to point at either the the post-IK/
+ * - Everything else which depends on bone-results hook up to the component
+ * only so that we can redirect those to point at either the the post-IK/
* post-constraint/post-matrix steps, as needed.
*/
@@ -207,8 +223,8 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
DEG_NODE_TYPE_EVAL_POSE,
function_bind(BKE_pose_eval_init,
_1,
- scene_,
- object),
+ scene_cow,
+ object_cow),
DEG_OPCODE_POSE_INIT);
op_node->set_as_entry();
@@ -216,16 +232,16 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
DEG_NODE_TYPE_EVAL_POSE,
function_bind(BKE_pose_eval_init_ik,
_1,
- scene_,
- object),
+ scene_cow,
+ object_cow),
DEG_OPCODE_POSE_INIT_IK);
op_node = add_operation_node(&object->id,
DEG_NODE_TYPE_EVAL_POSE,
function_bind(BKE_pose_eval_flush,
_1,
- scene_,
- object),
+ scene_cow,
+ object_cow),
DEG_OPCODE_POSE_DONE);
op_node->set_as_exit();
@@ -238,17 +254,21 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
op_node->set_as_entry();
add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
- function_bind(BKE_pose_eval_bone, _1, scene_, object, pchan_index),
+ function_bind(BKE_pose_eval_bone, _1,
+ scene_cow,
+ object_cow,
+ pchan_index),
DEG_OPCODE_BONE_POSE_PARENT);
+ /* NOTE: Dedicated noop for easier relationship construction. */
add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
- NULL, /* NOTE: dedicated noop for easier relationship construction */
+ NULL,
DEG_OPCODE_BONE_READY);
op_node = add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
function_bind(BKE_pose_bone_done,
_1,
- object,
+ object_cow,
pchan_index),
DEG_OPCODE_BONE_DONE);
op_node->set_as_exit();
@@ -260,7 +280,7 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
DEG_OPCODE_PARAMETERS_EVAL,
pchan->name);
}
- /* Constraints. */
+ /* Build constraints. */
if (pchan->constraints.first != NULL) {
build_pose_constraints(object, pchan, pchan_index);
}
@@ -273,8 +293,8 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
*
* Unsolved Issues:
* - Care is needed to ensure that multi-headed trees work out the same
- * as in ik-tree building.
- * - Animated chain-lengths are a problem...
+ * as in ik-tree building
+ * - Animated chain-lengths are a problem.
*/
LISTBASE_FOREACH (bConstraint *, con, &pchan->constraints) {
switch (con->type) {
@@ -293,7 +313,7 @@ void DepsgraphNodeBuilder::build_rig(Object *object)
/* Custom shape. */
if (pchan->custom != NULL) {
- build_object(NULL, pchan->custom);
+ build_object(-1, pchan->custom, DEG_ID_LINKED_INDIRECTLY);
}
pchan_index++;
@@ -304,34 +324,49 @@ void DepsgraphNodeBuilder::build_proxy_rig(Object *object)
{
bArmature *arm = (bArmature *)object->data;
OperationDepsNode *op_node;
-
- build_animdata(&arm->id);
-
+ Object *object_cow;
+ if (DEG_depsgraph_use_copy_on_write()) {
+ object_cow = get_cow_datablock(object);
+ }
+ else {
+ object_cow = object;
+ }
+ /* Sanity check. */
BLI_assert(object->pose != NULL);
-
+ /* Animation. */
+ build_animdata(&arm->id);
/* speed optimization for animation lookups */
BKE_pose_channels_hash_make(object->pose);
if (object->pose->flag & POSE_CONSTRAINTS_NEED_UPDATE_FLAGS) {
BKE_pose_update_constraint_flags(object->pose);
}
-
op_node = add_operation_node(&object->id,
DEG_NODE_TYPE_EVAL_POSE,
- function_bind(BKE_pose_eval_proxy_copy, _1, object),
+ function_bind(BKE_pose_eval_proxy_copy,
+ _1,
+ object_cow),
DEG_OPCODE_POSE_INIT);
op_node->set_as_entry();
-
LISTBASE_FOREACH (bPoseChannel *, pchan, &object->pose->chanbase) {
- op_node = add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
- NULL, DEG_OPCODE_BONE_LOCAL);
+ op_node = add_operation_node(&object->id,
+ DEG_NODE_TYPE_BONE,
+ pchan->name,
+ NULL,
+ DEG_OPCODE_BONE_LOCAL);
op_node->set_as_entry();
-
- add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
- NULL, DEG_OPCODE_BONE_READY);
-
- op_node = add_operation_node(&object->id, DEG_NODE_TYPE_BONE, pchan->name,
- NULL, DEG_OPCODE_BONE_DONE);
+ /* Bone is ready for solvers. */
+ add_operation_node(&object->id,
+ DEG_NODE_TYPE_BONE,
+ pchan->name,
+ NULL,
+ DEG_OPCODE_BONE_READY);
+ /* Bone is fully evaluated. */
+ op_node = add_operation_node(&object->id,
+ DEG_NODE_TYPE_BONE,
+ pchan->name,
+ NULL,
+ DEG_OPCODE_BONE_DONE);
op_node->set_as_exit();
/* Custom properties. */
@@ -343,9 +378,10 @@ void DepsgraphNodeBuilder::build_proxy_rig(Object *object)
pchan->name);
}
}
-
- op_node = add_operation_node(&object->id, DEG_NODE_TYPE_EVAL_POSE,
- NULL, DEG_OPCODE_POSE_DONE);
+ op_node = add_operation_node(&object->id,
+ DEG_NODE_TYPE_EVAL_POSE,
+ NULL,
+ DEG_OPCODE_POSE_DONE);
op_node->set_as_exit();
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc
deleted file mode 100644
index 4bb15350f3a..00000000000
--- a/source/blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2013 Blender Foundation.
- * All rights reserved.
- *
- * Original Author: Joshua Leung
- * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/depsgraph/intern/builder/deg_builder_nodes_scene.cc
- * \ingroup depsgraph
- *
- * Methods for constructing depsgraph's nodes
- */
-
-#include "intern/builder/deg_builder_nodes.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_blenlib.h"
-#include "BLI_string.h"
-
-extern "C" {
-#include "DNA_node_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-
-#include "BKE_main.h"
-#include "BKE_node.h"
-} /* extern "C" */
-
-#include "DEG_depsgraph.h"
-#include "DEG_depsgraph_build.h"
-
-#include "intern/builder/deg_builder.h"
-#include "intern/nodes/deg_node.h"
-#include "intern/nodes/deg_node_component.h"
-#include "intern/nodes/deg_node_operation.h"
-#include "intern/depsgraph_types.h"
-#include "intern/depsgraph_intern.h"
-#include "util/deg_util_foreach.h"
-
-namespace DEG {
-
-void DepsgraphNodeBuilder::build_scene(Scene *scene)
-{
- /* Scene ID block. */
- add_id_node(&scene->id);
- /* timesource */
- add_time_source();
- /* build subgraph for set, and link this in... */
- // XXX: depending on how this goes, that scene itself could probably store its
- // own little partial depsgraph?
- if (scene->set != NULL) {
- build_scene(scene->set);
- }
- /* Setup currently building context. */
- scene_ = scene;
- /* scene objects */
- LISTBASE_FOREACH (Base *, base, &scene->base) {
- Object *object = base->object;
- build_object(base, object);
- }
- /* Rigidbody. */
- if (scene->rigidbody_world != NULL) {
- build_rigidbody(scene);
- }
- /* Scene's animation and drivers. */
- if (scene->adt != NULL) {
- build_animdata(&scene->id);
- }
- /* World. */
- if (scene->world != NULL) {
- build_world(scene->world);
- }
- /* Compositor nodes. */
- if (scene->nodetree != NULL) {
- build_compositor(scene);
- }
- /* Grease pencil. */
- if (scene->gpd != NULL) {
- build_gpencil(scene->gpd);
- }
- /* Cache file. */
- LISTBASE_FOREACH (CacheFile *, cachefile, &bmain_->cachefiles) {
- build_cachefile(cachefile);
- }
- /* Masks. */
- LISTBASE_FOREACH (Mask *, mask, &bmain_->mask) {
- build_mask(mask);
- }
- /* Movie clips. */
- LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
- build_movieclip(clip);
- }
- /* Parameters evaluation for scene relations mainly. */
- add_operation_node(&scene->id,
- DEG_NODE_TYPE_PARAMETERS,
- NULL,
- DEG_OPCODE_PLACEHOLDER,
- "Scene Eval");
-}
-
-} // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
new file mode 100644
index 00000000000..ac3970ed3ab
--- /dev/null
+++ b/source/blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
@@ -0,0 +1,159 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2013 Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Joshua Leung
+ * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/depsgraph/intern/builder/deg_builder_nodes_view_layer.cc
+ * \ingroup depsgraph
+ *
+ * Methods for constructing depsgraph's nodes
+ */
+
+#include "intern/builder/deg_builder_nodes.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_blenlib.h"
+#include "BLI_string.h"
+
+extern "C" {
+#include "DNA_node_types.h"
+#include "DNA_layer_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_layer.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+} /* extern "C" */
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
+#include "intern/builder/deg_builder.h"
+#include "intern/nodes/deg_node.h"
+#include "intern/nodes/deg_node_component.h"
+#include "intern/nodes/deg_node_operation.h"
+#include "intern/depsgraph_types.h"
+#include "intern/depsgraph_intern.h"
+#include "util/deg_util_foreach.h"
+
+namespace DEG {
+
+void DepsgraphNodeBuilder::build_view_layer(
+ Scene *scene,
+ ViewLayer *view_layer,
+ eDepsNode_LinkedState_Type linked_state)
+{
+ view_layer_index_ = BLI_findindex(&scene->view_layers, view_layer);
+ BLI_assert(view_layer_index_ != -1);
+ /* Scene ID block. */
+ add_id_node(&scene->id);
+ /* Time source. */
+ add_time_source();
+ /* Setup currently building context. */
+ scene_ = scene;
+ view_layer_ = view_layer;
+ /* Get pointer to a CoW version of scene ID. */
+ Scene *scene_cow;
+ if (DEG_depsgraph_use_copy_on_write()) {
+ scene_cow = get_cow_datablock(scene);
+ }
+ else {
+ scene_cow = scene;
+ }
+ /* Scene objects. */
+ int select_color = 1;
+ /* NOTE: Base is used for function bindings as-is, so need to pass CoW base,
+ * but object is expected to be an original one. Hence we go into some
+ * tricks here iterating over the view layer.
+ */
+ int base_index = 0;
+ LISTBASE_FOREACH(Base *, base, &view_layer->object_bases) {
+ /* object itself */
+ build_object(base_index, base->object, linked_state);
+ base->object->select_color = select_color++;
+ ++base_index;
+ }
+ if (scene->camera != NULL) {
+ build_object(-1, scene->camera, DEG_ID_LINKED_INDIRECTLY);
+ }
+ /* Rigidbody. */
+ if (scene->rigidbody_world != NULL) {
+ build_rigidbody(scene);
+ }
+ /* Scene's animation and drivers. */
+ if (scene->adt != NULL) {
+ build_animdata(&scene->id);
+ }
+ /* World. */
+ if (scene->world != NULL) {
+ build_world(scene->world);
+ }
+ /* Compositor nodes */
+ if (scene->nodetree != NULL) {
+ build_compositor(scene);
+ }
+ /* Grease pencil. */
+ if (scene->gpd != NULL) {
+ build_gpencil(scene->gpd);
+ }
+ /* Cache file. */
+ LISTBASE_FOREACH (CacheFile *, cachefile, &bmain_->cachefiles) {
+ build_cachefile(cachefile);
+ }
+ /* Masks. */
+ LISTBASE_FOREACH (Mask *, mask, &bmain_->mask) {
+ build_mask(mask);
+ }
+ /* Movie clips. */
+ LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
+ build_movieclip(clip);
+ }
+ /* Collections. */
+ add_operation_node(&scene->id,
+ DEG_NODE_TYPE_LAYER_COLLECTIONS,
+ function_bind(BKE_layer_eval_view_layer_indexed,
+ _1,
+ &scene_cow->id,
+ view_layer_index_),
+ DEG_OPCODE_VIEW_LAYER_EVAL);
+ /* Parameters evaluation for scene relations mainly. */
+ add_operation_node(&scene->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ NULL,
+ DEG_OPCODE_PLACEHOLDER,
+ "Scene Eval");
+ /* Build all set scenes. */
+ if (scene->set != NULL) {
+ ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set);
+ build_view_layer(scene->set, set_view_layer, DEG_ID_LINKED_VIA_SET);
+ }
+}
+
+} // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index 2d1e1f289ea..ae25aa77d98 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -61,6 +61,7 @@ extern "C" {
#include "DNA_movieclip_types.h"
#include "DNA_node_types.h"
#include "DNA_particle_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_object_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
@@ -168,6 +169,16 @@ static bool object_particles_depends_on_time(Object *object)
return false;
}
+static bool check_id_has_anim_component(ID *id)
+{
+ AnimData *adt = BKE_animdata_from_id(id);
+ if (adt == NULL) {
+ return false;
+ }
+ return (adt->action != NULL) ||
+ (!BLI_listbase_is_empty(&adt->nla_tracks));
+}
+
/* **** General purpose functions **** */
DepsgraphRelationBuilder::DepsgraphRelationBuilder(Main *bmain,
@@ -210,7 +221,7 @@ OperationDepsNode *DepsgraphRelationBuilder::get_node(
OperationDepsNode *op_node = find_node(key);
if (op_node == NULL) {
fprintf(stderr, "find_node_operation: Failed for (%s, '%s')\n",
- DEG_OPNAMES[key.opcode], key.name);
+ operationCodeAsString(key.opcode), key.name);
}
return op_node;
}
@@ -250,7 +261,8 @@ DepsRelation *DepsgraphRelationBuilder::add_time_relation(
return graph_->add_new_relation(timesrc, node_to, description, check_unique);
}
else {
- DEG_DEBUG_PRINTF(BUILD, "add_time_relation(%p = %s, %p = %s, %s) Failed\n",
+ DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
+ BUILD, "add_time_relation(%p = %s, %p = %s, %s) Failed\n",
timesrc, (timesrc) ? timesrc->identifier().c_str() : "<None>",
node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
description);
@@ -271,7 +283,8 @@ DepsRelation *DepsgraphRelationBuilder::add_operation_relation(
check_unique);
}
else {
- DEG_DEBUG_PRINTF(BUILD, "add_operation_relation(%p = %s, %p = %s, %s) Failed\n",
+ DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
+ BUILD, "add_operation_relation(%p = %s, %p = %s, %s) Failed\n",
node_from, (node_from) ? node_from->identifier().c_str() : "<None>",
node_to, (node_to) ? node_to->identifier().c_str() : "<None>",
description);
@@ -284,19 +297,16 @@ void DepsgraphRelationBuilder::add_collision_relations(
Scene *scene,
Object *object,
Group *group,
- int layer,
bool dupli,
const char *name)
{
unsigned int numcollobj;
- Object **collobjs = get_collisionobjects_ext(
- scene,
- object,
- group,
- layer,
- &numcollobj,
- eModifierType_Collision,
- dupli);
+ Object **collobjs = get_collisionobjects_ext(scene,
+ object,
+ group,
+ &numcollobj,
+ eModifierType_Collision,
+ dupli);
for (unsigned int i = 0; i < numcollobj; i++) {
Object *ob1 = collobjs[i];
@@ -320,9 +330,9 @@ void DepsgraphRelationBuilder::add_forcefield_relations(
bool add_absorption,
const char *name)
{
- ListBase *effectors = pdInitEffectors(scene, object, psys, eff, false);
+ ListBase *effectors = pdInitEffectors(NULL, scene, object, psys, eff, false);
if (effectors != NULL) {
- LISTBASE_FOREACH(EffectorCache *, eff, effectors) {
+ LISTBASE_FOREACH (EffectorCache *, eff, effectors) {
if (eff->ob != object) {
ComponentKey eff_key(&eff->ob->id, DEG_NODE_TYPE_TRANSFORM);
add_relation(eff_key, key, name);
@@ -360,7 +370,6 @@ void DepsgraphRelationBuilder::add_forcefield_relations(
scene,
object,
NULL,
- eff->ob->lay,
true,
"Force Absorption");
}
@@ -381,26 +390,65 @@ void DepsgraphRelationBuilder::begin_build()
{
}
+void DepsgraphRelationBuilder::build_id(ID* id) {
+ if (id == NULL) {
+ return;
+ }
+ switch (GS(id->name)) {
+ case ID_GR:
+ build_group(NULL, (Group *)id);
+ break;
+ case ID_OB:
+ build_object(NULL, (Object *)id);
+ break;
+ case ID_NT:
+ build_nodetree((bNodeTree *)id);
+ break;
+ case ID_MA:
+ build_material((Material *)id);
+ break;
+ case ID_TE:
+ build_texture((Tex *)id);
+ break;
+ case ID_WO:
+ build_world((World *)id);
+ break;
+ case ID_MSK:
+ build_mask((Mask *)id);
+ break;
+ case ID_MC:
+ build_movieclip((MovieClip *)id);
+ break;
+ default:
+ fprintf(stderr, "Unhandled ID %s\n", id->name);
+ }
+}
+
void DepsgraphRelationBuilder::build_group(Object *object, Group *group)
{
const bool group_done = built_map_.checkIsBuiltAndTag(group);
OperationKey object_local_transform_key(object != NULL ? &object->id : NULL,
DEG_NODE_TYPE_TRANSFORM,
DEG_OPCODE_TRANSFORM_LOCAL);
- LISTBASE_FOREACH (GroupObject *, go, &group->gobject) {
- if (!group_done) {
- build_object(go->ob);
+ if (!group_done) {
+ LISTBASE_FOREACH (Base *, base, &group->view_layer->object_bases) {
+ build_object(NULL, base->object);
}
- if (object != NULL) {
- ComponentKey dupli_transform_key(&go->ob->id, DEG_NODE_TYPE_TRANSFORM);
+ }
+ if (object != NULL) {
+ LISTBASE_FOREACH (Base *, base, &group->view_layer->object_bases) {
+ ComponentKey dupli_transform_key(&base->object->id, DEG_NODE_TYPE_TRANSFORM);
add_relation(dupli_transform_key, object_local_transform_key, "Dupligroup");
}
}
}
-void DepsgraphRelationBuilder::build_object(Object *object)
+void DepsgraphRelationBuilder::build_object(Base *base, Object *object)
{
if (built_map_.checkIsBuiltAndTag(object)) {
+ if (base != NULL) {
+ build_object_flags(base, object);
+ }
return;
}
/* Object Transforms */
@@ -419,10 +467,12 @@ void DepsgraphRelationBuilder::build_object(Object *object)
OperationKey ob_ubereval_key(&object->id,
DEG_NODE_TYPE_TRANSFORM,
DEG_OPCODE_TRANSFORM_OBJECT_UBEREVAL);
+ /* Various flags, flushing from bases/collections. */
+ build_object_flags(base, object);
/* Parenting. */
if (object->parent != NULL) {
/* Make sure parent object's relations are built. */
- build_object(object->parent);
+ build_object(NULL, object->parent);
/* Parent relationship. */
build_object_parent(object);
/* Local -> parent. */
@@ -488,7 +538,7 @@ void DepsgraphRelationBuilder::build_object(Object *object)
/* Object that this is a proxy for. */
if (object->proxy != NULL) {
object->proxy->proxy_from = object;
- build_object(object->proxy);
+ build_object(NULL, object->proxy);
/* TODO(sergey): This is an inverted relation, matches old depsgraph
* behavior and need to be investigated if it still need to be inverted.
*/
@@ -502,6 +552,20 @@ void DepsgraphRelationBuilder::build_object(Object *object)
}
}
+void DepsgraphRelationBuilder::build_object_flags(Base *base, Object *object)
+{
+ if (base == NULL) {
+ return;
+ }
+ OperationKey view_layer_done_key(&scene_->id,
+ DEG_NODE_TYPE_LAYER_COLLECTIONS,
+ DEG_OPCODE_VIEW_LAYER_EVAL);
+ OperationKey object_flags_key(&object->id,
+ DEG_NODE_TYPE_LAYER_COLLECTIONS,
+ DEG_OPCODE_OBJECT_BASE_FLAGS);
+ add_relation(view_layer_done_key, object_flags_key, "Base flags flush");
+}
+
void DepsgraphRelationBuilder::build_object_data(Object *object)
{
if (object->data == NULL) {
@@ -538,12 +602,16 @@ void DepsgraphRelationBuilder::build_object_data(Object *object)
case OB_CAMERA:
build_camera(object);
break;
+ case OB_LIGHTPROBE:
+ build_lightprobe(object);
+ break;
}
Key *key = BKE_key_from_object(object);
if (key != NULL) {
ComponentKey geometry_key((ID *)object->data, DEG_NODE_TYPE_GEOMETRY);
ComponentKey key_key(&key->id, DEG_NODE_TYPE_GEOMETRY);
add_relation(key_key, geometry_key, "Shapekeys");
+ build_nested_shapekey(&object->id, key);
}
}
@@ -878,6 +946,11 @@ void DepsgraphRelationBuilder::build_animdata_curves(ID *id)
ComponentKey adt_key(id, DEG_NODE_TYPE_ANIMATION);
TimeSourceKey time_src_key;
add_relation(time_src_key, adt_key, "TimeSrc -> Animation");
+ /* Relation from action itself. */
+ if (adt->action != NULL) {
+ ComponentKey action_key(&adt->action->id, DEG_NODE_TYPE_ANIMATION);
+ add_relation(action_key, adt_key, "Action -> Animation");
+ }
/* Get source operations. */
DepsNode *node_from = get_node(adt_key);
BLI_assert(node_from != NULL);
@@ -935,6 +1008,18 @@ void DepsgraphRelationBuilder::build_animdata_curves_targets(
graph_->add_new_relation(operation_from, operation_to,
"Animation -> Prop",
true);
+ /* It is possible that animation is writing to a nested ID datablock,
+ * need to make sure animation is evaluated after target ID is copied.
+ */
+ if (DEG_depsgraph_use_copy_on_write()) {
+ const IDDepsNode *id_node_from = operation_from->owner->owner;
+ const IDDepsNode *id_node_to = operation_to->owner->owner;
+ if (id_node_from != id_node_to) {
+ ComponentKey cow_key(id_node_to->id_orig,
+ DEG_NODE_TYPE_COPY_ON_WRITE);
+ add_relation(cow_key, adt_key, "Target CoW -> Animation", true);
+ }
+ }
}
}
@@ -973,7 +1058,6 @@ void DepsgraphRelationBuilder::build_animdata_drivers(ID *id)
/* create the driver's relations to targets */
build_driver(id, fcu);
-
/* Special case for array drivers: we can not multithread them because
* of the way how they work internally: animation system will write the
* whole array back to RNA even when changing individual array value.
@@ -1068,18 +1152,18 @@ void DepsgraphRelationBuilder::build_driver_data(ID *id, FCurve *fcu)
*/
IDDepsNode *arm_node = graph_->find_id_node(id);
char *bone_name = BLI_str_quoted_substrN(rna_path, "bones[");
- if (arm_node && bone_name) {
+ if (arm_node != NULL && bone_name != NULL) {
/* Find objects which use this, and make their eval callbacks
* depend on this.
*/
foreach (DepsRelation *rel, arm_node->outlinks) {
IDDepsNode *to_node = (IDDepsNode *)rel->to;
/* We only care about objects with pose data which use this. */
- if (GS(to_node->id->name) == ID_OB) {
- Object *object = (Object *)to_node->id;
- /* NOTE: object->pose may be NULL. */
- bPoseChannel *pchan = BKE_pose_channel_find_name(
- object->pose, bone_name);
+ if (GS(to_node->id_orig->name) == ID_OB) {
+ Object *object = (Object *)to_node->id_orig;
+ // NOTE: object->pose may be NULL
+ bPoseChannel *pchan = BKE_pose_channel_find_name(object->pose,
+ bone_name);
if (pchan != NULL) {
OperationKey bone_key(&object->id,
DEG_NODE_TYPE_BONE,
@@ -1103,6 +1187,26 @@ void DepsgraphRelationBuilder::build_driver_data(ID *id, FCurve *fcu)
}
else {
RNAPathKey target_key(id, rna_path);
+ add_relation(driver_key, target_key, "Driver -> Target");
+ /* Similar to the case with f-curves, driver might drive a nested
+ * datablock, which means driver execution should wait for that
+ * datablock to be copied.
+ */
+ if (DEG_depsgraph_use_copy_on_write()) {
+ PointerRNA id_ptr;
+ PointerRNA ptr;
+ RNA_id_pointer_create(id, &id_ptr);
+ if (RNA_path_resolve_full(&id_ptr, fcu->rna_path, &ptr, NULL, NULL)) {
+ if (id_ptr.id.data != ptr.id.data) {
+ ComponentKey cow_key((ID *)ptr.id.data,
+ DEG_NODE_TYPE_COPY_ON_WRITE);
+ add_relation(cow_key,
+ driver_key,
+ "Target CoW -> Driver",
+ true);
+ }
+ }
+ }
if (RNA_pointer_is_null(&target_key.ptr)) {
/* TODO(sergey): This would only mean that driver is broken.
* so we can't create relation anyway. However, we need to avoid
@@ -1144,6 +1248,7 @@ void DepsgraphRelationBuilder::build_driver_variables(ID *id, FCurve *fcu)
if (dtar->id == NULL) {
continue;
}
+ build_id(dtar->id);
/* Special handling for directly-named bones. */
if ((dtar->flag & DTAR_FLAG_STRUCT_REF) &&
(((Object *)dtar->id)->type == OB_ARMATURE) &&
@@ -1217,14 +1322,13 @@ void DepsgraphRelationBuilder::build_world(World *world)
}
build_animdata(&world->id);
/* TODO: other settings? */
- /* textures */
- build_texture_stack(world->mtex);
/* world's nodetree */
if (world->nodetree != NULL) {
build_nodetree(world->nodetree);
- ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
- ComponentKey world_key(&world->id, DEG_NODE_TYPE_PARAMETERS);
- add_relation(ntree_key, world_key, "NTree->World Parameters");
+ ComponentKey ntree_key(&world->nodetree->id, DEG_NODE_TYPE_SHADING);
+ ComponentKey world_key(&world->id, DEG_NODE_TYPE_SHADING);
+ add_relation(ntree_key, world_key, "NTree->World Shading Update");
+ build_nested_nodetree(&world->id, world->nodetree);
}
}
@@ -1246,8 +1350,8 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
/* objects - simulation participants */
if (rbw->group) {
- LISTBASE_FOREACH (GroupObject *, go, &rbw->group->gobject) {
- Object *object = go->ob;
+ LISTBASE_FOREACH (Base *, base, &rbw->group->view_layer->object_bases) {
+ Object *object = base->object;
if (object == NULL || object->type != OB_MESH) {
continue;
}
@@ -1300,8 +1404,8 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene *scene)
/* constraints */
if (rbw->constraints) {
- LISTBASE_FOREACH (GroupObject *, go, &rbw->constraints->gobject) {
- Object *object = go->ob;
+ LISTBASE_FOREACH (Base *, base, &rbw->constraints->view_layer->object_bases) {
+ Object *object = base->object;
if (object == NULL || !object->rigidbody_constraint) {
continue;
}
@@ -1338,13 +1442,24 @@ void DepsgraphRelationBuilder::build_particles(Object *object)
/* Particle systems. */
LISTBASE_FOREACH (ParticleSystem *, psys, &object->particlesystem) {
ParticleSettings *part = psys->part;
- /* Animation of particle settings, */
- build_animdata(&part->id);
+
+ /* Build particle settings relations.
+ *
+ * NOTE: The call itself ensures settings are only build once.
+ */
+ build_particle_settings(part);
+
/* This particle system. */
OperationKey psys_key(&object->id,
DEG_NODE_TYPE_EVAL_PARTICLES,
DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
psys->name);
+
+ /* Update particle system when settings changes. */
+ OperationKey particle_settings_key(&part->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ DEG_OPCODE_PARTICLE_SETTINGS_EVAL);
+ add_relation(particle_settings_key, eval_init_key, "Particle Settings Change");
add_relation(eval_init_key, psys_key, "Init -> PSys");
/* TODO(sergey): Currently particle update is just a placeholder,
* hook it to the ubereval node so particle system is getting updated
@@ -1357,18 +1472,17 @@ void DepsgraphRelationBuilder::build_particles(Object *object)
scene_,
object,
part->collision_group,
- object->lay,
true,
"Particle Collision");
}
else if ((psys->flag & PSYS_HAIR_DYNAMICS) &&
- psys->clmd && psys->clmd->coll_parms)
+ psys->clmd != NULL &&
+ psys->clmd->coll_parms != NULL)
{
add_collision_relations(psys_key,
scene_,
object,
psys->clmd->coll_parms->group,
- object->lay | scene_->lay,
true,
"Hair Collision");
}
@@ -1380,7 +1494,7 @@ void DepsgraphRelationBuilder::build_particles(Object *object)
part->effector_weights,
part->type == PART_HAIR,
"Particle Field");
- /* Boids. */
+ /* Boids .*/
if (part->boids) {
LISTBASE_FOREACH (BoidState *, state, &part->boids->states) {
LISTBASE_FOREACH (BoidRule *, rule, &state->rules) {
@@ -1399,12 +1513,11 @@ void DepsgraphRelationBuilder::build_particles(Object *object)
}
}
}
-
switch (part->ren_as) {
case PART_DRAW_OB:
if (part->dup_ob != NULL) {
/* Make sure object's relations are all built. */
- build_object(part->dup_ob);
+ build_object(NULL, part->dup_ob);
/* Build relation for the particle visualization. */
build_particles_visualization_object(object,
psys,
@@ -1433,8 +1546,20 @@ void DepsgraphRelationBuilder::build_particles(Object *object)
ComponentKey transform_key(&object->id, DEG_NODE_TYPE_TRANSFORM);
add_relation(transform_key, obdata_ubereval_key, "Partcile Eval");
- /* pointcache */
- // TODO...
+ OperationKey point_cache_reset_key(&object->id,
+ DEG_NODE_TYPE_CACHE,
+ DEG_OPCODE_POINT_CACHE_RESET);
+ add_relation(transform_key, point_cache_reset_key, "Object Transform -> Point Cache Reset");
+ add_relation(point_cache_reset_key, obdata_ubereval_key, "Point Cache Reset -> UberEval");
+}
+
+void DepsgraphRelationBuilder::build_particle_settings(ParticleSettings *part)
+{
+ if (built_map_.checkIsBuiltAndTag(part)) {
+ return;
+ }
+ /* Animation data relations. */
+ build_animdata(&part->id);
}
void DepsgraphRelationBuilder::build_particles_visualization_object(
@@ -1530,11 +1655,22 @@ void DepsgraphRelationBuilder::build_obdata_geom(Object *object)
/* link components to each other */
add_relation(obdata_geom_key, geom_key, "Object Geometry Base Data");
+ OperationKey obdata_ubereval_key(&object->id,
+ DEG_NODE_TYPE_GEOMETRY,
+ DEG_OPCODE_GEOMETRY_UBEREVAL);
+
+ /* Special case: modifiers and DerivedMesh creation queries scene for various
+ * things like data mask to be used. We add relation here to ensure object is
+ * never evaluated prior to Scene's CoW is ready.
+ */
+ OperationKey scene_key(&scene_->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ DEG_OPCODE_PLACEHOLDER,
+ "Scene Eval");
+ add_relation(scene_key, obdata_ubereval_key, "CoW Relation");
+
/* Modifiers */
if (object->modifiers.first != NULL) {
- OperationKey obdata_ubereval_key(&object->id,
- DEG_NODE_TYPE_GEOMETRY,
- DEG_OPCODE_GEOMETRY_UBEREVAL);
ModifierUpdateDepsgraphContext ctx = {};
ctx.scene = scene_;
ctx.object = object;
@@ -1562,6 +1698,14 @@ void DepsgraphRelationBuilder::build_obdata_geom(Object *object)
Material *ma = give_current_material(object, a);
if (ma != NULL) {
build_material(ma);
+
+ if (object->type == OB_MESH) {
+ OperationKey material_key(&ma->id,
+ DEG_NODE_TYPE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ OperationKey shading_key(&object->id, DEG_NODE_TYPE_SHADING, DEG_OPCODE_SHADING);
+ add_relation(material_key, shading_key, "Material Update");
+ }
}
}
}
@@ -1639,18 +1783,18 @@ void DepsgraphRelationBuilder::build_obdata_geom(Object *object)
// XXX: these needs geom data, but where is geom stored?
if (cu->bevobj) {
ComponentKey bevob_key(&cu->bevobj->id, DEG_NODE_TYPE_GEOMETRY);
- build_object(cu->bevobj);
+ build_object(NULL, cu->bevobj);
add_relation(bevob_key, geom_key, "Curve Bevel");
}
if (cu->taperobj) {
ComponentKey taperob_key(&cu->taperobj->id, DEG_NODE_TYPE_GEOMETRY);
- build_object(cu->taperobj);
+ build_object(NULL, cu->taperobj);
add_relation(taperob_key, geom_key, "Curve Taper");
}
if (object->type == OB_FONT) {
if (cu->textoncurve) {
ComponentKey textoncurve_key(&cu->textoncurve->id, DEG_NODE_TYPE_GEOMETRY);
- build_object(cu->textoncurve);
+ build_object(NULL, cu->textoncurve);
add_relation(textoncurve_key, geom_key, "Text on Curve");
}
}
@@ -1683,11 +1827,17 @@ void DepsgraphRelationBuilder::build_camera(Object *object)
if (built_map_.checkIsBuiltAndTag(camera)) {
return;
}
+
+ ComponentKey object_parameters_key(&object->id, DEG_NODE_TYPE_PARAMETERS);
+ ComponentKey camera_parameters_key(&camera->id, DEG_NODE_TYPE_PARAMETERS);
+
+ add_relation(camera_parameters_key, object_parameters_key,
+ "Camera -> Object");
+
/* DOF */
- if (camera->dof_ob) {
- ComponentKey ob_param_key(&object->id, DEG_NODE_TYPE_PARAMETERS);
+ if (camera->dof_ob != NULL) {
ComponentKey dof_ob_key(&camera->dof_ob->id, DEG_NODE_TYPE_TRANSFORM);
- add_relation(dof_ob_key, ob_param_key, "Camera DOF");
+ add_relation(dof_ob_key, object_parameters_key, "Camera DOF");
}
}
@@ -1698,15 +1848,33 @@ void DepsgraphRelationBuilder::build_lamp(Object *object)
if (built_map_.checkIsBuiltAndTag(lamp)) {
return;
}
+
+ ComponentKey object_parameters_key(&object->id, DEG_NODE_TYPE_PARAMETERS);
+ ComponentKey lamp_parameters_key(&lamp->id, DEG_NODE_TYPE_PARAMETERS);
+
+ add_relation(lamp_parameters_key, object_parameters_key,
+ "Lamp -> Object");
+
/* lamp's nodetree */
if (lamp->nodetree != NULL) {
build_nodetree(lamp->nodetree);
- ComponentKey parameters_key(&lamp->id, DEG_NODE_TYPE_PARAMETERS);
- ComponentKey nodetree_key(&lamp->nodetree->id, DEG_NODE_TYPE_PARAMETERS);
- add_relation(nodetree_key, parameters_key, "NTree->Lamp Parameters");
+ ComponentKey nodetree_key(&lamp->nodetree->id, DEG_NODE_TYPE_SHADING);
+ add_relation(nodetree_key, lamp_parameters_key, "NTree->Lamp Parameters");
+ build_nested_nodetree(&lamp->id, lamp->nodetree);
+ }
+
+ if (DEG_depsgraph_use_copy_on_write()) {
+ /* Make sure copy on write of lamp data is always properly updated for
+ * visible lamps.
+ */
+ OperationKey ob_copy_on_write_key(&object->id,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ OperationKey lamp_copy_on_write_key(&lamp->id,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ add_relation(lamp_copy_on_write_key, ob_copy_on_write_key, "Eval Order");
}
- /* textures */
- build_texture_stack(lamp->mtex);
}
void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
@@ -1718,9 +1886,7 @@ void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
return;
}
build_animdata(&ntree->id);
- OperationKey parameters_key(&ntree->id,
- DEG_NODE_TYPE_PARAMETERS,
- DEG_OPCODE_PARAMETERS_EVAL);
+ ComponentKey shading_key(&ntree->id, DEG_NODE_TYPE_SHADING);
/* nodetree's nodes... */
LISTBASE_FOREACH (bNode *, bnode, &ntree->nodes) {
ID *id = bnode->id;
@@ -1738,7 +1904,7 @@ void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
/* nothing for now. */
}
else if (id_type == ID_OB) {
- build_object((Object *)id);
+ build_object(NULL, (Object *)id);
}
else if (id_type == ID_SCE) {
/* Scenes are used by compositor trees, and handled by render
@@ -1751,15 +1917,27 @@ void DepsgraphRelationBuilder::build_nodetree(bNodeTree *ntree)
else if (bnode->type == NODE_GROUP) {
bNodeTree *group_ntree = (bNodeTree *)id;
build_nodetree(group_ntree);
- OperationKey group_parameters_key(&group_ntree->id,
- DEG_NODE_TYPE_PARAMETERS,
- DEG_OPCODE_PARAMETERS_EVAL);
- add_relation(group_parameters_key, parameters_key, "Group Node");
+ ComponentKey group_shading_key(&group_ntree->id,
+ DEG_NODE_TYPE_SHADING);
+ add_relation(group_shading_key, shading_key, "Group Node");
}
else {
BLI_assert(!"Unknown ID type used for node");
}
}
+
+ OperationKey shading_update_key(&ntree->id,
+ DEG_NODE_TYPE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ OperationKey shading_parameters_key(&ntree->id,
+ DEG_NODE_TYPE_SHADING_PARAMETERS,
+ DEG_OPCODE_MATERIAL_UPDATE);
+ add_relation(shading_parameters_key, shading_update_key, "NTree Shading Parameters");
+
+ if (check_id_has_anim_component(&ntree->id)) {
+ ComponentKey animation_key(&ntree->id, DEG_NODE_TYPE_ANIMATION);
+ add_relation(shading_parameters_key, animation_key, "NTree Shading Parameters");
+ }
}
/* Recursively build graph for material */
@@ -1770,19 +1948,17 @@ void DepsgraphRelationBuilder::build_material(Material *material)
}
/* animation */
build_animdata(&material->id);
- /* textures */
- build_texture_stack(material->mtex);
/* material's nodetree */
if (material->nodetree != NULL) {
build_nodetree(material->nodetree);
OperationKey ntree_key(&material->nodetree->id,
- DEG_NODE_TYPE_PARAMETERS,
- DEG_OPCODE_PARAMETERS_EVAL);
+ DEG_NODE_TYPE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE);
OperationKey material_key(&material->id,
DEG_NODE_TYPE_SHADING,
- DEG_OPCODE_PLACEHOLDER,
- "Material Update");
+ DEG_OPCODE_MATERIAL_UPDATE);
add_relation(ntree_key, material_key, "Material's NTree");
+ build_nested_nodetree(&material->id, material->nodetree);
}
}
@@ -1796,17 +1972,7 @@ void DepsgraphRelationBuilder::build_texture(Tex *texture)
build_animdata(&texture->id);
/* texture's nodetree */
build_nodetree(texture->nodetree);
-}
-
-/* Texture-stack attached to some shading datablock */
-void DepsgraphRelationBuilder::build_texture_stack(MTex **texture_stack)
-{
- /* for now assume that all texture-stacks have same number of max items */
- for (int i = 0; i < MAX_MTEX; i++) {
- MTex *mtex = texture_stack[i];
- if (mtex && mtex->tex)
- build_texture(mtex->tex);
- }
+ build_nested_nodetree(&texture->id, texture->nodetree);
}
void DepsgraphRelationBuilder::build_compositor(Scene *scene)
@@ -1817,6 +1983,9 @@ void DepsgraphRelationBuilder::build_compositor(Scene *scene)
void DepsgraphRelationBuilder::build_gpencil(bGPdata *gpd)
{
+ if (built_map_.checkIsBuiltAndTag(gpd)) {
+ return;
+ }
/* animation */
build_animdata(&gpd->id);
@@ -1825,12 +1994,18 @@ void DepsgraphRelationBuilder::build_gpencil(bGPdata *gpd)
void DepsgraphRelationBuilder::build_cachefile(CacheFile *cache_file)
{
+ if (built_map_.checkIsBuiltAndTag(cache_file)) {
+ return;
+ }
/* Animation. */
build_animdata(&cache_file->id);
}
void DepsgraphRelationBuilder::build_mask(Mask *mask)
{
+ if (built_map_.checkIsBuiltAndTag(mask)) {
+ return;
+ }
ID *mask_id = &mask->id;
/* F-Curve animation. */
build_animdata(mask_id);
@@ -1847,10 +2022,164 @@ void DepsgraphRelationBuilder::build_mask(Mask *mask)
void DepsgraphRelationBuilder::build_movieclip(MovieClip *clip)
{
+ if (built_map_.checkIsBuiltAndTag(clip)) {
+ return;
+ }
/* Animation. */
build_animdata(&clip->id);
}
+void DepsgraphRelationBuilder::build_lightprobe(Object *object)
+{
+ LightProbe *probe = (LightProbe *)object->data;
+ if (built_map_.checkIsBuiltAndTag(probe)) {
+ return;
+ }
+ build_animdata(&probe->id);
+
+ OperationKey probe_key(&probe->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ DEG_OPCODE_PLACEHOLDER,
+ "LightProbe Eval");
+ OperationKey object_key(&object->id,
+ DEG_NODE_TYPE_PARAMETERS,
+ DEG_OPCODE_PLACEHOLDER,
+ "LightProbe Eval");
+ add_relation(probe_key, object_key, "LightProbe Update");
+}
+
+void DepsgraphRelationBuilder::build_copy_on_write_relations()
+{
+ foreach (IDDepsNode *id_node, graph_->id_nodes) {
+ build_copy_on_write_relations(id_node);
+ }
+}
+
+/* Nested datablocks (node trees, shape keys) requires special relation to
+ * ensure owner's datablock remapping happens after node tree itself is ready.
+ *
+ * This is similar to what happens in ntree_hack_remap_pointers().
+ */
+void DepsgraphRelationBuilder::build_nested_datablock(ID *owner, ID *id) {
+ if (!DEG_depsgraph_use_copy_on_write()) {
+ return;
+ }
+ OperationKey owner_copy_on_write_key(owner,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ OperationKey id_copy_on_write_key(id,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ add_relation(id_copy_on_write_key,
+ owner_copy_on_write_key,
+ "Eval Order");
+}
+
+void DepsgraphRelationBuilder::build_nested_nodetree(ID *owner,
+ bNodeTree *ntree)
+{
+ if (ntree == NULL) {
+ return;
+ }
+ build_nested_datablock(owner, &ntree->id);
+}
+
+void DepsgraphRelationBuilder::build_nested_shapekey(ID *owner, Key *key)
+{
+ if (key == NULL) {
+ return;
+ }
+ build_nested_datablock(owner, &key->id);
+}
+
+void DepsgraphRelationBuilder::build_copy_on_write_relations(IDDepsNode *id_node)
+{
+ ID *id_orig = id_node->id_orig;
+
+ TimeSourceKey time_source_key;
+ OperationKey copy_on_write_key(id_orig,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ /* XXX: This is a quick hack to make Alt-A to work. */
+ // add_relation(time_source_key, copy_on_write_key, "Fluxgate capacitor hack");
+ /* Resat of code is using rather low level trickery, so need to get some
+ * explicit pointers.
+ */
+ DepsNode *node_cow = find_node(copy_on_write_key);
+ OperationDepsNode *op_cow = node_cow->get_exit_operation();
+ /* Plug any other components to this one. */
+ GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, id_node->components)
+ {
+ if (comp_node->type == DEG_NODE_TYPE_COPY_ON_WRITE) {
+ /* Copy-on-write component never depends on itself. */
+ continue;
+ }
+ if (!comp_node->depends_on_cow()) {
+ /* Component explicitly requests to not add relation. */
+ continue;
+ }
+ /* All entry operations of each component should wait for a proper
+ * copy of ID.
+ */
+ OperationDepsNode *op_entry = comp_node->get_entry_operation();
+ if (op_entry != NULL) {
+ graph_->add_new_relation(op_cow, op_entry, "CoW Dependency");
+ }
+ /* All dangling operations should also be executed after copy-on-write. */
+ GHASH_FOREACH_BEGIN(OperationDepsNode *, op_node, comp_node->operations_map)
+ {
+ if (op_node == op_entry) {
+ continue;
+ }
+ if (op_node->inlinks.size() == 0) {
+ graph_->add_new_relation(op_cow, op_node, "CoW Dependency");
+ }
+ else {
+ bool has_same_comp_dependency = false;
+ foreach (DepsRelation *rel, op_node->inlinks) {
+ if (rel->from->type != DEG_NODE_TYPE_OPERATION) {
+ continue;
+ }
+ OperationDepsNode *op_node_from = (OperationDepsNode *)rel->from;
+ if (op_node_from->owner == op_node->owner) {
+ has_same_comp_dependency = true;
+ break;
+ }
+ }
+ if (!has_same_comp_dependency) {
+ graph_->add_new_relation(op_cow, op_node, "CoW Dependency");
+ }
+ }
+ }
+ GHASH_FOREACH_END();
+ /* NOTE: We currently ignore implicit relations to an external
+ * datablocks for copy-on-write operations. This means, for example,
+ * copy-on-write component of Object will not wait for copy-on-write
+ * component of it's Mesh. This is because pointers are all known
+ * already so remapping will happen all correct. And then If some object
+ * evaluation step needs geometry, it will have transitive dependency
+ * to Mesh copy-on-write already.
+ */
+ }
+ GHASH_FOREACH_END();
+ /* TODO(sergey): This solves crash for now, but causes too many
+ * updates potentially.
+ */
+ if (GS(id_orig->name) == ID_OB) {
+ Object *object = (Object *)id_orig;
+ ID *object_data_id = (ID *)object->data;
+ if (object_data_id != NULL) {
+ OperationKey data_copy_on_write_key(object_data_id,
+ DEG_NODE_TYPE_COPY_ON_WRITE,
+ DEG_OPCODE_COPY_ON_WRITE);
+ add_relation(data_copy_on_write_key, copy_on_write_key, "Eval Order");
+ }
+ else {
+ BLI_assert(object->type == OB_EMPTY);
+ }
+ }
+}
+
/* **** ID traversal callbacks functions **** */
void DepsgraphRelationBuilder::modifier_walk(void *user_data,
@@ -1865,7 +2194,7 @@ void DepsgraphRelationBuilder::modifier_walk(void *user_data,
}
switch (GS(id->name)) {
case ID_OB:
- data->builder->build_object((Object *)id);
+ data->builder->build_object(NULL, (Object *)id);
break;
case ID_TE:
data->builder->build_texture((Tex *)id);
@@ -1885,7 +2214,7 @@ void DepsgraphRelationBuilder::constraint_walk(bConstraint * /*con*/,
if (*idpoin) {
ID *id = *idpoin;
if (GS(id->name) == ID_OB) {
- data->builder->build_object((Object *)id);
+ data->builder->build_object(NULL, (Object *)id);
}
}
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.h b/source/blender/depsgraph/intern/builder/deg_builder_relations.h
index 4a8e91f18db..9e45d01fd79 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.h
@@ -57,6 +57,7 @@ struct ID;
struct FCurve;
struct Group;
struct Key;
+struct LayerCollection;
struct Main;
struct Mask;
struct Material;
@@ -68,7 +69,9 @@ struct Object;
struct bPoseChannel;
struct bConstraint;
struct ParticleSystem;
+struct ParticleSettings;
struct Scene;
+struct ViewLayer;
struct Tex;
struct World;
struct EffectorWeights;
@@ -191,9 +194,11 @@ struct DepsgraphRelationBuilder
const char *description,
bool check_unique = false);
- void build_scene(Scene *scene);
+ void build_id(ID* id);
+ void build_view_layer(Scene *scene, ViewLayer *view_layer);
void build_group(Object *object, Group *group);
- void build_object(Object *object);
+ void build_object(Base *base, Object *object);
+ void build_object_flags(Base *base, Object *object);
void build_object_data(Object *object);
void build_object_parent(Object *object);
void build_constraints(ID *id,
@@ -218,6 +223,7 @@ struct DepsgraphRelationBuilder
void build_world(World *world);
void build_rigidbody(Scene *scene);
void build_particles(Object *object);
+ void build_particle_settings(ParticleSettings *part);
void build_particles_visualization_object(Object *object,
ParticleSystem *psys,
Object *draw_object);
@@ -239,18 +245,21 @@ struct DepsgraphRelationBuilder
void build_nodetree(bNodeTree *ntree);
void build_material(Material *ma);
void build_texture(Tex *tex);
- void build_texture_stack(MTex **texture_stack);
void build_compositor(Scene *scene);
void build_gpencil(bGPdata *gpd);
void build_cachefile(CacheFile *cache_file);
void build_mask(Mask *mask);
void build_movieclip(MovieClip *clip);
+ void build_lightprobe(Object *object);
+
+ void build_nested_datablock(ID *owner, ID *id);
+ void build_nested_nodetree(ID *owner, bNodeTree *ntree);
+ void build_nested_shapekey(ID *owner, Key *key);
void add_collision_relations(const OperationKey &key,
Scene *scene,
Object *object,
Group *group,
- int layer,
bool dupli,
const char *name);
void add_forcefield_relations(const OperationKey &key,
@@ -258,8 +267,10 @@ struct DepsgraphRelationBuilder
Object *object,
ParticleSystem *psys,
EffectorWeights *eff,
- bool add_absorption,
- const char *name);
+ bool add_absorption, const char *name);
+
+ void build_copy_on_write_relations();
+ void build_copy_on_write_relations(IDDepsNode *id_node);
template <typename KeyType>
OperationDepsNode *find_operation_node(const KeyType &key);
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_impl.h b/source/blender/depsgraph/intern/builder/deg_builder_relations_impl.h
index 570227601db..894d4172c00 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_impl.h
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_impl.h
@@ -184,7 +184,7 @@ bool DepsgraphRelationBuilder::is_same_nodetree_node_dependency(
return false;
}
/* Check if this is actually a node tree. */
- if (GS(op_from->owner->owner->id->name) != ID_NT) {
+ if (GS(op_from->owner->owner->id_orig->name) != ID_NT) {
return false;
}
/* Different node trees. */
@@ -217,7 +217,7 @@ bool DepsgraphRelationBuilder::is_same_shapekey_dependency(
return false;
}
/* Check if this is actually a shape key datablock. */
- if (GS(op_from->owner->owner->id->name) != ID_KE) {
+ if (GS(op_from->owner->owner->id_orig->name) != ID_KE) {
return false;
}
/* Different key data blocks. */
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc
index 4b8e4faae3f..a965d890496 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_keys.cc
@@ -179,7 +179,7 @@ string OperationKey::identifier() const
return string("OperationKey(") +
"t: " + typebuf +
", cn: '" + component_name +
- "', c: " + DEG_OPNAMES[opcode] +
+ "', c: " + operationCodeAsString(opcode) +
", n: '" + name + "')";
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
index 43df6d2a94b..a9895eb3af1 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_rig.cc
@@ -176,7 +176,8 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *object,
}
}
- DEG_DEBUG_PRINTF(BUILD, "\nStarting IK Build: pchan = %s, target = (%s, %s), segcount = %d\n",
+ DEG_DEBUG_PRINTF((::Depsgraph *)graph_,
+ BUILD, "\nStarting IK Build: pchan = %s, target = (%s, %s), segcount = %d\n",
pchan->name, data->tar->id.name, data->subtarget, data->rootbone);
bPoseChannel *parchan = pchan;
@@ -219,7 +220,7 @@ void DepsgraphRelationBuilder::build_ik_pose(Object *object,
root_map->add_bone(parchan->name, rootchan->name);
/* continue up chain, until we reach target number of items... */
- DEG_DEBUG_PRINTF(BUILD, " %d = %s\n", segcount, parchan->name);
+ DEG_DEBUG_PRINTF((::Depsgraph *)graph_, BUILD, " %d = %s\n", segcount, parchan->name);
segcount++;
if ((segcount == data->rootbone) || (segcount > 255)) break; /* 255 is weak */
@@ -387,16 +388,12 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
OperationKey bone_pose_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_POSE_PARENT);
OperationKey bone_ready_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_READY);
OperationKey bone_done_key(&object->id, DEG_NODE_TYPE_BONE, pchan->name, DEG_OPCODE_BONE_DONE);
-
pchan->flag &= ~POSE_DONE;
-
- /* pose init to bone local */
+ /* Pose init to bone local. */
add_relation(init_key, bone_local_key, "PoseEval Source-Bone Link");
-
- /* local to pose parenting operation */
+ /* Local to pose parenting operation. */
add_relation(bone_local_key, bone_pose_key, "Bone Local - PoseSpace Link");
-
- /* parent relation */
+ /* Parent relation. */
if (pchan->parent != NULL) {
eDepsOperation_Code parent_key_opcode;
@@ -411,8 +408,7 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
OperationKey parent_key(&object->id, DEG_NODE_TYPE_BONE, pchan->parent->name, parent_key_opcode);
add_relation(parent_key, bone_pose_key, "Parent Bone -> Child Bone");
}
-
- /* constraints */
+ /* Buil constraints. */
if (pchan->constraints.first != NULL) {
/* Build relations for indirectly linked objects. */
BuilderWalkUserData data;
@@ -447,7 +443,7 @@ void DepsgraphRelationBuilder::build_rig(Object *object)
/* Custom shape. */
if (pchan->custom != NULL) {
- build_object(pchan->custom);
+ build_object(NULL, pchan->custom);
}
}
}
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc
deleted file mode 100644
index c51addbd206..00000000000
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations_scene.cc
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2013 Blender Foundation.
- * All rights reserved.
- *
- * Original Author: Joshua Leung
- * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/depsgraph/intern/builder/deg_builder_relations_scene.cc
- * \ingroup depsgraph
- *
- * Methods for constructing depsgraph
- */
-
-#include "intern/builder/deg_builder_relations.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <cstring> /* required for STREQ later on. */
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_blenlib.h"
-
-extern "C" {
-#include "DNA_node_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-
-#include "BKE_main.h"
-#include "BKE_node.h"
-} /* extern "C" */
-
-#include "DEG_depsgraph.h"
-#include "DEG_depsgraph_build.h"
-
-#include "intern/builder/deg_builder.h"
-#include "intern/builder/deg_builder_pchanmap.h"
-
-#include "intern/nodes/deg_node.h"
-#include "intern/nodes/deg_node_component.h"
-#include "intern/nodes/deg_node_id.h"
-#include "intern/nodes/deg_node_operation.h"
-
-#include "intern/depsgraph_intern.h"
-#include "intern/depsgraph_types.h"
-
-#include "util/deg_util_foreach.h"
-
-namespace DEG {
-
-void DepsgraphRelationBuilder::build_scene(Scene *scene)
-{
- if (scene->set != NULL) {
- build_scene(scene->set);
- }
- /* Setup currently building context. */
- scene_ = scene;
- /* Scene objects. */
- LISTBASE_FOREACH (Base *, base, &scene->base) {
- Object *object = base->object;
- build_object(object);
- }
- /* Rigidbody. */
- if (scene->rigidbody_world != NULL) {
- build_rigidbody(scene);
- }
- /* Scene's animation and drivers. */
- if (scene->adt != NULL) {
- build_animdata(&scene->id);
- }
- /* World. */
- if (scene->world != NULL) {
- build_world(scene->world);
- }
- /* Compositor nodes. */
- if (scene->nodetree != NULL) {
- build_compositor(scene);
- }
- /* Grease pencil. */
- if (scene->gpd != NULL) {
- build_gpencil(scene->gpd);
- }
- /* Masks. */
- LISTBASE_FOREACH (Mask *, mask, &bmain_->mask) {
- build_mask(mask);
- }
- /* Movie clips. */
- LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
- build_movieclip(clip);
- }
- for (Depsgraph::OperationNodes::const_iterator it_op = graph_->operations.begin();
- it_op != graph_->operations.end();
- ++it_op)
- {
- OperationDepsNode *node = *it_op;
- IDDepsNode *id_node = node->owner->owner;
- ID *id = id_node->id;
- if (GS(id->name) == ID_OB) {
- Object *object = (Object *)id;
- object->customdata_mask |= node->customdata_mask;
- }
- }
-}
-
-} // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
new file mode 100644
index 00000000000..99295a733fc
--- /dev/null
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
@@ -0,0 +1,131 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2013 Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Joshua Leung
+ * Contributor(s): Based on original depsgraph.c code - Blender Foundation (2005-2013)
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/depsgraph/intern/builder/deg_builder_relations_view_layer.cc
+ * \ingroup depsgraph
+ *
+ * Methods for constructing depsgraph
+ */
+
+#include "intern/builder/deg_builder_relations.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <cstring> /* required for STREQ later on. */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_blenlib.h"
+
+extern "C" {
+#include "DNA_node_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "BKE_layer.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+} /* extern "C" */
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
+#include "intern/builder/deg_builder.h"
+#include "intern/builder/deg_builder_pchanmap.h"
+
+#include "intern/nodes/deg_node.h"
+#include "intern/nodes/deg_node_component.h"
+#include "intern/nodes/deg_node_id.h"
+#include "intern/nodes/deg_node_operation.h"
+
+#include "intern/depsgraph_intern.h"
+#include "intern/depsgraph_types.h"
+
+#include "util/deg_util_foreach.h"
+
+namespace DEG {
+
+void DepsgraphRelationBuilder::build_view_layer(Scene *scene, ViewLayer *view_layer)
+{
+ /* Setup currently building context. */
+ scene_ = scene;
+ /* Scene objects. */
+ /* NOTE: Nodes builder requires us to pass CoW base because it's being
+ * passed to the evaluation functions. During relations builder we only
+ * do NULL-pointer check of the base, so it's fine to pass original one.
+ */
+ LISTBASE_FOREACH (Base *, base, &view_layer->object_bases) {
+ build_object(base, base->object);
+ }
+ if (scene->camera != NULL) {
+ build_object(NULL, scene->camera);
+ }
+ /* Rigidbody. */
+ if (scene->rigidbody_world != NULL) {
+ build_rigidbody(scene);
+ }
+ /* Scene's animation and drivers. */
+ if (scene->adt != NULL) {
+ build_animdata(&scene->id);
+ }
+ /* World. */
+ if (scene->world != NULL) {
+ build_world(scene->world);
+ }
+ /* Compositor nodes. */
+ if (scene->nodetree != NULL) {
+ build_compositor(scene);
+ }
+ /* Grease pencil. */
+ if (scene->gpd != NULL) {
+ build_gpencil(scene->gpd);
+ }
+ /* Masks. */
+ LISTBASE_FOREACH (Mask *, mask, &bmain_->mask) {
+ build_mask(mask);
+ }
+ /* Movie clips. */
+ LISTBASE_FOREACH (MovieClip *, clip, &bmain_->movieclip) {
+ build_movieclip(clip);
+ }
+ /* TODO(sergey): Do this flush on CoW object? */
+ foreach (OperationDepsNode *node, graph_->operations) {
+ IDDepsNode *id_node = node->owner->owner;
+ ID *id = id_node->id_orig;
+ if (GS(id->name) == ID_OB) {
+ Object *object = (Object *)id;
+ object->customdata_mask |= node->customdata_mask;
+ }
+ }
+ /* Build all set scenes. */
+ if (scene->set != NULL) {
+ ViewLayer *set_view_layer = BKE_view_layer_default_render(scene->set);
+ build_view_layer(scene->set, set_view_layer);
+ }
+}
+
+} // namespace DEG
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
index 12760cad73c..17e64c5f685 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_transitive.cc
@@ -117,7 +117,7 @@ void deg_graph_transitive_reduction(Depsgraph *graph)
}
}
}
- DEG_DEBUG_PRINTF(BUILD, "Removed %d relations\n", num_removed_relations);
+ DEG_DEBUG_PRINTF((::Depsgraph *)graph, BUILD, "Removed %d relations\n", num_removed_relations);
}
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
index 80772f9595f..d64ab79d918 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
@@ -81,18 +81,21 @@ static const char *deg_debug_colors_light[] = {
#ifdef COLOR_SCHEME_NODE_TYPE
static const int deg_debug_node_type_color_map[][2] = {
{DEG_NODE_TYPE_TIMESOURCE, 0},
- {DEG_NODE_TYPE_ID_REF, 2},
+ {DEG_NODE_TYPE_ID_REF, 1},
/* Outer Types */
- {DEG_NODE_TYPE_PARAMETERS, 2},
- {DEG_NODE_TYPE_PROXY, 3},
- {DEG_NODE_TYPE_ANIMATION, 4},
- {DEG_NODE_TYPE_TRANSFORM, 5},
- {DEG_NODE_TYPE_GEOMETRY, 6},
- {DEG_NODE_TYPE_SEQUENCER, 7},
- {DEG_NODE_TYPE_SHADING, 8},
- {DEG_NODE_TYPE_CACHE, 9},
- {-1, 0}
+ {DEG_NODE_TYPE_PARAMETERS, 2},
+ {DEG_NODE_TYPE_PROXY, 3},
+ {DEG_NODE_TYPE_ANIMATION, 4},
+ {DEG_NODE_TYPE_TRANSFORM, 5},
+ {DEG_NODE_TYPE_GEOMETRY, 6},
+ {DEG_NODE_TYPE_SEQUENCER, 7},
+ {DEG_NODE_TYPE_SHADING, 8},
+ {DEG_NODE_TYPE_SHADING_PARAMETERS, 9},
+ {DEG_NODE_TYPE_CACHE, 10},
+ {DEG_NODE_TYPE_LAYER_COLLECTIONS, 11},
+ {DEG_NODE_TYPE_COPY_ON_WRITE, 12},
+ {-1, 0}
};
#endif
@@ -297,12 +300,6 @@ static void deg_debug_graphviz_node_single(const DebugContext &ctx,
{
const char *shape = "box";
string name = node->identifier();
- if (node->type == DEG_NODE_TYPE_ID_REF) {
- IDDepsNode *id_node = (IDDepsNode *)node;
- char buf[256];
- BLI_snprintf(buf, sizeof(buf), " (Layers: %u)", id_node->layers);
- name += buf;
- }
deg_debug_fprintf(ctx, "// %s\n", name.c_str());
deg_debug_fprintf(ctx, "\"node_%p\"", node);
deg_debug_fprintf(ctx, "[");
@@ -323,12 +320,6 @@ static void deg_debug_graphviz_node_cluster_begin(const DebugContext &ctx,
const DepsNode *node)
{
string name = node->identifier();
- if (node->type == DEG_NODE_TYPE_ID_REF) {
- IDDepsNode *id_node = (IDDepsNode *)node;
- char buf[256];
- BLI_snprintf(buf, sizeof(buf), " (Layers: %u)", id_node->layers);
- name += buf;
- }
deg_debug_fprintf(ctx, "// %s\n", name.c_str());
deg_debug_fprintf(ctx, "subgraph \"cluster_%p\" {" NL, node);
// deg_debug_fprintf(ctx, "label=<<B>%s</B>>;" NL, name);
@@ -390,8 +381,12 @@ static void deg_debug_graphviz_node(const DebugContext &ctx,
case DEG_NODE_TYPE_EVAL_POSE:
case DEG_NODE_TYPE_BONE:
case DEG_NODE_TYPE_SHADING:
+ case DEG_NODE_TYPE_SHADING_PARAMETERS:
case DEG_NODE_TYPE_CACHE:
+ case DEG_NODE_TYPE_LAYER_COLLECTIONS:
case DEG_NODE_TYPE_EVAL_PARTICLES:
+ case DEG_NODE_TYPE_COPY_ON_WRITE:
+ case DEG_NODE_TYPE_BATCH_CACHE:
{
ComponentDepsNode *comp_node = (ComponentDepsNode *)node;
if (!comp_node->operations.empty()) {
@@ -406,9 +401,13 @@ static void deg_debug_graphviz_node(const DebugContext &ctx,
}
break;
}
- default:
+ case DEG_NODE_TYPE_UNDEFINED:
+ case DEG_NODE_TYPE_TIMESOURCE:
+ case DEG_NODE_TYPE_OPERATION:
deg_debug_graphviz_node_single(ctx, node);
break;
+ case NUM_DEG_NODE_TYPES:
+ break;
}
}
diff --git a/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc b/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc
index e92c7730482..35888f8d5e3 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc
@@ -110,7 +110,7 @@ void write_stats_data(const DebugContext& ctx)
deg_debug_fprintf(ctx, "$data << EOD" NL);
foreach (const StatsEntry& entry, stats) {
deg_debug_fprintf(ctx, "\"%s\",%f" NL,
- entry.id_node->id->name + 2,
+ entry.id_node->id_orig->name + 2,
entry.time);
}
deg_debug_fprintf(ctx, "EOD" NL);
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index 34fb20ee2ba..f25be922db9 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -48,15 +48,18 @@ extern "C" {
#include "DNA_object_types.h"
#include "DNA_sequence_types.h"
-#include "BKE_depsgraph.h"
-
#include "RNA_access.h"
+
+#include "BKE_scene.h"
}
#include <algorithm>
#include <cstring>
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_debug.h"
+
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node.h"
#include "intern/nodes/deg_node_component.h"
@@ -67,11 +70,22 @@ extern "C" {
#include "intern/depsgraph_intern.h"
#include "util/deg_util_foreach.h"
+static bool use_copy_on_write = false;
+
+bool DEG_depsgraph_use_copy_on_write(void)
+{
+ return use_copy_on_write;
+}
+
+void DEG_depsgraph_enable_copy_on_write(void)
+{
+ use_copy_on_write = true;
+}
+
namespace DEG {
static DEG_EditorUpdateIDCb deg_editor_update_id_cb = NULL;
static DEG_EditorUpdateSceneCb deg_editor_update_scene_cb = NULL;
-static DEG_EditorUpdateScenePreCb deg_editor_update_scene_pre_cb = NULL;
/* TODO(sergey): Find a better place for this. */
template <typename T>
@@ -81,14 +95,21 @@ static void remove_from_vector(vector<T> *vector, const T& value)
vector->end());
}
-Depsgraph::Depsgraph()
+Depsgraph::Depsgraph(Scene *scene,
+ ViewLayer *view_layer,
+ eEvaluationMode mode)
: time_source(NULL),
- need_update(false),
- layers(0)
+ need_update(true),
+ scene(scene),
+ view_layer(view_layer),
+ mode(mode),
+ ctime(BKE_scene_frame_get(scene)),
+ scene_cow(NULL)
{
BLI_spin_init(&lock);
id_hash = BLI_ghash_ptr_new("Depsgraph id hash");
entry_tags = BLI_gset_ptr_new("Depsgraph entry_tags");
+ debug_flags = G.debug;
}
Depsgraph::~Depsgraph()
@@ -214,6 +235,10 @@ static bool pointer_to_component_node_criteria(
*subdata = seq->name; // xxx?
return true;
}
+ else if (RNA_struct_is_a(ptr->type, &RNA_NodeSocket)) {
+ *type = DEG_NODE_TYPE_SHADING;
+ return true;
+ }
else if (ptr->type == &RNA_Curve) {
*id = (ID *)ptr->id.data;
*type = DEG_NODE_TYPE_GEOMETRY;
@@ -274,12 +299,6 @@ DepsNode *Depsgraph::find_node_from_pointer(const PointerRNA *ptr,
/* Node Management ---------------------------- */
-static void id_node_deleter(void *value)
-{
- IDDepsNode *id_node = reinterpret_cast<IDDepsNode *>(value);
- OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
-}
-
TimeSourceDepsNode *Depsgraph::add_time_source()
{
if (time_source == NULL) {
@@ -299,13 +318,19 @@ IDDepsNode *Depsgraph::find_id_node(const ID *id) const
return reinterpret_cast<IDDepsNode *>(BLI_ghash_lookup(id_hash, id));
}
-IDDepsNode *Depsgraph::add_id_node(ID *id, const char *name)
+IDDepsNode *Depsgraph::add_id_node(ID *id, ID *id_cow_hint)
{
+ BLI_assert((id->tag & LIB_TAG_COPY_ON_WRITE) == 0);
IDDepsNode *id_node = find_id_node(id);
if (!id_node) {
DepsNodeFactory *factory = deg_type_get_factory(DEG_NODE_TYPE_ID_REF);
- id_node = (IDDepsNode *)factory->create_node(id, "", name);
- /* register */
+ id_node = (IDDepsNode *)factory->create_node(id, "", id->name);
+ id_node->init_copy_on_write(id_cow_hint);
+ /* Register node in ID hash.
+ *
+ * NOTE: We address ID nodes by the original ID pointer they are
+ * referencing to.
+ */
BLI_ghash_insert(id_hash, id, id_node);
id_nodes.push_back(id_node);
}
@@ -314,7 +339,30 @@ IDDepsNode *Depsgraph::add_id_node(ID *id, const char *name)
void Depsgraph::clear_id_nodes()
{
- BLI_ghash_clear(id_hash, NULL, id_node_deleter);
+ /* Free memory used by ID nodes. */
+ if (use_copy_on_write) {
+ /* Stupid workaround to ensure we free IDs in a proper order. */
+ foreach (IDDepsNode *id_node, id_nodes) {
+ if (id_node->id_cow == NULL) {
+ /* This means builder "stole" ownership of the copy-on-written
+ * datablock for her own dirty needs.
+ */
+ continue;
+ }
+ if (!deg_copy_on_write_is_expanded(id_node->id_cow)) {
+ continue;
+ }
+ const ID_Type id_type = GS(id_node->id_cow->name);
+ if (id_type != ID_PA) {
+ id_node->destroy();
+ }
+ }
+ }
+ foreach (IDDepsNode *id_node, id_nodes) {
+ OBJECT_GUARDED_DELETE(id_node, IDDepsNode);
+ }
+ /* Clear containers. */
+ BLI_ghash_clear(id_hash, NULL, NULL);
id_nodes.clear();
}
@@ -339,7 +387,7 @@ DepsRelation *Depsgraph::add_new_relation(OperationDepsNode *from,
if (comp_node->type == DEG_NODE_TYPE_GEOMETRY) {
IDDepsNode *id_to = to->owner->owner;
IDDepsNode *id_from = from->owner->owner;
- if (id_to != id_from && (id_to->id->recalc & ID_RECALC_ALL)) {
+ if (id_to != id_from && (id_to->id_orig->recalc & ID_RECALC_ALL)) {
if ((id_from->eval_flags & DAG_EVAL_NEED_CPU) == 0) {
id_from->tag_update(this);
id_from->eval_flags |= DAG_EVAL_NEED_CPU;
@@ -433,9 +481,9 @@ void DepsRelation::unlink()
void Depsgraph::add_entry_tag(OperationDepsNode *node)
{
/* Sanity check. */
- if (!node)
+ if (node == NULL) {
return;
-
+ }
/* Add to graph-level set of directly modified nodes to start searching from.
* NOTE: this is necessary since we have several thousand nodes to play with...
*/
@@ -451,17 +499,46 @@ void Depsgraph::clear_all_nodes()
}
}
-void deg_editors_id_update(Main *bmain, ID *id)
+ID *Depsgraph::get_cow_id(const ID *id_orig) const
+{
+ IDDepsNode *id_node = find_id_node(id_orig);
+ if (id_node == NULL) {
+ /* This function is used from places where we expect ID to be either
+ * already a copy-on-write version or have a corresponding copy-on-write
+ * version.
+ *
+ * We try to enforce that in debug builds, for for release we play a bit
+ * safer game here.
+ */
+ if ((id_orig->tag & LIB_TAG_COPY_ON_WRITE) == 0) {
+ /* TODO(sergey): This is nice sanity check to have, but it fails
+ * in following situations:
+ *
+ * - Material has link to texture, which is not needed by new
+ * shading system and hence can be ignored at construction.
+ * - Object or mesh has material at a slot which is not used (for
+ * example, object has material slot by materials are set to
+ * object data).
+ */
+ // BLI_assert(!"Request for non-existing copy-on-write ID");
+ }
+ return (ID *)id_orig;
+ }
+ return id_node->id_cow;
+}
+
+void deg_editors_id_update(const DEGEditorUpdateContext *update_ctx, ID *id)
{
if (deg_editor_update_id_cb != NULL) {
- deg_editor_update_id_cb(bmain, id);
+ deg_editor_update_id_cb(update_ctx, id);
}
}
-void deg_editors_scene_update(Main *bmain, Scene *scene, bool updated)
+void deg_editors_scene_update(const DEGEditorUpdateContext *update_ctx,
+ bool updated)
{
if (deg_editor_update_scene_cb != NULL) {
- deg_editor_update_scene_cb(bmain, scene, updated);
+ deg_editor_update_scene_cb(update_ctx, updated);
}
}
@@ -496,9 +573,14 @@ string deg_color_end(void)
/* Public Graph API */
/* Initialize a new Depsgraph */
-Depsgraph *DEG_graph_new()
-{
- DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph);
+Depsgraph *DEG_graph_new(Scene *scene,
+ ViewLayer *view_layer,
+ eEvaluationMode mode)
+{
+ DEG::Depsgraph *deg_depsgraph = OBJECT_GUARDED_NEW(DEG::Depsgraph,
+ scene,
+ view_layer,
+ mode);
return reinterpret_cast<Depsgraph *>(deg_depsgraph);
}
@@ -512,32 +594,40 @@ void DEG_graph_free(Depsgraph *graph)
/* Set callbacks which are being called when depsgraph changes. */
void DEG_editors_set_update_cb(DEG_EditorUpdateIDCb id_func,
- DEG_EditorUpdateSceneCb scene_func,
- DEG_EditorUpdateScenePreCb scene_pre_func)
+ DEG_EditorUpdateSceneCb scene_func)
{
DEG::deg_editor_update_id_cb = id_func;
DEG::deg_editor_update_scene_cb = scene_func;
- DEG::deg_editor_update_scene_pre_cb = scene_pre_func;
}
-void DEG_editors_update_pre(Main *bmain, Scene *scene, bool time)
+/* Evaluation and debug */
+
+static DEG::string depsgraph_name_for_logging(struct Depsgraph *depsgraph)
{
- if (DEG::deg_editor_update_scene_pre_cb != NULL) {
- DEG::deg_editor_update_scene_pre_cb(bmain, scene, time);
+ const char *name = DEG_debug_name_get(depsgraph);
+ if (name[0] == '\0') {
+ return "";
}
+ return "[" + DEG::string(name) + "]: ";
}
-/* Evaluation and debug */
+void DEG_debug_print_begin(struct Depsgraph *depsgraph)
+{
+ fprintf(stdout, "%s",
+ depsgraph_name_for_logging(depsgraph).c_str());
+}
-void DEG_debug_print_eval(const char *function_name,
+void DEG_debug_print_eval(struct Depsgraph *depsgraph,
+ const char *function_name,
const char *object_name,
const void *object_address)
{
- if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
+ if ((DEG_debug_flags_get(depsgraph) & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
return;
}
fprintf(stdout,
- "%s on %s %s(%p)%s\n",
+ "%s%s on %s %s(%p)%s\n",
+ depsgraph_name_for_logging(depsgraph).c_str(),
function_name,
object_name,
DEG::deg_color_for_pointer(object_address).c_str(),
@@ -546,18 +636,20 @@ void DEG_debug_print_eval(const char *function_name,
fflush(stdout);
}
-void DEG_debug_print_eval_subdata(const char *function_name,
+void DEG_debug_print_eval_subdata(struct Depsgraph *depsgraph,
+ const char *function_name,
const char *object_name,
const void *object_address,
const char *subdata_comment,
const char *subdata_name,
const void *subdata_address)
{
- if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
+ if ((DEG_debug_flags_get(depsgraph) & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
return;
}
fprintf(stdout,
- "%s on %s %s(%p)%s %s %s %s(%p)%s\n",
+ "%s%s on %s %s(%p)%s %s %s %s(%p)%s\n",
+ depsgraph_name_for_logging(depsgraph).c_str(),
function_name,
object_name,
DEG::deg_color_for_pointer(object_address).c_str(),
@@ -571,7 +663,8 @@ void DEG_debug_print_eval_subdata(const char *function_name,
fflush(stdout);
}
-void DEG_debug_print_eval_subdata_index(const char *function_name,
+void DEG_debug_print_eval_subdata_index(struct Depsgraph *depsgraph,
+ const char *function_name,
const char *object_name,
const void *object_address,
const char *subdata_comment,
@@ -579,11 +672,12 @@ void DEG_debug_print_eval_subdata_index(const char *function_name,
const void *subdata_address,
const int subdata_index)
{
- if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
+ if ((DEG_debug_flags_get(depsgraph) & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
return;
}
fprintf(stdout,
- "%s on %s %s(%p)^%s %s %s[%d] %s(%p)%s\n",
+ "%s%s on %s %s(%p)%s %s %s[%d] %s(%p)%s\n",
+ depsgraph_name_for_logging(depsgraph).c_str(),
function_name,
object_name,
DEG::deg_color_for_pointer(object_address).c_str(),
@@ -598,16 +692,49 @@ void DEG_debug_print_eval_subdata_index(const char *function_name,
fflush(stdout);
}
-void DEG_debug_print_eval_time(const char *function_name,
+void DEG_debug_print_eval_parent_typed(struct Depsgraph *depsgraph,
+ const char *function_name,
+ const char *object_name,
+ const void *object_address,
+ const char *object_type,
+ const char *parent_comment,
+ const char *parent_name,
+ const void *parent_address,
+ const char *parent_type)
+{
+ if ((DEG_debug_flags_get(depsgraph) & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
+ return;
+ }
+ fprintf(stdout,
+ "%s%s on %s %s(%p)%s [%s] %s %s %s(%p)%s %s\n",
+ depsgraph_name_for_logging(depsgraph).c_str(),
+ function_name,
+ object_name,
+ DEG::deg_color_for_pointer(object_address).c_str(),
+ object_address,
+ object_type,
+ DEG::deg_color_end().c_str(),
+ parent_comment,
+ parent_name,
+ DEG::deg_color_for_pointer(parent_address).c_str(),
+ parent_address,
+ DEG::deg_color_end().c_str(),
+ parent_type);
+ fflush(stdout);
+}
+
+void DEG_debug_print_eval_time(struct Depsgraph *depsgraph,
+ const char *function_name,
const char *object_name,
const void *object_address,
float time)
{
- if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
+ if ((DEG_debug_flags_get(depsgraph) & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
return;
}
fprintf(stdout,
- "%s on %s %s(%p)%s at time %f\n",
+ "%s%s on %s %s(%p)%s at time %f\n",
+ depsgraph_name_for_logging(depsgraph).c_str(),
function_name,
object_name,
DEG::deg_color_for_pointer(object_address).c_str(),
diff --git a/source/blender/depsgraph/intern/depsgraph.h b/source/blender/depsgraph/intern/depsgraph.h
index dda4da7bc13..7b6af9deee1 100644
--- a/source/blender/depsgraph/intern/depsgraph.h
+++ b/source/blender/depsgraph/intern/depsgraph.h
@@ -38,13 +38,18 @@
#include "BLI_threads.h" /* for SpinLock */
+#include "DEG_depsgraph.h"
+
#include "intern/depsgraph_types.h"
struct ID;
struct GHash;
+struct Main;
struct GSet;
struct PointerRNA;
struct PropertyRNA;
+struct Scene;
+struct ViewLayer;
namespace DEG {
@@ -96,14 +101,17 @@ struct Depsgraph {
typedef vector<OperationDepsNode *> OperationNodes;
typedef vector<IDDepsNode *> IDDepsNodes;
- Depsgraph();
+ Depsgraph(Scene *scene,
+ ViewLayer *view_layer,
+ eEvaluationMode mode);
~Depsgraph();
/**
* Convenience wrapper to find node given just pointer + property.
*
* \param ptr: pointer to the data that node will represent
- * \param prop: optional property affected - providing this effectively results in inner nodes being returned
+ * \param prop: optional property affected - providing this effectively
+ * results in inner nodes being returned
*
* \return A node matching the required characteristics if it exists
* or NULL if no such node exists in the graph
@@ -114,7 +122,7 @@ struct Depsgraph {
TimeSourceDepsNode *find_time_source() const;
IDDepsNode *find_id_node(const ID *id) const;
- IDDepsNode *add_id_node(ID *id, const char *name = "");
+ IDDepsNode *add_id_node(ID *id, ID *id_cow_hint = NULL);
void clear_id_nodes();
/* Add new relationship between two nodes. */
@@ -142,6 +150,11 @@ struct Depsgraph {
/* Clear storage used by all nodes. */
void clear_all_nodes();
+ /* Copy-on-Write Functionality ........ */
+
+ /* For given original ID get ID which is created by CoW system. */
+ ID *get_cow_id(const ID *id_orig) const;
+
/* Core Graph Functionality ........... */
/* <ID : IDDepsNode> mapping from ID blocks to nodes representing these
@@ -177,12 +190,22 @@ struct Depsgraph {
*/
SpinLock lock;
- /* Layers Visibility .................. */
+ /* Scene, layer, mode this dependency graph is built for. */
+ Scene *scene;
+ ViewLayer *view_layer;
+ eEvaluationMode mode;
- /* Visible layers bitfield, used for skipping invisible objects updates. */
- unsigned int layers;
+ /* Time at which dependency graph is being or was last evaluated. */
+ float ctime;
+
+ /* Evaluated version of datablocks we access a lot.
+ * Stored here to save us form doing hash lookup.
+ */
+ Scene *scene_cow;
- // XXX: additional stuff like eval contexts, mempools for allocating nodes from, etc.
+ /* NITE: Corresponds to G_DEBUG_DEPSGRAPH_* flags. */
+ int debug_flags;
+ string debug_name;
};
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/depsgraph_build.cc b/source/blender/depsgraph/intern/depsgraph_build.cc
index 1b270e71d64..18f1d6edbaf 100644
--- a/source/blender/depsgraph/intern/depsgraph_build.cc
+++ b/source/blender/depsgraph/intern/depsgraph_build.cc
@@ -34,6 +34,7 @@
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
+#include "BLI_listbase.h"
#include "PIL_time.h"
#include "PIL_time_utildefines.h"
@@ -48,6 +49,7 @@ extern "C" {
#include "BKE_collision.h"
#include "BKE_effect.h"
#include "BKE_modifier.h"
+#include "BKE_scene.h"
} /* extern "C" */
#include "DEG_depsgraph.h"
@@ -188,32 +190,50 @@ void DEG_add_special_eval_flag(Depsgraph *graph, ID *id, short flag)
/* ******************** */
/* Graph Building API's */
-/* Build depsgraph for the given scene, and dump results in given
+/* Build depsgraph for the given scene layer, and dump results in given
* graph container.
*/
-/* XXX: assume that this is called from outside, given the current scene as
- * the "main" scene.
- */
-void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
+void DEG_graph_build_from_view_layer(Depsgraph *graph,
+ Main *bmain,
+ Scene *scene,
+ ViewLayer *view_layer)
{
- double start_time;
+ double start_time = 0.0;
if (G.debug & G_DEBUG_DEPSGRAPH_BUILD) {
start_time = PIL_check_seconds_timer();
}
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
+ BLI_assert(BLI_findindex(&scene->view_layers, view_layer) != -1);
+
+ BLI_assert(deg_graph->scene == scene);
+ BLI_assert(deg_graph->view_layer == view_layer);
+
+ /* TODO(sergey): This is a bit tricky, but ensures that all the data
+ * is evaluated properly when depsgraph is becoming "visible".
+ *
+ * This now could happen for both visible scene is changed and extra
+ * dependency graph was created for render engine.
+ */
+ const bool need_on_visible_update = (deg_graph->id_nodes.size() == 0);
/* 1) Generate all the nodes in the graph first */
DEG::DepsgraphNodeBuilder node_builder(bmain, deg_graph);
node_builder.begin_build();
- node_builder.build_scene(scene);
+ node_builder.build_view_layer(scene,
+ view_layer,
+ DEG::DEG_ID_LINKED_DIRECTLY);
+ node_builder.end_build();
/* 2) Hook up relationships between operations - to determine evaluation
* order.
*/
DEG::DepsgraphRelationBuilder relation_builder(bmain, deg_graph);
relation_builder.begin_build();
- relation_builder.build_scene(scene);
+ relation_builder.build_view_layer(scene, view_layer);
+ if (DEG_depsgraph_use_copy_on_write()) {
+ relation_builder.build_copy_on_write_relations();
+ }
/* Detect and solve cycles. */
DEG::deg_graph_detect_cycles(deg_graph);
@@ -228,7 +248,7 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
}
/* 4) Flush visibility layer and re-schedule nodes for update. */
- DEG::deg_graph_build_finalize(deg_graph);
+ DEG::deg_graph_build_finalize(bmain, deg_graph);
#if 0
if (!DEG_debug_consistency_check(deg_graph)) {
@@ -237,6 +257,16 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
}
#endif
+ /* Relations are up to date. */
+ deg_graph->need_update = false;
+
+ /* Store pointers to commonly used valuated datablocks. */
+ deg_graph->scene_cow = (Scene *)deg_graph->get_cow_id(&deg_graph->scene->id);
+
+ if (need_on_visible_update) {
+ DEG_graph_on_visible_update(bmain, graph);
+ }
+
if (G.debug & G_DEBUG_DEPSGRAPH_BUILD) {
printf("Depsgraph built in %f seconds.\n",
PIL_check_seconds_timer() - start_time);
@@ -246,68 +276,52 @@ void DEG_graph_build_from_scene(Depsgraph *graph, Main *bmain, Scene *scene)
/* Tag graph relations for update. */
void DEG_graph_tag_relations_update(Depsgraph *graph)
{
+ DEG_DEBUG_PRINTF(graph, TAG, "%s: Tagging relations for update.\n", __func__);
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
deg_graph->need_update = true;
-}
-
-/* Tag all relations for update. */
-void DEG_relations_tag_update(Main *bmain)
-{
- for (Scene *scene = (Scene *)bmain->scene.first;
- scene != NULL;
- scene = (Scene *)scene->id.next)
+ /* NOTE: When relations are updated, it's quite possible that
+ * we've got new bases in the scene. This means, we need to
+ * re-create flat array of bases in view layer.
+ *
+ * TODO(sergey): Try to make it so we don't flush updates
+ * to the whole depsgraph.
+ */
{
- if (scene->depsgraph != NULL) {
- DEG_graph_tag_relations_update(scene->depsgraph);
+ DEG::IDDepsNode *id_node = deg_graph->find_id_node(&deg_graph->scene->id);
+ if (id_node != NULL) {
+ id_node->tag_update(deg_graph);
}
}
}
-/* Create new graph if didn't exist yet,
- * or update relations if graph was tagged for update.
- */
-void DEG_scene_relations_update(Main *bmain, Scene *scene)
+/* Create or update relations in the specified graph. */
+void DEG_graph_relations_update(Depsgraph *graph,
+ Main *bmain,
+ Scene *scene,
+ ViewLayer *view_layer)
{
- if (scene->depsgraph == NULL) {
- /* Rebuild graph from scratch and exit. */
- scene->depsgraph = DEG_graph_new();
- DEG_graph_build_from_scene(scene->depsgraph, bmain, scene);
- return;
- }
-
- DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph);
- if (!graph->need_update) {
+ DEG::Depsgraph *deg_graph = (DEG::Depsgraph *)graph;
+ if (!deg_graph->need_update) {
/* Graph is up to date, nothing to do. */
return;
}
-
- /* Clear all previous nodes and operations. */
- graph->clear_all_nodes();
- graph->operations.clear();
- BLI_gset_clear(graph->entry_tags, NULL);
-
- /* Build new nodes and relations. */
- DEG_graph_build_from_scene(reinterpret_cast< ::Depsgraph * >(graph),
- bmain,
- scene);
-
- graph->need_update = false;
+ DEG_graph_build_from_view_layer(graph, bmain, scene, view_layer);
}
-/* Rebuild dependency graph only for a given scene. */
-void DEG_scene_relations_rebuild(Main *bmain, Scene *scene)
-{
- if (scene->depsgraph != NULL) {
- DEG_graph_tag_relations_update(scene->depsgraph);
- }
- DEG_scene_relations_update(bmain, scene);
-}
-
-void DEG_scene_graph_free(Scene *scene)
+/* Tag all relations for update. */
+void DEG_relations_tag_update(Main *bmain)
{
- if (scene->depsgraph) {
- DEG_graph_free(scene->depsgraph);
- scene->depsgraph = NULL;
+ DEG_GLOBAL_DEBUG_PRINTF(TAG, "%s: Tagging relations for update.\n", __func__);
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scene) {
+ LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
+ Depsgraph *depsgraph =
+ (Depsgraph *)BKE_scene_get_depsgraph(scene,
+ view_layer,
+ false);
+ if (depsgraph != NULL) {
+ DEG_graph_tag_relations_update(depsgraph);
+ }
+ }
}
}
@@ -315,14 +329,13 @@ void DEG_add_collision_relations(DepsNodeHandle *handle,
Scene *scene,
Object *object,
Group *group,
- int layer,
unsigned int modifier_type,
DEG_CollobjFilterFunction fn,
bool dupli,
const char *name)
{
unsigned int numcollobj;
- Object **collobjs = get_collisionobjects_ext(scene, object, group, layer, &numcollobj, modifier_type, dupli);
+ Object **collobjs = get_collisionobjects_ext(scene, object, group, &numcollobj, modifier_type, dupli);
for (unsigned int i = 0; i < numcollobj; i++) {
Object *ob1 = collobjs[i];
@@ -345,7 +358,7 @@ void DEG_add_forcefield_relations(DepsNodeHandle *handle,
int skip_forcefield,
const char *name)
{
- ListBase *effectors = pdInitEffectors(scene, object, NULL, effector_weights, false);
+ ListBase *effectors = pdInitEffectors(NULL, scene, object, NULL, effector_weights, false);
if (effectors == NULL) {
return;
}
@@ -374,7 +387,6 @@ void DEG_add_forcefield_relations(DepsNodeHandle *handle,
scene,
object,
NULL,
- eff->ob->lay,
eModifierType_Collision,
NULL,
true,
diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc
index b7bf63e0cb0..f7adaafe5b3 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cc
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cc
@@ -37,16 +37,48 @@ extern "C" {
#include "DNA_scene_types.h"
} /* extern "C" */
+#include "DNA_object_types.h"
+
#include "DEG_depsgraph.h"
#include "DEG_depsgraph_debug.h"
#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
#include "intern/depsgraph_intern.h"
+#include "intern/depsgraph_types.h"
#include "intern/nodes/deg_node_id.h"
#include "intern/nodes/deg_node_time.h"
#include "util/deg_util_foreach.h"
+void DEG_debug_flags_set(Depsgraph *depsgraph, int flags)
+{
+ DEG::Depsgraph *deg_graph =
+ reinterpret_cast<DEG::Depsgraph *>(depsgraph);
+ deg_graph->debug_flags = flags;
+}
+
+int DEG_debug_flags_get(const Depsgraph *depsgraph)
+{
+ const DEG::Depsgraph *deg_graph =
+ reinterpret_cast<const DEG::Depsgraph *>(depsgraph);
+ return deg_graph->debug_flags;
+}
+
+void DEG_debug_name_set(struct Depsgraph *depsgraph, const char *name)
+{
+ DEG::Depsgraph *deg_graph =
+ reinterpret_cast<DEG::Depsgraph *>(depsgraph);
+ deg_graph->debug_name = name;
+}
+
+const char *DEG_debug_name_get(struct Depsgraph *depsgraph)
+{
+ const DEG::Depsgraph *deg_graph =
+ reinterpret_cast<const DEG::Depsgraph *>(depsgraph);
+ return deg_graph->debug_name.c_str();
+}
+
bool DEG_debug_compare(const struct Depsgraph *graph1,
const struct Depsgraph *graph2)
{
@@ -67,18 +99,20 @@ bool DEG_debug_compare(const struct Depsgraph *graph1,
return true;
}
-bool DEG_debug_scene_relations_validate(Main *bmain,
- Scene *scene)
+bool DEG_debug_graph_relations_validate(Depsgraph *graph,
+ Main *bmain,
+ Scene *scene,
+ ViewLayer *view_layer)
{
- Depsgraph *depsgraph = DEG_graph_new();
+ Depsgraph *temp_depsgraph = DEG_graph_new(scene, view_layer, DEG_get_mode(graph));
bool valid = true;
- DEG_graph_build_from_scene(depsgraph, bmain, scene);
- if (!DEG_debug_compare(depsgraph, scene->depsgraph)) {
+ DEG_graph_build_from_view_layer(temp_depsgraph, bmain, scene, view_layer);
+ if (!DEG_debug_compare(temp_depsgraph, graph)) {
fprintf(stderr, "ERROR! Depsgraph wasn't tagged for update when it should have!\n");
BLI_assert(!"This should not happen!");
valid = false;
}
- DEG_graph_free(depsgraph);
+ DEG_graph_free(temp_depsgraph);
return valid;
}
diff --git a/source/blender/depsgraph/intern/depsgraph_eval.cc b/source/blender/depsgraph/intern/depsgraph_eval.cc
index a6bdcdca19d..edb6600f3e0 100644
--- a/source/blender/depsgraph/intern/depsgraph_eval.cc
+++ b/source/blender/depsgraph/intern/depsgraph_eval.cc
@@ -32,17 +32,19 @@
#include "MEM_guardedalloc.h"
+#include "BLI_listbase.h"
#include "BLI_utildefines.h"
#include "BLI_ghash.h"
extern "C" {
-#include "DNA_scene_types.h"
-
-#include "BKE_depsgraph.h"
#include "BKE_scene.h"
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
} /* extern "C" */
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "intern/eval/deg_eval.h"
#include "intern/eval/deg_eval_flush.h"
@@ -53,103 +55,31 @@ extern "C" {
#include "intern/depsgraph.h"
-#ifdef WITH_LEGACY_DEPSGRAPH
-static bool use_legacy_depsgraph = true;
-#endif
-
-bool DEG_depsgraph_use_legacy(void)
-{
-#ifdef DISABLE_NEW_DEPSGRAPH
- return true;
-#elif defined(WITH_LEGACY_DEPSGRAPH)
- return use_legacy_depsgraph;
-#else
- BLI_assert(!"Should not be used with new depsgraph");
- return false;
-#endif
-}
-
-void DEG_depsgraph_switch_to_legacy(void)
-{
-#ifdef WITH_LEGACY_DEPSGRAPH
- use_legacy_depsgraph = true;
-#else
- BLI_assert(!"Should not be used with new depsgraph");
-#endif
-}
-
-void DEG_depsgraph_switch_to_new(void)
-{
-#ifdef WITH_LEGACY_DEPSGRAPH
- use_legacy_depsgraph = false;
-#else
- BLI_assert(!"Should not be used with new depsgraph");
-#endif
-}
-
-/* ****************** */
-/* Evaluation Context */
-
-/* Create new evaluation context. */
-EvaluationContext *DEG_evaluation_context_new(int mode)
-{
- EvaluationContext *eval_ctx =
- (EvaluationContext *)MEM_callocN(sizeof(EvaluationContext),
- "EvaluationContext");
- eval_ctx->mode = mode;
- return eval_ctx;
-}
-
-/**
- * Initialize evaluation context.
- * Used by the areas which currently overrides the context or doesn't have
- * access to a proper one.
- */
-void DEG_evaluation_context_init(EvaluationContext *eval_ctx, int mode)
-{
- eval_ctx->mode = mode;
-}
-
-/* Free evaluation context. */
-void DEG_evaluation_context_free(EvaluationContext *eval_ctx)
-{
- MEM_freeN(eval_ctx);
-}
-
/* Evaluate all nodes tagged for updating. */
-void DEG_evaluate_on_refresh(EvaluationContext *eval_ctx,
- Depsgraph *graph,
- Scene *scene)
+void DEG_evaluate_on_refresh(Depsgraph *graph)
{
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
+ deg_graph->ctime = BKE_scene_frame_get(deg_graph->scene);
/* Update time on primary timesource. */
DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
- tsrc->cfra = BKE_scene_frame_get(scene);
- unsigned int layers = deg_graph->layers;
- /* XXX(sergey): This works around missing updates in temp scenes used
- * by various scripts, but is weak and needs closer investigation.
- */
- if (layers == 0) {
- layers = scene->lay;
- }
- DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph, layers);
+ tsrc->cfra = deg_graph->ctime;
+ DEG::deg_evaluate_on_refresh(deg_graph);
}
/* Frame-change happened for root scene that graph belongs to. */
-void DEG_evaluate_on_framechange(EvaluationContext *eval_ctx,
- Main *bmain,
+void DEG_evaluate_on_framechange(Main *bmain,
Depsgraph *graph,
- float ctime,
- const unsigned int layers)
+ float ctime)
{
DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
+ deg_graph->ctime = ctime;
/* Update time on primary timesource. */
DEG::TimeSourceDepsNode *tsrc = deg_graph->find_time_source();
tsrc->cfra = ctime;
tsrc->tag_update(deg_graph);
DEG::deg_graph_flush_updates(bmain, deg_graph);
/* Perform recalculation updates. */
- DEG::deg_evaluate_on_refresh(eval_ctx, deg_graph, layers);
+ DEG::deg_evaluate_on_refresh(deg_graph);
}
bool DEG_needs_eval(Depsgraph *graph)
diff --git a/source/blender/depsgraph/intern/depsgraph_intern.h b/source/blender/depsgraph/intern/depsgraph_intern.h
index 89432e17f87..c048a7c1b93 100644
--- a/source/blender/depsgraph/intern/depsgraph_intern.h
+++ b/source/blender/depsgraph/intern/depsgraph_intern.h
@@ -46,8 +46,11 @@ extern "C" {
#include "intern/nodes/deg_node_operation.h"
#include "intern/depsgraph.h"
-struct Main;
+#include "DEG_depsgraph_debug.h"
+
+struct DEGEditorUpdateContext;
struct Group;
+struct Main;
struct Scene;
namespace DEG {
@@ -105,17 +108,33 @@ DepsNodeFactory *deg_type_get_factory(const eDepsNode_Type type);
/* Editors Integration -------------------------------------------------- */
-void deg_editors_id_update(struct Main *bmain, struct ID *id);
+void deg_editors_id_update(const DEGEditorUpdateContext *update_ctx,
+ struct ID *id);
-void deg_editors_scene_update(struct Main *bmain, struct Scene *scene, bool updated);
+void deg_editors_scene_update(const DEGEditorUpdateContext *update_ctx,
+ bool updated);
-#define DEG_DEBUG_PRINTF(type, ...) \
+#define DEG_DEBUG_PRINTF(depsgraph, type, ...) \
+ do { \
+ if (DEG_debug_flags_get(depsgraph) & G_DEBUG_DEPSGRAPH_ ## type) { \
+ DEG_debug_print_begin(depsgraph); \
+ fprintf(stdout, __VA_ARGS__); \
+ } \
+ } while (0)
+
+#define DEG_GLOBAL_DEBUG_PRINTF(type, ...) \
do { \
if (G.debug & G_DEBUG_DEPSGRAPH_ ## type) { \
- fprintf(stderr, __VA_ARGS__); \
+ fprintf(stdout, __VA_ARGS__); \
} \
} while (0)
+#define DEG_ERROR_PRINTF(...) \
+ do { \
+ fprintf(stderr, __VA_ARGS__); \
+ fflush(stderr); \
+ } while (0)
+
bool deg_terminal_do_color(void);
string deg_color_for_pointer(const void *pointer);
string deg_color_end(void);
diff --git a/source/blender/depsgraph/intern/depsgraph_query.cc b/source/blender/depsgraph/intern/depsgraph_query.cc
index 9b1961baa48..fea28736627 100644
--- a/source/blender/depsgraph/intern/depsgraph_query.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query.cc
@@ -33,21 +33,53 @@
#include "MEM_guardedalloc.h"
extern "C" {
+#include "BLI_utildefines.h"
#include "BKE_idcode.h"
#include "BKE_main.h"
+#include "BLI_listbase.h"
} /* extern "C" */
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "DEG_depsgraph.h"
#include "DEG_depsgraph_query.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/depsgraph_intern.h"
#include "intern/nodes/deg_node_id.h"
-bool DEG_id_type_tagged(Main *bmain, short idtype)
+struct Scene *DEG_get_input_scene(const Depsgraph *graph)
+{
+ const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+ return deg_graph->scene;
+}
+
+struct ViewLayer *DEG_get_input_view_layer(const Depsgraph *graph)
+{
+ const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+ return deg_graph->view_layer;
+}
+
+eEvaluationMode DEG_get_mode(const Depsgraph *graph)
{
- return bmain->id_tag_update[BKE_idcode_to_index(idtype)] != 0;
+ const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+ return deg_graph->mode;
}
-short DEG_get_eval_flags_for_id(Depsgraph *graph, ID *id)
+float DEG_get_ctime(const Depsgraph *graph)
+{
+ const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+ return deg_graph->ctime;
+}
+
+
+bool DEG_id_type_tagged(Main *bmain, short id_type)
+{
+ return bmain->id_tag_update[BKE_idcode_to_index(id_type)] != 0;
+}
+
+short DEG_get_eval_flags_for_id(const Depsgraph *graph, ID *id)
{
if (graph == NULL) {
/* Happens when converting objects to mesh from a python script
@@ -59,9 +91,8 @@ short DEG_get_eval_flags_for_id(Depsgraph *graph, ID *id)
return 0;
}
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
-
- DEG::IDDepsNode *id_node = deg_graph->find_id_node(id);
+ const DEG::Depsgraph *deg_graph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+ const DEG::IDDepsNode *id_node = deg_graph->find_id_node(id);
if (id_node == NULL) {
/* TODO(sergey): Does it mean we need to check set scene? */
return 0;
@@ -69,3 +100,71 @@ short DEG_get_eval_flags_for_id(Depsgraph *graph, ID *id)
return id_node->eval_flags;
}
+
+Scene *DEG_get_evaluated_scene(const Depsgraph *graph)
+{
+ const DEG::Depsgraph *deg_graph =
+ reinterpret_cast<const DEG::Depsgraph *>(graph);
+ Scene *scene_cow = deg_graph->scene_cow;
+ /* TODO(sergey): Shall we expand datablock here? Or is it OK to assume
+ * that calleer is OK with just a pointer in case scene is not up[dated
+ * yet?
+ */
+ BLI_assert(DEG::deg_copy_on_write_is_expanded(&scene_cow->id));
+ return scene_cow;
+}
+
+ViewLayer *DEG_get_evaluated_view_layer(const Depsgraph *graph)
+{
+ const DEG::Depsgraph *deg_graph =
+ reinterpret_cast<const DEG::Depsgraph *>(graph);
+ Scene *scene_cow = DEG_get_evaluated_scene(graph);
+ /* Do name-based lookup. */
+ /* TODO(sergey): Can this be optimized? */
+ ViewLayer *view_layer_orig = deg_graph->view_layer;
+ ViewLayer *view_layer_cow =
+ (ViewLayer *)BLI_findstring(&scene_cow->view_layers,
+ view_layer_orig->name,
+ offsetof(ViewLayer, name));
+ BLI_assert(view_layer_cow != NULL);
+ return view_layer_cow;
+}
+
+Object *DEG_get_evaluated_object(const Depsgraph *depsgraph, Object *object)
+{
+ return (Object *)DEG_get_evaluated_id(depsgraph, &object->id);
+}
+
+ID *DEG_get_evaluated_id(const Depsgraph *depsgraph, ID *id)
+{
+ if (id == NULL) {
+ return NULL;
+ }
+ /* TODO(sergey): This is a duplicate of Depsgraph::get_cow_id(),
+ * but here we never do assert, since we don't know nature of the
+ * incoming ID datablock.
+ */
+ const DEG::Depsgraph *deg_graph = (const DEG::Depsgraph *)depsgraph;
+ const DEG::IDDepsNode *id_node = deg_graph->find_id_node(id);
+ if (id_node == NULL) {
+ return id;
+ }
+ return id_node->id_cow;
+}
+
+Object *DEG_get_original_object(Object *object)
+{
+ return (Object *)DEG_get_original_id(&object->id);
+}
+
+ID *DEG_get_original_id(ID *id)
+{
+ if (id == NULL) {
+ return NULL;
+ }
+ if (id->orig_id == NULL) {
+ return id;
+ }
+ BLI_assert((id->tag & LIB_TAG_COPY_ON_WRITE) != 0);
+ return (ID *)id->orig_id;
+}
diff --git a/source/blender/depsgraph/intern/depsgraph_query_foreach.cc b/source/blender/depsgraph/intern/depsgraph_query_foreach.cc
index 65d8f58b851..b5ed3e38f09 100644
--- a/source/blender/depsgraph/intern/depsgraph_query_foreach.cc
+++ b/source/blender/depsgraph/intern/depsgraph_query_foreach.cc
@@ -108,7 +108,7 @@ static void deg_foreach_dependent_ID(const Depsgraph *graph,
IDDepsNode *id_node = comp_node->owner;
if (!id_node->done) {
/* TODO(sergey): Is it orig or CoW? */
- callback(id_node->id, user_data);
+ callback(id_node->id_orig, user_data);
id_node->done = true;
}
/* Schedule outgoing operation nodes. */
@@ -136,6 +136,14 @@ static void deg_foreach_dependent_ID(const Depsgraph *graph,
}
}
+static void deg_foreach_id(const Depsgraph *depsgraph,
+ DEGForeachIDCallback callback, void *user_data)
+{
+ foreach (const IDDepsNode *id_node, depsgraph->id_nodes) {
+ callback(id_node->id_orig, user_data);
+ }
+}
+
} // namespace DEG
void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
@@ -146,3 +154,9 @@ void DEG_foreach_dependent_ID(const Depsgraph *depsgraph,
id,
callback, user_data);
}
+
+void DEG_foreach_ID(const Depsgraph *depsgraph,
+ DEGForeachIDCallback callback, void *user_data)
+{
+ DEG::deg_foreach_id((const DEG::Depsgraph *)depsgraph, callback, user_data);
+}
diff --git a/source/blender/depsgraph/intern/depsgraph_query_iter.cc b/source/blender/depsgraph/intern/depsgraph_query_iter.cc
new file mode 100644
index 00000000000..0399882b659
--- /dev/null
+++ b/source/blender/depsgraph/intern/depsgraph_query_iter.cc
@@ -0,0 +1,282 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Dalai Felinto
+ * Contributor(s): Sergey Sharybin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/depsgraph/intern/depsgraph_query_iter.cc
+ * \ingroup depsgraph
+ *
+ * Implementation of Querying and Filtering API's
+ */
+
+/* Silence warnings from copying deprecated fields. */
+#define DNA_DEPRECATED_ALLOW
+
+#include "MEM_guardedalloc.h"
+
+extern "C" {
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+#include "BKE_anim.h"
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
+#include "BKE_object.h"
+} /* extern "C" */
+
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "intern/depsgraph_intern.h"
+#include "util/deg_util_foreach.h"
+
+#include "intern/nodes/deg_node_id.h"
+
+#ifndef NDEBUG
+# include "intern/eval/deg_eval_copy_on_write.h"
+#endif
+
+/* ************************ DEG ITERATORS ********************* */
+
+static void verify_id_proeprties_freed(DEGObjectIterData *data)
+{
+ if (data->dupli_object_current == NULL) {
+ // We didn't enter duplication yet, so we can't have any dangling
+ // pointers.
+ return;
+ }
+ const Object *dupli_object = data->dupli_object_current->ob;
+ Object *temp_dupli_object = &data->temp_dupli_object;
+ if (temp_dupli_object->id.properties == NULL) {
+ // No ID proeprties in temp datablock -- no leak is possible.
+ return;
+ }
+ if (temp_dupli_object->id.properties == dupli_object->id.properties) {
+ // Temp copy of object did not modify ID properties.
+ return;
+ }
+ // Free memory which is owned by temporary storage which is about to
+ // get overwritten.
+ IDP_FreeProperty(temp_dupli_object->id.properties);
+ MEM_freeN(temp_dupli_object->id.properties);
+ temp_dupli_object->id.properties = NULL;
+}
+
+static bool deg_objects_dupli_iterator_next(BLI_Iterator *iter)
+{
+ DEGObjectIterData *data = (DEGObjectIterData *)iter->data;
+ while (data->dupli_object_next != NULL) {
+ DupliObject *dob = data->dupli_object_next;
+ Object *obd = dob->ob;
+
+ data->dupli_object_next = data->dupli_object_next->next;
+
+ /* Group duplis need to set ob matrices correct, for deform. so no_draw
+ * is part handled.
+ */
+ if ((obd->transflag & OB_RENDER_DUPLI) == 0 && dob->no_draw) {
+ continue;
+ }
+
+ if (obd->type == OB_MBALL) {
+ continue;
+ }
+
+ verify_id_proeprties_freed(data);
+
+ data->dupli_object_current = dob;
+
+ /* Temporary object to evaluate. */
+ Object *dupli_parent = data->dupli_parent;
+ Object *temp_dupli_object = &data->temp_dupli_object;
+ *temp_dupli_object = *dob->ob;
+ temp_dupli_object->select_color = dupli_parent->select_color;
+ temp_dupli_object->base_flag = dupli_parent->base_flag | BASE_FROMDUPLI;
+
+ /* Duplicated elements shouldn't care whether their original collection is visible or not. */
+ temp_dupli_object->base_flag |= BASE_VISIBLED;
+
+ if (BKE_object_is_visible(temp_dupli_object, (eObjectVisibilityCheck)data->visibility_check) == false) {
+ continue;
+ }
+
+ temp_dupli_object->transflag &= ~OB_DUPLI;
+
+ if (dob->collection_properties != NULL) {
+ temp_dupli_object->base_collection_properties = dob->collection_properties;
+ IDP_MergeGroup(temp_dupli_object->base_collection_properties,
+ dupli_parent->base_collection_properties,
+ false);
+ }
+ else {
+ temp_dupli_object->base_collection_properties =
+ dupli_parent->base_collection_properties;
+ }
+
+ copy_m4_m4(data->temp_dupli_object.obmat, dob->mat);
+ iter->current = &data->temp_dupli_object;
+ BLI_assert(
+ DEG::deg_validate_copy_on_write_datablock(
+ &data->temp_dupli_object.id));
+ return true;
+ }
+
+ return false;
+}
+
+static void DEG_iterator_objects_step(BLI_Iterator *iter, DEG::IDDepsNode *id_node)
+{
+ /* Set it early in case we need to exit and we are running from within a loop. */
+ iter->skip = true;
+
+ DEGObjectIterData *data = (DEGObjectIterData *)iter->data;
+ const ID_Type id_type = GS(id_node->id_orig->name);
+
+ if (id_type != ID_OB) {
+ return;
+ }
+
+ switch (id_node->linked_state) {
+ case DEG::DEG_ID_LINKED_DIRECTLY:
+ if ((data->flag & DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY) == 0) {
+ return;
+ }
+ break;
+ case DEG::DEG_ID_LINKED_VIA_SET:
+ if ((data->flag & DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET) == 0) {
+ return;
+ }
+ break;
+ case DEG::DEG_ID_LINKED_INDIRECTLY:
+ if ((data->flag & DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY) == 0) {
+ return;
+ }
+ break;
+ }
+
+ Object *object = (Object *)id_node->id_cow;
+ BLI_assert(DEG::deg_validate_copy_on_write_datablock(&object->id));
+
+ if ((BKE_object_is_visible(object, OB_VISIBILITY_CHECK_UNKNOWN_RENDER_MODE) == false) &&
+ ((data->flag & DEG_ITER_OBJECT_FLAG_VISIBLE) != 0))
+ {
+ return;
+ }
+
+ if ((data->flag & DEG_ITER_OBJECT_FLAG_DUPLI) &&
+ (object->transflag & OB_DUPLI))
+ {
+ data->dupli_parent = object;
+ data->dupli_list = object_duplilist(data->graph, data->scene, object);
+ data->dupli_object_next = (DupliObject *)data->dupli_list->first;
+ if (BKE_object_is_visible(object, (eObjectVisibilityCheck)data->visibility_check) == false) {
+ return;
+ }
+ }
+
+ iter->current = object;
+ iter->skip = false;
+}
+
+void DEG_iterator_objects_begin(BLI_Iterator *iter, DEGObjectIterData *data)
+{
+ Depsgraph *depsgraph = data->graph;
+ DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
+ const size_t num_id_nodes = deg_graph->id_nodes.size();
+
+ if (num_id_nodes == 0) {
+ iter->data = NULL;
+ iter->valid = false;
+ return;
+ }
+
+ iter->data = data;
+ data->dupli_parent = NULL;
+ data->dupli_list = NULL;
+ data->dupli_object_next = NULL;
+ data->dupli_object_current = NULL;
+ data->scene = DEG_get_evaluated_scene(depsgraph);
+ data->id_node_index = 0;
+ data->num_id_nodes = num_id_nodes;
+ data->visibility_check = (data->mode == DEG_ITER_OBJECT_MODE_RENDER)
+ ? OB_VISIBILITY_CHECK_FOR_RENDER
+ : OB_VISIBILITY_CHECK_FOR_VIEWPORT;
+
+ DEG::IDDepsNode *id_node = deg_graph->id_nodes[data->id_node_index];
+ DEG_iterator_objects_step(iter, id_node);
+
+ if (iter->skip) {
+ DEG_iterator_objects_next(iter);
+ }
+}
+
+void DEG_iterator_objects_next(BLI_Iterator *iter)
+{
+ DEGObjectIterData *data = (DEGObjectIterData *)iter->data;
+ Depsgraph *depsgraph = data->graph;
+ DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(depsgraph);
+ do {
+ iter->skip = false;
+ if (data->dupli_list) {
+ if (deg_objects_dupli_iterator_next(iter)) {
+ return;
+ }
+ else {
+ verify_id_proeprties_freed(data);
+ free_object_duplilist(data->dupli_list);
+ data->dupli_parent = NULL;
+ data->dupli_list = NULL;
+ data->dupli_object_next = NULL;
+ data->dupli_object_current = NULL;
+ }
+ }
+
+ ++data->id_node_index;
+ if (data->id_node_index == data->num_id_nodes) {
+ iter->valid = false;
+ return;
+ }
+
+ DEG::IDDepsNode *id_node = deg_graph->id_nodes[data->id_node_index];
+ DEG_iterator_objects_step(iter, id_node);
+ } while (iter->skip);
+}
+
+void DEG_iterator_objects_end(BLI_Iterator *iter)
+{
+#ifndef NDEBUG
+ DEGObjectIterData *data = (DEGObjectIterData *)iter->data;
+
+ if (data) {
+ /* Force crash in case the iterator data is referenced and accessed down
+ * the line. (T51718)
+ */
+ memset(&data->temp_dupli_object, 0xff, sizeof(data->temp_dupli_object));
+ }
+#else
+ (void) iter;
+#endif
+}
diff --git a/source/blender/depsgraph/intern/depsgraph_tag.cc b/source/blender/depsgraph/intern/depsgraph_tag.cc
index 948e4fc1f1b..466e6053ef3 100644
--- a/source/blender/depsgraph/intern/depsgraph_tag.cc
+++ b/source/blender/depsgraph/intern/depsgraph_tag.cc
@@ -35,20 +35,26 @@
#include <queue>
#include "BLI_utildefines.h"
-#include "BLI_task.h"
#include "BLI_listbase.h"
+#include "BLI_math_bits.h"
+#include "BLI_task.h"
extern "C" {
+#include "DNA_curve_types.h"
+#include "DNA_key_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_particle_types.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
-
#include "BKE_idcode.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_node.h"
+#include "BKE_scene.h"
+#include "BKE_workspace.h"
#define new new_
#include "BKE_screen.h"
@@ -70,298 +76,548 @@ extern "C" {
/* *********************** */
/* Update Tagging/Flushing */
-/* Legacy depsgraph did some special trickery for things like particle systems
- * when tagging ID for an update. Ideally that tagging needs to become obsolete
- * in favor of havng dedicated node for that which gets tagged, but for until
- * design of those areas is more clear we'll do the same legacy code here.
- * - sergey -
- */
-#define DEPSGRAPH_USE_LEGACY_TAGGING
+namespace DEG {
namespace {
-/* Data-Based Tagging ------------------------------- */
-
-void lib_id_recalc_tag(Main *bmain, ID *id)
-{
- id->recalc |= ID_RECALC;
- DEG_id_type_tag(bmain, GS(id->name));
-}
+void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag);
-void lib_id_recalc_data_tag(Main *bmain, ID *id)
+void depsgraph_geometry_tag_to_component(const ID *id,
+ eDepsNode_Type *component_type)
{
- id->recalc |= ID_RECALC_DATA;
- DEG_id_type_tag(bmain, GS(id->name));
+ const ID_Type id_type = GS(id->name);
+ switch (id_type) {
+ case ID_OB:
+ {
+ const Object *object = (Object *)id;
+ switch (object->type) {
+ case OB_MESH:
+ case OB_CURVE:
+ case OB_SURF:
+ case OB_FONT:
+ case OB_LATTICE:
+ case OB_MBALL:
+ *component_type = DEG_NODE_TYPE_GEOMETRY;
+ break;
+ case OB_ARMATURE:
+ *component_type = DEG_NODE_TYPE_EVAL_POSE;
+ break;
+ /* TODO(sergey): More cases here? */
+ }
+ break;
+ }
+ case ID_ME:
+ *component_type = DEG_NODE_TYPE_GEOMETRY;
+ break;
+ case ID_PA:
+ return;
+ case ID_LP:
+ *component_type = DEG_NODE_TYPE_PARAMETERS;
+ break;
+ default:
+ break;
+ }
}
-void lib_id_recalc_tag_flag(Main *bmain, ID *id, int flag)
+void depsgraph_select_tag_to_component_opcode(
+ const ID *id,
+ eDepsNode_Type *component_type,
+ eDepsOperation_Code *operation_code)
{
- if (flag) {
- /* This bit of code ensures legacy object->recalc flags
- * are still filled in the same way as it was expected
- * with the old dependency graph.
- *
- * This is because some areas like motion paths and likely
- * some other physics baking process are doing manual scene
- * update on all the frames, trying to minimize number of
- * updates.
+ const ID_Type id_type = GS(id->name);
+ if (id_type == ID_SCE) {
+ /* We need to flush base flags to all objects in a scene since we
+ * don't know which ones changed. However, we don't want to update
+ * the whole scene, so pick up some operation which will do as less
+ * as possible.
*
- * But this flag will also let us to re-construct entry
- * nodes for update after relations update and after layer
- * visibility changes.
+ * TODO(sergey): We can introduce explicit exit operation which
+ * does nothing and which is only used to cascade flush down the
+ * road.
*/
- ID_Type idtype = GS(id->name);
- if (idtype == ID_OB) {
- Object *object = (Object *)id;
- object->recalc |= (flag & OB_RECALC_ALL);
- }
-
- if (flag & OB_RECALC_OB)
- lib_id_recalc_tag(bmain, id);
- if (flag & (OB_RECALC_DATA | PSYS_RECALC))
- lib_id_recalc_data_tag(bmain, id);
+ *component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;
+ *operation_code = DEG_OPCODE_VIEW_LAYER_EVAL;
+ }
+ else if (id_type == ID_OB) {
+ *component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;
+ *operation_code = DEG_OPCODE_OBJECT_BASE_FLAGS;
}
else {
- lib_id_recalc_tag(bmain, id);
+ *component_type = DEG_NODE_TYPE_BATCH_CACHE;
+ *operation_code = DEG_OPCODE_GEOMETRY_SELECT_UPDATE;
}
}
-#ifdef DEPSGRAPH_USE_LEGACY_TAGGING
-void depsgraph_legacy_handle_update_tag(Main *bmain, ID *id, short flag)
+void depsgraph_base_flags_tag_to_component_opcode(
+ const ID *id,
+ eDepsNode_Type *component_type,
+ eDepsOperation_Code *operation_code)
{
- if (flag) {
- Object *object;
- short idtype = GS(id->name);
- if (idtype == ID_PA) {
- ParticleSystem *psys;
- for (object = (Object *)bmain->object.first;
- object != NULL;
- object = (Object *)object->id.next)
- {
- for (psys = (ParticleSystem *)object->particlesystem.first;
- psys != NULL;
- psys = (ParticleSystem *)psys->next)
- {
- if (&psys->part->id == id) {
- DEG_id_tag_update_ex(bmain, &object->id, flag & OB_RECALC_ALL);
- psys->recalc |= (flag & PSYS_RECALC);
- }
- }
- }
- }
+ const ID_Type id_type = GS(id->name);
+ if (id_type == ID_SCE) {
+ *component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;
+ *operation_code = DEG_OPCODE_VIEW_LAYER_EVAL;
+ }
+ else if (id_type == ID_OB) {
+ *component_type = DEG_NODE_TYPE_LAYER_COLLECTIONS;
+ *operation_code = DEG_OPCODE_OBJECT_BASE_FLAGS;
}
}
-#endif
-} /* namespace */
+void depsgraph_tag_to_component_opcode(const ID *id,
+ eDepsgraph_Tag tag,
+ eDepsNode_Type *component_type,
+ eDepsOperation_Code *operation_code)
+{
+ const ID_Type id_type = GS(id->name);
+ *component_type = DEG_NODE_TYPE_UNDEFINED;
+ *operation_code = DEG_OPCODE_OPERATION;
+ /* Special case for now, in the future we should get rid of this. */
+ if (tag == 0) {
+ *component_type = DEG_NODE_TYPE_ID_REF;
+ *operation_code = DEG_OPCODE_OPERATION;
+ return;
+ }
+ switch (tag) {
+ case DEG_TAG_TRANSFORM:
+ *component_type = DEG_NODE_TYPE_TRANSFORM;
+ break;
+ case DEG_TAG_GEOMETRY:
+ depsgraph_geometry_tag_to_component(id, component_type);
+ break;
+ case DEG_TAG_TIME:
+ *component_type = DEG_NODE_TYPE_ANIMATION;
+ break;
+ case DEG_TAG_PSYS_REDO:
+ case DEG_TAG_PSYS_RESET:
+ case DEG_TAG_PSYS_TYPE:
+ case DEG_TAG_PSYS_CHILD:
+ case DEG_TAG_PSYS_PHYS:
+ if (id_type == ID_PA) {
+ /* NOTES:
+ * - For particle settings node we need to use different
+ * component. Will be nice to get this unified with object,
+ * but we can survive for now with single exception here.
+ * Particles needs reconsideration anyway,
+ */
+ *component_type = DEG_NODE_TYPE_PARAMETERS;
+ }
+ else {
+ *component_type = DEG_NODE_TYPE_EVAL_PARTICLES;
+ }
+ break;
+ case DEG_TAG_COPY_ON_WRITE:
+ *component_type = DEG_NODE_TYPE_COPY_ON_WRITE;
+ break;
+ case DEG_TAG_SHADING_UPDATE:
+ if (id_type == ID_NT) {
+ *component_type = DEG_NODE_TYPE_SHADING_PARAMETERS;
+ }
+ else {
+ *component_type = DEG_NODE_TYPE_SHADING;
+ }
+ break;
+ case DEG_TAG_SELECT_UPDATE:
+ depsgraph_select_tag_to_component_opcode(id,
+ component_type,
+ operation_code);
+ break;
+ case DEG_TAG_BASE_FLAGS_UPDATE:
+ depsgraph_base_flags_tag_to_component_opcode(id,
+ component_type,
+ operation_code);
+ case DEG_TAG_EDITORS_UPDATE:
+ /* There is no such node in depsgraph, this tag is to be handled
+ * separately.
+ */
+ break;
+ case DEG_TAG_PSYS_ALL:
+ BLI_assert(!"Should not happen");
+ break;
+ }
+}
-/* Tag all nodes in ID-block for update.
- * This is a crude measure, but is most convenient for old code.
- */
-void DEG_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id)
+void id_tag_update_ntree_special(Main *bmain, Depsgraph *graph, ID *id, int flag)
{
- DEG::Depsgraph *deg_graph = reinterpret_cast<DEG::Depsgraph *>(graph);
- DEG::IDDepsNode *node = deg_graph->find_id_node(id);
- lib_id_recalc_tag(bmain, id);
- if (node != NULL) {
- node->tag_update(deg_graph);
+ bNodeTree *ntree = ntreeFromID(id);
+ if (ntree == NULL) {
+ return;
}
+ deg_graph_id_tag_update(bmain, graph, &ntree->id, flag);
}
-/* Tag given ID for an update in all the dependency graphs. */
-void DEG_id_tag_update(ID *id, short flag)
+void depsgraph_update_editors_tag(Main *bmain, Depsgraph *graph, ID *id)
{
- DEG_id_tag_update_ex(G.main, id, flag);
+ /* NOTE: We handle this immediately, without delaying anything, to be
+ * sure we don't cause threading issues with OpenGL.
+ */
+ /* TODO(sergey): Make sure this works for CoW-ed datablocks as well. */
+ DEGEditorUpdateContext update_ctx = {NULL};
+ update_ctx.bmain = bmain;
+ update_ctx.depsgraph = (::Depsgraph *)graph;
+ update_ctx.scene = graph->scene;
+ update_ctx.view_layer = graph->view_layer;
+ deg_editors_id_update(&update_ctx, id);
}
-void DEG_id_tag_update_ex(Main *bmain, ID *id, short flag)
+void depsgraph_tag_component(Depsgraph *graph,
+ IDDepsNode *id_node,
+ eDepsNode_Type component_type,
+ eDepsOperation_Code operation_code)
{
- if (id == NULL) {
- /* Ideally should not happen, but old depsgraph allowed this. */
+ ComponentDepsNode *component_node =
+ id_node->find_component(component_type);
+ if (component_node == NULL) {
return;
}
- DEG_DEBUG_PRINTF(TAG, "%s: id=%s flag=%d\n", __func__, id->name, flag);
- lib_id_recalc_tag_flag(bmain, id, flag);
- for (Scene *scene = (Scene *)bmain->scene.first;
- scene != NULL;
- scene = (Scene *)scene->id.next)
- {
- if (scene->depsgraph) {
- Depsgraph *graph = scene->depsgraph;
- if (flag == 0) {
- /* TODO(sergey): Currently blender is still tagging IDs
- * for recalc just using flag=0. This isn't totally correct
- * but we'd better deal with such cases and don't fail.
- */
- DEG_graph_id_tag_update(bmain, graph, id);
- continue;
- }
- if (flag & OB_RECALC_DATA && GS(id->name) == ID_OB) {
+ if (operation_code == DEG_OPCODE_OPERATION) {
+ component_node->tag_update(graph);
+ }
+ else {
+ OperationDepsNode *operation_node =
+ component_node->find_operation(operation_code);
+ if (operation_node != NULL) {
+ operation_node->tag_update(graph);
+ }
+ }
+ /* If component depends on copy-on-write, tag it as well. */
+ if (DEG_depsgraph_use_copy_on_write() && component_node->depends_on_cow()) {
+ ComponentDepsNode *cow_comp =
+ id_node->find_component(DEG_NODE_TYPE_COPY_ON_WRITE);
+ cow_comp->tag_update(graph);
+ id_node->id_orig->recalc |= ID_RECALC_COPY_ON_WRITE;
+ }
+}
+
+/* This is a tag compatibility with legacy code.
+ *
+ * Mainly, old code was tagging object with OB_RECALC_DATA tag to inform
+ * that object's data datablock changed. Now API expects that ID is given
+ * explicitly, but not all areas are aware of this yet.
+ */
+void deg_graph_id_tag_legacy_compat(Main *bmain,
+ ID *id,
+ eDepsgraph_Tag tag)
+{
+ if (tag == DEG_TAG_GEOMETRY || tag == 0) {
+ switch (GS(id->name)) {
+ case ID_OB:
+ {
Object *object = (Object *)id;
- if (object->data != NULL) {
- DEG_graph_id_tag_update(bmain,
- graph,
- (ID *)object->data);
+ ID *data_id = (ID *)object->data;
+ if (data_id != NULL) {
+ DEG_id_tag_update_ex(bmain, data_id, 0);
}
+ break;
}
- if (flag & (OB_RECALC_OB | OB_RECALC_DATA)) {
- DEG_graph_id_tag_update(bmain, graph, id);
+ /* TODO(sergey): Shape keys are annoying, maybe we should find a
+ * way to chain geometry evaluation to them, so we don't need extra
+ * tagging here.
+ */
+ case ID_ME:
+ {
+ Mesh *mesh = (Mesh *)id;
+ ID *key_id = &mesh->key->id;
+ if (key_id != NULL) {
+ DEG_id_tag_update_ex(bmain, key_id, 0);
+ }
+ break;
}
- else if (flag & OB_RECALC_TIME) {
- DEG_graph_id_tag_update(bmain, graph, id);
+ case ID_LT:
+ {
+ Lattice *lattice = (Lattice *)id;
+ ID *key_id = &lattice->key->id;
+ if (key_id != NULL) {
+ DEG_id_tag_update_ex(bmain, key_id, 0);
+ }
+ break;
}
+ case ID_CU:
+ {
+ Curve *curve = (Curve *)id;
+ ID *key_id = &curve->key->id;
+ if (key_id != NULL) {
+ DEG_id_tag_update_ex(bmain, key_id, 0);
+ }
+ break;
+ }
+ default:
+ break;
}
}
-
-#ifdef DEPSGRAPH_USE_LEGACY_TAGGING
- /* Special handling from the legacy depsgraph.
- * TODO(sergey): Need to get rid of those once all the areas
- * are re-formulated in terms of franular nodes.
- */
- depsgraph_legacy_handle_update_tag(bmain, id, flag);
-#endif
}
-/* Mark a particular datablock type as having changing. */
-void DEG_id_type_tag(Main *bmain, short idtype)
+void deg_graph_id_tag_update_single_flag(Main *bmain,
+ Depsgraph *graph,
+ ID *id,
+ IDDepsNode *id_node,
+ eDepsgraph_Tag tag)
{
- if (idtype == ID_NT) {
- /* Stupid workaround so parent datablocks of nested nodetree get looped
- * over when we loop over tagged datablock types.
+ if (tag == DEG_TAG_EDITORS_UPDATE) {
+ if (graph != NULL) {
+ depsgraph_update_editors_tag(bmain, graph, id);
+ }
+ return;
+ }
+ /* Get description of what is to be tagged. */
+ eDepsNode_Type component_type;
+ eDepsOperation_Code operation_code;
+ depsgraph_tag_to_component_opcode(id,
+ tag,
+ &component_type,
+ &operation_code);
+ /* Check whether we've got something to tag. */
+ if (component_type == DEG_NODE_TYPE_UNDEFINED) {
+ /* Given ID does not support tag. */
+ /* TODO(sergey): Shall we raise some panic here? */
+ return;
+ }
+ /* Tag ID recalc flag. */
+ DepsNodeFactory *factory = deg_type_get_factory(component_type);
+ BLI_assert(factory != NULL);
+ id->recalc |= factory->id_recalc_tag();
+ /* NOTE: This way we clearly separate direct animation recalc flag from
+ * a flushed one. Needed for auto-keyframe hack feature.
+ *
+ * TODO(sergey): Find a more generic way to set/access direct tagged ID
+ * recalc flags.
+ */
+ if (tag == DEG_TAG_TIME) {
+ id->recalc |= ID_RECALC_TIME;
+ }
+ /* Some sanity checks before moving forward. */
+ if (id_node == NULL) {
+ /* Happens when object is tagged for update and not yet in the
+ * dependency graph (but will be after relations update).
*/
- DEG_id_type_tag(bmain, ID_MA);
- DEG_id_type_tag(bmain, ID_TE);
- DEG_id_type_tag(bmain, ID_LA);
- DEG_id_type_tag(bmain, ID_WO);
- DEG_id_type_tag(bmain, ID_SCE);
+ return;
+ }
+ /* Tag corresponding dependency graph operation for update. */
+ if (component_type == DEG_NODE_TYPE_ID_REF) {
+ id_node->tag_update(graph);
}
+ else {
+ depsgraph_tag_component(graph, id_node, component_type, operation_code);
+ }
+ /* TODO(sergey): Get rid of this once all areas are using proper data ID
+ * for tagging.
+ */
+ deg_graph_id_tag_legacy_compat(bmain, id, tag);
- bmain->id_tag_update[BKE_idcode_to_index(idtype)] = 1;
}
-/* Recursively push updates out to all nodes dependent on this,
- * until all affected are tagged and/or scheduled up for eval
- */
-void DEG_ids_flush_tagged(Main *bmain)
+string stringify_append_bit(const string& str, eDepsgraph_Tag tag)
{
- for (Scene *scene = (Scene *)bmain->scene.first;
- scene != NULL;
- scene = (Scene *)scene->id.next)
- {
- DEG_scene_flush_update(bmain, scene);
+ string result = str;
+ if (!result.empty()) {
+ result += ", ";
}
+ result += DEG_update_tag_as_string(tag);
+ return result;
}
-void DEG_scene_flush_update(Main *bmain, Scene *scene)
+string stringify_update_bitfield(int flag)
{
- if (scene->depsgraph == NULL) {
- return;
+ if (flag == 0) {
+ return "LEGACY_0";
+ }
+ string result = "";
+ int current_flag = flag;
+ /* Special cases to avoid ALL flags form being split into
+ * individual bits.
+ */
+ if ((current_flag & DEG_TAG_PSYS_ALL) == DEG_TAG_PSYS_ALL) {
+ result = stringify_append_bit(result, DEG_TAG_PSYS_ALL);
}
- DEG::deg_graph_flush_updates(
- bmain,
- reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph));
+ /* Handle all the rest of the flags. */
+ while (current_flag != 0) {
+ eDepsgraph_Tag tag =
+ (eDepsgraph_Tag)(1 << bitscan_forward_clear_i(&current_flag));
+ result = stringify_append_bit(result, tag);
+ }
+ return result;
}
-/* Update dependency graph when visible scenes/layers changes. */
-void DEG_graph_on_visible_update(Main *bmain, Scene *scene)
+void deg_graph_id_tag_update(Main *bmain, Depsgraph *graph, ID *id, int flag)
{
- DEG::Depsgraph *graph = reinterpret_cast<DEG::Depsgraph *>(scene->depsgraph);
- wmWindowManager *wm = (wmWindowManager *)bmain->wm.first;
- int old_layers = graph->layers;
- if (wm != NULL) {
- BKE_main_id_tag_listbase(&bmain->scene, LIB_TAG_DOIT, true);
- graph->layers = 0;
- for (wmWindow *win = (wmWindow *)wm->windows.first;
- win != NULL;
- win = (wmWindow *)win->next)
- {
- Scene *scene = win->screen->scene;
- if (scene->id.tag & LIB_TAG_DOIT) {
- graph->layers |= BKE_screen_visible_layers(win->screen, scene);
- scene->id.tag &= ~LIB_TAG_DOIT;
- }
+ const int debug_flags = (graph != NULL)
+ ? DEG_debug_flags_get((::Depsgraph *)graph)
+ : G.debug;
+ if (debug_flags & G_DEBUG_DEPSGRAPH_TAG) {
+ printf("%s: id=%s flags=%s\n",
+ __func__,
+ id->name,
+ stringify_update_bitfield(flag).c_str());
+ }
+ IDDepsNode *id_node = (graph != NULL) ? graph->find_id_node(id)
+ : NULL;
+ DEG_id_type_tag(bmain, GS(id->name));
+ if (flag == 0) {
+ /* TODO(sergey): Which recalc flags to set here? */
+ id->recalc |= ID_RECALC_ALL & ~DEG_TAG_PSYS_ALL;
+ if (id_node != NULL) {
+ id_node->tag_update(graph);
}
+ deg_graph_id_tag_legacy_compat(bmain, id, (eDepsgraph_Tag)0);
}
- else {
- /* All the layers for background render for now. */
- graph->layers = (1 << 20) - 1;
+ id->recalc |= (flag & PSYS_RECALC);
+ int current_flag = flag;
+ while (current_flag != 0) {
+ eDepsgraph_Tag tag =
+ (eDepsgraph_Tag)(1 << bitscan_forward_clear_i(&current_flag));
+ deg_graph_id_tag_update_single_flag(bmain,
+ graph,
+ id,
+ id_node,
+ tag);
+ }
+ /* Special case for nested node tree datablocks. */
+ id_tag_update_ntree_special(bmain, graph, id, flag);
+}
+
+void deg_id_tag_update(Main *bmain, ID *id, int flag)
+{
+ deg_graph_id_tag_update(bmain, NULL, id, flag);
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scene) {
+ LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
+ Depsgraph *depsgraph =
+ (Depsgraph *)BKE_scene_get_depsgraph(scene,
+ view_layer,
+ false);
+ if (depsgraph != NULL) {
+ deg_graph_id_tag_update(bmain, depsgraph, id, flag);
+ }
+ }
}
- if (old_layers != graph->layers) {
- /* Tag all objects which becomes visible (or which becomes needed for dependencies)
- * for recalc.
+}
+
+void deg_graph_on_visible_update(Main *bmain, Depsgraph *graph)
+{
+ /* Make sure objects are up to date. */
+ foreach (DEG::IDDepsNode *id_node, graph->id_nodes) {
+ const ID_Type id_type = GS(id_node->id_orig->name);
+ int flag = DEG_TAG_TIME | DEG_TAG_COPY_ON_WRITE;
+ /* We only tag components which needs an update. Tagging everything is
+ * not a good idea because that might reset particles cache (or any
+ * other type of cache).
*
- * This is mainly needed on file load only, after that updates of invisible objects
- * will be stored in the pending list.
+ * TODO(sergey): Need to generalize this somehow.
*/
- foreach (DEG::IDDepsNode *id_node, graph->id_nodes) {
- ID *id = id_node->id;
- if ((id->recalc & ID_RECALC_ALL) != 0 ||
- (id_node->layers & scene->lay_updated) == 0)
- {
- id_node->tag_update(graph);
- }
- /* A bit of magic: if object->recalc is set it means somebody tagged
- * it for update. If corresponding ID recalc flags are zero it means
- * graph has been evaluated after that and the recalc was skipped
- * because of visibility check.
- */
- if (GS(id->name) == ID_OB) {
- Object *object = (Object *)id;
- if ((id->recalc & ID_RECALC_ALL) == 0 &&
- (object->recalc & OB_RECALC_ALL) != 0)
- {
- id_node->tag_update(graph);
- DEG::ComponentDepsNode *anim_comp =
- id_node->find_component(DEG::DEG_NODE_TYPE_ANIMATION);
- if (anim_comp != NULL && object->recalc & OB_RECALC_TIME) {
- anim_comp->tag_update(graph);
- }
- }
- }
+ if (id_type == ID_OB) {
+ flag |= OB_RECALC_OB | OB_RECALC_DATA;
}
+ deg_graph_id_tag_update(bmain, graph, id_node->id_orig, flag);
}
- scene->lay_updated |= graph->layers;
- /* If graph is tagged for update, we don't need to bother with updates here,
- * nodes will be re-created.
- */
- if (graph->need_update) {
+ /* Make sure collection properties are up to date. */
+ for (Scene *scene_iter = graph->scene;
+ scene_iter != NULL;
+ scene_iter = scene_iter->set)
+ {
+ IDDepsNode *scene_id_node = graph->find_id_node(&scene_iter->id);
+ if (scene_id_node != NULL) {
+ scene_id_node->tag_update(graph);
+ }
+ else {
+ BLI_assert(graph->need_update);
+ }
+ }
+}
+
+} /* namespace */
+
+} // namespace DEG
+
+const char *DEG_update_tag_as_string(eDepsgraph_Tag flag)
+{
+ switch (flag) {
+ case DEG_TAG_TRANSFORM: return "TRANSFORM";
+ case DEG_TAG_GEOMETRY: return "GEOMETRY";
+ case DEG_TAG_TIME: return "TIME";
+ case DEG_TAG_PSYS_REDO: return "PSYS_REDO";
+ case DEG_TAG_PSYS_RESET: return "PSYS_RESET";
+ case DEG_TAG_PSYS_TYPE: return "PSYS_TYPE";
+ case DEG_TAG_PSYS_CHILD: return "PSYS_CHILD";
+ case DEG_TAG_PSYS_PHYS: return "PSYS_PHYS";
+ case DEG_TAG_PSYS_ALL: return "PSYS_ALL";
+ case DEG_TAG_COPY_ON_WRITE: return "COPY_ON_WRITE";
+ case DEG_TAG_SHADING_UPDATE: return "SHADING_UPDATE";
+ case DEG_TAG_SELECT_UPDATE: return "SELECT_UPDATE";
+ case DEG_TAG_BASE_FLAGS_UPDATE: return "BASE_FLAGS_UPDATE";
+ case DEG_TAG_EDITORS_UPDATE: return "EDITORS_UPDATE";
+ }
+ BLI_assert(!"Unhandled update flag, should never happen!");
+ return "UNKNOWN";
+}
+
+/* Data-Based Tagging */
+
+/* Tag given ID for an update in all the dependency graphs. */
+void DEG_id_tag_update(ID *id, int flag)
+{
+ DEG_id_tag_update_ex(G.main, id, flag);
+}
+
+void DEG_id_tag_update_ex(Main *bmain, ID *id, int flag)
+{
+ if (id == NULL) {
+ /* Ideally should not happen, but old depsgraph allowed this. */
return;
}
- /* Special trick to get local view to work. */
- LISTBASE_FOREACH (Base *, base, &scene->base) {
- Object *object = base->object;
- DEG::IDDepsNode *id_node = graph->find_id_node(&object->id);
- id_node->layers = 0;
- }
- LISTBASE_FOREACH (Base *, base, &scene->base) {
- Object *object = base->object;
- DEG::IDDepsNode *id_node = graph->find_id_node(&object->id);
- id_node->layers |= base->lay;
- if (object == scene->camera || object->type == OB_CAMERA) {
- /* Camera should always be updated, it used directly by viewport. */
- id_node->layers |= (unsigned int)(-1);
- }
+ DEG::deg_id_tag_update(bmain, id, flag);
+}
+
+void DEG_graph_id_tag_update(struct Main *bmain,
+ struct Depsgraph *depsgraph,
+ struct ID *id,
+ int flag)
+{
+ DEG::Depsgraph *graph = (DEG::Depsgraph *)depsgraph;
+ DEG::deg_graph_id_tag_update(bmain, graph, id, flag);
+}
+
+/* Mark a particular datablock type as having changing. */
+void DEG_id_type_tag(Main *bmain, short id_type)
+{
+ if (id_type == ID_NT) {
+ /* Stupid workaround so parent datablocks of nested nodetree get looped
+ * over when we loop over tagged datablock types.
+ */
+ DEG_id_type_tag(bmain, ID_MA);
+ DEG_id_type_tag(bmain, ID_TE);
+ DEG_id_type_tag(bmain, ID_LA);
+ DEG_id_type_tag(bmain, ID_WO);
+ DEG_id_type_tag(bmain, ID_SCE);
}
- DEG::deg_graph_build_flush_layers(graph);
- LISTBASE_FOREACH (Base *, base, &scene->base) {
- Object *object = base->object;
- DEG::IDDepsNode *id_node = graph->find_id_node(&object->id);
- GHASH_FOREACH_BEGIN(DEG::ComponentDepsNode *, comp, id_node->components)
- {
- id_node->layers |= comp->layers;
- }
- GHASH_FOREACH_END();
+
+ bmain->id_tag_update[BKE_idcode_to_index(id_type)] = 1;
+}
+
+void DEG_graph_flush_update(Main *bmain, Depsgraph *depsgraph)
+{
+ if (depsgraph == NULL) {
+ return;
}
+ DEG::deg_graph_flush_updates(bmain, (DEG::Depsgraph *)depsgraph);
+}
+
+/* Update dependency graph when visible scenes/layers changes. */
+void DEG_graph_on_visible_update(Main *bmain, Depsgraph *depsgraph)
+{
+ DEG::Depsgraph *graph = (DEG::Depsgraph *)depsgraph;
+ DEG::deg_graph_on_visible_update(bmain, graph);
}
void DEG_on_visible_update(Main *bmain, const bool UNUSED(do_time))
{
- for (Scene *scene = (Scene *)bmain->scene.first;
- scene != NULL;
- scene = (Scene *)scene->id.next)
- {
- if (scene->depsgraph != NULL) {
- DEG_graph_on_visible_update(bmain, scene);
+ LISTBASE_FOREACH (Scene *, scene, &bmain->scene) {
+ LISTBASE_FOREACH (ViewLayer *, view_layer, &scene->view_layers) {
+ Depsgraph *depsgraph =
+ (Depsgraph *)BKE_scene_get_depsgraph(scene,
+ view_layer,
+ false);
+ if (depsgraph != NULL) {
+ DEG_graph_on_visible_update(bmain, depsgraph);
+ }
}
}
}
@@ -369,7 +625,11 @@ void DEG_on_visible_update(Main *bmain, const bool UNUSED(do_time))
/* Check if something was changed in the database and inform
* editors about this.
*/
-void DEG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
+void DEG_ids_check_recalc(Main *bmain,
+ Depsgraph *depsgraph,
+ Scene *scene,
+ ViewLayer *view_layer,
+ bool time)
{
ListBase *lbarray[MAX_LIBARRAY];
int a;
@@ -387,7 +647,12 @@ void DEG_ids_check_recalc(Main *bmain, Scene *scene, bool time)
}
}
- DEG::deg_editors_scene_update(bmain, scene, (updated || time));
+ DEGEditorUpdateContext update_ctx = {NULL};
+ update_ctx.bmain = bmain;
+ update_ctx.depsgraph = depsgraph;
+ update_ctx.scene = scene;
+ update_ctx.view_layer = view_layer;
+ DEG::deg_editors_scene_update(&update_ctx, (updated || time));
}
void DEG_ids_clear_recalc(Main *bmain)
diff --git a/source/blender/depsgraph/intern/depsgraph_type_defines.cc b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
index 41c72d11eac..6484d1f21ad 100644
--- a/source/blender/depsgraph/intern/depsgraph_type_defines.cc
+++ b/source/blender/depsgraph/intern/depsgraph_type_defines.cc
@@ -71,11 +71,46 @@ DepsNodeFactory *deg_type_get_factory(const eDepsNode_Type type)
return depsnode_typeinfo_registry[type];
}
-/* Stringified opcodes ------------------------------------- */
+/* Stringified node types ---------------------------------- */
+
+const char* nodeTypeAsString(eDepsNode_Type type)
+{
+ switch (type) {
+#define STRINGIFY_TYPE(name) case DEG_NODE_TYPE_##name: return #name
+
+ STRINGIFY_TYPE(UNDEFINED);
+ STRINGIFY_TYPE(OPERATION);
+ /* **** Generic Types **** */
+ STRINGIFY_TYPE(TIMESOURCE);
+ STRINGIFY_TYPE(ID_REF);
+ /* **** Outer Types **** */
+ STRINGIFY_TYPE(PARAMETERS);
+ STRINGIFY_TYPE(PROXY);
+ STRINGIFY_TYPE(ANIMATION);
+ STRINGIFY_TYPE(TRANSFORM);
+ STRINGIFY_TYPE(GEOMETRY);
+ STRINGIFY_TYPE(SEQUENCER);
+ STRINGIFY_TYPE(LAYER_COLLECTIONS);
+ STRINGIFY_TYPE(COPY_ON_WRITE);
+ /* **** Evaluation-Related Outer Types (with Subdata) **** */
+ STRINGIFY_TYPE(EVAL_POSE);
+ STRINGIFY_TYPE(BONE);
+ STRINGIFY_TYPE(EVAL_PARTICLES);
+ STRINGIFY_TYPE(SHADING);
+ STRINGIFY_TYPE(SHADING_PARAMETERS);
+ STRINGIFY_TYPE(CACHE);
+ STRINGIFY_TYPE(BATCH_CACHE);
+
+ /* Total number of meaningful node types. */
+ case NUM_DEG_NODE_TYPES: return "SpecialCase";
+#undef STRINGIFY_TYPE
+ }
+ return "UNKNOWN";
+}
-DepsOperationStringifier DEG_OPNAMES;
+/* Stringified opcodes ------------------------------------- */
-static const char *stringify_opcode(eDepsOperation_Code opcode)
+const char* operationCodeAsString(eDepsOperation_Code opcode)
{
switch (opcode) {
#define STRINGIFY_OPCODE(name) case DEG_OPCODE_##name: return #name
@@ -87,6 +122,8 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
/* Animation, Drivers, etc. */
STRINGIFY_OPCODE(ANIMATION);
STRINGIFY_OPCODE(DRIVER);
+ /* Object related. */
+ STRINGIFY_OPCODE(OBJECT_BASE_FLAGS);
/* Transform. */
STRINGIFY_OPCODE(TRANSFORM_LOCAL);
STRINGIFY_OPCODE(TRANSFORM_PARENT);
@@ -116,11 +153,22 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
/* Particles. */
STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL_INIT);
STRINGIFY_OPCODE(PARTICLE_SYSTEM_EVAL);
+ STRINGIFY_OPCODE(PARTICLE_SETTINGS_EVAL);
+ /* Point Cache. */
+ STRINGIFY_OPCODE(POINT_CACHE_RESET);
+ /* Batch cache. */
+ STRINGIFY_OPCODE(GEOMETRY_SELECT_UPDATE);
/* Masks. */
STRINGIFY_OPCODE(MASK_ANIMATION);
STRINGIFY_OPCODE(MASK_EVAL);
+ /* Collections. */
+ STRINGIFY_OPCODE(VIEW_LAYER_EVAL);
+ /* Copy on write. */
+ STRINGIFY_OPCODE(COPY_ON_WRITE);
/* Shading. */
STRINGIFY_OPCODE(SHADING);
+ STRINGIFY_OPCODE(MATERIAL_UPDATE);
+ STRINGIFY_OPCODE(WORLD_UPDATE);
/* Movie clip. */
STRINGIFY_OPCODE(MOVIECLIP_EVAL);
@@ -130,22 +178,6 @@ static const char *stringify_opcode(eDepsOperation_Code opcode)
return "UNKNOWN";
}
-DepsOperationStringifier::DepsOperationStringifier()
-{
- for (int i = 0; i < DEG_NUM_OPCODES; ++i) {
- names_[i] = stringify_opcode((eDepsOperation_Code)i);
- }
-}
-
-const char *DepsOperationStringifier::operator[](eDepsOperation_Code opcode)
-{
- BLI_assert((opcode >= 0) && (opcode < DEG_NUM_OPCODES));
- if (opcode >= 0 && opcode < DEG_NUM_OPCODES) {
- return names_[opcode];
- }
- return "UnknownOpcode";
-}
-
} // namespace DEG
/* Register all node types */
diff --git a/source/blender/depsgraph/intern/depsgraph_types.h b/source/blender/depsgraph/intern/depsgraph_types.h
index 0e48be6b1e2..766f02c0d26 100644
--- a/source/blender/depsgraph/intern/depsgraph_types.h
+++ b/source/blender/depsgraph/intern/depsgraph_types.h
@@ -49,17 +49,19 @@ struct bAction;
struct ChannelDriver;
struct ModifierData;
struct PointerRNA;
-struct EvaluationContext;
struct FCurve;
+struct Depsgraph;
namespace DEG {
+/* TODO(sergey): Find a better place for this. */
using std::string;
using std::vector;
+using std::max;
/* Evaluation Operation for atomic operation */
// XXX: move this to another header that can be exposed?
-typedef function<void(struct EvaluationContext *)> DepsEvalOperationCb;
+typedef function<void(struct ::Depsgraph *)> DepsEvalOperationCb;
/* Metatype of Nodes - The general "level" in the graph structure
* the node serves.
@@ -80,6 +82,18 @@ typedef enum eDepsNode_Class {
DEG_NODE_CLASS_OPERATION = 2,
} eDepsNode_Class;
+/* Note: We use max comparison to mark an id node that is linked more than once
+ * So keep this enum ordered accordingly.
+ */
+typedef enum eDepsNode_LinkedState_Type {
+ /* Generic indirectly linked id node. */
+ DEG_ID_LINKED_INDIRECTLY = 0,
+ /* Id node present in the set (background) only. */
+ DEG_ID_LINKED_VIA_SET = 1,
+ /* Id node directly linked via the ScenLayer. */
+ DEG_ID_LINKED_DIRECTLY = 2,
+} eDepsNode_LinkedState_Type;
+
/* Types of Nodes */
typedef enum eDepsNode_Type {
/* Fallback type for invalid return value */
@@ -112,6 +126,14 @@ typedef enum eDepsNode_Type {
DEG_NODE_TYPE_GEOMETRY,
/* Sequencer Component (Scene Only) */
DEG_NODE_TYPE_SEQUENCER,
+ /* Component which contains all operations needed for layer collections
+ * evaluation.
+ */
+ DEG_NODE_TYPE_LAYER_COLLECTIONS,
+ /* Entry component of majority of ID nodes: prepares CoW pointers for
+ * execution.
+ */
+ DEG_NODE_TYPE_COPY_ON_WRITE,
/* **** Evaluation-Related Outer Types (with Subdata) **** */
@@ -123,13 +145,18 @@ typedef enum eDepsNode_Type {
DEG_NODE_TYPE_EVAL_PARTICLES,
/* Material Shading Component */
DEG_NODE_TYPE_SHADING,
+ DEG_NODE_TYPE_SHADING_PARAMETERS,
/* Cache Component */
DEG_NODE_TYPE_CACHE,
+ /* Batch Cache Component */
+ DEG_NODE_TYPE_BATCH_CACHE,
/* Total number of meaningful node types. */
NUM_DEG_NODE_TYPES,
} eDepsNode_Type;
+const char* nodeTypeAsString(eDepsNode_Type type);
+
/* Identifiers for common operations (as an enum). */
typedef enum eDepsOperation_Code {
/* Generic Operations. ------------------------------ */
@@ -150,6 +177,9 @@ typedef enum eDepsOperation_Code {
/* Driver */
DEG_OPCODE_DRIVER,
+ /* Object related. --------------------------------- */
+ DEG_OPCODE_OBJECT_BASE_FLAGS,
+
/* Transform. -------------------------------------- */
/* Transform entry point - local transforms only */
DEG_OPCODE_TRANSFORM_LOCAL,
@@ -211,9 +241,24 @@ typedef enum eDepsOperation_Code {
/* Particle System evaluation. */
DEG_OPCODE_PARTICLE_SYSTEM_EVAL_INIT,
DEG_OPCODE_PARTICLE_SYSTEM_EVAL,
+ DEG_OPCODE_PARTICLE_SETTINGS_EVAL,
+
+ /* Point Cache. ------------------------------------- */
+ DEG_OPCODE_POINT_CACHE_RESET,
+
+ /* Collections. ------------------------------------- */
+ DEG_OPCODE_VIEW_LAYER_EVAL,
+
+ /* Copy on Write. ------------------------------------ */
+ DEG_OPCODE_COPY_ON_WRITE,
/* Shading. ------------------------------------------- */
DEG_OPCODE_SHADING,
+ DEG_OPCODE_MATERIAL_UPDATE,
+ DEG_OPCODE_WORLD_UPDATE,
+
+ /* Batch caches. -------------------------------------- */
+ DEG_OPCODE_GEOMETRY_SELECT_UPDATE,
/* Masks. ------------------------------------------ */
DEG_OPCODE_MASK_ANIMATION,
@@ -225,16 +270,6 @@ typedef enum eDepsOperation_Code {
DEG_NUM_OPCODES,
} eDepsOperation_Code;
-/* Some magic to stringify operation codes. */
-class DepsOperationStringifier {
-public:
- DepsOperationStringifier();
- const char *operator[](eDepsOperation_Code opcodex);
-protected:
- const char *names_[DEG_NUM_OPCODES];
-};
-
-/* String defines for these opcodes, defined in depsgraph_type_defines.cpp */
-extern DepsOperationStringifier DEG_OPNAMES;
+const char* operationCodeAsString(eDepsOperation_Code opcode);
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc
index fc71b5ccb7b..95084717dad 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval.cc
@@ -38,15 +38,15 @@
#include "BLI_task.h"
#include "BLI_ghash.h"
-extern "C" {
-#include "BKE_depsgraph.h"
-#include "BKE_global.h"
-} /* extern "C" */
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "atomic_ops.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/eval/deg_eval_flush.h"
#include "intern/eval/deg_eval_stats.h"
#include "intern/nodes/deg_node.h"
@@ -68,13 +68,10 @@ namespace DEG {
static void schedule_children(TaskPool *pool,
Depsgraph *graph,
OperationDepsNode *node,
- const unsigned int layers,
const int thread_id);
struct DepsgraphEvalState {
- EvaluationContext *eval_ctx;
Depsgraph *graph;
- unsigned int layers;
bool do_stats;
};
@@ -90,21 +87,20 @@ static void deg_task_run_func(TaskPool *pool,
/* Perform operation. */
if (state->do_stats) {
const double start_time = PIL_check_seconds_timer();
- node->evaluate(state->eval_ctx);
+ node->evaluate((::Depsgraph *)state->graph);
node->stats.current_time += PIL_check_seconds_timer() - start_time;
}
else {
- node->evaluate(state->eval_ctx);
+ node->evaluate((::Depsgraph *)state->graph);
}
/* Schedule children. */
BLI_task_pool_delayed_push_begin(pool, thread_id);
- schedule_children(pool, state->graph, node, state->layers, thread_id);
+ schedule_children(pool, state->graph, node, thread_id);
BLI_task_pool_delayed_push_end(pool, thread_id);
}
typedef struct CalculatePengindData {
Depsgraph *graph;
- unsigned int layers;
} CalculatePengindData;
static void calculate_pending_func(
@@ -114,26 +110,19 @@ static void calculate_pending_func(
{
CalculatePengindData *data = (CalculatePengindData *)data_v;
Depsgraph *graph = data->graph;
- unsigned int layers = data->layers;
OperationDepsNode *node = graph->operations[i];
- IDDepsNode *id_node = node->owner->owner;
node->num_links_pending = 0;
node->scheduled = false;
/* count number of inputs that need updates */
- if ((id_node->layers & layers) != 0 &&
- (node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
- {
+ if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0) {
foreach (DepsRelation *rel, node->inlinks) {
if (rel->from->type == DEG_NODE_TYPE_OPERATION &&
(rel->flag & DEPSREL_FLAG_CYCLIC) == 0)
{
OperationDepsNode *from = (OperationDepsNode *)rel->from;
- IDDepsNode *id_from_node = from->owner->owner;
- if ((id_from_node->layers & layers) != 0 &&
- (from->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0)
- {
+ if ((from->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0) {
++node->num_links_pending;
}
}
@@ -141,12 +130,11 @@ static void calculate_pending_func(
}
}
-static void calculate_pending_parents(Depsgraph *graph, unsigned int layers)
+static void calculate_pending_parents(Depsgraph *graph)
{
const int num_operations = graph->operations.size();
CalculatePengindData data;
data.graph = graph;
- data.layers = layers;
ParallelRangeSettings settings;
BLI_parallel_range_settings_defaults(&settings);
settings.min_iter_per_thread = 1024;
@@ -160,7 +148,7 @@ static void calculate_pending_parents(Depsgraph *graph, unsigned int layers)
static void initialize_execution(DepsgraphEvalState *state, Depsgraph *graph)
{
const bool do_stats = state->do_stats;
- calculate_pending_parents(graph, state->layers);
+ calculate_pending_parents(graph);
/* Clear tags and other things which needs to be clear. */
foreach (OperationDepsNode *node, graph->operations) {
node->done = 0;
@@ -174,15 +162,11 @@ static void initialize_execution(DepsgraphEvalState *state, Depsgraph *graph)
* dec_parents: Decrement pending parents count, true when child nodes are
* scheduled after a task has been completed.
*/
-static void schedule_node(TaskPool *pool, Depsgraph *graph, unsigned int layers,
+static void schedule_node(TaskPool *pool, Depsgraph *graph,
OperationDepsNode *node, bool dec_parents,
const int thread_id)
{
- unsigned int id_layers = node->owner->owner->layers;
-
- if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0 &&
- (id_layers & layers) != 0)
- {
+ if ((node->flag & DEPSOP_FLAG_NEEDS_UPDATE) != 0) {
if (dec_parents) {
BLI_assert(node->num_links_pending > 0);
atomic_sub_and_fetch_uint32(&node->num_links_pending, 1);
@@ -194,7 +178,7 @@ static void schedule_node(TaskPool *pool, Depsgraph *graph, unsigned int layers,
if (!is_scheduled) {
if (node->is_noop()) {
/* skip NOOP node, schedule children right away */
- schedule_children(pool, graph, node, layers, thread_id);
+ schedule_children(pool, graph, node, thread_id);
}
else {
/* children are scheduled once this task is completed */
@@ -210,19 +194,16 @@ static void schedule_node(TaskPool *pool, Depsgraph *graph, unsigned int layers,
}
}
-static void schedule_graph(TaskPool *pool,
- Depsgraph *graph,
- const unsigned int layers)
+static void schedule_graph(TaskPool *pool, Depsgraph *graph)
{
foreach (OperationDepsNode *node, graph->operations) {
- schedule_node(pool, graph, layers, node, false, 0);
+ schedule_node(pool, graph, node, false, 0);
}
}
static void schedule_children(TaskPool *pool,
Depsgraph *graph,
OperationDepsNode *node,
- const unsigned int layers,
const int thread_id)
{
foreach (DepsRelation *rel, node->outlinks) {
@@ -234,13 +215,31 @@ static void schedule_children(TaskPool *pool,
}
schedule_node(pool,
graph,
- layers,
child,
(rel->flag & DEPSREL_FLAG_CYCLIC) == 0,
thread_id);
}
}
+static void depsgraph_ensure_view_layer(Depsgraph *graph)
+{
+ /* We update copy-on-write scene in the following cases:
+ * - It was not expanded yet.
+ * - It was tagged for update of CoW component.
+ * This allows us to have proper view layer pointer.
+ */
+ if (!DEG_depsgraph_use_copy_on_write()) {
+ return;
+ }
+ Scene *scene_cow = graph->scene_cow;
+ if (!deg_copy_on_write_is_expanded(&scene_cow->id) ||
+ scene_cow->id.recalc & ID_RECALC_COPY_ON_WRITE)
+ {
+ const IDDepsNode *id_node = graph->find_id_node(&graph->scene->id);
+ deg_update_copy_on_write_datablock(graph, id_node);
+ }
+}
+
/**
* Evaluate all nodes tagged for updating,
* \warning This is usually done as part of main loop, but may also be
@@ -248,28 +247,18 @@ static void schedule_children(TaskPool *pool,
*
* \note Time sources should be all valid!
*/
-void deg_evaluate_on_refresh(EvaluationContext *eval_ctx,
- Depsgraph *graph,
- const unsigned int layers)
+void deg_evaluate_on_refresh(Depsgraph *graph)
{
- /* Set time for the current graph evaluation context. */
- TimeSourceDepsNode *time_src = graph->find_time_source();
- eval_ctx->ctime = time_src->cfra;
/* Nothing to update, early out. */
if (BLI_gset_len(graph->entry_tags) == 0) {
return;
}
- DEG_DEBUG_PRINTF(EVAL, "%s: layers:%u, graph->layers:%u\n",
- __func__,
- layers,
- graph->layers);
const bool do_time_debug = ((G.debug & G_DEBUG_DEPSGRAPH_TIME) != 0);
const double start_time = do_time_debug ? PIL_check_seconds_timer() : 0;
- /* Set up evaluation context for depsgraph itself. */
+ depsgraph_ensure_view_layer(graph);
+ /* Set up evaluation state. */
DepsgraphEvalState state;
- state.eval_ctx = eval_ctx;
state.graph = graph;
- state.layers = layers;
state.do_stats = do_time_debug;
/* Set up task scheduler and pull for threaded evaluation. */
TaskScheduler *task_scheduler;
@@ -286,7 +275,7 @@ void deg_evaluate_on_refresh(EvaluationContext *eval_ctx,
/* Prepare all nodes for evaluation. */
initialize_execution(&state, graph);
/* Do actual evaluation now. */
- schedule_graph(task_pool, graph, layers);
+ schedule_graph(task_pool, graph);
BLI_task_pool_work_and_wait(task_pool);
BLI_task_pool_free(task_pool);
/* Finalize statistics gathering. This is because we only gather single
diff --git a/source/blender/depsgraph/intern/eval/deg_eval.h b/source/blender/depsgraph/intern/eval/deg_eval.h
index 49c0379939e..a8f5f7c145f 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval.h
+++ b/source/blender/depsgraph/intern/eval/deg_eval.h
@@ -32,8 +32,6 @@
#pragma once
-struct EvaluationContext;
-
namespace DEG {
struct Depsgraph;
@@ -45,8 +43,6 @@ struct Depsgraph;
*
* \note Time sources should be all valid!
*/
-void deg_evaluate_on_refresh(EvaluationContext *eval_ctx,
- Depsgraph *graph,
- const unsigned int layers);
+void deg_evaluate_on_refresh(Depsgraph *graph);
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
new file mode 100644
index 00000000000..7321b394636
--- /dev/null
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
@@ -0,0 +1,850 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 20137Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Sergey Sharybin
+ * Contributor(s): None Yet
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+
+/** \file blender/depsgraph/intern/eval/deg_eval_copy_on_write.cc
+ * \ingroup depsgraph
+ */
+
+/* Enable special; trickery to treat nested owned IDs (such as nodetree of
+ * material) to be handled in same way as "real" datablocks, even tho some
+ * internal BKE routines doesn't treat them like that.
+ *
+ * TODO(sergey): Re-evaluate that after new ID handling is in place.
+ */
+#define NESTED_ID_NASTY_WORKAROUND
+
+/* Silence warnings from copying deprecated fields. */
+#define DNA_DEPRECATED_ALLOW
+
+#include "intern/eval/deg_eval_copy_on_write.h"
+
+#include <cstring>
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+#include "BLI_threads.h"
+#include "BLI_string.h"
+
+#include "BKE_global.h"
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_scene.h"
+
+#include "DEG_depsgraph.h"
+
+#include "MEM_guardedalloc.h"
+
+extern "C" {
+#include "DNA_ID.h"
+#include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
+
+#ifdef NESTED_ID_NASTY_WORKAROUND
+# include "DNA_curve_types.h"
+# include "DNA_key_types.h"
+# include "DNA_lamp_types.h"
+# include "DNA_lattice_types.h"
+# include "DNA_linestyle_types.h"
+# include "DNA_material_types.h"
+# include "DNA_node_types.h"
+# include "DNA_texture_types.h"
+# include "DNA_world_types.h"
+#endif
+
+#include "BKE_action.h"
+#include "BKE_animsys.h"
+#include "BKE_armature.h"
+#include "BKE_editmesh.h"
+#include "BKE_library_query.h"
+#include "BKE_object.h"
+}
+
+#include "intern/depsgraph.h"
+#include "intern/builder/deg_builder_nodes.h"
+#include "intern/nodes/deg_node.h"
+#include "intern/nodes/deg_node_id.h"
+
+namespace DEG {
+
+#define DEBUG_PRINT if (G.debug & G_DEBUG_DEPSGRAPH_EVAL) printf
+
+namespace {
+
+#ifdef NESTED_ID_NASTY_WORKAROUND
+union NestedIDHackTempStorage {
+ Curve curve;
+ FreestyleLineStyle linestyle;
+ Lamp lamp;
+ Lattice lattice;
+ Material material;
+ Mesh mesh;
+ Scene scene;
+ Tex tex;
+ World world;
+};
+
+/* Set nested owned ID pointers to NULL. */
+void nested_id_hack_discard_pointers(ID *id_cow)
+{
+ switch (GS(id_cow->name)) {
+# define SPECIAL_CASE(id_type, dna_type, field) \
+ case id_type: \
+ { \
+ ((dna_type *)id_cow)->field = NULL; \
+ break; \
+ }
+
+ SPECIAL_CASE(ID_LS, FreestyleLineStyle, nodetree)
+ SPECIAL_CASE(ID_LA, Lamp, nodetree)
+ SPECIAL_CASE(ID_MA, Material, nodetree)
+ SPECIAL_CASE(ID_SCE, Scene, nodetree)
+ SPECIAL_CASE(ID_TE, Tex, nodetree)
+ SPECIAL_CASE(ID_WO, World, nodetree)
+
+ SPECIAL_CASE(ID_CU, Curve, key)
+ SPECIAL_CASE(ID_LT, Lattice, key)
+ SPECIAL_CASE(ID_ME, Mesh, key)
+
+# undef SPECIAL_CASE
+
+ default:
+ break;
+ }
+}
+
+/* Set ID pointer of nested owned IDs (nodetree, key) to NULL.
+ *
+ * Return pointer to a new ID to be used.
+ */
+const ID *nested_id_hack_get_discarded_pointers(NestedIDHackTempStorage *storage,
+ const ID *id)
+{
+ switch (GS(id->name)) {
+# define SPECIAL_CASE(id_type, dna_type, field, variable) \
+ case id_type: \
+ { \
+ storage->variable = *(dna_type *)id; \
+ storage->variable.field = NULL; \
+ return &storage->variable.id; \
+ }
+
+ SPECIAL_CASE(ID_LS, FreestyleLineStyle, nodetree, linestyle)
+ SPECIAL_CASE(ID_LA, Lamp, nodetree, lamp)
+ SPECIAL_CASE(ID_MA, Material, nodetree, material)
+ SPECIAL_CASE(ID_SCE, Scene, nodetree, scene)
+ SPECIAL_CASE(ID_TE, Tex, nodetree, tex)
+ SPECIAL_CASE(ID_WO, World, nodetree, world)
+
+ SPECIAL_CASE(ID_CU, Curve, key, curve)
+ SPECIAL_CASE(ID_LT, Lattice, key, lattice)
+ SPECIAL_CASE(ID_ME, Mesh, key, mesh)
+
+# undef SPECIAL_CASE
+
+ default:
+ break;
+ }
+ return id;
+}
+
+/* Set ID pointer of nested owned IDs (nodetree, key) to the original value. */
+void nested_id_hack_restore_pointers(const ID *old_id, ID *new_id)
+{
+ if (new_id == NULL) {
+ return;
+ }
+ switch (GS(old_id->name)) {
+# define SPECIAL_CASE(id_type, dna_type, field) \
+ case id_type: \
+ { \
+ ((dna_type *)(new_id))->field = \
+ ((dna_type *)(old_id))->field; \
+ break; \
+ }
+
+ SPECIAL_CASE(ID_LS, FreestyleLineStyle, nodetree)
+ SPECIAL_CASE(ID_LA, Lamp, nodetree)
+ SPECIAL_CASE(ID_MA, Material, nodetree)
+ SPECIAL_CASE(ID_SCE, Scene, nodetree)
+ SPECIAL_CASE(ID_TE, Tex, nodetree)
+ SPECIAL_CASE(ID_WO, World, nodetree)
+
+ SPECIAL_CASE(ID_CU, Curve, key)
+ SPECIAL_CASE(ID_LT, Lattice, key)
+ SPECIAL_CASE(ID_ME, Mesh, key)
+
+#undef SPECIAL_CASE
+ default:
+ break;
+ }
+}
+
+/* Remap pointer of nested owned IDs (nodetree. key) to the new ID values. */
+void ntree_hack_remap_pointers(const Depsgraph *depsgraph, ID *id_cow)
+{
+ switch (GS(id_cow->name)) {
+# define SPECIAL_CASE(id_type, dna_type, field, field_type) \
+ case id_type: \
+ { \
+ dna_type *data = (dna_type *)id_cow; \
+ if (data->field != NULL) { \
+ ID *ntree_id_cow = depsgraph->get_cow_id(&data->field->id); \
+ if (ntree_id_cow != NULL) { \
+ DEG_COW_PRINT(" Remapping datablock for %s: id_orig=%p id_cow=%p\n", \
+ data->field->id.name, \
+ data->field, \
+ ntree_id_cow); \
+ data->field = (field_type *)ntree_id_cow; \
+ } \
+ } \
+ break; \
+ }
+
+ SPECIAL_CASE(ID_LS, FreestyleLineStyle, nodetree, bNodeTree)
+ SPECIAL_CASE(ID_LA, Lamp, nodetree, bNodeTree)
+ SPECIAL_CASE(ID_MA, Material, nodetree, bNodeTree)
+ SPECIAL_CASE(ID_SCE, Scene, nodetree, bNodeTree)
+ SPECIAL_CASE(ID_TE, Tex, nodetree, bNodeTree)
+ SPECIAL_CASE(ID_WO, World, nodetree, bNodeTree)
+
+ SPECIAL_CASE(ID_CU, Curve, key, Key)
+ SPECIAL_CASE(ID_LT, Lattice, key, Key)
+ SPECIAL_CASE(ID_ME, Mesh, key, Key)
+
+#undef SPECIAL_CASE
+ default:
+ break;
+ }
+}
+#endif /* NODETREE_NASTY_WORKAROUND */
+
+struct ValidateData {
+ bool is_valid;
+};
+
+/* Similar to generic id_copy() but does not require main and assumes pointer
+ * is already allocated,
+ */
+bool id_copy_inplace_no_main(const ID *id, ID *newid)
+{
+ const ID *id_for_copy = id;
+
+#ifdef NESTED_ID_NASTY_WORKAROUND
+ NestedIDHackTempStorage id_hack_storage;
+ id_for_copy = nested_id_hack_get_discarded_pointers(&id_hack_storage, id);
+#endif
+
+ bool result = BKE_id_copy_ex(NULL,
+ (ID *)id_for_copy,
+ &newid,
+ LIB_ID_CREATE_NO_MAIN |
+ LIB_ID_CREATE_NO_USER_REFCOUNT |
+ LIB_ID_CREATE_NO_ALLOCATE |
+ LIB_ID_CREATE_NO_DEG_TAG,
+ false);
+
+#ifdef NESTED_ID_NASTY_WORKAROUND
+ if (result) {
+ nested_id_hack_restore_pointers(id, newid);
+ }
+#endif
+
+ return result;
+}
+
+/* Similar to BKE_scene_copy() but does not require main and assumes pointer
+ * is already allocated.
+ */
+bool scene_copy_inplace_no_main(const Scene *scene, Scene *new_scene)
+{
+ const ID *id_for_copy = &scene->id;
+
+#ifdef NESTED_ID_NASTY_WORKAROUND
+ NestedIDHackTempStorage id_hack_storage;
+ id_for_copy = nested_id_hack_get_discarded_pointers(&id_hack_storage,
+ &scene->id);
+#endif
+
+ bool result = BKE_id_copy_ex(NULL,
+ id_for_copy,
+ (ID **)&new_scene,
+ LIB_ID_CREATE_NO_MAIN |
+ LIB_ID_CREATE_NO_USER_REFCOUNT |
+ LIB_ID_CREATE_NO_ALLOCATE |
+ LIB_ID_CREATE_NO_DEG_TAG,
+ false);
+
+#ifdef NESTED_ID_NASTY_WORKAROUND
+ if (result) {
+ nested_id_hack_restore_pointers(&scene->id, &new_scene->id);
+ }
+#endif
+
+ return result;
+}
+
+/* Check whether given ID is expanded or still a shallow copy. */
+BLI_INLINE bool check_datablock_expanded(const ID *id_cow)
+{
+ return (id_cow->name[0] != '\0');
+}
+
+/* Those are datablocks which are not covered by dependency graph and hence
+ * does not need any remapping or anything.
+ *
+ * TODO(sergey): How to make it more robust for the future, so we don't have
+ * to maintain exception lists all over the code?
+ */
+static bool check_datablocks_copy_on_writable(const ID *id_orig)
+{
+ const ID_Type id_type = GS(id_orig->name);
+ /* We shouldn't bother if copied ID is same as original one. */
+ if (!deg_copy_on_write_is_needed(id_orig)) {
+ return false;
+ }
+ return !ELEM(id_type, ID_BR,
+ ID_LS,
+ ID_PAL);
+}
+
+/* Callback for BKE_library_foreach_ID_link which remaps original ID pointer
+ * with the one created by CoW system.
+ */
+
+struct RemapCallbackUserData {
+ /* Dependency graph for which remapping is happening. */
+ const Depsgraph *depsgraph;
+ /* Create placeholder for ID nodes for cases when we need to remap original
+ * ID to it[s CoW version but we don't have required ID node yet.
+ *
+ * This happens when expansion happens a ta construction time.
+ */
+ DepsgraphNodeBuilder *node_builder;
+ bool create_placeholders;
+};
+
+int foreach_libblock_remap_callback(void *user_data_v,
+ ID *id_self,
+ ID **id_p,
+ int /*cb_flag*/)
+{
+ if (*id_p == NULL) {
+ return IDWALK_RET_NOP;
+ }
+ RemapCallbackUserData *user_data = (RemapCallbackUserData *)user_data_v;
+ const Depsgraph *depsgraph = user_data->depsgraph;
+ ID *id_orig = *id_p;
+ if (check_datablocks_copy_on_writable(id_orig)) {
+ ID *id_cow;
+ if (user_data->create_placeholders) {
+ /* Special workaround to stop creating temp datablocks for
+ * objects which are coming from scene's collection and which
+ * are never linked to any of layers.
+ *
+ * TODO(sergey): Ideally we need to tell ID looper to ignore
+ * those or at least make it more reliable check where the
+ * pointer is coming from.
+ */
+ const ID_Type id_type = GS(id_orig->name);
+ const ID_Type id_type_self = GS(id_self->name);
+ if (id_type == ID_OB && id_type_self == ID_SCE) {
+ IDDepsNode *id_node = depsgraph->find_id_node(id_orig);
+ if (id_node == NULL) {
+ id_cow = id_orig;
+ }
+ else {
+ id_cow = id_node->id_cow;
+ }
+ }
+ else {
+ id_cow = user_data->node_builder->ensure_cow_id(id_orig);
+ }
+ }
+ else {
+ id_cow = depsgraph->get_cow_id(id_orig);
+ }
+ BLI_assert(id_cow != NULL);
+ DEG_COW_PRINT(" Remapping datablock for %s: id_orig=%p id_cow=%p\n",
+ id_orig->name, id_orig, id_cow);
+ *id_p = id_cow;
+ }
+ return IDWALK_RET_NOP;
+}
+
+/* Do some special treatment of data transfer from original ID to it's
+ * CoW complementary part.
+ *
+ * Only use for the newly created CoW datablocks.
+ */
+void update_special_pointers(const Depsgraph *depsgraph,
+ const ID *id_orig, ID *id_cow)
+{
+ const ID_Type type = GS(id_orig->name);
+ switch (type) {
+ case ID_OB:
+ {
+ /* Ensure we don't drag someone's else derived mesh to the
+ * new copy of the object.
+ */
+ Object *object_cow = (Object *)id_cow;
+ const Object *object_orig = (const Object *)id_orig;
+ (void) object_cow; /* Ignored for release builds. */
+ BLI_assert(object_cow->derivedFinal == NULL);
+ BLI_assert(object_cow->derivedDeform == NULL);
+ object_cow->mode = object_orig->mode;
+ if (object_cow->type == OB_ARMATURE) {
+ BKE_pose_remap_bone_pointers((bArmature *)object_cow->data,
+ object_cow->pose);
+ }
+ break;
+ }
+ case ID_AR:
+ {
+ const bArmature *armature_orig = (const bArmature *)id_orig;
+ bArmature *armature_cow = (bArmature *)id_cow;
+ armature_cow->edbo = armature_orig->edbo;
+ break;
+ }
+ case ID_ME:
+ {
+ /* For meshes we need to update edit_btmesh to make it to point
+ * to the CoW version of object.
+ *
+ * This is kind of confusing, because actual bmesh is not owned by
+ * the CoW object, so need to be accurate about using link from
+ * edit_btmesh to object.
+ */
+ const Mesh *mesh_orig = (const Mesh *)id_orig;
+ Mesh *mesh_cow = (Mesh *)id_cow;
+ if (mesh_orig->edit_btmesh != NULL) {
+ mesh_cow->edit_btmesh = (BMEditMesh *)MEM_dupallocN(mesh_orig->edit_btmesh);
+ mesh_cow->edit_btmesh->ob =
+ (Object *)depsgraph->get_cow_id(&mesh_orig->edit_btmesh->ob->id);
+ mesh_cow->edit_btmesh->derivedFinal = NULL;
+ mesh_cow->edit_btmesh->derivedCage = NULL;
+ }
+ break;
+ }
+ default:
+ break;
+ }
+}
+
+/* This callback is used to validate that all nested ID datablocks are
+ * properly expanded.
+ */
+int foreach_libblock_validate_callback(void *user_data,
+ ID * /*id_self*/,
+ ID **id_p,
+ int /*cb_flag*/)
+{
+ ValidateData *data = (ValidateData *)user_data;
+ if (*id_p != NULL) {
+ if (!check_datablock_expanded(*id_p)) {
+ data->is_valid = false;
+ /* TODO(sergey): Store which is is not valid? */
+ }
+ }
+ return IDWALK_RET_NOP;
+}
+
+} // namespace
+
+/* Actual implementation of logic which "expands" all the data which was not
+ * yet copied-on-write.
+ *
+ * NOTE: Expects that CoW datablock is empty.
+ */
+ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
+ const IDDepsNode *id_node,
+ DepsgraphNodeBuilder *node_builder,
+ bool create_placeholders)
+{
+ const ID *id_orig = id_node->id_orig;
+ ID *id_cow = id_node->id_cow;
+ const int id_cow_recalc = id_cow->recalc;
+ /* No need to expand such datablocks, their copied ID is same as original
+ * one already.
+ */
+ if (!deg_copy_on_write_is_needed(id_orig)) {
+ return id_cow;
+ }
+ DEG_COW_PRINT("Expanding datablock for %s: id_orig=%p id_cow=%p\n",
+ id_orig->name, id_orig, id_cow);
+ /* Sanity checks. */
+ /* NOTE: Disabled for now, conflicts when re-using evaluated datablock when
+ * rebuilding dependencies.
+ */
+ if (check_datablock_expanded(id_cow) && create_placeholders) {
+ deg_free_copy_on_write_datablock(id_cow);
+ }
+ // BLI_assert(check_datablock_expanded(id_cow) == false);
+ /* Copy data from original ID to a copied version. */
+ /* TODO(sergey): Avoid doing full ID copy somehow, make Mesh to reference
+ * original geometry arrays for until those are modified.
+ */
+ /* TODO(sergey): We do some trickery with temp bmain and extra ID pointer
+ * just to be able to use existing API. Ideally we need to replace this with
+ * in-place copy from existing datablock to a prepared memory.
+ *
+ * NOTE: We don't use BKE_main_{new,free} because:
+ * - We don't want heap-allocations here.
+ * - We don't want bmain's content to be freed when main is freed.
+ */
+ bool done = false;
+ /* First we handle special cases which are not covered by id_copy() yet.
+ * or cases where we want to do something smarter than simple datablock
+ * copy.
+ */
+ const ID_Type id_type = GS(id_orig->name);
+ switch (id_type) {
+ case ID_SCE:
+ {
+ done = scene_copy_inplace_no_main((Scene *)id_orig, (Scene *)id_cow);
+ break;
+ }
+ case ID_ME:
+ {
+ /* TODO(sergey): Ideally we want to handle meshes in a special
+ * manner here to avoid initial copy of all the geometry arrays.
+ */
+ break;
+ }
+ default:
+ break;
+ }
+ if (!done) {
+ done = id_copy_inplace_no_main(id_orig, id_cow);
+ }
+ if (!done) {
+ BLI_assert(!"No idea how to perform CoW on datablock");
+ }
+ /* Update pointers to nested ID datablocks. */
+ DEG_COW_PRINT(" Remapping ID links for %s: id_orig=%p id_cow=%p\n",
+ id_orig->name, id_orig, id_cow);
+
+#ifdef NESTED_ID_NASTY_WORKAROUND
+ ntree_hack_remap_pointers(depsgraph, id_cow);
+#endif
+ /* Do it now, so remapping will understand that possibly remapped self ID
+ * is not to be remapped again.
+ */
+ deg_tag_copy_on_write_id(id_cow, id_orig);
+ /* Perform remapping of the nodes. */
+ RemapCallbackUserData user_data = {NULL};
+ user_data.depsgraph = depsgraph;
+ user_data.node_builder = node_builder;
+ user_data.create_placeholders = create_placeholders;
+ BKE_library_foreach_ID_link(NULL,
+ id_cow,
+ foreach_libblock_remap_callback,
+ (void *)&user_data,
+ IDWALK_NOP);
+ /* Correct or tweak some pointers which are not taken care by foreach
+ * from above.
+ */
+ update_special_pointers(depsgraph, id_orig, id_cow);
+ id_cow->recalc = id_orig->recalc | id_cow_recalc;
+ return id_cow;
+}
+
+/* NOTE: Depsgraph is supposed to have ID node already. */
+ID *deg_expand_copy_on_write_datablock(const Depsgraph *depsgraph,
+ ID *id_orig,
+ DepsgraphNodeBuilder *node_builder,
+ bool create_placeholders)
+{
+ DEG::IDDepsNode *id_node = depsgraph->find_id_node(id_orig);
+ BLI_assert(id_node != NULL);
+ return deg_expand_copy_on_write_datablock(depsgraph,
+ id_node,
+ node_builder,
+ create_placeholders);
+}
+
+static void deg_update_copy_on_write_animation(const Depsgraph *depsgraph,
+ const IDDepsNode *id_node)
+{
+ DEG_debug_print_eval((::Depsgraph *)depsgraph,
+ __func__,
+ id_node->id_orig->name,
+ id_node->id_cow);
+ BKE_animdata_copy_id(NULL, id_node->id_cow, id_node->id_orig, false, false);
+ RemapCallbackUserData user_data = {NULL};
+ user_data.depsgraph = depsgraph;
+ BKE_library_foreach_ID_link(NULL,
+ id_node->id_cow,
+ foreach_libblock_remap_callback,
+ (void *)&user_data,
+ IDWALK_NOP);
+}
+
+ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
+ const IDDepsNode *id_node)
+{
+ const ID *id_orig = id_node->id_orig;
+ const ID_Type id_type = GS(id_orig->name);
+ ID *id_cow = id_node->id_cow;
+ /* Similar to expansion, no need to do anything here. */
+ if (!deg_copy_on_write_is_needed(id_orig)) {
+ return id_cow;
+ }
+ /* For the rest if datablock types we use simple logic:
+ * - Free previously expanded data, if any.
+ * - Perform full datablock copy.
+ *
+ * Note that we never free GPU materials from here since that's not
+ * safe for threading and GPU materials are likely to be re-used.
+ */
+ /* TODO(sergey): Either move this to an utility function or redesign
+ * Copy-on-Write components in a way that only needed parts are being
+ * copied over.
+ */
+ ListBase gpumaterial_backup;
+ ListBase *gpumaterial_ptr = NULL;
+ Mesh *mesh_evaluated = NULL;
+ IDProperty *base_collection_properties = NULL;
+ short base_flag = 0;
+ if (check_datablock_expanded(id_cow)) {
+ switch (id_type) {
+ case ID_MA:
+ {
+ Material *material = (Material *)id_cow;
+ gpumaterial_ptr = &material->gpumaterial;
+ break;
+ }
+ case ID_WO:
+ {
+ World *world = (World *)id_cow;
+ gpumaterial_ptr = &world->gpumaterial;
+ break;
+ }
+ case ID_NT:
+ {
+ /* Node trees should try to preserve their socket pointers
+ * as much as possible. This is due to UBOs code in GPU,
+ * which references sockets from trees.
+ *
+ * These flags CURRENTLY don't need full datablock update,
+ * everything is done by node tree update function which
+ * only copies socket values.
+ */
+ const int ignore_flag = (ID_RECALC_DRAW |
+ ID_RECALC_ANIMATION |
+ ID_RECALC_COPY_ON_WRITE);
+ if ((id_cow->recalc & ~ignore_flag) == 0) {
+ deg_update_copy_on_write_animation(depsgraph, id_node);
+ return id_cow;
+ }
+ break;
+ }
+ case ID_OB:
+ {
+ Object *object = (Object *)id_cow;
+ /* Store evaluated mesh, make sure we don't free it. */
+ mesh_evaluated = object->mesh_evaluated;
+ object->mesh_evaluated = NULL;
+ /* Currently object update will override actual object->data
+ * to an evaluated version. Need to make sure we don't have
+ * data set to evaluated one before free anything.
+ */
+ if (mesh_evaluated != NULL) {
+ if (object->data == mesh_evaluated) {
+ object->data = mesh_evaluated->id.orig_id;
+ }
+ }
+ /* Make a backup of base flags. */
+ base_collection_properties = object->base_collection_properties;
+ base_flag = object->base_flag;
+ break;
+ }
+ default:
+ break;
+ }
+ if (gpumaterial_ptr != NULL) {
+ gpumaterial_backup = *gpumaterial_ptr;
+ gpumaterial_ptr->first = gpumaterial_ptr->last = NULL;
+ }
+ }
+ deg_free_copy_on_write_datablock(id_cow);
+ deg_expand_copy_on_write_datablock(depsgraph, id_node);
+ /* Restore GPU materials. */
+ if (gpumaterial_ptr != NULL) {
+ *gpumaterial_ptr = gpumaterial_backup;
+ }
+ if (id_type == ID_OB) {
+ Object *object = (Object *)id_cow;
+ if (mesh_evaluated != NULL) {
+ object->mesh_evaluated = mesh_evaluated;
+ /* Do same thing as object update: override actual object data
+ * pointer with evaluated datablock.
+ */
+ if (object->type == OB_MESH) {
+ object->data = mesh_evaluated;
+ /* Evaluated mesh simply copied edit_btmesh pointer from
+ * original mesh during update, need to make sure no dead
+ * pointers are left behind.
+ */
+ mesh_evaluated->edit_btmesh =
+ ((Mesh *)mesh_evaluated->id.orig_id)->edit_btmesh;
+ }
+ }
+ if (base_collection_properties != NULL) {
+ object->base_collection_properties = base_collection_properties;
+ object->base_flag = base_flag;
+ }
+ }
+ return id_cow;
+}
+
+/* NOTE: Depsgraph is supposed to have ID node already. */
+ID *deg_update_copy_on_write_datablock(const Depsgraph *depsgraph,
+ ID *id_orig)
+{
+ DEG::IDDepsNode *id_node = depsgraph->find_id_node(id_orig);
+ BLI_assert(id_node != NULL);
+ return deg_update_copy_on_write_datablock(depsgraph, id_node);
+}
+
+/* Free content of the CoW datablock
+ * Notes:
+ * - Does not recurs into nested ID datablocks.
+ * - Does not free datablock itself.
+ */
+void deg_free_copy_on_write_datablock(ID *id_cow)
+{
+ if (!check_datablock_expanded(id_cow)) {
+ /* Actual content was never copied on top of CoW block, we have
+ * nothing to free.
+ */
+ return;
+ }
+ const ID_Type type = GS(id_cow->name);
+#ifdef NESTED_ID_NASTY_WORKAROUND
+ nested_id_hack_discard_pointers(id_cow);
+#endif
+ switch (type) {
+ case ID_OB:
+ {
+ /* TODO(sergey): This workaround is only to prevent free derived
+ * caches from modifying object->data. This is currently happening
+ * due to mesh/curve datablock boundbox tagging dirty.
+ */
+ Object *ob_cow = (Object *)id_cow;
+ ob_cow->data = NULL;
+ break;
+ }
+ case ID_AR:
+ {
+ bArmature *armature_cow = (bArmature *)id_cow;
+ armature_cow->edbo = NULL;
+ break;
+ }
+ case ID_ME:
+ {
+ Mesh *mesh_cow = (Mesh *)id_cow;
+ if (mesh_cow->edit_btmesh != NULL) {
+ BKE_editmesh_free_derivedmesh(mesh_cow->edit_btmesh);
+ MEM_freeN(mesh_cow->edit_btmesh);
+ mesh_cow->edit_btmesh = NULL;
+ }
+ break;
+ }
+ case ID_SCE:
+ {
+ /* Special case for scene: we use explicit function call which
+ * ensures no access to other datablocks is done.
+ */
+ Scene *scene = (Scene *)id_cow;
+ BKE_scene_free_ex(scene, false);
+ BKE_libblock_free_data(id_cow, false);
+ id_cow->name[0] = '\0';
+ return;
+ }
+ default:
+ break;
+ }
+ BKE_libblock_free_datablock(id_cow, 0);
+ BKE_libblock_free_data(id_cow, false);
+ /* Signal datablock as not being expanded. */
+ id_cow->name[0] = '\0';
+}
+
+void deg_evaluate_copy_on_write(struct ::Depsgraph *graph,
+ const IDDepsNode *id_node)
+{
+ const DEG::Depsgraph *depsgraph = reinterpret_cast<const DEG::Depsgraph *>(graph);
+ DEG_debug_print_eval(graph, __func__, id_node->id_orig->name, id_node->id_cow);
+ if (id_node->id_orig == &depsgraph->scene->id) {
+ /* NOTE: This is handled by eval_ctx setup routines, which
+ * ensures scene and view layer pointers are valid.
+ */
+ return;
+ }
+ deg_update_copy_on_write_datablock(depsgraph, id_node);
+}
+
+bool deg_validate_copy_on_write_datablock(ID *id_cow)
+{
+ if (id_cow == NULL) {
+ return false;
+ }
+ ValidateData data;
+ data.is_valid = true;
+ BKE_library_foreach_ID_link(NULL,
+ id_cow,
+ foreach_libblock_validate_callback,
+ &data,
+ IDWALK_NOP);
+ return data.is_valid;
+}
+
+void deg_tag_copy_on_write_id(ID *id_cow, const ID *id_orig)
+{
+ BLI_assert(id_cow != id_orig);
+ BLI_assert((id_orig->tag & LIB_TAG_COPY_ON_WRITE) == 0);
+ id_cow->tag |= LIB_TAG_COPY_ON_WRITE;
+ id_cow->orig_id = (ID *)id_orig;
+}
+
+bool deg_copy_on_write_is_expanded(const ID *id_cow)
+{
+ return check_datablock_expanded(id_cow);
+}
+
+bool deg_copy_on_write_is_needed(const ID *id_orig)
+{
+ const ID_Type id_type = GS(id_orig->name);
+ return !ELEM(id_type, ID_IM);
+}
+
+} // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h
new file mode 100644
index 00000000000..8fca90e9f5b
--- /dev/null
+++ b/source/blender/depsgraph/intern/eval/deg_eval_copy_on_write.h
@@ -0,0 +1,109 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 20137Blender Foundation.
+ * All rights reserved.
+ *
+ * Original Author: Sergey Sharybin
+ * Contributor(s): None Yet
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/depsgraph/intern/eval/deg_eval_copy_on_write.h
+ * \ingroup depsgraph
+ */
+
+#pragma once
+
+#include <stddef.h>
+
+struct ID;
+
+/* Unkomment this to have verbose log about original and CoW pointers
+ * logged, with detailed information when they are allocated, expanded
+ * and remapped.
+ */
+// #define DEG_DEBUG_COW_POINTERS
+
+#ifdef DEG_DEBUG_COW_POINTERS
+# define DEG_COW_PRINT(format, ...) printf(format, __VA_ARGS__);
+#else
+# define DEG_COW_PRINT(format, ...)
+#endif
+
+struct Depsgraph;
+
+namespace DEG {
+
+struct Depsgraph;
+struct DepsgraphNodeBuilder;
+struct IDDepsNode;
+
+/* Get fully expanded (ready for use) copy-on-write datablock for the given
+ * original datablock.
+ */
+ID *deg_expand_copy_on_write_datablock(const struct Depsgraph *depsgraph,
+ const IDDepsNode *id_node,
+ DepsgraphNodeBuilder *node_builder = NULL,
+ bool create_placeholders = false);
+ID *deg_expand_copy_on_write_datablock(const struct Depsgraph *depsgraph,
+ struct ID *id_orig,
+ DepsgraphNodeBuilder *node_builder = NULL,
+ bool create_placeholders = false);
+
+/* Makes sure given CoW datablock is brought back to state of the original
+ * datablock.
+ */
+ID *deg_update_copy_on_write_datablock(const struct Depsgraph *depsgraph,
+ const IDDepsNode *id_node);
+ID *deg_update_copy_on_write_datablock(const struct Depsgraph *depsgraph,
+ struct ID *id_orig);
+
+/* Helper function which frees memory used by copy-on-written databnlock. */
+void deg_free_copy_on_write_datablock(struct ID *id_cow);
+
+/* Callback function for depsgraph operation node which ensures copy-on-write
+ * datablock is ready for use by further evaluation routines.
+ */
+void deg_evaluate_copy_on_write(struct ::Depsgraph *depsgraph,
+ const struct IDDepsNode *id_node);
+
+/* Check that given ID is propely expanded and does not have any shallow
+ * copies inside.
+ */
+bool deg_validate_copy_on_write_datablock(ID *id_cow);
+
+/* Tag given ID block as being copy-on-wtritten. */
+void deg_tag_copy_on_write_id(struct ID *id_cow, const struct ID *id_orig);
+
+/* Check whether ID datablock is expanded.
+ *
+ * TODO(sergey): Make it an inline function or a macro.
+ */
+bool deg_copy_on_write_is_expanded(const struct ID *id_cow);
+
+/* Check whether copy-on-write datablock is needed for given ID.
+ *
+ * There are some exceptions on datablocks which are covered by dependency graph
+ * but which we don't want to start duplicating.
+ *
+ * This includes images.
+ */
+bool deg_copy_on_write_is_needed(const ID *id_orig);
+
+} // namespace DEG
diff --git a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
index e7764cf5a27..02f10130fed 100644
--- a/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
+++ b/source/blender/depsgraph/intern/eval/deg_eval_flush.cc
@@ -36,6 +36,7 @@
#include <deque>
#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
#include "BLI_task.h"
#include "BLI_ghash.h"
@@ -51,6 +52,7 @@ extern "C" {
#include "intern/nodes/deg_node_operation.h"
#include "intern/depsgraph_intern.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "util/deg_util_foreach.h"
namespace DEG {
@@ -70,19 +72,6 @@ typedef std::deque<OperationDepsNode *> FlushQueue;
namespace {
-// TODO(sergey): De-duplicate with depsgraph_tag,cc
-void lib_id_recalc_tag(Main *bmain, ID *id)
-{
- id->recalc |= ID_RECALC;
- DEG_id_type_tag(bmain, GS(id->name));
-}
-
-void lib_id_recalc_data_tag(Main *bmain, ID *id)
-{
- id->recalc |= ID_RECALC_DATA;
- DEG_id_type_tag(bmain, GS(id->name));
-}
-
void flush_init_operation_node_func(
void *__restrict data_v,
const int i,
@@ -146,8 +135,7 @@ BLI_INLINE void flush_handle_id_node(IDDepsNode *id_node)
}
/* TODO(sergey): We can reduce number of arguments here. */
-BLI_INLINE void flush_handle_component_node(Depsgraph * /*graph*/,
- IDDepsNode *id_node,
+BLI_INLINE void flush_handle_component_node(IDDepsNode *id_node,
ComponentDepsNode *comp_node,
FlushQueue *queue)
{
@@ -158,46 +146,17 @@ BLI_INLINE void flush_handle_component_node(Depsgraph * /*graph*/,
comp_node->done = COMPONENT_STATE_DONE;
/* Tag all required operations in component for update. */
foreach (OperationDepsNode *op, comp_node->operations) {
- op->flag |= DEPSOP_FLAG_NEEDS_UPDATE;
- }
- if (GS(id_node->id->name) == ID_OB) {
- Object *object = (Object *)id_node->id;
- /* This code is used to preserve those areas which does
- * direct object update,
+ /* We don't want to flush tags in "upstream" direction for
+ * certain types of operations.
*
- * Plus it ensures visibility changes and relations and
- * layers visibility update has proper flags to work with.
+ * TODO(sergey): Need a more generic solution for this.
*/
- switch (comp_node->type) {
- case DEG_NODE_TYPE_UNDEFINED:
- case DEG_NODE_TYPE_OPERATION:
- case DEG_NODE_TYPE_TIMESOURCE:
- case DEG_NODE_TYPE_ID_REF:
- case DEG_NODE_TYPE_SEQUENCER:
- case NUM_DEG_NODE_TYPES:
- /* Ignore, does not translate to object component. */
- BLI_assert(!"This should never happen!");
- break;
- case DEG_NODE_TYPE_ANIMATION:
- object->recalc |= OB_RECALC_TIME;
- break;
- case DEG_NODE_TYPE_TRANSFORM:
- object->recalc |= OB_RECALC_OB;
- break;
- case DEG_NODE_TYPE_GEOMETRY:
- case DEG_NODE_TYPE_EVAL_POSE:
- case DEG_NODE_TYPE_BONE:
- case DEG_NODE_TYPE_EVAL_PARTICLES:
- case DEG_NODE_TYPE_SHADING:
- case DEG_NODE_TYPE_CACHE:
- case DEG_NODE_TYPE_PROXY:
- object->recalc |= OB_RECALC_DATA;
- break;
- case DEG_NODE_TYPE_PARAMETERS:
- break;
+ if (op->opcode == DEG_OPCODE_PARTICLE_SETTINGS_EVAL) {
+ continue;
}
+ op->flag |= DEPSOP_FLAG_NEEDS_UPDATE;
}
- /* When some target changes bone, we might need to re-run the
+ /* when some target changes bone, we might need to re-run the
* whole IK solver, otherwise result might be unpredictable.
*/
if (comp_node->type == DEG_NODE_TYPE_BONE) {
@@ -240,19 +199,59 @@ BLI_INLINE OperationDepsNode *flush_schedule_children(
return result;
}
-BLI_INLINE void flush_editors_id_update(Main *bmain,
- Depsgraph *graph)
+void flush_engine_data_update(ID *id)
+{
+ if (GS(id->name) != ID_OB) {
+ return;
+ }
+ Object *object = (Object *)id;
+ LISTBASE_FOREACH(ObjectEngineData *, engine_data, &object->drawdata) {
+ engine_data->recalc |= id->recalc;
+ }
+}
+
+/* NOTE: It will also accumulate flags from changed components. */
+void flush_editors_id_update(Main *bmain,
+ Depsgraph *graph,
+ const DEGEditorUpdateContext *update_ctx)
{
foreach (IDDepsNode *id_node, graph->id_nodes) {
if (id_node->done != ID_STATE_MODIFIED) {
continue;
}
+ DEG_id_type_tag(bmain, GS(id_node->id_orig->name));
/* TODO(sergey): Do we need to pass original or evaluated ID here? */
- ID *id = id_node->id;
- deg_editors_id_update(bmain, id);
- lib_id_recalc_tag(bmain, id);
- /* TODO(sergey): For until we've got proper data nodes in the graph. */
- lib_id_recalc_data_tag(bmain, id);
+ ID *id_orig = id_node->id_orig;
+ ID *id_cow = id_node->id_cow;
+ /* Copy tag from original data to CoW storage.
+ * This is because DEG_id_tag_update() sets tags on original
+ * data.
+ */
+ id_cow->recalc |= (id_orig->recalc & ID_RECALC_ALL);
+ /* Gather recalc flags from all changed components. */
+ GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, id_node->components)
+ {
+ if (comp_node->done != COMPONENT_STATE_DONE) {
+ continue;
+ }
+ DepsNodeFactory *factory = deg_type_get_factory(comp_node->type);
+ BLI_assert(factory != NULL);
+ id_cow->recalc |= factory->id_recalc_tag();
+ }
+ GHASH_FOREACH_END();
+ DEG_DEBUG_PRINTF((::Depsgraph *)graph,
+ EVAL, "Accumulated recalc bits for %s: %u\n",
+ id_orig->name, (unsigned int)id_cow->recalc);
+ /* Inform editors. */
+ if (deg_copy_on_write_is_expanded(id_cow)) {
+ deg_editors_id_update(update_ctx, id_cow);
+ /* ID may need to get its auto-override operations refreshed. */
+ if (ID_IS_STATIC_OVERRIDE_AUTO(id_orig)) {
+ id_orig->tag |= LIB_TAG_OVERRIDESTATIC_AUTOREFRESH;
+ }
+ /* Inform draw engines that something was changed. */
+ flush_engine_data_update(id_cow);
+ }
}
}
@@ -275,6 +274,12 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
/* Starting from the tagged "entry" nodes, flush outwards. */
FlushQueue queue;
flush_schedule_entrypoints(graph, &queue);
+ /* Prepare update context for editors. */
+ DEGEditorUpdateContext update_ctx;
+ update_ctx.bmain = bmain;
+ update_ctx.depsgraph = (::Depsgraph *)graph;
+ update_ctx.scene = graph->scene;
+ update_ctx.view_layer = graph->view_layer;
/* Do actual flush. */
while (!queue.empty()) {
OperationDepsNode *op_node = queue.front();
@@ -286,8 +291,7 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
ComponentDepsNode *comp_node = op_node->owner;
IDDepsNode *id_node = comp_node->owner;
flush_handle_id_node(id_node);
- flush_handle_component_node(graph,
- id_node,
+ flush_handle_component_node(id_node,
comp_node,
&queue);
/* Flush to nodes along links. */
@@ -295,10 +299,10 @@ void deg_graph_flush_updates(Main *bmain, Depsgraph *graph)
}
}
/* Inform editors about all changes. */
- flush_editors_id_update(bmain, graph);
+ flush_editors_id_update(bmain, graph, &update_ctx);
}
-static void graph_clear_func(
+static void graph_clear_operation_func(
void *__restrict data_v,
const int i,
const ParallelRangeTLS *__restrict /*tls*/)
@@ -309,18 +313,41 @@ static void graph_clear_func(
node->flag &= ~(DEPSOP_FLAG_DIRECTLY_MODIFIED | DEPSOP_FLAG_NEEDS_UPDATE);
}
+static void graph_clear_id_node_func(
+ void *__restrict data_v,
+ const int i,
+ const ParallelRangeTLS *__restrict /*tls*/)
+{
+ Depsgraph *graph = (Depsgraph *)data_v;
+ IDDepsNode *id_node = graph->id_nodes[i];
+ id_node->id_cow->recalc &= ~ID_RECALC_ALL;
+}
+
/* Clear tags from all operation nodes. */
void deg_graph_clear_tags(Depsgraph *graph)
{
/* Go over all operation nodes, clearing tags. */
- const int num_operations = graph->operations.size();
- ParallelRangeSettings settings;
- BLI_parallel_range_settings_defaults(&settings);
- settings.min_iter_per_thread = 1024;
- BLI_task_parallel_range(0, num_operations,
- graph,
- graph_clear_func,
- &settings);
+ {
+ const int num_operations = graph->operations.size();
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.min_iter_per_thread = 1024;
+ BLI_task_parallel_range(0, num_operations,
+ graph,
+ graph_clear_operation_func,
+ &settings);
+ }
+ /* Go over all ID nodes nodes, clearing tags. */
+ {
+ const int num_id_nodes = graph->id_nodes.size();
+ ParallelRangeSettings settings;
+ BLI_parallel_range_settings_defaults(&settings);
+ settings.min_iter_per_thread = 1024;
+ BLI_task_parallel_range(0, num_id_nodes,
+ graph,
+ graph_clear_id_node_func,
+ &settings);
+ }
/* Clear any entry tags which haven't been flushed. */
BLI_gset_clear(graph->entry_tags, NULL);
}
diff --git a/source/blender/depsgraph/intern/nodes/deg_node.cc b/source/blender/depsgraph/intern/nodes/deg_node.cc
index d72ca384044..e09ba8c4f05 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node.cc
@@ -34,6 +34,7 @@
#include "BLI_utildefines.h"
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node_component.h"
#include "intern/nodes/deg_node_id.h"
#include "intern/nodes/deg_node_operation.h"
@@ -41,6 +42,7 @@
#include "intern/depsgraph_intern.h"
#include "util/deg_util_foreach.h"
+#include "util/deg_util_function.h"
namespace DEG {
@@ -101,10 +103,7 @@ DepsNode::~DepsNode()
/* Generic identifier for Depsgraph Nodes. */
string DepsNode::identifier() const
{
- char typebuf[7];
- sprintf(typebuf, "(%d)", type);
-
- return string(typebuf) + " : " + name;
+ return string(nodeTypeAsString(type)) + " : " + name;
}
eDepsNode_Class DepsNode::get_class() const {
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.cc b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
index 755b10c3f1d..786faa6e86c 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_component.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_component.cc
@@ -124,8 +124,7 @@ static void comp_node_hash_value_free(void *value_v)
ComponentDepsNode::ComponentDepsNode() :
entry_operation(NULL),
- exit_operation(NULL),
- layers(0)
+ exit_operation(NULL)
{
operations_map = BLI_ghash_new(comp_node_hash_key,
comp_node_hash_key_cmp,
@@ -158,10 +157,7 @@ string ComponentDepsNode::identifier() const
char typebuf[16];
sprintf(typebuf, "(%d)", type);
- char layers[16];
- sprintf(layers, "%u", this->layers);
-
- return string(typebuf) + name + " : " + idname + " (Layers: " + layers + ")";
+ return string(typebuf) + name + " : " + idname;
}
OperationDepsNode *ComponentDepsNode::find_operation(OperationIDKey key) const
@@ -233,7 +229,7 @@ OperationDepsNode *ComponentDepsNode::add_operation(const DepsEvalOperationCb& o
OperationDepsNode *op_node = find_operation(opcode, name, name_tag);
if (!op_node) {
DepsNodeFactory *factory = deg_type_get_factory(DEG_NODE_TYPE_OPERATION);
- op_node = (OperationDepsNode *)factory->create_node(this->owner->id, "", name);
+ op_node = (OperationDepsNode *)factory->create_node(this->owner->id_orig, "", name);
/* register opnode in this component's operation set */
OperationIDKey *key = OBJECT_GUARDED_NEW(OperationIDKey, opcode, name, name_tag);
@@ -346,7 +342,7 @@ OperationDepsNode *ComponentDepsNode::get_exit_operation()
return NULL;
}
-void ComponentDepsNode::finalize_build()
+void ComponentDepsNode::finalize_build(Depsgraph * /*graph*/)
{
operations.reserve(BLI_ghash_len(operations_map));
GHASH_FOREACH_BEGIN(OperationDepsNode *, op_node, operations_map)
@@ -381,36 +377,41 @@ void BoneComponentDepsNode::init(const ID *id, const char *subdata)
/* Register all components. =============================== */
-DEG_COMPONENT_NODE_DEFINE(Animation, ANIMATION, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Bone, BONE, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Cache, CACHE, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Geometry, GEOMETRY, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Parameters, PARAMETERS, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Particles, EVAL_PARTICLES, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Proxy, PROXY, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Pose, EVAL_POSE, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Sequencer, SEQUENCER, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Shading, SHADING, ID_RECALC_NONE);
-DEG_COMPONENT_NODE_DEFINE(Transform, TRANSFORM, ID_RECALC_NONE);
+DEG_COMPONENT_NODE_DEFINE(Animation, ANIMATION, ID_RECALC_ANIMATION);
+DEG_COMPONENT_NODE_DEFINE(BatchCache, BATCH_CACHE, ID_RECALC_DRAW_CACHE);
+DEG_COMPONENT_NODE_DEFINE(Bone, BONE, ID_RECALC_GEOMETRY);
+DEG_COMPONENT_NODE_DEFINE(Cache, CACHE, ID_RECALC);
+DEG_COMPONENT_NODE_DEFINE(CopyOnWrite, COPY_ON_WRITE, ID_RECALC_COPY_ON_WRITE);
+DEG_COMPONENT_NODE_DEFINE(Geometry, GEOMETRY, ID_RECALC_GEOMETRY);
+DEG_COMPONENT_NODE_DEFINE(LayerCollections, LAYER_COLLECTIONS, ID_RECALC_COLLECTIONS);
+DEG_COMPONENT_NODE_DEFINE(Parameters, PARAMETERS, ID_RECALC);
+DEG_COMPONENT_NODE_DEFINE(Particles, EVAL_PARTICLES, ID_RECALC_GEOMETRY);
+DEG_COMPONENT_NODE_DEFINE(Proxy, PROXY, ID_RECALC_GEOMETRY);
+DEG_COMPONENT_NODE_DEFINE(Pose, EVAL_POSE, ID_RECALC_GEOMETRY);
+DEG_COMPONENT_NODE_DEFINE(Sequencer, SEQUENCER, ID_RECALC);
+DEG_COMPONENT_NODE_DEFINE(Shading, SHADING, ID_RECALC_DRAW);
+DEG_COMPONENT_NODE_DEFINE(ShadingParameters, SHADING_PARAMETERS, ID_RECALC_DRAW);
+DEG_COMPONENT_NODE_DEFINE(Transform, TRANSFORM, ID_RECALC_TRANSFORM);
/* Node Types Register =================================== */
void deg_register_component_depsnodes()
{
- deg_register_node_typeinfo(&DNTI_PARAMETERS);
- deg_register_node_typeinfo(&DNTI_PROXY);
deg_register_node_typeinfo(&DNTI_ANIMATION);
- deg_register_node_typeinfo(&DNTI_TRANSFORM);
- deg_register_node_typeinfo(&DNTI_GEOMETRY);
- deg_register_node_typeinfo(&DNTI_SEQUENCER);
-
- deg_register_node_typeinfo(&DNTI_EVAL_POSE);
deg_register_node_typeinfo(&DNTI_BONE);
-
+ deg_register_node_typeinfo(&DNTI_CACHE);
+ deg_register_node_typeinfo(&DNTI_BATCH_CACHE);
+ deg_register_node_typeinfo(&DNTI_COPY_ON_WRITE);
+ deg_register_node_typeinfo(&DNTI_GEOMETRY);
+ deg_register_node_typeinfo(&DNTI_LAYER_COLLECTIONS);
+ deg_register_node_typeinfo(&DNTI_PARAMETERS);
deg_register_node_typeinfo(&DNTI_EVAL_PARTICLES);
+ deg_register_node_typeinfo(&DNTI_PROXY);
+ deg_register_node_typeinfo(&DNTI_EVAL_POSE);
+ deg_register_node_typeinfo(&DNTI_SEQUENCER);
deg_register_node_typeinfo(&DNTI_SHADING);
-
- deg_register_node_typeinfo(&DNTI_CACHE);
+ deg_register_node_typeinfo(&DNTI_SHADING_PARAMETERS);
+ deg_register_node_typeinfo(&DNTI_TRANSFORM);
}
} // namespace DEG
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_component.h b/source/blender/depsgraph/intern/nodes/deg_node_component.h
index 985716deaac..5b6461f950e 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_component.h
+++ b/source/blender/depsgraph/intern/nodes/deg_node_component.h
@@ -39,8 +39,6 @@ struct ID;
struct bPoseChannel;
struct GHash;
-struct EvaluationContext;
-
namespace DEG {
struct Depsgraph;
@@ -127,7 +125,7 @@ struct ComponentDepsNode : public DepsNode {
OperationDepsNode *get_entry_operation();
OperationDepsNode *get_exit_operation();
- void finalize_build();
+ void finalize_build(Depsgraph *graph);
IDDepsNode *owner;
@@ -147,9 +145,7 @@ struct ComponentDepsNode : public DepsNode {
OperationDepsNode *exit_operation;
// XXX: a poll() callback to check if component's first node can be started?
-
- /* Temporary bitmask, used during graph construction. */
- unsigned int layers;
+ virtual bool depends_on_cow() { return true; }
};
/* ---------------------------------------- */
@@ -173,14 +169,18 @@ struct ComponentDepsNode : public DepsNode {
}
DEG_COMPONENT_NODE_DECLARE_GENERIC(Animation);
+DEG_COMPONENT_NODE_DECLARE_GENERIC(BatchCache);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Cache);
+DEG_COMPONENT_NODE_DECLARE_GENERIC(CopyOnWrite);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Geometry);
+DEG_COMPONENT_NODE_DECLARE_GENERIC(LayerCollections);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Parameters);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Particles);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Proxy);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Pose);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Sequencer);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Shading);
+DEG_COMPONENT_NODE_DECLARE_GENERIC(ShadingParameters);
DEG_COMPONENT_NODE_DECLARE_GENERIC(Transform);
/* Bone Component */
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_id.cc b/source/blender/depsgraph/intern/nodes/deg_node_id.cc
index 478cc2863b0..9f161db73ad 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_id.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_id.cc
@@ -41,8 +41,12 @@ extern "C" {
#include "DNA_anim_types.h"
#include "BKE_animsys.h"
+#include "BKE_library.h"
}
+#include "DEG_depsgraph.h"
+
+#include "intern/eval/deg_eval_copy_on_write.h"
#include "intern/nodes/deg_node_time.h"
#include "intern/depsgraph_intern.h"
@@ -58,8 +62,8 @@ IDDepsNode::ComponentIDKey::ComponentIDKey(eDepsNode_Type type,
bool IDDepsNode::ComponentIDKey::operator== (const ComponentIDKey &other) const
{
- return type == other.type &&
- STREQ(name, other.name);
+ return type == other.type &&
+ STREQ(name, other.name);
}
static unsigned int id_deps_node_hash_key(const void *key_v)
@@ -95,33 +99,86 @@ static void id_deps_node_hash_value_free(void *value_v)
/* Initialize 'id' node - from pointer data given. */
void IDDepsNode::init(const ID *id, const char *UNUSED(subdata))
{
- /* Store ID-pointer. */
BLI_assert(id != NULL);
- this->id = (ID *)id;
- this->layers = (1 << 20) - 1;
- this->eval_flags = 0;
-
- /* For object we initialize layers to layer from base. */
- if (GS(id->name) == ID_OB) {
- this->layers = 0;
- }
+ /* Store ID-pointer. */
+ id_orig = (ID *)id;
+ eval_flags = 0;
+ linked_state = DEG_ID_LINKED_INDIRECTLY;
components = BLI_ghash_new(id_deps_node_hash_key,
id_deps_node_hash_key_cmp,
"Depsgraph id components hash");
+}
- /* NOTE: components themselves are created if/when needed.
- * This prevents problems with components getting added
- * twice if an ID-Ref needs to be created to house it...
+void IDDepsNode::init_copy_on_write(ID *id_cow_hint)
+{
+ /* Early output for non-copy-on-write case: we keep CoW pointer same as
+ * an original one.
*/
+ if (!DEG_depsgraph_use_copy_on_write()) {
+ UNUSED_VARS(id_cow_hint);
+ id_cow = id_orig;
+ return;
+ }
+ /* Create pointer as early as possible, so we can use it for function
+ * bindings. Rest of data we'll be copying to the new datablock when
+ * it is actually needed.
+ */
+ if (id_cow_hint != NULL) {
+ // BLI_assert(deg_copy_on_write_is_needed(id_orig));
+ if (deg_copy_on_write_is_needed(id_orig)) {
+ id_cow = id_cow_hint;
+ }
+ else {
+ id_cow = id_orig;
+ }
+ }
+ else if (deg_copy_on_write_is_needed(id_orig)) {
+ id_cow = (ID *)BKE_libblock_alloc_notest(GS(id_orig->name));
+ DEG_COW_PRINT("Create shallow copy for %s: id_orig=%p id_cow=%p\n",
+ id_orig->name, id_orig, id_cow);
+ deg_tag_copy_on_write_id(id_cow, id_orig);
+ }
+ else {
+ id_cow = id_orig;
+ }
}
/* Free 'id' node. */
IDDepsNode::~IDDepsNode()
{
+ destroy();
+}
+
+void IDDepsNode::destroy()
+{
+ if (id_orig == NULL) {
+ return;
+ }
+
BLI_ghash_free(components,
id_deps_node_hash_key_free,
id_deps_node_hash_value_free);
+
+ /* Free memory used by this CoW ID. */
+ if (id_cow != id_orig && id_cow != NULL) {
+ deg_free_copy_on_write_datablock(id_cow);
+ MEM_freeN(id_cow);
+ DEG_COW_PRINT("Destroy CoW for %s: id_orig=%p id_cow=%p\n",
+ id_orig->name, id_orig, id_cow);
+ }
+
+ /* Tag that the node is freed. */
+ id_orig = NULL;
+}
+
+string IDDepsNode::identifier() const
+{
+ char orig_ptr[24], cow_ptr[24];
+ BLI_snprintf(orig_ptr, sizeof(orig_ptr), "%p", id_orig);
+ BLI_snprintf(cow_ptr, sizeof(cow_ptr), "%p", id_cow);
+ return string(nodeTypeAsString(type)) + " : " + name +
+ " (orig: " + orig_ptr + ", eval: " + cow_ptr + ")";
}
ComponentDepsNode *IDDepsNode::find_component(eDepsNode_Type type,
@@ -137,7 +194,7 @@ ComponentDepsNode *IDDepsNode::add_component(eDepsNode_Type type,
ComponentDepsNode *comp_node = find_component(type, name);
if (!comp_node) {
DepsNodeFactory *factory = deg_type_get_factory(type);
- comp_node = (ComponentDepsNode *)factory->create_node(this->id, "", name);
+ comp_node = (ComponentDepsNode *)factory->create_node(this->id_orig, "", name);
/* Register. */
ComponentIDKey *key = OBJECT_GUARDED_NEW(ComponentIDKey, type, name);
@@ -151,27 +208,17 @@ void IDDepsNode::tag_update(Depsgraph *graph)
{
GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components)
{
- /* TODO(sergey): What about drievrs? */
- bool do_component_tag = comp_node->type != DEG_NODE_TYPE_ANIMATION;
- if (comp_node->type == DEG_NODE_TYPE_ANIMATION) {
- AnimData *adt = BKE_animdata_from_id(id);
- /* Animation data might be null if relations are tagged for update. */
- if (adt != NULL && (adt->recalc & ADT_RECALC_ANIM)) {
- do_component_tag = true;
- }
- }
- if (do_component_tag) {
- comp_node->tag_update(graph);
- }
+ comp_node->tag_update(graph);
}
GHASH_FOREACH_END();
}
-void IDDepsNode::finalize_build()
+void IDDepsNode::finalize_build(Depsgraph *graph)
{
+ /* Finalize build of all components. */
GHASH_FOREACH_BEGIN(ComponentDepsNode *, comp_node, components)
{
- comp_node->finalize_build();
+ comp_node->finalize_build(graph);
}
GHASH_FOREACH_END();
}
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_id.h b/source/blender/depsgraph/intern/nodes/deg_node_id.h
index 55022916c4d..12dbc16b4fa 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_id.h
+++ b/source/blender/depsgraph/intern/nodes/deg_node_id.h
@@ -47,7 +47,11 @@ struct IDDepsNode : public DepsNode {
};
void init(const ID *id, const char *subdata);
+ void init_copy_on_write(ID *id_cow_hint = NULL);
~IDDepsNode();
+ void destroy();
+
+ virtual string identifier() const;
ComponentDepsNode *find_component(eDepsNode_Type type,
const char *name = "") const;
@@ -56,23 +60,23 @@ struct IDDepsNode : public DepsNode {
void tag_update(Depsgraph *graph);
- void finalize_build();
+ void finalize_build(Depsgraph *graph);
/* ID Block referenced. */
- ID *id;
+ ID *id_orig;
+ ID *id_cow;
/* Hash to make it faster to look up components. */
GHash *components;
- /* Layers of this node with accumulated layers of it's output relations. */
- unsigned int layers;
-
/* Additional flags needed for scene evaluation.
* TODO(sergey): Only needed for until really granular updates
* of all the entities.
*/
int eval_flags;
+ eDepsNode_LinkedState_Type linked_state;
+
DEG_DEPSNODE_DECLARE;
};
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
index cbc0fbb4241..e82bbbc0e8a 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_operation.cc
@@ -56,7 +56,7 @@ OperationDepsNode::~OperationDepsNode()
string OperationDepsNode::identifier() const
{
- return string(DEG_OPNAMES[opcode]) + "(" + name + ")";
+ return string(operationCodeAsString(opcode)) + "(" + name + ")";
}
/* Full node identifier, including owner name.
diff --git a/source/blender/depsgraph/intern/nodes/deg_node_time.cc b/source/blender/depsgraph/intern/nodes/deg_node_time.cc
index 230488b2328..7b871d6d42b 100644
--- a/source/blender/depsgraph/intern/nodes/deg_node_time.cc
+++ b/source/blender/depsgraph/intern/nodes/deg_node_time.cc
@@ -33,10 +33,13 @@
#include "intern/depsgraph_intern.h"
#include "util/deg_util_foreach.h"
+#include "DNA_scene_types.h"
+
namespace DEG {
void TimeSourceDepsNode::tag_update(Depsgraph *graph)
{
+ graph->scene_cow->id.recalc |= ID_RECALC_TIME;
foreach (DepsRelation *rel, outlinks) {
DepsNode *node = rel->to;
node->tag_update(graph);
diff --git a/source/blender/depsgraph/util/deg_util_foreach.h b/source/blender/depsgraph/util/deg_util_foreach.h
index cb7361fc708..e00aa5dbb5e 100644
--- a/source/blender/depsgraph/util/deg_util_foreach.h
+++ b/source/blender/depsgraph/util/deg_util_foreach.h
@@ -36,13 +36,5 @@
# include <boost/foreach.hpp>
# define foreach BOOST_FOREACH
#else
-#pragma message("No available foreach() implementation. Using stub instead, disabling new depsgraph")
-
-#ifndef WITH_LEGACY_DEPSGRAPH
-# error "Unable to build new depsgraph and legacy one is disabled."
-#endif
-
-#define DISABLE_NEW_DEPSGRAPH
-
-# define foreach(x, y) for (x; false; (void)y)
+# error "Depsgraph requires either Boost or C++11 for range-based loops."
#endif
diff --git a/source/blender/depsgraph/util/deg_util_function.h b/source/blender/depsgraph/util/deg_util_function.h
index 99625e57f4b..41669919c99 100644
--- a/source/blender/depsgraph/util/deg_util_function.h
+++ b/source/blender/depsgraph/util/deg_util_function.h
@@ -47,64 +47,5 @@ using boost::function;
#define function_bind boost::bind
#else
-
-#pragma message("No available function binding implementation. Using stub instead, disabling new depsgraph")
-
-#ifndef WITH_LEGACY_DEPSGRAPH
-# error "Unable to build new depsgraph and legacy one is disabled."
-#endif
-
-#define DISABLE_NEW_DEPSGRAPH
-
-#include "BLI_utildefines.h"
-#include <cstdlib>
-
-template<typename T>
-class function {
-public:
- function() {};
- function(void *) {}
- operator bool() const { return false; }
- bool operator== (void *) { return false; }
-
- template<typename T1>
- void operator() (T1) {
- BLI_assert(!"Should not be used");
- }
-};
-
-class Wrap {
-public:
- Wrap() {}
- template <typename T>
- Wrap(T /*arg*/) {}
-};
-
-template <typename T>
-void *function_bind(T func,
- Wrap arg1 = Wrap(),
- Wrap arg2 = Wrap(),
- Wrap arg3 = Wrap(),
- Wrap arg4 = Wrap(),
- Wrap arg5 = Wrap(),
- Wrap arg6 = Wrap(),
- Wrap arg7 = Wrap())
-{
- BLI_assert(!"Should not be used");
- (void)func;
- (void)arg1;
- (void)arg2;
- (void)arg3;
- (void)arg4;
- (void)arg5;
- (void)arg6;
- (void)arg7;
- return NULL;
-}
-
-#define _1 Wrap()
-#define _2 Wrap()
-#define _3 Wrap()
-#define _4 Wrap()
-
+# error "Depsgraph requires either Boost or C++11 for function bindings."
#endif
diff --git a/source/blender/draw/CMakeLists.txt b/source/blender/draw/CMakeLists.txt
new file mode 100644
index 00000000000..53d46575a62
--- /dev/null
+++ b/source/blender/draw/CMakeLists.txt
@@ -0,0 +1,282 @@
+# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# The Original Code is Copyright (C) 2016, Blender Foundation
+# All rights reserved.
+#
+# The Original Code is: all of this file.
+#
+# Contributor(s): Blender Institute
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+ intern
+ modes
+
+ ../blenfont
+ ../blenkernel
+ ../blenlib
+ ../blentranslation
+ ../bmesh
+ ../depsgraph
+ ../editors/include
+ ../editors/space_view3d
+ ../gpu
+ ../imbuf
+ ../makesdna
+ ../makesrna
+ ../render/extern/include
+ ../render/intern/include
+ ../windowmanager
+
+ ../../../intern/glew-mx
+ ../../../intern/guardedalloc
+)
+
+set(INC_SYS
+ ${GLEW_INCLUDE_PATH}
+)
+
+set(SRC
+ intern/draw_armature.c
+ intern/draw_cache.c
+ intern/draw_cache_impl_curve.c
+ intern/draw_cache_impl_displist.c
+ intern/draw_cache_impl_lattice.c
+ intern/draw_cache_impl_mesh.c
+ intern/draw_cache_impl_metaball.c
+ intern/draw_cache_impl_particles.c
+ intern/draw_common.c
+ intern/draw_instance_data.c
+ intern/draw_manager.c
+ intern/draw_manager_data.c
+ intern/draw_manager_exec.c
+ intern/draw_manager_shader.c
+ intern/draw_manager_text.c
+ intern/draw_manager_texture.c
+ intern/draw_manager_profiling.c
+ intern/draw_view.c
+ modes/edit_armature_mode.c
+ modes/edit_curve_mode.c
+ modes/edit_lattice_mode.c
+ modes/edit_mesh_mode.c
+ modes/edit_mesh_mode_text.c
+ modes/edit_metaball_mode.c
+ modes/edit_surface_mode.c
+ modes/edit_text_mode.c
+ modes/object_mode.c
+ modes/overlay_mode.c
+ modes/paint_texture_mode.c
+ modes/paint_vertex_mode.c
+ modes/paint_weight_mode.c
+ modes/particle_mode.c
+ modes/pose_mode.c
+ modes/sculpt_mode.c
+ engines/basic/basic_engine.c
+ engines/clay/clay_engine.c
+ engines/eevee/eevee_bloom.c
+ engines/eevee/eevee_data.c
+ engines/eevee/eevee_depth_of_field.c
+ engines/eevee/eevee_effects.c
+ engines/eevee/eevee_engine.c
+ engines/eevee/eevee_lightprobes.c
+ engines/eevee/eevee_lights.c
+ engines/eevee/eevee_materials.c
+ engines/eevee/eevee_mist.c
+ engines/eevee/eevee_motion_blur.c
+ engines/eevee/eevee_occlusion.c
+ engines/eevee/eevee_render.c
+ engines/eevee/eevee_screen_raytrace.c
+ engines/eevee/eevee_subsurface.c
+ engines/eevee/eevee_temporal_sampling.c
+ engines/eevee/eevee_volumes.c
+ engines/workbench/workbench_engine.c
+ engines/workbench/workbench_materials.c
+ engines/workbench/workbench_studiolight.c
+ engines/workbench/solid_mode.c
+ engines/external/external_engine.c
+
+ DRW_engine.h
+ intern/DRW_render.h
+ intern/draw_cache.h
+ intern/draw_cache_impl.h
+ intern/draw_common.h
+ intern/draw_instance_data.h
+ intern/draw_manager.h
+ intern/draw_manager_text.h
+ intern/draw_manager_profiling.h
+ intern/draw_view.h
+ modes/draw_mode_engines.h
+ modes/edit_mesh_mode_intern.h
+ engines/basic/basic_engine.h
+ engines/clay/clay_engine.h
+ engines/eevee/eevee_engine.h
+ engines/eevee/eevee_lut.h
+ engines/eevee/eevee_private.h
+ engines/external/external_engine.h
+)
+
+if(WITH_CLAY_ENGINE)
+ add_definitions(-DWITH_CLAY_ENGINE)
+endif()
+
+data_to_c_simple(engines/clay/shaders/clay_frag.glsl SRC)
+data_to_c_simple(engines/clay/shaders/clay_fxaa.glsl SRC)
+data_to_c_simple(engines/clay/shaders/clay_copy.glsl SRC)
+data_to_c_simple(engines/clay/shaders/clay_prepass_frag.glsl SRC)
+data_to_c_simple(engines/clay/shaders/clay_vert.glsl SRC)
+data_to_c_simple(engines/clay/shaders/clay_particle_vert.glsl SRC)
+data_to_c_simple(engines/clay/shaders/clay_particle_strand_frag.glsl SRC)
+data_to_c_simple(engines/clay/shaders/ssao_alchemy.glsl SRC)
+data_to_c_simple(engines/clay/shaders/ssao_groundtruth.glsl SRC)
+
+data_to_c_simple(engines/eevee/shaders/ambient_occlusion_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/default_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/default_world_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/background_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/concentric_samples_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/common_uniforms_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lamps_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_geom.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_cube_display_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_cube_display_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_grid_display_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_grid_display_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_grid_fill_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_planar_display_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_planar_display_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lit_surface_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lit_surface_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_bloom_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_dof_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_dof_geom.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_dof_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_downsample_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_downsample_cube_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_gtao_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_velocity_resolve_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_minmaxz_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_mist_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_motion_blur_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_ssr_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_subsurface_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/effect_temporal_aa.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/prepass_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/prepass_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/shadow_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/shadow_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/shadow_store_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/shadow_copy_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/bsdf_lut_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/btdf_lut_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/bsdf_direct_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/bsdf_common_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/irradiance_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/octahedron_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/bsdf_sampling_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/raytrace_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/ltc_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/ssr_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/update_noise_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/volumetric_lib.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/volumetric_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/volumetric_geom.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/volumetric_vert.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/volumetric_resolve_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/volumetric_scatter_frag.glsl SRC)
+data_to_c_simple(engines/eevee/shaders/volumetric_integration_frag.glsl SRC)
+
+data_to_c_simple(engines/workbench/shaders/workbench_prepass_vert.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_prepass_frag.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_composite_frag.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_shadow_vert.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_shadow_geom.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_background_lib.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_common_lib.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_data_lib.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_object_overlap_lib.glsl SRC)
+data_to_c_simple(engines/workbench/shaders/workbench_world_light_lib.glsl SRC)
+
+data_to_c_simple(modes/shaders/common_globals_lib.glsl SRC)
+data_to_c_simple(modes/shaders/common_view_lib.glsl SRC)
+data_to_c_simple(modes/shaders/common_fxaa_lib.glsl SRC)
+data_to_c_simple(modes/shaders/common_fullscreen_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_axes_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_sphere_solid_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_sphere_solid_frag.glsl SRC)
+data_to_c_simple(modes/shaders/armature_sphere_outline_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_envelope_solid_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_envelope_solid_frag.glsl SRC)
+data_to_c_simple(modes/shaders/armature_envelope_outline_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_envelope_distance_frag.glsl SRC)
+data_to_c_simple(modes/shaders/armature_shape_solid_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_shape_solid_frag.glsl SRC)
+data_to_c_simple(modes/shaders/armature_shape_outline_vert.glsl SRC)
+data_to_c_simple(modes/shaders/armature_shape_outline_geom.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_frag.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_geom_tri.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_geom_edge.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_loosevert_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_facedot_frag.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_facedot_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_mix_frag.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_facefill_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_mesh_overlay_facefill_frag.glsl SRC)
+data_to_c_simple(modes/shaders/edit_curve_overlay_frag.glsl SRC)
+data_to_c_simple(modes/shaders/edit_curve_overlay_handle_geom.glsl SRC)
+data_to_c_simple(modes/shaders/edit_curve_overlay_loosevert_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_lattice_overlay_frag.glsl SRC)
+data_to_c_simple(modes/shaders/edit_lattice_overlay_loosevert_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_normals_vert.glsl SRC)
+data_to_c_simple(modes/shaders/edit_normals_geom.glsl SRC)
+data_to_c_simple(modes/shaders/overlay_face_orientation_frag.glsl SRC)
+data_to_c_simple(modes/shaders/overlay_face_orientation_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_empty_image_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_empty_image_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_outline_resolve_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_outline_expand_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_outline_detect_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_outline_prepass_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_grid_frag.glsl SRC)
+data_to_c_simple(modes/shaders/object_grid_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_lightprobe_grid_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_mball_handles_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_particle_prim_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_particle_dot_vert.glsl SRC)
+data_to_c_simple(modes/shaders/object_particle_dot_frag.glsl SRC)
+data_to_c_simple(modes/shaders/paint_texture_frag.glsl SRC)
+data_to_c_simple(modes/shaders/paint_texture_vert.glsl SRC)
+data_to_c_simple(modes/shaders/paint_vertex_frag.glsl SRC)
+data_to_c_simple(modes/shaders/paint_vertex_vert.glsl SRC)
+data_to_c_simple(modes/shaders/paint_wire_frag.glsl SRC)
+data_to_c_simple(modes/shaders/paint_wire_vert.glsl SRC)
+data_to_c_simple(modes/shaders/paint_vert_frag.glsl SRC)
+
+list(APPEND INC
+)
+
+blender_add_lib(bf_draw "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/draw/DRW_engine.h b/source/blender/draw/DRW_engine.h
new file mode 100644
index 00000000000..3afbe3b66e2
--- /dev/null
+++ b/source/blender/draw/DRW_engine.h
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file DRW_engine.h
+ * \ingroup draw
+ */
+
+#ifndef __DRW_ENGINE_H__
+#define __DRW_ENGINE_H__
+
+#include "BLI_sys_types.h" /* for bool */
+
+struct ARegion;
+struct CollectionEngineSettings;
+struct Depsgraph;
+struct DRWPass;
+struct DRWInstanceDataList;
+struct Main;
+struct Material;
+struct Scene;
+struct DrawEngineType;
+struct ID;
+struct IDProperty;
+struct bContext;
+struct Object;
+struct ViewLayer;
+struct ViewContext;
+struct ViewportEngineData;
+struct View3D;
+struct rcti;
+struct GPUMaterial;
+struct GPUOffScreen;
+struct GPUViewport;
+struct RenderEngine;
+struct RenderEngineType;
+struct WorkSpace;
+
+#include "DNA_object_enums.h"
+
+/* Buffer and textures used by the viewport by default */
+typedef struct DefaultFramebufferList {
+ struct GPUFrameBuffer *default_fb;
+ struct GPUFrameBuffer *color_only_fb;
+ struct GPUFrameBuffer *depth_only_fb;
+ struct GPUFrameBuffer *multisample_fb;
+} DefaultFramebufferList;
+
+typedef struct DefaultTextureList {
+ struct GPUTexture *color;
+ struct GPUTexture *depth;
+ struct GPUTexture *multisample_color;
+ struct GPUTexture *multisample_depth;
+} DefaultTextureList;
+
+void DRW_engines_register(void);
+void DRW_engines_free(void);
+
+bool DRW_engine_render_support(struct DrawEngineType *draw_engine_type);
+void DRW_engine_register(struct DrawEngineType *draw_engine_type);
+void DRW_engine_viewport_data_size_get(
+ const void *engine_type,
+ int *r_fbl_len, int *r_txl_len, int *r_psl_len, int *r_stl_len);
+
+typedef struct DRWUpdateContext {
+ struct Main *bmain;
+ struct Depsgraph *depsgraph;
+ struct Scene *scene;
+ struct ViewLayer *view_layer;
+ struct ARegion *ar;
+ struct View3D *v3d;
+ struct RenderEngineType *engine_type;
+} DRWUpdateContext;
+void DRW_notify_view_update(const DRWUpdateContext *update_ctx);
+
+
+typedef enum eDRWSelectStage { DRW_SELECT_PASS_PRE = 1, DRW_SELECT_PASS_POST, } eDRWSelectStage;
+typedef bool (*DRW_SelectPassFn)(
+ eDRWSelectStage stage, void *user_data);
+
+void DRW_draw_view(const struct bContext *C);
+
+void DRW_draw_render_loop_ex(
+ struct Depsgraph *depsgraph,
+ struct RenderEngineType *engine_type,
+ struct ARegion *ar, struct View3D *v3d,
+ struct GPUViewport *viewport,
+ const struct bContext *evil_C);
+void DRW_draw_render_loop(
+ struct Depsgraph *depsgraph,
+ struct ARegion *ar, struct View3D *v3d,
+ struct GPUViewport *viewport);
+void DRW_draw_render_loop_offscreen(
+ struct Depsgraph *depsgraph,
+ struct RenderEngineType *engine_type,
+ struct ARegion *ar, struct View3D *v3d,
+ const bool draw_background,
+ struct GPUOffScreen *ofs,
+ struct GPUViewport *viewport);
+void DRW_draw_select_loop(
+ struct Depsgraph *depsgraph,
+ struct ARegion *ar, struct View3D *v3d,
+ bool use_obedit_skip, bool use_nearest, const struct rcti *rect,
+ DRW_SelectPassFn select_pass_fn, void *select_pass_user_data);
+void DRW_draw_depth_loop(
+ struct Depsgraph *depsgraph,
+ struct ARegion *ar, struct View3D *v3d);
+
+/* This is here because GPUViewport needs it */
+void DRW_pass_free(struct DRWPass *pass);
+struct DRWInstanceDataList *DRW_instance_data_list_create(void);
+void DRW_instance_data_list_free(struct DRWInstanceDataList *idatalist);
+
+void DRW_opengl_context_create(void);
+void DRW_opengl_context_destroy(void);
+void DRW_opengl_context_enable(void);
+void DRW_opengl_context_disable(void);
+
+void DRW_deferred_shader_remove(struct GPUMaterial *mat);
+
+unsigned int *WORKBENCH_generate_studiolight_preview(int studiolight_id, int icon_size);
+#endif /* __DRW_ENGINE_H__ */
diff --git a/source/blender/draw/engines/basic/basic_engine.c b/source/blender/draw/engines/basic/basic_engine.c
new file mode 100644
index 00000000000..2e0a0881928
--- /dev/null
+++ b/source/blender/draw/engines/basic/basic_engine.c
@@ -0,0 +1,253 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file basic_engine.c
+ * \ingroup draw_engine
+ *
+ * Simple engine for drawing color and/or depth.
+ * When we only need simple flat shaders.
+ */
+
+#include "DRW_render.h"
+
+#include "BKE_icons.h"
+#include "BKE_idprop.h"
+#include "BKE_main.h"
+#include "BKE_particle.h"
+
+#include "DNA_particle_types.h"
+
+#include "GPU_shader.h"
+
+#include "basic_engine.h"
+/* Shaders */
+
+#define BASIC_ENGINE "BLENDER_BASIC"
+
+/* we may want this later? */
+#define USE_DEPTH
+
+/* *********** LISTS *********** */
+
+/* GPUViewport.storage
+ * Is freed everytime the viewport engine changes */
+typedef struct BASIC_StorageList {
+ struct BASIC_PrivateData *g_data;
+} BASIC_StorageList;
+
+typedef struct BASIC_PassList {
+#ifdef USE_DEPTH
+ struct DRWPass *depth_pass;
+ struct DRWPass *depth_pass_cull;
+#endif
+ struct DRWPass *color_pass;
+} BASIC_PassList;
+
+typedef struct BASIC_Data {
+ void *engine_type;
+ DRWViewportEmptyList *fbl;
+ DRWViewportEmptyList *txl;
+ BASIC_PassList *psl;
+ BASIC_StorageList *stl;
+} BASIC_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+#ifdef USE_DEPTH
+ /* Depth Pre Pass */
+ struct GPUShader *depth_sh;
+#endif
+ /* Shading Pass */
+ struct GPUShader *color_sh;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct BASIC_PrivateData {
+#ifdef USE_DEPTH
+ DRWShadingGroup *depth_shgrp;
+ DRWShadingGroup *depth_shgrp_cull;
+ DRWShadingGroup *depth_shgrp_hair;
+#endif
+ DRWShadingGroup *color_shgrp;
+} BASIC_PrivateData; /* Transient data */
+
+/* Functions */
+
+static void basic_engine_init(void *UNUSED(vedata))
+{
+#ifdef USE_DEPTH
+ /* Depth prepass */
+ if (!e_data.depth_sh) {
+ e_data.depth_sh = DRW_shader_create_3D_depth_only();
+ }
+#endif
+
+ /* Shading pass */
+ if (!e_data.color_sh) {
+ e_data.color_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+}
+
+static void basic_cache_init(void *vedata)
+{
+ BASIC_PassList *psl = ((BASIC_Data *)vedata)->psl;
+ BASIC_StorageList *stl = ((BASIC_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+#ifdef USE_DEPTH
+ /* Depth Pass */
+ {
+ psl->depth_pass = DRW_pass_create("Depth Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE);
+ stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass);
+
+ psl->depth_pass_cull = DRW_pass_create(
+ "Depth Pass Cull",
+ DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK);
+ stl->g_data->depth_shgrp_cull = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass_cull);
+ }
+#endif
+
+ /* Color Pass */
+ {
+ psl->color_pass = DRW_pass_create("Color Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
+ stl->g_data->color_shgrp = DRW_shgroup_create(e_data.color_sh, psl->color_pass);
+ }
+}
+
+static void basic_cache_populate(void *vedata, Object *ob)
+{
+ BASIC_StorageList *stl = ((BASIC_Data *)vedata)->stl;
+
+ if (!DRW_object_is_renderable(ob))
+ return;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ if (ob != draw_ctx->object_edit) {
+ for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) {
+ if (psys_check_enabled(ob, psys, false)) {
+ ParticleSettings *part = psys->part;
+ int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
+
+ if (draw_as == PART_DRAW_PATH && !psys->pathcache && !psys->childcache) {
+ draw_as = PART_DRAW_DOT;
+ }
+
+ if (draw_as == PART_DRAW_PATH) {
+ struct Gwn_Batch *hairs = DRW_cache_particles_get_hair(psys, NULL);
+ DRW_shgroup_call_add(stl->g_data->depth_shgrp, hairs, NULL);
+ }
+ }
+ }
+ }
+
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
+ if (geom) {
+ bool do_cull = false; /* TODO (we probably wan't to take this from the viewport?) */
+#ifdef USE_DEPTH
+ /* Depth Prepass */
+ DRW_shgroup_call_add((do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp, geom, ob->obmat);
+#endif
+ /* Shading */
+ DRW_shgroup_call_add(stl->g_data->color_shgrp, geom, ob->obmat);
+ }
+}
+
+static void basic_cache_finish(void *vedata)
+{
+ BASIC_StorageList *stl = ((BASIC_Data *)vedata)->stl;
+
+ UNUSED_VARS(stl);
+}
+
+static void basic_draw_scene(void *vedata)
+{
+
+ BASIC_PassList *psl = ((BASIC_Data *)vedata)->psl;
+ const bool is_select = DRW_state_is_select();
+
+ bool use_color = true;
+ bool use_depth = true;
+ bool use_depth_cull = true;
+
+ if (is_select) {
+ /* Needed for depth-picking,
+ * for other selection types there are no need for extra passes either. */
+ use_color = false;
+ use_depth_cull = false;
+ }
+
+#ifdef USE_DEPTH
+ /* Pass 1 : Depth pre-pass */
+ if (use_depth) {
+ DRW_draw_pass(psl->depth_pass);
+ }
+
+ if (use_depth_cull) {
+ DRW_draw_pass(psl->depth_pass_cull);
+ }
+#endif
+
+ /* Pass 3 : Shading */
+ if (use_color) {
+ DRW_draw_pass(psl->color_pass);
+ }
+}
+
+static void basic_engine_free(void)
+{
+ /* all shaders are builtin */
+}
+
+static const DrawEngineDataSize basic_data_size = DRW_VIEWPORT_DATA_SIZE(BASIC_Data);
+
+DrawEngineType draw_engine_basic_type = {
+ NULL, NULL,
+ N_("Basic"),
+ &basic_data_size,
+ &basic_engine_init,
+ &basic_engine_free,
+ &basic_cache_init,
+ &basic_cache_populate,
+ &basic_cache_finish,
+ NULL,
+ &basic_draw_scene,
+ NULL,
+ NULL,
+ NULL,
+};
+
+/* Note: currently unused, we may want to register so we can see this when debugging the view. */
+
+RenderEngineType DRW_engine_viewport_basic_type = {
+ NULL, NULL,
+ BASIC_ENGINE, N_("Basic"), RE_INTERNAL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ &draw_engine_basic_type,
+ {NULL, NULL, NULL}
+};
+
+
+#undef BASIC_ENGINE
diff --git a/source/blender/draw/engines/basic/basic_engine.h b/source/blender/draw/engines/basic/basic_engine.h
new file mode 100644
index 00000000000..0adf99835a2
--- /dev/null
+++ b/source/blender/draw/engines/basic/basic_engine.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file basic_engine.h
+ * \ingroup draw_engine
+ */
+
+#ifndef __BASIC_ENGINE_H__
+#define __BASIC_ENGINE_H__
+
+extern DrawEngineType draw_engine_basic_type;
+extern RenderEngineType DRW_engine_viewport_basic_type;
+
+#endif /* __BASIC_ENGINE_H__ */
diff --git a/source/blender/draw/engines/clay/clay_engine.c b/source/blender/draw/engines/clay/clay_engine.c
new file mode 100644
index 00000000000..d7af8fb5398
--- /dev/null
+++ b/source/blender/draw/engines/clay/clay_engine.c
@@ -0,0 +1,1060 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+#include "BLI_utildefines.h"
+#include "BLI_string_utils.h"
+#include "BLI_rand.h"
+
+#include "DNA_particle_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_icons.h"
+#include "BKE_idprop.h"
+#include "BKE_main.h"
+#include "BKE_particle.h"
+
+#include "GPU_shader.h"
+
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
+
+#include "UI_resources.h"
+#include "UI_interface_icons.h"
+
+#include "DRW_render.h"
+
+#include "clay_engine.h"
+
+#ifdef WITH_CLAY_ENGINE
+#include "../eevee/eevee_lut.h" /* TODO find somewhere to share blue noise Table */
+
+/* Shaders */
+
+#define CLAY_ENGINE "BLENDER_CLAY"
+
+#define MAX_CLAY_MAT 512 /* 512 = 9 bit material id */
+
+#define SHADER_DEFINES_NO_AO \
+ "#define MAX_MATERIAL " STRINGIFY(MAX_CLAY_MAT) "\n" \
+ "#define USE_ROTATION\n" \
+ "#define USE_HSV\n"
+
+#define SHADER_DEFINES \
+ SHADER_DEFINES_NO_AO \
+ "#define USE_AO\n"
+
+extern char datatoc_clay_frag_glsl[];
+extern char datatoc_clay_prepass_frag_glsl[];
+extern char datatoc_clay_copy_glsl[];
+extern char datatoc_clay_vert_glsl[];
+extern char datatoc_clay_fxaa_glsl[];
+extern char datatoc_clay_particle_vert_glsl[];
+extern char datatoc_clay_particle_strand_frag_glsl[];
+extern char datatoc_ssao_alchemy_glsl[];
+extern char datatoc_common_fxaa_lib_glsl[];
+
+/* *********** LISTS *********** */
+
+/**
+ * UBOs data needs to be 16 byte aligned (size of vec4)
+ *
+ * Reminder: float, int, bool are 4 bytes
+ *
+ * \note struct is expected to be initialized with all pad-bits zero'd
+ * so we can use 'memcmp' to check for duplicates. Possibly hash data later.
+ */
+typedef struct CLAY_UBO_Material {
+ float ssao_params_var[4];
+ /* - 16 -*/
+ float matcap_hsv[3];
+ float matcap_id; /* even float encoding have enough precision */
+ /* - 16 -*/
+ float matcap_rot[2];
+ float pad[2]; /* ensure 16 bytes alignement */
+} CLAY_UBO_Material; /* 48 bytes */
+BLI_STATIC_ASSERT_ALIGN(CLAY_UBO_Material, 16)
+
+typedef struct CLAY_HAIR_UBO_Material {
+ float hair_randomness;
+ float matcap_id;
+ float matcap_rot[2];
+ float matcap_hsv[3];
+ float pad;
+} CLAY_HAIR_UBO_Material; /* 32 bytes */
+BLI_STATIC_ASSERT_ALIGN(CLAY_HAIR_UBO_Material, 16)
+
+typedef struct CLAY_UBO_Storage {
+ CLAY_UBO_Material materials[MAX_CLAY_MAT];
+} CLAY_UBO_Storage;
+
+typedef struct CLAY_HAIR_UBO_Storage {
+ CLAY_HAIR_UBO_Material materials[MAX_CLAY_MAT];
+} CLAY_HAIR_UBO_Storage;
+
+/* GPUViewport.storage
+ * Is freed everytime the viewport engine changes */
+typedef struct CLAY_Storage {
+ /* Materials Parameter UBO */
+ CLAY_UBO_Storage mat_storage;
+ CLAY_HAIR_UBO_Storage hair_mat_storage;
+ int ubo_current_id;
+ int hair_ubo_current_id;
+ DRWShadingGroup *shgrps[MAX_CLAY_MAT];
+ DRWShadingGroup *shgrps_flat[MAX_CLAY_MAT];
+ DRWShadingGroup *shgrps_pre[MAX_CLAY_MAT];
+ DRWShadingGroup *shgrps_pre_flat[MAX_CLAY_MAT];
+ DRWShadingGroup *hair_shgrps[MAX_CLAY_MAT];
+} CLAY_Storage;
+
+typedef struct CLAY_StorageList {
+ struct CLAY_Storage *storage;
+ struct CLAY_PrivateData *g_data;
+} CLAY_StorageList;
+
+typedef struct CLAY_FramebufferList {
+ struct GPUFrameBuffer *antialias_fb;
+ struct GPUFrameBuffer *prepass_fb;
+} CLAY_FramebufferList;
+
+typedef struct CLAY_PassList {
+ struct DRWPass *clay_ps;
+ struct DRWPass *clay_cull_ps;
+ struct DRWPass *clay_flat_ps;
+ struct DRWPass *clay_flat_cull_ps;
+ struct DRWPass *clay_pre_ps;
+ struct DRWPass *clay_pre_cull_ps;
+ struct DRWPass *clay_flat_pre_ps;
+ struct DRWPass *clay_flat_pre_cull_ps;
+ struct DRWPass *clay_deferred_ps;
+ struct DRWPass *fxaa_ps;
+ struct DRWPass *copy_ps;
+ struct DRWPass *hair_pass;
+} CLAY_PassList;
+
+
+typedef struct CLAY_Data {
+ void *engine_type;
+ CLAY_FramebufferList *fbl;
+ DRWViewportEmptyList *txl;
+ CLAY_PassList *psl;
+ CLAY_StorageList *stl;
+} CLAY_Data;
+
+typedef struct CLAY_ViewLayerData {
+ struct GPUTexture *jitter_tx;
+ struct GPUUniformBuffer *mat_ubo;
+ struct GPUUniformBuffer *matcaps_ubo;
+ struct GPUUniformBuffer *hair_mat_ubo;
+ struct GPUUniformBuffer *sampling_ubo;
+ int cached_sample_num;
+} CLAY_ViewLayerData;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Shading Pass */
+ struct GPUShader *clay_sh;
+ struct GPUShader *clay_flat_sh;
+ struct GPUShader *clay_prepass_flat_sh;
+ struct GPUShader *clay_prepass_sh;
+ struct GPUShader *clay_deferred_shading_sh;
+ struct GPUShader *fxaa_sh;
+ struct GPUShader *copy_sh;
+ struct GPUShader *hair_sh;
+ /* Matcap textures */
+ struct GPUTexture *matcap_array;
+ float matcap_colors[24][4];
+ /* Just a serie of int from 0 to MAX_CLAY_MAT-1 */
+ int ubo_mat_idxs[MAX_CLAY_MAT];
+ /* To avoid useless texture and ubo binds. */
+ bool first_shgrp;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct CLAY_PrivateData {
+ DRWShadingGroup *depth_shgrp;
+ DRWShadingGroup *depth_shgrp_select;
+ DRWShadingGroup *depth_shgrp_active;
+ DRWShadingGroup *depth_shgrp_cull;
+ DRWShadingGroup *depth_shgrp_cull_select;
+ DRWShadingGroup *depth_shgrp_cull_active;
+ /* Deferred shading */
+ struct GPUTexture *depth_tx; /* ref only, not alloced */
+ struct GPUTexture *normal_tx; /* ref only, not alloced */
+ struct GPUTexture *id_tx; /* ref only, not alloced */
+ struct GPUTexture *color_copy; /* ref only, not alloced */
+ bool enable_deferred_path;
+ /* Ssao */
+ float winmat[4][4];
+ float viewvecs[3][4];
+ float ssao_params[4];
+} CLAY_PrivateData; /* Transient data */
+
+/* Functions */
+
+static void clay_view_layer_data_free(void *storage)
+{
+ CLAY_ViewLayerData *sldata = (CLAY_ViewLayerData *)storage;
+
+ DRW_UBO_FREE_SAFE(sldata->mat_ubo);
+ DRW_UBO_FREE_SAFE(sldata->matcaps_ubo);
+ DRW_UBO_FREE_SAFE(sldata->hair_mat_ubo);
+ DRW_UBO_FREE_SAFE(sldata->sampling_ubo);
+ DRW_TEXTURE_FREE_SAFE(sldata->jitter_tx);
+}
+
+static CLAY_ViewLayerData *CLAY_view_layer_data_get(void)
+{
+ CLAY_ViewLayerData **sldata = (CLAY_ViewLayerData **)DRW_view_layer_engine_data_ensure(&draw_engine_clay_type, &clay_view_layer_data_free);
+
+ if (*sldata == NULL) {
+ *sldata = MEM_callocN(sizeof(**sldata), "CLAY_ViewLayerData");
+ }
+
+ return *sldata;
+}
+
+static void add_icon_to_rect(PreviewImage *prv, float *final_rect, int layer)
+{
+ int image_size = prv->w[0] * prv->h[0];
+ float *new_rect = &final_rect[image_size * 4 * layer];
+
+ IMB_buffer_float_from_byte(new_rect, (unsigned char *)prv->rect[0], IB_PROFILE_SRGB, IB_PROFILE_SRGB,
+ false, prv->w[0], prv->h[0], prv->w[0], prv->w[0]);
+
+ /* Find overall color */
+ for (int y = 0; y < 4; ++y) {
+ for (int x = 0; x < 4; ++x) {
+ e_data.matcap_colors[layer][0] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 0];
+ e_data.matcap_colors[layer][1] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 1];
+ e_data.matcap_colors[layer][2] += new_rect[y * 512 * 128 * 4 + x * 128 * 4 + 2];
+ }
+ }
+
+ e_data.matcap_colors[layer][0] /= 16.0f * 2.0f; /* the * 2 is to darken for shadows */
+ e_data.matcap_colors[layer][1] /= 16.0f * 2.0f;
+ e_data.matcap_colors[layer][2] /= 16.0f * 2.0f;
+}
+
+static struct GPUTexture *load_matcaps(PreviewImage *prv[24], int nbr)
+{
+ struct GPUTexture *tex;
+ int w = prv[0]->w[0];
+ int h = prv[0]->h[0];
+ float *final_rect = MEM_callocN(sizeof(float) * 4 * w * h * nbr, "Clay Matcap array rect");
+
+ for (int i = 0; i < nbr; ++i) {
+ add_icon_to_rect(prv[i], final_rect, i);
+ BKE_previewimg_free(&prv[i]);
+ }
+
+ tex = DRW_texture_create_2D_array(w, h, nbr, GPU_RGBA8, DRW_TEX_FILTER, final_rect);
+ MEM_freeN(final_rect);
+
+ return tex;
+}
+
+static int matcap_to_index(int matcap)
+{
+ switch (matcap) {
+ case ICON_MATCAP_01: return 0;
+ case ICON_MATCAP_02: return 1;
+ case ICON_MATCAP_03: return 2;
+ case ICON_MATCAP_04: return 3;
+ case ICON_MATCAP_05: return 4;
+ case ICON_MATCAP_06: return 5;
+ case ICON_MATCAP_07: return 6;
+ case ICON_MATCAP_08: return 7;
+ case ICON_MATCAP_09: return 8;
+ case ICON_MATCAP_10: return 9;
+ case ICON_MATCAP_11: return 10;
+ case ICON_MATCAP_12: return 11;
+ case ICON_MATCAP_13: return 12;
+ case ICON_MATCAP_14: return 13;
+ case ICON_MATCAP_15: return 14;
+ case ICON_MATCAP_16: return 15;
+ case ICON_MATCAP_17: return 16;
+ case ICON_MATCAP_18: return 17;
+ case ICON_MATCAP_19: return 18;
+ case ICON_MATCAP_20: return 19;
+ case ICON_MATCAP_21: return 20;
+ case ICON_MATCAP_22: return 21;
+ case ICON_MATCAP_23: return 22;
+ case ICON_MATCAP_24: return 23;
+ }
+ BLI_assert(!"Should not happen");
+ return 0;
+}
+
+/* Using Hammersley distribution */
+static float *create_disk_samples(int num_samples)
+{
+ /* vec4 to ensure memory alignment. */
+ float (*texels)[4] = MEM_mallocN(sizeof(float[4]) * num_samples, "concentric_tex");
+ const float num_samples_inv = 1.0f / num_samples;
+
+ for (int i = 0; i < num_samples; i++) {
+ float r = (i + 0.5f) * num_samples_inv;
+ double dphi;
+ BLI_hammersley_1D(i, &dphi);
+
+ float phi = (float)dphi * 2.0f * M_PI;
+ texels[i][0] = cosf(phi);
+ texels[i][1] = sinf(phi);
+ /* This deliberatly distribute more samples
+ * at the center of the disk (and thus the shadow). */
+ texels[i][2] = r;
+ }
+
+ return (float *)texels;
+}
+
+static struct GPUTexture *create_jitter_texture(int num_samples)
+{
+ float jitter[64 * 64][3];
+ const float num_samples_inv = 1.0f / num_samples;
+
+ for (int i = 0; i < 64 * 64; i++) {
+ float phi = blue_noise[i][0] * 2.0f * M_PI;
+ /* This rotate the sample per pixels */
+ jitter[i][0] = cosf(phi);
+ jitter[i][1] = sinf(phi);
+ /* This offset the sample along it's direction axis (reduce banding) */
+ float bn = blue_noise[i][1] - 0.5f;
+ CLAMP(bn, -0.499f, 0.499f); /* fix fireflies */
+ jitter[i][2] = bn * num_samples_inv;
+ }
+
+ UNUSED_VARS(bsdf_split_sum_ggx, btdf_split_sum_ggx, ltc_mag_ggx, ltc_mat_ggx, ltc_disk_integral);
+
+ return DRW_texture_create_2D(64, 64, GPU_RGB16F, DRW_TEX_FILTER | DRW_TEX_WRAP, &jitter[0][0]);
+}
+
+static void clay_engine_init(void *vedata)
+{
+ CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl;
+ CLAY_FramebufferList *fbl = ((CLAY_Data *)vedata)->fbl;
+ CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ /* Create Texture Array */
+ if (!e_data.matcap_array) {
+ PreviewImage *prv[24]; /* For now use all of the 24 internal matcaps */
+
+ /* TODO only load used matcaps */
+ prv[0] = UI_icon_to_preview(ICON_MATCAP_01);
+ prv[1] = UI_icon_to_preview(ICON_MATCAP_02);
+ prv[2] = UI_icon_to_preview(ICON_MATCAP_03);
+ prv[3] = UI_icon_to_preview(ICON_MATCAP_04);
+ prv[4] = UI_icon_to_preview(ICON_MATCAP_05);
+ prv[5] = UI_icon_to_preview(ICON_MATCAP_06);
+ prv[6] = UI_icon_to_preview(ICON_MATCAP_07);
+ prv[7] = UI_icon_to_preview(ICON_MATCAP_08);
+ prv[8] = UI_icon_to_preview(ICON_MATCAP_09);
+ prv[9] = UI_icon_to_preview(ICON_MATCAP_10);
+ prv[10] = UI_icon_to_preview(ICON_MATCAP_11);
+ prv[11] = UI_icon_to_preview(ICON_MATCAP_12);
+ prv[12] = UI_icon_to_preview(ICON_MATCAP_13);
+ prv[13] = UI_icon_to_preview(ICON_MATCAP_14);
+ prv[14] = UI_icon_to_preview(ICON_MATCAP_15);
+ prv[15] = UI_icon_to_preview(ICON_MATCAP_16);
+ prv[16] = UI_icon_to_preview(ICON_MATCAP_17);
+ prv[17] = UI_icon_to_preview(ICON_MATCAP_18);
+ prv[18] = UI_icon_to_preview(ICON_MATCAP_19);
+ prv[19] = UI_icon_to_preview(ICON_MATCAP_20);
+ prv[20] = UI_icon_to_preview(ICON_MATCAP_21);
+ prv[21] = UI_icon_to_preview(ICON_MATCAP_22);
+ prv[22] = UI_icon_to_preview(ICON_MATCAP_23);
+ prv[23] = UI_icon_to_preview(ICON_MATCAP_24);
+
+ e_data.matcap_array = load_matcaps(prv, 24);
+ }
+
+ /* Shading pass */
+ if (!e_data.clay_sh) {
+ char *matcap_with_ao = BLI_string_joinN(
+ datatoc_clay_frag_glsl,
+ datatoc_ssao_alchemy_glsl);
+
+ e_data.clay_sh = DRW_shader_create(
+ datatoc_clay_vert_glsl, NULL, datatoc_clay_frag_glsl,
+ SHADER_DEFINES_NO_AO);
+ e_data.clay_flat_sh = DRW_shader_create(
+ datatoc_clay_vert_glsl, NULL, datatoc_clay_frag_glsl,
+ SHADER_DEFINES_NO_AO
+ "#define USE_FLAT_NORMAL\n");
+
+ e_data.clay_prepass_sh = DRW_shader_create(
+ datatoc_clay_vert_glsl, NULL, datatoc_clay_prepass_frag_glsl,
+ SHADER_DEFINES);
+ e_data.clay_prepass_flat_sh = DRW_shader_create(
+ datatoc_clay_vert_glsl, NULL, datatoc_clay_prepass_frag_glsl,
+ SHADER_DEFINES
+ "#define USE_FLAT_NORMAL\n");
+
+ e_data.clay_deferred_shading_sh = DRW_shader_create_fullscreen(
+ matcap_with_ao,
+ SHADER_DEFINES
+ "#define DEFERRED_SHADING\n");
+
+ MEM_freeN(matcap_with_ao);
+
+ char *fxaa_str = BLI_string_joinN(
+ datatoc_common_fxaa_lib_glsl,
+ datatoc_clay_fxaa_glsl);
+
+ e_data.fxaa_sh = DRW_shader_create_fullscreen(fxaa_str, NULL);
+
+ MEM_freeN(fxaa_str);
+
+ e_data.copy_sh = DRW_shader_create_fullscreen(datatoc_clay_copy_glsl, NULL);
+ }
+
+ if (!stl->storage) {
+ stl->storage = MEM_callocN(sizeof(CLAY_Storage), "CLAY_Storage");
+ }
+
+ if (!stl->g_data) {
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), "CLAY_PrivateStorage");
+ }
+
+ CLAY_PrivateData *g_data = stl->g_data;
+
+ if (!sldata->mat_ubo) {
+ sldata->mat_ubo = DRW_uniformbuffer_create(sizeof(CLAY_UBO_Storage), NULL);
+ }
+
+ if (!sldata->hair_mat_ubo) {
+ sldata->hair_mat_ubo = DRW_uniformbuffer_create(sizeof(CLAY_HAIR_UBO_Storage), NULL);
+ }
+
+ if (!sldata->matcaps_ubo) {
+ sldata->matcaps_ubo = DRW_uniformbuffer_create(sizeof(e_data.matcap_colors), e_data.matcap_colors);
+ }
+
+ if (e_data.ubo_mat_idxs[1] == 0) {
+ /* Just int to have pointers to them */
+ for (int i = 0; i < MAX_CLAY_MAT; ++i) {
+ e_data.ubo_mat_idxs[i] = i;
+ }
+ }
+
+ /* FBO setup */
+ {
+ const float *viewport_size = DRW_viewport_size_get();
+ const int size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+
+ g_data->normal_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RG8, &draw_engine_clay_type);
+ g_data->id_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_R16UI, &draw_engine_clay_type);
+
+ GPU_framebuffer_ensure_config(&fbl->prepass_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(g_data->normal_tx),
+ GPU_ATTACHMENT_TEXTURE(g_data->id_tx)
+ });
+
+ /* For FXAA */
+ /* TODO(fclem): OPTI: we could merge normal_tx and id_tx into a GPU_RGBA8
+ * and reuse it for the fxaa target. */
+ g_data->color_copy = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8, &draw_engine_clay_type);
+
+ GPU_framebuffer_ensure_config(&fbl->antialias_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(g_data->color_copy)
+ });
+ }
+
+ /* SSAO setup */
+ {
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(
+ view_layer, RE_engine_id_BLENDER_CLAY);
+ int ssao_samples = BKE_collection_engine_property_value_get_int(props, "ssao_samples");
+
+ float invproj[4][4];
+ float dfdyfacs[2];
+ const bool is_persp = DRW_viewport_is_persp_get();
+ /* view vectors for the corners of the view frustum.
+ * Can be used to recreate the world space position easily */
+ float viewvecs[3][4] = {
+ {-1.0f, -1.0f, -1.0f, 1.0f},
+ {1.0f, -1.0f, -1.0f, 1.0f},
+ {-1.0f, 1.0f, -1.0f, 1.0f}
+ };
+ int i;
+ const float *size = DRW_viewport_size_get();
+
+ DRW_state_dfdy_factors_get(dfdyfacs);
+
+ g_data->ssao_params[0] = ssao_samples;
+ g_data->ssao_params[1] = size[0] / 64.0;
+ g_data->ssao_params[2] = size[1] / 64.0;
+ g_data->ssao_params[3] = dfdyfacs[1]; /* dfdy sign for offscreen */
+
+ /* invert the view matrix */
+ DRW_viewport_matrix_get(g_data->winmat, DRW_MAT_WIN);
+ invert_m4_m4(invproj, g_data->winmat);
+
+ /* convert the view vectors to view space */
+ for (i = 0; i < 3; i++) {
+ mul_m4_v4(invproj, viewvecs[i]);
+ /* normalized trick see:
+ * http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */
+ mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][3]);
+ if (is_persp)
+ mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]);
+ viewvecs[i][3] = 1.0;
+
+ copy_v4_v4(g_data->viewvecs[i], viewvecs[i]);
+ }
+
+ /* we need to store the differences */
+ g_data->viewvecs[1][0] -= g_data->viewvecs[0][0];
+ g_data->viewvecs[1][1] = g_data->viewvecs[2][1] - g_data->viewvecs[0][1];
+
+ /* calculate a depth offset as well */
+ if (!is_persp) {
+ float vec_far[] = {-1.0f, -1.0f, 1.0f, 1.0f};
+ mul_m4_v4(invproj, vec_far);
+ mul_v3_fl(vec_far, 1.0f / vec_far[3]);
+ g_data->viewvecs[1][2] = vec_far[2] - g_data->viewvecs[0][2];
+ }
+
+ /* AO Samples Tex */
+ if (sldata->sampling_ubo && (sldata->cached_sample_num != ssao_samples)) {
+ DRW_UBO_FREE_SAFE(sldata->sampling_ubo);
+ DRW_TEXTURE_FREE_SAFE(sldata->jitter_tx);
+ }
+
+ if (sldata->sampling_ubo == NULL) {
+ float *samples = create_disk_samples(ssao_samples);
+ sldata->jitter_tx = create_jitter_texture(ssao_samples);
+ sldata->sampling_ubo = DRW_uniformbuffer_create(sizeof(float[4]) * ssao_samples, samples);
+ sldata->cached_sample_num = ssao_samples;
+ MEM_freeN(samples);
+ }
+ }
+}
+
+static DRWShadingGroup *CLAY_shgroup_create(DRWPass *pass, GPUShader *sh, int id)
+{
+ CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get();
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
+ DRW_shgroup_uniform_int(grp, "mat_id", &e_data.ubo_mat_idxs[id], 1);
+ if (e_data.first_shgrp) {
+ DRW_shgroup_uniform_texture_persistent(grp, "matcaps", e_data.matcap_array);
+ DRW_shgroup_uniform_block_persistent(grp, "material_block", sldata->mat_ubo);
+ DRW_shgroup_uniform_block_persistent(grp, "matcaps_block", sldata->matcaps_ubo);
+ }
+ return grp;
+}
+
+static DRWShadingGroup *CLAY_shgroup_deferred_prepass_create(DRWPass *pass, GPUShader *sh, int id)
+{
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
+ DRW_shgroup_uniform_int(grp, "mat_id", &e_data.ubo_mat_idxs[id], 1);
+
+ return grp;
+}
+
+static DRWShadingGroup *CLAY_shgroup_deferred_shading_create(DRWPass *pass, CLAY_PrivateData *g_data)
+{
+ CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get();
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.clay_deferred_shading_sh, pass);
+ DRW_shgroup_uniform_texture_ref(grp, "depthtex", &g_data->depth_tx);
+ DRW_shgroup_uniform_texture_ref(grp, "normaltex", &g_data->normal_tx);
+ DRW_shgroup_uniform_texture_ref(grp, "idtex", &g_data->id_tx);
+ DRW_shgroup_uniform_texture(grp, "matcaps", e_data.matcap_array);
+ DRW_shgroup_uniform_texture(grp, "ssao_jitter", sldata->jitter_tx);
+ DRW_shgroup_uniform_block(grp, "samples_block", sldata->sampling_ubo);
+ DRW_shgroup_uniform_block(grp, "material_block", sldata->mat_ubo);
+ DRW_shgroup_uniform_block(grp, "matcaps_block", sldata->matcaps_ubo);
+ /* TODO put in ubo */
+ DRW_shgroup_uniform_mat4(grp, "WinMatrix", g_data->winmat);
+ DRW_shgroup_uniform_vec2(grp, "invscreenres", DRW_viewport_invert_size_get(), 1);
+ DRW_shgroup_uniform_vec4(grp, "viewvecs[0]", (float *)g_data->viewvecs, 3);
+ DRW_shgroup_uniform_vec4(grp, "ssao_params", g_data->ssao_params, 1);
+ return grp;
+}
+
+static DRWShadingGroup *CLAY_hair_shgroup_create(DRWPass *pass, int id)
+{
+ CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get();
+
+ if (!e_data.hair_sh) {
+ e_data.hair_sh = DRW_shader_create(
+ datatoc_clay_particle_vert_glsl, NULL, datatoc_clay_particle_strand_frag_glsl,
+ "#define MAX_MATERIAL 512\n");
+ }
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.hair_sh, pass);
+ DRW_shgroup_uniform_texture(grp, "matcaps", e_data.matcap_array);
+ DRW_shgroup_uniform_block(grp, "material_block", sldata->mat_ubo);
+ DRW_shgroup_uniform_int(grp, "mat_id", &e_data.ubo_mat_idxs[id], 1);
+
+ return grp;
+}
+
+static int search_mat_to_ubo(CLAY_Storage *storage, const CLAY_UBO_Material *mat_ubo_test)
+{
+ /* For now just use a linear search and test all parameters */
+ /* TODO make a hash table */
+ for (int i = 0; i < storage->ubo_current_id; ++i) {
+ CLAY_UBO_Material *ubo = &storage->mat_storage.materials[i];
+ if (memcmp(ubo, mat_ubo_test, sizeof(*mat_ubo_test)) == 0) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+static int search_hair_mat_to_ubo(CLAY_Storage *storage, const CLAY_HAIR_UBO_Material *hair_mat_ubo_test)
+{
+ /* For now just use a linear search and test all parameters */
+ /* TODO make a hash table */
+ for (int i = 0; i < storage->hair_ubo_current_id; ++i) {
+ CLAY_HAIR_UBO_Material *ubo = &storage->hair_mat_storage.materials[i];
+ if (memcmp(ubo, hair_mat_ubo_test, sizeof(*hair_mat_ubo_test)) == 0) {
+ return i;
+ }
+ }
+
+ return -1;
+}
+
+static int push_mat_to_ubo(CLAY_Storage *storage, const CLAY_UBO_Material *mat_ubo_test)
+{
+ int id = storage->ubo_current_id++;
+ id = min_ii(MAX_CLAY_MAT, id);
+ storage->mat_storage.materials[id] = *mat_ubo_test;
+ return id;
+}
+
+static int push_hair_mat_to_ubo(CLAY_Storage *storage, const CLAY_HAIR_UBO_Material *hair_mat_ubo_test)
+{
+ int id = storage->hair_ubo_current_id++;
+ id = min_ii(MAX_CLAY_MAT, id);
+ storage->hair_mat_storage.materials[id] = *hair_mat_ubo_test;
+ return id;
+}
+
+static int mat_in_ubo(CLAY_Storage *storage, const CLAY_UBO_Material *mat_ubo_test)
+{
+ /* Search material in UBO */
+ int id = search_mat_to_ubo(storage, mat_ubo_test);
+
+ /* if not found create it */
+ if (id == -1) {
+ id = push_mat_to_ubo(storage, mat_ubo_test);
+ }
+
+ return id;
+}
+
+static int hair_mat_in_ubo(CLAY_Storage *storage, const CLAY_HAIR_UBO_Material *hair_mat_ubo_test)
+{
+ /* Search material in UBO */
+ int id = search_hair_mat_to_ubo(storage, hair_mat_ubo_test);
+
+ /* if not found create it */
+ if (id == -1) {
+ id = push_hair_mat_to_ubo(storage, hair_mat_ubo_test);
+ }
+
+ return id;
+}
+
+static void ubo_mat_from_object(CLAY_Storage *storage, Object *ob, bool *r_needs_ao, int *r_id)
+{
+ IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, RE_engine_id_BLENDER_CLAY);
+
+ int matcap_icon = BKE_collection_engine_property_value_get_int(props, "matcap_icon");
+ float matcap_rot = BKE_collection_engine_property_value_get_float(props, "matcap_rotation");
+ float matcap_hue = BKE_collection_engine_property_value_get_float(props, "matcap_hue");
+ float matcap_sat = BKE_collection_engine_property_value_get_float(props, "matcap_saturation");
+ float matcap_val = BKE_collection_engine_property_value_get_float(props, "matcap_value");
+ float ssao_distance = BKE_collection_engine_property_value_get_float(props, "ssao_distance");
+ float ssao_factor_cavity = BKE_collection_engine_property_value_get_float(props, "ssao_factor_cavity");
+ float ssao_factor_edge = BKE_collection_engine_property_value_get_float(props, "ssao_factor_edge");
+ float ssao_attenuation = BKE_collection_engine_property_value_get_float(props, "ssao_attenuation");
+
+ CLAY_UBO_Material r_ubo = {{0.0f}};
+
+ if (((ssao_factor_cavity > 0.0) || (ssao_factor_edge > 0.0)) &&
+ (ssao_distance > 0.0))
+ {
+ *r_needs_ao = true;
+
+ r_ubo.ssao_params_var[0] = ssao_distance;
+ r_ubo.ssao_params_var[1] = ssao_factor_cavity;
+ r_ubo.ssao_params_var[2] = ssao_factor_edge;
+ r_ubo.ssao_params_var[3] = ssao_attenuation;
+ }
+ else {
+ *r_needs_ao = false;
+ }
+
+ r_ubo.matcap_rot[0] = cosf(matcap_rot * 3.14159f * 2.0f);
+ r_ubo.matcap_rot[1] = sinf(matcap_rot * 3.14159f * 2.0f);
+
+ r_ubo.matcap_hsv[0] = matcap_hue + 0.5f;
+ r_ubo.matcap_hsv[1] = matcap_sat * 2.0f;
+ r_ubo.matcap_hsv[2] = matcap_val * 2.0f;
+
+ r_ubo.matcap_id = matcap_to_index(matcap_icon);
+
+ *r_id = mat_in_ubo(storage, &r_ubo);
+}
+
+static void hair_ubo_mat_from_object(Object *ob, CLAY_HAIR_UBO_Material *r_ubo)
+{
+ IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, RE_engine_id_BLENDER_CLAY);
+
+ int matcap_icon = BKE_collection_engine_property_value_get_int(props, "matcap_icon");
+ float matcap_rot = BKE_collection_engine_property_value_get_float(props, "matcap_rotation");
+ float matcap_hue = BKE_collection_engine_property_value_get_float(props, "matcap_hue");
+ float matcap_sat = BKE_collection_engine_property_value_get_float(props, "matcap_saturation");
+ float matcap_val = BKE_collection_engine_property_value_get_float(props, "matcap_value");
+ float hair_randomness = BKE_collection_engine_property_value_get_float(props, "hair_brightness_randomness");
+
+ memset(r_ubo, 0x0, sizeof(*r_ubo));
+
+ r_ubo->matcap_rot[0] = cosf(matcap_rot * 3.14159f * 2.0f);
+ r_ubo->matcap_rot[1] = sinf(matcap_rot * 3.14159f * 2.0f);
+ r_ubo->matcap_hsv[0] = matcap_hue + 0.5f;
+ r_ubo->matcap_hsv[1] = matcap_sat * 2.0f;
+ r_ubo->matcap_hsv[2] = matcap_val * 2.0f;
+ r_ubo->hair_randomness = hair_randomness;
+ r_ubo->matcap_id = matcap_to_index(matcap_icon);
+}
+
+static DRWShadingGroup *CLAY_object_shgrp_get(CLAY_Data *vedata, Object *ob, bool use_flat, bool cull)
+{
+ bool prepass; int id;
+ CLAY_PassList *psl = vedata->psl;
+ CLAY_Storage *storage = vedata->stl->storage;
+ DRWShadingGroup **shgrps;
+ DRWPass *pass; GPUShader *sh;
+
+ ubo_mat_from_object(storage, ob, &prepass, &id);
+
+ if (prepass) {
+ if (use_flat) {
+ shgrps = storage->shgrps_pre_flat;
+ pass = (cull) ? psl->clay_flat_pre_cull_ps : psl->clay_flat_pre_ps;
+ sh = e_data.clay_prepass_flat_sh;
+ }
+ else {
+ shgrps = storage->shgrps_pre;
+ pass = (cull) ? psl->clay_pre_cull_ps : psl->clay_pre_ps;
+ sh = e_data.clay_prepass_sh;
+ }
+
+ if (shgrps[id] == NULL) {
+ shgrps[id] = CLAY_shgroup_deferred_prepass_create(pass, sh, id);
+ }
+
+ vedata->stl->g_data->enable_deferred_path = true;
+ }
+ else {
+ if (use_flat) {
+ shgrps = storage->shgrps_flat;
+ pass = (cull) ? psl->clay_flat_cull_ps : psl->clay_flat_ps;
+ sh = e_data.clay_flat_sh;
+ }
+ else {
+ shgrps = storage->shgrps;
+ pass = (cull) ? psl->clay_cull_ps : psl->clay_ps;
+ sh = e_data.clay_sh;
+ }
+
+ if (shgrps[id] == NULL) {
+ shgrps[id] = CLAY_shgroup_create(pass, sh, id);
+ e_data.first_shgrp = false;
+ }
+ }
+
+ return shgrps[id];
+}
+
+static DRWShadingGroup *CLAY_hair_shgrp_get(CLAY_Data *UNUSED(vedata), Object *ob, CLAY_StorageList *stl, CLAY_PassList *psl)
+{
+ DRWShadingGroup **hair_shgrps = stl->storage->hair_shgrps;
+
+ CLAY_HAIR_UBO_Material hair_mat_ubo_test;
+ hair_ubo_mat_from_object(ob, &hair_mat_ubo_test);
+
+ int hair_id = hair_mat_in_ubo(stl->storage, &hair_mat_ubo_test);
+
+ if (hair_shgrps[hair_id] == NULL) {
+ hair_shgrps[hair_id] = CLAY_hair_shgroup_create(psl->hair_pass, hair_id);
+ }
+
+ return hair_shgrps[hair_id];
+}
+
+static void clay_cache_init(void *vedata)
+{
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ CLAY_PassList *psl = ((CLAY_Data *)vedata)->psl;
+ CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl;
+
+ /* Disable AO unless a material needs it. */
+ stl->g_data->enable_deferred_path = false;
+
+ /* Reset UBO datas, shgrp pointers and material id counters. */
+ memset(stl->storage, 0, sizeof(*stl->storage));
+ e_data.first_shgrp = true;
+
+ /* Solid Passes */
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ psl->clay_ps = DRW_pass_create("Clay", state);
+ psl->clay_cull_ps = DRW_pass_create("Clay Culled", state | DRW_STATE_CULL_BACK);
+ psl->clay_flat_ps = DRW_pass_create("Clay Flat", state);
+ psl->clay_flat_cull_ps = DRW_pass_create("Clay Flat Culled", state | DRW_STATE_CULL_BACK);
+
+ DRWState prepass_state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ DRWState prepass_cull_state = prepass_state | DRW_STATE_CULL_BACK;
+ psl->clay_pre_ps = DRW_pass_create("Clay Deferred Pre", prepass_state);
+ psl->clay_pre_cull_ps = DRW_pass_create("Clay Deferred Pre Culled", prepass_cull_state);
+ psl->clay_flat_pre_ps = DRW_pass_create("Clay Deferred Flat Pre", prepass_state);
+ psl->clay_flat_pre_cull_ps = DRW_pass_create("Clay Deferred Flat Pre Culled", prepass_cull_state);
+
+ psl->clay_deferred_ps = DRW_pass_create("Clay Deferred Shading", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = CLAY_shgroup_deferred_shading_create(psl->clay_deferred_ps, stl->g_data);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+ /* Hair Pass */
+ {
+ psl->hair_pass = DRW_pass_create(
+ "Hair Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE);
+ }
+
+ {
+ psl->fxaa_ps = DRW_pass_create("Fxaa", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.fxaa_sh, psl->fxaa_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "colortex", &dtxl->color);
+ DRW_shgroup_uniform_vec2(grp, "invscreenres", DRW_viewport_invert_size_get(), 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+
+ psl->copy_ps = DRW_pass_create("Copy", DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_create(e_data.copy_sh, psl->copy_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "colortex", &stl->g_data->color_copy);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+}
+
+static void clay_cache_populate_particles(void *vedata, Object *ob)
+{
+ CLAY_PassList *psl = ((CLAY_Data *)vedata)->psl;
+ CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ if (ob != draw_ctx->object_edit) {
+ for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) {
+ if (psys_check_enabled(ob, psys, false)) {
+ ParticleSettings *part = psys->part;
+ int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
+
+ if (draw_as == PART_DRAW_PATH && !psys->pathcache && !psys->childcache) {
+ draw_as = PART_DRAW_DOT;
+ }
+
+ static float mat[4][4];
+ unit_m4(mat);
+
+ if (draw_as == PART_DRAW_PATH) {
+ struct Gwn_Batch *geom = DRW_cache_particles_get_hair(psys, NULL);
+ DRWShadingGroup *hair_shgrp = CLAY_hair_shgrp_get(vedata, ob, stl, psl);
+ DRW_shgroup_call_add(hair_shgrp, geom, mat);
+ }
+ }
+ }
+ }
+}
+
+static void clay_cache_populate(void *vedata, Object *ob)
+{
+ DRWShadingGroup *clay_shgrp;
+
+ if (!DRW_object_is_renderable(ob))
+ return;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const bool is_active = (ob == draw_ctx->obact);
+ if (is_active) {
+ if (DRW_object_is_mode_shade(ob) == true) {
+ return;
+ }
+ }
+
+ /* Handle particles first in case the emitter itself shouldn't be rendered. */
+ if (ob->type == OB_MESH) {
+ clay_cache_populate_particles(vedata, ob);
+ }
+
+ if (DRW_check_object_visible_within_active_context(ob) == false) {
+ return;
+ }
+
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
+ if (geom) {
+ const bool do_cull = (draw_ctx->v3d && (draw_ctx->v3d->flag2 & V3D_BACKFACE_CULLING));
+ const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0;
+ const bool use_flat = is_sculpt_mode && DRW_object_is_flat_normal(ob);
+
+ clay_shgrp = CLAY_object_shgrp_get(vedata, ob, use_flat, do_cull);
+
+ if (is_sculpt_mode) {
+ DRW_shgroup_call_sculpt_add(clay_shgrp, ob, ob->obmat);
+ }
+ else {
+ DRW_shgroup_call_object_add(clay_shgrp, geom, ob);
+ }
+ }
+}
+
+static void clay_cache_finish(void *vedata)
+{
+ CLAY_ViewLayerData *sldata = CLAY_view_layer_data_get();
+ CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl;
+
+ DRW_uniformbuffer_update(sldata->mat_ubo, &stl->storage->mat_storage);
+ DRW_uniformbuffer_update(sldata->hair_mat_ubo, &stl->storage->hair_mat_storage);
+}
+
+static void clay_draw_scene(void *vedata)
+{
+ CLAY_StorageList *stl = ((CLAY_Data *)vedata)->stl;
+ CLAY_PassList *psl = ((CLAY_Data *)vedata)->psl;
+ CLAY_FramebufferList *fbl = ((CLAY_Data *)vedata)->fbl;
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ stl->g_data->depth_tx = dtxl->depth;
+
+ /* Passes are ordered to have less _potential_ overdraw */
+ DRW_draw_pass(psl->clay_cull_ps);
+ DRW_draw_pass(psl->clay_flat_cull_ps);
+ DRW_draw_pass(psl->clay_ps);
+ DRW_draw_pass(psl->clay_flat_ps);
+ DRW_draw_pass(psl->hair_pass);
+
+ if (stl->g_data->enable_deferred_path) {
+ GPU_framebuffer_bind(fbl->prepass_fb);
+ /* We need to clear the id texture unfortunately. */
+ const float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ GPU_framebuffer_clear_color(fbl->prepass_fb, clear_col);
+
+ DRW_draw_pass(psl->clay_pre_cull_ps);
+ DRW_draw_pass(psl->clay_flat_pre_cull_ps);
+ DRW_draw_pass(psl->clay_pre_ps);
+ DRW_draw_pass(psl->clay_flat_pre_ps);
+
+ GPU_framebuffer_bind(dfbl->color_only_fb);
+ DRW_draw_pass(psl->clay_deferred_ps);
+ }
+
+ if (true) { /* Always on for now. We might want a parameter for this. */
+ GPU_framebuffer_bind(fbl->antialias_fb);
+ DRW_draw_pass(psl->fxaa_ps);
+
+ GPU_framebuffer_bind(dfbl->color_only_fb);
+ DRW_draw_pass(psl->copy_ps);
+ }
+}
+
+static void clay_layer_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
+{
+ BLI_assert(props &&
+ props->type == IDP_GROUP &&
+ props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
+
+ BKE_collection_engine_property_add_int(props, "matcap_icon", ICON_MATCAP_01);
+ BKE_collection_engine_property_add_int(props, "type", CLAY_MATCAP_NONE);
+ BKE_collection_engine_property_add_float(props, "matcap_rotation", 0.0f);
+ BKE_collection_engine_property_add_float(props, "matcap_hue", 0.5f);
+ BKE_collection_engine_property_add_float(props, "matcap_saturation", 0.5f);
+ BKE_collection_engine_property_add_float(props, "matcap_value", 0.5f);
+ BKE_collection_engine_property_add_float(props, "ssao_distance", 0.2f);
+ BKE_collection_engine_property_add_float(props, "ssao_attenuation", 1.0f);
+ BKE_collection_engine_property_add_float(props, "ssao_factor_cavity", 1.0f);
+ BKE_collection_engine_property_add_float(props, "ssao_factor_edge", 1.0f);
+ BKE_collection_engine_property_add_float(props, "hair_brightness_randomness", 0.0f);
+}
+
+static void clay_view_layer_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
+{
+ BLI_assert(props &&
+ props->type == IDP_GROUP &&
+ props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
+
+ BKE_collection_engine_property_add_int(props, "ssao_samples", 16);
+}
+
+static void clay_engine_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.clay_sh);
+ DRW_SHADER_FREE_SAFE(e_data.clay_flat_sh);
+ DRW_SHADER_FREE_SAFE(e_data.clay_prepass_flat_sh);
+ DRW_SHADER_FREE_SAFE(e_data.clay_prepass_sh);
+ DRW_SHADER_FREE_SAFE(e_data.clay_deferred_shading_sh);
+ DRW_SHADER_FREE_SAFE(e_data.fxaa_sh);
+ DRW_SHADER_FREE_SAFE(e_data.copy_sh);
+ DRW_SHADER_FREE_SAFE(e_data.hair_sh);
+ DRW_TEXTURE_FREE_SAFE(e_data.matcap_array);
+}
+
+static const DrawEngineDataSize clay_data_size = DRW_VIEWPORT_DATA_SIZE(CLAY_Data);
+
+DrawEngineType draw_engine_clay_type = {
+ NULL, NULL,
+ N_("Clay"),
+ &clay_data_size,
+ &clay_engine_init,
+ &clay_engine_free,
+ &clay_cache_init,
+ &clay_cache_populate,
+ &clay_cache_finish,
+ NULL,
+ &clay_draw_scene,
+ NULL,
+ NULL,
+ NULL,
+};
+
+RenderEngineType DRW_engine_viewport_clay_type = {
+ NULL, NULL,
+ CLAY_ENGINE, N_("Clay"), RE_INTERNAL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ &clay_layer_collection_settings_create,
+ &clay_view_layer_settings_create,
+ &draw_engine_clay_type,
+ {NULL, NULL, NULL}
+};
+
+
+#undef CLAY_ENGINE
+
+#endif /* WITH_CLAY_ENGINE */
diff --git a/source/blender/draw/engines/clay/clay_engine.h b/source/blender/draw/engines/clay/clay_engine.h
new file mode 100644
index 00000000000..b7c9d00c9ae
--- /dev/null
+++ b/source/blender/draw/engines/clay/clay_engine.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file clay_engine.h
+ * \ingroup draw_engine
+ */
+
+#ifndef __CLAY_ENGINE_H__
+#define __CLAY_ENGINE_H__
+
+extern DrawEngineType draw_engine_clay_type;
+extern RenderEngineType DRW_engine_viewport_clay_type;
+
+struct IDProperty;
+
+struct IDProperty *CLAY_render_settings_create(void);
+
+#endif /* __CLAY_ENGINE_H__ */
diff --git a/source/blender/draw/engines/clay/shaders/clay_copy.glsl b/source/blender/draw/engines/clay/shaders/clay_copy.glsl
new file mode 100644
index 00000000000..ec462978e67
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/clay_copy.glsl
@@ -0,0 +1,10 @@
+
+in vec4 uvcoordsvar;
+out vec4 fragColor;
+
+uniform sampler2D colortex;
+
+void main()
+{
+ fragColor = texture(colortex, uvcoordsvar.st);
+}
diff --git a/source/blender/draw/engines/clay/shaders/clay_frag.glsl b/source/blender/draw/engines/clay/shaders/clay_frag.glsl
new file mode 100644
index 00000000000..1939e4b735d
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/clay_frag.glsl
@@ -0,0 +1,252 @@
+uniform vec2 invscreenres;
+uniform mat4 WinMatrix;
+
+/* Matcap */
+uniform sampler2DArray matcaps;
+
+/* Screen Space Occlusion */
+/* store the view space vectors for the corners of the view frustum here.
+ * It helps to quickly reconstruct view space vectors by using uv coordinates,
+ * see http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */
+uniform vec4 viewvecs[3];
+uniform vec4 ssao_params;
+
+uniform sampler2D ssao_jitter;
+
+/* Material Parameters packed in an UBO */
+struct Material {
+ vec4 ssao_params_var;
+ vec4 matcap_hsv_id;
+ vec4 matcap_rot; /* vec4 to ensure 16 bytes alignement (don't trust compiler) */
+};
+
+layout(std140) uniform samples_block {
+ vec4 ssao_samples[500];
+};
+
+layout(std140) uniform matcaps_block {
+ vec4 matcaps_color[24];
+};
+
+layout(std140) uniform material_block {
+ Material matcaps_param[MAX_MATERIAL];
+};
+
+#ifdef DEFERRED_SHADING
+uniform sampler2D depthtex;
+uniform sampler2D normaltex;
+uniform isampler2D idtex;
+int mat_id; /* global */
+#else
+uniform int mat_id;
+#endif
+
+/* Aliases */
+#define ssao_samples_num ssao_params.x
+#define jitter_tilling ssao_params.yz
+#define dfdy_sign ssao_params.w
+
+#define matcap_hsv matcaps_param[mat_id].matcap_hsv_id.xyz
+#define matcap_index matcaps_param[mat_id].matcap_hsv_id.w
+#define matcap_rotation matcaps_param[mat_id].matcap_rot.xy
+
+#ifndef DEFERRED_SHADING
+# ifdef USE_FLAT_NORMAL
+flat in vec3 normal;
+# else
+in vec3 normal;
+# endif
+#endif
+
+out vec4 fragColor;
+
+/* TODO Move this to SSAO modules */
+/* simple depth reconstruction, see http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer
+ * we change the factors from the article to fit the OpennGL model. */
+vec3 get_view_space_from_depth(in vec2 uvcoords, in float depth)
+{
+ if (WinMatrix[3][3] == 0.0) {
+ /* Perspective */
+ float d = 2.0 * depth - 1.0;
+
+ float zview = -WinMatrix[3][2] / (d + WinMatrix[2][2]);
+
+ return zview * (viewvecs[0].xyz + vec3(uvcoords, 0.0) * viewvecs[1].xyz);
+ }
+ else {
+ /* Orthographic */
+ vec3 offset = vec3(uvcoords, depth);
+
+ return viewvecs[0].xyz + offset * viewvecs[1].xyz;
+ }
+}
+
+#ifdef USE_HSV
+void rgb_to_hsv(vec3 rgb, out vec3 outcol)
+{
+ float cmax, cmin, h, s, v, cdelta;
+ vec3 c;
+
+ cmax = max(rgb[0], max(rgb[1], rgb[2]));
+ cmin = min(rgb[0], min(rgb[1], rgb[2]));
+ cdelta = cmax - cmin;
+
+ v = cmax;
+ if (cmax != 0.0)
+ s = cdelta / cmax;
+ else {
+ s = 0.0;
+ h = 0.0;
+ }
+
+ if (s == 0.0) {
+ h = 0.0;
+ }
+ else {
+ c = (vec3(cmax, cmax, cmax) - rgb.xyz) / cdelta;
+
+ if (rgb.x == cmax) h = c[2] - c[1];
+ else if (rgb.y == cmax) h = 2.0 + c[0] - c[2];
+ else h = 4.0 + c[1] - c[0];
+
+ h /= 6.0;
+
+ if (h < 0.0)
+ h += 1.0;
+ }
+
+ outcol = vec3(h, s, v);
+}
+
+void hsv_to_rgb(vec3 hsv, out vec3 outcol)
+{
+ float i, f, p, q, t, h, s, v;
+ vec3 rgb;
+
+ h = hsv[0];
+ s = hsv[1];
+ v = hsv[2];
+
+ if (s == 0.0) {
+ rgb = vec3(v, v, v);
+ }
+ else {
+ if (h == 1.0)
+ h = 0.0;
+
+ h *= 6.0;
+ i = floor(h);
+ f = h - i;
+ rgb = vec3(f, f, f);
+ p = v * (1.0 - s);
+ q = v * (1.0 - (s * f));
+ t = v * (1.0 - (s * (1.0 - f)));
+
+ if (i == 0.0) rgb = vec3(v, t, p);
+ else if (i == 1.0) rgb = vec3(q, v, p);
+ else if (i == 2.0) rgb = vec3(p, v, t);
+ else if (i == 3.0) rgb = vec3(p, q, v);
+ else if (i == 4.0) rgb = vec3(t, p, v);
+ else rgb = vec3(v, p, q);
+ }
+
+ outcol = rgb;
+}
+
+void hue_sat(float hue, float sat, float value, inout vec3 col)
+{
+ vec3 hsv;
+
+ rgb_to_hsv(col, hsv);
+
+ hsv.x += hue;
+ hsv.x -= floor(hsv.x);
+ hsv.y *= sat;
+ hsv.y = clamp(hsv.y, 0.0, 1.0);
+ hsv.z *= value;
+ hsv.z = clamp(hsv.z, 0.0, 1.0);
+
+ hsv_to_rgb(hsv, col);
+}
+#endif
+
+#ifdef USE_AO
+/* Prototype */
+void ssao_factors(
+ in float depth, in vec3 normal, in vec3 position, in vec2 screenco,
+ out float cavities, out float edges);
+#endif
+
+/* From http://aras-p.info/texts/CompactNormalStorage.html
+ * Using Method #4: Spheremap Transform */
+vec3 normal_decode(vec2 enc)
+{
+ vec2 fenc = enc * 4.0 - 2.0;
+ float f = dot(fenc, fenc);
+ float g = sqrt(1.0 - f / 4.0);
+ vec3 n;
+ n.xy = fenc*g;
+ n.z = 1 - f / 2;
+ return n;
+}
+
+vec3 shade(vec3 N, vec3 position, float depth, vec2 screenco)
+{
+#ifdef USE_ROTATION
+ /* Rotate texture coordinates */
+ vec2 rotY = vec2(-matcap_rotation.y, matcap_rotation.x);
+ vec2 texco = abs(vec2(dot(N.xy, matcap_rotation), dot(N.xy, rotY)) * .49 + 0.5);
+#else
+ vec2 texco = abs(N.xy * .49 + 0.5);
+#endif
+ vec3 col = texture(matcaps, vec3(texco, matcap_index)).rgb;
+
+#ifdef USE_AO
+ float cavity = 0.0, edges = 0.0;
+ ssao_factors(depth, N, position, screenco, cavity, edges);
+
+ col *= mix(vec3(1.0), matcaps_color[int(matcap_index)].rgb, cavity);
+#endif
+
+#ifdef USE_HSV
+ hue_sat(matcap_hsv.x, matcap_hsv.y, matcap_hsv.z, col);
+#endif
+
+#ifdef USE_AO
+ /* Apply highlights after hue shift */
+ col *= edges + 1.0;
+#endif
+
+ return col;
+}
+
+void main()
+{
+ vec2 screenco = vec2(gl_FragCoord.xy) * invscreenres;
+
+#ifdef DEFERRED_SHADING
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+ mat_id = texelFetch(idtex, texel, 0).r;
+
+ /* early out (manual stencil test) */
+ if (mat_id == 0)
+ discard;
+
+ float depth = texelFetch(depthtex, texel, 0).r;
+ vec3 N = normal_decode(texelFetch(normaltex, texel, 0).rg);
+ /* see the prepass for explanations. */
+ if (mat_id < 0) {
+ N = -N;
+ }
+ mat_id = abs(mat_id) - 1;
+#else
+ float depth = gl_FragCoord.z;
+ vec3 N = normal;
+#endif
+
+ vec3 position = get_view_space_from_depth(screenco, depth);
+
+ vec3 col = shade(N, position, depth, screenco);
+
+ fragColor = vec4(col, 1.0);
+}
diff --git a/source/blender/draw/engines/clay/shaders/clay_fxaa.glsl b/source/blender/draw/engines/clay/shaders/clay_fxaa.glsl
new file mode 100644
index 00000000000..924e51421aa
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/clay_fxaa.glsl
@@ -0,0 +1,18 @@
+
+in vec4 uvcoordsvar;
+out vec4 fragColor;
+
+uniform vec2 invscreenres;
+uniform sampler2D colortex;
+
+void main()
+{
+ fragColor = vec4(FxaaPixelShader(
+ uvcoordsvar.st,
+ colortex,
+ invscreenres,
+ 1.0,
+ 0.166,
+ 0.0833
+ ).rgb, 1.0);
+}
diff --git a/source/blender/draw/engines/clay/shaders/clay_particle_strand_frag.glsl b/source/blender/draw/engines/clay/shaders/clay_particle_strand_frag.glsl
new file mode 100644
index 00000000000..980a1e4690d
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/clay_particle_strand_frag.glsl
@@ -0,0 +1,144 @@
+
+/* Material Parameters packed in an UBO */
+struct Material {
+ vec4 one;
+ vec4 two;
+};
+
+layout(std140) uniform material_block {
+ Material shader_param[MAX_MATERIAL];
+};
+
+uniform mat4 ProjectionMatrix;
+uniform sampler2DArray matcaps;
+uniform int mat_id;
+
+#define randomness shader_param[mat_id].one.x
+#define matcap_index shader_param[mat_id].one.y
+#define matcap_rotation shader_param[mat_id].one.zw
+#define matcap_hsv shader_param[mat_id].two.xyz
+
+in vec3 tangent;
+in vec3 viewPosition;
+flat in float colRand;
+out vec4 fragColor;
+
+vec3 rotate(vec3 norm, vec3 ortho, float ang)
+{
+ return norm * cos(ang) + ortho * sin(ang);
+}
+
+void rgb_to_hsv(vec3 rgb, out vec3 outcol)
+{
+ float cmax, cmin, h, s, v, cdelta;
+ vec3 c;
+
+ cmax = max(rgb[0], max(rgb[1], rgb[2]));
+ cmin = min(rgb[0], min(rgb[1], rgb[2]));
+ cdelta = cmax - cmin;
+
+ v = cmax;
+ if (cmax != 0.0)
+ s = cdelta / cmax;
+ else {
+ s = 0.0;
+ h = 0.0;
+ }
+
+ if (s == 0.0) {
+ h = 0.0;
+ }
+ else {
+ c = (vec3(cmax, cmax, cmax) - rgb.xyz) / cdelta;
+
+ if (rgb.x == cmax) h = c[2] - c[1];
+ else if (rgb.y == cmax) h = 2.0 + c[0] - c[2];
+ else h = 4.0 + c[1] - c[0];
+
+ h /= 6.0;
+
+ if (h < 0.0)
+ h += 1.0;
+ }
+
+ outcol = vec3(h, s, v);
+}
+
+void hsv_to_rgb(vec3 hsv, out vec3 outcol)
+{
+ float i, f, p, q, t, h, s, v;
+ vec3 rgb;
+
+ h = hsv[0];
+ s = hsv[1];
+ v = hsv[2];
+
+ if (s == 0.0) {
+ rgb = vec3(v, v, v);
+ }
+ else {
+ if (h == 1.0)
+ h = 0.0;
+
+ h *= 6.0;
+ i = floor(h);
+ f = h - i;
+ rgb = vec3(f, f, f);
+ p = v * (1.0 - s);
+ q = v * (1.0 - (s * f));
+ t = v * (1.0 - (s * (1.0 - f)));
+
+ if (i == 0.0) rgb = vec3(v, t, p);
+ else if (i == 1.0) rgb = vec3(q, v, p);
+ else if (i == 2.0) rgb = vec3(p, v, t);
+ else if (i == 3.0) rgb = vec3(p, q, v);
+ else if (i == 4.0) rgb = vec3(t, p, v);
+ else rgb = vec3(v, p, q);
+ }
+
+ outcol = rgb;
+}
+
+void hue_sat(float hue, float sat, float value, inout vec3 col)
+{
+ vec3 hsv;
+
+ rgb_to_hsv(col, hsv);
+
+ hsv.x += hue;
+ hsv.x -= floor(hsv.x);
+ hsv.y *= sat;
+ hsv.y = clamp(hsv.y, 0.0, 1.0);
+ hsv.z *= value;
+ hsv.z = clamp(hsv.z, 0.0, 1.0);
+
+ hsv_to_rgb(hsv, col);
+}
+
+void main()
+{
+ vec3 viewvec = (ProjectionMatrix[3][3] == 0.0) ? normalize(viewPosition) : vec3(0.0, 0.0, -1.0);
+ vec3 ortho = normalize(cross(viewvec, tangent));
+ vec3 norm = normalize(cross(ortho, tangent));
+
+ vec3 col = vec3(0);
+
+ vec2 rotY = vec2(-matcap_rotation.y, matcap_rotation.x);
+
+ for (int i = 0; i < 9; i++) {
+ vec3 rotNorm = rotate(norm, ortho, -0.5 + (i * 0.125));
+ vec3 ray = reflect(viewvec, rotNorm);
+ vec2 texco = abs(vec2(dot(ray.xy, matcap_rotation), dot(ray.xy, rotY)) * .49 + 0.5);
+
+ col += texture(matcaps, vec3(texco, matcap_index)).rgb / 9.0;
+ }
+
+ hue_sat(matcap_hsv.x, matcap_hsv.y, matcap_hsv.z, col);
+
+ float maxChan = max(max(col.r, col.g), col.b);
+
+ col += (colRand * maxChan * randomness * 1.5) - (maxChan * randomness * 0.75);
+
+ fragColor.rgb = col;
+ fragColor.a = 1.0;
+}
diff --git a/source/blender/draw/engines/clay/shaders/clay_particle_vert.glsl b/source/blender/draw/engines/clay/shaders/clay_particle_vert.glsl
new file mode 100644
index 00000000000..d4c35d14182
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/clay_particle_vert.glsl
@@ -0,0 +1,34 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat3 NormalMatrix;
+uniform mat4 ModelViewMatrix;
+
+in vec3 pos;
+in vec3 nor;
+in int ind;
+out vec3 tangent;
+out vec3 viewPosition;
+flat out float colRand;
+
+float rand(int s)
+{
+ int seed = s * 1023423;
+
+ seed = (seed ^ 61) ^ (seed >> 16);
+ seed *= 9;
+ seed = seed ^ (seed >> 4);
+ seed *= 0x27d4eb2d;
+ seed = seed ^ (seed >> 15);
+
+ float value = float(seed);
+ value *= 1.0 / 42596.0;
+ return fract(value);
+}
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ tangent = normalize(NormalMatrix * nor);
+ viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
+ colRand = rand(ind);
+}
diff --git a/source/blender/draw/engines/clay/shaders/clay_prepass_frag.glsl b/source/blender/draw/engines/clay/shaders/clay_prepass_frag.glsl
new file mode 100644
index 00000000000..f30322bc9fe
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/clay_prepass_frag.glsl
@@ -0,0 +1,44 @@
+uniform int mat_id;
+
+#ifdef USE_FLAT_NORMAL
+flat in vec3 normal;
+#else
+in vec3 normal;
+#endif
+
+layout(location = 0) out vec2 outNormals;
+layout(location = 1) out int outIndex;
+
+/* From http://aras-p.info/texts/CompactNormalStorage.html
+ * Using Method #4: Spheremap Transform */
+vec2 normal_encode(vec3 n)
+{
+ float p = sqrt(n.z * 8.0 + 8.0);
+ return n.xy / p + 0.5;
+}
+
+/* 4x4 bayer matrix prepared for 8bit UNORM precision error. */
+#define P(x) (((x + 0.5) * (1.0 / 16.0) - 0.5) * (1.0 / 255.0))
+const vec4 dither_mat[4] = vec4[4](
+ vec4( P(0.0), P(8.0), P(2.0), P(10.0)),
+ vec4(P(12.0), P(4.0), P(14.0), P(6.0)),
+ vec4( P(3.0), P(11.0), P(1.0), P(9.0)),
+ vec4(P(15.0), P(7.0), P(13.0), P(5.0))
+);
+
+void main() {
+ outIndex = (mat_id + 1); /* 0 is clear color */
+ /**
+ * To fix the normal buffer precision issue for backfaces,
+ * we invert normals and use the sign of the index buffer
+ * to tag them, and re-invert in deferred pass.
+ **/
+ vec3 N = (gl_FrontFacing) ? normal : -normal;
+ outIndex = (gl_FrontFacing) ? outIndex : -outIndex;
+
+ outNormals = normal_encode(N);
+
+ /* Dither the output to fight low quality. */
+ ivec2 tx = ivec2(gl_FragCoord.xy) % 4;
+ outNormals += dither_mat[tx.x][tx.y];
+}
diff --git a/source/blender/draw/engines/clay/shaders/clay_vert.glsl b/source/blender/draw/engines/clay/shaders/clay_vert.glsl
new file mode 100644
index 00000000000..8f8866b3839
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/clay_vert.glsl
@@ -0,0 +1,17 @@
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat3 NormalMatrix;
+
+in vec3 pos;
+in vec3 nor;
+
+#ifdef USE_FLAT_NORMAL
+flat out vec3 normal;
+#else
+out vec3 normal;
+#endif
+
+void main()
+{
+ normal = normalize(NormalMatrix * nor);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl b/source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl
new file mode 100644
index 00000000000..94e2d6f3c7b
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/ssao_alchemy.glsl
@@ -0,0 +1,82 @@
+#define ssao_distance matcaps_param[mat_id].ssao_params_var.x
+#define ssao_factor_cavity matcaps_param[mat_id].ssao_params_var.y
+#define ssao_factor_edge matcaps_param[mat_id].ssao_params_var.z
+#define ssao_attenuation matcaps_param[mat_id].ssao_params_var.w
+
+/* from The Alchemy screen-space ambient obscurance algorithm
+ * http://graphics.cs.williams.edu/papers/AlchemyHPG11/VV11AlchemyAO.pdf */
+
+void ssao_factors(
+ in float depth, in vec3 normal, in vec3 position, in vec2 screenco,
+ out float cavities, out float edges)
+{
+ cavities = edges = 0.0;
+ /* early out if there is no need for SSAO */
+ if (ssao_factor_cavity == 0.0 && ssao_factor_edge == 0.0)
+ return;
+
+ /* take the normalized ray direction here */
+ vec3 noise = texture(ssao_jitter, screenco.xy * jitter_tilling).rgb;
+
+ /* find the offset in screen space by multiplying a point
+ * in camera space at the depth of the point by the projection matrix. */
+ vec2 offset;
+ float homcoord = WinMatrix[2][3] * position.z + WinMatrix[3][3];
+ offset.x = WinMatrix[0][0] * ssao_distance / homcoord;
+ offset.y = WinMatrix[1][1] * ssao_distance / homcoord;
+ /* convert from -1.0...1.0 range to 0.0..1.0 for easy use with texture coordinates */
+ offset *= 0.5;
+
+ int num_samples = int(ssao_samples_num);
+
+ /* Note. Putting noise usage here to put some ALU after texture fetch. */
+ vec2 rotX = noise.rg;
+ vec2 rotY = vec2(-rotX.y, rotX.x);
+
+ for (int x = 0; x < num_samples && x < 500; x++) {
+ /* ssao_samples[x].xy is sample direction (normalized).
+ * ssao_samples[x].z is sample distance from disk center. */
+
+ /* Rotate with random direction to get jittered result. */
+ vec2 dir_jittered = vec2(dot(ssao_samples[x].xy, rotX), dot(ssao_samples[x].xy, rotY));
+ dir_jittered.xy *= ssao_samples[x].z + noise.b;
+
+ vec2 uvcoords = screenco.xy + dir_jittered * offset;
+
+ if (uvcoords.x > 1.0 || uvcoords.x < 0.0 || uvcoords.y > 1.0 || uvcoords.y < 0.0)
+ continue;
+
+ float depth_new = texture(depthtex, uvcoords).r;
+
+ /* Handle Background case */
+ bool is_background = (depth_new == 1.0);
+
+ /* This trick provide good edge effect even if no neighboor is found. */
+ vec3 pos_new = get_view_space_from_depth(uvcoords, (is_background) ? depth : depth_new);
+
+ if (is_background)
+ pos_new.z -= ssao_distance;
+
+ vec3 dir = pos_new - position;
+ float len = length(dir);
+ float f_cavities = dot(dir, normal);
+ float f_edge = -f_cavities;
+ float f_bias = 0.05 * len + 0.0001;
+
+ float attenuation = 1.0 / (len * (1.0 + len * len * ssao_attenuation));
+
+ /* use minor bias here to avoid self shadowing */
+ if (f_cavities > -f_bias)
+ cavities += f_cavities * attenuation;
+
+ if (f_edge > f_bias)
+ edges += f_edge * attenuation;
+ }
+
+ cavities /= ssao_samples_num;
+ edges /= ssao_samples_num;
+
+ /* don't let cavity wash out the surface appearance */
+ cavities = clamp(cavities * ssao_factor_cavity, 0.0, 1.0);
+ edges = edges * ssao_factor_edge;
+}
diff --git a/source/blender/draw/engines/clay/shaders/ssao_groundtruth.glsl b/source/blender/draw/engines/clay/shaders/ssao_groundtruth.glsl
new file mode 100644
index 00000000000..9c203a4246c
--- /dev/null
+++ b/source/blender/draw/engines/clay/shaders/ssao_groundtruth.glsl
@@ -0,0 +1,122 @@
+#define ssao_distance matcaps_param[mat_id].ssao_params_var.x
+#define ssao_factor_cavity matcaps_param[mat_id].ssao_params_var.y
+#define ssao_factor_edge matcaps_param[mat_id].ssao_params_var.z
+#define ssao_attenuation matcaps_param[mat_id].ssao_params_var.w
+
+/* Based on Practical Realtime Strategies for Accurate Indirect Occlusion
+ * http://blog.selfshadow.com/publications/s2016-shading-course/activision/s2016_pbs_activision_occlusion.pdf
+ * http://blog.selfshadow.com/publications/s2016-shading-course/activision/s2016_pbs_activision_occlusion.pptx */
+
+#define COSINE_WEIGHTING
+
+float integrate_arc(in float h1, in float h2, in float gamma, in float n_proj_len)
+{
+ float a = 0.0;
+#ifdef COSINE_WEIGHTING
+ float cos_gamma = cos(gamma);
+ float sin_gamma_2 = 2.0 * sin(gamma);
+ a += -cos(2.0 * h1 - gamma) + cos_gamma + h1 * sin_gamma_2;
+ a += -cos(2.0 * h2 - gamma) + cos_gamma + h2 * sin_gamma_2;
+ a *= 0.25; /* 1/4 */
+ a *= n_proj_len;
+#else
+ /* Uniform weighting (slide 59) */
+ a += 1 - cos(h1);
+ a += 1 - cos(h2);
+#endif
+ return a;
+}
+
+float get_max_horizon(in vec2 co, in vec3 x, in vec3 omega_o, in float h)
+{
+ if (co.x > 1.0 || co.x < 0.0 || co.y > 1.0 || co.y < 0.0)
+ return h;
+
+ float depth = texture(depthtex, co).r;
+
+ /* Background case */
+ if (depth == 1.0)
+ return h;
+
+ vec3 s = get_view_space_from_depth(co, depth); /* s View coordinate */
+ vec3 omega_s = s - x;
+ float len = length(omega_s);
+
+ if (len < ssao_distance) {
+ omega_s /= len;
+ h = max(h, dot(omega_s, omega_o));
+ }
+ return h;
+}
+
+void ssao_factors(
+ in float depth, in vec3 normal, in vec3 position, in vec2 screenco,
+ out float cavities, out float edges)
+{
+ /* Renaming */
+ vec3 omega_o = -normalize(position); /* viewvec */
+ vec2 x_ = screenco; /* x^ Screen coordinate */
+ vec3 x = position; /* x view space coordinate */
+
+#ifdef SPATIAL_DENOISE
+ float noise_dir = (1.0 / 16.0) * float(((int(gl_FragCoord.x + gl_FragCoord.y) & 0x3) << 2) + (int(gl_FragCoord.x) & 0x3));
+ float noise_offset = (1.0 / 4.0) * float(int(gl_FragCoord.y - gl_FragCoord.x) & 0x3);
+#else
+ float noise_dir = (1.0 / 16.0) * float(((int(gl_FragCoord.x + gl_FragCoord.y) & 0x3) << 2) + (int(gl_FragCoord.x) & 0x3));
+ float noise_offset = (0.5 / 16.0) + (1.0 / 16.0) * float(((int(gl_FragCoord.x - gl_FragCoord.y) & 0x3) << 2) + (int(gl_FragCoord.x) & 0x3));
+#endif
+
+ const float phi_step = 16.0;
+ const float theta_step = 16.0;
+ const float m_pi = 3.14159265358979323846;
+ vec2 pixel_ratio = vec2(screenres.y / screenres.x, 1.0);
+ vec2 pixel_size = vec2(1.0) / screenres.xy;
+ float min_stride = length(pixel_size);
+ float homcco = WinMatrix[2][3] * position.z + WinMatrix[3][3];
+ float n = max(min_stride * theta_step, ssao_distance / homcco); /* Search distance */
+
+ /* Integral over PI */
+ float A = 0.0;
+ for (float i = 0.0; i < phi_step; i++) {
+ float phi = m_pi * ((noise_dir + i) / phi_step);
+
+ vec2 t_phi = vec2(cos(phi), sin(phi)); /* Screen space direction */
+
+ /* Search maximum horizon angles Theta1 and Theta2 */
+ float theta1 = -1.0, theta2 = -1.0; /* init at cos(pi) */
+ for (float j = 0.0; j < theta_step; j++) {
+ vec2 s_ = t_phi * pixel_ratio * n * ((j + noise_offset)/ theta_step); /* s^ Screen coordinate */
+ vec2 co;
+
+ co = x_ + s_;
+ theta1 = get_max_horizon(co, x, omega_o, theta1);
+
+ co = x_ - s_;
+ theta2 = get_max_horizon(co, x, omega_o, theta2);
+ }
+
+ /* (Slide 54) */
+ theta1 = -acos(theta1);
+ theta2 = acos(theta2);
+
+ /* Projecting Normal to Plane P defined by t_phi and omega_o */
+ vec3 h = normalize(cross(vec3(t_phi, 0.0), omega_o)); /* Normal vector to Integration plane */
+ vec3 t = cross(h, omega_o); /* Normal vector to plane */
+ vec3 n_proj = normal - h * dot(normal, h);
+ float n_proj_len = length(n_proj);
+ vec3 n_proj_norm = normalize(n_proj);
+
+ /* Clamping thetas (slide 58) */
+ float gamma = sign(dot(n_proj_norm, t)) * acos(dot(normal, omega_o)); /* Angle between view vec and normal */
+ theta1 = gamma + max(theta1 - gamma, -m_pi * 0.5);
+ theta2 = gamma + min(theta2 - gamma, m_pi * 0.5);
+
+ /* Solving inner integral */
+ A += integrate_arc(theta1, theta2, gamma, n_proj_len);
+ }
+
+ A /= phi_step;
+
+ cavities = 1.0 - A;
+ edges = 0.0;
+}
diff --git a/source/blender/draw/engines/eevee/eevee_bloom.c b/source/blender/draw/engines/eevee/eevee_bloom.c
new file mode 100644
index 00000000000..2b0cdf846b4
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_bloom.c
@@ -0,0 +1,334 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_bloom.c
+ * \ingroup draw_engine
+ *
+ * Eevee's bloom shader.
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_dynstr.h"
+
+#include "BKE_global.h" /* for G.debug_value */
+
+#include "eevee_private.h"
+#include "GPU_extensions.h"
+#include "GPU_texture.h"
+
+static struct {
+ /* Bloom */
+ struct GPUShader *bloom_blit_sh[2];
+ struct GPUShader *bloom_downsample_sh[2];
+ struct GPUShader *bloom_upsample_sh[2];
+ struct GPUShader *bloom_resolve_sh[2];
+} e_data = {{NULL}}; /* Engine data */
+
+extern char datatoc_effect_bloom_frag_glsl[];
+
+static void eevee_create_shader_bloom(void)
+{
+ e_data.bloom_blit_sh[0] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_BLIT\n");
+ e_data.bloom_blit_sh[1] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_BLIT\n"
+ "#define HIGH_QUALITY\n");
+
+ e_data.bloom_downsample_sh[0] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_DOWNSAMPLE\n");
+ e_data.bloom_downsample_sh[1] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_DOWNSAMPLE\n"
+ "#define HIGH_QUALITY\n");
+
+ e_data.bloom_upsample_sh[0] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_UPSAMPLE\n");
+ e_data.bloom_upsample_sh[1] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_UPSAMPLE\n"
+ "#define HIGH_QUALITY\n");
+
+ e_data.bloom_resolve_sh[0] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_RESOLVE\n");
+ e_data.bloom_resolve_sh[1] = DRW_shader_create_fullscreen(
+ datatoc_effect_bloom_frag_glsl,
+ "#define STEP_RESOLVE\n"
+ "#define HIGH_QUALITY\n");
+}
+
+int EEVEE_bloom_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "bloom_enable")) {
+ const float *viewport_size = DRW_viewport_size_get();
+
+ /* Shaders */
+ if (!e_data.bloom_blit_sh[0]) {
+ eevee_create_shader_bloom();
+ }
+
+ /* Bloom */
+ int blitsize[2], texsize[2];
+
+ /* Blit Buffer */
+ effects->source_texel_size[0] = 1.0f / viewport_size[0];
+ effects->source_texel_size[1] = 1.0f / viewport_size[1];
+
+ blitsize[0] = (int)viewport_size[0];
+ blitsize[1] = (int)viewport_size[1];
+
+ effects->blit_texel_size[0] = 1.0f / (float)blitsize[0];
+ effects->blit_texel_size[1] = 1.0f / (float)blitsize[1];
+
+ effects->bloom_blit = DRW_texture_pool_query_2D(blitsize[0], blitsize[1], GPU_R11F_G11F_B10F,
+ &draw_engine_eevee_type);
+
+ GPU_framebuffer_ensure_config(&fbl->bloom_blit_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->bloom_blit)
+ });
+
+ /* Parameters */
+ float threshold = BKE_collection_engine_property_value_get_float(props, "bloom_threshold");
+ float knee = BKE_collection_engine_property_value_get_float(props, "bloom_knee");
+ float intensity = BKE_collection_engine_property_value_get_float(props, "bloom_intensity");
+ const float *color = BKE_collection_engine_property_value_get_float_array(props, "bloom_color");
+ float radius = BKE_collection_engine_property_value_get_float(props, "bloom_radius");
+ effects->bloom_clamp = BKE_collection_engine_property_value_get_float(props, "bloom_clamp");
+
+ /* determine the iteration count */
+ const float minDim = (float)MIN2(blitsize[0], blitsize[1]);
+ const float maxIter = (radius - 8.0f) + log(minDim) / log(2);
+ const int maxIterInt = effects->bloom_iteration_ct = (int)maxIter;
+
+ CLAMP(effects->bloom_iteration_ct, 1, MAX_BLOOM_STEP);
+
+ effects->bloom_sample_scale = 0.5f + maxIter - (float)maxIterInt;
+ effects->bloom_curve_threshold[0] = threshold - knee;
+ effects->bloom_curve_threshold[1] = knee * 2.0f;
+ effects->bloom_curve_threshold[2] = 0.25f / max_ff(1e-5f, knee);
+ effects->bloom_curve_threshold[3] = threshold;
+
+ mul_v3_v3fl(effects->bloom_color, color, intensity);
+
+ /* Downsample buffers */
+ copy_v2_v2_int(texsize, blitsize);
+ for (int i = 0; i < effects->bloom_iteration_ct; ++i) {
+ texsize[0] /= 2; texsize[1] /= 2;
+
+ texsize[0] = MAX2(texsize[0], 2);
+ texsize[1] = MAX2(texsize[1], 2);
+
+ effects->downsamp_texel_size[i][0] = 1.0f / (float)texsize[0];
+ effects->downsamp_texel_size[i][1] = 1.0f / (float)texsize[1];
+
+ effects->bloom_downsample[i] = DRW_texture_pool_query_2D(texsize[0], texsize[1], GPU_R11F_G11F_B10F,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->bloom_down_fb[i], {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->bloom_downsample[i])
+ });
+ }
+
+ /* Upsample buffers */
+ copy_v2_v2_int(texsize, blitsize);
+ for (int i = 0; i < effects->bloom_iteration_ct - 1; ++i) {
+ texsize[0] /= 2; texsize[1] /= 2;
+
+ texsize[0] = MAX2(texsize[0], 2);
+ texsize[1] = MAX2(texsize[1], 2);
+
+ effects->bloom_upsample[i] = DRW_texture_pool_query_2D(texsize[0], texsize[1], GPU_R11F_G11F_B10F,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->bloom_accum_fb[i], {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->bloom_upsample[i])
+ });
+ }
+
+ return EFFECT_BLOOM | EFFECT_POST_BUFFER;
+ }
+
+ /* Cleanup to release memory */
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->bloom_blit_fb);
+
+ for (int i = 0; i < MAX_BLOOM_STEP - 1; ++i) {
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->bloom_down_fb[i]);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->bloom_accum_fb[i]);
+ }
+
+ return 0;
+}
+
+static DRWShadingGroup *eevee_create_bloom_pass(
+ const char *name, EEVEE_EffectsInfo *effects, struct GPUShader *sh, DRWPass **pass, bool upsample)
+{
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ *pass = DRW_pass_create(name, DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, *pass);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ DRW_shgroup_uniform_texture_ref(grp, "sourceBuffer", &effects->unf_source_buffer);
+ DRW_shgroup_uniform_vec2(grp, "sourceBufferTexelSize", effects->unf_source_texel_size, 1);
+ if (upsample) {
+ DRW_shgroup_uniform_texture_ref(grp, "baseBuffer", &effects->unf_base_buffer);
+ DRW_shgroup_uniform_float(grp, "sampleScale", &effects->bloom_sample_scale, 1);
+ }
+
+ return grp;
+}
+
+void EEVEE_bloom_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & EFFECT_BLOOM) != 0) {
+ /** Bloom algorithm
+ *
+ * Overview :
+ * - Downsample the color buffer doing a small blur during each step.
+ * - Accumulate bloom color using previously downsampled color buffers
+ * and do an upsample blur for each new accumulated layer.
+ * - Finally add accumulation buffer onto the source color buffer.
+ *
+ * [1/1] is original copy resolution (can be half or quater res for performance)
+ *
+ * [DOWNSAMPLE CHAIN] [UPSAMPLE CHAIN]
+ *
+ * Source Color ── [Blit] ──> Bright Color Extract [1/1] Final Color
+ * | Λ
+ * [Downsample First] Source Color ─> + [Resolve]
+ * v |
+ * Color Downsampled [1/2] ────────────> + Accumulation Buffer [1/2]
+ * | Λ
+ * ─── ───
+ * Repeat Repeat
+ * ─── ───
+ * v |
+ * Color Downsampled [1/N-1] ──────────> + Accumulation Buffer [1/N-1]
+ * | Λ
+ * [Downsample] [Upsample]
+ * v |
+ * Color Downsampled [1/N] ─────────────────────────┘
+ **/
+ DRWShadingGroup *grp;
+ const bool use_highres = true;
+ const bool use_antiflicker = true;
+ eevee_create_bloom_pass("Bloom Downsample First", effects, e_data.bloom_downsample_sh[use_antiflicker], &psl->bloom_downsample_first, false);
+ eevee_create_bloom_pass("Bloom Downsample", effects, e_data.bloom_downsample_sh[0], &psl->bloom_downsample, false);
+ eevee_create_bloom_pass("Bloom Upsample", effects, e_data.bloom_upsample_sh[use_highres], &psl->bloom_upsample, true);
+
+ grp = eevee_create_bloom_pass("Bloom Blit", effects, e_data.bloom_blit_sh[use_antiflicker], &psl->bloom_blit, false);
+ DRW_shgroup_uniform_vec4(grp, "curveThreshold", effects->bloom_curve_threshold, 1);
+ DRW_shgroup_uniform_float(grp, "clampIntensity", &effects->bloom_clamp, 1);
+
+ grp = eevee_create_bloom_pass("Bloom Resolve", effects, e_data.bloom_resolve_sh[use_highres], &psl->bloom_resolve, true);
+ DRW_shgroup_uniform_vec3(grp, "bloomColor", effects->bloom_color, 1);
+ }
+}
+
+void EEVEE_bloom_draw(EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ /* Bloom */
+ if ((effects->enabled_effects & EFFECT_BLOOM) != 0) {
+ struct GPUTexture *last;
+
+ /* Extract bright pixels */
+ copy_v2_v2(effects->unf_source_texel_size, effects->source_texel_size);
+ effects->unf_source_buffer = effects->source_buffer;
+
+ GPU_framebuffer_bind(fbl->bloom_blit_fb);
+ DRW_draw_pass(psl->bloom_blit);
+
+ /* Downsample */
+ copy_v2_v2(effects->unf_source_texel_size, effects->blit_texel_size);
+ effects->unf_source_buffer = effects->bloom_blit;
+
+ GPU_framebuffer_bind(fbl->bloom_down_fb[0]);
+ DRW_draw_pass(psl->bloom_downsample_first);
+
+ last = effects->bloom_downsample[0];
+
+ for (int i = 1; i < effects->bloom_iteration_ct; ++i) {
+ copy_v2_v2(effects->unf_source_texel_size, effects->downsamp_texel_size[i - 1]);
+ effects->unf_source_buffer = last;
+
+ GPU_framebuffer_bind(fbl->bloom_down_fb[i]);
+ DRW_draw_pass(psl->bloom_downsample);
+
+ /* Used in next loop */
+ last = effects->bloom_downsample[i];
+ }
+
+ /* Upsample and accumulate */
+ for (int i = effects->bloom_iteration_ct - 2; i >= 0; --i) {
+ copy_v2_v2(effects->unf_source_texel_size, effects->downsamp_texel_size[i]);
+ effects->unf_source_buffer = effects->bloom_downsample[i];
+ effects->unf_base_buffer = last;
+
+ GPU_framebuffer_bind(fbl->bloom_accum_fb[i]);
+ DRW_draw_pass(psl->bloom_upsample);
+
+ last = effects->bloom_upsample[i];
+ }
+
+ /* Resolve */
+ copy_v2_v2(effects->unf_source_texel_size, effects->downsamp_texel_size[0]);
+ effects->unf_source_buffer = last;
+ effects->unf_base_buffer = effects->source_buffer;
+
+ GPU_framebuffer_bind(effects->target_buffer);
+ DRW_draw_pass(psl->bloom_resolve);
+ SWAP_BUFFERS();
+ }
+}
+
+void EEVEE_bloom_free(void)
+{
+ for (int i = 0; i < 2; ++i) {
+ DRW_SHADER_FREE_SAFE(e_data.bloom_blit_sh[i]);
+ DRW_SHADER_FREE_SAFE(e_data.bloom_downsample_sh[i]);
+ DRW_SHADER_FREE_SAFE(e_data.bloom_upsample_sh[i]);
+ DRW_SHADER_FREE_SAFE(e_data.bloom_resolve_sh[i]);
+ }
+}
diff --git a/source/blender/draw/engines/eevee/eevee_data.c b/source/blender/draw/engines/eevee/eevee_data.c
new file mode 100644
index 00000000000..e9883cc3054
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_data.c
@@ -0,0 +1,183 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_data.c
+ * \ingroup draw_engine
+ *
+ * All specific data handler for Objects, Lights, ViewLayers, ...
+ */
+
+#include "DRW_render.h"
+
+#include "eevee_private.h"
+
+static void eevee_view_layer_data_free(void *storage)
+{
+ EEVEE_ViewLayerData *sldata = (EEVEE_ViewLayerData *)storage;
+
+ /* Lights */
+ MEM_SAFE_FREE(sldata->lamps);
+ DRW_UBO_FREE_SAFE(sldata->light_ubo);
+ DRW_UBO_FREE_SAFE(sldata->shadow_ubo);
+ DRW_UBO_FREE_SAFE(sldata->shadow_render_ubo);
+ GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_target_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cube_store_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cascade_target_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(sldata->shadow_cascade_store_fb);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_blur);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_target);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_blur);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_pool);
+ MEM_SAFE_FREE(sldata->shcasters_buffers[0].shadow_casters);
+ MEM_SAFE_FREE(sldata->shcasters_buffers[0].flags);
+ MEM_SAFE_FREE(sldata->shcasters_buffers[1].shadow_casters);
+ MEM_SAFE_FREE(sldata->shcasters_buffers[1].flags);
+
+ /* Probes */
+ MEM_SAFE_FREE(sldata->probes);
+ DRW_UBO_FREE_SAFE(sldata->probe_ubo);
+ DRW_UBO_FREE_SAFE(sldata->grid_ubo);
+ DRW_UBO_FREE_SAFE(sldata->planar_ubo);
+ DRW_UBO_FREE_SAFE(sldata->common_ubo);
+ DRW_UBO_FREE_SAFE(sldata->clip_ubo);
+ GPU_FRAMEBUFFER_FREE_SAFE(sldata->probe_filter_fb);
+ for (int i = 0; i < 6; ++i) {
+ GPU_FRAMEBUFFER_FREE_SAFE(sldata->probe_face_fb[i]);
+ }
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_rt);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_depth_rt);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->irradiance_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->irradiance_rt);
+}
+
+EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void)
+{
+ return (EEVEE_ViewLayerData *)DRW_view_layer_engine_data_get(
+ &draw_engine_eevee_type);
+}
+
+EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure(void)
+{
+ EEVEE_ViewLayerData **sldata = (EEVEE_ViewLayerData **)DRW_view_layer_engine_data_ensure(
+ &draw_engine_eevee_type, &eevee_view_layer_data_free);
+
+ if (*sldata == NULL) {
+ *sldata = MEM_callocN(sizeof(**sldata), "EEVEE_ViewLayerData");
+ }
+
+ return *sldata;
+}
+
+/* Object data. */
+
+static void eevee_object_data_init(ObjectEngineData *engine_data)
+{
+ EEVEE_ObjectEngineData *eevee_data = (EEVEE_ObjectEngineData *)engine_data;
+ eevee_data->shadow_caster_id = -1;
+}
+
+EEVEE_ObjectEngineData *EEVEE_object_data_get(Object *ob)
+{
+ if (ELEM(ob->type, OB_LIGHTPROBE, OB_LAMP)) {
+ return NULL;
+ }
+ return (EEVEE_ObjectEngineData *)DRW_object_engine_data_get(
+ ob, &draw_engine_eevee_type);
+}
+
+EEVEE_ObjectEngineData *EEVEE_object_data_ensure(Object *ob)
+{
+ BLI_assert(!ELEM(ob->type, OB_LIGHTPROBE, OB_LAMP));
+ return (EEVEE_ObjectEngineData *)DRW_object_engine_data_ensure(
+ ob,
+ &draw_engine_eevee_type,
+ sizeof(EEVEE_ObjectEngineData),
+ eevee_object_data_init,
+ NULL);
+}
+
+/* Light probe data. */
+
+static void eevee_lightprobe_data_init(ObjectEngineData *engine_data)
+{
+ EEVEE_LightProbeEngineData *ped = (EEVEE_LightProbeEngineData *)engine_data;
+ ped->need_full_update = true;
+ ped->need_update = true;
+}
+
+static void eevee_lightprobe_data_free(ObjectEngineData *engine_data)
+{
+ EEVEE_LightProbeEngineData *ped = (EEVEE_LightProbeEngineData *)engine_data;
+
+ BLI_freelistN(&ped->captured_object_list);
+}
+
+EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_get(Object *ob)
+{
+ if (ob->type != OB_LIGHTPROBE) {
+ return NULL;
+ }
+ return (EEVEE_LightProbeEngineData *)DRW_object_engine_data_get(
+ ob, &draw_engine_eevee_type);
+}
+
+EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_ensure(Object *ob)
+{
+ BLI_assert(ob->type == OB_LIGHTPROBE);
+ return (EEVEE_LightProbeEngineData *)DRW_object_engine_data_ensure(
+ ob,
+ &draw_engine_eevee_type,
+ sizeof(EEVEE_LightProbeEngineData),
+ eevee_lightprobe_data_init,
+ eevee_lightprobe_data_free);
+}
+
+/* Lamp data. */
+
+static void eevee_lamp_data_init(ObjectEngineData *engine_data)
+{
+ EEVEE_LampEngineData *led = (EEVEE_LampEngineData *)engine_data;
+ led->need_update = true;
+ led->prev_cube_shadow_id = -1;
+}
+
+EEVEE_LampEngineData *EEVEE_lamp_data_get(Object *ob)
+{
+ if (ob->type != OB_LAMP) {
+ return NULL;
+ }
+ return (EEVEE_LampEngineData *)DRW_object_engine_data_get(
+ ob, &draw_engine_eevee_type);
+}
+
+EEVEE_LampEngineData *EEVEE_lamp_data_ensure(Object *ob)
+{
+ BLI_assert(ob->type == OB_LAMP);
+ return (EEVEE_LampEngineData *)DRW_object_engine_data_ensure(
+ ob,
+ &draw_engine_eevee_type,
+ sizeof(EEVEE_LampEngineData),
+ eevee_lamp_data_init,
+ NULL);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_depth_of_field.c b/source/blender/draw/engines/eevee/eevee_depth_of_field.c
new file mode 100644
index 00000000000..393dbede00f
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_depth_of_field.c
@@ -0,0 +1,281 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_depth_of_field.c
+ * \ingroup draw_engine
+ *
+ * Depth of field post process effect.
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_dynstr.h"
+#include "BLI_rand.h"
+
+#include "DNA_anim_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_object_force_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_world_types.h"
+
+#include "BKE_global.h" /* for G.debug_value */
+#include "BKE_camera.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_animsys.h"
+#include "BKE_screen.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "eevee_private.h"
+#include "GPU_extensions.h"
+#include "GPU_framebuffer.h"
+#include "GPU_texture.h"
+
+#include "ED_screen.h"
+
+static struct {
+ /* Depth Of Field */
+ struct GPUShader *dof_downsample_sh;
+ struct GPUShader *dof_scatter_sh;
+ struct GPUShader *dof_resolve_sh;
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_effect_dof_vert_glsl[];
+extern char datatoc_effect_dof_geom_glsl[];
+extern char datatoc_effect_dof_frag_glsl[];
+
+static void eevee_create_shader_depth_of_field(void)
+{
+ e_data.dof_downsample_sh = DRW_shader_create(datatoc_effect_dof_vert_glsl, NULL,
+ datatoc_effect_dof_frag_glsl, "#define STEP_DOWNSAMPLE\n");
+ e_data.dof_scatter_sh = DRW_shader_create(datatoc_effect_dof_vert_glsl, NULL,
+ datatoc_effect_dof_frag_glsl, "#define STEP_SCATTER\n");
+ e_data.dof_resolve_sh = DRW_shader_create(datatoc_effect_dof_vert_glsl, NULL,
+ datatoc_effect_dof_frag_glsl, "#define STEP_RESOLVE\n");
+}
+
+int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, Object *camera)
+{
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "dof_enable")) {
+ Scene *scene = draw_ctx->scene;
+ RegionView3D *rv3d = draw_ctx->rv3d;
+
+ if (!e_data.dof_downsample_sh) {
+ eevee_create_shader_depth_of_field();
+ }
+
+ if (camera) {
+ const float *viewport_size = DRW_viewport_size_get();
+ Camera *cam = (Camera *)camera->data;
+
+ /* Retreive Near and Far distance */
+ effects->dof_near_far[0] = -cam->clipsta;
+ effects->dof_near_far[1] = -cam->clipend;
+
+ int buffer_size[2] = {(int)viewport_size[0] / 2, (int)viewport_size[1] / 2};
+
+ effects->dof_down_near = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], GPU_R11F_G11F_B10F,
+ &draw_engine_eevee_type);
+ effects->dof_down_far = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], GPU_R11F_G11F_B10F,
+ &draw_engine_eevee_type);
+ effects->dof_coc = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], GPU_RG16F,
+ &draw_engine_eevee_type);
+
+ GPU_framebuffer_ensure_config(&fbl->dof_down_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->dof_down_near),
+ GPU_ATTACHMENT_TEXTURE(effects->dof_down_far),
+ GPU_ATTACHMENT_TEXTURE(effects->dof_coc)
+ });
+
+ /* Go full 32bits for rendering and reduce the color artifacts. */
+ GPUTextureFormat fb_format = DRW_state_is_image_render() ? GPU_RGBA32F : GPU_RGBA16F;
+
+ effects->dof_far_blur = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], fb_format,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->dof_scatter_far_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->dof_far_blur),
+ });
+
+ effects->dof_near_blur = DRW_texture_pool_query_2D(buffer_size[0], buffer_size[1], fb_format,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->dof_scatter_near_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->dof_near_blur),
+ });
+
+ /* Parameters */
+ /* TODO UI Options */
+ float fstop = cam->gpu_dof.fstop;
+ float blades = cam->gpu_dof.num_blades;
+ float rotation = cam->gpu_dof.rotation;
+ float ratio = 1.0f / cam->gpu_dof.ratio;
+ float sensor = BKE_camera_sensor_size(cam->sensor_fit, cam->sensor_x, cam->sensor_y);
+ float focus_dist = BKE_camera_object_dof_distance(camera);
+ float focal_len = cam->lens;
+
+ UNUSED_VARS(rotation, ratio);
+
+ /* this is factor that converts to the scene scale. focal length and sensor are expressed in mm
+ * unit.scale_length is how many meters per blender unit we have. We want to convert to blender units though
+ * because the shader reads coordinates in world space, which is in blender units.
+ * Note however that focus_distance is already in blender units and shall not be scaled here (see T48157). */
+ float scale = (scene->unit.system) ? scene->unit.scale_length : 1.0f;
+ float scale_camera = 0.001f / scale;
+ /* we want radius here for the aperture number */
+ float aperture = 0.5f * scale_camera * focal_len / fstop;
+ float focal_len_scaled = scale_camera * focal_len;
+ float sensor_scaled = scale_camera * sensor;
+
+ if (rv3d != NULL) {
+ sensor_scaled *= rv3d->viewcamtexcofac[0];
+ }
+
+ effects->dof_params[0] = aperture * fabsf(focal_len_scaled / (focus_dist - focal_len_scaled));
+ effects->dof_params[1] = -focus_dist;
+ effects->dof_params[2] = viewport_size[0] / sensor_scaled;
+ effects->dof_bokeh[0] = blades;
+ effects->dof_bokeh[1] = rotation;
+ effects->dof_bokeh[2] = ratio;
+ effects->dof_bokeh[3] = BKE_collection_engine_property_value_get_float(props, "bokeh_max_size");
+
+ return EFFECT_DOF | EFFECT_POST_BUFFER;
+ }
+ }
+
+ /* Cleanup to release memory */
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_down_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_far_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->dof_scatter_near_fb);
+
+ return 0;
+}
+
+void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ if ((effects->enabled_effects & EFFECT_DOF) != 0) {
+ /** Depth of Field algorithm
+ *
+ * Overview :
+ * - Downsample the color buffer into 2 buffers weighted with
+ * CoC values. Also output CoC into a texture.
+ * - Shoot quads for every pixel and expand it depending on the CoC.
+ * Do one pass for near Dof and one pass for far Dof.
+ * - Finally composite the 2 blurred buffers with the original render.
+ **/
+ DRWShadingGroup *grp;
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ psl->dof_down = DRW_pass_create("DoF Downsample", DRW_STATE_WRITE_COLOR);
+
+ grp = DRW_shgroup_create(e_data.dof_downsample_sh, psl->dof_down);
+ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1);
+ DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ psl->dof_scatter = DRW_pass_create("DoF Scatter", DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE_FULL);
+
+ /* This create an empty batch of N triangles to be positioned
+ * by the vertex shader 0.4ms against 6ms with instancing */
+ const float *viewport_size = DRW_viewport_size_get();
+ const int sprite_ct = ((int)viewport_size[0] / 2) * ((int)viewport_size[1] / 2); /* brackets matters */
+ grp = DRW_shgroup_empty_tri_batch_create(e_data.dof_scatter_sh, psl->dof_scatter, sprite_ct);
+
+ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->unf_source_buffer);
+ DRW_shgroup_uniform_texture_ref(grp, "cocBuffer", &effects->dof_coc);
+ DRW_shgroup_uniform_vec2(grp, "layerSelection", effects->dof_layer_select, 1);
+ DRW_shgroup_uniform_vec4(grp, "bokehParams", effects->dof_bokeh, 1);
+
+ psl->dof_resolve = DRW_pass_create("DoF Resolve", DRW_STATE_WRITE_COLOR);
+
+ grp = DRW_shgroup_create(e_data.dof_resolve_sh, psl->dof_resolve);
+ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer);
+ DRW_shgroup_uniform_texture_ref(grp, "nearBuffer", &effects->dof_near_blur);
+ DRW_shgroup_uniform_texture_ref(grp, "farBuffer", &effects->dof_far_blur);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_vec2(grp, "nearFar", effects->dof_near_far, 1);
+ DRW_shgroup_uniform_vec3(grp, "dofParams", effects->dof_params, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+}
+
+void EEVEE_depth_of_field_draw(EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ /* Depth Of Field */
+ if ((effects->enabled_effects & EFFECT_DOF) != 0) {
+ float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ /* Downsample */
+ GPU_framebuffer_bind(fbl->dof_down_fb);
+ DRW_draw_pass(psl->dof_down);
+
+ /* Scatter Far */
+ effects->unf_source_buffer = effects->dof_down_far;
+ copy_v2_fl2(effects->dof_layer_select, 0.0f, 1.0f);
+ GPU_framebuffer_bind(fbl->dof_scatter_far_fb);
+ GPU_framebuffer_clear_color(fbl->dof_scatter_far_fb, clear_col);
+ DRW_draw_pass(psl->dof_scatter);
+
+ /* Scatter Near */
+ effects->unf_source_buffer = effects->dof_down_near;
+ copy_v2_fl2(effects->dof_layer_select, 1.0f, 0.0f);
+ GPU_framebuffer_bind(fbl->dof_scatter_near_fb);
+ GPU_framebuffer_clear_color(fbl->dof_scatter_near_fb, clear_col);
+ DRW_draw_pass(psl->dof_scatter);
+
+ /* Resolve */
+ GPU_framebuffer_bind(effects->target_buffer);
+ DRW_draw_pass(psl->dof_resolve);
+ SWAP_BUFFERS();
+ }
+}
+
+void EEVEE_depth_of_field_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.dof_downsample_sh);
+ DRW_SHADER_FREE_SAFE(e_data.dof_scatter_sh);
+ DRW_SHADER_FREE_SAFE(e_data.dof_resolve_sh);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_effects.c b/source/blender/draw/engines/eevee/eevee_effects.c
new file mode 100644
index 00000000000..984ecfcea89
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_effects.c
@@ -0,0 +1,544 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_effects.c
+ * \ingroup draw_engine
+ *
+ * Gather all screen space effects technique such as Bloom, Motion Blur, DoF, SSAO, SSR, ...
+ */
+
+#include "DRW_render.h"
+
+#include "BKE_global.h" /* for G.debug_value */
+
+#include "BLI_string_utils.h"
+
+#include "eevee_private.h"
+#include "GPU_texture.h"
+#include "GPU_extensions.h"
+
+static struct {
+ /* Downsample Depth */
+ struct GPUShader *minz_downlevel_sh;
+ struct GPUShader *maxz_downlevel_sh;
+ struct GPUShader *minz_downdepth_sh;
+ struct GPUShader *maxz_downdepth_sh;
+ struct GPUShader *minz_downdepth_layer_sh;
+ struct GPUShader *maxz_downdepth_layer_sh;
+ struct GPUShader *minz_copydepth_sh;
+ struct GPUShader *maxz_copydepth_sh;
+
+ /* Simple Downsample */
+ struct GPUShader *downsample_sh;
+ struct GPUShader *downsample_cube_sh;
+
+ /* Velocity Resolve */
+ struct GPUShader *velocity_resolve_sh;
+
+ /* Theses are just references, not actually allocated */
+ struct GPUTexture *depth_src;
+ struct GPUTexture *color_src;
+
+ int depth_src_layer;
+ float cube_texel_size;
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_effect_velocity_resolve_frag_glsl[];
+extern char datatoc_effect_minmaxz_frag_glsl[];
+extern char datatoc_effect_downsample_frag_glsl[];
+extern char datatoc_effect_downsample_cube_frag_glsl[];
+extern char datatoc_lightprobe_vert_glsl[];
+extern char datatoc_lightprobe_geom_glsl[];
+
+static void eevee_create_shader_downsample(void)
+{
+ char *frag_str = BLI_string_joinN(
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_common_view_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_effect_velocity_resolve_frag_glsl);
+
+ e_data.velocity_resolve_sh = DRW_shader_create_fullscreen(frag_str, NULL);
+
+ MEM_freeN(frag_str);
+
+ e_data.downsample_sh = DRW_shader_create_fullscreen(datatoc_effect_downsample_frag_glsl, NULL);
+ e_data.downsample_cube_sh = DRW_shader_create(
+ datatoc_lightprobe_vert_glsl,
+ datatoc_lightprobe_geom_glsl,
+ datatoc_effect_downsample_cube_frag_glsl, NULL);
+
+ e_data.minz_downlevel_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MIN_PASS\n");
+ e_data.maxz_downlevel_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MAX_PASS\n");
+ e_data.minz_downdepth_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MIN_PASS\n");
+ e_data.maxz_downdepth_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MAX_PASS\n");
+ e_data.minz_downdepth_layer_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MIN_PASS\n"
+ "#define LAYERED\n");
+ e_data.maxz_downdepth_layer_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MAX_PASS\n"
+ "#define LAYERED\n");
+ e_data.minz_copydepth_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MIN_PASS\n"
+ "#define COPY_DEPTH\n");
+ e_data.maxz_copydepth_sh = DRW_shader_create_fullscreen(
+ datatoc_effect_minmaxz_frag_glsl,
+ "#define MAX_PASS\n"
+ "#define COPY_DEPTH\n");
+}
+
+void EEVEE_effects_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Object *camera)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+
+ const float *viewport_size = DRW_viewport_size_get();
+ int size_fs[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+
+ /* Shaders */
+ if (!e_data.downsample_sh) {
+ eevee_create_shader_downsample();
+ }
+
+ if (!stl->effects) {
+ stl->effects = MEM_callocN(sizeof(EEVEE_EffectsInfo), "EEVEE_EffectsInfo");
+ }
+
+ effects = stl->effects;
+
+ effects->enabled_effects = 0;
+ effects->enabled_effects |= (G.debug_value == 9) ? EFFECT_VELOCITY_BUFFER : 0;
+ effects->enabled_effects |= EEVEE_motion_blur_init(sldata, vedata, camera);
+ effects->enabled_effects |= EEVEE_bloom_init(sldata, vedata);
+ effects->enabled_effects |= EEVEE_depth_of_field_init(sldata, vedata, camera);
+ effects->enabled_effects |= EEVEE_temporal_sampling_init(sldata, vedata);
+ effects->enabled_effects |= EEVEE_occlusion_init(sldata, vedata);
+ effects->enabled_effects |= EEVEE_subsurface_init(sldata, vedata);
+ effects->enabled_effects |= EEVEE_screen_raytrace_init(sldata, vedata);
+ effects->enabled_effects |= EEVEE_volumes_init(sldata, vedata);
+
+ /* Force normal buffer creation. */
+ if (DRW_state_is_image_render() &&
+ (view_layer->passflag & SCE_PASS_NORMAL) != 0)
+ {
+ effects->enabled_effects |= EFFECT_NORMAL_BUFFER;
+ }
+
+ /**
+ * Ping Pong buffer
+ */
+ if ((effects->enabled_effects & EFFECT_POST_BUFFER) != 0) {
+ DRW_texture_ensure_fullscreen_2D(&txl->color_post, GPU_RGBA16F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
+
+ GPU_framebuffer_ensure_config(&fbl->effect_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(txl->color_post),
+ });
+
+ GPU_framebuffer_ensure_config(&fbl->effect_color_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->color_post),
+ });
+ }
+ else {
+ /* Cleanup to release memory */
+ DRW_TEXTURE_FREE_SAFE(txl->color_post);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->effect_fb);
+ }
+
+ /**
+ * MinMax Pyramid
+ */
+ int size[2];
+ size[0] = max_ii(size_fs[0] / 2, 1);
+ size[1] = max_ii(size_fs[1] / 2, 1);
+
+ if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+ /* Intel gpu seems to have problem rendering to only depth format */
+ DRW_texture_ensure_2D(&txl->maxzbuffer, size[0], size[1], GPU_R32F, DRW_TEX_MIPMAP);
+ }
+ else {
+ DRW_texture_ensure_2D(&txl->maxzbuffer, size[0], size[1], GPU_DEPTH_COMPONENT24, DRW_TEX_MIPMAP);
+ }
+
+ if (fbl->downsample_fb == NULL) {
+ fbl->downsample_fb = GPU_framebuffer_create();
+ }
+
+ /**
+ * Compute Mipmap texel alignement.
+ */
+ for (int i = 0; i < 10; ++i) {
+ float mip_size[2] = {viewport_size[0], viewport_size[1]};
+ for (int j = 0; j < i; ++j) {
+ mip_size[0] = floorf(fmaxf(1.0f, mip_size[0] / 2.0f));
+ mip_size[1] = floorf(fmaxf(1.0f, mip_size[1] / 2.0f));
+ }
+ common_data->mip_ratio[i][0] = viewport_size[0] / (mip_size[0] * powf(2.0f, floorf(log2f(floorf(viewport_size[0] / mip_size[0])))));
+ common_data->mip_ratio[i][1] = viewport_size[1] / (mip_size[1] * powf(2.0f, floorf(log2f(floorf(viewport_size[1] / mip_size[1])))));
+ }
+
+
+ /**
+ * Normal buffer for deferred passes.
+ */
+ if ((effects->enabled_effects & EFFECT_NORMAL_BUFFER) != 0) {
+ effects->ssr_normal_input = DRW_texture_pool_query_2D(size_fs[0], size_fs[1], GPU_RG16F,
+ &draw_engine_eevee_type);
+
+ GPU_framebuffer_texture_attach(fbl->main_fb, effects->ssr_normal_input, 1, 0);
+ }
+ else {
+ effects->ssr_normal_input = NULL;
+ }
+
+ /**
+ * Motion vector buffer for correct TAA / motion blur.
+ */
+ if ((effects->enabled_effects & EFFECT_VELOCITY_BUFFER) != 0) {
+ effects->velocity_tx = DRW_texture_pool_query_2D(size_fs[0], size_fs[1], GPU_RG16,
+ &draw_engine_eevee_type);
+
+ /* TODO output objects velocity during the mainpass. */
+ // GPU_framebuffer_texture_attach(fbl->main_fb, effects->velocity_tx, 1, 0);
+
+ GPU_framebuffer_ensure_config(&fbl->velocity_resolve_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->velocity_tx)
+ });
+ }
+ else {
+ effects->velocity_tx = NULL;
+ }
+
+ /**
+ * Setup depth double buffer.
+ */
+ if ((effects->enabled_effects & EFFECT_DEPTH_DOUBLE_BUFFER) != 0) {
+ DRW_texture_ensure_fullscreen_2D(&txl->depth_double_buffer, GPU_DEPTH24_STENCIL8, 0);
+
+ GPU_framebuffer_ensure_config(&fbl->double_buffer_depth_fb, {
+ GPU_ATTACHMENT_TEXTURE(txl->depth_double_buffer)
+ });
+ }
+ else {
+ /* Cleanup to release memory */
+ DRW_TEXTURE_FREE_SAFE(txl->depth_double_buffer);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->double_buffer_depth_fb);
+ }
+
+ /**
+ * Setup double buffer so we can access last frame as it was before post processes.
+ */
+ if ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0) {
+ DRW_texture_ensure_fullscreen_2D(&txl->color_double_buffer, GPU_RGBA16F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
+
+ GPU_framebuffer_ensure_config(&fbl->double_buffer_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(txl->color_double_buffer)
+ });
+
+ GPU_framebuffer_ensure_config(&fbl->double_buffer_color_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->color_double_buffer)
+ });
+ }
+ else {
+ /* Cleanup to release memory */
+ DRW_TEXTURE_FREE_SAFE(txl->color_double_buffer);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->double_buffer_fb);
+ }
+}
+
+void EEVEE_effects_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ int downsample_write = DRW_STATE_WRITE_DEPTH;
+
+ /* Intel gpu seems to have problem rendering to only depth format.
+ * Use color texture instead. */
+ if (GPU_type_matches(GPU_DEVICE_INTEL, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+ downsample_write = DRW_STATE_WRITE_COLOR;
+ }
+
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ {
+ psl->color_downsample_ps = DRW_pass_create("Downsample", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.downsample_sh, psl->color_downsample_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "source", &e_data.color_src);
+ DRW_shgroup_uniform_float(grp, "fireflyFactor", &sldata->common_data.ssr_firefly_fac, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+
+ {
+ static int zero = 0;
+ static unsigned int six = 6;
+ psl->color_downsample_cube_ps = DRW_pass_create("Downsample Cube", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.downsample_cube_sh, psl->color_downsample_cube_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "source", &e_data.color_src);
+ DRW_shgroup_uniform_float(grp, "texelSize", &e_data.cube_texel_size, 1);
+ DRW_shgroup_uniform_int(grp, "Layer", &zero, 1);
+ DRW_shgroup_call_instances_add(grp, quad, NULL, &six);
+ }
+
+ {
+ /* Perform min/max downsample */
+ DRWShadingGroup *grp;
+
+ psl->maxz_downlevel_ps = DRW_pass_create("HiZ Max Down Level", downsample_write | DRW_STATE_DEPTH_ALWAYS);
+ grp = DRW_shgroup_create(e_data.maxz_downlevel_sh, psl->maxz_downlevel_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &txl->maxzbuffer);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ /* Copy depth buffer to halfres top level of HiZ */
+
+ psl->maxz_downdepth_ps = DRW_pass_create("HiZ Max Copy Depth Halfres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
+ grp = DRW_shgroup_create(e_data.maxz_downdepth_sh, psl->maxz_downdepth_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data.depth_src);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ psl->maxz_downdepth_layer_ps = DRW_pass_create("HiZ Max Copy DepthLayer Halfres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
+ grp = DRW_shgroup_create(e_data.maxz_downdepth_layer_sh, psl->maxz_downdepth_layer_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data.depth_src);
+ DRW_shgroup_uniform_int(grp, "depthLayer", &e_data.depth_src_layer, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ psl->maxz_copydepth_ps = DRW_pass_create("HiZ Max Copy Depth Fullres", downsample_write | DRW_STATE_DEPTH_ALWAYS);
+ grp = DRW_shgroup_create(e_data.maxz_copydepth_sh, psl->maxz_copydepth_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data.depth_src);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+
+ if ((effects->enabled_effects & EFFECT_VELOCITY_BUFFER) != 0) {
+ /* This pass compute camera motions to the non moving objects. */
+ psl->velocity_resolve = DRW_pass_create("Velocity Resolve", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.velocity_resolve_sh, psl->velocity_resolve);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data.depth_src);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_uniform_mat4(grp, "currPersinv", effects->velocity_curr_persinv);
+ DRW_shgroup_uniform_mat4(grp, "pastPersmat", effects->velocity_past_persmat);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+}
+
+#if 0 /* Not required for now */
+static void min_downsample_cb(void *vedata, int UNUSED(level))
+{
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ DRW_draw_pass(psl->minz_downlevel_ps);
+}
+#endif
+
+static void max_downsample_cb(void *vedata, int UNUSED(level))
+{
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ DRW_draw_pass(psl->maxz_downlevel_ps);
+}
+
+static void simple_downsample_cb(void *vedata, int UNUSED(level))
+{
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ DRW_draw_pass(psl->color_downsample_ps);
+}
+
+static void simple_downsample_cube_cb(void *vedata, int level)
+{
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ e_data.cube_texel_size = (float)(1 << level) / (float)GPU_texture_width(e_data.color_src);
+ DRW_draw_pass(psl->color_downsample_cube_ps);
+}
+
+void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, GPUTexture *depth_src, int layer)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+
+ e_data.depth_src = depth_src;
+ e_data.depth_src_layer = layer;
+
+#if 0 /* Not required for now */
+ DRW_stats_group_start("Min buffer");
+ /* Copy depth buffer to min texture top level */
+ GPU_framebuffer_texture_attach(fbl->downsample_fb, stl->g_data->minzbuffer, 0, 0);
+ GPU_framebuffer_bind(fbl->downsample_fb);
+ if (layer >= 0) {
+ DRW_draw_pass(psl->minz_downdepth_layer_ps);
+ }
+ else {
+ DRW_draw_pass(psl->minz_downdepth_ps);
+ }
+ GPU_framebuffer_texture_detach(stl->g_data->minzbuffer);
+
+ /* Create lower levels */
+ GPU_framebuffer_recursive_downsample(fbl->downsample_fb, stl->g_data->minzbuffer, 8, &min_downsample_cb, vedata);
+ DRW_stats_group_end();
+#endif
+
+ DRW_stats_group_start("Max buffer");
+ /* Copy depth buffer to max texture top level */
+ GPU_framebuffer_texture_attach(fbl->downsample_fb, txl->maxzbuffer, 0, 0);
+ GPU_framebuffer_bind(fbl->downsample_fb);
+ if (layer >= 0) {
+ DRW_draw_pass(psl->maxz_downdepth_layer_ps);
+ }
+ else {
+ DRW_draw_pass(psl->maxz_downdepth_ps);
+ }
+
+ /* Create lower levels */
+ GPU_framebuffer_recursive_downsample(fbl->downsample_fb, 8, &max_downsample_cb, vedata);
+ GPU_framebuffer_texture_detach(fbl->downsample_fb, txl->maxzbuffer);
+ DRW_stats_group_end();
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+}
+
+/**
+ * Simple downsampling algorithm. Reconstruct mip chain up to mip level.
+ **/
+void EEVEE_downsample_buffer(EEVEE_Data *vedata, GPUTexture *texture_src, int level)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ e_data.color_src = texture_src;
+
+ /* Create lower levels */
+ DRW_stats_group_start("Downsample buffer");
+ GPU_framebuffer_texture_attach(fbl->downsample_fb, texture_src, 0, 0);
+ GPU_framebuffer_recursive_downsample(fbl->downsample_fb, level, &simple_downsample_cb, vedata);
+ GPU_framebuffer_texture_detach(fbl->downsample_fb, texture_src);
+ DRW_stats_group_end();
+}
+
+/**
+ * Simple downsampling algorithm for cubemap. Reconstruct mip chain up to mip level.
+ **/
+void EEVEE_downsample_cube_buffer(EEVEE_Data *vedata, GPUTexture *texture_src, int level)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ e_data.color_src = texture_src;
+
+ /* Create lower levels */
+ DRW_stats_group_start("Downsample Cube buffer");
+ GPU_framebuffer_texture_attach(fbl->downsample_fb, texture_src, 0, 0);
+ GPU_framebuffer_recursive_downsample(fbl->downsample_fb, level, &simple_downsample_cube_cb, vedata);
+ GPU_framebuffer_texture_detach(fbl->downsample_fb, texture_src);
+ DRW_stats_group_end();
+}
+
+void EEVEE_draw_effects(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ /* First resolve the velocity. */
+ if ((effects->enabled_effects & EFFECT_VELOCITY_BUFFER) != 0) {
+ DRW_viewport_matrix_get(effects->velocity_curr_persinv, DRW_MAT_PERSINV);
+
+ GPU_framebuffer_bind(fbl->velocity_resolve_fb);
+ DRW_draw_pass(psl->velocity_resolve);
+ }
+ DRW_viewport_matrix_get(effects->velocity_past_persmat, DRW_MAT_PERS);
+
+ /* only once per frame after the first post process */
+ effects->swap_double_buffer = ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0);
+
+ /* Init pointers */
+ effects->source_buffer = txl->color; /* latest updated texture */
+ effects->target_buffer = fbl->effect_color_fb; /* next target to render to */
+
+ /* Temporal Anti-Aliasing MUST come first */
+ EEVEE_temporal_sampling_draw(vedata);
+
+ /* Post process stack (order matters) */
+ EEVEE_motion_blur_draw(vedata);
+ EEVEE_depth_of_field_draw(vedata);
+ EEVEE_bloom_draw(vedata);
+
+ /* Save the final texture and framebuffer for final transformation or read. */
+ effects->final_tx = effects->source_buffer;
+ effects->final_fb = (effects->target_buffer != fbl->main_color_fb) ? fbl->main_fb : fbl->effect_fb;
+
+ /* If no post processes is enabled, buffers are still not swapped, do it now. */
+ SWAP_DOUBLE_BUFFERS();
+
+ if (!stl->g_data->valid_double_buffer &&
+ ((effects->enabled_effects & EFFECT_DOUBLE_BUFFER) != 0) &&
+ (DRW_state_is_image_render() == false))
+ {
+ /* If history buffer is not valid request another frame.
+ * This fix black reflections on area resize. */
+ DRW_viewport_request_redraw();
+ }
+
+ /* Record pers matrix for the next frame. */
+ DRW_viewport_matrix_get(stl->effects->prev_persmat, DRW_MAT_PERS);
+
+ /* Update double buffer status if render mode. */
+ if (DRW_state_is_image_render()) {
+ stl->g_data->valid_double_buffer = (txl->color_double_buffer != NULL);
+ }
+}
+
+void EEVEE_effects_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.velocity_resolve_sh);
+
+ DRW_SHADER_FREE_SAFE(e_data.downsample_sh);
+ DRW_SHADER_FREE_SAFE(e_data.downsample_cube_sh);
+
+ DRW_SHADER_FREE_SAFE(e_data.minz_downlevel_sh);
+ DRW_SHADER_FREE_SAFE(e_data.maxz_downlevel_sh);
+ DRW_SHADER_FREE_SAFE(e_data.minz_downdepth_sh);
+ DRW_SHADER_FREE_SAFE(e_data.maxz_downdepth_sh);
+ DRW_SHADER_FREE_SAFE(e_data.minz_downdepth_layer_sh);
+ DRW_SHADER_FREE_SAFE(e_data.maxz_downdepth_layer_sh);
+ DRW_SHADER_FREE_SAFE(e_data.minz_copydepth_sh);
+ DRW_SHADER_FREE_SAFE(e_data.maxz_copydepth_sh);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_engine.c b/source/blender/draw/engines/eevee/eevee_engine.c
new file mode 100644
index 00000000000..1c0247068cc
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_engine.c
@@ -0,0 +1,535 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_engine.c
+ * \ingroup draw_engine
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_dynstr.h"
+#include "BLI_rand.h"
+
+#include "BKE_object.h"
+#include "BKE_global.h" /* for G.debug_value */
+#include "BKE_screen.h"
+
+#include "DNA_world_types.h"
+
+#include "ED_screen.h"
+
+#include "GPU_material.h"
+#include "GPU_glew.h"
+
+#include "eevee_engine.h"
+#include "eevee_private.h"
+
+#define EEVEE_ENGINE "BLENDER_EEVEE"
+
+extern GlobalsUboStorage ts;
+
+/* *********** FUNCTIONS *********** */
+
+static void eevee_engine_init(void *ved)
+{
+ EEVEE_Data *vedata = (EEVEE_Data *)ved;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ RegionView3D *rv3d = draw_ctx->rv3d;
+ Object *camera = (rv3d->persp == RV3D_CAMOB) ? v3d->camera : NULL;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
+ }
+ stl->g_data->background_alpha = DRW_state_draw_background() ? 1.0f : 0.0f;
+ stl->g_data->valid_double_buffer = (txl->color_double_buffer != NULL);
+
+ /* Main Buffer */
+ DRW_texture_ensure_fullscreen_2D(&txl->color, GPU_RGBA16F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
+
+ GPU_framebuffer_ensure_config(&fbl->main_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(txl->color),
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE
+ });
+
+ GPU_framebuffer_ensure_config(&fbl->main_color_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->color)
+ });
+
+ if (sldata->common_ubo == NULL) {
+ sldata->common_ubo = DRW_uniformbuffer_create(sizeof(sldata->common_data), &sldata->common_data);
+ }
+ if (sldata->clip_ubo == NULL) {
+ sldata->clip_ubo = DRW_uniformbuffer_create(sizeof(sldata->clip_data), &sldata->clip_data);
+ }
+
+ /* EEVEE_effects_init needs to go first for TAA */
+ EEVEE_effects_init(sldata, vedata, camera);
+ EEVEE_materials_init(sldata, stl, fbl);
+ EEVEE_lights_init(sldata);
+ EEVEE_lightprobes_init(sldata, vedata);
+
+ if ((stl->effects->taa_current_sample > 1) && !DRW_state_is_image_render()) {
+ /* XXX otherwise it would break the other engines. */
+ DRW_viewport_matrix_override_unset_all();
+ }
+}
+
+static void eevee_cache_init(void *vedata)
+{
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+
+ EEVEE_bloom_cache_init(sldata, vedata);
+ EEVEE_depth_of_field_cache_init(sldata, vedata);
+ EEVEE_effects_cache_init(sldata, vedata);
+ EEVEE_lightprobes_cache_init(sldata, vedata);
+ EEVEE_lights_cache_init(sldata, vedata);
+ EEVEE_materials_cache_init(sldata, vedata);
+ EEVEE_motion_blur_cache_init(sldata, vedata);
+ EEVEE_occlusion_cache_init(sldata, vedata);
+ EEVEE_screen_raytrace_cache_init(sldata, vedata);
+ EEVEE_subsurface_cache_init(sldata, vedata);
+ EEVEE_temporal_sampling_cache_init(sldata, vedata);
+ EEVEE_volumes_cache_init(sldata, vedata);
+}
+
+static void eevee_cache_populate(void *vedata, Object *ob)
+{
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const bool is_active = (ob == draw_ctx->obact);
+ if (is_active) {
+ if (DRW_object_is_mode_shade(ob) == true) {
+ return;
+ }
+ }
+
+ if (DRW_check_object_visible_within_active_context(ob) == false) {
+ return;
+ }
+
+ if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
+ bool cast_shadow;
+
+ EEVEE_materials_cache_populate(vedata, sldata, ob, &cast_shadow);
+
+ if (cast_shadow) {
+ EEVEE_lights_cache_shcaster_object_add(sldata, ob);
+ }
+ }
+ else if (ob->type == OB_LIGHTPROBE) {
+ if ((ob->base_flag & BASE_FROMDUPLI) != 0) {
+ /* TODO: Special case for dupli objects because we cannot save the object pointer. */
+ }
+ else {
+ EEVEE_lightprobes_cache_add(sldata, ob);
+ }
+ }
+ else if (ob->type == OB_LAMP) {
+ EEVEE_lights_cache_add(sldata, ob);
+ }
+}
+
+static void eevee_cache_finish(void *vedata)
+{
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+
+ EEVEE_materials_cache_finish(vedata);
+ EEVEE_lights_cache_finish(sldata);
+ EEVEE_lightprobes_cache_finish(sldata, vedata);
+}
+
+/* As renders in an HDR offscreen buffer, we need draw everything once
+ * during the background pass. This way the other drawing callback between
+ * the background and the scene pass are visible.
+ * Note: we could break it up in two passes using some depth test
+ * to reduce the fillrate */
+static void eevee_draw_background(void *vedata)
+{
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ EEVEE_TextureList *txl = ((EEVEE_Data *)vedata)->txl;
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+ EEVEE_FramebufferList *fbl = ((EEVEE_Data *)vedata)->fbl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+
+ /* Default framebuffer and texture */
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+
+ /* Sort transparents before the loop. */
+ DRW_pass_sort_shgroup_z(psl->transparent_pass);
+
+ /* Number of iteration: needed for all temporal effect (SSR, volumetrics)
+ * when using opengl render. */
+ int loop_ct = (DRW_state_is_image_render() &&
+ (stl->effects->enabled_effects & (EFFECT_VOLUMETRIC | EFFECT_SSR)) != 0) ? 4 : 1;
+
+ while (loop_ct--) {
+ float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ float clear_depth = 1.0f;
+ unsigned int clear_stencil = 0xFF;
+ unsigned int primes[3] = {2, 3, 7};
+ double offset[3] = {0.0, 0.0, 0.0};
+ double r[3];
+
+ bool taa_use_reprojection = (stl->effects->enabled_effects & EFFECT_TAA_REPROJECT) != 0;
+
+ if (DRW_state_is_image_render() ||
+ taa_use_reprojection ||
+ ((stl->effects->enabled_effects & EFFECT_TAA) != 0))
+ {
+ int samp = taa_use_reprojection
+ ? stl->effects->taa_reproject_sample + 1
+ : stl->effects->taa_current_sample;
+ BLI_halton_3D(primes, offset, samp, r);
+ EEVEE_update_noise(psl, fbl, r);
+ EEVEE_volumes_set_jitter(sldata, samp - 1);
+ EEVEE_materials_init(sldata, stl, fbl);
+ }
+ /* Copy previous persmat to UBO data */
+ copy_m4_m4(sldata->common_data.prev_persmat, stl->effects->prev_persmat);
+
+ if (((stl->effects->enabled_effects & EFFECT_TAA) != 0) &&
+ (stl->effects->taa_current_sample > 1) &&
+ !DRW_state_is_image_render() &&
+ !taa_use_reprojection)
+ {
+ DRW_viewport_matrix_override_set(stl->effects->overide_persmat, DRW_MAT_PERS);
+ DRW_viewport_matrix_override_set(stl->effects->overide_persinv, DRW_MAT_PERSINV);
+ DRW_viewport_matrix_override_set(stl->effects->overide_winmat, DRW_MAT_WIN);
+ DRW_viewport_matrix_override_set(stl->effects->overide_wininv, DRW_MAT_WININV);
+ }
+
+ /* Refresh Probes */
+ DRW_stats_group_start("Probes Refresh");
+ EEVEE_lightprobes_refresh(sldata, vedata);
+ /* Probes refresh can have reset the current sample. */
+ if (stl->effects->taa_current_sample == 1) {
+ DRW_viewport_matrix_override_unset_all();
+ }
+ EEVEE_lightprobes_refresh_planar(sldata, vedata);
+ DRW_stats_group_end();
+
+ /* Update common buffer after probe rendering. */
+ DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data);
+
+ /* Refresh shadows */
+ DRW_stats_group_start("Shadows");
+ EEVEE_draw_shadows(sldata, psl);
+ DRW_stats_group_end();
+
+ GPU_framebuffer_bind(fbl->main_fb);
+ GPUFrameBufferBits clear_bits = GPU_DEPTH_BIT;
+ clear_bits |= (DRW_state_draw_background()) ? 0 : GPU_COLOR_BIT;
+ clear_bits |= ((stl->effects->enabled_effects & EFFECT_SSS) != 0) ? GPU_STENCIL_BIT : 0;
+ GPU_framebuffer_clear(fbl->main_fb, clear_bits, clear_col, clear_depth, clear_stencil);
+
+ /* Depth prepass */
+ DRW_stats_group_start("Prepass");
+ DRW_draw_pass(psl->depth_pass);
+ DRW_draw_pass(psl->depth_pass_cull);
+ DRW_stats_group_end();
+
+ /* Create minmax texture */
+ DRW_stats_group_start("Main MinMax buffer");
+ EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1);
+ DRW_stats_group_end();
+
+ EEVEE_occlusion_compute(sldata, vedata, dtxl->depth, -1);
+ EEVEE_volumes_compute(sldata, vedata);
+
+ /* Shading pass */
+ DRW_stats_group_start("Shading");
+ if (DRW_state_draw_background()) {
+ DRW_draw_pass(psl->background_pass);
+ }
+ EEVEE_draw_default_passes(psl);
+ DRW_draw_pass(psl->material_pass);
+ EEVEE_subsurface_data_render(sldata, vedata);
+ DRW_stats_group_end();
+
+ /* Effects pre-transparency */
+ EEVEE_subsurface_compute(sldata, vedata);
+ EEVEE_reflection_compute(sldata, vedata);
+ EEVEE_occlusion_draw_debug(sldata, vedata);
+ DRW_draw_pass(psl->probe_display);
+ EEVEE_refraction_compute(sldata, vedata);
+
+ /* Opaque refraction */
+ DRW_stats_group_start("Opaque Refraction");
+ DRW_draw_pass(psl->refract_depth_pass);
+ DRW_draw_pass(psl->refract_depth_pass_cull);
+ DRW_draw_pass(psl->refract_pass);
+ DRW_stats_group_end();
+
+ /* Volumetrics Resolve Opaque */
+ EEVEE_volumes_resolve(sldata, vedata);
+
+ /* Transparent */
+ DRW_draw_pass(psl->transparent_pass);
+
+ /* Post Process */
+ DRW_stats_group_start("Post FX");
+ EEVEE_draw_effects(sldata, vedata);
+ DRW_stats_group_end();
+
+ if ((stl->effects->taa_current_sample > 1) && !DRW_state_is_image_render()) {
+ DRW_viewport_matrix_override_unset_all();
+ }
+ }
+
+ /* Tonemapping and transfer result to default framebuffer. */
+ GPU_framebuffer_bind(dfbl->default_fb);
+ DRW_transform_to_display(stl->effects->final_tx);
+
+ /* Debug : Ouput buffer to view. */
+ switch (G.debug_value) {
+ case 1:
+ if (txl->maxzbuffer) DRW_transform_to_display(txl->maxzbuffer);
+ break;
+ case 2:
+ if (effects->ssr_pdf_output) DRW_transform_to_display(effects->ssr_pdf_output);
+ break;
+ case 3:
+ if (effects->ssr_normal_input) DRW_transform_to_display(effects->ssr_normal_input);
+ break;
+ case 4:
+ if (effects->ssr_specrough_input) DRW_transform_to_display(effects->ssr_specrough_input);
+ break;
+ case 5:
+ if (txl->color_double_buffer) DRW_transform_to_display(txl->color_double_buffer);
+ break;
+ case 6:
+ if (effects->gtao_horizons_debug) DRW_transform_to_display(effects->gtao_horizons_debug);
+ break;
+ case 7:
+ if (effects->gtao_horizons) DRW_transform_to_display(effects->gtao_horizons);
+ break;
+ case 8:
+ if (effects->sss_data) DRW_transform_to_display(effects->sss_data);
+ break;
+ case 9:
+ if (effects->velocity_tx) DRW_transform_to_display(effects->velocity_tx);
+ break;
+ default:
+ break;
+ }
+
+ EEVEE_volumes_free_smoke_textures();
+
+ stl->g_data->view_updated = false;
+}
+
+static void eevee_view_update(void *vedata)
+{
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+ if (stl->g_data) {
+ stl->g_data->view_updated = true;
+ }
+}
+
+static void eevee_id_object_update(void *UNUSED(vedata), Object *object)
+{
+ /* This is a bit mask of components which update is to be ignored. */
+ const int ignore_updates = ID_RECALC_COLLECTIONS;
+ const int allowed_updates = ~ignore_updates;
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_get(object);
+ if (ped != NULL && (ped->engine_data.recalc & allowed_updates) != 0) {
+ ped->need_full_update = true;
+ ped->engine_data.recalc = 0;
+ }
+ EEVEE_LampEngineData *led = EEVEE_lamp_data_get(object);
+ if (led != NULL && (led->engine_data.recalc & allowed_updates) != 0) {
+ led->need_update = true;
+ led->engine_data.recalc = 0;
+ }
+ EEVEE_ObjectEngineData *oedata = EEVEE_object_data_get(object);
+ if (oedata != NULL && (oedata->engine_data.recalc & allowed_updates) != 0) {
+ oedata->need_update = true;
+ oedata->engine_data.recalc = 0;
+ }
+}
+
+static void eevee_id_update(void *vedata, ID *id)
+{
+ /* Handle updates based on ID type. */
+ switch (GS(id->name)) {
+ case ID_OB:
+ eevee_id_object_update(vedata, (Object *)id);
+ break;
+ default:
+ /* pass */
+ break;
+ }
+}
+
+static void eevee_render_to_image(void *vedata, RenderEngine *engine, struct RenderLayer *render_layer, const rcti *rect)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ EEVEE_render_init(vedata, engine, draw_ctx->depsgraph);
+
+ DRW_render_object_iter(vedata, engine, draw_ctx->depsgraph, EEVEE_render_cache);
+
+ /* Actually do the rendering. */
+ EEVEE_render_draw(vedata, engine, render_layer, rect);
+}
+
+static void eevee_engine_free(void)
+{
+ EEVEE_bloom_free();
+ EEVEE_depth_of_field_free();
+ EEVEE_effects_free();
+ EEVEE_lightprobes_free();
+ EEVEE_lights_free();
+ EEVEE_materials_free();
+ EEVEE_mist_free();
+ EEVEE_motion_blur_free();
+ EEVEE_occlusion_free();
+ EEVEE_screen_raytrace_free();
+ EEVEE_subsurface_free();
+ EEVEE_temporal_sampling_free();
+ EEVEE_volumes_free();
+}
+
+static void eevee_layer_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
+{
+ BLI_assert(props &&
+ props->type == IDP_GROUP &&
+ props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
+ // BKE_collection_engine_property_add_int(props, "high_quality_sphere_lamps", false);
+ UNUSED_VARS_NDEBUG(props);
+}
+
+static void eevee_view_layer_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
+{
+ BLI_assert(props &&
+ props->type == IDP_GROUP &&
+ props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
+
+ BKE_collection_engine_property_add_int(props, "gi_diffuse_bounces", 3);
+ BKE_collection_engine_property_add_int(props, "gi_cubemap_resolution", 512);
+ BKE_collection_engine_property_add_int(props, "gi_visibility_resolution", 32);
+
+ BKE_collection_engine_property_add_int(props, "taa_samples", 16);
+ BKE_collection_engine_property_add_int(props, "taa_render_samples", 64);
+ BKE_collection_engine_property_add_bool(props, "taa_reprojection", true);
+
+ BKE_collection_engine_property_add_bool(props, "sss_enable", false);
+ BKE_collection_engine_property_add_int(props, "sss_samples", 7);
+ BKE_collection_engine_property_add_float(props, "sss_jitter_threshold", 0.3f);
+ BKE_collection_engine_property_add_bool(props, "sss_separate_albedo", false);
+
+ BKE_collection_engine_property_add_bool(props, "ssr_enable", false);
+ BKE_collection_engine_property_add_bool(props, "ssr_refraction", false);
+ BKE_collection_engine_property_add_bool(props, "ssr_halfres", true);
+ BKE_collection_engine_property_add_float(props, "ssr_quality", 0.25f);
+ BKE_collection_engine_property_add_float(props, "ssr_max_roughness", 0.5f);
+ BKE_collection_engine_property_add_float(props, "ssr_thickness", 0.2f);
+ BKE_collection_engine_property_add_float(props, "ssr_border_fade", 0.075f);
+ BKE_collection_engine_property_add_float(props, "ssr_firefly_fac", 10.0f);
+
+ BKE_collection_engine_property_add_bool(props, "volumetric_enable", false);
+ BKE_collection_engine_property_add_float(props, "volumetric_start", 0.1f);
+ BKE_collection_engine_property_add_float(props, "volumetric_end", 100.0f);
+ BKE_collection_engine_property_add_int(props, "volumetric_tile_size", 8);
+ BKE_collection_engine_property_add_int(props, "volumetric_samples", 64);
+ BKE_collection_engine_property_add_float(props, "volumetric_sample_distribution", 0.8f);
+ BKE_collection_engine_property_add_bool(props, "volumetric_lights", true);
+ BKE_collection_engine_property_add_float(props, "volumetric_light_clamp", 0.0f);
+ BKE_collection_engine_property_add_bool(props, "volumetric_shadows", false);
+ BKE_collection_engine_property_add_int(props, "volumetric_shadow_samples", 16);
+ BKE_collection_engine_property_add_bool(props, "volumetric_colored_transmittance", true);
+
+ BKE_collection_engine_property_add_bool(props, "gtao_enable", false);
+ BKE_collection_engine_property_add_bool(props, "gtao_use_bent_normals", true);
+ BKE_collection_engine_property_add_bool(props, "gtao_bounce", true);
+ BKE_collection_engine_property_add_float(props, "gtao_distance", 0.2f);
+ BKE_collection_engine_property_add_float(props, "gtao_factor", 1.0f);
+ BKE_collection_engine_property_add_float(props, "gtao_quality", 0.25f);
+
+ BKE_collection_engine_property_add_bool(props, "dof_enable", false);
+ BKE_collection_engine_property_add_float(props, "bokeh_max_size", 100.0f);
+ BKE_collection_engine_property_add_float(props, "bokeh_threshold", 1.0f);
+
+ float default_bloom_color[3] = {1.0f, 1.0f, 1.0f};
+ BKE_collection_engine_property_add_bool(props, "bloom_enable", false);
+ BKE_collection_engine_property_add_float_array(props, "bloom_color", default_bloom_color, 3);
+ BKE_collection_engine_property_add_float(props, "bloom_threshold", 0.8f);
+ BKE_collection_engine_property_add_float(props, "bloom_knee", 0.5f);
+ BKE_collection_engine_property_add_float(props, "bloom_intensity", 0.8f);
+ BKE_collection_engine_property_add_float(props, "bloom_radius", 6.5f);
+ BKE_collection_engine_property_add_float(props, "bloom_clamp", 1.0f);
+
+ BKE_collection_engine_property_add_bool(props, "motion_blur_enable", false);
+ BKE_collection_engine_property_add_int(props, "motion_blur_samples", 8);
+ BKE_collection_engine_property_add_float(props, "motion_blur_shutter", 1.0f);
+
+ BKE_collection_engine_property_add_int(props, "shadow_method", SHADOW_ESM);
+ BKE_collection_engine_property_add_int(props, "shadow_cube_size", 512);
+ BKE_collection_engine_property_add_int(props, "shadow_cascade_size", 1024);
+ BKE_collection_engine_property_add_bool(props, "shadow_high_bitdepth", false);
+}
+
+static const DrawEngineDataSize eevee_data_size = DRW_VIEWPORT_DATA_SIZE(EEVEE_Data);
+
+DrawEngineType draw_engine_eevee_type = {
+ NULL, NULL,
+ N_("Eevee"),
+ &eevee_data_size,
+ &eevee_engine_init,
+ &eevee_engine_free,
+ &eevee_cache_init,
+ &eevee_cache_populate,
+ &eevee_cache_finish,
+ &eevee_draw_background,
+ NULL, /* Everything is drawn in the background pass (see comment on function) */
+ &eevee_view_update,
+ &eevee_id_update,
+ &eevee_render_to_image,
+};
+
+RenderEngineType DRW_engine_viewport_eevee_type = {
+ NULL, NULL,
+ EEVEE_ENGINE, N_("Eevee"), RE_INTERNAL | RE_USE_SHADING_NODES | RE_USE_PREVIEW,
+ NULL, &DRW_render_to_image, NULL, NULL, NULL, NULL,
+ &EEVEE_render_update_passes,
+ &eevee_layer_collection_settings_create,
+ &eevee_view_layer_settings_create,
+ &draw_engine_eevee_type,
+ {NULL, NULL, NULL}
+};
+
+
+#undef EEVEE_ENGINE
diff --git a/source/blender/draw/engines/eevee/eevee_engine.h b/source/blender/draw/engines/eevee/eevee_engine.h
new file mode 100644
index 00000000000..b7de3a055b9
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_engine.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_engine.h
+ * \ingroup DNA
+ */
+
+#ifndef __EEVEE_ENGINE_H__
+#define __EEVEE_ENGINE_H__
+
+extern RenderEngineType DRW_engine_viewport_eevee_type;
+
+#endif /* __EEVEE_ENGINE_H__ */
diff --git a/source/blender/draw/engines/eevee/eevee_lightprobes.c b/source/blender/draw/engines/eevee/eevee_lightprobes.c
new file mode 100644
index 00000000000..22eeab55598
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_lightprobes.c
@@ -0,0 +1,1844 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_lightprobes.c
+ * \ingroup DNA
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_string_utils.h"
+#include "BLI_rand.h"
+
+#include "DNA_world_types.h"
+#include "DNA_texture_types.h"
+#include "DNA_image_types.h"
+#include "DNA_lightprobe_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_object.h"
+#include "BKE_group.h"
+#include "MEM_guardedalloc.h"
+
+#include "GPU_material.h"
+#include "GPU_texture.h"
+#include "GPU_glew.h"
+
+#include "eevee_engine.h"
+#include "eevee_private.h"
+
+#include "ED_screen.h"
+
+/* Rounded to nearest PowerOfTwo */
+#if defined(IRRADIANCE_SH_L2)
+#define IRRADIANCE_SAMPLE_SIZE_X 4 /* 3 in reality */
+#define IRRADIANCE_SAMPLE_SIZE_Y 4 /* 3 in reality */
+#elif defined(IRRADIANCE_CUBEMAP)
+#define IRRADIANCE_SAMPLE_SIZE_X 8
+#define IRRADIANCE_SAMPLE_SIZE_Y 8
+#elif defined(IRRADIANCE_HL2)
+#define IRRADIANCE_SAMPLE_SIZE_X 4 /* 3 in reality */
+#define IRRADIANCE_SAMPLE_SIZE_Y 2
+#endif
+
+#define IRRADIANCE_MAX_POOL_LAYER 256 /* OpenGL 3.3 core requirement, can be extended but it's already very big */
+#define IRRADIANCE_MAX_POOL_SIZE 1024
+#define MAX_IRRADIANCE_SAMPLES \
+ (IRRADIANCE_MAX_POOL_SIZE / IRRADIANCE_SAMPLE_SIZE_X) * \
+ (IRRADIANCE_MAX_POOL_SIZE / IRRADIANCE_SAMPLE_SIZE_Y)
+#define HAMMERSLEY_SIZE 1024
+
+static struct {
+ struct GPUShader *probe_default_sh;
+ struct GPUShader *probe_filter_glossy_sh;
+ struct GPUShader *probe_filter_diffuse_sh;
+ struct GPUShader *probe_filter_visibility_sh;
+ struct GPUShader *probe_grid_fill_sh;
+ struct GPUShader *probe_grid_display_sh;
+ struct GPUShader *probe_planar_display_sh;
+ struct GPUShader *probe_planar_downsample_sh;
+ struct GPUShader *probe_cube_display_sh;
+
+ struct GPUTexture *hammersley;
+ struct GPUTexture *planar_pool_placeholder;
+ struct GPUTexture *depth_placeholder;
+ struct GPUTexture *depth_array_placeholder;
+ struct GPUTexture *cube_face_minmaxz;
+
+ struct Gwn_VertFormat *format_probe_display_cube;
+ struct Gwn_VertFormat *format_probe_display_planar;
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_background_vert_glsl[];
+extern char datatoc_default_world_frag_glsl[];
+extern char datatoc_lightprobe_filter_glossy_frag_glsl[];
+extern char datatoc_lightprobe_filter_diffuse_frag_glsl[];
+extern char datatoc_lightprobe_filter_visibility_frag_glsl[];
+extern char datatoc_lightprobe_geom_glsl[];
+extern char datatoc_lightprobe_vert_glsl[];
+extern char datatoc_lightprobe_planar_display_frag_glsl[];
+extern char datatoc_lightprobe_planar_display_vert_glsl[];
+extern char datatoc_lightprobe_planar_downsample_frag_glsl[];
+extern char datatoc_lightprobe_planar_downsample_geom_glsl[];
+extern char datatoc_lightprobe_planar_downsample_vert_glsl[];
+extern char datatoc_lightprobe_cube_display_frag_glsl[];
+extern char datatoc_lightprobe_cube_display_vert_glsl[];
+extern char datatoc_lightprobe_grid_display_frag_glsl[];
+extern char datatoc_lightprobe_grid_display_vert_glsl[];
+extern char datatoc_lightprobe_grid_fill_frag_glsl[];
+extern char datatoc_irradiance_lib_glsl[];
+extern char datatoc_lightprobe_lib_glsl[];
+extern char datatoc_octahedron_lib_glsl[];
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_bsdf_sampling_lib_glsl[];
+
+extern GlobalsUboStorage ts;
+
+/* *********** FUNCTIONS *********** */
+
+static void irradiance_pool_size_get(int visibility_size, int total_samples, int r_size[3])
+{
+ /* Compute how many irradiance samples we can store per visibility sample. */
+ int irr_per_vis = (visibility_size / IRRADIANCE_SAMPLE_SIZE_X) *
+ (visibility_size / IRRADIANCE_SAMPLE_SIZE_Y);
+
+ /* The irradiance itself take one layer, hence the +1 */
+ int layer_ct = MIN2(irr_per_vis + 1, IRRADIANCE_MAX_POOL_LAYER);
+
+ int texel_ct = (int)ceilf((float)total_samples / (float)(layer_ct - 1));
+ r_size[0] = visibility_size * max_ii(1, min_ii(texel_ct, (IRRADIANCE_MAX_POOL_SIZE / visibility_size)));
+ r_size[1] = visibility_size * max_ii(1, (texel_ct / (IRRADIANCE_MAX_POOL_SIZE / visibility_size)));
+ r_size[2] = layer_ct;
+}
+
+static struct GPUTexture *create_hammersley_sample_texture(int samples)
+{
+ struct GPUTexture *tex;
+ float (*texels)[2] = MEM_mallocN(sizeof(float[2]) * samples, "hammersley_tex");
+ int i;
+
+ for (i = 0; i < samples; i++) {
+ double dphi;
+ BLI_hammersley_1D(i, &dphi);
+ float phi = (float)dphi * 2.0f * M_PI;
+ texels[i][0] = cosf(phi);
+ texels[i][1] = sinf(phi);
+ }
+
+ tex = DRW_texture_create_1D(samples, GPU_RG16F, DRW_TEX_WRAP, (float *)texels);
+ MEM_freeN(texels);
+ return tex;
+}
+
+static void planar_pool_ensure_alloc(EEVEE_Data *vedata, int num_planar_ref)
+{
+ /* XXX TODO OPTIMISATION : This is a complete waist of texture memory.
+ * Instead of allocating each planar probe for each viewport,
+ * only alloc them once using the biggest viewport resolution. */
+ EEVEE_TextureList *txl = vedata->txl;
+
+ const float *viewport_size = DRW_viewport_size_get();
+
+ /* TODO get screen percentage from layer setting */
+ // const DRWContextState *draw_ctx = DRW_context_state_get();
+ // ViewLayer *view_layer = draw_ctx->view_layer;
+ float screen_percentage = 1.0f;
+
+ int width = (int)(viewport_size[0] * screen_percentage);
+ int height = (int)(viewport_size[1] * screen_percentage);
+
+ /* We need an Array texture so allocate it ourself */
+ if (!txl->planar_pool) {
+ if (num_planar_ref > 0) {
+ txl->planar_pool = DRW_texture_create_2D_array(width, height, max_ff(1, num_planar_ref),
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+ txl->planar_depth = DRW_texture_create_2D_array(width, height, max_ff(1, num_planar_ref),
+ GPU_DEPTH_COMPONENT24, 0, NULL);
+ }
+ else if (num_planar_ref == 0) {
+ /* Makes Opengl Happy : Create a placeholder texture that will never be sampled but still bound to shader. */
+ txl->planar_pool = DRW_texture_create_2D_array(1, 1, 1, GPU_RGBA8, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+ txl->planar_depth = DRW_texture_create_2D_array(1, 1, 1, GPU_DEPTH_COMPONENT24, 0, NULL);
+ }
+ }
+}
+
+static void lightprobe_shaders_init(void)
+{
+ const char *filter_defines = "#define HAMMERSLEY_SIZE " STRINGIFY(HAMMERSLEY_SIZE) "\n"
+#if defined(IRRADIANCE_SH_L2)
+ "#define IRRADIANCE_SH_L2\n"
+#elif defined(IRRADIANCE_CUBEMAP)
+ "#define IRRADIANCE_CUBEMAP\n"
+#elif defined(IRRADIANCE_HL2)
+ "#define IRRADIANCE_HL2\n"
+#endif
+ "#define NOISE_SIZE 64\n";
+
+ char *shader_str = NULL;
+ char *vert_str = NULL;
+
+ shader_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_sampling_lib_glsl,
+ datatoc_lightprobe_filter_glossy_frag_glsl);
+
+ e_data.probe_filter_glossy_sh = DRW_shader_create(
+ datatoc_lightprobe_vert_glsl, datatoc_lightprobe_geom_glsl, shader_str, filter_defines);
+
+ e_data.probe_default_sh = DRW_shader_create(
+ datatoc_background_vert_glsl, NULL, datatoc_default_world_frag_glsl, NULL);
+
+ MEM_freeN(shader_str);
+
+ shader_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_sampling_lib_glsl,
+ datatoc_lightprobe_filter_diffuse_frag_glsl);
+
+ e_data.probe_filter_diffuse_sh = DRW_shader_create_fullscreen(shader_str, filter_defines);
+
+ MEM_freeN(shader_str);
+
+ shader_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_sampling_lib_glsl,
+ datatoc_lightprobe_filter_visibility_frag_glsl);
+
+ e_data.probe_filter_visibility_sh = DRW_shader_create_fullscreen(shader_str, filter_defines);
+
+ MEM_freeN(shader_str);
+
+ shader_str = BLI_string_joinN(
+ datatoc_octahedron_lib_glsl,
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_irradiance_lib_glsl,
+ datatoc_lightprobe_lib_glsl,
+ datatoc_lightprobe_grid_display_frag_glsl);
+
+ vert_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_lightprobe_grid_display_vert_glsl);
+
+ e_data.probe_grid_display_sh = DRW_shader_create(vert_str, NULL, shader_str, filter_defines);
+
+ MEM_freeN(vert_str);
+ MEM_freeN(shader_str);
+
+ e_data.probe_grid_fill_sh = DRW_shader_create_fullscreen(
+ datatoc_lightprobe_grid_fill_frag_glsl, filter_defines);
+
+ shader_str = BLI_string_joinN(
+ datatoc_octahedron_lib_glsl,
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_lightprobe_lib_glsl,
+ datatoc_lightprobe_cube_display_frag_glsl);
+
+ vert_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_lightprobe_cube_display_vert_glsl);
+
+ e_data.probe_cube_display_sh = DRW_shader_create(vert_str, NULL, shader_str, NULL);
+
+ MEM_freeN(vert_str);
+ MEM_freeN(shader_str);
+
+ vert_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_lightprobe_planar_display_vert_glsl);
+
+ shader_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_lightprobe_planar_display_frag_glsl);
+
+ e_data.probe_planar_display_sh = DRW_shader_create(vert_str, NULL, shader_str, NULL);
+
+ MEM_freeN(vert_str);
+ MEM_freeN(shader_str);
+
+ e_data.probe_planar_downsample_sh = DRW_shader_create(
+ datatoc_lightprobe_planar_downsample_vert_glsl,
+ datatoc_lightprobe_planar_downsample_geom_glsl,
+ datatoc_lightprobe_planar_downsample_frag_glsl,
+ NULL);
+
+ e_data.hammersley = create_hammersley_sample_texture(HAMMERSLEY_SIZE);
+}
+
+void EEVEE_lightprobes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *UNUSED(vedata))
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ bool update_all = false;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ /* Shaders */
+ if (!e_data.probe_filter_glossy_sh) {
+ lightprobe_shaders_init();
+ }
+
+ if (!sldata->probes) {
+ sldata->probes = MEM_callocN(sizeof(EEVEE_LightProbesInfo), "EEVEE_LightProbesInfo");
+ sldata->probes->grid_initialized = false;
+ sldata->probe_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_LightProbe) * MAX_PROBE, NULL);
+ sldata->grid_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_LightGrid) * MAX_GRID, NULL);
+ sldata->planar_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_PlanarReflection) * MAX_PLANAR, NULL);
+ }
+
+ /* Only start doing probes if all materials have finished compiling. */
+ sldata->probes->all_materials_updated = true;
+
+ common_data->spec_toggle = true;
+ common_data->ssr_toggle = true;
+ common_data->sss_toggle = true;
+
+ int prop_bounce_num = BKE_collection_engine_property_value_get_int(props, "gi_diffuse_bounces");
+ if (sldata->probes->num_bounce != prop_bounce_num) {
+ sldata->probes->num_bounce = prop_bounce_num;
+ update_all = true;
+ }
+
+ int prop_cubemap_res = BKE_collection_engine_property_value_get_int(props, "gi_cubemap_resolution");
+ if (sldata->probes->cubemap_res != prop_cubemap_res) {
+ sldata->probes->cubemap_res = prop_cubemap_res;
+ update_all = true;
+
+ sldata->probes->target_size = prop_cubemap_res >> 1;
+
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_depth_rt);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_rt);
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_pool);
+ }
+
+ int visibility_res = BKE_collection_engine_property_value_get_int(props, "gi_visibility_resolution");
+ if (common_data->prb_irradiance_vis_size != visibility_res) {
+ common_data->prb_irradiance_vis_size = visibility_res;
+ update_all = true;
+ }
+
+ if (update_all) {
+ sldata->probes->update_world |= PROBE_UPDATE_ALL;
+ sldata->probes->updated_bounce = 0;
+ sldata->probes->grid_initialized = false;
+ }
+
+ /* Setup Render Target Cubemap */
+ if (!sldata->probe_rt) {
+ sldata->probe_depth_rt = DRW_texture_create_cube(sldata->probes->target_size, GPU_DEPTH_COMPONENT24, 0, NULL);
+ sldata->probe_rt = DRW_texture_create_cube(sldata->probes->target_size, GPU_RGBA16F, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+ }
+
+ for (int i = 0; i < 6; ++i) {
+ GPU_framebuffer_ensure_config(&sldata->probe_face_fb[i], {
+ GPU_ATTACHMENT_TEXTURE_CUBEFACE(sldata->probe_depth_rt, i),
+ GPU_ATTACHMENT_TEXTURE_CUBEFACE(sldata->probe_rt, i)
+ });
+ }
+
+ /* Placeholder planar pool: used when rendering planar reflections (avoid dependency loop). */
+ if (!e_data.planar_pool_placeholder) {
+ e_data.planar_pool_placeholder = DRW_texture_create_2D_array(1, 1, 1, GPU_RGBA8, DRW_TEX_FILTER, NULL);
+ }
+
+ if (!e_data.depth_placeholder) {
+ e_data.depth_placeholder = DRW_texture_create_2D(1, 1, GPU_DEPTH_COMPONENT24, 0, NULL);
+ }
+ if (!e_data.depth_array_placeholder) {
+ e_data.depth_array_placeholder = DRW_texture_create_2D_array(1, 1, 1, GPU_DEPTH_COMPONENT24, 0, NULL);
+ }
+}
+
+void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+
+ /* Make sure no aditionnal visibility check runs by default. */
+ pinfo->vis_data.group = NULL;
+
+ pinfo->do_cube_update = false;
+ pinfo->num_cube = 1; /* at least one for the world */
+ pinfo->num_grid = 1;
+ pinfo->num_planar = 0;
+ pinfo->total_irradiance_samples = 1;
+ memset(pinfo->probes_cube_ref, 0, sizeof(pinfo->probes_cube_ref));
+ memset(pinfo->probes_grid_ref, 0, sizeof(pinfo->probes_grid_ref));
+ memset(pinfo->probes_planar_ref, 0, sizeof(pinfo->probes_planar_ref));
+
+ {
+ psl->probe_background = DRW_pass_create("World Probe Background Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
+
+ struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+ DRWShadingGroup *grp = NULL;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ World *wo = scene->world;
+
+ float *col = ts.colorBackground;
+ if (wo) {
+ col = &wo->horr;
+ bool wo_sh_compiled = true;
+
+ if (wo->use_nodes && wo->nodetree) {
+ static float error_col[3] = {1.0f, 0.0f, 1.0f};
+ static float compile_col[3] = {0.5f, 0.5f, 0.5f};
+ struct GPUMaterial *gpumat = EEVEE_material_world_lightprobe_get(scene, wo);
+
+ GPUMaterialStatus status = GPU_material_status(gpumat);
+
+ switch (status) {
+ case GPU_MAT_SUCCESS:
+ grp = DRW_shgroup_material_create(gpumat, psl->probe_background);
+ DRW_shgroup_uniform_float(grp, "backgroundAlpha", &stl->g_data->background_alpha, 1);
+ DRW_shgroup_call_add(grp, geom, NULL);
+ wo_sh_compiled = true;
+ break;
+ case GPU_MAT_QUEUED:
+ pinfo->all_materials_updated = false;
+ wo_sh_compiled = false;
+ /* TODO Bypass probe compilation. */
+ col = compile_col;
+ break;
+ case GPU_MAT_FAILED:
+ default:
+ wo_sh_compiled = true;
+ col = error_col;
+ break;
+ }
+ }
+
+ if (wo->update_flag != 0 || pinfo->prev_world != wo || pinfo->prev_wo_sh_compiled != wo_sh_compiled) {
+ pinfo->update_world |= PROBE_UPDATE_ALL;
+ pinfo->prev_wo_sh_compiled = wo_sh_compiled;
+ pinfo->prev_world = wo;
+ }
+ wo->update_flag = 0;
+ }
+ else if (pinfo->prev_world) {
+ pinfo->update_world |= PROBE_UPDATE_ALL;
+ pinfo->prev_wo_sh_compiled = false;
+ pinfo->prev_world = NULL;
+ }
+
+ /* Fallback if shader fails or if not using nodetree. */
+ if (grp == NULL) {
+ grp = DRW_shgroup_create(e_data.probe_default_sh, psl->probe_background);
+ DRW_shgroup_uniform_vec3(grp, "color", col, 1);
+ DRW_shgroup_uniform_float(grp, "backgroundAlpha", &stl->g_data->background_alpha, 1);
+ DRW_shgroup_call_add(grp, geom, NULL);
+ }
+ }
+
+ {
+ psl->probe_glossy_compute = DRW_pass_create("LightProbe Glossy Compute", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_filter_glossy_sh, psl->probe_glossy_compute);
+ DRW_shgroup_uniform_float(grp, "intensityFac", &pinfo->intensity_fac, 1);
+ DRW_shgroup_uniform_float(grp, "sampleCount", &pinfo->samples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "invSampleCount", &pinfo->invsamples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "roughnessSquared", &pinfo->roughness, 1);
+ DRW_shgroup_uniform_float(grp, "lodFactor", &pinfo->lodfactor, 1);
+ DRW_shgroup_uniform_float(grp, "lodMax", &pinfo->lod_rt_max, 1);
+ DRW_shgroup_uniform_float(grp, "texelSize", &pinfo->texel_size, 1);
+ DRW_shgroup_uniform_float(grp, "paddingSize", &pinfo->padding_size, 1);
+ DRW_shgroup_uniform_int(grp, "Layer", &pinfo->layer, 1);
+ DRW_shgroup_uniform_texture(grp, "texHammersley", e_data.hammersley);
+ // DRW_shgroup_uniform_texture(grp, "texJitter", e_data.jitter);
+ DRW_shgroup_uniform_texture(grp, "probeHdr", sldata->probe_rt);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+ {
+ psl->probe_diffuse_compute = DRW_pass_create("LightProbe Diffuse Compute", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_filter_diffuse_sh, psl->probe_diffuse_compute);
+#ifdef IRRADIANCE_SH_L2
+ DRW_shgroup_uniform_int(grp, "probeSize", &pinfo->shres, 1);
+#else
+ DRW_shgroup_uniform_float(grp, "sampleCount", &pinfo->samples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "invSampleCount", &pinfo->invsamples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "lodFactor", &pinfo->lodfactor, 1);
+ DRW_shgroup_uniform_float(grp, "lodMax", &pinfo->lod_rt_max, 1);
+ DRW_shgroup_uniform_texture(grp, "texHammersley", e_data.hammersley);
+#endif
+ DRW_shgroup_uniform_float(grp, "intensityFac", &pinfo->intensity_fac, 1);
+ DRW_shgroup_uniform_texture(grp, "probeHdr", sldata->probe_rt);
+
+ struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+ DRW_shgroup_call_add(grp, geom, NULL);
+ }
+
+ {
+ psl->probe_visibility_compute = DRW_pass_create("LightProbe Visibility Compute", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_filter_visibility_sh, psl->probe_visibility_compute);
+ DRW_shgroup_uniform_int(grp, "outputSize", &pinfo->shres, 1);
+ DRW_shgroup_uniform_float(grp, "visibilityRange", &pinfo->visibility_range, 1);
+ DRW_shgroup_uniform_float(grp, "visibilityBlur", &pinfo->visibility_blur, 1);
+ DRW_shgroup_uniform_float(grp, "sampleCount", &pinfo->samples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "invSampleCount", &pinfo->invsamples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "storedTexelSize", &pinfo->texel_size, 1);
+ DRW_shgroup_uniform_float(grp, "nearClip", &pinfo->near_clip, 1);
+ DRW_shgroup_uniform_float(grp, "farClip", &pinfo->far_clip, 1);
+ DRW_shgroup_uniform_texture(grp, "texHammersley", e_data.hammersley);
+ DRW_shgroup_uniform_texture(grp, "probeDepth", sldata->probe_depth_rt);
+
+ struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+ DRW_shgroup_call_add(grp, geom, NULL);
+ }
+
+ {
+ psl->probe_grid_fill = DRW_pass_create("LightProbe Grid Floodfill", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_grid_fill_sh, psl->probe_grid_fill);
+ DRW_shgroup_uniform_texture_ref(grp, "irradianceGrid", &sldata->irradiance_pool);
+
+ struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+ DRW_shgroup_call_add(grp, geom, NULL);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
+ psl->probe_display = DRW_pass_create("LightProbe Display", state);
+
+ DRW_shgroup_instance_format(e_data.format_probe_display_cube, {
+ {"probe_id", DRW_ATTRIB_INT, 1},
+ {"probe_location", DRW_ATTRIB_FLOAT, 3},
+ {"sphere_size", DRW_ATTRIB_FLOAT, 1},
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(
+ e_data.probe_cube_display_sh,
+ psl->probe_display,
+ DRW_cache_sphere_get(),
+ e_data.format_probe_display_cube);
+ stl->g_data->cube_display_shgrp = grp;
+ DRW_shgroup_uniform_texture_ref(grp, "probeCubes", &sldata->probe_pool);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+
+ DRW_shgroup_instance_format(e_data.format_probe_display_planar, {
+ {"probe_id", DRW_ATTRIB_INT, 1},
+ {"probe_mat", DRW_ATTRIB_FLOAT, 16},
+ });
+
+ grp = DRW_shgroup_instance_create(
+ e_data.probe_planar_display_sh,
+ psl->probe_display,
+ DRW_cache_quad_get(),
+ e_data.format_probe_display_planar);
+ stl->g_data->planar_display_shgrp = grp;
+ DRW_shgroup_uniform_texture_ref(grp, "probePlanars", &txl->planar_pool);
+ }
+
+ {
+ psl->probe_planar_downsample_ps = DRW_pass_create("LightProbe Planar Downsample", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_planar_downsample_sh, psl->probe_planar_downsample_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "source", &txl->planar_pool);
+ DRW_shgroup_uniform_float(grp, "fireflyFactor", &sldata->common_data.ssr_firefly_fac, 1);
+ DRW_shgroup_call_instances_add(grp, DRW_cache_fullscreen_quad_get(), NULL, (unsigned int *)&pinfo->num_planar);
+ }
+}
+
+bool EEVEE_lightprobes_obj_visibility_cb(bool vis_in, void *user_data)
+{
+ EEVEE_ObjectEngineData *oed = (EEVEE_ObjectEngineData *)user_data;
+
+ /* test disabled if group is NULL */
+ if (oed->test_data->group == NULL)
+ return vis_in;
+
+ if (oed->test_data->cached == false)
+ oed->ob_vis_dirty = true;
+
+ /* early out, don't need to compute ob_vis yet. */
+ if (vis_in == false)
+ return vis_in;
+
+ if (oed->ob_vis_dirty) {
+ oed->ob_vis_dirty = false;
+ oed->ob_vis = BKE_group_object_exists(oed->test_data->group, oed->ob);
+ oed->ob_vis = (oed->test_data->invert) ? !oed->ob_vis : oed->ob_vis;
+ }
+
+ return vis_in && oed->ob_vis;
+}
+
+void EEVEE_lightprobes_cache_add(EEVEE_ViewLayerData *sldata, Object *ob)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ LightProbe *probe = (LightProbe *)ob->data;
+
+ if ((probe->type == LIGHTPROBE_TYPE_CUBE && pinfo->num_cube >= MAX_PROBE) ||
+ (probe->type == LIGHTPROBE_TYPE_GRID && pinfo->num_grid >= MAX_PROBE) ||
+ (probe->type == LIGHTPROBE_TYPE_PLANAR && pinfo->num_grid >= MAX_PLANAR))
+ {
+ printf("Too much probes in the scene !!!\n");
+ return;
+ }
+
+ if (probe->type == LIGHTPROBE_TYPE_PLANAR) {
+ /* See if this planar probe is inside the view frustum. If not, no need to update it. */
+ /* NOTE: this could be bypassed if we want feedback loop mirrors for rendering. */
+ BoundBox bbox; float tmp[4][4];
+ const float min[3] = {-1.0f, -1.0f, -1.0f};
+ const float max[3] = { 1.0f, 1.0f, 1.0f};
+ BKE_boundbox_init_from_minmax(&bbox, min, max);
+
+ copy_m4_m4(tmp, ob->obmat);
+ normalize_v3(tmp[2]);
+ mul_v3_fl(tmp[2], probe->distinf);
+
+ for (int v = 0; v < 8; ++v) {
+ mul_m4_v3(tmp, bbox.vec[v]);
+ }
+ if (!DRW_culling_box_test(&bbox)) {
+ return; /* Culled */
+ }
+ }
+
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+
+ ped->num_cell = probe->grid_resolution_x * probe->grid_resolution_y * probe->grid_resolution_z;
+
+ if ((probe->type == LIGHTPROBE_TYPE_GRID) &&
+ ((pinfo->total_irradiance_samples + ped->num_cell) >= MAX_IRRADIANCE_SAMPLES))
+ {
+ printf("Too much grid samples !!!\n");
+ return;
+ }
+
+ if (ped->need_full_update) {
+ ped->need_full_update = false;
+
+ ped->need_update = true;
+ ped->probe_id = 0;
+ if (probe->type == LIGHTPROBE_TYPE_GRID) {
+ ped->updated_cells = 0;
+ ped->updated_lvl = 0;
+ pinfo->updated_bounce = 0;
+ pinfo->grid_initialized = false;
+ }
+ }
+
+ if (pinfo->update_world) {
+ ped->need_update = true;
+ ped->updated_cells = 0;
+ ped->updated_lvl = 0;
+ ped->probe_id = 0;
+ }
+
+ pinfo->do_cube_update |= ped->need_update;
+
+ switch (probe->type) {
+ case LIGHTPROBE_TYPE_CUBE:
+ pinfo->probes_cube_ref[pinfo->num_cube] = ob;
+ pinfo->num_cube++;
+ break;
+ case LIGHTPROBE_TYPE_PLANAR:
+ pinfo->probes_planar_ref[pinfo->num_planar] = ob;
+ pinfo->num_planar++;
+ break;
+ case LIGHTPROBE_TYPE_GRID:
+ pinfo->probes_grid_ref[pinfo->num_grid] = ob;
+ pinfo->num_grid++;
+ pinfo->total_irradiance_samples += ped->num_cell;
+ break;
+ }
+}
+
+/* TODO find a nice name to push it to math_matrix.c */
+static void scale_m4_v3(float R[4][4], float v[3])
+{
+ for (int i = 0; i < 4; ++i)
+ mul_v3_v3(R[i], v);
+}
+
+static void EEVEE_planar_reflections_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ Object *ob;
+
+ for (int i = 0; (ob = pinfo->probes_planar_ref[i]) && (i < MAX_PLANAR); i++) {
+ LightProbe *probe = (LightProbe *)ob->data;
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+
+ ped->probe_id = i;
+
+ /* Debug Display */
+ if (DRW_state_draw_support() &&
+ (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
+ {
+ DRW_shgroup_call_dynamic_add(stl->g_data->planar_display_shgrp, &ped->probe_id, ob->obmat);
+ }
+ }
+}
+
+static void EEVEE_planar_reflections_updates(EEVEE_ViewLayerData *sldata)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ Object *ob;
+ float mtx[4][4], normat[4][4], imat[4][4], rangemat[4][4];
+
+ float viewmat[4][4];
+ DRW_viewport_matrix_get(viewmat, DRW_MAT_VIEW);
+
+ zero_m4(rangemat);
+ rangemat[0][0] = rangemat[1][1] = rangemat[2][2] = 0.5f;
+ rangemat[3][0] = rangemat[3][1] = rangemat[3][2] = 0.5f;
+ rangemat[3][3] = 1.0f;
+
+ /* PLANAR REFLECTION */
+ for (int i = 0; (ob = pinfo->probes_planar_ref[i]) && (i < MAX_PLANAR); i++) {
+ LightProbe *probe = (LightProbe *)ob->data;
+ EEVEE_PlanarReflection *eplanar = &pinfo->planar_data[i];
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+ /* Computing mtx : matrix that mirror position around object's XY plane. */
+ normalize_m4_m4(normat, ob->obmat); /* object > world */
+ invert_m4_m4(imat, normat); /* world > object */
+ float reflect[3] = {1.0f, 1.0f, -1.0f}; /* XY reflection plane */
+ scale_m4_v3(imat, reflect); /* world > object > mirrored obj */
+ mul_m4_m4m4(mtx, normat, imat); /* world > object > mirrored obj > world */
+ /* Reflect Camera Matrix. */
+ mul_m4_m4m4(ped->mats.mat[DRW_MAT_VIEW], viewmat, mtx);
+ /* TODO FOV margin */
+ /* Temporal sampling jitter should be already applied to the DRW_MAT_WIN. */
+ DRW_viewport_matrix_get(ped->mats.mat[DRW_MAT_WIN], DRW_MAT_WIN);
+ /* Apply Projection Matrix. */
+ mul_m4_m4m4(ped->mats.mat[DRW_MAT_PERS], ped->mats.mat[DRW_MAT_WIN], ped->mats.mat[DRW_MAT_VIEW]);
+ /* This is the matrix used to reconstruct texture coordinates.
+ * We use the original view matrix because it does not create
+ * visual artifacts if receiver is not perfectly aligned with
+ * the planar reflection probe. */
+ mul_m4_m4m4(eplanar->reflectionmat, ped->mats.mat[DRW_MAT_WIN], viewmat); /* TODO FOV margin */
+ /* Convert from [-1, 1] to [0, 1] (NDC to Texture coord). */
+ mul_m4_m4m4(eplanar->reflectionmat, rangemat, eplanar->reflectionmat);
+
+ /* Compute clip plane equation / normal. */
+ float refpoint[3];
+ copy_v3_v3(eplanar->plane_equation, ob->obmat[2]);
+ normalize_v3(eplanar->plane_equation); /* plane normal */
+ eplanar->plane_equation[3] = -dot_v3v3(eplanar->plane_equation, ob->obmat[3]);
+
+ /* Compute offset plane equation (fix missing texels near reflection plane). */
+ copy_v3_v3(ped->planer_eq_offset, eplanar->plane_equation);
+ mul_v3_v3fl(refpoint, eplanar->plane_equation, -probe->clipsta);
+ add_v3_v3(refpoint, ob->obmat[3]);
+ ped->planer_eq_offset[3] = -dot_v3v3(eplanar->plane_equation, refpoint);
+
+ /* Compute XY clip planes. */
+ normalize_v3_v3(eplanar->clip_vec_x, ob->obmat[0]);
+ normalize_v3_v3(eplanar->clip_vec_y, ob->obmat[1]);
+
+ float vec[3] = {0.0f, 0.0f, 0.0f};
+ vec[0] = 1.0f; vec[1] = 0.0f; vec[2] = 0.0f;
+ mul_m4_v3(ob->obmat, vec); /* Point on the edge */
+ eplanar->clip_edge_x_pos = dot_v3v3(eplanar->clip_vec_x, vec);
+
+ vec[0] = 0.0f; vec[1] = 1.0f; vec[2] = 0.0f;
+ mul_m4_v3(ob->obmat, vec); /* Point on the edge */
+ eplanar->clip_edge_y_pos = dot_v3v3(eplanar->clip_vec_y, vec);
+
+ vec[0] = -1.0f; vec[1] = 0.0f; vec[2] = 0.0f;
+ mul_m4_v3(ob->obmat, vec); /* Point on the edge */
+ eplanar->clip_edge_x_neg = dot_v3v3(eplanar->clip_vec_x, vec);
+
+ vec[0] = 0.0f; vec[1] = -1.0f; vec[2] = 0.0f;
+ mul_m4_v3(ob->obmat, vec); /* Point on the edge */
+ eplanar->clip_edge_y_neg = dot_v3v3(eplanar->clip_vec_y, vec);
+
+ /* Facing factors */
+ float max_angle = max_ff(1e-2f, probe->falloff) * M_PI * 0.5f;
+ float min_angle = 0.0f;
+ eplanar->facing_scale = 1.0f / max_ff(1e-8f, cosf(min_angle) - cosf(max_angle));
+ eplanar->facing_bias = -min_ff(1.0f - 1e-8f, cosf(max_angle)) * eplanar->facing_scale;
+
+ /* Distance factors */
+ float max_dist = probe->distinf;
+ float min_dist = min_ff(1.0f - 1e-8f, 1.0f - probe->falloff) * probe->distinf;
+ eplanar->attenuation_scale = -1.0f / max_ff(1e-8f, max_dist - min_dist);
+ eplanar->attenuation_bias = max_dist * -eplanar->attenuation_scale;
+ }
+}
+
+static void EEVEE_lightprobes_updates(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl, EEVEE_StorageList *stl)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ Object *ob;
+
+ /* CUBE REFLECTION */
+ for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) {
+ LightProbe *probe = (LightProbe *)ob->data;
+ EEVEE_LightProbe *eprobe = &pinfo->probe_data[i];
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+
+ /* Update transforms */
+ copy_v3_v3(eprobe->position, ob->obmat[3]);
+
+ /* Attenuation */
+ eprobe->attenuation_type = probe->attenuation_type;
+ eprobe->attenuation_fac = 1.0f / max_ff(1e-8f, probe->falloff);
+
+ unit_m4(eprobe->attenuationmat);
+ scale_m4_fl(eprobe->attenuationmat, probe->distinf);
+ mul_m4_m4m4(eprobe->attenuationmat, ob->obmat, eprobe->attenuationmat);
+ invert_m4(eprobe->attenuationmat);
+
+ /* Parallax */
+ float dist;
+ if ((probe->flag & LIGHTPROBE_FLAG_CUSTOM_PARALLAX) != 0) {
+ eprobe->parallax_type = probe->parallax_type;
+ dist = probe->distpar;
+ }
+ else {
+ eprobe->parallax_type = probe->attenuation_type;
+ dist = probe->distinf;
+ }
+
+ unit_m4(eprobe->parallaxmat);
+ scale_m4_fl(eprobe->parallaxmat, dist);
+ mul_m4_m4m4(eprobe->parallaxmat, ob->obmat, eprobe->parallaxmat);
+ invert_m4(eprobe->parallaxmat);
+
+ /* Debug Display */
+ if (DRW_state_draw_support() &&
+ (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
+ {
+ ped->probe_size = probe->data_draw_size * 0.1f;
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->cube_display_shgrp, &ped->probe_id, ob->obmat[3], &ped->probe_size);
+ }
+ }
+
+ /* IRRADIANCE GRID */
+ int offset = 1; /* to account for the world probe */
+ for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) {
+ LightProbe *probe = (LightProbe *)ob->data;
+ EEVEE_LightGrid *egrid = &pinfo->grid_data[i];
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+
+ /* If one grid has move we need to recompute all the lighting. */
+ if (!pinfo->grid_initialized) {
+ ped->updated_cells = 0;
+ ped->updated_lvl = 0;
+ ped->need_update = true;
+ }
+
+ /* Add one for level 0 */
+ ped->max_lvl = 1.0f + floorf(log2f((float)MAX3(probe->grid_resolution_x,
+ probe->grid_resolution_y,
+ probe->grid_resolution_z)));
+
+ egrid->offset = offset;
+ float fac = 1.0f / max_ff(1e-8f, probe->falloff);
+ egrid->attenuation_scale = fac / max_ff(1e-8f, probe->distinf);
+ egrid->attenuation_bias = fac;
+
+ /* Set offset for the next grid */
+ offset += ped->num_cell;
+
+ /* Update transforms */
+ float cell_dim[3], half_cell_dim[3];
+ cell_dim[0] = 2.0f / (float)(probe->grid_resolution_x);
+ cell_dim[1] = 2.0f / (float)(probe->grid_resolution_y);
+ cell_dim[2] = 2.0f / (float)(probe->grid_resolution_z);
+
+ mul_v3_v3fl(half_cell_dim, cell_dim, 0.5f);
+
+ /* Matrix converting world space to cell ranges. */
+ invert_m4_m4(egrid->mat, ob->obmat);
+
+ /* First cell. */
+ copy_v3_fl(egrid->corner, -1.0f);
+ add_v3_v3(egrid->corner, half_cell_dim);
+ mul_m4_v3(ob->obmat, egrid->corner);
+
+ /* Opposite neighbor cell. */
+ copy_v3_fl3(egrid->increment_x, cell_dim[0], 0.0f, 0.0f);
+ add_v3_v3(egrid->increment_x, half_cell_dim);
+ add_v3_fl(egrid->increment_x, -1.0f);
+ mul_m4_v3(ob->obmat, egrid->increment_x);
+ sub_v3_v3(egrid->increment_x, egrid->corner);
+
+ copy_v3_fl3(egrid->increment_y, 0.0f, cell_dim[1], 0.0f);
+ add_v3_v3(egrid->increment_y, half_cell_dim);
+ add_v3_fl(egrid->increment_y, -1.0f);
+ mul_m4_v3(ob->obmat, egrid->increment_y);
+ sub_v3_v3(egrid->increment_y, egrid->corner);
+
+ copy_v3_fl3(egrid->increment_z, 0.0f, 0.0f, cell_dim[2]);
+ add_v3_v3(egrid->increment_z, half_cell_dim);
+ add_v3_fl(egrid->increment_z, -1.0f);
+ mul_m4_v3(ob->obmat, egrid->increment_z);
+ sub_v3_v3(egrid->increment_z, egrid->corner);
+
+ copy_v3_v3_int(egrid->resolution, &probe->grid_resolution_x);
+
+ /* Visibility bias */
+ egrid->visibility_bias = 0.05f * probe->vis_bias;
+ egrid->visibility_bleed = probe->vis_bleedbias;
+ egrid->visibility_range = (
+ sqrtf(max_fff(len_squared_v3(egrid->increment_x),
+ len_squared_v3(egrid->increment_y),
+ len_squared_v3(egrid->increment_z))) + 1.0f);
+
+ /* Debug Display */
+ if (DRW_state_draw_support() &&
+ (probe->flag & LIGHTPROBE_FLAG_SHOW_DATA))
+ {
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.probe_grid_display_sh, psl->probe_display);
+ DRW_shgroup_uniform_int(grp, "offset", &egrid->offset, 1);
+ DRW_shgroup_uniform_ivec3(grp, "grid_resolution", egrid->resolution, 1);
+ DRW_shgroup_uniform_vec3(grp, "corner", egrid->corner, 1);
+ DRW_shgroup_uniform_vec3(grp, "increment_x", egrid->increment_x, 1);
+ DRW_shgroup_uniform_vec3(grp, "increment_y", egrid->increment_y, 1);
+ DRW_shgroup_uniform_vec3(grp, "increment_z", egrid->increment_z, 1);
+ DRW_shgroup_uniform_texture_ref(grp, "irradianceGrid", &sldata->irradiance_pool);
+ DRW_shgroup_uniform_float(grp, "sphere_size", &probe->data_draw_size, 1);
+ DRW_shgroup_call_instances_add(grp, DRW_cache_sphere_get(), NULL, (unsigned int *)&ped->num_cell);
+ }
+ }
+}
+
+void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ Object *ob;
+
+ /* Setup enough layers. */
+ /* Free textures if number mismatch. */
+ if (pinfo->num_cube != pinfo->cache_num_cube) {
+ DRW_TEXTURE_FREE_SAFE(sldata->probe_pool);
+ pinfo->cache_num_cube = pinfo->num_cube;
+ }
+
+ if (pinfo->num_planar != pinfo->cache_num_planar) {
+ DRW_TEXTURE_FREE_SAFE(vedata->txl->planar_pool);
+ DRW_TEXTURE_FREE_SAFE(vedata->txl->planar_depth);
+ pinfo->cache_num_planar = pinfo->num_planar;
+ }
+
+ int irr_size[3];
+ irradiance_pool_size_get(common_data->prb_irradiance_vis_size, pinfo->total_irradiance_samples, irr_size);
+
+ if ((irr_size[0] != pinfo->cache_irradiance_size[0]) ||
+ (irr_size[1] != pinfo->cache_irradiance_size[1]) ||
+ (irr_size[2] != pinfo->cache_irradiance_size[2]))
+ {
+ DRW_TEXTURE_FREE_SAFE(sldata->irradiance_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->irradiance_rt);
+ copy_v3_v3_int(pinfo->cache_irradiance_size, irr_size);
+ }
+
+ /* XXX this should be run each frame as it ensure planar_depth is set */
+ planar_pool_ensure_alloc(vedata, pinfo->num_planar);
+
+ if (!sldata->probe_pool) {
+ sldata->probe_pool = DRW_texture_create_2D_array(pinfo->cubemap_res, pinfo->cubemap_res, max_ff(1, pinfo->num_cube),
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER | DRW_TEX_MIPMAP, NULL);
+ if (sldata->probe_filter_fb) {
+ GPU_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->probe_pool, 0, 0);
+ }
+ /* Tag probes to refresh */
+ pinfo->update_world |= PROBE_UPDATE_CUBE;
+ }
+
+ if ((pinfo->update_world & PROBE_UPDATE_CUBE) != 0) {
+ common_data->prb_num_render_cube = 0;
+ for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) {
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+ ped->need_update = true;
+ ped->ready_to_shade = false;
+ ped->probe_id = 0;
+ }
+ }
+
+#ifdef IRRADIANCE_SH_L2
+ /* we need a signed format for Spherical Harmonics */
+ int irradiance_format = GPU_RGBA16F;
+#else
+ int irradiance_format = GPU_RGBA8;
+#endif
+
+ if (!sldata->irradiance_pool || !sldata->irradiance_rt) {
+ if (!sldata->irradiance_pool) {
+ sldata->irradiance_pool = DRW_texture_create_2D_array(irr_size[0], irr_size[1], irr_size[2],
+ irradiance_format, DRW_TEX_FILTER, NULL);
+ }
+ if (!sldata->irradiance_rt) {
+ sldata->irradiance_rt = DRW_texture_create_2D_array(irr_size[0], irr_size[1], irr_size[2],
+ irradiance_format, DRW_TEX_FILTER, NULL);
+ }
+ /* Tag probes to refresh */
+ pinfo->update_world |= PROBE_UPDATE_GRID;
+ pinfo->grid_initialized = false;
+ }
+
+ if ((pinfo->update_world & PROBE_UPDATE_GRID) != 0) {
+ common_data->prb_num_render_grid = 0;
+ pinfo->updated_bounce = 0;
+ for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_PROBE); i++) {
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+ ped->need_update = true;
+ ped->updated_cells = 0;
+ }
+ }
+
+ if (common_data->prb_num_render_grid > pinfo->num_grid) {
+ /* This can happen when deleting a probe. */
+ common_data->prb_num_render_grid = pinfo->num_grid;
+ }
+
+ EEVEE_planar_reflections_cache_finish(sldata, vedata->stl);
+
+ EEVEE_lightprobes_updates(sldata, vedata->psl, vedata->stl);
+
+ DRW_uniformbuffer_update(sldata->probe_ubo, &sldata->probes->probe_data);
+ DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data);
+}
+
+static void downsample_planar(void *vedata, int level)
+{
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+
+ const float *size = DRW_viewport_size_get();
+ copy_v2_v2(stl->g_data->planar_texel_size, size);
+ for (int i = 0; i < level - 1; ++i) {
+ stl->g_data->planar_texel_size[0] /= 2.0f;
+ stl->g_data->planar_texel_size[1] /= 2.0f;
+ min_ff(floorf(stl->g_data->planar_texel_size[0]), 1.0f);
+ min_ff(floorf(stl->g_data->planar_texel_size[1]), 1.0f);
+ }
+ invert_v2(stl->g_data->planar_texel_size);
+
+ DRW_draw_pass(psl->probe_planar_downsample_ps);
+}
+
+/* Glossy filter probe_rt to probe_pool at index probe_idx */
+static void glossy_filter_probe(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, EEVEE_PassList *psl, int probe_idx, float intensity)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+
+ pinfo->intensity_fac = intensity;
+
+ /* Max lod used from the render target probe */
+ pinfo->lod_rt_max = floorf(log2f(pinfo->target_size)) - 2.0f;
+
+ /* Start fresh */
+ GPU_framebuffer_ensure_config(&sldata->probe_filter_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_NONE
+ });
+
+ /* 2 - Let gpu create Mipmaps for Filtered Importance Sampling. */
+ /* Bind next framebuffer to be able to gen. mips for probe_rt. */
+ EEVEE_downsample_cube_buffer(vedata, sldata->probe_rt, (int)(pinfo->lod_rt_max));
+
+ /* 3 - Render to probe array to the specified layer, do prefiltering. */
+ float mipsize = pinfo->cubemap_res;
+ const int maxlevel = (int)floorf(log2f(pinfo->cubemap_res));
+ const int min_lod_level = 3;
+ for (int i = 0; i < maxlevel - min_lod_level; i++) {
+ float bias = (i == 0) ? -1.0f : 1.0f;
+ pinfo->texel_size = 1.0f / mipsize;
+ pinfo->padding_size = powf(2.0f, (float)(maxlevel - min_lod_level - 1 - i));
+ /* XXX : WHY THE HECK DO WE NEED THIS ??? */
+ /* padding is incorrect without this! float precision issue? */
+ if (pinfo->padding_size > 32) {
+ pinfo->padding_size += 5;
+ }
+ if (pinfo->padding_size > 16) {
+ pinfo->padding_size += 4;
+ }
+ else if (pinfo->padding_size > 8) {
+ pinfo->padding_size += 2;
+ }
+ else if (pinfo->padding_size > 4) {
+ pinfo->padding_size += 1;
+ }
+ pinfo->layer = probe_idx;
+ pinfo->roughness = (float)i / ((float)maxlevel - 4.0f);
+ pinfo->roughness *= pinfo->roughness; /* Disney Roughness */
+ pinfo->roughness *= pinfo->roughness; /* Distribute Roughness accros lod more evenly */
+ CLAMP(pinfo->roughness, 1e-8f, 0.99999f); /* Avoid artifacts */
+
+#if 1 /* Variable Sample count (fast) */
+ switch (i) {
+ case 0: pinfo->samples_ct = 1.0f; break;
+ case 1: pinfo->samples_ct = 16.0f; break;
+ case 2: pinfo->samples_ct = 32.0f; break;
+ case 3: pinfo->samples_ct = 64.0f; break;
+ default: pinfo->samples_ct = 128.0f; break;
+ }
+#else /* Constant Sample count (slow) */
+ pinfo->samples_ct = 1024.0f;
+#endif
+
+ pinfo->invsamples_ct = 1.0f / pinfo->samples_ct;
+ pinfo->lodfactor = bias + 0.5f * log((float)(pinfo->target_size * pinfo->target_size) * pinfo->invsamples_ct) / log(2);
+
+ GPU_framebuffer_ensure_config(&sldata->probe_filter_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE_MIP(sldata->probe_pool, i)
+ });
+ GPU_framebuffer_bind(sldata->probe_filter_fb);
+ GPU_framebuffer_viewport_set(sldata->probe_filter_fb, 0, 0, mipsize, mipsize);
+ DRW_draw_pass(psl->probe_glossy_compute);
+
+ mipsize /= 2;
+ CLAMP_MIN(mipsize, 1);
+ }
+ /* For shading, save max level of the octahedron map */
+ sldata->common_data.prb_lod_cube_max = (float)(maxlevel - min_lod_level) - 1.0f;
+}
+
+/* Diffuse filter probe_rt to irradiance_pool at index probe_idx */
+static void diffuse_filter_probe(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, EEVEE_PassList *psl, int offset,
+ float clipsta, float clipend, float vis_range, float vis_blur, float intensity)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+
+ pinfo->intensity_fac = intensity;
+
+ int pool_size[3];
+ irradiance_pool_size_get(common_data->prb_irradiance_vis_size, pinfo->total_irradiance_samples, pool_size);
+
+ /* find cell position on the virtual 3D texture */
+ /* NOTE : Keep in sync with load_irradiance_cell() */
+#if defined(IRRADIANCE_SH_L2)
+ int size[2] = {3, 3};
+#elif defined(IRRADIANCE_CUBEMAP)
+ int size[2] = {8, 8};
+ pinfo->samples_ct = 1024.0f;
+#elif defined(IRRADIANCE_HL2)
+ int size[2] = {3, 2};
+ pinfo->samples_ct = 1024.0f;
+#endif
+
+ int cell_per_row = pool_size[0] / size[0];
+ int x = size[0] * (offset % cell_per_row);
+ int y = size[1] * (offset / cell_per_row);
+
+#ifndef IRRADIANCE_SH_L2
+ /* Tweaking parameters to balance perf. vs precision */
+ const float bias = 0.0f;
+ pinfo->invsamples_ct = 1.0f / pinfo->samples_ct;
+ pinfo->lodfactor = bias + 0.5f * log((float)(pinfo->target_size * pinfo->target_size) * pinfo->invsamples_ct) / log(2);
+ pinfo->lod_rt_max = floorf(log2f(pinfo->target_size)) - 2.0f;
+#else
+ pinfo->shres = 32; /* Less texture fetches & reduce branches */
+ pinfo->lod_rt_max = 2.0f; /* Improve cache reuse */
+#endif
+
+ /* Start fresh */
+ GPU_framebuffer_ensure_config(&sldata->probe_filter_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_NONE
+ });
+
+ /* 4 - Compute spherical harmonics */
+ EEVEE_downsample_cube_buffer(vedata, sldata->probe_rt, (int)(pinfo->lod_rt_max));
+
+ GPU_framebuffer_ensure_config(&sldata->probe_filter_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE_LAYER(sldata->irradiance_rt, 0)
+ });
+ GPU_framebuffer_bind(sldata->probe_filter_fb);
+ GPU_framebuffer_viewport_set(sldata->probe_filter_fb, x, y, size[0], size[1]);
+ DRW_draw_pass(psl->probe_diffuse_compute);
+
+ /* World irradiance have no visibility */
+ if (offset > 0) {
+ /* Compute visibility */
+ pinfo->samples_ct = 512.0f; /* TODO refine */
+ pinfo->invsamples_ct = 1.0f / pinfo->samples_ct;
+ pinfo->shres = common_data->prb_irradiance_vis_size;
+ pinfo->visibility_range = vis_range;
+ pinfo->visibility_blur = vis_blur;
+ pinfo->near_clip = -clipsta;
+ pinfo->far_clip = -clipend;
+ pinfo->texel_size = 1.0f / (float)common_data->prb_irradiance_vis_size;
+
+ int cell_per_col = pool_size[1] / common_data->prb_irradiance_vis_size;
+ cell_per_row = pool_size[0] / common_data->prb_irradiance_vis_size;
+ x = common_data->prb_irradiance_vis_size * (offset % cell_per_row);
+ y = common_data->prb_irradiance_vis_size * ((offset / cell_per_row) % cell_per_col);
+ int layer = 1 + ((offset / cell_per_row) / cell_per_col);
+ const int vis_size = common_data->prb_irradiance_vis_size;
+
+ GPU_framebuffer_ensure_config(&sldata->probe_filter_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE_LAYER(sldata->irradiance_rt, layer)
+ });
+ GPU_framebuffer_bind(sldata->probe_filter_fb);
+ GPU_framebuffer_viewport_set(sldata->probe_filter_fb, x, y, vis_size, vis_size);
+ DRW_draw_pass(psl->probe_visibility_compute);
+ }
+}
+
+/* Render the scene to the probe_rt texture. */
+static void render_scene_to_probe(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata,
+ const float pos[3], float clipsta, float clipend)
+{
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+
+ DRWMatrixState matstate;
+ float (*viewmat)[4] = matstate.mat[DRW_MAT_VIEW];
+ float (*viewinv)[4] = matstate.mat[DRW_MAT_VIEWINV];
+ float (*persmat)[4] = matstate.mat[DRW_MAT_PERS];
+ float (*persinv)[4] = matstate.mat[DRW_MAT_PERSINV];
+ float (*winmat)[4] = matstate.mat[DRW_MAT_WIN];
+ float (*wininv)[4] = matstate.mat[DRW_MAT_WININV];
+
+ float posmat[4][4];
+ unit_m4(posmat);
+
+ /* Move to capture position */
+ negate_v3_v3(posmat[3], pos);
+
+ /* 1 - Render to each cubeface individually.
+ * We do this instead of using geometry shader because a) it's faster,
+ * b) it's easier than fixing the nodetree shaders (for view dependant effects). */
+ pinfo->layer = 0;
+ perspective_m4(winmat, -clipsta, clipsta, -clipsta, clipsta, clipsta, clipend);
+
+ /* Avoid using the texture attached to framebuffer when rendering. */
+ /* XXX */
+ GPUTexture *tmp_planar_pool = txl->planar_pool;
+ GPUTexture *tmp_maxz = txl->maxzbuffer;
+ txl->planar_pool = e_data.planar_pool_placeholder;
+ txl->maxzbuffer = e_data.depth_placeholder;
+
+ DRW_stats_group_start("Cubemap Render");
+
+ /* Update common uniforms */
+ DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data);
+
+ for (int i = 0; i < 6; ++i) {
+ /* Recompute only on 1st drawloop. */
+ pinfo->vis_data.cached = (i != 0);
+
+ DRW_stats_group_start("Cubemap Face");
+
+ /* Setup custom matrices */
+ mul_m4_m4m4(viewmat, cubefacemat[i], posmat);
+ mul_m4_m4m4(persmat, winmat, viewmat);
+ invert_m4_m4(persinv, persmat);
+ invert_m4_m4(viewinv, viewmat);
+ invert_m4_m4(wininv, winmat);
+
+ DRW_viewport_matrix_override_set_all(&matstate);
+
+ /* Be sure that cascaded shadow maps are updated. */
+ EEVEE_draw_shadows(sldata, psl);
+
+ GPU_framebuffer_bind(sldata->probe_face_fb[i]);
+ GPU_framebuffer_clear_depth(sldata->probe_face_fb[i], 1.0);
+
+ /* Depth prepass */
+ DRW_draw_pass(psl->depth_pass);
+ DRW_draw_pass(psl->depth_pass_cull);
+
+ DRW_draw_pass(psl->probe_background);
+
+ // EEVEE_create_minmax_buffer(vedata, sldata->probe_depth_rt);
+
+ /* Rebind Target FB */
+ GPU_framebuffer_bind(sldata->probe_face_fb[i]);
+
+ /* Shading pass */
+ EEVEE_draw_default_passes(psl);
+ DRW_draw_pass(psl->material_pass);
+ DRW_draw_pass(psl->sss_pass); /* Only output standard pass */
+
+ DRW_stats_group_end();
+ }
+
+ DRW_stats_group_end();
+
+ /* Make sure no aditionnal visibility check runs after this. */
+ pinfo->vis_data.group = NULL;
+
+ /* Restore */
+ txl->planar_pool = tmp_planar_pool;
+ txl->maxzbuffer = tmp_maxz;
+}
+
+static void render_scene_to_planar(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, int layer,
+ EEVEE_LightProbeEngineData *ped)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_PassList *psl = vedata->psl;
+
+ float (*viewmat)[4] = ped->mats.mat[DRW_MAT_VIEW];
+ float (*viewinv)[4] = ped->mats.mat[DRW_MAT_VIEWINV];
+ float (*persmat)[4] = ped->mats.mat[DRW_MAT_PERS];
+ float (*persinv)[4] = ped->mats.mat[DRW_MAT_PERSINV];
+ float (*winmat)[4] = ped->mats.mat[DRW_MAT_WIN];
+ float (*wininv)[4] = ped->mats.mat[DRW_MAT_WININV];
+
+ invert_m4_m4(viewinv, viewmat);
+ invert_m4_m4(persinv, persmat);
+ invert_m4_m4(wininv, winmat);
+
+ DRW_stats_group_start("Planar Reflection");
+
+ DRW_viewport_matrix_override_set_all(&ped->mats);
+
+ /* Don't reuse previous visibility. */
+ pinfo->vis_data.cached = false;
+
+ /* Be sure that cascaded shadow maps are updated. */
+ EEVEE_draw_shadows(sldata, psl);
+
+ /* Since we are rendering with an inverted view matrix, we need
+ * to invert the facing for backface culling to be the same. */
+ DRW_state_invert_facing();
+ /* Set clipping plan */
+ copy_v4_v4(sldata->clip_data.clip_planes[0], ped->planer_eq_offset);
+ DRW_uniformbuffer_update(sldata->clip_ubo, &sldata->clip_data);
+ DRW_state_clip_planes_count_set(1);
+
+ GPU_framebuffer_ensure_config(&fbl->planarref_fb, {
+ GPU_ATTACHMENT_TEXTURE_LAYER(txl->planar_depth, layer),
+ GPU_ATTACHMENT_TEXTURE_LAYER(txl->planar_pool, layer)
+ });
+
+ GPU_framebuffer_bind(fbl->planarref_fb);
+ GPU_framebuffer_clear_depth(fbl->planarref_fb, 1.0);
+
+ /* Avoid using the texture attached to framebuffer when rendering. */
+ /* XXX */
+ GPUTexture *tmp_planar_pool = txl->planar_pool;
+ GPUTexture *tmp_planar_depth = txl->planar_depth;
+ txl->planar_pool = e_data.planar_pool_placeholder;
+ txl->planar_depth = e_data.depth_array_placeholder;
+
+ /* Slight modification: we handle refraction as normal
+ * shading and don't do SSRefraction. */
+
+ /* Depth prepass */
+ DRW_draw_pass(psl->depth_pass_clip);
+ DRW_draw_pass(psl->depth_pass_clip_cull);
+ DRW_draw_pass(psl->refract_depth_pass);
+ DRW_draw_pass(psl->refract_depth_pass_cull);
+
+ /* Background */
+ DRW_draw_pass(psl->probe_background);
+
+ EEVEE_create_minmax_buffer(vedata, tmp_planar_depth, layer);
+
+ /* Compute GTAO Horizons */
+ EEVEE_occlusion_compute(sldata, vedata, tmp_planar_depth, layer);
+
+ /* Rebind Planar FB */
+ GPU_framebuffer_bind(fbl->planarref_fb);
+
+ /* Shading pass */
+ EEVEE_draw_default_passes(psl);
+ DRW_draw_pass(psl->material_pass);
+ DRW_draw_pass(psl->sss_pass); /* Only output standard pass */
+ DRW_draw_pass(psl->refract_pass);
+
+ /* Transparent */
+ if (DRW_state_is_image_render()) {
+ /* Do the reordering only for offline because it can be costly. */
+ DRW_pass_sort_shgroup_z(psl->transparent_pass);
+ }
+ DRW_draw_pass(psl->transparent_pass);
+
+ DRW_state_invert_facing();
+ DRW_state_clip_planes_reset();
+
+ DRW_stats_group_end();
+
+ /* Make sure no aditionnal visibility check runs after this. */
+ pinfo->vis_data.group = NULL;
+
+ /* Restore */
+ txl->planar_pool = tmp_planar_pool;
+ txl->planar_depth = tmp_planar_depth;
+}
+
+static void render_world_to_probe(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ DRWMatrixState matstate;
+ float (*viewmat)[4] = matstate.mat[DRW_MAT_VIEW];
+ float (*viewinv)[4] = matstate.mat[DRW_MAT_VIEWINV];
+ float (*persmat)[4] = matstate.mat[DRW_MAT_PERS];
+ float (*persinv)[4] = matstate.mat[DRW_MAT_PERSINV];
+ float (*winmat)[4] = matstate.mat[DRW_MAT_WIN];
+ float (*wininv)[4] = matstate.mat[DRW_MAT_WININV];
+
+ /* For world probe, we don't need to clear since we render the background directly. */
+ pinfo->layer = 0;
+
+ perspective_m4(winmat, -0.1f, 0.1f, -0.1f, 0.1f, 0.1f, 1.0f);
+ invert_m4_m4(wininv, winmat);
+
+ for (int i = 0; i < 6; ++i) {
+ /* Setup custom matrices */
+ copy_m4_m4(viewmat, cubefacemat[i]);
+ mul_m4_m4m4(persmat, winmat, viewmat);
+ invert_m4_m4(persinv, persmat);
+ invert_m4_m4(viewinv, viewmat);
+ DRW_viewport_matrix_override_set_all(&matstate);
+
+ GPU_framebuffer_bind(sldata->probe_face_fb[i]);
+ GPU_framebuffer_clear_depth(sldata->probe_face_fb[i], 1.0f);
+ DRW_draw_pass(psl->probe_background);
+ }
+}
+
+static void lightprobe_cell_grid_location_get(EEVEE_LightGrid *egrid, int cell_idx, float r_local_cell[3])
+{
+ /* Keep in sync with lightprobe_grid_display_vert */
+ r_local_cell[2] = (float)(cell_idx % egrid->resolution[2]);
+ r_local_cell[1] = (float)((cell_idx / egrid->resolution[2]) % egrid->resolution[1]);
+ r_local_cell[0] = (float)(cell_idx / (egrid->resolution[2] * egrid->resolution[1]));
+}
+
+static void lightprobe_cell_world_location_get(EEVEE_LightGrid *egrid, float local_cell[3], float r_pos[3])
+{
+ float tmp[3];
+
+ copy_v3_v3(r_pos, egrid->corner);
+ mul_v3_v3fl(tmp, egrid->increment_x, local_cell[0]);
+ add_v3_v3(r_pos, tmp);
+ mul_v3_v3fl(tmp, egrid->increment_y, local_cell[1]);
+ add_v3_v3(r_pos, tmp);
+ mul_v3_v3fl(tmp, egrid->increment_z, local_cell[2]);
+ add_v3_v3(r_pos, tmp);
+}
+
+static void lightprobes_refresh_world(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ DRWMatrixState saved_mats;
+
+ /* We need to save the Matrices before overidding them */
+ DRW_viewport_matrix_get_all(&saved_mats);
+
+ render_world_to_probe(sldata, psl);
+ if (pinfo->update_world & PROBE_UPDATE_CUBE) {
+ glossy_filter_probe(sldata, vedata, psl, 0, 1.0);
+ common_data->prb_num_render_cube = 1;
+ }
+ if (pinfo->update_world & PROBE_UPDATE_GRID) {
+ diffuse_filter_probe(sldata, vedata, psl, 0, 0.0, 0.0, 0.0, 0.0, 1.0);
+
+ SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+
+ GPU_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->irradiance_rt, 0, 0);
+ GPU_framebuffer_bind(sldata->probe_filter_fb);
+ DRW_draw_pass(psl->probe_grid_fill);
+
+ common_data->prb_num_render_grid = 1;
+ /* Reset volume history. */
+ stl->effects->volume_current_sample = -1;
+ common_data->vol_history_alpha = 0.0f;
+ }
+ pinfo->update_world = 0;
+ DRW_viewport_request_redraw();
+ /* Do not let this frame accumulate. */
+ stl->effects->taa_current_sample = 1;
+
+ DRW_viewport_matrix_override_set_all(&saved_mats);
+}
+
+static void lightprobes_refresh_initialize_grid(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ EEVEE_PassList *psl = vedata->psl;
+ if (pinfo->grid_initialized) {
+ /* Grid is already initialized, nothing to do. */
+ return;
+ }
+ /* Flood fill with world irradiance. */
+ GPU_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->irradiance_rt, 0, 0);
+ GPU_framebuffer_bind(sldata->probe_filter_fb);
+ DRW_draw_pass(psl->probe_grid_fill);
+
+ SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+
+ GPU_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->irradiance_rt, 0, 0);
+ GPU_framebuffer_bind(sldata->probe_filter_fb);
+ DRW_draw_pass(psl->probe_grid_fill);
+
+ SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+
+ pinfo->grid_initialized = true;
+}
+
+void EEVEE_lightprobes_refresh_planar(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ Object *ob;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ DRWMatrixState saved_mats;
+
+ if (pinfo->num_planar == 0) {
+ /* Disable SSR if we cannot read previous frame */
+ common_data->ssr_toggle = vedata->stl->g_data->valid_double_buffer;
+ common_data->prb_num_planar = 0;
+ return;
+ }
+
+ EEVEE_planar_reflections_updates(sldata);
+ DRW_uniformbuffer_update(sldata->planar_ubo, &sldata->probes->planar_data);
+
+ /* We need to save the Matrices before overidding them */
+ DRW_viewport_matrix_get_all(&saved_mats);
+
+ /* Temporary Remove all planar reflections (avoid lag effect). */
+ common_data->prb_num_planar = 0;
+ /* Turn off ssr to avoid black specular */
+ common_data->ssr_toggle = false;
+ common_data->sss_toggle = false;
+
+ DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data);
+
+ for (int i = 0; (ob = pinfo->probes_planar_ref[i]) && (i < MAX_PLANAR); i++) {
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+ LightProbe *prb = (LightProbe *)ob->data;
+ pinfo->vis_data.group = prb->visibility_grp;
+ pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP;
+ render_scene_to_planar(sldata, vedata, i, ped);
+ }
+
+ /* Restore */
+ common_data->prb_num_planar = pinfo->num_planar;
+ common_data->ssr_toggle = true;
+ common_data->sss_toggle = true;
+
+ /* Prefilter for SSR */
+ if ((vedata->stl->effects->enabled_effects & EFFECT_SSR) != 0) {
+ const int max_lod = 9;
+ DRW_stats_group_start("Planar Probe Downsample");
+
+ GPU_framebuffer_ensure_config(&fbl->planar_downsample_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->planar_pool)
+ });
+ GPU_framebuffer_recursive_downsample(fbl->planar_downsample_fb, max_lod, &downsample_planar, vedata);
+ /* For shading, save max level of the planar map */
+ common_data->prb_lod_planar_max = (float)(max_lod);
+ DRW_stats_group_end();
+ }
+
+ DRW_viewport_matrix_override_set_all(&saved_mats);
+
+ if (DRW_state_is_image_render()) {
+ /* Sort transparents because planar reflections could have re-sorted them. */
+ DRW_pass_sort_shgroup_z(vedata->psl->transparent_pass);
+ }
+
+ /* Disable SSR if we cannot read previous frame */
+ common_data->ssr_toggle = vedata->stl->g_data->valid_double_buffer;
+}
+
+static void lightprobes_refresh_cube(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ Object *ob;
+ for (int i = 1; (ob = pinfo->probes_cube_ref[i]) && (i < MAX_PROBE); i++) {
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+ if (!ped->need_update) {
+ continue;
+ }
+ LightProbe *prb = (LightProbe *)ob->data;
+ pinfo->vis_data.group = prb->visibility_grp;
+ pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP;
+ render_scene_to_probe(sldata, vedata, ob->obmat[3], prb->clipsta, prb->clipend);
+ glossy_filter_probe(sldata, vedata, psl, i, prb->intensity);
+ ped->need_update = false;
+ ped->probe_id = i;
+ if (!ped->ready_to_shade) {
+ common_data->prb_num_render_cube++;
+ ped->ready_to_shade = true;
+ }
+#if 0
+ printf("Update Cubemap %d\n", i);
+#endif
+ DRW_viewport_request_redraw();
+ /* Do not let this frame accumulate. */
+ stl->effects->taa_current_sample = 1;
+ /* Only do one probe per frame */
+ return;
+ }
+
+ pinfo->do_cube_update = false;
+}
+
+static void lightprobes_refresh_all_no_world(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ Object *ob;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ RegionView3D *rv3d = draw_ctx->rv3d;
+
+ if (draw_ctx->evil_C != NULL) {
+ /* Only compute probes if not navigating or in playback */
+ struct wmWindowManager *wm = CTX_wm_manager(draw_ctx->evil_C);
+ if (((rv3d->rflag & RV3D_NAVIGATING) != 0) || ED_screen_animation_no_scrub(wm) != NULL) {
+ return;
+ }
+ }
+ /* We need to save the Matrices before overidding them */
+ DRWMatrixState saved_mats;
+ DRW_viewport_matrix_get_all(&saved_mats);
+ /* Make sure grid is initialized. */
+ lightprobes_refresh_initialize_grid(sldata, vedata);
+ /* Reflection probes depend on diffuse lighting thus on irradiance grid,
+ * so update them first. */
+ while (pinfo->updated_bounce < pinfo->num_bounce) {
+ common_data->prb_num_render_grid = pinfo->num_grid;
+ /* TODO(sergey): This logic can be split into smaller functions. */
+ for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) {
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+ if (!ped->need_update) {
+ continue;
+ }
+ EEVEE_LightGrid *egrid = &pinfo->grid_data[i];
+ LightProbe *prb = (LightProbe *)ob->data;
+ /* Find the next cell corresponding to the current level. */
+ bool valid_cell = false;
+ int cell_id = ped->updated_cells;
+ float pos[3], grid_loc[3];
+ /* Other levels */
+ int current_stride = 1 << max_ii(0, ped->max_lvl - ped->updated_lvl);
+ int prev_stride = current_stride << 1;
+ bool do_rendering = true;
+ while (!valid_cell) {
+ cell_id = ped->updated_cells;
+ lightprobe_cell_grid_location_get(egrid, cell_id, grid_loc);
+ if (ped->updated_lvl == 0 && cell_id == 0) {
+ valid_cell = true;
+ ped->updated_cells = ped->num_cell;
+ continue;
+ }
+ else if (((((int)grid_loc[0] % current_stride) == 0) &&
+ (((int)grid_loc[1] % current_stride) == 0) &&
+ (((int)grid_loc[2] % current_stride) == 0)) &&
+ !((((int)grid_loc[0] % prev_stride) == 0) &&
+ (((int)grid_loc[1] % prev_stride) == 0) &&
+ (((int)grid_loc[2] % prev_stride) == 0)))
+ {
+ valid_cell = true;
+ }
+ ped->updated_cells++;
+ if (ped->updated_cells > ped->num_cell) {
+ do_rendering = false;
+ break;
+ }
+ }
+ if (do_rendering) {
+ lightprobe_cell_world_location_get(egrid, grid_loc, pos);
+ SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+ /* Temporary Remove all probes. */
+ int tmp_num_render_grid = common_data->prb_num_render_grid;
+ int tmp_num_render_cube = common_data->prb_num_render_cube;
+ int tmp_num_planar = common_data->prb_num_planar;
+ float tmp_level_bias = egrid->level_bias;
+ common_data->prb_num_render_cube = 0;
+ common_data->prb_num_planar = 0;
+ /* Use light from previous bounce when capturing radiance. */
+ if (pinfo->updated_bounce == 0) {
+ /* But not on first bounce. */
+ common_data->prb_num_render_grid = 0;
+ }
+ else {
+ /* Remove bias */
+ egrid->level_bias = (float)(1 << 0);
+ DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data);
+ }
+ pinfo->vis_data.group = prb->visibility_grp;
+ pinfo->vis_data.invert = prb->flag & LIGHTPROBE_FLAG_INVERT_GROUP;
+ render_scene_to_probe(sldata, vedata, pos, prb->clipsta, prb->clipend);
+ diffuse_filter_probe(sldata, vedata, psl, egrid->offset + cell_id,
+ prb->clipsta, prb->clipend, egrid->visibility_range, prb->vis_blur,
+ prb->intensity);
+ /* To see what is going on. */
+ SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+ /* Restore */
+ common_data->prb_num_render_cube = tmp_num_render_cube;
+ pinfo->num_planar = tmp_num_planar;
+ if (pinfo->updated_bounce == 0) {
+ common_data->prb_num_render_grid = tmp_num_render_grid;
+ }
+ else {
+ egrid->level_bias = tmp_level_bias;
+ DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data);
+ }
+#if 0
+ printf("Updated Grid %d : cell %d / %d, bounce %d / %d\n",
+ i, cell_id + 1, ped->num_cell, pinfo->updated_bounce + 1, pinfo->num_bounce);
+#endif
+ }
+ if (ped->updated_cells >= ped->num_cell) {
+ ped->updated_lvl++;
+ ped->updated_cells = 0;
+ if (ped->updated_lvl > ped->max_lvl) {
+ ped->need_update = false;
+ }
+ egrid->level_bias = (float)(1 << max_ii(0, ped->max_lvl - ped->updated_lvl + 1));
+ DRW_uniformbuffer_update(sldata->grid_ubo, &sldata->probes->grid_data);
+ }
+ /* Only do one probe per frame */
+ DRW_viewport_request_redraw();
+ /* Do not let this frame accumulate. */
+ stl->effects->taa_current_sample = 1;
+ /* Reset volume history. */
+ stl->effects->volume_current_sample = -1;
+ common_data->vol_history_alpha = 0.0f;
+ /* Restore matrices */
+ DRW_viewport_matrix_override_set_all(&saved_mats);
+ return;
+ }
+
+ pinfo->updated_bounce++;
+ common_data->prb_num_render_grid = pinfo->num_grid;
+
+ if (pinfo->updated_bounce < pinfo->num_bounce) {
+ /* Retag all grids to update for next bounce */
+ for (int i = 1; (ob = pinfo->probes_grid_ref[i]) && (i < MAX_GRID); i++) {
+ EEVEE_LightProbeEngineData *ped = EEVEE_lightprobe_data_ensure(ob);
+ ped->need_update = true;
+ ped->updated_cells = 0;
+ ped->updated_lvl = 0;
+ }
+ /* Reset the next buffer so we can see the progress. */
+ /* irradiance_rt is already the next rt because of the previous SWAP */
+ GPU_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->irradiance_rt, 0, 0);
+ GPU_framebuffer_bind(sldata->probe_filter_fb);
+ DRW_draw_pass(psl->probe_grid_fill);
+
+ GPU_framebuffer_texture_attach(sldata->probe_filter_fb, sldata->probe_pool, 0, 0);
+ /* Swap AFTER */
+ SWAP(GPUTexture *, sldata->irradiance_pool, sldata->irradiance_rt);
+ }
+ }
+ /* Refresh cube probe when needed. */
+ lightprobes_refresh_cube(sldata, vedata);
+ /* Restore matrices */
+ DRW_viewport_matrix_override_set_all(&saved_mats);
+}
+
+bool EEVEE_lightprobes_all_probes_ready(EEVEE_ViewLayerData *sldata, EEVEE_Data *UNUSED(vedata))
+{
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+
+ return ((pinfo->do_cube_update == false) &&
+ (pinfo->updated_bounce == pinfo->num_bounce) &&
+ (common_data->prb_num_render_cube == pinfo->num_cube));
+}
+
+void EEVEE_lightprobes_refresh(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_LightProbesInfo *pinfo = sldata->probes;
+
+ /* Disable specular lighting when rendering probes to avoid feedback loops (looks bad). */
+ common_data->spec_toggle = false;
+ common_data->ssr_toggle = false;
+ common_data->sss_toggle = false;
+
+ /* Disable AO until we find a way to hide really bad discontinuities between cubefaces. */
+ float tmp_ao_dist = common_data->ao_dist;
+ float tmp_ao_settings = common_data->ao_settings;
+ common_data->ao_settings = 0.0f;
+ common_data->ao_dist = 0.0f;
+
+ /* Render world in priority */
+ if (pinfo->update_world) {
+ lightprobes_refresh_world(sldata, vedata);
+ }
+ else if (EEVEE_lightprobes_all_probes_ready(sldata, vedata) == false && pinfo->all_materials_updated) {
+ lightprobes_refresh_all_no_world(sldata, vedata);
+ }
+
+ /* Restore */
+ common_data->spec_toggle = true;
+ common_data->ssr_toggle = true;
+ common_data->sss_toggle = true;
+ common_data->ao_dist = tmp_ao_dist;
+ common_data->ao_settings = tmp_ao_settings;
+}
+
+void EEVEE_lightprobes_free(void)
+{
+ MEM_SAFE_FREE(e_data.format_probe_display_cube);
+ MEM_SAFE_FREE(e_data.format_probe_display_planar);
+ DRW_SHADER_FREE_SAFE(e_data.probe_default_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_filter_glossy_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_filter_diffuse_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_filter_visibility_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_grid_fill_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_grid_display_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_planar_display_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_planar_downsample_sh);
+ DRW_SHADER_FREE_SAFE(e_data.probe_cube_display_sh);
+ DRW_TEXTURE_FREE_SAFE(e_data.hammersley);
+ DRW_TEXTURE_FREE_SAFE(e_data.planar_pool_placeholder);
+ DRW_TEXTURE_FREE_SAFE(e_data.depth_placeholder);
+ DRW_TEXTURE_FREE_SAFE(e_data.depth_array_placeholder);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_lights.c b/source/blender/draw/engines/eevee/eevee_lights.c
new file mode 100644
index 00000000000..15d813e56c6
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_lights.c
@@ -0,0 +1,1241 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_lights.c
+ * \ingroup DNA
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_dynstr.h"
+#include "BLI_rect.h"
+
+#include "BKE_object.h"
+
+#include "eevee_engine.h"
+#include "eevee_private.h"
+
+#define SHADOW_CASTER_ALLOC_CHUNK 16
+
+static struct {
+ struct GPUShader *shadow_sh;
+ struct GPUShader *shadow_store_cube_sh[SHADOW_METHOD_MAX];
+ struct GPUShader *shadow_store_cascade_sh[SHADOW_METHOD_MAX];
+ struct GPUShader *shadow_copy_cube_sh[SHADOW_METHOD_MAX];
+ struct GPUShader *shadow_copy_cascade_sh[SHADOW_METHOD_MAX];
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_shadow_vert_glsl[];
+extern char datatoc_shadow_frag_glsl[];
+extern char datatoc_shadow_store_frag_glsl[];
+extern char datatoc_shadow_copy_frag_glsl[];
+extern char datatoc_concentric_samples_lib_glsl[];
+
+/* Prototype */
+static void eevee_light_setup(Object *ob, EEVEE_Light *evli);
+
+/* *********** LIGHT BITS *********** */
+static void lightbits_set_single(EEVEE_LightBits *bitf, unsigned int idx, bool val)
+{
+ if (val) {
+ bitf->fields[idx / 8] |= (1 << (idx % 8));
+ }
+ else {
+ bitf->fields[idx / 8] &= ~(1 << (idx % 8));
+ }
+}
+
+static void lightbits_set_all(EEVEE_LightBits *bitf, bool val)
+{
+ memset(bitf, (val) ? 0xFF : 0x00, sizeof(EEVEE_LightBits));
+}
+
+static void lightbits_or(EEVEE_LightBits *r, const EEVEE_LightBits *v)
+{
+ for (int i = 0; i < MAX_LIGHTBITS_FIELDS; ++i) {
+ r->fields[i] |= v->fields[i];
+ }
+}
+
+static bool lightbits_get(const EEVEE_LightBits *r, unsigned int idx)
+{
+ return r->fields[idx / 8] & (1 << (idx % 8));
+}
+
+static void lightbits_convert(EEVEE_LightBits *r, const EEVEE_LightBits *bitf, const int *light_bit_conv_table, unsigned int table_length)
+{
+ for (int i = 0; i < table_length; ++i) {
+ if (lightbits_get(bitf, i) != 0) {
+ if (light_bit_conv_table[i] >= 0) {
+ r->fields[i / 8] |= (1 << (i % 8));
+ }
+ }
+ }
+}
+
+/* *********** FUNCTIONS *********** */
+
+void EEVEE_lights_init(EEVEE_ViewLayerData *sldata)
+{
+ const unsigned int shadow_ubo_size = sizeof(EEVEE_Shadow) * MAX_SHADOW +
+ sizeof(EEVEE_ShadowCube) * MAX_SHADOW_CUBE +
+ sizeof(EEVEE_ShadowCascade) * MAX_SHADOW_CASCADE;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ if (!e_data.shadow_sh) {
+ e_data.shadow_sh = DRW_shader_create(
+ datatoc_shadow_vert_glsl, NULL, datatoc_shadow_frag_glsl, NULL);
+ }
+
+ if (!sldata->lamps) {
+ sldata->lamps = MEM_callocN(sizeof(EEVEE_LampsInfo), "EEVEE_LampsInfo");
+ sldata->light_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_Light) * MAX_LIGHT, NULL);
+ sldata->shadow_ubo = DRW_uniformbuffer_create(shadow_ubo_size, NULL);
+ sldata->shadow_render_ubo = DRW_uniformbuffer_create(sizeof(EEVEE_ShadowRender), NULL);
+
+ for (int i = 0; i < 2; ++i) {
+ sldata->shcasters_buffers[i].shadow_casters = MEM_callocN(sizeof(EEVEE_ShadowCaster) * SHADOW_CASTER_ALLOC_CHUNK, "EEVEE_ShadowCaster buf");
+ sldata->shcasters_buffers[i].flags = MEM_callocN(sizeof(sldata->shcasters_buffers[0].flags) * SHADOW_CASTER_ALLOC_CHUNK, "EEVEE_shcast_buffer flags buf");
+ sldata->shcasters_buffers[i].alloc_count = SHADOW_CASTER_ALLOC_CHUNK;
+ sldata->shcasters_buffers[i].count = 0;
+ }
+
+ sldata->lamps->shcaster_frontbuffer = &sldata->shcasters_buffers[0];
+ sldata->lamps->shcaster_backbuffer = &sldata->shcasters_buffers[1];
+ }
+
+ /* Flip buffers */
+ SWAP(EEVEE_ShadowCasterBuffer *, sldata->lamps->shcaster_frontbuffer, sldata->lamps->shcaster_backbuffer);
+
+ int sh_method = BKE_collection_engine_property_value_get_int(props, "shadow_method");
+ int sh_cube_size = BKE_collection_engine_property_value_get_int(props, "shadow_cube_size");
+ int sh_cascade_size = BKE_collection_engine_property_value_get_int(props, "shadow_cascade_size");
+ int sh_high_bitdepth = BKE_collection_engine_property_value_get_int(props, "shadow_high_bitdepth");
+
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+ if ((linfo->shadow_cube_size != sh_cube_size) ||
+ (linfo->shadow_method != sh_method) ||
+ (linfo->shadow_high_bitdepth != sh_high_bitdepth))
+ {
+ BLI_assert((sh_cube_size > 0) && (sh_cube_size <= 4096));
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_target);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_blur);
+
+ /* Compute adequate size for the octahedral map. */
+ linfo->shadow_cube_store_size = (int)ceil(sqrt((sh_cube_size * sh_cube_size) * 6.0f));
+
+ CLAMP(linfo->shadow_cube_store_size, 1, 4096);
+ CLAMP(sh_cube_size, 1, 4096);
+
+ linfo->shadow_render_data.cube_texel_size = 1.0f / sh_cube_size;
+ }
+
+ if ((linfo->shadow_cascade_size != sh_cascade_size) ||
+ (linfo->shadow_method != sh_method) ||
+ (linfo->shadow_high_bitdepth != sh_high_bitdepth))
+ {
+ BLI_assert((sh_cascade_size > 0) && (sh_cascade_size <= 4096));
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_pool);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_target);
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_blur);
+
+ CLAMP(sh_cascade_size, 1, 4096);
+ }
+
+ linfo->shadow_high_bitdepth = sh_high_bitdepth;
+ linfo->shadow_method = sh_method;
+ linfo->shadow_cube_size = sh_cube_size;
+ linfo->shadow_cascade_size = sh_cascade_size;
+
+ /* only compile the ones needed. reduce startup time. */
+ if ((sh_method == SHADOW_ESM) && !e_data.shadow_store_cube_sh[SHADOW_ESM]) {
+ DynStr *ds_frag = BLI_dynstr_new();
+ BLI_dynstr_append(ds_frag, datatoc_concentric_samples_lib_glsl);
+ BLI_dynstr_append(ds_frag, datatoc_shadow_store_frag_glsl);
+ char *store_shadow_shader_str = BLI_dynstr_get_cstring(ds_frag);
+ BLI_dynstr_free(ds_frag);
+
+ e_data.shadow_store_cube_sh[SHADOW_ESM] = DRW_shader_create_fullscreen(
+ store_shadow_shader_str,
+ "#define ESM\n");
+ e_data.shadow_store_cascade_sh[SHADOW_ESM] = DRW_shader_create_fullscreen(
+ store_shadow_shader_str,
+ "#define ESM\n"
+ "#define CSM\n");
+ MEM_freeN(store_shadow_shader_str);
+
+ e_data.shadow_copy_cube_sh[SHADOW_ESM] = DRW_shader_create_fullscreen(
+ datatoc_shadow_copy_frag_glsl,
+ "#define ESM\n"
+ "#define COPY\n");
+ e_data.shadow_copy_cascade_sh[SHADOW_ESM] = DRW_shader_create_fullscreen(
+ datatoc_shadow_copy_frag_glsl,
+ "#define ESM\n"
+ "#define COPY\n"
+ "#define CSM\n");
+ }
+ else if ((sh_method == SHADOW_VSM) && !e_data.shadow_store_cube_sh[SHADOW_VSM]) {
+ DynStr *ds_frag = BLI_dynstr_new();
+ BLI_dynstr_append(ds_frag, datatoc_concentric_samples_lib_glsl);
+ BLI_dynstr_append(ds_frag, datatoc_shadow_store_frag_glsl);
+ char *store_shadow_shader_str = BLI_dynstr_get_cstring(ds_frag);
+ BLI_dynstr_free(ds_frag);
+
+ e_data.shadow_store_cube_sh[SHADOW_VSM] = DRW_shader_create_fullscreen(
+ store_shadow_shader_str,
+ "#define VSM\n");
+ e_data.shadow_store_cascade_sh[SHADOW_VSM] = DRW_shader_create_fullscreen(
+ store_shadow_shader_str,
+ "#define VSM\n"
+ "#define CSM\n");
+ MEM_freeN(store_shadow_shader_str);
+
+ e_data.shadow_copy_cube_sh[SHADOW_VSM] = DRW_shader_create_fullscreen(
+ datatoc_shadow_copy_frag_glsl,
+ "#define VSM\n"
+ "#define COPY\n");
+ e_data.shadow_copy_cascade_sh[SHADOW_VSM] = DRW_shader_create_fullscreen(
+ datatoc_shadow_copy_frag_glsl,
+ "#define VSM\n"
+ "#define COPY\n"
+ "#define CSM\n");
+ }
+}
+
+void EEVEE_lights_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_PassList *psl = vedata->psl;
+
+ linfo->shcaster_frontbuffer->count = 0;
+ linfo->num_light = 0;
+ linfo->num_cube_layer = 0;
+ linfo->num_cascade_layer = 0;
+ linfo->gpu_cube_ct = linfo->gpu_cascade_ct = linfo->gpu_shadow_ct = 0;
+ linfo->cpu_cube_ct = linfo->cpu_cascade_ct = 0;
+ memset(linfo->light_ref, 0, sizeof(linfo->light_ref));
+ memset(linfo->shadow_cube_ref, 0, sizeof(linfo->shadow_cube_ref));
+ memset(linfo->shadow_cascade_ref, 0, sizeof(linfo->shadow_cascade_ref));
+ memset(linfo->new_shadow_id, -1, sizeof(linfo->new_shadow_id));
+
+ /* Shadow Casters: Reset flags. */
+ memset(linfo->shcaster_backbuffer->flags, (char)SHADOW_CASTER_PRUNED, linfo->shcaster_backbuffer->alloc_count);
+ memset(linfo->shcaster_frontbuffer->flags, 0x00, linfo->shcaster_frontbuffer->alloc_count);
+
+ {
+ psl->shadow_cube_store_pass = DRW_pass_create("Shadow Storage Pass", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(
+ e_data.shadow_store_cube_sh[linfo->shadow_method], psl->shadow_cube_store_pass);
+ DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cube_blur);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
+ DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+ {
+ psl->shadow_cascade_store_pass = DRW_pass_create("Shadow Cascade Storage Pass", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(
+ e_data.shadow_store_cascade_sh[linfo->shadow_method], psl->shadow_cascade_store_pass);
+ DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cascade_blur);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
+ DRW_shgroup_uniform_int(grp, "cascadeId", &linfo->current_shadow_cascade, 1);
+ DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+ {
+ psl->shadow_cube_copy_pass = DRW_pass_create("Shadow Copy Pass", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(
+ e_data.shadow_copy_cube_sh[linfo->shadow_method], psl->shadow_cube_copy_pass);
+ DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cube_target);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
+ DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
+ DRW_shgroup_uniform_int(grp, "faceId", &linfo->current_shadow_face, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+ {
+ psl->shadow_cascade_copy_pass = DRW_pass_create("Shadow Cascade Copy Pass", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(
+ e_data.shadow_copy_cascade_sh[linfo->shadow_method], psl->shadow_cascade_copy_pass);
+ DRW_shgroup_uniform_texture_ref(grp, "shadowTexture", &sldata->shadow_cascade_target);
+ DRW_shgroup_uniform_block(grp, "shadow_render_block", sldata->shadow_render_ubo);
+ DRW_shgroup_uniform_float(grp, "shadowFilterSize", &linfo->filter_size, 1);
+ DRW_shgroup_uniform_int(grp, "cascadeId", &linfo->current_shadow_cascade, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ psl->shadow_pass = DRW_pass_create("Shadow Pass", state);
+
+ stl->g_data->shadow_shgrp = DRW_shgroup_create(e_data.shadow_sh, psl->shadow_pass);
+ }
+}
+
+void EEVEE_lights_cache_add(EEVEE_ViewLayerData *sldata, Object *ob)
+{
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+
+ /* Step 1 find all lamps in the scene and setup them */
+ if (linfo->num_light >= MAX_LIGHT) {
+ printf("Too many lamps in the scene !!!\n");
+ }
+ else {
+ Lamp *la = (Lamp *)ob->data;
+ EEVEE_Light *evli = linfo->light_data + linfo->num_light;
+ eevee_light_setup(ob, evli);
+
+ /* We do not support shadowmaps for dupli lamps. */
+ if ((ob->base_flag & BASE_FROMDUPLI) != 0) {
+ linfo->num_light++;
+ return;
+ }
+
+ EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
+
+ /* Save previous shadow id. */
+ int prev_cube_sh_id = led->prev_cube_shadow_id;
+
+ /* Default light without shadows */
+ led->data.ld.shadow_id = -1;
+ led->prev_cube_shadow_id = -1;
+
+ if (la->mode & LA_SHADOW) {
+ if (la->type == LA_SUN) {
+ int sh_nbr = 1; /* TODO : MSM */
+ int cascade_nbr = la->cascade_count;
+
+ if ((linfo->gpu_cascade_ct + sh_nbr) <= MAX_SHADOW_CASCADE) {
+ /* Save Light object. */
+ linfo->shadow_cascade_ref[linfo->cpu_cascade_ct] = ob;
+
+ /* Store indices. */
+ EEVEE_ShadowCascadeData *data = &led->data.scad;
+ data->shadow_id = linfo->gpu_shadow_ct;
+ data->cascade_id = linfo->gpu_cascade_ct;
+ data->layer_id = linfo->num_cascade_layer;
+
+ /* Increment indices. */
+ linfo->gpu_shadow_ct += 1;
+ linfo->gpu_cascade_ct += sh_nbr;
+ linfo->num_cascade_layer += sh_nbr * cascade_nbr;
+
+ linfo->cpu_cascade_ct += 1;
+ }
+ }
+ else if (la->type == LA_SPOT || la->type == LA_LOCAL || la->type == LA_AREA) {
+ int sh_nbr = 1; /* TODO : MSM */
+
+ if ((linfo->gpu_cube_ct + sh_nbr) <= MAX_SHADOW_CUBE) {
+ /* Save Light object. */
+ linfo->shadow_cube_ref[linfo->cpu_cube_ct] = ob;
+
+ /* For light update tracking. */
+ if ((prev_cube_sh_id >= 0) &&
+ (prev_cube_sh_id < linfo->shcaster_backbuffer->count))
+ {
+ linfo->new_shadow_id[prev_cube_sh_id] = linfo->cpu_cube_ct;
+ }
+ led->prev_cube_shadow_id = linfo->cpu_cube_ct;
+
+ /* Saving lamp bounds for later. */
+ BLI_assert(linfo->cpu_cube_ct >= 0 && linfo->cpu_cube_ct < MAX_LIGHT);
+ copy_v3_v3(linfo->shadow_bounds[linfo->cpu_cube_ct].center, ob->obmat[3]);
+ linfo->shadow_bounds[linfo->cpu_cube_ct].radius = la->clipend;
+
+ EEVEE_ShadowCubeData *data = &led->data.scd;
+ /* Store indices. */
+ data->shadow_id = linfo->gpu_shadow_ct;
+ data->cube_id = linfo->gpu_cube_ct;
+ data->layer_id = linfo->num_cube_layer;
+
+ /* Increment indices. */
+ linfo->gpu_shadow_ct += 1;
+ linfo->gpu_cube_ct += sh_nbr;
+ linfo->num_cube_layer += sh_nbr;
+
+ linfo->cpu_cube_ct += 1;
+ }
+ }
+ }
+
+ led->data.ld.light_id = linfo->num_light;
+ linfo->light_ref[linfo->num_light] = ob;
+ linfo->num_light++;
+ }
+}
+
+/* Add a shadow caster to the shadowpasses */
+void EEVEE_lights_cache_shcaster_add(
+ EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_StorageList *stl, struct Gwn_Batch *geom, Object *ob)
+{
+ DRW_shgroup_call_object_add(
+ stl->g_data->shadow_shgrp,
+ geom, ob);
+}
+
+void EEVEE_lights_cache_shcaster_material_add(
+ EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_PassList *psl, struct GPUMaterial *gpumat,
+ struct Gwn_Batch *geom, struct Object *ob, float *alpha_threshold)
+{
+ /* TODO / PERF : reuse the same shading group for objects with the same material */
+ DRWShadingGroup *grp = DRW_shgroup_material_create(gpumat, psl->shadow_pass);
+
+ if (grp == NULL) return;
+
+ if (alpha_threshold != NULL)
+ DRW_shgroup_uniform_float(grp, "alphaThreshold", alpha_threshold, 1);
+
+ DRW_shgroup_call_object_add(grp, geom, ob);
+}
+
+/* Make that object update shadow casting lamps inside its influence bounding box. */
+void EEVEE_lights_cache_shcaster_object_add(EEVEE_ViewLayerData *sldata, Object *ob)
+{
+ if ((ob->base_flag & BASE_FROMDUPLI) != 0) {
+ /* TODO: Special case for dupli objects because we cannot save the object pointer. */
+ return;
+ }
+
+ EEVEE_ObjectEngineData *oedata = EEVEE_object_data_ensure(ob);
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+ EEVEE_ShadowCasterBuffer *backbuffer = linfo->shcaster_backbuffer;
+ EEVEE_ShadowCasterBuffer *frontbuffer = linfo->shcaster_frontbuffer;
+ int past_id = oedata->shadow_caster_id;
+
+ /* Update flags in backbuffer. */
+ if (past_id > -1 && past_id < backbuffer->count) {
+ backbuffer->flags[past_id] &= ~SHADOW_CASTER_PRUNED;
+
+ if (oedata->need_update) {
+ backbuffer->flags[past_id] |= SHADOW_CASTER_UPDATED;
+ }
+ }
+
+ /* Update id. */
+ oedata->shadow_caster_id = frontbuffer->count++;
+
+ /* Make sure shadow_casters is big enough. */
+ if (oedata->shadow_caster_id >= frontbuffer->alloc_count) {
+ frontbuffer->alloc_count += SHADOW_CASTER_ALLOC_CHUNK;
+ frontbuffer->shadow_casters = MEM_reallocN(frontbuffer->shadow_casters, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
+ frontbuffer->flags = MEM_reallocN(frontbuffer->flags, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
+ }
+
+ EEVEE_ShadowCaster *shcaster = frontbuffer->shadow_casters + oedata->shadow_caster_id;
+
+ if (oedata->need_update) {
+ frontbuffer->flags[oedata->shadow_caster_id] = SHADOW_CASTER_UPDATED;
+ }
+
+ /* Update World AABB in frontbuffer. */
+ BoundBox *bb = BKE_object_boundbox_get(ob);
+ float min[3], max[3];
+ INIT_MINMAX(min, max);
+ for (int i = 0; i < 8; ++i) {
+ float vec[3];
+ copy_v3_v3(vec, bb->vec[i]);
+ mul_m4_v3(ob->obmat, vec);
+ minmax_v3v3_v3(min, max, vec);
+ }
+
+ EEVEE_BoundBox *aabb = &shcaster->bbox;
+ add_v3_v3v3(aabb->center, min, max);
+ mul_v3_fl(aabb->center, 0.5f);
+ sub_v3_v3v3(aabb->halfdim, aabb->center, max);
+
+ aabb->halfdim[0] = fabsf(aabb->halfdim[0]);
+ aabb->halfdim[1] = fabsf(aabb->halfdim[1]);
+ aabb->halfdim[2] = fabsf(aabb->halfdim[2]);
+
+ oedata->need_update = false;
+}
+
+void EEVEE_lights_cache_finish(EEVEE_ViewLayerData *sldata)
+{
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+ GPUTextureFormat shadow_pool_format = GPU_R32F;
+
+ sldata->common_data.la_num_light = linfo->num_light;
+
+ /* Setup enough layers. */
+ /* Free textures if number mismatch. */
+ if (linfo->num_cube_layer != linfo->cache_num_cube_layer) {
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cube_pool);
+ linfo->cache_num_cube_layer = linfo->num_cube_layer;
+ linfo->update_flag |= LIGHT_UPDATE_SHADOW_CUBE;
+ }
+
+ if (linfo->num_cascade_layer != linfo->cache_num_cascade_layer) {
+ DRW_TEXTURE_FREE_SAFE(sldata->shadow_cascade_pool);
+ linfo->cache_num_cascade_layer = linfo->num_cascade_layer;
+ }
+
+ switch (linfo->shadow_method) {
+ case SHADOW_ESM: shadow_pool_format = ((linfo->shadow_high_bitdepth) ? GPU_R32F : GPU_R16F); break;
+ case SHADOW_VSM: shadow_pool_format = ((linfo->shadow_high_bitdepth) ? GPU_RG32F : GPU_RG16F); break;
+ default:
+ BLI_assert(!"Incorrect Shadow Method");
+ break;
+ }
+
+ /* Cubemaps */
+ if (!sldata->shadow_cube_target) {
+ sldata->shadow_cube_target = DRW_texture_create_cube(
+ linfo->shadow_cube_size, GPU_DEPTH_COMPONENT24, 0, NULL);
+ sldata->shadow_cube_blur = DRW_texture_create_cube(
+ linfo->shadow_cube_size, shadow_pool_format, DRW_TEX_FILTER, NULL);
+ }
+ if (!sldata->shadow_cube_pool) {
+ sldata->shadow_cube_pool = DRW_texture_create_2D_array(
+ linfo->shadow_cube_store_size, linfo->shadow_cube_store_size, max_ii(1, linfo->num_cube_layer),
+ shadow_pool_format, DRW_TEX_FILTER, NULL);
+ }
+ GPU_framebuffer_ensure_config(&sldata->shadow_cube_target_fb, {
+ GPU_ATTACHMENT_TEXTURE(sldata->shadow_cube_target)
+ });
+ GPU_framebuffer_ensure_config(&sldata->shadow_cube_store_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(sldata->shadow_cube_pool)
+ });
+
+ /* CSM */
+ if (!sldata->shadow_cascade_target) {
+ sldata->shadow_cascade_target = DRW_texture_create_2D_array(
+ linfo->shadow_cascade_size, linfo->shadow_cascade_size, MAX_CASCADE_NUM, GPU_DEPTH_COMPONENT24, 0, NULL);
+ sldata->shadow_cascade_blur = DRW_texture_create_2D_array(
+ linfo->shadow_cascade_size, linfo->shadow_cascade_size, MAX_CASCADE_NUM, shadow_pool_format, DRW_TEX_FILTER, NULL);
+ }
+ if (!sldata->shadow_cascade_pool) {
+ sldata->shadow_cascade_pool = DRW_texture_create_2D_array(
+ linfo->shadow_cascade_size, linfo->shadow_cascade_size, max_ii(1, linfo->num_cascade_layer),
+ shadow_pool_format, DRW_TEX_FILTER, NULL);
+ }
+ GPU_framebuffer_ensure_config(&sldata->shadow_cascade_target_fb, {
+ GPU_ATTACHMENT_TEXTURE(sldata->shadow_cascade_target)
+ });
+ GPU_framebuffer_ensure_config(&sldata->shadow_cascade_store_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(sldata->shadow_cascade_pool)
+ });
+
+ /* Update Lamps UBOs. */
+ EEVEE_lights_update(sldata);
+}
+
+/* Update buffer with lamp data */
+static void eevee_light_setup(Object *ob, EEVEE_Light *evli)
+{
+ Lamp *la = (Lamp *)ob->data;
+ float mat[4][4], scale[3], power;
+
+ /* Position */
+ copy_v3_v3(evli->position, ob->obmat[3]);
+
+ /* Color */
+ copy_v3_v3(evli->color, &la->r);
+
+ evli->spec = la->spec_fac;
+
+ /* Influence Radius */
+ evli->dist = la->dist;
+
+ /* Vectors */
+ normalize_m4_m4_ex(mat, ob->obmat, scale);
+ copy_v3_v3(evli->forwardvec, mat[2]);
+ normalize_v3(evli->forwardvec);
+ negate_v3(evli->forwardvec);
+
+ copy_v3_v3(evli->rightvec, mat[0]);
+ normalize_v3(evli->rightvec);
+
+ copy_v3_v3(evli->upvec, mat[1]);
+ normalize_v3(evli->upvec);
+
+ /* Spot size & blend */
+ if (la->type == LA_SPOT) {
+ evli->sizex = scale[0] / scale[2];
+ evli->sizey = scale[1] / scale[2];
+ evli->spotsize = cosf(la->spotsize * 0.5f);
+ evli->spotblend = (1.0f - evli->spotsize) * la->spotblend;
+ evli->radius = max_ff(0.001f, la->area_size);
+ }
+ else if (la->type == LA_AREA) {
+ evli->sizex = max_ff(0.0001f, la->area_size * scale[0] * 0.5f);
+ if (la->area_shape == LA_AREA_RECT) {
+ evli->sizey = max_ff(0.0001f, la->area_sizey * scale[1] * 0.5f);
+ }
+ else {
+ evli->sizey = max_ff(0.0001f, la->area_size * scale[1] * 0.5f);
+ }
+ }
+ else {
+ evli->radius = max_ff(0.001f, la->area_size);
+ }
+
+ /* Make illumination power constant */
+ if (la->type == LA_AREA) {
+ power = 1.0f / (evli->sizex * evli->sizey * 4.0f * M_PI) * /* 1/(w*h*Pi) */
+ 80.0f; /* XXX : Empirical, Fit cycles power */
+ }
+ else if (la->type == LA_SPOT || la->type == LA_LOCAL) {
+ power = 1.0f / (4.0f * evli->radius * evli->radius * M_PI * M_PI) * /* 1/(4*r²*Pi²) */
+ M_PI * M_PI * 10.0; /* XXX : Empirical, Fit cycles power */
+
+ /* for point lights (a.k.a radius == 0.0) */
+ // power = M_PI * M_PI * 0.78; /* XXX : Empirical, Fit cycles power */
+ }
+ else {
+ power = 1.0f / (4.0f * evli->radius * evli->radius * M_PI * M_PI) * /* 1/(r²*Pi) */
+ 12.5f; /* XXX : Empirical, Fit cycles power */
+ }
+ mul_v3_fl(evli->color, power * la->energy);
+
+ /* Lamp Type */
+ evli->lamptype = (float)la->type;
+
+ /* No shadow by default */
+ evli->shadowid = -1.0f;
+}
+
+static void eevee_shadow_cube_setup(Object *ob, EEVEE_LampsInfo *linfo, EEVEE_LampEngineData *led)
+{
+ EEVEE_ShadowCubeData *sh_data = &led->data.scd;
+ EEVEE_Light *evli = linfo->light_data + sh_data->light_id;
+ EEVEE_Shadow *ubo_data = linfo->shadow_data + sh_data->shadow_id;
+ EEVEE_ShadowCube *cube_data = linfo->shadow_cube_data + sh_data->cube_id;
+ Lamp *la = (Lamp *)ob->data;
+
+ int sh_nbr = 1; /* TODO: MSM */
+
+ for (int i = 0; i < sh_nbr; ++i) {
+ /* TODO : choose MSM sample point here. */
+ copy_v3_v3(cube_data->position, ob->obmat[3]);
+ }
+
+ ubo_data->bias = 0.05f * la->bias;
+ ubo_data->near = la->clipsta;
+ ubo_data->far = la->clipend;
+ ubo_data->exp = (linfo->shadow_method == SHADOW_VSM) ? la->bleedbias : la->bleedexp;
+
+ evli->shadowid = (float)(sh_data->shadow_id);
+ ubo_data->shadow_start = (float)(sh_data->layer_id);
+ ubo_data->data_start = (float)(sh_data->cube_id);
+ ubo_data->multi_shadow_count = (float)(sh_nbr);
+ ubo_data->shadow_blur = la->soft * 0.02f; /* Used by translucence shadowmap blur */
+
+ ubo_data->contact_dist = (la->mode & LA_SHAD_CONTACT) ? la->contact_dist : 0.0f;
+ ubo_data->contact_bias = 0.05f * la->contact_bias;
+ ubo_data->contact_spread = la->contact_spread;
+ ubo_data->contact_thickness = la->contact_thickness;
+}
+
+#define LERP(t, a, b) ((a) + (t) * ((b) - (a)))
+
+static double round_to_digits(double value, int digits)
+{
+ double factor = pow(10.0, digits - ceil(log10(fabs(value))));
+ return round(value * factor) / factor;
+}
+
+static void frustum_min_bounding_sphere(const float corners[8][3], float r_center[3], float *r_radius)
+{
+#if 0 /* Simple solution but waste too much space. */
+ float minvec[3], maxvec[3];
+
+ /* compute the bounding box */
+ INIT_MINMAX(minvec, maxvec);
+ for (int i = 0; i < 8; ++i) {
+ minmax_v3v3_v3(minvec, maxvec, corners[i]);
+ }
+
+ /* compute the bounding sphere of this box */
+ r_radius = len_v3v3(minvec, maxvec) * 0.5f;
+ add_v3_v3v3(r_center, minvec, maxvec);
+ mul_v3_fl(r_center, 0.5f);
+#else
+ /* Find averaged center. */
+ zero_v3(r_center);
+ for (int i = 0; i < 8; ++i) {
+ add_v3_v3(r_center, corners[i]);
+ }
+ mul_v3_fl(r_center, 1.0f / 8.0f);
+
+ /* Search the largest distance from the sphere center. */
+ *r_radius = 0.0f;
+ for (int i = 0; i < 8; ++i) {
+ float rad = len_squared_v3v3(corners[i], r_center);
+ if (rad > *r_radius) {
+ *r_radius = rad;
+ }
+ }
+
+ /* TODO try to reduce the radius further by moving the center.
+ * Remember we need a __stable__ solution! */
+
+ /* Try to reduce float imprecision leading to shimmering. */
+ *r_radius = (float)round_to_digits(sqrtf(*r_radius), 3);
+#endif
+}
+
+static void eevee_shadow_cascade_setup(
+ Object *ob, EEVEE_LampsInfo *linfo, EEVEE_LampEngineData *led,
+ DRWMatrixState *saved_mats, float view_near, float view_far)
+{
+ Lamp *la = (Lamp *)ob->data;
+
+ /* Camera Matrices */
+ float (*persinv)[4] = saved_mats->mat[DRW_MAT_PERSINV];
+ float (*vp_projmat)[4] = saved_mats->mat[DRW_MAT_WIN];
+ bool is_persp = DRW_viewport_is_persp_get();
+
+ /* Lamps Matrices */
+ int sh_nbr = 1; /* TODO : MSM */
+ int cascade_nbr = la->cascade_count;
+
+ EEVEE_ShadowCascadeData *sh_data = &led->data.scad;
+ EEVEE_Light *evli = linfo->light_data + sh_data->light_id;
+ EEVEE_Shadow *ubo_data = linfo->shadow_data + sh_data->shadow_id;
+ EEVEE_ShadowCascade *cascade_data = linfo->shadow_cascade_data + sh_data->cascade_id;
+
+ /* obmat = Object Space > World Space */
+ /* viewmat = World Space > View Space */
+ float (*viewmat)[4] = sh_data->viewmat;
+#if 0 /* done at culling time */
+ normalize_m4_m4(viewmat, ob->obmat);
+#endif
+ invert_m4(viewmat);
+ invert_m4_m4(sh_data->viewinv, viewmat);
+
+ /* The technique consists into splitting
+ * the view frustum into several sub-frustum
+ * that are individually receiving one shadow map */
+
+ float csm_start, csm_end;
+
+ if (is_persp) {
+ csm_start = view_near;
+ csm_end = max_ff(view_far, -la->cascade_max_dist);
+ /* Avoid artifacts */
+ csm_end = min_ff(view_near, csm_end);
+ }
+ else {
+ csm_start = -view_far;
+ csm_end = view_far;
+ }
+
+ /* init near/far */
+ for (int c = 0; c < MAX_CASCADE_NUM; ++c) {
+ cascade_data->split_start[c] = csm_end;
+ cascade_data->split_end[c] = csm_end;
+ }
+
+ /* Compute split planes */
+ float splits_start_ndc[MAX_CASCADE_NUM];
+ float splits_end_ndc[MAX_CASCADE_NUM];
+
+ {
+ /* Nearest plane */
+ float p[4] = {1.0f, 1.0f, csm_start, 1.0f};
+ /* TODO: we don't need full m4 multiply here */
+ mul_m4_v4(vp_projmat, p);
+ splits_start_ndc[0] = p[2];
+ if (is_persp) {
+ splits_start_ndc[0] /= p[3];
+ }
+ }
+
+ {
+ /* Farthest plane */
+ float p[4] = {1.0f, 1.0f, csm_end, 1.0f};
+ /* TODO: we don't need full m4 multiply here */
+ mul_m4_v4(vp_projmat, p);
+ splits_end_ndc[cascade_nbr - 1] = p[2];
+ if (is_persp) {
+ splits_end_ndc[cascade_nbr - 1] /= p[3];
+ }
+ }
+
+ cascade_data->split_start[0] = csm_start;
+ cascade_data->split_end[cascade_nbr - 1] = csm_end;
+
+ for (int c = 1; c < cascade_nbr; ++c) {
+ /* View Space */
+ float linear_split = LERP(((float)(c) / (float)cascade_nbr), csm_start, csm_end);
+ float exp_split = csm_start * powf(csm_end / csm_start, (float)(c) / (float)cascade_nbr);
+
+ if (is_persp) {
+ cascade_data->split_start[c] = LERP(la->cascade_exponent, linear_split, exp_split);
+ }
+ else {
+ cascade_data->split_start[c] = linear_split;
+ }
+ cascade_data->split_end[c - 1] = cascade_data->split_start[c];
+
+ /* Add some overlap for smooth transition */
+ cascade_data->split_start[c] = LERP(la->cascade_fade, cascade_data->split_end[c - 1],
+ (c > 1) ? cascade_data->split_end[c - 2] : cascade_data->split_start[0]);
+
+ /* NDC Space */
+ {
+ float p[4] = {1.0f, 1.0f, cascade_data->split_start[c], 1.0f};
+ /* TODO: we don't need full m4 multiply here */
+ mul_m4_v4(vp_projmat, p);
+ splits_start_ndc[c] = p[2];
+
+ if (is_persp) {
+ splits_start_ndc[c] /= p[3];
+ }
+ }
+
+ {
+ float p[4] = {1.0f, 1.0f, cascade_data->split_end[c - 1], 1.0f};
+ /* TODO: we don't need full m4 multiply here */
+ mul_m4_v4(vp_projmat, p);
+ splits_end_ndc[c - 1] = p[2];
+
+ if (is_persp) {
+ splits_end_ndc[c - 1] /= p[3];
+ }
+ }
+ }
+
+ /* Set last cascade split fade distance into the first split_start. */
+ float prev_split = (cascade_nbr > 1) ? cascade_data->split_end[cascade_nbr - 2] : cascade_data->split_start[0];
+ cascade_data->split_start[0] = LERP(la->cascade_fade, cascade_data->split_end[cascade_nbr - 1], prev_split);
+
+ /* For each cascade */
+ for (int c = 0; c < cascade_nbr; ++c) {
+ float (*projmat)[4] = sh_data->projmat[c];
+ /* Given 8 frustum corners */
+ float corners[8][3] = {
+ /* Near Cap */
+ {-1.0f, -1.0f, splits_start_ndc[c]},
+ { 1.0f, -1.0f, splits_start_ndc[c]},
+ {-1.0f, 1.0f, splits_start_ndc[c]},
+ { 1.0f, 1.0f, splits_start_ndc[c]},
+ /* Far Cap */
+ {-1.0f, -1.0f, splits_end_ndc[c]},
+ { 1.0f, -1.0f, splits_end_ndc[c]},
+ {-1.0f, 1.0f, splits_end_ndc[c]},
+ { 1.0f, 1.0f, splits_end_ndc[c]}
+ };
+
+ /* Transform them into world space */
+ for (int i = 0; i < 8; ++i) {
+ mul_project_m4_v3(persinv, corners[i]);
+ }
+
+ float center[3];
+ frustum_min_bounding_sphere(corners, center, &(sh_data->radius[c]));
+
+ /* Project into lightspace */
+ mul_mat3_m4_v3(viewmat, center);
+
+ /* Snap projection center to nearest texel to cancel shimmering. */
+ float shadow_origin[2], shadow_texco[2];
+ /* Light to texture space. */
+ mul_v2_v2fl(shadow_origin, center, linfo->shadow_cascade_size / (2.0f * sh_data->radius[c]));
+
+ /* Find the nearest texel. */
+ shadow_texco[0] = roundf(shadow_origin[0]);
+ shadow_texco[1] = roundf(shadow_origin[1]);
+
+ /* Compute offset. */
+ sub_v2_v2(shadow_texco, shadow_origin);
+ mul_v2_fl(shadow_texco, (2.0f * sh_data->radius[c]) / linfo->shadow_cascade_size); /* Texture to light space. */
+
+ /* Apply offset. */
+ add_v2_v2(center, shadow_texco);
+
+ /* Expand the projection to cover frustum range */
+ rctf rect_cascade;
+ BLI_rctf_init_pt_radius(&rect_cascade, center, sh_data->radius[c]);
+ orthographic_m4(projmat,
+ rect_cascade.xmin, rect_cascade.xmax,
+ rect_cascade.ymin, rect_cascade.ymax,
+ la->clipsta, la->clipend);
+
+ mul_m4_m4m4(sh_data->viewprojmat[c], projmat, viewmat);
+ mul_m4_m4m4(cascade_data->shadowmat[c], texcomat, sh_data->viewprojmat[c]);
+ }
+
+ ubo_data->bias = 0.05f * la->bias;
+ ubo_data->near = la->clipsta;
+ ubo_data->far = la->clipend;
+ ubo_data->exp = (linfo->shadow_method == SHADOW_VSM) ? la->bleedbias : la->bleedexp;
+
+ evli->shadowid = (float)(sh_data->shadow_id);
+ ubo_data->shadow_start = (float)(sh_data->layer_id);
+ ubo_data->data_start = (float)(sh_data->cascade_id);
+ ubo_data->multi_shadow_count = (float)(sh_nbr);
+ ubo_data->shadow_blur = la->soft * 0.02f; /* Used by translucence shadowmap blur */
+
+ ubo_data->contact_dist = (la->mode & LA_SHAD_CONTACT) ? la->contact_dist : 0.0f;
+ ubo_data->contact_bias = 0.05f * la->contact_bias;
+ ubo_data->contact_spread = la->contact_spread;
+ ubo_data->contact_thickness = la->contact_thickness;
+}
+
+/* Used for checking if object is inside the shadow volume. */
+static bool sphere_bbox_intersect(const EEVEE_BoundSphere *bs, const EEVEE_BoundBox *bb)
+{
+ /* We are testing using a rougher AABB vs AABB test instead of full AABB vs Sphere. */
+ /* TODO test speed with AABB vs Sphere. */
+ bool x = fabsf(bb->center[0] - bs->center[0]) <= (bb->halfdim[0] + bs->radius);
+ bool y = fabsf(bb->center[1] - bs->center[1]) <= (bb->halfdim[1] + bs->radius);
+ bool z = fabsf(bb->center[2] - bs->center[2]) <= (bb->halfdim[2] + bs->radius);
+
+ return x && y && z;
+}
+
+void EEVEE_lights_update(EEVEE_ViewLayerData *sldata)
+{
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+ Object *ob;
+ int i;
+ char *flag;
+ EEVEE_ShadowCaster *shcaster;
+ EEVEE_BoundSphere *bsphere;
+ EEVEE_ShadowCasterBuffer *frontbuffer = linfo->shcaster_frontbuffer;
+ EEVEE_ShadowCasterBuffer *backbuffer = linfo->shcaster_backbuffer;
+
+ EEVEE_LightBits update_bits = {{0}};
+ if ((linfo->update_flag & LIGHT_UPDATE_SHADOW_CUBE) != 0) {
+ /* Update all lights. */
+ lightbits_set_all(&update_bits, true);
+ }
+ else {
+ /* Search for deleted shadow casters and if shcaster WAS in shadow radius. */
+ /* No need to run this if we already update all lamps. */
+ EEVEE_LightBits past_bits = {{0}};
+ EEVEE_LightBits curr_bits = {{0}};
+ shcaster = backbuffer->shadow_casters;
+ flag = backbuffer->flags;
+ for (i = 0; i < backbuffer->count; ++i, ++flag, ++shcaster) {
+ /* If the shadowcaster has been deleted or updated. */
+ if (*flag != 0) {
+ /* Add the lamps that were intersecting with its BBox. */
+ lightbits_or(&past_bits, &shcaster->bits);
+ }
+ }
+ /* Convert old bits to new bits and add result to final update bits. */
+ /* NOTE: This might be overkill since all lights are tagged to refresh if
+ * the light count changes. */
+ lightbits_convert(&curr_bits, &past_bits, linfo->new_shadow_id, MAX_LIGHT);
+ lightbits_or(&update_bits, &curr_bits);
+ }
+
+ /* Search for updates in current shadow casters. */
+ shcaster = frontbuffer->shadow_casters;
+ flag = frontbuffer->flags;
+ for (i = 0; i < frontbuffer->count; i++, flag++, shcaster++) {
+ /* Run intersection checks to fill the bitfields. */
+ bsphere = linfo->shadow_bounds;
+ for (int j = 0; j < linfo->cpu_cube_ct; j++, bsphere++) {
+ bool iter = sphere_bbox_intersect(bsphere, &shcaster->bbox);
+ lightbits_set_single(&shcaster->bits, j, iter);
+ }
+ /* Only add to final bits if objects has been updated. */
+ if (*flag != 0) {
+ lightbits_or(&update_bits, &shcaster->bits);
+ }
+ }
+
+ /* Setup shadow cube in UBO and tag for update if necessary. */
+ for (i = 0; (i < MAX_SHADOW_CUBE) && (ob = linfo->shadow_cube_ref[i]); i++) {
+ EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
+
+ eevee_shadow_cube_setup(ob, linfo, led);
+ if (lightbits_get(&update_bits, i) != 0) {
+ led->need_update = true;
+ }
+ }
+
+ /* Resize shcasters buffers if too big. */
+ if (frontbuffer->alloc_count - frontbuffer->count > SHADOW_CASTER_ALLOC_CHUNK) {
+ frontbuffer->alloc_count = (frontbuffer->count / SHADOW_CASTER_ALLOC_CHUNK) * SHADOW_CASTER_ALLOC_CHUNK;
+ frontbuffer->alloc_count += (frontbuffer->count % SHADOW_CASTER_ALLOC_CHUNK != 0) ? SHADOW_CASTER_ALLOC_CHUNK : 0;
+ frontbuffer->shadow_casters = MEM_reallocN(frontbuffer->shadow_casters, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
+ frontbuffer->flags = MEM_reallocN(frontbuffer->flags, sizeof(EEVEE_ShadowCaster) * frontbuffer->alloc_count);
+ }
+}
+
+/* this refresh lamps shadow buffers */
+void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl)
+{
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+ Object *ob;
+ int i;
+
+ DRWMatrixState saved_mats;
+
+ /* Precompute all shadow/view test before rendering and trashing the culling cache. */
+ bool cube_visible[MAX_SHADOW_CUBE];
+ for (i = 0; (ob = linfo->shadow_cube_ref[i]) && (i < MAX_SHADOW_CUBE); i++) {
+ Lamp *la = (Lamp *)ob->data;
+ BoundSphere bsphere = {
+ .center = {ob->obmat[3][0], ob->obmat[3][1], ob->obmat[3][2]},
+ .radius = la->dist
+ };
+ cube_visible[i] = DRW_culling_sphere_test(&bsphere);
+ }
+ bool cascade_visible[MAX_SHADOW_CASCADE];
+ for (i = 0; (ob = linfo->shadow_cascade_ref[i]) && (i < MAX_SHADOW_CASCADE); i++) {
+ EEVEE_LampEngineData *led = EEVEE_lamp_data_get(ob);
+ EEVEE_ShadowCascadeData *sh_data = &led->data.scad;
+ float plane[4];
+ normalize_m4_m4(sh_data->viewmat, ob->obmat);
+ plane_from_point_normal_v3(plane, sh_data->viewmat[3], sh_data->viewmat[2]);
+ /* TODO: check against near/far instead of "local Z = 0" plane.
+ * Or even the cascades AABB. */
+ cascade_visible[i] = DRW_culling_plane_test(plane);
+ }
+
+ /* We need to save the Matrices before overidding them */
+ DRW_viewport_matrix_get_all(&saved_mats);
+
+ /* Cube Shadow Maps */
+ DRW_stats_group_start("Cube Shadow Maps");
+ /* Render each shadow to one layer of the array */
+ for (i = 0; (ob = linfo->shadow_cube_ref[i]) && (i < MAX_SHADOW_CUBE); i++) {
+ EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
+ Lamp *la = (Lamp *)ob->data;
+
+ if (!led->need_update || !cube_visible[i]) {
+ continue;
+ }
+
+ DRWMatrixState render_mats;
+ float (*winmat)[4] = render_mats.mat[DRW_MAT_WIN];
+ float (*viewmat)[4] = render_mats.mat[DRW_MAT_VIEW];
+ float (*persmat)[4] = render_mats.mat[DRW_MAT_PERS];
+
+ EEVEE_ShadowRender *srd = &linfo->shadow_render_data;
+ EEVEE_ShadowCubeData *evscd = &led->data.scd;
+
+ perspective_m4(winmat, -la->clipsta, la->clipsta, -la->clipsta, la->clipsta, la->clipsta, la->clipend);
+
+ srd->clip_near = la->clipsta;
+ srd->clip_far = la->clipend;
+ copy_v3_v3(srd->position, ob->obmat[3]);
+
+ srd->stored_texel_size = 1.0 / (float)linfo->shadow_cube_store_size;
+
+ DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
+
+ /* Render shadow cube */
+ /* Render 6 faces separatly: seems to be faster for the general case.
+ * The only time it's more beneficial is when the CPU culling overhead
+ * outweight the instancing overhead. which is rarelly the case. */
+ for (int j = 0; j < 6; j++) {
+ /* TODO optimize */
+ float tmp[4][4];
+ unit_m4(tmp);
+ negate_v3_v3(tmp[3], srd->position);
+ mul_m4_m4m4(viewmat, cubefacemat[j], tmp);
+ mul_m4_m4m4(persmat, winmat, viewmat);
+ invert_m4_m4(render_mats.mat[DRW_MAT_WININV], winmat);
+ invert_m4_m4(render_mats.mat[DRW_MAT_VIEWINV], viewmat);
+ invert_m4_m4(render_mats.mat[DRW_MAT_PERSINV], persmat);
+
+ DRW_viewport_matrix_override_set_all(&render_mats);
+
+ GPU_framebuffer_texture_cubeface_attach(sldata->shadow_cube_target_fb,
+ sldata->shadow_cube_target, 0, j, 0);
+ GPU_framebuffer_bind(sldata->shadow_cube_target_fb);
+ GPU_framebuffer_clear_depth(sldata->shadow_cube_target_fb, 1.0f);
+ DRW_draw_pass(psl->shadow_pass);
+ }
+
+ /* 0.001f is arbitrary, but it should be relatively small so that filter size is not too big. */
+ float filter_texture_size = la->soft * 0.001f;
+ float filter_pixel_size = ceil(filter_texture_size / srd->cube_texel_size);
+ linfo->filter_size = srd->cube_texel_size * ((filter_pixel_size > 1.0f) ? 1.5f : 0.0f);
+
+ /* TODO: OPTI: Filter all faces in one/two draw call */
+ /* TODO: OPTI: Don't do this intermediate step if no filter is needed. */
+ for (linfo->current_shadow_face = 0;
+ linfo->current_shadow_face < 6;
+ linfo->current_shadow_face++)
+ {
+ /* Copy using a small 3x3 box filter */
+ GPU_framebuffer_texture_cubeface_attach(sldata->shadow_cube_store_fb, sldata->shadow_cube_blur, 0,
+ linfo->current_shadow_face, 0);
+ GPU_framebuffer_bind(sldata->shadow_cube_store_fb);
+ DRW_draw_pass(psl->shadow_cube_copy_pass);
+ }
+
+ /* Push it to shadowmap array */
+
+ /* Adjust constants if concentric samples change. */
+ const float max_filter_size = 7.5f;
+ const float magic = 4.5f; /* Dunno why but that works. */
+ const int max_sample = 256;
+
+ if (filter_pixel_size > 2.0f) {
+ linfo->filter_size = srd->cube_texel_size * max_filter_size * magic;
+ filter_pixel_size = max_ff(0.0f, filter_pixel_size - 3.0f);
+ /* Compute number of concentric samples. Depends directly on filter size. */
+ float pix_size_sqr = filter_pixel_size * filter_pixel_size;
+ srd->shadow_samples_ct = min_ii(max_sample, 4 + 8 * (int)filter_pixel_size + 4 * (int)(pix_size_sqr));
+ }
+ else {
+ linfo->filter_size = 0.0f;
+ srd->shadow_samples_ct = 4;
+ }
+ srd->shadow_inv_samples_ct = 1.0f / (float)srd->shadow_samples_ct;
+ DRW_uniformbuffer_update(sldata->shadow_render_ubo, srd);
+
+ GPU_framebuffer_texture_layer_attach(sldata->shadow_cube_store_fb, sldata->shadow_cube_pool, 0, evscd->layer_id, 0);
+ GPU_framebuffer_bind(sldata->shadow_cube_store_fb);
+ DRW_draw_pass(psl->shadow_cube_store_pass);
+
+ led->need_update = false;
+ }
+ linfo->update_flag &= ~LIGHT_UPDATE_SHADOW_CUBE;
+ DRW_stats_group_end();
+
+ DRW_viewport_matrix_override_set_all(&saved_mats);
+ float near = DRW_viewport_near_distance_get();
+ float far = DRW_viewport_far_distance_get();
+
+ /* Cascaded Shadow Maps */
+ DRW_stats_group_start("Cascaded Shadow Maps");
+ for (i = 0; (ob = linfo->shadow_cascade_ref[i]) && (i < MAX_SHADOW_CASCADE); i++) {
+ if (!cascade_visible[i]) {
+ continue;
+ }
+
+ EEVEE_LampEngineData *led = EEVEE_lamp_data_ensure(ob);
+ Lamp *la = (Lamp *)ob->data;
+
+ EEVEE_ShadowCascadeData *evscd = &led->data.scad;
+ EEVEE_ShadowRender *srd = &linfo->shadow_render_data;
+
+ DRWMatrixState render_mats;
+ float (*winmat)[4] = render_mats.mat[DRW_MAT_WIN];
+ float (*viewmat)[4] = render_mats.mat[DRW_MAT_VIEW];
+ float (*persmat)[4] = render_mats.mat[DRW_MAT_PERS];
+
+ eevee_shadow_cascade_setup(ob, linfo, led, &saved_mats, near, far);
+
+ srd->clip_near = la->clipsta;
+ srd->clip_far = la->clipend;
+ srd->stored_texel_size = 1.0 / (float)linfo->shadow_cascade_size;
+
+ DRW_uniformbuffer_update(sldata->shadow_render_ubo, &linfo->shadow_render_data);
+
+ copy_m4_m4(viewmat, evscd->viewmat);
+ invert_m4_m4(render_mats.mat[DRW_MAT_VIEWINV], viewmat);
+
+ /* Render shadow cascades */
+ /* Render cascade separatly: seems to be faster for the general case.
+ * The only time it's more beneficial is when the CPU culling overhead
+ * outweight the instancing overhead. which is rarelly the case. */
+ for (int j = 0; j < la->cascade_count; j++) {
+ copy_m4_m4(winmat, evscd->projmat[j]);
+ copy_m4_m4(persmat, evscd->viewprojmat[j]);
+ invert_m4_m4(render_mats.mat[DRW_MAT_WININV], winmat);
+ invert_m4_m4(render_mats.mat[DRW_MAT_PERSINV], persmat);
+
+ DRW_viewport_matrix_override_set_all(&render_mats);
+
+ GPU_framebuffer_texture_layer_attach(sldata->shadow_cascade_target_fb,
+ sldata->shadow_cascade_target, 0, j, 0);
+ GPU_framebuffer_bind(sldata->shadow_cascade_target_fb);
+ GPU_framebuffer_clear_depth(sldata->shadow_cascade_target_fb, 1.0f);
+ DRW_draw_pass(psl->shadow_pass);
+ }
+
+ /* TODO: OPTI: Filter all cascade in one/two draw call */
+ for (linfo->current_shadow_cascade = 0;
+ linfo->current_shadow_cascade < la->cascade_count;
+ ++linfo->current_shadow_cascade)
+ {
+ /* 0.01f factor to convert to percentage */
+ float filter_texture_size = la->soft * 0.01f / evscd->radius[linfo->current_shadow_cascade];
+ float filter_pixel_size = ceil(linfo->shadow_cascade_size * filter_texture_size);
+
+ /* Copy using a small 3x3 box filter */
+ /* NOTE: We always do it in the case of CSM because of artifacts in the farthest cascade. */
+ linfo->filter_size = srd->stored_texel_size;
+ GPU_framebuffer_texture_layer_attach(
+ sldata->shadow_cascade_store_fb, sldata->shadow_cascade_blur, 0, linfo->current_shadow_cascade, 0);
+ GPU_framebuffer_bind(sldata->shadow_cascade_store_fb);
+ DRW_draw_pass(psl->shadow_cascade_copy_pass);
+
+ /* Push it to shadowmap array and blur more */
+
+ /* Adjust constants if concentric samples change. */
+ const float max_filter_size = 7.5f;
+ const float magic = 3.2f; /* Arbitrary: less banding */
+ const int max_sample = 256;
+
+ if (filter_pixel_size > 2.0f) {
+ linfo->filter_size = srd->stored_texel_size * max_filter_size * magic;
+ filter_pixel_size = max_ff(0.0f, filter_pixel_size - 3.0f);
+ /* Compute number of concentric samples. Depends directly on filter size. */
+ float pix_size_sqr = filter_pixel_size * filter_pixel_size;
+ srd->shadow_samples_ct = min_ii(max_sample, 4 + 8 * (int)filter_pixel_size + 4 * (int)(pix_size_sqr));
+ }
+ else {
+ linfo->filter_size = 0.0f;
+ srd->shadow_samples_ct = 4;
+ }
+ srd->shadow_inv_samples_ct = 1.0f / (float)srd->shadow_samples_ct;
+ DRW_uniformbuffer_update(sldata->shadow_render_ubo, &linfo->shadow_render_data);
+
+ int layer = evscd->layer_id + linfo->current_shadow_cascade;
+ GPU_framebuffer_texture_layer_attach(sldata->shadow_cascade_store_fb, sldata->shadow_cascade_pool, 0, layer, 0);
+ GPU_framebuffer_bind(sldata->shadow_cascade_store_fb);
+ DRW_draw_pass(psl->shadow_cascade_store_pass);
+ }
+ }
+
+ DRW_stats_group_end();
+
+ DRW_viewport_matrix_override_set_all(&saved_mats);
+
+ DRW_uniformbuffer_update(sldata->light_ubo, &linfo->light_data);
+ DRW_uniformbuffer_update(sldata->shadow_ubo, &linfo->shadow_data); /* Update all data at once */
+}
+
+void EEVEE_lights_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.shadow_sh);
+ for (int i = 0; i < SHADOW_METHOD_MAX; ++i) {
+ DRW_SHADER_FREE_SAFE(e_data.shadow_store_cube_sh[i]);
+ DRW_SHADER_FREE_SAFE(e_data.shadow_store_cascade_sh[i]);
+ DRW_SHADER_FREE_SAFE(e_data.shadow_copy_cube_sh[i]);
+ DRW_SHADER_FREE_SAFE(e_data.shadow_copy_cascade_sh[i]);
+ }
+}
diff --git a/source/blender/draw/engines/eevee/eevee_lut.h b/source/blender/draw/engines/eevee/eevee_lut.h
new file mode 100644
index 00000000000..da765b3e53a
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_lut.h
@@ -0,0 +1,16926 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Clement Foucault.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file eevee_lut.h
+ * \ingroup gpu
+ */
+
+#ifndef __EEVEE_LUT_H__
+#define __EEVEE_LUT_H__
+
+static float ltc_mat_ggx[64 * 64 * 4] = {
+ 0.000200, -0.000000, 1.000000, -0.000000, 0.000504, -0.000000, 1.000000, -0.000000, 0.002016,
+ -0.000000, 1.000000, -0.000000, 0.004535, -0.000000, 1.000000, -0.000000, 0.008063, -0.000000,
+ 1.000000, -0.000000, 0.012598, -0.000000, 1.000000, -0.000000, 0.018141, -0.000000, 1.000000,
+ -0.000000, 0.024692, -0.000000, 1.000000, -0.000000, 0.032252, -0.000000, 1.000000, -0.000000,
+ 0.040821, -0.000000, 1.000000, -0.000000, 0.050400, -0.000000, 1.000000, -0.000000, 0.060989,
+ -0.000000, 1.000000, -0.000000, 0.072591, -0.000000, 1.000000, -0.000000, 0.085206, -0.000000,
+ 1.000000, -0.000000, 0.098836, -0.000000, 1.000000, -0.000000, 0.113483, -0.000000, 1.000000,
+ -0.000000, 0.129147, -0.000000, 1.000000, -0.000000, 0.145828, -0.000000, 1.000000, -0.000000,
+ 0.163499, -0.000000, 1.000000, -0.000000, 0.181972, -0.000000, 1.000000, -0.000000, 0.199498,
+ -0.000000, 1.000000, -0.000000, 0.220031, -0.000000, 1.000000, -0.000000, 0.241588, -0.000000,
+ 1.000000, -0.000000, 0.264120, -0.000000, 1.000000, -0.000000, 0.287521, -0.000000, 1.000000,
+ -0.000000, 0.311478, -0.000000, 1.000000, -0.000000, 0.335127, -0.000000, 1.000000, -0.000000,
+ 0.359811, -0.000000, 1.000000, -0.000000, 0.386446, -0.000000, 1.000000, -0.000000, 0.413161,
+ -0.000000, 1.000000, -0.000000, 0.439142, -0.000000, 1.000000, -0.000000, 0.467039, -0.000000,
+ 1.000000, -0.000000, 0.495170, -0.000000, 1.000000, -0.000000, 0.522324, -0.000000, 1.000000,
+ -0.000000, 0.551482, -0.000000, 1.000000, -0.000000, 0.579621, -0.000000, 1.000000, -0.000000,
+ 0.608255, -0.000000, 1.000000, -0.000000, 0.636515, -0.000000, 1.000000, -0.000000, 0.664835,
+ -0.000000, 1.000000, -0.000000, 0.692549, -0.000000, 1.000000, -0.000000, 0.720375, -0.000000,
+ 1.000000, -0.000000, 0.747238, -0.000000, 1.000000, -0.000000, 0.773956, -0.000000, 1.000000,
+ -0.000000, 0.799879, -0.000000, 1.000000, -0.000000, 0.824889, -0.000000, 1.000000, -0.000000,
+ 0.849357, -0.000000, 1.000000, -0.000000, 0.873016, -0.000000, 1.000000, -0.000000, 0.895670,
+ -0.000000, 1.000000, -0.000000, 0.917194, -0.000000, 1.000000, -0.000000, 0.937978, -0.000000,
+ 1.000000, -0.000000, 0.957872, -0.000000, 1.000000, -0.000000, 0.976736, -0.000000, 1.000000,
+ -0.000000, 0.994433, -0.000000, 1.000000, -0.000000, 1.011206, -0.000000, 1.000000, -0.000000,
+ 1.026820, -0.000000, 1.000000, -0.000000, 1.041720, -0.000000, 1.000000, -0.000000, 1.055657,
+ -0.000000, 1.000000, -0.000000, 1.068642, -0.000000, 1.000000, -0.000000, 1.080646, -0.000000,
+ 1.000000, -0.000000, 1.091637, -0.000000, 1.000000, -0.000000, 1.101837, -0.000000, 1.000000,
+ -0.000000, 1.111292, -0.000000, 1.000000, -0.000000, 1.120025, -0.000000, 1.000000, -0.000000,
+ 1.127918, -0.000000, 1.000000, -0.000000, 0.000200, -0.000005, 1.000623, 0.024938, 0.000504,
+ -0.000013, 1.000643, 0.024938, 0.002016, -0.000050, 1.000618, 0.024938, 0.004535, -0.000113,
+ 1.000621, 0.024938, 0.008063, -0.000201, 1.000746, 0.024938, 0.012596, -0.000314, 1.000463,
+ 0.024937, 0.018140, -0.000452, 1.000511, 0.024939, 0.024693, -0.000616, 1.000541, 0.024938,
+ 0.032253, -0.000804, 1.000684, 0.024938, 0.040815, -0.001018, 1.000524, 0.024940, 0.050399,
+ -0.001257, 1.000582, 0.024937, 0.060989, -0.001521, 1.000655, 0.024937, 0.072591, -0.001810,
+ 1.000608, 0.024938, 0.085204, -0.002125, 1.000622, 0.024939, 0.098835, -0.002465, 1.000632,
+ 0.024937, 0.113483, -0.002830, 1.000640, 0.024939, 0.129143, -0.003220, 1.000568, 0.024938,
+ 0.145830, -0.003633, 1.000635, 0.024938, 0.163497, -0.004062, 1.000626, 0.024938, 0.181956,
+ -0.004424, 1.000612, 0.024924, 0.199791, -0.004593, 1.000627, 0.024890, 0.220029, -0.005480,
+ 1.000594, 0.024935, 0.241586, -0.006010, 1.000616, 0.024933, 0.264115, -0.006550, 1.000607,
+ 0.024927, 0.287514, -0.007072, 1.000595, 0.024909, 0.311455, -0.007472, 1.000616, 0.024872,
+ 0.335083, -0.007491, 1.000589, 0.024755, 0.359805, -0.008810, 1.000601, 0.024877, 0.386438,
+ -0.009282, 1.000640, 0.024824, 0.413131, -0.009534, 1.000599, 0.024708, 0.439249, -0.009701,
+ 1.000497, 0.024573, 0.466997, -0.010878, 1.000467, 0.024652, 0.495138, -0.010959, 1.000539,
+ 0.024455, 0.522654, -0.011386, 1.000518, 0.024318, 0.551415, -0.012022, 1.000533, 0.024216,
+ 0.579610, -0.011805, 1.000495, 0.023867, 0.608185, -0.012773, 1.000474, 0.023834, 0.636492,
+ -0.012377, 1.000488, 0.023327, 0.664826, -0.013172, 1.000576, 0.023205, 0.692674, -0.012847,
+ 1.000505, 0.022708, 0.720341, -0.013141, 1.000424, 0.022349, 0.747373, -0.013227, 1.000449,
+ 0.021871, 0.773980, -0.012739, 1.000478, 0.021171, 0.799839, -0.012999, 1.000396, 0.020606,
+ 0.825113, -0.012727, 1.000425, 0.020006, 0.849579, -0.012170, 1.000469, 0.019089, 0.873046,
+ -0.011855, 1.000411, 0.018291, 0.895777, -0.011711, 1.000426, 0.017534, 0.917518, -0.011107,
+ 1.000373, 0.016542, 0.938264, -0.010439, 1.000322, 0.015512, 0.958032, -0.009807, 1.000324,
+ 0.014491, 0.976838, -0.009268, 1.000341, 0.013468, 0.994631, -0.008662, 1.000318, 0.012376,
+ 1.011434, -0.007923, 1.000289, 0.011187, 1.027169, -0.007132, 1.000216, 0.010078, 1.041929,
+ -0.006332, 1.000096, 0.008924, 1.055767, -0.005554, 1.000156, 0.007770, 1.068595, -0.004811,
+ 1.000084, 0.006611, 1.080612, -0.003950, 1.000047, 0.005485, 1.091785, -0.003174, 1.000109,
+ 0.004352, 1.101998, -0.002363, 1.000029, 0.003180, 1.111423, -0.001552, 0.999985, 0.002091,
+ 1.120007, -0.000786, 0.999947, 0.000991, 1.127918, 0.000004, 1.000000, -0.000004, 0.000200,
+ -0.000010, 1.002495, 0.049907, 0.000504, -0.000025, 1.002476, 0.049908, 0.002016, -0.000101,
+ 1.002500, 0.049908, 0.004535, -0.000226, 1.002487, 0.049908, 0.008062, -0.000402, 1.002364,
+ 0.049908, 0.012598, -0.000629, 1.002412, 0.049908, 0.018140, -0.000905, 1.002379, 0.049908,
+ 0.024691, -0.001232, 1.002490, 0.049907, 0.032251, -0.001610, 1.002398, 0.049908, 0.040821,
+ -0.002037, 1.002392, 0.049908, 0.050398, -0.002515, 1.002431, 0.049907, 0.060989, -0.003044,
+ 1.002475, 0.049908, 0.072592, -0.003623, 1.002546, 0.049907, 0.085204, -0.004252, 1.002467,
+ 0.049907, 0.098832, -0.004932, 1.002450, 0.049908, 0.113481, -0.005663, 1.002482, 0.049907,
+ 0.129145, -0.006443, 1.002443, 0.049907, 0.145825, -0.007271, 1.002495, 0.049906, 0.163491,
+ -0.008128, 1.002475, 0.049903, 0.181911, -0.008826, 1.002459, 0.049879, 0.200065, -0.009285,
+ 1.002443, 0.049824, 0.220025, -0.010966, 1.002450, 0.049897, 0.241581, -0.012025, 1.002463,
+ 0.049893, 0.264099, -0.013105, 1.002395, 0.049881, 0.287493, -0.014145, 1.002390, 0.049855,
+ 0.311399, -0.014925, 1.002414, 0.049769, 0.335096, -0.015239, 1.002363, 0.049591, 0.359815,
+ -0.017559, 1.002415, 0.049777, 0.386365, -0.018554, 1.002354, 0.049675, 0.413017, -0.019043,
+ 1.002297, 0.049444, 0.439519, -0.019815, 1.002284, 0.049253, 0.466938, -0.021741, 1.002307,
+ 0.049327, 0.494999, -0.021887, 1.002181, 0.048922, 0.522922, -0.022844, 1.002107, 0.048677,
+ 0.551270, -0.024014, 1.002101, 0.048478, 0.579771, -0.024156, 1.002060, 0.047904, 0.608156,
+ -0.025317, 1.002077, 0.047594, 0.636662, -0.025321, 1.001975, 0.046876, 0.664846, -0.026018,
+ 1.001992, 0.046354, 0.692877, -0.026041, 1.001846, 0.045504, 0.720316, -0.026252, 1.001846,
+ 0.044655, 0.747658, -0.026159, 1.001931, 0.043670, 0.774252, -0.026086, 1.001845, 0.042515,
+ 0.800179, -0.025653, 1.001794, 0.041211, 0.825525, -0.025170, 1.001787, 0.039823, 0.850013,
+ -0.024788, 1.001806, 0.038409, 0.873593, -0.023992, 1.001688, 0.036767, 0.896343, -0.022985,
+ 1.001666, 0.034900, 0.918062, -0.022005, 1.001548, 0.033010, 0.938928, -0.021110, 1.001503,
+ 0.031143, 0.958667, -0.019893, 1.001341, 0.029059, 0.977457, -0.018546, 1.001194, 0.026888,
+ 0.995243, -0.017152, 1.001095, 0.024713, 1.012023, -0.015750, 1.001100, 0.022496, 1.027614,
+ -0.014289, 1.000851, 0.020153, 1.042389, -0.012688, 1.000724, 0.017839, 1.056161, -0.011118,
+ 1.000572, 0.015529, 1.068968, -0.009540, 1.000407, 0.013240, 1.080866, -0.007963, 1.000258,
+ 0.010940, 1.091944, -0.006416, 1.000254, 0.008716, 1.102104, -0.004771, 1.000175, 0.006434,
+ 1.111571, -0.003056, 1.000148, 0.004169, 1.120084, -0.001458, 1.000050, 0.002033, 1.127981,
+ 0.000021, 0.999987, -0.000027, 0.000200, -0.000015, 1.005620, 0.074940, 0.000504, -0.000038,
+ 1.005650, 0.074939, 0.002016, -0.000151, 1.005613, 0.074939, 0.004535, -0.000340, 1.005618,
+ 0.074939, 0.008062, -0.000604, 1.005614, 0.074939, 0.012597, -0.000944, 1.005616, 0.074940,
+ 0.018141, -0.001359, 1.005558, 0.074939, 0.024695, -0.001851, 1.005495, 0.074940, 0.032253,
+ -0.002417, 1.005616, 0.074939, 0.040822, -0.003059, 1.005591, 0.074940, 0.050399, -0.003777,
+ 1.005596, 0.074940, 0.060989, -0.004570, 1.005599, 0.074939, 0.072591, -0.005440, 1.005616,
+ 0.074940, 0.085203, -0.006385, 1.005616, 0.074939, 0.098833, -0.007406, 1.005595, 0.074938,
+ 0.113481, -0.008502, 1.005605, 0.074938, 0.129147, -0.009674, 1.005605, 0.074937, 0.145817,
+ -0.010916, 1.005513, 0.074937, 0.163485, -0.012199, 1.005579, 0.074928, 0.181824, -0.013172,
+ 1.005552, 0.074885, 0.200274, -0.014100, 1.005524, 0.074825, 0.220017, -0.016464, 1.005529,
+ 0.074928, 0.241568, -0.018052, 1.005490, 0.074914, 0.264084, -0.019671, 1.005457, 0.074898,
+ 0.287450, -0.021217, 1.005431, 0.074860, 0.311281, -0.022341, 1.005395, 0.074717, 0.335228,
+ -0.023296, 1.005320, 0.074526, 0.360047, -0.025965, 1.005302, 0.074649, 0.386273, -0.027808,
+ 1.005285, 0.074575, 0.412855, -0.028504, 1.005167, 0.074237, 0.439705, -0.030007, 1.005129,
+ 0.074013, 0.466975, -0.032263, 1.005082, 0.073967, 0.494874, -0.032931, 1.004960, 0.073475,
+ 0.523066, -0.034348, 1.004834, 0.073084, 0.551198, -0.035739, 1.004806, 0.072657, 0.579889,
+ -0.036575, 1.004687, 0.072029, 0.608282, -0.037434, 1.004605, 0.071309, 0.636812, -0.038323,
+ 1.004589, 0.070507, 0.665010, -0.038676, 1.004403, 0.069424, 0.693063, -0.039237, 1.004340,
+ 0.068370, 0.720750, -0.039332, 1.004224, 0.066988, 0.747911, -0.039179, 1.004117, 0.065447,
+ 0.774576, -0.039110, 1.004035, 0.063838, 0.800737, -0.038542, 1.004027, 0.061923, 0.825966,
+ -0.037966, 1.003825, 0.059859, 0.850534, -0.036943, 1.003786, 0.057529, 0.874289, -0.035853,
+ 1.003560, 0.055081, 0.897152, -0.034730, 1.003549, 0.052476, 0.919029, -0.033242, 1.003454,
+ 0.049647, 0.939851, -0.031508, 1.003215, 0.046670, 0.959599, -0.029695, 1.002916, 0.043588,
+ 0.978293, -0.027845, 1.002720, 0.040401, 0.996085, -0.025775, 1.002445, 0.037060, 1.012768,
+ -0.023607, 1.002133, 0.033726, 1.028404, -0.021374, 1.001822, 0.030217, 1.043150, -0.019108,
+ 1.001602, 0.026820, 1.056760, -0.016823, 1.001274, 0.023372, 1.069471, -0.014378, 1.000964,
+ 0.019891, 1.081283, -0.011884, 1.000684, 0.016405, 1.092238, -0.009398, 1.000514, 0.012950,
+ 1.102384, -0.007030, 1.000319, 0.009579, 1.111737, -0.004751, 1.000225, 0.006384, 1.120274,
+ -0.002404, 1.000046, 0.003192, 1.128182, 0.000031, 1.000020, 0.000033, 0.000200, -0.000020,
+ 1.010006, 0.100065, 0.000504, -0.000050, 1.009927, 0.100065, 0.002016, -0.000202, 1.010026,
+ 0.100064, 0.004535, -0.000454, 1.010018, 0.100065, 0.008062, -0.000807, 1.009891, 0.100064,
+ 0.012599, -0.001261, 1.010175, 0.100064, 0.018141, -0.001815, 1.010067, 0.100065, 0.024692,
+ -0.002471, 1.010014, 0.100066, 0.032251, -0.003227, 1.009950, 0.100065, 0.040818, -0.004084,
+ 1.009963, 0.100067, 0.050401, -0.005043, 1.010032, 0.100064, 0.060988, -0.006102, 1.009979,
+ 0.100064, 0.072588, -0.007263, 1.009984, 0.100063, 0.085205, -0.008525, 1.010023, 0.100063,
+ 0.098832, -0.009888, 1.009960, 0.100062, 0.113479, -0.011352, 1.009974, 0.100063, 0.129142,
+ -0.012916, 1.009945, 0.100062, 0.145817, -0.014573, 1.009924, 0.100058, 0.163468, -0.016276,
+ 1.009912, 0.100050, 0.181674, -0.017411, 1.009859, 0.099975, 0.200435, -0.019002, 1.009842,
+ 0.099932, 0.220005, -0.021978, 1.009820, 0.100043, 0.241550, -0.024096, 1.009778, 0.100031,
+ 0.264058, -0.026250, 1.009765, 0.100002, 0.287399, -0.028286, 1.009724, 0.099939, 0.311134,
+ -0.029698, 1.009596, 0.099748, 0.335350, -0.031442, 1.009508, 0.099582, 0.360295, -0.034401,
+ 1.009475, 0.099613, 0.386112, -0.037030, 1.009329, 0.099558, 0.412733, -0.038163, 1.009250,
+ 0.099137, 0.439833, -0.040250, 1.009125, 0.098866, 0.467099, -0.042583, 1.009011, 0.098626,
+ 0.494828, -0.044299, 1.008803, 0.098149, 0.523217, -0.045876, 1.008712, 0.097600, 0.551338,
+ -0.047440, 1.008509, 0.096929, 0.579917, -0.048995, 1.008371, 0.096178, 0.608454, -0.049901,
+ 1.008212, 0.095145, 0.636785, -0.051224, 1.007963, 0.094151, 0.665220, -0.051675, 1.007741,
+ 0.092728, 0.693194, -0.052278, 1.007616, 0.091195, 0.721008, -0.052406, 1.007327, 0.089384,
+ 0.748196, -0.052529, 1.007219, 0.087461, 0.774975, -0.051950, 1.006851, 0.085133, 0.801129,
+ -0.051456, 1.006732, 0.082628, 0.826668, -0.050569, 1.006612, 0.079817, 0.851291, -0.049328,
+ 1.006374, 0.076710, 0.875056, -0.047988, 1.006183, 0.073481, 0.897872, -0.046149, 1.005742,
+ 0.069943, 0.919803, -0.044144, 1.005514, 0.066151, 0.940701, -0.042095, 1.005153, 0.062247,
+ 0.960580, -0.039730, 1.004843, 0.058158, 0.979427, -0.037104, 1.004535, 0.053850, 0.997157,
+ -0.034369, 1.004023, 0.049403, 1.013777, -0.031555, 1.003622, 0.044944, 1.029452, -0.028571,
+ 1.003212, 0.040414, 1.044029, -0.025416, 1.002698, 0.035723, 1.057586, -0.022217, 1.002202,
+ 0.031072, 1.070148, -0.019037, 1.001703, 0.026429, 1.081875, -0.015936, 1.001322, 0.021896,
+ 1.092789, -0.012734, 1.001053, 0.017288, 1.102704, -0.009454, 1.000604, 0.012841, 1.112011,
+ -0.006199, 1.000387, 0.008446, 1.120590, -0.003010, 1.000166, 0.004122, 1.128283, 0.000027,
+ 0.999956, -0.000038, 0.000200, -0.000025, 1.015664, 0.125315, 0.000504, -0.000063, 1.015664,
+ 0.125316, 0.002016, -0.000253, 1.015727, 0.125315, 0.004535, -0.000568, 1.015695, 0.125314,
+ 0.008063, -0.001010, 1.015823, 0.125316, 0.012599, -0.001579, 1.015867, 0.125315, 0.018141,
+ -0.002273, 1.015758, 0.125316, 0.024691, -0.003094, 1.015662, 0.125316, 0.032252, -0.004042,
+ 1.015674, 0.125316, 0.040820, -0.005115, 1.015678, 0.125316, 0.050400, -0.006316, 1.015684,
+ 0.125315, 0.060989, -0.007642, 1.015685, 0.125315, 0.072590, -0.009096, 1.015703, 0.125314,
+ 0.085203, -0.010676, 1.015654, 0.125314, 0.098833, -0.012383, 1.015670, 0.125315, 0.113477,
+ -0.014215, 1.015635, 0.125312, 0.129138, -0.016173, 1.015599, 0.125311, 0.145815, -0.018246,
+ 1.015610, 0.125306, 0.163450, -0.020360, 1.015564, 0.125294, 0.181595, -0.021807, 1.015460,
+ 0.125204, 0.200563, -0.023971, 1.015440, 0.125165, 0.220186, -0.027280, 1.015412, 0.125250,
+ 0.241528, -0.030164, 1.015342, 0.125267, 0.264020, -0.032847, 1.015269, 0.125233, 0.287311,
+ -0.035345, 1.015232, 0.125138, 0.310993, -0.037108, 1.015063, 0.124903, 0.335467, -0.039653,
+ 1.014970, 0.124749, 0.360497, -0.042914, 1.014819, 0.124702, 0.385986, -0.046142, 1.014685,
+ 0.124623, 0.412703, -0.048050, 1.014543, 0.124193, 0.439929, -0.050527, 1.014315, 0.123833,
+ 0.467163, -0.052880, 1.014087, 0.123375, 0.494824, -0.055672, 1.013898, 0.122982, 0.523222,
+ -0.057388, 1.013647, 0.122166, 0.551557, -0.059328, 1.013403, 0.121343, 0.579884, -0.061315,
+ 1.013059, 0.120430, 0.608619, -0.062531, 1.012745, 0.119140, 0.637014, -0.063778, 1.012425,
+ 0.117721, 0.665425, -0.064734, 1.012067, 0.116069, 0.693580, -0.065315, 1.011712, 0.114146,
+ 0.721194, -0.065535, 1.011200, 0.111846, 0.748586, -0.065501, 1.010896, 0.109309, 0.775437,
+ -0.065091, 1.010576, 0.106504, 0.801554, -0.064332, 1.010136, 0.103308, 0.827079, -0.063078,
+ 1.009629, 0.099695, 0.851693, -0.061728, 1.009233, 0.095946, 0.875586, -0.059853, 1.008726,
+ 0.091802, 0.898589, -0.057727, 1.008412, 0.087339, 0.920421, -0.055377, 1.007767, 0.082687,
+ 0.941533, -0.052571, 1.007529, 0.077716, 0.961426, -0.049544, 1.006929, 0.072574, 0.980287,
+ -0.046400, 1.006393, 0.067217, 0.998080, -0.042966, 1.005872, 0.061757, 1.014940, -0.039321,
+ 1.005346, 0.056072, 1.030455, -0.035585, 1.004609, 0.050410, 1.045078, -0.031823, 1.004151,
+ 0.044622, 1.058555, -0.027947, 1.003421, 0.038893, 1.071009, -0.023891, 1.002704, 0.032977,
+ 1.082594, -0.019822, 1.002023, 0.027290, 1.093265, -0.015765, 1.001403, 0.021543, 1.103132,
+ -0.011790, 1.000944, 0.016072, 1.112348, -0.007784, 1.000550, 0.010511, 1.120845, -0.003849,
+ 1.000224, 0.005174, 1.128573, 0.000057, 0.999975, -0.000039, 0.000200, -0.000030, 1.022609,
+ 0.150725, 0.000504, -0.000076, 1.022728, 0.150725, 0.002016, -0.000304, 1.022728, 0.150725,
+ 0.004535, -0.000684, 1.022733, 0.150725, 0.008062, -0.001215, 1.022715, 0.150725, 0.012598,
+ -0.001899, 1.022720, 0.150725, 0.018141, -0.002734, 1.022659, 0.150725, 0.024694, -0.003722,
+ 1.022801, 0.150724, 0.032254, -0.004861, 1.022779, 0.150726, 0.040815, -0.006152, 1.022693,
+ 0.150724, 0.050400, -0.007596, 1.022716, 0.150725, 0.060990, -0.009192, 1.022733, 0.150725,
+ 0.072587, -0.010939, 1.022630, 0.150723, 0.085203, -0.012839, 1.022676, 0.150725, 0.098828,
+ -0.014891, 1.022659, 0.150725, 0.113473, -0.017095, 1.022589, 0.150720, 0.129137, -0.019449,
+ 1.022572, 0.150716, 0.145803, -0.021938, 1.022508, 0.150712, 0.163417, -0.024443, 1.022471,
+ 0.150691, 0.181580, -0.026329, 1.022406, 0.150600, 0.200667, -0.028997, 1.022336, 0.150553,
+ 0.220429, -0.032584, 1.022296, 0.150610, 0.241497, -0.036260, 1.022202, 0.150658, 0.263975,
+ -0.039465, 1.022119, 0.150619, 0.287210, -0.042385, 1.021988, 0.150490, 0.310935, -0.044758,
+ 1.021771, 0.150241, 0.335556, -0.047922, 1.021658, 0.150076, 0.360667, -0.051493, 1.021437,
+ 0.149931, 0.386028, -0.054931, 1.021228, 0.149754, 0.412665, -0.058007, 1.021023, 0.149400,
+ 0.439951, -0.060813, 1.020723, 0.148913, 0.467262, -0.063461, 1.020332, 0.148319, 0.494972,
+ -0.066738, 1.020097, 0.147798, 0.523153, -0.068976, 1.019630, 0.146903, 0.551700, -0.071268,
+ 1.019245, 0.145863, 0.580046, -0.073439, 1.018797, 0.144695, 0.608649, -0.075193, 1.018201,
+ 0.143237, 0.637239, -0.076536, 1.017746, 0.141463, 0.665388, -0.077771, 1.017111, 0.139462,
+ 0.693755, -0.078344, 1.016609, 0.137082, 0.721345, -0.078817, 1.015863, 0.134403, 0.748879,
+ -0.078512, 1.015390, 0.131252, 0.775560, -0.078128, 1.014652, 0.127866, 0.801897, -0.077094,
+ 1.013877, 0.123928, 0.827193, -0.075863, 1.013021, 0.119733, 0.851990, -0.073973, 1.012395,
+ 0.115055, 0.875823, -0.071765, 1.011595, 0.110098, 0.898655, -0.069241, 1.010862, 0.104722,
+ 0.920915, -0.066232, 1.010185, 0.098991, 0.941969, -0.062980, 1.009588, 0.093044, 0.961882,
+ -0.059507, 1.008777, 0.086925, 0.980952, -0.055606, 1.008252, 0.080520, 0.998955, -0.051503,
+ 1.007633, 0.073890, 1.015756, -0.047292, 1.006908, 0.067302, 1.031571, -0.042804, 1.006338,
+ 0.060412, 1.046095, -0.038132, 1.005512, 0.053497, 1.059542, -0.033380, 1.004592, 0.046569,
+ 1.072006, -0.028613, 1.003731, 0.039679, 1.083348, -0.023811, 1.002871, 0.032772, 1.093969,
+ -0.018930, 1.002068, 0.025894, 1.103697, -0.014098, 1.001284, 0.019178, 1.112813, -0.009339,
+ 1.000820, 0.012652, 1.121193, -0.004661, 1.000324, 0.006226, 1.128930, 0.000052, 0.999988,
+ -0.000008, 0.000200, -0.000035, 1.030857, 0.176327, 0.000504, -0.000089, 1.031137, 0.176326,
+ 0.002016, -0.000355, 1.031049, 0.176325, 0.004535, -0.000800, 1.031105, 0.176326, 0.008062,
+ -0.001422, 1.030973, 0.176326, 0.012598, -0.002221, 1.031168, 0.176326, 0.018141, -0.003199,
+ 1.031093, 0.176326, 0.024695, -0.004354, 1.031297, 0.176326, 0.032253, -0.005687, 1.031091,
+ 0.176327, 0.040821, -0.007197, 1.031012, 0.176326, 0.050399, -0.008886, 1.031068, 0.176325,
+ 0.060987, -0.010752, 1.030967, 0.176323, 0.072588, -0.012797, 1.031028, 0.176324, 0.085200,
+ -0.015019, 1.030985, 0.176322, 0.098829, -0.017419, 1.030983, 0.176320, 0.113474, -0.019997,
+ 1.030953, 0.176317, 0.129133, -0.022748, 1.030891, 0.176312, 0.145800, -0.025655, 1.030825,
+ 0.176306, 0.163372, -0.028510, 1.030781, 0.176279, 0.181578, -0.030914, 1.030683, 0.176187,
+ 0.200761, -0.034076, 1.030574, 0.176139, 0.220645, -0.037985, 1.030476, 0.176160, 0.241473,
+ -0.042391, 1.030384, 0.176238, 0.263922, -0.046105, 1.030241, 0.176175, 0.287074, -0.049390,
+ 1.030049, 0.176013, 0.310915, -0.052511, 1.029839, 0.175776, 0.335604, -0.056236, 1.029608,
+ 0.175578, 0.360775, -0.060118, 1.029355, 0.175359, 0.386196, -0.063907, 1.029052, 0.175083,
+ 0.412599, -0.067997, 1.028766, 0.174791, 0.439916, -0.071088, 1.028326, 0.174174, 0.467444,
+ -0.074247, 1.027890, 0.173487, 0.495132, -0.077728, 1.027374, 0.172774, 0.523117, -0.080822,
+ 1.026763, 0.171824, 0.551783, -0.083228, 1.026205, 0.170554, 0.580234, -0.085682, 1.025614,
+ 0.169090, 0.608568, -0.087860, 1.024668, 0.167468, 0.637357, -0.089346, 1.023939, 0.165283,
+ 0.665507, -0.090704, 1.022946, 0.162966, 0.693704, -0.091388, 1.022010, 0.160131, 0.721396,
+ -0.091783, 1.021085, 0.156957, 0.748676, -0.091688, 1.019894, 0.153292, 0.775370, -0.090992,
+ 1.018608, 0.149158, 0.801547, -0.089881, 1.017646, 0.144551, 0.827013, -0.088267, 1.016355,
+ 0.139614, 0.851708, -0.086132, 1.015446, 0.134026, 0.875652, -0.083707, 1.014321, 0.128101,
+ 0.898703, -0.080619, 1.013454, 0.121841, 0.920904, -0.077280, 1.012634, 0.115379, 0.942077,
+ -0.073484, 1.011770, 0.108355, 0.962245, -0.069252, 1.010894, 0.101153, 0.981385, -0.064807,
+ 1.010114, 0.093666, 0.999379, -0.060080, 1.009294, 0.086007, 1.016494, -0.055007, 1.008591,
+ 0.078194, 1.032357, -0.049760, 1.007821, 0.070328, 1.047061, -0.044468, 1.006871, 0.062358,
+ 1.060675, -0.038960, 1.006062, 0.054279, 1.073032, -0.033343, 1.004911, 0.046158, 1.084293,
+ -0.027699, 1.003791, 0.038111, 1.094724, -0.022130, 1.002744, 0.030239, 1.104302, -0.016508,
+ 1.001815, 0.022397, 1.113290, -0.010846, 1.001083, 0.014747, 1.121649, -0.005294, 1.000490,
+ 0.007234, 1.129230, 0.000071, 0.999975, -0.000053, 0.000200, -0.000040, 1.040431, 0.202155,
+ 0.000504, -0.000102, 1.040912, 0.202154, 0.002016, -0.000407, 1.041328, 0.202152, 0.004535,
+ -0.000917, 1.040877, 0.202154, 0.008063, -0.001630, 1.040867, 0.202153, 0.012598, -0.002547,
+ 1.040870, 0.202153, 0.018140, -0.003667, 1.040808, 0.202153, 0.024692, -0.004991, 1.040861,
+ 0.202153, 0.032252, -0.006519, 1.040861, 0.202153, 0.040822, -0.008252, 1.040864, 0.202153,
+ 0.050397, -0.010187, 1.040717, 0.202151, 0.060988, -0.012327, 1.040791, 0.202152, 0.072582,
+ -0.014669, 1.040640, 0.202149, 0.085198, -0.017217, 1.040716, 0.202147, 0.098827, -0.019968,
+ 1.040748, 0.202141, 0.113467, -0.022921, 1.040632, 0.202142, 0.129129, -0.026074, 1.040606,
+ 0.202137, 0.145793, -0.029399, 1.040566, 0.202127, 0.163294, -0.032524, 1.040459, 0.202078,
+ 0.181589, -0.035552, 1.040315, 0.201996, 0.200844, -0.039208, 1.040221, 0.201948, 0.220835,
+ -0.043489, 1.040047, 0.201945, 0.241471, -0.048523, 1.039921, 0.202031, 0.263854, -0.052764,
+ 1.039756, 0.201957, 0.286935, -0.056387, 1.039497, 0.201743, 0.310902, -0.060338, 1.039252,
+ 0.201531, 0.335642, -0.064594, 1.038954, 0.201286, 0.360859, -0.068772, 1.038582, 0.200983,
+ 0.386419, -0.073086, 1.038160, 0.200651, 0.412588, -0.077887, 1.037724, 0.200343, 0.439836,
+ -0.081391, 1.037182, 0.199618, 0.467538, -0.085121, 1.036602, 0.198839, 0.495286, -0.088718,
+ 1.035893, 0.197895, 0.523231, -0.092514, 1.035121, 0.196887, 0.551730, -0.095238, 1.034127,
+ 0.195390, 0.580302, -0.097949, 1.033131, 0.193668, 0.608559, -0.100418, 1.031962, 0.191773,
+ 0.637224, -0.102129, 1.030838, 0.189319, 0.665597, -0.103578, 1.029511, 0.186529, 0.693535,
+ -0.104652, 1.028263, 0.183303, 0.721325, -0.104766, 1.026611, 0.179497, 0.748384, -0.104717,
+ 1.025128, 0.175283, 0.775058, -0.103846, 1.023385, 0.170493, 0.801387, -0.102728, 1.022236,
+ 0.165187, 0.826412, -0.100679, 1.019908, 0.159362, 0.851314, -0.098451, 1.018839, 0.153059,
+ 0.875100, -0.095363, 1.017306, 0.146284, 0.898280, -0.092008, 1.016151, 0.138975, 0.920450,
+ -0.088095, 1.014880, 0.131361, 0.941727, -0.083690, 1.013556, 0.123417, 0.962308, -0.079077,
+ 1.012998, 0.115201, 0.981364, -0.073894, 1.011841, 0.106711, 0.999798, -0.068435, 1.011021,
+ 0.098063, 1.016983, -0.062830, 1.010194, 0.089183, 1.033039, -0.056914, 1.009292, 0.080190,
+ 1.047994, -0.050721, 1.008474, 0.071010, 1.061580, -0.044454, 1.007386, 0.061867, 1.074023,
+ -0.038145, 1.006135, 0.052711, 1.085470, -0.031679, 1.004890, 0.043595, 1.095673, -0.025157,
+ 1.003627, 0.034506, 1.105000, -0.018702, 1.002331, 0.025468, 1.113795, -0.012458, 1.001278,
+ 0.016834, 1.122012, -0.006169, 1.000548, 0.008265, 1.129683, 0.000078, 0.999988, -0.000072,
+ 0.000200, -0.000046, 1.052496, 0.228243, 0.000504, -0.000115, 1.052079, 0.228243, 0.002016,
+ -0.000460, 1.052079, 0.228241, 0.004535, -0.001035, 1.052091, 0.228242, 0.008062, -0.001840,
+ 1.051962, 0.228242, 0.012598, -0.002875, 1.052087, 0.228242, 0.018141, -0.004140, 1.052088,
+ 0.228242, 0.024692, -0.005636, 1.052096, 0.228239, 0.032251, -0.007361, 1.052029, 0.228243,
+ 0.040820, -0.009316, 1.052038, 0.228241, 0.050399, -0.011501, 1.052042, 0.228239, 0.060990,
+ -0.013917, 1.052046, 0.228238, 0.072586, -0.016562, 1.051990, 0.228236, 0.085198, -0.019437,
+ 1.051946, 0.228234, 0.098824, -0.022542, 1.051879, 0.228229, 0.113467, -0.025875, 1.051841,
+ 0.228227, 0.129121, -0.029430, 1.051724, 0.228219, 0.145780, -0.033170, 1.051672, 0.228205,
+ 0.163222, -0.036567, 1.051556, 0.228143, 0.181604, -0.040245, 1.051382, 0.228069, 0.200913,
+ -0.044395, 1.051230, 0.228010, 0.221005, -0.049088, 1.051062, 0.227988, 0.241667, -0.054506,
+ 1.050881, 0.228044, 0.263777, -0.059437, 1.050643, 0.227986, 0.286841, -0.063590, 1.050312,
+ 0.227755, 0.310879, -0.068224, 1.050009, 0.227525, 0.335650, -0.072986, 1.049597, 0.227253,
+ 0.360869, -0.077435, 1.049121, 0.226845, 0.386609, -0.082385, 1.048587, 0.226466, 0.412742,
+ -0.087570, 1.047987, 0.226059, 0.439789, -0.091929, 1.047308, 0.225331, 0.467558, -0.096038,
+ 1.046423, 0.224409, 0.495406, -0.099938, 1.045481, 0.223288, 0.523417, -0.104050, 1.044512,
+ 0.222066, 0.551755, -0.107503, 1.043408, 0.220487, 0.580468, -0.110234, 1.042016, 0.218451,
+ 0.608904, -0.112993, 1.040535, 0.216200, 0.637230, -0.115173, 1.038934, 0.213458, 0.665566,
+ -0.116433, 1.036961, 0.210158, 0.693413, -0.117589, 1.035130, 0.206457, 0.721025, -0.117885,
+ 1.033080, 0.202197, 0.748054, -0.117606, 1.030752, 0.197296, 0.774631, -0.116771, 1.028608,
+ 0.191813, 0.800677, -0.115194, 1.026350, 0.185691, 0.826062, -0.113138, 1.024472, 0.179053,
+ 0.850590, -0.110359, 1.022174, 0.171839, 0.874550, -0.107072, 1.020381, 0.164067, 0.897567,
+ -0.103268, 1.018777, 0.155959, 0.919609, -0.098794, 1.016886, 0.147320, 0.941177, -0.094067,
+ 1.015880, 0.138365, 0.961752, -0.088670, 1.014616, 0.129051, 0.981518, -0.082965, 1.013807,
+ 0.119515, 0.999880, -0.076971, 1.012793, 0.109897, 1.017370, -0.070518, 1.011894, 0.099872,
+ 1.033661, -0.063830, 1.010943, 0.089883, 1.048672, -0.057040, 1.009802, 0.079691, 1.062479,
+ -0.049917, 1.008670, 0.069458, 1.075052, -0.042735, 1.007429, 0.059191, 1.086371, -0.035513,
+ 1.005991, 0.048894, 1.096623, -0.028359, 1.004468, 0.038770, 1.105871, -0.021111, 1.002927,
+ 0.028745, 1.114481, -0.013908, 1.001728, 0.018884, 1.122610, -0.006843, 1.000740, 0.009264,
+ 1.130165, 0.000062, 0.999983, -0.000006, 0.000200, -0.000051, 1.064931, 0.254630, 0.000504,
+ -0.000128, 1.064668, 0.254630, 0.002016, -0.000513, 1.064794, 0.254630, 0.004535, -0.001155,
+ 1.064851, 0.254630, 0.008063, -0.002053, 1.064966, 0.254630, 0.012598, -0.003208, 1.064840,
+ 0.254630, 0.018140, -0.004619, 1.064602, 0.254631, 0.024695, -0.006288, 1.064965, 0.254632,
+ 0.032251, -0.008211, 1.064795, 0.254630, 0.040821, -0.010393, 1.064802, 0.254628, 0.050398,
+ -0.012830, 1.064758, 0.254627, 0.060987, -0.015525, 1.064731, 0.254625, 0.072584, -0.018474,
+ 1.064615, 0.254621, 0.085199, -0.021682, 1.064672, 0.254619, 0.098826, -0.025144, 1.064630,
+ 0.254613, 0.113465, -0.028860, 1.064515, 0.254606, 0.129119, -0.032823, 1.064416, 0.254598,
+ 0.145767, -0.036969, 1.064347, 0.254579, 0.163190, -0.040754, 1.064132, 0.254506, 0.181622,
+ -0.044989, 1.063951, 0.254437, 0.200981, -0.049642, 1.063745, 0.254370, 0.221145, -0.054776,
+ 1.063547, 0.254324, 0.241896, -0.060538, 1.063289, 0.254346, 0.263684, -0.066113, 1.063013,
+ 0.254296, 0.286796, -0.070925, 1.062625, 0.254059, 0.310867, -0.076187, 1.062216, 0.253817,
+ 0.335644, -0.081406, 1.061703, 0.253481, 0.360917, -0.086336, 1.061066, 0.253005, 0.386786,
+ -0.091790, 1.060454, 0.252558, 0.412921, -0.097230, 1.059568, 0.252008, 0.439722, -0.102574,
+ 1.058706, 0.251323, 0.467559, -0.106972, 1.057682, 0.250239, 0.495605, -0.111329, 1.056612,
+ 0.248944, 0.523589, -0.115561, 1.055101, 0.247471, 0.551787, -0.119732, 1.053745, 0.245777,
+ 0.580426, -0.122711, 1.051829, 0.243448, 0.608778, -0.125436, 1.049642, 0.240769, 0.637069,
+ -0.127993, 1.047749, 0.237739, 0.665251, -0.129448, 1.045244, 0.233928, 0.692977, -0.130408,
+ 1.042279, 0.229640, 0.720346, -0.130931, 1.039693, 0.224829, 0.747365, -0.130392, 1.036675,
+ 0.219144, 0.773734, -0.129540, 1.033719, 0.212965, 0.799578, -0.127689, 1.030774, 0.206047,
+ 0.825002, -0.125456, 1.028551, 0.198576, 0.849564, -0.122291, 1.025800, 0.190471, 0.873412,
+ -0.118720, 1.023657, 0.181739, 0.896628, -0.114323, 1.021381, 0.172586, 0.918952, -0.109587,
+ 1.019674, 0.162914, 0.940602, -0.104093, 1.018126, 0.153039, 0.960917, -0.098187, 1.016339,
+ 0.142774, 0.980911, -0.091963, 1.015440, 0.132316, 0.999686, -0.085159, 1.014377, 0.121453,
+ 1.017538, -0.078139, 1.013498, 0.110527, 1.033918, -0.070797, 1.012332, 0.099437, 1.049390,
+ -0.063129, 1.011368, 0.088157, 1.063402, -0.055354, 1.010111, 0.076951, 1.076096, -0.047522,
+ 1.008774, 0.065616, 1.087562, -0.039447, 1.007202, 0.054310, 1.097591, -0.031359, 1.005346,
+ 0.042948, 1.106782, -0.023393, 1.003710, 0.031799, 1.115234, -0.015461, 1.002116, 0.020943,
+ 1.123166, -0.007589, 1.000858, 0.010288, 1.130796, 0.000104, 1.000032, -0.000024, 0.000200,
+ -0.000056, 1.078780, 0.281356, 0.000504, -0.000142, 1.079271, 0.281355, 0.002015, -0.000567,
+ 1.078635, 0.281355, 0.004535, -0.001276, 1.079164, 0.281356, 0.008064, -0.002269, 1.079300,
+ 0.281355, 0.012598, -0.003544, 1.079149, 0.281355, 0.018143, -0.005104, 1.079329, 0.281355,
+ 0.024691, -0.006947, 1.079073, 0.281353, 0.032254, -0.009074, 1.079253, 0.281354, 0.040822,
+ -0.011484, 1.079176, 0.281353, 0.050399, -0.014177, 1.079057, 0.281349, 0.060987, -0.017153,
+ 1.079007, 0.281347, 0.072586, -0.020412, 1.078998, 0.281343, 0.085203, -0.023956, 1.078962,
+ 0.281336, 0.098823, -0.027778, 1.078839, 0.281332, 0.113464, -0.031882, 1.078783, 0.281325,
+ 0.129114, -0.036255, 1.078633, 0.281315, 0.145748, -0.040790, 1.078545, 0.281287, 0.163179,
+ -0.045024, 1.078311, 0.281208, 0.181649, -0.049791, 1.078135, 0.281137, 0.201042, -0.054953,
+ 1.077845, 0.281063, 0.221267, -0.060551, 1.077576, 0.281006, 0.242114, -0.066663, 1.077257,
+ 0.280978, 0.263568, -0.072771, 1.076897, 0.280925, 0.286744, -0.078349, 1.076405, 0.280689,
+ 0.310840, -0.084201, 1.075898, 0.280418, 0.335612, -0.089846, 1.075287, 0.280020, 0.360975,
+ -0.095394, 1.074482, 0.279513, 0.386932, -0.101290, 1.073617, 0.278961, 0.413171, -0.107042,
+ 1.072719, 0.278283, 0.439886, -0.113083, 1.071698, 0.277547, 0.467535, -0.118010, 1.070213,
+ 0.276311, 0.495701, -0.122793, 1.068857, 0.274867, 0.523772, -0.127278, 1.067037, 0.273153,
+ 0.551849, -0.131671, 1.064923, 0.271176, 0.580338, -0.135293, 1.062749, 0.268626, 0.608771,
+ -0.138065, 1.059944, 0.265569, 0.636756, -0.140565, 1.056851, 0.262054, 0.664574, -0.142434,
+ 1.053461, 0.257807, 0.692151, -0.143237, 1.049910, 0.252930, 0.719376, -0.143717, 1.046426,
+ 0.247414, 0.745852, -0.143117, 1.042377, 0.241001, 0.772300, -0.141975, 1.038789, 0.233797,
+ 0.798050, -0.140114, 1.035290, 0.226218, 0.823370, -0.137379, 1.032374, 0.217785, 0.847735,
+ -0.134119, 1.028853, 0.208748, 0.871897, -0.129985, 1.026395, 0.198877, 0.894950, -0.125324,
+ 1.023787, 0.188803, 0.917909, -0.120007, 1.022073, 0.178493, 0.939567, -0.114099, 1.020098,
+ 0.167466, 0.960534, -0.107748, 1.018851, 0.156223, 0.980423, -0.100748, 1.017362, 0.144716,
+ 0.999334, -0.093494, 1.015961, 0.133028, 1.017561, -0.085728, 1.015059, 0.120953, 1.034225,
+ -0.077627, 1.013888, 0.108943, 1.049937, -0.069375, 1.012898, 0.096678, 1.064265, -0.060807,
+ 1.011635, 0.084350, 1.077188, -0.052052, 1.010095, 0.071964, 1.088637, -0.043304, 1.008399,
+ 0.059531, 1.098766, -0.034458, 1.006397, 0.047134, 1.107697, -0.025637, 1.004354, 0.034887,
+ 1.116055, -0.016932, 1.002611, 0.022948, 1.123819, -0.008437, 1.001023, 0.011386, 1.131333,
+ 0.000087, 0.999952, -0.000097, 0.000200, -0.000062, 1.095622, 0.308458, 0.000504, -0.000155,
+ 1.094863, 0.308458, 0.002016, -0.000622, 1.095169, 0.308458, 0.004535, -0.001399, 1.095156,
+ 0.308458, 0.008063, -0.002487, 1.095413, 0.308455, 0.012598, -0.003886, 1.095147, 0.308458,
+ 0.018141, -0.005596, 1.095150, 0.308457, 0.024692, -0.007616, 1.095140, 0.308457, 0.032252,
+ -0.009947, 1.095098, 0.308456, 0.040822, -0.012589, 1.095096, 0.308453, 0.050399, -0.015541,
+ 1.095070, 0.308451, 0.060985, -0.018803, 1.094922, 0.308448, 0.072583, -0.022375, 1.094902,
+ 0.308444, 0.085197, -0.026258, 1.094882, 0.308438, 0.098822, -0.030448, 1.094775, 0.308429,
+ 0.113460, -0.034944, 1.094641, 0.308419, 0.129112, -0.039731, 1.094530, 0.308403, 0.145711,
+ -0.044610, 1.094332, 0.308365, 0.163178, -0.049362, 1.094149, 0.308285, 0.181679, -0.054666,
+ 1.093876, 0.308210, 0.201109, -0.060336, 1.093603, 0.308132, 0.221388, -0.066414, 1.093250,
+ 0.308047, 0.242315, -0.072881, 1.092835, 0.307985, 0.263651, -0.079453, 1.092391, 0.307902,
+ 0.286720, -0.085882, 1.091866, 0.307688, 0.310817, -0.092274, 1.091225, 0.307379, 0.335562,
+ -0.098306, 1.090346, 0.306906, 0.361043, -0.104572, 1.089423, 0.306374, 0.387051, -0.110843,
+ 1.088437, 0.305710, 0.413405, -0.117062, 1.087228, 0.304906, 0.440122, -0.123501, 1.085879,
+ 0.304017, 0.467522, -0.129245, 1.084197, 0.302783, 0.495721, -0.134285, 1.082284, 0.301104,
+ 0.523925, -0.139143, 1.080109, 0.299142, 0.551814, -0.143638, 1.077043, 0.296825, 0.579878,
+ -0.147774, 1.074071, 0.294071, 0.608316, -0.150724, 1.070621, 0.290519, 0.636059, -0.153168,
+ 1.066390, 0.286424, 0.663481, -0.155139, 1.062069, 0.281559, 0.690753, -0.155944, 1.057211,
+ 0.276024, 0.717767, -0.156176, 1.052682, 0.269622, 0.743937, -0.155783, 1.047747, 0.262532,
+ 0.770214, -0.154245, 1.043510, 0.254609, 0.795542, -0.152192, 1.039121, 0.246007, 0.821099,
+ -0.149256, 1.035962, 0.236663, 0.845452, -0.145605, 1.032320, 0.226751, 0.869780, -0.141186,
+ 1.029390, 0.216165, 0.893141, -0.136137, 1.026485, 0.204937, 0.916034, -0.130332, 1.024389,
+ 0.193624, 0.938089, -0.124040, 1.022270, 0.181756, 0.959488, -0.117011, 1.020457, 0.169339,
+ 0.979594, -0.109617, 1.018871, 0.156875, 0.998912, -0.101562, 1.017533, 0.144288, 1.017100,
+ -0.093164, 1.016445, 0.131370, 1.034413, -0.084488, 1.015453, 0.118322, 1.050347, -0.075377,
+ 1.014259, 0.104963, 1.064958, -0.066108, 1.013057, 0.091722, 1.078045, -0.056702, 1.011491,
+ 0.078231, 1.089749, -0.047106, 1.009662, 0.064797, 1.099831, -0.037467, 1.007417, 0.051315,
+ 1.108789, -0.027990, 1.005144, 0.038064, 1.116865, -0.018464, 1.002925, 0.025008, 1.124609,
+ -0.009068, 1.001221, 0.012250, 1.132040, 0.000093, 0.999984, -0.000071, 0.000200, -0.000067,
+ 1.112554, 0.335981, 0.000504, -0.000169, 1.112660, 0.335981, 0.002016, -0.000677, 1.112827,
+ 0.335981, 0.004533, -0.001523, 1.112147, 0.335982, 0.008063, -0.002709, 1.112882, 0.335979,
+ 0.012598, -0.004233, 1.112891, 0.335980, 0.018141, -0.006095, 1.112882, 0.335980, 0.024693,
+ -0.008296, 1.112877, 0.335978, 0.032252, -0.010834, 1.112860, 0.335976, 0.040824, -0.013713,
+ 1.112965, 0.335974, 0.050398, -0.016927, 1.112753, 0.335971, 0.060991, -0.020482, 1.112826,
+ 0.335970, 0.072587, -0.024371, 1.112676, 0.335962, 0.085199, -0.028597, 1.112593, 0.335955,
+ 0.098822, -0.033159, 1.112453, 0.335943, 0.113461, -0.038052, 1.112329, 0.335930, 0.129108,
+ -0.043255, 1.112144, 0.335910, 0.145665, -0.048412, 1.111905, 0.335857, 0.163185, -0.053786,
+ 1.111668, 0.335781, 0.181710, -0.059608, 1.111345, 0.335696, 0.201166, -0.065794, 1.110979,
+ 0.335606, 0.221489, -0.072361, 1.110553, 0.335505, 0.242471, -0.079184, 1.110112, 0.335396,
+ 0.263900, -0.086213, 1.109584, 0.335271, 0.286688, -0.093491, 1.108927, 0.335089, 0.310773,
+ -0.100406, 1.108091, 0.334737, 0.335573, -0.106987, 1.107169, 0.334208, 0.361117, -0.113844,
+ 1.106097, 0.333600, 0.387175, -0.120463, 1.104826, 0.332828, 0.413665, -0.127245, 1.103415,
+ 0.331929, 0.440386, -0.133927, 1.101632, 0.330851, 0.467527, -0.140496, 1.099563, 0.329538,
+ 0.495630, -0.145874, 1.096956, 0.327618, 0.523864, -0.150997, 1.094201, 0.325390, 0.551705,
+ -0.155713, 1.090342, 0.322688, 0.579383, -0.159993, 1.086010, 0.319483, 0.607301, -0.163238,
+ 1.081226, 0.315522, 0.634873, -0.165667, 1.076065, 0.310840, 0.662028, -0.167606, 1.070466,
+ 0.305377, 0.688755, -0.168626, 1.064601, 0.299056, 0.715612, -0.168578, 1.059269, 0.291963,
+ 0.741604, -0.167961, 1.053648, 0.284018, 0.767757, -0.166439, 1.048928, 0.275474, 0.793264,
+ -0.164023, 1.044343, 0.266056, 0.818165, -0.160965, 1.039909, 0.255750, 0.843255, -0.156896,
+ 1.036180, 0.244843, 0.867249, -0.152262, 1.032303, 0.233464, 0.890994, -0.146655, 1.029365,
+ 0.221128, 0.913829, -0.140574, 1.026607, 0.208554, 0.936508, -0.133640, 1.024512, 0.195772,
+ 0.957720, -0.126220, 1.022421, 0.182420, 0.978940, -0.118164, 1.021293, 0.168852, 0.998285,
+ -0.109558, 1.019444, 0.155261, 1.016764, -0.100562, 1.017825, 0.141395, 1.034387, -0.091064,
+ 1.016996, 0.127311, 1.050916, -0.081468, 1.015945, 0.113089, 1.065652, -0.071463, 1.014547,
+ 0.098879, 1.079155, -0.061240, 1.013066, 0.084468, 1.090822, -0.050980, 1.010788, 0.069940,
+ 1.101100, -0.040549, 1.008563, 0.055475, 1.109824, -0.030101, 1.005950, 0.041033, 1.117828,
+ -0.019884, 1.003453, 0.027022, 1.125443, -0.009900, 1.001484, 0.013306, 1.132869, 0.000094,
+ 1.000004, -0.000046, 0.000200, -0.000073, 1.132849, 0.363970, 0.000504, -0.000183, 1.132155,
+ 0.363969, 0.002016, -0.000734, 1.132516, 0.363969, 0.004535, -0.001651, 1.132256, 0.363969,
+ 0.008062, -0.002934, 1.132318, 0.363966, 0.012597, -0.004585, 1.132386, 0.363968, 0.018141,
+ -0.006602, 1.132457, 0.363967, 0.024693, -0.008987, 1.132511, 0.363967, 0.032252, -0.011737,
+ 1.132488, 0.363965, 0.040819, -0.014853, 1.132241, 0.363959, 0.050398, -0.018336, 1.132372,
+ 0.363958, 0.060988, -0.022185, 1.132373, 0.363954, 0.072582, -0.026396, 1.132137, 0.363943,
+ 0.085195, -0.030973, 1.132071, 0.363935, 0.098822, -0.035913, 1.131978, 0.363922, 0.113461,
+ -0.041209, 1.131801, 0.363905, 0.129116, -0.046833, 1.131535, 0.363867, 0.145640, -0.052346,
+ 1.131290, 0.363814, 0.163199, -0.058275, 1.131046, 0.363734, 0.181742, -0.064623, 1.130671,
+ 0.363642, 0.201227, -0.071336, 1.130224, 0.363539, 0.221587, -0.078396, 1.129758, 0.363419,
+ 0.242625, -0.085545, 1.129213, 0.363256, 0.264183, -0.093110, 1.128549, 0.363097, 0.286668,
+ -0.101206, 1.127767, 0.362939, 0.310745, -0.108586, 1.126796, 0.362516, 0.335602, -0.115827,
+ 1.125686, 0.361953, 0.361202, -0.123212, 1.124451, 0.361275, 0.387298, -0.130294, 1.122861,
+ 0.360376, 0.413918, -0.137553, 1.121154, 0.359362, 0.440680, -0.144577, 1.118825, 0.358069,
+ 0.467667, -0.151558, 1.116002, 0.356581, 0.495449, -0.157621, 1.112778, 0.354531, 0.523514,
+ -0.162844, 1.108842, 0.351915, 0.551250, -0.167744, 1.104075, 0.348797, 0.578629, -0.172132,
+ 1.098733, 0.345222, 0.605757, -0.175733, 1.092224, 0.340665, 0.633392, -0.178109, 1.086201,
+ 0.335286, 0.660783, -0.180009, 1.080110, 0.329286, 0.687219, -0.181105, 1.073419, 0.322319,
+ 0.713873, -0.181046, 1.067410, 0.314616, 0.740094, -0.180219, 1.061414, 0.306014, 0.765233,
+ -0.178559, 1.055287, 0.296704, 0.790885, -0.175806, 1.049727, 0.286394, 0.815464, -0.172354,
+ 1.044519, 0.275189, 0.840259, -0.168048, 1.040375, 0.263441, 0.864285, -0.162904, 1.036010,
+ 0.250918, 0.888806, -0.157194, 1.033525, 0.237611, 0.911682, -0.150486, 1.029490, 0.223809,
+ 0.934481, -0.143212, 1.026778, 0.209705, 0.956337, -0.135233, 1.024632, 0.195281, 0.977380,
+ -0.126650, 1.022737, 0.180878, 0.997427, -0.117552, 1.021110, 0.166112, 1.016666, -0.107814,
+ 1.019869, 0.151231, 1.034337, -0.097814, 1.018543, 0.136375, 1.051082, -0.087330, 1.017476,
+ 0.121187, 1.066326, -0.076614, 1.016083, 0.106043, 1.079897, -0.065793, 1.014227, 0.090566,
+ 1.092136, -0.054654, 1.012334, 0.074988, 1.102315, -0.043516, 1.009627, 0.059577, 1.111105,
+ -0.032509, 1.006808, 0.044202, 1.118861, -0.021381, 1.003917, 0.028995, 1.126363, -0.010489,
+ 1.001670, 0.014269, 1.133598, 0.000083, 0.999989, -0.000035, 0.000200, -0.000079, 1.155026,
+ 0.392470, 0.000504, -0.000198, 1.154184, 0.392469, 0.002016, -0.000791, 1.153990, 0.392469,
+ 0.004535, -0.001780, 1.154045, 0.392469, 0.008063, -0.003164, 1.154007, 0.392466, 0.012598,
+ -0.004944, 1.154022, 0.392469, 0.018141, -0.007119, 1.154015, 0.392468, 0.024692, -0.009690,
+ 1.154017, 0.392466, 0.032254, -0.012656, 1.154069, 0.392465, 0.040826, -0.016018, 1.153980,
+ 0.392459, 0.050399, -0.019771, 1.153911, 0.392456, 0.060987, -0.023919, 1.153860, 0.392447,
+ 0.072588, -0.028461, 1.153777, 0.392442, 0.085197, -0.033393, 1.153582, 0.392428, 0.098822,
+ -0.038716, 1.153434, 0.392412, 0.113462, -0.044422, 1.153271, 0.392390, 0.129101, -0.050455,
+ 1.153019, 0.392359, 0.145642, -0.056392, 1.152721, 0.392283, 0.163223, -0.062859, 1.152404,
+ 0.392201, 0.181779, -0.069721, 1.151941, 0.392099, 0.201289, -0.076968, 1.151422, 0.391978,
+ 0.221678, -0.084518, 1.150861, 0.391833, 0.242752, -0.092017, 1.150156, 0.391618, 0.264474,
+ -0.100184, 1.149402, 0.391421, 0.286768, -0.108921, 1.148545, 0.391249, 0.310719, -0.116815,
+ 1.147388, 0.390773, 0.335638, -0.124785, 1.146042, 0.390168, 0.361240, -0.132630, 1.144529,
+ 0.389394, 0.387443, -0.140298, 1.142602, 0.388391, 0.414067, -0.147913, 1.140361, 0.387199,
+ 0.440904, -0.155362, 1.137612, 0.385742, 0.467771, -0.162574, 1.133659, 0.383926, 0.494907,
+ -0.169312, 1.129246, 0.381715, 0.522801, -0.174778, 1.124228, 0.378678, 0.550751, -0.179824,
+ 1.118697, 0.375158, 0.578018, -0.184284, 1.112019, 0.370851, 0.605291, -0.188215, 1.105151,
+ 0.365928, 0.632269, -0.190760, 1.097677, 0.360114, 0.659432, -0.192457, 1.090816, 0.353498,
+ 0.685839, -0.193458, 1.083286, 0.346094, 0.711876, -0.193502, 1.076245, 0.337754, 0.738184,
+ -0.192371, 1.069684, 0.328412, 0.763723, -0.190531, 1.063249, 0.318164, 0.789192, -0.187726,
+ 1.057265, 0.306900, 0.813744, -0.183783, 1.051177, 0.295021, 0.838408, -0.179328, 1.045902,
+ 0.282144, 0.862116, -0.173573, 1.040853, 0.268438, 0.885636, -0.167350, 1.036515, 0.254108,
+ 0.909342, -0.160229, 1.033269, 0.239082, 0.931962, -0.152529, 1.029627, 0.224024, 0.954671,
+ -0.144080, 1.027507, 0.208393, 0.975707, -0.135023, 1.024657, 0.192630, 0.996644, -0.125258,
+ 1.022998, 0.176741, 1.015817, -0.115089, 1.021234, 0.160926, 1.034301, -0.104317, 1.020025,
+ 0.145042, 1.051131, -0.093218, 1.018739, 0.129052, 1.066836, -0.081828, 1.017419, 0.112905,
+ 1.081027, -0.070132, 1.015714, 0.096578, 1.093225, -0.058382, 1.013465, 0.080077, 1.103691,
+ -0.046527, 1.010853, 0.063580, 1.112431, -0.034624, 1.007702, 0.047118, 1.120035, -0.022913,
+ 1.004551, 0.031018, 1.127336, -0.011284, 1.001924, 0.015283, 1.134510, 0.000170, 0.999937,
+ -0.000058, 0.000200, -0.000084, 1.177044, 0.421534, 0.000504, -0.000212, 1.177312, 0.421533,
+ 0.002016, -0.000850, 1.177730, 0.421533, 0.004535, -0.001912, 1.177722, 0.421533, 0.008063,
+ -0.003399, 1.177844, 0.421529, 0.012598, -0.005310, 1.177768, 0.421533, 0.018141, -0.007646,
+ 1.177730, 0.421531, 0.024692, -0.010407, 1.177663, 0.421530, 0.032252, -0.013592, 1.177681,
+ 0.421527, 0.040821, -0.017201, 1.177562, 0.421524, 0.050401, -0.021234, 1.177445, 0.421516,
+ 0.060988, -0.025688, 1.177461, 0.421509, 0.072590, -0.030565, 1.177364, 0.421498, 0.085200,
+ -0.035860, 1.177205, 0.421482, 0.098823, -0.041572, 1.177011, 0.421462, 0.113465, -0.047694,
+ 1.176794, 0.421436, 0.129094, -0.054122, 1.176504, 0.421396, 0.145652, -0.060530, 1.176203,
+ 0.421311, 0.163245, -0.067517, 1.175805, 0.421218, 0.181825, -0.074919, 1.175271, 0.421108,
+ 0.201360, -0.082700, 1.174717, 0.420974, 0.221773, -0.090727, 1.174021, 0.420795, 0.242908,
+ -0.098719, 1.173173, 0.420536, 0.264742, -0.107417, 1.172285, 0.420296, 0.287091, -0.116601,
+ 1.171326, 0.420065, 0.310723, -0.125265, 1.169907, 0.419582, 0.335685, -0.133876, 1.168352,
+ 0.418912, 0.361285, -0.142140, 1.166322, 0.418006, 0.387562, -0.150436, 1.164136, 0.416899,
+ 0.414175, -0.158388, 1.161162, 0.415513, 0.441021, -0.166258, 1.157608, 0.413836, 0.467698,
+ -0.173720, 1.152519, 0.411702, 0.494730, -0.180843, 1.147020, 0.409102, 0.522524, -0.186906,
+ 1.141256, 0.405789, 0.550055, -0.192004, 1.134114, 0.401759, 0.577512, -0.196588, 1.127086,
+ 0.397153, 0.604348, -0.200420, 1.119029, 0.391767, 0.630970, -0.203320, 1.110308, 0.385573,
+ 0.658023, -0.204883, 1.102643, 0.378245, 0.684422, -0.205716, 1.094573, 0.370191, 0.710405,
+ -0.205767, 1.086405, 0.361231, 0.736417, -0.204513, 1.078712, 0.351106, 0.761836, -0.202281,
+ 1.071619, 0.340096, 0.787140, -0.199395, 1.064873, 0.328139, 0.812197, -0.195185, 1.058313,
+ 0.315044, 0.836342, -0.190191, 1.052085, 0.300933, 0.860311, -0.184343, 1.046705, 0.286411,
+ 0.883597, -0.177415, 1.041072, 0.270897, 0.906852, -0.170003, 1.036797, 0.254825, 0.929991,
+ -0.161592, 1.033264, 0.238176, 0.952478, -0.152792, 1.030250, 0.221581, 0.974216, -0.143032,
+ 1.027331, 0.204378, 0.995372, -0.132922, 1.025135, 0.187470, 1.015330, -0.122009, 1.023250,
+ 0.170538, 1.034070, -0.110740, 1.022021, 0.153777, 1.051295, -0.099016, 1.020271, 0.136916,
+ 1.067460, -0.086920, 1.018948, 0.119880, 1.082022, -0.074729, 1.017336, 0.102565, 1.094378,
+ -0.062036, 1.014820, 0.084994, 1.104998, -0.049413, 1.011999, 0.067650, 1.113773, -0.036812,
+ 1.008711, 0.050148, 1.121263, -0.024274, 1.005141, 0.032976, 1.128420, -0.012038, 1.002196,
+ 0.016239, 1.135496, 0.000106, 1.000042, -0.000062, 0.000200, -0.000090, 1.203048, 0.451217,
+ 0.000504, -0.000227, 1.203226, 0.451215, 0.002016, -0.000909, 1.203450, 0.451215, 0.004535,
+ -0.002046, 1.203569, 0.451215, 0.008062, -0.003638, 1.203609, 0.451209, 0.012598, -0.005684,
+ 1.203580, 0.451214, 0.018141, -0.008185, 1.203515, 0.451212, 0.024694, -0.011141, 1.203618,
+ 0.451211, 0.032253, -0.014549, 1.203609, 0.451207, 0.040815, -0.018409, 1.203302, 0.451203,
+ 0.050401, -0.022727, 1.203454, 0.451195, 0.060990, -0.027495, 1.203480, 0.451188, 0.072591,
+ -0.032713, 1.203220, 0.451172, 0.085203, -0.038378, 1.203058, 0.451154, 0.098829, -0.044489,
+ 1.202838, 0.451130, 0.113466, -0.051031, 1.202530, 0.451098, 0.129084, -0.057808, 1.202270,
+ 0.451041, 0.145669, -0.064769, 1.201904, 0.450956, 0.163278, -0.072278, 1.201411, 0.450853,
+ 0.181880, -0.080224, 1.200825, 0.450721, 0.201436, -0.088537, 1.200164, 0.450566, 0.221865,
+ -0.097009, 1.199335, 0.450351, 0.243083, -0.105591, 1.198383, 0.450062, 0.265033, -0.114818,
+ 1.197380, 0.449769, 0.287456, -0.124372, 1.196137, 0.449438, 0.310758, -0.133892, 1.194554,
+ 0.448974, 0.335721, -0.143052, 1.192649, 0.448216, 0.361348, -0.151868, 1.190233, 0.447202,
+ 0.387573, -0.160644, 1.187211, 0.445926, 0.414159, -0.169028, 1.183452, 0.444313, 0.440950,
+ -0.177169, 1.178562, 0.442315, 0.467998, -0.185090, 1.173540, 0.439960, 0.494566, -0.192396,
+ 1.166344, 0.436989, 0.521730, -0.198915, 1.159283, 0.433439, 0.549405, -0.204240, 1.151503,
+ 0.428984, 0.576755, -0.208861, 1.143004, 0.423839, 0.603635, -0.212734, 1.134099, 0.418012,
+ 0.629979, -0.215712, 1.124555, 0.411445, 0.656597, -0.217385, 1.115293, 0.403628, 0.683317,
+ -0.218093, 1.106460, 0.394639, 0.708990, -0.217835, 1.097389, 0.385012, 0.734898, -0.216774,
+ 1.088940, 0.373999, 0.760342, -0.214120, 1.080385, 0.362128, 0.785517, -0.210821, 1.072959,
+ 0.349184, 0.809933, -0.206443, 1.065450, 0.335080, 0.834339, -0.200942, 1.058701, 0.320257,
+ 0.858793, -0.194938, 1.052711, 0.304133, 0.882300, -0.187615, 1.047044, 0.287771, 0.905560,
+ -0.179626, 1.042083, 0.270571, 0.927916, -0.170753, 1.037077, 0.252741, 0.950415, -0.161270,
+ 1.033200, 0.234656, 0.972920, -0.151239, 1.030418, 0.216652, 0.993893, -0.140358, 1.027479,
+ 0.198252, 1.014204, -0.128963, 1.024897, 0.180113, 1.033878, -0.117128, 1.023648, 0.162282,
+ 1.051754, -0.104678, 1.022230, 0.144366, 1.067924, -0.092000, 1.020453, 0.126455, 1.082643,
+ -0.078837, 1.018518, 0.108194, 1.095503, -0.065669, 1.016199, 0.089966, 1.106290, -0.052345,
+ 1.013113, 0.071530, 1.115219, -0.039024, 1.009636, 0.053158, 1.122587, -0.025789, 1.005801,
+ 0.034959, 1.129461, -0.012622, 1.002442, 0.017222, 1.136468, 0.000152, 0.999964, -0.000065,
+ 0.000200, -0.000096, 1.231156, 0.481574, 0.000504, -0.000243, 1.232187, 0.481572, 0.002016,
+ -0.000971, 1.231948, 0.481572, 0.004535, -0.002184, 1.231919, 0.481572, 0.008061, -0.003882,
+ 1.231453, 0.481566, 0.012597, -0.006066, 1.231800, 0.481572, 0.018142, -0.008736, 1.231756,
+ 0.481569, 0.024693, -0.011889, 1.232062, 0.481570, 0.032254, -0.015528, 1.231915, 0.481563,
+ 0.040822, -0.019650, 1.231863, 0.481559, 0.050402, -0.024255, 1.231737, 0.481550, 0.060992,
+ -0.029342, 1.231678, 0.481537, 0.072592, -0.034908, 1.231537, 0.481521, 0.085207, -0.040953,
+ 1.231336, 0.481499, 0.098834, -0.047469, 1.231071, 0.481469, 0.113474, -0.054441, 1.230757,
+ 0.481431, 0.129077, -0.061556, 1.230424, 0.481359, 0.145691, -0.069091, 1.230022, 0.481269,
+ 0.163321, -0.077151, 1.229461, 0.481156, 0.181936, -0.085636, 1.228718, 0.481011, 0.201516,
+ -0.094484, 1.228023, 0.480830, 0.221963, -0.103362, 1.227057, 0.480562, 0.243264, -0.112628,
+ 1.225997, 0.480247, 0.265291, -0.122366, 1.224744, 0.479891, 0.287824, -0.132256, 1.223255,
+ 0.479461, 0.310927, -0.142614, 1.221348, 0.478978, 0.335749, -0.152326, 1.218953, 0.478132,
+ 0.361361, -0.161747, 1.215806, 0.476971, 0.387480, -0.170879, 1.211853, 0.475477, 0.414231,
+ -0.179865, 1.207783, 0.473686, 0.441065, -0.188331, 1.202051, 0.471415, 0.467923, -0.196454,
+ 1.195463, 0.468647, 0.494526, -0.204048, 1.187542, 0.465459, 0.521318, -0.211020, 1.179235,
+ 0.461650, 0.548654, -0.216520, 1.170110, 0.456868, 0.575778, -0.221098, 1.160163, 0.451227,
+ 0.602610, -0.224923, 1.149751, 0.444866, 0.628891, -0.227895, 1.139169, 0.437577, 0.655635,
+ -0.230020, 1.129736, 0.429369, 0.682115, -0.230419, 1.119516, 0.419673, 0.707514, -0.229789,
+ 1.108277, 0.409143, 0.733169, -0.228520, 1.099159, 0.397296, 0.758342, -0.225793, 1.089839,
+ 0.384578, 0.783477, -0.222049, 1.081428, 0.370323, 0.808497, -0.217562, 1.073742, 0.355253,
+ 0.832790, -0.211697, 1.065850, 0.339282, 0.856677, -0.204989, 1.058834, 0.322181, 0.880662,
+ -0.197653, 1.053291, 0.304610, 0.903474, -0.188858, 1.046822, 0.286042, 0.926313, -0.179746,
+ 1.041663, 0.267224, 0.948458, -0.169542, 1.036532, 0.247978, 0.970873, -0.159005, 1.033008,
+ 0.228535, 0.992958, -0.147658, 1.029844, 0.208819, 1.013413, -0.135771, 1.026930, 0.189486,
+ 1.033483, -0.123256, 1.025545, 0.170422, 1.051872, -0.110401, 1.023935, 0.152075, 1.068396,
+ -0.096860, 1.022092, 0.133169, 1.083731, -0.083259, 1.020221, 0.114022, 1.096849, -0.069266,
+ 1.017663, 0.094772, 1.107864, -0.055203, 1.014524, 0.075432, 1.116600, -0.041097, 1.010514,
+ 0.055980, 1.123871, -0.027083, 1.006313, 0.036839, 1.130718, -0.013510, 1.002778, 0.018156,
+ 1.137649, 0.000154, 1.000033, -0.000028, 0.000200, -0.000103, 1.264025, 0.512670, 0.000504,
+ -0.000258, 1.262437, 0.512667, 0.002016, -0.001033, 1.262691, 0.512668, 0.004535, -0.002325,
+ 1.262834, 0.512667, 0.008063, -0.004133, 1.262783, 0.512659, 0.012598, -0.006458, 1.262803,
+ 0.512666, 0.018141, -0.009299, 1.262720, 0.512665, 0.024683, -0.012652, 1.262061, 0.512655,
+ 0.032257, -0.016532, 1.262858, 0.512656, 0.040826, -0.020919, 1.262709, 0.512649, 0.050403,
+ -0.025820, 1.262685, 0.512639, 0.060993, -0.031233, 1.262544, 0.512625, 0.072597, -0.037157,
+ 1.262435, 0.512607, 0.085211, -0.043587, 1.262209, 0.512581, 0.098842, -0.050520, 1.261907,
+ 0.512544, 0.113484, -0.057926, 1.261575, 0.512500, 0.129097, -0.065460, 1.261293, 0.512420,
+ 0.145727, -0.073543, 1.260736, 0.512316, 0.163375, -0.082134, 1.260117, 0.512190, 0.182011,
+ -0.091173, 1.259299, 0.512024, 0.201598, -0.100540, 1.258381, 0.511810, 0.222084, -0.109931,
+ 1.257293, 0.511505, 0.243446, -0.119838, 1.256050, 0.511151, 0.265574, -0.130090, 1.254607,
+ 0.510724, 0.288230, -0.140421, 1.252808, 0.510191, 0.311336, -0.151343, 1.250489, 0.509627,
+ 0.335719, -0.161689, 1.247279, 0.508688, 0.361314, -0.171748, 1.243467, 0.507393, 0.387541,
+ -0.181399, 1.239145, 0.505758, 0.414204, -0.190768, 1.233760, 0.503676, 0.441092, -0.199659,
+ 1.227433, 0.501129, 0.467789, -0.207934, 1.219247, 0.498078, 0.494454, -0.215747, 1.210441,
+ 0.494630, 0.520950, -0.222869, 1.200559, 0.490467, 0.547802, -0.228881, 1.189872, 0.485444,
+ 0.575563, -0.233760, 1.180081, 0.479268, 0.602426, -0.237566, 1.168544, 0.472272, 0.628772,
+ -0.240447, 1.156546, 0.464390, 0.654963, -0.242427, 1.145123, 0.455345, 0.681384, -0.242980,
+ 1.134322, 0.444885, 0.707173, -0.242150, 1.122665, 0.433338, 0.732477, -0.240435, 1.111733,
+ 0.420647, 0.757567, -0.237806, 1.101271, 0.406799, 0.782341, -0.233503, 1.091341, 0.391761,
+ 0.806690, -0.228346, 1.082042, 0.375576, 0.830804, -0.222386, 1.073504, 0.358545, 0.854940,
+ -0.215141, 1.065880, 0.340431, 0.878709, -0.207207, 1.058850, 0.321690, 0.901928, -0.198273,
+ 1.052588, 0.301930, 0.924845, -0.188476, 1.046521, 0.281513, 0.946932, -0.177996, 1.040966,
+ 0.261234, 0.969256, -0.166644, 1.036670, 0.240356, 0.991323, -0.154968, 1.032694, 0.219748,
+ 1.013013, -0.142425, 1.030061, 0.199103, 1.032845, -0.129456, 1.027254, 0.178936, 1.051887,
+ -0.115763, 1.025497, 0.159243, 1.069179, -0.101851, 1.023807, 0.139560, 1.084499, -0.087357,
+ 1.021441, 0.119607, 1.097921, -0.072796, 1.018780, 0.099501, 1.109281, -0.058037, 1.015566,
+ 0.079211, 1.118194, -0.043226, 1.011494, 0.058873, 1.125351, -0.028633, 1.007089, 0.038736,
+ 1.132002, -0.013996, 1.003014, 0.019063, 1.138951, 0.000132, 1.000036, -0.000007, 0.000200,
+ -0.000109, 1.296791, 0.544571, 0.000504, -0.000274, 1.296055, 0.544568, 0.002016, -0.001098,
+ 1.297239, 0.544568, 0.004535, -0.002470, 1.296600, 0.544568, 0.008062, -0.004390, 1.296368,
+ 0.544559, 0.012597, -0.006860, 1.296454, 0.544566, 0.018141, -0.009878, 1.296522, 0.544565,
+ 0.024693, -0.013444, 1.296536, 0.544560, 0.032256, -0.017559, 1.296638, 0.544557, 0.040824,
+ -0.022218, 1.296491, 0.544547, 0.050408, -0.027426, 1.296552, 0.544532, 0.060997, -0.033173,
+ 1.296283, 0.544518, 0.072600, -0.039463, 1.296113, 0.544496, 0.085220, -0.046292, 1.295894,
+ 0.544466, 0.098851, -0.053648, 1.295545, 0.544422, 0.113496, -0.061487, 1.295201, 0.544371,
+ 0.129112, -0.069467, 1.294754, 0.544273, 0.145765, -0.078092, 1.294209, 0.544160, 0.163431,
+ -0.087231, 1.293534, 0.544017, 0.182088, -0.096837, 1.292580, 0.543828, 0.201698, -0.106713,
+ 1.291586, 0.543585, 0.222231, -0.116699, 1.290325, 0.543238, 0.243653, -0.127208, 1.288888,
+ 0.542836, 0.265855, -0.137949, 1.287131, 0.542329, 0.288623, -0.148847, 1.284936, 0.541700,
+ 0.311830, -0.160204, 1.282109, 0.540997, 0.335728, -0.171324, 1.278036, 0.540045, 0.361403,
+ -0.181915, 1.273912, 0.538603, 0.387647, -0.192124, 1.268881, 0.536741, 0.414217, -0.201807,
+ 1.262363, 0.534432, 0.441090, -0.211093, 1.254755, 0.531623, 0.467823, -0.219678, 1.245456,
+ 0.528314, 0.494361, -0.227581, 1.234953, 0.524391, 0.521264, -0.235087, 1.224839, 0.519902,
+ 0.547881, -0.241508, 1.213175, 0.514574, 0.574965, -0.246315, 1.200505, 0.507837, 0.601847,
+ -0.250061, 1.187901, 0.500286, 0.628207, -0.252822, 1.174601, 0.491502, 0.654445, -0.254691,
+ 1.161944, 0.481726, 0.680175, -0.255318, 1.149305, 0.470727, 0.706168, -0.254257, 1.136708,
+ 0.458045, 0.731458, -0.252100, 1.124047, 0.444438, 0.756378, -0.249115, 1.112942, 0.429611,
+ 0.781311, -0.244899, 1.101800, 0.413501, 0.805755, -0.239225, 1.091662, 0.395889, 0.829867,
+ -0.232830, 1.082291, 0.377860, 0.853067, -0.225193, 1.072820, 0.358704, 0.877084, -0.216648,
+ 1.065415, 0.338413, 0.900123, -0.207390, 1.058403, 0.317596, 0.923370, -0.197095, 1.051412,
+ 0.296301, 0.946021, -0.186084, 1.045877, 0.274498, 0.967669, -0.174262, 1.040316, 0.252565,
+ 0.989761, -0.161814, 1.035489, 0.230312, 1.012163, -0.149076, 1.032540, 0.208746, 1.032547,
+ -0.135299, 1.029598, 0.187180, 1.052032, -0.121277, 1.027355, 0.166482, 1.069907, -0.106582,
+ 1.025622, 0.145939, 1.085563, -0.091589, 1.023244, 0.125362, 1.099447, -0.076263, 1.020661,
+ 0.104087, 1.110848, -0.060825, 1.017035, 0.083036, 1.119923, -0.045319, 1.012675, 0.061719,
+ 1.126805, -0.029852, 1.007668, 0.040583, 1.133282, -0.014846, 1.003335, 0.019969, 1.140128,
+ 0.000149, 1.000024, -0.000037, 0.000200, -0.000116, 1.334863, 0.577350, 0.000504, -0.000291,
+ 1.333350, 0.577348, 0.002015, -0.001164, 1.332853, 0.577347, 0.004535, -0.002618, 1.333295,
+ 0.577347, 0.008062, -0.004655, 1.333189, 0.577336, 0.012598, -0.007273, 1.333309, 0.577345,
+ 0.018141, -0.010472, 1.333274, 0.577342, 0.024694, -0.014253, 1.333231, 0.577339, 0.032254,
+ -0.018614, 1.333265, 0.577332, 0.040827, -0.023556, 1.333261, 0.577321, 0.050400, -0.029069,
+ 1.332893, 0.577309, 0.061000, -0.035166, 1.332998, 0.577288, 0.072608, -0.041833, 1.332901,
+ 0.577263, 0.085227, -0.049067, 1.332603, 0.577226, 0.098864, -0.056860, 1.332264, 0.577177,
+ 0.113507, -0.065114, 1.331825, 0.577109, 0.129146, -0.073610, 1.331311, 0.577005, 0.145808,
+ -0.082766, 1.330639, 0.576872, 0.163494, -0.092458, 1.329878, 0.576709, 0.182176, -0.102639,
+ 1.328889, 0.576501, 0.201804, -0.112983, 1.327710, 0.576207, 0.222394, -0.123650, 1.326256,
+ 0.575823, 0.243881, -0.134780, 1.324593, 0.575363, 0.266122, -0.145931, 1.322426, 0.574751,
+ 0.289043, -0.157500, 1.319837, 0.574033, 0.312330, -0.169208, 1.316301, 0.573181, 0.336120,
+ -0.181125, 1.312251, 0.572188, 0.361506, -0.192232, 1.307003, 0.570631, 0.387757, -0.202981,
+ 1.301068, 0.568558, 0.414365, -0.213160, 1.293695, 0.566027, 0.440986, -0.222617, 1.283958,
+ 0.562942, 0.467943, -0.231583, 1.274057, 0.559219, 0.494821, -0.239881, 1.262864, 0.554913,
+ 0.521486, -0.247336, 1.250633, 0.549953, 0.547884, -0.253921, 1.237448, 0.544251, 0.574582,
+ -0.259099, 1.223164, 0.537120, 0.601342, -0.262695, 1.208784, 0.528650, 0.627861, -0.265337,
+ 1.194424, 0.518978, 0.653745, -0.266872, 1.179361, 0.508525, 0.679348, -0.267403, 1.165010,
+ 0.496705, 0.705068, -0.266429, 1.151693, 0.482926, 0.730312, -0.263829, 1.137584, 0.468519,
+ 0.755576, -0.260491, 1.125328, 0.452213, 0.780371, -0.256166, 1.113759, 0.435127, 0.804632,
+ -0.250079, 1.101656, 0.416833, 0.828983, -0.243181, 1.091235, 0.397009, 0.852585, -0.235383,
+ 1.081475, 0.376647, 0.875237, -0.226031, 1.071806, 0.355506, 0.899152, -0.216343, 1.064453,
+ 0.333133, 0.922121, -0.205772, 1.057161, 0.311073, 0.944523, -0.193980, 1.050447, 0.287781,
+ 0.967313, -0.181920, 1.044531, 0.264350, 0.989042, -0.168822, 1.039312, 0.241128, 1.010881,
+ -0.155350, 1.035298, 0.218138, 1.032368, -0.141231, 1.032073, 0.195579, 1.052254, -0.126521,
+ 1.029395, 0.173399, 1.070207, -0.111243, 1.026938, 0.151866, 1.086528, -0.095617, 1.024957,
+ 0.130711, 1.100670, -0.079687, 1.021924, 0.108865, 1.112461, -0.063593, 1.018281, 0.086760,
+ 1.121588, -0.047313, 1.013747, 0.064575, 1.128522, -0.031385, 1.008433, 0.042499, 1.134759,
+ -0.015356, 1.003569, 0.020840, 1.141448, 0.000114, 0.999978, -0.000056, 0.000200, -0.000122,
+ 1.372763, 0.611086, 0.000503, -0.000308, 1.371456, 0.611084, 0.002016, -0.001232, 1.373440,
+ 0.611084, 0.004535, -0.002771, 1.373387, 0.611083, 0.008061, -0.004926, 1.372916, 0.611083,
+ 0.012601, -0.007700, 1.373956, 0.611084, 0.018142, -0.011084, 1.373419, 0.611078, 0.024695,
+ -0.015087, 1.373492, 0.611074, 0.032255, -0.019701, 1.373360, 0.611066, 0.040827, -0.024930,
+ 1.373327, 0.611055, 0.050408, -0.030769, 1.373222, 0.611037, 0.061004, -0.037217, 1.373079,
+ 0.611014, 0.072613, -0.044270, 1.372895, 0.610982, 0.085238, -0.051923, 1.372624, 0.610941,
+ 0.098878, -0.060161, 1.372252, 0.610883, 0.113522, -0.068785, 1.371785, 0.610798, 0.129176,
+ -0.077863, 1.371103, 0.610683, 0.145876, -0.087593, 1.370541, 0.610537, 0.163570, -0.097847,
+ 1.369496, 0.610349, 0.182283, -0.108592, 1.368477, 0.610109, 0.201930, -0.119420, 1.366980,
+ 0.609763, 0.222570, -0.130789, 1.365375, 0.609343, 0.244123, -0.142514, 1.363456, 0.608815,
+ 0.266437, -0.154232, 1.360916, 0.608114, 0.289467, -0.166370, 1.357909, 0.607291, 0.312861,
+ -0.178505, 1.353588, 0.606272, 0.336736, -0.190980, 1.349211, 0.605153, 0.361740, -0.202859,
+ 1.343319, 0.603548, 0.387878, -0.213997, 1.335908, 0.601268, 0.414357, -0.224584, 1.326676,
+ 0.598499, 0.441442, -0.234664, 1.317331, 0.595066, 0.468409, -0.243875, 1.305818, 0.590996,
+ 0.494999, -0.252121, 1.291863, 0.586293, 0.521730, -0.259714, 1.278212, 0.580840, 0.547894,
+ -0.266242, 1.262656, 0.574494, 0.573865, -0.271578, 1.246364, 0.567007, 0.601124, -0.275503,
+ 1.231274, 0.557771, 0.627606, -0.277954, 1.215252, 0.547255, 0.654004, -0.279404, 1.199977,
+ 0.535766, 0.679554, -0.279632, 1.183995, 0.522792, 0.704280, -0.278457, 1.167428, 0.508488,
+ 0.729830, -0.275706, 1.152760, 0.492425, 0.754376, -0.271640, 1.137942, 0.475285, 0.779209,
+ -0.266911, 1.125222, 0.456679, 0.803562, -0.260838, 1.112179, 0.437267, 0.827985, -0.253353,
+ 1.101439, 0.416227, 0.851737, -0.245027, 1.089890, 0.394728, 0.874850, -0.235719, 1.080018,
+ 0.372244, 0.897680, -0.225051, 1.070807, 0.348846, 0.921351, -0.214051, 1.063180, 0.324961,
+ 0.943818, -0.202039, 1.056148, 0.300836, 0.966368, -0.189134, 1.049277, 0.276333, 0.987426,
+ -0.175613, 1.042176, 0.251862, 1.010162, -0.161473, 1.038567, 0.227217, 1.031224, -0.146866,
+ 1.034102, 0.203582, 1.052317, -0.131644, 1.031600, 0.180629, 1.070879, -0.115909, 1.028913,
+ 0.158165, 1.087407, -0.099638, 1.026193, 0.135905, 1.102159, -0.083091, 1.023567, 0.113394,
+ 1.114006, -0.066178, 1.019567, 0.090325, 1.123374, -0.049430, 1.014856, 0.067302, 1.130310,
+ -0.032557, 1.009141, 0.044264, 1.136334, -0.016157, 1.003984, 0.021807, 1.142961, 0.000172,
+ 0.999951, -0.000077, 0.000200, -0.000129, 1.416584, 0.645866, 0.000504, -0.000326, 1.417762,
+ 0.645865, 0.002016, -0.001302, 1.417825, 0.645866, 0.004535, -0.002929, 1.417142, 0.645865,
+ 0.008062, -0.005207, 1.416968, 0.645864, 0.012598, -0.008136, 1.417109, 0.645862, 0.018141,
+ -0.011715, 1.417001, 0.645859, 0.024690, -0.015941, 1.416878, 0.645853, 0.032257, -0.020823,
+ 1.417134, 0.645843, 0.040827, -0.026347, 1.416983, 0.645829, 0.050411, -0.032518, 1.416949,
+ 0.645808, 0.061007, -0.039330, 1.416694, 0.645781, 0.072621, -0.046783, 1.416599, 0.645746,
+ 0.085249, -0.054865, 1.416241, 0.645695, 0.098897, -0.063563, 1.415832, 0.645630, 0.113546,
+ -0.072607, 1.415264, 0.645529, 0.129220, -0.082257, 1.414482, 0.645396, 0.145888, -0.092515,
+ 1.413626, 0.645268, 0.163659, -0.103393, 1.412710, 0.645018, 0.182385, -0.114684, 1.411418,
+ 0.644739, 0.202078, -0.126098, 1.409822, 0.644348, 0.222772, -0.138145, 1.407948, 0.643872,
+ 0.244370, -0.150405, 1.405678, 0.643255, 0.266787, -0.162798, 1.402763, 0.642463, 0.289844,
+ -0.175434, 1.398863, 0.641504, 0.313540, -0.188158, 1.394695, 0.640346, 0.337489, -0.201014,
+ 1.389376, 0.639042, 0.362008, -0.213719, 1.382439, 0.637412, 0.387990, -0.225248, 1.373281,
+ 0.634930, 0.414728, -0.236348, 1.363729, 0.631861, 0.441635, -0.246701, 1.352304, 0.628155,
+ 0.468588, -0.256167, 1.339162, 0.623625, 0.495337, -0.264662, 1.323811, 0.618458, 0.521886,
+ -0.272207, 1.307630, 0.612373, 0.548355, -0.278890, 1.291265, 0.605263, 0.574535, -0.284442,
+ 1.273752, 0.597048, 0.600870, -0.288389, 1.256171, 0.587401, 0.627715, -0.290816, 1.238447,
+ 0.576001, 0.653830, -0.291886, 1.221036, 0.563198, 0.679175, -0.291629, 1.202283, 0.549249,
+ 0.704539, -0.290489, 1.185866, 0.533881, 0.729126, -0.287529, 1.168822, 0.516966, 0.754297,
+ -0.283184, 1.152934, 0.498501, 0.778678, -0.277732, 1.137821, 0.478728, 0.802473, -0.271203,
+ 1.123387, 0.457814, 0.826596, -0.263494, 1.110573, 0.435865, 0.850835, -0.254572, 1.099099,
+ 0.412597, 0.874203, -0.244815, 1.088403, 0.388995, 0.897271, -0.233993, 1.078085, 0.364487,
+ 0.919667, -0.221934, 1.068543, 0.339344, 0.943001, -0.209714, 1.061081, 0.313770, 0.965688,
+ -0.196367, 1.054023, 0.287928, 0.987598, -0.182263, 1.047247, 0.262157, 1.009280, -0.167775,
+ 1.041376, 0.236855, 1.031762, -0.152530, 1.037647, 0.211847, 1.051965, -0.136809, 1.033396,
+ 0.187546, 1.071699, -0.120418, 1.031021, 0.164186, 1.088881, -0.103618, 1.028403, 0.141184,
+ 1.103482, -0.086271, 1.024987, 0.117665, 1.115646, -0.068973, 1.020884, 0.093896, 1.125258,
+ -0.051285, 1.015966, 0.069978, 1.132045, -0.033998, 1.009990, 0.046126, 1.138004, -0.016696,
+ 1.004270, 0.022635, 1.144463, 0.000089, 0.999987, -0.000016, 0.000200, -0.000136, 1.463614,
+ 0.681786, 0.000504, -0.000344, 1.465345, 0.681785, 0.002015, -0.001374, 1.464172, 0.681783,
+ 0.004535, -0.003092, 1.464846, 0.681784, 0.008062, -0.005496, 1.464783, 0.681784, 0.012598,
+ -0.008588, 1.464883, 0.681781, 0.018141, -0.012366, 1.464740, 0.681777, 0.024692, -0.016829,
+ 1.464665, 0.681770, 0.032258, -0.021980, 1.464720, 0.681760, 0.040829, -0.027811, 1.464625,
+ 0.681742, 0.050415, -0.034324, 1.464571, 0.681720, 0.061013, -0.041513, 1.464346, 0.681688,
+ 0.072628, -0.049375, 1.464131, 0.681644, 0.085264, -0.057903, 1.463847, 0.681588, 0.098918,
+ -0.067067, 1.463369, 0.681509, 0.113568, -0.076570, 1.462549, 0.681389, 0.129265, -0.086782,
+ 1.461703, 0.681239, 0.145997, -0.097637, 1.460840, 0.681047, 0.163751, -0.109101, 1.459737,
+ 0.680806, 0.182505, -0.120922, 1.458231, 0.680480, 0.202241, -0.133007, 1.456393, 0.680042,
+ 0.222987, -0.145693, 1.454258, 0.679503, 0.244638, -0.158488, 1.451543, 0.678792, 0.267132,
+ -0.171585, 1.448115, 0.677907, 0.290365, -0.184746, 1.443992, 0.676796, 0.314178, -0.198101,
+ 1.439271, 0.675498, 0.338289, -0.211370, 1.432830, 0.673922, 0.362543, -0.224489, 1.424163,
+ 0.672151, 0.388470, -0.236914, 1.415160, 0.669601, 0.415105, -0.248342, 1.403811, 0.666255,
+ 0.441925, -0.258957, 1.390149, 0.662166, 0.468668, -0.268556, 1.374104, 0.657229, 0.495720,
+ -0.277359, 1.358102, 0.651347, 0.522574, -0.285078, 1.340754, 0.644598, 0.548981, -0.291718,
+ 1.322033, 0.636820, 0.574946, -0.297087, 1.302148, 0.627812, 0.600744, -0.301079, 1.282130,
+ 0.617485, 0.627565, -0.303566, 1.263339, 0.605047, 0.653598, -0.304330, 1.242712, 0.591167,
+ 0.679239, -0.303820, 1.223212, 0.576025, 0.704043, -0.302064, 1.203763, 0.559649, 0.728796,
+ -0.299095, 1.185434, 0.541271, 0.753581, -0.294392, 1.167630, 0.521800, 0.778577, -0.288603,
+ 1.151930, 0.500628, 0.802550, -0.281604, 1.136072, 0.478434, 0.825803, -0.273472, 1.121673,
+ 0.455384, 0.849768, -0.264011, 1.108491, 0.430811, 0.873250, -0.253653, 1.096550, 0.405524,
+ 0.896725, -0.242642, 1.085905, 0.380038, 0.919158, -0.230191, 1.075091, 0.353482, 0.942236,
+ -0.217145, 1.066848, 0.326605, 0.965031, -0.203555, 1.059310, 0.299842, 0.987048, -0.188777,
+ 1.051749, 0.272859, 1.008718, -0.173613, 1.044999, 0.246040, 1.031097, -0.157972, 1.040066,
+ 0.219826, 1.052493, -0.141589, 1.035951, 0.194278, 1.071773, -0.124814, 1.032520, 0.169830,
+ 1.089646, -0.107321, 1.029803, 0.146135, 1.104932, -0.089726, 1.026612, 0.122127, 1.117687,
+ -0.071433, 1.022391, 0.097461, 1.127188, -0.053395, 1.017113, 0.072556, 1.134010, -0.035151,
+ 1.010934, 0.047749, 1.139746, -0.017427, 1.004633, 0.023530, 1.146205, 0.000151, 1.000020,
+ -0.000106, 0.000200, -0.000144, 1.517643, 0.718949, 0.000504, -0.000362, 1.516387, 0.718947,
+ 0.002016, -0.001449, 1.516742, 0.718946, 0.004536, -0.003261, 1.517196, 0.718946, 0.008063,
+ -0.005796, 1.516806, 0.718945, 0.012598, -0.009057, 1.516986, 0.718943, 0.018140, -0.013039,
+ 1.516603, 0.718937, 0.024694, -0.017747, 1.516739, 0.718929, 0.032260, -0.023178, 1.516994,
+ 0.718917, 0.040831, -0.029325, 1.516649, 0.718896, 0.050419, -0.036192, 1.516594, 0.718870,
+ 0.061019, -0.043770, 1.516327, 0.718833, 0.072638, -0.052056, 1.516054, 0.718782, 0.085274,
+ -0.061039, 1.515628, 0.718714, 0.098938, -0.070676, 1.515199, 0.718623, 0.113607, -0.080679,
+ 1.514222, 0.718483, 0.129329, -0.091485, 1.513354, 0.718316, 0.146077, -0.102931, 1.512301,
+ 0.718096, 0.163856, -0.114986, 1.510977, 0.717818, 0.182640, -0.127305, 1.509225, 0.717432,
+ 0.202432, -0.140147, 1.507152, 0.716939, 0.223229, -0.153468, 1.504780, 0.716331, 0.244943,
+ -0.166875, 1.501612, 0.715527, 0.267559, -0.180658, 1.497898, 0.714523, 0.290926, -0.194405,
+ 1.493208, 0.713266, 0.314863, -0.208302, 1.487388, 0.711758, 0.339053, -0.222020, 1.479677,
+ 0.709982, 0.363627, -0.235683, 1.470950, 0.707958, 0.388887, -0.248723, 1.459907, 0.705346,
+ 0.415474, -0.260563, 1.446579, 0.701644, 0.442065, -0.271352, 1.429962, 0.697134, 0.469418,
+ -0.281541, 1.414343, 0.691665, 0.496419, -0.290429, 1.395681, 0.685227, 0.523071, -0.298032,
+ 1.375347, 0.677815, 0.549641, -0.304679, 1.354816, 0.669063, 0.575489, -0.309902, 1.332505,
+ 0.659071, 0.601108, -0.313771, 1.309752, 0.647799, 0.627199, -0.316225, 1.288381, 0.634856,
+ 0.653243, -0.316679, 1.265785, 0.619627, 0.678960, -0.315816, 1.244333, 0.603244, 0.704055,
+ -0.313776, 1.223315, 0.585191, 0.728713, -0.310417, 1.203142, 0.565969, 0.753301, -0.305786,
+ 1.184323, 0.545347, 0.777890, -0.299262, 1.166070, 0.522753, 0.802354, -0.291830, 1.149599,
+ 0.499017, 0.826005, -0.283281, 1.133655, 0.474335, 0.848920, -0.273512, 1.118132, 0.449019,
+ 0.872765, -0.262525, 1.105606, 0.422329, 0.895950, -0.250769, 1.093539, 0.395057, 0.918816,
+ -0.238257, 1.082388, 0.367709, 0.941089, -0.224381, 1.072484, 0.339350, 0.964514, -0.210289,
+ 1.064054, 0.311239, 0.987128, -0.195488, 1.056645, 0.283272, 1.009064, -0.179491, 1.049549,
+ 0.255163, 1.030163, -0.163172, 1.042741, 0.227757, 1.052502, -0.146457, 1.038270, 0.200970,
+ 1.072971, -0.129054, 1.035014, 0.175767, 1.091223, -0.111285, 1.032231, 0.151118, 1.106518,
+ -0.092617, 1.028211, 0.126196, 1.119235, -0.074168, 1.023686, 0.100828, 1.129311, -0.055212,
+ 1.018311, 0.075240, 1.135983, -0.036571, 1.011485, 0.049558, 1.141648, -0.017954, 1.004952,
+ 0.024273, 1.147938, 0.000125, 1.000009, -0.000048, 0.000199, -0.000151, 1.566887, 0.757466,
+ 0.000504, -0.000382, 1.574111, 0.757466, 0.002016, -0.001527, 1.573735, 0.757466, 0.004535,
+ -0.003435, 1.573737, 0.757466, 0.008062, -0.006107, 1.573782, 0.757464, 0.012599, -0.009542,
+ 1.573796, 0.757460, 0.018142, -0.013739, 1.573710, 0.757455, 0.024694, -0.018697, 1.573562,
+ 0.757446, 0.032259, -0.024418, 1.573667, 0.757429, 0.040834, -0.030895, 1.573555, 0.757407,
+ 0.050422, -0.038127, 1.573383, 0.757376, 0.061025, -0.046108, 1.573086, 0.757332, 0.072650,
+ -0.054835, 1.572833, 0.757274, 0.085296, -0.064294, 1.572395, 0.757195, 0.098962, -0.074376,
+ 1.571729, 0.757087, 0.113649, -0.084955, 1.570571, 0.756925, 0.129389, -0.096334, 1.569582,
+ 0.756729, 0.146167, -0.108406, 1.568444, 0.756481, 0.163973, -0.121056, 1.566905, 0.756158,
+ 0.182798, -0.133970, 1.564939, 0.755715, 0.202650, -0.147522, 1.562666, 0.755167, 0.223502,
+ -0.161466, 1.559877, 0.754465, 0.245269, -0.175539, 1.556008, 0.753552, 0.268010, -0.189957,
+ 1.552013, 0.752420, 0.291474, -0.204361, 1.546509, 0.751008, 0.315527, -0.218714, 1.539575,
+ 0.749266, 0.339954, -0.233029, 1.530968, 0.747232, 0.364649, -0.247149, 1.520994, 0.744906,
+ 0.389520, -0.260672, 1.507748, 0.742123, 0.415717, -0.272873, 1.491777, 0.738187, 0.442862,
+ -0.284317, 1.475658, 0.733189, 0.469939, -0.294552, 1.456572, 0.727165, 0.496916, -0.303517,
+ 1.435237, 0.720043, 0.523480, -0.311061, 1.412192, 0.711640, 0.550092, -0.317596, 1.389033,
+ 0.702174, 0.576384, -0.322921, 1.365086, 0.691225, 0.602280, -0.326806, 1.341317, 0.678841,
+ 0.627676, -0.329057, 1.316518, 0.664815, 0.653458, -0.329372, 1.291877, 0.648548, 0.679227,
+ -0.328067, 1.268126, 0.630676, 0.704476, -0.325585, 1.244424, 0.611585, 0.729232, -0.321775,
+ 1.223010, 0.590803, 0.753405, -0.316713, 1.201297, 0.568653, 0.777274, -0.309858, 1.181071,
+ 0.544763, 0.801882, -0.301866, 1.162826, 0.519747, 0.826030, -0.292861, 1.145704, 0.493531,
+ 0.849359, -0.282794, 1.129629, 0.466900, 0.871837, -0.271197, 1.114155, 0.439230, 0.895896,
+ -0.258954, 1.102334, 0.410570, 0.918951, -0.245878, 1.090163, 0.381314, 0.941148, -0.231897,
+ 1.078738, 0.352268, 0.963464, -0.216743, 1.068862, 0.322688, 0.986628, -0.201486, 1.061077,
+ 0.293523, 1.009289, -0.185521, 1.053561, 0.264125, 1.030659, -0.168429, 1.046627, 0.235706,
+ 1.052382, -0.151210, 1.040953, 0.208022, 1.073476, -0.133289, 1.036534, 0.181245, 1.092237,
+ -0.114768, 1.033580, 0.155661, 1.108200, -0.095917, 1.029997, 0.130223, 1.121435, -0.076492,
+ 1.025374, 0.104098, 1.131382, -0.057204, 1.019485, 0.077776, 1.137994, -0.037747, 1.012188,
+ 0.051250, 1.143441, -0.018673, 1.005309, 0.025245, 1.149714, 0.000216, 1.000004, -0.000120,
+ 0.000200, -0.000159, 1.633988, 0.797469, 0.000504, -0.000402, 1.636076, 0.797469, 0.002016,
+ -0.001607, 1.635679, 0.797467, 0.004535, -0.003617, 1.636040, 0.797468, 0.008063, -0.006430,
+ 1.636159, 0.797467, 0.012599, -0.010046, 1.636128, 0.797462, 0.018141, -0.014464, 1.635730,
+ 0.797457, 0.024696, -0.019685, 1.635836, 0.797445, 0.032259, -0.025705, 1.635719, 0.797426,
+ 0.040835, -0.032523, 1.635610, 0.797401, 0.050425, -0.040135, 1.635460, 0.797363, 0.061033,
+ -0.048536, 1.635182, 0.797313, 0.072661, -0.057718, 1.634817, 0.797243, 0.085315, -0.067666,
+ 1.634314, 0.797150, 0.098985, -0.078179, 1.633350, 0.797016, 0.113699, -0.089383, 1.632253,
+ 0.796839, 0.129456, -0.101364, 1.631025, 0.796623, 0.146275, -0.114081, 1.629867, 0.796331,
+ 0.164108, -0.127318, 1.628043, 0.795956, 0.182983, -0.140901, 1.625813, 0.795458, 0.202891,
+ -0.155174, 1.623149, 0.794834, 0.223787, -0.169654, 1.619686, 0.794015, 0.245678, -0.184540,
+ 1.615694, 0.793013, 0.268495, -0.199543, 1.610812, 0.791727, 0.292093, -0.214639, 1.604629,
+ 0.790107, 0.316184, -0.229499, 1.596061, 0.788154, 0.340986, -0.244407, 1.587195, 0.785797,
+ 0.365808, -0.258907, 1.575031, 0.783093, 0.390528, -0.272746, 1.559448, 0.779970, 0.416510,
+ -0.285845, 1.543294, 0.775852, 0.443443, -0.297404, 1.523476, 0.770323, 0.470442, -0.307757,
+ 1.501515, 0.763721, 0.497499, -0.316846, 1.477841, 0.755889, 0.524316, -0.324561, 1.452427,
+ 0.746662, 0.551212, -0.331060, 1.427421, 0.736004, 0.577323, -0.335956, 1.400369, 0.723810,
+ 0.602976, -0.339501, 1.373093, 0.710184, 0.628357, -0.341577, 1.345853, 0.695017, 0.653642,
+ -0.342031, 1.319040, 0.677972, 0.679440, -0.340342, 1.292490, 0.658877, 0.704744, -0.337356,
+ 1.267182, 0.638085, 0.729692, -0.333042, 1.243280, 0.615615, 0.753920, -0.327504, 1.219751,
+ 0.592054, 0.777695, -0.320537, 1.197796, 0.566967, 0.801426, -0.311880, 1.176872, 0.540643,
+ 0.825649, -0.302211, 1.158160, 0.512906, 0.849282, -0.291665, 1.141257, 0.484587, 0.872341,
+ -0.280050, 1.125469, 0.455556, 0.895110, -0.266978, 1.110222, 0.425652, 0.918841, -0.253326,
+ 1.097419, 0.395015, 0.941209, -0.238899, 1.086101, 0.364948, 0.963142, -0.223523, 1.075023,
+ 0.334151, 0.985996, -0.207346, 1.065628, 0.303708, 1.008718, -0.190889, 1.057256, 0.273008,
+ 1.030554, -0.173517, 1.049720, 0.243221, 1.053085, -0.155645, 1.043837, 0.214426, 1.074267,
+ -0.137472, 1.039312, 0.187036, 1.093591, -0.118385, 1.035457, 0.160512, 1.109850, -0.098883,
+ 1.031630, 0.134384, 1.123516, -0.079050, 1.026762, 0.107424, 1.133578, -0.058977, 1.020640,
+ 0.080317, 1.140289, -0.039013, 1.013096, 0.052944, 1.145610, -0.019228, 1.005694, 0.025989,
+ 1.151704, 0.000105, 0.999981, -0.000019, 0.000200, -0.000168, 1.704841, 0.839096, 0.000504,
+ -0.000423, 1.704242, 0.839097, 0.002016, -0.001691, 1.703821, 0.839091, 0.004534, -0.003805,
+ 1.703804, 0.839094, 0.008063, -0.006765, 1.704224, 0.839092, 0.012598, -0.010570, 1.704013,
+ 0.839087, 0.018142, -0.015219, 1.703889, 0.839079, 0.024697, -0.020712, 1.704023, 0.839066,
+ 0.032261, -0.027046, 1.703836, 0.839045, 0.040837, -0.034218, 1.703608, 0.839014, 0.050429,
+ -0.042224, 1.703414, 0.838972, 0.061041, -0.051061, 1.703148, 0.838912, 0.072676, -0.060717,
+ 1.702744, 0.838831, 0.085340, -0.071175, 1.702223, 0.838724, 0.099023, -0.082182, 1.700984,
+ 0.838567, 0.113759, -0.094007, 1.699764, 0.838367, 0.129546, -0.106621, 1.698462, 0.838112,
+ 0.146382, -0.119956, 1.696938, 0.837782, 0.164260, -0.133760, 1.694868, 0.837346, 0.183188,
+ -0.148108, 1.692262, 0.836780, 0.203158, -0.163075, 1.689251, 0.836073, 0.224147, -0.178255,
+ 1.685408, 0.835148, 0.246147, -0.193900, 1.680946, 0.833992, 0.269072, -0.209553, 1.675277,
+ 0.832546, 0.292718, -0.225226, 1.667626, 0.830727, 0.317159, -0.240836, 1.658952, 0.828510,
+ 0.341979, -0.256103, 1.647624, 0.825843, 0.366844, -0.270887, 1.633014, 0.822760, 0.392043,
+ -0.285324, 1.617191, 0.819159, 0.417356, -0.298817, 1.597501, 0.814788, 0.444093, -0.310711,
+ 1.575184, 0.808751, 0.471379, -0.321410, 1.551590, 0.801294, 0.498267, -0.330421, 1.524134,
+ 0.792711, 0.525401, -0.338331, 1.496672, 0.782480, 0.551846, -0.344430, 1.467062, 0.770659,
+ 0.578009, -0.349047, 1.436943, 0.757348, 0.604054, -0.352490, 1.407611, 0.742541, 0.629387,
+ -0.354158, 1.377441, 0.726071, 0.654435, -0.354422, 1.347651, 0.707524, 0.679845, -0.352663,
+ 1.318769, 0.687067, 0.704892, -0.348994, 1.290600, 0.664637, 0.729763, -0.344105, 1.263997,
+ 0.640663, 0.754345, -0.338129, 1.239273, 0.615484, 0.778629, -0.330905, 1.215858, 0.589210,
+ 0.801939, -0.322113, 1.192318, 0.561550, 0.825723, -0.311673, 1.171380, 0.532175, 0.849387,
+ -0.300410, 1.152991, 0.502055, 0.872792, -0.288328, 1.136139, 0.471308, 0.895083, -0.275087,
+ 1.119534, 0.440427, 0.918335, -0.260700, 1.105542, 0.409260, 0.941577, -0.245717, 1.093070,
+ 0.377142, 0.963992, -0.230079, 1.081207, 0.345289, 0.986510, -0.213523, 1.071488, 0.313508,
+ 1.008806, -0.196157, 1.062011, 0.281962, 1.030724, -0.178467, 1.053240, 0.251177, 1.053782,
+ -0.160291, 1.047057, 0.220986, 1.075451, -0.141308, 1.041842, 0.192256, 1.094947, -0.121975,
+ 1.037704, 0.165023, 1.111783, -0.101744, 1.033300, 0.138228, 1.125525, -0.081476, 1.028234,
+ 0.110679, 1.135873, -0.060770, 1.021695, 0.082672, 1.142478, -0.040207, 1.013838, 0.054506,
+ 1.147889, -0.019908, 1.006166, 0.026938, 1.153852, 0.000204, 0.999983, -0.000123, 0.000199,
+ -0.000176, 1.771601, 0.882501, 0.000504, -0.000445, 1.779195, 0.882504, 0.002016, -0.001779,
+ 1.779635, 0.882498, 0.004536, -0.004003, 1.779586, 0.882499, 0.008062, -0.007115, 1.778613,
+ 0.882496, 0.012598, -0.011116, 1.778678, 0.882492, 0.018142, -0.016005, 1.778531, 0.882481,
+ 0.024696, -0.021782, 1.778556, 0.882466, 0.032262, -0.028444, 1.778507, 0.882442, 0.040842,
+ -0.035987, 1.778385, 0.882408, 0.050436, -0.044404, 1.778034, 0.882364, 0.061053, -0.053695,
+ 1.777761, 0.882287, 0.072692, -0.063842, 1.777256, 0.882190, 0.085364, -0.074821, 1.776518,
+ 0.882067, 0.099064, -0.086368, 1.775080, 0.881884, 0.113828, -0.098805, 1.773836, 0.881657,
+ 0.129649, -0.112090, 1.772370, 0.881361, 0.146518, -0.126067, 1.770594, 0.880982, 0.164440,
+ -0.140493, 1.768089, 0.880484, 0.183437, -0.155646, 1.765301, 0.879843, 0.203468, -0.171266,
+ 1.761698, 0.879035, 0.224562, -0.187231, 1.757518, 0.877982, 0.246665, -0.203540, 1.752318,
+ 0.876667, 0.269652, -0.219916, 1.745356, 0.875028, 0.293531, -0.236255, 1.737186, 0.872977,
+ 0.318048, -0.252410, 1.726709, 0.870448, 0.342963, -0.268192, 1.713109, 0.867400, 0.368336,
+ -0.283587, 1.698087, 0.863882, 0.393512, -0.298186, 1.678638, 0.859724, 0.418602, -0.311882,
+ 1.655604, 0.854835, 0.445080, -0.324500, 1.632250, 0.848353, 0.472289, -0.335295, 1.605069,
+ 0.840218, 0.499128, -0.344256, 1.573846, 0.830556, 0.525834, -0.351716, 1.541120, 0.819269,
+ 0.553177, -0.358241, 1.511385, 0.806222, 0.579480, -0.362640, 1.477866, 0.791647, 0.605205,
+ -0.365513, 1.444218, 0.775398, 0.630617, -0.366822, 1.410954, 0.757144, 0.655730, -0.366785,
+ 1.379010, 0.737323, 0.680529, -0.364904, 1.347280, 0.715601, 0.705800, -0.360990, 1.316416,
+ 0.691547, 0.730550, -0.355397, 1.286344, 0.666141, 0.754970, -0.348664, 1.258954, 0.638929,
+ 0.779042, -0.340774, 1.232965, 0.611015, 0.802839, -0.331767, 1.209775, 0.581877, 0.825793,
+ -0.321054, 1.185813, 0.551509, 0.849512, -0.309016, 1.165080, 0.519698, 0.873120, -0.296369,
+ 1.147091, 0.487506, 0.895942, -0.282704, 1.129658, 0.455320, 0.917996, -0.268007, 1.113463,
+ 0.422605, 0.941281, -0.252329, 1.100040, 0.389347, 0.964584, -0.236203, 1.087973, 0.356430,
+ 0.986371, -0.219209, 1.075983, 0.323089, 1.009522, -0.201588, 1.066940, 0.290806, 1.031976,
+ -0.183296, 1.057999, 0.258682, 1.053461, -0.164509, 1.049542, 0.227722, 1.076121, -0.145165,
+ 1.043718, 0.197439, 1.096597, -0.125199, 1.039607, 0.169578, 1.113908, -0.104921, 1.035528,
+ 0.142222, 1.127939, -0.083623, 1.029807, 0.113802, 1.138391, -0.062589, 1.023312, 0.085164,
+ 1.145110, -0.041376, 1.014806, 0.056186, 1.150141, -0.020433, 1.006501, 0.027654, 1.156069,
+ 0.000097, 0.999949, -0.000046, 0.000200, -0.000185, 1.858268, 0.927857, 0.000504, -0.000468,
+ 1.861583, 0.927859, 0.002016, -0.001870, 1.860659, 0.927855, 0.004535, -0.004208, 1.860963,
+ 0.927867, 0.008063, -0.007480, 1.860766, 0.927855, 0.012594, -0.011683, 1.859996, 0.927851,
+ 0.018142, -0.016828, 1.860739, 0.927839, 0.024698, -0.022901, 1.860763, 0.927818, 0.032263,
+ -0.029903, 1.860501, 0.927791, 0.040846, -0.037834, 1.860431, 0.927751, 0.050440, -0.046680,
+ 1.859827, 0.927690, 0.061066, -0.056446, 1.859624, 0.927610, 0.072713, -0.067109, 1.859039,
+ 0.927505, 0.085393, -0.078613, 1.858144, 0.927357, 0.099120, -0.090747, 1.856618, 0.927145,
+ 0.113910, -0.103850, 1.855221, 0.926884, 0.129755, -0.117777, 1.853470, 0.926546, 0.146669,
+ -0.132441, 1.851413, 0.926104, 0.164648, -0.147565, 1.848498, 0.925530, 0.183708, -0.163470,
+ 1.845281, 0.924802, 0.203832, -0.179763, 1.841273, 0.923871, 0.225029, -0.196564, 1.836481,
+ 0.922691, 0.247221, -0.213537, 1.830273, 0.921198, 0.270343, -0.230662, 1.822374, 0.919320,
+ 0.294399, -0.247740, 1.812975, 0.917008, 0.319040, -0.264448, 1.800693, 0.914141, 0.344269,
+ -0.280831, 1.785923, 0.910707, 0.369625, -0.296478, 1.767203, 0.906585, 0.394925, -0.311287,
+ 1.744434, 0.901918, 0.420583, -0.325578, 1.720938, 0.896240, 0.446200, -0.338384, 1.693005,
+ 0.889335, 0.472969, -0.349187, 1.660901, 0.880394, 0.500490, -0.358687, 1.628806, 0.869705,
+ 0.527312, -0.366042, 1.593001, 0.857145, 0.554207, -0.372045, 1.557046, 0.842943, 0.580620,
+ -0.376134, 1.520192, 0.826837, 0.606480, -0.378636, 1.482947, 0.808891, 0.631815, -0.379414,
+ 1.445954, 0.789119, 0.657021, -0.378972, 1.410833, 0.767564, 0.681686, -0.376728, 1.376575,
+ 0.744338, 0.706498, -0.372844, 1.342935, 0.718799, 0.731258, -0.366649, 1.311052, 0.691756,
+ 0.755937, -0.359354, 1.280478, 0.662683, 0.779259, -0.350487, 1.250585, 0.632892, 0.803295,
+ -0.340941, 1.225722, 0.602160, 0.826570, -0.330174, 1.201003, 0.570520, 0.849954, -0.317854,
+ 1.178488, 0.537651, 0.873696, -0.304426, 1.158302, 0.503799, 0.896695, -0.290120, 1.139886,
+ 0.469645, 0.919149, -0.275106, 1.122884, 0.435625, 0.942121, -0.259282, 1.107691, 0.401228,
+ 0.964627, -0.242123, 1.093661, 0.367086, 0.986614, -0.224575, 1.081580, 0.332885, 1.009623,
+ -0.206837, 1.071375, 0.299209, 1.033126, -0.188092, 1.062241, 0.266187, 1.054954, -0.168637,
+ 1.052912, 0.233733, 1.077660, -0.149166, 1.047047, 0.203192, 1.097983, -0.128587, 1.041607,
+ 0.173918, 1.115586, -0.107339, 1.036850, 0.145531, 1.130170, -0.086203, 1.031427, 0.116890,
+ 1.141018, -0.064171, 1.024395, 0.087388, 1.147681, -0.042530, 1.015719, 0.057733, 1.152560,
+ -0.021011, 1.006883, 0.028413, 1.158406, 0.000158, 0.999897, -0.000106, 0.000200, -0.000195,
+ 1.950982, 0.975366, 0.000504, -0.000491, 1.950207, 0.975365, 0.002015, -0.001966, 1.950675,
+ 0.975362, 0.004535, -0.004423, 1.951281, 0.975370, 0.008062, -0.007863, 1.951045, 0.975362,
+ 0.012597, -0.012285, 1.951199, 0.975356, 0.018145, -0.017692, 1.951528, 0.975340, 0.024699,
+ -0.024074, 1.951194, 0.975321, 0.032266, -0.031434, 1.950865, 0.975288, 0.040853, -0.039771,
+ 1.951038, 0.975244, 0.050452, -0.049067, 1.950336, 0.975173, 0.061077, -0.059324, 1.949805,
+ 0.975078, 0.072736, -0.070526, 1.949133, 0.974951, 0.085431, -0.082528, 1.947947, 0.974777,
+ 0.099182, -0.095345, 1.946337, 0.974540, 0.113999, -0.109118, 1.944725, 0.974241, 0.129888,
+ -0.123741, 1.942857, 0.973852, 0.146842, -0.139071, 1.940251, 0.973342, 0.164890, -0.154986,
+ 1.937086, 0.972684, 0.184025, -0.171661, 1.933404, 0.971856, 0.204245, -0.188672, 1.928770,
+ 0.970785, 0.225528, -0.206252, 1.923041, 0.969448, 0.247841, -0.223972, 1.915788, 0.967742,
+ 0.271157, -0.241827, 1.907008, 0.965607, 0.295297, -0.259562, 1.895854, 0.963007, 0.320121,
+ -0.276909, 1.881289, 0.959722, 0.345566, -0.293883, 1.864528, 0.955831, 0.371012, -0.309816,
+ 1.842062, 0.951127, 0.396834, -0.325157, 1.818068, 0.945725, 0.422277, -0.339357, 1.788874,
+ 0.939318, 0.447928, -0.352387, 1.758283, 0.931470, 0.474315, -0.363680, 1.723668, 0.921900,
+ 0.501560, -0.372963, 1.686081, 0.909996, 0.528391, -0.380159, 1.645816, 0.896244, 0.554754,
+ -0.385545, 1.603709, 0.880326, 0.581888, -0.389778, 1.565475, 0.862716, 0.607791, -0.391839,
+ 1.524196, 0.843146, 0.633511, -0.392331, 1.483921, 0.821554, 0.658621, -0.391193, 1.445013,
+ 0.798336, 0.683160, -0.388424, 1.406963, 0.773299, 0.707429, -0.384104, 1.370996, 0.746668,
+ 0.732212, -0.377945, 1.335879, 0.717502, 0.756871, -0.369856, 1.302489, 0.686954, 0.781065,
+ -0.360707, 1.271815, 0.655372, 0.804167, -0.350091, 1.242416, 0.622683, 0.827948, -0.338941,
+ 1.217208, 0.589185, 0.850901, -0.326427, 1.192354, 0.555005, 0.873589, -0.312199, 1.169639,
+ 0.519594, 0.897085, -0.297374, 1.150181, 0.484105, 0.920459, -0.281932, 1.132858, 0.448661,
+ 0.942637, -0.265625, 1.115401, 0.413051, 0.965341, -0.248332, 1.101078, 0.377329, 0.987530,
+ -0.229983, 1.087377, 0.342349, 1.010739, -0.211647, 1.076582, 0.307824, 1.033449, -0.192725,
+ 1.065900, 0.273368, 1.055618, -0.172726, 1.056958, 0.240238, 1.079345, -0.152640, 1.049620,
+ 0.208322, 1.100058, -0.131931, 1.044084, 0.178242, 1.118547, -0.110351, 1.039387, 0.149493,
+ 1.132748, -0.088128, 1.033049, 0.119673, 1.143419, -0.066069, 1.025521, 0.089728, 1.150316,
+ -0.043513, 1.016378, 0.059253, 1.155208, -0.021593, 1.007506, 0.029140, 1.160871, 0.000111,
+ 0.999916, -0.000035, 0.000201, -0.000206, 2.061000, 1.025243, 0.000504, -0.000516, 2.049647,
+ 1.025237, 0.002015, -0.002066, 2.050169, 1.025237, 0.004535, -0.004650, 2.051254, 1.025255,
+ 0.008063, -0.008266, 2.051302, 1.025236, 0.012600, -0.012915, 2.051508, 1.025226, 0.018144,
+ -0.018594, 2.050981, 1.025215, 0.024700, -0.025304, 2.050841, 1.025190, 0.032267, -0.033038,
+ 2.050537, 1.025152, 0.040852, -0.041795, 2.050660, 1.025090, 0.050460, -0.051570, 2.049921,
+ 1.025017, 0.061094, -0.062347, 2.049350, 1.024908, 0.072762, -0.074111, 2.048517, 1.024760,
+ 0.085475, -0.086661, 2.047009, 1.024555, 0.099249, -0.100160, 2.045261, 1.024278, 0.114106,
+ -0.114628, 2.043508, 1.023941, 0.130032, -0.130002, 2.041321, 1.023488, 0.147050, -0.145985,
+ 2.038299, 1.022905, 0.165164, -0.162762, 2.034658, 1.022151, 0.184380, -0.180172, 2.030312,
+ 1.021200, 0.204704, -0.198022, 2.024944, 1.019966, 0.226129, -0.216359, 2.018546, 1.018424,
+ 0.248582, -0.234923, 2.010153, 1.016519, 0.272011, -0.253474, 1.999659, 1.014072, 0.296259,
+ -0.271820, 1.986076, 1.011071, 0.321423, -0.289959, 1.970618, 1.007389, 0.346897, -0.307283,
+ 1.949667, 1.002955, 0.372750, -0.323817, 1.925287, 0.997633, 0.398603, -0.339241, 1.896006,
+ 0.991354, 0.424351, -0.353633, 1.863658, 0.983937, 0.449887, -0.366660, 1.827430, 0.975254,
+ 0.475715, -0.378213, 1.789521, 0.964753, 0.502204, -0.387133, 1.745632, 0.951594, 0.530179,
+ -0.394976, 1.705347, 0.936344, 0.556732, -0.400134, 1.658928, 0.918907, 0.583123, -0.403439,
+ 1.613077, 0.899504, 0.609477, -0.405285, 1.567884, 0.878172, 0.634927, -0.405055, 1.523507,
+ 0.854396, 0.660357, -0.403494, 1.481712, 0.829259, 0.684851, -0.400104, 1.439000, 0.802359,
+ 0.709654, -0.395536, 1.400956, 0.773534, 0.733472, -0.388996, 1.362156, 0.743230, 0.757502,
+ -0.380263, 1.325113, 0.711090, 0.782249, -0.370594, 1.292913, 0.677166, 0.806017, -0.359509,
+ 1.262088, 0.642527, 0.828687, -0.347126, 1.232059, 0.607589, 0.852372, -0.334474, 1.207160,
+ 0.571938, 0.874266, -0.320074, 1.181978, 0.535518, 0.898168, -0.304719, 1.161156, 0.498375,
+ 0.920456, -0.288246, 1.140667, 0.461179, 0.942832, -0.271311, 1.122780, 0.424533, 0.966458,
+ -0.254154, 1.108743, 0.387784, 0.988907, -0.235659, 1.093872, 0.351689, 1.011557, -0.216322,
+ 1.081959, 0.315743, 1.035099, -0.197007, 1.070885, 0.280402, 1.056354, -0.176878, 1.059968,
+ 0.246472, 1.079854, -0.156058, 1.051815, 0.212818, 1.101494, -0.134772, 1.045757, 0.182143,
+ 1.120587, -0.113071, 1.041169, 0.152867, 1.135399, -0.090411, 1.034844, 0.122796, 1.146612,
+ -0.067477, 1.026974, 0.091888, 1.153168, -0.044849, 1.017303, 0.060779, 1.157912, -0.021998,
+ 1.007735, 0.029919, 1.163607, 0.000121, 0.999959, 0.000003, 0.000200, -0.000216, 2.163956,
+ 1.077737, 0.000504, -0.000543, 2.161128, 1.077732, 0.002016, -0.002173, 2.162732, 1.077729,
+ 0.004535, -0.004887, 2.161402, 1.077749, 0.008066, -0.008692, 2.163252, 1.077732, 0.012599,
+ -0.013576, 2.161300, 1.077727, 0.018145, -0.019546, 2.161151, 1.077702, 0.024702, -0.026599,
+ 2.161223, 1.077675, 0.032272, -0.034729, 2.160949, 1.077632, 0.040862, -0.043936, 2.160967,
+ 1.077575, 0.050470, -0.054203, 2.160035, 1.077473, 0.061113, -0.065528, 2.159490, 1.077348,
+ 0.072794, -0.077882, 2.158517, 1.077178, 0.085528, -0.091030, 2.156605, 1.076937, 0.099337,
+ -0.105251, 2.154828, 1.076631, 0.114228, -0.120456, 2.152812, 1.076229, 0.130202, -0.136573,
+ 2.150298, 1.075713, 0.147284, -0.153306, 2.146752, 1.075031, 0.165480, -0.170931, 2.142744,
+ 1.074173, 0.184793, -0.189083, 2.137475, 1.073063, 0.205224, -0.207840, 2.131320, 1.071683,
+ 0.226743, -0.226939, 2.123154, 1.069914, 0.249401, -0.246344, 2.114086, 1.067718, 0.272955,
+ -0.265640, 2.101599, 1.064924, 0.297494, -0.284846, 2.086612, 1.061512, 0.322731, -0.303452,
+ 2.067356, 1.057359, 0.348451, -0.321330, 2.043711, 1.052294, 0.374451, -0.338201, 2.015033,
+ 1.046153, 0.400454, -0.353816, 1.981139, 1.039003, 0.426434, -0.368216, 1.944128, 1.030498,
+ 0.452088, -0.381251, 1.903094, 1.020454, 0.477901, -0.392833, 1.860402, 1.008793, 0.504173,
+ -0.402408, 1.814402, 0.994791, 0.531520, -0.409545, 1.766273, 0.977733, 0.558049, -0.414351,
+ 1.714119, 0.958625, 0.584778, -0.417437, 1.664612, 0.937189, 0.610808, -0.418519, 1.613793,
+ 0.913543, 0.636915, -0.418094, 1.565942, 0.888137, 0.662204, -0.415742, 1.518783, 0.860728,
+ 0.686848, -0.411746, 1.473306, 0.831793, 0.710992, -0.406153, 1.430153, 0.800862, 0.735382,
+ -0.399519, 1.389824, 0.768768, 0.759079, -0.390927, 1.350744, 0.734825, 0.782912, -0.380111,
+ 1.313559, 0.699450, 0.806746, -0.368383, 1.280028, 0.663191, 0.830269, -0.355606, 1.249814,
+ 0.625927, 0.853305, -0.341988, 1.221138, 0.588644, 0.876326, -0.327545, 1.195837, 0.550849,
+ 0.898322, -0.311779, 1.171844, 0.512694, 0.921811, -0.294944, 1.150671, 0.474225, 0.944563,
+ -0.277333, 1.132224, 0.435772, 0.967089, -0.259340, 1.115422, 0.398001, 0.989754, -0.240836,
+ 1.100405, 0.360802, 1.012470, -0.221293, 1.086533, 0.323566, 1.036426, -0.201191, 1.075496,
+ 0.287387, 1.058709, -0.180590, 1.064233, 0.252184, 1.081593, -0.159810, 1.055296, 0.218441,
+ 1.103146, -0.137772, 1.047978, 0.186223, 1.122814, -0.115347, 1.042693, 0.156019, 1.137790,
+ -0.092582, 1.036049, 0.125579, 1.149184, -0.069152, 1.027944, 0.093986, 1.156062, -0.045661,
+ 1.018039, 0.062122, 1.160733, -0.022719, 1.008072, 0.030650, 1.166487, 0.000231, 1.000063,
+ -0.000120, 0.000201, -0.000228, 2.308308, 1.133128, 0.000504, -0.000571, 2.283756, 1.133123,
+ 0.002016, -0.002284, 2.283756, 1.133123, 0.004535, -0.005138, 2.283310, 1.133144, 0.008048,
+ -0.009119, 2.266192, 1.133138, 0.012600, -0.014274, 2.284377, 1.133110, 0.018147, -0.020553,
+ 2.284204, 1.133093, 0.024702, -0.027964, 2.283517, 1.133060, 0.032272, -0.036510, 2.282997,
+ 1.133007, 0.040866, -0.046188, 2.282986, 1.132930, 0.050481, -0.056979, 2.282260, 1.132824,
+ 0.061133, -0.068881, 2.281533, 1.132678, 0.072830, -0.081850, 2.280504, 1.132481, 0.085592,
+ -0.095657, 2.278304, 1.132202, 0.099431, -0.110594, 2.276269, 1.131845, 0.114360, -0.126590,
+ 2.273890, 1.131383, 0.130388, -0.143454, 2.270761, 1.130784, 0.147547, -0.161029, 2.266794,
+ 1.130003, 0.165836, -0.179523, 2.262332, 1.129016, 0.185269, -0.198527, 2.256326, 1.127738,
+ 0.205822, -0.218138, 2.249031, 1.126156, 0.227527, -0.238141, 2.239993, 1.124132, 0.250325,
+ -0.258302, 2.228878, 1.121594, 0.274070, -0.278329, 2.214204, 1.118449, 0.298793, -0.298310,
+ 2.196654, 1.114528, 0.324131, -0.317462, 2.173394, 1.109783, 0.350101, -0.335853, 2.146395,
+ 1.103901, 0.376293, -0.353064, 2.112341, 1.096954, 0.402547, -0.368950, 2.073700, 1.088642,
+ 0.428791, -0.383462, 2.031152, 1.078946, 0.454976, -0.396635, 1.986661, 1.067536, 0.480566,
+ -0.407873, 1.937038, 1.054403, 0.506154, -0.417303, 1.885155, 1.038894, 0.532862, -0.424194,
+ 1.830369, 1.020535, 0.560354, -0.429344, 1.776976, 0.999295, 0.587114, -0.431949, 1.721214,
+ 0.975990, 0.613345, -0.432547, 1.665739, 0.950239, 0.639335, -0.431338, 1.612200, 0.922467,
+ 0.664996, -0.428473, 1.561035, 0.892593, 0.688947, -0.423355, 1.508240, 0.861325, 0.713403,
+ -0.417235, 1.461776, 0.828289, 0.737649, -0.409848, 1.418888, 0.793863, 0.761275, -0.400901,
+ 1.376807, 0.758074, 0.784778, -0.390174, 1.337204, 0.721974, 0.808762, -0.377683, 1.301527,
+ 0.682718, 0.831993, -0.364037, 1.267144, 0.644001, 0.854696, -0.349494, 1.236023, 0.605478,
+ 0.877933, -0.334499, 1.209284, 0.565588, 0.900180, -0.318435, 1.183967, 0.526138, 0.923039,
+ -0.301669, 1.161513, 0.486524, 0.945895, -0.283298, 1.140838, 0.446747, 0.968069, -0.264438,
+ 1.122475, 0.408041, 0.991179, -0.245463, 1.106968, 0.369477, 1.012926, -0.225680, 1.091435,
+ 0.331626, 1.036995, -0.205401, 1.079561, 0.294288, 1.060909, -0.184310, 1.068215, 0.257696,
+ 1.083531, -0.162846, 1.058133, 0.223343, 1.105644, -0.141040, 1.050851, 0.190541, 1.125691,
+ -0.117965, 1.045001, 0.159310, 1.141297, -0.094377, 1.038028, 0.128238, 1.152672, -0.070831,
+ 1.029694, 0.096282, 1.159333, -0.046853, 1.019136, 0.063720, 1.163819, -0.022991, 1.008518,
+ 0.031234, 1.169564, 0.000125, 1.000069, -0.000024, 0.000202, -0.000241, 2.458341, 1.191742,
+ 0.000504, -0.000600, 2.418738, 1.191740, 0.002015, -0.002401, 2.418821, 1.191730, 0.004535,
+ -0.005405, 2.421986, 1.191756, 0.008071, -0.009618, 2.424988, 1.191753, 0.012600, -0.015012,
+ 2.420242, 1.191727, 0.018145, -0.021612, 2.419937, 1.191703, 0.024704, -0.029410, 2.419746,
+ 1.191662, 0.032278, -0.038398, 2.419409, 1.191604, 0.040874, -0.048574, 2.418995, 1.191515,
+ 0.050496, -0.059920, 2.418190, 1.191389, 0.061160, -0.072432, 2.417487, 1.191221, 0.072871,
+ -0.086009, 2.415853, 1.190984, 0.085664, -0.100559, 2.413669, 1.190664, 0.099543, -0.116283,
+ 2.411423, 1.190256, 0.114520, -0.133071, 2.408711, 1.189719, 0.130616, -0.150670, 2.404900,
+ 1.189019, 0.147856, -0.169197, 2.400512, 1.188125, 0.166235, -0.188545, 2.394939, 1.186972,
+ 0.185804, -0.208480, 2.388232, 1.185515, 0.206488, -0.228883, 2.379190, 1.183673, 0.228383,
+ -0.249897, 2.369208, 1.181382, 0.251305, -0.270851, 2.355459, 1.178478, 0.275349, -0.291780,
+ 2.339142, 1.174857, 0.300106, -0.312257, 2.316655, 1.170411, 0.325849, -0.332225, 2.291540,
+ 1.164883, 0.351782, -0.350862, 2.257242, 1.158196, 0.378248, -0.368431, 2.218671, 1.150173,
+ 0.404674, -0.384428, 2.173680, 1.140703, 0.431385, -0.399230, 2.127083, 1.129555, 0.457407,
+ -0.411875, 2.073236, 1.116436, 0.483275, -0.423013, 2.018223, 1.101373, 0.509278, -0.432624,
+ 1.962674, 1.084257, 0.534751, -0.439261, 1.900814, 1.064592, 0.561895, -0.443801, 1.839558,
+ 1.040881, 0.588677, -0.445872, 1.777763, 1.015208, 0.614900, -0.445896, 1.716550, 0.987252,
+ 0.641051, -0.444148, 1.657984, 0.957271, 0.666409, -0.440299, 1.600832, 0.924841, 0.691872,
+ -0.435318, 1.548237, 0.891185, 0.716638, -0.428631, 1.497572, 0.855929, 0.739864, -0.419872,
+ 1.447043, 0.819676, 0.763707, -0.410456, 1.403648, 0.781455, 0.786744, -0.399390, 1.360844,
+ 0.742965, 0.809585, -0.386381, 1.320529, 0.703260, 0.834164, -0.372622, 1.286467, 0.662385,
+ 0.856713, -0.357177, 1.252306, 0.621379, 0.879820, -0.341458, 1.223070, 0.580238, 0.902721,
+ -0.325024, 1.197115, 0.539028, 0.924650, -0.307543, 1.172314, 0.498592, 0.947613, -0.289557,
+ 1.151171, 0.457980, 0.969590, -0.269799, 1.129986, 0.417696, 0.992961, -0.250111, 1.113321,
+ 0.377529, 1.014582, -0.229761, 1.097149, 0.339096, 1.038069, -0.209375, 1.083913, 0.301119,
+ 1.061661, -0.188038, 1.071241, 0.263506, 1.085069, -0.165874, 1.060508, 0.227921, 1.107744,
+ -0.143437, 1.052930, 0.194062, 1.127982, -0.120574, 1.046396, 0.162506, 1.144541, -0.096569,
+ 1.039880, 0.130788, 1.155876, -0.072039, 1.030946, 0.098057, 1.162719, -0.047888, 1.020124,
+ 0.064956, 1.167089, -0.023740, 1.008953, 0.031966, 1.172775, 0.000277, 1.000067, -0.000111,
+ 0.000200, -0.000251, 2.573709, 1.253951, 0.000504, -0.000632, 2.572401, 1.253940, 0.002015,
+ -0.002527, 2.571267, 1.253927, 0.004535, -0.005687, 2.572481, 1.253948, 0.008062, -0.010108,
+ 2.571851, 1.253941, 0.012588, -0.015780, 2.568431, 1.253934, 0.018139, -0.022731, 2.569765,
+ 1.253893, 0.024709, -0.030948, 2.572115, 1.253853, 0.032283, -0.040401, 2.571456, 1.253785,
+ 0.040883, -0.051105, 2.571041, 1.253683, 0.050514, -0.063041, 2.570153, 1.253538, 0.061188,
+ -0.076195, 2.569085, 1.253336, 0.072926, -0.090402, 2.567184, 1.253065, 0.085746, -0.105745,
+ 2.564731, 1.252697, 0.099661, -0.122296, 2.561995, 1.252218, 0.114699, -0.139912, 2.559019,
+ 1.251590, 0.130882, -0.158362, 2.555017, 1.250766, 0.148202, -0.177856, 2.549419, 1.249744,
+ 0.166706, -0.198049, 2.542908, 1.248423, 0.186404, -0.219014, 2.535205, 1.246741, 0.207272,
+ -0.240376, 2.524893, 1.244596, 0.229345, -0.262230, 2.512804, 1.241917, 0.252494, -0.284134,
+ 2.496923, 1.238610, 0.276690, -0.305828, 2.476583, 1.234474, 0.301798, -0.327107, 2.451548,
+ 1.229292, 0.327423, -0.347300, 2.418630, 1.222997, 0.353848, -0.366699, 2.381002, 1.215366,
+ 0.380342, -0.384421, 2.334413, 1.206199, 0.407390, -0.400855, 2.285660, 1.195374, 0.433913,
+ -0.415241, 2.228604, 1.182290, 0.460837, -0.428275, 2.171532, 1.167385, 0.486381, -0.438573,
+ 2.105639, 1.150401, 0.511959, -0.447348, 2.040835, 1.130990, 0.537586, -0.454152, 1.974797,
+ 1.109302, 0.564035, -0.458684, 1.907895, 1.084131, 0.590690, -0.460058, 1.839482, 1.055803,
+ 0.617250, -0.459662, 1.772332, 1.025103, 0.643406, -0.457260, 1.707313, 0.992502, 0.668794,
+ -0.452666, 1.644722, 0.957657, 0.693930, -0.446641, 1.586832, 0.921340, 0.718708, -0.439121,
+ 1.531197, 0.883841, 0.743469, -0.430429, 1.480765, 0.844931, 0.766080, -0.419622, 1.430338,
+ 0.804786, 0.789801, -0.408368, 1.386295, 0.764206, 0.812718, -0.395392, 1.343758, 0.722565,
+ 0.835453, -0.380699, 1.304655, 0.680585, 0.858801, -0.364834, 1.269287, 0.637235, 0.881537,
+ -0.348092, 1.237493, 0.594579, 0.904656, -0.331087, 1.208862, 0.552313, 0.926357, -0.312966,
+ 1.182365, 0.510080, 0.949001, -0.294684, 1.159452, 0.468677, 0.971598, -0.275361, 1.138706,
+ 0.426723, 0.994905, -0.254947, 1.120552, 0.385875, 1.017981, -0.234109, 1.104215, 0.345751,
+ 1.040840, -0.213040, 1.089276, 0.306762, 1.063893, -0.191616, 1.075845, 0.269066, 1.086907,
+ -0.169272, 1.063788, 0.232171, 1.109937, -0.146076, 1.054977, 0.197826, 1.130808, -0.122544,
+ 1.048572, 0.165272, 1.146831, -0.098492, 1.040742, 0.133280, 1.158955, -0.073710, 1.031818,
+ 0.100262, 1.166161, -0.048610, 1.020747, 0.066165, 1.170491, -0.024209, 1.009380, 0.032741,
+ 1.176111, 0.000010, 1.000042, 0.000056, 0.000202, -0.000267, 2.786357, 1.320169, 0.000504,
+ -0.000665, 2.741889, 1.320168, 0.002015, -0.002660, 2.740000, 1.320143, 0.004536, -0.005987,
+ 2.744276, 1.320161, 0.008063, -0.010644, 2.743432, 1.320162, 0.012600, -0.016628, 2.741741,
+ 1.320148, 0.018144, -0.023937, 2.741314, 1.320127, 0.024708, -0.032577, 2.741916, 1.320061,
+ 0.032290, -0.042536, 2.742132, 1.319976, 0.040894, -0.053799, 2.741199, 1.319861, 0.050533,
+ -0.066361, 2.740258, 1.319691, 0.061223, -0.080202, 2.739045, 1.319458, 0.072985, -0.095109,
+ 2.736519, 1.319138, 0.085841, -0.111296, 2.733903, 1.318715, 0.099808, -0.128685, 2.730944,
+ 1.318156, 0.114903, -0.147202, 2.727293, 1.317424, 0.131164, -0.166575, 2.722169, 1.316485,
+ 0.148599, -0.187019, 2.716148, 1.315274, 0.167245, -0.208240, 2.708701, 1.313733, 0.187078,
+ -0.230151, 2.698998, 1.311792, 0.208153, -0.252538, 2.687341, 1.309343, 0.230418, -0.275295,
+ 2.672621, 1.306247, 0.253802, -0.298066, 2.653619, 1.302374, 0.278261, -0.320673, 2.629943,
+ 1.297573, 0.303527, -0.342528, 2.599228, 1.291625, 0.329571, -0.363531, 2.562226, 1.284374,
+ 0.355939, -0.382963, 2.515491, 1.275478, 0.382987, -0.401306, 2.464858, 1.264866, 0.409917,
+ -0.417455, 2.404877, 1.252184, 0.437015, -0.432067, 2.341408, 1.237415, 0.463474, -0.444204,
+ 2.271837, 1.220687, 0.489835, -0.454631, 2.200593, 1.200973, 0.516054, -0.463338, 2.129733,
+ 1.179346, 0.541397, -0.469425, 2.055635, 1.155039, 0.566798, -0.473526, 1.980812, 1.127866,
+ 0.593114, -0.474632, 1.904723, 1.097304, 0.619945, -0.473597, 1.832456, 1.063603, 0.646325,
+ -0.470656, 1.761501, 1.027971, 0.672320, -0.465675, 1.694248, 0.990692, 0.697163, -0.458527,
+ 1.629227, 0.951582, 0.721472, -0.449904, 1.568132, 0.911197, 0.745855, -0.440140, 1.512084,
+ 0.869745, 0.770089, -0.429338, 1.460694, 0.827648, 0.792546, -0.416701, 1.410739, 0.784728,
+ 0.815161, -0.403151, 1.365438, 0.741884, 0.837994, -0.388714, 1.324811, 0.697800, 0.861220,
+ -0.372573, 1.287723, 0.653341, 0.883737, -0.355024, 1.252491, 0.609455, 0.906784, -0.337092,
+ 1.221844, 0.565275, 0.928493, -0.318370, 1.192881, 0.521558, 0.951495, -0.299605, 1.169131,
+ 0.478149, 0.973586, -0.280067, 1.146316, 0.436325, 0.996400, -0.259823, 1.127860, 0.394409,
+ 1.019780, -0.238313, 1.110521, 0.353045, 1.042775, -0.216506, 1.093915, 0.312803, 1.066822,
+ -0.194695, 1.080326, 0.274100, 1.089869, -0.172290, 1.067722, 0.236657, 1.113606, -0.149264,
+ 1.058471, 0.201603, 1.134229, -0.124814, 1.050701, 0.168398, 1.150922, -0.100070, 1.043051,
+ 0.135616, 1.163224, -0.075155, 1.033742, 0.102144, 1.169965, -0.049933, 1.021818, 0.067532,
+ 1.174200, -0.024461, 1.009916, 0.033215, 1.179766, 0.000188, 1.000045, -0.000014, 0.000202,
+ -0.000281, 2.964186, 1.390880, 0.000505, -0.000702, 2.945157, 1.390903, 0.002015, -0.002802,
+ 2.931184, 1.390863, 0.004535, -0.006307, 2.935673, 1.390900, 0.008063, -0.011213, 2.934274,
+ 1.390890, 0.012598, -0.017516, 2.932216, 1.390876, 0.018147, -0.025221, 2.933324, 1.390832,
+ 0.024711, -0.034322, 2.933945, 1.390769, 0.032295, -0.044810, 2.933496, 1.390674, 0.040904,
+ -0.056673, 2.932487, 1.390538, 0.050555, -0.069906, 2.931571, 1.390342, 0.061259, -0.084468,
+ 2.929914, 1.390064, 0.073053, -0.100152, 2.927039, 1.389695, 0.085948, -0.117202, 2.924241,
+ 1.389201, 0.099968, -0.135531, 2.920760, 1.388548, 0.115135, -0.154906, 2.915998, 1.387692,
+ 0.131496, -0.175352, 2.910285, 1.386611, 0.149049, -0.196783, 2.903174, 1.385190, 0.167848,
+ -0.219066, 2.894584, 1.383407, 0.187879, -0.241983, 2.883171, 1.381148, 0.209143, -0.265398,
+ 2.869102, 1.378261, 0.231689, -0.289254, 2.852238, 1.374690, 0.255223, -0.312776, 2.828264,
+ 1.370166, 0.279952, -0.336260, 2.800175, 1.364591, 0.305572, -0.358865, 2.764282, 1.357758,
+ 0.331650, -0.380223, 2.717845, 1.349413, 0.358491, -0.400252, 2.665326, 1.339084, 0.385445,
+ -0.418422, 2.602293, 1.326773, 0.412947, -0.434993, 2.536973, 1.312141, 0.439681, -0.448757,
+ 2.459463, 1.295205, 0.467272, -0.461427, 2.386250, 1.275573, 0.493568, -0.471102, 2.303225,
+ 1.253400, 0.519743, -0.478930, 2.221945, 1.228890, 0.544882, -0.484098, 2.136425, 1.201730,
+ 0.570690, -0.488125, 2.057093, 1.172022, 0.595905, -0.489185, 1.975334, 1.139312, 0.622747,
+ -0.487535, 1.895055, 1.103038, 0.648695, -0.483482, 1.815995, 1.064364, 0.675159, -0.478096,
+ 1.744272, 1.024098, 0.700714, -0.470492, 1.675257, 0.982186, 0.725641, -0.461398, 1.609135,
+ 0.939137, 0.748552, -0.449825, 1.545091, 0.894791, 0.772808, -0.438185, 1.489394, 0.850373,
+ 0.795928, -0.425073, 1.437026, 0.805287, 0.818900, -0.411028, 1.389654, 0.760003, 0.841633,
+ -0.396047, 1.345873, 0.714914, 0.863213, -0.379637, 1.305185, 0.669271, 0.886662, -0.362227,
+ 1.269147, 0.622935, 0.908504, -0.343068, 1.234714, 0.577757, 0.931425, -0.323982, 1.204997,
+ 0.532922, 0.953835, -0.304347, 1.178871, 0.488154, 0.975813, -0.284219, 1.155019, 0.444885,
+ 0.997662, -0.263544, 1.133941, 0.402224, 1.021167, -0.242611, 1.116100, 0.360530, 1.044038,
+ -0.220065, 1.098348, 0.318968, 1.068837, -0.197580, 1.084605, 0.279107, 1.092548, -0.174779,
+ 1.071217, 0.241111, 1.116157, -0.151596, 1.060486, 0.204913, 1.137486, -0.127478, 1.052751,
+ 0.171410, 1.154694, -0.101915, 1.044807, 0.137999, 1.166867, -0.076246, 1.034824, 0.103807,
+ 1.173715, -0.050661, 1.022501, 0.068802, 1.178236, -0.025355, 1.010324, 0.034155, 1.183545,
+ 0.000205, 1.000059, -0.000110, 0.000201, -0.000294, 3.161080, 1.466721, 0.000505, -0.000740,
+ 3.155526, 1.466737, 0.002016, -0.002957, 3.152852, 1.466688, 0.004537, -0.006655, 3.150654,
+ 1.466667, 0.008066, -0.011828, 3.153109, 1.466694, 0.012604, -0.018479, 3.152143, 1.466721,
+ 0.018150, -0.026598, 3.151025, 1.466636, 0.024714, -0.036191, 3.150300, 1.466562, 0.032301,
+ -0.047249, 3.149861, 1.466450, 0.040924, -0.059766, 3.149548, 1.466289, 0.050579, -0.073703,
+ 3.147516, 1.466055, 0.061306, -0.089022, 3.145680, 1.465738, 0.073135, -0.105563, 3.142428,
+ 1.465301, 0.086075, -0.123544, 3.139113, 1.464715, 0.100153, -0.142853, 3.135064, 1.463956,
+ 0.115411, -0.163183, 3.129509, 1.462962, 0.131876, -0.184760, 3.122959, 1.461670, 0.149570,
+ -0.207172, 3.114153, 1.460045, 0.168523, -0.230578, 3.103626, 1.457945, 0.188784, -0.254658,
+ 3.090818, 1.455279, 0.210264, -0.279114, 3.073352, 1.451998, 0.233030, -0.303930, 3.052592,
+ 1.447780, 0.256959, -0.328517, 3.025187, 1.442568, 0.281901, -0.352755, 2.990341, 1.436026,
+ 0.307728, -0.375894, 2.946820, 1.427979, 0.334197, -0.397924, 2.892845, 1.418249, 0.360966,
+ -0.417914, 2.827937, 1.406370, 0.388478, -0.436526, 2.758006, 1.392134, 0.415567, -0.452366,
+ 2.674696, 1.375244, 0.443518, -0.466917, 2.595136, 1.355660, 0.470631, -0.478417, 2.504173,
+ 1.333123, 0.497419, -0.487825, 2.413227, 1.308181, 0.523961, -0.495064, 2.321239, 1.280227,
+ 0.549708, -0.499844, 2.228911, 1.249894, 0.575296, -0.502844, 2.138834, 1.217130, 0.600168,
+ -0.503368, 2.049030, 1.181412, 0.625874, -0.501622, 1.962267, 1.142648, 0.652164, -0.496936,
+ 1.876900, 1.101268, 0.678029, -0.490319, 1.796344, 1.057782, 0.703248, -0.481575, 1.718925,
+ 1.012884, 0.728520, -0.471822, 1.648358, 0.966487, 0.752577, -0.460134, 1.581989, 0.919880,
+ 0.776163, -0.447164, 1.520109, 0.873087, 0.800016, -0.433601, 1.465081, 0.825803, 0.822176,
+ -0.418388, 1.412564, 0.778249, 0.844873, -0.402704, 1.366184, 0.730849, 0.865955, -0.385633,
+ 1.321865, 0.684037, 0.888173, -0.368255, 1.283464, 0.637192, 0.910994, -0.349332, 1.249215,
+ 0.590131, 0.934270, -0.329612, 1.218366, 0.543213, 0.956653, -0.309228, 1.189808, 0.497752,
+ 0.978476, -0.288310, 1.163674, 0.452837, 1.000755, -0.267243, 1.141389, 0.409481, 1.023827,
+ -0.246015, 1.122012, 0.367354, 1.045572, -0.223777, 1.103303, 0.325171, 1.070445, -0.200837,
+ 1.088010, 0.284442, 1.094268, -0.177211, 1.073650, 0.245138, 1.118639, -0.153531, 1.063051,
+ 0.208289, 1.139786, -0.129074, 1.053921, 0.173607, 1.157848, -0.104051, 1.045968, 0.140467,
+ 1.170697, -0.077694, 1.035782, 0.105594, 1.177874, -0.051393, 1.023483, 0.069898, 1.182242,
+ -0.025392, 1.010620, 0.034532, 1.187612, -0.000032, 1.000062, -0.000035, 0.000202, -0.000313,
+ 3.450327, 1.548291, 0.000504, -0.000780, 3.396162, 1.548289, 0.002015, -0.003120, 3.395621,
+ 1.548260, 0.004533, -0.007019, 3.394299, 1.548217, 0.008066, -0.012486, 3.398803, 1.548274,
+ 0.012600, -0.019500, 3.396363, 1.548245, 0.018151, -0.028076, 3.396805, 1.548192, 0.024722,
+ -0.038209, 3.396384, 1.548109, 0.032306, -0.049868, 3.395158, 1.547979, 0.040936, -0.063077,
+ 3.394303, 1.547785, 0.050610, -0.077791, 3.392979, 1.547513, 0.061360, -0.093869, 3.389910,
+ 1.547134, 0.073227, -0.111380, 3.386669, 1.546619, 0.086217, -0.130371, 3.382974, 1.545938,
+ 0.100364, -0.150684, 3.378046, 1.545039, 0.115733, -0.172116, 3.371719, 1.543880, 0.132309,
+ -0.194809, 3.363764, 1.542380, 0.150174, -0.218431, 3.353699, 1.540462, 0.169340, -0.242954,
+ 3.341397, 1.538002, 0.189788, -0.268175, 3.324957, 1.534894, 0.211581, -0.293776, 3.304776,
+ 1.530954, 0.234561, -0.319619, 3.278192, 1.526033, 0.258776, -0.345089, 3.244910, 1.519926,
+ 0.284059, -0.370176, 3.203338, 1.512296, 0.310312, -0.394171, 3.152477, 1.502956, 0.336748,
+ -0.416137, 3.083616, 1.491463, 0.364029, -0.436752, 3.010481, 1.477493, 0.391575, -0.455102,
+ 2.925454, 1.460933, 0.419409, -0.471378, 2.834380, 1.441554, 0.446811, -0.484714, 2.733329,
+ 1.418861, 0.474489, -0.496021, 2.633630, 1.393405, 0.501751, -0.504991, 2.530935, 1.364633,
+ 0.528488, -0.511392, 2.426653, 1.333234, 0.554428, -0.515395, 2.323633, 1.299138, 0.580434,
+ -0.517761, 2.224964, 1.262462, 0.605474, -0.517598, 2.127228, 1.223784, 0.629888, -0.514946,
+ 2.030545, 1.182321, 0.655579, -0.510177, 1.939070, 1.138515, 0.681940, -0.503097, 1.852355,
+ 1.091502, 0.707228, -0.493537, 1.768084, 1.043464, 0.731894, -0.482372, 1.690840, 0.994242,
+ 0.756741, -0.470312, 1.619277, 0.944749, 0.780160, -0.456412, 1.553430, 0.894816, 0.803384,
+ -0.441492, 1.493357, 0.845202, 0.826347, -0.425944, 1.437830, 0.795954, 0.849145, -0.409532,
+ 1.388578, 0.746915, 0.870617, -0.391988, 1.341527, 0.698025, 0.892943, -0.374229, 1.302188,
+ 0.649579, 0.913828, -0.355148, 1.262877, 0.601833, 0.936830, -0.335238, 1.230136, 0.554521,
+ 0.958687, -0.313939, 1.199596, 0.507208, 0.982008, -0.292741, 1.173619, 0.461357, 1.003691,
+ -0.270940, 1.149015, 0.416031, 1.027223, -0.249102, 1.128689, 0.372457, 1.050048, -0.226899,
+ 1.109444, 0.330281, 1.074105, -0.204329, 1.092943, 0.288987, 1.098971, -0.180560, 1.078591,
+ 0.249075, 1.123324, -0.155987, 1.066885, 0.211519, 1.145445, -0.130929, 1.057617, 0.176506,
+ 1.162856, -0.105269, 1.048453, 0.142345, 1.175360, -0.079267, 1.037439, 0.107452, 1.182514,
+ -0.052547, 1.024393, 0.071252, 1.186575, -0.025744, 1.011093, 0.035019, 1.192050, 0.000318,
+ 1.000013, -0.000152, 0.000204, -0.000334, 3.909175, 1.636412, 0.000504, -0.000825, 3.678647,
+ 1.636410, 0.002015, -0.003298, 3.678315, 1.636387, 0.004533, -0.007417, 3.674126, 1.636310,
+ 0.008062, -0.013190, 3.676771, 1.636376, 0.012603, -0.020613, 3.678135, 1.636369, 0.018153,
+ -0.029675, 3.677315, 1.636299, 0.024723, -0.040378, 3.676872, 1.636196, 0.032318, -0.052708,
+ 3.675750, 1.636038, 0.040955, -0.066660, 3.674803, 1.635810, 0.050645, -0.082203, 3.672735,
+ 1.635494, 0.061429, -0.099150, 3.669047, 1.635048, 0.073333, -0.117679, 3.665401, 1.634437,
+ 0.086388, -0.137725, 3.661315, 1.633634, 0.100620, -0.159081, 3.654992, 1.632571, 0.116087,
+ -0.181721, 3.647341, 1.631202, 0.132820, -0.205611, 3.637877, 1.629432, 0.150867, -0.230542,
+ 3.626333, 1.627161, 0.170234, -0.256239, 3.610671, 1.624266, 0.190981, -0.282751, 3.591685,
+ 1.620589, 0.213013, -0.309430, 3.565864, 1.615999, 0.236387, -0.336427, 3.534826, 1.610216,
+ 0.260943, -0.362931, 3.493984, 1.603047, 0.286497, -0.388644, 3.442075, 1.593920, 0.312769,
+ -0.412912, 3.375973, 1.582961, 0.339832, -0.435635, 3.299355, 1.569343, 0.367214, -0.456181,
+ 3.208994, 1.553137, 0.394935, -0.474325, 3.108910, 1.533791, 0.422935, -0.490318, 3.001767,
+ 1.511093, 0.451166, -0.503827, 2.891735, 1.485145, 0.478695, -0.514185, 2.773430, 1.455617,
+ 0.506313, -0.522502, 2.657639, 1.422946, 0.533427, -0.528119, 2.541132, 1.387843, 0.559942,
+ -0.531430, 2.426950, 1.349542, 0.585150, -0.531978, 2.312437, 1.309303, 0.610500, -0.531054,
+ 2.205966, 1.266280, 0.635380, -0.528058, 2.101993, 1.221709, 0.659852, -0.522751, 2.002950,
+ 1.175062, 0.685151, -0.515026, 1.908647, 1.125078, 0.710920, -0.505020, 1.819389, 1.074296,
+ 0.736066, -0.493268, 1.735806, 1.022420, 0.760503, -0.480032, 1.658607, 0.970230, 0.785091,
+ -0.465986, 1.589424, 0.917077, 0.807523, -0.449721, 1.522533, 0.864888, 0.830974, -0.433461,
+ 1.465416, 0.813006, 0.852659, -0.415808, 1.409076, 0.761689, 0.874841, -0.397855, 1.360758,
+ 0.711258, 0.896322, -0.379041, 1.316829, 0.661721, 0.918134, -0.360048, 1.278574, 0.612263,
+ 0.939356, -0.340108, 1.242200, 0.564369, 0.961025, -0.318877, 1.210305, 0.516506, 0.984371,
+ -0.297130, 1.183689, 0.469342, 1.006905, -0.274661, 1.157466, 0.423080, 1.029941, -0.252234,
+ 1.135066, 0.378315, 1.052751, -0.229268, 1.114518, 0.335169, 1.077981, -0.206662, 1.097760,
+ 0.293336, 1.102542, -0.183331, 1.082051, 0.252984, 1.126539, -0.158797, 1.068935, 0.214990,
+ 1.149023, -0.133014, 1.058996, 0.178903, 1.167550, -0.106641, 1.050245, 0.144559, 1.179994,
+ -0.079952, 1.038648, 0.108667, 1.187104, -0.053316, 1.025284, 0.072209, 1.191406, -0.026826,
+ 1.011453, 0.035833, 1.196748, 0.000226, 1.000034, -0.000061, 0.000200, -0.000346, 3.996419,
+ 1.732034, 0.000504, -0.000873, 4.000138, 1.732038, 0.002016, -0.003492, 4.002078, 1.732012,
+ 0.004538, -0.007859, 4.005626, 1.731962, 0.008064, -0.013963, 3.998500, 1.731999, 0.012590,
+ -0.021794, 3.995024, 1.732004, 0.018154, -0.031406, 3.999233, 1.731901, 0.024727, -0.042733,
+ 3.998497, 1.731774, 0.032327, -0.055781, 3.997064, 1.731599, 0.040974, -0.070543, 3.995856,
+ 1.731325, 0.050685, -0.086984, 3.993839, 1.730945, 0.061506, -0.104897, 3.989519, 1.730417,
+ 0.073458, -0.124506, 3.985313, 1.729697, 0.086573, -0.145706, 3.979984, 1.728747, 0.100909,
+ -0.168211, 3.972562, 1.727491, 0.116509, -0.192198, 3.963836, 1.725854, 0.133404, -0.217280,
+ 3.951919, 1.723749, 0.151659, -0.243556, 3.937734, 1.721093, 0.171288, -0.270611, 3.919021,
+ 1.717640, 0.192301, -0.298389, 3.895171, 1.713272, 0.214683, -0.326338, 3.864171, 1.707825,
+ 0.238392, -0.354394, 3.824682, 1.700956, 0.263151, -0.381636, 3.771168, 1.692392, 0.289155,
+ -0.408266, 3.709961, 1.681769, 0.315832, -0.433070, 3.630302, 1.668539, 0.342942, -0.455741,
+ 3.534719, 1.652513, 0.370892, -0.476655, 3.431531, 1.633428, 0.398985, -0.494692, 3.314933,
+ 1.610694, 0.427206, -0.510313, 3.189741, 1.584240, 0.455266, -0.522760, 3.058325, 1.554195,
+ 0.483472, -0.532872, 2.927213, 1.520805, 0.511192, -0.540229, 2.794112, 1.484026, 0.538706,
+ -0.545105, 2.663786, 1.443796, 0.565422, -0.547251, 2.534841, 1.401429, 0.591270, -0.547115,
+ 2.408437, 1.356231, 0.616787, -0.545113, 2.291284, 1.308887, 0.641380, -0.540853, 2.177478,
+ 1.260447, 0.665344, -0.534561, 2.069265, 1.210634, 0.690147, -0.527115, 1.969776, 1.158569,
+ 0.714578, -0.516171, 1.870847, 1.104593, 0.740349, -0.504048, 1.782674, 1.049578, 0.764563,
+ -0.489683, 1.698614, 0.994458, 0.788710, -0.474541, 1.624447, 0.938612, 0.812154, -0.458099,
+ 1.554453, 0.883694, 0.834566, -0.440345, 1.490045, 0.830220, 0.857486, -0.422491, 1.432889,
+ 0.776499, 0.879224, -0.403588, 1.380669, 0.724257, 0.899971, -0.383819, 1.333124, 0.673311,
+ 0.922111, -0.364250, 1.292648, 0.622999, 0.942842, -0.343873, 1.253933, 0.573304, 0.964398,
+ -0.323206, 1.221027, 0.525090, 0.986860, -0.301711, 1.191806, 0.477580, 1.009760, -0.278695,
+ 1.165162, 0.430624, 1.033347, -0.255591, 1.141715, 0.384482, 1.055937, -0.232039, 1.119739,
+ 0.340532, 1.081178, -0.208664, 1.102117, 0.297311, 1.105696, -0.184935, 1.085062, 0.256227,
+ 1.129575, -0.160673, 1.070918, 0.217709, 1.152135, -0.135414, 1.060642, 0.181471, 1.171221,
+ -0.108462, 1.051041, 0.146380, 1.184412, -0.081008, 1.039694, 0.110120, 1.191820, -0.053710,
+ 1.025903, 0.073052, 1.196195, -0.026625, 1.011816, 0.036129, 1.201677, -0.000175, 0.999945,
+ 0.000098, 0.000196, -0.000360, 4.100786, 1.836290, 0.000504, -0.000925, 4.370184, 1.836295,
+ 0.002018, -0.003706, 4.385247, 1.836243, 0.004534, -0.008324, 4.370146, 1.836210, 0.008064,
+ -0.014805, 4.372335, 1.836256, 0.012597, -0.023116, 4.359918, 1.836259, 0.018158, -0.033299,
+ 4.371503, 1.836123, 0.024732, -0.045301, 4.370533, 1.835988, 0.032344, -0.059143, 4.369649,
+ 1.835768, 0.040999, -0.074779, 4.367861, 1.835454, 0.050739, -0.092178, 4.364322, 1.834974,
+ 0.061594, -0.111161, 4.359221, 1.834355, 0.073604, -0.131958, 4.354620, 1.833499, 0.086796,
+ -0.154393, 4.347915, 1.832355, 0.101246, -0.178201, 4.339152, 1.830880, 0.116990, -0.203531,
+ 4.328327, 1.828936, 0.134086, -0.230043, 4.314240, 1.826442, 0.152589, -0.257718, 4.296795,
+ 1.823230, 0.172514, -0.286176, 4.273985, 1.819124, 0.193853, -0.315295, 4.244136, 1.813909,
+ 0.216582, -0.344507, 4.205152, 1.807410, 0.240668, -0.373646, 4.154781, 1.799084, 0.265904,
+ -0.401897, 4.091563, 1.788905, 0.292226, -0.429136, 4.013199, 1.776206, 0.319045, -0.454057,
+ 3.912886, 1.760500, 0.346721, -0.477219, 3.800927, 1.741586, 0.374849, -0.497883, 3.675652,
+ 1.718818, 0.403078, -0.515504, 3.536892, 1.692138, 0.431597, -0.530621, 3.391351, 1.661434,
+ 0.460246, -0.542852, 3.242817, 1.626989, 0.488899, -0.552238, 3.093685, 1.588582, 0.517215,
+ -0.559045, 2.944163, 1.546300, 0.544480, -0.562351, 2.794189, 1.501299, 0.571542, -0.563394,
+ 2.650239, 1.453758, 0.598167, -0.562590, 2.513757, 1.403321, 0.624104, -0.559636, 2.384203,
+ 1.352431, 0.648789, -0.554148, 2.259149, 1.298758, 0.672715, -0.546779, 2.140250, 1.244943,
+ 0.696258, -0.537896, 2.030401, 1.189971, 0.720048, -0.527401, 1.928311, 1.134526, 0.744078,
+ -0.514142, 1.830175, 1.076504, 0.768895, -0.499352, 1.740731, 1.018032, 0.792551, -0.482982,
+ 1.658911, 0.960250, 0.817007, -0.466406, 1.586579, 0.903029, 0.839035, -0.447616, 1.516969,
+ 0.846484, 0.862742, -0.429261, 1.458675, 0.791420, 0.884307, -0.409479, 1.402989, 0.737125,
+ 0.905641, -0.389303, 1.352817, 0.683912, 0.926185, -0.368344, 1.306684, 0.632690, 0.947229,
+ -0.347366, 1.267395, 0.581739, 0.969502, -0.326720, 1.233192, 0.532305, 0.990758, -0.304973,
+ 1.201017, 0.484166, 1.012749, -0.282816, 1.173018, 0.437385, 1.035533, -0.259084, 1.147184,
+ 0.390755, 1.059915, -0.235239, 1.125388, 0.345399, 1.084348, -0.211044, 1.105859, 0.301356,
+ 1.109544, -0.186698, 1.088888, 0.259708, 1.133770, -0.161900, 1.073848, 0.220324, 1.157553,
+ -0.136604, 1.063190, 0.183857, 1.176461, -0.110428, 1.053110, 0.148521, 1.190137, -0.082898,
+ 1.041484, 0.112124, 1.197215, -0.054554, 1.026844, 0.074160, 1.201654, -0.026744, 1.012264,
+ 0.036527, 1.207085, 0.000399, 1.000034, -0.000201, 0.000191, -0.000373, 4.194318, 1.950551,
+ 0.000504, -0.000983, 4.804350, 1.950552, 0.002015, -0.003931, 4.802820, 1.950518, 0.004536,
+ -0.008847, 4.805254, 1.950472, 0.008064, -0.015725, 4.804152, 1.950517, 0.012693, -0.024740,
+ 4.826828, 1.949914, 0.018159, -0.035365, 4.803103, 1.950349, 0.024740, -0.048122, 4.803220,
+ 1.950183, 0.032361, -0.062822, 4.801522, 1.949917, 0.041034, -0.079430, 4.799593, 1.949538,
+ 0.050815, -0.097841, 4.797179, 1.948972, 0.061702, -0.118026, 4.789557, 1.948246, 0.073766,
+ -0.140112, 4.783293, 1.947204, 0.087066, -0.163819, 4.775698, 1.945855, 0.101637, -0.189122,
+ 4.764612, 1.944052, 0.117558, -0.215884, 4.751486, 1.941710, 0.134884, -0.243968, 4.734791,
+ 1.938727, 0.153637, -0.273170, 4.712078, 1.934891, 0.173890, -0.303146, 4.683575, 1.929976,
+ 0.195643, -0.333704, 4.646766, 1.923740, 0.218767, -0.364170, 4.596814, 1.915888, 0.243337,
+ -0.394530, 4.535509, 1.905970, 0.268860, -0.423512, 4.452006, 1.893623, 0.295173, -0.450609,
+ 4.345682, 1.878286, 0.322784, -0.476488, 4.231632, 1.859391, 0.350616, -0.499420, 4.093553,
+ 1.836912, 0.379127, -0.519862, 3.944127, 1.809625, 0.407860, -0.537373, 3.782223, 1.778529,
+ 0.436717, -0.551802, 3.615563, 1.742684, 0.465345, -0.562951, 3.440672, 1.702289, 0.494158,
+ -0.571334, 3.268070, 1.658666, 0.522896, -0.577227, 3.100668, 1.611027, 0.551379, -0.580514,
+ 2.937615, 1.559742, 0.578992, -0.580610, 2.778703, 1.507257, 0.605095, -0.577729, 2.621626,
+ 1.451941, 0.630653, -0.573000, 2.476506, 1.395218, 0.656175, -0.566944, 2.341592, 1.337862,
+ 0.681036, -0.558988, 2.216478, 1.279275, 0.704713, -0.549211, 2.096972, 1.220526, 0.726894,
+ -0.537190, 1.983311, 1.161709, 0.749865, -0.524167, 1.881100, 1.102095, 0.773553, -0.508991,
+ 1.785637, 1.042039, 0.797102, -0.491658, 1.697234, 0.981588, 0.821187, -0.474093, 1.620250,
+ 0.921265, 0.843848, -0.454980, 1.547071, 0.862757, 0.866662, -0.435421, 1.482008, 0.804700,
+ 0.888696, -0.414990, 1.424116, 0.749432, 0.910945, -0.394472, 1.372658, 0.694767, 0.932300,
+ -0.373239, 1.325157, 0.641106, 0.952850, -0.351347, 1.282217, 0.589689, 0.974718, -0.329809,
+ 1.244897, 0.539322, 0.996445, -0.307902, 1.212306, 0.490083, 1.017580, -0.285392, 1.181402,
+ 0.442702, 1.040342, -0.262782, 1.155996, 0.395911, 1.064399, -0.238995, 1.131708, 0.350206,
+ 1.089464, -0.214297, 1.111215, 0.305175, 1.115565, -0.189293, 1.093094, 0.262686, 1.140640,
+ -0.163843, 1.077994, 0.223078, 1.163824, -0.137789, 1.066014, 0.185651, 1.182577, -0.111087,
+ 1.055615, 0.150045, 1.195775, -0.083945, 1.042940, 0.113457, 1.203175, -0.056145, 1.028015,
+ 0.075453, 1.207282, -0.027685, 1.012552, 0.037217, 1.213019, 0.000362, 0.999938, -0.000293,
+ 0.000187, -0.000388, 4.316009, 2.076500, 0.000504, -0.001048, 5.317799, 2.076499, 0.002014,
+ -0.004182, 5.306557, 2.076523, 0.004539, -0.009425, 5.317505, 2.076453, 0.008063, -0.016737,
+ 5.312143, 2.076410, 0.012614, -0.026171, 5.316434, 2.076389, 0.018158, -0.037641, 5.307836,
+ 2.076265, 0.024767, -0.051266, 5.315297, 2.076044, 0.032372, -0.066859, 5.307433, 2.075743,
+ 0.041066, -0.084538, 5.304809, 2.075270, 0.050871, -0.104062, 5.299277, 2.074622, 0.061821,
+ -0.125613, 5.293419, 2.073708, 0.073970, -0.149085, 5.286629, 2.072457, 0.087375, -0.174214,
+ 5.275937, 2.070804, 0.102105, -0.201136, 5.263267, 2.068647, 0.118223, -0.229505, 5.246309,
+ 2.065846, 0.135814, -0.259217, 5.225496, 2.062189, 0.154887, -0.289990, 5.196580, 2.057566,
+ 0.175510, -0.321618, 5.160716, 2.051593, 0.197636, -0.353632, 5.112202, 2.043949, 0.221168,
+ -0.385303, 5.046981, 2.034445, 0.246099, -0.416511, 4.965386, 2.022368, 0.272070, -0.446377,
+ 4.860735, 2.007160, 0.299090, -0.474279, 4.735140, 1.988598, 0.326702, -0.499809, 4.584962,
+ 1.965865, 0.355017, -0.522790, 4.420447, 1.938705, 0.383856, -0.542755, 4.241942, 1.906370,
+ 0.413059, -0.559903, 4.053302, 1.869455, 0.441882, -0.573174, 3.852753, 1.827946, 0.471516,
+ -0.584151, 3.660377, 1.781652, 0.500872, -0.591843, 3.466027, 1.730885, 0.529677, -0.596253,
+ 3.272812, 1.676821, 0.557683, -0.597604, 3.084286, 1.620064, 0.585652, -0.596591, 2.906111,
+ 1.560909, 0.612819, -0.593138, 2.738258, 1.500318, 0.639848, -0.588245, 2.584172, 1.438127,
+ 0.664758, -0.580140, 2.430697, 1.375746, 0.688754, -0.570189, 2.290701, 1.312727, 0.712848,
+ -0.559420, 2.162679, 1.250063, 0.735111, -0.546570, 2.042186, 1.187840, 0.757521, -0.532944,
+ 1.933435, 1.125513, 0.780056, -0.517981, 1.833524, 1.063827, 0.802513, -0.500724, 1.739053,
+ 1.002154, 0.825462, -0.481625, 1.652381, 0.939811, 0.848973, -0.462327, 1.577560, 0.878279,
+ 0.871521, -0.441928, 1.509291, 0.819200, 0.892325, -0.420297, 1.443799, 0.761607, 0.914935,
+ -0.399072, 1.389647, 0.705351, 0.936429, -0.377232, 1.339903, 0.650213, 0.957614, -0.355091,
+ 1.295467, 0.597773, 0.979578, -0.332767, 1.256692, 0.545914, 1.000860, -0.310147, 1.221666,
+ 0.495661, 1.022550, -0.287395, 1.190775, 0.448026, 1.045005, -0.264582, 1.162641, 0.400490,
+ 1.068703, -0.241464, 1.138358, 0.354088, 1.093098, -0.217504, 1.115973, 0.309812, 1.119230,
+ -0.192140, 1.096284, 0.266297, 1.144608, -0.165975, 1.080042, 0.225831, 1.168599, -0.139174,
+ 1.067749, 0.187761, 1.187970, -0.111910, 1.056635, 0.151322, 1.201240, -0.083978, 1.043566,
+ 0.114337, 1.208895, -0.056089, 1.028366, 0.076083, 1.213344, -0.028369, 1.013074, 0.037735,
+ 1.219220, -0.000534, 0.999968, 0.000076, 0.000182, -0.000404, 4.433519, 2.216201, 0.000504,
+ -0.001117, 5.911693, 2.216198, 0.002017, -0.004469, 5.919142, 2.216190, 0.004536, -0.010051,
+ 5.913172, 2.216130, 0.008065, -0.017867, 5.911791, 2.216145, 0.012467, -0.027603, 5.785357,
+ 2.216447, 0.018156, -0.040159, 5.901121, 2.215958, 0.024758, -0.054670, 5.908781, 2.215654,
+ 0.032395, -0.071352, 5.906098, 2.215283, 0.041108, -0.090201, 5.902558, 2.214715, 0.050955,
+ -0.111004, 5.895707, 2.213905, 0.061968, -0.134002, 5.888736, 2.212807, 0.074206, -0.159038,
+ 5.880633, 2.211303, 0.087742, -0.185801, 5.867001, 2.209297, 0.102652, -0.214368, 5.851446,
+ 2.206657, 0.119006, -0.244573, 5.830722, 2.203232, 0.136883, -0.276067, 5.802688, 2.198778,
+ 0.156335, -0.308660, 5.767185, 2.193091, 0.177396, -0.341940, 5.719726, 2.185858, 0.200070,
+ -0.375591, 5.658792, 2.176584, 0.224067, -0.408564, 5.573508, 2.164759, 0.249420, -0.440668,
+ 5.465696, 2.149777, 0.275879, -0.471138, 5.332207, 2.131225, 0.303307, -0.499204, 5.173339,
+ 2.108794, 0.331189, -0.524547, 4.985102, 2.080585, 0.359932, -0.547256, 4.785788, 2.047792,
+ 0.389063, -0.566479, 4.569344, 2.009518, 0.418725, -0.583031, 4.349557, 1.965601, 0.448181,
+ -0.595809, 4.121278, 1.916911, 0.477703, -0.605102, 3.892291, 1.863530, 0.507999, -0.612462,
+ 3.676557, 1.806286, 0.536889, -0.615451, 3.456241, 1.745841, 0.565778, -0.616029, 3.249464,
+ 1.681137, 0.593863, -0.613644, 3.050273, 1.615238, 0.620770, -0.608268, 2.859599, 1.548003,
+ 0.647171, -0.601116, 2.683287, 1.480447, 0.673458, -0.592840, 2.524036, 1.412084, 0.698064,
+ -0.581973, 2.371046, 1.345130, 0.721011, -0.568963, 2.229104, 1.278440, 0.744293, -0.555642,
+ 2.103213, 1.212448, 0.766314, -0.540934, 1.985370, 1.146287, 0.788164, -0.525271, 1.878842,
+ 1.082600, 0.809019, -0.507986, 1.779821, 1.019978, 0.830947, -0.489717, 1.691630, 0.956931,
+ 0.853732, -0.469345, 1.607513, 0.894207, 0.874904, -0.447618, 1.531176, 0.833436, 0.897289,
+ -0.426124, 1.467302, 0.773611, 0.919226, -0.404025, 1.408321, 0.716016, 0.940860, -0.381454,
+ 1.356209, 0.659515, 0.962764, -0.358901, 1.310082, 0.604629, 0.984322, -0.335983, 1.268485,
+ 0.552335, 1.005343, -0.312533, 1.230662, 0.501591, 1.028153, -0.289452, 1.199168, 0.452032,
+ 1.049283, -0.265754, 1.168575, 0.404347, 1.073687, -0.242571, 1.143533, 0.357445, 1.097546,
+ -0.218681, 1.119859, 0.312534, 1.123340, -0.194465, 1.099634, 0.269437, 1.148166, -0.168797,
+ 1.081968, 0.228586, 1.172518, -0.141552, 1.068789, 0.189866, 1.192930, -0.113325, 1.057548,
+ 0.152772, 1.206816, -0.084800, 1.044145, 0.115390, 1.215045, -0.056019, 1.028938, 0.076493,
+ 1.220048, -0.027733, 1.013338, 0.037767, 1.225852, 0.000050, 0.999927, -0.000160, 0.000178,
+ -0.000422, 4.587902, 2.372253, 0.000504, -0.001195, 6.624675, 2.372248, 0.002016, -0.004782,
+ 6.626884, 2.372187, 0.004531, -0.010746, 6.607379, 2.372318, 0.008081, -0.019161, 6.640102,
+ 2.372084, 0.012637, -0.029945, 6.653708, 2.372128, 0.018167, -0.042999, 6.623837, 2.371902,
+ 0.024769, -0.058516, 6.624484, 2.371595, 0.032421, -0.076370, 6.620877, 2.371120, 0.041164,
+ -0.096474, 6.615235, 2.370428, 0.051057, -0.118786, 6.607844, 2.369440, 0.062136, -0.143390,
+ 6.599216, 2.368075, 0.074490, -0.170034, 6.588018, 2.366218, 0.088179, -0.198717, 6.572526,
+ 2.363747, 0.103307, -0.229147, 6.551868, 2.360517, 0.119964, -0.261253, 6.526089, 2.356304,
+ 0.138173, -0.294703, 6.489593, 2.350797, 0.158072, -0.329261, 6.443573, 2.343783, 0.179592,
+ -0.364298, 6.379764, 2.334673, 0.202709, -0.399375, 6.295845, 2.323125, 0.227335, -0.433616,
+ 6.184929, 2.308547, 0.253230, -0.466794, 6.045905, 2.289980, 0.280100, -0.497509, 5.871803,
+ 2.266964, 0.308146, -0.525956, 5.672422, 2.239074, 0.336544, -0.551101, 5.443256, 2.204809,
+ 0.365223, -0.572471, 5.188034, 2.164827, 0.395484, -0.592088, 4.943783, 2.119489, 0.424416,
+ -0.606026, 4.666400, 2.067262, 0.455641, -0.619671, 4.418961, 2.009937, 0.485298, -0.627583,
+ 4.152737, 1.948900, 0.514774, -0.632072, 3.893344, 1.882692, 0.544172, -0.634033, 3.645332,
+ 1.814073, 0.573283, -0.633239, 3.414651, 1.742717, 0.602155, -0.630008, 3.195712, 1.669703,
+ 0.630520, -0.624550, 2.994536, 1.596021, 0.657121, -0.615749, 2.799373, 1.522572, 0.682071,
+ -0.604738, 2.616102, 1.448978, 0.707605, -0.593301, 2.456112, 1.376250, 0.731492, -0.579628,
+ 2.303517, 1.305297, 0.754139, -0.564473, 2.165340, 1.235548, 0.776505, -0.548787, 2.041646,
+ 1.167051, 0.796833, -0.531415, 1.923334, 1.100534, 0.817565, -0.513778, 1.818176, 1.035144,
+ 0.837981, -0.495167, 1.723830, 0.971583, 0.858513, -0.475690, 1.638448, 0.908841, 0.879892,
+ -0.454099, 1.559420, 0.846701, 0.902258, -0.432038, 1.491471, 0.785332, 0.924114, -0.409316,
+ 1.428878, 0.726409, 0.944230, -0.385618, 1.370785, 0.668588, 0.967001, -0.362604, 1.323529,
+ 0.612943, 0.988579, -0.339117, 1.279679, 0.559038, 1.010210, -0.315355, 1.240104, 0.506867,
+ 1.032084, -0.291408, 1.205261, 0.456934, 1.054671, -0.267387, 1.175197, 0.407792, 1.078314,
+ -0.243346, 1.148153, 0.360992, 1.102443, -0.219205, 1.123799, 0.315577, 1.128524, -0.194996,
+ 1.102624, 0.271742, 1.153989, -0.169897, 1.085134, 0.230702, 1.179420, -0.143960, 1.071699,
+ 0.192146, 1.200098, -0.116173, 1.060179, 0.155164, 1.214837, -0.086655, 1.046290, 0.117071,
+ 1.222749, -0.056956, 1.030040, 0.077450, 1.227273, -0.027883, 1.013650, 0.038092, 1.233293,
+ 0.000831, 1.000043, -0.000462, 0.000173, -0.000442, 4.741539, 2.547922, 0.000504, -0.001284,
+ 7.491127, 2.547919, 0.002014, -0.005132, 7.484889, 2.547844, 0.004523, -0.011521, 7.439875,
+ 2.547587, 0.008059, -0.020524, 7.483694, 2.547725, 0.012586, -0.032029, 7.470912, 2.547685,
+ 0.018081, -0.045948, 7.422534, 2.547686, 0.024783, -0.062844, 7.487581, 2.547107, 0.032451,
+ -0.082011, 7.483603, 2.546522, 0.041233, -0.103540, 7.475124, 2.545684, 0.051181, -0.127537,
+ 7.467521, 2.544438, 0.062347, -0.153921, 7.456266, 2.542744, 0.074829, -0.182427, 7.440422,
+ 2.540459, 0.088703, -0.213134, 7.420694, 2.537380, 0.104080, -0.245750, 7.394875, 2.533347,
+ 0.121050, -0.279941, 7.358515, 2.528069, 0.139697, -0.315591, 7.313001, 2.521237, 0.160036,
+ -0.351980, 7.246342, 2.512378, 0.182147, -0.388993, 7.163688, 2.500993, 0.205799, -0.425570,
+ 7.048339, 2.486450, 0.231091, -0.461093, 6.902586, 2.468174, 0.257405, -0.494668, 6.712721,
+ 2.444774, 0.284956, -0.525889, 6.491261, 2.415538, 0.313180, -0.553693, 6.232833, 2.380610,
+ 0.342327, -0.578724, 5.953834, 2.338525, 0.371689, -0.599706, 5.649698, 2.290256, 0.401919,
+ -0.617615, 5.347900, 2.235157, 0.432204, -0.631632, 5.036417, 2.173932, 0.463151, -0.643082,
+ 4.735976, 2.107298, 0.493388, -0.649970, 4.432044, 2.036121, 0.524128, -0.654188, 4.145472,
+ 1.961595, 0.553930, -0.654671, 3.866877, 1.883602, 0.583856, -0.653051, 3.607848, 1.804521,
+ 0.611762, -0.646994, 3.356237, 1.724047, 0.639117, -0.638860, 3.122531, 1.643016, 0.666279,
+ -0.629093, 2.913178, 1.563932, 0.692936, -0.617862, 2.722675, 1.484614, 0.716498, -0.603279,
+ 2.536926, 1.406734, 0.742273, -0.589878, 2.381054, 1.331469, 0.764031, -0.572744, 2.228312,
+ 1.256796, 0.786601, -0.555933, 2.095451, 1.185290, 0.807776, -0.537992, 1.972866, 1.115940,
+ 0.828400, -0.519596, 1.863394, 1.048371, 0.847412, -0.499847, 1.760630, 0.982934, 0.866850,
+ -0.479920, 1.670998, 0.919972, 0.886340, -0.459434, 1.587962, 0.858100, 0.906933, -0.437767,
+ 1.515505, 0.796714, 0.927490, -0.414068, 1.448243, 0.736162, 0.950217, -0.390910, 1.390505,
+ 0.677613, 0.971545, -0.366964, 1.337865, 0.620477, 0.992901, -0.342603, 1.291104, 0.565807,
+ 1.015460, -0.318596, 1.251138, 0.513086, 1.037859, -0.294242, 1.214291, 0.461573, 1.060535,
+ -0.269601, 1.182517, 0.411838, 1.086885, -0.245608, 1.155300, 0.363221, 1.111237, -0.220589,
+ 1.129715, 0.317174, 1.138718, -0.196008, 1.108103, 0.273213, 1.164223, -0.170408, 1.089640,
+ 0.231968, 1.187256, -0.144205, 1.074145, 0.192987, 1.207851, -0.116945, 1.061615, 0.156118,
+ 1.222217, -0.088852, 1.047599, 0.118674, 1.230315, -0.059381, 1.030869, 0.078993, 1.235052,
+ -0.029145, 1.014126, 0.038924, 1.241359, 0.000479, 1.000114, -0.000211, 0.000169, -0.000465,
+ 4.953966, 2.747437, 0.000504, -0.001384, 8.544530, 2.747430, 0.002015, -0.005537, 8.545147,
+ 2.747339, 0.004542, -0.012477, 8.557734, 2.747125, 0.008064, -0.022143, 8.530193, 2.747341,
+ 0.012543, -0.034411, 8.465151, 2.747411, 0.018178, -0.049792, 8.543328, 2.746874, 0.024810,
+ -0.067784, 8.547247, 2.746396, 0.032489, -0.088416, 8.537436, 2.745730, 0.041313, -0.111580,
+ 8.526655, 2.744596, 0.051332, -0.137462, 8.517438, 2.743082, 0.062603, -0.165860, 8.502803,
+ 2.740950, 0.075240, -0.196548, 8.481507, 2.738057, 0.089341, -0.229440, 8.454287, 2.734174,
+ 0.105021, -0.264395, 8.420289, 2.729086, 0.122399, -0.301020, 8.373503, 2.722420, 0.141526,
+ -0.338997, 8.309059, 2.713686, 0.162451, -0.377589, 8.221539, 2.702492, 0.185098, -0.416349,
+ 8.100116, 2.687893, 0.209406, -0.454284, 7.941704, 2.669386, 0.235098, -0.490450, 7.733318,
+ 2.645590, 0.262100, -0.524592, 7.486120, 2.615709, 0.290103, -0.555558, 7.193498, 2.579231,
+ 0.319135, -0.583516, 6.874796, 2.534957, 0.348286, -0.606714, 6.516118, 2.483017, 0.378840,
+ -0.627850, 6.163912, 2.424214, 0.409608, -0.644715, 5.801404, 2.357563, 0.440553, -0.657657,
+ 5.435955, 2.285835, 0.470599, -0.665621, 5.063481, 2.207940, 0.503172, -0.673767, 4.743532,
+ 2.126440, 0.533884, -0.676009, 4.413409, 2.040694, 0.563808, -0.674536, 4.092169, 1.953979,
+ 0.591849, -0.668913, 3.787057, 1.865897, 0.621474, -0.663159, 3.520578, 1.777762, 0.650500,
+ -0.655018, 3.275065, 1.689902, 0.678011, -0.643949, 3.043141, 1.603528, 0.703490, -0.630030,
+ 2.827104, 1.519484, 0.728250, -0.614910, 2.632620, 1.436677, 0.752165, -0.598649, 2.455570,
+ 1.355753, 0.775894, -0.581771, 2.295932, 1.278884, 0.797650, -0.563193, 2.152291, 1.202767,
+ 0.818505, -0.543750, 2.022099, 1.130338, 0.838596, -0.524017, 1.903562, 1.060263, 0.858396,
+ -0.504064, 1.797204, 0.993077, 0.877088, -0.483418, 1.701208, 0.928606, 0.896606, -0.462786,
+ 1.617736, 0.866039, 0.914342, -0.440943, 1.539227, 0.804293, 0.933550, -0.419129, 1.470383,
+ 0.745206, 0.955237, -0.396100, 1.409100, 0.685832, 0.976700, -0.371743, 1.354930, 0.627953,
+ 0.997681, -0.346882, 1.305249, 0.572127, 1.020784, -0.322391, 1.262603, 0.517941, 1.043840,
+ -0.297564, 1.225115, 0.466188, 1.067224, -0.272639, 1.190817, 0.415499, 1.092358, -0.247664,
+ 1.161265, 0.366782, 1.117573, -0.222260, 1.133935, 0.319377, 1.145730, -0.196933, 1.111750,
+ 0.275293, 1.170822, -0.170577, 1.091981, 0.233306, 1.194559, -0.143878, 1.075810, 0.193950,
+ 1.214819, -0.116347, 1.062438, 0.156724, 1.229830, -0.088233, 1.048092, 0.118984, 1.238185,
+ -0.059408, 1.031325, 0.079385, 1.243527, -0.030703, 1.014698, 0.039893, 1.249724, -0.001520,
+ 0.999819, 0.000760, 0.000164, -0.000489, 5.157359, 2.976300, 0.000505, -0.001502, 9.891415,
+ 2.976286, 0.002016, -0.006000, 9.857730, 2.976197, 0.004543, -0.013519, 9.870651, 2.975832,
+ 0.008064, -0.023985, 9.855780, 2.976170, 0.012611, -0.037471, 9.850209, 2.975941, 0.018162,
+ -0.053866, 9.827134, 2.974968, 0.024820, -0.073390, 9.849955, 2.975010, 0.032545, -0.095758,
+ 9.842021, 2.974073, 0.041418, -0.120834, 9.829989, 2.972700, 0.051511, -0.148861, 9.817421,
+ 2.970736, 0.062920, -0.179456, 9.797347, 2.968033, 0.075744, -0.212674, 9.771533, 2.964371,
+ 0.090131, -0.248193, 9.735924, 2.959437, 0.106187, -0.285748, 9.687707, 2.952881, 0.124035,
+ -0.325017, 9.622684, 2.944273, 0.143733, -0.365463, 9.531452, 2.933093, 0.165262, -0.406157,
+ 9.401732, 2.918484, 0.188622, -0.446833, 9.232451, 2.899529, 0.213693, -0.486209, 9.013432,
+ 2.875137, 0.239987, -0.522925, 8.725671, 2.844166, 0.267796, -0.557452, 8.400028, 2.805649,
+ 0.296547, -0.588266, 8.023041, 2.758720, 0.325838, -0.614837, 7.606773, 2.702676, 0.355479,
+ -0.636760, 7.160680, 2.638483, 0.386984, -0.657230, 6.736765, 2.566849, 0.418853, -0.673592,
+ 6.313742, 2.488091, 0.450302, -0.684966, 5.884479, 2.402458, 0.481149, -0.691591, 5.455771,
+ 2.311816, 0.512177, -0.695337, 5.055698, 2.217330, 0.543437, -0.696370, 4.681506, 2.121285,
+ 0.574309, -0.694186, 4.334716, 2.024160, 0.604787, -0.689158, 4.008524, 1.927738, 0.633483,
+ -0.680580, 3.703505, 1.830456, 0.660766, -0.669088, 3.418386, 1.734934, 0.688471, -0.656673,
+ 3.168101, 1.642316, 0.715729, -0.642820, 2.941735, 1.550744, 0.740435, -0.626155, 2.730570,
+ 1.463345, 0.764114, -0.608299, 2.537561, 1.378151, 0.787028, -0.589519, 2.364323, 1.297630,
+ 0.807985, -0.569257, 2.207970, 1.217830, 0.830663, -0.550055, 2.076646, 1.142746, 0.850416,
+ -0.528812, 1.948085, 1.070757, 0.869609, -0.507478, 1.834684, 1.001282, 0.888324, -0.486131,
+ 1.734879, 0.934987, 0.907482, -0.464910, 1.645974, 0.871203, 0.924829, -0.442742, 1.563550,
+ 0.809260, 0.942958, -0.420777, 1.491264, 0.750037, 0.961999, -0.398842, 1.428069, 0.691715,
+ 0.981043, -0.375967, 1.369668, 0.635669, 1.002371, -0.351469, 1.318588, 0.578689, 1.025343,
+ -0.326601, 1.273628, 0.524424, 1.048511, -0.301395, 1.234572, 0.471403, 1.072242, -0.275835,
+ 1.198354, 0.419950, 1.096758, -0.250200, 1.166392, 0.370733, 1.122781, -0.224474, 1.138991,
+ 0.322864, 1.150871, -0.198592, 1.114313, 0.277723, 1.177319, -0.171805, 1.093534, 0.234950,
+ 1.201765, -0.144291, 1.077462, 0.195376, 1.222629, -0.115949, 1.063288, 0.157315, 1.237334,
+ -0.087140, 1.048366, 0.118843, 1.246153, -0.058094, 1.031224, 0.079207, 1.252570, -0.029194,
+ 1.014695, 0.039376, 1.259060, -0.000418, 0.999881, 0.000307, 0.000159, -0.000515, 5.393984,
+ 3.241865, 0.000505, -0.001636, 11.548038, 3.241848, 0.002016, -0.006534, 11.506640, 3.241718,
+ 0.004537, -0.014706, 11.513460, 3.241196, 0.008068, -0.026134, 11.510533, 3.241693, 0.012573,
+ -0.040676, 11.428978, 3.241030, 0.018212, -0.058794, 11.510745, 3.240924, 0.024847, -0.079926,
+ 11.497339, 3.240201, 0.032603, -0.104160, 11.484607, 3.238994, 0.041543, -0.131552, 11.470801,
+ 3.237182, 0.051738, -0.162012, 11.453219, 3.234635, 0.063313, -0.195260, 11.427244, 3.231153,
+ 0.076381, -0.231205, 11.388534, 3.226361, 0.091096, -0.269678, 11.340406, 3.219943, 0.107600,
+ -0.310170, 11.270127, 3.211448, 0.126017, -0.352435, 11.178583, 3.200168, 0.146411, -0.395551,
+ 11.046559, 3.185328, 0.168663, -0.438627, 10.858624, 3.165972, 0.192730, -0.480660, 10.606379,
+ 3.140735, 0.218497, -0.520987, 10.288093, 3.108388, 0.245752, -0.558483, 9.907480, 3.067586,
+ 0.273993, -0.592090, 9.453246, 3.016931, 0.303495, -0.622416, 8.966138, 2.956444, 0.333717,
+ -0.648303, 8.443776, 2.885116, 0.363928, -0.668640, 7.894122, 2.805963, 0.396240, -0.687748,
+ 7.385728, 2.718338, 0.427161, -0.699903, 6.838511, 2.622346, 0.460175, -0.711210, 6.356371,
+ 2.522476, 0.492593, -0.717734, 5.878312, 2.417984, 0.524449, -0.719956, 5.423285, 2.310941,
+ 0.556010, -0.719127, 4.997909, 2.201885, 0.587032, -0.715077, 4.600426, 2.093330, 0.617030,
+ -0.707574, 4.235885, 1.986585, 0.644684, -0.695781, 3.881712, 1.881279, 0.674483, -0.685313,
+ 3.590960, 1.777918, 0.700290, -0.669619, 3.303138, 1.678004, 0.727892, -0.654728, 3.057771,
+ 1.581162, 0.751694, -0.635727, 2.826642, 1.487769, 0.776271, -0.617343, 2.622178, 1.399628,
+ 0.799502, -0.597683, 2.441265, 1.313195, 0.821768, -0.577090, 2.276954, 1.232316, 0.841960,
+ -0.555165, 2.125744, 1.153914, 0.861582, -0.532983, 1.991236, 1.079598, 0.881460, -0.510933,
+ 1.874027, 1.008883, 0.899952, -0.488321, 1.766812, 0.940802, 0.918954, -0.466405, 1.673436,
+ 0.875653, 0.936130, -0.443623, 1.586986, 0.813130, 0.954799, -0.421532, 1.513558, 0.752241,
+ 0.972435, -0.398897, 1.445787, 0.694711, 0.990147, -0.376302, 1.384382, 0.638770, 1.009189,
+ -0.353623, 1.331934, 0.583826, 1.029687, -0.330635, 1.284478, 0.530476, 1.052604, -0.305698,
+ 1.243632, 0.477187, 1.076524, -0.279917, 1.204997, 0.425349, 1.101701, -0.253951, 1.171750,
+ 0.375165, 1.127264, -0.227541, 1.142519, 0.326869, 1.156397, -0.201265, 1.116817, 0.280912,
+ 1.183020, -0.173943, 1.095289, 0.237447, 1.208448, -0.145860, 1.078296, 0.196694, 1.230417,
+ -0.116901, 1.064416, 0.158409, 1.248617, -0.087507, 1.050504, 0.119483, 1.257310, -0.057353,
+ 1.032796, 0.079092, 1.263076, -0.027785, 1.015128, 0.038883, 1.269870, 0.001331, 0.999935,
+ -0.000557, 0.000154, -0.000549, 5.705205, 3.554136, 0.000506, -0.001797, 13.703335, 3.554133,
+ 0.002014, -0.007156, 13.614074, 3.553937, 0.004544, -0.016145, 13.657344, 3.553096, 0.008070,
+ -0.028652, 13.627997, 3.553894, 0.012584, -0.044617, 13.606235, 3.554000, 0.018180, -0.064288,
+ 13.581339, 3.549637, 0.024887, -0.087627, 13.608851, 3.552006, 0.032690, -0.114134, 13.599099,
+ 3.550341, 0.041705, -0.144154, 13.579829, 3.547982, 0.052035, -0.177400, 13.552845, 3.544641,
+ 0.063810, -0.213813, 13.515619, 3.539941, 0.077171, -0.252978, 13.460460, 3.533696, 0.092329,
+ -0.294852, 13.393559, 3.524977, 0.109390, -0.338688, 13.292376, 3.513655, 0.128455, -0.384018,
+ 13.147332, 3.498484, 0.149661, -0.429960, 12.945774, 3.478323, 0.172694, -0.475024, 12.658979,
+ 3.451862, 0.197650, -0.518614, 12.289564, 3.417602, 0.224156, -0.559298, 11.828307, 3.372913,
+ 0.252008, -0.596110, 11.285162, 3.317454, 0.281165, -0.629292, 10.684922, 3.251171, 0.311434,
+ -0.658379, 10.052939, 3.172222, 0.342741, -0.683455, 9.405296, 3.082825, 0.373543, -0.701674,
+ 8.716078, 2.983976, 0.407008, -0.719664, 8.108425, 2.876244, 0.438623, -0.729882, 7.461252,
+ 2.763279, 0.471872, -0.738696, 6.880182, 2.645590, 0.504700, -0.743136, 6.324308, 2.524680,
+ 0.537118, -0.743676, 5.808302, 2.402723, 0.569412, -0.741181, 5.332306, 2.281437, 0.598202,
+ -0.732348, 4.857402, 2.161401, 0.629640, -0.724832, 4.465554, 2.043872, 0.659239, -0.713435,
+ 4.093661, 1.930129, 0.686547, -0.698539, 3.752593, 1.817654, 0.715529, -0.684471, 3.457593,
+ 1.712567, 0.739456, -0.664983, 3.171220, 1.610687, 0.764892, -0.646322, 2.929674, 1.512031,
+ 0.789301, -0.626393, 2.710719, 1.419033, 0.809881, -0.603498, 2.506139, 1.330115, 0.833385,
+ -0.582934, 2.336089, 1.245859, 0.854254, -0.560419, 2.178470, 1.165042, 0.873964, -0.537294,
+ 2.040087, 1.086633, 0.893433, -0.514264, 1.911969, 1.015028, 0.911756, -0.490657, 1.799840,
+ 0.944938, 0.930894, -0.467601, 1.703188, 0.878743, 0.948078, -0.444043, 1.612092, 0.815356,
+ 0.966162, -0.421155, 1.534444, 0.753883, 0.984166, -0.398238, 1.462397, 0.695534, 1.002184,
+ -0.375278, 1.400793, 0.638806, 1.019669, -0.352159, 1.344172, 0.584549, 1.039571, -0.329651,
+ 1.295227, 0.531660, 1.059989, -0.306804, 1.251281, 0.480529, 1.081116, -0.283345, 1.211504,
+ 0.430071, 1.105742, -0.258568, 1.176400, 0.380277, 1.133080, -0.232146, 1.144519, 0.331076,
+ 1.161888, -0.205244, 1.118059, 0.284040, 1.192408, -0.177932, 1.097561, 0.239958, 1.221043,
+ -0.149532, 1.082021, 0.198751, 1.244141, -0.120046, 1.067634, 0.160114, 1.259465, -0.089542,
+ 1.051626, 0.121101, 1.268124, -0.058593, 1.033296, 0.079898, 1.274330, -0.028011, 1.015382,
+ 0.039038, 1.281590, 0.002330, 1.000087, -0.001259, 0.000149, -0.000587, 6.059834, 3.927143,
+ 0.000507, -0.001992, 16.560400, 3.927149, 0.002014, -0.007910, 16.406326, 3.926821, 0.004549,
+ -0.017856, 16.545532, 3.927027, 0.008064, -0.031632, 16.375853, 3.925487, 0.012450, -0.048749,
+ 15.928564, 3.928272, 0.018030, -0.070371, 16.072989, 3.917862, 0.024964, -0.096897, 16.458925,
+ 3.924489, 0.032807, -0.126073, 16.377851, 3.921896, 0.041917, -0.159205, 16.351561, 3.918860,
+ 0.052416, -0.195762, 16.307037, 3.914339, 0.064464, -0.235784, 16.255514, 3.907954, 0.078225,
+ -0.278812, 16.176226, 3.899254, 0.093900, -0.324457, 16.066530, 3.887455, 0.111657, -0.372174,
+ 15.913818, 3.871777, 0.131478, -0.420530, 15.669197, 3.850776, 0.153574, -0.469330, 15.355453,
+ 3.822348, 0.177505, -0.516029, 14.908978, 3.785168, 0.203383, -0.560585, 14.352687, 3.736602,
+ 0.230569, -0.600607, 13.666022, 3.675046, 0.259188, -0.636296, 12.900244, 3.599811, 0.289272,
+ -0.668312, 12.111226, 3.510550, 0.320490, -0.695986, 11.292102, 3.408535, 0.353031, -0.719848,
+ 10.493485, 3.295667, 0.385228, -0.737073, 9.661955, 3.171998, 0.419219, -0.752419, 8.909942,
+ 3.042428, 0.452096, -0.761179, 8.155107, 2.907108, 0.484909, -0.766166, 7.450609, 2.769858,
+ 0.518306, -0.768596, 6.811866, 2.631935, 0.550067, -0.765683, 6.205275, 2.492870, 0.582562,
+ -0.761197, 5.663215, 2.358645, 0.614450, -0.753834, 5.165358, 2.227377, 0.644563, -0.742860,
+ 4.712554, 2.097547, 0.673658, -0.729294, 4.306101, 1.974920, 0.702857, -0.714839, 3.943352,
+ 1.857613, 0.729350, -0.696774, 3.609432, 1.743601, 0.754958, -0.677394, 3.308389, 1.636607,
+ 0.779575, -0.657018, 3.043803, 1.533841, 0.800491, -0.633342, 2.793592, 1.437092, 0.825030,
+ -0.612471, 2.590307, 1.344272, 0.847535, -0.589882, 2.406477, 1.256436, 0.865979, -0.564850,
+ 2.231999, 1.173938, 0.886254, -0.541357, 2.083556, 1.094722, 0.905566, -0.517353, 1.950928,
+ 1.021107, 0.924607, -0.493320, 1.835979, 0.948941, 0.943365, -0.469366, 1.731417, 0.881060,
+ 0.960405, -0.444745, 1.635838, 0.816479, 0.977893, -0.420493, 1.552981, 0.754604, 0.996573,
+ -0.397150, 1.481595, 0.694917, 1.014000, -0.373483, 1.414070, 0.638445, 1.031807, -0.349985,
+ 1.356031, 0.584035, 1.051877, -0.327062, 1.305041, 0.530010, 1.071701, -0.304134, 1.258836,
+ 0.479439, 1.093109, -0.280962, 1.217297, 0.429763, 1.116681, -0.258121, 1.182063, 0.381050,
+ 1.143886, -0.235365, 1.150039, 0.333395, 1.175163, -0.211621, 1.125074, 0.287477, 1.203675,
+ -0.184061, 1.102339, 0.243301, 1.230477, -0.154815, 1.083927, 0.201826, 1.253134, -0.124513,
+ 1.067989, 0.162271, 1.270092, -0.093383, 1.052032, 0.122855, 1.279576, -0.061770, 1.033685,
+ 0.081639, 1.286472, -0.030317, 1.015583, 0.040411, 1.294476, 0.000964, 1.000206, -0.000454,
+ 0.000144, -0.000630, 6.467978, 4.381146, 0.000504, -0.002208, 20.193617, 4.381151, 0.002017,
+ -0.008834, 20.206446, 4.380687, 0.004536, -0.019864, 20.183254, 4.380550, 0.008174, -0.035759,
+ 20.564249, 4.381247, 0.012608, -0.055034, 20.111612, 4.382390, 0.018198, -0.079119, 20.106096,
+ 4.379815, 0.025057, -0.108067, 20.215635, 4.376874, 0.032962, -0.140630, 20.153549, 4.374143,
+ 0.042199, -0.177350, 20.084061, 4.369558, 0.052928, -0.218094, 20.026609, 4.363287, 0.065327,
+ -0.262407, 19.940054, 4.354386, 0.079568, -0.309833, 19.806814, 4.342127, 0.095961, -0.360074,
+ 19.641878, 4.325533, 0.114516, -0.411747, 19.370914, 4.302950, 0.135349, -0.463726, 18.983900,
+ 4.271991, 0.158293, -0.514211, 18.433926, 4.230856, 0.183348, -0.562511, 17.733471, 4.176250,
+ 0.209959, -0.606310, 16.864214, 4.105895, 0.238736, -0.646958, 15.935207, 4.020104, 0.268543,
+ -0.681574, 14.890014, 3.916094, 0.299996, -0.712458, 13.846786, 3.798239, 0.331930, -0.737130,
+ 12.758296, 3.664191, 0.365222, -0.758156, 11.732940, 3.521867, 0.399061, -0.774364, 10.741743,
+ 3.369831, 0.433480, -0.786412, 9.812527, 3.212079, 0.467002, -0.792373, 8.915130, 3.053715,
+ 0.500754, -0.795410, 8.094276, 2.894526, 0.534023, -0.794617, 7.342067, 2.735959, 0.566988,
+ -0.790689, 6.664186, 2.581160, 0.599960, -0.784433, 6.052983, 2.432318, 0.630599, -0.773378,
+ 5.486277, 2.287630, 0.660807, -0.760334, 4.982516, 2.150183, 0.690103, -0.745430, 4.531104,
+ 2.017266, 0.717315, -0.727511, 4.120734, 1.891699, 0.743819, -0.708376, 3.759599, 1.772680,
+ 0.770147, -0.688632, 3.441912, 1.660620, 0.793510, -0.665931, 3.152600, 1.553166, 0.816535,
+ -0.643045, 2.898883, 1.452080, 0.839163, -0.619917, 2.674488, 1.355544, 0.859066, -0.594923,
+ 2.469262, 1.267232, 0.879489, -0.570343, 2.292209, 1.181702, 0.898525, -0.544975, 2.131086,
+ 1.102089, 0.918359, -0.520585, 1.994526, 1.024744, 0.937502, -0.496044, 1.873079, 0.951712,
+ 0.955573, -0.471010, 1.761232, 0.883374, 0.972957, -0.445712, 1.661604, 0.818008, 0.991248,
+ -0.421201, 1.577169, 0.754446, 1.008997, -0.396444, 1.499653, 0.694518, 1.028127, -0.372362,
+ 1.432030, 0.637259, 1.045710, -0.347895, 1.369870, 0.581515, 1.065977, -0.324409, 1.317341,
+ 0.527713, 1.087469, -0.301181, 1.270447, 0.476281, 1.109943, -0.277866, 1.228398, 0.426403,
+ 1.134440, -0.254849, 1.190986, 0.377822, 1.160986, -0.231754, 1.157681, 0.330740, 1.188458,
+ -0.207973, 1.128665, 0.286014, 1.214405, -0.183424, 1.103711, 0.243600, 1.239504, -0.157972,
+ 1.084253, 0.203686, 1.262961, -0.130607, 1.068258, 0.165214, 1.280340, -0.099652, 1.051919,
+ 0.126067, 1.292129, -0.067363, 1.034016, 0.084791, 1.299876, -0.035026, 1.015775, 0.042786,
+ 1.308328, -0.002944, 0.999963, 0.001385, 0.000138, -0.000681, 6.943771, 4.946556, 0.000503,
+ -0.002486, 25.346689, 4.946532, 0.002016, -0.009973, 25.494320, 4.946311, 0.004539, -0.022440,
+ 25.484949, 4.945823, 0.008069, -0.039836, 25.420902, 4.945311, 0.012628, -0.062172, 25.394403,
+ 4.945041, 0.018294, -0.089609, 25.440279, 4.943295, 0.025079, -0.121584, 25.399988, 4.939368,
+ 0.033142, -0.158595, 25.356537, 4.936200, 0.042596, -0.199971, 25.295067, 4.929842, 0.053628,
+ -0.245624, 25.196465, 4.920586, 0.066496, -0.295240, 25.055311, 4.907700, 0.081434, -0.348006,
+ 24.846170, 4.889647, 0.098640, -0.403167, 24.527803, 4.864680, 0.118231, -0.459106, 24.051735,
+ 4.830574, 0.140139, -0.513907, 23.352467, 4.783530, 0.164198, -0.565953, 22.418245, 4.720530,
+ 0.190502, -0.614858, 21.324049, 4.638075, 0.218530, -0.658304, 20.038671, 4.535464, 0.248094,
+ -0.696133, 18.639786, 4.411646, 0.279435, -0.729388, 17.234526, 4.268872, 0.312002, -0.757534,
+ 15.830426, 4.109603, 0.346173, -0.781866, 14.495901, 3.938782, 0.379435, -0.797579, 13.136444,
+ 3.756138, 0.414945, -0.812334, 11.946491, 3.571258, 0.449991, -0.821119, 10.811908, 3.384217,
+ 0.484636, -0.825066, 9.763482, 3.198076, 0.518675, -0.824728, 8.796811, 3.015808, 0.552559,
+ -0.821710, 7.932528, 2.836886, 0.587272, -0.817478, 7.185156, 2.664995, 0.616960, -0.804441,
+ 6.445302, 2.502223, 0.648054, -0.792063, 5.818812, 2.345851, 0.678575, -0.777793, 5.264731,
+ 2.197150, 0.707287, -0.760476, 4.766033, 2.056042, 0.735851, -0.742541, 4.335871, 1.922805,
+ 0.760594, -0.720503, 3.928021, 1.798585, 0.784534, -0.697719, 3.579153, 1.680605, 0.811029,
+ -0.677036, 3.285307, 1.568942, 0.831809, -0.651479, 3.001423, 1.465496, 0.854364, -0.627376,
+ 2.760672, 1.367849, 0.872639, -0.600496, 2.540697, 1.275644, 0.894296, -0.576297, 2.355273,
+ 1.188638, 0.913123, -0.550377, 2.188563, 1.105652, 0.932025, -0.524640, 2.040739, 1.028614,
+ 0.949876, -0.498402, 1.910315, 0.954421, 0.968933, -0.473220, 1.795750, 0.884061, 0.985366,
+ -0.447086, 1.690336, 0.817765, 1.004940, -0.422394, 1.599626, 0.753295, 1.022217, -0.396726,
+ 1.519055, 0.693380, 1.041490, -0.371854, 1.448745, 0.635747, 1.059920, -0.346769, 1.384292,
+ 0.579508, 1.080408, -0.322343, 1.328798, 0.525045, 1.101632, -0.297979, 1.279898, 0.473773,
+ 1.124812, -0.274059, 1.234005, 0.422949, 1.148503, -0.249954, 1.195373, 0.374609, 1.174554,
+ -0.225988, 1.160362, 0.327350, 1.202931, -0.201932, 1.131307, 0.283494, 1.229335, -0.176886,
+ 1.105885, 0.241092, 1.254254, -0.151225, 1.085802, 0.201514, 1.275743, -0.124282, 1.068524,
+ 0.162866, 1.292929, -0.097122, 1.051493, 0.124991, 1.305805, -0.068939, 1.033890, 0.085521,
+ 1.314991, -0.040082, 1.015927, 0.045247, 1.324033, -0.009923, 0.999893, 0.004738, 0.000131,
+ -0.000745, 7.562414, 5.671075, 0.000473, -0.002681, 27.216688, 5.670949, 0.002021, -0.011462,
+ 32.962402, 5.670177, 0.004540, -0.025728, 33.183949, 5.670197, 0.008087, -0.045746, 33.185688,
+ 5.667313, 0.012673, -0.071427, 33.170441, 5.668396, 0.018358, -0.102673, 33.145138, 5.665252,
+ 0.025299, -0.139780, 33.303326, 5.653404, 0.033469, -0.181718, 33.107243, 5.652829, 0.043139,
+ -0.228698, 32.859524, 5.645676, 0.054622, -0.280648, 32.694893, 5.631547, 0.068115, -0.336524,
+ 32.422569, 5.611561, 0.083957, -0.395671, 32.035511, 5.583449, 0.102259, -0.456164, 31.415047,
+ 5.543651, 0.123021, -0.515765, 30.470440, 5.488278, 0.146127, -0.572309, 29.186451, 5.413118,
+ 0.171749, -0.625710, 27.653852, 5.312369, 0.199549, -0.673853, 25.902435, 5.185774, 0.229188,
+ -0.715905, 23.978609, 5.030582, 0.260421, -0.751533, 21.999035, 4.853484, 0.293421, -0.782309,
+ 20.087366, 4.656137, 0.327077, -0.806332, 18.186535, 4.443975, 0.361892, -0.825818, 16.418409,
+ 4.223844, 0.397146, -0.840019, 14.774344, 3.998959, 0.434169, -0.852434, 13.321097, 3.775443,
+ 0.469288, -0.856632, 11.929448, 3.552818, 0.504319, -0.857130, 10.675201, 3.338825, 0.540067,
+ -0.855903, 9.591900, 3.130547, 0.575404, -0.851565, 8.607655, 2.932930, 0.606782, -0.839818,
+ 7.690560, 2.743876, 0.638660, -0.827508, 6.900781, 2.565115, 0.670577, -0.814154, 6.216821,
+ 2.395215, 0.696718, -0.793162, 5.551886, 2.238233, 0.725990, -0.775291, 5.015406, 2.090264,
+ 0.754140, -0.755758, 4.546843, 1.950834, 0.775992, -0.729824, 4.094254, 1.820582, 0.802990,
+ -0.708909, 3.732984, 1.699191, 0.828291, -0.686483, 3.413194, 1.583805, 0.847406, -0.659162,
+ 3.103861, 1.478093, 0.864951, -0.631051, 2.832976, 1.378496, 0.887154, -0.606590, 2.616645,
+ 1.282127, 0.906337, -0.580124, 2.413988, 1.194643, 0.927184, -0.554835, 2.244380, 1.110354,
+ 0.943810, -0.527583, 2.081964, 1.031996, 0.963630, -0.502243, 1.948979, 0.956718, 0.979691,
+ -0.475006, 1.822701, 0.886957, 0.997690, -0.448815, 1.715714, 0.819006, 1.016460, -0.423044,
+ 1.621868, 0.754892, 1.035485, -0.397637, 1.539537, 0.693707, 1.053165, -0.371775, 1.462285,
+ 0.634867, 1.072394, -0.346372, 1.396193, 0.578574, 1.093397, -0.321291, 1.338344, 0.524341,
+ 1.115194, -0.296102, 1.287594, 0.472059, 1.137943, -0.271023, 1.240495, 0.421674, 1.164163,
+ -0.246367, 1.201224, 0.371963, 1.191457, -0.221414, 1.164472, 0.325040, 1.220253, -0.196228,
+ 1.134325, 0.280343, 1.245456, -0.169991, 1.108214, 0.238098, 1.270647, -0.143314, 1.087277,
+ 0.197886, 1.292124, -0.115881, 1.069397, 0.159560, 1.309091, -0.087816, 1.051426, 0.120547,
+ 1.321130, -0.059301, 1.032904, 0.080834, 1.332484, -0.030912, 1.015767, 0.040933, 1.342834,
+ -0.002172, 0.999591, 0.001185, 0.000125, -0.000830, 8.392562, 6.634228, 0.000443, -0.002936,
+ 29.687805, 6.634032, 0.002016, -0.013374, 45.025234, 6.633008, 0.004540, -0.030089, 45.020294,
+ 6.633056, 0.008092, -0.053499, 45.066029, 6.626466, 0.012710, -0.083610, 44.810101, 6.630330,
+ 0.018485, -0.120260, 45.216747, 6.614516, 0.025134, -0.161031, 44.674168, 6.600349, 0.033897,
+ -0.212161, 44.819195, 6.610186, 0.043978, -0.266661, 44.450245, 6.593605, 0.056094, -0.326582,
+ 44.134544, 6.570142, 0.070528, -0.390342, 43.591648, 6.536712, 0.087498, -0.456162, 42.708160,
+ 6.488329, 0.107138, -0.521609, 41.365093, 6.420198, 0.129461, -0.584225, 39.525822, 6.323702,
+ 0.154245, -0.641931, 37.186111, 6.193606, 0.181228, -0.692829, 34.478470, 6.026897, 0.210711,
+ -0.738440, 31.680904, 5.825769, 0.242181, -0.777397, 28.828054, 5.595428, 0.275337, -0.809980,
+ 26.042755, 5.342321, 0.309698, -0.835990, 23.376804, 5.073076, 0.345702, -0.858077, 20.965754,
+ 4.794572, 0.382135, -0.874122, 18.710079, 4.516676, 0.419871, -0.887133, 16.713011, 4.241767,
+ 0.455609, -0.891199, 14.819674, 3.972124, 0.492617, -0.894082, 13.187921, 3.717271, 0.528186,
+ -0.891270, 11.708584, 3.471719, 0.563462, -0.885719, 10.422834, 3.237760, 0.596013, -0.874241,
+ 9.237741, 3.019060, 0.629455, -0.862814, 8.248549, 2.813572, 0.661110, -0.848126, 7.358398,
+ 2.621046, 0.690314, -0.829798, 6.569392, 2.441627, 0.720589, -0.812314, 5.905934, 2.274629,
+ 0.745631, -0.788704, 5.276800, 2.119423, 0.771488, -0.766133, 4.752773, 1.974380, 0.798704,
+ -0.744726, 4.306095, 1.839482, 0.820172, -0.718062, 3.889792, 1.713244, 0.844368, -0.693972,
+ 3.545456, 1.594809, 0.863128, -0.665748, 3.212762, 1.487512, 0.880094, -0.637003, 2.926572,
+ 1.386724, 0.904252, -0.613728, 2.704260, 1.288131, 0.920506, -0.585217, 2.483164, 1.199845,
+ 0.940919, -0.559603, 2.300348, 1.114958, 0.957044, -0.531597, 2.130516, 1.034754, 0.972648,
+ -0.503583, 1.979313, 0.960912, 0.994318, -0.478813, 1.859664, 0.889786, 1.008754, -0.450943,
+ 1.742705, 0.820833, 1.028667, -0.425516, 1.645220, 0.756332, 1.046145, -0.398977, 1.557184,
+ 0.693921, 1.067212, -0.373657, 1.480814, 0.635955, 1.084111, -0.346657, 1.408762, 0.578832,
+ 1.106749, -0.321392, 1.350468, 0.523561, 1.128440, -0.295773, 1.294865, 0.471146, 1.151073,
+ -0.270028, 1.246118, 0.420298, 1.178601, -0.244816, 1.204226, 0.370575, 1.206845, -0.219027,
+ 1.166896, 0.323716, 1.235963, -0.192622, 1.135756, 0.278058, 1.263030, -0.165331, 1.109240,
+ 0.235743, 1.288937, -0.137489, 1.088379, 0.195390, 1.310681, -0.108685, 1.068987, 0.156439,
+ 1.334352, -0.079710, 1.054273, 0.117096, 1.344847, -0.049947, 1.034598, 0.076554, 1.354943,
+ -0.020272, 1.016079, 0.035585, 1.365515, 0.009170, 0.999969, -0.004771, 0.000117, -0.000935,
+ 9.424866, 7.979243, 0.000410, -0.003275, 33.013195, 7.979422, 0.002009, -0.016024, 64.370331,
+ 7.977156, 0.004541, -0.036176, 64.655952, 7.976128, 0.008109, -0.064384, 64.864494, 7.964988,
+ 0.012694, -0.099984, 64.487198, 7.971348, 0.018554, -0.143991, 64.637970, 7.923116, 0.025303,
+ -0.192040, 61.930538, 7.953975, 0.035297, -0.259442, 66.274422, 7.921861, 0.045226, -0.318370,
+ 63.334690, 7.909609, 0.058370, -0.388821, 62.686401, 7.864696, 0.074083, -0.461667, 61.332054,
+ 7.801843, 0.092537, -0.533744, 59.125607, 7.708949, 0.113781, -0.601905, 55.997845, 7.575799,
+ 0.137786, -0.664409, 52.177567, 7.393524, 0.164770, -0.721193, 48.019485, 7.161756, 0.193894,
+ -0.768842, 43.460278, 6.882018, 0.225586, -0.810332, 39.086590, 6.564607, 0.259311, -0.845096,
+ 34.896049, 6.221983, 0.294517, -0.872849, 30.952213, 5.865831, 0.331163, -0.895159, 27.375792,
+ 5.507064, 0.368964, -0.912860, 24.213310, 5.149763, 0.407255, -0.925338, 21.364958, 4.806172,
+ 0.444704, -0.930956, 18.791691, 4.472272, 0.482041, -0.932576, 16.521160, 4.160864, 0.519572,
+ -0.931547, 14.589918, 3.865206, 0.556236, -0.926554, 12.887797, 3.590445, 0.590431, -0.915839,
+ 11.352402, 3.332747, 0.622723, -0.901266, 10.002660, 3.093264, 0.657029, -0.888747, 8.905210,
+ 2.873842, 0.686164, -0.868666, 7.876704, 2.666740, 0.719168, -0.853152, 7.051816, 2.479017,
+ 0.742294, -0.826169, 6.226034, 2.306498, 0.770320, -0.804936, 5.590831, 2.141328, 0.792337,
+ -0.777772, 4.984083, 1.994663, 0.819050, -0.755478, 4.507655, 1.853950, 0.837684, -0.726072,
+ 4.049884, 1.725590, 0.861324, -0.701424, 3.678201, 1.606303, 0.880741, -0.673615, 3.337163,
+ 1.495452, 0.903335, -0.648506, 3.055720, 1.391162, 0.920311, -0.619640, 2.792068, 1.294734,
+ 0.935769, -0.590245, 2.554566, 1.204518, 0.956592, -0.564944, 2.366468, 1.118630, 0.972424,
+ -0.536842, 2.187863, 1.038323, 0.986269, -0.508020, 2.023480, 0.963803, 1.006122, -0.482411,
+ 1.895137, 0.890986, 1.022504, -0.455110, 1.775886, 0.820936, 1.037905, -0.427450, 1.665951,
+ 0.758556, 1.059281, -0.402198, 1.577363, 0.696126, 1.076613, -0.375156, 1.493391, 0.636676,
+ 1.097828, -0.349577, 1.421129, 0.579947, 1.116671, -0.322955, 1.355205, 0.525140, 1.140514,
+ -0.297406, 1.299979, 0.471460, 1.166473, -0.271786, 1.249847, 0.420473, 1.192591, -0.245461,
+ 1.204625, 0.371118, 1.223349, -0.219412, 1.166686, 0.322600, 1.254833, -0.192660, 1.134121,
+ 0.277572, 1.285808, -0.165167, 1.108617, 0.234417, 1.322015, -0.137236, 1.093841, 0.194640,
+ 1.342172, -0.106871, 1.074616, 0.155001, 1.357238, -0.075759, 1.053550, 0.114648, 1.367725,
+ -0.044279, 1.033851, 0.073254, 1.379461, -0.013001, 1.015713, 0.031895, 1.391625, 0.018075,
+ 1.000203, -0.009397, 0.000109, -0.001093, 10.986820, 9.992467, 0.000378, -0.003779, 37.989063,
+ 9.992861, 0.002028, -0.020252, 101.850441, 9.988345, 0.004557, -0.045429, 101.106750, 9.983879,
+ 0.008115, -0.080453, 100.646606, 9.953411, 0.012864, -0.125836, 101.366592, 9.943727, 0.018734,
+ -0.179350, 100.786118, 9.908408, 0.026314, -0.243680, 99.779343, 9.821631, 0.035500, -0.313552,
+ 98.608231, 9.782450, 0.047562, -0.394644, 97.689568, 9.845875, 0.062065, -0.476697, 95.177795,
+ 9.755218, 0.079552, -0.557933, 91.095581, 9.615121, 0.099905, -0.632818, 85.110382, 9.408299,
+ 0.123231, -0.699926, 77.948921, 9.120996, 0.149980, -0.760671, 70.491119, 8.764173, 0.179550,
+ -0.812251, 62.821407, 8.341752, 0.211839, -0.855909, 55.512890, 7.876337, 0.246434, -0.892023,
+ 48.744549, 7.386268, 0.282317, -0.919200, 42.462059, 6.886009, 0.319580, -0.940333, 36.901031,
+ 6.400318, 0.360135, -0.962176, 32.353752, 5.937503, 0.397805, -0.969755, 27.996445, 5.489783,
+ 0.437077, -0.976494, 24.359192, 5.072855, 0.474388, -0.975265, 21.124300, 4.684682, 0.513695,
+ -0.975335, 18.476677, 4.326597, 0.551542, -0.970264, 16.167391, 3.999049, 0.587525, -0.960365,
+ 14.143442, 3.696317, 0.621251, -0.945944, 12.374341, 3.414176, 0.654738, -0.930709, 10.877112,
+ 3.160455, 0.685794, -0.911702, 9.580887, 2.921461, 0.717135, -0.892948, 8.481939, 2.707478,
+ 0.740798, -0.865086, 7.435941, 2.510382, 0.770920, -0.845137, 6.650625, 2.329648, 0.792303,
+ -0.815956, 5.879976, 2.163206, 0.818363, -0.792225, 5.274404, 2.008042, 0.837362, -0.762396,
+ 4.700960, 1.867576, 0.862266, -0.738465, 4.254798, 1.735819, 0.880069, -0.708890, 3.828697,
+ 1.614690, 0.896021, -0.678588, 3.451655, 1.503477, 0.920156, -0.654832, 3.168722, 1.395800,
+ 0.934948, -0.624740, 2.879533, 1.299955, 0.949686, -0.595203, 2.628258, 1.208597, 0.970989,
+ -0.570041, 2.433689, 1.122310, 0.985606, -0.541116, 2.241461, 1.042168, 1.000819, -0.512835,
+ 2.075567, 0.966543, 1.012209, -0.483024, 1.919932, 0.895758, 1.035320, -0.459125, 1.807884,
+ 0.825668, 1.052077, -0.432333, 1.695689, 0.760812, 1.070459, -0.406131, 1.595491, 0.699897,
+ 1.088704, -0.379721, 1.508512, 0.640575, 1.103817, -0.352104, 1.428159, 0.583765, 1.131711,
+ -0.328122, 1.366565, 0.528240, 1.156448, -0.302568, 1.306843, 0.473988, 1.181821, -0.276487,
+ 1.252861, 0.422189, 1.211347, -0.250540, 1.205265, 0.372005, 1.243636, -0.224264, 1.165943,
+ 0.324184, 1.283038, -0.198289, 1.137772, 0.278419, 1.316722, -0.170179, 1.115057, 0.235425,
+ 1.342715, -0.140095, 1.092994, 0.195084, 1.363288, -0.108794, 1.071875, 0.155439, 1.380656,
+ -0.076774, 1.052475, 0.114636, 1.394826, -0.044509, 1.032525, 0.072890, 1.408830, -0.011968,
+ 1.015459, 0.031101, 1.422370, 0.020555, 0.999808, -0.011002, 0.000100, -0.001334, 13.377127,
+ 13.342275, 0.000342, -0.004563, 45.758434, 13.342710, 0.002026, -0.027004, 179.672058,
+ 13.331846, 0.004559, -0.060563, 179.294235, 13.314877, 0.008232, -0.108154, 181.242035,
+ 13.222856, 0.013031, -0.167590, 179.684509, 13.153860, 0.019526, -0.242041, 181.004608,
+ 12.986094, 0.026364, -0.309289, 159.606293, 13.247752, 0.037670, -0.409755, 179.468521,
+ 12.368877, 0.051804, -0.512051, 167.955582, 12.981333, 0.068214, -0.601994, 156.278793,
+ 12.704532, 0.088295, -0.686849, 143.096878, 12.316531, 0.111478, -0.758670, 127.423111,
+ 11.793048, 0.138336, -0.821348, 111.763031, 11.157992, 0.168447, -0.873616, 96.887924,
+ 10.447472, 0.201411, -0.916322, 83.225327, 9.696606, 0.237443, -0.953090, 71.403137, 8.949244,
+ 0.274234, -0.977751, 60.739277, 8.225874, 0.314566, -1.003135, 52.115578, 7.547433, 0.353932,
+ -1.016312, 44.341869, 6.910326, 0.393858, -1.024848, 37.827263, 6.324401, 0.433805, -1.028950,
+ 32.380932, 5.790555, 0.475812, -1.034084, 27.955982, 5.312826, 0.513254, -1.026743, 23.977417,
+ 4.866118, 0.549965, -1.016740, 20.628025, 4.468437, 0.590300, -1.012030, 18.036856, 4.105483,
+ 0.626420, -0.998919, 15.669224, 3.780593, 0.658897, -0.979874, 13.603898, 3.482054, 0.687252,
+ -0.955238, 11.788331, 3.211213, 0.718941, -0.935663, 10.355552, 2.962083, 0.749877, -0.915206,
+ 9.131123, 2.741382, 0.772094, -0.884837, 7.973935, 2.536501, 0.799495, -0.861214, 7.086230,
+ 2.347282, 0.820136, -0.830976, 6.240769, 2.179332, 0.846715, -0.807408, 5.604792, 2.018005,
+ 0.865176, -0.776657, 4.975034, 1.877021, 0.881100, -0.744657, 4.442767, 1.743528, 0.907637,
+ -0.722088, 4.035177, 1.621563, 0.922239, -0.690432, 3.633160, 1.506158, 0.936558, -0.659650,
+ 3.281798, 1.403606, 0.950047, -0.629105, 2.974179, 1.304276, 0.961959, -0.598277, 2.704483,
+ 1.213888, 0.987410, -0.576085, 2.510453, 1.125569, 0.999996, -0.546494, 2.304016, 1.045567,
+ 1.014127, -0.518186, 2.127867, 0.970718, 1.036275, -0.494009, 1.985804, 0.897557, 1.049695,
+ -0.465659, 1.845074, 0.830584, 1.064617, -0.438159, 1.725130, 0.766083, 1.077131, -0.409813,
+ 1.613818, 0.705101, 1.101054, -0.385632, 1.528694, 0.644828, 1.122361, -0.360045, 1.447086,
+ 0.587878, 1.147359, -0.335186, 1.377588, 0.532130, 1.169881, -0.309040, 1.313673, 0.478843,
+ 1.200554, -0.284590, 1.257256, 0.426855, 1.232047, -0.259332, 1.208431, 0.376125, 1.275402,
+ -0.235215, 1.174692, 0.326614, 1.306595, -0.207508, 1.141042, 0.281524, 1.334304, -0.178290,
+ 1.111778, 0.238694, 1.364678, -0.148530, 1.090976, 0.198549, 1.387168, -0.117114, 1.069308,
+ 0.158529, 1.408657, -0.084977, 1.050625, 0.118042, 1.426214, -0.052052, 1.031444, 0.076541,
+ 1.444257, -0.018653, 1.014298, 0.034061, 1.460618, 0.015206, 0.999413, -0.008132, 0.000100,
+ -0.002003, 20.052612, 20.032721, 0.000297, -0.005947, 59.540512, 20.033842, 0.002022,
+ -0.040439, 404.848511, 20.032743, 0.004588, -0.090999, 403.741241, 19.910591, 0.008769,
+ -0.169802, 441.471558, 19.572552, 0.013708, -0.253629, 411.667816, 19.145721, 0.020331,
+ -0.349396, 371.322571, 18.591049, 0.030259, -0.468121, 385.816498, 18.331083, 0.045190,
+ -0.611444, 391.924133, 15.807686, 0.058476, -0.676875, 319.638641, 16.947781, 0.079894,
+ -0.781421, 278.804260, 17.512903, 0.103871, -0.855116, 235.999786, 16.290295, 0.131756,
+ -0.915747, 197.168076, 14.956566, 0.163487, -0.966333, 163.452347, 13.608010, 0.198693,
+ -1.008386, 135.632706, 12.299661, 0.236157, -1.039862, 111.919281, 11.088790, 0.274579,
+ -1.059988, 92.136581, 9.983883, 0.317164, -1.084069, 77.063034, 9.008505, 0.357624, -1.092124,
+ 63.963051, 8.127298, 0.399009, -1.097560, 53.483341, 7.347628, 0.441182, -1.100981, 45.052429,
+ 6.658191, 0.481606, -1.097318, 37.932640, 6.047333, 0.524253, -1.096570, 32.395638, 5.505878,
+ 0.564351, -1.088739, 27.679380, 5.018494, 0.600843, -1.073396, 23.611519, 4.580770, 0.635527,
+ -1.055024, 20.207081, 4.194785, 0.672045, -1.039775, 17.469036, 3.847436, 0.698372, -1.009545,
+ 14.928226, 3.532546, 0.729336, -0.987168, 12.953170, 3.248834, 0.761147, -0.966299, 11.346271,
+ 2.994166, 0.782270, -0.932841, 9.813129, 2.762244, 0.811832, -0.910431, 8.672224, 2.549933,
+ 0.832053, -0.878369, 7.578633, 2.363132, 0.849383, -0.844673, 6.648379, 2.189266, 0.866020,
+ -0.811703, 5.850784, 2.031716, 0.893083, -0.789181, 5.273372, 1.884480, 0.909212, -0.757541,
+ 4.700618, 1.750298, 0.923169, -0.725157, 4.196640, 1.627590, 0.937112, -0.693769, 3.764841,
+ 1.514906, 0.961901, -0.670828, 3.444598, 1.406839, 0.975245, -0.640240, 3.120745, 1.307873,
+ 0.989696, -0.611032, 2.840732, 1.216417, 1.002057, -0.581144, 2.591596, 1.132553, 1.014022,
+ -0.551620, 2.373820, 1.051695, 1.025307, -0.522268, 2.177992, 0.977500, 1.052190, -0.500826,
+ 2.042511, 0.904301, 1.064408, -0.472355, 1.891934, 0.837557, 1.077876, -0.444815, 1.761054,
+ 0.773004, 1.088939, -0.416531, 1.638939, 0.713958, 1.118551, -0.395057, 1.555724, 0.652485,
+ 1.134469, -0.368289, 1.465490, 0.596330, 1.162778, -0.345095, 1.390977, 0.539703, 1.185298,
+ -0.319527, 1.321225, 0.486250, 1.208419, -0.293590, 1.259318, 0.434178, 1.261013, -0.273471,
+ 1.219767, 0.382032, 1.297811, -0.248226, 1.176422, 0.334190, 1.326591, -0.220354, 1.139881,
+ 0.289075, 1.357918, -0.191937, 1.111418, 0.246259, 1.387590, -0.162282, 1.086511, 0.205129,
+ 1.415797, -0.131515, 1.067072, 0.165601, 1.440194, -0.099555, 1.047799, 0.125462, 1.465600,
+ -0.066957, 1.030406, 0.084082, 1.487714, -0.033496, 1.013889, 0.041981, 1.509947, 0.000663,
+ 0.998773, -0.000485, 0.000100, -0.004009, 40.102047, 40.087105, 0.000228, -0.009141, 91.431366,
+ 40.074432, 0.001522, -0.060544, 605.651733, 39.918827, 0.004919, -0.188871, 1712.982300,
+ 38.873421, 0.009053, -0.320325, 1583.453125, 39.715633, 0.015375, -0.471415, 1486.033691,
+ 39.162876, 0.029306, -0.735111, 1751.701050, 28.083200, 0.043450, -0.859759, 1392.475220,
+ 24.599945, 0.079075, -1.220033, 1629.972656, 18.507019, 0.090130, -1.091255, 940.347351,
+ 17.961655, 0.098008, -0.945965, 425.901093, 24.478010, 0.138246, -1.084105, 416.823944,
+ 20.003433, 0.174489, -1.133148, 302.730042, 18.550846, 0.207969, -1.138483, 242.853577,
+ 15.923334, 0.249132, -1.168197, 191.649445, 13.940813, 0.291391, -1.187038, 152.910309,
+ 12.263267, 0.332856, -1.192793, 121.905075, 10.822873, 0.377473, -1.202846, 99.145561,
+ 9.618412, 0.422601, -1.208871, 81.343315, 8.591735, 0.465276, -1.204545, 66.742569, 7.692911,
+ 0.504710, -1.190839, 54.787876, 6.915612, 0.544909, -1.178827, 45.507313, 6.242786, 0.582125,
+ -1.160590, 37.819912, 5.651690, 0.620694, -1.145481, 31.926588, 5.123660, 0.659127, -1.130178,
+ 27.147310, 4.669475, 0.684358, -1.093728, 22.650702, 4.258717, 0.719453, -1.074591, 19.454103,
+ 3.901225, 0.751695, -1.051678, 16.735672, 3.576870, 0.775082, -1.017716, 14.281039, 3.287471,
+ 0.796233, -0.982759, 12.261332, 3.023708, 0.827404, -0.961227, 10.767912, 2.787740, 0.848149,
+ -0.928433, 9.371350, 2.570737, 0.864891, -0.892838, 8.142364, 2.379204, 0.880979, -0.858193,
+ 7.118954, 2.204470, 0.910434, -0.837281, 6.389041, 2.041554, 0.925396, -0.803638, 5.643217,
+ 1.893353, 0.942463, -0.772925, 5.031223, 1.757331, 0.955217, -0.739720, 4.486978, 1.633572,
+ 0.968570, -0.708048, 4.014621, 1.520414, 0.981672, -0.677109, 3.617768, 1.412506, 0.992829,
+ -0.645712, 3.258773, 1.317079, 1.021270, -0.625746, 3.006640, 1.222611, 1.031247, -0.594628,
+ 2.733073, 1.137911, 1.043581, -0.565540, 2.498495, 1.058439, 1.055930, -0.536962, 2.289843,
+ 0.984428, 1.066727, -0.508076, 2.108603, 0.912794, 1.081225, -0.481297, 1.951454, 0.845536,
+ 1.088198, -0.451563, 1.801891, 0.782718, 1.123316, -0.433247, 1.704316, 0.721664, 1.133206,
+ -0.404812, 1.586153, 0.662761, 1.152889, -0.379901, 1.490958, 0.606866, 1.188158, -0.359421,
+ 1.415730, 0.550666, 1.217064, -0.336049, 1.344172, 0.496748, 1.257727, -0.314816, 1.283196,
+ 0.443538, 1.286647, -0.289530, 1.225903, 0.394018, 1.308729, -0.262053, 1.173928, 0.346255,
+ 1.351453, -0.237704, 1.139992, 0.300393, 1.380284, -0.209733, 1.105997, 0.256661, 1.414621,
+ -0.181613, 1.082109, 0.215429, 1.453045, -0.152797, 1.063853, 0.177098, 1.481066, -0.121803,
+ 1.043185, 0.137203, 1.514113, -0.090250, 1.027072, 0.096998, 1.547317, -0.057603, 1.012551,
+ 0.055328, 1.577983, -0.023799, 0.999267, 0.013094, 0.000108, -0.124970, 1249.704346,
+ 1249.703491, 0.000140, -0.119585, 1195.855469, 1195.854370, 0.003995, -0.927433, 9274.246094,
+ 232.443573, 0.012013, -1.131580, 11315.999023, 98.211105, 0.023892, -1.216018, 12162.739258,
+ 67.214500, 0.047506, -1.517865, 15186.294922, 42.410069, 0.082523, -1.812564, 18145.718750,
+ 24.421545, 0.112452, -1.805072, 11112.966797, 18.450365, 0.164460, -2.016784, 8086.032715,
+ 14.043465, 0.195870, -1.898199, 4245.658203, 13.178202, 0.197797, -1.556158, 1315.561768,
+ 30.760096, 0.219540, -1.433455, 802.380371, 25.037956, 0.268696, -1.483235, 579.715515,
+ 20.975695, 0.265968, -1.261051, 386.583649, 12.017023, 0.325369, -1.343349, 316.795959,
+ 12.612406, 0.387968, -1.411606, 232.491623, 13.296940, 0.435543, -1.411236, 181.515228,
+ 11.646996, 0.482729, -1.405722, 143.425354, 10.265131, 0.531742, -1.402782, 114.920082,
+ 9.114828, 0.559383, -1.346165, 88.589005, 8.089214, 0.607851, -1.342407, 73.056610, 7.249064,
+ 0.656928, -1.338238, 60.826897, 6.531094, 0.681212, -1.285692, 48.727219, 5.868711, 0.729238,
+ -1.279951, 41.256016, 5.324553, 0.751172, -1.230045, 33.728260, 4.816513, 0.773107, -1.184288,
+ 27.913816, 4.377203, 0.815726, -1.171653, 24.065962, 3.999965, 0.837886, -1.130636, 20.254860,
+ 3.658493, 0.857674, -1.089071, 17.138168, 3.347930, 0.876120, -1.048303, 14.572968, 3.072666,
+ 0.893935, -1.009040, 12.496377, 2.825165, 0.927998, -0.989064, 11.040731, 2.605520, 0.928445,
+ -0.935017, 9.365102, 2.401481, 0.945279, -0.899993, 8.177711, 2.222282, 0.959378, -0.863854,
+ 7.155303, 2.059342, 0.971761, -0.827684, 6.284632, 1.909314, 0.987812, -0.795878, 5.583837,
+ 1.771094, 1.001958, -0.763540, 4.962345, 1.645968, 1.014357, -0.730897, 4.435898, 1.527438,
+ 1.025946, -0.698675, 3.973241, 1.421337, 1.036435, -0.666662, 3.568025, 1.323677, 1.046807,
+ -0.635466, 3.218647, 1.232678, 1.052974, -0.602660, 2.902273, 1.147675, 1.086089, -0.585364,
+ 2.694939, 1.068352, 1.094660, -0.554784, 2.454491, 0.993445, 1.117131, -0.531500, 2.270746,
+ 0.923758, 1.114009, -0.496581, 2.063934, 0.858381, 1.137328, -0.473914, 1.917990, 0.794980,
+ 1.158671, -0.450127, 1.786523, 0.735697, 1.177878, -0.425306, 1.662454, 0.677498, 1.207510,
+ -0.403797, 1.559058, 0.621762, 1.244496, -0.383812, 1.466801, 0.566190, 1.240412, -0.351080,
+ 1.366853, 0.514288, 1.321257, -0.341200, 1.309808, 0.464621, 1.336512, -0.312710, 1.241822,
+ 0.413228, 1.365047, -0.286935, 1.186612, 0.366092, 1.418984, -0.265184, 1.152120, 0.321528,
+ 1.388864, -0.227750, 1.089937, 0.271827, 1.464383, -0.207168, 1.077271, 0.232838, 1.473125,
+ -0.175770, 1.041835, 0.193289, 1.542908, -0.150424, 1.036794, 0.156153, 1.563005, -0.118748,
+ 1.013029, 0.114866, 1.637048, -0.089604, 1.013493, 0.076804, 1.670777, -0.056398, 0.999208,
+ 0.032691,
+};
+static float ltc_mag_ggx[64 * 64] = {
+ 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
+ 1.000000, 1.000000, 1.000000, 0.999995, 0.999990, 0.999971, 0.999937, 0.999853, 0.999670,
+ 0.999138, 0.996746, 0.979578, 0.979309, 0.978836, 0.977972, 0.976223, 0.972205, 0.962466,
+ 0.953919, 0.949829, 0.942492, 0.929870, 0.921319, 0.911112, 0.896015, 0.885105, 0.869971,
+ 0.855017, 0.838328, 0.821241, 0.802352, 0.783873, 0.763309, 0.743058, 0.721929, 0.699755,
+ 0.677721, 0.655456, 0.632681, 0.609629, 0.586831, 0.564287, 0.541772, 0.519428, 0.497353,
+ 0.475624, 0.454606, 0.434099, 0.414085, 0.394605, 0.375698, 0.357386, 0.339871, 0.323085,
+ 0.306905, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
+ 0.999999, 0.999999, 0.999998, 0.999995, 0.999990, 0.999980, 0.999959, 0.999923, 0.999842,
+ 0.999660, 0.999119, 0.996613, 0.981824, 0.979298, 0.978826, 0.977957, 0.976184, 0.972091,
+ 0.962188, 0.953875, 0.949746, 0.942335, 0.930166, 0.921211, 0.910927, 0.896979, 0.884940,
+ 0.869864, 0.854835, 0.838200, 0.821049, 0.802552, 0.783659, 0.763512, 0.742927, 0.721715,
+ 0.699938, 0.677775, 0.655246, 0.632555, 0.609805, 0.586996, 0.564225, 0.541606, 0.519346,
+ 0.497419, 0.475863, 0.454738, 0.434099, 0.414003, 0.394547, 0.375747, 0.357564, 0.340012,
+ 0.323099, 0.306861, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
+ 1.000000, 1.000000, 0.999999, 0.999998, 0.999995, 0.999991, 0.999979, 0.999959, 0.999917,
+ 0.999839, 0.999648, 0.999074, 0.996168, 0.983770, 0.979279, 0.978800, 0.977905, 0.976058,
+ 0.971727, 0.962120, 0.953901, 0.949485, 0.941859, 0.930911, 0.920853, 0.910394, 0.897600,
+ 0.884427, 0.870101, 0.854522, 0.838325, 0.820754, 0.802707, 0.783223, 0.763605, 0.742872,
+ 0.721565, 0.699935, 0.677726, 0.655242, 0.632580, 0.609766, 0.586946, 0.564275, 0.541759,
+ 0.519467, 0.497478, 0.475886, 0.454794, 0.434233, 0.414207, 0.394751, 0.375892, 0.357683,
+ 0.340146, 0.323287, 0.307095, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
+ 1.000000, 0.999999, 0.999999, 0.999998, 0.999996, 0.999992, 0.999987, 0.999975, 0.999953,
+ 0.999913, 0.999830, 0.999630, 0.998993, 0.995279, 0.985142, 0.979252, 0.978754, 0.977821,
+ 0.975838, 0.971088, 0.962563, 0.954785, 0.949048, 0.941052, 0.931420, 0.920812, 0.909750,
+ 0.897867, 0.883856, 0.870091, 0.854353, 0.838166, 0.820661, 0.802465, 0.783308, 0.763346,
+ 0.742734, 0.721608, 0.699747, 0.677626, 0.655245, 0.632547, 0.609793, 0.587044, 0.564340,
+ 0.541779, 0.519529, 0.497633, 0.476114, 0.455030, 0.434430, 0.414406, 0.394974, 0.376154,
+ 0.357979, 0.340443, 0.323572, 0.307379, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000,
+ 1.000000, 1.000000, 1.000000, 0.999998, 0.999998, 0.999996, 0.999991, 0.999984, 0.999970,
+ 0.999946, 0.999905, 0.999815, 0.999599, 0.998856, 0.993704, 0.986135, 0.979212, 0.978690,
+ 0.977691, 0.975504, 0.970133, 0.962951, 0.955649, 0.948405, 0.940418, 0.931660, 0.920881,
+ 0.909376, 0.897785, 0.883844, 0.869756, 0.854326, 0.837732, 0.820617, 0.802053, 0.783195,
+ 0.763119, 0.742610, 0.721344, 0.699709, 0.677624, 0.655114, 0.632523, 0.609812, 0.587052,
+ 0.564417, 0.541966, 0.519751, 0.497824, 0.476309, 0.455271, 0.434735, 0.414736, 0.395317,
+ 0.376524, 0.358364, 0.340852, 0.323988, 0.307786, 1.000000, 1.000000, 1.000000, 1.000000,
+ 1.000000, 1.000000, 0.999999, 0.999999, 0.999997, 0.999996, 0.999994, 0.999989, 0.999980,
+ 0.999965, 0.999940, 0.999895, 0.999796, 0.999559, 0.998638, 0.992774, 0.986878, 0.980297,
+ 0.978602, 0.977514, 0.975026, 0.969169, 0.963214, 0.956267, 0.947689, 0.940054, 0.931637,
+ 0.920678, 0.908990, 0.897349, 0.883905, 0.869139, 0.854177, 0.837476, 0.820295, 0.801977,
+ 0.782798, 0.762978, 0.742418, 0.721193, 0.699560, 0.677402, 0.655108, 0.632543, 0.609804,
+ 0.587158, 0.564557, 0.542096, 0.519908, 0.498088, 0.476632, 0.455623, 0.435104, 0.415161,
+ 0.395783, 0.377005, 0.358843, 0.341345, 0.324529, 0.308355, 1.000000, 1.000000, 1.000000,
+ 1.000000, 1.000000, 0.999999, 0.999999, 0.999998, 0.999997, 0.999992, 0.999991, 0.999985,
+ 0.999977, 0.999959, 0.999935, 0.999878, 0.999773, 0.999505, 0.998284, 0.992353, 0.987457,
+ 0.981665, 0.978492, 0.977277, 0.974360, 0.968716, 0.963373, 0.956629, 0.947397, 0.939657,
+ 0.931339, 0.920588, 0.908975, 0.896712, 0.883763, 0.868890, 0.853731, 0.837333, 0.819702,
+ 0.801738, 0.782454, 0.762712, 0.742024, 0.721037, 0.699325, 0.677359, 0.655030, 0.632439,
+ 0.609869, 0.587221, 0.564663, 0.542328, 0.520220, 0.498400, 0.476997, 0.456053, 0.435593,
+ 0.415658, 0.396300, 0.377577, 0.359473, 0.342004, 0.325170, 0.308997, 1.000000, 1.000000,
+ 1.000000, 1.000000, 1.000000, 0.999999, 0.999998, 0.999998, 0.999996, 0.999993, 0.999988,
+ 0.999981, 0.999971, 0.999951, 0.999921, 0.999863, 0.999748, 0.999433, 0.997681, 0.992120,
+ 0.987920, 0.982864, 0.978353, 0.976961, 0.973451, 0.968396, 0.963400, 0.956680, 0.947529,
+ 0.939151, 0.930747, 0.920511, 0.908867, 0.896142, 0.883335, 0.868764, 0.853025, 0.837015,
+ 0.819452, 0.801249, 0.782176, 0.762345, 0.741843, 0.720721, 0.699135, 0.677194, 0.654889,
+ 0.632487, 0.609902, 0.587328, 0.564891, 0.542567, 0.520501, 0.498793, 0.477442, 0.456528,
+ 0.436131, 0.416273, 0.396980, 0.378276, 0.360176, 0.342738, 0.325950, 0.309803, 1.000000,
+ 1.000000, 1.000000, 1.000000, 0.999999, 0.999998, 0.999999, 0.999997, 0.999995, 0.999991,
+ 0.999985, 0.999978, 0.999963, 0.999942, 0.999907, 0.999844, 0.999715, 0.999332, 0.996612,
+ 0.991974, 0.988297, 0.983843, 0.978349, 0.976540, 0.972351, 0.968109, 0.963280, 0.956464,
+ 0.947779, 0.938754, 0.929952, 0.920253, 0.908530, 0.895785, 0.882679, 0.868456, 0.852669,
+ 0.836406, 0.819138, 0.800708, 0.781803, 0.761855, 0.741534, 0.720405, 0.698959, 0.676964,
+ 0.654827, 0.632411, 0.609922, 0.587477, 0.565051, 0.542829, 0.520889, 0.499225, 0.477951,
+ 0.457148, 0.436792, 0.416963, 0.397723, 0.379068, 0.361025, 0.343608, 0.326842, 0.310718,
+ 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 0.999999, 0.999998, 0.999995, 0.999994,
+ 0.999990, 0.999983, 0.999971, 0.999954, 0.999932, 0.999892, 0.999820, 0.999675, 0.999190,
+ 0.995492, 0.991911, 0.988610, 0.984662, 0.979221, 0.975975, 0.971671, 0.967788, 0.963002,
+ 0.955938, 0.947965, 0.938692, 0.929309, 0.919781, 0.908268, 0.895518, 0.882022, 0.867884,
+ 0.852346, 0.835746, 0.818607, 0.800261, 0.781335, 0.761539, 0.741063, 0.720116, 0.698617,
+ 0.676815, 0.654700, 0.632389, 0.610037, 0.587591, 0.565328, 0.543205, 0.521293, 0.499745,
+ 0.478562, 0.457776, 0.437515, 0.417776, 0.398586, 0.379963, 0.361984, 0.344616, 0.327857,
+ 0.311751, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 0.999999, 0.999997, 0.999996,
+ 0.999992, 0.999986, 0.999977, 0.999965, 0.999947, 0.999916, 0.999873, 0.999794, 0.999628,
+ 0.998966, 0.994914, 0.991849, 0.988873, 0.985288, 0.980170, 0.975207, 0.971156, 0.967476,
+ 0.962538, 0.955601, 0.947978, 0.938542, 0.928618, 0.919056, 0.907890, 0.895098, 0.881352,
+ 0.867263, 0.851806, 0.835168, 0.818003, 0.799785, 0.780633, 0.761080, 0.740618, 0.719795,
+ 0.698332, 0.676629, 0.654544, 0.632411, 0.610042, 0.587805, 0.565593, 0.543549, 0.521793,
+ 0.500309, 0.479195, 0.458546, 0.438353, 0.418669, 0.399557, 0.381012, 0.363049, 0.345710,
+ 0.329006, 0.312948, 1.000000, 1.000000, 1.000000, 1.000000, 1.000000, 0.999999, 0.999997,
+ 0.999993, 0.999990, 0.999984, 0.999972, 0.999960, 0.999939, 0.999906, 0.999853, 0.999765,
+ 0.999567, 0.998603, 0.994519, 0.991794, 0.989089, 0.985781, 0.980956, 0.974161, 0.970688,
+ 0.967064, 0.961890, 0.955292, 0.947848, 0.938359, 0.928226, 0.918214, 0.907361, 0.894702,
+ 0.880834, 0.866500, 0.851209, 0.834627, 0.817211, 0.799250, 0.780131, 0.760512, 0.740218,
+ 0.719264, 0.698063, 0.676325, 0.654450, 0.632316, 0.610170, 0.587988, 0.565891, 0.544013,
+ 0.522305, 0.500958, 0.479971, 0.459376, 0.439271, 0.419699, 0.400620, 0.382126, 0.364246,
+ 0.346967, 0.330273, 0.314236, 1.000000, 1.000000, 1.000000, 1.000000, 0.999999, 0.999998,
+ 0.999996, 0.999994, 0.999988, 0.999979, 0.999967, 0.999952, 0.999924, 0.999888, 0.999833,
+ 0.999733, 0.999490, 0.997946, 0.994192, 0.991812, 0.989274, 0.986224, 0.981547, 0.974000,
+ 0.970269, 0.966545, 0.961031, 0.954921, 0.947416, 0.938226, 0.928003, 0.917390, 0.906553,
+ 0.894191, 0.880329, 0.865540, 0.850476, 0.834058, 0.816467, 0.798509, 0.779561, 0.759828,
+ 0.739738, 0.718878, 0.697718, 0.676138, 0.654342, 0.632317, 0.610292, 0.588207, 0.566289,
+ 0.544443, 0.522927, 0.501674, 0.480765, 0.460314, 0.440304, 0.420782, 0.401824, 0.383410,
+ 0.365538, 0.348312, 0.331692, 0.315688, 1.000000, 1.000000, 1.000000, 1.000000, 0.999999,
+ 0.999998, 0.999996, 0.999993, 0.999985, 0.999976, 0.999961, 0.999943, 0.999913, 0.999872,
+ 0.999807, 0.999691, 0.999390, 0.996859, 0.994003, 0.991808, 0.989423, 0.986523, 0.981783,
+ 0.974511, 0.969791, 0.965933, 0.960377, 0.954434, 0.946803, 0.938026, 0.927620, 0.916545,
+ 0.905639, 0.893489, 0.879820, 0.864852, 0.849513, 0.833311, 0.815878, 0.797621, 0.778938,
+ 0.759253, 0.739142, 0.718479, 0.697274, 0.675902, 0.654135, 0.632357, 0.610364, 0.588497,
+ 0.566631, 0.545012, 0.523579, 0.502429, 0.481680, 0.461304, 0.441425, 0.422039, 0.403135,
+ 0.384779, 0.366976, 0.349796, 0.333231, 0.317277, 1.000000, 1.000000, 1.000000, 1.000000,
+ 0.999999, 0.999998, 0.999996, 0.999991, 0.999983, 0.999974, 0.999956, 0.999932, 0.999901,
+ 0.999852, 0.999780, 0.999646, 0.999248, 0.996193, 0.993784, 0.991782, 0.989539, 0.986694,
+ 0.981765, 0.975135, 0.969309, 0.965128, 0.959788, 0.953831, 0.946255, 0.937664, 0.927351,
+ 0.916044, 0.904715, 0.892528, 0.879111, 0.864256, 0.848452, 0.832434, 0.815129, 0.796806,
+ 0.778118, 0.758668, 0.738466, 0.718024, 0.696958, 0.675642, 0.654067, 0.632325, 0.610546,
+ 0.588786, 0.567123, 0.545617, 0.524312, 0.503348, 0.482637, 0.462418, 0.442657, 0.423338,
+ 0.404564, 0.386277, 0.368545, 0.351448, 0.334906, 0.318961, 1.000000, 1.000000, 1.000000,
+ 0.999999, 0.999999, 0.999998, 0.999994, 0.999989, 0.999979, 0.999968, 0.999949, 0.999921,
+ 0.999886, 0.999833, 0.999747, 0.999596, 0.999029, 0.995749, 0.993677, 0.991724, 0.989620,
+ 0.986723, 0.981515, 0.975767, 0.969056, 0.964124, 0.959142, 0.953036, 0.945650, 0.937022,
+ 0.926971, 0.915515, 0.903584, 0.891603, 0.878212, 0.863472, 0.847652, 0.831398, 0.814299,
+ 0.796105, 0.777231, 0.757977, 0.737895, 0.717415, 0.696595, 0.675317, 0.653980, 0.632343,
+ 0.610735, 0.589076, 0.567620, 0.546251, 0.525165, 0.504255, 0.483759, 0.463666, 0.443987,
+ 0.424783, 0.406042, 0.387891, 0.370293, 0.353221, 0.336715, 0.320806, 1.000000, 1.000000,
+ 1.000000, 0.999999, 0.999998, 0.999998, 0.999993, 0.999987, 0.999977, 0.999964, 0.999943,
+ 0.999911, 0.999867, 0.999807, 0.999714, 0.999531, 0.998645, 0.995399, 0.993512, 0.991717,
+ 0.989661, 0.986652, 0.981559, 0.976183, 0.969411, 0.963317, 0.958457, 0.952091, 0.944951,
+ 0.936307, 0.926454, 0.915043, 0.902668, 0.890462, 0.877245, 0.862672, 0.846823, 0.830201,
+ 0.813293, 0.795306, 0.776393, 0.757199, 0.737324, 0.716808, 0.696187, 0.675094, 0.653814,
+ 0.632453, 0.610885, 0.589483, 0.568099, 0.546975, 0.525953, 0.505268, 0.484936, 0.464988,
+ 0.445458, 0.426314, 0.407750, 0.389670, 0.372098, 0.355105, 0.338682, 0.322825, 1.000000,
+ 1.000000, 1.000000, 1.000000, 0.999999, 0.999996, 0.999992, 0.999983, 0.999976, 0.999959,
+ 0.999933, 0.999898, 0.999849, 0.999780, 0.999676, 0.999454, 0.997884, 0.995166, 0.993394,
+ 0.991723, 0.989654, 0.986389, 0.981632, 0.976607, 0.969701, 0.962555, 0.957605, 0.951232,
+ 0.944099, 0.935556, 0.925699, 0.914492, 0.902027, 0.889116, 0.876093, 0.861649, 0.845956,
+ 0.829238, 0.812220, 0.794420, 0.775657, 0.756265, 0.736673, 0.716372, 0.695669, 0.674886,
+ 0.653728, 0.632568, 0.611217, 0.589929, 0.568783, 0.547752, 0.526931, 0.506425, 0.486238,
+ 0.466425, 0.446945, 0.428026, 0.409536, 0.391551, 0.374087, 0.357155, 0.340787, 0.324974,
+ 1.000000, 1.000000, 1.000000, 1.000000, 0.999998, 0.999996, 0.999990, 0.999984, 0.999970,
+ 0.999952, 0.999925, 0.999886, 0.999831, 0.999757, 0.999633, 0.999356, 0.997017, 0.994868,
+ 0.993337, 0.991710, 0.989580, 0.985848, 0.981640, 0.976711, 0.969755, 0.962166, 0.956609,
+ 0.950365, 0.943026, 0.934693, 0.924880, 0.913729, 0.901350, 0.887966, 0.874726, 0.860474,
+ 0.844905, 0.828269, 0.810905, 0.793364, 0.774812, 0.755478, 0.735886, 0.715847, 0.695231,
+ 0.674537, 0.653667, 0.632527, 0.611475, 0.590363, 0.569462, 0.548571, 0.527976, 0.507634,
+ 0.487632, 0.467901, 0.448680, 0.429833, 0.411467, 0.393568, 0.376197, 0.359374, 0.343034,
+ 0.327273, 1.000000, 1.000000, 1.000000, 0.999999, 0.999998, 0.999993, 0.999989, 0.999980,
+ 0.999965, 0.999945, 0.999913, 0.999869, 0.999810, 0.999723, 0.999583, 0.999213, 0.996540,
+ 0.994740, 0.993244, 0.991671, 0.989411, 0.985533, 0.981616, 0.976847, 0.969968, 0.962315,
+ 0.955468, 0.949420, 0.942016, 0.933617, 0.923949, 0.912899, 0.900495, 0.887022, 0.873283,
+ 0.859153, 0.843830, 0.827325, 0.809888, 0.792172, 0.773832, 0.754686, 0.735035, 0.715297,
+ 0.694955, 0.674242, 0.653660, 0.632752, 0.611804, 0.590993, 0.570154, 0.549539, 0.529087,
+ 0.508974, 0.489030, 0.469599, 0.450466, 0.431761, 0.413508, 0.395761, 0.378480, 0.361679,
+ 0.345465, 0.329752, 1.000000, 1.000000, 1.000000, 1.000000, 0.999997, 0.999994, 0.999987,
+ 0.999978, 0.999961, 0.999936, 0.999903, 0.999855, 0.999786, 0.999689, 0.999527, 0.998988,
+ 0.996137, 0.994527, 0.993108, 0.991599, 0.989084, 0.985308, 0.981527, 0.976677, 0.970079,
+ 0.962535, 0.954490, 0.948271, 0.940942, 0.932422, 0.922836, 0.911896, 0.899632, 0.886118,
+ 0.871864, 0.857719, 0.842536, 0.826163, 0.808849, 0.790860, 0.772802, 0.753860, 0.734335,
+ 0.714582, 0.694543, 0.674071, 0.653544, 0.632922, 0.612153, 0.591573, 0.570951, 0.550520,
+ 0.530352, 0.510311, 0.490707, 0.471359, 0.452396, 0.433837, 0.415736, 0.398052, 0.380874,
+ 0.364232, 0.348023, 0.332368, 1.000000, 1.000000, 1.000000, 0.999999, 0.999998, 0.999994,
+ 0.999988, 0.999976, 0.999957, 0.999928, 0.999891, 0.999837, 0.999759, 0.999650, 0.999463,
+ 0.998551, 0.995879, 0.994366, 0.992964, 0.991479, 0.988521, 0.985101, 0.981482, 0.976168,
+ 0.970242, 0.962585, 0.953950, 0.946973, 0.939686, 0.931248, 0.921614, 0.910765, 0.898617,
+ 0.885183, 0.870772, 0.856138, 0.841120, 0.824962, 0.807732, 0.789813, 0.771638, 0.753008,
+ 0.733686, 0.713927, 0.694082, 0.673967, 0.653549, 0.633135, 0.612702, 0.592200, 0.571904,
+ 0.551679, 0.531678, 0.511898, 0.492437, 0.473239, 0.454451, 0.436067, 0.418054, 0.400542,
+ 0.383486, 0.366848, 0.350781, 0.335182, 1.000000, 1.000000, 1.000000, 0.999999, 0.999997,
+ 0.999993, 0.999985, 0.999972, 0.999951, 0.999919, 0.999877, 0.999817, 0.999733, 0.999608,
+ 0.999380, 0.997685, 0.995603, 0.994264, 0.992911, 0.991287, 0.987923, 0.984871, 0.981239,
+ 0.975933, 0.970149, 0.962511, 0.953824, 0.945699, 0.938285, 0.929907, 0.920343, 0.909537,
+ 0.897435, 0.884056, 0.869626, 0.854490, 0.839459, 0.823511, 0.806511, 0.788752, 0.770440,
+ 0.751995, 0.732962, 0.713424, 0.693525, 0.673798, 0.653622, 0.633301, 0.613224, 0.592938,
+ 0.572833, 0.552904, 0.533030, 0.513556, 0.494215, 0.475279, 0.456673, 0.438411, 0.420583,
+ 0.403178, 0.386178, 0.369728, 0.353688, 0.338147, 1.000000, 1.000000, 1.000000, 0.999999,
+ 0.999997, 0.999991, 0.999984, 0.999967, 0.999944, 0.999912, 0.999863, 0.999796, 0.999703,
+ 0.999563, 0.999279, 0.997104, 0.995394, 0.994111, 0.992825, 0.990979, 0.987529, 0.984661,
+ 0.980774, 0.975758, 0.969866, 0.962465, 0.953678, 0.944489, 0.936886, 0.928356, 0.918820,
+ 0.908073, 0.896092, 0.882833, 0.868463, 0.853212, 0.837744, 0.822048, 0.805333, 0.787643,
+ 0.769414, 0.750830, 0.732178, 0.712972, 0.693227, 0.673569, 0.653744, 0.633739, 0.613735,
+ 0.593822, 0.573916, 0.554158, 0.534652, 0.515248, 0.496233, 0.477436, 0.459009, 0.440929,
+ 0.423259, 0.405951, 0.389136, 0.372690, 0.356789, 0.341329, 1.000000, 1.000000, 1.000000,
+ 0.999999, 0.999996, 0.999991, 0.999981, 0.999966, 0.999939, 0.999903, 0.999847, 0.999771,
+ 0.999666, 0.999510, 0.999131, 0.996690, 0.995147, 0.993882, 0.992696, 0.990474, 0.987227,
+ 0.984334, 0.980153, 0.975438, 0.969406, 0.962238, 0.953598, 0.943868, 0.935356, 0.926721,
+ 0.917122, 0.906430, 0.894550, 0.881354, 0.867131, 0.851954, 0.835972, 0.820331, 0.803911,
+ 0.786452, 0.768420, 0.749821, 0.731298, 0.712393, 0.692979, 0.673418, 0.653859, 0.634232,
+ 0.614327, 0.594732, 0.575131, 0.555584, 0.536346, 0.517175, 0.498323, 0.479744, 0.461485,
+ 0.443645, 0.426061, 0.408969, 0.392155, 0.375921, 0.360060, 0.344677, 1.000000, 1.000000,
+ 1.000000, 0.999999, 0.999997, 0.999991, 0.999979, 0.999960, 0.999931, 0.999891, 0.999832,
+ 0.999748, 0.999629, 0.999449, 0.998880, 0.996305, 0.995024, 0.993812, 0.992508, 0.989721,
+ 0.986936, 0.983936, 0.979629, 0.974979, 0.968928, 0.961970, 0.953291, 0.943458, 0.933644,
+ 0.925007, 0.915388, 0.904755, 0.892932, 0.879831, 0.865794, 0.850672, 0.834591, 0.818398,
+ 0.802304, 0.785151, 0.767450, 0.748987, 0.730325, 0.711758, 0.692761, 0.673417, 0.653908,
+ 0.634686, 0.615168, 0.595707, 0.576393, 0.557198, 0.538018, 0.519253, 0.500555, 0.482220,
+ 0.464197, 0.446414, 0.429106, 0.412035, 0.395508, 0.379284, 0.363538, 0.348220, 1.000000,
+ 1.000000, 1.000000, 0.999999, 0.999995, 0.999989, 0.999977, 0.999955, 0.999924, 0.999879,
+ 0.999813, 0.999722, 0.999590, 0.999381, 0.998335, 0.996088, 0.994814, 0.993709, 0.992220,
+ 0.989209, 0.986575, 0.983383, 0.979084, 0.974272, 0.968359, 0.961275, 0.953025, 0.943098,
+ 0.932434, 0.923101, 0.913477, 0.902861, 0.891059, 0.878072, 0.864118, 0.849188, 0.833281,
+ 0.816808, 0.800596, 0.783745, 0.766331, 0.748123, 0.729686, 0.711078, 0.692527, 0.673491,
+ 0.654296, 0.635113, 0.616048, 0.596847, 0.577720, 0.558879, 0.540028, 0.521371, 0.502996,
+ 0.484858, 0.466997, 0.449477, 0.432217, 0.415426, 0.398924, 0.382890, 0.367206, 0.351955,
+ 1.000000, 1.000000, 1.000000, 0.999998, 0.999996, 0.999988, 0.999974, 0.999953, 0.999918,
+ 0.999865, 0.999791, 0.999690, 0.999542, 0.999293, 0.997535, 0.995790, 0.994609, 0.993557,
+ 0.991766, 0.988767, 0.986255, 0.982544, 0.978541, 0.973528, 0.967700, 0.960596, 0.952299,
+ 0.942684, 0.931653, 0.921211, 0.911489, 0.900818, 0.889018, 0.876245, 0.862406, 0.847517,
+ 0.831852, 0.815367, 0.798719, 0.782224, 0.765167, 0.747304, 0.729133, 0.710485, 0.692196,
+ 0.673589, 0.654770, 0.635717, 0.616986, 0.598119, 0.579298, 0.560560, 0.542163, 0.523669,
+ 0.505564, 0.487642, 0.469991, 0.452658, 0.435620, 0.418937, 0.402612, 0.386633, 0.371091,
+ 0.355949, 1.000000, 1.000000, 0.999999, 0.999998, 0.999995, 0.999986, 0.999973, 0.999948,
+ 0.999909, 0.999852, 0.999769, 0.999656, 0.999490, 0.999186, 0.997059, 0.995624, 0.994510,
+ 0.993327, 0.991020, 0.988379, 0.985771, 0.981971, 0.978051, 0.972892, 0.967020, 0.959965,
+ 0.951625, 0.941902, 0.930951, 0.919370, 0.909285, 0.898562, 0.886809, 0.874251, 0.860597,
+ 0.845808, 0.830365, 0.813972, 0.797260, 0.780597, 0.763854, 0.746401, 0.728519, 0.710203,
+ 0.691882, 0.673687, 0.655275, 0.636621, 0.617909, 0.599473, 0.581032, 0.562560, 0.544295,
+ 0.526228, 0.508293, 0.490652, 0.473242, 0.456004, 0.439212, 0.422663, 0.406476, 0.390647,
+ 0.375204, 0.360129, 1.000000, 1.000000, 1.000000, 0.999999, 0.999994, 0.999984, 0.999969,
+ 0.999940, 0.999898, 0.999837, 0.999746, 0.999617, 0.999438, 0.999016, 0.996703, 0.995302,
+ 0.994356, 0.992993, 0.990390, 0.988072, 0.985152, 0.981447, 0.977273, 0.972234, 0.966113,
+ 0.959033, 0.950869, 0.941217, 0.930175, 0.918279, 0.906941, 0.896201, 0.884509, 0.871920,
+ 0.858420, 0.843906, 0.828730, 0.812524, 0.795978, 0.778979, 0.762450, 0.745459, 0.727966,
+ 0.710046, 0.691808, 0.673739, 0.655756, 0.637574, 0.619153, 0.600887, 0.582796, 0.564748,
+ 0.546636, 0.528904, 0.511252, 0.493791, 0.476563, 0.459695, 0.442942, 0.426632, 0.410558,
+ 0.394895, 0.379517, 0.364560, 1.000000, 1.000000, 1.000000, 0.999998, 0.999994, 0.999984,
+ 0.999966, 0.999934, 0.999887, 0.999819, 0.999720, 0.999578, 0.999367, 0.998696, 0.996353,
+ 0.995201, 0.994115, 0.992665, 0.989948, 0.987633, 0.984331, 0.980827, 0.976390, 0.971327,
+ 0.965201, 0.957977, 0.949712, 0.940128, 0.929187, 0.917237, 0.904645, 0.893711, 0.882112,
+ 0.869516, 0.856236, 0.841929, 0.826924, 0.810991, 0.794686, 0.777761, 0.760980, 0.744384,
+ 0.727314, 0.709877, 0.691988, 0.674098, 0.656243, 0.638603, 0.620606, 0.602574, 0.584694,
+ 0.567018, 0.549311, 0.531673, 0.514403, 0.497148, 0.480177, 0.463439, 0.446998, 0.430743,
+ 0.414943, 0.399304, 0.384121, 0.369251, 1.000000, 1.000000, 1.000000, 0.999997, 0.999992,
+ 0.999981, 0.999962, 0.999927, 0.999874, 0.999798, 0.999691, 0.999533, 0.999291, 0.997909,
+ 0.996117, 0.995029, 0.993880, 0.992142, 0.989576, 0.987185, 0.983587, 0.980055, 0.975487,
+ 0.970172, 0.963998, 0.956738, 0.948637, 0.939083, 0.928169, 0.916144, 0.903147, 0.890916,
+ 0.879389, 0.866895, 0.853826, 0.839729, 0.824957, 0.809472, 0.793341, 0.776743, 0.759808,
+ 0.743277, 0.726643, 0.709685, 0.692249, 0.674639, 0.657008, 0.639576, 0.622114, 0.604471,
+ 0.586851, 0.569340, 0.552135, 0.534806, 0.517599, 0.500765, 0.484035, 0.467440, 0.451212,
+ 0.435240, 0.419399, 0.404083, 0.388944, 0.374182, 1.000000, 1.000000, 1.000000, 0.999998,
+ 0.999993, 0.999979, 0.999958, 0.999919, 0.999861, 0.999774, 0.999656, 0.999482, 0.999195,
+ 0.997307, 0.995837, 0.994722, 0.993707, 0.991391, 0.989169, 0.986461, 0.982904, 0.979062,
+ 0.974536, 0.969035, 0.962653, 0.955486, 0.947243, 0.937747, 0.926861, 0.914936, 0.901835,
+ 0.888472, 0.876571, 0.864223, 0.851252, 0.837374, 0.822985, 0.807788, 0.791927, 0.775702,
+ 0.758928, 0.742347, 0.725914, 0.709495, 0.692569, 0.675363, 0.658085, 0.640639, 0.623698,
+ 0.606505, 0.589267, 0.572008, 0.554939, 0.538132, 0.521211, 0.504487, 0.488048, 0.471807,
+ 0.455651, 0.439858, 0.424332, 0.408983, 0.394071, 0.379402, 1.000000, 1.000000, 1.000000,
+ 0.999997, 0.999992, 0.999978, 0.999954, 0.999913, 0.999844, 0.999753, 0.999618, 0.999424,
+ 0.999067, 0.996875, 0.995659, 0.994603, 0.993420, 0.990874, 0.988713, 0.985585, 0.982193,
+ 0.978145, 0.973416, 0.967801, 0.961483, 0.954069, 0.945704, 0.936138, 0.925374, 0.913395,
+ 0.900339, 0.886675, 0.873512, 0.861326, 0.848513, 0.834956, 0.820820, 0.805943, 0.790574,
+ 0.774677, 0.758279, 0.741807, 0.725271, 0.709231, 0.692874, 0.676189, 0.659352, 0.642296,
+ 0.625250, 0.608700, 0.591823, 0.575012, 0.558143, 0.541491, 0.525075, 0.508558, 0.492277,
+ 0.476270, 0.460459, 0.444740, 0.429400, 0.414309, 0.399421, 0.384907, 1.000000, 1.000000,
+ 1.000000, 0.999997, 0.999990, 0.999977, 0.999947, 0.999902, 0.999832, 0.999730, 0.999577,
+ 0.999359, 0.998845, 0.996554, 0.995328, 0.994442, 0.992919, 0.990393, 0.988170, 0.984855,
+ 0.981312, 0.977149, 0.972137, 0.966207, 0.959967, 0.952454, 0.943873, 0.934434, 0.923813,
+ 0.911942, 0.898928, 0.885120, 0.871043, 0.858248, 0.845666, 0.832346, 0.818482, 0.804029,
+ 0.788982, 0.773571, 0.757700, 0.741484, 0.725186, 0.708915, 0.693244, 0.677028, 0.660656,
+ 0.644079, 0.627377, 0.610804, 0.594542, 0.578112, 0.561650, 0.545163, 0.528962, 0.512926,
+ 0.496893, 0.481007, 0.465397, 0.450042, 0.434740, 0.419831, 0.405156, 0.390692, 1.000000,
+ 1.000000, 0.999999, 0.999997, 0.999989, 0.999973, 0.999942, 0.999891, 0.999813, 0.999698,
+ 0.999532, 0.999285, 0.998286, 0.996295, 0.995215, 0.994182, 0.992032, 0.989855, 0.987415,
+ 0.984047, 0.980050, 0.976017, 0.970845, 0.964767, 0.958269, 0.950600, 0.942033, 0.932501,
+ 0.921807, 0.910017, 0.897149, 0.883414, 0.869182, 0.855055, 0.842687, 0.829548, 0.816162,
+ 0.802072, 0.787436, 0.772533, 0.757043, 0.741263, 0.725330, 0.709262, 0.693497, 0.678038,
+ 0.662128, 0.646068, 0.629824, 0.613437, 0.597334, 0.581401, 0.565372, 0.549288, 0.533182,
+ 0.517405, 0.501765, 0.486143, 0.470675, 0.455465, 0.440532, 0.425630, 0.411113, 0.396887,
+ 1.000000, 1.000000, 0.999999, 0.999996, 0.999989, 0.999970, 0.999934, 0.999879, 0.999793,
+ 0.999665, 0.999481, 0.999192, 0.997506, 0.995926, 0.995009, 0.993736, 0.991298, 0.989326,
+ 0.986371, 0.983199, 0.979032, 0.974596, 0.969364, 0.963198, 0.956385, 0.948509, 0.939993,
+ 0.930421, 0.919590, 0.908140, 0.895349, 0.881699, 0.867456, 0.852784, 0.839500, 0.826629,
+ 0.813602, 0.799983, 0.785873, 0.771340, 0.756480, 0.741190, 0.725687, 0.709997, 0.694192,
+ 0.678975, 0.663673, 0.648135, 0.632442, 0.616477, 0.600565, 0.584772, 0.569202, 0.553595,
+ 0.537881, 0.522193, 0.506784, 0.491554, 0.476349, 0.461278, 0.446419, 0.431913, 0.417443,
+ 0.403271, 1.000000, 1.000000, 0.999999, 0.999995, 0.999986, 0.999966, 0.999927, 0.999867,
+ 0.999772, 0.999629, 0.999423, 0.999075, 0.997024, 0.995773, 0.994651, 0.993353, 0.990822,
+ 0.988569, 0.985596, 0.982182, 0.977871, 0.973140, 0.967584, 0.961408, 0.954294, 0.946398,
+ 0.937603, 0.927937, 0.917305, 0.905833, 0.893138, 0.879770, 0.865720, 0.851023, 0.836801,
+ 0.823784, 0.810909, 0.797886, 0.784177, 0.770243, 0.755925, 0.741144, 0.726214, 0.710971,
+ 0.695563, 0.680212, 0.665304, 0.650297, 0.635168, 0.619796, 0.604217, 0.588692, 0.573254,
+ 0.557998, 0.542839, 0.527470, 0.512162, 0.497115, 0.482296, 0.467477, 0.452812, 0.438310,
+ 0.424184, 0.410163, 1.000000, 1.000000, 0.999999, 0.999996, 0.999984, 0.999962, 0.999920,
+ 0.999852, 0.999745, 0.999586, 0.999354, 0.998894, 0.996686, 0.995485, 0.994493, 0.992573,
+ 0.990323, 0.987772, 0.984692, 0.980887, 0.976446, 0.971625, 0.965717, 0.959421, 0.951975,
+ 0.944086, 0.935066, 0.925403, 0.914814, 0.903208, 0.890958, 0.877817, 0.863828, 0.849289,
+ 0.834872, 0.820889, 0.808183, 0.795660, 0.782556, 0.769066, 0.755386, 0.741229, 0.726726,
+ 0.712170, 0.697209, 0.682170, 0.667203, 0.652689, 0.637938, 0.623262, 0.608190, 0.593002,
+ 0.577817, 0.562737, 0.547836, 0.533036, 0.518052, 0.503135, 0.488422, 0.473986, 0.459552,
+ 0.445282, 0.431149, 0.417407, 1.000000, 1.000000, 0.999999, 0.999994, 0.999983, 0.999957,
+ 0.999914, 0.999835, 0.999718, 0.999538, 0.999275, 0.998454, 0.996341, 0.995246, 0.994222,
+ 0.991844, 0.989829, 0.986688, 0.983562, 0.979638, 0.974932, 0.969827, 0.963621, 0.957146,
+ 0.949365, 0.941398, 0.932245, 0.922556, 0.911949, 0.900627, 0.888440, 0.875544, 0.862005,
+ 0.847810, 0.833372, 0.819134, 0.805508, 0.793339, 0.780916, 0.767837, 0.754858, 0.741307,
+ 0.727496, 0.713386, 0.699131, 0.684542, 0.669878, 0.655261, 0.641035, 0.626685, 0.612377,
+ 0.597625, 0.582805, 0.568030, 0.553204, 0.538684, 0.524269, 0.509662, 0.495119, 0.480735,
+ 0.466634, 0.452593, 0.438748, 0.424915, 1.000000, 1.000000, 0.999998, 0.999994, 0.999982,
+ 0.999956, 0.999901, 0.999818, 0.999683, 0.999487, 0.999185, 0.997584, 0.996004, 0.995050,
+ 0.993715, 0.991212, 0.989057, 0.985879, 0.982243, 0.978206, 0.973119, 0.967919, 0.961343,
+ 0.954603, 0.946712, 0.938378, 0.929266, 0.919443, 0.908911, 0.897725, 0.885589, 0.873254,
+ 0.859889, 0.846123, 0.832094, 0.817898, 0.803866, 0.791061, 0.779235, 0.766885, 0.754292,
+ 0.741565, 0.728331, 0.714861, 0.701179, 0.687166, 0.673012, 0.658716, 0.644442, 0.630472,
+ 0.616519, 0.602514, 0.588172, 0.573689, 0.559281, 0.544768, 0.530543, 0.516485, 0.502303,
+ 0.488100, 0.474095, 0.460245, 0.446598, 0.433169, 1.000000, 1.000000, 0.999997, 0.999993,
+ 0.999980, 0.999947, 0.999891, 0.999794, 0.999647, 0.999425, 0.999062, 0.997049, 0.995778,
+ 0.994652, 0.992778, 0.990482, 0.988004, 0.984893, 0.980881, 0.976605, 0.971199, 0.965610,
+ 0.958925, 0.951746, 0.943791, 0.935200, 0.926018, 0.916028, 0.905724, 0.894528, 0.882914,
+ 0.870740, 0.857802, 0.844552, 0.830857, 0.816921, 0.803102, 0.789625, 0.777480, 0.765891,
+ 0.753908, 0.741795, 0.729390, 0.716440, 0.703411, 0.690068, 0.676438, 0.662586, 0.648697,
+ 0.634732, 0.620997, 0.607451, 0.593765, 0.579748, 0.565661, 0.551594, 0.537396, 0.523433,
+ 0.509708, 0.495972, 0.482082, 0.468427, 0.454890, 0.441623, 1.000000, 1.000000, 0.999999,
+ 0.999991, 0.999977, 0.999940, 0.999875, 0.999769, 0.999605, 0.999352, 0.998882, 0.996665,
+ 0.995459, 0.994380, 0.992014, 0.989912, 0.986796, 0.983537, 0.979326, 0.974792, 0.969140,
+ 0.963160, 0.956222, 0.948807, 0.940518, 0.931755, 0.922452, 0.912319, 0.902227, 0.891142,
+ 0.879838, 0.868047, 0.855745, 0.842718, 0.829827, 0.816398, 0.802786, 0.789396, 0.776581,
+ 0.764901, 0.753710, 0.742102, 0.730448, 0.718337, 0.705768, 0.693172, 0.680153, 0.666882,
+ 0.653401, 0.639837, 0.626152, 0.612676, 0.599435, 0.586109, 0.572473, 0.558715, 0.544964,
+ 0.531112, 0.517416, 0.503992, 0.490653, 0.477162, 0.463832, 0.450645, 1.000000, 1.000000,
+ 0.999999, 0.999992, 0.999973, 0.999933, 0.999861, 0.999741, 0.999554, 0.999267, 0.998411,
+ 0.996303, 0.995191, 0.993945, 0.991406, 0.989019, 0.985720, 0.982057, 0.977501, 0.972605,
+ 0.966697, 0.960340, 0.953031, 0.945347, 0.936866, 0.927917, 0.918562, 0.908598, 0.898486,
+ 0.887794, 0.876545, 0.865379, 0.853428, 0.841167, 0.828649, 0.815967, 0.802957, 0.789865,
+ 0.777077, 0.764695, 0.753544, 0.742694, 0.731571, 0.720304, 0.708490, 0.696351, 0.684134,
+ 0.671470, 0.658541, 0.645376, 0.632209, 0.618776, 0.605511, 0.592527, 0.579546, 0.566310,
+ 0.552860, 0.539492, 0.526005, 0.512564, 0.499340, 0.486360, 0.473357, 0.460306, 1.000000,
+ 1.000000, 0.999998, 0.999991, 0.999970, 0.999926, 0.999842, 0.999710, 0.999498, 0.999164,
+ 0.997464, 0.995870, 0.994917, 0.992911, 0.990682, 0.987816, 0.984410, 0.980551, 0.975693,
+ 0.970263, 0.963946, 0.957248, 0.949765, 0.941571, 0.932941, 0.923873, 0.914332, 0.904560,
+ 0.894394, 0.884127, 0.873294, 0.862503, 0.851335, 0.839566, 0.827776, 0.815708, 0.803370,
+ 0.790821, 0.778386, 0.766121, 0.754193, 0.743420, 0.732975, 0.722326, 0.711376, 0.699992,
+ 0.688180, 0.676354, 0.664004, 0.651449, 0.638600, 0.625776, 0.612660, 0.599603, 0.586719,
+ 0.574078, 0.561273, 0.548129, 0.535155, 0.522015, 0.508851, 0.495837, 0.483190, 0.470624,
+ 1.000000, 1.000000, 0.999998, 0.999988, 0.999965, 0.999916, 0.999823, 0.999669, 0.999425,
+ 0.999025, 0.996874, 0.995670, 0.994415, 0.991991, 0.989766, 0.986646, 0.982812, 0.978356,
+ 0.973317, 0.967612, 0.960820, 0.953603, 0.945969, 0.937323, 0.928661, 0.919507, 0.909833,
+ 0.900245, 0.890390, 0.880252, 0.870000, 0.859518, 0.849163, 0.838101, 0.826960, 0.815688,
+ 0.804126, 0.792234, 0.780356, 0.768474, 0.756678, 0.745159, 0.734601, 0.724624, 0.714339,
+ 0.703751, 0.692766, 0.681267, 0.669799, 0.657871, 0.645577, 0.633102, 0.620560, 0.607737,
+ 0.594890, 0.582143, 0.569779, 0.557360, 0.544651, 0.531942, 0.519228, 0.506467, 0.493710,
+ 0.481143, 1.000000, 1.000000, 0.999998, 0.999988, 0.999961, 0.999902, 0.999798, 0.999622,
+ 0.999341, 0.998801, 0.996397, 0.995225, 0.993927, 0.991338, 0.988500, 0.985327, 0.981195,
+ 0.976383, 0.970726, 0.964471, 0.957386, 0.949813, 0.941694, 0.932681, 0.923974, 0.914755,
+ 0.905026, 0.895649, 0.886178, 0.876277, 0.866629, 0.856890, 0.846934, 0.836887, 0.826373,
+ 0.815885, 0.805169, 0.794133, 0.782812, 0.771547, 0.760175, 0.748896, 0.737687, 0.727152,
+ 0.717601, 0.707670, 0.697425, 0.686788, 0.675664, 0.664513, 0.652962, 0.640965, 0.628851,
+ 0.616551, 0.604168, 0.591559, 0.579009, 0.566648, 0.554597, 0.542382, 0.529999, 0.517655,
+ 0.505254, 0.492894, 1.000000, 1.000000, 0.999997, 0.999986, 0.999956, 0.999889, 0.999766,
+ 0.999562, 0.999240, 0.997952, 0.996094, 0.994979, 0.992773, 0.990536, 0.987214, 0.983322,
+ 0.978938, 0.973714, 0.967681, 0.960981, 0.953144, 0.945475, 0.936909, 0.927734, 0.918826,
+ 0.909590, 0.900085, 0.890867, 0.881801, 0.872565, 0.863236, 0.854239, 0.845060, 0.835686,
+ 0.826251, 0.816284, 0.806586, 0.796419, 0.785914, 0.775210, 0.764461, 0.753599, 0.742805,
+ 0.731872, 0.721370, 0.711898, 0.702337, 0.692383, 0.682137, 0.671365, 0.660479, 0.649314,
+ 0.637685, 0.625899, 0.613898, 0.601865, 0.589582, 0.577285, 0.565013, 0.553106, 0.541280,
+ 0.529367, 0.517320, 0.505411, 1.000000, 1.000000, 0.999997, 0.999983, 0.999948, 0.999869,
+ 0.999732, 0.999499, 0.999111, 0.997167, 0.995720, 0.994349, 0.991727, 0.989197, 0.985883,
+ 0.981483, 0.976618, 0.970597, 0.964122, 0.956994, 0.948639, 0.940500, 0.931606, 0.922385,
+ 0.913291, 0.904205, 0.894938, 0.885890, 0.877334, 0.868754, 0.860053, 0.851683, 0.843447,
+ 0.834889, 0.826304, 0.817441, 0.808285, 0.799141, 0.789570, 0.779600, 0.769510, 0.759155,
+ 0.748882, 0.738346, 0.727629, 0.717273, 0.707467, 0.698283, 0.688609, 0.678748, 0.668371,
+ 0.657739, 0.646951, 0.635765, 0.624254, 0.612647, 0.600900, 0.589061, 0.576998, 0.564991,
+ 0.553102, 0.541517, 0.530027, 0.518495, 1.000000, 1.000000, 0.999997, 0.999983, 0.999939,
+ 0.999851, 0.999684, 0.999412, 0.998925, 0.996597, 0.995207, 0.993603, 0.990903, 0.987594,
+ 0.983814, 0.979016, 0.973647, 0.967048, 0.960109, 0.952123, 0.943560, 0.934900, 0.925747,
+ 0.916566, 0.907305, 0.898441, 0.889629, 0.881042, 0.872874, 0.865064, 0.857225, 0.849446,
+ 0.842063, 0.834561, 0.826814, 0.818875, 0.810748, 0.802316, 0.793699, 0.784704, 0.775198,
+ 0.765643, 0.755735, 0.745873, 0.735526, 0.725229, 0.714892, 0.704807, 0.695502, 0.686241,
+ 0.676633, 0.666688, 0.656384, 0.645871, 0.635174, 0.624113, 0.612788, 0.601426, 0.589925,
+ 0.578399, 0.566612, 0.554931, 0.543383, 0.532065, 1.000000, 1.000000, 0.999996, 0.999977,
+ 0.999928, 0.999824, 0.999633, 0.999306, 0.998429, 0.996133, 0.994890, 0.992316, 0.989752,
+ 0.986095, 0.981564, 0.976234, 0.970081, 0.962779, 0.955232, 0.946702, 0.937716, 0.928604,
+ 0.919281, 0.910167, 0.901046, 0.892446, 0.884183, 0.876253, 0.868619, 0.861545, 0.854673,
+ 0.847885, 0.841074, 0.834610, 0.827984, 0.820945, 0.813648, 0.806232, 0.798444, 0.790232,
+ 0.781853, 0.772897, 0.763648, 0.754227, 0.744542, 0.734689, 0.724526, 0.714204, 0.704152,
+ 0.694222, 0.685143, 0.675860, 0.666319, 0.656415, 0.646273, 0.635902, 0.625399, 0.614563,
+ 0.603490, 0.592413, 0.581217, 0.570000, 0.558608, 0.547242, 1.000000, 0.999999, 0.999995,
+ 0.999972, 0.999915, 0.999790, 0.999562, 0.999168, 0.997237, 0.995672, 0.994074, 0.991220,
+ 0.987792, 0.983822, 0.978599, 0.972804, 0.965718, 0.958053, 0.949460, 0.940503, 0.931011,
+ 0.921608, 0.912409, 0.903378, 0.894606, 0.886369, 0.878756, 0.871573, 0.864862, 0.858421,
+ 0.852541, 0.846802, 0.841027, 0.835206, 0.829628, 0.823730, 0.817415, 0.810655, 0.803873,
+ 0.796659, 0.788887, 0.780940, 0.772537, 0.763507, 0.754487, 0.745163, 0.735572, 0.725687,
+ 0.715611, 0.705398, 0.695418, 0.685592, 0.676518, 0.667304, 0.657875, 0.648182, 0.638235,
+ 0.628062, 0.617813, 0.607283, 0.596552, 0.585770, 0.575033, 0.564153, 1.000000, 1.000000,
+ 0.999995, 0.999970, 0.999898, 0.999748, 0.999472, 0.998969, 0.996528, 0.995102, 0.992701,
+ 0.989963, 0.985981, 0.981194, 0.975183, 0.968501, 0.960502, 0.952012, 0.942861, 0.933376,
+ 0.923506, 0.914042, 0.904921, 0.896282, 0.887987, 0.880341, 0.873536, 0.867293, 0.861556,
+ 0.856148, 0.850987, 0.846352, 0.841684, 0.836880, 0.832036, 0.827091, 0.821900, 0.816206,
+ 0.810042, 0.803629, 0.796918, 0.789653, 0.781915, 0.774014, 0.765530, 0.756526, 0.747669,
+ 0.738342, 0.728770, 0.718942, 0.708942, 0.698855, 0.688933, 0.679131, 0.669855, 0.660811,
+ 0.651549, 0.642127, 0.632454, 0.622651, 0.612709, 0.602606, 0.592344, 0.581877, 1.000000,
+ 0.999999, 0.999993, 0.999963, 0.999874, 0.999691, 0.999350, 0.998431, 0.995873, 0.994456,
+ 0.991327, 0.987798, 0.983232, 0.977500, 0.970828, 0.962815, 0.954228, 0.944752, 0.935126,
+ 0.925179, 0.915102, 0.905763, 0.897087, 0.888933, 0.881452, 0.874687, 0.868716, 0.863585,
+ 0.858931, 0.854662, 0.850569, 0.846719, 0.843151, 0.839426, 0.835588, 0.831443, 0.827004,
+ 0.822395, 0.817254, 0.811630, 0.805464, 0.799124, 0.792382, 0.785091, 0.777315, 0.769360,
+ 0.760908, 0.751957, 0.743128, 0.733917, 0.724340, 0.714713, 0.704721, 0.694835, 0.684862,
+ 0.675099, 0.665570, 0.656644, 0.647651, 0.638581, 0.629337, 0.619926, 0.610358, 0.600707,
+ 1.000000, 1.000000, 0.999990, 0.999953, 0.999843, 0.999613, 0.999186, 0.997025, 0.995317,
+ 0.992850, 0.989760, 0.985270, 0.979807, 0.973049, 0.965228, 0.956248, 0.946394, 0.936324,
+ 0.926124, 0.915808, 0.905942, 0.897060, 0.889001, 0.881755, 0.875351, 0.869688, 0.864736,
+ 0.860745, 0.857305, 0.854190, 0.851261, 0.848484, 0.845642, 0.842948, 0.840060, 0.836901,
+ 0.833379, 0.829393, 0.825103, 0.820431, 0.815288, 0.809575, 0.803326, 0.796949, 0.790174,
+ 0.782873, 0.775048, 0.767139, 0.758772, 0.750019, 0.741120, 0.732127, 0.722743, 0.713225,
+ 0.703637, 0.693768, 0.684016, 0.674277, 0.664703, 0.655328, 0.646550, 0.637812, 0.629036,
+ 0.620129, 1.000000, 1.000000, 0.999988, 0.999933, 0.999800, 0.999508, 0.998917, 0.996236,
+ 0.994617, 0.991176, 0.987089, 0.981880, 0.974966, 0.967156, 0.957914, 0.947585, 0.936937,
+ 0.926318, 0.915662, 0.905567, 0.896223, 0.888166, 0.881117, 0.875079, 0.869981, 0.865675,
+ 0.862091, 0.859183, 0.856981, 0.855065, 0.853273, 0.851572, 0.849782, 0.847768, 0.845668,
+ 0.843345, 0.840703, 0.837646, 0.834094, 0.830030, 0.825631, 0.820873, 0.815619, 0.809856,
+ 0.803578, 0.797096, 0.790359, 0.783152, 0.775507, 0.767504, 0.759411, 0.750982, 0.742208,
+ 0.733383, 0.724445, 0.715190, 0.705827, 0.696440, 0.686773, 0.677242, 0.667735, 0.658471,
+ 0.649236, 0.640305, 1.000000, 0.999999, 0.999984, 0.999918, 0.999737, 0.999350, 0.997576,
+ 0.995476, 0.992614, 0.988817, 0.983601, 0.976880, 0.968694, 0.959092, 0.948297, 0.936831,
+ 0.925592, 0.914494, 0.904159, 0.894643, 0.886417, 0.879620, 0.874023, 0.869533, 0.865967,
+ 0.863238, 0.861113, 0.859527, 0.858367, 0.857594, 0.856882, 0.856172, 0.855316, 0.854197,
+ 0.852818, 0.851062, 0.849046, 0.846747, 0.844043, 0.840842, 0.837164, 0.832985, 0.828344,
+ 0.823544, 0.818276, 0.812543, 0.806374, 0.799838, 0.793170, 0.786246, 0.778956, 0.771297,
+ 0.763278, 0.755252, 0.746984, 0.738445, 0.729688, 0.721045, 0.712189, 0.703099, 0.694045,
+ 0.684930, 0.675601, 0.666480, 1.000000, 0.999999, 0.999978, 0.999888, 0.999639, 0.999093,
+ 0.996310, 0.994405, 0.990527, 0.985186, 0.978518, 0.969748, 0.959597, 0.948104, 0.935724,
+ 0.923704, 0.912023, 0.901356, 0.891850, 0.883847, 0.877280, 0.872289, 0.868583, 0.865913,
+ 0.864098, 0.862993, 0.862356, 0.862125, 0.862107, 0.862168, 0.862359, 0.862490, 0.862430,
+ 0.862063, 0.861431, 0.860386, 0.858950, 0.857090, 0.854848, 0.852381, 0.849503, 0.846167,
+ 0.842399, 0.838194, 0.833566, 0.828579, 0.823464, 0.817951, 0.812079, 0.805873, 0.799320,
+ 0.792533, 0.785715, 0.778636, 0.771260, 0.763618, 0.755719, 0.747815, 0.739825, 0.731602,
+ 0.723212, 0.714845, 0.706465, 0.697933, 1.000000, 0.999998, 0.999969, 0.999836, 0.999475,
+ 0.997943, 0.995219, 0.991760, 0.986663, 0.979592, 0.970218, 0.959155, 0.946575, 0.933047,
+ 0.920022, 0.907749, 0.896801, 0.887506, 0.880077, 0.874322, 0.870126, 0.867481, 0.865949,
+ 0.865293, 0.865287, 0.865746, 0.866502, 0.867439, 0.868442, 0.869382, 0.870161, 0.870782,
+ 0.871303, 0.871511, 0.871427, 0.870978, 0.870136, 0.868892, 0.867248, 0.865209, 0.862775,
+ 0.859944, 0.857004, 0.853671, 0.849984, 0.845927, 0.841518, 0.836774, 0.831750, 0.826407,
+ 0.821001, 0.815333, 0.809412, 0.803238, 0.796802, 0.790204, 0.783457, 0.776713, 0.769749,
+ 0.762596, 0.755239, 0.747690, 0.740127, 0.732595, 1.000000, 0.999997, 0.999950, 0.999744,
+ 0.999162, 0.996124, 0.992844, 0.987757, 0.980062, 0.969642, 0.957087, 0.942735, 0.927747,
+ 0.913622, 0.900889, 0.890115, 0.881584, 0.875288, 0.870926, 0.868307, 0.867033, 0.866972,
+ 0.867692, 0.868950, 0.870549, 0.872320, 0.874144, 0.875947, 0.877674, 0.879192, 0.880478,
+ 0.881539, 0.882307, 0.882739, 0.882902, 0.882847, 0.882461, 0.881725, 0.880636, 0.879197,
+ 0.877422, 0.875296, 0.872849, 0.870076, 0.866988, 0.863637, 0.860159, 0.856475, 0.852525,
+ 0.848328, 0.843883, 0.839198, 0.834322, 0.829221, 0.823907, 0.818461, 0.812972, 0.807316,
+ 0.801474, 0.795459, 0.789276, 0.783025, 0.776615, 0.770223, 0.999999, 0.999994, 0.999909,
+ 0.999536, 0.997195, 0.994123, 0.988168, 0.979344, 0.967003, 0.951763, 0.934724, 0.917948,
+ 0.902918, 0.890432, 0.880902, 0.874401, 0.870394, 0.868503, 0.868209, 0.869062, 0.870725,
+ 0.873006, 0.875558, 0.878230, 0.880893, 0.883445, 0.885832, 0.888059, 0.890058, 0.891782,
+ 0.893247, 0.894460, 0.895397, 0.896023, 0.896380, 0.896433, 0.896198, 0.895673, 0.894865,
+ 0.893908, 0.892700, 0.891224, 0.889501, 0.887539, 0.885336, 0.882903, 0.880244, 0.877373,
+ 0.874296, 0.871019, 0.867549, 0.863933, 0.860153, 0.856355, 0.852395, 0.848277, 0.844006,
+ 0.839587, 0.835045, 0.830378, 0.825579, 0.820649, 0.815592, 0.810432, 0.999998, 0.999988,
+ 0.999795, 0.998892, 0.994635, 0.987290, 0.975397, 0.958508, 0.938352, 0.917733, 0.899800,
+ 0.885878, 0.876516, 0.871200, 0.869099, 0.869317, 0.871112, 0.873870, 0.877160, 0.880682,
+ 0.884228, 0.887737, 0.891076, 0.894161, 0.896981, 0.899543, 0.901847, 0.903882, 0.905672,
+ 0.907188, 0.908451, 0.909480, 0.910289, 0.910878, 0.911259, 0.911430, 0.911396, 0.911154,
+ 0.910712, 0.910081, 0.909266, 0.908264, 0.907094, 0.905752, 0.904244, 0.902577, 0.900799,
+ 0.898931, 0.896923, 0.894782, 0.892513, 0.890117, 0.887600, 0.884968, 0.882222, 0.879369,
+ 0.876408, 0.873345, 0.870183, 0.866926, 0.863575, 0.860160, 0.856672, 0.853098, 0.999991,
+ 0.999947, 0.999158, 0.992842, 0.980107, 0.957230, 0.928231, 0.901539, 0.882688, 0.872588,
+ 0.869394, 0.870671, 0.874458, 0.879378, 0.884639, 0.889770, 0.894601, 0.898972, 0.902930,
+ 0.906456, 0.909568, 0.912329, 0.914750, 0.916893, 0.918774, 0.920429, 0.921868, 0.923110,
+ 0.924185, 0.925089, 0.925842, 0.926457, 0.926934, 0.927285, 0.927522, 0.927639, 0.927650,
+ 0.927553, 0.927356, 0.927061, 0.926671, 0.926187, 0.925617, 0.924962, 0.924224, 0.923409,
+ 0.922519, 0.921555, 0.920521, 0.919419, 0.918252, 0.917021, 0.915729, 0.914377, 0.912967,
+ 0.911503, 0.909984, 0.908414, 0.906791, 0.905122, 0.903401, 0.901637, 0.899826, 0.897972,
+ 0.987461, 0.940121, 0.871507, 0.898572, 0.916705, 0.926425, 0.931922, 0.935265, 0.937431,
+ 0.938899, 0.939950, 0.940717, 0.941301, 0.941754, 0.942111, 0.942397, 0.942631, 0.942823,
+ 0.942983, 0.943117, 0.943231, 0.943329, 0.943412, 0.943484, 0.943545, 0.943599, 0.943644,
+ 0.943682, 0.943716, 0.943744, 0.943766, 0.943785, 0.943799, 0.943808, 0.943815, 0.943818,
+ 0.943818, 0.943814, 0.943807, 0.943797, 0.943784, 0.943769, 0.943751, 0.943730, 0.943707,
+ 0.943681, 0.943652, 0.943623, 0.943589, 0.943554, 0.943518, 0.943479, 0.943438, 0.943396,
+ 0.943351, 0.943305, 0.943257, 0.943207, 0.943156, 0.943104, 0.943049, 0.942993, 0.942936,
+ 0.942877,
+};
+
+static float bsdf_split_sum_ggx[64 * 64 * 2] = {
+ 1.000000f, 0.000000f, 1.000000f, 0.000000f, 1.000000f, 0.000000f, 1.000000f, 0.000000f,
+ 1.000000f, 0.000000f, 1.000000f, 0.000000f, 0.999512f, 0.000000f, 0.999512f, 0.000000f,
+ 0.999512f, 0.000000f, 0.999023f, 0.000001f, 0.999023f, 0.000001f, 0.998535f, 0.000001f,
+ 0.998047f, 0.000001f, 0.997559f, 0.000002f, 0.997070f, 0.000003f, 0.996094f, 0.000004f,
+ 0.994629f, 0.000004f, 0.993652f, 0.000006f, 0.991699f, 0.000007f, 0.989746f, 0.000008f,
+ 0.987305f, 0.000010f, 0.984375f, 0.000012f, 0.980957f, 0.000013f, 0.977539f, 0.000016f,
+ 0.973145f, 0.000018f, 0.967773f, 0.000020f, 0.961914f, 0.000023f, 0.955566f, 0.000025f,
+ 0.947754f, 0.000028f, 0.939941f, 0.000031f, 0.930664f, 0.000033f, 0.920410f, 0.000036f,
+ 0.909180f, 0.000039f, 0.896973f, 0.000042f, 0.884277f, 0.000044f, 0.870117f, 0.000047f,
+ 0.854980f, 0.000049f, 0.838867f, 0.000051f, 0.821777f, 0.000053f, 0.803711f, 0.000055f,
+ 0.785156f, 0.000057f, 0.765625f, 0.000058f, 0.745605f, 0.000059f, 0.724609f, 0.000060f,
+ 0.703613f, 0.000061f, 0.681641f, 0.000061f, 0.659668f, 0.000061f, 0.637695f, 0.000061f,
+ 0.615234f, 0.000061f, 0.592773f, 0.000060f, 0.570801f, 0.000060f, 0.548340f, 0.000059f,
+ 0.526855f, 0.000058f, 0.504883f, 0.000057f, 0.483887f, 0.000055f, 0.462891f, 0.000054f,
+ 0.442627f, 0.000053f, 0.422607f, 0.000051f, 0.403320f, 0.000050f, 0.384766f, 0.000048f,
+ 0.366455f, 0.000046f, 0.348877f, 0.000045f, 0.332031f, 0.000043f, 0.315918f, 0.000041f,
+ 0.999512f, 0.000000f, 0.999512f, 0.000000f, 1.000000f, 0.000000f, 1.000000f, 0.000000f,
+ 0.999512f, 0.000000f, 1.000000f, 0.000000f, 0.999512f, 0.000000f, 0.999512f, 0.000000f,
+ 0.999512f, 0.000000f, 0.999023f, 0.000001f, 0.999023f, 0.000001f, 0.998535f, 0.000002f,
+ 0.998047f, 0.000003f, 0.997559f, 0.000004f, 0.997070f, 0.000005f, 0.996094f, 0.000006f,
+ 0.994629f, 0.000008f, 0.993164f, 0.000010f, 0.991699f, 0.000012f, 0.989746f, 0.000015f,
+ 0.987305f, 0.000018f, 0.984375f, 0.000020f, 0.980957f, 0.000024f, 0.977051f, 0.000027f,
+ 0.972168f, 0.000031f, 0.967285f, 0.000035f, 0.961426f, 0.000039f, 0.954590f, 0.000043f,
+ 0.947266f, 0.000048f, 0.938965f, 0.000052f, 0.929199f, 0.000057f, 0.919434f, 0.000061f,
+ 0.908203f, 0.000065f, 0.895996f, 0.000069f, 0.882812f, 0.000073f, 0.868652f, 0.000077f,
+ 0.853027f, 0.000080f, 0.837402f, 0.000083f, 0.820312f, 0.000086f, 0.802246f, 0.000088f,
+ 0.783691f, 0.000090f, 0.764160f, 0.000092f, 0.744141f, 0.000093f, 0.723633f, 0.000093f,
+ 0.702637f, 0.000094f, 0.681152f, 0.000094f, 0.659180f, 0.000093f, 0.637207f, 0.000093f,
+ 0.615234f, 0.000091f, 0.593262f, 0.000090f, 0.571289f, 0.000088f, 0.549316f, 0.000087f,
+ 0.527344f, 0.000085f, 0.505859f, 0.000082f, 0.485107f, 0.000080f, 0.464355f, 0.000078f,
+ 0.444336f, 0.000075f, 0.424561f, 0.000072f, 0.405273f, 0.000070f, 0.386719f, 0.000067f,
+ 0.368652f, 0.000065f, 0.351318f, 0.000062f, 0.334473f, 0.000059f, 0.318115f, 0.000057f,
+ 0.999512f, 0.000000f, 0.999512f, 0.000000f, 0.999512f, 0.000000f, 1.000000f, 0.000000f,
+ 0.999512f, 0.000000f, 0.999512f, 0.000000f, 0.999512f, 0.000001f, 0.999512f, 0.000001f,
+ 0.999512f, 0.000001f, 0.999512f, 0.000003f, 0.999023f, 0.000002f, 0.998535f, 0.000004f,
+ 0.998047f, 0.000005f, 0.997559f, 0.000007f, 0.997070f, 0.000009f, 0.996094f, 0.000011f,
+ 0.994629f, 0.000013f, 0.993164f, 0.000017f, 0.991211f, 0.000020f, 0.989258f, 0.000024f,
+ 0.986816f, 0.000028f, 0.983887f, 0.000033f, 0.980469f, 0.000038f, 0.976562f, 0.000043f,
+ 0.971680f, 0.000049f, 0.966797f, 0.000055f, 0.960449f, 0.000062f, 0.953613f, 0.000068f,
+ 0.946289f, 0.000075f, 0.937500f, 0.000081f, 0.928223f, 0.000088f, 0.917969f, 0.000094f,
+ 0.906738f, 0.000100f, 0.894531f, 0.000106f, 0.880859f, 0.000111f, 0.866699f, 0.000116f,
+ 0.851562f, 0.000120f, 0.835449f, 0.000124f, 0.818359f, 0.000127f, 0.800781f, 0.000130f,
+ 0.782227f, 0.000132f, 0.762695f, 0.000134f, 0.742676f, 0.000134f, 0.722656f, 0.000135f,
+ 0.701660f, 0.000134f, 0.680176f, 0.000133f, 0.658691f, 0.000132f, 0.636719f, 0.000130f,
+ 0.615234f, 0.000128f, 0.593262f, 0.000125f, 0.571289f, 0.000123f, 0.549805f, 0.000119f,
+ 0.528320f, 0.000116f, 0.507324f, 0.000112f, 0.486328f, 0.000109f, 0.466064f, 0.000105f,
+ 0.446045f, 0.000101f, 0.426514f, 0.000097f, 0.407471f, 0.000093f, 0.388916f, 0.000089f,
+ 0.370850f, 0.000085f, 0.353516f, 0.000082f, 0.336914f, 0.000078f, 0.320557f, 0.000074f,
+ 1.000000f, 0.000000f, 0.999512f, 0.000000f, 0.999512f, 0.000000f, 0.999512f, 0.000000f,
+ 1.000000f, 0.000000f, 1.000000f, 0.000001f, 0.999512f, 0.000001f, 0.999512f, 0.000002f,
+ 0.999512f, 0.000002f, 0.999023f, 0.000003f, 0.999023f, 0.000005f, 0.998535f, 0.000006f,
+ 0.998535f, 0.000008f, 0.997559f, 0.000011f, 0.997070f, 0.000014f, 0.996094f, 0.000017f,
+ 0.994629f, 0.000020f, 0.993164f, 0.000026f, 0.991211f, 0.000030f, 0.989258f, 0.000036f,
+ 0.986816f, 0.000043f, 0.983398f, 0.000050f, 0.979980f, 0.000058f, 0.976074f, 0.000066f,
+ 0.971191f, 0.000074f, 0.965820f, 0.000082f, 0.959961f, 0.000093f, 0.952637f, 0.000101f,
+ 0.945312f, 0.000111f, 0.936523f, 0.000120f, 0.927246f, 0.000129f, 0.916504f, 0.000137f,
+ 0.905273f, 0.000145f, 0.892578f, 0.000153f, 0.879395f, 0.000160f, 0.865234f, 0.000166f,
+ 0.850098f, 0.000171f, 0.833984f, 0.000176f, 0.816895f, 0.000179f, 0.799316f, 0.000182f,
+ 0.780762f, 0.000184f, 0.761230f, 0.000185f, 0.741699f, 0.000185f, 0.721191f, 0.000184f,
+ 0.700684f, 0.000183f, 0.679688f, 0.000181f, 0.658203f, 0.000178f, 0.636719f, 0.000175f,
+ 0.615234f, 0.000171f, 0.593262f, 0.000167f, 0.571777f, 0.000162f, 0.550293f, 0.000158f,
+ 0.529297f, 0.000152f, 0.508301f, 0.000147f, 0.487793f, 0.000142f, 0.467529f, 0.000136f,
+ 0.447754f, 0.000131f, 0.428223f, 0.000125f, 0.409424f, 0.000120f, 0.391113f, 0.000115f,
+ 0.373291f, 0.000109f, 0.355957f, 0.000104f, 0.339355f, 0.000099f, 0.323242f, 0.000094f,
+ 0.999512f, 0.000002f, 0.999512f, 0.000002f, 1.000000f, 0.000002f, 0.999512f, 0.000002f,
+ 1.000000f, 0.000002f, 0.999512f, 0.000002f, 0.999512f, 0.000002f, 0.999512f, 0.000003f,
+ 0.999512f, 0.000004f, 0.999512f, 0.000005f, 0.999023f, 0.000007f, 0.998535f, 0.000010f,
+ 0.998047f, 0.000012f, 0.997559f, 0.000017f, 0.996582f, 0.000020f, 0.995605f, 0.000025f,
+ 0.994629f, 0.000032f, 0.993164f, 0.000038f, 0.991211f, 0.000047f, 0.988770f, 0.000055f,
+ 0.986328f, 0.000063f, 0.983398f, 0.000074f, 0.979492f, 0.000085f, 0.975586f, 0.000095f,
+ 0.970703f, 0.000108f, 0.965332f, 0.000121f, 0.958984f, 0.000132f, 0.952148f, 0.000145f,
+ 0.944336f, 0.000157f, 0.935547f, 0.000170f, 0.925781f, 0.000181f, 0.915039f, 0.000192f,
+ 0.903809f, 0.000203f, 0.891113f, 0.000212f, 0.877930f, 0.000220f, 0.863281f, 0.000227f,
+ 0.848145f, 0.000234f, 0.832031f, 0.000239f, 0.814941f, 0.000242f, 0.797363f, 0.000245f,
+ 0.778809f, 0.000247f, 0.759766f, 0.000247f, 0.740234f, 0.000246f, 0.720215f, 0.000244f,
+ 0.699707f, 0.000241f, 0.678711f, 0.000237f, 0.657715f, 0.000233f, 0.636230f, 0.000228f,
+ 0.614746f, 0.000222f, 0.593750f, 0.000216f, 0.572266f, 0.000209f, 0.551270f, 0.000202f,
+ 0.530273f, 0.000195f, 0.509277f, 0.000187f, 0.489014f, 0.000180f, 0.468994f, 0.000172f,
+ 0.449463f, 0.000165f, 0.430176f, 0.000157f, 0.411377f, 0.000150f, 0.393311f, 0.000143f,
+ 0.375488f, 0.000136f, 0.358398f, 0.000129f, 0.341797f, 0.000123f, 0.325684f, 0.000116f,
+ 0.999512f, 0.000005f, 0.999512f, 0.000005f, 0.999512f, 0.000005f, 0.999512f, 0.000005f,
+ 0.999512f, 0.000005f, 0.999512f, 0.000005f, 0.999512f, 0.000006f, 0.999512f, 0.000007f,
+ 0.999512f, 0.000008f, 0.999512f, 0.000011f, 0.999023f, 0.000013f, 0.998535f, 0.000015f,
+ 0.998047f, 0.000019f, 0.997559f, 0.000026f, 0.996582f, 0.000033f, 0.995605f, 0.000040f,
+ 0.994141f, 0.000047f, 0.993164f, 0.000058f, 0.991211f, 0.000069f, 0.988770f, 0.000080f,
+ 0.985840f, 0.000093f, 0.982910f, 0.000106f, 0.979004f, 0.000121f, 0.975098f, 0.000137f,
+ 0.970215f, 0.000153f, 0.964355f, 0.000169f, 0.958008f, 0.000186f, 0.951172f, 0.000201f,
+ 0.943359f, 0.000218f, 0.934082f, 0.000233f, 0.924316f, 0.000248f, 0.914062f, 0.000262f,
+ 0.902344f, 0.000275f, 0.889648f, 0.000286f, 0.875977f, 0.000295f, 0.861816f, 0.000304f,
+ 0.846680f, 0.000311f, 0.830566f, 0.000316f, 0.813477f, 0.000319f, 0.795898f, 0.000321f,
+ 0.777344f, 0.000322f, 0.758301f, 0.000320f, 0.739258f, 0.000318f, 0.719238f, 0.000314f,
+ 0.698730f, 0.000309f, 0.678223f, 0.000303f, 0.657227f, 0.000296f, 0.636230f, 0.000288f,
+ 0.614746f, 0.000280f, 0.593750f, 0.000271f, 0.572754f, 0.000262f, 0.551758f, 0.000252f,
+ 0.531250f, 0.000243f, 0.510742f, 0.000233f, 0.490479f, 0.000223f, 0.470703f, 0.000213f,
+ 0.451172f, 0.000203f, 0.432129f, 0.000194f, 0.413574f, 0.000184f, 0.395508f, 0.000175f,
+ 0.377930f, 0.000166f, 0.360840f, 0.000157f, 0.344238f, 0.000149f, 0.328125f, 0.000141f,
+ 0.999512f, 0.000011f, 0.999512f, 0.000011f, 0.999512f, 0.000011f, 0.999512f, 0.000011f,
+ 0.999512f, 0.000011f, 0.999512f, 0.000012f, 0.999512f, 0.000014f, 0.999512f, 0.000015f,
+ 0.999512f, 0.000017f, 0.999023f, 0.000020f, 0.998535f, 0.000022f, 0.998535f, 0.000028f,
+ 0.998047f, 0.000034f, 0.997559f, 0.000042f, 0.996582f, 0.000050f, 0.995605f, 0.000060f,
+ 0.994141f, 0.000072f, 0.992676f, 0.000084f, 0.990723f, 0.000099f, 0.988281f, 0.000115f,
+ 0.985840f, 0.000133f, 0.982422f, 0.000150f, 0.978516f, 0.000171f, 0.974609f, 0.000191f,
+ 0.969238f, 0.000211f, 0.963867f, 0.000232f, 0.957520f, 0.000253f, 0.950195f, 0.000274f,
+ 0.941895f, 0.000294f, 0.933105f, 0.000314f, 0.922852f, 0.000332f, 0.912109f, 0.000348f,
+ 0.900879f, 0.000363f, 0.888184f, 0.000377f, 0.874512f, 0.000387f, 0.859863f, 0.000397f,
+ 0.844727f, 0.000404f, 0.828613f, 0.000408f, 0.811523f, 0.000411f, 0.793945f, 0.000412f,
+ 0.775879f, 0.000411f, 0.756836f, 0.000407f, 0.737793f, 0.000403f, 0.717773f, 0.000396f,
+ 0.697754f, 0.000389f, 0.677246f, 0.000380f, 0.656738f, 0.000370f, 0.635742f, 0.000359f,
+ 0.614746f, 0.000347f, 0.594238f, 0.000335f, 0.573242f, 0.000323f, 0.552734f, 0.000310f,
+ 0.532227f, 0.000297f, 0.511719f, 0.000284f, 0.491943f, 0.000272f, 0.472412f, 0.000259f,
+ 0.453125f, 0.000246f, 0.434082f, 0.000234f, 0.415771f, 0.000222f, 0.397705f, 0.000211f,
+ 0.380127f, 0.000199f, 0.363281f, 0.000189f, 0.346680f, 0.000178f, 0.330811f, 0.000168f,
+ 0.999512f, 0.000022f, 0.999512f, 0.000022f, 0.999512f, 0.000022f, 0.999512f, 0.000022f,
+ 0.999512f, 0.000023f, 0.999512f, 0.000025f, 0.999512f, 0.000024f, 0.999512f, 0.000028f,
+ 0.999023f, 0.000030f, 0.999023f, 0.000035f, 0.999023f, 0.000040f, 0.998535f, 0.000046f,
+ 0.998047f, 0.000056f, 0.997559f, 0.000063f, 0.996094f, 0.000077f, 0.995605f, 0.000089f,
+ 0.994141f, 0.000106f, 0.992188f, 0.000123f, 0.990234f, 0.000143f, 0.987793f, 0.000163f,
+ 0.985352f, 0.000185f, 0.981934f, 0.000211f, 0.978027f, 0.000236f, 0.973633f, 0.000261f,
+ 0.968750f, 0.000288f, 0.962891f, 0.000314f, 0.956055f, 0.000341f, 0.949219f, 0.000366f,
+ 0.940918f, 0.000391f, 0.931641f, 0.000414f, 0.921875f, 0.000436f, 0.910645f, 0.000455f,
+ 0.898926f, 0.000471f, 0.886230f, 0.000487f, 0.872559f, 0.000499f, 0.858398f, 0.000509f,
+ 0.842773f, 0.000515f, 0.826660f, 0.000518f, 0.810059f, 0.000520f, 0.792480f, 0.000519f,
+ 0.774414f, 0.000515f, 0.755371f, 0.000509f, 0.736328f, 0.000501f, 0.716797f, 0.000492f,
+ 0.696777f, 0.000480f, 0.676758f, 0.000468f, 0.656250f, 0.000454f, 0.635742f, 0.000439f,
+ 0.615234f, 0.000424f, 0.594238f, 0.000408f, 0.573730f, 0.000392f, 0.553223f, 0.000375f,
+ 0.533203f, 0.000359f, 0.513184f, 0.000342f, 0.493408f, 0.000326f, 0.474121f, 0.000310f,
+ 0.455078f, 0.000294f, 0.436279f, 0.000279f, 0.417969f, 0.000264f, 0.400146f, 0.000250f,
+ 0.382812f, 0.000237f, 0.365723f, 0.000223f, 0.349365f, 0.000211f, 0.333496f, 0.000199f,
+ 0.999512f, 0.000041f, 0.999512f, 0.000041f, 0.999512f, 0.000041f, 0.999512f, 0.000042f,
+ 0.999512f, 0.000042f, 0.999512f, 0.000044f, 0.999512f, 0.000046f, 0.999512f, 0.000049f,
+ 0.999512f, 0.000054f, 0.999512f, 0.000059f, 0.999023f, 0.000065f, 0.998535f, 0.000076f,
+ 0.998047f, 0.000087f, 0.997070f, 0.000098f, 0.996582f, 0.000117f, 0.995117f, 0.000135f,
+ 0.993652f, 0.000152f, 0.992188f, 0.000176f, 0.989746f, 0.000201f, 0.987793f, 0.000228f,
+ 0.984863f, 0.000256f, 0.981445f, 0.000286f, 0.977539f, 0.000318f, 0.973145f, 0.000352f,
+ 0.967773f, 0.000384f, 0.961914f, 0.000417f, 0.955566f, 0.000451f, 0.947754f, 0.000481f,
+ 0.939453f, 0.000510f, 0.930176f, 0.000537f, 0.919922f, 0.000563f, 0.909180f, 0.000585f,
+ 0.897461f, 0.000604f, 0.884766f, 0.000620f, 0.871094f, 0.000632f, 0.856445f, 0.000641f,
+ 0.841309f, 0.000647f, 0.825195f, 0.000648f, 0.808105f, 0.000648f, 0.790527f, 0.000643f,
+ 0.772949f, 0.000637f, 0.754395f, 0.000627f, 0.735352f, 0.000615f, 0.715820f, 0.000601f,
+ 0.695801f, 0.000585f, 0.675781f, 0.000568f, 0.655762f, 0.000550f, 0.635742f, 0.000530f,
+ 0.615234f, 0.000510f, 0.594727f, 0.000490f, 0.574707f, 0.000469f, 0.554199f, 0.000448f,
+ 0.534180f, 0.000428f, 0.514648f, 0.000407f, 0.495117f, 0.000387f, 0.475830f, 0.000367f,
+ 0.456787f, 0.000348f, 0.438232f, 0.000329f, 0.420166f, 0.000311f, 0.402344f, 0.000294f,
+ 0.385254f, 0.000277f, 0.368408f, 0.000262f, 0.352051f, 0.000246f, 0.336182f, 0.000232f,
+ 0.999512f, 0.000072f, 0.999512f, 0.000072f, 0.999512f, 0.000072f, 0.999512f, 0.000072f,
+ 0.999512f, 0.000073f, 0.999512f, 0.000076f, 0.999512f, 0.000078f, 0.999512f, 0.000082f,
+ 0.999023f, 0.000086f, 0.999023f, 0.000095f, 0.998535f, 0.000102f, 0.998047f, 0.000116f,
+ 0.998047f, 0.000131f, 0.997070f, 0.000147f, 0.996094f, 0.000167f, 0.995117f, 0.000195f,
+ 0.993652f, 0.000219f, 0.991699f, 0.000246f, 0.989746f, 0.000278f, 0.987305f, 0.000315f,
+ 0.984375f, 0.000350f, 0.980957f, 0.000385f, 0.976562f, 0.000427f, 0.972168f, 0.000467f,
+ 0.967285f, 0.000509f, 0.960938f, 0.000548f, 0.954102f, 0.000587f, 0.946777f, 0.000623f,
+ 0.937988f, 0.000657f, 0.928711f, 0.000690f, 0.918457f, 0.000718f, 0.907715f, 0.000741f,
+ 0.895508f, 0.000762f, 0.882812f, 0.000778f, 0.869141f, 0.000791f, 0.854492f, 0.000798f,
+ 0.839355f, 0.000802f, 0.823242f, 0.000801f, 0.806152f, 0.000796f, 0.789062f, 0.000788f,
+ 0.770996f, 0.000777f, 0.752930f, 0.000762f, 0.733887f, 0.000745f, 0.714844f, 0.000726f,
+ 0.695312f, 0.000704f, 0.675293f, 0.000682f, 0.655273f, 0.000658f, 0.635254f, 0.000633f,
+ 0.615234f, 0.000607f, 0.595215f, 0.000582f, 0.575195f, 0.000556f, 0.555176f, 0.000530f,
+ 0.535645f, 0.000504f, 0.515625f, 0.000479f, 0.496582f, 0.000455f, 0.477539f, 0.000431f,
+ 0.458984f, 0.000407f, 0.440430f, 0.000385f, 0.422363f, 0.000363f, 0.404785f, 0.000343f,
+ 0.387695f, 0.000323f, 0.370850f, 0.000304f, 0.354736f, 0.000286f, 0.338867f, 0.000268f,
+ 0.999512f, 0.000119f, 0.999512f, 0.000119f, 0.999512f, 0.000119f, 0.999512f, 0.000119f,
+ 0.999512f, 0.000121f, 0.999512f, 0.000122f, 0.999512f, 0.000128f, 0.999512f, 0.000131f,
+ 0.999512f, 0.000139f, 0.999023f, 0.000149f, 0.998535f, 0.000161f, 0.998047f, 0.000179f,
+ 0.998047f, 0.000194f, 0.997070f, 0.000220f, 0.996094f, 0.000247f, 0.994629f, 0.000275f,
+ 0.993652f, 0.000309f, 0.991699f, 0.000344f, 0.989746f, 0.000385f, 0.986816f, 0.000429f,
+ 0.983887f, 0.000471f, 0.980469f, 0.000519f, 0.976074f, 0.000565f, 0.971680f, 0.000614f,
+ 0.966309f, 0.000664f, 0.959961f, 0.000710f, 0.953125f, 0.000754f, 0.945312f, 0.000797f,
+ 0.936523f, 0.000837f, 0.927246f, 0.000873f, 0.916992f, 0.000902f, 0.905762f, 0.000929f,
+ 0.893555f, 0.000950f, 0.880859f, 0.000966f, 0.866699f, 0.000977f, 0.852539f, 0.000981f,
+ 0.836914f, 0.000981f, 0.821289f, 0.000977f, 0.804688f, 0.000968f, 0.787109f, 0.000955f,
+ 0.769531f, 0.000937f, 0.751465f, 0.000917f, 0.732422f, 0.000894f, 0.713379f, 0.000868f,
+ 0.694336f, 0.000840f, 0.674805f, 0.000811f, 0.655273f, 0.000780f, 0.635254f, 0.000749f,
+ 0.615723f, 0.000716f, 0.595703f, 0.000685f, 0.575684f, 0.000653f, 0.556152f, 0.000621f,
+ 0.536621f, 0.000590f, 0.517090f, 0.000559f, 0.498291f, 0.000530f, 0.479492f, 0.000501f,
+ 0.460938f, 0.000473f, 0.442627f, 0.000446f, 0.424805f, 0.000420f, 0.407227f, 0.000396f,
+ 0.390137f, 0.000373f, 0.373535f, 0.000350f, 0.357422f, 0.000329f, 0.341553f, 0.000309f,
+ 0.999512f, 0.000187f, 0.999512f, 0.000187f, 0.999512f, 0.000188f, 0.999512f, 0.000188f,
+ 0.999512f, 0.000190f, 0.999512f, 0.000194f, 0.999512f, 0.000201f, 0.999023f, 0.000204f,
+ 0.999023f, 0.000213f, 0.999023f, 0.000228f, 0.998535f, 0.000242f, 0.998535f, 0.000264f,
+ 0.997559f, 0.000285f, 0.997070f, 0.000311f, 0.996094f, 0.000351f, 0.995117f, 0.000386f,
+ 0.993164f, 0.000429f, 0.991211f, 0.000470f, 0.989258f, 0.000520f, 0.986328f, 0.000575f,
+ 0.983398f, 0.000628f, 0.979492f, 0.000683f, 0.975586f, 0.000741f, 0.970703f, 0.000801f,
+ 0.965332f, 0.000855f, 0.958984f, 0.000910f, 0.951660f, 0.000961f, 0.943848f, 0.001009f,
+ 0.935059f, 0.001053f, 0.925781f, 0.001090f, 0.915039f, 0.001123f, 0.903809f, 0.001152f,
+ 0.891602f, 0.001172f, 0.878906f, 0.001186f, 0.864746f, 0.001194f, 0.850586f, 0.001195f,
+ 0.835449f, 0.001191f, 0.819336f, 0.001181f, 0.802734f, 0.001164f, 0.785645f, 0.001144f,
+ 0.768066f, 0.001121f, 0.750000f, 0.001092f, 0.731445f, 0.001061f, 0.712402f, 0.001027f,
+ 0.693359f, 0.000992f, 0.674316f, 0.000955f, 0.654785f, 0.000916f, 0.635254f, 0.000877f,
+ 0.615723f, 0.000838f, 0.596191f, 0.000799f, 0.576660f, 0.000760f, 0.557129f, 0.000721f,
+ 0.538086f, 0.000684f, 0.518555f, 0.000648f, 0.500000f, 0.000612f, 0.481445f, 0.000578f,
+ 0.462891f, 0.000545f, 0.444824f, 0.000513f, 0.427246f, 0.000483f, 0.409912f, 0.000454f,
+ 0.392822f, 0.000427f, 0.376221f, 0.000401f, 0.360107f, 0.000376f, 0.344482f, 0.000353f,
+ 0.999512f, 0.000284f, 0.999512f, 0.000284f, 0.999512f, 0.000284f, 0.999512f, 0.000285f,
+ 0.999512f, 0.000287f, 0.999512f, 0.000292f, 0.999512f, 0.000296f, 0.999023f, 0.000307f,
+ 0.999023f, 0.000320f, 0.999023f, 0.000338f, 0.998535f, 0.000349f, 0.998047f, 0.000381f,
+ 0.997559f, 0.000407f, 0.996582f, 0.000447f, 0.995605f, 0.000480f, 0.994629f, 0.000531f,
+ 0.992676f, 0.000579f, 0.990723f, 0.000637f, 0.988770f, 0.000693f, 0.985840f, 0.000755f,
+ 0.982422f, 0.000824f, 0.979004f, 0.000889f, 0.975098f, 0.000958f, 0.969727f, 0.001024f,
+ 0.963867f, 0.001090f, 0.957520f, 0.001152f, 0.950684f, 0.001211f, 0.942383f, 0.001263f,
+ 0.933594f, 0.001309f, 0.923828f, 0.001353f, 0.913086f, 0.001387f, 0.901855f, 0.001413f,
+ 0.889648f, 0.001432f, 0.876465f, 0.001443f, 0.862793f, 0.001446f, 0.848145f, 0.001442f,
+ 0.833008f, 0.001431f, 0.817383f, 0.001413f, 0.800781f, 0.001390f, 0.783691f, 0.001362f,
+ 0.766113f, 0.001328f, 0.748535f, 0.001291f, 0.729980f, 0.001250f, 0.711426f, 0.001207f,
+ 0.692871f, 0.001163f, 0.673828f, 0.001116f, 0.654785f, 0.001068f, 0.635254f, 0.001020f,
+ 0.616211f, 0.000973f, 0.596680f, 0.000926f, 0.577637f, 0.000878f, 0.558105f, 0.000833f,
+ 0.539062f, 0.000788f, 0.520508f, 0.000745f, 0.501465f, 0.000702f, 0.483154f, 0.000663f,
+ 0.465088f, 0.000624f, 0.447266f, 0.000587f, 0.429443f, 0.000552f, 0.412354f, 0.000518f,
+ 0.395508f, 0.000486f, 0.378906f, 0.000456f, 0.363037f, 0.000427f, 0.347168f, 0.000400f,
+ 0.999512f, 0.000417f, 0.999512f, 0.000417f, 0.999512f, 0.000418f, 0.999512f, 0.000419f,
+ 0.999512f, 0.000422f, 0.999512f, 0.000425f, 0.999023f, 0.000434f, 0.999023f, 0.000447f,
+ 0.999023f, 0.000462f, 0.999023f, 0.000480f, 0.998047f, 0.000508f, 0.998047f, 0.000538f,
+ 0.997070f, 0.000576f, 0.996582f, 0.000621f, 0.995605f, 0.000669f, 0.993652f, 0.000721f,
+ 0.992188f, 0.000784f, 0.990723f, 0.000849f, 0.987793f, 0.000918f, 0.985840f, 0.000996f,
+ 0.982422f, 0.001071f, 0.978516f, 0.001148f, 0.973633f, 0.001225f, 0.968750f, 0.001304f,
+ 0.962891f, 0.001378f, 0.956543f, 0.001447f, 0.948730f, 0.001511f, 0.940918f, 0.001568f,
+ 0.931641f, 0.001617f, 0.921875f, 0.001660f, 0.911621f, 0.001697f, 0.899902f, 0.001719f,
+ 0.887695f, 0.001735f, 0.874512f, 0.001740f, 0.860840f, 0.001738f, 0.846191f, 0.001725f,
+ 0.831055f, 0.001706f, 0.815430f, 0.001679f, 0.798828f, 0.001646f, 0.782227f, 0.001607f,
+ 0.764648f, 0.001562f, 0.747070f, 0.001514f, 0.729004f, 0.001462f, 0.710449f, 0.001409f,
+ 0.691895f, 0.001352f, 0.673340f, 0.001295f, 0.654297f, 0.001237f, 0.635254f, 0.001179f,
+ 0.616211f, 0.001122f, 0.597168f, 0.001065f, 0.578125f, 0.001010f, 0.559570f, 0.000955f,
+ 0.540527f, 0.000902f, 0.521973f, 0.000852f, 0.503418f, 0.000803f, 0.485352f, 0.000755f,
+ 0.467285f, 0.000710f, 0.449463f, 0.000668f, 0.431885f, 0.000626f, 0.414795f, 0.000587f,
+ 0.398193f, 0.000551f, 0.381836f, 0.000516f, 0.365723f, 0.000483f, 0.350098f, 0.000452f,
+ 0.999023f, 0.000597f, 0.999023f, 0.000597f, 0.999023f, 0.000597f, 0.999023f, 0.000598f,
+ 0.999023f, 0.000602f, 0.999023f, 0.000610f, 0.999023f, 0.000618f, 0.999023f, 0.000632f,
+ 0.998535f, 0.000651f, 0.998535f, 0.000675f, 0.998047f, 0.000704f, 0.997559f, 0.000742f,
+ 0.997070f, 0.000787f, 0.996094f, 0.000843f, 0.995117f, 0.000902f, 0.993652f, 0.000966f,
+ 0.992188f, 0.001039f, 0.990234f, 0.001117f, 0.987793f, 0.001197f, 0.984863f, 0.001286f,
+ 0.981445f, 0.001372f, 0.977539f, 0.001464f, 0.972656f, 0.001553f, 0.967773f, 0.001639f,
+ 0.961914f, 0.001722f, 0.955078f, 0.001798f, 0.947754f, 0.001868f, 0.938965f, 0.001928f,
+ 0.930176f, 0.001982f, 0.920410f, 0.002026f, 0.909668f, 0.002056f, 0.897949f, 0.002075f,
+ 0.885254f, 0.002085f, 0.872559f, 0.002083f, 0.858398f, 0.002071f, 0.844238f, 0.002048f,
+ 0.828613f, 0.002018f, 0.812988f, 0.001980f, 0.796875f, 0.001934f, 0.780273f, 0.001883f,
+ 0.763184f, 0.001824f, 0.745605f, 0.001763f, 0.728027f, 0.001698f, 0.709473f, 0.001632f,
+ 0.691406f, 0.001563f, 0.672852f, 0.001494f, 0.654297f, 0.001422f, 0.635254f, 0.001355f,
+ 0.616699f, 0.001286f, 0.598145f, 0.001218f, 0.579102f, 0.001152f, 0.560547f, 0.001089f,
+ 0.541992f, 0.001027f, 0.523438f, 0.000968f, 0.505371f, 0.000911f, 0.487305f, 0.000857f,
+ 0.469482f, 0.000804f, 0.451904f, 0.000755f, 0.434570f, 0.000708f, 0.417480f, 0.000663f,
+ 0.400879f, 0.000621f, 0.384521f, 0.000581f, 0.368652f, 0.000544f, 0.353027f, 0.000508f,
+ 0.999023f, 0.000833f, 0.999023f, 0.000833f, 0.999023f, 0.000834f, 0.999023f, 0.000835f,
+ 0.999023f, 0.000840f, 0.999023f, 0.000845f, 0.998535f, 0.000861f, 0.998535f, 0.000875f,
+ 0.998535f, 0.000897f, 0.998047f, 0.000928f, 0.997559f, 0.000965f, 0.997070f, 0.001007f,
+ 0.996582f, 0.001061f, 0.995605f, 0.001128f, 0.994629f, 0.001195f, 0.993164f, 0.001276f,
+ 0.991699f, 0.001362f, 0.989258f, 0.001453f, 0.986816f, 0.001539f, 0.983887f, 0.001645f,
+ 0.980469f, 0.001747f, 0.976562f, 0.001849f, 0.971680f, 0.001945f, 0.966309f, 0.002045f,
+ 0.959961f, 0.002136f, 0.953613f, 0.002218f, 0.945801f, 0.002291f, 0.937500f, 0.002357f,
+ 0.928223f, 0.002407f, 0.917969f, 0.002447f, 0.907227f, 0.002472f, 0.895508f, 0.002487f,
+ 0.883301f, 0.002485f, 0.870117f, 0.002474f, 0.856445f, 0.002451f, 0.841797f, 0.002417f,
+ 0.826660f, 0.002373f, 0.811035f, 0.002317f, 0.794922f, 0.002258f, 0.778320f, 0.002190f,
+ 0.761230f, 0.002117f, 0.744141f, 0.002041f, 0.726562f, 0.001961f, 0.708496f, 0.001880f,
+ 0.690430f, 0.001796f, 0.672363f, 0.001713f, 0.654297f, 0.001630f, 0.635742f, 0.001547f,
+ 0.617188f, 0.001466f, 0.598633f, 0.001387f, 0.580078f, 0.001310f, 0.561523f, 0.001235f,
+ 0.543457f, 0.001164f, 0.524902f, 0.001095f, 0.507324f, 0.001029f, 0.489258f, 0.000967f,
+ 0.471680f, 0.000906f, 0.454346f, 0.000850f, 0.437012f, 0.000796f, 0.420166f, 0.000745f,
+ 0.403564f, 0.000698f, 0.387451f, 0.000652f, 0.371582f, 0.000609f, 0.356201f, 0.000569f,
+ 0.998535f, 0.001139f, 0.998535f, 0.001139f, 0.998535f, 0.001140f, 0.998535f, 0.001142f,
+ 0.998535f, 0.001147f, 0.998535f, 0.001159f, 0.998535f, 0.001168f, 0.998047f, 0.001190f,
+ 0.998047f, 0.001217f, 0.997559f, 0.001254f, 0.997559f, 0.001301f, 0.997070f, 0.001356f,
+ 0.996094f, 0.001416f, 0.995605f, 0.001493f, 0.994141f, 0.001574f, 0.992676f, 0.001663f,
+ 0.990723f, 0.001759f, 0.988770f, 0.001867f, 0.986328f, 0.001980f, 0.982910f, 0.002087f,
+ 0.979492f, 0.002199f, 0.975586f, 0.002319f, 0.970703f, 0.002422f, 0.965332f, 0.002531f,
+ 0.958496f, 0.002628f, 0.952148f, 0.002714f, 0.944336f, 0.002792f, 0.935547f, 0.002851f,
+ 0.926270f, 0.002903f, 0.916016f, 0.002935f, 0.904785f, 0.002954f, 0.893066f, 0.002956f,
+ 0.880859f, 0.002947f, 0.867676f, 0.002920f, 0.853516f, 0.002882f, 0.839355f, 0.002831f,
+ 0.824219f, 0.002769f, 0.809082f, 0.002699f, 0.792969f, 0.002619f, 0.776367f, 0.002533f,
+ 0.759766f, 0.002443f, 0.742676f, 0.002350f, 0.725586f, 0.002251f, 0.708008f, 0.002151f,
+ 0.689941f, 0.002052f, 0.671875f, 0.001953f, 0.653809f, 0.001854f, 0.635742f, 0.001758f,
+ 0.617676f, 0.001663f, 0.599121f, 0.001572f, 0.581055f, 0.001482f, 0.562988f, 0.001395f,
+ 0.544922f, 0.001313f, 0.526855f, 0.001234f, 0.508789f, 0.001158f, 0.491455f, 0.001086f,
+ 0.473877f, 0.001018f, 0.456787f, 0.000954f, 0.439697f, 0.000892f, 0.422852f, 0.000834f,
+ 0.406494f, 0.000780f, 0.390381f, 0.000729f, 0.374512f, 0.000680f, 0.359131f, 0.000635f,
+ 0.998047f, 0.001528f, 0.998047f, 0.001528f, 0.998047f, 0.001529f, 0.998047f, 0.001532f,
+ 0.998047f, 0.001539f, 0.998047f, 0.001546f, 0.998047f, 0.001562f, 0.998047f, 0.001589f,
+ 0.997559f, 0.001621f, 0.997559f, 0.001668f, 0.996582f, 0.001715f, 0.996582f, 0.001777f,
+ 0.995605f, 0.001859f, 0.994629f, 0.001939f, 0.993652f, 0.002035f, 0.992188f, 0.002140f,
+ 0.990234f, 0.002243f, 0.987793f, 0.002369f, 0.985352f, 0.002489f, 0.981934f, 0.002621f,
+ 0.978516f, 0.002750f, 0.974121f, 0.002876f, 0.969238f, 0.002991f, 0.963867f, 0.003105f,
+ 0.957031f, 0.003206f, 0.950195f, 0.003300f, 0.942383f, 0.003374f, 0.933594f, 0.003431f,
+ 0.923828f, 0.003473f, 0.913574f, 0.003498f, 0.902344f, 0.003506f, 0.890625f, 0.003494f,
+ 0.878418f, 0.003468f, 0.865234f, 0.003426f, 0.851074f, 0.003366f, 0.836914f, 0.003296f,
+ 0.822266f, 0.003216f, 0.806641f, 0.003122f, 0.791016f, 0.003023f, 0.774902f, 0.002916f,
+ 0.758301f, 0.002804f, 0.741211f, 0.002689f, 0.724121f, 0.002573f, 0.707031f, 0.002453f,
+ 0.689453f, 0.002335f, 0.671875f, 0.002216f, 0.653809f, 0.002102f, 0.636230f, 0.001987f,
+ 0.618164f, 0.001878f, 0.600098f, 0.001771f, 0.582031f, 0.001668f, 0.564453f, 0.001569f,
+ 0.546387f, 0.001475f, 0.528809f, 0.001384f, 0.511230f, 0.001297f, 0.493652f, 0.001217f,
+ 0.476318f, 0.001139f, 0.459229f, 0.001065f, 0.442383f, 0.000996f, 0.425781f, 0.000930f,
+ 0.409424f, 0.000869f, 0.393311f, 0.000811f, 0.377686f, 0.000757f, 0.362305f, 0.000707f,
+ 0.997559f, 0.002018f, 0.997559f, 0.002018f, 0.997559f, 0.002018f, 0.997559f, 0.002022f,
+ 0.997559f, 0.002028f, 0.997559f, 0.002045f, 0.997559f, 0.002066f, 0.997559f, 0.002092f,
+ 0.997559f, 0.002129f, 0.996582f, 0.002176f, 0.996094f, 0.002235f, 0.995605f, 0.002312f,
+ 0.995605f, 0.002407f, 0.993652f, 0.002491f, 0.992676f, 0.002605f, 0.991211f, 0.002729f,
+ 0.989258f, 0.002846f, 0.987305f, 0.002987f, 0.984375f, 0.003120f, 0.980957f, 0.003263f,
+ 0.977051f, 0.003403f, 0.972656f, 0.003542f, 0.967285f, 0.003666f, 0.961914f, 0.003782f,
+ 0.955566f, 0.003889f, 0.947754f, 0.003967f, 0.939941f, 0.004044f, 0.931152f, 0.004097f,
+ 0.921387f, 0.004131f, 0.911133f, 0.004139f, 0.899902f, 0.004131f, 0.888184f, 0.004108f,
+ 0.875488f, 0.004055f, 0.862305f, 0.003990f, 0.848633f, 0.003914f, 0.834473f, 0.003819f,
+ 0.819824f, 0.003712f, 0.804199f, 0.003593f, 0.788574f, 0.003469f, 0.772949f, 0.003338f,
+ 0.756348f, 0.003201f, 0.739746f, 0.003063f, 0.723145f, 0.002924f, 0.706055f, 0.002781f,
+ 0.688965f, 0.002644f, 0.671387f, 0.002506f, 0.653809f, 0.002371f, 0.636230f, 0.002239f,
+ 0.618652f, 0.002111f, 0.601074f, 0.001989f, 0.583496f, 0.001871f, 0.565430f, 0.001759f,
+ 0.547852f, 0.001650f, 0.530273f, 0.001547f, 0.513184f, 0.001449f, 0.495850f, 0.001356f,
+ 0.478760f, 0.001269f, 0.461670f, 0.001185f, 0.445068f, 0.001107f, 0.428467f, 0.001035f,
+ 0.412354f, 0.000965f, 0.396240f, 0.000901f, 0.380615f, 0.000840f, 0.365479f, 0.000783f,
+ 0.997070f, 0.002625f, 0.997070f, 0.002625f, 0.997070f, 0.002626f, 0.997070f, 0.002630f,
+ 0.997070f, 0.002640f, 0.997070f, 0.002659f, 0.997070f, 0.002676f, 0.996582f, 0.002708f,
+ 0.996582f, 0.002752f, 0.996094f, 0.002813f, 0.995605f, 0.002886f, 0.995117f, 0.002956f,
+ 0.994141f, 0.003071f, 0.992676f, 0.003172f, 0.991699f, 0.003292f, 0.990234f, 0.003433f,
+ 0.988281f, 0.003580f, 0.985840f, 0.003727f, 0.982910f, 0.003870f, 0.979492f, 0.004028f,
+ 0.975586f, 0.004177f, 0.971191f, 0.004322f, 0.966309f, 0.004456f, 0.959961f, 0.004570f,
+ 0.953125f, 0.004669f, 0.945801f, 0.004757f, 0.937500f, 0.004826f, 0.928711f, 0.004864f,
+ 0.918945f, 0.004883f, 0.908691f, 0.004875f, 0.897461f, 0.004845f, 0.885254f, 0.004795f,
+ 0.872559f, 0.004723f, 0.859863f, 0.004631f, 0.846191f, 0.004520f, 0.832031f, 0.004398f,
+ 0.817383f, 0.004261f, 0.802246f, 0.004116f, 0.786621f, 0.003963f, 0.770996f, 0.003805f,
+ 0.754883f, 0.003639f, 0.738770f, 0.003475f, 0.722168f, 0.003307f, 0.705078f, 0.003143f,
+ 0.688477f, 0.002981f, 0.671387f, 0.002821f, 0.653809f, 0.002665f, 0.636719f, 0.002512f,
+ 0.619141f, 0.002367f, 0.602051f, 0.002226f, 0.584473f, 0.002090f, 0.566895f, 0.001963f,
+ 0.549805f, 0.001840f, 0.532227f, 0.001722f, 0.515137f, 0.001613f, 0.498047f, 0.001508f,
+ 0.481201f, 0.001409f, 0.464355f, 0.001316f, 0.447754f, 0.001228f, 0.431396f, 0.001145f,
+ 0.415283f, 0.001069f, 0.399414f, 0.000997f, 0.383789f, 0.000929f, 0.368652f, 0.000865f,
+ 0.996582f, 0.003370f, 0.996582f, 0.003370f, 0.996582f, 0.003372f, 0.996582f, 0.003378f,
+ 0.996582f, 0.003389f, 0.996094f, 0.003410f, 0.996094f, 0.003435f, 0.996094f, 0.003471f,
+ 0.996094f, 0.003523f, 0.995117f, 0.003588f, 0.995117f, 0.003664f, 0.994141f, 0.003754f,
+ 0.993164f, 0.003864f, 0.992676f, 0.003990f, 0.990723f, 0.004128f, 0.989746f, 0.004288f,
+ 0.987793f, 0.004429f, 0.984375f, 0.004601f, 0.981445f, 0.004757f, 0.978027f, 0.004925f,
+ 0.974121f, 0.005089f, 0.969727f, 0.005241f, 0.964355f, 0.005375f, 0.958008f, 0.005486f,
+ 0.951172f, 0.005596f, 0.943848f, 0.005665f, 0.935547f, 0.005718f, 0.925781f, 0.005737f,
+ 0.916016f, 0.005733f, 0.905762f, 0.005707f, 0.894531f, 0.005650f, 0.882324f, 0.005569f,
+ 0.870117f, 0.005466f, 0.856934f, 0.005341f, 0.843262f, 0.005199f, 0.829102f, 0.005043f,
+ 0.814941f, 0.004871f, 0.799805f, 0.004692f, 0.784668f, 0.004505f, 0.769043f, 0.004314f,
+ 0.753418f, 0.004116f, 0.737305f, 0.003922f, 0.721191f, 0.003729f, 0.704590f, 0.003536f,
+ 0.687988f, 0.003347f, 0.670898f, 0.003162f, 0.654297f, 0.002983f, 0.637207f, 0.002810f,
+ 0.620117f, 0.002642f, 0.603027f, 0.002481f, 0.585938f, 0.002329f, 0.568359f, 0.002182f,
+ 0.551270f, 0.002045f, 0.534180f, 0.001913f, 0.517090f, 0.001788f, 0.500488f, 0.001671f,
+ 0.483643f, 0.001560f, 0.467041f, 0.001456f, 0.450684f, 0.001358f, 0.434326f, 0.001266f,
+ 0.418213f, 0.001181f, 0.402588f, 0.001101f, 0.386963f, 0.001025f, 0.371826f, 0.000954f,
+ 0.995605f, 0.004276f, 0.995605f, 0.004276f, 0.995605f, 0.004280f, 0.995605f, 0.004284f,
+ 0.995605f, 0.004299f, 0.995117f, 0.004318f, 0.995117f, 0.004349f, 0.995117f, 0.004383f,
+ 0.994629f, 0.004456f, 0.994629f, 0.004524f, 0.994141f, 0.004612f, 0.993164f, 0.004704f,
+ 0.992676f, 0.004848f, 0.991699f, 0.004974f, 0.990234f, 0.005142f, 0.987793f, 0.005291f,
+ 0.986328f, 0.005474f, 0.982910f, 0.005638f, 0.980469f, 0.005825f, 0.976562f, 0.005989f,
+ 0.972656f, 0.006157f, 0.967773f, 0.006313f, 0.961914f, 0.006443f, 0.955566f, 0.006554f,
+ 0.948730f, 0.006645f, 0.940918f, 0.006702f, 0.932617f, 0.006733f, 0.923340f, 0.006733f,
+ 0.913574f, 0.006699f, 0.902832f, 0.006645f, 0.891602f, 0.006550f, 0.879395f, 0.006435f,
+ 0.867188f, 0.006294f, 0.854004f, 0.006130f, 0.840332f, 0.005951f, 0.826660f, 0.005756f,
+ 0.812500f, 0.005543f, 0.797363f, 0.005325f, 0.782715f, 0.005100f, 0.767090f, 0.004871f,
+ 0.751465f, 0.004642f, 0.735840f, 0.004414f, 0.719727f, 0.004185f, 0.703613f, 0.003960f,
+ 0.687500f, 0.003744f, 0.670898f, 0.003531f, 0.654297f, 0.003326f, 0.637695f, 0.003128f,
+ 0.620605f, 0.002939f, 0.604004f, 0.002756f, 0.586914f, 0.002584f, 0.569824f, 0.002420f,
+ 0.553223f, 0.002264f, 0.536133f, 0.002117f, 0.519531f, 0.001978f, 0.502930f, 0.001847f,
+ 0.486328f, 0.001723f, 0.469727f, 0.001607f, 0.453369f, 0.001498f, 0.437256f, 0.001395f,
+ 0.421387f, 0.001300f, 0.405762f, 0.001211f, 0.390381f, 0.001127f, 0.375244f, 0.001050f,
+ 0.994141f, 0.005367f, 0.994141f, 0.005367f, 0.994141f, 0.005371f, 0.994141f, 0.005375f,
+ 0.994141f, 0.005394f, 0.994141f, 0.005413f, 0.994141f, 0.005447f, 0.994141f, 0.005508f,
+ 0.993652f, 0.005558f, 0.993652f, 0.005650f, 0.992676f, 0.005741f, 0.991699f, 0.005848f,
+ 0.991211f, 0.006004f, 0.990234f, 0.006149f, 0.988281f, 0.006317f, 0.986328f, 0.006504f,
+ 0.984863f, 0.006687f, 0.981934f, 0.006866f, 0.978516f, 0.007050f, 0.974609f, 0.007233f,
+ 0.970215f, 0.007393f, 0.965820f, 0.007553f, 0.959961f, 0.007675f, 0.953125f, 0.007774f,
+ 0.946289f, 0.007843f, 0.938477f, 0.007889f, 0.929688f, 0.007889f, 0.920410f, 0.007858f,
+ 0.910156f, 0.007793f, 0.899414f, 0.007694f, 0.888672f, 0.007565f, 0.876465f, 0.007401f,
+ 0.864258f, 0.007214f, 0.851074f, 0.007008f, 0.837402f, 0.006779f, 0.823730f, 0.006535f,
+ 0.809570f, 0.006279f, 0.794922f, 0.006023f, 0.780273f, 0.005753f, 0.765137f, 0.005482f,
+ 0.750000f, 0.005215f, 0.734375f, 0.004944f, 0.718750f, 0.004681f, 0.703125f, 0.004425f,
+ 0.687012f, 0.004173f, 0.670898f, 0.003929f, 0.654297f, 0.003700f, 0.638184f, 0.003473f,
+ 0.621582f, 0.003260f, 0.604980f, 0.003056f, 0.588379f, 0.002861f, 0.571777f, 0.002676f,
+ 0.555176f, 0.002502f, 0.538574f, 0.002337f, 0.521973f, 0.002180f, 0.505371f, 0.002035f,
+ 0.488770f, 0.001898f, 0.472656f, 0.001769f, 0.456299f, 0.001649f, 0.440430f, 0.001534f,
+ 0.424561f, 0.001430f, 0.408936f, 0.001329f, 0.393555f, 0.001238f, 0.378418f, 0.001151f,
+ 0.993164f, 0.006672f, 0.993164f, 0.006672f, 0.993164f, 0.006676f, 0.993164f, 0.006687f,
+ 0.993164f, 0.006699f, 0.993164f, 0.006721f, 0.992676f, 0.006760f, 0.992676f, 0.006821f,
+ 0.992188f, 0.006897f, 0.991699f, 0.006973f, 0.991211f, 0.007099f, 0.990234f, 0.007206f,
+ 0.990234f, 0.007366f, 0.988281f, 0.007519f, 0.986328f, 0.007706f, 0.984863f, 0.007912f,
+ 0.982422f, 0.008087f, 0.979980f, 0.008286f, 0.977051f, 0.008476f, 0.972656f, 0.008667f,
+ 0.968262f, 0.008827f, 0.962891f, 0.008980f, 0.957520f, 0.009079f, 0.951172f, 0.009171f,
+ 0.943848f, 0.009216f, 0.935547f, 0.009224f, 0.926758f, 0.009193f, 0.917480f, 0.009125f,
+ 0.906738f, 0.009010f, 0.895996f, 0.008865f, 0.885254f, 0.008682f, 0.873047f, 0.008469f,
+ 0.860840f, 0.008232f, 0.847656f, 0.007973f, 0.834473f, 0.007690f, 0.820801f, 0.007397f,
+ 0.807129f, 0.007092f, 0.792969f, 0.006783f, 0.778320f, 0.006462f, 0.763184f, 0.006145f,
+ 0.748535f, 0.005833f, 0.733398f, 0.005524f, 0.717773f, 0.005219f, 0.702148f, 0.004925f,
+ 0.686523f, 0.004639f, 0.670898f, 0.004364f, 0.654785f, 0.004097f, 0.638672f, 0.003847f,
+ 0.622559f, 0.003605f, 0.605957f, 0.003376f, 0.589844f, 0.003157f, 0.573242f, 0.002951f,
+ 0.556641f, 0.002756f, 0.540527f, 0.002573f, 0.523926f, 0.002399f, 0.507812f, 0.002237f,
+ 0.491455f, 0.002085f, 0.475342f, 0.001943f, 0.459229f, 0.001809f, 0.443359f, 0.001684f,
+ 0.427734f, 0.001567f, 0.412109f, 0.001457f, 0.396973f, 0.001356f, 0.382080f, 0.001261f,
+ 0.991699f, 0.008217f, 0.991699f, 0.008217f, 0.991699f, 0.008217f, 0.991699f, 0.008232f,
+ 0.991211f, 0.008240f, 0.991211f, 0.008270f, 0.991211f, 0.008324f, 0.991211f, 0.008377f,
+ 0.990723f, 0.008461f, 0.990234f, 0.008553f, 0.989746f, 0.008682f, 0.988770f, 0.008820f,
+ 0.987793f, 0.008972f, 0.986816f, 0.009163f, 0.985352f, 0.009338f, 0.982910f, 0.009567f,
+ 0.980957f, 0.009758f, 0.977539f, 0.009956f, 0.974609f, 0.010155f, 0.970215f, 0.010330f,
+ 0.965820f, 0.010483f, 0.960449f, 0.010597f, 0.954590f, 0.010696f, 0.947754f, 0.010750f,
+ 0.940430f, 0.010757f, 0.932129f, 0.010735f, 0.923340f, 0.010651f, 0.913574f, 0.010536f,
+ 0.903809f, 0.010376f, 0.892578f, 0.010162f, 0.881348f, 0.009926f, 0.869629f, 0.009651f,
+ 0.857422f, 0.009354f, 0.844727f, 0.009026f, 0.831543f, 0.008690f, 0.817871f, 0.008331f,
+ 0.804199f, 0.007973f, 0.790527f, 0.007603f, 0.775879f, 0.007233f, 0.761719f, 0.006866f,
+ 0.747070f, 0.006500f, 0.731934f, 0.006145f, 0.716797f, 0.005798f, 0.701660f, 0.005466f,
+ 0.686523f, 0.005138f, 0.670898f, 0.004829f, 0.655273f, 0.004532f, 0.639160f, 0.004246f,
+ 0.623535f, 0.003975f, 0.607422f, 0.003719f, 0.591309f, 0.003477f, 0.575195f, 0.003246f,
+ 0.558594f, 0.003029f, 0.542480f, 0.002827f, 0.526367f, 0.002634f, 0.510254f, 0.002455f,
+ 0.494141f, 0.002285f, 0.478271f, 0.002129f, 0.462402f, 0.001980f, 0.446533f, 0.001843f,
+ 0.430908f, 0.001715f, 0.415527f, 0.001594f, 0.400391f, 0.001483f, 0.385498f, 0.001378f,
+ 0.989746f, 0.010040f, 0.989746f, 0.010040f, 0.989746f, 0.010040f, 0.989746f, 0.010048f,
+ 0.989746f, 0.010071f, 0.989746f, 0.010094f, 0.989258f, 0.010147f, 0.989258f, 0.010223f,
+ 0.988770f, 0.010300f, 0.988770f, 0.010406f, 0.987793f, 0.010529f, 0.986816f, 0.010696f,
+ 0.986328f, 0.010857f, 0.984863f, 0.011055f, 0.982422f, 0.011238f, 0.981445f, 0.011467f,
+ 0.978516f, 0.011673f, 0.975098f, 0.011871f, 0.972168f, 0.012062f, 0.967285f, 0.012215f,
+ 0.962402f, 0.012352f, 0.957031f, 0.012459f, 0.951172f, 0.012535f, 0.944336f, 0.012535f,
+ 0.937012f, 0.012520f, 0.928711f, 0.012428f, 0.919922f, 0.012299f, 0.910156f, 0.012115f,
+ 0.899414f, 0.011879f, 0.889160f, 0.011612f, 0.877441f, 0.011299f, 0.865723f, 0.010956f,
+ 0.853516f, 0.010582f, 0.841309f, 0.010193f, 0.828125f, 0.009773f, 0.814941f, 0.009361f,
+ 0.801270f, 0.008926f, 0.787598f, 0.008499f, 0.773926f, 0.008064f, 0.759766f, 0.007641f,
+ 0.745117f, 0.007225f, 0.730469f, 0.006817f, 0.716309f, 0.006424f, 0.701172f, 0.006042f,
+ 0.686035f, 0.005676f, 0.670898f, 0.005329f, 0.655273f, 0.004993f, 0.640137f, 0.004673f,
+ 0.624512f, 0.004372f, 0.608398f, 0.004086f, 0.592773f, 0.003817f, 0.576660f, 0.003561f,
+ 0.561035f, 0.003323f, 0.544922f, 0.003098f, 0.528809f, 0.002884f, 0.512695f, 0.002686f,
+ 0.497070f, 0.002501f, 0.481201f, 0.002327f, 0.465332f, 0.002165f, 0.449707f, 0.002014f,
+ 0.434326f, 0.001873f, 0.418945f, 0.001740f, 0.403809f, 0.001617f, 0.388916f, 0.001504f,
+ 0.987793f, 0.012169f, 0.987793f, 0.012169f, 0.987793f, 0.012169f, 0.987793f, 0.012184f,
+ 0.987305f, 0.012207f, 0.987305f, 0.012245f, 0.987305f, 0.012291f, 0.986816f, 0.012360f,
+ 0.986816f, 0.012459f, 0.986328f, 0.012573f, 0.985840f, 0.012695f, 0.984863f, 0.012878f,
+ 0.983887f, 0.013046f, 0.982422f, 0.013237f, 0.980469f, 0.013466f, 0.979004f, 0.013680f,
+ 0.976074f, 0.013878f, 0.972656f, 0.014069f, 0.969238f, 0.014259f, 0.964355f, 0.014397f,
+ 0.959961f, 0.014488f, 0.954102f, 0.014580f, 0.947754f, 0.014595f, 0.940430f, 0.014557f,
+ 0.933105f, 0.014481f, 0.925293f, 0.014328f, 0.915527f, 0.014122f, 0.906250f, 0.013870f,
+ 0.895996f, 0.013565f, 0.885254f, 0.013206f, 0.873535f, 0.012817f, 0.862305f, 0.012383f,
+ 0.850098f, 0.011932f, 0.837891f, 0.011452f, 0.824707f, 0.010963f, 0.812012f, 0.010460f,
+ 0.798828f, 0.009964f, 0.785156f, 0.009460f, 0.771484f, 0.008965f, 0.757812f, 0.008484f,
+ 0.743652f, 0.008003f, 0.729492f, 0.007542f, 0.715332f, 0.007095f, 0.700684f, 0.006668f,
+ 0.686035f, 0.006256f, 0.670898f, 0.005863f, 0.655762f, 0.005489f, 0.640625f, 0.005135f,
+ 0.625488f, 0.004799f, 0.609863f, 0.004478f, 0.594238f, 0.004181f, 0.578613f, 0.003901f,
+ 0.562988f, 0.003635f, 0.547363f, 0.003386f, 0.531250f, 0.003153f, 0.515625f, 0.002935f,
+ 0.500000f, 0.002729f, 0.484131f, 0.002539f, 0.468506f, 0.002361f, 0.453125f, 0.002195f,
+ 0.437744f, 0.002041f, 0.422363f, 0.001897f, 0.407471f, 0.001763f, 0.392578f, 0.001637f,
+ 0.985352f, 0.014641f, 0.985352f, 0.014641f, 0.984863f, 0.014648f, 0.984863f, 0.014656f,
+ 0.984863f, 0.014679f, 0.984863f, 0.014717f, 0.984863f, 0.014771f, 0.984375f, 0.014839f,
+ 0.984375f, 0.014938f, 0.983398f, 0.015060f, 0.983398f, 0.015244f, 0.981934f, 0.015388f,
+ 0.980957f, 0.015587f, 0.979492f, 0.015778f, 0.977539f, 0.015976f, 0.975586f, 0.016190f,
+ 0.972656f, 0.016388f, 0.969727f, 0.016571f, 0.965820f, 0.016739f, 0.961426f, 0.016861f,
+ 0.956055f, 0.016922f, 0.950684f, 0.016953f, 0.943848f, 0.016922f, 0.937012f, 0.016815f,
+ 0.929199f, 0.016663f, 0.920410f, 0.016434f, 0.911621f, 0.016144f, 0.901855f, 0.015793f,
+ 0.891602f, 0.015411f, 0.880859f, 0.014954f, 0.869629f, 0.014473f, 0.857910f, 0.013947f,
+ 0.846191f, 0.013390f, 0.833984f, 0.012825f, 0.821289f, 0.012253f, 0.809082f, 0.011665f,
+ 0.795898f, 0.011086f, 0.782715f, 0.010506f, 0.769531f, 0.009933f, 0.755859f, 0.009377f,
+ 0.742188f, 0.008842f, 0.728516f, 0.008316f, 0.714355f, 0.007812f, 0.700195f, 0.007336f,
+ 0.685547f, 0.006874f, 0.670898f, 0.006435f, 0.656250f, 0.006020f, 0.641602f, 0.005623f,
+ 0.626465f, 0.005253f, 0.611328f, 0.004902f, 0.596191f, 0.004570f, 0.580566f, 0.004261f,
+ 0.564941f, 0.003967f, 0.549316f, 0.003695f, 0.533691f, 0.003437f, 0.518066f, 0.003199f,
+ 0.502930f, 0.002975f, 0.487305f, 0.002766f, 0.471680f, 0.002571f, 0.456299f, 0.002388f,
+ 0.441162f, 0.002220f, 0.426025f, 0.002062f, 0.411133f, 0.001916f, 0.396240f, 0.001781f,
+ 0.982422f, 0.017502f, 0.982422f, 0.017502f, 0.982422f, 0.017502f, 0.982422f, 0.017517f,
+ 0.981934f, 0.017532f, 0.981934f, 0.017593f, 0.981934f, 0.017639f, 0.981934f, 0.017731f,
+ 0.981445f, 0.017838f, 0.980957f, 0.017960f, 0.979980f, 0.018112f, 0.979004f, 0.018295f,
+ 0.978027f, 0.018478f, 0.975586f, 0.018677f, 0.974609f, 0.018860f, 0.972168f, 0.019073f,
+ 0.969238f, 0.019287f, 0.965820f, 0.019455f, 0.962402f, 0.019562f, 0.958008f, 0.019653f,
+ 0.952637f, 0.019653f, 0.946289f, 0.019623f, 0.939453f, 0.019516f, 0.932617f, 0.019348f,
+ 0.924316f, 0.019089f, 0.916016f, 0.018784f, 0.907227f, 0.018387f, 0.897461f, 0.017944f,
+ 0.887207f, 0.017426f, 0.876465f, 0.016861f, 0.865234f, 0.016266f, 0.854004f, 0.015640f,
+ 0.842285f, 0.014999f, 0.830078f, 0.014320f, 0.818359f, 0.013641f, 0.805664f, 0.012962f,
+ 0.792969f, 0.012291f, 0.780273f, 0.011627f, 0.767090f, 0.010979f, 0.753906f, 0.010345f,
+ 0.740723f, 0.009735f, 0.727539f, 0.009155f, 0.713867f, 0.008591f, 0.699707f, 0.008049f,
+ 0.685547f, 0.007534f, 0.671387f, 0.007050f, 0.656738f, 0.006588f, 0.642578f, 0.006149f,
+ 0.627441f, 0.005737f, 0.612793f, 0.005352f, 0.597656f, 0.004986f, 0.582520f, 0.004642f,
+ 0.567383f, 0.004322f, 0.551758f, 0.004021f, 0.536621f, 0.003744f, 0.520996f, 0.003481f,
+ 0.505859f, 0.003235f, 0.490479f, 0.003006f, 0.475098f, 0.002794f, 0.459717f, 0.002596f,
+ 0.444580f, 0.002411f, 0.429688f, 0.002241f, 0.414795f, 0.002081f, 0.400146f, 0.001933f,
+ 0.979004f, 0.020798f, 0.979004f, 0.020798f, 0.979004f, 0.020798f, 0.979004f, 0.020813f,
+ 0.979004f, 0.020844f, 0.978516f, 0.020874f, 0.978516f, 0.020935f, 0.978027f, 0.021027f,
+ 0.978027f, 0.021149f, 0.977539f, 0.021286f, 0.977051f, 0.021454f, 0.975586f, 0.021622f,
+ 0.974121f, 0.021820f, 0.972656f, 0.021988f, 0.970215f, 0.022186f, 0.968750f, 0.022385f,
+ 0.965820f, 0.022552f, 0.961914f, 0.022675f, 0.958008f, 0.022736f, 0.953613f, 0.022751f,
+ 0.948242f, 0.022736f, 0.942383f, 0.022614f, 0.935547f, 0.022415f, 0.927734f, 0.022156f,
+ 0.919922f, 0.021790f, 0.911621f, 0.021362f, 0.901855f, 0.020859f, 0.892090f, 0.020279f,
+ 0.882324f, 0.019638f, 0.872070f, 0.018951f, 0.860840f, 0.018234f, 0.849609f, 0.017487f,
+ 0.838379f, 0.016708f, 0.826172f, 0.015930f, 0.814453f, 0.015144f, 0.802246f, 0.014359f,
+ 0.790527f, 0.013588f, 0.777832f, 0.012833f, 0.765137f, 0.012100f, 0.752441f, 0.011383f,
+ 0.739258f, 0.010696f, 0.726074f, 0.010040f, 0.712891f, 0.009415f, 0.699219f, 0.008812f,
+ 0.685547f, 0.008240f, 0.671875f, 0.007698f, 0.657715f, 0.007191f, 0.643555f, 0.006710f,
+ 0.628906f, 0.006252f, 0.614258f, 0.005829f, 0.599609f, 0.005428f, 0.584473f, 0.005051f,
+ 0.569336f, 0.004704f, 0.554199f, 0.004372f, 0.539062f, 0.004063f, 0.523926f, 0.003780f,
+ 0.508789f, 0.003513f, 0.493652f, 0.003263f, 0.478271f, 0.003033f, 0.463135f, 0.002817f,
+ 0.448242f, 0.002615f, 0.433350f, 0.002430f, 0.418457f, 0.002256f, 0.403809f, 0.002094f,
+ 0.975098f, 0.024582f, 0.975098f, 0.024567f, 0.975098f, 0.024582f, 0.975098f, 0.024597f,
+ 0.975098f, 0.024628f, 0.975098f, 0.024658f, 0.975098f, 0.024734f, 0.974609f, 0.024826f,
+ 0.973633f, 0.024933f, 0.973633f, 0.025055f, 0.972656f, 0.025223f, 0.972168f, 0.025421f,
+ 0.970215f, 0.025589f, 0.968262f, 0.025742f, 0.966309f, 0.025925f, 0.964355f, 0.026108f,
+ 0.960938f, 0.026230f, 0.957520f, 0.026321f, 0.953613f, 0.026352f, 0.948242f, 0.026260f,
+ 0.943848f, 0.026154f, 0.937500f, 0.025970f, 0.930664f, 0.025650f, 0.922852f, 0.025253f,
+ 0.915039f, 0.024765f, 0.906738f, 0.024200f, 0.897461f, 0.023560f, 0.887207f, 0.022827f,
+ 0.877441f, 0.022064f, 0.866699f, 0.021225f, 0.855957f, 0.020370f, 0.845215f, 0.019470f,
+ 0.833984f, 0.018570f, 0.822266f, 0.017654f, 0.811035f, 0.016754f, 0.799316f, 0.015854f,
+ 0.787109f, 0.014984f, 0.775391f, 0.014122f, 0.763184f, 0.013298f, 0.750488f, 0.012489f,
+ 0.737793f, 0.011726f, 0.725098f, 0.010986f, 0.712402f, 0.010284f, 0.699219f, 0.009621f,
+ 0.685547f, 0.008987f, 0.671875f, 0.008392f, 0.658203f, 0.007828f, 0.644531f, 0.007305f,
+ 0.630371f, 0.006802f, 0.615723f, 0.006336f, 0.601562f, 0.005898f, 0.586914f, 0.005489f,
+ 0.571777f, 0.005104f, 0.557129f, 0.004745f, 0.541992f, 0.004414f, 0.526855f, 0.004101f,
+ 0.511719f, 0.003809f, 0.496826f, 0.003538f, 0.481689f, 0.003286f, 0.466797f, 0.003052f,
+ 0.451904f, 0.002832f, 0.437012f, 0.002630f, 0.422363f, 0.002441f, 0.407715f, 0.002268f,
+ 0.970703f, 0.028870f, 0.970703f, 0.028870f, 0.970703f, 0.028885f, 0.970703f, 0.028900f,
+ 0.970703f, 0.028915f, 0.970703f, 0.028961f, 0.970215f, 0.029022f, 0.970215f, 0.029114f,
+ 0.969727f, 0.029251f, 0.968750f, 0.029373f, 0.968262f, 0.029526f, 0.966797f, 0.029678f,
+ 0.966309f, 0.029877f, 0.964844f, 0.030045f, 0.962402f, 0.030167f, 0.959473f, 0.030304f,
+ 0.956543f, 0.030411f, 0.953125f, 0.030411f, 0.948242f, 0.030319f, 0.943359f, 0.030197f,
+ 0.938477f, 0.029968f, 0.931641f, 0.029648f, 0.924805f, 0.029221f, 0.917969f, 0.028687f,
+ 0.909180f, 0.028030f, 0.900879f, 0.027313f, 0.891602f, 0.026505f, 0.881836f, 0.025620f,
+ 0.871582f, 0.024673f, 0.861816f, 0.023697f, 0.851074f, 0.022659f, 0.840820f, 0.021622f,
+ 0.829590f, 0.020569f, 0.818359f, 0.019516f, 0.807129f, 0.018478f, 0.795898f, 0.017456f,
+ 0.784180f, 0.016464f, 0.772461f, 0.015503f, 0.760742f, 0.014572f, 0.748535f, 0.013672f,
+ 0.736816f, 0.012817f, 0.724121f, 0.012001f, 0.711914f, 0.011215f, 0.698730f, 0.010483f,
+ 0.686035f, 0.009789f, 0.672852f, 0.009132f, 0.659180f, 0.008514f, 0.645508f, 0.007935f,
+ 0.631836f, 0.007389f, 0.617676f, 0.006878f, 0.603516f, 0.006397f, 0.588867f, 0.005951f,
+ 0.574219f, 0.005531f, 0.559570f, 0.005142f, 0.544922f, 0.004776f, 0.529785f, 0.004436f,
+ 0.515137f, 0.004120f, 0.500000f, 0.003828f, 0.485352f, 0.003555f, 0.470215f, 0.003302f,
+ 0.455566f, 0.003065f, 0.440918f, 0.002844f, 0.426270f, 0.002642f, 0.411621f, 0.002451f,
+ 0.965820f, 0.033752f, 0.965820f, 0.033752f, 0.965820f, 0.033752f, 0.965820f, 0.033783f,
+ 0.965820f, 0.033783f, 0.965820f, 0.033875f, 0.965332f, 0.033905f, 0.965332f, 0.033997f,
+ 0.964844f, 0.034088f, 0.963867f, 0.034241f, 0.963379f, 0.034393f, 0.962402f, 0.034546f,
+ 0.960938f, 0.034698f, 0.958496f, 0.034851f, 0.957520f, 0.034973f, 0.954102f, 0.035034f,
+ 0.951172f, 0.035034f, 0.947754f, 0.034943f, 0.942871f, 0.034821f, 0.937988f, 0.034576f,
+ 0.932129f, 0.034180f, 0.926270f, 0.033722f, 0.918945f, 0.033142f, 0.911133f, 0.032410f,
+ 0.902832f, 0.031616f, 0.894531f, 0.030685f, 0.885254f, 0.029694f, 0.876465f, 0.028641f,
+ 0.866699f, 0.027512f, 0.856445f, 0.026337f, 0.846191f, 0.025146f, 0.835449f, 0.023926f,
+ 0.825195f, 0.022720f, 0.814453f, 0.021515f, 0.803711f, 0.020340f, 0.792480f, 0.019165f,
+ 0.781250f, 0.018051f, 0.770020f, 0.016968f, 0.758789f, 0.015915f, 0.747070f, 0.014931f,
+ 0.735352f, 0.013977f, 0.723145f, 0.013069f, 0.710938f, 0.012215f, 0.698730f, 0.011398f,
+ 0.686035f, 0.010635f, 0.673340f, 0.009918f, 0.660156f, 0.009239f, 0.646484f, 0.008598f,
+ 0.633301f, 0.008003f, 0.619141f, 0.007446f, 0.605469f, 0.006927f, 0.591309f, 0.006439f,
+ 0.576660f, 0.005985f, 0.562500f, 0.005562f, 0.547852f, 0.005165f, 0.533203f, 0.004795f,
+ 0.518066f, 0.004456f, 0.503418f, 0.004135f, 0.488770f, 0.003841f, 0.474121f, 0.003565f,
+ 0.459229f, 0.003311f, 0.444580f, 0.003073f, 0.430176f, 0.002853f, 0.415771f, 0.002647f,
+ 0.960449f, 0.039276f, 0.960449f, 0.039276f, 0.960449f, 0.039276f, 0.960449f, 0.039307f,
+ 0.960449f, 0.039337f, 0.959961f, 0.039368f, 0.959961f, 0.039429f, 0.959961f, 0.039520f,
+ 0.959473f, 0.039612f, 0.958984f, 0.039764f, 0.958008f, 0.039886f, 0.956543f, 0.040009f,
+ 0.955566f, 0.040131f, 0.953125f, 0.040253f, 0.951172f, 0.040314f, 0.948242f, 0.040283f,
+ 0.945801f, 0.040222f, 0.940918f, 0.040039f, 0.936523f, 0.039764f, 0.931152f, 0.039368f,
+ 0.926270f, 0.038879f, 0.919434f, 0.038208f, 0.913086f, 0.037445f, 0.905273f, 0.036530f,
+ 0.897461f, 0.035522f, 0.888184f, 0.034393f, 0.879395f, 0.033173f, 0.870117f, 0.031891f,
+ 0.860352f, 0.030563f, 0.850586f, 0.029190f, 0.840820f, 0.027802f, 0.830566f, 0.026398f,
+ 0.820312f, 0.025009f, 0.810059f, 0.023636f, 0.799805f, 0.022308f, 0.789062f, 0.020996f,
+ 0.778809f, 0.019730f, 0.767578f, 0.018524f, 0.756348f, 0.017365f, 0.745605f, 0.016251f,
+ 0.733887f, 0.015213f, 0.722656f, 0.014206f, 0.710938f, 0.013260f, 0.698730f, 0.012367f,
+ 0.686523f, 0.011536f, 0.673828f, 0.010742f, 0.661133f, 0.010002f, 0.647949f, 0.009308f,
+ 0.634766f, 0.008659f, 0.621094f, 0.008057f, 0.607422f, 0.007488f, 0.593262f, 0.006958f,
+ 0.579102f, 0.006466f, 0.564941f, 0.006004f, 0.550781f, 0.005577f, 0.536133f, 0.005177f,
+ 0.521484f, 0.004807f, 0.506836f, 0.004463f, 0.492432f, 0.004143f, 0.477783f, 0.003847f,
+ 0.463135f, 0.003571f, 0.448730f, 0.003315f, 0.434082f, 0.003077f, 0.419922f, 0.002857f,
+ 0.954102f, 0.045502f, 0.954102f, 0.045502f, 0.954102f, 0.045502f, 0.954102f, 0.045532f,
+ 0.954102f, 0.045563f, 0.954102f, 0.045593f, 0.953613f, 0.045654f, 0.953613f, 0.045715f,
+ 0.953125f, 0.045868f, 0.952148f, 0.045990f, 0.951660f, 0.046082f, 0.950195f, 0.046143f,
+ 0.948242f, 0.046265f, 0.946777f, 0.046265f, 0.943848f, 0.046265f, 0.941895f, 0.046204f,
+ 0.938477f, 0.046021f, 0.935059f, 0.045685f, 0.929199f, 0.045258f, 0.925293f, 0.044708f,
+ 0.919434f, 0.044006f, 0.912109f, 0.043121f, 0.905273f, 0.042145f, 0.897949f, 0.041016f,
+ 0.890137f, 0.039734f, 0.881348f, 0.038391f, 0.872559f, 0.036926f, 0.863770f, 0.035431f,
+ 0.854004f, 0.033813f, 0.844727f, 0.032227f, 0.835449f, 0.030640f, 0.825195f, 0.029037f,
+ 0.815430f, 0.027451f, 0.806152f, 0.025909f, 0.795898f, 0.024399f, 0.785645f, 0.022934f,
+ 0.775391f, 0.021530f, 0.765137f, 0.020187f, 0.754883f, 0.018890f, 0.743652f, 0.017670f,
+ 0.732910f, 0.016510f, 0.721680f, 0.015411f, 0.710449f, 0.014374f, 0.698730f, 0.013405f,
+ 0.686523f, 0.012482f, 0.674316f, 0.011620f, 0.662109f, 0.010811f, 0.649414f, 0.010063f,
+ 0.636230f, 0.009354f, 0.623047f, 0.008698f, 0.609375f, 0.008080f, 0.595703f, 0.007507f,
+ 0.582031f, 0.006973f, 0.567871f, 0.006477f, 0.553711f, 0.006016f, 0.539551f, 0.005585f,
+ 0.524902f, 0.005180f, 0.510254f, 0.004810f, 0.496094f, 0.004463f, 0.481689f, 0.004147f,
+ 0.467041f, 0.003847f, 0.452637f, 0.003571f, 0.438232f, 0.003315f, 0.424072f, 0.003077f,
+ 0.947266f, 0.052490f, 0.947266f, 0.052490f, 0.947266f, 0.052490f, 0.947266f, 0.052521f,
+ 0.947266f, 0.052551f, 0.946777f, 0.052582f, 0.946777f, 0.052612f, 0.946289f, 0.052734f,
+ 0.945801f, 0.052795f, 0.945312f, 0.052887f, 0.944336f, 0.052948f, 0.942871f, 0.053040f,
+ 0.941406f, 0.053009f, 0.939941f, 0.053009f, 0.937012f, 0.052917f, 0.934570f, 0.052704f,
+ 0.931641f, 0.052399f, 0.926758f, 0.051971f, 0.922852f, 0.051331f, 0.917480f, 0.050568f,
+ 0.911133f, 0.049622f, 0.904297f, 0.048523f, 0.898438f, 0.047272f, 0.890137f, 0.045868f,
+ 0.882812f, 0.044312f, 0.874512f, 0.042694f, 0.865723f, 0.040955f, 0.856934f, 0.039154f,
+ 0.847656f, 0.037354f, 0.838867f, 0.035522f, 0.829590f, 0.033661f, 0.820312f, 0.031830f,
+ 0.811035f, 0.030060f, 0.801270f, 0.028305f, 0.791992f, 0.026611f, 0.782227f, 0.024994f,
+ 0.772461f, 0.023422f, 0.762695f, 0.021927f, 0.752441f, 0.020508f, 0.742188f, 0.019165f,
+ 0.731445f, 0.017883f, 0.721191f, 0.016678f, 0.709961f, 0.015556f, 0.698730f, 0.014488f,
+ 0.687012f, 0.013489f, 0.675293f, 0.012550f, 0.663086f, 0.011673f, 0.650879f, 0.010849f,
+ 0.638184f, 0.010086f, 0.625000f, 0.009369f, 0.611816f, 0.008705f, 0.598145f, 0.008087f,
+ 0.584961f, 0.007511f, 0.570801f, 0.006977f, 0.556641f, 0.006474f, 0.542480f, 0.006012f,
+ 0.528320f, 0.005581f, 0.514160f, 0.005180f, 0.499756f, 0.004807f, 0.485596f, 0.004459f,
+ 0.471191f, 0.004139f, 0.456787f, 0.003843f, 0.442383f, 0.003569f, 0.428467f, 0.003313f,
+ 0.939453f, 0.060333f, 0.939453f, 0.060333f, 0.939453f, 0.060333f, 0.939453f, 0.060333f,
+ 0.939453f, 0.060394f, 0.938965f, 0.060394f, 0.938965f, 0.060455f, 0.938477f, 0.060516f,
+ 0.937988f, 0.060577f, 0.937500f, 0.060638f, 0.936035f, 0.060669f, 0.935547f, 0.060669f,
+ 0.933594f, 0.060608f, 0.931641f, 0.060516f, 0.929688f, 0.060272f, 0.927246f, 0.059967f,
+ 0.922363f, 0.059448f, 0.918945f, 0.058868f, 0.914062f, 0.057953f, 0.908691f, 0.056946f,
+ 0.902832f, 0.055786f, 0.897461f, 0.054382f, 0.890137f, 0.052826f, 0.882324f, 0.051117f,
+ 0.874023f, 0.049255f, 0.866211f, 0.047302f, 0.858398f, 0.045288f, 0.849609f, 0.043213f,
+ 0.840820f, 0.041107f, 0.832031f, 0.038971f, 0.823730f, 0.036896f, 0.814453f, 0.034821f,
+ 0.806152f, 0.032806f, 0.796875f, 0.030853f, 0.788086f, 0.028961f, 0.778809f, 0.027161f,
+ 0.769531f, 0.025421f, 0.760254f, 0.023788f, 0.750488f, 0.022217f, 0.740723f, 0.020737f,
+ 0.730957f, 0.019333f, 0.720703f, 0.018021f, 0.709961f, 0.016785f, 0.698730f, 0.015625f,
+ 0.687500f, 0.014549f, 0.676270f, 0.013535f, 0.664551f, 0.012573f, 0.652344f, 0.011688f,
+ 0.640137f, 0.010864f, 0.627441f, 0.010086f, 0.614258f, 0.009369f, 0.601074f, 0.008698f,
+ 0.587402f, 0.008080f, 0.573730f, 0.007500f, 0.560059f, 0.006962f, 0.545898f, 0.006462f,
+ 0.531738f, 0.006001f, 0.517578f, 0.005569f, 0.503418f, 0.005165f, 0.489502f, 0.004795f,
+ 0.475098f, 0.004452f, 0.460938f, 0.004131f, 0.446777f, 0.003838f, 0.432861f, 0.003563f,
+ 0.930664f, 0.069031f, 0.930664f, 0.069031f, 0.930664f, 0.069031f, 0.930664f, 0.069031f,
+ 0.930664f, 0.069092f, 0.930664f, 0.069092f, 0.930176f, 0.069214f, 0.929688f, 0.069153f,
+ 0.929199f, 0.069214f, 0.929199f, 0.069275f, 0.927246f, 0.069214f, 0.926758f, 0.069153f,
+ 0.925293f, 0.069031f, 0.923340f, 0.068787f, 0.920410f, 0.068420f, 0.917480f, 0.067932f,
+ 0.914551f, 0.067261f, 0.911133f, 0.066345f, 0.905273f, 0.065247f, 0.900391f, 0.063965f,
+ 0.894043f, 0.062469f, 0.888184f, 0.060699f, 0.880859f, 0.058807f, 0.873535f, 0.056763f,
+ 0.866211f, 0.054565f, 0.858887f, 0.052277f, 0.850586f, 0.049896f, 0.841797f, 0.047485f,
+ 0.833496f, 0.045105f, 0.825684f, 0.042664f, 0.817383f, 0.040283f, 0.809082f, 0.037964f,
+ 0.800781f, 0.035706f, 0.792480f, 0.033539f, 0.784180f, 0.031433f, 0.775391f, 0.029449f,
+ 0.766602f, 0.027542f, 0.757812f, 0.025726f, 0.748535f, 0.024017f, 0.739258f, 0.022400f,
+ 0.729980f, 0.020874f, 0.719727f, 0.019440f, 0.709961f, 0.018097f, 0.699219f, 0.016830f,
+ 0.688477f, 0.015656f, 0.677246f, 0.014557f, 0.665527f, 0.013527f, 0.653809f, 0.012573f,
+ 0.641602f, 0.011681f, 0.629395f, 0.010841f, 0.616699f, 0.010071f, 0.603516f, 0.009346f,
+ 0.590332f, 0.008682f, 0.577148f, 0.008057f, 0.563477f, 0.007481f, 0.549316f, 0.006943f,
+ 0.535645f, 0.006443f, 0.521484f, 0.005978f, 0.507324f, 0.005550f, 0.493408f, 0.005150f,
+ 0.479248f, 0.004780f, 0.465332f, 0.004436f, 0.451172f, 0.004124f, 0.437256f, 0.003828f,
+ 0.920898f, 0.078735f, 0.920898f, 0.078735f, 0.920898f, 0.078735f, 0.920898f, 0.078735f,
+ 0.920898f, 0.078796f, 0.920898f, 0.078796f, 0.920410f, 0.078796f, 0.919922f, 0.078857f,
+ 0.919922f, 0.078857f, 0.918945f, 0.078796f, 0.917480f, 0.078735f, 0.916992f, 0.078613f,
+ 0.915039f, 0.078308f, 0.913086f, 0.077942f, 0.910645f, 0.077454f, 0.908691f, 0.076660f,
+ 0.905273f, 0.075745f, 0.899902f, 0.074585f, 0.895996f, 0.073181f, 0.889648f, 0.071533f,
+ 0.883789f, 0.069641f, 0.877930f, 0.067566f, 0.872070f, 0.065247f, 0.864258f, 0.062805f,
+ 0.856934f, 0.060242f, 0.849121f, 0.057556f, 0.841797f, 0.054810f, 0.833984f, 0.052063f,
+ 0.827148f, 0.049316f, 0.818848f, 0.046570f, 0.811035f, 0.043915f, 0.803223f, 0.041290f,
+ 0.795898f, 0.038788f, 0.788086f, 0.036377f, 0.779785f, 0.034058f, 0.771973f, 0.031830f,
+ 0.763672f, 0.029755f, 0.755371f, 0.027771f, 0.747070f, 0.025894f, 0.738281f, 0.024139f,
+ 0.729004f, 0.022476f, 0.719238f, 0.020935f, 0.709473f, 0.019470f, 0.699707f, 0.018097f,
+ 0.688965f, 0.016830f, 0.678223f, 0.015640f, 0.666992f, 0.014534f, 0.655762f, 0.013496f,
+ 0.643555f, 0.012535f, 0.631348f, 0.011642f, 0.619141f, 0.010803f, 0.606445f, 0.010033f,
+ 0.593262f, 0.009308f, 0.580078f, 0.008644f, 0.566406f, 0.008018f, 0.553223f, 0.007446f,
+ 0.539062f, 0.006908f, 0.525391f, 0.006413f, 0.511230f, 0.005951f, 0.497559f, 0.005527f,
+ 0.483643f, 0.005131f, 0.469482f, 0.004765f, 0.455566f, 0.004421f, 0.441650f, 0.004108f,
+ 0.910156f, 0.089539f, 0.910156f, 0.089539f, 0.910156f, 0.089539f, 0.910156f, 0.089539f,
+ 0.910156f, 0.089539f, 0.909668f, 0.089539f, 0.909668f, 0.089539f, 0.909180f, 0.089539f,
+ 0.908691f, 0.089478f, 0.907715f, 0.089417f, 0.907227f, 0.089233f, 0.905762f, 0.088989f,
+ 0.904297f, 0.088562f, 0.902832f, 0.088013f, 0.900391f, 0.087280f, 0.896973f, 0.086243f,
+ 0.895020f, 0.085083f, 0.889160f, 0.083557f, 0.884766f, 0.081787f, 0.878906f, 0.079712f,
+ 0.874512f, 0.077393f, 0.867676f, 0.074951f, 0.860840f, 0.072205f, 0.854492f, 0.069275f,
+ 0.848145f, 0.066223f, 0.840820f, 0.063171f, 0.833008f, 0.060059f, 0.826172f, 0.056885f,
+ 0.819336f, 0.053741f, 0.812012f, 0.050690f, 0.804688f, 0.047699f, 0.797852f, 0.044800f,
+ 0.790527f, 0.042023f, 0.783691f, 0.039337f, 0.776367f, 0.036804f, 0.768555f, 0.034393f,
+ 0.761230f, 0.032074f, 0.753418f, 0.029922f, 0.745117f, 0.027893f, 0.736816f, 0.025970f,
+ 0.728516f, 0.024170f, 0.719238f, 0.022491f, 0.709961f, 0.020905f, 0.700195f, 0.019440f,
+ 0.689941f, 0.018066f, 0.679688f, 0.016785f, 0.668457f, 0.015587f, 0.657227f, 0.014473f,
+ 0.645996f, 0.013443f, 0.633789f, 0.012474f, 0.621582f, 0.011581f, 0.609375f, 0.010750f,
+ 0.596191f, 0.009972f, 0.583496f, 0.009262f, 0.569824f, 0.008591f, 0.556641f, 0.007973f,
+ 0.542969f, 0.007404f, 0.529297f, 0.006874f, 0.515625f, 0.006378f, 0.501465f, 0.005920f,
+ 0.487793f, 0.005501f, 0.474121f, 0.005108f, 0.460205f, 0.004742f, 0.446289f, 0.004406f,
+ 0.898438f, 0.101440f, 0.898438f, 0.101440f, 0.898438f, 0.101440f, 0.898438f, 0.101440f,
+ 0.897949f, 0.101440f, 0.897949f, 0.101440f, 0.897461f, 0.101440f, 0.896973f, 0.101379f,
+ 0.896973f, 0.101318f, 0.895996f, 0.101135f, 0.895508f, 0.100830f, 0.894043f, 0.100464f,
+ 0.893066f, 0.099854f, 0.890625f, 0.099121f, 0.888184f, 0.098083f, 0.885254f, 0.096802f,
+ 0.882324f, 0.095215f, 0.878418f, 0.093323f, 0.872559f, 0.091125f, 0.869629f, 0.088623f,
+ 0.862793f, 0.085815f, 0.855957f, 0.082764f, 0.850098f, 0.079590f, 0.844727f, 0.076172f,
+ 0.837402f, 0.072693f, 0.831055f, 0.069092f, 0.824219f, 0.065491f, 0.817871f, 0.061981f,
+ 0.811035f, 0.058472f, 0.804688f, 0.055023f, 0.797852f, 0.051697f, 0.791992f, 0.048492f,
+ 0.785645f, 0.045410f, 0.778809f, 0.042480f, 0.771973f, 0.039673f, 0.765625f, 0.037018f,
+ 0.758789f, 0.034515f, 0.750977f, 0.032166f, 0.743652f, 0.029968f, 0.735840f, 0.027878f,
+ 0.727539f, 0.025940f, 0.718750f, 0.024124f, 0.709961f, 0.022430f, 0.700684f, 0.020844f,
+ 0.690918f, 0.019363f, 0.680664f, 0.017975f, 0.670410f, 0.016693f, 0.659180f, 0.015495f,
+ 0.647949f, 0.014389f, 0.636230f, 0.013359f, 0.624512f, 0.012398f, 0.611816f, 0.011505f,
+ 0.599609f, 0.010681f, 0.586426f, 0.009911f, 0.573730f, 0.009201f, 0.560547f, 0.008537f,
+ 0.546875f, 0.007927f, 0.533203f, 0.007355f, 0.519531f, 0.006828f, 0.505859f, 0.006340f,
+ 0.492432f, 0.005890f, 0.478516f, 0.005470f, 0.464844f, 0.005077f, 0.450928f, 0.004719f,
+ 0.885254f, 0.114624f, 0.885254f, 0.114624f, 0.885254f, 0.114624f, 0.885254f, 0.114624f,
+ 0.884766f, 0.114624f, 0.884766f, 0.114563f, 0.884766f, 0.114502f, 0.884277f, 0.114380f,
+ 0.883789f, 0.114258f, 0.883301f, 0.114014f, 0.882324f, 0.113525f, 0.881348f, 0.112976f,
+ 0.879395f, 0.112183f, 0.877441f, 0.111145f, 0.875977f, 0.109802f, 0.872559f, 0.108215f,
+ 0.869141f, 0.106201f, 0.865723f, 0.103821f, 0.860352f, 0.101196f, 0.854492f, 0.098145f,
+ 0.850586f, 0.094849f, 0.845215f, 0.091187f, 0.838379f, 0.087463f, 0.833496f, 0.083496f,
+ 0.826660f, 0.079468f, 0.820801f, 0.075378f, 0.814453f, 0.071289f, 0.809082f, 0.067322f,
+ 0.803711f, 0.063354f, 0.797363f, 0.059540f, 0.791992f, 0.055878f, 0.786133f, 0.052338f,
+ 0.780762f, 0.048950f, 0.774414f, 0.045746f, 0.768555f, 0.042664f, 0.762207f, 0.039795f,
+ 0.755859f, 0.037079f, 0.749023f, 0.034546f, 0.741699f, 0.032135f, 0.734863f, 0.029892f,
+ 0.727051f, 0.027802f, 0.718750f, 0.025833f, 0.710449f, 0.024002f, 0.701172f, 0.022293f,
+ 0.691895f, 0.020706f, 0.682129f, 0.019226f, 0.671875f, 0.017853f, 0.661133f, 0.016571f,
+ 0.650391f, 0.015381f, 0.639160f, 0.014282f, 0.626953f, 0.013252f, 0.615234f, 0.012299f,
+ 0.602539f, 0.011414f, 0.590332f, 0.010597f, 0.577148f, 0.009834f, 0.563965f, 0.009132f,
+ 0.550781f, 0.008476f, 0.537598f, 0.007866f, 0.523926f, 0.007309f, 0.510254f, 0.006786f,
+ 0.496826f, 0.006306f, 0.483154f, 0.005856f, 0.469482f, 0.005440f, 0.455811f, 0.005054f,
+ 0.870605f, 0.129028f, 0.870605f, 0.129028f, 0.870605f, 0.129028f, 0.870605f, 0.129028f,
+ 0.870605f, 0.129028f, 0.870605f, 0.129028f, 0.870117f, 0.128906f, 0.870117f, 0.128784f,
+ 0.869629f, 0.128540f, 0.869141f, 0.128052f, 0.868164f, 0.127563f, 0.867188f, 0.126709f,
+ 0.865723f, 0.125732f, 0.863281f, 0.124329f, 0.862305f, 0.122742f, 0.858887f, 0.120544f,
+ 0.854980f, 0.118103f, 0.850098f, 0.115173f, 0.847168f, 0.111938f, 0.843750f, 0.108276f,
+ 0.836426f, 0.104309f, 0.832031f, 0.100159f, 0.827148f, 0.095764f, 0.821289f, 0.091187f,
+ 0.815918f, 0.086609f, 0.810547f, 0.081970f, 0.806152f, 0.077393f, 0.800781f, 0.072937f,
+ 0.795410f, 0.068542f, 0.790039f, 0.064270f, 0.785645f, 0.060242f, 0.780762f, 0.056335f,
+ 0.775391f, 0.052643f, 0.770020f, 0.049133f, 0.765137f, 0.045807f, 0.759766f, 0.042694f,
+ 0.753906f, 0.039734f, 0.747559f, 0.036987f, 0.740723f, 0.034393f, 0.733887f, 0.031982f,
+ 0.726562f, 0.029739f, 0.719238f, 0.027618f, 0.710449f, 0.025650f, 0.702148f, 0.023834f,
+ 0.692871f, 0.022125f, 0.683594f, 0.020538f, 0.673828f, 0.019058f, 0.663574f, 0.017685f,
+ 0.652832f, 0.016418f, 0.641602f, 0.015244f, 0.629883f, 0.014153f, 0.618164f, 0.013138f,
+ 0.605957f, 0.012192f, 0.593750f, 0.011314f, 0.581055f, 0.010506f, 0.567871f, 0.009750f,
+ 0.555176f, 0.009056f, 0.541504f, 0.008408f, 0.528320f, 0.007809f, 0.514648f, 0.007252f,
+ 0.501465f, 0.006741f, 0.487793f, 0.006260f, 0.474365f, 0.005817f, 0.460938f, 0.005409f,
+ 0.854492f, 0.145020f, 0.854492f, 0.145020f, 0.854492f, 0.145020f, 0.854492f, 0.145020f,
+ 0.854492f, 0.144897f, 0.854492f, 0.144897f, 0.854004f, 0.144653f, 0.854492f, 0.144531f,
+ 0.854004f, 0.144165f, 0.853027f, 0.143555f, 0.852051f, 0.142822f, 0.851074f, 0.141724f,
+ 0.850586f, 0.140503f, 0.848145f, 0.138672f, 0.846191f, 0.136475f, 0.843262f, 0.133911f,
+ 0.839844f, 0.130859f, 0.835449f, 0.127319f, 0.832031f, 0.123474f, 0.828613f, 0.119141f,
+ 0.823242f, 0.114502f, 0.819824f, 0.109558f, 0.813477f, 0.104431f, 0.809570f, 0.099304f,
+ 0.804199f, 0.094055f, 0.799316f, 0.088867f, 0.794922f, 0.083740f, 0.791992f, 0.078735f,
+ 0.786621f, 0.073914f, 0.783203f, 0.069214f, 0.779297f, 0.064758f, 0.774902f, 0.060516f,
+ 0.770508f, 0.056488f, 0.765625f, 0.052673f, 0.761230f, 0.049072f, 0.756348f, 0.045715f,
+ 0.750977f, 0.042511f, 0.745605f, 0.039551f, 0.739746f, 0.036774f, 0.733398f, 0.034180f,
+ 0.726562f, 0.031738f, 0.719238f, 0.029495f, 0.711426f, 0.027390f, 0.703125f, 0.025421f,
+ 0.694336f, 0.023605f, 0.685059f, 0.021912f, 0.675781f, 0.020340f, 0.665527f, 0.018875f,
+ 0.655273f, 0.017517f, 0.644043f, 0.016251f, 0.632812f, 0.015091f, 0.621582f, 0.014008f,
+ 0.609375f, 0.013000f, 0.597168f, 0.012070f, 0.584473f, 0.011200f, 0.571777f, 0.010406f,
+ 0.559082f, 0.009659f, 0.545898f, 0.008972f, 0.532715f, 0.008339f, 0.519531f, 0.007748f,
+ 0.505859f, 0.007198f, 0.492676f, 0.006691f, 0.479248f, 0.006218f, 0.465820f, 0.005783f,
+ 0.837402f, 0.162476f, 0.837402f, 0.162476f, 0.837402f, 0.162476f, 0.837402f, 0.162354f,
+ 0.837402f, 0.162354f, 0.836914f, 0.162231f, 0.836914f, 0.161987f, 0.836426f, 0.161743f,
+ 0.836426f, 0.161133f, 0.835449f, 0.160522f, 0.835449f, 0.159546f, 0.834473f, 0.158203f,
+ 0.833496f, 0.156372f, 0.831055f, 0.154175f, 0.830078f, 0.151489f, 0.826660f, 0.148315f,
+ 0.823242f, 0.144531f, 0.821289f, 0.140381f, 0.817383f, 0.135620f, 0.812012f, 0.130615f,
+ 0.810547f, 0.125122f, 0.805176f, 0.119507f, 0.800293f, 0.113647f, 0.797852f, 0.107788f,
+ 0.792480f, 0.101868f, 0.788574f, 0.096008f, 0.785156f, 0.090332f, 0.782715f, 0.084839f,
+ 0.779297f, 0.079468f, 0.774902f, 0.074341f, 0.772461f, 0.069458f, 0.769531f, 0.064819f,
+ 0.765137f, 0.060486f, 0.761719f, 0.056366f, 0.758301f, 0.052490f, 0.753418f, 0.048828f,
+ 0.749023f, 0.045410f, 0.743652f, 0.042206f, 0.738770f, 0.039215f, 0.732422f, 0.036438f,
+ 0.726074f, 0.033844f, 0.719238f, 0.031433f, 0.711914f, 0.029190f, 0.704102f, 0.027100f,
+ 0.695801f, 0.025146f, 0.687012f, 0.023346f, 0.677734f, 0.021667f, 0.667969f, 0.020111f,
+ 0.657715f, 0.018646f, 0.646973f, 0.017319f, 0.636230f, 0.016068f, 0.624512f, 0.014923f,
+ 0.612793f, 0.013855f, 0.601074f, 0.012863f, 0.588379f, 0.011948f, 0.576172f, 0.011093f,
+ 0.563477f, 0.010300f, 0.550293f, 0.009567f, 0.537109f, 0.008896f, 0.523926f, 0.008263f,
+ 0.510742f, 0.007687f, 0.497559f, 0.007145f, 0.484375f, 0.006645f, 0.470947f, 0.006180f,
+ 0.818359f, 0.181519f, 0.818359f, 0.181519f, 0.818359f, 0.181519f, 0.817871f, 0.181519f,
+ 0.817871f, 0.181396f, 0.817871f, 0.181274f, 0.817871f, 0.181030f, 0.817871f, 0.180542f,
+ 0.817871f, 0.179932f, 0.817383f, 0.178955f, 0.816406f, 0.177612f, 0.815918f, 0.175903f,
+ 0.814941f, 0.173584f, 0.812500f, 0.170898f, 0.811035f, 0.167603f, 0.808594f, 0.163696f,
+ 0.805664f, 0.159180f, 0.802246f, 0.154175f, 0.799805f, 0.148560f, 0.796875f, 0.142700f,
+ 0.792480f, 0.136353f, 0.789551f, 0.129883f, 0.787598f, 0.123230f, 0.782227f, 0.116577f,
+ 0.780273f, 0.109985f, 0.777344f, 0.103516f, 0.774414f, 0.097168f, 0.771973f, 0.091125f,
+ 0.770508f, 0.085205f, 0.767578f, 0.079651f, 0.765625f, 0.074341f, 0.763184f, 0.069336f,
+ 0.760254f, 0.064636f, 0.757812f, 0.060181f, 0.754395f, 0.056000f, 0.750977f, 0.052063f,
+ 0.747559f, 0.048431f, 0.742188f, 0.044983f, 0.737793f, 0.041779f, 0.732422f, 0.038818f,
+ 0.726074f, 0.036041f, 0.719727f, 0.033447f, 0.712891f, 0.031052f, 0.705566f, 0.028824f,
+ 0.697266f, 0.026749f, 0.688965f, 0.024826f, 0.679688f, 0.023041f, 0.670410f, 0.021393f,
+ 0.660645f, 0.019852f, 0.649902f, 0.018433f, 0.639160f, 0.017105f, 0.627930f, 0.015869f,
+ 0.616211f, 0.014748f, 0.604492f, 0.013687f, 0.592773f, 0.012718f, 0.580078f, 0.011818f,
+ 0.567871f, 0.010979f, 0.554688f, 0.010201f, 0.541992f, 0.009483f, 0.528809f, 0.008812f,
+ 0.515625f, 0.008194f, 0.502441f, 0.007626f, 0.489502f, 0.007088f, 0.476318f, 0.006599f,
+ 0.797363f, 0.202393f, 0.797363f, 0.202393f, 0.797363f, 0.202393f, 0.797363f, 0.202393f,
+ 0.797363f, 0.202148f, 0.797363f, 0.202026f, 0.797363f, 0.201660f, 0.797363f, 0.201050f,
+ 0.796875f, 0.200195f, 0.796875f, 0.198975f, 0.796387f, 0.197266f, 0.795898f, 0.195068f,
+ 0.794922f, 0.192261f, 0.792969f, 0.188843f, 0.792480f, 0.184937f, 0.789551f, 0.180298f,
+ 0.787598f, 0.174927f, 0.785645f, 0.168823f, 0.782715f, 0.162231f, 0.779297f, 0.155273f,
+ 0.775879f, 0.148071f, 0.775391f, 0.140747f, 0.772461f, 0.133179f, 0.770508f, 0.125732f,
+ 0.767578f, 0.118347f, 0.766113f, 0.111206f, 0.764648f, 0.104248f, 0.763184f, 0.097595f,
+ 0.762695f, 0.091187f, 0.761719f, 0.085144f, 0.759277f, 0.079407f, 0.758301f, 0.073975f,
+ 0.755859f, 0.068909f, 0.754395f, 0.064087f, 0.751465f, 0.059631f, 0.748535f, 0.055450f,
+ 0.745117f, 0.051514f, 0.741211f, 0.047852f, 0.737305f, 0.044434f, 0.731934f, 0.041260f,
+ 0.726562f, 0.038300f, 0.720215f, 0.035553f, 0.713867f, 0.032990f, 0.706543f, 0.030624f,
+ 0.699219f, 0.028427f, 0.690918f, 0.026382f, 0.682129f, 0.024475f, 0.672852f, 0.022720f,
+ 0.663086f, 0.021088f, 0.652832f, 0.019577f, 0.642578f, 0.018173f, 0.631348f, 0.016876f,
+ 0.620117f, 0.015671f, 0.608398f, 0.014565f, 0.596680f, 0.013535f, 0.584473f, 0.012573f,
+ 0.572266f, 0.011681f, 0.559570f, 0.010857f, 0.546875f, 0.010101f, 0.533691f, 0.009392f,
+ 0.520996f, 0.008736f, 0.507812f, 0.008125f, 0.494629f, 0.007565f, 0.481689f, 0.007042f,
+ 0.774414f, 0.225098f, 0.774414f, 0.225098f, 0.774414f, 0.225098f, 0.774414f, 0.225098f,
+ 0.774414f, 0.224854f, 0.774902f, 0.224609f, 0.774414f, 0.224121f, 0.774414f, 0.223389f,
+ 0.774414f, 0.222290f, 0.773926f, 0.220581f, 0.773926f, 0.218628f, 0.773926f, 0.215942f,
+ 0.773438f, 0.212524f, 0.772461f, 0.208374f, 0.771484f, 0.203491f, 0.770508f, 0.197754f,
+ 0.769043f, 0.191284f, 0.766113f, 0.184204f, 0.763672f, 0.176514f, 0.760742f, 0.168457f,
+ 0.760742f, 0.160278f, 0.757812f, 0.151855f, 0.757812f, 0.143433f, 0.756836f, 0.135132f,
+ 0.754395f, 0.126953f, 0.755371f, 0.119141f, 0.755371f, 0.111511f, 0.754395f, 0.104309f,
+ 0.753418f, 0.097351f, 0.754395f, 0.090820f, 0.753906f, 0.084595f, 0.752441f, 0.078796f,
+ 0.751465f, 0.073303f, 0.750000f, 0.068176f, 0.748535f, 0.063354f, 0.746094f, 0.058899f,
+ 0.743164f, 0.054718f, 0.740234f, 0.050812f, 0.736816f, 0.047150f, 0.731934f, 0.043793f,
+ 0.727051f, 0.040649f, 0.721191f, 0.037720f, 0.714844f, 0.035004f, 0.708008f, 0.032501f,
+ 0.700684f, 0.030167f, 0.692871f, 0.027985f, 0.684570f, 0.025986f, 0.675781f, 0.024124f,
+ 0.666016f, 0.022385f, 0.656250f, 0.020782f, 0.645996f, 0.019302f, 0.635254f, 0.017929f,
+ 0.624023f, 0.016647f, 0.612793f, 0.015480f, 0.601074f, 0.014381f, 0.588867f, 0.013367f,
+ 0.576660f, 0.012428f, 0.563965f, 0.011559f, 0.551270f, 0.010750f, 0.539062f, 0.010002f,
+ 0.525879f, 0.009308f, 0.513184f, 0.008659f, 0.500000f, 0.008064f, 0.487061f, 0.007511f,
+ 0.750000f, 0.249878f, 0.749512f, 0.249878f, 0.750000f, 0.249878f, 0.750000f, 0.249756f,
+ 0.750000f, 0.249512f, 0.750000f, 0.249146f, 0.750000f, 0.248413f, 0.750488f, 0.247559f,
+ 0.750488f, 0.246094f, 0.750488f, 0.244141f, 0.750488f, 0.241577f, 0.750488f, 0.238281f,
+ 0.748535f, 0.234009f, 0.749512f, 0.229004f, 0.749023f, 0.223022f, 0.747070f, 0.216309f,
+ 0.745117f, 0.208496f, 0.743164f, 0.200195f, 0.744629f, 0.191406f, 0.741211f, 0.182251f,
+ 0.741699f, 0.172852f, 0.740234f, 0.163330f, 0.742676f, 0.154053f, 0.741211f, 0.144775f,
+ 0.743652f, 0.135864f, 0.744629f, 0.127197f, 0.743164f, 0.118958f, 0.744629f, 0.111145f,
+ 0.745605f, 0.103638f, 0.746582f, 0.096558f, 0.748047f, 0.089966f, 0.747559f, 0.083679f,
+ 0.747559f, 0.077820f, 0.746582f, 0.072327f, 0.745605f, 0.067261f, 0.744629f, 0.062469f,
+ 0.742676f, 0.058014f, 0.739746f, 0.053864f, 0.735840f, 0.049988f, 0.731934f, 0.046417f,
+ 0.727539f, 0.043091f, 0.722168f, 0.039978f, 0.716309f, 0.037079f, 0.709473f, 0.034424f,
+ 0.702637f, 0.031952f, 0.695312f, 0.029663f, 0.687012f, 0.027542f, 0.678223f, 0.025558f,
+ 0.668945f, 0.023743f, 0.659180f, 0.022049f, 0.649414f, 0.020477f, 0.638672f, 0.019028f,
+ 0.627930f, 0.017670f, 0.616699f, 0.016434f, 0.604980f, 0.015274f, 0.593262f, 0.014198f,
+ 0.581055f, 0.013206f, 0.568848f, 0.012283f, 0.556641f, 0.011429f, 0.543945f, 0.010643f,
+ 0.531250f, 0.009903f, 0.518066f, 0.009224f, 0.505371f, 0.008591f, 0.492676f, 0.008003f,
+ 0.723145f, 0.276611f, 0.723145f, 0.276611f, 0.723145f, 0.276611f, 0.723145f, 0.276611f,
+ 0.723145f, 0.276123f, 0.723145f, 0.275635f, 0.723145f, 0.274902f, 0.723633f, 0.273682f,
+ 0.723633f, 0.271973f, 0.724121f, 0.269531f, 0.724609f, 0.266113f, 0.725098f, 0.262207f,
+ 0.725098f, 0.257080f, 0.724609f, 0.250732f, 0.722656f, 0.243652f, 0.725586f, 0.235474f,
+ 0.724121f, 0.226685f, 0.723145f, 0.216919f, 0.722656f, 0.206787f, 0.720703f, 0.196289f,
+ 0.723145f, 0.185791f, 0.723633f, 0.175171f, 0.724121f, 0.164795f, 0.728027f, 0.154663f,
+ 0.730469f, 0.144897f, 0.731934f, 0.135498f, 0.734863f, 0.126587f, 0.737305f, 0.118103f,
+ 0.739258f, 0.110107f, 0.739746f, 0.102478f, 0.741699f, 0.095398f, 0.743164f, 0.088745f,
+ 0.743652f, 0.082520f, 0.743652f, 0.076660f, 0.743652f, 0.071228f, 0.742676f, 0.066101f,
+ 0.741211f, 0.061401f, 0.739258f, 0.057007f, 0.735840f, 0.052887f, 0.732422f, 0.049103f,
+ 0.728516f, 0.045563f, 0.723145f, 0.042297f, 0.717773f, 0.039246f, 0.711914f, 0.036438f,
+ 0.704590f, 0.033813f, 0.697754f, 0.031403f, 0.689453f, 0.029160f, 0.681152f, 0.027069f,
+ 0.671875f, 0.025146f, 0.662598f, 0.023346f, 0.652832f, 0.021698f, 0.642578f, 0.020157f,
+ 0.631836f, 0.018738f, 0.621094f, 0.017426f, 0.609375f, 0.016205f, 0.597656f, 0.015076f,
+ 0.585938f, 0.014023f, 0.573730f, 0.013054f, 0.561523f, 0.012146f, 0.548828f, 0.011314f,
+ 0.536621f, 0.010536f, 0.523926f, 0.009811f, 0.511230f, 0.009148f, 0.498291f, 0.008530f,
+ 0.693848f, 0.305664f, 0.693848f, 0.305664f, 0.693848f, 0.305664f, 0.693848f, 0.305664f,
+ 0.693848f, 0.305176f, 0.694336f, 0.304443f, 0.694824f, 0.303467f, 0.695312f, 0.302002f,
+ 0.695312f, 0.299561f, 0.696289f, 0.296631f, 0.696777f, 0.292725f, 0.696777f, 0.287598f,
+ 0.697754f, 0.281250f, 0.698242f, 0.273926f, 0.698730f, 0.265137f, 0.697266f, 0.255615f,
+ 0.699707f, 0.245239f, 0.699707f, 0.234131f, 0.700195f, 0.222412f, 0.702637f, 0.210693f,
+ 0.705078f, 0.198853f, 0.708496f, 0.187134f, 0.708984f, 0.175781f, 0.715332f, 0.164673f,
+ 0.718750f, 0.154053f, 0.722168f, 0.143921f, 0.724121f, 0.134277f, 0.727539f, 0.125244f,
+ 0.731934f, 0.116638f, 0.733398f, 0.108582f, 0.736816f, 0.101013f, 0.738281f, 0.093872f,
+ 0.740234f, 0.087219f, 0.741699f, 0.081055f, 0.741211f, 0.075256f, 0.741211f, 0.069885f,
+ 0.740723f, 0.064880f, 0.738281f, 0.060211f, 0.736328f, 0.055908f, 0.732910f, 0.051849f,
+ 0.729004f, 0.048157f, 0.724609f, 0.044678f, 0.719727f, 0.041473f, 0.713379f, 0.038483f,
+ 0.707031f, 0.035736f, 0.699707f, 0.033173f, 0.692383f, 0.030823f, 0.684082f, 0.028625f,
+ 0.675293f, 0.026596f, 0.666016f, 0.024704f, 0.656738f, 0.022964f, 0.646484f, 0.021347f,
+ 0.636230f, 0.019852f, 0.625488f, 0.018463f, 0.614258f, 0.017181f, 0.602539f, 0.015976f,
+ 0.590820f, 0.014877f, 0.578613f, 0.013855f, 0.566895f, 0.012901f, 0.554688f, 0.012024f,
+ 0.541992f, 0.011200f, 0.529297f, 0.010437f, 0.516602f, 0.009735f, 0.503906f, 0.009079f,
+ 0.662598f, 0.337158f, 0.662598f, 0.337158f, 0.662598f, 0.337158f, 0.662598f, 0.336914f,
+ 0.662598f, 0.336670f, 0.663086f, 0.335938f, 0.663086f, 0.334473f, 0.664062f, 0.332520f,
+ 0.665039f, 0.329834f, 0.666016f, 0.325928f, 0.665527f, 0.320801f, 0.667969f, 0.314697f,
+ 0.667480f, 0.306885f, 0.669922f, 0.298096f, 0.669434f, 0.287842f, 0.671387f, 0.276367f,
+ 0.675781f, 0.264404f, 0.675781f, 0.251465f, 0.677734f, 0.238403f, 0.681152f, 0.225342f,
+ 0.686035f, 0.212036f, 0.690430f, 0.199219f, 0.694824f, 0.186768f, 0.700684f, 0.174805f,
+ 0.702637f, 0.163330f, 0.708008f, 0.152466f, 0.714844f, 0.142212f, 0.718750f, 0.132446f,
+ 0.724609f, 0.123291f, 0.728516f, 0.114685f, 0.731445f, 0.106628f, 0.734375f, 0.099121f,
+ 0.736816f, 0.092102f, 0.738770f, 0.085510f, 0.740723f, 0.079407f, 0.740234f, 0.073730f,
+ 0.739258f, 0.068420f, 0.738770f, 0.063538f, 0.736328f, 0.058960f, 0.734375f, 0.054718f,
+ 0.730469f, 0.050781f, 0.726562f, 0.047150f, 0.721191f, 0.043762f, 0.715332f, 0.040619f,
+ 0.709473f, 0.037720f, 0.702637f, 0.035034f, 0.695312f, 0.032532f, 0.687500f, 0.030243f,
+ 0.678711f, 0.028107f, 0.669922f, 0.026123f, 0.660645f, 0.024277f, 0.650391f, 0.022583f,
+ 0.640137f, 0.021011f, 0.629395f, 0.019547f, 0.618652f, 0.018188f, 0.607422f, 0.016937f,
+ 0.595703f, 0.015778f, 0.583984f, 0.014694f, 0.572266f, 0.013695f, 0.560059f, 0.012764f,
+ 0.547852f, 0.011902f, 0.535156f, 0.011101f, 0.522461f, 0.010353f, 0.510254f, 0.009666f,
+ 0.628418f, 0.371338f, 0.628418f, 0.371338f, 0.628418f, 0.371094f, 0.628418f, 0.371094f,
+ 0.628418f, 0.370361f, 0.629395f, 0.369385f, 0.629883f, 0.367920f, 0.630859f, 0.365234f,
+ 0.631836f, 0.361816f, 0.633301f, 0.357178f, 0.634766f, 0.350830f, 0.635742f, 0.343262f,
+ 0.638184f, 0.333984f, 0.640137f, 0.322998f, 0.641113f, 0.311035f, 0.645508f, 0.297852f,
+ 0.647949f, 0.283691f, 0.652344f, 0.269043f, 0.657227f, 0.254395f, 0.662598f, 0.239868f,
+ 0.669922f, 0.225464f, 0.673340f, 0.211426f, 0.680664f, 0.197876f, 0.685547f, 0.184937f,
+ 0.693359f, 0.172729f, 0.700684f, 0.161011f, 0.705566f, 0.150146f, 0.711426f, 0.139771f,
+ 0.718750f, 0.130005f, 0.722168f, 0.120911f, 0.727051f, 0.112427f, 0.732422f, 0.104431f,
+ 0.733887f, 0.097046f, 0.737305f, 0.090088f, 0.738770f, 0.083618f, 0.740234f, 0.077637f,
+ 0.739258f, 0.072083f, 0.738281f, 0.066895f, 0.736816f, 0.062073f, 0.734375f, 0.057648f,
+ 0.731934f, 0.053497f, 0.728027f, 0.049683f, 0.723145f, 0.046112f, 0.717773f, 0.042816f,
+ 0.712402f, 0.039764f, 0.705566f, 0.036957f, 0.698242f, 0.034332f, 0.690430f, 0.031891f,
+ 0.682617f, 0.029663f, 0.673340f, 0.027573f, 0.664551f, 0.025650f, 0.654785f, 0.023865f,
+ 0.644531f, 0.022202f, 0.634277f, 0.020676f, 0.623535f, 0.019257f, 0.612305f, 0.017929f,
+ 0.601074f, 0.016708f, 0.589355f, 0.015579f, 0.577637f, 0.014526f, 0.565430f, 0.013550f,
+ 0.553223f, 0.012642f, 0.541016f, 0.011787f, 0.528809f, 0.011009f, 0.516113f, 0.010277f,
+ 0.591309f, 0.407959f, 0.591797f, 0.407959f, 0.591797f, 0.407959f, 0.591797f, 0.407471f,
+ 0.592285f, 0.406982f, 0.592773f, 0.405762f, 0.593750f, 0.403564f, 0.594727f, 0.400391f,
+ 0.596680f, 0.396240f, 0.598145f, 0.390137f, 0.600098f, 0.382568f, 0.602539f, 0.373047f,
+ 0.604980f, 0.361816f, 0.606934f, 0.348877f, 0.611816f, 0.334473f, 0.616699f, 0.319336f,
+ 0.620605f, 0.302979f, 0.627930f, 0.286865f, 0.634277f, 0.270508f, 0.638672f, 0.254150f,
+ 0.647949f, 0.238525f, 0.654297f, 0.223389f, 0.663086f, 0.208862f, 0.673828f, 0.195068f,
+ 0.680176f, 0.182007f, 0.689941f, 0.169678f, 0.696289f, 0.157959f, 0.705078f, 0.147095f,
+ 0.713867f, 0.136841f, 0.719727f, 0.127197f, 0.724121f, 0.118225f, 0.729980f, 0.109863f,
+ 0.731934f, 0.101990f, 0.735840f, 0.094727f, 0.737305f, 0.087952f, 0.738770f, 0.081604f,
+ 0.740234f, 0.075745f, 0.739258f, 0.070312f, 0.738281f, 0.065247f, 0.735840f, 0.060608f,
+ 0.733398f, 0.056274f, 0.729492f, 0.052246f, 0.725098f, 0.048523f, 0.720703f, 0.045074f,
+ 0.714355f, 0.041870f, 0.708496f, 0.038910f, 0.701660f, 0.036163f, 0.693848f, 0.033630f,
+ 0.686035f, 0.031281f, 0.677734f, 0.029099f, 0.668457f, 0.027069f, 0.659180f, 0.025192f,
+ 0.648926f, 0.023453f, 0.639160f, 0.021851f, 0.628418f, 0.020355f, 0.617676f, 0.018967f,
+ 0.605957f, 0.017685f, 0.594727f, 0.016495f, 0.583008f, 0.015388f, 0.571289f, 0.014366f,
+ 0.559570f, 0.013412f, 0.546875f, 0.012520f, 0.534668f, 0.011696f, 0.522461f, 0.010925f,
+ 0.551758f, 0.447754f, 0.551758f, 0.447754f, 0.552246f, 0.447510f, 0.552246f, 0.447266f,
+ 0.552734f, 0.446289f, 0.553223f, 0.444580f, 0.555176f, 0.441895f, 0.556152f, 0.438232f,
+ 0.558594f, 0.432617f, 0.561035f, 0.425049f, 0.563477f, 0.415527f, 0.566406f, 0.404053f,
+ 0.570312f, 0.390381f, 0.575195f, 0.375000f, 0.578613f, 0.358154f, 0.584473f, 0.340332f,
+ 0.593750f, 0.322266f, 0.600098f, 0.303955f, 0.611328f, 0.286133f, 0.617676f, 0.268555f,
+ 0.629395f, 0.251709f, 0.640625f, 0.235352f, 0.649902f, 0.219849f, 0.661621f, 0.205078f,
+ 0.671387f, 0.191284f, 0.678711f, 0.178223f, 0.688965f, 0.166016f, 0.699707f, 0.154419f,
+ 0.707031f, 0.143555f, 0.714844f, 0.133545f, 0.719727f, 0.124084f, 0.726074f, 0.115295f,
+ 0.731445f, 0.107056f, 0.734863f, 0.099365f, 0.737305f, 0.092285f, 0.739258f, 0.085632f,
+ 0.740234f, 0.079529f, 0.739746f, 0.073792f, 0.739258f, 0.068542f, 0.737793f, 0.063599f,
+ 0.734863f, 0.059082f, 0.731934f, 0.054871f, 0.727539f, 0.050964f, 0.723633f, 0.047394f,
+ 0.717773f, 0.044006f, 0.711426f, 0.040924f, 0.705078f, 0.038055f, 0.697754f, 0.035400f,
+ 0.689941f, 0.032928f, 0.681641f, 0.030655f, 0.672852f, 0.028534f, 0.663574f, 0.026581f,
+ 0.653809f, 0.024750f, 0.644043f, 0.023071f, 0.633301f, 0.021515f, 0.622559f, 0.020050f,
+ 0.611328f, 0.018707f, 0.600098f, 0.017456f, 0.588867f, 0.016296f, 0.577148f, 0.015221f,
+ 0.565430f, 0.014221f, 0.553223f, 0.013290f, 0.541504f, 0.012421f, 0.528809f, 0.011620f,
+ 0.509277f, 0.490234f, 0.509277f, 0.490234f, 0.509277f, 0.489990f, 0.509766f, 0.489502f,
+ 0.510254f, 0.488525f, 0.511230f, 0.486328f, 0.512695f, 0.482910f, 0.514160f, 0.478027f,
+ 0.517578f, 0.470947f, 0.520996f, 0.461670f, 0.523926f, 0.449707f, 0.528809f, 0.435303f,
+ 0.534180f, 0.418945f, 0.540527f, 0.400635f, 0.548340f, 0.381348f, 0.554688f, 0.361328f,
+ 0.566895f, 0.340820f, 0.577637f, 0.320801f, 0.588867f, 0.301270f, 0.601074f, 0.282471f,
+ 0.610352f, 0.264404f, 0.624023f, 0.247070f, 0.637207f, 0.230591f, 0.649414f, 0.215210f,
+ 0.662109f, 0.200562f, 0.672852f, 0.186768f, 0.685547f, 0.173828f, 0.693359f, 0.161743f,
+ 0.702148f, 0.150391f, 0.711426f, 0.139771f, 0.720703f, 0.129883f, 0.726074f, 0.120667f,
+ 0.730469f, 0.112061f, 0.733887f, 0.104065f, 0.738281f, 0.096619f, 0.739258f, 0.089722f,
+ 0.740234f, 0.083252f, 0.741699f, 0.077332f, 0.740723f, 0.071777f, 0.739258f, 0.066711f,
+ 0.736816f, 0.061951f, 0.734375f, 0.057556f, 0.730469f, 0.053497f, 0.726074f, 0.049713f,
+ 0.720703f, 0.046234f, 0.714844f, 0.042999f, 0.708496f, 0.039978f, 0.701172f, 0.037231f,
+ 0.693848f, 0.034637f, 0.685547f, 0.032257f, 0.677246f, 0.030060f, 0.667969f, 0.028000f,
+ 0.658691f, 0.026108f, 0.648926f, 0.024338f, 0.638672f, 0.022705f, 0.627930f, 0.021194f,
+ 0.617188f, 0.019775f, 0.605957f, 0.018463f, 0.594727f, 0.017258f, 0.583008f, 0.016129f,
+ 0.571289f, 0.015076f, 0.559570f, 0.014099f, 0.547852f, 0.013191f, 0.535645f, 0.012337f,
+ 0.463623f, 0.536133f, 0.463623f, 0.536133f, 0.463867f, 0.535645f, 0.464111f, 0.535156f,
+ 0.465088f, 0.533691f, 0.466064f, 0.530762f, 0.468506f, 0.526367f, 0.471191f, 0.520020f,
+ 0.474609f, 0.511230f, 0.478516f, 0.499268f, 0.483643f, 0.484375f, 0.489990f, 0.466797f,
+ 0.495361f, 0.447266f, 0.502441f, 0.425537f, 0.515137f, 0.403564f, 0.526855f, 0.380859f,
+ 0.540039f, 0.358887f, 0.553711f, 0.336914f, 0.564453f, 0.315918f, 0.587891f, 0.295898f,
+ 0.600098f, 0.276611f, 0.610840f, 0.258545f, 0.624512f, 0.241211f, 0.641113f, 0.225098f,
+ 0.657715f, 0.209717f, 0.668457f, 0.195312f, 0.678223f, 0.181763f, 0.687988f, 0.169067f,
+ 0.701172f, 0.157104f, 0.707031f, 0.146118f, 0.715332f, 0.135620f, 0.723145f, 0.125977f,
+ 0.728516f, 0.117126f, 0.734375f, 0.108704f, 0.736328f, 0.100952f, 0.739746f, 0.093750f,
+ 0.741699f, 0.087036f, 0.742188f, 0.080872f, 0.741699f, 0.075134f, 0.741211f, 0.069763f,
+ 0.739258f, 0.064819f, 0.736816f, 0.060272f, 0.733398f, 0.056030f, 0.729004f, 0.052124f,
+ 0.724121f, 0.048492f, 0.718750f, 0.045105f, 0.712402f, 0.041992f, 0.705078f, 0.039093f,
+ 0.698242f, 0.036407f, 0.689941f, 0.033905f, 0.681641f, 0.031616f, 0.672852f, 0.029480f,
+ 0.663574f, 0.027512f, 0.653809f, 0.025665f, 0.644043f, 0.023956f, 0.633301f, 0.022369f,
+ 0.622559f, 0.020889f, 0.611816f, 0.019516f, 0.601074f, 0.018250f, 0.589355f, 0.017059f,
+ 0.578125f, 0.015961f, 0.565918f, 0.014946f, 0.554199f, 0.013992f, 0.542480f, 0.013107f,
+ 0.414551f, 0.584961f, 0.414551f, 0.584961f, 0.414795f, 0.584961f, 0.415039f, 0.583984f,
+ 0.416260f, 0.582031f, 0.418457f, 0.578613f, 0.420166f, 0.572754f, 0.424072f, 0.563965f,
+ 0.428467f, 0.552246f, 0.433838f, 0.537109f, 0.441162f, 0.518066f, 0.448730f, 0.497070f,
+ 0.458984f, 0.473633f, 0.467773f, 0.449219f, 0.480713f, 0.424072f, 0.497559f, 0.399414f,
+ 0.511719f, 0.375244f, 0.529297f, 0.352051f, 0.543945f, 0.329834f, 0.566895f, 0.308838f,
+ 0.581543f, 0.288574f, 0.598633f, 0.269531f, 0.619629f, 0.251465f, 0.635742f, 0.234497f,
+ 0.646973f, 0.218506f, 0.659668f, 0.203369f, 0.674805f, 0.189331f, 0.684570f, 0.176025f,
+ 0.695801f, 0.163696f, 0.707031f, 0.152222f, 0.718750f, 0.141357f, 0.723145f, 0.131348f,
+ 0.729004f, 0.122009f, 0.734375f, 0.113342f, 0.738281f, 0.105286f, 0.741211f, 0.097778f,
+ 0.743164f, 0.090820f, 0.744629f, 0.084412f, 0.744629f, 0.078430f, 0.743652f, 0.072876f,
+ 0.742676f, 0.067749f, 0.739746f, 0.062988f, 0.735840f, 0.058624f, 0.731934f, 0.054535f,
+ 0.727539f, 0.050751f, 0.721680f, 0.047241f, 0.715820f, 0.044006f, 0.709473f, 0.040985f,
+ 0.702148f, 0.038208f, 0.694824f, 0.035614f, 0.686523f, 0.033234f, 0.677734f, 0.031006f,
+ 0.668457f, 0.028946f, 0.659180f, 0.027023f, 0.649414f, 0.025238f, 0.639160f, 0.023590f,
+ 0.628906f, 0.022049f, 0.618164f, 0.020630f, 0.606934f, 0.019287f, 0.595703f, 0.018051f,
+ 0.584473f, 0.016907f, 0.572754f, 0.015839f, 0.561035f, 0.014839f, 0.549316f, 0.013908f,
+ 0.361816f, 0.637695f, 0.361816f, 0.637695f, 0.362061f, 0.637207f, 0.362793f, 0.636230f,
+ 0.364258f, 0.633301f, 0.366455f, 0.628906f, 0.369873f, 0.621094f, 0.374512f, 0.609375f,
+ 0.378906f, 0.593750f, 0.387451f, 0.573730f, 0.396484f, 0.550293f, 0.407471f, 0.524414f,
+ 0.419189f, 0.497314f, 0.433594f, 0.469971f, 0.453613f, 0.442627f, 0.473633f, 0.416016f,
+ 0.488037f, 0.390381f, 0.509277f, 0.365967f, 0.528809f, 0.343262f, 0.549805f, 0.320801f,
+ 0.574707f, 0.299805f, 0.590332f, 0.280029f, 0.609375f, 0.261475f, 0.631836f, 0.243774f,
+ 0.641602f, 0.227173f, 0.659668f, 0.211426f, 0.671387f, 0.196777f, 0.685059f, 0.183105f,
+ 0.698730f, 0.170166f, 0.705078f, 0.158203f, 0.715820f, 0.146973f, 0.723145f, 0.136597f,
+ 0.730469f, 0.126831f, 0.737793f, 0.117920f, 0.740723f, 0.109558f, 0.741699f, 0.101807f,
+ 0.745117f, 0.094604f, 0.747559f, 0.087891f, 0.747070f, 0.081726f, 0.747070f, 0.075989f,
+ 0.744141f, 0.070679f, 0.742676f, 0.065796f, 0.739258f, 0.061218f, 0.735840f, 0.056976f,
+ 0.730957f, 0.053070f, 0.725586f, 0.049438f, 0.719727f, 0.046082f, 0.713867f, 0.042938f,
+ 0.706543f, 0.040070f, 0.699219f, 0.037384f, 0.690918f, 0.034882f, 0.682617f, 0.032562f,
+ 0.673828f, 0.030426f, 0.664551f, 0.028442f, 0.654785f, 0.026581f, 0.645020f, 0.024857f,
+ 0.634766f, 0.023254f, 0.624023f, 0.021774f, 0.613281f, 0.020386f, 0.602051f, 0.019089f,
+ 0.590820f, 0.017899f, 0.579590f, 0.016769f, 0.567871f, 0.015732f, 0.556641f, 0.014755f,
+ 0.305420f, 0.694336f, 0.305420f, 0.694336f, 0.305664f, 0.693848f, 0.306641f, 0.691895f,
+ 0.308105f, 0.687988f, 0.311279f, 0.681152f, 0.316162f, 0.669922f, 0.321777f, 0.654297f,
+ 0.330078f, 0.632812f, 0.344238f, 0.606934f, 0.353027f, 0.578125f, 0.367432f, 0.547852f,
+ 0.385498f, 0.517578f, 0.405273f, 0.487793f, 0.422852f, 0.458496f, 0.448730f, 0.431152f,
+ 0.473633f, 0.404541f, 0.493896f, 0.379639f, 0.519531f, 0.355469f, 0.539551f, 0.332520f,
+ 0.563477f, 0.310791f, 0.583008f, 0.290283f, 0.604004f, 0.270752f, 0.626953f, 0.252686f,
+ 0.642090f, 0.235352f, 0.657715f, 0.218994f, 0.672852f, 0.203857f, 0.686523f, 0.189575f,
+ 0.699219f, 0.176270f, 0.707031f, 0.163818f, 0.717285f, 0.152344f, 0.723633f, 0.141602f,
+ 0.730469f, 0.131592f, 0.739258f, 0.122375f, 0.741699f, 0.113708f, 0.745605f, 0.105713f,
+ 0.747559f, 0.098267f, 0.748047f, 0.091370f, 0.749023f, 0.085022f, 0.748535f, 0.079102f,
+ 0.747070f, 0.073608f, 0.746582f, 0.068542f, 0.742188f, 0.063843f, 0.739258f, 0.059448f,
+ 0.734375f, 0.055420f, 0.730469f, 0.051666f, 0.724609f, 0.048187f, 0.717773f, 0.044952f,
+ 0.710938f, 0.041962f, 0.704102f, 0.039154f, 0.695801f, 0.036591f, 0.687988f, 0.034180f,
+ 0.679199f, 0.031952f, 0.670410f, 0.029892f, 0.660645f, 0.027969f, 0.650879f, 0.026184f,
+ 0.640625f, 0.024521f, 0.630371f, 0.022964f, 0.619629f, 0.021515f, 0.608887f, 0.020172f,
+ 0.598145f, 0.018921f, 0.586914f, 0.017761f, 0.575195f, 0.016663f, 0.563965f, 0.015656f,
+ 0.244995f, 0.754395f, 0.245117f, 0.754395f, 0.245483f, 0.753418f, 0.246704f, 0.750977f,
+ 0.249634f, 0.745117f, 0.253662f, 0.734863f, 0.260010f, 0.717773f, 0.268555f, 0.694336f,
+ 0.277344f, 0.665527f, 0.292480f, 0.632812f, 0.309814f, 0.599121f, 0.331787f, 0.565918f,
+ 0.352539f, 0.533203f, 0.376465f, 0.501953f, 0.405518f, 0.472412f, 0.433838f, 0.444336f,
+ 0.456787f, 0.417236f, 0.488281f, 0.391357f, 0.510254f, 0.366211f, 0.540039f, 0.343018f,
+ 0.564941f, 0.320557f, 0.579590f, 0.299561f, 0.606445f, 0.279541f, 0.627441f, 0.260498f,
+ 0.638184f, 0.242676f, 0.666504f, 0.226074f, 0.670898f, 0.210327f, 0.687988f, 0.195801f,
+ 0.700684f, 0.182129f, 0.706055f, 0.169312f, 0.718262f, 0.157471f, 0.727539f, 0.146362f,
+ 0.735840f, 0.136108f, 0.738770f, 0.126587f, 0.743164f, 0.117737f, 0.746582f, 0.109497f,
+ 0.751953f, 0.101868f, 0.751953f, 0.094788f, 0.753906f, 0.088257f, 0.752930f, 0.082153f,
+ 0.750977f, 0.076538f, 0.749512f, 0.071289f, 0.745605f, 0.066406f, 0.742188f, 0.061951f,
+ 0.738281f, 0.057770f, 0.734375f, 0.053894f, 0.729004f, 0.050293f, 0.722656f, 0.046967f,
+ 0.715332f, 0.043854f, 0.708496f, 0.040985f, 0.701172f, 0.038330f, 0.693359f, 0.035828f,
+ 0.684570f, 0.033539f, 0.676270f, 0.031403f, 0.666992f, 0.029404f, 0.657227f, 0.027542f,
+ 0.646973f, 0.025818f, 0.636719f, 0.024200f, 0.626465f, 0.022705f, 0.615723f, 0.021301f,
+ 0.604980f, 0.020004f, 0.593750f, 0.018784f, 0.582520f, 0.017654f, 0.571289f, 0.016586f,
+ 0.180542f, 0.818848f, 0.180664f, 0.818848f, 0.181274f, 0.817383f, 0.183350f, 0.812988f,
+ 0.187134f, 0.802734f, 0.193237f, 0.784180f, 0.201416f, 0.757324f, 0.214355f, 0.723145f,
+ 0.231445f, 0.685547f, 0.248901f, 0.648438f, 0.272217f, 0.611816f, 0.302979f, 0.577148f,
+ 0.329834f, 0.544922f, 0.364258f, 0.514160f, 0.394043f, 0.484619f, 0.425781f, 0.456055f,
+ 0.456543f, 0.428467f, 0.481934f, 0.402344f, 0.512207f, 0.376709f, 0.540039f, 0.352783f,
+ 0.566406f, 0.329346f, 0.579102f, 0.307617f, 0.607910f, 0.286865f, 0.627930f, 0.267822f,
+ 0.645996f, 0.249512f, 0.661621f, 0.232178f, 0.677734f, 0.216309f, 0.691406f, 0.201172f,
+ 0.702637f, 0.187256f, 0.711426f, 0.174194f, 0.721680f, 0.161987f, 0.730957f, 0.150879f,
+ 0.736328f, 0.140259f, 0.742188f, 0.130493f, 0.746582f, 0.121582f, 0.750488f, 0.113159f,
+ 0.751953f, 0.105347f, 0.752930f, 0.098083f, 0.756836f, 0.091370f, 0.755859f, 0.085144f,
+ 0.755371f, 0.079346f, 0.752441f, 0.073975f, 0.750488f, 0.069031f, 0.746582f, 0.064392f,
+ 0.743652f, 0.060120f, 0.737793f, 0.056152f, 0.733398f, 0.052460f, 0.727051f, 0.049011f,
+ 0.720215f, 0.045837f, 0.713867f, 0.042847f, 0.706543f, 0.040100f, 0.699219f, 0.037537f,
+ 0.690430f, 0.035156f, 0.682129f, 0.032928f, 0.672852f, 0.030884f, 0.663086f, 0.028961f,
+ 0.653809f, 0.027161f, 0.644043f, 0.025497f, 0.633301f, 0.023941f, 0.622559f, 0.022491f,
+ 0.612305f, 0.021133f, 0.601074f, 0.019867f, 0.590332f, 0.018692f, 0.579102f, 0.017578f,
+ 0.111816f, 0.888184f, 0.112000f, 0.887207f, 0.112976f, 0.883789f, 0.115845f, 0.873047f,
+ 0.122864f, 0.849609f, 0.133301f, 0.813477f, 0.147217f, 0.770996f, 0.167236f, 0.728027f,
+ 0.196411f, 0.688965f, 0.222290f, 0.653320f, 0.258057f, 0.619629f, 0.293457f, 0.587402f,
+ 0.328613f, 0.556152f, 0.361328f, 0.524902f, 0.392578f, 0.495850f, 0.430420f, 0.466064f,
+ 0.459961f, 0.437744f, 0.482422f, 0.410889f, 0.511230f, 0.385010f, 0.536621f, 0.359863f,
+ 0.568848f, 0.336182f, 0.592773f, 0.313721f, 0.614258f, 0.293213f, 0.626953f, 0.273193f,
+ 0.646484f, 0.254639f, 0.657227f, 0.237427f, 0.683105f, 0.221191f, 0.693359f, 0.205933f,
+ 0.698242f, 0.191772f, 0.709473f, 0.178589f, 0.724609f, 0.166260f, 0.733398f, 0.154907f,
+ 0.739746f, 0.144165f, 0.745605f, 0.134399f, 0.750977f, 0.125122f, 0.753906f, 0.116577f,
+ 0.754883f, 0.108704f, 0.758301f, 0.101257f, 0.759766f, 0.094482f, 0.757812f, 0.088074f,
+ 0.759766f, 0.082092f, 0.758301f, 0.076660f, 0.756348f, 0.071594f, 0.752441f, 0.066833f,
+ 0.748047f, 0.062469f, 0.741699f, 0.058380f, 0.736816f, 0.054596f, 0.732910f, 0.051086f,
+ 0.726074f, 0.047791f, 0.719727f, 0.044769f, 0.711914f, 0.041901f, 0.704590f, 0.039276f,
+ 0.696289f, 0.036804f, 0.688477f, 0.034546f, 0.678711f, 0.032410f, 0.669922f, 0.030411f,
+ 0.660156f, 0.028564f, 0.650391f, 0.026840f, 0.640625f, 0.025223f, 0.630371f, 0.023727f,
+ 0.619629f, 0.022324f, 0.608887f, 0.020996f, 0.597656f, 0.019775f, 0.586914f, 0.018631f,
+ 0.038452f, 0.960938f, 0.039124f, 0.957520f, 0.042480f, 0.933594f, 0.051575f, 0.879395f,
+ 0.069275f, 0.824219f, 0.091064f, 0.785156f, 0.126343f, 0.753906f, 0.154419f, 0.725586f,
+ 0.192139f, 0.695312f, 0.234375f, 0.663086f, 0.273438f, 0.630371f, 0.305908f, 0.597656f,
+ 0.338379f, 0.565430f, 0.379150f, 0.532227f, 0.413818f, 0.501465f, 0.444336f, 0.471191f,
+ 0.471436f, 0.442383f, 0.504395f, 0.414795f, 0.531250f, 0.388672f, 0.547363f, 0.364014f,
+ 0.579590f, 0.340088f, 0.603516f, 0.317627f, 0.622559f, 0.297119f, 0.635742f, 0.276855f,
+ 0.669434f, 0.258301f, 0.670410f, 0.241089f, 0.685547f, 0.224854f, 0.699219f, 0.209717f,
+ 0.712402f, 0.195190f, 0.720703f, 0.182373f, 0.729980f, 0.169678f, 0.746582f, 0.158325f,
+ 0.744629f, 0.147705f, 0.748535f, 0.137695f, 0.760254f, 0.128296f, 0.757812f, 0.119629f,
+ 0.761230f, 0.111755f, 0.762207f, 0.104248f, 0.764160f, 0.097290f, 0.763184f, 0.090881f,
+ 0.762207f, 0.084900f, 0.760742f, 0.079285f, 0.759766f, 0.074097f, 0.755859f, 0.069275f,
+ 0.752930f, 0.064758f, 0.747559f, 0.060669f, 0.742676f, 0.056793f, 0.737305f, 0.053131f,
+ 0.731445f, 0.049774f, 0.725586f, 0.046661f, 0.718262f, 0.043732f, 0.710449f, 0.041077f,
+ 0.702637f, 0.038544f, 0.694336f, 0.036163f, 0.685547f, 0.033966f, 0.676758f, 0.031921f,
+ 0.667480f, 0.030014f, 0.657715f, 0.028229f, 0.647461f, 0.026566f, 0.637207f, 0.025009f,
+ 0.626953f, 0.023544f, 0.616699f, 0.022186f, 0.605957f, 0.020920f, 0.594727f, 0.019730f
+};
+
+static float ltc_disk_integral[64 * 64] = {
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.015873f, 0.047619f, 0.079365f, 0.111111f, 0.142857f, 0.174603f, 0.206349f, 0.238095f,
+ 0.269841f, 0.301587f, 0.333333f, 0.365079f, 0.396825f, 0.428571f, 0.460317f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000148f, 0.002454f, 0.008675f, 0.019560f,
+ 0.035433f, 0.056294f, 0.081819f, 0.111259f, 0.142857f, 0.174603f, 0.206349f, 0.238095f,
+ 0.269841f, 0.301587f, 0.333333f, 0.365079f, 0.396825f, 0.428571f, 0.460317f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000002f, 0.000761f, 0.003673f, 0.009403f, 0.018333f, 0.030683f,
+ 0.046556f, 0.065952f, 0.088768f, 0.114784f, 0.143618f, 0.174606f, 0.206349f, 0.238095f,
+ 0.269841f, 0.301587f, 0.333333f, 0.365079f, 0.396825f, 0.428571f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000039f, 0.000969f, 0.003703f, 0.008684f, 0.016189f, 0.026395f, 0.039409f,
+ 0.055282f, 0.074014f, 0.095554f, 0.119795f, 0.146560f, 0.175573f, 0.206388f, 0.238095f,
+ 0.269841f, 0.301587f, 0.333333f, 0.365079f, 0.396825f, 0.428571f, 0.460317f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000047f, 0.000895f, 0.003265f, 0.007514f, 0.013873f, 0.022495f, 0.033483f, 0.046897f,
+ 0.062770f, 0.081102f, 0.101860f, 0.124985f, 0.150372f, 0.177868f, 0.207245f, 0.238143f,
+ 0.269841f, 0.301587f, 0.333333f, 0.365079f, 0.396825f, 0.428571f, 0.460317f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000028f,
+ 0.000695f, 0.002655f, 0.006230f, 0.011623f, 0.018976f, 0.028384f, 0.039915f, 0.053606f,
+ 0.069479f, 0.087534f, 0.107749f, 0.130087f, 0.154481f, 0.180833f, 0.209005f, 0.238791f,
+ 0.269869f, 0.301587f, 0.333333f, 0.365079f, 0.396825f, 0.428571f, 0.460317f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000007f, 0.000465f,
+ 0.002017f, 0.004975f, 0.009533f, 0.015821f, 0.023934f, 0.033937f, 0.045874f, 0.059772f,
+ 0.075645f, 0.093493f, 0.113302f, 0.135045f, 0.158678f, 0.184136f, 0.211325f, 0.240113f,
+ 0.270306f, 0.301594f, 0.333333f, 0.365079f, 0.396825f, 0.428571f, 0.460317f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000260f, 0.001426f,
+ 0.003823f, 0.007642f, 0.013012f, 0.020025f, 0.028745f, 0.039218f, 0.051475f, 0.065535f,
+ 0.081408f, 0.099094f, 0.118583f, 0.139856f, 0.162882f, 0.187615f, 0.213991f, 0.241918f,
+ 0.271267f, 0.301847f, 0.333333f, 0.365079f, 0.396826f, 0.428572f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000109f, 0.000921f, 0.002807f,
+ 0.005966f, 0.010528f, 0.016585f, 0.024200f, 0.033420f, 0.044278f, 0.056796f, 0.070988f,
+ 0.086861f, 0.104415f, 0.123643f, 0.144531f, 0.167057f, 0.191188f, 0.216878f, 0.244062f,
+ 0.272649f, 0.302509f, 0.333442f, 0.365079f, 0.396826f, 0.428572f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000024f, 0.000524f, 0.001947f, 0.004511f,
+ 0.008351f, 0.013561f, 0.020206f, 0.028332f, 0.037974f, 0.049155f, 0.061892f, 0.076194f,
+ 0.092067f, 0.109511f, 0.128520f, 0.149085f, 0.171189f, 0.194809f, 0.219910f, 0.246447f,
+ 0.274352f, 0.303535f, 0.333857f, 0.365104f, 0.396826f, 0.428572f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000242f, 0.001250f, 0.003275f, 0.006463f,
+ 0.010913f, 0.016693f, 0.023849f, 0.032418f, 0.042423f, 0.053881f, 0.066805f, 0.081201f,
+ 0.097074f, 0.114424f, 0.133246f, 0.153534f, 0.175275f, 0.198453f, 0.223042f, 0.249009f,
+ 0.276304f, 0.304862f, 0.334584f, 0.365322f, 0.396826f, 0.428571f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000074f, 0.000716f, 0.002252f, 0.004848f, 0.008610f,
+ 0.013608f, 0.019894f, 0.027502f, 0.036458f, 0.046780f, 0.058480f, 0.071567f, 0.086045f,
+ 0.101918f, 0.119186f, 0.137845f, 0.157891f, 0.179316f, 0.202106f, 0.226243f, 0.251704f,
+ 0.278451f, 0.306436f, 0.335586f, 0.365796f, 0.396900f, 0.428571f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000006f, 0.000342f, 0.001437f, 0.003492f, 0.006624f, 0.010911f,
+ 0.016406f, 0.023146f, 0.031157f, 0.040457f, 0.051059f, 0.062972f, 0.076203f, 0.090753f,
+ 0.106626f, 0.123822f, 0.142337f, 0.162170f, 0.183314f, 0.205760f, 0.229496f, 0.254502f,
+ 0.280753f, 0.308212f, 0.336825f, 0.366517f, 0.397167f, 0.428578f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000114f, 0.000820f, 0.002381f, 0.004935f, 0.008569f, 0.013339f,
+ 0.019286f, 0.026437f, 0.034810f, 0.044418f, 0.055271f, 0.067375f, 0.080733f, 0.095348f,
+ 0.111221f, 0.128352f, 0.146740f, 0.166382f, 0.187276f, 0.209413f, 0.232786f, 0.257382f,
+ 0.283181f, 0.310156f, 0.338269f, 0.367461f, 0.397646f, 0.428685f, 0.460318f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000014f, 0.000390f, 0.001503f, 0.003525f, 0.006554f, 0.010655f, 0.015872f,
+ 0.022233f, 0.029758f, 0.038460f, 0.048347f, 0.059427f, 0.071702f, 0.085175f, 0.099848f,
+ 0.115721f, 0.132794f, 0.151067f, 0.170538f, 0.191204f, 0.213063f, 0.236107f, 0.260329f,
+ 0.285714f, 0.312243f, 0.339887f, 0.368604f, 0.398329f, 0.428961f, 0.460331f, 0.492064f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000130f, 0.000845f, 0.002376f, 0.004845f, 0.008325f, 0.012864f, 0.018495f,
+ 0.025237f, 0.033105f, 0.042107f, 0.052249f, 0.063534f, 0.075965f, 0.089543f, 0.104269f,
+ 0.120142f, 0.137163f, 0.155330f, 0.174645f, 0.195106f, 0.216710f, 0.239454f, 0.263332f,
+ 0.288336f, 0.314451f, 0.341658f, 0.369924f, 0.399202f, 0.429416f, 0.460447f, 0.492064f,
+ 0.523809f, 0.555555f, 0.587301f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000016f, 0.000391f, 0.001475f, 0.003423f, 0.006322f, 0.010230f, 0.015179f, 0.021195f,
+ 0.028290f, 0.036474f, 0.045752f, 0.056128f, 0.067602f, 0.080176f, 0.093850f, 0.108623f,
+ 0.124496f, 0.141469f, 0.159541f, 0.178713f, 0.198985f, 0.220355f, 0.242823f, 0.266385f,
+ 0.291036f, 0.316767f, 0.343563f, 0.371402f, 0.400248f, 0.430047f, 0.460709f, 0.492079f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000123f, 0.000807f, 0.002272f, 0.004628f, 0.007942f, 0.012253f, 0.017589f, 0.023963f,
+ 0.031387f, 0.039864f, 0.049398f, 0.059990f, 0.071638f, 0.084344f, 0.098106f, 0.112923f,
+ 0.128796f, 0.145725f, 0.163709f, 0.182749f, 0.202847f, 0.224001f, 0.246214f, 0.269482f,
+ 0.293805f, 0.319176f, 0.345587f, 0.373021f, 0.401454f, 0.430844f, 0.461125f, 0.492187f,
+ 0.523810f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000012f,
+ 0.000356f, 0.001378f, 0.003225f, 0.005979f, 0.009689f, 0.014384f, 0.020083f, 0.026795f,
+ 0.034525f, 0.043276f, 0.053047f, 0.063839f, 0.075649f, 0.088476f, 0.102320f, 0.117178f,
+ 0.133051f, 0.149939f, 0.167841f, 0.186760f, 0.206696f, 0.227650f, 0.249625f, 0.272620f,
+ 0.296636f, 0.321671f, 0.347718f, 0.374768f, 0.402804f, 0.431796f, 0.461695f, 0.492420f,
+ 0.523822f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000100f,
+ 0.000725f, 0.002097f, 0.004323f, 0.007463f, 0.011553f, 0.016613f, 0.022655f, 0.029684f,
+ 0.037702f, 0.046708f, 0.056701f, 0.067680f, 0.079640f, 0.092581f, 0.106501f, 0.121397f,
+ 0.137270f, 0.154120f, 0.171946f, 0.190751f, 0.210537f, 0.231305f, 0.253057f, 0.275797f,
+ 0.299525f, 0.324242f, 0.349947f, 0.376633f, 0.404289f, 0.432895f, 0.462415f, 0.492788f,
+ 0.523909f, 0.555556f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000005f, 0.000296f,
+ 0.001231f, 0.002960f, 0.005558f, 0.009072f, 0.013526f, 0.018933f, 0.025299f, 0.032627f,
+ 0.040916f, 0.050162f, 0.060364f, 0.071517f, 0.083619f, 0.096666f, 0.110656f, 0.125588f,
+ 0.141461f, 0.158275f, 0.176031f, 0.194730f, 0.214374f, 0.234967f, 0.256512f, 0.279011f,
+ 0.302468f, 0.326887f, 0.352266f, 0.378605f, 0.405897f, 0.434130f, 0.463277f, 0.493295f,
+ 0.524106f, 0.555561f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000068f, 0.000613f,
+ 0.001874f, 0.003958f, 0.006921f, 0.010796f, 0.015599f, 0.021336f, 0.028011f, 0.035623f,
+ 0.044167f, 0.053640f, 0.064038f, 0.075355f, 0.087589f, 0.100736f, 0.114793f, 0.129759f,
+ 0.145632f, 0.162412f, 0.180101f, 0.198700f, 0.218213f, 0.238641f, 0.259989f, 0.282262f,
+ 0.305464f, 0.329599f, 0.354670f, 0.380678f, 0.407622f, 0.435493f, 0.464275f, 0.493938f,
+ 0.524422f, 0.555624f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000223f, 0.001054f,
+ 0.002649f, 0.005086f, 0.008406f, 0.012629f, 0.017766f, 0.023820f, 0.030789f, 0.038669f,
+ 0.047455f, 0.057143f, 0.067726f, 0.079199f, 0.091558f, 0.104798f, 0.118918f, 0.133915f,
+ 0.149788f, 0.166537f, 0.184164f, 0.202669f, 0.222056f, 0.242329f, 0.263492f, 0.285551f,
+ 0.308510f, 0.332376f, 0.357153f, 0.382845f, 0.409454f, 0.436977f, 0.465404f, 0.494713f,
+ 0.524864f, 0.555779f, 0.587302f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000037f, 0.000486f, 0.001621f,
+ 0.003553f, 0.006338f, 0.010004f, 0.014565f, 0.020024f, 0.026380f, 0.033629f, 0.041765f,
+ 0.050782f, 0.060673f, 0.071431f, 0.083052f, 0.095529f, 0.108859f, 0.123038f, 0.138065f,
+ 0.153938f, 0.170657f, 0.188224f, 0.206640f, 0.225909f, 0.246035f, 0.267022f, 0.288878f,
+ 0.311607f, 0.335216f, 0.359713f, 0.385103f, 0.411390f, 0.438576f, 0.466656f, 0.495617f,
+ 0.525431f, 0.556041f, 0.587338f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000149f, 0.000861f, 0.002312f,
+ 0.004581f, 0.007709f, 0.011713f, 0.016599f, 0.022367f, 0.029014f, 0.036531f, 0.044912f,
+ 0.054148f, 0.064233f, 0.075158f, 0.086918f, 0.099507f, 0.112922f, 0.127157f, 0.142212f,
+ 0.158085f, 0.174776f, 0.192287f, 0.210619f, 0.229775f, 0.249761f, 0.270582f, 0.292243f,
+ 0.314753f, 0.338118f, 0.362347f, 0.387447f, 0.413424f, 0.440284f, 0.468027f, 0.496645f,
+ 0.526122f, 0.556417f, 0.587451f, 0.619048f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000012f, 0.000355f, 0.001353f, 0.003126f,
+ 0.005730f, 0.009194f, 0.013526f, 0.018728f, 0.024795f, 0.031720f, 0.039494f, 0.048109f,
+ 0.057555f, 0.067824f, 0.078909f, 0.090802f, 0.103499f, 0.116993f, 0.131282f, 0.146364f,
+ 0.162237f, 0.178902f, 0.196358f, 0.214610f, 0.233660f, 0.253512f, 0.274174f, 0.295650f,
+ 0.317950f, 0.341081f, 0.365053f, 0.389874f, 0.415553f, 0.442098f, 0.469512f, 0.497794f,
+ 0.526935f, 0.556908f, 0.587657f, 0.619060f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000083f, 0.000665f, 0.001962f, 0.004059f,
+ 0.006997f, 0.010790f, 0.015442f, 0.020949f, 0.027304f, 0.034497f, 0.042518f, 0.051358f,
+ 0.061005f, 0.071451f, 0.082688f, 0.094709f, 0.107507f, 0.121078f, 0.135419f, 0.150526f,
+ 0.166399f, 0.183038f, 0.200443f, 0.218618f, 0.237566f, 0.257291f, 0.277800f, 0.299100f,
+ 0.321199f, 0.344106f, 0.367830f, 0.392383f, 0.417774f, 0.444013f, 0.471107f, 0.499060f,
+ 0.527869f, 0.557517f, 0.587966f, 0.619130f, 0.650794f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000233f, 0.001082f, 0.002688f, 0.005111f,
+ 0.008377f, 0.012493f, 0.017456f, 0.023260f, 0.029893f, 0.037345f, 0.045604f, 0.054659f,
+ 0.064499f, 0.075115f, 0.086498f, 0.098641f, 0.111537f, 0.125182f, 0.139571f, 0.154703f,
+ 0.170576f, 0.187190f, 0.204547f, 0.222648f, 0.241498f, 0.261101f, 0.281465f, 0.302595f,
+ 0.324501f, 0.347192f, 0.370679f, 0.394973f, 0.420085f, 0.446027f, 0.472810f, 0.500441f,
+ 0.528921f, 0.558244f, 0.588384f, 0.619281f, 0.650795f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000033f, 0.000477f, 0.001611f, 0.003532f, 0.006280f,
+ 0.009869f, 0.014301f, 0.019568f, 0.025659f, 0.032563f, 0.040265f, 0.048753f, 0.058016f,
+ 0.068042f, 0.078821f, 0.090344f, 0.102604f, 0.115594f, 0.129309f, 0.143745f, 0.158901f,
+ 0.174774f, 0.191365f, 0.208674f, 0.226705f, 0.245461f, 0.264947f, 0.285170f, 0.306137f,
+ 0.327857f, 0.350341f, 0.373598f, 0.397642f, 0.422485f, 0.448139f, 0.474619f, 0.501933f,
+ 0.530089f, 0.559087f, 0.588913f, 0.619525f, 0.650826f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000130f, 0.000821f, 0.002252f, 0.004491f, 0.007562f,
+ 0.011472f, 0.016213f, 0.021776f, 0.028147f, 0.035312f, 0.043256f, 0.051966f, 0.061430f,
+ 0.071635f, 0.082571f, 0.094229f, 0.106602f, 0.119682f, 0.133465f, 0.147947f, 0.163125f,
+ 0.178998f, 0.195566f, 0.212830f, 0.230793f, 0.249459f, 0.268832f, 0.288920f, 0.309730f,
+ 0.331271f, 0.353554f, 0.376590f, 0.400391f, 0.424973f, 0.450347f, 0.476531f, 0.503535f,
+ 0.531372f, 0.560047f, 0.589554f, 0.619869f, 0.650923f, 0.682540f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000005f, 0.000309f, 0.001270f, 0.003008f, 0.005566f, 0.008959f,
+ 0.013183f, 0.018228f, 0.024080f, 0.030723f, 0.038142f, 0.046321f, 0.055246f, 0.064903f,
+ 0.075281f, 0.086369f, 0.098158f, 0.110639f, 0.123806f, 0.137655f, 0.152180f, 0.167380f,
+ 0.183253f, 0.199799f, 0.217020f, 0.234918f, 0.253496f, 0.272761f, 0.292719f, 0.313377f,
+ 0.334745f, 0.356833f, 0.379654f, 0.403221f, 0.427548f, 0.452651f, 0.478545f, 0.505246f,
+ 0.532768f, 0.561122f, 0.590309f, 0.620318f, 0.651102f, 0.682545f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000053f, 0.000579f, 0.001828f, 0.003878f, 0.006757f, 0.010468f,
+ 0.015002f, 0.020344f, 0.026479f, 0.033388f, 0.041054f, 0.049461f, 0.058594f, 0.068440f,
+ 0.078985f, 0.090220f, 0.102134f, 0.114721f, 0.127972f, 0.141884f, 0.156451f, 0.171672f,
+ 0.187545f, 0.204070f, 0.221249f, 0.239083f, 0.257578f, 0.276738f, 0.296569f, 0.317080f,
+ 0.338281f, 0.360181f, 0.382794f, 0.406133f, 0.430213f, 0.455050f, 0.480662f, 0.507065f,
+ 0.534278f, 0.562313f, 0.591180f, 0.620875f, 0.651373f, 0.682593f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000169f, 0.000949f, 0.002497f, 0.004864f, 0.008063f, 0.012089f,
+ 0.016929f, 0.022563f, 0.028974f, 0.036142f, 0.044049f, 0.052678f, 0.062014f, 0.072042f,
+ 0.082750f, 0.094127f, 0.106164f, 0.118852f, 0.132185f, 0.146157f, 0.160766f, 0.176007f,
+ 0.191880f, 0.208385f, 0.225523f, 0.243296f, 0.261709f, 0.280767f, 0.300476f, 0.320845f,
+ 0.341883f, 0.363601f, 0.386011f, 0.409128f, 0.432967f, 0.457545f, 0.482881f, 0.508992f,
+ 0.535899f, 0.563619f, 0.592165f, 0.621544f, 0.651743f, 0.682709f, 0.714286f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000010f, 0.000368f, 0.001423f, 0.003279f, 0.005966f, 0.009485f, 0.013824f,
+ 0.018964f, 0.024886f, 0.031567f, 0.038988f, 0.047130f, 0.055975f, 0.065508f, 0.075714f,
+ 0.086580f, 0.098095f, 0.110251f, 0.123038f, 0.136450f, 0.150482f, 0.165129f, 0.180390f,
+ 0.196263f, 0.212748f, 0.229847f, 0.247561f, 0.265895f, 0.284854f, 0.304445f, 0.324675f,
+ 0.345555f, 0.367095f, 0.389309f, 0.412210f, 0.435814f, 0.460138f, 0.485203f, 0.511028f,
+ 0.537634f, 0.565041f, 0.593268f, 0.622327f, 0.652217f, 0.682907f, 0.714296f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000068f, 0.000658f, 0.002006f, 0.004178f, 0.007186f, 0.011024f, 0.015672f,
+ 0.021109f, 0.027312f, 0.034259f, 0.041928f, 0.050300f, 0.059356f, 0.069081f, 0.079460f,
+ 0.090480f, 0.102130f, 0.114400f, 0.127284f, 0.140772f, 0.154862f, 0.169548f, 0.184828f,
+ 0.200701f, 0.217167f, 0.234227f, 0.251884f, 0.270141f, 0.289004f, 0.308479f, 0.328575f,
+ 0.349301f, 0.370668f, 0.392689f, 0.415379f, 0.438754f, 0.462830f, 0.487630f, 0.513173f,
+ 0.539482f, 0.566579f, 0.594488f, 0.623226f, 0.652800f, 0.683198f, 0.714354f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000196f, 0.001048f, 0.002702f, 0.005194f, 0.008526f, 0.012680f, 0.017635f,
+ 0.023365f, 0.029846f, 0.037053f, 0.044965f, 0.053561f, 0.062824f, 0.072737f, 0.083284f,
+ 0.094454f, 0.106236f, 0.118619f, 0.131595f, 0.145159f, 0.159305f, 0.174028f, 0.189327f,
+ 0.205200f, 0.221647f, 0.238670f, 0.256270f, 0.274453f, 0.293222f, 0.312585f, 0.332550f,
+ 0.353126f, 0.374324f, 0.396158f, 0.418641f, 0.441790f, 0.465624f, 0.490163f, 0.515429f,
+ 0.541445f, 0.568236f, 0.595828f, 0.624242f, 0.653496f, 0.683588f, 0.714482f, 0.746032f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000012f, 0.000407f, 0.001545f, 0.003514f, 0.006332f, 0.009987f, 0.014457f, 0.019715f,
+ 0.025734f, 0.032488f, 0.039952f, 0.048102f, 0.056919f, 0.066384f, 0.076480f, 0.087193f,
+ 0.098509f, 0.110419f, 0.122912f, 0.135980f, 0.149617f, 0.163817f, 0.178577f, 0.193894f,
+ 0.209767f, 0.226196f, 0.243182f, 0.260728f, 0.278837f, 0.297515f, 0.316768f, 0.336605f,
+ 0.357034f, 0.378067f, 0.399717f, 0.421998f, 0.444928f, 0.468523f, 0.492806f, 0.517798f,
+ 0.543525f, 0.570012f, 0.597288f, 0.625379f, 0.654307f, 0.684084f, 0.714693f, 0.746044f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000074f, 0.000713f, 0.002152f, 0.004446f, 0.007592f, 0.011571f, 0.016356f, 0.021915f,
+ 0.028220f, 0.035243f, 0.042959f, 0.051344f, 0.060377f, 0.070040f, 0.080316f, 0.091191f,
+ 0.102651f, 0.114686f, 0.127286f, 0.140443f, 0.154151f, 0.168405f, 0.183201f, 0.198536f,
+ 0.214409f, 0.230820f, 0.247770f, 0.265263f, 0.283301f, 0.301889f, 0.321035f, 0.340746f,
+ 0.361032f, 0.381904f, 0.403374f, 0.425457f, 0.448169f, 0.471530f, 0.495561f, 0.520284f,
+ 0.545725f, 0.571911f, 0.598873f, 0.626640f, 0.655239f, 0.684692f, 0.714999f, 0.746106f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000208f, 0.001121f, 0.002877f, 0.005501f, 0.008979f, 0.013283f, 0.018380f, 0.024238f,
+ 0.030826f, 0.038115f, 0.046079f, 0.054695f, 0.063941f, 0.073799f, 0.084252f, 0.095285f,
+ 0.106886f, 0.119044f, 0.131749f, 0.144994f, 0.158772f, 0.173078f, 0.187908f, 0.203261f,
+ 0.219134f, 0.235527f, 0.252443f, 0.269883f, 0.287851f, 0.306352f, 0.325393f, 0.344981f,
+ 0.365126f, 0.385839f, 0.407132f, 0.429020f, 0.451520f, 0.474651f, 0.498433f, 0.522890f,
+ 0.548048f, 0.573936f, 0.600584f, 0.628027f, 0.656295f, 0.685417f, 0.715406f, 0.746240f,
+ 0.777778f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000011f,
+ 0.000427f, 0.001638f, 0.003724f, 0.006685f, 0.010497f, 0.015125f, 0.020534f, 0.026688f,
+ 0.033557f, 0.041109f, 0.049318f, 0.058161f, 0.067617f, 0.077666f, 0.088293f, 0.099482f,
+ 0.111221f, 0.123499f, 0.136308f, 0.149639f, 0.163485f, 0.177843f, 0.192707f, 0.208077f,
+ 0.223950f, 0.240326f, 0.257208f, 0.274596f, 0.292496f, 0.310911f, 0.329849f, 0.349316f,
+ 0.369323f, 0.389880f, 0.410999f, 0.432696f, 0.454987f, 0.477890f, 0.501426f, 0.525620f,
+ 0.550498f, 0.576089f, 0.602427f, 0.629544f, 0.657479f, 0.686264f, 0.715924f, 0.746459f,
+ 0.777789f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000071f,
+ 0.000744f, 0.002274f, 0.004698f, 0.008002f, 0.012149f, 0.017102f, 0.022822f, 0.029271f,
+ 0.036417f, 0.044229f, 0.052681f, 0.061749f, 0.071411f, 0.081649f, 0.092447f, 0.103790f,
+ 0.115665f, 0.128062f, 0.140972f, 0.154387f, 0.168301f, 0.182709f, 0.197608f, 0.212994f,
+ 0.228867f, 0.245227f, 0.262074f, 0.279412f, 0.297244f, 0.315575f, 0.334412f, 0.353760f,
+ 0.373631f, 0.394034f, 0.414983f, 0.436491f, 0.458575f, 0.481253f, 0.504547f, 0.528481f,
+ 0.553081f, 0.578377f, 0.604404f, 0.631197f, 0.658795f, 0.687238f, 0.716559f, 0.746776f,
+ 0.777849f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000205f,
+ 0.001168f, 0.003033f, 0.005806f, 0.009456f, 0.013942f, 0.019220f, 0.025250f, 0.031992f,
+ 0.039414f, 0.047484f, 0.056176f, 0.065466f, 0.075333f, 0.085757f, 0.096724f, 0.108218f,
+ 0.120227f, 0.132741f, 0.145751f, 0.159249f, 0.173230f, 0.187687f, 0.202619f, 0.218021f,
+ 0.233894f, 0.250238f, 0.267052f, 0.284341f, 0.302106f, 0.320354f, 0.339090f, 0.358322f,
+ 0.378059f, 0.398311f, 0.419090f, 0.440412f, 0.462292f, 0.484748f, 0.507802f, 0.531477f,
+ 0.555802f, 0.580805f, 0.606522f, 0.632990f, 0.660250f, 0.688346f, 0.717319f, 0.747200f,
+ 0.777982f, 0.809524f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000007f, 0.000427f,
+ 0.001710f, 0.003925f, 0.007054f, 0.011055f, 0.015881f, 0.021485f, 0.027824f, 0.034859f,
+ 0.042554f, 0.050881f, 0.059811f, 0.069321f, 0.079390f, 0.089998f, 0.101132f, 0.112775f,
+ 0.124917f, 0.137547f, 0.150655f, 0.164236f, 0.178281f, 0.192788f, 0.207752f, 0.223171f,
+ 0.239044f, 0.255371f, 0.272153f, 0.289393f, 0.307093f, 0.325259f, 0.343896f, 0.363012f,
+ 0.382617f, 0.402719f, 0.423332f, 0.444469f, 0.466146f, 0.488383f, 0.511199f, 0.534618f,
+ 0.558668f, 0.583380f, 0.608787f, 0.634929f, 0.661849f, 0.689594f, 0.718211f, 0.747742f,
+ 0.778205f, 0.809530f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000059f, 0.000754f,
+ 0.002379f, 0.004956f, 0.008449f, 0.012806f, 0.017974f, 0.023905f, 0.030553f, 0.037879f,
+ 0.045847f, 0.054429f, 0.063595f, 0.073323f, 0.083592f, 0.094384f, 0.105682f, 0.117474f,
+ 0.129747f, 0.142491f, 0.155697f, 0.169358f, 0.183469f, 0.198024f, 0.213020f, 0.228455f,
+ 0.244329f, 0.260639f, 0.277389f, 0.294580f, 0.312216f, 0.330300f, 0.348840f, 0.367842f,
+ 0.387315f, 0.407270f, 0.427717f, 0.448671f, 0.470149f, 0.492167f, 0.514746f, 0.537911f,
+ 0.561688f, 0.586108f, 0.611206f, 0.637022f, 0.663599f, 0.690989f, 0.719242f, 0.748411f,
+ 0.778531f, 0.809583f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000187f, 0.001196f,
+ 0.003184f, 0.006136f, 0.010000f, 0.014716f, 0.020230f, 0.026488f, 0.033445f, 0.041062f,
+ 0.049303f, 0.058138f, 0.067540f, 0.077485f, 0.087953f, 0.098926f, 0.110388f, 0.122327f,
+ 0.134729f, 0.147587f, 0.160889f, 0.174631f, 0.188806f, 0.203409f, 0.218437f, 0.233888f,
+ 0.249761f, 0.266056f, 0.282774f, 0.299917f, 0.317488f, 0.335493f, 0.353936f, 0.372825f,
+ 0.392168f, 0.411976f, 0.432259f, 0.453032f, 0.474310f, 0.496111f, 0.518456f, 0.541367f,
+ 0.564872f, 0.589001f, 0.613789f, 0.639277f, 0.665510f, 0.692539f, 0.720422f, 0.749216f,
+ 0.778974f, 0.809711f, 0.841270f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000002f, 0.000409f, 0.001767f,
+ 0.004137f, 0.007474f, 0.011716f, 0.016797f, 0.022657f, 0.029244f, 0.036512f, 0.044420f,
+ 0.052933f, 0.062021f, 0.071657f, 0.081819f, 0.092485f, 0.103638f, 0.115263f, 0.127348f,
+ 0.139880f, 0.152849f, 0.166248f, 0.180070f, 0.194308f, 0.208958f, 0.224018f, 0.239485f,
+ 0.255359f, 0.271638f, 0.288324f, 0.305419f, 0.322927f, 0.340851f, 0.359199f, 0.377975f,
+ 0.397189f, 0.416851f, 0.436971f, 0.457564f, 0.478644f, 0.500229f, 0.522339f, 0.544997f,
+ 0.568230f, 0.592068f, 0.616546f, 0.641705f, 0.667590f, 0.694255f, 0.721760f, 0.750168f,
+ 0.779545f, 0.809933f, 0.841272f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000041f, 0.000744f, 0.002481f,
+ 0.005248f, 0.008982f, 0.013608f, 0.019058f, 0.025269f, 0.032188f, 0.039767f, 0.047967f,
+ 0.056752f, 0.066093f, 0.075963f, 0.086340f, 0.097203f, 0.108537f, 0.120325f, 0.132554f,
+ 0.145215f, 0.158296f, 0.171790f, 0.185691f, 0.199993f, 0.214691f, 0.229782f, 0.245265f,
+ 0.261138f, 0.277401f, 0.294056f, 0.311104f, 0.328548f, 0.346394f, 0.364645f, 0.383310f,
+ 0.402396f, 0.421912f, 0.441870f, 0.462283f, 0.483165f, 0.504535f, 0.526410f, 0.548816f,
+ 0.571776f, 0.595323f, 0.619489f, 0.644317f, 0.669852f, 0.696148f, 0.723267f, 0.751280f,
+ 0.780258f, 0.810268f, 0.841311f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000156f, 0.001209f, 0.003349f,
+ 0.006531f, 0.010672f, 0.015691f, 0.021515f, 0.028080f, 0.035332f, 0.043225f, 0.051717f,
+ 0.060775f, 0.070370f, 0.080474f, 0.091067f, 0.102128f, 0.113641f, 0.125591f, 0.137965f,
+ 0.150754f, 0.163947f, 0.177537f, 0.191516f, 0.205881f, 0.220626f, 0.235749f, 0.251248f,
+ 0.267121f, 0.283368f, 0.299992f, 0.316992f, 0.334374f, 0.352140f, 0.370296f, 0.388849f,
+ 0.407807f, 0.427178f, 0.446974f, 0.467207f, 0.487892f, 0.509046f, 0.530687f, 0.552839f,
+ 0.575527f, 0.598780f, 0.622634f, 0.647128f, 0.672308f, 0.698231f, 0.724958f, 0.752563f,
+ 0.781127f, 0.810733f, 0.841426f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000374f, 0.001821f, 0.004389f,
+ 0.008001f, 0.012559f, 0.017979f, 0.024182f, 0.031106f, 0.038695f, 0.046903f, 0.055690f,
+ 0.065023f, 0.074872f, 0.085211f, 0.096020f, 0.107279f, 0.118971f, 0.131084f, 0.143604f,
+ 0.156521f, 0.169825f, 0.183510f, 0.197569f, 0.211997f, 0.226789f, 0.241944f, 0.257458f,
+ 0.273331f, 0.289563f, 0.306154f, 0.323108f, 0.340426f, 0.358113f, 0.376175f, 0.394616f,
+ 0.413445f, 0.432671f, 0.452305f, 0.472358f, 0.492845f, 0.513783f, 0.535189f, 0.557087f,
+ 0.579500f, 0.602459f, 0.625997f, 0.650154f, 0.674976f, 0.700518f, 0.726845f, 0.754032f,
+ 0.782167f, 0.811344f, 0.841644f, 0.873016f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000020f, 0.000719f, 0.002598f, 0.005618f,
+ 0.009675f, 0.014663f, 0.020490f, 0.027080f, 0.034367f, 0.042297f, 0.050824f, 0.059909f,
+ 0.069517f, 0.079622f, 0.090198f, 0.101224f, 0.112682f, 0.124555f, 0.136831f, 0.149496f,
+ 0.162542f, 0.175958f, 0.189739f, 0.203877f, 0.218368f, 0.233208f, 0.248393f, 0.263923f,
+ 0.279796f, 0.296012f, 0.312573f, 0.329479f, 0.346734f, 0.364342f, 0.382307f, 0.400637f,
+ 0.419337f, 0.438418f, 0.457889f, 0.477761f, 0.498050f, 0.518770f, 0.539940f, 0.561581f,
+ 0.583718f, 0.606380f, 0.629599f, 0.653415f, 0.677874f, 0.703030f, 0.728948f, 0.755706f,
+ 0.783396f, 0.812121f, 0.841989f, 0.873035f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000114f, 0.001215f, 0.003561f, 0.007056f,
+ 0.011574f, 0.017003f, 0.023248f, 0.030232f, 0.037888f, 0.046164f, 0.055014f, 0.064399f,
+ 0.074287f, 0.084650f, 0.095464f, 0.106709f, 0.118367f, 0.130423f, 0.142862f, 0.155674f,
+ 0.168849f, 0.182378f, 0.196255f, 0.210473f, 0.225027f, 0.239915f, 0.255132f, 0.270678f,
+ 0.286551f, 0.302751f, 0.319280f, 0.336138f, 0.353330f, 0.370858f, 0.388728f, 0.406944f,
+ 0.425515f, 0.444449f, 0.463756f, 0.483447f, 0.503535f, 0.524036f, 0.544968f, 0.566350f,
+ 0.588208f, 0.610569f, 0.633466f, 0.656936f, 0.681025f, 0.705788f, 0.731289f, 0.757606f,
+ 0.784834f, 0.813085f, 0.842485f, 0.873130f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000324f, 0.001887f, 0.004735f, 0.008727f,
+ 0.013724f, 0.019607f, 0.026280f, 0.033666f, 0.041699f, 0.050326f, 0.059504f, 0.069194f,
+ 0.079365f, 0.089989f, 0.101045f, 0.112512f, 0.124372f, 0.136611f, 0.149216f, 0.162176f,
+ 0.175482f, 0.189125f, 0.203098f, 0.217396f, 0.232015f, 0.246950f, 0.262200f, 0.277761f,
+ 0.293634f, 0.309819f, 0.326315f, 0.343126f, 0.360254f, 0.377701f, 0.395474f, 0.413577f,
+ 0.432018f, 0.450804f, 0.469944f, 0.489451f, 0.509337f, 0.529617f, 0.550307f, 0.571428f,
+ 0.593003f, 0.615059f, 0.637628f, 0.660746f, 0.684460f, 0.708820f, 0.733893f, 0.759756f,
+ 0.786505f, 0.814259f, 0.843157f, 0.873340f, 0.904762f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000003f, 0.000683f, 0.002764f, 0.006148f, 0.010661f,
+ 0.016155f, 0.022506f, 0.029620f, 0.037417f, 0.045835f, 0.054821f, 0.064333f, 0.074333f,
+ 0.084792f, 0.095683f, 0.106984f, 0.118675f, 0.130741f, 0.143166f, 0.155939f, 0.169049f,
+ 0.182487f, 0.196245f, 0.210317f, 0.224697f, 0.239380f, 0.254364f, 0.269646f, 0.285223f,
+ 0.301096f, 0.317265f, 0.333729f, 0.350491f, 0.367554f, 0.384920f, 0.402594f, 0.420582f,
+ 0.438891f, 0.457527f, 0.476499f, 0.495820f, 0.515500f, 0.535555f, 0.556000f, 0.576855f,
+ 0.598143f, 0.619888f, 0.642123f, 0.664883f, 0.688211f, 0.712160f, 0.736792f, 0.762186f,
+ 0.788439f, 0.815672f, 0.844034f, 0.873699f, 0.904765f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000066f, 0.001228f, 0.003880f, 0.007835f, 0.012895f,
+ 0.018905f, 0.025742f, 0.033309f, 0.041530f, 0.050342f, 0.059696f, 0.069550f, 0.079868f,
+ 0.090620f, 0.101783f, 0.113333f, 0.125254f, 0.137529f, 0.150144f, 0.163088f, 0.176351f,
+ 0.189924f, 0.203799f, 0.217970f, 0.232433f, 0.247182f, 0.262216f, 0.277530f, 0.293124f,
+ 0.308997f, 0.325149f, 0.341581f, 0.358294f, 0.375290f, 0.392573f, 0.410148f, 0.428019f,
+ 0.446192f, 0.464676f, 0.483478f, 0.502608f, 0.522079f, 0.541905f, 0.562100f, 0.582684f,
+ 0.603677f, 0.625106f, 0.646998f, 0.669390f, 0.692324f, 0.715849f, 0.740028f, 0.764937f,
+ 0.790673f, 0.817358f, 0.845150f, 0.874244f, 0.904828f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000260f, 0.002001f, 0.005278f, 0.009840f, 0.015475f,
+ 0.022025f, 0.029365f, 0.037402f, 0.046060f, 0.055280f, 0.065013f, 0.075218f, 0.085861f,
+ 0.096916f, 0.108356f, 0.120163f, 0.132319f, 0.144808f, 0.157618f, 0.170737f, 0.184155f,
+ 0.197866f, 0.211861f, 0.226134f, 0.240682f, 0.255499f, 0.270583f, 0.285931f, 0.301542f,
+ 0.317415f, 0.333550f, 0.349948f, 0.366610f, 0.383539f, 0.400738f, 0.418210f, 0.435961f,
+ 0.453997f, 0.472324f, 0.490951f, 0.509887f, 0.529144f, 0.548735f, 0.568674f, 0.588979f,
+ 0.609671f, 0.630773f, 0.652314f, 0.674328f, 0.696854f, 0.719942f, 0.743651f, 0.768057f,
+ 0.793253f, 0.819363f, 0.846547f, 0.875017f, 0.905021f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000642f, 0.003053f, 0.007010f, 0.012219f, 0.018462f,
+ 0.025577f, 0.033444f, 0.041970f, 0.051082f, 0.060724f, 0.070849f, 0.081417f, 0.092397f,
+ 0.103763f, 0.115491f, 0.127562f, 0.139960f, 0.152670f, 0.165679f, 0.178979f, 0.192558f,
+ 0.206410f, 0.220529f, 0.234907f, 0.249542f, 0.264428f, 0.279564f, 0.294947f, 0.310575f,
+ 0.326448f, 0.342566f, 0.358929f, 0.375540f, 0.392399f, 0.409511f, 0.426878f, 0.444506f,
+ 0.462400f, 0.480566f, 0.499013f, 0.517749f, 0.536785f, 0.556134f, 0.575809f, 0.595827f,
+ 0.616207f, 0.636973f, 0.658150f, 0.679772f, 0.701876f, 0.724509f, 0.747730f, 0.771609f,
+ 0.796240f, 0.821743f, 0.848280f, 0.876069f, 0.905404f, 0.936508f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000020f, 0.001278f, 0.004450f, 0.009147f, 0.015050f, 0.021937f,
+ 0.029649f, 0.038068f, 0.047106f, 0.056694f, 0.066777f, 0.077310f, 0.088257f, 0.099588f,
+ 0.111277f, 0.123304f, 0.135650f, 0.148299f, 0.161237f, 0.174455f, 0.187941f, 0.201687f,
+ 0.215687f, 0.229933f, 0.244420f, 0.259145f, 0.274103f, 0.289293f, 0.304711f, 0.320357f,
+ 0.336230f, 0.352330f, 0.368658f, 0.385214f, 0.402002f, 0.419023f, 0.436282f, 0.453782f,
+ 0.471529f, 0.489528f, 0.507788f, 0.526317f, 0.545124f, 0.564221f, 0.583621f, 0.603341f,
+ 0.623397f, 0.643812f, 0.664611f, 0.685824f, 0.707488f, 0.729646f, 0.752354f, 0.775680f,
+ 0.799715f, 0.824574f, 0.850417f, 0.877466f, 0.906040f, 0.936528f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000183f, 0.002253f, 0.006282f, 0.011786f, 0.018436f, 0.026011f,
+ 0.034358f, 0.043364f, 0.052944f, 0.063033f, 0.073580f, 0.084544f, 0.095889f, 0.107588f,
+ 0.119617f, 0.131957f, 0.144591f, 0.157503f, 0.170682f, 0.184117f, 0.197799f, 0.211720f,
+ 0.225873f, 0.240253f, 0.254854f, 0.269673f, 0.284707f, 0.299953f, 0.315408f, 0.331073f,
+ 0.346946f, 0.363028f, 0.379318f, 0.395818f, 0.412530f, 0.429457f, 0.446602f, 0.463968f,
+ 0.481561f, 0.499386f, 0.517450f, 0.535761f, 0.554328f, 0.573162f, 0.592275f, 0.611681f,
+ 0.631398f, 0.651445f, 0.671845f, 0.692628f, 0.713827f, 0.735484f, 0.757650f, 0.780390f,
+ 0.803789f, 0.827960f, 0.853056f, 0.879298f, 0.907014f, 0.936691f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000617f, 0.003679f, 0.008674f, 0.015068f, 0.022531f, 0.030851f,
+ 0.039880f, 0.049515f, 0.059675f, 0.070300f, 0.081343f, 0.092764f, 0.104533f, 0.116624f,
+ 0.129015f, 0.141687f, 0.154626f, 0.167818f, 0.181252f, 0.194918f, 0.208807f, 0.222913f,
+ 0.237229f, 0.251750f, 0.266473f, 0.281392f, 0.296505f, 0.311811f, 0.327306f, 0.342991f,
+ 0.358864f, 0.374925f, 0.391176f, 0.407616f, 0.424249f, 0.441076f, 0.458100f, 0.475324f,
+ 0.492754f, 0.510394f, 0.528251f, 0.546331f, 0.564644f, 0.583198f, 0.602005f, 0.621078f,
+ 0.640434f, 0.660089f, 0.680066f, 0.700390f, 0.721094f, 0.742215f, 0.763800f, 0.785912f,
+ 0.808628f, 0.832055f, 0.856338f, 0.881690f, 0.908441f, 0.937125f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000000f, 0.001477f, 0.005732f, 0.011826f, 0.019212f, 0.027573f, 0.036710f,
+ 0.046487f, 0.056807f, 0.067598f, 0.078806f, 0.090386f, 0.102304f, 0.114532f, 0.127047f,
+ 0.139828f, 0.152861f, 0.166130f, 0.179624f, 0.193332f, 0.207247f, 0.221360f, 0.235666f,
+ 0.250158f, 0.264832f, 0.279684f, 0.294711f, 0.309911f, 0.325280f, 0.340819f, 0.356524f,
+ 0.372397f, 0.388438f, 0.404645f, 0.421022f, 0.437569f, 0.454287f, 0.471181f, 0.488253f,
+ 0.505507f, 0.522947f, 0.540580f, 0.558412f, 0.576449f, 0.594701f, 0.613178f, 0.631892f,
+ 0.650856f, 0.670088f, 0.689606f, 0.709434f, 0.729600f, 0.750138f, 0.771093f, 0.792519f,
+ 0.814488f, 0.837097f, 0.860481f, 0.884842f, 0.910494f, 0.937985f, 0.968254f, 1.000000f,
+ 0.000000f, 0.000096f, 0.003012f, 0.008704f, 0.016071f, 0.024590f, 0.033968f, 0.044025f,
+ 0.054641f, 0.065728f, 0.077225f, 0.089081f, 0.101260f, 0.113731f, 0.126469f, 0.139454f,
+ 0.152670f, 0.166101f, 0.179736f, 0.193565f, 0.207578f, 0.221769f, 0.236130f, 0.250656f,
+ 0.265343f, 0.280187f, 0.295183f, 0.310330f, 0.325624f, 0.341065f, 0.356650f, 0.372380f,
+ 0.388253f, 0.404269f, 0.420430f, 0.436735f, 0.453187f, 0.469786f, 0.486536f, 0.503439f,
+ 0.520498f, 0.537717f, 0.555102f, 0.572657f, 0.590390f, 0.608307f, 0.626419f, 0.644733f,
+ 0.663264f, 0.682025f, 0.701032f, 0.720308f, 0.739875f, 0.759764f, 0.780014f, 0.800673f,
+ 0.821803f, 0.843492f, 0.865860f, 0.889087f, 0.913466f, 0.939520f, 0.968350f, 1.000000f,
+ 0.000000f, 0.000727f, 0.005696f, 0.013170f, 0.022074f, 0.031940f, 0.042520f, 0.053660f,
+ 0.065258f, 0.077243f, 0.089562f, 0.102175f, 0.115050f, 0.128164f, 0.141495f, 0.155026f,
+ 0.168745f, 0.182639f, 0.196699f, 0.210915f, 0.225282f, 0.239792f, 0.254440f, 0.269223f,
+ 0.284135f, 0.299174f, 0.314337f, 0.329622f, 0.345026f, 0.360549f, 0.376189f, 0.391946f,
+ 0.407819f, 0.423808f, 0.439914f, 0.456137f, 0.472479f, 0.488940f, 0.505523f, 0.522230f,
+ 0.539064f, 0.556028f, 0.573125f, 0.590361f, 0.607741f, 0.625270f, 0.642957f, 0.660809f,
+ 0.678836f, 0.697050f, 0.715465f, 0.734098f, 0.752968f, 0.772101f, 0.791529f, 0.811290f,
+ 0.831438f, 0.852044f, 0.873210f, 0.895090f, 0.917932f, 0.942204f, 0.968981f, 1.000000f,
+ 0.000000f, 0.002796f, 0.010764f, 0.020645f, 0.031576f, 0.043202f, 0.055340f, 0.067877f,
+ 0.080740f, 0.093877f, 0.107250f, 0.120832f, 0.134598f, 0.148533f, 0.162620f, 0.176849f,
+ 0.191210f, 0.205694f, 0.220294f, 0.235005f, 0.249820f, 0.264737f, 0.279751f, 0.294859f,
+ 0.310058f, 0.325346f, 0.340721f, 0.356181f, 0.371725f, 0.387353f, 0.403063f, 0.418854f,
+ 0.434727f, 0.450682f, 0.466718f, 0.482837f, 0.499038f, 0.515324f, 0.531695f, 0.548153f,
+ 0.564700f, 0.581338f, 0.598070f, 0.614900f, 0.631830f, 0.648865f, 0.666011f, 0.683273f,
+ 0.700659f, 0.718176f, 0.735834f, 0.753646f, 0.771625f, 0.789790f, 0.808162f, 0.826771f,
+ 0.845654f, 0.864863f, 0.884472f, 0.904592f, 0.925407f, 0.947271f, 0.971050f, 1.000000f,
+ 0.000000f, 0.015873f, 0.031746f, 0.047619f, 0.063492f, 0.079365f, 0.095238f, 0.111111f,
+ 0.126984f, 0.142857f, 0.158730f, 0.174603f, 0.190476f, 0.206349f, 0.222222f, 0.238095f,
+ 0.253968f, 0.269841f, 0.285714f, 0.301587f, 0.317460f, 0.333333f, 0.349206f, 0.365079f,
+ 0.380952f, 0.396825f, 0.412698f, 0.428571f, 0.444444f, 0.460317f, 0.476190f, 0.492063f,
+ 0.507937f, 0.523810f, 0.539683f, 0.555556f, 0.571429f, 0.587302f, 0.603175f, 0.619048f,
+ 0.634921f, 0.650794f, 0.666667f, 0.682540f, 0.698413f, 0.714286f, 0.730159f, 0.746032f,
+ 0.761905f, 0.777778f, 0.793651f, 0.809524f, 0.825397f, 0.841270f, 0.857143f, 0.873016f,
+ 0.888889f, 0.904762f, 0.920635f, 0.936508f, 0.952381f, 0.968254f, 0.984127f, 1.000000f
+};
+
+static float btdf_split_sum_ggx[32][64 * 64] = {
+ {
+ 0.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f,
+ 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 0.999512f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.039917f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.999512f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ },
+ {
+ 0.000122f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000122f, 0.004147f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.897949f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000732f, 0.996094f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.002439f,
+ 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000366f, 0.078308f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.001098f, 0.992188f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.005001f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000732f, 0.902344f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.002928f, 0.997070f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 1.000000f, 0.999512f, 0.999512f, 1.000000f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000732f, 0.301758f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f, 1.000000f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.002562f, 0.996094f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000732f, 0.433594f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000244f, 0.004021f, 0.996582f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.001098f, 0.949219f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000610f,
+ 0.012039f, 0.998047f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.002073f, 0.993652f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000854f, 0.725586f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000610f, 0.011856f, 0.998047f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.002905f, 0.995117f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.001098f, 0.978027f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000732f, 0.314941f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000731f, 0.017670f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000366f, 0.005852f, 0.997559f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.003050f,
+ 0.996094f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.001957f, 0.993652f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.001586f, 0.990234f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.001220f, 0.986816f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.001220f, 0.984375f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f,
+ 0.001098f, 0.985352f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.001220f, 0.989258f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.001341f, 0.993652f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.001586f, 0.996094f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.002802f, 0.997559f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000117f, 0.000122f, 0.000122f,
+ 0.000243f, 0.006088f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000366f, 0.026321f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000732f, 0.892578f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000975f, 0.993652f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.002317f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.017944f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000731f, 0.983887f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000122f, 0.000122f, 0.001653f, 0.998535f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.026108f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000732f, 0.995605f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.003777f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000365f, 0.991211f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.002195f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000364f, 0.993164f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.002672f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000360f, 0.998047f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.017075f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000731f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.997070f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.006874f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000480f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.996582f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000067f, 0.005440f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000365f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.995605f, 0.995117f,
+ 0.995117f, 0.995605f, 0.995117f, 0.995117f,
+ },
+ {
+ 0.003168f, 0.995605f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000976f, 0.053314f, 0.994629f, 0.998535f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000122f, 0.000122f, 0.000732f, 0.003660f,
+ 0.653809f, 0.995117f, 0.998047f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000488f, 0.001463f, 0.010452f, 0.947266f, 0.995605f, 0.998535f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000365f, 0.000853f, 0.002928f, 0.037750f,
+ 0.980957f, 0.996582f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000243f, 0.000610f, 0.001342f, 0.006100f, 0.314453f, 0.989746f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000487f, 0.001091f, 0.002317f, 0.015839f, 0.910645f,
+ 0.993652f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000366f, 0.000732f, 0.001463f, 0.005302f, 0.068909f, 0.977539f, 0.995605f, 0.998047f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000732f, 0.001098f, 0.002560f, 0.011551f, 0.658691f, 0.989746f,
+ 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000366f,
+ 0.000732f, 0.001585f, 0.004868f, 0.041077f, 0.958984f, 0.994141f, 0.997559f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000732f, 0.001215f, 0.002802f, 0.010834f, 0.441895f, 0.987305f, 0.996094f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000242f, 0.000488f, 0.000850f,
+ 0.001586f, 0.004753f, 0.039154f, 0.948242f, 0.993652f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000366f, 0.000732f, 0.001220f, 0.003159f, 0.012032f, 0.480713f, 0.985840f, 0.996094f, 0.998047f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000240f, 0.000731f, 0.001097f, 0.001950f,
+ 0.005966f, 0.054413f, 0.957520f, 0.994141f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000486f, 0.000732f, 0.001534f, 0.003536f, 0.016937f, 0.726562f, 0.988281f, 0.996582f, 0.998047f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000365f, 0.000732f, 0.001098f, 0.002192f, 0.008278f,
+ 0.125244f, 0.974121f, 0.994629f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000365f, 0.000731f, 0.000947f, 0.001828f, 0.005314f, 0.031677f, 0.916016f, 0.991699f, 0.997070f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000488f, 0.000732f, 0.001339f, 0.003294f, 0.014389f, 0.562012f,
+ 0.985840f, 0.996094f, 0.998047f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000487f,
+ 0.000732f, 0.001098f, 0.002310f, 0.008163f, 0.123779f, 0.973633f, 0.994629f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000365f, 0.000732f, 0.001097f, 0.002071f, 0.005669f, 0.041199f, 0.937988f, 0.992676f,
+ 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000118f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000366f, 0.000728f, 0.000732f,
+ 0.001585f, 0.004143f, 0.020813f, 0.813965f, 0.989746f, 0.996582f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000116f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000488f, 0.000732f, 0.001220f, 0.003292f, 0.012581f, 0.446533f, 0.984863f, 0.996094f, 0.998047f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000471f, 0.000732f, 0.001220f, 0.002796f,
+ 0.009338f, 0.161865f, 0.977051f, 0.995117f, 0.997559f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000365f, 0.000732f, 0.001098f, 0.002285f, 0.006870f, 0.074097f, 0.965820f, 0.994141f, 0.997559f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000366f, 0.000731f, 0.001086f, 0.001945f, 0.005238f, 0.043732f,
+ 0.947754f, 0.993652f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000366f,
+ 0.000730f, 0.000893f, 0.001826f, 0.004871f, 0.030411f, 0.922852f, 0.992188f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000609f, 0.000732f, 0.001407f, 0.004375f, 0.023758f, 0.892090f, 0.992188f,
+ 0.997070f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000605f, 0.000732f,
+ 0.001579f, 0.003941f, 0.020767f, 0.862793f, 0.991699f, 0.997559f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000238f, 0.000483f, 0.000732f, 0.001449f, 0.003654f, 0.018951f, 0.847656f, 0.991699f, 0.997559f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000233f, 0.000485f, 0.000732f, 0.001308f, 0.003353f,
+ 0.018997f, 0.855469f, 0.991699f, 0.997559f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000118f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000487f, 0.000732f, 0.001292f, 0.003649f, 0.019791f, 0.881836f, 0.992188f, 0.997559f, 0.998535f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000432f, 0.000732f, 0.001220f, 0.003635f, 0.021912f, 0.916992f,
+ 0.993652f, 0.997559f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000116f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000487f,
+ 0.000732f, 0.001245f, 0.004002f, 0.028107f, 0.946289f, 0.994141f, 0.998047f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000085f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000475f, 0.000732f, 0.001611f, 0.004581f, 0.040466f, 0.966309f, 0.995605f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000487f, 0.000732f, 0.001703f,
+ 0.005589f, 0.073486f, 0.979980f, 0.996094f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000475f, 0.000732f, 0.001706f, 0.006809f, 0.198730f, 0.987305f, 0.997559f, 0.998535f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000488f, 0.000732f, 0.002071f, 0.009590f, 0.647949f,
+ 0.992188f, 0.997559f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000710f, 0.001093f, 0.002541f, 0.015533f, 0.922852f, 0.995117f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000116f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000242f, 0.000728f, 0.001218f, 0.003387f, 0.034454f, 0.975586f, 0.996582f, 0.998535f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000365f, 0.000731f, 0.001219f,
+ 0.004959f, 0.161865f, 0.989746f, 0.998047f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000366f, 0.000731f, 0.001767f, 0.009331f, 0.849121f, 0.994629f, 0.998535f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000487f, 0.000732f, 0.002644f, 0.024231f, 0.977051f,
+ 0.997559f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000685f, 0.001217f, 0.004139f, 0.195435f, 0.992676f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000362f, 0.000731f, 0.001570f, 0.010086f, 0.944824f, 0.997070f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000365f, 0.000745f, 0.002781f,
+ 0.051758f, 0.990723f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000599f, 0.001176f, 0.006641f, 0.899414f, 0.997070f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000731f, 0.002066f, 0.032654f, 0.991211f, 0.998535f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000448f,
+ 0.001088f, 0.005440f, 0.918457f, 0.997070f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000725f, 0.001822f, 0.038452f, 0.994141f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000329f, 0.000848f, 0.005672f, 0.972168f,
+ 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000581f, 0.001982f, 0.155273f, 0.997070f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000330f, 0.000848f, 0.009247f, 0.992676f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000589f, 0.002625f,
+ 0.958496f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.001199f, 0.083374f, 0.998047f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000716f, 0.007244f, 0.996582f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f,
+ 0.002277f, 0.991211f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000070f, 0.000121f, 0.000122f, 0.000122f, 0.000854f, 0.950684f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000111f, 0.000121f, 0.000122f, 0.000475f, 0.067139f, 0.999512f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000118f, 0.000122f,
+ 0.000002f, 0.005859f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000014f, 0.001376f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000572f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000077f, 0.000002f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000103f, 0.992188f, 0.991699f, 0.991699f, 0.992188f, 0.992188f, 0.991699f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.940430f, 0.940430f,
+ 0.940918f, 0.940918f, 0.940430f, 0.940430f,
+ },
+ {
+ 0.014023f, 0.979492f, 0.994629f, 0.997070f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000488f, 0.004757f, 0.163330f, 0.975098f, 0.993164f, 0.996582f, 0.997559f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000610f, 0.002928f, 0.017166f,
+ 0.563965f, 0.978027f, 0.992676f, 0.996094f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000364f, 0.000732f, 0.002192f, 0.006573f, 0.044952f, 0.830566f, 0.980957f, 0.992676f, 0.996094f, 0.997070f, 0.998047f,
+ 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 1.000000f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000366f, 0.000854f, 0.001586f, 0.004253f, 0.014313f, 0.130371f,
+ 0.919922f, 0.984375f, 0.993652f, 0.996094f, 0.997070f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000488f,
+ 0.000854f, 0.001342f, 0.003025f, 0.007305f, 0.028870f, 0.407715f, 0.954590f, 0.987305f, 0.993652f, 0.996094f, 0.997070f, 0.998047f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000609f, 0.000842f, 0.000976f, 0.002193f, 0.005112f, 0.012505f, 0.066589f, 0.768066f,
+ 0.970703f, 0.989746f, 0.994629f, 0.996582f, 0.997070f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000244f, 0.000599f, 0.000609f, 0.000976f,
+ 0.001829f, 0.003046f, 0.007256f, 0.023499f, 0.194946f, 0.908691f, 0.979980f, 0.991699f, 0.995117f, 0.996582f, 0.997559f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000244f, 0.000488f, 0.000609f, 0.000976f, 0.001583f, 0.002647f, 0.004726f, 0.012169f, 0.050537f, 0.568359f, 0.954102f,
+ 0.985840f, 0.993164f, 0.995605f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000488f, 0.000610f, 0.000975f, 0.001211f, 0.001946f,
+ 0.003532f, 0.007793f, 0.022446f, 0.139648f, 0.856445f, 0.974121f, 0.989746f, 0.994141f, 0.996094f, 0.997559f, 0.998047f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000241f,
+ 0.000310f, 0.000609f, 0.000807f, 0.001098f, 0.001822f, 0.002794f, 0.005699f, 0.012878f, 0.047821f, 0.469238f, 0.941406f, 0.982910f,
+ 0.991699f, 0.995117f, 0.996582f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000244f, 0.000609f, 0.000732f, 0.001098f, 0.001461f, 0.002274f, 0.004025f,
+ 0.008247f, 0.023254f, 0.135254f, 0.833984f, 0.969727f, 0.987793f, 0.993652f, 0.995605f, 0.997070f, 0.998047f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000207f, 0.000244f, 0.000609f,
+ 0.000610f, 0.001096f, 0.001098f, 0.002071f, 0.003370f, 0.006172f, 0.014442f, 0.052795f, 0.486572f, 0.940430f, 0.981934f, 0.991699f,
+ 0.994629f, 0.996582f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000485f, 0.000610f, 0.001080f, 0.001098f, 0.001742f, 0.002668f, 0.004692f, 0.010147f,
+ 0.028076f, 0.168701f, 0.854004f, 0.970703f, 0.988770f, 0.993652f, 0.996094f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000487f, 0.000610f, 0.000731f,
+ 0.001098f, 0.001413f, 0.002411f, 0.003895f, 0.007072f, 0.017242f, 0.069580f, 0.605957f, 0.948730f, 0.983398f, 0.992188f, 0.995117f,
+ 0.996582f, 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000244f, 0.000244f, 0.000609f, 0.000610f, 0.001094f, 0.001337f, 0.001828f, 0.003275f, 0.005814f, 0.012054f, 0.036987f,
+ 0.270752f, 0.899414f, 0.975586f, 0.989746f, 0.993652f, 0.996094f, 0.997070f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000241f, 0.000365f, 0.000597f, 0.000610f, 0.000970f, 0.001098f,
+ 0.001815f, 0.002771f, 0.005009f, 0.008888f, 0.023804f, 0.115845f, 0.775879f, 0.962891f, 0.986328f, 0.993164f, 0.995605f, 0.997070f,
+ 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000244f, 0.000536f, 0.000731f, 0.000937f, 0.001203f, 0.001581f, 0.002186f, 0.004005f, 0.007061f, 0.016830f, 0.061218f, 0.522949f,
+ 0.940430f, 0.981934f, 0.991211f, 0.994629f, 0.996582f, 0.997559f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000363f, 0.000487f, 0.000731f, 0.000732f, 0.001097f, 0.001339f, 0.002071f,
+ 0.003498f, 0.005947f, 0.012390f, 0.037964f, 0.268799f, 0.896973f, 0.975586f, 0.989258f, 0.994141f, 0.996094f, 0.997070f, 0.998047f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000366f,
+ 0.000609f, 0.000610f, 0.001094f, 0.001215f, 0.002056f, 0.003183f, 0.004742f, 0.009880f, 0.026337f, 0.139526f, 0.813477f, 0.966309f,
+ 0.986816f, 0.993164f, 0.996094f, 0.997070f, 0.997559f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000163f, 0.000363f, 0.000600f, 0.000731f, 0.001088f, 0.001216f, 0.001616f, 0.002640f, 0.004402f,
+ 0.008156f, 0.019669f, 0.083191f, 0.664062f, 0.953125f, 0.984375f, 0.992188f, 0.995117f, 0.997070f, 0.998047f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000244f, 0.000523f, 0.000731f,
+ 0.000732f, 0.001097f, 0.001690f, 0.002169f, 0.003998f, 0.006939f, 0.015808f, 0.055634f, 0.471191f, 0.935059f, 0.980957f, 0.991211f,
+ 0.995117f, 0.996582f, 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000336f, 0.000486f, 0.000731f, 0.000732f, 0.001097f, 0.001558f, 0.002069f, 0.003525f, 0.006058f, 0.013062f,
+ 0.040894f, 0.306396f, 0.910156f, 0.978027f, 0.990234f, 0.994141f, 0.996582f, 0.997559f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000113f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000360f, 0.000515f, 0.000731f, 0.000731f, 0.001094f,
+ 0.001219f, 0.002148f, 0.003159f, 0.005577f, 0.011360f, 0.031952f, 0.203979f, 0.874512f, 0.973633f, 0.989258f, 0.994141f, 0.996582f,
+ 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000325f, 0.000366f, 0.000731f, 0.000731f, 0.001093f, 0.001219f, 0.001820f, 0.002916f, 0.005291f, 0.009758f, 0.026352f, 0.145020f,
+ 0.832520f, 0.969238f, 0.988281f, 0.993652f, 0.996094f, 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f, 0.000440f, 0.000605f, 0.000731f, 0.001086f, 0.001097f, 0.001646f,
+ 0.002670f, 0.004230f, 0.008835f, 0.022415f, 0.112183f, 0.786133f, 0.966309f, 0.987793f, 0.993652f, 0.996094f, 0.997559f, 0.998047f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000272f, 0.000358f,
+ 0.000565f, 0.000731f, 0.000790f, 0.001210f, 0.001573f, 0.002434f, 0.004360f, 0.008102f, 0.020660f, 0.092896f, 0.741699f, 0.962891f,
+ 0.987305f, 0.993164f, 0.996094f, 0.997070f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000364f, 0.000723f, 0.000731f, 0.000731f, 0.001216f, 0.001698f, 0.002510f, 0.003998f,
+ 0.007484f, 0.018463f, 0.082336f, 0.709961f, 0.961426f, 0.986816f, 0.993652f, 0.996094f, 0.997559f, 0.998535f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000242f, 0.000362f, 0.000704f, 0.000730f,
+ 0.000845f, 0.001096f, 0.001513f, 0.002302f, 0.003941f, 0.007168f, 0.017746f, 0.076782f, 0.693848f, 0.961426f, 0.987305f, 0.993652f,
+ 0.996094f, 0.997559f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000364f, 0.000579f, 0.000728f, 0.000731f, 0.001096f, 0.001491f, 0.002069f, 0.003899f, 0.007195f, 0.017059f,
+ 0.075439f, 0.701172f, 0.962402f, 0.987793f, 0.993652f, 0.996094f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000357f, 0.000482f, 0.000730f, 0.000731f, 0.001094f,
+ 0.001334f, 0.002230f, 0.003708f, 0.007217f, 0.017410f, 0.079163f, 0.730469f, 0.965820f, 0.988281f, 0.994141f, 0.996582f, 0.998047f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000112f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000238f,
+ 0.000243f, 0.000365f, 0.000729f, 0.000731f, 0.001095f, 0.001330f, 0.002066f, 0.003637f, 0.007118f, 0.018112f, 0.087708f, 0.775391f,
+ 0.969238f, 0.989258f, 0.994629f, 0.997070f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000073f, 0.000121f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000323f, 0.000390f, 0.000729f, 0.000731f, 0.001094f, 0.001332f, 0.002275f,
+ 0.003782f, 0.007252f, 0.019379f, 0.105042f, 0.827637f, 0.973145f, 0.990723f, 0.994629f, 0.997070f, 0.998047f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000114f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000240f, 0.000369f,
+ 0.000729f, 0.000731f, 0.001093f, 0.001330f, 0.002209f, 0.003937f, 0.007896f, 0.021805f, 0.137207f, 0.876953f, 0.979004f, 0.991699f,
+ 0.995605f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000272f, 0.000479f, 0.000727f, 0.000731f, 0.001085f, 0.001331f, 0.002291f, 0.004105f, 0.008446f,
+ 0.025024f, 0.202271f, 0.916504f, 0.982910f, 0.993164f, 0.996094f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000120f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000360f, 0.000469f, 0.000681f, 0.000731f,
+ 0.001092f, 0.001331f, 0.002184f, 0.004227f, 0.009521f, 0.030899f, 0.335205f, 0.945312f, 0.986816f, 0.993652f, 0.996582f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000116f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000241f, 0.000429f, 0.000726f, 0.000731f, 0.001091f, 0.001649f, 0.002464f, 0.004810f, 0.010895f, 0.041931f, 0.563477f,
+ 0.963867f, 0.989746f, 0.995117f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000101f, 0.000120f,
+ 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000288f, 0.000481f, 0.000720f, 0.000731f, 0.001093f, 0.001571f,
+ 0.002735f, 0.005405f, 0.013199f, 0.064880f, 0.786133f, 0.976562f, 0.992188f, 0.995605f, 0.997559f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000112f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000240f,
+ 0.000481f, 0.000727f, 0.000731f, 0.001093f, 0.001655f, 0.003132f, 0.005909f, 0.017181f, 0.123169f, 0.904297f, 0.984375f, 0.993652f,
+ 0.996582f, 0.998047f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000110f, 0.000120f, 0.000121f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000264f, 0.000392f, 0.000727f, 0.000835f, 0.001196f, 0.001765f, 0.003252f, 0.007343f,
+ 0.024521f, 0.304199f, 0.954102f, 0.989258f, 0.995605f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000034f, 0.000119f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000235f, 0.000375f, 0.000728f,
+ 0.000822f, 0.001095f, 0.002024f, 0.003952f, 0.009193f, 0.040894f, 0.694824f, 0.975586f, 0.992676f, 0.996582f, 0.998047f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000112f, 0.000121f, 0.000121f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000307f, 0.000475f, 0.000728f, 0.000943f, 0.001216f, 0.002283f, 0.004829f, 0.013008f, 0.092224f, 0.908203f,
+ 0.986328f, 0.995117f, 0.997559f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000073f, 0.000118f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000240f, 0.000576f, 0.000728f, 0.001073f, 0.001569f,
+ 0.002668f, 0.005947f, 0.020889f, 0.331543f, 0.965820f, 0.992188f, 0.996582f, 0.998047f, 0.998535f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000100f, 0.000120f, 0.000121f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000362f, 0.000630f, 0.000729f, 0.001087f, 0.001567f, 0.003241f, 0.008240f, 0.043793f, 0.824219f, 0.984375f, 0.994629f, 0.997559f,
+ 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000075f, 0.000119f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000363f, 0.000689f, 0.000730f, 0.001185f, 0.002022f, 0.004108f, 0.013702f,
+ 0.161011f, 0.957031f, 0.991699f, 0.996582f, 0.998047f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000003f, 0.000105f, 0.000120f, 0.000121f, 0.000121f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000156f, 0.000372f, 0.000689f,
+ 0.000730f, 0.001198f, 0.002651f, 0.006214f, 0.028854f, 0.750000f, 0.984375f, 0.995605f, 0.998047f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000102f,
+ 0.000118f, 0.000120f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000472f, 0.000724f, 0.000966f, 0.001658f, 0.003397f, 0.010582f, 0.116028f, 0.959473f, 0.993164f,
+ 0.997559f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000111f, 0.000119f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000130f, 0.000479f, 0.000726f, 0.001163f, 0.002157f,
+ 0.004829f, 0.024338f, 0.776855f, 0.987793f, 0.996582f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000097f, 0.000117f,
+ 0.000120f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000219f, 0.000580f, 0.000728f, 0.001203f, 0.002872f, 0.009109f, 0.130371f, 0.972168f, 0.995117f, 0.998047f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000112f, 0.000118f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000333f, 0.000681f, 0.000940f, 0.001629f, 0.004120f, 0.025467f, 0.890625f,
+ 0.991699f, 0.997559f, 0.999512f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000083f, 0.000116f, 0.000120f,
+ 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000353f, 0.000722f,
+ 0.000961f, 0.002403f, 0.009354f, 0.295166f, 0.985840f, 0.997070f, 0.999512f, 0.999023f, 0.999512f, 0.999023f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000105f, 0.000118f, 0.000120f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000130f, 0.000427f, 0.000605f, 0.001345f, 0.004620f, 0.041229f, 0.966797f, 0.996094f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000074f, 0.000114f, 0.000119f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000089f, 0.000562f, 0.000942f, 0.002352f, 0.012459f,
+ 0.854004f, 0.994141f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000103f, 0.000117f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000007f, 0.000002f,
+ 0.000231f, 0.000596f, 0.001180f, 0.005474f, 0.211426f, 0.991211f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000111f, 0.000118f, 0.000120f, 0.000121f,
+ 0.000121f, 0.000122f, 0.000029f, 0.000004f, 0.000001f, 0.000348f, 0.000896f, 0.002764f, 0.032562f, 0.984375f, 0.998535f, 0.998535f,
+ 0.999023f, 0.998535f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000089f, 0.000116f, 0.000119f, 0.000121f, 0.000121f, 0.000121f, 0.000013f, 0.000003f, 0.000075f, 0.000586f, 0.001508f,
+ 0.010292f, 0.963379f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000006f, 0.000107f, 0.000118f, 0.000120f, 0.000121f, 0.000116f,
+ 0.000008f, 0.000002f, 0.000233f, 0.000857f, 0.004566f, 0.834961f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000083f, 0.000114f, 0.000119f, 0.000120f, 0.000060f, 0.000005f, 0.000001f, 0.000557f, 0.002064f, 0.182373f, 0.997559f, 0.997559f,
+ 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000103f, 0.000117f, 0.000120f, 0.000024f, 0.000003f, 0.000168f,
+ 0.000968f, 0.026428f, 0.996582f, 0.997070f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000047f,
+ 0.000110f, 0.000118f, 0.000017f, 0.000002f, 0.000513f, 0.006870f, 0.995605f, 0.995605f, 0.995117f, 0.995117f, 0.995117f, 0.995117f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000096f, 0.000115f, 0.000011f, 0.000042f, 0.001919f, 0.992676f, 0.992676f,
+ 0.992676f, 0.992676f, 0.992676f, 0.992676f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000044f, 0.000109f,
+ 0.000008f, 0.000314f, 0.985840f, 0.985840f, 0.985840f, 0.985840f, 0.986328f, 0.985840f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000089f, 0.000060f, 0.964355f, 0.964355f, 0.963867f, 0.963867f, 0.963379f, 0.964355f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000022f, 0.818848f, 0.819824f,
+ 0.819336f, 0.819824f, 0.819824f, 0.819824f,
+ },
+ {
+ 0.038849f, 0.941406f, 0.984375f, 0.992188f, 0.994141f, 0.996094f, 0.996582f, 0.997070f, 0.998047f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 1.000000f, 1.000000f, 1.000000f, 0.999512f, 0.001582f, 0.014984f, 0.262451f, 0.930664f, 0.979980f, 0.989258f, 0.993164f, 0.995117f,
+ 0.996094f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f, 0.000244f, 0.002317f, 0.009003f, 0.047180f,
+ 0.524902f, 0.936523f, 0.978027f, 0.988281f, 0.992188f, 0.994629f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 1.000000f,
+ 0.000122f, 0.001098f, 0.002560f, 0.006824f, 0.020493f, 0.108826f, 0.715820f, 0.946289f, 0.978516f, 0.988281f, 0.992188f, 0.994141f,
+ 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000607f, 0.001098f, 0.002310f, 0.005646f, 0.012825f, 0.040131f, 0.231201f,
+ 0.825195f, 0.954590f, 0.979980f, 0.988281f, 0.992188f, 0.994141f, 0.995117f, 0.996582f, 0.996582f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000244f, 0.000609f, 0.001341f,
+ 0.002310f, 0.004208f, 0.008865f, 0.021591f, 0.074585f, 0.439209f, 0.885742f, 0.962402f, 0.981934f, 0.989258f, 0.992676f, 0.994141f,
+ 0.995605f, 0.996582f, 0.997070f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.999512f,
+ 0.000000f, 0.000122f, 0.000483f, 0.000610f, 0.001460f, 0.002192f, 0.003994f, 0.007030f, 0.013847f, 0.036316f, 0.146362f, 0.661621f,
+ 0.921875f, 0.969238f, 0.983398f, 0.989746f, 0.993164f, 0.994141f, 0.995605f, 0.996582f, 0.996582f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000243f, 0.000604f, 0.000730f, 0.001307f, 0.001944f, 0.003017f,
+ 0.004997f, 0.009834f, 0.021606f, 0.063416f, 0.295410f, 0.808594f, 0.944336f, 0.974609f, 0.985352f, 0.990234f, 0.993652f, 0.995117f,
+ 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 1.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000366f,
+ 0.000495f, 0.000731f, 0.001217f, 0.001823f, 0.002796f, 0.004398f, 0.007656f, 0.015366f, 0.035828f, 0.119263f, 0.531738f, 0.886230f,
+ 0.958496f, 0.979004f, 0.986816f, 0.991699f, 0.993652f, 0.995117f, 0.996094f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000244f, 0.000366f, 0.000607f, 0.000731f, 0.001211f, 0.001650f, 0.002441f, 0.003975f, 0.006207f,
+ 0.011536f, 0.023315f, 0.060822f, 0.242798f, 0.744141f, 0.927734f, 0.969238f, 0.982422f, 0.989258f, 0.992188f, 0.994141f, 0.995605f,
+ 0.996094f, 0.996582f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000211f, 0.000455f, 0.000486f, 0.000853f,
+ 0.001081f, 0.001810f, 0.002426f, 0.003759f, 0.005501f, 0.009094f, 0.016876f, 0.037109f, 0.114075f, 0.475586f, 0.862305f, 0.951172f,
+ 0.975586f, 0.985840f, 0.990234f, 0.992676f, 0.995117f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000364f, 0.000366f, 0.000464f, 0.000731f, 0.001093f, 0.001577f, 0.002235f, 0.002798f, 0.004841f, 0.007637f, 0.013008f,
+ 0.025635f, 0.063965f, 0.238403f, 0.720215f, 0.919434f, 0.965820f, 0.981445f, 0.987793f, 0.991211f, 0.993652f, 0.995117f, 0.996094f,
+ 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000238f, 0.000609f, 0.000712f, 0.000974f, 0.000976f, 0.001507f,
+ 0.002031f, 0.002680f, 0.004066f, 0.006294f, 0.010284f, 0.018326f, 0.040924f, 0.124146f, 0.485596f, 0.859375f, 0.949707f, 0.975586f,
+ 0.984375f, 0.989746f, 0.992676f, 0.994629f, 0.995605f, 0.996582f, 0.997070f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000113f, 0.000487f,
+ 0.000488f, 0.000610f, 0.000961f, 0.000976f, 0.001337f, 0.001705f, 0.002663f, 0.003521f, 0.005417f, 0.008408f, 0.014809f, 0.028793f,
+ 0.073120f, 0.270996f, 0.741699f, 0.922363f, 0.965332f, 0.980957f, 0.987793f, 0.991699f, 0.993652f, 0.995117f, 0.996094f, 0.997070f,
+ 0.997070f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000244f, 0.000224f, 0.000486f, 0.000609f, 0.000610f, 0.000973f, 0.000975f, 0.001306f, 0.001703f, 0.002350f,
+ 0.003239f, 0.004848f, 0.007122f, 0.011955f, 0.021820f, 0.048859f, 0.152710f, 0.554199f, 0.875977f, 0.953125f, 0.976562f, 0.985352f,
+ 0.990234f, 0.993164f, 0.994629f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000234f, 0.000244f, 0.000485f, 0.000488f, 0.000610f,
+ 0.000969f, 0.000975f, 0.001335f, 0.001693f, 0.001991f, 0.002811f, 0.004097f, 0.006397f, 0.009903f, 0.017303f, 0.035034f, 0.094421f,
+ 0.354736f, 0.795898f, 0.933594f, 0.969238f, 0.981934f, 0.988281f, 0.991699f, 0.993652f, 0.995117f, 0.996094f, 0.997070f, 0.997559f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000244f, 0.000244f, 0.000480f, 0.000608f, 0.000488f, 0.000922f, 0.000975f, 0.000976f, 0.001339f, 0.001827f, 0.002674f, 0.003891f,
+ 0.005688f, 0.008324f, 0.014320f, 0.026917f, 0.064392f, 0.216431f, 0.668945f, 0.904785f, 0.959961f, 0.978516f, 0.986816f, 0.990723f,
+ 0.993652f, 0.994141f, 0.996094f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 1.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000188f, 0.000220f, 0.000480f, 0.000608f, 0.000609f, 0.000876f, 0.000975f,
+ 0.000976f, 0.001454f, 0.002068f, 0.002649f, 0.003481f, 0.004757f, 0.007801f, 0.012230f, 0.021698f, 0.046814f, 0.138306f, 0.506348f,
+ 0.859375f, 0.947754f, 0.974121f, 0.984375f, 0.989746f, 0.992188f, 0.994141f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000244f,
+ 0.000446f, 0.000487f, 0.000609f, 0.000731f, 0.000973f, 0.000975f, 0.001310f, 0.001823f, 0.002304f, 0.002869f, 0.004890f, 0.006813f,
+ 0.010475f, 0.017731f, 0.036163f, 0.095337f, 0.353516f, 0.792480f, 0.932129f, 0.968262f, 0.982422f, 0.988770f, 0.992188f, 0.993652f,
+ 0.995605f, 0.996094f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000241f, 0.000362f, 0.000487f, 0.000609f, 0.000609f, 0.000973f, 0.001213f, 0.001419f,
+ 0.001807f, 0.002068f, 0.002794f, 0.004070f, 0.005917f, 0.009140f, 0.015129f, 0.029053f, 0.070068f, 0.242554f, 0.700684f, 0.911621f,
+ 0.961914f, 0.979492f, 0.987305f, 0.991211f, 0.993164f, 0.995117f, 0.995605f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000243f, 0.000483f, 0.000603f,
+ 0.000609f, 0.000730f, 0.001076f, 0.000975f, 0.001327f, 0.001598f, 0.002056f, 0.002848f, 0.003519f, 0.005589f, 0.008041f, 0.013321f,
+ 0.024155f, 0.054718f, 0.171875f, 0.590332f, 0.885742f, 0.955566f, 0.977051f, 0.985840f, 0.990723f, 0.993164f, 0.994629f, 0.995605f,
+ 0.997070f, 0.997070f, 0.997559f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000192f, 0.000122f, 0.000244f, 0.000483f, 0.000606f, 0.000608f, 0.000731f, 0.000953f, 0.001095f, 0.001258f, 0.001575f, 0.002066f,
+ 0.002594f, 0.003857f, 0.004734f, 0.007683f, 0.011642f, 0.021179f, 0.044464f, 0.127930f, 0.476807f, 0.850586f, 0.947266f, 0.974121f,
+ 0.984375f, 0.989746f, 0.992676f, 0.994141f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000229f, 0.000239f, 0.000244f, 0.000343f, 0.000483f, 0.000608f, 0.000609f,
+ 0.000857f, 0.000973f, 0.001097f, 0.001571f, 0.002041f, 0.002399f, 0.002922f, 0.004471f, 0.006836f, 0.010643f, 0.018661f, 0.037354f,
+ 0.100037f, 0.378418f, 0.810547f, 0.937988f, 0.971191f, 0.983887f, 0.989258f, 0.992188f, 0.994141f, 0.995605f, 0.996582f, 0.997070f,
+ 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000161f,
+ 0.000230f, 0.000244f, 0.000486f, 0.000607f, 0.000609f, 0.000819f, 0.000972f, 0.000975f, 0.001431f, 0.001945f, 0.002283f, 0.003031f,
+ 0.004238f, 0.006424f, 0.009995f, 0.016068f, 0.032104f, 0.081360f, 0.302246f, 0.765625f, 0.928223f, 0.968750f, 0.982422f, 0.988770f,
+ 0.992676f, 0.994629f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000240f, 0.000240f, 0.000244f, 0.000450f, 0.000607f, 0.000609f, 0.000731f, 0.001084f,
+ 0.000974f, 0.001341f, 0.001910f, 0.002254f, 0.003216f, 0.004017f, 0.005692f, 0.008980f, 0.014832f, 0.028854f, 0.069641f, 0.248657f,
+ 0.719238f, 0.918945f, 0.965820f, 0.981445f, 0.988770f, 0.992188f, 0.994629f, 0.995605f, 0.996094f, 0.997070f, 0.997559f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000360f,
+ 0.000461f, 0.000607f, 0.000608f, 0.000731f, 0.001086f, 0.001202f, 0.001307f, 0.001592f, 0.002066f, 0.003134f, 0.003990f, 0.005611f,
+ 0.008133f, 0.013680f, 0.025986f, 0.061462f, 0.211670f, 0.676758f, 0.910156f, 0.963867f, 0.980957f, 0.988281f, 0.991699f, 0.994629f,
+ 0.995605f, 0.996582f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000240f, 0.000243f, 0.000482f, 0.000604f, 0.000608f, 0.000730f, 0.001040f, 0.001188f, 0.001287f,
+ 0.001574f, 0.002064f, 0.002613f, 0.003721f, 0.005428f, 0.008018f, 0.013161f, 0.024200f, 0.055573f, 0.186401f, 0.642578f, 0.904785f,
+ 0.962402f, 0.980469f, 0.987793f, 0.991699f, 0.994141f, 0.995605f, 0.996582f, 0.997070f, 0.998047f, 0.998535f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000480f, 0.000602f,
+ 0.000721f, 0.000705f, 0.000907f, 0.001094f, 0.001096f, 0.001493f, 0.002058f, 0.002607f, 0.003639f, 0.004826f, 0.007595f, 0.012413f,
+ 0.022171f, 0.051697f, 0.171143f, 0.619629f, 0.899414f, 0.961426f, 0.980957f, 0.987793f, 0.992188f, 0.994629f, 0.995605f, 0.996582f,
+ 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000172f, 0.000232f, 0.000243f, 0.000244f, 0.000576f, 0.000711f, 0.000608f, 0.000767f, 0.001089f, 0.001213f, 0.001509f, 0.002029f,
+ 0.002684f, 0.003550f, 0.005161f, 0.007107f, 0.011871f, 0.021545f, 0.049347f, 0.163086f, 0.609863f, 0.900391f, 0.962891f, 0.980957f,
+ 0.988281f, 0.992676f, 0.994629f, 0.996094f, 0.996582f, 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000210f, 0.000122f, 0.000337f, 0.000290f, 0.000594f, 0.000726f, 0.000730f,
+ 0.000731f, 0.001090f, 0.001212f, 0.001506f, 0.002029f, 0.002335f, 0.003489f, 0.005077f, 0.007000f, 0.011398f, 0.021027f, 0.048218f,
+ 0.161133f, 0.614258f, 0.903809f, 0.963379f, 0.981934f, 0.988770f, 0.992188f, 0.994629f, 0.996094f, 0.997070f, 0.997559f, 0.998047f,
+ 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000281f, 0.000440f, 0.000683f, 0.000726f, 0.000730f, 0.000731f, 0.001087f, 0.001095f, 0.001485f, 0.001793f, 0.002214f, 0.002991f,
+ 0.004951f, 0.006912f, 0.011162f, 0.020905f, 0.048187f, 0.165527f, 0.633789f, 0.910156f, 0.965820f, 0.982422f, 0.989746f, 0.993164f,
+ 0.995117f, 0.996094f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000241f, 0.000243f, 0.000480f, 0.000725f, 0.000697f, 0.000731f, 0.001007f,
+ 0.001094f, 0.001360f, 0.001795f, 0.002161f, 0.003244f, 0.004871f, 0.006966f, 0.011330f, 0.020706f, 0.049591f, 0.178345f, 0.667969f,
+ 0.918457f, 0.968262f, 0.983887f, 0.990234f, 0.993652f, 0.995605f, 0.996582f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000086f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000243f,
+ 0.000465f, 0.000592f, 0.000729f, 0.000730f, 0.001079f, 0.001093f, 0.001332f, 0.001885f, 0.002129f, 0.003254f, 0.004818f, 0.006889f,
+ 0.011429f, 0.021957f, 0.052521f, 0.201294f, 0.714355f, 0.929199f, 0.972168f, 0.985352f, 0.991211f, 0.994141f, 0.995605f, 0.997070f,
+ 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000115f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000184f, 0.000241f, 0.000347f, 0.000453f, 0.000579f, 0.000728f, 0.000729f, 0.001034f, 0.001093f, 0.001292f,
+ 0.001857f, 0.002131f, 0.003296f, 0.004826f, 0.006958f, 0.011726f, 0.023071f, 0.057983f, 0.239258f, 0.767578f, 0.939453f, 0.976074f,
+ 0.987305f, 0.992676f, 0.994629f, 0.996094f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000088f, 0.000119f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000191f, 0.000242f, 0.000425f, 0.000558f,
+ 0.000723f, 0.000730f, 0.001058f, 0.001092f, 0.001297f, 0.001653f, 0.002352f, 0.003124f, 0.004860f, 0.007072f, 0.012131f, 0.024551f,
+ 0.066406f, 0.300537f, 0.820312f, 0.951172f, 0.979492f, 0.988281f, 0.993164f, 0.995117f, 0.996582f, 0.997070f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000119f,
+ 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000227f, 0.000239f, 0.000341f, 0.000359f, 0.000587f, 0.000605f, 0.000729f, 0.001040f, 0.001185f, 0.001275f, 0.001849f, 0.002390f,
+ 0.003399f, 0.005001f, 0.007404f, 0.012871f, 0.027237f, 0.079529f, 0.395264f, 0.868164f, 0.960938f, 0.982910f, 0.990234f, 0.993164f,
+ 0.995605f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000211f, 0.000239f, 0.000307f, 0.000394f, 0.000704f, 0.000711f, 0.000728f,
+ 0.001001f, 0.001088f, 0.001204f, 0.001713f, 0.002367f, 0.003151f, 0.004639f, 0.007820f, 0.014084f, 0.030609f, 0.102722f, 0.527344f,
+ 0.906250f, 0.969727f, 0.985840f, 0.991699f, 0.994629f, 0.996094f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000117f, 0.000115f, 0.000121f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000196f,
+ 0.000332f, 0.000363f, 0.000686f, 0.000719f, 0.000723f, 0.000963f, 0.001089f, 0.001290f, 0.001849f, 0.002394f, 0.003458f, 0.004833f,
+ 0.008301f, 0.015579f, 0.036926f, 0.143188f, 0.676270f, 0.934570f, 0.976562f, 0.988281f, 0.992676f, 0.995605f, 0.996582f, 0.998047f,
+ 0.998047f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000102f, 0.000120f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000311f, 0.000345f, 0.000479f, 0.000723f, 0.000728f, 0.000934f, 0.001085f,
+ 0.001282f, 0.001821f, 0.002399f, 0.003355f, 0.005524f, 0.008881f, 0.017807f, 0.047058f, 0.222046f, 0.803223f, 0.954102f, 0.981445f,
+ 0.990723f, 0.994141f, 0.996582f, 0.997559f, 0.998047f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000090f, 0.000116f, 0.000121f, 0.000121f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000201f, 0.000239f, 0.000358f,
+ 0.000618f, 0.000719f, 0.000727f, 0.000863f, 0.001087f, 0.001350f, 0.001945f, 0.002689f, 0.003731f, 0.005817f, 0.010033f, 0.021332f,
+ 0.064514f, 0.374512f, 0.885254f, 0.969238f, 0.986328f, 0.992676f, 0.995605f, 0.996582f, 0.998047f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000086f, 0.000117f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000164f, 0.000238f, 0.000353f, 0.000596f, 0.000591f, 0.000727f, 0.000901f, 0.001085f, 0.001266f, 0.001767f,
+ 0.002663f, 0.003914f, 0.006153f, 0.011612f, 0.026871f, 0.100525f, 0.605957f, 0.934082f, 0.978027f, 0.989746f, 0.994141f, 0.996094f,
+ 0.997559f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999023f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000107f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000195f, 0.000323f, 0.000339f, 0.000461f, 0.000706f,
+ 0.000726f, 0.000845f, 0.001086f, 0.001298f, 0.001843f, 0.003027f, 0.004387f, 0.007011f, 0.013832f, 0.036530f, 0.183228f, 0.805664f,
+ 0.959961f, 0.984863f, 0.991699f, 0.995605f, 0.997070f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000117f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000224f, 0.000336f, 0.000464f, 0.000708f, 0.000726f, 0.000965f, 0.001083f, 0.001458f, 0.002180f, 0.003096f, 0.004425f,
+ 0.008377f, 0.017639f, 0.056610f, 0.390869f, 0.909180f, 0.975586f, 0.989746f, 0.994141f, 0.996582f, 0.998047f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000110f, 0.000113f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000135f, 0.000336f, 0.000467f, 0.000713f, 0.000725f, 0.000959f,
+ 0.001191f, 0.001287f, 0.001939f, 0.003231f, 0.005306f, 0.009888f, 0.024414f, 0.105835f, 0.709961f, 0.955078f, 0.984863f, 0.993164f,
+ 0.996094f, 0.997559f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000061f, 0.000089f,
+ 0.000118f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000309f,
+ 0.000299f, 0.000460f, 0.000710f, 0.000724f, 0.000997f, 0.001073f, 0.001410f, 0.002117f, 0.003506f, 0.006031f, 0.012863f, 0.038391f,
+ 0.260742f, 0.892090f, 0.975098f, 0.990723f, 0.995117f, 0.997559f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000085f, 0.000110f, 0.000118f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000317f, 0.000499f, 0.000706f, 0.000599f, 0.000851f, 0.001069f, 0.001633f,
+ 0.002367f, 0.003918f, 0.007580f, 0.017929f, 0.074646f, 0.645508f, 0.956055f, 0.986328f, 0.994141f, 0.996582f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000099f, 0.000113f,
+ 0.000119f, 0.000119f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000160f, 0.000326f, 0.000308f,
+ 0.000578f, 0.000602f, 0.000921f, 0.001071f, 0.001807f, 0.002783f, 0.004620f, 0.010017f, 0.029465f, 0.211792f, 0.896484f, 0.979004f,
+ 0.992188f, 0.996094f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000027f, 0.000103f, 0.000114f, 0.000118f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000090f, 0.000212f, 0.000309f, 0.000586f, 0.000602f, 0.000937f, 0.001147f, 0.002031f, 0.003237f, 0.006134f,
+ 0.014969f, 0.063171f, 0.665527f, 0.964355f, 0.989258f, 0.995117f, 0.999023f, 0.998535f, 0.999023f, 0.999023f, 0.998535f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000018f, 0.000103f, 0.000113f,
+ 0.000117f, 0.000119f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000004f, 0.000002f, 0.000199f, 0.000390f, 0.000586f, 0.000665f,
+ 0.000946f, 0.001365f, 0.002207f, 0.003767f, 0.008308f, 0.025955f, 0.227661f, 0.924316f, 0.984863f, 0.994141f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000098f, 0.000109f, 0.000117f, 0.000119f, 0.000120f, 0.000120f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000011f, 0.000005f, 0.000003f,
+ 0.000002f, 0.000193f, 0.000388f, 0.000586f, 0.000659f, 0.000952f, 0.001580f, 0.002762f, 0.005363f, 0.013153f, 0.066589f, 0.781738f,
+ 0.977051f, 0.993164f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000075f, 0.000112f,
+ 0.000116f, 0.000118f, 0.000119f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000122f,
+ 0.000088f, 0.000026f, 0.000010f, 0.000005f, 0.000003f, 0.000002f, 0.000186f, 0.000407f, 0.000586f, 0.000760f, 0.000986f, 0.001796f,
+ 0.003275f, 0.007565f, 0.026794f, 0.363281f, 0.959473f, 0.990723f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000010f, 0.000090f, 0.000110f, 0.000115f, 0.000117f, 0.000119f, 0.000120f, 0.000120f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000077f, 0.000023f, 0.000011f, 0.000005f, 0.000003f, 0.000002f, 0.000158f,
+ 0.000407f, 0.000587f, 0.000826f, 0.001264f, 0.002174f, 0.004894f, 0.013359f, 0.098511f, 0.911133f, 0.987793f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000084f, 0.000107f,
+ 0.000114f, 0.000117f, 0.000119f, 0.000119f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000093f, 0.000024f,
+ 0.000011f, 0.000005f, 0.000003f, 0.000002f, 0.000220f, 0.000476f, 0.000585f, 0.000913f, 0.001374f, 0.002951f, 0.007511f, 0.034973f,
+ 0.736328f, 0.982910f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000056f, 0.000102f, 0.000112f, 0.000116f, 0.000117f, 0.000119f, 0.000120f, 0.000120f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000075f, 0.000025f, 0.000010f, 0.000005f, 0.000003f, 0.000034f, 0.000222f, 0.000491f, 0.000589f,
+ 0.001020f, 0.001881f, 0.004669f, 0.015717f, 0.298340f, 0.974609f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000048f, 0.000095f,
+ 0.000106f, 0.000114f, 0.000117f, 0.000118f, 0.000119f, 0.000120f, 0.000120f, 0.000121f, 0.000089f, 0.000029f, 0.000012f, 0.000006f,
+ 0.000003f, 0.000002f, 0.000223f, 0.000525f, 0.000687f, 0.001122f, 0.002672f, 0.008255f, 0.079590f, 0.954590f, 0.996582f, 0.996582f,
+ 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000077f, 0.000104f, 0.000112f, 0.000115f, 0.000117f, 0.000119f, 0.000119f,
+ 0.000120f, 0.000109f, 0.000031f, 0.000013f, 0.000006f, 0.000003f, 0.000002f, 0.000254f, 0.000550f, 0.000846f, 0.001545f, 0.004223f,
+ 0.027771f, 0.901855f, 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000037f,
+ 0.000090f, 0.000107f, 0.000113f, 0.000116f, 0.000118f, 0.000119f, 0.000120f, 0.000041f, 0.000015f, 0.000007f, 0.000004f, 0.000002f,
+ 0.000271f, 0.000563f, 0.000786f, 0.002211f, 0.012207f, 0.711426f, 0.994629f, 0.994629f, 0.995117f, 0.994629f, 0.994629f, 0.994629f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000028f, 0.000083f, 0.000102f, 0.000110f, 0.000114f, 0.000117f, 0.000118f,
+ 0.000052f, 0.000019f, 0.000008f, 0.000004f, 0.000002f, 0.000314f, 0.000444f, 0.001049f, 0.005669f, 0.266846f, 0.993164f, 0.993652f,
+ 0.993164f, 0.993652f, 0.993164f, 0.993164f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000048f, 0.000089f, 0.000106f, 0.000112f, 0.000115f, 0.000077f, 0.000026f, 0.000010f, 0.000005f, 0.000079f, 0.000425f, 0.000405f,
+ 0.002468f, 0.064209f, 0.990234f, 0.990723f, 0.990234f, 0.990234f, 0.990234f, 0.991211f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000020f, 0.000075f, 0.000098f, 0.000108f, 0.000113f, 0.000044f,
+ 0.000016f, 0.000006f, 0.000027f, 0.000270f, 0.000825f, 0.018448f, 0.986328f, 0.986328f, 0.986328f, 0.986328f, 0.986328f, 0.986328f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000049f, 0.000085f, 0.000102f, 0.000070f, 0.000022f, 0.000008f, 0.000133f, 0.000295f, 0.005318f, 0.978516f, 0.979004f,
+ 0.977539f, 0.977539f, 0.978027f, 0.978516f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000066f, 0.000092f, 0.000036f, 0.000011f,
+ 0.000135f, 0.000925f, 0.959473f, 0.959961f, 0.959961f, 0.959473f, 0.959961f, 0.959473f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000027f, 0.000065f, 0.000016f, 0.000109f, 0.907715f, 0.907227f, 0.907715f, 0.907227f, 0.907715f, 0.907715f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000017f, 0.711914f, 0.712402f,
+ 0.711426f, 0.711426f, 0.711914f, 0.712402f,
+ },
+ {
+ 0.076172f, 0.877441f, 0.964355f, 0.980957f, 0.987305f, 0.990723f, 0.992676f, 0.993652f, 0.994629f, 0.995605f, 0.996094f, 0.996582f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.003897f, 0.033173f, 0.320557f, 0.863770f, 0.953613f, 0.975586f, 0.984863f, 0.988770f,
+ 0.991211f, 0.992676f, 0.994141f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997559f, 0.997559f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000975f, 0.005951f, 0.020935f, 0.093140f,
+ 0.501465f, 0.873047f, 0.950684f, 0.973145f, 0.981934f, 0.986816f, 0.990234f, 0.992188f, 0.993164f, 0.994629f, 0.995605f, 0.996094f,
+ 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998047f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000610f, 0.002430f, 0.006081f, 0.015915f, 0.045593f, 0.179810f, 0.635254f, 0.889648f, 0.951172f, 0.972168f, 0.981445f, 0.986328f,
+ 0.989746f, 0.991699f, 0.993652f, 0.994629f, 0.995117f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000244f, 0.001219f, 0.002796f, 0.006172f, 0.012848f, 0.028458f, 0.081177f, 0.301758f,
+ 0.733398f, 0.905273f, 0.953613f, 0.972168f, 0.981445f, 0.986328f, 0.989258f, 0.991699f, 0.993652f, 0.994141f, 0.995117f, 0.996094f,
+ 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000244f, 0.000731f, 0.001706f, 0.003166f,
+ 0.005470f, 0.010406f, 0.020813f, 0.047089f, 0.136719f, 0.449951f, 0.803223f, 0.919434f, 0.957520f, 0.973633f, 0.981934f, 0.986328f,
+ 0.989746f, 0.991699f, 0.993164f, 0.994629f, 0.995117f, 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000244f, 0.000366f, 0.001214f, 0.001894f, 0.003159f, 0.005108f, 0.008720f, 0.015839f, 0.031586f, 0.074951f, 0.224121f, 0.596680f,
+ 0.851074f, 0.932617f, 0.962402f, 0.975586f, 0.982910f, 0.987305f, 0.989746f, 0.991699f, 0.993164f, 0.994141f, 0.995117f, 0.995605f,
+ 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000366f, 0.000731f, 0.000976f, 0.001827f, 0.002987f, 0.004757f, 0.007988f,
+ 0.013023f, 0.023544f, 0.048431f, 0.120239f, 0.352783f, 0.717285f, 0.887207f, 0.943848f, 0.966309f, 0.978027f, 0.983887f, 0.987305f,
+ 0.990234f, 0.992188f, 0.993652f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000434f, 0.000488f, 0.000704f,
+ 0.001218f, 0.002190f, 0.002783f, 0.004723f, 0.006878f, 0.011040f, 0.018372f, 0.034241f, 0.073242f, 0.194336f, 0.510742f, 0.803711f,
+ 0.912598f, 0.952637f, 0.970703f, 0.979004f, 0.984863f, 0.988281f, 0.991211f, 0.992676f, 0.994141f, 0.994629f, 0.995605f, 0.996094f,
+ 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000243f, 0.000488f, 0.000488f, 0.000916f, 0.001219f, 0.002308f, 0.002914f, 0.004124f, 0.006523f, 0.009537f, 0.014793f,
+ 0.025833f, 0.050446f, 0.116089f, 0.312744f, 0.661133f, 0.860840f, 0.931641f, 0.960449f, 0.974121f, 0.981445f, 0.986328f, 0.989258f,
+ 0.991211f, 0.992676f, 0.994141f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000121f, 0.000356f, 0.000488f, 0.000609f, 0.000944f, 0.001339f, 0.002296f,
+ 0.002964f, 0.003880f, 0.005676f, 0.008476f, 0.012909f, 0.020874f, 0.036926f, 0.075500f, 0.187988f, 0.474854f, 0.774414f, 0.900391f,
+ 0.946289f, 0.966309f, 0.978027f, 0.983887f, 0.987793f, 0.990234f, 0.991699f, 0.993164f, 0.994141f, 0.995117f, 0.995605f, 0.996094f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000244f, 0.000483f,
+ 0.000488f, 0.000731f, 0.001070f, 0.001551f, 0.002024f, 0.002520f, 0.003990f, 0.004738f, 0.007584f, 0.010834f, 0.016800f, 0.028763f,
+ 0.054535f, 0.120728f, 0.309082f, 0.642090f, 0.848145f, 0.926270f, 0.957031f, 0.971191f, 0.980469f, 0.985352f, 0.988770f, 0.990723f,
+ 0.992188f, 0.993652f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000242f, 0.000485f, 0.000608f, 0.000731f, 0.001091f, 0.001339f, 0.001943f, 0.002602f, 0.003466f,
+ 0.004845f, 0.006649f, 0.009529f, 0.014824f, 0.023407f, 0.041351f, 0.083496f, 0.199951f, 0.482422f, 0.770996f, 0.896484f, 0.944336f,
+ 0.965332f, 0.976562f, 0.982910f, 0.986816f, 0.990234f, 0.991699f, 0.993164f, 0.994141f, 0.995117f, 0.995117f, 0.996094f, 0.996582f,
+ 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000121f, 0.000243f, 0.000243f, 0.000602f, 0.000609f, 0.000799f,
+ 0.001088f, 0.001459f, 0.001822f, 0.002432f, 0.003033f, 0.004375f, 0.006042f, 0.008560f, 0.012810f, 0.019791f, 0.032715f, 0.061584f,
+ 0.135254f, 0.335693f, 0.660156f, 0.853027f, 0.926758f, 0.956543f, 0.972168f, 0.980469f, 0.984863f, 0.988281f, 0.991211f, 0.992676f,
+ 0.993652f, 0.994141f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000119f,
+ 0.000243f, 0.000366f, 0.000605f, 0.000730f, 0.000731f, 0.001201f, 0.001458f, 0.001804f, 0.002428f, 0.003593f, 0.004234f, 0.005745f,
+ 0.007755f, 0.011139f, 0.016754f, 0.027054f, 0.047424f, 0.097107f, 0.231323f, 0.525879f, 0.791016f, 0.902832f, 0.945801f, 0.966797f,
+ 0.977051f, 0.982910f, 0.987793f, 0.990234f, 0.991699f, 0.993164f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000116f, 0.000122f, 0.000365f, 0.000244f, 0.000602f, 0.000721f, 0.000730f, 0.000852f, 0.001451f,
+ 0.001842f, 0.002518f, 0.002993f, 0.004097f, 0.005253f, 0.007099f, 0.009865f, 0.014908f, 0.022827f, 0.038879f, 0.072815f, 0.163940f,
+ 0.396484f, 0.707031f, 0.869141f, 0.932129f, 0.960449f, 0.973145f, 0.980957f, 0.986328f, 0.988770f, 0.991211f, 0.992676f, 0.993652f,
+ 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000110f, 0.000361f, 0.000242f, 0.000244f,
+ 0.000602f, 0.000728f, 0.000853f, 0.001260f, 0.001569f, 0.001704f, 0.002287f, 0.003103f, 0.003857f, 0.004848f, 0.006680f, 0.009003f,
+ 0.012978f, 0.019897f, 0.032135f, 0.057983f, 0.121033f, 0.291504f, 0.604980f, 0.827148f, 0.915039f, 0.953125f, 0.969238f, 0.978516f,
+ 0.984375f, 0.988281f, 0.991211f, 0.992188f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000241f, 0.000241f, 0.000365f, 0.000365f, 0.000589f, 0.000852f, 0.000852f, 0.001246f, 0.001562f, 0.001812f, 0.002241f,
+ 0.002794f, 0.003633f, 0.004669f, 0.006069f, 0.008202f, 0.011772f, 0.016891f, 0.027618f, 0.047089f, 0.093506f, 0.216309f, 0.495605f,
+ 0.771484f, 0.894531f, 0.942383f, 0.965332f, 0.976074f, 0.982910f, 0.987305f, 0.989746f, 0.991699f, 0.993164f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000364f, 0.000242f, 0.000487f, 0.000737f, 0.000730f,
+ 0.000974f, 0.001083f, 0.001520f, 0.001701f, 0.001938f, 0.002768f, 0.003658f, 0.004227f, 0.005741f, 0.007671f, 0.010796f, 0.015511f,
+ 0.023529f, 0.040009f, 0.074158f, 0.165405f, 0.395264f, 0.703613f, 0.868164f, 0.932129f, 0.959473f, 0.973633f, 0.980957f, 0.985840f,
+ 0.988770f, 0.991699f, 0.992676f, 0.994141f, 0.995117f, 0.995117f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000100f, 0.000000f, 0.000241f,
+ 0.000224f, 0.000487f, 0.000488f, 0.000710f, 0.000972f, 0.000848f, 0.001181f, 0.001333f, 0.001910f, 0.001830f, 0.002661f, 0.003298f,
+ 0.004154f, 0.005386f, 0.007271f, 0.009735f, 0.013908f, 0.021149f, 0.034149f, 0.062042f, 0.130371f, 0.313477f, 0.627930f, 0.837402f,
+ 0.919922f, 0.954590f, 0.970215f, 0.979492f, 0.985352f, 0.988770f, 0.991211f, 0.992676f, 0.993652f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996582f, 0.996582f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000049f, 0.000242f, 0.000483f, 0.000606f, 0.000487f, 0.000695f, 0.000970f, 0.000974f, 0.001136f,
+ 0.001328f, 0.001694f, 0.002028f, 0.002617f, 0.002953f, 0.003847f, 0.004951f, 0.006653f, 0.009193f, 0.012672f, 0.018661f, 0.029968f,
+ 0.052673f, 0.106689f, 0.250977f, 0.549805f, 0.801758f, 0.907227f, 0.948242f, 0.967773f, 0.978027f, 0.984375f, 0.987793f, 0.990723f,
+ 0.992188f, 0.993652f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000166f, 0.000243f, 0.000485f, 0.000487f,
+ 0.000487f, 0.000945f, 0.000834f, 0.000974f, 0.000974f, 0.001300f, 0.001810f, 0.002058f, 0.002573f, 0.002703f, 0.003761f, 0.004887f,
+ 0.006393f, 0.008514f, 0.011818f, 0.016937f, 0.026672f, 0.046051f, 0.089478f, 0.204712f, 0.476807f, 0.762207f, 0.891602f, 0.942383f,
+ 0.965820f, 0.976562f, 0.983398f, 0.987793f, 0.990234f, 0.992188f, 0.993652f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.997070f,
+ 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000224f, 0.000358f, 0.000477f, 0.000486f, 0.000487f, 0.000580f, 0.000841f, 0.000973f, 0.001079f, 0.001255f, 0.001649f,
+ 0.002045f, 0.002241f, 0.002995f, 0.003841f, 0.004826f, 0.005920f, 0.007866f, 0.010925f, 0.015930f, 0.024109f, 0.040619f, 0.077454f,
+ 0.171509f, 0.412354f, 0.720215f, 0.876953f, 0.936035f, 0.962402f, 0.975098f, 0.982422f, 0.987305f, 0.990234f, 0.992188f, 0.993164f,
+ 0.994629f, 0.995117f, 0.996094f, 0.996582f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000165f, 0.000205f, 0.000411f, 0.000480f, 0.000486f, 0.000608f, 0.000688f,
+ 0.000966f, 0.000968f, 0.000974f, 0.001421f, 0.001489f, 0.001695f, 0.002090f, 0.002886f, 0.003326f, 0.004608f, 0.005604f, 0.007317f,
+ 0.010414f, 0.014862f, 0.022232f, 0.036469f, 0.067810f, 0.146973f, 0.359375f, 0.680664f, 0.861816f, 0.931152f, 0.959961f, 0.974609f,
+ 0.981934f, 0.986816f, 0.989746f, 0.991699f, 0.993652f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000242f,
+ 0.000453f, 0.000539f, 0.000486f, 0.000487f, 0.000487f, 0.000957f, 0.000969f, 0.001202f, 0.001139f, 0.001393f, 0.001986f, 0.002045f,
+ 0.002863f, 0.003216f, 0.004128f, 0.005417f, 0.007378f, 0.009689f, 0.013466f, 0.020432f, 0.033722f, 0.060883f, 0.129395f, 0.318115f,
+ 0.642090f, 0.847656f, 0.926270f, 0.958008f, 0.973145f, 0.981934f, 0.986328f, 0.989746f, 0.992188f, 0.993164f, 0.994629f, 0.995605f,
+ 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000380f, 0.000482f, 0.000606f, 0.000607f, 0.000608f, 0.000829f, 0.000970f,
+ 0.000972f, 0.001070f, 0.001402f, 0.001812f, 0.002138f, 0.002619f, 0.003246f, 0.004082f, 0.005318f, 0.006699f, 0.009262f, 0.012764f,
+ 0.019318f, 0.031052f, 0.055878f, 0.116821f, 0.286621f, 0.610352f, 0.835938f, 0.922852f, 0.956543f, 0.973145f, 0.981445f, 0.986328f,
+ 0.989746f, 0.991699f, 0.993652f, 0.995117f, 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000243f, 0.000350f, 0.000480f,
+ 0.000605f, 0.000596f, 0.000608f, 0.000890f, 0.000963f, 0.000972f, 0.000974f, 0.001316f, 0.001798f, 0.002058f, 0.002560f, 0.002811f,
+ 0.003983f, 0.005108f, 0.006489f, 0.008888f, 0.012314f, 0.018021f, 0.029495f, 0.051941f, 0.107422f, 0.263428f, 0.585449f, 0.827148f,
+ 0.919434f, 0.956055f, 0.971680f, 0.981445f, 0.986816f, 0.989746f, 0.992188f, 0.994141f, 0.995117f, 0.995605f, 0.996582f, 0.996582f,
+ 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000130f, 0.000176f, 0.000462f, 0.000483f, 0.000604f, 0.000607f, 0.000638f, 0.000922f, 0.000965f, 0.000971f, 0.001235f,
+ 0.001376f, 0.001769f, 0.002041f, 0.002575f, 0.003130f, 0.003487f, 0.004936f, 0.006264f, 0.008415f, 0.012047f, 0.017517f, 0.027786f,
+ 0.049164f, 0.101257f, 0.249512f, 0.568848f, 0.821777f, 0.918945f, 0.956055f, 0.972168f, 0.981445f, 0.986816f, 0.990234f, 0.992188f,
+ 0.993652f, 0.995117f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000130f, 0.000122f, 0.000242f, 0.000352f, 0.000560f, 0.000602f, 0.000604f,
+ 0.000606f, 0.000767f, 0.001046f, 0.001089f, 0.000973f, 0.001327f, 0.001583f, 0.002033f, 0.002272f, 0.002657f, 0.003563f, 0.004589f,
+ 0.006138f, 0.008194f, 0.011299f, 0.016861f, 0.026718f, 0.047119f, 0.097656f, 0.240967f, 0.562500f, 0.821289f, 0.919922f, 0.957031f,
+ 0.973145f, 0.981934f, 0.987305f, 0.990234f, 0.992676f, 0.994141f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000241f, 0.000314f, 0.000459f, 0.000600f, 0.000605f, 0.000598f, 0.000804f, 0.000958f, 0.001084f, 0.001104f, 0.001389f, 0.001709f,
+ 0.002041f, 0.002211f, 0.002645f, 0.003635f, 0.004467f, 0.005718f, 0.008072f, 0.011185f, 0.016846f, 0.026184f, 0.046112f, 0.094971f,
+ 0.239014f, 0.565430f, 0.825684f, 0.922363f, 0.958496f, 0.973633f, 0.983398f, 0.987793f, 0.990723f, 0.992676f, 0.994141f, 0.995605f,
+ 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000238f, 0.000122f, 0.000173f, 0.000246f, 0.000387f, 0.000480f, 0.000604f, 0.000604f, 0.000701f,
+ 0.000951f, 0.000968f, 0.001184f, 0.001315f, 0.001597f, 0.001899f, 0.002268f, 0.002813f, 0.003716f, 0.004372f, 0.005886f, 0.007759f,
+ 0.010918f, 0.015915f, 0.025726f, 0.045685f, 0.095459f, 0.243774f, 0.579102f, 0.833984f, 0.926270f, 0.960449f, 0.976074f, 0.983887f,
+ 0.988770f, 0.991211f, 0.993164f, 0.994629f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999023f, 0.999512f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000238f, 0.000237f, 0.000242f,
+ 0.000463f, 0.000585f, 0.000587f, 0.000718f, 0.000607f, 0.000885f, 0.001081f, 0.001087f, 0.001299f, 0.001553f, 0.001982f, 0.002104f,
+ 0.002777f, 0.003494f, 0.004406f, 0.005798f, 0.007645f, 0.010750f, 0.016159f, 0.025467f, 0.045959f, 0.097778f, 0.256104f, 0.603516f,
+ 0.847168f, 0.931152f, 0.963379f, 0.977539f, 0.985352f, 0.989258f, 0.991699f, 0.993652f, 0.995117f, 0.996094f, 0.996582f, 0.997559f,
+ 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000231f, 0.000122f, 0.000242f, 0.000242f, 0.000400f, 0.000525f, 0.000495f, 0.000605f, 0.000607f, 0.000898f, 0.001075f,
+ 0.001191f, 0.001133f, 0.001420f, 0.001794f, 0.002041f, 0.002733f, 0.003548f, 0.004448f, 0.005585f, 0.007656f, 0.010735f, 0.015671f,
+ 0.025589f, 0.047363f, 0.102783f, 0.276855f, 0.637695f, 0.862793f, 0.938477f, 0.966797f, 0.979004f, 0.985840f, 0.990234f, 0.992676f,
+ 0.994141f, 0.995117f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000226f, 0.000242f, 0.000470f, 0.000469f,
+ 0.000547f, 0.000711f, 0.000723f, 0.000829f, 0.001024f, 0.001188f, 0.001081f, 0.001415f, 0.001765f, 0.002048f, 0.002708f, 0.003252f,
+ 0.004448f, 0.005711f, 0.007557f, 0.010780f, 0.016220f, 0.026398f, 0.048950f, 0.111267f, 0.309082f, 0.680664f, 0.880371f, 0.945801f,
+ 0.970703f, 0.980957f, 0.986816f, 0.990723f, 0.993164f, 0.994629f, 0.995605f, 0.996582f, 0.997559f, 0.998047f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000204f, 0.000239f, 0.000242f, 0.000283f, 0.000479f, 0.000594f, 0.000603f, 0.000606f, 0.000779f, 0.001068f, 0.001084f, 0.001118f,
+ 0.001515f, 0.001926f, 0.002098f, 0.002674f, 0.002975f, 0.004040f, 0.005478f, 0.007488f, 0.010651f, 0.016327f, 0.027222f, 0.052460f,
+ 0.123718f, 0.355713f, 0.729980f, 0.899902f, 0.952637f, 0.973145f, 0.983887f, 0.988770f, 0.991699f, 0.994141f, 0.995117f, 0.996094f,
+ 0.997070f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000122f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000236f, 0.000207f, 0.000240f, 0.000435f, 0.000534f, 0.000594f, 0.000602f,
+ 0.000722f, 0.000727f, 0.000947f, 0.001081f, 0.001090f, 0.001471f, 0.001829f, 0.002010f, 0.002478f, 0.002956f, 0.004051f, 0.005753f,
+ 0.007717f, 0.011040f, 0.017105f, 0.028748f, 0.057159f, 0.142944f, 0.421387f, 0.780762f, 0.916992f, 0.960449f, 0.976562f, 0.985352f,
+ 0.989746f, 0.992676f, 0.994629f, 0.996094f, 0.997070f, 0.997559f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000224f, 0.000232f,
+ 0.000230f, 0.000382f, 0.000472f, 0.000576f, 0.000715f, 0.000721f, 0.000727f, 0.001046f, 0.001078f, 0.001186f, 0.001434f, 0.001674f,
+ 0.002066f, 0.002546f, 0.003407f, 0.004181f, 0.005634f, 0.007542f, 0.011330f, 0.017609f, 0.031189f, 0.064392f, 0.172729f, 0.506836f,
+ 0.828125f, 0.933105f, 0.966309f, 0.980469f, 0.987305f, 0.991211f, 0.993652f, 0.995117f, 0.996582f, 0.997070f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000232f, 0.000234f, 0.000352f, 0.000461f, 0.000535f, 0.000594f, 0.000722f, 0.000725f,
+ 0.000921f, 0.001116f, 0.001192f, 0.001416f, 0.001637f, 0.001911f, 0.002380f, 0.002949f, 0.003948f, 0.005589f, 0.007942f, 0.011650f,
+ 0.018631f, 0.034302f, 0.075867f, 0.219238f, 0.607422f, 0.870605f, 0.946777f, 0.972656f, 0.983887f, 0.989258f, 0.992676f, 0.995117f,
+ 0.996094f, 0.997070f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000239f, 0.000302f,
+ 0.000396f, 0.000564f, 0.000674f, 0.000617f, 0.000722f, 0.001003f, 0.001068f, 0.001084f, 0.001302f, 0.001598f, 0.001929f, 0.002375f,
+ 0.002935f, 0.004349f, 0.005714f, 0.007957f, 0.012306f, 0.020493f, 0.039001f, 0.092590f, 0.293213f, 0.711426f, 0.905762f, 0.958984f,
+ 0.978027f, 0.986328f, 0.990723f, 0.994141f, 0.995605f, 0.996582f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000232f, 0.000227f, 0.000240f, 0.000282f, 0.000542f, 0.000703f, 0.000718f, 0.000724f, 0.000833f, 0.001069f,
+ 0.001184f, 0.001346f, 0.001464f, 0.001898f, 0.002649f, 0.003164f, 0.004467f, 0.005863f, 0.008400f, 0.013199f, 0.022614f, 0.046051f,
+ 0.120605f, 0.406738f, 0.801270f, 0.931641f, 0.968262f, 0.982422f, 0.988770f, 0.992676f, 0.994629f, 0.996094f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000120f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000219f, 0.000237f, 0.000235f, 0.000241f, 0.000480f,
+ 0.000584f, 0.000715f, 0.000723f, 0.000775f, 0.001061f, 0.000959f, 0.001139f, 0.001526f, 0.001770f, 0.002546f, 0.003151f, 0.004250f,
+ 0.006195f, 0.009071f, 0.014595f, 0.026413f, 0.056763f, 0.169067f, 0.557617f, 0.869141f, 0.951172f, 0.976074f, 0.986328f, 0.990723f,
+ 0.994141f, 0.995605f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000120f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000216f, 0.000228f, 0.000285f, 0.000339f, 0.000454f, 0.000572f, 0.000595f, 0.000721f, 0.000604f, 0.000930f, 0.000958f, 0.001171f,
+ 0.001431f, 0.001888f, 0.002663f, 0.003256f, 0.004402f, 0.006527f, 0.009964f, 0.016281f, 0.031189f, 0.074524f, 0.258301f, 0.714355f,
+ 0.916016f, 0.965332f, 0.982422f, 0.989746f, 0.992676f, 0.995117f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000063f, 0.000120f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000194f, 0.000184f, 0.000228f, 0.000340f, 0.000396f, 0.000668f, 0.000571f,
+ 0.000478f, 0.000602f, 0.000919f, 0.000956f, 0.001061f, 0.001497f, 0.001888f, 0.002565f, 0.003523f, 0.004578f, 0.006935f, 0.010765f,
+ 0.018417f, 0.038635f, 0.107727f, 0.416260f, 0.832520f, 0.946289f, 0.975586f, 0.986328f, 0.991699f, 0.994629f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000045f, 0.000118f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000234f, 0.000294f, 0.000220f, 0.000486f, 0.000579f, 0.000588f, 0.000669f, 0.000878f, 0.001038f, 0.001135f, 0.001451f, 0.001820f,
+ 0.002529f, 0.003551f, 0.005199f, 0.007542f, 0.012230f, 0.022369f, 0.051910f, 0.174927f, 0.630859f, 0.905273f, 0.965332f, 0.982910f,
+ 0.990234f, 0.993652f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000091f,
+ 0.000117f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000171f, 0.000151f, 0.000166f, 0.000195f, 0.000342f, 0.000452f, 0.000594f, 0.000599f,
+ 0.000862f, 0.001019f, 0.001135f, 0.001465f, 0.002031f, 0.002676f, 0.003714f, 0.005497f, 0.008286f, 0.014320f, 0.028854f, 0.077332f,
+ 0.322754f, 0.809082f, 0.946289f, 0.977051f, 0.987793f, 0.993164f, 0.998047f, 0.998535f, 0.998047f, 0.998047f, 0.998535f, 0.998047f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000079f, 0.000105f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000008f, 0.000006f, 0.000098f, 0.000137f,
+ 0.000233f, 0.000324f, 0.000566f, 0.000589f, 0.000618f, 0.000874f, 0.000941f, 0.001108f, 0.001621f, 0.001880f, 0.002726f, 0.003788f,
+ 0.005840f, 0.009583f, 0.017563f, 0.039368f, 0.133545f, 0.582520f, 0.906738f, 0.968262f, 0.984863f, 0.992188f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000069f, 0.000114f,
+ 0.000117f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000021f,
+ 0.000013f, 0.000009f, 0.000006f, 0.000004f, 0.000090f, 0.000206f, 0.000305f, 0.000538f, 0.000585f, 0.000596f, 0.000869f, 0.000941f,
+ 0.001149f, 0.001516f, 0.002150f, 0.002729f, 0.004475f, 0.006660f, 0.011360f, 0.022690f, 0.061401f, 0.281494f, 0.813965f, 0.952148f,
+ 0.980957f, 0.990723f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000006f, 0.000085f, 0.000114f, 0.000117f, 0.000119f, 0.000119f, 0.000120f, 0.000120f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000122f, 0.000122f, 0.000077f, 0.000041f, 0.000022f, 0.000013f, 0.000009f, 0.000006f, 0.000066f, 0.000107f, 0.000223f, 0.000250f,
+ 0.000532f, 0.000576f, 0.000593f, 0.000784f, 0.000937f, 0.001126f, 0.001523f, 0.002306f, 0.003193f, 0.004574f, 0.007717f, 0.014191f,
+ 0.032410f, 0.116577f, 0.595215f, 0.921875f, 0.974609f, 0.988770f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000056f, 0.000112f,
+ 0.000114f, 0.000118f, 0.000119f, 0.000120f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000074f, 0.000038f, 0.000021f, 0.000013f, 0.000009f,
+ 0.000006f, 0.000004f, 0.000003f, 0.000179f, 0.000258f, 0.000367f, 0.000469f, 0.000583f, 0.000770f, 0.000932f, 0.001131f, 0.001758f,
+ 0.002483f, 0.003517f, 0.005432f, 0.009232f, 0.019302f, 0.054504f, 0.293457f, 0.853516f, 0.964844f, 0.986816f, 0.997070f, 0.997070f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000015f, 0.000084f, 0.000107f, 0.000113f, 0.000117f, 0.000118f, 0.000119f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000076f, 0.000042f, 0.000023f, 0.000015f, 0.000009f, 0.000007f, 0.000005f, 0.000004f, 0.000147f, 0.000238f, 0.000457f, 0.000545f,
+ 0.000586f, 0.000821f, 0.000936f, 0.001139f, 0.001849f, 0.002665f, 0.003687f, 0.006367f, 0.011810f, 0.028931f, 0.120605f, 0.687988f,
+ 0.947754f, 0.982910f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000082f, 0.000095f,
+ 0.000111f, 0.000115f, 0.000117f, 0.000118f, 0.000119f, 0.000119f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000083f, 0.000042f, 0.000026f, 0.000015f, 0.000010f, 0.000007f, 0.000005f,
+ 0.000013f, 0.000086f, 0.000185f, 0.000309f, 0.000552f, 0.000577f, 0.000796f, 0.000925f, 0.001251f, 0.001838f, 0.002878f, 0.004509f,
+ 0.007572f, 0.016617f, 0.054932f, 0.391602f, 0.912109f, 0.978516f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996094f, 0.996094f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000095f, 0.000106f, 0.000112f, 0.000113f, 0.000115f, 0.000118f, 0.000118f,
+ 0.000119f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000099f, 0.000048f,
+ 0.000027f, 0.000017f, 0.000011f, 0.000008f, 0.000006f, 0.000004f, 0.000089f, 0.000182f, 0.000347f, 0.000495f, 0.000570f, 0.000777f,
+ 0.000922f, 0.001316f, 0.001831f, 0.003004f, 0.005028f, 0.010078f, 0.028183f, 0.161865f, 0.833496f, 0.972168f, 0.995117f, 0.995605f,
+ 0.995605f, 0.995117f, 0.995117f, 0.995605f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000074f,
+ 0.000093f, 0.000107f, 0.000111f, 0.000115f, 0.000116f, 0.000117f, 0.000118f, 0.000119f, 0.000119f, 0.000119f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000120f, 0.000120f, 0.000121f, 0.000057f, 0.000032f, 0.000021f, 0.000013f, 0.000008f, 0.000006f, 0.000005f, 0.000034f,
+ 0.000159f, 0.000267f, 0.000514f, 0.000566f, 0.000714f, 0.000888f, 0.001348f, 0.001995f, 0.003302f, 0.006447f, 0.015945f, 0.069153f,
+ 0.646484f, 0.960449f, 0.994629f, 0.995117f, 0.994629f, 0.995117f, 0.994629f, 0.995117f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000080f, 0.000095f, 0.000102f, 0.000109f, 0.000114f, 0.000115f,
+ 0.000116f, 0.000118f, 0.000118f, 0.000119f, 0.000119f, 0.000119f, 0.000120f, 0.000120f, 0.000120f, 0.000077f, 0.000044f, 0.000025f,
+ 0.000015f, 0.000011f, 0.000007f, 0.000005f, 0.000004f, 0.000106f, 0.000244f, 0.000476f, 0.000561f, 0.000622f, 0.000893f, 0.001266f,
+ 0.001968f, 0.003990f, 0.009476f, 0.033234f, 0.342529f, 0.940918f, 0.993652f, 0.993652f, 0.993652f, 0.993652f, 0.993652f, 0.993652f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000046f, 0.000079f, 0.000093f, 0.000104f, 0.000110f, 0.000111f, 0.000113f, 0.000116f, 0.000117f, 0.000118f, 0.000118f, 0.000119f,
+ 0.000119f, 0.000119f, 0.000092f, 0.000050f, 0.000029f, 0.000019f, 0.000012f, 0.000009f, 0.000006f, 0.000004f, 0.000061f, 0.000188f,
+ 0.000324f, 0.000456f, 0.000525f, 0.000657f, 0.001371f, 0.002445f, 0.005634f, 0.017563f, 0.135986f, 0.902832f, 0.992188f, 0.992188f,
+ 0.992676f, 0.992188f, 0.992676f, 0.992188f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000038f, 0.000075f, 0.000092f, 0.000100f, 0.000105f,
+ 0.000111f, 0.000112f, 0.000114f, 0.000116f, 0.000117f, 0.000117f, 0.000118f, 0.000118f, 0.000074f, 0.000041f, 0.000024f, 0.000016f,
+ 0.000010f, 0.000007f, 0.000005f, 0.000033f, 0.000167f, 0.000423f, 0.000410f, 0.000413f, 0.000575f, 0.001446f, 0.003387f, 0.009644f,
+ 0.056183f, 0.817383f, 0.990234f, 0.990234f, 0.990234f, 0.990723f, 0.990234f, 0.990723f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000011f, 0.000067f, 0.000084f, 0.000096f, 0.000103f, 0.000108f, 0.000110f, 0.000113f, 0.000115f, 0.000115f,
+ 0.000116f, 0.000104f, 0.000057f, 0.000035f, 0.000021f, 0.000013f, 0.000009f, 0.000006f, 0.000054f, 0.000161f, 0.000317f, 0.000332f,
+ 0.000393f, 0.000723f, 0.001760f, 0.005203f, 0.025345f, 0.617676f, 0.987793f, 0.987793f, 0.987793f, 0.988281f, 0.988281f, 0.988281f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000017f, 0.000052f, 0.000075f,
+ 0.000091f, 0.000097f, 0.000105f, 0.000108f, 0.000111f, 0.000113f, 0.000114f, 0.000085f, 0.000050f, 0.000031f, 0.000018f, 0.000012f,
+ 0.000008f, 0.000005f, 0.000095f, 0.000314f, 0.000306f, 0.000363f, 0.000813f, 0.002583f, 0.011734f, 0.308105f, 0.983887f, 0.984375f,
+ 0.984375f, 0.984375f, 0.983887f, 0.983887f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000037f, 0.000065f, 0.000083f, 0.000093f, 0.000099f, 0.000105f, 0.000108f,
+ 0.000110f, 0.000082f, 0.000045f, 0.000027f, 0.000017f, 0.000011f, 0.000007f, 0.000114f, 0.000245f, 0.000209f, 0.000379f, 0.001151f,
+ 0.005260f, 0.107971f, 0.977539f, 0.979004f, 0.978027f, 0.978027f, 0.978027f, 0.978027f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000007f, 0.000045f, 0.000069f, 0.000084f, 0.000093f, 0.000099f, 0.000104f, 0.000076f, 0.000044f, 0.000026f, 0.000016f, 0.000010f,
+ 0.000012f, 0.000152f, 0.000179f, 0.000373f, 0.001760f, 0.035522f, 0.969238f, 0.968750f, 0.968750f, 0.968750f, 0.968750f, 0.968750f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000014f, 0.000050f, 0.000070f, 0.000082f,
+ 0.000092f, 0.000075f, 0.000044f, 0.000026f, 0.000015f, 0.000009f, 0.000121f, 0.000117f, 0.000611f, 0.010231f, 0.951172f, 0.951172f,
+ 0.951172f, 0.951172f, 0.950684f, 0.951660f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000020f, 0.000047f, 0.000069f, 0.000077f, 0.000042f, 0.000024f, 0.000013f, 0.000078f,
+ 0.000130f, 0.001914f, 0.915039f, 0.915527f, 0.915039f, 0.915527f, 0.916016f, 0.915039f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000017f, 0.000047f, 0.000040f, 0.000019f, 0.000035f, 0.000188f, 0.833984f, 0.833496f, 0.833496f, 0.834473f, 0.834473f, 0.833984f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000014f, 0.000007f, 0.642578f, 0.643555f,
+ 0.643066f, 0.643555f, 0.642578f, 0.642578f,
+ },
+ {
+ 0.113464f, 0.797852f, 0.930176f, 0.961914f, 0.974609f, 0.980469f, 0.984863f, 0.987793f, 0.989258f, 0.991211f, 0.992188f, 0.993164f,
+ 0.993652f, 0.994141f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.007183f, 0.058716f, 0.349609f, 0.784668f, 0.912598f, 0.952148f, 0.968262f, 0.977539f,
+ 0.981934f, 0.985352f, 0.988281f, 0.990234f, 0.991211f, 0.992188f, 0.993652f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.995605f,
+ 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.002432f, 0.011818f, 0.039581f, 0.143677f,
+ 0.482910f, 0.800293f, 0.908691f, 0.947266f, 0.964844f, 0.974609f, 0.980469f, 0.984375f, 0.987305f, 0.989258f, 0.990723f, 0.991699f,
+ 0.992676f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.001096f, 0.005062f, 0.012482f, 0.030151f, 0.079956f, 0.239014f, 0.581055f, 0.819824f, 0.909180f, 0.946289f, 0.963379f, 0.973145f,
+ 0.979492f, 0.983398f, 0.986328f, 0.988281f, 0.990234f, 0.991699f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995605f, 0.996094f,
+ 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000610f, 0.002434f, 0.005779f, 0.012207f, 0.023972f, 0.052765f, 0.129883f, 0.342773f,
+ 0.660156f, 0.841309f, 0.914062f, 0.947266f, 0.963379f, 0.973145f, 0.979004f, 0.982910f, 0.985840f, 0.987793f, 0.989746f, 0.991211f,
+ 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000397f, 0.001559f, 0.003397f, 0.006058f,
+ 0.011177f, 0.020355f, 0.039307f, 0.083130f, 0.196777f, 0.452148f, 0.724121f, 0.862305f, 0.920410f, 0.949219f, 0.964355f, 0.973145f,
+ 0.979004f, 0.982910f, 0.985840f, 0.988770f, 0.989258f, 0.991211f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995605f, 0.995605f,
+ 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000366f, 0.001097f, 0.002163f, 0.003523f, 0.006268f, 0.010941f, 0.017487f, 0.030930f, 0.058411f, 0.122925f, 0.281738f, 0.556152f,
+ 0.776367f, 0.881348f, 0.928223f, 0.951660f, 0.966309f, 0.973633f, 0.979492f, 0.983398f, 0.986328f, 0.988281f, 0.989746f, 0.991211f,
+ 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000244f, 0.000728f, 0.001340f, 0.002533f, 0.003813f, 0.006081f, 0.009750f, 0.015419f,
+ 0.025177f, 0.044067f, 0.084473f, 0.179077f, 0.384033f, 0.649902f, 0.818848f, 0.897949f, 0.935547f, 0.956055f, 0.967285f, 0.975098f,
+ 0.980957f, 0.983887f, 0.986328f, 0.988281f, 0.990234f, 0.991699f, 0.992676f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000244f, 0.000609f, 0.000854f, 0.001898f,
+ 0.002781f, 0.004246f, 0.006218f, 0.008835f, 0.013504f, 0.021362f, 0.035400f, 0.062347f, 0.121460f, 0.255127f, 0.495361f, 0.726562f,
+ 0.852539f, 0.912598f, 0.943359f, 0.959473f, 0.969238f, 0.976562f, 0.981445f, 0.984375f, 0.987305f, 0.988770f, 0.990234f, 0.991699f,
+ 0.992676f, 0.993652f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000244f, 0.000244f, 0.000731f, 0.001295f, 0.002159f, 0.003092f, 0.004051f, 0.005836f, 0.008560f, 0.011925f, 0.018585f, 0.029373f,
+ 0.048950f, 0.088013f, 0.174194f, 0.354980f, 0.604492f, 0.788086f, 0.880371f, 0.925293f, 0.950195f, 0.963867f, 0.972168f, 0.978027f,
+ 0.982422f, 0.985840f, 0.987793f, 0.990234f, 0.991699f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000114f, 0.000244f, 0.000709f, 0.001089f, 0.001580f, 0.002100f, 0.002848f, 0.004028f,
+ 0.005646f, 0.008232f, 0.011276f, 0.016647f, 0.024948f, 0.039215f, 0.067566f, 0.125244f, 0.249878f, 0.471436f, 0.698242f, 0.834961f,
+ 0.902344f, 0.937012f, 0.955078f, 0.967773f, 0.974609f, 0.979492f, 0.983887f, 0.987305f, 0.988770f, 0.990723f, 0.991699f, 0.992676f,
+ 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000244f, 0.000480f, 0.001081f,
+ 0.001216f, 0.001684f, 0.002287f, 0.003113f, 0.004246f, 0.005711f, 0.007412f, 0.010658f, 0.014900f, 0.021408f, 0.033173f, 0.053711f,
+ 0.094299f, 0.179688f, 0.351807f, 0.591309f, 0.774902f, 0.871582f, 0.919922f, 0.946289f, 0.961426f, 0.971191f, 0.977051f, 0.981934f,
+ 0.984863f, 0.987305f, 0.989258f, 0.991211f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000364f, 0.000366f, 0.000729f, 0.001195f, 0.001218f, 0.001693f, 0.002209f, 0.003038f, 0.004192f, 0.005249f, 0.006981f,
+ 0.009926f, 0.013405f, 0.019165f, 0.028473f, 0.044250f, 0.073975f, 0.134521f, 0.260010f, 0.476562f, 0.696289f, 0.830566f, 0.898438f,
+ 0.933594f, 0.954102f, 0.966309f, 0.974609f, 0.979492f, 0.982910f, 0.986328f, 0.988281f, 0.989746f, 0.991699f, 0.992676f, 0.993652f,
+ 0.994141f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000226f, 0.000365f, 0.000488f, 0.000731f, 0.001090f, 0.001245f, 0.002028f,
+ 0.002169f, 0.003023f, 0.003952f, 0.005043f, 0.006790f, 0.009026f, 0.012276f, 0.016754f, 0.024628f, 0.037384f, 0.060120f, 0.104431f,
+ 0.196045f, 0.372803f, 0.604980f, 0.779785f, 0.872070f, 0.919922f, 0.945312f, 0.960938f, 0.970703f, 0.977539f, 0.980957f, 0.984863f,
+ 0.987305f, 0.989258f, 0.991211f, 0.992188f, 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f,
+ 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000364f, 0.000487f,
+ 0.000488f, 0.000608f, 0.001092f, 0.001323f, 0.001909f, 0.002028f, 0.002829f, 0.003754f, 0.004940f, 0.006329f, 0.008850f, 0.011353f,
+ 0.015572f, 0.022110f, 0.032196f, 0.050293f, 0.083984f, 0.151978f, 0.288574f, 0.507812f, 0.715332f, 0.839844f, 0.902832f, 0.936035f,
+ 0.955566f, 0.966797f, 0.974609f, 0.979492f, 0.983887f, 0.986816f, 0.988281f, 0.989746f, 0.991699f, 0.992676f, 0.993652f, 0.994141f,
+ 0.994629f, 0.995605f, 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000341f, 0.000486f, 0.000487f, 0.000591f, 0.000846f, 0.001213f, 0.001407f, 0.002018f, 0.002306f, 0.003119f,
+ 0.003736f, 0.004700f, 0.005936f, 0.007858f, 0.010498f, 0.013939f, 0.019913f, 0.028564f, 0.043060f, 0.069275f, 0.120972f, 0.225830f,
+ 0.416748f, 0.642090f, 0.798828f, 0.881836f, 0.924805f, 0.948730f, 0.962891f, 0.971191f, 0.978516f, 0.982422f, 0.985352f, 0.987793f,
+ 0.989746f, 0.991211f, 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996582f, 0.996582f, 0.996582f, 0.997070f,
+ 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000121f, 0.000122f, 0.000475f, 0.000486f, 0.000487f, 0.000714f, 0.000913f,
+ 0.001296f, 0.001350f, 0.001884f, 0.002163f, 0.002871f, 0.003702f, 0.004578f, 0.005573f, 0.007278f, 0.009819f, 0.013039f, 0.017883f,
+ 0.025589f, 0.037445f, 0.058655f, 0.099243f, 0.180542f, 0.338867f, 0.563965f, 0.751465f, 0.857422f, 0.912109f, 0.941406f, 0.958496f,
+ 0.968262f, 0.976074f, 0.980957f, 0.984375f, 0.986816f, 0.989258f, 0.990723f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000122f, 0.000242f,
+ 0.000417f, 0.000607f, 0.000602f, 0.000644f, 0.001016f, 0.001223f, 0.001337f, 0.002010f, 0.002087f, 0.002752f, 0.003380f, 0.004486f,
+ 0.005760f, 0.007523f, 0.009048f, 0.012169f, 0.016312f, 0.022949f, 0.033295f, 0.050812f, 0.082886f, 0.146851f, 0.275635f, 0.486572f,
+ 0.696777f, 0.828613f, 0.896484f, 0.933594f, 0.953613f, 0.965820f, 0.973633f, 0.979980f, 0.983887f, 0.986328f, 0.988770f, 0.990723f,
+ 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997559f, 0.997559f, 0.997559f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000262f, 0.000463f, 0.000603f, 0.000665f, 0.000716f, 0.001069f, 0.001322f, 0.001538f,
+ 0.001895f, 0.002293f, 0.003120f, 0.003323f, 0.004166f, 0.005638f, 0.006828f, 0.008942f, 0.011368f, 0.015465f, 0.021057f, 0.029663f,
+ 0.044861f, 0.070923f, 0.123169f, 0.228149f, 0.416504f, 0.640137f, 0.797363f, 0.880859f, 0.924805f, 0.948730f, 0.963379f, 0.971680f,
+ 0.978516f, 0.982422f, 0.985840f, 0.988281f, 0.990723f, 0.991699f, 0.992676f, 0.993652f, 0.994141f, 0.995117f, 0.995117f, 0.996094f,
+ 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000120f, 0.000172f, 0.000243f, 0.000365f, 0.000475f, 0.000607f,
+ 0.000608f, 0.000609f, 0.001013f, 0.001424f, 0.001456f, 0.001904f, 0.002411f, 0.002903f, 0.003145f, 0.004314f, 0.004944f, 0.006607f,
+ 0.008156f, 0.010719f, 0.014297f, 0.018906f, 0.027069f, 0.040070f, 0.062103f, 0.104858f, 0.191162f, 0.355469f, 0.581543f, 0.762695f,
+ 0.863281f, 0.915039f, 0.943848f, 0.960449f, 0.970703f, 0.977051f, 0.981445f, 0.985840f, 0.987793f, 0.989746f, 0.991211f, 0.992676f,
+ 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.997070f, 0.997070f, 0.998047f, 0.997559f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000000f, 0.000000f, 0.000096f,
+ 0.000239f, 0.000241f, 0.000336f, 0.000482f, 0.000719f, 0.000729f, 0.000831f, 0.001049f, 0.001552f, 0.001576f, 0.001710f, 0.002373f,
+ 0.002846f, 0.003254f, 0.004051f, 0.005035f, 0.006405f, 0.007706f, 0.009987f, 0.013092f, 0.017715f, 0.024872f, 0.035980f, 0.055328f,
+ 0.091248f, 0.163330f, 0.305664f, 0.524902f, 0.726562f, 0.845215f, 0.906250f, 0.938965f, 0.957031f, 0.969238f, 0.976074f, 0.981445f,
+ 0.984863f, 0.987305f, 0.989258f, 0.991211f, 0.992188f, 0.993164f, 0.994141f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f,
+ 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000118f, 0.000120f, 0.000351f, 0.000364f, 0.000421f, 0.000480f, 0.000606f, 0.000728f, 0.000852f,
+ 0.001175f, 0.001535f, 0.001673f, 0.001671f, 0.002277f, 0.002743f, 0.003220f, 0.003922f, 0.004868f, 0.005951f, 0.007488f, 0.009430f,
+ 0.012527f, 0.016266f, 0.022964f, 0.033142f, 0.049805f, 0.080688f, 0.141846f, 0.265625f, 0.473145f, 0.688477f, 0.825684f, 0.897949f,
+ 0.934082f, 0.954102f, 0.966797f, 0.975098f, 0.980469f, 0.984375f, 0.987305f, 0.989258f, 0.991211f, 0.992676f, 0.993164f, 0.993652f,
+ 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000058f, 0.000235f, 0.000360f, 0.000243f,
+ 0.000440f, 0.000583f, 0.000847f, 0.000851f, 0.000852f, 0.001189f, 0.001411f, 0.001645f, 0.001898f, 0.002417f, 0.002617f, 0.003435f,
+ 0.003695f, 0.004616f, 0.005733f, 0.007278f, 0.009216f, 0.012016f, 0.015701f, 0.021561f, 0.030396f, 0.045746f, 0.073120f, 0.125732f,
+ 0.233521f, 0.428223f, 0.653320f, 0.807617f, 0.887695f, 0.929688f, 0.951660f, 0.965820f, 0.974121f, 0.980469f, 0.984375f, 0.986816f,
+ 0.989746f, 0.991211f, 0.992676f, 0.993164f, 0.994141f, 0.995117f, 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000237f, 0.000237f, 0.000362f, 0.000365f, 0.000558f, 0.000814f, 0.000727f, 0.000729f, 0.000935f, 0.001189f, 0.001403f,
+ 0.001569f, 0.001989f, 0.002216f, 0.002533f, 0.003307f, 0.003906f, 0.004463f, 0.005646f, 0.006908f, 0.008980f, 0.011230f, 0.014755f,
+ 0.020020f, 0.028320f, 0.041931f, 0.065979f, 0.113098f, 0.209229f, 0.389648f, 0.620605f, 0.789551f, 0.879395f, 0.924805f, 0.950684f,
+ 0.964844f, 0.974121f, 0.979980f, 0.983398f, 0.987305f, 0.989258f, 0.991211f, 0.992676f, 0.993652f, 0.993652f, 0.995117f, 0.995605f,
+ 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000121f, 0.000241f, 0.000486f, 0.000575f, 0.000707f,
+ 0.000726f, 0.000971f, 0.000849f, 0.000966f, 0.001350f, 0.001660f, 0.001678f, 0.002224f, 0.002483f, 0.003197f, 0.003611f, 0.004200f,
+ 0.005318f, 0.006744f, 0.008476f, 0.010506f, 0.014145f, 0.019089f, 0.026627f, 0.039001f, 0.061096f, 0.103333f, 0.189819f, 0.358887f,
+ 0.591309f, 0.773438f, 0.872559f, 0.922363f, 0.948730f, 0.963867f, 0.973145f, 0.979492f, 0.983887f, 0.986816f, 0.989258f, 0.991211f,
+ 0.992188f, 0.993164f, 0.994629f, 0.995117f, 0.995605f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000175f, 0.000361f,
+ 0.000481f, 0.000485f, 0.000364f, 0.000562f, 0.000703f, 0.000827f, 0.000842f, 0.000972f, 0.001172f, 0.001321f, 0.001675f, 0.001684f,
+ 0.002153f, 0.002455f, 0.003122f, 0.003391f, 0.004177f, 0.005314f, 0.006325f, 0.007896f, 0.010368f, 0.013527f, 0.018082f, 0.025162f,
+ 0.037140f, 0.057343f, 0.095886f, 0.175659f, 0.334473f, 0.567871f, 0.760742f, 0.866699f, 0.919922f, 0.947754f, 0.963379f, 0.972656f,
+ 0.979492f, 0.984375f, 0.987305f, 0.989258f, 0.991211f, 0.992676f, 0.993652f, 0.994629f, 0.995117f, 0.996094f, 0.996582f, 0.997070f,
+ 0.998047f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000325f, 0.000311f, 0.000243f, 0.000484f, 0.000486f, 0.000536f, 0.000698f, 0.000723f, 0.000844f,
+ 0.000972f, 0.001081f, 0.001312f, 0.001658f, 0.001914f, 0.001932f, 0.002390f, 0.003017f, 0.003668f, 0.004353f, 0.005199f, 0.006336f,
+ 0.007812f, 0.009972f, 0.012802f, 0.017029f, 0.024200f, 0.035034f, 0.053833f, 0.090027f, 0.164185f, 0.316162f, 0.549805f, 0.751465f,
+ 0.863281f, 0.918457f, 0.947266f, 0.963379f, 0.974121f, 0.979492f, 0.984375f, 0.987793f, 0.989746f, 0.991699f, 0.993164f, 0.994141f,
+ 0.995117f, 0.995605f, 0.996094f, 0.997070f, 0.997559f, 0.997559f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000231f, 0.000453f, 0.000480f, 0.000484f,
+ 0.000485f, 0.000486f, 0.000917f, 0.000963f, 0.000969f, 0.000970f, 0.001043f, 0.001288f, 0.001523f, 0.001684f, 0.001885f, 0.002464f,
+ 0.002531f, 0.003565f, 0.004124f, 0.004745f, 0.006077f, 0.007580f, 0.009605f, 0.012634f, 0.016953f, 0.023346f, 0.033386f, 0.051697f,
+ 0.085632f, 0.156250f, 0.303955f, 0.537598f, 0.746582f, 0.860840f, 0.918457f, 0.947754f, 0.963867f, 0.973633f, 0.979980f, 0.984863f,
+ 0.987793f, 0.990234f, 0.991699f, 0.993652f, 0.994141f, 0.995117f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000235f, 0.000239f, 0.000359f, 0.000484f, 0.000485f, 0.000486f, 0.000628f, 0.000957f, 0.000967f, 0.000969f, 0.001065f,
+ 0.001288f, 0.001602f, 0.001850f, 0.001995f, 0.002409f, 0.002523f, 0.003462f, 0.003838f, 0.004993f, 0.005917f, 0.007233f, 0.009338f,
+ 0.012230f, 0.015610f, 0.022415f, 0.032288f, 0.049805f, 0.082947f, 0.151489f, 0.296631f, 0.532715f, 0.745117f, 0.862793f, 0.919434f,
+ 0.948242f, 0.964844f, 0.974609f, 0.980957f, 0.985352f, 0.988281f, 0.990723f, 0.992676f, 0.994141f, 0.994629f, 0.995605f, 0.996094f,
+ 0.996582f, 0.997070f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000187f, 0.000437f, 0.000473f, 0.000483f, 0.000485f, 0.000606f,
+ 0.000583f, 0.000711f, 0.000772f, 0.000968f, 0.001107f, 0.001287f, 0.001434f, 0.001662f, 0.001984f, 0.002449f, 0.002634f, 0.003145f,
+ 0.003777f, 0.004410f, 0.005722f, 0.007114f, 0.008926f, 0.011696f, 0.016006f, 0.021683f, 0.031342f, 0.048309f, 0.080750f, 0.149170f,
+ 0.294678f, 0.534668f, 0.749512f, 0.866211f, 0.922363f, 0.950684f, 0.966309f, 0.975586f, 0.981934f, 0.985840f, 0.989258f, 0.991699f,
+ 0.992676f, 0.994141f, 0.994629f, 0.996094f, 0.996582f, 0.997070f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000247f,
+ 0.000238f, 0.000407f, 0.000482f, 0.000484f, 0.000604f, 0.000869f, 0.000909f, 0.000721f, 0.000955f, 0.001000f, 0.001241f, 0.001342f,
+ 0.001655f, 0.001721f, 0.002329f, 0.002623f, 0.003086f, 0.003677f, 0.004349f, 0.005600f, 0.006962f, 0.008835f, 0.011581f, 0.015274f,
+ 0.021286f, 0.030884f, 0.047760f, 0.079895f, 0.148926f, 0.298584f, 0.543945f, 0.758301f, 0.872559f, 0.925781f, 0.953125f, 0.967773f,
+ 0.977051f, 0.982910f, 0.986816f, 0.989258f, 0.991211f, 0.993164f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000237f, 0.000410f, 0.000472f, 0.000481f, 0.000483f, 0.000485f, 0.000687f, 0.000913f,
+ 0.000956f, 0.000966f, 0.000997f, 0.001341f, 0.001415f, 0.001813f, 0.002029f, 0.002043f, 0.002594f, 0.003210f, 0.003641f, 0.004734f,
+ 0.005356f, 0.006882f, 0.008675f, 0.011360f, 0.014816f, 0.020920f, 0.030380f, 0.047485f, 0.080200f, 0.151733f, 0.308105f, 0.561523f,
+ 0.772949f, 0.881348f, 0.931152f, 0.956055f, 0.969727f, 0.978516f, 0.983887f, 0.987793f, 0.990234f, 0.992188f, 0.993652f, 0.994629f,
+ 0.995605f, 0.996094f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000254f, 0.000345f, 0.000468f,
+ 0.000585f, 0.000482f, 0.000603f, 0.000485f, 0.000862f, 0.000928f, 0.000965f, 0.001174f, 0.001162f, 0.001405f, 0.001761f, 0.002016f,
+ 0.002182f, 0.002733f, 0.002831f, 0.003504f, 0.004456f, 0.005440f, 0.006775f, 0.008553f, 0.011055f, 0.014694f, 0.020859f, 0.030334f,
+ 0.047852f, 0.081970f, 0.157593f, 0.325439f, 0.586914f, 0.790527f, 0.890137f, 0.936523f, 0.959473f, 0.973145f, 0.980469f, 0.985352f,
+ 0.988770f, 0.990723f, 0.992676f, 0.994141f, 0.995117f, 0.996094f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000241f, 0.000237f, 0.000340f, 0.000457f, 0.000580f, 0.000481f, 0.000601f, 0.000605f, 0.000742f, 0.000951f, 0.000953f,
+ 0.001131f, 0.001257f, 0.001396f, 0.001730f, 0.001936f, 0.002102f, 0.002682f, 0.002762f, 0.003733f, 0.004425f, 0.005344f, 0.006516f,
+ 0.008354f, 0.010971f, 0.014793f, 0.020859f, 0.030640f, 0.048859f, 0.085144f, 0.167358f, 0.350586f, 0.620117f, 0.811035f, 0.900391f,
+ 0.942383f, 0.963379f, 0.975098f, 0.981934f, 0.986816f, 0.989746f, 0.992188f, 0.993164f, 0.994629f, 0.995117f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000131f, 0.000301f, 0.000430f, 0.000470f, 0.000593f,
+ 0.000571f, 0.000587f, 0.000693f, 0.000906f, 0.000959f, 0.000965f, 0.001094f, 0.001364f, 0.001522f, 0.001783f, 0.002094f, 0.002615f,
+ 0.003038f, 0.003365f, 0.004307f, 0.005135f, 0.006493f, 0.008347f, 0.011055f, 0.014824f, 0.020844f, 0.031204f, 0.050507f, 0.090027f,
+ 0.182129f, 0.385498f, 0.659668f, 0.834473f, 0.913086f, 0.949219f, 0.967285f, 0.978027f, 0.983887f, 0.987793f, 0.991211f, 0.992188f,
+ 0.994141f, 0.995117f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000189f, 0.000122f, 0.000122f,
+ 0.000241f, 0.000295f, 0.000425f, 0.000457f, 0.000592f, 0.000481f, 0.000603f, 0.000697f, 0.000926f, 0.000943f, 0.000960f, 0.001022f,
+ 0.001435f, 0.001632f, 0.001658f, 0.002024f, 0.002468f, 0.003010f, 0.003210f, 0.004124f, 0.005219f, 0.006351f, 0.008163f, 0.010933f,
+ 0.015030f, 0.021271f, 0.032257f, 0.053009f, 0.097534f, 0.203003f, 0.432373f, 0.704102f, 0.858887f, 0.924805f, 0.955566f, 0.970703f,
+ 0.979492f, 0.985840f, 0.989258f, 0.991699f, 0.993164f, 0.995117f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000214f, 0.000201f, 0.000239f, 0.000241f, 0.000383f, 0.000461f, 0.000474f, 0.000479f, 0.000598f,
+ 0.000736f, 0.000905f, 0.000947f, 0.001072f, 0.001180f, 0.001376f, 0.001572f, 0.001752f, 0.001900f, 0.002258f, 0.002792f, 0.003487f,
+ 0.004055f, 0.005161f, 0.006424f, 0.008209f, 0.010933f, 0.015030f, 0.021942f, 0.033630f, 0.056671f, 0.107666f, 0.233276f, 0.492188f,
+ 0.752441f, 0.881836f, 0.937012f, 0.961914f, 0.975098f, 0.982910f, 0.987305f, 0.990234f, 0.992676f, 0.994629f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998047f, 0.998535f, 0.998535f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000132f, 0.000224f, 0.000129f, 0.000237f, 0.000240f,
+ 0.000337f, 0.000430f, 0.000468f, 0.000579f, 0.000593f, 0.000602f, 0.000881f, 0.000936f, 0.000956f, 0.000963f, 0.001282f, 0.001519f,
+ 0.001607f, 0.001852f, 0.002150f, 0.002737f, 0.003508f, 0.003990f, 0.005077f, 0.006516f, 0.008179f, 0.011185f, 0.015511f, 0.022446f,
+ 0.035614f, 0.061859f, 0.122681f, 0.275879f, 0.563965f, 0.798828f, 0.903809f, 0.946777f, 0.967773f, 0.978516f, 0.984863f, 0.988770f,
+ 0.991699f, 0.993652f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000149f, 0.000122f, 0.000207f, 0.000371f, 0.000430f, 0.000573f, 0.000591f, 0.000598f, 0.000597f, 0.000804f,
+ 0.000901f, 0.000948f, 0.001053f, 0.001083f, 0.001376f, 0.001584f, 0.001878f, 0.002331f, 0.002529f, 0.003376f, 0.003944f, 0.005230f,
+ 0.006504f, 0.008537f, 0.011459f, 0.015747f, 0.024002f, 0.038361f, 0.069458f, 0.144409f, 0.336914f, 0.644043f, 0.841797f, 0.922363f,
+ 0.957520f, 0.972656f, 0.981934f, 0.987305f, 0.990234f, 0.993164f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000230f, 0.000234f, 0.000235f, 0.000268f, 0.000400f,
+ 0.000448f, 0.000585f, 0.000590f, 0.000599f, 0.000641f, 0.000788f, 0.000930f, 0.000968f, 0.001107f, 0.001251f, 0.001656f, 0.001701f,
+ 0.002047f, 0.002691f, 0.003437f, 0.003998f, 0.004829f, 0.006329f, 0.008492f, 0.011757f, 0.016525f, 0.025345f, 0.042297f, 0.080200f,
+ 0.177490f, 0.420654f, 0.724121f, 0.878906f, 0.938965f, 0.964355f, 0.977539f, 0.984863f, 0.989746f, 0.992188f, 0.997559f, 0.997559f,
+ 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000214f, 0.000235f, 0.000228f, 0.000240f, 0.000429f, 0.000439f, 0.000574f, 0.000654f, 0.000583f, 0.000493f, 0.000788f, 0.000813f,
+ 0.000947f, 0.001062f, 0.001225f, 0.001569f, 0.001721f, 0.002048f, 0.002844f, 0.002979f, 0.003902f, 0.004997f, 0.006454f, 0.008698f,
+ 0.012192f, 0.018143f, 0.027634f, 0.047913f, 0.095886f, 0.228394f, 0.526855f, 0.796875f, 0.910156f, 0.953125f, 0.973145f, 0.982422f,
+ 0.987793f, 0.991699f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000205f, 0.000236f, 0.000232f, 0.000299f, 0.000446f, 0.000417f,
+ 0.000466f, 0.000580f, 0.000508f, 0.000710f, 0.000800f, 0.000940f, 0.000954f, 0.001228f, 0.001496f, 0.001631f, 0.002043f, 0.002798f,
+ 0.003359f, 0.004139f, 0.004951f, 0.006680f, 0.008995f, 0.012764f, 0.018860f, 0.030823f, 0.056061f, 0.120911f, 0.307617f, 0.645508f,
+ 0.855957f, 0.934082f, 0.964355f, 0.978516f, 0.985840f, 0.990234f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000226f,
+ 0.000122f, 0.000226f, 0.000373f, 0.000272f, 0.000325f, 0.000460f, 0.000471f, 0.000477f, 0.000673f, 0.000877f, 0.000929f, 0.000951f,
+ 0.001129f, 0.001446f, 0.001614f, 0.002096f, 0.002619f, 0.002939f, 0.003941f, 0.005363f, 0.006844f, 0.009491f, 0.013596f, 0.020905f,
+ 0.035370f, 0.068420f, 0.161743f, 0.426270f, 0.755859f, 0.900879f, 0.952148f, 0.973145f, 0.983398f, 0.989746f, 0.997070f, 0.997070f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000111f, 0.000236f, 0.000297f, 0.000368f, 0.000449f, 0.000467f,
+ 0.000588f, 0.000641f, 0.000813f, 0.000924f, 0.001035f, 0.001124f, 0.001348f, 0.001764f, 0.001922f, 0.002439f, 0.003160f, 0.004005f,
+ 0.005280f, 0.007107f, 0.010109f, 0.014748f, 0.023148f, 0.041595f, 0.088440f, 0.232910f, 0.578125f, 0.841797f, 0.933594f, 0.965820f,
+ 0.980469f, 0.987305f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000014f, 0.000011f, 0.000116f,
+ 0.000148f, 0.000128f, 0.000369f, 0.000418f, 0.000563f, 0.000470f, 0.000592f, 0.000776f, 0.000901f, 0.000937f, 0.001112f, 0.001348f,
+ 0.001743f, 0.001904f, 0.002470f, 0.003187f, 0.003986f, 0.005360f, 0.007557f, 0.010674f, 0.016068f, 0.026871f, 0.051666f, 0.122925f,
+ 0.356445f, 0.729492f, 0.901855f, 0.955078f, 0.976074f, 0.985840f, 0.996094f, 0.996582f, 0.996094f, 0.996582f, 0.996094f, 0.996582f,
+ 0.000122f, 0.000122f, 0.000121f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000028f, 0.000019f, 0.000014f, 0.000011f, 0.000033f, 0.000118f, 0.000247f, 0.000305f, 0.000412f, 0.000447f, 0.000576f, 0.000587f,
+ 0.000693f, 0.000850f, 0.000949f, 0.001083f, 0.001319f, 0.001557f, 0.001957f, 0.002424f, 0.003340f, 0.004417f, 0.005688f, 0.007774f,
+ 0.011497f, 0.017731f, 0.032257f, 0.068604f, 0.189575f, 0.541992f, 0.843262f, 0.938477f, 0.970703f, 0.983887f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.000121f, 0.000118f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000067f, 0.000042f, 0.000028f, 0.000020f, 0.000015f, 0.000066f, 0.000009f, 0.000101f, 0.000118f,
+ 0.000260f, 0.000358f, 0.000520f, 0.000456f, 0.000563f, 0.000711f, 0.000872f, 0.000980f, 0.001059f, 0.001309f, 0.001699f, 0.002066f,
+ 0.002708f, 0.003248f, 0.004166f, 0.005836f, 0.008224f, 0.012619f, 0.021484f, 0.041260f, 0.101074f, 0.323486f, 0.733887f, 0.912109f,
+ 0.962402f, 0.980957f, 0.995117f, 0.995117f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.000000f, 0.000000f, 0.000119f, 0.000119f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000105f, 0.000067f, 0.000042f, 0.000029f, 0.000022f,
+ 0.000015f, 0.000011f, 0.000040f, 0.000033f, 0.000153f, 0.000204f, 0.000313f, 0.000501f, 0.000554f, 0.000575f, 0.000585f, 0.000778f,
+ 0.000925f, 0.000980f, 0.001245f, 0.001634f, 0.001989f, 0.002413f, 0.003433f, 0.004028f, 0.005989f, 0.008911f, 0.014374f, 0.026443f,
+ 0.057495f, 0.170166f, 0.549805f, 0.864746f, 0.951172f, 0.977051f, 0.994629f, 0.994629f, 0.994629f, 0.994629f, 0.995605f, 0.994629f,
+ 0.000000f, 0.000046f, 0.000088f, 0.000118f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000108f, 0.000069f, 0.000047f, 0.000030f, 0.000022f, 0.000016f, 0.000012f, 0.000052f, 0.000081f, 0.000100f, 0.000184f, 0.000226f,
+ 0.000400f, 0.000467f, 0.000452f, 0.000597f, 0.000807f, 0.000895f, 0.000942f, 0.001219f, 0.001611f, 0.002022f, 0.002352f, 0.003222f,
+ 0.004177f, 0.006481f, 0.009850f, 0.017517f, 0.034668f, 0.090637f, 0.331055f, 0.776367f, 0.932129f, 0.972656f, 0.994141f, 0.994141f,
+ 0.994629f, 0.994141f, 0.994629f, 0.994629f, 0.000000f, 0.000000f, 0.000000f, 0.000107f, 0.000115f, 0.000112f, 0.000119f, 0.000118f,
+ 0.000119f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000117f, 0.000072f, 0.000049f, 0.000032f, 0.000023f, 0.000017f, 0.000013f,
+ 0.000011f, 0.000008f, 0.000075f, 0.000151f, 0.000207f, 0.000305f, 0.000509f, 0.000499f, 0.000560f, 0.000704f, 0.000863f, 0.000917f,
+ 0.001220f, 0.001505f, 0.001740f, 0.002174f, 0.003153f, 0.004559f, 0.007095f, 0.011826f, 0.022247f, 0.051147f, 0.173462f, 0.618652f,
+ 0.902344f, 0.966309f, 0.993164f, 0.993652f, 0.992676f, 0.992676f, 0.993164f, 0.993164f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000060f, 0.000102f, 0.000113f, 0.000117f, 0.000118f, 0.000119f, 0.000119f, 0.000119f, 0.000120f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000078f,
+ 0.000052f, 0.000038f, 0.000027f, 0.000019f, 0.000015f, 0.000011f, 0.000054f, 0.000007f, 0.000085f, 0.000108f, 0.000258f, 0.000466f,
+ 0.000533f, 0.000560f, 0.000662f, 0.000849f, 0.000856f, 0.000965f, 0.001180f, 0.001678f, 0.002075f, 0.003193f, 0.005016f, 0.008095f,
+ 0.014343f, 0.030899f, 0.090820f, 0.401367f, 0.848145f, 0.956543f, 0.992188f, 0.992188f, 0.992188f, 0.992676f, 0.991699f, 0.992188f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000059f, 0.000096f, 0.000107f, 0.000112f, 0.000115f, 0.000116f,
+ 0.000117f, 0.000118f, 0.000118f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000088f, 0.000059f, 0.000041f, 0.000031f, 0.000022f, 0.000017f, 0.000013f, 0.000010f,
+ 0.000056f, 0.000091f, 0.000183f, 0.000201f, 0.000309f, 0.000506f, 0.000547f, 0.000525f, 0.000629f, 0.000613f, 0.000817f, 0.001012f,
+ 0.001640f, 0.002420f, 0.003588f, 0.005520f, 0.009453f, 0.019119f, 0.050415f, 0.214722f, 0.751465f, 0.943848f, 0.990723f, 0.990723f,
+ 0.991211f, 0.991211f, 0.991211f, 0.991211f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000055f, 0.000095f, 0.000103f, 0.000105f, 0.000112f, 0.000114f, 0.000115f, 0.000117f, 0.000117f, 0.000117f, 0.000118f,
+ 0.000118f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000120f, 0.000120f, 0.000105f, 0.000069f, 0.000048f,
+ 0.000035f, 0.000025f, 0.000019f, 0.000015f, 0.000011f, 0.000014f, 0.000008f, 0.000071f, 0.000193f, 0.000311f, 0.000315f, 0.000524f,
+ 0.000483f, 0.000558f, 0.000591f, 0.000705f, 0.000950f, 0.001389f, 0.002428f, 0.003494f, 0.006321f, 0.012306f, 0.029480f, 0.108948f,
+ 0.581543f, 0.924316f, 0.989746f, 0.989746f, 0.989258f, 0.989746f, 0.989258f, 0.989746f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000069f, 0.000096f, 0.000103f, 0.000107f,
+ 0.000109f, 0.000112f, 0.000113f, 0.000115f, 0.000115f, 0.000116f, 0.000117f, 0.000117f, 0.000118f, 0.000118f, 0.000118f, 0.000118f,
+ 0.000119f, 0.000119f, 0.000119f, 0.000084f, 0.000061f, 0.000042f, 0.000031f, 0.000023f, 0.000018f, 0.000014f, 0.000011f, 0.000009f,
+ 0.000095f, 0.000127f, 0.000223f, 0.000402f, 0.000432f, 0.000399f, 0.000494f, 0.000535f, 0.000557f, 0.000933f, 0.001474f, 0.002300f,
+ 0.004192f, 0.007919f, 0.017838f, 0.057068f, 0.360840f, 0.890625f, 0.986816f, 0.987793f, 0.987305f, 0.987305f, 0.987793f, 0.987305f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000035f, 0.000041f, 0.000088f, 0.000098f, 0.000103f, 0.000106f, 0.000110f, 0.000110f, 0.000113f, 0.000113f,
+ 0.000115f, 0.000116f, 0.000116f, 0.000117f, 0.000117f, 0.000117f, 0.000117f, 0.000118f, 0.000111f, 0.000074f, 0.000053f, 0.000038f,
+ 0.000029f, 0.000022f, 0.000016f, 0.000013f, 0.000010f, 0.000008f, 0.000073f, 0.000152f, 0.000296f, 0.000369f, 0.000365f, 0.000437f,
+ 0.000507f, 0.000661f, 0.000876f, 0.001451f, 0.002531f, 0.004898f, 0.010384f, 0.031113f, 0.183838f, 0.833008f, 0.984375f, 0.984863f,
+ 0.984863f, 0.984375f, 0.984863f, 0.984863f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000024f, 0.000044f, 0.000073f,
+ 0.000087f, 0.000097f, 0.000102f, 0.000105f, 0.000108f, 0.000110f, 0.000111f, 0.000113f, 0.000114f, 0.000114f, 0.000115f, 0.000115f,
+ 0.000116f, 0.000116f, 0.000101f, 0.000070f, 0.000052f, 0.000037f, 0.000027f, 0.000021f, 0.000016f, 0.000013f, 0.000010f, 0.000008f,
+ 0.000083f, 0.000183f, 0.000352f, 0.000355f, 0.000362f, 0.000365f, 0.000528f, 0.000790f, 0.001469f, 0.003029f, 0.005970f, 0.017242f,
+ 0.089050f, 0.728516f, 0.980957f, 0.981445f, 0.981445f, 0.980957f, 0.980957f, 0.981445f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000033f, 0.000041f, 0.000073f, 0.000083f, 0.000088f, 0.000097f, 0.000102f,
+ 0.000105f, 0.000108f, 0.000108f, 0.000111f, 0.000112f, 0.000113f, 0.000113f, 0.000114f, 0.000097f, 0.000068f, 0.000049f, 0.000038f,
+ 0.000028f, 0.000021f, 0.000016f, 0.000013f, 0.000010f, 0.000056f, 0.000151f, 0.000243f, 0.000264f, 0.000221f, 0.000328f, 0.000449f,
+ 0.000850f, 0.001612f, 0.003340f, 0.009361f, 0.043121f, 0.548340f, 0.976074f, 0.976562f, 0.975586f, 0.976074f, 0.976074f, 0.976562f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000019f, 0.000052f, 0.000065f, 0.000077f, 0.000088f, 0.000094f, 0.000098f, 0.000100f, 0.000104f, 0.000106f, 0.000108f,
+ 0.000109f, 0.000110f, 0.000095f, 0.000069f, 0.000052f, 0.000037f, 0.000028f, 0.000021f, 0.000017f, 0.000013f, 0.000025f, 0.000063f,
+ 0.000195f, 0.000233f, 0.000205f, 0.000264f, 0.000401f, 0.000789f, 0.001532f, 0.004520f, 0.020844f, 0.321289f, 0.969238f, 0.968750f,
+ 0.969238f, 0.968750f, 0.969238f, 0.969238f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000018f, 0.000039f, 0.000053f,
+ 0.000066f, 0.000079f, 0.000086f, 0.000090f, 0.000096f, 0.000100f, 0.000102f, 0.000105f, 0.000098f, 0.000074f, 0.000053f, 0.000041f,
+ 0.000031f, 0.000023f, 0.000017f, 0.000013f, 0.000028f, 0.000139f, 0.000189f, 0.000179f, 0.000219f, 0.000333f, 0.000840f, 0.002119f,
+ 0.009193f, 0.144775f, 0.958496f, 0.958496f, 0.958008f, 0.958496f, 0.958008f, 0.958008f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000025f, 0.000040f, 0.000052f, 0.000067f, 0.000077f, 0.000082f,
+ 0.000089f, 0.000093f, 0.000097f, 0.000079f, 0.000059f, 0.000044f, 0.000033f, 0.000024f, 0.000018f, 0.000014f, 0.000034f, 0.000084f,
+ 0.000157f, 0.000199f, 0.000309f, 0.000817f, 0.003424f, 0.054901f, 0.940918f, 0.940918f, 0.940918f, 0.940918f, 0.941406f, 0.940430f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000021f, 0.000040f, 0.000054f, 0.000063f, 0.000072f, 0.000078f, 0.000085f, 0.000065f, 0.000049f,
+ 0.000036f, 0.000026f, 0.000019f, 0.000014f, 0.000042f, 0.000114f, 0.000122f, 0.000276f, 0.001024f, 0.016357f, 0.912109f, 0.912598f,
+ 0.911621f, 0.912598f, 0.911621f, 0.913086f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000016f, 0.000032f, 0.000045f, 0.000056f, 0.000065f, 0.000054f, 0.000039f, 0.000028f, 0.000019f, 0.000013f, 0.000049f, 0.000079f,
+ 0.000226f, 0.003199f, 0.860840f, 0.859863f, 0.860352f, 0.860840f, 0.860840f, 0.860352f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000004f, 0.000021f, 0.000035f,
+ 0.000040f, 0.000027f, 0.000018f, 0.000013f, 0.000033f, 0.000333f, 0.764160f, 0.765137f, 0.764648f, 0.764648f, 0.764648f, 0.765137f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000006f, 0.000011f, 0.000009f, 0.600586f, 0.602051f,
+ 0.602051f, 0.601562f, 0.601074f, 0.601074f,
+ },
+ {
+ 0.142456f, 0.713867f, 0.883789f, 0.933105f, 0.953613f, 0.964844f, 0.972168f, 0.977539f, 0.980957f, 0.983398f, 0.985352f, 0.987305f,
+ 0.989258f, 0.989746f, 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.993652f, 0.994141f, 0.995117f, 0.995117f, 0.995605f,
+ 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.012886f, 0.087646f, 0.360840f, 0.709473f, 0.859863f, 0.916992f, 0.943848f, 0.958496f,
+ 0.967773f, 0.973633f, 0.978516f, 0.980957f, 0.984375f, 0.986328f, 0.987793f, 0.988770f, 0.990234f, 0.991211f, 0.992188f, 0.993164f,
+ 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997070f,
+ 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.003895f, 0.020126f, 0.063599f, 0.188721f,
+ 0.464844f, 0.727539f, 0.853027f, 0.909668f, 0.938477f, 0.954590f, 0.965332f, 0.971680f, 0.976562f, 0.979980f, 0.982910f, 0.985840f,
+ 0.986816f, 0.988770f, 0.990234f, 0.990723f, 0.991699f, 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f,
+ 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.002062f, 0.008438f, 0.021774f, 0.049713f, 0.117676f, 0.279541f, 0.541016f, 0.751465f, 0.855469f, 0.909180f, 0.936035f, 0.952637f,
+ 0.963379f, 0.970703f, 0.975098f, 0.979492f, 0.982910f, 0.984863f, 0.986328f, 0.987793f, 0.989258f, 0.990234f, 0.990723f, 0.992188f,
+ 0.992676f, 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.995117f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.997070f,
+ 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.001335f, 0.004597f, 0.010628f, 0.020844f, 0.040283f, 0.082764f, 0.177612f, 0.366211f,
+ 0.605469f, 0.773926f, 0.863281f, 0.910156f, 0.936035f, 0.952148f, 0.962402f, 0.969727f, 0.975098f, 0.979004f, 0.982422f, 0.984863f,
+ 0.986328f, 0.988281f, 0.988770f, 0.989746f, 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.995117f,
+ 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000851f, 0.002769f, 0.006130f, 0.010994f,
+ 0.019394f, 0.034943f, 0.063293f, 0.122253f, 0.244019f, 0.448242f, 0.660156f, 0.798828f, 0.872559f, 0.914062f, 0.937988f, 0.954102f,
+ 0.961914f, 0.970215f, 0.974609f, 0.978516f, 0.981934f, 0.984375f, 0.986328f, 0.987793f, 0.988770f, 0.989746f, 0.991211f, 0.991699f,
+ 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f,
+ 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000466f, 0.001933f, 0.003809f, 0.007095f, 0.011353f, 0.018204f, 0.030029f, 0.050568f, 0.090759f, 0.170898f, 0.318848f, 0.526367f,
+ 0.708496f, 0.820801f, 0.884277f, 0.918457f, 0.940918f, 0.954102f, 0.963867f, 0.970215f, 0.975098f, 0.978516f, 0.981934f, 0.984863f,
+ 0.986328f, 0.988281f, 0.988770f, 0.990234f, 0.991211f, 0.991699f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.994629f, 0.995605f,
+ 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000487f, 0.001685f, 0.002766f, 0.004467f, 0.007305f, 0.011215f, 0.017136f, 0.026489f,
+ 0.042419f, 0.071716f, 0.125244f, 0.228271f, 0.399658f, 0.599609f, 0.751953f, 0.842773f, 0.894531f, 0.924805f, 0.943359f, 0.955566f,
+ 0.965820f, 0.971191f, 0.976562f, 0.979980f, 0.981934f, 0.984863f, 0.986816f, 0.988281f, 0.989258f, 0.990723f, 0.991211f, 0.992188f,
+ 0.992676f, 0.993652f, 0.994141f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997070f,
+ 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000244f, 0.000965f, 0.002024f, 0.003202f,
+ 0.005009f, 0.007050f, 0.011070f, 0.015869f, 0.023987f, 0.036835f, 0.058563f, 0.097168f, 0.169800f, 0.297852f, 0.484131f, 0.664062f,
+ 0.789062f, 0.861816f, 0.905273f, 0.930176f, 0.947266f, 0.958984f, 0.967285f, 0.972168f, 0.976562f, 0.980469f, 0.982910f, 0.984863f,
+ 0.986816f, 0.988770f, 0.989746f, 0.990723f, 0.992188f, 0.992188f, 0.993652f, 0.993652f, 0.994629f, 0.995117f, 0.995117f, 0.995605f,
+ 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000244f, 0.000974f, 0.001576f, 0.002403f, 0.003510f, 0.005344f, 0.007332f, 0.010567f, 0.015099f, 0.022064f, 0.032104f, 0.048706f,
+ 0.078003f, 0.130249f, 0.224243f, 0.378174f, 0.566406f, 0.720703f, 0.820312f, 0.879883f, 0.915039f, 0.936523f, 0.951660f, 0.961426f,
+ 0.968262f, 0.974121f, 0.978027f, 0.980957f, 0.983887f, 0.985840f, 0.987793f, 0.989258f, 0.990234f, 0.991211f, 0.992188f, 0.992676f,
+ 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997070f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000240f, 0.000609f, 0.001096f, 0.001580f, 0.002674f, 0.004131f, 0.005245f, 0.007660f,
+ 0.010757f, 0.014221f, 0.019775f, 0.028381f, 0.041870f, 0.064697f, 0.103638f, 0.173706f, 0.293945f, 0.466553f, 0.642090f, 0.769531f,
+ 0.849121f, 0.895996f, 0.924316f, 0.942871f, 0.956055f, 0.963867f, 0.970703f, 0.975098f, 0.979004f, 0.981934f, 0.984863f, 0.986328f,
+ 0.988770f, 0.989746f, 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000000f, 0.000608f, 0.001062f, 0.001268f,
+ 0.002001f, 0.003099f, 0.003937f, 0.005379f, 0.007595f, 0.010078f, 0.013176f, 0.018524f, 0.025787f, 0.036896f, 0.054932f, 0.085327f,
+ 0.137573f, 0.229980f, 0.376953f, 0.555664f, 0.708984f, 0.810547f, 0.873047f, 0.909180f, 0.933594f, 0.948730f, 0.959961f, 0.967285f,
+ 0.973145f, 0.977539f, 0.980469f, 0.983398f, 0.985840f, 0.986816f, 0.988770f, 0.989746f, 0.991211f, 0.992188f, 0.993164f, 0.993652f,
+ 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000244f, 0.000606f, 0.000609f, 0.001317f, 0.001564f, 0.002674f, 0.003273f, 0.004402f, 0.005630f, 0.007141f, 0.009514f, 0.012398f,
+ 0.016678f, 0.023331f, 0.032776f, 0.047363f, 0.071594f, 0.112610f, 0.183960f, 0.303711f, 0.470215f, 0.639648f, 0.766113f, 0.844727f,
+ 0.892090f, 0.921875f, 0.941895f, 0.954590f, 0.963379f, 0.970215f, 0.975098f, 0.979004f, 0.981934f, 0.984863f, 0.986328f, 0.987793f,
+ 0.989746f, 0.991211f, 0.991699f, 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.996094f,
+ 0.996582f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000244f, 0.000244f, 0.000727f, 0.000803f, 0.001575f, 0.002035f, 0.002821f, 0.003527f,
+ 0.004475f, 0.005421f, 0.007023f, 0.009491f, 0.011879f, 0.015976f, 0.021530f, 0.029587f, 0.041809f, 0.061737f, 0.094360f, 0.150146f,
+ 0.246460f, 0.393066f, 0.566406f, 0.712891f, 0.812500f, 0.872070f, 0.909180f, 0.933105f, 0.948242f, 0.959961f, 0.967773f, 0.972656f,
+ 0.977539f, 0.980957f, 0.982910f, 0.986328f, 0.987305f, 0.988770f, 0.989746f, 0.991211f, 0.992188f, 0.993164f, 0.993652f, 0.994629f,
+ 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000244f, 0.000244f, 0.000471f, 0.000727f,
+ 0.000967f, 0.001572f, 0.002161f, 0.002680f, 0.003246f, 0.004337f, 0.005241f, 0.006950f, 0.009087f, 0.011497f, 0.015038f, 0.019913f,
+ 0.026688f, 0.037537f, 0.054352f, 0.080383f, 0.125122f, 0.202515f, 0.327148f, 0.493652f, 0.656250f, 0.774414f, 0.849609f, 0.895508f,
+ 0.923828f, 0.942383f, 0.954590f, 0.963867f, 0.971191f, 0.975586f, 0.979004f, 0.982422f, 0.984863f, 0.987305f, 0.988281f, 0.989746f,
+ 0.990723f, 0.992188f, 0.992676f, 0.993652f, 0.994141f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999023f,
+ 0.000121f, 0.000244f, 0.000244f, 0.000715f, 0.001089f, 0.001278f, 0.001781f, 0.002275f, 0.002548f, 0.003334f, 0.004150f, 0.005314f,
+ 0.006824f, 0.008430f, 0.011200f, 0.014145f, 0.018631f, 0.024750f, 0.033905f, 0.047760f, 0.069885f, 0.106445f, 0.169312f, 0.273682f,
+ 0.426270f, 0.596191f, 0.732422f, 0.823242f, 0.879883f, 0.914062f, 0.936035f, 0.950684f, 0.960938f, 0.968750f, 0.973633f, 0.978516f,
+ 0.981934f, 0.984375f, 0.986328f, 0.988281f, 0.989258f, 0.990234f, 0.991699f, 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995117f,
+ 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999512f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999023f, 0.000241f, 0.000244f, 0.000365f, 0.000600f, 0.000961f, 0.000972f, 0.001621f, 0.001697f,
+ 0.002274f, 0.002684f, 0.003359f, 0.004238f, 0.005573f, 0.006691f, 0.008057f, 0.010529f, 0.013832f, 0.017593f, 0.022812f, 0.031174f,
+ 0.042786f, 0.061462f, 0.092407f, 0.143799f, 0.231201f, 0.366943f, 0.535645f, 0.688477f, 0.794922f, 0.861816f, 0.902832f, 0.928711f,
+ 0.945801f, 0.957520f, 0.966797f, 0.972656f, 0.976562f, 0.980469f, 0.983398f, 0.985840f, 0.987793f, 0.989258f, 0.990234f, 0.991699f,
+ 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.997070f, 0.997070f, 0.997559f, 0.997559f,
+ 0.998047f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000243f, 0.000365f, 0.000365f,
+ 0.000798f, 0.000968f, 0.001249f, 0.001528f, 0.001798f, 0.002457f, 0.002798f, 0.003494f, 0.004353f, 0.005306f, 0.006363f, 0.008141f,
+ 0.010147f, 0.012596f, 0.016006f, 0.021423f, 0.028503f, 0.039185f, 0.055420f, 0.081116f, 0.124390f, 0.198120f, 0.316895f, 0.478516f,
+ 0.641113f, 0.763672f, 0.842773f, 0.891113f, 0.921387f, 0.941406f, 0.954590f, 0.963867f, 0.970215f, 0.975586f, 0.979492f, 0.982910f,
+ 0.985352f, 0.987305f, 0.988770f, 0.989746f, 0.991211f, 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f,
+ 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000238f, 0.000365f, 0.000365f, 0.000598f, 0.000820f, 0.001200f, 0.001279f, 0.001631f, 0.001736f, 0.002172f, 0.002874f,
+ 0.003576f, 0.004391f, 0.005096f, 0.006176f, 0.007545f, 0.009674f, 0.012505f, 0.015945f, 0.020187f, 0.026550f, 0.035706f, 0.049835f,
+ 0.072510f, 0.109253f, 0.171631f, 0.275391f, 0.426514f, 0.594238f, 0.730469f, 0.822754f, 0.877930f, 0.913574f, 0.936523f, 0.951172f,
+ 0.961426f, 0.969727f, 0.974609f, 0.978027f, 0.982422f, 0.984863f, 0.986816f, 0.988770f, 0.989746f, 0.991699f, 0.992188f, 0.993164f,
+ 0.993652f, 0.994629f, 0.994629f, 0.995117f, 0.996094f, 0.996094f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000364f, 0.000486f, 0.000487f, 0.000562f, 0.000822f, 0.000967f,
+ 0.001213f, 0.001871f, 0.001803f, 0.002485f, 0.002796f, 0.003410f, 0.004242f, 0.005070f, 0.006153f, 0.007698f, 0.009262f, 0.011635f,
+ 0.014709f, 0.019104f, 0.024521f, 0.033295f, 0.045746f, 0.065674f, 0.096741f, 0.150635f, 0.241455f, 0.380127f, 0.548828f, 0.698242f,
+ 0.802246f, 0.867188f, 0.906738f, 0.931152f, 0.948242f, 0.959473f, 0.967285f, 0.973633f, 0.978516f, 0.981445f, 0.984375f, 0.986328f,
+ 0.988281f, 0.989258f, 0.990723f, 0.992188f, 0.993164f, 0.993652f, 0.994629f, 0.994629f, 0.995117f, 0.996094f, 0.996582f, 0.996582f,
+ 0.997559f, 0.997559f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000350f, 0.000483f,
+ 0.000486f, 0.000604f, 0.000743f, 0.001093f, 0.001187f, 0.001297f, 0.001601f, 0.001921f, 0.002501f, 0.002922f, 0.003296f, 0.004200f,
+ 0.005211f, 0.006054f, 0.007603f, 0.008904f, 0.011169f, 0.014091f, 0.017685f, 0.023331f, 0.030991f, 0.042358f, 0.059326f, 0.087646f,
+ 0.134521f, 0.213867f, 0.341309f, 0.506348f, 0.665039f, 0.780762f, 0.854492f, 0.899414f, 0.927246f, 0.945312f, 0.957520f, 0.966309f,
+ 0.973145f, 0.977539f, 0.981445f, 0.984375f, 0.986328f, 0.988770f, 0.989746f, 0.991211f, 0.992188f, 0.993164f, 0.993652f, 0.994629f,
+ 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000000f, 0.000120f, 0.000360f, 0.000485f, 0.000486f, 0.000487f, 0.000604f, 0.000947f, 0.001201f, 0.001374f, 0.001715f,
+ 0.002127f, 0.002239f, 0.002876f, 0.003426f, 0.004063f, 0.005276f, 0.005810f, 0.006744f, 0.008713f, 0.010597f, 0.013680f, 0.016754f,
+ 0.021744f, 0.028778f, 0.039093f, 0.054901f, 0.079956f, 0.121399f, 0.191895f, 0.307861f, 0.468262f, 0.633301f, 0.760742f, 0.842285f,
+ 0.892090f, 0.923340f, 0.942383f, 0.956543f, 0.965332f, 0.972168f, 0.977539f, 0.980469f, 0.983887f, 0.985840f, 0.988281f, 0.989746f,
+ 0.990723f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000121f, 0.000219f, 0.000474f, 0.000484f, 0.000486f, 0.000487f,
+ 0.000720f, 0.001108f, 0.001199f, 0.001209f, 0.001689f, 0.002253f, 0.002489f, 0.002916f, 0.003714f, 0.004040f, 0.005054f, 0.006001f,
+ 0.006737f, 0.008713f, 0.010376f, 0.012665f, 0.016251f, 0.020615f, 0.027145f, 0.036499f, 0.050720f, 0.073181f, 0.110474f, 0.174072f,
+ 0.280518f, 0.434570f, 0.604980f, 0.742188f, 0.830566f, 0.885742f, 0.918945f, 0.940918f, 0.954102f, 0.964355f, 0.971680f, 0.977051f,
+ 0.980957f, 0.984375f, 0.986816f, 0.988281f, 0.989746f, 0.990723f, 0.992188f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996582f, 0.997070f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000000f, 0.000120f, 0.000239f,
+ 0.000319f, 0.000475f, 0.000484f, 0.000485f, 0.000618f, 0.000844f, 0.001094f, 0.001201f, 0.001570f, 0.001782f, 0.002010f, 0.002407f,
+ 0.003046f, 0.003099f, 0.004208f, 0.004700f, 0.005882f, 0.006878f, 0.007980f, 0.009949f, 0.012344f, 0.015358f, 0.019821f, 0.026047f,
+ 0.034271f, 0.047455f, 0.067993f, 0.102112f, 0.160034f, 0.258057f, 0.406494f, 0.578613f, 0.723633f, 0.820312f, 0.880371f, 0.916016f,
+ 0.938965f, 0.953125f, 0.963867f, 0.971191f, 0.976562f, 0.980469f, 0.983887f, 0.985840f, 0.988770f, 0.989746f, 0.991699f, 0.992676f,
+ 0.993652f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.999023f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000242f, 0.000455f, 0.000481f, 0.000583f, 0.000601f, 0.000804f, 0.000912f, 0.001247f,
+ 0.001319f, 0.001571f, 0.001793f, 0.002337f, 0.002464f, 0.003099f, 0.003164f, 0.003809f, 0.004627f, 0.005764f, 0.006397f, 0.008118f,
+ 0.009605f, 0.011917f, 0.015083f, 0.018692f, 0.024384f, 0.032806f, 0.044983f, 0.063477f, 0.095337f, 0.148560f, 0.240112f, 0.382324f,
+ 0.556641f, 0.708984f, 0.812500f, 0.875488f, 0.913574f, 0.937500f, 0.953125f, 0.963867f, 0.971191f, 0.977051f, 0.980957f, 0.983887f,
+ 0.986816f, 0.988281f, 0.990234f, 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.995605f, 0.995605f, 0.996094f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000240f, 0.000242f, 0.000524f, 0.000597f,
+ 0.000604f, 0.000606f, 0.000674f, 0.001040f, 0.001238f, 0.001427f, 0.001637f, 0.001670f, 0.002104f, 0.002432f, 0.002775f, 0.003416f,
+ 0.003860f, 0.004482f, 0.005573f, 0.006374f, 0.007828f, 0.009384f, 0.011635f, 0.014175f, 0.018219f, 0.023224f, 0.031052f, 0.042603f,
+ 0.060730f, 0.089661f, 0.139526f, 0.225464f, 0.363525f, 0.538574f, 0.696289f, 0.806152f, 0.872559f, 0.912109f, 0.937012f, 0.952637f,
+ 0.963867f, 0.971191f, 0.976562f, 0.981445f, 0.984863f, 0.987305f, 0.988770f, 0.990723f, 0.992188f, 0.993164f, 0.994141f, 0.994629f,
+ 0.995117f, 0.996094f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000119f,
+ 0.000192f, 0.000240f, 0.000242f, 0.000535f, 0.000478f, 0.000600f, 0.000843f, 0.000925f, 0.001027f, 0.001236f, 0.001502f, 0.001490f,
+ 0.001658f, 0.002256f, 0.002430f, 0.002880f, 0.003056f, 0.003983f, 0.004292f, 0.005333f, 0.006264f, 0.007393f, 0.009064f, 0.011131f,
+ 0.013741f, 0.017242f, 0.022690f, 0.029922f, 0.040680f, 0.057831f, 0.085022f, 0.132446f, 0.214844f, 0.349121f, 0.524414f, 0.688477f,
+ 0.801758f, 0.871094f, 0.912109f, 0.937500f, 0.953125f, 0.964355f, 0.971680f, 0.977539f, 0.981445f, 0.985352f, 0.987305f, 0.989258f,
+ 0.991211f, 0.992188f, 0.993652f, 0.994629f, 0.995117f, 0.995605f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000119f, 0.000232f, 0.000233f, 0.000363f, 0.000457f, 0.000714f, 0.000724f, 0.000727f,
+ 0.000847f, 0.000992f, 0.001177f, 0.001525f, 0.001560f, 0.001740f, 0.002090f, 0.002329f, 0.002718f, 0.003372f, 0.003902f, 0.004307f,
+ 0.005184f, 0.005886f, 0.007446f, 0.008667f, 0.010574f, 0.013588f, 0.016556f, 0.021744f, 0.028854f, 0.039124f, 0.055176f, 0.081726f,
+ 0.127075f, 0.206421f, 0.338867f, 0.515625f, 0.683105f, 0.800293f, 0.870605f, 0.912598f, 0.937500f, 0.954590f, 0.965332f, 0.973145f,
+ 0.978516f, 0.982422f, 0.985840f, 0.988281f, 0.989746f, 0.991211f, 0.992676f, 0.993652f, 0.994141f, 0.995117f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000103f, 0.000120f, 0.000240f, 0.000240f,
+ 0.000484f, 0.000574f, 0.000596f, 0.000837f, 0.000820f, 0.000859f, 0.000985f, 0.001070f, 0.001509f, 0.001554f, 0.001785f, 0.002214f,
+ 0.002476f, 0.002754f, 0.002991f, 0.003487f, 0.004303f, 0.005074f, 0.005920f, 0.007126f, 0.008743f, 0.010361f, 0.013023f, 0.016403f,
+ 0.021011f, 0.027817f, 0.037811f, 0.053375f, 0.079041f, 0.123291f, 0.201172f, 0.333252f, 0.511719f, 0.682129f, 0.801270f, 0.872070f,
+ 0.914062f, 0.939941f, 0.955078f, 0.966309f, 0.973633f, 0.979004f, 0.982910f, 0.986328f, 0.988770f, 0.990234f, 0.991699f, 0.992676f,
+ 0.993652f, 0.995117f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000079f, 0.000053f, 0.000118f, 0.000418f, 0.000358f, 0.000363f, 0.000678f, 0.000708f, 0.000825f, 0.000838f, 0.000878f, 0.001146f,
+ 0.000978f, 0.001483f, 0.001541f, 0.001769f, 0.001812f, 0.002434f, 0.002699f, 0.003225f, 0.003298f, 0.004002f, 0.004948f, 0.005932f,
+ 0.007084f, 0.008461f, 0.010414f, 0.012665f, 0.015915f, 0.020615f, 0.027023f, 0.036743f, 0.051941f, 0.077332f, 0.120789f, 0.198608f,
+ 0.331543f, 0.512695f, 0.686523f, 0.805664f, 0.875488f, 0.917480f, 0.941406f, 0.957031f, 0.968262f, 0.975098f, 0.980469f, 0.983887f,
+ 0.986816f, 0.989258f, 0.990723f, 0.992188f, 0.993164f, 0.994629f, 0.998047f, 0.998047f, 0.998535f, 0.998047f, 0.998535f, 0.998535f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000109f, 0.000232f, 0.000349f, 0.000478f, 0.000483f, 0.000483f, 0.000609f,
+ 0.000795f, 0.000835f, 0.000806f, 0.000726f, 0.001022f, 0.001222f, 0.001442f, 0.001536f, 0.001650f, 0.001714f, 0.002377f, 0.002588f,
+ 0.003159f, 0.003643f, 0.004036f, 0.004929f, 0.005718f, 0.006813f, 0.008072f, 0.009880f, 0.012527f, 0.015854f, 0.020035f, 0.026352f,
+ 0.035950f, 0.051178f, 0.076416f, 0.119751f, 0.198730f, 0.334229f, 0.519531f, 0.694824f, 0.812988f, 0.880859f, 0.920898f, 0.944336f,
+ 0.958984f, 0.969727f, 0.976562f, 0.980957f, 0.984863f, 0.987793f, 0.989746f, 0.991211f, 0.992676f, 0.993652f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000068f, 0.000265f,
+ 0.000361f, 0.000478f, 0.000480f, 0.000479f, 0.000568f, 0.000693f, 0.000714f, 0.000806f, 0.000843f, 0.000919f, 0.001222f, 0.001376f,
+ 0.001531f, 0.001554f, 0.001987f, 0.002342f, 0.002558f, 0.002798f, 0.003132f, 0.004021f, 0.004864f, 0.005455f, 0.006664f, 0.008110f,
+ 0.009613f, 0.011955f, 0.015335f, 0.019608f, 0.025879f, 0.035522f, 0.050629f, 0.075623f, 0.120239f, 0.201416f, 0.342041f, 0.533203f,
+ 0.707031f, 0.821777f, 0.887695f, 0.925293f, 0.946777f, 0.961914f, 0.971680f, 0.977539f, 0.982422f, 0.985352f, 0.988281f, 0.989746f,
+ 0.992188f, 0.993164f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000000f, 0.000122f, 0.000322f, 0.000241f, 0.000478f, 0.000480f, 0.000480f, 0.000510f, 0.000695f, 0.000710f,
+ 0.000958f, 0.000765f, 0.001075f, 0.001116f, 0.001318f, 0.001606f, 0.001546f, 0.001916f, 0.002306f, 0.002499f, 0.002905f, 0.003202f,
+ 0.003914f, 0.004498f, 0.005459f, 0.006611f, 0.007687f, 0.009331f, 0.011757f, 0.014923f, 0.019241f, 0.025833f, 0.035492f, 0.050507f,
+ 0.076233f, 0.122131f, 0.207153f, 0.355225f, 0.551758f, 0.724609f, 0.833496f, 0.894531f, 0.930664f, 0.951660f, 0.964844f, 0.973145f,
+ 0.979492f, 0.983887f, 0.986816f, 0.989258f, 0.991211f, 0.993164f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.997559f, 0.997559f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000351f, 0.000458f, 0.000476f,
+ 0.000480f, 0.000482f, 0.000528f, 0.000650f, 0.000704f, 0.000956f, 0.000828f, 0.000963f, 0.001111f, 0.001265f, 0.001474f, 0.001806f,
+ 0.001872f, 0.002308f, 0.002445f, 0.002701f, 0.003229f, 0.003851f, 0.004375f, 0.005356f, 0.006317f, 0.007458f, 0.009300f, 0.011574f,
+ 0.014725f, 0.019165f, 0.025696f, 0.035461f, 0.050812f, 0.077637f, 0.125977f, 0.216797f, 0.374756f, 0.576660f, 0.745117f, 0.848145f,
+ 0.904785f, 0.936523f, 0.956055f, 0.967773f, 0.975586f, 0.980957f, 0.984863f, 0.987793f, 0.990234f, 0.992188f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000292f, 0.000224f, 0.000452f, 0.000453f, 0.000479f, 0.000480f, 0.000517f, 0.000614f, 0.000902f, 0.000712f, 0.000959f,
+ 0.000978f, 0.001100f, 0.001276f, 0.001461f, 0.001524f, 0.001651f, 0.002041f, 0.002350f, 0.002853f, 0.003433f, 0.003622f, 0.004166f,
+ 0.005043f, 0.006187f, 0.007534f, 0.009209f, 0.011551f, 0.014908f, 0.019012f, 0.025406f, 0.035461f, 0.051575f, 0.079651f, 0.131714f,
+ 0.230957f, 0.401367f, 0.607910f, 0.769531f, 0.863281f, 0.914062f, 0.942871f, 0.959961f, 0.970703f, 0.978027f, 0.982910f, 0.986816f,
+ 0.988770f, 0.991699f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000238f, 0.000355f, 0.000449f, 0.000462f, 0.000474f, 0.000477f,
+ 0.000482f, 0.000846f, 0.000726f, 0.000706f, 0.000953f, 0.000889f, 0.001012f, 0.001259f, 0.001390f, 0.001755f, 0.001658f, 0.002060f,
+ 0.002369f, 0.002539f, 0.003170f, 0.003460f, 0.004131f, 0.004993f, 0.006008f, 0.007431f, 0.009109f, 0.011444f, 0.014252f, 0.019058f,
+ 0.025574f, 0.036011f, 0.053162f, 0.083435f, 0.140381f, 0.250488f, 0.436035f, 0.645996f, 0.795898f, 0.880371f, 0.924316f, 0.949219f,
+ 0.963867f, 0.973145f, 0.980469f, 0.984863f, 0.988281f, 0.990723f, 0.997070f, 0.997559f, 0.997070f, 0.997559f, 0.997559f, 0.997070f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000239f,
+ 0.000306f, 0.000440f, 0.000437f, 0.000474f, 0.000478f, 0.000481f, 0.000523f, 0.000664f, 0.000731f, 0.000802f, 0.000935f, 0.001022f,
+ 0.001173f, 0.001314f, 0.001504f, 0.001831f, 0.001984f, 0.002317f, 0.002472f, 0.003199f, 0.003370f, 0.004189f, 0.004868f, 0.005924f,
+ 0.007320f, 0.008926f, 0.011421f, 0.014595f, 0.019119f, 0.026260f, 0.036987f, 0.055176f, 0.088440f, 0.152466f, 0.277832f, 0.479980f,
+ 0.686523f, 0.823242f, 0.895508f, 0.933105f, 0.955566f, 0.969238f, 0.976562f, 0.982422f, 0.986816f, 0.989746f, 0.996582f, 0.997070f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000194f, 0.000280f, 0.000417f, 0.000448f, 0.000468f, 0.000476f, 0.000479f, 0.000490f,
+ 0.000845f, 0.000688f, 0.000740f, 0.000945f, 0.000998f, 0.001148f, 0.001266f, 0.001414f, 0.001475f, 0.001667f, 0.002262f, 0.002537f,
+ 0.003019f, 0.003288f, 0.004223f, 0.004768f, 0.005890f, 0.007259f, 0.009026f, 0.011360f, 0.014297f, 0.019272f, 0.026474f, 0.038116f,
+ 0.058197f, 0.095032f, 0.168945f, 0.313965f, 0.533203f, 0.731445f, 0.850098f, 0.911133f, 0.942871f, 0.961914f, 0.972656f, 0.979980f,
+ 0.984863f, 0.988770f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.000000f, 0.000000f, 0.000122f, 0.000000f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000187f, 0.000233f, 0.000141f, 0.000271f, 0.000341f,
+ 0.000380f, 0.000465f, 0.000473f, 0.000590f, 0.000605f, 0.000798f, 0.000847f, 0.000934f, 0.000946f, 0.000836f, 0.001009f, 0.001142f,
+ 0.001430f, 0.001495f, 0.001850f, 0.002111f, 0.002541f, 0.003035f, 0.003300f, 0.004139f, 0.004913f, 0.005718f, 0.007141f, 0.008934f,
+ 0.011475f, 0.014832f, 0.019653f, 0.027573f, 0.039917f, 0.062225f, 0.104919f, 0.192017f, 0.362305f, 0.594238f, 0.775879f, 0.875977f,
+ 0.925293f, 0.952148f, 0.967773f, 0.977051f, 0.983398f, 0.988281f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996094f, 0.996582f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000238f, 0.000243f, 0.000238f, 0.000424f, 0.000453f, 0.000467f, 0.000475f, 0.000581f, 0.000689f, 0.000795f,
+ 0.000634f, 0.000823f, 0.001014f, 0.000900f, 0.001083f, 0.001485f, 0.001731f, 0.001851f, 0.002056f, 0.002373f, 0.002621f, 0.003445f,
+ 0.004082f, 0.004578f, 0.005821f, 0.007217f, 0.008881f, 0.011330f, 0.014778f, 0.020416f, 0.028473f, 0.042419f, 0.067993f, 0.118286f,
+ 0.225342f, 0.425293f, 0.661621f, 0.818848f, 0.899902f, 0.939453f, 0.960449f, 0.973145f, 0.980957f, 0.985840f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000205f, 0.000224f, 0.000122f, 0.000231f, 0.000245f, 0.000411f, 0.000520f,
+ 0.000463f, 0.000470f, 0.000587f, 0.000361f, 0.000712f, 0.000694f, 0.000815f, 0.000978f, 0.001055f, 0.001105f, 0.001390f, 0.001438f,
+ 0.001705f, 0.001984f, 0.002333f, 0.002546f, 0.003408f, 0.003876f, 0.004627f, 0.005783f, 0.007198f, 0.008995f, 0.011383f, 0.015396f,
+ 0.020828f, 0.030029f, 0.045654f, 0.075439f, 0.137451f, 0.271973f, 0.503418f, 0.728516f, 0.857910f, 0.920410f, 0.951172f, 0.968262f,
+ 0.977539f, 0.984375f, 0.995117f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000173f, 0.000150f, 0.000278f, 0.000376f, 0.000427f, 0.000470f, 0.000352f, 0.000356f, 0.000475f, 0.000441f, 0.000709f, 0.000774f,
+ 0.000970f, 0.001013f, 0.000998f, 0.001193f, 0.001397f, 0.001677f, 0.001957f, 0.002268f, 0.002529f, 0.003353f, 0.003874f, 0.004555f,
+ 0.005692f, 0.007160f, 0.008987f, 0.011543f, 0.015732f, 0.021896f, 0.032135f, 0.050140f, 0.086548f, 0.165894f, 0.337646f, 0.593750f,
+ 0.791504f, 0.892090f, 0.938477f, 0.961914f, 0.974609f, 0.982422f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.995117f, 0.995605f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000187f, 0.000130f, 0.000231f, 0.000315f, 0.000298f, 0.000332f, 0.000343f,
+ 0.000465f, 0.000472f, 0.000579f, 0.000717f, 0.000839f, 0.000932f, 0.000817f, 0.001086f, 0.001090f, 0.001545f, 0.001735f, 0.001837f,
+ 0.002485f, 0.002493f, 0.003288f, 0.003828f, 0.004520f, 0.005833f, 0.007156f, 0.009193f, 0.012123f, 0.015839f, 0.022934f, 0.034760f,
+ 0.056488f, 0.102600f, 0.208862f, 0.427734f, 0.687988f, 0.846191f, 0.919434f, 0.952637f, 0.969727f, 0.979980f, 0.993652f, 0.994629f,
+ 0.994141f, 0.994629f, 0.994629f, 0.994629f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000133f,
+ 0.000141f, 0.000234f, 0.000300f, 0.000397f, 0.000436f, 0.000456f, 0.000465f, 0.000534f, 0.000663f, 0.000810f, 0.000796f, 0.000812f,
+ 0.001062f, 0.001237f, 0.001428f, 0.001565f, 0.001818f, 0.002182f, 0.002783f, 0.002943f, 0.003773f, 0.004715f, 0.005482f, 0.007195f,
+ 0.009285f, 0.012207f, 0.016922f, 0.024567f, 0.038483f, 0.066101f, 0.127563f, 0.274170f, 0.540527f, 0.774414f, 0.891113f, 0.940430f,
+ 0.965332f, 0.977539f, 0.993652f, 0.994141f, 0.994629f, 0.994141f, 0.994629f, 0.994141f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000124f, 0.000116f, 0.000119f, 0.000125f, 0.000121f, 0.000197f, 0.000323f, 0.000418f, 0.000446f, 0.000433f,
+ 0.000467f, 0.000612f, 0.000710f, 0.000783f, 0.000911f, 0.000817f, 0.001161f, 0.001343f, 0.001514f, 0.001707f, 0.002081f, 0.002386f,
+ 0.002882f, 0.003609f, 0.004627f, 0.005478f, 0.007011f, 0.009384f, 0.012695f, 0.017960f, 0.026901f, 0.044067f, 0.080078f, 0.167114f,
+ 0.374023f, 0.664062f, 0.845703f, 0.923340f, 0.957031f, 0.974121f, 0.992676f, 0.993652f, 0.993164f, 0.993652f, 0.993652f, 0.993164f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000121f, 0.000121f, 0.000052f, 0.000039f, 0.000029f, 0.000054f, 0.000045f, 0.000118f,
+ 0.000128f, 0.000231f, 0.000387f, 0.000429f, 0.000446f, 0.000544f, 0.000539f, 0.000648f, 0.000749f, 0.000790f, 0.000978f, 0.001102f,
+ 0.001195f, 0.001501f, 0.001761f, 0.001978f, 0.002661f, 0.003170f, 0.003519f, 0.004509f, 0.005344f, 0.007004f, 0.009361f, 0.013229f,
+ 0.019196f, 0.030258f, 0.052002f, 0.102661f, 0.234131f, 0.511230f, 0.774902f, 0.898438f, 0.947754f, 0.970215f, 0.992188f, 0.992676f,
+ 0.993164f, 0.992676f, 0.992188f, 0.992188f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000070f, 0.000052f,
+ 0.000038f, 0.000030f, 0.000023f, 0.000060f, 0.000116f, 0.000121f, 0.000252f, 0.000337f, 0.000306f, 0.000435f, 0.000450f, 0.000562f,
+ 0.000584f, 0.000722f, 0.000858f, 0.000888f, 0.000969f, 0.001230f, 0.001429f, 0.001576f, 0.001827f, 0.002361f, 0.002863f, 0.003267f,
+ 0.004047f, 0.005394f, 0.007256f, 0.009781f, 0.013855f, 0.021439f, 0.035034f, 0.065063f, 0.141724f, 0.346680f, 0.665527f, 0.859375f,
+ 0.934570f, 0.965820f, 0.991699f, 0.991699f, 0.991699f, 0.992188f, 0.991699f, 0.991699f, 0.000000f, 0.000000f, 0.000122f, 0.000121f,
+ 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000099f, 0.000069f, 0.000051f, 0.000039f, 0.000030f, 0.000023f, 0.000024f, 0.000115f, 0.000103f, 0.000224f,
+ 0.000204f, 0.000339f, 0.000407f, 0.000437f, 0.000452f, 0.000489f, 0.000663f, 0.000821f, 0.000922f, 0.001004f, 0.001086f, 0.001279f,
+ 0.001554f, 0.001651f, 0.001997f, 0.002390f, 0.003136f, 0.004223f, 0.005508f, 0.007339f, 0.010094f, 0.014854f, 0.024048f, 0.042664f,
+ 0.087036f, 0.213867f, 0.516113f, 0.799805f, 0.915527f, 0.958984f, 0.990723f, 0.991211f, 0.990723f, 0.990723f, 0.990723f, 0.991211f,
+ 0.000000f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000096f, 0.000073f, 0.000053f, 0.000040f, 0.000031f,
+ 0.000025f, 0.000020f, 0.000017f, 0.000105f, 0.000110f, 0.000135f, 0.000235f, 0.000380f, 0.000462f, 0.000513f, 0.000556f, 0.000638f,
+ 0.000804f, 0.000868f, 0.000897f, 0.001002f, 0.001079f, 0.001246f, 0.001596f, 0.002153f, 0.002213f, 0.003094f, 0.004158f, 0.005306f,
+ 0.007458f, 0.010887f, 0.017166f, 0.028748f, 0.055176f, 0.128174f, 0.350586f, 0.703613f, 0.888184f, 0.951172f, 0.988770f, 0.989746f,
+ 0.989746f, 0.989746f, 0.989746f, 0.989746f, 0.000122f, 0.000120f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000101f, 0.000073f, 0.000057f, 0.000043f, 0.000033f, 0.000027f, 0.000021f, 0.000018f, 0.000105f, 0.000112f, 0.000111f, 0.000161f,
+ 0.000320f, 0.000390f, 0.000421f, 0.000438f, 0.000559f, 0.000665f, 0.000735f, 0.000719f, 0.000704f, 0.000887f, 0.001223f, 0.001384f,
+ 0.001867f, 0.002462f, 0.003216f, 0.004032f, 0.005367f, 0.007988f, 0.012054f, 0.019943f, 0.035919f, 0.078064f, 0.215332f, 0.566895f,
+ 0.845703f, 0.939941f, 0.987793f, 0.988281f, 0.987793f, 0.987793f, 0.988281f, 0.988281f, 0.000000f, 0.000120f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000103f, 0.000077f, 0.000061f, 0.000046f, 0.000037f, 0.000030f, 0.000023f,
+ 0.000019f, 0.000016f, 0.000039f, 0.000094f, 0.000181f, 0.000205f, 0.000350f, 0.000392f, 0.000423f, 0.000510f, 0.000619f, 0.000672f,
+ 0.000705f, 0.000632f, 0.000807f, 0.001038f, 0.001278f, 0.001894f, 0.002245f, 0.002758f, 0.003883f, 0.005863f, 0.008636f, 0.013672f,
+ 0.023880f, 0.048828f, 0.127441f, 0.400879f, 0.779297f, 0.925781f, 0.985840f, 0.986328f, 0.986328f, 0.985840f, 0.986328f, 0.986328f,
+ 0.000000f, 0.000100f, 0.000108f, 0.000118f, 0.000119f, 0.000118f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000111f, 0.000086f,
+ 0.000066f, 0.000051f, 0.000041f, 0.000032f, 0.000026f, 0.000021f, 0.000018f, 0.000015f, 0.000086f, 0.000131f, 0.000190f, 0.000293f,
+ 0.000419f, 0.000481f, 0.000477f, 0.000438f, 0.000542f, 0.000564f, 0.000599f, 0.000700f, 0.000916f, 0.001122f, 0.001589f, 0.001997f,
+ 0.002678f, 0.004017f, 0.005814f, 0.009361f, 0.015808f, 0.031250f, 0.075989f, 0.250732f, 0.676758f, 0.904297f, 0.983887f, 0.983887f,
+ 0.983887f, 0.984375f, 0.984375f, 0.983887f, 0.000000f, 0.000000f, 0.000077f, 0.000112f, 0.000104f, 0.000115f, 0.000115f, 0.000117f,
+ 0.000117f, 0.000117f, 0.000118f, 0.000118f, 0.000118f, 0.000118f, 0.000119f, 0.000118f, 0.000119f, 0.000119f, 0.000119f, 0.000119f,
+ 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000097f, 0.000076f, 0.000060f, 0.000046f, 0.000037f, 0.000030f, 0.000024f, 0.000020f,
+ 0.000045f, 0.000063f, 0.000091f, 0.000140f, 0.000202f, 0.000333f, 0.000305f, 0.000399f, 0.000462f, 0.000452f, 0.000535f, 0.000531f,
+ 0.000631f, 0.000866f, 0.000858f, 0.001307f, 0.001844f, 0.002823f, 0.004070f, 0.006264f, 0.010536f, 0.020035f, 0.045990f, 0.145996f,
+ 0.532227f, 0.874023f, 0.980957f, 0.981445f, 0.980957f, 0.981445f, 0.980957f, 0.981445f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000091f, 0.000103f, 0.000105f, 0.000106f, 0.000111f, 0.000113f, 0.000115f, 0.000114f, 0.000116f, 0.000116f, 0.000117f, 0.000117f,
+ 0.000117f, 0.000117f, 0.000117f, 0.000118f, 0.000118f, 0.000118f, 0.000118f, 0.000118f, 0.000118f, 0.000112f, 0.000084f, 0.000069f,
+ 0.000055f, 0.000043f, 0.000036f, 0.000028f, 0.000024f, 0.000020f, 0.000028f, 0.000039f, 0.000083f, 0.000141f, 0.000211f, 0.000262f,
+ 0.000413f, 0.000305f, 0.000370f, 0.000358f, 0.000489f, 0.000564f, 0.000599f, 0.000893f, 0.001084f, 0.001696f, 0.002697f, 0.004074f,
+ 0.006836f, 0.012878f, 0.028122f, 0.083496f, 0.364014f, 0.826660f, 0.976562f, 0.977539f, 0.977051f, 0.977539f, 0.978027f, 0.977051f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000015f, 0.000086f, 0.000077f, 0.000103f, 0.000100f, 0.000109f,
+ 0.000110f, 0.000111f, 0.000112f, 0.000112f, 0.000114f, 0.000114f, 0.000115f, 0.000115f, 0.000116f, 0.000115f, 0.000116f, 0.000116f,
+ 0.000117f, 0.000117f, 0.000117f, 0.000100f, 0.000079f, 0.000066f, 0.000053f, 0.000041f, 0.000035f, 0.000028f, 0.000023f, 0.000019f,
+ 0.000017f, 0.000034f, 0.000113f, 0.000174f, 0.000257f, 0.000325f, 0.000356f, 0.000324f, 0.000409f, 0.000454f, 0.000474f, 0.000659f,
+ 0.000778f, 0.001243f, 0.001575f, 0.002472f, 0.004105f, 0.007957f, 0.016800f, 0.047852f, 0.217529f, 0.755371f, 0.972656f, 0.973145f,
+ 0.973145f, 0.973145f, 0.973145f, 0.973145f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000028f, 0.000049f, 0.000085f, 0.000081f, 0.000096f, 0.000101f, 0.000104f, 0.000106f, 0.000108f, 0.000109f, 0.000110f,
+ 0.000111f, 0.000112f, 0.000113f, 0.000113f, 0.000114f, 0.000114f, 0.000114f, 0.000115f, 0.000115f, 0.000096f, 0.000078f, 0.000064f,
+ 0.000051f, 0.000043f, 0.000035f, 0.000029f, 0.000024f, 0.000020f, 0.000026f, 0.000055f, 0.000087f, 0.000135f, 0.000248f, 0.000261f,
+ 0.000274f, 0.000258f, 0.000296f, 0.000359f, 0.000474f, 0.000627f, 0.001012f, 0.001484f, 0.002630f, 0.004536f, 0.010277f, 0.027405f,
+ 0.119507f, 0.645996f, 0.966797f, 0.967285f, 0.967285f, 0.967285f, 0.966797f, 0.966797f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000014f, 0.000021f, 0.000065f, 0.000074f,
+ 0.000077f, 0.000091f, 0.000091f, 0.000099f, 0.000098f, 0.000103f, 0.000103f, 0.000106f, 0.000107f, 0.000108f, 0.000109f, 0.000110f,
+ 0.000111f, 0.000111f, 0.000112f, 0.000096f, 0.000079f, 0.000064f, 0.000053f, 0.000043f, 0.000036f, 0.000030f, 0.000024f, 0.000021f,
+ 0.000018f, 0.000028f, 0.000072f, 0.000125f, 0.000233f, 0.000243f, 0.000220f, 0.000258f, 0.000320f, 0.000353f, 0.000630f, 0.000932f,
+ 0.001324f, 0.002357f, 0.005402f, 0.014534f, 0.062561f, 0.493164f, 0.958008f, 0.958008f, 0.958984f, 0.958496f, 0.958496f, 0.958008f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000011f, 0.000035f, 0.000041f, 0.000064f, 0.000074f, 0.000081f, 0.000082f, 0.000090f,
+ 0.000092f, 0.000096f, 0.000099f, 0.000100f, 0.000102f, 0.000104f, 0.000105f, 0.000106f, 0.000107f, 0.000099f, 0.000082f, 0.000067f,
+ 0.000055f, 0.000047f, 0.000038f, 0.000031f, 0.000026f, 0.000022f, 0.000018f, 0.000037f, 0.000071f, 0.000111f, 0.000190f, 0.000204f,
+ 0.000153f, 0.000245f, 0.000299f, 0.000482f, 0.000790f, 0.001330f, 0.002619f, 0.007282f, 0.031097f, 0.318115f, 0.946289f, 0.946777f,
+ 0.946777f, 0.946777f, 0.946777f, 0.946777f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000008f, 0.000029f, 0.000044f, 0.000055f, 0.000063f, 0.000073f, 0.000075f, 0.000081f, 0.000087f, 0.000090f, 0.000092f,
+ 0.000094f, 0.000097f, 0.000099f, 0.000100f, 0.000087f, 0.000071f, 0.000059f, 0.000049f, 0.000040f, 0.000034f, 0.000028f, 0.000024f,
+ 0.000020f, 0.000016f, 0.000072f, 0.000114f, 0.000169f, 0.000147f, 0.000181f, 0.000246f, 0.000367f, 0.000626f, 0.001325f, 0.003117f,
+ 0.013741f, 0.167480f, 0.929688f, 0.929688f, 0.929688f, 0.930176f, 0.930664f, 0.930176f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000019f,
+ 0.000030f, 0.000044f, 0.000049f, 0.000062f, 0.000068f, 0.000072f, 0.000078f, 0.000081f, 0.000084f, 0.000087f, 0.000090f, 0.000079f,
+ 0.000065f, 0.000054f, 0.000044f, 0.000037f, 0.000030f, 0.000025f, 0.000021f, 0.000017f, 0.000052f, 0.000100f, 0.000132f, 0.000130f,
+ 0.000164f, 0.000297f, 0.000552f, 0.001273f, 0.005009f, 0.071594f, 0.903809f, 0.905273f, 0.904297f, 0.904785f, 0.904785f, 0.904785f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000013f, 0.000028f, 0.000036f,
+ 0.000045f, 0.000053f, 0.000060f, 0.000066f, 0.000071f, 0.000075f, 0.000071f, 0.000058f, 0.000049f, 0.000040f, 0.000033f, 0.000027f,
+ 0.000022f, 0.000018f, 0.000032f, 0.000078f, 0.000090f, 0.000123f, 0.000175f, 0.000441f, 0.001637f, 0.022537f, 0.865234f, 0.865234f,
+ 0.865723f, 0.865723f, 0.865234f, 0.864746f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000004f, 0.000017f, 0.000027f, 0.000036f, 0.000042f,
+ 0.000050f, 0.000056f, 0.000052f, 0.000043f, 0.000035f, 0.000028f, 0.000022f, 0.000018f, 0.000049f, 0.000055f, 0.000047f, 0.000108f,
+ 0.000342f, 0.004566f, 0.802734f, 0.803711f, 0.803711f, 0.803711f, 0.803711f, 0.803711f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000013f, 0.000022f, 0.000030f, 0.000033f, 0.000027f,
+ 0.000021f, 0.000015f, 0.000011f, 0.000031f, 0.000045f, 0.000449f, 0.708496f, 0.707520f, 0.708984f, 0.708496f, 0.707520f, 0.708008f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000004f, 0.000011f, 0.000006f, 0.000007f, 0.575195f, 0.575195f,
+ 0.575195f, 0.575195f, 0.575195f, 0.575195f,
+ },
+ {
+ 0.158813f, 0.632812f, 0.824219f, 0.891602f, 0.924805f, 0.942383f, 0.954102f, 0.962402f, 0.968262f, 0.972656f, 0.976074f, 0.978516f,
+ 0.980957f, 0.982910f, 0.984375f, 0.985840f, 0.986816f, 0.988770f, 0.989746f, 0.989746f, 0.990234f, 0.991211f, 0.992188f, 0.992676f,
+ 0.993652f, 0.993652f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.996582f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.019775f, 0.115845f, 0.361084f, 0.642578f, 0.798340f, 0.872559f, 0.911133f, 0.933594f,
+ 0.947266f, 0.957031f, 0.964355f, 0.968750f, 0.973145f, 0.976562f, 0.979492f, 0.981934f, 0.983398f, 0.984863f, 0.986816f, 0.987793f,
+ 0.988770f, 0.989258f, 0.990234f, 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.993164f, 0.993652f, 0.994141f, 0.995117f, 0.995117f,
+ 0.995605f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.006638f, 0.031082f, 0.089661f, 0.222168f,
+ 0.448242f, 0.663086f, 0.794434f, 0.864258f, 0.903320f, 0.926758f, 0.942383f, 0.953613f, 0.961426f, 0.966797f, 0.972168f, 0.975586f,
+ 0.978027f, 0.980469f, 0.982910f, 0.984375f, 0.985840f, 0.986816f, 0.988281f, 0.989258f, 0.990234f, 0.991211f, 0.991699f, 0.992188f,
+ 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.996582f,
+ 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.003246f, 0.013367f, 0.032806f, 0.072754f, 0.152954f, 0.304199f, 0.509766f, 0.687500f, 0.797852f, 0.862305f, 0.900391f, 0.923828f,
+ 0.940430f, 0.950684f, 0.959473f, 0.965820f, 0.970703f, 0.974121f, 0.977051f, 0.979492f, 0.981934f, 0.983887f, 0.985840f, 0.987305f,
+ 0.987793f, 0.989258f, 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.992188f, 0.993164f, 0.993652f, 0.993652f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.002029f, 0.007267f, 0.016678f, 0.032288f, 0.061462f, 0.115051f, 0.215088f, 0.376709f,
+ 0.562988f, 0.712891f, 0.807617f, 0.865234f, 0.901367f, 0.923828f, 0.939453f, 0.950684f, 0.958984f, 0.965332f, 0.970215f, 0.974609f,
+ 0.977051f, 0.979980f, 0.981934f, 0.983887f, 0.984863f, 0.986328f, 0.988281f, 0.988770f, 0.989746f, 0.990723f, 0.990723f, 0.991699f,
+ 0.992188f, 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995117f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996582f,
+ 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.001274f, 0.004623f, 0.009880f, 0.017792f,
+ 0.030869f, 0.052673f, 0.091431f, 0.160645f, 0.277832f, 0.442383f, 0.610352f, 0.737793f, 0.819824f, 0.870605f, 0.902832f, 0.924805f,
+ 0.939941f, 0.950195f, 0.958496f, 0.964844f, 0.970215f, 0.973633f, 0.977051f, 0.979980f, 0.981934f, 0.983398f, 0.984863f, 0.986328f,
+ 0.987305f, 0.988770f, 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000943f, 0.003231f, 0.006317f, 0.011040f, 0.018051f, 0.029190f, 0.046936f, 0.075867f, 0.125488f, 0.210449f, 0.341797f, 0.503906f,
+ 0.652344f, 0.761230f, 0.832031f, 0.877441f, 0.906738f, 0.927734f, 0.940918f, 0.951172f, 0.959473f, 0.965820f, 0.970703f, 0.974121f,
+ 0.977051f, 0.979492f, 0.981934f, 0.983398f, 0.985352f, 0.987305f, 0.988281f, 0.989258f, 0.990234f, 0.990723f, 0.991211f, 0.992188f,
+ 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996582f,
+ 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000731f, 0.001970f, 0.004425f, 0.007351f, 0.011627f, 0.017975f, 0.027161f, 0.041779f,
+ 0.064270f, 0.101685f, 0.164917f, 0.265137f, 0.406494f, 0.561035f, 0.692383f, 0.785156f, 0.845703f, 0.884766f, 0.911621f, 0.930176f,
+ 0.942871f, 0.953125f, 0.959961f, 0.965332f, 0.970703f, 0.974121f, 0.977539f, 0.979492f, 0.982422f, 0.983887f, 0.985840f, 0.987305f,
+ 0.987793f, 0.989258f, 0.990234f, 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.995117f, 0.995117f, 0.995605f,
+ 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.000487f, 0.001872f, 0.003445f, 0.005367f,
+ 0.008400f, 0.012405f, 0.017822f, 0.025345f, 0.037964f, 0.056244f, 0.085327f, 0.132935f, 0.210327f, 0.325928f, 0.471924f, 0.615723f,
+ 0.729004f, 0.807617f, 0.859375f, 0.894043f, 0.916504f, 0.934570f, 0.945801f, 0.955078f, 0.961426f, 0.967285f, 0.972168f, 0.975586f,
+ 0.978516f, 0.980957f, 0.982422f, 0.984863f, 0.985840f, 0.986816f, 0.988770f, 0.989258f, 0.990723f, 0.991699f, 0.992188f, 0.992676f,
+ 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.997070f, 0.997070f, 0.997559f,
+ 0.997559f, 0.998047f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.000363f, 0.001300f, 0.002499f, 0.003784f, 0.006153f, 0.008896f, 0.012367f, 0.017227f, 0.024185f, 0.034241f, 0.049591f, 0.072754f,
+ 0.111023f, 0.170776f, 0.263184f, 0.391113f, 0.535645f, 0.665527f, 0.761719f, 0.828613f, 0.871582f, 0.902344f, 0.922852f, 0.937988f,
+ 0.949219f, 0.957031f, 0.963867f, 0.968750f, 0.972656f, 0.976074f, 0.979004f, 0.981445f, 0.983887f, 0.984863f, 0.986328f, 0.988281f,
+ 0.989258f, 0.990234f, 0.991211f, 0.991699f, 0.992676f, 0.993652f, 0.993652f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999023f, 0.999023f, 0.000365f, 0.000972f, 0.001874f, 0.003323f, 0.004669f, 0.006599f, 0.008919f, 0.012360f,
+ 0.016785f, 0.022720f, 0.031616f, 0.044647f, 0.064026f, 0.094055f, 0.141235f, 0.215332f, 0.323486f, 0.459229f, 0.597168f, 0.710449f,
+ 0.791992f, 0.847656f, 0.885254f, 0.910645f, 0.929199f, 0.941895f, 0.952148f, 0.960449f, 0.965332f, 0.970703f, 0.974121f, 0.977539f,
+ 0.979980f, 0.981934f, 0.984375f, 0.985840f, 0.987305f, 0.988770f, 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.993164f, 0.993164f,
+ 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f,
+ 0.998047f, 0.998535f, 0.999023f, 0.999512f, 0.999023f, 0.999512f, 0.999512f, 0.999023f, 0.000244f, 0.000764f, 0.001375f, 0.002415f,
+ 0.003582f, 0.004963f, 0.006973f, 0.008751f, 0.011726f, 0.016113f, 0.021683f, 0.029129f, 0.040283f, 0.057098f, 0.081421f, 0.119019f,
+ 0.178955f, 0.268311f, 0.390625f, 0.528809f, 0.654785f, 0.751465f, 0.820312f, 0.866211f, 0.896973f, 0.919434f, 0.935547f, 0.946777f,
+ 0.956055f, 0.962402f, 0.968262f, 0.972168f, 0.975098f, 0.979004f, 0.981445f, 0.983398f, 0.985352f, 0.986816f, 0.987793f, 0.989258f,
+ 0.990723f, 0.991211f, 0.992188f, 0.992188f, 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996094f,
+ 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000122f, 0.000606f, 0.001439f, 0.002058f, 0.002743f, 0.004169f, 0.005035f, 0.006775f, 0.009010f, 0.012085f, 0.015717f, 0.020813f,
+ 0.027573f, 0.037170f, 0.050812f, 0.071472f, 0.102905f, 0.151489f, 0.225708f, 0.332031f, 0.463623f, 0.596191f, 0.707031f, 0.787598f,
+ 0.844238f, 0.881348f, 0.908691f, 0.927246f, 0.940918f, 0.951660f, 0.958984f, 0.965820f, 0.970215f, 0.974121f, 0.977539f, 0.979980f,
+ 0.982422f, 0.984375f, 0.985840f, 0.987305f, 0.988281f, 0.990234f, 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994141f,
+ 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000118f, 0.000846f, 0.001303f, 0.001593f, 0.002180f, 0.003050f, 0.004353f, 0.005577f,
+ 0.006954f, 0.009331f, 0.011826f, 0.015007f, 0.019653f, 0.025391f, 0.034119f, 0.046112f, 0.063660f, 0.090210f, 0.130737f, 0.192139f,
+ 0.283203f, 0.404053f, 0.537598f, 0.658691f, 0.753418f, 0.818848f, 0.865234f, 0.896973f, 0.918945f, 0.934570f, 0.946289f, 0.955566f,
+ 0.962402f, 0.967285f, 0.972168f, 0.976074f, 0.979004f, 0.981445f, 0.983398f, 0.985840f, 0.986816f, 0.988281f, 0.989258f, 0.990723f,
+ 0.991211f, 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f,
+ 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000117f, 0.000487f, 0.000957f, 0.001514f,
+ 0.002008f, 0.002619f, 0.003424f, 0.004551f, 0.005836f, 0.007381f, 0.009155f, 0.011459f, 0.014366f, 0.018646f, 0.024017f, 0.031281f,
+ 0.042664f, 0.057068f, 0.080139f, 0.113586f, 0.165894f, 0.243164f, 0.352051f, 0.481934f, 0.610840f, 0.716309f, 0.793945f, 0.847168f,
+ 0.884766f, 0.910645f, 0.928223f, 0.942383f, 0.952637f, 0.959961f, 0.965332f, 0.970703f, 0.975098f, 0.978027f, 0.980957f, 0.983398f,
+ 0.984863f, 0.986816f, 0.988281f, 0.989258f, 0.990723f, 0.991211f, 0.992188f, 0.992676f, 0.993164f, 0.993652f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997559f, 0.997070f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000000f, 0.000608f, 0.000952f, 0.001111f, 0.001660f, 0.002102f, 0.002817f, 0.003517f, 0.004742f, 0.005585f, 0.007080f, 0.008980f,
+ 0.011078f, 0.014191f, 0.017838f, 0.022614f, 0.029404f, 0.038940f, 0.052551f, 0.071533f, 0.100769f, 0.145020f, 0.211548f, 0.307373f,
+ 0.430176f, 0.561523f, 0.676758f, 0.764648f, 0.828613f, 0.872070f, 0.900879f, 0.921875f, 0.937012f, 0.948730f, 0.957520f, 0.964355f,
+ 0.969238f, 0.973633f, 0.977539f, 0.979980f, 0.982422f, 0.984863f, 0.986328f, 0.987793f, 0.988770f, 0.990234f, 0.991211f, 0.991699f,
+ 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000244f, 0.000576f, 0.000727f, 0.001083f, 0.001186f, 0.001810f, 0.002558f, 0.002968f,
+ 0.003725f, 0.004913f, 0.005955f, 0.007011f, 0.008759f, 0.010918f, 0.013718f, 0.016953f, 0.021423f, 0.027832f, 0.035980f, 0.047913f,
+ 0.064941f, 0.090332f, 0.128174f, 0.185791f, 0.270264f, 0.384033f, 0.514160f, 0.638184f, 0.736328f, 0.807617f, 0.856934f, 0.891602f,
+ 0.915039f, 0.932617f, 0.945801f, 0.954102f, 0.962402f, 0.968262f, 0.972168f, 0.976562f, 0.979492f, 0.981445f, 0.983887f, 0.985840f,
+ 0.987305f, 0.988281f, 0.990234f, 0.990723f, 0.992188f, 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996582f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000000f, 0.000244f, 0.000708f, 0.000903f,
+ 0.001129f, 0.001511f, 0.002031f, 0.002565f, 0.003189f, 0.004112f, 0.004696f, 0.005989f, 0.006954f, 0.008865f, 0.010826f, 0.013031f,
+ 0.016312f, 0.020493f, 0.026154f, 0.033966f, 0.044159f, 0.059845f, 0.081665f, 0.114929f, 0.164917f, 0.239624f, 0.343750f, 0.469971f,
+ 0.598145f, 0.706055f, 0.786133f, 0.842773f, 0.881348f, 0.908203f, 0.927246f, 0.941895f, 0.952148f, 0.959961f, 0.966797f, 0.971191f,
+ 0.976074f, 0.978516f, 0.981445f, 0.983887f, 0.985352f, 0.987305f, 0.988281f, 0.989258f, 0.990723f, 0.991699f, 0.992676f, 0.993652f,
+ 0.994141f, 0.994629f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000122f, 0.000244f, 0.000482f, 0.000674f, 0.001029f, 0.001440f, 0.001746f, 0.002153f, 0.002804f, 0.003206f, 0.003859f, 0.004948f,
+ 0.005722f, 0.007206f, 0.008568f, 0.010498f, 0.012413f, 0.015793f, 0.019989f, 0.024826f, 0.031799f, 0.041382f, 0.054932f, 0.074768f,
+ 0.103882f, 0.147949f, 0.213867f, 0.308838f, 0.429932f, 0.560059f, 0.675781f, 0.765625f, 0.827148f, 0.871582f, 0.901367f, 0.923340f,
+ 0.937988f, 0.949707f, 0.958496f, 0.965820f, 0.969727f, 0.974609f, 0.978027f, 0.980469f, 0.983398f, 0.985840f, 0.986816f, 0.988281f,
+ 0.989258f, 0.990723f, 0.992188f, 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996582f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000244f, 0.000244f, 0.000363f, 0.000604f, 0.000834f, 0.001020f, 0.001548f, 0.001970f,
+ 0.002262f, 0.002548f, 0.003157f, 0.003914f, 0.004681f, 0.005962f, 0.006943f, 0.008263f, 0.010277f, 0.012589f, 0.015144f, 0.018951f,
+ 0.023788f, 0.030014f, 0.039001f, 0.051056f, 0.069092f, 0.094666f, 0.133911f, 0.192993f, 0.279053f, 0.394287f, 0.524414f, 0.646484f,
+ 0.743652f, 0.812988f, 0.861328f, 0.895020f, 0.917969f, 0.935547f, 0.947754f, 0.957520f, 0.963867f, 0.969238f, 0.974121f, 0.978027f,
+ 0.980469f, 0.983398f, 0.984863f, 0.987305f, 0.988281f, 0.989258f, 0.990723f, 0.991699f, 0.992676f, 0.993652f, 0.994141f, 0.994629f,
+ 0.995117f, 0.996094f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000118f, 0.000244f, 0.000244f, 0.000584f,
+ 0.000837f, 0.000847f, 0.001295f, 0.001681f, 0.002018f, 0.002348f, 0.003014f, 0.003157f, 0.004124f, 0.004547f, 0.005432f, 0.006607f,
+ 0.008163f, 0.010071f, 0.011925f, 0.014786f, 0.017990f, 0.022659f, 0.028824f, 0.036621f, 0.047882f, 0.063477f, 0.087158f, 0.122559f,
+ 0.175781f, 0.254639f, 0.363037f, 0.492188f, 0.618652f, 0.722168f, 0.799805f, 0.852051f, 0.889648f, 0.914551f, 0.932129f, 0.944824f,
+ 0.955078f, 0.962891f, 0.968262f, 0.973633f, 0.977051f, 0.980469f, 0.982910f, 0.984863f, 0.987305f, 0.988281f, 0.990234f, 0.991211f,
+ 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000242f, 0.000243f, 0.000243f, 0.000481f, 0.000742f, 0.000843f, 0.000969f, 0.001348f, 0.001726f, 0.001791f, 0.002348f, 0.002853f,
+ 0.003452f, 0.003735f, 0.004757f, 0.005516f, 0.006744f, 0.008102f, 0.009621f, 0.011948f, 0.014320f, 0.017365f, 0.021698f, 0.027298f,
+ 0.034546f, 0.044891f, 0.059875f, 0.081055f, 0.112915f, 0.161255f, 0.234009f, 0.335693f, 0.462646f, 0.592285f, 0.702637f, 0.785645f,
+ 0.843750f, 0.883301f, 0.911133f, 0.929688f, 0.944336f, 0.954590f, 0.961914f, 0.967773f, 0.973633f, 0.977539f, 0.980469f, 0.982910f,
+ 0.985352f, 0.986816f, 0.988770f, 0.990234f, 0.991211f, 0.992188f, 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000100f, 0.000216f, 0.000243f, 0.000365f, 0.000517f, 0.000836f, 0.000964f, 0.001148f,
+ 0.001472f, 0.001674f, 0.001785f, 0.002438f, 0.002815f, 0.003490f, 0.004070f, 0.004837f, 0.005608f, 0.006630f, 0.008095f, 0.009483f,
+ 0.011551f, 0.013847f, 0.016953f, 0.020584f, 0.025879f, 0.033051f, 0.042664f, 0.055817f, 0.075500f, 0.105103f, 0.149536f, 0.216553f,
+ 0.312988f, 0.436768f, 0.568359f, 0.685059f, 0.773926f, 0.835449f, 0.878418f, 0.907227f, 0.927734f, 0.943359f, 0.953125f, 0.962402f,
+ 0.967285f, 0.973145f, 0.977051f, 0.980469f, 0.983887f, 0.985352f, 0.987305f, 0.989258f, 0.990234f, 0.991699f, 0.992188f, 0.993164f,
+ 0.994141f, 0.994629f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000150f, 0.000242f, 0.000364f,
+ 0.000441f, 0.000627f, 0.000916f, 0.000959f, 0.000968f, 0.001463f, 0.001671f, 0.002222f, 0.002577f, 0.002714f, 0.003479f, 0.004208f,
+ 0.004723f, 0.005669f, 0.006886f, 0.007637f, 0.009315f, 0.011154f, 0.013596f, 0.016205f, 0.019821f, 0.024963f, 0.031250f, 0.040375f,
+ 0.053009f, 0.071167f, 0.098511f, 0.139648f, 0.202271f, 0.293457f, 0.414307f, 0.548340f, 0.669434f, 0.762695f, 0.829590f, 0.874512f,
+ 0.904785f, 0.926758f, 0.941895f, 0.953613f, 0.961914f, 0.968262f, 0.973633f, 0.977539f, 0.980957f, 0.983398f, 0.985352f, 0.987793f,
+ 0.989258f, 0.990234f, 0.991211f, 0.992188f, 0.993164f, 0.994629f, 0.998047f, 0.998535f, 0.998047f, 0.998047f, 0.998047f, 0.998047f,
+ 0.000000f, 0.000231f, 0.000232f, 0.000363f, 0.000486f, 0.000503f, 0.000724f, 0.001104f, 0.001080f, 0.001271f, 0.001509f, 0.001976f,
+ 0.002247f, 0.002476f, 0.002895f, 0.003553f, 0.004192f, 0.004871f, 0.005623f, 0.006332f, 0.007584f, 0.008957f, 0.010849f, 0.012917f,
+ 0.015396f, 0.019226f, 0.023941f, 0.030060f, 0.038513f, 0.050385f, 0.067627f, 0.093140f, 0.131714f, 0.190674f, 0.278076f, 0.395752f,
+ 0.530273f, 0.655762f, 0.753906f, 0.823242f, 0.870605f, 0.903320f, 0.925781f, 0.941406f, 0.953125f, 0.961914f, 0.969238f, 0.974121f,
+ 0.978027f, 0.980957f, 0.983887f, 0.985840f, 0.988281f, 0.989258f, 0.990723f, 0.991699f, 0.992676f, 0.993652f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000000f, 0.000009f, 0.000116f, 0.000360f, 0.000484f, 0.000485f, 0.000536f, 0.000827f,
+ 0.000935f, 0.001077f, 0.001204f, 0.001561f, 0.001974f, 0.002136f, 0.002777f, 0.002964f, 0.003517f, 0.004192f, 0.004711f, 0.005505f,
+ 0.006283f, 0.007408f, 0.008713f, 0.010674f, 0.012375f, 0.015099f, 0.018677f, 0.022797f, 0.028732f, 0.036835f, 0.047974f, 0.064270f,
+ 0.088318f, 0.124634f, 0.180664f, 0.264893f, 0.380615f, 0.516113f, 0.645020f, 0.747559f, 0.819824f, 0.870117f, 0.902344f, 0.925293f,
+ 0.941406f, 0.953613f, 0.962402f, 0.969238f, 0.974121f, 0.978027f, 0.981934f, 0.984375f, 0.986328f, 0.988281f, 0.989746f, 0.990723f,
+ 0.992676f, 0.993164f, 0.997559f, 0.998047f, 0.998047f, 0.997559f, 0.998047f, 0.998047f, 0.000000f, 0.000000f, 0.000074f, 0.000337f,
+ 0.000481f, 0.000484f, 0.000485f, 0.000556f, 0.000823f, 0.001143f, 0.001187f, 0.001391f, 0.001781f, 0.002155f, 0.002327f, 0.002760f,
+ 0.003008f, 0.003433f, 0.004101f, 0.004681f, 0.005417f, 0.006443f, 0.007393f, 0.008560f, 0.010345f, 0.012177f, 0.014496f, 0.018127f,
+ 0.022125f, 0.027740f, 0.035736f, 0.046173f, 0.061920f, 0.084717f, 0.119324f, 0.173218f, 0.254883f, 0.368652f, 0.505371f, 0.637207f,
+ 0.742676f, 0.818359f, 0.868164f, 0.902832f, 0.925781f, 0.942383f, 0.953613f, 0.963379f, 0.970215f, 0.975098f, 0.979004f, 0.982422f,
+ 0.984863f, 0.986328f, 0.988770f, 0.990723f, 0.991699f, 0.992676f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000188f, 0.000358f, 0.000481f, 0.000484f, 0.000484f, 0.000704f, 0.000852f, 0.001165f, 0.001316f,
+ 0.001500f, 0.001685f, 0.001933f, 0.002079f, 0.002720f, 0.003136f, 0.003727f, 0.003723f, 0.004513f, 0.005207f, 0.006275f, 0.007236f,
+ 0.008453f, 0.010056f, 0.011848f, 0.014191f, 0.017212f, 0.021652f, 0.026978f, 0.034241f, 0.044678f, 0.058990f, 0.081421f, 0.114929f,
+ 0.167236f, 0.247070f, 0.360596f, 0.498291f, 0.632812f, 0.741211f, 0.818359f, 0.869629f, 0.903809f, 0.927734f, 0.943848f, 0.955566f,
+ 0.964355f, 0.970703f, 0.976074f, 0.979492f, 0.982422f, 0.985840f, 0.987793f, 0.989258f, 0.990723f, 0.992188f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000000f, 0.000121f, 0.000120f, 0.000288f, 0.000357f, 0.000479f, 0.000483f,
+ 0.000535f, 0.000711f, 0.000862f, 0.001256f, 0.001351f, 0.001502f, 0.001719f, 0.002146f, 0.002037f, 0.002653f, 0.003248f, 0.003222f,
+ 0.003820f, 0.004456f, 0.005173f, 0.006008f, 0.007072f, 0.008247f, 0.009758f, 0.011826f, 0.013771f, 0.016861f, 0.020935f, 0.025986f,
+ 0.032928f, 0.043030f, 0.057587f, 0.078918f, 0.111755f, 0.162964f, 0.241943f, 0.355713f, 0.495117f, 0.632324f, 0.742676f, 0.819336f,
+ 0.871582f, 0.905762f, 0.929688f, 0.945312f, 0.957031f, 0.965332f, 0.972168f, 0.976562f, 0.980957f, 0.983887f, 0.986328f, 0.988281f,
+ 0.990234f, 0.991699f, 0.997070f, 0.997559f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000000f, 0.000000f, 0.000121f,
+ 0.000200f, 0.000412f, 0.000471f, 0.000599f, 0.000598f, 0.000596f, 0.000805f, 0.001099f, 0.001334f, 0.001417f, 0.001456f, 0.001723f,
+ 0.002102f, 0.002283f, 0.002579f, 0.003208f, 0.003233f, 0.003740f, 0.004574f, 0.005287f, 0.006012f, 0.006870f, 0.008018f, 0.009354f,
+ 0.011208f, 0.013542f, 0.016495f, 0.020370f, 0.025284f, 0.032410f, 0.041901f, 0.056183f, 0.077087f, 0.109558f, 0.160278f, 0.239380f,
+ 0.354492f, 0.496094f, 0.635254f, 0.747070f, 0.823730f, 0.875488f, 0.908691f, 0.931641f, 0.947266f, 0.958008f, 0.966309f, 0.972656f,
+ 0.978027f, 0.981445f, 0.984863f, 0.986816f, 0.989258f, 0.990723f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997070f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000117f, 0.000237f, 0.000239f, 0.000430f, 0.000465f, 0.000599f, 0.000724f, 0.000716f, 0.000815f,
+ 0.000981f, 0.001334f, 0.001299f, 0.001545f, 0.001617f, 0.001935f, 0.002110f, 0.002501f, 0.002823f, 0.003408f, 0.003790f, 0.004467f,
+ 0.005112f, 0.005848f, 0.006718f, 0.007942f, 0.009514f, 0.011093f, 0.013092f, 0.015945f, 0.019608f, 0.024689f, 0.031494f, 0.041046f,
+ 0.054901f, 0.075989f, 0.108032f, 0.158936f, 0.239014f, 0.356201f, 0.500488f, 0.642090f, 0.753418f, 0.830566f, 0.880859f, 0.912598f,
+ 0.935059f, 0.950195f, 0.960449f, 0.968262f, 0.975098f, 0.979980f, 0.982910f, 0.985352f, 0.987793f, 0.990234f, 0.996582f, 0.997070f,
+ 0.997070f, 0.996582f, 0.997070f, 0.996582f, 0.000000f, 0.000000f, 0.000000f, 0.000117f, 0.000120f, 0.000121f, 0.000312f, 0.000407f,
+ 0.000707f, 0.000597f, 0.000648f, 0.000720f, 0.000941f, 0.001008f, 0.001229f, 0.001289f, 0.001423f, 0.001726f, 0.002060f, 0.002211f,
+ 0.002506f, 0.002985f, 0.003036f, 0.003683f, 0.004066f, 0.004833f, 0.005592f, 0.006611f, 0.007675f, 0.008965f, 0.010811f, 0.012833f,
+ 0.015854f, 0.019485f, 0.024429f, 0.031036f, 0.040466f, 0.054108f, 0.074890f, 0.107727f, 0.159180f, 0.241699f, 0.362549f, 0.510742f,
+ 0.653809f, 0.763184f, 0.837891f, 0.887207f, 0.917480f, 0.938477f, 0.953613f, 0.962891f, 0.970703f, 0.976562f, 0.980469f, 0.984375f,
+ 0.986816f, 0.988770f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.000000f, 0.000000f, 0.000000f, 0.000117f,
+ 0.000118f, 0.000120f, 0.000129f, 0.000434f, 0.000536f, 0.000613f, 0.000716f, 0.000799f, 0.000720f, 0.000768f, 0.001024f, 0.001202f,
+ 0.001501f, 0.001530f, 0.001568f, 0.001897f, 0.002190f, 0.002502f, 0.002893f, 0.003105f, 0.003551f, 0.004021f, 0.004791f, 0.005405f,
+ 0.006313f, 0.007309f, 0.008720f, 0.010712f, 0.012657f, 0.015472f, 0.018982f, 0.023697f, 0.030579f, 0.040009f, 0.054138f, 0.075012f,
+ 0.107849f, 0.161377f, 0.247070f, 0.373047f, 0.525391f, 0.667969f, 0.776855f, 0.847656f, 0.894043f, 0.923340f, 0.942871f, 0.956543f,
+ 0.965820f, 0.973145f, 0.978027f, 0.982422f, 0.985352f, 0.987793f, 0.996094f, 0.996094f, 0.996582f, 0.996094f, 0.996582f, 0.996094f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000081f, 0.000116f, 0.000227f, 0.000360f, 0.000366f, 0.000642f, 0.000691f, 0.000711f,
+ 0.000806f, 0.000721f, 0.000925f, 0.000947f, 0.001155f, 0.001478f, 0.001554f, 0.001612f, 0.001929f, 0.002354f, 0.002291f, 0.002712f,
+ 0.003029f, 0.003441f, 0.003876f, 0.004452f, 0.005276f, 0.006256f, 0.007149f, 0.008568f, 0.010040f, 0.012566f, 0.015160f, 0.018677f,
+ 0.023376f, 0.030411f, 0.039642f, 0.053986f, 0.075134f, 0.109436f, 0.165527f, 0.255127f, 0.387695f, 0.544434f, 0.686523f, 0.791016f,
+ 0.858398f, 0.901367f, 0.928711f, 0.947266f, 0.959961f, 0.968262f, 0.975098f, 0.980469f, 0.983887f, 0.987305f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000088f, 0.000085f, 0.000338f, 0.000351f,
+ 0.000359f, 0.000480f, 0.000539f, 0.000698f, 0.000798f, 0.000793f, 0.000834f, 0.000891f, 0.000941f, 0.001143f, 0.001422f, 0.001512f,
+ 0.001833f, 0.001955f, 0.002144f, 0.002426f, 0.002716f, 0.003262f, 0.003572f, 0.003860f, 0.004456f, 0.005173f, 0.006191f, 0.006939f,
+ 0.008545f, 0.010162f, 0.012375f, 0.014969f, 0.018555f, 0.023376f, 0.029953f, 0.039673f, 0.054077f, 0.076477f, 0.112000f, 0.171509f,
+ 0.268066f, 0.408203f, 0.569336f, 0.709961f, 0.808105f, 0.872070f, 0.910645f, 0.935059f, 0.951660f, 0.963379f, 0.971680f, 0.977539f,
+ 0.982422f, 0.985840f, 0.995117f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000116f, 0.000340f, 0.000353f, 0.000349f, 0.000480f, 0.000576f, 0.000668f, 0.000700f, 0.000818f, 0.000833f,
+ 0.000787f, 0.001125f, 0.001110f, 0.001407f, 0.001489f, 0.001563f, 0.001804f, 0.002073f, 0.002285f, 0.002409f, 0.002985f, 0.003052f,
+ 0.003853f, 0.004433f, 0.005100f, 0.006046f, 0.007046f, 0.008156f, 0.009827f, 0.012138f, 0.014740f, 0.018311f, 0.023071f, 0.029770f,
+ 0.040009f, 0.054810f, 0.078003f, 0.116150f, 0.180176f, 0.284668f, 0.434570f, 0.599121f, 0.735352f, 0.827637f, 0.885254f, 0.919922f,
+ 0.941895f, 0.957031f, 0.967285f, 0.975098f, 0.979980f, 0.984375f, 0.995117f, 0.995117f, 0.995117f, 0.995117f, 0.995117f, 0.995605f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000000f, 0.000122f, 0.000235f, 0.000320f, 0.000351f, 0.000353f, 0.000478f,
+ 0.000602f, 0.000651f, 0.000793f, 0.000706f, 0.000816f, 0.000814f, 0.000898f, 0.001062f, 0.001259f, 0.001441f, 0.001564f, 0.001772f,
+ 0.001743f, 0.002134f, 0.002512f, 0.002668f, 0.003193f, 0.003746f, 0.004341f, 0.004902f, 0.005909f, 0.006920f, 0.008125f, 0.009605f,
+ 0.011711f, 0.014549f, 0.018280f, 0.023163f, 0.030334f, 0.040375f, 0.055939f, 0.080566f, 0.122070f, 0.192383f, 0.307373f, 0.467773f,
+ 0.634277f, 0.763184f, 0.846191f, 0.897461f, 0.928711f, 0.948730f, 0.962402f, 0.971680f, 0.978516f, 0.982422f, 0.994141f, 0.994629f,
+ 0.994629f, 0.995117f, 0.995117f, 0.995117f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000185f, 0.000190f,
+ 0.000272f, 0.000281f, 0.000464f, 0.000466f, 0.000476f, 0.000521f, 0.000654f, 0.000680f, 0.000699f, 0.000815f, 0.000814f, 0.000890f,
+ 0.001110f, 0.001283f, 0.001311f, 0.001590f, 0.001727f, 0.001801f, 0.002020f, 0.002312f, 0.002897f, 0.003267f, 0.003592f, 0.004143f,
+ 0.004810f, 0.005844f, 0.006618f, 0.008018f, 0.009697f, 0.011597f, 0.014374f, 0.018127f, 0.023056f, 0.030258f, 0.041107f, 0.057373f,
+ 0.084045f, 0.129517f, 0.208618f, 0.337646f, 0.508789f, 0.673828f, 0.793457f, 0.866211f, 0.911133f, 0.938965f, 0.955566f, 0.967285f,
+ 0.975586f, 0.980469f, 0.994141f, 0.994141f, 0.994629f, 0.994629f, 0.994629f, 0.994141f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000226f, 0.000431f, 0.000456f, 0.000467f, 0.000352f, 0.000496f, 0.000588f,
+ 0.000891f, 0.000771f, 0.000803f, 0.000947f, 0.000972f, 0.001078f, 0.001033f, 0.001279f, 0.001436f, 0.001483f, 0.001831f, 0.002033f,
+ 0.002264f, 0.002710f, 0.002996f, 0.003582f, 0.004032f, 0.004665f, 0.005592f, 0.006527f, 0.007820f, 0.009323f, 0.011581f, 0.014328f,
+ 0.018219f, 0.023239f, 0.030777f, 0.042084f, 0.059448f, 0.089233f, 0.140869f, 0.230713f, 0.375977f, 0.556641f, 0.715332f, 0.822266f,
+ 0.885742f, 0.924316f, 0.947266f, 0.962402f, 0.972656f, 0.978516f, 0.993164f, 0.994141f, 0.994141f, 0.994141f, 0.994141f, 0.994141f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000283f, 0.000229f, 0.000425f,
+ 0.000303f, 0.000336f, 0.000469f, 0.000474f, 0.000728f, 0.000663f, 0.000883f, 0.000695f, 0.000679f, 0.000858f, 0.000919f, 0.000980f,
+ 0.001218f, 0.001330f, 0.001665f, 0.001637f, 0.002054f, 0.002335f, 0.002508f, 0.002880f, 0.003323f, 0.004055f, 0.004730f, 0.005463f,
+ 0.006485f, 0.007740f, 0.009293f, 0.011566f, 0.014175f, 0.017944f, 0.023346f, 0.031433f, 0.043304f, 0.063232f, 0.096313f, 0.155518f,
+ 0.260498f, 0.424561f, 0.611328f, 0.758789f, 0.852051f, 0.904785f, 0.937012f, 0.955566f, 0.968262f, 0.977051f, 0.992676f, 0.992676f,
+ 0.993164f, 0.993652f, 0.993164f, 0.993652f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000256f, 0.000216f, 0.000406f, 0.000426f, 0.000457f, 0.000453f, 0.000472f, 0.000651f, 0.000593f, 0.000876f,
+ 0.000571f, 0.000590f, 0.000819f, 0.000809f, 0.001000f, 0.001224f, 0.001293f, 0.001637f, 0.001790f, 0.001863f, 0.002298f, 0.002550f,
+ 0.002995f, 0.003201f, 0.003933f, 0.004677f, 0.005360f, 0.006447f, 0.007763f, 0.009377f, 0.011330f, 0.014420f, 0.017944f, 0.023560f,
+ 0.032196f, 0.045380f, 0.067383f, 0.105469f, 0.175659f, 0.301025f, 0.484375f, 0.669922f, 0.801270f, 0.879395f, 0.922852f, 0.948242f,
+ 0.963379f, 0.974121f, 0.992188f, 0.992188f, 0.992188f, 0.993164f, 0.992188f, 0.993164f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000230f, 0.000206f, 0.000355f, 0.000335f, 0.000305f,
+ 0.000461f, 0.000565f, 0.000474f, 0.000429f, 0.000520f, 0.000758f, 0.000777f, 0.000668f, 0.000821f, 0.001013f, 0.001089f, 0.001325f,
+ 0.001570f, 0.001787f, 0.001707f, 0.002037f, 0.002457f, 0.002892f, 0.003359f, 0.003881f, 0.004616f, 0.005203f, 0.006336f, 0.007477f,
+ 0.009048f, 0.011345f, 0.014015f, 0.018356f, 0.024307f, 0.033661f, 0.048279f, 0.073303f, 0.118774f, 0.204102f, 0.354492f, 0.554688f,
+ 0.729492f, 0.840332f, 0.902832f, 0.937988f, 0.958008f, 0.971191f, 0.991699f, 0.992188f, 0.992188f, 0.991699f, 0.992188f, 0.991699f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000205f, 0.000248f, 0.000213f, 0.000344f, 0.000437f, 0.000351f, 0.000352f, 0.000359f, 0.000389f, 0.000482f, 0.000676f, 0.000560f,
+ 0.000806f, 0.000813f, 0.000927f, 0.001230f, 0.001392f, 0.001526f, 0.001627f, 0.001629f, 0.002047f, 0.002321f, 0.002661f, 0.003317f,
+ 0.003752f, 0.004406f, 0.005119f, 0.005936f, 0.007156f, 0.009003f, 0.010941f, 0.013985f, 0.018539f, 0.025131f, 0.035248f, 0.051880f,
+ 0.081543f, 0.137207f, 0.244507f, 0.424561f, 0.632812f, 0.787598f, 0.876465f, 0.924805f, 0.951172f, 0.966797f, 0.990723f, 0.991211f,
+ 0.991211f, 0.991211f, 0.991211f, 0.991211f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000224f, 0.000171f, 0.000276f, 0.000278f, 0.000288f, 0.000329f, 0.000365f,
+ 0.000459f, 0.000483f, 0.000626f, 0.000716f, 0.000767f, 0.000793f, 0.000800f, 0.000897f, 0.000976f, 0.001156f, 0.001322f, 0.001427f,
+ 0.001799f, 0.001997f, 0.002256f, 0.002773f, 0.002806f, 0.003515f, 0.004040f, 0.004910f, 0.005730f, 0.007046f, 0.008858f, 0.011124f,
+ 0.014374f, 0.018982f, 0.026123f, 0.037659f, 0.057129f, 0.093445f, 0.164062f, 0.301514f, 0.511230f, 0.712402f, 0.838867f, 0.906738f,
+ 0.942383f, 0.961914f, 0.989746f, 0.990234f, 0.989746f, 0.990234f, 0.989746f, 0.990234f, 0.000000f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000173f, 0.000140f,
+ 0.000138f, 0.000232f, 0.000291f, 0.000318f, 0.000338f, 0.000346f, 0.000422f, 0.000368f, 0.000680f, 0.000722f, 0.000765f, 0.000766f,
+ 0.000803f, 0.001069f, 0.001103f, 0.001185f, 0.001611f, 0.001593f, 0.001939f, 0.002211f, 0.002569f, 0.003008f, 0.003239f, 0.003952f,
+ 0.004681f, 0.005630f, 0.007008f, 0.008720f, 0.011200f, 0.014587f, 0.019653f, 0.027527f, 0.040955f, 0.064514f, 0.110413f, 0.204224f,
+ 0.381104f, 0.609863f, 0.785645f, 0.881836f, 0.931152f, 0.956543f, 0.988770f, 0.989258f, 0.989258f, 0.989258f, 0.989258f, 0.988770f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000121f,
+ 0.000121f, 0.000123f, 0.000121f, 0.000090f, 0.000102f, 0.000063f, 0.000156f, 0.000248f, 0.000333f, 0.000321f, 0.000431f, 0.000392f,
+ 0.000349f, 0.000434f, 0.000674f, 0.000741f, 0.000776f, 0.000936f, 0.000888f, 0.001049f, 0.001179f, 0.001326f, 0.001686f, 0.001732f,
+ 0.002050f, 0.002150f, 0.002453f, 0.003016f, 0.003601f, 0.004444f, 0.005692f, 0.006741f, 0.008324f, 0.011093f, 0.014709f, 0.020752f,
+ 0.029800f, 0.045654f, 0.074951f, 0.136108f, 0.264893f, 0.486816f, 0.710938f, 0.848145f, 0.916992f, 0.950684f, 0.987305f, 0.987793f,
+ 0.987793f, 0.988281f, 0.987793f, 0.987793f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000100f, 0.000049f, 0.000039f, 0.000125f, 0.000121f,
+ 0.000184f, 0.000280f, 0.000366f, 0.000392f, 0.000333f, 0.000341f, 0.000477f, 0.000597f, 0.000607f, 0.000747f, 0.000767f, 0.000961f,
+ 0.000936f, 0.001056f, 0.001306f, 0.001388f, 0.001633f, 0.001836f, 0.001997f, 0.002348f, 0.002878f, 0.003332f, 0.004131f, 0.005165f,
+ 0.006519f, 0.008568f, 0.011444f, 0.015419f, 0.021881f, 0.032532f, 0.052032f, 0.091187f, 0.177246f, 0.357910f, 0.610352f, 0.800781f,
+ 0.897461f, 0.942871f, 0.985352f, 0.986328f, 0.986816f, 0.986328f, 0.986328f, 0.986328f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000099f, 0.000076f,
+ 0.000060f, 0.000108f, 0.000040f, 0.000127f, 0.000127f, 0.000121f, 0.000200f, 0.000265f, 0.000360f, 0.000316f, 0.000428f, 0.000455f,
+ 0.000456f, 0.000583f, 0.000682f, 0.000750f, 0.000773f, 0.000824f, 0.000937f, 0.001220f, 0.001262f, 0.001384f, 0.001622f, 0.001862f,
+ 0.002157f, 0.002817f, 0.003414f, 0.004082f, 0.004993f, 0.006561f, 0.008560f, 0.011696f, 0.016022f, 0.023529f, 0.036469f, 0.062286f,
+ 0.117126f, 0.245605f, 0.487549f, 0.732910f, 0.870605f, 0.933105f, 0.983887f, 0.984863f, 0.984863f, 0.984863f, 0.984375f, 0.984863f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000096f, 0.000075f, 0.000061f, 0.000083f, 0.000096f, 0.000034f, 0.000101f, 0.000121f, 0.000137f,
+ 0.000211f, 0.000324f, 0.000381f, 0.000373f, 0.000420f, 0.000472f, 0.000494f, 0.000690f, 0.000793f, 0.000768f, 0.000853f, 0.000867f,
+ 0.000978f, 0.001003f, 0.001145f, 0.001416f, 0.001888f, 0.002125f, 0.002491f, 0.003004f, 0.003864f, 0.005028f, 0.006500f, 0.008682f,
+ 0.011856f, 0.016922f, 0.025757f, 0.042603f, 0.078247f, 0.161743f, 0.358398f, 0.641602f, 0.833496f, 0.920410f, 0.981934f, 0.982910f,
+ 0.982910f, 0.982910f, 0.982910f, 0.982910f, 0.000122f, 0.000000f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000120f, 0.000097f, 0.000078f, 0.000062f, 0.000051f,
+ 0.000043f, 0.000072f, 0.000030f, 0.000060f, 0.000109f, 0.000206f, 0.000216f, 0.000333f, 0.000347f, 0.000395f, 0.000415f, 0.000458f,
+ 0.000568f, 0.000664f, 0.000709f, 0.000598f, 0.000781f, 0.000628f, 0.001053f, 0.001046f, 0.001179f, 0.001579f, 0.001649f, 0.002386f,
+ 0.002857f, 0.003727f, 0.004894f, 0.006363f, 0.008789f, 0.012314f, 0.018616f, 0.029709f, 0.052429f, 0.105652f, 0.244385f, 0.524414f,
+ 0.782715f, 0.904785f, 0.979492f, 0.980957f, 0.979980f, 0.979980f, 0.980469f, 0.980469f, 0.000000f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000097f, 0.000079f, 0.000065f, 0.000054f, 0.000045f, 0.000073f, 0.000032f, 0.000089f, 0.000038f, 0.000134f, 0.000138f,
+ 0.000211f, 0.000333f, 0.000370f, 0.000400f, 0.000420f, 0.000496f, 0.000566f, 0.000494f, 0.000584f, 0.000714f, 0.000708f, 0.000843f,
+ 0.001056f, 0.001019f, 0.001327f, 0.001812f, 0.001908f, 0.002798f, 0.003479f, 0.004578f, 0.006195f, 0.008881f, 0.012901f, 0.020599f,
+ 0.035339f, 0.069214f, 0.159058f, 0.394531f, 0.709961f, 0.882812f, 0.977051f, 0.978027f, 0.977539f, 0.976562f, 0.977051f, 0.977539f,
+ 0.000000f, 0.000121f, 0.000120f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f,
+ 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000119f, 0.000120f, 0.000102f, 0.000084f, 0.000071f, 0.000059f, 0.000048f, 0.000041f,
+ 0.000035f, 0.000062f, 0.000026f, 0.000098f, 0.000103f, 0.000136f, 0.000230f, 0.000327f, 0.000356f, 0.000338f, 0.000387f, 0.000499f,
+ 0.000577f, 0.000627f, 0.000669f, 0.000611f, 0.000699f, 0.000904f, 0.000893f, 0.001340f, 0.001666f, 0.002068f, 0.002377f, 0.003105f,
+ 0.004345f, 0.006218f, 0.009178f, 0.013962f, 0.024170f, 0.045441f, 0.101868f, 0.271973f, 0.612305f, 0.853027f, 0.973145f, 0.974121f,
+ 0.973633f, 0.974121f, 0.973633f, 0.974121f, 0.000121f, 0.000120f, 0.000119f, 0.000120f, 0.000119f, 0.000119f, 0.000119f, 0.000119f,
+ 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000108f,
+ 0.000091f, 0.000075f, 0.000063f, 0.000053f, 0.000045f, 0.000039f, 0.000034f, 0.000040f, 0.000090f, 0.000068f, 0.000104f, 0.000127f,
+ 0.000220f, 0.000302f, 0.000412f, 0.000316f, 0.000444f, 0.000495f, 0.000428f, 0.000510f, 0.000463f, 0.000614f, 0.000726f, 0.000719f,
+ 0.001164f, 0.001533f, 0.001707f, 0.002079f, 0.002848f, 0.004189f, 0.006142f, 0.009491f, 0.016113f, 0.029343f, 0.064758f, 0.175415f,
+ 0.490723f, 0.812012f, 0.968750f, 0.969727f, 0.969238f, 0.969727f, 0.969727f, 0.969727f, 0.000000f, 0.000117f, 0.000117f, 0.000115f,
+ 0.000118f, 0.000118f, 0.000117f, 0.000117f, 0.000117f, 0.000117f, 0.000118f, 0.000117f, 0.000117f, 0.000118f, 0.000117f, 0.000117f,
+ 0.000117f, 0.000117f, 0.000117f, 0.000118f, 0.000117f, 0.000100f, 0.000082f, 0.000070f, 0.000060f, 0.000051f, 0.000043f, 0.000038f,
+ 0.000033f, 0.000053f, 0.000027f, 0.000089f, 0.000105f, 0.000137f, 0.000227f, 0.000277f, 0.000293f, 0.000284f, 0.000300f, 0.000420f,
+ 0.000367f, 0.000473f, 0.000467f, 0.000555f, 0.000625f, 0.000870f, 0.001177f, 0.001563f, 0.001982f, 0.002714f, 0.004051f, 0.006134f,
+ 0.010384f, 0.018967f, 0.040314f, 0.108887f, 0.358643f, 0.755859f, 0.962891f, 0.963867f, 0.964355f, 0.963867f, 0.963379f, 0.963379f,
+ 0.000000f, 0.000000f, 0.000098f, 0.000103f, 0.000111f, 0.000112f, 0.000112f, 0.000114f, 0.000113f, 0.000115f, 0.000114f, 0.000115f,
+ 0.000115f, 0.000115f, 0.000115f, 0.000115f, 0.000116f, 0.000116f, 0.000116f, 0.000116f, 0.000116f, 0.000116f, 0.000109f, 0.000094f,
+ 0.000078f, 0.000067f, 0.000058f, 0.000050f, 0.000043f, 0.000038f, 0.000033f, 0.000054f, 0.000025f, 0.000078f, 0.000091f, 0.000173f,
+ 0.000203f, 0.000252f, 0.000331f, 0.000277f, 0.000264f, 0.000407f, 0.000342f, 0.000444f, 0.000470f, 0.000542f, 0.000773f, 0.001081f,
+ 0.001245f, 0.001682f, 0.002602f, 0.003744f, 0.006248f, 0.011566f, 0.025040f, 0.065491f, 0.236938f, 0.678223f, 0.956055f, 0.956543f,
+ 0.956543f, 0.956543f, 0.957031f, 0.957031f, 0.000000f, 0.000000f, 0.000021f, 0.000080f, 0.000072f, 0.000089f, 0.000100f, 0.000099f,
+ 0.000105f, 0.000107f, 0.000107f, 0.000110f, 0.000109f, 0.000110f, 0.000111f, 0.000111f, 0.000112f, 0.000112f, 0.000112f, 0.000113f,
+ 0.000113f, 0.000113f, 0.000113f, 0.000113f, 0.000105f, 0.000090f, 0.000078f, 0.000067f, 0.000057f, 0.000050f, 0.000043f, 0.000038f,
+ 0.000033f, 0.000029f, 0.000025f, 0.000055f, 0.000091f, 0.000130f, 0.000225f, 0.000275f, 0.000254f, 0.000290f, 0.000259f, 0.000378f,
+ 0.000333f, 0.000362f, 0.000458f, 0.000587f, 0.000876f, 0.001062f, 0.001382f, 0.002398f, 0.003763f, 0.006603f, 0.014496f, 0.038300f,
+ 0.143677f, 0.573730f, 0.946777f, 0.947266f, 0.947266f, 0.947266f, 0.948242f, 0.947266f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000014f, 0.000036f, 0.000072f, 0.000082f, 0.000080f, 0.000094f, 0.000096f, 0.000099f, 0.000098f, 0.000103f, 0.000103f,
+ 0.000103f, 0.000106f, 0.000105f, 0.000107f, 0.000107f, 0.000108f, 0.000108f, 0.000109f, 0.000109f, 0.000109f, 0.000105f, 0.000090f,
+ 0.000078f, 0.000067f, 0.000059f, 0.000051f, 0.000045f, 0.000039f, 0.000034f, 0.000030f, 0.000026f, 0.000045f, 0.000086f, 0.000108f,
+ 0.000143f, 0.000212f, 0.000227f, 0.000204f, 0.000231f, 0.000263f, 0.000315f, 0.000354f, 0.000481f, 0.000702f, 0.000888f, 0.001257f,
+ 0.002018f, 0.003738f, 0.007675f, 0.021317f, 0.080933f, 0.444336f, 0.934082f, 0.935059f, 0.935059f, 0.935059f, 0.935059f, 0.935059f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000024f, 0.000038f, 0.000059f,
+ 0.000063f, 0.000076f, 0.000080f, 0.000085f, 0.000089f, 0.000091f, 0.000092f, 0.000095f, 0.000097f, 0.000099f, 0.000098f, 0.000101f,
+ 0.000101f, 0.000102f, 0.000103f, 0.000104f, 0.000104f, 0.000091f, 0.000080f, 0.000069f, 0.000062f, 0.000053f, 0.000046f, 0.000041f,
+ 0.000035f, 0.000032f, 0.000027f, 0.000039f, 0.000052f, 0.000103f, 0.000139f, 0.000178f, 0.000190f, 0.000178f, 0.000185f, 0.000247f,
+ 0.000274f, 0.000368f, 0.000528f, 0.000637f, 0.001027f, 0.001937f, 0.003853f, 0.010445f, 0.041718f, 0.304199f, 0.917480f, 0.917480f,
+ 0.917969f, 0.917480f, 0.918457f, 0.917969f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000023f, 0.000037f, 0.000048f, 0.000048f, 0.000063f, 0.000063f,
+ 0.000074f, 0.000077f, 0.000080f, 0.000083f, 0.000086f, 0.000088f, 0.000090f, 0.000091f, 0.000092f, 0.000094f, 0.000095f, 0.000096f,
+ 0.000084f, 0.000073f, 0.000064f, 0.000057f, 0.000049f, 0.000043f, 0.000037f, 0.000033f, 0.000029f, 0.000025f, 0.000060f, 0.000061f,
+ 0.000087f, 0.000118f, 0.000156f, 0.000131f, 0.000175f, 0.000226f, 0.000230f, 0.000373f, 0.000507f, 0.000992f, 0.001814f, 0.004639f,
+ 0.018799f, 0.176758f, 0.894043f, 0.894531f, 0.895508f, 0.895020f, 0.895020f, 0.895996f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000019f, 0.000028f, 0.000034f, 0.000043f, 0.000052f, 0.000057f, 0.000062f, 0.000067f,
+ 0.000070f, 0.000074f, 0.000075f, 0.000079f, 0.000081f, 0.000083f, 0.000085f, 0.000076f, 0.000068f, 0.000059f, 0.000051f, 0.000046f,
+ 0.000040f, 0.000035f, 0.000030f, 0.000026f, 0.000028f, 0.000038f, 0.000072f, 0.000100f, 0.000120f, 0.000107f, 0.000152f, 0.000156f,
+ 0.000254f, 0.000436f, 0.000722f, 0.001875f, 0.007088f, 0.083069f, 0.863281f, 0.862305f, 0.863281f, 0.862305f, 0.863281f, 0.862793f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000005f, 0.000015f, 0.000022f, 0.000030f, 0.000037f, 0.000042f, 0.000048f, 0.000053f, 0.000058f, 0.000060f,
+ 0.000064f, 0.000067f, 0.000069f, 0.000061f, 0.000053f, 0.000047f, 0.000041f, 0.000036f, 0.000031f, 0.000027f, 0.000023f, 0.000020f,
+ 0.000036f, 0.000063f, 0.000082f, 0.000081f, 0.000104f, 0.000149f, 0.000263f, 0.000616f, 0.002337f, 0.028168f, 0.816406f, 0.816895f,
+ 0.816895f, 0.816895f, 0.817383f, 0.816895f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000003f, 0.000011f, 0.000019f, 0.000026f, 0.000031f, 0.000036f, 0.000041f, 0.000045f, 0.000050f, 0.000047f,
+ 0.000041f, 0.000036f, 0.000031f, 0.000027f, 0.000023f, 0.000019f, 0.000028f, 0.000029f, 0.000053f, 0.000052f, 0.000072f, 0.000165f,
+ 0.000511f, 0.006050f, 0.751465f, 0.752441f, 0.752930f, 0.752441f, 0.752441f, 0.752930f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000004f, 0.000011f, 0.000017f, 0.000021f, 0.000027f, 0.000028f, 0.000024f, 0.000020f, 0.000017f,
+ 0.000013f, 0.000020f, 0.000021f, 0.000029f, 0.000057f, 0.000588f, 0.665039f, 0.664551f, 0.665527f, 0.665039f, 0.665039f, 0.665039f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000003f, 0.000009f, 0.000006f, 0.000004f, 0.000007f, 0.557129f, 0.558105f,
+ 0.557617f, 0.557617f, 0.558594f, 0.558105f,
+ },
+ {
+ 0.163818f, 0.558105f, 0.755859f, 0.841797f, 0.886230f, 0.912109f, 0.929199f, 0.941406f, 0.950195f, 0.957031f, 0.961914f, 0.966309f,
+ 0.970215f, 0.972656f, 0.975586f, 0.978027f, 0.979492f, 0.981445f, 0.982910f, 0.984375f, 0.985840f, 0.986328f, 0.987305f, 0.988770f,
+ 0.989258f, 0.989746f, 0.990234f, 0.991211f, 0.991699f, 0.992188f, 0.993164f, 0.993652f, 0.993652f, 0.993652f, 0.994141f, 0.995117f,
+ 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.027023f, 0.138184f, 0.353760f, 0.583984f, 0.735352f, 0.819336f, 0.868652f, 0.898926f,
+ 0.918945f, 0.933594f, 0.943848f, 0.952148f, 0.958984f, 0.963867f, 0.967773f, 0.971680f, 0.974121f, 0.976562f, 0.978516f, 0.980469f,
+ 0.982422f, 0.983398f, 0.984863f, 0.986328f, 0.986816f, 0.988281f, 0.989258f, 0.989746f, 0.990723f, 0.990723f, 0.991699f, 0.992676f,
+ 0.993164f, 0.993164f, 0.993652f, 0.994141f, 0.994141f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997070f,
+ 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.009819f, 0.044250f, 0.113525f, 0.244995f,
+ 0.430420f, 0.608887f, 0.733887f, 0.810547f, 0.860352f, 0.892578f, 0.913086f, 0.929688f, 0.940918f, 0.949219f, 0.956055f, 0.961426f,
+ 0.966309f, 0.970215f, 0.972656f, 0.975586f, 0.977539f, 0.979980f, 0.980957f, 0.983398f, 0.983887f, 0.985352f, 0.986328f, 0.987793f,
+ 0.988281f, 0.989746f, 0.989746f, 0.991211f, 0.991699f, 0.992188f, 0.992676f, 0.993164f, 0.993652f, 0.993652f, 0.994141f, 0.995117f,
+ 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.004848f, 0.020447f, 0.046814f, 0.096313f, 0.183228f, 0.319092f, 0.484375f, 0.631836f, 0.739258f, 0.810547f, 0.857422f, 0.888672f,
+ 0.910645f, 0.925781f, 0.938965f, 0.947754f, 0.954590f, 0.960449f, 0.964355f, 0.968750f, 0.971191f, 0.974609f, 0.977051f, 0.979004f,
+ 0.980957f, 0.982422f, 0.983887f, 0.985840f, 0.986816f, 0.987793f, 0.988770f, 0.989258f, 0.990234f, 0.990723f, 0.991211f, 0.991699f,
+ 0.992676f, 0.992676f, 0.993652f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996582f,
+ 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.003096f, 0.011017f, 0.024399f, 0.046600f, 0.083191f, 0.145386f, 0.243774f, 0.379395f,
+ 0.529297f, 0.656738f, 0.750977f, 0.813965f, 0.857910f, 0.887695f, 0.909668f, 0.925293f, 0.937500f, 0.946289f, 0.953613f, 0.959473f,
+ 0.964355f, 0.968262f, 0.971191f, 0.974121f, 0.976562f, 0.979004f, 0.980957f, 0.982910f, 0.984375f, 0.985840f, 0.986328f, 0.987793f,
+ 0.988281f, 0.989258f, 0.989746f, 0.991211f, 0.991699f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.001808f, 0.006992f, 0.014923f, 0.026413f,
+ 0.044403f, 0.073120f, 0.119446f, 0.193115f, 0.300537f, 0.433594f, 0.568848f, 0.680664f, 0.763184f, 0.821289f, 0.860840f, 0.890137f,
+ 0.909668f, 0.925293f, 0.937500f, 0.945801f, 0.953613f, 0.959473f, 0.963867f, 0.968262f, 0.971680f, 0.974609f, 0.977051f, 0.979004f,
+ 0.980957f, 0.982422f, 0.983887f, 0.984863f, 0.986816f, 0.987305f, 0.987793f, 0.989746f, 0.989746f, 0.991211f, 0.991699f, 0.992188f,
+ 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.994629f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997070f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.001668f, 0.005253f, 0.010010f, 0.016602f, 0.026459f, 0.042023f, 0.065369f, 0.101868f, 0.158081f, 0.241455f, 0.354248f, 0.483887f,
+ 0.606934f, 0.706055f, 0.777832f, 0.830566f, 0.867188f, 0.893066f, 0.912109f, 0.926270f, 0.938477f, 0.946289f, 0.953125f, 0.959473f,
+ 0.964355f, 0.968750f, 0.971680f, 0.975098f, 0.977051f, 0.979492f, 0.980957f, 0.982910f, 0.984375f, 0.985840f, 0.986328f, 0.987305f,
+ 0.988770f, 0.989746f, 0.990234f, 0.991211f, 0.992188f, 0.993164f, 0.993164f, 0.994141f, 0.994629f, 0.994629f, 0.995117f, 0.995605f,
+ 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998047f, 0.998535f, 0.999023f, 0.999023f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999023f, 0.001086f, 0.003477f, 0.006756f, 0.011604f, 0.018066f, 0.027222f, 0.039978f, 0.059448f,
+ 0.088257f, 0.132690f, 0.198120f, 0.291504f, 0.408447f, 0.531250f, 0.641602f, 0.728516f, 0.793457f, 0.839844f, 0.873047f, 0.896973f,
+ 0.915527f, 0.929199f, 0.939941f, 0.948730f, 0.955566f, 0.960938f, 0.965332f, 0.969238f, 0.972168f, 0.975098f, 0.977539f, 0.979492f,
+ 0.981445f, 0.983398f, 0.984375f, 0.985840f, 0.986816f, 0.988281f, 0.989258f, 0.989746f, 0.990723f, 0.991699f, 0.992188f, 0.993164f,
+ 0.993652f, 0.994141f, 0.994629f, 0.994629f, 0.995605f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997559f, 0.997559f,
+ 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000982f, 0.002764f, 0.004925f, 0.008194f,
+ 0.012703f, 0.018417f, 0.026154f, 0.037964f, 0.053894f, 0.078552f, 0.113770f, 0.166626f, 0.242310f, 0.343262f, 0.460449f, 0.576660f,
+ 0.675293f, 0.753418f, 0.809570f, 0.851074f, 0.879883f, 0.902344f, 0.919434f, 0.931152f, 0.941895f, 0.950195f, 0.956055f, 0.960938f,
+ 0.965820f, 0.969727f, 0.973145f, 0.976074f, 0.978027f, 0.980469f, 0.981934f, 0.983887f, 0.985352f, 0.986328f, 0.987793f, 0.988770f,
+ 0.989746f, 0.990234f, 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996582f, 0.996582f, 0.997559f, 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000723f, 0.002268f, 0.003639f, 0.006371f, 0.009392f, 0.013046f, 0.018570f, 0.026016f, 0.035919f, 0.049957f, 0.070618f, 0.099609f,
+ 0.142212f, 0.204590f, 0.290039f, 0.396973f, 0.512207f, 0.619141f, 0.707520f, 0.775391f, 0.825195f, 0.860352f, 0.887207f, 0.907715f,
+ 0.923340f, 0.935547f, 0.944824f, 0.951660f, 0.958496f, 0.963379f, 0.967773f, 0.971191f, 0.974121f, 0.977051f, 0.979492f, 0.980957f,
+ 0.982910f, 0.984375f, 0.985352f, 0.987305f, 0.988281f, 0.989258f, 0.989746f, 0.990723f, 0.991699f, 0.992188f, 0.993164f, 0.993164f,
+ 0.994141f, 0.994629f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000364f, 0.001690f, 0.003056f, 0.004982f, 0.007217f, 0.010124f, 0.013931f, 0.018738f,
+ 0.025177f, 0.034332f, 0.045990f, 0.063599f, 0.088501f, 0.124146f, 0.175781f, 0.248047f, 0.341797f, 0.451416f, 0.562012f, 0.659668f,
+ 0.738281f, 0.797852f, 0.841797f, 0.872559f, 0.896484f, 0.914062f, 0.928711f, 0.938477f, 0.947266f, 0.954590f, 0.959473f, 0.964844f,
+ 0.969238f, 0.972168f, 0.975098f, 0.977539f, 0.979980f, 0.981934f, 0.983398f, 0.985352f, 0.986816f, 0.987793f, 0.988770f, 0.989746f,
+ 0.990723f, 0.991211f, 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996094f, 0.996582f,
+ 0.997070f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000365f, 0.001221f, 0.002531f, 0.003979f,
+ 0.005829f, 0.007874f, 0.010475f, 0.013962f, 0.018402f, 0.024368f, 0.032257f, 0.042847f, 0.057983f, 0.079346f, 0.109375f, 0.153198f,
+ 0.214233f, 0.295898f, 0.397705f, 0.506836f, 0.609863f, 0.698730f, 0.767578f, 0.817871f, 0.854980f, 0.883301f, 0.903809f, 0.920410f,
+ 0.933105f, 0.942871f, 0.950195f, 0.957031f, 0.962402f, 0.966797f, 0.970703f, 0.973633f, 0.976562f, 0.979004f, 0.981445f, 0.982910f,
+ 0.984375f, 0.985840f, 0.986816f, 0.988281f, 0.989746f, 0.989746f, 0.991211f, 0.992188f, 0.992676f, 0.993164f, 0.993652f, 0.994141f,
+ 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.000343f, 0.001357f, 0.002039f, 0.003130f, 0.004398f, 0.006432f, 0.008141f, 0.010925f, 0.014008f, 0.018326f, 0.023331f, 0.030655f,
+ 0.040558f, 0.053680f, 0.071960f, 0.098206f, 0.134644f, 0.187012f, 0.258057f, 0.349854f, 0.455566f, 0.562012f, 0.656738f, 0.734863f,
+ 0.792969f, 0.836914f, 0.868652f, 0.894043f, 0.912598f, 0.926758f, 0.937988f, 0.947266f, 0.954590f, 0.960449f, 0.964355f, 0.968750f,
+ 0.972656f, 0.975586f, 0.978027f, 0.980469f, 0.981934f, 0.983398f, 0.985840f, 0.986816f, 0.988281f, 0.989258f, 0.990723f, 0.990723f,
+ 0.991699f, 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000244f, 0.001185f, 0.001561f, 0.002504f, 0.003990f, 0.005272f, 0.006573f, 0.008606f,
+ 0.010933f, 0.013878f, 0.017715f, 0.022415f, 0.029068f, 0.038086f, 0.049774f, 0.066162f, 0.088257f, 0.120361f, 0.164917f, 0.227173f,
+ 0.308838f, 0.407959f, 0.515137f, 0.615723f, 0.700684f, 0.767090f, 0.817383f, 0.854492f, 0.882812f, 0.904297f, 0.920898f, 0.932617f,
+ 0.943359f, 0.951172f, 0.957520f, 0.962891f, 0.967773f, 0.971191f, 0.974121f, 0.977539f, 0.979492f, 0.981445f, 0.983887f, 0.985352f,
+ 0.986816f, 0.988281f, 0.988770f, 0.989258f, 0.990723f, 0.991699f, 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.995117f, 0.995605f,
+ 0.995605f, 0.996582f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000243f, 0.000847f, 0.001555f, 0.002224f,
+ 0.003141f, 0.004093f, 0.005264f, 0.006817f, 0.008850f, 0.010948f, 0.014053f, 0.017456f, 0.022339f, 0.028351f, 0.036011f, 0.046326f,
+ 0.060791f, 0.080444f, 0.107788f, 0.146851f, 0.201660f, 0.274658f, 0.366699f, 0.470215f, 0.574707f, 0.666016f, 0.740234f, 0.797363f,
+ 0.839355f, 0.871094f, 0.895508f, 0.913574f, 0.927734f, 0.938965f, 0.947754f, 0.955566f, 0.960449f, 0.965332f, 0.969727f, 0.973145f,
+ 0.976074f, 0.979004f, 0.981445f, 0.982910f, 0.984863f, 0.986328f, 0.987305f, 0.988770f, 0.989258f, 0.990723f, 0.991699f, 0.992188f,
+ 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.996094f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000244f, 0.000767f, 0.001042f, 0.001934f, 0.002502f, 0.003588f, 0.004292f, 0.005558f, 0.006824f, 0.008667f, 0.010872f, 0.013802f,
+ 0.017426f, 0.021637f, 0.027176f, 0.033936f, 0.043304f, 0.056549f, 0.073914f, 0.098083f, 0.132446f, 0.180664f, 0.245239f, 0.330078f,
+ 0.429199f, 0.533203f, 0.631348f, 0.711914f, 0.775879f, 0.823242f, 0.860352f, 0.886230f, 0.907227f, 0.923340f, 0.935059f, 0.944824f,
+ 0.952148f, 0.958984f, 0.964844f, 0.968750f, 0.972168f, 0.975586f, 0.978516f, 0.980957f, 0.982422f, 0.983887f, 0.985840f, 0.987305f,
+ 0.988770f, 0.989746f, 0.990234f, 0.992188f, 0.992676f, 0.992676f, 0.994141f, 0.994141f, 0.995117f, 0.995605f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000000f, 0.000485f, 0.001062f, 0.001658f, 0.002398f, 0.002998f, 0.003805f, 0.004723f,
+ 0.006004f, 0.007084f, 0.009102f, 0.011093f, 0.013489f, 0.016876f, 0.020813f, 0.025803f, 0.032257f, 0.040924f, 0.052673f, 0.068298f,
+ 0.090149f, 0.120239f, 0.162598f, 0.221313f, 0.298096f, 0.392822f, 0.496582f, 0.597656f, 0.684082f, 0.754883f, 0.807617f, 0.848145f,
+ 0.877930f, 0.900391f, 0.917969f, 0.931641f, 0.941406f, 0.950684f, 0.957031f, 0.962402f, 0.967773f, 0.971680f, 0.974609f, 0.978027f,
+ 0.980469f, 0.982422f, 0.984375f, 0.985840f, 0.987305f, 0.988281f, 0.989746f, 0.990723f, 0.991699f, 0.992188f, 0.993164f, 0.993652f,
+ 0.994141f, 0.995117f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000244f, 0.000477f, 0.000852f, 0.001439f,
+ 0.002045f, 0.002424f, 0.003101f, 0.004093f, 0.004887f, 0.005989f, 0.007751f, 0.008606f, 0.011002f, 0.013420f, 0.016251f, 0.020035f,
+ 0.024628f, 0.030579f, 0.039093f, 0.049255f, 0.063599f, 0.083191f, 0.109924f, 0.148071f, 0.200928f, 0.270996f, 0.359863f, 0.461670f,
+ 0.564453f, 0.656738f, 0.732910f, 0.791992f, 0.836426f, 0.869629f, 0.894531f, 0.913086f, 0.928223f, 0.939453f, 0.949219f, 0.956055f,
+ 0.961914f, 0.966797f, 0.970703f, 0.975098f, 0.977051f, 0.979492f, 0.982422f, 0.983887f, 0.985352f, 0.987305f, 0.988770f, 0.989746f,
+ 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994629f, 0.998047f, 0.998535f, 0.998535f, 0.998047f, 0.998047f, 0.998535f,
+ 0.000242f, 0.000650f, 0.000847f, 0.001138f, 0.001621f, 0.002239f, 0.002527f, 0.003325f, 0.004227f, 0.005165f, 0.006462f, 0.007389f,
+ 0.008904f, 0.011024f, 0.013130f, 0.015915f, 0.019272f, 0.023819f, 0.029205f, 0.036652f, 0.046417f, 0.059418f, 0.077209f, 0.101562f,
+ 0.136230f, 0.183350f, 0.248047f, 0.331055f, 0.429688f, 0.533203f, 0.630859f, 0.711426f, 0.776367f, 0.824219f, 0.861328f, 0.887695f,
+ 0.908691f, 0.924805f, 0.937500f, 0.946777f, 0.954102f, 0.960938f, 0.966309f, 0.970215f, 0.974121f, 0.977539f, 0.979492f, 0.981934f,
+ 0.983887f, 0.985840f, 0.987305f, 0.989258f, 0.989746f, 0.990723f, 0.991211f, 0.992676f, 0.993164f, 0.994141f, 0.997559f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000089f, 0.000243f, 0.000827f, 0.000964f, 0.001418f, 0.001579f, 0.002296f, 0.002914f,
+ 0.003632f, 0.004280f, 0.005344f, 0.006130f, 0.007545f, 0.008949f, 0.010498f, 0.012733f, 0.015686f, 0.018646f, 0.023010f, 0.028229f,
+ 0.034851f, 0.044098f, 0.056122f, 0.072388f, 0.094788f, 0.125610f, 0.168945f, 0.228271f, 0.306396f, 0.401123f, 0.504883f, 0.604492f,
+ 0.691895f, 0.760742f, 0.813477f, 0.853027f, 0.881836f, 0.904297f, 0.921387f, 0.934570f, 0.944824f, 0.953125f, 0.959961f, 0.964844f,
+ 0.969727f, 0.973633f, 0.976562f, 0.979492f, 0.981934f, 0.983887f, 0.986328f, 0.987305f, 0.988281f, 0.989258f, 0.991211f, 0.992188f,
+ 0.992676f, 0.993652f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000069f, 0.000461f, 0.000609f, 0.000933f,
+ 0.001088f, 0.001488f, 0.001900f, 0.002378f, 0.003101f, 0.003687f, 0.004547f, 0.005276f, 0.006233f, 0.007282f, 0.008820f, 0.010239f,
+ 0.012581f, 0.015312f, 0.018341f, 0.022095f, 0.027344f, 0.034027f, 0.041687f, 0.053467f, 0.067810f, 0.088440f, 0.117126f, 0.156616f,
+ 0.211426f, 0.284180f, 0.375977f, 0.478760f, 0.581543f, 0.672363f, 0.746094f, 0.802734f, 0.845703f, 0.877441f, 0.900879f, 0.918457f,
+ 0.933105f, 0.943848f, 0.951660f, 0.959473f, 0.964355f, 0.968750f, 0.974121f, 0.977051f, 0.979492f, 0.982422f, 0.984375f, 0.985840f,
+ 0.987305f, 0.988770f, 0.990234f, 0.991211f, 0.992188f, 0.993164f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f,
+ 0.000244f, 0.000348f, 0.000606f, 0.000737f, 0.001079f, 0.001458f, 0.001783f, 0.002192f, 0.002924f, 0.003231f, 0.003862f, 0.004551f,
+ 0.005169f, 0.006367f, 0.007381f, 0.008682f, 0.010590f, 0.012199f, 0.014900f, 0.017761f, 0.021530f, 0.026108f, 0.032349f, 0.039642f,
+ 0.050446f, 0.064392f, 0.083313f, 0.109436f, 0.145996f, 0.197021f, 0.266357f, 0.354248f, 0.455811f, 0.560059f, 0.654785f, 0.732910f,
+ 0.793457f, 0.837891f, 0.873047f, 0.897461f, 0.917480f, 0.931641f, 0.941895f, 0.951172f, 0.958984f, 0.964844f, 0.969727f, 0.973633f,
+ 0.977051f, 0.979980f, 0.981934f, 0.984375f, 0.985840f, 0.988281f, 0.989258f, 0.990234f, 0.991211f, 0.992676f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000244f, 0.000520f, 0.000592f, 0.000720f, 0.000812f, 0.001174f, 0.001500f, 0.001884f,
+ 0.002178f, 0.002831f, 0.003321f, 0.003885f, 0.004471f, 0.005436f, 0.006275f, 0.007584f, 0.008675f, 0.010521f, 0.012238f, 0.014557f,
+ 0.017197f, 0.020874f, 0.025467f, 0.030960f, 0.038208f, 0.047821f, 0.061249f, 0.078552f, 0.103149f, 0.136841f, 0.184937f, 0.249878f,
+ 0.334473f, 0.435059f, 0.539551f, 0.638184f, 0.720215f, 0.784668f, 0.832031f, 0.868164f, 0.894531f, 0.914062f, 0.929688f, 0.942383f,
+ 0.950684f, 0.958984f, 0.964844f, 0.970215f, 0.974121f, 0.977539f, 0.979980f, 0.982422f, 0.984863f, 0.985840f, 0.988281f, 0.989258f,
+ 0.990723f, 0.992188f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997559f, 0.997559f, 0.000000f, 0.000243f, 0.000351f, 0.000603f,
+ 0.000708f, 0.001079f, 0.001493f, 0.001752f, 0.001936f, 0.002171f, 0.002911f, 0.003382f, 0.003906f, 0.004578f, 0.005222f, 0.006161f,
+ 0.007362f, 0.008850f, 0.010010f, 0.011971f, 0.014145f, 0.016983f, 0.020477f, 0.024582f, 0.029739f, 0.036804f, 0.045837f, 0.057648f,
+ 0.074829f, 0.097534f, 0.130127f, 0.174438f, 0.236572f, 0.318604f, 0.416992f, 0.523926f, 0.624023f, 0.709961f, 0.777344f, 0.827148f,
+ 0.865234f, 0.893066f, 0.914062f, 0.929688f, 0.941406f, 0.951660f, 0.958496f, 0.965820f, 0.969238f, 0.974609f, 0.977539f, 0.980469f,
+ 0.983398f, 0.985352f, 0.986816f, 0.988281f, 0.989746f, 0.990723f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997070f,
+ 0.000243f, 0.000244f, 0.000456f, 0.000592f, 0.000602f, 0.001025f, 0.001282f, 0.001656f, 0.001856f, 0.002073f, 0.002535f, 0.002768f,
+ 0.003487f, 0.003822f, 0.004574f, 0.005589f, 0.006519f, 0.007336f, 0.008453f, 0.009911f, 0.011581f, 0.013985f, 0.016373f, 0.019638f,
+ 0.023819f, 0.028473f, 0.035339f, 0.043945f, 0.055939f, 0.071350f, 0.093140f, 0.123474f, 0.165771f, 0.225342f, 0.304199f, 0.402344f,
+ 0.509277f, 0.612305f, 0.702148f, 0.771973f, 0.824219f, 0.863281f, 0.891113f, 0.913086f, 0.930176f, 0.942383f, 0.951660f, 0.959473f,
+ 0.965820f, 0.970215f, 0.974609f, 0.977539f, 0.980957f, 0.983887f, 0.985352f, 0.987305f, 0.988770f, 0.990723f, 0.996582f, 0.996582f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.000000f, 0.000243f, 0.000276f, 0.000557f, 0.000594f, 0.000849f, 0.000845f, 0.001282f,
+ 0.001520f, 0.001774f, 0.002119f, 0.002499f, 0.002840f, 0.003252f, 0.004005f, 0.004555f, 0.005245f, 0.006168f, 0.007233f, 0.008301f,
+ 0.009911f, 0.011330f, 0.013748f, 0.015945f, 0.019089f, 0.023071f, 0.027786f, 0.034058f, 0.042542f, 0.053619f, 0.068237f, 0.089539f,
+ 0.117798f, 0.158325f, 0.215698f, 0.293213f, 0.389893f, 0.498291f, 0.603027f, 0.694824f, 0.767090f, 0.821777f, 0.862305f, 0.891113f,
+ 0.914062f, 0.930176f, 0.942383f, 0.952148f, 0.959473f, 0.965820f, 0.971680f, 0.975098f, 0.978516f, 0.981445f, 0.983887f, 0.985840f,
+ 0.988281f, 0.989258f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996094f, 0.996582f, 0.000240f, 0.000240f, 0.000242f, 0.000365f,
+ 0.000678f, 0.000779f, 0.000957f, 0.001003f, 0.001390f, 0.001656f, 0.001828f, 0.002274f, 0.002455f, 0.003210f, 0.003704f, 0.004097f,
+ 0.004616f, 0.005409f, 0.006180f, 0.007092f, 0.008453f, 0.009521f, 0.011154f, 0.013397f, 0.015656f, 0.018509f, 0.022247f, 0.026810f,
+ 0.032928f, 0.041046f, 0.051727f, 0.065613f, 0.085205f, 0.113098f, 0.152832f, 0.208496f, 0.284424f, 0.380371f, 0.489258f, 0.596680f,
+ 0.690918f, 0.764648f, 0.821777f, 0.862305f, 0.892578f, 0.914551f, 0.931152f, 0.943848f, 0.953613f, 0.960938f, 0.967773f, 0.971680f,
+ 0.976074f, 0.979492f, 0.982422f, 0.984863f, 0.986816f, 0.988281f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.996094f,
+ 0.000000f, 0.000242f, 0.000242f, 0.000364f, 0.000465f, 0.000803f, 0.000927f, 0.000956f, 0.001275f, 0.001335f, 0.001570f, 0.001968f,
+ 0.002184f, 0.002726f, 0.003069f, 0.003294f, 0.003906f, 0.004662f, 0.005245f, 0.006027f, 0.007191f, 0.008202f, 0.009460f, 0.010735f,
+ 0.012970f, 0.015404f, 0.018051f, 0.021484f, 0.026321f, 0.032135f, 0.039581f, 0.049805f, 0.063538f, 0.082458f, 0.109497f, 0.147827f,
+ 0.202393f, 0.277344f, 0.373535f, 0.483887f, 0.593262f, 0.688477f, 0.764648f, 0.821289f, 0.863281f, 0.894043f, 0.916016f, 0.932129f,
+ 0.944336f, 0.954590f, 0.962402f, 0.968262f, 0.973633f, 0.977051f, 0.980957f, 0.983398f, 0.985352f, 0.987793f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.000000f, 0.000239f, 0.000360f, 0.000362f, 0.000363f, 0.000475f, 0.000767f, 0.000931f,
+ 0.000951f, 0.001211f, 0.001491f, 0.001634f, 0.002129f, 0.002457f, 0.002678f, 0.002995f, 0.003393f, 0.003922f, 0.004711f, 0.005135f,
+ 0.005955f, 0.006935f, 0.008072f, 0.009270f, 0.010841f, 0.012558f, 0.014618f, 0.017502f, 0.020828f, 0.025269f, 0.030884f, 0.038269f,
+ 0.048218f, 0.061554f, 0.080505f, 0.106567f, 0.144287f, 0.197998f, 0.272705f, 0.369141f, 0.480469f, 0.591797f, 0.690430f, 0.767090f,
+ 0.824707f, 0.866699f, 0.896484f, 0.918457f, 0.934570f, 0.946777f, 0.956543f, 0.963379f, 0.969727f, 0.974609f, 0.978027f, 0.981934f,
+ 0.984375f, 0.986328f, 0.995117f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.000000f, 0.000208f, 0.000238f, 0.000362f,
+ 0.000363f, 0.000555f, 0.000600f, 0.000888f, 0.001140f, 0.001140f, 0.001272f, 0.001661f, 0.001811f, 0.002041f, 0.002550f, 0.002636f,
+ 0.002941f, 0.003492f, 0.004032f, 0.004593f, 0.005062f, 0.005875f, 0.007015f, 0.007965f, 0.009079f, 0.010300f, 0.012291f, 0.014229f,
+ 0.016937f, 0.020248f, 0.024689f, 0.030151f, 0.037354f, 0.047028f, 0.060211f, 0.078491f, 0.104431f, 0.141602f, 0.195068f, 0.270264f,
+ 0.367676f, 0.480957f, 0.594238f, 0.693848f, 0.770996f, 0.828613f, 0.869629f, 0.898438f, 0.921875f, 0.937012f, 0.949219f, 0.958008f,
+ 0.964844f, 0.971680f, 0.976074f, 0.979980f, 0.982422f, 0.985840f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.995117f, 0.995117f,
+ 0.000000f, 0.000000f, 0.000229f, 0.000358f, 0.000479f, 0.000362f, 0.000498f, 0.000634f, 0.000836f, 0.000927f, 0.001288f, 0.001244f,
+ 0.001605f, 0.001732f, 0.002106f, 0.002478f, 0.002613f, 0.003183f, 0.003510f, 0.004021f, 0.004528f, 0.005047f, 0.005768f, 0.006859f,
+ 0.007759f, 0.008865f, 0.009933f, 0.011742f, 0.013741f, 0.016678f, 0.019897f, 0.024017f, 0.029297f, 0.036469f, 0.045990f, 0.058990f,
+ 0.077026f, 0.102722f, 0.140015f, 0.193604f, 0.269531f, 0.369141f, 0.485107f, 0.600098f, 0.700195f, 0.777344f, 0.833984f, 0.873535f,
+ 0.903809f, 0.924316f, 0.940430f, 0.951172f, 0.960938f, 0.968262f, 0.973145f, 0.978027f, 0.980957f, 0.983887f, 0.994629f, 0.995117f,
+ 0.995117f, 0.995605f, 0.995117f, 0.995117f, 0.000000f, 0.000000f, 0.000078f, 0.000353f, 0.000354f, 0.000360f, 0.000482f, 0.000573f,
+ 0.000757f, 0.000923f, 0.001230f, 0.001266f, 0.001485f, 0.001679f, 0.001963f, 0.002161f, 0.002235f, 0.002739f, 0.003115f, 0.003563f,
+ 0.003933f, 0.004436f, 0.004917f, 0.005623f, 0.006599f, 0.007469f, 0.008484f, 0.010101f, 0.011665f, 0.013695f, 0.016403f, 0.019531f,
+ 0.023300f, 0.028870f, 0.035889f, 0.045135f, 0.058014f, 0.075928f, 0.101746f, 0.139160f, 0.193848f, 0.271729f, 0.374023f, 0.492920f,
+ 0.609863f, 0.709473f, 0.786133f, 0.842285f, 0.880859f, 0.908691f, 0.928711f, 0.943848f, 0.954102f, 0.963867f, 0.969727f, 0.975098f,
+ 0.979004f, 0.982422f, 0.994141f, 0.994629f, 0.994141f, 0.994141f, 0.994141f, 0.994629f, 0.000000f, 0.000000f, 0.000000f, 0.000330f,
+ 0.000336f, 0.000352f, 0.000478f, 0.000481f, 0.000676f, 0.000822f, 0.001072f, 0.001228f, 0.001283f, 0.001417f, 0.001621f, 0.001938f,
+ 0.001953f, 0.002377f, 0.002737f, 0.002914f, 0.003624f, 0.003721f, 0.004555f, 0.004845f, 0.005531f, 0.006325f, 0.007244f, 0.008255f,
+ 0.009911f, 0.011467f, 0.013496f, 0.016068f, 0.018951f, 0.022888f, 0.028183f, 0.035126f, 0.044617f, 0.057220f, 0.075134f, 0.101501f,
+ 0.139526f, 0.195679f, 0.276123f, 0.381592f, 0.503418f, 0.622070f, 0.721680f, 0.796387f, 0.850098f, 0.887207f, 0.914551f, 0.933594f,
+ 0.947266f, 0.957520f, 0.966797f, 0.972656f, 0.977539f, 0.980957f, 0.993164f, 0.994141f, 0.994141f, 0.994141f, 0.994141f, 0.994141f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000243f, 0.000466f, 0.000474f, 0.000475f, 0.000600f, 0.000740f, 0.000796f, 0.001130f,
+ 0.001333f, 0.001339f, 0.001440f, 0.001575f, 0.001961f, 0.002031f, 0.002388f, 0.002563f, 0.003174f, 0.003345f, 0.003555f, 0.004143f,
+ 0.004681f, 0.005333f, 0.006191f, 0.007111f, 0.008278f, 0.009666f, 0.011177f, 0.013451f, 0.015511f, 0.018707f, 0.022629f, 0.027847f,
+ 0.034515f, 0.043976f, 0.056671f, 0.075012f, 0.101685f, 0.140869f, 0.199341f, 0.282959f, 0.393311f, 0.519043f, 0.639160f, 0.736328f,
+ 0.809082f, 0.860352f, 0.896484f, 0.920898f, 0.939453f, 0.951660f, 0.961914f, 0.969238f, 0.975098f, 0.979492f, 0.993164f, 0.993652f,
+ 0.994141f, 0.993652f, 0.993652f, 0.993652f, 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000120f, 0.000367f, 0.000448f, 0.000589f,
+ 0.000595f, 0.000719f, 0.000707f, 0.000809f, 0.000966f, 0.001217f, 0.001369f, 0.001405f, 0.001579f, 0.001786f, 0.002100f, 0.002260f,
+ 0.002600f, 0.002762f, 0.003023f, 0.003531f, 0.004219f, 0.004810f, 0.005409f, 0.006092f, 0.007053f, 0.008064f, 0.009163f, 0.010941f,
+ 0.012733f, 0.015251f, 0.018280f, 0.022202f, 0.027573f, 0.034271f, 0.043732f, 0.056458f, 0.075134f, 0.102661f, 0.143433f, 0.205078f,
+ 0.293701f, 0.409668f, 0.538574f, 0.658203f, 0.753418f, 0.823242f, 0.870605f, 0.905273f, 0.927734f, 0.943848f, 0.956055f, 0.964844f,
+ 0.972168f, 0.977539f, 0.992188f, 0.992676f, 0.993164f, 0.993652f, 0.993164f, 0.992676f, 0.000000f, 0.000000f, 0.000000f, 0.000111f,
+ 0.000224f, 0.000231f, 0.000314f, 0.000562f, 0.000589f, 0.000699f, 0.000717f, 0.000776f, 0.000926f, 0.000968f, 0.001242f, 0.001360f,
+ 0.001487f, 0.001564f, 0.001713f, 0.002073f, 0.002169f, 0.002380f, 0.002941f, 0.003229f, 0.003534f, 0.003914f, 0.004509f, 0.005127f,
+ 0.005939f, 0.006596f, 0.007812f, 0.009354f, 0.010559f, 0.012581f, 0.015007f, 0.018021f, 0.022079f, 0.027191f, 0.034119f, 0.043427f,
+ 0.057190f, 0.075623f, 0.104492f, 0.147949f, 0.213135f, 0.308105f, 0.430664f, 0.562500f, 0.681641f, 0.772949f, 0.839355f, 0.884277f,
+ 0.913574f, 0.934570f, 0.950195f, 0.961426f, 0.969238f, 0.975098f, 0.991211f, 0.992676f, 0.992676f, 0.992676f, 0.992676f, 0.992188f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000084f, 0.000117f, 0.000119f, 0.000367f, 0.000473f, 0.000555f, 0.000576f, 0.000674f, 0.000713f,
+ 0.000816f, 0.000913f, 0.001049f, 0.001168f, 0.001263f, 0.001473f, 0.001580f, 0.001781f, 0.002005f, 0.002123f, 0.002316f, 0.002674f,
+ 0.003094f, 0.003475f, 0.003967f, 0.004318f, 0.004833f, 0.005798f, 0.006699f, 0.007801f, 0.008888f, 0.010429f, 0.012268f, 0.014824f,
+ 0.017792f, 0.021790f, 0.026978f, 0.033844f, 0.043518f, 0.057068f, 0.077148f, 0.107605f, 0.154053f, 0.224609f, 0.326904f, 0.456543f,
+ 0.591797f, 0.708984f, 0.795410f, 0.855957f, 0.895508f, 0.923340f, 0.942383f, 0.955566f, 0.965332f, 0.973145f, 0.991211f, 0.991699f,
+ 0.992188f, 0.992188f, 0.992188f, 0.991699f, 0.000000f, 0.000000f, 0.000000f, 0.000092f, 0.000070f, 0.000236f, 0.000119f, 0.000376f,
+ 0.000433f, 0.000561f, 0.000688f, 0.000586f, 0.000742f, 0.000842f, 0.000881f, 0.000937f, 0.001141f, 0.001300f, 0.001434f, 0.001464f,
+ 0.001598f, 0.001829f, 0.002062f, 0.002338f, 0.002583f, 0.003036f, 0.003460f, 0.003704f, 0.004383f, 0.004986f, 0.005615f, 0.006439f,
+ 0.007267f, 0.008797f, 0.010330f, 0.012146f, 0.014473f, 0.017532f, 0.021622f, 0.026535f, 0.033539f, 0.043579f, 0.058044f, 0.079041f,
+ 0.111572f, 0.162109f, 0.239746f, 0.350830f, 0.488770f, 0.625000f, 0.737305f, 0.817871f, 0.871582f, 0.908203f, 0.932129f, 0.949219f,
+ 0.961914f, 0.970215f, 0.990234f, 0.991211f, 0.991211f, 0.991211f, 0.991211f, 0.991211f, 0.000000f, 0.000000f, 0.000000f, 0.000080f,
+ 0.000100f, 0.000115f, 0.000335f, 0.000350f, 0.000355f, 0.000473f, 0.000633f, 0.000678f, 0.000695f, 0.000694f, 0.000812f, 0.000733f,
+ 0.001109f, 0.001098f, 0.001260f, 0.001452f, 0.001377f, 0.001534f, 0.001972f, 0.001982f, 0.002232f, 0.002567f, 0.002764f, 0.003273f,
+ 0.003542f, 0.004181f, 0.004738f, 0.005466f, 0.006268f, 0.007126f, 0.008614f, 0.010170f, 0.012093f, 0.014359f, 0.017075f, 0.021042f,
+ 0.026459f, 0.033722f, 0.044159f, 0.059113f, 0.082092f, 0.117249f, 0.173218f, 0.259766f, 0.382080f, 0.526367f, 0.662598f, 0.768066f,
+ 0.840332f, 0.889648f, 0.920410f, 0.940918f, 0.956543f, 0.966309f, 0.989746f, 0.990234f, 0.990723f, 0.990723f, 0.990723f, 0.990723f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000191f, 0.000236f, 0.000335f, 0.000337f, 0.000466f, 0.000399f, 0.000608f,
+ 0.000626f, 0.000669f, 0.000696f, 0.000808f, 0.000859f, 0.000915f, 0.000903f, 0.001168f, 0.001245f, 0.001500f, 0.001525f, 0.001863f,
+ 0.001941f, 0.002121f, 0.002399f, 0.002861f, 0.002953f, 0.003632f, 0.004105f, 0.004745f, 0.005333f, 0.006317f, 0.007236f, 0.008255f,
+ 0.009857f, 0.011414f, 0.014015f, 0.016922f, 0.020828f, 0.026321f, 0.034149f, 0.044861f, 0.061279f, 0.085571f, 0.124878f, 0.187866f,
+ 0.285645f, 0.420654f, 0.570801f, 0.703125f, 0.799805f, 0.864258f, 0.905273f, 0.932129f, 0.950684f, 0.963379f, 0.988770f, 0.989258f,
+ 0.989746f, 0.989746f, 0.989746f, 0.989746f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000000f, 0.000122f, 0.000125f, 0.000232f,
+ 0.000360f, 0.000342f, 0.000463f, 0.000388f, 0.000569f, 0.000638f, 0.000671f, 0.000791f, 0.000774f, 0.000943f, 0.000774f, 0.001018f,
+ 0.001044f, 0.001245f, 0.001377f, 0.001410f, 0.001643f, 0.001970f, 0.002041f, 0.002316f, 0.002758f, 0.003023f, 0.003433f, 0.003859f,
+ 0.004444f, 0.005180f, 0.006134f, 0.006920f, 0.008102f, 0.009354f, 0.011475f, 0.013649f, 0.016739f, 0.021011f, 0.026566f, 0.034454f,
+ 0.046051f, 0.063843f, 0.090942f, 0.135498f, 0.207642f, 0.319580f, 0.467529f, 0.620605f, 0.745605f, 0.830566f, 0.886230f, 0.920898f,
+ 0.943848f, 0.958984f, 0.987793f, 0.988281f, 0.988770f, 0.988770f, 0.988281f, 0.988770f, 0.000000f, 0.000000f, 0.000000f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000188f, 0.000200f, 0.000332f, 0.000417f, 0.000338f, 0.000459f, 0.000349f, 0.000558f, 0.000642f, 0.000636f,
+ 0.000629f, 0.000807f, 0.000695f, 0.000747f, 0.000827f, 0.001058f, 0.001182f, 0.001269f, 0.001422f, 0.001472f, 0.001921f, 0.002100f,
+ 0.002337f, 0.002462f, 0.003073f, 0.003374f, 0.003708f, 0.004265f, 0.004826f, 0.005646f, 0.006596f, 0.007710f, 0.008926f, 0.011063f,
+ 0.013580f, 0.016495f, 0.020737f, 0.026459f, 0.035126f, 0.047791f, 0.066833f, 0.097778f, 0.149170f, 0.233887f, 0.363037f, 0.523438f,
+ 0.674805f, 0.788086f, 0.860352f, 0.906250f, 0.935547f, 0.954102f, 0.986328f, 0.987305f, 0.987305f, 0.987305f, 0.987305f, 0.987793f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000175f, 0.000155f, 0.000319f, 0.000241f, 0.000318f,
+ 0.000455f, 0.000462f, 0.000496f, 0.000593f, 0.000516f, 0.000564f, 0.000667f, 0.000668f, 0.000715f, 0.000749f, 0.000925f, 0.001111f,
+ 0.001246f, 0.001381f, 0.001443f, 0.001856f, 0.001997f, 0.002264f, 0.002363f, 0.002880f, 0.003212f, 0.003727f, 0.004208f, 0.004673f,
+ 0.005394f, 0.006367f, 0.007404f, 0.009003f, 0.010651f, 0.013138f, 0.016312f, 0.020767f, 0.027054f, 0.036377f, 0.050262f, 0.071655f,
+ 0.107361f, 0.167969f, 0.269287f, 0.418457f, 0.587402f, 0.730957f, 0.828125f, 0.888184f, 0.924805f, 0.948242f, 0.984863f, 0.986328f,
+ 0.986328f, 0.985840f, 0.986328f, 0.986328f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f,
+ 0.000202f, 0.000133f, 0.000215f, 0.000263f, 0.000304f, 0.000442f, 0.000332f, 0.000365f, 0.000403f, 0.000549f, 0.000607f, 0.000750f,
+ 0.000788f, 0.000802f, 0.000841f, 0.000958f, 0.001049f, 0.001188f, 0.001354f, 0.001318f, 0.001582f, 0.001928f, 0.002064f, 0.002321f,
+ 0.002594f, 0.003042f, 0.003222f, 0.003796f, 0.004440f, 0.005112f, 0.006081f, 0.007259f, 0.008736f, 0.010612f, 0.013077f, 0.016464f,
+ 0.020950f, 0.027664f, 0.037506f, 0.052795f, 0.077698f, 0.120361f, 0.194336f, 0.317627f, 0.486572f, 0.657227f, 0.785156f, 0.865234f,
+ 0.913086f, 0.942871f, 0.983887f, 0.984863f, 0.984375f, 0.984863f, 0.984375f, 0.984863f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000152f, 0.000257f, 0.000243f, 0.000288f, 0.000345f, 0.000228f,
+ 0.000358f, 0.000363f, 0.000432f, 0.000494f, 0.000530f, 0.000582f, 0.000762f, 0.000771f, 0.000913f, 0.000978f, 0.001100f, 0.001305f,
+ 0.001373f, 0.001706f, 0.001712f, 0.001922f, 0.002155f, 0.002569f, 0.002573f, 0.003094f, 0.003401f, 0.004272f, 0.004978f, 0.005829f,
+ 0.006924f, 0.008453f, 0.010452f, 0.012871f, 0.016617f, 0.021072f, 0.028427f, 0.039429f, 0.056732f, 0.086243f, 0.138916f, 0.231812f,
+ 0.381592f, 0.566406f, 0.726562f, 0.833496f, 0.896973f, 0.933594f, 0.981934f, 0.982910f, 0.982910f, 0.982910f, 0.982910f, 0.982910f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000121f, 0.000127f, 0.000215f,
+ 0.000159f, 0.000233f, 0.000284f, 0.000326f, 0.000339f, 0.000339f, 0.000352f, 0.000394f, 0.000623f, 0.000622f, 0.000731f, 0.000730f,
+ 0.000741f, 0.000829f, 0.000914f, 0.001017f, 0.001151f, 0.001469f, 0.001263f, 0.001480f, 0.001740f, 0.002069f, 0.002104f, 0.002443f,
+ 0.002831f, 0.003519f, 0.003929f, 0.004627f, 0.005455f, 0.006634f, 0.008316f, 0.009949f, 0.012596f, 0.016495f, 0.021729f, 0.029877f,
+ 0.042084f, 0.062805f, 0.098694f, 0.165283f, 0.284668f, 0.465088f, 0.654297f, 0.793945f, 0.877930f, 0.924805f, 0.979980f, 0.980957f,
+ 0.980957f, 0.981445f, 0.981445f, 0.980957f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000150f, 0.000163f, 0.000069f, 0.000057f, 0.000121f, 0.000231f, 0.000291f, 0.000304f, 0.000334f, 0.000339f,
+ 0.000346f, 0.000569f, 0.000648f, 0.000674f, 0.000649f, 0.000697f, 0.000772f, 0.000834f, 0.000972f, 0.001005f, 0.001189f, 0.001359f,
+ 0.001237f, 0.001567f, 0.001794f, 0.001963f, 0.002378f, 0.002712f, 0.002867f, 0.003853f, 0.004330f, 0.005196f, 0.006516f, 0.008026f,
+ 0.009888f, 0.012703f, 0.016479f, 0.022110f, 0.031158f, 0.045746f, 0.070557f, 0.117004f, 0.204956f, 0.360596f, 0.564453f, 0.740723f,
+ 0.852051f, 0.912598f, 0.977539f, 0.979492f, 0.979492f, 0.979004f, 0.979492f, 0.979004f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000098f, 0.000082f, 0.000067f, 0.000056f, 0.000124f,
+ 0.000193f, 0.000240f, 0.000258f, 0.000310f, 0.000326f, 0.000335f, 0.000341f, 0.000471f, 0.000613f, 0.000494f, 0.000716f, 0.000742f,
+ 0.000804f, 0.000873f, 0.000832f, 0.001070f, 0.001120f, 0.001146f, 0.001225f, 0.001696f, 0.001814f, 0.002041f, 0.002419f, 0.002941f,
+ 0.003433f, 0.004154f, 0.004818f, 0.006077f, 0.007652f, 0.009521f, 0.012444f, 0.017029f, 0.023193f, 0.033539f, 0.050690f, 0.082092f,
+ 0.144043f, 0.265869f, 0.463379f, 0.672363f, 0.818848f, 0.898438f, 0.975586f, 0.976562f, 0.976562f, 0.976562f, 0.976074f, 0.976562f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000114f,
+ 0.000096f, 0.000079f, 0.000125f, 0.000056f, 0.000142f, 0.000120f, 0.000195f, 0.000246f, 0.000321f, 0.000305f, 0.000319f, 0.000395f,
+ 0.000442f, 0.000540f, 0.000642f, 0.000638f, 0.000696f, 0.000674f, 0.000687f, 0.000857f, 0.000955f, 0.001128f, 0.001224f, 0.001364f,
+ 0.001347f, 0.001555f, 0.001910f, 0.002245f, 0.002714f, 0.003229f, 0.003824f, 0.004673f, 0.005676f, 0.007225f, 0.009293f, 0.012802f,
+ 0.017273f, 0.024368f, 0.036682f, 0.058075f, 0.100952f, 0.188721f, 0.358154f, 0.587891f, 0.775879f, 0.881348f, 0.972168f, 0.972656f,
+ 0.972656f, 0.973145f, 0.973145f, 0.973633f, 0.000000f, 0.000000f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000120f, 0.000112f, 0.000093f, 0.000079f, 0.000067f, 0.000057f, 0.000049f, 0.000133f, 0.000137f,
+ 0.000163f, 0.000244f, 0.000328f, 0.000366f, 0.000356f, 0.000415f, 0.000436f, 0.000543f, 0.000555f, 0.000638f, 0.000597f, 0.000702f,
+ 0.000786f, 0.000648f, 0.000891f, 0.000804f, 0.001218f, 0.001070f, 0.001355f, 0.001731f, 0.002171f, 0.002352f, 0.002796f, 0.003546f,
+ 0.004189f, 0.005558f, 0.006939f, 0.009209f, 0.012337f, 0.017776f, 0.026016f, 0.040833f, 0.069946f, 0.130981f, 0.262207f, 0.489258f,
+ 0.719238f, 0.859375f, 0.968262f, 0.969238f, 0.969727f, 0.969727f, 0.969727f, 0.969727f, 0.000000f, 0.000122f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000110f, 0.000093f, 0.000080f,
+ 0.000068f, 0.000094f, 0.000119f, 0.000117f, 0.000120f, 0.000123f, 0.000173f, 0.000263f, 0.000263f, 0.000359f, 0.000386f, 0.000390f,
+ 0.000401f, 0.000556f, 0.000549f, 0.000573f, 0.000502f, 0.000707f, 0.000789f, 0.000629f, 0.000847f, 0.001003f, 0.001024f, 0.001242f,
+ 0.001423f, 0.001877f, 0.002012f, 0.002571f, 0.003071f, 0.003925f, 0.005131f, 0.006767f, 0.009140f, 0.012672f, 0.018509f, 0.028992f,
+ 0.048309f, 0.089233f, 0.183838f, 0.383545f, 0.646973f, 0.830078f, 0.963867f, 0.964844f, 0.964844f, 0.965820f, 0.965820f, 0.965820f,
+ 0.000000f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000120f,
+ 0.000119f, 0.000119f, 0.000113f, 0.000095f, 0.000083f, 0.000070f, 0.000061f, 0.000054f, 0.000048f, 0.000042f, 0.000115f, 0.000112f,
+ 0.000151f, 0.000213f, 0.000309f, 0.000298f, 0.000359f, 0.000337f, 0.000382f, 0.000440f, 0.000576f, 0.000477f, 0.000453f, 0.000690f,
+ 0.000687f, 0.000795f, 0.000776f, 0.000911f, 0.001117f, 0.001119f, 0.001352f, 0.002001f, 0.002140f, 0.002832f, 0.003609f, 0.004715f,
+ 0.006302f, 0.008835f, 0.013115f, 0.020004f, 0.032867f, 0.060333f, 0.124512f, 0.281982f, 0.557617f, 0.794434f, 0.959473f, 0.959961f,
+ 0.960449f, 0.960449f, 0.960449f, 0.959961f, 0.000122f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000119f, 0.000119f,
+ 0.000119f, 0.000119f, 0.000119f, 0.000119f, 0.000118f, 0.000118f, 0.000118f, 0.000116f, 0.000098f, 0.000087f, 0.000076f, 0.000065f,
+ 0.000057f, 0.000050f, 0.000045f, 0.000091f, 0.000074f, 0.000106f, 0.000185f, 0.000193f, 0.000228f, 0.000328f, 0.000323f, 0.000399f,
+ 0.000429f, 0.000498f, 0.000552f, 0.000432f, 0.000542f, 0.000592f, 0.000599f, 0.000729f, 0.000734f, 0.000885f, 0.001304f, 0.001273f,
+ 0.001756f, 0.001931f, 0.002445f, 0.003120f, 0.004456f, 0.006165f, 0.008751f, 0.013466f, 0.022141f, 0.040192f, 0.082397f, 0.195679f,
+ 0.455322f, 0.745117f, 0.952637f, 0.953613f, 0.953613f, 0.954102f, 0.952637f, 0.953613f, 0.000000f, 0.000120f, 0.000120f, 0.000119f,
+ 0.000119f, 0.000119f, 0.000118f, 0.000118f, 0.000118f, 0.000118f, 0.000118f, 0.000117f, 0.000117f, 0.000117f, 0.000117f, 0.000117f,
+ 0.000117f, 0.000104f, 0.000092f, 0.000079f, 0.000071f, 0.000062f, 0.000055f, 0.000049f, 0.000044f, 0.000039f, 0.000099f, 0.000106f,
+ 0.000158f, 0.000169f, 0.000241f, 0.000274f, 0.000293f, 0.000389f, 0.000360f, 0.000399f, 0.000387f, 0.000446f, 0.000401f, 0.000530f,
+ 0.000565f, 0.000691f, 0.000722f, 0.000848f, 0.001147f, 0.001418f, 0.001677f, 0.002087f, 0.002972f, 0.004169f, 0.005623f, 0.008835f,
+ 0.014404f, 0.026077f, 0.053467f, 0.129395f, 0.346924f, 0.685059f, 0.943848f, 0.945801f, 0.945801f, 0.945312f, 0.945801f, 0.945801f,
+ 0.000000f, 0.000000f, 0.000117f, 0.000116f, 0.000117f, 0.000117f, 0.000116f, 0.000116f, 0.000115f, 0.000116f, 0.000115f, 0.000116f,
+ 0.000115f, 0.000115f, 0.000115f, 0.000115f, 0.000115f, 0.000115f, 0.000110f, 0.000097f, 0.000086f, 0.000077f, 0.000067f, 0.000060f,
+ 0.000053f, 0.000048f, 0.000043f, 0.000061f, 0.000090f, 0.000083f, 0.000139f, 0.000139f, 0.000216f, 0.000254f, 0.000307f, 0.000358f,
+ 0.000269f, 0.000377f, 0.000324f, 0.000369f, 0.000405f, 0.000455f, 0.000524f, 0.000706f, 0.000701f, 0.001012f, 0.001206f, 0.001316f,
+ 0.001663f, 0.002350f, 0.003571f, 0.005505f, 0.008873f, 0.016006f, 0.033234f, 0.081848f, 0.244751f, 0.605469f, 0.934082f, 0.935059f,
+ 0.936035f, 0.935547f, 0.935547f, 0.935547f, 0.000105f, 0.000114f, 0.000113f, 0.000113f, 0.000111f, 0.000111f, 0.000112f, 0.000111f,
+ 0.000112f, 0.000112f, 0.000112f, 0.000112f, 0.000111f, 0.000112f, 0.000112f, 0.000112f, 0.000112f, 0.000112f, 0.000112f, 0.000112f,
+ 0.000105f, 0.000093f, 0.000083f, 0.000074f, 0.000066f, 0.000059f, 0.000053f, 0.000048f, 0.000043f, 0.000062f, 0.000052f, 0.000063f,
+ 0.000092f, 0.000146f, 0.000176f, 0.000216f, 0.000227f, 0.000263f, 0.000244f, 0.000267f, 0.000370f, 0.000326f, 0.000360f, 0.000391f,
+ 0.000505f, 0.000618f, 0.000726f, 0.000969f, 0.001117f, 0.001651f, 0.002131f, 0.003090f, 0.005188f, 0.009499f, 0.019836f, 0.049042f,
+ 0.159180f, 0.509766f, 0.921875f, 0.922852f, 0.922852f, 0.922363f, 0.923340f, 0.922852f, 0.000000f, 0.000000f, 0.000065f, 0.000098f,
+ 0.000096f, 0.000101f, 0.000100f, 0.000104f, 0.000104f, 0.000103f, 0.000106f, 0.000106f, 0.000106f, 0.000105f, 0.000107f, 0.000107f,
+ 0.000106f, 0.000107f, 0.000107f, 0.000108f, 0.000107f, 0.000108f, 0.000104f, 0.000092f, 0.000082f, 0.000075f, 0.000067f, 0.000059f,
+ 0.000054f, 0.000048f, 0.000044f, 0.000039f, 0.000037f, 0.000058f, 0.000066f, 0.000122f, 0.000137f, 0.000175f, 0.000208f, 0.000194f,
+ 0.000208f, 0.000240f, 0.000270f, 0.000281f, 0.000323f, 0.000364f, 0.000479f, 0.000591f, 0.000712f, 0.000986f, 0.001224f, 0.001896f,
+ 0.002996f, 0.005196f, 0.010506f, 0.027527f, 0.095581f, 0.399658f, 0.905762f, 0.906738f, 0.906250f, 0.905762f, 0.905762f, 0.907227f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000017f, 0.000030f, 0.000054f, 0.000061f, 0.000081f, 0.000087f, 0.000088f, 0.000089f, 0.000093f,
+ 0.000093f, 0.000096f, 0.000096f, 0.000097f, 0.000098f, 0.000099f, 0.000098f, 0.000100f, 0.000100f, 0.000101f, 0.000100f, 0.000101f,
+ 0.000101f, 0.000092f, 0.000082f, 0.000074f, 0.000067f, 0.000060f, 0.000054f, 0.000049f, 0.000045f, 0.000040f, 0.000036f, 0.000037f,
+ 0.000059f, 0.000077f, 0.000093f, 0.000143f, 0.000155f, 0.000188f, 0.000178f, 0.000184f, 0.000231f, 0.000234f, 0.000272f, 0.000352f,
+ 0.000420f, 0.000525f, 0.000764f, 0.001091f, 0.001653f, 0.002705f, 0.005474f, 0.013939f, 0.051880f, 0.283691f, 0.883789f, 0.884766f,
+ 0.885254f, 0.885254f, 0.885742f, 0.885254f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000013f,
+ 0.000032f, 0.000046f, 0.000050f, 0.000060f, 0.000065f, 0.000065f, 0.000075f, 0.000078f, 0.000080f, 0.000079f, 0.000084f, 0.000083f,
+ 0.000087f, 0.000087f, 0.000089f, 0.000090f, 0.000091f, 0.000091f, 0.000092f, 0.000092f, 0.000083f, 0.000075f, 0.000068f, 0.000062f,
+ 0.000056f, 0.000050f, 0.000046f, 0.000042f, 0.000037f, 0.000039f, 0.000044f, 0.000072f, 0.000068f, 0.000089f, 0.000125f, 0.000124f,
+ 0.000126f, 0.000153f, 0.000183f, 0.000212f, 0.000219f, 0.000311f, 0.000363f, 0.000566f, 0.000846f, 0.001332f, 0.002522f, 0.006252f,
+ 0.023834f, 0.175415f, 0.855957f, 0.856934f, 0.856934f, 0.856934f, 0.857422f, 0.856934f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000007f, 0.000024f, 0.000028f,
+ 0.000040f, 0.000044f, 0.000051f, 0.000053f, 0.000060f, 0.000063f, 0.000064f, 0.000067f, 0.000071f, 0.000072f, 0.000074f, 0.000076f,
+ 0.000077f, 0.000079f, 0.000079f, 0.000075f, 0.000068f, 0.000062f, 0.000056f, 0.000051f, 0.000046f, 0.000042f, 0.000038f, 0.000034f,
+ 0.000031f, 0.000030f, 0.000045f, 0.000079f, 0.000081f, 0.000107f, 0.000114f, 0.000106f, 0.000144f, 0.000136f, 0.000171f, 0.000254f,
+ 0.000377f, 0.000531f, 0.001037f, 0.002504f, 0.009140f, 0.088379f, 0.818848f, 0.820801f, 0.819824f, 0.820312f, 0.819336f, 0.820801f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000007f, 0.000014f, 0.000021f, 0.000028f,
+ 0.000034f, 0.000036f, 0.000042f, 0.000046f, 0.000049f, 0.000052f, 0.000054f, 0.000056f, 0.000059f, 0.000061f, 0.000064f, 0.000061f,
+ 0.000055f, 0.000050f, 0.000045f, 0.000041f, 0.000037f, 0.000033f, 0.000030f, 0.000027f, 0.000024f, 0.000033f, 0.000060f, 0.000059f,
+ 0.000075f, 0.000073f, 0.000101f, 0.000089f, 0.000144f, 0.000226f, 0.000384f, 0.000847f, 0.003033f, 0.031860f, 0.770020f, 0.770996f,
+ 0.772461f, 0.771973f, 0.772461f, 0.771973f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000006f, 0.000010f, 0.000016f,
+ 0.000021f, 0.000023f, 0.000029f, 0.000032f, 0.000036f, 0.000039f, 0.000042f, 0.000044f, 0.000042f, 0.000038f, 0.000035f, 0.000031f,
+ 0.000028f, 0.000025f, 0.000022f, 0.000020f, 0.000017f, 0.000024f, 0.000040f, 0.000047f, 0.000053f, 0.000063f, 0.000087f, 0.000190f,
+ 0.000666f, 0.007278f, 0.708496f, 0.709961f, 0.710449f, 0.710938f, 0.710938f, 0.710449f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f,
+ 0.000005f, 0.000010f, 0.000014f, 0.000018f, 0.000021f, 0.000024f, 0.000024f, 0.000021f, 0.000018f, 0.000016f, 0.000014f, 0.000012f,
+ 0.000008f, 0.000020f, 0.000022f, 0.000025f, 0.000073f, 0.000744f, 0.632324f, 0.632812f, 0.633789f, 0.633789f, 0.633301f, 0.632812f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000003f, 0.000007f, 0.000006f, 0.000004f, 0.000005f, 0.000007f, 0.543945f, 0.545410f,
+ 0.545410f, 0.545410f, 0.546387f, 0.545898f,
+ },
+ {
+ 0.159546f, 0.492676f, 0.684570f, 0.783203f, 0.838379f, 0.873535f, 0.897949f, 0.913574f, 0.926270f, 0.936035f, 0.943359f, 0.950195f,
+ 0.955566f, 0.959473f, 0.963379f, 0.966797f, 0.969238f, 0.972168f, 0.973633f, 0.976562f, 0.978027f, 0.979492f, 0.980957f, 0.982422f,
+ 0.983887f, 0.984863f, 0.985840f, 0.986816f, 0.987793f, 0.988770f, 0.989258f, 0.989746f, 0.990234f, 0.990723f, 0.991699f, 0.992676f,
+ 0.993164f, 0.993652f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995117f, 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.997070f,
+ 0.997070f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.034119f, 0.154175f, 0.341309f, 0.532227f, 0.672363f, 0.763184f, 0.820801f, 0.858398f,
+ 0.885742f, 0.904297f, 0.918945f, 0.929199f, 0.938965f, 0.945801f, 0.951660f, 0.956543f, 0.961426f, 0.964355f, 0.968262f, 0.970703f,
+ 0.973145f, 0.975586f, 0.977539f, 0.979004f, 0.980469f, 0.981934f, 0.983398f, 0.984375f, 0.985352f, 0.986328f, 0.987305f, 0.988281f,
+ 0.988770f, 0.989746f, 0.990234f, 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.999023f,
+ 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.013390f, 0.056915f, 0.134155f, 0.257080f,
+ 0.412109f, 0.560547f, 0.675781f, 0.755859f, 0.812012f, 0.851074f, 0.877930f, 0.898926f, 0.913574f, 0.925781f, 0.935059f, 0.942871f,
+ 0.949707f, 0.954590f, 0.959473f, 0.963379f, 0.966797f, 0.969238f, 0.971680f, 0.975098f, 0.976562f, 0.978516f, 0.979980f, 0.980957f,
+ 0.982422f, 0.984375f, 0.985352f, 0.985840f, 0.987305f, 0.987793f, 0.988770f, 0.989746f, 0.990723f, 0.991211f, 0.991699f, 0.992188f,
+ 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995605f, 0.995605f, 0.995605f, 0.996582f, 0.996582f, 0.997070f, 0.997070f,
+ 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f,
+ 0.006939f, 0.027863f, 0.061951f, 0.117859f, 0.204834f, 0.324707f, 0.460205f, 0.585449f, 0.684570f, 0.757324f, 0.810059f, 0.847168f,
+ 0.874023f, 0.895996f, 0.910645f, 0.922852f, 0.933105f, 0.940918f, 0.947754f, 0.953613f, 0.958496f, 0.961914f, 0.965820f, 0.968750f,
+ 0.971680f, 0.974121f, 0.976074f, 0.978027f, 0.979492f, 0.981445f, 0.982910f, 0.983887f, 0.984863f, 0.986328f, 0.987305f, 0.988281f,
+ 0.988770f, 0.989746f, 0.990234f, 0.990723f, 0.991699f, 0.992188f, 0.993164f, 0.993652f, 0.993652f, 0.994141f, 0.995117f, 0.995605f,
+ 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.998535f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.004211f, 0.016022f, 0.034119f, 0.061432f, 0.104797f, 0.170288f, 0.262695f, 0.377686f,
+ 0.499756f, 0.608887f, 0.696777f, 0.762207f, 0.810547f, 0.847168f, 0.873535f, 0.893066f, 0.910156f, 0.922852f, 0.932617f, 0.939941f,
+ 0.946777f, 0.953125f, 0.958496f, 0.961914f, 0.965332f, 0.968750f, 0.971680f, 0.973633f, 0.975586f, 0.977539f, 0.979492f, 0.981445f,
+ 0.982910f, 0.984375f, 0.985840f, 0.986328f, 0.987793f, 0.987793f, 0.989258f, 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.992676f,
+ 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f,
+ 0.998047f, 0.998535f, 0.999512f, 0.999512f, 0.999023f, 0.999512f, 0.999023f, 0.999023f, 0.002724f, 0.010384f, 0.020813f, 0.036285f,
+ 0.059784f, 0.093933f, 0.145508f, 0.218018f, 0.313232f, 0.424072f, 0.534180f, 0.632812f, 0.709961f, 0.769531f, 0.815918f, 0.848145f,
+ 0.874512f, 0.894043f, 0.909668f, 0.922363f, 0.932129f, 0.939941f, 0.946777f, 0.953125f, 0.958008f, 0.961914f, 0.965332f, 0.968750f,
+ 0.971680f, 0.973633f, 0.976562f, 0.978516f, 0.979980f, 0.981445f, 0.982910f, 0.984863f, 0.985352f, 0.986816f, 0.987793f, 0.988281f,
+ 0.988770f, 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996582f, 0.996582f, 0.997559f, 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f,
+ 0.002113f, 0.007004f, 0.014091f, 0.023895f, 0.037811f, 0.057373f, 0.085632f, 0.127075f, 0.185425f, 0.263672f, 0.360596f, 0.465576f,
+ 0.566895f, 0.655762f, 0.725586f, 0.779297f, 0.822266f, 0.853516f, 0.877441f, 0.895996f, 0.911621f, 0.923828f, 0.933105f, 0.940918f,
+ 0.947754f, 0.953613f, 0.957520f, 0.962402f, 0.965820f, 0.968750f, 0.972168f, 0.974121f, 0.976074f, 0.978027f, 0.980469f, 0.981934f,
+ 0.983398f, 0.984863f, 0.985352f, 0.986328f, 0.988281f, 0.988281f, 0.989258f, 0.990234f, 0.991211f, 0.992188f, 0.992676f, 0.993164f,
+ 0.993652f, 0.994629f, 0.994629f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.001575f, 0.005211f, 0.010040f, 0.016220f, 0.025665f, 0.037415f, 0.054138f, 0.078491f,
+ 0.112915f, 0.160156f, 0.225464f, 0.308594f, 0.405029f, 0.506348f, 0.599121f, 0.678711f, 0.743164f, 0.791016f, 0.829590f, 0.859375f,
+ 0.881836f, 0.899414f, 0.913086f, 0.924805f, 0.934570f, 0.942383f, 0.948730f, 0.955078f, 0.958984f, 0.963379f, 0.966797f, 0.970215f,
+ 0.972168f, 0.974609f, 0.977051f, 0.979004f, 0.980957f, 0.981934f, 0.983398f, 0.984863f, 0.986328f, 0.987305f, 0.988281f, 0.989258f,
+ 0.990234f, 0.991211f, 0.991699f, 0.992188f, 0.993164f, 0.993652f, 0.994629f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996094f,
+ 0.996582f, 0.997559f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.000985f, 0.004086f, 0.007362f, 0.011887f,
+ 0.018127f, 0.026199f, 0.036804f, 0.052002f, 0.072754f, 0.101318f, 0.140747f, 0.195190f, 0.266113f, 0.352539f, 0.448730f, 0.543945f,
+ 0.630371f, 0.702637f, 0.759277f, 0.803711f, 0.839355f, 0.865234f, 0.886719f, 0.903320f, 0.916504f, 0.927734f, 0.936523f, 0.944336f,
+ 0.950195f, 0.955566f, 0.959961f, 0.964355f, 0.967773f, 0.970215f, 0.973145f, 0.975586f, 0.978027f, 0.979004f, 0.980957f, 0.982910f,
+ 0.984375f, 0.985352f, 0.987305f, 0.987305f, 0.988770f, 0.990234f, 0.990234f, 0.991699f, 0.991699f, 0.993164f, 0.993164f, 0.993652f,
+ 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.998535f, 0.999023f,
+ 0.000829f, 0.002878f, 0.005596f, 0.009109f, 0.013359f, 0.019089f, 0.026901f, 0.036774f, 0.049347f, 0.067200f, 0.091736f, 0.125854f,
+ 0.171631f, 0.232544f, 0.308594f, 0.397461f, 0.491455f, 0.581055f, 0.659668f, 0.724609f, 0.775879f, 0.817383f, 0.848633f, 0.873047f,
+ 0.892090f, 0.907715f, 0.920410f, 0.930664f, 0.939453f, 0.946289f, 0.951660f, 0.957520f, 0.960938f, 0.965820f, 0.968750f, 0.972168f,
+ 0.974609f, 0.976562f, 0.978516f, 0.980469f, 0.981934f, 0.983887f, 0.984863f, 0.986328f, 0.986816f, 0.988770f, 0.989746f, 0.990234f,
+ 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996582f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000836f, 0.002403f, 0.004837f, 0.006950f, 0.010269f, 0.014679f, 0.019699f, 0.026291f,
+ 0.035431f, 0.046875f, 0.062744f, 0.084045f, 0.113403f, 0.152588f, 0.204712f, 0.271729f, 0.353271f, 0.443115f, 0.532715f, 0.617188f,
+ 0.688477f, 0.748047f, 0.793945f, 0.829102f, 0.857422f, 0.880371f, 0.898438f, 0.912598f, 0.924316f, 0.934082f, 0.941406f, 0.948242f,
+ 0.954590f, 0.959473f, 0.963379f, 0.967285f, 0.970215f, 0.973145f, 0.975586f, 0.977539f, 0.979980f, 0.981445f, 0.982910f, 0.984375f,
+ 0.985840f, 0.987305f, 0.988281f, 0.988770f, 0.990234f, 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.995117f,
+ 0.995605f, 0.996094f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.000698f, 0.002052f, 0.003618f, 0.005703f,
+ 0.008430f, 0.011230f, 0.015083f, 0.019821f, 0.026474f, 0.034393f, 0.044922f, 0.059204f, 0.077698f, 0.102661f, 0.136963f, 0.182373f,
+ 0.241089f, 0.314941f, 0.398926f, 0.489014f, 0.575195f, 0.652344f, 0.717285f, 0.769043f, 0.810059f, 0.842773f, 0.869141f, 0.888672f,
+ 0.904785f, 0.917969f, 0.928711f, 0.936523f, 0.945312f, 0.951660f, 0.957031f, 0.961426f, 0.964844f, 0.968750f, 0.971680f, 0.974121f,
+ 0.976562f, 0.979004f, 0.980469f, 0.982422f, 0.983887f, 0.985352f, 0.986816f, 0.987793f, 0.988770f, 0.990234f, 0.990723f, 0.991699f,
+ 0.992676f, 0.993164f, 0.994141f, 0.994141f, 0.994629f, 0.995605f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f,
+ 0.000244f, 0.001565f, 0.002975f, 0.004433f, 0.006596f, 0.008957f, 0.012215f, 0.015533f, 0.020294f, 0.026062f, 0.033722f, 0.042816f,
+ 0.055237f, 0.071960f, 0.094543f, 0.124023f, 0.164185f, 0.216309f, 0.281738f, 0.360352f, 0.446533f, 0.534180f, 0.615234f, 0.686523f,
+ 0.743652f, 0.790527f, 0.825684f, 0.855957f, 0.878418f, 0.895996f, 0.911133f, 0.923340f, 0.933105f, 0.941406f, 0.948242f, 0.953613f,
+ 0.959473f, 0.963379f, 0.966797f, 0.970703f, 0.973145f, 0.976074f, 0.978516f, 0.980469f, 0.982422f, 0.983398f, 0.984863f, 0.986328f,
+ 0.987305f, 0.989258f, 0.989746f, 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994141f, 0.995117f, 0.998047f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998047f, 0.000365f, 0.001394f, 0.002546f, 0.004055f, 0.005394f, 0.007465f, 0.009674f, 0.012070f,
+ 0.015556f, 0.019913f, 0.025696f, 0.032623f, 0.041046f, 0.052643f, 0.067383f, 0.087463f, 0.113708f, 0.148315f, 0.194946f, 0.254395f,
+ 0.326416f, 0.408691f, 0.495117f, 0.579102f, 0.654297f, 0.716797f, 0.768066f, 0.809570f, 0.843262f, 0.868652f, 0.888184f, 0.904785f,
+ 0.918457f, 0.929199f, 0.937500f, 0.945801f, 0.951660f, 0.957520f, 0.961914f, 0.965820f, 0.969238f, 0.972656f, 0.975098f, 0.978027f,
+ 0.979492f, 0.981934f, 0.983398f, 0.984863f, 0.986328f, 0.987793f, 0.989258f, 0.989746f, 0.991211f, 0.991211f, 0.992188f, 0.993164f,
+ 0.993652f, 0.994629f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.000596f, 0.001077f, 0.001882f, 0.003033f,
+ 0.004559f, 0.006241f, 0.007805f, 0.010002f, 0.012840f, 0.015900f, 0.019974f, 0.025131f, 0.031250f, 0.039337f, 0.049988f, 0.063843f,
+ 0.080933f, 0.105164f, 0.135986f, 0.176880f, 0.230103f, 0.296631f, 0.374268f, 0.459961f, 0.544434f, 0.623535f, 0.691895f, 0.748535f,
+ 0.792969f, 0.829102f, 0.857422f, 0.880371f, 0.897949f, 0.913086f, 0.924805f, 0.934570f, 0.942383f, 0.949219f, 0.955566f, 0.960938f,
+ 0.964844f, 0.968750f, 0.971191f, 0.974121f, 0.977051f, 0.979004f, 0.980957f, 0.982910f, 0.984863f, 0.985840f, 0.987305f, 0.989258f,
+ 0.989746f, 0.991211f, 0.991211f, 0.992676f, 0.993164f, 0.993652f, 0.997559f, 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.998047f,
+ 0.000243f, 0.001173f, 0.001889f, 0.002661f, 0.003933f, 0.005131f, 0.006496f, 0.008324f, 0.010574f, 0.013115f, 0.015839f, 0.019913f,
+ 0.024445f, 0.030609f, 0.037781f, 0.047333f, 0.059906f, 0.075928f, 0.097229f, 0.124939f, 0.161743f, 0.209595f, 0.271240f, 0.343994f,
+ 0.426758f, 0.511719f, 0.592773f, 0.666504f, 0.727051f, 0.776855f, 0.815918f, 0.847656f, 0.871582f, 0.892090f, 0.907715f, 0.920898f,
+ 0.931152f, 0.940918f, 0.947754f, 0.953613f, 0.958496f, 0.963867f, 0.967773f, 0.970703f, 0.974121f, 0.976074f, 0.979004f, 0.980469f,
+ 0.982910f, 0.984375f, 0.985840f, 0.987305f, 0.988770f, 0.990234f, 0.990234f, 0.992188f, 0.992188f, 0.993164f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.000351f, 0.000842f, 0.001560f, 0.002363f, 0.003258f, 0.004131f, 0.005272f, 0.007179f,
+ 0.008682f, 0.010643f, 0.013016f, 0.016037f, 0.019516f, 0.024078f, 0.029602f, 0.036591f, 0.045044f, 0.056641f, 0.071350f, 0.090576f,
+ 0.116211f, 0.149414f, 0.193237f, 0.248779f, 0.317871f, 0.396973f, 0.481201f, 0.564453f, 0.640137f, 0.705566f, 0.759766f, 0.802734f,
+ 0.836914f, 0.863281f, 0.885742f, 0.902832f, 0.916992f, 0.927734f, 0.937012f, 0.945801f, 0.952637f, 0.958008f, 0.961914f, 0.966309f,
+ 0.970703f, 0.974121f, 0.976074f, 0.978516f, 0.980957f, 0.982910f, 0.984863f, 0.985840f, 0.987305f, 0.988281f, 0.989746f, 0.990723f,
+ 0.991211f, 0.992676f, 0.997070f, 0.997559f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.000000f, 0.000886f, 0.001405f, 0.001915f,
+ 0.002651f, 0.003870f, 0.004845f, 0.006035f, 0.006912f, 0.008812f, 0.010887f, 0.013229f, 0.016022f, 0.019196f, 0.023590f, 0.028992f,
+ 0.035248f, 0.043304f, 0.053711f, 0.066956f, 0.085083f, 0.107727f, 0.138428f, 0.178589f, 0.229980f, 0.293945f, 0.370117f, 0.453369f,
+ 0.537109f, 0.616699f, 0.685059f, 0.743164f, 0.790039f, 0.826660f, 0.856445f, 0.878906f, 0.897949f, 0.913574f, 0.925293f, 0.935547f,
+ 0.943848f, 0.951172f, 0.957031f, 0.961914f, 0.966797f, 0.970215f, 0.973145f, 0.976562f, 0.979004f, 0.980469f, 0.982910f, 0.984375f,
+ 0.985840f, 0.987305f, 0.988770f, 0.989746f, 0.991211f, 0.992188f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997070f,
+ 0.000104f, 0.000719f, 0.001065f, 0.001970f, 0.002544f, 0.003149f, 0.004230f, 0.005138f, 0.006119f, 0.007580f, 0.009201f, 0.010902f,
+ 0.013260f, 0.015526f, 0.019272f, 0.022858f, 0.027512f, 0.033569f, 0.041199f, 0.050873f, 0.063782f, 0.079895f, 0.101135f, 0.128906f,
+ 0.165771f, 0.213745f, 0.273193f, 0.345703f, 0.427002f, 0.511719f, 0.592773f, 0.666016f, 0.727051f, 0.776367f, 0.817871f, 0.848633f,
+ 0.875000f, 0.894531f, 0.909668f, 0.922852f, 0.934082f, 0.942383f, 0.949707f, 0.956055f, 0.961914f, 0.966309f, 0.970215f, 0.973145f,
+ 0.976562f, 0.978516f, 0.980957f, 0.982910f, 0.984375f, 0.986328f, 0.987305f, 0.988281f, 0.989746f, 0.991211f, 0.996582f, 0.997070f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.000240f, 0.000686f, 0.001052f, 0.001375f, 0.002308f, 0.002735f, 0.003510f, 0.004269f,
+ 0.005173f, 0.006649f, 0.007442f, 0.009109f, 0.011246f, 0.012886f, 0.015732f, 0.018829f, 0.022354f, 0.026672f, 0.032867f, 0.039764f,
+ 0.048492f, 0.060455f, 0.075806f, 0.095276f, 0.121033f, 0.155273f, 0.199097f, 0.255859f, 0.324463f, 0.404053f, 0.488525f, 0.571289f,
+ 0.646484f, 0.711426f, 0.765625f, 0.808105f, 0.841797f, 0.869141f, 0.890137f, 0.907227f, 0.920898f, 0.931641f, 0.940918f, 0.948730f,
+ 0.955078f, 0.960449f, 0.965820f, 0.969727f, 0.972656f, 0.976562f, 0.978516f, 0.980957f, 0.982910f, 0.984863f, 0.986328f, 0.987793f,
+ 0.989746f, 0.990723f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.000244f, 0.000597f, 0.000939f, 0.001369f,
+ 0.001999f, 0.002329f, 0.003105f, 0.003786f, 0.004395f, 0.005413f, 0.006474f, 0.007793f, 0.009254f, 0.010971f, 0.012970f, 0.015526f,
+ 0.018112f, 0.022049f, 0.026581f, 0.031586f, 0.038666f, 0.046967f, 0.057617f, 0.071777f, 0.089783f, 0.113953f, 0.145264f, 0.186646f,
+ 0.239990f, 0.305908f, 0.383301f, 0.467285f, 0.551270f, 0.629883f, 0.697266f, 0.754883f, 0.799805f, 0.835938f, 0.864258f, 0.886719f,
+ 0.905273f, 0.918945f, 0.931152f, 0.940918f, 0.948242f, 0.955078f, 0.961426f, 0.965332f, 0.969727f, 0.973633f, 0.976074f, 0.979004f,
+ 0.980957f, 0.983398f, 0.984863f, 0.987305f, 0.988281f, 0.989258f, 0.996094f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.996582f,
+ 0.000000f, 0.000475f, 0.000891f, 0.001390f, 0.001730f, 0.002060f, 0.002501f, 0.003109f, 0.003836f, 0.004837f, 0.005852f, 0.006859f,
+ 0.007740f, 0.009216f, 0.010918f, 0.012863f, 0.014915f, 0.017731f, 0.021317f, 0.025482f, 0.030930f, 0.037262f, 0.044891f, 0.055115f,
+ 0.068298f, 0.085510f, 0.107910f, 0.137207f, 0.176025f, 0.226929f, 0.289551f, 0.364746f, 0.447998f, 0.532715f, 0.613770f, 0.685547f,
+ 0.744629f, 0.791992f, 0.830078f, 0.860352f, 0.884277f, 0.903320f, 0.917969f, 0.930176f, 0.939941f, 0.947754f, 0.954590f, 0.961426f,
+ 0.966309f, 0.970215f, 0.973145f, 0.976562f, 0.979492f, 0.981445f, 0.983398f, 0.985352f, 0.987793f, 0.988281f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996582f, 0.996094f, 0.996094f, 0.000102f, 0.000243f, 0.000844f, 0.001124f, 0.001554f, 0.002077f, 0.002098f, 0.002682f,
+ 0.003357f, 0.004280f, 0.005035f, 0.005764f, 0.006805f, 0.007633f, 0.009354f, 0.010872f, 0.012665f, 0.015099f, 0.017258f, 0.020599f,
+ 0.024887f, 0.029495f, 0.035522f, 0.042999f, 0.053070f, 0.065125f, 0.081299f, 0.102661f, 0.130371f, 0.166992f, 0.215088f, 0.275635f,
+ 0.348877f, 0.431641f, 0.517578f, 0.600098f, 0.672852f, 0.735352f, 0.785645f, 0.826172f, 0.856934f, 0.881836f, 0.900879f, 0.916992f,
+ 0.930176f, 0.940430f, 0.947754f, 0.955078f, 0.960938f, 0.966309f, 0.969238f, 0.973633f, 0.977051f, 0.979492f, 0.981934f, 0.983887f,
+ 0.986328f, 0.987793f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.000241f, 0.000242f, 0.000823f, 0.000956f,
+ 0.001225f, 0.001549f, 0.002031f, 0.002613f, 0.003124f, 0.003574f, 0.004467f, 0.004955f, 0.005672f, 0.006752f, 0.007603f, 0.009186f,
+ 0.010704f, 0.012741f, 0.014366f, 0.017487f, 0.020142f, 0.024002f, 0.028915f, 0.034943f, 0.041656f, 0.050964f, 0.062622f, 0.077881f,
+ 0.097961f, 0.124207f, 0.158936f, 0.204590f, 0.263184f, 0.334961f, 0.416748f, 0.502930f, 0.587891f, 0.664062f, 0.728516f, 0.780762f,
+ 0.822266f, 0.854492f, 0.879395f, 0.900879f, 0.916504f, 0.928711f, 0.940430f, 0.948730f, 0.955566f, 0.961914f, 0.967285f, 0.970215f,
+ 0.974121f, 0.977539f, 0.979980f, 0.982422f, 0.984863f, 0.986816f, 0.994629f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.995605f,
+ 0.000000f, 0.000473f, 0.000607f, 0.000921f, 0.000957f, 0.001448f, 0.001884f, 0.002270f, 0.002703f, 0.002998f, 0.003862f, 0.004307f,
+ 0.005074f, 0.005665f, 0.006737f, 0.007851f, 0.009216f, 0.010735f, 0.012459f, 0.014572f, 0.016998f, 0.019821f, 0.023605f, 0.027969f,
+ 0.033783f, 0.040192f, 0.049286f, 0.060303f, 0.074829f, 0.093750f, 0.118774f, 0.152222f, 0.195801f, 0.252441f, 0.322754f, 0.404053f,
+ 0.491943f, 0.577637f, 0.655273f, 0.722168f, 0.776367f, 0.820312f, 0.854004f, 0.878906f, 0.900879f, 0.916992f, 0.929688f, 0.940430f,
+ 0.949707f, 0.956055f, 0.962402f, 0.967285f, 0.971191f, 0.975586f, 0.978516f, 0.980957f, 0.983398f, 0.985352f, 0.994141f, 0.995117f,
+ 0.995117f, 0.995605f, 0.995117f, 0.995605f, 0.000000f, 0.000444f, 0.000605f, 0.000649f, 0.000926f, 0.001096f, 0.001624f, 0.001669f,
+ 0.002373f, 0.002716f, 0.003231f, 0.003769f, 0.004395f, 0.005005f, 0.005878f, 0.006710f, 0.007793f, 0.008957f, 0.010712f, 0.012230f,
+ 0.014244f, 0.016693f, 0.019531f, 0.022827f, 0.027100f, 0.032318f, 0.038971f, 0.047302f, 0.058105f, 0.072021f, 0.089966f, 0.114319f,
+ 0.146362f, 0.188965f, 0.244019f, 0.312988f, 0.394287f, 0.482178f, 0.569824f, 0.650391f, 0.718262f, 0.774414f, 0.819336f, 0.853027f,
+ 0.880371f, 0.900879f, 0.917969f, 0.930664f, 0.940918f, 0.950684f, 0.957031f, 0.962891f, 0.968262f, 0.972656f, 0.976562f, 0.979004f,
+ 0.981934f, 0.984375f, 0.994141f, 0.994629f, 0.994629f, 0.995117f, 0.994629f, 0.995117f, 0.000000f, 0.000336f, 0.000601f, 0.000712f,
+ 0.000810f, 0.001174f, 0.001286f, 0.001618f, 0.002037f, 0.002592f, 0.002920f, 0.003223f, 0.003847f, 0.004463f, 0.005119f, 0.006020f,
+ 0.006783f, 0.007957f, 0.008888f, 0.010590f, 0.012230f, 0.013885f, 0.016220f, 0.019318f, 0.022278f, 0.026474f, 0.031403f, 0.037781f,
+ 0.046021f, 0.055969f, 0.069397f, 0.086975f, 0.110413f, 0.140991f, 0.182739f, 0.236694f, 0.304932f, 0.385986f, 0.475586f, 0.563965f,
+ 0.646484f, 0.716797f, 0.772461f, 0.818359f, 0.853027f, 0.880859f, 0.901855f, 0.918945f, 0.932129f, 0.942383f, 0.951172f, 0.958496f,
+ 0.964355f, 0.969238f, 0.973633f, 0.977051f, 0.979980f, 0.982910f, 0.993652f, 0.994141f, 0.994629f, 0.994141f, 0.994141f, 0.994629f,
+ 0.000000f, 0.000244f, 0.000418f, 0.000597f, 0.000600f, 0.001085f, 0.001236f, 0.001535f, 0.001970f, 0.002096f, 0.002354f, 0.002834f,
+ 0.003323f, 0.003822f, 0.004463f, 0.005146f, 0.005798f, 0.006859f, 0.007587f, 0.008827f, 0.009956f, 0.011833f, 0.013725f, 0.015945f,
+ 0.018585f, 0.021988f, 0.025665f, 0.030807f, 0.036774f, 0.044373f, 0.054108f, 0.067383f, 0.084229f, 0.106812f, 0.137207f, 0.177734f,
+ 0.230835f, 0.299072f, 0.380127f, 0.470215f, 0.560547f, 0.644531f, 0.715820f, 0.774414f, 0.820312f, 0.854980f, 0.882324f, 0.903809f,
+ 0.921387f, 0.933594f, 0.944824f, 0.952637f, 0.960449f, 0.965820f, 0.971191f, 0.974609f, 0.978027f, 0.981934f, 0.993164f, 0.994629f,
+ 0.994141f, 0.994141f, 0.994141f, 0.994141f, 0.000000f, 0.000244f, 0.000411f, 0.000589f, 0.000820f, 0.000729f, 0.001086f, 0.001301f,
+ 0.001677f, 0.001935f, 0.002312f, 0.002678f, 0.002846f, 0.003590f, 0.003914f, 0.004578f, 0.005020f, 0.005753f, 0.006706f, 0.007710f,
+ 0.008911f, 0.010155f, 0.011528f, 0.013504f, 0.015747f, 0.018036f, 0.021408f, 0.024994f, 0.029816f, 0.035858f, 0.043152f, 0.053009f,
+ 0.065491f, 0.082031f, 0.104065f, 0.133789f, 0.174072f, 0.226929f, 0.294434f, 0.376465f, 0.467773f, 0.560059f, 0.644531f, 0.717285f,
+ 0.777344f, 0.823242f, 0.857910f, 0.885742f, 0.906738f, 0.922852f, 0.936523f, 0.947266f, 0.955078f, 0.961426f, 0.967285f, 0.972656f,
+ 0.976562f, 0.979980f, 0.992676f, 0.993164f, 0.993652f, 0.993652f, 0.993652f, 0.993652f, 0.000000f, 0.000243f, 0.000243f, 0.000442f,
+ 0.000695f, 0.000759f, 0.000837f, 0.001089f, 0.001625f, 0.001702f, 0.002045f, 0.002176f, 0.002756f, 0.003063f, 0.003687f, 0.003893f,
+ 0.004456f, 0.005337f, 0.006062f, 0.006523f, 0.007572f, 0.008430f, 0.009880f, 0.011612f, 0.013237f, 0.015114f, 0.017487f, 0.020584f,
+ 0.024445f, 0.028931f, 0.034729f, 0.042023f, 0.051788f, 0.063843f, 0.079956f, 0.102295f, 0.131592f, 0.171021f, 0.223877f, 0.292236f,
+ 0.375000f, 0.468018f, 0.562012f, 0.648438f, 0.721191f, 0.781250f, 0.826660f, 0.862305f, 0.888672f, 0.909668f, 0.926270f, 0.938965f,
+ 0.949707f, 0.957520f, 0.964355f, 0.969727f, 0.974121f, 0.978027f, 0.992676f, 0.993164f, 0.993164f, 0.992676f, 0.993164f, 0.993164f,
+ 0.000000f, 0.000242f, 0.000242f, 0.000242f, 0.000564f, 0.000692f, 0.000826f, 0.001094f, 0.001280f, 0.001457f, 0.001673f, 0.002232f,
+ 0.002411f, 0.002789f, 0.003174f, 0.003649f, 0.003859f, 0.004349f, 0.004990f, 0.005898f, 0.006622f, 0.007496f, 0.008209f, 0.009583f,
+ 0.011284f, 0.013062f, 0.014763f, 0.017120f, 0.020020f, 0.023804f, 0.028412f, 0.033905f, 0.041016f, 0.050140f, 0.062469f, 0.078552f,
+ 0.100159f, 0.129272f, 0.169067f, 0.222290f, 0.291504f, 0.376465f, 0.470703f, 0.566406f, 0.653320f, 0.728027f, 0.786621f, 0.832031f,
+ 0.866699f, 0.893555f, 0.914062f, 0.929688f, 0.942383f, 0.952148f, 0.959961f, 0.966797f, 0.972168f, 0.976074f, 0.991211f, 0.992188f,
+ 0.992676f, 0.992188f, 0.992676f, 0.992676f, 0.000241f, 0.000241f, 0.000240f, 0.000242f, 0.000486f, 0.000637f, 0.000916f, 0.000933f,
+ 0.001003f, 0.001284f, 0.001584f, 0.001925f, 0.002134f, 0.002502f, 0.002731f, 0.003134f, 0.003435f, 0.004036f, 0.004379f, 0.005077f,
+ 0.005688f, 0.006557f, 0.007347f, 0.007942f, 0.009506f, 0.010712f, 0.012527f, 0.014603f, 0.016693f, 0.019592f, 0.023285f, 0.027512f,
+ 0.033173f, 0.040283f, 0.049347f, 0.061432f, 0.077271f, 0.098938f, 0.128052f, 0.168091f, 0.222168f, 0.292725f, 0.379150f, 0.476807f,
+ 0.573730f, 0.662598f, 0.735840f, 0.794434f, 0.839844f, 0.873535f, 0.898926f, 0.918945f, 0.934082f, 0.945312f, 0.955566f, 0.962402f,
+ 0.969238f, 0.974609f, 0.990723f, 0.991699f, 0.992188f, 0.992188f, 0.992188f, 0.992188f, 0.000000f, 0.000238f, 0.000240f, 0.000362f,
+ 0.000362f, 0.000521f, 0.000631f, 0.000909f, 0.000937f, 0.001249f, 0.001373f, 0.001693f, 0.001746f, 0.002184f, 0.002436f, 0.002680f,
+ 0.003094f, 0.003576f, 0.003828f, 0.004463f, 0.004990f, 0.005589f, 0.006439f, 0.006943f, 0.008217f, 0.009384f, 0.010719f, 0.012184f,
+ 0.014130f, 0.016373f, 0.019241f, 0.022675f, 0.027161f, 0.032379f, 0.039307f, 0.048645f, 0.060455f, 0.076416f, 0.097778f, 0.127441f,
+ 0.168213f, 0.223633f, 0.296387f, 0.385986f, 0.485107f, 0.583984f, 0.673340f, 0.746582f, 0.804199f, 0.848633f, 0.880371f, 0.905273f,
+ 0.923828f, 0.938477f, 0.949707f, 0.958984f, 0.965820f, 0.972656f, 0.990234f, 0.991211f, 0.991211f, 0.991211f, 0.991211f, 0.991211f,
+ 0.000000f, 0.000234f, 0.000238f, 0.000236f, 0.000360f, 0.000482f, 0.000614f, 0.000786f, 0.000900f, 0.001056f, 0.001336f, 0.001466f,
+ 0.001671f, 0.001907f, 0.002333f, 0.002546f, 0.002871f, 0.003067f, 0.003500f, 0.003813f, 0.004425f, 0.004574f, 0.005459f, 0.006092f,
+ 0.006660f, 0.007660f, 0.008987f, 0.010071f, 0.011841f, 0.013847f, 0.016022f, 0.018829f, 0.022339f, 0.026779f, 0.031677f, 0.038910f,
+ 0.047913f, 0.059601f, 0.075684f, 0.097290f, 0.127319f, 0.169189f, 0.226807f, 0.302490f, 0.394775f, 0.497314f, 0.598633f, 0.686523f,
+ 0.759766f, 0.814941f, 0.857422f, 0.888672f, 0.912109f, 0.930176f, 0.943359f, 0.954102f, 0.962402f, 0.968750f, 0.988770f, 0.990234f,
+ 0.990234f, 0.990234f, 0.991211f, 0.990723f, 0.000000f, 0.000036f, 0.000166f, 0.000357f, 0.000356f, 0.000478f, 0.000566f, 0.000638f,
+ 0.000893f, 0.001146f, 0.001242f, 0.001330f, 0.001502f, 0.001773f, 0.001918f, 0.002024f, 0.002501f, 0.002604f, 0.003067f, 0.003334f,
+ 0.003708f, 0.004044f, 0.004646f, 0.005268f, 0.006241f, 0.006931f, 0.007774f, 0.008911f, 0.010277f, 0.011475f, 0.013542f, 0.015732f,
+ 0.018417f, 0.022049f, 0.026154f, 0.031189f, 0.038269f, 0.047119f, 0.059265f, 0.075256f, 0.097534f, 0.128906f, 0.172119f, 0.231934f,
+ 0.311035f, 0.407715f, 0.513184f, 0.615723f, 0.703613f, 0.773926f, 0.827637f, 0.867188f, 0.897461f, 0.919434f, 0.936035f, 0.948730f,
+ 0.958984f, 0.966309f, 0.988770f, 0.989746f, 0.989746f, 0.990234f, 0.989746f, 0.989746f, 0.000000f, 0.000028f, 0.000093f, 0.000334f,
+ 0.000465f, 0.000472f, 0.000373f, 0.000685f, 0.000695f, 0.001027f, 0.001128f, 0.001155f, 0.001419f, 0.001435f, 0.001760f, 0.001850f,
+ 0.002241f, 0.002373f, 0.002604f, 0.002821f, 0.003334f, 0.003666f, 0.004139f, 0.004627f, 0.005207f, 0.005886f, 0.006596f, 0.007580f,
+ 0.008705f, 0.009911f, 0.011520f, 0.013237f, 0.015427f, 0.017944f, 0.021423f, 0.025497f, 0.030945f, 0.037537f, 0.046692f, 0.058624f,
+ 0.075317f, 0.098267f, 0.130493f, 0.176025f, 0.239136f, 0.323242f, 0.424561f, 0.533691f, 0.636230f, 0.723145f, 0.790039f, 0.841797f,
+ 0.880371f, 0.906738f, 0.926758f, 0.941406f, 0.953613f, 0.963379f, 0.987793f, 0.988770f, 0.988770f, 0.989258f, 0.989258f, 0.989258f,
+ 0.000000f, 0.000000f, 0.000047f, 0.000321f, 0.000332f, 0.000351f, 0.000470f, 0.000596f, 0.000655f, 0.000727f, 0.001008f, 0.001112f,
+ 0.001350f, 0.001379f, 0.001380f, 0.001751f, 0.002008f, 0.002151f, 0.002327f, 0.002548f, 0.002691f, 0.003056f, 0.003475f, 0.003925f,
+ 0.004749f, 0.005161f, 0.005863f, 0.006538f, 0.007153f, 0.008453f, 0.009789f, 0.010986f, 0.013168f, 0.015121f, 0.017563f, 0.020966f,
+ 0.025009f, 0.030151f, 0.037048f, 0.046570f, 0.058624f, 0.075623f, 0.099243f, 0.133667f, 0.181641f, 0.249756f, 0.338623f, 0.445312f,
+ 0.556641f, 0.659180f, 0.744141f, 0.808594f, 0.855957f, 0.890137f, 0.916992f, 0.934570f, 0.949219f, 0.959473f, 0.986816f, 0.987793f,
+ 0.987793f, 0.987793f, 0.987793f, 0.988281f, 0.000000f, 0.000000f, 0.000000f, 0.000244f, 0.000429f, 0.000440f, 0.000348f, 0.000592f,
+ 0.000606f, 0.000755f, 0.000690f, 0.000935f, 0.001172f, 0.001257f, 0.001368f, 0.001458f, 0.001786f, 0.001809f, 0.002060f, 0.002274f,
+ 0.002478f, 0.002642f, 0.002987f, 0.003435f, 0.003866f, 0.004337f, 0.005066f, 0.005409f, 0.006355f, 0.007111f, 0.008011f, 0.009392f,
+ 0.011032f, 0.012321f, 0.014717f, 0.017319f, 0.020432f, 0.024551f, 0.029953f, 0.036835f, 0.045929f, 0.058716f, 0.076416f, 0.101562f,
+ 0.137695f, 0.189453f, 0.262451f, 0.358154f, 0.470215f, 0.584961f, 0.686523f, 0.767578f, 0.828125f, 0.871582f, 0.903809f, 0.926270f,
+ 0.941895f, 0.956055f, 0.985352f, 0.986328f, 0.986816f, 0.986816f, 0.986816f, 0.986816f, 0.000000f, 0.000000f, 0.000000f, 0.000119f,
+ 0.000237f, 0.000314f, 0.000570f, 0.000575f, 0.000583f, 0.000632f, 0.000651f, 0.000789f, 0.000947f, 0.001097f, 0.001300f, 0.001320f,
+ 0.001384f, 0.001443f, 0.001641f, 0.001869f, 0.002047f, 0.002396f, 0.002634f, 0.003025f, 0.003412f, 0.003757f, 0.004238f, 0.004620f,
+ 0.005463f, 0.006168f, 0.007072f, 0.008080f, 0.009155f, 0.010590f, 0.012306f, 0.014175f, 0.016769f, 0.020081f, 0.023972f, 0.029495f,
+ 0.036560f, 0.045959f, 0.059265f, 0.078125f, 0.104797f, 0.143677f, 0.199951f, 0.279785f, 0.382812f, 0.500977f, 0.616699f, 0.716309f,
+ 0.791992f, 0.847168f, 0.887207f, 0.915527f, 0.936523f, 0.950684f, 0.984375f, 0.985352f, 0.986328f, 0.985840f, 0.986328f, 0.985840f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000205f, 0.000239f, 0.000299f, 0.000537f, 0.000574f, 0.000696f, 0.000583f, 0.000740f,
+ 0.000778f, 0.000867f, 0.001013f, 0.001257f, 0.001325f, 0.001277f, 0.001416f, 0.001718f, 0.001965f, 0.002079f, 0.002356f, 0.002577f,
+ 0.002771f, 0.003305f, 0.003693f, 0.004028f, 0.004593f, 0.005234f, 0.005905f, 0.006802f, 0.007698f, 0.008553f, 0.009995f, 0.011635f,
+ 0.013824f, 0.016174f, 0.019547f, 0.023544f, 0.029114f, 0.036377f, 0.046417f, 0.060211f, 0.080017f, 0.108643f, 0.151611f, 0.213379f,
+ 0.301758f, 0.414062f, 0.537598f, 0.653320f, 0.748047f, 0.817871f, 0.868164f, 0.903320f, 0.928711f, 0.945801f, 0.982910f, 0.983887f,
+ 0.984375f, 0.984375f, 0.984863f, 0.984375f, 0.000000f, 0.000000f, 0.000045f, 0.000105f, 0.000114f, 0.000340f, 0.000371f, 0.000501f,
+ 0.000639f, 0.000554f, 0.000687f, 0.000675f, 0.000711f, 0.000738f, 0.000824f, 0.001092f, 0.001040f, 0.001185f, 0.001212f, 0.001408f,
+ 0.001624f, 0.001813f, 0.001982f, 0.002182f, 0.002634f, 0.002748f, 0.003252f, 0.003540f, 0.004089f, 0.004505f, 0.005001f, 0.005657f,
+ 0.006500f, 0.007195f, 0.008286f, 0.009750f, 0.011208f, 0.013420f, 0.015762f, 0.019226f, 0.023209f, 0.029144f, 0.036591f, 0.047150f,
+ 0.061615f, 0.082947f, 0.114014f, 0.161621f, 0.231323f, 0.329834f, 0.451416f, 0.579590f, 0.692871f, 0.780273f, 0.844238f, 0.888184f,
+ 0.917969f, 0.939453f, 0.981445f, 0.982422f, 0.982910f, 0.982910f, 0.982910f, 0.982910f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000208f, 0.000311f, 0.000238f, 0.000337f, 0.000524f, 0.000617f, 0.000533f, 0.000675f, 0.000665f, 0.000776f, 0.000840f, 0.000819f,
+ 0.000902f, 0.001169f, 0.001130f, 0.001178f, 0.001382f, 0.001571f, 0.001941f, 0.001932f, 0.002138f, 0.002306f, 0.002586f, 0.002937f,
+ 0.003468f, 0.003740f, 0.004292f, 0.004704f, 0.005444f, 0.006081f, 0.007019f, 0.008255f, 0.009521f, 0.010796f, 0.012840f, 0.015503f,
+ 0.018784f, 0.023178f, 0.029129f, 0.036774f, 0.047699f, 0.063416f, 0.086548f, 0.121399f, 0.175293f, 0.254883f, 0.365234f, 0.496582f,
+ 0.626953f, 0.733398f, 0.813477f, 0.869629f, 0.906738f, 0.933105f, 0.979980f, 0.980957f, 0.981445f, 0.981445f, 0.980957f, 0.981445f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000208f, 0.000312f, 0.000236f, 0.000343f, 0.000475f, 0.000496f, 0.000528f,
+ 0.000659f, 0.000582f, 0.000685f, 0.000710f, 0.000761f, 0.000784f, 0.000941f, 0.001013f, 0.001117f, 0.001339f, 0.001500f, 0.001623f,
+ 0.001769f, 0.002039f, 0.002298f, 0.002565f, 0.002802f, 0.003119f, 0.003471f, 0.003857f, 0.004658f, 0.005177f, 0.005836f, 0.006752f,
+ 0.007324f, 0.008911f, 0.010422f, 0.012527f, 0.015373f, 0.018585f, 0.022964f, 0.029037f, 0.037231f, 0.049072f, 0.066345f, 0.091492f,
+ 0.131470f, 0.193359f, 0.285645f, 0.409912f, 0.548828f, 0.676758f, 0.776367f, 0.845703f, 0.893066f, 0.924805f, 0.978027f, 0.979492f,
+ 0.979492f, 0.979004f, 0.979492f, 0.979492f, 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000166f, 0.000228f, 0.000227f,
+ 0.000369f, 0.000337f, 0.000368f, 0.000452f, 0.000500f, 0.000547f, 0.000543f, 0.000575f, 0.000623f, 0.000723f, 0.000783f, 0.000874f,
+ 0.001141f, 0.001226f, 0.001279f, 0.001336f, 0.001499f, 0.001655f, 0.001922f, 0.002090f, 0.002453f, 0.002298f, 0.003139f, 0.003181f,
+ 0.003674f, 0.004166f, 0.004814f, 0.005447f, 0.006348f, 0.007179f, 0.008736f, 0.010406f, 0.012321f, 0.014984f, 0.018219f, 0.022934f,
+ 0.028824f, 0.037598f, 0.050476f, 0.069397f, 0.098694f, 0.144775f, 0.218018f, 0.325439f, 0.464111f, 0.607910f, 0.729492f, 0.817383f,
+ 0.876953f, 0.915527f, 0.976562f, 0.977539f, 0.977539f, 0.977051f, 0.977051f, 0.977539f, 0.000000f, 0.000000f, 0.000000f, 0.000122f,
+ 0.000122f, 0.000122f, 0.000154f, 0.000200f, 0.000267f, 0.000316f, 0.000324f, 0.000449f, 0.000319f, 0.000379f, 0.000515f, 0.000519f,
+ 0.000558f, 0.000628f, 0.000645f, 0.000690f, 0.000777f, 0.000940f, 0.001096f, 0.001204f, 0.001278f, 0.001485f, 0.001670f, 0.001929f,
+ 0.001961f, 0.002016f, 0.002367f, 0.002785f, 0.003025f, 0.003248f, 0.003805f, 0.004539f, 0.004845f, 0.005733f, 0.006851f, 0.008278f,
+ 0.010017f, 0.011841f, 0.014542f, 0.017807f, 0.022705f, 0.029190f, 0.038544f, 0.052612f, 0.073853f, 0.108093f, 0.162842f, 0.250977f,
+ 0.377930f, 0.529785f, 0.672363f, 0.782715f, 0.855957f, 0.904297f, 0.973145f, 0.974121f, 0.974609f, 0.975586f, 0.974609f, 0.975098f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000158f, 0.000121f, 0.000190f, 0.000238f, 0.000397f, 0.000354f,
+ 0.000364f, 0.000365f, 0.000440f, 0.000474f, 0.000509f, 0.000612f, 0.000611f, 0.000648f, 0.000804f, 0.000755f, 0.000943f, 0.001050f,
+ 0.001221f, 0.001340f, 0.001338f, 0.001443f, 0.001635f, 0.001822f, 0.002083f, 0.002226f, 0.002480f, 0.002682f, 0.003185f, 0.003609f,
+ 0.003948f, 0.005074f, 0.005558f, 0.006741f, 0.007904f, 0.009384f, 0.011360f, 0.014000f, 0.017883f, 0.022675f, 0.029648f, 0.039917f,
+ 0.055695f, 0.080261f, 0.120728f, 0.188354f, 0.296143f, 0.443848f, 0.603027f, 0.737793f, 0.831055f, 0.891113f, 0.970703f, 0.971680f,
+ 0.972168f, 0.972656f, 0.971680f, 0.972168f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000122f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000251f, 0.000260f, 0.000278f, 0.000315f, 0.000334f, 0.000235f, 0.000357f, 0.000442f, 0.000513f, 0.000504f, 0.000598f,
+ 0.000556f, 0.000771f, 0.000831f, 0.000886f, 0.000977f, 0.001145f, 0.001105f, 0.001244f, 0.001281f, 0.001431f, 0.001544f, 0.001850f,
+ 0.001986f, 0.002131f, 0.002537f, 0.002737f, 0.003252f, 0.003826f, 0.004555f, 0.005184f, 0.006199f, 0.007195f, 0.009041f, 0.011337f,
+ 0.013878f, 0.017395f, 0.022552f, 0.030502f, 0.041962f, 0.059875f, 0.089111f, 0.139404f, 0.224609f, 0.357910f, 0.524902f, 0.684082f,
+ 0.800781f, 0.875977f, 0.967773f, 0.968750f, 0.968262f, 0.968750f, 0.969238f, 0.969238f, 0.000000f, 0.000000f, 0.000122f, 0.000122f,
+ 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000095f, 0.000081f, 0.000217f, 0.000149f, 0.000204f, 0.000212f, 0.000338f,
+ 0.000345f, 0.000348f, 0.000456f, 0.000463f, 0.000495f, 0.000570f, 0.000583f, 0.000748f, 0.000799f, 0.000731f, 0.000965f, 0.001041f,
+ 0.001071f, 0.001210f, 0.001318f, 0.001238f, 0.001410f, 0.001631f, 0.001932f, 0.002327f, 0.002577f, 0.003057f, 0.003452f, 0.003956f,
+ 0.004639f, 0.005714f, 0.006817f, 0.008446f, 0.010605f, 0.013443f, 0.017319f, 0.022964f, 0.031021f, 0.044281f, 0.065857f, 0.102112f,
+ 0.166504f, 0.277344f, 0.439941f, 0.617188f, 0.762207f, 0.856445f, 0.963379f, 0.964355f, 0.965332f, 0.964844f, 0.965332f, 0.965332f,
+ 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000107f, 0.000091f, 0.000161f,
+ 0.000119f, 0.000184f, 0.000266f, 0.000284f, 0.000314f, 0.000319f, 0.000334f, 0.000344f, 0.000565f, 0.000455f, 0.000488f, 0.000667f,
+ 0.000710f, 0.000713f, 0.000787f, 0.000755f, 0.000849f, 0.000972f, 0.001097f, 0.001286f, 0.001427f, 0.001556f, 0.001667f, 0.001687f,
+ 0.002155f, 0.002369f, 0.002674f, 0.003086f, 0.003710f, 0.004536f, 0.005585f, 0.006783f, 0.007957f, 0.010262f, 0.013115f, 0.017212f,
+ 0.023102f, 0.032715f, 0.047943f, 0.074158f, 0.121155f, 0.207520f, 0.353027f, 0.541504f, 0.715332f, 0.834473f, 0.959473f, 0.960449f,
+ 0.960938f, 0.960938f, 0.960938f, 0.961426f, 0.000000f, 0.000000f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000121f,
+ 0.000120f, 0.000120f, 0.000103f, 0.000089f, 0.000077f, 0.000080f, 0.000121f, 0.000218f, 0.000209f, 0.000245f, 0.000303f, 0.000316f,
+ 0.000388f, 0.000341f, 0.000549f, 0.000594f, 0.000604f, 0.000679f, 0.000625f, 0.000628f, 0.000795f, 0.000883f, 0.000857f, 0.000991f,
+ 0.001166f, 0.000955f, 0.001194f, 0.001347f, 0.001548f, 0.001804f, 0.002048f, 0.002388f, 0.002911f, 0.003130f, 0.003933f, 0.004845f,
+ 0.006031f, 0.007385f, 0.009705f, 0.012688f, 0.017044f, 0.023788f, 0.034882f, 0.053284f, 0.086670f, 0.151123f, 0.271484f, 0.457031f,
+ 0.658203f, 0.805176f, 0.954102f, 0.955078f, 0.956055f, 0.956055f, 0.956055f, 0.955566f, 0.000000f, 0.000122f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000116f, 0.000101f, 0.000088f, 0.000077f, 0.000131f, 0.000071f,
+ 0.000146f, 0.000200f, 0.000237f, 0.000270f, 0.000289f, 0.000302f, 0.000311f, 0.000441f, 0.000396f, 0.000588f, 0.000630f, 0.000570f,
+ 0.000575f, 0.000537f, 0.000589f, 0.000750f, 0.000721f, 0.001048f, 0.001122f, 0.000951f, 0.001243f, 0.001346f, 0.001703f, 0.001592f,
+ 0.001880f, 0.002340f, 0.002804f, 0.003637f, 0.004356f, 0.005329f, 0.006805f, 0.009094f, 0.012566f, 0.017181f, 0.025040f, 0.038147f,
+ 0.061249f, 0.107788f, 0.200195f, 0.369629f, 0.587891f, 0.771973f, 0.948242f, 0.949707f, 0.950195f, 0.949707f, 0.950195f, 0.950195f,
+ 0.000000f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000120f, 0.000119f, 0.000119f, 0.000114f,
+ 0.000101f, 0.000088f, 0.000079f, 0.000070f, 0.000063f, 0.000136f, 0.000136f, 0.000183f, 0.000207f, 0.000277f, 0.000271f, 0.000291f,
+ 0.000369f, 0.000344f, 0.000494f, 0.000459f, 0.000515f, 0.000509f, 0.000532f, 0.000504f, 0.000716f, 0.000589f, 0.000691f, 0.000902f,
+ 0.000972f, 0.000968f, 0.001067f, 0.001483f, 0.001780f, 0.001652f, 0.002090f, 0.002602f, 0.003113f, 0.003738f, 0.004738f, 0.006420f,
+ 0.008522f, 0.012100f, 0.017334f, 0.026489f, 0.042786f, 0.074524f, 0.142578f, 0.283936f, 0.509277f, 0.729492f, 0.940918f, 0.941895f,
+ 0.942383f, 0.942383f, 0.942383f, 0.942871f, 0.000122f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000119f, 0.000119f,
+ 0.000119f, 0.000118f, 0.000118f, 0.000118f, 0.000116f, 0.000102f, 0.000090f, 0.000081f, 0.000091f, 0.000066f, 0.000059f, 0.000110f,
+ 0.000109f, 0.000155f, 0.000184f, 0.000227f, 0.000297f, 0.000333f, 0.000355f, 0.000349f, 0.000344f, 0.000421f, 0.000459f, 0.000561f,
+ 0.000600f, 0.000563f, 0.000630f, 0.000563f, 0.000682f, 0.000737f, 0.000892f, 0.001037f, 0.001026f, 0.001163f, 0.001743f, 0.001782f,
+ 0.002117f, 0.002573f, 0.003389f, 0.004429f, 0.005871f, 0.007942f, 0.011841f, 0.018066f, 0.029190f, 0.050842f, 0.098511f, 0.207397f,
+ 0.422363f, 0.677734f, 0.932129f, 0.933594f, 0.933594f, 0.934082f, 0.934082f, 0.934082f, 0.000000f, 0.000121f, 0.000120f, 0.000119f,
+ 0.000119f, 0.000119f, 0.000118f, 0.000118f, 0.000118f, 0.000117f, 0.000117f, 0.000117f, 0.000117f, 0.000116f, 0.000104f, 0.000093f,
+ 0.000084f, 0.000076f, 0.000069f, 0.000091f, 0.000057f, 0.000051f, 0.000112f, 0.000120f, 0.000179f, 0.000232f, 0.000225f, 0.000283f,
+ 0.000301f, 0.000308f, 0.000353f, 0.000437f, 0.000395f, 0.000523f, 0.000486f, 0.000504f, 0.000469f, 0.000614f, 0.000581f, 0.000755f,
+ 0.000789f, 0.001121f, 0.000981f, 0.001218f, 0.001565f, 0.001795f, 0.002296f, 0.002958f, 0.003866f, 0.005329f, 0.007675f, 0.011658f,
+ 0.019043f, 0.033478f, 0.065430f, 0.144043f, 0.331299f, 0.613770f, 0.921387f, 0.922852f, 0.923340f, 0.923340f, 0.923340f, 0.923340f,
+ 0.000000f, 0.000000f, 0.000119f, 0.000118f, 0.000118f, 0.000117f, 0.000116f, 0.000116f, 0.000116f, 0.000116f, 0.000115f, 0.000115f,
+ 0.000115f, 0.000115f, 0.000114f, 0.000108f, 0.000097f, 0.000087f, 0.000079f, 0.000072f, 0.000065f, 0.000060f, 0.000094f, 0.000050f,
+ 0.000104f, 0.000104f, 0.000121f, 0.000164f, 0.000195f, 0.000247f, 0.000265f, 0.000328f, 0.000290f, 0.000355f, 0.000395f, 0.000356f,
+ 0.000361f, 0.000459f, 0.000470f, 0.000515f, 0.000580f, 0.000624f, 0.000751f, 0.000964f, 0.001105f, 0.001279f, 0.001413f, 0.001823f,
+ 0.002441f, 0.003407f, 0.004852f, 0.007210f, 0.011803f, 0.021225f, 0.041473f, 0.095032f, 0.244019f, 0.537598f, 0.907715f, 0.910156f,
+ 0.910156f, 0.909180f, 0.909668f, 0.911133f, 0.000120f, 0.000118f, 0.000117f, 0.000116f, 0.000114f, 0.000114f, 0.000114f, 0.000113f,
+ 0.000113f, 0.000112f, 0.000112f, 0.000112f, 0.000111f, 0.000112f, 0.000111f, 0.000111f, 0.000111f, 0.000101f, 0.000093f, 0.000084f,
+ 0.000077f, 0.000070f, 0.000064f, 0.000059f, 0.000074f, 0.000079f, 0.000059f, 0.000087f, 0.000097f, 0.000128f, 0.000185f, 0.000213f,
+ 0.000265f, 0.000235f, 0.000239f, 0.000288f, 0.000299f, 0.000371f, 0.000341f, 0.000369f, 0.000460f, 0.000446f, 0.000490f, 0.000602f,
+ 0.000694f, 0.000904f, 0.001012f, 0.001234f, 0.001544f, 0.002096f, 0.002989f, 0.004299f, 0.006840f, 0.012383f, 0.024948f, 0.059204f,
+ 0.166626f, 0.452637f, 0.892578f, 0.894043f, 0.894043f, 0.894531f, 0.894531f, 0.894043f, 0.000115f, 0.000107f, 0.000108f, 0.000111f,
+ 0.000108f, 0.000109f, 0.000108f, 0.000108f, 0.000108f, 0.000107f, 0.000108f, 0.000107f, 0.000107f, 0.000106f, 0.000107f, 0.000107f,
+ 0.000106f, 0.000107f, 0.000106f, 0.000097f, 0.000090f, 0.000082f, 0.000075f, 0.000069f, 0.000063f, 0.000058f, 0.000053f, 0.000070f,
+ 0.000073f, 0.000085f, 0.000077f, 0.000088f, 0.000136f, 0.000168f, 0.000190f, 0.000204f, 0.000199f, 0.000252f, 0.000233f, 0.000270f,
+ 0.000325f, 0.000295f, 0.000348f, 0.000383f, 0.000435f, 0.000534f, 0.000581f, 0.000803f, 0.001004f, 0.001330f, 0.001812f, 0.002489f,
+ 0.003944f, 0.006832f, 0.013748f, 0.033997f, 0.104858f, 0.356689f, 0.873047f, 0.873047f, 0.875000f, 0.874023f, 0.874023f, 0.874023f,
+ 0.000000f, 0.000071f, 0.000063f, 0.000094f, 0.000092f, 0.000094f, 0.000093f, 0.000098f, 0.000098f, 0.000098f, 0.000098f, 0.000099f,
+ 0.000098f, 0.000099f, 0.000099f, 0.000099f, 0.000099f, 0.000099f, 0.000099f, 0.000100f, 0.000100f, 0.000094f, 0.000087f, 0.000080f,
+ 0.000074f, 0.000068f, 0.000062f, 0.000058f, 0.000053f, 0.000049f, 0.000059f, 0.000059f, 0.000045f, 0.000078f, 0.000082f, 0.000118f,
+ 0.000155f, 0.000160f, 0.000174f, 0.000180f, 0.000226f, 0.000213f, 0.000248f, 0.000258f, 0.000288f, 0.000352f, 0.000396f, 0.000465f,
+ 0.000566f, 0.000789f, 0.000941f, 0.001343f, 0.002199f, 0.003616f, 0.006912f, 0.017380f, 0.058960f, 0.259521f, 0.847656f, 0.849121f,
+ 0.850586f, 0.850098f, 0.849121f, 0.850586f, 0.000000f, 0.000000f, 0.000019f, 0.000044f, 0.000048f, 0.000061f, 0.000071f, 0.000073f,
+ 0.000076f, 0.000079f, 0.000079f, 0.000082f, 0.000082f, 0.000082f, 0.000085f, 0.000086f, 0.000087f, 0.000086f, 0.000088f, 0.000087f,
+ 0.000089f, 0.000089f, 0.000089f, 0.000090f, 0.000084f, 0.000078f, 0.000072f, 0.000067f, 0.000062f, 0.000057f, 0.000052f, 0.000049f,
+ 0.000045f, 0.000041f, 0.000038f, 0.000040f, 0.000062f, 0.000092f, 0.000100f, 0.000121f, 0.000144f, 0.000133f, 0.000137f, 0.000170f,
+ 0.000181f, 0.000168f, 0.000215f, 0.000286f, 0.000327f, 0.000397f, 0.000504f, 0.000738f, 0.001039f, 0.001729f, 0.003317f, 0.007721f,
+ 0.028458f, 0.166626f, 0.815430f, 0.818359f, 0.818359f, 0.817383f, 0.818848f, 0.818359f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000008f, 0.000016f, 0.000031f, 0.000035f, 0.000048f, 0.000050f, 0.000053f, 0.000058f, 0.000059f,
+ 0.000063f, 0.000064f, 0.000067f, 0.000067f, 0.000070f, 0.000071f, 0.000072f, 0.000073f, 0.000075f, 0.000075f, 0.000076f, 0.000075f,
+ 0.000069f, 0.000064f, 0.000060f, 0.000055f, 0.000051f, 0.000047f, 0.000043f, 0.000040f, 0.000037f, 0.000034f, 0.000040f, 0.000041f,
+ 0.000054f, 0.000069f, 0.000096f, 0.000111f, 0.000109f, 0.000113f, 0.000142f, 0.000136f, 0.000158f, 0.000196f, 0.000237f, 0.000349f,
+ 0.000423f, 0.000744f, 0.001380f, 0.003214f, 0.011124f, 0.088135f, 0.777344f, 0.779297f, 0.780273f, 0.779785f, 0.779785f, 0.779785f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000003f, 0.000007f, 0.000021f, 0.000023f, 0.000031f, 0.000034f, 0.000038f, 0.000041f, 0.000043f, 0.000047f,
+ 0.000049f, 0.000050f, 0.000053f, 0.000055f, 0.000056f, 0.000057f, 0.000059f, 0.000060f, 0.000055f, 0.000051f, 0.000048f, 0.000044f,
+ 0.000041f, 0.000038f, 0.000035f, 0.000032f, 0.000029f, 0.000028f, 0.000028f, 0.000037f, 0.000044f, 0.000064f, 0.000078f, 0.000072f,
+ 0.000089f, 0.000098f, 0.000104f, 0.000146f, 0.000200f, 0.000272f, 0.000479f, 0.001077f, 0.003733f, 0.033752f, 0.729492f, 0.730957f,
+ 0.732422f, 0.731934f, 0.732422f, 0.732422f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000002f, 0.000006f, 0.000009f, 0.000013f, 0.000019f, 0.000021f, 0.000025f, 0.000027f, 0.000030f,
+ 0.000033f, 0.000034f, 0.000037f, 0.000039f, 0.000041f, 0.000039f, 0.000036f, 0.000033f, 0.000031f, 0.000028f, 0.000026f, 0.000024f,
+ 0.000021f, 0.000019f, 0.000017f, 0.000023f, 0.000033f, 0.000041f, 0.000043f, 0.000058f, 0.000061f, 0.000081f, 0.000121f, 0.000248f,
+ 0.000821f, 0.008255f, 0.673340f, 0.674805f, 0.674316f, 0.674805f, 0.674805f, 0.673828f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000004f, 0.000006f, 0.000010f, 0.000013f,
+ 0.000015f, 0.000017f, 0.000020f, 0.000022f, 0.000021f, 0.000019f, 0.000017f, 0.000015f, 0.000013f, 0.000012f, 0.000010f, 0.000011f,
+ 0.000016f, 0.000019f, 0.000019f, 0.000036f, 0.000090f, 0.000897f, 0.606934f, 0.609863f, 0.609375f, 0.609863f, 0.609863f, 0.610352f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000001f, 0.000003f, 0.000006f, 0.000005f, 0.000004f, 0.000003f, 0.000004f, 0.000008f, 0.534668f, 0.536621f,
+ 0.537109f, 0.537109f, 0.536621f, 0.536621f,
+ },
+ {
+ 0.149292f, 0.432373f, 0.614258f, 0.719238f, 0.784180f, 0.826660f, 0.856934f, 0.879883f, 0.896484f, 0.909180f, 0.919922f, 0.928711f,
+ 0.936035f, 0.942383f, 0.947266f, 0.952148f, 0.956055f, 0.959473f, 0.962891f, 0.965820f, 0.968262f, 0.970703f, 0.972656f, 0.974609f,
+ 0.976562f, 0.978027f, 0.979492f, 0.980469f, 0.981934f, 0.983398f, 0.984863f, 0.985352f, 0.986328f, 0.987305f, 0.988281f, 0.989258f,
+ 0.989746f, 0.990234f, 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.993652f, 0.994629f, 0.995117f, 0.995117f, 0.996094f,
+ 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.998047f, 0.998047f, 0.998535f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999512f, 0.999512f, 0.999512f, 0.999023f, 0.040161f, 0.161255f, 0.324951f, 0.486572f, 0.612305f, 0.704590f, 0.767090f, 0.811523f,
+ 0.844238f, 0.868652f, 0.887695f, 0.902344f, 0.913574f, 0.924316f, 0.932129f, 0.937988f, 0.944336f, 0.949707f, 0.954102f, 0.957520f,
+ 0.960938f, 0.964355f, 0.966797f, 0.969727f, 0.971191f, 0.973633f, 0.975586f, 0.977539f, 0.979004f, 0.980469f, 0.981445f, 0.982910f,
+ 0.983887f, 0.985352f, 0.985840f, 0.987305f, 0.987793f, 0.988770f, 0.989258f, 0.990234f, 0.991211f, 0.992188f, 0.992676f, 0.993164f,
+ 0.993164f, 0.993652f, 0.994141f, 0.995117f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f,
+ 0.999023f, 0.999023f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999023f, 0.017395f, 0.068542f, 0.149292f, 0.262451f,
+ 0.392822f, 0.518066f, 0.621582f, 0.700195f, 0.759766f, 0.803711f, 0.836426f, 0.862305f, 0.880859f, 0.896484f, 0.909668f, 0.919434f,
+ 0.929199f, 0.935547f, 0.941895f, 0.947754f, 0.952637f, 0.956055f, 0.959961f, 0.963867f, 0.965820f, 0.968750f, 0.970703f, 0.973145f,
+ 0.975098f, 0.977051f, 0.979004f, 0.979980f, 0.981934f, 0.983398f, 0.983887f, 0.984863f, 0.985840f, 0.986816f, 0.987793f, 0.989258f,
+ 0.989746f, 0.990234f, 0.991211f, 0.991699f, 0.992188f, 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995605f, 0.996094f, 0.996094f,
+ 0.996582f, 0.997070f, 0.997559f, 0.997559f, 0.998047f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999512f, 0.999023f,
+ 0.009125f, 0.035492f, 0.075806f, 0.135864f, 0.219971f, 0.324707f, 0.437012f, 0.543457f, 0.633789f, 0.704102f, 0.758789f, 0.802246f,
+ 0.833496f, 0.857910f, 0.878418f, 0.894043f, 0.906738f, 0.917480f, 0.925781f, 0.933594f, 0.940918f, 0.946777f, 0.951172f, 0.954590f,
+ 0.959473f, 0.962891f, 0.965820f, 0.968262f, 0.971191f, 0.973145f, 0.975098f, 0.976562f, 0.978516f, 0.979980f, 0.981445f, 0.982422f,
+ 0.983887f, 0.985840f, 0.986328f, 0.987305f, 0.988281f, 0.988770f, 0.989746f, 0.990234f, 0.991699f, 0.992188f, 0.992676f, 0.993652f,
+ 0.994141f, 0.994629f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996582f, 0.997559f, 0.997559f, 0.998047f, 0.999023f, 0.999023f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.005848f, 0.021225f, 0.043640f, 0.076782f, 0.124084f, 0.189575f, 0.274414f, 0.372559f,
+ 0.473633f, 0.567383f, 0.646973f, 0.711426f, 0.761230f, 0.801758f, 0.833496f, 0.857422f, 0.876953f, 0.893066f, 0.905273f, 0.916504f,
+ 0.925293f, 0.932617f, 0.939941f, 0.945801f, 0.950684f, 0.955566f, 0.958984f, 0.962402f, 0.965820f, 0.968262f, 0.970703f, 0.972656f,
+ 0.975098f, 0.977051f, 0.978516f, 0.980469f, 0.981934f, 0.982422f, 0.983887f, 0.985840f, 0.986328f, 0.987305f, 0.988281f, 0.989258f,
+ 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.995117f, 0.996094f, 0.996094f, 0.997070f,
+ 0.997559f, 0.997559f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.998535f, 0.998535f, 0.003937f, 0.014107f, 0.027664f, 0.047211f,
+ 0.075195f, 0.113953f, 0.166748f, 0.236328f, 0.320312f, 0.412354f, 0.504395f, 0.589844f, 0.661621f, 0.719727f, 0.768066f, 0.805664f,
+ 0.834961f, 0.858398f, 0.877441f, 0.893066f, 0.906738f, 0.916992f, 0.926270f, 0.933105f, 0.940430f, 0.946289f, 0.951172f, 0.955566f,
+ 0.959473f, 0.962891f, 0.965820f, 0.968262f, 0.970703f, 0.973145f, 0.975098f, 0.977051f, 0.979004f, 0.980469f, 0.981934f, 0.983398f,
+ 0.984375f, 0.985840f, 0.986328f, 0.987305f, 0.988770f, 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.992676f, 0.993652f, 0.994629f,
+ 0.994629f, 0.995117f, 0.995605f, 0.995605f, 0.996582f, 0.997070f, 0.998535f, 0.999023f, 0.999023f, 0.999023f, 0.998535f, 0.998535f,
+ 0.002962f, 0.009674f, 0.019348f, 0.031708f, 0.049255f, 0.072754f, 0.105164f, 0.149048f, 0.206665f, 0.278076f, 0.361572f, 0.448730f,
+ 0.534668f, 0.611816f, 0.677734f, 0.730957f, 0.775879f, 0.809570f, 0.837891f, 0.861328f, 0.879395f, 0.894531f, 0.907227f, 0.916992f,
+ 0.926270f, 0.934082f, 0.940918f, 0.946289f, 0.951172f, 0.956055f, 0.959473f, 0.962891f, 0.966797f, 0.969238f, 0.971191f, 0.973633f,
+ 0.976074f, 0.977539f, 0.979492f, 0.980957f, 0.982422f, 0.983398f, 0.984863f, 0.986328f, 0.986816f, 0.988281f, 0.989746f, 0.989746f,
+ 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.994629f, 0.995605f, 0.996094f, 0.997070f, 0.998535f, 0.999023f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.001900f, 0.007225f, 0.013733f, 0.022552f, 0.033661f, 0.049164f, 0.070374f, 0.097534f,
+ 0.135132f, 0.183350f, 0.244507f, 0.317871f, 0.400146f, 0.483643f, 0.562988f, 0.633301f, 0.693848f, 0.743652f, 0.784180f, 0.816895f,
+ 0.842773f, 0.865234f, 0.882812f, 0.896973f, 0.908691f, 0.919434f, 0.927734f, 0.935547f, 0.942383f, 0.947266f, 0.952637f, 0.957031f,
+ 0.960938f, 0.964355f, 0.967285f, 0.969727f, 0.971680f, 0.974609f, 0.976074f, 0.978027f, 0.979980f, 0.981445f, 0.982910f, 0.984375f,
+ 0.985840f, 0.986328f, 0.988281f, 0.988770f, 0.989746f, 0.990723f, 0.991699f, 0.992188f, 0.993164f, 0.993652f, 0.994629f, 0.995117f,
+ 0.995605f, 0.996094f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998047f, 0.001921f, 0.005543f, 0.010223f, 0.016312f,
+ 0.024918f, 0.035217f, 0.049164f, 0.067017f, 0.091125f, 0.122986f, 0.164673f, 0.217896f, 0.282471f, 0.356934f, 0.436768f, 0.516602f,
+ 0.590820f, 0.656250f, 0.711426f, 0.757812f, 0.794922f, 0.825684f, 0.850098f, 0.870605f, 0.885742f, 0.900879f, 0.912109f, 0.921387f,
+ 0.929688f, 0.937500f, 0.943848f, 0.949219f, 0.953125f, 0.958496f, 0.961426f, 0.964844f, 0.967773f, 0.970703f, 0.973145f, 0.975098f,
+ 0.977539f, 0.979004f, 0.980957f, 0.982422f, 0.983887f, 0.985352f, 0.986328f, 0.987793f, 0.988770f, 0.989258f, 0.990723f, 0.991211f,
+ 0.992188f, 0.993164f, 0.993652f, 0.994141f, 0.994629f, 0.995117f, 0.998047f, 0.998535f, 0.998535f, 0.998535f, 0.998047f, 0.998047f,
+ 0.001360f, 0.004257f, 0.007988f, 0.013092f, 0.018753f, 0.026352f, 0.035645f, 0.048096f, 0.064270f, 0.085449f, 0.113770f, 0.149292f,
+ 0.195190f, 0.251953f, 0.320557f, 0.395020f, 0.474121f, 0.549316f, 0.618652f, 0.678223f, 0.729492f, 0.770996f, 0.805176f, 0.833496f,
+ 0.855957f, 0.875977f, 0.891113f, 0.904785f, 0.915039f, 0.924316f, 0.933105f, 0.939453f, 0.945312f, 0.950684f, 0.955078f, 0.959473f,
+ 0.962891f, 0.966309f, 0.969727f, 0.972168f, 0.974121f, 0.976562f, 0.978516f, 0.979980f, 0.981934f, 0.983398f, 0.984375f, 0.986328f,
+ 0.986816f, 0.988281f, 0.989746f, 0.990234f, 0.991699f, 0.992188f, 0.992676f, 0.994141f, 0.994141f, 0.994629f, 0.998047f, 0.998047f,
+ 0.998535f, 0.998047f, 0.998047f, 0.998047f, 0.001075f, 0.003492f, 0.006275f, 0.010223f, 0.014473f, 0.019821f, 0.026581f, 0.035492f,
+ 0.046967f, 0.061829f, 0.080750f, 0.105164f, 0.136475f, 0.177246f, 0.227783f, 0.288818f, 0.358154f, 0.433594f, 0.509277f, 0.581543f,
+ 0.645508f, 0.701172f, 0.747070f, 0.783691f, 0.817383f, 0.842773f, 0.864258f, 0.881836f, 0.896484f, 0.908691f, 0.918945f, 0.928223f,
+ 0.935547f, 0.941895f, 0.948730f, 0.952637f, 0.957031f, 0.962402f, 0.964844f, 0.967773f, 0.970703f, 0.973633f, 0.975586f, 0.977539f,
+ 0.979492f, 0.981445f, 0.982910f, 0.984375f, 0.985840f, 0.986816f, 0.988281f, 0.988770f, 0.990234f, 0.991211f, 0.992188f, 0.992676f,
+ 0.993164f, 0.994141f, 0.997559f, 0.997559f, 0.998047f, 0.997559f, 0.997559f, 0.998047f, 0.000967f, 0.002928f, 0.005283f, 0.007759f,
+ 0.011612f, 0.015823f, 0.020966f, 0.027802f, 0.035461f, 0.045959f, 0.059235f, 0.075928f, 0.097778f, 0.126099f, 0.162598f, 0.207153f,
+ 0.261963f, 0.326416f, 0.398193f, 0.471680f, 0.543945f, 0.612305f, 0.671875f, 0.722656f, 0.765137f, 0.799805f, 0.828125f, 0.854004f,
+ 0.872070f, 0.888184f, 0.902344f, 0.914062f, 0.923340f, 0.931641f, 0.938965f, 0.945312f, 0.950684f, 0.955566f, 0.958984f, 0.962891f,
+ 0.966309f, 0.969727f, 0.972168f, 0.974609f, 0.977051f, 0.978516f, 0.980469f, 0.982422f, 0.984375f, 0.985352f, 0.987305f, 0.987793f,
+ 0.988770f, 0.990234f, 0.991211f, 0.992188f, 0.992676f, 0.993164f, 0.997559f, 0.997559f, 0.997559f, 0.998047f, 0.997559f, 0.998047f,
+ 0.000602f, 0.002605f, 0.004345f, 0.006706f, 0.009590f, 0.012650f, 0.016617f, 0.021423f, 0.027893f, 0.035004f, 0.044495f, 0.056610f,
+ 0.072327f, 0.092285f, 0.116821f, 0.148926f, 0.189697f, 0.238892f, 0.298340f, 0.365723f, 0.437988f, 0.511230f, 0.579590f, 0.642090f,
+ 0.698242f, 0.744141f, 0.781738f, 0.814453f, 0.840332f, 0.861816f, 0.880371f, 0.895996f, 0.907715f, 0.918945f, 0.928223f, 0.935547f,
+ 0.942871f, 0.948730f, 0.953125f, 0.958008f, 0.961914f, 0.965332f, 0.968750f, 0.971680f, 0.973633f, 0.976562f, 0.978516f, 0.979980f,
+ 0.981934f, 0.983398f, 0.985352f, 0.986816f, 0.988281f, 0.988770f, 0.989746f, 0.990723f, 0.991699f, 0.992676f, 0.997070f, 0.997559f,
+ 0.997559f, 0.997070f, 0.997070f, 0.997070f, 0.000607f, 0.001955f, 0.003616f, 0.005772f, 0.007656f, 0.010269f, 0.013496f, 0.017273f,
+ 0.022018f, 0.027466f, 0.034729f, 0.043488f, 0.054932f, 0.068359f, 0.086365f, 0.108765f, 0.137939f, 0.174316f, 0.219360f, 0.273926f,
+ 0.336670f, 0.406494f, 0.478516f, 0.549316f, 0.614746f, 0.673340f, 0.722656f, 0.765137f, 0.800293f, 0.828125f, 0.853516f, 0.872070f,
+ 0.888672f, 0.902832f, 0.914551f, 0.924316f, 0.932129f, 0.940430f, 0.946289f, 0.951660f, 0.956055f, 0.960449f, 0.964355f, 0.967773f,
+ 0.970703f, 0.972656f, 0.975586f, 0.978027f, 0.980469f, 0.981934f, 0.983398f, 0.985352f, 0.986328f, 0.988281f, 0.988770f, 0.990234f,
+ 0.990723f, 0.992188f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.000600f, 0.001813f, 0.003101f, 0.004559f,
+ 0.006580f, 0.008873f, 0.011047f, 0.014091f, 0.017639f, 0.022049f, 0.027557f, 0.033997f, 0.042297f, 0.052704f, 0.065369f, 0.081238f,
+ 0.101929f, 0.127930f, 0.161255f, 0.202515f, 0.252686f, 0.311523f, 0.378174f, 0.449707f, 0.519531f, 0.587891f, 0.647949f, 0.701660f,
+ 0.746582f, 0.784668f, 0.817383f, 0.843262f, 0.864746f, 0.882324f, 0.896973f, 0.910156f, 0.920898f, 0.929688f, 0.937012f, 0.943848f,
+ 0.949707f, 0.955078f, 0.959473f, 0.963379f, 0.966797f, 0.970215f, 0.973145f, 0.975098f, 0.978027f, 0.980469f, 0.982422f, 0.983887f,
+ 0.984863f, 0.986328f, 0.987793f, 0.988770f, 0.989746f, 0.991211f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.997070f,
+ 0.000604f, 0.001429f, 0.002676f, 0.003708f, 0.005745f, 0.006973f, 0.009270f, 0.011452f, 0.014503f, 0.018295f, 0.022369f, 0.027222f,
+ 0.033417f, 0.040833f, 0.050171f, 0.062744f, 0.077454f, 0.095886f, 0.119995f, 0.150391f, 0.187622f, 0.234253f, 0.289307f, 0.353027f,
+ 0.421631f, 0.492676f, 0.561523f, 0.625488f, 0.681152f, 0.730469f, 0.770996f, 0.806152f, 0.833984f, 0.857422f, 0.876465f, 0.893066f,
+ 0.906250f, 0.916992f, 0.926758f, 0.935059f, 0.942871f, 0.948242f, 0.954102f, 0.958496f, 0.962891f, 0.966309f, 0.969727f, 0.972168f,
+ 0.975098f, 0.977539f, 0.979492f, 0.981934f, 0.983398f, 0.984863f, 0.986328f, 0.987793f, 0.989258f, 0.990234f, 0.996094f, 0.996582f,
+ 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.000365f, 0.001367f, 0.002123f, 0.003353f, 0.004692f, 0.006054f, 0.007675f, 0.009819f,
+ 0.012314f, 0.014862f, 0.018066f, 0.022064f, 0.026901f, 0.032471f, 0.039764f, 0.048584f, 0.060089f, 0.073730f, 0.090698f, 0.112854f,
+ 0.140381f, 0.175415f, 0.218018f, 0.269775f, 0.329834f, 0.396240f, 0.467285f, 0.537598f, 0.603516f, 0.662109f, 0.712891f, 0.757324f,
+ 0.793945f, 0.823730f, 0.849121f, 0.869629f, 0.887695f, 0.902344f, 0.914062f, 0.924805f, 0.932129f, 0.940430f, 0.947266f, 0.952148f,
+ 0.957031f, 0.962402f, 0.966309f, 0.969238f, 0.972656f, 0.975586f, 0.977051f, 0.979492f, 0.981934f, 0.983398f, 0.984863f, 0.986328f,
+ 0.988281f, 0.988770f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.000356f, 0.001341f, 0.001913f, 0.002897f,
+ 0.003983f, 0.005322f, 0.006607f, 0.008514f, 0.010399f, 0.012451f, 0.015282f, 0.018356f, 0.021912f, 0.026443f, 0.031982f, 0.038635f,
+ 0.047150f, 0.057495f, 0.070007f, 0.086609f, 0.106689f, 0.131714f, 0.164429f, 0.203613f, 0.252441f, 0.310059f, 0.374512f, 0.444092f,
+ 0.514160f, 0.582031f, 0.643066f, 0.697266f, 0.743652f, 0.783691f, 0.814941f, 0.842773f, 0.865234f, 0.882812f, 0.897949f, 0.910645f,
+ 0.922363f, 0.931152f, 0.938965f, 0.945801f, 0.952148f, 0.957520f, 0.961426f, 0.965820f, 0.969727f, 0.972168f, 0.975098f, 0.977539f,
+ 0.979980f, 0.981934f, 0.983887f, 0.985352f, 0.986816f, 0.988281f, 0.995117f, 0.995605f, 0.996094f, 0.996094f, 0.996094f, 0.996094f,
+ 0.000243f, 0.000937f, 0.001662f, 0.002617f, 0.003527f, 0.004555f, 0.005642f, 0.007217f, 0.008820f, 0.010483f, 0.012383f, 0.015175f,
+ 0.018341f, 0.022049f, 0.026245f, 0.031067f, 0.037903f, 0.045563f, 0.054962f, 0.066956f, 0.082092f, 0.101074f, 0.124939f, 0.154663f,
+ 0.191528f, 0.237305f, 0.291992f, 0.354492f, 0.422852f, 0.492676f, 0.562012f, 0.625488f, 0.682617f, 0.731934f, 0.772949f, 0.807129f,
+ 0.835449f, 0.859863f, 0.878906f, 0.895020f, 0.908203f, 0.920898f, 0.929199f, 0.937988f, 0.945312f, 0.951660f, 0.957031f, 0.961914f,
+ 0.965332f, 0.968750f, 0.972656f, 0.975098f, 0.977539f, 0.979980f, 0.982422f, 0.983887f, 0.986328f, 0.987793f, 0.995117f, 0.995605f,
+ 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.000362f, 0.000970f, 0.001489f, 0.002251f, 0.002892f, 0.003727f, 0.004978f, 0.006264f,
+ 0.007530f, 0.009125f, 0.010551f, 0.012756f, 0.015259f, 0.018097f, 0.021637f, 0.025986f, 0.030594f, 0.036804f, 0.044006f, 0.053162f,
+ 0.064148f, 0.078003f, 0.096130f, 0.118042f, 0.146118f, 0.181030f, 0.224487f, 0.276123f, 0.336670f, 0.403320f, 0.473633f, 0.543457f,
+ 0.609375f, 0.667480f, 0.719238f, 0.763184f, 0.799316f, 0.829590f, 0.854492f, 0.875488f, 0.892578f, 0.906738f, 0.918945f, 0.928711f,
+ 0.937012f, 0.944336f, 0.951172f, 0.956543f, 0.961426f, 0.965820f, 0.968750f, 0.972656f, 0.975098f, 0.978027f, 0.980469f, 0.982910f,
+ 0.984375f, 0.985840f, 0.994629f, 0.995117f, 0.995117f, 0.995117f, 0.995117f, 0.995117f, 0.000346f, 0.000923f, 0.001273f, 0.002010f,
+ 0.002619f, 0.003689f, 0.004452f, 0.005177f, 0.006290f, 0.007561f, 0.009033f, 0.010902f, 0.012970f, 0.015495f, 0.018280f, 0.021576f,
+ 0.024948f, 0.030304f, 0.035400f, 0.042480f, 0.051086f, 0.061401f, 0.074890f, 0.091187f, 0.112427f, 0.138794f, 0.171631f, 0.212158f,
+ 0.262451f, 0.320557f, 0.385986f, 0.456055f, 0.525391f, 0.593262f, 0.654297f, 0.708984f, 0.754883f, 0.792969f, 0.824707f, 0.850098f,
+ 0.872070f, 0.890137f, 0.904785f, 0.917480f, 0.927734f, 0.937012f, 0.944336f, 0.951172f, 0.956055f, 0.961914f, 0.966309f, 0.969727f,
+ 0.973145f, 0.976074f, 0.978516f, 0.980469f, 0.982910f, 0.984863f, 0.993652f, 0.995117f, 0.994629f, 0.994629f, 0.994629f, 0.994629f,
+ 0.000242f, 0.000666f, 0.001081f, 0.001806f, 0.002512f, 0.003397f, 0.003866f, 0.004894f, 0.005566f, 0.006859f, 0.007957f, 0.009506f,
+ 0.011009f, 0.013046f, 0.015266f, 0.018173f, 0.021027f, 0.024811f, 0.029526f, 0.034790f, 0.041443f, 0.049835f, 0.059265f, 0.071899f,
+ 0.087769f, 0.107422f, 0.132202f, 0.163208f, 0.201782f, 0.249512f, 0.305908f, 0.370361f, 0.440430f, 0.511230f, 0.578613f, 0.642090f,
+ 0.698730f, 0.746582f, 0.787109f, 0.819824f, 0.848145f, 0.869141f, 0.888672f, 0.903809f, 0.916992f, 0.927246f, 0.936523f, 0.943848f,
+ 0.951660f, 0.957031f, 0.961426f, 0.965820f, 0.970215f, 0.973145f, 0.976074f, 0.979004f, 0.981445f, 0.983398f, 0.994141f, 0.994141f,
+ 0.994629f, 0.994141f, 0.994629f, 0.994141f, 0.000242f, 0.000709f, 0.000917f, 0.001194f, 0.002018f, 0.002634f, 0.003504f, 0.003918f,
+ 0.005020f, 0.005726f, 0.006935f, 0.008141f, 0.009666f, 0.011040f, 0.012848f, 0.014961f, 0.017624f, 0.020660f, 0.024368f, 0.028381f,
+ 0.033905f, 0.040283f, 0.047760f, 0.057312f, 0.069214f, 0.083984f, 0.102539f, 0.126221f, 0.155640f, 0.193359f, 0.238892f, 0.293701f,
+ 0.356689f, 0.425537f, 0.497070f, 0.568359f, 0.632812f, 0.690918f, 0.739746f, 0.782227f, 0.816406f, 0.845703f, 0.868652f, 0.887695f,
+ 0.903320f, 0.916992f, 0.927734f, 0.937012f, 0.944824f, 0.951660f, 0.957031f, 0.962891f, 0.966797f, 0.971191f, 0.973633f, 0.976562f,
+ 0.979492f, 0.981934f, 0.992676f, 0.993652f, 0.994141f, 0.993652f, 0.993652f, 0.994141f, 0.000244f, 0.000660f, 0.000918f, 0.001343f,
+ 0.002117f, 0.002407f, 0.002779f, 0.003626f, 0.004246f, 0.005207f, 0.005913f, 0.007145f, 0.008163f, 0.009438f, 0.011101f, 0.012871f,
+ 0.014999f, 0.017426f, 0.020096f, 0.024185f, 0.027725f, 0.032623f, 0.038910f, 0.046387f, 0.055298f, 0.066467f, 0.080627f, 0.098328f,
+ 0.120972f, 0.149658f, 0.184814f, 0.229492f, 0.282715f, 0.344727f, 0.414062f, 0.486084f, 0.556641f, 0.624023f, 0.683594f, 0.735352f,
+ 0.778320f, 0.814453f, 0.843750f, 0.867188f, 0.887207f, 0.903320f, 0.916504f, 0.928223f, 0.937500f, 0.945312f, 0.953125f, 0.958008f,
+ 0.964355f, 0.967285f, 0.971680f, 0.975098f, 0.978516f, 0.980957f, 0.992676f, 0.993652f, 0.994141f, 0.993652f, 0.993652f, 0.993164f,
+ 0.000200f, 0.000480f, 0.000808f, 0.001303f, 0.001680f, 0.002104f, 0.002510f, 0.002934f, 0.003468f, 0.004429f, 0.005539f, 0.006046f,
+ 0.006889f, 0.008438f, 0.009415f, 0.011108f, 0.012787f, 0.014572f, 0.017517f, 0.020279f, 0.023483f, 0.027359f, 0.031860f, 0.037964f,
+ 0.045227f, 0.053711f, 0.064148f, 0.077759f, 0.095093f, 0.116272f, 0.143311f, 0.177856f, 0.221191f, 0.273193f, 0.334473f, 0.403320f,
+ 0.476318f, 0.548828f, 0.617188f, 0.677734f, 0.730957f, 0.775879f, 0.812500f, 0.842285f, 0.866699f, 0.887695f, 0.903809f, 0.916992f,
+ 0.928711f, 0.938477f, 0.946777f, 0.953125f, 0.959473f, 0.963867f, 0.968750f, 0.972656f, 0.976074f, 0.979004f, 0.992188f, 0.992676f,
+ 0.993164f, 0.993164f, 0.992676f, 0.993164f, 0.000243f, 0.000469f, 0.000878f, 0.001158f, 0.001382f, 0.001801f, 0.002220f, 0.002699f,
+ 0.003273f, 0.004063f, 0.004715f, 0.005447f, 0.005917f, 0.007099f, 0.008385f, 0.009521f, 0.011032f, 0.012627f, 0.014870f, 0.016922f,
+ 0.019836f, 0.023010f, 0.026642f, 0.031174f, 0.036926f, 0.043549f, 0.051941f, 0.062561f, 0.075317f, 0.091553f, 0.112427f, 0.138428f,
+ 0.172485f, 0.213867f, 0.265381f, 0.326172f, 0.394775f, 0.467773f, 0.541504f, 0.610840f, 0.673340f, 0.728516f, 0.774414f, 0.812012f,
+ 0.842773f, 0.867676f, 0.887695f, 0.904297f, 0.918457f, 0.929688f, 0.939453f, 0.948242f, 0.955078f, 0.959961f, 0.965820f, 0.970215f,
+ 0.974121f, 0.977051f, 0.991211f, 0.993164f, 0.993164f, 0.992188f, 0.993164f, 0.992188f, 0.000000f, 0.000242f, 0.000799f, 0.000998f,
+ 0.001273f, 0.001671f, 0.002069f, 0.002485f, 0.003212f, 0.003578f, 0.003948f, 0.004559f, 0.005524f, 0.006321f, 0.007046f, 0.008438f,
+ 0.009438f, 0.010986f, 0.012390f, 0.014320f, 0.016663f, 0.019165f, 0.022476f, 0.025833f, 0.030487f, 0.035675f, 0.042358f, 0.050018f,
+ 0.060211f, 0.072693f, 0.088379f, 0.108948f, 0.134766f, 0.166626f, 0.208008f, 0.258545f, 0.318848f, 0.387451f, 0.461670f, 0.536621f,
+ 0.606934f, 0.671387f, 0.727539f, 0.773438f, 0.811523f, 0.843750f, 0.868164f, 0.889160f, 0.906250f, 0.920410f, 0.932617f, 0.941895f,
+ 0.949707f, 0.956055f, 0.962402f, 0.967285f, 0.971680f, 0.975586f, 0.990723f, 0.991699f, 0.991699f, 0.992188f, 0.992188f, 0.991699f,
+ 0.000237f, 0.000482f, 0.000772f, 0.000877f, 0.001109f, 0.001494f, 0.001991f, 0.002041f, 0.002537f, 0.002975f, 0.003469f, 0.004128f,
+ 0.004841f, 0.005550f, 0.006306f, 0.007359f, 0.008369f, 0.009415f, 0.010788f, 0.012306f, 0.014160f, 0.016571f, 0.018921f, 0.021896f,
+ 0.025497f, 0.029587f, 0.034576f, 0.041260f, 0.049011f, 0.058319f, 0.070557f, 0.086060f, 0.105774f, 0.130737f, 0.162720f, 0.203247f,
+ 0.252930f, 0.313477f, 0.382568f, 0.457275f, 0.532715f, 0.605469f, 0.671387f, 0.728027f, 0.774902f, 0.814453f, 0.844727f, 0.870605f,
+ 0.891113f, 0.909180f, 0.922852f, 0.934082f, 0.943359f, 0.951660f, 0.958008f, 0.964355f, 0.968750f, 0.973145f, 0.990234f, 0.990723f,
+ 0.991699f, 0.991211f, 0.991211f, 0.991211f, 0.000235f, 0.000461f, 0.000484f, 0.000891f, 0.001105f, 0.001346f, 0.001634f, 0.001936f,
+ 0.002438f, 0.002874f, 0.003353f, 0.003925f, 0.004189f, 0.004887f, 0.005684f, 0.006279f, 0.007298f, 0.008339f, 0.009384f, 0.010674f,
+ 0.012360f, 0.013901f, 0.016113f, 0.018677f, 0.021469f, 0.024841f, 0.029144f, 0.033783f, 0.039948f, 0.047272f, 0.056915f, 0.068726f,
+ 0.083801f, 0.102905f, 0.127563f, 0.159058f, 0.199341f, 0.248901f, 0.309570f, 0.379395f, 0.454834f, 0.532715f, 0.606934f, 0.672852f,
+ 0.729980f, 0.778320f, 0.817383f, 0.849121f, 0.874512f, 0.895020f, 0.911621f, 0.924805f, 0.937012f, 0.946289f, 0.954102f, 0.960938f,
+ 0.965820f, 0.971191f, 0.989258f, 0.990234f, 0.990723f, 0.991211f, 0.990723f, 0.990723f, 0.000000f, 0.000360f, 0.000477f, 0.000756f,
+ 0.000896f, 0.001065f, 0.001570f, 0.001622f, 0.002064f, 0.002525f, 0.002819f, 0.003004f, 0.003700f, 0.004356f, 0.005077f, 0.005428f,
+ 0.006283f, 0.007370f, 0.008339f, 0.009323f, 0.010567f, 0.012070f, 0.013672f, 0.015839f, 0.018066f, 0.020844f, 0.024002f, 0.028183f,
+ 0.033051f, 0.039246f, 0.046417f, 0.055450f, 0.067200f, 0.082031f, 0.100586f, 0.125122f, 0.156250f, 0.196167f, 0.245972f, 0.307129f,
+ 0.378174f, 0.454834f, 0.533203f, 0.608398f, 0.675781f, 0.734375f, 0.782715f, 0.821777f, 0.853516f, 0.878906f, 0.898926f, 0.915039f,
+ 0.929199f, 0.939941f, 0.948730f, 0.956055f, 0.963379f, 0.968262f, 0.988770f, 0.989746f, 0.990234f, 0.989746f, 0.989746f, 0.990234f,
+ 0.000000f, 0.000256f, 0.000467f, 0.000590f, 0.000772f, 0.001095f, 0.001356f, 0.001781f, 0.001984f, 0.002161f, 0.002546f, 0.002956f,
+ 0.003338f, 0.003899f, 0.004440f, 0.004986f, 0.005486f, 0.006310f, 0.006969f, 0.008148f, 0.009148f, 0.010284f, 0.011902f, 0.013573f,
+ 0.015465f, 0.017853f, 0.020340f, 0.023590f, 0.027298f, 0.032227f, 0.038208f, 0.045563f, 0.054047f, 0.065796f, 0.080322f, 0.098999f,
+ 0.122864f, 0.153809f, 0.193970f, 0.244629f, 0.306396f, 0.378662f, 0.457031f, 0.536621f, 0.613770f, 0.681641f, 0.740723f, 0.788574f,
+ 0.827637f, 0.858398f, 0.884277f, 0.903320f, 0.919922f, 0.932129f, 0.942871f, 0.951660f, 0.959961f, 0.965820f, 0.987305f, 0.988281f,
+ 0.989258f, 0.989258f, 0.989258f, 0.989258f, 0.000244f, 0.000243f, 0.000583f, 0.000585f, 0.000822f, 0.001073f, 0.001159f, 0.001452f,
+ 0.001525f, 0.002001f, 0.002201f, 0.002714f, 0.002932f, 0.003525f, 0.003904f, 0.004482f, 0.004997f, 0.005581f, 0.006233f, 0.006954f,
+ 0.007820f, 0.008949f, 0.009941f, 0.011482f, 0.013168f, 0.015099f, 0.017151f, 0.020111f, 0.022949f, 0.026947f, 0.031647f, 0.037354f,
+ 0.044342f, 0.053375f, 0.064331f, 0.078857f, 0.097351f, 0.121033f, 0.152588f, 0.192749f, 0.244263f, 0.307129f, 0.380615f, 0.461426f,
+ 0.543457f, 0.621582f, 0.690430f, 0.748047f, 0.796387f, 0.834961f, 0.865723f, 0.889160f, 0.908691f, 0.924316f, 0.937500f, 0.946777f,
+ 0.955078f, 0.962891f, 0.986328f, 0.987793f, 0.988770f, 0.988770f, 0.988770f, 0.988770f, 0.000000f, 0.000243f, 0.000308f, 0.000541f,
+ 0.000801f, 0.000827f, 0.001057f, 0.001280f, 0.001460f, 0.001781f, 0.002090f, 0.002481f, 0.002756f, 0.003054f, 0.003321f, 0.003948f,
+ 0.004303f, 0.004898f, 0.005306f, 0.006405f, 0.006954f, 0.007851f, 0.008537f, 0.009918f, 0.011208f, 0.012825f, 0.014534f, 0.016861f,
+ 0.019379f, 0.022629f, 0.026276f, 0.030838f, 0.036407f, 0.043488f, 0.051819f, 0.063416f, 0.077209f, 0.095825f, 0.119812f, 0.151489f,
+ 0.192749f, 0.245361f, 0.309814f, 0.385986f, 0.469238f, 0.552246f, 0.630859f, 0.699707f, 0.757324f, 0.805176f, 0.842773f, 0.873047f,
+ 0.895508f, 0.914062f, 0.929688f, 0.941406f, 0.952148f, 0.959473f, 0.985840f, 0.986816f, 0.987305f, 0.987305f, 0.987305f, 0.987305f,
+ 0.000000f, 0.000243f, 0.000242f, 0.000548f, 0.000695f, 0.000803f, 0.001053f, 0.001198f, 0.001363f, 0.001513f, 0.001886f, 0.002069f,
+ 0.002447f, 0.002676f, 0.003138f, 0.003551f, 0.003868f, 0.004261f, 0.004936f, 0.005337f, 0.005852f, 0.006615f, 0.007519f, 0.008575f,
+ 0.009705f, 0.010872f, 0.012688f, 0.014397f, 0.016479f, 0.019119f, 0.022064f, 0.025589f, 0.030304f, 0.035828f, 0.042603f, 0.050812f,
+ 0.062012f, 0.076355f, 0.094971f, 0.119263f, 0.151367f, 0.193726f, 0.247925f, 0.314941f, 0.393311f, 0.478271f, 0.563965f, 0.642578f,
+ 0.711914f, 0.769043f, 0.815430f, 0.851562f, 0.881348f, 0.902832f, 0.921387f, 0.934570f, 0.945801f, 0.955078f, 0.984375f, 0.986328f,
+ 0.986328f, 0.986328f, 0.986328f, 0.986328f, 0.000000f, 0.000234f, 0.000239f, 0.000308f, 0.000597f, 0.000690f, 0.000868f, 0.000937f,
+ 0.001189f, 0.001404f, 0.001696f, 0.001854f, 0.002180f, 0.002249f, 0.002672f, 0.002979f, 0.003494f, 0.003761f, 0.004257f, 0.004745f,
+ 0.005154f, 0.005821f, 0.006561f, 0.007557f, 0.008575f, 0.009575f, 0.010963f, 0.012238f, 0.014130f, 0.016113f, 0.018539f, 0.021545f,
+ 0.025162f, 0.029404f, 0.034851f, 0.041626f, 0.050354f, 0.061218f, 0.075562f, 0.094482f, 0.119507f, 0.152344f, 0.196167f, 0.252197f,
+ 0.322266f, 0.404053f, 0.490967f, 0.577637f, 0.658203f, 0.726074f, 0.782715f, 0.827637f, 0.861816f, 0.889648f, 0.910645f, 0.926758f,
+ 0.940918f, 0.950684f, 0.983398f, 0.985352f, 0.984863f, 0.985352f, 0.985840f, 0.985352f, 0.000000f, 0.000240f, 0.000237f, 0.000239f,
+ 0.000436f, 0.000648f, 0.000661f, 0.000892f, 0.001089f, 0.001484f, 0.001446f, 0.001586f, 0.001896f, 0.002176f, 0.002325f, 0.002634f,
+ 0.003057f, 0.003315f, 0.003561f, 0.004150f, 0.004578f, 0.005180f, 0.005768f, 0.006485f, 0.007286f, 0.008400f, 0.009453f, 0.010429f,
+ 0.011795f, 0.013680f, 0.015671f, 0.018005f, 0.020981f, 0.024521f, 0.028748f, 0.034119f, 0.040863f, 0.049622f, 0.060303f, 0.074829f,
+ 0.094116f, 0.119995f, 0.154297f, 0.199341f, 0.258301f, 0.331787f, 0.416504f, 0.507812f, 0.595703f, 0.675781f, 0.743164f, 0.797852f,
+ 0.840820f, 0.873535f, 0.899414f, 0.919434f, 0.934082f, 0.947266f, 0.982422f, 0.983887f, 0.983887f, 0.984375f, 0.984375f, 0.983887f,
+ 0.000136f, 0.000115f, 0.000237f, 0.000238f, 0.000358f, 0.000452f, 0.000759f, 0.000961f, 0.001026f, 0.001113f, 0.001433f, 0.001564f,
+ 0.001659f, 0.001955f, 0.002024f, 0.002384f, 0.002647f, 0.002974f, 0.003267f, 0.003611f, 0.003971f, 0.004498f, 0.005043f, 0.005539f,
+ 0.006344f, 0.007168f, 0.007942f, 0.009010f, 0.010353f, 0.011711f, 0.013458f, 0.015213f, 0.017548f, 0.020279f, 0.023926f, 0.028061f,
+ 0.033356f, 0.040283f, 0.048615f, 0.060455f, 0.074890f, 0.094727f, 0.121216f, 0.156860f, 0.204102f, 0.266846f, 0.344238f, 0.433105f,
+ 0.526855f, 0.616699f, 0.696289f, 0.761230f, 0.813965f, 0.854492f, 0.884766f, 0.909180f, 0.927734f, 0.941895f, 0.980957f, 0.982422f,
+ 0.982910f, 0.982422f, 0.982422f, 0.982910f, 0.000000f, 0.000103f, 0.000208f, 0.000356f, 0.000355f, 0.000400f, 0.000454f, 0.000861f,
+ 0.000922f, 0.001202f, 0.001088f, 0.001401f, 0.001493f, 0.001779f, 0.001881f, 0.002180f, 0.002329f, 0.002483f, 0.002846f, 0.003178f,
+ 0.003542f, 0.003914f, 0.004406f, 0.004871f, 0.005352f, 0.006119f, 0.006927f, 0.007904f, 0.008759f, 0.009972f, 0.011284f, 0.013046f,
+ 0.014938f, 0.016998f, 0.019943f, 0.023224f, 0.027161f, 0.032776f, 0.039917f, 0.048218f, 0.059937f, 0.075134f, 0.095642f, 0.123169f,
+ 0.160767f, 0.211670f, 0.278320f, 0.360352f, 0.454102f, 0.550293f, 0.640625f, 0.718262f, 0.781738f, 0.831055f, 0.869141f, 0.897461f,
+ 0.919434f, 0.936035f, 0.979492f, 0.980957f, 0.980957f, 0.981934f, 0.981445f, 0.981445f, 0.000000f, 0.000192f, 0.000191f, 0.000350f,
+ 0.000352f, 0.000354f, 0.000599f, 0.000721f, 0.000835f, 0.001044f, 0.000988f, 0.001141f, 0.001255f, 0.001479f, 0.001705f, 0.001815f,
+ 0.001843f, 0.002151f, 0.002369f, 0.002831f, 0.003067f, 0.003431f, 0.003698f, 0.004295f, 0.004738f, 0.005352f, 0.005859f, 0.006615f,
+ 0.007587f, 0.008583f, 0.009682f, 0.010735f, 0.012405f, 0.014381f, 0.016708f, 0.018921f, 0.022736f, 0.026947f, 0.032104f, 0.039032f,
+ 0.048004f, 0.059784f, 0.075500f, 0.096924f, 0.125977f, 0.166626f, 0.221069f, 0.292969f, 0.380371f, 0.479004f, 0.577637f, 0.667969f,
+ 0.743164f, 0.803711f, 0.849609f, 0.883789f, 0.910645f, 0.930176f, 0.977539f, 0.979492f, 0.979492f, 0.979492f, 0.979980f, 0.979492f,
+ 0.000000f, 0.000000f, 0.000191f, 0.000214f, 0.000441f, 0.000465f, 0.000351f, 0.000656f, 0.000672f, 0.000957f, 0.000881f, 0.001092f,
+ 0.001209f, 0.001259f, 0.001315f, 0.001583f, 0.001630f, 0.001834f, 0.002033f, 0.002367f, 0.002596f, 0.002924f, 0.003387f, 0.003693f,
+ 0.004063f, 0.004601f, 0.004986f, 0.005676f, 0.006557f, 0.006973f, 0.007801f, 0.008781f, 0.010475f, 0.012100f, 0.013817f, 0.015625f,
+ 0.018784f, 0.021927f, 0.026260f, 0.031677f, 0.038879f, 0.048004f, 0.059845f, 0.076233f, 0.098633f, 0.130005f, 0.173950f, 0.233032f,
+ 0.311035f, 0.405518f, 0.507812f, 0.608887f, 0.698242f, 0.769531f, 0.826172f, 0.868164f, 0.899414f, 0.922852f, 0.976074f, 0.977539f,
+ 0.977539f, 0.977051f, 0.978027f, 0.978027f, 0.000000f, 0.000000f, 0.000117f, 0.000211f, 0.000326f, 0.000573f, 0.000574f, 0.000583f,
+ 0.000584f, 0.000659f, 0.000901f, 0.001014f, 0.001064f, 0.001033f, 0.001163f, 0.001234f, 0.001546f, 0.001585f, 0.001894f, 0.002085f,
+ 0.002361f, 0.002504f, 0.003023f, 0.003147f, 0.003580f, 0.004032f, 0.004314f, 0.004936f, 0.005215f, 0.006081f, 0.006725f, 0.007927f,
+ 0.008743f, 0.009918f, 0.011642f, 0.013367f, 0.015404f, 0.018219f, 0.021545f, 0.025787f, 0.031174f, 0.038361f, 0.047577f, 0.060425f,
+ 0.077881f, 0.102051f, 0.135376f, 0.182861f, 0.249023f, 0.333984f, 0.436035f, 0.542969f, 0.644043f, 0.730469f, 0.798340f, 0.848633f,
+ 0.886719f, 0.914062f, 0.973633f, 0.974609f, 0.975098f, 0.976074f, 0.975098f, 0.976074f, 0.000000f, 0.000000f, 0.000114f, 0.000112f,
+ 0.000271f, 0.000510f, 0.000450f, 0.000565f, 0.000572f, 0.000581f, 0.000654f, 0.000825f, 0.000954f, 0.001085f, 0.001050f, 0.001087f,
+ 0.001282f, 0.001547f, 0.001585f, 0.001825f, 0.002066f, 0.002182f, 0.002384f, 0.002659f, 0.003172f, 0.003357f, 0.003721f, 0.004238f,
+ 0.004505f, 0.005024f, 0.005878f, 0.006512f, 0.007324f, 0.008293f, 0.009201f, 0.011040f, 0.012993f, 0.015007f, 0.017639f, 0.020920f,
+ 0.025131f, 0.030899f, 0.038269f, 0.047760f, 0.061188f, 0.079651f, 0.105469f, 0.142944f, 0.195801f, 0.268799f, 0.363525f, 0.472168f,
+ 0.582520f, 0.683594f, 0.765137f, 0.826660f, 0.872070f, 0.905273f, 0.972168f, 0.973633f, 0.973145f, 0.973633f, 0.973633f, 0.973633f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000111f, 0.000224f, 0.000412f, 0.000494f, 0.000543f, 0.000561f, 0.000680f, 0.000665f, 0.000675f,
+ 0.000679f, 0.000797f, 0.000926f, 0.001122f, 0.001132f, 0.001207f, 0.001375f, 0.001606f, 0.001838f, 0.001963f, 0.002163f, 0.002314f,
+ 0.002480f, 0.002956f, 0.003189f, 0.003489f, 0.003744f, 0.004311f, 0.004749f, 0.005276f, 0.005867f, 0.006962f, 0.008186f, 0.008987f,
+ 0.010498f, 0.012283f, 0.014374f, 0.017075f, 0.020355f, 0.024719f, 0.030640f, 0.037720f, 0.048309f, 0.062134f, 0.082336f, 0.110840f,
+ 0.151978f, 0.212891f, 0.294922f, 0.399170f, 0.515137f, 0.628418f, 0.724609f, 0.799805f, 0.854980f, 0.894043f, 0.968750f, 0.970215f,
+ 0.970703f, 0.971191f, 0.970703f, 0.970703f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000228f, 0.000233f, 0.000436f, 0.000457f,
+ 0.000621f, 0.000546f, 0.000622f, 0.000633f, 0.000576f, 0.000644f, 0.000717f, 0.000909f, 0.000994f, 0.001127f, 0.001179f, 0.001267f,
+ 0.001513f, 0.001628f, 0.001742f, 0.001974f, 0.002111f, 0.002403f, 0.002810f, 0.003139f, 0.003231f, 0.003466f, 0.004021f, 0.004459f,
+ 0.004971f, 0.005581f, 0.006809f, 0.007568f, 0.008759f, 0.010002f, 0.011665f, 0.013847f, 0.016342f, 0.019714f, 0.024368f, 0.030106f,
+ 0.037811f, 0.048706f, 0.063843f, 0.085327f, 0.118042f, 0.164917f, 0.234131f, 0.328125f, 0.443359f, 0.565430f, 0.677246f, 0.767578f,
+ 0.833496f, 0.882812f, 0.965820f, 0.967285f, 0.967773f, 0.968262f, 0.967773f, 0.968262f, 0.000000f, 0.000000f, 0.000000f, 0.000214f,
+ 0.000210f, 0.000296f, 0.000309f, 0.000386f, 0.000462f, 0.000482f, 0.000525f, 0.000572f, 0.000525f, 0.000558f, 0.000689f, 0.000685f,
+ 0.000841f, 0.000934f, 0.001008f, 0.001182f, 0.001271f, 0.001412f, 0.001757f, 0.001787f, 0.001769f, 0.002110f, 0.002321f, 0.002331f,
+ 0.002737f, 0.002951f, 0.003189f, 0.003588f, 0.004253f, 0.004627f, 0.005505f, 0.006119f, 0.006969f, 0.008018f, 0.009583f, 0.010971f,
+ 0.013245f, 0.015915f, 0.019257f, 0.023651f, 0.030014f, 0.038086f, 0.049683f, 0.066406f, 0.091125f, 0.127441f, 0.182617f, 0.262939f,
+ 0.370605f, 0.497070f, 0.623047f, 0.729004f, 0.810547f, 0.867188f, 0.962891f, 0.963867f, 0.964844f, 0.964844f, 0.964355f, 0.964355f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000200f, 0.000215f, 0.000229f, 0.000319f, 0.000330f, 0.000411f, 0.000491f, 0.000527f,
+ 0.000547f, 0.000560f, 0.000634f, 0.000648f, 0.000716f, 0.000778f, 0.000855f, 0.000998f, 0.001182f, 0.001111f, 0.001274f, 0.001625f,
+ 0.001584f, 0.001559f, 0.001864f, 0.002037f, 0.002296f, 0.002438f, 0.002600f, 0.002993f, 0.003290f, 0.003801f, 0.004467f, 0.005085f,
+ 0.005508f, 0.006519f, 0.007645f, 0.008743f, 0.010757f, 0.012558f, 0.014946f, 0.018661f, 0.023422f, 0.029556f, 0.038574f, 0.050964f,
+ 0.069702f, 0.097351f, 0.140015f, 0.205566f, 0.301025f, 0.424561f, 0.559082f, 0.683594f, 0.781250f, 0.852051f, 0.958496f, 0.960449f,
+ 0.960938f, 0.960938f, 0.960938f, 0.960449f, 0.000000f, 0.000000f, 0.000122f, 0.000122f, 0.000122f, 0.000194f, 0.000214f, 0.000251f,
+ 0.000302f, 0.000365f, 0.000370f, 0.000429f, 0.000495f, 0.000521f, 0.000504f, 0.000547f, 0.000632f, 0.000656f, 0.000695f, 0.000795f,
+ 0.000922f, 0.001074f, 0.001125f, 0.001192f, 0.001166f, 0.001303f, 0.001555f, 0.001575f, 0.001763f, 0.001970f, 0.002232f, 0.002560f,
+ 0.002657f, 0.003082f, 0.003559f, 0.003799f, 0.004620f, 0.005241f, 0.006081f, 0.007103f, 0.008385f, 0.009796f, 0.012192f, 0.014702f,
+ 0.018234f, 0.022934f, 0.029556f, 0.039307f, 0.053009f, 0.073547f, 0.106628f, 0.157715f, 0.237793f, 0.351318f, 0.490479f, 0.629883f,
+ 0.746094f, 0.832031f, 0.954590f, 0.956055f, 0.956055f, 0.957031f, 0.956543f, 0.956055f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000121f, 0.000146f, 0.000191f, 0.000200f, 0.000255f, 0.000232f, 0.000252f, 0.000359f, 0.000291f, 0.000342f, 0.000406f, 0.000498f,
+ 0.000520f, 0.000533f, 0.000632f, 0.000605f, 0.000689f, 0.000768f, 0.000908f, 0.001013f, 0.001087f, 0.001030f, 0.001211f, 0.001318f,
+ 0.001497f, 0.001609f, 0.001753f, 0.001957f, 0.002234f, 0.002352f, 0.002663f, 0.003040f, 0.003635f, 0.004082f, 0.004723f, 0.005516f,
+ 0.006367f, 0.007675f, 0.009224f, 0.011360f, 0.013695f, 0.017868f, 0.022598f, 0.029724f, 0.040222f, 0.055542f, 0.080078f, 0.119202f,
+ 0.182617f, 0.281738f, 0.417725f, 0.568848f, 0.705566f, 0.807129f, 0.948730f, 0.951172f, 0.951172f, 0.951172f, 0.951660f, 0.951660f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000203f, 0.000186f, 0.000184f, 0.000321f,
+ 0.000231f, 0.000337f, 0.000359f, 0.000430f, 0.000455f, 0.000531f, 0.000502f, 0.000517f, 0.000728f, 0.000643f, 0.000673f, 0.000816f,
+ 0.000930f, 0.000991f, 0.001028f, 0.001161f, 0.001284f, 0.001369f, 0.001474f, 0.001719f, 0.001781f, 0.001883f, 0.002258f, 0.002518f,
+ 0.002831f, 0.003201f, 0.003744f, 0.004349f, 0.005127f, 0.006130f, 0.007210f, 0.008423f, 0.010696f, 0.013405f, 0.017136f, 0.022522f,
+ 0.030029f, 0.041321f, 0.059631f, 0.089050f, 0.138062f, 0.218994f, 0.343750f, 0.500488f, 0.657227f, 0.780762f, 0.943848f, 0.945312f,
+ 0.945312f, 0.945801f, 0.945801f, 0.946289f, 0.000000f, 0.000000f, 0.000122f, 0.000121f, 0.000121f, 0.000121f, 0.000121f, 0.000120f,
+ 0.000118f, 0.000137f, 0.000139f, 0.000241f, 0.000202f, 0.000304f, 0.000313f, 0.000332f, 0.000357f, 0.000420f, 0.000435f, 0.000463f,
+ 0.000645f, 0.000544f, 0.000700f, 0.000717f, 0.000669f, 0.000834f, 0.000865f, 0.000916f, 0.001109f, 0.001193f, 0.001246f, 0.001300f,
+ 0.001488f, 0.001538f, 0.001806f, 0.001929f, 0.002001f, 0.002462f, 0.002666f, 0.003260f, 0.003904f, 0.004364f, 0.005325f, 0.006306f,
+ 0.008041f, 0.009720f, 0.012718f, 0.016525f, 0.022217f, 0.030579f, 0.043854f, 0.065247f, 0.101929f, 0.166016f, 0.273193f, 0.428223f,
+ 0.600586f, 0.748047f, 0.936523f, 0.938477f, 0.938965f, 0.939453f, 0.938965f, 0.938965f, 0.000000f, 0.000122f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000114f, 0.000102f, 0.000090f, 0.000096f, 0.000131f, 0.000245f, 0.000276f, 0.000257f,
+ 0.000307f, 0.000316f, 0.000322f, 0.000373f, 0.000411f, 0.000440f, 0.000433f, 0.000650f, 0.000578f, 0.000704f, 0.000746f, 0.000723f,
+ 0.000819f, 0.000756f, 0.000758f, 0.000878f, 0.001009f, 0.001270f, 0.001399f, 0.001530f, 0.001798f, 0.001803f, 0.002151f, 0.002317f,
+ 0.002728f, 0.003222f, 0.003782f, 0.004612f, 0.005951f, 0.006985f, 0.009308f, 0.011955f, 0.016052f, 0.022324f, 0.031525f, 0.047272f,
+ 0.073853f, 0.122192f, 0.209717f, 0.352783f, 0.537109f, 0.709473f, 0.928223f, 0.930664f, 0.931152f, 0.930664f, 0.931641f, 0.931152f,
+ 0.000000f, 0.000000f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000120f, 0.000119f, 0.000119f, 0.000111f, 0.000100f, 0.000139f,
+ 0.000082f, 0.000154f, 0.000121f, 0.000216f, 0.000147f, 0.000271f, 0.000288f, 0.000298f, 0.000386f, 0.000463f, 0.000370f, 0.000485f,
+ 0.000555f, 0.000530f, 0.000578f, 0.000574f, 0.000612f, 0.000712f, 0.000776f, 0.000716f, 0.000931f, 0.000831f, 0.000967f, 0.001154f,
+ 0.001176f, 0.001284f, 0.001497f, 0.001884f, 0.002270f, 0.002415f, 0.002947f, 0.003412f, 0.004032f, 0.005066f, 0.006485f, 0.008400f,
+ 0.011215f, 0.015404f, 0.022079f, 0.033264f, 0.052124f, 0.087646f, 0.155029f, 0.279297f, 0.465820f, 0.664062f, 0.918945f, 0.921387f,
+ 0.921875f, 0.922363f, 0.922363f, 0.921875f, 0.000000f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000119f, 0.000119f, 0.000119f,
+ 0.000118f, 0.000118f, 0.000110f, 0.000100f, 0.000091f, 0.000082f, 0.000075f, 0.000095f, 0.000166f, 0.000113f, 0.000163f, 0.000248f,
+ 0.000258f, 0.000277f, 0.000336f, 0.000301f, 0.000445f, 0.000495f, 0.000473f, 0.000505f, 0.000494f, 0.000470f, 0.000584f, 0.000752f,
+ 0.000821f, 0.000814f, 0.000845f, 0.000807f, 0.000932f, 0.000996f, 0.001380f, 0.001481f, 0.001507f, 0.001757f, 0.002146f, 0.002443f,
+ 0.002869f, 0.003546f, 0.004559f, 0.005878f, 0.007561f, 0.010475f, 0.015320f, 0.022675f, 0.036133f, 0.060883f, 0.110352f, 0.211670f,
+ 0.389160f, 0.610352f, 0.908691f, 0.909180f, 0.910645f, 0.912109f, 0.909668f, 0.910156f, 0.000000f, 0.000121f, 0.000120f, 0.000119f,
+ 0.000119f, 0.000118f, 0.000118f, 0.000117f, 0.000117f, 0.000117f, 0.000116f, 0.000110f, 0.000100f, 0.000099f, 0.000083f, 0.000077f,
+ 0.000071f, 0.000081f, 0.000087f, 0.000166f, 0.000177f, 0.000233f, 0.000238f, 0.000273f, 0.000325f, 0.000357f, 0.000292f, 0.000406f,
+ 0.000418f, 0.000440f, 0.000428f, 0.000568f, 0.000459f, 0.000628f, 0.000678f, 0.000688f, 0.000647f, 0.000830f, 0.000925f, 0.001111f,
+ 0.001011f, 0.001420f, 0.001504f, 0.001771f, 0.001997f, 0.002495f, 0.003147f, 0.003944f, 0.005077f, 0.006958f, 0.010040f, 0.015053f,
+ 0.023727f, 0.040680f, 0.075989f, 0.153076f, 0.312012f, 0.547363f, 0.894531f, 0.897461f, 0.897949f, 0.897949f, 0.897949f, 0.898438f,
+ 0.000000f, 0.000000f, 0.000119f, 0.000118f, 0.000118f, 0.000117f, 0.000116f, 0.000116f, 0.000115f, 0.000115f, 0.000114f, 0.000114f,
+ 0.000111f, 0.000101f, 0.000093f, 0.000086f, 0.000079f, 0.000095f, 0.000095f, 0.000090f, 0.000117f, 0.000109f, 0.000158f, 0.000199f,
+ 0.000207f, 0.000223f, 0.000286f, 0.000288f, 0.000267f, 0.000347f, 0.000368f, 0.000450f, 0.000377f, 0.000460f, 0.000504f, 0.000498f,
+ 0.000494f, 0.000616f, 0.000632f, 0.000699f, 0.000755f, 0.000938f, 0.000978f, 0.001222f, 0.001355f, 0.001673f, 0.002016f, 0.002539f,
+ 0.003258f, 0.004410f, 0.006332f, 0.009285f, 0.014847f, 0.025864f, 0.049042f, 0.104736f, 0.236572f, 0.477295f, 0.879395f, 0.881348f,
+ 0.882324f, 0.881836f, 0.882324f, 0.882324f, 0.000000f, 0.000119f, 0.000118f, 0.000116f, 0.000115f, 0.000114f, 0.000114f, 0.000113f,
+ 0.000112f, 0.000112f, 0.000111f, 0.000111f, 0.000110f, 0.000110f, 0.000103f, 0.000095f, 0.000088f, 0.000081f, 0.000076f, 0.000070f,
+ 0.000065f, 0.000100f, 0.000104f, 0.000099f, 0.000120f, 0.000145f, 0.000190f, 0.000204f, 0.000213f, 0.000230f, 0.000241f, 0.000279f,
+ 0.000325f, 0.000322f, 0.000328f, 0.000381f, 0.000351f, 0.000466f, 0.000452f, 0.000516f, 0.000591f, 0.000622f, 0.000733f, 0.000882f,
+ 0.000895f, 0.001092f, 0.001456f, 0.001765f, 0.002069f, 0.002821f, 0.003851f, 0.005558f, 0.008865f, 0.015579f, 0.029999f, 0.066895f,
+ 0.167480f, 0.400391f, 0.860352f, 0.862793f, 0.863281f, 0.864258f, 0.863281f, 0.863770f, 0.000119f, 0.000114f, 0.000113f, 0.000113f,
+ 0.000111f, 0.000110f, 0.000109f, 0.000109f, 0.000108f, 0.000107f, 0.000107f, 0.000107f, 0.000106f, 0.000105f, 0.000106f, 0.000105f,
+ 0.000098f, 0.000090f, 0.000084f, 0.000078f, 0.000073f, 0.000068f, 0.000063f, 0.000063f, 0.000066f, 0.000053f, 0.000080f, 0.000107f,
+ 0.000126f, 0.000150f, 0.000188f, 0.000187f, 0.000206f, 0.000205f, 0.000235f, 0.000242f, 0.000277f, 0.000340f, 0.000323f, 0.000308f,
+ 0.000417f, 0.000411f, 0.000445f, 0.000536f, 0.000622f, 0.000673f, 0.000887f, 0.000985f, 0.001289f, 0.001623f, 0.002337f, 0.003241f,
+ 0.004929f, 0.008560f, 0.016739f, 0.039307f, 0.109619f, 0.317383f, 0.837402f, 0.840332f, 0.841309f, 0.840820f, 0.840820f, 0.841309f,
+ 0.000000f, 0.000106f, 0.000099f, 0.000104f, 0.000102f, 0.000101f, 0.000100f, 0.000101f, 0.000101f, 0.000100f, 0.000099f, 0.000100f,
+ 0.000099f, 0.000099f, 0.000099f, 0.000098f, 0.000098f, 0.000098f, 0.000093f, 0.000086f, 0.000080f, 0.000075f, 0.000070f, 0.000065f,
+ 0.000061f, 0.000057f, 0.000059f, 0.000054f, 0.000061f, 0.000080f, 0.000087f, 0.000101f, 0.000136f, 0.000147f, 0.000163f, 0.000171f,
+ 0.000179f, 0.000205f, 0.000223f, 0.000237f, 0.000281f, 0.000272f, 0.000299f, 0.000364f, 0.000373f, 0.000448f, 0.000507f, 0.000643f,
+ 0.000801f, 0.001000f, 0.001276f, 0.001765f, 0.002712f, 0.004585f, 0.008492f, 0.020462f, 0.063721f, 0.233643f, 0.811035f, 0.813477f,
+ 0.814453f, 0.813965f, 0.813965f, 0.814453f, 0.000000f, 0.000057f, 0.000085f, 0.000085f, 0.000083f, 0.000085f, 0.000087f, 0.000086f,
+ 0.000087f, 0.000087f, 0.000086f, 0.000087f, 0.000087f, 0.000086f, 0.000087f, 0.000087f, 0.000088f, 0.000086f, 0.000088f, 0.000087f,
+ 0.000087f, 0.000081f, 0.000076f, 0.000071f, 0.000067f, 0.000063f, 0.000058f, 0.000055f, 0.000051f, 0.000048f, 0.000046f, 0.000042f,
+ 0.000051f, 0.000063f, 0.000081f, 0.000101f, 0.000122f, 0.000137f, 0.000147f, 0.000143f, 0.000157f, 0.000183f, 0.000205f, 0.000188f,
+ 0.000196f, 0.000249f, 0.000310f, 0.000329f, 0.000413f, 0.000534f, 0.000679f, 0.000944f, 0.001365f, 0.002199f, 0.004150f, 0.009369f,
+ 0.031677f, 0.153564f, 0.779297f, 0.781250f, 0.782227f, 0.782715f, 0.781738f, 0.781250f, 0.000000f, 0.000000f, 0.000000f, 0.000009f,
+ 0.000030f, 0.000048f, 0.000051f, 0.000054f, 0.000055f, 0.000059f, 0.000060f, 0.000065f, 0.000065f, 0.000066f, 0.000068f, 0.000068f,
+ 0.000070f, 0.000070f, 0.000071f, 0.000071f, 0.000072f, 0.000073f, 0.000073f, 0.000073f, 0.000071f, 0.000066f, 0.000062f, 0.000058f,
+ 0.000055f, 0.000051f, 0.000048f, 0.000045f, 0.000042f, 0.000039f, 0.000044f, 0.000036f, 0.000046f, 0.000056f, 0.000067f, 0.000085f,
+ 0.000099f, 0.000108f, 0.000107f, 0.000113f, 0.000139f, 0.000144f, 0.000165f, 0.000169f, 0.000196f, 0.000266f, 0.000311f, 0.000426f,
+ 0.000598f, 0.000948f, 0.001744f, 0.003975f, 0.012856f, 0.084351f, 0.739746f, 0.743164f, 0.743652f, 0.743652f, 0.743652f, 0.743164f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000012f, 0.000012f, 0.000020f,
+ 0.000028f, 0.000030f, 0.000033f, 0.000034f, 0.000041f, 0.000041f, 0.000045f, 0.000047f, 0.000048f, 0.000049f, 0.000051f, 0.000052f,
+ 0.000054f, 0.000054f, 0.000056f, 0.000057f, 0.000056f, 0.000052f, 0.000049f, 0.000046f, 0.000043f, 0.000041f, 0.000038f, 0.000035f,
+ 0.000033f, 0.000031f, 0.000029f, 0.000029f, 0.000036f, 0.000055f, 0.000048f, 0.000067f, 0.000067f, 0.000073f, 0.000075f, 0.000097f,
+ 0.000085f, 0.000111f, 0.000137f, 0.000191f, 0.000233f, 0.000371f, 0.000609f, 0.001319f, 0.004341f, 0.033844f, 0.696289f, 0.698730f,
+ 0.699219f, 0.698242f, 0.698730f, 0.698730f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000003f, 0.000007f,
+ 0.000009f, 0.000012f, 0.000015f, 0.000020f, 0.000022f, 0.000023f, 0.000026f, 0.000029f, 0.000030f, 0.000032f, 0.000033f, 0.000035f,
+ 0.000037f, 0.000037f, 0.000036f, 0.000034f, 0.000032f, 0.000030f, 0.000028f, 0.000026f, 0.000024f, 0.000022f, 0.000021f, 0.000019f,
+ 0.000024f, 0.000024f, 0.000029f, 0.000037f, 0.000043f, 0.000046f, 0.000059f, 0.000058f, 0.000075f, 0.000095f, 0.000160f, 0.000306f,
+ 0.001006f, 0.008865f, 0.643066f, 0.647461f, 0.647949f, 0.647461f, 0.647949f, 0.648438f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000003f, 0.000005f, 0.000007f, 0.000010f, 0.000012f, 0.000013f, 0.000015f, 0.000017f,
+ 0.000019f, 0.000020f, 0.000018f, 0.000017f, 0.000015f, 0.000014f, 0.000013f, 0.000012f, 0.000010f, 0.000012f, 0.000014f, 0.000018f,
+ 0.000018f, 0.000025f, 0.000028f, 0.000045f, 0.000110f, 0.001030f, 0.586914f, 0.589844f, 0.590820f, 0.591309f, 0.591309f, 0.590820f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000002f, 0.000004f, 0.000005f, 0.000004f, 0.000004f, 0.000003f, 0.000003f, 0.000004f, 0.000009f, 0.527344f, 0.529785f,
+ 0.529785f, 0.530273f, 0.530762f, 0.530762f,
+ },
+ {
+ 0.135132f, 0.377441f, 0.544434f, 0.653320f, 0.724609f, 0.773926f, 0.811035f, 0.838867f, 0.860840f, 0.876465f, 0.891113f, 0.902832f,
+ 0.912109f, 0.920898f, 0.928223f, 0.934082f, 0.938965f, 0.943848f, 0.948242f, 0.952637f, 0.955566f, 0.958984f, 0.961914f, 0.964844f,
+ 0.966797f, 0.969238f, 0.971191f, 0.973145f, 0.975098f, 0.976562f, 0.978027f, 0.979492f, 0.980469f, 0.982422f, 0.983398f, 0.984863f,
+ 0.985840f, 0.986328f, 0.987793f, 0.988770f, 0.989746f, 0.989746f, 0.990234f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994141f,
+ 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999512f, 0.999512f, 0.999512f,
+ 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.044891f, 0.163330f, 0.306885f, 0.444336f, 0.559570f, 0.645020f, 0.710938f, 0.760742f,
+ 0.797852f, 0.827148f, 0.850098f, 0.868652f, 0.883789f, 0.895996f, 0.907227f, 0.916016f, 0.923340f, 0.930176f, 0.936523f, 0.941406f,
+ 0.946777f, 0.950684f, 0.954102f, 0.957031f, 0.960938f, 0.963379f, 0.965820f, 0.968262f, 0.970703f, 0.972168f, 0.974609f, 0.976562f,
+ 0.977539f, 0.979492f, 0.980469f, 0.981934f, 0.982910f, 0.984375f, 0.985840f, 0.986816f, 0.987793f, 0.988770f, 0.988770f, 0.990234f,
+ 0.991211f, 0.991699f, 0.992676f, 0.993164f, 0.993164f, 0.994141f, 0.995605f, 0.995605f, 0.996094f, 0.996582f, 0.997070f, 0.997559f,
+ 0.998047f, 0.998535f, 0.999512f, 0.999512f, 0.999512f, 0.999023f, 0.999023f, 0.999023f, 0.020325f, 0.077820f, 0.158936f, 0.260498f,
+ 0.372314f, 0.479736f, 0.572754f, 0.648438f, 0.707520f, 0.754883f, 0.791016f, 0.820312f, 0.843750f, 0.862793f, 0.878906f, 0.891602f,
+ 0.903320f, 0.912598f, 0.920898f, 0.928223f, 0.933594f, 0.939941f, 0.944824f, 0.949219f, 0.952637f, 0.956543f, 0.959961f, 0.962402f,
+ 0.965332f, 0.967773f, 0.970215f, 0.971680f, 0.974121f, 0.976074f, 0.977539f, 0.979004f, 0.980957f, 0.981445f, 0.983398f, 0.984375f,
+ 0.985352f, 0.986328f, 0.987793f, 0.988770f, 0.989746f, 0.990234f, 0.991211f, 0.992188f, 0.992676f, 0.993164f, 0.994141f, 0.994629f,
+ 0.995605f, 0.996094f, 0.996582f, 0.996582f, 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.999023f, 0.998535f, 0.998535f,
+ 0.012032f, 0.042908f, 0.088196f, 0.149292f, 0.228027f, 0.319824f, 0.415527f, 0.506348f, 0.586914f, 0.653809f, 0.709473f, 0.752441f,
+ 0.787598f, 0.817383f, 0.840820f, 0.860352f, 0.876465f, 0.889648f, 0.900879f, 0.910156f, 0.918945f, 0.926270f, 0.933105f, 0.938965f,
+ 0.944336f, 0.948730f, 0.952637f, 0.956055f, 0.958984f, 0.962402f, 0.965332f, 0.967773f, 0.970215f, 0.972656f, 0.974609f, 0.976562f,
+ 0.978027f, 0.979492f, 0.980957f, 0.982422f, 0.983887f, 0.984375f, 0.985352f, 0.986816f, 0.987793f, 0.988770f, 0.989746f, 0.990234f,
+ 0.991211f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.996094f, 0.996094f, 0.996582f, 0.997559f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.007637f, 0.026825f, 0.053436f, 0.090759f, 0.140137f, 0.203125f, 0.279053f, 0.363281f,
+ 0.449463f, 0.529785f, 0.601562f, 0.663574f, 0.713379f, 0.756348f, 0.789551f, 0.816895f, 0.840332f, 0.858887f, 0.875488f, 0.887695f,
+ 0.900391f, 0.909668f, 0.918945f, 0.926270f, 0.932617f, 0.938477f, 0.943848f, 0.948242f, 0.952148f, 0.955566f, 0.959473f, 0.962402f,
+ 0.965332f, 0.967773f, 0.970215f, 0.972168f, 0.974121f, 0.976562f, 0.978516f, 0.979492f, 0.980957f, 0.981934f, 0.984375f, 0.985352f,
+ 0.985840f, 0.987793f, 0.988281f, 0.989258f, 0.990723f, 0.991211f, 0.991699f, 0.992676f, 0.993652f, 0.994141f, 0.994629f, 0.995605f,
+ 0.996094f, 0.997070f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998535f, 0.998047f, 0.004784f, 0.018082f, 0.035400f, 0.058868f,
+ 0.089783f, 0.130981f, 0.183716f, 0.248047f, 0.321289f, 0.400391f, 0.478760f, 0.552734f, 0.617188f, 0.673828f, 0.720703f, 0.759766f,
+ 0.792480f, 0.818359f, 0.840820f, 0.859863f, 0.875000f, 0.888184f, 0.899902f, 0.910645f, 0.918945f, 0.926270f, 0.931641f, 0.938965f,
+ 0.943848f, 0.948242f, 0.952148f, 0.957031f, 0.959473f, 0.962891f, 0.965332f, 0.968262f, 0.970215f, 0.972656f, 0.975098f, 0.977051f,
+ 0.978516f, 0.979980f, 0.981445f, 0.982910f, 0.984863f, 0.985352f, 0.986328f, 0.987305f, 0.988770f, 0.989746f, 0.990723f, 0.991699f,
+ 0.992676f, 0.993164f, 0.994141f, 0.994629f, 0.995605f, 0.996094f, 0.998047f, 0.998535f, 0.998047f, 0.998047f, 0.998047f, 0.998047f,
+ 0.004044f, 0.012550f, 0.024628f, 0.040466f, 0.060760f, 0.087708f, 0.122742f, 0.167236f, 0.222534f, 0.287109f, 0.358643f, 0.432617f,
+ 0.506348f, 0.573242f, 0.632812f, 0.685059f, 0.728516f, 0.766602f, 0.797363f, 0.822266f, 0.843750f, 0.861328f, 0.877441f, 0.890625f,
+ 0.901367f, 0.910645f, 0.919434f, 0.926758f, 0.933105f, 0.940430f, 0.944824f, 0.948730f, 0.953125f, 0.957520f, 0.960449f, 0.963867f,
+ 0.966309f, 0.969238f, 0.970703f, 0.973633f, 0.976074f, 0.977539f, 0.979004f, 0.980469f, 0.982422f, 0.983398f, 0.984863f, 0.986816f,
+ 0.986816f, 0.988281f, 0.989746f, 0.990723f, 0.991211f, 0.992188f, 0.993164f, 0.994141f, 0.994629f, 0.995117f, 0.998047f, 0.998047f,
+ 0.998047f, 0.998047f, 0.998047f, 0.998047f, 0.002975f, 0.009315f, 0.017868f, 0.029129f, 0.043243f, 0.062012f, 0.084961f, 0.115540f,
+ 0.154419f, 0.201660f, 0.257812f, 0.322754f, 0.391846f, 0.463135f, 0.530762f, 0.594727f, 0.650391f, 0.698730f, 0.739258f, 0.773926f,
+ 0.803711f, 0.826660f, 0.847656f, 0.865723f, 0.879883f, 0.892090f, 0.903809f, 0.913086f, 0.921387f, 0.928223f, 0.935059f, 0.940918f,
+ 0.945801f, 0.950684f, 0.954102f, 0.958008f, 0.961426f, 0.964844f, 0.967285f, 0.970215f, 0.972168f, 0.974609f, 0.976074f, 0.978027f,
+ 0.979980f, 0.981934f, 0.983398f, 0.984375f, 0.985352f, 0.987305f, 0.988281f, 0.989258f, 0.990234f, 0.991211f, 0.992188f, 0.993164f,
+ 0.993652f, 0.994629f, 0.997559f, 0.998047f, 0.998047f, 0.997559f, 0.997559f, 0.997559f, 0.002329f, 0.007256f, 0.013611f, 0.021790f,
+ 0.032043f, 0.044617f, 0.061554f, 0.082336f, 0.108765f, 0.142578f, 0.184448f, 0.234375f, 0.292725f, 0.357422f, 0.424805f, 0.493164f,
+ 0.556641f, 0.615723f, 0.666504f, 0.711914f, 0.750977f, 0.782715f, 0.809570f, 0.832520f, 0.853516f, 0.868652f, 0.882812f, 0.895508f,
+ 0.905762f, 0.916016f, 0.923340f, 0.931152f, 0.936523f, 0.942383f, 0.947266f, 0.951172f, 0.956055f, 0.958984f, 0.962402f, 0.965820f,
+ 0.968750f, 0.971191f, 0.973633f, 0.975586f, 0.977539f, 0.979980f, 0.980957f, 0.982422f, 0.983887f, 0.985352f, 0.985840f, 0.988281f,
+ 0.989746f, 0.990234f, 0.991211f, 0.991699f, 0.993164f, 0.993652f, 0.997070f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f,
+ 0.001871f, 0.006084f, 0.010963f, 0.016953f, 0.024277f, 0.033722f, 0.046234f, 0.060669f, 0.079224f, 0.103638f, 0.132812f, 0.169678f,
+ 0.214478f, 0.267090f, 0.326172f, 0.390137f, 0.456543f, 0.519531f, 0.581543f, 0.636230f, 0.685547f, 0.726562f, 0.762207f, 0.792969f,
+ 0.818359f, 0.839844f, 0.858398f, 0.874023f, 0.887695f, 0.898926f, 0.909668f, 0.918945f, 0.926270f, 0.933105f, 0.938965f, 0.944336f,
+ 0.949219f, 0.953613f, 0.958008f, 0.961426f, 0.964844f, 0.967773f, 0.969727f, 0.972168f, 0.974609f, 0.976074f, 0.979004f, 0.979980f,
+ 0.981934f, 0.983887f, 0.985352f, 0.986328f, 0.987793f, 0.989746f, 0.989746f, 0.990723f, 0.991211f, 0.992676f, 0.996582f, 0.997070f,
+ 0.997559f, 0.997070f, 0.997070f, 0.997070f, 0.001322f, 0.004795f, 0.008530f, 0.013504f, 0.018921f, 0.026154f, 0.035065f, 0.045807f,
+ 0.059662f, 0.076416f, 0.098267f, 0.124512f, 0.157715f, 0.197388f, 0.244873f, 0.299805f, 0.359619f, 0.423096f, 0.487549f, 0.549316f,
+ 0.605957f, 0.657715f, 0.703125f, 0.741211f, 0.774902f, 0.802734f, 0.827148f, 0.847656f, 0.865234f, 0.879883f, 0.893066f, 0.903320f,
+ 0.913086f, 0.920898f, 0.929199f, 0.935547f, 0.941406f, 0.947266f, 0.951172f, 0.956055f, 0.959473f, 0.962891f, 0.965332f, 0.969238f,
+ 0.971191f, 0.974121f, 0.976562f, 0.977539f, 0.979980f, 0.981445f, 0.982910f, 0.984863f, 0.986328f, 0.988281f, 0.988281f, 0.989746f,
+ 0.990723f, 0.991699f, 0.996582f, 0.996582f, 0.997070f, 0.997070f, 0.997070f, 0.996582f, 0.001077f, 0.003971f, 0.006985f, 0.010750f,
+ 0.015579f, 0.020920f, 0.027420f, 0.035522f, 0.045776f, 0.058228f, 0.074097f, 0.093140f, 0.117310f, 0.146851f, 0.182495f, 0.225952f,
+ 0.276611f, 0.332764f, 0.394287f, 0.456543f, 0.518555f, 0.577637f, 0.630371f, 0.679199f, 0.720703f, 0.756836f, 0.787598f, 0.813477f,
+ 0.836426f, 0.855469f, 0.872070f, 0.885742f, 0.897949f, 0.908203f, 0.917480f, 0.925293f, 0.933105f, 0.939453f, 0.944336f, 0.949219f,
+ 0.954590f, 0.957520f, 0.961426f, 0.964844f, 0.968262f, 0.970703f, 0.974121f, 0.975586f, 0.978027f, 0.979492f, 0.981445f, 0.983398f,
+ 0.984863f, 0.986328f, 0.987793f, 0.988770f, 0.989746f, 0.991211f, 0.996094f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996582f,
+ 0.000954f, 0.003330f, 0.005733f, 0.008904f, 0.012505f, 0.016617f, 0.022446f, 0.028351f, 0.036041f, 0.045807f, 0.056854f, 0.071350f,
+ 0.088867f, 0.110596f, 0.137451f, 0.170654f, 0.209717f, 0.256592f, 0.309326f, 0.366943f, 0.427979f, 0.489502f, 0.549316f, 0.604980f,
+ 0.655762f, 0.700195f, 0.738770f, 0.772461f, 0.801270f, 0.825195f, 0.845703f, 0.864258f, 0.879395f, 0.893066f, 0.903809f, 0.914062f,
+ 0.922363f, 0.929688f, 0.936523f, 0.942871f, 0.947266f, 0.952148f, 0.956055f, 0.960449f, 0.963867f, 0.966797f, 0.969727f, 0.972656f,
+ 0.975586f, 0.976562f, 0.979004f, 0.981445f, 0.982910f, 0.984375f, 0.985840f, 0.986816f, 0.988770f, 0.989746f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996094f, 0.996094f, 0.000949f, 0.002804f, 0.004730f, 0.007236f, 0.010384f, 0.014160f, 0.018478f, 0.023102f,
+ 0.028992f, 0.036346f, 0.044647f, 0.055542f, 0.068481f, 0.085144f, 0.105286f, 0.130005f, 0.159668f, 0.195557f, 0.238647f, 0.287842f,
+ 0.343018f, 0.402588f, 0.463135f, 0.522949f, 0.580566f, 0.632812f, 0.680664f, 0.721680f, 0.757812f, 0.788574f, 0.814453f, 0.836914f,
+ 0.856934f, 0.872070f, 0.887207f, 0.899414f, 0.909668f, 0.918945f, 0.926758f, 0.933594f, 0.940430f, 0.946289f, 0.950684f, 0.954590f,
+ 0.959473f, 0.963379f, 0.966797f, 0.969238f, 0.972168f, 0.975098f, 0.977051f, 0.979492f, 0.980957f, 0.982910f, 0.984375f, 0.986328f,
+ 0.987793f, 0.988770f, 0.995117f, 0.996094f, 0.995605f, 0.996094f, 0.996094f, 0.995605f, 0.000828f, 0.002361f, 0.004116f, 0.006119f,
+ 0.008797f, 0.011391f, 0.014854f, 0.018890f, 0.023666f, 0.029083f, 0.036011f, 0.044434f, 0.053986f, 0.066589f, 0.081543f, 0.100159f,
+ 0.122314f, 0.149536f, 0.183350f, 0.222900f, 0.269043f, 0.321533f, 0.378418f, 0.438477f, 0.499023f, 0.556641f, 0.611328f, 0.661133f,
+ 0.703613f, 0.742188f, 0.775391f, 0.804199f, 0.828613f, 0.849121f, 0.866211f, 0.881348f, 0.894043f, 0.905762f, 0.916016f, 0.924316f,
+ 0.931641f, 0.938477f, 0.944336f, 0.949707f, 0.954590f, 0.958496f, 0.962402f, 0.966309f, 0.969238f, 0.972168f, 0.974121f, 0.977051f,
+ 0.979004f, 0.980957f, 0.982910f, 0.984863f, 0.985840f, 0.987793f, 0.995117f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.995605f,
+ 0.000606f, 0.001948f, 0.003483f, 0.005394f, 0.007290f, 0.009735f, 0.012352f, 0.015747f, 0.019485f, 0.023788f, 0.029358f, 0.035706f,
+ 0.043732f, 0.053162f, 0.064331f, 0.077942f, 0.094971f, 0.116089f, 0.140991f, 0.172485f, 0.209473f, 0.252686f, 0.302002f, 0.356934f,
+ 0.415283f, 0.475830f, 0.534180f, 0.589844f, 0.641602f, 0.687500f, 0.728516f, 0.763184f, 0.792969f, 0.819336f, 0.841309f, 0.860840f,
+ 0.876953f, 0.890625f, 0.902344f, 0.913086f, 0.921875f, 0.930176f, 0.937012f, 0.943359f, 0.948242f, 0.954102f, 0.958008f, 0.961914f,
+ 0.965820f, 0.969238f, 0.971680f, 0.974609f, 0.977051f, 0.979004f, 0.981445f, 0.983398f, 0.984863f, 0.986816f, 0.994141f, 0.994629f,
+ 0.995117f, 0.995117f, 0.995117f, 0.994629f, 0.000672f, 0.001569f, 0.002895f, 0.004528f, 0.006180f, 0.008324f, 0.010864f, 0.013161f,
+ 0.016357f, 0.020096f, 0.024216f, 0.029327f, 0.035583f, 0.042664f, 0.051453f, 0.062073f, 0.075012f, 0.091125f, 0.110291f, 0.134155f,
+ 0.162476f, 0.197266f, 0.238037f, 0.285156f, 0.337646f, 0.395020f, 0.454590f, 0.513672f, 0.570312f, 0.624023f, 0.672363f, 0.714844f,
+ 0.750977f, 0.783691f, 0.811035f, 0.834473f, 0.854004f, 0.872070f, 0.886230f, 0.899414f, 0.911133f, 0.918945f, 0.928223f, 0.936035f,
+ 0.942871f, 0.948242f, 0.953613f, 0.957031f, 0.961426f, 0.965820f, 0.968750f, 0.972168f, 0.974121f, 0.976562f, 0.979492f, 0.981445f,
+ 0.983398f, 0.985352f, 0.994141f, 0.994629f, 0.995117f, 0.995117f, 0.995117f, 0.994629f, 0.000413f, 0.001430f, 0.002577f, 0.004269f,
+ 0.005703f, 0.007137f, 0.008888f, 0.011124f, 0.013885f, 0.016891f, 0.020355f, 0.024384f, 0.029221f, 0.035217f, 0.041748f, 0.049988f,
+ 0.060059f, 0.072083f, 0.086914f, 0.105286f, 0.126953f, 0.154175f, 0.186523f, 0.224731f, 0.269287f, 0.320557f, 0.375732f, 0.434570f,
+ 0.493896f, 0.552246f, 0.606934f, 0.655762f, 0.701660f, 0.740723f, 0.774902f, 0.803711f, 0.827637f, 0.848633f, 0.867188f, 0.882812f,
+ 0.895996f, 0.908203f, 0.917969f, 0.926758f, 0.934570f, 0.941895f, 0.947266f, 0.952637f, 0.957520f, 0.960938f, 0.965820f, 0.968750f,
+ 0.971680f, 0.974609f, 0.977051f, 0.979980f, 0.981934f, 0.983887f, 0.993652f, 0.994629f, 0.994141f, 0.994141f, 0.994141f, 0.994141f,
+ 0.000240f, 0.001406f, 0.002373f, 0.003283f, 0.004620f, 0.006264f, 0.007744f, 0.009552f, 0.011711f, 0.014069f, 0.017273f, 0.020584f,
+ 0.024429f, 0.028946f, 0.034393f, 0.041046f, 0.048798f, 0.058289f, 0.070312f, 0.083618f, 0.100403f, 0.121338f, 0.146118f, 0.177002f,
+ 0.213257f, 0.255371f, 0.304443f, 0.358887f, 0.416504f, 0.476562f, 0.534668f, 0.590332f, 0.642090f, 0.688965f, 0.729492f, 0.766113f,
+ 0.796387f, 0.822754f, 0.844727f, 0.862305f, 0.880371f, 0.894043f, 0.905762f, 0.916992f, 0.926270f, 0.934082f, 0.940918f, 0.946777f,
+ 0.953125f, 0.956543f, 0.961426f, 0.964844f, 0.969238f, 0.972656f, 0.974609f, 0.977539f, 0.979980f, 0.982422f, 0.992676f, 0.994141f,
+ 0.993652f, 0.993652f, 0.993652f, 0.993652f, 0.000242f, 0.001257f, 0.001991f, 0.003138f, 0.004299f, 0.005302f, 0.006584f, 0.008308f,
+ 0.010048f, 0.012283f, 0.014526f, 0.017578f, 0.020340f, 0.023972f, 0.028671f, 0.033661f, 0.040161f, 0.047821f, 0.056213f, 0.067261f,
+ 0.080444f, 0.096191f, 0.115784f, 0.139771f, 0.168457f, 0.203125f, 0.243286f, 0.290527f, 0.343506f, 0.400879f, 0.459473f, 0.519043f,
+ 0.576172f, 0.629395f, 0.678223f, 0.721191f, 0.757324f, 0.789062f, 0.816895f, 0.839844f, 0.859863f, 0.877930f, 0.892578f, 0.904297f,
+ 0.915527f, 0.925293f, 0.933105f, 0.940430f, 0.946777f, 0.952148f, 0.957031f, 0.961914f, 0.965820f, 0.969238f, 0.973145f, 0.975586f,
+ 0.978516f, 0.980469f, 0.992188f, 0.993652f, 0.993164f, 0.993164f, 0.993652f, 0.993164f, 0.000434f, 0.001172f, 0.001865f, 0.002825f,
+ 0.003633f, 0.004757f, 0.005722f, 0.007175f, 0.009010f, 0.010651f, 0.012520f, 0.014412f, 0.017532f, 0.020599f, 0.024139f, 0.028488f,
+ 0.033356f, 0.039001f, 0.046295f, 0.054749f, 0.064758f, 0.077209f, 0.092834f, 0.111084f, 0.134033f, 0.160767f, 0.193604f, 0.233032f,
+ 0.278320f, 0.329590f, 0.386230f, 0.445068f, 0.504395f, 0.563477f, 0.617188f, 0.666504f, 0.711426f, 0.750000f, 0.783691f, 0.812500f,
+ 0.836426f, 0.857422f, 0.875488f, 0.891113f, 0.903809f, 0.915039f, 0.924805f, 0.933105f, 0.940430f, 0.947266f, 0.953125f, 0.958496f,
+ 0.962402f, 0.966309f, 0.969727f, 0.973145f, 0.976562f, 0.978516f, 0.991699f, 0.992188f, 0.992676f, 0.993164f, 0.993164f, 0.992676f,
+ 0.000358f, 0.000835f, 0.001738f, 0.002270f, 0.002996f, 0.004078f, 0.005157f, 0.006416f, 0.007904f, 0.009331f, 0.010826f, 0.012245f,
+ 0.014938f, 0.017303f, 0.020233f, 0.023926f, 0.027954f, 0.032715f, 0.038147f, 0.045166f, 0.053070f, 0.062561f, 0.074768f, 0.089661f,
+ 0.106689f, 0.128052f, 0.154175f, 0.185547f, 0.223022f, 0.266846f, 0.317383f, 0.373047f, 0.431152f, 0.491943f, 0.550293f, 0.606445f,
+ 0.658203f, 0.704102f, 0.744141f, 0.779297f, 0.809082f, 0.833984f, 0.855957f, 0.875000f, 0.889648f, 0.903320f, 0.915039f, 0.924805f,
+ 0.933594f, 0.940918f, 0.947754f, 0.954102f, 0.958984f, 0.962402f, 0.966797f, 0.970703f, 0.974121f, 0.977539f, 0.990723f, 0.992188f,
+ 0.992676f, 0.992676f, 0.992188f, 0.992676f, 0.000428f, 0.000789f, 0.001460f, 0.002172f, 0.002695f, 0.003561f, 0.004608f, 0.005848f,
+ 0.006886f, 0.007736f, 0.009560f, 0.011078f, 0.012817f, 0.015015f, 0.017563f, 0.020157f, 0.023666f, 0.027145f, 0.031891f, 0.037384f,
+ 0.044189f, 0.051788f, 0.061188f, 0.072327f, 0.085999f, 0.102966f, 0.123413f, 0.148071f, 0.178101f, 0.214478f, 0.256836f, 0.306396f,
+ 0.360840f, 0.419678f, 0.479736f, 0.540527f, 0.597656f, 0.649902f, 0.697754f, 0.738770f, 0.775391f, 0.805664f, 0.831543f, 0.854004f,
+ 0.873535f, 0.889160f, 0.902832f, 0.915039f, 0.925293f, 0.934082f, 0.941895f, 0.948730f, 0.954102f, 0.959961f, 0.963867f, 0.968262f,
+ 0.971680f, 0.975586f, 0.990723f, 0.991699f, 0.991699f, 0.991699f, 0.991699f, 0.991211f, 0.000237f, 0.000782f, 0.001245f, 0.001923f,
+ 0.002417f, 0.003225f, 0.004101f, 0.005062f, 0.005920f, 0.007030f, 0.008102f, 0.009743f, 0.011009f, 0.013054f, 0.015190f, 0.017380f,
+ 0.020126f, 0.023346f, 0.027161f, 0.031464f, 0.036316f, 0.042664f, 0.050110f, 0.058807f, 0.069946f, 0.083191f, 0.099121f, 0.118835f,
+ 0.142822f, 0.171997f, 0.206665f, 0.248413f, 0.296143f, 0.350586f, 0.408936f, 0.469727f, 0.530762f, 0.589844f, 0.643555f, 0.691895f,
+ 0.734375f, 0.772461f, 0.803223f, 0.830566f, 0.854492f, 0.873047f, 0.889648f, 0.903809f, 0.916016f, 0.926270f, 0.935059f, 0.943359f,
+ 0.949219f, 0.955566f, 0.960938f, 0.965332f, 0.969727f, 0.973145f, 0.989746f, 0.990723f, 0.990723f, 0.990723f, 0.991211f, 0.990723f,
+ 0.000243f, 0.000793f, 0.001210f, 0.001616f, 0.002260f, 0.003069f, 0.003649f, 0.004444f, 0.005322f, 0.006088f, 0.006954f, 0.008278f,
+ 0.009766f, 0.011139f, 0.012970f, 0.014908f, 0.016968f, 0.019897f, 0.023193f, 0.026962f, 0.030792f, 0.035522f, 0.041931f, 0.048920f,
+ 0.057404f, 0.067993f, 0.080383f, 0.095825f, 0.114929f, 0.137695f, 0.165771f, 0.199585f, 0.241089f, 0.287842f, 0.341553f, 0.400391f,
+ 0.462402f, 0.523438f, 0.583008f, 0.638184f, 0.687988f, 0.732422f, 0.770020f, 0.802246f, 0.830566f, 0.854004f, 0.873047f, 0.891113f,
+ 0.904785f, 0.916992f, 0.926758f, 0.936523f, 0.943848f, 0.951172f, 0.956543f, 0.961914f, 0.966797f, 0.971191f, 0.989258f, 0.990234f,
+ 0.990234f, 0.990234f, 0.990234f, 0.989746f, 0.000000f, 0.000484f, 0.000973f, 0.001453f, 0.001999f, 0.002689f, 0.003359f, 0.003864f,
+ 0.004726f, 0.005444f, 0.006516f, 0.007404f, 0.008461f, 0.009720f, 0.011261f, 0.012985f, 0.014908f, 0.017120f, 0.019699f, 0.022614f,
+ 0.026093f, 0.030228f, 0.034668f, 0.040619f, 0.047699f, 0.055756f, 0.066284f, 0.078308f, 0.092834f, 0.111328f, 0.133423f, 0.160889f,
+ 0.194214f, 0.233765f, 0.281006f, 0.334473f, 0.392822f, 0.455078f, 0.517090f, 0.578125f, 0.634766f, 0.686035f, 0.730957f, 0.768555f,
+ 0.803223f, 0.831055f, 0.854492f, 0.875488f, 0.892090f, 0.906250f, 0.918457f, 0.929688f, 0.937988f, 0.945801f, 0.952148f, 0.958496f,
+ 0.963867f, 0.968750f, 0.988281f, 0.989258f, 0.989746f, 0.989258f, 0.989746f, 0.989258f, 0.000241f, 0.000699f, 0.000835f, 0.001354f,
+ 0.002066f, 0.002405f, 0.003073f, 0.003466f, 0.003847f, 0.004868f, 0.005798f, 0.006325f, 0.007446f, 0.008553f, 0.009789f, 0.011375f,
+ 0.013031f, 0.014702f, 0.016937f, 0.019455f, 0.022171f, 0.025467f, 0.029541f, 0.034271f, 0.039734f, 0.046295f, 0.054291f, 0.063904f,
+ 0.075745f, 0.089966f, 0.107727f, 0.129395f, 0.156250f, 0.188965f, 0.228394f, 0.274658f, 0.327637f, 0.386963f, 0.449219f, 0.512695f,
+ 0.574707f, 0.632324f, 0.684570f, 0.730469f, 0.770508f, 0.804688f, 0.832520f, 0.857422f, 0.876953f, 0.893066f, 0.908691f, 0.920410f,
+ 0.931152f, 0.940430f, 0.947754f, 0.954590f, 0.960938f, 0.965820f, 0.986816f, 0.988770f, 0.988770f, 0.988770f, 0.988770f, 0.988770f,
+ 0.000122f, 0.000480f, 0.000793f, 0.001184f, 0.001847f, 0.002220f, 0.002459f, 0.003109f, 0.003740f, 0.004234f, 0.005127f, 0.005730f,
+ 0.006557f, 0.007458f, 0.008469f, 0.009911f, 0.011162f, 0.012848f, 0.014519f, 0.016693f, 0.019135f, 0.021820f, 0.025024f, 0.028931f,
+ 0.033508f, 0.038757f, 0.045135f, 0.052856f, 0.062042f, 0.073547f, 0.087646f, 0.104736f, 0.126099f, 0.152588f, 0.184570f, 0.223511f,
+ 0.269775f, 0.323242f, 0.382324f, 0.445801f, 0.510254f, 0.573242f, 0.631348f, 0.685059f, 0.731934f, 0.772461f, 0.806641f, 0.834961f,
+ 0.859375f, 0.879883f, 0.897461f, 0.911133f, 0.923828f, 0.933594f, 0.942383f, 0.950195f, 0.956055f, 0.962402f, 0.985840f, 0.987305f,
+ 0.987793f, 0.987793f, 0.988281f, 0.987793f, 0.000244f, 0.000471f, 0.000666f, 0.001267f, 0.001592f, 0.001838f, 0.002251f, 0.002855f,
+ 0.003225f, 0.003828f, 0.004372f, 0.005112f, 0.005695f, 0.006340f, 0.007534f, 0.008797f, 0.009895f, 0.011215f, 0.012604f, 0.014503f,
+ 0.016602f, 0.018738f, 0.021408f, 0.024567f, 0.028305f, 0.032654f, 0.037872f, 0.043732f, 0.051239f, 0.060669f, 0.071716f, 0.085510f,
+ 0.102356f, 0.123230f, 0.149170f, 0.180664f, 0.219849f, 0.265869f, 0.319092f, 0.379150f, 0.443604f, 0.508789f, 0.572754f, 0.633301f,
+ 0.686523f, 0.734863f, 0.775391f, 0.809570f, 0.838379f, 0.862305f, 0.883301f, 0.900391f, 0.914551f, 0.926270f, 0.937012f, 0.944824f,
+ 0.953125f, 0.959473f, 0.985352f, 0.986816f, 0.986816f, 0.986816f, 0.986816f, 0.986816f, 0.000242f, 0.000346f, 0.000827f, 0.001065f,
+ 0.001428f, 0.001572f, 0.001984f, 0.002367f, 0.002851f, 0.003277f, 0.003786f, 0.004501f, 0.005253f, 0.005955f, 0.006573f, 0.007736f,
+ 0.008659f, 0.009880f, 0.011177f, 0.012459f, 0.014153f, 0.016403f, 0.018173f, 0.020859f, 0.024017f, 0.027496f, 0.031708f, 0.036682f,
+ 0.042877f, 0.050446f, 0.059174f, 0.070068f, 0.083374f, 0.100159f, 0.120728f, 0.145874f, 0.177612f, 0.216187f, 0.262695f, 0.316650f,
+ 0.377686f, 0.443115f, 0.509766f, 0.575195f, 0.635742f, 0.691406f, 0.738281f, 0.779785f, 0.813965f, 0.843750f, 0.866699f, 0.887207f,
+ 0.904297f, 0.918945f, 0.930176f, 0.940918f, 0.948730f, 0.956055f, 0.984375f, 0.985840f, 0.985840f, 0.985840f, 0.986328f, 0.985840f,
+ 0.000242f, 0.000540f, 0.000708f, 0.000830f, 0.001143f, 0.001451f, 0.001861f, 0.002249f, 0.002661f, 0.003010f, 0.003435f, 0.003922f,
+ 0.004707f, 0.005165f, 0.005787f, 0.006840f, 0.007374f, 0.008545f, 0.009651f, 0.011147f, 0.012581f, 0.014084f, 0.015991f, 0.017899f,
+ 0.020325f, 0.023392f, 0.026978f, 0.031113f, 0.035919f, 0.042023f, 0.049103f, 0.057831f, 0.068420f, 0.081543f, 0.098145f, 0.118530f,
+ 0.143921f, 0.175293f, 0.213989f, 0.260742f, 0.316162f, 0.377441f, 0.444336f, 0.512207f, 0.579590f, 0.641113f, 0.696289f, 0.744629f,
+ 0.786621f, 0.820801f, 0.849609f, 0.872559f, 0.892578f, 0.908691f, 0.922363f, 0.934570f, 0.944336f, 0.951660f, 0.982910f, 0.984375f,
+ 0.984863f, 0.984863f, 0.985352f, 0.984863f, 0.000106f, 0.000477f, 0.000649f, 0.000901f, 0.001110f, 0.001206f, 0.001630f, 0.002121f,
+ 0.002192f, 0.002743f, 0.003128f, 0.003538f, 0.003941f, 0.004688f, 0.005276f, 0.005905f, 0.006546f, 0.007568f, 0.008461f, 0.009483f,
+ 0.010674f, 0.011864f, 0.013649f, 0.015549f, 0.017731f, 0.020111f, 0.023010f, 0.026199f, 0.030304f, 0.035278f, 0.040833f, 0.047821f,
+ 0.056580f, 0.066895f, 0.079895f, 0.096191f, 0.116760f, 0.141968f, 0.173584f, 0.212646f, 0.260498f, 0.316162f, 0.379883f, 0.447754f,
+ 0.517578f, 0.584961f, 0.647949f, 0.704102f, 0.752930f, 0.792969f, 0.827148f, 0.855957f, 0.877930f, 0.898438f, 0.914062f, 0.928223f,
+ 0.938965f, 0.948242f, 0.981445f, 0.983398f, 0.983887f, 0.983887f, 0.983887f, 0.983398f, 0.000208f, 0.000456f, 0.000582f, 0.000788f,
+ 0.001016f, 0.001428f, 0.001507f, 0.001769f, 0.002203f, 0.002525f, 0.002718f, 0.003187f, 0.003761f, 0.004238f, 0.004635f, 0.005348f,
+ 0.005901f, 0.006805f, 0.007500f, 0.008545f, 0.009270f, 0.010437f, 0.011742f, 0.013344f, 0.015198f, 0.017242f, 0.019516f, 0.022430f,
+ 0.025665f, 0.029922f, 0.034180f, 0.040161f, 0.046936f, 0.055420f, 0.065735f, 0.078552f, 0.094666f, 0.114563f, 0.140503f, 0.172485f,
+ 0.212646f, 0.260986f, 0.318359f, 0.383545f, 0.453125f, 0.524414f, 0.593750f, 0.656738f, 0.712891f, 0.761230f, 0.801270f, 0.835938f,
+ 0.862305f, 0.885742f, 0.904785f, 0.919922f, 0.933594f, 0.943359f, 0.980469f, 0.982422f, 0.982422f, 0.981934f, 0.982422f, 0.982422f,
+ 0.000170f, 0.000350f, 0.000583f, 0.000682f, 0.000845f, 0.001036f, 0.001265f, 0.001821f, 0.001953f, 0.002163f, 0.002525f, 0.002771f,
+ 0.003418f, 0.003729f, 0.004040f, 0.004871f, 0.005188f, 0.005726f, 0.006512f, 0.007130f, 0.008087f, 0.009018f, 0.010216f, 0.011490f,
+ 0.013084f, 0.014565f, 0.016891f, 0.019073f, 0.021851f, 0.025253f, 0.029022f, 0.033539f, 0.039124f, 0.045563f, 0.054230f, 0.064270f,
+ 0.077271f, 0.093323f, 0.113403f, 0.139648f, 0.172485f, 0.213379f, 0.262939f, 0.322266f, 0.389404f, 0.461426f, 0.534180f, 0.604492f,
+ 0.668457f, 0.724609f, 0.772461f, 0.812500f, 0.845703f, 0.872070f, 0.894043f, 0.911621f, 0.926758f, 0.938477f, 0.979004f, 0.980469f,
+ 0.980957f, 0.980957f, 0.980957f, 0.980957f, 0.000000f, 0.000332f, 0.000583f, 0.000583f, 0.000848f, 0.000959f, 0.001125f, 0.001425f,
+ 0.001810f, 0.001899f, 0.002300f, 0.002529f, 0.002996f, 0.003162f, 0.003607f, 0.004150f, 0.004761f, 0.005146f, 0.005791f, 0.006329f,
+ 0.007099f, 0.008110f, 0.008949f, 0.009941f, 0.011253f, 0.012756f, 0.014565f, 0.016434f, 0.018707f, 0.021271f, 0.024475f, 0.028290f,
+ 0.032745f, 0.037964f, 0.044769f, 0.052795f, 0.063416f, 0.076050f, 0.092102f, 0.113464f, 0.139526f, 0.172974f, 0.214600f, 0.266602f,
+ 0.327637f, 0.397461f, 0.471191f, 0.546387f, 0.617188f, 0.682129f, 0.737793f, 0.784668f, 0.823730f, 0.854980f, 0.881348f, 0.902344f,
+ 0.918945f, 0.933105f, 0.977539f, 0.979492f, 0.979492f, 0.979492f, 0.979492f, 0.979492f, 0.000000f, 0.000243f, 0.000553f, 0.000575f,
+ 0.000591f, 0.000798f, 0.000991f, 0.001234f, 0.001419f, 0.001812f, 0.001935f, 0.002186f, 0.002518f, 0.002975f, 0.003202f, 0.003614f,
+ 0.004047f, 0.004425f, 0.005013f, 0.005718f, 0.006172f, 0.007046f, 0.007740f, 0.008835f, 0.009819f, 0.011192f, 0.012444f, 0.014114f,
+ 0.015884f, 0.018204f, 0.020844f, 0.023392f, 0.027420f, 0.031921f, 0.037170f, 0.043610f, 0.052032f, 0.062408f, 0.075256f, 0.091675f,
+ 0.112610f, 0.140015f, 0.173950f, 0.217651f, 0.271973f, 0.335693f, 0.407715f, 0.484619f, 0.561035f, 0.633789f, 0.698242f, 0.752930f,
+ 0.798828f, 0.836426f, 0.867676f, 0.891602f, 0.911621f, 0.926270f, 0.975098f, 0.977539f, 0.978516f, 0.977539f, 0.977539f, 0.978027f,
+ 0.000121f, 0.000121f, 0.000241f, 0.000385f, 0.000684f, 0.000693f, 0.000932f, 0.001156f, 0.001410f, 0.001648f, 0.001893f, 0.002184f,
+ 0.002367f, 0.002579f, 0.002872f, 0.003319f, 0.003653f, 0.003922f, 0.004425f, 0.004925f, 0.005436f, 0.006180f, 0.006836f, 0.007645f,
+ 0.008278f, 0.009476f, 0.010788f, 0.012169f, 0.013695f, 0.015305f, 0.017319f, 0.020111f, 0.022858f, 0.026718f, 0.030975f, 0.036255f,
+ 0.042938f, 0.051270f, 0.061493f, 0.074768f, 0.091187f, 0.112976f, 0.140747f, 0.176392f, 0.222168f, 0.278809f, 0.345703f, 0.421387f,
+ 0.500488f, 0.578613f, 0.651855f, 0.715820f, 0.769531f, 0.813965f, 0.850586f, 0.878418f, 0.901855f, 0.920410f, 0.973633f, 0.975586f,
+ 0.976074f, 0.976562f, 0.976562f, 0.975098f, 0.000240f, 0.000120f, 0.000281f, 0.000333f, 0.000498f, 0.000680f, 0.000684f, 0.001083f,
+ 0.001312f, 0.001618f, 0.001606f, 0.001834f, 0.002087f, 0.002316f, 0.002735f, 0.002792f, 0.003084f, 0.003386f, 0.003944f, 0.004353f,
+ 0.004761f, 0.005390f, 0.005997f, 0.006615f, 0.007389f, 0.008324f, 0.008987f, 0.010284f, 0.011703f, 0.013382f, 0.014717f, 0.016953f,
+ 0.019424f, 0.022278f, 0.026047f, 0.030029f, 0.035492f, 0.042145f, 0.050446f, 0.060608f, 0.073975f, 0.091187f, 0.113831f, 0.142700f,
+ 0.180176f, 0.228271f, 0.288086f, 0.359131f, 0.437988f, 0.519531f, 0.600098f, 0.673340f, 0.735352f, 0.787598f, 0.830566f, 0.865234f,
+ 0.891602f, 0.913086f, 0.971680f, 0.974121f, 0.974121f, 0.974121f, 0.974121f, 0.974609f, 0.000000f, 0.000239f, 0.000236f, 0.000425f,
+ 0.000487f, 0.000608f, 0.000850f, 0.001012f, 0.001140f, 0.001260f, 0.001410f, 0.001640f, 0.001953f, 0.002003f, 0.002342f, 0.002434f,
+ 0.002686f, 0.002934f, 0.003305f, 0.003771f, 0.004169f, 0.004692f, 0.005028f, 0.005817f, 0.006371f, 0.007179f, 0.007919f, 0.008965f,
+ 0.009857f, 0.011261f, 0.012703f, 0.014229f, 0.016312f, 0.018494f, 0.021744f, 0.025024f, 0.029633f, 0.034790f, 0.041199f, 0.049561f,
+ 0.060242f, 0.073608f, 0.091675f, 0.114502f, 0.144897f, 0.185547f, 0.236328f, 0.300049f, 0.375732f, 0.458496f, 0.542969f, 0.624023f,
+ 0.696289f, 0.758301f, 0.808105f, 0.847656f, 0.879395f, 0.903809f, 0.968750f, 0.971191f, 0.972168f, 0.971680f, 0.972168f, 0.971680f,
+ 0.000000f, 0.000217f, 0.000235f, 0.000235f, 0.000321f, 0.000560f, 0.000588f, 0.000897f, 0.001034f, 0.001040f, 0.001246f, 0.001369f,
+ 0.001611f, 0.001692f, 0.001942f, 0.002153f, 0.002337f, 0.002638f, 0.002878f, 0.003330f, 0.003672f, 0.003986f, 0.004498f, 0.004826f,
+ 0.005535f, 0.006176f, 0.006561f, 0.007538f, 0.008362f, 0.009544f, 0.010612f, 0.011879f, 0.013794f, 0.015839f, 0.018326f, 0.020889f,
+ 0.024567f, 0.028625f, 0.033783f, 0.040527f, 0.049133f, 0.059998f, 0.073608f, 0.092041f, 0.116394f, 0.148682f, 0.191528f, 0.246582f,
+ 0.315186f, 0.395508f, 0.482910f, 0.570312f, 0.651367f, 0.722168f, 0.781738f, 0.828613f, 0.866211f, 0.895508f, 0.966797f, 0.968750f,
+ 0.969238f, 0.969727f, 0.969238f, 0.969238f, 0.000000f, 0.000108f, 0.000215f, 0.000346f, 0.000352f, 0.000501f, 0.000783f, 0.000828f,
+ 0.000954f, 0.000980f, 0.001130f, 0.001353f, 0.001429f, 0.001522f, 0.001690f, 0.001760f, 0.002172f, 0.002363f, 0.002522f, 0.002777f,
+ 0.003202f, 0.003550f, 0.004040f, 0.004364f, 0.004734f, 0.005192f, 0.005909f, 0.006271f, 0.007015f, 0.007957f, 0.008774f, 0.010185f,
+ 0.011681f, 0.013306f, 0.015327f, 0.017517f, 0.020264f, 0.023636f, 0.027740f, 0.033234f, 0.039856f, 0.048340f, 0.059387f, 0.074097f,
+ 0.093567f, 0.118896f, 0.153931f, 0.200073f, 0.260254f, 0.334473f, 0.420410f, 0.511719f, 0.601562f, 0.682129f, 0.750488f, 0.807617f,
+ 0.851074f, 0.884277f, 0.963867f, 0.966309f, 0.966797f, 0.966797f, 0.966797f, 0.966797f, 0.000000f, 0.000059f, 0.000292f, 0.000331f,
+ 0.000344f, 0.000613f, 0.000532f, 0.000703f, 0.000853f, 0.000915f, 0.000936f, 0.001102f, 0.001284f, 0.001430f, 0.001417f, 0.001475f,
+ 0.001791f, 0.001989f, 0.002161f, 0.002388f, 0.002775f, 0.003017f, 0.003357f, 0.003763f, 0.004124f, 0.004383f, 0.004917f, 0.005436f,
+ 0.005840f, 0.006733f, 0.007511f, 0.008667f, 0.009567f, 0.011032f, 0.012474f, 0.014610f, 0.016739f, 0.019379f, 0.022873f, 0.027252f,
+ 0.032410f, 0.039062f, 0.048065f, 0.059296f, 0.074646f, 0.094971f, 0.123108f, 0.161011f, 0.211426f, 0.277344f, 0.358154f, 0.450195f,
+ 0.545410f, 0.636230f, 0.715332f, 0.781250f, 0.832520f, 0.872070f, 0.960449f, 0.962402f, 0.963867f, 0.963379f, 0.962891f, 0.963379f,
+ 0.000000f, 0.000000f, 0.000098f, 0.000301f, 0.000315f, 0.000566f, 0.000587f, 0.000627f, 0.000643f, 0.000795f, 0.000974f, 0.001023f,
+ 0.000987f, 0.001031f, 0.001245f, 0.001470f, 0.001637f, 0.001820f, 0.001884f, 0.002146f, 0.002357f, 0.002630f, 0.002913f, 0.003164f,
+ 0.003380f, 0.003824f, 0.004189f, 0.004353f, 0.004940f, 0.005688f, 0.006409f, 0.007347f, 0.008018f, 0.009163f, 0.010559f, 0.012039f,
+ 0.013695f, 0.016144f, 0.018723f, 0.022354f, 0.026337f, 0.031433f, 0.038818f, 0.047546f, 0.059662f, 0.075623f, 0.097473f, 0.127808f,
+ 0.169556f, 0.225830f, 0.299072f, 0.387451f, 0.486084f, 0.583984f, 0.674805f, 0.751465f, 0.812012f, 0.859375f, 0.957031f, 0.958984f,
+ 0.959473f, 0.959961f, 0.959961f, 0.959961f, 0.000000f, 0.000000f, 0.000004f, 0.000078f, 0.000408f, 0.000432f, 0.000563f, 0.000560f,
+ 0.000566f, 0.000623f, 0.000782f, 0.000829f, 0.000896f, 0.000956f, 0.001056f, 0.001249f, 0.001414f, 0.001473f, 0.001646f, 0.001764f,
+ 0.002066f, 0.002230f, 0.002436f, 0.002651f, 0.003012f, 0.003252f, 0.003414f, 0.004055f, 0.004143f, 0.004784f, 0.005356f, 0.006077f,
+ 0.006870f, 0.007538f, 0.008728f, 0.009834f, 0.011322f, 0.013130f, 0.015427f, 0.017914f, 0.021271f, 0.025436f, 0.030960f, 0.038086f,
+ 0.047485f, 0.060303f, 0.077087f, 0.101196f, 0.134521f, 0.180786f, 0.244507f, 0.326172f, 0.423584f, 0.527832f, 0.628418f, 0.716797f,
+ 0.788086f, 0.843262f, 0.953125f, 0.955566f, 0.955566f, 0.956543f, 0.956055f, 0.956543f, 0.000000f, 0.000000f, 0.000000f, 0.000236f,
+ 0.000320f, 0.000484f, 0.000521f, 0.000549f, 0.000556f, 0.000584f, 0.000574f, 0.000690f, 0.000758f, 0.000841f, 0.001003f, 0.001013f,
+ 0.001169f, 0.001292f, 0.001437f, 0.001658f, 0.001830f, 0.002001f, 0.002081f, 0.002146f, 0.002434f, 0.002712f, 0.002964f, 0.003220f,
+ 0.003513f, 0.003963f, 0.004410f, 0.004875f, 0.005608f, 0.006245f, 0.007179f, 0.008118f, 0.009201f, 0.010582f, 0.012360f, 0.014343f,
+ 0.016968f, 0.020401f, 0.024628f, 0.030365f, 0.037567f, 0.047455f, 0.060913f, 0.079529f, 0.105774f, 0.143555f, 0.196167f, 0.268799f,
+ 0.361084f, 0.467041f, 0.576172f, 0.676758f, 0.760254f, 0.825195f, 0.948242f, 0.951660f, 0.951660f, 0.951660f, 0.951660f, 0.951660f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000122f, 0.000257f, 0.000334f, 0.000390f, 0.000496f, 0.000520f, 0.000539f, 0.000590f, 0.000602f,
+ 0.000646f, 0.000725f, 0.000909f, 0.000949f, 0.001023f, 0.001121f, 0.001181f, 0.001308f, 0.001474f, 0.001457f, 0.001714f, 0.002007f,
+ 0.001929f, 0.002039f, 0.002468f, 0.002672f, 0.003025f, 0.003317f, 0.003635f, 0.004047f, 0.004433f, 0.004864f, 0.005756f, 0.006493f,
+ 0.007515f, 0.008331f, 0.009697f, 0.011383f, 0.014000f, 0.016235f, 0.019653f, 0.024185f, 0.029465f, 0.037109f, 0.047699f, 0.062164f,
+ 0.082642f, 0.112488f, 0.155151f, 0.216919f, 0.300049f, 0.404541f, 0.520020f, 0.631836f, 0.728516f, 0.805664f, 0.943848f, 0.946289f,
+ 0.946777f, 0.946777f, 0.947266f, 0.947266f, 0.000000f, 0.000000f, 0.000122f, 0.000088f, 0.000219f, 0.000229f, 0.000355f, 0.000414f,
+ 0.000482f, 0.000545f, 0.000559f, 0.000568f, 0.000481f, 0.000668f, 0.000636f, 0.000728f, 0.000924f, 0.000980f, 0.001017f, 0.001109f,
+ 0.001258f, 0.001353f, 0.001451f, 0.001564f, 0.001621f, 0.001740f, 0.002066f, 0.002289f, 0.002459f, 0.002621f, 0.002975f, 0.003349f,
+ 0.003588f, 0.003998f, 0.004723f, 0.005116f, 0.006035f, 0.006859f, 0.007957f, 0.009064f, 0.010658f, 0.012711f, 0.015511f, 0.018555f,
+ 0.023026f, 0.028854f, 0.037140f, 0.048035f, 0.064026f, 0.086914f, 0.121033f, 0.171387f, 0.244141f, 0.341797f, 0.458740f, 0.580078f,
+ 0.691895f, 0.780762f, 0.937988f, 0.940430f, 0.941406f, 0.940918f, 0.941895f, 0.941406f, 0.000000f, 0.000000f, 0.000000f, 0.000080f,
+ 0.000211f, 0.000221f, 0.000225f, 0.000192f, 0.000352f, 0.000368f, 0.000397f, 0.000529f, 0.000510f, 0.000504f, 0.000540f, 0.000671f,
+ 0.000694f, 0.000763f, 0.000902f, 0.000998f, 0.001063f, 0.001074f, 0.001128f, 0.001407f, 0.001370f, 0.001449f, 0.001682f, 0.001635f,
+ 0.001976f, 0.002108f, 0.002335f, 0.002558f, 0.002905f, 0.003176f, 0.003637f, 0.003948f, 0.004650f, 0.005341f, 0.006237f, 0.007034f,
+ 0.008415f, 0.009811f, 0.012032f, 0.014565f, 0.017731f, 0.022324f, 0.028427f, 0.036713f, 0.048859f, 0.066406f, 0.092957f, 0.133057f,
+ 0.193848f, 0.281250f, 0.395508f, 0.524902f, 0.648926f, 0.754395f, 0.931152f, 0.934570f, 0.934570f, 0.934570f, 0.935547f, 0.935059f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000181f, 0.000196f, 0.000236f, 0.000250f, 0.000226f, 0.000281f, 0.000335f, 0.000457f,
+ 0.000406f, 0.000511f, 0.000522f, 0.000593f, 0.000539f, 0.000663f, 0.000661f, 0.000779f, 0.000978f, 0.000855f, 0.000937f, 0.001128f,
+ 0.001163f, 0.001253f, 0.001241f, 0.001531f, 0.001595f, 0.001796f, 0.001888f, 0.002226f, 0.002350f, 0.002609f, 0.002787f, 0.003260f,
+ 0.003656f, 0.004303f, 0.004910f, 0.005577f, 0.006683f, 0.007603f, 0.009102f, 0.011017f, 0.013603f, 0.016968f, 0.021652f, 0.027939f,
+ 0.037109f, 0.050262f, 0.070374f, 0.101624f, 0.150391f, 0.225220f, 0.331543f, 0.463867f, 0.601074f, 0.723145f, 0.923828f, 0.927246f,
+ 0.927246f, 0.928223f, 0.927734f, 0.928223f, 0.000000f, 0.000000f, 0.000122f, 0.000121f, 0.000121f, 0.000174f, 0.000156f, 0.000204f,
+ 0.000180f, 0.000221f, 0.000246f, 0.000346f, 0.000313f, 0.000426f, 0.000468f, 0.000482f, 0.000559f, 0.000582f, 0.000536f, 0.000611f,
+ 0.000770f, 0.000666f, 0.000919f, 0.000947f, 0.001013f, 0.000948f, 0.001129f, 0.001169f, 0.001463f, 0.001579f, 0.001540f, 0.001555f,
+ 0.001888f, 0.002007f, 0.002390f, 0.002623f, 0.002708f, 0.003235f, 0.003584f, 0.004223f, 0.005001f, 0.005791f, 0.006905f, 0.008118f,
+ 0.010117f, 0.012512f, 0.015961f, 0.020798f, 0.027374f, 0.037628f, 0.052673f, 0.076172f, 0.114197f, 0.175659f, 0.270752f, 0.399658f,
+ 0.546875f, 0.687012f, 0.915527f, 0.918457f, 0.919434f, 0.919434f, 0.919434f, 0.919434f, 0.000000f, 0.000000f, 0.000121f, 0.000121f,
+ 0.000121f, 0.000120f, 0.000139f, 0.000141f, 0.000152f, 0.000186f, 0.000209f, 0.000222f, 0.000297f, 0.000330f, 0.000367f, 0.000403f,
+ 0.000433f, 0.000456f, 0.000457f, 0.000484f, 0.000521f, 0.000544f, 0.000594f, 0.000807f, 0.000790f, 0.000841f, 0.000784f, 0.001025f,
+ 0.001112f, 0.001014f, 0.001146f, 0.001287f, 0.001485f, 0.001541f, 0.001740f, 0.002014f, 0.002264f, 0.002460f, 0.002825f, 0.003124f,
+ 0.003683f, 0.004177f, 0.005024f, 0.006004f, 0.007454f, 0.009041f, 0.011833f, 0.014839f, 0.019791f, 0.027283f, 0.038361f, 0.055817f,
+ 0.084656f, 0.133057f, 0.213013f, 0.334717f, 0.488770f, 0.645996f, 0.905762f, 0.909668f, 0.909668f, 0.909180f, 0.910645f, 0.908691f,
+ 0.000000f, 0.000000f, 0.000121f, 0.000121f, 0.000120f, 0.000120f, 0.000119f, 0.000115f, 0.000104f, 0.000105f, 0.000203f, 0.000235f,
+ 0.000185f, 0.000290f, 0.000201f, 0.000306f, 0.000259f, 0.000370f, 0.000401f, 0.000428f, 0.000596f, 0.000617f, 0.000474f, 0.000593f,
+ 0.000641f, 0.000676f, 0.000682f, 0.000826f, 0.000897f, 0.000934f, 0.000972f, 0.000972f, 0.001213f, 0.001281f, 0.001410f, 0.001451f,
+ 0.001562f, 0.001786f, 0.002031f, 0.002417f, 0.002764f, 0.003162f, 0.003763f, 0.004406f, 0.005310f, 0.006454f, 0.008156f, 0.010849f,
+ 0.014305f, 0.019318f, 0.027328f, 0.039856f, 0.061310f, 0.097717f, 0.162354f, 0.270752f, 0.424805f, 0.599609f, 0.894043f, 0.897949f,
+ 0.898438f, 0.898438f, 0.898926f, 0.898438f, 0.000000f, 0.000121f, 0.000121f, 0.000120f, 0.000119f, 0.000119f, 0.000118f, 0.000118f,
+ 0.000112f, 0.000102f, 0.000094f, 0.000109f, 0.000131f, 0.000145f, 0.000232f, 0.000171f, 0.000278f, 0.000230f, 0.000347f, 0.000331f,
+ 0.000379f, 0.000381f, 0.000512f, 0.000427f, 0.000541f, 0.000566f, 0.000547f, 0.000613f, 0.000706f, 0.000660f, 0.000809f, 0.000941f,
+ 0.000950f, 0.001035f, 0.001069f, 0.001220f, 0.001149f, 0.001314f, 0.001603f, 0.001801f, 0.002062f, 0.002394f, 0.002737f, 0.003057f,
+ 0.003771f, 0.004471f, 0.005875f, 0.007217f, 0.009651f, 0.013344f, 0.018829f, 0.027710f, 0.043091f, 0.069214f, 0.119141f, 0.210571f,
+ 0.358398f, 0.544922f, 0.881348f, 0.883789f, 0.885254f, 0.885742f, 0.885254f, 0.885254f, 0.000000f, 0.000121f, 0.000120f, 0.000119f,
+ 0.000119f, 0.000118f, 0.000117f, 0.000116f, 0.000116f, 0.000110f, 0.000101f, 0.000094f, 0.000087f, 0.000157f, 0.000151f, 0.000168f,
+ 0.000146f, 0.000219f, 0.000214f, 0.000261f, 0.000313f, 0.000363f, 0.000311f, 0.000415f, 0.000476f, 0.000448f, 0.000429f, 0.000460f,
+ 0.000481f, 0.000560f, 0.000544f, 0.000695f, 0.000626f, 0.000789f, 0.000877f, 0.000894f, 0.000948f, 0.001177f, 0.001175f, 0.001366f,
+ 0.001487f, 0.001738f, 0.002008f, 0.002304f, 0.002663f, 0.003250f, 0.004002f, 0.004932f, 0.006416f, 0.008636f, 0.012344f, 0.018127f,
+ 0.028610f, 0.047150f, 0.083923f, 0.156860f, 0.291260f, 0.487305f, 0.866211f, 0.869141f, 0.870605f, 0.870117f, 0.871094f, 0.870117f,
+ 0.000000f, 0.000000f, 0.000119f, 0.000118f, 0.000117f, 0.000116f, 0.000115f, 0.000115f, 0.000114f, 0.000114f, 0.000109f, 0.000101f,
+ 0.000094f, 0.000087f, 0.000081f, 0.000085f, 0.000129f, 0.000150f, 0.000176f, 0.000193f, 0.000216f, 0.000257f, 0.000241f, 0.000302f,
+ 0.000259f, 0.000299f, 0.000397f, 0.000403f, 0.000384f, 0.000402f, 0.000425f, 0.000582f, 0.000467f, 0.000614f, 0.000660f, 0.000625f,
+ 0.000650f, 0.000819f, 0.000790f, 0.000879f, 0.001001f, 0.001140f, 0.001403f, 0.001555f, 0.001844f, 0.002213f, 0.002636f, 0.003235f,
+ 0.004082f, 0.005604f, 0.007896f, 0.011292f, 0.018005f, 0.030472f, 0.055786f, 0.109985f, 0.224976f, 0.421875f, 0.848145f, 0.852539f,
+ 0.853027f, 0.852539f, 0.852539f, 0.853027f, 0.000000f, 0.000119f, 0.000118f, 0.000116f, 0.000115f, 0.000114f, 0.000113f, 0.000112f,
+ 0.000111f, 0.000111f, 0.000110f, 0.000108f, 0.000101f, 0.000094f, 0.000088f, 0.000082f, 0.000077f, 0.000109f, 0.000068f, 0.000102f,
+ 0.000127f, 0.000158f, 0.000177f, 0.000192f, 0.000207f, 0.000214f, 0.000249f, 0.000278f, 0.000296f, 0.000320f, 0.000330f, 0.000342f,
+ 0.000415f, 0.000371f, 0.000389f, 0.000508f, 0.000463f, 0.000586f, 0.000606f, 0.000649f, 0.000724f, 0.000841f, 0.000910f, 0.001065f,
+ 0.001236f, 0.001475f, 0.001807f, 0.002138f, 0.002716f, 0.003622f, 0.004921f, 0.006950f, 0.010574f, 0.018433f, 0.034607f, 0.072449f,
+ 0.163818f, 0.352295f, 0.827637f, 0.831055f, 0.831543f, 0.832031f, 0.833008f, 0.832520f, 0.000120f, 0.000116f, 0.000114f, 0.000113f,
+ 0.000111f, 0.000110f, 0.000109f, 0.000108f, 0.000107f, 0.000106f, 0.000106f, 0.000105f, 0.000104f, 0.000101f, 0.000094f, 0.000088f,
+ 0.000083f, 0.000078f, 0.000073f, 0.000092f, 0.000064f, 0.000097f, 0.000073f, 0.000105f, 0.000125f, 0.000162f, 0.000179f, 0.000177f,
+ 0.000191f, 0.000221f, 0.000241f, 0.000235f, 0.000270f, 0.000277f, 0.000287f, 0.000329f, 0.000319f, 0.000428f, 0.000417f, 0.000409f,
+ 0.000524f, 0.000537f, 0.000612f, 0.000750f, 0.000770f, 0.000961f, 0.001153f, 0.001347f, 0.001702f, 0.002081f, 0.002903f, 0.003956f,
+ 0.006184f, 0.010368f, 0.019592f, 0.043427f, 0.109924f, 0.280518f, 0.803223f, 0.806152f, 0.807617f, 0.808594f, 0.809082f, 0.808105f,
+ 0.000000f, 0.000111f, 0.000106f, 0.000107f, 0.000104f, 0.000103f, 0.000101f, 0.000101f, 0.000101f, 0.000100f, 0.000099f, 0.000098f,
+ 0.000097f, 0.000097f, 0.000097f, 0.000094f, 0.000088f, 0.000083f, 0.000078f, 0.000073f, 0.000069f, 0.000070f, 0.000061f, 0.000068f,
+ 0.000059f, 0.000067f, 0.000084f, 0.000097f, 0.000128f, 0.000137f, 0.000165f, 0.000160f, 0.000176f, 0.000185f, 0.000217f, 0.000239f,
+ 0.000237f, 0.000238f, 0.000272f, 0.000281f, 0.000314f, 0.000372f, 0.000395f, 0.000430f, 0.000504f, 0.000578f, 0.000665f, 0.000856f,
+ 0.000969f, 0.001210f, 0.001594f, 0.002216f, 0.003370f, 0.005527f, 0.010170f, 0.023239f, 0.066101f, 0.207275f, 0.775391f, 0.779785f,
+ 0.780273f, 0.780762f, 0.780273f, 0.780762f, 0.000000f, 0.000094f, 0.000097f, 0.000095f, 0.000092f, 0.000091f, 0.000091f, 0.000090f,
+ 0.000089f, 0.000089f, 0.000088f, 0.000088f, 0.000087f, 0.000086f, 0.000087f, 0.000086f, 0.000086f, 0.000085f, 0.000081f, 0.000076f,
+ 0.000072f, 0.000068f, 0.000064f, 0.000060f, 0.000057f, 0.000054f, 0.000058f, 0.000048f, 0.000048f, 0.000069f, 0.000068f, 0.000092f,
+ 0.000110f, 0.000122f, 0.000133f, 0.000136f, 0.000146f, 0.000154f, 0.000175f, 0.000194f, 0.000204f, 0.000206f, 0.000238f, 0.000262f,
+ 0.000266f, 0.000338f, 0.000361f, 0.000432f, 0.000527f, 0.000659f, 0.000848f, 0.001183f, 0.001713f, 0.002661f, 0.004921f, 0.010887f,
+ 0.033936f, 0.138428f, 0.743652f, 0.747559f, 0.748047f, 0.748535f, 0.749512f, 0.749023f, 0.000045f, 0.000047f, 0.000059f, 0.000059f,
+ 0.000063f, 0.000068f, 0.000068f, 0.000068f, 0.000067f, 0.000069f, 0.000068f, 0.000070f, 0.000070f, 0.000070f, 0.000071f, 0.000070f,
+ 0.000071f, 0.000071f, 0.000071f, 0.000071f, 0.000071f, 0.000069f, 0.000065f, 0.000062f, 0.000058f, 0.000055f, 0.000052f, 0.000049f,
+ 0.000046f, 0.000044f, 0.000041f, 0.000050f, 0.000051f, 0.000048f, 0.000061f, 0.000070f, 0.000084f, 0.000095f, 0.000107f, 0.000104f,
+ 0.000111f, 0.000128f, 0.000143f, 0.000154f, 0.000157f, 0.000186f, 0.000198f, 0.000216f, 0.000268f, 0.000315f, 0.000414f, 0.000537f,
+ 0.000735f, 0.001149f, 0.002075f, 0.004669f, 0.014175f, 0.077881f, 0.707031f, 0.710449f, 0.712402f, 0.711914f, 0.712891f, 0.712402f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000012f, 0.000013f, 0.000029f, 0.000028f, 0.000037f, 0.000035f, 0.000039f,
+ 0.000043f, 0.000043f, 0.000045f, 0.000045f, 0.000048f, 0.000048f, 0.000050f, 0.000051f, 0.000052f, 0.000052f, 0.000053f, 0.000054f,
+ 0.000054f, 0.000053f, 0.000050f, 0.000048f, 0.000045f, 0.000043f, 0.000040f, 0.000038f, 0.000036f, 0.000034f, 0.000032f, 0.000030f,
+ 0.000028f, 0.000030f, 0.000038f, 0.000043f, 0.000057f, 0.000069f, 0.000072f, 0.000073f, 0.000082f, 0.000095f, 0.000101f, 0.000099f,
+ 0.000116f, 0.000130f, 0.000184f, 0.000211f, 0.000301f, 0.000443f, 0.000737f, 0.001601f, 0.004978f, 0.032593f, 0.666504f, 0.669922f,
+ 0.669922f, 0.672363f, 0.670898f, 0.670410f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000006f, 0.000010f, 0.000012f, 0.000015f, 0.000018f, 0.000021f,
+ 0.000022f, 0.000023f, 0.000025f, 0.000028f, 0.000029f, 0.000029f, 0.000031f, 0.000033f, 0.000033f, 0.000035f, 0.000035f, 0.000035f,
+ 0.000033f, 0.000031f, 0.000029f, 0.000028f, 0.000026f, 0.000024f, 0.000023f, 0.000021f, 0.000020f, 0.000019f, 0.000022f, 0.000022f,
+ 0.000030f, 0.000038f, 0.000042f, 0.000041f, 0.000052f, 0.000047f, 0.000064f, 0.000072f, 0.000078f, 0.000129f, 0.000201f, 0.000382f,
+ 0.001180f, 0.009117f, 0.620605f, 0.624512f, 0.625000f, 0.625000f, 0.625000f, 0.625488f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000003f, 0.000005f, 0.000007f, 0.000008f, 0.000010f, 0.000011f, 0.000012f, 0.000014f, 0.000016f, 0.000016f, 0.000018f, 0.000017f,
+ 0.000016f, 0.000015f, 0.000014f, 0.000013f, 0.000012f, 0.000011f, 0.000010f, 0.000009f, 0.000011f, 0.000014f, 0.000018f, 0.000018f,
+ 0.000021f, 0.000028f, 0.000035f, 0.000053f, 0.000136f, 0.001152f, 0.571777f, 0.575684f, 0.575684f, 0.576172f, 0.576660f, 0.576660f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f,
+ 0.000002f, 0.000004f, 0.000004f, 0.000004f, 0.000003f, 0.000003f, 0.000002f, 0.000004f, 0.000003f, 0.000011f, 0.520020f, 0.523926f,
+ 0.524902f, 0.524902f, 0.524902f, 0.524902f,
+ },
+ {
+ 0.119934f, 0.328857f, 0.480713f, 0.586914f, 0.663086f, 0.717773f, 0.759766f, 0.791504f, 0.818359f, 0.838867f, 0.856934f, 0.871094f,
+ 0.883301f, 0.894043f, 0.902832f, 0.911621f, 0.917969f, 0.924805f, 0.930664f, 0.936035f, 0.939941f, 0.944824f, 0.948242f, 0.951660f,
+ 0.954590f, 0.958008f, 0.961426f, 0.962891f, 0.966309f, 0.967285f, 0.970215f, 0.972656f, 0.973633f, 0.975586f, 0.977539f, 0.978516f,
+ 0.979980f, 0.981445f, 0.982910f, 0.984375f, 0.985352f, 0.986328f, 0.987793f, 0.988770f, 0.989746f, 0.990234f, 0.991699f, 0.992676f,
+ 0.993164f, 0.993652f, 0.994629f, 0.995117f, 0.996094f, 0.996582f, 0.997559f, 0.998047f, 0.998535f, 0.999023f, 0.999512f, 0.999023f,
+ 0.999023f, 0.998535f, 0.998535f, 0.998047f, 0.046875f, 0.160400f, 0.286621f, 0.405518f, 0.507812f, 0.590820f, 0.656250f, 0.708008f,
+ 0.748535f, 0.781250f, 0.809082f, 0.830566f, 0.848633f, 0.864258f, 0.877441f, 0.888672f, 0.898926f, 0.906738f, 0.915039f, 0.921387f,
+ 0.928223f, 0.933105f, 0.937988f, 0.942871f, 0.946777f, 0.950684f, 0.954102f, 0.957031f, 0.959961f, 0.962402f, 0.965332f, 0.966797f,
+ 0.969727f, 0.971191f, 0.973145f, 0.975098f, 0.977539f, 0.978027f, 0.980469f, 0.981934f, 0.982910f, 0.984375f, 0.985352f, 0.986816f,
+ 0.987793f, 0.988770f, 0.989258f, 0.990723f, 0.991699f, 0.992676f, 0.993164f, 0.993652f, 0.994629f, 0.995605f, 0.996582f, 0.996582f,
+ 0.997559f, 0.998047f, 0.999023f, 0.999023f, 0.999023f, 0.998535f, 0.998535f, 0.998047f, 0.023788f, 0.084473f, 0.163696f, 0.255615f,
+ 0.351807f, 0.445312f, 0.527832f, 0.597656f, 0.656738f, 0.703613f, 0.742676f, 0.775879f, 0.802734f, 0.824707f, 0.843262f, 0.858887f,
+ 0.873047f, 0.884766f, 0.895508f, 0.903809f, 0.913086f, 0.919434f, 0.925781f, 0.931641f, 0.937012f, 0.941406f, 0.945801f, 0.949707f,
+ 0.953125f, 0.956543f, 0.959473f, 0.962402f, 0.964844f, 0.967285f, 0.969238f, 0.972168f, 0.973633f, 0.975098f, 0.977539f, 0.979492f,
+ 0.980469f, 0.981445f, 0.982910f, 0.984375f, 0.985840f, 0.986816f, 0.988281f, 0.988770f, 0.989746f, 0.990723f, 0.992188f, 0.992676f,
+ 0.993652f, 0.994629f, 0.995605f, 0.996094f, 0.996582f, 0.997559f, 0.998535f, 0.998535f, 0.998535f, 0.998047f, 0.998047f, 0.997559f,
+ 0.014595f, 0.050110f, 0.097717f, 0.158569f, 0.230347f, 0.311523f, 0.394531f, 0.473145f, 0.544922f, 0.606934f, 0.660645f, 0.705566f,
+ 0.743164f, 0.775391f, 0.800781f, 0.822266f, 0.841309f, 0.856934f, 0.870605f, 0.883301f, 0.894043f, 0.902832f, 0.911133f, 0.918945f,
+ 0.925293f, 0.931152f, 0.936035f, 0.941406f, 0.945801f, 0.949707f, 0.953125f, 0.956055f, 0.959473f, 0.962402f, 0.964844f, 0.967285f,
+ 0.970215f, 0.972168f, 0.974121f, 0.975098f, 0.977539f, 0.979004f, 0.980957f, 0.981934f, 0.983398f, 0.984375f, 0.985840f, 0.987305f,
+ 0.988281f, 0.989258f, 0.990723f, 0.991699f, 0.992676f, 0.993652f, 0.994629f, 0.995117f, 0.995605f, 0.996582f, 0.998535f, 0.998535f,
+ 0.998535f, 0.998047f, 0.998047f, 0.997559f, 0.009178f, 0.032379f, 0.062561f, 0.102417f, 0.151611f, 0.210938f, 0.279785f, 0.352783f,
+ 0.426758f, 0.496826f, 0.561035f, 0.618164f, 0.666992f, 0.708496f, 0.744141f, 0.773926f, 0.800781f, 0.821777f, 0.840820f, 0.856445f,
+ 0.870117f, 0.882324f, 0.893066f, 0.901855f, 0.910645f, 0.918457f, 0.925293f, 0.930176f, 0.935547f, 0.941406f, 0.946289f, 0.949707f,
+ 0.953125f, 0.956543f, 0.959961f, 0.962891f, 0.965332f, 0.967773f, 0.969727f, 0.972656f, 0.974121f, 0.976074f, 0.977539f, 0.979492f,
+ 0.981445f, 0.982422f, 0.984375f, 0.985840f, 0.986328f, 0.987793f, 0.989258f, 0.990234f, 0.991211f, 0.992188f, 0.993164f, 0.994141f,
+ 0.994629f, 0.995605f, 0.998047f, 0.998047f, 0.998047f, 0.997559f, 0.997559f, 0.997559f, 0.006382f, 0.022430f, 0.042908f, 0.068970f,
+ 0.102844f, 0.144653f, 0.195557f, 0.253906f, 0.318848f, 0.386230f, 0.454590f, 0.518066f, 0.577148f, 0.628906f, 0.675293f, 0.714844f,
+ 0.748535f, 0.777344f, 0.802246f, 0.823730f, 0.841797f, 0.856934f, 0.871094f, 0.882812f, 0.893555f, 0.902832f, 0.911133f, 0.918457f,
+ 0.925293f, 0.930176f, 0.937012f, 0.940918f, 0.945801f, 0.950195f, 0.953613f, 0.957031f, 0.960449f, 0.963379f, 0.966309f, 0.968262f,
+ 0.970703f, 0.973145f, 0.974609f, 0.976562f, 0.978516f, 0.980469f, 0.981934f, 0.983398f, 0.984375f, 0.985840f, 0.988281f, 0.988770f,
+ 0.989746f, 0.990723f, 0.991699f, 0.992676f, 0.993652f, 0.994629f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997559f, 0.997070f,
+ 0.004585f, 0.015961f, 0.030930f, 0.049133f, 0.072144f, 0.101013f, 0.137451f, 0.181519f, 0.232544f, 0.290039f, 0.352539f, 0.416748f,
+ 0.479736f, 0.538574f, 0.592773f, 0.641602f, 0.684570f, 0.723145f, 0.754395f, 0.782715f, 0.805176f, 0.825195f, 0.843750f, 0.859863f,
+ 0.872559f, 0.884766f, 0.895020f, 0.904297f, 0.912109f, 0.919922f, 0.926270f, 0.932129f, 0.937500f, 0.942383f, 0.946289f, 0.950195f,
+ 0.955078f, 0.958008f, 0.961426f, 0.964355f, 0.967285f, 0.969238f, 0.971680f, 0.974121f, 0.975586f, 0.977539f, 0.979492f, 0.980957f,
+ 0.982910f, 0.984375f, 0.985840f, 0.986328f, 0.988281f, 0.989746f, 0.990723f, 0.992188f, 0.992676f, 0.993164f, 0.997559f, 0.997559f,
+ 0.997070f, 0.997070f, 0.997070f, 0.997070f, 0.003483f, 0.012291f, 0.023209f, 0.036041f, 0.052429f, 0.073486f, 0.099182f, 0.131226f,
+ 0.169678f, 0.214844f, 0.266846f, 0.323242f, 0.383545f, 0.444580f, 0.503418f, 0.559082f, 0.609375f, 0.655762f, 0.695312f, 0.730957f,
+ 0.760254f, 0.788086f, 0.810059f, 0.829590f, 0.847168f, 0.862793f, 0.875488f, 0.886719f, 0.896973f, 0.906250f, 0.914551f, 0.921387f,
+ 0.927734f, 0.933594f, 0.938965f, 0.944336f, 0.948242f, 0.952148f, 0.956543f, 0.958984f, 0.961914f, 0.965332f, 0.968262f, 0.970703f,
+ 0.972656f, 0.974609f, 0.977051f, 0.979004f, 0.980469f, 0.981934f, 0.983887f, 0.985352f, 0.986328f, 0.987793f, 0.989746f, 0.990234f,
+ 0.991699f, 0.992676f, 0.996582f, 0.997070f, 0.997070f, 0.996582f, 0.996582f, 0.996094f, 0.002962f, 0.009613f, 0.017792f, 0.027481f,
+ 0.039429f, 0.055176f, 0.073914f, 0.096985f, 0.125610f, 0.159180f, 0.199707f, 0.246216f, 0.297607f, 0.353760f, 0.412842f, 0.470215f,
+ 0.526367f, 0.578613f, 0.626953f, 0.669434f, 0.707031f, 0.740723f, 0.769043f, 0.794922f, 0.814941f, 0.835449f, 0.851074f, 0.866699f,
+ 0.879395f, 0.890137f, 0.899902f, 0.909180f, 0.916992f, 0.924316f, 0.929688f, 0.936035f, 0.941406f, 0.945312f, 0.950195f, 0.953613f,
+ 0.957520f, 0.960938f, 0.963867f, 0.966797f, 0.969238f, 0.971680f, 0.974121f, 0.976562f, 0.979004f, 0.979980f, 0.981934f, 0.982910f,
+ 0.984375f, 0.986816f, 0.987793f, 0.988770f, 0.990234f, 0.991699f, 0.996582f, 0.996582f, 0.996582f, 0.996582f, 0.996094f, 0.996094f,
+ 0.002077f, 0.007637f, 0.013802f, 0.021606f, 0.031006f, 0.042419f, 0.055969f, 0.073242f, 0.094055f, 0.119446f, 0.150513f, 0.186401f,
+ 0.228638f, 0.276123f, 0.328857f, 0.384277f, 0.440674f, 0.496338f, 0.549805f, 0.598633f, 0.644043f, 0.683594f, 0.719727f, 0.750977f,
+ 0.779297f, 0.802246f, 0.823730f, 0.840820f, 0.855957f, 0.871582f, 0.882324f, 0.893555f, 0.903809f, 0.911621f, 0.920410f, 0.926758f,
+ 0.932617f, 0.938477f, 0.943359f, 0.947754f, 0.953125f, 0.955566f, 0.959473f, 0.962402f, 0.965332f, 0.968262f, 0.970703f, 0.972656f,
+ 0.976074f, 0.977051f, 0.979492f, 0.981445f, 0.983398f, 0.984863f, 0.986328f, 0.987793f, 0.989258f, 0.990723f, 0.995605f, 0.996094f,
+ 0.996094f, 0.996094f, 0.996094f, 0.995605f, 0.002014f, 0.006035f, 0.011299f, 0.017410f, 0.024368f, 0.033020f, 0.043701f, 0.056458f,
+ 0.072205f, 0.091431f, 0.114807f, 0.141968f, 0.174316f, 0.213257f, 0.256836f, 0.306152f, 0.358887f, 0.413330f, 0.468018f, 0.520996f,
+ 0.572266f, 0.618652f, 0.661621f, 0.699707f, 0.732910f, 0.762695f, 0.788574f, 0.810547f, 0.830078f, 0.848145f, 0.862305f, 0.875977f,
+ 0.887695f, 0.898438f, 0.907227f, 0.915527f, 0.922852f, 0.929199f, 0.936035f, 0.940918f, 0.946289f, 0.950684f, 0.953613f, 0.958496f,
+ 0.960938f, 0.964355f, 0.967285f, 0.970215f, 0.972656f, 0.975586f, 0.977539f, 0.979492f, 0.980957f, 0.982910f, 0.984863f, 0.986328f,
+ 0.987793f, 0.988770f, 0.995117f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.001496f, 0.005196f, 0.009201f, 0.013985f,
+ 0.019806f, 0.026413f, 0.034943f, 0.044647f, 0.056641f, 0.070923f, 0.088623f, 0.109680f, 0.135254f, 0.164795f, 0.200073f, 0.240845f,
+ 0.285645f, 0.335449f, 0.387939f, 0.441650f, 0.495850f, 0.546875f, 0.595215f, 0.639160f, 0.679199f, 0.715820f, 0.746582f, 0.774414f,
+ 0.798828f, 0.819824f, 0.837402f, 0.854492f, 0.869629f, 0.881348f, 0.893066f, 0.902832f, 0.912109f, 0.918945f, 0.926758f, 0.933105f,
+ 0.938477f, 0.943359f, 0.948730f, 0.952637f, 0.956055f, 0.960449f, 0.963379f, 0.966797f, 0.969238f, 0.972656f, 0.975098f, 0.977051f,
+ 0.979004f, 0.981445f, 0.982910f, 0.984375f, 0.986328f, 0.987305f, 0.994629f, 0.995605f, 0.995117f, 0.995117f, 0.995117f, 0.994629f,
+ 0.001187f, 0.004314f, 0.007740f, 0.011337f, 0.016373f, 0.021759f, 0.028198f, 0.035889f, 0.045197f, 0.056580f, 0.069946f, 0.085938f,
+ 0.105408f, 0.128784f, 0.155884f, 0.187866f, 0.225830f, 0.268066f, 0.315186f, 0.365479f, 0.418213f, 0.471680f, 0.522949f, 0.572754f,
+ 0.617676f, 0.659668f, 0.697754f, 0.730957f, 0.760742f, 0.787109f, 0.809570f, 0.830078f, 0.846680f, 0.862793f, 0.875488f, 0.888184f,
+ 0.898926f, 0.907715f, 0.916016f, 0.923340f, 0.930664f, 0.936523f, 0.941895f, 0.947754f, 0.951660f, 0.955566f, 0.959473f, 0.963867f,
+ 0.966309f, 0.969238f, 0.972168f, 0.974121f, 0.976562f, 0.979004f, 0.980957f, 0.982910f, 0.984863f, 0.986816f, 0.994141f, 0.994629f,
+ 0.994629f, 0.994629f, 0.994629f, 0.994141f, 0.001187f, 0.003733f, 0.006496f, 0.009918f, 0.013634f, 0.017899f, 0.023026f, 0.029343f,
+ 0.036621f, 0.045227f, 0.055786f, 0.068298f, 0.083740f, 0.101135f, 0.122314f, 0.147827f, 0.177612f, 0.212891f, 0.252686f, 0.297119f,
+ 0.345215f, 0.395996f, 0.448730f, 0.500488f, 0.550781f, 0.597656f, 0.641113f, 0.680664f, 0.716309f, 0.747559f, 0.774414f, 0.799316f,
+ 0.820312f, 0.838867f, 0.855957f, 0.870117f, 0.883301f, 0.894531f, 0.904785f, 0.913086f, 0.920898f, 0.928223f, 0.935059f, 0.940430f,
+ 0.945312f, 0.950684f, 0.955566f, 0.958496f, 0.962891f, 0.965820f, 0.968750f, 0.971680f, 0.974609f, 0.976562f, 0.978516f, 0.980957f,
+ 0.982910f, 0.984863f, 0.994141f, 0.994141f, 0.994629f, 0.994141f, 0.994141f, 0.994629f, 0.000998f, 0.003178f, 0.005444f, 0.008179f,
+ 0.011337f, 0.015091f, 0.019058f, 0.024368f, 0.029587f, 0.037140f, 0.045197f, 0.055115f, 0.066772f, 0.080688f, 0.097229f, 0.117371f,
+ 0.140869f, 0.169312f, 0.201538f, 0.238770f, 0.280762f, 0.326660f, 0.376709f, 0.427490f, 0.479248f, 0.530273f, 0.578613f, 0.623535f,
+ 0.664551f, 0.701660f, 0.733887f, 0.763672f, 0.790039f, 0.812500f, 0.832520f, 0.849121f, 0.865234f, 0.878906f, 0.890625f, 0.901367f,
+ 0.910645f, 0.919434f, 0.926758f, 0.933105f, 0.939453f, 0.944824f, 0.949707f, 0.954590f, 0.958008f, 0.961914f, 0.965332f, 0.968750f,
+ 0.971680f, 0.974121f, 0.977051f, 0.979004f, 0.980957f, 0.982910f, 0.993164f, 0.993164f, 0.994141f, 0.993652f, 0.993652f, 0.993164f,
+ 0.000948f, 0.002638f, 0.004784f, 0.007153f, 0.009590f, 0.012505f, 0.016388f, 0.020599f, 0.025299f, 0.031097f, 0.037323f, 0.045197f,
+ 0.054047f, 0.065002f, 0.078674f, 0.094055f, 0.112305f, 0.134399f, 0.160889f, 0.191040f, 0.226318f, 0.265869f, 0.310303f, 0.358154f,
+ 0.409180f, 0.459473f, 0.510254f, 0.559082f, 0.606445f, 0.648926f, 0.687500f, 0.722168f, 0.753418f, 0.781250f, 0.804199f, 0.825684f,
+ 0.843262f, 0.860840f, 0.874512f, 0.886719f, 0.898926f, 0.907227f, 0.916992f, 0.924805f, 0.932129f, 0.937988f, 0.943848f, 0.949219f,
+ 0.954102f, 0.958496f, 0.961426f, 0.965332f, 0.968750f, 0.972168f, 0.974609f, 0.977051f, 0.979492f, 0.981445f, 0.992188f, 0.993164f,
+ 0.993164f, 0.993164f, 0.993164f, 0.992676f, 0.000696f, 0.002352f, 0.004002f, 0.006138f, 0.008446f, 0.010826f, 0.013840f, 0.017258f,
+ 0.021194f, 0.025970f, 0.031128f, 0.037140f, 0.044281f, 0.053436f, 0.063660f, 0.076050f, 0.090271f, 0.107727f, 0.128662f, 0.152832f,
+ 0.182007f, 0.214111f, 0.252930f, 0.295166f, 0.341553f, 0.390625f, 0.442139f, 0.492676f, 0.541992f, 0.589844f, 0.633301f, 0.674316f,
+ 0.710938f, 0.743652f, 0.772461f, 0.796875f, 0.819824f, 0.839355f, 0.854980f, 0.870605f, 0.884277f, 0.895508f, 0.906738f, 0.915527f,
+ 0.923828f, 0.931152f, 0.937500f, 0.944336f, 0.949219f, 0.953613f, 0.958008f, 0.962402f, 0.965332f, 0.968750f, 0.972168f, 0.974609f,
+ 0.977051f, 0.979980f, 0.991211f, 0.992676f, 0.992188f, 0.992188f, 0.992188f, 0.992676f, 0.000838f, 0.002033f, 0.003664f, 0.005077f,
+ 0.007282f, 0.009415f, 0.011749f, 0.014931f, 0.017853f, 0.021606f, 0.025864f, 0.031219f, 0.037231f, 0.044464f, 0.052338f, 0.062500f,
+ 0.073853f, 0.087463f, 0.104065f, 0.123230f, 0.146362f, 0.173340f, 0.205078f, 0.240845f, 0.281982f, 0.326660f, 0.374756f, 0.425049f,
+ 0.476807f, 0.526855f, 0.574219f, 0.620117f, 0.662598f, 0.699219f, 0.733398f, 0.764160f, 0.791016f, 0.813965f, 0.833984f, 0.851074f,
+ 0.867676f, 0.880859f, 0.893555f, 0.904785f, 0.914062f, 0.922852f, 0.930176f, 0.937012f, 0.942383f, 0.948242f, 0.953125f, 0.957520f,
+ 0.962402f, 0.966309f, 0.969238f, 0.973145f, 0.975098f, 0.978027f, 0.991699f, 0.991699f, 0.992676f, 0.992188f, 0.991699f, 0.992188f,
+ 0.000600f, 0.001687f, 0.003023f, 0.004963f, 0.006405f, 0.008163f, 0.010368f, 0.012718f, 0.015480f, 0.018311f, 0.022064f, 0.026169f,
+ 0.031097f, 0.036926f, 0.043457f, 0.051392f, 0.060669f, 0.071350f, 0.084473f, 0.100220f, 0.118103f, 0.140259f, 0.166016f, 0.195679f,
+ 0.230469f, 0.269531f, 0.313232f, 0.360596f, 0.410156f, 0.460693f, 0.511719f, 0.560547f, 0.607422f, 0.650879f, 0.689941f, 0.724609f,
+ 0.756348f, 0.784180f, 0.808594f, 0.828613f, 0.847656f, 0.864258f, 0.879395f, 0.892090f, 0.903320f, 0.912598f, 0.921875f, 0.929688f,
+ 0.936523f, 0.942871f, 0.947754f, 0.953125f, 0.957520f, 0.961914f, 0.966309f, 0.969238f, 0.972656f, 0.975586f, 0.990234f, 0.991211f,
+ 0.991211f, 0.991699f, 0.991211f, 0.991211f, 0.000269f, 0.001538f, 0.002800f, 0.003868f, 0.005524f, 0.007179f, 0.008987f, 0.011063f,
+ 0.013084f, 0.015747f, 0.019211f, 0.022324f, 0.026474f, 0.031311f, 0.036530f, 0.042969f, 0.050201f, 0.059174f, 0.069641f, 0.081543f,
+ 0.096680f, 0.114075f, 0.134644f, 0.158691f, 0.187622f, 0.220581f, 0.258301f, 0.300781f, 0.347168f, 0.395996f, 0.447266f, 0.498291f,
+ 0.547852f, 0.595215f, 0.640625f, 0.680176f, 0.717285f, 0.749512f, 0.778320f, 0.803223f, 0.825684f, 0.845215f, 0.862793f, 0.877441f,
+ 0.890625f, 0.901855f, 0.912109f, 0.920898f, 0.929688f, 0.937012f, 0.942871f, 0.949707f, 0.954102f, 0.958496f, 0.962402f, 0.966309f,
+ 0.970215f, 0.974121f, 0.989746f, 0.990234f, 0.990723f, 0.990723f, 0.990723f, 0.990234f, 0.000341f, 0.001337f, 0.002573f, 0.003475f,
+ 0.004765f, 0.006329f, 0.007717f, 0.009499f, 0.011642f, 0.014107f, 0.016556f, 0.019470f, 0.022491f, 0.026169f, 0.030945f, 0.036011f,
+ 0.042389f, 0.049042f, 0.057678f, 0.067993f, 0.079468f, 0.093384f, 0.110046f, 0.129883f, 0.152710f, 0.180420f, 0.212158f, 0.248291f,
+ 0.289551f, 0.334961f, 0.383301f, 0.434570f, 0.485596f, 0.536133f, 0.584473f, 0.630371f, 0.671875f, 0.710449f, 0.743652f, 0.773926f,
+ 0.799316f, 0.823242f, 0.843262f, 0.860352f, 0.875977f, 0.889648f, 0.901367f, 0.911621f, 0.921387f, 0.929688f, 0.937012f, 0.943848f,
+ 0.950195f, 0.955078f, 0.959473f, 0.963379f, 0.967773f, 0.971191f, 0.988770f, 0.989746f, 0.990234f, 0.990234f, 0.990234f, 0.990234f,
+ 0.000564f, 0.001324f, 0.002092f, 0.003191f, 0.004471f, 0.005348f, 0.007069f, 0.008438f, 0.010201f, 0.011810f, 0.014297f, 0.016586f,
+ 0.019470f, 0.022644f, 0.026428f, 0.030579f, 0.035797f, 0.041718f, 0.048248f, 0.056213f, 0.065857f, 0.076782f, 0.090271f, 0.106262f,
+ 0.125122f, 0.147095f, 0.173462f, 0.204224f, 0.239746f, 0.279785f, 0.323730f, 0.372314f, 0.422607f, 0.474121f, 0.526367f, 0.575195f,
+ 0.621582f, 0.664062f, 0.703613f, 0.738770f, 0.769043f, 0.796387f, 0.820312f, 0.841797f, 0.858887f, 0.875488f, 0.889648f, 0.900879f,
+ 0.912598f, 0.921875f, 0.930664f, 0.937500f, 0.944336f, 0.950195f, 0.955566f, 0.959961f, 0.964844f, 0.968750f, 0.987305f, 0.989258f,
+ 0.989258f, 0.989258f, 0.989258f, 0.988770f, 0.000369f, 0.001128f, 0.001871f, 0.002792f, 0.003712f, 0.004723f, 0.006016f, 0.007542f,
+ 0.008896f, 0.010773f, 0.012421f, 0.014381f, 0.016632f, 0.019791f, 0.022354f, 0.025955f, 0.030609f, 0.035065f, 0.040924f, 0.047333f,
+ 0.055084f, 0.064209f, 0.075012f, 0.087769f, 0.102966f, 0.120911f, 0.142456f, 0.167358f, 0.197144f, 0.231812f, 0.270752f, 0.314209f,
+ 0.362549f, 0.412598f, 0.464844f, 0.515625f, 0.566895f, 0.614258f, 0.657715f, 0.698730f, 0.734863f, 0.766602f, 0.794922f, 0.818848f,
+ 0.839844f, 0.858887f, 0.875000f, 0.889648f, 0.901855f, 0.912598f, 0.922852f, 0.931152f, 0.938965f, 0.945312f, 0.951660f, 0.957520f,
+ 0.961426f, 0.966309f, 0.986816f, 0.988281f, 0.988281f, 0.988770f, 0.988281f, 0.988281f, 0.000466f, 0.000900f, 0.001792f, 0.002695f,
+ 0.003458f, 0.004204f, 0.005356f, 0.006512f, 0.007896f, 0.009300f, 0.010895f, 0.012459f, 0.014786f, 0.016739f, 0.019424f, 0.022461f,
+ 0.026062f, 0.029831f, 0.034851f, 0.039764f, 0.046417f, 0.053711f, 0.062164f, 0.072388f, 0.085205f, 0.099365f, 0.117004f, 0.137573f,
+ 0.162231f, 0.190674f, 0.224121f, 0.262451f, 0.305664f, 0.353027f, 0.403809f, 0.456055f, 0.508301f, 0.559082f, 0.608398f, 0.652832f,
+ 0.694824f, 0.731445f, 0.764160f, 0.793945f, 0.817871f, 0.839355f, 0.858398f, 0.875488f, 0.890137f, 0.902832f, 0.913574f, 0.923828f,
+ 0.932617f, 0.940918f, 0.946777f, 0.953613f, 0.958984f, 0.963379f, 0.985840f, 0.987305f, 0.987305f, 0.987793f, 0.987305f, 0.987305f,
+ 0.000234f, 0.001040f, 0.001661f, 0.002392f, 0.003101f, 0.003681f, 0.004944f, 0.005844f, 0.007065f, 0.008217f, 0.009247f, 0.010925f,
+ 0.012894f, 0.014549f, 0.017090f, 0.019455f, 0.022385f, 0.025650f, 0.029449f, 0.033936f, 0.039215f, 0.045135f, 0.052612f, 0.060944f,
+ 0.070312f, 0.082397f, 0.096924f, 0.113525f, 0.133179f, 0.156860f, 0.184814f, 0.217773f, 0.255127f, 0.298340f, 0.345215f, 0.395996f,
+ 0.448242f, 0.501953f, 0.553223f, 0.603516f, 0.649414f, 0.691895f, 0.729980f, 0.763184f, 0.792480f, 0.818359f, 0.841309f, 0.858887f,
+ 0.877441f, 0.891113f, 0.904785f, 0.915527f, 0.925781f, 0.933594f, 0.941895f, 0.949219f, 0.955566f, 0.960449f, 0.984863f, 0.985840f,
+ 0.986328f, 0.986816f, 0.986328f, 0.986816f, 0.000241f, 0.000808f, 0.001395f, 0.001986f, 0.002731f, 0.003429f, 0.004131f, 0.005402f,
+ 0.006077f, 0.007347f, 0.008522f, 0.009544f, 0.011345f, 0.013046f, 0.014534f, 0.016953f, 0.019241f, 0.022339f, 0.025208f, 0.029175f,
+ 0.033691f, 0.038300f, 0.044067f, 0.051331f, 0.059143f, 0.068726f, 0.080322f, 0.093567f, 0.109802f, 0.129883f, 0.152466f, 0.179810f,
+ 0.211792f, 0.249390f, 0.291748f, 0.338623f, 0.389404f, 0.442139f, 0.496338f, 0.548340f, 0.599121f, 0.645996f, 0.689941f, 0.728516f,
+ 0.762695f, 0.792969f, 0.818848f, 0.842285f, 0.862793f, 0.878906f, 0.894043f, 0.906250f, 0.917969f, 0.927734f, 0.935547f, 0.944336f,
+ 0.951172f, 0.957031f, 0.983398f, 0.985352f, 0.985840f, 0.985352f, 0.985840f, 0.985352f, 0.000340f, 0.000735f, 0.001377f, 0.001853f,
+ 0.002382f, 0.003159f, 0.004021f, 0.004642f, 0.005604f, 0.006340f, 0.007298f, 0.008591f, 0.009895f, 0.011154f, 0.012871f, 0.014580f,
+ 0.016876f, 0.019180f, 0.022141f, 0.024979f, 0.028748f, 0.032745f, 0.037964f, 0.043213f, 0.050171f, 0.057831f, 0.066833f, 0.078247f,
+ 0.091553f, 0.107178f, 0.125977f, 0.148315f, 0.175415f, 0.207153f, 0.244019f, 0.286377f, 0.333008f, 0.383789f, 0.437744f, 0.491943f,
+ 0.545410f, 0.597168f, 0.645508f, 0.688965f, 0.729004f, 0.764160f, 0.794434f, 0.821289f, 0.843750f, 0.864258f, 0.881348f, 0.895996f,
+ 0.909180f, 0.920898f, 0.929199f, 0.938965f, 0.946777f, 0.952637f, 0.982910f, 0.983887f, 0.984863f, 0.984863f, 0.984375f, 0.984863f,
+ 0.000236f, 0.000605f, 0.001135f, 0.001415f, 0.002329f, 0.002747f, 0.003551f, 0.004158f, 0.004723f, 0.005535f, 0.006687f, 0.007534f,
+ 0.008545f, 0.009979f, 0.011375f, 0.012993f, 0.014656f, 0.016754f, 0.018921f, 0.021759f, 0.024506f, 0.028183f, 0.032043f, 0.036743f,
+ 0.042236f, 0.048645f, 0.056030f, 0.065125f, 0.075928f, 0.089050f, 0.104370f, 0.122681f, 0.145142f, 0.171509f, 0.202759f, 0.239258f,
+ 0.281250f, 0.328369f, 0.379639f, 0.433838f, 0.489014f, 0.543945f, 0.596191f, 0.645020f, 0.690430f, 0.730957f, 0.766113f, 0.797852f,
+ 0.824219f, 0.846680f, 0.867188f, 0.884766f, 0.899414f, 0.912109f, 0.923828f, 0.933105f, 0.942383f, 0.949707f, 0.980957f, 0.982910f,
+ 0.983398f, 0.983398f, 0.983887f, 0.982910f, 0.000214f, 0.000710f, 0.001021f, 0.001429f, 0.001858f, 0.002607f, 0.003220f, 0.003738f,
+ 0.004459f, 0.005032f, 0.005726f, 0.006748f, 0.007748f, 0.008659f, 0.010002f, 0.011368f, 0.012985f, 0.014656f, 0.016525f, 0.018921f,
+ 0.021286f, 0.024231f, 0.027649f, 0.031464f, 0.035858f, 0.041321f, 0.047363f, 0.054840f, 0.063538f, 0.074097f, 0.086609f, 0.101990f,
+ 0.120117f, 0.141846f, 0.168213f, 0.199219f, 0.235352f, 0.277344f, 0.324707f, 0.376953f, 0.432373f, 0.488037f, 0.543457f, 0.597168f,
+ 0.646973f, 0.692871f, 0.732910f, 0.769531f, 0.801270f, 0.828125f, 0.850586f, 0.871582f, 0.888184f, 0.903809f, 0.915527f, 0.927246f,
+ 0.936523f, 0.946289f, 0.979492f, 0.981445f, 0.981934f, 0.982422f, 0.981934f, 0.981934f, 0.000000f, 0.000468f, 0.001076f, 0.001489f,
+ 0.002048f, 0.002413f, 0.002853f, 0.003468f, 0.003952f, 0.004444f, 0.005211f, 0.005917f, 0.006733f, 0.007763f, 0.008713f, 0.010262f,
+ 0.011368f, 0.012733f, 0.014458f, 0.016296f, 0.018478f, 0.021072f, 0.023666f, 0.026810f, 0.030746f, 0.035278f, 0.040131f, 0.046295f,
+ 0.053711f, 0.062195f, 0.072327f, 0.084717f, 0.099487f, 0.117371f, 0.139038f, 0.164795f, 0.195923f, 0.232422f, 0.274414f, 0.322266f,
+ 0.374756f, 0.431641f, 0.488525f, 0.545410f, 0.599121f, 0.650879f, 0.697754f, 0.738770f, 0.774414f, 0.806641f, 0.832520f, 0.856445f,
+ 0.875488f, 0.893555f, 0.907715f, 0.920410f, 0.931152f, 0.940918f, 0.978027f, 0.980469f, 0.980469f, 0.980957f, 0.980957f, 0.980957f,
+ 0.000279f, 0.000497f, 0.000763f, 0.001353f, 0.001794f, 0.002079f, 0.002451f, 0.002956f, 0.003498f, 0.004150f, 0.004589f, 0.005310f,
+ 0.006130f, 0.006958f, 0.007828f, 0.008888f, 0.009895f, 0.011124f, 0.012772f, 0.014282f, 0.016235f, 0.018127f, 0.020630f, 0.022873f,
+ 0.026321f, 0.029938f, 0.034241f, 0.039368f, 0.045319f, 0.052338f, 0.060852f, 0.070801f, 0.082947f, 0.097595f, 0.115051f, 0.136353f,
+ 0.162231f, 0.193481f, 0.229858f, 0.272217f, 0.321777f, 0.375000f, 0.432373f, 0.490479f, 0.548340f, 0.604004f, 0.655762f, 0.702637f,
+ 0.743652f, 0.780273f, 0.812500f, 0.838867f, 0.862305f, 0.881348f, 0.897949f, 0.912598f, 0.925293f, 0.935547f, 0.976562f, 0.978516f,
+ 0.979492f, 0.979980f, 0.979492f, 0.979004f, 0.000110f, 0.000473f, 0.000781f, 0.001262f, 0.001584f, 0.001890f, 0.002270f, 0.002607f,
+ 0.003241f, 0.003704f, 0.004055f, 0.004795f, 0.005356f, 0.005997f, 0.006760f, 0.007896f, 0.008896f, 0.009918f, 0.011200f, 0.012451f,
+ 0.013802f, 0.015556f, 0.017838f, 0.020065f, 0.022751f, 0.025864f, 0.029358f, 0.033600f, 0.038574f, 0.044342f, 0.050995f, 0.059296f,
+ 0.069214f, 0.081116f, 0.095459f, 0.113159f, 0.133911f, 0.160400f, 0.191406f, 0.228638f, 0.272217f, 0.321289f, 0.375732f, 0.434326f,
+ 0.493896f, 0.552734f, 0.609863f, 0.662109f, 0.709961f, 0.750977f, 0.787598f, 0.819336f, 0.846680f, 0.868164f, 0.887695f, 0.904297f,
+ 0.917969f, 0.930176f, 0.975098f, 0.977539f, 0.977051f, 0.977539f, 0.977539f, 0.977539f, 0.000242f, 0.000464f, 0.000831f, 0.001027f,
+ 0.001271f, 0.001722f, 0.001965f, 0.002243f, 0.002714f, 0.003036f, 0.003651f, 0.004025f, 0.004902f, 0.005638f, 0.006176f, 0.006943f,
+ 0.007763f, 0.008789f, 0.009804f, 0.010872f, 0.012070f, 0.013695f, 0.015381f, 0.017395f, 0.019608f, 0.022232f, 0.025009f, 0.028885f,
+ 0.032623f, 0.037659f, 0.043182f, 0.050018f, 0.058167f, 0.067810f, 0.079224f, 0.093811f, 0.111328f, 0.132324f, 0.158569f, 0.190063f,
+ 0.228149f, 0.271973f, 0.322510f, 0.378906f, 0.438477f, 0.499756f, 0.560059f, 0.618164f, 0.671387f, 0.718750f, 0.760742f, 0.796875f,
+ 0.826660f, 0.854492f, 0.875000f, 0.894531f, 0.911133f, 0.923828f, 0.973145f, 0.976074f, 0.975586f, 0.976074f, 0.976074f, 0.977051f,
+ 0.000242f, 0.000552f, 0.000701f, 0.001063f, 0.001186f, 0.001462f, 0.001690f, 0.002340f, 0.002703f, 0.002728f, 0.003325f, 0.003828f,
+ 0.004333f, 0.004913f, 0.005474f, 0.006077f, 0.006943f, 0.007607f, 0.008553f, 0.009460f, 0.010582f, 0.011871f, 0.013451f, 0.015091f,
+ 0.016983f, 0.019165f, 0.021637f, 0.024673f, 0.027863f, 0.031525f, 0.036713f, 0.041962f, 0.048615f, 0.056396f, 0.066162f, 0.077942f,
+ 0.092590f, 0.110046f, 0.130981f, 0.157593f, 0.189331f, 0.228394f, 0.273926f, 0.325684f, 0.383301f, 0.444580f, 0.507324f, 0.569824f,
+ 0.627441f, 0.682129f, 0.729980f, 0.770508f, 0.807129f, 0.837402f, 0.863281f, 0.884766f, 0.902832f, 0.917969f, 0.971191f, 0.973633f,
+ 0.974609f, 0.974121f, 0.974609f, 0.974609f, 0.000239f, 0.000239f, 0.000658f, 0.000899f, 0.001204f, 0.001252f, 0.001629f, 0.001815f,
+ 0.002470f, 0.002430f, 0.003134f, 0.003321f, 0.003925f, 0.004238f, 0.004856f, 0.005341f, 0.006161f, 0.006615f, 0.007511f, 0.008224f,
+ 0.009277f, 0.010445f, 0.011818f, 0.013046f, 0.014473f, 0.016510f, 0.018814f, 0.021057f, 0.023834f, 0.027237f, 0.030853f, 0.035675f,
+ 0.040894f, 0.047241f, 0.055145f, 0.064758f, 0.076782f, 0.090942f, 0.108398f, 0.130371f, 0.157104f, 0.189819f, 0.229248f, 0.276367f,
+ 0.329834f, 0.390137f, 0.453125f, 0.517578f, 0.580566f, 0.640625f, 0.694336f, 0.741699f, 0.782715f, 0.817871f, 0.848145f, 0.872559f,
+ 0.893555f, 0.910645f, 0.969727f, 0.971191f, 0.972656f, 0.972168f, 0.972168f, 0.972168f, 0.000222f, 0.000463f, 0.000620f, 0.000837f,
+ 0.000900f, 0.001048f, 0.001381f, 0.001820f, 0.001957f, 0.002329f, 0.002747f, 0.002964f, 0.003330f, 0.003986f, 0.004322f, 0.004677f,
+ 0.005302f, 0.005760f, 0.006569f, 0.007359f, 0.008141f, 0.009293f, 0.010101f, 0.011452f, 0.012779f, 0.014496f, 0.016144f, 0.018097f,
+ 0.020157f, 0.023148f, 0.026611f, 0.029785f, 0.034515f, 0.039856f, 0.046478f, 0.054016f, 0.063843f, 0.075378f, 0.089233f, 0.107666f,
+ 0.129639f, 0.156860f, 0.190674f, 0.231445f, 0.280518f, 0.336426f, 0.398193f, 0.463379f, 0.530273f, 0.595215f, 0.654785f, 0.708984f,
+ 0.755371f, 0.796875f, 0.831543f, 0.860352f, 0.883789f, 0.903809f, 0.966797f, 0.968750f, 0.969727f, 0.970215f, 0.970215f, 0.969727f,
+ 0.000000f, 0.000345f, 0.000464f, 0.000686f, 0.000782f, 0.001030f, 0.001139f, 0.001598f, 0.001846f, 0.002237f, 0.002489f, 0.002684f,
+ 0.003067f, 0.003344f, 0.003895f, 0.004158f, 0.004845f, 0.005131f, 0.005886f, 0.006561f, 0.007195f, 0.007912f, 0.008965f, 0.009941f,
+ 0.010956f, 0.012383f, 0.013893f, 0.015602f, 0.017303f, 0.019623f, 0.022156f, 0.025452f, 0.028976f, 0.033722f, 0.038910f, 0.045288f,
+ 0.052887f, 0.062561f, 0.074097f, 0.088623f, 0.106812f, 0.129639f, 0.157715f, 0.192261f, 0.235107f, 0.285889f, 0.344482f, 0.408691f,
+ 0.476807f, 0.545410f, 0.610840f, 0.671387f, 0.725098f, 0.771484f, 0.811035f, 0.843750f, 0.871582f, 0.894043f, 0.964355f, 0.967285f,
+ 0.967285f, 0.967773f, 0.967773f, 0.967773f, 0.000000f, 0.000320f, 0.000576f, 0.000572f, 0.000767f, 0.000945f, 0.001066f, 0.001375f,
+ 0.001848f, 0.001980f, 0.002190f, 0.002399f, 0.002695f, 0.002943f, 0.003397f, 0.003664f, 0.004063f, 0.004566f, 0.005119f, 0.005688f,
+ 0.006130f, 0.007057f, 0.007778f, 0.008675f, 0.009590f, 0.010666f, 0.011971f, 0.013443f, 0.015129f, 0.016953f, 0.018875f, 0.021576f,
+ 0.024658f, 0.028488f, 0.032959f, 0.037811f, 0.043793f, 0.051819f, 0.061371f, 0.073181f, 0.088257f, 0.106506f, 0.129883f, 0.159180f,
+ 0.195679f, 0.240479f, 0.293457f, 0.355225f, 0.422852f, 0.492432f, 0.563477f, 0.629883f, 0.690918f, 0.743652f, 0.789062f, 0.827148f,
+ 0.858398f, 0.884277f, 0.961914f, 0.964844f, 0.964355f, 0.964844f, 0.964355f, 0.965332f, 0.000000f, 0.000242f, 0.000435f, 0.000547f,
+ 0.000688f, 0.000803f, 0.001175f, 0.001318f, 0.001593f, 0.001652f, 0.001961f, 0.002209f, 0.002481f, 0.002716f, 0.002911f, 0.003210f,
+ 0.003595f, 0.004005f, 0.004490f, 0.004894f, 0.005508f, 0.006107f, 0.006714f, 0.007462f, 0.008438f, 0.009277f, 0.010170f, 0.011436f,
+ 0.012756f, 0.014145f, 0.016205f, 0.018433f, 0.020966f, 0.023819f, 0.027405f, 0.031464f, 0.036713f, 0.043152f, 0.050842f, 0.060577f,
+ 0.071960f, 0.087219f, 0.106689f, 0.130371f, 0.161377f, 0.199585f, 0.246948f, 0.303467f, 0.367920f, 0.439697f, 0.512207f, 0.584473f,
+ 0.651855f, 0.712402f, 0.764160f, 0.808105f, 0.844727f, 0.875000f, 0.958008f, 0.961426f, 0.961914f, 0.961914f, 0.962402f, 0.961914f,
+ 0.000000f, 0.000237f, 0.000266f, 0.000387f, 0.000557f, 0.000691f, 0.000774f, 0.001221f, 0.001455f, 0.001492f, 0.001769f, 0.001896f,
+ 0.002151f, 0.002386f, 0.002529f, 0.002911f, 0.003147f, 0.003523f, 0.003862f, 0.004311f, 0.004848f, 0.005260f, 0.005795f, 0.006416f,
+ 0.007114f, 0.007942f, 0.008667f, 0.009666f, 0.010818f, 0.012184f, 0.013718f, 0.015541f, 0.017685f, 0.020126f, 0.023056f, 0.026306f,
+ 0.030853f, 0.035797f, 0.042053f, 0.049683f, 0.059784f, 0.072144f, 0.086914f, 0.106873f, 0.132202f, 0.164429f, 0.205200f, 0.255615f,
+ 0.315918f, 0.384521f, 0.458984f, 0.534668f, 0.607910f, 0.676758f, 0.735840f, 0.785645f, 0.828125f, 0.862305f, 0.955566f, 0.958008f,
+ 0.958984f, 0.958496f, 0.958984f, 0.958984f, 0.000000f, 0.000119f, 0.000234f, 0.000484f, 0.000603f, 0.000758f, 0.000934f, 0.000999f,
+ 0.001200f, 0.001343f, 0.001534f, 0.001725f, 0.001860f, 0.002056f, 0.002235f, 0.002445f, 0.002783f, 0.003115f, 0.003448f, 0.003757f,
+ 0.004192f, 0.004723f, 0.005077f, 0.005653f, 0.006172f, 0.006527f, 0.007328f, 0.008247f, 0.009140f, 0.010368f, 0.011711f, 0.013351f,
+ 0.014702f, 0.016937f, 0.019226f, 0.022156f, 0.025604f, 0.029877f, 0.034668f, 0.040710f, 0.048920f, 0.058624f, 0.071289f, 0.087219f,
+ 0.107727f, 0.134521f, 0.168701f, 0.212769f, 0.267090f, 0.331543f, 0.404785f, 0.482910f, 0.561523f, 0.635742f, 0.702637f, 0.760742f,
+ 0.809570f, 0.849121f, 0.951660f, 0.954590f, 0.955566f, 0.955566f, 0.956055f, 0.955566f, 0.000238f, 0.000218f, 0.000229f, 0.000242f,
+ 0.000313f, 0.000859f, 0.000623f, 0.000978f, 0.001021f, 0.001150f, 0.001320f, 0.001431f, 0.001546f, 0.001746f, 0.001895f, 0.002106f,
+ 0.002502f, 0.002630f, 0.002926f, 0.003296f, 0.003651f, 0.003918f, 0.004391f, 0.004910f, 0.005249f, 0.005558f, 0.006413f, 0.007114f,
+ 0.007866f, 0.008789f, 0.009872f, 0.011093f, 0.012413f, 0.013939f, 0.015945f, 0.018692f, 0.021225f, 0.024643f, 0.028687f, 0.033936f,
+ 0.040192f, 0.047791f, 0.058014f, 0.070923f, 0.087585f, 0.109131f, 0.137573f, 0.174683f, 0.222290f, 0.280762f, 0.350830f, 0.428955f,
+ 0.511230f, 0.592285f, 0.666992f, 0.733398f, 0.789062f, 0.834473f, 0.947754f, 0.951172f, 0.951660f, 0.951172f, 0.951660f, 0.951172f,
+ 0.000000f, 0.000205f, 0.000222f, 0.000344f, 0.000301f, 0.000775f, 0.000827f, 0.000719f, 0.000944f, 0.000976f, 0.001306f, 0.001249f,
+ 0.001404f, 0.001569f, 0.001604f, 0.001819f, 0.002182f, 0.002354f, 0.002569f, 0.002857f, 0.003113f, 0.003426f, 0.003649f, 0.004112f,
+ 0.004307f, 0.004925f, 0.005508f, 0.005802f, 0.006565f, 0.007450f, 0.008125f, 0.009079f, 0.010269f, 0.011665f, 0.013565f, 0.015213f,
+ 0.017410f, 0.020203f, 0.023743f, 0.028168f, 0.032684f, 0.039062f, 0.047058f, 0.057404f, 0.070984f, 0.088623f, 0.111389f, 0.142090f,
+ 0.182373f, 0.234253f, 0.298828f, 0.375000f, 0.458008f, 0.543945f, 0.627441f, 0.702148f, 0.765137f, 0.818359f, 0.942871f, 0.946289f,
+ 0.947266f, 0.947266f, 0.946777f, 0.947266f, 0.000064f, 0.000095f, 0.000197f, 0.000213f, 0.000459f, 0.000491f, 0.000647f, 0.000696f,
+ 0.000884f, 0.000911f, 0.001121f, 0.001115f, 0.001234f, 0.001371f, 0.001410f, 0.001743f, 0.001905f, 0.002016f, 0.002207f, 0.002438f,
+ 0.002714f, 0.002939f, 0.003183f, 0.003323f, 0.003727f, 0.004143f, 0.004555f, 0.005276f, 0.005531f, 0.006264f, 0.006702f, 0.007572f,
+ 0.008705f, 0.009712f, 0.011238f, 0.012650f, 0.014320f, 0.016815f, 0.019516f, 0.022400f, 0.026566f, 0.031799f, 0.038055f, 0.046417f,
+ 0.057037f, 0.071350f, 0.089722f, 0.114868f, 0.148193f, 0.192749f, 0.249878f, 0.321045f, 0.404053f, 0.493408f, 0.583008f, 0.666016f,
+ 0.739258f, 0.799316f, 0.937988f, 0.941406f, 0.941895f, 0.942383f, 0.942383f, 0.942383f, 0.000000f, 0.000007f, 0.000144f, 0.000427f,
+ 0.000443f, 0.000566f, 0.000589f, 0.000615f, 0.000725f, 0.000731f, 0.000896f, 0.000953f, 0.001062f, 0.001167f, 0.001344f, 0.001345f,
+ 0.001636f, 0.001774f, 0.001893f, 0.002069f, 0.002350f, 0.002457f, 0.002678f, 0.002743f, 0.003105f, 0.003513f, 0.003830f, 0.004227f,
+ 0.004589f, 0.005047f, 0.005669f, 0.006176f, 0.007153f, 0.007896f, 0.008911f, 0.010231f, 0.011818f, 0.013618f, 0.015465f, 0.018188f,
+ 0.021576f, 0.025452f, 0.030533f, 0.037048f, 0.045685f, 0.056915f, 0.071533f, 0.091675f, 0.118958f, 0.156006f, 0.205444f, 0.270020f,
+ 0.349609f, 0.439941f, 0.533691f, 0.625977f, 0.708984f, 0.778320f, 0.931641f, 0.936035f, 0.936523f, 0.937012f, 0.937012f, 0.937012f,
+ 0.000000f, 0.000000f, 0.000137f, 0.000262f, 0.000432f, 0.000437f, 0.000444f, 0.000590f, 0.000558f, 0.000606f, 0.000817f, 0.000877f,
+ 0.000909f, 0.000951f, 0.001191f, 0.001244f, 0.001373f, 0.001506f, 0.001702f, 0.001690f, 0.001955f, 0.001940f, 0.002283f, 0.002340f,
+ 0.002571f, 0.002871f, 0.003265f, 0.003475f, 0.003910f, 0.004181f, 0.004608f, 0.005112f, 0.005833f, 0.006416f, 0.007145f, 0.008209f,
+ 0.009636f, 0.010750f, 0.012642f, 0.014481f, 0.017197f, 0.020203f, 0.024353f, 0.029694f, 0.036041f, 0.045105f, 0.056702f, 0.072388f,
+ 0.094482f, 0.124329f, 0.166504f, 0.223022f, 0.295898f, 0.384766f, 0.482910f, 0.582031f, 0.675293f, 0.754883f, 0.926270f, 0.929688f,
+ 0.930664f, 0.930664f, 0.931152f, 0.930664f, 0.000000f, 0.000000f, 0.000000f, 0.000232f, 0.000357f, 0.000411f, 0.000513f, 0.000527f,
+ 0.000490f, 0.000504f, 0.000653f, 0.000750f, 0.000780f, 0.000976f, 0.000942f, 0.000967f, 0.001180f, 0.001252f, 0.001385f, 0.001425f,
+ 0.001559f, 0.001801f, 0.001886f, 0.002144f, 0.002111f, 0.002354f, 0.002645f, 0.002827f, 0.003187f, 0.003414f, 0.003792f, 0.004360f,
+ 0.004662f, 0.005146f, 0.005875f, 0.006783f, 0.007610f, 0.008797f, 0.010033f, 0.011566f, 0.013565f, 0.016006f, 0.019165f, 0.023163f,
+ 0.028320f, 0.035400f, 0.044647f, 0.057129f, 0.074402f, 0.098572f, 0.132812f, 0.180542f, 0.245728f, 0.330078f, 0.428955f, 0.535156f,
+ 0.638184f, 0.728516f, 0.919434f, 0.922852f, 0.923828f, 0.923828f, 0.923828f, 0.924316f, 0.000000f, 0.000000f, 0.000000f, 0.000114f,
+ 0.000248f, 0.000359f, 0.000386f, 0.000342f, 0.000465f, 0.000461f, 0.000490f, 0.000609f, 0.000638f, 0.000694f, 0.000807f, 0.000923f,
+ 0.000961f, 0.001074f, 0.001123f, 0.001268f, 0.001311f, 0.001494f, 0.001537f, 0.001754f, 0.001899f, 0.001917f, 0.002199f, 0.002241f,
+ 0.002583f, 0.002769f, 0.003101f, 0.003441f, 0.003775f, 0.004200f, 0.004787f, 0.005272f, 0.006062f, 0.006702f, 0.007732f, 0.009102f,
+ 0.010582f, 0.012466f, 0.014984f, 0.017990f, 0.021957f, 0.027222f, 0.034332f, 0.044128f, 0.057434f, 0.076538f, 0.104126f, 0.143799f,
+ 0.199829f, 0.275879f, 0.373047f, 0.482422f, 0.594727f, 0.698730f, 0.910645f, 0.914551f, 0.916504f, 0.916016f, 0.916504f, 0.915527f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000121f, 0.000221f, 0.000222f, 0.000392f, 0.000402f, 0.000396f, 0.000434f, 0.000476f, 0.000548f,
+ 0.000536f, 0.000644f, 0.000642f, 0.000793f, 0.000795f, 0.000912f, 0.000953f, 0.000989f, 0.001164f, 0.001197f, 0.001285f, 0.001480f,
+ 0.001511f, 0.001674f, 0.001703f, 0.001901f, 0.002075f, 0.002340f, 0.002499f, 0.002800f, 0.003019f, 0.003296f, 0.003695f, 0.004093f,
+ 0.004780f, 0.005260f, 0.006207f, 0.006939f, 0.008034f, 0.009598f, 0.011353f, 0.013702f, 0.016678f, 0.020874f, 0.026062f, 0.033539f,
+ 0.044006f, 0.058746f, 0.080139f, 0.111877f, 0.158447f, 0.226318f, 0.317627f, 0.428711f, 0.548828f, 0.665039f, 0.901367f, 0.907227f,
+ 0.907715f, 0.908203f, 0.908203f, 0.907227f, 0.000000f, 0.000000f, 0.000122f, 0.000173f, 0.000191f, 0.000215f, 0.000224f, 0.000261f,
+ 0.000340f, 0.000374f, 0.000380f, 0.000496f, 0.000416f, 0.000535f, 0.000592f, 0.000622f, 0.000701f, 0.000772f, 0.000742f, 0.000774f,
+ 0.000990f, 0.000945f, 0.001088f, 0.001105f, 0.001348f, 0.001231f, 0.001460f, 0.001620f, 0.001758f, 0.001941f, 0.002008f, 0.002092f,
+ 0.002430f, 0.002615f, 0.002886f, 0.003208f, 0.003519f, 0.004112f, 0.004704f, 0.005371f, 0.006149f, 0.007351f, 0.008659f, 0.010201f,
+ 0.012550f, 0.015549f, 0.019577f, 0.025436f, 0.032928f, 0.044220f, 0.060608f, 0.084961f, 0.123474f, 0.180664f, 0.263184f, 0.372314f,
+ 0.498291f, 0.626465f, 0.892578f, 0.895996f, 0.896973f, 0.896973f, 0.897949f, 0.897949f, 0.000000f, 0.000000f, 0.000121f, 0.000121f,
+ 0.000120f, 0.000192f, 0.000201f, 0.000222f, 0.000222f, 0.000276f, 0.000295f, 0.000344f, 0.000433f, 0.000470f, 0.000485f, 0.000549f,
+ 0.000555f, 0.000558f, 0.000566f, 0.000639f, 0.000678f, 0.000757f, 0.000840f, 0.000905f, 0.000999f, 0.000946f, 0.001018f, 0.001309f,
+ 0.001402f, 0.001417f, 0.001624f, 0.001692f, 0.001869f, 0.002003f, 0.002184f, 0.002602f, 0.002851f, 0.003157f, 0.003595f, 0.004063f,
+ 0.004734f, 0.005398f, 0.006275f, 0.007542f, 0.009148f, 0.011383f, 0.014275f, 0.018250f, 0.024063f, 0.032135f, 0.044922f, 0.063721f,
+ 0.093811f, 0.139648f, 0.211914f, 0.314697f, 0.444092f, 0.584961f, 0.879883f, 0.884766f, 0.885254f, 0.885742f, 0.886230f, 0.885742f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000120f, 0.000154f, 0.000150f, 0.000160f, 0.000202f, 0.000217f, 0.000308f, 0.000319f,
+ 0.000278f, 0.000392f, 0.000362f, 0.000432f, 0.000416f, 0.000448f, 0.000495f, 0.000526f, 0.000710f, 0.000754f, 0.000657f, 0.000755f,
+ 0.000806f, 0.000919f, 0.000815f, 0.001080f, 0.001152f, 0.001207f, 0.001218f, 0.001373f, 0.001320f, 0.001685f, 0.001764f, 0.001819f,
+ 0.002068f, 0.002380f, 0.002668f, 0.003033f, 0.003584f, 0.003979f, 0.004829f, 0.005402f, 0.006630f, 0.008080f, 0.010254f, 0.013069f,
+ 0.017044f, 0.023422f, 0.031647f, 0.046417f, 0.068604f, 0.104919f, 0.165161f, 0.258789f, 0.387207f, 0.537598f, 0.867188f, 0.871582f,
+ 0.872559f, 0.872559f, 0.872559f, 0.873047f, 0.000000f, 0.000121f, 0.000120f, 0.000120f, 0.000119f, 0.000118f, 0.000122f, 0.000108f,
+ 0.000143f, 0.000149f, 0.000184f, 0.000194f, 0.000189f, 0.000210f, 0.000321f, 0.000282f, 0.000376f, 0.000420f, 0.000533f, 0.000437f,
+ 0.000467f, 0.000477f, 0.000587f, 0.000519f, 0.000673f, 0.000662f, 0.000679f, 0.000845f, 0.000881f, 0.000863f, 0.001016f, 0.001093f,
+ 0.001176f, 0.001191f, 0.001336f, 0.001561f, 0.001573f, 0.001754f, 0.001919f, 0.002264f, 0.002596f, 0.002911f, 0.003372f, 0.003870f,
+ 0.004723f, 0.005733f, 0.007092f, 0.008965f, 0.011650f, 0.015701f, 0.022339f, 0.032043f, 0.048370f, 0.076050f, 0.124084f, 0.204834f,
+ 0.328369f, 0.485596f, 0.852539f, 0.856934f, 0.858887f, 0.858887f, 0.858887f, 0.858398f, 0.000000f, 0.000121f, 0.000120f, 0.000119f,
+ 0.000118f, 0.000117f, 0.000116f, 0.000114f, 0.000105f, 0.000110f, 0.000165f, 0.000133f, 0.000157f, 0.000240f, 0.000256f, 0.000257f,
+ 0.000249f, 0.000303f, 0.000342f, 0.000346f, 0.000485f, 0.000510f, 0.000398f, 0.000493f, 0.000492f, 0.000524f, 0.000590f, 0.000585f,
+ 0.000601f, 0.000740f, 0.000647f, 0.000871f, 0.000834f, 0.000969f, 0.001020f, 0.001190f, 0.001244f, 0.001432f, 0.001393f, 0.001702f,
+ 0.001912f, 0.002171f, 0.002445f, 0.002958f, 0.003330f, 0.004025f, 0.004860f, 0.006161f, 0.007896f, 0.010742f, 0.014671f, 0.021378f,
+ 0.032928f, 0.052612f, 0.089050f, 0.155884f, 0.268555f, 0.430664f, 0.836426f, 0.841309f, 0.841309f, 0.842285f, 0.842773f, 0.842285f,
+ 0.000000f, 0.000000f, 0.000119f, 0.000117f, 0.000116f, 0.000115f, 0.000114f, 0.000114f, 0.000111f, 0.000103f, 0.000097f, 0.000118f,
+ 0.000115f, 0.000130f, 0.000176f, 0.000130f, 0.000223f, 0.000235f, 0.000244f, 0.000252f, 0.000274f, 0.000389f, 0.000309f, 0.000430f,
+ 0.000340f, 0.000399f, 0.000408f, 0.000459f, 0.000514f, 0.000501f, 0.000519f, 0.000657f, 0.000588f, 0.000775f, 0.000813f, 0.000789f,
+ 0.000904f, 0.001076f, 0.001027f, 0.001170f, 0.001342f, 0.001425f, 0.001662f, 0.002005f, 0.002298f, 0.002699f, 0.003227f, 0.003990f,
+ 0.005062f, 0.006855f, 0.009415f, 0.013504f, 0.020905f, 0.034424f, 0.060333f, 0.112000f, 0.210693f, 0.371094f, 0.816406f, 0.822754f,
+ 0.822754f, 0.823242f, 0.823242f, 0.823730f, 0.000000f, 0.000119f, 0.000117f, 0.000116f, 0.000114f, 0.000113f, 0.000112f, 0.000111f,
+ 0.000110f, 0.000109f, 0.000102f, 0.000095f, 0.000090f, 0.000084f, 0.000093f, 0.000103f, 0.000118f, 0.000165f, 0.000162f, 0.000190f,
+ 0.000204f, 0.000218f, 0.000223f, 0.000237f, 0.000256f, 0.000272f, 0.000344f, 0.000365f, 0.000365f, 0.000396f, 0.000386f, 0.000412f,
+ 0.000530f, 0.000466f, 0.000492f, 0.000615f, 0.000611f, 0.000748f, 0.000712f, 0.000795f, 0.000908f, 0.000971f, 0.001106f, 0.001353f,
+ 0.001572f, 0.001822f, 0.002251f, 0.002676f, 0.003290f, 0.004349f, 0.005951f, 0.008316f, 0.012543f, 0.021149f, 0.038025f, 0.075500f,
+ 0.156006f, 0.308838f, 0.794922f, 0.800293f, 0.800781f, 0.801270f, 0.801758f, 0.802246f, 0.000121f, 0.000116f, 0.000114f, 0.000113f,
+ 0.000111f, 0.000109f, 0.000108f, 0.000107f, 0.000106f, 0.000104f, 0.000104f, 0.000100f, 0.000094f, 0.000088f, 0.000083f, 0.000078f,
+ 0.000074f, 0.000105f, 0.000078f, 0.000122f, 0.000113f, 0.000153f, 0.000174f, 0.000175f, 0.000207f, 0.000216f, 0.000225f, 0.000215f,
+ 0.000262f, 0.000308f, 0.000297f, 0.000287f, 0.000307f, 0.000342f, 0.000363f, 0.000411f, 0.000401f, 0.000453f, 0.000522f, 0.000555f,
+ 0.000680f, 0.000701f, 0.000751f, 0.000873f, 0.000966f, 0.001181f, 0.001445f, 0.001666f, 0.002077f, 0.002512f, 0.003359f, 0.004856f,
+ 0.007347f, 0.012001f, 0.022049f, 0.046417f, 0.107117f, 0.245361f, 0.770508f, 0.775879f, 0.776367f, 0.776855f, 0.777344f, 0.777832f,
+ 0.000000f, 0.000113f, 0.000108f, 0.000107f, 0.000104f, 0.000103f, 0.000101f, 0.000100f, 0.000099f, 0.000098f, 0.000097f, 0.000096f,
+ 0.000095f, 0.000091f, 0.000086f, 0.000081f, 0.000077f, 0.000073f, 0.000069f, 0.000079f, 0.000084f, 0.000091f, 0.000074f, 0.000100f,
+ 0.000117f, 0.000140f, 0.000144f, 0.000166f, 0.000174f, 0.000178f, 0.000225f, 0.000197f, 0.000234f, 0.000239f, 0.000273f, 0.000289f,
+ 0.000283f, 0.000293f, 0.000338f, 0.000386f, 0.000386f, 0.000432f, 0.000459f, 0.000525f, 0.000625f, 0.000691f, 0.000800f, 0.001004f,
+ 0.001227f, 0.001479f, 0.001984f, 0.002745f, 0.003983f, 0.006413f, 0.011642f, 0.025269f, 0.066040f, 0.182495f, 0.743164f, 0.748535f,
+ 0.749023f, 0.749512f, 0.750000f, 0.749512f, 0.000000f, 0.000102f, 0.000101f, 0.000098f, 0.000094f, 0.000093f, 0.000092f, 0.000090f,
+ 0.000089f, 0.000088f, 0.000087f, 0.000086f, 0.000085f, 0.000084f, 0.000085f, 0.000082f, 0.000078f, 0.000074f, 0.000070f, 0.000066f,
+ 0.000063f, 0.000060f, 0.000057f, 0.000056f, 0.000061f, 0.000060f, 0.000073f, 0.000087f, 0.000100f, 0.000105f, 0.000124f, 0.000136f,
+ 0.000140f, 0.000140f, 0.000159f, 0.000179f, 0.000186f, 0.000205f, 0.000214f, 0.000229f, 0.000248f, 0.000267f, 0.000299f, 0.000344f,
+ 0.000367f, 0.000422f, 0.000496f, 0.000557f, 0.000639f, 0.000837f, 0.001037f, 0.001419f, 0.002081f, 0.003202f, 0.005730f, 0.012199f,
+ 0.034943f, 0.122925f, 0.711426f, 0.716797f, 0.718750f, 0.718262f, 0.718262f, 0.718750f, 0.000094f, 0.000079f, 0.000078f, 0.000074f,
+ 0.000074f, 0.000075f, 0.000074f, 0.000073f, 0.000071f, 0.000072f, 0.000070f, 0.000071f, 0.000071f, 0.000070f, 0.000070f, 0.000069f,
+ 0.000070f, 0.000069f, 0.000068f, 0.000065f, 0.000062f, 0.000059f, 0.000056f, 0.000053f, 0.000050f, 0.000048f, 0.000045f, 0.000044f,
+ 0.000041f, 0.000050f, 0.000050f, 0.000061f, 0.000068f, 0.000085f, 0.000091f, 0.000101f, 0.000102f, 0.000107f, 0.000119f, 0.000129f,
+ 0.000144f, 0.000151f, 0.000160f, 0.000184f, 0.000212f, 0.000213f, 0.000235f, 0.000294f, 0.000315f, 0.000392f, 0.000505f, 0.000637f,
+ 0.000880f, 0.001400f, 0.002462f, 0.005333f, 0.015160f, 0.070312f, 0.678223f, 0.683105f, 0.684082f, 0.684570f, 0.684570f, 0.684570f,
+ 0.000000f, 0.000000f, 0.000023f, 0.000034f, 0.000032f, 0.000038f, 0.000037f, 0.000044f, 0.000043f, 0.000047f, 0.000045f, 0.000047f,
+ 0.000049f, 0.000049f, 0.000049f, 0.000048f, 0.000051f, 0.000050f, 0.000051f, 0.000051f, 0.000052f, 0.000052f, 0.000052f, 0.000049f,
+ 0.000047f, 0.000045f, 0.000042f, 0.000040f, 0.000038f, 0.000036f, 0.000035f, 0.000033f, 0.000031f, 0.000029f, 0.000038f, 0.000037f,
+ 0.000042f, 0.000051f, 0.000055f, 0.000067f, 0.000074f, 0.000073f, 0.000083f, 0.000093f, 0.000088f, 0.000102f, 0.000122f, 0.000122f,
+ 0.000142f, 0.000169f, 0.000206f, 0.000265f, 0.000355f, 0.000531f, 0.000897f, 0.001822f, 0.005493f, 0.030579f, 0.640137f, 0.644531f,
+ 0.647461f, 0.647949f, 0.647461f, 0.648438f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000001f, 0.000000f, 0.000008f, 0.000012f, 0.000014f, 0.000014f, 0.000019f, 0.000021f, 0.000022f, 0.000024f, 0.000026f, 0.000027f,
+ 0.000027f, 0.000028f, 0.000029f, 0.000031f, 0.000031f, 0.000032f, 0.000032f, 0.000033f, 0.000033f, 0.000032f, 0.000030f, 0.000029f,
+ 0.000027f, 0.000026f, 0.000024f, 0.000023f, 0.000022f, 0.000021f, 0.000019f, 0.000018f, 0.000021f, 0.000024f, 0.000028f, 0.000033f,
+ 0.000043f, 0.000041f, 0.000046f, 0.000053f, 0.000050f, 0.000059f, 0.000068f, 0.000094f, 0.000096f, 0.000140f, 0.000239f, 0.000447f,
+ 0.001340f, 0.009087f, 0.600098f, 0.605957f, 0.606934f, 0.606934f, 0.607422f, 0.606934f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000002f, 0.000004f, 0.000006f, 0.000006f,
+ 0.000009f, 0.000010f, 0.000011f, 0.000012f, 0.000013f, 0.000014f, 0.000015f, 0.000016f, 0.000017f, 0.000016f, 0.000015f, 0.000014f,
+ 0.000013f, 0.000012f, 0.000012f, 0.000011f, 0.000010f, 0.000009f, 0.000008f, 0.000012f, 0.000014f, 0.000018f, 0.000017f, 0.000022f,
+ 0.000022f, 0.000026f, 0.000040f, 0.000060f, 0.000157f, 0.001244f, 0.557129f, 0.563477f, 0.563477f, 0.564941f, 0.564941f, 0.564941f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000002f, 0.000003f,
+ 0.000003f, 0.000004f, 0.000003f, 0.000003f, 0.000003f, 0.000002f, 0.000003f, 0.000003f, 0.000003f, 0.000012f, 0.513672f, 0.520020f,
+ 0.520020f, 0.520508f, 0.521484f, 0.521484f,
+ },
+ {
+ 0.103943f, 0.284912f, 0.422119f, 0.523438f, 0.600586f, 0.659668f, 0.705078f, 0.741699f, 0.771484f, 0.795898f, 0.816895f, 0.834961f,
+ 0.850586f, 0.862793f, 0.874512f, 0.884277f, 0.894043f, 0.901855f, 0.909180f, 0.915039f, 0.921387f, 0.926270f, 0.932129f, 0.936035f,
+ 0.940430f, 0.944336f, 0.948242f, 0.951660f, 0.954590f, 0.957520f, 0.959961f, 0.962891f, 0.965332f, 0.967285f, 0.969727f, 0.971680f,
+ 0.973145f, 0.975586f, 0.977051f, 0.979004f, 0.979980f, 0.981934f, 0.983887f, 0.984375f, 0.985840f, 0.986816f, 0.988770f, 0.989258f,
+ 0.990723f, 0.992188f, 0.992676f, 0.993652f, 0.994629f, 0.995605f, 0.996582f, 0.997559f, 0.998535f, 0.999023f, 0.999512f, 0.999023f,
+ 0.998535f, 0.998047f, 0.997559f, 0.997070f, 0.046997f, 0.153564f, 0.264160f, 0.369385f, 0.460205f, 0.538574f, 0.602051f, 0.654785f,
+ 0.697754f, 0.733398f, 0.762695f, 0.787598f, 0.809082f, 0.827637f, 0.843262f, 0.856934f, 0.868652f, 0.880859f, 0.889648f, 0.898438f,
+ 0.906738f, 0.912598f, 0.918945f, 0.924805f, 0.929688f, 0.935059f, 0.938965f, 0.943359f, 0.947266f, 0.951172f, 0.954102f, 0.956543f,
+ 0.959961f, 0.961914f, 0.964844f, 0.966797f, 0.969727f, 0.971191f, 0.974121f, 0.975098f, 0.977051f, 0.979492f, 0.980469f, 0.981934f,
+ 0.983887f, 0.985352f, 0.985840f, 0.987305f, 0.989258f, 0.990234f, 0.991211f, 0.992188f, 0.993164f, 0.994141f, 0.995117f, 0.996094f,
+ 0.996582f, 0.997559f, 0.999023f, 0.998535f, 0.998047f, 0.997559f, 0.997070f, 0.997070f, 0.025940f, 0.088501f, 0.162964f, 0.246094f,
+ 0.331055f, 0.411865f, 0.486328f, 0.550293f, 0.606934f, 0.655762f, 0.695312f, 0.729980f, 0.758301f, 0.783691f, 0.804199f, 0.823730f,
+ 0.838867f, 0.853027f, 0.865723f, 0.877441f, 0.887207f, 0.895996f, 0.904785f, 0.911133f, 0.916992f, 0.923828f, 0.928223f, 0.933594f,
+ 0.937988f, 0.942871f, 0.946777f, 0.950195f, 0.953613f, 0.956543f, 0.959473f, 0.962402f, 0.964844f, 0.967285f, 0.970215f, 0.971680f,
+ 0.973633f, 0.976074f, 0.977539f, 0.979492f, 0.980469f, 0.982422f, 0.984863f, 0.985352f, 0.986816f, 0.987793f, 0.989258f, 0.990234f,
+ 0.991699f, 0.992676f, 0.994141f, 0.995117f, 0.995605f, 0.996582f, 0.998535f, 0.998047f, 0.998047f, 0.997559f, 0.997070f, 0.996582f,
+ 0.016159f, 0.055176f, 0.104126f, 0.162720f, 0.229126f, 0.300781f, 0.372803f, 0.442871f, 0.506836f, 0.563477f, 0.613281f, 0.657715f,
+ 0.696289f, 0.729004f, 0.757324f, 0.782227f, 0.802734f, 0.821289f, 0.837402f, 0.852539f, 0.865234f, 0.875977f, 0.885742f, 0.895508f,
+ 0.903320f, 0.910156f, 0.917480f, 0.922852f, 0.928711f, 0.934082f, 0.937988f, 0.942871f, 0.947266f, 0.950195f, 0.954102f, 0.957031f,
+ 0.959473f, 0.962402f, 0.964844f, 0.968262f, 0.969727f, 0.972168f, 0.974121f, 0.976562f, 0.978516f, 0.979980f, 0.981934f, 0.982910f,
+ 0.983887f, 0.985840f, 0.986816f, 0.988770f, 0.989746f, 0.991211f, 0.992188f, 0.993652f, 0.994141f, 0.995117f, 0.998047f, 0.997559f,
+ 0.997559f, 0.997070f, 0.996582f, 0.996582f, 0.010841f, 0.036865f, 0.070007f, 0.110962f, 0.159546f, 0.214355f, 0.276367f, 0.340576f,
+ 0.405029f, 0.465820f, 0.523926f, 0.576172f, 0.623535f, 0.664062f, 0.699707f, 0.731445f, 0.758301f, 0.782227f, 0.803223f, 0.821289f,
+ 0.837891f, 0.852051f, 0.864258f, 0.875488f, 0.884766f, 0.894531f, 0.903320f, 0.910156f, 0.916992f, 0.923828f, 0.928223f, 0.933594f,
+ 0.938477f, 0.943359f, 0.947266f, 0.950684f, 0.954102f, 0.957520f, 0.960449f, 0.962891f, 0.965820f, 0.968750f, 0.971191f, 0.973145f,
+ 0.975586f, 0.977539f, 0.978516f, 0.980957f, 0.982422f, 0.984375f, 0.985352f, 0.987305f, 0.988281f, 0.989746f, 0.990723f, 0.992188f,
+ 0.993164f, 0.994141f, 0.997559f, 0.997559f, 0.997070f, 0.996582f, 0.996582f, 0.996094f, 0.007637f, 0.026566f, 0.049896f, 0.078247f,
+ 0.113403f, 0.154663f, 0.202637f, 0.255371f, 0.313232f, 0.372314f, 0.431152f, 0.488037f, 0.540039f, 0.588867f, 0.633301f, 0.670898f,
+ 0.704102f, 0.734375f, 0.761230f, 0.785156f, 0.804688f, 0.822754f, 0.838867f, 0.852539f, 0.864746f, 0.876953f, 0.886230f, 0.895996f,
+ 0.903320f, 0.910645f, 0.917480f, 0.923828f, 0.929199f, 0.935059f, 0.938965f, 0.943359f, 0.948730f, 0.952148f, 0.954590f, 0.958496f,
+ 0.961426f, 0.964355f, 0.966797f, 0.969238f, 0.971680f, 0.974121f, 0.976074f, 0.978027f, 0.979980f, 0.981445f, 0.982910f, 0.984863f,
+ 0.986816f, 0.987793f, 0.989258f, 0.990723f, 0.991699f, 0.993164f, 0.996582f, 0.996582f, 0.996094f, 0.996094f, 0.996094f, 0.995605f,
+ 0.005714f, 0.019485f, 0.036194f, 0.056976f, 0.082336f, 0.113342f, 0.149048f, 0.191284f, 0.238770f, 0.290039f, 0.344727f, 0.400391f,
+ 0.454590f, 0.507324f, 0.557129f, 0.602539f, 0.642578f, 0.679199f, 0.711426f, 0.740234f, 0.766602f, 0.788574f, 0.807617f, 0.825195f,
+ 0.841309f, 0.854980f, 0.867676f, 0.877930f, 0.888184f, 0.896484f, 0.904785f, 0.912109f, 0.918945f, 0.925293f, 0.930176f, 0.935547f,
+ 0.940918f, 0.944336f, 0.948730f, 0.952637f, 0.956055f, 0.959473f, 0.962402f, 0.965332f, 0.967773f, 0.970703f, 0.972656f, 0.975098f,
+ 0.977051f, 0.979004f, 0.981445f, 0.982910f, 0.984375f, 0.985840f, 0.987793f, 0.989258f, 0.990234f, 0.991211f, 0.996094f, 0.996094f,
+ 0.996094f, 0.996094f, 0.995605f, 0.995117f, 0.004505f, 0.014908f, 0.027634f, 0.043274f, 0.061707f, 0.084045f, 0.111694f, 0.143921f,
+ 0.180542f, 0.223877f, 0.270996f, 0.320557f, 0.373291f, 0.425781f, 0.478027f, 0.526855f, 0.573242f, 0.615723f, 0.654785f, 0.688965f,
+ 0.720215f, 0.747559f, 0.771973f, 0.793457f, 0.812500f, 0.829102f, 0.844238f, 0.858398f, 0.870117f, 0.881348f, 0.890625f, 0.898926f,
+ 0.906738f, 0.914062f, 0.921387f, 0.926758f, 0.932617f, 0.937500f, 0.942383f, 0.945801f, 0.950684f, 0.954102f, 0.958008f, 0.960938f,
+ 0.964355f, 0.966797f, 0.969727f, 0.972656f, 0.974609f, 0.976562f, 0.978516f, 0.980469f, 0.981934f, 0.984375f, 0.985840f, 0.987793f,
+ 0.988281f, 0.990234f, 0.995605f, 0.995605f, 0.995605f, 0.995605f, 0.995117f, 0.994629f, 0.003691f, 0.011925f, 0.021622f, 0.033203f,
+ 0.047241f, 0.065247f, 0.085266f, 0.109558f, 0.138550f, 0.172363f, 0.210205f, 0.253418f, 0.299805f, 0.348877f, 0.400146f, 0.450195f,
+ 0.499512f, 0.546387f, 0.589844f, 0.629883f, 0.666016f, 0.700195f, 0.728516f, 0.755371f, 0.778320f, 0.798828f, 0.817383f, 0.833984f,
+ 0.848145f, 0.861816f, 0.874023f, 0.883789f, 0.893555f, 0.902344f, 0.910645f, 0.916992f, 0.922852f, 0.929688f, 0.934570f, 0.938965f,
+ 0.944336f, 0.948730f, 0.951660f, 0.956543f, 0.959473f, 0.962891f, 0.965820f, 0.968262f, 0.970703f, 0.974121f, 0.976074f, 0.978516f,
+ 0.979980f, 0.981934f, 0.983887f, 0.985840f, 0.987305f, 0.988281f, 0.994629f, 0.995117f, 0.995117f, 0.994629f, 0.994629f, 0.994141f,
+ 0.002726f, 0.009560f, 0.017136f, 0.026871f, 0.037415f, 0.050079f, 0.066406f, 0.084717f, 0.107849f, 0.133423f, 0.164062f, 0.198853f,
+ 0.238281f, 0.281250f, 0.327148f, 0.375977f, 0.424805f, 0.473877f, 0.521973f, 0.564941f, 0.606934f, 0.644531f, 0.679199f, 0.710449f,
+ 0.738770f, 0.764160f, 0.786133f, 0.805664f, 0.824219f, 0.838867f, 0.853516f, 0.866211f, 0.876953f, 0.887695f, 0.896484f, 0.905762f,
+ 0.912598f, 0.919922f, 0.925781f, 0.932129f, 0.937500f, 0.942383f, 0.946777f, 0.951660f, 0.955078f, 0.958984f, 0.961426f, 0.965332f,
+ 0.967773f, 0.970703f, 0.972656f, 0.975586f, 0.978027f, 0.979492f, 0.981934f, 0.983887f, 0.984863f, 0.986816f, 0.994629f, 0.994629f,
+ 0.994629f, 0.994141f, 0.994141f, 0.993652f, 0.002487f, 0.007553f, 0.013863f, 0.021439f, 0.029755f, 0.040771f, 0.052643f, 0.067444f,
+ 0.084473f, 0.104980f, 0.128784f, 0.157227f, 0.189087f, 0.224609f, 0.265381f, 0.308838f, 0.354004f, 0.401611f, 0.450439f, 0.496582f,
+ 0.541992f, 0.583984f, 0.623047f, 0.660645f, 0.693359f, 0.722168f, 0.749512f, 0.772949f, 0.793457f, 0.812988f, 0.830078f, 0.845215f,
+ 0.859375f, 0.871094f, 0.882812f, 0.892090f, 0.900879f, 0.908691f, 0.916504f, 0.922852f, 0.930176f, 0.935547f, 0.940430f, 0.944824f,
+ 0.949219f, 0.952637f, 0.956543f, 0.960449f, 0.963867f, 0.967285f, 0.970215f, 0.972656f, 0.974609f, 0.977539f, 0.979492f, 0.981934f,
+ 0.983887f, 0.985352f, 0.993652f, 0.994141f, 0.994141f, 0.993652f, 0.993652f, 0.993164f, 0.001893f, 0.006641f, 0.011551f, 0.017319f,
+ 0.024612f, 0.032959f, 0.042023f, 0.053772f, 0.067444f, 0.083435f, 0.102356f, 0.123840f, 0.150024f, 0.179688f, 0.213501f, 0.250488f,
+ 0.291992f, 0.335938f, 0.381592f, 0.427246f, 0.473877f, 0.518555f, 0.563477f, 0.603027f, 0.640625f, 0.676270f, 0.707031f, 0.735352f,
+ 0.760254f, 0.782715f, 0.802734f, 0.821777f, 0.838379f, 0.851562f, 0.865234f, 0.876953f, 0.886719f, 0.896484f, 0.905273f, 0.913086f,
+ 0.921387f, 0.927734f, 0.933105f, 0.938477f, 0.942871f, 0.948242f, 0.951660f, 0.955566f, 0.959961f, 0.963867f, 0.966309f, 0.969238f,
+ 0.972168f, 0.975098f, 0.977539f, 0.979492f, 0.981934f, 0.983887f, 0.993164f, 0.993652f, 0.993164f, 0.993164f, 0.993164f, 0.992676f,
+ 0.001740f, 0.005634f, 0.009407f, 0.014992f, 0.020157f, 0.026840f, 0.035156f, 0.043793f, 0.054718f, 0.067505f, 0.082092f, 0.099731f,
+ 0.120239f, 0.143921f, 0.171265f, 0.202393f, 0.237915f, 0.276367f, 0.318848f, 0.362793f, 0.407959f, 0.454346f, 0.499023f, 0.542480f,
+ 0.583984f, 0.623535f, 0.659180f, 0.691895f, 0.721680f, 0.748047f, 0.772461f, 0.793457f, 0.812988f, 0.829102f, 0.845215f, 0.859863f,
+ 0.872559f, 0.883789f, 0.893555f, 0.902344f, 0.911133f, 0.918457f, 0.924805f, 0.930664f, 0.937012f, 0.941895f, 0.947266f, 0.951172f,
+ 0.956055f, 0.959473f, 0.962402f, 0.966309f, 0.968750f, 0.972168f, 0.974609f, 0.977051f, 0.979492f, 0.981934f, 0.992188f, 0.992676f,
+ 0.992676f, 0.992676f, 0.992188f, 0.992676f, 0.001502f, 0.004482f, 0.008278f, 0.012276f, 0.016800f, 0.022644f, 0.029129f, 0.036194f,
+ 0.045197f, 0.055298f, 0.067017f, 0.080750f, 0.096863f, 0.115906f, 0.138184f, 0.163940f, 0.192993f, 0.225952f, 0.262695f, 0.302490f,
+ 0.344971f, 0.389648f, 0.434814f, 0.480469f, 0.523926f, 0.566406f, 0.605957f, 0.643066f, 0.677246f, 0.708496f, 0.736816f, 0.761719f,
+ 0.784668f, 0.804688f, 0.823242f, 0.840332f, 0.854004f, 0.867188f, 0.878906f, 0.890137f, 0.898438f, 0.907715f, 0.916016f, 0.922852f,
+ 0.930176f, 0.935547f, 0.940918f, 0.946289f, 0.950684f, 0.955078f, 0.959473f, 0.961914f, 0.966309f, 0.969238f, 0.972168f, 0.974609f,
+ 0.977539f, 0.979492f, 0.991211f, 0.992188f, 0.991699f, 0.992188f, 0.991699f, 0.991211f, 0.001411f, 0.003645f, 0.007160f, 0.010414f,
+ 0.014397f, 0.018677f, 0.024338f, 0.030426f, 0.037384f, 0.045654f, 0.055054f, 0.066101f, 0.079529f, 0.094543f, 0.112793f, 0.133057f,
+ 0.157227f, 0.183960f, 0.215210f, 0.250488f, 0.288086f, 0.329102f, 0.372314f, 0.416992f, 0.461914f, 0.505859f, 0.549316f, 0.589355f,
+ 0.627930f, 0.664062f, 0.695801f, 0.725098f, 0.752441f, 0.775879f, 0.797363f, 0.815918f, 0.833984f, 0.849121f, 0.863281f, 0.875488f,
+ 0.886230f, 0.895996f, 0.904785f, 0.914062f, 0.920898f, 0.928223f, 0.935059f, 0.940918f, 0.945312f, 0.950195f, 0.954102f, 0.958984f,
+ 0.962402f, 0.966309f, 0.969238f, 0.972656f, 0.974609f, 0.977539f, 0.990234f, 0.992188f, 0.991211f, 0.991211f, 0.990723f, 0.991211f,
+ 0.000926f, 0.003523f, 0.006207f, 0.008949f, 0.012718f, 0.016312f, 0.020447f, 0.025467f, 0.031128f, 0.037994f, 0.045532f, 0.054901f,
+ 0.065430f, 0.077576f, 0.091797f, 0.109131f, 0.128418f, 0.151245f, 0.176636f, 0.206055f, 0.238525f, 0.275146f, 0.314697f, 0.357178f,
+ 0.400391f, 0.445312f, 0.489746f, 0.531738f, 0.574219f, 0.613281f, 0.650391f, 0.683594f, 0.714355f, 0.742188f, 0.768066f, 0.790039f,
+ 0.810059f, 0.828125f, 0.843262f, 0.858398f, 0.871582f, 0.883789f, 0.893555f, 0.903809f, 0.912598f, 0.919434f, 0.926758f, 0.933594f,
+ 0.939453f, 0.944336f, 0.950195f, 0.954590f, 0.958008f, 0.962402f, 0.966309f, 0.969727f, 0.972656f, 0.975586f, 0.989746f, 0.990723f,
+ 0.990723f, 0.990234f, 0.990234f, 0.990234f, 0.001140f, 0.003021f, 0.005527f, 0.008102f, 0.010445f, 0.013977f, 0.017349f, 0.021637f,
+ 0.026535f, 0.031677f, 0.038330f, 0.045776f, 0.054382f, 0.064392f, 0.076233f, 0.089844f, 0.105713f, 0.123840f, 0.145020f, 0.169556f,
+ 0.196899f, 0.229248f, 0.263672f, 0.302002f, 0.342529f, 0.385986f, 0.429932f, 0.473877f, 0.517578f, 0.560547f, 0.600586f, 0.638184f,
+ 0.672852f, 0.704590f, 0.733398f, 0.759277f, 0.782715f, 0.803711f, 0.823242f, 0.840820f, 0.854980f, 0.869141f, 0.881348f, 0.892090f,
+ 0.902344f, 0.910645f, 0.919922f, 0.927246f, 0.933105f, 0.938965f, 0.944824f, 0.949707f, 0.954102f, 0.959473f, 0.962891f, 0.966309f,
+ 0.969727f, 0.972168f, 0.988770f, 0.990234f, 0.989746f, 0.989746f, 0.989746f, 0.989258f, 0.000870f, 0.002666f, 0.004578f, 0.006737f,
+ 0.009430f, 0.012077f, 0.015381f, 0.018463f, 0.022293f, 0.027313f, 0.032654f, 0.038727f, 0.045746f, 0.053619f, 0.063232f, 0.074524f,
+ 0.087219f, 0.102356f, 0.119324f, 0.139648f, 0.162842f, 0.189941f, 0.219482f, 0.253174f, 0.289795f, 0.329346f, 0.372070f, 0.415039f,
+ 0.459717f, 0.503418f, 0.546387f, 0.587402f, 0.625977f, 0.661621f, 0.694336f, 0.725586f, 0.752441f, 0.776855f, 0.798828f, 0.818359f,
+ 0.837402f, 0.852539f, 0.866699f, 0.878906f, 0.891113f, 0.900879f, 0.910156f, 0.918457f, 0.926270f, 0.932617f, 0.938965f, 0.944824f,
+ 0.950195f, 0.955078f, 0.958984f, 0.962891f, 0.966797f, 0.970703f, 0.987793f, 0.988770f, 0.989258f, 0.989258f, 0.988770f, 0.988770f,
+ 0.000835f, 0.002302f, 0.004078f, 0.005802f, 0.008026f, 0.010490f, 0.013153f, 0.016235f, 0.019485f, 0.023636f, 0.027847f, 0.033081f,
+ 0.038849f, 0.045441f, 0.053253f, 0.062500f, 0.072571f, 0.085205f, 0.098999f, 0.115662f, 0.135254f, 0.156860f, 0.182373f, 0.211060f,
+ 0.243042f, 0.279053f, 0.318115f, 0.359619f, 0.402832f, 0.447021f, 0.490234f, 0.533691f, 0.575195f, 0.615234f, 0.651855f, 0.686035f,
+ 0.717285f, 0.746094f, 0.771484f, 0.793945f, 0.813965f, 0.833496f, 0.848633f, 0.864258f, 0.877930f, 0.889648f, 0.900391f, 0.909180f,
+ 0.918945f, 0.926270f, 0.932129f, 0.939453f, 0.945312f, 0.950684f, 0.955566f, 0.959473f, 0.963867f, 0.967773f, 0.987305f, 0.988281f,
+ 0.988281f, 0.988281f, 0.988281f, 0.987793f, 0.000815f, 0.001984f, 0.003475f, 0.005302f, 0.007103f, 0.009354f, 0.011528f, 0.013977f,
+ 0.017197f, 0.020111f, 0.023788f, 0.027771f, 0.033447f, 0.038452f, 0.045013f, 0.052704f, 0.061066f, 0.071228f, 0.082886f, 0.096313f,
+ 0.112488f, 0.130737f, 0.151245f, 0.175659f, 0.203125f, 0.234619f, 0.269043f, 0.306885f, 0.347656f, 0.390381f, 0.434570f, 0.478760f,
+ 0.522461f, 0.564453f, 0.605957f, 0.644043f, 0.678223f, 0.710449f, 0.739746f, 0.766602f, 0.791016f, 0.811035f, 0.831055f, 0.847168f,
+ 0.862793f, 0.875977f, 0.888672f, 0.899414f, 0.909180f, 0.917480f, 0.926270f, 0.933105f, 0.939941f, 0.945801f, 0.950684f, 0.955566f,
+ 0.960938f, 0.964844f, 0.985840f, 0.987305f, 0.987793f, 0.987305f, 0.987305f, 0.987305f, 0.000587f, 0.002005f, 0.003122f, 0.004707f,
+ 0.006283f, 0.007778f, 0.009972f, 0.012581f, 0.014435f, 0.017426f, 0.020691f, 0.024475f, 0.028519f, 0.033203f, 0.038513f, 0.044708f,
+ 0.051727f, 0.060028f, 0.069763f, 0.080627f, 0.093506f, 0.109009f, 0.125977f, 0.146362f, 0.169678f, 0.196533f, 0.226685f, 0.259766f,
+ 0.297119f, 0.337646f, 0.380127f, 0.424072f, 0.468018f, 0.512207f, 0.555176f, 0.596680f, 0.635254f, 0.671387f, 0.704590f, 0.734863f,
+ 0.762207f, 0.787109f, 0.809082f, 0.828613f, 0.846191f, 0.860840f, 0.875977f, 0.888184f, 0.899902f, 0.908691f, 0.918457f, 0.926270f,
+ 0.934082f, 0.940430f, 0.947266f, 0.951660f, 0.958008f, 0.961914f, 0.984863f, 0.986328f, 0.986816f, 0.986816f, 0.986328f, 0.986328f,
+ 0.000475f, 0.001671f, 0.003019f, 0.004379f, 0.005592f, 0.006882f, 0.008682f, 0.010757f, 0.012856f, 0.015343f, 0.018112f, 0.021164f,
+ 0.024353f, 0.028595f, 0.033020f, 0.038086f, 0.044006f, 0.050812f, 0.058594f, 0.067993f, 0.078735f, 0.091248f, 0.105530f, 0.122009f,
+ 0.142212f, 0.164062f, 0.189697f, 0.219238f, 0.251953f, 0.288330f, 0.328125f, 0.369629f, 0.413818f, 0.458008f, 0.503418f, 0.547363f,
+ 0.588867f, 0.628418f, 0.665039f, 0.699707f, 0.730469f, 0.758301f, 0.784668f, 0.807129f, 0.826660f, 0.844727f, 0.862305f, 0.875977f,
+ 0.888672f, 0.900879f, 0.910156f, 0.919434f, 0.927734f, 0.935059f, 0.941406f, 0.947754f, 0.953125f, 0.958496f, 0.983887f, 0.985352f,
+ 0.985352f, 0.985352f, 0.984863f, 0.985352f, 0.000325f, 0.001517f, 0.002554f, 0.003811f, 0.004990f, 0.006638f, 0.007706f, 0.009399f,
+ 0.011177f, 0.013580f, 0.015671f, 0.018478f, 0.021393f, 0.024612f, 0.028442f, 0.032990f, 0.037750f, 0.043427f, 0.050354f, 0.057861f,
+ 0.066101f, 0.076294f, 0.088684f, 0.102417f, 0.119080f, 0.137451f, 0.159058f, 0.183838f, 0.212524f, 0.244385f, 0.280273f, 0.319336f,
+ 0.361084f, 0.405029f, 0.449707f, 0.494873f, 0.539551f, 0.582031f, 0.622559f, 0.660156f, 0.695801f, 0.727539f, 0.756348f, 0.782715f,
+ 0.805664f, 0.826172f, 0.845215f, 0.861328f, 0.875977f, 0.889648f, 0.901367f, 0.910645f, 0.920410f, 0.928711f, 0.937012f, 0.942871f,
+ 0.949219f, 0.955078f, 0.982422f, 0.983887f, 0.984375f, 0.984375f, 0.983887f, 0.983887f, 0.000349f, 0.001533f, 0.002413f, 0.003326f,
+ 0.004463f, 0.005524f, 0.006954f, 0.008202f, 0.010025f, 0.011864f, 0.013924f, 0.015884f, 0.018478f, 0.021484f, 0.024658f, 0.028671f,
+ 0.032562f, 0.037170f, 0.042969f, 0.049194f, 0.056641f, 0.065063f, 0.074951f, 0.086182f, 0.099731f, 0.115662f, 0.133789f, 0.154175f,
+ 0.178589f, 0.206421f, 0.237671f, 0.272949f, 0.312012f, 0.352783f, 0.396973f, 0.442627f, 0.487793f, 0.532227f, 0.576660f, 0.617188f,
+ 0.657227f, 0.692383f, 0.725586f, 0.754395f, 0.780762f, 0.805664f, 0.826172f, 0.845215f, 0.861816f, 0.876465f, 0.890137f, 0.902344f,
+ 0.912598f, 0.921875f, 0.930176f, 0.937988f, 0.945312f, 0.952148f, 0.981445f, 0.982910f, 0.982910f, 0.983398f, 0.983398f, 0.983398f,
+ 0.000475f, 0.001141f, 0.002058f, 0.002846f, 0.004120f, 0.005013f, 0.006207f, 0.007664f, 0.009193f, 0.010368f, 0.012222f, 0.014404f,
+ 0.016403f, 0.018799f, 0.021439f, 0.024567f, 0.028076f, 0.032379f, 0.036652f, 0.042145f, 0.048157f, 0.055389f, 0.063660f, 0.073059f,
+ 0.083740f, 0.097046f, 0.112366f, 0.129517f, 0.149780f, 0.173584f, 0.200684f, 0.231812f, 0.266357f, 0.304688f, 0.346680f, 0.390137f,
+ 0.435547f, 0.481445f, 0.526367f, 0.572266f, 0.613770f, 0.653320f, 0.690430f, 0.723633f, 0.754395f, 0.781250f, 0.806152f, 0.826172f,
+ 0.847168f, 0.862793f, 0.878906f, 0.892090f, 0.904297f, 0.914551f, 0.924316f, 0.933105f, 0.940430f, 0.947754f, 0.979492f, 0.981934f,
+ 0.981934f, 0.981934f, 0.981445f, 0.981445f, 0.000239f, 0.000882f, 0.001744f, 0.002878f, 0.003819f, 0.004532f, 0.005550f, 0.006653f,
+ 0.007942f, 0.009277f, 0.010628f, 0.012421f, 0.014397f, 0.016312f, 0.018845f, 0.021576f, 0.024536f, 0.027817f, 0.031860f, 0.036346f,
+ 0.041595f, 0.047333f, 0.054138f, 0.062317f, 0.071350f, 0.081970f, 0.094299f, 0.109070f, 0.126221f, 0.146118f, 0.169067f, 0.195801f,
+ 0.226196f, 0.260742f, 0.298584f, 0.340088f, 0.384277f, 0.429688f, 0.476807f, 0.522461f, 0.568359f, 0.611328f, 0.651855f, 0.689453f,
+ 0.723633f, 0.754395f, 0.782715f, 0.807617f, 0.829590f, 0.848145f, 0.865723f, 0.880859f, 0.894531f, 0.906738f, 0.917969f, 0.927246f,
+ 0.936035f, 0.943359f, 0.978027f, 0.979980f, 0.980469f, 0.980469f, 0.980469f, 0.980469f, 0.000240f, 0.000948f, 0.001495f, 0.002592f,
+ 0.003241f, 0.004055f, 0.004856f, 0.006111f, 0.007133f, 0.008125f, 0.009445f, 0.011108f, 0.012474f, 0.014374f, 0.016586f, 0.018784f,
+ 0.021286f, 0.024475f, 0.027481f, 0.031403f, 0.035828f, 0.040710f, 0.046204f, 0.052704f, 0.060577f, 0.069519f, 0.079651f, 0.092224f,
+ 0.106506f, 0.122986f, 0.142456f, 0.165161f, 0.191284f, 0.221924f, 0.255615f, 0.293457f, 0.335205f, 0.379395f, 0.425537f, 0.472900f,
+ 0.519531f, 0.566406f, 0.610840f, 0.652344f, 0.689941f, 0.724609f, 0.755371f, 0.784180f, 0.808594f, 0.831055f, 0.851562f, 0.869141f,
+ 0.884277f, 0.897461f, 0.909668f, 0.920410f, 0.930176f, 0.937988f, 0.976562f, 0.979004f, 0.979492f, 0.979492f, 0.979492f, 0.979492f,
+ 0.000302f, 0.000863f, 0.001315f, 0.002195f, 0.002905f, 0.003592f, 0.004784f, 0.005478f, 0.006199f, 0.007389f, 0.008545f, 0.009811f,
+ 0.011185f, 0.012787f, 0.014603f, 0.016342f, 0.018784f, 0.021347f, 0.024033f, 0.027496f, 0.031006f, 0.034790f, 0.039856f, 0.045288f,
+ 0.051636f, 0.059052f, 0.067566f, 0.078003f, 0.089905f, 0.103760f, 0.119934f, 0.139282f, 0.161865f, 0.187622f, 0.217407f, 0.251221f,
+ 0.288818f, 0.330811f, 0.375244f, 0.422607f, 0.470703f, 0.518066f, 0.565430f, 0.609863f, 0.651855f, 0.691406f, 0.726562f, 0.758301f,
+ 0.787109f, 0.812500f, 0.835449f, 0.855957f, 0.872559f, 0.887695f, 0.901367f, 0.913574f, 0.923828f, 0.933105f, 0.975098f, 0.977539f,
+ 0.977539f, 0.977539f, 0.978027f, 0.977051f, 0.000240f, 0.000808f, 0.001537f, 0.002106f, 0.002493f, 0.003729f, 0.004036f, 0.004982f,
+ 0.005539f, 0.006454f, 0.007526f, 0.008690f, 0.009987f, 0.011421f, 0.012894f, 0.014618f, 0.016464f, 0.018539f, 0.021118f, 0.023865f,
+ 0.026794f, 0.030487f, 0.034241f, 0.038879f, 0.044067f, 0.050690f, 0.057678f, 0.066040f, 0.076111f, 0.087524f, 0.101379f, 0.117737f,
+ 0.136353f, 0.158325f, 0.183594f, 0.213501f, 0.247192f, 0.284912f, 0.327393f, 0.372803f, 0.420410f, 0.468750f, 0.518066f, 0.565430f,
+ 0.611328f, 0.654297f, 0.694336f, 0.729980f, 0.762207f, 0.791504f, 0.817383f, 0.839844f, 0.859863f, 0.876953f, 0.891602f, 0.905762f,
+ 0.917480f, 0.928711f, 0.973633f, 0.975098f, 0.976562f, 0.975586f, 0.976562f, 0.976562f, 0.000240f, 0.000587f, 0.001223f, 0.001691f,
+ 0.002499f, 0.003008f, 0.003643f, 0.004295f, 0.004795f, 0.005726f, 0.006649f, 0.007671f, 0.008766f, 0.010002f, 0.011307f, 0.012764f,
+ 0.014465f, 0.016388f, 0.018387f, 0.020599f, 0.023453f, 0.026291f, 0.029572f, 0.033417f, 0.037964f, 0.043427f, 0.049316f, 0.056519f,
+ 0.064819f, 0.074219f, 0.085693f, 0.099121f, 0.115112f, 0.133301f, 0.155273f, 0.180420f, 0.210205f, 0.244751f, 0.282715f, 0.324951f,
+ 0.371338f, 0.419434f, 0.468994f, 0.518555f, 0.566895f, 0.613770f, 0.658203f, 0.698242f, 0.735352f, 0.766602f, 0.796875f, 0.821289f,
+ 0.844238f, 0.863770f, 0.881836f, 0.896973f, 0.910156f, 0.922363f, 0.971191f, 0.974121f, 0.974609f, 0.974121f, 0.974609f, 0.974609f,
+ 0.000228f, 0.000671f, 0.001122f, 0.001607f, 0.002291f, 0.002836f, 0.003319f, 0.003817f, 0.004509f, 0.005253f, 0.005894f, 0.006840f,
+ 0.007820f, 0.008972f, 0.010086f, 0.011391f, 0.012848f, 0.014328f, 0.016266f, 0.018158f, 0.020447f, 0.022720f, 0.026031f, 0.029053f,
+ 0.032593f, 0.037109f, 0.042236f, 0.048340f, 0.055115f, 0.063049f, 0.072632f, 0.083801f, 0.097351f, 0.112488f, 0.130493f, 0.152222f,
+ 0.178101f, 0.208008f, 0.241943f, 0.280762f, 0.323730f, 0.370117f, 0.419434f, 0.470459f, 0.520996f, 0.570801f, 0.617676f, 0.663086f,
+ 0.704102f, 0.740234f, 0.773438f, 0.802246f, 0.829102f, 0.850098f, 0.870117f, 0.887695f, 0.902832f, 0.916016f, 0.969238f, 0.972168f,
+ 0.972168f, 0.972656f, 0.972656f, 0.972168f, 0.000121f, 0.000526f, 0.001092f, 0.001670f, 0.001744f, 0.002420f, 0.002945f, 0.003237f,
+ 0.004013f, 0.004894f, 0.005421f, 0.005932f, 0.006996f, 0.007904f, 0.008873f, 0.009995f, 0.011391f, 0.012756f, 0.014053f, 0.015884f,
+ 0.017715f, 0.019775f, 0.022324f, 0.025406f, 0.028290f, 0.032349f, 0.036560f, 0.041412f, 0.047058f, 0.053772f, 0.061493f, 0.070862f,
+ 0.081848f, 0.094666f, 0.110229f, 0.128662f, 0.150024f, 0.175903f, 0.205566f, 0.239990f, 0.279785f, 0.323486f, 0.370850f, 0.421143f,
+ 0.473633f, 0.524902f, 0.576172f, 0.625000f, 0.668457f, 0.710938f, 0.748535f, 0.781250f, 0.810059f, 0.835449f, 0.857910f, 0.877441f,
+ 0.894531f, 0.908691f, 0.966797f, 0.970215f, 0.970703f, 0.970703f, 0.970703f, 0.970215f, 0.000127f, 0.000521f, 0.001083f, 0.001460f,
+ 0.001684f, 0.002111f, 0.002563f, 0.003048f, 0.003618f, 0.004124f, 0.004936f, 0.005543f, 0.006340f, 0.007111f, 0.008049f, 0.008774f,
+ 0.009865f, 0.011162f, 0.012360f, 0.013840f, 0.015465f, 0.017181f, 0.019531f, 0.021973f, 0.024582f, 0.027847f, 0.031342f, 0.035706f,
+ 0.040100f, 0.045990f, 0.052521f, 0.060089f, 0.069214f, 0.080017f, 0.093079f, 0.108521f, 0.126709f, 0.148071f, 0.174072f, 0.204224f,
+ 0.239502f, 0.279541f, 0.324219f, 0.373047f, 0.424805f, 0.477295f, 0.530762f, 0.583008f, 0.632324f, 0.677246f, 0.719727f, 0.756348f,
+ 0.789551f, 0.819336f, 0.842773f, 0.866211f, 0.885742f, 0.901855f, 0.965332f, 0.967773f, 0.968262f, 0.967773f, 0.968750f, 0.968262f,
+ 0.000244f, 0.000397f, 0.001001f, 0.001181f, 0.001642f, 0.001872f, 0.002460f, 0.002712f, 0.003061f, 0.003723f, 0.004520f, 0.005043f,
+ 0.005547f, 0.006451f, 0.007057f, 0.007828f, 0.008942f, 0.009872f, 0.010857f, 0.012131f, 0.013557f, 0.015198f, 0.017059f, 0.019241f,
+ 0.021454f, 0.024048f, 0.027069f, 0.030594f, 0.034332f, 0.039001f, 0.044952f, 0.050873f, 0.058716f, 0.067505f, 0.078369f, 0.091309f,
+ 0.106506f, 0.124695f, 0.146484f, 0.172852f, 0.203369f, 0.239014f, 0.280273f, 0.326172f, 0.376465f, 0.429443f, 0.483643f, 0.538574f,
+ 0.591309f, 0.641602f, 0.687500f, 0.729492f, 0.766602f, 0.800293f, 0.828613f, 0.854004f, 0.874512f, 0.893555f, 0.961914f, 0.965332f,
+ 0.965820f, 0.966309f, 0.966309f, 0.965820f, 0.000243f, 0.000453f, 0.000888f, 0.001245f, 0.001342f, 0.001847f, 0.002060f, 0.002541f,
+ 0.002991f, 0.003355f, 0.003679f, 0.004379f, 0.005177f, 0.005413f, 0.006283f, 0.007038f, 0.007896f, 0.008507f, 0.009552f, 0.010628f,
+ 0.011909f, 0.013306f, 0.015038f, 0.016388f, 0.018433f, 0.020752f, 0.023254f, 0.026413f, 0.029617f, 0.033447f, 0.037842f, 0.043701f,
+ 0.049896f, 0.057190f, 0.066101f, 0.076660f, 0.089600f, 0.104553f, 0.123230f, 0.145386f, 0.171387f, 0.202637f, 0.239624f, 0.281982f,
+ 0.329346f, 0.380859f, 0.436035f, 0.491943f, 0.547852f, 0.602539f, 0.653809f, 0.699707f, 0.741699f, 0.778320f, 0.811035f, 0.838867f,
+ 0.862793f, 0.884766f, 0.959961f, 0.963379f, 0.963379f, 0.963379f, 0.964355f, 0.963379f, 0.000241f, 0.000452f, 0.000798f, 0.001119f,
+ 0.001220f, 0.001430f, 0.001902f, 0.002277f, 0.002737f, 0.002893f, 0.003624f, 0.003937f, 0.004436f, 0.005089f, 0.005669f, 0.006226f,
+ 0.006680f, 0.007519f, 0.008568f, 0.009384f, 0.010422f, 0.011795f, 0.012840f, 0.014526f, 0.016235f, 0.017929f, 0.020218f, 0.022736f,
+ 0.025146f, 0.028580f, 0.032684f, 0.036896f, 0.042511f, 0.048431f, 0.055634f, 0.064453f, 0.075317f, 0.088196f, 0.103333f, 0.121948f,
+ 0.144287f, 0.171143f, 0.203491f, 0.241577f, 0.285156f, 0.334229f, 0.387939f, 0.444580f, 0.501953f, 0.559570f, 0.614746f, 0.666504f,
+ 0.712402f, 0.755371f, 0.791504f, 0.823242f, 0.851074f, 0.875000f, 0.956543f, 0.959961f, 0.960938f, 0.960449f, 0.960449f, 0.960449f,
+ 0.000000f, 0.000263f, 0.000693f, 0.000873f, 0.001183f, 0.001447f, 0.001476f, 0.002068f, 0.002171f, 0.002857f, 0.003164f, 0.003542f,
+ 0.003778f, 0.004326f, 0.004906f, 0.005436f, 0.006126f, 0.006687f, 0.007229f, 0.008377f, 0.009232f, 0.010223f, 0.011436f, 0.012527f,
+ 0.013832f, 0.015747f, 0.017365f, 0.019363f, 0.021667f, 0.024231f, 0.027695f, 0.031769f, 0.035889f, 0.041016f, 0.047028f, 0.054504f,
+ 0.063110f, 0.073975f, 0.086487f, 0.101807f, 0.120972f, 0.143555f, 0.171753f, 0.204956f, 0.244263f, 0.289551f, 0.340576f, 0.396484f,
+ 0.455078f, 0.514648f, 0.573730f, 0.630371f, 0.681152f, 0.729004f, 0.770020f, 0.806641f, 0.837402f, 0.863770f, 0.953613f, 0.956543f,
+ 0.957520f, 0.957031f, 0.957031f, 0.958008f, 0.000000f, 0.000356f, 0.000641f, 0.000870f, 0.000998f, 0.001134f, 0.001495f, 0.001724f,
+ 0.002436f, 0.002478f, 0.002775f, 0.003113f, 0.003435f, 0.003864f, 0.004314f, 0.004704f, 0.005276f, 0.005886f, 0.006599f, 0.007309f,
+ 0.008003f, 0.008987f, 0.009987f, 0.010941f, 0.012192f, 0.013466f, 0.015030f, 0.016708f, 0.018906f, 0.021103f, 0.023788f, 0.026886f,
+ 0.030457f, 0.034943f, 0.040009f, 0.045959f, 0.053162f, 0.061920f, 0.072144f, 0.085205f, 0.101257f, 0.120422f, 0.143555f, 0.172363f,
+ 0.206909f, 0.248047f, 0.295410f, 0.349121f, 0.407715f, 0.468750f, 0.530762f, 0.589844f, 0.647949f, 0.699707f, 0.746094f, 0.786621f,
+ 0.823242f, 0.852051f, 0.950195f, 0.953125f, 0.954102f, 0.954102f, 0.954102f, 0.954102f, 0.000231f, 0.000449f, 0.000516f, 0.000760f,
+ 0.000868f, 0.001152f, 0.001403f, 0.001773f, 0.002165f, 0.002245f, 0.002550f, 0.002783f, 0.003277f, 0.003660f, 0.003782f, 0.004120f,
+ 0.004631f, 0.005268f, 0.005795f, 0.006344f, 0.007053f, 0.007835f, 0.008598f, 0.009460f, 0.010689f, 0.011551f, 0.012726f, 0.014359f,
+ 0.016052f, 0.017975f, 0.020218f, 0.022812f, 0.025803f, 0.029251f, 0.033386f, 0.038574f, 0.044556f, 0.051941f, 0.060577f, 0.071045f,
+ 0.084106f, 0.100342f, 0.119751f, 0.144043f, 0.174194f, 0.209961f, 0.253418f, 0.303467f, 0.359619f, 0.420898f, 0.483887f, 0.547852f,
+ 0.609375f, 0.667480f, 0.719727f, 0.765625f, 0.804688f, 0.839844f, 0.946289f, 0.949707f, 0.950195f, 0.950684f, 0.950684f, 0.950195f,
+ 0.000201f, 0.000336f, 0.000452f, 0.000627f, 0.000793f, 0.000966f, 0.001134f, 0.001578f, 0.001790f, 0.001896f, 0.002254f, 0.002464f,
+ 0.002825f, 0.003012f, 0.003414f, 0.003626f, 0.004131f, 0.004608f, 0.005058f, 0.005642f, 0.006191f, 0.006771f, 0.007378f, 0.008057f,
+ 0.009132f, 0.009918f, 0.010826f, 0.012314f, 0.013794f, 0.015381f, 0.017197f, 0.019257f, 0.021912f, 0.024841f, 0.028259f, 0.032318f,
+ 0.037262f, 0.043427f, 0.050537f, 0.059021f, 0.070007f, 0.083191f, 0.099609f, 0.120239f, 0.145508f, 0.176636f, 0.214600f, 0.260254f,
+ 0.313232f, 0.372803f, 0.437012f, 0.503418f, 0.568359f, 0.631836f, 0.688965f, 0.741211f, 0.786621f, 0.825195f, 0.941406f, 0.946289f,
+ 0.946289f, 0.946777f, 0.946289f, 0.947266f, 0.000000f, 0.000317f, 0.000445f, 0.000453f, 0.000781f, 0.000794f, 0.001183f, 0.001289f,
+ 0.001479f, 0.001832f, 0.001874f, 0.002256f, 0.002270f, 0.002716f, 0.002960f, 0.003273f, 0.003630f, 0.003948f, 0.004467f, 0.004833f,
+ 0.005451f, 0.005962f, 0.006367f, 0.007088f, 0.007717f, 0.008400f, 0.009506f, 0.010445f, 0.011658f, 0.012993f, 0.014618f, 0.016357f,
+ 0.018524f, 0.021210f, 0.023712f, 0.027252f, 0.031219f, 0.036041f, 0.041962f, 0.049194f, 0.057892f, 0.068604f, 0.082642f, 0.099304f,
+ 0.120728f, 0.147217f, 0.180054f, 0.221191f, 0.269287f, 0.325928f, 0.388916f, 0.457275f, 0.525391f, 0.593262f, 0.657715f, 0.714355f,
+ 0.766113f, 0.809082f, 0.937500f, 0.940918f, 0.941895f, 0.941895f, 0.941895f, 0.942383f, 0.000243f, 0.000238f, 0.000411f, 0.000532f,
+ 0.000530f, 0.000764f, 0.000853f, 0.001171f, 0.001417f, 0.001545f, 0.001799f, 0.001900f, 0.002094f, 0.002354f, 0.002577f, 0.002703f,
+ 0.003155f, 0.003428f, 0.003809f, 0.004227f, 0.004677f, 0.004997f, 0.005386f, 0.005913f, 0.006741f, 0.007225f, 0.008057f, 0.008873f,
+ 0.009819f, 0.011101f, 0.012253f, 0.013725f, 0.015488f, 0.017410f, 0.019791f, 0.022598f, 0.025635f, 0.030014f, 0.034973f, 0.040527f,
+ 0.047729f, 0.056702f, 0.067505f, 0.081848f, 0.099609f, 0.121521f, 0.149902f, 0.185181f, 0.228516f, 0.280762f, 0.341553f, 0.408936f,
+ 0.480225f, 0.552246f, 0.622070f, 0.686035f, 0.742188f, 0.792480f, 0.932129f, 0.935547f, 0.937012f, 0.937012f, 0.936523f, 0.937500f,
+ 0.000000f, 0.000232f, 0.000330f, 0.000512f, 0.000523f, 0.000907f, 0.000953f, 0.001018f, 0.001234f, 0.001344f, 0.001610f, 0.001612f,
+ 0.001845f, 0.002054f, 0.002218f, 0.002453f, 0.002829f, 0.003105f, 0.003300f, 0.003712f, 0.003853f, 0.004280f, 0.004631f, 0.005112f,
+ 0.005665f, 0.006279f, 0.006779f, 0.007481f, 0.008362f, 0.009270f, 0.010338f, 0.011505f, 0.012848f, 0.014549f, 0.016403f, 0.018936f,
+ 0.021622f, 0.024750f, 0.028900f, 0.033447f, 0.039185f, 0.046448f, 0.055603f, 0.067078f, 0.081238f, 0.100037f, 0.123230f, 0.153564f,
+ 0.191284f, 0.238525f, 0.295166f, 0.361084f, 0.432861f, 0.507812f, 0.582520f, 0.653320f, 0.717285f, 0.772461f, 0.926270f, 0.931152f,
+ 0.931152f, 0.932129f, 0.932129f, 0.932129f, 0.000118f, 0.000219f, 0.000227f, 0.000405f, 0.000689f, 0.000726f, 0.000910f, 0.000847f,
+ 0.001072f, 0.001114f, 0.001388f, 0.001447f, 0.001656f, 0.001811f, 0.001897f, 0.002253f, 0.002373f, 0.002617f, 0.002796f, 0.003054f,
+ 0.003414f, 0.003681f, 0.003929f, 0.004353f, 0.004902f, 0.005322f, 0.005863f, 0.006424f, 0.007000f, 0.007755f, 0.008675f, 0.009506f,
+ 0.010704f, 0.012215f, 0.013557f, 0.015686f, 0.017807f, 0.020630f, 0.023376f, 0.027328f, 0.032013f, 0.038177f, 0.045288f, 0.054626f,
+ 0.066284f, 0.081543f, 0.100891f, 0.125977f, 0.158447f, 0.199951f, 0.251465f, 0.313965f, 0.384521f, 0.461670f, 0.540527f, 0.617188f,
+ 0.688965f, 0.750977f, 0.920410f, 0.924805f, 0.925781f, 0.926270f, 0.926758f, 0.925781f, 0.000230f, 0.000198f, 0.000217f, 0.000338f,
+ 0.000584f, 0.000786f, 0.000699f, 0.000893f, 0.000954f, 0.000959f, 0.001153f, 0.001165f, 0.001375f, 0.001545f, 0.001752f, 0.001752f,
+ 0.002062f, 0.002235f, 0.002399f, 0.002699f, 0.002853f, 0.002995f, 0.003372f, 0.003603f, 0.003944f, 0.004513f, 0.004704f, 0.005226f,
+ 0.005878f, 0.006527f, 0.006992f, 0.007889f, 0.008919f, 0.010002f, 0.011124f, 0.012604f, 0.014526f, 0.016510f, 0.019104f, 0.022308f,
+ 0.026077f, 0.030701f, 0.036774f, 0.044098f, 0.053558f, 0.065735f, 0.081299f, 0.101990f, 0.129517f, 0.164917f, 0.210938f, 0.268066f,
+ 0.336914f, 0.413818f, 0.496094f, 0.579102f, 0.657227f, 0.727539f, 0.913574f, 0.917969f, 0.918945f, 0.919434f, 0.919922f, 0.919922f,
+ 0.000000f, 0.000101f, 0.000214f, 0.000208f, 0.000339f, 0.000461f, 0.000577f, 0.000780f, 0.000777f, 0.000840f, 0.000853f, 0.001064f,
+ 0.001198f, 0.001327f, 0.001489f, 0.001687f, 0.001809f, 0.001884f, 0.002008f, 0.002129f, 0.002434f, 0.002514f, 0.002949f, 0.003000f,
+ 0.003351f, 0.003674f, 0.003918f, 0.004356f, 0.004875f, 0.005310f, 0.005768f, 0.006458f, 0.007244f, 0.008255f, 0.008949f, 0.010361f,
+ 0.011589f, 0.013290f, 0.015335f, 0.017776f, 0.020828f, 0.024521f, 0.029236f, 0.035431f, 0.042694f, 0.052490f, 0.065369f, 0.082336f,
+ 0.104492f, 0.134277f, 0.173828f, 0.225464f, 0.290039f, 0.365234f, 0.449707f, 0.536133f, 0.623047f, 0.702637f, 0.905273f, 0.911133f,
+ 0.912598f, 0.913086f, 0.913086f, 0.913086f, 0.000000f, 0.000167f, 0.000167f, 0.000316f, 0.000432f, 0.000444f, 0.000608f, 0.000611f,
+ 0.000678f, 0.000750f, 0.000899f, 0.000925f, 0.001043f, 0.001125f, 0.001222f, 0.001343f, 0.001470f, 0.001608f, 0.001679f, 0.001804f,
+ 0.001976f, 0.002234f, 0.002361f, 0.002710f, 0.002748f, 0.003035f, 0.003290f, 0.003647f, 0.003990f, 0.004295f, 0.004745f, 0.005318f,
+ 0.005920f, 0.006618f, 0.007347f, 0.008270f, 0.009361f, 0.010719f, 0.012291f, 0.014221f, 0.016693f, 0.019592f, 0.023239f, 0.027969f,
+ 0.033752f, 0.041534f, 0.051666f, 0.065369f, 0.083618f, 0.108276f, 0.141357f, 0.186035f, 0.244141f, 0.316650f, 0.400635f, 0.491699f,
+ 0.585938f, 0.672852f, 0.897461f, 0.903320f, 0.904297f, 0.903809f, 0.903809f, 0.904297f, 0.000000f, 0.000098f, 0.000145f, 0.000289f,
+ 0.000399f, 0.000424f, 0.000429f, 0.000382f, 0.000529f, 0.000613f, 0.000660f, 0.000836f, 0.000907f, 0.000940f, 0.001005f, 0.001188f,
+ 0.001306f, 0.001451f, 0.001420f, 0.001554f, 0.001667f, 0.001783f, 0.001955f, 0.002125f, 0.002357f, 0.002493f, 0.002760f, 0.002867f,
+ 0.003298f, 0.003626f, 0.003878f, 0.004341f, 0.004704f, 0.005356f, 0.005905f, 0.006512f, 0.007435f, 0.008377f, 0.009598f, 0.011055f,
+ 0.012978f, 0.015388f, 0.018036f, 0.021698f, 0.026337f, 0.032532f, 0.040192f, 0.050995f, 0.065125f, 0.085510f, 0.113037f, 0.150513f,
+ 0.201538f, 0.268799f, 0.351318f, 0.444824f, 0.543457f, 0.641602f, 0.888672f, 0.894043f, 0.894531f, 0.895508f, 0.895020f, 0.895508f,
+ 0.000000f, 0.000000f, 0.000032f, 0.000169f, 0.000338f, 0.000372f, 0.000468f, 0.000471f, 0.000460f, 0.000493f, 0.000588f, 0.000715f,
+ 0.000762f, 0.000912f, 0.000831f, 0.001001f, 0.001043f, 0.001133f, 0.001242f, 0.001312f, 0.001446f, 0.001529f, 0.001647f, 0.001829f,
+ 0.001982f, 0.002121f, 0.002165f, 0.002438f, 0.002628f, 0.002865f, 0.003113f, 0.003424f, 0.003622f, 0.004131f, 0.004639f, 0.005222f,
+ 0.005875f, 0.006622f, 0.007496f, 0.008575f, 0.009987f, 0.011665f, 0.013985f, 0.016617f, 0.019913f, 0.024704f, 0.030960f, 0.039185f,
+ 0.050323f, 0.066284f, 0.088196f, 0.119568f, 0.163208f, 0.223511f, 0.302002f, 0.395752f, 0.499756f, 0.605957f, 0.878418f, 0.883301f,
+ 0.884766f, 0.884766f, 0.885254f, 0.885254f, 0.000000f, 0.000000f, 0.000000f, 0.000216f, 0.000237f, 0.000338f, 0.000387f, 0.000341f,
+ 0.000435f, 0.000441f, 0.000461f, 0.000577f, 0.000544f, 0.000720f, 0.000813f, 0.000823f, 0.000912f, 0.000936f, 0.000994f, 0.001026f,
+ 0.001240f, 0.001268f, 0.001365f, 0.001415f, 0.001590f, 0.001565f, 0.001870f, 0.001929f, 0.002123f, 0.002377f, 0.002430f, 0.002565f,
+ 0.002947f, 0.003384f, 0.003662f, 0.004105f, 0.004513f, 0.005047f, 0.005741f, 0.006550f, 0.007549f, 0.008865f, 0.010612f, 0.012466f,
+ 0.015350f, 0.018677f, 0.023270f, 0.029800f, 0.038361f, 0.050323f, 0.067932f, 0.092590f, 0.129395f, 0.181274f, 0.253418f, 0.345459f,
+ 0.452637f, 0.567383f, 0.866699f, 0.872559f, 0.873047f, 0.873535f, 0.873047f, 0.873535f, 0.000000f, 0.000000f, 0.000121f, 0.000182f,
+ 0.000187f, 0.000237f, 0.000264f, 0.000360f, 0.000360f, 0.000397f, 0.000398f, 0.000412f, 0.000432f, 0.000546f, 0.000575f, 0.000690f,
+ 0.000731f, 0.000727f, 0.000807f, 0.000843f, 0.000924f, 0.001034f, 0.001093f, 0.001111f, 0.001251f, 0.001249f, 0.001334f, 0.001612f,
+ 0.001717f, 0.001820f, 0.002090f, 0.002161f, 0.002354f, 0.002600f, 0.002787f, 0.003119f, 0.003586f, 0.003878f, 0.004452f, 0.004913f,
+ 0.005772f, 0.006508f, 0.007679f, 0.009285f, 0.011086f, 0.013840f, 0.016968f, 0.021820f, 0.028259f, 0.037628f, 0.050812f, 0.070129f,
+ 0.099670f, 0.143433f, 0.207031f, 0.294922f, 0.403076f, 0.525879f, 0.853516f, 0.859375f, 0.860840f, 0.860352f, 0.862305f, 0.861328f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000181f, 0.000198f, 0.000181f, 0.000240f, 0.000275f, 0.000311f, 0.000427f, 0.000447f,
+ 0.000395f, 0.000472f, 0.000456f, 0.000557f, 0.000518f, 0.000562f, 0.000635f, 0.000664f, 0.000868f, 0.000887f, 0.000865f, 0.001025f,
+ 0.001014f, 0.001164f, 0.001096f, 0.001317f, 0.001382f, 0.001432f, 0.001445f, 0.001765f, 0.001744f, 0.002100f, 0.002144f, 0.002350f,
+ 0.002655f, 0.002947f, 0.003294f, 0.003780f, 0.004265f, 0.004971f, 0.005699f, 0.006786f, 0.007957f, 0.009636f, 0.011932f, 0.015823f,
+ 0.020142f, 0.026749f, 0.036530f, 0.051392f, 0.073792f, 0.109375f, 0.164185f, 0.244629f, 0.351562f, 0.479980f, 0.839355f, 0.844727f,
+ 0.846680f, 0.847656f, 0.847168f, 0.846680f, 0.000000f, 0.000121f, 0.000120f, 0.000119f, 0.000162f, 0.000133f, 0.000170f, 0.000201f,
+ 0.000204f, 0.000222f, 0.000258f, 0.000285f, 0.000324f, 0.000327f, 0.000422f, 0.000395f, 0.000431f, 0.000517f, 0.000632f, 0.000529f,
+ 0.000589f, 0.000592f, 0.000735f, 0.000714f, 0.000795f, 0.000778f, 0.000823f, 0.001063f, 0.001080f, 0.001141f, 0.001154f, 0.001308f,
+ 0.001439f, 0.001546f, 0.001689f, 0.001886f, 0.001978f, 0.002174f, 0.002377f, 0.002798f, 0.003277f, 0.003519f, 0.004181f, 0.004780f,
+ 0.005768f, 0.006863f, 0.008644f, 0.010750f, 0.014030f, 0.018448f, 0.025635f, 0.036194f, 0.053223f, 0.080811f, 0.125610f, 0.196533f,
+ 0.299316f, 0.430176f, 0.822754f, 0.830078f, 0.831055f, 0.831543f, 0.832031f, 0.831543f, 0.000000f, 0.000121f, 0.000120f, 0.000118f,
+ 0.000117f, 0.000120f, 0.000123f, 0.000151f, 0.000154f, 0.000175f, 0.000254f, 0.000190f, 0.000211f, 0.000306f, 0.000335f, 0.000358f,
+ 0.000394f, 0.000417f, 0.000443f, 0.000410f, 0.000565f, 0.000565f, 0.000491f, 0.000623f, 0.000616f, 0.000631f, 0.000738f, 0.000676f,
+ 0.000759f, 0.000924f, 0.000895f, 0.001030f, 0.001064f, 0.001176f, 0.001267f, 0.001438f, 0.001518f, 0.001704f, 0.001742f, 0.002028f,
+ 0.002384f, 0.002703f, 0.002972f, 0.003393f, 0.004051f, 0.004959f, 0.005993f, 0.007271f, 0.009277f, 0.012390f, 0.016968f, 0.024368f,
+ 0.036560f, 0.056610f, 0.091797f, 0.151245f, 0.246460f, 0.379639f, 0.805664f, 0.812500f, 0.813477f, 0.813965f, 0.813965f, 0.813965f,
+ 0.000000f, 0.000000f, 0.000118f, 0.000117f, 0.000116f, 0.000114f, 0.000113f, 0.000108f, 0.000127f, 0.000153f, 0.000133f, 0.000202f,
+ 0.000217f, 0.000223f, 0.000242f, 0.000186f, 0.000280f, 0.000304f, 0.000318f, 0.000342f, 0.000338f, 0.000473f, 0.000360f, 0.000484f,
+ 0.000422f, 0.000514f, 0.000527f, 0.000571f, 0.000633f, 0.000568f, 0.000639f, 0.000816f, 0.000789f, 0.000889f, 0.000891f, 0.000966f,
+ 0.001125f, 0.001276f, 0.001316f, 0.001496f, 0.001658f, 0.001818f, 0.002047f, 0.002502f, 0.002781f, 0.003201f, 0.003914f, 0.004795f,
+ 0.006096f, 0.007996f, 0.010918f, 0.015617f, 0.023697f, 0.037567f, 0.063477f, 0.111084f, 0.194824f, 0.324951f, 0.786133f, 0.792969f,
+ 0.794434f, 0.793945f, 0.794922f, 0.794434f, 0.000000f, 0.000119f, 0.000117f, 0.000115f, 0.000113f, 0.000112f, 0.000110f, 0.000109f,
+ 0.000104f, 0.000098f, 0.000099f, 0.000136f, 0.000112f, 0.000126f, 0.000175f, 0.000189f, 0.000196f, 0.000220f, 0.000216f, 0.000247f,
+ 0.000258f, 0.000274f, 0.000285f, 0.000309f, 0.000308f, 0.000321f, 0.000381f, 0.000390f, 0.000475f, 0.000511f, 0.000485f, 0.000501f,
+ 0.000641f, 0.000588f, 0.000652f, 0.000764f, 0.000808f, 0.000952f, 0.000906f, 0.001037f, 0.001110f, 0.001249f, 0.001411f, 0.001647f,
+ 0.001894f, 0.002159f, 0.002687f, 0.003223f, 0.004036f, 0.005150f, 0.006989f, 0.009644f, 0.014420f, 0.023361f, 0.040802f, 0.076050f,
+ 0.146362f, 0.269287f, 0.763184f, 0.770996f, 0.771973f, 0.771973f, 0.772461f, 0.772461f, 0.000121f, 0.000116f, 0.000114f, 0.000112f,
+ 0.000109f, 0.000108f, 0.000106f, 0.000105f, 0.000104f, 0.000101f, 0.000095f, 0.000090f, 0.000085f, 0.000083f, 0.000104f, 0.000097f,
+ 0.000094f, 0.000154f, 0.000127f, 0.000178f, 0.000197f, 0.000194f, 0.000233f, 0.000213f, 0.000279f, 0.000294f, 0.000293f, 0.000258f,
+ 0.000319f, 0.000394f, 0.000344f, 0.000369f, 0.000394f, 0.000410f, 0.000438f, 0.000509f, 0.000514f, 0.000580f, 0.000617f, 0.000684f,
+ 0.000807f, 0.000812f, 0.000914f, 0.001094f, 0.001183f, 0.001436f, 0.001639f, 0.002033f, 0.002523f, 0.003073f, 0.004063f, 0.005680f,
+ 0.008560f, 0.013466f, 0.024109f, 0.047791f, 0.102051f, 0.213867f, 0.740234f, 0.746582f, 0.748047f, 0.748535f, 0.749023f, 0.749023f,
+ 0.000000f, 0.000113f, 0.000108f, 0.000107f, 0.000104f, 0.000102f, 0.000099f, 0.000099f, 0.000097f, 0.000096f, 0.000095f, 0.000091f,
+ 0.000086f, 0.000081f, 0.000077f, 0.000073f, 0.000085f, 0.000091f, 0.000070f, 0.000102f, 0.000117f, 0.000131f, 0.000145f, 0.000148f,
+ 0.000171f, 0.000178f, 0.000178f, 0.000207f, 0.000225f, 0.000209f, 0.000285f, 0.000238f, 0.000260f, 0.000298f, 0.000331f, 0.000360f,
+ 0.000371f, 0.000346f, 0.000407f, 0.000443f, 0.000494f, 0.000516f, 0.000578f, 0.000662f, 0.000767f, 0.000847f, 0.001004f, 0.001149f,
+ 0.001451f, 0.001783f, 0.002310f, 0.003262f, 0.004593f, 0.007309f, 0.012985f, 0.026703f, 0.064026f, 0.158813f, 0.712891f, 0.719238f,
+ 0.722168f, 0.721680f, 0.722168f, 0.722656f, 0.000000f, 0.000105f, 0.000102f, 0.000098f, 0.000094f, 0.000092f, 0.000091f, 0.000089f,
+ 0.000088f, 0.000086f, 0.000085f, 0.000084f, 0.000083f, 0.000080f, 0.000076f, 0.000073f, 0.000069f, 0.000065f, 0.000062f, 0.000059f,
+ 0.000068f, 0.000063f, 0.000069f, 0.000074f, 0.000087f, 0.000102f, 0.000112f, 0.000130f, 0.000137f, 0.000129f, 0.000143f, 0.000168f,
+ 0.000180f, 0.000178f, 0.000189f, 0.000198f, 0.000222f, 0.000240f, 0.000262f, 0.000285f, 0.000304f, 0.000317f, 0.000339f, 0.000399f,
+ 0.000439f, 0.000490f, 0.000570f, 0.000658f, 0.000781f, 0.000988f, 0.001235f, 0.001674f, 0.002407f, 0.003725f, 0.006485f, 0.013199f,
+ 0.034546f, 0.107605f, 0.682129f, 0.691406f, 0.692871f, 0.691406f, 0.692871f, 0.692871f, 0.000105f, 0.000089f, 0.000085f, 0.000080f,
+ 0.000078f, 0.000078f, 0.000075f, 0.000074f, 0.000072f, 0.000072f, 0.000070f, 0.000071f, 0.000069f, 0.000069f, 0.000069f, 0.000068f,
+ 0.000066f, 0.000063f, 0.000060f, 0.000057f, 0.000054f, 0.000052f, 0.000049f, 0.000047f, 0.000046f, 0.000045f, 0.000048f, 0.000055f,
+ 0.000060f, 0.000068f, 0.000083f, 0.000087f, 0.000092f, 0.000103f, 0.000109f, 0.000117f, 0.000130f, 0.000150f, 0.000148f, 0.000142f,
+ 0.000167f, 0.000186f, 0.000210f, 0.000213f, 0.000232f, 0.000280f, 0.000292f, 0.000329f, 0.000391f, 0.000456f, 0.000596f, 0.000764f,
+ 0.001065f, 0.001633f, 0.002806f, 0.005909f, 0.015488f, 0.062378f, 0.651367f, 0.659668f, 0.661133f, 0.661133f, 0.660645f, 0.661621f,
+ 0.000034f, 0.000037f, 0.000048f, 0.000051f, 0.000047f, 0.000049f, 0.000047f, 0.000051f, 0.000049f, 0.000051f, 0.000049f, 0.000050f,
+ 0.000051f, 0.000050f, 0.000050f, 0.000049f, 0.000051f, 0.000050f, 0.000051f, 0.000050f, 0.000049f, 0.000047f, 0.000045f, 0.000043f,
+ 0.000041f, 0.000039f, 0.000037f, 0.000035f, 0.000033f, 0.000032f, 0.000030f, 0.000029f, 0.000034f, 0.000041f, 0.000046f, 0.000057f,
+ 0.000063f, 0.000067f, 0.000065f, 0.000072f, 0.000083f, 0.000093f, 0.000096f, 0.000102f, 0.000102f, 0.000135f, 0.000134f, 0.000151f,
+ 0.000184f, 0.000198f, 0.000245f, 0.000306f, 0.000425f, 0.000607f, 0.001032f, 0.002081f, 0.005886f, 0.027924f, 0.617188f, 0.625977f,
+ 0.627441f, 0.627930f, 0.626953f, 0.628418f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000006f, 0.000010f, 0.000014f,
+ 0.000016f, 0.000014f, 0.000019f, 0.000022f, 0.000022f, 0.000022f, 0.000025f, 0.000026f, 0.000027f, 0.000028f, 0.000029f, 0.000029f,
+ 0.000029f, 0.000030f, 0.000030f, 0.000031f, 0.000032f, 0.000032f, 0.000031f, 0.000030f, 0.000028f, 0.000027f, 0.000026f, 0.000024f,
+ 0.000023f, 0.000022f, 0.000021f, 0.000020f, 0.000019f, 0.000021f, 0.000022f, 0.000024f, 0.000027f, 0.000035f, 0.000041f, 0.000034f,
+ 0.000041f, 0.000052f, 0.000051f, 0.000051f, 0.000058f, 0.000070f, 0.000074f, 0.000103f, 0.000119f, 0.000169f, 0.000277f, 0.000510f,
+ 0.001495f, 0.008766f, 0.583008f, 0.590332f, 0.591797f, 0.591797f, 0.592285f, 0.592285f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000002f, 0.000003f, 0.000005f, 0.000006f, 0.000008f, 0.000009f, 0.000010f, 0.000010f,
+ 0.000012f, 0.000012f, 0.000013f, 0.000014f, 0.000015f, 0.000015f, 0.000015f, 0.000015f, 0.000014f, 0.000013f, 0.000013f, 0.000012f,
+ 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000014f, 0.000011f, 0.000015f, 0.000017f, 0.000017f, 0.000021f, 0.000020f,
+ 0.000026f, 0.000026f, 0.000042f, 0.000069f, 0.000178f, 0.001302f, 0.544434f, 0.553711f, 0.554688f, 0.554688f, 0.556152f, 0.556641f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000002f, 0.000003f, 0.000003f,
+ 0.000003f, 0.000003f, 0.000003f, 0.000002f, 0.000002f, 0.000001f, 0.000003f, 0.000003f, 0.000004f, 0.000014f, 0.506836f, 0.515137f,
+ 0.516113f, 0.516602f, 0.517090f, 0.517578f,
+ },
+ {
+ 0.089539f, 0.244873f, 0.368164f, 0.464355f, 0.539551f, 0.599121f, 0.648438f, 0.688477f, 0.721680f, 0.749512f, 0.772461f, 0.793945f,
+ 0.811523f, 0.826172f, 0.841309f, 0.854004f, 0.863770f, 0.874512f, 0.883301f, 0.891602f, 0.898438f, 0.906250f, 0.912109f, 0.917969f,
+ 0.922852f, 0.928223f, 0.932617f, 0.937012f, 0.940918f, 0.944336f, 0.948242f, 0.951660f, 0.954590f, 0.957520f, 0.960449f, 0.962891f,
+ 0.965820f, 0.967773f, 0.970215f, 0.972656f, 0.974609f, 0.976074f, 0.978516f, 0.979492f, 0.981934f, 0.983398f, 0.984863f, 0.986328f,
+ 0.987793f, 0.988770f, 0.990234f, 0.991699f, 0.993164f, 0.994141f, 0.995117f, 0.996582f, 0.997559f, 0.998535f, 0.999023f, 0.998535f,
+ 0.997559f, 0.997070f, 0.996582f, 0.995605f, 0.045563f, 0.143921f, 0.242798f, 0.334717f, 0.417969f, 0.489258f, 0.550293f, 0.602051f,
+ 0.646484f, 0.683594f, 0.715820f, 0.743652f, 0.767090f, 0.788086f, 0.805664f, 0.822266f, 0.836426f, 0.849609f, 0.861328f, 0.870117f,
+ 0.879883f, 0.889160f, 0.896973f, 0.903320f, 0.909668f, 0.916016f, 0.921875f, 0.926758f, 0.931641f, 0.936523f, 0.940430f, 0.943848f,
+ 0.947266f, 0.951172f, 0.954102f, 0.957520f, 0.960449f, 0.962891f, 0.965820f, 0.968262f, 0.970215f, 0.973145f, 0.974121f, 0.976074f,
+ 0.979004f, 0.980469f, 0.982422f, 0.983887f, 0.985352f, 0.986816f, 0.988281f, 0.989746f, 0.991211f, 0.992188f, 0.994141f, 0.995117f,
+ 0.996094f, 0.997070f, 0.998535f, 0.997559f, 0.997070f, 0.996582f, 0.996094f, 0.995117f, 0.026855f, 0.089233f, 0.159790f, 0.234619f,
+ 0.308838f, 0.381348f, 0.447754f, 0.507812f, 0.561035f, 0.606934f, 0.646484f, 0.683105f, 0.712402f, 0.740234f, 0.763184f, 0.784668f,
+ 0.802246f, 0.819336f, 0.833984f, 0.846680f, 0.857910f, 0.868652f, 0.878418f, 0.886719f, 0.895508f, 0.903320f, 0.909668f, 0.915527f,
+ 0.920410f, 0.926270f, 0.931152f, 0.935547f, 0.940430f, 0.943848f, 0.947754f, 0.951172f, 0.954590f, 0.958008f, 0.960449f, 0.963379f,
+ 0.966309f, 0.968750f, 0.971191f, 0.973145f, 0.975586f, 0.977051f, 0.979004f, 0.981445f, 0.982910f, 0.983887f, 0.985840f, 0.987305f,
+ 0.988770f, 0.990723f, 0.992188f, 0.993164f, 0.994629f, 0.996094f, 0.998047f, 0.997070f, 0.996582f, 0.996094f, 0.995605f, 0.995117f,
+ 0.017746f, 0.058746f, 0.108276f, 0.163818f, 0.224365f, 0.288086f, 0.351562f, 0.413086f, 0.470947f, 0.522949f, 0.569824f, 0.612793f,
+ 0.650879f, 0.684570f, 0.713867f, 0.739258f, 0.762695f, 0.783203f, 0.800781f, 0.817871f, 0.833008f, 0.845215f, 0.857422f, 0.868164f,
+ 0.877441f, 0.886230f, 0.894043f, 0.902832f, 0.908691f, 0.915039f, 0.921387f, 0.925781f, 0.930664f, 0.936035f, 0.939941f, 0.944336f,
+ 0.948242f, 0.951660f, 0.955078f, 0.957520f, 0.961426f, 0.964355f, 0.967285f, 0.968750f, 0.971680f, 0.974121f, 0.975586f, 0.978027f,
+ 0.979980f, 0.981934f, 0.983887f, 0.985352f, 0.987305f, 0.988770f, 0.989746f, 0.991211f, 0.992676f, 0.993652f, 0.997070f, 0.996582f,
+ 0.996582f, 0.996094f, 0.995117f, 0.994629f, 0.012337f, 0.041229f, 0.075928f, 0.117065f, 0.163208f, 0.214478f, 0.270020f, 0.327148f,
+ 0.383301f, 0.437500f, 0.490234f, 0.536621f, 0.581543f, 0.621094f, 0.656250f, 0.688477f, 0.716797f, 0.741699f, 0.763672f, 0.784668f,
+ 0.802246f, 0.818359f, 0.832520f, 0.845703f, 0.857422f, 0.868164f, 0.877930f, 0.886230f, 0.895020f, 0.902344f, 0.909668f, 0.915039f,
+ 0.921875f, 0.926758f, 0.931641f, 0.937012f, 0.940430f, 0.946289f, 0.949219f, 0.952637f, 0.956055f, 0.958984f, 0.961914f, 0.964844f,
+ 0.967773f, 0.970215f, 0.972656f, 0.974609f, 0.976562f, 0.979004f, 0.980957f, 0.982910f, 0.984863f, 0.986816f, 0.987793f, 0.989746f,
+ 0.990723f, 0.992676f, 0.996582f, 0.996094f, 0.995605f, 0.995117f, 0.994629f, 0.994141f, 0.009315f, 0.030411f, 0.055756f, 0.085632f,
+ 0.121094f, 0.160889f, 0.206055f, 0.254150f, 0.305664f, 0.357422f, 0.408447f, 0.459717f, 0.506836f, 0.551270f, 0.592773f, 0.629395f,
+ 0.662598f, 0.692871f, 0.719727f, 0.745117f, 0.767090f, 0.786133f, 0.804688f, 0.819336f, 0.834473f, 0.847168f, 0.858398f, 0.869629f,
+ 0.879395f, 0.888672f, 0.895020f, 0.903320f, 0.910156f, 0.916016f, 0.922363f, 0.928223f, 0.933105f, 0.937012f, 0.941406f, 0.946289f,
+ 0.950195f, 0.954102f, 0.957031f, 0.960449f, 0.963379f, 0.965820f, 0.969238f, 0.971191f, 0.974121f, 0.976074f, 0.978027f, 0.979980f,
+ 0.982422f, 0.984375f, 0.985840f, 0.987793f, 0.989258f, 0.990723f, 0.995605f, 0.995605f, 0.995117f, 0.994629f, 0.994629f, 0.993652f,
+ 0.006634f, 0.022736f, 0.041962f, 0.064026f, 0.090759f, 0.122192f, 0.157593f, 0.197510f, 0.240356f, 0.287354f, 0.335693f, 0.384766f,
+ 0.432373f, 0.479736f, 0.523438f, 0.565430f, 0.604004f, 0.639160f, 0.670898f, 0.699219f, 0.726562f, 0.749023f, 0.770508f, 0.790527f,
+ 0.806641f, 0.822754f, 0.836426f, 0.848633f, 0.859863f, 0.871582f, 0.881348f, 0.889160f, 0.897949f, 0.905273f, 0.912598f, 0.918945f,
+ 0.924316f, 0.929199f, 0.935059f, 0.938965f, 0.943848f, 0.947266f, 0.951660f, 0.955078f, 0.958496f, 0.961914f, 0.964844f, 0.967773f,
+ 0.970703f, 0.973145f, 0.975098f, 0.977539f, 0.979492f, 0.981445f, 0.983887f, 0.985352f, 0.987305f, 0.989258f, 0.995117f, 0.994629f,
+ 0.994141f, 0.994141f, 0.993652f, 0.993164f, 0.005428f, 0.017807f, 0.032166f, 0.049652f, 0.070007f, 0.093811f, 0.121765f, 0.153564f,
+ 0.189087f, 0.228516f, 0.270752f, 0.316162f, 0.362061f, 0.408936f, 0.453857f, 0.498779f, 0.540527f, 0.579590f, 0.615723f, 0.649902f,
+ 0.679688f, 0.707520f, 0.732422f, 0.755371f, 0.775391f, 0.794922f, 0.811035f, 0.826172f, 0.839844f, 0.852051f, 0.864258f, 0.875000f,
+ 0.883301f, 0.892578f, 0.899902f, 0.907715f, 0.914062f, 0.920410f, 0.926270f, 0.931641f, 0.936035f, 0.940918f, 0.945312f, 0.949219f,
+ 0.954102f, 0.957031f, 0.960938f, 0.963379f, 0.966797f, 0.969238f, 0.972168f, 0.974609f, 0.977051f, 0.979492f, 0.980957f, 0.983398f,
+ 0.985352f, 0.987305f, 0.994141f, 0.994141f, 0.994141f, 0.993652f, 0.993164f, 0.992676f, 0.004223f, 0.014046f, 0.025452f, 0.039062f,
+ 0.055115f, 0.073608f, 0.095642f, 0.120239f, 0.149292f, 0.182251f, 0.217529f, 0.257080f, 0.298828f, 0.342773f, 0.387207f, 0.431152f,
+ 0.474609f, 0.516602f, 0.556641f, 0.593750f, 0.628418f, 0.660156f, 0.689453f, 0.715820f, 0.740723f, 0.762207f, 0.782227f, 0.799805f,
+ 0.816406f, 0.830566f, 0.844727f, 0.855469f, 0.867188f, 0.877441f, 0.886230f, 0.895020f, 0.903809f, 0.910645f, 0.917480f, 0.923340f,
+ 0.928711f, 0.934570f, 0.939453f, 0.943848f, 0.948242f, 0.952148f, 0.956055f, 0.959473f, 0.961914f, 0.965820f, 0.968750f, 0.971680f,
+ 0.974121f, 0.975586f, 0.979004f, 0.980957f, 0.983398f, 0.985352f, 0.993652f, 0.993652f, 0.993164f, 0.993164f, 0.992676f, 0.991699f,
+ 0.003532f, 0.011536f, 0.020645f, 0.031342f, 0.044098f, 0.058624f, 0.075989f, 0.096252f, 0.119141f, 0.145386f, 0.175049f, 0.208130f,
+ 0.244385f, 0.283203f, 0.324463f, 0.367432f, 0.410400f, 0.453369f, 0.495361f, 0.534668f, 0.572266f, 0.607910f, 0.641602f, 0.672852f,
+ 0.700195f, 0.725098f, 0.748047f, 0.769531f, 0.789062f, 0.806152f, 0.821777f, 0.835938f, 0.848633f, 0.860352f, 0.872070f, 0.881836f,
+ 0.890625f, 0.898926f, 0.906738f, 0.913086f, 0.919922f, 0.925781f, 0.931641f, 0.936523f, 0.941406f, 0.946289f, 0.950684f, 0.954590f,
+ 0.958008f, 0.961426f, 0.964844f, 0.968262f, 0.970703f, 0.973633f, 0.976074f, 0.978516f, 0.980469f, 0.982910f, 0.992676f, 0.992676f,
+ 0.992188f, 0.992188f, 0.991699f, 0.990723f, 0.002850f, 0.009483f, 0.016647f, 0.025833f, 0.035889f, 0.047424f, 0.061646f, 0.076660f,
+ 0.095642f, 0.117065f, 0.141113f, 0.168457f, 0.198975f, 0.233032f, 0.269775f, 0.308838f, 0.349854f, 0.391357f, 0.432861f, 0.474121f,
+ 0.515625f, 0.552734f, 0.589355f, 0.622559f, 0.654785f, 0.683594f, 0.710938f, 0.735352f, 0.757812f, 0.777344f, 0.795898f, 0.812988f,
+ 0.827637f, 0.842285f, 0.854492f, 0.866211f, 0.876953f, 0.886719f, 0.895508f, 0.902832f, 0.911133f, 0.917969f, 0.924316f, 0.929688f,
+ 0.935059f, 0.940430f, 0.945312f, 0.949219f, 0.953125f, 0.958008f, 0.961426f, 0.964844f, 0.967285f, 0.970703f, 0.973633f, 0.975586f,
+ 0.978516f, 0.981445f, 0.991699f, 0.992188f, 0.991699f, 0.991211f, 0.991211f, 0.990723f, 0.002628f, 0.007713f, 0.014069f, 0.021484f,
+ 0.029709f, 0.038910f, 0.050201f, 0.063171f, 0.078186f, 0.094849f, 0.114563f, 0.137329f, 0.162720f, 0.190918f, 0.222656f, 0.257568f,
+ 0.293945f, 0.332764f, 0.372803f, 0.414551f, 0.455078f, 0.495361f, 0.533691f, 0.571289f, 0.606445f, 0.639160f, 0.668457f, 0.697754f,
+ 0.723633f, 0.746094f, 0.767090f, 0.787598f, 0.804199f, 0.820801f, 0.834473f, 0.848633f, 0.860352f, 0.872559f, 0.882324f, 0.891602f,
+ 0.899902f, 0.907715f, 0.915039f, 0.921387f, 0.927734f, 0.934082f, 0.938965f, 0.944824f, 0.948730f, 0.953125f, 0.956543f, 0.960938f,
+ 0.963867f, 0.967285f, 0.970215f, 0.973145f, 0.976074f, 0.978516f, 0.990234f, 0.990723f, 0.990723f, 0.991211f, 0.990234f, 0.990234f,
+ 0.002131f, 0.006535f, 0.012016f, 0.017670f, 0.024780f, 0.032837f, 0.041199f, 0.051819f, 0.063904f, 0.077759f, 0.093689f, 0.112610f,
+ 0.133057f, 0.156860f, 0.183472f, 0.213257f, 0.245605f, 0.281006f, 0.318115f, 0.357422f, 0.397217f, 0.437500f, 0.478271f, 0.516602f,
+ 0.554688f, 0.589844f, 0.623535f, 0.654785f, 0.684082f, 0.710938f, 0.734375f, 0.757812f, 0.777832f, 0.795898f, 0.813477f, 0.828613f,
+ 0.843262f, 0.855957f, 0.867676f, 0.878906f, 0.888184f, 0.897461f, 0.905273f, 0.912598f, 0.919922f, 0.926758f, 0.932129f, 0.937988f,
+ 0.942871f, 0.947754f, 0.951660f, 0.955566f, 0.960449f, 0.964355f, 0.967285f, 0.970215f, 0.973145f, 0.976074f, 0.989746f, 0.990234f,
+ 0.990234f, 0.990234f, 0.989746f, 0.988770f, 0.001566f, 0.005798f, 0.010231f, 0.015259f, 0.020920f, 0.027176f, 0.034607f, 0.043335f,
+ 0.052887f, 0.064392f, 0.077576f, 0.092712f, 0.109802f, 0.129639f, 0.151611f, 0.176758f, 0.204346f, 0.235474f, 0.269043f, 0.304688f,
+ 0.342529f, 0.381836f, 0.421143f, 0.460449f, 0.500488f, 0.538086f, 0.574219f, 0.608887f, 0.640625f, 0.670898f, 0.699219f, 0.725098f,
+ 0.748535f, 0.769043f, 0.788574f, 0.807129f, 0.823242f, 0.837402f, 0.850586f, 0.863281f, 0.874512f, 0.885254f, 0.894043f, 0.902832f,
+ 0.910645f, 0.917969f, 0.924805f, 0.931152f, 0.936523f, 0.941895f, 0.947266f, 0.951172f, 0.955566f, 0.960449f, 0.963867f, 0.966797f,
+ 0.970703f, 0.973145f, 0.988281f, 0.989258f, 0.989258f, 0.989258f, 0.988770f, 0.988281f, 0.001427f, 0.004749f, 0.008934f, 0.012833f,
+ 0.017670f, 0.023483f, 0.029114f, 0.036438f, 0.044556f, 0.054047f, 0.064453f, 0.077148f, 0.091309f, 0.107544f, 0.125854f, 0.146729f,
+ 0.170776f, 0.197266f, 0.226440f, 0.257568f, 0.292236f, 0.329346f, 0.367188f, 0.405762f, 0.445557f, 0.484619f, 0.522949f, 0.559570f,
+ 0.595215f, 0.627441f, 0.659180f, 0.687012f, 0.714355f, 0.739258f, 0.761719f, 0.781738f, 0.800781f, 0.817383f, 0.833984f, 0.847168f,
+ 0.859375f, 0.872070f, 0.882324f, 0.891602f, 0.900879f, 0.909668f, 0.916504f, 0.923828f, 0.930176f, 0.936523f, 0.941895f, 0.946777f,
+ 0.951172f, 0.956055f, 0.960449f, 0.963867f, 0.967285f, 0.970703f, 0.987305f, 0.988770f, 0.988281f, 0.987793f, 0.987793f, 0.987793f,
+ 0.001357f, 0.004501f, 0.007557f, 0.011284f, 0.015236f, 0.019791f, 0.025101f, 0.030838f, 0.037628f, 0.045532f, 0.054596f, 0.064636f,
+ 0.076355f, 0.089905f, 0.105042f, 0.122498f, 0.142334f, 0.164307f, 0.189697f, 0.217896f, 0.248413f, 0.281494f, 0.316406f, 0.354004f,
+ 0.391846f, 0.430664f, 0.469971f, 0.508301f, 0.545898f, 0.582031f, 0.615723f, 0.647461f, 0.677734f, 0.704590f, 0.731445f, 0.754395f,
+ 0.775391f, 0.794922f, 0.811523f, 0.829102f, 0.842773f, 0.856934f, 0.868652f, 0.880371f, 0.891113f, 0.899414f, 0.908203f, 0.915527f,
+ 0.922852f, 0.930176f, 0.936035f, 0.941406f, 0.947266f, 0.951660f, 0.957031f, 0.960449f, 0.963867f, 0.968262f, 0.986328f, 0.987305f,
+ 0.987793f, 0.987305f, 0.987305f, 0.986816f, 0.001239f, 0.003864f, 0.006699f, 0.009621f, 0.013008f, 0.017059f, 0.021805f, 0.026703f,
+ 0.032562f, 0.039185f, 0.045807f, 0.054352f, 0.064514f, 0.075439f, 0.088257f, 0.102478f, 0.119263f, 0.138306f, 0.159546f, 0.183228f,
+ 0.209961f, 0.239258f, 0.271484f, 0.305176f, 0.341797f, 0.379639f, 0.417480f, 0.456787f, 0.495605f, 0.532227f, 0.570801f, 0.604980f,
+ 0.637207f, 0.666992f, 0.696289f, 0.722656f, 0.746582f, 0.768555f, 0.789062f, 0.808105f, 0.824219f, 0.839844f, 0.854492f, 0.865723f,
+ 0.878418f, 0.888672f, 0.897461f, 0.906738f, 0.915039f, 0.922363f, 0.929199f, 0.935547f, 0.941895f, 0.946289f, 0.952148f, 0.956543f,
+ 0.960449f, 0.964844f, 0.985352f, 0.986816f, 0.986816f, 0.986328f, 0.986328f, 0.985840f, 0.001151f, 0.003429f, 0.005753f, 0.008400f,
+ 0.011391f, 0.014877f, 0.018494f, 0.022858f, 0.028046f, 0.033112f, 0.039642f, 0.046661f, 0.054565f, 0.064026f, 0.074280f, 0.086243f,
+ 0.100403f, 0.116150f, 0.133789f, 0.154053f, 0.176636f, 0.202393f, 0.230957f, 0.261719f, 0.295166f, 0.330322f, 0.367432f, 0.405518f,
+ 0.445312f, 0.483398f, 0.520996f, 0.558105f, 0.594238f, 0.626465f, 0.659668f, 0.688477f, 0.714844f, 0.740723f, 0.763672f, 0.784180f,
+ 0.804199f, 0.821289f, 0.837402f, 0.852051f, 0.864258f, 0.876465f, 0.886719f, 0.897949f, 0.906250f, 0.915039f, 0.922363f, 0.929199f,
+ 0.935547f, 0.941406f, 0.946777f, 0.952637f, 0.958008f, 0.961914f, 0.983887f, 0.985840f, 0.985352f, 0.985352f, 0.984863f, 0.984863f,
+ 0.001000f, 0.002768f, 0.005127f, 0.007515f, 0.010155f, 0.013283f, 0.016205f, 0.019714f, 0.023987f, 0.028854f, 0.033905f, 0.040161f,
+ 0.046814f, 0.054199f, 0.063110f, 0.073303f, 0.084839f, 0.098145f, 0.112854f, 0.129883f, 0.149292f, 0.171387f, 0.195435f, 0.222778f,
+ 0.252686f, 0.285400f, 0.320312f, 0.356689f, 0.394531f, 0.433105f, 0.471924f, 0.510742f, 0.547852f, 0.584473f, 0.617676f, 0.650879f,
+ 0.680664f, 0.708984f, 0.734375f, 0.759277f, 0.780762f, 0.799805f, 0.817383f, 0.834473f, 0.849121f, 0.862793f, 0.875488f, 0.886719f,
+ 0.896484f, 0.906250f, 0.915039f, 0.923828f, 0.930176f, 0.936035f, 0.942871f, 0.948242f, 0.953613f, 0.958008f, 0.982910f, 0.983887f,
+ 0.984375f, 0.983887f, 0.984375f, 0.983398f, 0.000799f, 0.002705f, 0.004459f, 0.006573f, 0.008842f, 0.011375f, 0.014099f, 0.017487f,
+ 0.020798f, 0.024963f, 0.029465f, 0.034637f, 0.039703f, 0.046478f, 0.054047f, 0.062256f, 0.072388f, 0.082947f, 0.095764f, 0.110229f,
+ 0.126099f, 0.144775f, 0.165771f, 0.189697f, 0.216187f, 0.244995f, 0.276123f, 0.310303f, 0.346191f, 0.384521f, 0.422607f, 0.461670f,
+ 0.500000f, 0.538574f, 0.575195f, 0.609863f, 0.643555f, 0.673828f, 0.702637f, 0.730469f, 0.754395f, 0.777344f, 0.797363f, 0.815430f,
+ 0.833008f, 0.848633f, 0.861328f, 0.875000f, 0.886719f, 0.896973f, 0.906738f, 0.915039f, 0.923340f, 0.930176f, 0.936523f, 0.943848f,
+ 0.948730f, 0.954102f, 0.981445f, 0.983398f, 0.982910f, 0.983398f, 0.982910f, 0.982910f, 0.000774f, 0.002554f, 0.003899f, 0.005875f,
+ 0.007759f, 0.009949f, 0.012733f, 0.015060f, 0.018280f, 0.021667f, 0.025574f, 0.029678f, 0.034698f, 0.040405f, 0.046570f, 0.053650f,
+ 0.061462f, 0.071106f, 0.081360f, 0.093323f, 0.107300f, 0.122864f, 0.140747f, 0.160522f, 0.183960f, 0.209229f, 0.237305f, 0.268799f,
+ 0.302002f, 0.337402f, 0.374023f, 0.413330f, 0.451904f, 0.490967f, 0.529785f, 0.567383f, 0.603027f, 0.636719f, 0.668457f, 0.698242f,
+ 0.725586f, 0.750977f, 0.773926f, 0.793945f, 0.813965f, 0.831543f, 0.847656f, 0.861816f, 0.874512f, 0.886719f, 0.897461f, 0.906738f,
+ 0.915527f, 0.923828f, 0.931641f, 0.937988f, 0.944824f, 0.949707f, 0.979980f, 0.981934f, 0.981934f, 0.981934f, 0.981934f, 0.981445f,
+ 0.000657f, 0.001934f, 0.003330f, 0.005280f, 0.006748f, 0.009079f, 0.010994f, 0.013763f, 0.015945f, 0.019150f, 0.022003f, 0.026001f,
+ 0.030350f, 0.034790f, 0.040253f, 0.045898f, 0.052795f, 0.060852f, 0.069641f, 0.079346f, 0.091187f, 0.104492f, 0.119751f, 0.136963f,
+ 0.156372f, 0.178345f, 0.203247f, 0.230957f, 0.260742f, 0.294189f, 0.328613f, 0.365723f, 0.403564f, 0.443115f, 0.482910f, 0.521484f,
+ 0.559570f, 0.596680f, 0.630859f, 0.664062f, 0.694336f, 0.722168f, 0.747559f, 0.771484f, 0.793457f, 0.813477f, 0.830078f, 0.846191f,
+ 0.861816f, 0.874023f, 0.887207f, 0.898438f, 0.908691f, 0.916992f, 0.925293f, 0.933594f, 0.939941f, 0.946777f, 0.978516f, 0.980469f,
+ 0.980469f, 0.980469f, 0.980469f, 0.980469f, 0.000818f, 0.001935f, 0.003246f, 0.004658f, 0.006229f, 0.007912f, 0.010017f, 0.012093f,
+ 0.014259f, 0.016586f, 0.019653f, 0.022659f, 0.026413f, 0.030289f, 0.034790f, 0.039917f, 0.045441f, 0.052338f, 0.059479f, 0.068115f,
+ 0.077759f, 0.089050f, 0.102051f, 0.116272f, 0.133179f, 0.152344f, 0.173340f, 0.197876f, 0.224243f, 0.254150f, 0.286621f, 0.321533f,
+ 0.357666f, 0.396729f, 0.436279f, 0.475830f, 0.514648f, 0.553711f, 0.590332f, 0.626465f, 0.659180f, 0.689941f, 0.719238f, 0.746094f,
+ 0.770020f, 0.792480f, 0.812500f, 0.830566f, 0.846680f, 0.862305f, 0.875977f, 0.888184f, 0.899414f, 0.910156f, 0.918945f, 0.927246f,
+ 0.935059f, 0.941895f, 0.977051f, 0.979004f, 0.979492f, 0.979004f, 0.979492f, 0.979004f, 0.000583f, 0.001696f, 0.003044f, 0.004276f,
+ 0.005394f, 0.007111f, 0.009048f, 0.010727f, 0.012802f, 0.014549f, 0.017319f, 0.019943f, 0.023132f, 0.026459f, 0.030212f, 0.034576f,
+ 0.039612f, 0.045105f, 0.051422f, 0.058594f, 0.066833f, 0.076416f, 0.087341f, 0.099792f, 0.113647f, 0.130005f, 0.147827f, 0.168945f,
+ 0.192261f, 0.218750f, 0.247803f, 0.280029f, 0.314209f, 0.351074f, 0.389404f, 0.429199f, 0.468750f, 0.508301f, 0.547852f, 0.585938f,
+ 0.622070f, 0.655762f, 0.687988f, 0.718262f, 0.744629f, 0.769531f, 0.792480f, 0.812500f, 0.832520f, 0.848633f, 0.863770f, 0.877441f,
+ 0.890137f, 0.901367f, 0.912109f, 0.921387f, 0.929199f, 0.937500f, 0.975586f, 0.978027f, 0.978027f, 0.977539f, 0.977539f, 0.977051f,
+ 0.000463f, 0.001634f, 0.002899f, 0.003574f, 0.004932f, 0.006233f, 0.007866f, 0.009644f, 0.011055f, 0.012894f, 0.015518f, 0.017792f,
+ 0.020279f, 0.023178f, 0.026657f, 0.030136f, 0.034271f, 0.039062f, 0.044586f, 0.050446f, 0.057739f, 0.065613f, 0.074646f, 0.084900f,
+ 0.097107f, 0.111023f, 0.126099f, 0.143921f, 0.164673f, 0.187500f, 0.213257f, 0.242065f, 0.273926f, 0.308594f, 0.344971f, 0.383301f,
+ 0.423340f, 0.463623f, 0.503906f, 0.543945f, 0.582520f, 0.619629f, 0.653809f, 0.686523f, 0.717285f, 0.744629f, 0.770020f, 0.792969f,
+ 0.814453f, 0.833496f, 0.850098f, 0.866211f, 0.879395f, 0.893066f, 0.904297f, 0.914551f, 0.923828f, 0.932129f, 0.973145f, 0.976074f,
+ 0.976562f, 0.976074f, 0.976074f, 0.976074f, 0.000472f, 0.001289f, 0.002508f, 0.003481f, 0.004459f, 0.005894f, 0.007042f, 0.008232f,
+ 0.009972f, 0.011719f, 0.013435f, 0.015884f, 0.017899f, 0.020386f, 0.023422f, 0.026428f, 0.030411f, 0.034180f, 0.038757f, 0.043854f,
+ 0.049652f, 0.056549f, 0.064270f, 0.073303f, 0.083252f, 0.095093f, 0.107910f, 0.123169f, 0.141113f, 0.160645f, 0.183472f, 0.208618f,
+ 0.237305f, 0.268799f, 0.302734f, 0.339600f, 0.377930f, 0.418457f, 0.459473f, 0.500000f, 0.540527f, 0.579102f, 0.617188f, 0.652832f,
+ 0.685547f, 0.716309f, 0.745117f, 0.771484f, 0.794922f, 0.815918f, 0.834961f, 0.853027f, 0.868652f, 0.882324f, 0.895996f, 0.907227f,
+ 0.916992f, 0.927246f, 0.972168f, 0.974121f, 0.975098f, 0.973633f, 0.974609f, 0.973633f, 0.000238f, 0.001453f, 0.002047f, 0.002985f,
+ 0.004227f, 0.005272f, 0.006096f, 0.007309f, 0.008957f, 0.010437f, 0.012184f, 0.014214f, 0.015793f, 0.018082f, 0.020538f, 0.023270f,
+ 0.026505f, 0.029648f, 0.033813f, 0.038300f, 0.043457f, 0.049042f, 0.055298f, 0.062744f, 0.070984f, 0.081299f, 0.092590f, 0.105591f,
+ 0.120361f, 0.137695f, 0.156982f, 0.179443f, 0.204346f, 0.232788f, 0.263672f, 0.297363f, 0.334229f, 0.373047f, 0.414307f, 0.455322f,
+ 0.497314f, 0.538086f, 0.578613f, 0.616211f, 0.653320f, 0.686523f, 0.718262f, 0.747559f, 0.773438f, 0.797363f, 0.818848f, 0.838867f,
+ 0.856934f, 0.871582f, 0.885742f, 0.898926f, 0.910645f, 0.920410f, 0.970215f, 0.971680f, 0.972656f, 0.972656f, 0.972168f, 0.972168f,
+ 0.000376f, 0.001075f, 0.002052f, 0.002823f, 0.003603f, 0.004509f, 0.005619f, 0.007008f, 0.008064f, 0.009132f, 0.010849f, 0.012314f,
+ 0.013817f, 0.015945f, 0.018188f, 0.020676f, 0.022995f, 0.026230f, 0.029587f, 0.033234f, 0.037598f, 0.042328f, 0.048004f, 0.054230f,
+ 0.061188f, 0.069824f, 0.079468f, 0.090454f, 0.103271f, 0.117493f, 0.134644f, 0.153931f, 0.175293f, 0.200806f, 0.228149f, 0.259277f,
+ 0.293945f, 0.330566f, 0.370117f, 0.410889f, 0.453369f, 0.495605f, 0.537109f, 0.578125f, 0.616699f, 0.653809f, 0.689453f, 0.721191f,
+ 0.750000f, 0.776855f, 0.800293f, 0.822754f, 0.841309f, 0.859863f, 0.876465f, 0.890137f, 0.902832f, 0.914062f, 0.967773f, 0.970703f,
+ 0.970703f, 0.970703f, 0.970703f, 0.970703f, 0.000237f, 0.000972f, 0.001674f, 0.002413f, 0.003336f, 0.003956f, 0.005093f, 0.006039f,
+ 0.007069f, 0.008202f, 0.009613f, 0.011017f, 0.012520f, 0.014282f, 0.016068f, 0.017853f, 0.020508f, 0.023117f, 0.025986f, 0.029160f,
+ 0.032898f, 0.036865f, 0.041565f, 0.046997f, 0.052887f, 0.060089f, 0.068176f, 0.077515f, 0.088257f, 0.100586f, 0.114929f, 0.131592f,
+ 0.150635f, 0.172241f, 0.196411f, 0.224731f, 0.255859f, 0.290039f, 0.327393f, 0.367188f, 0.409180f, 0.451172f, 0.493896f, 0.536621f,
+ 0.578613f, 0.618164f, 0.655762f, 0.691406f, 0.724121f, 0.753906f, 0.781738f, 0.805176f, 0.827637f, 0.847656f, 0.864746f, 0.880859f,
+ 0.895508f, 0.907715f, 0.965332f, 0.968262f, 0.968750f, 0.969238f, 0.967773f, 0.967773f, 0.000450f, 0.001033f, 0.001554f, 0.002131f,
+ 0.002939f, 0.003662f, 0.004551f, 0.005722f, 0.006405f, 0.007542f, 0.008484f, 0.009750f, 0.011017f, 0.012596f, 0.014046f, 0.015854f,
+ 0.017975f, 0.020264f, 0.022736f, 0.025497f, 0.028671f, 0.031952f, 0.036011f, 0.040741f, 0.045746f, 0.051910f, 0.058868f, 0.066772f,
+ 0.075867f, 0.086304f, 0.098328f, 0.112244f, 0.128784f, 0.147217f, 0.168945f, 0.193848f, 0.221558f, 0.252441f, 0.287109f, 0.324951f,
+ 0.365234f, 0.407715f, 0.450684f, 0.494629f, 0.539062f, 0.580566f, 0.621094f, 0.659668f, 0.695801f, 0.729004f, 0.758789f, 0.786133f,
+ 0.810547f, 0.833008f, 0.852539f, 0.870117f, 0.886719f, 0.900879f, 0.962891f, 0.966309f, 0.966309f, 0.966797f, 0.966797f, 0.966309f,
+ 0.000304f, 0.001050f, 0.001257f, 0.002295f, 0.002689f, 0.003885f, 0.004284f, 0.004726f, 0.005547f, 0.006721f, 0.007595f, 0.008667f,
+ 0.009811f, 0.011330f, 0.012642f, 0.014130f, 0.016098f, 0.017975f, 0.019867f, 0.022247f, 0.024811f, 0.028030f, 0.031403f, 0.035461f,
+ 0.039642f, 0.044800f, 0.050720f, 0.057495f, 0.065002f, 0.073914f, 0.084290f, 0.095947f, 0.109985f, 0.126343f, 0.144409f, 0.166138f,
+ 0.190918f, 0.218750f, 0.250244f, 0.285400f, 0.323730f, 0.364258f, 0.407471f, 0.452148f, 0.496338f, 0.540527f, 0.584473f, 0.625977f,
+ 0.665039f, 0.701172f, 0.735352f, 0.765137f, 0.792480f, 0.817383f, 0.840332f, 0.859863f, 0.876953f, 0.893066f, 0.959961f, 0.963379f,
+ 0.963867f, 0.964355f, 0.963867f, 0.963867f, 0.000228f, 0.000682f, 0.001293f, 0.001717f, 0.002352f, 0.003160f, 0.003626f, 0.004360f,
+ 0.005348f, 0.005871f, 0.006870f, 0.007660f, 0.008957f, 0.010002f, 0.011299f, 0.012375f, 0.014099f, 0.015900f, 0.017670f, 0.019363f,
+ 0.022034f, 0.024216f, 0.027420f, 0.030930f, 0.034454f, 0.038910f, 0.044006f, 0.049530f, 0.055878f, 0.063477f, 0.072083f, 0.082275f,
+ 0.094177f, 0.107666f, 0.123840f, 0.142090f, 0.163452f, 0.188477f, 0.216919f, 0.248047f, 0.283447f, 0.322754f, 0.364990f, 0.408447f,
+ 0.453613f, 0.500000f, 0.544922f, 0.589355f, 0.631348f, 0.671387f, 0.708008f, 0.742188f, 0.773438f, 0.800781f, 0.824219f, 0.846680f,
+ 0.866699f, 0.884277f, 0.958008f, 0.960938f, 0.961426f, 0.962402f, 0.961914f, 0.960938f, 0.000239f, 0.000731f, 0.001204f, 0.001637f,
+ 0.002144f, 0.002913f, 0.003521f, 0.003828f, 0.004517f, 0.005291f, 0.006203f, 0.006954f, 0.007740f, 0.008911f, 0.010239f, 0.011017f,
+ 0.012413f, 0.013863f, 0.015396f, 0.017181f, 0.019196f, 0.021439f, 0.024078f, 0.026993f, 0.030182f, 0.033752f, 0.038055f, 0.042664f,
+ 0.048004f, 0.054657f, 0.061920f, 0.070312f, 0.080688f, 0.092041f, 0.105774f, 0.121094f, 0.140015f, 0.161255f, 0.186523f, 0.214966f,
+ 0.246948f, 0.283203f, 0.322998f, 0.365967f, 0.410400f, 0.457275f, 0.503906f, 0.550781f, 0.596191f, 0.638672f, 0.678711f, 0.716797f,
+ 0.750488f, 0.781738f, 0.809082f, 0.833496f, 0.855469f, 0.874512f, 0.954590f, 0.958008f, 0.958984f, 0.958984f, 0.958984f, 0.958984f,
+ 0.000226f, 0.000663f, 0.001073f, 0.001420f, 0.002163f, 0.002567f, 0.003052f, 0.003433f, 0.004181f, 0.004734f, 0.005516f, 0.006424f,
+ 0.007050f, 0.008003f, 0.008659f, 0.009827f, 0.011086f, 0.012398f, 0.013649f, 0.015266f, 0.016891f, 0.018921f, 0.021118f, 0.023560f,
+ 0.026505f, 0.029556f, 0.032715f, 0.036865f, 0.041077f, 0.046570f, 0.053314f, 0.060150f, 0.068787f, 0.078552f, 0.090027f, 0.103638f,
+ 0.119690f, 0.138184f, 0.159546f, 0.184692f, 0.213745f, 0.245972f, 0.283203f, 0.324219f, 0.367920f, 0.414062f, 0.461914f, 0.509766f,
+ 0.557129f, 0.604492f, 0.647461f, 0.688965f, 0.727051f, 0.761230f, 0.791504f, 0.819824f, 0.844238f, 0.865234f, 0.951660f, 0.955566f,
+ 0.955566f, 0.956055f, 0.955078f, 0.956543f, 0.000156f, 0.000587f, 0.001056f, 0.001499f, 0.001647f, 0.002380f, 0.002594f, 0.003469f,
+ 0.003777f, 0.004112f, 0.004925f, 0.005699f, 0.006180f, 0.007019f, 0.007957f, 0.008942f, 0.009560f, 0.010727f, 0.011963f, 0.013123f,
+ 0.014885f, 0.016556f, 0.018494f, 0.020355f, 0.022766f, 0.025330f, 0.028320f, 0.031830f, 0.035736f, 0.040161f, 0.045532f, 0.052032f,
+ 0.059113f, 0.066833f, 0.076782f, 0.088501f, 0.101868f, 0.117310f, 0.136108f, 0.157959f, 0.183105f, 0.212769f, 0.247070f, 0.284424f,
+ 0.326660f, 0.371338f, 0.419189f, 0.468994f, 0.518066f, 0.567383f, 0.613770f, 0.658691f, 0.700684f, 0.738770f, 0.771973f, 0.803223f,
+ 0.829590f, 0.854492f, 0.947266f, 0.952637f, 0.952637f, 0.952637f, 0.953125f, 0.952637f, 0.000155f, 0.000358f, 0.000859f, 0.001402f,
+ 0.001830f, 0.002092f, 0.002499f, 0.002672f, 0.003410f, 0.003763f, 0.004375f, 0.005077f, 0.005535f, 0.006554f, 0.007004f, 0.007874f,
+ 0.008537f, 0.009529f, 0.010742f, 0.011749f, 0.013016f, 0.014427f, 0.015945f, 0.017929f, 0.019775f, 0.022018f, 0.024460f, 0.027618f,
+ 0.030640f, 0.034668f, 0.039154f, 0.044250f, 0.050293f, 0.057068f, 0.065491f, 0.074951f, 0.086487f, 0.099670f, 0.115906f, 0.134277f,
+ 0.156860f, 0.182495f, 0.213135f, 0.248047f, 0.286621f, 0.329834f, 0.376709f, 0.426025f, 0.476562f, 0.527832f, 0.577637f, 0.626465f,
+ 0.671387f, 0.713379f, 0.752441f, 0.784668f, 0.815430f, 0.841797f, 0.944336f, 0.948242f, 0.949219f, 0.949219f, 0.949219f, 0.949707f,
+ 0.000233f, 0.000639f, 0.000930f, 0.001277f, 0.001579f, 0.001916f, 0.002041f, 0.002625f, 0.003035f, 0.003571f, 0.004124f, 0.004375f,
+ 0.004978f, 0.005379f, 0.006348f, 0.006886f, 0.007526f, 0.008430f, 0.009216f, 0.010262f, 0.011436f, 0.012779f, 0.014160f, 0.015549f,
+ 0.017120f, 0.019089f, 0.021164f, 0.023621f, 0.026352f, 0.029724f, 0.033447f, 0.037842f, 0.042603f, 0.048737f, 0.055573f, 0.063721f,
+ 0.073364f, 0.084778f, 0.098206f, 0.114197f, 0.133423f, 0.155762f, 0.182739f, 0.213623f, 0.249512f, 0.289795f, 0.335205f, 0.383789f,
+ 0.434814f, 0.487305f, 0.540039f, 0.591797f, 0.640137f, 0.686035f, 0.727539f, 0.765137f, 0.800293f, 0.830078f, 0.940430f, 0.944336f,
+ 0.945312f, 0.946289f, 0.945801f, 0.945312f, 0.000217f, 0.000519f, 0.000848f, 0.001180f, 0.001366f, 0.001589f, 0.001986f, 0.002354f,
+ 0.002987f, 0.003170f, 0.003576f, 0.003901f, 0.004440f, 0.004738f, 0.005543f, 0.006058f, 0.006508f, 0.007511f, 0.008163f, 0.009132f,
+ 0.010078f, 0.011246f, 0.012390f, 0.013412f, 0.014938f, 0.016632f, 0.018433f, 0.020676f, 0.022995f, 0.025726f, 0.028702f, 0.032227f,
+ 0.036377f, 0.041992f, 0.047394f, 0.053986f, 0.062195f, 0.071716f, 0.082825f, 0.096802f, 0.112732f, 0.132202f, 0.155273f, 0.182861f,
+ 0.215210f, 0.252441f, 0.294678f, 0.341553f, 0.392090f, 0.445557f, 0.499512f, 0.553711f, 0.606445f, 0.656250f, 0.703125f, 0.745605f,
+ 0.782715f, 0.816895f, 0.935547f, 0.939941f, 0.941406f, 0.941406f, 0.941406f, 0.940918f, 0.000242f, 0.000678f, 0.000781f, 0.000928f,
+ 0.001200f, 0.001592f, 0.001694f, 0.002096f, 0.002703f, 0.002903f, 0.003170f, 0.003531f, 0.003918f, 0.004433f, 0.004955f, 0.005390f,
+ 0.005939f, 0.006454f, 0.007298f, 0.007782f, 0.008759f, 0.009567f, 0.010559f, 0.011650f, 0.013046f, 0.014420f, 0.015793f, 0.017715f,
+ 0.019699f, 0.021774f, 0.024460f, 0.027481f, 0.031082f, 0.035065f, 0.039917f, 0.045715f, 0.052246f, 0.060486f, 0.070129f, 0.081482f,
+ 0.095093f, 0.111755f, 0.131714f, 0.155273f, 0.183838f, 0.217285f, 0.256348f, 0.300781f, 0.350342f, 0.403076f, 0.458252f, 0.514160f,
+ 0.570312f, 0.624512f, 0.675781f, 0.722168f, 0.763672f, 0.800293f, 0.930664f, 0.935547f, 0.937500f, 0.937012f, 0.937500f, 0.937012f,
+ 0.000239f, 0.000297f, 0.000667f, 0.000785f, 0.001044f, 0.001269f, 0.001569f, 0.001950f, 0.002224f, 0.002419f, 0.002810f, 0.003063f,
+ 0.003626f, 0.003895f, 0.004261f, 0.004749f, 0.005066f, 0.005726f, 0.006260f, 0.007019f, 0.007771f, 0.008369f, 0.008919f, 0.009941f,
+ 0.011101f, 0.012375f, 0.013519f, 0.015190f, 0.016891f, 0.018631f, 0.021011f, 0.023590f, 0.026581f, 0.029892f, 0.033875f, 0.038757f,
+ 0.044281f, 0.051147f, 0.058746f, 0.068481f, 0.079834f, 0.094116f, 0.110779f, 0.131348f, 0.155884f, 0.185669f, 0.220825f, 0.261963f,
+ 0.308594f, 0.360352f, 0.416260f, 0.473877f, 0.532715f, 0.589844f, 0.645508f, 0.696289f, 0.743652f, 0.784668f, 0.925781f, 0.930664f,
+ 0.932129f, 0.932129f, 0.932129f, 0.932129f, 0.000226f, 0.000351f, 0.000434f, 0.000624f, 0.000887f, 0.001040f, 0.001246f, 0.001665f,
+ 0.001856f, 0.002384f, 0.002420f, 0.002842f, 0.002874f, 0.003471f, 0.003735f, 0.004078f, 0.004639f, 0.004910f, 0.005531f, 0.006065f,
+ 0.006664f, 0.007370f, 0.007690f, 0.008690f, 0.009544f, 0.010536f, 0.011795f, 0.012833f, 0.014183f, 0.015900f, 0.017899f, 0.019684f,
+ 0.022430f, 0.025253f, 0.028412f, 0.032410f, 0.037201f, 0.042633f, 0.049316f, 0.057159f, 0.066772f, 0.078186f, 0.092590f, 0.110107f,
+ 0.131348f, 0.156982f, 0.188232f, 0.225342f, 0.269043f, 0.318604f, 0.373535f, 0.431641f, 0.492188f, 0.554199f, 0.613281f, 0.668945f,
+ 0.720703f, 0.766602f, 0.919922f, 0.925781f, 0.926758f, 0.926758f, 0.927246f, 0.926758f, 0.000000f, 0.000340f, 0.000458f, 0.000715f,
+ 0.000823f, 0.000895f, 0.001165f, 0.001518f, 0.001636f, 0.001876f, 0.002190f, 0.002472f, 0.002640f, 0.002964f, 0.003340f, 0.003527f,
+ 0.004005f, 0.004227f, 0.004803f, 0.005260f, 0.005878f, 0.006042f, 0.006805f, 0.007500f, 0.008469f, 0.009132f, 0.009949f, 0.011009f,
+ 0.012077f, 0.013687f, 0.014938f, 0.016785f, 0.018997f, 0.021194f, 0.023895f, 0.027283f, 0.030945f, 0.035583f, 0.040955f, 0.047760f,
+ 0.055573f, 0.065247f, 0.077209f, 0.091736f, 0.109619f, 0.131470f, 0.159058f, 0.192017f, 0.231812f, 0.278076f, 0.331543f, 0.389404f,
+ 0.450928f, 0.513672f, 0.577637f, 0.638672f, 0.695801f, 0.746582f, 0.914062f, 0.919922f, 0.920898f, 0.921387f, 0.921387f, 0.921387f,
+ 0.000146f, 0.000319f, 0.000443f, 0.000458f, 0.000704f, 0.000894f, 0.001199f, 0.001324f, 0.001549f, 0.001592f, 0.002081f, 0.002092f,
+ 0.002237f, 0.002604f, 0.002815f, 0.003159f, 0.003510f, 0.003937f, 0.004147f, 0.004425f, 0.004814f, 0.005318f, 0.005878f, 0.006413f,
+ 0.006924f, 0.007782f, 0.008408f, 0.009239f, 0.010414f, 0.011505f, 0.012642f, 0.014015f, 0.015884f, 0.017563f, 0.019852f, 0.022598f,
+ 0.025650f, 0.029663f, 0.033875f, 0.039307f, 0.045898f, 0.053955f, 0.063782f, 0.075928f, 0.090820f, 0.109497f, 0.132690f, 0.161621f,
+ 0.196777f, 0.239624f, 0.290039f, 0.346436f, 0.408203f, 0.473633f, 0.540527f, 0.605957f, 0.667969f, 0.725586f, 0.907715f, 0.914062f,
+ 0.914062f, 0.915039f, 0.915039f, 0.915039f, 0.000121f, 0.000251f, 0.000506f, 0.000532f, 0.000665f, 0.000830f, 0.001190f, 0.001164f,
+ 0.001290f, 0.001413f, 0.001755f, 0.001900f, 0.002157f, 0.002319f, 0.002422f, 0.002853f, 0.003042f, 0.003254f, 0.003529f, 0.003725f,
+ 0.004288f, 0.004585f, 0.005043f, 0.005539f, 0.005970f, 0.006386f, 0.007126f, 0.007812f, 0.008652f, 0.009598f, 0.010651f, 0.011803f,
+ 0.013130f, 0.014702f, 0.016510f, 0.018814f, 0.021011f, 0.024368f, 0.028122f, 0.032379f, 0.037506f, 0.044128f, 0.052277f, 0.062042f,
+ 0.075073f, 0.090088f, 0.110107f, 0.134766f, 0.165405f, 0.203613f, 0.249268f, 0.303955f, 0.365234f, 0.431396f, 0.501465f, 0.571777f,
+ 0.638672f, 0.702148f, 0.900879f, 0.906738f, 0.907227f, 0.908203f, 0.907227f, 0.908203f, 0.000241f, 0.000122f, 0.000417f, 0.000505f,
+ 0.000741f, 0.000782f, 0.000916f, 0.001145f, 0.001189f, 0.001289f, 0.001331f, 0.001565f, 0.001779f, 0.002020f, 0.002171f, 0.002228f,
+ 0.002623f, 0.002752f, 0.002949f, 0.003157f, 0.003515f, 0.003847f, 0.004082f, 0.004429f, 0.004990f, 0.005405f, 0.006008f, 0.006603f,
+ 0.007103f, 0.007889f, 0.008789f, 0.009766f, 0.010605f, 0.012177f, 0.013672f, 0.015305f, 0.017487f, 0.019913f, 0.022781f, 0.026245f,
+ 0.030670f, 0.035980f, 0.042389f, 0.050812f, 0.060883f, 0.073792f, 0.090088f, 0.111145f, 0.138062f, 0.171143f, 0.212524f, 0.262695f,
+ 0.322266f, 0.388184f, 0.460205f, 0.533203f, 0.606445f, 0.676758f, 0.893066f, 0.898926f, 0.899414f, 0.899414f, 0.900879f, 0.900391f,
+ 0.000000f, 0.000114f, 0.000227f, 0.000407f, 0.000532f, 0.000732f, 0.000714f, 0.000922f, 0.000993f, 0.001072f, 0.001190f, 0.001412f,
+ 0.001569f, 0.001726f, 0.001959f, 0.002071f, 0.002159f, 0.002350f, 0.002565f, 0.002729f, 0.003090f, 0.003248f, 0.003702f, 0.003761f,
+ 0.004192f, 0.004585f, 0.004925f, 0.005272f, 0.005966f, 0.006405f, 0.007275f, 0.007965f, 0.008850f, 0.009872f, 0.011017f, 0.012383f,
+ 0.014275f, 0.015900f, 0.018463f, 0.021194f, 0.024673f, 0.028870f, 0.034271f, 0.040955f, 0.048981f, 0.059723f, 0.073059f, 0.090149f,
+ 0.112549f, 0.141357f, 0.178467f, 0.223755f, 0.280029f, 0.345215f, 0.417969f, 0.494385f, 0.572266f, 0.648438f, 0.884277f, 0.890137f,
+ 0.891602f, 0.891602f, 0.893066f, 0.892090f, 0.000000f, 0.000219f, 0.000211f, 0.000333f, 0.000559f, 0.000609f, 0.000788f, 0.000805f,
+ 0.000869f, 0.000903f, 0.001101f, 0.001166f, 0.001302f, 0.001399f, 0.001456f, 0.001668f, 0.001853f, 0.001999f, 0.002102f, 0.002256f,
+ 0.002447f, 0.002728f, 0.002943f, 0.003178f, 0.003515f, 0.003836f, 0.004074f, 0.004475f, 0.004745f, 0.005325f, 0.005970f, 0.006569f,
+ 0.007248f, 0.008102f, 0.008888f, 0.010132f, 0.011169f, 0.012947f, 0.014763f, 0.016891f, 0.019760f, 0.023087f, 0.027176f, 0.032562f,
+ 0.038940f, 0.047516f, 0.058167f, 0.072754f, 0.090698f, 0.114929f, 0.146851f, 0.187744f, 0.239258f, 0.301514f, 0.373291f, 0.452637f,
+ 0.535645f, 0.617676f, 0.874512f, 0.880859f, 0.882324f, 0.883301f, 0.883301f, 0.882324f, 0.000204f, 0.000207f, 0.000204f, 0.000322f,
+ 0.000435f, 0.000480f, 0.000556f, 0.000615f, 0.000747f, 0.000782f, 0.000844f, 0.001006f, 0.001159f, 0.001191f, 0.001231f, 0.001450f,
+ 0.001585f, 0.001633f, 0.001790f, 0.001919f, 0.002117f, 0.002298f, 0.002432f, 0.002651f, 0.002939f, 0.003172f, 0.003399f, 0.003614f,
+ 0.003944f, 0.004421f, 0.004704f, 0.005203f, 0.005886f, 0.006454f, 0.007160f, 0.008049f, 0.009041f, 0.010201f, 0.011627f, 0.013237f,
+ 0.015404f, 0.018097f, 0.021469f, 0.025284f, 0.030884f, 0.036987f, 0.045990f, 0.056915f, 0.072083f, 0.092163f, 0.119141f, 0.154419f,
+ 0.200928f, 0.259277f, 0.328857f, 0.409424f, 0.495605f, 0.584473f, 0.864258f, 0.871094f, 0.872070f, 0.873047f, 0.872559f, 0.873047f,
+ 0.000000f, 0.000044f, 0.000176f, 0.000290f, 0.000410f, 0.000390f, 0.000513f, 0.000546f, 0.000647f, 0.000680f, 0.000827f, 0.000858f,
+ 0.000958f, 0.001131f, 0.001102f, 0.001223f, 0.001367f, 0.001401f, 0.001525f, 0.001610f, 0.001826f, 0.001821f, 0.002039f, 0.002253f,
+ 0.002459f, 0.002617f, 0.002708f, 0.003036f, 0.003279f, 0.003431f, 0.003805f, 0.004219f, 0.004471f, 0.004929f, 0.005569f, 0.006310f,
+ 0.007107f, 0.007988f, 0.009003f, 0.010384f, 0.011856f, 0.014015f, 0.016418f, 0.019669f, 0.023666f, 0.028809f, 0.035583f, 0.044159f,
+ 0.056458f, 0.072571f, 0.094604f, 0.124329f, 0.164917f, 0.218018f, 0.284912f, 0.364746f, 0.454102f, 0.549316f, 0.853027f, 0.859863f,
+ 0.861328f, 0.861816f, 0.861816f, 0.861816f, 0.000000f, 0.000069f, 0.000120f, 0.000345f, 0.000371f, 0.000398f, 0.000452f, 0.000396f,
+ 0.000498f, 0.000530f, 0.000596f, 0.000648f, 0.000781f, 0.000921f, 0.000995f, 0.001007f, 0.001101f, 0.001146f, 0.001282f, 0.001278f,
+ 0.001471f, 0.001554f, 0.001710f, 0.001811f, 0.001995f, 0.001986f, 0.002314f, 0.002399f, 0.002499f, 0.002903f, 0.002975f, 0.003305f,
+ 0.003605f, 0.004086f, 0.004425f, 0.005081f, 0.005402f, 0.006035f, 0.006889f, 0.007755f, 0.009041f, 0.010422f, 0.012672f, 0.014885f,
+ 0.017746f, 0.021530f, 0.026733f, 0.033691f, 0.043060f, 0.055847f, 0.073181f, 0.097473f, 0.132324f, 0.179077f, 0.241821f, 0.320068f,
+ 0.410400f, 0.510742f, 0.839844f, 0.847656f, 0.849121f, 0.849609f, 0.849121f, 0.849609f, 0.000000f, 0.000000f, 0.000121f, 0.000243f,
+ 0.000321f, 0.000354f, 0.000341f, 0.000431f, 0.000423f, 0.000444f, 0.000473f, 0.000508f, 0.000595f, 0.000706f, 0.000737f, 0.000861f,
+ 0.000869f, 0.000926f, 0.001055f, 0.001104f, 0.001199f, 0.001306f, 0.001360f, 0.001433f, 0.001530f, 0.001555f, 0.001673f, 0.001942f,
+ 0.002138f, 0.002247f, 0.002562f, 0.002609f, 0.002911f, 0.003204f, 0.003466f, 0.003757f, 0.004192f, 0.004845f, 0.005482f, 0.006008f,
+ 0.006874f, 0.007904f, 0.009171f, 0.011124f, 0.013260f, 0.015839f, 0.019821f, 0.024872f, 0.031982f, 0.041534f, 0.055054f, 0.075012f,
+ 0.103516f, 0.143677f, 0.199951f, 0.273438f, 0.364502f, 0.469482f, 0.825684f, 0.834473f, 0.834961f, 0.835938f, 0.835938f, 0.835938f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000120f, 0.000199f, 0.000272f, 0.000265f, 0.000363f, 0.000379f, 0.000388f, 0.000489f, 0.000500f,
+ 0.000488f, 0.000569f, 0.000604f, 0.000700f, 0.000683f, 0.000720f, 0.000784f, 0.000844f, 0.001009f, 0.001047f, 0.001108f, 0.001258f,
+ 0.001276f, 0.001388f, 0.001410f, 0.001565f, 0.001592f, 0.001814f, 0.001800f, 0.002167f, 0.002192f, 0.002556f, 0.002665f, 0.002905f,
+ 0.003195f, 0.003574f, 0.004028f, 0.004513f, 0.005127f, 0.005859f, 0.006847f, 0.008018f, 0.009491f, 0.011452f, 0.014099f, 0.017792f,
+ 0.022995f, 0.030258f, 0.040588f, 0.055878f, 0.078308f, 0.111450f, 0.160278f, 0.229248f, 0.318359f, 0.425781f, 0.810547f, 0.818359f,
+ 0.820312f, 0.821777f, 0.821777f, 0.820801f, 0.000000f, 0.000121f, 0.000120f, 0.000172f, 0.000195f, 0.000171f, 0.000208f, 0.000272f,
+ 0.000316f, 0.000333f, 0.000348f, 0.000355f, 0.000412f, 0.000410f, 0.000515f, 0.000485f, 0.000545f, 0.000656f, 0.000777f, 0.000659f,
+ 0.000705f, 0.000762f, 0.000874f, 0.000927f, 0.000959f, 0.000978f, 0.001045f, 0.001228f, 0.001294f, 0.001398f, 0.001443f, 0.001637f,
+ 0.001752f, 0.001925f, 0.002005f, 0.002230f, 0.002407f, 0.002670f, 0.002895f, 0.003267f, 0.003933f, 0.004280f, 0.005051f, 0.005772f,
+ 0.006718f, 0.008141f, 0.010117f, 0.012383f, 0.015930f, 0.020920f, 0.028671f, 0.039673f, 0.056702f, 0.083313f, 0.124695f, 0.185791f,
+ 0.270996f, 0.379639f, 0.793457f, 0.801270f, 0.803711f, 0.803711f, 0.804688f, 0.804688f, 0.000000f, 0.000121f, 0.000119f, 0.000144f,
+ 0.000149f, 0.000166f, 0.000173f, 0.000167f, 0.000214f, 0.000245f, 0.000334f, 0.000287f, 0.000303f, 0.000391f, 0.000401f, 0.000440f,
+ 0.000469f, 0.000493f, 0.000534f, 0.000513f, 0.000690f, 0.000682f, 0.000645f, 0.000712f, 0.000715f, 0.000747f, 0.000842f, 0.000849f,
+ 0.000967f, 0.000995f, 0.001178f, 0.001167f, 0.001273f, 0.001395f, 0.001586f, 0.001748f, 0.001796f, 0.001986f, 0.002132f, 0.002476f,
+ 0.002893f, 0.003294f, 0.003653f, 0.004086f, 0.004890f, 0.005821f, 0.006927f, 0.008553f, 0.010857f, 0.014137f, 0.019211f, 0.027084f,
+ 0.039642f, 0.059448f, 0.092468f, 0.144775f, 0.224487f, 0.332764f, 0.775391f, 0.784668f, 0.786133f, 0.786133f, 0.787109f, 0.786621f,
+ 0.000000f, 0.000000f, 0.000118f, 0.000116f, 0.000115f, 0.000113f, 0.000140f, 0.000140f, 0.000149f, 0.000220f, 0.000171f, 0.000255f,
+ 0.000274f, 0.000292f, 0.000318f, 0.000295f, 0.000346f, 0.000352f, 0.000380f, 0.000406f, 0.000401f, 0.000533f, 0.000490f, 0.000551f,
+ 0.000558f, 0.000648f, 0.000628f, 0.000723f, 0.000788f, 0.000749f, 0.000836f, 0.000941f, 0.000997f, 0.001065f, 0.001112f, 0.001207f,
+ 0.001328f, 0.001535f, 0.001621f, 0.001840f, 0.002022f, 0.002163f, 0.002522f, 0.002825f, 0.003391f, 0.003830f, 0.004616f, 0.005665f,
+ 0.007172f, 0.009247f, 0.012482f, 0.017532f, 0.025970f, 0.040161f, 0.064941f, 0.107422f, 0.178833f, 0.283447f, 0.754883f, 0.764648f,
+ 0.766113f, 0.767090f, 0.767578f, 0.767090f, 0.000000f, 0.000119f, 0.000116f, 0.000114f, 0.000112f, 0.000110f, 0.000109f, 0.000117f,
+ 0.000114f, 0.000117f, 0.000125f, 0.000193f, 0.000141f, 0.000196f, 0.000221f, 0.000235f, 0.000259f, 0.000278f, 0.000308f, 0.000316f,
+ 0.000323f, 0.000315f, 0.000329f, 0.000351f, 0.000388f, 0.000422f, 0.000465f, 0.000512f, 0.000571f, 0.000568f, 0.000588f, 0.000633f,
+ 0.000747f, 0.000751f, 0.000829f, 0.000958f, 0.000914f, 0.001104f, 0.001145f, 0.001255f, 0.001337f, 0.001499f, 0.001701f, 0.001966f,
+ 0.002275f, 0.002609f, 0.003119f, 0.003773f, 0.004658f, 0.005920f, 0.007935f, 0.010948f, 0.015900f, 0.025284f, 0.042511f, 0.075012f,
+ 0.135010f, 0.234619f, 0.733398f, 0.743164f, 0.744629f, 0.745117f, 0.745605f, 0.745605f, 0.000000f, 0.000116f, 0.000113f, 0.000111f,
+ 0.000108f, 0.000106f, 0.000104f, 0.000103f, 0.000098f, 0.000092f, 0.000099f, 0.000085f, 0.000098f, 0.000105f, 0.000163f, 0.000162f,
+ 0.000128f, 0.000193f, 0.000203f, 0.000214f, 0.000284f, 0.000239f, 0.000303f, 0.000268f, 0.000327f, 0.000326f, 0.000329f, 0.000330f,
+ 0.000407f, 0.000486f, 0.000406f, 0.000454f, 0.000465f, 0.000495f, 0.000535f, 0.000592f, 0.000648f, 0.000727f, 0.000753f, 0.000807f,
+ 0.000956f, 0.000992f, 0.001108f, 0.001294f, 0.001418f, 0.001703f, 0.001978f, 0.002390f, 0.002930f, 0.003643f, 0.004753f, 0.006519f,
+ 0.009499f, 0.014824f, 0.025497f, 0.048065f, 0.095154f, 0.185425f, 0.709961f, 0.719727f, 0.721191f, 0.721191f, 0.721680f, 0.721680f,
+ 0.000000f, 0.000113f, 0.000107f, 0.000106f, 0.000102f, 0.000100f, 0.000097f, 0.000096f, 0.000095f, 0.000092f, 0.000087f, 0.000083f,
+ 0.000078f, 0.000098f, 0.000077f, 0.000091f, 0.000114f, 0.000128f, 0.000114f, 0.000147f, 0.000154f, 0.000162f, 0.000186f, 0.000174f,
+ 0.000220f, 0.000233f, 0.000235f, 0.000245f, 0.000250f, 0.000253f, 0.000321f, 0.000296f, 0.000311f, 0.000354f, 0.000417f, 0.000419f,
+ 0.000438f, 0.000443f, 0.000495f, 0.000513f, 0.000585f, 0.000634f, 0.000705f, 0.000778f, 0.000912f, 0.001002f, 0.001163f, 0.001379f,
+ 0.001745f, 0.002092f, 0.002697f, 0.003721f, 0.005230f, 0.008194f, 0.013870f, 0.027359f, 0.061066f, 0.138062f, 0.685547f, 0.694336f,
+ 0.696777f, 0.696289f, 0.697754f, 0.697754f, 0.000000f, 0.000106f, 0.000102f, 0.000097f, 0.000093f, 0.000091f, 0.000089f, 0.000087f,
+ 0.000085f, 0.000084f, 0.000082f, 0.000080f, 0.000076f, 0.000072f, 0.000069f, 0.000074f, 0.000076f, 0.000059f, 0.000075f, 0.000062f,
+ 0.000085f, 0.000091f, 0.000103f, 0.000111f, 0.000121f, 0.000135f, 0.000128f, 0.000159f, 0.000171f, 0.000160f, 0.000178f, 0.000193f,
+ 0.000196f, 0.000202f, 0.000220f, 0.000230f, 0.000273f, 0.000289f, 0.000312f, 0.000330f, 0.000335f, 0.000397f, 0.000408f, 0.000463f,
+ 0.000517f, 0.000577f, 0.000691f, 0.000771f, 0.000919f, 0.001150f, 0.001436f, 0.001955f, 0.002737f, 0.004185f, 0.007103f, 0.013863f,
+ 0.033661f, 0.093628f, 0.657227f, 0.667480f, 0.668945f, 0.669434f, 0.670898f, 0.669922f, 0.000108f, 0.000093f, 0.000087f, 0.000082f,
+ 0.000079f, 0.000078f, 0.000075f, 0.000073f, 0.000071f, 0.000070f, 0.000069f, 0.000069f, 0.000067f, 0.000066f, 0.000064f, 0.000061f,
+ 0.000059f, 0.000056f, 0.000053f, 0.000051f, 0.000053f, 0.000049f, 0.000044f, 0.000047f, 0.000055f, 0.000058f, 0.000071f, 0.000077f,
+ 0.000093f, 0.000094f, 0.000103f, 0.000102f, 0.000110f, 0.000126f, 0.000130f, 0.000138f, 0.000143f, 0.000166f, 0.000166f, 0.000178f,
+ 0.000194f, 0.000217f, 0.000228f, 0.000231f, 0.000265f, 0.000330f, 0.000341f, 0.000411f, 0.000459f, 0.000549f, 0.000705f, 0.000867f,
+ 0.001228f, 0.001863f, 0.003143f, 0.006283f, 0.015594f, 0.054993f, 0.628418f, 0.638184f, 0.640137f, 0.640137f, 0.641602f, 0.641602f,
+ 0.000071f, 0.000058f, 0.000059f, 0.000058f, 0.000054f, 0.000054f, 0.000051f, 0.000053f, 0.000051f, 0.000052f, 0.000050f, 0.000050f,
+ 0.000051f, 0.000050f, 0.000049f, 0.000049f, 0.000049f, 0.000049f, 0.000047f, 0.000045f, 0.000043f, 0.000041f, 0.000039f, 0.000038f,
+ 0.000036f, 0.000034f, 0.000035f, 0.000037f, 0.000033f, 0.000034f, 0.000038f, 0.000047f, 0.000054f, 0.000061f, 0.000064f, 0.000068f,
+ 0.000069f, 0.000076f, 0.000083f, 0.000092f, 0.000098f, 0.000103f, 0.000112f, 0.000129f, 0.000113f, 0.000139f, 0.000152f, 0.000185f,
+ 0.000204f, 0.000238f, 0.000282f, 0.000365f, 0.000503f, 0.000685f, 0.001178f, 0.002274f, 0.006100f, 0.025162f, 0.597656f, 0.607910f,
+ 0.610840f, 0.611816f, 0.610352f, 0.611328f, 0.000000f, 0.000000f, 0.000004f, 0.000012f, 0.000014f, 0.000020f, 0.000022f, 0.000023f,
+ 0.000024f, 0.000022f, 0.000025f, 0.000027f, 0.000027f, 0.000026f, 0.000028f, 0.000029f, 0.000029f, 0.000029f, 0.000030f, 0.000030f,
+ 0.000030f, 0.000030f, 0.000030f, 0.000030f, 0.000029f, 0.000028f, 0.000027f, 0.000026f, 0.000024f, 0.000023f, 0.000022f, 0.000021f,
+ 0.000020f, 0.000019f, 0.000018f, 0.000019f, 0.000023f, 0.000024f, 0.000027f, 0.000032f, 0.000038f, 0.000040f, 0.000041f, 0.000045f,
+ 0.000054f, 0.000052f, 0.000055f, 0.000060f, 0.000068f, 0.000089f, 0.000089f, 0.000115f, 0.000146f, 0.000198f, 0.000318f, 0.000586f,
+ 0.001614f, 0.008278f, 0.565918f, 0.576660f, 0.578125f, 0.579102f, 0.579590f, 0.580078f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f,
+ 0.000003f, 0.000003f, 0.000005f, 0.000005f, 0.000006f, 0.000007f, 0.000009f, 0.000009f, 0.000010f, 0.000011f, 0.000012f, 0.000012f,
+ 0.000013f, 0.000014f, 0.000014f, 0.000015f, 0.000014f, 0.000014f, 0.000013f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000010f,
+ 0.000009f, 0.000009f, 0.000008f, 0.000010f, 0.000013f, 0.000013f, 0.000013f, 0.000017f, 0.000017f, 0.000022f, 0.000021f, 0.000023f,
+ 0.000031f, 0.000032f, 0.000049f, 0.000079f, 0.000204f, 0.001328f, 0.533203f, 0.543945f, 0.545410f, 0.546387f, 0.546875f, 0.546875f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000003f,
+ 0.000003f, 0.000003f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000016f, 0.499756f, 0.510254f,
+ 0.513184f, 0.513672f, 0.514160f, 0.514160f,
+ },
+ {
+ 0.076172f, 0.209839f, 0.320312f, 0.408691f, 0.481689f, 0.541016f, 0.591309f, 0.633789f, 0.668945f, 0.699707f, 0.727051f, 0.749512f,
+ 0.770020f, 0.788086f, 0.803711f, 0.817871f, 0.832520f, 0.843750f, 0.854492f, 0.864258f, 0.873535f, 0.881836f, 0.889160f, 0.895996f,
+ 0.903320f, 0.909180f, 0.914551f, 0.920410f, 0.925781f, 0.929199f, 0.933594f, 0.938965f, 0.942383f, 0.946289f, 0.949219f, 0.953125f,
+ 0.955566f, 0.959473f, 0.961914f, 0.964355f, 0.967285f, 0.970215f, 0.971680f, 0.974609f, 0.976562f, 0.978516f, 0.980469f, 0.982422f,
+ 0.984375f, 0.986328f, 0.987793f, 0.989746f, 0.990723f, 0.992676f, 0.993652f, 0.995117f, 0.996582f, 0.998047f, 0.999023f, 0.997559f,
+ 0.996582f, 0.995605f, 0.994629f, 0.993652f, 0.043396f, 0.133301f, 0.221313f, 0.303223f, 0.377441f, 0.442871f, 0.500000f, 0.550781f,
+ 0.595215f, 0.632812f, 0.666992f, 0.696777f, 0.723145f, 0.745605f, 0.765137f, 0.783691f, 0.799805f, 0.815430f, 0.828613f, 0.839844f,
+ 0.851562f, 0.861328f, 0.871582f, 0.879395f, 0.887207f, 0.894531f, 0.901855f, 0.907227f, 0.914062f, 0.919434f, 0.924316f, 0.928711f,
+ 0.933594f, 0.937988f, 0.942383f, 0.945801f, 0.949219f, 0.953125f, 0.956055f, 0.959473f, 0.962402f, 0.964355f, 0.967773f, 0.970215f,
+ 0.972656f, 0.975098f, 0.977051f, 0.979492f, 0.980957f, 0.983398f, 0.985352f, 0.986816f, 0.988281f, 0.990234f, 0.991699f, 0.993652f,
+ 0.995117f, 0.996094f, 0.998047f, 0.997070f, 0.996094f, 0.995117f, 0.994141f, 0.993164f, 0.027832f, 0.088440f, 0.153198f, 0.221313f,
+ 0.288086f, 0.352051f, 0.411621f, 0.466797f, 0.515625f, 0.561523f, 0.601074f, 0.637207f, 0.667969f, 0.695312f, 0.721680f, 0.743652f,
+ 0.763184f, 0.781738f, 0.797852f, 0.812500f, 0.826172f, 0.838867f, 0.850098f, 0.859863f, 0.869141f, 0.877930f, 0.886230f, 0.893555f,
+ 0.900879f, 0.907227f, 0.912598f, 0.918457f, 0.922852f, 0.928711f, 0.934082f, 0.938477f, 0.942383f, 0.946289f, 0.950195f, 0.953125f,
+ 0.956543f, 0.959961f, 0.962402f, 0.965820f, 0.968262f, 0.970703f, 0.973145f, 0.975586f, 0.978027f, 0.979980f, 0.982422f, 0.984375f,
+ 0.985840f, 0.987793f, 0.989746f, 0.991211f, 0.993164f, 0.994141f, 0.997559f, 0.996582f, 0.995605f, 0.994629f, 0.993652f, 0.993164f,
+ 0.018921f, 0.061493f, 0.109497f, 0.161987f, 0.217041f, 0.273438f, 0.330811f, 0.384521f, 0.437500f, 0.486084f, 0.530273f, 0.570312f,
+ 0.607910f, 0.640137f, 0.670410f, 0.697266f, 0.722656f, 0.743652f, 0.763672f, 0.781250f, 0.797363f, 0.812012f, 0.825684f, 0.837891f,
+ 0.848633f, 0.859863f, 0.869141f, 0.878418f, 0.886719f, 0.893066f, 0.900879f, 0.906738f, 0.913574f, 0.919434f, 0.924316f, 0.930176f,
+ 0.934082f, 0.939453f, 0.942871f, 0.946777f, 0.950684f, 0.954590f, 0.958008f, 0.960449f, 0.963379f, 0.966797f, 0.969238f, 0.971680f,
+ 0.974121f, 0.977051f, 0.978516f, 0.980957f, 0.983398f, 0.985352f, 0.987305f, 0.989258f, 0.991211f, 0.992676f, 0.996094f, 0.995605f,
+ 0.994629f, 0.993652f, 0.993164f, 0.992188f, 0.013596f, 0.044495f, 0.080017f, 0.119873f, 0.164307f, 0.211670f, 0.261475f, 0.311523f,
+ 0.362793f, 0.410645f, 0.458008f, 0.501953f, 0.542969f, 0.580078f, 0.614746f, 0.645996f, 0.674805f, 0.701172f, 0.723633f, 0.745117f,
+ 0.765625f, 0.782227f, 0.798828f, 0.812988f, 0.826172f, 0.838867f, 0.849609f, 0.861328f, 0.870605f, 0.878906f, 0.887695f, 0.895020f,
+ 0.901855f, 0.907715f, 0.914551f, 0.920898f, 0.925781f, 0.930664f, 0.934570f, 0.940918f, 0.943848f, 0.947754f, 0.951660f, 0.955566f,
+ 0.958984f, 0.961914f, 0.964844f, 0.967773f, 0.970703f, 0.973145f, 0.975586f, 0.978027f, 0.979980f, 0.982422f, 0.984863f, 0.986328f,
+ 0.988770f, 0.990234f, 0.995117f, 0.995117f, 0.994141f, 0.993652f, 0.992676f, 0.991699f, 0.010414f, 0.033203f, 0.060364f, 0.090942f,
+ 0.125610f, 0.163818f, 0.206421f, 0.250488f, 0.295898f, 0.341797f, 0.388428f, 0.433350f, 0.475830f, 0.517090f, 0.555176f, 0.589844f,
+ 0.622559f, 0.652344f, 0.680176f, 0.704590f, 0.729004f, 0.748535f, 0.767578f, 0.784668f, 0.800293f, 0.814941f, 0.828125f, 0.839844f,
+ 0.852051f, 0.861816f, 0.871582f, 0.879883f, 0.888672f, 0.895996f, 0.903320f, 0.909180f, 0.916016f, 0.921387f, 0.927246f, 0.931641f,
+ 0.937012f, 0.940918f, 0.946289f, 0.950195f, 0.953125f, 0.957520f, 0.960449f, 0.963867f, 0.966309f, 0.969238f, 0.972168f, 0.975098f,
+ 0.976562f, 0.979492f, 0.981934f, 0.983887f, 0.985840f, 0.988281f, 0.994629f, 0.994141f, 0.993652f, 0.992676f, 0.991699f, 0.990723f,
+ 0.007889f, 0.025772f, 0.046539f, 0.070312f, 0.097168f, 0.128540f, 0.162354f, 0.200195f, 0.239868f, 0.281738f, 0.325195f, 0.368896f,
+ 0.411621f, 0.453125f, 0.493652f, 0.531738f, 0.566406f, 0.601074f, 0.631836f, 0.659668f, 0.687988f, 0.709961f, 0.732422f, 0.753418f,
+ 0.770996f, 0.788086f, 0.804199f, 0.818359f, 0.831543f, 0.843750f, 0.854492f, 0.864746f, 0.873535f, 0.882812f, 0.890137f, 0.898438f,
+ 0.905273f, 0.912598f, 0.917969f, 0.923828f, 0.929199f, 0.934570f, 0.938477f, 0.942871f, 0.948242f, 0.951660f, 0.955078f, 0.958496f,
+ 0.961914f, 0.965332f, 0.968262f, 0.971680f, 0.973633f, 0.976562f, 0.979492f, 0.981445f, 0.983398f, 0.985352f, 0.993164f, 0.993164f,
+ 0.992676f, 0.991699f, 0.991211f, 0.990234f, 0.006332f, 0.020325f, 0.036438f, 0.055573f, 0.077026f, 0.101562f, 0.129028f, 0.160278f,
+ 0.194458f, 0.230347f, 0.268555f, 0.309326f, 0.350830f, 0.391846f, 0.432373f, 0.472412f, 0.509277f, 0.545410f, 0.579102f, 0.611816f,
+ 0.640625f, 0.668945f, 0.693848f, 0.716797f, 0.739258f, 0.758789f, 0.775879f, 0.793945f, 0.807617f, 0.821777f, 0.834961f, 0.846680f,
+ 0.857422f, 0.867676f, 0.877441f, 0.885742f, 0.893555f, 0.900391f, 0.908203f, 0.915039f, 0.920898f, 0.926270f, 0.931152f, 0.937012f,
+ 0.940918f, 0.946289f, 0.949219f, 0.954102f, 0.958008f, 0.960938f, 0.964355f, 0.967773f, 0.970703f, 0.973145f, 0.975586f, 0.978516f,
+ 0.981445f, 0.983398f, 0.992188f, 0.992188f, 0.991699f, 0.990723f, 0.990723f, 0.989746f, 0.005226f, 0.016647f, 0.029556f, 0.044434f,
+ 0.061523f, 0.081543f, 0.103760f, 0.129150f, 0.157837f, 0.188477f, 0.221924f, 0.257812f, 0.295654f, 0.334473f, 0.374023f, 0.412842f,
+ 0.451904f, 0.489990f, 0.525391f, 0.560059f, 0.593262f, 0.623047f, 0.651855f, 0.678223f, 0.702148f, 0.725098f, 0.745605f, 0.764160f,
+ 0.781738f, 0.799316f, 0.812500f, 0.827148f, 0.838867f, 0.851074f, 0.861328f, 0.871582f, 0.880371f, 0.889648f, 0.896973f, 0.904297f,
+ 0.911621f, 0.917480f, 0.923340f, 0.929688f, 0.934570f, 0.939941f, 0.943848f, 0.948242f, 0.951660f, 0.957031f, 0.959473f, 0.963379f,
+ 0.966797f, 0.969727f, 0.972656f, 0.976074f, 0.979004f, 0.980957f, 0.991699f, 0.991211f, 0.990723f, 0.990234f, 0.989746f, 0.988770f,
+ 0.004108f, 0.013542f, 0.023819f, 0.036194f, 0.050262f, 0.066223f, 0.084717f, 0.104797f, 0.128174f, 0.153809f, 0.182861f, 0.213989f,
+ 0.247437f, 0.282471f, 0.319580f, 0.357422f, 0.395508f, 0.433350f, 0.470947f, 0.506348f, 0.542480f, 0.575684f, 0.605957f, 0.635254f,
+ 0.662109f, 0.687988f, 0.711426f, 0.732910f, 0.753418f, 0.771973f, 0.789062f, 0.804688f, 0.819336f, 0.831543f, 0.843750f, 0.855469f,
+ 0.866211f, 0.875488f, 0.884766f, 0.893066f, 0.901367f, 0.907715f, 0.914062f, 0.921387f, 0.927246f, 0.932129f, 0.937012f, 0.942383f,
+ 0.946777f, 0.951660f, 0.956055f, 0.959473f, 0.962891f, 0.966309f, 0.969238f, 0.972168f, 0.975098f, 0.978027f, 0.989746f, 0.990234f,
+ 0.990234f, 0.989258f, 0.989258f, 0.988281f, 0.003597f, 0.011330f, 0.020065f, 0.029938f, 0.041412f, 0.054504f, 0.068970f, 0.086182f,
+ 0.105469f, 0.126709f, 0.151123f, 0.177612f, 0.206909f, 0.237915f, 0.271484f, 0.305664f, 0.342529f, 0.378906f, 0.416748f, 0.453125f,
+ 0.489502f, 0.524414f, 0.558105f, 0.589844f, 0.619629f, 0.646973f, 0.673828f, 0.698242f, 0.721191f, 0.742676f, 0.761230f, 0.778809f,
+ 0.796387f, 0.810547f, 0.824707f, 0.837891f, 0.850098f, 0.861328f, 0.871094f, 0.881348f, 0.889648f, 0.896973f, 0.904785f, 0.912109f,
+ 0.919434f, 0.924316f, 0.931152f, 0.936523f, 0.941895f, 0.946289f, 0.951172f, 0.955078f, 0.959473f, 0.962402f, 0.965820f, 0.969238f,
+ 0.972656f, 0.975586f, 0.988770f, 0.989258f, 0.989258f, 0.988770f, 0.987793f, 0.987305f, 0.002836f, 0.009857f, 0.016693f, 0.025208f,
+ 0.034668f, 0.045288f, 0.057617f, 0.071106f, 0.087463f, 0.104858f, 0.125000f, 0.147461f, 0.172119f, 0.199829f, 0.229248f, 0.260742f,
+ 0.294434f, 0.329102f, 0.365479f, 0.400879f, 0.437012f, 0.472656f, 0.508301f, 0.541992f, 0.574219f, 0.604980f, 0.634766f, 0.660645f,
+ 0.686523f, 0.709473f, 0.731445f, 0.751953f, 0.770996f, 0.789062f, 0.804199f, 0.817871f, 0.832520f, 0.844727f, 0.856445f, 0.867188f,
+ 0.876953f, 0.886719f, 0.895020f, 0.902832f, 0.909668f, 0.916504f, 0.923340f, 0.929688f, 0.935547f, 0.939941f, 0.944824f, 0.949707f,
+ 0.954102f, 0.958496f, 0.961914f, 0.965820f, 0.969238f, 0.972656f, 0.987793f, 0.988281f, 0.988281f, 0.987793f, 0.986816f, 0.986328f,
+ 0.002541f, 0.008118f, 0.014244f, 0.021194f, 0.029480f, 0.037811f, 0.048584f, 0.060028f, 0.073242f, 0.088196f, 0.104370f, 0.123047f,
+ 0.144531f, 0.167114f, 0.193237f, 0.220947f, 0.250977f, 0.282227f, 0.316162f, 0.351074f, 0.386719f, 0.422119f, 0.457520f, 0.492432f,
+ 0.526367f, 0.559082f, 0.590332f, 0.621094f, 0.648438f, 0.674316f, 0.698730f, 0.721191f, 0.742188f, 0.762207f, 0.780762f, 0.797363f,
+ 0.812500f, 0.826172f, 0.840332f, 0.852051f, 0.863770f, 0.873535f, 0.883301f, 0.892090f, 0.900391f, 0.908203f, 0.915039f, 0.922363f,
+ 0.928711f, 0.933594f, 0.939453f, 0.944824f, 0.950195f, 0.953125f, 0.958008f, 0.962402f, 0.965332f, 0.969238f, 0.986816f, 0.987305f,
+ 0.986816f, 0.986328f, 0.985840f, 0.984863f, 0.002115f, 0.007030f, 0.012138f, 0.017944f, 0.024521f, 0.032318f, 0.040955f, 0.050476f,
+ 0.061676f, 0.073914f, 0.087769f, 0.103271f, 0.121033f, 0.140747f, 0.162598f, 0.187256f, 0.213379f, 0.242065f, 0.272705f, 0.305176f,
+ 0.338623f, 0.373047f, 0.408691f, 0.443848f, 0.478760f, 0.512695f, 0.545898f, 0.577637f, 0.607910f, 0.636719f, 0.663086f, 0.688965f,
+ 0.712402f, 0.734863f, 0.754395f, 0.774414f, 0.791016f, 0.806641f, 0.822266f, 0.835449f, 0.848145f, 0.859863f, 0.870605f, 0.880371f,
+ 0.890137f, 0.898438f, 0.906250f, 0.914551f, 0.921387f, 0.926758f, 0.933594f, 0.938965f, 0.944336f, 0.949219f, 0.954102f, 0.958984f,
+ 0.961914f, 0.965820f, 0.985840f, 0.986328f, 0.985840f, 0.985352f, 0.985352f, 0.984375f, 0.001999f, 0.006226f, 0.010384f, 0.015594f,
+ 0.021027f, 0.027435f, 0.034637f, 0.042969f, 0.052124f, 0.062469f, 0.074097f, 0.087646f, 0.102173f, 0.119141f, 0.137695f, 0.158203f,
+ 0.181396f, 0.206543f, 0.233643f, 0.263184f, 0.295166f, 0.327148f, 0.360596f, 0.395264f, 0.430420f, 0.464600f, 0.499023f, 0.532227f,
+ 0.564941f, 0.595703f, 0.625000f, 0.651855f, 0.679199f, 0.703613f, 0.726074f, 0.747559f, 0.766602f, 0.784668f, 0.801758f, 0.816895f,
+ 0.831055f, 0.843750f, 0.856934f, 0.867188f, 0.878418f, 0.887207f, 0.896484f, 0.904785f, 0.913086f, 0.919922f, 0.926270f, 0.932617f,
+ 0.938477f, 0.944336f, 0.949707f, 0.953613f, 0.958496f, 0.962891f, 0.983887f, 0.984863f, 0.984863f, 0.984375f, 0.983887f, 0.983398f,
+ 0.001891f, 0.004959f, 0.009300f, 0.013786f, 0.018433f, 0.023560f, 0.029892f, 0.037018f, 0.044586f, 0.053284f, 0.062805f, 0.074341f,
+ 0.086975f, 0.100586f, 0.116760f, 0.133789f, 0.154175f, 0.176025f, 0.200317f, 0.226318f, 0.254395f, 0.284424f, 0.316650f, 0.349365f,
+ 0.383301f, 0.418213f, 0.452393f, 0.487061f, 0.520508f, 0.553223f, 0.584473f, 0.613770f, 0.643066f, 0.668945f, 0.695312f, 0.718262f,
+ 0.740234f, 0.761230f, 0.778809f, 0.797363f, 0.812988f, 0.827148f, 0.840332f, 0.854004f, 0.865723f, 0.875977f, 0.886230f, 0.895020f,
+ 0.904297f, 0.912598f, 0.919922f, 0.926270f, 0.932617f, 0.938965f, 0.943359f, 0.949219f, 0.955078f, 0.958984f, 0.982422f, 0.983887f,
+ 0.983398f, 0.982910f, 0.982910f, 0.981934f, 0.001368f, 0.004715f, 0.008041f, 0.011948f, 0.016235f, 0.020889f, 0.025848f, 0.031921f,
+ 0.038391f, 0.045563f, 0.054108f, 0.063477f, 0.074036f, 0.085815f, 0.099304f, 0.114563f, 0.131104f, 0.150146f, 0.170654f, 0.193970f,
+ 0.219360f, 0.246338f, 0.275146f, 0.306396f, 0.338867f, 0.372559f, 0.406494f, 0.440918f, 0.474609f, 0.508789f, 0.541992f, 0.574219f,
+ 0.604492f, 0.634277f, 0.661133f, 0.687500f, 0.710938f, 0.733887f, 0.754883f, 0.774414f, 0.792480f, 0.809570f, 0.824707f, 0.838379f,
+ 0.852051f, 0.862793f, 0.874023f, 0.885254f, 0.895020f, 0.903320f, 0.912109f, 0.919434f, 0.926758f, 0.932617f, 0.939941f, 0.945312f,
+ 0.951172f, 0.955078f, 0.980957f, 0.982910f, 0.982422f, 0.982422f, 0.981445f, 0.981445f, 0.001393f, 0.004227f, 0.007011f, 0.010323f,
+ 0.014107f, 0.018234f, 0.022766f, 0.027649f, 0.032898f, 0.039581f, 0.046539f, 0.054230f, 0.063293f, 0.073608f, 0.085144f, 0.097961f,
+ 0.112305f, 0.127930f, 0.146362f, 0.166260f, 0.188599f, 0.212524f, 0.238647f, 0.266846f, 0.297363f, 0.328369f, 0.361816f, 0.395752f,
+ 0.429932f, 0.464844f, 0.498535f, 0.531250f, 0.564453f, 0.596191f, 0.625488f, 0.653320f, 0.680176f, 0.704590f, 0.728027f, 0.750977f,
+ 0.770020f, 0.788574f, 0.805176f, 0.821289f, 0.835449f, 0.849609f, 0.862793f, 0.874023f, 0.884277f, 0.894043f, 0.903320f, 0.911621f,
+ 0.919434f, 0.926758f, 0.933594f, 0.939453f, 0.945312f, 0.951172f, 0.979492f, 0.980957f, 0.980957f, 0.980957f, 0.980469f, 0.979980f,
+ 0.001163f, 0.003527f, 0.006229f, 0.009323f, 0.012199f, 0.015808f, 0.019928f, 0.024200f, 0.028870f, 0.033997f, 0.040161f, 0.046967f,
+ 0.054871f, 0.063477f, 0.073181f, 0.083618f, 0.096252f, 0.109863f, 0.125122f, 0.142334f, 0.161743f, 0.182739f, 0.206421f, 0.232300f,
+ 0.259277f, 0.288086f, 0.320068f, 0.352783f, 0.386475f, 0.420410f, 0.454590f, 0.489258f, 0.521973f, 0.555176f, 0.586914f, 0.617188f,
+ 0.646484f, 0.673828f, 0.699707f, 0.723633f, 0.746094f, 0.766113f, 0.785645f, 0.803223f, 0.819336f, 0.834961f, 0.848633f, 0.861328f,
+ 0.873535f, 0.884766f, 0.893555f, 0.903809f, 0.911621f, 0.920410f, 0.928223f, 0.934082f, 0.939941f, 0.946777f, 0.978027f, 0.979492f,
+ 0.979492f, 0.979004f, 0.979004f, 0.978516f, 0.000981f, 0.002987f, 0.005329f, 0.008186f, 0.010895f, 0.013832f, 0.017532f, 0.021149f,
+ 0.025253f, 0.029999f, 0.035034f, 0.040985f, 0.047485f, 0.054993f, 0.063049f, 0.072510f, 0.082581f, 0.094421f, 0.107727f, 0.122498f,
+ 0.138794f, 0.157471f, 0.178467f, 0.200562f, 0.225586f, 0.251953f, 0.281250f, 0.311279f, 0.343750f, 0.377197f, 0.411621f, 0.445557f,
+ 0.479736f, 0.513672f, 0.546875f, 0.579590f, 0.610352f, 0.640625f, 0.668457f, 0.694336f, 0.718750f, 0.742188f, 0.762695f, 0.782715f,
+ 0.801270f, 0.817871f, 0.833496f, 0.847168f, 0.860840f, 0.872559f, 0.884277f, 0.894531f, 0.904297f, 0.912598f, 0.920898f, 0.928711f,
+ 0.935547f, 0.942383f, 0.976074f, 0.978027f, 0.978516f, 0.978027f, 0.977539f, 0.977051f, 0.000880f, 0.002707f, 0.005089f, 0.007305f,
+ 0.010147f, 0.012596f, 0.015160f, 0.018616f, 0.022507f, 0.026230f, 0.030777f, 0.035767f, 0.041351f, 0.047455f, 0.054565f, 0.062256f,
+ 0.071289f, 0.081299f, 0.092346f, 0.105408f, 0.119812f, 0.135620f, 0.153320f, 0.173462f, 0.195068f, 0.219482f, 0.245361f, 0.273682f,
+ 0.303711f, 0.335938f, 0.368896f, 0.402588f, 0.437500f, 0.472168f, 0.505859f, 0.539551f, 0.573242f, 0.604492f, 0.634766f, 0.663086f,
+ 0.689453f, 0.714844f, 0.738770f, 0.760254f, 0.780762f, 0.799316f, 0.817383f, 0.833496f, 0.847168f, 0.860840f, 0.873535f, 0.884766f,
+ 0.895508f, 0.905273f, 0.914062f, 0.922363f, 0.930176f, 0.937012f, 0.974609f, 0.976074f, 0.976074f, 0.976562f, 0.976074f, 0.975586f,
+ 0.000851f, 0.002659f, 0.004692f, 0.006466f, 0.008545f, 0.011055f, 0.013649f, 0.016403f, 0.019714f, 0.023056f, 0.026962f, 0.031235f,
+ 0.035828f, 0.041656f, 0.047699f, 0.054077f, 0.061859f, 0.070496f, 0.080200f, 0.091125f, 0.103088f, 0.116882f, 0.132446f, 0.149780f,
+ 0.168701f, 0.190430f, 0.213379f, 0.239258f, 0.267334f, 0.296631f, 0.328369f, 0.360840f, 0.395020f, 0.429932f, 0.464355f, 0.499512f,
+ 0.533203f, 0.566406f, 0.599121f, 0.629883f, 0.658203f, 0.687012f, 0.712402f, 0.735840f, 0.758789f, 0.779297f, 0.798828f, 0.816406f,
+ 0.832520f, 0.847168f, 0.861328f, 0.874023f, 0.886230f, 0.896973f, 0.907227f, 0.915527f, 0.924805f, 0.931641f, 0.972168f, 0.975586f,
+ 0.975586f, 0.974609f, 0.974121f, 0.973633f, 0.000762f, 0.002214f, 0.004040f, 0.005859f, 0.007790f, 0.009689f, 0.012161f, 0.014786f,
+ 0.017441f, 0.020493f, 0.023956f, 0.027618f, 0.031860f, 0.036255f, 0.041595f, 0.047394f, 0.053894f, 0.061188f, 0.069214f, 0.078735f,
+ 0.089050f, 0.101135f, 0.114441f, 0.129150f, 0.145874f, 0.164673f, 0.185303f, 0.208862f, 0.233765f, 0.260742f, 0.290283f, 0.321045f,
+ 0.354248f, 0.388184f, 0.422607f, 0.457764f, 0.493652f, 0.526855f, 0.561523f, 0.594238f, 0.625977f, 0.655273f, 0.683594f, 0.710449f,
+ 0.734863f, 0.758301f, 0.779297f, 0.798828f, 0.817383f, 0.833984f, 0.848145f, 0.862793f, 0.875488f, 0.887207f, 0.899414f, 0.908691f,
+ 0.917969f, 0.926270f, 0.970215f, 0.972656f, 0.974121f, 0.973145f, 0.972656f, 0.972168f, 0.000732f, 0.001928f, 0.003513f, 0.005234f,
+ 0.007042f, 0.008629f, 0.010620f, 0.012985f, 0.015244f, 0.018158f, 0.020935f, 0.024475f, 0.027908f, 0.032013f, 0.036316f, 0.041290f,
+ 0.046661f, 0.053040f, 0.060089f, 0.068115f, 0.077087f, 0.087463f, 0.099121f, 0.111633f, 0.126221f, 0.142578f, 0.160767f, 0.181396f,
+ 0.203003f, 0.228149f, 0.255127f, 0.284180f, 0.315186f, 0.347900f, 0.381836f, 0.416748f, 0.451904f, 0.487549f, 0.522949f, 0.556641f,
+ 0.590332f, 0.623047f, 0.652832f, 0.682129f, 0.708984f, 0.733887f, 0.757324f, 0.779785f, 0.799316f, 0.818359f, 0.835449f, 0.850586f,
+ 0.865234f, 0.877441f, 0.890137f, 0.901367f, 0.912109f, 0.920410f, 0.968262f, 0.970703f, 0.971191f, 0.970703f, 0.971191f, 0.971191f,
+ 0.000524f, 0.001758f, 0.003185f, 0.004864f, 0.006081f, 0.007820f, 0.009705f, 0.011467f, 0.013634f, 0.016068f, 0.018707f, 0.021378f,
+ 0.024597f, 0.028030f, 0.032135f, 0.036224f, 0.041016f, 0.046692f, 0.052399f, 0.059265f, 0.067505f, 0.076050f, 0.085510f, 0.096558f,
+ 0.109253f, 0.123657f, 0.138794f, 0.157227f, 0.176880f, 0.198730f, 0.223267f, 0.250000f, 0.278809f, 0.309326f, 0.342041f, 0.375977f,
+ 0.410889f, 0.447021f, 0.483154f, 0.518555f, 0.554199f, 0.586914f, 0.620117f, 0.650879f, 0.681641f, 0.708496f, 0.734375f, 0.757324f,
+ 0.780762f, 0.801270f, 0.819336f, 0.837891f, 0.852539f, 0.867188f, 0.880371f, 0.893066f, 0.903809f, 0.914551f, 0.966309f, 0.968750f,
+ 0.969238f, 0.969727f, 0.968750f, 0.968750f, 0.000503f, 0.001896f, 0.002653f, 0.004128f, 0.005627f, 0.007004f, 0.008797f, 0.010361f,
+ 0.012230f, 0.014175f, 0.016647f, 0.019348f, 0.021454f, 0.024872f, 0.028290f, 0.031830f, 0.036163f, 0.040649f, 0.045715f, 0.051941f,
+ 0.058319f, 0.065979f, 0.074402f, 0.083618f, 0.094360f, 0.106812f, 0.120239f, 0.135742f, 0.153320f, 0.172974f, 0.194824f, 0.218506f,
+ 0.245117f, 0.273926f, 0.304688f, 0.336426f, 0.371094f, 0.406982f, 0.442627f, 0.479492f, 0.514648f, 0.550781f, 0.584961f, 0.618652f,
+ 0.650879f, 0.681152f, 0.709473f, 0.735352f, 0.760742f, 0.782715f, 0.803711f, 0.821777f, 0.838867f, 0.855957f, 0.870605f, 0.884277f,
+ 0.895996f, 0.906738f, 0.964355f, 0.966309f, 0.967285f, 0.966797f, 0.966309f, 0.966309f, 0.000636f, 0.001421f, 0.002768f, 0.003761f,
+ 0.004944f, 0.006462f, 0.007889f, 0.009262f, 0.010780f, 0.013000f, 0.014946f, 0.017029f, 0.019516f, 0.022049f, 0.024933f, 0.028091f,
+ 0.031616f, 0.035553f, 0.040161f, 0.045380f, 0.051239f, 0.057281f, 0.064270f, 0.072693f, 0.081970f, 0.092468f, 0.104736f, 0.117859f,
+ 0.132690f, 0.150391f, 0.169189f, 0.190796f, 0.214233f, 0.240601f, 0.268555f, 0.299561f, 0.332520f, 0.367188f, 0.402344f, 0.438965f,
+ 0.476074f, 0.512695f, 0.549805f, 0.584473f, 0.619141f, 0.651367f, 0.681152f, 0.709961f, 0.737305f, 0.762695f, 0.785156f, 0.806641f,
+ 0.826172f, 0.843262f, 0.859375f, 0.874023f, 0.888184f, 0.900391f, 0.961426f, 0.964355f, 0.965332f, 0.964844f, 0.964355f, 0.964844f,
+ 0.000295f, 0.001419f, 0.002342f, 0.003471f, 0.004539f, 0.005821f, 0.006882f, 0.008354f, 0.010155f, 0.011574f, 0.013283f, 0.015129f,
+ 0.017090f, 0.019333f, 0.022125f, 0.024643f, 0.028122f, 0.031586f, 0.035522f, 0.039825f, 0.044586f, 0.050110f, 0.056091f, 0.063354f,
+ 0.071045f, 0.080078f, 0.090637f, 0.102112f, 0.115479f, 0.130127f, 0.147217f, 0.165649f, 0.186768f, 0.210571f, 0.236694f, 0.265137f,
+ 0.295654f, 0.328857f, 0.363770f, 0.399902f, 0.436523f, 0.474365f, 0.511230f, 0.548828f, 0.584961f, 0.619141f, 0.652344f, 0.684082f,
+ 0.712891f, 0.741211f, 0.766113f, 0.789062f, 0.810547f, 0.830078f, 0.848633f, 0.864258f, 0.879395f, 0.892578f, 0.958496f, 0.962402f,
+ 0.962402f, 0.962402f, 0.961914f, 0.962402f, 0.000464f, 0.001313f, 0.002159f, 0.003134f, 0.004463f, 0.005001f, 0.006466f, 0.007595f,
+ 0.008842f, 0.010277f, 0.011971f, 0.013550f, 0.015434f, 0.017242f, 0.019348f, 0.021805f, 0.024734f, 0.027817f, 0.031174f, 0.034821f,
+ 0.039124f, 0.043823f, 0.049164f, 0.055237f, 0.062164f, 0.069336f, 0.078430f, 0.088501f, 0.099976f, 0.112854f, 0.127319f, 0.143555f,
+ 0.162354f, 0.183350f, 0.207031f, 0.233032f, 0.260986f, 0.291992f, 0.325195f, 0.361084f, 0.397217f, 0.435059f, 0.473389f, 0.510742f,
+ 0.549316f, 0.586426f, 0.620605f, 0.654785f, 0.686523f, 0.716797f, 0.744629f, 0.769043f, 0.793945f, 0.815918f, 0.834961f, 0.852539f,
+ 0.869141f, 0.884277f, 0.955078f, 0.959473f, 0.959473f, 0.959473f, 0.959961f, 0.959961f, 0.000541f, 0.001223f, 0.002172f, 0.002886f,
+ 0.003679f, 0.004681f, 0.005512f, 0.006683f, 0.008049f, 0.009346f, 0.010704f, 0.012024f, 0.013626f, 0.015213f, 0.017227f, 0.019516f,
+ 0.022079f, 0.024612f, 0.027313f, 0.030731f, 0.034180f, 0.038239f, 0.042969f, 0.048187f, 0.053864f, 0.060516f, 0.068298f, 0.076843f,
+ 0.086670f, 0.097473f, 0.110107f, 0.124268f, 0.140869f, 0.159302f, 0.180420f, 0.203613f, 0.229614f, 0.258057f, 0.289062f, 0.323486f,
+ 0.358398f, 0.395996f, 0.434082f, 0.472900f, 0.511719f, 0.550293f, 0.587402f, 0.624023f, 0.658203f, 0.690918f, 0.721191f, 0.749512f,
+ 0.774902f, 0.799316f, 0.821289f, 0.840820f, 0.859375f, 0.875488f, 0.952637f, 0.956543f, 0.957520f, 0.957520f, 0.957520f, 0.957031f,
+ 0.000252f, 0.001056f, 0.001923f, 0.002523f, 0.003414f, 0.003960f, 0.005146f, 0.006172f, 0.007130f, 0.008179f, 0.009567f, 0.010735f,
+ 0.012077f, 0.013878f, 0.015640f, 0.017456f, 0.019638f, 0.021622f, 0.024170f, 0.026978f, 0.030121f, 0.033630f, 0.037445f, 0.042053f,
+ 0.047119f, 0.052826f, 0.059174f, 0.066711f, 0.075012f, 0.084473f, 0.095276f, 0.107727f, 0.122070f, 0.138184f, 0.156250f, 0.177246f,
+ 0.200928f, 0.226929f, 0.255371f, 0.286865f, 0.321289f, 0.356934f, 0.395264f, 0.434326f, 0.473877f, 0.514160f, 0.553711f, 0.591797f,
+ 0.628418f, 0.663574f, 0.696777f, 0.728027f, 0.755859f, 0.782715f, 0.806152f, 0.829102f, 0.847656f, 0.867188f, 0.949707f, 0.954102f,
+ 0.954590f, 0.954590f, 0.954102f, 0.954590f, 0.000365f, 0.000963f, 0.001581f, 0.002337f, 0.002996f, 0.003952f, 0.004608f, 0.005459f,
+ 0.006489f, 0.007351f, 0.008484f, 0.009544f, 0.011108f, 0.012413f, 0.013901f, 0.015388f, 0.017181f, 0.019012f, 0.021439f, 0.023727f,
+ 0.026520f, 0.029449f, 0.032898f, 0.036835f, 0.041046f, 0.045868f, 0.051575f, 0.058075f, 0.064758f, 0.073120f, 0.082520f, 0.093079f,
+ 0.105652f, 0.119385f, 0.135620f, 0.153687f, 0.174683f, 0.198364f, 0.224365f, 0.253662f, 0.285400f, 0.320557f, 0.357178f, 0.395752f,
+ 0.435791f, 0.476318f, 0.516602f, 0.557129f, 0.596191f, 0.633789f, 0.669434f, 0.703613f, 0.734375f, 0.763672f, 0.790039f, 0.812988f,
+ 0.836914f, 0.855957f, 0.946289f, 0.949707f, 0.951172f, 0.951172f, 0.951172f, 0.951172f, 0.000404f, 0.001028f, 0.001410f, 0.002098f,
+ 0.002657f, 0.003445f, 0.004391f, 0.005039f, 0.005665f, 0.006569f, 0.007549f, 0.008614f, 0.009743f, 0.011108f, 0.012390f, 0.013611f,
+ 0.015396f, 0.017044f, 0.018921f, 0.020874f, 0.023453f, 0.025833f, 0.028809f, 0.032501f, 0.036011f, 0.040161f, 0.044952f, 0.050018f,
+ 0.056091f, 0.063477f, 0.071533f, 0.080200f, 0.091064f, 0.103027f, 0.117065f, 0.133057f, 0.151489f, 0.171997f, 0.196045f, 0.222290f,
+ 0.251709f, 0.284424f, 0.319824f, 0.357422f, 0.397217f, 0.438232f, 0.479492f, 0.521484f, 0.562500f, 0.602051f, 0.641113f, 0.677734f,
+ 0.711914f, 0.743164f, 0.772461f, 0.799316f, 0.822754f, 0.845215f, 0.942383f, 0.946777f, 0.947754f, 0.947754f, 0.948242f, 0.948242f,
+ 0.000406f, 0.000992f, 0.001447f, 0.001986f, 0.002499f, 0.003149f, 0.003769f, 0.004272f, 0.005016f, 0.005981f, 0.006924f, 0.007675f,
+ 0.008766f, 0.009727f, 0.010765f, 0.011986f, 0.013588f, 0.014915f, 0.016724f, 0.018478f, 0.020508f, 0.022873f, 0.025497f, 0.028336f,
+ 0.031525f, 0.034882f, 0.038818f, 0.043243f, 0.048615f, 0.054626f, 0.061707f, 0.069214f, 0.078430f, 0.089111f, 0.101013f, 0.115112f,
+ 0.130859f, 0.148926f, 0.170166f, 0.193604f, 0.220947f, 0.250732f, 0.283936f, 0.320068f, 0.358887f, 0.400391f, 0.442139f, 0.483887f,
+ 0.527344f, 0.569824f, 0.610352f, 0.649414f, 0.686523f, 0.722168f, 0.753906f, 0.782227f, 0.809570f, 0.833496f, 0.938477f, 0.942871f,
+ 0.944824f, 0.944336f, 0.943848f, 0.943848f, 0.000235f, 0.000984f, 0.001204f, 0.001706f, 0.002239f, 0.002998f, 0.003462f, 0.004093f,
+ 0.004372f, 0.005371f, 0.006149f, 0.006962f, 0.007736f, 0.008766f, 0.009804f, 0.010780f, 0.011887f, 0.013336f, 0.014618f, 0.016159f,
+ 0.018158f, 0.020050f, 0.022232f, 0.024597f, 0.027313f, 0.030334f, 0.033752f, 0.037872f, 0.042389f, 0.047516f, 0.053192f, 0.059937f,
+ 0.067749f, 0.076599f, 0.086975f, 0.098755f, 0.112610f, 0.128662f, 0.146973f, 0.168091f, 0.192383f, 0.220215f, 0.250732f, 0.284668f,
+ 0.322021f, 0.361572f, 0.403564f, 0.446777f, 0.490723f, 0.534668f, 0.577637f, 0.619629f, 0.660156f, 0.697754f, 0.731934f, 0.764648f,
+ 0.794922f, 0.820312f, 0.934082f, 0.939453f, 0.939941f, 0.941406f, 0.940430f, 0.940918f, 0.000237f, 0.000591f, 0.001098f, 0.001619f,
+ 0.002241f, 0.002636f, 0.003176f, 0.003521f, 0.004101f, 0.004631f, 0.005398f, 0.006378f, 0.007000f, 0.007767f, 0.008713f, 0.009758f,
+ 0.010475f, 0.011734f, 0.013016f, 0.014404f, 0.015762f, 0.017517f, 0.019440f, 0.021469f, 0.023651f, 0.026199f, 0.029495f, 0.033112f,
+ 0.036499f, 0.040955f, 0.045959f, 0.051849f, 0.058197f, 0.065552f, 0.074585f, 0.085022f, 0.096680f, 0.110535f, 0.126709f, 0.145264f,
+ 0.166626f, 0.191406f, 0.219482f, 0.250488f, 0.286133f, 0.323975f, 0.365723f, 0.408447f, 0.453125f, 0.498779f, 0.542969f, 0.588379f,
+ 0.631836f, 0.671387f, 0.709473f, 0.745117f, 0.777344f, 0.807617f, 0.930176f, 0.935059f, 0.936523f, 0.936523f, 0.936523f, 0.936035f,
+ 0.000242f, 0.000761f, 0.000943f, 0.001624f, 0.001858f, 0.002390f, 0.002638f, 0.003054f, 0.003805f, 0.004559f, 0.005035f, 0.005493f,
+ 0.006157f, 0.006878f, 0.007687f, 0.008530f, 0.009178f, 0.010406f, 0.011406f, 0.012520f, 0.014053f, 0.015579f, 0.017105f, 0.018661f,
+ 0.020737f, 0.022903f, 0.025650f, 0.028259f, 0.031433f, 0.035065f, 0.039581f, 0.044342f, 0.049988f, 0.056366f, 0.064026f, 0.072632f,
+ 0.082825f, 0.094666f, 0.108582f, 0.124634f, 0.143799f, 0.165405f, 0.190796f, 0.219360f, 0.251953f, 0.287842f, 0.328125f, 0.370605f,
+ 0.415283f, 0.461670f, 0.507812f, 0.555176f, 0.600586f, 0.645020f, 0.685547f, 0.724121f, 0.759277f, 0.792969f, 0.924805f, 0.931152f,
+ 0.931641f, 0.932129f, 0.932129f, 0.931641f, 0.000240f, 0.000685f, 0.000955f, 0.001395f, 0.001768f, 0.002157f, 0.002533f, 0.002970f,
+ 0.003223f, 0.003813f, 0.004601f, 0.004993f, 0.005428f, 0.005981f, 0.006878f, 0.007484f, 0.008110f, 0.009132f, 0.009964f, 0.011208f,
+ 0.012138f, 0.013374f, 0.015099f, 0.016190f, 0.018112f, 0.020187f, 0.022202f, 0.024780f, 0.027573f, 0.030411f, 0.034119f, 0.037964f,
+ 0.042755f, 0.048553f, 0.054474f, 0.061890f, 0.070984f, 0.080688f, 0.092590f, 0.106812f, 0.123291f, 0.142456f, 0.164551f, 0.190430f,
+ 0.220459f, 0.253418f, 0.291504f, 0.332520f, 0.376709f, 0.423340f, 0.471436f, 0.520508f, 0.567383f, 0.614746f, 0.660156f, 0.702148f,
+ 0.741211f, 0.776367f, 0.920410f, 0.925293f, 0.926270f, 0.926758f, 0.927246f, 0.926758f, 0.000244f, 0.000431f, 0.000799f, 0.001309f,
+ 0.001587f, 0.001945f, 0.002317f, 0.002514f, 0.003290f, 0.003548f, 0.004082f, 0.004349f, 0.004707f, 0.005348f, 0.006027f, 0.006565f,
+ 0.007141f, 0.008011f, 0.008850f, 0.009552f, 0.010757f, 0.011650f, 0.012794f, 0.014145f, 0.015778f, 0.017303f, 0.019028f, 0.021088f,
+ 0.023575f, 0.026169f, 0.029175f, 0.032562f, 0.036713f, 0.041382f, 0.046448f, 0.052948f, 0.060303f, 0.068787f, 0.079041f, 0.090942f,
+ 0.105103f, 0.121643f, 0.141113f, 0.164185f, 0.190308f, 0.221191f, 0.256836f, 0.295898f, 0.339355f, 0.385010f, 0.433838f, 0.484619f,
+ 0.534668f, 0.583496f, 0.631348f, 0.678223f, 0.719727f, 0.759766f, 0.913574f, 0.920410f, 0.921387f, 0.921875f, 0.921875f, 0.921387f,
+ 0.000243f, 0.000496f, 0.000847f, 0.001157f, 0.001426f, 0.001634f, 0.002020f, 0.002338f, 0.002607f, 0.003035f, 0.003502f, 0.003872f,
+ 0.004459f, 0.004726f, 0.005402f, 0.005779f, 0.006325f, 0.007095f, 0.007767f, 0.008568f, 0.009331f, 0.010086f, 0.011009f, 0.012314f,
+ 0.013611f, 0.015060f, 0.016312f, 0.018158f, 0.020401f, 0.022476f, 0.024979f, 0.027863f, 0.031036f, 0.034943f, 0.039581f, 0.044830f,
+ 0.050903f, 0.058289f, 0.066895f, 0.076782f, 0.088989f, 0.103210f, 0.120422f, 0.140259f, 0.164185f, 0.191772f, 0.223877f, 0.260742f,
+ 0.301758f, 0.347168f, 0.395508f, 0.446533f, 0.497803f, 0.551270f, 0.601562f, 0.651855f, 0.697754f, 0.741211f, 0.908203f, 0.915039f,
+ 0.916016f, 0.916016f, 0.916504f, 0.915527f, 0.000239f, 0.000345f, 0.000690f, 0.000913f, 0.001250f, 0.001343f, 0.001579f, 0.002050f,
+ 0.002331f, 0.002861f, 0.003048f, 0.003616f, 0.003696f, 0.004211f, 0.004723f, 0.005074f, 0.005657f, 0.006100f, 0.006893f, 0.007290f,
+ 0.008118f, 0.008659f, 0.009552f, 0.010704f, 0.011681f, 0.012764f, 0.014114f, 0.015533f, 0.017227f, 0.018982f, 0.021286f, 0.023560f,
+ 0.026489f, 0.029861f, 0.033417f, 0.037933f, 0.043121f, 0.049286f, 0.056519f, 0.065002f, 0.075073f, 0.087158f, 0.101624f, 0.118835f,
+ 0.139648f, 0.164185f, 0.193481f, 0.226929f, 0.265625f, 0.309570f, 0.356934f, 0.408203f, 0.461426f, 0.516113f, 0.569824f, 0.623047f,
+ 0.674316f, 0.720703f, 0.902344f, 0.908203f, 0.909668f, 0.910645f, 0.910645f, 0.911133f, 0.000000f, 0.000281f, 0.000560f, 0.000977f,
+ 0.001063f, 0.001171f, 0.001569f, 0.001903f, 0.002075f, 0.002413f, 0.002695f, 0.003004f, 0.003399f, 0.003553f, 0.003998f, 0.004333f,
+ 0.004971f, 0.005314f, 0.005806f, 0.006340f, 0.007015f, 0.007492f, 0.008377f, 0.009186f, 0.010094f, 0.010910f, 0.012199f, 0.013351f,
+ 0.014618f, 0.016266f, 0.018082f, 0.019852f, 0.022491f, 0.025085f, 0.028168f, 0.031799f, 0.036041f, 0.041107f, 0.047394f, 0.054321f,
+ 0.062866f, 0.073181f, 0.085327f, 0.100525f, 0.118408f, 0.139648f, 0.165527f, 0.196411f, 0.231812f, 0.273193f, 0.318848f, 0.369629f,
+ 0.423828f, 0.480225f, 0.536621f, 0.592773f, 0.647949f, 0.699707f, 0.894043f, 0.900879f, 0.903809f, 0.903320f, 0.903320f, 0.902832f,
+ 0.000232f, 0.000227f, 0.000555f, 0.000656f, 0.000937f, 0.000985f, 0.001351f, 0.001723f, 0.001925f, 0.002010f, 0.002445f, 0.002625f,
+ 0.002760f, 0.003220f, 0.003551f, 0.003870f, 0.004303f, 0.004826f, 0.005028f, 0.005451f, 0.005985f, 0.006523f, 0.007000f, 0.007744f,
+ 0.008499f, 0.009361f, 0.010109f, 0.011185f, 0.012413f, 0.013603f, 0.015121f, 0.016891f, 0.018753f, 0.020920f, 0.023407f, 0.026764f,
+ 0.030197f, 0.034302f, 0.039429f, 0.044891f, 0.052368f, 0.060822f, 0.071167f, 0.083557f, 0.098877f, 0.117493f, 0.139893f, 0.167725f,
+ 0.200195f, 0.238037f, 0.281982f, 0.331543f, 0.385010f, 0.442627f, 0.501465f, 0.561523f, 0.620605f, 0.675781f, 0.887207f, 0.894531f,
+ 0.895020f, 0.896484f, 0.896484f, 0.895996f, 0.000000f, 0.000332f, 0.000577f, 0.000723f, 0.000720f, 0.001210f, 0.001469f, 0.001456f,
+ 0.001546f, 0.001775f, 0.002159f, 0.002291f, 0.002659f, 0.002916f, 0.003046f, 0.003439f, 0.003752f, 0.003883f, 0.004375f, 0.004635f,
+ 0.005241f, 0.005638f, 0.006054f, 0.006630f, 0.007191f, 0.007744f, 0.008545f, 0.009178f, 0.010498f, 0.011536f, 0.012802f, 0.013931f,
+ 0.015808f, 0.017548f, 0.019379f, 0.022110f, 0.025040f, 0.028473f, 0.032471f, 0.037323f, 0.043152f, 0.050476f, 0.058807f, 0.069214f,
+ 0.082520f, 0.098145f, 0.116821f, 0.141602f, 0.170044f, 0.204834f, 0.245728f, 0.293213f, 0.346436f, 0.403564f, 0.464111f, 0.527832f,
+ 0.589844f, 0.650879f, 0.878418f, 0.886719f, 0.888184f, 0.887695f, 0.888672f, 0.888672f, 0.000243f, 0.000307f, 0.000526f, 0.000561f,
+ 0.000923f, 0.000980f, 0.001143f, 0.001386f, 0.001414f, 0.001683f, 0.001735f, 0.001972f, 0.002232f, 0.002481f, 0.002657f, 0.002754f,
+ 0.003193f, 0.003359f, 0.003603f, 0.003956f, 0.004368f, 0.004692f, 0.005119f, 0.005596f, 0.005955f, 0.006634f, 0.007256f, 0.007881f,
+ 0.008652f, 0.009552f, 0.010376f, 0.011719f, 0.012634f, 0.014595f, 0.016113f, 0.018219f, 0.020554f, 0.023254f, 0.026520f, 0.030502f,
+ 0.035553f, 0.041168f, 0.048065f, 0.057190f, 0.067261f, 0.080811f, 0.097107f, 0.117737f, 0.143066f, 0.173950f, 0.211182f, 0.256592f,
+ 0.307129f, 0.364502f, 0.427002f, 0.491943f, 0.557617f, 0.624023f, 0.869629f, 0.877930f, 0.879883f, 0.879883f, 0.879883f, 0.880371f,
+ 0.000000f, 0.000270f, 0.000342f, 0.000509f, 0.000668f, 0.000989f, 0.000945f, 0.001105f, 0.001230f, 0.001335f, 0.001492f, 0.001757f,
+ 0.001917f, 0.002140f, 0.002386f, 0.002501f, 0.002644f, 0.002884f, 0.003199f, 0.003441f, 0.003620f, 0.003891f, 0.004337f, 0.004631f,
+ 0.005119f, 0.005520f, 0.006100f, 0.006504f, 0.007301f, 0.007771f, 0.008751f, 0.009521f, 0.010658f, 0.011765f, 0.013145f, 0.014641f,
+ 0.016785f, 0.018829f, 0.021545f, 0.024719f, 0.028381f, 0.033203f, 0.038849f, 0.046112f, 0.055084f, 0.065552f, 0.079529f, 0.096985f,
+ 0.118530f, 0.145630f, 0.179321f, 0.220337f, 0.269287f, 0.325439f, 0.387207f, 0.454102f, 0.524414f, 0.595215f, 0.859863f, 0.868652f,
+ 0.870605f, 0.869629f, 0.870117f, 0.870605f, 0.000000f, 0.000230f, 0.000334f, 0.000416f, 0.000700f, 0.000726f, 0.000921f, 0.001008f,
+ 0.001065f, 0.001186f, 0.001365f, 0.001471f, 0.001627f, 0.001796f, 0.001843f, 0.002069f, 0.002266f, 0.002438f, 0.002596f, 0.002831f,
+ 0.003000f, 0.003298f, 0.003597f, 0.003887f, 0.004265f, 0.004581f, 0.004986f, 0.005505f, 0.005947f, 0.006454f, 0.007069f, 0.007801f,
+ 0.008621f, 0.009575f, 0.010612f, 0.011848f, 0.013321f, 0.015259f, 0.017410f, 0.019775f, 0.022934f, 0.026550f, 0.031464f, 0.036713f,
+ 0.043945f, 0.052887f, 0.064209f, 0.078735f, 0.096924f, 0.120361f, 0.149536f, 0.186768f, 0.232422f, 0.285889f, 0.347656f, 0.415527f,
+ 0.488281f, 0.563965f, 0.849121f, 0.857910f, 0.859375f, 0.860840f, 0.860840f, 0.860352f, 0.000233f, 0.000225f, 0.000219f, 0.000431f,
+ 0.000579f, 0.000648f, 0.000671f, 0.000744f, 0.000946f, 0.000994f, 0.001091f, 0.001307f, 0.001364f, 0.001490f, 0.001561f, 0.001712f,
+ 0.001892f, 0.001999f, 0.002190f, 0.002369f, 0.002512f, 0.002733f, 0.003014f, 0.003145f, 0.003553f, 0.003822f, 0.004135f, 0.004326f,
+ 0.004799f, 0.005344f, 0.005718f, 0.006378f, 0.007008f, 0.007721f, 0.008400f, 0.009537f, 0.010597f, 0.011917f, 0.013542f, 0.015579f,
+ 0.018051f, 0.020889f, 0.024765f, 0.029236f, 0.034668f, 0.041779f, 0.051056f, 0.062439f, 0.077576f, 0.097595f, 0.122864f, 0.155273f,
+ 0.196655f, 0.247437f, 0.307617f, 0.375977f, 0.450684f, 0.531250f, 0.837891f, 0.847168f, 0.848633f, 0.849609f, 0.849121f, 0.849609f,
+ 0.000202f, 0.000180f, 0.000206f, 0.000339f, 0.000479f, 0.000536f, 0.000687f, 0.000739f, 0.000771f, 0.000849f, 0.001051f, 0.001060f,
+ 0.001154f, 0.001219f, 0.001389f, 0.001505f, 0.001469f, 0.001729f, 0.001858f, 0.001980f, 0.002209f, 0.002243f, 0.002483f, 0.002695f,
+ 0.002951f, 0.003149f, 0.003374f, 0.003654f, 0.004002f, 0.004154f, 0.004539f, 0.005032f, 0.005428f, 0.005989f, 0.006760f, 0.007549f,
+ 0.008423f, 0.009499f, 0.010620f, 0.012016f, 0.013992f, 0.016434f, 0.019135f, 0.022583f, 0.026840f, 0.032501f, 0.039551f, 0.048828f,
+ 0.061066f, 0.077393f, 0.098755f, 0.127075f, 0.163208f, 0.209717f, 0.267578f, 0.334961f, 0.411133f, 0.494629f, 0.825684f, 0.834473f,
+ 0.836426f, 0.837402f, 0.837402f, 0.837402f, 0.000000f, 0.000185f, 0.000184f, 0.000404f, 0.000408f, 0.000454f, 0.000480f, 0.000506f,
+ 0.000660f, 0.000694f, 0.000742f, 0.000801f, 0.000989f, 0.001111f, 0.001167f, 0.001250f, 0.001311f, 0.001424f, 0.001541f, 0.001574f,
+ 0.001712f, 0.001930f, 0.001982f, 0.002201f, 0.002375f, 0.002439f, 0.002792f, 0.002905f, 0.003065f, 0.003412f, 0.003653f, 0.003952f,
+ 0.004463f, 0.004723f, 0.005230f, 0.005936f, 0.006386f, 0.007092f, 0.008240f, 0.009247f, 0.010765f, 0.012344f, 0.014420f, 0.017090f,
+ 0.020493f, 0.024551f, 0.030014f, 0.037689f, 0.047302f, 0.060028f, 0.077820f, 0.100830f, 0.132812f, 0.174561f, 0.228516f, 0.294434f,
+ 0.371582f, 0.457031f, 0.812012f, 0.820801f, 0.823730f, 0.824219f, 0.824707f, 0.824219f, 0.000000f, 0.000053f, 0.000206f, 0.000360f,
+ 0.000379f, 0.000391f, 0.000379f, 0.000478f, 0.000549f, 0.000589f, 0.000626f, 0.000674f, 0.000762f, 0.000832f, 0.000894f, 0.001050f,
+ 0.001111f, 0.001155f, 0.001286f, 0.001345f, 0.001449f, 0.001564f, 0.001666f, 0.001750f, 0.001856f, 0.001925f, 0.002056f, 0.002359f,
+ 0.002542f, 0.002728f, 0.003042f, 0.003164f, 0.003460f, 0.003786f, 0.004116f, 0.004578f, 0.005116f, 0.005688f, 0.006508f, 0.007229f,
+ 0.008125f, 0.009232f, 0.010796f, 0.012741f, 0.015137f, 0.018158f, 0.022186f, 0.028030f, 0.035248f, 0.045593f, 0.059052f, 0.078308f,
+ 0.105042f, 0.141602f, 0.190308f, 0.252930f, 0.329102f, 0.417969f, 0.797852f, 0.807129f, 0.810059f, 0.810547f, 0.811035f, 0.810547f,
+ 0.000000f, 0.000000f, 0.000082f, 0.000195f, 0.000309f, 0.000336f, 0.000324f, 0.000414f, 0.000439f, 0.000460f, 0.000599f, 0.000643f,
+ 0.000637f, 0.000690f, 0.000733f, 0.000834f, 0.000821f, 0.000922f, 0.000989f, 0.001067f, 0.001207f, 0.001293f, 0.001327f, 0.001476f,
+ 0.001581f, 0.001663f, 0.001725f, 0.001906f, 0.001934f, 0.002180f, 0.002258f, 0.002602f, 0.002701f, 0.003019f, 0.003229f, 0.003502f,
+ 0.003847f, 0.004261f, 0.004795f, 0.005318f, 0.006130f, 0.007008f, 0.008118f, 0.009277f, 0.011024f, 0.013229f, 0.016205f, 0.020203f,
+ 0.025620f, 0.033020f, 0.043854f, 0.059021f, 0.080383f, 0.111206f, 0.154419f, 0.212646f, 0.287354f, 0.378418f, 0.781250f, 0.792480f,
+ 0.793457f, 0.795410f, 0.795898f, 0.794922f, 0.000000f, 0.000121f, 0.000120f, 0.000198f, 0.000275f, 0.000249f, 0.000290f, 0.000360f,
+ 0.000375f, 0.000379f, 0.000391f, 0.000438f, 0.000505f, 0.000534f, 0.000669f, 0.000629f, 0.000659f, 0.000754f, 0.000890f, 0.000833f,
+ 0.000849f, 0.000975f, 0.001029f, 0.001117f, 0.001193f, 0.001203f, 0.001269f, 0.001424f, 0.001594f, 0.001675f, 0.001737f, 0.001957f,
+ 0.002094f, 0.002319f, 0.002342f, 0.002609f, 0.002928f, 0.003248f, 0.003523f, 0.003967f, 0.004547f, 0.005138f, 0.005871f, 0.006760f,
+ 0.007912f, 0.009430f, 0.011528f, 0.014236f, 0.017899f, 0.023346f, 0.031235f, 0.042694f, 0.059235f, 0.084229f, 0.120972f, 0.173950f,
+ 0.245239f, 0.334473f, 0.764160f, 0.775391f, 0.777344f, 0.778809f, 0.777832f, 0.778809f, 0.000000f, 0.000121f, 0.000119f, 0.000182f,
+ 0.000177f, 0.000179f, 0.000262f, 0.000239f, 0.000309f, 0.000322f, 0.000404f, 0.000370f, 0.000361f, 0.000430f, 0.000458f, 0.000540f,
+ 0.000589f, 0.000615f, 0.000648f, 0.000632f, 0.000777f, 0.000782f, 0.000798f, 0.000871f, 0.000857f, 0.000925f, 0.001000f, 0.001045f,
+ 0.001191f, 0.001223f, 0.001426f, 0.001419f, 0.001512f, 0.001635f, 0.001884f, 0.002092f, 0.002100f, 0.002293f, 0.002577f, 0.003012f,
+ 0.003258f, 0.003761f, 0.004253f, 0.004814f, 0.005619f, 0.006676f, 0.008064f, 0.009750f, 0.012268f, 0.015854f, 0.021255f, 0.029282f,
+ 0.041687f, 0.061005f, 0.091370f, 0.136230f, 0.202759f, 0.291504f, 0.746582f, 0.757324f, 0.759277f, 0.760254f, 0.760254f, 0.760254f,
+ 0.000000f, 0.000000f, 0.000117f, 0.000126f, 0.000113f, 0.000146f, 0.000158f, 0.000155f, 0.000189f, 0.000288f, 0.000254f, 0.000336f,
+ 0.000347f, 0.000353f, 0.000370f, 0.000355f, 0.000390f, 0.000417f, 0.000456f, 0.000480f, 0.000525f, 0.000587f, 0.000596f, 0.000620f,
+ 0.000676f, 0.000740f, 0.000758f, 0.000852f, 0.000907f, 0.000947f, 0.001057f, 0.001122f, 0.001170f, 0.001293f, 0.001316f, 0.001437f,
+ 0.001531f, 0.001813f, 0.001952f, 0.002090f, 0.002346f, 0.002560f, 0.002974f, 0.003334f, 0.003899f, 0.004547f, 0.005360f, 0.006516f,
+ 0.008179f, 0.010468f, 0.013947f, 0.019241f, 0.027832f, 0.041443f, 0.064941f, 0.102600f, 0.162231f, 0.247437f, 0.726074f, 0.737793f,
+ 0.739258f, 0.740723f, 0.741211f, 0.741211f, 0.000000f, 0.000118f, 0.000115f, 0.000113f, 0.000110f, 0.000126f, 0.000121f, 0.000139f,
+ 0.000147f, 0.000160f, 0.000161f, 0.000233f, 0.000199f, 0.000266f, 0.000286f, 0.000297f, 0.000329f, 0.000313f, 0.000347f, 0.000358f,
+ 0.000364f, 0.000394f, 0.000435f, 0.000446f, 0.000489f, 0.000506f, 0.000546f, 0.000625f, 0.000648f, 0.000674f, 0.000723f, 0.000782f,
+ 0.000865f, 0.000918f, 0.000979f, 0.001104f, 0.001100f, 0.001196f, 0.001352f, 0.001488f, 0.001586f, 0.001749f, 0.001955f, 0.002275f,
+ 0.002644f, 0.003054f, 0.003563f, 0.004322f, 0.005314f, 0.006786f, 0.008980f, 0.012115f, 0.017319f, 0.026520f, 0.043121f, 0.072693f,
+ 0.123535f, 0.203613f, 0.705566f, 0.716797f, 0.719238f, 0.719727f, 0.720703f, 0.721191f, 0.000000f, 0.000000f, 0.000112f, 0.000109f,
+ 0.000106f, 0.000104f, 0.000102f, 0.000096f, 0.000091f, 0.000113f, 0.000147f, 0.000129f, 0.000155f, 0.000134f, 0.000196f, 0.000205f,
+ 0.000181f, 0.000239f, 0.000297f, 0.000255f, 0.000317f, 0.000273f, 0.000335f, 0.000299f, 0.000379f, 0.000385f, 0.000398f, 0.000402f,
+ 0.000473f, 0.000552f, 0.000489f, 0.000543f, 0.000557f, 0.000606f, 0.000662f, 0.000698f, 0.000747f, 0.000810f, 0.000902f, 0.000961f,
+ 0.001063f, 0.001166f, 0.001312f, 0.001523f, 0.001662f, 0.001908f, 0.002298f, 0.002758f, 0.003365f, 0.004135f, 0.005394f, 0.007290f,
+ 0.010490f, 0.015991f, 0.026215f, 0.047180f, 0.087646f, 0.160645f, 0.682617f, 0.695801f, 0.697266f, 0.697266f, 0.697266f, 0.698730f,
+ 0.000000f, 0.000112f, 0.000106f, 0.000104f, 0.000100f, 0.000098f, 0.000095f, 0.000094f, 0.000090f, 0.000085f, 0.000080f, 0.000081f,
+ 0.000085f, 0.000123f, 0.000123f, 0.000138f, 0.000151f, 0.000158f, 0.000147f, 0.000171f, 0.000183f, 0.000192f, 0.000242f, 0.000215f,
+ 0.000253f, 0.000256f, 0.000269f, 0.000278f, 0.000293f, 0.000315f, 0.000377f, 0.000357f, 0.000357f, 0.000423f, 0.000479f, 0.000493f,
+ 0.000489f, 0.000535f, 0.000579f, 0.000628f, 0.000683f, 0.000731f, 0.000833f, 0.000935f, 0.001068f, 0.001200f, 0.001347f, 0.001581f,
+ 0.001995f, 0.002419f, 0.003109f, 0.004147f, 0.005829f, 0.008919f, 0.014641f, 0.027405f, 0.056885f, 0.119385f, 0.658691f, 0.669922f,
+ 0.673828f, 0.673828f, 0.675293f, 0.675293f, 0.000000f, 0.000105f, 0.000101f, 0.000096f, 0.000092f, 0.000089f, 0.000087f, 0.000085f,
+ 0.000083f, 0.000081f, 0.000077f, 0.000073f, 0.000070f, 0.000066f, 0.000080f, 0.000084f, 0.000089f, 0.000068f, 0.000101f, 0.000094f,
+ 0.000116f, 0.000118f, 0.000125f, 0.000129f, 0.000150f, 0.000168f, 0.000153f, 0.000192f, 0.000195f, 0.000185f, 0.000200f, 0.000217f,
+ 0.000226f, 0.000247f, 0.000257f, 0.000262f, 0.000319f, 0.000334f, 0.000347f, 0.000376f, 0.000395f, 0.000447f, 0.000504f, 0.000544f,
+ 0.000590f, 0.000670f, 0.000789f, 0.000887f, 0.001069f, 0.001345f, 0.001670f, 0.002167f, 0.003065f, 0.004562f, 0.007660f, 0.014290f,
+ 0.032135f, 0.081299f, 0.632812f, 0.645996f, 0.648926f, 0.649414f, 0.648926f, 0.649902f, 0.000109f, 0.000094f, 0.000087f, 0.000082f,
+ 0.000078f, 0.000076f, 0.000074f, 0.000071f, 0.000069f, 0.000068f, 0.000067f, 0.000066f, 0.000064f, 0.000061f, 0.000058f, 0.000055f,
+ 0.000053f, 0.000050f, 0.000051f, 0.000046f, 0.000059f, 0.000056f, 0.000057f, 0.000068f, 0.000078f, 0.000088f, 0.000096f, 0.000096f,
+ 0.000105f, 0.000107f, 0.000128f, 0.000121f, 0.000133f, 0.000141f, 0.000156f, 0.000151f, 0.000160f, 0.000200f, 0.000209f, 0.000198f,
+ 0.000222f, 0.000242f, 0.000258f, 0.000275f, 0.000314f, 0.000352f, 0.000410f, 0.000468f, 0.000537f, 0.000639f, 0.000799f, 0.001002f,
+ 0.001390f, 0.002092f, 0.003466f, 0.006653f, 0.015305f, 0.048004f, 0.606934f, 0.618652f, 0.622559f, 0.623047f, 0.623535f, 0.624023f,
+ 0.000084f, 0.000067f, 0.000064f, 0.000062f, 0.000057f, 0.000056f, 0.000053f, 0.000054f, 0.000051f, 0.000052f, 0.000050f, 0.000050f,
+ 0.000050f, 0.000049f, 0.000048f, 0.000047f, 0.000046f, 0.000044f, 0.000042f, 0.000040f, 0.000039f, 0.000037f, 0.000035f, 0.000036f,
+ 0.000037f, 0.000031f, 0.000040f, 0.000041f, 0.000042f, 0.000051f, 0.000058f, 0.000063f, 0.000067f, 0.000069f, 0.000072f, 0.000079f,
+ 0.000085f, 0.000092f, 0.000093f, 0.000101f, 0.000107f, 0.000123f, 0.000125f, 0.000139f, 0.000147f, 0.000154f, 0.000181f, 0.000204f,
+ 0.000229f, 0.000270f, 0.000327f, 0.000425f, 0.000559f, 0.000772f, 0.001265f, 0.002462f, 0.006191f, 0.022415f, 0.578613f, 0.592285f,
+ 0.595215f, 0.596191f, 0.596191f, 0.597656f, 0.000008f, 0.000022f, 0.000022f, 0.000024f, 0.000024f, 0.000027f, 0.000028f, 0.000028f,
+ 0.000028f, 0.000026f, 0.000028f, 0.000029f, 0.000029f, 0.000028f, 0.000029f, 0.000029f, 0.000029f, 0.000029f, 0.000030f, 0.000030f,
+ 0.000030f, 0.000029f, 0.000028f, 0.000027f, 0.000026f, 0.000025f, 0.000024f, 0.000023f, 0.000022f, 0.000021f, 0.000020f, 0.000019f,
+ 0.000021f, 0.000020f, 0.000022f, 0.000026f, 0.000028f, 0.000033f, 0.000037f, 0.000036f, 0.000039f, 0.000045f, 0.000051f, 0.000046f,
+ 0.000056f, 0.000059f, 0.000061f, 0.000071f, 0.000084f, 0.000098f, 0.000110f, 0.000133f, 0.000169f, 0.000223f, 0.000356f, 0.000648f,
+ 0.001702f, 0.007713f, 0.550293f, 0.564453f, 0.566895f, 0.567871f, 0.568359f, 0.568848f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000002f, 0.000003f, 0.000004f, 0.000006f,
+ 0.000007f, 0.000007f, 0.000008f, 0.000008f, 0.000009f, 0.000010f, 0.000011f, 0.000011f, 0.000012f, 0.000012f, 0.000013f, 0.000013f,
+ 0.000013f, 0.000014f, 0.000014f, 0.000013f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f,
+ 0.000008f, 0.000008f, 0.000009f, 0.000011f, 0.000014f, 0.000017f, 0.000015f, 0.000018f, 0.000021f, 0.000022f, 0.000023f, 0.000026f,
+ 0.000035f, 0.000040f, 0.000056f, 0.000089f, 0.000225f, 0.001332f, 0.520996f, 0.535156f, 0.538086f, 0.540039f, 0.540039f, 0.540039f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000003f, 0.000003f,
+ 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000017f, 0.491211f, 0.506348f,
+ 0.508789f, 0.510254f, 0.510254f, 0.510742f,
+ },
+ {
+ 0.064758f, 0.179688f, 0.277344f, 0.358398f, 0.427002f, 0.485107f, 0.535156f, 0.578613f, 0.615234f, 0.647949f, 0.677734f, 0.703125f,
+ 0.725586f, 0.745605f, 0.763672f, 0.780273f, 0.795410f, 0.810059f, 0.821777f, 0.833496f, 0.843750f, 0.854004f, 0.862793f, 0.871582f,
+ 0.879883f, 0.886719f, 0.894043f, 0.900879f, 0.906250f, 0.912109f, 0.917969f, 0.922852f, 0.927246f, 0.932129f, 0.936523f, 0.940918f,
+ 0.944824f, 0.948242f, 0.951660f, 0.955078f, 0.958496f, 0.961426f, 0.964844f, 0.967773f, 0.970215f, 0.973145f, 0.975586f, 0.977539f,
+ 0.979980f, 0.982422f, 0.984863f, 0.986328f, 0.988770f, 0.990234f, 0.992676f, 0.993652f, 0.995605f, 0.997559f, 0.998535f, 0.996582f,
+ 0.995117f, 0.993652f, 0.992188f, 0.990723f, 0.040344f, 0.121460f, 0.199341f, 0.272949f, 0.339600f, 0.401123f, 0.455078f, 0.501953f,
+ 0.546875f, 0.583984f, 0.618164f, 0.648926f, 0.676270f, 0.700195f, 0.723145f, 0.743164f, 0.761230f, 0.776855f, 0.793457f, 0.806641f,
+ 0.819336f, 0.831543f, 0.842285f, 0.852051f, 0.861328f, 0.869629f, 0.877930f, 0.886230f, 0.892578f, 0.899902f, 0.905273f, 0.911621f,
+ 0.917480f, 0.922852f, 0.927246f, 0.932129f, 0.936035f, 0.940430f, 0.945312f, 0.949219f, 0.952148f, 0.956055f, 0.958984f, 0.961914f,
+ 0.965332f, 0.967773f, 0.970703f, 0.973633f, 0.976074f, 0.978516f, 0.980957f, 0.983398f, 0.985840f, 0.987305f, 0.989258f, 0.991699f,
+ 0.993652f, 0.995117f, 0.997070f, 0.995605f, 0.994141f, 0.993164f, 0.991699f, 0.990234f, 0.027191f, 0.084961f, 0.145630f, 0.206177f,
+ 0.266113f, 0.323242f, 0.377930f, 0.428711f, 0.474609f, 0.517090f, 0.554688f, 0.591309f, 0.621582f, 0.650391f, 0.676758f, 0.700684f,
+ 0.723145f, 0.741699f, 0.760254f, 0.776855f, 0.791504f, 0.805664f, 0.818359f, 0.830566f, 0.841309f, 0.851074f, 0.861816f, 0.870117f,
+ 0.878418f, 0.885254f, 0.892090f, 0.899414f, 0.906250f, 0.912598f, 0.916992f, 0.922363f, 0.928223f, 0.932617f, 0.937500f, 0.941895f,
+ 0.945801f, 0.949219f, 0.953613f, 0.957031f, 0.960449f, 0.963379f, 0.966797f, 0.969727f, 0.971680f, 0.974609f, 0.977539f, 0.979980f,
+ 0.981934f, 0.984375f, 0.986328f, 0.989258f, 0.991211f, 0.992676f, 0.996094f, 0.994629f, 0.993652f, 0.992188f, 0.990723f, 0.989746f,
+ 0.019577f, 0.061340f, 0.108337f, 0.156860f, 0.207153f, 0.258789f, 0.310059f, 0.358887f, 0.405762f, 0.450928f, 0.491211f, 0.530273f,
+ 0.565430f, 0.597656f, 0.627441f, 0.654297f, 0.680176f, 0.702637f, 0.724121f, 0.743164f, 0.760742f, 0.776855f, 0.791992f, 0.806152f,
+ 0.817871f, 0.830078f, 0.841797f, 0.852539f, 0.861816f, 0.870117f, 0.878906f, 0.886230f, 0.893066f, 0.900391f, 0.906738f, 0.912598f,
+ 0.918457f, 0.923340f, 0.928223f, 0.933594f, 0.938477f, 0.942871f, 0.946777f, 0.950684f, 0.954590f, 0.958496f, 0.960938f, 0.964844f,
+ 0.967773f, 0.970703f, 0.973633f, 0.976074f, 0.979004f, 0.981445f, 0.983398f, 0.985840f, 0.987793f, 0.990234f, 0.995117f, 0.993652f,
+ 0.992676f, 0.991699f, 0.990234f, 0.989258f, 0.014397f, 0.046295f, 0.081543f, 0.120728f, 0.162842f, 0.206177f, 0.250977f, 0.296143f,
+ 0.342041f, 0.385986f, 0.427979f, 0.468262f, 0.506348f, 0.542480f, 0.575195f, 0.605469f, 0.633789f, 0.660156f, 0.684570f, 0.706543f,
+ 0.727539f, 0.745117f, 0.763184f, 0.778809f, 0.793945f, 0.807617f, 0.820312f, 0.833008f, 0.842773f, 0.852539f, 0.862305f, 0.872070f,
+ 0.879395f, 0.887207f, 0.894531f, 0.900879f, 0.907227f, 0.914551f, 0.919922f, 0.925293f, 0.930176f, 0.935547f, 0.938965f, 0.943359f,
+ 0.948730f, 0.952637f, 0.956055f, 0.959473f, 0.962891f, 0.966309f, 0.969238f, 0.972656f, 0.975098f, 0.977539f, 0.980957f, 0.982910f,
+ 0.984863f, 0.987793f, 0.994141f, 0.993164f, 0.991699f, 0.990723f, 0.989746f, 0.988281f, 0.010925f, 0.035828f, 0.063660f, 0.094360f,
+ 0.128174f, 0.164551f, 0.203247f, 0.244385f, 0.285645f, 0.326416f, 0.367432f, 0.409424f, 0.447998f, 0.484131f, 0.520508f, 0.553711f,
+ 0.584473f, 0.614258f, 0.641113f, 0.666016f, 0.689453f, 0.710938f, 0.730469f, 0.750488f, 0.766602f, 0.781250f, 0.796387f, 0.809570f,
+ 0.822266f, 0.833496f, 0.844727f, 0.854980f, 0.864258f, 0.873047f, 0.881348f, 0.889648f, 0.895996f, 0.903809f, 0.910156f, 0.916504f,
+ 0.921387f, 0.926758f, 0.932129f, 0.937500f, 0.941895f, 0.946777f, 0.950684f, 0.954102f, 0.958008f, 0.960938f, 0.965332f, 0.968262f,
+ 0.971680f, 0.975098f, 0.977539f, 0.979492f, 0.982422f, 0.984863f, 0.992676f, 0.991699f, 0.990723f, 0.989746f, 0.988770f, 0.987793f,
+ 0.008698f, 0.028244f, 0.049866f, 0.074463f, 0.102295f, 0.132935f, 0.165161f, 0.200073f, 0.236206f, 0.275391f, 0.313477f, 0.352051f,
+ 0.391113f, 0.428955f, 0.465088f, 0.500977f, 0.534180f, 0.565430f, 0.593750f, 0.622559f, 0.648438f, 0.671875f, 0.694824f, 0.715820f,
+ 0.734863f, 0.753906f, 0.771484f, 0.784668f, 0.799805f, 0.813477f, 0.825195f, 0.836914f, 0.847656f, 0.857910f, 0.866699f, 0.875488f,
+ 0.884766f, 0.892090f, 0.898438f, 0.906250f, 0.913086f, 0.918457f, 0.923828f, 0.929688f, 0.935059f, 0.939941f, 0.944336f, 0.948730f,
+ 0.952637f, 0.956055f, 0.959961f, 0.963379f, 0.967285f, 0.970703f, 0.973633f, 0.976074f, 0.979492f, 0.982422f, 0.991211f, 0.990723f,
+ 0.990234f, 0.988770f, 0.987793f, 0.986328f, 0.007210f, 0.022797f, 0.040039f, 0.060181f, 0.082153f, 0.107300f, 0.134155f, 0.164673f,
+ 0.196167f, 0.229492f, 0.265381f, 0.301025f, 0.338379f, 0.374756f, 0.411133f, 0.446533f, 0.481201f, 0.515625f, 0.546387f, 0.576660f,
+ 0.605957f, 0.631348f, 0.656738f, 0.681152f, 0.702148f, 0.722168f, 0.741699f, 0.758789f, 0.775391f, 0.791016f, 0.803711f, 0.817383f,
+ 0.829102f, 0.840820f, 0.851562f, 0.860840f, 0.871094f, 0.879395f, 0.887695f, 0.895020f, 0.901855f, 0.909180f, 0.915527f, 0.921387f,
+ 0.927734f, 0.932129f, 0.937500f, 0.941895f, 0.947266f, 0.950684f, 0.955078f, 0.958984f, 0.962891f, 0.966797f, 0.969727f, 0.973145f,
+ 0.976562f, 0.979004f, 0.990234f, 0.989746f, 0.988770f, 0.987793f, 0.986816f, 0.985840f, 0.005863f, 0.018936f, 0.032898f, 0.049377f,
+ 0.067261f, 0.088257f, 0.110535f, 0.135254f, 0.162231f, 0.191895f, 0.223389f, 0.255371f, 0.290039f, 0.324707f, 0.359863f, 0.395996f,
+ 0.429932f, 0.464355f, 0.497314f, 0.529297f, 0.559570f, 0.587891f, 0.616699f, 0.642090f, 0.665527f, 0.688965f, 0.709961f, 0.729492f,
+ 0.747559f, 0.765625f, 0.780762f, 0.794922f, 0.809082f, 0.822754f, 0.833984f, 0.844727f, 0.855957f, 0.864746f, 0.875000f, 0.883789f,
+ 0.891113f, 0.898926f, 0.906250f, 0.912598f, 0.918457f, 0.925293f, 0.930664f, 0.935059f, 0.940918f, 0.945312f, 0.950195f, 0.954590f,
+ 0.958496f, 0.962402f, 0.965820f, 0.969238f, 0.972656f, 0.976074f, 0.988770f, 0.988770f, 0.987793f, 0.986816f, 0.985840f, 0.984863f,
+ 0.004925f, 0.015518f, 0.027451f, 0.041199f, 0.055786f, 0.072998f, 0.091492f, 0.112427f, 0.135254f, 0.160767f, 0.187500f, 0.216919f,
+ 0.247314f, 0.280273f, 0.313477f, 0.346680f, 0.381592f, 0.415283f, 0.448730f, 0.481201f, 0.513184f, 0.543945f, 0.573242f, 0.601562f,
+ 0.627441f, 0.652344f, 0.675293f, 0.697754f, 0.718262f, 0.737793f, 0.754883f, 0.771973f, 0.787109f, 0.800781f, 0.815430f, 0.828125f,
+ 0.839844f, 0.851074f, 0.860840f, 0.870117f, 0.879883f, 0.887695f, 0.896484f, 0.902832f, 0.911133f, 0.916992f, 0.922852f, 0.928711f,
+ 0.934082f, 0.939941f, 0.944336f, 0.948730f, 0.954102f, 0.958008f, 0.961426f, 0.965332f, 0.969238f, 0.972168f, 0.987305f, 0.987305f,
+ 0.986816f, 0.985840f, 0.984863f, 0.983887f, 0.004139f, 0.012955f, 0.022781f, 0.034088f, 0.046997f, 0.061005f, 0.076538f, 0.094360f,
+ 0.113464f, 0.134888f, 0.158203f, 0.183716f, 0.210693f, 0.239990f, 0.270264f, 0.302734f, 0.334961f, 0.367676f, 0.400635f, 0.434082f,
+ 0.467041f, 0.497803f, 0.528809f, 0.558105f, 0.586426f, 0.614258f, 0.638672f, 0.663574f, 0.686035f, 0.707520f, 0.728027f, 0.745605f,
+ 0.762695f, 0.779297f, 0.794434f, 0.808594f, 0.821777f, 0.834473f, 0.845215f, 0.855957f, 0.866699f, 0.876465f, 0.884766f, 0.892090f,
+ 0.900391f, 0.908203f, 0.915039f, 0.920898f, 0.927246f, 0.932617f, 0.937988f, 0.943848f, 0.948730f, 0.952637f, 0.957520f, 0.961426f,
+ 0.965820f, 0.968750f, 0.985840f, 0.985840f, 0.985840f, 0.984375f, 0.983887f, 0.982910f, 0.003492f, 0.011307f, 0.019608f, 0.028793f,
+ 0.039246f, 0.051544f, 0.064392f, 0.078796f, 0.095337f, 0.113953f, 0.134033f, 0.155396f, 0.179688f, 0.205200f, 0.232300f, 0.261475f,
+ 0.291748f, 0.323730f, 0.355225f, 0.387939f, 0.420410f, 0.452637f, 0.483887f, 0.514648f, 0.544922f, 0.573730f, 0.601074f, 0.626953f,
+ 0.651367f, 0.675293f, 0.697266f, 0.717285f, 0.736816f, 0.755371f, 0.771973f, 0.786621f, 0.803223f, 0.815430f, 0.828613f, 0.840820f,
+ 0.851562f, 0.863281f, 0.873047f, 0.880859f, 0.890625f, 0.898438f, 0.905762f, 0.913086f, 0.919434f, 0.925781f, 0.931641f, 0.937500f,
+ 0.942871f, 0.947754f, 0.952637f, 0.957520f, 0.960938f, 0.965820f, 0.984375f, 0.984863f, 0.984375f, 0.983398f, 0.982422f, 0.981445f,
+ 0.002977f, 0.009415f, 0.016708f, 0.024811f, 0.033356f, 0.043457f, 0.054535f, 0.067017f, 0.080322f, 0.096130f, 0.113708f, 0.132080f,
+ 0.152710f, 0.175415f, 0.199829f, 0.226440f, 0.253662f, 0.282959f, 0.313232f, 0.343750f, 0.375000f, 0.406982f, 0.439453f, 0.471191f,
+ 0.501465f, 0.531738f, 0.560547f, 0.587891f, 0.615234f, 0.640625f, 0.664062f, 0.687500f, 0.708496f, 0.728516f, 0.747559f, 0.765137f,
+ 0.781738f, 0.795898f, 0.811523f, 0.824707f, 0.836426f, 0.847656f, 0.858887f, 0.869141f, 0.878906f, 0.887695f, 0.895996f, 0.904297f,
+ 0.911133f, 0.917969f, 0.925293f, 0.931152f, 0.937012f, 0.942383f, 0.947266f, 0.953125f, 0.957031f, 0.961426f, 0.982910f, 0.983398f,
+ 0.982910f, 0.982422f, 0.981445f, 0.980957f, 0.002743f, 0.008568f, 0.014305f, 0.021378f, 0.028732f, 0.037201f, 0.046387f, 0.057068f,
+ 0.068848f, 0.082336f, 0.096924f, 0.113159f, 0.130859f, 0.150146f, 0.171509f, 0.194824f, 0.219482f, 0.246338f, 0.273926f, 0.302734f,
+ 0.333496f, 0.364502f, 0.395752f, 0.426758f, 0.458252f, 0.489990f, 0.519531f, 0.548340f, 0.576660f, 0.604004f, 0.630859f, 0.654297f,
+ 0.678223f, 0.700684f, 0.720215f, 0.740234f, 0.758301f, 0.775391f, 0.790527f, 0.805176f, 0.818848f, 0.833008f, 0.844238f, 0.855469f,
+ 0.866699f, 0.876953f, 0.886230f, 0.894043f, 0.902832f, 0.910645f, 0.917480f, 0.924316f, 0.930664f, 0.937012f, 0.941895f, 0.947266f,
+ 0.952148f, 0.957031f, 0.981445f, 0.982422f, 0.981445f, 0.980957f, 0.980469f, 0.979004f, 0.002504f, 0.007004f, 0.012634f, 0.018555f,
+ 0.024933f, 0.032654f, 0.040283f, 0.048920f, 0.059357f, 0.070007f, 0.082642f, 0.096741f, 0.112122f, 0.128906f, 0.147339f, 0.167603f,
+ 0.189697f, 0.213257f, 0.238770f, 0.265869f, 0.293701f, 0.323242f, 0.354004f, 0.384766f, 0.415283f, 0.447021f, 0.478516f, 0.507812f,
+ 0.536621f, 0.565918f, 0.593750f, 0.620605f, 0.645508f, 0.668945f, 0.692383f, 0.712891f, 0.733398f, 0.751465f, 0.769531f, 0.785156f,
+ 0.801270f, 0.814941f, 0.828125f, 0.841797f, 0.853516f, 0.864746f, 0.874512f, 0.883789f, 0.893555f, 0.900879f, 0.910156f, 0.917480f,
+ 0.923340f, 0.930664f, 0.936523f, 0.942383f, 0.947754f, 0.952637f, 0.979492f, 0.980469f, 0.980469f, 0.979492f, 0.978516f, 0.978027f,
+ 0.002039f, 0.006287f, 0.010864f, 0.016129f, 0.021637f, 0.027786f, 0.034485f, 0.042450f, 0.051331f, 0.060760f, 0.071594f, 0.082886f,
+ 0.096313f, 0.110840f, 0.126587f, 0.145020f, 0.164185f, 0.185181f, 0.207520f, 0.232300f, 0.258301f, 0.285889f, 0.314941f, 0.344238f,
+ 0.374268f, 0.405029f, 0.436035f, 0.466797f, 0.498291f, 0.527344f, 0.555664f, 0.583984f, 0.611328f, 0.636230f, 0.661133f, 0.684082f,
+ 0.705566f, 0.726562f, 0.745605f, 0.764648f, 0.781250f, 0.797852f, 0.812500f, 0.825195f, 0.838867f, 0.851074f, 0.862305f, 0.873535f,
+ 0.883301f, 0.892578f, 0.901367f, 0.908203f, 0.916992f, 0.923828f, 0.931152f, 0.937012f, 0.942383f, 0.947266f, 0.978027f, 0.978516f,
+ 0.979004f, 0.978027f, 0.977051f, 0.977051f, 0.001762f, 0.005489f, 0.009804f, 0.013931f, 0.019028f, 0.024445f, 0.030518f, 0.036865f,
+ 0.044189f, 0.052460f, 0.061432f, 0.071960f, 0.083008f, 0.095642f, 0.109558f, 0.124756f, 0.141602f, 0.160156f, 0.180664f, 0.202148f,
+ 0.225952f, 0.250977f, 0.278076f, 0.305664f, 0.334961f, 0.364990f, 0.394775f, 0.425537f, 0.456543f, 0.487061f, 0.517090f, 0.546387f,
+ 0.575195f, 0.602539f, 0.627930f, 0.653809f, 0.676758f, 0.699707f, 0.721191f, 0.740723f, 0.759766f, 0.777832f, 0.793945f, 0.809082f,
+ 0.823242f, 0.836426f, 0.849609f, 0.861328f, 0.872070f, 0.881836f, 0.892578f, 0.900391f, 0.908691f, 0.916992f, 0.924316f, 0.931152f,
+ 0.937500f, 0.943359f, 0.976074f, 0.977051f, 0.977051f, 0.976562f, 0.976074f, 0.975098f, 0.001675f, 0.005020f, 0.008400f, 0.012253f,
+ 0.016724f, 0.021469f, 0.026428f, 0.032104f, 0.039062f, 0.045563f, 0.053741f, 0.062103f, 0.072205f, 0.082947f, 0.094666f, 0.107727f,
+ 0.122681f, 0.139038f, 0.156250f, 0.176514f, 0.197388f, 0.220581f, 0.244629f, 0.270752f, 0.297607f, 0.326172f, 0.355957f, 0.386475f,
+ 0.416748f, 0.447754f, 0.478027f, 0.507812f, 0.538086f, 0.566406f, 0.594727f, 0.621582f, 0.647461f, 0.671387f, 0.694336f, 0.716797f,
+ 0.737305f, 0.755859f, 0.773438f, 0.791016f, 0.807129f, 0.820801f, 0.834961f, 0.848145f, 0.860352f, 0.871582f, 0.881836f, 0.891602f,
+ 0.901367f, 0.909180f, 0.917480f, 0.925293f, 0.932129f, 0.938965f, 0.974609f, 0.975586f, 0.976074f, 0.974609f, 0.974121f, 0.973633f,
+ 0.001437f, 0.004513f, 0.007427f, 0.010994f, 0.014526f, 0.018829f, 0.023331f, 0.028229f, 0.034058f, 0.040192f, 0.046844f, 0.054321f,
+ 0.062683f, 0.071716f, 0.082397f, 0.093933f, 0.106567f, 0.120728f, 0.136230f, 0.153320f, 0.172485f, 0.192627f, 0.214233f, 0.237915f,
+ 0.263672f, 0.290527f, 0.318115f, 0.347412f, 0.377197f, 0.408203f, 0.438477f, 0.469482f, 0.499512f, 0.529785f, 0.558594f, 0.586914f,
+ 0.614258f, 0.641602f, 0.665527f, 0.689941f, 0.711914f, 0.732422f, 0.752930f, 0.771484f, 0.789062f, 0.805664f, 0.819824f, 0.833984f,
+ 0.847656f, 0.860840f, 0.871094f, 0.881836f, 0.891602f, 0.902344f, 0.910156f, 0.918457f, 0.926270f, 0.932617f, 0.972168f, 0.973633f,
+ 0.973633f, 0.973145f, 0.973145f, 0.971680f, 0.001390f, 0.003952f, 0.006779f, 0.009941f, 0.013062f, 0.017029f, 0.020905f, 0.024994f,
+ 0.029877f, 0.035187f, 0.041077f, 0.047119f, 0.055145f, 0.062500f, 0.071594f, 0.081543f, 0.092712f, 0.104736f, 0.118530f, 0.133179f,
+ 0.150024f, 0.168091f, 0.187378f, 0.209717f, 0.232178f, 0.256836f, 0.283447f, 0.311279f, 0.339844f, 0.369873f, 0.399658f, 0.429932f,
+ 0.461426f, 0.492188f, 0.521973f, 0.551758f, 0.580566f, 0.608887f, 0.635254f, 0.660645f, 0.685059f, 0.708008f, 0.729492f, 0.750488f,
+ 0.769043f, 0.786621f, 0.802734f, 0.818848f, 0.832520f, 0.846680f, 0.860352f, 0.871582f, 0.882324f, 0.892578f, 0.902832f, 0.911133f,
+ 0.919922f, 0.926758f, 0.970703f, 0.971680f, 0.971680f, 0.971680f, 0.971680f, 0.969238f, 0.001328f, 0.003641f, 0.006138f, 0.008690f,
+ 0.011444f, 0.014786f, 0.018311f, 0.022125f, 0.026337f, 0.031403f, 0.036011f, 0.041809f, 0.047943f, 0.054901f, 0.062622f, 0.071106f,
+ 0.081299f, 0.091614f, 0.103455f, 0.116333f, 0.130493f, 0.146484f, 0.164307f, 0.183228f, 0.204224f, 0.226685f, 0.251221f, 0.277100f,
+ 0.303711f, 0.332764f, 0.361572f, 0.391846f, 0.422852f, 0.454102f, 0.485352f, 0.515625f, 0.545410f, 0.574707f, 0.603027f, 0.630371f,
+ 0.656250f, 0.681641f, 0.705078f, 0.726562f, 0.747070f, 0.767578f, 0.784668f, 0.803223f, 0.818848f, 0.833008f, 0.847656f, 0.860352f,
+ 0.872559f, 0.883301f, 0.894043f, 0.903809f, 0.913574f, 0.921387f, 0.967773f, 0.970215f, 0.970215f, 0.968750f, 0.969238f, 0.968750f,
+ 0.001053f, 0.002905f, 0.005432f, 0.007912f, 0.010658f, 0.012901f, 0.016464f, 0.019363f, 0.023376f, 0.027237f, 0.031799f, 0.036346f,
+ 0.042145f, 0.048248f, 0.054871f, 0.062256f, 0.070618f, 0.079834f, 0.089844f, 0.101440f, 0.113831f, 0.128174f, 0.143433f, 0.160156f,
+ 0.179077f, 0.199707f, 0.222046f, 0.245483f, 0.271240f, 0.297363f, 0.325684f, 0.355469f, 0.385254f, 0.416016f, 0.447754f, 0.479004f,
+ 0.508789f, 0.539551f, 0.570312f, 0.598145f, 0.626465f, 0.652344f, 0.678223f, 0.702148f, 0.725098f, 0.746094f, 0.765625f, 0.785645f,
+ 0.803223f, 0.819336f, 0.834961f, 0.848145f, 0.861328f, 0.873535f, 0.884766f, 0.895508f, 0.905762f, 0.915527f, 0.965332f, 0.967773f,
+ 0.968262f, 0.967773f, 0.967285f, 0.966309f, 0.001106f, 0.002684f, 0.004913f, 0.006733f, 0.009300f, 0.011955f, 0.014435f, 0.017700f,
+ 0.020477f, 0.024124f, 0.028091f, 0.032532f, 0.037231f, 0.042511f, 0.048309f, 0.054596f, 0.061798f, 0.069885f, 0.078857f, 0.089050f,
+ 0.099915f, 0.112183f, 0.125488f, 0.140503f, 0.157104f, 0.175293f, 0.195068f, 0.216309f, 0.240356f, 0.265381f, 0.291748f, 0.319580f,
+ 0.348633f, 0.379150f, 0.410156f, 0.441406f, 0.472900f, 0.503418f, 0.534668f, 0.565430f, 0.594727f, 0.622070f, 0.649902f, 0.676270f,
+ 0.700195f, 0.723633f, 0.746094f, 0.766602f, 0.786133f, 0.802734f, 0.819824f, 0.835449f, 0.849609f, 0.863281f, 0.875977f, 0.887695f,
+ 0.898438f, 0.908203f, 0.962891f, 0.965820f, 0.966309f, 0.965332f, 0.964844f, 0.964355f, 0.000782f, 0.002707f, 0.004574f, 0.006184f,
+ 0.008286f, 0.010681f, 0.012878f, 0.015640f, 0.018478f, 0.021912f, 0.025208f, 0.028976f, 0.032867f, 0.037598f, 0.042938f, 0.048370f,
+ 0.054443f, 0.061432f, 0.069214f, 0.077515f, 0.087402f, 0.098145f, 0.109497f, 0.122803f, 0.137329f, 0.153564f, 0.171509f, 0.190918f,
+ 0.212158f, 0.235352f, 0.259766f, 0.286133f, 0.314209f, 0.343262f, 0.373535f, 0.404297f, 0.436279f, 0.467773f, 0.499512f, 0.530273f,
+ 0.561523f, 0.590820f, 0.620117f, 0.647461f, 0.674316f, 0.699219f, 0.722656f, 0.745605f, 0.766602f, 0.785645f, 0.804688f, 0.821777f,
+ 0.836426f, 0.852051f, 0.865234f, 0.878418f, 0.890625f, 0.901855f, 0.959961f, 0.962891f, 0.963867f, 0.963379f, 0.962402f, 0.962402f,
+ 0.000787f, 0.002195f, 0.004250f, 0.005775f, 0.007774f, 0.009445f, 0.011795f, 0.013725f, 0.016678f, 0.019531f, 0.022018f, 0.025665f,
+ 0.029495f, 0.033142f, 0.037598f, 0.042664f, 0.048248f, 0.053772f, 0.060699f, 0.067993f, 0.076416f, 0.085815f, 0.095764f, 0.107422f,
+ 0.120239f, 0.134277f, 0.150269f, 0.167358f, 0.186646f, 0.207764f, 0.230347f, 0.255127f, 0.281250f, 0.308838f, 0.337891f, 0.368408f,
+ 0.399414f, 0.431396f, 0.463135f, 0.495605f, 0.526855f, 0.558594f, 0.588379f, 0.618652f, 0.646973f, 0.673828f, 0.699707f, 0.723633f,
+ 0.746094f, 0.767090f, 0.788086f, 0.806641f, 0.823730f, 0.840332f, 0.854980f, 0.869141f, 0.881836f, 0.893555f, 0.957520f, 0.960938f,
+ 0.960938f, 0.961426f, 0.960449f, 0.959961f, 0.000765f, 0.002207f, 0.003666f, 0.005177f, 0.006973f, 0.008301f, 0.010704f, 0.012794f,
+ 0.015015f, 0.017303f, 0.020309f, 0.022568f, 0.026123f, 0.029587f, 0.033325f, 0.037659f, 0.042206f, 0.047516f, 0.053223f, 0.059814f,
+ 0.067017f, 0.075195f, 0.083801f, 0.094055f, 0.105042f, 0.117737f, 0.131470f, 0.146851f, 0.163940f, 0.182739f, 0.203369f, 0.225952f,
+ 0.250244f, 0.276367f, 0.304199f, 0.333008f, 0.364258f, 0.395264f, 0.427002f, 0.459961f, 0.491699f, 0.524414f, 0.555664f, 0.586914f,
+ 0.617676f, 0.645996f, 0.673340f, 0.699707f, 0.724121f, 0.748047f, 0.770020f, 0.790039f, 0.809082f, 0.827148f, 0.842773f, 0.858398f,
+ 0.873047f, 0.885742f, 0.954102f, 0.958008f, 0.958496f, 0.958496f, 0.958496f, 0.957520f, 0.000586f, 0.001937f, 0.003107f, 0.004745f,
+ 0.006168f, 0.007610f, 0.009590f, 0.011345f, 0.013321f, 0.015587f, 0.017593f, 0.020294f, 0.023346f, 0.026154f, 0.029205f, 0.033234f,
+ 0.037415f, 0.041962f, 0.046906f, 0.052673f, 0.058533f, 0.065796f, 0.073669f, 0.082642f, 0.092346f, 0.103027f, 0.115234f, 0.128784f,
+ 0.143799f, 0.160889f, 0.179199f, 0.199585f, 0.221802f, 0.246094f, 0.271973f, 0.299805f, 0.329102f, 0.359863f, 0.391357f, 0.423340f,
+ 0.456299f, 0.490234f, 0.522949f, 0.555176f, 0.586426f, 0.617188f, 0.645996f, 0.675293f, 0.701660f, 0.726074f, 0.750488f, 0.773926f,
+ 0.793945f, 0.812988f, 0.831543f, 0.847656f, 0.862793f, 0.877441f, 0.951660f, 0.955078f, 0.955566f, 0.955566f, 0.955078f, 0.954590f,
+ 0.000678f, 0.001864f, 0.003138f, 0.004333f, 0.005707f, 0.006893f, 0.008224f, 0.009850f, 0.012215f, 0.013954f, 0.015747f, 0.018219f,
+ 0.020584f, 0.023148f, 0.026047f, 0.029434f, 0.033020f, 0.037018f, 0.041626f, 0.046509f, 0.051910f, 0.058105f, 0.064636f, 0.072510f,
+ 0.080750f, 0.090149f, 0.100891f, 0.112549f, 0.126343f, 0.141113f, 0.157593f, 0.175537f, 0.195801f, 0.218018f, 0.242554f, 0.268311f,
+ 0.295898f, 0.325195f, 0.355713f, 0.388184f, 0.421143f, 0.454834f, 0.488281f, 0.522949f, 0.554199f, 0.587402f, 0.618164f, 0.648438f,
+ 0.676758f, 0.704102f, 0.730957f, 0.754395f, 0.776855f, 0.798340f, 0.817871f, 0.836426f, 0.852051f, 0.868164f, 0.948242f, 0.952637f,
+ 0.953125f, 0.952637f, 0.952148f, 0.951660f, 0.000470f, 0.001578f, 0.002934f, 0.003838f, 0.005032f, 0.006310f, 0.007725f, 0.008972f,
+ 0.010826f, 0.012657f, 0.014359f, 0.015991f, 0.018402f, 0.020721f, 0.023102f, 0.026230f, 0.029495f, 0.032867f, 0.036743f, 0.040680f,
+ 0.045654f, 0.050812f, 0.056763f, 0.063477f, 0.071045f, 0.078918f, 0.088440f, 0.098938f, 0.110657f, 0.123535f, 0.138062f, 0.154175f,
+ 0.172363f, 0.192627f, 0.214478f, 0.238770f, 0.264404f, 0.292236f, 0.322266f, 0.353271f, 0.385742f, 0.419189f, 0.453857f, 0.487549f,
+ 0.521484f, 0.555664f, 0.588867f, 0.621094f, 0.651367f, 0.680176f, 0.708008f, 0.733887f, 0.759766f, 0.780762f, 0.802734f, 0.821289f,
+ 0.840820f, 0.858398f, 0.943848f, 0.949219f, 0.949707f, 0.949707f, 0.949707f, 0.949219f, 0.000485f, 0.001689f, 0.002386f, 0.003698f,
+ 0.004547f, 0.005936f, 0.006851f, 0.008217f, 0.009834f, 0.011055f, 0.012810f, 0.014473f, 0.016449f, 0.018509f, 0.020950f, 0.023209f,
+ 0.025940f, 0.029114f, 0.032410f, 0.036133f, 0.040161f, 0.044861f, 0.050018f, 0.055664f, 0.061859f, 0.069153f, 0.077515f, 0.086365f,
+ 0.096680f, 0.108093f, 0.120605f, 0.135132f, 0.151489f, 0.169556f, 0.189209f, 0.211426f, 0.235352f, 0.261475f, 0.289307f, 0.319580f,
+ 0.351074f, 0.384521f, 0.418701f, 0.452881f, 0.487549f, 0.522461f, 0.556641f, 0.591309f, 0.623535f, 0.653809f, 0.684570f, 0.712891f,
+ 0.739258f, 0.764160f, 0.787109f, 0.809570f, 0.829102f, 0.847168f, 0.940918f, 0.945801f, 0.946289f, 0.946777f, 0.946777f, 0.945312f,
+ 0.000620f, 0.001351f, 0.002413f, 0.003273f, 0.004307f, 0.004971f, 0.006138f, 0.007542f, 0.008835f, 0.009972f, 0.011581f, 0.013069f,
+ 0.014717f, 0.016495f, 0.018738f, 0.020691f, 0.023315f, 0.025879f, 0.028793f, 0.031860f, 0.035309f, 0.039246f, 0.043762f, 0.048950f,
+ 0.054474f, 0.060669f, 0.067932f, 0.075378f, 0.084351f, 0.094055f, 0.105774f, 0.118469f, 0.132690f, 0.148315f, 0.166504f, 0.186401f,
+ 0.208130f, 0.232544f, 0.258789f, 0.287109f, 0.317627f, 0.349854f, 0.383057f, 0.417725f, 0.453125f, 0.488770f, 0.523926f, 0.559082f,
+ 0.594238f, 0.627441f, 0.659180f, 0.689941f, 0.719238f, 0.745117f, 0.770508f, 0.794434f, 0.815430f, 0.836914f, 0.936523f, 0.941895f,
+ 0.942871f, 0.942871f, 0.942871f, 0.942383f, 0.000404f, 0.001095f, 0.002087f, 0.002983f, 0.003986f, 0.004673f, 0.005844f, 0.006878f,
+ 0.007740f, 0.008873f, 0.010323f, 0.011757f, 0.013176f, 0.014915f, 0.016586f, 0.018585f, 0.020523f, 0.022720f, 0.025391f, 0.028244f,
+ 0.031219f, 0.034821f, 0.038788f, 0.042908f, 0.047943f, 0.053040f, 0.058960f, 0.066162f, 0.073547f, 0.082397f, 0.092285f, 0.102844f,
+ 0.115234f, 0.129883f, 0.146118f, 0.163452f, 0.183350f, 0.205688f, 0.229614f, 0.256592f, 0.285156f, 0.316162f, 0.348633f, 0.383057f,
+ 0.418457f, 0.454590f, 0.490967f, 0.526855f, 0.563477f, 0.598633f, 0.632812f, 0.665527f, 0.696777f, 0.726074f, 0.752930f, 0.779297f,
+ 0.803223f, 0.825684f, 0.933105f, 0.938477f, 0.938477f, 0.938965f, 0.938477f, 0.938477f, 0.000415f, 0.000864f, 0.001907f, 0.002775f,
+ 0.003519f, 0.004204f, 0.005352f, 0.006237f, 0.007019f, 0.008064f, 0.009239f, 0.010483f, 0.011742f, 0.013130f, 0.014877f, 0.016571f,
+ 0.018494f, 0.020126f, 0.022537f, 0.024826f, 0.027649f, 0.030701f, 0.033875f, 0.037964f, 0.042114f, 0.046356f, 0.051605f, 0.057587f,
+ 0.064209f, 0.071777f, 0.080261f, 0.089722f, 0.100952f, 0.113220f, 0.127075f, 0.143066f, 0.160767f, 0.180664f, 0.202759f, 0.227417f,
+ 0.254395f, 0.284180f, 0.315674f, 0.348633f, 0.383789f, 0.420166f, 0.457275f, 0.494385f, 0.531250f, 0.569336f, 0.605469f, 0.639160f,
+ 0.672363f, 0.705078f, 0.735352f, 0.762207f, 0.788574f, 0.811523f, 0.928711f, 0.934082f, 0.934570f, 0.935059f, 0.935059f, 0.935059f,
+ 0.000236f, 0.001136f, 0.001664f, 0.002502f, 0.003187f, 0.004082f, 0.004631f, 0.005386f, 0.006275f, 0.007385f, 0.008217f, 0.009453f,
+ 0.010567f, 0.011787f, 0.013115f, 0.014420f, 0.016083f, 0.017944f, 0.019867f, 0.022079f, 0.024414f, 0.026962f, 0.029755f, 0.033112f,
+ 0.036926f, 0.040771f, 0.045258f, 0.050232f, 0.056183f, 0.062500f, 0.069946f, 0.078430f, 0.087708f, 0.098389f, 0.110779f, 0.124634f,
+ 0.140259f, 0.158203f, 0.178223f, 0.200928f, 0.225708f, 0.253174f, 0.282715f, 0.315430f, 0.349365f, 0.385254f, 0.422363f, 0.460938f,
+ 0.499023f, 0.537109f, 0.574707f, 0.612305f, 0.646484f, 0.682129f, 0.713867f, 0.745117f, 0.772461f, 0.799316f, 0.923828f, 0.930176f,
+ 0.930664f, 0.931152f, 0.930664f, 0.930664f, 0.000229f, 0.000964f, 0.001582f, 0.002182f, 0.002838f, 0.003653f, 0.004341f, 0.004921f,
+ 0.005615f, 0.006626f, 0.007423f, 0.008545f, 0.009483f, 0.010666f, 0.011612f, 0.013000f, 0.014275f, 0.015900f, 0.017487f, 0.019333f,
+ 0.021484f, 0.023773f, 0.026276f, 0.028992f, 0.032135f, 0.035492f, 0.039398f, 0.044037f, 0.049072f, 0.054443f, 0.061035f, 0.067871f,
+ 0.076111f, 0.085632f, 0.096252f, 0.108154f, 0.122253f, 0.138306f, 0.156006f, 0.175903f, 0.199219f, 0.224243f, 0.251953f, 0.282715f,
+ 0.315918f, 0.350830f, 0.387451f, 0.425781f, 0.465332f, 0.504395f, 0.544434f, 0.583008f, 0.620117f, 0.657715f, 0.692383f, 0.725098f,
+ 0.755371f, 0.783691f, 0.919434f, 0.925781f, 0.926270f, 0.926758f, 0.926758f, 0.925781f, 0.000410f, 0.000856f, 0.001542f, 0.001844f,
+ 0.002565f, 0.003380f, 0.003971f, 0.004246f, 0.005047f, 0.005863f, 0.006653f, 0.007744f, 0.008568f, 0.009407f, 0.010529f, 0.011482f,
+ 0.012657f, 0.013924f, 0.015602f, 0.017105f, 0.018997f, 0.020859f, 0.022980f, 0.025192f, 0.028030f, 0.031036f, 0.034515f, 0.038300f,
+ 0.042236f, 0.047180f, 0.052795f, 0.059113f, 0.065857f, 0.074097f, 0.083374f, 0.094360f, 0.105896f, 0.119873f, 0.135620f, 0.154175f,
+ 0.174072f, 0.197632f, 0.223267f, 0.251465f, 0.283447f, 0.317139f, 0.353760f, 0.391113f, 0.431152f, 0.470703f, 0.512207f, 0.552734f,
+ 0.592285f, 0.631348f, 0.669434f, 0.704590f, 0.737793f, 0.768555f, 0.913574f, 0.919922f, 0.920898f, 0.920898f, 0.921387f, 0.921387f,
+ 0.000214f, 0.000619f, 0.001172f, 0.001941f, 0.002228f, 0.002960f, 0.003490f, 0.003994f, 0.004761f, 0.005180f, 0.005806f, 0.006622f,
+ 0.007565f, 0.008301f, 0.009262f, 0.010170f, 0.011208f, 0.012482f, 0.013855f, 0.015060f, 0.016739f, 0.018311f, 0.020248f, 0.022034f,
+ 0.024597f, 0.027084f, 0.030045f, 0.033051f, 0.036743f, 0.041016f, 0.045807f, 0.050964f, 0.056946f, 0.063904f, 0.071899f, 0.080994f,
+ 0.091675f, 0.103699f, 0.117920f, 0.133667f, 0.151978f, 0.172729f, 0.196533f, 0.222534f, 0.252197f, 0.284424f, 0.319580f, 0.356689f,
+ 0.396973f, 0.437500f, 0.479492f, 0.521484f, 0.562500f, 0.604004f, 0.644043f, 0.682129f, 0.718262f, 0.751465f, 0.907715f, 0.915039f,
+ 0.916016f, 0.916504f, 0.916504f, 0.916504f, 0.000405f, 0.000760f, 0.001116f, 0.001688f, 0.002180f, 0.002670f, 0.003313f, 0.003569f,
+ 0.003979f, 0.004543f, 0.005466f, 0.005985f, 0.006699f, 0.007359f, 0.008102f, 0.009094f, 0.009949f, 0.011055f, 0.012047f, 0.013412f,
+ 0.014488f, 0.016068f, 0.017532f, 0.019348f, 0.021210f, 0.023834f, 0.025986f, 0.028854f, 0.031891f, 0.035339f, 0.039490f, 0.043976f,
+ 0.049347f, 0.055084f, 0.061951f, 0.069763f, 0.078918f, 0.089478f, 0.101379f, 0.115479f, 0.131592f, 0.150024f, 0.171387f, 0.195068f,
+ 0.222900f, 0.252686f, 0.286621f, 0.323242f, 0.362061f, 0.402588f, 0.445312f, 0.488770f, 0.532715f, 0.575684f, 0.618652f, 0.659180f,
+ 0.698242f, 0.734375f, 0.901367f, 0.909180f, 0.911133f, 0.910645f, 0.911133f, 0.910645f, 0.000218f, 0.000539f, 0.001187f, 0.001617f,
+ 0.001987f, 0.002316f, 0.002666f, 0.003176f, 0.003841f, 0.004425f, 0.004917f, 0.005402f, 0.005768f, 0.006462f, 0.007233f, 0.008018f,
+ 0.008575f, 0.009758f, 0.010582f, 0.011520f, 0.012756f, 0.013832f, 0.015312f, 0.016968f, 0.018509f, 0.020279f, 0.022644f, 0.024857f,
+ 0.027740f, 0.030472f, 0.033783f, 0.037567f, 0.042175f, 0.047150f, 0.052979f, 0.059601f, 0.067505f, 0.076538f, 0.087158f, 0.099243f,
+ 0.113281f, 0.129272f, 0.148315f, 0.170532f, 0.194702f, 0.223267f, 0.254639f, 0.289795f, 0.327393f, 0.368408f, 0.410889f, 0.455322f,
+ 0.499756f, 0.544434f, 0.590332f, 0.633789f, 0.676270f, 0.716309f, 0.895508f, 0.902344f, 0.903809f, 0.905762f, 0.903809f, 0.904297f,
+ 0.000184f, 0.000612f, 0.001122f, 0.001464f, 0.001848f, 0.002150f, 0.002514f, 0.002651f, 0.003391f, 0.003666f, 0.004368f, 0.004677f,
+ 0.005219f, 0.005882f, 0.006531f, 0.007019f, 0.007675f, 0.008530f, 0.009224f, 0.010269f, 0.011017f, 0.012146f, 0.013321f, 0.014626f,
+ 0.016098f, 0.017639f, 0.019440f, 0.021317f, 0.023773f, 0.026123f, 0.029144f, 0.032410f, 0.036072f, 0.040314f, 0.045013f, 0.051086f,
+ 0.057587f, 0.065308f, 0.074402f, 0.084961f, 0.097107f, 0.111267f, 0.127930f, 0.147217f, 0.169556f, 0.195312f, 0.224365f, 0.257568f,
+ 0.294189f, 0.333496f, 0.375977f, 0.420166f, 0.467041f, 0.514160f, 0.561035f, 0.607422f, 0.652344f, 0.695312f, 0.888672f, 0.896484f,
+ 0.897461f, 0.897461f, 0.897949f, 0.897949f, 0.000159f, 0.000537f, 0.000830f, 0.001206f, 0.001578f, 0.001760f, 0.002050f, 0.002504f,
+ 0.002951f, 0.003397f, 0.003674f, 0.004238f, 0.004520f, 0.005245f, 0.005692f, 0.006138f, 0.006748f, 0.007240f, 0.008087f, 0.008728f,
+ 0.009636f, 0.010437f, 0.011543f, 0.012611f, 0.013763f, 0.015266f, 0.016617f, 0.018433f, 0.020248f, 0.022354f, 0.024887f, 0.027390f,
+ 0.030716f, 0.034454f, 0.038422f, 0.043365f, 0.048950f, 0.055511f, 0.062988f, 0.072021f, 0.082336f, 0.094727f, 0.109375f, 0.125977f,
+ 0.145874f, 0.169556f, 0.195679f, 0.226929f, 0.260986f, 0.299805f, 0.341309f, 0.385498f, 0.432129f, 0.480957f, 0.529297f, 0.579102f,
+ 0.627441f, 0.673828f, 0.881348f, 0.889160f, 0.890625f, 0.891113f, 0.891602f, 0.891113f, 0.000204f, 0.000566f, 0.000741f, 0.001033f,
+ 0.001378f, 0.001599f, 0.001961f, 0.002354f, 0.002609f, 0.002974f, 0.003300f, 0.003609f, 0.004101f, 0.004463f, 0.004906f, 0.005337f,
+ 0.006020f, 0.006290f, 0.007023f, 0.007656f, 0.008301f, 0.009140f, 0.009918f, 0.010933f, 0.011940f, 0.013107f, 0.014252f, 0.015656f,
+ 0.017136f, 0.019058f, 0.021057f, 0.023209f, 0.025940f, 0.029190f, 0.032715f, 0.036591f, 0.041138f, 0.046661f, 0.053253f, 0.060944f,
+ 0.069702f, 0.080444f, 0.092651f, 0.107788f, 0.124695f, 0.145630f, 0.169189f, 0.197632f, 0.229736f, 0.266113f, 0.306396f, 0.350586f,
+ 0.397217f, 0.447021f, 0.497803f, 0.549805f, 0.600586f, 0.650391f, 0.872559f, 0.881836f, 0.882812f, 0.883301f, 0.884277f, 0.884277f,
+ 0.000240f, 0.000349f, 0.000795f, 0.000892f, 0.001151f, 0.001377f, 0.001773f, 0.001984f, 0.002415f, 0.002602f, 0.002932f, 0.003168f,
+ 0.003483f, 0.003906f, 0.004257f, 0.004681f, 0.005173f, 0.005596f, 0.006119f, 0.006550f, 0.007126f, 0.007759f, 0.008522f, 0.009270f,
+ 0.010086f, 0.011108f, 0.012138f, 0.013199f, 0.014549f, 0.015884f, 0.017776f, 0.019623f, 0.022003f, 0.024384f, 0.027237f, 0.030624f,
+ 0.034515f, 0.039215f, 0.044342f, 0.050873f, 0.058411f, 0.067017f, 0.078003f, 0.090332f, 0.105530f, 0.123718f, 0.144775f, 0.170410f,
+ 0.200195f, 0.234131f, 0.272461f, 0.315674f, 0.362305f, 0.412354f, 0.465332f, 0.518555f, 0.572754f, 0.626465f, 0.863770f, 0.873047f,
+ 0.875488f, 0.875488f, 0.875977f, 0.875977f, 0.000102f, 0.000298f, 0.000604f, 0.000950f, 0.001089f, 0.001472f, 0.001760f, 0.001823f,
+ 0.001903f, 0.002325f, 0.002611f, 0.002775f, 0.003185f, 0.003405f, 0.003674f, 0.004005f, 0.004406f, 0.004814f, 0.005203f, 0.005665f,
+ 0.006062f, 0.006702f, 0.007317f, 0.007881f, 0.008560f, 0.009239f, 0.010193f, 0.010994f, 0.012161f, 0.013588f, 0.015068f, 0.016479f,
+ 0.018250f, 0.020386f, 0.022781f, 0.025665f, 0.028809f, 0.032501f, 0.037048f, 0.042297f, 0.048553f, 0.055908f, 0.065491f, 0.075378f,
+ 0.088501f, 0.104248f, 0.122742f, 0.145874f, 0.171997f, 0.203247f, 0.239990f, 0.281250f, 0.326904f, 0.376953f, 0.430176f, 0.486328f,
+ 0.542480f, 0.600586f, 0.855469f, 0.864746f, 0.866211f, 0.867188f, 0.867188f, 0.867188f, 0.000000f, 0.000357f, 0.000576f, 0.000692f,
+ 0.001013f, 0.001069f, 0.001383f, 0.001702f, 0.001789f, 0.002102f, 0.002182f, 0.002377f, 0.002686f, 0.002985f, 0.003347f, 0.003359f,
+ 0.003782f, 0.004036f, 0.004436f, 0.004749f, 0.005169f, 0.005672f, 0.006145f, 0.006649f, 0.007187f, 0.007828f, 0.008644f, 0.009529f,
+ 0.010269f, 0.011200f, 0.012337f, 0.013596f, 0.015038f, 0.017044f, 0.018784f, 0.021011f, 0.023727f, 0.026871f, 0.030457f, 0.034637f,
+ 0.039978f, 0.046478f, 0.053436f, 0.062622f, 0.073730f, 0.086792f, 0.102661f, 0.122437f, 0.146240f, 0.174561f, 0.208252f, 0.247437f,
+ 0.291748f, 0.341064f, 0.395020f, 0.451904f, 0.511230f, 0.571777f, 0.844238f, 0.854980f, 0.857422f, 0.858887f, 0.857910f, 0.857910f,
+ 0.000101f, 0.000326f, 0.000535f, 0.000683f, 0.000848f, 0.001161f, 0.001184f, 0.001284f, 0.001576f, 0.001701f, 0.001839f, 0.002167f,
+ 0.002321f, 0.002584f, 0.002645f, 0.002941f, 0.003141f, 0.003538f, 0.003817f, 0.004112f, 0.004395f, 0.004646f, 0.005165f, 0.005531f,
+ 0.006096f, 0.006496f, 0.007217f, 0.007767f, 0.008629f, 0.009163f, 0.010239f, 0.011276f, 0.012611f, 0.013779f, 0.015213f, 0.017120f,
+ 0.019379f, 0.021606f, 0.024994f, 0.028351f, 0.032379f, 0.037201f, 0.043640f, 0.050903f, 0.060120f, 0.071045f, 0.084900f, 0.101868f,
+ 0.122559f, 0.147827f, 0.178223f, 0.214722f, 0.257080f, 0.305664f, 0.358887f, 0.416992f, 0.478027f, 0.542969f, 0.834473f, 0.845215f,
+ 0.847656f, 0.847656f, 0.847656f, 0.848633f, 0.000092f, 0.000316f, 0.000410f, 0.000556f, 0.000808f, 0.000918f, 0.001094f, 0.001287f,
+ 0.001309f, 0.001411f, 0.001671f, 0.001780f, 0.001909f, 0.002092f, 0.002274f, 0.002523f, 0.002733f, 0.002974f, 0.003101f, 0.003401f,
+ 0.003677f, 0.003956f, 0.004311f, 0.004551f, 0.004940f, 0.005444f, 0.005768f, 0.006451f, 0.006977f, 0.007568f, 0.008270f, 0.009201f,
+ 0.010170f, 0.011230f, 0.012566f, 0.013939f, 0.015503f, 0.017761f, 0.020111f, 0.022873f, 0.025940f, 0.029938f, 0.035217f, 0.040985f,
+ 0.048431f, 0.057770f, 0.069092f, 0.083618f, 0.100891f, 0.123047f, 0.150146f, 0.183838f, 0.223633f, 0.269531f, 0.322510f, 0.381348f,
+ 0.444824f, 0.511719f, 0.823730f, 0.834473f, 0.835938f, 0.836914f, 0.836914f, 0.837402f, 0.000240f, 0.000273f, 0.000326f, 0.000564f,
+ 0.000682f, 0.000807f, 0.000854f, 0.000949f, 0.001139f, 0.001238f, 0.001404f, 0.001548f, 0.001637f, 0.001840f, 0.001893f, 0.002077f,
+ 0.002321f, 0.002434f, 0.002642f, 0.002821f, 0.003044f, 0.003271f, 0.003649f, 0.003763f, 0.004208f, 0.004448f, 0.004986f, 0.005169f,
+ 0.005657f, 0.006279f, 0.006680f, 0.007442f, 0.008194f, 0.008881f, 0.009895f, 0.010918f, 0.012138f, 0.013924f, 0.015915f, 0.018112f,
+ 0.020645f, 0.023743f, 0.027817f, 0.032745f, 0.038361f, 0.045990f, 0.055481f, 0.066895f, 0.082031f, 0.100769f, 0.124573f, 0.154541f,
+ 0.190796f, 0.235107f, 0.286133f, 0.344238f, 0.408936f, 0.478271f, 0.810547f, 0.822266f, 0.824707f, 0.825195f, 0.825684f, 0.825684f,
+ 0.000115f, 0.000222f, 0.000252f, 0.000524f, 0.000574f, 0.000673f, 0.000869f, 0.000928f, 0.000963f, 0.001022f, 0.001246f, 0.001292f,
+ 0.001404f, 0.001477f, 0.001652f, 0.001811f, 0.001822f, 0.002058f, 0.002237f, 0.002371f, 0.002588f, 0.002645f, 0.003019f, 0.003080f,
+ 0.003506f, 0.003689f, 0.003904f, 0.004383f, 0.004707f, 0.005020f, 0.005386f, 0.006023f, 0.006451f, 0.007038f, 0.007809f, 0.008911f,
+ 0.009949f, 0.011200f, 0.012222f, 0.014137f, 0.016068f, 0.018692f, 0.021683f, 0.025314f, 0.029861f, 0.035889f, 0.043335f, 0.052582f,
+ 0.065186f, 0.080627f, 0.101501f, 0.127441f, 0.159912f, 0.200806f, 0.250000f, 0.307129f, 0.371582f, 0.444580f, 0.798340f, 0.809570f,
+ 0.811523f, 0.812988f, 0.812988f, 0.812988f, 0.000000f, 0.000211f, 0.000204f, 0.000474f, 0.000555f, 0.000583f, 0.000600f, 0.000593f,
+ 0.000812f, 0.000865f, 0.000941f, 0.001013f, 0.001162f, 0.001348f, 0.001418f, 0.001465f, 0.001616f, 0.001722f, 0.001856f, 0.001888f,
+ 0.002048f, 0.002321f, 0.002396f, 0.002632f, 0.002821f, 0.002974f, 0.003265f, 0.003477f, 0.003632f, 0.004051f, 0.004299f, 0.004700f,
+ 0.005238f, 0.005592f, 0.006199f, 0.006756f, 0.007614f, 0.008324f, 0.009727f, 0.010811f, 0.012337f, 0.014168f, 0.016434f, 0.019257f,
+ 0.022858f, 0.027451f, 0.033295f, 0.040619f, 0.050690f, 0.063416f, 0.080261f, 0.102295f, 0.131104f, 0.168335f, 0.214355f, 0.270508f,
+ 0.334717f, 0.408936f, 0.783691f, 0.795898f, 0.798340f, 0.799316f, 0.800293f, 0.800293f, 0.000174f, 0.000090f, 0.000281f, 0.000397f,
+ 0.000401f, 0.000450f, 0.000488f, 0.000640f, 0.000674f, 0.000713f, 0.000753f, 0.000845f, 0.000872f, 0.001020f, 0.001115f, 0.001264f,
+ 0.001327f, 0.001373f, 0.001520f, 0.001616f, 0.001767f, 0.001875f, 0.001968f, 0.002090f, 0.002232f, 0.002333f, 0.002472f, 0.002802f,
+ 0.002926f, 0.003189f, 0.003569f, 0.003752f, 0.004009f, 0.004513f, 0.004860f, 0.005375f, 0.005997f, 0.006561f, 0.007378f, 0.008347f,
+ 0.009384f, 0.010612f, 0.012466f, 0.014526f, 0.017075f, 0.020447f, 0.024887f, 0.030533f, 0.038300f, 0.048584f, 0.062042f, 0.080383f,
+ 0.104736f, 0.137329f, 0.180176f, 0.232544f, 0.296875f, 0.371338f, 0.769043f, 0.781250f, 0.784180f, 0.784668f, 0.786133f, 0.786133f,
+ 0.000025f, 0.000135f, 0.000154f, 0.000260f, 0.000353f, 0.000364f, 0.000380f, 0.000520f, 0.000548f, 0.000587f, 0.000712f, 0.000735f,
+ 0.000772f, 0.000822f, 0.000886f, 0.001004f, 0.000946f, 0.001115f, 0.001177f, 0.001266f, 0.001454f, 0.001527f, 0.001575f, 0.001680f,
+ 0.001883f, 0.001961f, 0.002043f, 0.002193f, 0.002281f, 0.002520f, 0.002712f, 0.003021f, 0.003147f, 0.003561f, 0.003786f, 0.004116f,
+ 0.004570f, 0.005058f, 0.005634f, 0.006165f, 0.007095f, 0.008049f, 0.009201f, 0.010674f, 0.012550f, 0.014854f, 0.018051f, 0.022385f,
+ 0.027908f, 0.035522f, 0.046295f, 0.061035f, 0.081238f, 0.109131f, 0.146729f, 0.197021f, 0.258301f, 0.333008f, 0.752441f, 0.766113f,
+ 0.768555f, 0.769531f, 0.770020f, 0.769531f, 0.000000f, 0.000121f, 0.000209f, 0.000291f, 0.000337f, 0.000307f, 0.000324f, 0.000415f,
+ 0.000426f, 0.000453f, 0.000491f, 0.000573f, 0.000644f, 0.000650f, 0.000781f, 0.000746f, 0.000830f, 0.000803f, 0.000997f, 0.001017f,
+ 0.001020f, 0.001158f, 0.001241f, 0.001317f, 0.001375f, 0.001432f, 0.001524f, 0.001656f, 0.001858f, 0.001955f, 0.002050f, 0.002274f,
+ 0.002460f, 0.002724f, 0.002831f, 0.003050f, 0.003441f, 0.003790f, 0.004162f, 0.004623f, 0.005219f, 0.005951f, 0.006721f, 0.007729f,
+ 0.008926f, 0.010620f, 0.013000f, 0.015686f, 0.019852f, 0.025436f, 0.033295f, 0.044617f, 0.060608f, 0.083313f, 0.116211f, 0.161499f,
+ 0.220093f, 0.293945f, 0.734863f, 0.749512f, 0.752441f, 0.752930f, 0.753906f, 0.753906f, 0.000000f, 0.000121f, 0.000118f, 0.000246f,
+ 0.000233f, 0.000252f, 0.000338f, 0.000282f, 0.000353f, 0.000355f, 0.000448f, 0.000435f, 0.000464f, 0.000530f, 0.000578f, 0.000649f,
+ 0.000677f, 0.000710f, 0.000749f, 0.000792f, 0.000881f, 0.000903f, 0.000967f, 0.001049f, 0.001041f, 0.001100f, 0.001176f, 0.001254f,
+ 0.001402f, 0.001451f, 0.001697f, 0.001674f, 0.001804f, 0.001914f, 0.002195f, 0.002451f, 0.002474f, 0.002758f, 0.003029f, 0.003483f,
+ 0.003824f, 0.004272f, 0.004833f, 0.005573f, 0.006477f, 0.007629f, 0.009041f, 0.010918f, 0.013573f, 0.017319f, 0.022842f, 0.031036f,
+ 0.043030f, 0.061096f, 0.088440f, 0.127563f, 0.182861f, 0.254395f, 0.717285f, 0.731934f, 0.734863f, 0.735352f, 0.735840f, 0.736328f,
+ 0.000000f, 0.000000f, 0.000117f, 0.000163f, 0.000109f, 0.000208f, 0.000212f, 0.000208f, 0.000270f, 0.000356f, 0.000324f, 0.000377f,
+ 0.000391f, 0.000420f, 0.000449f, 0.000440f, 0.000484f, 0.000504f, 0.000534f, 0.000561f, 0.000639f, 0.000667f, 0.000715f, 0.000722f,
+ 0.000799f, 0.000845f, 0.000939f, 0.000945f, 0.001053f, 0.001149f, 0.001252f, 0.001310f, 0.001392f, 0.001507f, 0.001526f, 0.001710f,
+ 0.001773f, 0.002111f, 0.002300f, 0.002443f, 0.002661f, 0.002996f, 0.003376f, 0.003880f, 0.004482f, 0.005150f, 0.006115f, 0.007401f,
+ 0.009132f, 0.011696f, 0.015076f, 0.020416f, 0.029236f, 0.042389f, 0.063782f, 0.096802f, 0.146362f, 0.215576f, 0.698242f, 0.712891f,
+ 0.715332f, 0.716797f, 0.717285f, 0.717285f, 0.000000f, 0.000118f, 0.000115f, 0.000133f, 0.000144f, 0.000147f, 0.000162f, 0.000150f,
+ 0.000194f, 0.000215f, 0.000228f, 0.000299f, 0.000271f, 0.000313f, 0.000328f, 0.000358f, 0.000378f, 0.000360f, 0.000407f, 0.000438f,
+ 0.000441f, 0.000488f, 0.000515f, 0.000544f, 0.000576f, 0.000617f, 0.000659f, 0.000715f, 0.000741f, 0.000773f, 0.000850f, 0.000921f,
+ 0.000979f, 0.001066f, 0.001128f, 0.001292f, 0.001279f, 0.001400f, 0.001572f, 0.001668f, 0.001869f, 0.002029f, 0.002295f, 0.002607f,
+ 0.002985f, 0.003464f, 0.004066f, 0.004913f, 0.006023f, 0.007519f, 0.009827f, 0.013016f, 0.018524f, 0.027481f, 0.042847f, 0.068970f,
+ 0.111938f, 0.176392f, 0.675781f, 0.692871f, 0.695801f, 0.696777f, 0.698242f, 0.697754f, 0.000000f, 0.000000f, 0.000111f, 0.000108f,
+ 0.000104f, 0.000102f, 0.000118f, 0.000120f, 0.000134f, 0.000128f, 0.000188f, 0.000154f, 0.000197f, 0.000188f, 0.000245f, 0.000256f,
+ 0.000233f, 0.000266f, 0.000345f, 0.000281f, 0.000355f, 0.000322f, 0.000392f, 0.000358f, 0.000437f, 0.000425f, 0.000458f, 0.000477f,
+ 0.000564f, 0.000636f, 0.000578f, 0.000607f, 0.000668f, 0.000719f, 0.000769f, 0.000832f, 0.000880f, 0.000953f, 0.001060f, 0.001116f,
+ 0.001226f, 0.001363f, 0.001486f, 0.001760f, 0.001944f, 0.002216f, 0.002605f, 0.003107f, 0.003778f, 0.004715f, 0.005989f, 0.007942f,
+ 0.011292f, 0.016632f, 0.026550f, 0.045532f, 0.079956f, 0.138550f, 0.655762f, 0.671875f, 0.674805f, 0.675293f, 0.675781f, 0.678223f,
+ 0.000000f, 0.000112f, 0.000105f, 0.000102f, 0.000098f, 0.000095f, 0.000093f, 0.000088f, 0.000089f, 0.000085f, 0.000095f, 0.000126f,
+ 0.000109f, 0.000154f, 0.000153f, 0.000162f, 0.000176f, 0.000190f, 0.000202f, 0.000204f, 0.000212f, 0.000214f, 0.000266f, 0.000239f,
+ 0.000279f, 0.000293f, 0.000329f, 0.000329f, 0.000339f, 0.000365f, 0.000437f, 0.000424f, 0.000429f, 0.000474f, 0.000525f, 0.000596f,
+ 0.000572f, 0.000612f, 0.000666f, 0.000723f, 0.000791f, 0.000850f, 0.000977f, 0.001066f, 0.001225f, 0.001351f, 0.001555f, 0.001837f,
+ 0.002279f, 0.002760f, 0.003445f, 0.004612f, 0.006386f, 0.009438f, 0.015221f, 0.027008f, 0.052551f, 0.102966f, 0.633789f, 0.649414f,
+ 0.652832f, 0.653809f, 0.655273f, 0.655273f, 0.000000f, 0.000105f, 0.000099f, 0.000094f, 0.000090f, 0.000087f, 0.000084f, 0.000082f,
+ 0.000079f, 0.000075f, 0.000071f, 0.000068f, 0.000064f, 0.000072f, 0.000096f, 0.000105f, 0.000112f, 0.000088f, 0.000123f, 0.000129f,
+ 0.000132f, 0.000140f, 0.000147f, 0.000170f, 0.000188f, 0.000192f, 0.000171f, 0.000210f, 0.000217f, 0.000223f, 0.000237f, 0.000251f,
+ 0.000258f, 0.000294f, 0.000298f, 0.000316f, 0.000350f, 0.000382f, 0.000400f, 0.000437f, 0.000479f, 0.000514f, 0.000576f, 0.000620f,
+ 0.000688f, 0.000782f, 0.000916f, 0.001026f, 0.001219f, 0.001502f, 0.001892f, 0.002424f, 0.003359f, 0.004974f, 0.008118f, 0.014343f,
+ 0.030075f, 0.070068f, 0.610352f, 0.626953f, 0.629883f, 0.631348f, 0.632324f, 0.632324f, 0.000110f, 0.000094f, 0.000087f, 0.000081f,
+ 0.000077f, 0.000075f, 0.000072f, 0.000069f, 0.000067f, 0.000066f, 0.000064f, 0.000062f, 0.000058f, 0.000056f, 0.000053f, 0.000051f,
+ 0.000054f, 0.000047f, 0.000057f, 0.000055f, 0.000075f, 0.000078f, 0.000086f, 0.000093f, 0.000093f, 0.000102f, 0.000112f, 0.000113f,
+ 0.000130f, 0.000128f, 0.000142f, 0.000145f, 0.000156f, 0.000153f, 0.000180f, 0.000178f, 0.000183f, 0.000223f, 0.000230f, 0.000240f,
+ 0.000265f, 0.000276f, 0.000300f, 0.000332f, 0.000357f, 0.000411f, 0.000449f, 0.000540f, 0.000615f, 0.000741f, 0.000916f, 0.001144f,
+ 0.001566f, 0.002310f, 0.003731f, 0.006905f, 0.014793f, 0.041779f, 0.585938f, 0.603027f, 0.605957f, 0.608398f, 0.608398f, 0.609375f,
+ 0.000090f, 0.000071f, 0.000066f, 0.000062f, 0.000058f, 0.000056f, 0.000053f, 0.000053f, 0.000051f, 0.000051f, 0.000049f, 0.000048f,
+ 0.000048f, 0.000047f, 0.000045f, 0.000043f, 0.000042f, 0.000040f, 0.000038f, 0.000036f, 0.000036f, 0.000033f, 0.000034f, 0.000040f,
+ 0.000040f, 0.000040f, 0.000048f, 0.000053f, 0.000060f, 0.000064f, 0.000067f, 0.000070f, 0.000075f, 0.000081f, 0.000085f, 0.000090f,
+ 0.000091f, 0.000103f, 0.000106f, 0.000120f, 0.000134f, 0.000138f, 0.000142f, 0.000156f, 0.000174f, 0.000180f, 0.000212f, 0.000239f,
+ 0.000253f, 0.000310f, 0.000377f, 0.000479f, 0.000627f, 0.000875f, 0.001396f, 0.002623f, 0.006184f, 0.019897f, 0.560547f, 0.578125f,
+ 0.581543f, 0.583008f, 0.583984f, 0.583984f, 0.000038f, 0.000035f, 0.000031f, 0.000031f, 0.000030f, 0.000031f, 0.000031f, 0.000030f,
+ 0.000030f, 0.000028f, 0.000029f, 0.000030f, 0.000029f, 0.000028f, 0.000029f, 0.000029f, 0.000029f, 0.000029f, 0.000029f, 0.000028f,
+ 0.000027f, 0.000026f, 0.000025f, 0.000024f, 0.000023f, 0.000022f, 0.000021f, 0.000020f, 0.000019f, 0.000021f, 0.000019f, 0.000022f,
+ 0.000023f, 0.000027f, 0.000031f, 0.000035f, 0.000037f, 0.000039f, 0.000039f, 0.000043f, 0.000049f, 0.000052f, 0.000056f, 0.000050f,
+ 0.000068f, 0.000062f, 0.000070f, 0.000087f, 0.000094f, 0.000107f, 0.000122f, 0.000140f, 0.000191f, 0.000247f, 0.000388f, 0.000710f,
+ 0.001781f, 0.007076f, 0.535156f, 0.553223f, 0.556152f, 0.558105f, 0.559082f, 0.559082f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000003f, 0.000003f, 0.000005f, 0.000006f, 0.000007f, 0.000007f, 0.000009f,
+ 0.000009f, 0.000009f, 0.000010f, 0.000010f, 0.000011f, 0.000011f, 0.000012f, 0.000012f, 0.000012f, 0.000013f, 0.000013f, 0.000013f,
+ 0.000013f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000009f,
+ 0.000009f, 0.000010f, 0.000011f, 0.000015f, 0.000017f, 0.000016f, 0.000018f, 0.000021f, 0.000020f, 0.000024f, 0.000024f, 0.000032f,
+ 0.000035f, 0.000045f, 0.000065f, 0.000105f, 0.000246f, 0.001313f, 0.508789f, 0.527344f, 0.530762f, 0.531738f, 0.532715f, 0.533691f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000005f, 0.000018f, 0.481934f, 0.500977f,
+ 0.504883f, 0.505859f, 0.507324f, 0.507812f,
+ },
+ {
+ 0.053833f, 0.152832f, 0.239014f, 0.313477f, 0.377686f, 0.433838f, 0.481689f, 0.524414f, 0.562988f, 0.596680f, 0.626953f, 0.654785f,
+ 0.678711f, 0.700684f, 0.720703f, 0.739746f, 0.755859f, 0.771973f, 0.787109f, 0.798828f, 0.812012f, 0.823730f, 0.833984f, 0.844238f,
+ 0.853027f, 0.862793f, 0.870605f, 0.878418f, 0.885254f, 0.892090f, 0.898926f, 0.904297f, 0.910645f, 0.916504f, 0.921875f, 0.926270f,
+ 0.931641f, 0.936035f, 0.939941f, 0.944336f, 0.948242f, 0.952148f, 0.955566f, 0.959961f, 0.962402f, 0.966309f, 0.969238f, 0.972168f,
+ 0.975098f, 0.978027f, 0.980957f, 0.983398f, 0.985840f, 0.988281f, 0.990723f, 0.992676f, 0.995117f, 0.996582f, 0.998047f, 0.995117f,
+ 0.993164f, 0.990723f, 0.988770f, 0.986816f, 0.036804f, 0.109497f, 0.178589f, 0.244751f, 0.305908f, 0.361084f, 0.411621f, 0.457275f,
+ 0.498535f, 0.536133f, 0.569824f, 0.601562f, 0.629883f, 0.655273f, 0.679688f, 0.700195f, 0.720215f, 0.737793f, 0.755859f, 0.770508f,
+ 0.785645f, 0.798340f, 0.811035f, 0.822754f, 0.833008f, 0.843750f, 0.852539f, 0.861328f, 0.869629f, 0.877441f, 0.885742f, 0.892578f,
+ 0.898926f, 0.905273f, 0.911133f, 0.916504f, 0.921875f, 0.926758f, 0.931641f, 0.936523f, 0.940430f, 0.945312f, 0.949219f, 0.953613f,
+ 0.956543f, 0.960449f, 0.963867f, 0.967285f, 0.970703f, 0.973633f, 0.976562f, 0.979004f, 0.981934f, 0.984375f, 0.986816f, 0.989746f,
+ 0.992188f, 0.994141f, 0.996582f, 0.994141f, 0.992188f, 0.990234f, 0.988281f, 0.986328f, 0.025787f, 0.080383f, 0.136230f, 0.191650f,
+ 0.245239f, 0.297119f, 0.345947f, 0.392822f, 0.436035f, 0.476807f, 0.513184f, 0.547363f, 0.578125f, 0.607910f, 0.634766f, 0.658203f,
+ 0.681152f, 0.702637f, 0.721191f, 0.738770f, 0.755371f, 0.770508f, 0.784668f, 0.798828f, 0.810547f, 0.821777f, 0.833984f, 0.843262f,
+ 0.852539f, 0.861816f, 0.869629f, 0.877930f, 0.885254f, 0.893555f, 0.898926f, 0.906250f, 0.911621f, 0.917969f, 0.923340f, 0.928223f,
+ 0.933105f, 0.937500f, 0.941406f, 0.946289f, 0.950195f, 0.954102f, 0.958496f, 0.961914f, 0.965820f, 0.968750f, 0.971680f, 0.975098f,
+ 0.978027f, 0.980469f, 0.983887f, 0.985840f, 0.988770f, 0.991211f, 0.995117f, 0.993164f, 0.991211f, 0.989258f, 0.987305f, 0.985352f,
+ 0.019455f, 0.060944f, 0.104553f, 0.150513f, 0.196411f, 0.243164f, 0.289062f, 0.333740f, 0.376709f, 0.417725f, 0.454346f, 0.491211f,
+ 0.524414f, 0.556641f, 0.585938f, 0.613770f, 0.639160f, 0.662598f, 0.682617f, 0.703613f, 0.723633f, 0.740723f, 0.756836f, 0.771973f,
+ 0.787109f, 0.798828f, 0.812012f, 0.823242f, 0.833984f, 0.844238f, 0.853516f, 0.863281f, 0.871094f, 0.879395f, 0.886719f, 0.893555f,
+ 0.899902f, 0.907227f, 0.913086f, 0.918945f, 0.924805f, 0.928711f, 0.934082f, 0.938965f, 0.943848f, 0.947754f, 0.952637f, 0.955566f,
+ 0.959961f, 0.963867f, 0.966797f, 0.970215f, 0.973633f, 0.977051f, 0.979004f, 0.982422f, 0.985840f, 0.987793f, 0.993652f, 0.991699f,
+ 0.989746f, 0.988281f, 0.986328f, 0.984375f, 0.015221f, 0.047363f, 0.082092f, 0.119202f, 0.159058f, 0.199219f, 0.239380f, 0.280762f,
+ 0.321533f, 0.362061f, 0.400146f, 0.436768f, 0.472900f, 0.504883f, 0.536621f, 0.566406f, 0.594238f, 0.621094f, 0.645508f, 0.667969f,
+ 0.688477f, 0.707520f, 0.726562f, 0.742676f, 0.759277f, 0.773926f, 0.787598f, 0.800781f, 0.812988f, 0.825195f, 0.835938f, 0.846191f,
+ 0.856445f, 0.865234f, 0.872559f, 0.880859f, 0.888672f, 0.895020f, 0.902832f, 0.908203f, 0.914551f, 0.919922f, 0.926758f, 0.931152f,
+ 0.937012f, 0.941406f, 0.945312f, 0.949707f, 0.954102f, 0.958496f, 0.962402f, 0.965820f, 0.969238f, 0.972168f, 0.976074f, 0.978516f,
+ 0.981934f, 0.984863f, 0.992188f, 0.990723f, 0.988770f, 0.987305f, 0.985352f, 0.983887f, 0.011658f, 0.037170f, 0.065430f, 0.096008f,
+ 0.128784f, 0.162842f, 0.198975f, 0.235596f, 0.273926f, 0.310791f, 0.348145f, 0.385010f, 0.420410f, 0.454834f, 0.488037f, 0.519043f,
+ 0.548828f, 0.577148f, 0.603516f, 0.627441f, 0.650879f, 0.672363f, 0.693848f, 0.712402f, 0.729980f, 0.748535f, 0.762207f, 0.778809f,
+ 0.791504f, 0.804199f, 0.815918f, 0.827637f, 0.838867f, 0.848145f, 0.857910f, 0.866211f, 0.875977f, 0.883301f, 0.891602f, 0.898438f,
+ 0.905273f, 0.911133f, 0.917480f, 0.923340f, 0.928711f, 0.933594f, 0.938477f, 0.942871f, 0.948242f, 0.952637f, 0.956543f, 0.960449f,
+ 0.964355f, 0.968262f, 0.971191f, 0.974609f, 0.978027f, 0.980957f, 0.990723f, 0.989258f, 0.987793f, 0.985840f, 0.984375f, 0.983398f,
+ 0.009758f, 0.030121f, 0.052490f, 0.077576f, 0.104309f, 0.134277f, 0.164917f, 0.197510f, 0.231812f, 0.266113f, 0.301025f, 0.336426f,
+ 0.372070f, 0.405762f, 0.438721f, 0.471436f, 0.502441f, 0.531738f, 0.560059f, 0.587402f, 0.612793f, 0.634766f, 0.658691f, 0.679199f,
+ 0.699219f, 0.718262f, 0.735352f, 0.751953f, 0.767090f, 0.780762f, 0.794922f, 0.808105f, 0.820801f, 0.831055f, 0.842285f, 0.851562f,
+ 0.861328f, 0.870117f, 0.878906f, 0.886719f, 0.893555f, 0.900879f, 0.907715f, 0.913574f, 0.919434f, 0.926270f, 0.932129f, 0.936523f,
+ 0.941895f, 0.945801f, 0.951172f, 0.955078f, 0.959473f, 0.963867f, 0.966797f, 0.970703f, 0.974121f, 0.977539f, 0.989746f, 0.988281f,
+ 0.986328f, 0.984863f, 0.983398f, 0.982422f, 0.007744f, 0.024567f, 0.043365f, 0.063782f, 0.086487f, 0.111389f, 0.137451f, 0.166260f,
+ 0.195435f, 0.226929f, 0.259033f, 0.291748f, 0.324951f, 0.358398f, 0.391113f, 0.424316f, 0.456299f, 0.486328f, 0.516113f, 0.543945f,
+ 0.571289f, 0.597656f, 0.621094f, 0.644531f, 0.666504f, 0.686523f, 0.705078f, 0.724121f, 0.741211f, 0.757324f, 0.773438f, 0.786621f,
+ 0.801270f, 0.812988f, 0.823730f, 0.835938f, 0.846191f, 0.855957f, 0.865723f, 0.873047f, 0.882324f, 0.889648f, 0.897949f, 0.905762f,
+ 0.911133f, 0.917969f, 0.923828f, 0.929199f, 0.934082f, 0.940430f, 0.944824f, 0.949707f, 0.954102f, 0.958008f, 0.962891f, 0.966309f,
+ 0.970215f, 0.974121f, 0.987793f, 0.986816f, 0.985352f, 0.983887f, 0.981934f, 0.980469f, 0.006672f, 0.020828f, 0.035950f, 0.053345f,
+ 0.071594f, 0.092834f, 0.114624f, 0.139282f, 0.165649f, 0.192627f, 0.222290f, 0.252197f, 0.283203f, 0.314941f, 0.346680f, 0.377930f,
+ 0.409668f, 0.441650f, 0.471680f, 0.500977f, 0.529297f, 0.557129f, 0.583008f, 0.607422f, 0.630859f, 0.654297f, 0.674805f, 0.694824f,
+ 0.713867f, 0.731445f, 0.748535f, 0.763672f, 0.778320f, 0.791992f, 0.805664f, 0.817871f, 0.829590f, 0.840332f, 0.850098f, 0.860352f,
+ 0.869141f, 0.878906f, 0.886719f, 0.894043f, 0.901855f, 0.909180f, 0.915527f, 0.920898f, 0.927246f, 0.933105f, 0.938477f, 0.943848f,
+ 0.948730f, 0.953125f, 0.957520f, 0.961914f, 0.965820f, 0.970215f, 0.985840f, 0.985352f, 0.983887f, 0.981934f, 0.980957f, 0.979492f,
+ 0.005592f, 0.017181f, 0.030457f, 0.044739f, 0.060638f, 0.077454f, 0.097046f, 0.117981f, 0.140625f, 0.164673f, 0.190552f, 0.217896f,
+ 0.246582f, 0.275635f, 0.305176f, 0.336426f, 0.366943f, 0.397949f, 0.428711f, 0.457764f, 0.487061f, 0.515137f, 0.542480f, 0.568848f,
+ 0.593750f, 0.619141f, 0.641602f, 0.662598f, 0.683594f, 0.703613f, 0.721191f, 0.738281f, 0.755859f, 0.770996f, 0.784180f, 0.799316f,
+ 0.811035f, 0.823730f, 0.833984f, 0.845703f, 0.855957f, 0.865234f, 0.875000f, 0.883301f, 0.891602f, 0.898926f, 0.906738f, 0.912598f,
+ 0.919922f, 0.926270f, 0.931152f, 0.937988f, 0.942871f, 0.948242f, 0.952148f, 0.957520f, 0.961914f, 0.966309f, 0.984375f, 0.983398f,
+ 0.982422f, 0.981445f, 0.979492f, 0.978027f, 0.004829f, 0.014816f, 0.025711f, 0.037964f, 0.051300f, 0.065796f, 0.082458f, 0.100037f,
+ 0.120178f, 0.141357f, 0.163330f, 0.187622f, 0.213013f, 0.240601f, 0.268311f, 0.296387f, 0.325928f, 0.356445f, 0.385742f, 0.415771f,
+ 0.445557f, 0.474121f, 0.501465f, 0.530762f, 0.556152f, 0.581543f, 0.606445f, 0.630859f, 0.651855f, 0.672852f, 0.693359f, 0.712402f,
+ 0.730469f, 0.746582f, 0.762695f, 0.777832f, 0.791992f, 0.806152f, 0.818359f, 0.830566f, 0.840820f, 0.852051f, 0.862305f, 0.871094f,
+ 0.880371f, 0.888184f, 0.896484f, 0.904297f, 0.910645f, 0.917969f, 0.924316f, 0.931152f, 0.936035f, 0.942383f, 0.947266f, 0.951660f,
+ 0.957031f, 0.960938f, 0.982422f, 0.982422f, 0.981445f, 0.979492f, 0.978516f, 0.977051f, 0.004040f, 0.012436f, 0.022064f, 0.032440f,
+ 0.044006f, 0.056549f, 0.070068f, 0.085999f, 0.102539f, 0.120239f, 0.140625f, 0.161621f, 0.184448f, 0.208496f, 0.234253f, 0.260742f,
+ 0.288086f, 0.316406f, 0.345215f, 0.374512f, 0.404297f, 0.433350f, 0.462402f, 0.490234f, 0.518066f, 0.543945f, 0.570312f, 0.594727f,
+ 0.618652f, 0.642090f, 0.663086f, 0.683594f, 0.703613f, 0.721680f, 0.739258f, 0.755859f, 0.772461f, 0.786621f, 0.798828f, 0.812500f,
+ 0.825195f, 0.836914f, 0.848633f, 0.858887f, 0.869141f, 0.877441f, 0.886230f, 0.894531f, 0.902832f, 0.909668f, 0.916992f, 0.923340f,
+ 0.929688f, 0.935547f, 0.941406f, 0.947266f, 0.951660f, 0.957031f, 0.980469f, 0.980469f, 0.979492f, 0.978516f, 0.977051f, 0.976074f,
+ 0.003536f, 0.010872f, 0.018829f, 0.027893f, 0.037872f, 0.048492f, 0.060883f, 0.073425f, 0.088074f, 0.103638f, 0.120789f, 0.139038f,
+ 0.159912f, 0.181274f, 0.204102f, 0.227905f, 0.253906f, 0.280518f, 0.307861f, 0.335938f, 0.364746f, 0.393311f, 0.421631f, 0.451416f,
+ 0.479004f, 0.505859f, 0.533203f, 0.560059f, 0.584473f, 0.608398f, 0.631836f, 0.653320f, 0.674805f, 0.695801f, 0.714355f, 0.731934f,
+ 0.749512f, 0.765137f, 0.781250f, 0.794434f, 0.808594f, 0.821289f, 0.833496f, 0.844238f, 0.855469f, 0.866211f, 0.875000f, 0.883789f,
+ 0.892578f, 0.901855f, 0.908691f, 0.915527f, 0.922852f, 0.929199f, 0.935059f, 0.941406f, 0.947266f, 0.951172f, 0.978516f, 0.979004f,
+ 0.978027f, 0.977051f, 0.975586f, 0.974121f, 0.002989f, 0.009476f, 0.016785f, 0.024246f, 0.032745f, 0.041809f, 0.052246f, 0.063782f,
+ 0.076111f, 0.089722f, 0.104675f, 0.120605f, 0.138306f, 0.157959f, 0.178101f, 0.200073f, 0.223145f, 0.247192f, 0.273193f, 0.300293f,
+ 0.327148f, 0.354736f, 0.383545f, 0.411621f, 0.439941f, 0.468018f, 0.495605f, 0.522949f, 0.548828f, 0.574219f, 0.598145f, 0.622559f,
+ 0.645508f, 0.666016f, 0.687500f, 0.706543f, 0.725586f, 0.743164f, 0.759766f, 0.775391f, 0.791016f, 0.803711f, 0.817871f, 0.829590f,
+ 0.841797f, 0.852539f, 0.863281f, 0.873047f, 0.882812f, 0.891113f, 0.900391f, 0.906738f, 0.915039f, 0.922852f, 0.929688f, 0.936035f,
+ 0.941895f, 0.946777f, 0.976074f, 0.977051f, 0.976074f, 0.975586f, 0.974121f, 0.972656f, 0.002846f, 0.008568f, 0.014557f, 0.021484f,
+ 0.028442f, 0.036377f, 0.045074f, 0.055054f, 0.066101f, 0.077759f, 0.090759f, 0.104797f, 0.120483f, 0.136719f, 0.155029f, 0.175171f,
+ 0.196045f, 0.218262f, 0.241943f, 0.266357f, 0.292480f, 0.319336f, 0.345703f, 0.373535f, 0.402100f, 0.429932f, 0.457764f, 0.484863f,
+ 0.512207f, 0.539062f, 0.564941f, 0.589844f, 0.613281f, 0.636719f, 0.659180f, 0.680664f, 0.700684f, 0.718750f, 0.736816f, 0.754883f,
+ 0.770508f, 0.785645f, 0.799805f, 0.813965f, 0.826172f, 0.838867f, 0.850586f, 0.861328f, 0.871582f, 0.881836f, 0.890625f, 0.898926f,
+ 0.906738f, 0.915039f, 0.922363f, 0.928711f, 0.936035f, 0.941895f, 0.974609f, 0.975098f, 0.974609f, 0.973633f, 0.972656f, 0.971191f,
+ 0.002285f, 0.007290f, 0.012634f, 0.018280f, 0.024918f, 0.032074f, 0.039673f, 0.048157f, 0.057220f, 0.067810f, 0.078735f, 0.091248f,
+ 0.104370f, 0.119873f, 0.135742f, 0.152344f, 0.171631f, 0.191650f, 0.213501f, 0.236206f, 0.260010f, 0.285156f, 0.310547f, 0.338135f,
+ 0.364746f, 0.392578f, 0.420410f, 0.448242f, 0.476562f, 0.502441f, 0.529785f, 0.555664f, 0.581543f, 0.605469f, 0.629395f, 0.652344f,
+ 0.673340f, 0.693848f, 0.713867f, 0.732910f, 0.750000f, 0.767090f, 0.782715f, 0.797852f, 0.811035f, 0.825195f, 0.836914f, 0.848633f,
+ 0.860840f, 0.870605f, 0.880371f, 0.890137f, 0.898926f, 0.907227f, 0.915527f, 0.923340f, 0.929688f, 0.936523f, 0.972168f, 0.973145f,
+ 0.972656f, 0.972168f, 0.970703f, 0.969727f, 0.002064f, 0.006584f, 0.011154f, 0.016266f, 0.022263f, 0.028397f, 0.034973f, 0.042145f,
+ 0.050232f, 0.059235f, 0.069031f, 0.079346f, 0.091736f, 0.104553f, 0.118652f, 0.133789f, 0.150635f, 0.168457f, 0.188110f, 0.208984f,
+ 0.230225f, 0.253906f, 0.278076f, 0.303955f, 0.329346f, 0.356689f, 0.384033f, 0.411865f, 0.439941f, 0.467285f, 0.493896f, 0.520996f,
+ 0.547363f, 0.573730f, 0.597168f, 0.622559f, 0.645508f, 0.667969f, 0.688965f, 0.709473f, 0.728027f, 0.746094f, 0.762695f, 0.778809f,
+ 0.794922f, 0.809082f, 0.822754f, 0.834961f, 0.847168f, 0.858887f, 0.870117f, 0.880371f, 0.889648f, 0.898926f, 0.907227f, 0.915039f,
+ 0.923828f, 0.930176f, 0.970215f, 0.971680f, 0.970215f, 0.970215f, 0.968750f, 0.968262f, 0.001935f, 0.005634f, 0.010078f, 0.014389f,
+ 0.019669f, 0.024658f, 0.030716f, 0.037201f, 0.044098f, 0.051941f, 0.060333f, 0.070129f, 0.080383f, 0.091370f, 0.103638f, 0.116943f,
+ 0.131714f, 0.148193f, 0.165161f, 0.183838f, 0.203979f, 0.225220f, 0.247803f, 0.271240f, 0.296631f, 0.322510f, 0.349121f, 0.376221f,
+ 0.403076f, 0.431152f, 0.458984f, 0.485596f, 0.513672f, 0.540039f, 0.564941f, 0.590820f, 0.616211f, 0.638672f, 0.662109f, 0.683105f,
+ 0.704102f, 0.723633f, 0.741699f, 0.759766f, 0.776855f, 0.792480f, 0.807617f, 0.821777f, 0.833496f, 0.847168f, 0.858887f, 0.870117f,
+ 0.880859f, 0.889648f, 0.899414f, 0.908203f, 0.916992f, 0.924316f, 0.967285f, 0.968262f, 0.968750f, 0.968262f, 0.967285f, 0.966309f,
+ 0.001805f, 0.005119f, 0.009079f, 0.013023f, 0.017487f, 0.022278f, 0.027130f, 0.032684f, 0.038666f, 0.045959f, 0.052826f, 0.061401f,
+ 0.070801f, 0.080139f, 0.090698f, 0.102844f, 0.115845f, 0.130005f, 0.145264f, 0.162476f, 0.180176f, 0.199951f, 0.220459f, 0.242188f,
+ 0.265869f, 0.290283f, 0.315430f, 0.341309f, 0.368652f, 0.395752f, 0.423584f, 0.451416f, 0.479248f, 0.505859f, 0.532227f, 0.559082f,
+ 0.584961f, 0.609863f, 0.634277f, 0.656738f, 0.678711f, 0.700195f, 0.720703f, 0.738281f, 0.757324f, 0.774414f, 0.790527f, 0.805664f,
+ 0.820312f, 0.834473f, 0.846680f, 0.858887f, 0.869629f, 0.880859f, 0.890625f, 0.899902f, 0.909668f, 0.917969f, 0.964844f, 0.966797f,
+ 0.967285f, 0.965820f, 0.964844f, 0.963867f, 0.001437f, 0.004662f, 0.007919f, 0.011681f, 0.015404f, 0.019272f, 0.024261f, 0.029205f,
+ 0.034515f, 0.040619f, 0.046967f, 0.054138f, 0.061737f, 0.070496f, 0.080200f, 0.090271f, 0.101807f, 0.114136f, 0.127686f, 0.143188f,
+ 0.159058f, 0.176514f, 0.195190f, 0.215454f, 0.237305f, 0.260010f, 0.283936f, 0.309326f, 0.334717f, 0.361328f, 0.389160f, 0.416260f,
+ 0.444336f, 0.471436f, 0.499512f, 0.525879f, 0.552734f, 0.579590f, 0.604004f, 0.628906f, 0.651855f, 0.674805f, 0.696777f, 0.717773f,
+ 0.737305f, 0.755859f, 0.772949f, 0.789551f, 0.805664f, 0.819336f, 0.833984f, 0.847168f, 0.859375f, 0.871094f, 0.881836f, 0.892090f,
+ 0.902344f, 0.910156f, 0.962402f, 0.964355f, 0.964355f, 0.963867f, 0.962891f, 0.961914f, 0.001264f, 0.004036f, 0.007088f, 0.010170f,
+ 0.013672f, 0.017365f, 0.021423f, 0.025955f, 0.030533f, 0.035614f, 0.041321f, 0.047791f, 0.054626f, 0.062195f, 0.070679f, 0.080017f,
+ 0.089600f, 0.100769f, 0.112854f, 0.125977f, 0.139893f, 0.156128f, 0.172852f, 0.191650f, 0.211060f, 0.232056f, 0.254883f, 0.278076f,
+ 0.302979f, 0.328125f, 0.355225f, 0.381836f, 0.409912f, 0.437256f, 0.464844f, 0.492676f, 0.520508f, 0.547852f, 0.573242f, 0.599609f,
+ 0.625000f, 0.649414f, 0.672363f, 0.694336f, 0.714844f, 0.734863f, 0.753418f, 0.771484f, 0.788574f, 0.804688f, 0.820312f, 0.833496f,
+ 0.847656f, 0.859863f, 0.873047f, 0.883301f, 0.894043f, 0.903809f, 0.959961f, 0.961914f, 0.962402f, 0.960938f, 0.960449f, 0.959961f,
+ 0.001297f, 0.003721f, 0.006397f, 0.009308f, 0.012260f, 0.015808f, 0.019302f, 0.023010f, 0.027267f, 0.032013f, 0.037109f, 0.042419f,
+ 0.048523f, 0.054962f, 0.061920f, 0.070435f, 0.079407f, 0.088318f, 0.099121f, 0.111084f, 0.124023f, 0.137695f, 0.152832f, 0.169434f,
+ 0.187378f, 0.206421f, 0.227783f, 0.249268f, 0.272461f, 0.297363f, 0.322754f, 0.348389f, 0.376221f, 0.403809f, 0.431396f, 0.459229f,
+ 0.487305f, 0.515137f, 0.542480f, 0.569336f, 0.595215f, 0.621094f, 0.645996f, 0.669434f, 0.691406f, 0.712891f, 0.733887f, 0.753418f,
+ 0.770996f, 0.789062f, 0.805176f, 0.820801f, 0.835449f, 0.849121f, 0.861328f, 0.874512f, 0.885742f, 0.895508f, 0.956543f, 0.959473f,
+ 0.958984f, 0.958984f, 0.958008f, 0.957031f, 0.001267f, 0.003481f, 0.005955f, 0.008568f, 0.011185f, 0.014030f, 0.017151f, 0.020294f,
+ 0.024246f, 0.028427f, 0.032654f, 0.037476f, 0.042603f, 0.048523f, 0.054871f, 0.062408f, 0.070129f, 0.078552f, 0.087769f, 0.097534f,
+ 0.109192f, 0.121399f, 0.135010f, 0.150513f, 0.165894f, 0.183960f, 0.202881f, 0.222656f, 0.244385f, 0.267334f, 0.291260f, 0.317139f,
+ 0.343506f, 0.370605f, 0.397949f, 0.426025f, 0.454346f, 0.482666f, 0.511230f, 0.538086f, 0.565918f, 0.592285f, 0.618164f, 0.642578f,
+ 0.667480f, 0.690918f, 0.711914f, 0.732910f, 0.752930f, 0.771484f, 0.790039f, 0.806641f, 0.821777f, 0.837402f, 0.850586f, 0.864746f,
+ 0.875977f, 0.887695f, 0.953613f, 0.956543f, 0.957031f, 0.956055f, 0.956055f, 0.955078f, 0.001068f, 0.003025f, 0.005283f, 0.007442f,
+ 0.009857f, 0.012665f, 0.015930f, 0.018570f, 0.021820f, 0.025314f, 0.028931f, 0.033325f, 0.038147f, 0.042908f, 0.049011f, 0.055176f,
+ 0.061859f, 0.069397f, 0.077637f, 0.086792f, 0.096252f, 0.107117f, 0.119385f, 0.132690f, 0.147095f, 0.162720f, 0.180054f, 0.198486f,
+ 0.218384f, 0.239990f, 0.262207f, 0.287109f, 0.311523f, 0.337891f, 0.364990f, 0.392822f, 0.420654f, 0.449219f, 0.478027f, 0.505859f,
+ 0.535156f, 0.562012f, 0.588867f, 0.615723f, 0.641602f, 0.666016f, 0.688965f, 0.711914f, 0.732910f, 0.753906f, 0.773438f, 0.791016f,
+ 0.808594f, 0.823730f, 0.839355f, 0.854004f, 0.867188f, 0.879883f, 0.950195f, 0.954102f, 0.954102f, 0.953125f, 0.952637f, 0.952148f,
+ 0.000884f, 0.003082f, 0.004631f, 0.006931f, 0.008942f, 0.011513f, 0.013779f, 0.016663f, 0.019806f, 0.022934f, 0.026215f, 0.029999f,
+ 0.033813f, 0.038544f, 0.043365f, 0.048615f, 0.054352f, 0.061005f, 0.068420f, 0.076477f, 0.085022f, 0.095032f, 0.105469f, 0.117432f,
+ 0.130127f, 0.143799f, 0.159790f, 0.176270f, 0.194580f, 0.214478f, 0.235229f, 0.257568f, 0.281982f, 0.306641f, 0.332764f, 0.359863f,
+ 0.388184f, 0.416016f, 0.445557f, 0.474854f, 0.502441f, 0.531738f, 0.559570f, 0.586914f, 0.614258f, 0.640625f, 0.665039f, 0.689453f,
+ 0.712891f, 0.734863f, 0.755371f, 0.774902f, 0.793945f, 0.810547f, 0.827637f, 0.842773f, 0.857910f, 0.871094f, 0.946777f, 0.950684f,
+ 0.951172f, 0.950684f, 0.949707f, 0.949707f, 0.000848f, 0.002630f, 0.004330f, 0.006386f, 0.008148f, 0.010437f, 0.012436f, 0.014977f,
+ 0.017731f, 0.020645f, 0.023529f, 0.026413f, 0.030289f, 0.034302f, 0.038391f, 0.043365f, 0.048737f, 0.054413f, 0.060455f, 0.067383f,
+ 0.075134f, 0.083801f, 0.093262f, 0.103821f, 0.114746f, 0.127441f, 0.140991f, 0.156372f, 0.172729f, 0.190918f, 0.210449f, 0.231201f,
+ 0.253662f, 0.277344f, 0.302734f, 0.328857f, 0.355225f, 0.384033f, 0.413086f, 0.440918f, 0.471191f, 0.500488f, 0.529785f, 0.558594f,
+ 0.586426f, 0.613770f, 0.640137f, 0.666016f, 0.689453f, 0.714355f, 0.736328f, 0.757812f, 0.777832f, 0.796875f, 0.813965f, 0.831543f,
+ 0.847168f, 0.860840f, 0.943848f, 0.948242f, 0.947754f, 0.948242f, 0.946777f, 0.946777f, 0.000747f, 0.002462f, 0.004192f, 0.005573f,
+ 0.007454f, 0.009430f, 0.011253f, 0.013588f, 0.015762f, 0.018112f, 0.020859f, 0.023758f, 0.027084f, 0.030426f, 0.034332f, 0.038635f,
+ 0.042999f, 0.048340f, 0.053772f, 0.060028f, 0.066589f, 0.074402f, 0.082764f, 0.091553f, 0.101685f, 0.112854f, 0.125122f, 0.138184f,
+ 0.153320f, 0.169556f, 0.187500f, 0.206543f, 0.227539f, 0.249512f, 0.273193f, 0.298340f, 0.324463f, 0.351562f, 0.379883f, 0.409424f,
+ 0.438477f, 0.468750f, 0.498047f, 0.527832f, 0.556641f, 0.585449f, 0.614258f, 0.641113f, 0.666992f, 0.692383f, 0.716309f, 0.738281f,
+ 0.760742f, 0.780273f, 0.799805f, 0.818848f, 0.834473f, 0.851074f, 0.939941f, 0.944824f, 0.944336f, 0.944336f, 0.944336f, 0.943359f,
+ 0.000670f, 0.002079f, 0.003538f, 0.005146f, 0.006508f, 0.008247f, 0.010223f, 0.012260f, 0.014153f, 0.016479f, 0.018677f, 0.021515f,
+ 0.024323f, 0.027313f, 0.030518f, 0.034302f, 0.038422f, 0.042725f, 0.047760f, 0.053101f, 0.059113f, 0.065613f, 0.072937f, 0.080444f,
+ 0.089722f, 0.099426f, 0.110596f, 0.122314f, 0.135742f, 0.150513f, 0.166260f, 0.183716f, 0.202759f, 0.223633f, 0.245728f, 0.269287f,
+ 0.294189f, 0.320557f, 0.348633f, 0.376709f, 0.406494f, 0.436523f, 0.467285f, 0.497070f, 0.528320f, 0.557129f, 0.586426f, 0.614746f,
+ 0.642090f, 0.668945f, 0.694824f, 0.718750f, 0.742676f, 0.764648f, 0.786133f, 0.805176f, 0.823242f, 0.840820f, 0.936035f, 0.940918f,
+ 0.941406f, 0.941406f, 0.940430f, 0.939941f, 0.000645f, 0.001963f, 0.003384f, 0.004719f, 0.006042f, 0.007614f, 0.009384f, 0.011192f,
+ 0.012665f, 0.015083f, 0.016861f, 0.019165f, 0.021393f, 0.024445f, 0.027451f, 0.030716f, 0.034149f, 0.038116f, 0.042389f, 0.047028f,
+ 0.052277f, 0.058014f, 0.064270f, 0.071289f, 0.079041f, 0.087830f, 0.097351f, 0.108337f, 0.119995f, 0.132812f, 0.147217f, 0.163452f,
+ 0.180420f, 0.199585f, 0.219849f, 0.242065f, 0.265625f, 0.291260f, 0.318115f, 0.345703f, 0.375000f, 0.404541f, 0.434326f, 0.465820f,
+ 0.496582f, 0.526855f, 0.557617f, 0.587402f, 0.616699f, 0.645508f, 0.672363f, 0.698242f, 0.723145f, 0.747559f, 0.770020f, 0.791504f,
+ 0.810059f, 0.828613f, 0.931641f, 0.937012f, 0.937500f, 0.937500f, 0.937012f, 0.936523f, 0.000692f, 0.001705f, 0.003000f, 0.004238f,
+ 0.005798f, 0.006805f, 0.008659f, 0.009933f, 0.011681f, 0.013191f, 0.015259f, 0.017166f, 0.019379f, 0.021729f, 0.024796f, 0.027328f,
+ 0.030380f, 0.033661f, 0.037598f, 0.041718f, 0.046539f, 0.051270f, 0.056946f, 0.062988f, 0.069885f, 0.077271f, 0.085999f, 0.095398f,
+ 0.105652f, 0.117859f, 0.129883f, 0.144409f, 0.159912f, 0.177002f, 0.196045f, 0.216553f, 0.239014f, 0.262451f, 0.288086f, 0.314941f,
+ 0.343262f, 0.372314f, 0.403076f, 0.433594f, 0.465332f, 0.496826f, 0.527832f, 0.559082f, 0.589355f, 0.619629f, 0.648926f, 0.676758f,
+ 0.703125f, 0.728516f, 0.752930f, 0.775391f, 0.797363f, 0.817871f, 0.927246f, 0.933105f, 0.934082f, 0.933594f, 0.933594f, 0.933105f,
+ 0.000460f, 0.001622f, 0.002705f, 0.003983f, 0.004925f, 0.006363f, 0.007652f, 0.008965f, 0.010521f, 0.011963f, 0.013664f, 0.015480f,
+ 0.017258f, 0.019440f, 0.021912f, 0.024338f, 0.027084f, 0.030212f, 0.033356f, 0.037018f, 0.040833f, 0.045380f, 0.050110f, 0.055573f,
+ 0.061829f, 0.068359f, 0.075928f, 0.083984f, 0.093140f, 0.103333f, 0.115112f, 0.127441f, 0.141602f, 0.156982f, 0.174316f, 0.192871f,
+ 0.213257f, 0.235596f, 0.259766f, 0.285400f, 0.312256f, 0.341797f, 0.371094f, 0.402100f, 0.434082f, 0.465332f, 0.497314f, 0.529297f,
+ 0.562012f, 0.592773f, 0.623535f, 0.652832f, 0.681641f, 0.709473f, 0.735352f, 0.759766f, 0.783203f, 0.803711f, 0.922363f, 0.929199f,
+ 0.929688f, 0.929199f, 0.929688f, 0.928711f, 0.000341f, 0.001686f, 0.002537f, 0.003769f, 0.004745f, 0.005764f, 0.007034f, 0.008286f,
+ 0.009369f, 0.010742f, 0.012161f, 0.013931f, 0.015671f, 0.017563f, 0.019440f, 0.021851f, 0.024231f, 0.026672f, 0.029556f, 0.032776f,
+ 0.036255f, 0.040283f, 0.044464f, 0.049194f, 0.054413f, 0.060059f, 0.066589f, 0.074036f, 0.081909f, 0.091187f, 0.100769f, 0.112000f,
+ 0.124512f, 0.139038f, 0.154297f, 0.171265f, 0.189819f, 0.210571f, 0.232788f, 0.257324f, 0.283203f, 0.311035f, 0.339844f, 0.370850f,
+ 0.402100f, 0.433838f, 0.466797f, 0.499268f, 0.532227f, 0.565430f, 0.598145f, 0.628418f, 0.659180f, 0.687988f, 0.715820f, 0.742188f,
+ 0.767090f, 0.791504f, 0.917969f, 0.924805f, 0.925293f, 0.925293f, 0.924805f, 0.924805f, 0.000405f, 0.001282f, 0.002298f, 0.003269f,
+ 0.004448f, 0.005043f, 0.006294f, 0.007233f, 0.008606f, 0.009727f, 0.010849f, 0.012421f, 0.013885f, 0.015465f, 0.017426f, 0.019394f,
+ 0.021667f, 0.023819f, 0.026154f, 0.029175f, 0.032227f, 0.035706f, 0.039062f, 0.043427f, 0.047913f, 0.052856f, 0.058502f, 0.064880f,
+ 0.071960f, 0.079895f, 0.088867f, 0.098633f, 0.109619f, 0.122192f, 0.135742f, 0.151489f, 0.168457f, 0.187134f, 0.207764f, 0.230835f,
+ 0.254883f, 0.281494f, 0.310059f, 0.339355f, 0.370361f, 0.402588f, 0.435547f, 0.468994f, 0.502930f, 0.537109f, 0.569824f, 0.602051f,
+ 0.634766f, 0.665527f, 0.695801f, 0.724121f, 0.750488f, 0.776855f, 0.912598f, 0.919434f, 0.920410f, 0.920410f, 0.919922f, 0.920410f,
+ 0.000529f, 0.001217f, 0.002171f, 0.003035f, 0.003790f, 0.004784f, 0.005711f, 0.006756f, 0.007782f, 0.008987f, 0.009773f, 0.011185f,
+ 0.012650f, 0.013771f, 0.015656f, 0.017181f, 0.018890f, 0.021057f, 0.023239f, 0.025848f, 0.028488f, 0.031525f, 0.034607f, 0.038147f,
+ 0.042023f, 0.046539f, 0.051605f, 0.056793f, 0.063049f, 0.069946f, 0.078064f, 0.086548f, 0.096313f, 0.107117f, 0.119446f, 0.133301f,
+ 0.148560f, 0.165405f, 0.184570f, 0.205811f, 0.228394f, 0.253174f, 0.280029f, 0.308594f, 0.339111f, 0.370605f, 0.404053f, 0.437988f,
+ 0.471680f, 0.506348f, 0.541504f, 0.576172f, 0.609375f, 0.642578f, 0.674316f, 0.705078f, 0.734375f, 0.761719f, 0.907227f, 0.914062f,
+ 0.915527f, 0.915527f, 0.916016f, 0.915039f, 0.000402f, 0.001247f, 0.001841f, 0.002651f, 0.003414f, 0.004200f, 0.005337f, 0.005821f,
+ 0.006733f, 0.008041f, 0.008942f, 0.010201f, 0.011261f, 0.012749f, 0.013893f, 0.015472f, 0.016663f, 0.018829f, 0.020615f, 0.022873f,
+ 0.025299f, 0.027893f, 0.030533f, 0.033600f, 0.037140f, 0.040924f, 0.044983f, 0.049927f, 0.055359f, 0.061340f, 0.068176f, 0.075500f,
+ 0.084106f, 0.093933f, 0.104370f, 0.116638f, 0.130249f, 0.145996f, 0.162842f, 0.181885f, 0.203735f, 0.226562f, 0.251465f, 0.279297f,
+ 0.308594f, 0.339355f, 0.373047f, 0.406982f, 0.440918f, 0.477051f, 0.511719f, 0.548340f, 0.583496f, 0.618164f, 0.652344f, 0.684570f,
+ 0.715332f, 0.745605f, 0.901855f, 0.909180f, 0.910156f, 0.910645f, 0.910156f, 0.910156f, 0.000371f, 0.001090f, 0.001752f, 0.002409f,
+ 0.003042f, 0.003963f, 0.004898f, 0.005295f, 0.006077f, 0.006992f, 0.008102f, 0.009338f, 0.010101f, 0.011078f, 0.012375f, 0.013718f,
+ 0.015099f, 0.016403f, 0.018402f, 0.020203f, 0.022354f, 0.024475f, 0.026825f, 0.029388f, 0.032623f, 0.035522f, 0.039429f, 0.043762f,
+ 0.048462f, 0.053558f, 0.059265f, 0.065552f, 0.073120f, 0.081787f, 0.091431f, 0.102112f, 0.114136f, 0.127930f, 0.143066f, 0.160767f,
+ 0.179810f, 0.200928f, 0.224854f, 0.250732f, 0.279053f, 0.308838f, 0.340820f, 0.374756f, 0.410156f, 0.446045f, 0.482666f, 0.520020f,
+ 0.556152f, 0.593262f, 0.628906f, 0.663574f, 0.695801f, 0.728027f, 0.895508f, 0.903809f, 0.904297f, 0.904297f, 0.904297f, 0.904785f,
+ 0.000425f, 0.000937f, 0.001529f, 0.002129f, 0.002674f, 0.003696f, 0.004257f, 0.004990f, 0.005726f, 0.006161f, 0.007118f, 0.007919f,
+ 0.009109f, 0.009941f, 0.011055f, 0.011993f, 0.013191f, 0.014832f, 0.016281f, 0.017868f, 0.019562f, 0.021362f, 0.023514f, 0.025909f,
+ 0.028549f, 0.031189f, 0.034637f, 0.037994f, 0.042145f, 0.046570f, 0.051453f, 0.057129f, 0.063965f, 0.070984f, 0.079285f, 0.088806f,
+ 0.099426f, 0.111267f, 0.125366f, 0.140747f, 0.158203f, 0.178101f, 0.199585f, 0.223755f, 0.250732f, 0.279297f, 0.310059f, 0.343994f,
+ 0.377686f, 0.414307f, 0.451904f, 0.489258f, 0.527832f, 0.565918f, 0.603027f, 0.640137f, 0.675781f, 0.710449f, 0.888672f, 0.897461f,
+ 0.899902f, 0.900391f, 0.899414f, 0.899414f, 0.000317f, 0.000823f, 0.001386f, 0.002108f, 0.002684f, 0.003239f, 0.003883f, 0.004303f,
+ 0.004730f, 0.005569f, 0.006626f, 0.007214f, 0.008003f, 0.008865f, 0.009590f, 0.010948f, 0.011856f, 0.012871f, 0.014381f, 0.015640f,
+ 0.017075f, 0.018799f, 0.020569f, 0.022537f, 0.024704f, 0.027405f, 0.030090f, 0.033142f, 0.036346f, 0.040436f, 0.044830f, 0.049835f,
+ 0.055450f, 0.061584f, 0.068665f, 0.076904f, 0.086060f, 0.096741f, 0.109192f, 0.122559f, 0.138428f, 0.155762f, 0.176270f, 0.198242f,
+ 0.223145f, 0.250244f, 0.280518f, 0.312500f, 0.346680f, 0.382324f, 0.420410f, 0.458740f, 0.498779f, 0.538086f, 0.577637f, 0.616211f,
+ 0.654297f, 0.690918f, 0.881348f, 0.890625f, 0.892578f, 0.893066f, 0.893066f, 0.892578f, 0.000385f, 0.000766f, 0.001544f, 0.001925f,
+ 0.002359f, 0.002947f, 0.003176f, 0.003691f, 0.004288f, 0.005215f, 0.005917f, 0.006214f, 0.007019f, 0.007843f, 0.008469f, 0.009598f,
+ 0.010345f, 0.011559f, 0.012497f, 0.013634f, 0.014992f, 0.016373f, 0.017853f, 0.019608f, 0.021515f, 0.023788f, 0.026260f, 0.028931f,
+ 0.031860f, 0.034912f, 0.038635f, 0.042633f, 0.047638f, 0.053070f, 0.059540f, 0.066284f, 0.074524f, 0.083679f, 0.094177f, 0.106445f,
+ 0.120361f, 0.135620f, 0.154053f, 0.174072f, 0.197144f, 0.222900f, 0.251221f, 0.281982f, 0.315430f, 0.351318f, 0.388672f, 0.427734f,
+ 0.468506f, 0.508301f, 0.549805f, 0.591309f, 0.631348f, 0.670410f, 0.874512f, 0.884766f, 0.885742f, 0.886230f, 0.886230f, 0.886230f,
+ 0.000230f, 0.000832f, 0.001281f, 0.001865f, 0.002207f, 0.002605f, 0.003212f, 0.003284f, 0.004124f, 0.004597f, 0.005222f, 0.005703f,
+ 0.006260f, 0.007095f, 0.007790f, 0.008377f, 0.009010f, 0.010078f, 0.011009f, 0.011925f, 0.013153f, 0.014282f, 0.015610f, 0.017151f,
+ 0.018951f, 0.020416f, 0.022583f, 0.024826f, 0.027328f, 0.030136f, 0.033508f, 0.036835f, 0.040985f, 0.045410f, 0.050812f, 0.056854f,
+ 0.063965f, 0.071777f, 0.081177f, 0.091858f, 0.103699f, 0.117615f, 0.133423f, 0.152588f, 0.172974f, 0.196777f, 0.222900f, 0.252686f,
+ 0.284912f, 0.319824f, 0.356934f, 0.395996f, 0.436768f, 0.478516f, 0.521484f, 0.564453f, 0.607422f, 0.649414f, 0.866699f, 0.876953f,
+ 0.877930f, 0.879395f, 0.879883f, 0.878418f, 0.000228f, 0.000734f, 0.000993f, 0.001416f, 0.001935f, 0.002293f, 0.002541f, 0.003174f,
+ 0.003508f, 0.004040f, 0.004337f, 0.005039f, 0.005505f, 0.006054f, 0.006840f, 0.007366f, 0.008041f, 0.008644f, 0.009544f, 0.010460f,
+ 0.011238f, 0.012329f, 0.013542f, 0.014755f, 0.016083f, 0.017624f, 0.019424f, 0.021408f, 0.023422f, 0.025803f, 0.028366f, 0.031311f,
+ 0.034912f, 0.039124f, 0.043304f, 0.048492f, 0.054291f, 0.061188f, 0.069397f, 0.078552f, 0.089233f, 0.101074f, 0.115540f, 0.131226f,
+ 0.150757f, 0.172119f, 0.196533f, 0.224243f, 0.254883f, 0.288574f, 0.324707f, 0.364014f, 0.405029f, 0.447510f, 0.491699f, 0.536133f,
+ 0.581543f, 0.627441f, 0.858398f, 0.869141f, 0.870605f, 0.871582f, 0.871094f, 0.871582f, 0.000118f, 0.000713f, 0.000985f, 0.001328f,
+ 0.001612f, 0.001999f, 0.002399f, 0.002913f, 0.003139f, 0.003567f, 0.004055f, 0.004406f, 0.004986f, 0.005226f, 0.005856f, 0.006332f,
+ 0.007042f, 0.007553f, 0.008286f, 0.009064f, 0.009834f, 0.010696f, 0.011658f, 0.012726f, 0.013817f, 0.015289f, 0.016693f, 0.018265f,
+ 0.019699f, 0.021835f, 0.024307f, 0.026642f, 0.029770f, 0.033234f, 0.037048f, 0.041351f, 0.046478f, 0.052032f, 0.058960f, 0.066589f,
+ 0.075745f, 0.086182f, 0.099121f, 0.113037f, 0.129517f, 0.149048f, 0.171387f, 0.196899f, 0.225464f, 0.257812f, 0.293457f, 0.331787f,
+ 0.373291f, 0.416748f, 0.460938f, 0.507812f, 0.554688f, 0.602051f, 0.849609f, 0.859863f, 0.862793f, 0.863281f, 0.862793f, 0.862793f,
+ 0.000211f, 0.000522f, 0.000877f, 0.001204f, 0.001507f, 0.001724f, 0.002062f, 0.002426f, 0.002867f, 0.003157f, 0.003443f, 0.003752f,
+ 0.004192f, 0.004753f, 0.005154f, 0.005428f, 0.006065f, 0.006546f, 0.007210f, 0.007725f, 0.008530f, 0.009247f, 0.010025f, 0.010887f,
+ 0.011909f, 0.012970f, 0.014069f, 0.015335f, 0.017105f, 0.018433f, 0.020554f, 0.022552f, 0.025116f, 0.027802f, 0.031158f, 0.034485f,
+ 0.038971f, 0.044037f, 0.049469f, 0.055847f, 0.063843f, 0.072815f, 0.083618f, 0.095947f, 0.110840f, 0.128174f, 0.147949f, 0.171387f,
+ 0.198242f, 0.228271f, 0.262207f, 0.299805f, 0.340332f, 0.384277f, 0.430176f, 0.477295f, 0.527344f, 0.577637f, 0.839844f, 0.851074f,
+ 0.853516f, 0.854492f, 0.854980f, 0.854980f, 0.000218f, 0.000479f, 0.000706f, 0.001109f, 0.001245f, 0.001763f, 0.001800f, 0.002211f,
+ 0.002377f, 0.002783f, 0.003103f, 0.003223f, 0.003782f, 0.004089f, 0.004326f, 0.004711f, 0.005306f, 0.005569f, 0.006199f, 0.006653f,
+ 0.007168f, 0.007919f, 0.008560f, 0.009254f, 0.009979f, 0.010872f, 0.012054f, 0.012810f, 0.014221f, 0.015793f, 0.017181f, 0.018967f,
+ 0.021088f, 0.023361f, 0.026001f, 0.028915f, 0.032257f, 0.036469f, 0.040924f, 0.046875f, 0.053375f, 0.061218f, 0.070435f, 0.080811f,
+ 0.093628f, 0.108704f, 0.126709f, 0.147461f, 0.172241f, 0.199951f, 0.232788f, 0.268799f, 0.308594f, 0.351562f, 0.397705f, 0.447266f,
+ 0.498291f, 0.550293f, 0.830078f, 0.841797f, 0.843750f, 0.845215f, 0.845215f, 0.845703f, 0.000139f, 0.000379f, 0.000704f, 0.000896f,
+ 0.001095f, 0.001392f, 0.001649f, 0.002058f, 0.002235f, 0.002483f, 0.002621f, 0.002878f, 0.003214f, 0.003580f, 0.003820f, 0.004055f,
+ 0.004498f, 0.004791f, 0.005173f, 0.005692f, 0.006145f, 0.006691f, 0.007175f, 0.007874f, 0.008499f, 0.009239f, 0.010117f, 0.011032f,
+ 0.011864f, 0.012901f, 0.014282f, 0.015701f, 0.017242f, 0.019516f, 0.021469f, 0.024002f, 0.026749f, 0.029953f, 0.034027f, 0.038727f,
+ 0.044250f, 0.050568f, 0.058136f, 0.067139f, 0.078247f, 0.091614f, 0.106689f, 0.125366f, 0.147339f, 0.172974f, 0.202881f, 0.237671f,
+ 0.275879f, 0.318359f, 0.365234f, 0.415283f, 0.468018f, 0.521973f, 0.819336f, 0.832031f, 0.834473f, 0.834961f, 0.835449f, 0.835938f,
+ 0.000115f, 0.000396f, 0.000688f, 0.000885f, 0.000917f, 0.001393f, 0.001478f, 0.001590f, 0.001944f, 0.002123f, 0.002291f, 0.002644f,
+ 0.002666f, 0.003023f, 0.003197f, 0.003546f, 0.003714f, 0.004246f, 0.004551f, 0.004837f, 0.005108f, 0.005577f, 0.006054f, 0.006504f,
+ 0.007023f, 0.007633f, 0.008362f, 0.009148f, 0.009926f, 0.010742f, 0.011917f, 0.013062f, 0.014351f, 0.015991f, 0.017639f, 0.019455f,
+ 0.021729f, 0.024689f, 0.027740f, 0.031708f, 0.036102f, 0.041260f, 0.047882f, 0.055450f, 0.064392f, 0.075500f, 0.088928f, 0.104797f,
+ 0.124756f, 0.147949f, 0.175415f, 0.207275f, 0.244507f, 0.286133f, 0.332520f, 0.381836f, 0.436279f, 0.492432f, 0.808105f, 0.821289f,
+ 0.822754f, 0.824707f, 0.825195f, 0.824219f, 0.000209f, 0.000435f, 0.000493f, 0.000669f, 0.001040f, 0.001076f, 0.001254f, 0.001398f,
+ 0.001603f, 0.001697f, 0.001987f, 0.002140f, 0.002268f, 0.002472f, 0.002769f, 0.002991f, 0.003302f, 0.003572f, 0.003685f, 0.004002f,
+ 0.004337f, 0.004654f, 0.005062f, 0.005379f, 0.005871f, 0.006363f, 0.006733f, 0.007416f, 0.008102f, 0.008812f, 0.009727f, 0.010689f,
+ 0.011566f, 0.013145f, 0.014053f, 0.015762f, 0.017899f, 0.020096f, 0.022552f, 0.025528f, 0.028992f, 0.033325f, 0.038635f, 0.044952f,
+ 0.052582f, 0.061554f, 0.072998f, 0.086670f, 0.103577f, 0.124329f, 0.148804f, 0.178467f, 0.213501f, 0.253174f, 0.298828f, 0.348877f,
+ 0.403076f, 0.461914f, 0.795898f, 0.809570f, 0.812012f, 0.813477f, 0.813477f, 0.814453f, 0.000243f, 0.000322f, 0.000466f, 0.000710f,
+ 0.000863f, 0.000942f, 0.001051f, 0.001182f, 0.001369f, 0.001451f, 0.001716f, 0.001851f, 0.001968f, 0.002192f, 0.002323f, 0.002470f,
+ 0.002773f, 0.002850f, 0.003056f, 0.003399f, 0.003624f, 0.003832f, 0.004192f, 0.004467f, 0.004955f, 0.005276f, 0.005772f, 0.006084f,
+ 0.006672f, 0.007191f, 0.007828f, 0.008720f, 0.009575f, 0.010292f, 0.011505f, 0.012535f, 0.014114f, 0.016006f, 0.017838f, 0.020462f,
+ 0.023193f, 0.026489f, 0.030807f, 0.035858f, 0.041840f, 0.049652f, 0.059174f, 0.070435f, 0.084839f, 0.102783f, 0.124146f, 0.151489f,
+ 0.183472f, 0.221802f, 0.265137f, 0.315186f, 0.369629f, 0.430664f, 0.782715f, 0.796875f, 0.799805f, 0.800293f, 0.801758f, 0.801758f,
+ 0.000119f, 0.000369f, 0.000340f, 0.000595f, 0.000667f, 0.000841f, 0.001010f, 0.001086f, 0.001179f, 0.001225f, 0.001494f, 0.001555f,
+ 0.001654f, 0.001754f, 0.001965f, 0.002142f, 0.002197f, 0.002432f, 0.002619f, 0.002811f, 0.003021f, 0.003139f, 0.003567f, 0.003708f,
+ 0.004066f, 0.004360f, 0.004612f, 0.005123f, 0.005489f, 0.005878f, 0.006306f, 0.006824f, 0.007576f, 0.008286f, 0.008949f, 0.010155f,
+ 0.011322f, 0.012756f, 0.014046f, 0.015976f, 0.018250f, 0.020874f, 0.024094f, 0.027878f, 0.032867f, 0.039154f, 0.046509f, 0.055908f,
+ 0.068054f, 0.082886f, 0.102356f, 0.125732f, 0.155029f, 0.190674f, 0.232422f, 0.281006f, 0.335693f, 0.397949f, 0.770020f, 0.783691f,
+ 0.786621f, 0.787598f, 0.788086f, 0.789551f, 0.000000f, 0.000220f, 0.000275f, 0.000562f, 0.000618f, 0.000683f, 0.000733f, 0.000761f,
+ 0.000966f, 0.001022f, 0.001184f, 0.001237f, 0.001382f, 0.001552f, 0.001688f, 0.001724f, 0.001918f, 0.002024f, 0.002115f, 0.002243f,
+ 0.002403f, 0.002718f, 0.002840f, 0.003052f, 0.003330f, 0.003508f, 0.003860f, 0.004097f, 0.004314f, 0.004719f, 0.005074f, 0.005535f,
+ 0.006058f, 0.006584f, 0.007168f, 0.007874f, 0.008759f, 0.009651f, 0.011086f, 0.012459f, 0.013992f, 0.015945f, 0.018433f, 0.021408f,
+ 0.025192f, 0.029861f, 0.035950f, 0.043396f, 0.053406f, 0.065735f, 0.082031f, 0.102234f, 0.128052f, 0.160645f, 0.200073f, 0.247192f,
+ 0.301025f, 0.363281f, 0.755371f, 0.770996f, 0.772949f, 0.773926f, 0.775879f, 0.775879f, 0.000216f, 0.000102f, 0.000381f, 0.000487f,
+ 0.000429f, 0.000552f, 0.000579f, 0.000788f, 0.000804f, 0.000854f, 0.000937f, 0.000996f, 0.001078f, 0.001218f, 0.001315f, 0.001499f,
+ 0.001532f, 0.001642f, 0.001805f, 0.001825f, 0.002077f, 0.002178f, 0.002312f, 0.002396f, 0.002575f, 0.002735f, 0.002947f, 0.003317f,
+ 0.003428f, 0.003721f, 0.004185f, 0.004379f, 0.004704f, 0.005253f, 0.005650f, 0.006145f, 0.006870f, 0.007515f, 0.008415f, 0.009430f,
+ 0.010612f, 0.012093f, 0.013954f, 0.016052f, 0.018967f, 0.022476f, 0.027115f, 0.032898f, 0.040649f, 0.050690f, 0.063599f, 0.080811f,
+ 0.103210f, 0.132202f, 0.168823f, 0.213501f, 0.266602f, 0.329102f, 0.740234f, 0.756348f, 0.758789f, 0.760254f, 0.761230f, 0.761230f,
+ 0.000179f, 0.000181f, 0.000180f, 0.000289f, 0.000413f, 0.000458f, 0.000497f, 0.000620f, 0.000646f, 0.000688f, 0.000830f, 0.000868f,
+ 0.000904f, 0.000981f, 0.001024f, 0.001178f, 0.001146f, 0.001302f, 0.001382f, 0.001523f, 0.001679f, 0.001737f, 0.001824f, 0.001959f,
+ 0.002195f, 0.002283f, 0.002438f, 0.002579f, 0.002703f, 0.002939f, 0.003181f, 0.003454f, 0.003677f, 0.004051f, 0.004395f, 0.004738f,
+ 0.005283f, 0.005783f, 0.006420f, 0.007095f, 0.007988f, 0.009094f, 0.010384f, 0.011955f, 0.013939f, 0.016434f, 0.019836f, 0.024292f,
+ 0.030029f, 0.037659f, 0.048065f, 0.061890f, 0.080811f, 0.105774f, 0.138672f, 0.180542f, 0.231934f, 0.293213f, 0.724121f, 0.740234f,
+ 0.744141f, 0.745117f, 0.745605f, 0.746094f, 0.000000f, 0.000056f, 0.000263f, 0.000339f, 0.000369f, 0.000357f, 0.000376f, 0.000508f,
+ 0.000519f, 0.000558f, 0.000581f, 0.000678f, 0.000767f, 0.000775f, 0.000905f, 0.000849f, 0.000992f, 0.000942f, 0.001192f, 0.001169f,
+ 0.001204f, 0.001375f, 0.001439f, 0.001532f, 0.001634f, 0.001676f, 0.001799f, 0.001904f, 0.002165f, 0.002262f, 0.002377f, 0.002611f,
+ 0.002836f, 0.003103f, 0.003321f, 0.003550f, 0.004005f, 0.004356f, 0.004772f, 0.005295f, 0.005962f, 0.006756f, 0.007690f, 0.008690f,
+ 0.010078f, 0.011871f, 0.014252f, 0.017242f, 0.021393f, 0.027100f, 0.034851f, 0.046051f, 0.060455f, 0.081848f, 0.110474f, 0.148682f,
+ 0.197632f, 0.257568f, 0.706543f, 0.724121f, 0.727539f, 0.729492f, 0.729980f, 0.729492f, 0.000000f, 0.000130f, 0.000174f, 0.000312f,
+ 0.000290f, 0.000293f, 0.000372f, 0.000319f, 0.000397f, 0.000433f, 0.000550f, 0.000552f, 0.000564f, 0.000593f, 0.000638f, 0.000758f,
+ 0.000784f, 0.000797f, 0.000842f, 0.000937f, 0.001011f, 0.001068f, 0.001125f, 0.001231f, 0.001228f, 0.001288f, 0.001409f, 0.001465f,
+ 0.001644f, 0.001697f, 0.001965f, 0.001924f, 0.002136f, 0.002270f, 0.002436f, 0.002697f, 0.002916f, 0.003202f, 0.003492f, 0.003929f,
+ 0.004391f, 0.004887f, 0.005516f, 0.006233f, 0.007240f, 0.008461f, 0.010094f, 0.012070f, 0.014854f, 0.018585f, 0.024338f, 0.032379f,
+ 0.043884f, 0.060516f, 0.084656f, 0.118469f, 0.164185f, 0.222168f, 0.689941f, 0.708008f, 0.710449f, 0.711914f, 0.712891f, 0.712402f,
+ 0.000000f, 0.000000f, 0.000122f, 0.000226f, 0.000145f, 0.000282f, 0.000255f, 0.000247f, 0.000323f, 0.000389f, 0.000379f, 0.000435f,
+ 0.000461f, 0.000509f, 0.000535f, 0.000517f, 0.000557f, 0.000604f, 0.000649f, 0.000690f, 0.000757f, 0.000773f, 0.000836f, 0.000865f,
+ 0.000924f, 0.000957f, 0.001095f, 0.001104f, 0.001243f, 0.001361f, 0.001458f, 0.001486f, 0.001619f, 0.001745f, 0.001791f, 0.001993f,
+ 0.002100f, 0.002321f, 0.002539f, 0.002771f, 0.003084f, 0.003412f, 0.003866f, 0.004368f, 0.005062f, 0.005821f, 0.006882f, 0.008278f,
+ 0.010071f, 0.012756f, 0.016327f, 0.021774f, 0.029785f, 0.042206f, 0.061462f, 0.090149f, 0.131348f, 0.187378f, 0.669434f, 0.688965f,
+ 0.692383f, 0.694824f, 0.695801f, 0.695312f, 0.000000f, 0.000118f, 0.000113f, 0.000158f, 0.000158f, 0.000176f, 0.000224f, 0.000202f,
+ 0.000251f, 0.000260f, 0.000280f, 0.000332f, 0.000316f, 0.000365f, 0.000389f, 0.000419f, 0.000454f, 0.000435f, 0.000476f, 0.000494f,
+ 0.000516f, 0.000576f, 0.000609f, 0.000656f, 0.000678f, 0.000712f, 0.000792f, 0.000800f, 0.000852f, 0.000919f, 0.000961f, 0.001070f,
+ 0.001120f, 0.001238f, 0.001300f, 0.001480f, 0.001459f, 0.001634f, 0.001798f, 0.001947f, 0.002111f, 0.002377f, 0.002615f, 0.002966f,
+ 0.003410f, 0.003933f, 0.004585f, 0.005489f, 0.006706f, 0.008148f, 0.010757f, 0.013962f, 0.019257f, 0.027771f, 0.041931f, 0.065125f,
+ 0.101135f, 0.152832f, 0.650391f, 0.670898f, 0.674316f, 0.675293f, 0.675781f, 0.677246f, 0.000000f, 0.000000f, 0.000109f, 0.000106f,
+ 0.000121f, 0.000117f, 0.000130f, 0.000151f, 0.000161f, 0.000174f, 0.000234f, 0.000197f, 0.000205f, 0.000236f, 0.000272f, 0.000296f,
+ 0.000267f, 0.000296f, 0.000397f, 0.000344f, 0.000413f, 0.000395f, 0.000433f, 0.000434f, 0.000504f, 0.000488f, 0.000532f, 0.000550f,
+ 0.000602f, 0.000711f, 0.000675f, 0.000704f, 0.000752f, 0.000817f, 0.000896f, 0.000955f, 0.001009f, 0.001091f, 0.001223f, 0.001271f,
+ 0.001415f, 0.001560f, 0.001721f, 0.001989f, 0.002214f, 0.002508f, 0.002930f, 0.003504f, 0.004208f, 0.005169f, 0.006603f, 0.008606f,
+ 0.011864f, 0.017090f, 0.026367f, 0.043396f, 0.072571f, 0.119751f, 0.630859f, 0.650879f, 0.653809f, 0.656250f, 0.657227f, 0.657227f,
+ 0.000000f, 0.000111f, 0.000104f, 0.000100f, 0.000096f, 0.000094f, 0.000105f, 0.000096f, 0.000101f, 0.000115f, 0.000119f, 0.000155f,
+ 0.000129f, 0.000180f, 0.000186f, 0.000199f, 0.000208f, 0.000214f, 0.000232f, 0.000230f, 0.000237f, 0.000247f, 0.000303f, 0.000276f,
+ 0.000324f, 0.000332f, 0.000381f, 0.000371f, 0.000393f, 0.000428f, 0.000490f, 0.000468f, 0.000512f, 0.000540f, 0.000598f, 0.000670f,
+ 0.000673f, 0.000711f, 0.000767f, 0.000842f, 0.000894f, 0.000985f, 0.001120f, 0.001200f, 0.001416f, 0.001544f, 0.001768f, 0.002052f,
+ 0.002510f, 0.003044f, 0.003796f, 0.005016f, 0.006870f, 0.009918f, 0.015335f, 0.026077f, 0.048004f, 0.088745f, 0.610352f, 0.630859f,
+ 0.634277f, 0.636230f, 0.637207f, 0.638184f, 0.000000f, 0.000104f, 0.000098f, 0.000092f, 0.000087f, 0.000084f, 0.000081f, 0.000078f,
+ 0.000074f, 0.000070f, 0.000073f, 0.000075f, 0.000081f, 0.000081f, 0.000119f, 0.000124f, 0.000129f, 0.000115f, 0.000142f, 0.000169f,
+ 0.000155f, 0.000169f, 0.000172f, 0.000196f, 0.000209f, 0.000211f, 0.000203f, 0.000238f, 0.000245f, 0.000260f, 0.000282f, 0.000281f,
+ 0.000297f, 0.000333f, 0.000343f, 0.000374f, 0.000398f, 0.000428f, 0.000473f, 0.000494f, 0.000534f, 0.000591f, 0.000643f, 0.000708f,
+ 0.000790f, 0.000893f, 0.001040f, 0.001169f, 0.001381f, 0.001676f, 0.002123f, 0.002686f, 0.003658f, 0.005329f, 0.008347f, 0.014244f,
+ 0.027954f, 0.060638f, 0.587891f, 0.609375f, 0.613281f, 0.614746f, 0.616699f, 0.616211f, 0.000110f, 0.000094f, 0.000085f, 0.000079f,
+ 0.000075f, 0.000072f, 0.000069f, 0.000067f, 0.000065f, 0.000063f, 0.000059f, 0.000059f, 0.000054f, 0.000051f, 0.000055f, 0.000051f,
+ 0.000066f, 0.000066f, 0.000078f, 0.000074f, 0.000089f, 0.000091f, 0.000102f, 0.000109f, 0.000114f, 0.000126f, 0.000133f, 0.000130f,
+ 0.000141f, 0.000141f, 0.000156f, 0.000172f, 0.000180f, 0.000179f, 0.000206f, 0.000199f, 0.000214f, 0.000254f, 0.000247f, 0.000282f,
+ 0.000300f, 0.000324f, 0.000349f, 0.000374f, 0.000413f, 0.000459f, 0.000513f, 0.000619f, 0.000711f, 0.000823f, 0.001030f, 0.001269f,
+ 0.001724f, 0.002487f, 0.003948f, 0.007015f, 0.014122f, 0.036346f, 0.565430f, 0.586426f, 0.592285f, 0.592773f, 0.594238f, 0.594727f,
+ 0.000092f, 0.000073f, 0.000067f, 0.000062f, 0.000057f, 0.000055f, 0.000052f, 0.000052f, 0.000049f, 0.000049f, 0.000047f, 0.000046f,
+ 0.000046f, 0.000043f, 0.000041f, 0.000039f, 0.000038f, 0.000036f, 0.000039f, 0.000036f, 0.000039f, 0.000037f, 0.000039f, 0.000047f,
+ 0.000051f, 0.000057f, 0.000059f, 0.000060f, 0.000067f, 0.000071f, 0.000078f, 0.000085f, 0.000087f, 0.000091f, 0.000098f, 0.000095f,
+ 0.000102f, 0.000122f, 0.000122f, 0.000137f, 0.000143f, 0.000145f, 0.000168f, 0.000171f, 0.000197f, 0.000209f, 0.000234f, 0.000264f,
+ 0.000295f, 0.000349f, 0.000418f, 0.000520f, 0.000678f, 0.000958f, 0.001512f, 0.002745f, 0.006092f, 0.017456f, 0.542969f, 0.565430f,
+ 0.568848f, 0.569824f, 0.572266f, 0.572266f, 0.000052f, 0.000042f, 0.000037f, 0.000035f, 0.000033f, 0.000033f, 0.000032f, 0.000031f,
+ 0.000031f, 0.000029f, 0.000030f, 0.000030f, 0.000029f, 0.000028f, 0.000028f, 0.000028f, 0.000028f, 0.000028f, 0.000027f, 0.000026f,
+ 0.000024f, 0.000023f, 0.000022f, 0.000022f, 0.000021f, 0.000020f, 0.000019f, 0.000022f, 0.000020f, 0.000023f, 0.000024f, 0.000026f,
+ 0.000028f, 0.000035f, 0.000037f, 0.000038f, 0.000039f, 0.000043f, 0.000048f, 0.000050f, 0.000053f, 0.000055f, 0.000062f, 0.000059f,
+ 0.000072f, 0.000070f, 0.000087f, 0.000099f, 0.000100f, 0.000119f, 0.000142f, 0.000162f, 0.000217f, 0.000283f, 0.000425f, 0.000760f,
+ 0.001818f, 0.006405f, 0.519043f, 0.541504f, 0.546387f, 0.548828f, 0.549316f, 0.550781f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000004f, 0.000004f, 0.000006f, 0.000006f, 0.000008f, 0.000009f, 0.000009f, 0.000009f, 0.000010f,
+ 0.000010f, 0.000010f, 0.000011f, 0.000011f, 0.000011f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000013f, 0.000012f, 0.000012f,
+ 0.000011f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000008f, 0.000008f, 0.000011f,
+ 0.000011f, 0.000012f, 0.000015f, 0.000016f, 0.000016f, 0.000018f, 0.000018f, 0.000020f, 0.000022f, 0.000024f, 0.000028f, 0.000035f,
+ 0.000036f, 0.000052f, 0.000071f, 0.000117f, 0.000260f, 0.001269f, 0.495605f, 0.518555f, 0.523926f, 0.525879f, 0.526855f, 0.527344f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000005f, 0.000021f, 0.473145f, 0.495605f,
+ 0.500000f, 0.502441f, 0.503418f, 0.503906f,
+ },
+ {
+ 0.045868f, 0.130493f, 0.205322f, 0.272705f, 0.331787f, 0.384521f, 0.431885f, 0.473389f, 0.511719f, 0.545898f, 0.576660f, 0.605469f,
+ 0.631348f, 0.654785f, 0.676758f, 0.696289f, 0.714355f, 0.732422f, 0.749023f, 0.763184f, 0.777832f, 0.790527f, 0.802734f, 0.813477f,
+ 0.824219f, 0.834961f, 0.844238f, 0.853027f, 0.862305f, 0.869629f, 0.877441f, 0.884277f, 0.892090f, 0.898926f, 0.904297f, 0.910645f,
+ 0.916992f, 0.921875f, 0.926758f, 0.931641f, 0.937012f, 0.941406f, 0.945801f, 0.950195f, 0.954102f, 0.958496f, 0.962402f, 0.966309f,
+ 0.969238f, 0.973145f, 0.976074f, 0.979492f, 0.982422f, 0.985352f, 0.988281f, 0.991211f, 0.993652f, 0.996094f, 0.997070f, 0.993164f,
+ 0.990234f, 0.987305f, 0.984375f, 0.981445f, 0.033447f, 0.097717f, 0.160400f, 0.219238f, 0.273438f, 0.323486f, 0.371582f, 0.414062f,
+ 0.454834f, 0.491211f, 0.524414f, 0.555176f, 0.583984f, 0.610840f, 0.635254f, 0.658203f, 0.678223f, 0.697754f, 0.716309f, 0.732422f,
+ 0.749023f, 0.763184f, 0.776855f, 0.790527f, 0.802734f, 0.812988f, 0.824707f, 0.834473f, 0.844238f, 0.853516f, 0.862305f, 0.870117f,
+ 0.877930f, 0.884766f, 0.892090f, 0.897949f, 0.905762f, 0.910645f, 0.917480f, 0.923340f, 0.927734f, 0.933105f, 0.937988f, 0.942871f,
+ 0.947266f, 0.951172f, 0.955566f, 0.960449f, 0.963379f, 0.967285f, 0.970703f, 0.974609f, 0.978027f, 0.981445f, 0.984863f, 0.986816f,
+ 0.989746f, 0.993164f, 0.995605f, 0.992188f, 0.988770f, 0.986328f, 0.983398f, 0.980957f, 0.024796f, 0.075195f, 0.126221f, 0.176025f,
+ 0.224976f, 0.271729f, 0.317383f, 0.359375f, 0.399902f, 0.437744f, 0.472656f, 0.505371f, 0.536133f, 0.565430f, 0.591797f, 0.615723f,
+ 0.639648f, 0.660156f, 0.681152f, 0.699219f, 0.718262f, 0.734375f, 0.749512f, 0.764648f, 0.777832f, 0.791016f, 0.802734f, 0.813965f,
+ 0.825195f, 0.835449f, 0.844727f, 0.854004f, 0.862305f, 0.871094f, 0.878418f, 0.886230f, 0.893555f, 0.900391f, 0.906738f, 0.912598f,
+ 0.917969f, 0.923828f, 0.929688f, 0.935059f, 0.939941f, 0.943848f, 0.949219f, 0.953613f, 0.958008f, 0.961914f, 0.965332f, 0.969238f,
+ 0.972656f, 0.976074f, 0.979492f, 0.982910f, 0.986328f, 0.989258f, 0.993652f, 0.990723f, 0.987793f, 0.985352f, 0.982910f, 0.979980f,
+ 0.019119f, 0.058624f, 0.100220f, 0.142578f, 0.185303f, 0.227417f, 0.269287f, 0.310059f, 0.348877f, 0.385254f, 0.421875f, 0.455566f,
+ 0.489014f, 0.518555f, 0.546875f, 0.574707f, 0.598633f, 0.624023f, 0.645508f, 0.666016f, 0.684082f, 0.702637f, 0.720703f, 0.736816f,
+ 0.751465f, 0.766113f, 0.779785f, 0.792969f, 0.804199f, 0.815918f, 0.826660f, 0.836426f, 0.846191f, 0.855957f, 0.864746f, 0.872559f,
+ 0.880371f, 0.888184f, 0.895508f, 0.902344f, 0.908691f, 0.914062f, 0.919922f, 0.925293f, 0.932129f, 0.936035f, 0.941895f, 0.946289f,
+ 0.951172f, 0.955566f, 0.959473f, 0.963867f, 0.967773f, 0.970703f, 0.975586f, 0.978516f, 0.981934f, 0.985352f, 0.991699f, 0.988770f,
+ 0.986328f, 0.983887f, 0.981445f, 0.979004f, 0.015175f, 0.046997f, 0.080688f, 0.116028f, 0.152466f, 0.189819f, 0.227417f, 0.264404f,
+ 0.301758f, 0.338623f, 0.374268f, 0.407471f, 0.439941f, 0.471924f, 0.501465f, 0.529785f, 0.556641f, 0.582031f, 0.606445f, 0.629395f,
+ 0.649902f, 0.670898f, 0.688965f, 0.708496f, 0.725098f, 0.740723f, 0.755371f, 0.769531f, 0.782715f, 0.795410f, 0.807129f, 0.818848f,
+ 0.829590f, 0.839844f, 0.849121f, 0.857910f, 0.866699f, 0.875488f, 0.882812f, 0.890625f, 0.897461f, 0.904297f, 0.910645f, 0.916992f,
+ 0.922363f, 0.928223f, 0.933594f, 0.938477f, 0.944824f, 0.949707f, 0.953613f, 0.958008f, 0.962402f, 0.966309f, 0.970703f, 0.974121f,
+ 0.977539f, 0.981934f, 0.990234f, 0.987793f, 0.984863f, 0.982910f, 0.980469f, 0.978516f, 0.012215f, 0.038452f, 0.066101f, 0.095825f,
+ 0.126831f, 0.159180f, 0.192749f, 0.226685f, 0.260986f, 0.294922f, 0.328857f, 0.363037f, 0.394531f, 0.426270f, 0.457520f, 0.486572f,
+ 0.514648f, 0.541016f, 0.567871f, 0.590820f, 0.614746f, 0.636230f, 0.657227f, 0.676270f, 0.694336f, 0.711914f, 0.729492f, 0.744141f,
+ 0.759277f, 0.773438f, 0.786621f, 0.798340f, 0.811523f, 0.822266f, 0.833496f, 0.842773f, 0.851562f, 0.861816f, 0.869629f, 0.878418f,
+ 0.885742f, 0.893066f, 0.900879f, 0.907715f, 0.913574f, 0.919922f, 0.925781f, 0.932129f, 0.937012f, 0.942871f, 0.946777f, 0.951660f,
+ 0.957031f, 0.960938f, 0.965332f, 0.969727f, 0.973633f, 0.977051f, 0.988281f, 0.986328f, 0.983887f, 0.981445f, 0.979492f, 0.976562f,
+ 0.009903f, 0.031525f, 0.054626f, 0.078979f, 0.105408f, 0.133789f, 0.162720f, 0.192993f, 0.224976f, 0.256592f, 0.288330f, 0.320312f,
+ 0.352295f, 0.383545f, 0.414062f, 0.443848f, 0.473389f, 0.500488f, 0.526367f, 0.553223f, 0.577637f, 0.600586f, 0.622070f, 0.644043f,
+ 0.664551f, 0.683105f, 0.701660f, 0.718262f, 0.734375f, 0.750000f, 0.764648f, 0.778320f, 0.791016f, 0.802734f, 0.815430f, 0.826172f,
+ 0.836426f, 0.845703f, 0.855957f, 0.864258f, 0.874023f, 0.881348f, 0.889648f, 0.896973f, 0.904297f, 0.911621f, 0.917480f, 0.922852f,
+ 0.929199f, 0.935059f, 0.939941f, 0.944824f, 0.950195f, 0.954590f, 0.959961f, 0.964355f, 0.968262f, 0.972656f, 0.986328f, 0.984375f,
+ 0.981934f, 0.979980f, 0.978027f, 0.975586f, 0.008385f, 0.026154f, 0.045319f, 0.066467f, 0.089111f, 0.113220f, 0.138916f, 0.165405f,
+ 0.192871f, 0.222290f, 0.252197f, 0.281494f, 0.311279f, 0.342285f, 0.372314f, 0.402832f, 0.431641f, 0.459473f, 0.486572f, 0.513672f,
+ 0.539062f, 0.562988f, 0.587402f, 0.609863f, 0.631348f, 0.652344f, 0.671875f, 0.689941f, 0.708008f, 0.724609f, 0.740234f, 0.755371f,
+ 0.768066f, 0.783203f, 0.795410f, 0.808105f, 0.819336f, 0.830078f, 0.840332f, 0.851074f, 0.860352f, 0.869141f, 0.877930f, 0.885742f,
+ 0.893555f, 0.900879f, 0.907715f, 0.915039f, 0.920410f, 0.926758f, 0.933105f, 0.938965f, 0.944336f, 0.949707f, 0.953613f, 0.958984f,
+ 0.962891f, 0.967285f, 0.984375f, 0.982910f, 0.980957f, 0.978516f, 0.976562f, 0.974609f, 0.006992f, 0.022324f, 0.038544f, 0.056396f,
+ 0.075317f, 0.095947f, 0.117981f, 0.141968f, 0.166504f, 0.192627f, 0.219238f, 0.246704f, 0.275879f, 0.304443f, 0.333252f, 0.362305f,
+ 0.390869f, 0.419678f, 0.447266f, 0.474121f, 0.500977f, 0.525879f, 0.551270f, 0.574219f, 0.597656f, 0.620117f, 0.641602f, 0.661133f,
+ 0.680664f, 0.698242f, 0.715332f, 0.731934f, 0.746582f, 0.761230f, 0.775391f, 0.789551f, 0.802246f, 0.813477f, 0.825195f, 0.835938f,
+ 0.846191f, 0.855957f, 0.865723f, 0.873535f, 0.882324f, 0.890625f, 0.898438f, 0.905762f, 0.912598f, 0.918945f, 0.925781f, 0.931641f,
+ 0.937012f, 0.943848f, 0.948730f, 0.954102f, 0.957520f, 0.963379f, 0.981934f, 0.980957f, 0.979004f, 0.977051f, 0.975098f, 0.973145f,
+ 0.006260f, 0.018387f, 0.032684f, 0.047821f, 0.064636f, 0.082153f, 0.101318f, 0.122009f, 0.143921f, 0.166870f, 0.191406f, 0.216187f,
+ 0.243164f, 0.269287f, 0.297119f, 0.324951f, 0.352783f, 0.380859f, 0.408691f, 0.435547f, 0.462402f, 0.489258f, 0.514160f, 0.540039f,
+ 0.563965f, 0.585938f, 0.608398f, 0.629395f, 0.649414f, 0.669434f, 0.689453f, 0.705566f, 0.722656f, 0.739258f, 0.753418f, 0.769043f,
+ 0.783203f, 0.795898f, 0.807617f, 0.819824f, 0.830566f, 0.842285f, 0.852051f, 0.862305f, 0.871094f, 0.878906f, 0.888184f, 0.895996f,
+ 0.902832f, 0.910645f, 0.917480f, 0.924316f, 0.930176f, 0.936523f, 0.942383f, 0.946777f, 0.953613f, 0.958496f, 0.979980f, 0.979004f,
+ 0.977539f, 0.975586f, 0.973633f, 0.972168f, 0.005268f, 0.016418f, 0.028091f, 0.041107f, 0.055420f, 0.070435f, 0.087341f, 0.105347f,
+ 0.124512f, 0.144531f, 0.166260f, 0.189453f, 0.213989f, 0.238037f, 0.263184f, 0.290039f, 0.317139f, 0.344238f, 0.370850f, 0.398438f,
+ 0.425293f, 0.451660f, 0.477539f, 0.503418f, 0.528320f, 0.551270f, 0.576172f, 0.598145f, 0.619629f, 0.640137f, 0.659668f, 0.680176f,
+ 0.697754f, 0.714844f, 0.731934f, 0.748047f, 0.762695f, 0.776367f, 0.790039f, 0.803223f, 0.814453f, 0.827148f, 0.837891f, 0.847656f,
+ 0.858398f, 0.868164f, 0.876953f, 0.885742f, 0.893066f, 0.901855f, 0.908691f, 0.916504f, 0.922852f, 0.929199f, 0.935059f, 0.941895f,
+ 0.947754f, 0.953125f, 0.978027f, 0.977539f, 0.975586f, 0.973633f, 0.971680f, 0.969727f, 0.004372f, 0.013802f, 0.024185f, 0.036011f,
+ 0.047729f, 0.060944f, 0.075684f, 0.090820f, 0.107788f, 0.125488f, 0.144653f, 0.165771f, 0.187012f, 0.210205f, 0.233643f, 0.258545f,
+ 0.283447f, 0.309326f, 0.335449f, 0.362305f, 0.388672f, 0.415771f, 0.441650f, 0.468018f, 0.492920f, 0.518066f, 0.542480f, 0.564941f,
+ 0.587891f, 0.609863f, 0.630859f, 0.651855f, 0.670898f, 0.689453f, 0.707520f, 0.724609f, 0.740723f, 0.755859f, 0.770996f, 0.785156f,
+ 0.799316f, 0.809570f, 0.822754f, 0.834473f, 0.845215f, 0.855469f, 0.865723f, 0.874023f, 0.883301f, 0.892090f, 0.899902f, 0.907715f,
+ 0.915039f, 0.922363f, 0.928711f, 0.935059f, 0.941406f, 0.947266f, 0.975586f, 0.975098f, 0.973633f, 0.971680f, 0.969727f, 0.968262f,
+ 0.003809f, 0.012253f, 0.021240f, 0.030884f, 0.041473f, 0.052887f, 0.065308f, 0.079224f, 0.094177f, 0.109558f, 0.126709f, 0.145142f,
+ 0.163940f, 0.184814f, 0.207397f, 0.229736f, 0.252686f, 0.276855f, 0.302246f, 0.327881f, 0.353271f, 0.380127f, 0.405762f, 0.432129f,
+ 0.457520f, 0.482422f, 0.507324f, 0.531250f, 0.556152f, 0.578125f, 0.600586f, 0.622559f, 0.642578f, 0.662109f, 0.681641f, 0.700195f,
+ 0.716797f, 0.734375f, 0.750000f, 0.766113f, 0.779297f, 0.793457f, 0.807129f, 0.819336f, 0.830078f, 0.842285f, 0.853027f, 0.862793f,
+ 0.872559f, 0.881348f, 0.890625f, 0.899414f, 0.907227f, 0.914551f, 0.920898f, 0.928223f, 0.935059f, 0.941406f, 0.973633f, 0.973145f,
+ 0.971680f, 0.970215f, 0.968262f, 0.966797f, 0.003462f, 0.010796f, 0.018646f, 0.026962f, 0.036377f, 0.046173f, 0.057190f, 0.068665f,
+ 0.081726f, 0.095520f, 0.110962f, 0.127563f, 0.144897f, 0.162476f, 0.182373f, 0.202881f, 0.225342f, 0.248291f, 0.271729f, 0.294922f,
+ 0.320312f, 0.345459f, 0.370850f, 0.397217f, 0.422607f, 0.447998f, 0.473145f, 0.498291f, 0.522461f, 0.546875f, 0.569824f, 0.591797f,
+ 0.614258f, 0.635742f, 0.655273f, 0.674805f, 0.693359f, 0.711426f, 0.729492f, 0.745605f, 0.760742f, 0.775391f, 0.789551f, 0.803223f,
+ 0.816406f, 0.828125f, 0.839844f, 0.850586f, 0.861328f, 0.871094f, 0.880371f, 0.889648f, 0.898438f, 0.906250f, 0.915039f, 0.921875f,
+ 0.928223f, 0.935547f, 0.970703f, 0.970215f, 0.970215f, 0.967773f, 0.966309f, 0.965332f, 0.002872f, 0.009338f, 0.016174f, 0.024231f,
+ 0.031525f, 0.040558f, 0.050140f, 0.060455f, 0.071472f, 0.084167f, 0.097168f, 0.111450f, 0.127197f, 0.143433f, 0.160889f, 0.179565f,
+ 0.199463f, 0.220825f, 0.242554f, 0.265625f, 0.288818f, 0.312744f, 0.338135f, 0.362793f, 0.387939f, 0.414307f, 0.439453f, 0.464355f,
+ 0.489014f, 0.514648f, 0.537598f, 0.561523f, 0.583984f, 0.606445f, 0.627930f, 0.648926f, 0.667480f, 0.687988f, 0.705566f, 0.723633f,
+ 0.740234f, 0.756348f, 0.771484f, 0.786621f, 0.799805f, 0.812012f, 0.825195f, 0.836426f, 0.849121f, 0.859375f, 0.870605f, 0.879883f,
+ 0.888672f, 0.897461f, 0.905762f, 0.915039f, 0.921387f, 0.928711f, 0.967773f, 0.969238f, 0.966797f, 0.966797f, 0.964355f, 0.963379f,
+ 0.002750f, 0.008202f, 0.014519f, 0.021301f, 0.028183f, 0.035828f, 0.044342f, 0.053375f, 0.063354f, 0.074219f, 0.085876f, 0.098083f,
+ 0.111938f, 0.126343f, 0.142212f, 0.158936f, 0.177124f, 0.196411f, 0.216553f, 0.237427f, 0.260010f, 0.282715f, 0.306641f, 0.330811f,
+ 0.355957f, 0.381104f, 0.405518f, 0.431152f, 0.456543f, 0.480957f, 0.504883f, 0.529785f, 0.553223f, 0.577148f, 0.599121f, 0.620605f,
+ 0.642090f, 0.662598f, 0.682617f, 0.701172f, 0.718750f, 0.735352f, 0.751953f, 0.768066f, 0.783691f, 0.796875f, 0.810547f, 0.822754f,
+ 0.835938f, 0.847656f, 0.858398f, 0.869141f, 0.879395f, 0.888672f, 0.897949f, 0.906250f, 0.914551f, 0.922363f, 0.965820f, 0.966797f,
+ 0.965820f, 0.963867f, 0.963379f, 0.961426f, 0.002264f, 0.007446f, 0.012741f, 0.018494f, 0.024536f, 0.031769f, 0.039154f, 0.047424f,
+ 0.056122f, 0.065308f, 0.075623f, 0.087219f, 0.098755f, 0.111328f, 0.125854f, 0.140869f, 0.157349f, 0.174805f, 0.193115f, 0.212402f,
+ 0.233643f, 0.254883f, 0.276855f, 0.300293f, 0.324463f, 0.348389f, 0.374023f, 0.398193f, 0.423340f, 0.448242f, 0.473877f, 0.498291f,
+ 0.521973f, 0.545898f, 0.569824f, 0.592773f, 0.614258f, 0.635742f, 0.657227f, 0.676270f, 0.695801f, 0.714844f, 0.731445f, 0.749512f,
+ 0.765137f, 0.779785f, 0.793945f, 0.808594f, 0.821777f, 0.833496f, 0.846191f, 0.858398f, 0.868652f, 0.879395f, 0.888672f, 0.897949f,
+ 0.906738f, 0.916016f, 0.962402f, 0.963867f, 0.962891f, 0.961914f, 0.960938f, 0.958984f, 0.002377f, 0.006668f, 0.011467f, 0.016693f,
+ 0.021820f, 0.028091f, 0.034485f, 0.041748f, 0.049347f, 0.057678f, 0.066589f, 0.076538f, 0.086975f, 0.098816f, 0.111816f, 0.125366f,
+ 0.139404f, 0.155151f, 0.171875f, 0.190186f, 0.208496f, 0.228760f, 0.250244f, 0.271973f, 0.294189f, 0.317871f, 0.341797f, 0.365479f,
+ 0.391357f, 0.415771f, 0.440430f, 0.466797f, 0.491699f, 0.515625f, 0.539551f, 0.563477f, 0.585938f, 0.608887f, 0.630371f, 0.651855f,
+ 0.672363f, 0.692383f, 0.710449f, 0.729492f, 0.745605f, 0.762695f, 0.778320f, 0.792480f, 0.807129f, 0.820801f, 0.833984f, 0.846680f,
+ 0.857910f, 0.869141f, 0.879395f, 0.889648f, 0.899414f, 0.907715f, 0.959473f, 0.961426f, 0.960449f, 0.959961f, 0.958496f, 0.957031f,
+ 0.002062f, 0.006180f, 0.010201f, 0.015053f, 0.019531f, 0.025116f, 0.030960f, 0.037292f, 0.043915f, 0.051117f, 0.059570f, 0.067749f,
+ 0.076843f, 0.087708f, 0.099060f, 0.110352f, 0.123413f, 0.138062f, 0.153198f, 0.169067f, 0.186768f, 0.204956f, 0.224487f, 0.244873f,
+ 0.265625f, 0.288330f, 0.311768f, 0.335205f, 0.359863f, 0.384521f, 0.409668f, 0.434082f, 0.459717f, 0.483887f, 0.508789f, 0.533203f,
+ 0.557617f, 0.580566f, 0.603516f, 0.626465f, 0.646484f, 0.667969f, 0.687500f, 0.708008f, 0.726074f, 0.744141f, 0.760742f, 0.776367f,
+ 0.791504f, 0.806641f, 0.820312f, 0.833496f, 0.846191f, 0.858398f, 0.869629f, 0.879883f, 0.890625f, 0.900879f, 0.956543f, 0.958496f,
+ 0.958008f, 0.956543f, 0.955566f, 0.954102f, 0.001774f, 0.005459f, 0.009155f, 0.013290f, 0.017807f, 0.022537f, 0.027527f, 0.033081f,
+ 0.038818f, 0.045380f, 0.052643f, 0.060516f, 0.068420f, 0.077942f, 0.087952f, 0.098572f, 0.109863f, 0.122925f, 0.136230f, 0.150146f,
+ 0.166382f, 0.183105f, 0.201172f, 0.219482f, 0.240112f, 0.261230f, 0.283203f, 0.305664f, 0.329590f, 0.353027f, 0.377930f, 0.402344f,
+ 0.427490f, 0.453369f, 0.478516f, 0.502930f, 0.527832f, 0.552246f, 0.575684f, 0.598145f, 0.621094f, 0.643555f, 0.664551f, 0.685547f,
+ 0.704590f, 0.723633f, 0.742188f, 0.759277f, 0.775879f, 0.791016f, 0.806152f, 0.820801f, 0.833496f, 0.847168f, 0.859375f, 0.870605f,
+ 0.881348f, 0.893066f, 0.953125f, 0.956055f, 0.955566f, 0.954102f, 0.953125f, 0.951660f, 0.001655f, 0.004757f, 0.008308f, 0.011993f,
+ 0.015808f, 0.020187f, 0.024780f, 0.029434f, 0.034851f, 0.040741f, 0.046997f, 0.053650f, 0.061096f, 0.069397f, 0.078064f, 0.087280f,
+ 0.097351f, 0.108887f, 0.121033f, 0.134277f, 0.148560f, 0.163330f, 0.180054f, 0.197144f, 0.215332f, 0.235718f, 0.255859f, 0.277588f,
+ 0.300049f, 0.323730f, 0.347656f, 0.371826f, 0.396729f, 0.422607f, 0.447021f, 0.472168f, 0.497803f, 0.521973f, 0.547363f, 0.571289f,
+ 0.594238f, 0.618164f, 0.640137f, 0.662109f, 0.682617f, 0.702637f, 0.722168f, 0.739746f, 0.758301f, 0.774902f, 0.790527f, 0.806641f,
+ 0.820801f, 0.834961f, 0.848633f, 0.860352f, 0.872559f, 0.883789f, 0.949707f, 0.953125f, 0.952148f, 0.951172f, 0.950684f, 0.948730f,
+ 0.001418f, 0.004456f, 0.007584f, 0.010803f, 0.014450f, 0.018005f, 0.022186f, 0.026398f, 0.031342f, 0.036224f, 0.041687f, 0.048126f,
+ 0.054382f, 0.061676f, 0.069641f, 0.077759f, 0.086914f, 0.097168f, 0.107910f, 0.119263f, 0.132446f, 0.145752f, 0.161011f, 0.176758f,
+ 0.193726f, 0.211914f, 0.231201f, 0.251709f, 0.272705f, 0.294922f, 0.318604f, 0.342041f, 0.366455f, 0.390869f, 0.416992f, 0.441895f,
+ 0.467285f, 0.493164f, 0.517578f, 0.541992f, 0.566895f, 0.590820f, 0.614746f, 0.637207f, 0.660156f, 0.681152f, 0.701172f, 0.720703f,
+ 0.739746f, 0.758301f, 0.775391f, 0.791992f, 0.807617f, 0.821289f, 0.836426f, 0.850586f, 0.863281f, 0.874512f, 0.946777f, 0.949707f,
+ 0.949707f, 0.948730f, 0.947266f, 0.946289f, 0.001213f, 0.003864f, 0.006721f, 0.009796f, 0.012932f, 0.016037f, 0.020218f, 0.024231f,
+ 0.028275f, 0.032379f, 0.037567f, 0.042603f, 0.048584f, 0.054993f, 0.061798f, 0.069519f, 0.077637f, 0.086182f, 0.095703f, 0.106323f,
+ 0.117676f, 0.130127f, 0.143555f, 0.158203f, 0.173462f, 0.189941f, 0.207886f, 0.226807f, 0.247192f, 0.267822f, 0.290527f, 0.312500f,
+ 0.336670f, 0.360352f, 0.385742f, 0.410889f, 0.437256f, 0.462646f, 0.488281f, 0.513184f, 0.539062f, 0.563477f, 0.588379f, 0.612305f,
+ 0.636230f, 0.657715f, 0.679199f, 0.700195f, 0.720703f, 0.740234f, 0.758301f, 0.775879f, 0.793945f, 0.809082f, 0.824219f, 0.838867f,
+ 0.852539f, 0.865234f, 0.942871f, 0.946777f, 0.946777f, 0.945312f, 0.944824f, 0.943359f, 0.001063f, 0.003754f, 0.005909f, 0.008789f,
+ 0.011780f, 0.014671f, 0.017792f, 0.021378f, 0.025238f, 0.029221f, 0.033417f, 0.038300f, 0.043488f, 0.048828f, 0.054779f, 0.061554f,
+ 0.068604f, 0.076721f, 0.085388f, 0.094482f, 0.104614f, 0.115845f, 0.128296f, 0.141113f, 0.155029f, 0.170044f, 0.186401f, 0.204224f,
+ 0.222778f, 0.242188f, 0.263916f, 0.285156f, 0.308350f, 0.331787f, 0.355957f, 0.381348f, 0.407227f, 0.432617f, 0.459229f, 0.484619f,
+ 0.509277f, 0.536133f, 0.560547f, 0.585938f, 0.609863f, 0.633301f, 0.657715f, 0.678711f, 0.699707f, 0.721191f, 0.740723f, 0.759277f,
+ 0.777344f, 0.794922f, 0.811035f, 0.826660f, 0.841797f, 0.855469f, 0.939453f, 0.943359f, 0.943359f, 0.942871f, 0.941895f, 0.940918f,
+ 0.001175f, 0.003069f, 0.005558f, 0.007912f, 0.010712f, 0.013199f, 0.016235f, 0.019547f, 0.022659f, 0.026138f, 0.030151f, 0.034424f,
+ 0.038940f, 0.044067f, 0.049255f, 0.054993f, 0.061493f, 0.068359f, 0.075928f, 0.084290f, 0.093262f, 0.103760f, 0.114319f, 0.126099f,
+ 0.138550f, 0.152466f, 0.167114f, 0.183472f, 0.200439f, 0.219238f, 0.239014f, 0.259277f, 0.281250f, 0.303711f, 0.327148f, 0.351807f,
+ 0.376709f, 0.402344f, 0.428955f, 0.453857f, 0.480713f, 0.507324f, 0.533203f, 0.558594f, 0.583984f, 0.609375f, 0.633301f, 0.656738f,
+ 0.678711f, 0.700195f, 0.722168f, 0.742188f, 0.761719f, 0.780273f, 0.797852f, 0.813477f, 0.830078f, 0.845703f, 0.935547f, 0.939453f,
+ 0.939453f, 0.938965f, 0.937988f, 0.937012f, 0.001089f, 0.002945f, 0.005066f, 0.007225f, 0.009575f, 0.012016f, 0.014656f, 0.017288f,
+ 0.020142f, 0.023712f, 0.026764f, 0.030640f, 0.034637f, 0.039490f, 0.043854f, 0.048706f, 0.054688f, 0.060913f, 0.067871f, 0.075256f,
+ 0.083191f, 0.092163f, 0.101868f, 0.111938f, 0.123657f, 0.136108f, 0.149658f, 0.164185f, 0.179932f, 0.196777f, 0.215454f, 0.234375f,
+ 0.255371f, 0.276611f, 0.299805f, 0.323486f, 0.347656f, 0.373047f, 0.398682f, 0.425293f, 0.451172f, 0.477783f, 0.504883f, 0.530762f,
+ 0.557617f, 0.583008f, 0.607910f, 0.632812f, 0.657227f, 0.680664f, 0.702637f, 0.724121f, 0.743652f, 0.764160f, 0.783691f, 0.800781f,
+ 0.818848f, 0.833984f, 0.930664f, 0.936035f, 0.936035f, 0.935547f, 0.934570f, 0.933594f, 0.000847f, 0.002800f, 0.004562f, 0.006786f,
+ 0.008804f, 0.011017f, 0.013145f, 0.015640f, 0.018509f, 0.021255f, 0.024277f, 0.027603f, 0.030991f, 0.035248f, 0.039642f, 0.043854f,
+ 0.048798f, 0.054504f, 0.060516f, 0.067017f, 0.073914f, 0.082092f, 0.090515f, 0.099854f, 0.109863f, 0.121521f, 0.133545f, 0.146851f,
+ 0.161133f, 0.176514f, 0.192993f, 0.211426f, 0.230957f, 0.251465f, 0.272705f, 0.295410f, 0.319092f, 0.343994f, 0.369385f, 0.395020f,
+ 0.421631f, 0.448242f, 0.475342f, 0.501953f, 0.529785f, 0.556152f, 0.582031f, 0.608887f, 0.633789f, 0.658203f, 0.681152f, 0.704590f,
+ 0.726074f, 0.748535f, 0.768555f, 0.787109f, 0.804199f, 0.822754f, 0.926758f, 0.931641f, 0.932129f, 0.931641f, 0.931152f, 0.930176f,
+ 0.001035f, 0.002598f, 0.004147f, 0.006062f, 0.007942f, 0.009933f, 0.012405f, 0.014565f, 0.016174f, 0.019135f, 0.021988f, 0.024811f,
+ 0.028259f, 0.031616f, 0.035065f, 0.039429f, 0.043884f, 0.048615f, 0.053833f, 0.059723f, 0.065796f, 0.072693f, 0.080383f, 0.088745f,
+ 0.098206f, 0.107727f, 0.119080f, 0.130981f, 0.143677f, 0.157959f, 0.173218f, 0.189941f, 0.207642f, 0.226929f, 0.247437f, 0.269043f,
+ 0.291748f, 0.315674f, 0.340576f, 0.366211f, 0.392578f, 0.419434f, 0.446533f, 0.473877f, 0.502441f, 0.528320f, 0.556152f, 0.583008f,
+ 0.609375f, 0.635254f, 0.660156f, 0.684082f, 0.706543f, 0.729980f, 0.751953f, 0.771973f, 0.792480f, 0.810547f, 0.922363f, 0.927734f,
+ 0.928223f, 0.928223f, 0.927246f, 0.926758f, 0.000775f, 0.002325f, 0.003843f, 0.005573f, 0.007397f, 0.009163f, 0.010857f, 0.012939f,
+ 0.015312f, 0.017273f, 0.019684f, 0.022537f, 0.025070f, 0.028183f, 0.031616f, 0.035461f, 0.038940f, 0.043671f, 0.048096f, 0.053131f,
+ 0.058411f, 0.064941f, 0.071777f, 0.078857f, 0.086731f, 0.096130f, 0.105835f, 0.116760f, 0.128296f, 0.140747f, 0.154907f, 0.170410f,
+ 0.186646f, 0.204834f, 0.223633f, 0.243896f, 0.265625f, 0.288330f, 0.312012f, 0.337402f, 0.363037f, 0.389648f, 0.417480f, 0.444824f,
+ 0.473633f, 0.500000f, 0.529297f, 0.556641f, 0.583984f, 0.610840f, 0.638184f, 0.662598f, 0.687988f, 0.711914f, 0.734375f, 0.755859f,
+ 0.777832f, 0.798828f, 0.916992f, 0.922852f, 0.923828f, 0.923828f, 0.923340f, 0.922363f, 0.000617f, 0.002234f, 0.003510f, 0.005035f,
+ 0.006397f, 0.008156f, 0.010033f, 0.011665f, 0.013481f, 0.015717f, 0.017700f, 0.020004f, 0.022766f, 0.025391f, 0.028214f, 0.031586f,
+ 0.035217f, 0.038757f, 0.042999f, 0.047668f, 0.052368f, 0.057434f, 0.063538f, 0.070190f, 0.077698f, 0.085449f, 0.094299f, 0.103394f,
+ 0.113953f, 0.125610f, 0.137817f, 0.151855f, 0.167236f, 0.183228f, 0.200806f, 0.219971f, 0.240479f, 0.262451f, 0.285645f, 0.309570f,
+ 0.334961f, 0.360596f, 0.387939f, 0.416016f, 0.444092f, 0.473145f, 0.501465f, 0.529785f, 0.558105f, 0.585938f, 0.614258f, 0.640137f,
+ 0.666992f, 0.692383f, 0.716797f, 0.739746f, 0.763184f, 0.784180f, 0.912109f, 0.918457f, 0.919434f, 0.919434f, 0.918457f, 0.917969f,
+ 0.000665f, 0.002039f, 0.003386f, 0.004520f, 0.005989f, 0.007511f, 0.009262f, 0.010902f, 0.012314f, 0.014320f, 0.015869f, 0.018127f,
+ 0.020248f, 0.022476f, 0.025284f, 0.028122f, 0.030991f, 0.034668f, 0.038239f, 0.042206f, 0.046539f, 0.051361f, 0.056610f, 0.062347f,
+ 0.068604f, 0.075623f, 0.083313f, 0.092041f, 0.101379f, 0.111572f, 0.122986f, 0.135132f, 0.148926f, 0.164062f, 0.180054f, 0.197510f,
+ 0.216797f, 0.237183f, 0.259521f, 0.282227f, 0.307129f, 0.332764f, 0.358887f, 0.386475f, 0.415527f, 0.443604f, 0.473389f, 0.501465f,
+ 0.530762f, 0.560059f, 0.588867f, 0.617676f, 0.645020f, 0.671387f, 0.698242f, 0.722656f, 0.746094f, 0.770020f, 0.906738f, 0.913574f,
+ 0.915039f, 0.914551f, 0.914062f, 0.914062f, 0.000661f, 0.001754f, 0.002831f, 0.004066f, 0.005333f, 0.006668f, 0.008286f, 0.009773f,
+ 0.011124f, 0.012794f, 0.014320f, 0.016357f, 0.018036f, 0.020386f, 0.022766f, 0.025192f, 0.027924f, 0.030807f, 0.034027f, 0.037628f,
+ 0.041321f, 0.045349f, 0.050262f, 0.055328f, 0.060699f, 0.066833f, 0.073669f, 0.081360f, 0.089600f, 0.099060f, 0.108826f, 0.119995f,
+ 0.132324f, 0.145874f, 0.160889f, 0.176880f, 0.194702f, 0.213379f, 0.234497f, 0.256104f, 0.280029f, 0.304688f, 0.330811f, 0.358154f,
+ 0.385986f, 0.415039f, 0.444092f, 0.474609f, 0.503418f, 0.534180f, 0.563965f, 0.592773f, 0.621094f, 0.650391f, 0.678223f, 0.704590f,
+ 0.730469f, 0.754883f, 0.901855f, 0.908691f, 0.910156f, 0.909668f, 0.909668f, 0.908691f, 0.000653f, 0.001667f, 0.002666f, 0.003887f,
+ 0.004986f, 0.006359f, 0.007202f, 0.008751f, 0.010300f, 0.011757f, 0.012939f, 0.014595f, 0.016281f, 0.018234f, 0.020142f, 0.022415f,
+ 0.025101f, 0.027466f, 0.030182f, 0.033539f, 0.036865f, 0.040680f, 0.044342f, 0.048798f, 0.053619f, 0.059479f, 0.065491f, 0.071716f,
+ 0.079285f, 0.087341f, 0.096497f, 0.106445f, 0.117615f, 0.129395f, 0.142822f, 0.157959f, 0.174194f, 0.192139f, 0.210938f, 0.231567f,
+ 0.253906f, 0.277832f, 0.302979f, 0.329590f, 0.357422f, 0.385986f, 0.415283f, 0.446045f, 0.475830f, 0.506348f, 0.537109f, 0.567871f,
+ 0.599121f, 0.628418f, 0.657227f, 0.685547f, 0.712891f, 0.739746f, 0.895508f, 0.902344f, 0.904297f, 0.904785f, 0.904297f, 0.904297f,
+ 0.000372f, 0.001397f, 0.002384f, 0.003529f, 0.004509f, 0.005505f, 0.007015f, 0.008026f, 0.009201f, 0.010292f, 0.011536f, 0.013130f,
+ 0.014915f, 0.016266f, 0.018387f, 0.020218f, 0.022034f, 0.024399f, 0.026901f, 0.029617f, 0.032623f, 0.035950f, 0.039032f, 0.043030f,
+ 0.047577f, 0.052612f, 0.057556f, 0.063477f, 0.070007f, 0.077209f, 0.085083f, 0.094177f, 0.103821f, 0.114563f, 0.126709f, 0.140015f,
+ 0.154785f, 0.171143f, 0.188477f, 0.208252f, 0.229004f, 0.251709f, 0.275879f, 0.302002f, 0.328613f, 0.356445f, 0.385986f, 0.416504f,
+ 0.447510f, 0.478760f, 0.510254f, 0.542480f, 0.573730f, 0.604980f, 0.635742f, 0.665527f, 0.694336f, 0.722656f, 0.887695f, 0.897949f,
+ 0.898926f, 0.899414f, 0.897949f, 0.898438f, 0.000661f, 0.001222f, 0.002275f, 0.003313f, 0.004181f, 0.005119f, 0.006275f, 0.007126f,
+ 0.007988f, 0.009354f, 0.010300f, 0.012062f, 0.013313f, 0.014786f, 0.016251f, 0.018021f, 0.019516f, 0.021896f, 0.024017f, 0.026428f,
+ 0.029022f, 0.031799f, 0.034698f, 0.038422f, 0.042236f, 0.046265f, 0.050598f, 0.055786f, 0.061493f, 0.067871f, 0.074951f, 0.082458f,
+ 0.091187f, 0.101135f, 0.111694f, 0.123779f, 0.137207f, 0.151978f, 0.167969f, 0.186157f, 0.205688f, 0.226929f, 0.249756f, 0.274658f,
+ 0.301025f, 0.328613f, 0.357178f, 0.387207f, 0.418457f, 0.450195f, 0.482422f, 0.516113f, 0.548340f, 0.580566f, 0.612305f, 0.644043f,
+ 0.674805f, 0.705566f, 0.882812f, 0.890625f, 0.892578f, 0.893066f, 0.892578f, 0.893066f, 0.000379f, 0.001211f, 0.002066f, 0.003040f,
+ 0.003834f, 0.004616f, 0.005608f, 0.006550f, 0.007347f, 0.008408f, 0.009529f, 0.010452f, 0.011940f, 0.013039f, 0.014313f, 0.015961f,
+ 0.017746f, 0.019180f, 0.021210f, 0.023239f, 0.025482f, 0.028030f, 0.030640f, 0.033661f, 0.036987f, 0.040466f, 0.044617f, 0.048828f,
+ 0.053894f, 0.059235f, 0.065674f, 0.072632f, 0.079956f, 0.089050f, 0.098267f, 0.109009f, 0.120789f, 0.134521f, 0.148926f, 0.165405f,
+ 0.183228f, 0.202881f, 0.224731f, 0.248779f, 0.273193f, 0.300049f, 0.329346f, 0.358887f, 0.390381f, 0.421387f, 0.454590f, 0.488770f,
+ 0.521484f, 0.555176f, 0.588379f, 0.621582f, 0.654785f, 0.686523f, 0.875488f, 0.885254f, 0.886719f, 0.886230f, 0.886719f, 0.886230f,
+ 0.000282f, 0.001126f, 0.002010f, 0.002661f, 0.003340f, 0.004269f, 0.005192f, 0.005711f, 0.006638f, 0.007278f, 0.008377f, 0.009483f,
+ 0.010567f, 0.011742f, 0.012871f, 0.014061f, 0.015480f, 0.017242f, 0.018799f, 0.020584f, 0.022461f, 0.024490f, 0.027100f, 0.029434f,
+ 0.032532f, 0.035706f, 0.038971f, 0.042969f, 0.047241f, 0.052094f, 0.057373f, 0.063232f, 0.070007f, 0.077637f, 0.086243f, 0.095764f,
+ 0.106323f, 0.118164f, 0.131470f, 0.146118f, 0.162720f, 0.181030f, 0.200928f, 0.223022f, 0.247070f, 0.272705f, 0.300537f, 0.330322f,
+ 0.360107f, 0.393066f, 0.426270f, 0.459473f, 0.494629f, 0.529297f, 0.564453f, 0.598633f, 0.633789f, 0.666504f, 0.868652f, 0.878418f,
+ 0.879395f, 0.880371f, 0.879883f, 0.879395f, 0.000340f, 0.000963f, 0.001826f, 0.002459f, 0.003307f, 0.003847f, 0.004719f, 0.004936f,
+ 0.005802f, 0.006695f, 0.007748f, 0.008522f, 0.009506f, 0.010376f, 0.011383f, 0.012787f, 0.013901f, 0.015182f, 0.016663f, 0.018051f,
+ 0.019821f, 0.021759f, 0.023590f, 0.025818f, 0.028519f, 0.030975f, 0.034210f, 0.037811f, 0.040802f, 0.045349f, 0.050201f, 0.055298f,
+ 0.061310f, 0.067688f, 0.074768f, 0.083557f, 0.092590f, 0.103149f, 0.115479f, 0.128906f, 0.142944f, 0.160278f, 0.178345f, 0.198975f,
+ 0.221802f, 0.246094f, 0.272949f, 0.301514f, 0.331543f, 0.363525f, 0.396729f, 0.430908f, 0.466553f, 0.501953f, 0.538086f, 0.574707f,
+ 0.610840f, 0.646973f, 0.860352f, 0.870605f, 0.873047f, 0.873047f, 0.873535f, 0.872559f, 0.000225f, 0.001021f, 0.001653f, 0.002302f,
+ 0.002827f, 0.003448f, 0.003937f, 0.004486f, 0.004986f, 0.006252f, 0.007000f, 0.007416f, 0.008224f, 0.009300f, 0.009972f, 0.011322f,
+ 0.012115f, 0.013428f, 0.014557f, 0.015991f, 0.017532f, 0.018982f, 0.020706f, 0.022781f, 0.024567f, 0.027161f, 0.029770f, 0.032623f,
+ 0.035828f, 0.039551f, 0.043030f, 0.047852f, 0.052795f, 0.058716f, 0.065125f, 0.072266f, 0.080566f, 0.089661f, 0.100403f, 0.112854f,
+ 0.125732f, 0.140991f, 0.157349f, 0.176514f, 0.197510f, 0.220581f, 0.245850f, 0.273438f, 0.302979f, 0.334717f, 0.367676f, 0.401855f,
+ 0.437256f, 0.474609f, 0.512695f, 0.549316f, 0.588379f, 0.625000f, 0.853027f, 0.863281f, 0.866211f, 0.866211f, 0.866699f, 0.866211f,
+ 0.000324f, 0.000845f, 0.001534f, 0.002172f, 0.002474f, 0.003115f, 0.003824f, 0.003937f, 0.004848f, 0.005417f, 0.006222f, 0.006760f,
+ 0.007446f, 0.008186f, 0.009102f, 0.009888f, 0.010620f, 0.011551f, 0.012878f, 0.013954f, 0.015106f, 0.016495f, 0.018143f, 0.019669f,
+ 0.021713f, 0.023468f, 0.025818f, 0.028183f, 0.031021f, 0.033783f, 0.037445f, 0.041534f, 0.045532f, 0.050598f, 0.056152f, 0.062500f,
+ 0.069580f, 0.077698f, 0.086914f, 0.097717f, 0.108948f, 0.123047f, 0.138184f, 0.155273f, 0.174438f, 0.196167f, 0.219604f, 0.246094f,
+ 0.274902f, 0.305420f, 0.338379f, 0.372314f, 0.408936f, 0.445801f, 0.484131f, 0.523438f, 0.562988f, 0.604492f, 0.843262f, 0.856445f,
+ 0.857422f, 0.857910f, 0.858398f, 0.858398f, 0.000331f, 0.000944f, 0.001288f, 0.001833f, 0.002388f, 0.002769f, 0.003216f, 0.003664f,
+ 0.004276f, 0.004822f, 0.005173f, 0.005951f, 0.006531f, 0.007156f, 0.007896f, 0.008438f, 0.009430f, 0.010117f, 0.011208f, 0.012253f,
+ 0.012970f, 0.014297f, 0.015572f, 0.017059f, 0.018692f, 0.020264f, 0.022125f, 0.024323f, 0.026474f, 0.029343f, 0.032288f, 0.035461f,
+ 0.039062f, 0.043335f, 0.047821f, 0.053558f, 0.059509f, 0.067078f, 0.074341f, 0.083862f, 0.094360f, 0.106323f, 0.120117f, 0.135254f,
+ 0.153442f, 0.172852f, 0.195190f, 0.220337f, 0.246948f, 0.276611f, 0.308594f, 0.343262f, 0.379150f, 0.416992f, 0.455811f, 0.496582f,
+ 0.537598f, 0.579590f, 0.834473f, 0.847656f, 0.850098f, 0.850098f, 0.849609f, 0.850098f, 0.000316f, 0.000824f, 0.001088f, 0.001693f,
+ 0.002062f, 0.002403f, 0.003027f, 0.003460f, 0.003712f, 0.004166f, 0.004765f, 0.005138f, 0.005871f, 0.006218f, 0.006924f, 0.007431f,
+ 0.008255f, 0.008850f, 0.009781f, 0.010590f, 0.011391f, 0.012367f, 0.013474f, 0.014709f, 0.015823f, 0.017685f, 0.018982f, 0.020844f,
+ 0.022629f, 0.025070f, 0.027496f, 0.030380f, 0.033447f, 0.037140f, 0.041168f, 0.045654f, 0.050720f, 0.057251f, 0.063965f, 0.071777f,
+ 0.080811f, 0.091248f, 0.103638f, 0.117126f, 0.133179f, 0.151001f, 0.171631f, 0.194580f, 0.220337f, 0.248413f, 0.279785f, 0.313965f,
+ 0.349365f, 0.386963f, 0.426514f, 0.468262f, 0.510742f, 0.555176f, 0.825684f, 0.838379f, 0.839844f, 0.841309f, 0.841309f, 0.841309f,
+ 0.000210f, 0.000717f, 0.001084f, 0.001454f, 0.001882f, 0.002096f, 0.002468f, 0.002996f, 0.003395f, 0.003632f, 0.004066f, 0.004467f,
+ 0.005020f, 0.005569f, 0.005917f, 0.006474f, 0.006958f, 0.007576f, 0.008453f, 0.009140f, 0.010002f, 0.010689f, 0.011520f, 0.012596f,
+ 0.013695f, 0.014938f, 0.016220f, 0.017593f, 0.019424f, 0.020996f, 0.023331f, 0.025696f, 0.028427f, 0.031067f, 0.034668f, 0.038422f,
+ 0.042908f, 0.048096f, 0.054016f, 0.060699f, 0.068909f, 0.077515f, 0.088501f, 0.100464f, 0.114624f, 0.130615f, 0.149048f, 0.170654f,
+ 0.194214f, 0.222046f, 0.251465f, 0.283936f, 0.319580f, 0.357422f, 0.397461f, 0.440186f, 0.484375f, 0.528320f, 0.814941f, 0.828613f,
+ 0.830078f, 0.832031f, 0.831543f, 0.833008f, 0.000234f, 0.000576f, 0.000939f, 0.001362f, 0.001481f, 0.001999f, 0.002228f, 0.002714f,
+ 0.002846f, 0.003218f, 0.003555f, 0.003933f, 0.004356f, 0.004787f, 0.005169f, 0.005604f, 0.006145f, 0.006554f, 0.007275f, 0.007675f,
+ 0.008293f, 0.009201f, 0.009979f, 0.010651f, 0.011497f, 0.012527f, 0.013893f, 0.014771f, 0.016373f, 0.017975f, 0.019455f, 0.021683f,
+ 0.023895f, 0.026077f, 0.029114f, 0.032257f, 0.036072f, 0.040405f, 0.045197f, 0.050903f, 0.057770f, 0.065613f, 0.074524f, 0.085388f,
+ 0.097656f, 0.111694f, 0.128540f, 0.147949f, 0.170166f, 0.195435f, 0.223389f, 0.255127f, 0.289551f, 0.327393f, 0.367432f, 0.410400f,
+ 0.455078f, 0.502441f, 0.804199f, 0.818848f, 0.821289f, 0.822266f, 0.822754f, 0.822266f, 0.000213f, 0.000506f, 0.000756f, 0.001184f,
+ 0.001396f, 0.001697f, 0.002010f, 0.002474f, 0.002569f, 0.002918f, 0.003090f, 0.003496f, 0.003855f, 0.004139f, 0.004478f, 0.004852f,
+ 0.005253f, 0.005665f, 0.006100f, 0.006638f, 0.007080f, 0.007744f, 0.008293f, 0.009132f, 0.009750f, 0.010658f, 0.011536f, 0.012413f,
+ 0.013779f, 0.014908f, 0.016510f, 0.017990f, 0.019623f, 0.021637f, 0.024109f, 0.026718f, 0.029922f, 0.033539f, 0.037567f, 0.042572f,
+ 0.048279f, 0.054413f, 0.062042f, 0.071472f, 0.081909f, 0.094604f, 0.109436f, 0.127075f, 0.146484f, 0.170044f, 0.196533f, 0.226929f,
+ 0.260254f, 0.296875f, 0.337402f, 0.380615f, 0.426025f, 0.475342f, 0.792969f, 0.807617f, 0.811035f, 0.811523f, 0.812012f, 0.813477f,
+ 0.000119f, 0.000422f, 0.000883f, 0.001027f, 0.001189f, 0.001604f, 0.001783f, 0.001913f, 0.002228f, 0.002522f, 0.002645f, 0.003086f,
+ 0.003199f, 0.003534f, 0.003790f, 0.004105f, 0.004421f, 0.004902f, 0.005283f, 0.005589f, 0.006039f, 0.006401f, 0.007088f, 0.007519f,
+ 0.008217f, 0.008812f, 0.009712f, 0.010460f, 0.011337f, 0.012413f, 0.013596f, 0.014687f, 0.016159f, 0.018051f, 0.019913f, 0.022018f,
+ 0.024551f, 0.027359f, 0.030792f, 0.035065f, 0.039703f, 0.044983f, 0.051392f, 0.059204f, 0.068176f, 0.079102f, 0.092041f, 0.106873f,
+ 0.125000f, 0.145874f, 0.170532f, 0.198975f, 0.230835f, 0.267090f, 0.306641f, 0.349854f, 0.395508f, 0.445801f, 0.780762f, 0.796875f,
+ 0.799805f, 0.801270f, 0.801270f, 0.801270f, 0.000227f, 0.000521f, 0.000698f, 0.000817f, 0.001236f, 0.001359f, 0.001540f, 0.001619f,
+ 0.001940f, 0.002089f, 0.002430f, 0.002552f, 0.002655f, 0.002932f, 0.003241f, 0.003532f, 0.003841f, 0.004120f, 0.004292f, 0.004761f,
+ 0.005051f, 0.005459f, 0.005886f, 0.006290f, 0.006821f, 0.007320f, 0.007889f, 0.008652f, 0.009399f, 0.010063f, 0.010887f, 0.012215f,
+ 0.013206f, 0.014648f, 0.016037f, 0.017853f, 0.019958f, 0.022491f, 0.024994f, 0.028091f, 0.032135f, 0.036530f, 0.041809f, 0.048096f,
+ 0.055908f, 0.064941f, 0.076050f, 0.089050f, 0.104980f, 0.123596f, 0.146118f, 0.172363f, 0.203003f, 0.237183f, 0.276123f, 0.318359f,
+ 0.365479f, 0.416504f, 0.768555f, 0.784668f, 0.788086f, 0.789551f, 0.790039f, 0.790039f, 0.000000f, 0.000448f, 0.000566f, 0.000688f,
+ 0.000985f, 0.001144f, 0.001305f, 0.001437f, 0.001622f, 0.001731f, 0.001989f, 0.002174f, 0.002338f, 0.002552f, 0.002739f, 0.002924f,
+ 0.003239f, 0.003405f, 0.003628f, 0.003933f, 0.004200f, 0.004463f, 0.004948f, 0.005245f, 0.005615f, 0.006138f, 0.006699f, 0.006989f,
+ 0.007793f, 0.008247f, 0.008980f, 0.009918f, 0.010857f, 0.011795f, 0.013016f, 0.014244f, 0.015930f, 0.017868f, 0.019882f, 0.022659f,
+ 0.025543f, 0.029160f, 0.033417f, 0.038635f, 0.044983f, 0.052338f, 0.061859f, 0.072693f, 0.086487f, 0.102966f, 0.122864f, 0.146973f,
+ 0.175049f, 0.207764f, 0.245605f, 0.287842f, 0.334229f, 0.385986f, 0.755371f, 0.771973f, 0.775879f, 0.777344f, 0.777832f, 0.778809f,
+ 0.000000f, 0.000303f, 0.000512f, 0.000752f, 0.000828f, 0.001036f, 0.001184f, 0.001292f, 0.001281f, 0.001460f, 0.001717f, 0.001843f,
+ 0.001955f, 0.002060f, 0.002317f, 0.002476f, 0.002542f, 0.002869f, 0.003088f, 0.003313f, 0.003559f, 0.003693f, 0.004082f, 0.004318f,
+ 0.004696f, 0.005070f, 0.005245f, 0.005741f, 0.006126f, 0.006771f, 0.007298f, 0.007828f, 0.008583f, 0.009338f, 0.010246f, 0.011528f,
+ 0.012794f, 0.014160f, 0.015717f, 0.017853f, 0.019958f, 0.022995f, 0.026291f, 0.030533f, 0.035553f, 0.041565f, 0.048981f, 0.058350f,
+ 0.069824f, 0.083801f, 0.101685f, 0.122437f, 0.148438f, 0.178833f, 0.215454f, 0.256104f, 0.302490f, 0.354736f, 0.741699f, 0.758789f,
+ 0.762695f, 0.763672f, 0.764648f, 0.765625f, 0.000097f, 0.000306f, 0.000370f, 0.000618f, 0.000713f, 0.000810f, 0.000953f, 0.000920f,
+ 0.001167f, 0.001238f, 0.001406f, 0.001483f, 0.001540f, 0.001794f, 0.001970f, 0.002028f, 0.002264f, 0.002354f, 0.002459f, 0.002636f,
+ 0.002827f, 0.003096f, 0.003342f, 0.003544f, 0.003881f, 0.003948f, 0.004459f, 0.004742f, 0.005005f, 0.005394f, 0.005867f, 0.006374f,
+ 0.006901f, 0.007507f, 0.008202f, 0.008881f, 0.010017f, 0.010986f, 0.012451f, 0.013809f, 0.015511f, 0.017776f, 0.020325f, 0.023453f,
+ 0.027390f, 0.032349f, 0.038330f, 0.045624f, 0.055359f, 0.067078f, 0.082275f, 0.101013f, 0.123657f, 0.151611f, 0.185791f, 0.225342f,
+ 0.270752f, 0.322754f, 0.727051f, 0.746094f, 0.749512f, 0.750977f, 0.751953f, 0.751953f, 0.000228f, 0.000211f, 0.000504f, 0.000443f,
+ 0.000523f, 0.000672f, 0.000703f, 0.000902f, 0.000975f, 0.001010f, 0.001122f, 0.001178f, 0.001257f, 0.001424f, 0.001575f, 0.001631f,
+ 0.001789f, 0.001910f, 0.002090f, 0.002144f, 0.002411f, 0.002520f, 0.002703f, 0.002827f, 0.003010f, 0.003195f, 0.003403f, 0.003750f,
+ 0.003960f, 0.004276f, 0.004780f, 0.005005f, 0.005432f, 0.005981f, 0.006428f, 0.007015f, 0.007812f, 0.008537f, 0.009415f, 0.010658f,
+ 0.011963f, 0.013443f, 0.015396f, 0.017731f, 0.020782f, 0.024414f, 0.029083f, 0.034912f, 0.042572f, 0.052216f, 0.064392f, 0.080017f,
+ 0.100220f, 0.126099f, 0.157227f, 0.194946f, 0.239136f, 0.290283f, 0.712402f, 0.731445f, 0.734863f, 0.736816f, 0.737305f, 0.737793f,
+ 0.000211f, 0.000198f, 0.000195f, 0.000413f, 0.000517f, 0.000531f, 0.000586f, 0.000736f, 0.000769f, 0.000809f, 0.000970f, 0.001007f,
+ 0.001067f, 0.001134f, 0.001211f, 0.001348f, 0.001341f, 0.001534f, 0.001617f, 0.001734f, 0.001942f, 0.002010f, 0.002110f, 0.002268f,
+ 0.002523f, 0.002607f, 0.002829f, 0.003004f, 0.003113f, 0.003403f, 0.003681f, 0.003990f, 0.004257f, 0.004601f, 0.005039f, 0.005444f,
+ 0.005993f, 0.006561f, 0.007278f, 0.008026f, 0.009041f, 0.010124f, 0.011513f, 0.013222f, 0.015320f, 0.017914f, 0.021408f, 0.025833f,
+ 0.031433f, 0.039429f, 0.049255f, 0.062286f, 0.079102f, 0.101135f, 0.130005f, 0.164917f, 0.207764f, 0.258057f, 0.696289f, 0.716309f,
+ 0.720215f, 0.722168f, 0.722656f, 0.723145f, 0.000000f, 0.000080f, 0.000286f, 0.000374f, 0.000434f, 0.000457f, 0.000460f, 0.000568f,
+ 0.000610f, 0.000669f, 0.000715f, 0.000773f, 0.000877f, 0.000918f, 0.001030f, 0.000998f, 0.001148f, 0.001134f, 0.001305f, 0.001369f,
+ 0.001410f, 0.001534f, 0.001688f, 0.001780f, 0.001899f, 0.001963f, 0.002081f, 0.002199f, 0.002470f, 0.002563f, 0.002758f, 0.003006f,
+ 0.003273f, 0.003531f, 0.003817f, 0.004093f, 0.004532f, 0.004993f, 0.005463f, 0.006027f, 0.006657f, 0.007492f, 0.008537f, 0.009689f,
+ 0.011246f, 0.012985f, 0.015518f, 0.018539f, 0.022827f, 0.028534f, 0.036072f, 0.046234f, 0.060028f, 0.078918f, 0.103943f, 0.136353f,
+ 0.176514f, 0.225952f, 0.679199f, 0.699707f, 0.703613f, 0.706055f, 0.706543f, 0.708008f, 0.000089f, 0.000176f, 0.000232f, 0.000342f,
+ 0.000317f, 0.000319f, 0.000420f, 0.000382f, 0.000494f, 0.000515f, 0.000612f, 0.000650f, 0.000671f, 0.000701f, 0.000732f, 0.000859f,
+ 0.000888f, 0.000923f, 0.001002f, 0.001048f, 0.001170f, 0.001234f, 0.001292f, 0.001426f, 0.001414f, 0.001476f, 0.001622f, 0.001723f,
+ 0.001892f, 0.001976f, 0.002237f, 0.002239f, 0.002476f, 0.002645f, 0.002817f, 0.003092f, 0.003355f, 0.003626f, 0.003979f, 0.004459f,
+ 0.004948f, 0.005527f, 0.006256f, 0.007027f, 0.008026f, 0.009270f, 0.010918f, 0.013184f, 0.016098f, 0.019913f, 0.025253f, 0.033112f,
+ 0.043762f, 0.059113f, 0.079956f, 0.109009f, 0.146729f, 0.193726f, 0.660645f, 0.682129f, 0.688477f, 0.690430f, 0.689941f, 0.690918f,
+ 0.000000f, 0.000063f, 0.000194f, 0.000281f, 0.000187f, 0.000325f, 0.000278f, 0.000272f, 0.000386f, 0.000466f, 0.000462f, 0.000510f,
+ 0.000519f, 0.000587f, 0.000613f, 0.000603f, 0.000671f, 0.000709f, 0.000744f, 0.000808f, 0.000858f, 0.000913f, 0.000963f, 0.000999f,
+ 0.001062f, 0.001106f, 0.001262f, 0.001266f, 0.001431f, 0.001562f, 0.001672f, 0.001693f, 0.001810f, 0.001976f, 0.002090f, 0.002289f,
+ 0.002422f, 0.002666f, 0.002916f, 0.003166f, 0.003513f, 0.003862f, 0.004318f, 0.004936f, 0.005646f, 0.006493f, 0.007626f, 0.009048f,
+ 0.010826f, 0.013519f, 0.017166f, 0.022476f, 0.030258f, 0.041687f, 0.058807f, 0.083435f, 0.117737f, 0.162598f, 0.644043f, 0.666504f,
+ 0.670410f, 0.673340f, 0.674316f, 0.675293f, 0.000000f, 0.000117f, 0.000112f, 0.000178f, 0.000216f, 0.000222f, 0.000271f, 0.000229f,
+ 0.000280f, 0.000283f, 0.000326f, 0.000376f, 0.000376f, 0.000443f, 0.000456f, 0.000470f, 0.000499f, 0.000507f, 0.000547f, 0.000566f,
+ 0.000613f, 0.000667f, 0.000692f, 0.000749f, 0.000773f, 0.000803f, 0.000917f, 0.000924f, 0.000997f, 0.001055f, 0.001096f, 0.001236f,
+ 0.001261f, 0.001376f, 0.001466f, 0.001693f, 0.001695f, 0.001826f, 0.002077f, 0.002226f, 0.002411f, 0.002686f, 0.002985f, 0.003368f,
+ 0.003801f, 0.004353f, 0.005131f, 0.005974f, 0.007370f, 0.008842f, 0.011345f, 0.014717f, 0.019699f, 0.027893f, 0.040619f, 0.060730f,
+ 0.090454f, 0.132080f, 0.625488f, 0.649414f, 0.653809f, 0.655273f, 0.656250f, 0.658203f, 0.000000f, 0.000000f, 0.000108f, 0.000121f,
+ 0.000136f, 0.000154f, 0.000158f, 0.000191f, 0.000203f, 0.000213f, 0.000270f, 0.000223f, 0.000232f, 0.000270f, 0.000296f, 0.000342f,
+ 0.000324f, 0.000352f, 0.000453f, 0.000407f, 0.000450f, 0.000459f, 0.000486f, 0.000524f, 0.000545f, 0.000565f, 0.000630f, 0.000620f,
+ 0.000678f, 0.000803f, 0.000763f, 0.000813f, 0.000860f, 0.000937f, 0.001035f, 0.001101f, 0.001141f, 0.001254f, 0.001399f, 0.001449f,
+ 0.001616f, 0.001779f, 0.001942f, 0.002220f, 0.002493f, 0.002808f, 0.003258f, 0.003895f, 0.004623f, 0.005714f, 0.007111f, 0.009178f,
+ 0.012367f, 0.017319f, 0.025879f, 0.040741f, 0.065552f, 0.103577f, 0.606934f, 0.630371f, 0.635254f, 0.637695f, 0.638672f, 0.639648f,
+ 0.000000f, 0.000109f, 0.000102f, 0.000098f, 0.000105f, 0.000110f, 0.000113f, 0.000122f, 0.000117f, 0.000132f, 0.000147f, 0.000189f,
+ 0.000163f, 0.000212f, 0.000213f, 0.000222f, 0.000224f, 0.000233f, 0.000258f, 0.000262f, 0.000274f, 0.000305f, 0.000340f, 0.000329f,
+ 0.000358f, 0.000376f, 0.000445f, 0.000418f, 0.000447f, 0.000478f, 0.000546f, 0.000530f, 0.000594f, 0.000626f, 0.000679f, 0.000745f,
+ 0.000763f, 0.000804f, 0.000869f, 0.000952f, 0.001025f, 0.001119f, 0.001254f, 0.001359f, 0.001584f, 0.001728f, 0.001993f, 0.002295f,
+ 0.002790f, 0.003298f, 0.004135f, 0.005363f, 0.007267f, 0.010277f, 0.015350f, 0.024994f, 0.043518f, 0.076599f, 0.585938f, 0.611816f,
+ 0.616211f, 0.619141f, 0.619629f, 0.620605f, 0.000000f, 0.000102f, 0.000095f, 0.000090f, 0.000085f, 0.000081f, 0.000078f, 0.000073f,
+ 0.000075f, 0.000079f, 0.000087f, 0.000092f, 0.000095f, 0.000094f, 0.000133f, 0.000143f, 0.000152f, 0.000155f, 0.000161f, 0.000195f,
+ 0.000174f, 0.000183f, 0.000188f, 0.000216f, 0.000233f, 0.000241f, 0.000241f, 0.000257f, 0.000269f, 0.000302f, 0.000325f, 0.000321f,
+ 0.000350f, 0.000363f, 0.000405f, 0.000426f, 0.000456f, 0.000486f, 0.000539f, 0.000560f, 0.000614f, 0.000671f, 0.000722f, 0.000811f,
+ 0.000891f, 0.000989f, 0.001162f, 0.001312f, 0.001545f, 0.001863f, 0.002340f, 0.002920f, 0.003963f, 0.005615f, 0.008499f, 0.013931f,
+ 0.025833f, 0.052094f, 0.566406f, 0.591797f, 0.597168f, 0.599609f, 0.601074f, 0.601562f, 0.000110f, 0.000092f, 0.000084f, 0.000077f,
+ 0.000073f, 0.000070f, 0.000067f, 0.000064f, 0.000061f, 0.000058f, 0.000055f, 0.000064f, 0.000051f, 0.000054f, 0.000071f, 0.000059f,
+ 0.000082f, 0.000081f, 0.000090f, 0.000087f, 0.000099f, 0.000103f, 0.000127f, 0.000131f, 0.000135f, 0.000139f, 0.000142f, 0.000143f,
+ 0.000156f, 0.000162f, 0.000173f, 0.000194f, 0.000206f, 0.000201f, 0.000233f, 0.000225f, 0.000246f, 0.000294f, 0.000279f, 0.000313f,
+ 0.000333f, 0.000356f, 0.000395f, 0.000432f, 0.000459f, 0.000511f, 0.000577f, 0.000664f, 0.000770f, 0.000916f, 0.001114f, 0.001400f,
+ 0.001881f, 0.002665f, 0.004093f, 0.006966f, 0.013290f, 0.031525f, 0.545410f, 0.571777f, 0.577637f, 0.579102f, 0.580566f, 0.581055f,
+ 0.000093f, 0.000073f, 0.000066f, 0.000061f, 0.000056f, 0.000054f, 0.000051f, 0.000050f, 0.000048f, 0.000047f, 0.000045f, 0.000044f,
+ 0.000042f, 0.000040f, 0.000038f, 0.000036f, 0.000039f, 0.000033f, 0.000041f, 0.000040f, 0.000046f, 0.000048f, 0.000051f, 0.000057f,
+ 0.000060f, 0.000066f, 0.000062f, 0.000067f, 0.000080f, 0.000085f, 0.000088f, 0.000092f, 0.000092f, 0.000097f, 0.000109f, 0.000109f,
+ 0.000117f, 0.000132f, 0.000134f, 0.000147f, 0.000154f, 0.000156f, 0.000188f, 0.000197f, 0.000219f, 0.000234f, 0.000266f, 0.000286f,
+ 0.000335f, 0.000397f, 0.000472f, 0.000566f, 0.000751f, 0.001039f, 0.001626f, 0.002834f, 0.005909f, 0.015411f, 0.524414f, 0.551270f,
+ 0.557129f, 0.559570f, 0.561035f, 0.561523f, 0.000060f, 0.000046f, 0.000039f, 0.000037f, 0.000034f, 0.000034f, 0.000032f, 0.000032f,
+ 0.000031f, 0.000029f, 0.000029f, 0.000029f, 0.000028f, 0.000028f, 0.000028f, 0.000027f, 0.000026f, 0.000025f, 0.000024f, 0.000023f,
+ 0.000022f, 0.000021f, 0.000020f, 0.000021f, 0.000020f, 0.000018f, 0.000018f, 0.000023f, 0.000024f, 0.000028f, 0.000032f, 0.000033f,
+ 0.000032f, 0.000038f, 0.000039f, 0.000043f, 0.000046f, 0.000050f, 0.000052f, 0.000053f, 0.000057f, 0.000067f, 0.000073f, 0.000068f,
+ 0.000076f, 0.000083f, 0.000097f, 0.000110f, 0.000116f, 0.000127f, 0.000157f, 0.000185f, 0.000246f, 0.000319f, 0.000466f, 0.000810f,
+ 0.001841f, 0.005795f, 0.503418f, 0.531250f, 0.536621f, 0.539062f, 0.540039f, 0.540527f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000004f, 0.000005f, 0.000005f, 0.000008f, 0.000008f, 0.000009f, 0.000009f, 0.000010f, 0.000010f, 0.000010f, 0.000010f, 0.000011f,
+ 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000011f, 0.000011f,
+ 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000008f, 0.000009f, 0.000009f, 0.000010f, 0.000012f,
+ 0.000013f, 0.000014f, 0.000015f, 0.000017f, 0.000020f, 0.000021f, 0.000018f, 0.000023f, 0.000023f, 0.000025f, 0.000030f, 0.000038f,
+ 0.000043f, 0.000059f, 0.000079f, 0.000131f, 0.000279f, 0.001210f, 0.481934f, 0.510254f, 0.516113f, 0.518555f, 0.520020f, 0.520508f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000004f, 0.000006f, 0.000022f, 0.460449f, 0.489258f,
+ 0.495850f, 0.498291f, 0.499512f, 0.500000f,
+ },
+ {
+ 0.038544f, 0.111450f, 0.177368f, 0.237061f, 0.290771f, 0.339600f, 0.384277f, 0.425293f, 0.462402f, 0.497070f, 0.527344f, 0.556152f,
+ 0.583496f, 0.607910f, 0.630859f, 0.652344f, 0.672852f, 0.690918f, 0.708496f, 0.724609f, 0.740723f, 0.754883f, 0.768066f, 0.780273f,
+ 0.792480f, 0.803711f, 0.815430f, 0.825684f, 0.835449f, 0.844727f, 0.853516f, 0.861816f, 0.870117f, 0.877930f, 0.885254f, 0.892578f,
+ 0.899414f, 0.905762f, 0.912109f, 0.918945f, 0.923828f, 0.928711f, 0.934082f, 0.939941f, 0.944824f, 0.949707f, 0.953613f, 0.958496f,
+ 0.962402f, 0.967285f, 0.971191f, 0.974609f, 0.979004f, 0.982422f, 0.985352f, 0.989258f, 0.992188f, 0.996094f, 0.996094f, 0.990723f,
+ 0.986328f, 0.982422f, 0.978516f, 0.975098f, 0.029068f, 0.087219f, 0.142578f, 0.195190f, 0.244629f, 0.291016f, 0.334717f, 0.375000f,
+ 0.412842f, 0.446533f, 0.481201f, 0.511230f, 0.539062f, 0.565918f, 0.590820f, 0.614258f, 0.636719f, 0.656250f, 0.675293f, 0.693359f,
+ 0.710449f, 0.726562f, 0.741699f, 0.755371f, 0.769043f, 0.781738f, 0.793457f, 0.805176f, 0.815918f, 0.826660f, 0.835938f, 0.845703f,
+ 0.854980f, 0.862793f, 0.871582f, 0.879395f, 0.885742f, 0.894531f, 0.900879f, 0.907227f, 0.913086f, 0.919434f, 0.925293f, 0.931152f,
+ 0.936523f, 0.941406f, 0.946777f, 0.951172f, 0.956055f, 0.960449f, 0.964355f, 0.968750f, 0.972656f, 0.976562f, 0.980469f, 0.984375f,
+ 0.987793f, 0.991211f, 0.994141f, 0.989258f, 0.984863f, 0.981445f, 0.977539f, 0.974121f, 0.023346f, 0.069641f, 0.115601f, 0.160767f,
+ 0.205078f, 0.248047f, 0.289062f, 0.328125f, 0.365723f, 0.401367f, 0.435059f, 0.466309f, 0.495361f, 0.523926f, 0.550781f, 0.574707f,
+ 0.597168f, 0.620117f, 0.641113f, 0.660156f, 0.679688f, 0.696777f, 0.713379f, 0.728516f, 0.743652f, 0.757324f, 0.770996f, 0.784180f,
+ 0.795410f, 0.806641f, 0.817383f, 0.828125f, 0.837891f, 0.847168f, 0.855957f, 0.864258f, 0.873047f, 0.880859f, 0.888672f, 0.895996f,
+ 0.902832f, 0.909668f, 0.915039f, 0.921875f, 0.927246f, 0.934082f, 0.937988f, 0.943848f, 0.948242f, 0.953613f, 0.958496f, 0.962402f,
+ 0.967285f, 0.971191f, 0.975098f, 0.979492f, 0.983398f, 0.985840f, 0.992188f, 0.987305f, 0.983398f, 0.979980f, 0.977051f, 0.973633f,
+ 0.018600f, 0.056366f, 0.094299f, 0.133545f, 0.172729f, 0.211670f, 0.249756f, 0.285889f, 0.322021f, 0.356934f, 0.390869f, 0.421875f,
+ 0.452148f, 0.481201f, 0.509277f, 0.535156f, 0.560059f, 0.583496f, 0.605957f, 0.626465f, 0.647949f, 0.665527f, 0.684570f, 0.700684f,
+ 0.717285f, 0.731934f, 0.746582f, 0.760254f, 0.773926f, 0.786621f, 0.799316f, 0.809082f, 0.820312f, 0.830566f, 0.840332f, 0.850098f,
+ 0.858887f, 0.867188f, 0.875000f, 0.883789f, 0.890625f, 0.898926f, 0.904297f, 0.912109f, 0.916992f, 0.924316f, 0.930176f, 0.935547f,
+ 0.941406f, 0.945801f, 0.951172f, 0.956055f, 0.960938f, 0.964844f, 0.969727f, 0.974609f, 0.978516f, 0.981934f, 0.989746f, 0.985840f,
+ 0.981934f, 0.978516f, 0.975586f, 0.972168f, 0.015068f, 0.046143f, 0.077881f, 0.111816f, 0.145264f, 0.179688f, 0.214600f, 0.249023f,
+ 0.282715f, 0.316406f, 0.348389f, 0.380615f, 0.411133f, 0.440430f, 0.468018f, 0.494873f, 0.520508f, 0.546387f, 0.568848f, 0.591309f,
+ 0.613281f, 0.634277f, 0.653809f, 0.670898f, 0.688477f, 0.706055f, 0.721191f, 0.736328f, 0.751465f, 0.764648f, 0.776855f, 0.789551f,
+ 0.801270f, 0.812500f, 0.823730f, 0.833496f, 0.843262f, 0.853027f, 0.861328f, 0.869629f, 0.878418f, 0.885742f, 0.893555f, 0.900391f,
+ 0.908203f, 0.914551f, 0.921387f, 0.927246f, 0.932617f, 0.938965f, 0.943848f, 0.949219f, 0.953613f, 0.959473f, 0.963867f, 0.968262f,
+ 0.972656f, 0.977051f, 0.987305f, 0.983887f, 0.980957f, 0.977051f, 0.974121f, 0.970703f, 0.012444f, 0.037933f, 0.065613f, 0.093811f,
+ 0.123474f, 0.153809f, 0.185059f, 0.215820f, 0.247559f, 0.279297f, 0.310547f, 0.341309f, 0.370361f, 0.399658f, 0.428467f, 0.457031f,
+ 0.482910f, 0.507812f, 0.533203f, 0.556152f, 0.579590f, 0.600098f, 0.621094f, 0.641113f, 0.659668f, 0.676270f, 0.695312f, 0.710449f,
+ 0.726074f, 0.740723f, 0.756348f, 0.769043f, 0.780762f, 0.794434f, 0.805176f, 0.816895f, 0.827637f, 0.837891f, 0.847168f, 0.855957f,
+ 0.865723f, 0.873535f, 0.882324f, 0.889648f, 0.897949f, 0.904297f, 0.911133f, 0.917480f, 0.924316f, 0.930176f, 0.936523f, 0.941895f,
+ 0.947266f, 0.952637f, 0.958008f, 0.962891f, 0.967285f, 0.971680f, 0.984863f, 0.981934f, 0.978516f, 0.975586f, 0.972656f, 0.969238f,
+ 0.010353f, 0.032043f, 0.055359f, 0.079529f, 0.104980f, 0.131836f, 0.159424f, 0.187866f, 0.216431f, 0.245239f, 0.275146f, 0.304199f,
+ 0.333496f, 0.362061f, 0.390869f, 0.417969f, 0.445068f, 0.471191f, 0.496582f, 0.520508f, 0.543457f, 0.566895f, 0.588867f, 0.608398f,
+ 0.628906f, 0.648438f, 0.666992f, 0.684570f, 0.701660f, 0.716797f, 0.732422f, 0.746582f, 0.760254f, 0.773438f, 0.786133f, 0.798340f,
+ 0.810547f, 0.821777f, 0.832520f, 0.842773f, 0.851074f, 0.860352f, 0.869629f, 0.878906f, 0.886230f, 0.894043f, 0.901855f, 0.908691f,
+ 0.915527f, 0.922363f, 0.928223f, 0.935059f, 0.939941f, 0.945312f, 0.950684f, 0.956055f, 0.962402f, 0.966797f, 0.982910f, 0.979980f,
+ 0.977051f, 0.973633f, 0.970703f, 0.968262f, 0.008598f, 0.027328f, 0.046417f, 0.067871f, 0.089905f, 0.113220f, 0.137695f, 0.163330f,
+ 0.189087f, 0.216064f, 0.243164f, 0.270752f, 0.298340f, 0.326416f, 0.354004f, 0.381348f, 0.407715f, 0.434082f, 0.460205f, 0.484863f,
+ 0.508789f, 0.532227f, 0.555176f, 0.577637f, 0.598145f, 0.618652f, 0.637695f, 0.657227f, 0.674805f, 0.691406f, 0.708008f, 0.723633f,
+ 0.738770f, 0.751953f, 0.766113f, 0.779785f, 0.791992f, 0.804199f, 0.815918f, 0.825684f, 0.836914f, 0.846680f, 0.856934f, 0.866211f,
+ 0.874512f, 0.882324f, 0.890625f, 0.898438f, 0.905273f, 0.913086f, 0.919922f, 0.926758f, 0.933105f, 0.938477f, 0.944824f, 0.951172f,
+ 0.955566f, 0.960938f, 0.980469f, 0.978027f, 0.974609f, 0.972168f, 0.969238f, 0.966797f, 0.007561f, 0.023315f, 0.040344f, 0.058228f,
+ 0.077148f, 0.097534f, 0.119995f, 0.142212f, 0.165649f, 0.190063f, 0.214722f, 0.240601f, 0.266846f, 0.293457f, 0.319824f, 0.346924f,
+ 0.372314f, 0.398438f, 0.424561f, 0.449463f, 0.474609f, 0.498535f, 0.521973f, 0.544434f, 0.566895f, 0.587402f, 0.608398f, 0.628418f,
+ 0.645996f, 0.665039f, 0.683105f, 0.699219f, 0.716309f, 0.731445f, 0.745117f, 0.760254f, 0.772949f, 0.786133f, 0.799316f, 0.809570f,
+ 0.820801f, 0.832031f, 0.843262f, 0.852051f, 0.861816f, 0.871094f, 0.880371f, 0.887695f, 0.895996f, 0.904297f, 0.911133f, 0.917969f,
+ 0.924805f, 0.931641f, 0.937012f, 0.943848f, 0.949707f, 0.954590f, 0.978027f, 0.976074f, 0.973145f, 0.970215f, 0.967773f, 0.965332f,
+ 0.006416f, 0.020065f, 0.034943f, 0.050537f, 0.067078f, 0.084900f, 0.104065f, 0.123962f, 0.145264f, 0.166748f, 0.189575f, 0.213501f,
+ 0.237305f, 0.262451f, 0.288574f, 0.313477f, 0.338623f, 0.364502f, 0.389893f, 0.414551f, 0.440186f, 0.464600f, 0.487549f, 0.510742f,
+ 0.534668f, 0.556641f, 0.578613f, 0.598145f, 0.618652f, 0.637207f, 0.655273f, 0.674805f, 0.690430f, 0.707031f, 0.724121f, 0.739258f,
+ 0.752930f, 0.767090f, 0.779785f, 0.792969f, 0.805176f, 0.816895f, 0.827637f, 0.838379f, 0.849121f, 0.858398f, 0.868652f, 0.876465f,
+ 0.885742f, 0.894043f, 0.901855f, 0.909180f, 0.916992f, 0.923828f, 0.930176f, 0.937012f, 0.943359f, 0.949707f, 0.975586f, 0.973633f,
+ 0.971191f, 0.968262f, 0.965820f, 0.963379f, 0.005802f, 0.017502f, 0.030045f, 0.043823f, 0.058014f, 0.074280f, 0.090759f, 0.108459f,
+ 0.127197f, 0.146484f, 0.167725f, 0.189087f, 0.211304f, 0.234497f, 0.258301f, 0.282471f, 0.307373f, 0.331299f, 0.356689f, 0.381104f,
+ 0.405762f, 0.430420f, 0.455078f, 0.478516f, 0.502441f, 0.524414f, 0.545898f, 0.568359f, 0.588867f, 0.608887f, 0.628906f, 0.646973f,
+ 0.665527f, 0.684082f, 0.701172f, 0.715820f, 0.731934f, 0.746582f, 0.760742f, 0.774414f, 0.787598f, 0.800781f, 0.812500f, 0.823730f,
+ 0.834961f, 0.845703f, 0.855469f, 0.865234f, 0.874512f, 0.883789f, 0.892090f, 0.899902f, 0.908203f, 0.916016f, 0.922852f, 0.930176f,
+ 0.936523f, 0.942871f, 0.972656f, 0.971191f, 0.968750f, 0.966309f, 0.963867f, 0.961426f, 0.004734f, 0.014984f, 0.026169f, 0.038177f,
+ 0.051208f, 0.065186f, 0.079468f, 0.095276f, 0.111633f, 0.129639f, 0.148071f, 0.167969f, 0.188599f, 0.208984f, 0.231689f, 0.254639f,
+ 0.277832f, 0.301025f, 0.325439f, 0.349854f, 0.373779f, 0.397705f, 0.422607f, 0.446045f, 0.469727f, 0.492676f, 0.514648f, 0.537598f,
+ 0.559570f, 0.580078f, 0.600586f, 0.620117f, 0.639648f, 0.658203f, 0.676758f, 0.692871f, 0.708984f, 0.725586f, 0.740723f, 0.755859f,
+ 0.769531f, 0.783691f, 0.796875f, 0.808594f, 0.820801f, 0.832520f, 0.842285f, 0.852539f, 0.862793f, 0.872070f, 0.881836f, 0.890137f,
+ 0.898926f, 0.906738f, 0.915039f, 0.922363f, 0.929199f, 0.936523f, 0.969727f, 0.968750f, 0.966797f, 0.964355f, 0.961914f, 0.959473f,
+ 0.004055f, 0.013588f, 0.023132f, 0.033722f, 0.044891f, 0.057343f, 0.069763f, 0.083923f, 0.098389f, 0.114441f, 0.131226f, 0.148682f,
+ 0.167603f, 0.186768f, 0.207031f, 0.228516f, 0.250732f, 0.272949f, 0.295410f, 0.318604f, 0.342285f, 0.365967f, 0.390381f, 0.413574f,
+ 0.437744f, 0.460938f, 0.484131f, 0.506348f, 0.528320f, 0.550781f, 0.572266f, 0.592773f, 0.613281f, 0.632812f, 0.651367f, 0.669922f,
+ 0.687500f, 0.704102f, 0.720215f, 0.735840f, 0.751465f, 0.764160f, 0.778809f, 0.792480f, 0.803711f, 0.816895f, 0.829102f, 0.840332f,
+ 0.850586f, 0.860352f, 0.870605f, 0.880371f, 0.889648f, 0.897949f, 0.905762f, 0.914551f, 0.922363f, 0.929199f, 0.967285f, 0.966797f,
+ 0.964844f, 0.961426f, 0.959473f, 0.958008f, 0.003611f, 0.011971f, 0.020401f, 0.030029f, 0.039185f, 0.050415f, 0.061737f, 0.074341f,
+ 0.086975f, 0.101074f, 0.115845f, 0.131958f, 0.148682f, 0.166626f, 0.185059f, 0.205200f, 0.224854f, 0.245483f, 0.267334f, 0.290771f,
+ 0.312988f, 0.335449f, 0.359619f, 0.382080f, 0.406250f, 0.429443f, 0.452881f, 0.475830f, 0.498779f, 0.520996f, 0.542480f, 0.563477f,
+ 0.584473f, 0.604980f, 0.625977f, 0.643555f, 0.663086f, 0.681152f, 0.698242f, 0.714355f, 0.729980f, 0.746582f, 0.760742f, 0.774902f,
+ 0.788086f, 0.801758f, 0.814941f, 0.826660f, 0.838867f, 0.848633f, 0.859863f, 0.869141f, 0.879395f, 0.889160f, 0.897949f, 0.906250f,
+ 0.914551f, 0.922363f, 0.963867f, 0.964355f, 0.961914f, 0.959961f, 0.957520f, 0.955078f, 0.003393f, 0.010361f, 0.018494f, 0.026337f,
+ 0.035187f, 0.044556f, 0.054596f, 0.065186f, 0.077515f, 0.089783f, 0.102783f, 0.117249f, 0.132446f, 0.148071f, 0.165649f, 0.183838f,
+ 0.202026f, 0.221313f, 0.241943f, 0.262939f, 0.285156f, 0.307129f, 0.329102f, 0.352539f, 0.375977f, 0.398438f, 0.421875f, 0.445312f,
+ 0.468750f, 0.490723f, 0.512695f, 0.534668f, 0.556641f, 0.577637f, 0.598633f, 0.619141f, 0.637695f, 0.656738f, 0.674805f, 0.692383f,
+ 0.709473f, 0.726074f, 0.742188f, 0.756836f, 0.771973f, 0.786133f, 0.799316f, 0.812012f, 0.824707f, 0.835938f, 0.848145f, 0.858887f,
+ 0.868164f, 0.878906f, 0.888184f, 0.897949f, 0.906250f, 0.914551f, 0.960938f, 0.960938f, 0.959473f, 0.957520f, 0.955078f, 0.953125f,
+ 0.003084f, 0.009521f, 0.016144f, 0.023346f, 0.031204f, 0.039520f, 0.048523f, 0.057953f, 0.068359f, 0.079895f, 0.091309f, 0.104126f,
+ 0.117920f, 0.132324f, 0.147949f, 0.164062f, 0.181396f, 0.199219f, 0.218872f, 0.238403f, 0.258545f, 0.279541f, 0.301758f, 0.323486f,
+ 0.346191f, 0.368408f, 0.391846f, 0.414795f, 0.437256f, 0.460693f, 0.483643f, 0.505371f, 0.527832f, 0.550293f, 0.571289f, 0.591797f,
+ 0.612305f, 0.632324f, 0.651855f, 0.670898f, 0.687500f, 0.705566f, 0.722168f, 0.737793f, 0.753418f, 0.768555f, 0.783691f, 0.796875f,
+ 0.811035f, 0.823242f, 0.834473f, 0.846191f, 0.857422f, 0.868652f, 0.878418f, 0.887695f, 0.897949f, 0.906250f, 0.958008f, 0.958008f,
+ 0.957031f, 0.954590f, 0.952637f, 0.950684f, 0.002666f, 0.008293f, 0.014297f, 0.021225f, 0.027847f, 0.035156f, 0.043274f, 0.051666f,
+ 0.060791f, 0.070801f, 0.081543f, 0.092407f, 0.104858f, 0.118530f, 0.131836f, 0.146606f, 0.162598f, 0.179443f, 0.196777f, 0.215210f,
+ 0.234375f, 0.254150f, 0.274414f, 0.295898f, 0.317871f, 0.340088f, 0.362549f, 0.385010f, 0.407959f, 0.430664f, 0.454590f, 0.476562f,
+ 0.499268f, 0.521484f, 0.543945f, 0.564941f, 0.585938f, 0.606934f, 0.626465f, 0.646484f, 0.665527f, 0.683594f, 0.701660f, 0.717773f,
+ 0.735352f, 0.751465f, 0.766113f, 0.781738f, 0.794922f, 0.808105f, 0.821289f, 0.833496f, 0.846191f, 0.857910f, 0.868164f, 0.878906f,
+ 0.889160f, 0.899414f, 0.954102f, 0.955566f, 0.953613f, 0.952148f, 0.950195f, 0.948730f, 0.002396f, 0.007427f, 0.012978f, 0.018646f,
+ 0.025024f, 0.031403f, 0.038788f, 0.046112f, 0.054260f, 0.063354f, 0.072693f, 0.082886f, 0.093689f, 0.105469f, 0.118164f, 0.130859f,
+ 0.145996f, 0.161011f, 0.177124f, 0.193359f, 0.211670f, 0.230225f, 0.249634f, 0.270020f, 0.290771f, 0.311768f, 0.333740f, 0.356201f,
+ 0.378906f, 0.401855f, 0.424561f, 0.447754f, 0.470215f, 0.493408f, 0.515137f, 0.537109f, 0.559570f, 0.580078f, 0.601074f, 0.621582f,
+ 0.642090f, 0.661621f, 0.679688f, 0.697754f, 0.715820f, 0.732422f, 0.749512f, 0.765137f, 0.779785f, 0.794434f, 0.808594f, 0.821289f,
+ 0.833496f, 0.846191f, 0.857910f, 0.869141f, 0.879883f, 0.889648f, 0.950195f, 0.952637f, 0.950684f, 0.948730f, 0.947266f, 0.945801f,
+ 0.002029f, 0.006672f, 0.011658f, 0.016937f, 0.022476f, 0.028305f, 0.034332f, 0.041351f, 0.048584f, 0.056671f, 0.064697f, 0.073853f,
+ 0.083923f, 0.094482f, 0.105225f, 0.117798f, 0.130615f, 0.144287f, 0.159302f, 0.174683f, 0.190430f, 0.208740f, 0.226318f, 0.245483f,
+ 0.264893f, 0.285400f, 0.307129f, 0.328369f, 0.350342f, 0.372803f, 0.395264f, 0.418701f, 0.441650f, 0.462891f, 0.486816f, 0.509277f,
+ 0.532227f, 0.553711f, 0.575684f, 0.596680f, 0.617676f, 0.638672f, 0.657715f, 0.676758f, 0.695312f, 0.712402f, 0.729492f, 0.746582f,
+ 0.762695f, 0.778320f, 0.793457f, 0.807129f, 0.820801f, 0.833984f, 0.846191f, 0.858887f, 0.869629f, 0.881836f, 0.947266f, 0.949219f,
+ 0.947754f, 0.946289f, 0.944824f, 0.942871f, 0.002142f, 0.006401f, 0.010841f, 0.015251f, 0.019760f, 0.025055f, 0.031113f, 0.037201f,
+ 0.043671f, 0.050598f, 0.057892f, 0.066101f, 0.075012f, 0.084351f, 0.093994f, 0.105164f, 0.117432f, 0.129517f, 0.142822f, 0.157104f,
+ 0.172119f, 0.188110f, 0.204956f, 0.223145f, 0.241577f, 0.260498f, 0.280762f, 0.301758f, 0.322998f, 0.345215f, 0.366943f, 0.389893f,
+ 0.412842f, 0.435791f, 0.458008f, 0.482178f, 0.504395f, 0.526855f, 0.548828f, 0.571289f, 0.592285f, 0.612793f, 0.634277f, 0.654297f,
+ 0.673340f, 0.692383f, 0.710938f, 0.729004f, 0.745117f, 0.762207f, 0.777832f, 0.792480f, 0.807129f, 0.821289f, 0.834961f, 0.847168f,
+ 0.859863f, 0.871582f, 0.943359f, 0.946289f, 0.944824f, 0.943359f, 0.941895f, 0.940430f, 0.001760f, 0.005562f, 0.009621f, 0.013710f,
+ 0.018417f, 0.022736f, 0.027939f, 0.033264f, 0.039185f, 0.045166f, 0.052460f, 0.059143f, 0.067261f, 0.075745f, 0.084106f, 0.094177f,
+ 0.104980f, 0.116455f, 0.128174f, 0.141113f, 0.155151f, 0.169922f, 0.184937f, 0.201660f, 0.219238f, 0.237549f, 0.256348f, 0.276367f,
+ 0.296875f, 0.317871f, 0.339844f, 0.361572f, 0.383789f, 0.407227f, 0.430908f, 0.453857f, 0.476807f, 0.498779f, 0.521973f, 0.543945f,
+ 0.567383f, 0.589355f, 0.609863f, 0.631348f, 0.651855f, 0.671875f, 0.690918f, 0.709961f, 0.727539f, 0.744141f, 0.761719f, 0.777344f,
+ 0.793457f, 0.808594f, 0.823242f, 0.835449f, 0.848633f, 0.861328f, 0.938965f, 0.941895f, 0.941406f, 0.940430f, 0.938477f, 0.937012f,
+ 0.001594f, 0.005283f, 0.008789f, 0.012383f, 0.016342f, 0.020523f, 0.025284f, 0.029968f, 0.035217f, 0.040741f, 0.046417f, 0.052948f,
+ 0.060120f, 0.067566f, 0.076294f, 0.084534f, 0.093750f, 0.104614f, 0.115173f, 0.126831f, 0.139160f, 0.152832f, 0.166748f, 0.181885f,
+ 0.198853f, 0.215698f, 0.233521f, 0.252197f, 0.271973f, 0.291992f, 0.313477f, 0.334717f, 0.357178f, 0.379395f, 0.401855f, 0.425537f,
+ 0.448242f, 0.471924f, 0.495361f, 0.517578f, 0.541016f, 0.562988f, 0.585938f, 0.607422f, 0.627930f, 0.649414f, 0.670410f, 0.688965f,
+ 0.708496f, 0.727539f, 0.744629f, 0.761719f, 0.778809f, 0.794922f, 0.809082f, 0.824219f, 0.838379f, 0.851074f, 0.935059f, 0.938965f,
+ 0.937988f, 0.937012f, 0.936035f, 0.933594f, 0.001564f, 0.004665f, 0.007973f, 0.011276f, 0.014908f, 0.018600f, 0.022675f, 0.027176f,
+ 0.031464f, 0.036621f, 0.042023f, 0.047974f, 0.054108f, 0.060822f, 0.068237f, 0.075684f, 0.084229f, 0.093567f, 0.103210f, 0.113892f,
+ 0.125000f, 0.137329f, 0.150269f, 0.164307f, 0.179810f, 0.194946f, 0.212158f, 0.229248f, 0.247925f, 0.267578f, 0.287842f, 0.308350f,
+ 0.330322f, 0.352051f, 0.374756f, 0.397461f, 0.420654f, 0.444092f, 0.466797f, 0.490723f, 0.514160f, 0.537109f, 0.560059f, 0.582031f,
+ 0.604980f, 0.626953f, 0.648926f, 0.668457f, 0.688477f, 0.708008f, 0.727539f, 0.745117f, 0.763672f, 0.779297f, 0.795410f, 0.811523f,
+ 0.826660f, 0.840332f, 0.930664f, 0.934570f, 0.934082f, 0.933594f, 0.932129f, 0.930664f, 0.001424f, 0.004261f, 0.007122f, 0.010239f,
+ 0.013374f, 0.016693f, 0.020401f, 0.024368f, 0.028595f, 0.033325f, 0.037964f, 0.043152f, 0.048340f, 0.054962f, 0.060730f, 0.067749f,
+ 0.075684f, 0.083862f, 0.092041f, 0.102051f, 0.112305f, 0.123657f, 0.135376f, 0.148071f, 0.161987f, 0.176270f, 0.192139f, 0.208252f,
+ 0.226196f, 0.244141f, 0.263672f, 0.283447f, 0.304199f, 0.325195f, 0.346924f, 0.370605f, 0.392822f, 0.416260f, 0.439209f, 0.463623f,
+ 0.486084f, 0.511230f, 0.534180f, 0.558105f, 0.580566f, 0.603516f, 0.625000f, 0.647461f, 0.668457f, 0.688965f, 0.708496f, 0.727539f,
+ 0.746582f, 0.764160f, 0.781738f, 0.798340f, 0.813477f, 0.829590f, 0.926758f, 0.931152f, 0.930664f, 0.929199f, 0.928223f, 0.927246f,
+ 0.001294f, 0.004196f, 0.006538f, 0.009346f, 0.012306f, 0.015335f, 0.018845f, 0.022003f, 0.025558f, 0.029816f, 0.034149f, 0.038605f,
+ 0.043915f, 0.049042f, 0.054810f, 0.061188f, 0.067993f, 0.075256f, 0.083130f, 0.091553f, 0.100769f, 0.110779f, 0.121643f, 0.133057f,
+ 0.145630f, 0.159058f, 0.173218f, 0.188721f, 0.204590f, 0.222290f, 0.240234f, 0.259277f, 0.279053f, 0.299561f, 0.321533f, 0.343506f,
+ 0.365723f, 0.389404f, 0.412354f, 0.436035f, 0.459961f, 0.484131f, 0.508301f, 0.532227f, 0.555176f, 0.579102f, 0.601562f, 0.624512f,
+ 0.646484f, 0.668457f, 0.688965f, 0.709473f, 0.729004f, 0.748047f, 0.766602f, 0.784668f, 0.800293f, 0.817383f, 0.921875f, 0.926270f,
+ 0.926270f, 0.925781f, 0.924316f, 0.923340f, 0.001081f, 0.003603f, 0.006027f, 0.008575f, 0.010979f, 0.013847f, 0.016937f, 0.020020f,
+ 0.023315f, 0.026917f, 0.030930f, 0.035156f, 0.039429f, 0.044098f, 0.049622f, 0.054779f, 0.060791f, 0.067566f, 0.074341f, 0.082336f,
+ 0.090515f, 0.099548f, 0.109070f, 0.119263f, 0.130981f, 0.143188f, 0.156250f, 0.170288f, 0.185303f, 0.201294f, 0.218262f, 0.236450f,
+ 0.255615f, 0.275391f, 0.295654f, 0.316895f, 0.339111f, 0.362061f, 0.385498f, 0.408936f, 0.432861f, 0.457275f, 0.481689f, 0.505371f,
+ 0.529785f, 0.553711f, 0.577637f, 0.601074f, 0.624023f, 0.646484f, 0.669434f, 0.689941f, 0.711426f, 0.731445f, 0.750977f, 0.770020f,
+ 0.787598f, 0.804688f, 0.916992f, 0.922363f, 0.922363f, 0.921875f, 0.920898f, 0.918945f, 0.001064f, 0.003231f, 0.005322f, 0.007710f,
+ 0.010323f, 0.012489f, 0.015244f, 0.018051f, 0.020798f, 0.024338f, 0.027893f, 0.031738f, 0.035553f, 0.039795f, 0.044495f, 0.049133f,
+ 0.054657f, 0.060608f, 0.066895f, 0.073792f, 0.081421f, 0.089050f, 0.097717f, 0.106934f, 0.117554f, 0.128540f, 0.140503f, 0.153442f,
+ 0.167236f, 0.182129f, 0.197998f, 0.214966f, 0.232422f, 0.251465f, 0.271240f, 0.291992f, 0.313232f, 0.335693f, 0.358643f, 0.382080f,
+ 0.406006f, 0.430176f, 0.454590f, 0.479004f, 0.503906f, 0.528320f, 0.552734f, 0.577637f, 0.601562f, 0.625000f, 0.648438f, 0.670898f,
+ 0.691895f, 0.713867f, 0.733887f, 0.754883f, 0.774414f, 0.791992f, 0.912109f, 0.917969f, 0.918457f, 0.916992f, 0.916016f, 0.915039f,
+ 0.000998f, 0.003012f, 0.005123f, 0.007114f, 0.009438f, 0.011360f, 0.013763f, 0.016510f, 0.018951f, 0.022171f, 0.025101f, 0.028305f,
+ 0.031830f, 0.035736f, 0.039795f, 0.044067f, 0.048950f, 0.053864f, 0.059601f, 0.066345f, 0.072815f, 0.079956f, 0.087402f, 0.096375f,
+ 0.105835f, 0.115479f, 0.126343f, 0.138184f, 0.150635f, 0.164062f, 0.178711f, 0.194214f, 0.210815f, 0.229004f, 0.247314f, 0.267090f,
+ 0.288330f, 0.309570f, 0.332275f, 0.355469f, 0.378418f, 0.402832f, 0.427490f, 0.452637f, 0.477783f, 0.501953f, 0.527832f, 0.552734f,
+ 0.577637f, 0.602051f, 0.626465f, 0.649902f, 0.672852f, 0.695312f, 0.717773f, 0.737793f, 0.758789f, 0.778809f, 0.906250f, 0.913086f,
+ 0.913574f, 0.912598f, 0.911621f, 0.910645f, 0.001059f, 0.002985f, 0.004475f, 0.006496f, 0.008545f, 0.010300f, 0.012581f, 0.014969f,
+ 0.017471f, 0.019852f, 0.022507f, 0.025864f, 0.028824f, 0.032135f, 0.036041f, 0.039795f, 0.043884f, 0.048706f, 0.053680f, 0.059113f,
+ 0.064819f, 0.071472f, 0.078491f, 0.086365f, 0.094360f, 0.103577f, 0.113403f, 0.124023f, 0.135620f, 0.147705f, 0.160889f, 0.175537f,
+ 0.191284f, 0.207764f, 0.225464f, 0.244263f, 0.264160f, 0.284912f, 0.306641f, 0.329102f, 0.352295f, 0.376465f, 0.400635f, 0.426025f,
+ 0.451416f, 0.476562f, 0.502930f, 0.527344f, 0.553711f, 0.579102f, 0.603027f, 0.627930f, 0.652344f, 0.675781f, 0.700195f, 0.722168f,
+ 0.742676f, 0.764648f, 0.901367f, 0.907715f, 0.908691f, 0.908203f, 0.907227f, 0.906250f, 0.000988f, 0.002577f, 0.004124f, 0.006042f,
+ 0.007603f, 0.009506f, 0.011299f, 0.013680f, 0.015778f, 0.017883f, 0.020554f, 0.023102f, 0.025940f, 0.028946f, 0.031891f, 0.035431f,
+ 0.039825f, 0.043671f, 0.048157f, 0.053009f, 0.058075f, 0.063782f, 0.069885f, 0.077087f, 0.084839f, 0.092712f, 0.101379f, 0.110779f,
+ 0.121155f, 0.132446f, 0.144775f, 0.157837f, 0.172363f, 0.187744f, 0.204590f, 0.222290f, 0.240601f, 0.260254f, 0.281494f, 0.303223f,
+ 0.325439f, 0.349609f, 0.373535f, 0.399170f, 0.424561f, 0.450439f, 0.475586f, 0.501953f, 0.528320f, 0.554688f, 0.580566f, 0.605957f,
+ 0.630859f, 0.656250f, 0.680176f, 0.704102f, 0.727051f, 0.749512f, 0.895508f, 0.902344f, 0.903320f, 0.902832f, 0.901855f, 0.901855f,
+ 0.000842f, 0.002253f, 0.003597f, 0.005352f, 0.007195f, 0.008804f, 0.010460f, 0.012100f, 0.014130f, 0.016281f, 0.018341f, 0.021057f,
+ 0.023193f, 0.025742f, 0.029022f, 0.031830f, 0.035278f, 0.039246f, 0.042999f, 0.047211f, 0.052032f, 0.056946f, 0.062744f, 0.068848f,
+ 0.075195f, 0.082642f, 0.090332f, 0.099060f, 0.108215f, 0.118469f, 0.129517f, 0.141724f, 0.154907f, 0.169434f, 0.184448f, 0.201172f,
+ 0.218506f, 0.237427f, 0.257324f, 0.278320f, 0.300293f, 0.323242f, 0.347412f, 0.372070f, 0.397217f, 0.423340f, 0.449707f, 0.476807f,
+ 0.502930f, 0.529785f, 0.556641f, 0.582520f, 0.609863f, 0.635254f, 0.660645f, 0.686035f, 0.710938f, 0.733887f, 0.889648f, 0.897461f,
+ 0.898926f, 0.896973f, 0.896973f, 0.896484f, 0.000660f, 0.002014f, 0.003531f, 0.004951f, 0.006424f, 0.007935f, 0.009392f, 0.011322f,
+ 0.012924f, 0.014824f, 0.016754f, 0.018906f, 0.020935f, 0.023376f, 0.026245f, 0.028809f, 0.031860f, 0.034821f, 0.038330f, 0.042236f,
+ 0.046387f, 0.050812f, 0.056061f, 0.061279f, 0.066956f, 0.073547f, 0.080566f, 0.088074f, 0.096802f, 0.106079f, 0.116089f, 0.127075f,
+ 0.138672f, 0.151855f, 0.165649f, 0.180908f, 0.197754f, 0.215332f, 0.234375f, 0.254150f, 0.275391f, 0.298096f, 0.321533f, 0.344971f,
+ 0.370361f, 0.396973f, 0.422852f, 0.449219f, 0.477295f, 0.504395f, 0.532227f, 0.558594f, 0.586914f, 0.614258f, 0.640625f, 0.666016f,
+ 0.692871f, 0.718262f, 0.882812f, 0.891602f, 0.892578f, 0.892090f, 0.892090f, 0.890625f, 0.000623f, 0.002073f, 0.003298f, 0.004292f,
+ 0.005589f, 0.007401f, 0.008377f, 0.010315f, 0.011871f, 0.013596f, 0.015213f, 0.016632f, 0.018829f, 0.020920f, 0.023239f, 0.025726f,
+ 0.028381f, 0.031250f, 0.034241f, 0.037781f, 0.041473f, 0.045349f, 0.049469f, 0.054199f, 0.059448f, 0.065186f, 0.071716f, 0.078613f,
+ 0.085999f, 0.093872f, 0.103516f, 0.112976f, 0.123840f, 0.135620f, 0.148804f, 0.162720f, 0.178223f, 0.194824f, 0.212280f, 0.231079f,
+ 0.251953f, 0.273193f, 0.295410f, 0.319580f, 0.343994f, 0.370117f, 0.396729f, 0.422852f, 0.450684f, 0.478516f, 0.507324f, 0.534668f,
+ 0.562988f, 0.591797f, 0.619629f, 0.646484f, 0.674316f, 0.700195f, 0.875488f, 0.885254f, 0.886719f, 0.886719f, 0.885742f, 0.885254f,
+ 0.000583f, 0.001746f, 0.002840f, 0.004143f, 0.005234f, 0.006516f, 0.007835f, 0.009460f, 0.010788f, 0.012062f, 0.013428f, 0.015053f,
+ 0.017349f, 0.018753f, 0.021271f, 0.023163f, 0.025284f, 0.027924f, 0.030655f, 0.033478f, 0.036957f, 0.040527f, 0.044037f, 0.048309f,
+ 0.053223f, 0.058319f, 0.063660f, 0.069763f, 0.076172f, 0.083679f, 0.091431f, 0.100647f, 0.110229f, 0.120667f, 0.132690f, 0.145386f,
+ 0.159668f, 0.174805f, 0.191284f, 0.208984f, 0.228516f, 0.248535f, 0.270996f, 0.293701f, 0.317383f, 0.342529f, 0.369629f, 0.396240f,
+ 0.424072f, 0.452148f, 0.480957f, 0.509277f, 0.539551f, 0.567871f, 0.596680f, 0.625977f, 0.654785f, 0.682129f, 0.868652f, 0.878906f,
+ 0.880371f, 0.879883f, 0.879883f, 0.879395f, 0.000535f, 0.001538f, 0.002930f, 0.003725f, 0.004986f, 0.005920f, 0.006973f, 0.008247f,
+ 0.009575f, 0.010841f, 0.012115f, 0.013550f, 0.015343f, 0.016983f, 0.018814f, 0.020523f, 0.022568f, 0.024887f, 0.027206f, 0.029907f,
+ 0.032959f, 0.035828f, 0.039185f, 0.042877f, 0.046967f, 0.051605f, 0.056213f, 0.061432f, 0.067749f, 0.073730f, 0.081238f, 0.089111f,
+ 0.097656f, 0.107300f, 0.118042f, 0.129883f, 0.142334f, 0.156250f, 0.171875f, 0.187866f, 0.206665f, 0.225708f, 0.246704f, 0.268799f,
+ 0.291992f, 0.316650f, 0.342529f, 0.369629f, 0.397217f, 0.425537f, 0.454590f, 0.484131f, 0.513672f, 0.544434f, 0.574219f, 0.604492f,
+ 0.633789f, 0.664062f, 0.861328f, 0.871582f, 0.873535f, 0.874512f, 0.873047f, 0.872559f, 0.000581f, 0.001668f, 0.002563f, 0.003471f,
+ 0.004494f, 0.005562f, 0.006580f, 0.007782f, 0.008690f, 0.009766f, 0.011261f, 0.012314f, 0.013901f, 0.014969f, 0.016479f, 0.018265f,
+ 0.020294f, 0.022156f, 0.024353f, 0.026505f, 0.029053f, 0.031799f, 0.034607f, 0.037964f, 0.041382f, 0.045471f, 0.049591f, 0.054047f,
+ 0.059326f, 0.065186f, 0.071411f, 0.078735f, 0.086304f, 0.094971f, 0.104126f, 0.114807f, 0.126587f, 0.138916f, 0.153564f, 0.169067f,
+ 0.185669f, 0.203613f, 0.223389f, 0.244629f, 0.266602f, 0.291260f, 0.316406f, 0.342773f, 0.370361f, 0.398926f, 0.427734f, 0.458008f,
+ 0.488770f, 0.520020f, 0.550293f, 0.582031f, 0.613281f, 0.645020f, 0.854004f, 0.865234f, 0.866699f, 0.867188f, 0.866699f, 0.866699f,
+ 0.000571f, 0.001365f, 0.002483f, 0.003033f, 0.004120f, 0.005054f, 0.005981f, 0.006737f, 0.007603f, 0.008675f, 0.009789f, 0.011078f,
+ 0.012413f, 0.013626f, 0.014908f, 0.016174f, 0.017792f, 0.019699f, 0.021591f, 0.023499f, 0.025635f, 0.028000f, 0.030533f, 0.033417f,
+ 0.036499f, 0.039948f, 0.043762f, 0.047943f, 0.052460f, 0.057465f, 0.062622f, 0.068848f, 0.076111f, 0.083557f, 0.092102f, 0.101562f,
+ 0.111816f, 0.123230f, 0.135864f, 0.150024f, 0.165771f, 0.182373f, 0.200806f, 0.221191f, 0.242920f, 0.265869f, 0.290283f, 0.316406f,
+ 0.343262f, 0.371582f, 0.400879f, 0.431396f, 0.463623f, 0.494629f, 0.526367f, 0.558105f, 0.591309f, 0.624023f, 0.845215f, 0.856934f,
+ 0.859375f, 0.859375f, 0.859863f, 0.860352f, 0.000411f, 0.001296f, 0.002012f, 0.002808f, 0.003754f, 0.004543f, 0.005215f, 0.006012f,
+ 0.006725f, 0.007851f, 0.008888f, 0.009979f, 0.010994f, 0.012009f, 0.013062f, 0.014549f, 0.016113f, 0.017441f, 0.019073f, 0.020767f,
+ 0.022598f, 0.024689f, 0.026764f, 0.029358f, 0.032043f, 0.034760f, 0.038391f, 0.041779f, 0.045380f, 0.050110f, 0.055054f, 0.060394f,
+ 0.066650f, 0.073120f, 0.080688f, 0.089233f, 0.098450f, 0.108582f, 0.120178f, 0.133057f, 0.146973f, 0.162354f, 0.179565f, 0.198364f,
+ 0.218750f, 0.240967f, 0.264648f, 0.290039f, 0.316650f, 0.344971f, 0.374023f, 0.404541f, 0.435791f, 0.467773f, 0.500977f, 0.535156f,
+ 0.569336f, 0.601562f, 0.836914f, 0.850098f, 0.852051f, 0.852539f, 0.852539f, 0.852051f, 0.000408f, 0.001071f, 0.001857f, 0.002573f,
+ 0.003338f, 0.004078f, 0.004692f, 0.005379f, 0.006046f, 0.007275f, 0.007957f, 0.008606f, 0.009598f, 0.010864f, 0.011658f, 0.013084f,
+ 0.013977f, 0.015366f, 0.016724f, 0.018402f, 0.019669f, 0.021759f, 0.023697f, 0.025726f, 0.027954f, 0.030640f, 0.033356f, 0.036530f,
+ 0.039948f, 0.043701f, 0.047791f, 0.052704f, 0.057770f, 0.063782f, 0.070129f, 0.077881f, 0.085999f, 0.095337f, 0.105591f, 0.116882f,
+ 0.130005f, 0.143921f, 0.159302f, 0.177246f, 0.196411f, 0.217163f, 0.239746f, 0.263916f, 0.290039f, 0.317871f, 0.346924f, 0.377441f,
+ 0.408936f, 0.442139f, 0.476074f, 0.509766f, 0.545410f, 0.580078f, 0.828613f, 0.841309f, 0.843262f, 0.844238f, 0.843750f, 0.844238f,
+ 0.000322f, 0.001009f, 0.001674f, 0.002262f, 0.002949f, 0.003633f, 0.004250f, 0.004780f, 0.005478f, 0.006256f, 0.007248f, 0.007919f,
+ 0.008720f, 0.009552f, 0.010277f, 0.011391f, 0.012291f, 0.013466f, 0.014786f, 0.015976f, 0.017288f, 0.019043f, 0.020477f, 0.022385f,
+ 0.024292f, 0.026276f, 0.029175f, 0.031769f, 0.034546f, 0.037842f, 0.041626f, 0.045868f, 0.050293f, 0.055084f, 0.060669f, 0.067688f,
+ 0.074585f, 0.083008f, 0.092102f, 0.102234f, 0.113525f, 0.126587f, 0.140869f, 0.156860f, 0.174805f, 0.194214f, 0.215698f, 0.239014f,
+ 0.264404f, 0.291016f, 0.320068f, 0.350098f, 0.382080f, 0.414551f, 0.449463f, 0.485107f, 0.520996f, 0.557617f, 0.818848f, 0.833496f,
+ 0.836426f, 0.836914f, 0.836426f, 0.835938f, 0.000483f, 0.000841f, 0.001632f, 0.002142f, 0.002678f, 0.003359f, 0.003830f, 0.004333f,
+ 0.005077f, 0.005527f, 0.006104f, 0.006908f, 0.007675f, 0.008392f, 0.009216f, 0.009789f, 0.010880f, 0.011719f, 0.012817f, 0.013809f,
+ 0.015068f, 0.016357f, 0.017883f, 0.019485f, 0.021271f, 0.022995f, 0.025162f, 0.027359f, 0.029755f, 0.032806f, 0.036133f, 0.039459f,
+ 0.043091f, 0.047821f, 0.052368f, 0.058258f, 0.064514f, 0.071472f, 0.079224f, 0.088623f, 0.098694f, 0.109924f, 0.123230f, 0.137817f,
+ 0.154053f, 0.172363f, 0.192261f, 0.214478f, 0.238647f, 0.265137f, 0.292725f, 0.322998f, 0.354492f, 0.387695f, 0.422363f, 0.458740f,
+ 0.495605f, 0.533691f, 0.809570f, 0.824219f, 0.826660f, 0.827148f, 0.828125f, 0.827148f, 0.000240f, 0.000906f, 0.001379f, 0.001807f,
+ 0.002495f, 0.002916f, 0.003490f, 0.004139f, 0.004471f, 0.004898f, 0.005638f, 0.005978f, 0.006874f, 0.007313f, 0.007957f, 0.008698f,
+ 0.009560f, 0.010178f, 0.011345f, 0.012177f, 0.012985f, 0.014214f, 0.015274f, 0.016708f, 0.017929f, 0.019882f, 0.021393f, 0.023560f,
+ 0.025406f, 0.028137f, 0.030472f, 0.033752f, 0.036896f, 0.040619f, 0.044952f, 0.049622f, 0.055298f, 0.061249f, 0.068420f, 0.075928f,
+ 0.084900f, 0.095398f, 0.107300f, 0.119934f, 0.134766f, 0.151733f, 0.170410f, 0.191284f, 0.213867f, 0.238647f, 0.265869f, 0.295654f,
+ 0.326660f, 0.359863f, 0.394775f, 0.432129f, 0.469482f, 0.508789f, 0.798340f, 0.814941f, 0.817871f, 0.818359f, 0.818848f, 0.818848f,
+ 0.000376f, 0.000870f, 0.001291f, 0.001619f, 0.002251f, 0.002520f, 0.003016f, 0.003502f, 0.004036f, 0.004299f, 0.004723f, 0.005234f,
+ 0.005840f, 0.006512f, 0.006908f, 0.007595f, 0.008003f, 0.008797f, 0.009773f, 0.010536f, 0.011284f, 0.012161f, 0.013237f, 0.014465f,
+ 0.015579f, 0.016968f, 0.018402f, 0.019882f, 0.021759f, 0.023621f, 0.026138f, 0.028488f, 0.031738f, 0.034668f, 0.038239f, 0.042389f,
+ 0.046783f, 0.052094f, 0.058319f, 0.064941f, 0.072815f, 0.081726f, 0.092102f, 0.103516f, 0.117188f, 0.132202f, 0.149048f, 0.168091f,
+ 0.189941f, 0.213745f, 0.239990f, 0.268311f, 0.299316f, 0.332275f, 0.367188f, 0.403076f, 0.442871f, 0.483398f, 0.788086f, 0.805176f,
+ 0.808105f, 0.808594f, 0.809082f, 0.809082f, 0.000386f, 0.000765f, 0.000998f, 0.001537f, 0.001833f, 0.002407f, 0.002529f, 0.003113f,
+ 0.003334f, 0.003841f, 0.004192f, 0.004585f, 0.005096f, 0.005543f, 0.006073f, 0.006405f, 0.007118f, 0.007641f, 0.008278f, 0.008957f,
+ 0.009651f, 0.010498f, 0.011307f, 0.012184f, 0.013199f, 0.014343f, 0.015671f, 0.016678f, 0.018585f, 0.019852f, 0.021881f, 0.023987f,
+ 0.026398f, 0.029099f, 0.032227f, 0.035339f, 0.039246f, 0.043915f, 0.048859f, 0.054688f, 0.061554f, 0.069519f, 0.078247f, 0.088379f,
+ 0.100037f, 0.113770f, 0.129272f, 0.146606f, 0.166626f, 0.189575f, 0.214111f, 0.241577f, 0.271973f, 0.304199f, 0.339844f, 0.375977f,
+ 0.415527f, 0.457275f, 0.776855f, 0.794434f, 0.797363f, 0.797852f, 0.798828f, 0.799316f, 0.000232f, 0.000636f, 0.000996f, 0.001201f,
+ 0.001721f, 0.002029f, 0.002340f, 0.002802f, 0.003012f, 0.003462f, 0.003693f, 0.004059f, 0.004295f, 0.004822f, 0.005077f, 0.005623f,
+ 0.006126f, 0.006653f, 0.007027f, 0.007561f, 0.008049f, 0.008904f, 0.009399f, 0.010300f, 0.011200f, 0.012115f, 0.013092f, 0.014221f,
+ 0.015671f, 0.016891f, 0.018433f, 0.020294f, 0.022064f, 0.024277f, 0.026688f, 0.029678f, 0.032654f, 0.036499f, 0.040955f, 0.045715f,
+ 0.051514f, 0.058014f, 0.065674f, 0.074707f, 0.084717f, 0.096802f, 0.111023f, 0.126709f, 0.144775f, 0.165771f, 0.189209f, 0.215820f,
+ 0.244385f, 0.275879f, 0.310547f, 0.348145f, 0.387695f, 0.429932f, 0.765137f, 0.783203f, 0.787109f, 0.788574f, 0.788574f, 0.789551f,
+ 0.000171f, 0.000518f, 0.001106f, 0.001242f, 0.001475f, 0.001939f, 0.002092f, 0.002254f, 0.002607f, 0.002930f, 0.003084f, 0.003382f,
+ 0.003674f, 0.004040f, 0.004395f, 0.004780f, 0.005157f, 0.005653f, 0.006088f, 0.006355f, 0.006870f, 0.007420f, 0.008057f, 0.008667f,
+ 0.009361f, 0.010040f, 0.011101f, 0.011803f, 0.012711f, 0.013962f, 0.015343f, 0.016586f, 0.018036f, 0.020142f, 0.022079f, 0.024399f,
+ 0.027023f, 0.030075f, 0.033569f, 0.037750f, 0.042603f, 0.048096f, 0.054718f, 0.062134f, 0.071045f, 0.081299f, 0.093445f, 0.107605f,
+ 0.124268f, 0.142944f, 0.165405f, 0.189941f, 0.218262f, 0.249268f, 0.282227f, 0.319336f, 0.359375f, 0.402832f, 0.752930f, 0.771973f,
+ 0.775879f, 0.776855f, 0.777832f, 0.777832f, 0.000204f, 0.000608f, 0.000865f, 0.001011f, 0.001362f, 0.001632f, 0.001817f, 0.001930f,
+ 0.002274f, 0.002491f, 0.002796f, 0.002932f, 0.003139f, 0.003429f, 0.003736f, 0.004055f, 0.004448f, 0.004829f, 0.004971f, 0.005497f,
+ 0.005859f, 0.006298f, 0.006741f, 0.007080f, 0.007687f, 0.008308f, 0.009087f, 0.009880f, 0.010735f, 0.011528f, 0.012375f, 0.013664f,
+ 0.014862f, 0.016464f, 0.017868f, 0.019852f, 0.022156f, 0.024490f, 0.027435f, 0.030853f, 0.034637f, 0.039154f, 0.044495f, 0.050964f,
+ 0.058441f, 0.067383f, 0.077759f, 0.090332f, 0.104797f, 0.121826f, 0.142334f, 0.164795f, 0.191528f, 0.221313f, 0.254150f, 0.290771f,
+ 0.330078f, 0.374268f, 0.740234f, 0.759277f, 0.763672f, 0.766113f, 0.766602f, 0.766113f, 0.000150f, 0.000514f, 0.000666f, 0.000865f,
+ 0.001163f, 0.001389f, 0.001540f, 0.001672f, 0.001940f, 0.002110f, 0.002302f, 0.002419f, 0.002745f, 0.002974f, 0.003120f, 0.003366f,
+ 0.003695f, 0.003815f, 0.004173f, 0.004574f, 0.004879f, 0.005165f, 0.005646f, 0.006058f, 0.006481f, 0.006969f, 0.007626f, 0.007881f,
+ 0.008751f, 0.009445f, 0.010231f, 0.011246f, 0.012222f, 0.013268f, 0.014641f, 0.015976f, 0.017792f, 0.019867f, 0.021912f, 0.024704f,
+ 0.027786f, 0.031494f, 0.036011f, 0.041229f, 0.047363f, 0.054962f, 0.063904f, 0.074463f, 0.087036f, 0.102295f, 0.120483f, 0.141113f,
+ 0.166260f, 0.194214f, 0.226196f, 0.261719f, 0.301514f, 0.345459f, 0.727051f, 0.747070f, 0.751953f, 0.753418f, 0.754395f, 0.754883f,
+ 0.000103f, 0.000251f, 0.000628f, 0.000912f, 0.000978f, 0.001191f, 0.001365f, 0.001507f, 0.001513f, 0.001757f, 0.001980f, 0.002121f,
+ 0.002316f, 0.002373f, 0.002645f, 0.002909f, 0.003012f, 0.003305f, 0.003538f, 0.003775f, 0.004070f, 0.004246f, 0.004642f, 0.004986f,
+ 0.005394f, 0.005802f, 0.006031f, 0.006565f, 0.006969f, 0.007618f, 0.008293f, 0.008980f, 0.009766f, 0.010612f, 0.011528f, 0.012802f,
+ 0.014198f, 0.015671f, 0.017517f, 0.019592f, 0.021957f, 0.024918f, 0.028442f, 0.032562f, 0.037567f, 0.043762f, 0.051025f, 0.059753f,
+ 0.071045f, 0.084412f, 0.099792f, 0.119385f, 0.141846f, 0.167969f, 0.199341f, 0.233521f, 0.272461f, 0.315674f, 0.712891f, 0.733887f,
+ 0.738770f, 0.740234f, 0.741211f, 0.741699f, 0.000185f, 0.000434f, 0.000489f, 0.000732f, 0.000874f, 0.000968f, 0.001122f, 0.001124f,
+ 0.001371f, 0.001423f, 0.001639f, 0.001693f, 0.001805f, 0.002094f, 0.002241f, 0.002356f, 0.002567f, 0.002691f, 0.002871f, 0.003063f,
+ 0.003195f, 0.003582f, 0.003790f, 0.004089f, 0.004372f, 0.004536f, 0.005085f, 0.005314f, 0.005699f, 0.006153f, 0.006672f, 0.007202f,
+ 0.007805f, 0.008522f, 0.009216f, 0.010071f, 0.011086f, 0.012184f, 0.013596f, 0.015297f, 0.017014f, 0.019363f, 0.021988f, 0.025299f,
+ 0.029282f, 0.033936f, 0.040070f, 0.047028f, 0.056519f, 0.067932f, 0.080872f, 0.098083f, 0.118469f, 0.143188f, 0.171753f, 0.205200f,
+ 0.243286f, 0.286133f, 0.698730f, 0.721680f, 0.725098f, 0.727051f, 0.728027f, 0.728516f, 0.000116f, 0.000267f, 0.000565f, 0.000505f,
+ 0.000648f, 0.000772f, 0.000813f, 0.001031f, 0.001107f, 0.001184f, 0.001335f, 0.001391f, 0.001451f, 0.001633f, 0.001798f, 0.001874f,
+ 0.002090f, 0.002192f, 0.002392f, 0.002464f, 0.002707f, 0.002895f, 0.003044f, 0.003206f, 0.003468f, 0.003666f, 0.003887f, 0.004261f,
+ 0.004524f, 0.004898f, 0.005379f, 0.005711f, 0.006130f, 0.006721f, 0.007267f, 0.007912f, 0.008659f, 0.009575f, 0.010475f, 0.011749f,
+ 0.013252f, 0.014717f, 0.016815f, 0.019302f, 0.022369f, 0.025955f, 0.030502f, 0.036285f, 0.043579f, 0.052795f, 0.064453f, 0.078735f,
+ 0.096497f, 0.118591f, 0.145508f, 0.177368f, 0.213989f, 0.256592f, 0.683105f, 0.707031f, 0.710938f, 0.713379f, 0.714844f, 0.714844f,
+ 0.000223f, 0.000239f, 0.000286f, 0.000476f, 0.000580f, 0.000647f, 0.000715f, 0.000843f, 0.000914f, 0.000950f, 0.001090f, 0.001163f,
+ 0.001259f, 0.001328f, 0.001392f, 0.001560f, 0.001549f, 0.001775f, 0.001868f, 0.001999f, 0.002199f, 0.002235f, 0.002436f, 0.002575f,
+ 0.002842f, 0.002892f, 0.003111f, 0.003401f, 0.003563f, 0.003887f, 0.004196f, 0.004505f, 0.004791f, 0.005142f, 0.005684f, 0.006153f,
+ 0.006710f, 0.007378f, 0.008064f, 0.008881f, 0.009979f, 0.011177f, 0.012779f, 0.014435f, 0.016647f, 0.019150f, 0.022583f, 0.027252f,
+ 0.033051f, 0.040039f, 0.049561f, 0.061340f, 0.076843f, 0.096313f, 0.120544f, 0.150513f, 0.185547f, 0.227173f, 0.668457f, 0.692383f,
+ 0.696289f, 0.698242f, 0.699219f, 0.701172f, 0.000000f, 0.000109f, 0.000315f, 0.000449f, 0.000511f, 0.000507f, 0.000538f, 0.000653f,
+ 0.000724f, 0.000749f, 0.000830f, 0.000893f, 0.001007f, 0.001079f, 0.001189f, 0.001163f, 0.001335f, 0.001307f, 0.001502f, 0.001575f,
+ 0.001627f, 0.001778f, 0.001933f, 0.002029f, 0.002155f, 0.002254f, 0.002401f, 0.002535f, 0.002829f, 0.002943f, 0.003143f, 0.003422f,
+ 0.003710f, 0.003990f, 0.004318f, 0.004627f, 0.005108f, 0.005585f, 0.006142f, 0.006641f, 0.007378f, 0.008354f, 0.009430f, 0.010628f,
+ 0.012123f, 0.014015f, 0.016541f, 0.019836f, 0.023849f, 0.029312f, 0.036774f, 0.046356f, 0.058868f, 0.075562f, 0.097107f, 0.124634f,
+ 0.157837f, 0.197754f, 0.653320f, 0.677734f, 0.682129f, 0.684082f, 0.685547f, 0.684570f, 0.000166f, 0.000195f, 0.000256f, 0.000372f,
+ 0.000386f, 0.000415f, 0.000515f, 0.000432f, 0.000579f, 0.000606f, 0.000706f, 0.000745f, 0.000764f, 0.000837f, 0.000853f, 0.000993f,
+ 0.001034f, 0.001066f, 0.001156f, 0.001203f, 0.001339f, 0.001418f, 0.001470f, 0.001612f, 0.001614f, 0.001707f, 0.001850f, 0.001986f,
+ 0.002151f, 0.002254f, 0.002499f, 0.002560f, 0.002794f, 0.003000f, 0.003212f, 0.003510f, 0.003761f, 0.004086f, 0.004475f, 0.004967f,
+ 0.005428f, 0.006134f, 0.006840f, 0.007786f, 0.008858f, 0.010033f, 0.011909f, 0.014137f, 0.016907f, 0.020767f, 0.025894f, 0.033386f,
+ 0.043274f, 0.056854f, 0.075439f, 0.099548f, 0.130737f, 0.169434f, 0.634277f, 0.661133f, 0.667480f, 0.668945f, 0.669922f, 0.670898f,
+ 0.000115f, 0.000119f, 0.000230f, 0.000304f, 0.000221f, 0.000380f, 0.000322f, 0.000351f, 0.000453f, 0.000527f, 0.000535f, 0.000558f,
+ 0.000595f, 0.000675f, 0.000707f, 0.000670f, 0.000776f, 0.000812f, 0.000839f, 0.000911f, 0.000974f, 0.001033f, 0.001082f, 0.001154f,
+ 0.001209f, 0.001268f, 0.001416f, 0.001432f, 0.001607f, 0.001775f, 0.001877f, 0.001911f, 0.002041f, 0.002207f, 0.002380f, 0.002563f,
+ 0.002741f, 0.002956f, 0.003281f, 0.003513f, 0.003902f, 0.004353f, 0.004803f, 0.005405f, 0.006256f, 0.007072f, 0.008263f, 0.009659f,
+ 0.011627f, 0.014221f, 0.017792f, 0.022919f, 0.030075f, 0.040497f, 0.055878f, 0.076721f, 0.104980f, 0.141357f, 0.618652f, 0.644531f,
+ 0.650391f, 0.652832f, 0.653320f, 0.654785f, 0.000000f, 0.000122f, 0.000142f, 0.000227f, 0.000248f, 0.000246f, 0.000296f, 0.000254f,
+ 0.000308f, 0.000329f, 0.000387f, 0.000437f, 0.000443f, 0.000504f, 0.000515f, 0.000535f, 0.000566f, 0.000592f, 0.000618f, 0.000641f,
+ 0.000706f, 0.000746f, 0.000787f, 0.000839f, 0.000878f, 0.000920f, 0.001043f, 0.001041f, 0.001136f, 0.001199f, 0.001258f, 0.001393f,
+ 0.001428f, 0.001549f, 0.001632f, 0.001856f, 0.001945f, 0.002079f, 0.002310f, 0.002489f, 0.002708f, 0.002996f, 0.003315f, 0.003759f,
+ 0.004177f, 0.004803f, 0.005619f, 0.006527f, 0.007793f, 0.009468f, 0.011917f, 0.015152f, 0.019897f, 0.027298f, 0.038910f, 0.055908f,
+ 0.080811f, 0.114563f, 0.600586f, 0.628906f, 0.634277f, 0.636719f, 0.637207f, 0.638672f, 0.000000f, 0.000000f, 0.000106f, 0.000137f,
+ 0.000172f, 0.000211f, 0.000189f, 0.000226f, 0.000230f, 0.000248f, 0.000293f, 0.000251f, 0.000264f, 0.000321f, 0.000343f, 0.000399f,
+ 0.000368f, 0.000401f, 0.000499f, 0.000479f, 0.000498f, 0.000526f, 0.000550f, 0.000595f, 0.000631f, 0.000645f, 0.000726f, 0.000717f,
+ 0.000786f, 0.000902f, 0.000865f, 0.000916f, 0.000989f, 0.001059f, 0.001165f, 0.001246f, 0.001279f, 0.001408f, 0.001566f, 0.001628f,
+ 0.001808f, 0.001991f, 0.002165f, 0.002466f, 0.002766f, 0.003084f, 0.003534f, 0.004250f, 0.005016f, 0.006130f, 0.007584f, 0.009605f,
+ 0.012718f, 0.017395f, 0.025131f, 0.038269f, 0.058899f, 0.089661f, 0.582031f, 0.611328f, 0.616699f, 0.620117f, 0.621094f, 0.622559f,
+ 0.000000f, 0.000108f, 0.000104f, 0.000095f, 0.000117f, 0.000117f, 0.000122f, 0.000143f, 0.000147f, 0.000164f, 0.000174f, 0.000216f,
+ 0.000191f, 0.000227f, 0.000241f, 0.000250f, 0.000257f, 0.000271f, 0.000301f, 0.000298f, 0.000317f, 0.000344f, 0.000370f, 0.000392f,
+ 0.000404f, 0.000427f, 0.000491f, 0.000491f, 0.000519f, 0.000535f, 0.000611f, 0.000601f, 0.000668f, 0.000698f, 0.000767f, 0.000838f,
+ 0.000865f, 0.000895f, 0.000993f, 0.001066f, 0.001161f, 0.001242f, 0.001415f, 0.001521f, 0.001743f, 0.001901f, 0.002209f, 0.002523f,
+ 0.003038f, 0.003601f, 0.004478f, 0.005699f, 0.007545f, 0.010437f, 0.015175f, 0.023682f, 0.039429f, 0.066406f, 0.563477f, 0.593262f,
+ 0.598633f, 0.602051f, 0.602539f, 0.603516f, 0.000000f, 0.000101f, 0.000093f, 0.000087f, 0.000082f, 0.000078f, 0.000084f, 0.000087f,
+ 0.000093f, 0.000094f, 0.000099f, 0.000104f, 0.000114f, 0.000123f, 0.000158f, 0.000163f, 0.000166f, 0.000178f, 0.000177f, 0.000214f,
+ 0.000191f, 0.000208f, 0.000212f, 0.000247f, 0.000268f, 0.000263f, 0.000272f, 0.000287f, 0.000310f, 0.000336f, 0.000353f, 0.000368f,
+ 0.000396f, 0.000408f, 0.000453f, 0.000476f, 0.000511f, 0.000540f, 0.000615f, 0.000635f, 0.000682f, 0.000751f, 0.000812f, 0.000908f,
+ 0.000987f, 0.001116f, 0.001278f, 0.001431f, 0.001702f, 0.002047f, 0.002512f, 0.003126f, 0.004181f, 0.005817f, 0.008553f, 0.013489f,
+ 0.023697f, 0.045288f, 0.544922f, 0.575684f, 0.581543f, 0.584473f, 0.585938f, 0.587402f, 0.000109f, 0.000091f, 0.000081f, 0.000075f,
+ 0.000070f, 0.000067f, 0.000064f, 0.000061f, 0.000057f, 0.000054f, 0.000058f, 0.000075f, 0.000062f, 0.000064f, 0.000085f, 0.000068f,
+ 0.000092f, 0.000094f, 0.000103f, 0.000110f, 0.000113f, 0.000119f, 0.000141f, 0.000141f, 0.000148f, 0.000152f, 0.000159f, 0.000164f,
+ 0.000175f, 0.000188f, 0.000184f, 0.000218f, 0.000233f, 0.000223f, 0.000253f, 0.000265f, 0.000282f, 0.000321f, 0.000322f, 0.000351f,
+ 0.000371f, 0.000405f, 0.000443f, 0.000478f, 0.000515f, 0.000571f, 0.000652f, 0.000733f, 0.000856f, 0.001011f, 0.001227f, 0.001531f,
+ 0.002029f, 0.002817f, 0.004215f, 0.006874f, 0.012390f, 0.027405f, 0.525879f, 0.557129f, 0.563477f, 0.566895f, 0.568848f, 0.569824f,
+ 0.000094f, 0.000073f, 0.000065f, 0.000060f, 0.000055f, 0.000052f, 0.000049f, 0.000048f, 0.000046f, 0.000045f, 0.000042f, 0.000040f,
+ 0.000040f, 0.000037f, 0.000035f, 0.000035f, 0.000042f, 0.000036f, 0.000049f, 0.000051f, 0.000055f, 0.000056f, 0.000059f, 0.000062f,
+ 0.000064f, 0.000078f, 0.000071f, 0.000079f, 0.000088f, 0.000091f, 0.000093f, 0.000099f, 0.000103f, 0.000110f, 0.000125f, 0.000123f,
+ 0.000127f, 0.000151f, 0.000151f, 0.000161f, 0.000169f, 0.000179f, 0.000204f, 0.000219f, 0.000240f, 0.000267f, 0.000294f, 0.000321f,
+ 0.000378f, 0.000438f, 0.000524f, 0.000628f, 0.000818f, 0.001125f, 0.001693f, 0.002888f, 0.005638f, 0.013580f, 0.505859f, 0.539062f,
+ 0.544922f, 0.548340f, 0.550293f, 0.550781f, 0.000064f, 0.000048f, 0.000041f, 0.000037f, 0.000035f, 0.000034f, 0.000032f, 0.000031f,
+ 0.000030f, 0.000029f, 0.000028f, 0.000028f, 0.000027f, 0.000027f, 0.000026f, 0.000025f, 0.000024f, 0.000023f, 0.000022f, 0.000021f,
+ 0.000020f, 0.000019f, 0.000019f, 0.000023f, 0.000021f, 0.000022f, 0.000026f, 0.000029f, 0.000032f, 0.000031f, 0.000036f, 0.000037f,
+ 0.000036f, 0.000044f, 0.000046f, 0.000048f, 0.000052f, 0.000054f, 0.000056f, 0.000061f, 0.000070f, 0.000073f, 0.000076f, 0.000081f,
+ 0.000082f, 0.000095f, 0.000105f, 0.000120f, 0.000126f, 0.000143f, 0.000173f, 0.000203f, 0.000267f, 0.000346f, 0.000505f, 0.000853f,
+ 0.001829f, 0.005222f, 0.487061f, 0.519531f, 0.527344f, 0.529785f, 0.531738f, 0.532715f, 0.000000f, 0.000002f, 0.000003f, 0.000004f,
+ 0.000008f, 0.000008f, 0.000008f, 0.000010f, 0.000009f, 0.000010f, 0.000010f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f,
+ 0.000012f, 0.000011f, 0.000012f, 0.000011f, 0.000012f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000010f,
+ 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000007f, 0.000008f, 0.000009f, 0.000010f, 0.000012f, 0.000012f, 0.000015f,
+ 0.000013f, 0.000015f, 0.000018f, 0.000020f, 0.000021f, 0.000022f, 0.000022f, 0.000024f, 0.000026f, 0.000027f, 0.000034f, 0.000043f,
+ 0.000049f, 0.000065f, 0.000089f, 0.000138f, 0.000293f, 0.001143f, 0.466553f, 0.500488f, 0.508301f, 0.510742f, 0.512207f, 0.513672f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000004f, 0.000006f, 0.000023f, 0.446777f, 0.482178f,
+ 0.489746f, 0.492676f, 0.494629f, 0.496094f,
+ },
+ {
+ 0.032318f, 0.095032f, 0.152344f, 0.205322f, 0.254883f, 0.299316f, 0.342041f, 0.380859f, 0.416504f, 0.449707f, 0.481201f, 0.508789f,
+ 0.537109f, 0.562012f, 0.584961f, 0.608398f, 0.628418f, 0.648926f, 0.666504f, 0.684570f, 0.701172f, 0.716797f, 0.731934f, 0.746094f,
+ 0.759766f, 0.770996f, 0.784668f, 0.795898f, 0.806641f, 0.817871f, 0.827637f, 0.837402f, 0.846680f, 0.855469f, 0.863770f, 0.872559f,
+ 0.879883f, 0.887695f, 0.895508f, 0.901367f, 0.909180f, 0.915527f, 0.921387f, 0.927734f, 0.934082f, 0.939453f, 0.944824f, 0.950684f,
+ 0.955566f, 0.960449f, 0.965332f, 0.969238f, 0.974121f, 0.978516f, 0.982910f, 0.986816f, 0.990723f, 0.994629f, 0.994629f, 0.987793f,
+ 0.981934f, 0.976562f, 0.971680f, 0.966797f, 0.025833f, 0.076965f, 0.125854f, 0.173096f, 0.217896f, 0.259766f, 0.299561f, 0.338135f,
+ 0.372559f, 0.407471f, 0.437500f, 0.468262f, 0.496582f, 0.522949f, 0.547852f, 0.571289f, 0.593750f, 0.614746f, 0.633789f, 0.652832f,
+ 0.671387f, 0.687988f, 0.705078f, 0.719727f, 0.734863f, 0.749023f, 0.761719f, 0.774414f, 0.786621f, 0.797363f, 0.808594f, 0.818848f,
+ 0.829590f, 0.838867f, 0.848633f, 0.858398f, 0.865723f, 0.874512f, 0.881836f, 0.890137f, 0.897949f, 0.904297f, 0.910645f, 0.917480f,
+ 0.923828f, 0.929688f, 0.935547f, 0.941895f, 0.947266f, 0.952637f, 0.957520f, 0.962402f, 0.967285f, 0.971680f, 0.976562f, 0.980957f,
+ 0.984863f, 0.989258f, 0.992676f, 0.985840f, 0.979980f, 0.975098f, 0.970703f, 0.966309f, 0.020828f, 0.063049f, 0.104797f, 0.146606f,
+ 0.187134f, 0.225464f, 0.263916f, 0.299072f, 0.333252f, 0.366943f, 0.398438f, 0.429199f, 0.457031f, 0.484131f, 0.509766f, 0.534668f,
+ 0.559082f, 0.579590f, 0.600586f, 0.622070f, 0.640625f, 0.659180f, 0.676758f, 0.692383f, 0.708984f, 0.722656f, 0.737793f, 0.751465f,
+ 0.764648f, 0.776367f, 0.789062f, 0.801270f, 0.811523f, 0.821289f, 0.832031f, 0.841309f, 0.850586f, 0.860352f, 0.868652f, 0.876953f,
+ 0.884766f, 0.892090f, 0.899902f, 0.906738f, 0.913086f, 0.920410f, 0.927246f, 0.933105f, 0.938477f, 0.944336f, 0.950195f, 0.955078f,
+ 0.959961f, 0.965332f, 0.970215f, 0.975098f, 0.979492f, 0.983887f, 0.989746f, 0.983398f, 0.978516f, 0.973633f, 0.969238f, 0.964844f,
+ 0.017273f, 0.052429f, 0.088745f, 0.124207f, 0.160034f, 0.195068f, 0.230103f, 0.263916f, 0.297119f, 0.329102f, 0.360596f, 0.390625f,
+ 0.418945f, 0.446289f, 0.472656f, 0.498535f, 0.521973f, 0.545898f, 0.567871f, 0.588867f, 0.609375f, 0.629395f, 0.646973f, 0.664551f,
+ 0.681641f, 0.698242f, 0.712402f, 0.727539f, 0.741699f, 0.755371f, 0.768555f, 0.780762f, 0.792480f, 0.803711f, 0.814941f, 0.825195f,
+ 0.834961f, 0.844727f, 0.854004f, 0.863281f, 0.871094f, 0.879883f, 0.887695f, 0.895508f, 0.902832f, 0.909668f, 0.916504f, 0.923828f,
+ 0.929688f, 0.936035f, 0.941895f, 0.947754f, 0.952637f, 0.958496f, 0.963379f, 0.968750f, 0.973633f, 0.978027f, 0.986816f, 0.980957f,
+ 0.976562f, 0.972168f, 0.967285f, 0.963379f, 0.014076f, 0.043915f, 0.074951f, 0.106140f, 0.137573f, 0.169189f, 0.201416f, 0.233154f,
+ 0.264648f, 0.295166f, 0.324707f, 0.354248f, 0.381836f, 0.410156f, 0.436279f, 0.462891f, 0.487793f, 0.510742f, 0.534180f, 0.556152f,
+ 0.576660f, 0.598145f, 0.616211f, 0.636719f, 0.653320f, 0.670410f, 0.687500f, 0.703125f, 0.718262f, 0.733398f, 0.746582f, 0.760742f,
+ 0.772949f, 0.785156f, 0.796875f, 0.808105f, 0.818848f, 0.829590f, 0.838867f, 0.848145f, 0.857910f, 0.867188f, 0.875977f, 0.883301f,
+ 0.891602f, 0.899414f, 0.906738f, 0.913086f, 0.919922f, 0.926270f, 0.932617f, 0.938477f, 0.944824f, 0.951660f, 0.957520f, 0.961914f,
+ 0.967285f, 0.972168f, 0.984863f, 0.979004f, 0.974609f, 0.970215f, 0.966309f, 0.961914f, 0.012077f, 0.037445f, 0.063660f, 0.090881f,
+ 0.118774f, 0.147827f, 0.176636f, 0.206055f, 0.234253f, 0.262939f, 0.291504f, 0.320312f, 0.347168f, 0.374756f, 0.401367f, 0.427734f,
+ 0.451904f, 0.477051f, 0.500488f, 0.523438f, 0.545898f, 0.566406f, 0.587402f, 0.605957f, 0.624512f, 0.643555f, 0.662109f, 0.676758f,
+ 0.693848f, 0.708984f, 0.724609f, 0.738770f, 0.751465f, 0.765137f, 0.777344f, 0.790039f, 0.800781f, 0.812500f, 0.823242f, 0.833984f,
+ 0.842773f, 0.853027f, 0.861816f, 0.871094f, 0.879395f, 0.887695f, 0.895508f, 0.903320f, 0.910156f, 0.917969f, 0.924316f, 0.931152f,
+ 0.937988f, 0.943848f, 0.949219f, 0.955566f, 0.960449f, 0.966309f, 0.981445f, 0.977051f, 0.972168f, 0.968262f, 0.964355f, 0.960938f,
+ 0.010445f, 0.032562f, 0.054657f, 0.078613f, 0.103333f, 0.128540f, 0.153564f, 0.181274f, 0.207520f, 0.234619f, 0.261475f, 0.288818f,
+ 0.315674f, 0.342041f, 0.368408f, 0.394287f, 0.418945f, 0.443604f, 0.467773f, 0.490479f, 0.512695f, 0.534180f, 0.555664f, 0.575684f,
+ 0.596191f, 0.616211f, 0.633301f, 0.651855f, 0.668457f, 0.685547f, 0.701172f, 0.714844f, 0.729492f, 0.743652f, 0.758301f, 0.770996f,
+ 0.783203f, 0.794922f, 0.806641f, 0.817383f, 0.827637f, 0.838867f, 0.847656f, 0.857422f, 0.866699f, 0.875000f, 0.884277f, 0.892578f,
+ 0.900391f, 0.907227f, 0.914551f, 0.922363f, 0.929199f, 0.935059f, 0.941895f, 0.948242f, 0.953125f, 0.959473f, 0.978516f, 0.974609f,
+ 0.970215f, 0.966309f, 0.962402f, 0.958984f, 0.009117f, 0.027466f, 0.047424f, 0.067871f, 0.089783f, 0.112244f, 0.135376f, 0.159668f,
+ 0.184082f, 0.209106f, 0.233887f, 0.259277f, 0.285400f, 0.311523f, 0.336182f, 0.360840f, 0.385986f, 0.410889f, 0.435059f, 0.458252f,
+ 0.480713f, 0.503418f, 0.524902f, 0.546387f, 0.566895f, 0.586426f, 0.605469f, 0.624512f, 0.642578f, 0.659668f, 0.676758f, 0.692383f,
+ 0.708008f, 0.722168f, 0.736816f, 0.749512f, 0.763184f, 0.776855f, 0.789062f, 0.800781f, 0.812012f, 0.823730f, 0.833496f, 0.843750f,
+ 0.854004f, 0.863281f, 0.872559f, 0.880371f, 0.889648f, 0.896973f, 0.905762f, 0.912598f, 0.919922f, 0.927734f, 0.934082f, 0.940918f,
+ 0.946289f, 0.952637f, 0.976074f, 0.972168f, 0.967773f, 0.963867f, 0.960938f, 0.957031f, 0.007561f, 0.024231f, 0.041077f, 0.059631f,
+ 0.078369f, 0.098145f, 0.119507f, 0.140747f, 0.163208f, 0.185913f, 0.209839f, 0.233154f, 0.257324f, 0.281494f, 0.305908f, 0.330566f,
+ 0.354736f, 0.378906f, 0.402588f, 0.425781f, 0.449219f, 0.471924f, 0.494385f, 0.516602f, 0.536621f, 0.557617f, 0.576660f, 0.596680f,
+ 0.616211f, 0.632812f, 0.650879f, 0.668457f, 0.684082f, 0.700684f, 0.715332f, 0.729492f, 0.744141f, 0.757812f, 0.771973f, 0.783691f,
+ 0.796387f, 0.807129f, 0.818359f, 0.829590f, 0.840820f, 0.850098f, 0.859375f, 0.868652f, 0.877930f, 0.886719f, 0.894531f, 0.903320f,
+ 0.910645f, 0.918945f, 0.925781f, 0.932617f, 0.939453f, 0.945801f, 0.972656f, 0.969727f, 0.965820f, 0.961914f, 0.958496f, 0.955078f,
+ 0.006832f, 0.020676f, 0.036224f, 0.051758f, 0.069214f, 0.086609f, 0.105225f, 0.124146f, 0.144653f, 0.165527f, 0.186646f, 0.209106f,
+ 0.232178f, 0.254883f, 0.277588f, 0.301758f, 0.325195f, 0.348633f, 0.371826f, 0.395264f, 0.418213f, 0.440674f, 0.463135f, 0.485596f,
+ 0.506348f, 0.527832f, 0.548340f, 0.567871f, 0.587891f, 0.606934f, 0.625977f, 0.642578f, 0.660645f, 0.677734f, 0.692871f, 0.708008f,
+ 0.723633f, 0.737793f, 0.752441f, 0.765137f, 0.778320f, 0.791504f, 0.802734f, 0.814453f, 0.825684f, 0.835449f, 0.847168f, 0.856934f,
+ 0.866699f, 0.875488f, 0.884766f, 0.893066f, 0.901367f, 0.910156f, 0.917480f, 0.924805f, 0.932129f, 0.938965f, 0.970215f, 0.966797f,
+ 0.963379f, 0.959961f, 0.956543f, 0.953125f, 0.006050f, 0.018585f, 0.031860f, 0.045807f, 0.060883f, 0.076538f, 0.093323f, 0.109985f,
+ 0.128174f, 0.147949f, 0.167480f, 0.186768f, 0.208496f, 0.230591f, 0.252441f, 0.274170f, 0.297363f, 0.319824f, 0.342773f, 0.365723f,
+ 0.388672f, 0.411133f, 0.433350f, 0.455811f, 0.477295f, 0.498291f, 0.519531f, 0.539551f, 0.560059f, 0.580566f, 0.599121f, 0.617676f,
+ 0.635254f, 0.653320f, 0.669434f, 0.686523f, 0.702148f, 0.717773f, 0.732422f, 0.747070f, 0.760742f, 0.773926f, 0.786621f, 0.798340f,
+ 0.811035f, 0.822754f, 0.833008f, 0.843750f, 0.854004f, 0.863770f, 0.873047f, 0.882812f, 0.891602f, 0.900879f, 0.908691f, 0.916504f,
+ 0.924316f, 0.931152f, 0.966309f, 0.964355f, 0.961426f, 0.957520f, 0.954102f, 0.951172f, 0.005352f, 0.016388f, 0.027985f, 0.040222f,
+ 0.053436f, 0.067261f, 0.082520f, 0.098022f, 0.114319f, 0.131836f, 0.150146f, 0.167969f, 0.187744f, 0.208008f, 0.228271f, 0.249634f,
+ 0.270996f, 0.292969f, 0.314697f, 0.337158f, 0.359375f, 0.380859f, 0.403809f, 0.426025f, 0.447510f, 0.469482f, 0.490967f, 0.511719f,
+ 0.532227f, 0.552734f, 0.571777f, 0.591309f, 0.609375f, 0.628418f, 0.645508f, 0.663086f, 0.680664f, 0.696289f, 0.711426f, 0.727051f,
+ 0.741699f, 0.755859f, 0.768555f, 0.782227f, 0.795410f, 0.807617f, 0.818359f, 0.830078f, 0.841309f, 0.851074f, 0.861816f, 0.871582f,
+ 0.880859f, 0.890625f, 0.898438f, 0.907715f, 0.915527f, 0.923828f, 0.962402f, 0.961914f, 0.958496f, 0.955078f, 0.951172f, 0.948730f,
+ 0.004700f, 0.014397f, 0.025208f, 0.035675f, 0.047485f, 0.060120f, 0.073242f, 0.087097f, 0.102173f, 0.117249f, 0.133789f, 0.150513f,
+ 0.168823f, 0.186890f, 0.206665f, 0.225830f, 0.246216f, 0.267334f, 0.288574f, 0.309814f, 0.331299f, 0.353271f, 0.375244f, 0.396729f,
+ 0.418701f, 0.440674f, 0.461182f, 0.483398f, 0.504883f, 0.524902f, 0.544434f, 0.564941f, 0.584473f, 0.603027f, 0.621582f, 0.639648f,
+ 0.656738f, 0.673828f, 0.690430f, 0.705566f, 0.721680f, 0.736816f, 0.750977f, 0.764648f, 0.778809f, 0.791016f, 0.804688f, 0.815918f,
+ 0.826660f, 0.838867f, 0.850098f, 0.860840f, 0.870605f, 0.879883f, 0.889648f, 0.898438f, 0.907227f, 0.915527f, 0.959961f, 0.958496f,
+ 0.955078f, 0.952148f, 0.949219f, 0.946777f, 0.004238f, 0.013138f, 0.022202f, 0.031769f, 0.042358f, 0.053040f, 0.065613f, 0.077637f,
+ 0.090759f, 0.104980f, 0.119995f, 0.135498f, 0.151855f, 0.167725f, 0.186646f, 0.205078f, 0.224121f, 0.243042f, 0.263672f, 0.283936f,
+ 0.305176f, 0.326416f, 0.347168f, 0.369629f, 0.390625f, 0.411865f, 0.433350f, 0.454590f, 0.475830f, 0.497314f, 0.517578f, 0.537109f,
+ 0.557617f, 0.577637f, 0.596191f, 0.615723f, 0.632812f, 0.651367f, 0.668945f, 0.685059f, 0.701172f, 0.716797f, 0.732422f, 0.747559f,
+ 0.761230f, 0.775391f, 0.788574f, 0.800781f, 0.813965f, 0.824707f, 0.837402f, 0.848145f, 0.859375f, 0.869141f, 0.879395f, 0.889160f,
+ 0.897949f, 0.906250f, 0.956055f, 0.955566f, 0.952148f, 0.950195f, 0.947266f, 0.943848f, 0.003944f, 0.011490f, 0.019943f, 0.028748f,
+ 0.037964f, 0.047485f, 0.058014f, 0.069702f, 0.081360f, 0.093994f, 0.107361f, 0.121277f, 0.136353f, 0.151978f, 0.167480f, 0.185669f,
+ 0.202637f, 0.222168f, 0.240601f, 0.259766f, 0.279541f, 0.300293f, 0.321533f, 0.342285f, 0.362549f, 0.384033f, 0.405762f, 0.427002f,
+ 0.447998f, 0.469238f, 0.490479f, 0.510742f, 0.532227f, 0.551758f, 0.570312f, 0.589844f, 0.609375f, 0.628418f, 0.645508f, 0.662598f,
+ 0.680664f, 0.696777f, 0.712402f, 0.728516f, 0.744141f, 0.757812f, 0.771973f, 0.785156f, 0.798828f, 0.811523f, 0.824707f, 0.835449f,
+ 0.847168f, 0.858887f, 0.869141f, 0.878906f, 0.888672f, 0.897949f, 0.952148f, 0.952148f, 0.949219f, 0.946777f, 0.944336f, 0.941406f,
+ 0.003448f, 0.010574f, 0.017807f, 0.025558f, 0.033875f, 0.042633f, 0.052307f, 0.062134f, 0.073059f, 0.084045f, 0.096375f, 0.109192f,
+ 0.122803f, 0.136475f, 0.151367f, 0.167603f, 0.183960f, 0.201416f, 0.218506f, 0.237427f, 0.256104f, 0.275635f, 0.295410f, 0.315918f,
+ 0.336426f, 0.357178f, 0.378906f, 0.399414f, 0.421143f, 0.442139f, 0.462891f, 0.484375f, 0.504883f, 0.524902f, 0.544922f, 0.564941f,
+ 0.583984f, 0.603516f, 0.622070f, 0.640625f, 0.658691f, 0.675781f, 0.692871f, 0.709473f, 0.725098f, 0.740234f, 0.754883f, 0.769531f,
+ 0.783203f, 0.796875f, 0.809570f, 0.823242f, 0.834473f, 0.846191f, 0.857422f, 0.868164f, 0.878906f, 0.889160f, 0.948730f, 0.948242f,
+ 0.946289f, 0.944336f, 0.940918f, 0.938477f, 0.003017f, 0.009422f, 0.015900f, 0.023041f, 0.030380f, 0.038574f, 0.047150f, 0.055969f,
+ 0.065735f, 0.075684f, 0.086426f, 0.098267f, 0.110535f, 0.123047f, 0.136841f, 0.151489f, 0.166138f, 0.182495f, 0.198975f, 0.216553f,
+ 0.233765f, 0.252930f, 0.271484f, 0.291016f, 0.310547f, 0.331299f, 0.351562f, 0.372559f, 0.393555f, 0.415039f, 0.435059f, 0.457275f,
+ 0.477539f, 0.498047f, 0.519043f, 0.538574f, 0.559570f, 0.579102f, 0.598633f, 0.617188f, 0.635742f, 0.654297f, 0.672363f, 0.688965f,
+ 0.706055f, 0.721191f, 0.737793f, 0.752930f, 0.768066f, 0.782227f, 0.795898f, 0.809082f, 0.821289f, 0.833496f, 0.846191f, 0.857422f,
+ 0.869141f, 0.879883f, 0.944824f, 0.945312f, 0.942871f, 0.940918f, 0.938477f, 0.936035f, 0.002802f, 0.008575f, 0.014763f, 0.020844f,
+ 0.027557f, 0.034576f, 0.042084f, 0.050476f, 0.058990f, 0.067993f, 0.077942f, 0.087952f, 0.098999f, 0.111267f, 0.122803f, 0.136719f,
+ 0.150269f, 0.165527f, 0.180542f, 0.196533f, 0.213257f, 0.230591f, 0.248779f, 0.267334f, 0.286865f, 0.306152f, 0.325928f, 0.346436f,
+ 0.367188f, 0.387695f, 0.409424f, 0.429199f, 0.450195f, 0.471680f, 0.492920f, 0.513184f, 0.534180f, 0.553711f, 0.573730f, 0.593750f,
+ 0.612793f, 0.631836f, 0.649414f, 0.668457f, 0.685059f, 0.703125f, 0.719238f, 0.735352f, 0.750000f, 0.766113f, 0.781738f, 0.794434f,
+ 0.808105f, 0.821777f, 0.833984f, 0.846191f, 0.858398f, 0.870117f, 0.940918f, 0.941895f, 0.939941f, 0.937500f, 0.935059f, 0.932617f,
+ 0.002573f, 0.007603f, 0.013100f, 0.018799f, 0.024719f, 0.031372f, 0.038147f, 0.045105f, 0.052795f, 0.061127f, 0.069519f, 0.079529f,
+ 0.089355f, 0.099976f, 0.111084f, 0.123718f, 0.136353f, 0.148926f, 0.163574f, 0.178345f, 0.194214f, 0.210083f, 0.227783f, 0.245361f,
+ 0.263672f, 0.282471f, 0.301758f, 0.321533f, 0.341797f, 0.361816f, 0.383057f, 0.403320f, 0.424316f, 0.445557f, 0.466797f, 0.487061f,
+ 0.507812f, 0.528809f, 0.549805f, 0.569336f, 0.589844f, 0.608887f, 0.627930f, 0.646973f, 0.665527f, 0.682129f, 0.700195f, 0.717773f,
+ 0.732910f, 0.749512f, 0.765137f, 0.779785f, 0.794434f, 0.808105f, 0.821777f, 0.834473f, 0.847168f, 0.859375f, 0.936523f, 0.937988f,
+ 0.936035f, 0.933594f, 0.932129f, 0.929688f, 0.002409f, 0.007107f, 0.011833f, 0.017075f, 0.022278f, 0.028351f, 0.034088f, 0.040558f,
+ 0.047943f, 0.055389f, 0.063232f, 0.072021f, 0.080322f, 0.090454f, 0.100220f, 0.111389f, 0.122986f, 0.135010f, 0.148438f, 0.162109f,
+ 0.176270f, 0.191772f, 0.207642f, 0.224121f, 0.241699f, 0.259277f, 0.278076f, 0.297363f, 0.316650f, 0.336670f, 0.356934f, 0.377686f,
+ 0.397949f, 0.418701f, 0.439941f, 0.461914f, 0.482178f, 0.502930f, 0.524414f, 0.544922f, 0.565918f, 0.585938f, 0.605957f, 0.625000f,
+ 0.643066f, 0.662109f, 0.680176f, 0.698730f, 0.715820f, 0.731934f, 0.748047f, 0.764648f, 0.780273f, 0.794434f, 0.808594f, 0.821777f,
+ 0.836914f, 0.848145f, 0.932129f, 0.934082f, 0.932617f, 0.930176f, 0.928711f, 0.926270f, 0.002066f, 0.006329f, 0.010986f, 0.015541f,
+ 0.020294f, 0.025452f, 0.030975f, 0.037201f, 0.043152f, 0.049835f, 0.056824f, 0.064331f, 0.072998f, 0.081177f, 0.090637f, 0.100525f,
+ 0.110718f, 0.122131f, 0.134033f, 0.146851f, 0.159912f, 0.173584f, 0.189331f, 0.204468f, 0.221191f, 0.237671f, 0.255615f, 0.273682f,
+ 0.292969f, 0.312012f, 0.331543f, 0.352295f, 0.372314f, 0.393311f, 0.413818f, 0.435547f, 0.456055f, 0.477539f, 0.499023f, 0.520508f,
+ 0.540039f, 0.561523f, 0.581543f, 0.602051f, 0.622070f, 0.641113f, 0.659668f, 0.678223f, 0.697266f, 0.714844f, 0.731445f, 0.748535f,
+ 0.765137f, 0.778809f, 0.794922f, 0.810059f, 0.824219f, 0.837402f, 0.926758f, 0.930176f, 0.928711f, 0.926758f, 0.924805f, 0.922852f,
+ 0.001840f, 0.005703f, 0.009918f, 0.014099f, 0.018311f, 0.023026f, 0.028000f, 0.033508f, 0.038971f, 0.045044f, 0.051880f, 0.058289f,
+ 0.065796f, 0.073425f, 0.081482f, 0.090698f, 0.100464f, 0.110413f, 0.121216f, 0.132812f, 0.145142f, 0.158203f, 0.171997f, 0.186401f,
+ 0.201538f, 0.217651f, 0.234497f, 0.251465f, 0.269287f, 0.288330f, 0.307129f, 0.327148f, 0.346924f, 0.367920f, 0.388428f, 0.409668f,
+ 0.430420f, 0.451416f, 0.474121f, 0.494873f, 0.516113f, 0.537598f, 0.558105f, 0.579102f, 0.598633f, 0.619629f, 0.639160f, 0.657715f,
+ 0.677734f, 0.695801f, 0.713867f, 0.731934f, 0.748047f, 0.764160f, 0.781738f, 0.796875f, 0.810547f, 0.826172f, 0.922363f, 0.925781f,
+ 0.924805f, 0.922852f, 0.921387f, 0.919434f, 0.001621f, 0.005188f, 0.008888f, 0.012939f, 0.016724f, 0.021271f, 0.025772f, 0.029984f,
+ 0.035553f, 0.040741f, 0.046417f, 0.052490f, 0.059265f, 0.066528f, 0.074097f, 0.081482f, 0.090271f, 0.100220f, 0.109741f, 0.120178f,
+ 0.131226f, 0.143188f, 0.156006f, 0.169189f, 0.183716f, 0.198486f, 0.214233f, 0.230713f, 0.247925f, 0.265381f, 0.284424f, 0.303711f,
+ 0.322754f, 0.342773f, 0.363525f, 0.384277f, 0.405518f, 0.427002f, 0.447754f, 0.469727f, 0.491455f, 0.512207f, 0.534180f, 0.554688f,
+ 0.576172f, 0.597168f, 0.617188f, 0.636719f, 0.657227f, 0.677734f, 0.695312f, 0.713379f, 0.731934f, 0.749512f, 0.766113f, 0.782715f,
+ 0.798340f, 0.813477f, 0.917480f, 0.920898f, 0.920410f, 0.919922f, 0.916992f, 0.915039f, 0.001581f, 0.004616f, 0.008049f, 0.011917f,
+ 0.015556f, 0.019547f, 0.023270f, 0.027908f, 0.031860f, 0.036652f, 0.041992f, 0.047577f, 0.053528f, 0.060150f, 0.066772f, 0.073914f,
+ 0.082153f, 0.090088f, 0.099304f, 0.108887f, 0.118835f, 0.129517f, 0.141357f, 0.154297f, 0.166992f, 0.180908f, 0.195557f, 0.210815f,
+ 0.227173f, 0.244141f, 0.261963f, 0.279785f, 0.299072f, 0.318359f, 0.338379f, 0.358887f, 0.380127f, 0.401123f, 0.422607f, 0.443848f,
+ 0.466309f, 0.487793f, 0.509277f, 0.530762f, 0.553223f, 0.573730f, 0.594727f, 0.616699f, 0.636719f, 0.656250f, 0.676270f, 0.695801f,
+ 0.713867f, 0.733398f, 0.750488f, 0.767090f, 0.784180f, 0.801270f, 0.912598f, 0.916992f, 0.916504f, 0.914551f, 0.913086f, 0.911133f,
+ 0.001476f, 0.004410f, 0.007374f, 0.010620f, 0.013931f, 0.017258f, 0.021057f, 0.024979f, 0.029144f, 0.033478f, 0.037872f, 0.042969f,
+ 0.048737f, 0.053986f, 0.060150f, 0.066895f, 0.074036f, 0.081665f, 0.089417f, 0.098083f, 0.107361f, 0.117371f, 0.127930f, 0.139648f,
+ 0.151489f, 0.164062f, 0.178589f, 0.192627f, 0.208130f, 0.223755f, 0.240601f, 0.258057f, 0.275879f, 0.295654f, 0.314697f, 0.334961f,
+ 0.354980f, 0.375977f, 0.396729f, 0.418945f, 0.440430f, 0.462402f, 0.484619f, 0.506348f, 0.528809f, 0.550781f, 0.572266f, 0.593750f,
+ 0.615234f, 0.637207f, 0.656738f, 0.676758f, 0.696289f, 0.716309f, 0.734863f, 0.752930f, 0.770508f, 0.788574f, 0.906738f, 0.911621f,
+ 0.912109f, 0.910156f, 0.908691f, 0.907227f, 0.001204f, 0.003998f, 0.006786f, 0.009850f, 0.012642f, 0.015762f, 0.019226f, 0.022751f,
+ 0.026749f, 0.030502f, 0.034698f, 0.038940f, 0.044006f, 0.048615f, 0.054352f, 0.060608f, 0.066711f, 0.073059f, 0.080505f, 0.088318f,
+ 0.097290f, 0.105835f, 0.115845f, 0.126343f, 0.137085f, 0.148804f, 0.161377f, 0.175049f, 0.189331f, 0.204346f, 0.219604f, 0.236816f,
+ 0.253662f, 0.272217f, 0.291260f, 0.310547f, 0.330811f, 0.350830f, 0.372314f, 0.393799f, 0.415771f, 0.437500f, 0.459717f, 0.481934f,
+ 0.504883f, 0.527344f, 0.549316f, 0.571777f, 0.593750f, 0.615723f, 0.636230f, 0.657715f, 0.678223f, 0.697754f, 0.718262f, 0.737793f,
+ 0.756348f, 0.774902f, 0.900879f, 0.907227f, 0.906738f, 0.905762f, 0.904297f, 0.902832f, 0.001290f, 0.003807f, 0.006207f, 0.008652f,
+ 0.011368f, 0.014618f, 0.017792f, 0.020813f, 0.023849f, 0.027588f, 0.031036f, 0.035400f, 0.039917f, 0.044250f, 0.049408f, 0.054321f,
+ 0.059937f, 0.065918f, 0.072937f, 0.079773f, 0.087463f, 0.095703f, 0.104553f, 0.113892f, 0.124146f, 0.134888f, 0.146606f, 0.159058f,
+ 0.171753f, 0.185913f, 0.201416f, 0.216309f, 0.232910f, 0.250000f, 0.268555f, 0.287354f, 0.306885f, 0.326904f, 0.347412f, 0.369141f,
+ 0.390381f, 0.412842f, 0.434570f, 0.457764f, 0.479736f, 0.502930f, 0.525879f, 0.547852f, 0.570801f, 0.592773f, 0.615723f, 0.637207f,
+ 0.659180f, 0.680176f, 0.700684f, 0.720703f, 0.740234f, 0.759766f, 0.895996f, 0.901855f, 0.901855f, 0.900879f, 0.899414f, 0.897949f,
+ 0.001030f, 0.003561f, 0.005718f, 0.008301f, 0.010582f, 0.013283f, 0.015839f, 0.018753f, 0.022156f, 0.025314f, 0.028427f, 0.032318f,
+ 0.035889f, 0.040039f, 0.044434f, 0.048737f, 0.054077f, 0.059723f, 0.065613f, 0.072083f, 0.079224f, 0.086426f, 0.094238f, 0.102966f,
+ 0.111938f, 0.122253f, 0.132568f, 0.143555f, 0.155884f, 0.168945f, 0.182861f, 0.197510f, 0.213379f, 0.229492f, 0.246948f, 0.264648f,
+ 0.283203f, 0.303467f, 0.322998f, 0.343994f, 0.365479f, 0.387451f, 0.409912f, 0.432129f, 0.455078f, 0.478760f, 0.501465f, 0.523926f,
+ 0.547852f, 0.570801f, 0.593750f, 0.616211f, 0.639160f, 0.661133f, 0.682617f, 0.703613f, 0.725098f, 0.745117f, 0.888672f, 0.896484f,
+ 0.896973f, 0.895020f, 0.895508f, 0.893555f, 0.001051f, 0.002956f, 0.005398f, 0.007523f, 0.009613f, 0.012024f, 0.014725f, 0.017059f,
+ 0.019714f, 0.022537f, 0.025681f, 0.029236f, 0.032715f, 0.036102f, 0.040100f, 0.043945f, 0.048859f, 0.053772f, 0.058838f, 0.064880f,
+ 0.070862f, 0.077576f, 0.084839f, 0.092712f, 0.101013f, 0.110229f, 0.119446f, 0.130005f, 0.141113f, 0.153198f, 0.166016f, 0.179565f,
+ 0.193970f, 0.209351f, 0.225830f, 0.242920f, 0.261230f, 0.280273f, 0.299316f, 0.320068f, 0.341309f, 0.363037f, 0.384521f, 0.407227f,
+ 0.429443f, 0.453369f, 0.477051f, 0.500977f, 0.524414f, 0.547852f, 0.571777f, 0.595215f, 0.619141f, 0.641602f, 0.664062f, 0.686035f,
+ 0.707520f, 0.729004f, 0.882812f, 0.891602f, 0.891113f, 0.890625f, 0.889160f, 0.888184f, 0.000934f, 0.002998f, 0.004883f, 0.006859f,
+ 0.009102f, 0.010925f, 0.012871f, 0.015656f, 0.017853f, 0.020767f, 0.023422f, 0.026413f, 0.029251f, 0.032593f, 0.036011f, 0.039825f,
+ 0.044495f, 0.048645f, 0.053284f, 0.058258f, 0.063782f, 0.069885f, 0.076111f, 0.083313f, 0.090881f, 0.099060f, 0.107788f, 0.117126f,
+ 0.127075f, 0.138428f, 0.150391f, 0.162720f, 0.176270f, 0.190796f, 0.206177f, 0.222290f, 0.239624f, 0.257568f, 0.276367f, 0.296387f,
+ 0.316895f, 0.338623f, 0.360352f, 0.382812f, 0.404785f, 0.428467f, 0.452148f, 0.476562f, 0.500488f, 0.524902f, 0.548828f, 0.572754f,
+ 0.597168f, 0.621094f, 0.644531f, 0.667480f, 0.689941f, 0.712402f, 0.875977f, 0.883789f, 0.884766f, 0.884766f, 0.883301f, 0.883789f,
+ 0.001108f, 0.002474f, 0.004707f, 0.006248f, 0.007744f, 0.009888f, 0.011787f, 0.014244f, 0.016205f, 0.018631f, 0.021286f, 0.023758f,
+ 0.026535f, 0.029510f, 0.032654f, 0.035919f, 0.039825f, 0.043762f, 0.047852f, 0.052368f, 0.057373f, 0.062561f, 0.068604f, 0.074707f,
+ 0.081360f, 0.088623f, 0.096802f, 0.105103f, 0.114624f, 0.124573f, 0.135498f, 0.147217f, 0.159424f, 0.172729f, 0.187378f, 0.202881f,
+ 0.219116f, 0.235962f, 0.254639f, 0.273438f, 0.293945f, 0.314453f, 0.335449f, 0.358154f, 0.380371f, 0.403564f, 0.428223f, 0.452148f,
+ 0.476074f, 0.500977f, 0.525879f, 0.550293f, 0.575195f, 0.599609f, 0.625000f, 0.649414f, 0.672852f, 0.695801f, 0.870117f, 0.879395f,
+ 0.879883f, 0.879395f, 0.878906f, 0.877441f, 0.000877f, 0.002495f, 0.003918f, 0.005669f, 0.007484f, 0.009148f, 0.010895f, 0.012634f,
+ 0.014717f, 0.017014f, 0.019302f, 0.021347f, 0.023849f, 0.026443f, 0.029388f, 0.032532f, 0.035492f, 0.039185f, 0.042816f, 0.046906f,
+ 0.051453f, 0.056122f, 0.061310f, 0.066895f, 0.072937f, 0.079590f, 0.086548f, 0.094360f, 0.103027f, 0.111938f, 0.121643f, 0.132568f,
+ 0.144043f, 0.156006f, 0.169434f, 0.184204f, 0.199341f, 0.215698f, 0.233032f, 0.251221f, 0.269531f, 0.290039f, 0.311768f, 0.333740f,
+ 0.355957f, 0.379395f, 0.402344f, 0.426758f, 0.451172f, 0.476562f, 0.501465f, 0.526855f, 0.552246f, 0.578613f, 0.603516f, 0.629395f,
+ 0.653809f, 0.679199f, 0.863281f, 0.872559f, 0.874023f, 0.873535f, 0.872559f, 0.871094f, 0.000779f, 0.002241f, 0.003813f, 0.005371f,
+ 0.006763f, 0.008186f, 0.009827f, 0.011574f, 0.013260f, 0.015274f, 0.017303f, 0.019119f, 0.021362f, 0.023972f, 0.026505f, 0.029144f,
+ 0.031860f, 0.035126f, 0.038422f, 0.041809f, 0.045929f, 0.050323f, 0.054840f, 0.059631f, 0.065002f, 0.070984f, 0.077759f, 0.084656f,
+ 0.091736f, 0.100037f, 0.109436f, 0.118835f, 0.129272f, 0.140625f, 0.152832f, 0.166138f, 0.180786f, 0.195679f, 0.211914f, 0.229736f,
+ 0.247803f, 0.267822f, 0.287598f, 0.309326f, 0.331055f, 0.354492f, 0.377686f, 0.401855f, 0.426270f, 0.451660f, 0.477051f, 0.503418f,
+ 0.529785f, 0.555664f, 0.583008f, 0.608887f, 0.635254f, 0.661133f, 0.855957f, 0.865234f, 0.866699f, 0.867188f, 0.866211f, 0.865723f,
+ 0.000778f, 0.002155f, 0.003584f, 0.004871f, 0.006149f, 0.007519f, 0.008858f, 0.010498f, 0.012100f, 0.013977f, 0.015511f, 0.017303f,
+ 0.019363f, 0.021515f, 0.023880f, 0.026230f, 0.028564f, 0.031555f, 0.034241f, 0.037476f, 0.041138f, 0.044983f, 0.048859f, 0.053436f,
+ 0.058014f, 0.063232f, 0.069214f, 0.075195f, 0.081848f, 0.089417f, 0.097168f, 0.106201f, 0.115479f, 0.126343f, 0.137695f, 0.149658f,
+ 0.162476f, 0.177002f, 0.192993f, 0.209473f, 0.226440f, 0.245239f, 0.264404f, 0.285156f, 0.306885f, 0.330078f, 0.353271f, 0.376465f,
+ 0.402100f, 0.426758f, 0.453857f, 0.479492f, 0.505859f, 0.532715f, 0.560547f, 0.587402f, 0.614258f, 0.640137f, 0.847168f, 0.858398f,
+ 0.860352f, 0.859863f, 0.859863f, 0.858887f, 0.000673f, 0.002026f, 0.003120f, 0.004242f, 0.005390f, 0.006874f, 0.008087f, 0.009346f,
+ 0.011192f, 0.012642f, 0.013855f, 0.015511f, 0.017502f, 0.019394f, 0.021301f, 0.023331f, 0.025681f, 0.028137f, 0.030792f, 0.033295f,
+ 0.036804f, 0.039917f, 0.043488f, 0.047363f, 0.051880f, 0.056580f, 0.061646f, 0.066956f, 0.072998f, 0.079407f, 0.086609f, 0.094971f,
+ 0.103027f, 0.112793f, 0.122742f, 0.134399f, 0.146118f, 0.159058f, 0.173828f, 0.188599f, 0.205444f, 0.223633f, 0.241943f, 0.262451f,
+ 0.283203f, 0.304932f, 0.328369f, 0.352051f, 0.376953f, 0.402100f, 0.428467f, 0.454834f, 0.481934f, 0.509766f, 0.537598f, 0.566406f,
+ 0.594238f, 0.622559f, 0.838867f, 0.852051f, 0.853516f, 0.853027f, 0.853027f, 0.852051f, 0.000419f, 0.001721f, 0.003044f, 0.003881f,
+ 0.005161f, 0.006329f, 0.007500f, 0.009117f, 0.009941f, 0.011147f, 0.013023f, 0.014053f, 0.015869f, 0.017181f, 0.018906f, 0.020889f,
+ 0.023026f, 0.025085f, 0.027435f, 0.029724f, 0.032440f, 0.035492f, 0.038605f, 0.042175f, 0.045898f, 0.049988f, 0.054504f, 0.059143f,
+ 0.064697f, 0.070435f, 0.076721f, 0.083984f, 0.091675f, 0.100037f, 0.109009f, 0.119629f, 0.130737f, 0.143066f, 0.156250f, 0.170654f,
+ 0.186157f, 0.202393f, 0.220825f, 0.239990f, 0.259521f, 0.281250f, 0.303467f, 0.327148f, 0.351318f, 0.376953f, 0.402832f, 0.430664f,
+ 0.458252f, 0.485596f, 0.514648f, 0.543457f, 0.572754f, 0.602051f, 0.830566f, 0.844238f, 0.845703f, 0.845703f, 0.845703f, 0.845215f,
+ 0.000503f, 0.001644f, 0.002455f, 0.003765f, 0.004906f, 0.005901f, 0.006805f, 0.007744f, 0.008789f, 0.009972f, 0.011314f, 0.012688f,
+ 0.014160f, 0.015480f, 0.016953f, 0.018555f, 0.020325f, 0.022232f, 0.024338f, 0.026535f, 0.028717f, 0.031403f, 0.034119f, 0.037384f,
+ 0.040680f, 0.044128f, 0.047943f, 0.052551f, 0.057098f, 0.062134f, 0.067871f, 0.074158f, 0.081543f, 0.088684f, 0.097107f, 0.106262f,
+ 0.116028f, 0.127563f, 0.139404f, 0.152344f, 0.167358f, 0.182739f, 0.199951f, 0.217773f, 0.237427f, 0.257812f, 0.279541f, 0.303223f,
+ 0.327148f, 0.351807f, 0.377441f, 0.405518f, 0.433105f, 0.460449f, 0.491211f, 0.520020f, 0.550293f, 0.581543f, 0.821777f, 0.835938f,
+ 0.837891f, 0.838867f, 0.838867f, 0.837891f, 0.000649f, 0.001432f, 0.002455f, 0.003469f, 0.004162f, 0.005192f, 0.006046f, 0.007053f,
+ 0.007919f, 0.009148f, 0.010185f, 0.011490f, 0.012558f, 0.013748f, 0.015083f, 0.016663f, 0.018341f, 0.019897f, 0.021561f, 0.023376f,
+ 0.025513f, 0.027725f, 0.030075f, 0.032745f, 0.035583f, 0.038544f, 0.041901f, 0.045898f, 0.049896f, 0.054443f, 0.059784f, 0.065186f,
+ 0.071228f, 0.078247f, 0.085632f, 0.093872f, 0.103088f, 0.113098f, 0.123840f, 0.135986f, 0.148682f, 0.163696f, 0.179321f, 0.196533f,
+ 0.214722f, 0.234985f, 0.256104f, 0.278320f, 0.302246f, 0.326660f, 0.352783f, 0.379395f, 0.406738f, 0.436279f, 0.465820f, 0.496338f,
+ 0.527344f, 0.559082f, 0.813477f, 0.827148f, 0.829590f, 0.830566f, 0.830566f, 0.829590f, 0.000427f, 0.001431f, 0.002077f, 0.002947f,
+ 0.004009f, 0.004860f, 0.005501f, 0.006416f, 0.007008f, 0.008171f, 0.009155f, 0.010063f, 0.011154f, 0.012474f, 0.013336f, 0.014793f,
+ 0.016006f, 0.017471f, 0.019119f, 0.020630f, 0.022079f, 0.024078f, 0.026505f, 0.028687f, 0.031128f, 0.033813f, 0.036804f, 0.040283f,
+ 0.043732f, 0.047882f, 0.052094f, 0.057281f, 0.062500f, 0.068726f, 0.075012f, 0.082581f, 0.090393f, 0.099487f, 0.109375f, 0.120728f,
+ 0.131958f, 0.145508f, 0.160278f, 0.176025f, 0.193848f, 0.212891f, 0.232788f, 0.253906f, 0.277344f, 0.302002f, 0.327637f, 0.354248f,
+ 0.382080f, 0.411621f, 0.441162f, 0.472656f, 0.504395f, 0.536621f, 0.803223f, 0.818359f, 0.821777f, 0.821777f, 0.822266f, 0.821777f,
+ 0.000574f, 0.001416f, 0.001961f, 0.002621f, 0.003527f, 0.004250f, 0.004894f, 0.005653f, 0.006340f, 0.007263f, 0.008255f, 0.008965f,
+ 0.009819f, 0.010857f, 0.011864f, 0.012917f, 0.014114f, 0.015358f, 0.016678f, 0.018005f, 0.019669f, 0.021347f, 0.023239f, 0.025070f,
+ 0.027267f, 0.029434f, 0.032318f, 0.035156f, 0.038269f, 0.041534f, 0.045624f, 0.049469f, 0.054321f, 0.059479f, 0.065369f, 0.071655f,
+ 0.078857f, 0.086853f, 0.095886f, 0.105652f, 0.116943f, 0.128662f, 0.142090f, 0.156860f, 0.173096f, 0.190918f, 0.210327f, 0.231201f,
+ 0.253418f, 0.277100f, 0.302490f, 0.328369f, 0.356445f, 0.385254f, 0.415771f, 0.446533f, 0.479736f, 0.513184f, 0.794434f, 0.810547f,
+ 0.812500f, 0.813477f, 0.812988f, 0.813477f, 0.000417f, 0.001152f, 0.002066f, 0.002480f, 0.003115f, 0.003778f, 0.004543f, 0.005001f,
+ 0.005936f, 0.006420f, 0.007130f, 0.007881f, 0.008789f, 0.009666f, 0.010605f, 0.011276f, 0.012352f, 0.013367f, 0.014626f, 0.015732f,
+ 0.017090f, 0.018509f, 0.020096f, 0.021759f, 0.023895f, 0.025681f, 0.027740f, 0.030121f, 0.032776f, 0.036011f, 0.039276f, 0.042694f,
+ 0.046906f, 0.051575f, 0.056488f, 0.061951f, 0.068481f, 0.075684f, 0.083191f, 0.092102f, 0.101990f, 0.112915f, 0.125122f, 0.138672f,
+ 0.153564f, 0.170410f, 0.188477f, 0.208008f, 0.229980f, 0.252441f, 0.276855f, 0.303711f, 0.331055f, 0.360596f, 0.391357f, 0.422607f,
+ 0.456299f, 0.490234f, 0.783203f, 0.799805f, 0.803223f, 0.804688f, 0.804199f, 0.805176f, 0.000422f, 0.000885f, 0.001743f, 0.002075f,
+ 0.002930f, 0.003460f, 0.004105f, 0.004696f, 0.005257f, 0.005753f, 0.006550f, 0.006916f, 0.007805f, 0.008308f, 0.009109f, 0.010056f,
+ 0.010918f, 0.011627f, 0.012787f, 0.013725f, 0.014732f, 0.016113f, 0.017319f, 0.018906f, 0.020264f, 0.022324f, 0.023911f, 0.026230f,
+ 0.028183f, 0.030884f, 0.033661f, 0.036865f, 0.040314f, 0.044189f, 0.048615f, 0.053284f, 0.058838f, 0.065491f, 0.072205f, 0.079651f,
+ 0.088379f, 0.098389f, 0.109314f, 0.121765f, 0.135010f, 0.150513f, 0.167358f, 0.186035f, 0.206543f, 0.228516f, 0.252197f, 0.278320f,
+ 0.305176f, 0.333496f, 0.364746f, 0.396973f, 0.430176f, 0.465820f, 0.772949f, 0.790527f, 0.794434f, 0.794922f, 0.795410f, 0.794922f,
+ 0.000211f, 0.000970f, 0.001484f, 0.002035f, 0.002586f, 0.003040f, 0.003540f, 0.004086f, 0.004696f, 0.005016f, 0.005508f, 0.006100f,
+ 0.006763f, 0.007401f, 0.008011f, 0.008675f, 0.009247f, 0.010071f, 0.011009f, 0.011940f, 0.012802f, 0.013870f, 0.014771f, 0.016281f,
+ 0.017487f, 0.018890f, 0.020584f, 0.022171f, 0.024200f, 0.026505f, 0.028870f, 0.031372f, 0.034363f, 0.037659f, 0.041412f, 0.045685f,
+ 0.050262f, 0.055664f, 0.061768f, 0.068359f, 0.076172f, 0.084717f, 0.094666f, 0.105835f, 0.117798f, 0.131958f, 0.147095f, 0.164795f,
+ 0.184326f, 0.204956f, 0.228271f, 0.253174f, 0.279785f, 0.307861f, 0.338379f, 0.370361f, 0.404785f, 0.440430f, 0.761230f, 0.780273f,
+ 0.783691f, 0.785645f, 0.786133f, 0.785156f, 0.000281f, 0.000954f, 0.001275f, 0.001745f, 0.002159f, 0.002810f, 0.003002f, 0.003622f,
+ 0.003918f, 0.004471f, 0.004776f, 0.005352f, 0.005852f, 0.006298f, 0.006989f, 0.007339f, 0.008087f, 0.008698f, 0.009499f, 0.010208f,
+ 0.010986f, 0.011871f, 0.012802f, 0.013809f, 0.014923f, 0.016129f, 0.017624f, 0.018753f, 0.020645f, 0.022156f, 0.024399f, 0.026382f,
+ 0.029037f, 0.031769f, 0.034851f, 0.038513f, 0.042542f, 0.047180f, 0.052063f, 0.058136f, 0.064819f, 0.072205f, 0.080933f, 0.090698f,
+ 0.101685f, 0.114441f, 0.128784f, 0.144287f, 0.162476f, 0.182617f, 0.203979f, 0.228149f, 0.253906f, 0.282227f, 0.312744f, 0.344482f,
+ 0.378418f, 0.415039f, 0.749023f, 0.770020f, 0.773438f, 0.774902f, 0.775391f, 0.776367f, 0.000200f, 0.000790f, 0.001209f, 0.001475f,
+ 0.002022f, 0.002375f, 0.002754f, 0.003136f, 0.003532f, 0.003851f, 0.004253f, 0.004719f, 0.004864f, 0.005455f, 0.005749f, 0.006435f,
+ 0.007053f, 0.007557f, 0.007988f, 0.008614f, 0.009216f, 0.010101f, 0.010712f, 0.011604f, 0.012596f, 0.013588f, 0.014877f, 0.016052f,
+ 0.017334f, 0.018753f, 0.020401f, 0.022415f, 0.024338f, 0.026642f, 0.029282f, 0.032196f, 0.035461f, 0.039215f, 0.043854f, 0.048706f,
+ 0.054413f, 0.060913f, 0.068237f, 0.076965f, 0.086792f, 0.097961f, 0.110657f, 0.125488f, 0.141846f, 0.160278f, 0.180542f, 0.203857f,
+ 0.229004f, 0.256348f, 0.286133f, 0.317627f, 0.351807f, 0.388184f, 0.737305f, 0.757812f, 0.762695f, 0.763672f, 0.764160f, 0.764648f,
+ 0.000214f, 0.000700f, 0.001134f, 0.001480f, 0.001724f, 0.002056f, 0.002468f, 0.002672f, 0.003069f, 0.003412f, 0.003618f, 0.003883f,
+ 0.004265f, 0.004627f, 0.004971f, 0.005508f, 0.005817f, 0.006397f, 0.006866f, 0.007244f, 0.007812f, 0.008446f, 0.009003f, 0.009872f,
+ 0.010544f, 0.011345f, 0.012375f, 0.013321f, 0.014275f, 0.015587f, 0.017075f, 0.018372f, 0.020050f, 0.022186f, 0.024246f, 0.026596f,
+ 0.029388f, 0.032562f, 0.036285f, 0.040344f, 0.045197f, 0.050568f, 0.056946f, 0.064514f, 0.072876f, 0.082886f, 0.093933f, 0.107056f,
+ 0.122070f, 0.139404f, 0.158325f, 0.180176f, 0.204590f, 0.231201f, 0.260010f, 0.290771f, 0.325195f, 0.361816f, 0.726074f, 0.747070f,
+ 0.751465f, 0.753418f, 0.753906f, 0.754395f, 0.000187f, 0.000637f, 0.001095f, 0.001133f, 0.001488f, 0.001872f, 0.002007f, 0.002253f,
+ 0.002590f, 0.002880f, 0.003010f, 0.003420f, 0.003593f, 0.003914f, 0.004322f, 0.004650f, 0.005051f, 0.005424f, 0.005733f, 0.006134f,
+ 0.006683f, 0.007183f, 0.007671f, 0.008072f, 0.008720f, 0.009483f, 0.010201f, 0.011070f, 0.011871f, 0.012863f, 0.013924f, 0.015167f,
+ 0.016434f, 0.018143f, 0.019669f, 0.021851f, 0.024109f, 0.026749f, 0.029587f, 0.033020f, 0.037109f, 0.041718f, 0.047119f, 0.053192f,
+ 0.060516f, 0.068848f, 0.078857f, 0.090149f, 0.104004f, 0.119202f, 0.136841f, 0.157471f, 0.180420f, 0.205322f, 0.234009f, 0.264648f,
+ 0.297852f, 0.335449f, 0.711914f, 0.735352f, 0.740234f, 0.741211f, 0.742676f, 0.742676f, 0.000201f, 0.000676f, 0.000884f, 0.001044f,
+ 0.001369f, 0.001633f, 0.001786f, 0.002001f, 0.002237f, 0.002460f, 0.002680f, 0.002777f, 0.003117f, 0.003408f, 0.003632f, 0.003910f,
+ 0.004211f, 0.004375f, 0.004772f, 0.005226f, 0.005520f, 0.005909f, 0.006302f, 0.006882f, 0.007385f, 0.007858f, 0.008553f, 0.008919f,
+ 0.009827f, 0.010582f, 0.011398f, 0.012520f, 0.013611f, 0.014725f, 0.016190f, 0.017593f, 0.019424f, 0.021622f, 0.023941f, 0.026703f,
+ 0.029938f, 0.033539f, 0.038055f, 0.043243f, 0.049408f, 0.056519f, 0.065002f, 0.074951f, 0.086548f, 0.100403f, 0.116394f, 0.135132f,
+ 0.156860f, 0.181030f, 0.208252f, 0.238281f, 0.271240f, 0.307861f, 0.698730f, 0.722656f, 0.727539f, 0.729980f, 0.730957f, 0.730469f,
+ 0.000185f, 0.000371f, 0.000784f, 0.001028f, 0.001153f, 0.001304f, 0.001567f, 0.001792f, 0.001790f, 0.002028f, 0.002283f, 0.002424f,
+ 0.002640f, 0.002764f, 0.003044f, 0.003313f, 0.003445f, 0.003748f, 0.004044f, 0.004337f, 0.004677f, 0.004879f, 0.005207f, 0.005661f,
+ 0.006027f, 0.006481f, 0.006870f, 0.007454f, 0.007874f, 0.008583f, 0.009239f, 0.009880f, 0.010849f, 0.011871f, 0.012833f, 0.014153f,
+ 0.015656f, 0.017151f, 0.018967f, 0.021118f, 0.023621f, 0.026703f, 0.030197f, 0.034576f, 0.039368f, 0.045441f, 0.052460f, 0.061157f,
+ 0.070862f, 0.083069f, 0.097290f, 0.114441f, 0.134155f, 0.157104f, 0.182983f, 0.212158f, 0.244507f, 0.281250f, 0.684570f, 0.710449f,
+ 0.715332f, 0.717285f, 0.717773f, 0.718750f, 0.000109f, 0.000455f, 0.000558f, 0.000757f, 0.000986f, 0.001166f, 0.001298f, 0.001310f,
+ 0.001566f, 0.001614f, 0.001852f, 0.001933f, 0.002062f, 0.002327f, 0.002571f, 0.002699f, 0.002909f, 0.003057f, 0.003254f, 0.003496f,
+ 0.003643f, 0.004066f, 0.004295f, 0.004665f, 0.004822f, 0.005161f, 0.005722f, 0.006008f, 0.006424f, 0.006897f, 0.007435f, 0.008049f,
+ 0.008789f, 0.009529f, 0.010284f, 0.011177f, 0.012321f, 0.013466f, 0.014885f, 0.016586f, 0.018417f, 0.020844f, 0.023575f, 0.026810f,
+ 0.030655f, 0.035400f, 0.041412f, 0.048462f, 0.056976f, 0.067322f, 0.079712f, 0.094543f, 0.112610f, 0.133789f, 0.158691f, 0.186279f,
+ 0.217896f, 0.253418f, 0.670898f, 0.696777f, 0.702148f, 0.704590f, 0.705078f, 0.705566f, 0.000000f, 0.000317f, 0.000556f, 0.000619f,
+ 0.000759f, 0.000889f, 0.001012f, 0.001163f, 0.001282f, 0.001353f, 0.001531f, 0.001621f, 0.001681f, 0.001862f, 0.001976f, 0.002140f,
+ 0.002392f, 0.002502f, 0.002745f, 0.002838f, 0.003019f, 0.003311f, 0.003477f, 0.003639f, 0.003889f, 0.004166f, 0.004429f, 0.004784f,
+ 0.005119f, 0.005547f, 0.006042f, 0.006317f, 0.006901f, 0.007442f, 0.008110f, 0.008751f, 0.009583f, 0.010590f, 0.011566f, 0.012894f,
+ 0.014404f, 0.015930f, 0.018158f, 0.020569f, 0.023697f, 0.027374f, 0.031830f, 0.037567f, 0.044434f, 0.053009f, 0.063599f, 0.076538f,
+ 0.092346f, 0.111511f, 0.134521f, 0.161133f, 0.191772f, 0.227173f, 0.654297f, 0.684082f, 0.687988f, 0.690918f, 0.691895f, 0.691895f,
+ 0.000000f, 0.000275f, 0.000368f, 0.000572f, 0.000683f, 0.000731f, 0.000877f, 0.000979f, 0.001039f, 0.001091f, 0.001234f, 0.001332f,
+ 0.001447f, 0.001547f, 0.001601f, 0.001760f, 0.001790f, 0.002007f, 0.002119f, 0.002245f, 0.002493f, 0.002565f, 0.002747f, 0.002920f,
+ 0.003168f, 0.003235f, 0.003551f, 0.003830f, 0.004040f, 0.004368f, 0.004658f, 0.005001f, 0.005337f, 0.005798f, 0.006287f, 0.006794f,
+ 0.007488f, 0.008087f, 0.008865f, 0.009773f, 0.010963f, 0.012199f, 0.013649f, 0.015610f, 0.017822f, 0.020493f, 0.023849f, 0.028320f,
+ 0.033752f, 0.040466f, 0.049377f, 0.060028f, 0.073853f, 0.090698f, 0.111572f, 0.136841f, 0.166016f, 0.199341f, 0.640137f, 0.667969f,
+ 0.675781f, 0.676758f, 0.678223f, 0.678223f, 0.000017f, 0.000193f, 0.000383f, 0.000487f, 0.000586f, 0.000597f, 0.000618f, 0.000733f,
+ 0.000826f, 0.000863f, 0.000902f, 0.001037f, 0.001121f, 0.001244f, 0.001342f, 0.001329f, 0.001514f, 0.001506f, 0.001719f, 0.001793f,
+ 0.001851f, 0.002016f, 0.002182f, 0.002281f, 0.002432f, 0.002554f, 0.002708f, 0.002859f, 0.003168f, 0.003344f, 0.003563f, 0.003845f,
+ 0.004158f, 0.004478f, 0.004852f, 0.005154f, 0.005714f, 0.006207f, 0.006752f, 0.007370f, 0.008186f, 0.009155f, 0.010193f, 0.011490f,
+ 0.013016f, 0.015144f, 0.017517f, 0.020752f, 0.024811f, 0.029922f, 0.036835f, 0.045593f, 0.056946f, 0.071533f, 0.090576f, 0.113159f,
+ 0.140991f, 0.173340f, 0.624023f, 0.653809f, 0.660156f, 0.663574f, 0.664551f, 0.664062f, 0.000194f, 0.000227f, 0.000316f, 0.000451f,
+ 0.000449f, 0.000482f, 0.000610f, 0.000511f, 0.000654f, 0.000673f, 0.000804f, 0.000844f, 0.000880f, 0.000955f, 0.000961f, 0.001127f,
+ 0.001169f, 0.001210f, 0.001318f, 0.001330f, 0.001507f, 0.001592f, 0.001657f, 0.001771f, 0.001839f, 0.001953f, 0.002083f, 0.002214f,
+ 0.002399f, 0.002518f, 0.002815f, 0.002882f, 0.003132f, 0.003361f, 0.003605f, 0.003925f, 0.004177f, 0.004528f, 0.004963f, 0.005527f,
+ 0.006027f, 0.006783f, 0.007381f, 0.008469f, 0.009644f, 0.010849f, 0.012772f, 0.014748f, 0.017578f, 0.021332f, 0.026367f, 0.033142f,
+ 0.042389f, 0.054413f, 0.070129f, 0.091064f, 0.116943f, 0.147339f, 0.608887f, 0.640137f, 0.645996f, 0.647461f, 0.650391f, 0.651367f,
+ 0.000166f, 0.000146f, 0.000248f, 0.000320f, 0.000288f, 0.000446f, 0.000375f, 0.000407f, 0.000468f, 0.000514f, 0.000629f, 0.000638f,
+ 0.000681f, 0.000773f, 0.000806f, 0.000766f, 0.000883f, 0.000927f, 0.000959f, 0.001036f, 0.001097f, 0.001172f, 0.001224f, 0.001297f,
+ 0.001392f, 0.001425f, 0.001592f, 0.001631f, 0.001793f, 0.001965f, 0.002089f, 0.002157f, 0.002321f, 0.002495f, 0.002680f, 0.002874f,
+ 0.003054f, 0.003305f, 0.003632f, 0.003902f, 0.004314f, 0.004753f, 0.005306f, 0.005901f, 0.006828f, 0.007645f, 0.008896f, 0.010323f,
+ 0.012283f, 0.014816f, 0.018234f, 0.023010f, 0.029678f, 0.039276f, 0.052307f, 0.070190f, 0.093811f, 0.123474f, 0.591797f, 0.623535f,
+ 0.631348f, 0.633301f, 0.634766f, 0.635254f, 0.000000f, 0.000154f, 0.000184f, 0.000257f, 0.000265f, 0.000266f, 0.000323f, 0.000291f,
+ 0.000369f, 0.000384f, 0.000450f, 0.000472f, 0.000505f, 0.000572f, 0.000577f, 0.000604f, 0.000636f, 0.000675f, 0.000699f, 0.000736f,
+ 0.000787f, 0.000840f, 0.000890f, 0.000945f, 0.000988f, 0.001039f, 0.001165f, 0.001165f, 0.001266f, 0.001318f, 0.001410f, 0.001550f,
+ 0.001618f, 0.001743f, 0.001866f, 0.001997f, 0.002151f, 0.002319f, 0.002562f, 0.002779f, 0.002975f, 0.003298f, 0.003674f, 0.004131f,
+ 0.004604f, 0.005268f, 0.006065f, 0.007027f, 0.008316f, 0.009949f, 0.012390f, 0.015526f, 0.019852f, 0.026733f, 0.036682f, 0.051666f,
+ 0.072449f, 0.099792f, 0.574707f, 0.608398f, 0.614746f, 0.618164f, 0.619629f, 0.621094f, 0.000000f, 0.000008f, 0.000146f, 0.000181f,
+ 0.000203f, 0.000243f, 0.000206f, 0.000250f, 0.000257f, 0.000283f, 0.000335f, 0.000293f, 0.000304f, 0.000368f, 0.000373f, 0.000435f,
+ 0.000418f, 0.000468f, 0.000539f, 0.000540f, 0.000564f, 0.000598f, 0.000628f, 0.000657f, 0.000716f, 0.000724f, 0.000797f, 0.000807f,
+ 0.000883f, 0.001002f, 0.000974f, 0.001037f, 0.001104f, 0.001196f, 0.001316f, 0.001394f, 0.001445f, 0.001574f, 0.001746f, 0.001829f,
+ 0.002005f, 0.002222f, 0.002401f, 0.002699f, 0.003057f, 0.003372f, 0.003874f, 0.004505f, 0.005360f, 0.006500f, 0.007927f, 0.009972f,
+ 0.012878f, 0.017258f, 0.024155f, 0.035339f, 0.052795f, 0.077637f, 0.558105f, 0.592285f, 0.600586f, 0.602539f, 0.604004f, 0.605469f,
+ 0.000000f, 0.000107f, 0.000122f, 0.000093f, 0.000133f, 0.000142f, 0.000149f, 0.000174f, 0.000174f, 0.000184f, 0.000190f, 0.000234f,
+ 0.000214f, 0.000250f, 0.000273f, 0.000286f, 0.000292f, 0.000302f, 0.000329f, 0.000336f, 0.000366f, 0.000391f, 0.000408f, 0.000444f,
+ 0.000452f, 0.000495f, 0.000531f, 0.000559f, 0.000578f, 0.000611f, 0.000659f, 0.000675f, 0.000757f, 0.000771f, 0.000854f, 0.000906f,
+ 0.000957f, 0.001004f, 0.001102f, 0.001187f, 0.001267f, 0.001394f, 0.001546f, 0.001683f, 0.001922f, 0.002094f, 0.002420f, 0.002754f,
+ 0.003254f, 0.003878f, 0.004757f, 0.005997f, 0.007812f, 0.010544f, 0.014786f, 0.022324f, 0.035522f, 0.057465f, 0.541504f, 0.576172f,
+ 0.583984f, 0.585938f, 0.588379f, 0.590332f, 0.000000f, 0.000099f, 0.000091f, 0.000084f, 0.000084f, 0.000086f, 0.000089f, 0.000101f,
+ 0.000105f, 0.000109f, 0.000122f, 0.000124f, 0.000132f, 0.000146f, 0.000171f, 0.000172f, 0.000176f, 0.000198f, 0.000197f, 0.000239f,
+ 0.000218f, 0.000235f, 0.000240f, 0.000281f, 0.000309f, 0.000301f, 0.000312f, 0.000321f, 0.000347f, 0.000370f, 0.000387f, 0.000419f,
+ 0.000444f, 0.000458f, 0.000513f, 0.000536f, 0.000570f, 0.000607f, 0.000688f, 0.000703f, 0.000754f, 0.000834f, 0.000890f, 0.000997f,
+ 0.001100f, 0.001238f, 0.001410f, 0.001584f, 0.001859f, 0.002207f, 0.002665f, 0.003323f, 0.004353f, 0.005947f, 0.008492f, 0.012909f,
+ 0.021606f, 0.039368f, 0.522461f, 0.559082f, 0.566406f, 0.569824f, 0.572266f, 0.572754f, 0.000108f, 0.000089f, 0.000079f, 0.000072f,
+ 0.000068f, 0.000065f, 0.000061f, 0.000057f, 0.000061f, 0.000062f, 0.000063f, 0.000086f, 0.000070f, 0.000071f, 0.000095f, 0.000080f,
+ 0.000107f, 0.000113f, 0.000115f, 0.000124f, 0.000121f, 0.000130f, 0.000151f, 0.000154f, 0.000164f, 0.000170f, 0.000176f, 0.000189f,
+ 0.000193f, 0.000215f, 0.000211f, 0.000242f, 0.000252f, 0.000260f, 0.000280f, 0.000293f, 0.000312f, 0.000350f, 0.000359f, 0.000389f,
+ 0.000410f, 0.000452f, 0.000481f, 0.000535f, 0.000578f, 0.000643f, 0.000718f, 0.000812f, 0.000939f, 0.001107f, 0.001329f, 0.001644f,
+ 0.002155f, 0.002930f, 0.004284f, 0.006706f, 0.011452f, 0.023895f, 0.504395f, 0.542480f, 0.550293f, 0.553711f, 0.555664f, 0.557129f,
+ 0.000093f, 0.000072f, 0.000063f, 0.000058f, 0.000053f, 0.000050f, 0.000047f, 0.000046f, 0.000044f, 0.000042f, 0.000039f, 0.000037f,
+ 0.000042f, 0.000035f, 0.000036f, 0.000037f, 0.000051f, 0.000046f, 0.000057f, 0.000058f, 0.000061f, 0.000062f, 0.000066f, 0.000069f,
+ 0.000072f, 0.000087f, 0.000077f, 0.000088f, 0.000093f, 0.000099f, 0.000103f, 0.000109f, 0.000115f, 0.000122f, 0.000139f, 0.000134f,
+ 0.000142f, 0.000170f, 0.000175f, 0.000179f, 0.000192f, 0.000203f, 0.000228f, 0.000245f, 0.000265f, 0.000291f, 0.000326f, 0.000360f,
+ 0.000420f, 0.000481f, 0.000574f, 0.000686f, 0.000887f, 0.001203f, 0.001759f, 0.002892f, 0.005318f, 0.011955f, 0.487305f, 0.524902f,
+ 0.534180f, 0.538086f, 0.539551f, 0.540527f, 0.000066f, 0.000049f, 0.000041f, 0.000037f, 0.000034f, 0.000033f, 0.000032f, 0.000030f,
+ 0.000029f, 0.000028f, 0.000028f, 0.000027f, 0.000026f, 0.000025f, 0.000024f, 0.000023f, 0.000022f, 0.000021f, 0.000022f, 0.000023f,
+ 0.000019f, 0.000018f, 0.000019f, 0.000024f, 0.000026f, 0.000029f, 0.000032f, 0.000032f, 0.000036f, 0.000034f, 0.000040f, 0.000041f,
+ 0.000043f, 0.000049f, 0.000049f, 0.000050f, 0.000056f, 0.000059f, 0.000067f, 0.000067f, 0.000074f, 0.000078f, 0.000082f, 0.000092f,
+ 0.000094f, 0.000103f, 0.000120f, 0.000130f, 0.000141f, 0.000163f, 0.000191f, 0.000230f, 0.000286f, 0.000374f, 0.000543f, 0.000890f,
+ 0.001802f, 0.004650f, 0.468994f, 0.507812f, 0.516602f, 0.520508f, 0.522461f, 0.523926f, 0.000007f, 0.000008f, 0.000008f, 0.000008f,
+ 0.000011f, 0.000010f, 0.000010f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000012f,
+ 0.000012f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000010f, 0.000009f, 0.000009f,
+ 0.000008f, 0.000008f, 0.000009f, 0.000009f, 0.000009f, 0.000009f, 0.000010f, 0.000011f, 0.000012f, 0.000014f, 0.000013f, 0.000016f,
+ 0.000015f, 0.000018f, 0.000020f, 0.000021f, 0.000022f, 0.000025f, 0.000024f, 0.000025f, 0.000030f, 0.000031f, 0.000040f, 0.000046f,
+ 0.000052f, 0.000071f, 0.000099f, 0.000147f, 0.000306f, 0.001072f, 0.450439f, 0.491211f, 0.499756f, 0.503418f, 0.505859f, 0.507324f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000007f, 0.000024f, 0.432129f, 0.474121f,
+ 0.482666f, 0.486572f, 0.489014f, 0.490234f,
+ },
+ {
+ 0.027573f, 0.080750f, 0.130981f, 0.177734f, 0.222290f, 0.263672f, 0.302002f, 0.338623f, 0.373291f, 0.405029f, 0.435791f, 0.464111f,
+ 0.490967f, 0.516602f, 0.540039f, 0.563477f, 0.584961f, 0.605469f, 0.625000f, 0.644043f, 0.660645f, 0.677246f, 0.693848f, 0.708496f,
+ 0.724121f, 0.738281f, 0.751465f, 0.764648f, 0.776855f, 0.789062f, 0.799805f, 0.810547f, 0.821289f, 0.831055f, 0.840820f, 0.850098f,
+ 0.859863f, 0.867676f, 0.876953f, 0.884277f, 0.892578f, 0.900391f, 0.907227f, 0.914551f, 0.921875f, 0.928223f, 0.934082f, 0.940430f,
+ 0.946777f, 0.952637f, 0.957520f, 0.964355f, 0.968262f, 0.974121f, 0.979004f, 0.983887f, 0.989258f, 0.994141f, 0.993164f, 0.983398f,
+ 0.976074f, 0.969238f, 0.962891f, 0.957031f, 0.022873f, 0.067871f, 0.111511f, 0.153809f, 0.193359f, 0.232788f, 0.268799f, 0.303223f,
+ 0.337402f, 0.368652f, 0.399414f, 0.427734f, 0.455078f, 0.481201f, 0.506348f, 0.529785f, 0.552246f, 0.573242f, 0.593750f, 0.613281f,
+ 0.632324f, 0.650391f, 0.667480f, 0.683105f, 0.698730f, 0.713867f, 0.728516f, 0.741211f, 0.755371f, 0.767578f, 0.779785f, 0.791504f,
+ 0.803223f, 0.813477f, 0.823242f, 0.834473f, 0.843750f, 0.853027f, 0.861816f, 0.870605f, 0.878906f, 0.887695f, 0.895996f, 0.901855f,
+ 0.910645f, 0.917480f, 0.923828f, 0.930176f, 0.937012f, 0.943359f, 0.949707f, 0.955078f, 0.960938f, 0.966797f, 0.972656f, 0.977051f,
+ 0.982422f, 0.987305f, 0.989746f, 0.981445f, 0.973633f, 0.967773f, 0.961426f, 0.956055f, 0.019089f, 0.057007f, 0.095215f, 0.132202f,
+ 0.168823f, 0.204712f, 0.238281f, 0.272217f, 0.304688f, 0.334717f, 0.364502f, 0.392822f, 0.420898f, 0.446533f, 0.471924f, 0.495850f,
+ 0.518555f, 0.541992f, 0.562988f, 0.582520f, 0.602539f, 0.621094f, 0.639160f, 0.655762f, 0.672852f, 0.687988f, 0.703613f, 0.718262f,
+ 0.732422f, 0.746094f, 0.758789f, 0.771484f, 0.783203f, 0.795898f, 0.807129f, 0.817383f, 0.827637f, 0.837402f, 0.846680f, 0.856445f,
+ 0.865234f, 0.874023f, 0.882324f, 0.890137f, 0.898438f, 0.905273f, 0.913574f, 0.920410f, 0.927246f, 0.934082f, 0.940918f, 0.946777f,
+ 0.953125f, 0.958496f, 0.964844f, 0.969727f, 0.975586f, 0.980957f, 0.986816f, 0.979004f, 0.971680f, 0.965332f, 0.959961f, 0.954590f,
+ 0.016327f, 0.048676f, 0.081787f, 0.114807f, 0.147705f, 0.180176f, 0.211426f, 0.243652f, 0.273438f, 0.303223f, 0.332031f, 0.360107f,
+ 0.386963f, 0.412598f, 0.438477f, 0.462891f, 0.487305f, 0.510254f, 0.530762f, 0.552246f, 0.572754f, 0.590820f, 0.610352f, 0.629883f,
+ 0.647461f, 0.662598f, 0.679688f, 0.693848f, 0.709961f, 0.723633f, 0.737305f, 0.750977f, 0.763672f, 0.776367f, 0.788086f, 0.799316f,
+ 0.810059f, 0.820801f, 0.832031f, 0.841309f, 0.851074f, 0.860352f, 0.868652f, 0.877930f, 0.886230f, 0.894531f, 0.902832f, 0.910156f,
+ 0.916504f, 0.924316f, 0.930664f, 0.937500f, 0.943848f, 0.950684f, 0.957031f, 0.962891f, 0.968262f, 0.974121f, 0.983887f, 0.976074f,
+ 0.969727f, 0.963867f, 0.958496f, 0.953125f, 0.013573f, 0.041901f, 0.070801f, 0.100098f, 0.129517f, 0.159058f, 0.187866f, 0.217041f,
+ 0.246216f, 0.274414f, 0.302002f, 0.328857f, 0.354980f, 0.381592f, 0.406738f, 0.431641f, 0.455322f, 0.478271f, 0.500000f, 0.521484f,
+ 0.541992f, 0.563477f, 0.583008f, 0.600098f, 0.619141f, 0.636719f, 0.653320f, 0.671387f, 0.684570f, 0.699707f, 0.715332f, 0.729492f,
+ 0.743164f, 0.755371f, 0.768555f, 0.780762f, 0.792480f, 0.804199f, 0.814453f, 0.824707f, 0.835449f, 0.845215f, 0.854980f, 0.864746f,
+ 0.874023f, 0.882812f, 0.890137f, 0.898438f, 0.905762f, 0.914062f, 0.921387f, 0.928223f, 0.935059f, 0.941406f, 0.948242f, 0.955078f,
+ 0.961426f, 0.966797f, 0.980957f, 0.973633f, 0.967773f, 0.961914f, 0.956543f, 0.951660f, 0.011681f, 0.036316f, 0.061584f, 0.087524f,
+ 0.113342f, 0.140259f, 0.167358f, 0.194214f, 0.220947f, 0.247437f, 0.273926f, 0.300537f, 0.325684f, 0.351074f, 0.375732f, 0.400146f,
+ 0.423828f, 0.446533f, 0.469482f, 0.491943f, 0.512695f, 0.532715f, 0.553223f, 0.573242f, 0.592285f, 0.609863f, 0.627930f, 0.644531f,
+ 0.660156f, 0.676758f, 0.691406f, 0.706055f, 0.720215f, 0.734863f, 0.749023f, 0.762207f, 0.774414f, 0.786133f, 0.797852f, 0.809082f,
+ 0.820801f, 0.831055f, 0.840332f, 0.850098f, 0.859863f, 0.869629f, 0.878418f, 0.886719f, 0.895508f, 0.903809f, 0.910645f, 0.918945f,
+ 0.925781f, 0.932617f, 0.939453f, 0.947754f, 0.953613f, 0.958984f, 0.977539f, 0.970703f, 0.964844f, 0.959473f, 0.954102f, 0.949707f,
+ 0.010330f, 0.031525f, 0.053406f, 0.076538f, 0.100159f, 0.124084f, 0.148193f, 0.173096f, 0.197998f, 0.223267f, 0.247681f, 0.273193f,
+ 0.297607f, 0.322021f, 0.346924f, 0.370117f, 0.394043f, 0.417236f, 0.439697f, 0.462158f, 0.483887f, 0.504883f, 0.524902f, 0.545410f,
+ 0.563477f, 0.583008f, 0.602539f, 0.618652f, 0.636230f, 0.652344f, 0.669922f, 0.685059f, 0.699219f, 0.714355f, 0.729004f, 0.741211f,
+ 0.755371f, 0.767578f, 0.780762f, 0.792480f, 0.803711f, 0.815918f, 0.825195f, 0.836914f, 0.846191f, 0.855957f, 0.864746f, 0.874512f,
+ 0.883301f, 0.891602f, 0.900391f, 0.908203f, 0.916016f, 0.923828f, 0.931152f, 0.937988f, 0.945801f, 0.952148f, 0.974121f, 0.967773f,
+ 0.962891f, 0.957520f, 0.952637f, 0.947754f, 0.009186f, 0.027359f, 0.047302f, 0.067505f, 0.088806f, 0.109924f, 0.132202f, 0.154907f,
+ 0.177246f, 0.201050f, 0.224121f, 0.247925f, 0.271240f, 0.295410f, 0.318359f, 0.341797f, 0.365234f, 0.387939f, 0.410156f, 0.432861f,
+ 0.454590f, 0.475586f, 0.495850f, 0.517090f, 0.536621f, 0.556152f, 0.575195f, 0.592773f, 0.609863f, 0.628418f, 0.645020f, 0.661133f,
+ 0.677246f, 0.692383f, 0.707520f, 0.721191f, 0.735352f, 0.748047f, 0.762207f, 0.774414f, 0.786621f, 0.798828f, 0.810547f, 0.820801f,
+ 0.831543f, 0.842285f, 0.852539f, 0.862305f, 0.871094f, 0.880859f, 0.889648f, 0.898438f, 0.906738f, 0.914551f, 0.921875f, 0.929199f,
+ 0.936035f, 0.944824f, 0.971191f, 0.965332f, 0.959473f, 0.955078f, 0.950195f, 0.945801f, 0.008041f, 0.024384f, 0.041321f, 0.059631f,
+ 0.078003f, 0.097656f, 0.117554f, 0.138428f, 0.159912f, 0.181152f, 0.203003f, 0.224976f, 0.247070f, 0.269531f, 0.292480f, 0.314697f,
+ 0.337891f, 0.360352f, 0.382324f, 0.403809f, 0.426025f, 0.447998f, 0.468018f, 0.488770f, 0.508301f, 0.528320f, 0.547852f, 0.567383f,
+ 0.585449f, 0.603516f, 0.620605f, 0.637695f, 0.654297f, 0.670410f, 0.686523f, 0.700195f, 0.715820f, 0.729980f, 0.743164f, 0.756836f,
+ 0.769531f, 0.782715f, 0.794434f, 0.805664f, 0.816895f, 0.827637f, 0.838379f, 0.848633f, 0.859375f, 0.868164f, 0.877930f, 0.887695f,
+ 0.895996f, 0.905273f, 0.912598f, 0.920898f, 0.928711f, 0.936035f, 0.966797f, 0.962402f, 0.957031f, 0.952637f, 0.947754f, 0.943848f,
+ 0.007095f, 0.021515f, 0.036926f, 0.052704f, 0.069641f, 0.087463f, 0.105347f, 0.123413f, 0.143188f, 0.163452f, 0.183105f, 0.204102f,
+ 0.225220f, 0.246704f, 0.268066f, 0.290283f, 0.311768f, 0.333740f, 0.355225f, 0.376465f, 0.397949f, 0.419434f, 0.440430f, 0.461670f,
+ 0.481445f, 0.500977f, 0.520020f, 0.540527f, 0.559570f, 0.578125f, 0.595703f, 0.613770f, 0.630371f, 0.646973f, 0.663086f, 0.678223f,
+ 0.694336f, 0.709473f, 0.723145f, 0.736328f, 0.750000f, 0.764648f, 0.777344f, 0.790039f, 0.801270f, 0.812988f, 0.824707f, 0.834961f,
+ 0.846191f, 0.856934f, 0.865723f, 0.875977f, 0.884766f, 0.894531f, 0.903320f, 0.911621f, 0.919922f, 0.927734f, 0.962891f, 0.959473f,
+ 0.954102f, 0.949219f, 0.945312f, 0.941406f, 0.006138f, 0.019150f, 0.033051f, 0.047089f, 0.061829f, 0.077515f, 0.094299f, 0.111084f,
+ 0.128174f, 0.146729f, 0.165771f, 0.185059f, 0.205200f, 0.224731f, 0.245361f, 0.265625f, 0.286865f, 0.307861f, 0.328857f, 0.350098f,
+ 0.370605f, 0.392090f, 0.413086f, 0.433594f, 0.454346f, 0.474609f, 0.493896f, 0.513672f, 0.532227f, 0.552734f, 0.569824f, 0.588867f,
+ 0.605957f, 0.623047f, 0.640625f, 0.656738f, 0.672852f, 0.688477f, 0.703613f, 0.717773f, 0.732910f, 0.746582f, 0.759766f, 0.772461f,
+ 0.786621f, 0.798340f, 0.810059f, 0.820312f, 0.832520f, 0.842773f, 0.853516f, 0.863770f, 0.873535f, 0.883789f, 0.892578f, 0.901367f,
+ 0.910645f, 0.919434f, 0.958984f, 0.955566f, 0.951172f, 0.946777f, 0.942871f, 0.938965f, 0.005424f, 0.017059f, 0.029541f, 0.042023f,
+ 0.055389f, 0.069397f, 0.083984f, 0.099670f, 0.115601f, 0.132324f, 0.149292f, 0.167114f, 0.185547f, 0.204468f, 0.224121f, 0.243896f,
+ 0.262939f, 0.283691f, 0.304443f, 0.323486f, 0.345459f, 0.365479f, 0.386230f, 0.407471f, 0.426758f, 0.448486f, 0.467529f, 0.487061f,
+ 0.506348f, 0.526367f, 0.545410f, 0.563965f, 0.581543f, 0.600098f, 0.617676f, 0.634277f, 0.650391f, 0.666016f, 0.682617f, 0.697754f,
+ 0.712891f, 0.727539f, 0.741211f, 0.755859f, 0.769043f, 0.782227f, 0.793945f, 0.806152f, 0.818848f, 0.830566f, 0.840332f, 0.851074f,
+ 0.861328f, 0.872070f, 0.881836f, 0.892090f, 0.900879f, 0.910645f, 0.955566f, 0.952637f, 0.948730f, 0.943359f, 0.939941f, 0.935547f,
+ 0.004833f, 0.015442f, 0.026169f, 0.037689f, 0.049683f, 0.062164f, 0.075806f, 0.089539f, 0.103760f, 0.119263f, 0.134888f, 0.151978f,
+ 0.168335f, 0.186646f, 0.204102f, 0.223022f, 0.242065f, 0.260986f, 0.280518f, 0.300537f, 0.320801f, 0.340820f, 0.360107f, 0.381104f,
+ 0.401367f, 0.421387f, 0.441650f, 0.460449f, 0.480957f, 0.500000f, 0.519531f, 0.538574f, 0.557129f, 0.575684f, 0.593262f, 0.610840f,
+ 0.628906f, 0.645508f, 0.662109f, 0.677246f, 0.692871f, 0.708008f, 0.723145f, 0.738281f, 0.751465f, 0.766113f, 0.778320f, 0.791504f,
+ 0.802246f, 0.816406f, 0.827637f, 0.838867f, 0.850098f, 0.860352f, 0.871582f, 0.881348f, 0.890137f, 0.899902f, 0.951660f, 0.948730f,
+ 0.944824f, 0.940918f, 0.937012f, 0.933594f, 0.004269f, 0.013809f, 0.023911f, 0.033569f, 0.044342f, 0.056213f, 0.068054f, 0.080811f,
+ 0.093933f, 0.107910f, 0.122131f, 0.137451f, 0.152710f, 0.169434f, 0.185791f, 0.203979f, 0.221436f, 0.239990f, 0.257812f, 0.277344f,
+ 0.296631f, 0.316162f, 0.335693f, 0.355713f, 0.375244f, 0.395996f, 0.416016f, 0.436035f, 0.455078f, 0.474365f, 0.494629f, 0.513184f,
+ 0.532715f, 0.550781f, 0.569336f, 0.586914f, 0.604980f, 0.622559f, 0.639648f, 0.655762f, 0.672363f, 0.688477f, 0.704102f, 0.718750f,
+ 0.733887f, 0.747559f, 0.761230f, 0.775391f, 0.788574f, 0.800781f, 0.814453f, 0.825684f, 0.837402f, 0.848633f, 0.859375f, 0.870605f,
+ 0.880371f, 0.891113f, 0.947754f, 0.945312f, 0.941895f, 0.937988f, 0.934082f, 0.931152f, 0.004028f, 0.012581f, 0.021133f, 0.030396f,
+ 0.039948f, 0.050323f, 0.061523f, 0.072815f, 0.084961f, 0.096985f, 0.110535f, 0.124756f, 0.138916f, 0.153687f, 0.169800f, 0.185669f,
+ 0.202881f, 0.219116f, 0.237305f, 0.255615f, 0.273926f, 0.293213f, 0.311768f, 0.331055f, 0.351074f, 0.370605f, 0.390381f, 0.409668f,
+ 0.429688f, 0.449707f, 0.468994f, 0.487549f, 0.506836f, 0.526367f, 0.545898f, 0.562988f, 0.581543f, 0.599121f, 0.616699f, 0.634766f,
+ 0.651367f, 0.667480f, 0.683594f, 0.699707f, 0.714844f, 0.730957f, 0.744141f, 0.758789f, 0.772949f, 0.785645f, 0.799316f, 0.812500f,
+ 0.823730f, 0.836914f, 0.847168f, 0.859375f, 0.869629f, 0.880371f, 0.942383f, 0.941406f, 0.937500f, 0.934570f, 0.931152f, 0.927734f,
+ 0.003613f, 0.011391f, 0.018875f, 0.027679f, 0.036133f, 0.045624f, 0.055420f, 0.065491f, 0.076416f, 0.088135f, 0.099487f, 0.112427f,
+ 0.126099f, 0.139771f, 0.154419f, 0.169556f, 0.184814f, 0.201050f, 0.218262f, 0.234985f, 0.252441f, 0.271484f, 0.289062f, 0.308594f,
+ 0.326660f, 0.346924f, 0.365234f, 0.384521f, 0.404541f, 0.424072f, 0.443359f, 0.463135f, 0.482422f, 0.501953f, 0.521484f, 0.539551f,
+ 0.558594f, 0.576660f, 0.595215f, 0.612793f, 0.629883f, 0.647949f, 0.663574f, 0.679688f, 0.695801f, 0.711426f, 0.727539f, 0.741699f,
+ 0.757324f, 0.770996f, 0.785156f, 0.798828f, 0.811035f, 0.823730f, 0.835449f, 0.848145f, 0.858887f, 0.870605f, 0.937988f, 0.937988f,
+ 0.934570f, 0.931152f, 0.927734f, 0.924805f, 0.003248f, 0.010185f, 0.017395f, 0.025055f, 0.032928f, 0.041321f, 0.049957f, 0.059265f,
+ 0.069092f, 0.079407f, 0.090820f, 0.101746f, 0.113770f, 0.126953f, 0.140381f, 0.154053f, 0.168701f, 0.184082f, 0.199951f, 0.216431f,
+ 0.232788f, 0.250000f, 0.267578f, 0.285645f, 0.303955f, 0.322998f, 0.341553f, 0.361084f, 0.379150f, 0.399414f, 0.418701f, 0.437988f,
+ 0.457275f, 0.477051f, 0.496094f, 0.515137f, 0.534180f, 0.553223f, 0.571289f, 0.589844f, 0.606934f, 0.625488f, 0.643066f, 0.659668f,
+ 0.676758f, 0.692871f, 0.708984f, 0.725098f, 0.740234f, 0.753906f, 0.769043f, 0.782227f, 0.796387f, 0.810059f, 0.822266f, 0.834961f,
+ 0.847168f, 0.859375f, 0.933594f, 0.933594f, 0.931152f, 0.927246f, 0.923828f, 0.921387f, 0.002914f, 0.009361f, 0.015793f, 0.022659f,
+ 0.029938f, 0.037354f, 0.045593f, 0.053406f, 0.062988f, 0.072083f, 0.081665f, 0.092712f, 0.103943f, 0.114990f, 0.128174f, 0.140503f,
+ 0.153809f, 0.167725f, 0.182251f, 0.198242f, 0.213623f, 0.230225f, 0.246826f, 0.263672f, 0.281494f, 0.300049f, 0.318604f, 0.337158f,
+ 0.356201f, 0.374756f, 0.394531f, 0.413574f, 0.433105f, 0.451904f, 0.471680f, 0.491211f, 0.509766f, 0.529297f, 0.547852f, 0.566895f,
+ 0.584961f, 0.603516f, 0.621094f, 0.638672f, 0.656738f, 0.673340f, 0.689453f, 0.706543f, 0.722656f, 0.737793f, 0.752930f, 0.767578f,
+ 0.781250f, 0.796875f, 0.809082f, 0.823242f, 0.835449f, 0.847656f, 0.929199f, 0.929199f, 0.927246f, 0.923828f, 0.920898f, 0.917969f,
+ 0.002766f, 0.008736f, 0.014442f, 0.020691f, 0.027054f, 0.033905f, 0.040924f, 0.048645f, 0.056976f, 0.065674f, 0.074951f, 0.084229f,
+ 0.094116f, 0.105225f, 0.116333f, 0.127563f, 0.139771f, 0.153564f, 0.166626f, 0.181030f, 0.196411f, 0.211182f, 0.227417f, 0.243896f,
+ 0.260742f, 0.277588f, 0.295898f, 0.314209f, 0.332031f, 0.351562f, 0.370117f, 0.389404f, 0.408203f, 0.428223f, 0.447266f, 0.467041f,
+ 0.486084f, 0.505859f, 0.524414f, 0.543945f, 0.562012f, 0.581543f, 0.600098f, 0.617676f, 0.636230f, 0.654297f, 0.670898f, 0.687500f,
+ 0.704102f, 0.720703f, 0.736816f, 0.751465f, 0.766113f, 0.781738f, 0.796387f, 0.809082f, 0.823242f, 0.835938f, 0.923828f, 0.925781f,
+ 0.922852f, 0.920410f, 0.916992f, 0.914551f, 0.002483f, 0.007599f, 0.013161f, 0.018555f, 0.024551f, 0.030670f, 0.037476f, 0.044464f,
+ 0.051636f, 0.059174f, 0.067688f, 0.075928f, 0.085693f, 0.095093f, 0.105591f, 0.116394f, 0.127441f, 0.139648f, 0.152344f, 0.165527f,
+ 0.179565f, 0.193970f, 0.208862f, 0.224487f, 0.240356f, 0.256836f, 0.274658f, 0.291748f, 0.310059f, 0.328369f, 0.346680f, 0.365234f,
+ 0.384521f, 0.404297f, 0.423340f, 0.442139f, 0.462646f, 0.481445f, 0.500977f, 0.520020f, 0.540039f, 0.559082f, 0.577148f, 0.596191f,
+ 0.614746f, 0.632812f, 0.651367f, 0.669434f, 0.685059f, 0.702637f, 0.718750f, 0.734375f, 0.750488f, 0.766113f, 0.780762f, 0.795410f,
+ 0.811035f, 0.823730f, 0.919434f, 0.920898f, 0.918457f, 0.916016f, 0.913086f, 0.910645f, 0.002457f, 0.007114f, 0.011757f, 0.016708f,
+ 0.022125f, 0.027786f, 0.033752f, 0.040375f, 0.046661f, 0.053864f, 0.061584f, 0.069336f, 0.077515f, 0.086365f, 0.095947f, 0.105896f,
+ 0.116638f, 0.127075f, 0.138916f, 0.151245f, 0.164062f, 0.177490f, 0.191528f, 0.206177f, 0.221802f, 0.237427f, 0.253906f, 0.270508f,
+ 0.287842f, 0.305664f, 0.323730f, 0.342285f, 0.361572f, 0.379639f, 0.399170f, 0.418457f, 0.438965f, 0.458252f, 0.477295f, 0.497559f,
+ 0.516113f, 0.536133f, 0.554688f, 0.574707f, 0.593750f, 0.612305f, 0.630859f, 0.648926f, 0.666504f, 0.684082f, 0.701660f, 0.717773f,
+ 0.734863f, 0.751465f, 0.766602f, 0.781738f, 0.797852f, 0.812012f, 0.913086f, 0.916016f, 0.913574f, 0.911621f, 0.909180f, 0.906250f,
+ 0.002132f, 0.006493f, 0.010750f, 0.015717f, 0.020569f, 0.025604f, 0.030823f, 0.036682f, 0.043060f, 0.049286f, 0.055786f, 0.062988f,
+ 0.070557f, 0.078918f, 0.086914f, 0.096191f, 0.105530f, 0.116028f, 0.126953f, 0.138306f, 0.149902f, 0.162231f, 0.175537f, 0.189453f,
+ 0.203491f, 0.218628f, 0.234131f, 0.250000f, 0.266602f, 0.284180f, 0.301514f, 0.319580f, 0.338135f, 0.356689f, 0.375977f, 0.395020f,
+ 0.413818f, 0.434082f, 0.452881f, 0.473145f, 0.492920f, 0.512207f, 0.532227f, 0.552246f, 0.570801f, 0.591309f, 0.609375f, 0.629395f,
+ 0.646973f, 0.665527f, 0.683105f, 0.700684f, 0.717773f, 0.734863f, 0.751465f, 0.767578f, 0.782715f, 0.799316f, 0.908203f, 0.911133f,
+ 0.909180f, 0.907227f, 0.904785f, 0.902832f, 0.001891f, 0.006008f, 0.010025f, 0.014122f, 0.018616f, 0.023239f, 0.028442f, 0.033691f,
+ 0.038757f, 0.044556f, 0.050964f, 0.057465f, 0.064087f, 0.071167f, 0.079224f, 0.087463f, 0.096008f, 0.105591f, 0.115356f, 0.125488f,
+ 0.136597f, 0.148193f, 0.160278f, 0.173218f, 0.186768f, 0.200684f, 0.215332f, 0.231323f, 0.246338f, 0.262939f, 0.279785f, 0.297607f,
+ 0.314941f, 0.333984f, 0.353271f, 0.371094f, 0.391357f, 0.409668f, 0.430420f, 0.448975f, 0.469482f, 0.489746f, 0.509277f, 0.528809f,
+ 0.549316f, 0.568848f, 0.588379f, 0.607910f, 0.626953f, 0.645996f, 0.664062f, 0.683105f, 0.700684f, 0.718262f, 0.735840f, 0.751953f,
+ 0.768555f, 0.785645f, 0.902344f, 0.906250f, 0.904785f, 0.902832f, 0.900391f, 0.898438f, 0.001732f, 0.005573f, 0.009193f, 0.012932f,
+ 0.017075f, 0.021286f, 0.025406f, 0.030289f, 0.035675f, 0.040344f, 0.046326f, 0.052032f, 0.058411f, 0.064575f, 0.072205f, 0.079834f,
+ 0.087708f, 0.095947f, 0.104797f, 0.114380f, 0.124451f, 0.134888f, 0.146606f, 0.158691f, 0.170776f, 0.184082f, 0.197510f, 0.212524f,
+ 0.227417f, 0.243164f, 0.259521f, 0.276367f, 0.293457f, 0.311768f, 0.329590f, 0.348633f, 0.367188f, 0.386230f, 0.406006f, 0.425781f,
+ 0.446533f, 0.465332f, 0.486084f, 0.505859f, 0.526367f, 0.545898f, 0.567383f, 0.585938f, 0.605957f, 0.625977f, 0.645508f, 0.664551f,
+ 0.683105f, 0.701172f, 0.718750f, 0.736816f, 0.754395f, 0.770508f, 0.896484f, 0.900879f, 0.900391f, 0.897949f, 0.895996f, 0.894043f,
+ 0.001713f, 0.004684f, 0.008339f, 0.011818f, 0.015450f, 0.019409f, 0.023605f, 0.027832f, 0.032349f, 0.036865f, 0.041809f, 0.047302f,
+ 0.052673f, 0.058838f, 0.065613f, 0.072083f, 0.079407f, 0.087280f, 0.095337f, 0.104126f, 0.113037f, 0.122986f, 0.133667f, 0.144897f,
+ 0.156250f, 0.168579f, 0.181396f, 0.195068f, 0.208984f, 0.224243f, 0.239624f, 0.255859f, 0.272461f, 0.289551f, 0.307617f, 0.326172f,
+ 0.344482f, 0.363770f, 0.383301f, 0.402588f, 0.422607f, 0.443115f, 0.463135f, 0.483154f, 0.503418f, 0.523926f, 0.544434f, 0.564941f,
+ 0.584473f, 0.604980f, 0.624512f, 0.645508f, 0.664551f, 0.683594f, 0.701660f, 0.721191f, 0.738281f, 0.755859f, 0.889648f, 0.895996f,
+ 0.895020f, 0.893066f, 0.891602f, 0.889160f, 0.001545f, 0.004745f, 0.007710f, 0.010979f, 0.014450f, 0.017807f, 0.021469f, 0.025238f,
+ 0.029282f, 0.033661f, 0.038177f, 0.043182f, 0.048157f, 0.053436f, 0.059326f, 0.065674f, 0.072205f, 0.078857f, 0.086548f, 0.094604f,
+ 0.102905f, 0.111816f, 0.121521f, 0.131592f, 0.142334f, 0.153442f, 0.165894f, 0.178345f, 0.192139f, 0.205933f, 0.220703f, 0.236084f,
+ 0.251709f, 0.268555f, 0.285645f, 0.303467f, 0.321777f, 0.340332f, 0.359619f, 0.379150f, 0.398682f, 0.419189f, 0.440430f, 0.460449f,
+ 0.480957f, 0.501465f, 0.521973f, 0.543457f, 0.563477f, 0.584961f, 0.604492f, 0.625488f, 0.645508f, 0.665039f, 0.684082f, 0.704102f,
+ 0.723145f, 0.741211f, 0.885254f, 0.890137f, 0.889160f, 0.887695f, 0.886719f, 0.884277f, 0.001487f, 0.004356f, 0.006828f, 0.010162f,
+ 0.012993f, 0.016022f, 0.019333f, 0.023087f, 0.026886f, 0.030518f, 0.034668f, 0.039062f, 0.043671f, 0.048370f, 0.053741f, 0.059326f,
+ 0.065308f, 0.071655f, 0.078125f, 0.085693f, 0.093323f, 0.101807f, 0.110657f, 0.119507f, 0.129517f, 0.140137f, 0.151367f, 0.163330f,
+ 0.175781f, 0.188843f, 0.202759f, 0.217163f, 0.232666f, 0.248413f, 0.264893f, 0.282227f, 0.299805f, 0.318115f, 0.336914f, 0.356445f,
+ 0.375488f, 0.395996f, 0.416504f, 0.436279f, 0.457520f, 0.479004f, 0.499023f, 0.520508f, 0.541504f, 0.562988f, 0.583984f, 0.604492f,
+ 0.625488f, 0.646973f, 0.666504f, 0.687012f, 0.706055f, 0.725098f, 0.877441f, 0.885254f, 0.884766f, 0.882324f, 0.881836f, 0.880371f,
+ 0.001443f, 0.003807f, 0.006336f, 0.009171f, 0.011909f, 0.015007f, 0.018097f, 0.020905f, 0.024384f, 0.027893f, 0.031555f, 0.035370f,
+ 0.039581f, 0.044128f, 0.048889f, 0.053894f, 0.059174f, 0.065125f, 0.070984f, 0.077698f, 0.084656f, 0.091919f, 0.100037f, 0.108093f,
+ 0.117493f, 0.127563f, 0.137817f, 0.148438f, 0.159912f, 0.172485f, 0.185547f, 0.199585f, 0.213867f, 0.229248f, 0.244995f, 0.261230f,
+ 0.278564f, 0.296387f, 0.314697f, 0.333252f, 0.353271f, 0.372314f, 0.393311f, 0.413330f, 0.433594f, 0.455078f, 0.476318f, 0.497314f,
+ 0.519531f, 0.540527f, 0.562500f, 0.583496f, 0.605469f, 0.626953f, 0.648438f, 0.669434f, 0.689941f, 0.709961f, 0.870605f, 0.878906f,
+ 0.878418f, 0.877441f, 0.875488f, 0.873535f, 0.001302f, 0.003712f, 0.005859f, 0.008286f, 0.010910f, 0.013779f, 0.016235f, 0.019135f,
+ 0.021912f, 0.025345f, 0.029022f, 0.032166f, 0.036011f, 0.040131f, 0.044128f, 0.048492f, 0.053528f, 0.058533f, 0.064209f, 0.070129f,
+ 0.076355f, 0.083191f, 0.090149f, 0.098328f, 0.106628f, 0.115662f, 0.124817f, 0.134766f, 0.145630f, 0.157104f, 0.169678f, 0.182495f,
+ 0.195801f, 0.210205f, 0.225342f, 0.241455f, 0.257812f, 0.274902f, 0.292725f, 0.311035f, 0.330322f, 0.349365f, 0.369873f, 0.390137f,
+ 0.411133f, 0.432373f, 0.453369f, 0.474609f, 0.496826f, 0.519043f, 0.541504f, 0.563477f, 0.585449f, 0.606445f, 0.629395f, 0.650391f,
+ 0.672363f, 0.693848f, 0.863281f, 0.872070f, 0.872070f, 0.871582f, 0.869629f, 0.868164f, 0.001170f, 0.003151f, 0.005295f, 0.007812f,
+ 0.010132f, 0.012466f, 0.015076f, 0.017517f, 0.019943f, 0.023178f, 0.026443f, 0.029312f, 0.032471f, 0.036041f, 0.039978f, 0.044037f,
+ 0.048828f, 0.053070f, 0.057983f, 0.063232f, 0.068909f, 0.075378f, 0.081909f, 0.088745f, 0.096375f, 0.104309f, 0.113281f, 0.122437f,
+ 0.132202f, 0.142944f, 0.154419f, 0.166138f, 0.178955f, 0.192505f, 0.206421f, 0.221558f, 0.237183f, 0.253906f, 0.270996f, 0.289062f,
+ 0.308105f, 0.326904f, 0.346924f, 0.366455f, 0.387695f, 0.408936f, 0.430176f, 0.451416f, 0.474365f, 0.496582f, 0.518066f, 0.541016f,
+ 0.563965f, 0.585938f, 0.608887f, 0.630859f, 0.654297f, 0.675781f, 0.856934f, 0.865234f, 0.866211f, 0.864746f, 0.863281f, 0.862793f,
+ 0.001049f, 0.003254f, 0.005234f, 0.007263f, 0.009270f, 0.011307f, 0.013596f, 0.015869f, 0.018555f, 0.020844f, 0.023972f, 0.026566f,
+ 0.029739f, 0.033020f, 0.036316f, 0.039856f, 0.044159f, 0.048096f, 0.052277f, 0.057281f, 0.062439f, 0.067871f, 0.073792f, 0.079956f,
+ 0.087158f, 0.094055f, 0.102234f, 0.110535f, 0.119934f, 0.129517f, 0.140259f, 0.151245f, 0.162842f, 0.175537f, 0.189209f, 0.203369f,
+ 0.218262f, 0.233643f, 0.250488f, 0.268066f, 0.285645f, 0.304443f, 0.324219f, 0.343750f, 0.364014f, 0.385254f, 0.406494f, 0.428223f,
+ 0.450928f, 0.472656f, 0.495605f, 0.519043f, 0.541504f, 0.565918f, 0.588379f, 0.612305f, 0.635742f, 0.659180f, 0.850098f, 0.859863f,
+ 0.859863f, 0.858398f, 0.857910f, 0.856934f, 0.000914f, 0.002861f, 0.004742f, 0.006569f, 0.008415f, 0.010521f, 0.012596f, 0.014648f,
+ 0.016708f, 0.019089f, 0.021515f, 0.023865f, 0.026688f, 0.029572f, 0.032928f, 0.036377f, 0.039337f, 0.043365f, 0.047333f, 0.051544f,
+ 0.056305f, 0.061066f, 0.066406f, 0.071960f, 0.078247f, 0.084961f, 0.092163f, 0.099426f, 0.108215f, 0.116943f, 0.126831f, 0.136719f,
+ 0.148193f, 0.159302f, 0.171875f, 0.185669f, 0.199585f, 0.214478f, 0.230469f, 0.247070f, 0.264160f, 0.282471f, 0.301270f, 0.321045f,
+ 0.341553f, 0.362061f, 0.383545f, 0.404785f, 0.427734f, 0.449951f, 0.473389f, 0.496582f, 0.520020f, 0.543457f, 0.568359f, 0.592285f,
+ 0.615723f, 0.639648f, 0.840820f, 0.851074f, 0.853027f, 0.853027f, 0.852051f, 0.850586f, 0.000679f, 0.002518f, 0.004173f, 0.006149f,
+ 0.008064f, 0.009369f, 0.011551f, 0.013222f, 0.015175f, 0.017212f, 0.019592f, 0.021835f, 0.024048f, 0.026932f, 0.029846f, 0.032623f,
+ 0.035675f, 0.038940f, 0.042542f, 0.046295f, 0.050354f, 0.055054f, 0.059601f, 0.064880f, 0.070190f, 0.076233f, 0.082703f, 0.089661f,
+ 0.097229f, 0.105103f, 0.113831f, 0.123474f, 0.133423f, 0.144409f, 0.156006f, 0.168335f, 0.182495f, 0.196411f, 0.211304f, 0.227295f,
+ 0.243530f, 0.260986f, 0.279053f, 0.298828f, 0.318359f, 0.339111f, 0.360107f, 0.381348f, 0.403809f, 0.427490f, 0.449463f, 0.473633f,
+ 0.497803f, 0.521484f, 0.546875f, 0.570801f, 0.595703f, 0.620605f, 0.833008f, 0.845215f, 0.845703f, 0.845703f, 0.845215f, 0.843750f,
+ 0.000719f, 0.002470f, 0.003975f, 0.005337f, 0.007275f, 0.008713f, 0.010376f, 0.012032f, 0.013580f, 0.015793f, 0.017609f, 0.019501f,
+ 0.021530f, 0.024277f, 0.026657f, 0.029312f, 0.031982f, 0.035187f, 0.038086f, 0.041565f, 0.045288f, 0.049103f, 0.053436f, 0.058136f,
+ 0.062927f, 0.068054f, 0.073853f, 0.080383f, 0.087341f, 0.094666f, 0.102173f, 0.111084f, 0.120300f, 0.130859f, 0.141235f, 0.152954f,
+ 0.164429f, 0.178223f, 0.192749f, 0.207642f, 0.223145f, 0.239868f, 0.258301f, 0.276611f, 0.295654f, 0.316162f, 0.337402f, 0.358643f,
+ 0.380859f, 0.403320f, 0.427002f, 0.450684f, 0.474609f, 0.499756f, 0.523926f, 0.550781f, 0.575195f, 0.600586f, 0.824707f, 0.836914f,
+ 0.838379f, 0.838867f, 0.837402f, 0.837402f, 0.000683f, 0.002361f, 0.003649f, 0.005116f, 0.006416f, 0.008202f, 0.009460f, 0.010941f,
+ 0.012817f, 0.014099f, 0.015839f, 0.017593f, 0.019867f, 0.021988f, 0.023926f, 0.026276f, 0.028824f, 0.031311f, 0.034363f, 0.036957f,
+ 0.040375f, 0.043823f, 0.047546f, 0.051758f, 0.056183f, 0.061249f, 0.066162f, 0.071777f, 0.077942f, 0.084534f, 0.091553f, 0.099487f,
+ 0.107910f, 0.116882f, 0.127075f, 0.137451f, 0.148804f, 0.161499f, 0.174805f, 0.188721f, 0.203735f, 0.220093f, 0.237427f, 0.254639f,
+ 0.273926f, 0.293457f, 0.313965f, 0.334961f, 0.357666f, 0.379883f, 0.403076f, 0.427002f, 0.451660f, 0.476807f, 0.501953f, 0.527344f,
+ 0.553711f, 0.581055f, 0.815918f, 0.829102f, 0.831055f, 0.831055f, 0.831055f, 0.830566f, 0.000607f, 0.001863f, 0.003416f, 0.004528f,
+ 0.005943f, 0.007191f, 0.008781f, 0.009964f, 0.011337f, 0.012939f, 0.014458f, 0.015808f, 0.018051f, 0.019394f, 0.021332f, 0.023529f,
+ 0.025803f, 0.028168f, 0.030502f, 0.033020f, 0.036072f, 0.039032f, 0.042419f, 0.046082f, 0.049927f, 0.054321f, 0.058411f, 0.063538f,
+ 0.069336f, 0.075684f, 0.081787f, 0.088562f, 0.096436f, 0.104553f, 0.113281f, 0.123596f, 0.133667f, 0.145386f, 0.157471f, 0.171021f,
+ 0.185547f, 0.200562f, 0.216553f, 0.234619f, 0.251709f, 0.271240f, 0.291504f, 0.312012f, 0.333496f, 0.355957f, 0.379395f, 0.403076f,
+ 0.428223f, 0.453857f, 0.479492f, 0.506348f, 0.532715f, 0.560059f, 0.805664f, 0.820801f, 0.823730f, 0.822754f, 0.822754f, 0.822266f,
+ 0.000593f, 0.001862f, 0.002966f, 0.004341f, 0.005600f, 0.006516f, 0.007626f, 0.008995f, 0.010223f, 0.011292f, 0.012848f, 0.014427f,
+ 0.016098f, 0.017532f, 0.019165f, 0.021027f, 0.022842f, 0.024918f, 0.027115f, 0.029739f, 0.032013f, 0.034637f, 0.037506f, 0.040955f,
+ 0.044220f, 0.048065f, 0.051941f, 0.056305f, 0.061768f, 0.066528f, 0.072327f, 0.078979f, 0.085571f, 0.092834f, 0.101135f, 0.110229f,
+ 0.119690f, 0.130127f, 0.141602f, 0.153564f, 0.167114f, 0.181763f, 0.196899f, 0.213623f, 0.230957f, 0.249268f, 0.268555f, 0.289062f,
+ 0.310059f, 0.333252f, 0.355957f, 0.379883f, 0.404541f, 0.430176f, 0.456055f, 0.483887f, 0.510254f, 0.539062f, 0.797852f, 0.812988f,
+ 0.814941f, 0.815430f, 0.815918f, 0.814453f, 0.000556f, 0.001811f, 0.002998f, 0.003815f, 0.004658f, 0.005905f, 0.007099f, 0.008232f,
+ 0.009239f, 0.010483f, 0.011559f, 0.013016f, 0.014305f, 0.015671f, 0.017090f, 0.018646f, 0.020370f, 0.022369f, 0.024124f, 0.026062f,
+ 0.028458f, 0.030624f, 0.033264f, 0.036041f, 0.039307f, 0.042053f, 0.045807f, 0.049530f, 0.054016f, 0.058441f, 0.063904f, 0.069641f,
+ 0.075745f, 0.082520f, 0.089539f, 0.097717f, 0.106750f, 0.116150f, 0.126587f, 0.137817f, 0.150024f, 0.163452f, 0.177490f, 0.193359f,
+ 0.209717f, 0.227539f, 0.246704f, 0.266602f, 0.287598f, 0.309326f, 0.332520f, 0.355713f, 0.380371f, 0.406494f, 0.432861f, 0.459961f,
+ 0.488525f, 0.517090f, 0.787598f, 0.804199f, 0.806641f, 0.807617f, 0.807617f, 0.807129f, 0.000507f, 0.001697f, 0.002468f, 0.003351f,
+ 0.004425f, 0.005486f, 0.006325f, 0.007412f, 0.008156f, 0.009270f, 0.010239f, 0.011497f, 0.012520f, 0.013954f, 0.015182f, 0.016617f,
+ 0.018036f, 0.019714f, 0.021362f, 0.022934f, 0.024704f, 0.026886f, 0.029419f, 0.031525f, 0.034302f, 0.037292f, 0.040558f, 0.043701f,
+ 0.047577f, 0.051849f, 0.056183f, 0.061249f, 0.066467f, 0.072876f, 0.078918f, 0.086548f, 0.094116f, 0.102844f, 0.112427f, 0.122620f,
+ 0.133667f, 0.146362f, 0.159668f, 0.174438f, 0.190063f, 0.207153f, 0.225098f, 0.244263f, 0.264648f, 0.286377f, 0.308350f, 0.332275f,
+ 0.357178f, 0.382080f, 0.408936f, 0.436035f, 0.465820f, 0.495361f, 0.776855f, 0.794922f, 0.797852f, 0.799316f, 0.798828f, 0.798340f,
+ 0.000366f, 0.001644f, 0.002289f, 0.003046f, 0.004082f, 0.005032f, 0.005550f, 0.006599f, 0.007389f, 0.008369f, 0.009201f, 0.010315f,
+ 0.011276f, 0.012405f, 0.013466f, 0.014587f, 0.015991f, 0.017303f, 0.018692f, 0.020081f, 0.021851f, 0.023865f, 0.025726f, 0.027771f,
+ 0.030136f, 0.032532f, 0.035309f, 0.038422f, 0.041626f, 0.045044f, 0.048767f, 0.053375f, 0.057861f, 0.063477f, 0.069031f, 0.075684f,
+ 0.082336f, 0.090515f, 0.099182f, 0.107849f, 0.118958f, 0.130005f, 0.142212f, 0.156128f, 0.170898f, 0.186890f, 0.203857f, 0.222534f,
+ 0.241821f, 0.263428f, 0.285156f, 0.308105f, 0.332275f, 0.359131f, 0.385010f, 0.413086f, 0.441895f, 0.472168f, 0.767090f, 0.785645f,
+ 0.789062f, 0.789551f, 0.790527f, 0.789551f, 0.000340f, 0.001434f, 0.002129f, 0.002827f, 0.003696f, 0.004463f, 0.005112f, 0.005730f,
+ 0.006836f, 0.007465f, 0.008217f, 0.008972f, 0.009972f, 0.010887f, 0.011948f, 0.012794f, 0.013947f, 0.015030f, 0.016266f, 0.017670f,
+ 0.019165f, 0.020813f, 0.022415f, 0.024216f, 0.026047f, 0.028336f, 0.030594f, 0.033142f, 0.035858f, 0.039154f, 0.042328f, 0.046265f,
+ 0.050537f, 0.055237f, 0.059998f, 0.065918f, 0.072083f, 0.078918f, 0.086243f, 0.094788f, 0.104309f, 0.114807f, 0.125854f, 0.138672f,
+ 0.152222f, 0.166992f, 0.183716f, 0.200928f, 0.220459f, 0.240112f, 0.261719f, 0.284668f, 0.308838f, 0.333740f, 0.360840f, 0.388672f,
+ 0.418213f, 0.448730f, 0.756348f, 0.775391f, 0.779297f, 0.780273f, 0.781250f, 0.780273f, 0.000511f, 0.001174f, 0.002163f, 0.002554f,
+ 0.003391f, 0.003990f, 0.004547f, 0.005211f, 0.005993f, 0.006653f, 0.007462f, 0.007942f, 0.008781f, 0.009476f, 0.010323f, 0.011444f,
+ 0.012207f, 0.013062f, 0.014336f, 0.015427f, 0.016464f, 0.017929f, 0.019287f, 0.021164f, 0.022461f, 0.024567f, 0.026474f, 0.028885f,
+ 0.031067f, 0.033630f, 0.036835f, 0.040070f, 0.043488f, 0.047394f, 0.051910f, 0.056732f, 0.062378f, 0.068481f, 0.075073f, 0.082764f,
+ 0.090881f, 0.100403f, 0.110779f, 0.122009f, 0.134399f, 0.148560f, 0.163940f, 0.180298f, 0.198120f, 0.218140f, 0.239014f, 0.260986f,
+ 0.285645f, 0.310059f, 0.336182f, 0.364502f, 0.393311f, 0.424316f, 0.744629f, 0.765137f, 0.769531f, 0.770508f, 0.771484f, 0.771484f,
+ 0.000374f, 0.000983f, 0.001696f, 0.002279f, 0.002924f, 0.003571f, 0.004139f, 0.004742f, 0.005390f, 0.005817f, 0.006371f, 0.006981f,
+ 0.007648f, 0.008354f, 0.009041f, 0.009727f, 0.010536f, 0.011375f, 0.012398f, 0.013535f, 0.014389f, 0.015541f, 0.016602f, 0.018112f,
+ 0.019516f, 0.020996f, 0.022644f, 0.024582f, 0.026627f, 0.028748f, 0.031586f, 0.034210f, 0.037415f, 0.040588f, 0.044464f, 0.048676f,
+ 0.053192f, 0.058472f, 0.064880f, 0.070984f, 0.078674f, 0.086914f, 0.096191f, 0.106445f, 0.117859f, 0.130859f, 0.144775f, 0.160522f,
+ 0.177490f, 0.196411f, 0.215942f, 0.237793f, 0.261475f, 0.285645f, 0.312012f, 0.339111f, 0.368652f, 0.400391f, 0.733887f, 0.755371f,
+ 0.759766f, 0.760742f, 0.761719f, 0.761719f, 0.000298f, 0.000924f, 0.001542f, 0.002125f, 0.002439f, 0.003153f, 0.003502f, 0.004196f,
+ 0.004585f, 0.005039f, 0.005531f, 0.006054f, 0.006531f, 0.007217f, 0.007935f, 0.008362f, 0.009171f, 0.009773f, 0.010704f, 0.011505f,
+ 0.012207f, 0.013321f, 0.014381f, 0.015556f, 0.016586f, 0.017792f, 0.019608f, 0.020844f, 0.022583f, 0.024536f, 0.026566f, 0.028885f,
+ 0.031494f, 0.034332f, 0.037689f, 0.041260f, 0.045258f, 0.049927f, 0.054901f, 0.060699f, 0.067322f, 0.074768f, 0.082764f, 0.091675f,
+ 0.102173f, 0.113831f, 0.126831f, 0.141113f, 0.157104f, 0.175049f, 0.194580f, 0.215210f, 0.237305f, 0.261475f, 0.287598f, 0.314697f,
+ 0.344482f, 0.375977f, 0.721680f, 0.744629f, 0.749512f, 0.751465f, 0.751465f, 0.751465f, 0.000275f, 0.001002f, 0.001335f, 0.001704f,
+ 0.002264f, 0.002790f, 0.003202f, 0.003555f, 0.004017f, 0.004368f, 0.004894f, 0.005318f, 0.005592f, 0.006241f, 0.006611f, 0.007317f,
+ 0.007851f, 0.008560f, 0.009071f, 0.009758f, 0.010429f, 0.011375f, 0.011986f, 0.013130f, 0.013916f, 0.015205f, 0.016403f, 0.017624f,
+ 0.019119f, 0.020660f, 0.022278f, 0.024582f, 0.026474f, 0.029007f, 0.031738f, 0.034668f, 0.038025f, 0.041962f, 0.046417f, 0.051270f,
+ 0.056915f, 0.063110f, 0.070312f, 0.078369f, 0.087769f, 0.098145f, 0.109863f, 0.123352f, 0.137451f, 0.154785f, 0.172363f, 0.192261f,
+ 0.214233f, 0.237793f, 0.262939f, 0.289795f, 0.319336f, 0.351074f, 0.708984f, 0.733398f, 0.738281f, 0.740234f, 0.741211f, 0.740723f,
+ 0.000334f, 0.000805f, 0.001231f, 0.001640f, 0.002033f, 0.002277f, 0.002871f, 0.003115f, 0.003481f, 0.003895f, 0.004147f, 0.004379f,
+ 0.004841f, 0.005306f, 0.005653f, 0.006241f, 0.006630f, 0.007217f, 0.007721f, 0.008133f, 0.008842f, 0.009529f, 0.010010f, 0.011017f,
+ 0.011780f, 0.012733f, 0.013626f, 0.014824f, 0.015656f, 0.017212f, 0.018829f, 0.020248f, 0.021973f, 0.023926f, 0.026306f, 0.028900f,
+ 0.031616f, 0.034973f, 0.038605f, 0.042816f, 0.047424f, 0.052765f, 0.059021f, 0.066162f, 0.074219f, 0.083435f, 0.093994f, 0.105835f,
+ 0.119385f, 0.134277f, 0.151611f, 0.170532f, 0.191284f, 0.214233f, 0.239014f, 0.265381f, 0.293701f, 0.325684f, 0.696289f, 0.722168f,
+ 0.727051f, 0.729004f, 0.729980f, 0.729980f, 0.000215f, 0.000635f, 0.001184f, 0.001348f, 0.001758f, 0.002171f, 0.002249f, 0.002596f,
+ 0.003004f, 0.003325f, 0.003487f, 0.003906f, 0.004108f, 0.004494f, 0.004955f, 0.005241f, 0.005726f, 0.006134f, 0.006485f, 0.006916f,
+ 0.007496f, 0.008072f, 0.008629f, 0.009071f, 0.009857f, 0.010651f, 0.011375f, 0.012283f, 0.013283f, 0.014320f, 0.015350f, 0.016739f,
+ 0.017975f, 0.019852f, 0.021454f, 0.023712f, 0.025925f, 0.028717f, 0.031769f, 0.035217f, 0.038910f, 0.043396f, 0.048767f, 0.054901f,
+ 0.061707f, 0.069824f, 0.078613f, 0.089783f, 0.101685f, 0.115479f, 0.131104f, 0.149292f, 0.168823f, 0.190674f, 0.214844f, 0.241211f,
+ 0.269775f, 0.299561f, 0.683594f, 0.709961f, 0.715332f, 0.717773f, 0.718262f, 0.718750f, 0.000199f, 0.000826f, 0.001047f, 0.001288f,
+ 0.001600f, 0.001857f, 0.002014f, 0.002329f, 0.002535f, 0.002785f, 0.003027f, 0.003210f, 0.003580f, 0.003788f, 0.004025f, 0.004444f,
+ 0.004791f, 0.004974f, 0.005417f, 0.005909f, 0.006248f, 0.006672f, 0.007118f, 0.007664f, 0.008232f, 0.008759f, 0.009598f, 0.009964f,
+ 0.010956f, 0.011650f, 0.012665f, 0.013702f, 0.014832f, 0.016144f, 0.017654f, 0.019211f, 0.021118f, 0.023102f, 0.025681f, 0.028320f,
+ 0.031708f, 0.035370f, 0.039673f, 0.044739f, 0.050812f, 0.057800f, 0.065796f, 0.074768f, 0.085510f, 0.097961f, 0.112000f, 0.128662f,
+ 0.147217f, 0.168213f, 0.190796f, 0.216309f, 0.244751f, 0.274902f, 0.669922f, 0.698730f, 0.703613f, 0.705566f, 0.707031f, 0.707031f,
+ 0.000212f, 0.000458f, 0.000959f, 0.001192f, 0.001321f, 0.001500f, 0.001823f, 0.002064f, 0.002073f, 0.002293f, 0.002512f, 0.002768f,
+ 0.002981f, 0.003138f, 0.003431f, 0.003765f, 0.003918f, 0.004238f, 0.004482f, 0.004814f, 0.005245f, 0.005531f, 0.005871f, 0.006214f,
+ 0.006660f, 0.007236f, 0.007664f, 0.008331f, 0.008812f, 0.009628f, 0.010277f, 0.010979f, 0.012016f, 0.012978f, 0.014084f, 0.015495f,
+ 0.016937f, 0.018494f, 0.020386f, 0.022659f, 0.025208f, 0.028183f, 0.031860f, 0.036072f, 0.040894f, 0.046326f, 0.053009f, 0.061127f,
+ 0.070374f, 0.081238f, 0.094238f, 0.109314f, 0.126343f, 0.145874f, 0.167847f, 0.192505f, 0.219604f, 0.249634f, 0.656738f, 0.686035f,
+ 0.690430f, 0.694336f, 0.694336f, 0.696777f, 0.000151f, 0.000529f, 0.000692f, 0.000883f, 0.001153f, 0.001337f, 0.001380f, 0.001520f,
+ 0.001753f, 0.001886f, 0.002077f, 0.002243f, 0.002386f, 0.002556f, 0.002832f, 0.003029f, 0.003277f, 0.003447f, 0.003683f, 0.003952f,
+ 0.004135f, 0.004578f, 0.004833f, 0.005222f, 0.005417f, 0.005810f, 0.006355f, 0.006718f, 0.007076f, 0.007652f, 0.008293f, 0.008980f,
+ 0.009674f, 0.010422f, 0.011276f, 0.012283f, 0.013443f, 0.014664f, 0.016113f, 0.017853f, 0.019897f, 0.022156f, 0.024826f, 0.028275f,
+ 0.032135f, 0.036865f, 0.042389f, 0.049011f, 0.056732f, 0.066223f, 0.077576f, 0.090820f, 0.106384f, 0.124512f, 0.145264f, 0.169067f,
+ 0.195190f, 0.224976f, 0.642578f, 0.671387f, 0.679688f, 0.682617f, 0.682617f, 0.683594f, 0.000127f, 0.000376f, 0.000600f, 0.000721f,
+ 0.000901f, 0.001066f, 0.001180f, 0.001332f, 0.001455f, 0.001549f, 0.001709f, 0.001831f, 0.001947f, 0.002150f, 0.002245f, 0.002443f,
+ 0.002682f, 0.002844f, 0.002989f, 0.003201f, 0.003403f, 0.003683f, 0.003883f, 0.004097f, 0.004372f, 0.004665f, 0.004963f, 0.005348f,
+ 0.005711f, 0.006165f, 0.006672f, 0.007004f, 0.007610f, 0.008278f, 0.008873f, 0.009636f, 0.010475f, 0.011475f, 0.012634f, 0.014053f,
+ 0.015404f, 0.017242f, 0.019104f, 0.021774f, 0.024750f, 0.028458f, 0.032745f, 0.038391f, 0.044861f, 0.052795f, 0.062103f, 0.073914f,
+ 0.087830f, 0.104553f, 0.123718f, 0.145996f, 0.171509f, 0.200439f, 0.627930f, 0.658691f, 0.666504f, 0.668945f, 0.671387f, 0.671387f,
+ 0.000013f, 0.000374f, 0.000443f, 0.000688f, 0.000819f, 0.000844f, 0.001004f, 0.001132f, 0.001216f, 0.001259f, 0.001405f, 0.001523f,
+ 0.001566f, 0.001753f, 0.001842f, 0.001997f, 0.002022f, 0.002287f, 0.002377f, 0.002541f, 0.002787f, 0.002878f, 0.003096f, 0.003283f,
+ 0.003551f, 0.003651f, 0.003971f, 0.004272f, 0.004524f, 0.004887f, 0.005196f, 0.005527f, 0.005939f, 0.006386f, 0.006977f, 0.007526f,
+ 0.008148f, 0.008835f, 0.009689f, 0.010689f, 0.011810f, 0.013000f, 0.014641f, 0.016388f, 0.018799f, 0.021469f, 0.024734f, 0.029022f,
+ 0.034210f, 0.040588f, 0.048401f, 0.058319f, 0.070435f, 0.085205f, 0.102905f, 0.123901f, 0.147827f, 0.175903f, 0.612793f, 0.645508f,
+ 0.653320f, 0.656250f, 0.657227f, 0.657227f, 0.000113f, 0.000234f, 0.000465f, 0.000547f, 0.000646f, 0.000684f, 0.000711f, 0.000832f,
+ 0.000963f, 0.000999f, 0.001042f, 0.001183f, 0.001279f, 0.001402f, 0.001494f, 0.001513f, 0.001688f, 0.001716f, 0.001919f, 0.001993f,
+ 0.002081f, 0.002253f, 0.002441f, 0.002575f, 0.002714f, 0.002876f, 0.003050f, 0.003214f, 0.003531f, 0.003714f, 0.003956f, 0.004276f,
+ 0.004604f, 0.004967f, 0.005386f, 0.005718f, 0.006283f, 0.006790f, 0.007290f, 0.008133f, 0.008957f, 0.009987f, 0.010956f, 0.012375f,
+ 0.013916f, 0.015991f, 0.018311f, 0.021347f, 0.025253f, 0.030289f, 0.036560f, 0.044586f, 0.054779f, 0.067749f, 0.083252f, 0.102722f,
+ 0.125732f, 0.152100f, 0.597168f, 0.631836f, 0.639160f, 0.643555f, 0.643066f, 0.645508f, 0.000207f, 0.000175f, 0.000364f, 0.000507f,
+ 0.000496f, 0.000569f, 0.000683f, 0.000584f, 0.000737f, 0.000764f, 0.000885f, 0.000964f, 0.000999f, 0.001076f, 0.001085f, 0.001272f,
+ 0.001327f, 0.001354f, 0.001491f, 0.001494f, 0.001677f, 0.001781f, 0.001862f, 0.001976f, 0.002079f, 0.002190f, 0.002338f, 0.002481f,
+ 0.002691f, 0.002811f, 0.003117f, 0.003214f, 0.003422f, 0.003706f, 0.003990f, 0.004314f, 0.004608f, 0.004982f, 0.005379f, 0.006027f,
+ 0.006580f, 0.007351f, 0.008049f, 0.009041f, 0.010323f, 0.011551f, 0.013428f, 0.015419f, 0.018219f, 0.021713f, 0.026550f, 0.032715f,
+ 0.040833f, 0.051605f, 0.065552f, 0.082458f, 0.104004f, 0.129395f, 0.582031f, 0.618652f, 0.625488f, 0.627930f, 0.630859f, 0.631348f,
+ 0.000189f, 0.000160f, 0.000272f, 0.000387f, 0.000335f, 0.000486f, 0.000424f, 0.000469f, 0.000551f, 0.000589f, 0.000700f, 0.000727f,
+ 0.000772f, 0.000859f, 0.000891f, 0.000872f, 0.001000f, 0.001048f, 0.001076f, 0.001172f, 0.001224f, 0.001311f, 0.001376f, 0.001450f,
+ 0.001554f, 0.001591f, 0.001760f, 0.001838f, 0.001999f, 0.002180f, 0.002333f, 0.002388f, 0.002584f, 0.002777f, 0.002907f, 0.003162f,
+ 0.003368f, 0.003677f, 0.003979f, 0.004303f, 0.004715f, 0.005188f, 0.005787f, 0.006378f, 0.007313f, 0.008194f, 0.009407f, 0.010887f,
+ 0.012779f, 0.015198f, 0.018494f, 0.022888f, 0.029037f, 0.037659f, 0.048920f, 0.064270f, 0.083740f, 0.107300f, 0.565918f, 0.603516f,
+ 0.611328f, 0.614746f, 0.617188f, 0.618164f, 0.000000f, 0.000170f, 0.000207f, 0.000274f, 0.000292f, 0.000309f, 0.000381f, 0.000326f,
+ 0.000418f, 0.000439f, 0.000519f, 0.000519f, 0.000560f, 0.000574f, 0.000652f, 0.000678f, 0.000717f, 0.000756f, 0.000782f, 0.000820f,
+ 0.000893f, 0.000937f, 0.000991f, 0.001063f, 0.001112f, 0.001174f, 0.001284f, 0.001302f, 0.001408f, 0.001460f, 0.001586f, 0.001711f,
+ 0.001826f, 0.001959f, 0.002058f, 0.002207f, 0.002388f, 0.002565f, 0.002836f, 0.003046f, 0.003284f, 0.003567f, 0.004009f, 0.004463f,
+ 0.005001f, 0.005661f, 0.006451f, 0.007473f, 0.008751f, 0.010368f, 0.012611f, 0.015587f, 0.019730f, 0.025787f, 0.034729f, 0.047272f,
+ 0.064392f, 0.087097f, 0.550293f, 0.587891f, 0.596680f, 0.600586f, 0.602539f, 0.603516f, 0.000000f, 0.000057f, 0.000175f, 0.000210f,
+ 0.000221f, 0.000261f, 0.000224f, 0.000285f, 0.000296f, 0.000329f, 0.000374f, 0.000329f, 0.000344f, 0.000416f, 0.000421f, 0.000479f,
+ 0.000455f, 0.000530f, 0.000552f, 0.000598f, 0.000640f, 0.000670f, 0.000695f, 0.000740f, 0.000798f, 0.000806f, 0.000883f, 0.000908f,
+ 0.000983f, 0.001094f, 0.001083f, 0.001169f, 0.001242f, 0.001340f, 0.001440f, 0.001536f, 0.001601f, 0.001752f, 0.001893f, 0.002029f,
+ 0.002218f, 0.002424f, 0.002651f, 0.002934f, 0.003294f, 0.003681f, 0.004200f, 0.004833f, 0.005688f, 0.006863f, 0.008202f, 0.010178f,
+ 0.012955f, 0.016846f, 0.023163f, 0.032745f, 0.047150f, 0.067383f, 0.534180f, 0.574219f, 0.582031f, 0.584961f, 0.586914f, 0.589844f,
+ 0.000000f, 0.000105f, 0.000145f, 0.000101f, 0.000161f, 0.000163f, 0.000165f, 0.000193f, 0.000190f, 0.000202f, 0.000205f, 0.000260f,
+ 0.000251f, 0.000281f, 0.000305f, 0.000316f, 0.000323f, 0.000346f, 0.000364f, 0.000383f, 0.000413f, 0.000436f, 0.000461f, 0.000486f,
+ 0.000515f, 0.000564f, 0.000594f, 0.000616f, 0.000639f, 0.000677f, 0.000729f, 0.000748f, 0.000842f, 0.000861f, 0.000943f, 0.000970f,
+ 0.001054f, 0.001120f, 0.001219f, 0.001310f, 0.001398f, 0.001534f, 0.001709f, 0.001852f, 0.002096f, 0.002291f, 0.002594f, 0.002987f,
+ 0.003481f, 0.004128f, 0.004997f, 0.006218f, 0.007950f, 0.010445f, 0.014313f, 0.020874f, 0.032166f, 0.049866f, 0.517578f, 0.558105f,
+ 0.567383f, 0.570801f, 0.573730f, 0.574707f, 0.000000f, 0.000097f, 0.000089f, 0.000082f, 0.000092f, 0.000096f, 0.000092f, 0.000118f,
+ 0.000126f, 0.000130f, 0.000138f, 0.000138f, 0.000143f, 0.000163f, 0.000181f, 0.000187f, 0.000195f, 0.000228f, 0.000221f, 0.000261f,
+ 0.000243f, 0.000254f, 0.000274f, 0.000299f, 0.000334f, 0.000332f, 0.000345f, 0.000362f, 0.000394f, 0.000410f, 0.000433f, 0.000463f,
+ 0.000497f, 0.000510f, 0.000562f, 0.000594f, 0.000636f, 0.000670f, 0.000731f, 0.000777f, 0.000832f, 0.000927f, 0.000991f, 0.001101f,
+ 0.001210f, 0.001350f, 0.001513f, 0.001720f, 0.001999f, 0.002373f, 0.002815f, 0.003498f, 0.004478f, 0.006001f, 0.008347f, 0.012299f,
+ 0.019669f, 0.034210f, 0.501465f, 0.542969f, 0.552246f, 0.556641f, 0.559082f, 0.559570f, 0.000107f, 0.000087f, 0.000077f, 0.000070f,
+ 0.000065f, 0.000066f, 0.000059f, 0.000064f, 0.000065f, 0.000071f, 0.000070f, 0.000095f, 0.000081f, 0.000085f, 0.000110f, 0.000097f,
+ 0.000117f, 0.000126f, 0.000127f, 0.000133f, 0.000132f, 0.000141f, 0.000169f, 0.000173f, 0.000185f, 0.000183f, 0.000192f, 0.000215f,
+ 0.000216f, 0.000235f, 0.000236f, 0.000265f, 0.000278f, 0.000290f, 0.000313f, 0.000317f, 0.000347f, 0.000365f, 0.000400f, 0.000422f,
+ 0.000457f, 0.000494f, 0.000535f, 0.000586f, 0.000639f, 0.000700f, 0.000786f, 0.000888f, 0.001019f, 0.001207f, 0.001435f, 0.001746f,
+ 0.002258f, 0.003019f, 0.004299f, 0.006523f, 0.010612f, 0.020859f, 0.484619f, 0.527344f, 0.536621f, 0.541504f, 0.542969f, 0.544922f,
+ 0.000092f, 0.000070f, 0.000062f, 0.000056f, 0.000051f, 0.000048f, 0.000045f, 0.000044f, 0.000041f, 0.000039f, 0.000038f, 0.000037f,
+ 0.000047f, 0.000039f, 0.000041f, 0.000041f, 0.000058f, 0.000053f, 0.000062f, 0.000064f, 0.000068f, 0.000072f, 0.000076f, 0.000076f,
+ 0.000078f, 0.000092f, 0.000085f, 0.000101f, 0.000104f, 0.000110f, 0.000115f, 0.000118f, 0.000127f, 0.000133f, 0.000152f, 0.000150f,
+ 0.000163f, 0.000190f, 0.000190f, 0.000202f, 0.000213f, 0.000225f, 0.000249f, 0.000268f, 0.000296f, 0.000321f, 0.000354f, 0.000402f,
+ 0.000458f, 0.000520f, 0.000618f, 0.000744f, 0.000950f, 0.001263f, 0.001822f, 0.002865f, 0.005028f, 0.010544f, 0.468018f, 0.511230f,
+ 0.521484f, 0.524902f, 0.529297f, 0.529785f, 0.000067f, 0.000049f, 0.000041f, 0.000037f, 0.000034f, 0.000032f, 0.000031f, 0.000029f,
+ 0.000028f, 0.000027f, 0.000027f, 0.000026f, 0.000025f, 0.000023f, 0.000022f, 0.000021f, 0.000020f, 0.000020f, 0.000023f, 0.000024f,
+ 0.000021f, 0.000022f, 0.000025f, 0.000029f, 0.000030f, 0.000034f, 0.000036f, 0.000034f, 0.000039f, 0.000038f, 0.000045f, 0.000045f,
+ 0.000048f, 0.000051f, 0.000053f, 0.000055f, 0.000063f, 0.000070f, 0.000073f, 0.000073f, 0.000080f, 0.000084f, 0.000089f, 0.000102f,
+ 0.000107f, 0.000115f, 0.000128f, 0.000145f, 0.000156f, 0.000178f, 0.000213f, 0.000253f, 0.000311f, 0.000400f, 0.000572f, 0.000916f,
+ 0.001751f, 0.004158f, 0.450439f, 0.496338f, 0.505859f, 0.510742f, 0.513184f, 0.514648f, 0.000016f, 0.000013f, 0.000011f, 0.000010f,
+ 0.000012f, 0.000012f, 0.000011f, 0.000012f, 0.000011f, 0.000012f, 0.000011f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000011f,
+ 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000008f,
+ 0.000008f, 0.000009f, 0.000009f, 0.000009f, 0.000009f, 0.000011f, 0.000012f, 0.000012f, 0.000015f, 0.000014f, 0.000014f, 0.000017f,
+ 0.000018f, 0.000020f, 0.000020f, 0.000022f, 0.000026f, 0.000027f, 0.000028f, 0.000027f, 0.000033f, 0.000036f, 0.000044f, 0.000051f,
+ 0.000057f, 0.000078f, 0.000103f, 0.000159f, 0.000315f, 0.000997f, 0.433350f, 0.479980f, 0.490234f, 0.495605f, 0.498291f, 0.499512f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000004f, 0.000004f, 0.000007f, 0.000025f, 0.416016f, 0.464111f,
+ 0.474854f, 0.479248f, 0.481934f, 0.484375f,
+ },
+ {
+ 0.023209f, 0.069336f, 0.113037f, 0.154663f, 0.193726f, 0.231812f, 0.267578f, 0.301758f, 0.333740f, 0.364258f, 0.393555f, 0.421631f,
+ 0.447510f, 0.473145f, 0.497070f, 0.520020f, 0.541992f, 0.562988f, 0.583008f, 0.602539f, 0.620605f, 0.638184f, 0.655762f, 0.671387f,
+ 0.687500f, 0.702637f, 0.716309f, 0.729980f, 0.744141f, 0.757812f, 0.769531f, 0.782227f, 0.793945f, 0.804688f, 0.815918f, 0.826172f,
+ 0.836426f, 0.846191f, 0.855957f, 0.865234f, 0.874023f, 0.882812f, 0.891113f, 0.898926f, 0.907227f, 0.915039f, 0.922852f, 0.929688f,
+ 0.937012f, 0.943848f, 0.950684f, 0.956543f, 0.963379f, 0.969238f, 0.976074f, 0.981445f, 0.986816f, 0.992676f, 0.991211f, 0.978516f,
+ 0.968750f, 0.960449f, 0.952637f, 0.945312f, 0.019730f, 0.059631f, 0.098206f, 0.135864f, 0.172119f, 0.206421f, 0.239624f, 0.272461f,
+ 0.304932f, 0.333984f, 0.362549f, 0.389648f, 0.416016f, 0.441406f, 0.466309f, 0.489502f, 0.511230f, 0.533203f, 0.554199f, 0.573242f,
+ 0.593262f, 0.611816f, 0.629395f, 0.645508f, 0.662598f, 0.678711f, 0.693359f, 0.708496f, 0.722168f, 0.735840f, 0.750000f, 0.762207f,
+ 0.773926f, 0.786133f, 0.796875f, 0.808594f, 0.818848f, 0.829590f, 0.839355f, 0.850098f, 0.859863f, 0.868652f, 0.877441f, 0.886230f,
+ 0.895020f, 0.903809f, 0.911133f, 0.918457f, 0.925781f, 0.933105f, 0.940430f, 0.946777f, 0.954590f, 0.960938f, 0.966797f, 0.973145f,
+ 0.979004f, 0.984863f, 0.987793f, 0.976074f, 0.966797f, 0.958496f, 0.951172f, 0.943848f, 0.017151f, 0.051636f, 0.085510f, 0.119202f,
+ 0.152466f, 0.184814f, 0.216187f, 0.246582f, 0.276855f, 0.305664f, 0.332764f, 0.360107f, 0.385986f, 0.411621f, 0.435791f, 0.459473f,
+ 0.481445f, 0.502441f, 0.524414f, 0.546387f, 0.565430f, 0.583496f, 0.602051f, 0.619629f, 0.636719f, 0.653320f, 0.669434f, 0.684082f,
+ 0.699707f, 0.713867f, 0.728027f, 0.741211f, 0.754883f, 0.767090f, 0.779297f, 0.791016f, 0.802734f, 0.813965f, 0.824219f, 0.833984f,
+ 0.843750f, 0.854492f, 0.863281f, 0.873535f, 0.882324f, 0.890137f, 0.898926f, 0.906738f, 0.915039f, 0.922852f, 0.930176f, 0.937012f,
+ 0.944336f, 0.951172f, 0.958008f, 0.964844f, 0.970703f, 0.977051f, 0.983887f, 0.972656f, 0.964355f, 0.956543f, 0.949219f, 0.942383f,
+ 0.014885f, 0.044678f, 0.075195f, 0.104919f, 0.135254f, 0.165649f, 0.194702f, 0.223633f, 0.251221f, 0.279053f, 0.305420f, 0.331543f,
+ 0.357422f, 0.382568f, 0.406982f, 0.430420f, 0.453369f, 0.475586f, 0.496582f, 0.517090f, 0.536133f, 0.556641f, 0.575684f, 0.592773f,
+ 0.611328f, 0.628418f, 0.643555f, 0.661621f, 0.676270f, 0.691406f, 0.705566f, 0.720215f, 0.733887f, 0.746582f, 0.759766f, 0.772949f,
+ 0.784668f, 0.795898f, 0.807129f, 0.818359f, 0.828125f, 0.838867f, 0.848633f, 0.858887f, 0.867676f, 0.877441f, 0.886230f, 0.894531f,
+ 0.903320f, 0.911621f, 0.919434f, 0.927734f, 0.934570f, 0.940918f, 0.948730f, 0.956543f, 0.962402f, 0.969238f, 0.979980f, 0.970215f,
+ 0.961914f, 0.954102f, 0.947266f, 0.940918f, 0.013046f, 0.038940f, 0.066162f, 0.093323f, 0.120544f, 0.147583f, 0.174683f, 0.201538f,
+ 0.228516f, 0.254639f, 0.280518f, 0.304932f, 0.330566f, 0.354492f, 0.379395f, 0.402100f, 0.424561f, 0.446533f, 0.467529f, 0.488525f,
+ 0.509277f, 0.529297f, 0.547852f, 0.566895f, 0.585449f, 0.602539f, 0.620605f, 0.636230f, 0.653809f, 0.667480f, 0.684570f, 0.698242f,
+ 0.712891f, 0.726562f, 0.739746f, 0.753418f, 0.765625f, 0.777344f, 0.789551f, 0.801270f, 0.812500f, 0.823730f, 0.833984f, 0.844238f,
+ 0.854004f, 0.863770f, 0.874023f, 0.882324f, 0.891113f, 0.899902f, 0.908203f, 0.916504f, 0.924805f, 0.932129f, 0.939453f, 0.947266f,
+ 0.954102f, 0.960938f, 0.976562f, 0.967285f, 0.958984f, 0.951660f, 0.944824f, 0.938965f, 0.011696f, 0.034698f, 0.058807f, 0.083130f,
+ 0.107727f, 0.132324f, 0.156982f, 0.182251f, 0.207153f, 0.232178f, 0.256836f, 0.280762f, 0.304688f, 0.328369f, 0.352295f, 0.375244f,
+ 0.397461f, 0.419434f, 0.440430f, 0.461914f, 0.482178f, 0.501953f, 0.522461f, 0.540527f, 0.559570f, 0.577148f, 0.595703f, 0.613281f,
+ 0.628418f, 0.644531f, 0.661621f, 0.676270f, 0.691406f, 0.705078f, 0.719727f, 0.733887f, 0.746094f, 0.759766f, 0.771973f, 0.784180f,
+ 0.795898f, 0.807617f, 0.818359f, 0.829102f, 0.839844f, 0.850098f, 0.859375f, 0.869629f, 0.878906f, 0.887695f, 0.896484f, 0.905273f,
+ 0.914062f, 0.921875f, 0.929688f, 0.937988f, 0.944824f, 0.952637f, 0.973145f, 0.963379f, 0.956055f, 0.949219f, 0.942871f, 0.937012f,
+ 0.010094f, 0.030975f, 0.052063f, 0.073975f, 0.096069f, 0.118713f, 0.141479f, 0.164551f, 0.187866f, 0.211182f, 0.234985f, 0.258057f,
+ 0.280518f, 0.303467f, 0.326172f, 0.348145f, 0.370117f, 0.392822f, 0.413574f, 0.434814f, 0.455322f, 0.476074f, 0.495361f, 0.515137f,
+ 0.533203f, 0.551758f, 0.569824f, 0.586426f, 0.604492f, 0.621582f, 0.637695f, 0.654297f, 0.668945f, 0.683594f, 0.699219f, 0.712402f,
+ 0.728516f, 0.741699f, 0.753906f, 0.767090f, 0.778320f, 0.790527f, 0.802246f, 0.813965f, 0.824219f, 0.835449f, 0.846680f, 0.855957f,
+ 0.865723f, 0.875488f, 0.884766f, 0.894043f, 0.902832f, 0.911133f, 0.919434f, 0.927734f, 0.935547f, 0.943359f, 0.968750f, 0.960449f,
+ 0.953125f, 0.946289f, 0.940430f, 0.934570f, 0.008797f, 0.027466f, 0.045959f, 0.066223f, 0.086304f, 0.106506f, 0.127441f, 0.149170f,
+ 0.170532f, 0.192261f, 0.213867f, 0.236206f, 0.258057f, 0.280273f, 0.301758f, 0.323486f, 0.344727f, 0.367188f, 0.388184f, 0.408447f,
+ 0.429443f, 0.450439f, 0.469727f, 0.489014f, 0.508301f, 0.526855f, 0.545410f, 0.562500f, 0.581055f, 0.597656f, 0.613770f, 0.630859f,
+ 0.647461f, 0.663574f, 0.677734f, 0.693359f, 0.707031f, 0.720703f, 0.735352f, 0.748047f, 0.760254f, 0.772461f, 0.785156f, 0.797363f,
+ 0.810059f, 0.819824f, 0.831543f, 0.842285f, 0.852051f, 0.862793f, 0.873047f, 0.882324f, 0.891113f, 0.899902f, 0.909180f, 0.917969f,
+ 0.925781f, 0.934082f, 0.964355f, 0.957031f, 0.949707f, 0.943359f, 0.937988f, 0.932129f, 0.007927f, 0.024414f, 0.041077f, 0.059204f,
+ 0.077148f, 0.095581f, 0.115479f, 0.134644f, 0.154785f, 0.175293f, 0.196045f, 0.216553f, 0.236694f, 0.258057f, 0.278809f, 0.300049f,
+ 0.321289f, 0.342529f, 0.363281f, 0.383545f, 0.403564f, 0.424072f, 0.444092f, 0.463135f, 0.483154f, 0.501953f, 0.519531f, 0.539062f,
+ 0.555664f, 0.574707f, 0.591309f, 0.608398f, 0.624512f, 0.640137f, 0.655762f, 0.671875f, 0.686523f, 0.701172f, 0.715820f, 0.729004f,
+ 0.742676f, 0.755859f, 0.769043f, 0.781738f, 0.792969f, 0.805176f, 0.816895f, 0.827637f, 0.838867f, 0.849121f, 0.859375f, 0.870117f,
+ 0.879395f, 0.889160f, 0.898926f, 0.906738f, 0.916504f, 0.924805f, 0.960938f, 0.953125f, 0.947266f, 0.940430f, 0.935547f, 0.929688f,
+ 0.007080f, 0.022247f, 0.037445f, 0.053070f, 0.069336f, 0.086975f, 0.103577f, 0.121948f, 0.140503f, 0.158936f, 0.178833f, 0.198242f,
+ 0.217651f, 0.237793f, 0.257812f, 0.278076f, 0.297607f, 0.318604f, 0.338623f, 0.358643f, 0.378662f, 0.399170f, 0.418213f, 0.438721f,
+ 0.457520f, 0.477051f, 0.495361f, 0.513672f, 0.531250f, 0.549316f, 0.567383f, 0.583984f, 0.601562f, 0.617676f, 0.634277f, 0.650391f,
+ 0.666016f, 0.680176f, 0.695801f, 0.710449f, 0.723633f, 0.737305f, 0.750977f, 0.764648f, 0.776367f, 0.789551f, 0.802246f, 0.813477f,
+ 0.824219f, 0.835938f, 0.846680f, 0.857422f, 0.867188f, 0.876953f, 0.887207f, 0.895996f, 0.905762f, 0.915527f, 0.955566f, 0.949707f,
+ 0.943359f, 0.937988f, 0.932129f, 0.927246f, 0.006363f, 0.019516f, 0.033691f, 0.047577f, 0.062469f, 0.078186f, 0.093933f, 0.110657f,
+ 0.127563f, 0.144653f, 0.162598f, 0.181152f, 0.199707f, 0.218384f, 0.237427f, 0.257324f, 0.276367f, 0.295166f, 0.315674f, 0.335205f,
+ 0.355225f, 0.374756f, 0.393799f, 0.413574f, 0.432617f, 0.451904f, 0.470459f, 0.489258f, 0.508301f, 0.525879f, 0.543945f, 0.560059f,
+ 0.578613f, 0.595703f, 0.612793f, 0.628418f, 0.644531f, 0.659668f, 0.675293f, 0.689941f, 0.704590f, 0.719238f, 0.732910f, 0.747070f,
+ 0.759766f, 0.773438f, 0.785156f, 0.797852f, 0.809570f, 0.821289f, 0.833008f, 0.843750f, 0.854980f, 0.865723f, 0.875977f, 0.886230f,
+ 0.895508f, 0.904785f, 0.951660f, 0.945801f, 0.939941f, 0.934570f, 0.929199f, 0.924805f, 0.005985f, 0.017776f, 0.030212f, 0.043030f,
+ 0.056488f, 0.070190f, 0.085205f, 0.100342f, 0.115723f, 0.132446f, 0.148438f, 0.165771f, 0.183228f, 0.200684f, 0.218994f, 0.237183f,
+ 0.255859f, 0.274170f, 0.292725f, 0.313477f, 0.331299f, 0.351318f, 0.369873f, 0.389160f, 0.408936f, 0.426758f, 0.446533f, 0.464844f,
+ 0.483154f, 0.501465f, 0.519531f, 0.537598f, 0.555664f, 0.572754f, 0.589844f, 0.605957f, 0.622070f, 0.639648f, 0.654297f, 0.670898f,
+ 0.685059f, 0.700195f, 0.714844f, 0.728516f, 0.742188f, 0.754883f, 0.769043f, 0.781738f, 0.795410f, 0.808105f, 0.818359f, 0.830566f,
+ 0.841797f, 0.853027f, 0.863770f, 0.874023f, 0.884766f, 0.893555f, 0.947266f, 0.942383f, 0.936523f, 0.930664f, 0.926270f, 0.921387f,
+ 0.005173f, 0.016083f, 0.027359f, 0.038849f, 0.051056f, 0.063843f, 0.077026f, 0.091064f, 0.105591f, 0.120422f, 0.135498f, 0.150879f,
+ 0.167480f, 0.184326f, 0.201172f, 0.218384f, 0.236084f, 0.254395f, 0.272949f, 0.291260f, 0.309570f, 0.328125f, 0.346680f, 0.365967f,
+ 0.384766f, 0.403320f, 0.422119f, 0.440918f, 0.458984f, 0.477783f, 0.496094f, 0.513672f, 0.531738f, 0.548828f, 0.566406f, 0.583984f,
+ 0.600098f, 0.617188f, 0.632812f, 0.649902f, 0.665527f, 0.681152f, 0.694824f, 0.709473f, 0.724121f, 0.738770f, 0.752441f, 0.765137f,
+ 0.778809f, 0.791992f, 0.803711f, 0.815918f, 0.828125f, 0.839844f, 0.851562f, 0.862793f, 0.873535f, 0.883789f, 0.941895f, 0.938477f,
+ 0.933105f, 0.927246f, 0.922363f, 0.918457f, 0.004791f, 0.014610f, 0.024475f, 0.035126f, 0.046478f, 0.057922f, 0.069885f, 0.083008f,
+ 0.096069f, 0.109253f, 0.123840f, 0.137939f, 0.153076f, 0.168701f, 0.185059f, 0.200928f, 0.218262f, 0.234985f, 0.252686f, 0.270264f,
+ 0.288086f, 0.306396f, 0.324951f, 0.343018f, 0.362305f, 0.379883f, 0.398926f, 0.417236f, 0.435547f, 0.454346f, 0.472656f, 0.491211f,
+ 0.508301f, 0.526855f, 0.543457f, 0.561523f, 0.578125f, 0.595215f, 0.612305f, 0.628418f, 0.644043f, 0.660645f, 0.675781f, 0.691406f,
+ 0.706055f, 0.720215f, 0.735840f, 0.749023f, 0.762695f, 0.776855f, 0.789551f, 0.800781f, 0.814941f, 0.826172f, 0.838867f, 0.851074f,
+ 0.862305f, 0.872070f, 0.937500f, 0.933594f, 0.929199f, 0.923828f, 0.919434f, 0.915527f, 0.004387f, 0.013268f, 0.022385f, 0.031860f,
+ 0.041962f, 0.052612f, 0.063171f, 0.075073f, 0.086792f, 0.099854f, 0.113037f, 0.125977f, 0.140381f, 0.154663f, 0.169678f, 0.184814f,
+ 0.200562f, 0.217773f, 0.234131f, 0.250732f, 0.268066f, 0.284912f, 0.303223f, 0.321289f, 0.339355f, 0.357666f, 0.375488f, 0.394043f,
+ 0.411865f, 0.430664f, 0.448730f, 0.467041f, 0.485352f, 0.503418f, 0.520508f, 0.539062f, 0.556152f, 0.573242f, 0.590820f, 0.606934f,
+ 0.624512f, 0.640625f, 0.655762f, 0.672363f, 0.687500f, 0.702148f, 0.718750f, 0.731934f, 0.746582f, 0.759766f, 0.772949f, 0.787109f,
+ 0.800781f, 0.813477f, 0.825195f, 0.838379f, 0.850098f, 0.861816f, 0.932617f, 0.929688f, 0.925293f, 0.919922f, 0.915527f, 0.912109f,
+ 0.003941f, 0.011986f, 0.020630f, 0.029144f, 0.038544f, 0.048035f, 0.058075f, 0.068542f, 0.079590f, 0.090942f, 0.102661f, 0.115295f,
+ 0.128296f, 0.141602f, 0.155518f, 0.170654f, 0.185425f, 0.200684f, 0.216309f, 0.231812f, 0.249146f, 0.265137f, 0.282471f, 0.299072f,
+ 0.317139f, 0.334717f, 0.352783f, 0.371338f, 0.388916f, 0.406982f, 0.425537f, 0.443848f, 0.461914f, 0.479980f, 0.498291f, 0.515625f,
+ 0.533203f, 0.550293f, 0.568359f, 0.585449f, 0.603027f, 0.618652f, 0.635742f, 0.652344f, 0.668457f, 0.684082f, 0.699219f, 0.713867f,
+ 0.729004f, 0.743652f, 0.757812f, 0.771484f, 0.785645f, 0.798828f, 0.812012f, 0.824219f, 0.836914f, 0.850098f, 0.927246f, 0.925293f,
+ 0.920410f, 0.916504f, 0.912598f, 0.908203f, 0.003790f, 0.011009f, 0.018829f, 0.026779f, 0.035339f, 0.043762f, 0.053223f, 0.062408f,
+ 0.072693f, 0.082947f, 0.093689f, 0.105469f, 0.117554f, 0.130005f, 0.142822f, 0.156494f, 0.170166f, 0.184448f, 0.198975f, 0.213745f,
+ 0.230469f, 0.246460f, 0.262939f, 0.279541f, 0.296143f, 0.313721f, 0.331299f, 0.348633f, 0.367188f, 0.384521f, 0.402344f, 0.420410f,
+ 0.438965f, 0.457275f, 0.475830f, 0.493164f, 0.510742f, 0.528809f, 0.546387f, 0.564453f, 0.581055f, 0.598145f, 0.615234f, 0.631836f,
+ 0.647461f, 0.665527f, 0.680664f, 0.696289f, 0.711914f, 0.728027f, 0.741211f, 0.756836f, 0.770508f, 0.783691f, 0.798340f, 0.811523f,
+ 0.824219f, 0.837402f, 0.921387f, 0.920410f, 0.916504f, 0.913086f, 0.908691f, 0.904785f, 0.003479f, 0.009949f, 0.016937f, 0.024445f,
+ 0.031708f, 0.039948f, 0.048218f, 0.056793f, 0.066223f, 0.075928f, 0.085632f, 0.096313f, 0.107178f, 0.118958f, 0.130493f, 0.143311f,
+ 0.156494f, 0.170044f, 0.183960f, 0.197876f, 0.213501f, 0.228027f, 0.244019f, 0.260010f, 0.276611f, 0.293213f, 0.309814f, 0.327393f,
+ 0.344482f, 0.363037f, 0.379883f, 0.398438f, 0.416504f, 0.434082f, 0.451904f, 0.470215f, 0.488525f, 0.505859f, 0.523926f, 0.541504f,
+ 0.559570f, 0.577637f, 0.594238f, 0.611328f, 0.628418f, 0.645020f, 0.661133f, 0.677246f, 0.693848f, 0.709961f, 0.725586f, 0.739746f,
+ 0.755371f, 0.769531f, 0.783203f, 0.797852f, 0.810547f, 0.824707f, 0.916016f, 0.915527f, 0.912109f, 0.908691f, 0.904785f, 0.900879f,
+ 0.003014f, 0.008842f, 0.015640f, 0.022018f, 0.028885f, 0.036163f, 0.044250f, 0.051819f, 0.059967f, 0.069031f, 0.078247f, 0.088135f,
+ 0.098267f, 0.108337f, 0.119751f, 0.131470f, 0.143433f, 0.156006f, 0.169189f, 0.183105f, 0.196655f, 0.211304f, 0.226196f, 0.241211f,
+ 0.257080f, 0.273438f, 0.289307f, 0.306396f, 0.323975f, 0.340576f, 0.358398f, 0.375732f, 0.393799f, 0.411133f, 0.429688f, 0.447998f,
+ 0.466064f, 0.483887f, 0.501465f, 0.519531f, 0.537598f, 0.555664f, 0.573242f, 0.590820f, 0.607910f, 0.625000f, 0.642578f, 0.658203f,
+ 0.675293f, 0.691406f, 0.707520f, 0.724121f, 0.738770f, 0.753418f, 0.769531f, 0.783203f, 0.797363f, 0.811523f, 0.910156f, 0.910645f,
+ 0.907715f, 0.904785f, 0.900879f, 0.896973f, 0.002861f, 0.008591f, 0.014000f, 0.020203f, 0.026962f, 0.033203f, 0.040161f, 0.047485f,
+ 0.055237f, 0.062988f, 0.071594f, 0.080750f, 0.089905f, 0.099854f, 0.109741f, 0.120056f, 0.131592f, 0.143311f, 0.155640f, 0.167969f,
+ 0.181763f, 0.195190f, 0.209229f, 0.223877f, 0.238647f, 0.254150f, 0.269531f, 0.285889f, 0.302979f, 0.319824f, 0.336426f, 0.354004f,
+ 0.372070f, 0.389893f, 0.406982f, 0.424805f, 0.443359f, 0.461182f, 0.479492f, 0.498047f, 0.515625f, 0.533691f, 0.551270f, 0.569336f,
+ 0.587402f, 0.604492f, 0.622070f, 0.639160f, 0.656738f, 0.673828f, 0.689941f, 0.705566f, 0.722168f, 0.737793f, 0.753418f, 0.768066f,
+ 0.783203f, 0.798340f, 0.904297f, 0.905762f, 0.902832f, 0.899414f, 0.895996f, 0.893066f, 0.002535f, 0.007812f, 0.013252f, 0.018738f,
+ 0.024384f, 0.030548f, 0.036774f, 0.043427f, 0.050476f, 0.057556f, 0.065491f, 0.073425f, 0.082458f, 0.091370f, 0.100525f, 0.110413f,
+ 0.120605f, 0.131592f, 0.142822f, 0.154663f, 0.166870f, 0.180176f, 0.193237f, 0.207031f, 0.221191f, 0.236084f, 0.250732f, 0.266602f,
+ 0.282959f, 0.299072f, 0.315430f, 0.332520f, 0.350342f, 0.367676f, 0.385010f, 0.403076f, 0.421631f, 0.439209f, 0.457520f, 0.475342f,
+ 0.494141f, 0.512695f, 0.530273f, 0.547852f, 0.565918f, 0.584473f, 0.602051f, 0.619629f, 0.637207f, 0.655273f, 0.671387f, 0.688965f,
+ 0.706055f, 0.721191f, 0.737305f, 0.752930f, 0.769531f, 0.784668f, 0.898438f, 0.900879f, 0.897949f, 0.894531f, 0.891602f, 0.888672f,
+ 0.002411f, 0.007103f, 0.012161f, 0.017105f, 0.022385f, 0.027985f, 0.033203f, 0.039581f, 0.045532f, 0.052521f, 0.059814f, 0.067261f,
+ 0.074768f, 0.083313f, 0.092041f, 0.101013f, 0.110291f, 0.120361f, 0.130615f, 0.141724f, 0.153076f, 0.165283f, 0.177612f, 0.190918f,
+ 0.204346f, 0.218506f, 0.233154f, 0.247559f, 0.263428f, 0.279053f, 0.295166f, 0.312256f, 0.328857f, 0.345947f, 0.363281f, 0.381348f,
+ 0.398926f, 0.417236f, 0.435547f, 0.453369f, 0.471191f, 0.489502f, 0.508301f, 0.525879f, 0.545410f, 0.563477f, 0.581055f, 0.600098f,
+ 0.617676f, 0.635254f, 0.653809f, 0.670410f, 0.687500f, 0.705078f, 0.720703f, 0.736816f, 0.753418f, 0.769531f, 0.892090f, 0.895020f,
+ 0.892578f, 0.889648f, 0.887207f, 0.884277f, 0.002344f, 0.006565f, 0.011322f, 0.015686f, 0.020630f, 0.025574f, 0.030807f, 0.035980f,
+ 0.042084f, 0.048279f, 0.054352f, 0.061432f, 0.068848f, 0.076172f, 0.083618f, 0.092590f, 0.101135f, 0.109619f, 0.120178f, 0.130249f,
+ 0.140991f, 0.151978f, 0.163696f, 0.175781f, 0.188721f, 0.202026f, 0.215820f, 0.230103f, 0.244873f, 0.259766f, 0.275635f, 0.291504f,
+ 0.307617f, 0.324219f, 0.342041f, 0.358887f, 0.376709f, 0.394775f, 0.412354f, 0.431152f, 0.448975f, 0.468018f, 0.486328f, 0.504883f,
+ 0.523438f, 0.541992f, 0.560547f, 0.579102f, 0.597656f, 0.615234f, 0.633789f, 0.651855f, 0.669434f, 0.687500f, 0.704590f, 0.721680f,
+ 0.738770f, 0.755859f, 0.886719f, 0.889648f, 0.887695f, 0.884766f, 0.882812f, 0.879883f, 0.002003f, 0.006268f, 0.009987f, 0.014198f,
+ 0.018875f, 0.023605f, 0.028259f, 0.033203f, 0.038513f, 0.044495f, 0.049866f, 0.056152f, 0.062500f, 0.069458f, 0.076660f, 0.084473f,
+ 0.092163f, 0.100586f, 0.109741f, 0.119324f, 0.128662f, 0.139526f, 0.150146f, 0.161499f, 0.173706f, 0.185791f, 0.199341f, 0.212891f,
+ 0.227051f, 0.241455f, 0.256592f, 0.271729f, 0.288330f, 0.304199f, 0.321045f, 0.337891f, 0.355469f, 0.373291f, 0.391113f, 0.408936f,
+ 0.426758f, 0.446289f, 0.464600f, 0.483643f, 0.500977f, 0.520996f, 0.539551f, 0.558594f, 0.577148f, 0.595703f, 0.614746f, 0.632324f,
+ 0.650879f, 0.669434f, 0.687012f, 0.704590f, 0.722656f, 0.740234f, 0.880371f, 0.883301f, 0.881836f, 0.879883f, 0.877441f, 0.875000f,
+ 0.001739f, 0.005779f, 0.009598f, 0.013245f, 0.017334f, 0.021637f, 0.025955f, 0.030121f, 0.035217f, 0.040131f, 0.045990f, 0.051453f,
+ 0.056915f, 0.063354f, 0.070007f, 0.076965f, 0.084351f, 0.091980f, 0.100281f, 0.108826f, 0.117981f, 0.127441f, 0.137939f, 0.148315f,
+ 0.160034f, 0.171753f, 0.183594f, 0.196167f, 0.209961f, 0.223511f, 0.238037f, 0.252930f, 0.268066f, 0.284180f, 0.300537f, 0.317139f,
+ 0.333740f, 0.351074f, 0.368896f, 0.386719f, 0.405273f, 0.423584f, 0.442871f, 0.460938f, 0.479736f, 0.499512f, 0.517578f, 0.537109f,
+ 0.555664f, 0.575195f, 0.594238f, 0.613770f, 0.632324f, 0.650879f, 0.669922f, 0.687988f, 0.706055f, 0.724121f, 0.873047f, 0.876953f,
+ 0.875488f, 0.874023f, 0.872559f, 0.869141f, 0.001648f, 0.005039f, 0.008675f, 0.012161f, 0.015823f, 0.019760f, 0.023865f, 0.028015f,
+ 0.032318f, 0.036865f, 0.041504f, 0.046906f, 0.051758f, 0.057922f, 0.064087f, 0.070435f, 0.077209f, 0.084290f, 0.091736f, 0.099243f,
+ 0.108215f, 0.117004f, 0.126343f, 0.135620f, 0.146484f, 0.157349f, 0.168823f, 0.180908f, 0.193848f, 0.206909f, 0.220459f, 0.234619f,
+ 0.249634f, 0.264404f, 0.280273f, 0.296631f, 0.313232f, 0.329834f, 0.347412f, 0.365479f, 0.383545f, 0.401855f, 0.420166f, 0.438721f,
+ 0.458252f, 0.477783f, 0.496826f, 0.516602f, 0.535156f, 0.554199f, 0.574219f, 0.593750f, 0.612305f, 0.631836f, 0.651367f, 0.670410f,
+ 0.689453f, 0.708984f, 0.865234f, 0.872070f, 0.870605f, 0.868652f, 0.866699f, 0.863770f, 0.001492f, 0.004704f, 0.007973f, 0.011124f,
+ 0.014603f, 0.017792f, 0.021652f, 0.025314f, 0.029526f, 0.033722f, 0.038147f, 0.042694f, 0.047668f, 0.052673f, 0.057983f, 0.064209f,
+ 0.070068f, 0.076233f, 0.083313f, 0.090942f, 0.098572f, 0.106750f, 0.115295f, 0.124512f, 0.134277f, 0.144287f, 0.154663f, 0.166504f,
+ 0.178345f, 0.190063f, 0.203247f, 0.217041f, 0.231079f, 0.245850f, 0.260986f, 0.276611f, 0.293213f, 0.309570f, 0.326172f, 0.343994f,
+ 0.361816f, 0.379395f, 0.397949f, 0.417480f, 0.436523f, 0.455322f, 0.474854f, 0.493896f, 0.514160f, 0.533691f, 0.553711f, 0.573730f,
+ 0.593262f, 0.612793f, 0.632812f, 0.651855f, 0.672363f, 0.690918f, 0.857910f, 0.865723f, 0.864746f, 0.863281f, 0.860352f, 0.858887f,
+ 0.001657f, 0.004684f, 0.007290f, 0.010201f, 0.013657f, 0.016541f, 0.019989f, 0.023636f, 0.026932f, 0.030548f, 0.034576f, 0.039154f,
+ 0.043793f, 0.048126f, 0.053162f, 0.058319f, 0.063721f, 0.069885f, 0.076355f, 0.082947f, 0.089844f, 0.097046f, 0.105286f, 0.113281f,
+ 0.122559f, 0.131348f, 0.141357f, 0.152100f, 0.163330f, 0.175415f, 0.187256f, 0.199951f, 0.213501f, 0.227051f, 0.241943f, 0.257324f,
+ 0.273193f, 0.288818f, 0.305420f, 0.322754f, 0.340576f, 0.358643f, 0.375732f, 0.394775f, 0.414307f, 0.433105f, 0.453613f, 0.472168f,
+ 0.492188f, 0.512695f, 0.532715f, 0.552246f, 0.573242f, 0.593262f, 0.613770f, 0.632812f, 0.654785f, 0.673828f, 0.851074f, 0.859375f,
+ 0.858398f, 0.856934f, 0.855469f, 0.853027f, 0.001457f, 0.003944f, 0.006870f, 0.009392f, 0.012543f, 0.015190f, 0.018417f, 0.021576f,
+ 0.024811f, 0.028122f, 0.031708f, 0.035278f, 0.039398f, 0.043793f, 0.048218f, 0.052887f, 0.058044f, 0.063477f, 0.069397f, 0.075256f,
+ 0.081360f, 0.088318f, 0.095398f, 0.103210f, 0.111084f, 0.120361f, 0.129150f, 0.139038f, 0.149292f, 0.160645f, 0.172241f, 0.183716f,
+ 0.196533f, 0.209595f, 0.224121f, 0.238647f, 0.253174f, 0.268799f, 0.286133f, 0.302490f, 0.319092f, 0.337158f, 0.355225f, 0.373535f,
+ 0.392090f, 0.411133f, 0.430908f, 0.450928f, 0.470947f, 0.490967f, 0.511719f, 0.531250f, 0.551758f, 0.573730f, 0.594238f, 0.614746f,
+ 0.636230f, 0.656738f, 0.842773f, 0.852051f, 0.851562f, 0.851074f, 0.848633f, 0.846680f, 0.001404f, 0.003891f, 0.006233f, 0.008751f,
+ 0.011353f, 0.014175f, 0.017075f, 0.019592f, 0.022842f, 0.025772f, 0.028839f, 0.032410f, 0.036011f, 0.039764f, 0.043671f, 0.048126f,
+ 0.052704f, 0.057373f, 0.062561f, 0.067688f, 0.074158f, 0.080200f, 0.086853f, 0.093445f, 0.101379f, 0.109192f, 0.117432f, 0.126709f,
+ 0.136353f, 0.146484f, 0.157227f, 0.168823f, 0.180542f, 0.193115f, 0.206299f, 0.219727f, 0.234375f, 0.249756f, 0.265869f, 0.281738f,
+ 0.298096f, 0.315674f, 0.333252f, 0.352051f, 0.370850f, 0.389160f, 0.409180f, 0.428955f, 0.448730f, 0.469971f, 0.489502f, 0.510742f,
+ 0.531738f, 0.552246f, 0.574707f, 0.595215f, 0.617676f, 0.639160f, 0.835449f, 0.845215f, 0.845215f, 0.844238f, 0.843262f, 0.840332f,
+ 0.001275f, 0.003536f, 0.005600f, 0.007881f, 0.010628f, 0.012878f, 0.015610f, 0.018097f, 0.020996f, 0.023376f, 0.026443f, 0.029556f,
+ 0.032867f, 0.036163f, 0.039581f, 0.043915f, 0.047943f, 0.052216f, 0.056763f, 0.061981f, 0.067322f, 0.072449f, 0.078796f, 0.084717f,
+ 0.091919f, 0.098999f, 0.106995f, 0.115417f, 0.124084f, 0.133667f, 0.143433f, 0.154297f, 0.165161f, 0.177124f, 0.189697f, 0.202759f,
+ 0.216309f, 0.230713f, 0.245728f, 0.261719f, 0.278320f, 0.295410f, 0.312256f, 0.330566f, 0.349365f, 0.367676f, 0.386719f, 0.406494f,
+ 0.427246f, 0.447266f, 0.468506f, 0.489746f, 0.510742f, 0.532227f, 0.553711f, 0.575684f, 0.597656f, 0.619141f, 0.826172f, 0.837402f,
+ 0.837891f, 0.837402f, 0.835449f, 0.833984f, 0.001134f, 0.003105f, 0.005337f, 0.007462f, 0.009628f, 0.011833f, 0.014137f, 0.016113f,
+ 0.018875f, 0.021484f, 0.024063f, 0.026581f, 0.029709f, 0.032623f, 0.036194f, 0.039703f, 0.043335f, 0.047058f, 0.051422f, 0.055908f,
+ 0.060608f, 0.065491f, 0.071167f, 0.076843f, 0.083313f, 0.089661f, 0.097168f, 0.104492f, 0.112122f, 0.121155f, 0.130615f, 0.140137f,
+ 0.150757f, 0.161499f, 0.173462f, 0.185547f, 0.199341f, 0.212524f, 0.227051f, 0.242310f, 0.258057f, 0.274414f, 0.291016f, 0.309082f,
+ 0.327148f, 0.345459f, 0.364990f, 0.384521f, 0.404297f, 0.425781f, 0.445801f, 0.467285f, 0.489258f, 0.510254f, 0.533203f, 0.555664f,
+ 0.578125f, 0.601074f, 0.817871f, 0.830078f, 0.831055f, 0.830078f, 0.829102f, 0.828125f, 0.001101f, 0.003019f, 0.004818f, 0.006725f,
+ 0.008781f, 0.010864f, 0.013069f, 0.014801f, 0.017151f, 0.019531f, 0.021973f, 0.024429f, 0.026917f, 0.030121f, 0.033112f, 0.036041f,
+ 0.039337f, 0.042542f, 0.046509f, 0.050537f, 0.054596f, 0.058990f, 0.064209f, 0.069519f, 0.075134f, 0.080994f, 0.087158f, 0.094177f,
+ 0.102051f, 0.109741f, 0.117981f, 0.127319f, 0.136963f, 0.147095f, 0.158081f, 0.169434f, 0.182251f, 0.195557f, 0.208984f, 0.223267f,
+ 0.238281f, 0.254639f, 0.270996f, 0.288330f, 0.305908f, 0.324219f, 0.343018f, 0.362549f, 0.382324f, 0.402832f, 0.424805f, 0.445312f,
+ 0.467529f, 0.489258f, 0.511230f, 0.535645f, 0.558594f, 0.582031f, 0.809082f, 0.822266f, 0.824219f, 0.823242f, 0.821777f, 0.820801f,
+ 0.000987f, 0.002644f, 0.004562f, 0.006344f, 0.008133f, 0.009918f, 0.011696f, 0.013527f, 0.015572f, 0.017746f, 0.019714f, 0.021942f,
+ 0.024155f, 0.027069f, 0.029678f, 0.032288f, 0.035156f, 0.038574f, 0.041779f, 0.045319f, 0.049225f, 0.053284f, 0.057678f, 0.062225f,
+ 0.067505f, 0.072571f, 0.078613f, 0.084961f, 0.092041f, 0.098938f, 0.106506f, 0.115112f, 0.123779f, 0.133667f, 0.143311f, 0.154541f,
+ 0.165894f, 0.178345f, 0.191406f, 0.205200f, 0.219238f, 0.234985f, 0.250977f, 0.267578f, 0.284912f, 0.302734f, 0.321289f, 0.340332f,
+ 0.360352f, 0.380615f, 0.401611f, 0.423340f, 0.445312f, 0.467529f, 0.490967f, 0.514160f, 0.537598f, 0.561035f, 0.800293f, 0.814453f,
+ 0.815918f, 0.815918f, 0.814941f, 0.813965f, 0.000932f, 0.002567f, 0.004009f, 0.005722f, 0.007538f, 0.008812f, 0.010864f, 0.012413f,
+ 0.014290f, 0.015991f, 0.018051f, 0.019836f, 0.022247f, 0.024506f, 0.026520f, 0.029175f, 0.031769f, 0.034332f, 0.037689f, 0.040466f,
+ 0.043945f, 0.047607f, 0.051605f, 0.055817f, 0.060486f, 0.065125f, 0.070557f, 0.076111f, 0.081909f, 0.088806f, 0.095886f, 0.103210f,
+ 0.111755f, 0.120422f, 0.130249f, 0.140137f, 0.150513f, 0.162109f, 0.174561f, 0.187256f, 0.200928f, 0.215698f, 0.231323f, 0.246582f,
+ 0.264160f, 0.281982f, 0.299561f, 0.319092f, 0.338623f, 0.358643f, 0.379883f, 0.400879f, 0.423096f, 0.445557f, 0.468750f, 0.492188f,
+ 0.516113f, 0.541504f, 0.791016f, 0.805664f, 0.808105f, 0.808594f, 0.807129f, 0.806641f, 0.000871f, 0.002337f, 0.003727f, 0.005474f,
+ 0.006641f, 0.008377f, 0.009567f, 0.011154f, 0.012848f, 0.014610f, 0.016235f, 0.017960f, 0.019958f, 0.021729f, 0.023926f, 0.026154f,
+ 0.028351f, 0.030975f, 0.033722f, 0.036407f, 0.039459f, 0.042694f, 0.046082f, 0.049896f, 0.053833f, 0.058167f, 0.062744f, 0.067932f,
+ 0.073608f, 0.079468f, 0.085632f, 0.092651f, 0.100098f, 0.108521f, 0.116699f, 0.126099f, 0.136108f, 0.146606f, 0.157959f, 0.170410f,
+ 0.183594f, 0.197510f, 0.212280f, 0.227295f, 0.243652f, 0.260986f, 0.278564f, 0.297607f, 0.316406f, 0.336426f, 0.357178f, 0.378662f,
+ 0.400146f, 0.422852f, 0.446045f, 0.470215f, 0.494873f, 0.520020f, 0.781250f, 0.796875f, 0.800293f, 0.800781f, 0.799805f, 0.799316f,
+ 0.000782f, 0.002131f, 0.003649f, 0.004715f, 0.006054f, 0.007458f, 0.008759f, 0.010269f, 0.011711f, 0.012970f, 0.014664f, 0.016327f,
+ 0.017914f, 0.019699f, 0.021423f, 0.023499f, 0.025391f, 0.027374f, 0.029999f, 0.032501f, 0.035156f, 0.037872f, 0.040710f, 0.044403f,
+ 0.047791f, 0.051880f, 0.055969f, 0.060364f, 0.065247f, 0.070496f, 0.076172f, 0.082825f, 0.089294f, 0.096497f, 0.104431f, 0.112854f,
+ 0.122375f, 0.132202f, 0.142700f, 0.153931f, 0.166260f, 0.179565f, 0.193481f, 0.208008f, 0.223877f, 0.240479f, 0.257568f, 0.275879f,
+ 0.294922f, 0.314453f, 0.334961f, 0.355957f, 0.377686f, 0.400391f, 0.423828f, 0.448730f, 0.472900f, 0.498535f, 0.771484f, 0.789062f,
+ 0.791504f, 0.792480f, 0.791016f, 0.791016f, 0.000742f, 0.001822f, 0.003183f, 0.004444f, 0.005600f, 0.006550f, 0.008087f, 0.009247f,
+ 0.010559f, 0.011650f, 0.013184f, 0.014565f, 0.016083f, 0.017548f, 0.019119f, 0.020737f, 0.022644f, 0.024597f, 0.026627f, 0.028809f,
+ 0.031281f, 0.033539f, 0.036469f, 0.039429f, 0.042480f, 0.045654f, 0.049561f, 0.053406f, 0.057739f, 0.062469f, 0.067749f, 0.073364f,
+ 0.079773f, 0.086121f, 0.093262f, 0.100647f, 0.109253f, 0.118042f, 0.128174f, 0.138550f, 0.150024f, 0.162231f, 0.175171f, 0.189087f,
+ 0.204468f, 0.220215f, 0.236938f, 0.254639f, 0.273438f, 0.292236f, 0.312012f, 0.333252f, 0.355957f, 0.377686f, 0.401367f, 0.425781f,
+ 0.451416f, 0.476318f, 0.761230f, 0.779785f, 0.782227f, 0.782715f, 0.782715f, 0.782715f, 0.000632f, 0.001970f, 0.003042f, 0.004025f,
+ 0.005173f, 0.006435f, 0.007343f, 0.008522f, 0.009369f, 0.010475f, 0.011726f, 0.012962f, 0.014145f, 0.015411f, 0.016922f, 0.018478f,
+ 0.020111f, 0.021835f, 0.023682f, 0.025253f, 0.027466f, 0.029678f, 0.032196f, 0.034607f, 0.037415f, 0.040497f, 0.043610f, 0.047089f,
+ 0.051178f, 0.055573f, 0.059845f, 0.064758f, 0.070068f, 0.076111f, 0.082275f, 0.089417f, 0.096863f, 0.105286f, 0.114441f, 0.123535f,
+ 0.134399f, 0.145508f, 0.157959f, 0.171387f, 0.185425f, 0.200806f, 0.216919f, 0.233521f, 0.251953f, 0.270508f, 0.290527f, 0.310791f,
+ 0.332275f, 0.355469f, 0.378418f, 0.403564f, 0.428223f, 0.455322f, 0.750977f, 0.770996f, 0.774414f, 0.774414f, 0.774902f, 0.773926f,
+ 0.000517f, 0.001554f, 0.002741f, 0.003695f, 0.004669f, 0.005417f, 0.006466f, 0.007545f, 0.008453f, 0.009499f, 0.010468f, 0.011490f,
+ 0.012718f, 0.013985f, 0.014977f, 0.016235f, 0.017868f, 0.019211f, 0.020630f, 0.022263f, 0.024078f, 0.026291f, 0.028275f, 0.030380f,
+ 0.032928f, 0.035675f, 0.038513f, 0.041656f, 0.044769f, 0.048523f, 0.052216f, 0.057007f, 0.061493f, 0.066711f, 0.072510f, 0.078735f,
+ 0.085327f, 0.093201f, 0.101135f, 0.109619f, 0.119690f, 0.130371f, 0.141602f, 0.154053f, 0.167480f, 0.181396f, 0.197021f, 0.213623f,
+ 0.230835f, 0.248901f, 0.268066f, 0.289062f, 0.310303f, 0.332520f, 0.355225f, 0.379639f, 0.405273f, 0.432373f, 0.740234f, 0.760742f,
+ 0.763672f, 0.765625f, 0.765625f, 0.765625f, 0.000588f, 0.001405f, 0.002306f, 0.003370f, 0.004375f, 0.005116f, 0.005817f, 0.006630f,
+ 0.007797f, 0.008507f, 0.009216f, 0.010254f, 0.011246f, 0.012154f, 0.013191f, 0.014366f, 0.015503f, 0.016785f, 0.018127f, 0.019562f,
+ 0.021072f, 0.022919f, 0.024643f, 0.026749f, 0.028564f, 0.031006f, 0.033203f, 0.036072f, 0.039032f, 0.042114f, 0.045654f, 0.049561f,
+ 0.053650f, 0.058380f, 0.063049f, 0.068848f, 0.075256f, 0.081543f, 0.088562f, 0.096924f, 0.105652f, 0.115173f, 0.125977f, 0.137207f,
+ 0.149902f, 0.163208f, 0.177979f, 0.193726f, 0.210205f, 0.228027f, 0.247070f, 0.266602f, 0.287842f, 0.309326f, 0.333008f, 0.356934f,
+ 0.382568f, 0.408691f, 0.729004f, 0.751953f, 0.755371f, 0.756348f, 0.757324f, 0.756348f, 0.000431f, 0.001562f, 0.002253f, 0.003088f,
+ 0.003944f, 0.004536f, 0.005066f, 0.006020f, 0.006840f, 0.007542f, 0.008347f, 0.008949f, 0.009827f, 0.010719f, 0.011696f, 0.012756f,
+ 0.013649f, 0.014679f, 0.015808f, 0.017288f, 0.018356f, 0.019913f, 0.021332f, 0.023148f, 0.024719f, 0.026840f, 0.029007f, 0.031250f,
+ 0.033661f, 0.036469f, 0.039490f, 0.042969f, 0.046326f, 0.050293f, 0.054901f, 0.059845f, 0.064941f, 0.071289f, 0.077454f, 0.084656f,
+ 0.092529f, 0.101562f, 0.111145f, 0.121460f, 0.132935f, 0.145386f, 0.159302f, 0.174438f, 0.190186f, 0.206909f, 0.225098f, 0.244751f,
+ 0.265381f, 0.287109f, 0.310059f, 0.333984f, 0.359131f, 0.386230f, 0.716797f, 0.740723f, 0.744629f, 0.746582f, 0.747070f, 0.747070f,
+ 0.000576f, 0.001266f, 0.002028f, 0.002766f, 0.003317f, 0.004051f, 0.004742f, 0.005459f, 0.006054f, 0.006641f, 0.007240f, 0.007919f,
+ 0.008644f, 0.009300f, 0.010170f, 0.010925f, 0.011795f, 0.012733f, 0.013855f, 0.014885f, 0.015900f, 0.017212f, 0.018326f, 0.019684f,
+ 0.021469f, 0.023178f, 0.024734f, 0.026794f, 0.028946f, 0.031204f, 0.033844f, 0.036682f, 0.039948f, 0.043335f, 0.047150f, 0.051422f,
+ 0.055969f, 0.061066f, 0.067139f, 0.073242f, 0.080444f, 0.088440f, 0.096985f, 0.106445f, 0.116943f, 0.128906f, 0.141479f, 0.154907f,
+ 0.170410f, 0.186523f, 0.204102f, 0.222900f, 0.243774f, 0.264160f, 0.286865f, 0.310791f, 0.336182f, 0.362793f, 0.705078f, 0.730469f,
+ 0.735352f, 0.736816f, 0.737793f, 0.736816f, 0.000307f, 0.001126f, 0.001758f, 0.002436f, 0.002911f, 0.003540f, 0.004047f, 0.004711f,
+ 0.005245f, 0.005749f, 0.006302f, 0.006844f, 0.007355f, 0.008095f, 0.008835f, 0.009438f, 0.010139f, 0.010941f, 0.011963f, 0.012878f,
+ 0.013519f, 0.014847f, 0.015945f, 0.017029f, 0.018250f, 0.019669f, 0.021362f, 0.022675f, 0.024750f, 0.026657f, 0.028854f, 0.031219f,
+ 0.033844f, 0.036804f, 0.040222f, 0.043793f, 0.047791f, 0.052185f, 0.057251f, 0.062866f, 0.069275f, 0.075867f, 0.083923f, 0.092407f,
+ 0.102295f, 0.112366f, 0.124207f, 0.137085f, 0.151489f, 0.167114f, 0.183838f, 0.202148f, 0.221558f, 0.242065f, 0.263916f, 0.287842f,
+ 0.312256f, 0.339111f, 0.693848f, 0.719727f, 0.724609f, 0.726074f, 0.727539f, 0.727051f, 0.000428f, 0.000939f, 0.001581f, 0.002033f,
+ 0.002665f, 0.003222f, 0.003660f, 0.004059f, 0.004475f, 0.004997f, 0.005554f, 0.006031f, 0.006371f, 0.007080f, 0.007511f, 0.008263f,
+ 0.008820f, 0.009552f, 0.010124f, 0.010948f, 0.011665f, 0.012550f, 0.013397f, 0.014526f, 0.015388f, 0.016754f, 0.017960f, 0.019257f,
+ 0.020844f, 0.022583f, 0.024246f, 0.026642f, 0.028656f, 0.031128f, 0.033783f, 0.036865f, 0.040253f, 0.044312f, 0.048523f, 0.053314f,
+ 0.058655f, 0.064880f, 0.071594f, 0.079102f, 0.087891f, 0.097107f, 0.108276f, 0.119751f, 0.133179f, 0.148071f, 0.163818f, 0.180908f,
+ 0.199951f, 0.219849f, 0.241699f, 0.264160f, 0.288818f, 0.315918f, 0.680176f, 0.708496f, 0.713867f, 0.716309f, 0.716797f, 0.717285f,
+ 0.000467f, 0.001054f, 0.001476f, 0.001825f, 0.002386f, 0.002644f, 0.003218f, 0.003553f, 0.003866f, 0.004433f, 0.004700f, 0.004948f,
+ 0.005505f, 0.006023f, 0.006405f, 0.006920f, 0.007484f, 0.008057f, 0.008598f, 0.009178f, 0.009857f, 0.010551f, 0.011169f, 0.012199f,
+ 0.013092f, 0.014084f, 0.015091f, 0.016205f, 0.017303f, 0.018845f, 0.020538f, 0.021957f, 0.023773f, 0.025833f, 0.028152f, 0.030716f,
+ 0.033661f, 0.036896f, 0.040405f, 0.044708f, 0.049286f, 0.054321f, 0.060333f, 0.067322f, 0.074890f, 0.083435f, 0.092651f, 0.103516f,
+ 0.115784f, 0.129028f, 0.144287f, 0.160278f, 0.178345f, 0.197632f, 0.218994f, 0.241089f, 0.265869f, 0.292725f, 0.667969f, 0.697266f,
+ 0.702637f, 0.704590f, 0.706055f, 0.707031f, 0.000348f, 0.000841f, 0.001292f, 0.001580f, 0.001961f, 0.002508f, 0.002630f, 0.002993f,
+ 0.003458f, 0.003738f, 0.003952f, 0.004425f, 0.004639f, 0.005070f, 0.005547f, 0.005840f, 0.006462f, 0.006844f, 0.007214f, 0.007698f,
+ 0.008339f, 0.008980f, 0.009560f, 0.010094f, 0.010941f, 0.011711f, 0.012550f, 0.013565f, 0.014404f, 0.015579f, 0.016754f, 0.018082f,
+ 0.019592f, 0.021439f, 0.023209f, 0.025375f, 0.027863f, 0.030411f, 0.033478f, 0.037018f, 0.040680f, 0.045105f, 0.050476f, 0.056183f,
+ 0.062805f, 0.070251f, 0.078613f, 0.088196f, 0.099060f, 0.111450f, 0.125122f, 0.140869f, 0.158203f, 0.176880f, 0.197266f, 0.218506f,
+ 0.242798f, 0.268555f, 0.655273f, 0.686035f, 0.691406f, 0.694336f, 0.695312f, 0.695801f, 0.000170f, 0.000976f, 0.001161f, 0.001441f,
+ 0.001846f, 0.002144f, 0.002367f, 0.002632f, 0.002892f, 0.003178f, 0.003435f, 0.003618f, 0.004021f, 0.004292f, 0.004562f, 0.005028f,
+ 0.005405f, 0.005623f, 0.006069f, 0.006577f, 0.006973f, 0.007431f, 0.007904f, 0.008484f, 0.009018f, 0.009659f, 0.010559f, 0.010994f,
+ 0.012009f, 0.012840f, 0.013901f, 0.014915f, 0.016129f, 0.017502f, 0.019089f, 0.020676f, 0.022568f, 0.024673f, 0.027252f, 0.029984f,
+ 0.033234f, 0.037079f, 0.041016f, 0.045868f, 0.051758f, 0.058014f, 0.065613f, 0.073853f, 0.083801f, 0.094727f, 0.107483f, 0.121826f,
+ 0.137573f, 0.156006f, 0.175049f, 0.196167f, 0.219482f, 0.245850f, 0.641113f, 0.673340f, 0.679688f, 0.681641f, 0.683594f, 0.684082f,
+ 0.000293f, 0.000601f, 0.001049f, 0.001358f, 0.001532f, 0.001719f, 0.001882f, 0.002298f, 0.002317f, 0.002628f, 0.002750f, 0.003143f,
+ 0.003363f, 0.003559f, 0.003866f, 0.004204f, 0.004383f, 0.004753f, 0.005028f, 0.005348f, 0.005863f, 0.006176f, 0.006569f, 0.006954f,
+ 0.007401f, 0.008057f, 0.008537f, 0.009178f, 0.009735f, 0.010521f, 0.011208f, 0.011978f, 0.013130f, 0.014099f, 0.015289f, 0.016739f,
+ 0.018219f, 0.019821f, 0.021713f, 0.024200f, 0.026749f, 0.029785f, 0.033386f, 0.036987f, 0.041840f, 0.047089f, 0.053253f, 0.060760f,
+ 0.069214f, 0.079224f, 0.090515f, 0.103638f, 0.118652f, 0.135376f, 0.154175f, 0.174561f, 0.196777f, 0.222534f, 0.628906f, 0.660645f,
+ 0.668457f, 0.670410f, 0.672852f, 0.673340f, 0.000258f, 0.000656f, 0.000811f, 0.001049f, 0.001288f, 0.001462f, 0.001599f, 0.001740f,
+ 0.002012f, 0.002171f, 0.002367f, 0.002535f, 0.002705f, 0.002880f, 0.003115f, 0.003429f, 0.003666f, 0.003897f, 0.004116f, 0.004398f,
+ 0.004635f, 0.005066f, 0.005341f, 0.005779f, 0.006042f, 0.006454f, 0.006954f, 0.007450f, 0.007835f, 0.008400f, 0.009132f, 0.009819f,
+ 0.010536f, 0.011307f, 0.012245f, 0.013229f, 0.014580f, 0.015900f, 0.017303f, 0.019119f, 0.021103f, 0.023468f, 0.026123f, 0.029495f,
+ 0.033112f, 0.037628f, 0.042938f, 0.048859f, 0.056152f, 0.064941f, 0.074829f, 0.086548f, 0.100281f, 0.115967f, 0.133545f, 0.153198f,
+ 0.175171f, 0.199341f, 0.613770f, 0.648926f, 0.655273f, 0.658691f, 0.660645f, 0.662598f, 0.000176f, 0.000474f, 0.000602f, 0.000854f,
+ 0.001030f, 0.001240f, 0.001349f, 0.001505f, 0.001580f, 0.001738f, 0.001957f, 0.002068f, 0.002230f, 0.002420f, 0.002556f, 0.002705f,
+ 0.002998f, 0.003178f, 0.003345f, 0.003567f, 0.003811f, 0.004105f, 0.004284f, 0.004593f, 0.004848f, 0.005173f, 0.005527f, 0.005939f,
+ 0.006306f, 0.006817f, 0.007366f, 0.007729f, 0.008339f, 0.008995f, 0.009644f, 0.010551f, 0.011360f, 0.012344f, 0.013710f, 0.015030f,
+ 0.016510f, 0.018143f, 0.020279f, 0.022751f, 0.025650f, 0.029144f, 0.033508f, 0.038452f, 0.044556f, 0.052032f, 0.060364f, 0.070923f,
+ 0.082642f, 0.097290f, 0.113525f, 0.132446f, 0.153442f, 0.176880f, 0.600586f, 0.636719f, 0.644531f, 0.647461f, 0.648926f, 0.649414f,
+ 0.000121f, 0.000426f, 0.000509f, 0.000778f, 0.000931f, 0.000992f, 0.001135f, 0.001303f, 0.001359f, 0.001410f, 0.001519f, 0.001722f,
+ 0.001751f, 0.001951f, 0.002060f, 0.002218f, 0.002287f, 0.002487f, 0.002670f, 0.002848f, 0.003061f, 0.003233f, 0.003452f, 0.003664f,
+ 0.003883f, 0.004078f, 0.004379f, 0.004692f, 0.004982f, 0.005329f, 0.005756f, 0.006081f, 0.006504f, 0.007019f, 0.007599f, 0.008217f,
+ 0.008850f, 0.009628f, 0.010437f, 0.011597f, 0.012650f, 0.013931f, 0.015480f, 0.017380f, 0.019577f, 0.022247f, 0.025513f, 0.029617f,
+ 0.034363f, 0.040314f, 0.047241f, 0.056274f, 0.066711f, 0.079773f, 0.094482f, 0.112488f, 0.132446f, 0.154907f, 0.585449f, 0.624023f,
+ 0.630371f, 0.634277f, 0.636230f, 0.637207f, 0.000161f, 0.000263f, 0.000526f, 0.000627f, 0.000723f, 0.000775f, 0.000856f, 0.000960f,
+ 0.001079f, 0.001158f, 0.001208f, 0.001272f, 0.001441f, 0.001557f, 0.001657f, 0.001702f, 0.001897f, 0.001918f, 0.002151f, 0.002232f,
+ 0.002337f, 0.002522f, 0.002720f, 0.002865f, 0.003029f, 0.003193f, 0.003387f, 0.003601f, 0.003887f, 0.004124f, 0.004356f, 0.004639f,
+ 0.005070f, 0.005466f, 0.005863f, 0.006298f, 0.006874f, 0.007290f, 0.007965f, 0.008774f, 0.009560f, 0.010666f, 0.011719f, 0.013077f,
+ 0.014679f, 0.016693f, 0.019058f, 0.021881f, 0.025528f, 0.030121f, 0.036011f, 0.043396f, 0.052460f, 0.063477f, 0.076721f, 0.093079f,
+ 0.112305f, 0.133667f, 0.572266f, 0.609375f, 0.618164f, 0.622070f, 0.623535f, 0.625488f, 0.000109f, 0.000212f, 0.000404f, 0.000578f,
+ 0.000567f, 0.000655f, 0.000763f, 0.000676f, 0.000824f, 0.000869f, 0.000971f, 0.001064f, 0.001132f, 0.001210f, 0.001212f, 0.001398f,
+ 0.001486f, 0.001525f, 0.001653f, 0.001676f, 0.001867f, 0.001953f, 0.002062f, 0.002199f, 0.002295f, 0.002443f, 0.002586f, 0.002766f,
+ 0.002979f, 0.003128f, 0.003429f, 0.003551f, 0.003763f, 0.004074f, 0.004349f, 0.004688f, 0.005032f, 0.005470f, 0.005894f, 0.006519f,
+ 0.007092f, 0.007896f, 0.008629f, 0.009659f, 0.010910f, 0.012215f, 0.013962f, 0.015991f, 0.018646f, 0.021881f, 0.026428f, 0.032074f,
+ 0.039276f, 0.048645f, 0.060455f, 0.075256f, 0.092773f, 0.113220f, 0.554688f, 0.596191f, 0.605957f, 0.608887f, 0.610352f, 0.612305f,
+ 0.000202f, 0.000186f, 0.000312f, 0.000433f, 0.000382f, 0.000543f, 0.000482f, 0.000546f, 0.000621f, 0.000666f, 0.000789f, 0.000802f,
+ 0.000859f, 0.000950f, 0.000970f, 0.000975f, 0.001113f, 0.001162f, 0.001207f, 0.001312f, 0.001362f, 0.001433f, 0.001541f, 0.001618f,
+ 0.001720f, 0.001791f, 0.001966f, 0.002035f, 0.002199f, 0.002413f, 0.002546f, 0.002626f, 0.002855f, 0.003063f, 0.003204f, 0.003448f,
+ 0.003693f, 0.003986f, 0.004364f, 0.004684f, 0.005127f, 0.005619f, 0.006271f, 0.006870f, 0.007748f, 0.008713f, 0.009911f, 0.011368f,
+ 0.013191f, 0.015518f, 0.018646f, 0.022644f, 0.028107f, 0.035645f, 0.045471f, 0.058502f, 0.074646f, 0.093994f, 0.541016f, 0.583008f,
+ 0.591797f, 0.596191f, 0.599121f, 0.600098f, 0.000000f, 0.000179f, 0.000242f, 0.000318f, 0.000341f, 0.000345f, 0.000432f, 0.000364f,
+ 0.000475f, 0.000483f, 0.000572f, 0.000576f, 0.000619f, 0.000640f, 0.000716f, 0.000737f, 0.000791f, 0.000845f, 0.000871f, 0.000907f,
+ 0.000998f, 0.001025f, 0.001107f, 0.001181f, 0.001244f, 0.001303f, 0.001391f, 0.001462f, 0.001549f, 0.001631f, 0.001756f, 0.001906f,
+ 0.001984f, 0.002161f, 0.002264f, 0.002419f, 0.002613f, 0.002825f, 0.003103f, 0.003321f, 0.003584f, 0.003893f, 0.004349f, 0.004799f,
+ 0.005383f, 0.006020f, 0.006836f, 0.007858f, 0.009117f, 0.010674f, 0.012825f, 0.015533f, 0.019363f, 0.024780f, 0.032593f, 0.043274f,
+ 0.057770f, 0.076111f, 0.525879f, 0.569336f, 0.578613f, 0.583008f, 0.585449f, 0.586426f, 0.000000f, 0.000088f, 0.000192f, 0.000227f,
+ 0.000230f, 0.000286f, 0.000255f, 0.000317f, 0.000321f, 0.000371f, 0.000401f, 0.000373f, 0.000391f, 0.000457f, 0.000474f, 0.000530f,
+ 0.000509f, 0.000585f, 0.000625f, 0.000664f, 0.000707f, 0.000746f, 0.000772f, 0.000817f, 0.000877f, 0.000887f, 0.000978f, 0.001007f,
+ 0.001069f, 0.001202f, 0.001192f, 0.001290f, 0.001356f, 0.001464f, 0.001583f, 0.001678f, 0.001771f, 0.001929f, 0.002050f, 0.002230f,
+ 0.002424f, 0.002651f, 0.002888f, 0.003176f, 0.003534f, 0.003967f, 0.004475f, 0.005154f, 0.005993f, 0.007118f, 0.008469f, 0.010338f,
+ 0.012794f, 0.016403f, 0.021957f, 0.030090f, 0.042419f, 0.059052f, 0.510254f, 0.554199f, 0.564453f, 0.570312f, 0.572754f, 0.573242f,
+ 0.000000f, 0.000126f, 0.000180f, 0.000121f, 0.000178f, 0.000176f, 0.000177f, 0.000212f, 0.000210f, 0.000228f, 0.000238f, 0.000291f,
+ 0.000280f, 0.000298f, 0.000336f, 0.000350f, 0.000369f, 0.000387f, 0.000395f, 0.000427f, 0.000460f, 0.000476f, 0.000515f, 0.000536f,
+ 0.000573f, 0.000619f, 0.000650f, 0.000670f, 0.000703f, 0.000746f, 0.000798f, 0.000836f, 0.000902f, 0.000949f, 0.001031f, 0.001062f,
+ 0.001162f, 0.001227f, 0.001349f, 0.001442f, 0.001533f, 0.001690f, 0.001865f, 0.001995f, 0.002228f, 0.002495f, 0.002800f, 0.003191f,
+ 0.003653f, 0.004349f, 0.005203f, 0.006393f, 0.008026f, 0.010307f, 0.013710f, 0.019379f, 0.028854f, 0.043457f, 0.494873f, 0.541016f,
+ 0.550781f, 0.555664f, 0.558105f, 0.559570f, 0.000000f, 0.000095f, 0.000086f, 0.000079f, 0.000105f, 0.000124f, 0.000111f, 0.000137f,
+ 0.000141f, 0.000142f, 0.000147f, 0.000151f, 0.000160f, 0.000181f, 0.000202f, 0.000207f, 0.000214f, 0.000248f, 0.000244f, 0.000282f,
+ 0.000273f, 0.000283f, 0.000306f, 0.000334f, 0.000367f, 0.000378f, 0.000376f, 0.000399f, 0.000437f, 0.000459f, 0.000474f, 0.000516f,
+ 0.000552f, 0.000567f, 0.000616f, 0.000649f, 0.000693f, 0.000743f, 0.000805f, 0.000851f, 0.000918f, 0.000999f, 0.001085f, 0.001195f,
+ 0.001309f, 0.001466f, 0.001644f, 0.001850f, 0.002151f, 0.002487f, 0.002974f, 0.003654f, 0.004574f, 0.006001f, 0.008156f, 0.011452f,
+ 0.017853f, 0.029739f, 0.478271f, 0.526367f, 0.537109f, 0.541504f, 0.544434f, 0.545898f, 0.000106f, 0.000085f, 0.000074f, 0.000067f,
+ 0.000066f, 0.000070f, 0.000069f, 0.000073f, 0.000073f, 0.000080f, 0.000084f, 0.000109f, 0.000093f, 0.000098f, 0.000119f, 0.000108f,
+ 0.000128f, 0.000135f, 0.000137f, 0.000149f, 0.000150f, 0.000157f, 0.000182f, 0.000185f, 0.000207f, 0.000206f, 0.000214f, 0.000234f,
+ 0.000237f, 0.000253f, 0.000267f, 0.000289f, 0.000306f, 0.000313f, 0.000344f, 0.000352f, 0.000384f, 0.000406f, 0.000445f, 0.000467f,
+ 0.000503f, 0.000543f, 0.000593f, 0.000634f, 0.000697f, 0.000764f, 0.000850f, 0.000963f, 0.001105f, 0.001298f, 0.001536f, 0.001856f,
+ 0.002333f, 0.003069f, 0.004299f, 0.006271f, 0.009789f, 0.018234f, 0.462402f, 0.511719f, 0.522949f, 0.527344f, 0.530762f, 0.532715f,
+ 0.000091f, 0.000069f, 0.000060f, 0.000054f, 0.000049f, 0.000046f, 0.000043f, 0.000041f, 0.000040f, 0.000044f, 0.000040f, 0.000040f,
+ 0.000054f, 0.000044f, 0.000045f, 0.000044f, 0.000062f, 0.000062f, 0.000069f, 0.000071f, 0.000074f, 0.000079f, 0.000081f, 0.000081f,
+ 0.000085f, 0.000099f, 0.000098f, 0.000115f, 0.000115f, 0.000119f, 0.000125f, 0.000130f, 0.000140f, 0.000144f, 0.000165f, 0.000172f,
+ 0.000178f, 0.000191f, 0.000205f, 0.000222f, 0.000234f, 0.000251f, 0.000276f, 0.000293f, 0.000327f, 0.000354f, 0.000392f, 0.000437f,
+ 0.000494f, 0.000562f, 0.000662f, 0.000800f, 0.001005f, 0.001315f, 0.001852f, 0.002825f, 0.004723f, 0.009285f, 0.446533f, 0.497803f,
+ 0.508301f, 0.514160f, 0.516602f, 0.519043f, 0.000067f, 0.000048f, 0.000040f, 0.000036f, 0.000033f, 0.000031f, 0.000030f, 0.000028f,
+ 0.000027f, 0.000026f, 0.000025f, 0.000024f, 0.000023f, 0.000022f, 0.000021f, 0.000020f, 0.000019f, 0.000020f, 0.000024f, 0.000026f,
+ 0.000025f, 0.000027f, 0.000031f, 0.000032f, 0.000032f, 0.000037f, 0.000041f, 0.000038f, 0.000045f, 0.000042f, 0.000048f, 0.000049f,
+ 0.000053f, 0.000055f, 0.000059f, 0.000062f, 0.000071f, 0.000074f, 0.000077f, 0.000081f, 0.000086f, 0.000091f, 0.000098f, 0.000109f,
+ 0.000116f, 0.000125f, 0.000137f, 0.000158f, 0.000173f, 0.000193f, 0.000230f, 0.000273f, 0.000335f, 0.000425f, 0.000603f, 0.000935f,
+ 0.001694f, 0.003727f, 0.431396f, 0.481934f, 0.493652f, 0.499512f, 0.502930f, 0.504883f, 0.000021f, 0.000016f, 0.000013f, 0.000012f,
+ 0.000013f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000011f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000011f,
+ 0.000011f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000008f, 0.000007f,
+ 0.000008f, 0.000009f, 0.000009f, 0.000010f, 0.000010f, 0.000013f, 0.000014f, 0.000013f, 0.000015f, 0.000016f, 0.000017f, 0.000019f,
+ 0.000019f, 0.000020f, 0.000023f, 0.000026f, 0.000027f, 0.000027f, 0.000032f, 0.000030f, 0.000036f, 0.000039f, 0.000050f, 0.000056f,
+ 0.000063f, 0.000082f, 0.000109f, 0.000168f, 0.000317f, 0.000922f, 0.415283f, 0.467773f, 0.479980f, 0.486328f, 0.489014f, 0.490723f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000005f, 0.000008f, 0.000026f, 0.398926f, 0.452881f,
+ 0.465576f, 0.471436f, 0.474854f, 0.477051f,
+ },
+ {
+ 0.019653f, 0.058990f, 0.097473f, 0.134277f, 0.169189f, 0.203491f, 0.236450f, 0.267578f, 0.297852f, 0.326416f, 0.354004f, 0.380859f,
+ 0.406250f, 0.431641f, 0.455078f, 0.477539f, 0.500000f, 0.520996f, 0.541504f, 0.560547f, 0.580566f, 0.598633f, 0.615723f, 0.633301f,
+ 0.649902f, 0.666016f, 0.681641f, 0.695801f, 0.709961f, 0.724609f, 0.738770f, 0.751953f, 0.765137f, 0.775879f, 0.788574f, 0.799805f,
+ 0.812012f, 0.822754f, 0.833496f, 0.844238f, 0.854004f, 0.864258f, 0.874023f, 0.883301f, 0.891602f, 0.900391f, 0.909668f, 0.917969f,
+ 0.925781f, 0.934570f, 0.941895f, 0.949707f, 0.956543f, 0.963379f, 0.970703f, 0.977539f, 0.984863f, 0.991211f, 0.988770f, 0.972656f,
+ 0.960449f, 0.949707f, 0.940430f, 0.931641f, 0.017303f, 0.052399f, 0.086548f, 0.119446f, 0.153076f, 0.183594f, 0.214722f, 0.245117f,
+ 0.273193f, 0.301270f, 0.328613f, 0.354492f, 0.379883f, 0.404541f, 0.427979f, 0.450195f, 0.472656f, 0.494629f, 0.515137f, 0.534668f,
+ 0.554199f, 0.573242f, 0.591309f, 0.608887f, 0.625977f, 0.642578f, 0.658203f, 0.672852f, 0.688477f, 0.704102f, 0.717285f, 0.731445f,
+ 0.744629f, 0.756836f, 0.769531f, 0.782715f, 0.793945f, 0.805664f, 0.816406f, 0.828125f, 0.838379f, 0.849121f, 0.858887f, 0.868652f,
+ 0.877930f, 0.888184f, 0.896973f, 0.905762f, 0.915039f, 0.921875f, 0.930176f, 0.937988f, 0.946777f, 0.954102f, 0.960938f, 0.968750f,
+ 0.975586f, 0.982422f, 0.984375f, 0.969238f, 0.957520f, 0.947754f, 0.938477f, 0.930176f, 0.015221f, 0.045837f, 0.076843f, 0.107666f,
+ 0.136719f, 0.166504f, 0.196045f, 0.223999f, 0.250244f, 0.278320f, 0.303711f, 0.329346f, 0.353271f, 0.378906f, 0.401367f, 0.424316f,
+ 0.447266f, 0.468018f, 0.487793f, 0.508301f, 0.529297f, 0.547363f, 0.566406f, 0.583984f, 0.601562f, 0.618652f, 0.634766f, 0.650879f,
+ 0.666016f, 0.681641f, 0.695801f, 0.710449f, 0.724121f, 0.737305f, 0.750488f, 0.762695f, 0.775391f, 0.788086f, 0.799316f, 0.811035f,
+ 0.821777f, 0.833008f, 0.844238f, 0.854004f, 0.864258f, 0.874023f, 0.882812f, 0.892578f, 0.901367f, 0.910156f, 0.918457f, 0.926758f,
+ 0.936035f, 0.942871f, 0.950684f, 0.958496f, 0.965820f, 0.973145f, 0.980469f, 0.965820f, 0.955078f, 0.945312f, 0.936523f, 0.928223f,
+ 0.013420f, 0.041138f, 0.068359f, 0.096436f, 0.124023f, 0.150879f, 0.177246f, 0.204224f, 0.230103f, 0.255859f, 0.281494f, 0.305420f,
+ 0.329834f, 0.352783f, 0.376709f, 0.398682f, 0.420654f, 0.442627f, 0.462646f, 0.483887f, 0.502441f, 0.521484f, 0.540527f, 0.559082f,
+ 0.576172f, 0.595703f, 0.611328f, 0.627930f, 0.644043f, 0.659668f, 0.674316f, 0.688965f, 0.703613f, 0.717285f, 0.730957f, 0.744629f,
+ 0.756836f, 0.770020f, 0.781738f, 0.793945f, 0.805176f, 0.816895f, 0.828125f, 0.838379f, 0.849121f, 0.859375f, 0.869141f, 0.878418f,
+ 0.888184f, 0.897461f, 0.906738f, 0.915039f, 0.923828f, 0.932129f, 0.940430f, 0.947754f, 0.956543f, 0.963867f, 0.976074f, 0.962402f,
+ 0.951660f, 0.942383f, 0.934082f, 0.926758f, 0.012001f, 0.036591f, 0.061737f, 0.086670f, 0.112000f, 0.136719f, 0.161743f, 0.186768f,
+ 0.211792f, 0.235840f, 0.259521f, 0.283203f, 0.307129f, 0.329590f, 0.352295f, 0.374268f, 0.395996f, 0.416992f, 0.437744f, 0.457520f,
+ 0.477295f, 0.497314f, 0.515625f, 0.534180f, 0.553223f, 0.570312f, 0.588379f, 0.604492f, 0.621582f, 0.636719f, 0.653320f, 0.666992f,
+ 0.683105f, 0.697266f, 0.710449f, 0.724609f, 0.737793f, 0.750977f, 0.764160f, 0.775879f, 0.788086f, 0.799805f, 0.812012f, 0.823242f,
+ 0.833496f, 0.844238f, 0.854492f, 0.864746f, 0.875000f, 0.884277f, 0.894043f, 0.902832f, 0.911621f, 0.920898f, 0.929688f, 0.937500f,
+ 0.945801f, 0.953613f, 0.971191f, 0.958984f, 0.949219f, 0.939941f, 0.932129f, 0.924316f, 0.010612f, 0.032684f, 0.054810f, 0.077759f,
+ 0.100952f, 0.124023f, 0.146851f, 0.171021f, 0.193604f, 0.217163f, 0.239380f, 0.261963f, 0.284424f, 0.307129f, 0.328613f, 0.351318f,
+ 0.371826f, 0.392334f, 0.413574f, 0.432617f, 0.453613f, 0.472656f, 0.491943f, 0.510254f, 0.528320f, 0.546387f, 0.563965f, 0.580078f,
+ 0.598633f, 0.613770f, 0.629883f, 0.645996f, 0.661621f, 0.675293f, 0.688965f, 0.705078f, 0.718262f, 0.731934f, 0.745605f, 0.757812f,
+ 0.770996f, 0.782715f, 0.795410f, 0.807129f, 0.818359f, 0.829102f, 0.839844f, 0.851074f, 0.860840f, 0.871094f, 0.880859f, 0.891113f,
+ 0.900391f, 0.909668f, 0.917969f, 0.927246f, 0.935547f, 0.943848f, 0.966797f, 0.955566f, 0.945801f, 0.937012f, 0.929199f, 0.921875f,
+ 0.009483f, 0.029556f, 0.050140f, 0.070129f, 0.091797f, 0.112549f, 0.134155f, 0.156372f, 0.177368f, 0.198975f, 0.220825f, 0.243286f,
+ 0.263916f, 0.285645f, 0.306885f, 0.327393f, 0.348145f, 0.368896f, 0.389404f, 0.409424f, 0.429199f, 0.448730f, 0.467529f, 0.486572f,
+ 0.505371f, 0.522461f, 0.540039f, 0.558105f, 0.574219f, 0.591309f, 0.607422f, 0.623535f, 0.639648f, 0.654785f, 0.669922f, 0.685547f,
+ 0.698730f, 0.712891f, 0.726074f, 0.740234f, 0.752441f, 0.765625f, 0.778320f, 0.789551f, 0.802246f, 0.813477f, 0.825195f, 0.836426f,
+ 0.847168f, 0.856934f, 0.868164f, 0.877930f, 0.888184f, 0.897461f, 0.906738f, 0.915527f, 0.925293f, 0.935059f, 0.962402f, 0.951660f,
+ 0.942383f, 0.933594f, 0.926270f, 0.919434f, 0.008934f, 0.026581f, 0.044708f, 0.063354f, 0.082825f, 0.102844f, 0.122437f, 0.141968f,
+ 0.162720f, 0.183105f, 0.202515f, 0.224609f, 0.244995f, 0.265381f, 0.285645f, 0.306152f, 0.326416f, 0.346680f, 0.365967f, 0.385498f,
+ 0.406006f, 0.425293f, 0.444092f, 0.461914f, 0.480225f, 0.499268f, 0.517090f, 0.535156f, 0.552246f, 0.568359f, 0.585449f, 0.601562f,
+ 0.616699f, 0.633789f, 0.649414f, 0.663574f, 0.678711f, 0.693848f, 0.706543f, 0.721680f, 0.734375f, 0.746582f, 0.760742f, 0.773438f,
+ 0.786133f, 0.797852f, 0.809082f, 0.821777f, 0.832031f, 0.843262f, 0.854492f, 0.864746f, 0.875000f, 0.884766f, 0.895020f, 0.904785f,
+ 0.914062f, 0.922852f, 0.957520f, 0.947266f, 0.938965f, 0.930664f, 0.923340f, 0.916992f, 0.007668f, 0.024017f, 0.040405f, 0.057831f,
+ 0.075195f, 0.093079f, 0.111694f, 0.130127f, 0.148926f, 0.168213f, 0.187500f, 0.206543f, 0.226440f, 0.246460f, 0.265869f, 0.285400f,
+ 0.305176f, 0.324707f, 0.344238f, 0.363281f, 0.383057f, 0.401123f, 0.420166f, 0.439941f, 0.457764f, 0.475586f, 0.493164f, 0.511719f,
+ 0.528809f, 0.545898f, 0.562988f, 0.579590f, 0.596191f, 0.612305f, 0.627441f, 0.643555f, 0.658203f, 0.672363f, 0.687988f, 0.702637f,
+ 0.715332f, 0.728516f, 0.742676f, 0.756348f, 0.768555f, 0.781250f, 0.794434f, 0.806152f, 0.818359f, 0.828613f, 0.840332f, 0.851074f,
+ 0.861816f, 0.872559f, 0.882812f, 0.892578f, 0.903320f, 0.912598f, 0.952637f, 0.943848f, 0.935059f, 0.927246f, 0.920410f, 0.914062f,
+ 0.007263f, 0.021530f, 0.037048f, 0.052429f, 0.068909f, 0.084961f, 0.102112f, 0.119568f, 0.136475f, 0.154541f, 0.172852f, 0.191528f,
+ 0.209717f, 0.228638f, 0.246948f, 0.265869f, 0.284912f, 0.304199f, 0.322510f, 0.341309f, 0.360596f, 0.379639f, 0.397461f, 0.416504f,
+ 0.434570f, 0.452881f, 0.470947f, 0.489014f, 0.505859f, 0.523438f, 0.541016f, 0.557129f, 0.574219f, 0.590332f, 0.606445f, 0.622070f,
+ 0.637695f, 0.653809f, 0.667969f, 0.682129f, 0.697754f, 0.711426f, 0.724609f, 0.737793f, 0.750977f, 0.765625f, 0.777832f, 0.790039f,
+ 0.801270f, 0.813477f, 0.825684f, 0.837402f, 0.848145f, 0.859375f, 0.870117f, 0.880859f, 0.891602f, 0.900391f, 0.947754f, 0.938965f,
+ 0.931152f, 0.923828f, 0.917480f, 0.911133f, 0.006401f, 0.019730f, 0.033813f, 0.047729f, 0.062561f, 0.077515f, 0.093140f, 0.108948f,
+ 0.125366f, 0.141968f, 0.159058f, 0.175781f, 0.193726f, 0.212036f, 0.229980f, 0.247681f, 0.265869f, 0.284424f, 0.302734f, 0.320557f,
+ 0.339111f, 0.357910f, 0.376221f, 0.394287f, 0.412109f, 0.429688f, 0.448486f, 0.466064f, 0.483398f, 0.500977f, 0.517090f, 0.535156f,
+ 0.552246f, 0.568359f, 0.583984f, 0.600586f, 0.616699f, 0.632324f, 0.647949f, 0.662598f, 0.677246f, 0.692383f, 0.706543f, 0.719727f,
+ 0.734375f, 0.747070f, 0.761230f, 0.773926f, 0.786621f, 0.797852f, 0.811523f, 0.823242f, 0.834961f, 0.846680f, 0.857422f, 0.868652f,
+ 0.879395f, 0.890137f, 0.942383f, 0.934082f, 0.927246f, 0.919922f, 0.913574f, 0.908203f, 0.005836f, 0.018158f, 0.030746f, 0.043335f,
+ 0.057007f, 0.070801f, 0.085754f, 0.099548f, 0.115112f, 0.130127f, 0.146362f, 0.162354f, 0.178711f, 0.195801f, 0.212769f, 0.230103f,
+ 0.247925f, 0.264893f, 0.283203f, 0.300293f, 0.318604f, 0.336426f, 0.354492f, 0.372314f, 0.390137f, 0.408203f, 0.425537f, 0.443848f,
+ 0.461182f, 0.478271f, 0.496094f, 0.513184f, 0.529297f, 0.546387f, 0.563477f, 0.580566f, 0.595703f, 0.611816f, 0.626465f, 0.642090f,
+ 0.658691f, 0.671875f, 0.686523f, 0.702148f, 0.716797f, 0.729980f, 0.744629f, 0.757324f, 0.770020f, 0.783203f, 0.796875f, 0.808105f,
+ 0.820312f, 0.832520f, 0.844727f, 0.855957f, 0.867188f, 0.877930f, 0.937012f, 0.930176f, 0.922852f, 0.916504f, 0.910645f, 0.904785f,
+ 0.005486f, 0.016525f, 0.028030f, 0.039612f, 0.052185f, 0.064636f, 0.077576f, 0.091553f, 0.105347f, 0.119568f, 0.134521f, 0.149536f,
+ 0.164917f, 0.180664f, 0.197388f, 0.213623f, 0.230347f, 0.246826f, 0.264160f, 0.280518f, 0.298584f, 0.315674f, 0.334229f, 0.350830f,
+ 0.369141f, 0.386963f, 0.404053f, 0.422119f, 0.438477f, 0.456299f, 0.474121f, 0.491211f, 0.507812f, 0.524902f, 0.541504f, 0.557617f,
+ 0.574707f, 0.590820f, 0.606934f, 0.622559f, 0.637207f, 0.652832f, 0.668945f, 0.683105f, 0.698730f, 0.711914f, 0.726074f, 0.740723f,
+ 0.753906f, 0.766602f, 0.780273f, 0.792969f, 0.805664f, 0.818848f, 0.830566f, 0.842285f, 0.854492f, 0.866211f, 0.931641f, 0.925781f,
+ 0.918945f, 0.913086f, 0.907227f, 0.900879f, 0.004810f, 0.014847f, 0.025604f, 0.036621f, 0.047577f, 0.059174f, 0.071472f, 0.084106f,
+ 0.096985f, 0.109863f, 0.124146f, 0.137939f, 0.152954f, 0.167358f, 0.182495f, 0.197754f, 0.213745f, 0.230103f, 0.246216f, 0.262939f,
+ 0.279297f, 0.296387f, 0.313477f, 0.329834f, 0.348145f, 0.365479f, 0.382080f, 0.399658f, 0.417480f, 0.434082f, 0.452148f, 0.469238f,
+ 0.486084f, 0.502441f, 0.520020f, 0.536621f, 0.552734f, 0.569336f, 0.585938f, 0.601562f, 0.617676f, 0.632812f, 0.648438f, 0.664062f,
+ 0.679688f, 0.693848f, 0.708008f, 0.722656f, 0.735840f, 0.750488f, 0.765137f, 0.777832f, 0.791016f, 0.803711f, 0.816895f, 0.829102f,
+ 0.841309f, 0.853027f, 0.925781f, 0.921387f, 0.914551f, 0.908203f, 0.903320f, 0.897461f, 0.004494f, 0.013809f, 0.023331f, 0.033264f,
+ 0.043549f, 0.053833f, 0.065369f, 0.076660f, 0.088684f, 0.100708f, 0.113464f, 0.127075f, 0.140381f, 0.154419f, 0.169067f, 0.183472f,
+ 0.198975f, 0.213623f, 0.229370f, 0.245117f, 0.261475f, 0.277832f, 0.294678f, 0.311523f, 0.327148f, 0.344727f, 0.362061f, 0.378418f,
+ 0.395996f, 0.413086f, 0.430176f, 0.447021f, 0.464111f, 0.481689f, 0.498047f, 0.514648f, 0.531738f, 0.547363f, 0.565430f, 0.582031f,
+ 0.597656f, 0.612793f, 0.628418f, 0.644043f, 0.660645f, 0.674805f, 0.689941f, 0.705078f, 0.718750f, 0.734375f, 0.747559f, 0.761719f,
+ 0.775391f, 0.788086f, 0.803223f, 0.814453f, 0.828125f, 0.840332f, 0.919434f, 0.916504f, 0.909668f, 0.904785f, 0.898926f, 0.894043f,
+ 0.004120f, 0.012512f, 0.021423f, 0.030655f, 0.039673f, 0.049500f, 0.059845f, 0.070374f, 0.081543f, 0.093323f, 0.104614f, 0.116577f,
+ 0.129395f, 0.142456f, 0.156250f, 0.169434f, 0.183594f, 0.198364f, 0.213257f, 0.228638f, 0.244141f, 0.259766f, 0.275635f, 0.291748f,
+ 0.308105f, 0.324707f, 0.341309f, 0.359131f, 0.375244f, 0.391846f, 0.408447f, 0.426025f, 0.442871f, 0.459473f, 0.477051f, 0.494141f,
+ 0.510254f, 0.527344f, 0.543457f, 0.560059f, 0.577148f, 0.592773f, 0.608887f, 0.625977f, 0.640625f, 0.656738f, 0.671875f, 0.686523f,
+ 0.702637f, 0.716797f, 0.731445f, 0.746582f, 0.759277f, 0.773926f, 0.787598f, 0.800293f, 0.814453f, 0.827148f, 0.914062f, 0.911133f,
+ 0.905273f, 0.899902f, 0.895508f, 0.890625f, 0.004120f, 0.011566f, 0.019180f, 0.027969f, 0.036255f, 0.045746f, 0.054901f, 0.064941f,
+ 0.074707f, 0.085327f, 0.096436f, 0.107239f, 0.119324f, 0.131470f, 0.144165f, 0.157104f, 0.169922f, 0.183594f, 0.198242f, 0.212769f,
+ 0.227295f, 0.242188f, 0.257568f, 0.273193f, 0.289307f, 0.305420f, 0.321289f, 0.337891f, 0.354492f, 0.371094f, 0.387451f, 0.405029f,
+ 0.421143f, 0.438477f, 0.455322f, 0.472656f, 0.488525f, 0.505859f, 0.521973f, 0.539551f, 0.555664f, 0.572754f, 0.588867f, 0.605469f,
+ 0.621582f, 0.637207f, 0.653320f, 0.668945f, 0.684570f, 0.698242f, 0.714844f, 0.729492f, 0.745117f, 0.758301f, 0.771973f, 0.787109f,
+ 0.800781f, 0.813477f, 0.907715f, 0.905762f, 0.900879f, 0.895508f, 0.890625f, 0.886719f, 0.003464f, 0.010536f, 0.018143f, 0.025604f,
+ 0.033600f, 0.041992f, 0.050659f, 0.059631f, 0.068481f, 0.078552f, 0.088196f, 0.099060f, 0.110107f, 0.121033f, 0.133057f, 0.145020f,
+ 0.157349f, 0.170166f, 0.183838f, 0.197632f, 0.210938f, 0.225464f, 0.241089f, 0.255371f, 0.270508f, 0.286377f, 0.302246f, 0.317871f,
+ 0.334229f, 0.349854f, 0.367188f, 0.383789f, 0.399414f, 0.417236f, 0.433838f, 0.450928f, 0.468018f, 0.484131f, 0.501465f, 0.519043f,
+ 0.535156f, 0.551758f, 0.568359f, 0.585449f, 0.601074f, 0.617676f, 0.634277f, 0.649902f, 0.666016f, 0.681152f, 0.695801f, 0.711914f,
+ 0.727539f, 0.741699f, 0.756836f, 0.770508f, 0.785645f, 0.800293f, 0.901855f, 0.900391f, 0.895996f, 0.891113f, 0.886230f, 0.881836f,
+ 0.003197f, 0.009903f, 0.016525f, 0.023849f, 0.030853f, 0.038605f, 0.046265f, 0.054657f, 0.063232f, 0.072266f, 0.081543f, 0.090881f,
+ 0.100769f, 0.112061f, 0.123047f, 0.134155f, 0.145752f, 0.157471f, 0.170166f, 0.182861f, 0.196289f, 0.210327f, 0.223755f, 0.238525f,
+ 0.253418f, 0.268066f, 0.283203f, 0.299316f, 0.314697f, 0.330811f, 0.346680f, 0.363281f, 0.379639f, 0.396484f, 0.412842f, 0.429443f,
+ 0.446289f, 0.462891f, 0.480225f, 0.497559f, 0.514648f, 0.531250f, 0.547852f, 0.564453f, 0.581055f, 0.598145f, 0.615234f, 0.631836f,
+ 0.646484f, 0.663086f, 0.679199f, 0.694824f, 0.710449f, 0.726074f, 0.740234f, 0.755859f, 0.770508f, 0.784668f, 0.895020f, 0.894531f,
+ 0.890625f, 0.886719f, 0.881836f, 0.877441f, 0.003071f, 0.009163f, 0.015602f, 0.021729f, 0.028412f, 0.035522f, 0.042755f, 0.050598f,
+ 0.057983f, 0.066284f, 0.075317f, 0.083862f, 0.092773f, 0.102905f, 0.113342f, 0.123840f, 0.134399f, 0.145752f, 0.157593f, 0.169556f,
+ 0.182129f, 0.194702f, 0.207886f, 0.222046f, 0.235840f, 0.250977f, 0.265137f, 0.280273f, 0.295898f, 0.311279f, 0.326660f, 0.342773f,
+ 0.359375f, 0.375732f, 0.392090f, 0.409180f, 0.425049f, 0.441895f, 0.459473f, 0.476318f, 0.493652f, 0.510742f, 0.527344f, 0.544434f,
+ 0.561035f, 0.578125f, 0.595215f, 0.611328f, 0.628418f, 0.645020f, 0.661133f, 0.677246f, 0.693359f, 0.708496f, 0.724609f, 0.740723f,
+ 0.755859f, 0.771484f, 0.889160f, 0.889160f, 0.885254f, 0.881348f, 0.876953f, 0.873047f, 0.002748f, 0.008171f, 0.014084f, 0.019638f,
+ 0.026108f, 0.032318f, 0.039154f, 0.045990f, 0.053619f, 0.061066f, 0.068665f, 0.076477f, 0.085632f, 0.094727f, 0.104187f, 0.113831f,
+ 0.123535f, 0.134888f, 0.145508f, 0.157104f, 0.168701f, 0.181030f, 0.193481f, 0.206665f, 0.220093f, 0.233398f, 0.248169f, 0.262695f,
+ 0.277344f, 0.292236f, 0.307617f, 0.322998f, 0.339355f, 0.355469f, 0.371582f, 0.388184f, 0.404541f, 0.420410f, 0.438477f, 0.455322f,
+ 0.472656f, 0.489014f, 0.506348f, 0.523926f, 0.541016f, 0.557617f, 0.575195f, 0.591309f, 0.608887f, 0.625977f, 0.643555f, 0.659180f,
+ 0.674805f, 0.691406f, 0.707520f, 0.724121f, 0.739746f, 0.755371f, 0.882812f, 0.883789f, 0.879883f, 0.875977f, 0.872559f, 0.868652f,
+ 0.002491f, 0.007809f, 0.012764f, 0.018448f, 0.024094f, 0.029861f, 0.036102f, 0.042572f, 0.049500f, 0.056091f, 0.063293f, 0.070984f,
+ 0.079285f, 0.087036f, 0.095825f, 0.104858f, 0.114441f, 0.124084f, 0.133789f, 0.144653f, 0.156250f, 0.167480f, 0.179199f, 0.191650f,
+ 0.204102f, 0.217896f, 0.231445f, 0.245239f, 0.259521f, 0.274170f, 0.289307f, 0.304199f, 0.319580f, 0.334961f, 0.351074f, 0.367676f,
+ 0.384277f, 0.400635f, 0.417480f, 0.434570f, 0.451660f, 0.468994f, 0.485352f, 0.502441f, 0.520508f, 0.537109f, 0.554688f, 0.571777f,
+ 0.588867f, 0.605957f, 0.623047f, 0.639648f, 0.656738f, 0.673828f, 0.690430f, 0.708008f, 0.723633f, 0.739746f, 0.874023f, 0.876953f,
+ 0.874023f, 0.871582f, 0.867188f, 0.862793f, 0.002279f, 0.007130f, 0.012291f, 0.016922f, 0.022171f, 0.027847f, 0.033325f, 0.039185f,
+ 0.045349f, 0.051849f, 0.058411f, 0.064880f, 0.072144f, 0.080017f, 0.087891f, 0.096313f, 0.105103f, 0.114197f, 0.123779f, 0.134155f,
+ 0.144043f, 0.155151f, 0.166016f, 0.177246f, 0.189697f, 0.202271f, 0.214722f, 0.228271f, 0.242310f, 0.256592f, 0.270752f, 0.285400f,
+ 0.300537f, 0.315674f, 0.331543f, 0.347656f, 0.363525f, 0.379639f, 0.396729f, 0.414307f, 0.430908f, 0.447754f, 0.465088f, 0.482178f,
+ 0.499512f, 0.517090f, 0.533203f, 0.552246f, 0.568848f, 0.586426f, 0.603516f, 0.621582f, 0.639648f, 0.656250f, 0.673828f, 0.690918f,
+ 0.707520f, 0.724121f, 0.867676f, 0.870605f, 0.868164f, 0.865723f, 0.861328f, 0.857910f, 0.002220f, 0.006565f, 0.011238f, 0.015961f,
+ 0.020401f, 0.025558f, 0.030853f, 0.036133f, 0.041199f, 0.047180f, 0.053436f, 0.059723f, 0.066162f, 0.073853f, 0.080688f, 0.088440f,
+ 0.096436f, 0.105042f, 0.114319f, 0.123047f, 0.132446f, 0.142822f, 0.153198f, 0.164062f, 0.175659f, 0.187378f, 0.199463f, 0.212402f,
+ 0.225464f, 0.239014f, 0.252686f, 0.266846f, 0.281494f, 0.296631f, 0.312500f, 0.328369f, 0.343750f, 0.359863f, 0.376221f, 0.393066f,
+ 0.409668f, 0.426514f, 0.444336f, 0.461670f, 0.478760f, 0.496826f, 0.513672f, 0.532227f, 0.549316f, 0.567383f, 0.584961f, 0.602051f,
+ 0.620605f, 0.637207f, 0.655273f, 0.672363f, 0.689941f, 0.708008f, 0.860840f, 0.864746f, 0.862793f, 0.859375f, 0.855957f, 0.853027f,
+ 0.002190f, 0.005993f, 0.010117f, 0.014420f, 0.018738f, 0.023361f, 0.028015f, 0.033142f, 0.037781f, 0.043732f, 0.048920f, 0.054840f,
+ 0.061218f, 0.067810f, 0.074219f, 0.081299f, 0.088562f, 0.096130f, 0.104614f, 0.113098f, 0.122253f, 0.131714f, 0.141113f, 0.151245f,
+ 0.162109f, 0.173462f, 0.184692f, 0.196899f, 0.209473f, 0.222534f, 0.236206f, 0.249634f, 0.263672f, 0.277588f, 0.293213f, 0.308350f,
+ 0.323975f, 0.339844f, 0.355957f, 0.372070f, 0.389404f, 0.405762f, 0.422852f, 0.439941f, 0.458008f, 0.475098f, 0.492920f, 0.510742f,
+ 0.528320f, 0.546875f, 0.564453f, 0.583496f, 0.601074f, 0.619141f, 0.636719f, 0.654785f, 0.672852f, 0.691406f, 0.852539f, 0.858398f,
+ 0.856445f, 0.853516f, 0.850586f, 0.847656f, 0.001787f, 0.005753f, 0.009300f, 0.013611f, 0.017410f, 0.021576f, 0.025665f, 0.030533f,
+ 0.035126f, 0.040039f, 0.044952f, 0.050446f, 0.055817f, 0.061890f, 0.068054f, 0.074707f, 0.081482f, 0.088501f, 0.095764f, 0.103943f,
+ 0.112183f, 0.120850f, 0.130249f, 0.139526f, 0.149658f, 0.160400f, 0.171021f, 0.182007f, 0.194336f, 0.206421f, 0.219360f, 0.232666f,
+ 0.245850f, 0.260010f, 0.274170f, 0.289307f, 0.304443f, 0.319580f, 0.335693f, 0.352295f, 0.369141f, 0.385498f, 0.402344f, 0.419189f,
+ 0.437012f, 0.454346f, 0.472412f, 0.490234f, 0.507812f, 0.525879f, 0.545410f, 0.562500f, 0.581055f, 0.600098f, 0.618164f, 0.636719f,
+ 0.655273f, 0.674316f, 0.845703f, 0.852051f, 0.849609f, 0.847168f, 0.845215f, 0.841309f, 0.001766f, 0.005241f, 0.008881f, 0.012024f,
+ 0.016129f, 0.020233f, 0.024124f, 0.027664f, 0.032135f, 0.036835f, 0.041321f, 0.046173f, 0.051392f, 0.056946f, 0.062225f, 0.068604f,
+ 0.074524f, 0.080933f, 0.088135f, 0.095398f, 0.103210f, 0.110779f, 0.119263f, 0.128296f, 0.137695f, 0.147217f, 0.157349f, 0.168091f,
+ 0.179688f, 0.191284f, 0.203613f, 0.215942f, 0.228882f, 0.242554f, 0.255859f, 0.270508f, 0.285400f, 0.300537f, 0.316406f, 0.331787f,
+ 0.348877f, 0.364746f, 0.382080f, 0.398682f, 0.415771f, 0.434082f, 0.451416f, 0.469482f, 0.487793f, 0.505859f, 0.524414f, 0.542969f,
+ 0.562012f, 0.580566f, 0.598145f, 0.618652f, 0.637695f, 0.657227f, 0.837891f, 0.844727f, 0.843750f, 0.841309f, 0.838379f, 0.836426f,
+ 0.001598f, 0.004887f, 0.008217f, 0.011497f, 0.014786f, 0.018326f, 0.021652f, 0.025513f, 0.029541f, 0.033813f, 0.038086f, 0.042236f,
+ 0.046844f, 0.052032f, 0.057251f, 0.062622f, 0.068237f, 0.074280f, 0.080505f, 0.086975f, 0.094116f, 0.101074f, 0.109314f, 0.117554f,
+ 0.126587f, 0.135254f, 0.144775f, 0.155029f, 0.165405f, 0.176392f, 0.187744f, 0.199829f, 0.212646f, 0.224976f, 0.238647f, 0.252441f,
+ 0.267090f, 0.281738f, 0.296631f, 0.312256f, 0.328369f, 0.344971f, 0.361328f, 0.377686f, 0.395264f, 0.412842f, 0.430908f, 0.448730f,
+ 0.467041f, 0.485596f, 0.503906f, 0.522461f, 0.541504f, 0.561523f, 0.580078f, 0.599121f, 0.618164f, 0.639648f, 0.828613f, 0.837891f,
+ 0.836914f, 0.834473f, 0.833008f, 0.830566f, 0.001709f, 0.004494f, 0.007416f, 0.010628f, 0.013680f, 0.016785f, 0.020203f, 0.023712f,
+ 0.027435f, 0.031006f, 0.034424f, 0.038635f, 0.043182f, 0.047668f, 0.052307f, 0.057159f, 0.062042f, 0.067749f, 0.073730f, 0.079956f,
+ 0.086182f, 0.092773f, 0.100159f, 0.107727f, 0.115479f, 0.123962f, 0.132935f, 0.142578f, 0.151978f, 0.162476f, 0.173340f, 0.184570f,
+ 0.196411f, 0.208740f, 0.221436f, 0.235229f, 0.248779f, 0.262939f, 0.277832f, 0.293213f, 0.308105f, 0.324219f, 0.341309f, 0.357178f,
+ 0.374756f, 0.391846f, 0.409424f, 0.427490f, 0.446533f, 0.464844f, 0.483643f, 0.501953f, 0.521484f, 0.541504f, 0.561035f, 0.579590f,
+ 0.599609f, 0.620605f, 0.821289f, 0.830566f, 0.830078f, 0.828125f, 0.825684f, 0.823242f, 0.001367f, 0.004105f, 0.007023f, 0.009552f,
+ 0.012611f, 0.015289f, 0.018341f, 0.021652f, 0.024857f, 0.027878f, 0.031769f, 0.035614f, 0.039276f, 0.043610f, 0.047333f, 0.052155f,
+ 0.056549f, 0.061401f, 0.066895f, 0.072449f, 0.078613f, 0.084778f, 0.091309f, 0.098083f, 0.105774f, 0.113281f, 0.121399f, 0.130371f,
+ 0.139648f, 0.148926f, 0.159546f, 0.169922f, 0.180908f, 0.192749f, 0.204834f, 0.217651f, 0.231567f, 0.244385f, 0.259277f, 0.273926f,
+ 0.289307f, 0.304688f, 0.320557f, 0.336914f, 0.354248f, 0.371338f, 0.388184f, 0.406982f, 0.424316f, 0.443115f, 0.462646f, 0.481445f,
+ 0.501465f, 0.520508f, 0.541016f, 0.559570f, 0.580078f, 0.601074f, 0.812988f, 0.823242f, 0.823242f, 0.821289f, 0.819824f, 0.817383f,
+ 0.001398f, 0.003883f, 0.006351f, 0.008911f, 0.011559f, 0.014343f, 0.017212f, 0.020035f, 0.022797f, 0.026062f, 0.028793f, 0.031891f,
+ 0.035858f, 0.039368f, 0.043213f, 0.047607f, 0.051483f, 0.056030f, 0.060883f, 0.065979f, 0.071350f, 0.076843f, 0.083130f, 0.089172f,
+ 0.096069f, 0.103333f, 0.111023f, 0.119019f, 0.127319f, 0.136719f, 0.145996f, 0.156128f, 0.166138f, 0.177368f, 0.189453f, 0.201416f,
+ 0.213745f, 0.227295f, 0.240601f, 0.255371f, 0.269287f, 0.285400f, 0.301270f, 0.317139f, 0.333740f, 0.350586f, 0.367920f, 0.385986f,
+ 0.404297f, 0.422852f, 0.442383f, 0.460938f, 0.479980f, 0.500488f, 0.520508f, 0.541016f, 0.560547f, 0.582520f, 0.803711f, 0.814941f,
+ 0.815430f, 0.814453f, 0.812500f, 0.810547f, 0.001259f, 0.003464f, 0.006332f, 0.008286f, 0.010384f, 0.013000f, 0.015587f, 0.018234f,
+ 0.021027f, 0.023422f, 0.026566f, 0.029480f, 0.032379f, 0.035919f, 0.039215f, 0.043060f, 0.046997f, 0.050995f, 0.055267f, 0.059998f,
+ 0.065002f, 0.069946f, 0.075317f, 0.081299f, 0.087280f, 0.094116f, 0.101135f, 0.108276f, 0.116150f, 0.124695f, 0.133545f, 0.142700f,
+ 0.152222f, 0.162720f, 0.173950f, 0.185303f, 0.197754f, 0.210205f, 0.223022f, 0.237061f, 0.250732f, 0.265869f, 0.281250f, 0.297119f,
+ 0.313477f, 0.330322f, 0.347656f, 0.364746f, 0.383301f, 0.401367f, 0.420898f, 0.440186f, 0.459229f, 0.479736f, 0.499512f, 0.520996f,
+ 0.541016f, 0.562988f, 0.794434f, 0.807129f, 0.807617f, 0.807129f, 0.805176f, 0.803711f, 0.001070f, 0.003237f, 0.005432f, 0.007359f,
+ 0.009857f, 0.012337f, 0.014191f, 0.016586f, 0.019257f, 0.021561f, 0.024094f, 0.026901f, 0.029724f, 0.032745f, 0.035675f, 0.039368f,
+ 0.042572f, 0.045990f, 0.050354f, 0.054535f, 0.058746f, 0.063232f, 0.068420f, 0.073608f, 0.079529f, 0.085266f, 0.091370f, 0.098083f,
+ 0.105835f, 0.113159f, 0.121094f, 0.129639f, 0.139038f, 0.148926f, 0.159058f, 0.169678f, 0.181274f, 0.193481f, 0.205811f, 0.219482f,
+ 0.233032f, 0.247192f, 0.262207f, 0.277100f, 0.293213f, 0.309814f, 0.326660f, 0.344238f, 0.361816f, 0.380615f, 0.398926f, 0.418945f,
+ 0.438477f, 0.458008f, 0.479004f, 0.499512f, 0.520996f, 0.543945f, 0.784668f, 0.798828f, 0.800293f, 0.799805f, 0.797852f, 0.796875f,
+ 0.001074f, 0.002916f, 0.004955f, 0.007149f, 0.009033f, 0.011055f, 0.013268f, 0.015495f, 0.017365f, 0.019485f, 0.022095f, 0.024002f,
+ 0.026688f, 0.029633f, 0.032593f, 0.035370f, 0.038361f, 0.041870f, 0.045319f, 0.049225f, 0.052948f, 0.057068f, 0.061676f, 0.066345f,
+ 0.071167f, 0.076782f, 0.082581f, 0.088867f, 0.095886f, 0.102539f, 0.109802f, 0.118042f, 0.126709f, 0.135132f, 0.144897f, 0.155151f,
+ 0.165771f, 0.177368f, 0.189209f, 0.201904f, 0.215210f, 0.229370f, 0.242798f, 0.258057f, 0.274170f, 0.290039f, 0.306885f, 0.323242f,
+ 0.341309f, 0.359375f, 0.378418f, 0.397461f, 0.416260f, 0.437500f, 0.457031f, 0.479004f, 0.501465f, 0.522461f, 0.775391f, 0.790527f,
+ 0.791992f, 0.791504f, 0.791016f, 0.789551f, 0.000837f, 0.002916f, 0.004738f, 0.006477f, 0.008575f, 0.010170f, 0.012161f, 0.014023f,
+ 0.015808f, 0.017792f, 0.020111f, 0.022064f, 0.024414f, 0.026794f, 0.029251f, 0.032074f, 0.034698f, 0.037598f, 0.040741f, 0.043915f,
+ 0.047577f, 0.051361f, 0.055389f, 0.059692f, 0.064209f, 0.068787f, 0.074585f, 0.079712f, 0.085632f, 0.092346f, 0.099487f, 0.106323f,
+ 0.114929f, 0.122925f, 0.131958f, 0.141235f, 0.151123f, 0.161865f, 0.172974f, 0.184937f, 0.197632f, 0.210693f, 0.224854f, 0.239136f,
+ 0.254395f, 0.269531f, 0.285889f, 0.302979f, 0.320557f, 0.338623f, 0.356689f, 0.375977f, 0.395752f, 0.415527f, 0.436523f, 0.458252f,
+ 0.479248f, 0.501465f, 0.765137f, 0.781738f, 0.783691f, 0.784180f, 0.783203f, 0.781250f, 0.000854f, 0.002817f, 0.004089f, 0.005684f,
+ 0.007675f, 0.009277f, 0.010864f, 0.012413f, 0.014427f, 0.016235f, 0.017838f, 0.019913f, 0.021805f, 0.023987f, 0.026276f, 0.028915f,
+ 0.030960f, 0.033875f, 0.036652f, 0.039551f, 0.042816f, 0.045837f, 0.049591f, 0.053589f, 0.057526f, 0.061829f, 0.066650f, 0.071655f,
+ 0.077393f, 0.083008f, 0.088989f, 0.096008f, 0.103210f, 0.110657f, 0.119141f, 0.127930f, 0.137085f, 0.146973f, 0.157593f, 0.169312f,
+ 0.181274f, 0.193481f, 0.207031f, 0.220581f, 0.235229f, 0.250732f, 0.266357f, 0.282227f, 0.299805f, 0.317627f, 0.335449f, 0.354736f,
+ 0.374268f, 0.394531f, 0.415527f, 0.436279f, 0.458252f, 0.481689f, 0.754883f, 0.773438f, 0.775391f, 0.775879f, 0.774902f, 0.773926f,
+ 0.000852f, 0.002520f, 0.003937f, 0.005527f, 0.006836f, 0.008408f, 0.009773f, 0.011620f, 0.013039f, 0.014687f, 0.016327f, 0.017944f,
+ 0.019760f, 0.021774f, 0.023697f, 0.025894f, 0.027969f, 0.030121f, 0.032501f, 0.035370f, 0.038208f, 0.041046f, 0.044098f, 0.047791f,
+ 0.051453f, 0.055176f, 0.059570f, 0.064026f, 0.068787f, 0.074158f, 0.079834f, 0.085938f, 0.092590f, 0.099304f, 0.106873f, 0.114990f,
+ 0.124023f, 0.133301f, 0.143066f, 0.153687f, 0.164551f, 0.176392f, 0.189209f, 0.202637f, 0.216553f, 0.231323f, 0.246704f, 0.262451f,
+ 0.279297f, 0.296387f, 0.314697f, 0.333496f, 0.353516f, 0.373047f, 0.394775f, 0.415039f, 0.437500f, 0.460449f, 0.745117f, 0.763672f,
+ 0.766602f, 0.767090f, 0.767090f, 0.765625f, 0.000762f, 0.002342f, 0.003563f, 0.004787f, 0.006447f, 0.007648f, 0.009193f, 0.010353f,
+ 0.012016f, 0.013138f, 0.014557f, 0.016312f, 0.017929f, 0.019470f, 0.021103f, 0.023056f, 0.024918f, 0.026886f, 0.029099f, 0.031586f,
+ 0.034058f, 0.036499f, 0.039307f, 0.042450f, 0.045685f, 0.049072f, 0.052826f, 0.056915f, 0.061096f, 0.065918f, 0.070984f, 0.076538f,
+ 0.082520f, 0.088928f, 0.095520f, 0.102905f, 0.111206f, 0.119629f, 0.128662f, 0.138184f, 0.148682f, 0.160156f, 0.171997f, 0.184937f,
+ 0.198364f, 0.212524f, 0.227173f, 0.243042f, 0.259277f, 0.276611f, 0.294189f, 0.312500f, 0.331055f, 0.350830f, 0.372070f, 0.392334f,
+ 0.415771f, 0.438232f, 0.734375f, 0.754395f, 0.758789f, 0.758789f, 0.758789f, 0.757812f, 0.000848f, 0.002024f, 0.003553f, 0.004646f,
+ 0.005726f, 0.007050f, 0.008362f, 0.009438f, 0.010536f, 0.011810f, 0.013123f, 0.014481f, 0.015778f, 0.017242f, 0.018753f, 0.020447f,
+ 0.022278f, 0.023819f, 0.025940f, 0.027771f, 0.029999f, 0.032410f, 0.034851f, 0.037354f, 0.040375f, 0.043610f, 0.046631f, 0.050354f,
+ 0.054108f, 0.058563f, 0.062805f, 0.067871f, 0.073242f, 0.078796f, 0.085083f, 0.091797f, 0.098816f, 0.106689f, 0.115540f, 0.124207f,
+ 0.134155f, 0.144409f, 0.155762f, 0.167725f, 0.180664f, 0.193848f, 0.208618f, 0.223389f, 0.239746f, 0.256104f, 0.273438f, 0.291260f,
+ 0.310059f, 0.330078f, 0.349854f, 0.370850f, 0.393555f, 0.416992f, 0.724121f, 0.744629f, 0.748535f, 0.750000f, 0.749512f, 0.749512f,
+ 0.000736f, 0.001780f, 0.002937f, 0.004314f, 0.005211f, 0.006214f, 0.007423f, 0.008537f, 0.009392f, 0.010773f, 0.011726f, 0.012970f,
+ 0.014183f, 0.015373f, 0.016724f, 0.017990f, 0.019730f, 0.021194f, 0.022644f, 0.024368f, 0.026443f, 0.028610f, 0.030685f, 0.032898f,
+ 0.035583f, 0.038300f, 0.041351f, 0.044556f, 0.047638f, 0.051422f, 0.055359f, 0.059875f, 0.064392f, 0.069580f, 0.075195f, 0.080872f,
+ 0.087646f, 0.094849f, 0.102173f, 0.110596f, 0.119690f, 0.129761f, 0.139893f, 0.151367f, 0.163452f, 0.176147f, 0.190063f, 0.204590f,
+ 0.219238f, 0.235718f, 0.252441f, 0.270264f, 0.289062f, 0.307861f, 0.328613f, 0.350098f, 0.372314f, 0.395020f, 0.712402f, 0.734863f,
+ 0.739746f, 0.740723f, 0.740723f, 0.740234f, 0.000589f, 0.001616f, 0.002674f, 0.003841f, 0.004940f, 0.005676f, 0.006554f, 0.007442f,
+ 0.008812f, 0.009537f, 0.010277f, 0.011528f, 0.012634f, 0.013527f, 0.014671f, 0.016037f, 0.017136f, 0.018631f, 0.019943f, 0.021530f,
+ 0.023071f, 0.025146f, 0.026825f, 0.029037f, 0.030853f, 0.033447f, 0.035736f, 0.038849f, 0.041656f, 0.044922f, 0.048462f, 0.052277f,
+ 0.056519f, 0.061127f, 0.065796f, 0.071411f, 0.077148f, 0.083435f, 0.090393f, 0.097900f, 0.106079f, 0.115356f, 0.125122f, 0.135132f,
+ 0.146729f, 0.158936f, 0.171509f, 0.185059f, 0.200439f, 0.215576f, 0.232056f, 0.249756f, 0.267822f, 0.286621f, 0.306885f, 0.328125f,
+ 0.349854f, 0.373291f, 0.701172f, 0.725586f, 0.729980f, 0.730957f, 0.731934f, 0.730957f, 0.000547f, 0.001666f, 0.002367f, 0.003559f,
+ 0.004238f, 0.005028f, 0.005852f, 0.006859f, 0.007755f, 0.008530f, 0.009163f, 0.010056f, 0.010956f, 0.011978f, 0.013062f, 0.014076f,
+ 0.015053f, 0.016251f, 0.017471f, 0.018921f, 0.020233f, 0.021774f, 0.023315f, 0.025162f, 0.026871f, 0.029007f, 0.031204f, 0.033661f,
+ 0.036102f, 0.039062f, 0.042053f, 0.045380f, 0.048859f, 0.053040f, 0.057343f, 0.062225f, 0.067261f, 0.073120f, 0.079407f, 0.086243f,
+ 0.093567f, 0.101868f, 0.110596f, 0.120239f, 0.130859f, 0.141968f, 0.154053f, 0.167358f, 0.181274f, 0.196045f, 0.212158f, 0.229248f,
+ 0.247192f, 0.265381f, 0.285400f, 0.305664f, 0.327637f, 0.350586f, 0.689453f, 0.715820f, 0.720215f, 0.722168f, 0.722168f, 0.722168f,
+ 0.000492f, 0.001634f, 0.002342f, 0.003111f, 0.003866f, 0.004574f, 0.005417f, 0.005928f, 0.006588f, 0.007393f, 0.008041f, 0.008873f,
+ 0.009689f, 0.010391f, 0.011375f, 0.012146f, 0.013100f, 0.014183f, 0.015274f, 0.016479f, 0.017456f, 0.018768f, 0.020157f, 0.021606f,
+ 0.023300f, 0.024933f, 0.026855f, 0.028885f, 0.031143f, 0.033417f, 0.036133f, 0.039032f, 0.042236f, 0.045776f, 0.049713f, 0.053680f,
+ 0.058228f, 0.063232f, 0.069092f, 0.074829f, 0.081482f, 0.089050f, 0.096924f, 0.105591f, 0.115417f, 0.126221f, 0.137329f, 0.149658f,
+ 0.162964f, 0.176880f, 0.192505f, 0.208740f, 0.226318f, 0.244873f, 0.263428f, 0.283936f, 0.306396f, 0.329346f, 0.676270f, 0.705078f,
+ 0.709961f, 0.711914f, 0.712891f, 0.711914f, 0.000506f, 0.001342f, 0.002157f, 0.002813f, 0.003353f, 0.004105f, 0.004658f, 0.005344f,
+ 0.005871f, 0.006538f, 0.007050f, 0.007751f, 0.008247f, 0.009109f, 0.009865f, 0.010559f, 0.011269f, 0.012169f, 0.013290f, 0.014191f,
+ 0.015015f, 0.016312f, 0.017395f, 0.018570f, 0.019989f, 0.021439f, 0.023102f, 0.024536f, 0.026535f, 0.028702f, 0.030899f, 0.033356f,
+ 0.035980f, 0.039093f, 0.042328f, 0.046051f, 0.049927f, 0.054199f, 0.059052f, 0.064575f, 0.070496f, 0.076782f, 0.084412f, 0.092285f,
+ 0.100708f, 0.110779f, 0.121399f, 0.132690f, 0.145508f, 0.158813f, 0.173584f, 0.189453f, 0.205688f, 0.223755f, 0.242554f, 0.263184f,
+ 0.284180f, 0.306641f, 0.664551f, 0.693848f, 0.699707f, 0.702148f, 0.702637f, 0.703125f, 0.000500f, 0.001122f, 0.001810f, 0.002363f,
+ 0.002987f, 0.003576f, 0.004158f, 0.004620f, 0.005032f, 0.005627f, 0.006161f, 0.006721f, 0.007179f, 0.007790f, 0.008385f, 0.009163f,
+ 0.009758f, 0.010536f, 0.011284f, 0.011986f, 0.012878f, 0.013710f, 0.014725f, 0.015823f, 0.016937f, 0.018326f, 0.019547f, 0.020874f,
+ 0.022522f, 0.024399f, 0.026077f, 0.028427f, 0.030609f, 0.032990f, 0.035736f, 0.038788f, 0.042236f, 0.045990f, 0.050354f, 0.054901f,
+ 0.059967f, 0.065918f, 0.072205f, 0.079468f, 0.087219f, 0.096252f, 0.105713f, 0.116272f, 0.128174f, 0.140747f, 0.154419f, 0.169556f,
+ 0.186279f, 0.203125f, 0.221313f, 0.240601f, 0.261719f, 0.284424f, 0.652344f, 0.683105f, 0.688965f, 0.691406f, 0.692383f, 0.693359f,
+ 0.000482f, 0.001184f, 0.001604f, 0.002171f, 0.002562f, 0.003029f, 0.003656f, 0.003941f, 0.004410f, 0.004948f, 0.005325f, 0.005577f,
+ 0.006157f, 0.006702f, 0.007172f, 0.007751f, 0.008331f, 0.008904f, 0.009514f, 0.010063f, 0.010925f, 0.011719f, 0.012306f, 0.013321f,
+ 0.014275f, 0.015465f, 0.016510f, 0.017593f, 0.018845f, 0.020401f, 0.022095f, 0.023682f, 0.025513f, 0.027679f, 0.029968f, 0.032593f,
+ 0.035461f, 0.038757f, 0.042175f, 0.046326f, 0.050873f, 0.055939f, 0.061462f, 0.067444f, 0.074402f, 0.082520f, 0.091125f, 0.100830f,
+ 0.111572f, 0.123413f, 0.136719f, 0.150513f, 0.165894f, 0.182251f, 0.200684f, 0.219727f, 0.240234f, 0.261963f, 0.640137f, 0.671387f,
+ 0.679199f, 0.680664f, 0.682617f, 0.683105f, 0.000501f, 0.000919f, 0.001424f, 0.001853f, 0.002266f, 0.002789f, 0.002998f, 0.003397f,
+ 0.003902f, 0.004192f, 0.004417f, 0.004974f, 0.005207f, 0.005676f, 0.006134f, 0.006527f, 0.007179f, 0.007465f, 0.008018f, 0.008537f,
+ 0.009178f, 0.009888f, 0.010544f, 0.011093f, 0.011986f, 0.012794f, 0.013664f, 0.014717f, 0.015747f, 0.016983f, 0.018127f, 0.019470f,
+ 0.021103f, 0.022919f, 0.024826f, 0.026962f, 0.029358f, 0.031769f, 0.035065f, 0.038239f, 0.042297f, 0.046570f, 0.051422f, 0.056671f,
+ 0.062805f, 0.069763f, 0.077698f, 0.086182f, 0.095825f, 0.106812f, 0.119080f, 0.132568f, 0.147217f, 0.162598f, 0.180176f, 0.198730f,
+ 0.218628f, 0.241211f, 0.627441f, 0.660156f, 0.668457f, 0.669922f, 0.672363f, 0.671875f, 0.000235f, 0.001120f, 0.001356f, 0.001651f,
+ 0.002117f, 0.002441f, 0.002678f, 0.002993f, 0.003244f, 0.003519f, 0.003876f, 0.004086f, 0.004505f, 0.004787f, 0.005085f, 0.005604f,
+ 0.005985f, 0.006271f, 0.006783f, 0.007145f, 0.007679f, 0.008217f, 0.008728f, 0.009277f, 0.009956f, 0.010605f, 0.011490f, 0.012062f,
+ 0.013084f, 0.013962f, 0.014984f, 0.016113f, 0.017395f, 0.018829f, 0.020416f, 0.022125f, 0.023972f, 0.025955f, 0.028625f, 0.031616f,
+ 0.034515f, 0.038147f, 0.042114f, 0.046783f, 0.052094f, 0.058075f, 0.065002f, 0.072510f, 0.081604f, 0.091125f, 0.102539f, 0.114807f,
+ 0.128662f, 0.143921f, 0.160034f, 0.178467f, 0.198364f, 0.218750f, 0.613281f, 0.648926f, 0.657227f, 0.659668f, 0.661621f, 0.661621f,
+ 0.000382f, 0.000704f, 0.001099f, 0.001557f, 0.001774f, 0.001976f, 0.002132f, 0.002575f, 0.002634f, 0.002916f, 0.003103f, 0.003494f,
+ 0.003754f, 0.003956f, 0.004269f, 0.004684f, 0.004902f, 0.005234f, 0.005569f, 0.005890f, 0.006416f, 0.006786f, 0.007160f, 0.007645f,
+ 0.008118f, 0.008781f, 0.009346f, 0.010025f, 0.010658f, 0.011475f, 0.012230f, 0.013016f, 0.014122f, 0.015251f, 0.016342f, 0.017807f,
+ 0.019424f, 0.021103f, 0.023026f, 0.025436f, 0.027817f, 0.030914f, 0.034210f, 0.037750f, 0.042450f, 0.047455f, 0.053101f, 0.059998f,
+ 0.067688f, 0.076660f, 0.086670f, 0.097961f, 0.110779f, 0.125366f, 0.140747f, 0.158081f, 0.176880f, 0.197632f, 0.600098f, 0.637207f,
+ 0.644531f, 0.647949f, 0.649414f, 0.651855f, 0.000182f, 0.000738f, 0.000942f, 0.001220f, 0.001469f, 0.001634f, 0.001820f, 0.002005f,
+ 0.002291f, 0.002441f, 0.002636f, 0.002832f, 0.003019f, 0.003242f, 0.003502f, 0.003824f, 0.004017f, 0.004333f, 0.004570f, 0.004883f,
+ 0.005173f, 0.005615f, 0.005909f, 0.006317f, 0.006649f, 0.007160f, 0.007656f, 0.008156f, 0.008583f, 0.009209f, 0.009857f, 0.010696f,
+ 0.011322f, 0.012367f, 0.013229f, 0.014259f, 0.015686f, 0.016815f, 0.018402f, 0.020126f, 0.022095f, 0.024414f, 0.027176f, 0.030273f,
+ 0.033722f, 0.038086f, 0.042969f, 0.048645f, 0.055237f, 0.063171f, 0.071960f, 0.082031f, 0.093994f, 0.107300f, 0.122131f, 0.138550f,
+ 0.156494f, 0.177002f, 0.586426f, 0.625488f, 0.633789f, 0.637207f, 0.638672f, 0.639648f, 0.000199f, 0.000534f, 0.000745f, 0.000995f,
+ 0.001190f, 0.001387f, 0.001516f, 0.001691f, 0.001790f, 0.001941f, 0.002214f, 0.002346f, 0.002449f, 0.002686f, 0.002832f, 0.003042f,
+ 0.003304f, 0.003531f, 0.003662f, 0.003952f, 0.004181f, 0.004517f, 0.004704f, 0.005074f, 0.005352f, 0.005718f, 0.006096f, 0.006481f,
+ 0.006947f, 0.007454f, 0.007988f, 0.008484f, 0.009140f, 0.009804f, 0.010475f, 0.011307f, 0.012299f, 0.013268f, 0.014511f, 0.015823f,
+ 0.017410f, 0.018936f, 0.021225f, 0.023621f, 0.026367f, 0.029770f, 0.033661f, 0.038452f, 0.044067f, 0.050812f, 0.058411f, 0.067444f,
+ 0.077942f, 0.090149f, 0.104187f, 0.119812f, 0.137085f, 0.156372f, 0.572754f, 0.613770f, 0.621582f, 0.625977f, 0.627441f, 0.628906f,
+ 0.000165f, 0.000486f, 0.000618f, 0.000880f, 0.001063f, 0.001140f, 0.001258f, 0.001464f, 0.001498f, 0.001561f, 0.001707f, 0.001899f,
+ 0.001976f, 0.002171f, 0.002285f, 0.002474f, 0.002571f, 0.002764f, 0.002968f, 0.003170f, 0.003389f, 0.003580f, 0.003822f, 0.004036f,
+ 0.004269f, 0.004505f, 0.004738f, 0.005157f, 0.005474f, 0.005821f, 0.006279f, 0.006649f, 0.007107f, 0.007610f, 0.008240f, 0.008835f,
+ 0.009598f, 0.010361f, 0.011276f, 0.012299f, 0.013466f, 0.014740f, 0.016251f, 0.018021f, 0.020294f, 0.022797f, 0.025833f, 0.029739f,
+ 0.034058f, 0.039612f, 0.046021f, 0.053833f, 0.063110f, 0.074158f, 0.086914f, 0.101562f, 0.118164f, 0.136841f, 0.558594f, 0.601074f,
+ 0.608887f, 0.613281f, 0.615234f, 0.617188f, 0.000096f, 0.000348f, 0.000585f, 0.000707f, 0.000837f, 0.000866f, 0.000972f, 0.001095f,
+ 0.001198f, 0.001309f, 0.001355f, 0.001417f, 0.001615f, 0.001740f, 0.001863f, 0.001880f, 0.002048f, 0.002159f, 0.002380f, 0.002487f,
+ 0.002613f, 0.002777f, 0.003000f, 0.003143f, 0.003353f, 0.003521f, 0.003748f, 0.003963f, 0.004265f, 0.004490f, 0.004776f, 0.005093f,
+ 0.005577f, 0.005966f, 0.006321f, 0.006828f, 0.007320f, 0.007904f, 0.008575f, 0.009392f, 0.010231f, 0.011276f, 0.012321f, 0.013832f,
+ 0.015343f, 0.017242f, 0.019501f, 0.022247f, 0.025696f, 0.029922f, 0.035187f, 0.041779f, 0.049683f, 0.059387f, 0.070801f, 0.084106f,
+ 0.100037f, 0.117798f, 0.544434f, 0.588867f, 0.597656f, 0.602539f, 0.604492f, 0.605469f, 0.000123f, 0.000248f, 0.000443f, 0.000625f,
+ 0.000663f, 0.000733f, 0.000843f, 0.000780f, 0.000921f, 0.000986f, 0.001081f, 0.001178f, 0.001254f, 0.001348f, 0.001364f, 0.001515f,
+ 0.001565f, 0.001705f, 0.001824f, 0.001870f, 0.002066f, 0.002155f, 0.002274f, 0.002422f, 0.002525f, 0.002695f, 0.002863f, 0.003038f,
+ 0.003271f, 0.003441f, 0.003736f, 0.003901f, 0.004112f, 0.004478f, 0.004719f, 0.005093f, 0.005482f, 0.005913f, 0.006413f, 0.007019f,
+ 0.007626f, 0.008408f, 0.009201f, 0.010201f, 0.011436f, 0.012749f, 0.014389f, 0.016373f, 0.018906f, 0.022034f, 0.025909f, 0.031082f,
+ 0.037628f, 0.045715f, 0.055939f, 0.068176f, 0.082764f, 0.099365f, 0.529785f, 0.574707f, 0.584961f, 0.589844f, 0.591797f, 0.593750f,
+ 0.000210f, 0.000212f, 0.000365f, 0.000494f, 0.000438f, 0.000597f, 0.000538f, 0.000623f, 0.000638f, 0.000736f, 0.000866f, 0.000882f,
+ 0.000954f, 0.001040f, 0.001070f, 0.001086f, 0.001220f, 0.001274f, 0.001341f, 0.001457f, 0.001513f, 0.001598f, 0.001697f, 0.001781f,
+ 0.001898f, 0.001970f, 0.002131f, 0.002241f, 0.002401f, 0.002645f, 0.002783f, 0.002892f, 0.003120f, 0.003347f, 0.003508f, 0.003757f,
+ 0.004032f, 0.004314f, 0.004688f, 0.005066f, 0.005520f, 0.006012f, 0.006702f, 0.007332f, 0.008171f, 0.009140f, 0.010399f, 0.011787f,
+ 0.013496f, 0.015732f, 0.018509f, 0.022278f, 0.027267f, 0.033813f, 0.042328f, 0.053070f, 0.066406f, 0.082825f, 0.516602f, 0.562500f,
+ 0.573242f, 0.577637f, 0.580078f, 0.581543f, 0.000000f, 0.000216f, 0.000281f, 0.000346f, 0.000374f, 0.000388f, 0.000491f, 0.000416f,
+ 0.000516f, 0.000535f, 0.000635f, 0.000625f, 0.000681f, 0.000719f, 0.000790f, 0.000813f, 0.000879f, 0.000926f, 0.000968f, 0.001004f,
+ 0.001097f, 0.001135f, 0.001229f, 0.001300f, 0.001361f, 0.001431f, 0.001541f, 0.001610f, 0.001711f, 0.001802f, 0.001922f, 0.002094f,
+ 0.002169f, 0.002346f, 0.002468f, 0.002644f, 0.002844f, 0.003094f, 0.003368f, 0.003586f, 0.003883f, 0.004223f, 0.004662f, 0.005093f,
+ 0.005680f, 0.006348f, 0.007206f, 0.008202f, 0.009392f, 0.010895f, 0.012939f, 0.015465f, 0.018906f, 0.023682f, 0.030502f, 0.039825f,
+ 0.051331f, 0.066528f, 0.500977f, 0.548828f, 0.560059f, 0.564453f, 0.567871f, 0.569336f, 0.000000f, 0.000106f, 0.000201f, 0.000252f,
+ 0.000251f, 0.000322f, 0.000281f, 0.000340f, 0.000359f, 0.000428f, 0.000443f, 0.000419f, 0.000444f, 0.000500f, 0.000524f, 0.000590f,
+ 0.000574f, 0.000650f, 0.000693f, 0.000732f, 0.000778f, 0.000821f, 0.000848f, 0.000900f, 0.000965f, 0.000982f, 0.001072f, 0.001109f,
+ 0.001169f, 0.001307f, 0.001301f, 0.001409f, 0.001483f, 0.001610f, 0.001734f, 0.001835f, 0.001940f, 0.002098f, 0.002241f, 0.002426f,
+ 0.002634f, 0.002865f, 0.003136f, 0.003431f, 0.003763f, 0.004211f, 0.004742f, 0.005417f, 0.006229f, 0.007298f, 0.008621f, 0.010330f,
+ 0.012650f, 0.015808f, 0.020569f, 0.027908f, 0.037994f, 0.051514f, 0.485840f, 0.536133f, 0.547363f, 0.551758f, 0.554688f, 0.557617f,
+ 0.000026f, 0.000156f, 0.000201f, 0.000136f, 0.000188f, 0.000187f, 0.000192f, 0.000240f, 0.000245f, 0.000254f, 0.000262f, 0.000311f,
+ 0.000309f, 0.000331f, 0.000374f, 0.000385f, 0.000411f, 0.000431f, 0.000443f, 0.000461f, 0.000507f, 0.000522f, 0.000562f, 0.000596f,
+ 0.000634f, 0.000684f, 0.000718f, 0.000735f, 0.000776f, 0.000815f, 0.000875f, 0.000927f, 0.000982f, 0.001053f, 0.001123f, 0.001162f,
+ 0.001271f, 0.001346f, 0.001473f, 0.001577f, 0.001670f, 0.001838f, 0.002005f, 0.002161f, 0.002405f, 0.002670f, 0.002993f, 0.003399f,
+ 0.003860f, 0.004528f, 0.005386f, 0.006523f, 0.008003f, 0.010063f, 0.013206f, 0.017990f, 0.026031f, 0.038086f, 0.471191f, 0.522949f,
+ 0.534668f, 0.540039f, 0.543457f, 0.544922f, 0.000000f, 0.000093f, 0.000084f, 0.000085f, 0.000124f, 0.000145f, 0.000122f, 0.000149f,
+ 0.000152f, 0.000152f, 0.000158f, 0.000167f, 0.000186f, 0.000209f, 0.000217f, 0.000225f, 0.000231f, 0.000272f, 0.000273f, 0.000301f,
+ 0.000303f, 0.000310f, 0.000338f, 0.000361f, 0.000387f, 0.000423f, 0.000413f, 0.000436f, 0.000478f, 0.000503f, 0.000525f, 0.000570f,
+ 0.000608f, 0.000626f, 0.000677f, 0.000706f, 0.000753f, 0.000813f, 0.000884f, 0.000929f, 0.001000f, 0.001094f, 0.001183f, 0.001302f,
+ 0.001412f, 0.001563f, 0.001769f, 0.001974f, 0.002277f, 0.002626f, 0.003124f, 0.003761f, 0.004665f, 0.005993f, 0.007935f, 0.010818f,
+ 0.016205f, 0.026138f, 0.456299f, 0.509277f, 0.520996f, 0.527344f, 0.530762f, 0.532715f, 0.000105f, 0.000083f, 0.000072f, 0.000065f,
+ 0.000071f, 0.000072f, 0.000077f, 0.000084f, 0.000088f, 0.000093f, 0.000095f, 0.000120f, 0.000100f, 0.000108f, 0.000126f, 0.000118f,
+ 0.000139f, 0.000149f, 0.000153f, 0.000165f, 0.000169f, 0.000172f, 0.000194f, 0.000203f, 0.000233f, 0.000225f, 0.000233f, 0.000253f,
+ 0.000266f, 0.000275f, 0.000299f, 0.000319f, 0.000338f, 0.000345f, 0.000374f, 0.000384f, 0.000415f, 0.000448f, 0.000483f, 0.000511f,
+ 0.000543f, 0.000585f, 0.000647f, 0.000692f, 0.000755f, 0.000827f, 0.000924f, 0.001041f, 0.001186f, 0.001372f, 0.001608f, 0.001953f,
+ 0.002411f, 0.003098f, 0.004238f, 0.005989f, 0.009003f, 0.016006f, 0.441406f, 0.495361f, 0.508301f, 0.514160f, 0.518066f, 0.520508f,
+ 0.000090f, 0.000067f, 0.000058f, 0.000052f, 0.000047f, 0.000044f, 0.000044f, 0.000040f, 0.000042f, 0.000049f, 0.000042f, 0.000045f,
+ 0.000059f, 0.000047f, 0.000050f, 0.000054f, 0.000071f, 0.000073f, 0.000075f, 0.000078f, 0.000079f, 0.000084f, 0.000087f, 0.000090f,
+ 0.000097f, 0.000109f, 0.000108f, 0.000124f, 0.000124f, 0.000131f, 0.000138f, 0.000143f, 0.000155f, 0.000164f, 0.000178f, 0.000182f,
+ 0.000192f, 0.000209f, 0.000225f, 0.000244f, 0.000259f, 0.000274f, 0.000303f, 0.000321f, 0.000357f, 0.000385f, 0.000429f, 0.000470f,
+ 0.000537f, 0.000608f, 0.000710f, 0.000852f, 0.001052f, 0.001371f, 0.001877f, 0.002762f, 0.004406f, 0.008202f, 0.426270f, 0.483154f,
+ 0.495605f, 0.500977f, 0.505371f, 0.507324f, 0.000067f, 0.000047f, 0.000039f, 0.000035f, 0.000032f, 0.000030f, 0.000029f, 0.000027f,
+ 0.000026f, 0.000025f, 0.000024f, 0.000023f, 0.000021f, 0.000020f, 0.000019f, 0.000021f, 0.000020f, 0.000024f, 0.000028f, 0.000030f,
+ 0.000029f, 0.000032f, 0.000035f, 0.000034f, 0.000036f, 0.000044f, 0.000046f, 0.000040f, 0.000048f, 0.000047f, 0.000051f, 0.000053f,
+ 0.000059f, 0.000059f, 0.000064f, 0.000066f, 0.000077f, 0.000079f, 0.000081f, 0.000091f, 0.000094f, 0.000100f, 0.000108f, 0.000119f,
+ 0.000129f, 0.000137f, 0.000148f, 0.000173f, 0.000191f, 0.000210f, 0.000249f, 0.000292f, 0.000357f, 0.000448f, 0.000629f, 0.000943f,
+ 0.001630f, 0.003332f, 0.411377f, 0.468506f, 0.482910f, 0.488770f, 0.492188f, 0.495117f, 0.000025f, 0.000018f, 0.000015f, 0.000013f,
+ 0.000014f, 0.000013f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f,
+ 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000008f, 0.000008f, 0.000008f, 0.000007f,
+ 0.000008f, 0.000010f, 0.000010f, 0.000010f, 0.000012f, 0.000014f, 0.000014f, 0.000014f, 0.000016f, 0.000018f, 0.000019f, 0.000021f,
+ 0.000020f, 0.000023f, 0.000025f, 0.000027f, 0.000027f, 0.000029f, 0.000035f, 0.000033f, 0.000040f, 0.000044f, 0.000052f, 0.000061f,
+ 0.000069f, 0.000087f, 0.000117f, 0.000174f, 0.000319f, 0.000847f, 0.395996f, 0.454834f, 0.468750f, 0.475586f, 0.479004f, 0.481689f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000003f, 0.000004f, 0.000004f, 0.000005f, 0.000009f, 0.000027f, 0.381348f, 0.441406f,
+ 0.455566f, 0.462891f, 0.466309f, 0.468994f,
+ },
+ {
+ 0.016769f, 0.050629f, 0.083740f, 0.116638f, 0.148071f, 0.178955f, 0.208374f, 0.236938f, 0.265137f, 0.291992f, 0.317871f, 0.343994f,
+ 0.368164f, 0.391846f, 0.415527f, 0.437988f, 0.459717f, 0.480469f, 0.501465f, 0.520996f, 0.540527f, 0.559082f, 0.577637f, 0.594727f,
+ 0.612305f, 0.628418f, 0.644531f, 0.661133f, 0.676270f, 0.691406f, 0.705566f, 0.719727f, 0.734375f, 0.747070f, 0.760254f, 0.773438f,
+ 0.786133f, 0.798828f, 0.810059f, 0.821777f, 0.833008f, 0.843262f, 0.854492f, 0.865234f, 0.875488f, 0.885254f, 0.895508f, 0.904297f,
+ 0.913574f, 0.923340f, 0.932617f, 0.940918f, 0.949707f, 0.958008f, 0.966309f, 0.974609f, 0.981934f, 0.990234f, 0.985352f, 0.965332f,
+ 0.950195f, 0.937500f, 0.926270f, 0.915527f, 0.015083f, 0.045929f, 0.075806f, 0.105408f, 0.135254f, 0.163208f, 0.191772f, 0.219238f,
+ 0.245239f, 0.271973f, 0.297363f, 0.321045f, 0.345947f, 0.369141f, 0.391846f, 0.414062f, 0.435791f, 0.456787f, 0.477295f, 0.497314f,
+ 0.516113f, 0.535645f, 0.554199f, 0.571777f, 0.588867f, 0.606445f, 0.623047f, 0.639160f, 0.654785f, 0.669434f, 0.685059f, 0.699219f,
+ 0.713379f, 0.728027f, 0.741211f, 0.754883f, 0.767578f, 0.780273f, 0.792480f, 0.804688f, 0.815918f, 0.826660f, 0.838867f, 0.850098f,
+ 0.859863f, 0.871094f, 0.880859f, 0.891113f, 0.900879f, 0.909180f, 0.919434f, 0.929688f, 0.937500f, 0.946289f, 0.954590f, 0.963379f,
+ 0.971191f, 0.979004f, 0.980469f, 0.961426f, 0.947266f, 0.935059f, 0.924316f, 0.914062f, 0.013573f, 0.040955f, 0.068848f, 0.096313f,
+ 0.123169f, 0.150635f, 0.175537f, 0.202026f, 0.228271f, 0.251709f, 0.276367f, 0.300781f, 0.323730f, 0.347168f, 0.369385f, 0.390625f,
+ 0.412354f, 0.433594f, 0.454346f, 0.473145f, 0.491943f, 0.512207f, 0.529785f, 0.549316f, 0.566406f, 0.583008f, 0.600586f, 0.616211f,
+ 0.633301f, 0.648438f, 0.663574f, 0.679199f, 0.693359f, 0.708008f, 0.721680f, 0.735840f, 0.748535f, 0.762207f, 0.773926f, 0.786621f,
+ 0.798340f, 0.811035f, 0.822754f, 0.833984f, 0.845215f, 0.855957f, 0.865723f, 0.876465f, 0.886719f, 0.895508f, 0.906738f, 0.916016f,
+ 0.925293f, 0.934570f, 0.943848f, 0.952148f, 0.960449f, 0.969238f, 0.976074f, 0.958008f, 0.944336f, 0.932617f, 0.921875f, 0.912109f,
+ 0.012329f, 0.037201f, 0.062164f, 0.087646f, 0.112488f, 0.137451f, 0.161865f, 0.187134f, 0.210938f, 0.234253f, 0.258301f, 0.281006f,
+ 0.303467f, 0.325195f, 0.347656f, 0.368652f, 0.389648f, 0.410400f, 0.430664f, 0.450928f, 0.470215f, 0.488770f, 0.507812f, 0.525391f,
+ 0.543457f, 0.560059f, 0.579102f, 0.593750f, 0.611816f, 0.627441f, 0.643066f, 0.658203f, 0.672363f, 0.687500f, 0.702148f, 0.715820f,
+ 0.729004f, 0.742676f, 0.755371f, 0.768066f, 0.781738f, 0.792969f, 0.805176f, 0.816895f, 0.829102f, 0.839844f, 0.850586f, 0.861816f,
+ 0.872559f, 0.882812f, 0.893066f, 0.902832f, 0.912109f, 0.921875f, 0.930664f, 0.940430f, 0.948242f, 0.958008f, 0.970703f, 0.953613f,
+ 0.940430f, 0.929199f, 0.919434f, 0.910156f, 0.010979f, 0.033752f, 0.056763f, 0.080139f, 0.103516f, 0.126221f, 0.149414f, 0.172485f,
+ 0.195435f, 0.218262f, 0.240356f, 0.261719f, 0.284180f, 0.306396f, 0.326416f, 0.347900f, 0.368408f, 0.389160f, 0.408691f, 0.427979f,
+ 0.447754f, 0.467041f, 0.484863f, 0.502441f, 0.520996f, 0.538086f, 0.555664f, 0.573242f, 0.589355f, 0.604980f, 0.622559f, 0.637207f,
+ 0.652832f, 0.666992f, 0.680664f, 0.695801f, 0.710938f, 0.724121f, 0.737305f, 0.750977f, 0.763672f, 0.776855f, 0.789062f, 0.799805f,
+ 0.812012f, 0.824219f, 0.835449f, 0.846680f, 0.857910f, 0.868164f, 0.878418f, 0.889160f, 0.898926f, 0.909180f, 0.917969f, 0.928223f,
+ 0.937012f, 0.946777f, 0.965820f, 0.949707f, 0.937012f, 0.926270f, 0.916504f, 0.907715f, 0.009941f, 0.030746f, 0.051514f, 0.073181f,
+ 0.094116f, 0.116028f, 0.137817f, 0.158691f, 0.180664f, 0.202637f, 0.223511f, 0.244873f, 0.265869f, 0.285889f, 0.307129f, 0.327881f,
+ 0.347412f, 0.367188f, 0.387207f, 0.405762f, 0.425537f, 0.444092f, 0.462646f, 0.481201f, 0.499756f, 0.516602f, 0.533691f, 0.550781f,
+ 0.567383f, 0.583984f, 0.599609f, 0.616211f, 0.630859f, 0.647461f, 0.661621f, 0.676758f, 0.689453f, 0.704590f, 0.718750f, 0.731934f,
+ 0.745117f, 0.757812f, 0.770996f, 0.783691f, 0.796387f, 0.807617f, 0.819824f, 0.831543f, 0.842773f, 0.854004f, 0.864258f, 0.875488f,
+ 0.885742f, 0.895508f, 0.905762f, 0.915527f, 0.925781f, 0.934570f, 0.960449f, 0.945312f, 0.933594f, 0.922852f, 0.913574f, 0.905273f,
+ 0.009003f, 0.027756f, 0.046997f, 0.066711f, 0.085999f, 0.106506f, 0.127075f, 0.146973f, 0.166992f, 0.187500f, 0.207886f, 0.228149f,
+ 0.248169f, 0.268311f, 0.287842f, 0.307861f, 0.327393f, 0.347656f, 0.365967f, 0.385010f, 0.404541f, 0.422363f, 0.441162f, 0.458740f,
+ 0.477783f, 0.495117f, 0.512207f, 0.529297f, 0.546387f, 0.562012f, 0.578613f, 0.595215f, 0.610840f, 0.625977f, 0.641113f, 0.656738f,
+ 0.670410f, 0.685059f, 0.699707f, 0.714355f, 0.727051f, 0.741699f, 0.752441f, 0.767090f, 0.778809f, 0.791504f, 0.803711f, 0.815430f,
+ 0.827148f, 0.838867f, 0.850098f, 0.860840f, 0.872070f, 0.881836f, 0.893066f, 0.903809f, 0.913574f, 0.923828f, 0.955078f, 0.940918f,
+ 0.929199f, 0.919922f, 0.911133f, 0.902344f, 0.008469f, 0.025375f, 0.043121f, 0.060944f, 0.079468f, 0.097961f, 0.116394f, 0.135620f,
+ 0.154541f, 0.174072f, 0.193115f, 0.212280f, 0.231689f, 0.250732f, 0.270264f, 0.289307f, 0.307861f, 0.327148f, 0.345215f, 0.364990f,
+ 0.382812f, 0.401123f, 0.418945f, 0.437012f, 0.455811f, 0.472900f, 0.490234f, 0.507812f, 0.524414f, 0.541016f, 0.558105f, 0.573242f,
+ 0.590332f, 0.605469f, 0.620117f, 0.636230f, 0.651367f, 0.665039f, 0.679688f, 0.694336f, 0.708496f, 0.722168f, 0.735840f, 0.750000f,
+ 0.762695f, 0.774902f, 0.787598f, 0.798828f, 0.811523f, 0.823730f, 0.834473f, 0.846191f, 0.857910f, 0.868652f, 0.879883f, 0.891113f,
+ 0.900391f, 0.911133f, 0.949219f, 0.937012f, 0.925293f, 0.916016f, 0.907227f, 0.899414f, 0.007618f, 0.023178f, 0.039490f, 0.055542f,
+ 0.072937f, 0.090271f, 0.107605f, 0.125122f, 0.142944f, 0.160889f, 0.178955f, 0.197510f, 0.216553f, 0.234497f, 0.252686f, 0.271240f,
+ 0.289795f, 0.307861f, 0.326172f, 0.344238f, 0.362549f, 0.380859f, 0.398438f, 0.416504f, 0.433838f, 0.452393f, 0.468994f, 0.485840f,
+ 0.502930f, 0.519531f, 0.536133f, 0.553223f, 0.569336f, 0.584473f, 0.599609f, 0.615234f, 0.631348f, 0.646484f, 0.659668f, 0.675293f,
+ 0.689941f, 0.703125f, 0.716797f, 0.730957f, 0.744141f, 0.756836f, 0.771484f, 0.782227f, 0.795898f, 0.807617f, 0.819824f, 0.831543f,
+ 0.843750f, 0.854980f, 0.866211f, 0.877441f, 0.888672f, 0.898438f, 0.943359f, 0.931641f, 0.921387f, 0.912109f, 0.903809f, 0.896484f,
+ 0.007118f, 0.021255f, 0.035889f, 0.051514f, 0.066895f, 0.083191f, 0.098999f, 0.115540f, 0.132324f, 0.149292f, 0.166260f, 0.183716f,
+ 0.200928f, 0.218628f, 0.236084f, 0.253906f, 0.272217f, 0.289795f, 0.307617f, 0.325439f, 0.342529f, 0.360596f, 0.378906f, 0.395996f,
+ 0.413330f, 0.430908f, 0.447510f, 0.465332f, 0.481934f, 0.497803f, 0.514648f, 0.531738f, 0.547852f, 0.562988f, 0.579102f, 0.595215f,
+ 0.610840f, 0.625977f, 0.641113f, 0.655273f, 0.670410f, 0.685059f, 0.698730f, 0.712891f, 0.726074f, 0.739258f, 0.753418f, 0.766113f,
+ 0.779785f, 0.791992f, 0.803711f, 0.816406f, 0.829102f, 0.839844f, 0.852539f, 0.863770f, 0.874512f, 0.886719f, 0.937988f, 0.926758f,
+ 0.917480f, 0.908203f, 0.900391f, 0.893066f, 0.006481f, 0.019775f, 0.032928f, 0.047272f, 0.061371f, 0.076233f, 0.091064f, 0.107117f,
+ 0.122559f, 0.138062f, 0.154663f, 0.170532f, 0.187256f, 0.204346f, 0.220947f, 0.237915f, 0.254883f, 0.272217f, 0.289062f, 0.306641f,
+ 0.323730f, 0.341064f, 0.358643f, 0.375732f, 0.393555f, 0.410645f, 0.426758f, 0.444580f, 0.461182f, 0.477783f, 0.494141f, 0.510254f,
+ 0.526855f, 0.543457f, 0.559082f, 0.574219f, 0.590332f, 0.605957f, 0.621094f, 0.634766f, 0.650879f, 0.665039f, 0.679688f, 0.694824f,
+ 0.708008f, 0.722656f, 0.736816f, 0.749023f, 0.762695f, 0.775391f, 0.788086f, 0.801270f, 0.813965f, 0.826172f, 0.838379f, 0.849121f,
+ 0.861328f, 0.873535f, 0.932129f, 0.921875f, 0.912598f, 0.904297f, 0.896484f, 0.889160f, 0.005924f, 0.017899f, 0.030426f, 0.043427f,
+ 0.056824f, 0.070435f, 0.084106f, 0.098755f, 0.112976f, 0.128052f, 0.143311f, 0.158936f, 0.174072f, 0.189575f, 0.206421f, 0.222534f,
+ 0.238403f, 0.255615f, 0.271729f, 0.288818f, 0.305908f, 0.322021f, 0.339355f, 0.356445f, 0.373291f, 0.390137f, 0.407227f, 0.423584f,
+ 0.440430f, 0.457031f, 0.472900f, 0.489502f, 0.506836f, 0.521973f, 0.538574f, 0.554688f, 0.570312f, 0.585449f, 0.601074f, 0.616211f,
+ 0.631348f, 0.646484f, 0.661621f, 0.675781f, 0.690430f, 0.704590f, 0.717285f, 0.731934f, 0.746094f, 0.759277f, 0.771973f, 0.785156f,
+ 0.798340f, 0.810547f, 0.823242f, 0.835938f, 0.848145f, 0.860352f, 0.925781f, 0.916504f, 0.908203f, 0.900391f, 0.893066f, 0.886719f,
+ 0.005573f, 0.016693f, 0.028366f, 0.040192f, 0.052277f, 0.064880f, 0.078064f, 0.090698f, 0.105042f, 0.118591f, 0.133057f, 0.147461f,
+ 0.162231f, 0.177612f, 0.192383f, 0.207886f, 0.223633f, 0.239502f, 0.255615f, 0.272217f, 0.288330f, 0.304932f, 0.320312f, 0.337646f,
+ 0.354004f, 0.369873f, 0.386719f, 0.403320f, 0.419922f, 0.437012f, 0.453369f, 0.469482f, 0.485596f, 0.501465f, 0.517578f, 0.534180f,
+ 0.549316f, 0.565918f, 0.581055f, 0.595703f, 0.611328f, 0.626953f, 0.641602f, 0.657227f, 0.671387f, 0.686523f, 0.699707f, 0.714355f,
+ 0.729004f, 0.742676f, 0.756348f, 0.769043f, 0.782715f, 0.795410f, 0.809082f, 0.821289f, 0.833984f, 0.846680f, 0.919434f, 0.911133f,
+ 0.903320f, 0.895508f, 0.888672f, 0.882324f, 0.005016f, 0.015396f, 0.026169f, 0.037231f, 0.048126f, 0.059937f, 0.071716f, 0.084167f,
+ 0.096680f, 0.109558f, 0.123169f, 0.136719f, 0.150269f, 0.164917f, 0.179077f, 0.194580f, 0.208984f, 0.223877f, 0.239746f, 0.255127f,
+ 0.270996f, 0.286377f, 0.302490f, 0.319336f, 0.335205f, 0.351318f, 0.367432f, 0.383545f, 0.399902f, 0.415771f, 0.432373f, 0.448975f,
+ 0.465088f, 0.481934f, 0.497314f, 0.513672f, 0.529785f, 0.544434f, 0.561035f, 0.576660f, 0.592285f, 0.607422f, 0.622559f, 0.638184f,
+ 0.652344f, 0.667480f, 0.681641f, 0.696777f, 0.711426f, 0.725586f, 0.738770f, 0.753418f, 0.766602f, 0.779297f, 0.793945f, 0.807129f,
+ 0.819824f, 0.833008f, 0.913086f, 0.906738f, 0.898438f, 0.890625f, 0.884277f, 0.878418f, 0.004738f, 0.014053f, 0.024017f, 0.033752f,
+ 0.044495f, 0.055328f, 0.066467f, 0.078064f, 0.089661f, 0.102051f, 0.114258f, 0.126831f, 0.139771f, 0.153564f, 0.167114f, 0.181030f,
+ 0.195190f, 0.209839f, 0.224731f, 0.239136f, 0.253906f, 0.269531f, 0.285156f, 0.300293f, 0.317139f, 0.332520f, 0.348145f, 0.364990f,
+ 0.380859f, 0.396240f, 0.412109f, 0.428711f, 0.444336f, 0.460938f, 0.477295f, 0.492676f, 0.509277f, 0.524902f, 0.540527f, 0.556641f,
+ 0.572266f, 0.587402f, 0.604004f, 0.618164f, 0.633301f, 0.648438f, 0.664062f, 0.678223f, 0.693359f, 0.708008f, 0.722656f, 0.736328f,
+ 0.750000f, 0.764160f, 0.777832f, 0.791016f, 0.805176f, 0.817871f, 0.907227f, 0.900879f, 0.894043f, 0.886719f, 0.880371f, 0.874512f,
+ 0.004105f, 0.012741f, 0.022491f, 0.031769f, 0.041107f, 0.051208f, 0.061249f, 0.071777f, 0.083069f, 0.093811f, 0.105896f, 0.117554f,
+ 0.129761f, 0.142212f, 0.155273f, 0.168579f, 0.182251f, 0.196167f, 0.210449f, 0.223755f, 0.238525f, 0.253662f, 0.268799f, 0.283447f,
+ 0.298828f, 0.313965f, 0.329834f, 0.344971f, 0.361328f, 0.376953f, 0.393066f, 0.408691f, 0.424561f, 0.441406f, 0.457031f, 0.472656f,
+ 0.488770f, 0.504883f, 0.520996f, 0.536133f, 0.551758f, 0.567871f, 0.583496f, 0.599121f, 0.614258f, 0.629395f, 0.645996f, 0.660156f,
+ 0.675781f, 0.689453f, 0.704102f, 0.719727f, 0.733398f, 0.747559f, 0.761719f, 0.776367f, 0.789062f, 0.803223f, 0.899902f, 0.895020f,
+ 0.888184f, 0.881836f, 0.875488f, 0.870117f, 0.003925f, 0.011978f, 0.020538f, 0.028763f, 0.038269f, 0.047028f, 0.056732f, 0.066223f,
+ 0.076904f, 0.086731f, 0.097900f, 0.109314f, 0.120483f, 0.132324f, 0.144653f, 0.156982f, 0.169678f, 0.183228f, 0.196289f, 0.209961f,
+ 0.223633f, 0.237427f, 0.251953f, 0.266602f, 0.281982f, 0.296875f, 0.312012f, 0.326660f, 0.342041f, 0.357910f, 0.373779f, 0.389404f,
+ 0.404785f, 0.420166f, 0.436768f, 0.452637f, 0.468506f, 0.484863f, 0.500977f, 0.516602f, 0.531738f, 0.546875f, 0.563965f, 0.579102f,
+ 0.595215f, 0.610840f, 0.625977f, 0.641602f, 0.657227f, 0.671387f, 0.687500f, 0.702148f, 0.716309f, 0.731445f, 0.746094f, 0.760742f,
+ 0.774414f, 0.788086f, 0.893066f, 0.889648f, 0.882812f, 0.876953f, 0.870605f, 0.865723f, 0.003704f, 0.011169f, 0.019165f, 0.026550f,
+ 0.035339f, 0.043488f, 0.052277f, 0.061066f, 0.071045f, 0.080933f, 0.090576f, 0.101074f, 0.111877f, 0.122925f, 0.134277f, 0.146118f,
+ 0.157837f, 0.170288f, 0.183105f, 0.195557f, 0.209351f, 0.222900f, 0.236328f, 0.250732f, 0.264893f, 0.279297f, 0.294189f, 0.308838f,
+ 0.323975f, 0.339844f, 0.354736f, 0.370117f, 0.385986f, 0.401367f, 0.416504f, 0.432861f, 0.448486f, 0.463867f, 0.480469f, 0.497070f,
+ 0.511719f, 0.527832f, 0.544434f, 0.559570f, 0.575684f, 0.591797f, 0.606934f, 0.623047f, 0.638184f, 0.654297f, 0.668945f, 0.684570f,
+ 0.699219f, 0.714355f, 0.729492f, 0.744629f, 0.758789f, 0.773926f, 0.886230f, 0.883301f, 0.877441f, 0.871582f, 0.866211f, 0.860840f,
+ 0.003500f, 0.010292f, 0.017395f, 0.024963f, 0.032440f, 0.040344f, 0.048462f, 0.057098f, 0.065063f, 0.074646f, 0.083679f, 0.093445f,
+ 0.103882f, 0.114136f, 0.124451f, 0.135498f, 0.146606f, 0.158447f, 0.170410f, 0.182739f, 0.195435f, 0.208008f, 0.221558f, 0.234863f,
+ 0.248657f, 0.262695f, 0.276855f, 0.291748f, 0.306152f, 0.320801f, 0.335693f, 0.350830f, 0.365967f, 0.382080f, 0.396973f, 0.413330f,
+ 0.429199f, 0.444336f, 0.459473f, 0.476074f, 0.492188f, 0.507812f, 0.524414f, 0.540039f, 0.555664f, 0.571777f, 0.586914f, 0.604004f,
+ 0.619629f, 0.635742f, 0.650391f, 0.666504f, 0.682129f, 0.697754f, 0.712891f, 0.728027f, 0.743164f, 0.758301f, 0.878906f, 0.877441f,
+ 0.871582f, 0.866699f, 0.860840f, 0.856445f, 0.003084f, 0.009697f, 0.016403f, 0.022659f, 0.029892f, 0.037354f, 0.044281f, 0.052338f,
+ 0.060516f, 0.068970f, 0.077515f, 0.086243f, 0.096069f, 0.105713f, 0.115356f, 0.125610f, 0.136353f, 0.147339f, 0.158081f, 0.170410f,
+ 0.181396f, 0.194458f, 0.207275f, 0.219482f, 0.232910f, 0.246704f, 0.260010f, 0.274170f, 0.288330f, 0.302979f, 0.317383f, 0.332764f,
+ 0.347656f, 0.363037f, 0.378174f, 0.392578f, 0.408936f, 0.424316f, 0.440430f, 0.456299f, 0.472656f, 0.488525f, 0.503906f, 0.519531f,
+ 0.535645f, 0.552734f, 0.568359f, 0.584961f, 0.600586f, 0.616699f, 0.633301f, 0.648438f, 0.663574f, 0.679199f, 0.694824f, 0.710938f,
+ 0.726074f, 0.742188f, 0.872559f, 0.870605f, 0.865723f, 0.860840f, 0.855957f, 0.851074f, 0.002913f, 0.008781f, 0.014938f, 0.021759f,
+ 0.027878f, 0.034393f, 0.041412f, 0.048737f, 0.055969f, 0.063599f, 0.072021f, 0.080200f, 0.088928f, 0.097839f, 0.106934f, 0.116150f,
+ 0.126587f, 0.136353f, 0.147095f, 0.157715f, 0.169189f, 0.181519f, 0.193481f, 0.205933f, 0.217773f, 0.231323f, 0.244629f, 0.257812f,
+ 0.271240f, 0.285400f, 0.299561f, 0.314453f, 0.329590f, 0.343506f, 0.358887f, 0.373779f, 0.389648f, 0.405029f, 0.420410f, 0.437012f,
+ 0.452393f, 0.468262f, 0.484375f, 0.500000f, 0.516113f, 0.532227f, 0.548828f, 0.564941f, 0.581055f, 0.597168f, 0.612793f, 0.629883f,
+ 0.645508f, 0.662109f, 0.678223f, 0.694336f, 0.709473f, 0.726074f, 0.863770f, 0.864258f, 0.859863f, 0.854980f, 0.850586f, 0.846191f,
+ 0.002815f, 0.008194f, 0.013954f, 0.019653f, 0.025696f, 0.031982f, 0.038177f, 0.044830f, 0.051819f, 0.058502f, 0.066162f, 0.073792f,
+ 0.082031f, 0.090393f, 0.098999f, 0.107605f, 0.117493f, 0.126709f, 0.137207f, 0.146729f, 0.157593f, 0.168579f, 0.179810f, 0.191772f,
+ 0.203369f, 0.215820f, 0.228882f, 0.241455f, 0.254395f, 0.268311f, 0.282227f, 0.296631f, 0.310303f, 0.325439f, 0.339844f, 0.354736f,
+ 0.370361f, 0.385742f, 0.400879f, 0.416504f, 0.432617f, 0.448486f, 0.464355f, 0.479980f, 0.496094f, 0.513184f, 0.528809f, 0.545410f,
+ 0.561035f, 0.578613f, 0.594727f, 0.611328f, 0.626953f, 0.643555f, 0.660156f, 0.676270f, 0.693359f, 0.709473f, 0.856445f, 0.858398f,
+ 0.854492f, 0.849121f, 0.845215f, 0.841309f, 0.002583f, 0.007492f, 0.012878f, 0.018417f, 0.023941f, 0.029495f, 0.035339f, 0.041779f,
+ 0.047577f, 0.054047f, 0.061523f, 0.068787f, 0.075562f, 0.083313f, 0.091858f, 0.099792f, 0.108521f, 0.117615f, 0.126709f, 0.136108f,
+ 0.146851f, 0.156860f, 0.166992f, 0.178345f, 0.189819f, 0.202148f, 0.213623f, 0.225830f, 0.238892f, 0.252197f, 0.265137f, 0.278809f,
+ 0.292480f, 0.306885f, 0.321045f, 0.336914f, 0.350830f, 0.366943f, 0.381348f, 0.396240f, 0.412354f, 0.428223f, 0.444336f, 0.460449f,
+ 0.476318f, 0.493408f, 0.509277f, 0.525879f, 0.542480f, 0.559082f, 0.574707f, 0.591797f, 0.608398f, 0.625488f, 0.642090f, 0.659180f,
+ 0.675781f, 0.691406f, 0.848145f, 0.851562f, 0.848145f, 0.843750f, 0.838867f, 0.835449f, 0.002512f, 0.007374f, 0.012115f, 0.016983f,
+ 0.022064f, 0.027359f, 0.032715f, 0.038147f, 0.044373f, 0.050354f, 0.056641f, 0.063293f, 0.070190f, 0.077026f, 0.084717f, 0.092041f,
+ 0.100342f, 0.108398f, 0.117554f, 0.126221f, 0.135742f, 0.145142f, 0.155151f, 0.165771f, 0.176758f, 0.187988f, 0.199341f, 0.210815f,
+ 0.223389f, 0.236206f, 0.249023f, 0.261719f, 0.275879f, 0.289062f, 0.303467f, 0.317627f, 0.332520f, 0.347412f, 0.361816f, 0.377197f,
+ 0.393066f, 0.407959f, 0.424072f, 0.440186f, 0.457031f, 0.473145f, 0.489502f, 0.505859f, 0.522461f, 0.540039f, 0.555664f, 0.572754f,
+ 0.589844f, 0.606445f, 0.623535f, 0.640625f, 0.658203f, 0.675781f, 0.840820f, 0.843750f, 0.841309f, 0.836914f, 0.833984f, 0.830566f,
+ 0.002369f, 0.006668f, 0.011093f, 0.015778f, 0.020523f, 0.025223f, 0.030701f, 0.035339f, 0.040710f, 0.046600f, 0.051971f, 0.058075f,
+ 0.064819f, 0.071228f, 0.077942f, 0.085205f, 0.092224f, 0.100464f, 0.108398f, 0.116882f, 0.125610f, 0.134155f, 0.143555f, 0.153564f,
+ 0.164062f, 0.174316f, 0.185303f, 0.196899f, 0.208496f, 0.220093f, 0.232666f, 0.245239f, 0.258057f, 0.271729f, 0.285645f, 0.299561f,
+ 0.313721f, 0.328613f, 0.342773f, 0.358154f, 0.373535f, 0.388916f, 0.405518f, 0.419922f, 0.437012f, 0.453125f, 0.469238f, 0.486328f,
+ 0.502930f, 0.519531f, 0.536133f, 0.553223f, 0.571289f, 0.588379f, 0.605469f, 0.623047f, 0.640137f, 0.656250f, 0.833008f, 0.837402f,
+ 0.834473f, 0.831055f, 0.827637f, 0.824219f, 0.002188f, 0.006027f, 0.010582f, 0.014297f, 0.018921f, 0.023270f, 0.028183f, 0.032593f,
+ 0.037781f, 0.042999f, 0.048584f, 0.053650f, 0.059601f, 0.065369f, 0.071899f, 0.078369f, 0.085449f, 0.092407f, 0.099609f, 0.107788f,
+ 0.115601f, 0.124451f, 0.133301f, 0.142212f, 0.151978f, 0.161865f, 0.172363f, 0.182617f, 0.193970f, 0.205566f, 0.217407f, 0.229858f,
+ 0.241943f, 0.254639f, 0.268311f, 0.281494f, 0.295654f, 0.310059f, 0.324219f, 0.339600f, 0.353760f, 0.369629f, 0.385010f, 0.400879f,
+ 0.417725f, 0.433594f, 0.449219f, 0.465820f, 0.482910f, 0.499512f, 0.517090f, 0.534180f, 0.551270f, 0.568848f, 0.586426f, 0.604004f,
+ 0.622559f, 0.639160f, 0.824219f, 0.830078f, 0.827637f, 0.824707f, 0.821777f, 0.818359f, 0.002098f, 0.005634f, 0.009354f, 0.013557f,
+ 0.017685f, 0.021576f, 0.025604f, 0.030380f, 0.034943f, 0.039429f, 0.044281f, 0.049255f, 0.055023f, 0.060577f, 0.066101f, 0.072144f,
+ 0.078491f, 0.085083f, 0.091858f, 0.098999f, 0.106873f, 0.114502f, 0.122498f, 0.131592f, 0.140137f, 0.149536f, 0.159424f, 0.169556f,
+ 0.180054f, 0.191162f, 0.202026f, 0.213989f, 0.226318f, 0.239136f, 0.250977f, 0.264648f, 0.278320f, 0.291748f, 0.305908f, 0.320557f,
+ 0.334961f, 0.350342f, 0.365479f, 0.381592f, 0.397461f, 0.413818f, 0.429199f, 0.446289f, 0.462891f, 0.479736f, 0.496338f, 0.514160f,
+ 0.530762f, 0.548828f, 0.566406f, 0.584473f, 0.602539f, 0.621582f, 0.815918f, 0.823730f, 0.821289f, 0.817871f, 0.815430f, 0.812500f,
+ 0.001772f, 0.005249f, 0.008995f, 0.012260f, 0.016251f, 0.020020f, 0.024216f, 0.027603f, 0.032196f, 0.036377f, 0.041199f, 0.045410f,
+ 0.050110f, 0.055603f, 0.061005f, 0.066406f, 0.072327f, 0.077820f, 0.084290f, 0.090942f, 0.098083f, 0.105164f, 0.113037f, 0.120789f,
+ 0.129272f, 0.138062f, 0.147339f, 0.156982f, 0.166626f, 0.176758f, 0.187866f, 0.199097f, 0.210449f, 0.222412f, 0.234985f, 0.247559f,
+ 0.260742f, 0.273682f, 0.287598f, 0.302002f, 0.316650f, 0.331299f, 0.346191f, 0.362061f, 0.377686f, 0.393066f, 0.409668f, 0.426514f,
+ 0.443115f, 0.459717f, 0.476807f, 0.494629f, 0.511230f, 0.529785f, 0.547852f, 0.565430f, 0.583984f, 0.602539f, 0.806152f, 0.814453f,
+ 0.813965f, 0.811035f, 0.809082f, 0.806641f, 0.001631f, 0.005131f, 0.008186f, 0.011673f, 0.014938f, 0.018463f, 0.021957f, 0.025635f,
+ 0.029083f, 0.033325f, 0.037445f, 0.041840f, 0.046478f, 0.050751f, 0.055634f, 0.060760f, 0.065979f, 0.071472f, 0.077515f, 0.083801f,
+ 0.090027f, 0.096802f, 0.104065f, 0.110840f, 0.119080f, 0.127197f, 0.135498f, 0.144775f, 0.153931f, 0.163574f, 0.173462f, 0.184570f,
+ 0.195312f, 0.207153f, 0.218506f, 0.230591f, 0.243652f, 0.256348f, 0.270020f, 0.283691f, 0.297852f, 0.312744f, 0.326904f, 0.342529f,
+ 0.357910f, 0.373535f, 0.389404f, 0.406494f, 0.421875f, 0.439941f, 0.457275f, 0.474365f, 0.492432f, 0.509766f, 0.527832f, 0.546875f,
+ 0.564941f, 0.584473f, 0.797852f, 0.807129f, 0.807129f, 0.804199f, 0.801758f, 0.799316f, 0.001632f, 0.004704f, 0.007912f, 0.010788f,
+ 0.013870f, 0.017105f, 0.020187f, 0.023483f, 0.026932f, 0.030563f, 0.034332f, 0.038086f, 0.042694f, 0.046631f, 0.050995f, 0.055725f,
+ 0.060486f, 0.065674f, 0.070862f, 0.076721f, 0.082825f, 0.088623f, 0.094910f, 0.102112f, 0.109070f, 0.116516f, 0.124695f, 0.133057f,
+ 0.141968f, 0.151001f, 0.160522f, 0.170776f, 0.181030f, 0.191650f, 0.202881f, 0.214722f, 0.227417f, 0.239624f, 0.252686f, 0.265625f,
+ 0.279785f, 0.293213f, 0.308350f, 0.323242f, 0.338867f, 0.354248f, 0.370117f, 0.386475f, 0.403076f, 0.420410f, 0.437012f, 0.454102f,
+ 0.471924f, 0.490234f, 0.508789f, 0.526855f, 0.545410f, 0.564453f, 0.788086f, 0.799316f, 0.798828f, 0.797852f, 0.794434f, 0.791992f,
+ 0.001594f, 0.004177f, 0.007122f, 0.010201f, 0.012344f, 0.015839f, 0.018372f, 0.021683f, 0.024857f, 0.028534f, 0.031464f, 0.035034f,
+ 0.038879f, 0.042572f, 0.046295f, 0.051056f, 0.055389f, 0.059723f, 0.064697f, 0.069763f, 0.075073f, 0.080750f, 0.087219f, 0.093445f,
+ 0.099548f, 0.107056f, 0.114136f, 0.121887f, 0.130249f, 0.138794f, 0.147217f, 0.157104f, 0.166748f, 0.177124f, 0.187988f, 0.199097f,
+ 0.210693f, 0.222778f, 0.235352f, 0.248169f, 0.261719f, 0.275635f, 0.289062f, 0.303955f, 0.319336f, 0.334717f, 0.350098f, 0.365479f,
+ 0.382324f, 0.398926f, 0.416016f, 0.433594f, 0.451904f, 0.469238f, 0.487549f, 0.506348f, 0.525391f, 0.544922f, 0.779297f, 0.791504f,
+ 0.791504f, 0.789551f, 0.788086f, 0.786133f, 0.001365f, 0.004173f, 0.006222f, 0.008842f, 0.011703f, 0.014366f, 0.017242f, 0.020218f,
+ 0.022903f, 0.025787f, 0.028824f, 0.032227f, 0.035522f, 0.038818f, 0.042511f, 0.046326f, 0.050507f, 0.054657f, 0.058594f, 0.063660f,
+ 0.068359f, 0.073914f, 0.078918f, 0.085083f, 0.091125f, 0.097534f, 0.104126f, 0.111511f, 0.118896f, 0.126831f, 0.135742f, 0.144043f,
+ 0.153564f, 0.163330f, 0.173462f, 0.184082f, 0.195068f, 0.206787f, 0.218628f, 0.231079f, 0.243896f, 0.257080f, 0.270996f, 0.285645f,
+ 0.300049f, 0.314941f, 0.330322f, 0.346191f, 0.362305f, 0.379395f, 0.395508f, 0.412842f, 0.431641f, 0.448975f, 0.468262f, 0.487549f,
+ 0.505371f, 0.525391f, 0.769531f, 0.783691f, 0.783691f, 0.782715f, 0.781250f, 0.778809f, 0.001230f, 0.003925f, 0.006268f, 0.008659f,
+ 0.010796f, 0.013145f, 0.015617f, 0.018234f, 0.021133f, 0.023682f, 0.026215f, 0.029251f, 0.032349f, 0.035400f, 0.038696f, 0.042206f,
+ 0.045807f, 0.049377f, 0.053925f, 0.057953f, 0.062500f, 0.067078f, 0.071777f, 0.077271f, 0.082703f, 0.088806f, 0.094910f, 0.101379f,
+ 0.109192f, 0.115967f, 0.123779f, 0.131470f, 0.140259f, 0.149536f, 0.159302f, 0.169312f, 0.180054f, 0.190674f, 0.202515f, 0.214722f,
+ 0.226562f, 0.239624f, 0.253174f, 0.266602f, 0.281738f, 0.295898f, 0.311035f, 0.326904f, 0.342529f, 0.359131f, 0.375732f, 0.393066f,
+ 0.410400f, 0.428467f, 0.447510f, 0.466064f, 0.485596f, 0.504883f, 0.759277f, 0.774902f, 0.775879f, 0.774902f, 0.773438f, 0.771973f,
+ 0.001031f, 0.003601f, 0.005604f, 0.007858f, 0.009880f, 0.012146f, 0.014549f, 0.016998f, 0.019043f, 0.021362f, 0.024475f, 0.026566f,
+ 0.029358f, 0.032196f, 0.035248f, 0.038391f, 0.041656f, 0.045044f, 0.048553f, 0.052582f, 0.056213f, 0.060669f, 0.065186f, 0.070068f,
+ 0.074768f, 0.080322f, 0.086060f, 0.092102f, 0.098877f, 0.105408f, 0.112366f, 0.120239f, 0.128540f, 0.136597f, 0.145874f, 0.155396f,
+ 0.165283f, 0.175537f, 0.186401f, 0.198120f, 0.210083f, 0.222534f, 0.235229f, 0.248657f, 0.262451f, 0.277344f, 0.291504f, 0.307617f,
+ 0.322998f, 0.339111f, 0.354980f, 0.372559f, 0.390625f, 0.408936f, 0.426758f, 0.445312f, 0.466064f, 0.485840f, 0.749512f, 0.765137f,
+ 0.767578f, 0.767090f, 0.765137f, 0.764648f, 0.001161f, 0.003078f, 0.005310f, 0.007282f, 0.009201f, 0.011330f, 0.013214f, 0.015404f,
+ 0.017273f, 0.019409f, 0.021988f, 0.024078f, 0.026550f, 0.029358f, 0.032043f, 0.034454f, 0.037415f, 0.040710f, 0.043854f, 0.047272f,
+ 0.050659f, 0.054840f, 0.058777f, 0.063293f, 0.067566f, 0.072449f, 0.077759f, 0.083069f, 0.088928f, 0.095886f, 0.102478f, 0.109070f,
+ 0.116760f, 0.124390f, 0.132935f, 0.141479f, 0.151123f, 0.161011f, 0.171143f, 0.182007f, 0.193726f, 0.205688f, 0.218018f, 0.230835f,
+ 0.244507f, 0.258789f, 0.272949f, 0.287109f, 0.303467f, 0.319336f, 0.335449f, 0.352539f, 0.369873f, 0.387939f, 0.406250f, 0.425049f,
+ 0.444824f, 0.464844f, 0.739258f, 0.756348f, 0.758789f, 0.758789f, 0.757324f, 0.756836f, 0.001004f, 0.002939f, 0.005005f, 0.006779f,
+ 0.008453f, 0.010323f, 0.012177f, 0.013870f, 0.016052f, 0.018051f, 0.019638f, 0.022141f, 0.023956f, 0.026413f, 0.028870f, 0.031281f,
+ 0.033661f, 0.036591f, 0.039429f, 0.042542f, 0.045776f, 0.049011f, 0.053009f, 0.056885f, 0.061035f, 0.065186f, 0.069885f, 0.075134f,
+ 0.080505f, 0.085999f, 0.091858f, 0.098633f, 0.105591f, 0.112732f, 0.120667f, 0.128662f, 0.137573f, 0.146729f, 0.156372f, 0.166748f,
+ 0.177490f, 0.189331f, 0.201294f, 0.213501f, 0.226807f, 0.239746f, 0.254150f, 0.268555f, 0.283936f, 0.298828f, 0.316162f, 0.332275f,
+ 0.349609f, 0.367432f, 0.385498f, 0.404053f, 0.423828f, 0.443848f, 0.728516f, 0.747559f, 0.750488f, 0.750488f, 0.749512f, 0.748047f,
+ 0.000970f, 0.002523f, 0.004665f, 0.006203f, 0.007759f, 0.009491f, 0.011070f, 0.012802f, 0.014336f, 0.016266f, 0.017944f, 0.019852f,
+ 0.021805f, 0.023911f, 0.025818f, 0.028137f, 0.030579f, 0.032837f, 0.035248f, 0.038055f, 0.041046f, 0.044189f, 0.047333f, 0.050842f,
+ 0.054504f, 0.058502f, 0.062866f, 0.067383f, 0.071960f, 0.077393f, 0.082642f, 0.088928f, 0.095093f, 0.101685f, 0.108765f, 0.116272f,
+ 0.124451f, 0.133423f, 0.142212f, 0.152100f, 0.162354f, 0.172729f, 0.184692f, 0.196411f, 0.209106f, 0.221802f, 0.235718f, 0.250000f,
+ 0.265137f, 0.280029f, 0.296143f, 0.312012f, 0.329346f, 0.346924f, 0.364990f, 0.384277f, 0.403564f, 0.423340f, 0.718262f, 0.738770f,
+ 0.741211f, 0.742188f, 0.741211f, 0.740234f, 0.000785f, 0.002600f, 0.004028f, 0.005390f, 0.007275f, 0.008774f, 0.010124f, 0.011620f,
+ 0.013306f, 0.014427f, 0.015991f, 0.017838f, 0.019577f, 0.021469f, 0.023254f, 0.024902f, 0.027115f, 0.029190f, 0.031677f, 0.034088f,
+ 0.036682f, 0.039307f, 0.042175f, 0.045410f, 0.048553f, 0.052002f, 0.055908f, 0.060028f, 0.064270f, 0.068909f, 0.074097f, 0.079163f,
+ 0.085022f, 0.091309f, 0.097473f, 0.104797f, 0.112183f, 0.120239f, 0.128662f, 0.137451f, 0.146973f, 0.157471f, 0.168213f, 0.179810f,
+ 0.191650f, 0.204468f, 0.217529f, 0.231201f, 0.245605f, 0.260254f, 0.275879f, 0.292236f, 0.308838f, 0.326416f, 0.344238f, 0.363037f,
+ 0.382080f, 0.403076f, 0.707031f, 0.729980f, 0.732422f, 0.733398f, 0.733398f, 0.732910f, 0.000775f, 0.002190f, 0.003696f, 0.005081f,
+ 0.006397f, 0.007858f, 0.009239f, 0.010323f, 0.011803f, 0.012978f, 0.014328f, 0.015915f, 0.017349f, 0.019058f, 0.020630f, 0.022339f,
+ 0.024445f, 0.025909f, 0.028275f, 0.030151f, 0.032532f, 0.035065f, 0.037476f, 0.040283f, 0.042969f, 0.046448f, 0.049469f, 0.053314f,
+ 0.056976f, 0.061371f, 0.065613f, 0.070435f, 0.075623f, 0.081360f, 0.087341f, 0.093628f, 0.100220f, 0.107788f, 0.115845f, 0.123901f,
+ 0.133057f, 0.142456f, 0.152832f, 0.163574f, 0.174561f, 0.187012f, 0.199463f, 0.212646f, 0.226562f, 0.241455f, 0.256836f, 0.272705f,
+ 0.288818f, 0.305664f, 0.323486f, 0.341797f, 0.362305f, 0.382080f, 0.695312f, 0.719238f, 0.722656f, 0.724121f, 0.724121f, 0.723633f,
+ 0.000906f, 0.002022f, 0.003521f, 0.004963f, 0.005756f, 0.006847f, 0.008446f, 0.009392f, 0.010437f, 0.012039f, 0.012863f, 0.014343f,
+ 0.015457f, 0.016876f, 0.018295f, 0.019730f, 0.021484f, 0.023102f, 0.024689f, 0.026581f, 0.028717f, 0.030945f, 0.032928f, 0.035370f,
+ 0.037872f, 0.040894f, 0.043915f, 0.047028f, 0.050415f, 0.054169f, 0.058167f, 0.062286f, 0.067078f, 0.071960f, 0.077209f, 0.082947f,
+ 0.089417f, 0.096008f, 0.103271f, 0.110718f, 0.119324f, 0.128052f, 0.137817f, 0.147705f, 0.158691f, 0.169922f, 0.181519f, 0.195435f,
+ 0.208496f, 0.222534f, 0.237305f, 0.252441f, 0.268799f, 0.285645f, 0.302979f, 0.322266f, 0.340332f, 0.360840f, 0.683594f, 0.708984f,
+ 0.714355f, 0.715332f, 0.715820f, 0.715332f, 0.000700f, 0.002043f, 0.003139f, 0.004219f, 0.005417f, 0.006477f, 0.007442f, 0.008415f,
+ 0.009499f, 0.010475f, 0.011497f, 0.012619f, 0.013824f, 0.014969f, 0.016190f, 0.017639f, 0.018799f, 0.020386f, 0.021896f, 0.023560f,
+ 0.025131f, 0.027176f, 0.028900f, 0.031067f, 0.033295f, 0.035919f, 0.038239f, 0.041229f, 0.044373f, 0.047394f, 0.050934f, 0.054871f,
+ 0.058838f, 0.063293f, 0.068115f, 0.073303f, 0.078857f, 0.084839f, 0.091309f, 0.098328f, 0.106079f, 0.114136f, 0.123230f, 0.132690f,
+ 0.143066f, 0.153442f, 0.165161f, 0.177368f, 0.190186f, 0.203979f, 0.218262f, 0.232910f, 0.248901f, 0.265381f, 0.282227f, 0.301025f,
+ 0.319580f, 0.339355f, 0.672852f, 0.699707f, 0.704590f, 0.706055f, 0.706543f, 0.706055f, 0.000762f, 0.001804f, 0.002762f, 0.003914f,
+ 0.004791f, 0.005764f, 0.006542f, 0.007622f, 0.008606f, 0.009232f, 0.010178f, 0.011093f, 0.012108f, 0.013191f, 0.014412f, 0.015289f,
+ 0.016510f, 0.017731f, 0.019119f, 0.020615f, 0.022049f, 0.023483f, 0.025345f, 0.027100f, 0.028885f, 0.031067f, 0.033417f, 0.035797f,
+ 0.038422f, 0.041382f, 0.044495f, 0.047638f, 0.051178f, 0.055267f, 0.059387f, 0.064026f, 0.069092f, 0.074585f, 0.080566f, 0.087097f,
+ 0.093811f, 0.101624f, 0.109619f, 0.117798f, 0.127319f, 0.137817f, 0.148682f, 0.160278f, 0.172607f, 0.185669f, 0.199097f, 0.214233f,
+ 0.229492f, 0.245850f, 0.261963f, 0.280273f, 0.299316f, 0.319580f, 0.660645f, 0.689453f, 0.694824f, 0.696777f, 0.697266f, 0.697266f,
+ 0.000499f, 0.001527f, 0.002565f, 0.003622f, 0.004429f, 0.005138f, 0.005955f, 0.006691f, 0.007317f, 0.008156f, 0.008949f, 0.009903f,
+ 0.010635f, 0.011452f, 0.012512f, 0.013451f, 0.014503f, 0.015610f, 0.016632f, 0.017746f, 0.019073f, 0.020355f, 0.021957f, 0.023453f,
+ 0.025208f, 0.026932f, 0.028732f, 0.030945f, 0.033142f, 0.035614f, 0.038300f, 0.041199f, 0.044464f, 0.047760f, 0.051514f, 0.055573f,
+ 0.059998f, 0.064819f, 0.070312f, 0.075867f, 0.082275f, 0.088806f, 0.096436f, 0.104797f, 0.113342f, 0.122559f, 0.132568f, 0.143799f,
+ 0.155396f, 0.167725f, 0.181274f, 0.195068f, 0.209961f, 0.225708f, 0.242310f, 0.259766f, 0.277832f, 0.297363f, 0.648926f, 0.678711f,
+ 0.685059f, 0.687500f, 0.687500f, 0.687988f, 0.000653f, 0.001627f, 0.002562f, 0.003166f, 0.003872f, 0.004562f, 0.005287f, 0.005905f,
+ 0.006557f, 0.007309f, 0.007835f, 0.008621f, 0.009140f, 0.010109f, 0.010773f, 0.011627f, 0.012428f, 0.013351f, 0.014488f, 0.015472f,
+ 0.016479f, 0.017578f, 0.018845f, 0.020157f, 0.021591f, 0.023132f, 0.024765f, 0.026337f, 0.028473f, 0.030594f, 0.032867f, 0.035309f,
+ 0.037933f, 0.041107f, 0.044403f, 0.047852f, 0.051666f, 0.055756f, 0.060455f, 0.065552f, 0.070740f, 0.077454f, 0.083862f, 0.091125f,
+ 0.099304f, 0.107971f, 0.117859f, 0.127808f, 0.139038f, 0.150757f, 0.163574f, 0.176880f, 0.191162f, 0.206665f, 0.222656f, 0.239258f,
+ 0.257568f, 0.277100f, 0.636230f, 0.667969f, 0.675293f, 0.677734f, 0.678223f, 0.678711f, 0.000393f, 0.001375f, 0.002174f, 0.002773f,
+ 0.003334f, 0.004070f, 0.004692f, 0.005047f, 0.005672f, 0.006298f, 0.006893f, 0.007454f, 0.007957f, 0.008636f, 0.009171f, 0.010002f,
+ 0.010674f, 0.011574f, 0.012451f, 0.013145f, 0.014091f, 0.014893f, 0.016083f, 0.017151f, 0.018402f, 0.019714f, 0.021042f, 0.022415f,
+ 0.024155f, 0.026108f, 0.027786f, 0.030212f, 0.032379f, 0.034698f, 0.037415f, 0.040436f, 0.043793f, 0.047455f, 0.051727f, 0.056030f,
+ 0.061218f, 0.066284f, 0.072571f, 0.079041f, 0.086121f, 0.094299f, 0.102844f, 0.112305f, 0.122925f, 0.134033f, 0.145752f, 0.158569f,
+ 0.172729f, 0.187378f, 0.203003f, 0.219238f, 0.237671f, 0.255859f, 0.624023f, 0.657227f, 0.664062f, 0.666992f, 0.668457f, 0.668457f,
+ 0.000379f, 0.001404f, 0.001893f, 0.002403f, 0.002840f, 0.003458f, 0.004021f, 0.004459f, 0.004894f, 0.005527f, 0.005844f, 0.006256f,
+ 0.006866f, 0.007423f, 0.007957f, 0.008476f, 0.009155f, 0.009735f, 0.010422f, 0.011078f, 0.011925f, 0.012787f, 0.013458f, 0.014526f,
+ 0.015541f, 0.016632f, 0.017838f, 0.019028f, 0.020248f, 0.021851f, 0.023514f, 0.024979f, 0.027054f, 0.029236f, 0.031555f, 0.034180f,
+ 0.036713f, 0.040375f, 0.043854f, 0.047607f, 0.051727f, 0.056549f, 0.061768f, 0.067627f, 0.073792f, 0.081116f, 0.089111f, 0.097595f,
+ 0.107056f, 0.117371f, 0.128906f, 0.141113f, 0.154053f, 0.168579f, 0.183960f, 0.199585f, 0.216309f, 0.235352f, 0.612793f, 0.647949f,
+ 0.652832f, 0.656250f, 0.658691f, 0.658203f, 0.000506f, 0.001164f, 0.001575f, 0.002136f, 0.002600f, 0.003054f, 0.003405f, 0.003735f,
+ 0.004364f, 0.004681f, 0.004944f, 0.005569f, 0.005810f, 0.006187f, 0.006813f, 0.007233f, 0.007881f, 0.008217f, 0.008850f, 0.009293f,
+ 0.010109f, 0.010788f, 0.011543f, 0.012161f, 0.012993f, 0.013931f, 0.014809f, 0.015945f, 0.016983f, 0.018234f, 0.019440f, 0.020813f,
+ 0.022491f, 0.024261f, 0.026169f, 0.028458f, 0.030701f, 0.033295f, 0.036560f, 0.039520f, 0.043121f, 0.047333f, 0.052032f, 0.056885f,
+ 0.062561f, 0.068909f, 0.076111f, 0.083496f, 0.092407f, 0.101929f, 0.112671f, 0.124451f, 0.136719f, 0.150146f, 0.165039f, 0.180786f,
+ 0.197510f, 0.215210f, 0.597656f, 0.636230f, 0.642578f, 0.647461f, 0.647949f, 0.649902f, 0.000344f, 0.001057f, 0.001456f, 0.001907f,
+ 0.002377f, 0.002735f, 0.002983f, 0.003359f, 0.003651f, 0.003960f, 0.004311f, 0.004471f, 0.005009f, 0.005283f, 0.005653f, 0.006145f,
+ 0.006592f, 0.006889f, 0.007469f, 0.007889f, 0.008423f, 0.008911f, 0.009567f, 0.010124f, 0.010788f, 0.011574f, 0.012466f, 0.013123f,
+ 0.014053f, 0.015091f, 0.016159f, 0.017288f, 0.018539f, 0.020111f, 0.021698f, 0.023285f, 0.025024f, 0.027405f, 0.029800f, 0.032501f,
+ 0.035583f, 0.039001f, 0.042908f, 0.047302f, 0.052185f, 0.057465f, 0.063843f, 0.070984f, 0.078857f, 0.087463f, 0.097168f, 0.108215f,
+ 0.120117f, 0.132812f, 0.146851f, 0.161865f, 0.177856f, 0.195557f, 0.585449f, 0.624023f, 0.633301f, 0.636230f, 0.637695f, 0.638672f,
+ 0.000516f, 0.000847f, 0.001210f, 0.001663f, 0.002012f, 0.002218f, 0.002424f, 0.002861f, 0.002947f, 0.003275f, 0.003469f, 0.003819f,
+ 0.004169f, 0.004337f, 0.004658f, 0.005169f, 0.005424f, 0.005795f, 0.006138f, 0.006500f, 0.007057f, 0.007458f, 0.007874f, 0.008369f,
+ 0.008888f, 0.009583f, 0.010147f, 0.010864f, 0.011589f, 0.012428f, 0.013161f, 0.013931f, 0.015076f, 0.016266f, 0.017456f, 0.018845f,
+ 0.020432f, 0.022232f, 0.024094f, 0.026459f, 0.028809f, 0.031586f, 0.034973f, 0.038513f, 0.042755f, 0.047485f, 0.052643f, 0.058929f,
+ 0.065796f, 0.073792f, 0.082581f, 0.092407f, 0.103516f, 0.115723f, 0.128906f, 0.142944f, 0.158813f, 0.175781f, 0.572266f, 0.613770f,
+ 0.621094f, 0.625977f, 0.626953f, 0.628418f, 0.000262f, 0.000864f, 0.001096f, 0.001409f, 0.001576f, 0.001852f, 0.002047f, 0.002247f,
+ 0.002518f, 0.002741f, 0.002956f, 0.003157f, 0.003359f, 0.003597f, 0.003872f, 0.004230f, 0.004406f, 0.004772f, 0.005035f, 0.005379f,
+ 0.005695f, 0.006153f, 0.006485f, 0.006935f, 0.007275f, 0.007801f, 0.008301f, 0.008789f, 0.009300f, 0.009949f, 0.010727f, 0.011482f,
+ 0.012245f, 0.013145f, 0.014236f, 0.015236f, 0.016525f, 0.017838f, 0.019348f, 0.021088f, 0.023010f, 0.025253f, 0.027878f, 0.031128f,
+ 0.034149f, 0.038269f, 0.042694f, 0.047852f, 0.053833f, 0.060852f, 0.068665f, 0.077698f, 0.087891f, 0.099182f, 0.111633f, 0.125732f,
+ 0.140381f, 0.157227f, 0.558105f, 0.601562f, 0.610840f, 0.614746f, 0.617188f, 0.619141f, 0.000270f, 0.000683f, 0.000851f, 0.001138f,
+ 0.001346f, 0.001561f, 0.001701f, 0.001884f, 0.001984f, 0.002193f, 0.002455f, 0.002609f, 0.002743f, 0.002993f, 0.003159f, 0.003361f,
+ 0.003593f, 0.003883f, 0.004044f, 0.004360f, 0.004532f, 0.004971f, 0.005169f, 0.005573f, 0.005863f, 0.006252f, 0.006653f, 0.007095f,
+ 0.007572f, 0.008110f, 0.008713f, 0.009056f, 0.009827f, 0.010574f, 0.011307f, 0.012070f, 0.013069f, 0.014122f, 0.015297f, 0.016678f,
+ 0.018234f, 0.019775f, 0.021835f, 0.024216f, 0.026917f, 0.030151f, 0.033875f, 0.038147f, 0.043121f, 0.049408f, 0.056091f, 0.064026f,
+ 0.073059f, 0.083801f, 0.095276f, 0.108459f, 0.122803f, 0.138794f, 0.545410f, 0.590332f, 0.599609f, 0.603516f, 0.606445f, 0.607422f,
+ 0.000190f, 0.000607f, 0.000724f, 0.000989f, 0.001171f, 0.001265f, 0.001416f, 0.001602f, 0.001666f, 0.001761f, 0.001893f, 0.002102f,
+ 0.002199f, 0.002413f, 0.002537f, 0.002743f, 0.002850f, 0.003027f, 0.003258f, 0.003494f, 0.003729f, 0.003937f, 0.004204f, 0.004410f,
+ 0.004616f, 0.004921f, 0.005192f, 0.005604f, 0.005936f, 0.006298f, 0.006836f, 0.007233f, 0.007694f, 0.008224f, 0.008827f, 0.009506f,
+ 0.010262f, 0.011055f, 0.011978f, 0.012955f, 0.014099f, 0.015434f, 0.017029f, 0.018677f, 0.020813f, 0.023193f, 0.026169f, 0.029541f,
+ 0.033783f, 0.038513f, 0.044403f, 0.051208f, 0.059387f, 0.068665f, 0.079468f, 0.091858f, 0.105774f, 0.120728f, 0.530762f, 0.578125f,
+ 0.588379f, 0.592773f, 0.595215f, 0.597168f, 0.000151f, 0.000443f, 0.000673f, 0.000793f, 0.000937f, 0.000987f, 0.001092f, 0.001192f,
+ 0.001324f, 0.001460f, 0.001495f, 0.001565f, 0.001778f, 0.001944f, 0.002054f, 0.002096f, 0.002254f, 0.002338f, 0.002594f, 0.002737f,
+ 0.002886f, 0.003048f, 0.003294f, 0.003460f, 0.003679f, 0.003868f, 0.004086f, 0.004322f, 0.004642f, 0.004894f, 0.005199f, 0.005554f,
+ 0.006035f, 0.006451f, 0.006836f, 0.007359f, 0.007820f, 0.008461f, 0.009163f, 0.009956f, 0.010803f, 0.011871f, 0.012917f, 0.014343f,
+ 0.015900f, 0.017670f, 0.019791f, 0.022400f, 0.025589f, 0.029404f, 0.034210f, 0.039948f, 0.046936f, 0.055298f, 0.064941f, 0.076172f,
+ 0.089172f, 0.103821f, 0.517090f, 0.565918f, 0.576172f, 0.582031f, 0.584961f, 0.586426f, 0.000203f, 0.000287f, 0.000531f, 0.000688f,
+ 0.000738f, 0.000820f, 0.000915f, 0.000875f, 0.001036f, 0.001117f, 0.001215f, 0.001317f, 0.001374f, 0.001476f, 0.001524f, 0.001682f,
+ 0.001726f, 0.001867f, 0.002014f, 0.002056f, 0.002209f, 0.002365f, 0.002495f, 0.002663f, 0.002775f, 0.002953f, 0.003134f, 0.003325f,
+ 0.003567f, 0.003736f, 0.004070f, 0.004261f, 0.004494f, 0.004845f, 0.005116f, 0.005459f, 0.005928f, 0.006329f, 0.006863f, 0.007458f,
+ 0.008087f, 0.008873f, 0.009689f, 0.010651f, 0.011826f, 0.013130f, 0.014732f, 0.016617f, 0.018890f, 0.021912f, 0.025482f, 0.029938f,
+ 0.035736f, 0.042847f, 0.051453f, 0.061615f, 0.074158f, 0.087952f, 0.504395f, 0.554199f, 0.565918f, 0.569336f, 0.573242f, 0.574219f,
+ 0.000215f, 0.000259f, 0.000423f, 0.000534f, 0.000499f, 0.000649f, 0.000622f, 0.000690f, 0.000717f, 0.000817f, 0.000937f, 0.000984f,
+ 0.001045f, 0.001148f, 0.001182f, 0.001211f, 0.001339f, 0.001406f, 0.001463f, 0.001590f, 0.001666f, 0.001759f, 0.001867f, 0.001949f,
+ 0.002064f, 0.002176f, 0.002342f, 0.002453f, 0.002619f, 0.002871f, 0.003033f, 0.003101f, 0.003389f, 0.003620f, 0.003794f, 0.004059f,
+ 0.004368f, 0.004681f, 0.005035f, 0.005466f, 0.005917f, 0.006405f, 0.007092f, 0.007744f, 0.008591f, 0.009506f, 0.010567f, 0.011993f,
+ 0.013710f, 0.015762f, 0.018326f, 0.021759f, 0.026077f, 0.031891f, 0.039124f, 0.048462f, 0.059570f, 0.072571f, 0.489258f, 0.542480f,
+ 0.553223f, 0.558594f, 0.562012f, 0.563965f, 0.000067f, 0.000253f, 0.000305f, 0.000367f, 0.000422f, 0.000431f, 0.000530f, 0.000466f,
+ 0.000565f, 0.000590f, 0.000702f, 0.000690f, 0.000746f, 0.000795f, 0.000859f, 0.000897f, 0.000962f, 0.001021f, 0.001069f, 0.001105f,
+ 0.001207f, 0.001257f, 0.001354f, 0.001424f, 0.001483f, 0.001570f, 0.001687f, 0.001750f, 0.001857f, 0.001982f, 0.002071f, 0.002281f,
+ 0.002361f, 0.002527f, 0.002684f, 0.002846f, 0.003092f, 0.003342f, 0.003622f, 0.003866f, 0.004173f, 0.004520f, 0.004955f, 0.005428f,
+ 0.006023f, 0.006687f, 0.007481f, 0.008446f, 0.009628f, 0.011047f, 0.012840f, 0.015205f, 0.018326f, 0.022629f, 0.028442f, 0.036102f,
+ 0.046051f, 0.058197f, 0.476318f, 0.529785f, 0.541992f, 0.547852f, 0.550293f, 0.553223f, 0.000000f, 0.000118f, 0.000216f, 0.000288f,
+ 0.000272f, 0.000350f, 0.000312f, 0.000374f, 0.000395f, 0.000470f, 0.000488f, 0.000477f, 0.000495f, 0.000548f, 0.000573f, 0.000646f,
+ 0.000636f, 0.000714f, 0.000763f, 0.000803f, 0.000852f, 0.000897f, 0.000930f, 0.000985f, 0.001056f, 0.001089f, 0.001163f, 0.001210f,
+ 0.001281f, 0.001432f, 0.001431f, 0.001548f, 0.001622f, 0.001743f, 0.001869f, 0.001991f, 0.002104f, 0.002262f, 0.002428f, 0.002632f,
+ 0.002815f, 0.003077f, 0.003344f, 0.003656f, 0.004002f, 0.004478f, 0.004974f, 0.005627f, 0.006435f, 0.007481f, 0.008713f, 0.010307f,
+ 0.012291f, 0.015289f, 0.019409f, 0.025497f, 0.033966f, 0.045013f, 0.461914f, 0.517090f, 0.529297f, 0.536133f, 0.539551f, 0.541504f,
+ 0.000073f, 0.000175f, 0.000165f, 0.000149f, 0.000200f, 0.000208f, 0.000215f, 0.000260f, 0.000268f, 0.000277f, 0.000292f, 0.000341f,
+ 0.000334f, 0.000370f, 0.000413f, 0.000424f, 0.000449f, 0.000474f, 0.000488f, 0.000507f, 0.000555f, 0.000574f, 0.000616f, 0.000652f,
+ 0.000696f, 0.000746f, 0.000780f, 0.000804f, 0.000849f, 0.000888f, 0.000949f, 0.001011f, 0.001075f, 0.001151f, 0.001225f, 0.001266f,
+ 0.001385f, 0.001466f, 0.001596f, 0.001699f, 0.001808f, 0.001980f, 0.002157f, 0.002329f, 0.002544f, 0.002850f, 0.003178f, 0.003593f,
+ 0.004047f, 0.004658f, 0.005508f, 0.006565f, 0.007935f, 0.009819f, 0.012527f, 0.016647f, 0.023514f, 0.033173f, 0.447510f, 0.503906f,
+ 0.517578f, 0.523926f, 0.527344f, 0.529297f, 0.000000f, 0.000106f, 0.000097f, 0.000099f, 0.000136f, 0.000157f, 0.000129f, 0.000162f,
+ 0.000167f, 0.000172f, 0.000180f, 0.000186f, 0.000209f, 0.000227f, 0.000232f, 0.000248f, 0.000260f, 0.000291f, 0.000300f, 0.000327f,
+ 0.000335f, 0.000343f, 0.000363f, 0.000395f, 0.000428f, 0.000459f, 0.000458f, 0.000477f, 0.000515f, 0.000549f, 0.000578f, 0.000621f,
+ 0.000659f, 0.000683f, 0.000741f, 0.000767f, 0.000818f, 0.000877f, 0.000952f, 0.001010f, 0.001085f, 0.001177f, 0.001275f, 0.001406f,
+ 0.001516f, 0.001664f, 0.001884f, 0.002096f, 0.002415f, 0.002745f, 0.003231f, 0.003843f, 0.004715f, 0.005936f, 0.007629f, 0.010139f,
+ 0.014763f, 0.022812f, 0.433350f, 0.491455f, 0.506348f, 0.511719f, 0.515625f, 0.518066f, 0.000104f, 0.000080f, 0.000069f, 0.000062f,
+ 0.000074f, 0.000074f, 0.000089f, 0.000097f, 0.000099f, 0.000102f, 0.000105f, 0.000126f, 0.000106f, 0.000119f, 0.000139f, 0.000135f,
+ 0.000154f, 0.000164f, 0.000166f, 0.000175f, 0.000188f, 0.000194f, 0.000211f, 0.000220f, 0.000252f, 0.000248f, 0.000260f, 0.000272f,
+ 0.000293f, 0.000301f, 0.000328f, 0.000347f, 0.000365f, 0.000371f, 0.000401f, 0.000422f, 0.000447f, 0.000489f, 0.000524f, 0.000553f,
+ 0.000588f, 0.000635f, 0.000701f, 0.000751f, 0.000816f, 0.000897f, 0.000997f, 0.001109f, 0.001265f, 0.001460f, 0.001686f, 0.002035f,
+ 0.002457f, 0.003130f, 0.004124f, 0.005676f, 0.008263f, 0.014114f, 0.418945f, 0.479492f, 0.493652f, 0.500000f, 0.503418f, 0.506836f,
+ 0.000089f, 0.000065f, 0.000056f, 0.000050f, 0.000045f, 0.000042f, 0.000046f, 0.000042f, 0.000043f, 0.000055f, 0.000046f, 0.000049f,
+ 0.000065f, 0.000055f, 0.000057f, 0.000063f, 0.000075f, 0.000080f, 0.000078f, 0.000084f, 0.000085f, 0.000092f, 0.000097f, 0.000102f,
+ 0.000108f, 0.000117f, 0.000118f, 0.000138f, 0.000135f, 0.000142f, 0.000151f, 0.000160f, 0.000172f, 0.000180f, 0.000195f, 0.000197f,
+ 0.000210f, 0.000230f, 0.000244f, 0.000266f, 0.000279f, 0.000299f, 0.000324f, 0.000352f, 0.000383f, 0.000414f, 0.000457f, 0.000509f,
+ 0.000575f, 0.000650f, 0.000756f, 0.000904f, 0.001103f, 0.001410f, 0.001880f, 0.002668f, 0.004112f, 0.007290f, 0.404541f, 0.466309f,
+ 0.481201f, 0.488037f, 0.492432f, 0.495361f, 0.000066f, 0.000046f, 0.000038f, 0.000034f, 0.000031f, 0.000029f, 0.000027f, 0.000026f,
+ 0.000025f, 0.000023f, 0.000022f, 0.000024f, 0.000020f, 0.000021f, 0.000021f, 0.000026f, 0.000024f, 0.000028f, 0.000031f, 0.000032f,
+ 0.000032f, 0.000035f, 0.000040f, 0.000038f, 0.000041f, 0.000047f, 0.000049f, 0.000043f, 0.000050f, 0.000052f, 0.000056f, 0.000059f,
+ 0.000066f, 0.000062f, 0.000067f, 0.000071f, 0.000082f, 0.000083f, 0.000089f, 0.000098f, 0.000104f, 0.000107f, 0.000116f, 0.000125f,
+ 0.000141f, 0.000149f, 0.000160f, 0.000183f, 0.000207f, 0.000228f, 0.000264f, 0.000311f, 0.000376f, 0.000469f, 0.000646f, 0.000937f,
+ 0.001554f, 0.002983f, 0.390381f, 0.454346f, 0.469727f, 0.476318f, 0.480713f, 0.484131f, 0.000028f, 0.000019f, 0.000015f, 0.000014f,
+ 0.000014f, 0.000013f, 0.000012f, 0.000012f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000010f,
+ 0.000010f, 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000008f, 0.000007f, 0.000008f, 0.000009f, 0.000009f, 0.000010f,
+ 0.000010f, 0.000011f, 0.000012f, 0.000011f, 0.000014f, 0.000015f, 0.000016f, 0.000016f, 0.000018f, 0.000019f, 0.000019f, 0.000022f,
+ 0.000023f, 0.000024f, 0.000026f, 0.000028f, 0.000029f, 0.000032f, 0.000037f, 0.000037f, 0.000042f, 0.000048f, 0.000056f, 0.000066f,
+ 0.000077f, 0.000091f, 0.000124f, 0.000183f, 0.000318f, 0.000779f, 0.376465f, 0.441406f, 0.457275f, 0.464600f, 0.468994f, 0.471924f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000003f, 0.000004f, 0.000004f, 0.000005f, 0.000010f, 0.000027f, 0.363037f, 0.428223f,
+ 0.444580f, 0.452881f, 0.457031f, 0.459961f,
+ },
+ {
+ 0.014420f, 0.043488f, 0.072388f, 0.100830f, 0.129150f, 0.156494f, 0.183350f, 0.210327f, 0.235352f, 0.260986f, 0.285645f, 0.309082f,
+ 0.332764f, 0.355713f, 0.377441f, 0.399658f, 0.420898f, 0.441650f, 0.461914f, 0.481445f, 0.500977f, 0.520508f, 0.538574f, 0.556641f,
+ 0.574707f, 0.591797f, 0.608398f, 0.624512f, 0.641602f, 0.657227f, 0.672363f, 0.687500f, 0.702148f, 0.717285f, 0.730957f, 0.745117f,
+ 0.758789f, 0.772461f, 0.783203f, 0.797363f, 0.810547f, 0.822266f, 0.833984f, 0.845703f, 0.857422f, 0.868652f, 0.879395f, 0.890625f,
+ 0.901367f, 0.911621f, 0.921875f, 0.932129f, 0.941895f, 0.951660f, 0.960938f, 0.970215f, 0.979492f, 0.987793f, 0.981934f, 0.957031f,
+ 0.938965f, 0.923340f, 0.909668f, 0.897461f, 0.013199f, 0.039978f, 0.066284f, 0.093445f, 0.119324f, 0.145386f, 0.170410f, 0.195801f,
+ 0.220581f, 0.244019f, 0.268066f, 0.291260f, 0.314453f, 0.335938f, 0.358154f, 0.379639f, 0.399902f, 0.420898f, 0.441406f, 0.460938f,
+ 0.480225f, 0.498291f, 0.516602f, 0.535156f, 0.553223f, 0.570312f, 0.587891f, 0.603516f, 0.620117f, 0.636719f, 0.652832f, 0.667480f,
+ 0.682617f, 0.696777f, 0.711914f, 0.726074f, 0.739746f, 0.753418f, 0.766602f, 0.779785f, 0.791992f, 0.804688f, 0.817871f, 0.829102f,
+ 0.841309f, 0.852539f, 0.864258f, 0.875488f, 0.886230f, 0.896973f, 0.907227f, 0.917969f, 0.928223f, 0.937500f, 0.947266f, 0.957520f,
+ 0.966797f, 0.975586f, 0.976562f, 0.952637f, 0.935547f, 0.920898f, 0.907715f, 0.895996f, 0.011932f, 0.036499f, 0.061554f, 0.085999f,
+ 0.110962f, 0.135010f, 0.158813f, 0.182373f, 0.206421f, 0.229004f, 0.251221f, 0.274170f, 0.295654f, 0.317871f, 0.339111f, 0.360107f,
+ 0.379395f, 0.399414f, 0.420654f, 0.440430f, 0.458252f, 0.477295f, 0.496094f, 0.513672f, 0.531738f, 0.549805f, 0.566406f, 0.583984f,
+ 0.599121f, 0.616211f, 0.631348f, 0.647461f, 0.662598f, 0.677734f, 0.692383f, 0.705566f, 0.720703f, 0.734863f, 0.748047f, 0.761230f,
+ 0.774414f, 0.787598f, 0.799805f, 0.812500f, 0.824707f, 0.837402f, 0.848633f, 0.859375f, 0.871094f, 0.882324f, 0.892578f, 0.904297f,
+ 0.913574f, 0.924316f, 0.934570f, 0.943848f, 0.954102f, 0.963867f, 0.970703f, 0.948242f, 0.931641f, 0.917480f, 0.905273f, 0.894043f,
+ 0.011070f, 0.033478f, 0.056396f, 0.079529f, 0.101990f, 0.125244f, 0.147705f, 0.170410f, 0.192139f, 0.214111f, 0.235596f, 0.257812f,
+ 0.279053f, 0.300293f, 0.320557f, 0.340576f, 0.360596f, 0.381104f, 0.400635f, 0.420166f, 0.438965f, 0.458008f, 0.476562f, 0.493652f,
+ 0.511230f, 0.527832f, 0.545898f, 0.562012f, 0.579102f, 0.595703f, 0.610840f, 0.627930f, 0.642578f, 0.657227f, 0.672363f, 0.686523f,
+ 0.701660f, 0.715332f, 0.729492f, 0.742676f, 0.756348f, 0.769531f, 0.782227f, 0.795898f, 0.807617f, 0.820312f, 0.832031f, 0.843262f,
+ 0.855469f, 0.866699f, 0.877441f, 0.889648f, 0.899414f, 0.910156f, 0.920410f, 0.930664f, 0.940430f, 0.950684f, 0.964844f, 0.943848f,
+ 0.927734f, 0.914551f, 0.902344f, 0.891602f, 0.010010f, 0.031067f, 0.051880f, 0.073303f, 0.094421f, 0.116577f, 0.136963f, 0.157959f,
+ 0.180542f, 0.200684f, 0.221436f, 0.242676f, 0.262939f, 0.283447f, 0.303467f, 0.323242f, 0.342529f, 0.362305f, 0.381348f, 0.399414f,
+ 0.418701f, 0.437256f, 0.455322f, 0.472412f, 0.490479f, 0.507812f, 0.524902f, 0.541992f, 0.558105f, 0.574219f, 0.591309f, 0.606445f,
+ 0.622070f, 0.637695f, 0.652344f, 0.666504f, 0.683594f, 0.695801f, 0.710449f, 0.724121f, 0.737305f, 0.751465f, 0.765137f, 0.777344f,
+ 0.790039f, 0.802734f, 0.814941f, 0.827637f, 0.839355f, 0.851074f, 0.862305f, 0.874512f, 0.885254f, 0.895996f, 0.906738f, 0.917480f,
+ 0.927246f, 0.937988f, 0.958984f, 0.939453f, 0.923828f, 0.911133f, 0.899414f, 0.889160f, 0.009491f, 0.028305f, 0.047699f, 0.067810f,
+ 0.087341f, 0.107849f, 0.127686f, 0.147827f, 0.167725f, 0.187744f, 0.207886f, 0.227051f, 0.247314f, 0.266846f, 0.286377f, 0.305908f,
+ 0.324463f, 0.343262f, 0.361572f, 0.380371f, 0.399658f, 0.416748f, 0.435547f, 0.452881f, 0.470703f, 0.488281f, 0.503906f, 0.522461f,
+ 0.538086f, 0.554199f, 0.571289f, 0.586914f, 0.602051f, 0.617676f, 0.633789f, 0.647949f, 0.663086f, 0.677246f, 0.692871f, 0.705078f,
+ 0.718750f, 0.732910f, 0.746582f, 0.759766f, 0.773438f, 0.785645f, 0.798340f, 0.811035f, 0.823242f, 0.834961f, 0.847168f, 0.859863f,
+ 0.870117f, 0.881348f, 0.893066f, 0.903320f, 0.914551f, 0.924316f, 0.953125f, 0.934082f, 0.919434f, 0.906738f, 0.896484f, 0.885742f,
+ 0.008598f, 0.026245f, 0.044495f, 0.062622f, 0.081177f, 0.100098f, 0.119019f, 0.137817f, 0.156616f, 0.175903f, 0.194946f, 0.213745f,
+ 0.232788f, 0.251221f, 0.269775f, 0.288330f, 0.307129f, 0.325928f, 0.344238f, 0.362305f, 0.380371f, 0.397705f, 0.415771f, 0.433105f,
+ 0.450928f, 0.468262f, 0.484863f, 0.501953f, 0.518555f, 0.534668f, 0.550293f, 0.566406f, 0.582520f, 0.598145f, 0.612305f, 0.627930f,
+ 0.643555f, 0.657715f, 0.672852f, 0.687500f, 0.700684f, 0.715332f, 0.728516f, 0.742188f, 0.755371f, 0.769531f, 0.781738f, 0.794434f,
+ 0.807129f, 0.818359f, 0.831543f, 0.843262f, 0.855469f, 0.865723f, 0.877930f, 0.889160f, 0.900391f, 0.911621f, 0.946777f, 0.929199f,
+ 0.915039f, 0.903320f, 0.892578f, 0.883301f, 0.007896f, 0.024490f, 0.041138f, 0.057892f, 0.075439f, 0.092712f, 0.110229f, 0.128296f,
+ 0.146118f, 0.164429f, 0.181885f, 0.200562f, 0.218628f, 0.236572f, 0.255127f, 0.272949f, 0.291016f, 0.308594f, 0.326172f, 0.343994f,
+ 0.361816f, 0.380127f, 0.396973f, 0.414551f, 0.430908f, 0.447998f, 0.465576f, 0.481445f, 0.497559f, 0.514160f, 0.529785f, 0.546387f,
+ 0.562988f, 0.578613f, 0.593262f, 0.609375f, 0.623047f, 0.638672f, 0.653809f, 0.667480f, 0.681641f, 0.697266f, 0.710938f, 0.724121f,
+ 0.737305f, 0.752441f, 0.765625f, 0.776367f, 0.790527f, 0.803223f, 0.815918f, 0.827637f, 0.839844f, 0.851562f, 0.863281f, 0.875000f,
+ 0.886719f, 0.898926f, 0.940430f, 0.923828f, 0.910645f, 0.899414f, 0.889160f, 0.879883f, 0.007320f, 0.022369f, 0.038055f, 0.053925f,
+ 0.070190f, 0.086609f, 0.103027f, 0.119568f, 0.136475f, 0.153320f, 0.170532f, 0.187988f, 0.204834f, 0.223022f, 0.240112f, 0.257324f,
+ 0.275391f, 0.291504f, 0.308838f, 0.326904f, 0.344727f, 0.361572f, 0.378662f, 0.395020f, 0.411865f, 0.428711f, 0.445068f, 0.462646f,
+ 0.478271f, 0.494141f, 0.510254f, 0.525879f, 0.542480f, 0.557129f, 0.573242f, 0.588867f, 0.603516f, 0.618164f, 0.633789f, 0.648438f,
+ 0.663086f, 0.678223f, 0.691895f, 0.706543f, 0.720215f, 0.733398f, 0.746582f, 0.759766f, 0.774414f, 0.786621f, 0.799805f, 0.811523f,
+ 0.823730f, 0.836914f, 0.848145f, 0.860840f, 0.872070f, 0.884277f, 0.933594f, 0.918945f, 0.906250f, 0.895020f, 0.885254f, 0.876953f,
+ 0.006760f, 0.021011f, 0.034973f, 0.050049f, 0.065369f, 0.080261f, 0.095337f, 0.111633f, 0.127319f, 0.142822f, 0.159668f, 0.176514f,
+ 0.192383f, 0.209106f, 0.225586f, 0.242554f, 0.259277f, 0.275635f, 0.292480f, 0.309326f, 0.326904f, 0.343750f, 0.359619f, 0.376465f,
+ 0.393066f, 0.409424f, 0.426514f, 0.442871f, 0.458252f, 0.475586f, 0.490967f, 0.505859f, 0.522461f, 0.539062f, 0.554199f, 0.569336f,
+ 0.583984f, 0.600586f, 0.614258f, 0.630371f, 0.643555f, 0.658691f, 0.673340f, 0.687500f, 0.702148f, 0.715332f, 0.729980f, 0.743652f,
+ 0.756348f, 0.770020f, 0.782715f, 0.796387f, 0.808105f, 0.820801f, 0.833008f, 0.846680f, 0.857910f, 0.870117f, 0.927246f, 0.913574f,
+ 0.901367f, 0.891113f, 0.881348f, 0.873047f, 0.006367f, 0.019165f, 0.032379f, 0.046295f, 0.060089f, 0.074463f, 0.088867f, 0.103821f,
+ 0.118835f, 0.133911f, 0.149048f, 0.164673f, 0.180298f, 0.196289f, 0.212524f, 0.228516f, 0.244385f, 0.260742f, 0.277344f, 0.293213f,
+ 0.309570f, 0.326416f, 0.342773f, 0.358887f, 0.374512f, 0.391113f, 0.406982f, 0.423340f, 0.439453f, 0.455078f, 0.470947f, 0.487793f,
+ 0.502441f, 0.519043f, 0.533691f, 0.550293f, 0.564941f, 0.580078f, 0.595703f, 0.610840f, 0.625488f, 0.640137f, 0.654785f, 0.669434f,
+ 0.683594f, 0.696777f, 0.710938f, 0.725586f, 0.738770f, 0.752441f, 0.766113f, 0.778320f, 0.791016f, 0.805176f, 0.818359f, 0.830566f,
+ 0.842773f, 0.854980f, 0.920410f, 0.908203f, 0.896484f, 0.886230f, 0.877441f, 0.868652f, 0.005981f, 0.017914f, 0.030350f, 0.042908f,
+ 0.056213f, 0.069092f, 0.083008f, 0.096619f, 0.111084f, 0.124634f, 0.139526f, 0.154297f, 0.169312f, 0.184570f, 0.199951f, 0.215454f,
+ 0.230713f, 0.245728f, 0.261963f, 0.277588f, 0.293213f, 0.309326f, 0.325195f, 0.340820f, 0.356934f, 0.373047f, 0.388916f, 0.404785f,
+ 0.420410f, 0.436279f, 0.452148f, 0.468506f, 0.483154f, 0.499756f, 0.515137f, 0.530762f, 0.545898f, 0.560059f, 0.576172f, 0.590820f,
+ 0.606445f, 0.621094f, 0.635254f, 0.649902f, 0.663574f, 0.678223f, 0.692383f, 0.706543f, 0.720703f, 0.733887f, 0.748535f, 0.762695f,
+ 0.775391f, 0.789551f, 0.801758f, 0.814941f, 0.828125f, 0.840332f, 0.913574f, 0.902344f, 0.890625f, 0.881836f, 0.872559f, 0.865234f,
+ 0.005402f, 0.016617f, 0.028061f, 0.039948f, 0.051758f, 0.064270f, 0.076782f, 0.089600f, 0.102600f, 0.116455f, 0.130371f, 0.144165f,
+ 0.158936f, 0.172607f, 0.187744f, 0.201904f, 0.216431f, 0.232422f, 0.247192f, 0.261719f, 0.277100f, 0.292480f, 0.308838f, 0.323975f,
+ 0.339355f, 0.355469f, 0.371338f, 0.386230f, 0.402344f, 0.417725f, 0.433350f, 0.448486f, 0.464600f, 0.480225f, 0.495361f, 0.510742f,
+ 0.525879f, 0.541992f, 0.557129f, 0.571777f, 0.586914f, 0.601562f, 0.616211f, 0.631836f, 0.645508f, 0.661621f, 0.674805f, 0.688965f,
+ 0.703125f, 0.717773f, 0.731934f, 0.745605f, 0.757812f, 0.772949f, 0.785156f, 0.799316f, 0.812012f, 0.826172f, 0.906738f, 0.896484f,
+ 0.886230f, 0.876465f, 0.868164f, 0.860840f, 0.005264f, 0.015457f, 0.026474f, 0.037170f, 0.048157f, 0.059845f, 0.071594f, 0.083984f,
+ 0.096191f, 0.109070f, 0.121887f, 0.134766f, 0.148193f, 0.161255f, 0.175781f, 0.189209f, 0.203369f, 0.218384f, 0.233032f, 0.247681f,
+ 0.261963f, 0.277100f, 0.292480f, 0.307129f, 0.322998f, 0.337891f, 0.352539f, 0.368652f, 0.384033f, 0.399170f, 0.414307f, 0.430420f,
+ 0.445801f, 0.460693f, 0.475342f, 0.491211f, 0.506836f, 0.521973f, 0.537598f, 0.551758f, 0.567383f, 0.582520f, 0.598145f, 0.612305f,
+ 0.627441f, 0.642090f, 0.656738f, 0.670898f, 0.685059f, 0.698730f, 0.713867f, 0.728516f, 0.742188f, 0.755371f, 0.770020f, 0.782715f,
+ 0.796387f, 0.810547f, 0.899414f, 0.889648f, 0.879883f, 0.872070f, 0.863770f, 0.856445f, 0.004719f, 0.014229f, 0.024384f, 0.034607f,
+ 0.044708f, 0.055756f, 0.066895f, 0.077942f, 0.089600f, 0.101624f, 0.113525f, 0.125854f, 0.138428f, 0.151245f, 0.164673f, 0.177734f,
+ 0.191650f, 0.205078f, 0.219360f, 0.233154f, 0.247925f, 0.261475f, 0.276367f, 0.291504f, 0.305908f, 0.320312f, 0.335449f, 0.350098f,
+ 0.365723f, 0.380615f, 0.395996f, 0.411133f, 0.427002f, 0.441895f, 0.456543f, 0.472656f, 0.487793f, 0.502441f, 0.518555f, 0.533203f,
+ 0.547852f, 0.562988f, 0.577637f, 0.593262f, 0.607910f, 0.623535f, 0.638184f, 0.652344f, 0.666992f, 0.681641f, 0.696777f, 0.711426f,
+ 0.725098f, 0.738281f, 0.753418f, 0.766113f, 0.782227f, 0.794922f, 0.892090f, 0.884277f, 0.875000f, 0.866699f, 0.858887f, 0.852539f,
+ 0.004280f, 0.013329f, 0.022476f, 0.031982f, 0.042114f, 0.051849f, 0.062225f, 0.072449f, 0.083679f, 0.095032f, 0.105530f, 0.117676f,
+ 0.129517f, 0.141357f, 0.154297f, 0.166748f, 0.178711f, 0.192505f, 0.205933f, 0.219727f, 0.233521f, 0.247070f, 0.260986f, 0.275391f,
+ 0.290039f, 0.303955f, 0.319580f, 0.333740f, 0.347412f, 0.363037f, 0.377686f, 0.392822f, 0.408203f, 0.422852f, 0.437988f, 0.453125f,
+ 0.468506f, 0.483398f, 0.498779f, 0.514160f, 0.527832f, 0.543945f, 0.559570f, 0.574707f, 0.588867f, 0.604492f, 0.619141f, 0.634277f,
+ 0.648438f, 0.663086f, 0.678223f, 0.692383f, 0.707520f, 0.721680f, 0.735352f, 0.749512f, 0.764648f, 0.778320f, 0.884277f, 0.877441f,
+ 0.868652f, 0.861328f, 0.854492f, 0.847656f, 0.004280f, 0.012138f, 0.021103f, 0.029999f, 0.038940f, 0.048279f, 0.057831f, 0.067566f,
+ 0.077454f, 0.087524f, 0.098816f, 0.109558f, 0.120728f, 0.131958f, 0.143799f, 0.155762f, 0.168091f, 0.180176f, 0.193359f, 0.206177f,
+ 0.219360f, 0.232910f, 0.246338f, 0.260254f, 0.273682f, 0.287598f, 0.302246f, 0.316650f, 0.331299f, 0.344971f, 0.359863f, 0.374268f,
+ 0.389648f, 0.404297f, 0.419434f, 0.434326f, 0.449463f, 0.464844f, 0.479492f, 0.494141f, 0.509766f, 0.524414f, 0.540039f, 0.555176f,
+ 0.569824f, 0.584961f, 0.600098f, 0.615723f, 0.629883f, 0.645508f, 0.659668f, 0.675293f, 0.689453f, 0.704590f, 0.719238f, 0.732422f,
+ 0.748535f, 0.762207f, 0.876953f, 0.871582f, 0.863281f, 0.855957f, 0.849609f, 0.842773f, 0.003744f, 0.011436f, 0.019348f, 0.027893f,
+ 0.036102f, 0.044739f, 0.053711f, 0.063110f, 0.072205f, 0.081970f, 0.091919f, 0.101746f, 0.112732f, 0.122864f, 0.134521f, 0.145996f,
+ 0.157715f, 0.169434f, 0.181519f, 0.193848f, 0.206665f, 0.219360f, 0.231445f, 0.245361f, 0.259033f, 0.272217f, 0.286621f, 0.299805f,
+ 0.314209f, 0.328125f, 0.342285f, 0.357178f, 0.371826f, 0.386475f, 0.400635f, 0.415527f, 0.430420f, 0.445068f, 0.459717f, 0.476074f,
+ 0.490234f, 0.505371f, 0.521484f, 0.536133f, 0.551758f, 0.565430f, 0.581543f, 0.595703f, 0.611816f, 0.626465f, 0.641602f, 0.656738f,
+ 0.671875f, 0.686523f, 0.701172f, 0.715820f, 0.731445f, 0.746582f, 0.868652f, 0.864746f, 0.856934f, 0.851074f, 0.844727f, 0.837891f,
+ 0.003595f, 0.011093f, 0.018265f, 0.025711f, 0.033600f, 0.041656f, 0.050140f, 0.058350f, 0.067505f, 0.076416f, 0.085632f, 0.095093f,
+ 0.104919f, 0.115295f, 0.125610f, 0.136108f, 0.147583f, 0.157959f, 0.169800f, 0.181519f, 0.193359f, 0.205933f, 0.218140f, 0.231323f,
+ 0.243652f, 0.257324f, 0.270508f, 0.283447f, 0.297363f, 0.311523f, 0.325928f, 0.339111f, 0.353516f, 0.367432f, 0.382812f, 0.396973f,
+ 0.412109f, 0.426758f, 0.441406f, 0.456055f, 0.471436f, 0.486328f, 0.501953f, 0.516113f, 0.531738f, 0.546875f, 0.562500f, 0.577637f,
+ 0.592773f, 0.607910f, 0.622559f, 0.638184f, 0.653809f, 0.669434f, 0.684082f, 0.699219f, 0.714355f, 0.729492f, 0.860840f, 0.857422f,
+ 0.852051f, 0.844727f, 0.839355f, 0.832520f, 0.003349f, 0.009933f, 0.016754f, 0.024063f, 0.031204f, 0.038849f, 0.046356f, 0.054413f,
+ 0.062744f, 0.070984f, 0.080017f, 0.088989f, 0.097778f, 0.107361f, 0.117004f, 0.127197f, 0.137451f, 0.148071f, 0.159180f, 0.169922f,
+ 0.181519f, 0.192993f, 0.204956f, 0.217407f, 0.229980f, 0.242188f, 0.254883f, 0.267578f, 0.281494f, 0.294434f, 0.307861f, 0.321533f,
+ 0.335693f, 0.350098f, 0.364258f, 0.379150f, 0.393066f, 0.407715f, 0.422607f, 0.437500f, 0.452148f, 0.467041f, 0.482422f, 0.497314f,
+ 0.512695f, 0.527832f, 0.542969f, 0.558594f, 0.573730f, 0.589844f, 0.604004f, 0.619629f, 0.635254f, 0.651367f, 0.665527f, 0.681152f,
+ 0.696289f, 0.711914f, 0.852539f, 0.851562f, 0.846191f, 0.838867f, 0.832520f, 0.827637f, 0.003290f, 0.009415f, 0.015976f, 0.022095f,
+ 0.028946f, 0.036255f, 0.043396f, 0.050598f, 0.058502f, 0.066284f, 0.074036f, 0.082275f, 0.091187f, 0.099731f, 0.108826f, 0.118652f,
+ 0.128296f, 0.137939f, 0.148193f, 0.159302f, 0.170166f, 0.180786f, 0.191895f, 0.203491f, 0.215210f, 0.227661f, 0.240112f, 0.252686f,
+ 0.265625f, 0.278564f, 0.291748f, 0.305176f, 0.318604f, 0.332764f, 0.346924f, 0.360352f, 0.375000f, 0.389160f, 0.404297f, 0.418213f,
+ 0.433105f, 0.448486f, 0.463135f, 0.477783f, 0.493408f, 0.508301f, 0.523438f, 0.540039f, 0.554199f, 0.570312f, 0.585938f, 0.601074f,
+ 0.617188f, 0.633301f, 0.648926f, 0.664062f, 0.679688f, 0.695312f, 0.844727f, 0.844238f, 0.838867f, 0.833008f, 0.827148f, 0.822266f,
+ 0.002913f, 0.008621f, 0.014595f, 0.020950f, 0.027496f, 0.033600f, 0.040558f, 0.047119f, 0.054260f, 0.061615f, 0.068970f, 0.076782f,
+ 0.084717f, 0.093140f, 0.101562f, 0.109985f, 0.118591f, 0.129150f, 0.138306f, 0.148682f, 0.158447f, 0.169189f, 0.180054f, 0.191162f,
+ 0.202148f, 0.213379f, 0.225586f, 0.237305f, 0.250488f, 0.262939f, 0.275391f, 0.288086f, 0.302490f, 0.315186f, 0.329346f, 0.342529f,
+ 0.356934f, 0.370117f, 0.385742f, 0.400146f, 0.414795f, 0.429199f, 0.444336f, 0.459473f, 0.473389f, 0.489258f, 0.503906f, 0.519531f,
+ 0.535645f, 0.551270f, 0.566895f, 0.582520f, 0.598145f, 0.614258f, 0.629395f, 0.645996f, 0.661621f, 0.677734f, 0.837402f, 0.836914f,
+ 0.832520f, 0.826660f, 0.821777f, 0.816406f, 0.002748f, 0.008018f, 0.014168f, 0.019196f, 0.025040f, 0.031250f, 0.037506f, 0.043732f,
+ 0.050415f, 0.057098f, 0.063721f, 0.071167f, 0.078979f, 0.086609f, 0.094299f, 0.102783f, 0.111145f, 0.119812f, 0.128296f, 0.138306f,
+ 0.147583f, 0.157593f, 0.168213f, 0.178711f, 0.188843f, 0.200317f, 0.211792f, 0.223511f, 0.235352f, 0.247192f, 0.259521f, 0.272461f,
+ 0.285156f, 0.298584f, 0.312012f, 0.324707f, 0.339111f, 0.352783f, 0.366943f, 0.381348f, 0.395996f, 0.410889f, 0.425537f, 0.439941f,
+ 0.454834f, 0.470459f, 0.485352f, 0.501953f, 0.516113f, 0.531738f, 0.547363f, 0.563477f, 0.579102f, 0.595703f, 0.611328f, 0.626953f,
+ 0.642578f, 0.659668f, 0.828125f, 0.830566f, 0.825684f, 0.820801f, 0.815430f, 0.811035f, 0.002630f, 0.007412f, 0.012978f, 0.018356f,
+ 0.023758f, 0.028931f, 0.034729f, 0.040894f, 0.046631f, 0.053101f, 0.059143f, 0.065979f, 0.073669f, 0.080200f, 0.087585f, 0.095276f,
+ 0.102844f, 0.111633f, 0.119812f, 0.128296f, 0.137573f, 0.146729f, 0.156128f, 0.166382f, 0.176880f, 0.187256f, 0.197998f, 0.209351f,
+ 0.220581f, 0.232422f, 0.244385f, 0.256592f, 0.268799f, 0.281982f, 0.294922f, 0.308105f, 0.321045f, 0.334717f, 0.348633f, 0.363525f,
+ 0.378174f, 0.391846f, 0.406006f, 0.420898f, 0.436279f, 0.451660f, 0.466064f, 0.481934f, 0.496826f, 0.513184f, 0.528320f, 0.543945f,
+ 0.560059f, 0.576660f, 0.592285f, 0.608887f, 0.625000f, 0.640625f, 0.819336f, 0.822266f, 0.818848f, 0.813965f, 0.810059f, 0.805664f,
+ 0.002201f, 0.007240f, 0.011803f, 0.016617f, 0.021622f, 0.027344f, 0.032288f, 0.037598f, 0.043427f, 0.049194f, 0.055267f, 0.061462f,
+ 0.067566f, 0.073853f, 0.080872f, 0.088013f, 0.095703f, 0.103821f, 0.111145f, 0.119446f, 0.127563f, 0.136597f, 0.145752f, 0.155273f,
+ 0.165039f, 0.174683f, 0.185181f, 0.195801f, 0.206543f, 0.218140f, 0.229370f, 0.241455f, 0.253174f, 0.265381f, 0.278564f, 0.291504f,
+ 0.304199f, 0.317383f, 0.331299f, 0.344971f, 0.358643f, 0.373291f, 0.386963f, 0.402100f, 0.416016f, 0.431641f, 0.447266f, 0.462646f,
+ 0.477295f, 0.493652f, 0.509277f, 0.524902f, 0.541504f, 0.557617f, 0.574219f, 0.589844f, 0.605957f, 0.623047f, 0.810059f, 0.814453f,
+ 0.811035f, 0.807129f, 0.803223f, 0.798828f, 0.002293f, 0.006927f, 0.010994f, 0.015617f, 0.020584f, 0.025131f, 0.029663f, 0.034760f,
+ 0.040192f, 0.045532f, 0.050964f, 0.056793f, 0.062805f, 0.068726f, 0.074890f, 0.081482f, 0.088806f, 0.096069f, 0.103333f, 0.110535f,
+ 0.118896f, 0.126709f, 0.135254f, 0.144165f, 0.153442f, 0.162720f, 0.172119f, 0.182495f, 0.192749f, 0.203735f, 0.214600f, 0.225952f,
+ 0.237793f, 0.250000f, 0.261719f, 0.274170f, 0.287354f, 0.300293f, 0.313477f, 0.326904f, 0.340820f, 0.354980f, 0.369385f, 0.383545f,
+ 0.396973f, 0.411865f, 0.427734f, 0.442871f, 0.458740f, 0.473633f, 0.489502f, 0.505859f, 0.522461f, 0.537598f, 0.553711f, 0.572754f,
+ 0.588379f, 0.604492f, 0.802246f, 0.807617f, 0.804199f, 0.800781f, 0.797363f, 0.792969f, 0.002081f, 0.006172f, 0.010460f, 0.014503f,
+ 0.019104f, 0.023163f, 0.027832f, 0.032410f, 0.037354f, 0.041992f, 0.047211f, 0.052490f, 0.057831f, 0.063232f, 0.069458f, 0.075317f,
+ 0.082153f, 0.088257f, 0.094910f, 0.102295f, 0.110107f, 0.117554f, 0.125122f, 0.133667f, 0.142456f, 0.151001f, 0.160767f, 0.169922f,
+ 0.179443f, 0.190430f, 0.200562f, 0.211914f, 0.222412f, 0.234009f, 0.245850f, 0.258545f, 0.270752f, 0.283203f, 0.296387f, 0.309082f,
+ 0.322998f, 0.336670f, 0.350098f, 0.364990f, 0.378906f, 0.393311f, 0.408936f, 0.423096f, 0.438965f, 0.454834f, 0.470703f, 0.486572f,
+ 0.502441f, 0.518555f, 0.534668f, 0.551270f, 0.569336f, 0.585938f, 0.792480f, 0.799316f, 0.797363f, 0.793457f, 0.790039f, 0.786621f,
+ 0.002028f, 0.005669f, 0.009705f, 0.013565f, 0.017532f, 0.021286f, 0.025574f, 0.030197f, 0.034180f, 0.038757f, 0.043488f, 0.048737f,
+ 0.053497f, 0.058594f, 0.064026f, 0.070007f, 0.075623f, 0.081360f, 0.088135f, 0.094238f, 0.101379f, 0.108643f, 0.116028f, 0.123718f,
+ 0.131592f, 0.140137f, 0.149048f, 0.157715f, 0.167114f, 0.176636f, 0.187012f, 0.197388f, 0.208130f, 0.219238f, 0.230347f, 0.241943f,
+ 0.254150f, 0.266113f, 0.279053f, 0.291504f, 0.304932f, 0.318848f, 0.332031f, 0.345947f, 0.360107f, 0.375000f, 0.389404f, 0.404541f,
+ 0.419922f, 0.434814f, 0.450684f, 0.466553f, 0.482910f, 0.499023f, 0.516113f, 0.533203f, 0.550293f, 0.567383f, 0.783203f, 0.790527f,
+ 0.789551f, 0.786621f, 0.783691f, 0.780762f, 0.001852f, 0.005554f, 0.008957f, 0.012642f, 0.016296f, 0.020172f, 0.024033f, 0.027878f,
+ 0.031677f, 0.035919f, 0.040253f, 0.044952f, 0.049255f, 0.053955f, 0.058960f, 0.063965f, 0.069336f, 0.074951f, 0.080933f, 0.087219f,
+ 0.093201f, 0.100159f, 0.106689f, 0.114197f, 0.121521f, 0.129517f, 0.137817f, 0.146118f, 0.155151f, 0.164307f, 0.173462f, 0.183472f,
+ 0.193970f, 0.204224f, 0.215210f, 0.226562f, 0.238037f, 0.250244f, 0.262451f, 0.274902f, 0.287598f, 0.301025f, 0.314209f, 0.327393f,
+ 0.342041f, 0.356445f, 0.370850f, 0.385254f, 0.400879f, 0.415771f, 0.431396f, 0.446777f, 0.463379f, 0.480469f, 0.497314f, 0.514160f,
+ 0.530273f, 0.547363f, 0.774414f, 0.783203f, 0.782715f, 0.779297f, 0.776367f, 0.773438f, 0.001690f, 0.005207f, 0.008278f, 0.011696f,
+ 0.015068f, 0.018784f, 0.022186f, 0.025909f, 0.029221f, 0.033508f, 0.037109f, 0.041321f, 0.045471f, 0.049774f, 0.054108f, 0.058838f,
+ 0.063843f, 0.069214f, 0.074280f, 0.080078f, 0.086243f, 0.091980f, 0.098083f, 0.105164f, 0.111877f, 0.119446f, 0.126953f, 0.134888f,
+ 0.143555f, 0.151978f, 0.161133f, 0.170532f, 0.180176f, 0.189697f, 0.200684f, 0.211182f, 0.222412f, 0.234009f, 0.245972f, 0.257568f,
+ 0.270508f, 0.282959f, 0.295898f, 0.309570f, 0.323486f, 0.337158f, 0.351562f, 0.366211f, 0.381104f, 0.396729f, 0.411865f, 0.427490f,
+ 0.443604f, 0.459961f, 0.477051f, 0.494385f, 0.510742f, 0.529297f, 0.763184f, 0.774902f, 0.773438f, 0.771973f, 0.769043f, 0.767578f,
+ 0.001528f, 0.004692f, 0.007587f, 0.010956f, 0.014221f, 0.016907f, 0.020218f, 0.023407f, 0.027283f, 0.030273f, 0.033997f, 0.038055f,
+ 0.041809f, 0.045959f, 0.049683f, 0.053955f, 0.058838f, 0.063171f, 0.068176f, 0.073120f, 0.078491f, 0.084473f, 0.090332f, 0.096619f,
+ 0.102905f, 0.109619f, 0.116699f, 0.124207f, 0.131958f, 0.140503f, 0.148438f, 0.157349f, 0.166626f, 0.176392f, 0.186157f, 0.196045f,
+ 0.207031f, 0.218018f, 0.229736f, 0.241699f, 0.253174f, 0.265381f, 0.278320f, 0.291748f, 0.305176f, 0.318848f, 0.333496f, 0.347412f,
+ 0.362305f, 0.376709f, 0.392822f, 0.407715f, 0.424072f, 0.440430f, 0.457031f, 0.473633f, 0.491211f, 0.508789f, 0.753906f, 0.766602f,
+ 0.767090f, 0.764160f, 0.761719f, 0.759766f, 0.001261f, 0.004250f, 0.007389f, 0.010185f, 0.013023f, 0.015976f, 0.018692f, 0.021713f,
+ 0.024734f, 0.028183f, 0.031464f, 0.034943f, 0.038452f, 0.041870f, 0.045410f, 0.049561f, 0.054047f, 0.058044f, 0.062164f, 0.067017f,
+ 0.071838f, 0.077332f, 0.082581f, 0.088318f, 0.094360f, 0.100525f, 0.107117f, 0.114258f, 0.121643f, 0.128540f, 0.136841f, 0.144897f,
+ 0.153931f, 0.162476f, 0.171875f, 0.182007f, 0.192139f, 0.202637f, 0.213623f, 0.224854f, 0.237183f, 0.248657f, 0.260986f, 0.274170f,
+ 0.287354f, 0.300781f, 0.314453f, 0.328613f, 0.343018f, 0.358643f, 0.373291f, 0.388916f, 0.404785f, 0.420654f, 0.437744f, 0.454590f,
+ 0.471924f, 0.489990f, 0.744629f, 0.757812f, 0.757812f, 0.756836f, 0.754395f, 0.752441f, 0.001527f, 0.004047f, 0.006680f, 0.009369f,
+ 0.012024f, 0.014618f, 0.017288f, 0.020248f, 0.022705f, 0.025803f, 0.028778f, 0.031769f, 0.034912f, 0.038330f, 0.041595f, 0.045166f,
+ 0.048737f, 0.052673f, 0.056885f, 0.061218f, 0.065552f, 0.070251f, 0.075012f, 0.080505f, 0.086060f, 0.091614f, 0.097656f, 0.104065f,
+ 0.110901f, 0.118225f, 0.125366f, 0.133179f, 0.141357f, 0.149902f, 0.158569f, 0.168213f, 0.177734f, 0.187866f, 0.198364f, 0.208984f,
+ 0.220581f, 0.232422f, 0.244019f, 0.256836f, 0.269287f, 0.282471f, 0.296143f, 0.309326f, 0.324463f, 0.338379f, 0.353760f, 0.368652f,
+ 0.385498f, 0.400635f, 0.417725f, 0.434570f, 0.451660f, 0.469482f, 0.733887f, 0.749023f, 0.750977f, 0.749023f, 0.747070f, 0.744629f,
+ 0.001313f, 0.003803f, 0.006126f, 0.008507f, 0.011185f, 0.013550f, 0.015839f, 0.018219f, 0.021027f, 0.023438f, 0.026520f, 0.029129f,
+ 0.031738f, 0.034821f, 0.037964f, 0.041138f, 0.044434f, 0.048035f, 0.051636f, 0.055420f, 0.059540f, 0.063782f, 0.068176f, 0.073181f,
+ 0.077881f, 0.083496f, 0.088989f, 0.094849f, 0.101440f, 0.107849f, 0.114441f, 0.121887f, 0.129395f, 0.137207f, 0.145874f, 0.154419f,
+ 0.163574f, 0.173462f, 0.183228f, 0.193726f, 0.204712f, 0.216064f, 0.227661f, 0.239624f, 0.251709f, 0.264648f, 0.277832f, 0.291504f,
+ 0.305664f, 0.320312f, 0.334473f, 0.349854f, 0.365479f, 0.380615f, 0.397217f, 0.414551f, 0.432129f, 0.449951f, 0.722656f, 0.740234f,
+ 0.741699f, 0.741211f, 0.739746f, 0.737793f, 0.001137f, 0.003654f, 0.005871f, 0.007881f, 0.010262f, 0.012268f, 0.014496f, 0.017059f,
+ 0.018890f, 0.021317f, 0.023605f, 0.026291f, 0.029007f, 0.031494f, 0.034515f, 0.036987f, 0.040375f, 0.043457f, 0.046936f, 0.050385f,
+ 0.053925f, 0.058044f, 0.061981f, 0.066650f, 0.070679f, 0.075562f, 0.080994f, 0.085938f, 0.091919f, 0.098450f, 0.104370f, 0.110840f,
+ 0.118164f, 0.125366f, 0.133301f, 0.141357f, 0.150024f, 0.159546f, 0.168457f, 0.178711f, 0.189453f, 0.199707f, 0.211060f, 0.222656f,
+ 0.234741f, 0.247314f, 0.260010f, 0.272705f, 0.287354f, 0.300781f, 0.315674f, 0.330322f, 0.345947f, 0.362061f, 0.377441f, 0.394775f,
+ 0.412109f, 0.429199f, 0.712891f, 0.730957f, 0.733398f, 0.733398f, 0.731445f, 0.729492f, 0.001163f, 0.003218f, 0.005329f, 0.007542f,
+ 0.009331f, 0.011330f, 0.013367f, 0.015434f, 0.017685f, 0.019714f, 0.021515f, 0.024139f, 0.026062f, 0.028763f, 0.031204f, 0.033722f,
+ 0.036163f, 0.039398f, 0.041992f, 0.045624f, 0.048553f, 0.051971f, 0.056000f, 0.059937f, 0.063904f, 0.068054f, 0.072876f, 0.077820f,
+ 0.083374f, 0.088623f, 0.094116f, 0.100830f, 0.107117f, 0.114197f, 0.121399f, 0.129272f, 0.136963f, 0.145630f, 0.154785f, 0.163696f,
+ 0.173828f, 0.184204f, 0.194946f, 0.205933f, 0.217529f, 0.229614f, 0.242676f, 0.255859f, 0.269043f, 0.282471f, 0.296387f, 0.311523f,
+ 0.326172f, 0.341553f, 0.357910f, 0.374756f, 0.391846f, 0.409180f, 0.701660f, 0.721680f, 0.723633f, 0.724609f, 0.723145f, 0.722656f,
+ 0.001008f, 0.003147f, 0.004818f, 0.006882f, 0.008530f, 0.010468f, 0.012390f, 0.013832f, 0.016006f, 0.017899f, 0.019608f, 0.021866f,
+ 0.023849f, 0.025940f, 0.027847f, 0.030350f, 0.032806f, 0.035187f, 0.037994f, 0.040619f, 0.043732f, 0.046875f, 0.050110f, 0.053833f,
+ 0.057617f, 0.061371f, 0.065613f, 0.070068f, 0.074768f, 0.079895f, 0.085144f, 0.090637f, 0.096863f, 0.103149f, 0.110107f, 0.116943f,
+ 0.124634f, 0.132568f, 0.140991f, 0.149536f, 0.159302f, 0.169189f, 0.179443f, 0.189575f, 0.201538f, 0.213013f, 0.225342f, 0.236938f,
+ 0.250244f, 0.264160f, 0.278320f, 0.292236f, 0.307617f, 0.322021f, 0.337891f, 0.354248f, 0.371582f, 0.389160f, 0.689941f, 0.712891f,
+ 0.715820f, 0.715820f, 0.715820f, 0.714355f, 0.001126f, 0.002708f, 0.004486f, 0.006313f, 0.007927f, 0.009659f, 0.011238f, 0.012833f,
+ 0.014435f, 0.015823f, 0.017670f, 0.019485f, 0.021347f, 0.023453f, 0.025101f, 0.027161f, 0.029160f, 0.031525f, 0.033752f, 0.036560f,
+ 0.039154f, 0.041687f, 0.044891f, 0.047943f, 0.051453f, 0.054871f, 0.058655f, 0.062622f, 0.067078f, 0.071411f, 0.076355f, 0.081665f,
+ 0.086792f, 0.092957f, 0.098877f, 0.105713f, 0.112549f, 0.119995f, 0.127563f, 0.135864f, 0.144897f, 0.154297f, 0.164185f, 0.173828f,
+ 0.185059f, 0.196045f, 0.208008f, 0.219849f, 0.232666f, 0.245483f, 0.259033f, 0.273438f, 0.287842f, 0.302734f, 0.318604f, 0.334473f,
+ 0.351318f, 0.369385f, 0.679688f, 0.702637f, 0.707031f, 0.707031f, 0.707031f, 0.705566f, 0.000980f, 0.002733f, 0.004021f, 0.005688f,
+ 0.007084f, 0.008553f, 0.010345f, 0.011513f, 0.012962f, 0.014297f, 0.015823f, 0.017609f, 0.019119f, 0.020721f, 0.022568f, 0.024200f,
+ 0.026291f, 0.028000f, 0.030457f, 0.032410f, 0.034912f, 0.037476f, 0.039734f, 0.042786f, 0.045563f, 0.048920f, 0.052185f, 0.055817f,
+ 0.059662f, 0.063660f, 0.067993f, 0.072632f, 0.077759f, 0.083191f, 0.088623f, 0.094971f, 0.101135f, 0.107849f, 0.115479f, 0.122864f,
+ 0.131592f, 0.139893f, 0.149414f, 0.158447f, 0.169067f, 0.179443f, 0.191040f, 0.202393f, 0.214478f, 0.227539f, 0.240723f, 0.255127f,
+ 0.268555f, 0.283447f, 0.298828f, 0.315186f, 0.331787f, 0.348389f, 0.667480f, 0.693359f, 0.697754f, 0.698730f, 0.698242f, 0.697754f,
+ 0.000870f, 0.002420f, 0.003994f, 0.005165f, 0.006584f, 0.007763f, 0.009209f, 0.010468f, 0.011604f, 0.013336f, 0.013977f, 0.015442f,
+ 0.016830f, 0.018509f, 0.020065f, 0.021606f, 0.023224f, 0.024933f, 0.026672f, 0.028656f, 0.030914f, 0.033112f, 0.035187f, 0.037689f,
+ 0.040344f, 0.043335f, 0.046234f, 0.049438f, 0.052948f, 0.056427f, 0.060394f, 0.064331f, 0.069031f, 0.073853f, 0.078735f, 0.084412f,
+ 0.090271f, 0.096436f, 0.103455f, 0.110229f, 0.118042f, 0.126099f, 0.134766f, 0.143921f, 0.153198f, 0.163696f, 0.174438f, 0.185913f,
+ 0.197754f, 0.210083f, 0.222778f, 0.235962f, 0.250000f, 0.264648f, 0.279053f, 0.294922f, 0.311279f, 0.328613f, 0.655273f, 0.684082f,
+ 0.688477f, 0.689941f, 0.689941f, 0.689941f, 0.000790f, 0.002153f, 0.003576f, 0.004726f, 0.005966f, 0.007172f, 0.008186f, 0.009453f,
+ 0.010521f, 0.011482f, 0.012772f, 0.013771f, 0.015144f, 0.016434f, 0.017792f, 0.019226f, 0.020355f, 0.022049f, 0.023666f, 0.025375f,
+ 0.027145f, 0.029297f, 0.030975f, 0.033142f, 0.035339f, 0.037964f, 0.040405f, 0.043365f, 0.046478f, 0.049744f, 0.053101f, 0.057068f,
+ 0.060944f, 0.065063f, 0.069763f, 0.074646f, 0.079956f, 0.085938f, 0.091675f, 0.098083f, 0.105164f, 0.112732f, 0.121033f, 0.129395f,
+ 0.138428f, 0.148560f, 0.158325f, 0.169067f, 0.180664f, 0.192139f, 0.205078f, 0.217529f, 0.231934f, 0.246094f, 0.260010f, 0.275391f,
+ 0.292236f, 0.309570f, 0.644043f, 0.673340f, 0.678711f, 0.680664f, 0.680664f, 0.680176f, 0.000538f, 0.002022f, 0.003185f, 0.004456f,
+ 0.005360f, 0.006321f, 0.007286f, 0.008484f, 0.009422f, 0.010185f, 0.011177f, 0.012283f, 0.013191f, 0.014435f, 0.015587f, 0.016769f,
+ 0.017914f, 0.019302f, 0.020584f, 0.022171f, 0.023819f, 0.025391f, 0.027222f, 0.028992f, 0.030914f, 0.033234f, 0.035461f, 0.037903f,
+ 0.040649f, 0.043396f, 0.046326f, 0.049561f, 0.053131f, 0.056946f, 0.061279f, 0.065613f, 0.070374f, 0.075439f, 0.080811f, 0.086731f,
+ 0.093140f, 0.100037f, 0.107544f, 0.115662f, 0.124023f, 0.132935f, 0.143066f, 0.153320f, 0.163696f, 0.175415f, 0.187012f, 0.200195f,
+ 0.213013f, 0.227173f, 0.241455f, 0.256592f, 0.272461f, 0.288330f, 0.632812f, 0.663574f, 0.669434f, 0.670898f, 0.671387f, 0.671875f,
+ 0.000686f, 0.001864f, 0.002884f, 0.003883f, 0.004829f, 0.005592f, 0.006504f, 0.007454f, 0.008064f, 0.008995f, 0.009850f, 0.010948f,
+ 0.011711f, 0.012581f, 0.013763f, 0.014618f, 0.015701f, 0.016953f, 0.018112f, 0.019180f, 0.020691f, 0.021973f, 0.023560f, 0.025192f,
+ 0.026962f, 0.028717f, 0.030624f, 0.032959f, 0.035004f, 0.037567f, 0.040314f, 0.043121f, 0.046204f, 0.049713f, 0.053284f, 0.057129f,
+ 0.061157f, 0.065796f, 0.071167f, 0.076477f, 0.082214f, 0.088379f, 0.095276f, 0.102600f, 0.110596f, 0.118652f, 0.127808f, 0.137817f,
+ 0.147705f, 0.158569f, 0.170166f, 0.182251f, 0.195068f, 0.208008f, 0.222656f, 0.237671f, 0.252686f, 0.269287f, 0.620605f, 0.653320f,
+ 0.659180f, 0.661621f, 0.663086f, 0.663574f, 0.000782f, 0.001828f, 0.002949f, 0.003487f, 0.004421f, 0.005032f, 0.005878f, 0.006557f,
+ 0.007332f, 0.008110f, 0.008591f, 0.009537f, 0.010094f, 0.011147f, 0.011864f, 0.012779f, 0.013573f, 0.014549f, 0.015625f, 0.016846f,
+ 0.017822f, 0.018936f, 0.020279f, 0.021729f, 0.023117f, 0.024704f, 0.026505f, 0.028183f, 0.030289f, 0.032349f, 0.034546f, 0.037109f,
+ 0.039703f, 0.042786f, 0.045837f, 0.049133f, 0.053009f, 0.056763f, 0.061584f, 0.066284f, 0.071411f, 0.076843f, 0.083191f, 0.089722f,
+ 0.097290f, 0.104919f, 0.113647f, 0.122498f, 0.132324f, 0.142578f, 0.153809f, 0.164917f, 0.177612f, 0.190430f, 0.203857f, 0.218506f,
+ 0.233887f, 0.249390f, 0.606934f, 0.642578f, 0.649414f, 0.653320f, 0.652832f, 0.654785f, 0.000604f, 0.001636f, 0.002550f, 0.003180f,
+ 0.003799f, 0.004498f, 0.005051f, 0.005573f, 0.006325f, 0.006836f, 0.007607f, 0.008087f, 0.008820f, 0.009483f, 0.010132f, 0.010918f,
+ 0.011665f, 0.012527f, 0.013535f, 0.014297f, 0.015251f, 0.016190f, 0.017288f, 0.018433f, 0.019791f, 0.021133f, 0.022400f, 0.023865f,
+ 0.025742f, 0.027664f, 0.029373f, 0.031677f, 0.034027f, 0.036255f, 0.039032f, 0.042023f, 0.045197f, 0.048798f, 0.052643f, 0.056824f,
+ 0.061493f, 0.066467f, 0.072327f, 0.078308f, 0.084473f, 0.091858f, 0.099609f, 0.108032f, 0.117249f, 0.126831f, 0.137451f, 0.148193f,
+ 0.160034f, 0.172729f, 0.186035f, 0.199829f, 0.214722f, 0.229980f, 0.596680f, 0.632812f, 0.638672f, 0.642578f, 0.644531f, 0.645020f,
+ 0.000447f, 0.001384f, 0.001986f, 0.002697f, 0.003225f, 0.003828f, 0.004501f, 0.005009f, 0.005459f, 0.006027f, 0.006474f, 0.006935f,
+ 0.007591f, 0.008217f, 0.008644f, 0.009308f, 0.010025f, 0.010498f, 0.011330f, 0.012100f, 0.012909f, 0.013924f, 0.014618f, 0.015610f,
+ 0.016739f, 0.017807f, 0.019043f, 0.020340f, 0.021622f, 0.023178f, 0.024979f, 0.026520f, 0.028366f, 0.030640f, 0.032959f, 0.035492f,
+ 0.038239f, 0.041260f, 0.044495f, 0.048340f, 0.052399f, 0.056732f, 0.061768f, 0.067017f, 0.072754f, 0.079224f, 0.086304f, 0.093994f,
+ 0.102478f, 0.111511f, 0.121521f, 0.132080f, 0.143311f, 0.155518f, 0.168213f, 0.181763f, 0.196411f, 0.211548f, 0.583008f, 0.621094f,
+ 0.629395f, 0.632324f, 0.634766f, 0.635742f, 0.000375f, 0.001324f, 0.001728f, 0.002466f, 0.002872f, 0.003384f, 0.003685f, 0.004185f,
+ 0.004845f, 0.005184f, 0.005444f, 0.006130f, 0.006401f, 0.006844f, 0.007446f, 0.007957f, 0.008636f, 0.008965f, 0.009659f, 0.010139f,
+ 0.010971f, 0.011742f, 0.012497f, 0.013138f, 0.014099f, 0.014992f, 0.015900f, 0.017166f, 0.018143f, 0.019485f, 0.020676f, 0.022156f,
+ 0.023697f, 0.025528f, 0.027374f, 0.029556f, 0.031921f, 0.034424f, 0.037445f, 0.040375f, 0.044067f, 0.047577f, 0.052155f, 0.056824f,
+ 0.062042f, 0.067688f, 0.074158f, 0.081055f, 0.088745f, 0.097351f, 0.106323f, 0.116455f, 0.127075f, 0.138672f, 0.151123f, 0.164062f,
+ 0.177856f, 0.192871f, 0.570801f, 0.610840f, 0.619629f, 0.623047f, 0.625488f, 0.625977f, 0.000432f, 0.000921f, 0.001664f, 0.002056f,
+ 0.002697f, 0.003061f, 0.003326f, 0.003757f, 0.004044f, 0.004379f, 0.004761f, 0.004948f, 0.005463f, 0.005791f, 0.006199f, 0.006752f,
+ 0.007229f, 0.007526f, 0.008156f, 0.008621f, 0.009193f, 0.009712f, 0.010330f, 0.010994f, 0.011688f, 0.012466f, 0.013374f, 0.014153f,
+ 0.015099f, 0.016083f, 0.017212f, 0.018250f, 0.019623f, 0.021210f, 0.022614f, 0.024445f, 0.026321f, 0.028351f, 0.030762f, 0.033325f,
+ 0.036377f, 0.039642f, 0.043304f, 0.047485f, 0.051880f, 0.056885f, 0.062469f, 0.068542f, 0.075623f, 0.083374f, 0.091919f, 0.101135f,
+ 0.111389f, 0.122559f, 0.134277f, 0.146606f, 0.160278f, 0.174683f, 0.557617f, 0.600098f, 0.609375f, 0.612793f, 0.615723f, 0.616699f,
+ 0.000255f, 0.000997f, 0.001393f, 0.001908f, 0.002239f, 0.002512f, 0.002720f, 0.003166f, 0.003283f, 0.003616f, 0.003866f, 0.004223f,
+ 0.004597f, 0.004795f, 0.005127f, 0.005573f, 0.005939f, 0.006359f, 0.006657f, 0.007133f, 0.007687f, 0.008041f, 0.008545f, 0.009087f,
+ 0.009636f, 0.010300f, 0.010910f, 0.011757f, 0.012489f, 0.013313f, 0.014153f, 0.014954f, 0.016037f, 0.017258f, 0.018555f, 0.019867f,
+ 0.021530f, 0.023239f, 0.025055f, 0.027252f, 0.029663f, 0.032379f, 0.035339f, 0.038666f, 0.042664f, 0.047058f, 0.051849f, 0.057465f,
+ 0.063416f, 0.070557f, 0.078369f, 0.086731f, 0.096313f, 0.106384f, 0.117798f, 0.129761f, 0.143311f, 0.156982f, 0.544922f, 0.588867f,
+ 0.599121f, 0.602539f, 0.605469f, 0.606445f, 0.000353f, 0.000879f, 0.001276f, 0.001613f, 0.001785f, 0.002075f, 0.002300f, 0.002501f,
+ 0.002808f, 0.003010f, 0.003283f, 0.003487f, 0.003714f, 0.003967f, 0.004269f, 0.004597f, 0.004837f, 0.005230f, 0.005512f, 0.005878f,
+ 0.006203f, 0.006626f, 0.007030f, 0.007519f, 0.007866f, 0.008354f, 0.009010f, 0.009468f, 0.010017f, 0.010765f, 0.011444f, 0.012291f,
+ 0.013100f, 0.014030f, 0.015030f, 0.016098f, 0.017441f, 0.018646f, 0.020157f, 0.021912f, 0.023804f, 0.026047f, 0.028488f, 0.031342f,
+ 0.034424f, 0.037994f, 0.042206f, 0.046997f, 0.052338f, 0.058533f, 0.065369f, 0.073364f, 0.081787f, 0.091492f, 0.102356f, 0.113647f,
+ 0.126343f, 0.139526f, 0.531250f, 0.579102f, 0.587891f, 0.592773f, 0.595703f, 0.596680f, 0.000295f, 0.000784f, 0.000912f, 0.001261f,
+ 0.001517f, 0.001761f, 0.001893f, 0.002113f, 0.002211f, 0.002432f, 0.002676f, 0.002861f, 0.002993f, 0.003294f, 0.003479f, 0.003700f,
+ 0.003933f, 0.004242f, 0.004452f, 0.004745f, 0.004974f, 0.005428f, 0.005642f, 0.006081f, 0.006401f, 0.006817f, 0.007240f, 0.007641f,
+ 0.008209f, 0.008667f, 0.009361f, 0.009720f, 0.010506f, 0.011261f, 0.012024f, 0.012794f, 0.013840f, 0.014893f, 0.016113f, 0.017395f,
+ 0.018860f, 0.020493f, 0.022446f, 0.024658f, 0.027283f, 0.030228f, 0.033691f, 0.037659f, 0.042145f, 0.047546f, 0.053467f, 0.060547f,
+ 0.068359f, 0.077332f, 0.087158f, 0.098145f, 0.109741f, 0.123230f, 0.517090f, 0.566895f, 0.576660f, 0.581543f, 0.584961f, 0.587402f,
+ 0.000247f, 0.000702f, 0.000849f, 0.001033f, 0.001304f, 0.001416f, 0.001576f, 0.001754f, 0.001860f, 0.001953f, 0.002104f, 0.002327f,
+ 0.002419f, 0.002651f, 0.002785f, 0.003014f, 0.003134f, 0.003315f, 0.003584f, 0.003813f, 0.004078f, 0.004295f, 0.004555f, 0.004784f,
+ 0.005013f, 0.005329f, 0.005669f, 0.006069f, 0.006439f, 0.006821f, 0.007381f, 0.007797f, 0.008301f, 0.008812f, 0.009430f, 0.010139f,
+ 0.010948f, 0.011642f, 0.012573f, 0.013664f, 0.014671f, 0.016052f, 0.017502f, 0.019135f, 0.021255f, 0.023438f, 0.026199f, 0.029312f,
+ 0.033203f, 0.037476f, 0.042725f, 0.048828f, 0.055695f, 0.063721f, 0.072937f, 0.082947f, 0.094666f, 0.107117f, 0.504883f, 0.555664f,
+ 0.566406f, 0.572754f, 0.574707f, 0.577148f, 0.000217f, 0.000516f, 0.000750f, 0.000898f, 0.001011f, 0.001117f, 0.001203f, 0.001307f,
+ 0.001470f, 0.001604f, 0.001659f, 0.001750f, 0.001945f, 0.002121f, 0.002249f, 0.002316f, 0.002478f, 0.002581f, 0.002832f, 0.003000f,
+ 0.003164f, 0.003334f, 0.003593f, 0.003784f, 0.003990f, 0.004196f, 0.004440f, 0.004673f, 0.005035f, 0.005329f, 0.005642f, 0.005981f,
+ 0.006462f, 0.006916f, 0.007313f, 0.007805f, 0.008377f, 0.008987f, 0.009727f, 0.010521f, 0.011314f, 0.012421f, 0.013466f, 0.014755f,
+ 0.016235f, 0.017914f, 0.019913f, 0.022461f, 0.025330f, 0.028778f, 0.033081f, 0.038239f, 0.044189f, 0.051422f, 0.059662f, 0.069336f,
+ 0.080200f, 0.091980f, 0.492676f, 0.543945f, 0.555664f, 0.561035f, 0.564453f, 0.566406f, 0.000131f, 0.000355f, 0.000605f, 0.000759f,
+ 0.000832f, 0.000904f, 0.001018f, 0.000975f, 0.001144f, 0.001235f, 0.001336f, 0.001447f, 0.001518f, 0.001620f, 0.001668f, 0.001835f,
+ 0.001901f, 0.002045f, 0.002188f, 0.002270f, 0.002424f, 0.002577f, 0.002707f, 0.002893f, 0.003002f, 0.003223f, 0.003407f, 0.003572f,
+ 0.003851f, 0.004017f, 0.004391f, 0.004608f, 0.004833f, 0.005203f, 0.005497f, 0.005886f, 0.006351f, 0.006771f, 0.007278f, 0.007858f,
+ 0.008560f, 0.009315f, 0.010086f, 0.011078f, 0.012222f, 0.013443f, 0.015022f, 0.016769f, 0.018967f, 0.021591f, 0.024780f, 0.028931f,
+ 0.033875f, 0.039734f, 0.047241f, 0.056122f, 0.066101f, 0.077637f, 0.477783f, 0.532715f, 0.544922f, 0.551270f, 0.553711f, 0.555664f,
+ 0.000245f, 0.000303f, 0.000473f, 0.000498f, 0.000544f, 0.000707f, 0.000700f, 0.000767f, 0.000802f, 0.000892f, 0.001021f, 0.001086f,
+ 0.001140f, 0.001260f, 0.001303f, 0.001325f, 0.001462f, 0.001553f, 0.001603f, 0.001746f, 0.001816f, 0.001904f, 0.002043f, 0.002127f,
+ 0.002254f, 0.002356f, 0.002548f, 0.002672f, 0.002851f, 0.003092f, 0.003265f, 0.003374f, 0.003647f, 0.003891f, 0.004097f, 0.004360f,
+ 0.004669f, 0.004997f, 0.005390f, 0.005810f, 0.006226f, 0.006756f, 0.007450f, 0.008095f, 0.008934f, 0.009827f, 0.010902f, 0.012268f,
+ 0.013840f, 0.015701f, 0.018036f, 0.021072f, 0.024948f, 0.029800f, 0.035980f, 0.043945f, 0.053345f, 0.063843f, 0.465576f, 0.520996f,
+ 0.535645f, 0.540039f, 0.543457f, 0.545898f, 0.000108f, 0.000275f, 0.000332f, 0.000402f, 0.000462f, 0.000468f, 0.000580f, 0.000522f,
+ 0.000616f, 0.000657f, 0.000758f, 0.000762f, 0.000812f, 0.000870f, 0.000945f, 0.000978f, 0.001054f, 0.001109f, 0.001179f, 0.001213f,
+ 0.001311f, 0.001371f, 0.001473f, 0.001558f, 0.001629f, 0.001718f, 0.001837f, 0.001903f, 0.002016f, 0.002159f, 0.002258f, 0.002478f,
+ 0.002548f, 0.002731f, 0.002909f, 0.003086f, 0.003317f, 0.003580f, 0.003885f, 0.004116f, 0.004421f, 0.004818f, 0.005264f, 0.005745f,
+ 0.006294f, 0.006966f, 0.007748f, 0.008667f, 0.009766f, 0.011086f, 0.012787f, 0.014908f, 0.017746f, 0.021271f, 0.026382f, 0.032990f,
+ 0.041199f, 0.051239f, 0.452393f, 0.509277f, 0.522461f, 0.529297f, 0.533203f, 0.535156f, 0.000016f, 0.000143f, 0.000244f, 0.000315f,
+ 0.000309f, 0.000391f, 0.000344f, 0.000402f, 0.000429f, 0.000517f, 0.000522f, 0.000526f, 0.000546f, 0.000606f, 0.000628f, 0.000705f,
+ 0.000692f, 0.000781f, 0.000837f, 0.000868f, 0.000923f, 0.000969f, 0.001013f, 0.001070f, 0.001142f, 0.001186f, 0.001273f, 0.001326f,
+ 0.001397f, 0.001534f, 0.001561f, 0.001685f, 0.001775f, 0.001873f, 0.002024f, 0.002153f, 0.002272f, 0.002443f, 0.002611f, 0.002800f,
+ 0.003014f, 0.003250f, 0.003529f, 0.003868f, 0.004227f, 0.004692f, 0.005192f, 0.005836f, 0.006603f, 0.007587f, 0.008751f, 0.010193f,
+ 0.012001f, 0.014610f, 0.018219f, 0.023392f, 0.030594f, 0.039795f, 0.437744f, 0.498291f, 0.512207f, 0.517578f, 0.521484f, 0.525391f,
+ 0.000102f, 0.000186f, 0.000171f, 0.000181f, 0.000227f, 0.000229f, 0.000231f, 0.000278f, 0.000293f, 0.000304f, 0.000314f, 0.000375f,
+ 0.000365f, 0.000411f, 0.000446f, 0.000457f, 0.000496f, 0.000513f, 0.000533f, 0.000554f, 0.000603f, 0.000622f, 0.000669f, 0.000708f,
+ 0.000757f, 0.000789f, 0.000843f, 0.000875f, 0.000925f, 0.000964f, 0.001037f, 0.001094f, 0.001172f, 0.001243f, 0.001324f, 0.001373f,
+ 0.001497f, 0.001570f, 0.001712f, 0.001829f, 0.001947f, 0.002123f, 0.002291f, 0.002472f, 0.002703f, 0.003008f, 0.003342f, 0.003757f,
+ 0.004204f, 0.004810f, 0.005539f, 0.006554f, 0.007828f, 0.009537f, 0.011894f, 0.015442f, 0.021072f, 0.029282f, 0.424561f, 0.486084f,
+ 0.500488f, 0.506836f, 0.512207f, 0.514648f, 0.000014f, 0.000127f, 0.000112f, 0.000109f, 0.000143f, 0.000165f, 0.000141f, 0.000180f,
+ 0.000185f, 0.000191f, 0.000196f, 0.000203f, 0.000233f, 0.000252f, 0.000260f, 0.000274f, 0.000288f, 0.000314f, 0.000328f, 0.000363f,
+ 0.000362f, 0.000374f, 0.000400f, 0.000436f, 0.000464f, 0.000501f, 0.000504f, 0.000521f, 0.000563f, 0.000593f, 0.000635f, 0.000671f,
+ 0.000712f, 0.000740f, 0.000800f, 0.000837f, 0.000892f, 0.000955f, 0.001030f, 0.001092f, 0.001167f, 0.001270f, 0.001369f, 0.001491f,
+ 0.001626f, 0.001769f, 0.001993f, 0.002209f, 0.002523f, 0.002863f, 0.003325f, 0.003880f, 0.004715f, 0.005764f, 0.007320f, 0.009468f,
+ 0.013344f, 0.020187f, 0.410645f, 0.473877f, 0.489258f, 0.496826f, 0.500488f, 0.503906f, 0.000103f, 0.000078f, 0.000067f, 0.000065f,
+ 0.000086f, 0.000085f, 0.000101f, 0.000106f, 0.000106f, 0.000107f, 0.000115f, 0.000133f, 0.000118f, 0.000133f, 0.000154f, 0.000150f,
+ 0.000167f, 0.000177f, 0.000180f, 0.000190f, 0.000207f, 0.000213f, 0.000228f, 0.000238f, 0.000267f, 0.000277f, 0.000287f, 0.000298f,
+ 0.000313f, 0.000325f, 0.000347f, 0.000375f, 0.000393f, 0.000405f, 0.000440f, 0.000463f, 0.000486f, 0.000527f, 0.000562f, 0.000599f,
+ 0.000639f, 0.000688f, 0.000757f, 0.000807f, 0.000879f, 0.000961f, 0.001059f, 0.001180f, 0.001342f, 0.001533f, 0.001762f, 0.002102f,
+ 0.002502f, 0.003128f, 0.004028f, 0.005379f, 0.007591f, 0.012505f, 0.397217f, 0.462891f, 0.478760f, 0.485840f, 0.490479f, 0.492676f,
+ 0.000087f, 0.000063f, 0.000054f, 0.000048f, 0.000047f, 0.000044f, 0.000046f, 0.000047f, 0.000047f, 0.000060f, 0.000053f, 0.000056f,
+ 0.000072f, 0.000060f, 0.000064f, 0.000069f, 0.000078f, 0.000085f, 0.000084f, 0.000090f, 0.000094f, 0.000102f, 0.000105f, 0.000111f,
+ 0.000116f, 0.000126f, 0.000132f, 0.000150f, 0.000147f, 0.000158f, 0.000167f, 0.000178f, 0.000185f, 0.000192f, 0.000211f, 0.000216f,
+ 0.000226f, 0.000246f, 0.000265f, 0.000284f, 0.000299f, 0.000325f, 0.000349f, 0.000381f, 0.000415f, 0.000448f, 0.000490f, 0.000544f,
+ 0.000612f, 0.000694f, 0.000798f, 0.000943f, 0.001139f, 0.001436f, 0.001870f, 0.002586f, 0.003817f, 0.006474f, 0.383545f, 0.450195f,
+ 0.467041f, 0.474365f, 0.478760f, 0.482422f, 0.000065f, 0.000045f, 0.000037f, 0.000033f, 0.000030f, 0.000028f, 0.000026f, 0.000025f,
+ 0.000024f, 0.000022f, 0.000021f, 0.000025f, 0.000020f, 0.000021f, 0.000025f, 0.000029f, 0.000028f, 0.000031f, 0.000033f, 0.000034f,
+ 0.000036f, 0.000041f, 0.000045f, 0.000040f, 0.000045f, 0.000049f, 0.000051f, 0.000048f, 0.000055f, 0.000057f, 0.000061f, 0.000066f,
+ 0.000072f, 0.000068f, 0.000073f, 0.000078f, 0.000087f, 0.000089f, 0.000097f, 0.000104f, 0.000113f, 0.000115f, 0.000128f, 0.000137f,
+ 0.000148f, 0.000160f, 0.000174f, 0.000194f, 0.000221f, 0.000248f, 0.000283f, 0.000324f, 0.000396f, 0.000496f, 0.000657f, 0.000928f,
+ 0.001479f, 0.002684f, 0.371094f, 0.438477f, 0.455078f, 0.463867f, 0.468750f, 0.471191f, 0.000029f, 0.000019f, 0.000016f, 0.000014f,
+ 0.000014f, 0.000013f, 0.000012f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000010f,
+ 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000007f, 0.000008f, 0.000007f, 0.000008f, 0.000009f, 0.000010f, 0.000011f,
+ 0.000012f, 0.000011f, 0.000012f, 0.000013f, 0.000015f, 0.000017f, 0.000018f, 0.000018f, 0.000020f, 0.000019f, 0.000021f, 0.000024f,
+ 0.000024f, 0.000026f, 0.000028f, 0.000031f, 0.000031f, 0.000035f, 0.000040f, 0.000041f, 0.000045f, 0.000052f, 0.000059f, 0.000071f,
+ 0.000083f, 0.000099f, 0.000132f, 0.000188f, 0.000315f, 0.000712f, 0.356934f, 0.426514f, 0.444824f, 0.452637f, 0.457520f, 0.460938f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000001f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000003f, 0.000004f, 0.000004f, 0.000006f, 0.000010f, 0.000027f, 0.343750f, 0.414795f,
+ 0.433105f, 0.441895f, 0.446289f, 0.449951f,
+ },
+ {
+ 0.012436f, 0.037598f, 0.062805f, 0.087891f, 0.113037f, 0.137329f, 0.161621f, 0.185425f, 0.209717f, 0.232544f, 0.255371f, 0.278076f,
+ 0.300049f, 0.321289f, 0.343506f, 0.364014f, 0.385010f, 0.404785f, 0.424561f, 0.444824f, 0.463623f, 0.482422f, 0.501465f, 0.520020f,
+ 0.537598f, 0.554688f, 0.572266f, 0.589355f, 0.605957f, 0.622070f, 0.639648f, 0.655273f, 0.670410f, 0.685547f, 0.700684f, 0.715332f,
+ 0.730469f, 0.744629f, 0.758301f, 0.771973f, 0.785156f, 0.799316f, 0.812012f, 0.825684f, 0.837891f, 0.850586f, 0.863281f, 0.875000f,
+ 0.887207f, 0.898926f, 0.910156f, 0.921387f, 0.933105f, 0.944336f, 0.954102f, 0.964844f, 0.976074f, 0.985840f, 0.978027f, 0.947266f,
+ 0.925781f, 0.907715f, 0.892090f, 0.877930f, 0.011276f, 0.034546f, 0.058289f, 0.082031f, 0.105469f, 0.128662f, 0.152344f, 0.174805f,
+ 0.197876f, 0.219604f, 0.241455f, 0.263672f, 0.284912f, 0.306152f, 0.326416f, 0.347168f, 0.366699f, 0.387695f, 0.406494f, 0.426025f,
+ 0.444824f, 0.463379f, 0.481934f, 0.500000f, 0.518066f, 0.535645f, 0.552246f, 0.569824f, 0.586426f, 0.603027f, 0.619141f, 0.634766f,
+ 0.650391f, 0.666016f, 0.681152f, 0.695801f, 0.710938f, 0.725586f, 0.739258f, 0.753906f, 0.768066f, 0.781250f, 0.794922f, 0.807617f,
+ 0.821289f, 0.833496f, 0.846191f, 0.858398f, 0.870605f, 0.882812f, 0.894531f, 0.906250f, 0.917480f, 0.929199f, 0.939453f, 0.951660f,
+ 0.961426f, 0.972656f, 0.971680f, 0.942871f, 0.921875f, 0.904785f, 0.889160f, 0.875977f, 0.010628f, 0.032288f, 0.054932f, 0.076172f,
+ 0.099060f, 0.121216f, 0.142700f, 0.164795f, 0.186279f, 0.207642f, 0.229248f, 0.249756f, 0.269531f, 0.291016f, 0.310791f, 0.331543f,
+ 0.349609f, 0.369385f, 0.388916f, 0.409180f, 0.427246f, 0.444824f, 0.463135f, 0.480713f, 0.499512f, 0.516602f, 0.533203f, 0.550293f,
+ 0.567383f, 0.583496f, 0.599609f, 0.615723f, 0.630859f, 0.646973f, 0.661621f, 0.677246f, 0.691895f, 0.705566f, 0.720703f, 0.735352f,
+ 0.749512f, 0.763184f, 0.776367f, 0.790039f, 0.803223f, 0.816406f, 0.828613f, 0.842285f, 0.854492f, 0.867676f, 0.878418f, 0.890137f,
+ 0.902832f, 0.913086f, 0.925293f, 0.936035f, 0.947754f, 0.958008f, 0.964844f, 0.937500f, 0.917480f, 0.901367f, 0.886719f, 0.873535f,
+ 0.009926f, 0.030167f, 0.050995f, 0.071594f, 0.092346f, 0.113892f, 0.134399f, 0.154663f, 0.175537f, 0.195679f, 0.216309f, 0.235840f,
+ 0.256104f, 0.276611f, 0.295654f, 0.314453f, 0.333496f, 0.353027f, 0.370850f, 0.389404f, 0.408936f, 0.427490f, 0.445312f, 0.462891f,
+ 0.480225f, 0.497803f, 0.513672f, 0.531250f, 0.547363f, 0.563965f, 0.580078f, 0.597168f, 0.612305f, 0.627930f, 0.642578f, 0.658691f,
+ 0.673340f, 0.687500f, 0.702637f, 0.717285f, 0.731445f, 0.744629f, 0.758301f, 0.772461f, 0.786133f, 0.799316f, 0.811523f, 0.824707f,
+ 0.837891f, 0.849121f, 0.861816f, 0.874023f, 0.887207f, 0.898438f, 0.910156f, 0.920898f, 0.932617f, 0.943848f, 0.958008f, 0.932129f,
+ 0.913086f, 0.897461f, 0.883301f, 0.871094f, 0.009178f, 0.028107f, 0.047729f, 0.066895f, 0.086182f, 0.106384f, 0.125977f, 0.145386f,
+ 0.165527f, 0.184937f, 0.203857f, 0.224121f, 0.242676f, 0.261475f, 0.281006f, 0.300049f, 0.318604f, 0.336426f, 0.355469f, 0.372314f,
+ 0.391113f, 0.409424f, 0.426514f, 0.444092f, 0.461426f, 0.477783f, 0.495850f, 0.512207f, 0.528809f, 0.544434f, 0.561035f, 0.576660f,
+ 0.593262f, 0.608398f, 0.623047f, 0.638184f, 0.655273f, 0.668945f, 0.682617f, 0.697754f, 0.712402f, 0.726562f, 0.740234f, 0.753906f,
+ 0.768066f, 0.781250f, 0.794434f, 0.807617f, 0.820312f, 0.833496f, 0.845215f, 0.858398f, 0.870605f, 0.881836f, 0.894043f, 0.906738f,
+ 0.917480f, 0.928711f, 0.951172f, 0.926758f, 0.909180f, 0.893555f, 0.880859f, 0.868164f, 0.008667f, 0.025986f, 0.044922f, 0.062805f,
+ 0.081421f, 0.099854f, 0.118347f, 0.137085f, 0.155518f, 0.173828f, 0.193115f, 0.211304f, 0.229858f, 0.248413f, 0.266602f, 0.285400f,
+ 0.303223f, 0.321045f, 0.339111f, 0.357178f, 0.373779f, 0.391357f, 0.409424f, 0.426270f, 0.443115f, 0.460449f, 0.476807f, 0.494141f,
+ 0.510254f, 0.526855f, 0.541992f, 0.559082f, 0.574219f, 0.589355f, 0.605469f, 0.620117f, 0.636230f, 0.649902f, 0.664551f, 0.678711f,
+ 0.693848f, 0.707031f, 0.723145f, 0.736328f, 0.750977f, 0.762695f, 0.776855f, 0.790039f, 0.803223f, 0.816406f, 0.828613f, 0.842285f,
+ 0.853516f, 0.866211f, 0.878906f, 0.890625f, 0.902832f, 0.913574f, 0.944336f, 0.921875f, 0.903809f, 0.889160f, 0.876953f, 0.865234f,
+ 0.008057f, 0.024658f, 0.041321f, 0.058411f, 0.075989f, 0.093811f, 0.110535f, 0.128784f, 0.146729f, 0.164307f, 0.182007f, 0.200073f,
+ 0.217773f, 0.234619f, 0.252930f, 0.271240f, 0.288086f, 0.306152f, 0.322998f, 0.341064f, 0.357910f, 0.374756f, 0.391357f, 0.409180f,
+ 0.425293f, 0.442383f, 0.458496f, 0.475342f, 0.491455f, 0.507324f, 0.523438f, 0.539551f, 0.555176f, 0.570312f, 0.585938f, 0.601074f,
+ 0.616699f, 0.631836f, 0.646484f, 0.660645f, 0.676270f, 0.688477f, 0.704102f, 0.718262f, 0.731445f, 0.745117f, 0.760254f, 0.771484f,
+ 0.785156f, 0.799316f, 0.812500f, 0.824707f, 0.836914f, 0.850098f, 0.862793f, 0.874512f, 0.886719f, 0.898438f, 0.937500f, 0.915527f,
+ 0.899414f, 0.885254f, 0.872559f, 0.861816f, 0.007477f, 0.022919f, 0.038971f, 0.054901f, 0.070801f, 0.087646f, 0.104065f, 0.121155f,
+ 0.137573f, 0.155029f, 0.171875f, 0.188721f, 0.206177f, 0.222778f, 0.240112f, 0.257080f, 0.274170f, 0.290283f, 0.308350f, 0.324463f,
+ 0.342041f, 0.358154f, 0.375488f, 0.391113f, 0.407471f, 0.424561f, 0.440430f, 0.456787f, 0.474121f, 0.489746f, 0.505371f, 0.521484f,
+ 0.536133f, 0.552246f, 0.565918f, 0.582031f, 0.597168f, 0.613281f, 0.626953f, 0.642578f, 0.656738f, 0.670898f, 0.684570f, 0.699219f,
+ 0.712891f, 0.727539f, 0.741211f, 0.754395f, 0.768066f, 0.781738f, 0.794434f, 0.808105f, 0.820312f, 0.833984f, 0.846680f, 0.858887f,
+ 0.871582f, 0.883301f, 0.930176f, 0.910156f, 0.894043f, 0.880371f, 0.868652f, 0.858398f, 0.007023f, 0.021240f, 0.036224f, 0.051300f,
+ 0.066467f, 0.082092f, 0.097900f, 0.113892f, 0.129517f, 0.145752f, 0.161743f, 0.178223f, 0.194702f, 0.210327f, 0.227661f, 0.243408f,
+ 0.260986f, 0.276855f, 0.292725f, 0.309814f, 0.326172f, 0.342041f, 0.358398f, 0.375732f, 0.391113f, 0.406982f, 0.422852f, 0.438965f,
+ 0.454590f, 0.471191f, 0.486816f, 0.502441f, 0.517578f, 0.533203f, 0.548340f, 0.562988f, 0.578613f, 0.593750f, 0.609375f, 0.623535f,
+ 0.638184f, 0.652832f, 0.666992f, 0.680664f, 0.695312f, 0.708984f, 0.722656f, 0.736816f, 0.750000f, 0.764160f, 0.777344f, 0.789551f,
+ 0.803223f, 0.816895f, 0.830078f, 0.842773f, 0.854980f, 0.868652f, 0.922852f, 0.904297f, 0.889160f, 0.875977f, 0.864746f, 0.854492f,
+ 0.006458f, 0.019913f, 0.033691f, 0.048126f, 0.062744f, 0.077026f, 0.092224f, 0.106567f, 0.122192f, 0.137207f, 0.152222f, 0.167725f,
+ 0.183838f, 0.199951f, 0.215088f, 0.231323f, 0.246826f, 0.262695f, 0.279053f, 0.294678f, 0.310547f, 0.326172f, 0.342041f, 0.358887f,
+ 0.374268f, 0.389893f, 0.405518f, 0.421143f, 0.437012f, 0.452637f, 0.467773f, 0.483643f, 0.499512f, 0.513672f, 0.529785f, 0.545410f,
+ 0.560059f, 0.575195f, 0.590332f, 0.604980f, 0.618652f, 0.634277f, 0.648438f, 0.662598f, 0.676270f, 0.690918f, 0.704102f, 0.718750f,
+ 0.732422f, 0.745605f, 0.760254f, 0.773438f, 0.786621f, 0.801270f, 0.812988f, 0.826172f, 0.839844f, 0.851562f, 0.915527f, 0.897949f,
+ 0.883789f, 0.871094f, 0.860352f, 0.850586f, 0.006077f, 0.018921f, 0.031464f, 0.045258f, 0.058411f, 0.072144f, 0.085999f, 0.100220f,
+ 0.114258f, 0.129028f, 0.143677f, 0.158691f, 0.173584f, 0.188477f, 0.203247f, 0.219238f, 0.234497f, 0.249634f, 0.264893f, 0.280273f,
+ 0.295410f, 0.310791f, 0.326904f, 0.342285f, 0.357910f, 0.373535f, 0.388428f, 0.404053f, 0.420166f, 0.435303f, 0.450195f, 0.465332f,
+ 0.481201f, 0.496338f, 0.511230f, 0.525879f, 0.540527f, 0.556641f, 0.570312f, 0.585938f, 0.600098f, 0.614746f, 0.629883f, 0.644531f,
+ 0.657715f, 0.672363f, 0.687012f, 0.700684f, 0.714355f, 0.729004f, 0.742188f, 0.755371f, 0.769531f, 0.782227f, 0.796875f, 0.810059f,
+ 0.823242f, 0.836426f, 0.907715f, 0.891602f, 0.877930f, 0.866211f, 0.855957f, 0.846680f, 0.005596f, 0.017654f, 0.029587f, 0.041840f,
+ 0.055115f, 0.067871f, 0.080566f, 0.093994f, 0.107361f, 0.120911f, 0.134766f, 0.149414f, 0.163452f, 0.177979f, 0.192261f, 0.206787f,
+ 0.221191f, 0.236816f, 0.250732f, 0.266113f, 0.281250f, 0.295898f, 0.311279f, 0.326904f, 0.342041f, 0.356201f, 0.371826f, 0.387451f,
+ 0.402344f, 0.417236f, 0.432373f, 0.447266f, 0.462891f, 0.477539f, 0.492432f, 0.506836f, 0.522949f, 0.536621f, 0.551758f, 0.566895f,
+ 0.582031f, 0.596191f, 0.610352f, 0.625488f, 0.640625f, 0.653320f, 0.668457f, 0.682617f, 0.696777f, 0.710449f, 0.724609f, 0.739258f,
+ 0.751465f, 0.765625f, 0.780273f, 0.792480f, 0.806152f, 0.820801f, 0.899902f, 0.885742f, 0.872070f, 0.861328f, 0.851562f, 0.842285f,
+ 0.005451f, 0.016479f, 0.028259f, 0.039856f, 0.051331f, 0.063416f, 0.075867f, 0.088196f, 0.100952f, 0.113770f, 0.126953f, 0.140747f,
+ 0.153564f, 0.167847f, 0.181519f, 0.195679f, 0.210083f, 0.223633f, 0.237427f, 0.252197f, 0.267334f, 0.281738f, 0.296143f, 0.311035f,
+ 0.325928f, 0.340332f, 0.355469f, 0.370361f, 0.385010f, 0.400635f, 0.415039f, 0.429688f, 0.444092f, 0.459717f, 0.474121f, 0.489258f,
+ 0.503906f, 0.519043f, 0.533203f, 0.548828f, 0.562012f, 0.577637f, 0.591797f, 0.606445f, 0.621582f, 0.635742f, 0.650391f, 0.664551f,
+ 0.678223f, 0.692871f, 0.706055f, 0.721191f, 0.733887f, 0.747559f, 0.762207f, 0.775879f, 0.791016f, 0.804199f, 0.892090f, 0.878906f,
+ 0.866699f, 0.855957f, 0.846191f, 0.837891f, 0.004963f, 0.015343f, 0.026169f, 0.037079f, 0.047943f, 0.059570f, 0.070801f, 0.083008f,
+ 0.095093f, 0.106750f, 0.119507f, 0.132080f, 0.145142f, 0.158569f, 0.171143f, 0.184692f, 0.198730f, 0.211792f, 0.225830f, 0.239380f,
+ 0.253662f, 0.267578f, 0.281738f, 0.295898f, 0.309814f, 0.324219f, 0.340088f, 0.353760f, 0.368164f, 0.383057f, 0.397705f, 0.412842f,
+ 0.426758f, 0.441406f, 0.456787f, 0.470947f, 0.485352f, 0.500000f, 0.515137f, 0.529785f, 0.543945f, 0.559082f, 0.572754f, 0.588379f,
+ 0.602539f, 0.616699f, 0.631348f, 0.645996f, 0.659180f, 0.674805f, 0.689453f, 0.703125f, 0.716797f, 0.729980f, 0.744629f, 0.758789f,
+ 0.772461f, 0.786621f, 0.883789f, 0.872070f, 0.860840f, 0.850586f, 0.841309f, 0.833008f, 0.004726f, 0.014549f, 0.024109f, 0.034668f,
+ 0.044708f, 0.055573f, 0.066467f, 0.077820f, 0.088928f, 0.100342f, 0.112000f, 0.124390f, 0.136230f, 0.148804f, 0.161621f, 0.173950f,
+ 0.186768f, 0.200439f, 0.213623f, 0.226074f, 0.239868f, 0.253418f, 0.267090f, 0.281250f, 0.295410f, 0.309570f, 0.323486f, 0.337891f,
+ 0.352295f, 0.365967f, 0.381104f, 0.394775f, 0.409180f, 0.423828f, 0.438477f, 0.452881f, 0.467773f, 0.481689f, 0.496582f, 0.511230f,
+ 0.525391f, 0.539551f, 0.554199f, 0.568848f, 0.583984f, 0.599121f, 0.612305f, 0.627441f, 0.641113f, 0.656250f, 0.669922f, 0.684570f,
+ 0.699219f, 0.713379f, 0.727539f, 0.741699f, 0.755859f, 0.771484f, 0.875488f, 0.865723f, 0.854492f, 0.845215f, 0.836426f, 0.828613f,
+ 0.004452f, 0.013359f, 0.022690f, 0.032745f, 0.042297f, 0.051910f, 0.061920f, 0.072693f, 0.083496f, 0.094177f, 0.105408f, 0.116760f,
+ 0.128174f, 0.140137f, 0.151855f, 0.164185f, 0.176758f, 0.189087f, 0.201660f, 0.214478f, 0.227173f, 0.240356f, 0.253906f, 0.267578f,
+ 0.280273f, 0.294922f, 0.307373f, 0.321045f, 0.336670f, 0.350098f, 0.363770f, 0.378174f, 0.392334f, 0.406006f, 0.420410f, 0.434082f,
+ 0.448975f, 0.463623f, 0.478271f, 0.492676f, 0.506836f, 0.520996f, 0.536133f, 0.550781f, 0.565430f, 0.580078f, 0.593750f, 0.608887f,
+ 0.623047f, 0.638184f, 0.651367f, 0.666016f, 0.681152f, 0.695312f, 0.709473f, 0.723145f, 0.738281f, 0.752930f, 0.867676f, 0.858398f,
+ 0.848633f, 0.839355f, 0.831055f, 0.823730f, 0.004143f, 0.012794f, 0.021713f, 0.030396f, 0.039551f, 0.048645f, 0.058563f, 0.068176f,
+ 0.078308f, 0.088928f, 0.098328f, 0.109924f, 0.120728f, 0.131592f, 0.142944f, 0.154175f, 0.165771f, 0.178223f, 0.190186f, 0.202881f,
+ 0.214844f, 0.227417f, 0.240845f, 0.253906f, 0.265869f, 0.279541f, 0.293213f, 0.305908f, 0.320068f, 0.333496f, 0.347168f, 0.361816f,
+ 0.375000f, 0.389160f, 0.403320f, 0.417236f, 0.431396f, 0.444824f, 0.459473f, 0.473633f, 0.488525f, 0.503418f, 0.517578f, 0.532227f,
+ 0.545410f, 0.560547f, 0.575684f, 0.590332f, 0.604004f, 0.618652f, 0.632812f, 0.647949f, 0.663086f, 0.676758f, 0.691895f, 0.706543f,
+ 0.721191f, 0.735840f, 0.859375f, 0.852539f, 0.842773f, 0.833496f, 0.824707f, 0.818848f, 0.003839f, 0.012062f, 0.020126f, 0.028366f,
+ 0.036774f, 0.045593f, 0.054718f, 0.063416f, 0.073120f, 0.082825f, 0.092957f, 0.102966f, 0.113464f, 0.123535f, 0.134277f, 0.145020f,
+ 0.155762f, 0.167847f, 0.179199f, 0.190796f, 0.202393f, 0.214844f, 0.227417f, 0.239868f, 0.252197f, 0.264648f, 0.277588f, 0.291016f,
+ 0.304199f, 0.317383f, 0.330811f, 0.343750f, 0.357422f, 0.371826f, 0.385254f, 0.399902f, 0.413574f, 0.427246f, 0.441162f, 0.455566f,
+ 0.469971f, 0.484375f, 0.498535f, 0.514160f, 0.527344f, 0.541992f, 0.556152f, 0.570312f, 0.585449f, 0.600098f, 0.614746f, 0.629883f,
+ 0.645508f, 0.658203f, 0.673340f, 0.688477f, 0.703125f, 0.718262f, 0.851074f, 0.844727f, 0.835938f, 0.827637f, 0.820312f, 0.812988f,
+ 0.003786f, 0.011147f, 0.018921f, 0.026550f, 0.034729f, 0.042664f, 0.051117f, 0.060028f, 0.068298f, 0.077454f, 0.086914f, 0.096130f,
+ 0.105835f, 0.115662f, 0.126343f, 0.136475f, 0.146606f, 0.157715f, 0.168457f, 0.180176f, 0.191528f, 0.202759f, 0.215088f, 0.226929f,
+ 0.239014f, 0.251221f, 0.263428f, 0.275391f, 0.289062f, 0.301514f, 0.314941f, 0.328369f, 0.341797f, 0.354736f, 0.367676f, 0.382324f,
+ 0.395264f, 0.409912f, 0.423340f, 0.437012f, 0.451660f, 0.465576f, 0.480469f, 0.494629f, 0.508301f, 0.522949f, 0.538086f, 0.551758f,
+ 0.567383f, 0.582031f, 0.596191f, 0.610840f, 0.625977f, 0.639648f, 0.655273f, 0.670410f, 0.685547f, 0.700684f, 0.842285f, 0.837402f,
+ 0.829590f, 0.821289f, 0.813965f, 0.808105f, 0.003504f, 0.010445f, 0.017609f, 0.025131f, 0.032349f, 0.040314f, 0.047485f, 0.055756f,
+ 0.064026f, 0.072571f, 0.080872f, 0.089661f, 0.099426f, 0.108459f, 0.118286f, 0.127930f, 0.137817f, 0.147583f, 0.158203f, 0.169189f,
+ 0.180908f, 0.191040f, 0.203003f, 0.214111f, 0.225708f, 0.237549f, 0.249023f, 0.261475f, 0.273926f, 0.286865f, 0.299316f, 0.311768f,
+ 0.325684f, 0.338623f, 0.351562f, 0.364746f, 0.378418f, 0.392578f, 0.405518f, 0.419678f, 0.433105f, 0.447998f, 0.461670f, 0.475830f,
+ 0.490479f, 0.503906f, 0.519531f, 0.533203f, 0.547852f, 0.562988f, 0.576660f, 0.591797f, 0.606445f, 0.622070f, 0.636719f, 0.652344f,
+ 0.666504f, 0.682617f, 0.833496f, 0.830078f, 0.822754f, 0.815918f, 0.808594f, 0.802734f, 0.003447f, 0.009941f, 0.016373f, 0.023300f,
+ 0.030228f, 0.037689f, 0.044128f, 0.052551f, 0.059845f, 0.068115f, 0.076538f, 0.083862f, 0.092896f, 0.101440f, 0.110596f, 0.119995f,
+ 0.129028f, 0.138916f, 0.148926f, 0.158936f, 0.169189f, 0.180176f, 0.190308f, 0.201416f, 0.212769f, 0.224365f, 0.235962f, 0.247192f,
+ 0.259033f, 0.271973f, 0.283936f, 0.296631f, 0.309570f, 0.321777f, 0.334961f, 0.348389f, 0.361572f, 0.374756f, 0.388184f, 0.401611f,
+ 0.415771f, 0.429443f, 0.443359f, 0.457520f, 0.471436f, 0.486084f, 0.500977f, 0.514648f, 0.528809f, 0.543457f, 0.558594f, 0.573242f,
+ 0.588867f, 0.603516f, 0.617676f, 0.633301f, 0.648926f, 0.664551f, 0.824219f, 0.823242f, 0.815918f, 0.809082f, 0.802246f, 0.796387f,
+ 0.003141f, 0.009407f, 0.015251f, 0.021851f, 0.028107f, 0.034882f, 0.041779f, 0.048340f, 0.056244f, 0.062988f, 0.071106f, 0.078796f,
+ 0.087036f, 0.094910f, 0.103149f, 0.112305f, 0.121460f, 0.130371f, 0.139404f, 0.149048f, 0.159180f, 0.169189f, 0.179565f, 0.189087f,
+ 0.200317f, 0.211548f, 0.222412f, 0.233765f, 0.245117f, 0.257324f, 0.269043f, 0.281006f, 0.293213f, 0.305664f, 0.318848f, 0.331055f,
+ 0.343750f, 0.358398f, 0.369873f, 0.384033f, 0.397217f, 0.411865f, 0.424805f, 0.438965f, 0.453125f, 0.467529f, 0.481689f, 0.495850f,
+ 0.510254f, 0.524414f, 0.539551f, 0.554688f, 0.569824f, 0.584961f, 0.599121f, 0.614258f, 0.629883f, 0.645020f, 0.815430f, 0.814453f,
+ 0.809570f, 0.802734f, 0.796875f, 0.791504f, 0.002838f, 0.008461f, 0.014236f, 0.020676f, 0.026749f, 0.032593f, 0.039032f, 0.045715f,
+ 0.052216f, 0.059479f, 0.066467f, 0.073608f, 0.080933f, 0.088623f, 0.096619f, 0.104919f, 0.113098f, 0.121521f, 0.130493f, 0.139526f,
+ 0.148560f, 0.158203f, 0.167969f, 0.177979f, 0.187988f, 0.198730f, 0.208862f, 0.220093f, 0.231323f, 0.242798f, 0.253906f, 0.265869f,
+ 0.278320f, 0.289551f, 0.302246f, 0.314941f, 0.327393f, 0.340088f, 0.353516f, 0.365967f, 0.379883f, 0.392822f, 0.406738f, 0.420898f,
+ 0.434814f, 0.447998f, 0.462891f, 0.477539f, 0.491455f, 0.506836f, 0.520996f, 0.536133f, 0.550781f, 0.565918f, 0.581055f, 0.596680f,
+ 0.611816f, 0.627441f, 0.806152f, 0.807617f, 0.801270f, 0.796387f, 0.790039f, 0.784668f, 0.002689f, 0.008102f, 0.013618f, 0.019058f,
+ 0.024719f, 0.030548f, 0.036560f, 0.042725f, 0.048615f, 0.054779f, 0.061615f, 0.068604f, 0.075012f, 0.082703f, 0.090271f, 0.097900f,
+ 0.105530f, 0.113586f, 0.121826f, 0.130371f, 0.139282f, 0.147705f, 0.157349f, 0.166504f, 0.176147f, 0.186401f, 0.196289f, 0.207520f,
+ 0.217651f, 0.228394f, 0.239868f, 0.251465f, 0.262451f, 0.274414f, 0.286377f, 0.298828f, 0.311035f, 0.323730f, 0.336670f, 0.349121f,
+ 0.362549f, 0.375244f, 0.389160f, 0.402344f, 0.417236f, 0.429932f, 0.443848f, 0.458984f, 0.472168f, 0.487793f, 0.501953f, 0.517578f,
+ 0.531738f, 0.546875f, 0.561523f, 0.576660f, 0.593262f, 0.608398f, 0.797852f, 0.798828f, 0.794922f, 0.789551f, 0.784668f, 0.779297f,
+ 0.002666f, 0.007462f, 0.012596f, 0.018066f, 0.023026f, 0.028412f, 0.033813f, 0.039398f, 0.045166f, 0.051239f, 0.057587f, 0.063721f,
+ 0.070312f, 0.077148f, 0.084167f, 0.090820f, 0.098267f, 0.105591f, 0.113159f, 0.121460f, 0.129761f, 0.138428f, 0.147217f, 0.156128f,
+ 0.165283f, 0.174438f, 0.183960f, 0.194092f, 0.204834f, 0.214844f, 0.225830f, 0.236816f, 0.247925f, 0.259033f, 0.270752f, 0.282227f,
+ 0.294678f, 0.306641f, 0.319336f, 0.332031f, 0.344482f, 0.357910f, 0.371094f, 0.384033f, 0.398682f, 0.412109f, 0.425781f, 0.440186f,
+ 0.454102f, 0.468018f, 0.482910f, 0.497314f, 0.512207f, 0.528320f, 0.542969f, 0.558594f, 0.573242f, 0.589355f, 0.787598f, 0.791016f,
+ 0.787109f, 0.781738f, 0.777344f, 0.772461f, 0.002569f, 0.007069f, 0.012199f, 0.016739f, 0.021393f, 0.026672f, 0.031189f, 0.037109f,
+ 0.042480f, 0.047729f, 0.053345f, 0.059387f, 0.065430f, 0.071838f, 0.078186f, 0.084167f, 0.091492f, 0.098816f, 0.105774f, 0.112976f,
+ 0.121155f, 0.129028f, 0.136963f, 0.145508f, 0.153687f, 0.163086f, 0.172363f, 0.181885f, 0.191406f, 0.201782f, 0.211670f, 0.222412f,
+ 0.233032f, 0.244263f, 0.255371f, 0.266846f, 0.278809f, 0.290527f, 0.302734f, 0.314697f, 0.327393f, 0.340820f, 0.353027f, 0.366455f,
+ 0.380127f, 0.393799f, 0.406006f, 0.421143f, 0.435059f, 0.449707f, 0.463623f, 0.479248f, 0.494141f, 0.509277f, 0.523438f, 0.539551f,
+ 0.555176f, 0.570801f, 0.778320f, 0.783203f, 0.779785f, 0.775879f, 0.770996f, 0.767090f, 0.002398f, 0.006733f, 0.010918f, 0.015495f,
+ 0.020203f, 0.024963f, 0.029663f, 0.034485f, 0.039246f, 0.044678f, 0.049896f, 0.055267f, 0.060486f, 0.066345f, 0.072693f, 0.078857f,
+ 0.085083f, 0.091370f, 0.097961f, 0.105530f, 0.112244f, 0.119629f, 0.127563f, 0.135376f, 0.143799f, 0.152100f, 0.160889f, 0.169922f,
+ 0.178833f, 0.188843f, 0.198608f, 0.208496f, 0.218628f, 0.229492f, 0.240479f, 0.251953f, 0.262695f, 0.274902f, 0.286377f, 0.298340f,
+ 0.310547f, 0.323242f, 0.335693f, 0.349365f, 0.362061f, 0.375000f, 0.388916f, 0.402832f, 0.416748f, 0.430420f, 0.445068f, 0.459473f,
+ 0.474854f, 0.489258f, 0.504883f, 0.519531f, 0.535645f, 0.551758f, 0.769043f, 0.774902f, 0.771973f, 0.768555f, 0.764160f, 0.759766f,
+ 0.002062f, 0.006191f, 0.010384f, 0.014786f, 0.018402f, 0.023270f, 0.027435f, 0.031891f, 0.036163f, 0.041199f, 0.045685f, 0.051208f,
+ 0.056244f, 0.061371f, 0.066772f, 0.072510f, 0.078369f, 0.084656f, 0.091125f, 0.097290f, 0.104309f, 0.111145f, 0.118164f, 0.126221f,
+ 0.133301f, 0.141724f, 0.149658f, 0.157837f, 0.167236f, 0.176025f, 0.185547f, 0.195190f, 0.205444f, 0.215332f, 0.225830f, 0.236084f,
+ 0.247314f, 0.259033f, 0.270020f, 0.281982f, 0.293701f, 0.305908f, 0.318848f, 0.331787f, 0.344482f, 0.357178f, 0.370361f, 0.384521f,
+ 0.397461f, 0.411621f, 0.426025f, 0.440674f, 0.455322f, 0.470703f, 0.485596f, 0.500977f, 0.517578f, 0.532227f, 0.759277f, 0.766602f,
+ 0.764160f, 0.761230f, 0.757324f, 0.753418f, 0.002064f, 0.005859f, 0.009613f, 0.013626f, 0.017456f, 0.021606f, 0.025574f, 0.029526f,
+ 0.034302f, 0.038422f, 0.042938f, 0.047485f, 0.052155f, 0.056763f, 0.061951f, 0.067139f, 0.072754f, 0.078308f, 0.084167f, 0.090149f,
+ 0.096191f, 0.102722f, 0.109558f, 0.116699f, 0.123901f, 0.131104f, 0.139160f, 0.146729f, 0.155273f, 0.163940f, 0.173096f, 0.182129f,
+ 0.192017f, 0.201172f, 0.211060f, 0.221558f, 0.232544f, 0.243530f, 0.254150f, 0.266113f, 0.277588f, 0.289307f, 0.301758f, 0.313965f,
+ 0.326904f, 0.338867f, 0.352051f, 0.366211f, 0.379150f, 0.393066f, 0.407471f, 0.421875f, 0.436768f, 0.450439f, 0.466553f, 0.481201f,
+ 0.497314f, 0.513184f, 0.749512f, 0.758301f, 0.756348f, 0.753906f, 0.750000f, 0.746582f, 0.001851f, 0.005405f, 0.009109f, 0.012589f,
+ 0.016129f, 0.020020f, 0.023926f, 0.027481f, 0.031738f, 0.035492f, 0.039734f, 0.044128f, 0.048065f, 0.052765f, 0.057373f, 0.061859f,
+ 0.066711f, 0.072388f, 0.077393f, 0.083130f, 0.088745f, 0.094727f, 0.101135f, 0.107666f, 0.114380f, 0.121704f, 0.128540f, 0.136108f,
+ 0.144043f, 0.151733f, 0.160522f, 0.169678f, 0.178589f, 0.187622f, 0.197998f, 0.207397f, 0.217285f, 0.227905f, 0.238892f, 0.250000f,
+ 0.261230f, 0.272461f, 0.284180f, 0.296387f, 0.308838f, 0.321533f, 0.334473f, 0.347656f, 0.361328f, 0.375000f, 0.388672f, 0.402588f,
+ 0.417969f, 0.432617f, 0.447021f, 0.461914f, 0.478516f, 0.493652f, 0.739258f, 0.749512f, 0.749023f, 0.745605f, 0.742188f, 0.739746f,
+ 0.001666f, 0.005405f, 0.008575f, 0.011696f, 0.015327f, 0.018646f, 0.022293f, 0.025650f, 0.029327f, 0.032776f, 0.036530f, 0.040619f,
+ 0.044128f, 0.048828f, 0.052887f, 0.057098f, 0.061829f, 0.066467f, 0.071350f, 0.076355f, 0.081909f, 0.087341f, 0.092896f, 0.099304f,
+ 0.105469f, 0.112000f, 0.118835f, 0.125977f, 0.133545f, 0.140991f, 0.148438f, 0.156982f, 0.165771f, 0.174805f, 0.183960f, 0.193115f,
+ 0.203369f, 0.212891f, 0.223389f, 0.234497f, 0.244751f, 0.256348f, 0.268066f, 0.279541f, 0.291260f, 0.303955f, 0.316406f, 0.329590f,
+ 0.342529f, 0.355957f, 0.369385f, 0.384766f, 0.398926f, 0.413330f, 0.428467f, 0.442383f, 0.458740f, 0.474609f, 0.728516f, 0.740723f,
+ 0.740234f, 0.738281f, 0.735352f, 0.732910f, 0.001534f, 0.004936f, 0.007980f, 0.011223f, 0.013893f, 0.017212f, 0.020294f, 0.023361f,
+ 0.026688f, 0.030182f, 0.033600f, 0.037537f, 0.040924f, 0.044495f, 0.048340f, 0.052155f, 0.056732f, 0.061035f, 0.065430f, 0.069824f,
+ 0.075073f, 0.080078f, 0.085571f, 0.091003f, 0.096863f, 0.103271f, 0.109009f, 0.115723f, 0.123230f, 0.129639f, 0.137207f, 0.145264f,
+ 0.153320f, 0.161499f, 0.170410f, 0.179688f, 0.189087f, 0.198364f, 0.208740f, 0.218750f, 0.229126f, 0.240356f, 0.251465f, 0.263184f,
+ 0.274902f, 0.286621f, 0.299072f, 0.311768f, 0.324463f, 0.337402f, 0.351074f, 0.364746f, 0.378662f, 0.394287f, 0.408936f, 0.423096f,
+ 0.439453f, 0.455322f, 0.716797f, 0.731934f, 0.732422f, 0.729980f, 0.728027f, 0.725586f, 0.001639f, 0.004337f, 0.007439f, 0.009888f,
+ 0.013092f, 0.015717f, 0.018921f, 0.021805f, 0.024612f, 0.027542f, 0.030762f, 0.034088f, 0.037598f, 0.041107f, 0.044189f, 0.047699f,
+ 0.051666f, 0.055664f, 0.059723f, 0.064148f, 0.068542f, 0.073425f, 0.078003f, 0.083435f, 0.088806f, 0.094360f, 0.100159f, 0.106079f,
+ 0.112915f, 0.119690f, 0.125977f, 0.133667f, 0.141357f, 0.149414f, 0.157349f, 0.166260f, 0.175049f, 0.184326f, 0.193970f, 0.203735f,
+ 0.214355f, 0.224609f, 0.235352f, 0.246460f, 0.257568f, 0.269287f, 0.281738f, 0.294189f, 0.305908f, 0.319824f, 0.332520f, 0.346680f,
+ 0.360596f, 0.375244f, 0.389648f, 0.404297f, 0.419189f, 0.435791f, 0.707520f, 0.723145f, 0.723633f, 0.722656f, 0.720703f, 0.717773f,
+ 0.001469f, 0.004345f, 0.006844f, 0.009483f, 0.012428f, 0.014679f, 0.017166f, 0.019989f, 0.022949f, 0.025574f, 0.028320f, 0.031525f,
+ 0.034088f, 0.037323f, 0.040710f, 0.043762f, 0.047119f, 0.050873f, 0.054352f, 0.058441f, 0.062561f, 0.066711f, 0.071167f, 0.075989f,
+ 0.080627f, 0.086426f, 0.091553f, 0.097473f, 0.103210f, 0.109680f, 0.115723f, 0.122986f, 0.129761f, 0.137451f, 0.145142f, 0.153198f,
+ 0.161621f, 0.170654f, 0.179688f, 0.189087f, 0.198730f, 0.209229f, 0.219604f, 0.230225f, 0.241211f, 0.252197f, 0.264404f, 0.276367f,
+ 0.288574f, 0.301270f, 0.314453f, 0.328125f, 0.341309f, 0.354980f, 0.370117f, 0.385498f, 0.399902f, 0.415771f, 0.696289f, 0.714355f,
+ 0.715820f, 0.714355f, 0.712891f, 0.710449f, 0.001227f, 0.003862f, 0.006245f, 0.008644f, 0.010796f, 0.013344f, 0.015823f, 0.018448f,
+ 0.020645f, 0.023331f, 0.025681f, 0.028305f, 0.030975f, 0.033722f, 0.036987f, 0.039673f, 0.043121f, 0.046112f, 0.049774f, 0.053406f,
+ 0.056854f, 0.060760f, 0.064697f, 0.069397f, 0.073364f, 0.078369f, 0.083313f, 0.088257f, 0.094116f, 0.100098f, 0.105957f, 0.112122f,
+ 0.118774f, 0.125854f, 0.133057f, 0.140869f, 0.148682f, 0.157227f, 0.165405f, 0.174927f, 0.184082f, 0.193726f, 0.204102f, 0.214111f,
+ 0.225098f, 0.236328f, 0.247314f, 0.259277f, 0.270752f, 0.282959f, 0.296143f, 0.309082f, 0.322510f, 0.336426f, 0.350830f, 0.365479f,
+ 0.380371f, 0.396240f, 0.684570f, 0.705078f, 0.706543f, 0.706543f, 0.705078f, 0.703125f, 0.001069f, 0.003525f, 0.006062f, 0.008286f,
+ 0.010178f, 0.012589f, 0.014542f, 0.017075f, 0.019241f, 0.021179f, 0.023499f, 0.026047f, 0.028137f, 0.030762f, 0.033417f, 0.035889f,
+ 0.038757f, 0.041779f, 0.044586f, 0.048309f, 0.051056f, 0.054810f, 0.058777f, 0.062347f, 0.066528f, 0.070740f, 0.075256f, 0.080261f,
+ 0.085205f, 0.090393f, 0.095886f, 0.102478f, 0.108154f, 0.114441f, 0.121399f, 0.128784f, 0.135742f, 0.144165f, 0.151978f, 0.160767f,
+ 0.169434f, 0.178833f, 0.188721f, 0.198608f, 0.208984f, 0.220215f, 0.230957f, 0.241943f, 0.253906f, 0.265869f, 0.278564f, 0.291260f,
+ 0.304443f, 0.318359f, 0.332031f, 0.346680f, 0.361572f, 0.377197f, 0.673828f, 0.695801f, 0.698242f, 0.697754f, 0.697266f, 0.695312f,
+ 0.001211f, 0.003250f, 0.005112f, 0.007195f, 0.009651f, 0.011414f, 0.013641f, 0.015205f, 0.017334f, 0.019608f, 0.021164f, 0.023712f,
+ 0.025726f, 0.027863f, 0.029984f, 0.032410f, 0.035034f, 0.037689f, 0.040466f, 0.042938f, 0.046478f, 0.049591f, 0.052856f, 0.056274f,
+ 0.060089f, 0.063721f, 0.068115f, 0.072266f, 0.076904f, 0.081970f, 0.087036f, 0.092285f, 0.097961f, 0.104309f, 0.110535f, 0.117126f,
+ 0.124084f, 0.131226f, 0.139038f, 0.147095f, 0.155884f, 0.164429f, 0.174194f, 0.183228f, 0.192749f, 0.203491f, 0.214233f, 0.224976f,
+ 0.236206f, 0.247925f, 0.260498f, 0.272705f, 0.285889f, 0.299805f, 0.312988f, 0.327637f, 0.342529f, 0.356934f, 0.662598f, 0.686523f,
+ 0.689453f, 0.689453f, 0.688965f, 0.687500f, 0.001138f, 0.003206f, 0.005180f, 0.007309f, 0.008377f, 0.010635f, 0.012352f, 0.014153f,
+ 0.015640f, 0.017487f, 0.019272f, 0.021164f, 0.023026f, 0.025314f, 0.027222f, 0.029282f, 0.031433f, 0.033600f, 0.036041f, 0.038788f,
+ 0.041626f, 0.044281f, 0.047455f, 0.050507f, 0.054047f, 0.057556f, 0.061188f, 0.065063f, 0.069214f, 0.073486f, 0.078369f, 0.083191f,
+ 0.088196f, 0.093811f, 0.099609f, 0.106018f, 0.112305f, 0.119385f, 0.126343f, 0.134033f, 0.142090f, 0.150635f, 0.159546f, 0.168579f,
+ 0.177734f, 0.187500f, 0.198242f, 0.208618f, 0.219604f, 0.231812f, 0.242188f, 0.254883f, 0.267578f, 0.281494f, 0.294434f, 0.308350f,
+ 0.322998f, 0.338379f, 0.651367f, 0.676758f, 0.681152f, 0.680664f, 0.680664f, 0.679688f, 0.000977f, 0.002806f, 0.004559f, 0.006176f,
+ 0.008034f, 0.009476f, 0.011131f, 0.012741f, 0.014275f, 0.015732f, 0.017334f, 0.019104f, 0.020767f, 0.022293f, 0.024323f, 0.026016f,
+ 0.028198f, 0.030197f, 0.032257f, 0.034515f, 0.036957f, 0.039856f, 0.042084f, 0.044891f, 0.047791f, 0.051147f, 0.054535f, 0.058197f,
+ 0.061768f, 0.065674f, 0.069946f, 0.074585f, 0.079102f, 0.084412f, 0.089600f, 0.095398f, 0.101196f, 0.107544f, 0.114258f, 0.121094f,
+ 0.128662f, 0.137085f, 0.145020f, 0.153687f, 0.162720f, 0.172607f, 0.182129f, 0.192749f, 0.203125f, 0.214111f, 0.226074f, 0.237671f,
+ 0.249878f, 0.262207f, 0.275635f, 0.289551f, 0.304199f, 0.318848f, 0.639160f, 0.666992f, 0.671387f, 0.671875f, 0.671875f, 0.671387f,
+ 0.000968f, 0.002722f, 0.004318f, 0.005634f, 0.007393f, 0.008667f, 0.010139f, 0.011383f, 0.012856f, 0.014389f, 0.015427f, 0.016907f,
+ 0.018387f, 0.020081f, 0.021683f, 0.023315f, 0.025085f, 0.026840f, 0.028641f, 0.030624f, 0.032837f, 0.035065f, 0.037445f, 0.039948f,
+ 0.042542f, 0.045410f, 0.048340f, 0.051514f, 0.054840f, 0.058502f, 0.062408f, 0.066223f, 0.070679f, 0.075134f, 0.080078f, 0.085388f,
+ 0.090515f, 0.096436f, 0.102722f, 0.109314f, 0.116333f, 0.123352f, 0.131592f, 0.139526f, 0.147949f, 0.156860f, 0.166748f, 0.176758f,
+ 0.187134f, 0.197632f, 0.209106f, 0.220337f, 0.232666f, 0.244751f, 0.257568f, 0.270996f, 0.284912f, 0.300537f, 0.627441f, 0.657227f,
+ 0.662598f, 0.663574f, 0.663574f, 0.663086f, 0.001081f, 0.002466f, 0.003862f, 0.005348f, 0.006447f, 0.007927f, 0.009018f, 0.010490f,
+ 0.011436f, 0.012627f, 0.013916f, 0.015015f, 0.016449f, 0.017563f, 0.019165f, 0.020706f, 0.021973f, 0.023834f, 0.025467f, 0.027130f,
+ 0.029175f, 0.030991f, 0.033081f, 0.035156f, 0.037384f, 0.040039f, 0.042603f, 0.045502f, 0.048492f, 0.051636f, 0.054962f, 0.058716f,
+ 0.062439f, 0.066467f, 0.071045f, 0.075378f, 0.080811f, 0.085815f, 0.091492f, 0.098022f, 0.103943f, 0.111023f, 0.118164f, 0.125732f,
+ 0.133911f, 0.142456f, 0.151367f, 0.161011f, 0.170898f, 0.181396f, 0.192139f, 0.203247f, 0.214844f, 0.227173f, 0.239380f, 0.252441f,
+ 0.266602f, 0.281006f, 0.616699f, 0.647949f, 0.653320f, 0.655273f, 0.654785f, 0.655273f, 0.000735f, 0.002331f, 0.003601f, 0.005005f,
+ 0.005825f, 0.007061f, 0.008049f, 0.009148f, 0.010315f, 0.011131f, 0.012230f, 0.013367f, 0.014328f, 0.015541f, 0.016968f, 0.018234f,
+ 0.019257f, 0.020798f, 0.022202f, 0.023666f, 0.025452f, 0.027115f, 0.028885f, 0.030792f, 0.032715f, 0.035034f, 0.037323f, 0.039825f,
+ 0.042419f, 0.045258f, 0.048157f, 0.051422f, 0.054810f, 0.058411f, 0.062378f, 0.066528f, 0.071106f, 0.076233f, 0.081116f, 0.086853f,
+ 0.092407f, 0.098938f, 0.105469f, 0.112854f, 0.120361f, 0.128418f, 0.136841f, 0.145752f, 0.155273f, 0.165283f, 0.175537f, 0.186646f,
+ 0.197510f, 0.209473f, 0.221558f, 0.234619f, 0.248047f, 0.261719f, 0.603516f, 0.636719f, 0.644531f, 0.645020f, 0.645508f, 0.646484f,
+ 0.000837f, 0.002073f, 0.003357f, 0.004292f, 0.005409f, 0.006271f, 0.007271f, 0.007973f, 0.008873f, 0.009956f, 0.010811f, 0.012032f,
+ 0.012848f, 0.013664f, 0.014870f, 0.015839f, 0.017090f, 0.018280f, 0.019333f, 0.020691f, 0.022186f, 0.023453f, 0.025223f, 0.026779f,
+ 0.028595f, 0.030441f, 0.032410f, 0.034729f, 0.036743f, 0.039307f, 0.042023f, 0.044434f, 0.047791f, 0.050781f, 0.054413f, 0.058075f,
+ 0.061951f, 0.066711f, 0.071106f, 0.076355f, 0.081848f, 0.087341f, 0.093872f, 0.099854f, 0.107483f, 0.114441f, 0.122925f, 0.131104f,
+ 0.140381f, 0.149414f, 0.159180f, 0.170166f, 0.181152f, 0.192139f, 0.204468f, 0.216553f, 0.230103f, 0.244507f, 0.592773f, 0.626953f,
+ 0.635254f, 0.637207f, 0.636719f, 0.637695f, 0.000524f, 0.001863f, 0.003014f, 0.003777f, 0.004852f, 0.005516f, 0.006428f, 0.007111f,
+ 0.008095f, 0.008888f, 0.009476f, 0.010345f, 0.011063f, 0.012016f, 0.012810f, 0.013786f, 0.014648f, 0.015717f, 0.016891f, 0.017929f,
+ 0.019150f, 0.020401f, 0.021606f, 0.023193f, 0.024597f, 0.026276f, 0.027939f, 0.029770f, 0.031738f, 0.033936f, 0.036194f, 0.038574f,
+ 0.041107f, 0.043945f, 0.047180f, 0.050385f, 0.054291f, 0.057770f, 0.061981f, 0.066345f, 0.071167f, 0.076355f, 0.082153f, 0.088074f,
+ 0.094666f, 0.101685f, 0.109131f, 0.117249f, 0.125610f, 0.134399f, 0.143921f, 0.154175f, 0.164795f, 0.175659f, 0.187256f, 0.199341f,
+ 0.211670f, 0.225464f, 0.580078f, 0.617676f, 0.625000f, 0.627930f, 0.628906f, 0.628906f, 0.000657f, 0.001829f, 0.002909f, 0.003525f,
+ 0.004295f, 0.005051f, 0.005592f, 0.006123f, 0.006920f, 0.007553f, 0.008339f, 0.008888f, 0.009689f, 0.010262f, 0.011017f, 0.011848f,
+ 0.012634f, 0.013489f, 0.014572f, 0.015427f, 0.016449f, 0.017426f, 0.018539f, 0.019852f, 0.021133f, 0.022507f, 0.023834f, 0.025375f,
+ 0.027084f, 0.028976f, 0.030792f, 0.032959f, 0.035400f, 0.037720f, 0.040405f, 0.043243f, 0.046356f, 0.049530f, 0.053314f, 0.057190f,
+ 0.061554f, 0.066223f, 0.071472f, 0.076782f, 0.082825f, 0.089417f, 0.096191f, 0.103210f, 0.111633f, 0.119934f, 0.128662f, 0.138550f,
+ 0.148315f, 0.158813f, 0.170288f, 0.182373f, 0.194458f, 0.207642f, 0.567383f, 0.606445f, 0.615234f, 0.619141f, 0.620117f, 0.620117f,
+ 0.000584f, 0.001548f, 0.002333f, 0.003086f, 0.003660f, 0.004303f, 0.005020f, 0.005543f, 0.006042f, 0.006538f, 0.007118f, 0.007641f,
+ 0.008301f, 0.008919f, 0.009499f, 0.010147f, 0.010918f, 0.011414f, 0.012222f, 0.013084f, 0.013901f, 0.014954f, 0.015671f, 0.016724f,
+ 0.017914f, 0.019012f, 0.020325f, 0.021698f, 0.022949f, 0.024445f, 0.026215f, 0.027954f, 0.029755f, 0.032043f, 0.034210f, 0.036591f,
+ 0.039215f, 0.042297f, 0.045441f, 0.048676f, 0.052612f, 0.056580f, 0.061432f, 0.066040f, 0.071350f, 0.077332f, 0.083496f, 0.090393f,
+ 0.097717f, 0.105835f, 0.114380f, 0.123413f, 0.133301f, 0.143066f, 0.153931f, 0.165039f, 0.177124f, 0.190308f, 0.555176f, 0.597656f,
+ 0.604980f, 0.609375f, 0.609863f, 0.611328f, 0.000438f, 0.001456f, 0.001925f, 0.002811f, 0.003246f, 0.003731f, 0.004108f, 0.004669f,
+ 0.005344f, 0.005535f, 0.005913f, 0.006641f, 0.007038f, 0.007473f, 0.008049f, 0.008675f, 0.009361f, 0.009689f, 0.010513f, 0.011032f,
+ 0.011894f, 0.012695f, 0.013390f, 0.014183f, 0.015114f, 0.016037f, 0.016998f, 0.018280f, 0.019272f, 0.020645f, 0.022003f, 0.023361f,
+ 0.024796f, 0.026779f, 0.028656f, 0.030685f, 0.032928f, 0.035370f, 0.038147f, 0.040955f, 0.044403f, 0.047821f, 0.052032f, 0.056183f,
+ 0.060974f, 0.066162f, 0.071777f, 0.078125f, 0.084656f, 0.092102f, 0.100159f, 0.109009f, 0.117981f, 0.127563f, 0.138306f, 0.148804f,
+ 0.160645f, 0.173218f, 0.542969f, 0.586914f, 0.594727f, 0.599609f, 0.601074f, 0.601074f, 0.000520f, 0.001104f, 0.001921f, 0.002256f,
+ 0.002886f, 0.003389f, 0.003689f, 0.004063f, 0.004440f, 0.004829f, 0.005230f, 0.005466f, 0.005966f, 0.006332f, 0.006786f, 0.007347f,
+ 0.007835f, 0.008232f, 0.008812f, 0.009216f, 0.009865f, 0.010490f, 0.011124f, 0.011803f, 0.012573f, 0.013390f, 0.014275f, 0.015121f,
+ 0.016144f, 0.016953f, 0.018234f, 0.019257f, 0.020782f, 0.022064f, 0.023743f, 0.025360f, 0.027176f, 0.029327f, 0.031616f, 0.034058f,
+ 0.036957f, 0.039917f, 0.043182f, 0.047272f, 0.051025f, 0.055695f, 0.060913f, 0.066345f, 0.072693f, 0.079285f, 0.086548f, 0.094543f,
+ 0.103271f, 0.112793f, 0.122864f, 0.132812f, 0.144531f, 0.156616f, 0.530273f, 0.576660f, 0.585449f, 0.590332f, 0.592285f, 0.593262f,
+ 0.000366f, 0.001040f, 0.001583f, 0.002129f, 0.002522f, 0.002792f, 0.003012f, 0.003420f, 0.003630f, 0.003967f, 0.004246f, 0.004623f,
+ 0.005039f, 0.005253f, 0.005627f, 0.006096f, 0.006447f, 0.006939f, 0.007179f, 0.007710f, 0.008324f, 0.008698f, 0.009247f, 0.009796f,
+ 0.010414f, 0.011063f, 0.011627f, 0.012543f, 0.013191f, 0.014099f, 0.014938f, 0.015930f, 0.016983f, 0.018219f, 0.019440f, 0.020813f,
+ 0.022324f, 0.024002f, 0.025818f, 0.027969f, 0.030289f, 0.032898f, 0.035583f, 0.038727f, 0.042450f, 0.046234f, 0.050781f, 0.055695f,
+ 0.061157f, 0.067383f, 0.074158f, 0.081360f, 0.089478f, 0.098267f, 0.107788f, 0.117737f, 0.129028f, 0.140503f, 0.517578f, 0.566406f,
+ 0.575195f, 0.581055f, 0.582520f, 0.584473f, 0.000482f, 0.001008f, 0.001481f, 0.001818f, 0.002001f, 0.002296f, 0.002569f, 0.002781f,
+ 0.002998f, 0.003319f, 0.003620f, 0.003828f, 0.004082f, 0.004364f, 0.004658f, 0.004978f, 0.005257f, 0.005665f, 0.005993f, 0.006340f,
+ 0.006725f, 0.007160f, 0.007576f, 0.008095f, 0.008522f, 0.008980f, 0.009621f, 0.010170f, 0.010765f, 0.011543f, 0.012161f, 0.013023f,
+ 0.013840f, 0.014801f, 0.015869f, 0.016861f, 0.018127f, 0.019379f, 0.020859f, 0.022583f, 0.024261f, 0.026596f, 0.028839f, 0.031555f,
+ 0.034271f, 0.037628f, 0.041504f, 0.045837f, 0.050598f, 0.056000f, 0.062134f, 0.068726f, 0.076172f, 0.084656f, 0.093567f, 0.103088f,
+ 0.113586f, 0.125000f, 0.504883f, 0.554688f, 0.565918f, 0.570801f, 0.573242f, 0.574219f, 0.000400f, 0.000803f, 0.001046f, 0.001427f,
+ 0.001657f, 0.001952f, 0.002033f, 0.002337f, 0.002453f, 0.002678f, 0.002871f, 0.003120f, 0.003286f, 0.003605f, 0.003817f, 0.004036f,
+ 0.004299f, 0.004604f, 0.004848f, 0.005142f, 0.005428f, 0.005871f, 0.006107f, 0.006584f, 0.006908f, 0.007332f, 0.007736f, 0.008186f,
+ 0.008820f, 0.009308f, 0.009964f, 0.010422f, 0.011200f, 0.011993f, 0.012726f, 0.013512f, 0.014511f, 0.015610f, 0.016724f, 0.017914f,
+ 0.019440f, 0.021057f, 0.022827f, 0.024933f, 0.027466f, 0.030197f, 0.033295f, 0.036896f, 0.041077f, 0.045776f, 0.050995f, 0.056976f,
+ 0.063721f, 0.071167f, 0.079773f, 0.089172f, 0.098633f, 0.109314f, 0.491699f, 0.543457f, 0.555176f, 0.561035f, 0.563477f, 0.565430f,
+ 0.000279f, 0.000821f, 0.000974f, 0.001161f, 0.001382f, 0.001583f, 0.001670f, 0.001934f, 0.002064f, 0.002153f, 0.002306f, 0.002544f,
+ 0.002670f, 0.002909f, 0.003052f, 0.003288f, 0.003429f, 0.003624f, 0.003893f, 0.004082f, 0.004406f, 0.004635f, 0.004925f, 0.005196f,
+ 0.005444f, 0.005764f, 0.006134f, 0.006546f, 0.006947f, 0.007343f, 0.007858f, 0.008270f, 0.008858f, 0.009346f, 0.010010f, 0.010757f,
+ 0.011475f, 0.012260f, 0.013206f, 0.014214f, 0.015236f, 0.016479f, 0.017975f, 0.019623f, 0.021515f, 0.023590f, 0.026062f, 0.028976f,
+ 0.032471f, 0.036224f, 0.040833f, 0.046082f, 0.052094f, 0.059052f, 0.066650f, 0.075684f, 0.084778f, 0.094971f, 0.479492f, 0.532715f,
+ 0.545898f, 0.551270f, 0.553711f, 0.555664f, 0.000253f, 0.000612f, 0.000835f, 0.000998f, 0.001111f, 0.001228f, 0.001334f, 0.001452f,
+ 0.001619f, 0.001757f, 0.001837f, 0.001920f, 0.002140f, 0.002321f, 0.002453f, 0.002544f, 0.002670f, 0.002790f, 0.003086f, 0.003260f,
+ 0.003422f, 0.003620f, 0.003893f, 0.004101f, 0.004326f, 0.004528f, 0.004761f, 0.005051f, 0.005444f, 0.005756f, 0.006065f, 0.006435f,
+ 0.006882f, 0.007378f, 0.007763f, 0.008286f, 0.008865f, 0.009506f, 0.010162f, 0.011024f, 0.011826f, 0.012917f, 0.013916f, 0.015175f,
+ 0.016602f, 0.018204f, 0.020035f, 0.022293f, 0.024948f, 0.028076f, 0.031921f, 0.036377f, 0.041565f, 0.047577f, 0.054535f, 0.062622f,
+ 0.071777f, 0.081787f, 0.465576f, 0.522461f, 0.535645f, 0.541992f, 0.544922f, 0.546875f, 0.000155f, 0.000398f, 0.000680f, 0.000828f,
+ 0.000907f, 0.000989f, 0.001113f, 0.001081f, 0.001253f, 0.001350f, 0.001453f, 0.001573f, 0.001661f, 0.001777f, 0.001829f, 0.001978f,
+ 0.002062f, 0.002216f, 0.002346f, 0.002470f, 0.002644f, 0.002804f, 0.002930f, 0.003134f, 0.003265f, 0.003485f, 0.003674f, 0.003866f,
+ 0.004154f, 0.004333f, 0.004707f, 0.004910f, 0.005180f, 0.005581f, 0.005875f, 0.006283f, 0.006729f, 0.007164f, 0.007713f, 0.008270f,
+ 0.008934f, 0.009727f, 0.010513f, 0.011482f, 0.012520f, 0.013710f, 0.015152f, 0.016815f, 0.018799f, 0.021118f, 0.024048f, 0.027756f,
+ 0.032104f, 0.037201f, 0.043518f, 0.050903f, 0.059418f, 0.068420f, 0.453125f, 0.511719f, 0.525391f, 0.530762f, 0.535156f, 0.536621f,
+ 0.000303f, 0.000337f, 0.000498f, 0.000560f, 0.000603f, 0.000721f, 0.000782f, 0.000845f, 0.000880f, 0.000988f, 0.001119f, 0.001184f,
+ 0.001258f, 0.001377f, 0.001420f, 0.001446f, 0.001590f, 0.001666f, 0.001754f, 0.001889f, 0.001980f, 0.002073f, 0.002216f, 0.002308f,
+ 0.002447f, 0.002562f, 0.002758f, 0.002899f, 0.003084f, 0.003328f, 0.003506f, 0.003641f, 0.003922f, 0.004147f, 0.004391f, 0.004665f,
+ 0.004959f, 0.005322f, 0.005695f, 0.006119f, 0.006588f, 0.007072f, 0.007790f, 0.008392f, 0.009178f, 0.010056f, 0.011124f, 0.012383f,
+ 0.013832f, 0.015587f, 0.017685f, 0.020309f, 0.023926f, 0.028076f, 0.033447f, 0.039978f, 0.047638f, 0.056335f, 0.440186f, 0.500000f,
+ 0.514160f, 0.520996f, 0.524414f, 0.526855f, 0.000132f, 0.000296f, 0.000368f, 0.000444f, 0.000501f, 0.000519f, 0.000631f, 0.000580f,
+ 0.000675f, 0.000735f, 0.000820f, 0.000840f, 0.000882f, 0.000946f, 0.001029f, 0.001070f, 0.001164f, 0.001221f, 0.001286f, 0.001317f,
+ 0.001416f, 0.001494f, 0.001607f, 0.001681f, 0.001763f, 0.001863f, 0.001978f, 0.002069f, 0.002169f, 0.002348f, 0.002451f, 0.002661f,
+ 0.002754f, 0.002943f, 0.003130f, 0.003323f, 0.003553f, 0.003813f, 0.004124f, 0.004364f, 0.004669f, 0.005062f, 0.005493f, 0.005985f,
+ 0.006546f, 0.007172f, 0.007950f, 0.008850f, 0.009857f, 0.011116f, 0.012695f, 0.014603f, 0.016983f, 0.020157f, 0.024490f, 0.029968f,
+ 0.036957f, 0.045166f, 0.426025f, 0.488770f, 0.503906f, 0.511719f, 0.515137f, 0.517578f, 0.000063f, 0.000160f, 0.000267f, 0.000282f,
+ 0.000339f, 0.000417f, 0.000377f, 0.000433f, 0.000472f, 0.000570f, 0.000563f, 0.000578f, 0.000599f, 0.000663f, 0.000681f, 0.000759f,
+ 0.000760f, 0.000845f, 0.000910f, 0.000941f, 0.000997f, 0.001057f, 0.001110f, 0.001169f, 0.001238f, 0.001288f, 0.001381f, 0.001441f,
+ 0.001514f, 0.001655f, 0.001693f, 0.001815f, 0.001910f, 0.002028f, 0.002153f, 0.002308f, 0.002441f, 0.002607f, 0.002783f, 0.002962f,
+ 0.003214f, 0.003458f, 0.003744f, 0.004051f, 0.004444f, 0.004883f, 0.005402f, 0.006031f, 0.006699f, 0.007610f, 0.008766f, 0.009933f,
+ 0.011688f, 0.013931f, 0.017075f, 0.021454f, 0.027313f, 0.035004f, 0.414307f, 0.478271f, 0.493652f, 0.501465f, 0.505859f, 0.508301f,
+ 0.000120f, 0.000194f, 0.000194f, 0.000205f, 0.000245f, 0.000246f, 0.000251f, 0.000301f, 0.000322f, 0.000332f, 0.000343f, 0.000413f,
+ 0.000397f, 0.000448f, 0.000481f, 0.000494f, 0.000545f, 0.000556f, 0.000582f, 0.000601f, 0.000653f, 0.000676f, 0.000726f, 0.000767f,
+ 0.000821f, 0.000840f, 0.000919f, 0.000952f, 0.001011f, 0.001054f, 0.001116f, 0.001186f, 0.001263f, 0.001337f, 0.001418f, 0.001482f,
+ 0.001607f, 0.001685f, 0.001842f, 0.001965f, 0.002090f, 0.002235f, 0.002420f, 0.002613f, 0.002851f, 0.003159f, 0.003492f, 0.003887f,
+ 0.004345f, 0.004906f, 0.005600f, 0.006474f, 0.007645f, 0.009186f, 0.011230f, 0.014305f, 0.019135f, 0.025848f, 0.400635f, 0.466797f,
+ 0.483398f, 0.490967f, 0.495117f, 0.498047f, 0.000030f, 0.000140f, 0.000121f, 0.000114f, 0.000147f, 0.000178f, 0.000159f, 0.000195f,
+ 0.000199f, 0.000204f, 0.000216f, 0.000223f, 0.000255f, 0.000271f, 0.000288f, 0.000302f, 0.000314f, 0.000346f, 0.000357f, 0.000395f,
+ 0.000397f, 0.000408f, 0.000436f, 0.000470f, 0.000501f, 0.000542f, 0.000547f, 0.000566f, 0.000612f, 0.000641f, 0.000692f, 0.000722f,
+ 0.000767f, 0.000798f, 0.000861f, 0.000898f, 0.000963f, 0.001030f, 0.001107f, 0.001164f, 0.001255f, 0.001361f, 0.001464f, 0.001591f,
+ 0.001719f, 0.001871f, 0.002111f, 0.002312f, 0.002617f, 0.002964f, 0.003368f, 0.003902f, 0.004654f, 0.005653f, 0.006958f, 0.008888f,
+ 0.012161f, 0.017822f, 0.388672f, 0.456543f, 0.473389f, 0.481201f, 0.486328f, 0.489014f, 0.000102f, 0.000076f, 0.000076f, 0.000075f,
+ 0.000095f, 0.000092f, 0.000109f, 0.000111f, 0.000112f, 0.000113f, 0.000126f, 0.000147f, 0.000135f, 0.000144f, 0.000165f, 0.000161f,
+ 0.000179f, 0.000192f, 0.000198f, 0.000202f, 0.000224f, 0.000232f, 0.000248f, 0.000259f, 0.000278f, 0.000295f, 0.000308f, 0.000320f,
+ 0.000340f, 0.000353f, 0.000379f, 0.000402f, 0.000423f, 0.000440f, 0.000472f, 0.000503f, 0.000526f, 0.000564f, 0.000610f, 0.000644f,
+ 0.000690f, 0.000741f, 0.000810f, 0.000862f, 0.000946f, 0.001024f, 0.001121f, 0.001247f, 0.001407f, 0.001603f, 0.001822f, 0.002144f,
+ 0.002539f, 0.003098f, 0.003901f, 0.005096f, 0.006931f, 0.011024f, 0.375244f, 0.444092f, 0.462158f, 0.470215f, 0.475586f, 0.478760f,
+ 0.000085f, 0.000061f, 0.000052f, 0.000047f, 0.000049f, 0.000046f, 0.000047f, 0.000050f, 0.000055f, 0.000069f, 0.000060f, 0.000062f,
+ 0.000077f, 0.000066f, 0.000069f, 0.000075f, 0.000084f, 0.000093f, 0.000093f, 0.000098f, 0.000102f, 0.000108f, 0.000111f, 0.000121f,
+ 0.000129f, 0.000136f, 0.000142f, 0.000154f, 0.000162f, 0.000172f, 0.000182f, 0.000187f, 0.000197f, 0.000209f, 0.000225f, 0.000231f,
+ 0.000246f, 0.000262f, 0.000290f, 0.000306f, 0.000321f, 0.000349f, 0.000380f, 0.000402f, 0.000437f, 0.000480f, 0.000525f, 0.000579f,
+ 0.000649f, 0.000735f, 0.000842f, 0.000984f, 0.001173f, 0.001451f, 0.001855f, 0.002485f, 0.003542f, 0.005753f, 0.362305f, 0.434326f,
+ 0.451904f, 0.460693f, 0.465576f, 0.468506f, 0.000064f, 0.000044f, 0.000036f, 0.000032f, 0.000029f, 0.000027f, 0.000025f, 0.000024f,
+ 0.000022f, 0.000023f, 0.000021f, 0.000027f, 0.000023f, 0.000022f, 0.000028f, 0.000031f, 0.000030f, 0.000034f, 0.000036f, 0.000038f,
+ 0.000040f, 0.000045f, 0.000048f, 0.000042f, 0.000047f, 0.000053f, 0.000055f, 0.000054f, 0.000060f, 0.000062f, 0.000065f, 0.000072f,
+ 0.000078f, 0.000075f, 0.000079f, 0.000087f, 0.000093f, 0.000098f, 0.000106f, 0.000113f, 0.000121f, 0.000126f, 0.000136f, 0.000150f,
+ 0.000159f, 0.000173f, 0.000190f, 0.000209f, 0.000235f, 0.000265f, 0.000302f, 0.000343f, 0.000416f, 0.000515f, 0.000665f, 0.000917f,
+ 0.001396f, 0.002401f, 0.349854f, 0.421875f, 0.440918f, 0.449951f, 0.455811f, 0.458008f, 0.000030f, 0.000020f, 0.000016f, 0.000014f,
+ 0.000014f, 0.000013f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f,
+ 0.000009f, 0.000008f, 0.000008f, 0.000008f, 0.000007f, 0.000007f, 0.000008f, 0.000008f, 0.000009f, 0.000011f, 0.000011f, 0.000013f,
+ 0.000013f, 0.000012f, 0.000013f, 0.000014f, 0.000016f, 0.000018f, 0.000018f, 0.000019f, 0.000021f, 0.000021f, 0.000023f, 0.000027f,
+ 0.000025f, 0.000028f, 0.000031f, 0.000032f, 0.000033f, 0.000038f, 0.000043f, 0.000046f, 0.000050f, 0.000055f, 0.000062f, 0.000074f,
+ 0.000088f, 0.000106f, 0.000138f, 0.000191f, 0.000312f, 0.000653f, 0.337402f, 0.410645f, 0.431152f, 0.438965f, 0.445068f, 0.448975f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000004f, 0.000004f, 0.000006f, 0.000010f, 0.000026f, 0.324219f, 0.399902f,
+ 0.419922f, 0.429688f, 0.435059f, 0.438965f,
+ },
+ {
+ 0.010521f, 0.032043f, 0.054443f, 0.076843f, 0.098572f, 0.121216f, 0.142700f, 0.164062f, 0.185913f, 0.207275f, 0.229004f, 0.249268f,
+ 0.270508f, 0.290527f, 0.311035f, 0.331055f, 0.350586f, 0.370361f, 0.389648f, 0.408936f, 0.428223f, 0.446533f, 0.465088f, 0.482666f,
+ 0.500977f, 0.519043f, 0.536133f, 0.553223f, 0.570801f, 0.587891f, 0.604980f, 0.621582f, 0.637207f, 0.653320f, 0.668945f, 0.685547f,
+ 0.700684f, 0.716309f, 0.730957f, 0.745605f, 0.760254f, 0.774902f, 0.789551f, 0.803711f, 0.816895f, 0.831543f, 0.845703f, 0.858887f,
+ 0.871582f, 0.885254f, 0.897949f, 0.910645f, 0.923340f, 0.936035f, 0.948242f, 0.959961f, 0.972168f, 0.984375f, 0.972656f, 0.936035f,
+ 0.910645f, 0.890137f, 0.872070f, 0.855957f, 0.010048f, 0.030350f, 0.051392f, 0.072266f, 0.093506f, 0.114319f, 0.135620f, 0.155273f,
+ 0.177124f, 0.197144f, 0.217773f, 0.237915f, 0.257568f, 0.277588f, 0.298096f, 0.316895f, 0.336182f, 0.355225f, 0.374268f, 0.393311f,
+ 0.411865f, 0.430176f, 0.448486f, 0.466309f, 0.483398f, 0.501465f, 0.519043f, 0.535645f, 0.552734f, 0.570312f, 0.586426f, 0.602539f,
+ 0.618652f, 0.635254f, 0.650879f, 0.666016f, 0.682129f, 0.697266f, 0.712402f, 0.727539f, 0.741699f, 0.756836f, 0.770996f, 0.785645f,
+ 0.799805f, 0.812988f, 0.826660f, 0.840332f, 0.854004f, 0.867676f, 0.881348f, 0.893066f, 0.907715f, 0.919434f, 0.932617f, 0.943848f,
+ 0.955566f, 0.968262f, 0.965332f, 0.930664f, 0.906738f, 0.886719f, 0.869629f, 0.854004f, 0.009254f, 0.028961f, 0.048615f, 0.068054f,
+ 0.088562f, 0.108093f, 0.128540f, 0.147705f, 0.167236f, 0.188599f, 0.207886f, 0.227295f, 0.244873f, 0.265625f, 0.284668f, 0.303955f,
+ 0.322510f, 0.340820f, 0.358887f, 0.378662f, 0.396484f, 0.414307f, 0.431885f, 0.448975f, 0.466797f, 0.484619f, 0.500977f, 0.519043f,
+ 0.535645f, 0.551758f, 0.568359f, 0.584961f, 0.600586f, 0.616699f, 0.632324f, 0.647949f, 0.663086f, 0.678223f, 0.693848f, 0.708984f,
+ 0.723633f, 0.738281f, 0.752930f, 0.767578f, 0.780762f, 0.794922f, 0.809082f, 0.822754f, 0.835938f, 0.849609f, 0.863770f, 0.875488f,
+ 0.888672f, 0.902344f, 0.915527f, 0.927246f, 0.939453f, 0.952637f, 0.958008f, 0.925293f, 0.901855f, 0.882812f, 0.866211f, 0.851562f,
+ 0.008736f, 0.027039f, 0.045807f, 0.064514f, 0.083801f, 0.102844f, 0.121826f, 0.140869f, 0.159302f, 0.179077f, 0.197388f, 0.216064f,
+ 0.234741f, 0.253662f, 0.271729f, 0.290283f, 0.308350f, 0.327148f, 0.344238f, 0.362061f, 0.381836f, 0.398926f, 0.416016f, 0.432373f,
+ 0.450195f, 0.466797f, 0.484375f, 0.500977f, 0.517090f, 0.533691f, 0.550781f, 0.567871f, 0.582031f, 0.598145f, 0.613770f, 0.629395f,
+ 0.645020f, 0.659668f, 0.675781f, 0.689941f, 0.705566f, 0.719727f, 0.734375f, 0.749512f, 0.763184f, 0.776855f, 0.791016f, 0.804688f,
+ 0.818848f, 0.832031f, 0.845215f, 0.858398f, 0.872559f, 0.884766f, 0.897949f, 0.909668f, 0.922852f, 0.936035f, 0.950684f, 0.919434f,
+ 0.896973f, 0.878906f, 0.862793f, 0.848633f, 0.008339f, 0.025543f, 0.043427f, 0.060974f, 0.078979f, 0.097168f, 0.115051f, 0.133179f,
+ 0.151367f, 0.169678f, 0.187988f, 0.206055f, 0.223999f, 0.241821f, 0.260742f, 0.277832f, 0.295166f, 0.313232f, 0.331299f, 0.347412f,
+ 0.365479f, 0.383057f, 0.399902f, 0.416992f, 0.433350f, 0.450195f, 0.467773f, 0.484863f, 0.499756f, 0.515625f, 0.532715f, 0.548340f,
+ 0.564941f, 0.580566f, 0.596191f, 0.610840f, 0.626953f, 0.641602f, 0.656738f, 0.671875f, 0.686035f, 0.701660f, 0.714844f, 0.730469f,
+ 0.745117f, 0.759766f, 0.772461f, 0.786621f, 0.801270f, 0.814453f, 0.827637f, 0.841309f, 0.854004f, 0.867676f, 0.880859f, 0.893555f,
+ 0.907227f, 0.919434f, 0.943359f, 0.913086f, 0.891602f, 0.874512f, 0.858887f, 0.845703f, 0.008102f, 0.024002f, 0.040802f, 0.057098f,
+ 0.074768f, 0.091553f, 0.108826f, 0.126343f, 0.143921f, 0.161377f, 0.179077f, 0.195923f, 0.213745f, 0.230835f, 0.248047f, 0.265869f,
+ 0.282227f, 0.299561f, 0.316895f, 0.334473f, 0.350586f, 0.367920f, 0.384277f, 0.400391f, 0.417725f, 0.434326f, 0.450195f, 0.467285f,
+ 0.482910f, 0.498291f, 0.514648f, 0.530762f, 0.546387f, 0.561523f, 0.577637f, 0.593262f, 0.608398f, 0.623535f, 0.637695f, 0.654297f,
+ 0.668457f, 0.682617f, 0.698242f, 0.711914f, 0.727051f, 0.741211f, 0.754395f, 0.768066f, 0.782715f, 0.796387f, 0.810547f, 0.823730f,
+ 0.836426f, 0.849609f, 0.863770f, 0.876465f, 0.889648f, 0.902344f, 0.934570f, 0.907715f, 0.887207f, 0.870117f, 0.854980f, 0.842285f,
+ 0.007504f, 0.022812f, 0.038727f, 0.054871f, 0.070312f, 0.087097f, 0.103088f, 0.119446f, 0.136475f, 0.153442f, 0.169556f, 0.186523f,
+ 0.203369f, 0.219971f, 0.236450f, 0.253418f, 0.270264f, 0.287109f, 0.302979f, 0.319824f, 0.336182f, 0.353271f, 0.369141f, 0.386230f,
+ 0.402100f, 0.417725f, 0.433594f, 0.450684f, 0.466553f, 0.482178f, 0.498047f, 0.513184f, 0.528809f, 0.543945f, 0.559082f, 0.575195f,
+ 0.589844f, 0.605469f, 0.621094f, 0.634277f, 0.649414f, 0.665039f, 0.679688f, 0.694824f, 0.708496f, 0.722168f, 0.736816f, 0.750000f,
+ 0.763184f, 0.778809f, 0.791504f, 0.805664f, 0.819336f, 0.832520f, 0.845703f, 0.858887f, 0.872070f, 0.885742f, 0.927246f, 0.900879f,
+ 0.881836f, 0.864746f, 0.851074f, 0.838867f, 0.006836f, 0.021683f, 0.036224f, 0.051666f, 0.066772f, 0.081970f, 0.098022f, 0.113831f,
+ 0.129517f, 0.145264f, 0.161011f, 0.177856f, 0.193359f, 0.209106f, 0.226196f, 0.241821f, 0.257812f, 0.274414f, 0.290283f, 0.306641f,
+ 0.322754f, 0.338623f, 0.354492f, 0.370361f, 0.386230f, 0.402100f, 0.417725f, 0.433838f, 0.449463f, 0.465088f, 0.480469f, 0.495605f,
+ 0.511719f, 0.527344f, 0.541016f, 0.556641f, 0.571777f, 0.587402f, 0.601562f, 0.617676f, 0.631836f, 0.646484f, 0.660645f, 0.674805f,
+ 0.689941f, 0.704102f, 0.718262f, 0.731934f, 0.746582f, 0.760254f, 0.774414f, 0.786621f, 0.801758f, 0.815430f, 0.828125f, 0.842285f,
+ 0.854980f, 0.868652f, 0.918457f, 0.894531f, 0.875977f, 0.859863f, 0.846680f, 0.834961f, 0.006672f, 0.020401f, 0.034088f, 0.048462f,
+ 0.062927f, 0.077820f, 0.092529f, 0.107666f, 0.122803f, 0.137695f, 0.152954f, 0.169067f, 0.183716f, 0.199829f, 0.214722f, 0.230347f,
+ 0.246704f, 0.262207f, 0.277832f, 0.292969f, 0.308105f, 0.324219f, 0.339600f, 0.354492f, 0.371094f, 0.386963f, 0.401855f, 0.418457f,
+ 0.432861f, 0.449219f, 0.463379f, 0.478271f, 0.494385f, 0.508301f, 0.523438f, 0.539551f, 0.553711f, 0.568848f, 0.583984f, 0.598633f,
+ 0.612793f, 0.627441f, 0.642578f, 0.656250f, 0.670898f, 0.685547f, 0.698730f, 0.714355f, 0.728027f, 0.742188f, 0.755859f, 0.769531f,
+ 0.783691f, 0.795898f, 0.810059f, 0.824707f, 0.838379f, 0.850586f, 0.910645f, 0.887695f, 0.870117f, 0.854980f, 0.842285f, 0.831055f,
+ 0.006207f, 0.019211f, 0.032623f, 0.046112f, 0.059662f, 0.073181f, 0.087585f, 0.102051f, 0.116577f, 0.130249f, 0.145142f, 0.159790f,
+ 0.175171f, 0.189575f, 0.205322f, 0.219238f, 0.235474f, 0.249634f, 0.265137f, 0.280029f, 0.294678f, 0.310547f, 0.325928f, 0.340820f,
+ 0.356201f, 0.371094f, 0.386230f, 0.401367f, 0.416504f, 0.431885f, 0.446533f, 0.461670f, 0.476074f, 0.492188f, 0.507324f, 0.520996f,
+ 0.535645f, 0.550781f, 0.564941f, 0.580078f, 0.594727f, 0.609863f, 0.623535f, 0.637695f, 0.652832f, 0.667480f, 0.681152f, 0.695312f,
+ 0.709473f, 0.723633f, 0.737793f, 0.751953f, 0.765137f, 0.779297f, 0.793945f, 0.807129f, 0.819824f, 0.833496f, 0.901855f, 0.880859f,
+ 0.864258f, 0.850098f, 0.837891f, 0.826660f, 0.006020f, 0.018219f, 0.030579f, 0.043365f, 0.055908f, 0.069153f, 0.082336f, 0.096802f,
+ 0.109497f, 0.123535f, 0.137451f, 0.151855f, 0.165649f, 0.180054f, 0.194702f, 0.208252f, 0.223999f, 0.238037f, 0.252930f, 0.267334f,
+ 0.281982f, 0.296875f, 0.312012f, 0.326904f, 0.340820f, 0.355957f, 0.370850f, 0.385986f, 0.400391f, 0.415039f, 0.430176f, 0.445801f,
+ 0.459229f, 0.474365f, 0.489014f, 0.502441f, 0.518066f, 0.533203f, 0.547363f, 0.562012f, 0.576660f, 0.590820f, 0.605469f, 0.619629f,
+ 0.633789f, 0.647949f, 0.663574f, 0.676758f, 0.690918f, 0.705566f, 0.719238f, 0.733398f, 0.746582f, 0.760254f, 0.774414f, 0.788574f,
+ 0.802246f, 0.816406f, 0.894043f, 0.874023f, 0.858398f, 0.844238f, 0.832031f, 0.822266f, 0.005520f, 0.017059f, 0.028625f, 0.040649f,
+ 0.053131f, 0.065552f, 0.077698f, 0.091187f, 0.104065f, 0.117371f, 0.130859f, 0.143677f, 0.157349f, 0.171021f, 0.184814f, 0.198730f,
+ 0.213135f, 0.226807f, 0.241211f, 0.255127f, 0.269775f, 0.283691f, 0.298096f, 0.312744f, 0.326660f, 0.341553f, 0.355957f, 0.370117f,
+ 0.384766f, 0.399170f, 0.414307f, 0.427979f, 0.442627f, 0.457764f, 0.471924f, 0.486084f, 0.500488f, 0.515137f, 0.529785f, 0.543945f,
+ 0.558594f, 0.572754f, 0.587402f, 0.601074f, 0.615234f, 0.629395f, 0.644043f, 0.657715f, 0.672852f, 0.685547f, 0.700684f, 0.714844f,
+ 0.728027f, 0.743164f, 0.756348f, 0.770508f, 0.785645f, 0.798340f, 0.885254f, 0.867676f, 0.852051f, 0.839355f, 0.828125f, 0.817871f,
+ 0.005241f, 0.015854f, 0.027481f, 0.038605f, 0.050171f, 0.061859f, 0.073853f, 0.085693f, 0.098328f, 0.111206f, 0.123474f, 0.136475f,
+ 0.149658f, 0.162598f, 0.175293f, 0.188477f, 0.202148f, 0.216431f, 0.229858f, 0.242798f, 0.256104f, 0.270264f, 0.284668f, 0.298828f,
+ 0.312744f, 0.326904f, 0.341064f, 0.355469f, 0.369141f, 0.383057f, 0.396729f, 0.411621f, 0.426025f, 0.439697f, 0.454590f, 0.468506f,
+ 0.482666f, 0.497070f, 0.512207f, 0.525391f, 0.540527f, 0.555176f, 0.567871f, 0.582031f, 0.596191f, 0.610840f, 0.625488f, 0.639648f,
+ 0.653809f, 0.668457f, 0.681641f, 0.695801f, 0.710449f, 0.724121f, 0.738770f, 0.751953f, 0.766602f, 0.780273f, 0.876465f, 0.860352f,
+ 0.845703f, 0.833984f, 0.822754f, 0.812988f, 0.004982f, 0.015274f, 0.025681f, 0.036438f, 0.047119f, 0.058167f, 0.069397f, 0.081055f,
+ 0.092957f, 0.104492f, 0.116577f, 0.128418f, 0.141113f, 0.153442f, 0.166504f, 0.179321f, 0.192261f, 0.205200f, 0.218506f, 0.231934f,
+ 0.244629f, 0.258301f, 0.271729f, 0.284912f, 0.299072f, 0.312988f, 0.325684f, 0.340088f, 0.353271f, 0.367676f, 0.381836f, 0.395508f,
+ 0.408936f, 0.423584f, 0.438232f, 0.451416f, 0.466309f, 0.479736f, 0.493896f, 0.507812f, 0.521973f, 0.536133f, 0.550293f, 0.563965f,
+ 0.578613f, 0.592773f, 0.606934f, 0.620605f, 0.635254f, 0.649414f, 0.663086f, 0.677246f, 0.691406f, 0.706543f, 0.720703f, 0.734375f,
+ 0.748047f, 0.762695f, 0.868164f, 0.853027f, 0.839355f, 0.828125f, 0.817383f, 0.808105f, 0.004745f, 0.014290f, 0.024506f, 0.034393f,
+ 0.044617f, 0.054749f, 0.065308f, 0.076538f, 0.087646f, 0.098938f, 0.110535f, 0.121582f, 0.134155f, 0.145264f, 0.157837f, 0.170166f,
+ 0.182373f, 0.194824f, 0.207153f, 0.220337f, 0.233276f, 0.245728f, 0.259277f, 0.271973f, 0.285645f, 0.298584f, 0.311768f, 0.325684f,
+ 0.338623f, 0.352539f, 0.365967f, 0.379395f, 0.393066f, 0.406738f, 0.421143f, 0.434326f, 0.448730f, 0.462402f, 0.475586f, 0.490479f,
+ 0.503906f, 0.518066f, 0.532227f, 0.546387f, 0.560059f, 0.574219f, 0.588379f, 0.602539f, 0.616211f, 0.630371f, 0.644531f, 0.658691f,
+ 0.673340f, 0.686523f, 0.701660f, 0.715332f, 0.730469f, 0.745117f, 0.858887f, 0.845215f, 0.833008f, 0.821777f, 0.812012f, 0.802734f,
+ 0.004494f, 0.013550f, 0.022675f, 0.032227f, 0.042145f, 0.052002f, 0.061554f, 0.072205f, 0.082520f, 0.093323f, 0.104614f, 0.115112f,
+ 0.126099f, 0.137817f, 0.149536f, 0.160767f, 0.172607f, 0.184692f, 0.196167f, 0.208862f, 0.221924f, 0.233765f, 0.246216f, 0.258545f,
+ 0.272461f, 0.284424f, 0.297119f, 0.310547f, 0.323242f, 0.336914f, 0.350586f, 0.363281f, 0.376953f, 0.390869f, 0.403564f, 0.416992f,
+ 0.431152f, 0.444824f, 0.458496f, 0.472656f, 0.486084f, 0.500000f, 0.513672f, 0.527832f, 0.541504f, 0.555664f, 0.569824f, 0.583496f,
+ 0.598145f, 0.611816f, 0.626465f, 0.639648f, 0.654297f, 0.668457f, 0.683594f, 0.697754f, 0.711914f, 0.726562f, 0.849609f, 0.838867f,
+ 0.826172f, 0.815918f, 0.806641f, 0.796875f, 0.004288f, 0.012619f, 0.021713f, 0.030945f, 0.039368f, 0.048737f, 0.058533f, 0.067932f,
+ 0.077759f, 0.088013f, 0.098755f, 0.108398f, 0.119080f, 0.129639f, 0.141235f, 0.152466f, 0.163940f, 0.174927f, 0.186768f, 0.198608f,
+ 0.210205f, 0.222290f, 0.234131f, 0.246094f, 0.258789f, 0.270508f, 0.283203f, 0.296631f, 0.309326f, 0.321777f, 0.335449f, 0.348145f,
+ 0.361084f, 0.374023f, 0.386963f, 0.400391f, 0.414062f, 0.427734f, 0.441162f, 0.455078f, 0.467773f, 0.482422f, 0.495117f, 0.509277f,
+ 0.523926f, 0.536621f, 0.550781f, 0.564941f, 0.579102f, 0.593262f, 0.607422f, 0.621582f, 0.635742f, 0.649902f, 0.664551f, 0.678711f,
+ 0.693848f, 0.708008f, 0.840820f, 0.831055f, 0.819336f, 0.809570f, 0.801270f, 0.792969f, 0.004013f, 0.012070f, 0.019989f, 0.029190f,
+ 0.037415f, 0.045776f, 0.055023f, 0.064392f, 0.073669f, 0.083374f, 0.092224f, 0.102295f, 0.112610f, 0.122742f, 0.133057f, 0.143799f,
+ 0.155273f, 0.165527f, 0.176880f, 0.188110f, 0.199463f, 0.210815f, 0.222534f, 0.234619f, 0.245972f, 0.258301f, 0.270508f, 0.282715f,
+ 0.294678f, 0.307129f, 0.320557f, 0.333008f, 0.345947f, 0.358398f, 0.371826f, 0.384277f, 0.397461f, 0.410889f, 0.424561f, 0.437256f,
+ 0.451416f, 0.464600f, 0.477783f, 0.491455f, 0.504395f, 0.518555f, 0.532715f, 0.546875f, 0.560547f, 0.574219f, 0.588379f, 0.604004f,
+ 0.617188f, 0.631348f, 0.645020f, 0.660645f, 0.674316f, 0.689941f, 0.832031f, 0.823242f, 0.813477f, 0.803711f, 0.794922f, 0.787109f,
+ 0.003790f, 0.011559f, 0.019119f, 0.027069f, 0.035034f, 0.043762f, 0.052032f, 0.060059f, 0.069153f, 0.078369f, 0.087280f, 0.096741f,
+ 0.105957f, 0.115967f, 0.125732f, 0.135620f, 0.146118f, 0.156128f, 0.166992f, 0.177612f, 0.188965f, 0.199829f, 0.210815f, 0.222290f,
+ 0.233887f, 0.244873f, 0.257324f, 0.268799f, 0.281006f, 0.292969f, 0.305420f, 0.317627f, 0.329834f, 0.341797f, 0.355469f, 0.368164f,
+ 0.380859f, 0.393311f, 0.407227f, 0.419434f, 0.433350f, 0.446533f, 0.459961f, 0.473633f, 0.486328f, 0.500488f, 0.515625f, 0.528320f,
+ 0.541504f, 0.556152f, 0.570312f, 0.584473f, 0.598633f, 0.612305f, 0.626465f, 0.640625f, 0.655762f, 0.670410f, 0.822266f, 0.815918f,
+ 0.805664f, 0.796387f, 0.788574f, 0.782227f, 0.003599f, 0.010727f, 0.018219f, 0.025177f, 0.033203f, 0.041046f, 0.048981f, 0.057220f,
+ 0.065247f, 0.073792f, 0.082764f, 0.091064f, 0.100220f, 0.108826f, 0.118591f, 0.128052f, 0.137573f, 0.147705f, 0.158081f, 0.167603f,
+ 0.177979f, 0.188721f, 0.198975f, 0.210205f, 0.221924f, 0.232544f, 0.243774f, 0.255615f, 0.267090f, 0.278564f, 0.290039f, 0.302490f,
+ 0.314941f, 0.327393f, 0.338623f, 0.352295f, 0.364014f, 0.377441f, 0.390381f, 0.403564f, 0.415039f, 0.428955f, 0.441895f, 0.455078f,
+ 0.468994f, 0.482666f, 0.496094f, 0.509277f, 0.523926f, 0.537598f, 0.551270f, 0.565430f, 0.579590f, 0.594238f, 0.608887f, 0.622559f,
+ 0.637207f, 0.651855f, 0.813477f, 0.807617f, 0.798340f, 0.790527f, 0.782715f, 0.775391f, 0.003355f, 0.009918f, 0.017105f, 0.023911f,
+ 0.031281f, 0.038147f, 0.045990f, 0.053284f, 0.061493f, 0.069214f, 0.077026f, 0.085571f, 0.093567f, 0.102600f, 0.111755f, 0.120728f,
+ 0.129761f, 0.138916f, 0.148804f, 0.158447f, 0.167725f, 0.177979f, 0.188965f, 0.198608f, 0.209473f, 0.220215f, 0.231567f, 0.242554f,
+ 0.253906f, 0.264160f, 0.276123f, 0.287109f, 0.300049f, 0.312012f, 0.323975f, 0.336182f, 0.348145f, 0.360840f, 0.372803f, 0.385986f,
+ 0.398438f, 0.411621f, 0.424316f, 0.437256f, 0.450439f, 0.464844f, 0.478027f, 0.490723f, 0.504395f, 0.518066f, 0.532715f, 0.546387f,
+ 0.561523f, 0.575684f, 0.589355f, 0.604004f, 0.618164f, 0.632324f, 0.802246f, 0.800293f, 0.792480f, 0.783691f, 0.776367f, 0.769531f,
+ 0.003265f, 0.009575f, 0.016144f, 0.022415f, 0.029510f, 0.036316f, 0.042755f, 0.050812f, 0.057556f, 0.065002f, 0.072388f, 0.080200f,
+ 0.087952f, 0.096680f, 0.104858f, 0.113281f, 0.122070f, 0.130493f, 0.139771f, 0.148926f, 0.158447f, 0.168335f, 0.177612f, 0.187500f,
+ 0.198120f, 0.208130f, 0.218750f, 0.229492f, 0.240234f, 0.250732f, 0.262207f, 0.273682f, 0.285156f, 0.296143f, 0.308594f, 0.320068f,
+ 0.332520f, 0.344482f, 0.357178f, 0.368652f, 0.381836f, 0.394043f, 0.406494f, 0.420410f, 0.433105f, 0.445801f, 0.459717f, 0.473633f,
+ 0.486816f, 0.500000f, 0.513672f, 0.527832f, 0.541992f, 0.556152f, 0.570312f, 0.585449f, 0.598633f, 0.613770f, 0.794434f, 0.791504f,
+ 0.784180f, 0.776855f, 0.770020f, 0.764160f, 0.002954f, 0.008904f, 0.014961f, 0.021210f, 0.027420f, 0.033905f, 0.040619f, 0.047363f,
+ 0.053986f, 0.060883f, 0.068054f, 0.075378f, 0.082703f, 0.090515f, 0.098022f, 0.105896f, 0.114319f, 0.122742f, 0.131592f, 0.139771f,
+ 0.149170f, 0.157959f, 0.167480f, 0.177124f, 0.186768f, 0.196411f, 0.206543f, 0.216919f, 0.227539f, 0.237671f, 0.248413f, 0.259277f,
+ 0.270264f, 0.281738f, 0.292725f, 0.304443f, 0.315918f, 0.327637f, 0.340576f, 0.352539f, 0.364746f, 0.377930f, 0.390137f, 0.401855f,
+ 0.415039f, 0.428223f, 0.441406f, 0.454834f, 0.468506f, 0.481689f, 0.494873f, 0.509277f, 0.523438f, 0.537598f, 0.551758f, 0.565918f,
+ 0.580078f, 0.594727f, 0.783691f, 0.783203f, 0.776855f, 0.770508f, 0.763672f, 0.757324f, 0.002836f, 0.008659f, 0.014351f, 0.019913f,
+ 0.025772f, 0.032074f, 0.037933f, 0.044128f, 0.050903f, 0.057159f, 0.064026f, 0.070496f, 0.077698f, 0.085022f, 0.091919f, 0.099426f,
+ 0.107727f, 0.114990f, 0.123169f, 0.131226f, 0.140015f, 0.148682f, 0.157349f, 0.166260f, 0.175171f, 0.184692f, 0.194214f, 0.203979f,
+ 0.214355f, 0.224487f, 0.234985f, 0.245728f, 0.256104f, 0.267334f, 0.278320f, 0.288818f, 0.301025f, 0.312256f, 0.324219f, 0.335938f,
+ 0.347900f, 0.360596f, 0.372070f, 0.384521f, 0.397217f, 0.410400f, 0.423340f, 0.436279f, 0.449463f, 0.463135f, 0.476807f, 0.490723f,
+ 0.503906f, 0.517578f, 0.532227f, 0.546875f, 0.561035f, 0.575684f, 0.773926f, 0.775391f, 0.769043f, 0.763672f, 0.757812f, 0.751953f,
+ 0.002506f, 0.008080f, 0.013100f, 0.018738f, 0.024384f, 0.029953f, 0.035797f, 0.041473f, 0.047485f, 0.053558f, 0.059265f, 0.065918f,
+ 0.072693f, 0.079468f, 0.086426f, 0.093384f, 0.100708f, 0.108032f, 0.115417f, 0.122986f, 0.130615f, 0.139038f, 0.147827f, 0.156494f,
+ 0.165039f, 0.173828f, 0.182617f, 0.192139f, 0.201782f, 0.211426f, 0.221558f, 0.231323f, 0.242188f, 0.252686f, 0.263672f, 0.274414f,
+ 0.284912f, 0.296143f, 0.308105f, 0.319824f, 0.331543f, 0.343750f, 0.355225f, 0.367432f, 0.379883f, 0.393066f, 0.405273f, 0.418457f,
+ 0.431641f, 0.444580f, 0.457764f, 0.471924f, 0.485840f, 0.499268f, 0.512695f, 0.527344f, 0.542480f, 0.556641f, 0.764160f, 0.766602f,
+ 0.761719f, 0.756348f, 0.750488f, 0.745605f, 0.002640f, 0.007809f, 0.012497f, 0.017593f, 0.023102f, 0.028122f, 0.033569f, 0.038879f,
+ 0.044250f, 0.049988f, 0.055908f, 0.061615f, 0.067627f, 0.074036f, 0.080566f, 0.087524f, 0.093262f, 0.100769f, 0.107910f, 0.114929f,
+ 0.121948f, 0.130371f, 0.137939f, 0.146362f, 0.154297f, 0.163208f, 0.171509f, 0.180664f, 0.189697f, 0.199341f, 0.208618f, 0.218506f,
+ 0.228394f, 0.238892f, 0.248779f, 0.259277f, 0.270752f, 0.281250f, 0.292236f, 0.303467f, 0.315186f, 0.326660f, 0.338867f, 0.351074f,
+ 0.362305f, 0.374756f, 0.387939f, 0.400146f, 0.413330f, 0.426514f, 0.439209f, 0.452881f, 0.466553f, 0.480225f, 0.494141f, 0.508301f,
+ 0.522949f, 0.537109f, 0.753906f, 0.758301f, 0.754395f, 0.749023f, 0.743652f, 0.739258f, 0.002441f, 0.007088f, 0.011993f, 0.016266f,
+ 0.021255f, 0.026031f, 0.031189f, 0.036072f, 0.041260f, 0.046753f, 0.052155f, 0.057587f, 0.063232f, 0.068787f, 0.075623f, 0.081055f,
+ 0.087341f, 0.094177f, 0.100647f, 0.106689f, 0.113892f, 0.121399f, 0.129028f, 0.136841f, 0.144287f, 0.152222f, 0.160522f, 0.169312f,
+ 0.178101f, 0.186523f, 0.196045f, 0.205200f, 0.214966f, 0.224487f, 0.234863f, 0.244751f, 0.255371f, 0.265625f, 0.276367f, 0.287842f,
+ 0.298828f, 0.310303f, 0.321533f, 0.333984f, 0.345459f, 0.357666f, 0.370117f, 0.382568f, 0.394287f, 0.407959f, 0.421875f, 0.433838f,
+ 0.446777f, 0.461426f, 0.475098f, 0.488525f, 0.504395f, 0.517578f, 0.744141f, 0.749512f, 0.746094f, 0.741699f, 0.736816f, 0.732422f,
+ 0.002172f, 0.006695f, 0.011093f, 0.015266f, 0.020081f, 0.024521f, 0.029388f, 0.033966f, 0.038727f, 0.043427f, 0.048706f, 0.053772f,
+ 0.059418f, 0.064270f, 0.069580f, 0.075500f, 0.081421f, 0.087280f, 0.093262f, 0.099670f, 0.106567f, 0.113220f, 0.119995f, 0.127197f,
+ 0.134644f, 0.142212f, 0.150146f, 0.157959f, 0.166382f, 0.174927f, 0.184082f, 0.192505f, 0.201904f, 0.211792f, 0.220825f, 0.230713f,
+ 0.240601f, 0.251221f, 0.261719f, 0.272461f, 0.282715f, 0.294434f, 0.305420f, 0.316650f, 0.328369f, 0.340088f, 0.352783f, 0.364746f,
+ 0.377197f, 0.389648f, 0.402832f, 0.416016f, 0.429443f, 0.442627f, 0.456055f, 0.469971f, 0.484863f, 0.499268f, 0.733887f, 0.741211f,
+ 0.737793f, 0.734375f, 0.729980f, 0.725586f, 0.002045f, 0.006187f, 0.010406f, 0.014664f, 0.018570f, 0.022675f, 0.027176f, 0.031586f,
+ 0.035858f, 0.040253f, 0.045227f, 0.049774f, 0.054504f, 0.059692f, 0.065186f, 0.070374f, 0.075500f, 0.080627f, 0.086792f, 0.092285f,
+ 0.098999f, 0.104675f, 0.111816f, 0.118286f, 0.125610f, 0.132324f, 0.139771f, 0.147339f, 0.155029f, 0.163696f, 0.171631f, 0.180420f,
+ 0.189087f, 0.197754f, 0.207275f, 0.216309f, 0.226440f, 0.236694f, 0.246338f, 0.256836f, 0.267334f, 0.278320f, 0.289062f, 0.300537f,
+ 0.312012f, 0.323975f, 0.335449f, 0.347168f, 0.359375f, 0.372314f, 0.384521f, 0.396973f, 0.410400f, 0.423584f, 0.437500f, 0.450928f,
+ 0.465332f, 0.479736f, 0.723145f, 0.732422f, 0.729980f, 0.726562f, 0.722656f, 0.718750f, 0.002148f, 0.005802f, 0.009811f, 0.013565f,
+ 0.017578f, 0.021179f, 0.025040f, 0.029053f, 0.033417f, 0.037445f, 0.042114f, 0.046112f, 0.050720f, 0.055511f, 0.060028f, 0.065002f,
+ 0.069458f, 0.075134f, 0.080078f, 0.085693f, 0.091492f, 0.097290f, 0.103394f, 0.109802f, 0.116089f, 0.122925f, 0.129883f, 0.136963f,
+ 0.144165f, 0.151733f, 0.160156f, 0.167847f, 0.176392f, 0.184692f, 0.193848f, 0.203003f, 0.212402f, 0.221680f, 0.231689f, 0.242065f,
+ 0.251953f, 0.262207f, 0.273193f, 0.283936f, 0.295410f, 0.306152f, 0.318359f, 0.329590f, 0.342285f, 0.354248f, 0.366455f, 0.379150f,
+ 0.391846f, 0.405273f, 0.418701f, 0.432617f, 0.446289f, 0.460205f, 0.712891f, 0.723633f, 0.722168f, 0.718750f, 0.715332f, 0.712402f,
+ 0.001963f, 0.005642f, 0.009071f, 0.012756f, 0.016006f, 0.020020f, 0.023422f, 0.027679f, 0.030762f, 0.034943f, 0.038605f, 0.042969f,
+ 0.047028f, 0.051178f, 0.055542f, 0.060120f, 0.064575f, 0.069153f, 0.074280f, 0.079041f, 0.084595f, 0.089905f, 0.095276f, 0.101440f,
+ 0.107300f, 0.113586f, 0.119751f, 0.127075f, 0.134033f, 0.141357f, 0.148438f, 0.155884f, 0.164062f, 0.172729f, 0.180542f, 0.190063f,
+ 0.198364f, 0.207764f, 0.217163f, 0.226807f, 0.236938f, 0.247070f, 0.257324f, 0.268066f, 0.278320f, 0.289795f, 0.301025f, 0.312744f,
+ 0.324707f, 0.336182f, 0.347900f, 0.360840f, 0.372803f, 0.386230f, 0.399902f, 0.413574f, 0.427246f, 0.441162f, 0.702148f, 0.714355f,
+ 0.713867f, 0.711426f, 0.707520f, 0.704590f, 0.001995f, 0.005245f, 0.008553f, 0.011543f, 0.015015f, 0.018326f, 0.021881f, 0.025131f,
+ 0.028641f, 0.032349f, 0.035675f, 0.039520f, 0.043549f, 0.047089f, 0.051086f, 0.054962f, 0.059265f, 0.063782f, 0.068054f, 0.072571f,
+ 0.077759f, 0.082520f, 0.088013f, 0.093323f, 0.098755f, 0.104858f, 0.111145f, 0.117371f, 0.123840f, 0.130615f, 0.137207f, 0.144897f,
+ 0.152344f, 0.160278f, 0.167969f, 0.176514f, 0.185425f, 0.193848f, 0.202881f, 0.212524f, 0.221924f, 0.231323f, 0.241821f, 0.251953f,
+ 0.262451f, 0.272949f, 0.284424f, 0.295166f, 0.306396f, 0.319092f, 0.329590f, 0.343018f, 0.355225f, 0.368652f, 0.381348f, 0.393799f,
+ 0.408447f, 0.422852f, 0.691406f, 0.706055f, 0.706055f, 0.703125f, 0.700684f, 0.697754f, 0.001692f, 0.004898f, 0.007828f, 0.011070f,
+ 0.013992f, 0.017227f, 0.020187f, 0.023499f, 0.026520f, 0.029526f, 0.033081f, 0.036377f, 0.039459f, 0.043396f, 0.047028f, 0.050323f,
+ 0.054199f, 0.058350f, 0.062317f, 0.066711f, 0.071106f, 0.075928f, 0.080750f, 0.085510f, 0.090820f, 0.096497f, 0.102234f, 0.107727f,
+ 0.114075f, 0.120300f, 0.126587f, 0.133789f, 0.141113f, 0.148193f, 0.156006f, 0.163696f, 0.171753f, 0.180542f, 0.188965f, 0.198120f,
+ 0.207275f, 0.216797f, 0.226318f, 0.236206f, 0.246338f, 0.256836f, 0.267334f, 0.278809f, 0.289795f, 0.300781f, 0.313232f, 0.324707f,
+ 0.337402f, 0.349365f, 0.362305f, 0.376221f, 0.389404f, 0.403809f, 0.680176f, 0.696289f, 0.697266f, 0.695312f, 0.692871f, 0.689941f,
+ 0.001606f, 0.004543f, 0.007450f, 0.010269f, 0.012962f, 0.015900f, 0.018677f, 0.021591f, 0.024628f, 0.027618f, 0.030182f, 0.033783f,
+ 0.036194f, 0.039734f, 0.042725f, 0.046478f, 0.049652f, 0.053253f, 0.057251f, 0.060883f, 0.065186f, 0.069336f, 0.073730f, 0.078247f,
+ 0.083252f, 0.088501f, 0.093628f, 0.099182f, 0.104553f, 0.110718f, 0.116577f, 0.123108f, 0.129883f, 0.136719f, 0.143921f, 0.151367f,
+ 0.159302f, 0.167114f, 0.175415f, 0.183960f, 0.192871f, 0.202148f, 0.210938f, 0.221436f, 0.230713f, 0.240723f, 0.250977f, 0.261963f,
+ 0.272461f, 0.283691f, 0.295166f, 0.306885f, 0.319092f, 0.331055f, 0.343750f, 0.356689f, 0.370361f, 0.383545f, 0.669434f, 0.687500f,
+ 0.688965f, 0.687500f, 0.685547f, 0.682617f, 0.001701f, 0.004345f, 0.006802f, 0.009514f, 0.012283f, 0.014793f, 0.017288f, 0.019958f,
+ 0.022614f, 0.025177f, 0.027695f, 0.030487f, 0.033081f, 0.035858f, 0.039185f, 0.042236f, 0.045319f, 0.048523f, 0.051941f, 0.055847f,
+ 0.059326f, 0.063171f, 0.067139f, 0.071594f, 0.075928f, 0.080566f, 0.085571f, 0.090454f, 0.095520f, 0.101196f, 0.106567f, 0.112427f,
+ 0.119019f, 0.125610f, 0.132324f, 0.139282f, 0.146973f, 0.154419f, 0.161987f, 0.170532f, 0.178833f, 0.187134f, 0.196777f, 0.206177f,
+ 0.214966f, 0.225220f, 0.235352f, 0.246094f, 0.255615f, 0.266846f, 0.278320f, 0.290039f, 0.301270f, 0.313477f, 0.325195f, 0.338867f,
+ 0.352539f, 0.365234f, 0.657715f, 0.678711f, 0.679688f, 0.679199f, 0.677734f, 0.675293f, 0.001310f, 0.003979f, 0.006393f, 0.008522f,
+ 0.011223f, 0.013557f, 0.015976f, 0.018433f, 0.020737f, 0.022842f, 0.025421f, 0.027649f, 0.030289f, 0.032806f, 0.035645f, 0.038025f,
+ 0.041199f, 0.044220f, 0.047058f, 0.050720f, 0.053589f, 0.057281f, 0.061157f, 0.064941f, 0.068787f, 0.072998f, 0.077698f, 0.082153f,
+ 0.086975f, 0.092102f, 0.097229f, 0.103027f, 0.108826f, 0.114746f, 0.121094f, 0.127930f, 0.134521f, 0.141846f, 0.149292f, 0.157227f,
+ 0.164673f, 0.173218f, 0.182007f, 0.190552f, 0.199951f, 0.209717f, 0.219360f, 0.229004f, 0.239502f, 0.250244f, 0.260986f, 0.272461f,
+ 0.282959f, 0.295166f, 0.307373f, 0.320557f, 0.333252f, 0.346436f, 0.646973f, 0.668945f, 0.670898f, 0.671387f, 0.669922f, 0.668457f,
+ 0.001348f, 0.003523f, 0.005863f, 0.008133f, 0.010338f, 0.012520f, 0.014511f, 0.016464f, 0.018768f, 0.020920f, 0.022888f, 0.025665f,
+ 0.027588f, 0.029861f, 0.032135f, 0.034485f, 0.037140f, 0.040039f, 0.042725f, 0.045532f, 0.048859f, 0.051971f, 0.055237f, 0.058594f,
+ 0.062408f, 0.066101f, 0.070251f, 0.074280f, 0.078735f, 0.083435f, 0.088318f, 0.093567f, 0.098633f, 0.104431f, 0.110291f, 0.116455f,
+ 0.122986f, 0.129517f, 0.136963f, 0.143921f, 0.152222f, 0.159546f, 0.167358f, 0.176514f, 0.185181f, 0.194214f, 0.203857f, 0.213623f,
+ 0.223389f, 0.233521f, 0.244385f, 0.255127f, 0.266602f, 0.277832f, 0.289307f, 0.301758f, 0.314697f, 0.328613f, 0.635254f, 0.659668f,
+ 0.663086f, 0.663086f, 0.662109f, 0.660156f, 0.001084f, 0.003263f, 0.005554f, 0.007416f, 0.009445f, 0.011185f, 0.013161f, 0.015366f,
+ 0.017136f, 0.019058f, 0.020935f, 0.022781f, 0.024857f, 0.026886f, 0.029160f, 0.031097f, 0.033569f, 0.035858f, 0.038361f, 0.040924f,
+ 0.043427f, 0.046478f, 0.049500f, 0.052948f, 0.056122f, 0.059418f, 0.063293f, 0.067139f, 0.070923f, 0.075073f, 0.079712f, 0.084229f,
+ 0.089233f, 0.094604f, 0.100037f, 0.105774f, 0.111694f, 0.117798f, 0.124634f, 0.131226f, 0.139038f, 0.146484f, 0.154175f, 0.162231f,
+ 0.170654f, 0.179199f, 0.188599f, 0.197754f, 0.207153f, 0.217407f, 0.227295f, 0.238159f, 0.248657f, 0.260986f, 0.271973f, 0.284912f,
+ 0.296631f, 0.308838f, 0.623535f, 0.650391f, 0.653809f, 0.654297f, 0.653809f, 0.652832f, 0.001070f, 0.003069f, 0.005108f, 0.006855f,
+ 0.008522f, 0.010384f, 0.011993f, 0.013847f, 0.015549f, 0.016968f, 0.018677f, 0.020660f, 0.022079f, 0.024048f, 0.026077f, 0.027954f,
+ 0.030014f, 0.032135f, 0.034210f, 0.036560f, 0.038971f, 0.041840f, 0.044434f, 0.047089f, 0.049896f, 0.053284f, 0.056763f, 0.060120f,
+ 0.063477f, 0.067505f, 0.071533f, 0.075928f, 0.080261f, 0.085205f, 0.089905f, 0.095520f, 0.100830f, 0.106567f, 0.113159f, 0.119385f,
+ 0.126221f, 0.133301f, 0.140259f, 0.148560f, 0.156494f, 0.165039f, 0.173462f, 0.182861f, 0.192017f, 0.201172f, 0.211548f, 0.221802f,
+ 0.232666f, 0.243286f, 0.254639f, 0.265869f, 0.278809f, 0.291260f, 0.611816f, 0.640625f, 0.645508f, 0.645996f, 0.645508f, 0.645020f,
+ 0.001057f, 0.002815f, 0.004646f, 0.006187f, 0.007935f, 0.009583f, 0.011139f, 0.012428f, 0.013878f, 0.015404f, 0.016830f, 0.018433f,
+ 0.019836f, 0.021637f, 0.023300f, 0.024857f, 0.026855f, 0.028519f, 0.030533f, 0.032593f, 0.034790f, 0.037140f, 0.039520f, 0.041748f,
+ 0.044525f, 0.047302f, 0.050232f, 0.053497f, 0.056580f, 0.059998f, 0.063721f, 0.067627f, 0.071777f, 0.076111f, 0.080627f, 0.085571f,
+ 0.090698f, 0.096130f, 0.101624f, 0.107849f, 0.114258f, 0.120544f, 0.127686f, 0.135132f, 0.142700f, 0.150269f, 0.158813f, 0.167725f,
+ 0.176392f, 0.185791f, 0.195312f, 0.205444f, 0.216064f, 0.226562f, 0.237793f, 0.248657f, 0.260254f, 0.272949f, 0.600098f, 0.631348f,
+ 0.636230f, 0.637207f, 0.637695f, 0.636719f, 0.001022f, 0.002628f, 0.004486f, 0.005684f, 0.007179f, 0.008636f, 0.009911f, 0.011307f,
+ 0.012428f, 0.013771f, 0.015152f, 0.016342f, 0.017822f, 0.018997f, 0.020584f, 0.022263f, 0.023651f, 0.025482f, 0.027191f, 0.028793f,
+ 0.030960f, 0.032715f, 0.034912f, 0.036987f, 0.039368f, 0.041840f, 0.044495f, 0.047180f, 0.050110f, 0.053314f, 0.056580f, 0.060059f,
+ 0.063660f, 0.067383f, 0.071777f, 0.075928f, 0.081055f, 0.085938f, 0.091187f, 0.096619f, 0.102356f, 0.108826f, 0.115051f, 0.121948f,
+ 0.129150f, 0.136475f, 0.144653f, 0.152832f, 0.161621f, 0.170288f, 0.179932f, 0.189209f, 0.198730f, 0.209595f, 0.220459f, 0.231201f,
+ 0.242798f, 0.255615f, 0.588867f, 0.621094f, 0.626953f, 0.629883f, 0.629395f, 0.629883f, 0.001016f, 0.002304f, 0.003975f, 0.005024f,
+ 0.006584f, 0.007812f, 0.008926f, 0.009987f, 0.011024f, 0.012199f, 0.013321f, 0.014595f, 0.015617f, 0.016830f, 0.018326f, 0.019577f,
+ 0.020798f, 0.022293f, 0.023758f, 0.025253f, 0.027145f, 0.028656f, 0.030640f, 0.032501f, 0.034546f, 0.036682f, 0.039001f, 0.041412f,
+ 0.044037f, 0.046875f, 0.049622f, 0.052917f, 0.056030f, 0.059387f, 0.063354f, 0.067383f, 0.071655f, 0.075928f, 0.080750f, 0.085876f,
+ 0.091248f, 0.097168f, 0.102905f, 0.109497f, 0.116272f, 0.123413f, 0.130859f, 0.138550f, 0.147217f, 0.155518f, 0.164551f, 0.173828f,
+ 0.183350f, 0.193481f, 0.204102f, 0.214600f, 0.225342f, 0.237915f, 0.575684f, 0.611816f, 0.617188f, 0.621094f, 0.621582f, 0.620605f,
+ 0.000768f, 0.002398f, 0.003801f, 0.004875f, 0.005848f, 0.006889f, 0.008072f, 0.008820f, 0.009758f, 0.010910f, 0.011810f, 0.013023f,
+ 0.013878f, 0.014786f, 0.016083f, 0.017166f, 0.018402f, 0.019577f, 0.020691f, 0.022125f, 0.023743f, 0.025009f, 0.026779f, 0.028336f,
+ 0.030075f, 0.031921f, 0.033997f, 0.036255f, 0.038452f, 0.040833f, 0.043488f, 0.045959f, 0.049011f, 0.052216f, 0.055634f, 0.059052f,
+ 0.062744f, 0.066956f, 0.071289f, 0.075745f, 0.080566f, 0.086060f, 0.091614f, 0.097351f, 0.103821f, 0.110291f, 0.117432f, 0.124939f,
+ 0.132568f, 0.140869f, 0.149414f, 0.158325f, 0.168213f, 0.177368f, 0.187744f, 0.197876f, 0.208984f, 0.219849f, 0.563965f, 0.602051f,
+ 0.608887f, 0.610840f, 0.613770f, 0.612305f, 0.000764f, 0.002028f, 0.003302f, 0.004276f, 0.005325f, 0.006035f, 0.007034f, 0.007843f,
+ 0.008904f, 0.009628f, 0.010323f, 0.011192f, 0.012039f, 0.013092f, 0.013924f, 0.014854f, 0.015793f, 0.016953f, 0.018036f, 0.019211f,
+ 0.020355f, 0.021667f, 0.023010f, 0.024582f, 0.026016f, 0.027771f, 0.029434f, 0.031235f, 0.033264f, 0.035217f, 0.037628f, 0.039886f,
+ 0.042084f, 0.044952f, 0.048126f, 0.051392f, 0.054779f, 0.058197f, 0.062164f, 0.066223f, 0.070740f, 0.075439f, 0.080566f, 0.086182f,
+ 0.091919f, 0.098145f, 0.104431f, 0.111633f, 0.119080f, 0.126587f, 0.134888f, 0.143311f, 0.152710f, 0.162109f, 0.171631f, 0.182129f,
+ 0.192139f, 0.203491f, 0.552246f, 0.591309f, 0.599609f, 0.602539f, 0.604004f, 0.604980f, 0.000782f, 0.001970f, 0.003082f, 0.003859f,
+ 0.004635f, 0.005611f, 0.006123f, 0.006767f, 0.007595f, 0.008270f, 0.009140f, 0.009674f, 0.010490f, 0.011040f, 0.011902f, 0.012749f,
+ 0.013573f, 0.014526f, 0.015656f, 0.016541f, 0.017548f, 0.018631f, 0.019730f, 0.021103f, 0.022446f, 0.023758f, 0.025162f, 0.026611f,
+ 0.028458f, 0.030441f, 0.032074f, 0.034302f, 0.036316f, 0.038727f, 0.041138f, 0.044098f, 0.046997f, 0.050232f, 0.053711f, 0.057281f,
+ 0.061340f, 0.065491f, 0.070435f, 0.075256f, 0.080688f, 0.086426f, 0.092346f, 0.098694f, 0.105896f, 0.113098f, 0.120911f, 0.129028f,
+ 0.137695f, 0.146606f, 0.155884f, 0.165894f, 0.175903f, 0.186768f, 0.540527f, 0.582520f, 0.590332f, 0.593750f, 0.594727f, 0.596191f,
+ 0.000711f, 0.001649f, 0.002529f, 0.003332f, 0.004036f, 0.004799f, 0.005444f, 0.006050f, 0.006638f, 0.007160f, 0.007771f, 0.008331f,
+ 0.008980f, 0.009644f, 0.010307f, 0.010887f, 0.011787f, 0.012306f, 0.013176f, 0.014099f, 0.014915f, 0.015839f, 0.016708f, 0.017822f,
+ 0.019073f, 0.020233f, 0.021423f, 0.022690f, 0.024033f, 0.025589f, 0.027344f, 0.028976f, 0.030930f, 0.032990f, 0.035156f, 0.037445f,
+ 0.040131f, 0.042847f, 0.045776f, 0.049042f, 0.052551f, 0.056519f, 0.060486f, 0.064941f, 0.069458f, 0.074951f, 0.080444f, 0.086487f,
+ 0.092957f, 0.099915f, 0.107361f, 0.114929f, 0.123535f, 0.131714f, 0.140747f, 0.150513f, 0.160767f, 0.171265f, 0.527832f, 0.572754f,
+ 0.581543f, 0.583496f, 0.586426f, 0.587402f, 0.000504f, 0.001575f, 0.002235f, 0.003147f, 0.003641f, 0.004150f, 0.004570f, 0.005173f,
+ 0.005863f, 0.006016f, 0.006462f, 0.007111f, 0.007660f, 0.008156f, 0.008736f, 0.009354f, 0.010094f, 0.010475f, 0.011253f, 0.011879f,
+ 0.012657f, 0.013603f, 0.014267f, 0.015099f, 0.016144f, 0.017014f, 0.017990f, 0.019104f, 0.020416f, 0.021652f, 0.022919f, 0.024353f,
+ 0.025986f, 0.027710f, 0.029602f, 0.031494f, 0.033722f, 0.036102f, 0.038635f, 0.041412f, 0.044525f, 0.047729f, 0.051636f, 0.055511f,
+ 0.059540f, 0.064331f, 0.069580f, 0.075073f, 0.080750f, 0.087341f, 0.094116f, 0.101379f, 0.109558f, 0.117676f, 0.126221f, 0.135376f,
+ 0.145874f, 0.155518f, 0.516113f, 0.562012f, 0.571777f, 0.576172f, 0.578125f, 0.579102f, 0.000445f, 0.001304f, 0.002201f, 0.002535f,
+ 0.003126f, 0.003664f, 0.004047f, 0.004463f, 0.004887f, 0.005234f, 0.005711f, 0.005997f, 0.006500f, 0.006901f, 0.007389f, 0.007904f,
+ 0.008293f, 0.008919f, 0.009499f, 0.009941f, 0.010635f, 0.011269f, 0.011948f, 0.012589f, 0.013435f, 0.014252f, 0.015091f, 0.016052f,
+ 0.017059f, 0.017960f, 0.019241f, 0.020264f, 0.021667f, 0.022995f, 0.024628f, 0.026230f, 0.027985f, 0.029984f, 0.032288f, 0.034515f,
+ 0.037140f, 0.040009f, 0.043152f, 0.046722f, 0.050354f, 0.054504f, 0.059143f, 0.064026f, 0.069458f, 0.075256f, 0.081726f, 0.088562f,
+ 0.095825f, 0.103516f, 0.112000f, 0.120850f, 0.130005f, 0.140381f, 0.502441f, 0.551758f, 0.562012f, 0.566406f, 0.568848f, 0.571289f,
+ 0.000396f, 0.001226f, 0.001812f, 0.002357f, 0.002796f, 0.003094f, 0.003328f, 0.003763f, 0.003979f, 0.004364f, 0.004642f, 0.005051f,
+ 0.005489f, 0.005745f, 0.006126f, 0.006611f, 0.007004f, 0.007473f, 0.007771f, 0.008293f, 0.008919f, 0.009392f, 0.009941f, 0.010483f,
+ 0.011169f, 0.011765f, 0.012436f, 0.013344f, 0.014030f, 0.014908f, 0.015778f, 0.016769f, 0.017838f, 0.018997f, 0.020279f, 0.021622f,
+ 0.023056f, 0.024704f, 0.026474f, 0.028580f, 0.030579f, 0.033051f, 0.035706f, 0.038605f, 0.041840f, 0.045380f, 0.049500f, 0.053986f,
+ 0.058685f, 0.063843f, 0.069885f, 0.076050f, 0.083191f, 0.090576f, 0.098511f, 0.107056f, 0.115479f, 0.125122f, 0.491211f, 0.541504f,
+ 0.552734f, 0.557617f, 0.560547f, 0.562012f, 0.000559f, 0.001152f, 0.001668f, 0.001955f, 0.002234f, 0.002550f, 0.002821f, 0.003057f,
+ 0.003296f, 0.003635f, 0.003948f, 0.004189f, 0.004448f, 0.004761f, 0.005077f, 0.005417f, 0.005699f, 0.006142f, 0.006458f, 0.006844f,
+ 0.007271f, 0.007717f, 0.008156f, 0.008675f, 0.009132f, 0.009590f, 0.010277f, 0.010864f, 0.011482f, 0.012131f, 0.012901f, 0.013741f,
+ 0.014595f, 0.015549f, 0.016525f, 0.017563f, 0.018799f, 0.020111f, 0.021484f, 0.023087f, 0.024765f, 0.026840f, 0.028992f, 0.031403f,
+ 0.034119f, 0.037323f, 0.040680f, 0.044464f, 0.048584f, 0.053345f, 0.058838f, 0.064514f, 0.071045f, 0.078247f, 0.085571f, 0.093567f,
+ 0.101685f, 0.111023f, 0.477539f, 0.531738f, 0.542969f, 0.548340f, 0.552246f, 0.553711f, 0.000459f, 0.000939f, 0.001184f, 0.001600f,
+ 0.001761f, 0.002144f, 0.002258f, 0.002546f, 0.002708f, 0.002922f, 0.003157f, 0.003414f, 0.003588f, 0.003918f, 0.004154f, 0.004387f,
+ 0.004662f, 0.004993f, 0.005249f, 0.005566f, 0.005867f, 0.006252f, 0.006573f, 0.007061f, 0.007408f, 0.007858f, 0.008270f, 0.008713f,
+ 0.009361f, 0.009911f, 0.010513f, 0.011047f, 0.011841f, 0.012566f, 0.013252f, 0.014175f, 0.015182f, 0.016220f, 0.017258f, 0.018524f,
+ 0.019882f, 0.021454f, 0.023132f, 0.025146f, 0.027405f, 0.029877f, 0.032745f, 0.035919f, 0.039642f, 0.043823f, 0.048492f, 0.053619f,
+ 0.059235f, 0.065735f, 0.072693f, 0.080383f, 0.088867f, 0.097412f, 0.466309f, 0.520508f, 0.533691f, 0.539062f, 0.542480f, 0.543945f,
+ 0.000369f, 0.000915f, 0.001124f, 0.001297f, 0.001534f, 0.001741f, 0.001833f, 0.002111f, 0.002272f, 0.002369f, 0.002516f, 0.002766f,
+ 0.002920f, 0.003162f, 0.003317f, 0.003551f, 0.003723f, 0.003941f, 0.004211f, 0.004425f, 0.004757f, 0.004993f, 0.005306f, 0.005581f,
+ 0.005859f, 0.006203f, 0.006592f, 0.007015f, 0.007450f, 0.007828f, 0.008377f, 0.008797f, 0.009361f, 0.009895f, 0.010582f, 0.011322f,
+ 0.012016f, 0.012772f, 0.013687f, 0.014748f, 0.015778f, 0.016907f, 0.018326f, 0.019821f, 0.021622f, 0.023483f, 0.025742f, 0.028473f,
+ 0.031525f, 0.034943f, 0.038910f, 0.043457f, 0.048645f, 0.054749f, 0.061279f, 0.068420f, 0.076111f, 0.084778f, 0.453613f, 0.510742f,
+ 0.523926f, 0.529785f, 0.533203f, 0.536133f, 0.000186f, 0.000582f, 0.000925f, 0.001026f, 0.001228f, 0.001351f, 0.001470f, 0.001606f,
+ 0.001765f, 0.001908f, 0.001999f, 0.002104f, 0.002281f, 0.002476f, 0.002659f, 0.002766f, 0.002911f, 0.003040f, 0.003344f, 0.003475f,
+ 0.003683f, 0.003922f, 0.004185f, 0.004417f, 0.004673f, 0.004890f, 0.005123f, 0.005440f, 0.005817f, 0.006126f, 0.006481f, 0.006859f,
+ 0.007275f, 0.007740f, 0.008202f, 0.008728f, 0.009315f, 0.009972f, 0.010597f, 0.011391f, 0.012268f, 0.013252f, 0.014221f, 0.015388f,
+ 0.016724f, 0.018265f, 0.020004f, 0.022049f, 0.024445f, 0.027206f, 0.030762f, 0.034424f, 0.038971f, 0.044220f, 0.050262f, 0.056976f,
+ 0.064575f, 0.072083f, 0.441650f, 0.500488f, 0.514160f, 0.520020f, 0.524414f, 0.526855f, 0.000194f, 0.000467f, 0.000775f, 0.000911f,
+ 0.000994f, 0.001081f, 0.001221f, 0.001204f, 0.001368f, 0.001479f, 0.001582f, 0.001707f, 0.001801f, 0.001921f, 0.001993f, 0.002146f,
+ 0.002245f, 0.002398f, 0.002531f, 0.002674f, 0.002871f, 0.003033f, 0.003172f, 0.003374f, 0.003519f, 0.003742f, 0.003963f, 0.004158f,
+ 0.004448f, 0.004650f, 0.005032f, 0.005230f, 0.005550f, 0.005932f, 0.006241f, 0.006634f, 0.007088f, 0.007572f, 0.008110f, 0.008636f,
+ 0.009323f, 0.010071f, 0.010834f, 0.011757f, 0.012779f, 0.013863f, 0.015190f, 0.016769f, 0.018555f, 0.020706f, 0.023331f, 0.026352f,
+ 0.030182f, 0.034760f, 0.040039f, 0.046356f, 0.053406f, 0.060638f, 0.427979f, 0.489502f, 0.504883f, 0.511719f, 0.515137f, 0.518066f,
+ 0.000339f, 0.000388f, 0.000559f, 0.000617f, 0.000667f, 0.000795f, 0.000853f, 0.000938f, 0.000972f, 0.001079f, 0.001217f, 0.001274f,
+ 0.001369f, 0.001480f, 0.001536f, 0.001581f, 0.001711f, 0.001804f, 0.001900f, 0.002047f, 0.002129f, 0.002245f, 0.002394f, 0.002493f,
+ 0.002645f, 0.002773f, 0.002974f, 0.003124f, 0.003307f, 0.003559f, 0.003757f, 0.003893f, 0.004169f, 0.004353f, 0.004684f, 0.004963f,
+ 0.005272f, 0.005615f, 0.005981f, 0.006420f, 0.006878f, 0.007378f, 0.008080f, 0.008682f, 0.009438f, 0.010239f, 0.011299f, 0.012459f,
+ 0.013809f, 0.015305f, 0.017212f, 0.019501f, 0.022583f, 0.026245f, 0.030838f, 0.036255f, 0.042938f, 0.049988f, 0.416504f, 0.479492f,
+ 0.495361f, 0.501465f, 0.505859f, 0.508789f, 0.000148f, 0.000349f, 0.000414f, 0.000480f, 0.000554f, 0.000575f, 0.000675f, 0.000641f,
+ 0.000743f, 0.000809f, 0.000882f, 0.000919f, 0.000967f, 0.001019f, 0.001122f, 0.001156f, 0.001264f, 0.001322f, 0.001392f, 0.001431f,
+ 0.001529f, 0.001625f, 0.001735f, 0.001802f, 0.001912f, 0.002007f, 0.002131f, 0.002237f, 0.002338f, 0.002525f, 0.002638f, 0.002850f,
+ 0.002962f, 0.003130f, 0.003347f, 0.003536f, 0.003784f, 0.004063f, 0.004364f, 0.004623f, 0.004929f, 0.005314f, 0.005714f, 0.006191f,
+ 0.006760f, 0.007385f, 0.008080f, 0.008919f, 0.009933f, 0.011078f, 0.012390f, 0.014130f, 0.016251f, 0.019012f, 0.022720f, 0.027496f,
+ 0.033234f, 0.040192f, 0.403320f, 0.468994f, 0.485352f, 0.491943f, 0.497070f, 0.500000f, 0.000093f, 0.000191f, 0.000299f, 0.000284f,
+ 0.000367f, 0.000453f, 0.000420f, 0.000467f, 0.000519f, 0.000611f, 0.000607f, 0.000626f, 0.000647f, 0.000722f, 0.000741f, 0.000815f,
+ 0.000829f, 0.000910f, 0.000967f, 0.001023f, 0.001076f, 0.001138f, 0.001197f, 0.001260f, 0.001334f, 0.001393f, 0.001490f, 0.001562f,
+ 0.001633f, 0.001772f, 0.001831f, 0.001949f, 0.002056f, 0.002167f, 0.002312f, 0.002472f, 0.002607f, 0.002781f, 0.002972f, 0.003145f,
+ 0.003387f, 0.003647f, 0.003941f, 0.004253f, 0.004604f, 0.005051f, 0.005558f, 0.006165f, 0.006836f, 0.007660f, 0.008652f, 0.009796f,
+ 0.011284f, 0.013260f, 0.015945f, 0.019608f, 0.024734f, 0.031082f, 0.390625f, 0.459229f, 0.475586f, 0.482910f, 0.488037f, 0.490723f,
+ 0.000132f, 0.000208f, 0.000217f, 0.000221f, 0.000267f, 0.000272f, 0.000277f, 0.000320f, 0.000356f, 0.000372f, 0.000372f, 0.000446f,
+ 0.000436f, 0.000487f, 0.000514f, 0.000531f, 0.000587f, 0.000601f, 0.000629f, 0.000658f, 0.000707f, 0.000736f, 0.000784f, 0.000816f,
+ 0.000880f, 0.000909f, 0.000978f, 0.001035f, 0.001084f, 0.001135f, 0.001200f, 0.001278f, 0.001357f, 0.001429f, 0.001516f, 0.001588f,
+ 0.001724f, 0.001802f, 0.001949f, 0.002085f, 0.002230f, 0.002373f, 0.002554f, 0.002743f, 0.003000f, 0.003300f, 0.003611f, 0.003963f,
+ 0.004425f, 0.004967f, 0.005630f, 0.006424f, 0.007462f, 0.008812f, 0.010551f, 0.013184f, 0.017258f, 0.022980f, 0.377686f, 0.448242f,
+ 0.465820f, 0.474121f, 0.478760f, 0.481934f, 0.000041f, 0.000149f, 0.000126f, 0.000128f, 0.000158f, 0.000196f, 0.000174f, 0.000206f,
+ 0.000216f, 0.000223f, 0.000231f, 0.000244f, 0.000276f, 0.000291f, 0.000312f, 0.000326f, 0.000338f, 0.000374f, 0.000387f, 0.000423f,
+ 0.000430f, 0.000447f, 0.000471f, 0.000509f, 0.000538f, 0.000583f, 0.000591f, 0.000613f, 0.000659f, 0.000688f, 0.000743f, 0.000779f,
+ 0.000833f, 0.000865f, 0.000924f, 0.000966f, 0.001033f, 0.001106f, 0.001186f, 0.001245f, 0.001336f, 0.001453f, 0.001559f, 0.001685f,
+ 0.001807f, 0.001980f, 0.002207f, 0.002417f, 0.002689f, 0.003027f, 0.003418f, 0.003933f, 0.004604f, 0.005482f, 0.006641f, 0.008263f,
+ 0.011017f, 0.015778f, 0.364746f, 0.437256f, 0.456055f, 0.463623f, 0.469238f, 0.472656f, 0.000100f, 0.000089f, 0.000085f, 0.000081f,
+ 0.000101f, 0.000096f, 0.000116f, 0.000116f, 0.000119f, 0.000126f, 0.000141f, 0.000157f, 0.000149f, 0.000158f, 0.000179f, 0.000176f,
+ 0.000195f, 0.000206f, 0.000216f, 0.000222f, 0.000240f, 0.000246f, 0.000269f, 0.000279f, 0.000303f, 0.000320f, 0.000333f, 0.000345f,
+ 0.000365f, 0.000379f, 0.000409f, 0.000434f, 0.000453f, 0.000477f, 0.000511f, 0.000541f, 0.000569f, 0.000608f, 0.000656f, 0.000689f,
+ 0.000738f, 0.000795f, 0.000867f, 0.000918f, 0.001005f, 0.001087f, 0.001189f, 0.001312f, 0.001465f, 0.001656f, 0.001873f, 0.002171f,
+ 0.002546f, 0.003056f, 0.003767f, 0.004765f, 0.006390f, 0.009811f, 0.353516f, 0.426758f, 0.446045f, 0.455078f, 0.459717f, 0.464111f,
+ 0.000084f, 0.000059f, 0.000050f, 0.000049f, 0.000049f, 0.000047f, 0.000052f, 0.000058f, 0.000061f, 0.000075f, 0.000065f, 0.000066f,
+ 0.000080f, 0.000071f, 0.000076f, 0.000082f, 0.000092f, 0.000102f, 0.000100f, 0.000105f, 0.000110f, 0.000115f, 0.000121f, 0.000133f,
+ 0.000140f, 0.000146f, 0.000152f, 0.000164f, 0.000177f, 0.000185f, 0.000192f, 0.000202f, 0.000213f, 0.000224f, 0.000241f, 0.000252f,
+ 0.000268f, 0.000283f, 0.000310f, 0.000328f, 0.000348f, 0.000374f, 0.000406f, 0.000431f, 0.000470f, 0.000515f, 0.000560f, 0.000614f,
+ 0.000688f, 0.000771f, 0.000884f, 0.001019f, 0.001202f, 0.001466f, 0.001827f, 0.002369f, 0.003269f, 0.005184f, 0.341797f, 0.416016f,
+ 0.435791f, 0.445557f, 0.450928f, 0.455078f, 0.000062f, 0.000042f, 0.000035f, 0.000030f, 0.000028f, 0.000026f, 0.000024f, 0.000023f,
+ 0.000023f, 0.000023f, 0.000023f, 0.000030f, 0.000024f, 0.000024f, 0.000031f, 0.000034f, 0.000035f, 0.000037f, 0.000039f, 0.000040f,
+ 0.000043f, 0.000048f, 0.000050f, 0.000046f, 0.000051f, 0.000057f, 0.000059f, 0.000058f, 0.000063f, 0.000068f, 0.000070f, 0.000077f,
+ 0.000082f, 0.000082f, 0.000086f, 0.000093f, 0.000100f, 0.000106f, 0.000114f, 0.000120f, 0.000131f, 0.000136f, 0.000145f, 0.000161f,
+ 0.000171f, 0.000186f, 0.000204f, 0.000222f, 0.000251f, 0.000281f, 0.000318f, 0.000364f, 0.000430f, 0.000530f, 0.000672f, 0.000902f,
+ 0.001316f, 0.002153f, 0.329346f, 0.406006f, 0.426758f, 0.436035f, 0.441650f, 0.445801f, 0.000031f, 0.000020f, 0.000016f, 0.000014f,
+ 0.000014f, 0.000013f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000009f,
+ 0.000008f, 0.000008f, 0.000007f, 0.000007f, 0.000007f, 0.000008f, 0.000009f, 0.000010f, 0.000011f, 0.000012f, 0.000012f, 0.000014f,
+ 0.000014f, 0.000013f, 0.000015f, 0.000016f, 0.000018f, 0.000019f, 0.000019f, 0.000020f, 0.000023f, 0.000023f, 0.000025f, 0.000027f,
+ 0.000028f, 0.000031f, 0.000034f, 0.000034f, 0.000037f, 0.000041f, 0.000045f, 0.000049f, 0.000053f, 0.000059f, 0.000066f, 0.000079f,
+ 0.000093f, 0.000112f, 0.000144f, 0.000196f, 0.000307f, 0.000598f, 0.317383f, 0.394531f, 0.416504f, 0.425781f, 0.432129f, 0.436279f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000004f, 0.000004f, 0.000007f, 0.000010f, 0.000026f, 0.305420f, 0.384277f,
+ 0.405762f, 0.416504f, 0.423340f, 0.427246f,
+ },
+ {
+ 0.009338f, 0.028412f, 0.047394f, 0.066895f, 0.086548f, 0.105774f, 0.125854f, 0.145142f, 0.165039f, 0.184570f, 0.204712f, 0.223389f,
+ 0.243164f, 0.261719f, 0.280762f, 0.299805f, 0.318848f, 0.338135f, 0.356445f, 0.374512f, 0.393066f, 0.412354f, 0.429932f, 0.447510f,
+ 0.465576f, 0.483887f, 0.501465f, 0.518555f, 0.536133f, 0.553711f, 0.570312f, 0.587402f, 0.604492f, 0.621094f, 0.637695f, 0.653809f,
+ 0.670898f, 0.687012f, 0.702637f, 0.719238f, 0.734863f, 0.750488f, 0.765137f, 0.780762f, 0.795898f, 0.811523f, 0.825684f, 0.840820f,
+ 0.855469f, 0.870605f, 0.884277f, 0.899414f, 0.913086f, 0.926758f, 0.940918f, 0.955078f, 0.967773f, 0.981934f, 0.966797f, 0.923828f,
+ 0.894531f, 0.870605f, 0.850586f, 0.832520f, 0.008652f, 0.026825f, 0.045380f, 0.063965f, 0.082703f, 0.101807f, 0.120544f, 0.139282f,
+ 0.158569f, 0.177246f, 0.196167f, 0.214722f, 0.233521f, 0.252197f, 0.270508f, 0.289062f, 0.307861f, 0.325928f, 0.343994f, 0.361328f,
+ 0.380615f, 0.397705f, 0.415771f, 0.433594f, 0.450928f, 0.469238f, 0.485596f, 0.502930f, 0.520020f, 0.537598f, 0.553223f, 0.570801f,
+ 0.586914f, 0.603516f, 0.620117f, 0.636719f, 0.652832f, 0.668945f, 0.683594f, 0.700684f, 0.716309f, 0.731934f, 0.746582f, 0.762695f,
+ 0.777344f, 0.792480f, 0.807617f, 0.821777f, 0.836914f, 0.850586f, 0.865723f, 0.880371f, 0.894043f, 0.908691f, 0.921875f, 0.937012f,
+ 0.950195f, 0.963867f, 0.958496f, 0.917969f, 0.889648f, 0.867188f, 0.847656f, 0.830566f, 0.008293f, 0.025620f, 0.042999f, 0.061035f,
+ 0.079163f, 0.097656f, 0.115112f, 0.132812f, 0.151367f, 0.170532f, 0.188599f, 0.206787f, 0.223999f, 0.242920f, 0.259766f, 0.278809f,
+ 0.296143f, 0.313232f, 0.331055f, 0.349609f, 0.367432f, 0.385010f, 0.401611f, 0.418945f, 0.435791f, 0.453369f, 0.469727f, 0.487061f,
+ 0.503906f, 0.520508f, 0.537598f, 0.553223f, 0.569824f, 0.586426f, 0.603027f, 0.619141f, 0.634277f, 0.650879f, 0.666504f, 0.682129f,
+ 0.697754f, 0.713379f, 0.729004f, 0.743164f, 0.758301f, 0.773926f, 0.789062f, 0.803711f, 0.818359f, 0.833008f, 0.847168f, 0.862305f,
+ 0.875488f, 0.890137f, 0.903809f, 0.917480f, 0.931152f, 0.945801f, 0.950195f, 0.911133f, 0.884766f, 0.862793f, 0.844238f, 0.828125f,
+ 0.008148f, 0.024506f, 0.041016f, 0.058289f, 0.075256f, 0.092712f, 0.109802f, 0.127319f, 0.145020f, 0.162964f, 0.180298f, 0.198120f,
+ 0.215454f, 0.232300f, 0.250244f, 0.267822f, 0.285400f, 0.302734f, 0.318848f, 0.335693f, 0.354004f, 0.371582f, 0.388672f, 0.405029f,
+ 0.421143f, 0.438965f, 0.455078f, 0.472168f, 0.487549f, 0.503906f, 0.521484f, 0.537598f, 0.551758f, 0.568359f, 0.584961f, 0.601562f,
+ 0.616211f, 0.633301f, 0.648926f, 0.664062f, 0.679199f, 0.694824f, 0.709473f, 0.725098f, 0.740234f, 0.755371f, 0.770020f, 0.785156f,
+ 0.799805f, 0.813965f, 0.828125f, 0.842773f, 0.856934f, 0.871582f, 0.884766f, 0.898926f, 0.912598f, 0.926270f, 0.941895f, 0.905273f,
+ 0.879883f, 0.858887f, 0.840332f, 0.824707f, 0.007523f, 0.023010f, 0.039246f, 0.055542f, 0.072021f, 0.088257f, 0.105347f, 0.122070f,
+ 0.138306f, 0.155273f, 0.172852f, 0.189575f, 0.206421f, 0.223145f, 0.240112f, 0.256592f, 0.274170f, 0.291260f, 0.307617f, 0.323730f,
+ 0.340576f, 0.358154f, 0.374023f, 0.390137f, 0.406738f, 0.422852f, 0.440430f, 0.456543f, 0.472656f, 0.489014f, 0.504395f, 0.520996f,
+ 0.537109f, 0.552734f, 0.568848f, 0.584473f, 0.599121f, 0.615234f, 0.630859f, 0.645020f, 0.660645f, 0.677246f, 0.690918f, 0.706055f,
+ 0.721680f, 0.736328f, 0.750977f, 0.766113f, 0.780273f, 0.794922f, 0.809570f, 0.823730f, 0.837891f, 0.852539f, 0.866211f, 0.880371f,
+ 0.894531f, 0.908691f, 0.933105f, 0.898438f, 0.874023f, 0.853516f, 0.836426f, 0.821289f, 0.007339f, 0.021912f, 0.037170f, 0.052948f,
+ 0.068665f, 0.084412f, 0.100281f, 0.116333f, 0.133057f, 0.149048f, 0.164795f, 0.181274f, 0.198242f, 0.214233f, 0.230835f, 0.247314f,
+ 0.262939f, 0.279053f, 0.295898f, 0.312500f, 0.328613f, 0.344971f, 0.360107f, 0.376953f, 0.392578f, 0.408691f, 0.425293f, 0.441406f,
+ 0.456787f, 0.472656f, 0.488525f, 0.504883f, 0.520020f, 0.535156f, 0.550781f, 0.567383f, 0.582520f, 0.597656f, 0.612793f, 0.628418f,
+ 0.642578f, 0.657715f, 0.673340f, 0.688477f, 0.702637f, 0.718750f, 0.731445f, 0.748047f, 0.762207f, 0.775879f, 0.791016f, 0.804199f,
+ 0.818848f, 0.833008f, 0.847656f, 0.861328f, 0.875000f, 0.890625f, 0.924316f, 0.891602f, 0.868164f, 0.849121f, 0.832520f, 0.817871f,
+ 0.006817f, 0.021133f, 0.035675f, 0.050018f, 0.065186f, 0.080505f, 0.096069f, 0.111389f, 0.126831f, 0.142456f, 0.158203f, 0.174194f,
+ 0.189819f, 0.205444f, 0.220703f, 0.237183f, 0.253174f, 0.268555f, 0.284668f, 0.300049f, 0.316406f, 0.332275f, 0.347656f, 0.363281f,
+ 0.379395f, 0.394775f, 0.409668f, 0.426270f, 0.442139f, 0.457275f, 0.472656f, 0.488037f, 0.503906f, 0.518555f, 0.534668f, 0.548828f,
+ 0.564941f, 0.579590f, 0.595215f, 0.610352f, 0.625000f, 0.640137f, 0.654785f, 0.669434f, 0.685059f, 0.699707f, 0.713379f, 0.728027f,
+ 0.742676f, 0.758301f, 0.770996f, 0.786621f, 0.799316f, 0.813965f, 0.828613f, 0.842285f, 0.856445f, 0.871094f, 0.915527f, 0.884766f,
+ 0.862305f, 0.843750f, 0.827637f, 0.813965f, 0.006611f, 0.020111f, 0.033752f, 0.047974f, 0.062378f, 0.076843f, 0.091431f, 0.106262f,
+ 0.120911f, 0.136230f, 0.151123f, 0.166382f, 0.181396f, 0.196899f, 0.211670f, 0.227295f, 0.242554f, 0.257812f, 0.272705f, 0.288086f,
+ 0.304199f, 0.318848f, 0.334473f, 0.349609f, 0.365967f, 0.379883f, 0.395996f, 0.410889f, 0.426270f, 0.441895f, 0.457764f, 0.472412f,
+ 0.487061f, 0.502930f, 0.517090f, 0.532227f, 0.547363f, 0.563477f, 0.577637f, 0.592285f, 0.606934f, 0.621582f, 0.636230f, 0.651367f,
+ 0.665039f, 0.679688f, 0.694336f, 0.709473f, 0.724121f, 0.738770f, 0.752930f, 0.767578f, 0.780762f, 0.795410f, 0.809082f, 0.823242f,
+ 0.837891f, 0.852539f, 0.906250f, 0.877441f, 0.855957f, 0.838379f, 0.823242f, 0.809570f, 0.006153f, 0.019150f, 0.031952f, 0.045624f,
+ 0.059326f, 0.073303f, 0.087158f, 0.101562f, 0.115540f, 0.129395f, 0.144653f, 0.159180f, 0.173584f, 0.187866f, 0.203613f, 0.217651f,
+ 0.232300f, 0.247559f, 0.262207f, 0.277344f, 0.292969f, 0.307617f, 0.322021f, 0.336914f, 0.352051f, 0.367188f, 0.381592f, 0.396729f,
+ 0.411377f, 0.427002f, 0.440918f, 0.456787f, 0.471436f, 0.486572f, 0.500977f, 0.514648f, 0.530273f, 0.545410f, 0.560059f, 0.574219f,
+ 0.589355f, 0.604004f, 0.618164f, 0.632324f, 0.647461f, 0.661133f, 0.676270f, 0.691406f, 0.705078f, 0.719727f, 0.733887f, 0.748047f,
+ 0.763184f, 0.777344f, 0.791016f, 0.805176f, 0.819336f, 0.833496f, 0.896973f, 0.870117f, 0.849609f, 0.833008f, 0.818359f, 0.805176f,
+ 0.005947f, 0.018311f, 0.030731f, 0.043243f, 0.056732f, 0.069580f, 0.083435f, 0.096558f, 0.110474f, 0.123962f, 0.137695f, 0.152100f,
+ 0.166016f, 0.180054f, 0.194092f, 0.208862f, 0.222656f, 0.236816f, 0.251465f, 0.266113f, 0.281250f, 0.294922f, 0.309814f, 0.324219f,
+ 0.338623f, 0.352783f, 0.368164f, 0.382568f, 0.397461f, 0.411377f, 0.426025f, 0.441162f, 0.455078f, 0.469971f, 0.484131f, 0.499268f,
+ 0.513672f, 0.528320f, 0.542969f, 0.557129f, 0.571289f, 0.585449f, 0.599609f, 0.614258f, 0.628418f, 0.643066f, 0.657227f, 0.671875f,
+ 0.686523f, 0.700195f, 0.714355f, 0.729004f, 0.743164f, 0.756836f, 0.770996f, 0.785645f, 0.800293f, 0.814453f, 0.888184f, 0.862305f,
+ 0.843262f, 0.827148f, 0.813477f, 0.800781f, 0.005646f, 0.017136f, 0.029388f, 0.041534f, 0.053802f, 0.066162f, 0.078979f, 0.092285f,
+ 0.104980f, 0.118408f, 0.130981f, 0.144897f, 0.158203f, 0.172363f, 0.185547f, 0.199951f, 0.213501f, 0.226440f, 0.240356f, 0.254883f,
+ 0.269287f, 0.283691f, 0.297607f, 0.311279f, 0.325439f, 0.339600f, 0.353760f, 0.368408f, 0.382812f, 0.396973f, 0.410645f, 0.425049f,
+ 0.439697f, 0.454102f, 0.468262f, 0.482178f, 0.496094f, 0.510742f, 0.524902f, 0.539551f, 0.554199f, 0.568359f, 0.582031f, 0.596191f,
+ 0.610352f, 0.624023f, 0.639160f, 0.652832f, 0.667969f, 0.681152f, 0.696289f, 0.709961f, 0.723633f, 0.738770f, 0.752441f, 0.765625f,
+ 0.780273f, 0.794922f, 0.878418f, 0.855469f, 0.836914f, 0.821289f, 0.808105f, 0.796387f, 0.005478f, 0.016174f, 0.027740f, 0.038849f,
+ 0.051270f, 0.063293f, 0.075317f, 0.087402f, 0.099854f, 0.112793f, 0.125366f, 0.138184f, 0.151001f, 0.164307f, 0.177734f, 0.190918f,
+ 0.204102f, 0.217529f, 0.231079f, 0.244141f, 0.257324f, 0.271240f, 0.284668f, 0.299072f, 0.312744f, 0.326660f, 0.339600f, 0.354004f,
+ 0.368408f, 0.382324f, 0.395264f, 0.410156f, 0.423096f, 0.437500f, 0.452148f, 0.465332f, 0.480469f, 0.493408f, 0.507812f, 0.521484f,
+ 0.535645f, 0.549316f, 0.563477f, 0.578125f, 0.592285f, 0.605957f, 0.620605f, 0.634766f, 0.647949f, 0.662109f, 0.676758f, 0.691406f,
+ 0.705078f, 0.718750f, 0.732910f, 0.747559f, 0.762207f, 0.777344f, 0.869141f, 0.847656f, 0.830078f, 0.815430f, 0.802734f, 0.791504f,
+ 0.005005f, 0.015762f, 0.026657f, 0.037384f, 0.048218f, 0.059998f, 0.071594f, 0.083618f, 0.095215f, 0.107666f, 0.119141f, 0.131958f,
+ 0.144043f, 0.156128f, 0.169800f, 0.182129f, 0.194824f, 0.207031f, 0.219849f, 0.233032f, 0.247559f, 0.260010f, 0.272949f, 0.286133f,
+ 0.300293f, 0.313477f, 0.326172f, 0.339844f, 0.353516f, 0.367188f, 0.381592f, 0.394531f, 0.407959f, 0.422363f, 0.436279f, 0.449463f,
+ 0.462891f, 0.477539f, 0.490723f, 0.504395f, 0.518066f, 0.532227f, 0.545898f, 0.560059f, 0.574219f, 0.586914f, 0.602051f, 0.616211f,
+ 0.629395f, 0.644531f, 0.657227f, 0.671875f, 0.685547f, 0.699707f, 0.713867f, 0.728516f, 0.742676f, 0.756836f, 0.859375f, 0.840332f,
+ 0.823730f, 0.809082f, 0.797363f, 0.786621f, 0.004894f, 0.014786f, 0.025269f, 0.035614f, 0.045990f, 0.057129f, 0.068420f, 0.079224f,
+ 0.090698f, 0.102112f, 0.113708f, 0.125610f, 0.137817f, 0.149536f, 0.161377f, 0.174316f, 0.185791f, 0.198486f, 0.211670f, 0.223389f,
+ 0.236816f, 0.249512f, 0.261230f, 0.274414f, 0.287598f, 0.300537f, 0.313232f, 0.326904f, 0.340576f, 0.353027f, 0.366211f, 0.379883f,
+ 0.393066f, 0.406006f, 0.419678f, 0.433350f, 0.446289f, 0.460205f, 0.473633f, 0.487305f, 0.500977f, 0.515137f, 0.528320f, 0.542480f,
+ 0.554688f, 0.569824f, 0.583008f, 0.597656f, 0.610840f, 0.625488f, 0.638672f, 0.652832f, 0.666504f, 0.681152f, 0.694824f, 0.708984f,
+ 0.723145f, 0.737793f, 0.850098f, 0.833008f, 0.817383f, 0.802734f, 0.791992f, 0.780762f, 0.004536f, 0.014160f, 0.023972f, 0.033630f,
+ 0.043823f, 0.053955f, 0.064697f, 0.075195f, 0.086365f, 0.096802f, 0.108276f, 0.119751f, 0.130493f, 0.142212f, 0.153687f, 0.165405f,
+ 0.177246f, 0.189331f, 0.201538f, 0.213501f, 0.225464f, 0.237915f, 0.250244f, 0.262939f, 0.274902f, 0.288086f, 0.300781f, 0.312988f,
+ 0.326172f, 0.339600f, 0.352051f, 0.365479f, 0.377930f, 0.390625f, 0.403564f, 0.417480f, 0.430420f, 0.444092f, 0.457520f, 0.470215f,
+ 0.483643f, 0.497559f, 0.510742f, 0.524414f, 0.537598f, 0.551270f, 0.564941f, 0.579102f, 0.592285f, 0.605957f, 0.619629f, 0.633789f,
+ 0.647949f, 0.661621f, 0.675293f, 0.689453f, 0.704102f, 0.718262f, 0.840332f, 0.825195f, 0.809570f, 0.797363f, 0.786133f, 0.776367f,
+ 0.004433f, 0.013138f, 0.022720f, 0.032013f, 0.041199f, 0.051147f, 0.061462f, 0.071716f, 0.082336f, 0.091919f, 0.102722f, 0.113586f,
+ 0.124390f, 0.135010f, 0.145996f, 0.157837f, 0.168823f, 0.180054f, 0.192383f, 0.203491f, 0.215332f, 0.227417f, 0.239502f, 0.251221f,
+ 0.263672f, 0.275635f, 0.287842f, 0.300537f, 0.312500f, 0.324707f, 0.338135f, 0.350342f, 0.363037f, 0.375977f, 0.388672f, 0.401611f,
+ 0.413818f, 0.427246f, 0.440186f, 0.453613f, 0.466064f, 0.479736f, 0.492920f, 0.506836f, 0.519531f, 0.533203f, 0.546875f, 0.560059f,
+ 0.573242f, 0.587402f, 0.600098f, 0.614746f, 0.628418f, 0.642578f, 0.657227f, 0.670898f, 0.685059f, 0.699707f, 0.830566f, 0.816406f,
+ 0.802734f, 0.791016f, 0.780273f, 0.770996f, 0.004372f, 0.012619f, 0.021393f, 0.030350f, 0.039276f, 0.048523f, 0.058289f, 0.067505f,
+ 0.077393f, 0.087585f, 0.097290f, 0.107727f, 0.118225f, 0.128296f, 0.138550f, 0.149414f, 0.160278f, 0.171631f, 0.182739f, 0.193359f,
+ 0.205200f, 0.216187f, 0.228027f, 0.240234f, 0.251465f, 0.263428f, 0.275146f, 0.287598f, 0.298828f, 0.311523f, 0.323242f, 0.336182f,
+ 0.348633f, 0.360107f, 0.372803f, 0.385986f, 0.398682f, 0.411621f, 0.424072f, 0.436523f, 0.449951f, 0.462891f, 0.475098f, 0.488525f,
+ 0.501953f, 0.514648f, 0.527344f, 0.541992f, 0.555176f, 0.569336f, 0.582031f, 0.596191f, 0.609863f, 0.623047f, 0.637695f, 0.651855f,
+ 0.665527f, 0.679688f, 0.821289f, 0.808105f, 0.795410f, 0.784180f, 0.774902f, 0.765137f, 0.003937f, 0.012169f, 0.020477f, 0.028641f,
+ 0.037781f, 0.046448f, 0.055481f, 0.064209f, 0.073181f, 0.082458f, 0.092651f, 0.101990f, 0.111572f, 0.121948f, 0.132202f, 0.142212f,
+ 0.151978f, 0.162720f, 0.173340f, 0.184326f, 0.195312f, 0.206055f, 0.217163f, 0.228516f, 0.239990f, 0.250977f, 0.262695f, 0.274658f,
+ 0.285889f, 0.297363f, 0.308838f, 0.321045f, 0.333496f, 0.345459f, 0.357422f, 0.370117f, 0.382324f, 0.395020f, 0.407227f, 0.419922f,
+ 0.432617f, 0.444336f, 0.458008f, 0.470703f, 0.483398f, 0.497559f, 0.510254f, 0.522949f, 0.536133f, 0.550293f, 0.562988f, 0.577637f,
+ 0.590820f, 0.603516f, 0.618164f, 0.632324f, 0.645508f, 0.660645f, 0.811035f, 0.800293f, 0.788086f, 0.777832f, 0.768555f, 0.760254f,
+ 0.003868f, 0.011368f, 0.019257f, 0.027512f, 0.035431f, 0.043274f, 0.051880f, 0.060852f, 0.069214f, 0.078003f, 0.087524f, 0.096924f,
+ 0.105896f, 0.115112f, 0.124817f, 0.134766f, 0.144409f, 0.154663f, 0.164673f, 0.175415f, 0.184814f, 0.196289f, 0.206299f, 0.216797f,
+ 0.228394f, 0.239380f, 0.250244f, 0.260986f, 0.273193f, 0.284424f, 0.295410f, 0.307373f, 0.319092f, 0.331299f, 0.342285f, 0.354248f,
+ 0.366455f, 0.378662f, 0.390869f, 0.403809f, 0.415771f, 0.427734f, 0.440430f, 0.453369f, 0.466309f, 0.479736f, 0.492188f, 0.504883f,
+ 0.518066f, 0.531250f, 0.544922f, 0.558105f, 0.571777f, 0.584473f, 0.598633f, 0.612305f, 0.626465f, 0.641602f, 0.801758f, 0.792480f,
+ 0.781738f, 0.770508f, 0.761230f, 0.753906f, 0.003616f, 0.010872f, 0.018387f, 0.026077f, 0.033875f, 0.041351f, 0.049591f, 0.057434f,
+ 0.065674f, 0.073669f, 0.082153f, 0.091064f, 0.100098f, 0.109009f, 0.117981f, 0.127563f, 0.137207f, 0.146362f, 0.156494f, 0.165894f,
+ 0.176025f, 0.186157f, 0.196655f, 0.206421f, 0.216919f, 0.227539f, 0.237915f, 0.249268f, 0.260254f, 0.270752f, 0.282471f, 0.293945f,
+ 0.305176f, 0.316406f, 0.328125f, 0.338867f, 0.350342f, 0.361816f, 0.375244f, 0.387207f, 0.398926f, 0.411133f, 0.423584f, 0.436523f,
+ 0.448730f, 0.461182f, 0.474121f, 0.485840f, 0.499756f, 0.513672f, 0.525391f, 0.539062f, 0.552734f, 0.565918f, 0.580566f, 0.593750f,
+ 0.608398f, 0.621094f, 0.790527f, 0.783691f, 0.773926f, 0.764160f, 0.755859f, 0.747559f, 0.003450f, 0.010429f, 0.017487f, 0.024445f,
+ 0.031860f, 0.039581f, 0.046631f, 0.054718f, 0.061951f, 0.070251f, 0.078003f, 0.086121f, 0.094910f, 0.102905f, 0.111572f, 0.120300f,
+ 0.129761f, 0.138428f, 0.147217f, 0.156982f, 0.166992f, 0.176147f, 0.186157f, 0.196045f, 0.206299f, 0.216187f, 0.226318f, 0.236938f,
+ 0.247437f, 0.258301f, 0.268311f, 0.279785f, 0.290527f, 0.301758f, 0.312744f, 0.324219f, 0.335449f, 0.346680f, 0.359131f, 0.370605f,
+ 0.382812f, 0.394531f, 0.406982f, 0.419189f, 0.430908f, 0.443604f, 0.456055f, 0.468506f, 0.481445f, 0.494873f, 0.506836f, 0.520996f,
+ 0.534180f, 0.547363f, 0.561035f, 0.573730f, 0.588379f, 0.601074f, 0.780762f, 0.775879f, 0.766602f, 0.757324f, 0.748535f, 0.741699f,
+ 0.003281f, 0.009811f, 0.016174f, 0.023438f, 0.030060f, 0.037109f, 0.044464f, 0.051239f, 0.058441f, 0.066345f, 0.073792f, 0.081238f,
+ 0.089539f, 0.097229f, 0.105286f, 0.113647f, 0.122498f, 0.130615f, 0.139526f, 0.148438f, 0.157837f, 0.166626f, 0.176636f, 0.185547f,
+ 0.195312f, 0.204956f, 0.215088f, 0.224976f, 0.234863f, 0.245239f, 0.255859f, 0.266113f, 0.276367f, 0.287354f, 0.298096f, 0.309326f,
+ 0.320801f, 0.331787f, 0.343018f, 0.355225f, 0.366211f, 0.378418f, 0.389893f, 0.401611f, 0.413574f, 0.425781f, 0.438721f, 0.451416f,
+ 0.463135f, 0.476074f, 0.489014f, 0.501465f, 0.514648f, 0.528809f, 0.541992f, 0.554688f, 0.568848f, 0.582520f, 0.770508f, 0.767090f,
+ 0.758789f, 0.750488f, 0.743164f, 0.735352f, 0.002901f, 0.009422f, 0.015488f, 0.021729f, 0.028290f, 0.035278f, 0.041321f, 0.048523f,
+ 0.055420f, 0.062195f, 0.069336f, 0.076477f, 0.084412f, 0.091858f, 0.099609f, 0.107361f, 0.115112f, 0.123535f, 0.131592f, 0.140137f,
+ 0.148438f, 0.157715f, 0.166382f, 0.174927f, 0.184692f, 0.193970f, 0.203369f, 0.212646f, 0.222656f, 0.232910f, 0.242920f, 0.252197f,
+ 0.263184f, 0.273438f, 0.284180f, 0.294922f, 0.305664f, 0.316895f, 0.327881f, 0.338867f, 0.349854f, 0.361328f, 0.373291f, 0.385254f,
+ 0.397461f, 0.408691f, 0.420898f, 0.433350f, 0.445801f, 0.458252f, 0.470703f, 0.483154f, 0.496826f, 0.510254f, 0.522461f, 0.535645f,
+ 0.549805f, 0.562988f, 0.760742f, 0.758789f, 0.750488f, 0.743652f, 0.736328f, 0.729492f, 0.002861f, 0.008606f, 0.014488f, 0.021057f,
+ 0.026810f, 0.032898f, 0.038879f, 0.045532f, 0.051666f, 0.058319f, 0.065125f, 0.072449f, 0.079224f, 0.086426f, 0.093689f, 0.100830f,
+ 0.108276f, 0.116089f, 0.123962f, 0.131958f, 0.140625f, 0.148560f, 0.156494f, 0.164795f, 0.174194f, 0.183228f, 0.192017f, 0.201294f,
+ 0.210815f, 0.220093f, 0.229858f, 0.239746f, 0.249390f, 0.260010f, 0.270508f, 0.280518f, 0.290771f, 0.301758f, 0.312744f, 0.323486f,
+ 0.334473f, 0.345215f, 0.356934f, 0.368408f, 0.379883f, 0.391846f, 0.403564f, 0.416016f, 0.427490f, 0.439453f, 0.452881f, 0.465332f,
+ 0.478271f, 0.490234f, 0.503906f, 0.517090f, 0.529785f, 0.543945f, 0.750000f, 0.750000f, 0.743164f, 0.736328f, 0.729492f, 0.723145f,
+ 0.002977f, 0.008492f, 0.013931f, 0.019745f, 0.024948f, 0.030991f, 0.036804f, 0.042755f, 0.048889f, 0.055267f, 0.061737f, 0.067932f,
+ 0.074829f, 0.081116f, 0.087646f, 0.095215f, 0.102356f, 0.109436f, 0.116760f, 0.124023f, 0.131714f, 0.139648f, 0.147461f, 0.155762f,
+ 0.164185f, 0.172485f, 0.181152f, 0.189697f, 0.198730f, 0.208130f, 0.217285f, 0.226685f, 0.236572f, 0.245850f, 0.255859f, 0.265869f,
+ 0.276367f, 0.286377f, 0.297607f, 0.307861f, 0.318359f, 0.329102f, 0.340576f, 0.351807f, 0.363281f, 0.374023f, 0.386230f, 0.397949f,
+ 0.409668f, 0.422119f, 0.434082f, 0.446777f, 0.459229f, 0.471924f, 0.484863f, 0.497803f, 0.511230f, 0.525391f, 0.739746f, 0.741211f,
+ 0.735352f, 0.729004f, 0.722656f, 0.717285f, 0.002441f, 0.007896f, 0.013443f, 0.018402f, 0.023911f, 0.029343f, 0.034454f, 0.040375f,
+ 0.045868f, 0.051453f, 0.057800f, 0.063721f, 0.070068f, 0.075928f, 0.082520f, 0.089233f, 0.095703f, 0.102478f, 0.109314f, 0.116638f,
+ 0.123596f, 0.131348f, 0.138550f, 0.145996f, 0.153809f, 0.162109f, 0.170044f, 0.179199f, 0.187866f, 0.196045f, 0.205078f, 0.213745f,
+ 0.223389f, 0.233032f, 0.242554f, 0.252197f, 0.261963f, 0.271973f, 0.281982f, 0.292236f, 0.303223f, 0.312988f, 0.324463f, 0.335693f,
+ 0.346191f, 0.357910f, 0.368652f, 0.380371f, 0.391846f, 0.404541f, 0.415527f, 0.428467f, 0.440674f, 0.453369f, 0.466553f, 0.479248f,
+ 0.491455f, 0.505371f, 0.729492f, 0.732422f, 0.727539f, 0.721191f, 0.716309f, 0.709961f, 0.002457f, 0.007553f, 0.012489f, 0.017548f,
+ 0.022217f, 0.027405f, 0.032471f, 0.037689f, 0.043060f, 0.048553f, 0.054230f, 0.059631f, 0.065369f, 0.071533f, 0.077393f, 0.083069f,
+ 0.089417f, 0.096069f, 0.102356f, 0.108398f, 0.115417f, 0.122925f, 0.130127f, 0.137451f, 0.144531f, 0.152100f, 0.160156f, 0.168091f,
+ 0.176514f, 0.184570f, 0.192871f, 0.201660f, 0.210571f, 0.219238f, 0.229126f, 0.238281f, 0.248413f, 0.257812f, 0.267578f, 0.277588f,
+ 0.287354f, 0.298096f, 0.308594f, 0.319336f, 0.329590f, 0.340820f, 0.351318f, 0.363770f, 0.375732f, 0.386963f, 0.397949f, 0.409912f,
+ 0.422363f, 0.434326f, 0.446533f, 0.459473f, 0.473145f, 0.486084f, 0.718750f, 0.723633f, 0.719727f, 0.713867f, 0.708984f, 0.703613f,
+ 0.002436f, 0.006939f, 0.011612f, 0.016113f, 0.021072f, 0.025497f, 0.030640f, 0.035339f, 0.040222f, 0.045441f, 0.050690f, 0.055725f,
+ 0.060669f, 0.066589f, 0.072144f, 0.077881f, 0.083740f, 0.089294f, 0.095215f, 0.101501f, 0.108032f, 0.114868f, 0.121643f, 0.128052f,
+ 0.135010f, 0.142334f, 0.150024f, 0.157349f, 0.164917f, 0.173340f, 0.181274f, 0.189697f, 0.198120f, 0.206909f, 0.215698f, 0.224365f,
+ 0.234497f, 0.243652f, 0.252930f, 0.262695f, 0.272461f, 0.282471f, 0.292480f, 0.302979f, 0.313721f, 0.324463f, 0.335205f, 0.346436f,
+ 0.357666f, 0.369141f, 0.380859f, 0.391602f, 0.404541f, 0.416016f, 0.428467f, 0.440918f, 0.454102f, 0.466553f, 0.708496f, 0.715820f,
+ 0.711426f, 0.706055f, 0.701660f, 0.696777f, 0.002188f, 0.006599f, 0.011032f, 0.015068f, 0.019897f, 0.024048f, 0.028656f, 0.033264f,
+ 0.037720f, 0.042236f, 0.047028f, 0.051941f, 0.056824f, 0.062012f, 0.067444f, 0.072449f, 0.077942f, 0.083374f, 0.088867f, 0.094727f,
+ 0.100769f, 0.106750f, 0.112732f, 0.119263f, 0.126099f, 0.133179f, 0.139648f, 0.146729f, 0.154175f, 0.161987f, 0.170044f, 0.177612f,
+ 0.185791f, 0.194214f, 0.203125f, 0.211670f, 0.220581f, 0.229370f, 0.238770f, 0.248047f, 0.257812f, 0.267822f, 0.277344f, 0.287109f,
+ 0.297363f, 0.307861f, 0.318848f, 0.329590f, 0.341064f, 0.351562f, 0.363037f, 0.374512f, 0.385498f, 0.397461f, 0.409668f, 0.422363f,
+ 0.434326f, 0.447021f, 0.697266f, 0.706543f, 0.703125f, 0.698730f, 0.694336f, 0.689941f, 0.002024f, 0.006165f, 0.010399f, 0.014481f,
+ 0.018555f, 0.022797f, 0.026627f, 0.030869f, 0.035187f, 0.039459f, 0.043732f, 0.047943f, 0.052917f, 0.057434f, 0.062622f, 0.067261f,
+ 0.071838f, 0.077454f, 0.082581f, 0.087891f, 0.093628f, 0.099182f, 0.105469f, 0.111206f, 0.117126f, 0.123779f, 0.130371f, 0.137085f,
+ 0.143921f, 0.151001f, 0.158691f, 0.166016f, 0.173950f, 0.181641f, 0.190063f, 0.198120f, 0.206909f, 0.215698f, 0.224976f, 0.233398f,
+ 0.242798f, 0.252197f, 0.262207f, 0.271973f, 0.281738f, 0.291992f, 0.302734f, 0.313477f, 0.323242f, 0.334229f, 0.345459f, 0.355957f,
+ 0.368652f, 0.380615f, 0.391602f, 0.403809f, 0.415771f, 0.428467f, 0.686523f, 0.696777f, 0.695312f, 0.691895f, 0.687500f, 0.683105f,
+ 0.001931f, 0.005970f, 0.009651f, 0.013557f, 0.017136f, 0.021088f, 0.024902f, 0.028748f, 0.032623f, 0.036743f, 0.040833f, 0.044983f,
+ 0.049591f, 0.053467f, 0.057800f, 0.062500f, 0.066833f, 0.071533f, 0.076538f, 0.081238f, 0.086670f, 0.092224f, 0.097290f, 0.103088f,
+ 0.108887f, 0.114990f, 0.120972f, 0.127197f, 0.134277f, 0.140503f, 0.147705f, 0.154663f, 0.162231f, 0.169922f, 0.177612f, 0.185303f,
+ 0.193604f, 0.201904f, 0.210815f, 0.219238f, 0.228516f, 0.237427f, 0.247070f, 0.256592f, 0.265869f, 0.275879f, 0.285645f, 0.295898f,
+ 0.306396f, 0.317139f, 0.328369f, 0.338623f, 0.350342f, 0.362305f, 0.374023f, 0.385010f, 0.397461f, 0.410156f, 0.675781f, 0.687988f,
+ 0.687012f, 0.683594f, 0.680664f, 0.676270f, 0.001725f, 0.005436f, 0.009171f, 0.012589f, 0.016190f, 0.019485f, 0.023132f, 0.026978f,
+ 0.030899f, 0.034180f, 0.037659f, 0.041565f, 0.045074f, 0.049438f, 0.053345f, 0.057739f, 0.061768f, 0.065918f, 0.070679f, 0.075073f,
+ 0.080078f, 0.084656f, 0.089966f, 0.095215f, 0.100464f, 0.106445f, 0.112000f, 0.117615f, 0.124207f, 0.130737f, 0.136719f, 0.144043f,
+ 0.151123f, 0.158081f, 0.165405f, 0.173096f, 0.181152f, 0.189087f, 0.197510f, 0.205688f, 0.214600f, 0.223145f, 0.232178f, 0.241699f,
+ 0.250732f, 0.260254f, 0.270264f, 0.279785f, 0.289795f, 0.300293f, 0.310791f, 0.322510f, 0.333496f, 0.344238f, 0.355713f, 0.367188f,
+ 0.379395f, 0.392090f, 0.664551f, 0.678711f, 0.678223f, 0.675781f, 0.672852f, 0.669922f, 0.001741f, 0.005077f, 0.008522f, 0.011810f,
+ 0.014946f, 0.018524f, 0.021332f, 0.024872f, 0.028519f, 0.031799f, 0.034973f, 0.038727f, 0.041992f, 0.045654f, 0.049072f, 0.052856f,
+ 0.056671f, 0.060638f, 0.064819f, 0.069092f, 0.073425f, 0.078125f, 0.082886f, 0.087280f, 0.092651f, 0.098206f, 0.103638f, 0.109192f,
+ 0.114563f, 0.120667f, 0.126709f, 0.133057f, 0.139771f, 0.146851f, 0.153931f, 0.160767f, 0.168457f, 0.175903f, 0.183838f, 0.192505f,
+ 0.200195f, 0.208618f, 0.217407f, 0.226562f, 0.236084f, 0.245239f, 0.254639f, 0.263672f, 0.273926f, 0.283447f, 0.294189f, 0.304932f,
+ 0.315674f, 0.326172f, 0.337402f, 0.348877f, 0.360107f, 0.373291f, 0.653809f, 0.670410f, 0.669922f, 0.667480f, 0.665527f, 0.662109f,
+ 0.001639f, 0.004951f, 0.007996f, 0.010857f, 0.013779f, 0.016968f, 0.019974f, 0.023392f, 0.026001f, 0.029373f, 0.032013f, 0.035370f,
+ 0.038513f, 0.041992f, 0.044586f, 0.048706f, 0.052124f, 0.055634f, 0.059723f, 0.063354f, 0.067444f, 0.071289f, 0.075745f, 0.080444f,
+ 0.085022f, 0.089722f, 0.095032f, 0.100220f, 0.105347f, 0.111206f, 0.117126f, 0.123108f, 0.129395f, 0.135620f, 0.142090f, 0.148682f,
+ 0.156372f, 0.163574f, 0.170898f, 0.178711f, 0.186890f, 0.194580f, 0.203613f, 0.211426f, 0.220459f, 0.229492f, 0.238281f, 0.248169f,
+ 0.257324f, 0.267578f, 0.277832f, 0.287354f, 0.298340f, 0.308350f, 0.319824f, 0.331543f, 0.342041f, 0.354248f, 0.641602f, 0.660645f,
+ 0.662109f, 0.660645f, 0.658203f, 0.654785f, 0.001569f, 0.004539f, 0.007538f, 0.010368f, 0.013359f, 0.016006f, 0.018539f, 0.021210f,
+ 0.024384f, 0.026855f, 0.029892f, 0.032471f, 0.035034f, 0.038177f, 0.041199f, 0.044434f, 0.047485f, 0.050781f, 0.054321f, 0.057953f,
+ 0.061523f, 0.065430f, 0.069275f, 0.073547f, 0.077820f, 0.082092f, 0.086731f, 0.091736f, 0.096985f, 0.101990f, 0.107361f, 0.112549f,
+ 0.118774f, 0.124878f, 0.131104f, 0.137573f, 0.144409f, 0.150635f, 0.157837f, 0.165283f, 0.173340f, 0.181274f, 0.188599f, 0.197510f,
+ 0.205933f, 0.214600f, 0.223633f, 0.232056f, 0.241577f, 0.251709f, 0.261230f, 0.270996f, 0.281250f, 0.291260f, 0.302246f, 0.313477f,
+ 0.323730f, 0.336182f, 0.630859f, 0.651855f, 0.652832f, 0.652344f, 0.650391f, 0.647461f, 0.001558f, 0.004139f, 0.007103f, 0.009560f,
+ 0.012077f, 0.014313f, 0.016983f, 0.019653f, 0.021988f, 0.024490f, 0.027023f, 0.029526f, 0.031891f, 0.034821f, 0.037903f, 0.040192f,
+ 0.043457f, 0.046417f, 0.049316f, 0.052795f, 0.055725f, 0.059357f, 0.063354f, 0.066895f, 0.070740f, 0.074890f, 0.078979f, 0.083801f,
+ 0.088440f, 0.093018f, 0.097961f, 0.103394f, 0.108704f, 0.114563f, 0.120239f, 0.126343f, 0.132690f, 0.139038f, 0.145874f, 0.152710f,
+ 0.159912f, 0.168091f, 0.175537f, 0.183228f, 0.191650f, 0.199707f, 0.208130f, 0.216797f, 0.226074f, 0.235352f, 0.244507f, 0.254395f,
+ 0.264404f, 0.274414f, 0.285156f, 0.296631f, 0.307373f, 0.318604f, 0.619141f, 0.643066f, 0.644531f, 0.644043f, 0.642578f, 0.639648f,
+ 0.001314f, 0.004002f, 0.006603f, 0.009056f, 0.011490f, 0.013184f, 0.015587f, 0.017883f, 0.020157f, 0.022415f, 0.024582f, 0.027206f,
+ 0.029160f, 0.031677f, 0.034088f, 0.036530f, 0.039337f, 0.042206f, 0.044891f, 0.047729f, 0.050751f, 0.053955f, 0.057312f, 0.060486f,
+ 0.064148f, 0.068054f, 0.071960f, 0.075867f, 0.079895f, 0.084595f, 0.089172f, 0.094238f, 0.098999f, 0.104492f, 0.109802f, 0.115173f,
+ 0.121338f, 0.127686f, 0.134033f, 0.140991f, 0.147095f, 0.154541f, 0.161865f, 0.169800f, 0.177368f, 0.185547f, 0.193848f, 0.201904f,
+ 0.211060f, 0.219116f, 0.229004f, 0.238525f, 0.248047f, 0.257812f, 0.267822f, 0.277832f, 0.289062f, 0.300537f, 0.607910f, 0.633301f,
+ 0.636230f, 0.635742f, 0.634766f, 0.633301f, 0.001217f, 0.003571f, 0.005947f, 0.008011f, 0.010391f, 0.012207f, 0.014313f, 0.016617f,
+ 0.018280f, 0.020523f, 0.022537f, 0.024475f, 0.026443f, 0.028778f, 0.030884f, 0.032867f, 0.035553f, 0.037872f, 0.040375f, 0.042938f,
+ 0.045593f, 0.048431f, 0.051605f, 0.054688f, 0.057953f, 0.061279f, 0.065002f, 0.068665f, 0.072266f, 0.076294f, 0.080872f, 0.085083f,
+ 0.089783f, 0.094482f, 0.099915f, 0.104736f, 0.110901f, 0.116272f, 0.122314f, 0.128784f, 0.134888f, 0.142090f, 0.148560f, 0.155884f,
+ 0.163574f, 0.171753f, 0.179077f, 0.187500f, 0.195679f, 0.204346f, 0.213745f, 0.222656f, 0.231812f, 0.241455f, 0.250977f, 0.261230f,
+ 0.272461f, 0.282959f, 0.596680f, 0.623535f, 0.627441f, 0.627930f, 0.627441f, 0.625000f, 0.001111f, 0.003542f, 0.005569f, 0.007504f,
+ 0.009338f, 0.011452f, 0.012939f, 0.015030f, 0.016678f, 0.018326f, 0.020203f, 0.022217f, 0.023788f, 0.025604f, 0.027771f, 0.029877f,
+ 0.031860f, 0.033813f, 0.036102f, 0.038605f, 0.040985f, 0.043579f, 0.046448f, 0.049042f, 0.051849f, 0.055054f, 0.058319f, 0.061615f,
+ 0.065125f, 0.068909f, 0.072815f, 0.076843f, 0.080872f, 0.085571f, 0.089905f, 0.095398f, 0.100159f, 0.105713f, 0.111206f, 0.116882f,
+ 0.122925f, 0.129517f, 0.135742f, 0.142822f, 0.149902f, 0.157349f, 0.165161f, 0.172852f, 0.181152f, 0.189331f, 0.198120f, 0.206909f,
+ 0.215820f, 0.225342f, 0.235474f, 0.245239f, 0.254883f, 0.266602f, 0.584473f, 0.614746f, 0.619141f, 0.619629f, 0.619141f, 0.618164f,
+ 0.001149f, 0.003147f, 0.004826f, 0.006886f, 0.008629f, 0.010452f, 0.012024f, 0.013359f, 0.015175f, 0.016647f, 0.018143f, 0.019882f,
+ 0.021332f, 0.023026f, 0.024902f, 0.026550f, 0.028397f, 0.030045f, 0.032318f, 0.034393f, 0.036682f, 0.038910f, 0.041107f, 0.043671f,
+ 0.046295f, 0.048950f, 0.051819f, 0.054993f, 0.058258f, 0.061523f, 0.065063f, 0.068481f, 0.072510f, 0.076965f, 0.081055f, 0.085510f,
+ 0.090393f, 0.095093f, 0.100342f, 0.105774f, 0.111694f, 0.117371f, 0.124084f, 0.130371f, 0.136963f, 0.143921f, 0.151245f, 0.159058f,
+ 0.166626f, 0.174927f, 0.182983f, 0.191650f, 0.200195f, 0.209473f, 0.218750f, 0.228149f, 0.238037f, 0.249146f, 0.572266f, 0.604980f,
+ 0.609863f, 0.611328f, 0.610352f, 0.611328f, 0.001009f, 0.003059f, 0.004620f, 0.006283f, 0.007881f, 0.009415f, 0.010864f, 0.011940f,
+ 0.013443f, 0.014847f, 0.016403f, 0.017700f, 0.019012f, 0.020493f, 0.021927f, 0.023697f, 0.025177f, 0.026947f, 0.028732f, 0.030472f,
+ 0.032654f, 0.034302f, 0.036591f, 0.038757f, 0.041046f, 0.043488f, 0.045837f, 0.048706f, 0.051544f, 0.054810f, 0.057770f, 0.061188f,
+ 0.064331f, 0.068237f, 0.072083f, 0.076416f, 0.080872f, 0.085388f, 0.090149f, 0.095276f, 0.100403f, 0.105896f, 0.111877f, 0.117798f,
+ 0.124329f, 0.130859f, 0.138062f, 0.145020f, 0.152710f, 0.160034f, 0.168335f, 0.176514f, 0.185059f, 0.193481f, 0.203125f, 0.212158f,
+ 0.221924f, 0.232178f, 0.562500f, 0.594727f, 0.601074f, 0.602539f, 0.603516f, 0.602539f, 0.000865f, 0.002674f, 0.004444f, 0.005615f,
+ 0.007233f, 0.008430f, 0.009827f, 0.010880f, 0.011917f, 0.013206f, 0.014412f, 0.015717f, 0.016876f, 0.018173f, 0.019501f, 0.020950f,
+ 0.022217f, 0.023773f, 0.025284f, 0.026749f, 0.028610f, 0.030151f, 0.032166f, 0.034149f, 0.036041f, 0.038330f, 0.040558f, 0.042877f,
+ 0.045532f, 0.048157f, 0.050934f, 0.053894f, 0.056946f, 0.060303f, 0.063843f, 0.067566f, 0.071472f, 0.075806f, 0.080261f, 0.084778f,
+ 0.089600f, 0.094971f, 0.100220f, 0.105896f, 0.111877f, 0.118103f, 0.125000f, 0.131348f, 0.138550f, 0.146362f, 0.153687f, 0.161987f,
+ 0.169678f, 0.178223f, 0.187134f, 0.196045f, 0.205811f, 0.215698f, 0.549805f, 0.584961f, 0.592773f, 0.594238f, 0.593750f, 0.595215f,
+ 0.000951f, 0.002476f, 0.003956f, 0.005062f, 0.006268f, 0.007637f, 0.008888f, 0.009666f, 0.010628f, 0.011810f, 0.012856f, 0.013878f,
+ 0.014946f, 0.015900f, 0.017227f, 0.018356f, 0.019592f, 0.020889f, 0.022003f, 0.023438f, 0.025101f, 0.026489f, 0.028122f, 0.029739f,
+ 0.031555f, 0.033295f, 0.035431f, 0.037537f, 0.039795f, 0.041962f, 0.044647f, 0.047302f, 0.049957f, 0.052979f, 0.056122f, 0.059387f,
+ 0.062927f, 0.066956f, 0.070679f, 0.074951f, 0.079468f, 0.084167f, 0.089294f, 0.094482f, 0.100098f, 0.106018f, 0.112061f, 0.118835f,
+ 0.125366f, 0.132446f, 0.139893f, 0.147827f, 0.155762f, 0.163574f, 0.172607f, 0.180786f, 0.190063f, 0.199951f, 0.536621f, 0.576172f,
+ 0.583496f, 0.586914f, 0.587402f, 0.586914f, 0.000788f, 0.002115f, 0.003592f, 0.004780f, 0.005939f, 0.006615f, 0.007740f, 0.008598f,
+ 0.009514f, 0.010376f, 0.011200f, 0.012138f, 0.013016f, 0.014069f, 0.014977f, 0.015961f, 0.016922f, 0.018036f, 0.019043f, 0.020447f,
+ 0.021606f, 0.022995f, 0.024323f, 0.025864f, 0.027344f, 0.028946f, 0.030731f, 0.032593f, 0.034515f, 0.036530f, 0.038910f, 0.041016f,
+ 0.043274f, 0.046021f, 0.048981f, 0.051819f, 0.055176f, 0.058472f, 0.062012f, 0.065857f, 0.069946f, 0.074219f, 0.078796f, 0.083801f,
+ 0.088806f, 0.094299f, 0.100281f, 0.106018f, 0.112793f, 0.119446f, 0.126343f, 0.133545f, 0.141357f, 0.149292f, 0.157104f, 0.165894f,
+ 0.174683f, 0.184326f, 0.524902f, 0.566895f, 0.575195f, 0.576660f, 0.579102f, 0.579590f, 0.000661f, 0.001961f, 0.003382f, 0.004311f,
+ 0.005161f, 0.006062f, 0.006737f, 0.007427f, 0.008286f, 0.008995f, 0.009857f, 0.010368f, 0.011230f, 0.011955f, 0.012833f, 0.013786f,
+ 0.014565f, 0.015480f, 0.016647f, 0.017578f, 0.018677f, 0.019806f, 0.020950f, 0.022263f, 0.023651f, 0.024994f, 0.026306f, 0.027863f,
+ 0.029724f, 0.031525f, 0.033325f, 0.035370f, 0.037292f, 0.039673f, 0.042114f, 0.044769f, 0.047546f, 0.050537f, 0.053680f, 0.057098f,
+ 0.060852f, 0.064514f, 0.069031f, 0.073303f, 0.078064f, 0.083069f, 0.088379f, 0.094238f, 0.100220f, 0.106689f, 0.113342f, 0.120300f,
+ 0.127563f, 0.135132f, 0.142700f, 0.151245f, 0.160034f, 0.168823f, 0.512695f, 0.557129f, 0.566406f, 0.569824f, 0.569824f, 0.571289f,
+ 0.000757f, 0.001709f, 0.002844f, 0.003582f, 0.004448f, 0.005192f, 0.005989f, 0.006519f, 0.007038f, 0.007801f, 0.008453f, 0.009071f,
+ 0.009727f, 0.010391f, 0.011009f, 0.011726f, 0.012650f, 0.013184f, 0.014107f, 0.014977f, 0.015900f, 0.016800f, 0.017776f, 0.018936f,
+ 0.020172f, 0.021271f, 0.022446f, 0.023697f, 0.025055f, 0.026703f, 0.028397f, 0.030014f, 0.031921f, 0.033905f, 0.035919f, 0.038177f,
+ 0.040680f, 0.043243f, 0.045898f, 0.049072f, 0.052216f, 0.055725f, 0.059784f, 0.063538f, 0.067688f, 0.072327f, 0.077271f, 0.082764f,
+ 0.088379f, 0.094299f, 0.100708f, 0.107239f, 0.114136f, 0.121582f, 0.128906f, 0.136963f, 0.145630f, 0.153564f, 0.500977f, 0.547852f,
+ 0.556641f, 0.561523f, 0.562500f, 0.563965f, 0.000704f, 0.001769f, 0.002542f, 0.003523f, 0.004036f, 0.004562f, 0.005032f, 0.005661f,
+ 0.006176f, 0.006542f, 0.007072f, 0.007698f, 0.008339f, 0.008827f, 0.009323f, 0.010094f, 0.010757f, 0.011276f, 0.012093f, 0.012733f,
+ 0.013489f, 0.014488f, 0.015244f, 0.016006f, 0.017151f, 0.017975f, 0.018967f, 0.020142f, 0.021255f, 0.022552f, 0.023880f, 0.025314f,
+ 0.026840f, 0.028503f, 0.030441f, 0.032166f, 0.034424f, 0.036438f, 0.039001f, 0.041656f, 0.044464f, 0.047455f, 0.050842f, 0.054443f,
+ 0.058167f, 0.062286f, 0.066956f, 0.071899f, 0.076904f, 0.082458f, 0.088501f, 0.094482f, 0.101196f, 0.108337f, 0.115662f, 0.123352f,
+ 0.130981f, 0.139282f, 0.489746f, 0.538574f, 0.547852f, 0.551270f, 0.554688f, 0.555176f, 0.000579f, 0.001450f, 0.002396f, 0.002857f,
+ 0.003454f, 0.004032f, 0.004356f, 0.004791f, 0.005333f, 0.005718f, 0.006130f, 0.006485f, 0.007042f, 0.007473f, 0.007988f, 0.008476f,
+ 0.008865f, 0.009613f, 0.010086f, 0.010651f, 0.011345f, 0.012047f, 0.012764f, 0.013435f, 0.014282f, 0.015144f, 0.015884f, 0.016846f,
+ 0.017868f, 0.018814f, 0.020050f, 0.021164f, 0.022507f, 0.023773f, 0.025192f, 0.026978f, 0.028564f, 0.030640f, 0.032623f, 0.034882f,
+ 0.037231f, 0.039886f, 0.042786f, 0.046143f, 0.049286f, 0.052979f, 0.057098f, 0.061279f, 0.066223f, 0.071167f, 0.076660f, 0.082581f,
+ 0.088989f, 0.095581f, 0.102661f, 0.109863f, 0.117737f, 0.125488f, 0.476807f, 0.528320f, 0.538574f, 0.543945f, 0.546875f, 0.546875f,
+ 0.000510f, 0.001428f, 0.002037f, 0.002613f, 0.003086f, 0.003290f, 0.003672f, 0.004108f, 0.004345f, 0.004768f, 0.005035f, 0.005470f,
+ 0.005959f, 0.006207f, 0.006599f, 0.007095f, 0.007568f, 0.008003f, 0.008377f, 0.008904f, 0.009575f, 0.010010f, 0.010643f, 0.011131f,
+ 0.011871f, 0.012535f, 0.013199f, 0.014038f, 0.014839f, 0.015640f, 0.016586f, 0.017502f, 0.018585f, 0.019745f, 0.021088f, 0.022354f,
+ 0.023727f, 0.025253f, 0.026962f, 0.028870f, 0.030762f, 0.033051f, 0.035492f, 0.038177f, 0.041229f, 0.044403f, 0.048004f, 0.051880f,
+ 0.056213f, 0.060516f, 0.065857f, 0.071045f, 0.077271f, 0.083374f, 0.090027f, 0.096863f, 0.104492f, 0.112183f, 0.463623f, 0.518066f,
+ 0.529785f, 0.535156f, 0.538086f, 0.540039f, 0.000473f, 0.001222f, 0.001771f, 0.002117f, 0.002323f, 0.002796f, 0.003096f, 0.003355f,
+ 0.003601f, 0.003975f, 0.004295f, 0.004543f, 0.004833f, 0.005142f, 0.005455f, 0.005848f, 0.006165f, 0.006535f, 0.006947f, 0.007370f,
+ 0.007809f, 0.008240f, 0.008690f, 0.009216f, 0.009758f, 0.010223f, 0.010925f, 0.011536f, 0.012146f, 0.012833f, 0.013573f, 0.014389f,
+ 0.015244f, 0.016220f, 0.017120f, 0.018219f, 0.019379f, 0.020599f, 0.021988f, 0.023514f, 0.025131f, 0.027054f, 0.029037f, 0.031311f,
+ 0.033752f, 0.036591f, 0.039520f, 0.042999f, 0.046661f, 0.050873f, 0.055603f, 0.060333f, 0.066101f, 0.071960f, 0.078491f, 0.084961f,
+ 0.091797f, 0.099426f, 0.452148f, 0.508301f, 0.520508f, 0.526367f, 0.528809f, 0.530273f, 0.000299f, 0.001057f, 0.001329f, 0.001771f,
+ 0.001957f, 0.002350f, 0.002483f, 0.002697f, 0.002964f, 0.003181f, 0.003441f, 0.003653f, 0.003904f, 0.004238f, 0.004501f, 0.004738f,
+ 0.005024f, 0.005390f, 0.005657f, 0.005985f, 0.006279f, 0.006714f, 0.007053f, 0.007507f, 0.007881f, 0.008369f, 0.008774f, 0.009300f,
+ 0.009888f, 0.010483f, 0.011093f, 0.011627f, 0.012398f, 0.013130f, 0.013855f, 0.014717f, 0.015686f, 0.016739f, 0.017761f, 0.018890f,
+ 0.020248f, 0.021698f, 0.023376f, 0.025131f, 0.027237f, 0.029556f, 0.032166f, 0.035004f, 0.038208f, 0.041962f, 0.045868f, 0.050507f,
+ 0.055359f, 0.060852f, 0.066772f, 0.073242f, 0.080017f, 0.087097f, 0.440674f, 0.498047f, 0.511719f, 0.517090f, 0.520508f, 0.522949f,
+ 0.000427f, 0.001020f, 0.001253f, 0.001431f, 0.001690f, 0.001900f, 0.002018f, 0.002304f, 0.002481f, 0.002569f, 0.002731f, 0.002998f,
+ 0.003157f, 0.003424f, 0.003592f, 0.003838f, 0.004017f, 0.004253f, 0.004551f, 0.004776f, 0.005100f, 0.005379f, 0.005699f, 0.005932f,
+ 0.006290f, 0.006630f, 0.007038f, 0.007465f, 0.007927f, 0.008286f, 0.008858f, 0.009293f, 0.009888f, 0.010429f, 0.011086f, 0.011765f,
+ 0.012482f, 0.013298f, 0.014168f, 0.015068f, 0.016129f, 0.017288f, 0.018585f, 0.019943f, 0.021622f, 0.023361f, 0.025436f, 0.027847f,
+ 0.030655f, 0.033447f, 0.037079f, 0.041229f, 0.045776f, 0.050568f, 0.056061f, 0.062317f, 0.068726f, 0.075684f, 0.427734f, 0.488525f,
+ 0.502441f, 0.508789f, 0.513184f, 0.513672f, 0.000255f, 0.000597f, 0.001032f, 0.001150f, 0.001353f, 0.001493f, 0.001608f, 0.001750f,
+ 0.001933f, 0.002062f, 0.002178f, 0.002302f, 0.002474f, 0.002670f, 0.002872f, 0.002995f, 0.003147f, 0.003298f, 0.003565f, 0.003729f,
+ 0.003941f, 0.004219f, 0.004436f, 0.004719f, 0.005005f, 0.005230f, 0.005489f, 0.005806f, 0.006191f, 0.006496f, 0.006897f, 0.007267f,
+ 0.007671f, 0.008179f, 0.008636f, 0.009163f, 0.009766f, 0.010368f, 0.011047f, 0.011810f, 0.012611f, 0.013527f, 0.014519f, 0.015640f,
+ 0.016800f, 0.018265f, 0.019897f, 0.021698f, 0.023895f, 0.026260f, 0.029175f, 0.032715f, 0.036682f, 0.041168f, 0.045929f, 0.051758f,
+ 0.057922f, 0.064575f, 0.415771f, 0.478271f, 0.493652f, 0.500000f, 0.503906f, 0.505859f, 0.000255f, 0.000544f, 0.000863f, 0.000994f,
+ 0.001086f, 0.001183f, 0.001317f, 0.001328f, 0.001491f, 0.001608f, 0.001716f, 0.001851f, 0.001943f, 0.002075f, 0.002161f, 0.002319f,
+ 0.002426f, 0.002596f, 0.002741f, 0.002884f, 0.003088f, 0.003265f, 0.003391f, 0.003620f, 0.003777f, 0.004005f, 0.004215f, 0.004452f,
+ 0.004734f, 0.004963f, 0.005341f, 0.005577f, 0.005875f, 0.006271f, 0.006603f, 0.006996f, 0.007450f, 0.007919f, 0.008446f, 0.009003f,
+ 0.009674f, 0.010338f, 0.011101f, 0.011909f, 0.012917f, 0.013977f, 0.015190f, 0.016495f, 0.018112f, 0.020325f, 0.022415f, 0.025146f,
+ 0.028473f, 0.032349f, 0.036804f, 0.041992f, 0.047913f, 0.054077f, 0.404541f, 0.468506f, 0.484131f, 0.490967f, 0.495361f, 0.498291f,
+ 0.000377f, 0.000440f, 0.000606f, 0.000685f, 0.000735f, 0.000876f, 0.000929f, 0.001035f, 0.001068f, 0.001157f, 0.001307f, 0.001381f,
+ 0.001473f, 0.001595f, 0.001664f, 0.001708f, 0.001850f, 0.001957f, 0.002043f, 0.002195f, 0.002291f, 0.002422f, 0.002571f, 0.002687f,
+ 0.002842f, 0.002979f, 0.003183f, 0.003345f, 0.003532f, 0.003794f, 0.004002f, 0.004154f, 0.004429f, 0.004635f, 0.004967f, 0.005253f,
+ 0.005573f, 0.005909f, 0.006275f, 0.006695f, 0.007183f, 0.007660f, 0.008316f, 0.008934f, 0.009644f, 0.010429f, 0.011360f, 0.012497f,
+ 0.013634f, 0.014977f, 0.016663f, 0.018875f, 0.021423f, 0.024643f, 0.028549f, 0.033020f, 0.038483f, 0.044525f, 0.391602f, 0.458984f,
+ 0.474854f, 0.482178f, 0.488037f, 0.489990f, 0.000159f, 0.000401f, 0.000450f, 0.000522f, 0.000605f, 0.000634f, 0.000728f, 0.000702f,
+ 0.000808f, 0.000882f, 0.000959f, 0.000991f, 0.001043f, 0.001112f, 0.001205f, 0.001245f, 0.001357f, 0.001419f, 0.001513f, 0.001546f,
+ 0.001648f, 0.001752f, 0.001863f, 0.001942f, 0.002056f, 0.002159f, 0.002289f, 0.002392f, 0.002506f, 0.002697f, 0.002827f, 0.003023f,
+ 0.003172f, 0.003330f, 0.003542f, 0.003750f, 0.004017f, 0.004292f, 0.004559f, 0.004871f, 0.005161f, 0.005539f, 0.005932f, 0.006416f,
+ 0.006973f, 0.007526f, 0.008232f, 0.008980f, 0.009918f, 0.010895f, 0.012085f, 0.013680f, 0.015472f, 0.017975f, 0.021103f, 0.025146f,
+ 0.029938f, 0.035645f, 0.379395f, 0.448486f, 0.465820f, 0.473633f, 0.478760f, 0.481689f, 0.000112f, 0.000220f, 0.000321f, 0.000322f,
+ 0.000401f, 0.000489f, 0.000469f, 0.000510f, 0.000568f, 0.000653f, 0.000659f, 0.000676f, 0.000703f, 0.000789f, 0.000811f, 0.000886f,
+ 0.000888f, 0.000994f, 0.001048f, 0.001096f, 0.001155f, 0.001220f, 0.001289f, 0.001357f, 0.001431f, 0.001496f, 0.001599f, 0.001675f,
+ 0.001759f, 0.001894f, 0.001965f, 0.002083f, 0.002193f, 0.002310f, 0.002464f, 0.002634f, 0.002758f, 0.002949f, 0.003134f, 0.003319f,
+ 0.003551f, 0.003830f, 0.004120f, 0.004440f, 0.004784f, 0.005188f, 0.005680f, 0.006222f, 0.006886f, 0.007614f, 0.008461f, 0.009529f,
+ 0.010864f, 0.012596f, 0.014961f, 0.018097f, 0.022263f, 0.027466f, 0.367920f, 0.438232f, 0.456543f, 0.465332f, 0.470215f, 0.472900f,
+ 0.000140f, 0.000219f, 0.000241f, 0.000245f, 0.000290f, 0.000291f, 0.000302f, 0.000342f, 0.000380f, 0.000409f, 0.000408f, 0.000485f,
+ 0.000473f, 0.000527f, 0.000556f, 0.000575f, 0.000630f, 0.000642f, 0.000673f, 0.000711f, 0.000762f, 0.000800f, 0.000852f, 0.000886f,
+ 0.000952f, 0.000982f, 0.001049f, 0.001108f, 0.001159f, 0.001220f, 0.001281f, 0.001369f, 0.001454f, 0.001522f, 0.001595f, 0.001695f,
+ 0.001839f, 0.001928f, 0.002068f, 0.002209f, 0.002337f, 0.002504f, 0.002686f, 0.002876f, 0.003139f, 0.003437f, 0.003723f, 0.004078f,
+ 0.004509f, 0.005009f, 0.005615f, 0.006332f, 0.007317f, 0.008461f, 0.009926f, 0.012154f, 0.015640f, 0.020325f, 0.356445f, 0.429199f,
+ 0.447266f, 0.456299f, 0.462158f, 0.464844f, 0.000048f, 0.000154f, 0.000141f, 0.000147f, 0.000174f, 0.000207f, 0.000188f, 0.000221f,
+ 0.000233f, 0.000242f, 0.000248f, 0.000271f, 0.000299f, 0.000312f, 0.000337f, 0.000350f, 0.000367f, 0.000403f, 0.000416f, 0.000458f,
+ 0.000465f, 0.000483f, 0.000507f, 0.000546f, 0.000576f, 0.000625f, 0.000637f, 0.000659f, 0.000705f, 0.000742f, 0.000797f, 0.000837f,
+ 0.000890f, 0.000925f, 0.000978f, 0.001036f, 0.001103f, 0.001181f, 0.001253f, 0.001329f, 0.001421f, 0.001529f, 0.001647f, 0.001782f,
+ 0.001906f, 0.002075f, 0.002291f, 0.002483f, 0.002758f, 0.003059f, 0.003450f, 0.003906f, 0.004536f, 0.005306f, 0.006325f, 0.007713f,
+ 0.010101f, 0.014084f, 0.343262f, 0.418457f, 0.437744f, 0.447510f, 0.452881f, 0.456543f, 0.000099f, 0.000100f, 0.000091f, 0.000085f,
+ 0.000105f, 0.000099f, 0.000127f, 0.000127f, 0.000130f, 0.000137f, 0.000152f, 0.000164f, 0.000164f, 0.000172f, 0.000195f, 0.000186f,
+ 0.000209f, 0.000222f, 0.000231f, 0.000241f, 0.000258f, 0.000266f, 0.000290f, 0.000301f, 0.000324f, 0.000343f, 0.000357f, 0.000369f,
+ 0.000392f, 0.000409f, 0.000440f, 0.000463f, 0.000484f, 0.000513f, 0.000544f, 0.000578f, 0.000607f, 0.000650f, 0.000702f, 0.000737f,
+ 0.000787f, 0.000846f, 0.000918f, 0.000977f, 0.001062f, 0.001146f, 0.001259f, 0.001379f, 0.001524f, 0.001701f, 0.001924f, 0.002207f,
+ 0.002542f, 0.003006f, 0.003628f, 0.004494f, 0.005821f, 0.008774f, 0.332031f, 0.409180f, 0.428467f, 0.438965f, 0.444336f, 0.447998f,
+ 0.000082f, 0.000057f, 0.000048f, 0.000051f, 0.000055f, 0.000054f, 0.000057f, 0.000064f, 0.000066f, 0.000079f, 0.000070f, 0.000070f,
+ 0.000084f, 0.000078f, 0.000084f, 0.000091f, 0.000099f, 0.000108f, 0.000108f, 0.000114f, 0.000119f, 0.000124f, 0.000129f, 0.000144f,
+ 0.000151f, 0.000158f, 0.000163f, 0.000176f, 0.000188f, 0.000196f, 0.000208f, 0.000220f, 0.000227f, 0.000239f, 0.000259f, 0.000273f,
+ 0.000290f, 0.000303f, 0.000331f, 0.000351f, 0.000376f, 0.000402f, 0.000432f, 0.000460f, 0.000500f, 0.000547f, 0.000593f, 0.000648f,
+ 0.000720f, 0.000805f, 0.000918f, 0.001045f, 0.001225f, 0.001462f, 0.001788f, 0.002264f, 0.003029f, 0.004623f, 0.320801f, 0.398682f,
+ 0.419922f, 0.430420f, 0.436279f, 0.440674f, 0.000061f, 0.000041f, 0.000033f, 0.000029f, 0.000026f, 0.000025f, 0.000024f, 0.000024f,
+ 0.000023f, 0.000023f, 0.000025f, 0.000032f, 0.000026f, 0.000027f, 0.000035f, 0.000037f, 0.000039f, 0.000041f, 0.000041f, 0.000041f,
+ 0.000044f, 0.000050f, 0.000054f, 0.000051f, 0.000055f, 0.000060f, 0.000061f, 0.000062f, 0.000069f, 0.000074f, 0.000075f, 0.000081f,
+ 0.000087f, 0.000090f, 0.000093f, 0.000098f, 0.000108f, 0.000114f, 0.000123f, 0.000130f, 0.000142f, 0.000144f, 0.000156f, 0.000173f,
+ 0.000179f, 0.000200f, 0.000218f, 0.000237f, 0.000267f, 0.000299f, 0.000335f, 0.000382f, 0.000448f, 0.000544f, 0.000677f, 0.000883f,
+ 0.001233f, 0.001933f, 0.309570f, 0.388672f, 0.410889f, 0.421143f, 0.427246f, 0.431885f, 0.000031f, 0.000020f, 0.000016f, 0.000014f,
+ 0.000013f, 0.000012f, 0.000012f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000008f, 0.000009f,
+ 0.000009f, 0.000007f, 0.000007f, 0.000007f, 0.000008f, 0.000009f, 0.000011f, 0.000012f, 0.000012f, 0.000012f, 0.000013f, 0.000015f,
+ 0.000015f, 0.000014f, 0.000016f, 0.000017f, 0.000019f, 0.000020f, 0.000020f, 0.000022f, 0.000025f, 0.000023f, 0.000026f, 0.000029f,
+ 0.000031f, 0.000034f, 0.000036f, 0.000037f, 0.000040f, 0.000044f, 0.000048f, 0.000052f, 0.000056f, 0.000063f, 0.000068f, 0.000083f,
+ 0.000098f, 0.000117f, 0.000149f, 0.000201f, 0.000301f, 0.000544f, 0.297607f, 0.379150f, 0.400879f, 0.411865f, 0.419189f, 0.423340f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f,
+ 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000002f, 0.000003f, 0.000004f, 0.000004f, 0.000004f, 0.000005f, 0.000007f, 0.000011f, 0.000026f, 0.286621f, 0.368896f,
+ 0.391846f, 0.402588f, 0.409912f, 0.414551f,
+ },
+ {
+ 0.007935f, 0.024429f, 0.041290f, 0.058838f, 0.076355f, 0.093933f, 0.111145f, 0.128174f, 0.146606f, 0.164429f, 0.182617f, 0.200562f,
+ 0.218750f, 0.236206f, 0.254150f, 0.271729f, 0.289551f, 0.308105f, 0.325684f, 0.342773f, 0.360596f, 0.379150f, 0.396240f, 0.414795f,
+ 0.431641f, 0.450439f, 0.468018f, 0.484619f, 0.502441f, 0.520020f, 0.536621f, 0.554688f, 0.571777f, 0.588379f, 0.605469f, 0.622559f,
+ 0.640137f, 0.657227f, 0.672852f, 0.689941f, 0.707031f, 0.723633f, 0.740234f, 0.756836f, 0.773926f, 0.789551f, 0.805664f, 0.821777f,
+ 0.838379f, 0.854980f, 0.870117f, 0.885742f, 0.901855f, 0.917480f, 0.932617f, 0.948730f, 0.963379f, 0.979492f, 0.960449f, 0.909668f,
+ 0.876465f, 0.850098f, 0.827637f, 0.807617f, 0.007530f, 0.023422f, 0.039764f, 0.056610f, 0.073303f, 0.090149f, 0.107300f, 0.124084f,
+ 0.141968f, 0.158569f, 0.176392f, 0.193604f, 0.210815f, 0.228760f, 0.246094f, 0.262695f, 0.280518f, 0.298340f, 0.315430f, 0.333252f,
+ 0.350586f, 0.367432f, 0.384766f, 0.402344f, 0.419678f, 0.436768f, 0.453613f, 0.471436f, 0.488037f, 0.504883f, 0.521973f, 0.538574f,
+ 0.556641f, 0.573242f, 0.589844f, 0.605957f, 0.623535f, 0.639160f, 0.656250f, 0.673340f, 0.688477f, 0.706055f, 0.721680f, 0.738770f,
+ 0.754883f, 0.770508f, 0.786133f, 0.803711f, 0.817871f, 0.834473f, 0.850586f, 0.866211f, 0.881348f, 0.896973f, 0.913086f, 0.928223f,
+ 0.942871f, 0.958984f, 0.951172f, 0.903320f, 0.871094f, 0.845703f, 0.824219f, 0.805664f, 0.007320f, 0.022552f, 0.038391f, 0.054260f,
+ 0.070312f, 0.086792f, 0.103271f, 0.120178f, 0.136841f, 0.153564f, 0.170410f, 0.187256f, 0.203735f, 0.220825f, 0.237793f, 0.255127f,
+ 0.271240f, 0.288086f, 0.305420f, 0.322021f, 0.339844f, 0.356689f, 0.373047f, 0.390137f, 0.406738f, 0.423340f, 0.440186f, 0.456787f,
+ 0.474121f, 0.490967f, 0.507324f, 0.523926f, 0.540527f, 0.557129f, 0.573242f, 0.590332f, 0.606445f, 0.623047f, 0.638672f, 0.655273f,
+ 0.671875f, 0.687500f, 0.703613f, 0.720215f, 0.735840f, 0.751953f, 0.767578f, 0.783203f, 0.799316f, 0.814941f, 0.830078f, 0.845703f,
+ 0.861328f, 0.877441f, 0.892090f, 0.908203f, 0.922852f, 0.938477f, 0.941895f, 0.895996f, 0.865723f, 0.841309f, 0.820801f, 0.802734f,
+ 0.007008f, 0.021667f, 0.036865f, 0.052216f, 0.067871f, 0.083862f, 0.099426f, 0.115479f, 0.131470f, 0.148315f, 0.164551f, 0.180298f,
+ 0.196899f, 0.213379f, 0.229370f, 0.246460f, 0.262695f, 0.279541f, 0.295410f, 0.311523f, 0.329102f, 0.345215f, 0.360840f, 0.378174f,
+ 0.394043f, 0.410156f, 0.427246f, 0.443115f, 0.459717f, 0.476318f, 0.493652f, 0.508789f, 0.524902f, 0.541016f, 0.557129f, 0.573242f,
+ 0.589844f, 0.605469f, 0.621582f, 0.638672f, 0.652832f, 0.669434f, 0.685547f, 0.701660f, 0.717285f, 0.731934f, 0.749023f, 0.764160f,
+ 0.779785f, 0.794922f, 0.810059f, 0.826172f, 0.841309f, 0.856445f, 0.872070f, 0.886719f, 0.902344f, 0.917480f, 0.932129f, 0.889648f,
+ 0.859863f, 0.835938f, 0.816895f, 0.799316f, 0.006817f, 0.020645f, 0.035156f, 0.050110f, 0.065247f, 0.080383f, 0.096313f, 0.111450f,
+ 0.126587f, 0.142456f, 0.158447f, 0.174316f, 0.189819f, 0.205566f, 0.221802f, 0.237427f, 0.253662f, 0.269775f, 0.285889f, 0.301514f,
+ 0.317627f, 0.333740f, 0.349609f, 0.366211f, 0.381348f, 0.397705f, 0.414307f, 0.429932f, 0.447266f, 0.462646f, 0.477539f, 0.494385f,
+ 0.509766f, 0.525879f, 0.541992f, 0.557617f, 0.571777f, 0.588379f, 0.605469f, 0.619629f, 0.636230f, 0.651855f, 0.666992f, 0.681152f,
+ 0.698242f, 0.714355f, 0.729980f, 0.745117f, 0.759766f, 0.775391f, 0.790527f, 0.806152f, 0.821289f, 0.835938f, 0.850586f, 0.866211f,
+ 0.882324f, 0.896484f, 0.922363f, 0.882324f, 0.854004f, 0.831543f, 0.812500f, 0.795898f, 0.006378f, 0.019989f, 0.034027f, 0.048004f,
+ 0.062744f, 0.077148f, 0.091980f, 0.107178f, 0.122192f, 0.137207f, 0.152466f, 0.167603f, 0.183960f, 0.199097f, 0.214111f, 0.229736f,
+ 0.244995f, 0.260254f, 0.276367f, 0.291504f, 0.306641f, 0.322998f, 0.338623f, 0.354248f, 0.369629f, 0.385254f, 0.400879f, 0.416504f,
+ 0.432617f, 0.447510f, 0.464111f, 0.479492f, 0.494141f, 0.511230f, 0.525879f, 0.541016f, 0.556641f, 0.572754f, 0.586914f, 0.602051f,
+ 0.617676f, 0.633789f, 0.648926f, 0.665039f, 0.679688f, 0.695312f, 0.710449f, 0.726074f, 0.739746f, 0.755859f, 0.771484f, 0.785645f,
+ 0.800781f, 0.815918f, 0.831055f, 0.846680f, 0.860840f, 0.875977f, 0.912598f, 0.874512f, 0.847656f, 0.826172f, 0.807617f, 0.791504f,
+ 0.006603f, 0.019287f, 0.032776f, 0.046356f, 0.060272f, 0.073914f, 0.088135f, 0.102905f, 0.117554f, 0.132690f, 0.147095f, 0.161377f,
+ 0.176636f, 0.191162f, 0.205444f, 0.221680f, 0.236572f, 0.251465f, 0.267090f, 0.281250f, 0.296875f, 0.312256f, 0.327393f, 0.342285f,
+ 0.357666f, 0.373291f, 0.388184f, 0.403076f, 0.418457f, 0.433838f, 0.448975f, 0.465088f, 0.479980f, 0.494385f, 0.509277f, 0.525879f,
+ 0.540039f, 0.555176f, 0.570801f, 0.586426f, 0.601074f, 0.616211f, 0.631348f, 0.646484f, 0.661133f, 0.676270f, 0.692383f, 0.705078f,
+ 0.720215f, 0.735352f, 0.751953f, 0.766602f, 0.781250f, 0.796387f, 0.810059f, 0.825684f, 0.840820f, 0.855469f, 0.902344f, 0.866699f,
+ 0.841797f, 0.820312f, 0.803223f, 0.787598f, 0.006111f, 0.018433f, 0.031097f, 0.044739f, 0.057892f, 0.071472f, 0.085205f, 0.099304f,
+ 0.113037f, 0.127319f, 0.141357f, 0.156128f, 0.169678f, 0.183838f, 0.198608f, 0.213745f, 0.227661f, 0.243652f, 0.257324f, 0.272705f,
+ 0.286865f, 0.301025f, 0.316406f, 0.331543f, 0.345703f, 0.360107f, 0.375000f, 0.390625f, 0.405762f, 0.420410f, 0.435303f, 0.449951f,
+ 0.465088f, 0.479492f, 0.494141f, 0.509277f, 0.523926f, 0.538574f, 0.553711f, 0.569336f, 0.583496f, 0.598145f, 0.612793f, 0.628418f,
+ 0.642578f, 0.657227f, 0.671387f, 0.687012f, 0.702637f, 0.716797f, 0.731934f, 0.745605f, 0.761230f, 0.775391f, 0.790527f, 0.805176f,
+ 0.819824f, 0.834961f, 0.892578f, 0.858887f, 0.834473f, 0.814941f, 0.798340f, 0.783203f, 0.005756f, 0.017761f, 0.029907f, 0.042572f,
+ 0.055481f, 0.068420f, 0.081482f, 0.095276f, 0.108826f, 0.122070f, 0.135620f, 0.149902f, 0.163330f, 0.177368f, 0.191284f, 0.206421f,
+ 0.219482f, 0.233521f, 0.247925f, 0.262451f, 0.277100f, 0.290771f, 0.304688f, 0.319580f, 0.334229f, 0.348389f, 0.362549f, 0.377441f,
+ 0.391602f, 0.406250f, 0.421143f, 0.435791f, 0.450439f, 0.463867f, 0.478760f, 0.493164f, 0.507812f, 0.521973f, 0.537109f, 0.551270f,
+ 0.565430f, 0.580078f, 0.594727f, 0.609863f, 0.624023f, 0.638672f, 0.653320f, 0.668457f, 0.682129f, 0.697266f, 0.711914f, 0.726562f,
+ 0.740723f, 0.755859f, 0.770996f, 0.785156f, 0.799805f, 0.814453f, 0.882812f, 0.851562f, 0.827148f, 0.808594f, 0.792969f, 0.778809f,
+ 0.005741f, 0.017166f, 0.029053f, 0.041138f, 0.053345f, 0.065796f, 0.078674f, 0.091248f, 0.104614f, 0.117004f, 0.130737f, 0.143921f,
+ 0.156860f, 0.170288f, 0.183960f, 0.197754f, 0.211304f, 0.224976f, 0.238892f, 0.251953f, 0.266357f, 0.280273f, 0.294922f, 0.308594f,
+ 0.322021f, 0.336914f, 0.350098f, 0.364502f, 0.378174f, 0.393066f, 0.407471f, 0.420166f, 0.435059f, 0.449219f, 0.463135f, 0.477295f,
+ 0.491699f, 0.506348f, 0.520996f, 0.534668f, 0.549316f, 0.563477f, 0.577148f, 0.591309f, 0.605469f, 0.620605f, 0.634766f, 0.648438f,
+ 0.663086f, 0.677734f, 0.691895f, 0.706543f, 0.720215f, 0.734863f, 0.750488f, 0.765137f, 0.779297f, 0.793945f, 0.872559f, 0.843262f,
+ 0.820801f, 0.803223f, 0.787598f, 0.773926f, 0.005283f, 0.016052f, 0.028030f, 0.039246f, 0.050751f, 0.063232f, 0.074829f, 0.087341f,
+ 0.099976f, 0.112732f, 0.125122f, 0.138062f, 0.150757f, 0.163696f, 0.176758f, 0.189697f, 0.203125f, 0.216553f, 0.229614f, 0.243286f,
+ 0.256592f, 0.269775f, 0.283203f, 0.297119f, 0.310547f, 0.324463f, 0.337891f, 0.351807f, 0.365234f, 0.378662f, 0.392822f, 0.406738f,
+ 0.419922f, 0.434814f, 0.448730f, 0.461182f, 0.476562f, 0.489746f, 0.502930f, 0.517578f, 0.531738f, 0.545410f, 0.559082f, 0.573730f,
+ 0.587402f, 0.602051f, 0.615723f, 0.629395f, 0.644043f, 0.658203f, 0.672363f, 0.686523f, 0.701660f, 0.714844f, 0.729980f, 0.743652f,
+ 0.758301f, 0.774414f, 0.862305f, 0.835449f, 0.813965f, 0.796875f, 0.782227f, 0.769043f, 0.005272f, 0.015427f, 0.026230f, 0.037506f,
+ 0.049164f, 0.060516f, 0.072021f, 0.083740f, 0.095825f, 0.108521f, 0.120361f, 0.132324f, 0.144897f, 0.156738f, 0.169922f, 0.182373f,
+ 0.195068f, 0.208008f, 0.220459f, 0.233887f, 0.246948f, 0.260254f, 0.272461f, 0.285889f, 0.299561f, 0.312500f, 0.325684f, 0.338867f,
+ 0.352783f, 0.365479f, 0.378906f, 0.392334f, 0.406006f, 0.419189f, 0.432861f, 0.446777f, 0.460693f, 0.473877f, 0.486572f, 0.500977f,
+ 0.515137f, 0.528809f, 0.542480f, 0.555176f, 0.569824f, 0.583984f, 0.597656f, 0.611328f, 0.625000f, 0.639648f, 0.653320f, 0.667480f,
+ 0.681641f, 0.695801f, 0.709961f, 0.723633f, 0.738281f, 0.752930f, 0.852539f, 0.827148f, 0.807129f, 0.790527f, 0.776367f, 0.764160f,
+ 0.004822f, 0.014885f, 0.025360f, 0.035767f, 0.046570f, 0.057587f, 0.068726f, 0.080139f, 0.091736f, 0.103577f, 0.115479f, 0.126709f,
+ 0.138672f, 0.150879f, 0.162231f, 0.174805f, 0.187622f, 0.199951f, 0.212524f, 0.224854f, 0.236694f, 0.249878f, 0.262207f, 0.275391f,
+ 0.287842f, 0.300293f, 0.313477f, 0.326904f, 0.340088f, 0.353027f, 0.365479f, 0.378174f, 0.391602f, 0.404541f, 0.417236f, 0.431641f,
+ 0.444336f, 0.457764f, 0.470703f, 0.484375f, 0.497803f, 0.510742f, 0.524902f, 0.537598f, 0.552246f, 0.564941f, 0.579590f, 0.592285f,
+ 0.606445f, 0.621094f, 0.634277f, 0.646973f, 0.662109f, 0.675781f, 0.689453f, 0.704102f, 0.718262f, 0.733398f, 0.842285f, 0.818848f,
+ 0.799805f, 0.784180f, 0.770996f, 0.758301f, 0.004745f, 0.014427f, 0.024277f, 0.034546f, 0.044800f, 0.055176f, 0.066040f, 0.076477f,
+ 0.087341f, 0.099060f, 0.110474f, 0.121216f, 0.132690f, 0.144165f, 0.156006f, 0.167358f, 0.179688f, 0.191284f, 0.203247f, 0.216187f,
+ 0.227905f, 0.239868f, 0.252441f, 0.264648f, 0.277100f, 0.289307f, 0.301270f, 0.314453f, 0.326660f, 0.338867f, 0.352539f, 0.364990f,
+ 0.377686f, 0.390137f, 0.403076f, 0.416016f, 0.428467f, 0.441406f, 0.453857f, 0.468262f, 0.480957f, 0.494385f, 0.507324f, 0.520020f,
+ 0.534180f, 0.547363f, 0.560059f, 0.573730f, 0.586914f, 0.601074f, 0.615234f, 0.628418f, 0.641602f, 0.656250f, 0.669434f, 0.683594f,
+ 0.697754f, 0.712402f, 0.832520f, 0.809570f, 0.792480f, 0.778320f, 0.764160f, 0.753906f, 0.004612f, 0.013840f, 0.023483f, 0.033081f,
+ 0.042999f, 0.052490f, 0.063049f, 0.073303f, 0.083801f, 0.094238f, 0.105042f, 0.115967f, 0.127319f, 0.138062f, 0.149048f, 0.160645f,
+ 0.171875f, 0.183228f, 0.194946f, 0.206665f, 0.218384f, 0.230347f, 0.241699f, 0.253906f, 0.265869f, 0.277832f, 0.290039f, 0.301758f,
+ 0.314209f, 0.326660f, 0.339111f, 0.351074f, 0.363281f, 0.375977f, 0.388428f, 0.401123f, 0.413330f, 0.426270f, 0.439453f, 0.451904f,
+ 0.464111f, 0.478027f, 0.489746f, 0.503418f, 0.515625f, 0.529297f, 0.542480f, 0.556152f, 0.569336f, 0.582031f, 0.595215f, 0.608887f,
+ 0.622559f, 0.636230f, 0.649902f, 0.663574f, 0.677246f, 0.691895f, 0.821289f, 0.802246f, 0.785645f, 0.771484f, 0.758789f, 0.748047f,
+ 0.004345f, 0.012985f, 0.022156f, 0.030884f, 0.040802f, 0.050568f, 0.060303f, 0.069946f, 0.079956f, 0.090393f, 0.100403f, 0.111084f,
+ 0.120667f, 0.131714f, 0.142700f, 0.153198f, 0.164429f, 0.175659f, 0.186523f, 0.197876f, 0.208496f, 0.220337f, 0.231567f, 0.243286f,
+ 0.254639f, 0.266113f, 0.277832f, 0.289795f, 0.301758f, 0.313477f, 0.325439f, 0.337402f, 0.349609f, 0.361328f, 0.373779f, 0.385986f,
+ 0.398193f, 0.410889f, 0.423340f, 0.435059f, 0.447998f, 0.460205f, 0.473389f, 0.486084f, 0.499023f, 0.511230f, 0.524414f, 0.537109f,
+ 0.549805f, 0.563477f, 0.576172f, 0.589355f, 0.603027f, 0.616699f, 0.629883f, 0.644531f, 0.658691f, 0.670898f, 0.811035f, 0.792969f,
+ 0.777832f, 0.764648f, 0.752441f, 0.742676f, 0.004002f, 0.012718f, 0.021210f, 0.029877f, 0.039246f, 0.048431f, 0.057281f, 0.067078f,
+ 0.076538f, 0.086121f, 0.096008f, 0.105957f, 0.115540f, 0.125732f, 0.136475f, 0.146729f, 0.157227f, 0.167236f, 0.177979f, 0.189819f,
+ 0.200195f, 0.210693f, 0.221802f, 0.232788f, 0.243896f, 0.255127f, 0.266602f, 0.278320f, 0.289062f, 0.300293f, 0.312012f, 0.323975f,
+ 0.335449f, 0.347168f, 0.359131f, 0.371094f, 0.382812f, 0.394775f, 0.406982f, 0.419434f, 0.431152f, 0.443604f, 0.455566f, 0.468506f,
+ 0.481445f, 0.493408f, 0.506348f, 0.519043f, 0.531738f, 0.544922f, 0.558105f, 0.570801f, 0.583984f, 0.597168f, 0.610352f, 0.624512f,
+ 0.637695f, 0.651855f, 0.800293f, 0.785156f, 0.770508f, 0.757812f, 0.747070f, 0.737305f, 0.003967f, 0.011940f, 0.020203f, 0.028931f,
+ 0.037109f, 0.045898f, 0.054840f, 0.063477f, 0.073059f, 0.082214f, 0.090942f, 0.100647f, 0.110535f, 0.120178f, 0.129639f, 0.139648f,
+ 0.149902f, 0.160156f, 0.170044f, 0.180786f, 0.190674f, 0.201416f, 0.211792f, 0.222412f, 0.233521f, 0.244751f, 0.255615f, 0.266113f,
+ 0.276855f, 0.288574f, 0.299561f, 0.311279f, 0.322266f, 0.333984f, 0.344727f, 0.356934f, 0.368164f, 0.379395f, 0.390869f, 0.403076f,
+ 0.415283f, 0.427246f, 0.439453f, 0.451172f, 0.464111f, 0.476807f, 0.488281f, 0.500977f, 0.513672f, 0.526367f, 0.538574f, 0.551758f,
+ 0.564453f, 0.577637f, 0.590820f, 0.604492f, 0.618164f, 0.631836f, 0.790039f, 0.775879f, 0.763184f, 0.750977f, 0.740723f, 0.731445f,
+ 0.003679f, 0.011749f, 0.019135f, 0.027237f, 0.035431f, 0.043884f, 0.052399f, 0.060577f, 0.069153f, 0.077881f, 0.086731f, 0.095947f,
+ 0.104797f, 0.114380f, 0.123535f, 0.133057f, 0.142700f, 0.152588f, 0.162231f, 0.171753f, 0.182129f, 0.192261f, 0.202026f, 0.212524f,
+ 0.222900f, 0.233643f, 0.243896f, 0.254395f, 0.264893f, 0.276123f, 0.286621f, 0.297119f, 0.308105f, 0.319336f, 0.331299f, 0.341553f,
+ 0.353027f, 0.364258f, 0.375977f, 0.387451f, 0.399414f, 0.410645f, 0.422607f, 0.434814f, 0.445801f, 0.458984f, 0.470703f, 0.482910f,
+ 0.495361f, 0.508301f, 0.520020f, 0.532227f, 0.545410f, 0.558594f, 0.570801f, 0.584961f, 0.597656f, 0.611816f, 0.778809f, 0.768066f,
+ 0.754883f, 0.743652f, 0.733887f, 0.725098f, 0.003525f, 0.010956f, 0.018433f, 0.026260f, 0.033295f, 0.041870f, 0.049377f, 0.057709f,
+ 0.065735f, 0.074463f, 0.082764f, 0.091736f, 0.099976f, 0.108582f, 0.118103f, 0.126465f, 0.135742f, 0.144775f, 0.154175f, 0.164307f,
+ 0.173218f, 0.182983f, 0.192505f, 0.202759f, 0.212646f, 0.221924f, 0.232910f, 0.242188f, 0.252930f, 0.262939f, 0.273926f, 0.284180f,
+ 0.294922f, 0.305420f, 0.316162f, 0.327637f, 0.338867f, 0.349609f, 0.361084f, 0.371826f, 0.382812f, 0.395020f, 0.406494f, 0.417725f,
+ 0.429688f, 0.441406f, 0.452637f, 0.465088f, 0.477783f, 0.489258f, 0.501953f, 0.514160f, 0.527344f, 0.539062f, 0.551758f, 0.564941f,
+ 0.578125f, 0.591797f, 0.768555f, 0.759277f, 0.748047f, 0.736816f, 0.728027f, 0.718750f, 0.003363f, 0.010353f, 0.017548f, 0.024765f,
+ 0.032196f, 0.039673f, 0.046936f, 0.054565f, 0.062561f, 0.070496f, 0.078308f, 0.086731f, 0.094910f, 0.103333f, 0.111633f, 0.120422f,
+ 0.129150f, 0.137695f, 0.146973f, 0.155762f, 0.164673f, 0.173950f, 0.183228f, 0.193359f, 0.201782f, 0.212036f, 0.221436f, 0.231323f,
+ 0.241699f, 0.251221f, 0.261719f, 0.271729f, 0.281494f, 0.291992f, 0.302734f, 0.312988f, 0.323730f, 0.334961f, 0.345459f, 0.357666f,
+ 0.367432f, 0.378662f, 0.389893f, 0.401855f, 0.412842f, 0.424316f, 0.435791f, 0.447266f, 0.459473f, 0.471436f, 0.482910f, 0.495605f,
+ 0.507324f, 0.520508f, 0.533203f, 0.545898f, 0.558594f, 0.570801f, 0.757812f, 0.750488f, 0.740234f, 0.729980f, 0.720703f, 0.712402f,
+ 0.003254f, 0.010048f, 0.016815f, 0.023453f, 0.030609f, 0.037537f, 0.044617f, 0.051971f, 0.059265f, 0.066833f, 0.074280f, 0.082153f,
+ 0.089905f, 0.097717f, 0.106018f, 0.113770f, 0.122131f, 0.131104f, 0.139282f, 0.147705f, 0.155762f, 0.165161f, 0.173950f, 0.183228f,
+ 0.192139f, 0.200928f, 0.210693f, 0.220093f, 0.229736f, 0.239258f, 0.248657f, 0.259277f, 0.268799f, 0.279053f, 0.288574f, 0.299561f,
+ 0.309814f, 0.319580f, 0.330322f, 0.340820f, 0.352783f, 0.362549f, 0.374023f, 0.385010f, 0.395752f, 0.407471f, 0.418701f, 0.429688f,
+ 0.441650f, 0.453125f, 0.465088f, 0.477539f, 0.489014f, 0.500977f, 0.513184f, 0.526855f, 0.539062f, 0.552246f, 0.747559f, 0.741699f,
+ 0.731934f, 0.722656f, 0.714355f, 0.707031f, 0.003345f, 0.009262f, 0.015900f, 0.022614f, 0.029282f, 0.035522f, 0.042633f, 0.048981f,
+ 0.056000f, 0.063110f, 0.070801f, 0.077454f, 0.084839f, 0.092590f, 0.100281f, 0.107849f, 0.116089f, 0.123169f, 0.131348f, 0.139648f,
+ 0.148193f, 0.156616f, 0.164795f, 0.173584f, 0.182617f, 0.191284f, 0.200073f, 0.208740f, 0.218140f, 0.227417f, 0.236694f, 0.246338f,
+ 0.255859f, 0.265381f, 0.275146f, 0.285889f, 0.294922f, 0.305420f, 0.315918f, 0.325928f, 0.336670f, 0.347412f, 0.358154f, 0.368652f,
+ 0.378662f, 0.390381f, 0.402100f, 0.412842f, 0.424316f, 0.435059f, 0.447021f, 0.458984f, 0.470459f, 0.482422f, 0.494873f, 0.508301f,
+ 0.520020f, 0.532227f, 0.737305f, 0.732910f, 0.723633f, 0.715820f, 0.708008f, 0.700195f, 0.003195f, 0.009010f, 0.015137f, 0.021225f,
+ 0.027466f, 0.033844f, 0.040161f, 0.046417f, 0.053497f, 0.059875f, 0.066711f, 0.073425f, 0.080505f, 0.087280f, 0.094788f, 0.102173f,
+ 0.109070f, 0.117004f, 0.124634f, 0.132446f, 0.139893f, 0.147705f, 0.155884f, 0.163940f, 0.172729f, 0.180908f, 0.189697f, 0.198242f,
+ 0.206665f, 0.215820f, 0.225220f, 0.233765f, 0.243408f, 0.251953f, 0.262207f, 0.271484f, 0.281494f, 0.291260f, 0.300537f, 0.311035f,
+ 0.320801f, 0.332520f, 0.341797f, 0.352051f, 0.362305f, 0.373535f, 0.384521f, 0.395264f, 0.406494f, 0.417480f, 0.429443f, 0.440430f,
+ 0.451904f, 0.463867f, 0.476074f, 0.487793f, 0.499268f, 0.513184f, 0.726562f, 0.723633f, 0.716309f, 0.708496f, 0.700684f, 0.694336f,
+ 0.002859f, 0.008507f, 0.014366f, 0.020203f, 0.026123f, 0.031891f, 0.038025f, 0.044281f, 0.050354f, 0.056519f, 0.062683f, 0.069275f,
+ 0.075195f, 0.082458f, 0.088806f, 0.095947f, 0.102783f, 0.110046f, 0.117065f, 0.124878f, 0.132080f, 0.139282f, 0.146851f, 0.154907f,
+ 0.162598f, 0.171265f, 0.178833f, 0.187500f, 0.195435f, 0.204590f, 0.213013f, 0.221680f, 0.231079f, 0.239502f, 0.248047f, 0.258301f,
+ 0.267334f, 0.277100f, 0.286133f, 0.296387f, 0.306641f, 0.316162f, 0.326416f, 0.336426f, 0.346924f, 0.357422f, 0.367188f, 0.378418f,
+ 0.389160f, 0.400391f, 0.411865f, 0.422852f, 0.433594f, 0.445557f, 0.457520f, 0.468994f, 0.481445f, 0.493408f, 0.715332f, 0.715332f,
+ 0.708984f, 0.700684f, 0.693848f, 0.687988f, 0.002701f, 0.008080f, 0.013718f, 0.019058f, 0.024582f, 0.030197f, 0.035675f, 0.041748f,
+ 0.047302f, 0.053589f, 0.059082f, 0.065308f, 0.071777f, 0.077576f, 0.084106f, 0.090332f, 0.097107f, 0.103577f, 0.110046f, 0.117493f,
+ 0.124146f, 0.131470f, 0.138550f, 0.145508f, 0.153564f, 0.161377f, 0.169067f, 0.176880f, 0.184814f, 0.192627f, 0.201294f, 0.209717f,
+ 0.218140f, 0.226929f, 0.235229f, 0.245117f, 0.253418f, 0.262939f, 0.272705f, 0.281738f, 0.290771f, 0.300781f, 0.310791f, 0.321289f,
+ 0.330566f, 0.341064f, 0.351562f, 0.361572f, 0.372559f, 0.382568f, 0.393066f, 0.405273f, 0.415771f, 0.426758f, 0.438721f, 0.450439f,
+ 0.461670f, 0.474121f, 0.704102f, 0.706543f, 0.700195f, 0.693359f, 0.687012f, 0.681152f, 0.002546f, 0.007771f, 0.012985f, 0.017975f,
+ 0.023392f, 0.028976f, 0.034180f, 0.039368f, 0.044556f, 0.050110f, 0.055847f, 0.061218f, 0.066895f, 0.072815f, 0.078674f, 0.085083f,
+ 0.091309f, 0.097168f, 0.103516f, 0.110107f, 0.116821f, 0.123413f, 0.130371f, 0.137329f, 0.144165f, 0.151733f, 0.158813f, 0.166382f,
+ 0.174438f, 0.182129f, 0.190063f, 0.197510f, 0.206055f, 0.214355f, 0.222778f, 0.231812f, 0.240723f, 0.249023f, 0.258789f, 0.267578f,
+ 0.276855f, 0.285889f, 0.295654f, 0.305420f, 0.315430f, 0.324463f, 0.334961f, 0.345215f, 0.354492f, 0.365234f, 0.376221f, 0.387451f,
+ 0.398926f, 0.409424f, 0.419678f, 0.432129f, 0.443848f, 0.455566f, 0.693848f, 0.697266f, 0.691895f, 0.686523f, 0.680176f, 0.674805f,
+ 0.002542f, 0.007271f, 0.012337f, 0.017181f, 0.021744f, 0.026840f, 0.031555f, 0.037231f, 0.042236f, 0.046906f, 0.051941f, 0.057709f,
+ 0.063049f, 0.068542f, 0.073853f, 0.079712f, 0.085266f, 0.091064f, 0.096985f, 0.103027f, 0.109009f, 0.115417f, 0.122192f, 0.128540f,
+ 0.135132f, 0.141846f, 0.148926f, 0.156250f, 0.163696f, 0.171387f, 0.178223f, 0.186035f, 0.194580f, 0.202271f, 0.210327f, 0.218994f,
+ 0.227173f, 0.235596f, 0.244385f, 0.252930f, 0.262451f, 0.271240f, 0.280762f, 0.290771f, 0.299805f, 0.309082f, 0.318359f, 0.329102f,
+ 0.338623f, 0.348633f, 0.358643f, 0.370117f, 0.379639f, 0.390869f, 0.401611f, 0.413330f, 0.425293f, 0.436523f, 0.682129f, 0.688477f,
+ 0.684082f, 0.678711f, 0.673340f, 0.667969f, 0.002300f, 0.007076f, 0.011505f, 0.016251f, 0.020401f, 0.025665f, 0.029816f, 0.034790f,
+ 0.039368f, 0.044159f, 0.048798f, 0.053955f, 0.059174f, 0.064148f, 0.069153f, 0.074463f, 0.079346f, 0.085266f, 0.090759f, 0.096191f,
+ 0.102112f, 0.108032f, 0.114075f, 0.120117f, 0.126587f, 0.133057f, 0.139648f, 0.146240f, 0.153442f, 0.160400f, 0.167725f, 0.174683f,
+ 0.182739f, 0.190308f, 0.198120f, 0.206177f, 0.214355f, 0.222656f, 0.230713f, 0.239258f, 0.248413f, 0.257080f, 0.265869f, 0.274658f,
+ 0.284424f, 0.292725f, 0.302490f, 0.313232f, 0.321777f, 0.331787f, 0.341797f, 0.352295f, 0.363281f, 0.373535f, 0.383545f, 0.395264f,
+ 0.405762f, 0.416992f, 0.671387f, 0.679688f, 0.675293f, 0.670898f, 0.666016f, 0.661133f, 0.002104f, 0.006474f, 0.010506f, 0.015099f,
+ 0.018875f, 0.023911f, 0.028534f, 0.032715f, 0.036652f, 0.041290f, 0.046021f, 0.050171f, 0.054535f, 0.059570f, 0.064575f, 0.069458f,
+ 0.074341f, 0.079346f, 0.084351f, 0.089844f, 0.095032f, 0.100830f, 0.106628f, 0.112122f, 0.117859f, 0.124084f, 0.130249f, 0.136841f,
+ 0.143188f, 0.149780f, 0.157349f, 0.163940f, 0.171021f, 0.178345f, 0.186279f, 0.193848f, 0.201172f, 0.209717f, 0.217529f, 0.225464f,
+ 0.233765f, 0.242676f, 0.251221f, 0.260254f, 0.268311f, 0.278076f, 0.287109f, 0.296143f, 0.305908f, 0.315674f, 0.325195f, 0.335449f,
+ 0.344971f, 0.355469f, 0.365967f, 0.377441f, 0.387939f, 0.398193f, 0.660645f, 0.670410f, 0.667969f, 0.663086f, 0.659180f, 0.654785f,
+ 0.002085f, 0.006306f, 0.010506f, 0.014107f, 0.018448f, 0.022293f, 0.026215f, 0.029953f, 0.034515f, 0.038391f, 0.042786f, 0.046844f,
+ 0.051361f, 0.055573f, 0.059784f, 0.064331f, 0.068970f, 0.073425f, 0.078430f, 0.083313f, 0.088318f, 0.093567f, 0.098816f, 0.104126f,
+ 0.109924f, 0.115662f, 0.121521f, 0.127197f, 0.133545f, 0.139771f, 0.146729f, 0.153076f, 0.160278f, 0.166992f, 0.174316f, 0.181274f,
+ 0.188965f, 0.196045f, 0.204468f, 0.212036f, 0.220459f, 0.228638f, 0.237183f, 0.245483f, 0.254150f, 0.262451f, 0.271484f, 0.281250f,
+ 0.290283f, 0.299561f, 0.308350f, 0.318115f, 0.328369f, 0.337158f, 0.349121f, 0.358887f, 0.370117f, 0.380615f, 0.649414f, 0.661133f,
+ 0.659668f, 0.655762f, 0.651855f, 0.647949f, 0.001922f, 0.005867f, 0.009399f, 0.013565f, 0.017380f, 0.020859f, 0.024551f, 0.028442f,
+ 0.032318f, 0.035980f, 0.039551f, 0.043488f, 0.047333f, 0.051239f, 0.055573f, 0.059875f, 0.063660f, 0.067810f, 0.072876f, 0.077087f,
+ 0.081726f, 0.086304f, 0.091370f, 0.096863f, 0.101746f, 0.107483f, 0.112732f, 0.117920f, 0.124329f, 0.130005f, 0.136108f, 0.142822f,
+ 0.149170f, 0.155396f, 0.162598f, 0.169434f, 0.176636f, 0.183838f, 0.191772f, 0.198975f, 0.206665f, 0.214478f, 0.222290f, 0.230835f,
+ 0.239258f, 0.247803f, 0.256836f, 0.264893f, 0.274414f, 0.283203f, 0.292725f, 0.301758f, 0.311035f, 0.321289f, 0.332275f, 0.340820f,
+ 0.351562f, 0.363037f, 0.637695f, 0.652832f, 0.651367f, 0.647949f, 0.644531f, 0.641602f, 0.002052f, 0.005253f, 0.009117f, 0.012482f,
+ 0.016113f, 0.019302f, 0.022842f, 0.026230f, 0.029831f, 0.033447f, 0.036682f, 0.040588f, 0.044189f, 0.047333f, 0.051178f, 0.055267f,
+ 0.058807f, 0.062683f, 0.067200f, 0.070984f, 0.075195f, 0.079895f, 0.084534f, 0.088806f, 0.093933f, 0.098999f, 0.104309f, 0.109619f,
+ 0.114807f, 0.120422f, 0.126587f, 0.132080f, 0.138550f, 0.144775f, 0.151245f, 0.157837f, 0.164551f, 0.171387f, 0.178467f, 0.186157f,
+ 0.193359f, 0.201294f, 0.208740f, 0.216797f, 0.224854f, 0.233398f, 0.241211f, 0.250000f, 0.258545f, 0.267822f, 0.276855f, 0.286133f,
+ 0.295410f, 0.304932f, 0.314697f, 0.324463f, 0.334229f, 0.344238f, 0.626953f, 0.642578f, 0.643066f, 0.641113f, 0.637695f, 0.634277f,
+ 0.001711f, 0.005424f, 0.008347f, 0.012024f, 0.014977f, 0.018066f, 0.021500f, 0.024399f, 0.027756f, 0.030869f, 0.034058f, 0.037048f,
+ 0.040558f, 0.044006f, 0.046906f, 0.050690f, 0.054169f, 0.057983f, 0.061584f, 0.065247f, 0.069336f, 0.073425f, 0.077576f, 0.082092f,
+ 0.086670f, 0.091064f, 0.095886f, 0.101196f, 0.105957f, 0.111267f, 0.116943f, 0.122559f, 0.128174f, 0.133789f, 0.140259f, 0.146118f,
+ 0.153076f, 0.159424f, 0.166016f, 0.173462f, 0.180542f, 0.187744f, 0.195435f, 0.203003f, 0.209961f, 0.218994f, 0.226562f, 0.234619f,
+ 0.243286f, 0.251709f, 0.260742f, 0.269531f, 0.277832f, 0.287354f, 0.297363f, 0.306885f, 0.316406f, 0.326660f, 0.615234f, 0.633789f,
+ 0.634277f, 0.632812f, 0.630371f, 0.626953f, 0.001721f, 0.004829f, 0.008034f, 0.010857f, 0.013893f, 0.016953f, 0.019806f, 0.022705f,
+ 0.025589f, 0.028793f, 0.031616f, 0.034180f, 0.036926f, 0.039978f, 0.043213f, 0.046356f, 0.049744f, 0.052887f, 0.056305f, 0.059906f,
+ 0.063416f, 0.067322f, 0.070862f, 0.075134f, 0.079285f, 0.083435f, 0.088074f, 0.092712f, 0.097534f, 0.102173f, 0.107544f, 0.112305f,
+ 0.118225f, 0.123657f, 0.129272f, 0.135376f, 0.141602f, 0.147705f, 0.153931f, 0.160889f, 0.167847f, 0.174683f, 0.181885f, 0.189209f,
+ 0.196533f, 0.204224f, 0.212524f, 0.219727f, 0.228271f, 0.236572f, 0.245483f, 0.253418f, 0.261719f, 0.270996f, 0.280029f, 0.289307f,
+ 0.300537f, 0.309326f, 0.604004f, 0.625000f, 0.626953f, 0.625000f, 0.622559f, 0.620117f, 0.001624f, 0.004730f, 0.007412f, 0.010300f,
+ 0.013199f, 0.015717f, 0.018448f, 0.020935f, 0.023163f, 0.026138f, 0.028687f, 0.031204f, 0.033875f, 0.036743f, 0.039825f, 0.042389f,
+ 0.045166f, 0.048523f, 0.051422f, 0.054535f, 0.057953f, 0.061249f, 0.064880f, 0.068542f, 0.072388f, 0.076355f, 0.080505f, 0.084534f,
+ 0.089294f, 0.093750f, 0.098389f, 0.103210f, 0.108337f, 0.113647f, 0.118896f, 0.124817f, 0.130737f, 0.135986f, 0.142212f, 0.148560f,
+ 0.155151f, 0.162109f, 0.168579f, 0.175415f, 0.183105f, 0.190552f, 0.197998f, 0.205322f, 0.213623f, 0.221436f, 0.229370f, 0.237915f,
+ 0.246216f, 0.254883f, 0.264160f, 0.273438f, 0.282471f, 0.292236f, 0.593262f, 0.615723f, 0.618164f, 0.617188f, 0.615234f, 0.612793f,
+ 0.001355f, 0.004463f, 0.007061f, 0.009506f, 0.011612f, 0.014381f, 0.016830f, 0.019394f, 0.021576f, 0.023697f, 0.026428f, 0.028778f,
+ 0.030975f, 0.033386f, 0.035950f, 0.038513f, 0.041260f, 0.044067f, 0.046967f, 0.049622f, 0.052612f, 0.055847f, 0.059052f, 0.062164f,
+ 0.065918f, 0.069397f, 0.073242f, 0.077271f, 0.081055f, 0.085327f, 0.089661f, 0.094177f, 0.098877f, 0.103455f, 0.108582f, 0.113647f,
+ 0.119812f, 0.125000f, 0.130981f, 0.137085f, 0.142944f, 0.149414f, 0.156006f, 0.162354f, 0.169434f, 0.176514f, 0.183716f, 0.191284f,
+ 0.198975f, 0.206421f, 0.214844f, 0.222412f, 0.231323f, 0.238647f, 0.247437f, 0.256592f, 0.265625f, 0.276367f, 0.581055f, 0.606445f,
+ 0.609863f, 0.608887f, 0.607910f, 0.606445f, 0.001413f, 0.004128f, 0.006180f, 0.008781f, 0.010994f, 0.013496f, 0.015427f, 0.017654f,
+ 0.019684f, 0.021881f, 0.024139f, 0.025879f, 0.028137f, 0.030334f, 0.032471f, 0.034821f, 0.037354f, 0.039642f, 0.042236f, 0.044708f,
+ 0.047394f, 0.050079f, 0.053223f, 0.056244f, 0.059479f, 0.062622f, 0.066223f, 0.069946f, 0.073608f, 0.077209f, 0.081604f, 0.085632f,
+ 0.089722f, 0.094360f, 0.098999f, 0.103943f, 0.108826f, 0.114319f, 0.119568f, 0.125122f, 0.131104f, 0.137085f, 0.143433f, 0.150024f,
+ 0.156494f, 0.163330f, 0.170044f, 0.177490f, 0.184326f, 0.191895f, 0.199707f, 0.207764f, 0.215698f, 0.223755f, 0.231812f, 0.240845f,
+ 0.249756f, 0.258789f, 0.568848f, 0.598145f, 0.601562f, 0.600586f, 0.600586f, 0.599121f, 0.001182f, 0.003773f, 0.005970f, 0.008293f,
+ 0.010277f, 0.012512f, 0.014030f, 0.016129f, 0.017929f, 0.019791f, 0.021683f, 0.023590f, 0.025452f, 0.027328f, 0.029404f, 0.031677f,
+ 0.033539f, 0.035583f, 0.037903f, 0.040314f, 0.042877f, 0.045319f, 0.048126f, 0.050690f, 0.053436f, 0.056519f, 0.059723f, 0.062744f,
+ 0.066284f, 0.069702f, 0.073608f, 0.077209f, 0.081055f, 0.085754f, 0.089783f, 0.094421f, 0.099060f, 0.103821f, 0.109192f, 0.114563f,
+ 0.119934f, 0.125488f, 0.131104f, 0.137695f, 0.144043f, 0.149780f, 0.156738f, 0.163940f, 0.170654f, 0.177856f, 0.185181f, 0.192871f,
+ 0.200439f, 0.208740f, 0.216675f, 0.225342f, 0.233521f, 0.242554f, 0.557617f, 0.587891f, 0.592285f, 0.592773f, 0.592285f, 0.592285f,
+ 0.001198f, 0.003677f, 0.005547f, 0.007561f, 0.009468f, 0.011253f, 0.012833f, 0.014465f, 0.016205f, 0.017792f, 0.019394f, 0.021240f,
+ 0.022751f, 0.024475f, 0.026260f, 0.028015f, 0.030136f, 0.031708f, 0.034088f, 0.036102f, 0.038361f, 0.040497f, 0.042816f, 0.045288f,
+ 0.047882f, 0.050476f, 0.053284f, 0.056183f, 0.059174f, 0.062500f, 0.065796f, 0.069153f, 0.072998f, 0.076904f, 0.080994f, 0.085083f,
+ 0.089478f, 0.094116f, 0.098633f, 0.103394f, 0.108704f, 0.113953f, 0.119934f, 0.125366f, 0.131348f, 0.137329f, 0.143555f, 0.150391f,
+ 0.157227f, 0.163818f, 0.170776f, 0.178467f, 0.185791f, 0.193359f, 0.201538f, 0.209717f, 0.218018f, 0.226807f, 0.544922f, 0.578613f,
+ 0.583984f, 0.584961f, 0.585449f, 0.584473f, 0.001067f, 0.003101f, 0.004974f, 0.006855f, 0.008522f, 0.009949f, 0.011635f, 0.012985f,
+ 0.014595f, 0.016052f, 0.017685f, 0.019012f, 0.020264f, 0.021851f, 0.023346f, 0.025146f, 0.026688f, 0.028336f, 0.030304f, 0.031860f,
+ 0.034119f, 0.035889f, 0.038025f, 0.040283f, 0.042450f, 0.044952f, 0.047302f, 0.050049f, 0.052765f, 0.055908f, 0.058594f, 0.061859f,
+ 0.064880f, 0.068481f, 0.072327f, 0.076172f, 0.080200f, 0.084290f, 0.088684f, 0.093262f, 0.098145f, 0.102905f, 0.108337f, 0.113708f,
+ 0.119080f, 0.125000f, 0.131348f, 0.137329f, 0.143921f, 0.150391f, 0.157593f, 0.164551f, 0.171753f, 0.179077f, 0.186768f, 0.194702f,
+ 0.203003f, 0.210815f, 0.534180f, 0.569336f, 0.575684f, 0.577637f, 0.577637f, 0.577148f, 0.001196f, 0.003178f, 0.004601f, 0.006241f,
+ 0.007782f, 0.009262f, 0.010391f, 0.011795f, 0.012955f, 0.014198f, 0.015518f, 0.016785f, 0.018097f, 0.019409f, 0.020782f, 0.022247f,
+ 0.023544f, 0.025269f, 0.026749f, 0.028152f, 0.030045f, 0.031555f, 0.033630f, 0.035645f, 0.037567f, 0.039642f, 0.041992f, 0.044281f,
+ 0.046692f, 0.049042f, 0.052094f, 0.054779f, 0.057831f, 0.060760f, 0.064209f, 0.067627f, 0.071228f, 0.075256f, 0.079224f, 0.083557f,
+ 0.087891f, 0.092468f, 0.097168f, 0.102356f, 0.107605f, 0.113098f, 0.119019f, 0.124878f, 0.130859f, 0.137451f, 0.144287f, 0.150635f,
+ 0.157471f, 0.164917f, 0.171997f, 0.179932f, 0.187378f, 0.196899f, 0.521973f, 0.560547f, 0.566895f, 0.569824f, 0.570312f, 0.568848f,
+ 0.001242f, 0.002674f, 0.004421f, 0.005573f, 0.006882f, 0.008354f, 0.009491f, 0.010559f, 0.011406f, 0.012695f, 0.013893f, 0.014908f,
+ 0.015854f, 0.017044f, 0.018234f, 0.019501f, 0.020752f, 0.022003f, 0.023254f, 0.024689f, 0.026154f, 0.027802f, 0.029434f, 0.031113f,
+ 0.032898f, 0.034668f, 0.036774f, 0.038910f, 0.040802f, 0.043030f, 0.045593f, 0.048065f, 0.050873f, 0.053680f, 0.056458f, 0.059692f,
+ 0.062866f, 0.066467f, 0.069946f, 0.074036f, 0.077942f, 0.082275f, 0.086731f, 0.091614f, 0.096313f, 0.101562f, 0.106934f, 0.112671f,
+ 0.118591f, 0.124634f, 0.130859f, 0.137207f, 0.144043f, 0.151123f, 0.157593f, 0.165283f, 0.173218f, 0.180664f, 0.510254f, 0.550781f,
+ 0.558105f, 0.561035f, 0.562012f, 0.562012f, 0.000842f, 0.002552f, 0.003769f, 0.005333f, 0.006149f, 0.007298f, 0.008362f, 0.009224f,
+ 0.010254f, 0.011230f, 0.012108f, 0.013092f, 0.014000f, 0.014992f, 0.016006f, 0.016953f, 0.017990f, 0.019196f, 0.020142f, 0.021622f,
+ 0.022827f, 0.024216f, 0.025513f, 0.026993f, 0.028564f, 0.030212f, 0.032013f, 0.033813f, 0.035706f, 0.037598f, 0.039703f, 0.041840f,
+ 0.044159f, 0.046539f, 0.049347f, 0.052155f, 0.055084f, 0.058228f, 0.061554f, 0.065002f, 0.068909f, 0.072693f, 0.076599f, 0.081238f,
+ 0.085388f, 0.090515f, 0.095764f, 0.100891f, 0.106689f, 0.112366f, 0.118103f, 0.124634f, 0.130859f, 0.137573f, 0.144287f, 0.151855f,
+ 0.158447f, 0.166260f, 0.498535f, 0.541992f, 0.549805f, 0.553711f, 0.554199f, 0.554688f, 0.000874f, 0.002186f, 0.003445f, 0.004807f,
+ 0.005562f, 0.006607f, 0.007378f, 0.008102f, 0.008919f, 0.009666f, 0.010513f, 0.011131f, 0.012039f, 0.012848f, 0.013779f, 0.014671f,
+ 0.015465f, 0.016464f, 0.017517f, 0.018585f, 0.019730f, 0.020798f, 0.022018f, 0.023300f, 0.024612f, 0.026093f, 0.027374f, 0.029022f,
+ 0.030624f, 0.032440f, 0.034180f, 0.036285f, 0.038116f, 0.040344f, 0.042725f, 0.045349f, 0.047913f, 0.050476f, 0.053406f, 0.056488f,
+ 0.059998f, 0.063354f, 0.067383f, 0.071289f, 0.075562f, 0.079834f, 0.084656f, 0.089478f, 0.094849f, 0.100342f, 0.106140f, 0.111877f,
+ 0.118042f, 0.124573f, 0.130981f, 0.137451f, 0.144653f, 0.152588f, 0.486816f, 0.531738f, 0.541016f, 0.545410f, 0.547363f, 0.546875f,
+ 0.000667f, 0.002001f, 0.003244f, 0.003895f, 0.004936f, 0.005608f, 0.006477f, 0.006901f, 0.007648f, 0.008354f, 0.009132f, 0.009766f,
+ 0.010490f, 0.011177f, 0.011780f, 0.012543f, 0.013420f, 0.014084f, 0.015045f, 0.015961f, 0.016876f, 0.017822f, 0.018768f, 0.019958f,
+ 0.021255f, 0.022232f, 0.023560f, 0.024780f, 0.026108f, 0.027634f, 0.029221f, 0.030762f, 0.032684f, 0.034576f, 0.036621f, 0.038605f,
+ 0.040985f, 0.043488f, 0.046021f, 0.049042f, 0.051727f, 0.054901f, 0.058441f, 0.061981f, 0.065552f, 0.069885f, 0.074097f, 0.078857f,
+ 0.083923f, 0.088623f, 0.094360f, 0.099854f, 0.105957f, 0.111694f, 0.118164f, 0.124817f, 0.131836f, 0.138794f, 0.474365f, 0.522949f,
+ 0.532227f, 0.536621f, 0.538574f, 0.539062f, 0.000876f, 0.002020f, 0.002857f, 0.003855f, 0.004436f, 0.005009f, 0.005482f, 0.006130f,
+ 0.006588f, 0.007084f, 0.007656f, 0.008286f, 0.008949f, 0.009506f, 0.010025f, 0.010803f, 0.011444f, 0.012047f, 0.012802f, 0.013512f,
+ 0.014305f, 0.015282f, 0.016052f, 0.016846f, 0.017914f, 0.018829f, 0.019882f, 0.021027f, 0.022232f, 0.023453f, 0.024689f, 0.026169f,
+ 0.027573f, 0.029327f, 0.031036f, 0.032806f, 0.034882f, 0.036743f, 0.039032f, 0.041626f, 0.044312f, 0.046936f, 0.050018f, 0.053253f,
+ 0.056610f, 0.060272f, 0.064392f, 0.068542f, 0.072937f, 0.078003f, 0.082886f, 0.088318f, 0.093933f, 0.099670f, 0.106140f, 0.112000f,
+ 0.118713f, 0.125732f, 0.463135f, 0.513672f, 0.524414f, 0.528809f, 0.530762f, 0.532227f, 0.000573f, 0.001698f, 0.002670f, 0.003082f,
+ 0.003735f, 0.004318f, 0.004673f, 0.005161f, 0.005779f, 0.006203f, 0.006565f, 0.007015f, 0.007591f, 0.007965f, 0.008583f, 0.009094f,
+ 0.009491f, 0.010239f, 0.010780f, 0.011353f, 0.012047f, 0.012787f, 0.013504f, 0.014206f, 0.015060f, 0.015915f, 0.016708f, 0.017685f,
+ 0.018677f, 0.019653f, 0.020828f, 0.021866f, 0.023224f, 0.024445f, 0.025818f, 0.027557f, 0.029114f, 0.030991f, 0.032928f, 0.035034f,
+ 0.037201f, 0.039581f, 0.042328f, 0.045166f, 0.048157f, 0.051392f, 0.054962f, 0.058685f, 0.062988f, 0.067444f, 0.072021f, 0.077148f,
+ 0.082520f, 0.088196f, 0.093750f, 0.100403f, 0.106201f, 0.112976f, 0.450928f, 0.503906f, 0.515137f, 0.520020f, 0.522949f, 0.524414f,
+ 0.000643f, 0.001637f, 0.002197f, 0.002800f, 0.003376f, 0.003613f, 0.003914f, 0.004391f, 0.004742f, 0.005150f, 0.005466f, 0.005924f,
+ 0.006344f, 0.006645f, 0.007046f, 0.007591f, 0.008118f, 0.008560f, 0.008934f, 0.009529f, 0.010147f, 0.010651f, 0.011276f, 0.011787f,
+ 0.012543f, 0.013229f, 0.013916f, 0.014740f, 0.015564f, 0.016388f, 0.017258f, 0.018188f, 0.019257f, 0.020355f, 0.021729f, 0.022766f,
+ 0.024277f, 0.025696f, 0.027237f, 0.029022f, 0.030945f, 0.033020f, 0.035248f, 0.037689f, 0.040405f, 0.043182f, 0.046295f, 0.049866f,
+ 0.053528f, 0.057526f, 0.061920f, 0.066284f, 0.071716f, 0.077209f, 0.082703f, 0.088196f, 0.094177f, 0.101074f, 0.438965f, 0.494629f,
+ 0.507324f, 0.512207f, 0.515137f, 0.516113f, 0.000484f, 0.001272f, 0.001968f, 0.002327f, 0.002573f, 0.003054f, 0.003338f, 0.003660f,
+ 0.003906f, 0.004303f, 0.004658f, 0.004921f, 0.005222f, 0.005547f, 0.005878f, 0.006290f, 0.006542f, 0.007015f, 0.007442f, 0.007851f,
+ 0.008339f, 0.008713f, 0.009247f, 0.009811f, 0.010345f, 0.010849f, 0.011490f, 0.012123f, 0.012733f, 0.013428f, 0.014183f, 0.014961f,
+ 0.015839f, 0.016815f, 0.017731f, 0.018768f, 0.019821f, 0.021072f, 0.022385f, 0.023727f, 0.025345f, 0.027084f, 0.028946f, 0.030914f,
+ 0.033295f, 0.035614f, 0.038513f, 0.041473f, 0.044678f, 0.048462f, 0.052338f, 0.056671f, 0.061310f, 0.066101f, 0.071533f, 0.077148f,
+ 0.083069f, 0.089172f, 0.427246f, 0.485352f, 0.498535f, 0.503906f, 0.508301f, 0.509766f, 0.000416f, 0.001121f, 0.001410f, 0.001959f,
+ 0.002159f, 0.002558f, 0.002724f, 0.002939f, 0.003220f, 0.003447f, 0.003733f, 0.003944f, 0.004219f, 0.004578f, 0.004810f, 0.005100f,
+ 0.005402f, 0.005783f, 0.006077f, 0.006382f, 0.006729f, 0.007141f, 0.007526f, 0.007965f, 0.008354f, 0.008858f, 0.009300f, 0.009789f,
+ 0.010452f, 0.010986f, 0.011658f, 0.012131f, 0.012833f, 0.013702f, 0.014435f, 0.015266f, 0.016113f, 0.017136f, 0.018143f, 0.019241f,
+ 0.020493f, 0.021820f, 0.023346f, 0.025085f, 0.027023f, 0.028976f, 0.031174f, 0.033966f, 0.036743f, 0.039856f, 0.043396f, 0.047180f,
+ 0.051605f, 0.056152f, 0.061127f, 0.066284f, 0.072021f, 0.078247f, 0.415283f, 0.475586f, 0.490234f, 0.496338f, 0.499756f, 0.501953f,
+ 0.000493f, 0.001126f, 0.001391f, 0.001574f, 0.001786f, 0.002073f, 0.002188f, 0.002417f, 0.002657f, 0.002785f, 0.002964f, 0.003189f,
+ 0.003384f, 0.003687f, 0.003859f, 0.004124f, 0.004330f, 0.004555f, 0.004890f, 0.005119f, 0.005451f, 0.005749f, 0.006054f, 0.006348f,
+ 0.006683f, 0.007050f, 0.007458f, 0.007889f, 0.008339f, 0.008751f, 0.009323f, 0.009766f, 0.010353f, 0.010887f, 0.011520f, 0.012192f,
+ 0.012932f, 0.013748f, 0.014542f, 0.015434f, 0.016434f, 0.017471f, 0.018723f, 0.019989f, 0.021500f, 0.023117f, 0.024948f, 0.027100f,
+ 0.029770f, 0.032166f, 0.035248f, 0.038696f, 0.042633f, 0.046875f, 0.051605f, 0.056427f, 0.061859f, 0.067688f, 0.403320f, 0.467041f,
+ 0.480957f, 0.487793f, 0.491699f, 0.494385f, 0.000336f, 0.000673f, 0.001150f, 0.001274f, 0.001482f, 0.001630f, 0.001748f, 0.001904f,
+ 0.002087f, 0.002232f, 0.002306f, 0.002497f, 0.002672f, 0.002872f, 0.003092f, 0.003225f, 0.003387f, 0.003553f, 0.003819f, 0.003979f,
+ 0.004230f, 0.004517f, 0.004738f, 0.005016f, 0.005322f, 0.005569f, 0.005848f, 0.006184f, 0.006573f, 0.006851f, 0.007271f, 0.007660f,
+ 0.008064f, 0.008568f, 0.009048f, 0.009567f, 0.010139f, 0.010788f, 0.011391f, 0.012161f, 0.012939f, 0.013763f, 0.014694f, 0.015717f,
+ 0.016815f, 0.018097f, 0.019714f, 0.021149f, 0.023270f, 0.025421f, 0.028015f, 0.030991f, 0.034271f, 0.038116f, 0.042328f, 0.046997f,
+ 0.052094f, 0.057770f, 0.391113f, 0.457031f, 0.472412f, 0.479736f, 0.484375f, 0.486816f, 0.000309f, 0.000612f, 0.000953f, 0.001086f,
+ 0.001191f, 0.001281f, 0.001351f, 0.001442f, 0.001610f, 0.001733f, 0.001783f, 0.001991f, 0.002087f, 0.002232f, 0.002337f, 0.002495f,
+ 0.002611f, 0.002775f, 0.002935f, 0.003101f, 0.003302f, 0.003496f, 0.003622f, 0.003839f, 0.004047f, 0.004265f, 0.004494f, 0.004738f,
+ 0.005039f, 0.005272f, 0.005650f, 0.005898f, 0.006210f, 0.006588f, 0.006950f, 0.007332f, 0.007782f, 0.008240f, 0.008766f, 0.009331f,
+ 0.009964f, 0.010612f, 0.011314f, 0.012062f, 0.013023f, 0.014038f, 0.015007f, 0.016251f, 0.017761f, 0.019501f, 0.021530f, 0.023926f,
+ 0.026718f, 0.030106f, 0.033905f, 0.038361f, 0.043060f, 0.048370f, 0.379395f, 0.446777f, 0.464111f, 0.471191f, 0.475586f, 0.479492f,
+ 0.000439f, 0.000476f, 0.000672f, 0.000752f, 0.000810f, 0.000949f, 0.001011f, 0.001121f, 0.001160f, 0.001249f, 0.001408f, 0.001493f,
+ 0.001591f, 0.001719f, 0.001788f, 0.001845f, 0.001982f, 0.002106f, 0.002201f, 0.002357f, 0.002460f, 0.002598f, 0.002724f, 0.002869f,
+ 0.003036f, 0.003187f, 0.003397f, 0.003569f, 0.003763f, 0.004017f, 0.004211f, 0.004414f, 0.004704f, 0.004890f, 0.005234f, 0.005524f,
+ 0.005825f, 0.006187f, 0.006535f, 0.006977f, 0.007423f, 0.007874f, 0.008553f, 0.009079f, 0.009857f, 0.010567f, 0.011360f, 0.012306f,
+ 0.013390f, 0.014702f, 0.016220f, 0.017960f, 0.020157f, 0.022995f, 0.026352f, 0.030212f, 0.034790f, 0.039459f, 0.368408f, 0.437744f,
+ 0.455322f, 0.463379f, 0.468018f, 0.471436f, 0.000202f, 0.000437f, 0.000488f, 0.000579f, 0.000664f, 0.000692f, 0.000792f, 0.000762f,
+ 0.000875f, 0.000949f, 0.001038f, 0.001068f, 0.001116f, 0.001196f, 0.001300f, 0.001352f, 0.001458f, 0.001529f, 0.001623f, 0.001667f,
+ 0.001770f, 0.001884f, 0.001989f, 0.002071f, 0.002203f, 0.002310f, 0.002445f, 0.002556f, 0.002680f, 0.002876f, 0.002991f, 0.003206f,
+ 0.003365f, 0.003531f, 0.003759f, 0.003956f, 0.004227f, 0.004513f, 0.004768f, 0.005074f, 0.005402f, 0.005756f, 0.006142f, 0.006603f,
+ 0.007160f, 0.007645f, 0.008339f, 0.008987f, 0.009819f, 0.010780f, 0.011803f, 0.013153f, 0.014763f, 0.016876f, 0.019623f, 0.022995f,
+ 0.026978f, 0.031708f, 0.356445f, 0.428223f, 0.446533f, 0.455078f, 0.460449f, 0.463379f, 0.000126f, 0.000241f, 0.000344f, 0.000353f,
+ 0.000437f, 0.000522f, 0.000513f, 0.000552f, 0.000613f, 0.000699f, 0.000717f, 0.000727f, 0.000763f, 0.000848f, 0.000877f, 0.000956f,
+ 0.000963f, 0.001068f, 0.001128f, 0.001170f, 0.001238f, 0.001311f, 0.001385f, 0.001454f, 0.001534f, 0.001603f, 0.001714f, 0.001779f,
+ 0.001885f, 0.002016f, 0.002092f, 0.002214f, 0.002331f, 0.002460f, 0.002613f, 0.002777f, 0.002924f, 0.003120f, 0.003298f, 0.003496f,
+ 0.003708f, 0.004009f, 0.004292f, 0.004601f, 0.004951f, 0.005341f, 0.005772f, 0.006260f, 0.006901f, 0.007572f, 0.008324f, 0.009300f,
+ 0.010445f, 0.011848f, 0.013870f, 0.016678f, 0.020218f, 0.024536f, 0.345703f, 0.419189f, 0.437500f, 0.447021f, 0.452393f, 0.455811f,
+ 0.000146f, 0.000240f, 0.000268f, 0.000268f, 0.000310f, 0.000311f, 0.000331f, 0.000366f, 0.000410f, 0.000447f, 0.000446f, 0.000517f,
+ 0.000511f, 0.000571f, 0.000596f, 0.000618f, 0.000674f, 0.000691f, 0.000723f, 0.000762f, 0.000822f, 0.000856f, 0.000912f, 0.000950f,
+ 0.001014f, 0.001049f, 0.001128f, 0.001188f, 0.001237f, 0.001303f, 0.001371f, 0.001466f, 0.001532f, 0.001623f, 0.001701f, 0.001805f,
+ 0.001945f, 0.002035f, 0.002186f, 0.002329f, 0.002460f, 0.002632f, 0.002819f, 0.003012f, 0.003271f, 0.003550f, 0.003819f, 0.004162f,
+ 0.004539f, 0.005024f, 0.005585f, 0.006233f, 0.007050f, 0.008072f, 0.009331f, 0.011269f, 0.014160f, 0.018112f, 0.333740f, 0.408447f,
+ 0.428711f, 0.438232f, 0.443359f, 0.447510f, 0.000053f, 0.000163f, 0.000155f, 0.000160f, 0.000191f, 0.000228f, 0.000206f, 0.000233f,
+ 0.000248f, 0.000263f, 0.000267f, 0.000294f, 0.000324f, 0.000335f, 0.000364f, 0.000378f, 0.000396f, 0.000435f, 0.000445f, 0.000490f,
+ 0.000502f, 0.000522f, 0.000543f, 0.000582f, 0.000619f, 0.000665f, 0.000679f, 0.000705f, 0.000755f, 0.000797f, 0.000856f, 0.000887f,
+ 0.000953f, 0.000988f, 0.001043f, 0.001103f, 0.001177f, 0.001256f, 0.001331f, 0.001410f, 0.001508f, 0.001612f, 0.001734f, 0.001873f,
+ 0.001999f, 0.002163f, 0.002378f, 0.002565f, 0.002827f, 0.003119f, 0.003479f, 0.003899f, 0.004463f, 0.005116f, 0.005951f, 0.007153f,
+ 0.009163f, 0.012535f, 0.322510f, 0.400146f, 0.420654f, 0.430176f, 0.436523f, 0.440430f, 0.000097f, 0.000107f, 0.000095f, 0.000087f,
+ 0.000107f, 0.000110f, 0.000137f, 0.000139f, 0.000140f, 0.000147f, 0.000168f, 0.000175f, 0.000177f, 0.000184f, 0.000210f, 0.000200f,
+ 0.000224f, 0.000239f, 0.000246f, 0.000258f, 0.000278f, 0.000288f, 0.000312f, 0.000324f, 0.000347f, 0.000368f, 0.000382f, 0.000395f,
+ 0.000418f, 0.000440f, 0.000471f, 0.000495f, 0.000521f, 0.000547f, 0.000577f, 0.000620f, 0.000649f, 0.000695f, 0.000749f, 0.000785f,
+ 0.000838f, 0.000897f, 0.000972f, 0.001028f, 0.001118f, 0.001204f, 0.001316f, 0.001432f, 0.001580f, 0.001748f, 0.001961f, 0.002207f,
+ 0.002533f, 0.002941f, 0.003487f, 0.004223f, 0.005371f, 0.007809f, 0.311523f, 0.390381f, 0.411377f, 0.421875f, 0.428467f, 0.432617f,
+ 0.000000f, 0.000055f, 0.000046f, 0.000054f, 0.000060f, 0.000058f, 0.000060f, 0.000068f, 0.000068f, 0.000082f, 0.000076f, 0.000078f,
+ 0.000092f, 0.000087f, 0.000091f, 0.000097f, 0.000105f, 0.000115f, 0.000118f, 0.000124f, 0.000128f, 0.000133f, 0.000139f, 0.000154f,
+ 0.000160f, 0.000172f, 0.000175f, 0.000191f, 0.000201f, 0.000211f, 0.000221f, 0.000238f, 0.000242f, 0.000257f, 0.000277f, 0.000295f,
+ 0.000309f, 0.000326f, 0.000351f, 0.000375f, 0.000400f, 0.000428f, 0.000459f, 0.000490f, 0.000535f, 0.000579f, 0.000626f, 0.000683f,
+ 0.000754f, 0.000836f, 0.000952f, 0.001064f, 0.001237f, 0.001460f, 0.001751f, 0.002157f, 0.002800f, 0.004189f, 0.299561f, 0.380127f,
+ 0.403076f, 0.413574f, 0.419922f, 0.424072f, 0.000059f, 0.000039f, 0.000032f, 0.000028f, 0.000025f, 0.000025f, 0.000025f, 0.000024f,
+ 0.000023f, 0.000024f, 0.000026f, 0.000034f, 0.000029f, 0.000031f, 0.000038f, 0.000040f, 0.000042f, 0.000043f, 0.000042f, 0.000043f,
+ 0.000048f, 0.000054f, 0.000058f, 0.000056f, 0.000060f, 0.000062f, 0.000066f, 0.000069f, 0.000072f, 0.000078f, 0.000082f, 0.000085f,
+ 0.000093f, 0.000096f, 0.000099f, 0.000106f, 0.000116f, 0.000123f, 0.000132f, 0.000140f, 0.000150f, 0.000154f, 0.000167f, 0.000184f,
+ 0.000192f, 0.000212f, 0.000231f, 0.000251f, 0.000282f, 0.000314f, 0.000350f, 0.000401f, 0.000463f, 0.000554f, 0.000679f, 0.000861f,
+ 0.001157f, 0.001750f, 0.289307f, 0.371582f, 0.394043f, 0.406006f, 0.412109f, 0.417236f, 0.000031f, 0.000020f, 0.000016f, 0.000014f,
+ 0.000013f, 0.000012f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000008f, 0.000008f, 0.000009f,
+ 0.000009f, 0.000007f, 0.000008f, 0.000008f, 0.000010f, 0.000011f, 0.000012f, 0.000013f, 0.000013f, 0.000013f, 0.000014f, 0.000017f,
+ 0.000017f, 0.000016f, 0.000018f, 0.000019f, 0.000021f, 0.000021f, 0.000022f, 0.000025f, 0.000027f, 0.000025f, 0.000028f, 0.000030f,
+ 0.000033f, 0.000036f, 0.000038f, 0.000040f, 0.000042f, 0.000047f, 0.000052f, 0.000057f, 0.000060f, 0.000068f, 0.000073f, 0.000089f,
+ 0.000104f, 0.000124f, 0.000153f, 0.000204f, 0.000293f, 0.000497f, 0.278076f, 0.362793f, 0.385498f, 0.397705f, 0.405029f, 0.409912f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000004f, 0.000005f, 0.000005f, 0.000008f, 0.000012f, 0.000026f, 0.267822f, 0.353027f,
+ 0.376953f, 0.388916f, 0.395996f, 0.401367f,
+ },
+ {
+ 0.006824f, 0.021286f, 0.036285f, 0.051208f, 0.066467f, 0.082825f, 0.098694f, 0.114563f, 0.130737f, 0.146973f, 0.162720f, 0.179932f,
+ 0.196411f, 0.212646f, 0.229370f, 0.246338f, 0.263184f, 0.279785f, 0.297363f, 0.314209f, 0.331055f, 0.348389f, 0.365479f, 0.383301f,
+ 0.400146f, 0.417725f, 0.435303f, 0.451904f, 0.469971f, 0.486816f, 0.503906f, 0.521484f, 0.539551f, 0.556641f, 0.573730f, 0.592285f,
+ 0.609375f, 0.627441f, 0.644531f, 0.662598f, 0.679688f, 0.696777f, 0.714355f, 0.731934f, 0.749512f, 0.768066f, 0.784180f, 0.802246f,
+ 0.820312f, 0.837891f, 0.854980f, 0.871582f, 0.889648f, 0.906738f, 0.924805f, 0.941406f, 0.959473f, 0.976074f, 0.953125f, 0.895020f,
+ 0.857422f, 0.827637f, 0.803223f, 0.781738f, 0.006741f, 0.020706f, 0.035187f, 0.049866f, 0.065125f, 0.079895f, 0.095581f, 0.111206f,
+ 0.126953f, 0.142822f, 0.158569f, 0.174561f, 0.190796f, 0.207031f, 0.223511f, 0.239380f, 0.256104f, 0.272705f, 0.289307f, 0.305664f,
+ 0.322754f, 0.338867f, 0.356201f, 0.372314f, 0.389404f, 0.406494f, 0.423828f, 0.440430f, 0.457520f, 0.474854f, 0.491211f, 0.508789f,
+ 0.525391f, 0.541992f, 0.559082f, 0.576660f, 0.594238f, 0.610840f, 0.627930f, 0.645508f, 0.662598f, 0.679199f, 0.696289f, 0.713379f,
+ 0.731445f, 0.747559f, 0.765137f, 0.782715f, 0.799805f, 0.816895f, 0.834473f, 0.851074f, 0.868164f, 0.884766f, 0.902344f, 0.919434f,
+ 0.936523f, 0.953613f, 0.942871f, 0.887695f, 0.851562f, 0.823730f, 0.799805f, 0.779297f, 0.006504f, 0.020004f, 0.033875f, 0.048676f,
+ 0.063110f, 0.077759f, 0.092712f, 0.108032f, 0.123230f, 0.138672f, 0.153931f, 0.170044f, 0.185791f, 0.200806f, 0.217041f, 0.233276f,
+ 0.248901f, 0.265137f, 0.280762f, 0.297363f, 0.313721f, 0.329834f, 0.346680f, 0.363037f, 0.378418f, 0.395752f, 0.411621f, 0.428467f,
+ 0.445312f, 0.461670f, 0.479004f, 0.494873f, 0.511230f, 0.527832f, 0.544434f, 0.561523f, 0.578613f, 0.594727f, 0.611328f, 0.628906f,
+ 0.645508f, 0.662109f, 0.679199f, 0.695312f, 0.712402f, 0.729004f, 0.746094f, 0.762695f, 0.779297f, 0.796387f, 0.812500f, 0.829590f,
+ 0.846191f, 0.863281f, 0.879395f, 0.896973f, 0.914062f, 0.930176f, 0.932129f, 0.879395f, 0.845703f, 0.818848f, 0.795898f, 0.776367f,
+ 0.006226f, 0.019318f, 0.032959f, 0.046631f, 0.060699f, 0.075745f, 0.089966f, 0.104553f, 0.119385f, 0.134277f, 0.149292f, 0.164917f,
+ 0.179932f, 0.195190f, 0.210693f, 0.226562f, 0.242188f, 0.257568f, 0.273438f, 0.289062f, 0.304932f, 0.320557f, 0.336426f, 0.352539f,
+ 0.368652f, 0.384766f, 0.400391f, 0.417236f, 0.433105f, 0.448730f, 0.465088f, 0.481689f, 0.497559f, 0.513672f, 0.528809f, 0.546875f,
+ 0.562500f, 0.578613f, 0.595215f, 0.612793f, 0.627930f, 0.645508f, 0.661621f, 0.677246f, 0.693848f, 0.709961f, 0.726562f, 0.743164f,
+ 0.759766f, 0.774902f, 0.791992f, 0.808594f, 0.825195f, 0.841309f, 0.856934f, 0.874023f, 0.890625f, 0.907715f, 0.921387f, 0.872070f,
+ 0.839355f, 0.813477f, 0.791504f, 0.772461f, 0.005928f, 0.018997f, 0.031830f, 0.045380f, 0.059235f, 0.072754f, 0.087463f, 0.101562f,
+ 0.115723f, 0.130371f, 0.145264f, 0.159668f, 0.175049f, 0.189453f, 0.204468f, 0.219482f, 0.234497f, 0.250000f, 0.266113f, 0.280273f,
+ 0.295410f, 0.311768f, 0.327393f, 0.343018f, 0.357422f, 0.373779f, 0.389404f, 0.404785f, 0.421143f, 0.437012f, 0.452881f, 0.468262f,
+ 0.484375f, 0.499512f, 0.515137f, 0.531738f, 0.546875f, 0.562500f, 0.579102f, 0.595215f, 0.610840f, 0.627441f, 0.643555f, 0.659180f,
+ 0.674805f, 0.691406f, 0.708008f, 0.723145f, 0.738770f, 0.755371f, 0.771484f, 0.787598f, 0.803711f, 0.819824f, 0.835449f, 0.851562f,
+ 0.867676f, 0.884277f, 0.910156f, 0.864258f, 0.832520f, 0.808105f, 0.787109f, 0.769043f, 0.005939f, 0.018066f, 0.030991f, 0.043488f,
+ 0.057312f, 0.070557f, 0.084473f, 0.098328f, 0.112610f, 0.126587f, 0.140259f, 0.154907f, 0.169678f, 0.184326f, 0.198608f, 0.213379f,
+ 0.227783f, 0.242065f, 0.257568f, 0.272705f, 0.287109f, 0.302246f, 0.318115f, 0.333252f, 0.347656f, 0.362549f, 0.378418f, 0.393555f,
+ 0.408936f, 0.423828f, 0.439697f, 0.455078f, 0.471191f, 0.484863f, 0.500488f, 0.517578f, 0.532227f, 0.547363f, 0.562500f, 0.579102f,
+ 0.594727f, 0.610352f, 0.625488f, 0.641602f, 0.657227f, 0.671875f, 0.687500f, 0.704102f, 0.719238f, 0.733887f, 0.750488f, 0.767090f,
+ 0.782715f, 0.798340f, 0.813965f, 0.830566f, 0.845215f, 0.862305f, 0.899902f, 0.855469f, 0.825684f, 0.801758f, 0.782227f, 0.764648f,
+ 0.005684f, 0.017639f, 0.030334f, 0.042572f, 0.055298f, 0.068054f, 0.081787f, 0.095276f, 0.108765f, 0.122192f, 0.136353f, 0.150513f,
+ 0.164307f, 0.178467f, 0.192627f, 0.206665f, 0.221436f, 0.234985f, 0.249634f, 0.264404f, 0.278564f, 0.293213f, 0.308350f, 0.321533f,
+ 0.337646f, 0.353027f, 0.367432f, 0.381592f, 0.395996f, 0.411865f, 0.426758f, 0.441895f, 0.456543f, 0.471680f, 0.485840f, 0.501465f,
+ 0.517090f, 0.531738f, 0.546387f, 0.562012f, 0.576660f, 0.592773f, 0.608398f, 0.623047f, 0.638672f, 0.654297f, 0.668457f, 0.684082f,
+ 0.699707f, 0.714844f, 0.730469f, 0.745605f, 0.761230f, 0.777832f, 0.791504f, 0.807617f, 0.823242f, 0.839355f, 0.889160f, 0.847656f,
+ 0.818848f, 0.796387f, 0.776855f, 0.760254f, 0.005417f, 0.017136f, 0.028778f, 0.041016f, 0.054047f, 0.066528f, 0.079590f, 0.092102f,
+ 0.105225f, 0.118652f, 0.131714f, 0.145630f, 0.158813f, 0.172607f, 0.186523f, 0.200317f, 0.213745f, 0.227905f, 0.242188f, 0.256104f,
+ 0.270020f, 0.283936f, 0.299072f, 0.312744f, 0.327148f, 0.341797f, 0.355957f, 0.369629f, 0.384766f, 0.399414f, 0.413574f, 0.427490f,
+ 0.443115f, 0.457764f, 0.472656f, 0.487061f, 0.501465f, 0.516602f, 0.530762f, 0.545898f, 0.560547f, 0.574707f, 0.589844f, 0.605469f,
+ 0.619629f, 0.633301f, 0.648926f, 0.665527f, 0.679688f, 0.694824f, 0.709961f, 0.725586f, 0.739746f, 0.755371f, 0.770020f, 0.786133f,
+ 0.802246f, 0.817383f, 0.877930f, 0.838867f, 0.812012f, 0.790039f, 0.771973f, 0.755371f, 0.005520f, 0.016464f, 0.027695f, 0.039948f,
+ 0.051575f, 0.063965f, 0.076660f, 0.089111f, 0.101807f, 0.114319f, 0.126953f, 0.140381f, 0.153564f, 0.166992f, 0.180298f, 0.193970f,
+ 0.207153f, 0.220337f, 0.234131f, 0.248169f, 0.261475f, 0.275146f, 0.288818f, 0.302734f, 0.316162f, 0.330566f, 0.345459f, 0.358887f,
+ 0.372803f, 0.386719f, 0.401367f, 0.415527f, 0.429199f, 0.443848f, 0.458008f, 0.472412f, 0.486572f, 0.500977f, 0.515137f, 0.529785f,
+ 0.544434f, 0.558105f, 0.572754f, 0.587891f, 0.601074f, 0.617188f, 0.631836f, 0.645020f, 0.660645f, 0.674805f, 0.689453f, 0.704590f,
+ 0.719727f, 0.734375f, 0.750000f, 0.764160f, 0.780273f, 0.794922f, 0.866699f, 0.830566f, 0.804688f, 0.784180f, 0.766113f, 0.750977f,
+ 0.005222f, 0.016022f, 0.026962f, 0.038086f, 0.050049f, 0.061798f, 0.074158f, 0.085876f, 0.098145f, 0.110718f, 0.122986f, 0.135864f,
+ 0.148438f, 0.161133f, 0.173584f, 0.187378f, 0.199707f, 0.213501f, 0.226440f, 0.240112f, 0.252441f, 0.266113f, 0.279785f, 0.292725f,
+ 0.306152f, 0.320068f, 0.333984f, 0.347900f, 0.361572f, 0.374512f, 0.387695f, 0.402344f, 0.416504f, 0.429688f, 0.443604f, 0.458008f,
+ 0.471680f, 0.485596f, 0.499023f, 0.513184f, 0.527832f, 0.541016f, 0.555664f, 0.569336f, 0.583984f, 0.598633f, 0.612793f, 0.626465f,
+ 0.641602f, 0.656250f, 0.669922f, 0.684570f, 0.698730f, 0.713867f, 0.728516f, 0.742188f, 0.757812f, 0.771484f, 0.855957f, 0.822266f,
+ 0.797852f, 0.777832f, 0.760742f, 0.746094f, 0.004944f, 0.015327f, 0.026230f, 0.037201f, 0.048187f, 0.059448f, 0.071167f, 0.082642f,
+ 0.094727f, 0.106506f, 0.119019f, 0.130371f, 0.143555f, 0.155640f, 0.167725f, 0.180908f, 0.193604f, 0.206177f, 0.218506f, 0.231812f,
+ 0.244873f, 0.257568f, 0.270996f, 0.283203f, 0.296387f, 0.309814f, 0.322754f, 0.336670f, 0.348877f, 0.362061f, 0.376465f, 0.389893f,
+ 0.402588f, 0.415283f, 0.429443f, 0.443115f, 0.457031f, 0.470459f, 0.483887f, 0.497314f, 0.511230f, 0.524414f, 0.538574f, 0.551758f,
+ 0.565918f, 0.579590f, 0.593750f, 0.606934f, 0.621094f, 0.635254f, 0.649902f, 0.664062f, 0.678223f, 0.692871f, 0.707031f, 0.721191f,
+ 0.735840f, 0.750488f, 0.846191f, 0.813477f, 0.790527f, 0.770996f, 0.754883f, 0.740723f, 0.004951f, 0.014656f, 0.025253f, 0.035309f,
+ 0.046417f, 0.057465f, 0.068665f, 0.079773f, 0.091370f, 0.102844f, 0.114441f, 0.126099f, 0.138062f, 0.150391f, 0.161987f, 0.174561f,
+ 0.186523f, 0.198730f, 0.211060f, 0.223267f, 0.235352f, 0.248779f, 0.260986f, 0.274414f, 0.286621f, 0.298584f, 0.312256f, 0.324463f,
+ 0.337158f, 0.350342f, 0.363281f, 0.376953f, 0.389404f, 0.402344f, 0.415283f, 0.428955f, 0.441162f, 0.455322f, 0.467285f, 0.481201f,
+ 0.493896f, 0.507324f, 0.520996f, 0.534668f, 0.547852f, 0.561035f, 0.575195f, 0.588867f, 0.603027f, 0.616211f, 0.630371f, 0.643555f,
+ 0.658203f, 0.671875f, 0.686035f, 0.699707f, 0.714844f, 0.729492f, 0.833984f, 0.804688f, 0.782227f, 0.764160f, 0.749512f, 0.735352f,
+ 0.004700f, 0.014343f, 0.024200f, 0.034515f, 0.044586f, 0.055176f, 0.066162f, 0.077209f, 0.087830f, 0.098816f, 0.110413f, 0.121826f,
+ 0.132690f, 0.144897f, 0.156372f, 0.168213f, 0.179443f, 0.191650f, 0.203369f, 0.215088f, 0.227661f, 0.239990f, 0.251709f, 0.263916f,
+ 0.276611f, 0.289551f, 0.301270f, 0.313965f, 0.325928f, 0.338135f, 0.350586f, 0.363037f, 0.376465f, 0.388428f, 0.401123f, 0.414062f,
+ 0.426514f, 0.439209f, 0.452393f, 0.465088f, 0.478271f, 0.491455f, 0.503906f, 0.517090f, 0.530273f, 0.543457f, 0.556641f, 0.570312f,
+ 0.583008f, 0.597168f, 0.610352f, 0.624512f, 0.638184f, 0.651367f, 0.665527f, 0.679199f, 0.692871f, 0.708496f, 0.823242f, 0.796387f,
+ 0.774902f, 0.757812f, 0.742676f, 0.729980f, 0.004395f, 0.013802f, 0.023499f, 0.033173f, 0.043121f, 0.053345f, 0.063538f, 0.073730f,
+ 0.085083f, 0.095581f, 0.106140f, 0.116760f, 0.127930f, 0.139160f, 0.150757f, 0.161621f, 0.173096f, 0.184814f, 0.196289f, 0.207520f,
+ 0.219971f, 0.231201f, 0.242920f, 0.254150f, 0.266602f, 0.278320f, 0.290527f, 0.302490f, 0.314209f, 0.326904f, 0.338867f, 0.349854f,
+ 0.362305f, 0.375488f, 0.387451f, 0.400146f, 0.412354f, 0.424805f, 0.436768f, 0.449219f, 0.461914f, 0.475098f, 0.487061f, 0.500000f,
+ 0.512695f, 0.525391f, 0.538574f, 0.551758f, 0.564453f, 0.577148f, 0.590820f, 0.604004f, 0.618164f, 0.631348f, 0.644531f, 0.658203f,
+ 0.672363f, 0.686523f, 0.812500f, 0.786621f, 0.767090f, 0.750977f, 0.736816f, 0.724609f, 0.004425f, 0.013405f, 0.022385f, 0.032043f,
+ 0.041565f, 0.051605f, 0.061340f, 0.071106f, 0.081116f, 0.091125f, 0.101868f, 0.112671f, 0.123169f, 0.133667f, 0.144897f, 0.155029f,
+ 0.166748f, 0.177246f, 0.188599f, 0.199585f, 0.211182f, 0.222046f, 0.233643f, 0.245361f, 0.255615f, 0.268066f, 0.279053f, 0.291260f,
+ 0.303223f, 0.314209f, 0.325684f, 0.338379f, 0.349854f, 0.361572f, 0.374023f, 0.385254f, 0.397949f, 0.409912f, 0.421143f, 0.434082f,
+ 0.445801f, 0.457764f, 0.470215f, 0.482910f, 0.495361f, 0.508301f, 0.520996f, 0.534180f, 0.546387f, 0.560059f, 0.572266f, 0.584961f,
+ 0.597168f, 0.610840f, 0.624023f, 0.638184f, 0.650879f, 0.666016f, 0.801270f, 0.778320f, 0.760254f, 0.744141f, 0.730469f, 0.719238f,
+ 0.004261f, 0.012543f, 0.021591f, 0.031052f, 0.039734f, 0.049164f, 0.058838f, 0.068420f, 0.077881f, 0.087402f, 0.098145f, 0.108276f,
+ 0.118225f, 0.128784f, 0.138550f, 0.149292f, 0.159790f, 0.170654f, 0.181519f, 0.191772f, 0.203003f, 0.213623f, 0.225098f, 0.235107f,
+ 0.247070f, 0.257324f, 0.269287f, 0.280273f, 0.291260f, 0.302246f, 0.313721f, 0.325439f, 0.336670f, 0.348145f, 0.359619f, 0.371338f,
+ 0.382812f, 0.395020f, 0.406738f, 0.418213f, 0.429932f, 0.442139f, 0.454102f, 0.466309f, 0.479004f, 0.490723f, 0.502930f, 0.515625f,
+ 0.526855f, 0.540527f, 0.552246f, 0.565918f, 0.578613f, 0.591309f, 0.604492f, 0.617188f, 0.630859f, 0.644043f, 0.790039f, 0.769531f,
+ 0.751953f, 0.737305f, 0.724121f, 0.713379f, 0.003983f, 0.012329f, 0.020538f, 0.029312f, 0.038452f, 0.047241f, 0.056244f, 0.065552f,
+ 0.075195f, 0.084290f, 0.094238f, 0.103638f, 0.113403f, 0.123413f, 0.133057f, 0.143066f, 0.153076f, 0.163696f, 0.173584f, 0.184204f,
+ 0.194580f, 0.204834f, 0.215332f, 0.225952f, 0.237305f, 0.247803f, 0.258545f, 0.269531f, 0.280518f, 0.291260f, 0.301758f, 0.312988f,
+ 0.324219f, 0.335205f, 0.346191f, 0.357178f, 0.368896f, 0.380127f, 0.391113f, 0.403076f, 0.414551f, 0.426270f, 0.437500f, 0.449951f,
+ 0.460938f, 0.473389f, 0.485596f, 0.497314f, 0.509277f, 0.522461f, 0.533691f, 0.546875f, 0.558594f, 0.571289f, 0.583496f, 0.596680f,
+ 0.608887f, 0.623047f, 0.778809f, 0.761230f, 0.744141f, 0.730957f, 0.718262f, 0.707031f, 0.003717f, 0.012016f, 0.020142f, 0.028137f,
+ 0.036682f, 0.045441f, 0.053711f, 0.062927f, 0.071777f, 0.080627f, 0.090210f, 0.099060f, 0.108643f, 0.118164f, 0.127808f, 0.137329f,
+ 0.147095f, 0.156128f, 0.166748f, 0.175903f, 0.186157f, 0.196655f, 0.206909f, 0.216797f, 0.227417f, 0.236816f, 0.247559f, 0.258301f,
+ 0.268799f, 0.278809f, 0.289795f, 0.299805f, 0.310547f, 0.321777f, 0.333008f, 0.343262f, 0.354492f, 0.365234f, 0.376953f, 0.387939f,
+ 0.398438f, 0.410400f, 0.421387f, 0.433105f, 0.444824f, 0.455811f, 0.467529f, 0.479736f, 0.491943f, 0.502930f, 0.515625f, 0.527344f,
+ 0.540039f, 0.551758f, 0.563965f, 0.576660f, 0.589844f, 0.602539f, 0.767578f, 0.751465f, 0.736328f, 0.723633f, 0.711914f, 0.701660f,
+ 0.003813f, 0.011337f, 0.019028f, 0.027252f, 0.035583f, 0.043396f, 0.051849f, 0.060028f, 0.068481f, 0.077026f, 0.086121f, 0.095093f,
+ 0.103821f, 0.112610f, 0.121765f, 0.131470f, 0.140503f, 0.149780f, 0.159058f, 0.168701f, 0.178711f, 0.187744f, 0.197998f, 0.207397f,
+ 0.217651f, 0.227661f, 0.236694f, 0.246704f, 0.257080f, 0.267334f, 0.277832f, 0.288330f, 0.298584f, 0.308838f, 0.319336f, 0.329590f,
+ 0.340332f, 0.351318f, 0.361816f, 0.372559f, 0.383301f, 0.395020f, 0.405273f, 0.416260f, 0.427734f, 0.439209f, 0.450195f, 0.462158f,
+ 0.473389f, 0.485107f, 0.497314f, 0.508301f, 0.520996f, 0.533203f, 0.544922f, 0.557617f, 0.568848f, 0.582031f, 0.757324f, 0.742676f,
+ 0.729004f, 0.716309f, 0.705566f, 0.695801f, 0.003633f, 0.011040f, 0.018280f, 0.026062f, 0.033569f, 0.041229f, 0.049591f, 0.057373f,
+ 0.065308f, 0.073975f, 0.082214f, 0.090393f, 0.099243f, 0.107544f, 0.116028f, 0.125854f, 0.134155f, 0.143311f, 0.151978f, 0.160767f,
+ 0.170410f, 0.179321f, 0.188477f, 0.198242f, 0.207764f, 0.217896f, 0.227051f, 0.236328f, 0.246338f, 0.256104f, 0.265869f, 0.276123f,
+ 0.285645f, 0.295898f, 0.306152f, 0.316162f, 0.326172f, 0.336914f, 0.347412f, 0.358154f, 0.368164f, 0.378906f, 0.389648f, 0.400146f,
+ 0.410889f, 0.421631f, 0.432861f, 0.444824f, 0.456055f, 0.466797f, 0.479004f, 0.490234f, 0.501465f, 0.514160f, 0.525879f, 0.537598f,
+ 0.549316f, 0.561523f, 0.745605f, 0.733887f, 0.721191f, 0.708496f, 0.699219f, 0.689453f, 0.003469f, 0.010429f, 0.017609f, 0.024612f,
+ 0.032135f, 0.039520f, 0.047516f, 0.055206f, 0.062347f, 0.070618f, 0.078308f, 0.085938f, 0.094727f, 0.102417f, 0.111511f, 0.119446f,
+ 0.127441f, 0.136475f, 0.144897f, 0.154175f, 0.162476f, 0.171509f, 0.180054f, 0.189697f, 0.198486f, 0.207886f, 0.216553f, 0.225830f,
+ 0.235229f, 0.244873f, 0.254395f, 0.263428f, 0.273193f, 0.283203f, 0.292969f, 0.302734f, 0.312744f, 0.322510f, 0.333008f, 0.342773f,
+ 0.353027f, 0.363037f, 0.374023f, 0.384521f, 0.395264f, 0.405762f, 0.416260f, 0.427002f, 0.438232f, 0.449219f, 0.460449f, 0.471924f,
+ 0.482910f, 0.494629f, 0.506348f, 0.517578f, 0.529785f, 0.541504f, 0.734375f, 0.725098f, 0.712891f, 0.701660f, 0.692383f, 0.683594f,
+ 0.003328f, 0.009804f, 0.016373f, 0.023727f, 0.030746f, 0.037994f, 0.044952f, 0.052032f, 0.059998f, 0.067383f, 0.074707f, 0.082214f,
+ 0.089783f, 0.097961f, 0.105774f, 0.114197f, 0.122131f, 0.129517f, 0.137695f, 0.146118f, 0.154419f, 0.163330f, 0.171997f, 0.180664f,
+ 0.188477f, 0.197388f, 0.206055f, 0.215332f, 0.224365f, 0.233765f, 0.242798f, 0.251709f, 0.260986f, 0.270020f, 0.279785f, 0.289062f,
+ 0.299561f, 0.308594f, 0.318115f, 0.328613f, 0.338135f, 0.348877f, 0.358154f, 0.368408f, 0.378174f, 0.388916f, 0.399658f, 0.410156f,
+ 0.420898f, 0.431885f, 0.442871f, 0.453369f, 0.463867f, 0.475342f, 0.486572f, 0.498535f, 0.510742f, 0.521973f, 0.723633f, 0.715820f,
+ 0.705078f, 0.694336f, 0.686035f, 0.677246f, 0.003090f, 0.009628f, 0.016129f, 0.022644f, 0.029068f, 0.036407f, 0.042633f, 0.049866f,
+ 0.056946f, 0.063904f, 0.071167f, 0.078186f, 0.085327f, 0.092896f, 0.100098f, 0.107788f, 0.115662f, 0.123230f, 0.131104f, 0.139160f,
+ 0.146973f, 0.154907f, 0.162964f, 0.171265f, 0.179565f, 0.188110f, 0.196777f, 0.204834f, 0.213745f, 0.222168f, 0.231079f, 0.239868f,
+ 0.248779f, 0.258057f, 0.267090f, 0.276611f, 0.285645f, 0.294434f, 0.304688f, 0.314209f, 0.323242f, 0.332520f, 0.342773f, 0.353027f,
+ 0.362549f, 0.373047f, 0.383057f, 0.393311f, 0.404053f, 0.414307f, 0.424561f, 0.435059f, 0.445801f, 0.456787f, 0.467773f, 0.479004f,
+ 0.490479f, 0.501953f, 0.712891f, 0.707031f, 0.696777f, 0.687500f, 0.679199f, 0.671387f, 0.003096f, 0.009026f, 0.015450f, 0.021606f,
+ 0.027695f, 0.034302f, 0.040833f, 0.047455f, 0.054077f, 0.060669f, 0.067444f, 0.074097f, 0.081604f, 0.088501f, 0.095337f, 0.102295f,
+ 0.109375f, 0.116821f, 0.124146f, 0.131592f, 0.139404f, 0.147217f, 0.155029f, 0.162231f, 0.170288f, 0.177979f, 0.186646f, 0.194092f,
+ 0.203247f, 0.211670f, 0.219604f, 0.228149f, 0.236816f, 0.245605f, 0.254639f, 0.263184f, 0.272217f, 0.281250f, 0.290527f, 0.299805f,
+ 0.308838f, 0.318604f, 0.327637f, 0.337646f, 0.347900f, 0.356934f, 0.367432f, 0.376953f, 0.387451f, 0.397217f, 0.407227f, 0.417480f,
+ 0.427979f, 0.439209f, 0.449463f, 0.459717f, 0.470947f, 0.482666f, 0.701172f, 0.698242f, 0.688477f, 0.680176f, 0.671875f, 0.665039f,
+ 0.002831f, 0.008789f, 0.014702f, 0.020523f, 0.026642f, 0.032684f, 0.038757f, 0.044708f, 0.051666f, 0.057312f, 0.063660f, 0.070190f,
+ 0.076904f, 0.083435f, 0.090454f, 0.097046f, 0.103821f, 0.110535f, 0.117981f, 0.124817f, 0.131714f, 0.138916f, 0.146606f, 0.153687f,
+ 0.161011f, 0.168823f, 0.176270f, 0.184570f, 0.192139f, 0.200317f, 0.208008f, 0.216309f, 0.224609f, 0.233032f, 0.241821f, 0.250244f,
+ 0.258789f, 0.268066f, 0.276611f, 0.285400f, 0.294678f, 0.303223f, 0.312500f, 0.322021f, 0.331787f, 0.340088f, 0.350830f, 0.360596f,
+ 0.369385f, 0.380371f, 0.389893f, 0.399658f, 0.410645f, 0.420654f, 0.430908f, 0.442383f, 0.452148f, 0.464111f, 0.690430f, 0.688965f,
+ 0.681152f, 0.672852f, 0.665039f, 0.658691f, 0.002712f, 0.008553f, 0.013878f, 0.019638f, 0.025360f, 0.030716f, 0.037231f, 0.042633f,
+ 0.048615f, 0.054810f, 0.060638f, 0.066650f, 0.072205f, 0.078796f, 0.085083f, 0.091492f, 0.097961f, 0.104065f, 0.110718f, 0.117859f,
+ 0.124207f, 0.130981f, 0.138550f, 0.145142f, 0.152588f, 0.160156f, 0.166992f, 0.174561f, 0.181885f, 0.189453f, 0.197754f, 0.205444f,
+ 0.213013f, 0.220825f, 0.229004f, 0.237061f, 0.246094f, 0.254639f, 0.262939f, 0.271484f, 0.280273f, 0.288818f, 0.298584f, 0.307129f,
+ 0.316162f, 0.325195f, 0.334229f, 0.344482f, 0.353516f, 0.363525f, 0.372803f, 0.382812f, 0.392822f, 0.402344f, 0.412842f, 0.423096f,
+ 0.433350f, 0.444092f, 0.679199f, 0.679688f, 0.672852f, 0.665039f, 0.658203f, 0.651855f, 0.002674f, 0.007828f, 0.013290f, 0.018723f,
+ 0.023743f, 0.029160f, 0.034790f, 0.040100f, 0.045929f, 0.051544f, 0.057068f, 0.063110f, 0.068359f, 0.074280f, 0.080078f, 0.086243f,
+ 0.092346f, 0.098206f, 0.104919f, 0.110779f, 0.117493f, 0.123291f, 0.130005f, 0.136963f, 0.143677f, 0.150635f, 0.157471f, 0.164307f,
+ 0.171631f, 0.179199f, 0.186279f, 0.193604f, 0.201904f, 0.209229f, 0.217163f, 0.224976f, 0.233154f, 0.240967f, 0.249634f, 0.258301f,
+ 0.266113f, 0.274414f, 0.283691f, 0.291748f, 0.301025f, 0.310059f, 0.319336f, 0.327148f, 0.337402f, 0.347168f, 0.355957f, 0.364746f,
+ 0.375488f, 0.385498f, 0.394043f, 0.405273f, 0.415283f, 0.426025f, 0.667969f, 0.670410f, 0.664551f, 0.657227f, 0.651367f, 0.645508f,
+ 0.002731f, 0.007622f, 0.012627f, 0.017868f, 0.022781f, 0.028107f, 0.032959f, 0.037811f, 0.043121f, 0.048615f, 0.053925f, 0.059235f,
+ 0.064514f, 0.070007f, 0.075562f, 0.080688f, 0.086914f, 0.092102f, 0.098083f, 0.104309f, 0.110107f, 0.115906f, 0.122314f, 0.128540f,
+ 0.135010f, 0.141479f, 0.147949f, 0.154663f, 0.161865f, 0.168579f, 0.175415f, 0.182739f, 0.191040f, 0.197510f, 0.205200f, 0.212891f,
+ 0.219971f, 0.228638f, 0.236328f, 0.244263f, 0.252686f, 0.260498f, 0.268799f, 0.278076f, 0.286133f, 0.294434f, 0.303223f, 0.312500f,
+ 0.320801f, 0.329834f, 0.339844f, 0.347656f, 0.357910f, 0.367676f, 0.376709f, 0.386963f, 0.396729f, 0.406982f, 0.656738f, 0.662598f,
+ 0.656738f, 0.649902f, 0.644531f, 0.638672f, 0.002411f, 0.007168f, 0.012238f, 0.016739f, 0.021957f, 0.026184f, 0.031311f, 0.035583f,
+ 0.041016f, 0.045685f, 0.050568f, 0.055573f, 0.060791f, 0.065735f, 0.070557f, 0.076111f, 0.081238f, 0.086792f, 0.092163f, 0.097534f,
+ 0.103271f, 0.108887f, 0.114563f, 0.120605f, 0.126587f, 0.132446f, 0.139038f, 0.145508f, 0.152100f, 0.158447f, 0.165527f, 0.171997f,
+ 0.178833f, 0.186035f, 0.193481f, 0.200928f, 0.207886f, 0.215820f, 0.222900f, 0.230713f, 0.238770f, 0.246948f, 0.255127f, 0.262695f,
+ 0.271484f, 0.280029f, 0.287842f, 0.296631f, 0.305420f, 0.313965f, 0.322754f, 0.331787f, 0.340576f, 0.350342f, 0.359375f, 0.369385f,
+ 0.379150f, 0.388184f, 0.645508f, 0.652832f, 0.648438f, 0.643066f, 0.637695f, 0.632324f, 0.002480f, 0.006691f, 0.011452f, 0.015900f,
+ 0.020828f, 0.024734f, 0.029327f, 0.033752f, 0.038513f, 0.042999f, 0.047638f, 0.052429f, 0.056671f, 0.061859f, 0.066040f, 0.071289f,
+ 0.075684f, 0.080688f, 0.086243f, 0.091248f, 0.096436f, 0.101562f, 0.107300f, 0.112366f, 0.118347f, 0.124146f, 0.130249f, 0.135864f,
+ 0.141968f, 0.148438f, 0.155029f, 0.161377f, 0.167969f, 0.174683f, 0.181641f, 0.188599f, 0.195679f, 0.203247f, 0.210449f, 0.217529f,
+ 0.225342f, 0.233398f, 0.241577f, 0.249023f, 0.256592f, 0.264893f, 0.273193f, 0.281494f, 0.289795f, 0.297607f, 0.306885f, 0.315430f,
+ 0.323730f, 0.333496f, 0.342529f, 0.351318f, 0.360840f, 0.370605f, 0.634766f, 0.643555f, 0.640625f, 0.635742f, 0.630859f, 0.625488f,
+ 0.002230f, 0.006477f, 0.010582f, 0.014870f, 0.019073f, 0.023270f, 0.027893f, 0.031860f, 0.036072f, 0.040253f, 0.044373f, 0.048706f,
+ 0.052856f, 0.057312f, 0.061859f, 0.066406f, 0.070984f, 0.075317f, 0.080139f, 0.084839f, 0.089661f, 0.094910f, 0.099792f, 0.104858f,
+ 0.110718f, 0.115356f, 0.121399f, 0.126831f, 0.132690f, 0.138672f, 0.145142f, 0.151001f, 0.157471f, 0.164185f, 0.170532f, 0.177002f,
+ 0.184082f, 0.191040f, 0.197876f, 0.205200f, 0.212402f, 0.219604f, 0.227295f, 0.234985f, 0.242188f, 0.250244f, 0.257812f, 0.266113f,
+ 0.274170f, 0.282471f, 0.290771f, 0.299072f, 0.307373f, 0.316162f, 0.326416f, 0.333984f, 0.343750f, 0.353271f, 0.622070f, 0.634277f,
+ 0.631836f, 0.627930f, 0.623535f, 0.619141f, 0.002220f, 0.006039f, 0.010353f, 0.014328f, 0.017838f, 0.022141f, 0.025742f, 0.029510f,
+ 0.033600f, 0.037781f, 0.041443f, 0.045502f, 0.049469f, 0.053436f, 0.057190f, 0.061462f, 0.065735f, 0.069946f, 0.074524f, 0.078674f,
+ 0.083069f, 0.087830f, 0.092468f, 0.097412f, 0.102783f, 0.107910f, 0.112793f, 0.118164f, 0.123901f, 0.129395f, 0.135132f, 0.140991f,
+ 0.147339f, 0.152954f, 0.159302f, 0.165527f, 0.172363f, 0.178589f, 0.185425f, 0.191895f, 0.199219f, 0.206665f, 0.213989f, 0.221069f,
+ 0.228516f, 0.236206f, 0.243042f, 0.251709f, 0.258789f, 0.266846f, 0.275146f, 0.283203f, 0.291260f, 0.300537f, 0.308350f, 0.317627f,
+ 0.326904f, 0.335938f, 0.611816f, 0.625000f, 0.624023f, 0.620117f, 0.616211f, 0.612793f, 0.001965f, 0.005882f, 0.009613f, 0.013184f,
+ 0.016785f, 0.020370f, 0.024384f, 0.027664f, 0.031311f, 0.035126f, 0.038727f, 0.042572f, 0.046112f, 0.049347f, 0.053253f, 0.056915f,
+ 0.060883f, 0.064697f, 0.068909f, 0.072693f, 0.076843f, 0.081055f, 0.085754f, 0.090088f, 0.094849f, 0.099609f, 0.104614f, 0.109741f,
+ 0.114746f, 0.119995f, 0.125488f, 0.130981f, 0.136719f, 0.142700f, 0.148315f, 0.154541f, 0.160522f, 0.166870f, 0.173828f, 0.179932f,
+ 0.186768f, 0.193604f, 0.200439f, 0.207764f, 0.214844f, 0.221802f, 0.228882f, 0.236328f, 0.244385f, 0.252197f, 0.259277f, 0.268066f,
+ 0.275635f, 0.283447f, 0.292236f, 0.301270f, 0.309570f, 0.318848f, 0.600098f, 0.616211f, 0.615234f, 0.612793f, 0.609375f, 0.605469f,
+ 0.001966f, 0.005653f, 0.009109f, 0.012428f, 0.015945f, 0.018967f, 0.022537f, 0.025894f, 0.029175f, 0.032440f, 0.035797f, 0.038818f,
+ 0.042389f, 0.046051f, 0.049072f, 0.052521f, 0.056335f, 0.059906f, 0.063293f, 0.067017f, 0.070923f, 0.075134f, 0.078979f, 0.083496f,
+ 0.087646f, 0.091980f, 0.096619f, 0.101196f, 0.105957f, 0.111145f, 0.116028f, 0.121277f, 0.126831f, 0.132080f, 0.137817f, 0.143311f,
+ 0.149780f, 0.155029f, 0.161621f, 0.167847f, 0.173950f, 0.180786f, 0.187622f, 0.194214f, 0.201050f, 0.207764f, 0.215210f, 0.222046f,
+ 0.229370f, 0.236816f, 0.244751f, 0.251953f, 0.260010f, 0.268311f, 0.276123f, 0.284180f, 0.293213f, 0.301514f, 0.588379f, 0.606934f,
+ 0.607422f, 0.604980f, 0.602051f, 0.599609f, 0.001963f, 0.005333f, 0.008377f, 0.011589f, 0.014450f, 0.017593f, 0.021133f, 0.023972f,
+ 0.027145f, 0.030075f, 0.033295f, 0.035858f, 0.038818f, 0.041992f, 0.045288f, 0.048279f, 0.051849f, 0.054840f, 0.058289f, 0.061737f,
+ 0.065186f, 0.068848f, 0.072632f, 0.076721f, 0.080505f, 0.084717f, 0.088806f, 0.093079f, 0.097717f, 0.102356f, 0.106934f, 0.111755f,
+ 0.116882f, 0.121887f, 0.127319f, 0.132935f, 0.138306f, 0.144287f, 0.149902f, 0.156250f, 0.162109f, 0.168579f, 0.174316f, 0.180908f,
+ 0.187500f, 0.194458f, 0.201538f, 0.208252f, 0.215210f, 0.222656f, 0.229980f, 0.237061f, 0.244629f, 0.252441f, 0.260254f, 0.267334f,
+ 0.276123f, 0.284180f, 0.576660f, 0.597656f, 0.599609f, 0.598145f, 0.595215f, 0.591797f, 0.001631f, 0.004906f, 0.007805f, 0.010826f,
+ 0.013802f, 0.016983f, 0.019485f, 0.022079f, 0.024750f, 0.027939f, 0.030136f, 0.033112f, 0.035797f, 0.038727f, 0.041443f, 0.044281f,
+ 0.047058f, 0.050018f, 0.053253f, 0.056396f, 0.059662f, 0.063049f, 0.066406f, 0.069946f, 0.073730f, 0.077454f, 0.081360f, 0.085388f,
+ 0.089417f, 0.093750f, 0.098267f, 0.102844f, 0.107727f, 0.112244f, 0.117615f, 0.122253f, 0.127441f, 0.133057f, 0.138550f, 0.144287f,
+ 0.150024f, 0.156250f, 0.161987f, 0.167969f, 0.174805f, 0.181274f, 0.187744f, 0.194580f, 0.201294f, 0.208374f, 0.215210f, 0.222412f,
+ 0.229736f, 0.237183f, 0.244629f, 0.252197f, 0.260010f, 0.269287f, 0.566406f, 0.588867f, 0.590820f, 0.590332f, 0.587891f, 0.585938f,
+ 0.001858f, 0.004318f, 0.007465f, 0.010246f, 0.012550f, 0.015793f, 0.018143f, 0.020782f, 0.022980f, 0.025116f, 0.027924f, 0.030106f,
+ 0.032623f, 0.035126f, 0.037720f, 0.040283f, 0.042847f, 0.045380f, 0.048492f, 0.051300f, 0.054321f, 0.057373f, 0.060516f, 0.063599f,
+ 0.067139f, 0.070496f, 0.074219f, 0.078003f, 0.081848f, 0.085754f, 0.089783f, 0.093994f, 0.098267f, 0.102783f, 0.107239f, 0.112366f,
+ 0.117371f, 0.122498f, 0.127686f, 0.132935f, 0.138428f, 0.144043f, 0.150024f, 0.155884f, 0.161865f, 0.168091f, 0.174316f, 0.180664f,
+ 0.187622f, 0.194214f, 0.200928f, 0.207520f, 0.214966f, 0.221680f, 0.229370f, 0.236816f, 0.244751f, 0.252441f, 0.553223f, 0.579102f,
+ 0.583496f, 0.582031f, 0.581055f, 0.579590f, 0.001425f, 0.004284f, 0.007019f, 0.009521f, 0.011894f, 0.014191f, 0.016632f, 0.018723f,
+ 0.021210f, 0.023209f, 0.025482f, 0.027344f, 0.029617f, 0.032043f, 0.034210f, 0.036407f, 0.039001f, 0.041077f, 0.043976f, 0.046448f,
+ 0.049133f, 0.051819f, 0.054932f, 0.057770f, 0.060730f, 0.063965f, 0.067322f, 0.070862f, 0.074280f, 0.077698f, 0.082031f, 0.085571f,
+ 0.089844f, 0.093994f, 0.098022f, 0.102722f, 0.107178f, 0.111877f, 0.116821f, 0.121887f, 0.127075f, 0.132446f, 0.138062f, 0.143799f,
+ 0.149414f, 0.155518f, 0.161377f, 0.167480f, 0.173950f, 0.180176f, 0.186890f, 0.193481f, 0.200562f, 0.207397f, 0.214355f, 0.221313f,
+ 0.229492f, 0.237427f, 0.541504f, 0.570801f, 0.575195f, 0.575195f, 0.573730f, 0.572266f, 0.001613f, 0.004181f, 0.006252f, 0.008774f,
+ 0.011108f, 0.013054f, 0.015152f, 0.016937f, 0.019150f, 0.021011f, 0.023163f, 0.024826f, 0.026993f, 0.028793f, 0.030823f, 0.033081f,
+ 0.035156f, 0.037201f, 0.039612f, 0.041748f, 0.044464f, 0.046814f, 0.049438f, 0.052155f, 0.054840f, 0.057831f, 0.060699f, 0.063599f,
+ 0.067078f, 0.070374f, 0.073853f, 0.077087f, 0.081177f, 0.085083f, 0.089111f, 0.093262f, 0.097473f, 0.101929f, 0.106689f, 0.111023f,
+ 0.116455f, 0.121277f, 0.126343f, 0.132080f, 0.137573f, 0.142700f, 0.148682f, 0.154907f, 0.161133f, 0.167236f, 0.173340f, 0.179688f,
+ 0.186768f, 0.193115f, 0.200684f, 0.207275f, 0.214233f, 0.221924f, 0.530273f, 0.561523f, 0.565430f, 0.567383f, 0.564941f, 0.564941f,
+ 0.001237f, 0.003775f, 0.006348f, 0.008141f, 0.010117f, 0.012184f, 0.013763f, 0.015656f, 0.017319f, 0.018967f, 0.020645f, 0.022507f,
+ 0.023926f, 0.025757f, 0.027573f, 0.029449f, 0.031677f, 0.033325f, 0.035645f, 0.037659f, 0.039734f, 0.041809f, 0.044189f, 0.046692f,
+ 0.049133f, 0.051697f, 0.054504f, 0.057251f, 0.060059f, 0.063110f, 0.066467f, 0.069763f, 0.072937f, 0.076477f, 0.080505f, 0.084290f,
+ 0.088013f, 0.092407f, 0.096436f, 0.101013f, 0.105713f, 0.110352f, 0.115356f, 0.120605f, 0.125488f, 0.130981f, 0.136353f, 0.142090f,
+ 0.148438f, 0.153931f, 0.159912f, 0.166260f, 0.172485f, 0.179321f, 0.185791f, 0.193115f, 0.199463f, 0.206665f, 0.520020f, 0.552246f,
+ 0.558105f, 0.559570f, 0.559082f, 0.557617f, 0.001151f, 0.003399f, 0.005611f, 0.007439f, 0.009354f, 0.010925f, 0.012489f, 0.014061f,
+ 0.015610f, 0.017258f, 0.018845f, 0.020248f, 0.021484f, 0.023193f, 0.024796f, 0.026459f, 0.028183f, 0.029785f, 0.031738f, 0.033386f,
+ 0.035309f, 0.037384f, 0.039368f, 0.041626f, 0.043701f, 0.046204f, 0.048553f, 0.051178f, 0.053955f, 0.056488f, 0.059418f, 0.062256f,
+ 0.065308f, 0.068542f, 0.071899f, 0.075623f, 0.079224f, 0.082947f, 0.087097f, 0.091064f, 0.095520f, 0.099854f, 0.104736f, 0.109314f,
+ 0.114136f, 0.119324f, 0.124756f, 0.130127f, 0.135498f, 0.141113f, 0.146973f, 0.153198f, 0.159180f, 0.165527f, 0.172241f, 0.178711f,
+ 0.185425f, 0.192749f, 0.507324f, 0.543945f, 0.549316f, 0.552246f, 0.551270f, 0.551270f, 0.001070f, 0.002996f, 0.004986f, 0.006851f,
+ 0.008514f, 0.009850f, 0.011330f, 0.012596f, 0.014015f, 0.015259f, 0.016586f, 0.017731f, 0.019287f, 0.020676f, 0.022079f, 0.023468f,
+ 0.024765f, 0.026489f, 0.028030f, 0.029465f, 0.031311f, 0.032898f, 0.034851f, 0.036743f, 0.038940f, 0.040833f, 0.043091f, 0.045074f,
+ 0.047729f, 0.050079f, 0.052673f, 0.055389f, 0.058136f, 0.061188f, 0.064087f, 0.067261f, 0.070618f, 0.074158f, 0.077942f, 0.081726f,
+ 0.085815f, 0.089783f, 0.094055f, 0.098572f, 0.103088f, 0.107971f, 0.113037f, 0.118164f, 0.123413f, 0.128784f, 0.134521f, 0.140137f,
+ 0.146118f, 0.152100f, 0.158325f, 0.164307f, 0.171387f, 0.177368f, 0.496094f, 0.534668f, 0.541992f, 0.543945f, 0.544434f, 0.544434f,
+ 0.001086f, 0.003069f, 0.004463f, 0.006256f, 0.007393f, 0.009026f, 0.010178f, 0.011276f, 0.012260f, 0.013542f, 0.014648f, 0.015808f,
+ 0.016861f, 0.017899f, 0.019333f, 0.020599f, 0.021942f, 0.023117f, 0.024384f, 0.025833f, 0.027344f, 0.028992f, 0.030579f, 0.032318f,
+ 0.034149f, 0.035828f, 0.037842f, 0.039764f, 0.041901f, 0.044037f, 0.046539f, 0.048645f, 0.051147f, 0.053894f, 0.056641f, 0.059631f,
+ 0.062500f, 0.065735f, 0.069031f, 0.072754f, 0.076294f, 0.080139f, 0.083984f, 0.088379f, 0.092712f, 0.097229f, 0.101929f, 0.106873f,
+ 0.111694f, 0.117004f, 0.122314f, 0.127930f, 0.133789f, 0.139282f, 0.145142f, 0.151367f, 0.157349f, 0.163818f, 0.484619f, 0.525391f,
+ 0.534180f, 0.536621f, 0.536133f, 0.536621f, 0.001125f, 0.002892f, 0.003883f, 0.005867f, 0.006603f, 0.007935f, 0.009026f, 0.009911f,
+ 0.010956f, 0.012077f, 0.012909f, 0.013901f, 0.014977f, 0.015671f, 0.016983f, 0.018021f, 0.019058f, 0.020279f, 0.021225f, 0.022598f,
+ 0.023941f, 0.025299f, 0.026535f, 0.028107f, 0.029755f, 0.031113f, 0.033020f, 0.034668f, 0.036682f, 0.038483f, 0.040527f, 0.042511f,
+ 0.044708f, 0.046936f, 0.049744f, 0.052216f, 0.054840f, 0.057800f, 0.060791f, 0.064087f, 0.067505f, 0.071045f, 0.074463f, 0.078491f,
+ 0.082397f, 0.086609f, 0.091248f, 0.095581f, 0.100342f, 0.105530f, 0.110474f, 0.116272f, 0.120972f, 0.126953f, 0.132812f, 0.138672f,
+ 0.144287f, 0.150513f, 0.472412f, 0.516113f, 0.524902f, 0.528809f, 0.529785f, 0.529785f, 0.000859f, 0.002470f, 0.003815f, 0.005226f,
+ 0.005913f, 0.007206f, 0.007942f, 0.008652f, 0.009583f, 0.010406f, 0.011223f, 0.011971f, 0.012856f, 0.013664f, 0.014664f, 0.015549f,
+ 0.016464f, 0.017487f, 0.018478f, 0.019592f, 0.020767f, 0.021774f, 0.023117f, 0.024338f, 0.025604f, 0.027008f, 0.028519f, 0.029953f,
+ 0.031525f, 0.033173f, 0.034943f, 0.036865f, 0.038696f, 0.040863f, 0.042969f, 0.045471f, 0.048004f, 0.050293f, 0.052979f, 0.055847f,
+ 0.058960f, 0.062042f, 0.065491f, 0.069153f, 0.072937f, 0.076660f, 0.080750f, 0.085144f, 0.089539f, 0.094177f, 0.099304f, 0.104187f,
+ 0.109741f, 0.114807f, 0.120483f, 0.125977f, 0.131836f, 0.138306f, 0.460449f, 0.507812f, 0.516602f, 0.520020f, 0.522461f, 0.522949f,
+ 0.000906f, 0.002359f, 0.003643f, 0.004356f, 0.005310f, 0.005989f, 0.007030f, 0.007507f, 0.008255f, 0.009010f, 0.009834f, 0.010483f,
+ 0.011230f, 0.011887f, 0.012573f, 0.013367f, 0.014252f, 0.014954f, 0.015900f, 0.016785f, 0.017776f, 0.018631f, 0.019775f, 0.020874f,
+ 0.022110f, 0.023117f, 0.024368f, 0.025589f, 0.026932f, 0.028549f, 0.029938f, 0.031525f, 0.033325f, 0.035187f, 0.037109f, 0.038971f,
+ 0.041138f, 0.043396f, 0.045715f, 0.048370f, 0.051025f, 0.053772f, 0.057129f, 0.060089f, 0.063416f, 0.067261f, 0.070679f, 0.075012f,
+ 0.079285f, 0.083618f, 0.088379f, 0.093018f, 0.098083f, 0.102478f, 0.108093f, 0.114380f, 0.119507f, 0.125488f, 0.448975f, 0.498291f,
+ 0.508789f, 0.513672f, 0.514648f, 0.516113f, 0.000728f, 0.001932f, 0.003067f, 0.003990f, 0.004784f, 0.005295f, 0.005974f, 0.006584f,
+ 0.007099f, 0.007652f, 0.008255f, 0.008904f, 0.009491f, 0.010109f, 0.010658f, 0.011497f, 0.012131f, 0.012718f, 0.013535f, 0.014336f,
+ 0.015083f, 0.016083f, 0.016785f, 0.017761f, 0.018738f, 0.019669f, 0.020691f, 0.021805f, 0.023010f, 0.024170f, 0.025467f, 0.026794f,
+ 0.028336f, 0.029922f, 0.031555f, 0.033203f, 0.035034f, 0.036987f, 0.039062f, 0.041290f, 0.043671f, 0.046143f, 0.048920f, 0.051880f,
+ 0.054901f, 0.058228f, 0.061615f, 0.065369f, 0.069214f, 0.073425f, 0.077637f, 0.082214f, 0.087097f, 0.091797f, 0.096497f, 0.102356f,
+ 0.107483f, 0.113464f, 0.437256f, 0.489746f, 0.500977f, 0.504883f, 0.507812f, 0.509277f, 0.000724f, 0.001842f, 0.002728f, 0.003332f,
+ 0.004101f, 0.004707f, 0.005020f, 0.005497f, 0.006245f, 0.006603f, 0.007027f, 0.007515f, 0.008156f, 0.008537f, 0.009125f, 0.009659f,
+ 0.010101f, 0.010864f, 0.011482f, 0.012070f, 0.012756f, 0.013496f, 0.014236f, 0.014931f, 0.015808f, 0.016632f, 0.017487f, 0.018433f,
+ 0.019379f, 0.020416f, 0.021530f, 0.022583f, 0.023804f, 0.024979f, 0.026443f, 0.027939f, 0.029526f, 0.031235f, 0.033020f, 0.035004f,
+ 0.037018f, 0.039185f, 0.041595f, 0.044159f, 0.046783f, 0.049866f, 0.052856f, 0.056274f, 0.059906f, 0.063721f, 0.067749f, 0.072327f,
+ 0.076172f, 0.081299f, 0.085938f, 0.091309f, 0.096558f, 0.101807f, 0.426270f, 0.480469f, 0.492676f, 0.498047f, 0.500488f, 0.501953f,
+ 0.000673f, 0.001715f, 0.002426f, 0.002953f, 0.003588f, 0.003944f, 0.004200f, 0.004776f, 0.005131f, 0.005527f, 0.005886f, 0.006371f,
+ 0.006790f, 0.007076f, 0.007538f, 0.008133f, 0.008644f, 0.009140f, 0.009483f, 0.010071f, 0.010689f, 0.011230f, 0.011879f, 0.012474f,
+ 0.013222f, 0.013916f, 0.014587f, 0.015411f, 0.016190f, 0.016983f, 0.017883f, 0.018845f, 0.019867f, 0.020935f, 0.022141f, 0.023270f,
+ 0.024567f, 0.026001f, 0.027481f, 0.029114f, 0.030777f, 0.032684f, 0.034698f, 0.036865f, 0.039337f, 0.041748f, 0.044647f, 0.047882f,
+ 0.050964f, 0.054260f, 0.058258f, 0.062195f, 0.066528f, 0.070679f, 0.075623f, 0.080505f, 0.085510f, 0.090515f, 0.414307f, 0.472168f,
+ 0.484131f, 0.490234f, 0.492920f, 0.495850f, 0.000484f, 0.001445f, 0.002169f, 0.002569f, 0.002836f, 0.003317f, 0.003569f, 0.003952f,
+ 0.004215f, 0.004623f, 0.004959f, 0.005306f, 0.005592f, 0.005951f, 0.006306f, 0.006737f, 0.007004f, 0.007492f, 0.007942f, 0.008331f,
+ 0.008865f, 0.009270f, 0.009781f, 0.010338f, 0.010887f, 0.011429f, 0.012047f, 0.012726f, 0.013336f, 0.014030f, 0.014771f, 0.015572f,
+ 0.016418f, 0.017258f, 0.018234f, 0.019196f, 0.020279f, 0.021423f, 0.022675f, 0.023987f, 0.025375f, 0.027039f, 0.028702f, 0.030563f,
+ 0.032623f, 0.034698f, 0.037262f, 0.040039f, 0.042664f, 0.046051f, 0.049194f, 0.052948f, 0.057129f, 0.061371f, 0.065613f, 0.070007f,
+ 0.075317f, 0.080200f, 0.402588f, 0.462402f, 0.476807f, 0.482666f, 0.485107f, 0.487061f, 0.000459f, 0.001265f, 0.001572f, 0.002138f,
+ 0.002365f, 0.002775f, 0.002920f, 0.003189f, 0.003454f, 0.003723f, 0.003986f, 0.004250f, 0.004536f, 0.004906f, 0.005150f, 0.005463f,
+ 0.005787f, 0.006172f, 0.006481f, 0.006794f, 0.007156f, 0.007542f, 0.007980f, 0.008430f, 0.008827f, 0.009361f, 0.009796f, 0.010300f,
+ 0.010910f, 0.011497f, 0.012161f, 0.012672f, 0.013336f, 0.014183f, 0.014893f, 0.015640f, 0.016541f, 0.017517f, 0.018448f, 0.019485f,
+ 0.020676f, 0.021912f, 0.023392f, 0.024979f, 0.026627f, 0.028351f, 0.030457f, 0.032806f, 0.035034f, 0.037933f, 0.041229f, 0.044373f,
+ 0.047821f, 0.052002f, 0.056244f, 0.060547f, 0.065247f, 0.069885f, 0.390869f, 0.453857f, 0.468018f, 0.475098f, 0.478027f, 0.480469f,
+ 0.000332f, 0.001075f, 0.001464f, 0.001721f, 0.001911f, 0.002235f, 0.002375f, 0.002558f, 0.002834f, 0.002998f, 0.003185f, 0.003441f,
+ 0.003647f, 0.003952f, 0.004139f, 0.004421f, 0.004631f, 0.004879f, 0.005180f, 0.005447f, 0.005795f, 0.006115f, 0.006416f, 0.006718f,
+ 0.007099f, 0.007462f, 0.007881f, 0.008331f, 0.008797f, 0.009140f, 0.009735f, 0.010223f, 0.010803f, 0.011337f, 0.011986f, 0.012611f,
+ 0.013283f, 0.014076f, 0.014847f, 0.015732f, 0.016693f, 0.017700f, 0.018784f, 0.019897f, 0.021317f, 0.022873f, 0.024429f, 0.026306f,
+ 0.028473f, 0.030960f, 0.033600f, 0.036407f, 0.039856f, 0.043549f, 0.047119f, 0.051392f, 0.055969f, 0.060394f, 0.379639f, 0.444580f,
+ 0.458984f, 0.467529f, 0.470947f, 0.472900f, 0.000408f, 0.000770f, 0.001271f, 0.001390f, 0.001601f, 0.001762f, 0.001848f, 0.002052f,
+ 0.002247f, 0.002401f, 0.002491f, 0.002684f, 0.002878f, 0.003086f, 0.003304f, 0.003452f, 0.003626f, 0.003805f, 0.004074f, 0.004257f,
+ 0.004513f, 0.004807f, 0.005039f, 0.005299f, 0.005638f, 0.005905f, 0.006191f, 0.006516f, 0.006927f, 0.007206f, 0.007645f, 0.008034f,
+ 0.008415f, 0.008911f, 0.009384f, 0.009941f, 0.010483f, 0.011116f, 0.011711f, 0.012428f, 0.013191f, 0.013969f, 0.014862f, 0.015854f,
+ 0.016785f, 0.017975f, 0.019348f, 0.020721f, 0.022461f, 0.024445f, 0.026733f, 0.029175f, 0.032227f, 0.035248f, 0.038788f, 0.042755f,
+ 0.046967f, 0.051636f, 0.367920f, 0.435059f, 0.452148f, 0.459229f, 0.463623f, 0.466797f, 0.000382f, 0.000669f, 0.001037f, 0.001185f,
+ 0.001293f, 0.001379f, 0.001470f, 0.001565f, 0.001729f, 0.001864f, 0.001928f, 0.002138f, 0.002237f, 0.002398f, 0.002510f, 0.002672f,
+ 0.002802f, 0.002966f, 0.003134f, 0.003319f, 0.003517f, 0.003723f, 0.003870f, 0.004089f, 0.004311f, 0.004532f, 0.004772f, 0.005013f,
+ 0.005314f, 0.005573f, 0.005924f, 0.006203f, 0.006523f, 0.006897f, 0.007240f, 0.007660f, 0.008041f, 0.008530f, 0.009048f, 0.009621f,
+ 0.010201f, 0.010841f, 0.011467f, 0.012192f, 0.013138f, 0.013969f, 0.014931f, 0.016113f, 0.017380f, 0.018936f, 0.020630f, 0.022751f,
+ 0.025208f, 0.027924f, 0.031311f, 0.034851f, 0.038879f, 0.043274f, 0.356689f, 0.426270f, 0.443848f, 0.451660f, 0.456055f, 0.459473f,
+ 0.000482f, 0.000542f, 0.000723f, 0.000822f, 0.000881f, 0.001025f, 0.001100f, 0.001209f, 0.001249f, 0.001355f, 0.001522f, 0.001599f,
+ 0.001708f, 0.001836f, 0.001918f, 0.001970f, 0.002129f, 0.002251f, 0.002357f, 0.002522f, 0.002636f, 0.002768f, 0.002911f, 0.003056f,
+ 0.003237f, 0.003393f, 0.003605f, 0.003771f, 0.003994f, 0.004234f, 0.004444f, 0.004635f, 0.004932f, 0.005150f, 0.005486f, 0.005779f,
+ 0.006081f, 0.006458f, 0.006775f, 0.007179f, 0.007668f, 0.008110f, 0.008690f, 0.009209f, 0.009926f, 0.010551f, 0.011330f, 0.012184f,
+ 0.013184f, 0.014297f, 0.015610f, 0.017181f, 0.019165f, 0.021500f, 0.024384f, 0.027618f, 0.031372f, 0.035614f, 0.345459f, 0.417236f,
+ 0.435303f, 0.443604f, 0.448730f, 0.451904f, 0.000240f, 0.000479f, 0.000533f, 0.000625f, 0.000716f, 0.000746f, 0.000857f, 0.000835f,
+ 0.000941f, 0.001024f, 0.001104f, 0.001155f, 0.001204f, 0.001282f, 0.001396f, 0.001453f, 0.001554f, 0.001627f, 0.001737f, 0.001787f,
+ 0.001894f, 0.002012f, 0.002119f, 0.002218f, 0.002335f, 0.002453f, 0.002611f, 0.002714f, 0.002848f, 0.003050f, 0.003168f, 0.003395f,
+ 0.003529f, 0.003740f, 0.003963f, 0.004158f, 0.004429f, 0.004688f, 0.004982f, 0.005280f, 0.005600f, 0.005959f, 0.006340f, 0.006775f,
+ 0.007252f, 0.007748f, 0.008369f, 0.008980f, 0.009705f, 0.010513f, 0.011513f, 0.012665f, 0.014069f, 0.015869f, 0.018158f, 0.020950f,
+ 0.024338f, 0.028366f, 0.335205f, 0.408203f, 0.427002f, 0.435547f, 0.441162f, 0.445312f, 0.000138f, 0.000265f, 0.000381f, 0.000386f,
+ 0.000465f, 0.000556f, 0.000558f, 0.000597f, 0.000659f, 0.000748f, 0.000770f, 0.000786f, 0.000829f, 0.000904f, 0.000940f, 0.001021f,
+ 0.001043f, 0.001139f, 0.001201f, 0.001253f, 0.001327f, 0.001396f, 0.001481f, 0.001555f, 0.001637f, 0.001712f, 0.001813f, 0.001899f,
+ 0.002005f, 0.002140f, 0.002220f, 0.002348f, 0.002462f, 0.002600f, 0.002733f, 0.002932f, 0.003075f, 0.003279f, 0.003452f, 0.003630f,
+ 0.003872f, 0.004166f, 0.004436f, 0.004742f, 0.005077f, 0.005459f, 0.005848f, 0.006310f, 0.006874f, 0.007492f, 0.008171f, 0.009026f,
+ 0.009995f, 0.011307f, 0.013008f, 0.015343f, 0.018265f, 0.021881f, 0.323486f, 0.399170f, 0.418945f, 0.428467f, 0.434326f, 0.437988f,
+ 0.000165f, 0.000260f, 0.000287f, 0.000296f, 0.000331f, 0.000339f, 0.000360f, 0.000395f, 0.000442f, 0.000482f, 0.000487f, 0.000551f,
+ 0.000546f, 0.000611f, 0.000640f, 0.000667f, 0.000711f, 0.000742f, 0.000775f, 0.000816f, 0.000876f, 0.000916f, 0.000974f, 0.001015f,
+ 0.001081f, 0.001123f, 0.001195f, 0.001267f, 0.001317f, 0.001388f, 0.001459f, 0.001558f, 0.001630f, 0.001718f, 0.001804f, 0.001916f,
+ 0.002033f, 0.002148f, 0.002295f, 0.002455f, 0.002583f, 0.002754f, 0.002941f, 0.003134f, 0.003386f, 0.003639f, 0.003910f, 0.004215f,
+ 0.004597f, 0.005013f, 0.005520f, 0.006130f, 0.006821f, 0.007690f, 0.008789f, 0.010452f, 0.012909f, 0.016174f, 0.312012f, 0.390381f,
+ 0.410645f, 0.420654f, 0.426270f, 0.430664f, 0.000057f, 0.000171f, 0.000164f, 0.000170f, 0.000211f, 0.000213f, 0.000229f, 0.000247f,
+ 0.000267f, 0.000279f, 0.000289f, 0.000317f, 0.000349f, 0.000364f, 0.000390f, 0.000407f, 0.000427f, 0.000467f, 0.000476f, 0.000521f,
+ 0.000537f, 0.000561f, 0.000578f, 0.000626f, 0.000667f, 0.000714f, 0.000729f, 0.000753f, 0.000806f, 0.000855f, 0.000911f, 0.000945f,
+ 0.001004f, 0.001054f, 0.001112f, 0.001172f, 0.001251f, 0.001333f, 0.001406f, 0.001489f, 0.001595f, 0.001694f, 0.001811f, 0.001952f,
+ 0.002090f, 0.002243f, 0.002453f, 0.002638f, 0.002888f, 0.003143f, 0.003489f, 0.003870f, 0.004353f, 0.004921f, 0.005672f, 0.006664f,
+ 0.008423f, 0.011230f, 0.301758f, 0.381104f, 0.402832f, 0.413330f, 0.418457f, 0.423828f, 0.000096f, 0.000112f, 0.000097f, 0.000090f,
+ 0.000113f, 0.000119f, 0.000144f, 0.000149f, 0.000151f, 0.000158f, 0.000181f, 0.000184f, 0.000179f, 0.000201f, 0.000224f, 0.000216f,
+ 0.000237f, 0.000255f, 0.000263f, 0.000276f, 0.000297f, 0.000308f, 0.000332f, 0.000347f, 0.000369f, 0.000395f, 0.000408f, 0.000422f,
+ 0.000447f, 0.000471f, 0.000500f, 0.000531f, 0.000554f, 0.000583f, 0.000617f, 0.000660f, 0.000690f, 0.000739f, 0.000795f, 0.000833f,
+ 0.000885f, 0.000948f, 0.001022f, 0.001085f, 0.001175f, 0.001262f, 0.001371f, 0.001487f, 0.001633f, 0.001778f, 0.001986f, 0.002218f,
+ 0.002502f, 0.002865f, 0.003330f, 0.003979f, 0.004932f, 0.007000f, 0.291260f, 0.372070f, 0.394043f, 0.404541f, 0.412109f, 0.416260f,
+ 0.000000f, 0.000056f, 0.000049f, 0.000061f, 0.000064f, 0.000061f, 0.000062f, 0.000071f, 0.000072f, 0.000088f, 0.000083f, 0.000086f,
+ 0.000097f, 0.000094f, 0.000098f, 0.000105f, 0.000116f, 0.000122f, 0.000126f, 0.000134f, 0.000137f, 0.000143f, 0.000150f, 0.000164f,
+ 0.000171f, 0.000183f, 0.000188f, 0.000204f, 0.000214f, 0.000224f, 0.000236f, 0.000255f, 0.000258f, 0.000277f, 0.000293f, 0.000315f,
+ 0.000328f, 0.000349f, 0.000376f, 0.000396f, 0.000426f, 0.000454f, 0.000486f, 0.000521f, 0.000563f, 0.000605f, 0.000657f, 0.000714f,
+ 0.000791f, 0.000866f, 0.000977f, 0.001085f, 0.001243f, 0.001441f, 0.001703f, 0.002058f, 0.002573f, 0.003740f, 0.280029f, 0.362793f,
+ 0.385742f, 0.397217f, 0.404297f, 0.408936f, 0.000058f, 0.000038f, 0.000031f, 0.000027f, 0.000025f, 0.000026f, 0.000025f, 0.000024f,
+ 0.000024f, 0.000027f, 0.000030f, 0.000038f, 0.000032f, 0.000035f, 0.000040f, 0.000041f, 0.000044f, 0.000045f, 0.000045f, 0.000047f,
+ 0.000052f, 0.000058f, 0.000061f, 0.000059f, 0.000065f, 0.000067f, 0.000069f, 0.000073f, 0.000078f, 0.000083f, 0.000089f, 0.000091f,
+ 0.000099f, 0.000103f, 0.000106f, 0.000114f, 0.000124f, 0.000132f, 0.000141f, 0.000150f, 0.000158f, 0.000164f, 0.000180f, 0.000193f,
+ 0.000205f, 0.000225f, 0.000245f, 0.000267f, 0.000297f, 0.000329f, 0.000365f, 0.000416f, 0.000479f, 0.000563f, 0.000676f, 0.000839f,
+ 0.001088f, 0.001589f, 0.270264f, 0.353760f, 0.377197f, 0.390137f, 0.396973f, 0.402100f, 0.000030f, 0.000019f, 0.000016f, 0.000014f,
+ 0.000013f, 0.000012f, 0.000011f, 0.000011f, 0.000010f, 0.000010f, 0.000009f, 0.000009f, 0.000009f, 0.000008f, 0.000007f, 0.000009f,
+ 0.000009f, 0.000008f, 0.000009f, 0.000010f, 0.000011f, 0.000012f, 0.000012f, 0.000014f, 0.000014f, 0.000014f, 0.000015f, 0.000018f,
+ 0.000017f, 0.000017f, 0.000019f, 0.000020f, 0.000022f, 0.000022f, 0.000023f, 0.000026f, 0.000028f, 0.000027f, 0.000030f, 0.000032f,
+ 0.000035f, 0.000038f, 0.000040f, 0.000042f, 0.000045f, 0.000049f, 0.000055f, 0.000060f, 0.000065f, 0.000074f, 0.000078f, 0.000095f,
+ 0.000109f, 0.000129f, 0.000160f, 0.000205f, 0.000284f, 0.000452f, 0.259766f, 0.345703f, 0.369629f, 0.382812f, 0.390625f, 0.395264f,
+ 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000000f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f,
+ 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000001f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f, 0.000002f,
+ 0.000002f, 0.000003f, 0.000003f, 0.000004f, 0.000004f, 0.000005f, 0.000006f, 0.000009f, 0.000012f, 0.000026f, 0.249878f, 0.336182f,
+ 0.362061f, 0.374512f, 0.382080f, 0.387695f,
+ }
+};
+
+/* 4 different blue noise, one per channel */
+static float blue_noise[64 * 64][4] = {
+ {0.367188f, 0.855469f, 0.523438f, 0.375000f}, {0.242188f, 0.699219f, 0.164062f, 0.292969f},
+ {0.828125f, 0.257812f, 0.449219f, 0.679688f}, {0.128906f, 0.523438f, 0.058594f, 0.164062f},
+ {0.214844f, 0.648438f, 0.750000f, 0.492188f}, {0.535156f, 0.226562f, 0.492188f, 0.429688f},
+ {0.050781f, 0.425781f, 0.886719f, 0.019531f}, {0.199219f, 0.785156f, 0.378906f, 0.984375f},
+ {0.390625f, 0.039062f, 0.222656f, 0.777344f}, {0.574219f, 0.460938f, 0.687500f, 0.085938f},
+ {0.757812f, 0.117188f, 0.968750f, 0.343750f}, {0.109375f, 0.398438f, 0.500000f, 0.871094f},
+ {0.871094f, 0.796875f, 0.628906f, 0.132812f}, {0.289062f, 0.480469f, 0.851562f, 0.484375f},
+ {0.519531f, 0.035156f, 0.234375f, 0.832031f}, {0.390625f, 0.558594f, 0.738281f, 0.636719f},
+ {0.015625f, 0.648438f, 0.910156f, 0.507812f}, {0.199219f, 0.257812f, 0.640625f, 0.578125f},
+ {0.359375f, 0.976562f, 0.855469f, 0.726562f}, {0.523438f, 0.445312f, 0.335938f, 0.304688f},
+ {0.046875f, 0.296875f, 0.921875f, 0.687500f}, {0.476562f, 0.929688f, 0.777344f, 0.164062f},
+ {0.726562f, 0.515625f, 0.398438f, 0.781250f}, {0.652344f, 0.156250f, 0.191406f, 0.015625f},
+ {0.300781f, 0.695312f, 0.011719f, 0.417969f}, {0.433594f, 0.882812f, 0.738281f, 0.843750f},
+ {0.890625f, 0.308594f, 0.523438f, 0.496094f}, {0.589844f, 0.730469f, 0.050781f, 0.886719f},
+ {0.738281f, 0.539062f, 0.683594f, 0.640625f}, {0.421875f, 0.191406f, 0.265625f, 0.996094f},
+ {0.609375f, 0.339844f, 0.617188f, 0.066406f}, {0.371094f, 0.398438f, 0.378906f, 0.898438f},
+ {0.937500f, 0.578125f, 0.136719f, 0.136719f}, {0.453125f, 0.820312f, 0.664062f, 0.968750f},
+ {0.828125f, 0.070312f, 0.316406f, 0.328125f}, {0.558594f, 0.714844f, 0.593750f, 0.714844f},
+ {0.351562f, 0.781250f, 0.355469f, 0.804688f}, {0.203125f, 0.398438f, 0.214844f, 0.519531f},
+ {0.785156f, 0.207031f, 0.398438f, 0.453125f}, {0.617188f, 0.289062f, 0.281250f, 0.257812f},
+ {0.171875f, 0.609375f, 0.792969f, 0.027344f}, {0.539062f, 0.871094f, 0.007812f, 0.886719f},
+ {0.019531f, 0.246094f, 0.226562f, 0.363281f}, {0.988281f, 0.582031f, 0.777344f, 0.054688f},
+ {0.468750f, 0.933594f, 0.312500f, 0.246094f}, {0.218750f, 0.015625f, 0.851562f, 0.167969f},
+ {0.566406f, 0.699219f, 0.519531f, 0.902344f}, {0.125000f, 0.507812f, 0.136719f, 0.386719f},
+ {0.296875f, 0.812500f, 0.558594f, 0.203125f}, {0.402344f, 0.199219f, 0.058594f, 0.875000f},
+ {0.898438f, 0.386719f, 0.664062f, 0.660156f}, {0.027344f, 0.078125f, 0.296875f, 0.453125f},
+ {0.667969f, 0.828125f, 0.808594f, 0.171875f}, {0.257812f, 0.535156f, 0.464844f, 0.914062f},
+ {0.597656f, 0.363281f, 0.886719f, 0.718750f}, {0.332031f, 0.042969f, 0.683594f, 0.003906f},
+ {0.632812f, 0.480469f, 0.429688f, 0.425781f}, {0.226562f, 0.910156f, 0.566406f, 0.558594f},
+ {0.496094f, 0.062500f, 0.863281f, 0.226562f}, {0.105469f, 0.976562f, 0.707031f, 0.941406f},
+ {0.394531f, 0.203125f, 0.285156f, 0.277344f}, {0.003906f, 0.804688f, 0.781250f, 0.050781f},
+ {0.210938f, 0.289062f, 0.117188f, 0.601562f}, {0.972656f, 0.179688f, 0.589844f, 0.144531f},
+ {0.152344f, 0.359375f, 0.730469f, 0.449219f}, {0.765625f, 0.105469f, 0.292969f, 0.101562f},
+ {0.519531f, 0.812500f, 0.617188f, 0.976562f}, {0.988281f, 0.960938f, 0.902344f, 0.054688f},
+ {0.457031f, 0.738281f, 0.335938f, 0.875000f}, {0.871094f, 0.121094f, 0.195312f, 0.210938f},
+ {0.781250f, 0.296875f, 0.539062f, 0.585938f}, {0.636719f, 0.667969f, 0.621094f, 0.328125f},
+ {0.324219f, 0.929688f, 0.855469f, 0.148438f}, {0.984375f, 0.718750f, 0.421875f, 0.824219f},
+ {0.500000f, 0.308594f, 0.757812f, 0.699219f}, {0.664062f, 0.214844f, 0.269531f, 0.558594f},
+ {0.414062f, 0.984375f, 0.074219f, 0.757812f}, {0.589844f, 0.339844f, 0.925781f, 0.273438f},
+ {0.089844f, 0.847656f, 0.316406f, 0.398438f}, {0.695312f, 0.921875f, 0.460938f, 0.890625f},
+ {0.894531f, 0.093750f, 0.113281f, 0.347656f}, {0.562500f, 0.386719f, 0.289062f, 0.964844f},
+ {0.121094f, 0.820312f, 0.003906f, 0.214844f}, {0.765625f, 0.187500f, 0.710938f, 0.914062f},
+ {0.878906f, 0.773438f, 0.445312f, 0.078125f}, {0.218750f, 0.117188f, 0.613281f, 0.617188f},
+ {0.085938f, 0.652344f, 0.996094f, 0.339844f}, {0.863281f, 0.359375f, 0.496094f, 0.531250f},
+ {0.148438f, 0.437500f, 0.320312f, 0.695312f}, {0.503906f, 0.613281f, 0.792969f, 0.082031f},
+ {0.097656f, 0.109375f, 0.960938f, 0.238281f}, {0.246094f, 0.914062f, 0.414062f, 0.328125f},
+ {0.011719f, 0.648438f, 0.828125f, 0.738281f}, {0.980469f, 0.457031f, 0.343750f, 0.117188f},
+ {0.140625f, 0.937500f, 0.976562f, 0.601562f}, {0.234375f, 0.867188f, 0.574219f, 0.230469f},
+ {0.542969f, 0.519531f, 0.902344f, 0.402344f}, {0.027344f, 0.300781f, 0.253906f, 0.503906f},
+ {0.757812f, 0.964844f, 0.949219f, 0.058594f}, {0.152344f, 0.234375f, 0.039062f, 0.925781f},
+ {0.687500f, 0.628906f, 0.492188f, 0.386719f}, {0.929688f, 0.546875f, 0.667969f, 0.109375f},
+ {0.269531f, 0.136719f, 0.964844f, 0.617188f}, {0.320312f, 0.464844f, 0.542969f, 0.972656f},
+ {0.960938f, 0.960938f, 0.171875f, 0.093750f}, {0.355469f, 0.523438f, 0.429688f, 0.765625f},
+ {0.246094f, 0.328125f, 0.992188f, 0.496094f}, {0.648438f, 0.074219f, 0.097656f, 0.605469f},
+ {0.144531f, 0.648438f, 0.476562f, 0.808594f}, {0.855469f, 0.832031f, 0.195312f, 0.546875f},
+ {0.925781f, 0.414062f, 0.960938f, 0.675781f}, {0.000000f, 0.113281f, 0.746094f, 0.835938f},
+ {0.828125f, 0.324219f, 0.613281f, 0.500000f}, {0.699219f, 0.738281f, 0.332031f, 0.125000f},
+ {0.542969f, 0.906250f, 0.898438f, 0.250000f}, {0.105469f, 0.632812f, 0.511719f, 0.062500f},
+ {0.433594f, 0.273438f, 0.097656f, 0.816406f}, {0.511719f, 0.707031f, 0.593750f, 0.632812f},
+ {0.179688f, 0.980469f, 0.367188f, 0.335938f}, {0.882812f, 0.113281f, 0.031250f, 0.980469f},
+ {0.410156f, 0.656250f, 0.253906f, 0.675781f}, {0.039062f, 0.300781f, 0.785156f, 0.800781f},
+ {0.695312f, 0.382812f, 0.386719f, 0.156250f}, {0.847656f, 0.457031f, 0.000000f, 0.847656f},
+ {0.945312f, 0.542969f, 0.664062f, 0.683594f}, {0.730469f, 0.707031f, 0.238281f, 0.535156f},
+ {0.472656f, 0.921875f, 0.871094f, 0.910156f}, {0.867188f, 0.601562f, 0.031250f, 0.812500f},
+ {0.632812f, 0.769531f, 0.925781f, 0.625000f}, {0.433594f, 0.558594f, 0.078125f, 0.851562f},
+ {0.015625f, 0.187500f, 0.792969f, 0.515625f}, {0.343750f, 0.386719f, 0.562500f, 0.773438f},
+ {0.679688f, 0.035156f, 0.121094f, 0.347656f}, {0.300781f, 0.582031f, 0.703125f, 0.660156f},
+ {0.152344f, 0.878906f, 0.929688f, 0.902344f}, {0.433594f, 0.507812f, 0.093750f, 0.460938f},
+ {0.714844f, 0.171875f, 0.042969f, 0.531250f}, {0.828125f, 0.550781f, 0.312500f, 0.945312f},
+ {0.011719f, 0.894531f, 0.136719f, 0.417969f}, {0.257812f, 0.046875f, 0.562500f, 0.226562f},
+ {0.187500f, 0.601562f, 0.800781f, 0.929688f}, {0.949219f, 0.128906f, 0.437500f, 0.613281f},
+ {0.816406f, 0.277344f, 0.054688f, 0.035156f}, {0.226562f, 0.425781f, 0.542969f, 0.183594f},
+ {0.628906f, 0.750000f, 0.984375f, 0.113281f}, {0.839844f, 0.003906f, 0.792969f, 0.796875f},
+ {0.269531f, 0.324219f, 0.496094f, 0.003906f}, {0.683594f, 0.601562f, 0.574219f, 0.546875f},
+ {0.957031f, 0.703125f, 0.164062f, 0.378906f}, {0.605469f, 0.398438f, 0.078125f, 0.855469f},
+ {0.449219f, 0.250000f, 0.257812f, 0.988281f}, {0.367188f, 0.964844f, 0.859375f, 0.195312f},
+ {0.820312f, 0.007812f, 0.125000f, 0.753906f}, {0.625000f, 0.832031f, 0.453125f, 0.609375f},
+ {0.929688f, 0.230469f, 0.246094f, 0.925781f}, {0.394531f, 0.375000f, 0.097656f, 0.550781f},
+ {0.558594f, 0.148438f, 0.183594f, 0.191406f}, {0.480469f, 0.796875f, 0.488281f, 0.785156f},
+ {0.714844f, 0.250000f, 0.011719f, 0.296875f}, {0.660156f, 0.085938f, 0.804688f, 0.691406f},
+ {0.890625f, 0.695312f, 0.101562f, 0.855469f}, {0.320312f, 0.195312f, 0.441406f, 0.761719f},
+ {0.265625f, 0.375000f, 0.765625f, 0.191406f}, {0.996094f, 0.113281f, 0.832031f, 0.585938f},
+ {0.101562f, 0.882812f, 0.152344f, 0.285156f}, {0.468750f, 0.332031f, 0.722656f, 0.882812f},
+ {0.656250f, 0.816406f, 0.105469f, 0.339844f}, {0.035156f, 0.703125f, 0.855469f, 0.687500f},
+ {0.738281f, 0.003906f, 0.601562f, 0.566406f}, {0.441406f, 0.664062f, 0.703125f, 0.843750f},
+ {0.875000f, 0.789062f, 0.839844f, 0.187500f}, {0.781250f, 0.457031f, 0.640625f, 0.996094f},
+ {0.050781f, 0.210938f, 0.355469f, 0.332031f}, {0.363281f, 0.351562f, 0.039062f, 0.421875f},
+ {0.429688f, 0.550781f, 0.699219f, 0.089844f}, {0.753906f, 0.917969f, 0.269531f, 0.285156f},
+ {0.496094f, 0.058594f, 0.929688f, 0.980469f}, {0.343750f, 0.445312f, 0.445312f, 0.566406f},
+ {0.152344f, 0.160156f, 0.003906f, 0.750000f}, {0.738281f, 0.570312f, 0.847656f, 0.941406f},
+ {0.808594f, 0.027344f, 0.167969f, 0.292969f}, {0.992188f, 0.867188f, 0.921875f, 0.519531f},
+ {0.074219f, 0.187500f, 0.761719f, 0.199219f}, {0.750000f, 0.597656f, 0.312500f, 0.472656f},
+ {0.277344f, 0.753906f, 0.945312f, 0.089844f}, {0.796875f, 0.820312f, 0.511719f, 0.375000f},
+ {0.542969f, 0.878906f, 0.191406f, 0.503906f}, {0.175781f, 0.632812f, 0.597656f, 0.109375f},
+ {0.257812f, 0.335938f, 0.980469f, 0.339844f}, {0.664062f, 0.000000f, 0.542969f, 0.417969f},
+ {0.324219f, 0.144531f, 0.410156f, 0.078125f}, {0.062500f, 0.437500f, 0.472656f, 0.250000f},
+ {0.925781f, 0.058594f, 0.636719f, 0.332031f}, {0.269531f, 0.671875f, 0.234375f, 0.175781f},
+ {0.714844f, 0.285156f, 0.382812f, 0.574219f}, {0.570312f, 0.906250f, 0.988281f, 0.414062f},
+ {0.097656f, 0.460938f, 0.425781f, 0.257812f}, {0.953125f, 0.796875f, 0.265625f, 0.117188f},
+ {0.589844f, 0.367188f, 0.777344f, 0.746094f}, {0.035156f, 0.082031f, 0.457031f, 0.062500f},
+ {0.226562f, 0.253906f, 0.953125f, 0.628906f}, {0.527344f, 0.417969f, 0.519531f, 0.261719f},
+ {0.132812f, 0.812500f, 0.828125f, 0.000000f}, {0.906250f, 0.660156f, 0.386719f, 0.367188f},
+ {0.742188f, 0.500000f, 0.207031f, 0.093750f}, {0.359375f, 0.769531f, 0.609375f, 0.718750f},
+ {0.480469f, 0.695312f, 0.679688f, 0.539062f}, {0.144531f, 0.179688f, 0.757812f, 0.765625f},
+ {0.332031f, 0.625000f, 0.179688f, 0.679688f}, {0.445312f, 0.492188f, 0.378906f, 0.425781f},
+ {0.035156f, 0.550781f, 0.230469f, 0.476562f}, {0.402344f, 0.898438f, 0.898438f, 0.652344f},
+ {0.156250f, 0.046875f, 0.820312f, 0.132812f}, {0.328125f, 0.484375f, 0.679688f, 0.246094f},
+ {0.746094f, 0.750000f, 0.363281f, 0.453125f}, {0.238281f, 0.863281f, 0.558594f, 0.105469f},
+ {0.023438f, 0.289062f, 0.648438f, 0.292969f}, {0.683594f, 0.566406f, 0.906250f, 0.804688f},
+ {0.335938f, 0.773438f, 0.601562f, 0.375000f}, {0.781250f, 0.496094f, 0.710938f, 0.023438f},
+ {0.847656f, 0.996094f, 0.929688f, 0.425781f}, {0.308594f, 0.027344f, 0.656250f, 0.871094f},
+ {0.183594f, 0.625000f, 0.292969f, 0.480469f}, {0.089844f, 0.753906f, 0.164062f, 0.363281f},
+ {0.804688f, 0.476562f, 0.687500f, 0.011719f}, {0.503906f, 0.910156f, 0.523438f, 0.644531f},
+ {0.605469f, 0.609375f, 0.203125f, 0.441406f}, {0.417969f, 0.742188f, 0.621094f, 0.085938f},
+ {0.839844f, 0.441406f, 0.296875f, 0.679688f}, {0.531250f, 0.042969f, 0.929688f, 0.781250f},
+ {0.378906f, 0.929688f, 0.460938f, 0.148438f}, {0.902344f, 0.238281f, 0.050781f, 0.222656f},
+ {0.570312f, 0.378906f, 0.328125f, 0.390625f}, {0.105469f, 0.121094f, 0.253906f, 0.460938f},
+ {0.500000f, 0.906250f, 0.515625f, 0.281250f}, {0.296875f, 0.160156f, 0.148438f, 0.664062f},
+ {0.699219f, 0.722656f, 0.757812f, 0.007812f}, {0.539062f, 0.968750f, 0.589844f, 0.914062f},
+ {0.253906f, 0.246094f, 0.406250f, 0.769531f}, {0.609375f, 0.613281f, 0.105469f, 0.707031f},
+ {0.195312f, 0.687500f, 0.179688f, 0.031250f}, {0.949219f, 0.523438f, 0.785156f, 0.339844f},
+ {0.863281f, 0.804688f, 0.234375f, 0.433594f}, {0.230469f, 0.355469f, 0.648438f, 0.687500f},
+ {0.304688f, 0.757812f, 0.421875f, 0.378906f}, {0.375000f, 0.464844f, 0.539062f, 0.046875f},
+ {0.558594f, 0.324219f, 0.214844f, 0.761719f}, {0.679688f, 0.410156f, 0.074219f, 0.839844f},
+ {0.464844f, 0.519531f, 0.710938f, 0.281250f}, {0.968750f, 0.152344f, 0.140625f, 0.925781f},
+ {0.359375f, 0.230469f, 0.902344f, 0.609375f}, {0.593750f, 0.097656f, 0.457031f, 0.761719f},
+ {0.441406f, 0.785156f, 0.058594f, 0.960938f}, {0.125000f, 0.890625f, 0.312500f, 0.203125f},
+ {0.812500f, 0.488281f, 0.804688f, 0.878906f}, {0.558594f, 0.992188f, 0.175781f, 0.742188f},
+ {0.179688f, 0.222656f, 0.343750f, 0.039062f}, {0.789062f, 0.871094f, 0.843750f, 0.949219f},
+ {0.902344f, 0.503906f, 0.507812f, 0.718750f}, {0.402344f, 0.625000f, 0.027344f, 0.011719f},
+ {0.195312f, 0.152344f, 0.605469f, 0.929688f}, {0.753906f, 0.214844f, 0.160156f, 0.839844f},
+ {0.488281f, 0.687500f, 0.671875f, 0.390625f}, {0.851562f, 0.992188f, 0.363281f, 0.191406f},
+ {0.933594f, 0.617188f, 0.230469f, 0.308594f}, {0.375000f, 0.746094f, 0.656250f, 0.867188f},
+ {0.613281f, 0.105469f, 0.898438f, 0.671875f}, {0.316406f, 0.371094f, 0.714844f, 0.503906f},
+ {0.687500f, 0.234375f, 0.031250f, 0.808594f}, {0.550781f, 0.957031f, 0.957031f, 0.433594f},
+ {0.023438f, 0.539062f, 0.351562f, 0.308594f}, {0.964844f, 0.359375f, 0.261719f, 0.980469f},
+ {0.750000f, 0.941406f, 0.863281f, 0.234375f}, {0.906250f, 0.863281f, 0.605469f, 0.863281f},
+ {0.503906f, 0.109375f, 0.093750f, 0.289062f}, {0.582031f, 0.238281f, 0.414062f, 0.949219f},
+ {0.792969f, 0.992188f, 0.308594f, 0.757812f}, {0.062500f, 0.164062f, 0.039062f, 0.816406f},
+ {0.902344f, 0.542969f, 0.933594f, 0.675781f}, {0.554688f, 0.085938f, 0.726562f, 0.507812f},
+ {0.984375f, 0.460938f, 0.175781f, 0.890625f}, {0.468750f, 0.179688f, 0.027344f, 0.140625f},
+ {0.125000f, 0.679688f, 0.304688f, 0.468750f}, {0.203125f, 0.058594f, 0.531250f, 0.953125f},
+ {0.070312f, 0.328125f, 0.375000f, 0.667969f}, {0.746094f, 0.554688f, 0.785156f, 0.578125f},
+ {0.917969f, 0.421875f, 0.558594f, 0.089844f}, {0.445312f, 0.289062f, 0.855469f, 0.937500f},
+ {0.378906f, 0.156250f, 0.398438f, 0.539062f}, {0.066406f, 0.015625f, 0.335938f, 0.265625f},
+ {0.730469f, 0.812500f, 0.878906f, 0.820312f}, {0.191406f, 0.535156f, 0.015625f, 0.988281f},
+ {0.046875f, 0.171875f, 0.554688f, 0.484375f}, {0.777344f, 0.656250f, 0.375000f, 0.015625f},
+ {0.230469f, 0.488281f, 0.238281f, 0.535156f}, {0.144531f, 0.578125f, 0.750000f, 0.910156f},
+ {0.812500f, 0.757812f, 0.910156f, 0.714844f}, {0.207031f, 0.429688f, 0.386719f, 0.042969f},
+ {0.945312f, 0.292969f, 0.023438f, 0.136719f}, {0.597656f, 0.859375f, 0.941406f, 0.742188f},
+ {0.171875f, 0.593750f, 0.289062f, 0.519531f}, {0.914062f, 0.031250f, 0.886719f, 0.234375f},
+ {0.808594f, 0.773438f, 0.824219f, 0.160156f}, {0.082031f, 0.132812f, 0.496094f, 0.464844f},
+ {0.664062f, 0.871094f, 0.675781f, 0.597656f}, {0.042969f, 0.289062f, 0.546875f, 0.195312f},
+ {0.453125f, 0.996094f, 0.363281f, 0.859375f}, {0.585938f, 0.226562f, 0.718750f, 0.140625f},
+ {0.648438f, 0.093750f, 0.277344f, 0.609375f}, {0.035156f, 0.933594f, 0.980469f, 0.898438f},
+ {0.910156f, 0.671875f, 0.625000f, 0.410156f}, {0.210938f, 0.246094f, 0.472656f, 0.578125f},
+ {0.136719f, 0.960938f, 0.832031f, 0.031250f}, {0.066406f, 0.054688f, 0.656250f, 0.660156f},
+ {0.898438f, 0.714844f, 0.347656f, 0.218750f}, {0.765625f, 0.589844f, 0.820312f, 0.449219f},
+ {0.023438f, 0.398438f, 0.734375f, 0.011719f}, {0.960938f, 0.253906f, 0.132812f, 0.582031f},
+ {0.378906f, 0.644531f, 0.945312f, 0.480469f}, {0.496094f, 0.320312f, 0.683594f, 0.656250f},
+ {0.085938f, 0.722656f, 0.105469f, 0.386719f}, {0.316406f, 0.414062f, 0.753906f, 0.226562f},
+ {0.046875f, 0.011719f, 0.199219f, 0.464844f}, {0.621094f, 0.968750f, 0.714844f, 0.300781f},
+ {0.878906f, 0.726562f, 0.863281f, 0.593750f}, {0.257812f, 0.312500f, 0.324219f, 0.523438f},
+ {0.347656f, 0.835938f, 0.816406f, 0.687500f}, {0.074219f, 0.480469f, 0.000000f, 0.972656f},
+ {0.656250f, 0.007812f, 0.578125f, 0.785156f}, {0.792969f, 0.914062f, 0.152344f, 0.570312f},
+ {0.464844f, 0.292969f, 0.292969f, 0.152344f}, {0.863281f, 0.843750f, 0.101562f, 0.957031f},
+ {0.066406f, 0.449219f, 0.484375f, 0.199219f}, {0.437500f, 0.019531f, 0.878906f, 0.886719f},
+ {0.800781f, 0.074219f, 0.132812f, 0.136719f}, {0.296875f, 0.800781f, 0.511719f, 0.488281f},
+ {0.656250f, 0.253906f, 0.019531f, 0.371094f}, {0.101562f, 0.148438f, 0.726562f, 0.609375f},
+ {0.203125f, 0.664062f, 0.660156f, 0.089844f}, {0.976562f, 0.437500f, 0.972656f, 0.175781f},
+ {0.289062f, 0.781250f, 0.765625f, 0.578125f}, {0.660156f, 0.343750f, 0.519531f, 0.312500f},
+ {0.507812f, 0.625000f, 0.441406f, 0.019531f}, {0.175781f, 0.933594f, 0.230469f, 0.394531f},
+ {0.796875f, 0.722656f, 0.824219f, 0.570312f}, {0.277344f, 0.410156f, 0.406250f, 0.226562f},
+ {0.597656f, 0.949219f, 0.761719f, 0.707031f}, {0.949219f, 0.609375f, 0.882812f, 0.070312f},
+ {0.519531f, 0.859375f, 0.128906f, 0.273438f}, {0.632812f, 0.203125f, 0.042969f, 0.156250f},
+ {0.265625f, 0.890625f, 0.449219f, 0.812500f}, {0.585938f, 0.664062f, 0.230469f, 0.210938f},
+ {0.968750f, 0.960938f, 0.742188f, 0.726562f}, {0.226562f, 0.339844f, 0.992188f, 0.117188f},
+ {0.875000f, 0.410156f, 0.093750f, 0.894531f}, {0.640625f, 0.261719f, 0.710938f, 0.324219f},
+ {0.917969f, 0.980469f, 0.425781f, 0.234375f}, {0.308594f, 0.300781f, 0.804688f, 0.628906f},
+ {0.589844f, 0.105469f, 0.648438f, 0.421875f}, {0.714844f, 0.847656f, 0.125000f, 0.808594f},
+ {0.406250f, 0.187500f, 0.480469f, 0.300781f}, {0.667969f, 0.992188f, 0.679688f, 0.960938f},
+ {0.070312f, 0.542969f, 0.800781f, 0.859375f}, {0.835938f, 0.082031f, 0.554688f, 0.578125f},
+ {0.398438f, 0.496094f, 0.449219f, 0.402344f}, {0.113281f, 0.398438f, 0.222656f, 0.828125f},
+ {0.460938f, 0.308594f, 0.054688f, 0.625000f}, {0.976562f, 0.472656f, 0.984375f, 0.375000f},
+ {0.281250f, 0.203125f, 0.312500f, 0.937500f}, {0.386719f, 0.000000f, 0.875000f, 0.785156f},
+ {0.785156f, 0.402344f, 0.078125f, 0.527344f}, {0.117188f, 0.644531f, 0.812500f, 0.082031f},
+ {0.941406f, 0.503906f, 0.132812f, 0.972656f}, {0.488281f, 0.140625f, 0.023438f, 0.238281f},
+ {0.832031f, 0.843750f, 0.859375f, 0.167969f}, {0.335938f, 0.011719f, 0.382812f, 0.730469f},
+ {0.628906f, 0.777344f, 0.570312f, 0.875000f}, {0.527344f, 0.355469f, 0.285156f, 0.132812f},
+ {0.234375f, 0.472656f, 0.093750f, 0.312500f}, {0.308594f, 0.941406f, 0.214844f, 0.820312f},
+ {0.640625f, 0.164062f, 0.628906f, 0.714844f}, {0.871094f, 0.832031f, 0.390625f, 0.156250f},
+ {0.218750f, 0.531250f, 0.265625f, 0.289062f}, {0.699219f, 0.117188f, 0.550781f, 0.796875f},
+ {0.980469f, 0.578125f, 0.890625f, 0.125000f}, {0.523438f, 0.824219f, 0.460938f, 0.890625f},
+ {0.445312f, 0.347656f, 0.285156f, 0.675781f}, {0.816406f, 0.097656f, 0.949219f, 0.781250f},
+ {0.140625f, 0.550781f, 0.089844f, 0.160156f}, {0.675781f, 0.421875f, 0.484375f, 0.074219f},
+ {0.542969f, 0.062500f, 0.535156f, 0.230469f}, {0.421875f, 0.570312f, 0.886719f, 0.484375f},
+ {0.167969f, 0.339844f, 0.734375f, 0.035156f}, {0.277344f, 0.199219f, 0.425781f, 0.441406f},
+ {0.093750f, 0.527344f, 0.996094f, 0.714844f}, {0.214844f, 0.148438f, 0.632812f, 0.335938f},
+ {0.941406f, 0.585938f, 0.242188f, 0.593750f}, {0.160156f, 0.886719f, 0.410156f, 0.652344f},
+ {0.597656f, 0.679688f, 0.812500f, 0.019531f}, {0.242188f, 0.312500f, 0.585938f, 0.562500f},
+ {0.531250f, 0.460938f, 0.937500f, 0.921875f}, {0.375000f, 0.734375f, 0.328125f, 0.054688f},
+ {0.703125f, 0.382812f, 0.472656f, 0.734375f}, {0.824219f, 0.835938f, 0.140625f, 0.519531f},
+ {0.441406f, 0.289062f, 0.203125f, 0.414062f}, {0.121094f, 0.691406f, 0.628906f, 0.925781f},
+ {0.378906f, 0.019531f, 0.105469f, 0.082031f}, {0.714844f, 0.222656f, 0.347656f, 0.734375f},
+ {0.046875f, 0.816406f, 0.968750f, 0.976562f}, {0.421875f, 0.320312f, 0.078125f, 0.628906f},
+ {0.871094f, 0.097656f, 0.484375f, 0.835938f}, {0.695312f, 0.265625f, 0.207031f, 0.332031f},
+ {0.351562f, 0.718750f, 0.273438f, 0.761719f}, {0.406250f, 0.382812f, 0.957031f, 0.511719f},
+ {0.042969f, 0.785156f, 0.628906f, 0.980469f}, {0.832031f, 0.117188f, 0.910156f, 0.343750f},
+ {0.144531f, 0.500000f, 0.058594f, 0.421875f}, {0.699219f, 0.843750f, 0.589844f, 0.601562f},
+ {0.546875f, 0.574219f, 0.488281f, 0.164062f}, {0.363281f, 0.054688f, 0.265625f, 0.390625f},
+ {0.128906f, 0.785156f, 0.949219f, 0.746094f}, {0.492188f, 0.691406f, 0.175781f, 0.949219f},
+ {0.972656f, 0.902344f, 0.894531f, 0.183594f}, {0.027344f, 0.359375f, 0.570312f, 0.070312f},
+ {0.273438f, 0.062500f, 0.207031f, 0.500000f}, {0.472656f, 0.730469f, 0.972656f, 0.613281f},
+ {0.351562f, 0.640625f, 0.089844f, 0.363281f}, {0.742188f, 0.226562f, 0.187500f, 0.195312f},
+ {0.234375f, 0.699219f, 0.730469f, 0.945312f}, {0.625000f, 0.945312f, 0.636719f, 0.082031f},
+ {0.328125f, 0.839844f, 0.378906f, 0.312500f}, {0.707031f, 0.652344f, 0.574219f, 0.875000f},
+ {0.566406f, 0.742188f, 0.148438f, 0.050781f}, {0.882812f, 0.921875f, 0.460938f, 0.246094f},
+ {0.519531f, 0.585938f, 0.917969f, 0.656250f}, {0.730469f, 0.718750f, 0.597656f, 0.316406f},
+ {0.261719f, 0.808594f, 0.500000f, 0.460938f}, {0.171875f, 0.285156f, 0.324219f, 0.796875f},
+ {0.773438f, 0.562500f, 0.746094f, 0.546875f}, {0.433594f, 0.429688f, 0.183594f, 0.343750f},
+ {0.726562f, 0.628906f, 0.050781f, 0.488281f}, {0.859375f, 0.898438f, 0.972656f, 0.996094f},
+ {0.402344f, 0.542969f, 0.429688f, 0.402344f}, {0.101562f, 0.304688f, 0.535156f, 0.542969f},
+ {0.476562f, 0.675781f, 0.863281f, 0.902344f}, {0.734375f, 0.035156f, 0.488281f, 0.359375f},
+ {0.289062f, 0.761719f, 0.773438f, 0.976562f}, {0.589844f, 0.949219f, 0.007812f, 0.519531f},
+ {0.843750f, 0.269531f, 0.417969f, 0.835938f}, {0.664062f, 0.183594f, 0.144531f, 0.554688f},
+ {0.226562f, 0.652344f, 0.656250f, 0.085938f}, {0.367188f, 0.789062f, 0.562500f, 0.957031f},
+ {0.972656f, 0.238281f, 0.394531f, 0.433594f}, {0.000000f, 0.894531f, 0.207031f, 0.644531f},
+ {0.777344f, 0.136719f, 0.968750f, 0.820312f}, {0.910156f, 0.949219f, 0.261719f, 0.355469f},
+ {0.722656f, 0.785156f, 0.070312f, 0.917969f}, {0.996094f, 0.707031f, 0.792969f, 0.105469f},
+ {0.562500f, 0.644531f, 0.511719f, 0.246094f}, {0.648438f, 0.937500f, 0.335938f, 0.851562f},
+ {0.398438f, 0.738281f, 0.777344f, 0.078125f}, {0.832031f, 0.410156f, 0.695312f, 0.285156f},
+ {0.722656f, 0.210938f, 0.167969f, 0.785156f}, {0.042969f, 0.609375f, 0.296875f, 0.214844f},
+ {0.863281f, 0.976562f, 0.441406f, 0.824219f}, {0.167969f, 0.027344f, 0.066406f, 0.664062f},
+ {0.609375f, 0.562500f, 0.828125f, 0.347656f}, {0.000000f, 0.191406f, 0.562500f, 0.839844f},
+ {0.250000f, 0.070312f, 0.281250f, 0.207031f}, {0.875000f, 0.875000f, 0.917969f, 0.644531f},
+ {0.941406f, 0.523438f, 0.781250f, 0.867188f}, {0.617188f, 0.378906f, 0.687500f, 0.343750f},
+ {0.316406f, 0.132812f, 0.546875f, 0.171875f}, {0.542969f, 0.574219f, 0.609375f, 0.101562f},
+ {0.230469f, 0.484375f, 0.851562f, 0.433594f}, {0.007812f, 0.828125f, 0.671875f, 0.910156f},
+ {0.160156f, 0.160156f, 0.734375f, 0.605469f}, {0.890625f, 0.527344f, 0.351562f, 0.394531f},
+ {0.757812f, 0.042969f, 0.511719f, 0.039062f}, {0.507812f, 0.593750f, 0.144531f, 0.640625f},
+ {0.335938f, 0.238281f, 0.316406f, 0.781250f}, {0.464844f, 0.726562f, 0.191406f, 0.500000f},
+ {0.000000f, 0.093750f, 0.667969f, 0.707031f}, {0.273438f, 0.636719f, 0.843750f, 0.031250f},
+ {0.746094f, 0.210938f, 0.101562f, 0.570312f}, {0.437500f, 0.421875f, 0.343750f, 0.832031f},
+ {0.625000f, 0.519531f, 0.027344f, 0.355469f}, {0.824219f, 0.613281f, 0.777344f, 0.667969f},
+ {0.886719f, 0.261719f, 0.296875f, 0.121094f}, {0.554688f, 0.476562f, 0.609375f, 0.777344f},
+ {0.992188f, 0.328125f, 0.417969f, 0.253906f}, {0.007812f, 0.812500f, 0.339844f, 0.050781f},
+ {0.519531f, 0.371094f, 0.921875f, 0.476562f}, {0.867188f, 0.167969f, 0.121094f, 0.660156f},
+ {0.773438f, 0.054688f, 0.789062f, 0.718750f}, {0.066406f, 0.535156f, 0.253906f, 0.128906f},
+ {0.156250f, 0.343750f, 0.753906f, 0.503906f}, {0.218750f, 0.437500f, 0.027344f, 0.410156f},
+ {0.347656f, 0.070312f, 0.398438f, 0.839844f}, {0.019531f, 0.175781f, 0.222656f, 0.714844f},
+ {0.410156f, 0.375000f, 0.953125f, 0.011719f}, {0.605469f, 0.886719f, 0.652344f, 0.640625f},
+ {0.093750f, 0.082031f, 0.414062f, 0.097656f}, {0.289062f, 0.707031f, 0.886719f, 0.269531f},
+ {0.003906f, 0.195312f, 0.242188f, 0.691406f}, {0.980469f, 0.261719f, 0.781250f, 0.070312f},
+ {0.671875f, 0.070312f, 0.722656f, 0.621094f}, {0.820312f, 0.851562f, 0.914062f, 0.250000f},
+ {0.550781f, 0.429688f, 0.164062f, 0.097656f}, {0.140625f, 0.210938f, 0.082031f, 0.671875f},
+ {0.042969f, 0.367188f, 0.996094f, 0.054688f}, {0.394531f, 0.457031f, 0.605469f, 0.613281f},
+ {0.164062f, 0.695312f, 0.312500f, 0.417969f}, {0.109375f, 0.132812f, 0.929688f, 0.320312f},
+ {0.734375f, 0.937500f, 0.800781f, 0.207031f}, {0.578125f, 0.476562f, 0.039062f, 0.367188f},
+ {0.500000f, 0.382812f, 0.761719f, 0.859375f}, {0.304688f, 0.750000f, 0.628906f, 0.273438f},
+ {0.207031f, 0.617188f, 0.121094f, 0.730469f}, {0.597656f, 0.269531f, 0.683594f, 0.140625f},
+ {0.324219f, 0.445312f, 0.371094f, 0.613281f}, {0.027344f, 0.386719f, 0.187500f, 0.761719f},
+ {0.507812f, 0.093750f, 0.597656f, 0.546875f}, {0.769531f, 0.250000f, 0.015625f, 0.386719f},
+ {0.265625f, 0.335938f, 0.914062f, 0.472656f}, {0.335938f, 0.113281f, 0.539062f, 0.972656f},
+ {0.496094f, 0.828125f, 0.078125f, 0.730469f}, {0.980469f, 0.507812f, 0.656250f, 0.410156f},
+ {0.410156f, 0.093750f, 0.871094f, 0.148438f}, {0.777344f, 0.910156f, 0.238281f, 0.464844f},
+ {0.929688f, 0.644531f, 0.746094f, 0.253906f}, {0.343750f, 0.488281f, 0.394531f, 0.992188f},
+ {0.566406f, 0.949219f, 0.011719f, 0.117188f}, {0.476562f, 0.597656f, 0.859375f, 0.476562f},
+ {0.210938f, 0.449219f, 0.476562f, 0.273438f}, {0.816406f, 0.902344f, 0.156250f, 0.542969f},
+ {0.093750f, 0.738281f, 0.253906f, 0.773438f}, {0.964844f, 0.640625f, 0.316406f, 0.500000f},
+ {0.738281f, 0.925781f, 0.007812f, 0.257812f}, {0.828125f, 0.066406f, 0.433594f, 0.000000f},
+ {0.457031f, 0.437500f, 0.578125f, 0.187500f}, {0.667969f, 0.980469f, 0.089844f, 0.699219f},
+ {0.207031f, 0.351562f, 0.824219f, 0.886719f}, {0.105469f, 0.902344f, 0.703125f, 0.246094f},
+ {0.933594f, 0.183594f, 0.796875f, 0.070312f}, {0.796875f, 0.449219f, 0.457031f, 0.925781f},
+ {0.656250f, 0.945312f, 0.378906f, 0.289062f}, {0.957031f, 0.878906f, 0.769531f, 0.875000f},
+ {0.847656f, 0.335938f, 0.531250f, 0.097656f}, {0.089844f, 0.128906f, 0.628906f, 0.464844f},
+ {0.199219f, 0.824219f, 0.437500f, 0.273438f}, {0.335938f, 0.035156f, 0.507812f, 0.925781f},
+ {0.113281f, 0.773438f, 0.839844f, 0.554688f}, {0.160156f, 0.925781f, 0.042969f, 0.437500f},
+ {0.695312f, 0.132812f, 0.875000f, 0.687500f}, {0.300781f, 0.007812f, 0.519531f, 0.878906f},
+ {0.921875f, 0.898438f, 0.671875f, 0.800781f}, {0.187500f, 0.582031f, 0.000000f, 0.539062f},
+ {0.421875f, 0.253906f, 0.484375f, 0.265625f}, {0.503906f, 0.800781f, 0.945312f, 0.988281f},
+ {0.917969f, 0.117188f, 0.625000f, 0.753906f}, {0.812500f, 0.859375f, 0.707031f, 0.578125f},
+ {0.671875f, 0.269531f, 0.296875f, 0.171875f}, {0.984375f, 0.949219f, 0.769531f, 0.367188f},
+ {0.847656f, 0.476562f, 0.156250f, 0.957031f}, {0.703125f, 0.613281f, 0.554688f, 0.867188f},
+ {0.890625f, 0.328125f, 0.101562f, 0.421875f}, {0.503906f, 0.976562f, 0.687500f, 0.910156f},
+ {0.570312f, 0.511719f, 0.503906f, 0.777344f}, {0.156250f, 0.808594f, 0.597656f, 0.179688f},
+ {0.355469f, 0.125000f, 0.019531f, 0.839844f}, {0.199219f, 0.730469f, 0.308594f, 0.738281f},
+ {0.949219f, 0.984375f, 0.671875f, 0.496094f}, {0.429688f, 0.613281f, 0.246094f, 0.199219f},
+ {0.910156f, 0.085938f, 0.363281f, 0.765625f}, {0.769531f, 0.878906f, 0.707031f, 0.261719f},
+ {0.472656f, 0.519531f, 0.187500f, 0.000000f}, {0.894531f, 0.328125f, 0.519531f, 0.750000f},
+ {0.277344f, 0.593750f, 0.238281f, 0.632812f}, {0.058594f, 0.855469f, 0.359375f, 0.500000f},
+ {0.855469f, 0.023438f, 0.910156f, 0.027344f}, {0.699219f, 0.523438f, 0.449219f, 0.562500f},
+ {0.457031f, 0.667969f, 0.308594f, 0.980469f}, {0.125000f, 0.175781f, 0.824219f, 0.312500f},
+ {0.867188f, 0.867188f, 0.476562f, 0.414062f}, {0.375000f, 0.027344f, 0.929688f, 0.882812f},
+ {0.683594f, 0.812500f, 0.851562f, 0.175781f}, {0.117188f, 0.480469f, 0.125000f, 0.804688f},
+ {0.878906f, 0.980469f, 0.210938f, 0.679688f}, {0.058594f, 0.554688f, 0.378906f, 0.042969f},
+ {0.628906f, 0.167969f, 0.976562f, 0.527344f}, {0.132812f, 0.757812f, 0.769531f, 0.621094f},
+ {0.308594f, 0.371094f, 0.191406f, 0.312500f}, {0.464844f, 0.273438f, 0.527344f, 0.898438f},
+ {0.085938f, 0.808594f, 0.960938f, 0.007812f}, {0.734375f, 0.324219f, 0.691406f, 0.757812f},
+ {0.671875f, 0.105469f, 0.339844f, 0.593750f}, {0.058594f, 0.765625f, 0.585938f, 0.703125f},
+ {0.761719f, 0.246094f, 0.062500f, 0.031250f}, {0.156250f, 0.167969f, 0.417969f, 0.917969f},
+ {0.355469f, 0.035156f, 0.800781f, 0.382812f}, {0.644531f, 0.281250f, 0.925781f, 0.683594f},
+ {0.496094f, 0.773438f, 0.136719f, 0.957031f}, {0.121094f, 0.226562f, 0.890625f, 0.562500f},
+ {0.304688f, 0.699219f, 0.187500f, 0.824219f}, {0.992188f, 0.628906f, 0.980469f, 0.457031f},
+ {0.550781f, 0.300781f, 0.410156f, 0.308594f}, {0.621094f, 0.761719f, 0.242188f, 0.148438f},
+ {0.292969f, 0.671875f, 0.609375f, 0.816406f}, {0.414062f, 0.386719f, 0.000000f, 0.445312f},
+ {0.167969f, 0.289062f, 0.890625f, 0.207031f}, {0.238281f, 0.542969f, 0.140625f, 0.523438f},
+ {0.566406f, 0.710938f, 0.218750f, 0.625000f}, {0.382812f, 0.464844f, 0.980469f, 0.156250f},
+ {0.785156f, 0.972656f, 0.695312f, 0.730469f}, {0.535156f, 0.199219f, 0.246094f, 0.863281f},
+ {0.648438f, 0.390625f, 0.371094f, 0.210938f}, {0.425781f, 0.550781f, 0.722656f, 0.000000f},
+ {0.773438f, 0.671875f, 0.140625f, 0.980469f}, {0.585938f, 0.425781f, 0.234375f, 0.304688f},
+ {0.105469f, 0.734375f, 0.812500f, 0.164062f}, {0.656250f, 0.460938f, 0.281250f, 0.421875f},
+ {0.277344f, 0.632812f, 0.863281f, 0.351562f}, {0.031250f, 0.968750f, 0.347656f, 0.015625f},
+ {0.613281f, 0.195312f, 0.195312f, 0.214844f}, {0.445312f, 0.507812f, 0.527344f, 0.906250f},
+ {0.296875f, 0.777344f, 0.855469f, 0.093750f}, {0.132812f, 0.660156f, 0.062500f, 0.285156f},
+ {0.546875f, 0.031250f, 0.457031f, 0.496094f}, {0.195312f, 0.230469f, 0.808594f, 0.144531f},
+ {0.375000f, 0.750000f, 0.273438f, 0.210938f}, {0.933594f, 0.156250f, 0.941406f, 0.601562f},
+ {0.230469f, 0.402344f, 0.355469f, 0.367188f}, {0.753906f, 0.656250f, 0.128906f, 0.449219f},
+ {0.058594f, 0.351562f, 0.464844f, 0.015625f}, {0.597656f, 0.570312f, 0.398438f, 0.957031f},
+ {0.789062f, 0.289062f, 0.824219f, 0.386719f}, {0.246094f, 0.492188f, 0.578125f, 0.863281f},
+ {0.636719f, 0.792969f, 0.046875f, 0.457031f}, {0.332031f, 0.019531f, 0.839844f, 0.929688f},
+ {0.207031f, 0.410156f, 0.109375f, 0.707031f}, {0.617188f, 0.765625f, 0.621094f, 0.992188f},
+ {0.960938f, 0.066406f, 0.691406f, 0.132812f}, {0.417969f, 0.289062f, 0.074219f, 0.906250f},
+ {0.789062f, 0.207031f, 0.851562f, 0.769531f}, {0.093750f, 0.972656f, 0.171875f, 0.183594f},
+ {0.937500f, 0.101562f, 0.726562f, 0.066406f}, {0.253906f, 0.324219f, 0.554688f, 0.527344f},
+ {0.820312f, 0.503906f, 0.062500f, 0.656250f}, {0.476562f, 0.593750f, 0.648438f, 0.007812f},
+ {0.179688f, 0.910156f, 0.281250f, 0.289062f}, {0.957031f, 0.062500f, 0.445312f, 0.921875f},
+ {0.441406f, 0.632812f, 0.726562f, 0.128906f}, {0.574219f, 0.292969f, 0.621094f, 0.234375f},
+ {0.203125f, 0.875000f, 0.476562f, 0.363281f}, {0.679688f, 0.667969f, 0.031250f, 0.945312f},
+ {0.914062f, 0.441406f, 0.347656f, 0.097656f}, {0.546875f, 0.214844f, 0.609375f, 0.687500f},
+ {0.191406f, 0.718750f, 0.113281f, 0.550781f}, {0.269531f, 0.148438f, 0.164062f, 0.375000f},
+ {0.992188f, 0.414062f, 0.898438f, 0.164062f}, {0.398438f, 0.652344f, 0.652344f, 0.429688f},
+ {0.523438f, 0.351562f, 0.210938f, 0.800781f}, {0.863281f, 0.820312f, 0.992188f, 0.218750f},
+ {0.437500f, 0.988281f, 0.707031f, 0.066406f}, {0.261719f, 0.421875f, 0.382812f, 0.859375f},
+ {0.921875f, 0.339844f, 0.644531f, 0.132812f}, {0.585938f, 0.539062f, 0.746094f, 0.359375f},
+ {0.386719f, 0.855469f, 0.488281f, 0.738281f}, {0.804688f, 0.019531f, 0.289062f, 0.105469f},
+ {0.253906f, 0.480469f, 0.050781f, 0.539062f}, {0.027344f, 0.109375f, 0.867188f, 0.945312f},
+ {0.898438f, 0.828125f, 0.523438f, 0.582031f}, {0.718750f, 0.046875f, 0.964844f, 0.339844f},
+ {0.519531f, 0.152344f, 0.281250f, 0.675781f}, {0.062500f, 0.765625f, 0.570312f, 0.984375f},
+ {0.886719f, 0.003906f, 0.738281f, 0.792969f}, {0.687500f, 0.257812f, 0.316406f, 0.410156f},
+ {0.019531f, 0.585938f, 0.078125f, 0.039062f}, {0.964844f, 0.660156f, 0.164062f, 0.320312f},
+ {0.257812f, 0.863281f, 0.941406f, 0.597656f}, {0.906250f, 0.292969f, 0.640625f, 0.386719f},
+ {0.214844f, 0.960938f, 0.472656f, 0.746094f}, {0.464844f, 0.214844f, 0.996094f, 0.628906f},
+ {0.378906f, 0.851562f, 0.558594f, 0.097656f}, {0.820312f, 0.300781f, 0.394531f, 0.898438f},
+ {0.718750f, 0.066406f, 0.597656f, 0.566406f}, {0.968750f, 0.406250f, 0.085938f, 0.843750f},
+ {0.363281f, 0.687500f, 0.433594f, 0.683594f}, {0.750000f, 0.574219f, 0.125000f, 0.437500f},
+ {0.078125f, 0.316406f, 0.980469f, 0.617188f}, {0.636719f, 0.136719f, 0.675781f, 0.812500f},
+ {0.468750f, 0.910156f, 0.367188f, 0.757812f}, {0.324219f, 0.546875f, 0.910156f, 0.554688f},
+ {0.050781f, 0.832031f, 0.003906f, 0.671875f}, {0.808594f, 0.054688f, 0.203125f, 0.042969f},
+ {0.625000f, 0.929688f, 0.632812f, 0.937500f}, {0.460938f, 0.468750f, 0.796875f, 0.523438f},
+ {0.882812f, 0.003906f, 0.964844f, 0.292969f}, {0.304688f, 0.902344f, 0.195312f, 0.589844f},
+ {0.503906f, 0.160156f, 0.515625f, 0.128906f}, {0.011719f, 0.671875f, 0.933594f, 0.328125f},
+ {0.714844f, 0.250000f, 0.765625f, 0.570312f}, {0.539062f, 0.921875f, 0.472656f, 0.167969f},
+ {0.820312f, 0.187500f, 0.871094f, 0.355469f}, {0.031250f, 0.996094f, 0.953125f, 0.476562f},
+ {0.355469f, 0.628906f, 0.425781f, 0.289062f}, {0.554688f, 0.449219f, 0.578125f, 0.593750f},
+ {0.183594f, 0.710938f, 0.273438f, 0.398438f}, {0.644531f, 0.359375f, 0.511719f, 0.695312f},
+ {0.398438f, 0.820312f, 0.015625f, 0.464844f}, {0.535156f, 0.925781f, 0.941406f, 0.933594f},
+ {0.628906f, 0.691406f, 0.238281f, 0.222656f}, {0.074219f, 0.222656f, 0.402344f, 0.707031f},
+ {0.785156f, 0.757812f, 0.761719f, 0.496094f}, {0.242188f, 0.367188f, 0.570312f, 0.589844f},
+ {0.726562f, 0.718750f, 0.320312f, 0.445312f}, {0.925781f, 0.417969f, 0.890625f, 0.863281f},
+ {0.382812f, 0.000000f, 0.261719f, 0.753906f}, {0.753906f, 0.953125f, 0.839844f, 0.179688f},
+ {0.023438f, 0.078125f, 0.414062f, 0.832031f}, {0.843750f, 0.597656f, 0.906250f, 0.496094f},
+ {0.617188f, 0.894531f, 0.492188f, 0.792969f}, {0.886719f, 0.542969f, 0.261719f, 0.289062f},
+ {0.140625f, 0.968750f, 0.437500f, 0.960938f}, {0.296875f, 0.046875f, 0.757812f, 0.851562f},
+ {0.601562f, 0.710938f, 0.300781f, 0.324219f}, {0.699219f, 0.500000f, 0.496094f, 0.574219f},
+ {0.019531f, 0.558594f, 0.035156f, 0.648438f}, {0.785156f, 0.675781f, 0.535156f, 0.449219f},
+ {0.078125f, 0.089844f, 0.234375f, 0.300781f}, {0.191406f, 0.175781f, 0.339844f, 0.617188f},
+ {0.714844f, 0.398438f, 0.785156f, 0.222656f}, {0.054688f, 0.921875f, 0.562500f, 0.875000f},
+ {0.488281f, 0.257812f, 0.683594f, 0.652344f}, {0.765625f, 0.566406f, 0.335938f, 0.386719f},
+ {0.371094f, 0.957031f, 0.121094f, 0.750000f}, {0.117188f, 0.511719f, 0.718750f, 0.007812f},
+ {0.820312f, 0.871094f, 0.421875f, 0.125000f}, {0.453125f, 0.617188f, 0.062500f, 0.371094f},
+ {0.613281f, 0.937500f, 0.914062f, 0.246094f}, {0.300781f, 0.371094f, 0.460938f, 0.703125f},
+ {0.480469f, 0.078125f, 0.863281f, 0.957031f}, {0.730469f, 0.746094f, 0.785156f, 0.488281f},
+ {0.363281f, 0.164062f, 0.566406f, 0.812500f}, {0.074219f, 0.093750f, 0.093750f, 0.140625f},
+ {0.859375f, 0.503906f, 0.320312f, 0.527344f}, {0.039062f, 0.050781f, 0.765625f, 0.464844f},
+ {0.953125f, 0.566406f, 0.058594f, 0.222656f}, {0.531250f, 0.156250f, 0.156250f, 0.773438f},
+ {0.230469f, 0.914062f, 0.738281f, 0.644531f}, {0.117188f, 0.750000f, 0.898438f, 0.152344f},
+ {0.574219f, 0.363281f, 0.656250f, 0.484375f}, {0.179688f, 0.011719f, 0.808594f, 0.312500f},
+ {0.894531f, 0.980469f, 0.328125f, 0.941406f}, {0.246094f, 0.730469f, 0.242188f, 0.066406f},
+ {0.949219f, 0.386719f, 0.609375f, 0.398438f}, {0.781250f, 0.445312f, 0.511719f, 0.257812f},
+ {0.675781f, 0.679688f, 0.730469f, 0.843750f}, {0.121094f, 0.273438f, 0.433594f, 0.324219f},
+ {0.273438f, 0.582031f, 0.855469f, 0.726562f}, {0.390625f, 0.863281f, 0.289062f, 0.816406f},
+ {0.699219f, 0.226562f, 0.707031f, 0.218750f}, {0.925781f, 0.757812f, 0.078125f, 0.687500f},
+ {0.128906f, 0.382812f, 0.640625f, 0.906250f}, {0.382812f, 0.101562f, 0.140625f, 0.789062f},
+ {0.988281f, 0.843750f, 0.273438f, 0.074219f}, {0.093750f, 0.562500f, 0.386719f, 0.660156f},
+ {0.441406f, 0.726562f, 0.230469f, 0.218750f}, {0.746094f, 0.238281f, 0.023438f, 0.875000f},
+ {0.683594f, 0.109375f, 0.750000f, 0.042969f}, {0.238281f, 0.898438f, 0.328125f, 0.812500f},
+ {0.902344f, 0.796875f, 0.988281f, 0.230469f}, {0.335938f, 0.574219f, 0.792969f, 0.335938f},
+ {0.015625f, 0.035156f, 0.613281f, 0.835938f}, {0.738281f, 0.414062f, 0.343750f, 0.101562f},
+ {0.976562f, 0.128906f, 0.867188f, 0.789062f}, {0.308594f, 0.285156f, 0.148438f, 0.371094f},
+ {0.554688f, 0.535156f, 0.980469f, 0.964844f}, {0.351562f, 0.191406f, 0.046875f, 0.074219f},
+ {0.003906f, 0.140625f, 0.812500f, 0.324219f}, {0.515625f, 0.804688f, 0.101562f, 0.644531f},
+ {0.292969f, 0.242188f, 0.152344f, 0.546875f}, {0.816406f, 0.527344f, 0.554688f, 0.277344f},
+ {0.246094f, 0.343750f, 0.664062f, 0.050781f}, {0.425781f, 0.839844f, 0.058594f, 0.425781f},
+ {0.347656f, 0.031250f, 0.714844f, 0.207031f}, {0.496094f, 0.460938f, 0.804688f, 0.652344f},
+ {0.800781f, 0.226562f, 0.078125f, 0.058594f}, {0.039062f, 0.859375f, 0.546875f, 0.484375f},
+ {0.945312f, 0.300781f, 0.847656f, 0.109375f}, {0.226562f, 0.121094f, 0.121094f, 0.933594f},
+ {0.906250f, 0.210938f, 0.878906f, 0.746094f}, {0.546875f, 0.875000f, 0.601562f, 0.187500f},
+ {0.675781f, 0.953125f, 0.085938f, 0.804688f}, {0.339844f, 0.601562f, 0.933594f, 0.507812f},
+ {0.859375f, 0.792969f, 0.023438f, 0.996094f}, {0.429688f, 0.128906f, 0.156250f, 0.031250f},
+ {0.929688f, 0.742188f, 0.906250f, 0.269531f}, {0.179688f, 0.203125f, 0.453125f, 0.484375f},
+ {0.671875f, 0.640625f, 0.644531f, 0.195312f}, {0.582031f, 0.328125f, 0.191406f, 0.847656f},
+ {0.976562f, 0.425781f, 0.832031f, 0.601562f}, {0.343750f, 0.191406f, 0.347656f, 0.906250f},
+ {0.210938f, 0.488281f, 0.605469f, 0.062500f}, {0.941406f, 0.804688f, 0.023438f, 0.546875f},
+ {0.101562f, 0.910156f, 0.527344f, 0.191406f}, {0.175781f, 0.437500f, 0.402344f, 0.648438f},
+ {0.820312f, 0.332031f, 0.265625f, 0.914062f}, {0.515625f, 0.636719f, 0.882812f, 0.062500f},
+ {0.621094f, 0.785156f, 0.429688f, 0.253906f}, {0.746094f, 0.707031f, 0.199219f, 0.937500f},
+ {0.152344f, 0.355469f, 0.683594f, 0.332031f}, {0.332031f, 0.804688f, 0.457031f, 0.074219f},
+ {0.878906f, 0.492188f, 0.964844f, 0.968750f}, {0.480469f, 0.109375f, 0.226562f, 0.382812f},
+ {0.792969f, 0.867188f, 0.035156f, 0.042969f}, {0.417969f, 0.234375f, 0.480469f, 0.734375f},
+ {0.843750f, 0.464844f, 0.566406f, 0.539062f}, {0.511719f, 0.609375f, 0.171875f, 0.187500f},
+ {0.011719f, 0.062500f, 0.046875f, 0.703125f}, {0.582031f, 0.191406f, 0.871094f, 0.968750f},
+ {0.429688f, 0.347656f, 0.308594f, 0.121094f}, {0.988281f, 0.777344f, 0.578125f, 0.484375f},
+ {0.527344f, 0.109375f, 0.152344f, 0.078125f}, {0.085938f, 0.320312f, 0.050781f, 0.160156f},
+ {0.835938f, 0.699219f, 0.539062f, 0.640625f}, {0.558594f, 0.531250f, 0.890625f, 0.433594f},
+ {0.183594f, 0.968750f, 0.332031f, 0.031250f}, {0.660156f, 0.449219f, 0.433594f, 0.269531f},
+ {0.851562f, 0.640625f, 0.722656f, 0.503906f}, {0.289062f, 0.347656f, 0.558594f, 0.835938f},
+ {0.156250f, 0.488281f, 0.171875f, 0.101562f}, {0.878906f, 0.828125f, 0.804688f, 0.550781f},
+ {0.511719f, 0.386719f, 0.492188f, 0.437500f}, {0.132812f, 0.531250f, 0.148438f, 0.671875f},
+ {0.765625f, 0.144531f, 0.101562f, 0.117188f}, {0.484375f, 0.257812f, 0.210938f, 0.910156f},
+ {0.835938f, 0.480469f, 0.433594f, 0.574219f}, {0.152344f, 0.628906f, 0.699219f, 0.269531f},
+ {0.214844f, 0.773438f, 0.089844f, 0.441406f}, {0.417969f, 0.992188f, 0.535156f, 0.152344f},
+ {0.898438f, 0.453125f, 0.667969f, 0.746094f}, {0.640625f, 0.867188f, 0.195312f, 0.207031f},
+ {0.148438f, 0.578125f, 0.507812f, 0.796875f}, {0.855469f, 0.921875f, 0.699219f, 0.027344f},
+ {0.097656f, 0.468750f, 0.960938f, 0.988281f}, {0.585938f, 0.625000f, 0.757812f, 0.382812f},
+ {0.160156f, 0.773438f, 0.300781f, 0.613281f}, {0.714844f, 0.183594f, 0.214844f, 0.875000f},
+ {0.070312f, 0.691406f, 0.980469f, 0.937500f}, {0.656250f, 0.375000f, 0.332031f, 0.125000f},
+ {0.746094f, 0.789062f, 0.621094f, 0.738281f}, {0.457031f, 0.585938f, 0.949219f, 0.605469f},
+ {0.335938f, 0.933594f, 0.179688f, 0.253906f}, {0.171875f, 0.625000f, 0.359375f, 0.523438f},
+ {0.386719f, 0.457031f, 0.730469f, 0.394531f}, {0.472656f, 0.003906f, 0.273438f, 0.039062f},
+ {0.281250f, 0.726562f, 0.457031f, 0.902344f}, {0.972656f, 0.488281f, 0.832031f, 0.093750f},
+ {0.617188f, 0.312500f, 0.406250f, 0.414062f}, {0.136719f, 0.660156f, 0.613281f, 0.687500f},
+ {0.562500f, 0.441406f, 0.226562f, 0.781250f}, {0.324219f, 0.375000f, 0.800781f, 0.074219f},
+ {0.871094f, 0.808594f, 0.082031f, 0.964844f}, {0.269531f, 0.089844f, 0.941406f, 0.699219f},
+ {0.011719f, 0.250000f, 0.503906f, 0.503906f}, {0.148438f, 0.671875f, 0.242188f, 0.300781f},
+ {0.707031f, 0.125000f, 0.679688f, 0.453125f}, {0.843750f, 0.296875f, 0.812500f, 0.835938f},
+ {0.417969f, 0.566406f, 0.187500f, 0.113281f}, {0.578125f, 0.226562f, 0.652344f, 0.285156f},
+ {0.675781f, 0.523438f, 0.718750f, 0.363281f}, {0.312500f, 0.894531f, 0.039062f, 0.691406f},
+ {0.406250f, 0.398438f, 0.605469f, 0.781250f}, {0.265625f, 0.246094f, 0.917969f, 0.851562f},
+ {0.570312f, 0.992188f, 0.843750f, 0.589844f}, {0.644531f, 0.605469f, 0.339844f, 0.714844f},
+ {0.003906f, 0.269531f, 0.531250f, 0.511719f}, {0.699219f, 0.652344f, 0.296875f, 0.277344f},
+ {0.312500f, 0.546875f, 0.710938f, 0.824219f}, {0.054688f, 0.152344f, 0.402344f, 0.238281f},
+ {0.667969f, 0.796875f, 0.914062f, 0.875000f}, {0.351562f, 0.281250f, 0.769531f, 0.351562f},
+ {0.730469f, 0.839844f, 0.691406f, 0.000000f}, {0.289062f, 0.894531f, 0.394531f, 0.632812f},
+ {0.152344f, 0.519531f, 0.113281f, 0.429688f}, {0.867188f, 0.988281f, 0.992188f, 0.582031f},
+ {0.210938f, 0.636719f, 0.480469f, 0.878906f}, {0.640625f, 0.171875f, 0.753906f, 0.984375f},
+ {0.023438f, 0.425781f, 0.371094f, 0.343750f}, {0.437500f, 0.039062f, 0.222656f, 0.539062f},
+ {0.257812f, 0.800781f, 0.835938f, 0.718750f}, {0.777344f, 0.300781f, 0.007812f, 0.964844f},
+ {0.484375f, 0.054688f, 0.984375f, 0.406250f}, {0.582031f, 0.140625f, 0.664062f, 0.617188f},
+ {0.398438f, 0.597656f, 0.906250f, 0.933594f}, {0.933594f, 0.019531f, 0.367188f, 0.726562f},
+ {0.312500f, 0.691406f, 0.601562f, 0.164062f}, {0.074219f, 0.320312f, 0.882812f, 0.964844f},
+ {0.589844f, 0.644531f, 0.679688f, 0.515625f}, {0.949219f, 0.964844f, 0.375000f, 0.742188f},
+ {0.281250f, 0.187500f, 0.910156f, 0.023438f}, {0.687500f, 0.886719f, 0.773438f, 0.640625f},
+ {0.597656f, 0.343750f, 0.292969f, 0.871094f}, {0.054688f, 0.089844f, 0.464844f, 0.535156f},
+ {0.808594f, 0.015625f, 0.839844f, 0.613281f}, {0.710938f, 0.675781f, 0.339844f, 0.902344f},
+ {0.484375f, 0.320312f, 0.429688f, 0.406250f}, {0.988281f, 0.062500f, 0.242188f, 0.687500f},
+ {0.664062f, 0.707031f, 0.375000f, 0.140625f}, {0.460938f, 0.128906f, 0.019531f, 0.480469f},
+ {0.960938f, 0.296875f, 0.453125f, 0.707031f}, {0.535156f, 0.980469f, 0.828125f, 0.246094f},
+ {0.894531f, 0.101562f, 0.578125f, 0.570312f}, {0.218750f, 0.273438f, 0.398438f, 0.335938f},
+ {0.113281f, 0.507812f, 0.000000f, 0.406250f}, {0.554688f, 0.160156f, 0.242188f, 0.890625f},
+ {0.828125f, 0.066406f, 0.671875f, 0.695312f}, {0.632812f, 0.398438f, 0.425781f, 0.148438f},
+ {0.730469f, 0.781250f, 0.785156f, 0.968750f}, {0.125000f, 0.273438f, 0.964844f, 0.281250f},
+ {0.820312f, 0.371094f, 0.191406f, 0.707031f}, {0.031250f, 0.218750f, 0.695312f, 0.585938f},
+ {0.507812f, 0.054688f, 0.511719f, 0.343750f}, {0.242188f, 0.890625f, 0.988281f, 0.167969f},
+ {0.734375f, 0.972656f, 0.730469f, 0.531250f}, {0.070312f, 0.011719f, 0.285156f, 0.316406f},
+ {0.460938f, 0.707031f, 0.394531f, 0.417969f}, {0.781250f, 0.546875f, 0.585938f, 0.234375f},
+ {0.402344f, 0.992188f, 0.769531f, 0.152344f}, {0.644531f, 0.738281f, 0.148438f, 0.773438f},
+ {0.757812f, 0.855469f, 0.976562f, 0.636719f}, {0.539062f, 0.050781f, 0.382812f, 0.390625f},
+ {0.246094f, 0.714844f, 0.296875f, 0.742188f}, {0.910156f, 0.972656f, 0.125000f, 0.886719f},
+ {0.128906f, 0.011719f, 0.960938f, 0.445312f}, {0.984375f, 0.828125f, 0.351562f, 0.554688f},
+ {0.054688f, 0.132812f, 0.511719f, 0.175781f}, {0.800781f, 0.464844f, 0.117188f, 0.398438f},
+ {0.921875f, 0.027344f, 0.257812f, 0.019531f}, {0.437500f, 0.191406f, 0.015625f, 0.441406f},
+ {0.203125f, 0.433594f, 0.785156f, 0.195312f}, {0.996094f, 0.953125f, 0.632812f, 0.917969f},
+ {0.257812f, 0.335938f, 0.144531f, 0.652344f}, {0.617188f, 0.703125f, 0.835938f, 0.101562f},
+ {0.941406f, 0.929688f, 0.265625f, 0.597656f}, {0.109375f, 0.503906f, 0.097656f, 0.468750f},
+ {0.195312f, 0.093750f, 0.957031f, 0.785156f}, {0.917969f, 0.714844f, 0.218750f, 0.906250f},
+ {0.761719f, 0.242188f, 0.648438f, 0.281250f}, {0.367188f, 0.019531f, 0.789062f, 0.195312f},
+ {0.707031f, 0.480469f, 0.253906f, 0.386719f}, {0.328125f, 0.828125f, 0.917969f, 0.757812f},
+ {0.960938f, 0.941406f, 0.667969f, 0.242188f}, {0.742188f, 0.601562f, 0.601562f, 0.105469f},
+ {0.347656f, 0.203125f, 0.496094f, 0.871094f}, {0.886719f, 0.687500f, 0.777344f, 0.152344f},
+ {0.046875f, 0.886719f, 0.089844f, 0.316406f}, {0.222656f, 0.957031f, 0.316406f, 0.773438f},
+ {0.625000f, 0.750000f, 0.527344f, 0.253906f}, {0.003906f, 0.277344f, 0.050781f, 0.382812f},
+ {0.660156f, 0.937500f, 0.250000f, 0.328125f}, {0.808594f, 0.078125f, 0.734375f, 0.625000f},
+ {0.437500f, 0.425781f, 0.460938f, 0.281250f}, {0.386719f, 0.738281f, 0.566406f, 0.394531f},
+ {0.039062f, 0.050781f, 0.035156f, 0.175781f}, {0.523438f, 0.546875f, 0.175781f, 0.996094f},
+ {0.925781f, 0.714844f, 0.957031f, 0.347656f}, {0.453125f, 0.843750f, 0.585938f, 0.039062f},
+ {0.109375f, 0.617188f, 0.003906f, 0.296875f}, {0.269531f, 0.406250f, 0.750000f, 0.109375f},
+ {0.390625f, 0.949219f, 0.933594f, 0.519531f}, {0.207031f, 0.222656f, 0.597656f, 0.238281f},
+ {0.332031f, 0.378906f, 0.640625f, 0.820312f}, {0.785156f, 0.898438f, 0.914062f, 0.906250f},
+ {0.054688f, 0.496094f, 0.523438f, 0.085938f}, {0.386719f, 0.417969f, 0.089844f, 0.777344f},
+ {0.304688f, 0.562500f, 0.148438f, 0.031250f}, {0.929688f, 0.925781f, 0.773438f, 0.519531f},
+ {0.414062f, 0.667969f, 0.468750f, 0.195312f}, {0.257812f, 0.738281f, 0.835938f, 0.800781f},
+ {0.972656f, 0.332031f, 0.519531f, 0.003906f}, {0.078125f, 0.847656f, 0.062500f, 0.359375f},
+ {0.882812f, 0.691406f, 0.566406f, 0.625000f}, {0.585938f, 0.148438f, 0.140625f, 0.777344f},
+ {0.214844f, 0.941406f, 0.652344f, 0.476562f}, {0.757812f, 0.824219f, 0.308594f, 0.238281f},
+ {0.402344f, 0.527344f, 0.113281f, 0.867188f}, {0.945312f, 0.585938f, 0.359375f, 0.937500f},
+ {0.839844f, 0.277344f, 0.062500f, 0.621094f}, {0.632812f, 0.167969f, 0.550781f, 0.804688f},
+ {0.222656f, 0.464844f, 0.894531f, 0.914062f}, {0.535156f, 0.882812f, 0.011719f, 0.566406f},
+ {0.886719f, 0.039062f, 0.312500f, 0.085938f}, {0.496094f, 0.394531f, 0.449219f, 0.875000f},
+ {0.085938f, 0.593750f, 0.097656f, 0.972656f}, {0.289062f, 0.343750f, 0.742188f, 0.011719f},
+ {0.031250f, 0.460938f, 0.894531f, 0.589844f}, {0.777344f, 0.156250f, 0.488281f, 0.222656f},
+ {0.468750f, 0.679688f, 0.835938f, 0.042969f}, {0.195312f, 0.281250f, 0.230469f, 0.992188f},
+ {0.718750f, 0.589844f, 0.796875f, 0.109375f}, {0.492188f, 0.921875f, 0.667969f, 0.667969f},
+ {0.097656f, 0.667969f, 0.390625f, 0.292969f}, {0.835938f, 0.871094f, 0.582031f, 0.871094f},
+ {0.378906f, 0.097656f, 0.878906f, 0.128906f}, {0.753906f, 0.765625f, 0.078125f, 0.558594f},
+ {0.503906f, 0.039062f, 0.937500f, 0.761719f}, {0.148438f, 0.207031f, 0.515625f, 0.425781f},
+ {0.816406f, 0.421875f, 0.593750f, 0.996094f}, {0.390625f, 0.367188f, 0.335938f, 0.136719f},
+ {0.550781f, 0.656250f, 0.441406f, 0.226562f}, {0.488281f, 0.144531f, 0.828125f, 0.523438f},
+ {0.605469f, 0.593750f, 0.531250f, 0.734375f}, {0.035156f, 0.390625f, 0.347656f, 0.671875f},
+ {0.464844f, 0.742188f, 0.019531f, 0.023438f}, {0.812500f, 0.265625f, 0.421875f, 0.492188f},
+ {0.164062f, 0.359375f, 0.101562f, 0.605469f}, {0.507812f, 0.121094f, 0.171875f, 0.800781f},
+ {0.605469f, 0.503906f, 0.933594f, 0.453125f}, {0.082031f, 0.250000f, 0.261719f, 0.203125f},
+ {0.968750f, 0.550781f, 0.460938f, 0.570312f}, {0.718750f, 0.410156f, 0.628906f, 0.054688f},
+ {0.835938f, 0.105469f, 0.710938f, 0.468750f}, {0.359375f, 0.457031f, 0.421875f, 0.894531f},
+ {0.250000f, 0.875000f, 0.968750f, 0.015625f}, {0.996094f, 0.210938f, 0.074219f, 0.855469f},
+ {0.179688f, 0.785156f, 0.304688f, 0.074219f}, {0.714844f, 0.855469f, 0.832031f, 0.804688f},
+ {0.230469f, 0.296875f, 0.500000f, 0.488281f}, {0.859375f, 0.394531f, 0.253906f, 0.222656f},
+ {0.324219f, 0.230469f, 0.640625f, 0.679688f}, {0.765625f, 0.511719f, 0.390625f, 0.820312f},
+ {0.179688f, 0.269531f, 0.222656f, 0.726562f}, {0.843750f, 0.121094f, 0.128906f, 0.468750f},
+ {0.609375f, 0.781250f, 0.859375f, 0.960938f}, {0.035156f, 0.531250f, 0.066406f, 0.335938f},
+ {0.734375f, 0.855469f, 0.167969f, 0.578125f}, {0.261719f, 0.023438f, 0.324219f, 0.175781f},
+ {0.867188f, 0.652344f, 0.875000f, 0.304688f}, {0.632812f, 0.746094f, 0.683594f, 0.371094f},
+ {0.183594f, 0.214844f, 0.273438f, 0.851562f}, {0.773438f, 0.832031f, 0.921875f, 0.667969f},
+ {0.589844f, 0.011719f, 0.703125f, 0.992188f}, {0.691406f, 0.433594f, 0.113281f, 0.300781f},
+ {0.003906f, 0.246094f, 0.933594f, 0.457031f}, {0.511719f, 0.984375f, 0.320312f, 0.843750f},
+ {0.300781f, 0.496094f, 0.886719f, 0.203125f}, {0.433594f, 0.578125f, 0.390625f, 0.539062f},
+ {0.914062f, 0.648438f, 0.007812f, 0.121094f}, {0.085938f, 0.421875f, 0.867188f, 0.824219f},
+ {0.683594f, 0.117188f, 0.753906f, 0.015625f}, {0.304688f, 0.750000f, 0.210938f, 0.460938f},
+ {0.113281f, 0.355469f, 0.828125f, 0.113281f}, {0.367188f, 0.843750f, 0.472656f, 0.718750f},
+ {0.988281f, 0.621094f, 0.167969f, 0.035156f}, {0.050781f, 0.308594f, 0.710938f, 0.363281f},
+ {0.171875f, 0.144531f, 0.871094f, 0.667969f}, {0.929688f, 0.515625f, 0.648438f, 0.265625f},
+ {0.363281f, 0.781250f, 0.542969f, 0.183594f}, {0.859375f, 0.203125f, 0.226562f, 0.335938f},
+ {0.609375f, 0.878906f, 0.574219f, 0.496094f}, {0.386719f, 0.621094f, 0.003906f, 0.800781f},
+ {0.644531f, 0.378906f, 0.628906f, 0.625000f}, {0.871094f, 0.757812f, 0.437500f, 0.324219f},
+ {0.238281f, 0.082031f, 0.160156f, 0.750000f}, {0.355469f, 0.535156f, 0.984375f, 0.519531f},
+ {0.691406f, 0.308594f, 0.734375f, 0.960938f}, {0.167969f, 0.722656f, 0.480469f, 0.628906f},
+ {0.550781f, 0.390625f, 0.179688f, 0.792969f}, {0.070312f, 0.511719f, 0.441406f, 0.347656f},
+ {0.906250f, 0.843750f, 0.363281f, 0.023438f}, {0.589844f, 0.636719f, 0.203125f, 0.289062f},
+ {0.449219f, 0.070312f, 0.007812f, 0.695312f}, {0.238281f, 0.566406f, 0.746094f, 0.382812f},
+ {0.683594f, 0.953125f, 0.492188f, 0.832031f}, {0.855469f, 0.324219f, 0.062500f, 0.328125f},
+ {0.093750f, 0.812500f, 0.156250f, 0.093750f}, {0.253906f, 0.917969f, 0.609375f, 0.929688f},
+ {0.925781f, 0.550781f, 0.710938f, 0.812500f}, {0.574219f, 0.082031f, 0.843750f, 0.304688f},
+ {0.109375f, 0.894531f, 0.308594f, 0.066406f}, {0.234375f, 0.718750f, 0.550781f, 0.941406f},
+ {0.683594f, 0.851562f, 0.699219f, 0.371094f}, {0.410156f, 0.773438f, 0.402344f, 0.636719f},
+ {0.308594f, 0.335938f, 0.136719f, 0.843750f}, {0.519531f, 0.175781f, 0.820312f, 0.687500f},
+ {0.109375f, 0.820312f, 0.292969f, 0.527344f}, {0.457031f, 0.539062f, 0.183594f, 0.191406f},
+ {0.742188f, 0.617188f, 0.847656f, 0.750000f}, {0.539062f, 0.363281f, 0.617188f, 0.566406f},
+ {0.085938f, 0.500000f, 0.140625f, 0.449219f}, {0.890625f, 0.578125f, 0.937500f, 0.699219f},
+ {0.632812f, 0.113281f, 0.664062f, 0.917969f}, {0.128906f, 0.660156f, 0.105469f, 0.582031f},
+ {0.375000f, 0.933594f, 0.812500f, 0.410156f}, {0.652344f, 0.160156f, 0.882812f, 0.132812f},
+ {0.503906f, 0.820312f, 0.691406f, 0.253906f}, {0.941406f, 0.457031f, 0.300781f, 0.851562f},
+ {0.550781f, 0.734375f, 0.546875f, 0.656250f}, {0.902344f, 0.175781f, 0.488281f, 0.000000f},
+ {0.437500f, 0.593750f, 0.730469f, 0.753906f}, {0.125000f, 0.261719f, 0.785156f, 0.437500f},
+ {0.570312f, 0.816406f, 0.203125f, 0.632812f}, {0.500000f, 0.074219f, 0.417969f, 0.949219f},
+ {0.031250f, 0.351562f, 0.632812f, 0.472656f}, {0.839844f, 0.601562f, 0.343750f, 0.152344f},
+ {0.136719f, 0.128906f, 0.187500f, 0.753906f}, {0.476562f, 0.886719f, 0.597656f, 0.101562f},
+ {0.371094f, 0.550781f, 0.265625f, 0.578125f}, {0.792969f, 0.187500f, 0.722656f, 0.925781f},
+ {0.164062f, 0.089844f, 0.203125f, 0.070312f}, {0.660156f, 0.035156f, 0.617188f, 0.417969f},
+ {0.359375f, 0.324219f, 0.476562f, 0.671875f}, {0.539062f, 0.871094f, 0.542969f, 0.300781f},
+ {0.812500f, 0.195312f, 0.925781f, 0.750000f}, {0.171875f, 0.675781f, 0.433594f, 0.394531f},
+ {0.492188f, 0.066406f, 0.597656f, 0.210938f}, {0.710938f, 0.507812f, 0.675781f, 0.281250f},
+ {0.574219f, 0.765625f, 0.964844f, 0.851562f}, {0.808594f, 0.226562f, 0.250000f, 0.468750f},
+ {0.316406f, 0.925781f, 0.367188f, 0.757812f}, {0.675781f, 0.656250f, 0.816406f, 0.429688f},
+ {0.214844f, 0.265625f, 0.062500f, 0.539062f}, {0.457031f, 0.953125f, 0.937500f, 0.722656f},
+ {0.972656f, 0.101562f, 0.410156f, 0.132812f}, {0.070312f, 0.800781f, 0.320312f, 0.929688f},
+ {0.320312f, 0.500000f, 0.769531f, 0.261719f}, {0.527344f, 0.218750f, 0.085938f, 0.472656f},
+ {0.015625f, 0.851562f, 0.550781f, 0.820312f}, {0.960938f, 0.359375f, 0.285156f, 0.210938f},
+ {0.609375f, 0.144531f, 0.062500f, 0.371094f}, {0.292969f, 0.812500f, 0.925781f, 0.058594f},
+ {0.664062f, 0.226562f, 0.308594f, 0.242188f}, {0.863281f, 0.582031f, 0.671875f, 0.488281f},
+ {0.332031f, 0.292969f, 0.765625f, 0.945312f}, {0.023438f, 0.910156f, 0.988281f, 0.183594f},
+ {0.726562f, 0.734375f, 0.621094f, 0.531250f}, {0.968750f, 0.261719f, 0.898438f, 0.902344f},
+ {0.058594f, 0.851562f, 0.675781f, 0.046875f}, {0.320312f, 0.187500f, 0.292969f, 0.609375f},
+ {0.781250f, 0.449219f, 0.949219f, 0.167969f}, {0.410156f, 0.054688f, 0.882812f, 0.441406f},
+ {0.667969f, 0.210938f, 0.207031f, 0.542969f}, {0.296875f, 0.667969f, 0.468750f, 0.855469f},
+ {0.871094f, 0.417969f, 0.980469f, 0.148438f}, {0.761719f, 0.164062f, 0.765625f, 0.699219f},
+ {0.914062f, 0.460938f, 0.035156f, 0.511719f}, {0.148438f, 0.027344f, 0.871094f, 0.007812f},
+ {0.800781f, 0.929688f, 0.210938f, 0.988281f}, {0.199219f, 0.675781f, 0.945312f, 0.128906f},
+ {0.574219f, 0.230469f, 0.027344f, 0.796875f}, {0.875000f, 0.980469f, 0.781250f, 0.648438f},
+ {0.140625f, 0.144531f, 0.542969f, 0.968750f}, {0.609375f, 0.003906f, 0.359375f, 0.238281f},
+ {0.335938f, 0.683594f, 0.222656f, 0.148438f}, {0.476562f, 0.171875f, 0.761719f, 0.308594f},
+ {0.757812f, 0.902344f, 0.402344f, 0.105469f}, {0.562500f, 0.445312f, 0.324219f, 0.757812f},
+ {0.972656f, 0.039062f, 0.527344f, 0.050781f}, {0.019531f, 0.570312f, 0.054688f, 0.933594f},
+ {0.296875f, 0.964844f, 0.457031f, 0.562500f}, {0.695312f, 0.351562f, 0.984375f, 0.183594f},
+ {0.078125f, 0.636719f, 0.800781f, 0.382812f}, {0.347656f, 0.082031f, 0.402344f, 0.093750f},
+ {0.804688f, 0.988281f, 0.257812f, 0.921875f}, {0.191406f, 0.316406f, 0.101562f, 0.535156f},
+ {0.707031f, 0.453125f, 0.570312f, 0.722656f}, {0.937500f, 0.160156f, 0.996094f, 0.050781f},
+ {0.363281f, 0.960938f, 0.023438f, 0.230469f}, {0.671875f, 0.480469f, 0.496094f, 0.414062f},
+ {0.320312f, 0.296875f, 0.859375f, 0.554688f}, {0.949219f, 0.644531f, 0.386719f, 0.261719f},
+ {0.867188f, 0.757812f, 0.035156f, 0.648438f}, {0.226562f, 0.359375f, 0.460938f, 0.726562f},
+ {0.714844f, 0.804688f, 0.816406f, 0.328125f}, {0.996094f, 0.914062f, 0.980469f, 0.886719f},
+ {0.023438f, 0.257812f, 0.250000f, 0.976562f}, {0.265625f, 0.773438f, 0.789062f, 0.171875f},
+ {0.605469f, 0.472656f, 0.046875f, 0.636719f}, {0.449219f, 0.945312f, 0.273438f, 0.957031f},
+ {0.902344f, 0.250000f, 0.128906f, 0.582031f}, {0.000000f, 0.906250f, 0.332031f, 0.519531f},
+ {0.273438f, 0.101562f, 0.042969f, 0.175781f}, {0.421875f, 0.386719f, 0.515625f, 0.988281f},
+ {0.742188f, 0.820312f, 0.605469f, 0.605469f}, {0.589844f, 0.453125f, 0.132812f, 0.066406f},
+ {0.128906f, 0.066406f, 0.285156f, 0.910156f}, {0.800781f, 0.550781f, 0.714844f, 0.835938f},
+ {0.699219f, 0.421875f, 0.855469f, 0.398438f}, {0.175781f, 0.304688f, 0.175781f, 0.664062f},
+ {0.738281f, 0.039062f, 0.683594f, 0.074219f}, {0.832031f, 0.984375f, 0.898438f, 0.867188f},
+ {0.574219f, 0.437500f, 0.363281f, 0.144531f}, {0.421875f, 0.640625f, 0.859375f, 0.597656f},
+ {0.898438f, 0.937500f, 0.640625f, 0.906250f}, {0.125000f, 0.484375f, 0.214844f, 0.449219f},
+ {0.472656f, 0.000000f, 0.808594f, 0.675781f}, {0.218750f, 0.960938f, 0.109375f, 0.847656f},
+ {0.425781f, 0.167969f, 0.539062f, 0.585938f}, {0.800781f, 0.460938f, 0.257812f, 0.734375f},
+ {0.289062f, 0.125000f, 0.402344f, 0.070312f}, {0.179688f, 0.777344f, 0.125000f, 0.648438f},
+ {0.890625f, 0.011719f, 0.187500f, 0.480469f}, {0.628906f, 0.492188f, 0.558594f, 0.761719f},
+ {0.144531f, 0.691406f, 0.769531f, 0.957031f}, {0.957031f, 0.765625f, 0.378906f, 0.351562f},
+ {0.187500f, 0.292969f, 0.074219f, 0.222656f}, {0.496094f, 0.957031f, 0.589844f, 0.652344f},
+ {0.378906f, 0.597656f, 0.128906f, 0.410156f}, {0.007812f, 0.316406f, 0.269531f, 0.273438f},
+ {0.449219f, 0.644531f, 0.367188f, 0.777344f}, {0.542969f, 0.093750f, 0.648438f, 0.234375f},
+ {0.660156f, 0.582031f, 0.503906f, 0.335938f}, {0.941406f, 0.382812f, 0.585938f, 0.421875f},
+ {0.031250f, 0.042969f, 0.117188f, 0.285156f}, {0.414062f, 0.304688f, 0.679688f, 0.082031f},
+ {0.781250f, 0.722656f, 0.484375f, 0.351562f}, {0.277344f, 0.800781f, 0.875000f, 0.496094f},
+ {0.914062f, 0.265625f, 0.007812f, 0.816406f}, {0.406250f, 0.968750f, 0.445312f, 0.628906f},
+ {0.066406f, 0.339844f, 0.710938f, 0.375000f}, {0.261719f, 0.746094f, 0.968750f, 0.878906f},
+ {0.203125f, 0.800781f, 0.160156f, 0.511719f}, {0.812500f, 0.312500f, 0.613281f, 0.328125f},
+ {0.414062f, 0.691406f, 0.359375f, 0.445312f}, {0.148438f, 0.007812f, 0.179688f, 0.625000f},
+ {0.238281f, 0.226562f, 0.027344f, 0.785156f}, {0.476562f, 0.507812f, 0.664062f, 0.875000f},
+ {0.648438f, 0.390625f, 0.945312f, 0.210938f}, {0.972656f, 0.710938f, 0.367188f, 0.269531f},
+ {0.285156f, 0.558594f, 0.464844f, 0.128906f}, {0.082031f, 0.679688f, 0.816406f, 0.832031f},
+ {0.457031f, 0.769531f, 0.078125f, 0.601562f}, {0.242188f, 0.867188f, 0.738281f, 0.898438f},
+ {0.750000f, 0.394531f, 0.554688f, 0.019531f}, {0.101562f, 0.042969f, 0.968750f, 0.367188f},
+ {0.621094f, 0.957031f, 0.769531f, 0.820312f}, {0.046875f, 0.449219f, 0.660156f, 0.492188f},
+ {0.562500f, 0.613281f, 0.089844f, 0.234375f}, {0.480469f, 0.710938f, 0.335938f, 0.027344f},
+ {0.851562f, 0.402344f, 0.156250f, 0.566406f}, {0.144531f, 0.554688f, 0.691406f, 0.507812f},
+ {0.957031f, 0.023438f, 0.378906f, 0.355469f}, {0.750000f, 0.605469f, 0.640625f, 0.054688f},
+ {0.207031f, 0.722656f, 0.941406f, 0.878906f}, {0.644531f, 0.429688f, 0.847656f, 0.660156f},
+ {0.847656f, 0.558594f, 0.773438f, 0.328125f}, {0.089844f, 0.691406f, 0.425781f, 0.125000f},
+ {0.480469f, 0.000000f, 0.195312f, 0.816406f}, {0.960938f, 0.332031f, 0.992188f, 0.226562f},
+ {0.019531f, 0.750000f, 0.457031f, 0.304688f}, {0.546875f, 0.175781f, 0.503906f, 0.027344f},
+ {0.253906f, 0.703125f, 0.046875f, 0.566406f}, {0.433594f, 0.898438f, 0.601562f, 0.199219f},
+ {0.925781f, 0.582031f, 0.972656f, 0.359375f}, {0.136719f, 0.687500f, 0.250000f, 0.699219f},
+ {0.269531f, 0.183594f, 0.468750f, 0.417969f}, {0.792969f, 0.066406f, 0.031250f, 0.003906f},
+ {0.050781f, 0.566406f, 0.578125f, 0.718750f}, {0.710938f, 0.273438f, 0.414062f, 0.093750f},
+ {0.769531f, 0.695312f, 0.500000f, 0.300781f}, {0.976562f, 0.792969f, 0.867188f, 0.152344f},
+ {0.093750f, 0.613281f, 0.054688f, 0.410156f}, {0.652344f, 0.339844f, 0.722656f, 0.808594f},
+ {0.570312f, 0.527344f, 0.804688f, 0.214844f}, {0.480469f, 0.398438f, 0.324219f, 0.312500f},
+ {0.371094f, 0.996094f, 0.851562f, 0.867188f}, {0.531250f, 0.621094f, 0.429688f, 0.250000f},
+ {0.441406f, 0.117188f, 0.039062f, 0.574219f}, {0.718750f, 0.355469f, 0.250000f, 0.703125f},
+ {0.843750f, 0.867188f, 0.515625f, 0.050781f}, {0.078125f, 0.511719f, 0.816406f, 0.976562f},
+ {0.621094f, 0.000000f, 0.667969f, 0.589844f}, {0.992188f, 0.800781f, 0.441406f, 0.882812f},
+ {0.277344f, 0.988281f, 0.898438f, 0.093750f}, {0.058594f, 0.277344f, 0.070312f, 0.722656f},
+ {0.351562f, 0.867188f, 0.746094f, 0.914062f}, {0.246094f, 0.507812f, 0.343750f, 0.601562f},
+ {0.707031f, 0.433594f, 0.996094f, 0.875000f}, {0.972656f, 0.640625f, 0.394531f, 0.406250f},
+ {0.664062f, 0.894531f, 0.253906f, 0.710938f}, {0.195312f, 0.406250f, 0.640625f, 0.906250f},
+ {0.015625f, 0.480469f, 0.921875f, 0.035156f}, {0.800781f, 0.070312f, 0.582031f, 0.953125f},
+ {0.679688f, 0.628906f, 0.062500f, 0.199219f}, {0.855469f, 0.218750f, 0.273438f, 0.265625f},
+ {0.449219f, 0.492188f, 0.792969f, 0.664062f}, {0.714844f, 0.101562f, 0.906250f, 0.808594f},
+ {0.578125f, 0.894531f, 0.714844f, 0.980469f}, {0.957031f, 0.421875f, 0.246094f, 0.058594f},
+ {0.757812f, 0.851562f, 0.578125f, 0.304688f}, {0.886719f, 0.789062f, 0.839844f, 0.488281f},
+ {0.000000f, 0.925781f, 0.140625f, 0.679688f}, {0.523438f, 0.121094f, 0.617188f, 0.355469f},
+ {0.406250f, 0.886719f, 0.710938f, 0.984375f}, {0.769531f, 0.035156f, 0.285156f, 0.503906f},
+ {0.890625f, 0.242188f, 0.906250f, 0.292969f}, {0.574219f, 0.531250f, 0.242188f, 0.703125f},
+ {0.171875f, 0.179688f, 0.121094f, 0.769531f}, {0.527344f, 0.718750f, 0.308594f, 0.968750f},
+ {0.433594f, 0.226562f, 0.171875f, 0.171875f}, {0.281250f, 0.105469f, 0.523438f, 0.125000f},
+ {0.761719f, 0.285156f, 0.417969f, 0.402344f}, {0.328125f, 0.515625f, 0.574219f, 0.691406f},
+ {0.406250f, 0.164062f, 0.910156f, 0.792969f}, {0.652344f, 0.996094f, 0.101562f, 0.109375f},
+ {0.062500f, 0.121094f, 0.507812f, 0.832031f}, {0.320312f, 0.378906f, 0.742188f, 0.242188f},
+ {0.390625f, 0.316406f, 0.175781f, 0.703125f}, {0.527344f, 0.156250f, 0.558594f, 0.417969f},
+ {0.933594f, 0.972656f, 0.085938f, 0.000000f}, {0.160156f, 0.199219f, 0.722656f, 0.734375f},
+ {0.242188f, 0.589844f, 0.898438f, 0.378906f}, {0.386719f, 0.941406f, 0.664062f, 0.503906f},
+ {0.652344f, 0.851562f, 0.339844f, 0.695312f}, {0.910156f, 0.628906f, 0.765625f, 0.953125f},
+ {0.343750f, 0.367188f, 0.218750f, 0.460938f}, {0.503906f, 0.136719f, 0.386719f, 0.769531f},
+ {0.078125f, 0.816406f, 0.117188f, 0.976562f}, {0.632812f, 0.257812f, 0.523438f, 0.511719f},
+ {0.378906f, 0.335938f, 0.722656f, 0.281250f}, {0.203125f, 0.769531f, 0.789062f, 0.558594f},
+ {0.511719f, 0.882812f, 0.144531f, 0.953125f}, {0.347656f, 0.117188f, 0.695312f, 0.769531f},
+ {0.253906f, 0.371094f, 0.964844f, 0.523438f}, {0.542969f, 0.425781f, 0.355469f, 0.878906f},
+ {0.382812f, 0.082031f, 0.167969f, 0.109375f}, {0.910156f, 0.894531f, 0.582031f, 0.363281f},
+ {0.132812f, 0.707031f, 0.472656f, 0.980469f}, {0.765625f, 0.210938f, 0.023438f, 0.445312f},
+ {0.000000f, 0.304688f, 0.976562f, 0.148438f}, {0.820312f, 0.542969f, 0.695312f, 0.023438f},
+ {0.230469f, 0.925781f, 0.625000f, 0.398438f}, {0.042969f, 0.429688f, 0.902344f, 0.792969f},
+ {0.554688f, 0.152344f, 0.738281f, 0.117188f}, {0.339844f, 0.730469f, 0.320312f, 0.480469f},
+ {0.804688f, 0.234375f, 0.960938f, 0.187500f}, {0.714844f, 0.375000f, 0.183594f, 0.347656f},
+ {0.578125f, 0.492188f, 0.539062f, 0.457031f}, {0.859375f, 0.203125f, 0.230469f, 0.550781f},
+ {0.769531f, 0.730469f, 0.832031f, 0.175781f}, {0.484375f, 0.789062f, 0.453125f, 0.031250f},
+ {0.308594f, 0.953125f, 0.718750f, 0.746094f}, {0.066406f, 0.554688f, 0.890625f, 0.214844f},
+ {0.378906f, 0.105469f, 0.085938f, 0.121094f}, {0.503906f, 0.195312f, 0.316406f, 0.605469f},
+ {0.949219f, 0.867188f, 0.167969f, 0.429688f}, {0.546875f, 0.531250f, 0.824219f, 0.542969f},
+ {0.316406f, 0.832031f, 0.207031f, 0.718750f}, {0.117188f, 0.390625f, 0.554688f, 0.460938f},
+ {0.515625f, 0.152344f, 0.492188f, 0.011719f}, {0.906250f, 0.597656f, 0.117188f, 0.156250f},
+ {0.046875f, 0.261719f, 0.417969f, 0.234375f}, {0.625000f, 0.542969f, 0.773438f, 0.707031f},
+ {0.386719f, 0.667969f, 0.476562f, 0.121094f}, {0.308594f, 0.062500f, 0.320312f, 0.593750f},
+ {0.167969f, 0.285156f, 0.886719f, 0.417969f}, {0.601562f, 0.199219f, 0.042969f, 0.777344f},
+ {0.835938f, 0.425781f, 0.187500f, 0.082031f}, {0.214844f, 0.343750f, 0.539062f, 0.648438f},
+ {0.023438f, 0.632812f, 0.398438f, 0.390625f}, {0.640625f, 0.093750f, 0.671875f, 0.195312f},
+ {0.984375f, 0.820312f, 0.445312f, 0.074219f}, {0.382812f, 0.921875f, 0.617188f, 0.449219f},
+ {0.910156f, 0.492188f, 0.828125f, 0.531250f}, {0.832031f, 0.683594f, 0.941406f, 0.859375f},
+ {0.125000f, 0.859375f, 0.046875f, 0.941406f}, {0.929688f, 0.058594f, 0.750000f, 0.617188f},
+ {0.218750f, 0.816406f, 0.835938f, 0.273438f}, {0.730469f, 0.222656f, 0.296875f, 0.441406f},
+ {0.574219f, 0.652344f, 0.441406f, 0.921875f}, {0.832031f, 0.886719f, 0.878906f, 0.484375f},
+ {0.117188f, 0.835938f, 0.226562f, 0.085938f}, {0.773438f, 0.050781f, 0.476562f, 0.781250f},
+ {0.343750f, 0.789062f, 0.292969f, 0.929688f}, {0.695312f, 0.468750f, 0.382812f, 0.535156f},
+ {0.882812f, 0.281250f, 0.019531f, 0.898438f}, {0.785156f, 0.125000f, 0.804688f, 0.160156f},
+ {0.304688f, 0.507812f, 0.101562f, 0.640625f}, {0.093750f, 0.230469f, 0.546875f, 0.105469f},
+ {0.839844f, 0.968750f, 0.929688f, 0.253906f}, {0.593750f, 0.476562f, 0.652344f, 0.605469f},
+ {0.773438f, 0.011719f, 0.816406f, 0.046875f}, {0.976562f, 0.527344f, 0.304688f, 0.890625f},
+ {0.464844f, 0.941406f, 0.187500f, 0.183594f}, {0.660156f, 0.460938f, 0.921875f, 0.804688f},
+ {0.875000f, 0.718750f, 0.328125f, 0.335938f}, {0.933594f, 0.175781f, 0.246094f, 0.214844f},
+ {0.011719f, 0.636719f, 0.000000f, 0.640625f}, {0.628906f, 0.980469f, 0.632812f, 0.925781f},
+ {0.187500f, 0.246094f, 0.281250f, 0.261719f}, {0.835938f, 0.046875f, 0.921875f, 0.617188f},
+ {0.273438f, 0.832031f, 0.660156f, 0.542969f}, {0.691406f, 0.648438f, 0.226562f, 0.726562f},
+ {0.988281f, 0.882812f, 0.527344f, 0.675781f}, {0.597656f, 0.039062f, 0.351562f, 0.921875f},
+ {0.304688f, 0.253906f, 0.152344f, 0.515625f}, {0.902344f, 0.804688f, 0.484375f, 0.277344f},
+ {0.656250f, 0.632812f, 0.113281f, 0.898438f}, {0.257812f, 0.078125f, 0.410156f, 0.742188f},
+ {0.132812f, 0.566406f, 0.000000f, 0.828125f}, {0.210938f, 0.914062f, 0.781250f, 0.042969f},
+ {0.394531f, 0.675781f, 0.613281f, 0.949219f}, {0.171875f, 0.117188f, 0.929688f, 0.664062f},
+ {0.910156f, 0.351562f, 0.300781f, 0.808594f}, {0.605469f, 0.160156f, 0.160156f, 0.503906f},
+ {0.214844f, 0.695312f, 0.597656f, 0.980469f}, {0.550781f, 0.246094f, 0.207031f, 0.562500f},
+ {0.847656f, 0.335938f, 0.789062f, 0.851562f}, {0.152344f, 0.601562f, 0.519531f, 0.277344f},
+ {0.722656f, 0.738281f, 0.742188f, 0.171875f}, {0.226562f, 0.296875f, 0.375000f, 0.777344f},
+ {0.625000f, 0.031250f, 0.683594f, 0.078125f}, {0.984375f, 0.917969f, 0.867188f, 0.851562f},
+ {0.171875f, 0.710938f, 0.339844f, 0.585938f}, {0.351562f, 0.996094f, 0.011719f, 0.746094f},
+ {0.277344f, 0.765625f, 0.636719f, 0.406250f}, {0.101562f, 0.183594f, 0.964844f, 0.890625f},
+ {0.539062f, 0.332031f, 0.089844f, 0.542969f}, {0.847656f, 0.472656f, 0.218750f, 0.960938f},
+ {0.722656f, 0.621094f, 0.515625f, 0.015625f}, {0.109375f, 0.750000f, 0.750000f, 0.859375f},
+ {0.355469f, 0.835938f, 0.347656f, 0.167969f}, {0.679688f, 0.976562f, 0.949219f, 0.562500f},
+ {0.496094f, 0.468750f, 0.148438f, 0.812500f}, {0.292969f, 0.281250f, 0.789062f, 0.945312f},
+ {0.789062f, 0.585938f, 0.882812f, 0.335938f}, {0.062500f, 0.324219f, 0.007812f, 0.679688f},
+ {0.695312f, 0.410156f, 0.214844f, 0.597656f}, {0.191406f, 0.140625f, 0.371094f, 0.292969f},
+ {0.636719f, 0.933594f, 0.261719f, 0.054688f}, {0.078125f, 0.351562f, 0.675781f, 0.753906f},
+ {0.515625f, 0.585938f, 0.191406f, 0.195312f}, {0.886719f, 0.742188f, 0.625000f, 0.332031f},
+ {0.441406f, 0.457031f, 0.988281f, 0.726562f}, {0.253906f, 0.265625f, 0.015625f, 0.156250f},
+ {0.980469f, 0.511719f, 0.355469f, 0.570312f}, {0.031250f, 0.628906f, 0.824219f, 0.296875f},
+ {0.617188f, 0.347656f, 0.949219f, 0.203125f}, {0.566406f, 0.875000f, 0.636719f, 0.621094f},
+ {0.058594f, 0.664062f, 0.246094f, 0.257812f}, {0.515625f, 0.734375f, 0.574219f, 0.437500f},
+ {0.183594f, 0.406250f, 0.167969f, 0.796875f}, {0.414062f, 0.062500f, 0.273438f, 0.343750f},
+ {0.703125f, 0.292969f, 0.843750f, 0.855469f}, {0.222656f, 0.781250f, 0.011719f, 0.152344f},
+ {0.023438f, 0.648438f, 0.437500f, 0.312500f}, {0.292969f, 0.382812f, 0.582031f, 0.738281f},
+ {0.726562f, 0.851562f, 0.074219f, 0.628906f}, {0.066406f, 0.050781f, 0.406250f, 0.121094f},
+ {0.171875f, 0.300781f, 0.843750f, 0.464844f}, {0.585938f, 0.542969f, 0.539062f, 0.386719f},
+ {0.804688f, 0.839844f, 0.750000f, 0.039062f}, {0.453125f, 0.500000f, 0.882812f, 0.707031f},
+ {0.722656f, 0.757812f, 0.445312f, 0.484375f}, {0.066406f, 0.578125f, 0.382812f, 0.007812f},
+ {0.429688f, 0.449219f, 0.835938f, 0.789062f}, {0.347656f, 0.109375f, 0.085938f, 0.089844f},
+ {0.203125f, 0.378906f, 0.781250f, 0.343750f}, {0.085938f, 0.742188f, 0.269531f, 0.835938f},
+ {0.742188f, 0.585938f, 0.929688f, 0.179688f}, {0.394531f, 0.191406f, 0.839844f, 0.632812f},
+ {0.964844f, 0.960938f, 0.210938f, 0.328125f}, {0.515625f, 0.464844f, 0.570312f, 0.539062f},
+ {0.460938f, 0.828125f, 0.710938f, 0.226562f}, {0.941406f, 0.042969f, 0.351562f, 0.613281f},
+ {0.671875f, 0.425781f, 0.085938f, 0.386719f}, {0.085938f, 0.882812f, 0.484375f, 0.128906f},
+ {0.437500f, 0.617188f, 0.660156f, 0.253906f}, {0.125000f, 0.058594f, 0.015625f, 0.324219f},
+ {0.929688f, 0.468750f, 0.550781f, 0.632812f}, {0.792969f, 0.824219f, 0.425781f, 0.468750f},
+ {0.636719f, 0.023438f, 0.949219f, 0.007812f}, {0.335938f, 0.937500f, 0.046875f, 0.667969f},
+ {0.882812f, 0.437500f, 0.468750f, 0.339844f}, {0.437500f, 0.125000f, 0.976562f, 0.976562f},
+ {0.085938f, 0.671875f, 0.082031f, 0.394531f}, {0.398438f, 0.562500f, 0.433594f, 0.308594f},
+ {0.773438f, 0.351562f, 0.937500f, 0.925781f}, {0.664062f, 0.453125f, 0.742188f, 0.523438f},
+ {0.871094f, 0.046875f, 0.289062f, 0.351562f}, {0.792969f, 0.871094f, 0.847656f, 0.832031f},
+ {0.195312f, 0.132812f, 0.378906f, 0.261719f}, {0.425781f, 0.964844f, 0.687500f, 0.187500f},
+ {0.996094f, 0.570312f, 0.933594f, 0.734375f}, {0.253906f, 0.011719f, 0.429688f, 0.316406f},
+ {0.906250f, 0.519531f, 0.820312f, 0.457031f}, {0.140625f, 0.132812f, 0.644531f, 0.250000f},
+ {0.820312f, 0.667969f, 0.074219f, 0.035156f}, {0.089844f, 0.902344f, 0.500000f, 0.488281f},
+ {0.449219f, 0.781250f, 0.324219f, 0.871094f}, {0.339844f, 0.000000f, 0.562500f, 0.230469f},
+ {0.246094f, 0.546875f, 0.695312f, 0.101562f}, {0.578125f, 0.644531f, 0.898438f, 0.804688f},
+ {0.460938f, 0.757812f, 0.496094f, 0.367188f}, {0.796875f, 0.437500f, 0.117188f, 0.476562f},
+ {0.359375f, 0.304688f, 0.347656f, 0.984375f}, {0.015625f, 0.906250f, 0.542969f, 0.015625f},
+ {0.175781f, 0.007812f, 0.074219f, 0.605469f}, {0.660156f, 0.703125f, 0.718750f, 0.882812f},
+ {0.496094f, 0.183594f, 0.582031f, 0.382812f}, {0.410156f, 0.761719f, 0.687500f, 0.968750f},
+ {0.199219f, 0.093750f, 0.117188f, 0.460938f}, {0.285156f, 0.222656f, 0.519531f, 0.070312f},
+ {0.445312f, 0.539062f, 0.855469f, 0.859375f}, {0.746094f, 0.023438f, 0.445312f, 0.039062f},
+ {0.996094f, 0.828125f, 0.957031f, 0.558594f}, {0.625000f, 0.914062f, 0.714844f, 0.707031f},
+ {0.890625f, 0.574219f, 0.484375f, 0.917969f}, {0.144531f, 0.089844f, 0.355469f, 0.527344f},
+ {0.367188f, 0.710938f, 0.894531f, 0.390625f}, {0.906250f, 0.160156f, 0.746094f, 0.441406f},
+ {0.531250f, 0.218750f, 0.671875f, 0.062500f}, {0.828125f, 0.605469f, 0.957031f, 0.851562f},
+ {0.324219f, 0.414062f, 0.617188f, 0.992188f}, {0.406250f, 0.917969f, 0.113281f, 0.601562f},
+ {0.125000f, 0.023438f, 0.480469f, 0.160156f}, {0.296875f, 0.328125f, 0.199219f, 0.828125f},
+ {0.953125f, 0.191406f, 0.070312f, 0.429688f}, {0.527344f, 0.941406f, 0.730469f, 0.199219f},
+ {0.609375f, 0.289062f, 0.140625f, 0.894531f}, {0.929688f, 0.160156f, 0.949219f, 0.285156f},
+ {0.503906f, 0.812500f, 0.601562f, 0.582031f}, {0.863281f, 0.484375f, 0.421875f, 0.464844f},
+ {0.457031f, 0.082031f, 0.058594f, 0.078125f}, {0.164062f, 0.398438f, 0.644531f, 0.968750f},
+ {0.097656f, 0.281250f, 0.300781f, 0.425781f}, {0.781250f, 0.695312f, 0.945312f, 0.003906f},
+ {0.015625f, 0.328125f, 0.871094f, 0.695312f}, {0.851562f, 0.179688f, 0.257812f, 0.292969f},
+ {0.531250f, 0.777344f, 0.144531f, 0.765625f}, {0.328125f, 0.527344f, 0.859375f, 0.863281f},
+ {0.824219f, 0.296875f, 0.375000f, 0.437500f}, {0.726562f, 0.917969f, 0.808594f, 0.062500f},
+ {0.273438f, 0.394531f, 0.109375f, 0.164062f}, {0.417969f, 0.515625f, 0.332031f, 0.378906f},
+ {0.097656f, 0.761719f, 0.695312f, 0.792969f}, {0.472656f, 0.652344f, 0.609375f, 0.898438f},
+ {0.039062f, 0.171875f, 0.277344f, 0.511719f}, {0.261719f, 0.976562f, 0.136719f, 0.695312f},
+ {0.828125f, 0.238281f, 0.648438f, 0.140625f}, {0.585938f, 0.792969f, 0.234375f, 0.632812f},
+ {0.007812f, 0.082031f, 0.593750f, 0.218750f}, {0.492188f, 0.281250f, 0.152344f, 0.097656f},
+ {0.234375f, 0.636719f, 0.199219f, 0.652344f}, {0.457031f, 0.402344f, 0.542969f, 0.035156f},
+ {0.691406f, 0.714844f, 0.050781f, 0.476562f}, {0.054688f, 0.808594f, 0.625000f, 0.382812f},
+ {0.628906f, 0.371094f, 0.125000f, 0.617188f}, {0.480469f, 0.253906f, 0.261719f, 0.933594f},
+ {0.558594f, 0.699219f, 0.015625f, 0.667969f}, {0.414062f, 0.394531f, 0.585938f, 0.902344f},
+ {0.964844f, 0.214844f, 0.230469f, 0.746094f}, {0.726562f, 0.070312f, 0.968750f, 0.136719f},
+ {0.609375f, 0.714844f, 0.742188f, 0.628906f}, {0.871094f, 0.171875f, 0.109375f, 0.425781f},
+ {0.035156f, 0.988281f, 0.421875f, 0.917969f}, {0.742188f, 0.253906f, 0.781250f, 0.710938f},
+ {0.972656f, 0.039062f, 0.605469f, 0.554688f}, {0.285156f, 0.191406f, 0.968750f, 0.140625f},
+ {0.554688f, 0.531250f, 0.851562f, 0.656250f}, {0.949219f, 0.101562f, 0.406250f, 0.828125f},
+ {0.710938f, 0.394531f, 0.242188f, 0.507812f}, {0.312500f, 0.953125f, 0.796875f, 0.265625f},
+ {0.816406f, 0.566406f, 0.156250f, 0.683594f}, {0.902344f, 0.433594f, 0.425781f, 0.121094f},
+ {0.726562f, 0.921875f, 0.210938f, 0.820312f}, {0.953125f, 0.386719f, 0.054688f, 0.726562f},
+ {0.132812f, 0.988281f, 0.761719f, 0.320312f}, {0.847656f, 0.167969f, 0.320312f, 0.996094f},
+ {0.007812f, 0.445312f, 0.398438f, 0.406250f}, {0.261719f, 0.621094f, 0.632812f, 0.210938f},
+ {0.472656f, 0.343750f, 0.082031f, 0.011719f}, {0.804688f, 0.882812f, 0.207031f, 0.656250f},
+ {0.574219f, 0.429688f, 0.140625f, 0.816406f}, {0.429688f, 0.988281f, 0.265625f, 0.937500f},
+ {0.246094f, 0.757812f, 0.488281f, 0.242188f}, {0.109375f, 0.109375f, 0.042969f, 0.675781f},
+ {0.691406f, 0.675781f, 0.367188f, 0.507812f}, {0.992188f, 0.234375f, 0.292969f, 0.269531f},
+ {0.500000f, 0.730469f, 0.808594f, 0.753906f}, {0.761719f, 0.128906f, 0.984375f, 0.312500f},
+ {0.234375f, 0.667969f, 0.648438f, 0.964844f}, {0.851562f, 0.398438f, 0.550781f, 0.664062f},
+ {0.039062f, 0.523438f, 0.312500f, 0.136719f}, {0.152344f, 0.699219f, 0.492188f, 0.406250f},
+ {0.644531f, 0.976562f, 0.187500f, 0.945312f}, {0.253906f, 0.320312f, 0.710938f, 0.210938f},
+ {0.687500f, 0.667969f, 0.546875f, 0.761719f}, {0.570312f, 0.898438f, 0.757812f, 0.667969f},
+ {0.882812f, 0.769531f, 0.097656f, 0.144531f}, {0.359375f, 0.519531f, 0.460938f, 0.878906f},
+ {0.597656f, 0.105469f, 0.675781f, 0.472656f}, {0.285156f, 0.976562f, 0.523438f, 0.996094f},
+ {0.750000f, 0.250000f, 0.421875f, 0.082031f}, {0.050781f, 0.578125f, 0.980469f, 0.523438f},
+ {0.625000f, 0.738281f, 0.742188f, 0.683594f}, {0.500000f, 0.214844f, 0.269531f, 0.937500f},
+ {0.000000f, 0.992188f, 0.917969f, 0.296875f}, {0.187500f, 0.144531f, 0.832031f, 0.726562f},
+ {0.988281f, 0.277344f, 0.156250f, 0.226562f}, {0.769531f, 0.363281f, 0.398438f, 0.097656f},
+ {0.562500f, 0.570312f, 0.898438f, 0.437500f}, {0.687500f, 0.851562f, 0.531250f, 0.246094f},
+ {0.941406f, 0.410156f, 0.839844f, 0.027344f}, {0.730469f, 0.511719f, 0.308594f, 0.867188f},
+ {0.300781f, 0.199219f, 0.796875f, 0.492188f}, {0.914062f, 0.828125f, 0.496094f, 0.781250f},
+ {0.132812f, 0.949219f, 0.703125f, 0.171875f}, {0.953125f, 0.527344f, 0.445312f, 0.941406f},
+ {0.582031f, 0.230469f, 0.878906f, 0.691406f}, {0.339844f, 0.085938f, 0.781250f, 0.816406f},
+ {0.804688f, 0.890625f, 0.570312f, 0.062500f}, {0.082031f, 0.164062f, 0.312500f, 0.523438f},
+ {0.765625f, 0.785156f, 0.859375f, 0.101562f}, {0.312500f, 0.925781f, 0.453125f, 0.359375f},
+ {0.230469f, 0.558594f, 0.691406f, 0.578125f}, {0.535156f, 0.335938f, 0.378906f, 0.277344f},
+ {0.167969f, 0.441406f, 0.273438f, 0.777344f}, {0.941406f, 0.875000f, 0.855469f, 0.000000f},
+ {0.507812f, 0.371094f, 0.160156f, 0.507812f}, {0.394531f, 0.800781f, 0.050781f, 0.191406f},
+ {0.148438f, 0.597656f, 0.304688f, 0.261719f}, {0.679688f, 0.960938f, 0.457031f, 0.894531f},
+ {0.226562f, 0.855469f, 0.027344f, 0.410156f}, {0.843750f, 0.675781f, 0.765625f, 0.093750f},
+ {0.601562f, 0.796875f, 0.937500f, 0.222656f}, {0.097656f, 0.148438f, 0.488281f, 0.785156f},
+ {0.148438f, 0.300781f, 0.320312f, 0.035156f}, {0.539062f, 0.039062f, 0.906250f, 0.632812f},
+ {0.070312f, 0.609375f, 0.609375f, 0.363281f}, {0.671875f, 0.816406f, 0.972656f, 0.500000f},
+ {0.371094f, 0.312500f, 0.699219f, 0.585938f}, {0.589844f, 0.699219f, 0.136719f, 0.148438f},
+ {0.328125f, 0.261719f, 0.031250f, 0.773438f}, {0.546875f, 0.746094f, 0.910156f, 0.277344f},
+ {0.105469f, 0.195312f, 0.589844f, 0.472656f}, {0.679688f, 0.519531f, 0.773438f, 0.109375f},
+ {0.937500f, 0.246094f, 0.996094f, 0.722656f}, {0.179688f, 0.324219f, 0.558594f, 0.195312f},
+ {0.753906f, 0.562500f, 0.878906f, 0.562500f}, {0.601562f, 0.488281f, 0.222656f, 0.355469f},
+ {0.867188f, 0.949219f, 0.773438f, 0.105469f}, {0.210938f, 0.808594f, 0.167969f, 0.867188f},
+ {0.648438f, 0.363281f, 0.574219f, 0.058594f}, {0.078125f, 0.468750f, 0.410156f, 0.574219f},
+ {0.375000f, 0.878906f, 0.035156f, 0.515625f}, {0.679688f, 0.796875f, 0.234375f, 0.351562f},
+ {0.316406f, 0.007812f, 0.765625f, 0.742188f}, {0.792969f, 0.609375f, 0.375000f, 0.625000f},
+ {0.402344f, 0.234375f, 0.890625f, 0.808594f}, {0.019531f, 0.871094f, 0.007812f, 0.054688f},
+ {0.824219f, 0.546875f, 0.332031f, 0.546875f}, {0.320312f, 0.015625f, 0.812500f, 0.363281f},
+ {0.222656f, 0.144531f, 0.390625f, 0.246094f}, {0.722656f, 0.363281f, 0.167969f, 0.597656f},
+ {0.417969f, 0.859375f, 0.031250f, 0.792969f}, {0.179688f, 0.648438f, 0.800781f, 0.167969f},
+ {0.917969f, 0.402344f, 0.632812f, 0.351562f}, {0.246094f, 0.007812f, 0.058594f, 0.207031f},
+ {0.964844f, 0.839844f, 0.191406f, 0.585938f}, {0.367188f, 0.097656f, 0.503906f, 0.820312f},
+ {0.878906f, 0.609375f, 0.039062f, 0.117188f}, {0.589844f, 0.871094f, 0.640625f, 0.914062f},
+ {0.675781f, 0.058594f, 0.230469f, 0.542969f}, {0.296875f, 0.796875f, 0.773438f, 0.613281f},
+ {0.898438f, 0.484375f, 0.019531f, 0.828125f}, {0.140625f, 0.007812f, 0.730469f, 0.937500f},
+ {0.355469f, 0.304688f, 0.363281f, 0.578125f}, {0.191406f, 0.753906f, 0.070312f, 0.722656f},
+ {0.535156f, 0.906250f, 0.902344f, 0.433594f}, {0.636719f, 0.578125f, 0.031250f, 0.992188f},
+ {0.367188f, 0.019531f, 0.992188f, 0.332031f}, {0.738281f, 0.683594f, 0.343750f, 0.554688f},
+ {0.027344f, 0.320312f, 0.250000f, 0.128906f}, {0.285156f, 0.441406f, 0.167969f, 0.296875f},
+ {0.933594f, 0.605469f, 0.488281f, 0.234375f}, {0.179688f, 0.500000f, 0.980469f, 0.785156f},
+ {0.660156f, 0.304688f, 0.734375f, 0.433594f}, {0.011719f, 0.035156f, 0.183594f, 0.207031f},
+ {0.855469f, 0.843750f, 0.906250f, 0.703125f}, {0.371094f, 0.617188f, 0.042969f, 0.988281f},
+ {0.105469f, 0.269531f, 0.480469f, 0.398438f}, {0.656250f, 0.519531f, 0.640625f, 0.328125f},
+ {0.773438f, 0.097656f, 0.941406f, 0.843750f}, {0.312500f, 0.472656f, 0.539062f, 0.964844f},
+ {0.894531f, 0.703125f, 0.238281f, 0.046875f}, {0.109375f, 0.132812f, 0.703125f, 0.769531f},
+ {0.429688f, 0.273438f, 0.175781f, 0.585938f}, {0.046875f, 0.492188f, 0.574219f, 0.347656f},
+ {0.382812f, 0.355469f, 0.285156f, 0.953125f}, {0.472656f, 0.636719f, 0.660156f, 0.437500f},
+ {0.769531f, 0.847656f, 0.093750f, 0.542969f}, {0.347656f, 0.246094f, 0.832031f, 0.910156f},
+ {0.250000f, 0.726562f, 0.371094f, 0.175781f}, {0.875000f, 0.136719f, 0.273438f, 0.238281f},
+ {0.492188f, 0.484375f, 0.500000f, 0.671875f}, {0.210938f, 0.562500f, 0.871094f, 0.089844f},
+ {0.820312f, 0.078125f, 0.234375f, 0.890625f}, {0.718750f, 0.957031f, 0.812500f, 0.621094f},
+ {0.398438f, 0.121094f, 0.515625f, 0.949219f}, {0.035156f, 0.804688f, 0.300781f, 0.367188f},
+ {0.308594f, 0.015625f, 0.386719f, 0.589844f}, {0.640625f, 0.636719f, 0.707031f, 0.296875f},
+ {0.054688f, 0.898438f, 0.101562f, 0.023438f}, {0.468750f, 0.042969f, 0.445312f, 0.789062f},
+ {0.359375f, 0.285156f, 0.652344f, 0.714844f}, {0.027344f, 0.167969f, 0.925781f, 0.421875f},
+ {0.554688f, 0.539062f, 0.710938f, 0.929688f}, {0.890625f, 0.621094f, 0.332031f, 0.226562f},
+ {0.164062f, 0.093750f, 0.906250f, 0.109375f}, {0.578125f, 0.265625f, 0.855469f, 0.882812f},
+ {0.460938f, 0.910156f, 0.671875f, 0.042969f}, {0.914062f, 0.367188f, 0.105469f, 0.250000f},
+ {0.734375f, 0.070312f, 0.621094f, 0.492188f}, {0.542969f, 0.183594f, 0.996094f, 0.308594f},
+ {0.980469f, 0.421875f, 0.238281f, 0.703125f}, {0.128906f, 0.621094f, 0.503906f, 0.933594f},
+ {0.632812f, 0.925781f, 0.906250f, 0.839844f}, {0.953125f, 0.218750f, 0.597656f, 0.109375f},
+ {0.039062f, 0.589844f, 0.960938f, 0.402344f}, {0.667969f, 0.714844f, 0.218750f, 0.550781f},
+ {0.472656f, 0.484375f, 0.312500f, 0.718750f}, {0.558594f, 0.152344f, 0.582031f, 0.894531f},
+ {0.152344f, 0.355469f, 0.691406f, 0.023438f}, {0.691406f, 0.671875f, 0.445312f, 0.410156f},
+ {0.753906f, 0.316406f, 0.867188f, 0.496094f}, {0.527344f, 0.546875f, 0.562500f, 0.656250f},
+ {0.125000f, 0.714844f, 0.304688f, 0.042969f}, {0.390625f, 0.218750f, 0.988281f, 0.320312f},
+ {0.218750f, 0.894531f, 0.585938f, 0.183594f}, {0.511719f, 0.691406f, 0.187500f, 0.761719f},
+ {0.457031f, 0.101562f, 0.457031f, 0.296875f}, {0.050781f, 0.628906f, 0.671875f, 0.371094f},
+ {0.816406f, 0.148438f, 0.554688f, 0.054688f}, {0.082031f, 0.371094f, 0.386719f, 0.269531f},
+ {0.417969f, 0.472656f, 0.753906f, 0.617188f}, {0.839844f, 0.175781f, 0.109375f, 0.750000f},
+ {0.218750f, 0.933594f, 0.656250f, 0.421875f}, {0.527344f, 0.742188f, 0.910156f, 0.910156f},
+ {0.875000f, 0.050781f, 0.402344f, 0.589844f}, {0.390625f, 0.988281f, 0.082031f, 0.972656f},
+ {0.460938f, 0.652344f, 0.355469f, 0.148438f}, {0.921875f, 0.464844f, 0.546875f, 0.847656f},
+ {0.601562f, 0.113281f, 0.132812f, 0.484375f}, {0.710938f, 0.964844f, 0.773438f, 0.089844f},
+ {0.273438f, 0.761719f, 0.593750f, 0.550781f}, {0.433594f, 0.664062f, 0.199219f, 0.156250f},
+ {0.203125f, 0.222656f, 0.355469f, 0.664062f}, {0.000000f, 0.835938f, 0.812500f, 0.609375f},
+ {0.625000f, 0.320312f, 0.738281f, 0.445312f}, {0.804688f, 0.410156f, 0.914062f, 0.304688f},
+ {0.523438f, 0.617188f, 0.644531f, 0.695312f}, {0.738281f, 0.070312f, 0.121094f, 0.179688f},
+ {0.886719f, 0.210938f, 0.890625f, 0.859375f}, {0.210938f, 0.984375f, 0.531250f, 0.730469f},
+ {0.988281f, 0.464844f, 0.000000f, 0.312500f}, {0.628906f, 0.527344f, 0.726562f, 0.078125f},
+ {0.433594f, 0.902344f, 0.472656f, 0.765625f}, {0.789062f, 0.058594f, 0.171875f, 0.957031f},
+ {0.042969f, 0.656250f, 0.570312f, 0.441406f}, {0.652344f, 0.796875f, 0.656250f, 0.832031f},
+ {0.914062f, 0.371094f, 0.339844f, 0.332031f}, {0.164062f, 0.875000f, 0.453125f, 0.515625f},
+ {0.968750f, 0.476562f, 0.167969f, 0.750000f}, {0.777344f, 0.683594f, 0.683594f, 0.160156f},
+ {0.492188f, 0.851562f, 0.019531f, 0.843750f}, {0.855469f, 0.144531f, 0.808594f, 0.972656f},
+ {0.960938f, 0.449219f, 0.332031f, 0.453125f}, {0.265625f, 0.781250f, 0.531250f, 0.898438f},
+ {0.781250f, 0.394531f, 0.851562f, 0.183594f}, {0.921875f, 0.855469f, 0.015625f, 0.628906f},
+ {0.285156f, 0.066406f, 0.132812f, 0.378906f}, {0.421875f, 0.992188f, 0.507812f, 0.796875f},
+ {0.816406f, 0.753906f, 0.269531f, 0.695312f}, {0.972656f, 0.570312f, 0.468750f, 0.449219f},
+ {0.113281f, 0.148438f, 0.160156f, 0.554688f}, {0.199219f, 0.726562f, 0.796875f, 0.992188f},
+ {0.285156f, 0.464844f, 0.289062f, 0.164062f}, {0.070312f, 0.785156f, 0.453125f, 0.875000f},
+ {0.375000f, 0.832031f, 0.843750f, 0.437500f}, {0.500000f, 0.269531f, 0.125000f, 0.023438f},
+ {0.445312f, 0.726562f, 0.687500f, 0.507812f}, {0.089844f, 0.457031f, 0.277344f, 0.289062f},
+ {0.839844f, 0.046875f, 0.359375f, 0.917969f}, {0.773438f, 0.300781f, 0.761719f, 0.050781f},
+ {0.347656f, 0.945312f, 0.882812f, 0.640625f}, {0.101562f, 0.902344f, 0.117188f, 0.460938f},
+ {0.816406f, 0.785156f, 0.937500f, 0.265625f}, {0.445312f, 0.453125f, 0.351562f, 0.765625f},
+ {0.226562f, 0.171875f, 0.726562f, 0.351562f}, {0.324219f, 0.921875f, 0.082031f, 0.839844f},
+ {0.808594f, 0.402344f, 0.421875f, 0.988281f}, {0.027344f, 0.113281f, 0.492188f, 0.398438f},
+ {0.855469f, 0.589844f, 0.109375f, 0.480469f}, {0.648438f, 0.339844f, 0.878906f, 0.066406f},
+ {0.976562f, 0.945312f, 0.257812f, 0.539062f}, {0.765625f, 0.433594f, 0.953125f, 0.160156f},
+ {0.250000f, 0.726562f, 0.140625f, 0.820312f}, {0.570312f, 0.261719f, 0.210938f, 0.894531f},
+ {0.964844f, 0.789062f, 0.613281f, 0.097656f}, {0.160156f, 0.117188f, 0.300781f, 0.210938f},
+ {0.488281f, 0.839844f, 0.820312f, 0.859375f}, {0.707031f, 0.542969f, 0.019531f, 0.496094f},
+ {0.605469f, 0.273438f, 0.714844f, 0.007812f}, {0.125000f, 0.820312f, 0.222656f, 0.718750f},
+ {0.750000f, 0.363281f, 0.652344f, 0.339844f}, {0.207031f, 0.195312f, 0.804688f, 0.636719f},
+ {0.050781f, 0.718750f, 0.300781f, 0.039062f}, {0.492188f, 0.406250f, 0.406250f, 0.906250f},
+ {0.910156f, 0.152344f, 0.992188f, 0.796875f}, {0.832031f, 0.015625f, 0.683594f, 0.214844f},
+ {0.570312f, 0.937500f, 0.085938f, 0.738281f}, {0.984375f, 0.570312f, 0.472656f, 0.371094f},
+ {0.468750f, 0.050781f, 0.394531f, 0.121094f}, {0.253906f, 0.886719f, 0.066406f, 0.820312f},
+ {0.328125f, 0.769531f, 0.332031f, 0.535156f}, {0.937500f, 0.921875f, 0.441406f, 0.011719f},
+ {0.640625f, 0.718750f, 0.199219f, 0.488281f}, {0.289062f, 0.031250f, 0.390625f, 0.136719f},
+ {0.007812f, 0.773438f, 0.992188f, 0.601562f}, {0.566406f, 0.398438f, 0.230469f, 0.406250f},
+ {0.171875f, 0.191406f, 0.785156f, 0.855469f}, {0.933594f, 0.343750f, 0.046875f, 0.285156f},
+ {0.121094f, 0.949219f, 0.921875f, 0.003906f}, {0.292969f, 0.218750f, 0.097656f, 0.558594f},
+ {0.441406f, 0.027344f, 0.734375f, 0.199219f}, {0.515625f, 0.597656f, 0.976562f, 0.050781f},
+ {0.250000f, 0.402344f, 0.066406f, 0.425781f}, {0.363281f, 0.300781f, 0.859375f, 0.250000f},
+ {0.203125f, 0.546875f, 0.433594f, 0.066406f}, {0.117188f, 0.363281f, 0.613281f, 0.644531f},
+ {0.542969f, 0.726562f, 0.191406f, 0.535156f}, {0.410156f, 0.199219f, 0.964844f, 0.125000f},
+ {0.140625f, 0.578125f, 0.261719f, 0.316406f}, {0.667969f, 0.660156f, 0.394531f, 0.496094f},
+ {0.488281f, 0.441406f, 0.625000f, 0.003906f}, {0.734375f, 0.304688f, 0.820312f, 0.601562f},
+ {0.007812f, 0.203125f, 0.082031f, 0.292969f}, {0.250000f, 0.417969f, 0.593750f, 0.191406f},
+ {0.511719f, 0.503906f, 0.953125f, 0.832031f}, {0.703125f, 0.960938f, 0.417969f, 0.656250f},
+ {0.605469f, 0.656250f, 0.566406f, 0.386719f}, {0.886719f, 0.312500f, 0.070312f, 0.097656f},
+ {0.753906f, 0.511719f, 0.640625f, 0.777344f}, {0.191406f, 0.109375f, 0.203125f, 0.621094f},
+ {0.917969f, 0.992188f, 0.738281f, 0.175781f}, {0.300781f, 0.390625f, 0.437500f, 0.664062f},
+ {0.515625f, 0.816406f, 0.078125f, 0.742188f}, {0.230469f, 0.085938f, 0.488281f, 0.226562f},
+ {0.589844f, 0.203125f, 0.546875f, 0.324219f}, {0.894531f, 0.558594f, 0.406250f, 0.832031f},
+ {0.292969f, 0.261719f, 0.250000f, 0.964844f}, {0.058594f, 0.027344f, 0.789062f, 0.179688f},
+ {0.968750f, 0.812500f, 0.515625f, 0.554688f}, {0.484375f, 0.496094f, 0.207031f, 0.242188f},
+ {0.914062f, 0.253906f, 0.921875f, 0.144531f}, {0.605469f, 0.968750f, 0.816406f, 0.714844f},
+ {0.734375f, 0.457031f, 0.699219f, 0.648438f}, {0.097656f, 0.183594f, 0.332031f, 0.882812f},
+ {0.410156f, 0.832031f, 0.605469f, 0.957031f}, {0.292969f, 0.542969f, 0.761719f, 0.679688f},
+ {0.691406f, 0.039062f, 0.421875f, 0.597656f}, {0.878906f, 0.984375f, 0.859375f, 0.468750f},
+ {0.324219f, 0.601562f, 0.507812f, 0.710938f}, {0.664062f, 0.343750f, 0.925781f, 0.363281f},
+ {0.785156f, 0.640625f, 0.453125f, 0.070312f}, {0.093750f, 0.214844f, 0.582031f, 0.652344f},
+ {0.347656f, 0.417969f, 0.519531f, 0.390625f}, {0.949219f, 0.140625f, 0.843750f, 0.277344f},
+ {0.261719f, 0.769531f, 0.937500f, 0.546875f}, {0.566406f, 0.535156f, 0.066406f, 0.757812f},
+ {0.328125f, 0.250000f, 0.503906f, 0.253906f}, {0.796875f, 0.589844f, 0.871094f, 0.445312f},
+ {0.144531f, 0.898438f, 0.003906f, 0.304688f}, {0.074219f, 0.308594f, 0.261719f, 0.953125f},
+ {0.355469f, 0.390625f, 0.839844f, 0.492188f}, {0.691406f, 0.742188f, 0.144531f, 0.062500f},
+ {0.863281f, 0.183594f, 0.589844f, 0.917969f}, {0.175781f, 0.527344f, 0.976562f, 0.230469f},
+ {0.582031f, 0.238281f, 0.511719f, 0.992188f}, {0.074219f, 0.441406f, 0.855469f, 0.644531f},
+ {0.140625f, 0.554688f, 0.750000f, 0.277344f}, {0.488281f, 0.328125f, 0.687500f, 0.941406f},
+ {0.824219f, 0.121094f, 0.582031f, 0.210938f}, {0.703125f, 0.687500f, 0.332031f, 0.699219f},
+ {0.324219f, 0.593750f, 0.625000f, 0.519531f}, {0.734375f, 0.859375f, 0.429688f, 0.644531f},
+ {0.390625f, 0.433594f, 0.839844f, 0.378906f}, {0.609375f, 0.515625f, 0.390625f, 0.738281f},
+ {0.761719f, 0.714844f, 0.539062f, 0.976562f}, {0.074219f, 0.269531f, 0.277344f, 0.679688f},
+ {0.882812f, 0.167969f, 0.636719f, 0.796875f}, {0.667969f, 0.769531f, 0.226562f, 0.886719f},
+ {0.593750f, 0.925781f, 0.941406f, 0.492188f}, {0.734375f, 0.078125f, 0.128906f, 0.386719f},
+ {0.332031f, 0.980469f, 0.722656f, 0.765625f}, {0.699219f, 0.269531f, 0.058594f, 0.265625f},
+ {0.835938f, 0.105469f, 0.476562f, 0.699219f}, {0.058594f, 0.917969f, 0.753906f, 0.984375f},
+ {0.191406f, 0.710938f, 0.214844f, 0.847656f}, {0.609375f, 0.023438f, 0.976562f, 0.144531f},
+ {0.332031f, 0.894531f, 0.683594f, 0.953125f}, {0.640625f, 0.339844f, 0.355469f, 0.761719f},
+ {0.867188f, 0.839844f, 0.023438f, 0.027344f}, {0.359375f, 0.117188f, 0.222656f, 0.328125f},
+ {0.441406f, 0.242188f, 0.718750f, 0.726562f}, {0.136719f, 0.933594f, 0.878906f, 0.585938f},
+ {0.656250f, 0.027344f, 0.382812f, 0.218750f}, {0.796875f, 0.566406f, 0.531250f, 0.976562f},
+ {0.582031f, 0.160156f, 0.023438f, 0.339844f}, {0.703125f, 0.664062f, 0.921875f, 0.425781f},
+ {0.390625f, 0.765625f, 0.851562f, 0.812500f}, {0.132812f, 0.515625f, 0.156250f, 0.945312f},
+ {0.996094f, 0.871094f, 0.718750f, 0.140625f}, {0.718750f, 0.417969f, 0.003906f, 0.593750f},
+ {0.406250f, 0.632812f, 0.621094f, 0.066406f}, {0.652344f, 0.738281f, 0.148438f, 0.679688f},
+ {0.167969f, 0.363281f, 0.285156f, 0.929688f}, {0.082031f, 0.078125f, 0.667969f, 0.000000f},
+ {0.429688f, 0.675781f, 0.027344f, 0.453125f}, {0.261719f, 0.617188f, 0.382812f, 0.796875f},
+ {0.339844f, 0.785156f, 0.234375f, 0.265625f}, {0.546875f, 0.050781f, 0.523438f, 0.105469f},
+ {0.164062f, 0.273438f, 0.007812f, 0.222656f}, {0.910156f, 0.667969f, 0.804688f, 0.390625f},
+ {0.492188f, 0.203125f, 0.082031f, 0.011719f}, {0.121094f, 0.863281f, 0.269531f, 0.242188f},
+ {0.011719f, 0.414062f, 0.695312f, 0.519531f}, {0.449219f, 0.496094f, 0.058594f, 0.972656f},
+ {0.238281f, 0.914062f, 0.191406f, 0.765625f}, {0.855469f, 0.078125f, 0.367188f, 0.179688f},
+ {0.046875f, 0.882812f, 0.281250f, 0.828125f}, {0.437500f, 0.687500f, 0.148438f, 0.113281f},
+ {0.816406f, 0.015625f, 0.613281f, 0.949219f}, {0.683594f, 0.937500f, 0.437500f, 0.187500f},
+ {0.988281f, 0.859375f, 0.238281f, 0.867188f}, {0.398438f, 0.085938f, 0.574219f, 0.597656f},
+ {0.636719f, 0.496094f, 0.722656f, 0.683594f}, {0.742188f, 0.808594f, 0.339844f, 0.019531f},
+ {0.234375f, 0.625000f, 0.531250f, 0.574219f}, {0.535156f, 0.460938f, 0.890625f, 0.269531f},
+ {0.050781f, 0.976562f, 0.289062f, 0.781250f}, {0.730469f, 0.109375f, 0.214844f, 0.460938f},
+ {0.371094f, 0.363281f, 0.789062f, 0.390625f}, {0.789062f, 0.656250f, 0.042969f, 0.074219f},
+ {0.679688f, 0.164062f, 0.269531f, 0.757812f}, {0.402344f, 0.839844f, 0.105469f, 0.359375f},
+ {0.875000f, 0.261719f, 0.875000f, 0.808594f}, {0.234375f, 0.933594f, 0.144531f, 0.046875f},
+ {0.062500f, 0.082031f, 0.945312f, 0.125000f}, {0.523438f, 0.285156f, 0.289062f, 0.937500f},
+ {0.855469f, 0.753906f, 0.691406f, 0.164062f}, {0.984375f, 0.148438f, 0.207031f, 0.464844f},
+ {0.027344f, 0.894531f, 0.132812f, 0.265625f}, {0.562500f, 0.976562f, 0.785156f, 0.593750f},
+ {0.144531f, 0.625000f, 0.476562f, 0.136719f}, {0.824219f, 0.046875f, 0.355469f, 0.320312f},
+ {0.445312f, 0.226562f, 0.558594f, 0.710938f}, {0.000000f, 0.664062f, 0.289062f, 0.207031f},
+ {0.910156f, 0.468750f, 0.835938f, 0.921875f}, {0.222656f, 0.609375f, 0.589844f, 0.039062f},
+ {0.582031f, 0.820312f, 0.898438f, 0.812500f}, {0.984375f, 0.347656f, 0.308594f, 0.445312f},
+ {0.378906f, 0.238281f, 0.550781f, 0.238281f}, {0.796875f, 0.523438f, 0.437500f, 0.542969f},
+ {0.937500f, 0.792969f, 0.179688f, 0.355469f}, {0.097656f, 0.687500f, 0.742188f, 0.429688f},
+ {0.761719f, 0.597656f, 0.523438f, 0.511719f}, {0.035156f, 0.050781f, 0.929688f, 0.132812f},
+ {0.957031f, 0.406250f, 0.328125f, 0.921875f}, {0.230469f, 0.609375f, 0.148438f, 0.472656f},
+ {0.335938f, 0.707031f, 0.777344f, 0.285156f}, {0.019531f, 0.351562f, 0.976562f, 0.824219f},
+ {0.261719f, 0.859375f, 0.316406f, 0.058594f}, {0.058594f, 0.230469f, 0.570312f, 0.570312f},
+ {0.882812f, 0.324219f, 0.652344f, 0.484375f}, {0.628906f, 0.601562f, 0.210938f, 0.015625f},
+ {0.195312f, 0.132812f, 0.988281f, 0.371094f}, {0.015625f, 0.699219f, 0.832031f, 0.527344f},
+ {0.535156f, 0.066406f, 0.335938f, 0.433594f}, {0.851562f, 0.976562f, 0.953125f, 0.742188f},
+ {0.574219f, 0.578125f, 0.468750f, 0.621094f}, {0.773438f, 0.855469f, 0.843750f, 0.316406f},
+ {0.703125f, 0.148438f, 0.750000f, 0.898438f}, {0.187500f, 0.300781f, 0.136719f, 0.582031f},
+ {0.960938f, 0.742188f, 0.644531f, 0.359375f}, {0.796875f, 0.378906f, 0.972656f, 0.523438f},
+ {0.031250f, 0.917969f, 0.171875f, 0.847656f}, {0.593750f, 0.507812f, 0.468750f, 0.445312f},
+ {0.207031f, 0.332031f, 0.359375f, 0.785156f}, {0.753906f, 0.105469f, 0.566406f, 0.914062f},
+ {0.386719f, 0.695312f, 0.960938f, 0.128906f}, {0.613281f, 0.000000f, 0.128906f, 0.308594f},
+ {0.914062f, 0.296875f, 0.792969f, 0.570312f}, {0.300781f, 0.730469f, 0.734375f, 0.457031f},
+ {0.550781f, 0.574219f, 0.972656f, 0.890625f}, {0.644531f, 0.480469f, 0.046875f, 0.687500f},
+ {0.160156f, 0.312500f, 0.335938f, 0.500000f}, {0.507812f, 0.625000f, 0.765625f, 0.417969f},
+ {0.093750f, 0.433594f, 0.164062f, 0.082031f}, {0.195312f, 0.347656f, 0.953125f, 0.355469f},
+ {0.468750f, 0.699219f, 0.109375f, 0.140625f}, {0.941406f, 0.210938f, 0.449219f, 0.832031f},
+ {0.296875f, 0.039062f, 0.656250f, 0.410156f}, {0.417969f, 0.277344f, 0.761719f, 0.878906f},
+ {0.121094f, 0.679688f, 0.027344f, 0.625000f}, {0.910156f, 0.792969f, 0.699219f, 0.156250f},
+ {0.449219f, 0.863281f, 0.625000f, 0.710938f}, {0.968750f, 0.011719f, 0.367188f, 0.871094f},
+ {0.199219f, 0.964844f, 0.554688f, 0.546875f}, {0.531250f, 0.605469f, 0.816406f, 0.441406f},
+ {0.105469f, 0.496094f, 0.460938f, 0.906250f}, {0.960938f, 0.804688f, 0.062500f, 0.484375f},
+ {0.457031f, 0.546875f, 0.515625f, 0.324219f}, {0.660156f, 0.003906f, 0.753906f, 0.578125f},
+ {0.199219f, 0.636719f, 0.035156f, 0.804688f}, {0.265625f, 0.320312f, 0.593750f, 0.093750f},
+ {0.347656f, 0.101562f, 0.957031f, 0.906250f}, {0.710938f, 0.453125f, 0.875000f, 0.363281f},
+ {0.402344f, 0.824219f, 0.027344f, 0.019531f}, {0.292969f, 0.531250f, 0.750000f, 0.554688f},
+ {0.976562f, 0.414062f, 0.910156f, 0.949219f}, {0.078125f, 0.863281f, 0.507812f, 0.089844f},
+ {0.792969f, 0.312500f, 0.390625f, 0.609375f}, {0.500000f, 0.000000f, 0.664062f, 0.347656f},
+ {0.304688f, 0.507812f, 0.160156f, 0.570312f}, {0.089844f, 0.152344f, 0.109375f, 0.097656f},
+ {0.457031f, 0.957031f, 0.800781f, 0.664062f}, {0.539062f, 0.636719f, 0.066406f, 0.738281f},
+ {0.144531f, 0.085938f, 0.878906f, 0.082031f}, {0.414062f, 0.175781f, 0.277344f, 0.886719f},
+ {0.292969f, 0.285156f, 0.835938f, 0.636719f}, {0.570312f, 0.750000f, 0.617188f, 0.257812f},
+ {0.812500f, 0.886719f, 0.058594f, 0.851562f}, {0.527344f, 0.199219f, 0.464844f, 0.082031f},
+ {0.851562f, 0.773438f, 0.664062f, 0.535156f}, {0.414062f, 0.441406f, 0.257812f, 0.679688f},
+ {0.976562f, 0.914062f, 0.109375f, 0.148438f}, {0.539062f, 0.488281f, 0.812500f, 0.886719f},
+ {0.816406f, 0.000000f, 0.371094f, 0.257812f}, {0.316406f, 0.960938f, 0.285156f, 0.703125f},
+ {0.484375f, 0.382812f, 0.457031f, 0.785156f}, {0.785156f, 0.277344f, 0.675781f, 0.875000f},
+ {0.265625f, 0.476562f, 0.070312f, 0.289062f}, {0.355469f, 0.207031f, 0.585938f, 0.109375f},
+ {0.636719f, 0.917969f, 0.179688f, 0.851562f}, {0.929688f, 0.519531f, 0.347656f, 0.515625f},
+ {0.007812f, 0.425781f, 0.554688f, 0.199219f}, {0.507812f, 0.011719f, 0.445312f, 0.085938f},
+ {0.667969f, 0.886719f, 0.859375f, 0.976562f}, {0.382812f, 0.476562f, 0.300781f, 0.738281f},
+ {0.843750f, 0.128906f, 0.726562f, 0.613281f}, {0.437500f, 0.808594f, 0.898438f, 0.183594f},
+ {0.652344f, 0.582031f, 0.667969f, 0.332031f}, {0.984375f, 0.753906f, 0.835938f, 0.699219f},
+ {0.812500f, 0.242188f, 0.320312f, 0.636719f}, {0.511719f, 0.945312f, 0.625000f, 0.816406f},
+ {0.183594f, 0.796875f, 0.421875f, 0.027344f}, {0.742188f, 0.179688f, 0.882812f, 0.253906f},
+ {0.972656f, 0.375000f, 0.660156f, 0.613281f}, {0.378906f, 0.964844f, 0.480469f, 0.324219f},
+ {0.015625f, 0.222656f, 0.863281f, 0.046875f}, {0.871094f, 0.058594f, 0.695312f, 0.800781f},
+ {0.289062f, 0.792969f, 0.382812f, 0.644531f}, {0.765625f, 0.171875f, 0.636719f, 0.929688f},
+ {0.554688f, 0.988281f, 0.808594f, 0.531250f}, {0.023438f, 0.546875f, 0.218750f, 0.730469f},
+ {0.882812f, 0.886719f, 0.929688f, 0.191406f}, {0.605469f, 0.136719f, 0.167969f, 0.332031f},
+ {0.812500f, 0.335938f, 0.414062f, 0.519531f}, {0.652344f, 0.585938f, 0.953125f, 0.093750f},
+ {0.269531f, 0.488281f, 0.132812f, 0.312500f}, {0.019531f, 0.292969f, 0.472656f, 0.589844f},
+ {0.316406f, 0.410156f, 0.914062f, 0.195312f}, {0.613281f, 0.742188f, 0.175781f, 0.023438f},
+ {0.761719f, 0.207031f, 0.398438f, 0.660156f}, {0.363281f, 0.363281f, 0.664062f, 0.253906f},
+ {0.585938f, 0.449219f, 0.246094f, 0.746094f}, {0.796875f, 0.996094f, 0.902344f, 0.882812f},
+ {0.136719f, 0.835938f, 0.367188f, 0.230469f}, {0.492188f, 0.390625f, 0.492188f, 0.707031f},
+ {0.812500f, 0.562500f, 0.316406f, 0.515625f}, {0.636719f, 0.687500f, 0.421875f, 0.839844f},
+ {0.898438f, 0.343750f, 0.164062f, 0.664062f}, {0.179688f, 0.125000f, 0.695312f, 0.453125f},
+ {0.527344f, 0.746094f, 0.097656f, 0.816406f}, {0.625000f, 0.183594f, 0.207031f, 0.156250f},
+ {0.371094f, 0.906250f, 0.003906f, 0.421875f}, {0.160156f, 0.707031f, 0.781250f, 0.683594f},
+ {0.656250f, 0.773438f, 0.343750f, 0.894531f}, {0.875000f, 0.406250f, 0.945312f, 0.171875f},
+ {0.242188f, 0.859375f, 0.699219f, 0.394531f}, {0.703125f, 0.460938f, 0.375000f, 0.281250f},
+ {0.902344f, 0.371094f, 0.636719f, 0.937500f}, {0.207031f, 0.558594f, 0.476562f, 0.574219f},
+ {0.679688f, 0.980469f, 0.121094f, 0.203125f}, {0.476562f, 0.484375f, 0.402344f, 0.773438f},
+ {0.171875f, 0.332031f, 0.808594f, 0.699219f}, {0.718750f, 0.144531f, 0.906250f, 0.417969f},
+ {0.113281f, 0.527344f, 0.195312f, 0.351562f}, {0.617188f, 0.066406f, 0.507812f, 0.933594f},
+ {0.460938f, 0.277344f, 0.417969f, 0.734375f}, {0.160156f, 0.640625f, 0.613281f, 0.394531f},
+ {0.730469f, 0.738281f, 0.039062f, 0.105469f}, {0.078125f, 0.187500f, 0.777344f, 0.617188f},
+ {0.425781f, 0.824219f, 0.527344f, 0.171875f}, {0.679688f, 0.898438f, 0.128906f, 0.984375f},
+ {0.949219f, 0.769531f, 0.414062f, 0.230469f}, {0.128906f, 0.320312f, 0.886719f, 0.402344f},
+ {0.234375f, 0.648438f, 0.046875f, 0.160156f}, {0.394531f, 0.242188f, 0.964844f, 0.691406f},
+ {0.312500f, 0.800781f, 0.265625f, 0.769531f}, {0.875000f, 0.695312f, 0.785156f, 0.414062f},
+ {0.132812f, 0.562500f, 0.085938f, 0.046875f}, {0.238281f, 0.218750f, 0.574219f, 0.292969f},
+ {0.722656f, 0.640625f, 0.394531f, 0.136719f}, {0.304688f, 0.062500f, 0.222656f, 0.941406f},
+ {0.074219f, 0.972656f, 0.039062f, 0.078125f}, {0.351562f, 0.445312f, 0.152344f, 0.542969f},
+ {0.265625f, 0.148438f, 0.500000f, 0.417969f}, {0.054688f, 0.531250f, 0.246094f, 0.203125f},
+ {0.687500f, 0.621094f, 0.007812f, 0.937500f}, {0.113281f, 0.457031f, 0.535156f, 0.378906f},
+ {0.472656f, 0.105469f, 0.210938f, 0.144531f}, {0.218750f, 0.664062f, 0.113281f, 0.996094f},
+ {0.703125f, 0.843750f, 0.261719f, 0.218750f}, {0.925781f, 0.523438f, 0.550781f, 0.722656f},
+ {0.613281f, 0.730469f, 0.019531f, 0.289062f}, {0.367188f, 0.269531f, 0.886719f, 0.472656f},
+ {0.843750f, 0.074219f, 0.304688f, 0.238281f}, {0.703125f, 0.648438f, 0.054688f, 0.984375f},
+ {0.171875f, 0.425781f, 0.371094f, 0.078125f}, {0.335938f, 0.734375f, 0.566406f, 0.660156f},
+ {0.496094f, 0.949219f, 0.500000f, 0.906250f}, {0.214844f, 0.058594f, 0.312500f, 0.750000f},
+ {0.554688f, 0.203125f, 0.867188f, 0.964844f}, {0.839844f, 0.707031f, 0.238281f, 0.257812f},
+ {0.707031f, 0.113281f, 0.679688f, 0.828125f}, {0.890625f, 0.890625f, 0.296875f, 0.144531f},
+ {0.164062f, 0.042969f, 0.968750f, 0.972656f}, {0.273438f, 0.671875f, 0.796875f, 0.609375f},
+ {0.019531f, 0.156250f, 0.562500f, 0.078125f}, {0.910156f, 0.246094f, 0.183594f, 0.371094f},
+ {0.414062f, 0.707031f, 0.824219f, 0.437500f}, {0.085938f, 0.195312f, 0.082031f, 0.046875f},
+ {0.945312f, 0.781250f, 0.683594f, 0.308594f}, {0.218750f, 0.023438f, 0.621094f, 0.175781f},
+ {0.464844f, 0.234375f, 0.261719f, 0.964844f}, {0.105469f, 0.957031f, 0.582031f, 0.234375f},
+ {0.750000f, 0.488281f, 0.808594f, 0.738281f}, {0.253906f, 0.582031f, 0.457031f, 0.285156f},
+ {0.855469f, 0.367188f, 0.984375f, 0.859375f}, {0.425781f, 0.121094f, 0.250000f, 0.492188f},
+ {0.945312f, 0.550781f, 0.433594f, 0.222656f}, {0.738281f, 0.214844f, 0.503906f, 0.953125f},
+ {0.019531f, 0.046875f, 0.226562f, 0.515625f}, {0.324219f, 0.734375f, 0.574219f, 0.785156f},
+ {0.589844f, 0.257812f, 0.011719f, 0.015625f}, {0.843750f, 0.812500f, 0.988281f, 0.468750f},
+ {0.992188f, 0.007812f, 0.238281f, 0.312500f}, {0.082031f, 0.425781f, 0.699219f, 0.054688f},
+ {0.382812f, 0.843750f, 0.304688f, 0.972656f}, {0.890625f, 0.667969f, 0.558594f, 0.183594f},
+ {0.281250f, 0.968750f, 0.000000f, 0.003906f}, {0.687500f, 0.812500f, 0.742188f, 0.632812f},
+ {0.910156f, 0.121094f, 0.867188f, 0.207031f}, {0.347656f, 0.574219f, 0.957031f, 0.511719f},
+ {0.238281f, 0.421875f, 0.183594f, 0.957031f}, {0.960938f, 0.097656f, 0.707031f, 0.316406f},
+ {0.585938f, 0.667969f, 0.921875f, 0.445312f}, {0.835938f, 0.535156f, 0.238281f, 0.660156f},
+ {0.039062f, 0.031250f, 0.800781f, 0.074219f}, {0.464844f, 0.125000f, 0.734375f, 0.808594f},
+ {0.742188f, 0.390625f, 0.503906f, 0.367188f}, {0.828125f, 0.054688f, 0.113281f, 0.953125f},
+ {0.550781f, 0.996094f, 0.621094f, 0.472656f}, {0.625000f, 0.175781f, 0.203125f, 0.636719f},
+ {0.472656f, 0.347656f, 0.941406f, 0.871094f}, {0.046875f, 0.945312f, 0.050781f, 0.675781f},
+ {0.937500f, 0.414062f, 0.503906f, 0.492188f}, {0.500000f, 0.265625f, 0.632812f, 0.832031f},
+ {0.894531f, 0.683594f, 0.992188f, 0.753906f}, {0.148438f, 0.367188f, 0.437500f, 0.277344f},
+ {0.550781f, 0.890625f, 0.777344f, 0.050781f}, {0.945312f, 0.316406f, 0.710938f, 0.871094f},
+ {0.410156f, 0.046875f, 0.343750f, 0.484375f}, {0.597656f, 0.855469f, 0.949219f, 0.671875f},
+ {0.843750f, 0.261719f, 0.398438f, 0.781250f}, {0.781250f, 0.769531f, 0.597656f, 0.515625f},
+ {0.320312f, 0.140625f, 0.796875f, 0.578125f}, {0.425781f, 0.406250f, 0.988281f, 0.894531f},
+ {0.062500f, 0.593750f, 0.191406f, 0.160156f}, {0.246094f, 0.875000f, 0.515625f, 0.824219f},
+ {0.132812f, 0.484375f, 0.468750f, 0.031250f}, {0.437500f, 0.367188f, 0.605469f, 0.375000f},
+ {0.976562f, 0.835938f, 0.859375f, 0.785156f}, {0.046875f, 0.242188f, 0.726562f, 0.433594f},
+ {0.765625f, 0.519531f, 0.089844f, 0.226562f}, {0.921875f, 0.394531f, 0.824219f, 0.003906f},
+ {0.105469f, 0.921875f, 0.585938f, 0.382812f}, {0.390625f, 0.824219f, 0.007812f, 0.476562f},
+ {0.484375f, 0.558594f, 0.738281f, 0.683594f}, {0.070312f, 0.441406f, 0.082031f, 0.347656f},
+ {0.433594f, 0.332031f, 0.605469f, 0.417969f}, {0.949219f, 0.765625f, 0.339844f, 0.789062f},
+ {0.738281f, 0.906250f, 0.015625f, 0.183594f}, {0.312500f, 0.601562f, 0.441406f, 0.527344f},
+ {0.695312f, 0.089844f, 0.722656f, 0.992188f}, {0.605469f, 0.867188f, 0.925781f, 0.644531f},
+ {0.539062f, 0.500000f, 0.218750f, 0.769531f}, {0.011719f, 0.929688f, 0.847656f, 0.414062f},
+ {0.777344f, 0.296875f, 0.972656f, 0.613281f}, {0.332031f, 0.644531f, 0.398438f, 0.058594f},
+ {0.937500f, 0.835938f, 0.328125f, 0.378906f}, {0.691406f, 0.042969f, 0.867188f, 0.542969f},
+ {0.039062f, 0.257812f, 0.625000f, 0.011719f}, {0.546875f, 0.964844f, 0.562500f, 0.753906f},
+ {0.117188f, 0.632812f, 0.738281f, 0.320312f}, {0.605469f, 0.296875f, 0.054688f, 0.050781f},
+ {0.824219f, 0.902344f, 0.820312f, 0.621094f}, {0.507812f, 0.589844f, 0.906250f, 0.863281f},
+ {0.058594f, 0.136719f, 0.324219f, 0.152344f}, {0.445312f, 0.929688f, 0.753906f, 0.671875f},
+ {0.253906f, 0.703125f, 0.167969f, 0.828125f}, {0.644531f, 0.218750f, 0.593750f, 0.375000f},
+ {0.781250f, 0.574219f, 0.085938f, 0.609375f}, {0.000000f, 0.042969f, 0.964844f, 0.550781f},
+ {0.500000f, 0.296875f, 0.359375f, 0.871094f}, {0.207031f, 0.394531f, 0.683594f, 0.457031f},
+ {0.062500f, 0.214844f, 0.136719f, 0.277344f}, {0.777344f, 0.933594f, 0.480469f, 0.847656f},
+ {0.648438f, 0.863281f, 0.332031f, 0.765625f}, {0.121094f, 0.351562f, 0.089844f, 0.042969f},
+ {0.367188f, 0.250000f, 0.390625f, 0.554688f}, {0.183594f, 0.433594f, 0.566406f, 0.730469f},
+ {0.300781f, 0.593750f, 0.300781f, 0.500000f}, {0.894531f, 0.726562f, 0.636719f, 0.589844f},
+ {0.105469f, 0.839844f, 0.375000f, 0.296875f}, {0.199219f, 0.468750f, 0.710938f, 0.125000f},
+ {0.062500f, 0.289062f, 0.902344f, 0.027344f}, {0.992188f, 0.609375f, 0.410156f, 0.250000f},
+ {0.281250f, 0.101562f, 0.687500f, 0.343750f}, {0.789062f, 0.718750f, 0.343750f, 0.558594f},
+ {0.578125f, 0.832031f, 0.878906f, 0.214844f}, {0.187500f, 0.539062f, 0.746094f, 0.378906f},
+ {0.691406f, 0.187500f, 0.277344f, 0.457031f}, {0.621094f, 0.031250f, 0.105469f, 0.984375f},
+ {0.859375f, 0.812500f, 0.917969f, 0.597656f}, {0.757812f, 0.656250f, 0.558594f, 0.343750f},
+ {0.332031f, 0.402344f, 0.179688f, 0.726562f}, {0.027344f, 0.996094f, 0.812500f, 0.085938f},
+ {0.261719f, 0.554688f, 0.074219f, 0.851562f}, {0.144531f, 0.351562f, 0.742188f, 0.003906f},
+ {0.519531f, 0.925781f, 0.449219f, 0.406250f}, {0.585938f, 0.027344f, 0.324219f, 0.347656f},
+ {0.824219f, 0.320312f, 0.097656f, 0.109375f}, {0.953125f, 0.953125f, 0.707031f, 0.558594f},
+ {0.671875f, 0.121094f, 0.773438f, 0.695312f}, {0.523438f, 0.773438f, 0.128906f, 0.609375f},
+ {0.273438f, 0.003906f, 0.964844f, 0.496094f}, {0.621094f, 0.617188f, 0.265625f, 0.132812f},
+ {0.367188f, 0.167969f, 0.199219f, 0.847656f}, {0.722656f, 0.761719f, 0.652344f, 0.539062f},
+ {0.156250f, 0.652344f, 0.437500f, 0.621094f}, {0.996094f, 0.253906f, 0.359375f, 0.777344f},
+ {0.648438f, 0.148438f, 0.937500f, 0.109375f}, {0.242188f, 0.632812f, 0.496094f, 0.902344f},
+ {0.828125f, 0.957031f, 0.769531f, 0.562500f}, {0.558594f, 0.074219f, 0.136719f, 0.289062f},
+ {0.503906f, 0.531250f, 0.878906f, 0.703125f}, {0.175781f, 0.476562f, 0.636719f, 0.843750f},
+ {0.878906f, 0.277344f, 0.292969f, 0.132812f}, {0.367188f, 0.417969f, 0.125000f, 0.574219f},
+ {0.281250f, 0.062500f, 0.550781f, 0.910156f}, {0.847656f, 0.589844f, 0.054688f, 0.273438f},
+ {0.664062f, 0.730469f, 0.511719f, 0.121094f}, {0.394531f, 0.402344f, 0.140625f, 0.503906f},
+ {0.578125f, 0.089844f, 0.039062f, 0.914062f}, {0.480469f, 0.777344f, 0.714844f, 0.652344f},
+ {0.195312f, 0.445312f, 0.179688f, 0.976562f}, {0.785156f, 0.675781f, 0.113281f, 0.132812f},
+ {0.351562f, 0.816406f, 0.886719f, 0.835938f}, {0.265625f, 0.488281f, 0.296875f, 0.453125f},
+ {0.175781f, 0.093750f, 0.144531f, 0.722656f}, {0.386719f, 0.335938f, 0.656250f, 0.339844f},
+ {0.753906f, 0.656250f, 0.531250f, 0.234375f}, {0.132812f, 0.398438f, 0.421875f, 0.421875f},
+ {0.351562f, 0.515625f, 0.929688f, 0.925781f}, {0.917969f, 0.105469f, 0.500000f, 0.492188f},
+ {0.601562f, 0.914062f, 0.773438f, 0.136719f}, {0.324219f, 0.613281f, 0.441406f, 0.750000f},
+ {0.949219f, 0.730469f, 0.222656f, 0.324219f}, {0.578125f, 0.480469f, 0.824219f, 0.808594f},
+ {0.402344f, 0.660156f, 0.289062f, 0.062500f}, {0.863281f, 0.761719f, 0.585938f, 0.578125f},
+ {0.488281f, 0.515625f, 0.898438f, 0.132812f}, {0.550781f, 0.050781f, 0.644531f, 0.355469f},
+ {0.921875f, 0.968750f, 0.832031f, 0.882812f}, {0.710938f, 0.796875f, 0.011719f, 0.261719f},
+ {0.511719f, 0.160156f, 0.980469f, 0.019531f}, {0.605469f, 0.945312f, 0.199219f, 0.921875f},
+ {0.343750f, 0.214844f, 0.789062f, 0.218750f}, {0.675781f, 0.550781f, 0.019531f, 0.570312f},
+ {0.437500f, 0.746094f, 0.468750f, 0.734375f}, {0.707031f, 0.875000f, 0.542969f, 0.804688f},
+ {0.144531f, 0.503906f, 0.285156f, 0.910156f}, {0.406250f, 0.019531f, 0.121094f, 0.101562f},
+ {0.742188f, 0.312500f, 0.816406f, 0.714844f}, {0.097656f, 0.933594f, 0.183594f, 0.007812f},
+ {0.371094f, 0.761719f, 0.589844f, 0.648438f}, {0.453125f, 0.492188f, 0.378906f, 0.167969f},
+ {0.222656f, 0.585938f, 0.847656f, 0.796875f}, {0.121094f, 0.214844f, 0.058594f, 0.128906f},
+ {0.484375f, 0.730469f, 0.632812f, 0.546875f}, {0.914062f, 0.078125f, 0.871094f, 0.296875f},
+ {0.640625f, 0.191406f, 0.304688f, 0.441406f}, {0.886719f, 0.714844f, 0.148438f, 0.242188f},
+ {0.082031f, 0.464844f, 0.933594f, 0.750000f}, {0.742188f, 0.632812f, 0.640625f, 0.667969f},
+ {0.183594f, 0.230469f, 0.386719f, 0.953125f}, {0.484375f, 0.687500f, 0.917969f, 0.445312f},
+ {0.007812f, 0.187500f, 0.226562f, 0.308594f}, {0.804688f, 0.570312f, 0.417969f, 0.914062f},
+ {0.195312f, 0.304688f, 0.671875f, 0.253906f}, {0.878906f, 0.902344f, 0.351562f, 0.960938f},
+ {0.078125f, 0.082031f, 0.042969f, 0.710938f}, {0.460938f, 0.449219f, 0.988281f, 0.292969f},
+ {0.300781f, 0.320312f, 0.781250f, 0.058594f}, {0.593750f, 0.023438f, 0.171875f, 0.949219f},
+ {0.796875f, 0.500000f, 0.539062f, 0.207031f}, {0.339844f, 0.839844f, 0.218750f, 0.503906f},
+ {0.132812f, 0.289062f, 0.417969f, 0.070312f}, {0.675781f, 0.218750f, 0.269531f, 0.871094f},
+ {0.042969f, 0.378906f, 0.996094f, 0.035156f}, {0.230469f, 0.816406f, 0.515625f, 0.472656f},
+ {0.453125f, 0.964844f, 0.375000f, 0.332031f}, {0.746094f, 0.664062f, 0.792969f, 0.214844f},
+ {0.058594f, 0.351562f, 0.457031f, 0.000000f}, {0.968750f, 0.882812f, 0.343750f, 0.718750f},
+ {0.160156f, 0.140625f, 0.765625f, 0.878906f}, {0.238281f, 0.207031f, 0.675781f, 0.789062f},
+ {0.070312f, 0.535156f, 0.945312f, 0.335938f}, {0.894531f, 0.917969f, 0.277344f, 0.179688f},
+ {0.296875f, 0.332031f, 0.535156f, 0.597656f}, {0.988281f, 0.167969f, 0.359375f, 0.398438f},
+ {0.718750f, 0.015625f, 0.671875f, 0.257812f}, {0.472656f, 0.414062f, 0.960938f, 0.554688f},
+ {0.890625f, 0.996094f, 0.460938f, 0.109375f}, {0.964844f, 0.789062f, 0.199219f, 0.996094f},
+ {0.667969f, 0.875000f, 0.089844f, 0.585938f}, {0.804688f, 0.183594f, 0.859375f, 0.703125f},
+ {0.546875f, 0.312500f, 0.261719f, 0.089844f}, {0.050781f, 0.769531f, 0.046875f, 0.273438f},
+ {0.187500f, 0.253906f, 0.843750f, 0.894531f}, {0.441406f, 0.367188f, 0.644531f, 0.230469f},
+ {0.742188f, 0.171875f, 0.105469f, 0.097656f}, {0.824219f, 0.890625f, 0.535156f, 0.984375f},
+ {0.144531f, 0.015625f, 0.394531f, 0.656250f}, {0.296875f, 0.316406f, 0.058594f, 0.402344f},
+ {0.019531f, 0.144531f, 0.210938f, 0.691406f}, {0.753906f, 0.621094f, 0.730469f, 0.929688f},
+ {0.250000f, 0.703125f, 0.492188f, 0.191406f}, {0.054688f, 0.292969f, 0.152344f, 0.414062f},
+ {0.410156f, 0.492188f, 0.445312f, 0.777344f}, {0.796875f, 0.339844f, 0.871094f, 0.855469f},
+ {0.902344f, 0.085938f, 0.250000f, 0.632812f}, {0.531250f, 0.906250f, 0.324219f, 0.394531f},
+ {0.250000f, 0.132812f, 0.839844f, 0.976562f}, {0.917969f, 0.375000f, 0.160156f, 0.523438f},
+ {0.859375f, 0.792969f, 0.601562f, 0.160156f}, {0.335938f, 0.453125f, 0.714844f, 0.425781f},
+ {0.523438f, 0.152344f, 0.464844f, 0.949219f}, {0.957031f, 0.625000f, 0.000000f, 0.863281f},
+ {0.800781f, 0.089844f, 0.531250f, 0.257812f}, {0.000000f, 0.863281f, 0.316406f, 0.511719f},
+ {0.308594f, 0.285156f, 0.679688f, 0.906250f}, {0.824219f, 0.132812f, 0.472656f, 0.230469f},
+ {0.535156f, 0.917969f, 0.265625f, 0.656250f}, {0.683594f, 0.503906f, 0.429688f, 0.960938f},
+ {0.363281f, 0.609375f, 0.515625f, 0.171875f}, {0.445312f, 0.289062f, 0.683594f, 0.917969f},
+ {0.964844f, 0.808594f, 0.238281f, 0.617188f}, {0.277344f, 0.085938f, 0.042969f, 0.062500f},
+ {0.394531f, 0.511719f, 0.839844f, 0.203125f}, {0.636719f, 0.753906f, 0.585938f, 0.843750f},
+ {0.343750f, 0.417969f, 0.289062f, 0.761719f}, {0.746094f, 0.933594f, 0.011719f, 0.171875f},
+ {0.566406f, 0.472656f, 0.816406f, 0.066406f}, {0.398438f, 0.671875f, 0.550781f, 0.566406f},
+ {0.675781f, 0.855469f, 0.750000f, 0.351562f}, {0.832031f, 0.546875f, 0.488281f, 0.179688f},
+ {0.222656f, 0.992188f, 0.285156f, 0.449219f}, {0.531250f, 0.792969f, 0.117188f, 0.839844f},
+ {0.003906f, 0.382812f, 0.875000f, 0.320312f}, {0.718750f, 0.722656f, 0.625000f, 0.718750f},
+ {0.925781f, 0.574219f, 0.843750f, 0.636719f}, {0.382812f, 0.878906f, 0.070312f, 0.238281f},
+ {0.621094f, 0.015625f, 0.707031f, 0.398438f}, {0.988281f, 0.738281f, 0.195312f, 0.925781f},
+ {0.796875f, 0.125000f, 0.039062f, 0.667969f}, {0.136719f, 0.179688f, 0.953125f, 0.796875f},
+ {0.632812f, 0.542969f, 0.648438f, 0.382812f}, {0.496094f, 0.804688f, 0.253906f, 0.550781f},
+ {0.433594f, 0.449219f, 0.894531f, 0.457031f}, {0.730469f, 0.988281f, 0.203125f, 0.675781f},
+ {0.800781f, 0.273438f, 0.484375f, 0.222656f}, {0.136719f, 0.710938f, 0.414062f, 0.074219f},
+ {0.617188f, 0.597656f, 0.789062f, 0.472656f}, {0.417969f, 0.851562f, 0.843750f, 0.800781f},
+ {0.027344f, 0.242188f, 0.031250f, 0.695312f}, {0.566406f, 0.699219f, 0.398438f, 0.898438f},
+ {0.089844f, 0.195312f, 0.593750f, 0.187500f}, {0.617188f, 0.531250f, 0.792969f, 0.382812f},
+ {0.199219f, 0.445312f, 0.351562f, 0.769531f}, {0.289062f, 0.074219f, 0.675781f, 0.035156f},
+ {0.492188f, 0.632812f, 0.730469f, 0.535156f}, {0.699219f, 0.976562f, 0.382812f, 0.800781f},
+ {0.875000f, 0.464844f, 0.308594f, 0.640625f}, {0.121094f, 0.800781f, 0.171875f, 0.437500f},
+ {0.257812f, 0.078125f, 0.925781f, 0.714844f}, {0.523438f, 0.550781f, 0.718750f, 0.507812f},
+ {0.625000f, 0.992188f, 0.996094f, 0.171875f}, {0.968750f, 0.238281f, 0.781250f, 0.246094f},
+ {0.191406f, 0.453125f, 0.433594f, 0.468750f}, {0.441406f, 0.839844f, 0.269531f, 0.812500f},
+ {0.855469f, 0.203125f, 0.941406f, 0.621094f}, {0.652344f, 0.890625f, 0.347656f, 0.113281f},
+ {0.972656f, 0.007812f, 0.687500f, 0.480469f}, {0.156250f, 0.679688f, 0.585938f, 0.683594f},
+ {0.015625f, 0.617188f, 0.519531f, 0.078125f}, {0.761719f, 0.437500f, 0.945312f, 0.453125f},
+ {0.371094f, 0.261719f, 0.078125f, 0.320312f}, {0.585938f, 0.652344f, 0.757812f, 0.054688f},
+ {0.031250f, 0.207031f, 0.972656f, 0.609375f}, {0.644531f, 0.585938f, 0.375000f, 0.292969f},
+ {0.210938f, 0.894531f, 0.242188f, 0.769531f}, {0.269531f, 0.246094f, 0.902344f, 0.574219f},
+ {0.882812f, 0.390625f, 0.957031f, 0.355469f}, {0.570312f, 0.457031f, 0.769531f, 0.062500f},
+ {0.726562f, 0.953125f, 0.214844f, 0.406250f}, {0.988281f, 0.347656f, 0.136719f, 0.742188f},
+ {0.066406f, 0.785156f, 0.972656f, 0.035156f}, {0.156250f, 0.425781f, 0.726562f, 0.375000f},
+ {0.207031f, 0.015625f, 0.015625f, 0.589844f}, {0.710938f, 0.898438f, 0.894531f, 0.480469f},
+ {0.031250f, 0.160156f, 0.562500f, 0.792969f}, {0.546875f, 0.980469f, 0.480469f, 0.273438f},
+ {0.863281f, 0.859375f, 0.738281f, 0.535156f}, {0.101562f, 0.355469f, 0.171875f, 0.371094f},
+ {0.910156f, 0.054688f, 0.523438f, 0.011719f}, {0.296875f, 0.808594f, 0.894531f, 0.640625f},
+ {0.937500f, 0.257812f, 0.457031f, 0.414062f}, {0.125000f, 0.113281f, 0.152344f, 0.804688f},
+ {0.507812f, 0.363281f, 0.617188f, 0.882812f}, {0.957031f, 0.195312f, 0.394531f, 0.656250f},
+ {0.054688f, 0.695312f, 0.906250f, 0.750000f}, {0.902344f, 0.070312f, 0.703125f, 0.582031f},
+ {0.421875f, 0.929688f, 0.031250f, 0.140625f}, {0.187500f, 0.167969f, 0.671875f, 0.433594f},
+ {0.476562f, 0.101562f, 0.363281f, 0.980469f}, {0.281250f, 0.683594f, 0.570312f, 0.765625f},
+ {0.847656f, 0.437500f, 0.472656f, 0.167969f}, {0.078125f, 0.628906f, 0.832031f, 0.605469f},
+ {0.570312f, 0.328125f, 0.593750f, 0.101562f}, {0.261719f, 0.765625f, 0.738281f, 0.503906f},
+ {0.906250f, 0.242188f, 0.164062f, 0.960938f}, {0.324219f, 0.007812f, 0.824219f, 0.164062f},
+ {0.593750f, 0.683594f, 0.570312f, 0.089844f}, {0.921875f, 0.617188f, 0.105469f, 0.296875f},
+ {0.527344f, 0.050781f, 0.632812f, 0.851562f}, {0.359375f, 0.375000f, 0.910156f, 0.726562f},
+ {0.835938f, 0.128906f, 0.070312f, 0.937500f}, {0.664062f, 0.515625f, 0.226562f, 0.027344f},
+ {0.226562f, 0.890625f, 0.500000f, 0.300781f}, {0.851562f, 0.574219f, 0.757812f, 0.648438f},
+ {0.316406f, 0.753906f, 0.257812f, 0.058594f}, {0.429688f, 0.277344f, 0.937500f, 0.507812f},
+ {0.007812f, 0.031250f, 0.019531f, 0.878906f}, {0.933594f, 0.714844f, 0.550781f, 0.308594f},
+ {0.835938f, 0.847656f, 0.136719f, 0.164062f}, {0.234375f, 0.546875f, 0.617188f, 0.968750f},
+ {0.394531f, 0.132812f, 0.902344f, 0.355469f}, {0.980469f, 0.679688f, 0.566406f, 0.019531f},
+ {0.671875f, 0.839844f, 0.468750f, 0.585938f}, {0.046875f, 0.417969f, 0.250000f, 0.378906f},
+ {0.375000f, 0.597656f, 0.023438f, 0.898438f}, {0.695312f, 0.789062f, 0.625000f, 0.753906f},
+ {0.898438f, 0.375000f, 0.875000f, 0.007812f}, {0.328125f, 0.542969f, 0.113281f, 0.531250f},
+ {0.578125f, 0.109375f, 0.542969f, 0.300781f}, {0.085938f, 0.406250f, 0.765625f, 0.988281f},
+ {0.285156f, 0.566406f, 0.062500f, 0.339844f}, {0.472656f, 0.777344f, 0.128906f, 0.164062f},
+ {0.636719f, 0.363281f, 0.628906f, 0.750000f}, {0.832031f, 0.035156f, 0.394531f, 0.835938f},
+ {0.109375f, 0.972656f, 0.667969f, 0.195312f}, {0.183594f, 0.710938f, 0.222656f, 0.890625f},
+ {0.808594f, 0.066406f, 0.046875f, 0.707031f}, {0.460938f, 0.953125f, 0.855469f, 0.476562f},
+ {0.082031f, 0.335938f, 0.652344f, 0.203125f}, {0.667969f, 0.738281f, 0.093750f, 0.121094f},
+ {0.425781f, 0.664062f, 0.417969f, 0.683594f}, {0.164062f, 0.007812f, 0.613281f, 0.964844f},
+ {0.632812f, 0.703125f, 0.042969f, 0.617188f}, {0.250000f, 0.554688f, 0.804688f, 0.464844f},
+ {0.394531f, 0.242188f, 0.371094f, 0.878906f}, {0.937500f, 0.847656f, 0.601562f, 0.816406f},
+ {0.804688f, 0.679688f, 0.195312f, 0.113281f}, {0.601562f, 0.378906f, 0.335938f, 0.320312f},
+ {0.339844f, 0.562500f, 0.812500f, 0.867188f}, {0.785156f, 0.437500f, 0.125000f, 0.140625f},
+ {0.230469f, 0.273438f, 0.355469f, 0.980469f}, {0.687500f, 0.656250f, 0.957031f, 0.468750f},
+ {0.156250f, 0.148438f, 0.082031f, 0.726562f}, {0.464844f, 0.535156f, 0.703125f, 0.898438f},
+ {0.039062f, 0.722656f, 0.324219f, 0.285156f}, {0.250000f, 0.945312f, 0.945312f, 0.117188f},
+ {0.777344f, 0.589844f, 0.093750f, 0.484375f}, {0.328125f, 0.285156f, 0.222656f, 0.023438f},
+ {0.609375f, 0.421875f, 0.828125f, 0.390625f}, {0.746094f, 0.617188f, 0.335938f, 0.929688f},
+ {0.261719f, 0.238281f, 0.449219f, 0.265625f}, {0.863281f, 0.472656f, 0.953125f, 0.031250f},
+ {0.105469f, 0.316406f, 0.292969f, 0.355469f}, {0.765625f, 0.976562f, 0.152344f, 0.531250f},
+ {0.523438f, 0.195312f, 0.933594f, 0.828125f}, {0.343750f, 0.554688f, 0.242188f, 0.304688f},
+ {0.414062f, 0.890625f, 0.414062f, 0.742188f}, {0.695312f, 0.496094f, 0.085938f, 0.250000f},
+ {0.824219f, 0.933594f, 0.316406f, 0.832031f}, {0.109375f, 0.386719f, 0.433594f, 0.347656f},
+ {0.199219f, 0.304688f, 0.000000f, 0.632812f}, {0.023438f, 0.843750f, 0.378906f, 0.988281f},
+ {0.679688f, 0.480469f, 0.746094f, 0.429688f}, {0.265625f, 0.769531f, 0.312500f, 0.574219f},
+ {0.058594f, 0.941406f, 0.593750f, 0.359375f}, {0.507812f, 0.074219f, 0.992188f, 0.527344f},
+ {0.160156f, 0.308594f, 0.167969f, 0.214844f}, {0.945312f, 0.382812f, 0.644531f, 0.964844f},
+ {0.789062f, 0.105469f, 0.117188f, 0.441406f}, {0.523438f, 0.613281f, 0.875000f, 0.812500f},
+ {0.722656f, 0.953125f, 0.492188f, 0.226562f}, {0.371094f, 0.347656f, 0.226562f, 0.617188f},
+ {0.101562f, 0.214844f, 0.984375f, 0.464844f}, {0.628906f, 0.406250f, 0.433594f, 0.742188f},
+ {0.777344f, 0.011719f, 0.035156f, 0.199219f}, {0.480469f, 0.277344f, 0.753906f, 0.855469f},
+ {0.339844f, 0.332031f, 0.347656f, 0.281250f}, {0.093750f, 0.207031f, 0.671875f, 0.792969f},
+ {0.808594f, 0.699219f, 0.156250f, 0.121094f}, {0.226562f, 0.097656f, 0.507812f, 0.335938f},
+ {0.476562f, 0.941406f, 0.367188f, 0.945312f}, {0.109375f, 0.660156f, 0.187500f, 0.210938f},
+ {0.800781f, 0.750000f, 0.609375f, 0.066406f}, {0.382812f, 0.984375f, 0.824219f, 0.714844f},
+ {0.738281f, 0.242188f, 0.296875f, 0.554688f}, {0.222656f, 0.832031f, 0.917969f, 0.906250f},
+ {0.320312f, 0.929688f, 0.464844f, 0.503906f}, {0.980469f, 0.519531f, 0.175781f, 0.277344f},
+ {0.500000f, 0.312500f, 0.808594f, 0.664062f}, {0.285156f, 0.816406f, 0.562500f, 0.789062f},
+ {0.929688f, 0.542969f, 0.437500f, 0.382812f}, {0.542969f, 0.414062f, 0.507812f, 0.023438f},
+ {0.777344f, 0.847656f, 0.308594f, 0.843750f}, {0.976562f, 0.121094f, 0.738281f, 0.527344f},
+ {0.042969f, 0.511719f, 0.164062f, 0.316406f}, {0.507812f, 0.812500f, 0.492188f, 0.824219f},
+ {0.339844f, 0.183594f, 0.875000f, 0.089844f}, {0.773438f, 0.074219f, 0.546875f, 0.281250f},
+ {0.460938f, 0.640625f, 0.929688f, 0.195312f}, {0.558594f, 0.121094f, 0.105469f, 0.695312f},
+ {0.285156f, 0.316406f, 0.781250f, 0.523438f}, {0.875000f, 0.769531f, 0.414062f, 0.019531f},
+ {0.121094f, 0.222656f, 0.984375f, 0.710938f}, {0.488281f, 0.710938f, 0.269531f, 0.398438f},
+ {0.992188f, 0.031250f, 0.625000f, 0.656250f}, {0.421875f, 0.597656f, 0.437500f, 0.101562f},
+ {0.593750f, 0.890625f, 0.777344f, 0.226562f}, {0.839844f, 0.214844f, 0.601562f, 0.589844f},
+ {0.718750f, 0.402344f, 0.253906f, 0.523438f}, {0.644531f, 0.019531f, 0.855469f, 0.687500f},
+ {0.433594f, 0.820312f, 0.667969f, 0.992188f}, {0.167969f, 0.746094f, 0.050781f, 0.238281f},
+ {0.109375f, 0.128906f, 0.582031f, 0.105469f}, {0.363281f, 0.847656f, 0.527344f, 0.527344f},
+ {0.687500f, 0.531250f, 0.191406f, 0.804688f}, {0.562500f, 0.777344f, 0.101562f, 0.683594f},
+ {0.636719f, 0.597656f, 0.796875f, 0.890625f}, {0.953125f, 0.402344f, 0.726562f, 0.113281f},
+ {0.164062f, 0.832031f, 0.011719f, 0.453125f}, {0.734375f, 0.265625f, 0.343750f, 0.019531f},
+ {0.210938f, 0.046875f, 0.675781f, 0.941406f}, {0.003906f, 0.089844f, 0.910156f, 0.421875f},
+ {0.535156f, 0.703125f, 0.523438f, 0.058594f}, {0.382812f, 0.578125f, 0.980469f, 0.582031f},
+ {0.984375f, 0.113281f, 0.699219f, 0.761719f}, {0.304688f, 0.906250f, 0.851562f, 0.023438f},
+ {0.859375f, 0.167969f, 0.250000f, 0.261719f}, {0.453125f, 0.230469f, 0.144531f, 0.113281f},
+ {0.960938f, 0.429688f, 0.453125f, 0.828125f}, {0.757812f, 0.628906f, 0.695312f, 0.156250f},
+ {0.375000f, 0.792969f, 0.343750f, 0.757812f}, {0.691406f, 0.476562f, 0.558594f, 0.593750f},
+ {0.250000f, 0.906250f, 0.300781f, 0.332031f}, {0.140625f, 0.152344f, 0.707031f, 0.136719f},
+ {0.871094f, 0.824219f, 0.394531f, 0.667969f}, {0.582031f, 0.496094f, 0.828125f, 0.941406f},
+ {0.453125f, 0.589844f, 0.769531f, 0.394531f}, {0.167969f, 0.910156f, 0.285156f, 0.058594f},
+ {0.027344f, 0.750000f, 0.195312f, 0.675781f}, {0.570312f, 0.949219f, 0.867188f, 0.515625f},
+ {0.843750f, 0.519531f, 0.078125f, 0.933594f}, {0.937500f, 0.878906f, 0.835938f, 0.070312f},
+ {0.539062f, 0.039062f, 0.292969f, 0.625000f}, {0.761719f, 0.492188f, 0.796875f, 0.558594f},
+ {0.597656f, 0.285156f, 0.703125f, 0.828125f}, {0.160156f, 0.171875f, 0.957031f, 0.656250f},
+ {0.671875f, 0.058594f, 0.035156f, 0.433594f}, {0.503906f, 0.324219f, 0.417969f, 0.863281f},
+ {0.925781f, 0.453125f, 0.230469f, 0.250000f}, {0.566406f, 0.136719f, 0.742188f, 0.031250f},
+ {0.066406f, 0.195312f, 0.097656f, 0.968750f}, {0.417969f, 0.753906f, 0.988281f, 0.097656f},
+ {0.675781f, 0.113281f, 0.273438f, 0.546875f}, {0.726562f, 0.468750f, 0.339844f, 0.136719f},
+ {0.394531f, 0.171875f, 0.914062f, 0.253906f}, {0.144531f, 0.277344f, 0.128906f, 0.996094f},
+ {0.316406f, 0.039062f, 0.578125f, 0.644531f}, {0.714844f, 0.574219f, 0.820312f, 0.910156f},
+ {0.378906f, 0.222656f, 0.269531f, 0.437500f}, {0.906250f, 0.984375f, 0.707031f, 0.175781f},
+ {0.113281f, 0.371094f, 0.339844f, 0.765625f}, {0.851562f, 0.882812f, 0.242188f, 0.570312f},
+ {0.015625f, 0.472656f, 0.453125f, 0.343750f}, {0.664062f, 0.972656f, 0.292969f, 0.984375f},
+ {0.097656f, 0.523438f, 0.660156f, 0.421875f}, {0.429688f, 0.058594f, 0.527344f, 0.234375f},
+ {0.187500f, 0.933594f, 0.070312f, 0.925781f}, {0.628906f, 0.132812f, 0.679688f, 0.558594f},
+ {0.753906f, 0.796875f, 0.203125f, 0.773438f}, {0.070312f, 0.484375f, 0.847656f, 0.328125f},
+ {0.355469f, 0.964844f, 0.035156f, 0.855469f}, {0.527344f, 0.335938f, 0.390625f, 0.933594f},
+ {0.210938f, 0.625000f, 0.191406f, 0.367188f}, {0.976562f, 0.460938f, 0.507812f, 0.191406f},
+ {0.582031f, 0.171875f, 0.425781f, 0.765625f}, {0.882812f, 0.507812f, 0.761719f, 0.332031f},
+ {0.812500f, 0.914062f, 0.265625f, 0.636719f}, {0.496094f, 0.050781f, 0.976562f, 0.875000f},
+ {0.980469f, 0.355469f, 0.738281f, 0.187500f}, {0.031250f, 0.898438f, 0.605469f, 0.476562f},
+ {0.320312f, 0.027344f, 0.410156f, 0.597656f}, {0.441406f, 0.734375f, 0.507812f, 0.218750f},
+ {0.066406f, 0.140625f, 0.894531f, 0.714844f}, {0.894531f, 0.468750f, 0.550781f, 0.562500f},
+ {0.652344f, 0.789062f, 0.785156f, 0.648438f}, {0.863281f, 0.972656f, 0.132812f, 0.191406f},
+ {0.457031f, 0.425781f, 0.277344f, 0.894531f}, {0.738281f, 0.203125f, 0.605469f, 0.683594f},
+ {0.640625f, 0.808594f, 0.480469f, 0.472656f}, {0.777344f, 0.515625f, 0.183594f, 0.199219f},
+ {0.125000f, 0.339844f, 0.953125f, 0.921875f}, {0.570312f, 0.671875f, 0.539062f, 0.500000f},
+ {0.210938f, 0.730469f, 0.781250f, 0.671875f}, {0.097656f, 0.019531f, 0.019531f, 0.890625f},
+ {0.597656f, 0.968750f, 0.835938f, 0.406250f}, {0.468750f, 0.191406f, 0.914062f, 0.082031f},
+ {0.042969f, 0.667969f, 0.445312f, 0.847656f}, {0.648438f, 0.421875f, 0.050781f, 0.722656f},
+ {0.335938f, 0.773438f, 0.179688f, 0.000000f}, {0.992188f, 0.300781f, 0.636719f, 0.257812f},
+ {0.273438f, 0.066406f, 0.093750f, 0.562500f}, {0.750000f, 0.171875f, 0.476562f, 0.902344f},
+ {0.902344f, 0.660156f, 0.691406f, 0.320312f}, {0.300781f, 0.445312f, 0.527344f, 0.144531f},
+ {0.195312f, 0.621094f, 0.406250f, 0.457031f}, {0.429688f, 0.152344f, 0.968750f, 0.707031f},
+ {0.273438f, 0.734375f, 0.453125f, 0.414062f}, {0.003906f, 0.914062f, 0.578125f, 0.265625f},
+ {0.410156f, 0.355469f, 0.093750f, 0.484375f}, {0.996094f, 0.847656f, 0.316406f, 0.148438f},
+ {0.839844f, 0.605469f, 0.484375f, 0.359375f}, {0.031250f, 0.511719f, 0.898438f, 0.773438f},
+ {0.187500f, 0.726562f, 0.679688f, 0.589844f}, {0.867188f, 0.644531f, 0.355469f, 0.390625f},
+ {0.136719f, 0.878906f, 0.843750f, 0.640625f}, {0.597656f, 0.589844f, 0.597656f, 0.441406f},
+ {0.222656f, 0.394531f, 0.714844f, 0.355469f}, {0.003906f, 0.863281f, 0.031250f, 0.925781f},
+ {0.871094f, 0.691406f, 0.761719f, 0.597656f}, {0.621094f, 0.628906f, 0.195312f, 0.414062f},
+ {0.230469f, 0.769531f, 0.941406f, 0.074219f}, {0.582031f, 0.929688f, 0.023438f, 0.230469f},
+ {0.812500f, 0.433594f, 0.398438f, 0.722656f}, {0.195312f, 0.304688f, 0.996094f, 0.000000f},
+ {0.679688f, 0.761719f, 0.089844f, 0.496094f}, {0.593750f, 0.605469f, 0.636719f, 0.925781f},
+ {0.222656f, 0.277344f, 0.750000f, 0.136719f}, {0.902344f, 0.730469f, 0.164062f, 0.644531f},
+ {0.515625f, 0.191406f, 0.863281f, 0.785156f}, {0.722656f, 0.585938f, 0.031250f, 0.601562f},
+ {0.949219f, 0.457031f, 0.921875f, 0.183594f}, {0.312500f, 0.851562f, 0.468750f, 0.066406f},
+ {0.003906f, 0.390625f, 0.750000f, 0.257812f}, {0.265625f, 0.304688f, 0.308594f, 0.496094f},
+ {0.808594f, 0.097656f, 0.542969f, 0.035156f}, {0.894531f, 0.761719f, 0.136719f, 0.152344f},
+ {0.089844f, 0.691406f, 0.992188f, 0.445312f}, {0.382812f, 0.070312f, 0.792969f, 0.070312f},
+ {0.011719f, 0.984375f, 0.355469f, 0.843750f}, {0.281250f, 0.308594f, 0.910156f, 0.593750f},
+ {0.660156f, 0.648438f, 0.152344f, 0.429688f}, {0.210938f, 0.210938f, 0.468750f, 0.722656f},
+ {0.406250f, 0.703125f, 0.019531f, 0.304688f}, {0.148438f, 0.273438f, 0.882812f, 0.078125f},
+ {0.832031f, 0.089844f, 0.250000f, 0.968750f}, {0.242188f, 0.863281f, 0.652344f, 0.335938f},
+ {0.601562f, 0.371094f, 0.199219f, 0.847656f}, {0.484375f, 0.679688f, 0.062500f, 0.277344f},
+ {0.289062f, 0.617188f, 0.453125f, 0.378906f}, {0.941406f, 0.343750f, 0.863281f, 0.515625f},
+ {0.152344f, 0.281250f, 0.218750f, 0.128906f}, {0.238281f, 0.746094f, 0.039062f, 0.316406f},
+ {0.046875f, 0.636719f, 0.792969f, 0.871094f}, {0.496094f, 0.031250f, 0.351562f, 0.390625f},
+ {0.406250f, 0.980469f, 0.660156f, 0.789062f}, {0.707031f, 0.558594f, 0.054688f, 0.609375f},
+ {0.886719f, 0.859375f, 0.890625f, 0.320312f}, {0.312500f, 0.132812f, 0.394531f, 0.039062f},
+ {0.816406f, 0.265625f, 0.250000f, 0.242188f}, {0.906250f, 0.355469f, 0.097656f, 0.488281f},
+ {0.410156f, 0.539062f, 0.746094f, 0.921875f}, {0.769531f, 0.093750f, 0.972656f, 0.539062f},
+ {0.203125f, 0.246094f, 0.527344f, 0.425781f}, {0.070312f, 0.695312f, 0.324219f, 0.800781f},
+ {0.820312f, 0.878906f, 0.906250f, 0.117188f}, {0.515625f, 0.375000f, 0.574219f, 0.761719f},
+ {0.660156f, 0.238281f, 0.941406f, 0.605469f}, {0.113281f, 0.105469f, 0.132812f, 0.835938f},
+ {0.710938f, 0.820312f, 0.652344f, 0.238281f}, {0.621094f, 0.394531f, 0.214844f, 0.992188f},
+ {0.136719f, 0.253906f, 0.011719f, 0.187500f}, {0.921875f, 0.578125f, 0.902344f, 0.046875f},
+ {0.730469f, 0.441406f, 0.246094f, 0.886719f}, {0.300781f, 0.800781f, 0.847656f, 0.957031f},
+ {0.238281f, 0.222656f, 0.648438f, 0.687500f}, {0.355469f, 0.894531f, 0.136719f, 0.109375f},
+ {0.707031f, 0.027344f, 0.554688f, 0.199219f}, {0.453125f, 0.285156f, 0.003906f, 0.800781f},
+ {0.953125f, 0.074219f, 0.511719f, 0.156250f}, {0.750000f, 0.671875f, 0.152344f, 0.863281f},
+ {0.824219f, 0.238281f, 0.402344f, 0.699219f}, {0.339844f, 0.003906f, 0.492188f, 0.042969f},
+ {0.964844f, 0.980469f, 0.867188f, 0.753906f}, {0.101562f, 0.367188f, 0.617188f, 0.511719f},
+ {0.492188f, 0.488281f, 0.363281f, 0.300781f}, {0.062500f, 0.156250f, 0.667969f, 0.800781f},
+ {0.277344f, 0.652344f, 0.550781f, 0.355469f}, {0.441406f, 0.062500f, 0.847656f, 0.601562f},
+ {0.953125f, 0.535156f, 0.199219f, 0.847656f}, {0.316406f, 0.140625f, 0.011719f, 0.250000f},
+ {0.757812f, 0.019531f, 0.910156f, 0.390625f}, {0.359375f, 0.390625f, 0.570312f, 0.042969f},
+ {0.054688f, 0.902344f, 0.386719f, 0.863281f}, {0.824219f, 0.339844f, 0.714844f, 0.304688f},
+ {0.390625f, 0.632812f, 0.242188f, 0.457031f}, {0.562500f, 0.238281f, 0.589844f, 0.734375f},
+ {0.921875f, 0.683594f, 0.097656f, 0.953125f}, {0.507812f, 0.550781f, 0.949219f, 0.816406f},
+ {0.671875f, 0.191406f, 0.878906f, 0.617188f}, {0.175781f, 0.835938f, 0.644531f, 0.703125f},
+ {0.316406f, 0.273438f, 0.718750f, 0.789062f}, {0.757812f, 0.871094f, 0.000000f, 0.550781f},
+ {0.546875f, 0.566406f, 0.113281f, 0.265625f}, {0.472656f, 0.382812f, 0.621094f, 0.941406f},
+ {0.925781f, 0.796875f, 0.699219f, 0.156250f}, {0.058594f, 0.437500f, 0.386719f, 0.050781f},
+ {0.777344f, 0.945312f, 0.308594f, 0.781250f}, {0.535156f, 0.496094f, 0.820312f, 0.394531f},
+ {0.906250f, 0.644531f, 0.125000f, 0.656250f}, {0.703125f, 0.542969f, 0.371094f, 0.144531f},
+ {0.804688f, 0.226562f, 0.988281f, 0.914062f}, {0.378906f, 0.906250f, 0.300781f, 0.046875f},
+ {0.035156f, 0.175781f, 0.753906f, 0.785156f}, {0.570312f, 0.566406f, 0.628906f, 0.976562f},
+ {0.343750f, 0.125000f, 0.390625f, 0.730469f}, {0.804688f, 0.878906f, 0.722656f, 0.238281f},
+ {0.605469f, 0.453125f, 0.921875f, 0.539062f}, {0.953125f, 0.257812f, 0.089844f, 0.093750f},
+ {0.179688f, 0.085938f, 0.429688f, 0.714844f}, {0.347656f, 0.402344f, 0.281250f, 0.167969f},
+ {0.628906f, 0.300781f, 0.613281f, 0.449219f}, {0.007812f, 0.503906f, 0.507812f, 0.984375f},
+ {0.539062f, 0.601562f, 0.187500f, 0.710938f}, {0.281250f, 0.835938f, 0.660156f, 0.632812f},
+ {0.113281f, 0.738281f, 0.363281f, 0.285156f}, {0.953125f, 0.933594f, 0.593750f, 0.191406f},
+ {0.554688f, 0.007812f, 0.238281f, 0.355469f}, {0.683594f, 0.625000f, 0.800781f, 0.980469f},
+ {0.417969f, 0.472656f, 0.000000f, 0.500000f}, {0.222656f, 0.984375f, 0.371094f, 0.218750f},
+ {0.382812f, 0.777344f, 0.253906f, 0.070312f}, {0.972656f, 0.566406f, 0.808594f, 0.378906f},
+ {0.472656f, 0.308594f, 0.316406f, 0.542969f}, {0.789062f, 0.058594f, 0.609375f, 0.781250f},
+ {0.855469f, 0.972656f, 0.726562f, 0.648438f}, {0.359375f, 0.652344f, 0.519531f, 0.746094f},
+ {0.511719f, 0.000000f, 0.425781f, 0.582031f}, {0.074219f, 0.125000f, 0.750000f, 0.296875f},
+ {0.625000f, 0.683594f, 0.382812f, 0.027344f}, {0.546875f, 0.960938f, 0.199219f, 0.523438f},
+ {0.792969f, 0.414062f, 0.964844f, 0.917969f}, {0.269531f, 0.488281f, 0.773438f, 0.308594f},
+ {0.375000f, 0.332031f, 0.312500f, 0.007812f}, {0.519531f, 0.941406f, 0.894531f, 0.570312f},
+ {0.175781f, 0.777344f, 0.226562f, 0.210938f}, {0.558594f, 0.558594f, 0.687500f, 0.324219f},
+ {0.449219f, 0.316406f, 0.078125f, 0.828125f}, {0.656250f, 0.101562f, 0.449219f, 0.164062f},
+ {0.839844f, 0.832031f, 0.250000f, 0.683594f}, {0.914062f, 0.253906f, 0.777344f, 0.554688f},
+ {0.738281f, 0.906250f, 0.144531f, 0.125000f}, {0.550781f, 0.714844f, 0.472656f, 0.945312f},
+ {0.039062f, 0.863281f, 0.695312f, 0.660156f}, {0.140625f, 0.445312f, 0.421875f, 0.453125f},
+ {0.476562f, 0.832031f, 0.796875f, 0.738281f}, {0.980469f, 0.679688f, 0.496094f, 0.101562f},
+ {0.269531f, 0.792969f, 0.121094f, 0.500000f}, {0.160156f, 0.101562f, 0.324219f, 0.152344f},
+ {0.656250f, 0.960938f, 0.820312f, 0.894531f}, {0.226562f, 0.000000f, 0.406250f, 0.640625f},
+ {0.851562f, 0.742188f, 0.156250f, 0.343750f}, {0.136719f, 0.917969f, 0.359375f, 0.425781f},
+ {0.414062f, 0.054688f, 0.492188f, 0.210938f}, {0.613281f, 0.441406f, 0.257812f, 0.300781f},
+ {0.941406f, 0.511719f, 0.449219f, 0.972656f}, {0.699219f, 0.128906f, 0.570312f, 0.652344f},
+ {0.847656f, 0.226562f, 0.281250f, 0.003906f}, {0.128906f, 0.734375f, 0.871094f, 0.375000f},
+ {0.339844f, 0.007812f, 0.535156f, 0.507812f}, {0.726562f, 0.117188f, 0.074219f, 0.894531f},
+ {0.257812f, 0.582031f, 0.933594f, 0.570312f}, {0.593750f, 0.171875f, 0.566406f, 0.250000f},
+ {0.351562f, 0.410156f, 0.484375f, 0.488281f}, {0.117188f, 0.996094f, 0.703125f, 0.761719f},
+ {0.191406f, 0.308594f, 0.843750f, 0.425781f}, {0.992188f, 0.003906f, 0.578125f, 0.609375f},
+ {0.769531f, 0.503906f, 0.164062f, 0.097656f}, {0.105469f, 0.816406f, 0.945312f, 0.460938f},
+ {0.699219f, 0.046875f, 0.109375f, 0.824219f}, {0.421875f, 0.957031f, 0.535156f, 0.007812f},
+ {0.898438f, 0.359375f, 0.312500f, 0.636719f}, {0.281250f, 0.718750f, 0.582031f, 0.964844f},
+ {0.082031f, 0.605469f, 0.863281f, 0.285156f}, {0.847656f, 0.800781f, 0.757812f, 0.070312f},
+ {0.445312f, 0.203125f, 0.125000f, 0.820312f}, {0.980469f, 0.902344f, 0.714844f, 0.562500f},
+ {0.164062f, 0.691406f, 0.921875f, 0.359375f}, {0.734375f, 0.046875f, 0.812500f, 0.144531f},
+ {0.613281f, 0.457031f, 0.480469f, 0.777344f}, {0.359375f, 0.320312f, 0.140625f, 0.089844f},
+ {0.488281f, 0.574219f, 0.886719f, 0.863281f}, {0.152344f, 0.855469f, 0.703125f, 0.636719f},
+ {0.921875f, 0.136719f, 0.421875f, 0.296875f}, {0.011719f, 0.527344f, 0.167969f, 0.710938f},
+ {0.601562f, 0.027344f, 0.742188f, 0.441406f}, {0.328125f, 0.707031f, 0.066406f, 0.882812f},
+ {0.050781f, 0.906250f, 0.875000f, 0.015625f}, {0.246094f, 0.500000f, 0.378906f, 0.339844f},
+ {0.566406f, 0.769531f, 0.117188f, 0.121094f}, {0.179688f, 0.195312f, 0.175781f, 0.386719f},
+ {0.656250f, 0.527344f, 0.988281f, 0.816406f}, {0.882812f, 0.304688f, 0.042969f, 0.449219f},
+ {0.425781f, 0.375000f, 0.601562f, 0.242188f}, {0.929688f, 0.562500f, 0.812500f, 0.617188f},
+ {0.101562f, 0.164062f, 0.261719f, 0.468750f}, {0.644531f, 0.820312f, 0.441406f, 0.718750f},
+ {0.023438f, 0.523438f, 0.632812f, 0.261719f}, {0.898438f, 0.437500f, 0.945312f, 0.953125f},
+ {0.066406f, 0.140625f, 0.109375f, 0.492188f}, {0.281250f, 0.882812f, 0.832031f, 0.902344f},
+ {0.781250f, 0.207031f, 0.292969f, 0.445312f}, {0.148438f, 0.722656f, 0.976562f, 0.089844f},
+ {0.402344f, 0.593750f, 0.523438f, 0.960938f}, {0.351562f, 0.046875f, 0.066406f, 0.871094f},
+ {0.175781f, 0.402344f, 0.316406f, 0.402344f}, {0.640625f, 0.339844f, 0.937500f, 0.046875f},
+ {0.871094f, 0.199219f, 0.589844f, 0.203125f}, {0.414062f, 0.945312f, 0.355469f, 0.316406f},
+ {0.691406f, 0.246094f, 0.277344f, 0.902344f}, {0.539062f, 0.507812f, 0.980469f, 0.566406f},
+ {0.609375f, 0.167969f, 0.214844f, 0.679688f}, {0.781250f, 0.429688f, 0.617188f, 0.820312f},
+ {0.464844f, 0.285156f, 0.875000f, 0.375000f}, {0.101562f, 0.488281f, 0.511719f, 0.019531f},
+ {0.710938f, 0.156250f, 0.691406f, 0.121094f}, {0.363281f, 0.359375f, 0.792969f, 0.578125f},
+ {0.792969f, 0.593750f, 0.046875f, 0.906250f}, {0.476562f, 0.972656f, 0.199219f, 0.089844f},
+ {0.031250f, 0.667969f, 0.824219f, 0.390625f}, {0.242188f, 0.343750f, 0.933594f, 0.480469f},
+ {0.421875f, 0.937500f, 0.339844f, 0.132812f}, {0.191406f, 0.613281f, 0.183594f, 0.750000f},
+ {0.617188f, 0.472656f, 0.800781f, 0.675781f}, {0.867188f, 0.855469f, 0.230469f, 0.203125f},
+ {0.449219f, 0.328125f, 0.660156f, 0.953125f}, {0.964844f, 0.746094f, 0.769531f, 0.828125f},
+ {0.007812f, 0.824219f, 0.179688f, 0.011719f}, {0.503906f, 0.125000f, 0.085938f, 0.531250f},
+ {0.421875f, 0.777344f, 0.433594f, 0.199219f}, {0.660156f, 0.710938f, 0.027344f, 0.679688f},
+ {0.261719f, 0.941406f, 0.347656f, 0.257812f}, {0.527344f, 0.386719f, 0.492188f, 0.351562f},
+ {0.843750f, 0.660156f, 0.671875f, 0.179688f}, {0.195312f, 0.195312f, 0.246094f, 0.578125f},
+ {0.062500f, 0.539062f, 0.828125f, 0.429688f}, {0.519531f, 0.847656f, 0.156250f, 0.363281f},
+ {0.730469f, 0.156250f, 0.472656f, 0.855469f}, {0.789062f, 0.941406f, 0.210938f, 0.527344f},
+ {0.250000f, 0.445312f, 0.960938f, 0.218750f}, {0.671875f, 0.078125f, 0.320312f, 0.753906f},
+ {0.500000f, 0.378906f, 0.417969f, 0.015625f}, {0.222656f, 0.988281f, 0.066406f, 0.949219f},
+ {0.828125f, 0.164062f, 0.285156f, 0.453125f}, {0.031250f, 0.222656f, 0.761719f, 0.589844f},
+ {0.878906f, 0.800781f, 0.042969f, 0.691406f}, {0.308594f, 0.351562f, 0.460938f, 0.027344f},
+ {0.789062f, 0.417969f, 0.656250f, 0.160156f}, {0.726562f, 0.285156f, 0.972656f, 0.941406f},
+ {0.859375f, 0.207031f, 0.597656f, 0.796875f}, {0.535156f, 0.839844f, 0.496094f, 0.621094f},
+ {0.941406f, 0.343750f, 0.445312f, 0.285156f}, {0.097656f, 0.164062f, 0.949219f, 0.914062f},
+ {0.687500f, 0.421875f, 0.789062f, 0.492188f}, {0.453125f, 0.871094f, 0.675781f, 0.214844f},
+ {0.035156f, 0.710938f, 0.289062f, 0.078125f}, {0.781250f, 0.941406f, 0.542969f, 0.703125f},
+ {0.207031f, 0.777344f, 0.101562f, 0.867188f}, {0.152344f, 0.089844f, 0.339844f, 0.984375f},
+ {0.480469f, 0.257812f, 0.707031f, 0.371094f}, {0.843750f, 0.722656f, 0.070312f, 0.835938f},
+ {0.230469f, 0.199219f, 0.750000f, 0.417969f}, {0.417969f, 0.054688f, 0.542969f, 0.773438f},
+ {0.617188f, 0.632812f, 0.375000f, 0.070312f}, {0.710938f, 0.386719f, 0.578125f, 0.613281f},
+ {0.921875f, 0.500000f, 0.652344f, 0.281250f}, {0.246094f, 0.921875f, 0.164062f, 0.644531f},
+ {0.687500f, 0.445312f, 0.890625f, 0.218750f}, {0.023438f, 0.789062f, 0.718750f, 0.476562f},
+ {0.996094f, 0.523438f, 0.820312f, 0.269531f}, {0.507812f, 0.117188f, 0.234375f, 0.710938f},
+ {0.253906f, 0.628906f, 0.105469f, 0.531250f}, {0.824219f, 0.574219f, 0.886719f, 0.800781f},
+ {0.070312f, 0.316406f, 0.050781f, 0.164062f}, {0.199219f, 0.039062f, 0.664062f, 0.964844f},
+ {0.867188f, 0.652344f, 0.769531f, 0.277344f}, {0.023438f, 0.867188f, 0.078125f, 0.222656f},
+ {0.335938f, 0.769531f, 0.960938f, 0.535156f}, {0.898438f, 0.535156f, 0.015625f, 0.996094f},
+ {0.585938f, 0.890625f, 0.269531f, 0.691406f}, {0.054688f, 0.644531f, 0.925781f, 0.175781f},
+ {0.980469f, 0.261719f, 0.585938f, 0.511719f}, {0.285156f, 0.789062f, 0.667969f, 0.742188f},
+ {0.113281f, 0.023438f, 0.402344f, 0.859375f}, {0.578125f, 0.417969f, 0.066406f, 0.230469f},
+ {0.800781f, 0.816406f, 0.753906f, 0.921875f}, {0.992188f, 0.164062f, 0.492188f, 0.816406f},
+ {0.519531f, 0.281250f, 0.414062f, 0.289062f}, {0.085938f, 0.675781f, 0.968750f, 0.449219f},
+ {0.167969f, 0.964844f, 0.046875f, 0.347656f}, {0.671875f, 0.035156f, 0.347656f, 0.113281f},
+ {0.761719f, 0.257812f, 0.277344f, 0.714844f}, {0.300781f, 0.457031f, 0.925781f, 0.316406f},
+ {0.578125f, 0.605469f, 0.617188f, 0.984375f}, {0.875000f, 0.082031f, 0.789062f, 0.851562f},
+ {0.156250f, 0.437500f, 0.265625f, 0.558594f}, {0.453125f, 0.253906f, 0.738281f, 0.898438f},
+ {0.968750f, 0.761719f, 0.882812f, 0.703125f}, {0.312500f, 0.480469f, 0.406250f, 0.949219f},
+ {0.679688f, 0.097656f, 0.031250f, 0.773438f}, {0.589844f, 0.308594f, 0.996094f, 0.125000f},
+ {0.375000f, 0.679688f, 0.691406f, 0.675781f}, {0.128906f, 0.000000f, 0.375000f, 0.929688f},
+ {0.562500f, 0.753906f, 0.570312f, 0.421875f}, {0.050781f, 0.562500f, 0.003906f, 0.304688f},
+ {0.386719f, 0.250000f, 0.531250f, 0.648438f}, {0.937500f, 0.781250f, 0.621094f, 0.843750f},
+ {0.437500f, 0.636719f, 0.953125f, 0.515625f}, {0.695312f, 0.515625f, 0.214844f, 0.242188f},
+ {0.253906f, 0.949219f, 0.562500f, 0.910156f}, {0.636719f, 0.097656f, 0.296875f, 0.406250f},
+ {0.453125f, 0.746094f, 0.109375f, 0.566406f}, {0.121094f, 0.917969f, 0.832031f, 0.480469f},
+ {0.269531f, 0.632812f, 0.207031f, 0.105469f}, {0.183594f, 0.449219f, 0.281250f, 0.179688f},
+ {0.746094f, 0.675781f, 0.031250f, 0.691406f}, {0.402344f, 0.113281f, 0.558594f, 0.574219f},
+ {0.894531f, 0.613281f, 0.238281f, 0.839844f}, {0.277344f, 0.277344f, 0.351562f, 0.964844f},
+ {0.976562f, 0.074219f, 0.832031f, 0.535156f}, {0.332031f, 0.472656f, 0.464844f, 0.335938f},
+ {0.738281f, 0.597656f, 0.882812f, 0.171875f}, {0.601562f, 0.855469f, 0.937500f, 0.125000f},
+ {0.292969f, 0.648438f, 0.500000f, 0.058594f}, {0.687500f, 0.996094f, 0.175781f, 0.660156f},
+ {0.984375f, 0.582031f, 0.820312f, 0.527344f}, {0.757812f, 0.761719f, 0.253906f, 0.339844f},
+ {0.488281f, 0.843750f, 0.472656f, 0.128906f}, {0.324219f, 0.265625f, 0.007812f, 0.726562f},
+ {0.085938f, 0.023438f, 0.792969f, 0.386719f}, {0.519531f, 0.664062f, 0.414062f, 0.789062f},
+ {0.578125f, 0.175781f, 0.351562f, 0.015625f}, {0.792969f, 0.292969f, 0.035156f, 0.585938f},
+ {0.308594f, 0.992188f, 0.441406f, 0.769531f}, {0.105469f, 0.683594f, 0.648438f, 0.988281f},
+ {0.765625f, 0.804688f, 0.519531f, 0.093750f}, {0.371094f, 0.074219f, 0.734375f, 0.621094f},
+ {0.929688f, 0.746094f, 0.156250f, 0.359375f}, {0.296875f, 0.964844f, 0.546875f, 0.011719f},
+ {0.722656f, 0.554688f, 0.453125f, 0.414062f}, {0.402344f, 0.347656f, 0.371094f, 0.761719f},
+ {0.964844f, 0.207031f, 0.187500f, 0.078125f}, {0.511719f, 0.074219f, 0.558594f, 0.476562f},
+ {0.257812f, 0.808594f, 0.433594f, 0.781250f}, {0.191406f, 0.410156f, 0.746094f, 0.839844f},
+ {0.750000f, 0.109375f, 0.117188f, 0.281250f}, {0.531250f, 0.195312f, 0.312500f, 0.031250f},
+ {0.859375f, 0.562500f, 0.976562f, 0.570312f}, {0.664062f, 0.703125f, 0.148438f, 0.320312f},
+ {0.363281f, 0.078125f, 0.687500f, 0.613281f}, {0.062500f, 0.531250f, 0.593750f, 0.082031f},
+ {0.703125f, 0.886719f, 0.105469f, 0.539062f}, {0.316406f, 0.382812f, 0.632812f, 0.035156f},
+ {0.390625f, 0.218750f, 0.453125f, 0.644531f}, {0.835938f, 0.562500f, 0.718750f, 0.582031f},
+ {0.214844f, 0.660156f, 0.546875f, 0.886719f}, {0.933594f, 0.359375f, 0.875000f, 0.160156f},
+ {0.089844f, 0.890625f, 0.218750f, 0.378906f}, {0.730469f, 0.210938f, 0.519531f, 0.062500f},
+ {0.359375f, 0.558594f, 0.972656f, 0.480469f}, {0.621094f, 0.324219f, 0.074219f, 0.136719f},
+ {0.042969f, 0.871094f, 0.191406f, 0.304688f}, {0.761719f, 0.589844f, 0.449219f, 0.050781f},
+ {0.476562f, 0.914062f, 0.750000f, 0.253906f}, {0.929688f, 0.414062f, 0.621094f, 0.476562f},
+ {0.218750f, 0.234375f, 0.269531f, 0.195312f}, {0.867188f, 0.519531f, 0.082031f, 0.042969f},
+ {0.320312f, 0.648438f, 0.773438f, 0.613281f}, {0.898438f, 0.328125f, 0.882812f, 0.882812f},
+ {0.769531f, 0.882812f, 0.175781f, 0.113281f}, {0.093750f, 0.109375f, 0.828125f, 0.183594f},
+ {0.566406f, 0.406250f, 0.687500f, 0.378906f}, {0.179688f, 0.714844f, 0.394531f, 0.054688f},
+ {0.984375f, 0.042969f, 0.863281f, 0.316406f}, {0.066406f, 0.671875f, 0.937500f, 0.824219f},
+ {0.574219f, 0.183594f, 0.351562f, 0.757812f}, {0.371094f, 0.570312f, 0.531250f, 0.347656f},
+ {0.675781f, 0.070312f, 0.718750f, 0.261719f}, {0.480469f, 0.949219f, 0.902344f, 0.976562f},
+ {0.808594f, 0.250000f, 0.648438f, 0.398438f}, {0.343750f, 0.539062f, 0.761719f, 0.054688f},
+ {0.601562f, 0.984375f, 0.082031f, 0.152344f}, {0.828125f, 0.828125f, 0.917969f, 0.730469f},
+ {0.121094f, 0.355469f, 0.625000f, 0.636719f}, {0.554688f, 0.226562f, 0.148438f, 0.406250f},
+ {0.398438f, 0.148438f, 0.222656f, 0.792969f}, {0.945312f, 0.429688f, 0.664062f, 0.562500f},
+ {0.082031f, 0.015625f, 0.410156f, 0.753906f}, {0.351562f, 0.367188f, 0.039062f, 0.187500f},
+ {0.562500f, 0.121094f, 0.359375f, 0.238281f}, {0.191406f, 0.308594f, 0.992188f, 0.886719f},
+ {0.128906f, 0.703125f, 0.144531f, 0.988281f}, {0.812500f, 0.539062f, 0.707031f, 0.558594f},
+ {0.968750f, 0.968750f, 0.933594f, 0.179688f}, {0.429688f, 0.335938f, 0.214844f, 0.929688f},
+ {0.195312f, 0.753906f, 0.554688f, 0.859375f}, {0.902344f, 0.867188f, 0.613281f, 0.363281f},
+ {0.468750f, 0.031250f, 0.960938f, 0.152344f}, {0.613281f, 0.234375f, 0.183594f, 0.304688f},
+ {0.210938f, 0.417969f, 0.292969f, 0.429688f}, {0.570312f, 0.476562f, 0.855469f, 0.882812f},
+ {0.652344f, 0.828125f, 0.406250f, 0.480469f}, {0.453125f, 0.386719f, 0.941406f, 0.722656f},
+ {0.085938f, 0.117188f, 0.246094f, 0.585938f}, {0.558594f, 0.710938f, 0.730469f, 0.933594f},
+ {0.140625f, 0.609375f, 0.804688f, 0.632812f}, {0.828125f, 0.996094f, 0.652344f, 0.320312f},
+ {0.687500f, 0.312500f, 0.335938f, 0.234375f}, {0.441406f, 0.472656f, 0.222656f, 0.402344f},
+ {0.632812f, 0.730469f, 0.890625f, 0.937500f}, {0.332031f, 0.871094f, 0.531250f, 0.675781f},
+ {0.164062f, 0.304688f, 0.464844f, 0.445312f}, {0.906250f, 0.914062f, 0.851562f, 0.160156f},
+ {0.460938f, 0.238281f, 0.246094f, 0.722656f}, {0.273438f, 0.753906f, 0.917969f, 0.398438f},
+ {0.777344f, 0.046875f, 0.304688f, 0.992188f}, {0.941406f, 0.496094f, 0.863281f, 0.847656f},
+ {0.554688f, 0.781250f, 0.144531f, 0.179688f}, {0.050781f, 0.097656f, 0.816406f, 0.406250f},
+ {0.621094f, 0.925781f, 0.003906f, 0.789062f}, {0.468750f, 0.515625f, 0.406250f, 0.273438f},
+ {0.820312f, 0.156250f, 0.679688f, 0.621094f}, {0.027344f, 0.691406f, 0.140625f, 0.734375f},
+ {0.234375f, 0.828125f, 0.382812f, 0.808594f}, {0.890625f, 0.054688f, 0.640625f, 0.410156f},
+ {0.398438f, 0.144531f, 0.582031f, 0.652344f}, {0.117188f, 0.722656f, 0.804688f, 0.519531f},
+ {0.265625f, 0.035156f, 0.132812f, 0.835938f}, {0.824219f, 0.781250f, 0.335938f, 0.589844f},
+ {0.015625f, 0.972656f, 0.503906f, 0.324219f}, {0.644531f, 0.367188f, 0.843750f, 0.792969f},
+ {0.460938f, 0.839844f, 0.656250f, 0.375000f}, {0.707031f, 0.179688f, 0.445312f, 0.496094f},
+ {0.148438f, 0.484375f, 0.253906f, 0.269531f}, {0.292969f, 0.585938f, 0.347656f, 0.710938f},
+ {0.800781f, 0.292969f, 0.101562f, 0.792969f}, {0.343750f, 0.847656f, 0.503906f, 0.992188f},
+ {0.511719f, 0.453125f, 0.160156f, 0.542969f}, {0.843750f, 0.261719f, 0.628906f, 0.207031f},
+ {0.214844f, 0.878906f, 0.777344f, 0.082031f}, {0.957031f, 0.492188f, 0.054688f, 0.855469f},
+ {0.890625f, 0.382812f, 0.136719f, 0.656250f}, {0.019531f, 0.804688f, 0.328125f, 0.519531f},
+ {0.636719f, 0.042969f, 0.402344f, 0.753906f}, {0.148438f, 0.753906f, 0.179688f, 0.449219f},
+ {0.046875f, 0.398438f, 0.507812f, 0.320312f}, {0.511719f, 0.019531f, 0.429688f, 0.253906f},
+ {0.222656f, 0.660156f, 0.003906f, 0.003906f}, {0.707031f, 0.910156f, 0.726562f, 0.933594f},
+ {0.011719f, 0.742188f, 0.781250f, 0.281250f}, {0.863281f, 0.316406f, 0.281250f, 0.445312f},
+ {0.515625f, 0.496094f, 0.570312f, 0.910156f}, {0.785156f, 0.875000f, 0.867188f, 0.605469f},
+ {0.042969f, 0.230469f, 0.207031f, 0.824219f}, {0.667969f, 0.468750f, 0.605469f, 0.472656f},
+ {0.878906f, 0.906250f, 0.316406f, 0.046875f}, {0.382812f, 0.164062f, 0.765625f, 0.671875f},
+ {0.015625f, 0.093750f, 0.070312f, 0.312500f}, {0.640625f, 0.425781f, 0.277344f, 0.457031f},
+ {0.847656f, 0.613281f, 0.859375f, 0.113281f}, {0.062500f, 0.128906f, 0.128906f, 0.691406f},
+ {0.726562f, 0.558594f, 0.761719f, 0.503906f}, {0.398438f, 0.355469f, 0.382812f, 0.917969f},
+ {0.886719f, 0.925781f, 0.000000f, 0.667969f}, {0.000000f, 0.148438f, 0.792969f, 0.062500f},
+ {0.156250f, 0.277344f, 0.597656f, 0.242188f}, {0.808594f, 0.191406f, 0.316406f, 0.855469f},
+ {0.945312f, 0.910156f, 0.042969f, 0.117188f}, {0.226562f, 0.453125f, 0.914062f, 0.191406f},
+ {0.761719f, 0.250000f, 0.109375f, 0.441406f}, {0.308594f, 0.015625f, 0.480469f, 0.882812f},
+ {0.015625f, 0.671875f, 0.847656f, 0.132812f}, {0.878906f, 0.144531f, 0.074219f, 0.605469f},
+ {0.933594f, 0.945312f, 0.613281f, 0.074219f}, {0.074219f, 0.503906f, 0.777344f, 0.359375f},
+ {0.406250f, 0.378906f, 0.050781f, 0.796875f}, {0.718750f, 0.605469f, 0.367188f, 0.886719f},
+ {0.003906f, 0.449219f, 0.554688f, 0.500000f}, {0.218750f, 0.988281f, 0.015625f, 0.218750f},
+ {0.640625f, 0.636719f, 0.730469f, 0.769531f}, {0.117188f, 0.144531f, 0.375000f, 0.269531f},
+ {0.429688f, 0.429688f, 0.250000f, 0.691406f}, {0.902344f, 0.839844f, 0.488281f, 0.957031f},
+ {0.261719f, 0.316406f, 0.949219f, 0.460938f}, {0.339844f, 0.738281f, 0.304688f, 0.085938f},
+ {0.531250f, 0.015625f, 0.101562f, 0.507812f}, {0.691406f, 0.984375f, 0.832031f, 0.941406f},
+ {0.945312f, 0.378906f, 0.890625f, 0.015625f}, {0.562500f, 0.628906f, 0.324219f, 0.203125f},
+ {0.796875f, 0.953125f, 0.011719f, 0.921875f}, {0.656250f, 0.285156f, 0.953125f, 0.730469f},
+ {0.167969f, 0.183594f, 0.542969f, 0.085938f}, {0.542969f, 0.468750f, 0.906250f, 0.890625f},
+ {0.410156f, 0.617188f, 0.046875f, 0.695312f}, {0.996094f, 0.128906f, 0.199219f, 0.972656f},
+ {0.191406f, 0.050781f, 0.945312f, 0.148438f}, {0.511719f, 0.937500f, 0.117188f, 0.738281f},
+ {0.613281f, 0.734375f, 0.722656f, 0.910156f}, {0.921875f, 0.019531f, 0.988281f, 0.429688f},
+ {0.652344f, 0.972656f, 0.601562f, 0.601562f}, {0.003906f, 0.136719f, 0.746094f, 0.664062f},
+ {0.722656f, 0.359375f, 0.011719f, 0.148438f}, {0.402344f, 0.609375f, 0.257812f, 0.718750f},
+ {0.765625f, 0.785156f, 0.414062f, 0.437500f}, {0.082031f, 0.296875f, 0.480469f, 0.605469f},
+ {0.542969f, 0.144531f, 0.996094f, 0.011719f}, {0.312500f, 0.699219f, 0.589844f, 0.882812f},
+ {0.242188f, 0.328125f, 0.859375f, 0.222656f}, {0.968750f, 0.593750f, 0.699219f, 0.804688f},
+ {0.425781f, 0.156250f, 0.964844f, 0.902344f}, {0.753906f, 0.492188f, 0.296875f, 0.605469f},
+ {0.917969f, 0.792969f, 0.582031f, 0.472656f}, {0.468750f, 0.546875f, 0.382812f, 0.847656f},
+ {0.632812f, 0.058594f, 0.074219f, 0.066406f}, {0.261719f, 0.937500f, 0.968750f, 0.683594f},
+ {0.160156f, 0.687500f, 0.125000f, 0.320312f}, {0.441406f, 0.781250f, 0.648438f, 0.019531f},
+ {0.320312f, 0.972656f, 0.023438f, 0.710938f}, {0.937500f, 0.070312f, 0.429688f, 0.164062f},
+ {0.273438f, 0.406250f, 0.886719f, 0.414062f}, {0.585938f, 0.789062f, 0.511719f, 0.804688f},
+ {0.234375f, 0.574219f, 0.636719f, 0.230469f}, {0.750000f, 0.832031f, 0.460938f, 0.531250f},
+ {0.355469f, 0.250000f, 0.695312f, 0.750000f}, {0.281250f, 0.480469f, 0.328125f, 0.250000f},
+ {0.132812f, 0.726562f, 0.500000f, 0.035156f}, {0.671875f, 0.886719f, 0.917969f, 0.601562f},
+ {0.972656f, 0.621094f, 0.664062f, 0.199219f}, {0.328125f, 0.699219f, 0.472656f, 0.789062f},
+ {0.511719f, 0.519531f, 0.121094f, 0.519531f}, {0.695312f, 0.593750f, 0.699219f, 0.300781f},
+ {0.351562f, 0.054688f, 0.503906f, 0.683594f}, {0.621094f, 0.757812f, 0.628906f, 0.351562f},
+ {0.484375f, 0.882812f, 0.285156f, 0.808594f}, {0.660156f, 0.394531f, 0.152344f, 0.046875f},
+ {0.386719f, 0.574219f, 0.992188f, 0.660156f}, {0.121094f, 0.824219f, 0.691406f, 0.738281f},
+ {0.242188f, 0.234375f, 0.410156f, 0.531250f}, {0.601562f, 0.031250f, 0.171875f, 0.191406f},
+ {0.773438f, 0.085938f, 0.277344f, 0.960938f}, {0.507812f, 0.839844f, 0.656250f, 0.113281f},
+ {0.968750f, 0.179688f, 0.812500f, 0.023438f}, {0.566406f, 0.351562f, 0.203125f, 0.632812f},
+ {0.878906f, 0.289062f, 0.515625f, 0.343750f}, {0.484375f, 0.710938f, 0.996094f, 0.121094f},
+ {0.183594f, 0.957031f, 0.589844f, 0.519531f}, {0.734375f, 0.191406f, 0.187500f, 0.042969f},
+ {0.804688f, 0.621094f, 0.644531f, 0.222656f}, {0.148438f, 0.269531f, 0.757812f, 0.898438f},
+ {0.406250f, 0.480469f, 0.574219f, 0.664062f}, {0.109375f, 0.789062f, 0.457031f, 0.328125f},
+ {0.296875f, 0.234375f, 0.718750f, 0.246094f}, {0.191406f, 0.523438f, 0.500000f, 0.570312f},
+ {0.500000f, 0.449219f, 0.281250f, 0.351562f}, {0.324219f, 0.347656f, 0.218750f, 0.160156f},
+ {0.953125f, 0.683594f, 0.378906f, 0.441406f}, {0.710938f, 0.539062f, 0.703125f, 0.382812f},
+ {0.097656f, 0.886719f, 0.425781f, 0.003906f}, {0.347656f, 0.281250f, 0.296875f, 0.546875f},
+ {0.761719f, 0.695312f, 0.554688f, 0.246094f}, {0.039062f, 0.433594f, 0.386719f, 0.078125f},
+ {0.253906f, 0.230469f, 0.496094f, 0.566406f}, {0.378906f, 0.804688f, 0.058594f, 0.023438f},
+ {0.449219f, 0.648438f, 0.304688f, 0.335938f}, {0.875000f, 0.199219f, 0.437500f, 0.101562f},
+ {0.136719f, 0.917969f, 0.917969f, 0.476562f}, {0.285156f, 0.539062f, 0.847656f, 0.902344f},
+ {0.617188f, 0.003906f, 0.703125f, 0.250000f}, {0.167969f, 0.996094f, 0.210938f, 0.953125f},
+ {0.429688f, 0.437500f, 0.800781f, 0.308594f}, {0.738281f, 0.847656f, 0.265625f, 0.140625f},
+ {0.847656f, 0.210938f, 0.019531f, 0.566406f}, {0.558594f, 0.929688f, 0.125000f, 0.085938f},
+ {0.660156f, 0.878906f, 0.808594f, 0.363281f}, {0.179688f, 0.289062f, 0.203125f, 0.671875f},
+ {0.308594f, 0.203125f, 0.851562f, 0.117188f}, {0.367188f, 0.414062f, 0.902344f, 0.746094f},
+ {0.101562f, 0.621094f, 0.527344f, 0.210938f}, {0.804688f, 0.265625f, 0.332031f, 0.500000f},
+ {0.914062f, 0.175781f, 0.464844f, 0.960938f}, {0.726562f, 0.535156f, 0.734375f, 0.378906f},
+ {0.628906f, 0.656250f, 0.539062f, 0.628906f}, {0.074219f, 0.601562f, 0.804688f, 0.273438f},
+ {0.453125f, 0.347656f, 0.109375f, 0.578125f}, {0.531250f, 0.210938f, 0.378906f, 0.867188f},
+ {0.699219f, 0.683594f, 0.175781f, 0.085938f}, {0.156250f, 0.050781f, 0.832031f, 0.972656f},
+ {0.492188f, 0.945312f, 0.972656f, 0.625000f}, {0.953125f, 0.382812f, 0.085938f, 0.820312f},
+ {0.550781f, 0.199219f, 0.253906f, 0.417969f}, {0.246094f, 0.082031f, 0.566406f, 0.847656f},
+ {0.449219f, 0.308594f, 0.070312f, 0.371094f}, {0.785156f, 0.003906f, 0.234375f, 0.132812f},
+ {0.097656f, 0.984375f, 0.984375f, 0.746094f}, {0.269531f, 0.847656f, 0.187500f, 0.980469f},
+ {0.871094f, 0.656250f, 0.824219f, 0.031250f}, {0.039062f, 0.296875f, 0.398438f, 0.550781f},
+ {0.187500f, 0.503906f, 0.882812f, 0.917969f}, {0.992188f, 0.179688f, 0.589844f, 0.500000f},
+ {0.789062f, 0.718750f, 0.363281f, 0.289062f}, {0.558594f, 0.332031f, 0.007812f, 0.980469f},
+ {0.464844f, 0.531250f, 0.507812f, 0.460938f}, {0.824219f, 0.640625f, 0.902344f, 0.253906f},
+ {0.203125f, 0.781250f, 0.722656f, 0.593750f}, {0.304688f, 0.687500f, 0.960938f, 0.308594f},
+ {0.136719f, 0.117188f, 0.125000f, 0.707031f}, {0.839844f, 0.550781f, 0.410156f, 0.917969f},
+ {0.351562f, 0.808594f, 0.769531f, 0.468750f}, {0.289062f, 0.000000f, 0.074219f, 0.863281f},
+ {0.667969f, 0.582031f, 0.691406f, 0.597656f}, {0.015625f, 0.375000f, 0.117188f, 0.371094f},
+ {0.578125f, 0.054688f, 0.902344f, 0.765625f}, {0.957031f, 0.882812f, 0.351562f, 0.558594f},
+ {0.644531f, 0.417969f, 0.058594f, 0.128906f}, {0.847656f, 0.664062f, 0.238281f, 0.429688f},
+ {0.464844f, 0.070312f, 0.171875f, 0.773438f}, {0.746094f, 0.917969f, 0.929688f, 0.855469f},
+ {0.000000f, 0.109375f, 0.777344f, 0.613281f}, {0.867188f, 0.851562f, 0.660156f, 0.996094f},
+ {0.609375f, 0.796875f, 0.851562f, 0.273438f}, {0.445312f, 0.222656f, 0.160156f, 0.777344f},
+ {0.808594f, 0.078125f, 0.597656f, 0.199219f}, {0.277344f, 0.394531f, 0.800781f, 0.636719f},
+ {0.582031f, 0.824219f, 0.753906f, 0.464844f}, {0.945312f, 0.511719f, 0.632812f, 0.851562f},
+ {0.835938f, 0.316406f, 0.226562f, 0.941406f}, {0.082031f, 0.554688f, 0.863281f, 0.210938f},
+ {0.546875f, 0.378906f, 0.785156f, 0.812500f}, {0.222656f, 0.468750f, 0.191406f, 0.289062f},
+ {0.953125f, 0.753906f, 0.535156f, 0.843750f}, {0.484375f, 0.089844f, 0.652344f, 0.367188f},
+ {0.828125f, 0.226562f, 0.089844f, 0.042969f}, {0.687500f, 0.722656f, 0.566406f, 0.746094f},
+ {0.937500f, 0.640625f, 0.375000f, 0.488281f}, {0.496094f, 0.105469f, 0.675781f, 0.386719f},
+ {0.113281f, 0.527344f, 0.460938f, 0.699219f}, {0.375000f, 0.453125f, 0.546875f, 0.945312f},
+ {0.878906f, 0.679688f, 0.343750f, 0.511719f}, {0.070312f, 0.085938f, 0.644531f, 0.179688f},
+ {0.820312f, 0.718750f, 0.480469f, 0.996094f}, {0.992188f, 0.957031f, 0.160156f, 0.390625f},
+ {0.683594f, 0.121094f, 0.695312f, 0.582031f}, {0.582031f, 0.824219f, 0.242188f, 0.148438f},
+ {0.203125f, 0.382812f, 0.835938f, 0.867188f}, {0.386719f, 0.042969f, 0.925781f, 0.105469f},
+ {0.832031f, 0.285156f, 0.296875f, 0.792969f}, {0.152344f, 0.738281f, 0.671875f, 0.945312f},
+ {0.765625f, 0.855469f, 0.234375f, 0.347656f}, {0.855469f, 0.511719f, 0.914062f, 0.734375f},
+ {0.101562f, 0.917969f, 0.582031f, 0.000000f}, {0.917969f, 0.316406f, 0.019531f, 0.394531f},
+ {0.804688f, 0.636719f, 0.410156f, 0.328125f}, {0.601562f, 0.765625f, 0.199219f, 0.171875f},
+ {0.027344f, 0.515625f, 0.800781f, 0.949219f}, {0.761719f, 0.835938f, 0.890625f, 0.285156f},
+ {0.183594f, 0.429688f, 0.734375f, 0.554688f}, {0.855469f, 0.773438f, 0.433594f, 0.925781f},
+ {0.593750f, 0.222656f, 0.871094f, 0.457031f}, {0.402344f, 0.351562f, 0.351562f, 0.625000f},
+ {0.917969f, 0.414062f, 0.554688f, 0.402344f}, {0.539062f, 0.136719f, 0.023438f, 0.257812f},
+ {0.433594f, 0.792969f, 0.718750f, 0.757812f}, {0.082031f, 0.960938f, 0.210938f, 0.160156f},
+ {0.281250f, 0.097656f, 0.789062f, 0.378906f}, {0.714844f, 0.863281f, 0.304688f, 0.859375f},
+ {0.343750f, 0.433594f, 0.828125f, 0.000000f}, {0.953125f, 0.976562f, 0.226562f, 0.769531f},
+ {0.042969f, 0.273438f, 0.566406f, 0.843750f}, {0.691406f, 0.402344f, 0.335938f, 0.425781f},
+ {0.394531f, 0.937500f, 0.476562f, 0.550781f}, {0.613281f, 0.476562f, 0.636719f, 0.808594f},
+ {0.093750f, 0.878906f, 0.890625f, 0.167969f}, {0.789062f, 0.234375f, 0.324219f, 0.066406f},
+ {0.980469f, 0.511719f, 0.441406f, 0.933594f}, {0.382812f, 0.675781f, 0.796875f, 0.710938f},
+ {0.500000f, 0.765625f, 0.273438f, 0.312500f}, {0.078125f, 0.125000f, 0.527344f, 0.839844f},
+ {0.757812f, 0.554688f, 0.980469f, 0.187500f}, {0.246094f, 0.332031f, 0.816406f, 0.960938f},
+ {0.589844f, 0.167969f, 0.421875f, 0.687500f}, {0.984375f, 0.582031f, 0.609375f, 0.074219f},
+ {0.089844f, 0.746094f, 0.097656f, 0.472656f}, {0.375000f, 0.406250f, 0.046875f, 0.117188f},
+ {0.238281f, 0.023438f, 0.468750f, 0.664062f}, {0.042969f, 0.570312f, 0.984375f, 0.527344f},
+ {0.894531f, 0.988281f, 0.097656f, 0.917969f}, {0.679688f, 0.750000f, 0.882812f, 0.824219f},
+ {0.121094f, 0.156250f, 0.015625f, 0.296875f}, {0.417969f, 0.601562f, 0.152344f, 0.675781f},
+ {0.714844f, 0.062500f, 0.925781f, 0.367188f}, {0.187500f, 0.878906f, 0.679688f, 0.515625f},
+ {0.789062f, 0.097656f, 0.574219f, 0.632812f}, {0.671875f, 0.683594f, 0.132812f, 0.968750f},
+ {0.593750f, 0.828125f, 0.363281f, 0.695312f}, {0.332031f, 0.324219f, 0.281250f, 0.535156f},
+ {0.058594f, 0.406250f, 0.957031f, 0.585938f}, {0.250000f, 0.871094f, 0.164062f, 0.800781f},
+ {0.355469f, 0.574219f, 0.894531f, 0.187500f}, {0.042969f, 0.359375f, 0.070312f, 0.625000f},
+ {0.207031f, 0.265625f, 0.949219f, 0.839844f}, {0.703125f, 0.031250f, 0.746094f, 0.039062f},
+ {0.273438f, 0.609375f, 0.242188f, 0.246094f}, {0.601562f, 0.371094f, 0.093750f, 0.781250f},
+ {0.535156f, 0.859375f, 0.765625f, 0.542969f}, {0.140625f, 0.324219f, 0.035156f, 0.292969f},
+ {0.425781f, 0.476562f, 0.605469f, 0.812500f}, {0.292969f, 0.585938f, 0.417969f, 0.660156f},
+ {0.023438f, 0.890625f, 0.066406f, 0.246094f}, {0.542969f, 0.445312f, 0.183594f, 0.539062f},
+ {0.484375f, 0.152344f, 0.976562f, 0.027344f}, {0.226562f, 0.953125f, 0.480469f, 0.488281f},
+ {0.988281f, 0.003906f, 0.054688f, 0.128906f}, {0.339844f, 0.125000f, 0.703125f, 0.648438f},
+ {0.406250f, 0.265625f, 0.281250f, 0.511719f}, {0.203125f, 0.453125f, 0.746094f, 0.890625f},
+ {0.308594f, 0.164062f, 0.535156f, 0.105469f}, {0.425781f, 0.023438f, 0.679688f, 0.574219f},
+ {0.871094f, 0.976562f, 0.609375f, 0.718750f}, {0.371094f, 0.664062f, 0.367188f, 0.078125f},
+ {0.531250f, 0.140625f, 0.160156f, 0.660156f}, {0.050781f, 0.570312f, 0.289062f, 0.007812f},
+ {0.710938f, 0.488281f, 0.636719f, 0.332031f}, {0.214844f, 0.089844f, 0.773438f, 0.207031f},
+ {0.132812f, 0.937500f, 0.097656f, 0.871094f}, {0.746094f, 0.554688f, 0.257812f, 0.097656f},
+ {0.832031f, 0.039062f, 0.964844f, 0.601562f}, {0.597656f, 0.625000f, 0.464844f, 0.703125f},
+ {0.898438f, 0.371094f, 0.539062f, 0.218750f}, {0.160156f, 0.207031f, 0.132812f, 0.574219f},
+ {0.515625f, 0.050781f, 0.937500f, 0.121094f}, {0.089844f, 0.734375f, 0.449219f, 0.343750f},
+ {0.640625f, 0.156250f, 0.093750f, 0.671875f}, {0.894531f, 0.578125f, 0.039062f, 0.058594f},
+ {0.449219f, 0.218750f, 0.847656f, 0.226562f}, {0.753906f, 0.726562f, 0.175781f, 0.382812f},
+ {0.035156f, 0.082031f, 0.261719f, 0.281250f}, {0.542969f, 0.328125f, 0.023438f, 0.652344f},
+ {0.234375f, 0.910156f, 0.562500f, 0.433594f}, {0.707031f, 0.449219f, 0.855469f, 0.242188f},
+ {0.312500f, 0.941406f, 0.394531f, 0.003906f}, {0.203125f, 0.218750f, 0.035156f, 0.625000f},
+ {0.917969f, 0.835938f, 0.628906f, 0.492188f}, {0.363281f, 0.972656f, 0.699219f, 0.382812f},
+ {0.156250f, 0.710938f, 0.125000f, 0.035156f}, {0.425781f, 0.265625f, 0.367188f, 0.535156f},
+ {0.667969f, 0.875000f, 0.535156f, 0.300781f}, {0.527344f, 0.640625f, 0.742188f, 0.753906f},
+ {0.769531f, 0.148438f, 0.328125f, 0.871094f}, {0.152344f, 0.484375f, 0.230469f, 0.046875f},
+ {0.488281f, 0.332031f, 0.511719f, 0.339844f}, {0.214844f, 0.656250f, 0.265625f, 0.105469f},
+ {0.539062f, 0.906250f, 0.363281f, 0.417969f}, {0.878906f, 0.207031f, 0.464844f, 0.167969f},
+ {0.304688f, 0.957031f, 0.324219f, 0.769531f}, {0.496094f, 0.726562f, 0.039062f, 0.117188f},
+ {0.980469f, 0.273438f, 0.406250f, 0.453125f}, {0.031250f, 0.167969f, 0.976562f, 0.058594f},
+ {0.414062f, 0.585938f, 0.804688f, 0.156250f}, {0.117188f, 0.960938f, 0.023438f, 0.222656f},
+ {0.882812f, 0.507812f, 0.449219f, 0.414062f}, {0.554688f, 0.066406f, 0.757812f, 0.113281f},
+ {0.808594f, 0.175781f, 0.515625f, 0.984375f}, {0.621094f, 0.937500f, 0.304688f, 0.269531f},
+ {0.769531f, 0.824219f, 0.609375f, 0.449219f}, {0.906250f, 0.750000f, 0.386719f, 0.738281f},
+ {0.464844f, 0.980469f, 0.878906f, 0.335938f}, {0.000000f, 0.542969f, 0.441406f, 0.429688f},
+ {0.781250f, 0.179688f, 0.984375f, 0.027344f}, {0.238281f, 0.765625f, 0.304688f, 0.914062f},
+ {0.500000f, 0.011719f, 0.914062f, 0.082031f}, {0.871094f, 0.238281f, 0.792969f, 0.355469f},
+ {0.750000f, 0.707031f, 0.632812f, 0.742188f}, {0.945312f, 0.796875f, 0.382812f, 0.433594f},
+ {0.109375f, 0.207031f, 0.570312f, 0.316406f}, {0.707031f, 0.492188f, 0.761719f, 0.203125f},
+ {0.597656f, 0.390625f, 0.328125f, 0.917969f}, {0.003906f, 0.554688f, 0.941406f, 0.261719f},
+ {0.519531f, 0.777344f, 0.453125f, 0.445312f}, {0.628906f, 0.699219f, 0.144531f, 0.679688f},
+ {0.066406f, 0.867188f, 0.878906f, 0.226562f}, {0.683594f, 0.589844f, 0.308594f, 0.777344f},
+ {0.117188f, 0.246094f, 0.464844f, 0.437500f}, {0.933594f, 0.339844f, 0.027344f, 0.488281f},
+ {0.632812f, 0.917969f, 0.925781f, 0.234375f}, {0.320312f, 0.273438f, 0.535156f, 0.886719f},
+ {0.980469f, 0.816406f, 0.050781f, 0.734375f}, {0.476562f, 0.734375f, 0.488281f, 0.152344f},
+ {0.648438f, 0.187500f, 0.687500f, 0.824219f}, {0.308594f, 0.875000f, 0.847656f, 0.460938f},
+ {0.367188f, 0.695312f, 0.417969f, 0.949219f}, {0.234375f, 0.281250f, 0.097656f, 0.035156f},
+ {0.007812f, 0.468750f, 0.667969f, 0.421875f}, {0.664062f, 0.921875f, 0.753906f, 0.914062f},
+ {0.863281f, 0.597656f, 0.605469f, 0.718750f}, {0.378906f, 0.320312f, 0.386719f, 0.476562f},
+ {0.273438f, 0.492188f, 0.683594f, 0.953125f}, {0.550781f, 0.851562f, 0.781250f, 0.144531f},
+ {0.167969f, 0.027344f, 0.593750f, 0.613281f}, {0.250000f, 0.367188f, 0.925781f, 0.976562f},
+ {0.941406f, 0.656250f, 0.511719f, 0.746094f}, {0.468750f, 0.757812f, 0.675781f, 0.531250f},
+ {0.156250f, 0.140625f, 0.953125f, 0.132812f}, {0.890625f, 0.269531f, 0.164062f, 0.792969f},
+ {0.820312f, 0.074219f, 0.734375f, 0.988281f}, {0.449219f, 0.605469f, 0.476562f, 0.105469f},
+ {0.546875f, 0.503906f, 0.210938f, 0.738281f}, {0.058594f, 0.019531f, 0.320312f, 0.277344f},
+ {0.875000f, 0.390625f, 0.867188f, 0.914062f}, {0.718750f, 0.468750f, 0.261719f, 0.808594f},
+ {0.281250f, 0.207031f, 0.953125f, 0.175781f}, {0.832031f, 0.312500f, 0.835938f, 0.402344f},
+ {0.914062f, 0.945312f, 0.640625f, 0.230469f}, {0.316406f, 0.816406f, 0.402344f, 0.457031f},
+ {0.648438f, 0.257812f, 0.730469f, 0.593750f}, {0.976562f, 0.441406f, 0.667969f, 0.730469f},
+ {0.363281f, 0.011719f, 0.957031f, 0.984375f}, {0.015625f, 0.363281f, 0.820312f, 0.019531f},
+ {0.636719f, 0.476562f, 0.531250f, 0.574219f}, {0.144531f, 0.632812f, 0.734375f, 0.878906f},
+ {0.355469f, 0.421875f, 0.253906f, 0.269531f}, {0.269531f, 0.929688f, 0.484375f, 0.730469f},
+ {0.773438f, 0.027344f, 0.621094f, 0.339844f}, {0.921875f, 0.253906f, 0.707031f, 0.925781f},
+ {0.722656f, 0.660156f, 0.328125f, 0.867188f}, {0.453125f, 0.777344f, 0.839844f, 0.679688f},
+ {0.156250f, 0.292969f, 0.234375f, 0.324219f}, {0.988281f, 0.699219f, 0.128906f, 0.062500f},
+ {0.523438f, 0.402344f, 0.820312f, 0.898438f}, {0.128906f, 0.140625f, 0.183594f, 0.160156f},
+ {0.394531f, 0.238281f, 0.050781f, 0.597656f}, {0.964844f, 0.062500f, 0.660156f, 0.855469f},
+ {0.339844f, 0.429688f, 0.558594f, 0.707031f}, {0.722656f, 0.648438f, 0.363281f, 0.628906f},
+ {0.921875f, 0.515625f, 0.207031f, 0.460938f}, {0.054688f, 0.988281f, 0.503906f, 0.878906f},
+ {0.652344f, 0.089844f, 0.718750f, 0.179688f}, {0.351562f, 0.339844f, 0.140625f, 0.980469f},
+ {0.800781f, 0.902344f, 0.085938f, 0.679688f}, {0.429688f, 0.679688f, 0.859375f, 0.765625f},
+ {0.296875f, 0.820312f, 0.195312f, 0.546875f}, {0.675781f, 0.613281f, 0.621094f, 0.839844f},
+ {0.882812f, 0.933594f, 0.816406f, 0.167969f}, {0.769531f, 0.070312f, 0.363281f, 0.812500f},
+ {0.964844f, 0.367188f, 0.062500f, 0.937500f}, {0.480469f, 0.421875f, 0.988281f, 0.351562f},
+ {0.226562f, 0.113281f, 0.121094f, 0.144531f}, {0.277344f, 0.726562f, 0.828125f, 0.992188f},
+ {0.742188f, 0.464844f, 0.695312f, 0.804688f}, {0.152344f, 0.058594f, 0.398438f, 0.382812f},
+ {0.421875f, 0.675781f, 0.960938f, 0.574219f}, {0.792969f, 0.601562f, 0.144531f, 0.511719f},
+ {0.031250f, 0.320312f, 0.332031f, 0.648438f}, {0.933594f, 0.441406f, 0.578125f, 0.292969f},
+ {0.703125f, 0.230469f, 0.179688f, 0.789062f}, {0.492188f, 0.773438f, 0.925781f, 0.527344f},
+ {0.960938f, 0.535156f, 0.339844f, 0.324219f}, {0.425781f, 0.671875f, 0.035156f, 0.820312f},
+ {0.734375f, 0.804688f, 0.257812f, 0.628906f}, {0.207031f, 0.113281f, 0.164062f, 0.187500f},
+ {0.808594f, 0.902344f, 0.984375f, 0.289062f}, {0.988281f, 0.636719f, 0.300781f, 0.886719f},
+ {0.707031f, 0.441406f, 0.214844f, 0.507812f}, {0.328125f, 0.968750f, 0.371094f, 0.015625f},
+ {0.859375f, 0.183594f, 0.742188f, 0.839844f}, {0.656250f, 0.570312f, 0.121094f, 0.332031f},
+ {0.398438f, 0.414062f, 0.343750f, 0.882812f}, {0.113281f, 0.816406f, 0.234375f, 0.476562f},
+ {0.613281f, 0.703125f, 0.656250f, 0.398438f}, {0.027344f, 0.359375f, 0.093750f, 0.550781f},
+ {0.683594f, 0.292969f, 0.789062f, 0.855469f}, {0.785156f, 0.804688f, 0.917969f, 0.214844f},
+ {0.328125f, 0.910156f, 0.574219f, 0.617188f}, {0.621094f, 0.085938f, 0.007812f, 0.359375f},
+ {0.199219f, 0.687500f, 0.445312f, 0.964844f}, {0.117188f, 0.519531f, 0.183594f, 0.699219f},
+ {0.574219f, 0.066406f, 0.121094f, 0.628906f}, {0.394531f, 0.605469f, 0.914062f, 0.945312f},
+ {0.730469f, 0.718750f, 0.574219f, 0.144531f}, {0.078125f, 0.105469f, 0.066406f, 0.265625f},
+ {0.800781f, 0.546875f, 0.191406f, 0.523438f}, {0.460938f, 0.792969f, 0.609375f, 0.703125f},
+ {0.746094f, 0.847656f, 0.101562f, 0.218750f}, {0.582031f, 0.125000f, 0.914062f, 0.945312f},
+ {0.859375f, 0.335938f, 0.851562f, 0.402344f}, {0.695312f, 0.535156f, 0.070312f, 0.785156f},
+ {0.523438f, 0.792969f, 0.207031f, 0.593750f}, {0.210938f, 0.445312f, 0.886719f, 0.464844f},
+ {0.628906f, 0.132812f, 0.582031f, 0.000000f}, {0.285156f, 0.902344f, 0.054688f, 0.515625f},
+ {0.019531f, 0.472656f, 0.648438f, 0.773438f}, {0.410156f, 0.011719f, 0.414062f, 0.558594f},
+ {0.312500f, 0.632812f, 0.699219f, 0.652344f}, {0.230469f, 0.500000f, 0.527344f, 0.500000f},
+ {0.656250f, 0.789062f, 0.921875f, 0.109375f}, {0.843750f, 0.308594f, 0.265625f, 0.960938f},
+ {0.183594f, 0.835938f, 0.734375f, 0.218750f}, {0.632812f, 0.925781f, 0.109375f, 0.140625f},
+ {0.093750f, 0.136719f, 0.847656f, 0.269531f}, {0.394531f, 0.371094f, 0.011719f, 0.523438f},
+ {0.191406f, 0.625000f, 0.273438f, 0.046875f}, {0.269531f, 0.566406f, 0.894531f, 0.593750f},
+ {0.574219f, 0.035156f, 0.359375f, 0.906250f}, {0.164062f, 0.300781f, 0.523438f, 0.085938f},
+ {0.925781f, 0.101562f, 0.425781f, 0.359375f}, {0.089844f, 0.230469f, 0.003906f, 0.054688f},
+ {0.257812f, 0.332031f, 0.550781f, 0.589844f}, {0.378906f, 0.187500f, 0.242188f, 0.300781f},
+ {0.167969f, 0.531250f, 0.785156f, 0.023438f}, {0.722656f, 0.824219f, 0.640625f, 0.628906f},
+ {0.578125f, 0.898438f, 0.519531f, 0.546875f}, {0.835938f, 0.621094f, 0.257812f, 0.054688f},
+ {0.503906f, 0.175781f, 0.195312f, 0.691406f}, {0.074219f, 0.394531f, 0.601562f, 0.304688f},
+ {0.882812f, 0.953125f, 0.796875f, 0.085938f}, {0.574219f, 0.015625f, 0.230469f, 0.968750f},
+ {0.273438f, 0.515625f, 0.886719f, 0.050781f}, {0.113281f, 0.828125f, 0.742188f, 0.367188f},
+ {0.816406f, 0.101562f, 0.281250f, 0.183594f}, {0.187500f, 0.968750f, 0.625000f, 0.671875f},
+ {0.562500f, 0.003906f, 0.796875f, 0.113281f}, {0.320312f, 0.164062f, 0.898438f, 0.257812f},
+ {0.128906f, 0.257812f, 0.503906f, 0.062500f}, {0.593750f, 0.390625f, 0.843750f, 0.542969f},
+ {0.472656f, 0.757812f, 0.726562f, 0.402344f}, {0.023438f, 0.062500f, 0.539062f, 0.792969f},
+ {0.113281f, 0.296875f, 0.425781f, 0.722656f}, {0.523438f, 0.808594f, 0.054688f, 0.449219f},
+ {0.800781f, 0.515625f, 0.816406f, 0.093750f}, {0.054688f, 0.867188f, 0.460938f, 0.207031f},
+ {0.566406f, 0.019531f, 0.605469f, 0.582031f}, {0.742188f, 0.992188f, 0.882812f, 0.671875f},
+ {0.265625f, 0.472656f, 0.546875f, 0.171875f}, {0.992188f, 0.171875f, 0.964844f, 0.316406f},
+ {0.406250f, 0.746094f, 0.429688f, 0.695312f}, {0.132812f, 0.628906f, 0.160156f, 0.453125f},
+ {0.488281f, 0.140625f, 0.507812f, 0.136719f}, {0.937500f, 0.562500f, 0.679688f, 0.566406f},
+ {0.019531f, 0.789062f, 0.769531f, 0.085938f}, {0.464844f, 0.898438f, 0.597656f, 0.492188f},
+ {0.957031f, 0.378906f, 0.304688f, 0.011719f}, {0.050781f, 0.179688f, 0.027344f, 0.765625f},
+ {0.261719f, 0.859375f, 0.875000f, 0.375000f}, {0.609375f, 0.964844f, 0.437500f, 0.812500f},
+ {0.175781f, 0.296875f, 0.781250f, 0.894531f}, {0.929688f, 0.691406f, 0.289062f, 0.468750f},
+ {0.238281f, 0.234375f, 0.382812f, 0.347656f}, {0.093750f, 0.054688f, 0.160156f, 0.652344f},
+ {0.914062f, 0.750000f, 0.656250f, 0.035156f}, {0.445312f, 0.863281f, 0.320312f, 0.187500f},
+ {0.167969f, 0.199219f, 0.519531f, 0.828125f}, {0.070312f, 0.703125f, 0.117188f, 0.644531f},
+ {0.371094f, 0.382812f, 0.386719f, 0.289062f}, {0.949219f, 0.601562f, 0.917969f, 0.144531f},
+ {0.675781f, 0.218750f, 0.476562f, 0.394531f}, {0.867188f, 0.550781f, 0.988281f, 0.933594f},
+ {0.585938f, 0.960938f, 0.003906f, 0.199219f}, {0.753906f, 0.339844f, 0.328125f, 0.371094f},
+ {0.078125f, 0.914062f, 0.773438f, 0.796875f}, {0.542969f, 0.593750f, 0.488281f, 0.308594f},
+ {0.449219f, 0.683594f, 0.148438f, 0.558594f}, {0.289062f, 0.218750f, 0.406250f, 0.402344f},
+ {0.582031f, 0.281250f, 0.589844f, 0.929688f}, {0.828125f, 0.734375f, 0.941406f, 0.714844f},
+ {0.460938f, 0.867188f, 0.449219f, 0.832031f}, {0.960938f, 0.453125f, 0.660156f, 0.398438f},
+ {0.027344f, 0.757812f, 0.234375f, 0.230469f}, {0.742188f, 0.972656f, 0.730469f, 0.468750f},
+ {0.488281f, 0.429688f, 0.128906f, 0.640625f}, {0.839844f, 0.722656f, 0.968750f, 0.960938f},
+ {0.558594f, 0.484375f, 0.664062f, 0.742188f}, {0.039062f, 0.964844f, 0.894531f, 0.390625f},
+ {0.812500f, 0.753906f, 0.183594f, 0.503906f}, {0.335938f, 0.281250f, 0.417969f, 0.757812f},
+ {0.441406f, 0.035156f, 0.726562f, 0.878906f}, {0.019531f, 0.496094f, 0.347656f, 0.269531f},
+ {0.921875f, 0.777344f, 0.867188f, 0.175781f}, {0.679688f, 0.859375f, 0.074219f, 0.605469f},
+ {0.355469f, 0.242188f, 0.449219f, 0.433594f}, {0.175781f, 0.363281f, 0.656250f, 0.765625f},
+ {0.515625f, 0.898438f, 0.003906f, 0.246094f}, {0.613281f, 0.152344f, 0.468750f, 0.894531f},
+ {0.386719f, 0.402344f, 0.523438f, 0.566406f}, {0.066406f, 0.613281f, 0.062500f, 0.988281f},
+ {0.765625f, 0.347656f, 0.390625f, 0.449219f}, {0.851562f, 0.843750f, 0.203125f, 0.875000f},
+ {0.054688f, 0.445312f, 0.441406f, 0.750000f}, {0.929688f, 0.992188f, 0.644531f, 0.937500f},
+ {0.769531f, 0.554688f, 0.000000f, 0.597656f}, {0.632812f, 0.234375f, 0.132812f, 0.101562f},
+ {0.367188f, 0.691406f, 0.867188f, 0.347656f}, {0.425781f, 0.125000f, 0.632812f, 0.261719f},
+ {0.183594f, 0.613281f, 0.968750f, 0.691406f}, {0.285156f, 0.250000f, 0.078125f, 0.929688f},
+ {0.917969f, 0.320312f, 0.292969f, 0.039062f}, {0.347656f, 0.644531f, 0.800781f, 0.269531f},
+ {0.851562f, 0.539062f, 0.019531f, 0.945312f}, {0.515625f, 0.882812f, 0.359375f, 0.070312f},
+ {0.218750f, 0.050781f, 0.277344f, 0.886719f}, {0.898438f, 0.242188f, 0.714844f, 0.019531f},
+ {0.558594f, 0.441406f, 0.062500f, 0.773438f}, {0.250000f, 0.964844f, 0.390625f, 0.902344f},
+ {0.820312f, 0.343750f, 0.226562f, 0.265625f}, {0.343750f, 0.003906f, 0.972656f, 0.832031f},
+ {0.757812f, 0.753906f, 0.484375f, 0.316406f}, {0.507812f, 0.234375f, 0.808594f, 0.554688f},
+ {0.859375f, 0.410156f, 0.347656f, 0.203125f}, {0.425781f, 0.503906f, 0.140625f, 0.062500f},
+ {0.687500f, 0.140625f, 0.496094f, 0.601562f}, {0.292969f, 0.582031f, 0.996094f, 0.093750f},
+ {0.828125f, 0.386719f, 0.707031f, 0.300781f}, {0.398438f, 0.980469f, 0.578125f, 0.859375f},
+ {0.042969f, 0.496094f, 0.441406f, 0.500000f}, {0.320312f, 0.609375f, 0.777344f, 0.550781f},
+ {0.601562f, 0.304688f, 0.945312f, 0.089844f}, {0.851562f, 0.093750f, 0.269531f, 0.234375f},
+ {0.492188f, 0.988281f, 0.753906f, 0.953125f}, {0.792969f, 0.332031f, 0.175781f, 0.847656f},
+ {0.089844f, 0.843750f, 0.726562f, 0.710938f}, {0.183594f, 0.082031f, 0.277344f, 0.246094f},
+ {0.476562f, 0.714844f, 0.566406f, 0.039062f}, {0.925781f, 0.187500f, 0.835938f, 0.878906f},
+ {0.035156f, 0.109375f, 0.214844f, 0.691406f}, {0.695312f, 0.464844f, 0.621094f, 0.007812f},
+ {0.949219f, 0.023438f, 0.968750f, 0.472656f}, {0.136719f, 0.558594f, 0.800781f, 0.769531f},
+ {0.773438f, 0.410156f, 0.679688f, 0.066406f}, {0.519531f, 0.816406f, 0.320312f, 0.644531f},
+ {0.683594f, 0.066406f, 0.171875f, 0.296875f}, {0.867188f, 0.253906f, 0.820312f, 0.125000f},
+ {0.386719f, 0.523438f, 0.054688f, 0.562500f}, {0.332031f, 0.156250f, 0.601562f, 0.863281f},
+ {0.648438f, 0.851562f, 0.796875f, 0.281250f}, {0.214844f, 0.644531f, 0.269531f, 0.425781f},
+ {0.417969f, 0.023438f, 0.390625f, 0.140625f}, {0.917969f, 0.132812f, 0.082031f, 0.902344f},
+ {0.617188f, 0.664062f, 0.496094f, 0.093750f}, {0.101562f, 0.578125f, 0.589844f, 0.207031f},
+ {0.996094f, 0.222656f, 0.015625f, 0.414062f}, {0.199219f, 0.996094f, 0.949219f, 0.824219f},
+ {0.398438f, 0.316406f, 0.757812f, 0.480469f}, {0.605469f, 0.550781f, 0.562500f, 0.929688f},
+ {0.246094f, 0.085938f, 0.300781f, 0.855469f}, {0.832031f, 0.648438f, 0.363281f, 0.128906f},
+ {0.914062f, 0.757812f, 0.914062f, 0.699219f}, {0.691406f, 0.566406f, 0.828125f, 0.410156f},
+ {0.980469f, 0.292969f, 0.121094f, 0.007812f}, {0.457031f, 0.742188f, 0.949219f, 0.730469f},
+ {0.648438f, 0.914062f, 0.714844f, 0.148438f}, {0.257812f, 0.511719f, 0.566406f, 0.503906f},
+ {0.527344f, 0.082031f, 0.105469f, 0.375000f}, {0.398438f, 0.707031f, 0.285156f, 0.019531f},
+ {0.300781f, 0.183594f, 0.359375f, 0.230469f}, {0.222656f, 0.355469f, 0.933594f, 0.867188f},
+ {0.867188f, 0.500000f, 0.476562f, 0.167969f}, {0.964844f, 0.945312f, 0.257812f, 0.636719f},
+ {0.683594f, 0.386719f, 0.171875f, 0.535156f}, {0.601562f, 0.074219f, 0.710938f, 0.781250f},
+ {0.484375f, 0.785156f, 0.414062f, 0.359375f}, {0.074219f, 0.214844f, 0.503906f, 0.742188f},
+ {0.167969f, 0.113281f, 0.144531f, 0.609375f}, {0.640625f, 0.378906f, 0.746094f, 0.800781f},
+ {0.304688f, 0.949219f, 0.851562f, 0.507812f}, {0.750000f, 0.507812f, 0.613281f, 0.339844f},
+ {0.082031f, 0.671875f, 0.894531f, 0.656250f}, {0.660156f, 0.195312f, 0.324219f, 0.410156f},
+ {0.414062f, 0.281250f, 0.824219f, 0.722656f}, {0.703125f, 0.640625f, 0.085938f, 0.167969f},
+ {0.597656f, 0.464844f, 0.718750f, 0.437500f}, {0.140625f, 0.578125f, 0.253906f, 0.863281f},
+ {0.207031f, 0.667969f, 0.546875f, 0.921875f}, {0.968750f, 0.042969f, 0.679688f, 0.667969f},
+ {0.531250f, 0.875000f, 0.218750f, 0.410156f}, {0.117188f, 0.761719f, 0.000000f, 0.164062f},
+ {0.488281f, 0.179688f, 0.894531f, 0.800781f}, {0.562500f, 0.660156f, 0.238281f, 0.722656f},
+ {0.789062f, 0.265625f, 0.050781f, 0.125000f}, {0.664062f, 0.007812f, 0.835938f, 0.992188f},
+ {0.996094f, 0.894531f, 0.410156f, 0.375000f}, {0.753906f, 0.566406f, 0.636719f, 0.757812f},
+ {0.234375f, 0.804688f, 0.550781f, 0.437500f}, {0.562500f, 0.046875f, 0.082031f, 0.074219f},
+ {0.343750f, 0.757812f, 0.359375f, 0.597656f}, {0.726562f, 0.429688f, 0.863281f, 0.480469f},
+ {0.257812f, 0.875000f, 0.136719f, 0.753906f}, {0.816406f, 0.261719f, 0.437500f, 0.429688f},
+ {0.332031f, 0.390625f, 0.089844f, 0.273438f}, {0.382812f, 0.742188f, 0.351562f, 0.621094f},
+ {0.222656f, 0.890625f, 0.027344f, 0.839844f}, {0.890625f, 0.093750f, 0.246094f, 0.988281f},
+ {0.011719f, 0.968750f, 0.539062f, 0.203125f}, {0.316406f, 0.484375f, 0.074219f, 0.363281f},
+ {0.238281f, 0.187500f, 0.500000f, 0.496094f}, {0.105469f, 0.660156f, 0.996094f, 0.796875f},
+ {0.777344f, 0.386719f, 0.414062f, 0.167969f}, {0.531250f, 0.589844f, 0.308594f, 0.730469f},
+ {0.976562f, 0.347656f, 0.871094f, 0.027344f}, {0.125000f, 0.261719f, 0.468750f, 0.691406f},
+ {0.710938f, 0.910156f, 0.703125f, 0.531250f}, {0.468750f, 0.812500f, 0.328125f, 0.250000f},
+ {0.277344f, 0.441406f, 0.765625f, 0.667969f}, {0.535156f, 0.375000f, 0.917969f, 0.972656f},
+ {0.648438f, 0.074219f, 0.292969f, 0.324219f}, {0.785156f, 0.687500f, 0.156250f, 0.710938f},
+ {0.304688f, 0.136719f, 0.484375f, 0.011719f}, {0.089844f, 0.714844f, 0.113281f, 0.652344f},
+ {0.769531f, 0.453125f, 0.992188f, 0.214844f}, {0.437500f, 0.199219f, 0.703125f, 0.328125f},
+ {0.003906f, 0.980469f, 0.171875f, 0.488281f}, {0.300781f, 0.476562f, 0.410156f, 0.621094f},
+ {0.218750f, 0.695312f, 0.218750f, 0.843750f}, {0.140625f, 0.058594f, 0.652344f, 0.222656f},
+ {0.347656f, 0.199219f, 0.320312f, 0.335938f}, {0.945312f, 0.652344f, 0.863281f, 0.652344f},
+ {0.703125f, 0.312500f, 0.976562f, 0.808594f}, {0.171875f, 0.585938f, 0.753906f, 0.292969f},
+ {0.906250f, 0.863281f, 0.808594f, 0.683594f}, {0.082031f, 0.781250f, 0.582031f, 0.488281f},
+ {0.562500f, 0.007812f, 0.691406f, 0.988281f}, {0.734375f, 0.886719f, 0.332031f, 0.406250f},
+ {0.000000f, 0.730469f, 0.550781f, 0.894531f}, {0.234375f, 0.460938f, 0.894531f, 0.117188f},
+ {0.761719f, 0.929688f, 0.207031f, 0.492188f}, {0.957031f, 0.683594f, 0.933594f, 0.441406f},
+ {0.386719f, 0.828125f, 0.644531f, 0.152344f}, {0.718750f, 0.593750f, 0.246094f, 0.394531f},
+ {0.011719f, 0.308594f, 0.484375f, 0.242188f}, {0.839844f, 0.851562f, 0.113281f, 0.972656f},
+ {0.359375f, 0.765625f, 0.195312f, 0.199219f}, {0.957031f, 0.406250f, 0.933594f, 0.531250f},
+ {0.175781f, 0.117188f, 0.535156f, 0.054688f}, {0.039062f, 0.863281f, 0.648438f, 0.992188f},
+ {0.285156f, 0.996094f, 0.152344f, 0.648438f}, {0.898438f, 0.074219f, 0.410156f, 0.117188f},
+ {0.375000f, 0.808594f, 0.929688f, 0.507812f}, {0.777344f, 0.347656f, 0.761719f, 0.277344f},
+ {0.007812f, 0.937500f, 0.617188f, 0.757812f}, {0.339844f, 0.433594f, 0.816406f, 0.972656f},
+ {0.718750f, 0.085938f, 0.328125f, 0.621094f}, {0.957031f, 0.921875f, 0.542969f, 0.250000f},
+ {0.214844f, 0.460938f, 0.132812f, 0.421875f}, {0.128906f, 0.734375f, 0.691406f, 0.882812f},
+ {0.277344f, 0.398438f, 0.195312f, 0.312500f}, {0.011719f, 0.179688f, 0.011719f, 0.667969f},
+ {0.406250f, 0.476562f, 0.960938f, 0.566406f}, {0.140625f, 0.644531f, 0.796875f, 0.175781f},
+ {0.898438f, 0.277344f, 0.222656f, 0.343750f}, {0.433594f, 0.156250f, 0.675781f, 0.980469f},
+ {0.613281f, 0.664062f, 0.601562f, 0.125000f}, {0.117188f, 0.539062f, 0.953125f, 0.546875f},
+ {0.511719f, 0.820312f, 0.722656f, 0.914062f}, {0.859375f, 0.625000f, 0.902344f, 0.156250f},
+ {0.593750f, 0.355469f, 0.464844f, 0.332031f}, {0.421875f, 0.167969f, 0.871094f, 0.101562f},
+ {0.730469f, 0.707031f, 0.714844f, 0.582031f}, {0.996094f, 0.613281f, 0.375000f, 0.746094f},
+ {0.156250f, 0.328125f, 0.769531f, 0.039062f}, {0.625000f, 0.929688f, 0.628906f, 0.949219f},
+ {0.449219f, 0.113281f, 0.910156f, 0.625000f}, {0.257812f, 0.800781f, 0.562500f, 0.339844f},
+ {0.046875f, 0.054688f, 0.031250f, 0.996094f}, {0.792969f, 0.496094f, 0.160156f, 0.195312f},
+ {0.324219f, 0.562500f, 0.929688f, 0.847656f}, {0.175781f, 0.203125f, 0.210938f, 0.789062f},
+ {0.863281f, 0.304688f, 0.847656f, 0.468750f}, {0.746094f, 0.925781f, 0.070312f, 0.609375f},
+ {0.136719f, 0.843750f, 0.675781f, 0.156250f}, {0.886719f, 0.605469f, 0.390625f, 0.562500f},
+ {0.519531f, 0.414062f, 0.636719f, 0.113281f}, {0.710938f, 0.910156f, 0.214844f, 0.375000f},
+ {0.964844f, 0.808594f, 0.785156f, 0.531250f}, {0.128906f, 0.281250f, 0.066406f, 0.957031f},
+ {0.488281f, 0.031250f, 0.609375f, 0.816406f}, {0.750000f, 0.128906f, 0.542969f, 0.101562f},
+ {0.550781f, 0.878906f, 0.757812f, 0.281250f}, {0.886719f, 0.250000f, 0.261719f, 0.917969f},
+ {0.808594f, 0.417969f, 0.476562f, 0.585938f}, {0.585938f, 0.812500f, 0.156250f, 0.085938f},
+ {0.011719f, 0.027344f, 0.042969f, 0.968750f}, {0.445312f, 0.941406f, 0.515625f, 0.429688f},
+ {0.671875f, 0.136719f, 0.179688f, 0.136719f}, {0.812500f, 0.640625f, 0.230469f, 0.832031f},
+ {0.480469f, 0.433594f, 0.070312f, 0.562500f}, {0.144531f, 0.281250f, 0.789062f, 0.031250f},
+ {0.320312f, 0.179688f, 0.023438f, 0.304688f}, {0.886719f, 0.558594f, 0.757812f, 0.234375f},
+ {0.445312f, 0.347656f, 0.371094f, 0.968750f}, {0.121094f, 0.039062f, 0.585938f, 0.863281f},
+ {0.816406f, 0.421875f, 0.054688f, 0.648438f}, {0.578125f, 0.160156f, 0.992188f, 0.089844f},
+ {0.429688f, 0.722656f, 0.402344f, 0.574219f}, {0.148438f, 0.097656f, 0.562500f, 0.835938f},
+ {0.613281f, 0.035156f, 0.785156f, 0.117188f}, {0.468750f, 0.605469f, 0.449219f, 0.296875f},
+ {0.851562f, 0.800781f, 0.035156f, 0.609375f}, {0.535156f, 0.523438f, 0.367188f, 0.789062f},
+ {0.796875f, 0.152344f, 0.863281f, 0.238281f}, {0.667969f, 0.300781f, 0.585938f, 0.343750f},
+ {0.074219f, 0.722656f, 0.042969f, 0.714844f}, {0.574219f, 0.199219f, 0.300781f, 0.039062f},
+ {0.648438f, 0.269531f, 0.089844f, 0.464844f}, {0.847656f, 0.621094f, 0.402344f, 0.367188f},
+ {0.164062f, 0.527344f, 0.457031f, 0.003906f}, {0.617188f, 0.328125f, 0.742188f, 0.566406f},
+ {0.367188f, 0.835938f, 0.972656f, 0.195312f}, {0.468750f, 0.136719f, 0.351562f, 0.695312f},
+ {0.542969f, 0.679688f, 0.496094f, 0.480469f}, {0.695312f, 0.941406f, 0.855469f, 0.046875f},
+ {0.933594f, 0.234375f, 0.312500f, 0.902344f}, {0.640625f, 0.527344f, 0.429688f, 0.804688f},
+ {0.832031f, 0.375000f, 0.500000f, 0.640625f}, {0.046875f, 0.949219f, 0.066406f, 0.292969f},
+ {0.984375f, 0.460938f, 0.390625f, 0.824219f}, {0.675781f, 0.066406f, 0.179688f, 0.058594f},
+ {0.175781f, 0.992188f, 0.531250f, 0.664062f}, {0.785156f, 0.230469f, 0.660156f, 0.511719f},
+ {0.089844f, 0.792969f, 0.300781f, 0.242188f}, {0.652344f, 0.292969f, 0.121094f, 0.699219f},
+ {0.480469f, 0.535156f, 0.195312f, 0.433594f}, {0.363281f, 0.777344f, 0.933594f, 0.894531f},
+ {0.550781f, 0.011719f, 0.273438f, 0.265625f}, {0.886719f, 0.871094f, 0.144531f, 0.410156f},
+ {0.937500f, 0.679688f, 0.699219f, 0.515625f}, {0.183594f, 0.214844f, 0.218750f, 0.097656f},
+ {0.855469f, 0.988281f, 0.777344f, 0.457031f}, {0.566406f, 0.761719f, 0.519531f, 0.593750f},
+ {0.664062f, 0.394531f, 0.593750f, 0.308594f}, {0.960938f, 0.695312f, 0.113281f, 0.070312f},
+ {0.007812f, 0.101562f, 0.425781f, 0.359375f}, {0.242188f, 0.742188f, 0.546875f, 0.042969f},
+ {0.355469f, 0.480469f, 0.250000f, 0.921875f}, {0.433594f, 0.187500f, 0.828125f, 0.859375f},
+ {0.035156f, 0.000000f, 0.894531f, 0.789062f}, {0.218750f, 0.343750f, 0.535156f, 0.285156f},
+ {0.558594f, 0.523438f, 0.433594f, 0.734375f}, {0.371094f, 0.625000f, 0.273438f, 0.031250f},
+ {0.652344f, 0.835938f, 0.875000f, 0.171875f}, {0.851562f, 0.375000f, 0.332031f, 0.550781f},
+ {0.062500f, 0.605469f, 0.968750f, 0.371094f}, {0.417969f, 0.539062f, 0.031250f, 0.460938f},
+ {0.097656f, 0.957031f, 0.820312f, 0.761719f}, {0.500000f, 0.750000f, 0.601562f, 0.191406f},
+ {0.242188f, 0.472656f, 0.371094f, 0.535156f}, {0.757812f, 0.269531f, 0.660156f, 0.625000f},
+ {0.343750f, 0.394531f, 0.453125f, 0.730469f}, {0.613281f, 0.535156f, 0.914062f, 0.332031f},
+ {0.265625f, 0.085938f, 0.410156f, 0.097656f}, {0.410156f, 0.835938f, 0.980469f, 0.757812f},
+ {0.832031f, 0.664062f, 0.484375f, 0.812500f}, {0.644531f, 0.128906f, 0.664062f, 0.593750f},
+ {0.546875f, 0.761719f, 0.109375f, 0.191406f}, {0.207031f, 0.503906f, 0.304688f, 0.007812f},
+ {0.667969f, 0.898438f, 0.812500f, 0.300781f}, {0.253906f, 0.230469f, 0.687500f, 0.921875f},
+ {0.976562f, 0.468750f, 0.339844f, 0.687500f}, {0.519531f, 0.554688f, 0.003906f, 0.468750f},
+ {0.769531f, 0.359375f, 0.632812f, 0.746094f}, {0.230469f, 0.929688f, 0.289062f, 0.933594f},
+ {0.109375f, 0.695312f, 0.691406f, 0.367188f}, {0.328125f, 0.242188f, 0.246094f, 0.484375f},
+ {0.984375f, 0.429688f, 0.984375f, 0.082031f}, {0.242188f, 0.910156f, 0.464844f, 0.582031f},
+ {0.480469f, 0.488281f, 0.199219f, 0.957031f}, {0.300781f, 0.558594f, 0.835938f, 0.816406f},
+ {0.437500f, 0.023438f, 0.957031f, 0.214844f}, {0.933594f, 0.687500f, 0.527344f, 0.859375f},
+ {0.269531f, 0.800781f, 0.179688f, 0.511719f}, {0.039062f, 0.222656f, 0.871094f, 0.921875f},
+ {0.894531f, 0.062500f, 0.628906f, 0.074219f}, {0.746094f, 0.546875f, 0.277344f, 0.820312f},
+ {0.863281f, 0.343750f, 0.589844f, 0.265625f}, {0.335938f, 0.855469f, 0.105469f, 0.140625f},
+ {0.078125f, 0.109375f, 0.707031f, 0.515625f}, {0.515625f, 0.722656f, 0.617188f, 0.226562f},
+ {0.292969f, 0.886719f, 0.878906f, 0.027344f}, {0.214844f, 0.003906f, 0.937500f, 0.699219f},
+ {0.554688f, 0.601562f, 0.757812f, 0.402344f}, {0.390625f, 0.324219f, 0.281250f, 0.207031f},
+ {0.304688f, 0.128906f, 0.039062f, 0.957031f}, {0.960938f, 0.500000f, 0.808594f, 0.367188f},
+ {0.265625f, 0.031250f, 0.406250f, 0.808594f}, {0.054688f, 0.925781f, 0.613281f, 0.871094f},
+ {0.195312f, 0.429688f, 0.558594f, 0.539062f}, {0.835938f, 0.136719f, 0.828125f, 0.121094f},
+ {0.699219f, 0.242188f, 0.015625f, 0.660156f}, {0.035156f, 0.464844f, 0.480469f, 0.835938f},
+ {0.312500f, 0.554688f, 0.320312f, 0.003906f}, {0.738281f, 0.308594f, 0.093750f, 0.785156f},
+ {0.484375f, 0.621094f, 0.406250f, 0.890625f}, {0.375000f, 0.160156f, 0.957031f, 0.386719f},
+ {0.093750f, 0.882812f, 0.355469f, 0.125000f}, {0.410156f, 0.015625f, 0.644531f, 0.941406f},
+ {0.593750f, 0.597656f, 0.722656f, 0.542969f}, {0.492188f, 0.531250f, 0.984375f, 0.734375f},
+ {0.683594f, 0.265625f, 0.464844f, 0.398438f}, {0.835938f, 0.968750f, 0.035156f, 0.242188f},
+ {0.945312f, 0.761719f, 0.328125f, 0.453125f}, {0.625000f, 0.246094f, 0.730469f, 0.910156f},
+ {0.328125f, 0.078125f, 0.937500f, 0.593750f}, {0.902344f, 0.945312f, 0.015625f, 0.425781f},
+ {0.171875f, 0.433594f, 0.488281f, 0.687500f}, {0.250000f, 0.312500f, 0.804688f, 0.781250f},
+ {0.609375f, 0.781250f, 0.093750f, 0.941406f}, {0.312500f, 0.097656f, 0.687500f, 0.667969f},
+ {0.710938f, 0.160156f, 0.425781f, 0.031250f}, {0.164062f, 0.355469f, 0.945312f, 0.878906f},
+ {0.968750f, 0.628906f, 0.738281f, 0.261719f}, {0.839844f, 0.218750f, 0.296875f, 0.058594f},
+ {0.128906f, 0.902344f, 0.875000f, 0.933594f}, {0.035156f, 0.726562f, 0.113281f, 0.207031f},
+ {0.996094f, 0.335938f, 0.625000f, 0.464844f}, {0.531250f, 0.984375f, 0.277344f, 0.660156f},
+ {0.066406f, 0.589844f, 0.148438f, 0.367188f}, {0.363281f, 0.242188f, 0.867188f, 0.707031f},
+ {0.945312f, 0.953125f, 0.437500f, 0.527344f}, {0.042969f, 0.292969f, 0.535156f, 0.828125f},
+ {0.492188f, 0.617188f, 0.175781f, 0.730469f}, {0.332031f, 0.785156f, 0.886719f, 0.351562f},
+ {0.875000f, 0.984375f, 0.226562f, 0.179688f}, {0.062500f, 0.269531f, 0.839844f, 0.039062f},
+ {0.292969f, 0.875000f, 0.960938f, 0.421875f}, {0.917969f, 0.175781f, 0.167969f, 0.867188f},
+ {0.714844f, 0.324219f, 0.753906f, 0.000000f}, {0.593750f, 0.582031f, 0.523438f, 0.671875f},
+ {0.421875f, 0.089844f, 0.117188f, 0.910156f}, {0.136719f, 0.652344f, 0.730469f, 0.402344f},
+ {0.750000f, 0.363281f, 0.335938f, 0.179688f}, {0.906250f, 0.824219f, 0.660156f, 0.550781f},
+ {0.199219f, 0.976562f, 0.128906f, 0.128906f}, {0.101562f, 0.125000f, 0.714844f, 0.664062f},
+ {0.800781f, 0.378906f, 0.257812f, 0.296875f}, {0.515625f, 0.890625f, 0.027344f, 0.773438f},
+ {0.414062f, 0.605469f, 0.082031f, 0.351562f}, {0.070312f, 0.765625f, 0.804688f, 0.585938f},
+ {0.187500f, 0.433594f, 0.910156f, 0.968750f}, {0.796875f, 0.031250f, 0.468750f, 0.726562f},
+ {0.457031f, 0.589844f, 0.156250f, 0.410156f}, {0.160156f, 0.312500f, 0.257812f, 0.949219f},
+ {0.718750f, 0.785156f, 0.027344f, 0.363281f}, {0.773438f, 0.210938f, 0.554688f, 0.863281f},
+ {0.476562f, 0.683594f, 0.335938f, 0.488281f}, {0.007812f, 0.765625f, 0.839844f, 0.769531f},
+ {0.707031f, 0.859375f, 0.488281f, 0.605469f}, {0.445312f, 0.406250f, 0.230469f, 0.082031f},
+ {0.566406f, 0.675781f, 0.746094f, 0.464844f}, {0.757812f, 0.582031f, 0.957031f, 0.023438f},
+ {0.925781f, 0.843750f, 0.066406f, 0.183594f}, {0.281250f, 0.367188f, 0.429688f, 0.976562f},
+ {0.125000f, 0.957031f, 0.644531f, 0.324219f}, {0.421875f, 0.746094f, 0.757812f, 0.214844f},
+ {0.675781f, 0.410156f, 0.976562f, 0.933594f}, {0.074219f, 0.914062f, 0.851562f, 0.558594f},
+ {0.617188f, 0.070312f, 0.667969f, 0.238281f}, {0.910156f, 0.457031f, 0.246094f, 0.742188f},
+ {0.285156f, 0.335938f, 0.824219f, 0.636719f}, {0.722656f, 0.832031f, 0.007812f, 0.828125f},
+ {0.816406f, 0.949219f, 0.289062f, 0.273438f}, {0.925781f, 0.152344f, 0.148438f, 0.675781f},
+ {0.085938f, 0.359375f, 0.789062f, 0.187500f}, {0.277344f, 0.640625f, 0.585938f, 0.507812f},
+ {0.164062f, 0.867188f, 0.105469f, 0.640625f}, {0.457031f, 0.570312f, 0.183594f, 0.050781f},
+ {0.789062f, 0.675781f, 0.371094f, 0.203125f}, {0.050781f, 0.164062f, 0.675781f, 0.996094f},
+ {0.726562f, 0.718750f, 0.152344f, 0.316406f}, {0.992188f, 0.210938f, 0.578125f, 0.066406f},
+ {0.464844f, 0.894531f, 0.386719f, 0.242188f}, {0.792969f, 0.500000f, 0.203125f, 0.140625f},
+ {0.925781f, 0.687500f, 0.527344f, 0.414062f}, {0.644531f, 0.062500f, 0.132812f, 0.824219f},
+ {0.289062f, 0.847656f, 0.234375f, 0.492188f}, {0.390625f, 0.570312f, 0.054688f, 0.394531f},
+ {0.554688f, 0.042969f, 0.546875f, 0.890625f}, {0.917969f, 0.796875f, 0.695312f, 0.589844f},
+ {0.203125f, 0.207031f, 0.839844f, 0.273438f}, {0.773438f, 0.484375f, 0.355469f, 0.960938f},
+ {0.699219f, 0.035156f, 0.593750f, 0.152344f}, {0.171875f, 0.410156f, 0.218750f, 0.050781f},
+ {0.289062f, 0.824219f, 0.921875f, 0.406250f}, {0.851562f, 0.078125f, 0.765625f, 0.261719f},
+ {0.781250f, 0.703125f, 0.066406f, 0.457031f}, {0.105469f, 0.000000f, 0.460938f, 0.546875f},
+ {0.695312f, 0.140625f, 0.734375f, 0.792969f}, {0.187500f, 0.660156f, 0.515625f, 0.632812f},
+ {0.636719f, 0.433594f, 0.085938f, 0.257812f}, {0.402344f, 0.500000f, 0.425781f, 0.562500f},
+ {0.003906f, 0.019531f, 0.890625f, 0.214844f}, {0.878906f, 0.953125f, 0.816406f, 0.156250f},
+ {0.503906f, 0.847656f, 0.058594f, 0.835938f}, {0.062500f, 0.746094f, 0.617188f, 0.738281f},
+ {0.839844f, 0.058594f, 0.902344f, 0.312500f}, {0.691406f, 0.171875f, 0.496094f, 0.640625f},
+ {0.390625f, 0.417969f, 0.378906f, 0.433594f}, {0.593750f, 0.742188f, 0.578125f, 0.945312f},
+ {0.734375f, 0.484375f, 0.917969f, 0.722656f}, {0.316406f, 0.289062f, 0.667969f, 0.113281f},
+ {0.675781f, 0.164062f, 0.429688f, 0.460938f}, {0.972656f, 0.984375f, 0.371094f, 0.628906f},
+ {0.628906f, 0.257812f, 0.218750f, 0.015625f}, {0.242188f, 0.656250f, 0.773438f, 0.320312f},
+ {0.589844f, 0.957031f, 0.984375f, 0.777344f}, {0.957031f, 0.492188f, 0.402344f, 0.550781f},
+ {0.359375f, 0.144531f, 0.726562f, 0.105469f}, {0.859375f, 0.425781f, 0.203125f, 0.582031f},
+ {0.113281f, 0.921875f, 0.128906f, 0.261719f}, {0.933594f, 0.253906f, 0.628906f, 0.144531f},
+ {0.812500f, 0.570312f, 0.992188f, 0.890625f}, {0.148438f, 0.179688f, 0.093750f, 0.308594f},
+ {0.894531f, 0.734375f, 0.160156f, 0.734375f}, {0.339844f, 0.269531f, 0.343750f, 0.628906f},
+ {0.621094f, 0.089844f, 0.500000f, 0.394531f}, {0.523438f, 0.644531f, 0.906250f, 0.773438f},
+ {0.796875f, 0.507812f, 0.203125f, 0.480469f}, {0.582031f, 0.042969f, 0.367188f, 0.710938f},
+};
+
+#endif /* __EEVEE_LUT_H__ */
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c b/source/blender/draw/engines/eevee/eevee_materials.c
new file mode 100644
index 00000000000..a4055cf8eea
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -0,0 +1,1593 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_materials.c
+ * \ingroup draw_engine
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_dynstr.h"
+#include "BLI_ghash.h"
+#include "BLI_alloca.h"
+#include "BLI_rand.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_particle.h"
+#include "BKE_paint.h"
+#include "BKE_pbvh.h"
+
+#include "DNA_world_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_view3d_types.h"
+
+#include "GPU_material.h"
+
+#include "eevee_engine.h"
+#include "eevee_lut.h"
+#include "eevee_private.h"
+
+/* *********** STATIC *********** */
+static struct {
+ char *frag_shader_lib;
+ char *volume_shader_lib;
+
+ struct GPUShader *default_prepass_sh;
+ struct GPUShader *default_prepass_clip_sh;
+ struct GPUShader *default_lit[VAR_MAT_MAX];
+ struct GPUShader *default_background;
+ struct GPUShader *update_noise_sh;
+
+ /* 64*64 array texture containing all LUTs and other utilitarian arrays.
+ * Packing enables us to same precious textures slots. */
+ struct GPUTexture *util_tex;
+ struct GPUTexture *noise_tex;
+
+ unsigned int sss_count;
+
+ float alpha_hash_offset;
+ float noise_offsets[3];
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_lamps_lib_glsl[];
+extern char datatoc_lightprobe_lib_glsl[];
+extern char datatoc_ambient_occlusion_lib_glsl[];
+extern char datatoc_prepass_frag_glsl[];
+extern char datatoc_prepass_vert_glsl[];
+extern char datatoc_default_frag_glsl[];
+extern char datatoc_default_world_frag_glsl[];
+extern char datatoc_ltc_lib_glsl[];
+extern char datatoc_bsdf_lut_frag_glsl[];
+extern char datatoc_btdf_lut_frag_glsl[];
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_bsdf_direct_lib_glsl[];
+extern char datatoc_bsdf_sampling_lib_glsl[];
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_irradiance_lib_glsl[];
+extern char datatoc_octahedron_lib_glsl[];
+extern char datatoc_lit_surface_frag_glsl[];
+extern char datatoc_lit_surface_vert_glsl[];
+extern char datatoc_raytrace_lib_glsl[];
+extern char datatoc_ssr_lib_glsl[];
+extern char datatoc_shadow_vert_glsl[];
+extern char datatoc_lightprobe_geom_glsl[];
+extern char datatoc_lightprobe_vert_glsl[];
+extern char datatoc_background_vert_glsl[];
+extern char datatoc_update_noise_frag_glsl[];
+extern char datatoc_volumetric_vert_glsl[];
+extern char datatoc_volumetric_geom_glsl[];
+extern char datatoc_volumetric_frag_glsl[];
+extern char datatoc_volumetric_lib_glsl[];
+
+extern Material defmaterial;
+extern GlobalsUboStorage ts;
+
+/* *********** FUNCTIONS *********** */
+
+#if 0 /* Used only to generate the LUT values */
+static struct GPUTexture *create_ggx_lut_texture(int UNUSED(w), int UNUSED(h))
+{
+ struct GPUTexture *tex;
+ struct GPUFrameBuffer *fb = NULL;
+ static float samples_ct = 8192.0f;
+ static float inv_samples_ct = 1.0f / 8192.0f;
+
+ char *lib_str = BLI_string_joinN(
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_sampling_lib_glsl);
+
+ struct GPUShader *sh = DRW_shader_create_with_lib(
+ datatoc_lightprobe_vert_glsl, datatoc_lightprobe_geom_glsl, datatoc_bsdf_lut_frag_glsl, lib_str,
+ "#define HAMMERSLEY_SIZE 8192\n"
+ "#define BRDF_LUT_SIZE 64\n"
+ "#define NOISE_SIZE 64\n");
+
+ DRWPass *pass = DRW_pass_create("LightProbe Filtering", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
+ DRW_shgroup_uniform_float(grp, "sampleCount", &samples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "invSampleCount", &inv_samples_ct, 1);
+ DRW_shgroup_uniform_texture(grp, "texHammersley", e_data.hammersley);
+ DRW_shgroup_uniform_texture(grp, "texJitter", e_data.jitter);
+
+ struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+ DRW_shgroup_call_add(grp, geom, NULL);
+
+ float *texels = MEM_mallocN(sizeof(float[2]) * w * h, "lut");
+
+ tex = DRW_texture_create_2D(w, h, GPU_RG16F, DRW_TEX_FILTER, (float *)texels);
+
+ DRWFboTexture tex_filter = {&tex, GPU_RG16F, DRW_TEX_FILTER};
+ GPU_framebuffer_init(&fb, &draw_engine_eevee_type, w, h, &tex_filter, 1);
+
+ GPU_framebuffer_bind(fb);
+ DRW_draw_pass(pass);
+
+ float *data = MEM_mallocN(sizeof(float[3]) * w * h, "lut");
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
+ glReadPixels(0, 0, w, h, GL_RGB, GL_FLOAT, data);
+
+ printf("{");
+ for (int i = 0; i < w*h * 3; i+=3) {
+ printf("%ff, %ff, ", data[i], data[i+1]); i+=3;
+ printf("%ff, %ff, ", data[i], data[i+1]); i+=3;
+ printf("%ff, %ff, ", data[i], data[i+1]); i+=3;
+ printf("%ff, %ff, \n", data[i], data[i+1]);
+ }
+ printf("}");
+
+ MEM_freeN(texels);
+ MEM_freeN(data);
+
+ return tex;
+}
+
+static struct GPUTexture *create_ggx_refraction_lut_texture(int w, int h)
+{
+ struct GPUTexture *tex;
+ struct GPUTexture *hammersley = create_hammersley_sample_texture(8192);
+ struct GPUFrameBuffer *fb = NULL;
+ static float samples_ct = 8192.0f;
+ static float a2 = 0.0f;
+ static float inv_samples_ct = 1.0f / 8192.0f;
+
+ char *frag_str = BLI_string_joinN(
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_sampling_lib_glsl,
+ datatoc_btdf_lut_frag_glsl);
+
+ struct GPUShader *sh = DRW_shader_create_fullscreen(frag_str,
+ "#define HAMMERSLEY_SIZE 8192\n"
+ "#define BRDF_LUT_SIZE 64\n"
+ "#define NOISE_SIZE 64\n"
+ "#define LUT_SIZE 64\n");
+
+ MEM_freeN(frag_str);
+
+ DRWPass *pass = DRW_pass_create("LightProbe Filtering", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
+ DRW_shgroup_uniform_float(grp, "a2", &a2, 1);
+ DRW_shgroup_uniform_float(grp, "sampleCount", &samples_ct, 1);
+ DRW_shgroup_uniform_float(grp, "invSampleCount", &inv_samples_ct, 1);
+ DRW_shgroup_uniform_texture(grp, "texHammersley", hammersley);
+ DRW_shgroup_uniform_texture(grp, "utilTex", e_data.util_tex);
+
+ struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+ DRW_shgroup_call_add(grp, geom, NULL);
+
+ float *texels = MEM_mallocN(sizeof(float[2]) * w * h, "lut");
+
+ tex = DRW_texture_create_2D(w, h, GPU_R16F, DRW_TEX_FILTER, (float *)texels);
+
+ DRWFboTexture tex_filter = {&tex, GPU_R16F, DRW_TEX_FILTER};
+ GPU_framebuffer_init(&fb, &draw_engine_eevee_type, w, h, &tex_filter, 1);
+
+ GPU_framebuffer_bind(fb);
+
+ float *data = MEM_mallocN(sizeof(float[3]) * w * h, "lut");
+
+ float inc = 1.0f / 31.0f;
+ float roughness = 1e-8f - inc;
+ FILE *f = BLI_fopen("btdf_split_sum_ggx.h", "w");
+ fprintf(f, "static float btdf_split_sum_ggx[32][64 * 64] = {\n");
+ do {
+ roughness += inc;
+ CLAMP(roughness, 1e-4f, 1.0f);
+ a2 = powf(roughness, 4.0f);
+ DRW_draw_pass(pass);
+
+ GPU_framebuffer_read_data(0, 0, w, h, 3, 0, data);
+
+#if 1
+ fprintf(f, "\t{\n\t\t");
+ for (int i = 0; i < w*h * 3; i+=3) {
+ fprintf(f, "%ff,", data[i]);
+ if (((i/3)+1) % 12 == 0) fprintf(f, "\n\t\t");
+ else fprintf(f, " ");
+ }
+ fprintf(f, "\n\t},\n");
+#else
+ for (int i = 0; i < w*h * 3; i+=3) {
+ if (data[i] < 0.01) printf(" ");
+ else if (data[i] < 0.3) printf(".");
+ else if (data[i] < 0.6) printf("+");
+ else if (data[i] < 0.9) printf("%%");
+ else printf("#");
+ if ((i/3+1) % 64 == 0) printf("\n");
+ }
+#endif
+
+ } while (roughness < 1.0f);
+ fprintf(f, "\n};\n");
+
+ fclose(f);
+
+ MEM_freeN(texels);
+ MEM_freeN(data);
+
+ return tex;
+}
+#endif
+/* XXX TODO define all shared resources in a shared place without duplication */
+struct GPUTexture *EEVEE_materials_get_util_tex(void)
+{
+ return e_data.util_tex;
+}
+
+static int eevee_material_shadow_option(int shadow_method)
+{
+ switch (shadow_method) {
+ case SHADOW_ESM: return VAR_MAT_ESM;
+ case SHADOW_VSM: return VAR_MAT_VSM;
+ default:
+ BLI_assert(!"Incorrect Shadow Method");
+ break;
+ }
+
+ return 0;
+}
+
+static char *eevee_get_defines(int options)
+{
+ char *str = NULL;
+
+ DynStr *ds = BLI_dynstr_new();
+ BLI_dynstr_appendf(ds, SHADER_DEFINES);
+
+ if ((options & VAR_MAT_MESH) != 0) {
+ BLI_dynstr_appendf(ds, "#define MESH_SHADER\n");
+ }
+ if ((options & VAR_MAT_HAIR) != 0) {
+ BLI_dynstr_appendf(ds, "#define HAIR_SHADER\n");
+ }
+ if ((options & VAR_MAT_PROBE) != 0) {
+ BLI_dynstr_appendf(ds, "#define PROBE_CAPTURE\n");
+ }
+ if ((options & VAR_MAT_FLAT) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_FLAT_NORMAL\n");
+ }
+ if ((options & VAR_MAT_CLIP) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_ALPHA_CLIP\n");
+ }
+ if ((options & VAR_MAT_SHADOW) != 0) {
+ BLI_dynstr_appendf(ds, "#define SHADOW_SHADER\n");
+ }
+ if ((options & VAR_MAT_HASH) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_ALPHA_HASH\n");
+ }
+ if ((options & VAR_MAT_BLEND) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_ALPHA_BLEND\n");
+ }
+ if ((options & VAR_MAT_MULT) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_MULTIPLY\n");
+ }
+ if ((options & VAR_MAT_REFRACT) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_REFRACTION\n");
+ }
+ if ((options & VAR_MAT_SSS) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_SSS\n");
+ }
+ if ((options & VAR_MAT_SSSALBED) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_SSS_ALBEDO\n");
+ }
+ if ((options & VAR_MAT_TRANSLUC) != 0) {
+ BLI_dynstr_appendf(ds, "#define USE_TRANSLUCENCY\n");
+ }
+ if ((options & VAR_MAT_VSM) != 0) {
+ BLI_dynstr_appendf(ds, "#define SHADOW_VSM\n");
+ }
+ if ((options & VAR_MAT_ESM) != 0) {
+ BLI_dynstr_appendf(ds, "#define SHADOW_ESM\n");
+ }
+ if (((options & VAR_MAT_VOLUME) != 0) && ((options & VAR_MAT_BLEND) != 0)) {
+ BLI_dynstr_appendf(ds, "#define USE_ALPHA_BLEND_VOLUMETRICS\n");
+ }
+
+ str = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+
+ return str;
+}
+
+static char *eevee_get_volume_defines(int options)
+{
+ char *str = NULL;
+
+ DynStr *ds = BLI_dynstr_new();
+ BLI_dynstr_appendf(ds, SHADER_DEFINES);
+ BLI_dynstr_appendf(ds, "#define VOLUMETRICS\n");
+
+ if ((options & VAR_MAT_VOLUME) != 0) {
+ BLI_dynstr_appendf(ds, "#define MESH_SHADER\n");
+ }
+
+ str = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+
+ return str;
+}
+
+/**
+ * ssr_id can be null to disable ssr contribution.
+ **/
+static void add_standard_uniforms(
+ DRWShadingGroup *shgrp, EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata,
+ int *ssr_id, float *refract_depth, bool use_ssrefraction, bool use_alpha_blend)
+{
+ if (ssr_id == NULL) {
+ static int no_ssr = -1.0f;
+ ssr_id = &no_ssr;
+ }
+
+ DRW_shgroup_uniform_block(shgrp, "probe_block", sldata->probe_ubo);
+ DRW_shgroup_uniform_block(shgrp, "grid_block", sldata->grid_ubo);
+ DRW_shgroup_uniform_block(shgrp, "planar_block", sldata->planar_ubo);
+ DRW_shgroup_uniform_block(shgrp, "light_block", sldata->light_ubo);
+ DRW_shgroup_uniform_block(shgrp, "shadow_block", sldata->shadow_ubo);
+ DRW_shgroup_uniform_block(shgrp, "common_block", sldata->common_ubo);
+ DRW_shgroup_uniform_block(shgrp, "clip_block", sldata->clip_ubo);
+
+ /* TODO if glossy or diffuse bsdf */
+ if (true) {
+ DRW_shgroup_uniform_texture(shgrp, "utilTex", e_data.util_tex);
+ DRW_shgroup_uniform_texture_ref(shgrp, "shadowCubeTexture", &sldata->shadow_cube_pool);
+ DRW_shgroup_uniform_texture_ref(shgrp, "shadowCascadeTexture", &sldata->shadow_cascade_pool);
+ DRW_shgroup_uniform_texture_ref(shgrp, "maxzBuffer", &vedata->txl->maxzbuffer);
+
+ if ((vedata->stl->effects->enabled_effects & EFFECT_GTAO) != 0) {
+ DRW_shgroup_uniform_texture_ref(shgrp, "horizonBuffer", &vedata->stl->effects->gtao_horizons);
+ }
+ else {
+ /* Use maxzbuffer as fallback to avoid sampling problem on certain platform, see: T52593 */
+ DRW_shgroup_uniform_texture_ref(shgrp, "horizonBuffer", &vedata->txl->maxzbuffer);
+ }
+ }
+
+ /* TODO if diffuse bsdf */
+ if (true) {
+ DRW_shgroup_uniform_texture_ref(shgrp, "irradianceGrid", &sldata->irradiance_pool);
+ }
+
+ /* TODO if glossy bsdf */
+ if (true) {
+ DRW_shgroup_uniform_texture_ref(shgrp, "probeCubes", &sldata->probe_pool);
+ DRW_shgroup_uniform_texture_ref(shgrp, "probePlanars", &vedata->txl->planar_pool);
+ DRW_shgroup_uniform_int(shgrp, "outputSsrId", ssr_id, 1);
+ }
+
+ if (use_ssrefraction) {
+ BLI_assert(refract_depth != NULL);
+ DRW_shgroup_uniform_float(shgrp, "refractionDepth", refract_depth, 1);
+ DRW_shgroup_uniform_texture_ref(shgrp, "colorBuffer", &vedata->txl->refract_color);
+ }
+
+ if ((vedata->stl->effects->enabled_effects & EFFECT_VOLUMETRIC) != 0 &&
+ use_alpha_blend)
+ {
+ /* Do not use history buffers as they already have been swapped */
+ DRW_shgroup_uniform_texture_ref(shgrp, "inScattering", &vedata->txl->volume_scatter);
+ DRW_shgroup_uniform_texture_ref(shgrp, "inTransmittance", &vedata->txl->volume_transmittance);
+ }
+}
+
+static void create_default_shader(int options)
+{
+ char *frag_str = BLI_string_joinN(
+ e_data.frag_shader_lib,
+ datatoc_default_frag_glsl);
+
+ char *defines = eevee_get_defines(options);
+
+ e_data.default_lit[options] = DRW_shader_create(datatoc_lit_surface_vert_glsl, NULL, frag_str, defines);
+
+ MEM_freeN(defines);
+ MEM_freeN(frag_str);
+}
+
+static void eevee_init_noise_texture(void)
+{
+ e_data.noise_tex = DRW_texture_create_2D(64, 64, GPU_RGBA16F, 0, (float *)blue_noise);
+}
+
+static void eevee_init_util_texture(void)
+{
+ const int layers = 3 + 16;
+ float (*texels)[4] = MEM_mallocN(sizeof(float[4]) * 64 * 64 * layers, "utils texels");
+ float (*texels_layer)[4] = texels;
+
+ /* Copy ltc_mat_ggx into 1st layer */
+ memcpy(texels_layer, ltc_mat_ggx, sizeof(float[4]) * 64 * 64);
+ texels_layer += 64 * 64;
+
+ /* Copy bsdf_split_sum_ggx into 2nd layer red and green channels.
+ Copy ltc_mag_ggx into 2nd layer blue channel. */
+ for (int i = 0; i < 64 * 64; i++) {
+ texels_layer[i][0] = bsdf_split_sum_ggx[i * 2 + 0];
+ texels_layer[i][1] = bsdf_split_sum_ggx[i * 2 + 1];
+ texels_layer[i][2] = ltc_mag_ggx[i];
+ texels_layer[i][3] = ltc_disk_integral[i];
+ }
+ texels_layer += 64 * 64;
+
+ /* Copy blue noise in 3rd layer */
+ for (int i = 0; i < 64 * 64; i++) {
+ texels_layer[i][0] = blue_noise[i][0];
+ texels_layer[i][1] = blue_noise[i][2];
+ texels_layer[i][2] = cosf(blue_noise[i][1] * 2.0f * M_PI);
+ texels_layer[i][3] = sinf(blue_noise[i][1] * 2.0f * M_PI);
+ }
+ texels_layer += 64 * 64;
+
+ /* Copy Refraction GGX LUT in layer 4 - 20 */
+ for (int j = 0; j < 16; ++j) {
+ for (int i = 0; i < 64 * 64; i++) {
+ texels_layer[i][0] = btdf_split_sum_ggx[j * 2][i];
+ texels_layer[i][1] = btdf_split_sum_ggx[j * 2][i];
+ texels_layer[i][2] = btdf_split_sum_ggx[j * 2][i];
+ texels_layer[i][3] = btdf_split_sum_ggx[j * 2][i];
+ }
+ texels_layer += 64 * 64;
+ }
+
+ e_data.util_tex = DRW_texture_create_2D_array(
+ 64, 64, layers, GPU_RGBA16F, DRW_TEX_FILTER | DRW_TEX_WRAP, (float *)texels);
+
+ MEM_freeN(texels);
+}
+
+void EEVEE_update_noise(EEVEE_PassList *psl, EEVEE_FramebufferList *fbl, const double offsets[3])
+{
+ e_data.noise_offsets[0] = offsets[0];
+ e_data.noise_offsets[1] = offsets[1];
+ e_data.noise_offsets[2] = offsets[2];
+
+ /* Attach & detach because we don't currently support multiple FB per texture,
+ * and this would be the case for multiple viewport. */
+ GPU_framebuffer_bind(fbl->update_noise_fb);
+ DRW_draw_pass(psl->update_noise_pass);
+}
+
+static void EEVEE_update_viewvecs(float invproj[4][4], float winmat[4][4], float (*r_viewvecs)[4])
+{
+ /* view vectors for the corners of the view frustum.
+ * Can be used to recreate the world space position easily */
+ float view_vecs[4][4] = {
+ {-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}
+ };
+
+ /* convert the view vectors to view space */
+ const bool is_persp = (winmat[3][3] == 0.0f);
+ for (int i = 0; i < 4; i++) {
+ mul_project_m4_v3(invproj, view_vecs[i]);
+ /* normalized trick see:
+ * http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */
+ if (is_persp) {
+ /* Divide XY by Z. */
+ mul_v2_fl(view_vecs[i], 1.0f / view_vecs[i][2]);
+ }
+ }
+
+ /**
+ * If ortho : view_vecs[0] is the near-bottom-left corner of the frustum and
+ * view_vecs[1] is the vector going from the near-bottom-left corner to
+ * the far-top-right corner.
+ * If Persp : view_vecs[0].xy and view_vecs[1].xy are respectively the bottom-left corner
+ * when Z = 1, and top-left corner if Z = 1.
+ * view_vecs[0].z the near clip distance and view_vecs[1].z is the (signed)
+ * distance from the near plane to the far clip plane.
+ **/
+ copy_v4_v4(r_viewvecs[0], view_vecs[0]);
+
+ /* we need to store the differences */
+ r_viewvecs[1][0] = view_vecs[1][0] - view_vecs[0][0];
+ r_viewvecs[1][1] = view_vecs[2][1] - view_vecs[0][1];
+ r_viewvecs[1][2] = view_vecs[3][2] - view_vecs[0][2];
+}
+
+void EEVEE_materials_init(EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, EEVEE_FramebufferList *fbl)
+{
+ if (!e_data.frag_shader_lib) {
+ char *frag_str = NULL;
+
+ /* Shaders */
+ e_data.frag_shader_lib = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_sampling_lib_glsl,
+ datatoc_ambient_occlusion_lib_glsl,
+ datatoc_raytrace_lib_glsl,
+ datatoc_ssr_lib_glsl,
+ datatoc_octahedron_lib_glsl,
+ datatoc_irradiance_lib_glsl,
+ datatoc_lightprobe_lib_glsl,
+ datatoc_ltc_lib_glsl,
+ datatoc_bsdf_direct_lib_glsl,
+ datatoc_lamps_lib_glsl,
+ /* Add one for each Closure */
+ datatoc_lit_surface_frag_glsl,
+ datatoc_lit_surface_frag_glsl,
+ datatoc_lit_surface_frag_glsl,
+ datatoc_lit_surface_frag_glsl,
+ datatoc_lit_surface_frag_glsl,
+ datatoc_lit_surface_frag_glsl,
+ datatoc_lit_surface_frag_glsl,
+ datatoc_lit_surface_frag_glsl,
+ datatoc_volumetric_lib_glsl);
+
+ e_data.volume_shader_lib = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_ambient_occlusion_lib_glsl,
+ datatoc_octahedron_lib_glsl,
+ datatoc_irradiance_lib_glsl,
+ datatoc_lightprobe_lib_glsl,
+ datatoc_ltc_lib_glsl,
+ datatoc_bsdf_direct_lib_glsl,
+ datatoc_lamps_lib_glsl,
+ datatoc_volumetric_lib_glsl,
+ datatoc_volumetric_frag_glsl);
+
+ frag_str = BLI_string_joinN(
+ e_data.frag_shader_lib,
+ datatoc_default_frag_glsl);
+
+ e_data.default_background = DRW_shader_create(
+ datatoc_background_vert_glsl, NULL, datatoc_default_world_frag_glsl,
+ NULL);
+
+ e_data.default_prepass_sh = DRW_shader_create(
+ datatoc_prepass_vert_glsl, NULL, datatoc_prepass_frag_glsl,
+ NULL);
+
+ e_data.default_prepass_clip_sh = DRW_shader_create(
+ datatoc_prepass_vert_glsl, NULL, datatoc_prepass_frag_glsl,
+ "#define CLIP_PLANES\n");
+
+ MEM_freeN(frag_str);
+
+ e_data.update_noise_sh = DRW_shader_create_fullscreen(
+ datatoc_update_noise_frag_glsl, NULL);
+
+ eevee_init_util_texture();
+ eevee_init_noise_texture();
+ }
+
+ if (!DRW_state_is_image_render() &&
+ ((stl->effects->enabled_effects & EFFECT_TAA) == 0))
+ {
+ e_data.alpha_hash_offset = 0.0f;
+ }
+ else {
+ double r;
+ BLI_halton_1D(5, 0.0, stl->effects->taa_current_sample - 1, &r);
+ e_data.alpha_hash_offset = (float)r;
+ }
+
+ {
+ /* Update view_vecs */
+ float invproj[4][4], winmat[4][4];
+ DRW_viewport_matrix_get(winmat, DRW_MAT_WIN);
+ DRW_viewport_matrix_get(invproj, DRW_MAT_WININV);
+
+ EEVEE_update_viewvecs(invproj, winmat, sldata->common_data.view_vecs);
+ }
+
+ {
+ /* Update noise Framebuffer. */
+ GPU_framebuffer_ensure_config(&fbl->update_noise_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE_LAYER(e_data.util_tex, 2)
+ });
+ }
+}
+
+struct GPUMaterial *EEVEE_material_world_lightprobe_get(struct Scene *scene, World *wo)
+{
+ const void *engine = &DRW_engine_viewport_eevee_type;
+ const int options = VAR_WORLD_PROBE;
+
+ GPUMaterial *mat = DRW_shader_find_from_world(wo, engine, options);
+ if (mat != NULL) {
+ return mat;
+ }
+ return DRW_shader_create_from_world(
+ scene, wo, engine, options,
+ datatoc_background_vert_glsl, NULL, e_data.frag_shader_lib,
+ SHADER_DEFINES "#define PROBE_CAPTURE\n");
+}
+
+struct GPUMaterial *EEVEE_material_world_background_get(struct Scene *scene, World *wo)
+{
+ const void *engine = &DRW_engine_viewport_eevee_type;
+ int options = VAR_WORLD_BACKGROUND;
+
+ GPUMaterial *mat = DRW_shader_find_from_world(wo, engine, options);
+ if (mat != NULL) {
+ return mat;
+ }
+ return DRW_shader_create_from_world(
+ scene, wo, engine, options,
+ datatoc_background_vert_glsl, NULL, e_data.frag_shader_lib,
+ SHADER_DEFINES "#define WORLD_BACKGROUND\n");
+}
+
+struct GPUMaterial *EEVEE_material_world_volume_get(struct Scene *scene, World *wo)
+{
+ const void *engine = &DRW_engine_viewport_eevee_type;
+ int options = VAR_WORLD_VOLUME;
+
+ GPUMaterial *mat = DRW_shader_find_from_world(wo, engine, options);
+ if (mat != NULL) {
+ return mat;
+ }
+
+ char *defines = eevee_get_volume_defines(options);
+
+ mat = DRW_shader_create_from_world(
+ scene, wo, engine, options,
+ datatoc_volumetric_vert_glsl, datatoc_volumetric_geom_glsl, e_data.volume_shader_lib,
+ defines);
+
+ MEM_freeN(defines);
+
+ return mat;
+}
+
+struct GPUMaterial *EEVEE_material_mesh_get(
+ struct Scene *scene, Material *ma, EEVEE_Data *vedata,
+ bool use_blend, bool use_multiply, bool use_refract, bool use_sss, bool use_translucency, int shadow_method)
+{
+ EEVEE_EffectsInfo *effects = vedata->stl->effects;
+ const void *engine = &DRW_engine_viewport_eevee_type;
+ int options = VAR_MAT_MESH;
+
+ if (use_blend) options |= VAR_MAT_BLEND;
+ if (use_multiply) options |= VAR_MAT_MULT;
+ if (use_refract) options |= VAR_MAT_REFRACT;
+ if (use_sss) options |= VAR_MAT_SSS;
+ if (use_sss && effects->sss_separate_albedo) options |= VAR_MAT_SSSALBED;
+ if (use_translucency) options |= VAR_MAT_TRANSLUC;
+ if (((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) && use_blend) options |= VAR_MAT_VOLUME;
+
+ options |= eevee_material_shadow_option(shadow_method);
+
+ GPUMaterial *mat = DRW_shader_find_from_material(ma, engine, options);
+ if (mat) {
+ return mat;
+ }
+
+ char *defines = eevee_get_defines(options);
+
+ mat = DRW_shader_create_from_material(
+ scene, ma, engine, options,
+ datatoc_lit_surface_vert_glsl, NULL, e_data.frag_shader_lib,
+ defines);
+
+ MEM_freeN(defines);
+
+ return mat;
+}
+
+struct GPUMaterial *EEVEE_material_mesh_volume_get(struct Scene *scene, Material *ma)
+{
+ const void *engine = &DRW_engine_viewport_eevee_type;
+ int options = VAR_MAT_VOLUME;
+
+ GPUMaterial *mat = DRW_shader_find_from_material(ma, engine, options);
+ if (mat != NULL) {
+ return mat;
+ }
+
+ char *defines = eevee_get_volume_defines(options);
+
+ mat = DRW_shader_create_from_material(
+ scene, ma, engine, options,
+ datatoc_volumetric_vert_glsl, datatoc_volumetric_geom_glsl, e_data.volume_shader_lib,
+ defines);
+
+ MEM_freeN(defines);
+
+ return mat;
+}
+
+struct GPUMaterial *EEVEE_material_mesh_depth_get(
+ struct Scene *scene, Material *ma,
+ bool use_hashed_alpha, bool is_shadow)
+{
+ const void *engine = &DRW_engine_viewport_eevee_type;
+ int options = VAR_MAT_MESH;
+
+ if (use_hashed_alpha) {
+ options |= VAR_MAT_HASH;
+ }
+ else {
+ options |= VAR_MAT_CLIP;
+ }
+
+ if (is_shadow)
+ options |= VAR_MAT_SHADOW;
+
+ GPUMaterial *mat = DRW_shader_find_from_material(ma, engine, options);
+ if (mat) {
+ return mat;
+ }
+
+ char *defines = eevee_get_defines(options);
+
+ char *frag_str = BLI_string_joinN(
+ e_data.frag_shader_lib,
+ datatoc_prepass_frag_glsl);
+
+ mat = DRW_shader_create_from_material(
+ scene, ma, engine, options,
+ (is_shadow) ? datatoc_shadow_vert_glsl : datatoc_lit_surface_vert_glsl,
+ NULL,
+ frag_str,
+ defines);
+
+ MEM_freeN(frag_str);
+ MEM_freeN(defines);
+
+ return mat;
+}
+
+struct GPUMaterial *EEVEE_material_hair_get(
+ struct Scene *scene, Material *ma, int shadow_method)
+{
+ const void *engine = &DRW_engine_viewport_eevee_type;
+ int options = VAR_MAT_MESH | VAR_MAT_HAIR;
+
+ options |= eevee_material_shadow_option(shadow_method);
+
+ GPUMaterial *mat = DRW_shader_find_from_material(ma, engine, options);
+ if (mat) {
+ return mat;
+ }
+
+ char *defines = eevee_get_defines(options);
+
+ mat = DRW_shader_create_from_material(
+ scene, ma, engine, options,
+ datatoc_lit_surface_vert_glsl, NULL, e_data.frag_shader_lib,
+ defines);
+
+ MEM_freeN(defines);
+
+ return mat;
+}
+
+/**
+ * Create a default shading group inside the given pass.
+ **/
+static struct DRWShadingGroup *EEVEE_default_shading_group_create(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, DRWPass *pass,
+ bool is_hair, bool is_flat_normal, bool use_blend, bool use_ssr, int shadow_method)
+{
+ EEVEE_EffectsInfo *effects = vedata->stl->effects;
+ static int ssr_id;
+ ssr_id = (use_ssr) ? 1 : -1;
+ int options = VAR_MAT_MESH;
+
+ if (is_hair) options |= VAR_MAT_HAIR;
+ if (is_flat_normal) options |= VAR_MAT_FLAT;
+ if (use_blend) options |= VAR_MAT_BLEND;
+ if (((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) && use_blend) options |= VAR_MAT_VOLUME;
+
+ options |= eevee_material_shadow_option(shadow_method);
+
+ if (e_data.default_lit[options] == NULL) {
+ create_default_shader(options);
+ }
+
+ DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit[options], pass);
+ add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, use_blend);
+
+ return shgrp;
+}
+
+/**
+ * Create a default shading group inside the default pass without standard uniforms.
+ **/
+static struct DRWShadingGroup *EEVEE_default_shading_group_get(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata,
+ bool is_hair, bool is_flat_normal, bool use_ssr, int shadow_method)
+{
+ static int ssr_id;
+ ssr_id = (use_ssr) ? 1 : -1;
+ int options = VAR_MAT_MESH;
+
+ if (is_hair) options |= VAR_MAT_HAIR;
+ if (is_flat_normal) options |= VAR_MAT_FLAT;
+
+ options |= eevee_material_shadow_option(shadow_method);
+
+ if (e_data.default_lit[options] == NULL) {
+ create_default_shader(options);
+ }
+
+ if (vedata->psl->default_pass[options] == NULL) {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
+ vedata->psl->default_pass[options] = DRW_pass_create("Default Lit Pass", state);
+
+ DRWShadingGroup *shgrp = DRW_shgroup_create(e_data.default_lit[options], vedata->psl->default_pass[options]);
+ /* XXX / WATCH: This creates non persistent binds for the ubos and textures.
+ * But it's currently OK because the following shgroups does not add any bind. */
+ add_standard_uniforms(shgrp, sldata, vedata, &ssr_id, NULL, false, false);
+ }
+
+ return DRW_shgroup_create(e_data.default_lit[options], vedata->psl->default_pass[options]);
+}
+
+void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+
+ /* Create Material Ghash */
+ {
+ stl->g_data->material_hash = BLI_ghash_ptr_new("Eevee_material ghash");
+ stl->g_data->hair_material_hash = BLI_ghash_ptr_new("Eevee_hair_material ghash");
+ }
+
+ {
+ psl->background_pass = DRW_pass_create("Background Pass", DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL);
+
+ struct Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+ DRWShadingGroup *grp = NULL;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ World *wo = scene->world;
+
+ float *col = ts.colorBackground;
+
+ if (wo) {
+ col = &wo->horr;
+
+ if (wo->use_nodes && wo->nodetree) {
+ static float error_col[3] = {1.0f, 0.0f, 1.0f};
+ static float compile_col[3] = {0.5f, 0.5f, 0.5f};
+ struct GPUMaterial *gpumat = EEVEE_material_world_background_get(scene, wo);
+
+ switch (GPU_material_status(gpumat)) {
+ case GPU_MAT_SUCCESS:
+ grp = DRW_shgroup_material_create(gpumat, psl->background_pass);
+ DRW_shgroup_uniform_float(grp, "backgroundAlpha", &stl->g_data->background_alpha, 1);
+ DRW_shgroup_call_add(grp, geom, NULL);
+ break;
+ case GPU_MAT_QUEUED:
+ sldata->probes->all_materials_updated = false;
+ /* TODO Bypass probe compilation. */
+ col = compile_col;
+ break;
+ case GPU_MAT_FAILED:
+ default:
+ col = error_col;
+ break;
+ }
+ }
+ }
+
+ /* Fallback if shader fails or if not using nodetree. */
+ if (grp == NULL) {
+ grp = DRW_shgroup_create(e_data.default_background, psl->background_pass);
+ DRW_shgroup_uniform_vec3(grp, "color", col, 1);
+ DRW_shgroup_uniform_float(grp, "backgroundAlpha", &stl->g_data->background_alpha, 1);
+ DRW_shgroup_call_add(grp, geom, NULL);
+ }
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE;
+ psl->depth_pass = DRW_pass_create("Depth Pass", state);
+ stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.default_prepass_sh, psl->depth_pass);
+
+ state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
+ psl->depth_pass_cull = DRW_pass_create("Depth Pass Cull", state);
+ stl->g_data->depth_shgrp_cull = DRW_shgroup_create(e_data.default_prepass_sh, psl->depth_pass_cull);
+
+ state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
+ psl->depth_pass_clip = DRW_pass_create("Depth Pass Clip", state);
+ stl->g_data->depth_shgrp_clip = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->depth_pass_clip);
+ DRW_shgroup_uniform_block(stl->g_data->depth_shgrp_clip, "clip_block", sldata->clip_ubo);
+
+ state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_CULL_BACK;
+ psl->depth_pass_clip_cull = DRW_pass_create("Depth Pass Cull Clip", state);
+ stl->g_data->depth_shgrp_clip_cull = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->depth_pass_clip_cull);
+ DRW_shgroup_uniform_block(stl->g_data->depth_shgrp_clip_cull, "clip_block", sldata->clip_ubo);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
+ psl->material_pass = DRW_pass_create("Material Shader Pass", state);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE;
+ psl->refract_depth_pass = DRW_pass_create("Refract Depth Pass", state);
+ stl->g_data->refract_depth_shgrp = DRW_shgroup_create(e_data.default_prepass_sh, psl->refract_depth_pass);
+
+ state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
+ psl->refract_depth_pass_cull = DRW_pass_create("Refract Depth Pass Cull", state);
+ stl->g_data->refract_depth_shgrp_cull = DRW_shgroup_create(e_data.default_prepass_sh, psl->refract_depth_pass_cull);
+
+ state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
+ psl->refract_depth_pass_clip = DRW_pass_create("Refract Depth Pass Clip", state);
+ stl->g_data->refract_depth_shgrp_clip = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->refract_depth_pass_clip);
+ DRW_shgroup_uniform_block(stl->g_data->refract_depth_shgrp_clip, "clip_block", sldata->clip_ubo);
+
+ state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_CULL_BACK;
+ psl->refract_depth_pass_clip_cull = DRW_pass_create("Refract Depth Pass Cull Clip", state);
+ stl->g_data->refract_depth_shgrp_clip_cull = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->refract_depth_pass_clip_cull);
+ DRW_shgroup_uniform_block(stl->g_data->refract_depth_shgrp_clip_cull, "clip_block", sldata->clip_ubo);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
+ psl->refract_pass = DRW_pass_create("Opaque Refraction Pass", state);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE | DRW_STATE_WRITE_STENCIL;
+ psl->sss_pass = DRW_pass_create("Subsurface Pass", state);
+ e_data.sss_count = 0;
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_CLIP_PLANES | DRW_STATE_WIRE;
+ psl->transparent_pass = DRW_pass_create("Material Transparent Pass", state);
+ }
+
+ {
+ psl->update_noise_pass = DRW_pass_create("Update Noise Pass", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.update_noise_sh, psl->update_noise_pass);
+ DRW_shgroup_uniform_texture(grp, "blueNoise", e_data.noise_tex);
+ DRW_shgroup_uniform_vec3(grp, "offsets", e_data.noise_offsets, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+
+}
+
+#define ADD_SHGROUP_CALL(shgrp, ob, geom, oedata) do { \
+ if (is_sculpt_mode_draw) { \
+ DRW_shgroup_call_sculpt_add(shgrp, ob, ob->obmat); \
+ } \
+ else { \
+ if (oedata) { \
+ DRW_shgroup_call_object_add_with_callback(shgrp, geom, ob, EEVEE_lightprobes_obj_visibility_cb, oedata); \
+ } \
+ else { \
+ DRW_shgroup_call_object_add(shgrp, geom, ob); \
+ } \
+ } \
+} while (0)
+
+#define ADD_SHGROUP_CALL_SAFE(shgrp, ob, geom, oedata) do { \
+ if (shgrp) { \
+ ADD_SHGROUP_CALL(shgrp, ob, geom, oedata); \
+ } \
+} while (0)
+
+typedef struct EeveeMaterialShadingGroups {
+ struct DRWShadingGroup *shading_grp;
+ struct DRWShadingGroup *depth_grp;
+ struct DRWShadingGroup *depth_clip_grp;
+} EeveeMaterialShadingGroups;
+
+static void material_opaque(
+ Material *ma, GHash *material_hash, EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata,
+ bool do_cull, bool use_flat_nor, struct GPUMaterial **gpumat, struct GPUMaterial **gpumat_depth,
+ struct DRWShadingGroup **shgrp, struct DRWShadingGroup **shgrp_depth, struct DRWShadingGroup **shgrp_depth_clip)
+{
+ EEVEE_EffectsInfo *effects = vedata->stl->effects;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+
+ float *color_p = &ma->r;
+ float *metal_p = &ma->ray_mirror;
+ float *spec_p = &ma->spec;
+ float *rough_p = &ma->gloss_mir;
+
+ const bool use_gpumat = (ma->use_nodes && ma->nodetree);
+ const bool use_refract = ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) &&
+ ((effects->enabled_effects & EFFECT_REFRACT) != 0);
+ const bool use_sss = ((ma->blend_flag & MA_BL_SS_SUBSURFACE) != 0) &&
+ ((effects->enabled_effects & EFFECT_SSS) != 0);
+ const bool use_translucency = use_sss && ((ma->blend_flag & MA_BL_TRANSLUCENCY) != 0);
+
+ EeveeMaterialShadingGroups *emsg = BLI_ghash_lookup(material_hash, (const void *)ma);
+
+ if (emsg) {
+ *shgrp = emsg->shading_grp;
+ *shgrp_depth = emsg->depth_grp;
+ *shgrp_depth_clip = emsg->depth_clip_grp;
+
+ /* This will have been created already, just perform a lookup. */
+ *gpumat = (use_gpumat) ? EEVEE_material_mesh_get(
+ scene, ma, vedata, false, false, use_refract, use_sss, use_translucency, linfo->shadow_method) : NULL;
+ *gpumat_depth = (use_gpumat) ? EEVEE_material_mesh_depth_get(
+ scene, ma, (ma->blend_method == MA_BM_HASHED), false) : NULL;
+ return;
+ }
+
+ if (use_gpumat) {
+ static float error_col[3] = {1.0f, 0.0f, 1.0f};
+ static float compile_col[3] = {0.5f, 0.5f, 0.5f};
+ static float half = 0.5f;
+
+ /* Shading */
+ *gpumat = EEVEE_material_mesh_get(scene, ma, vedata, false, false, use_refract,
+ use_sss, use_translucency, linfo->shadow_method);
+
+ GPUMaterialStatus status_mat_surface = GPU_material_status(*gpumat);
+
+ /* Alpha CLipped : Discard pixel from depth pass, then
+ * fail the depth test for shading. */
+ if (ELEM(ma->blend_method, MA_BM_CLIP, MA_BM_HASHED)) {
+ *gpumat_depth = EEVEE_material_mesh_depth_get(scene, ma,
+ (ma->blend_method == MA_BM_HASHED), false);
+
+ GPUMaterialStatus status_mat_depth = GPU_material_status(*gpumat_depth);
+ if (status_mat_depth != GPU_MAT_SUCCESS) {
+ /* Mixing both flags. If depth shader fails, show it to the user by not using
+ * the surface shader. */
+ status_mat_surface = status_mat_depth;
+ }
+ else if (use_refract) {
+ *shgrp_depth = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->refract_depth_pass_cull : psl->refract_depth_pass);
+ *shgrp_depth_clip = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->refract_depth_pass_clip_cull : psl->refract_depth_pass_clip);
+ }
+ else {
+ *shgrp_depth = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->depth_pass_cull : psl->depth_pass);
+ *shgrp_depth_clip = DRW_shgroup_material_create(*gpumat_depth, (do_cull) ? psl->depth_pass_clip_cull : psl->depth_pass_clip);
+ }
+
+ if (*shgrp_depth != NULL) {
+ add_standard_uniforms(*shgrp_depth, sldata, vedata, NULL, NULL, false, false);
+ add_standard_uniforms(*shgrp_depth_clip, sldata, vedata, NULL, NULL, false, false);
+
+ if (ma->blend_method == MA_BM_CLIP) {
+ DRW_shgroup_uniform_float(*shgrp_depth, "alphaThreshold", &ma->alpha_threshold, 1);
+ DRW_shgroup_uniform_float(*shgrp_depth_clip, "alphaThreshold", &ma->alpha_threshold, 1);
+ }
+ else if (ma->blend_method == MA_BM_HASHED) {
+ DRW_shgroup_uniform_float(*shgrp_depth, "hashAlphaOffset", &e_data.alpha_hash_offset, 1);
+ DRW_shgroup_uniform_float(*shgrp_depth_clip, "hashAlphaOffset", &e_data.alpha_hash_offset, 1);
+ }
+ }
+ }
+
+ switch (status_mat_surface) {
+ case GPU_MAT_SUCCESS:
+ {
+ static int no_ssr = -1;
+ static int first_ssr = 1;
+ int *ssr_id = (((effects->enabled_effects & EFFECT_SSR) != 0) && !use_refract) ? &first_ssr : &no_ssr;
+
+ *shgrp = DRW_shgroup_material_create(*gpumat,
+ (use_refract) ? psl->refract_pass :
+ (use_sss) ? psl->sss_pass : psl->material_pass);
+ add_standard_uniforms(*shgrp, sldata, vedata, ssr_id, &ma->refract_depth, use_refract, false);
+
+ if (use_sss) {
+ struct GPUTexture *sss_tex_profile = NULL;
+ struct GPUUniformBuffer *sss_profile = GPU_material_sss_profile_get(*gpumat,
+ stl->effects->sss_sample_count,
+ &sss_tex_profile);
+
+ if (sss_profile) {
+ if (use_translucency) {
+ DRW_shgroup_uniform_block(*shgrp, "sssProfile", sss_profile);
+ DRW_shgroup_uniform_texture(*shgrp, "sssTexProfile", sss_tex_profile);
+ }
+
+ /* Limit of 8 bit stencil buffer. ID 255 is refraction. */
+ if (e_data.sss_count < 254) {
+ DRW_shgroup_stencil_mask(*shgrp, e_data.sss_count + 1);
+ EEVEE_subsurface_add_pass(sldata, vedata, e_data.sss_count + 1, sss_profile);
+ e_data.sss_count++;
+ }
+ else {
+ /* TODO : display message. */
+ printf("Error: Too many different Subsurface shader in the scene.\n");
+ }
+ }
+ }
+ break;
+ }
+ case GPU_MAT_QUEUED:
+ {
+ sldata->probes->all_materials_updated = false;
+ /* TODO Bypass probe compilation. */
+ color_p = compile_col;
+ metal_p = spec_p = rough_p = &half;
+ break;
+ }
+ case GPU_MAT_FAILED:
+ default:
+ color_p = error_col;
+ metal_p = spec_p = rough_p = &half;
+ break;
+ }
+ }
+
+ /* Fallback to default shader */
+ if (*shgrp == NULL) {
+ bool use_ssr = ((effects->enabled_effects & EFFECT_SSR) != 0);
+ *shgrp = EEVEE_default_shading_group_get(sldata, vedata, false, use_flat_nor, use_ssr, linfo->shadow_method);
+ DRW_shgroup_uniform_vec3(*shgrp, "basecol", color_p, 1);
+ DRW_shgroup_uniform_float(*shgrp, "metallic", metal_p, 1);
+ DRW_shgroup_uniform_float(*shgrp, "specular", spec_p, 1);
+ DRW_shgroup_uniform_float(*shgrp, "roughness", rough_p, 1);
+ }
+
+ /* Fallback default depth prepass */
+ if (*shgrp_depth == NULL) {
+ if (use_refract) {
+ *shgrp_depth = (do_cull) ? stl->g_data->refract_depth_shgrp_cull : stl->g_data->refract_depth_shgrp;
+ *shgrp_depth_clip = (do_cull) ? stl->g_data->refract_depth_shgrp_clip_cull : stl->g_data->refract_depth_shgrp_clip;
+ }
+ else {
+ *shgrp_depth = (do_cull) ? stl->g_data->depth_shgrp_cull : stl->g_data->depth_shgrp;
+ *shgrp_depth_clip = (do_cull) ? stl->g_data->depth_shgrp_clip_cull : stl->g_data->depth_shgrp_clip;
+ }
+ }
+
+ emsg = MEM_mallocN(sizeof(EeveeMaterialShadingGroups), "EeveeMaterialShadingGroups");
+ emsg->shading_grp = *shgrp;
+ emsg->depth_grp = *shgrp_depth;
+ emsg->depth_clip_grp = *shgrp_depth_clip;
+ BLI_ghash_insert(material_hash, ma, emsg);
+}
+
+static void material_transparent(
+ Material *ma, EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata,
+ bool do_cull, bool use_flat_nor, struct GPUMaterial **gpumat, struct DRWShadingGroup **shgrp, struct DRWShadingGroup **shgrp_depth)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+ EEVEE_PassList *psl = ((EEVEE_Data *)vedata)->psl;
+ EEVEE_LampsInfo *linfo = sldata->lamps;
+
+ const bool use_refract = ((ma->blend_flag & MA_BL_SS_REFRACTION) != 0) && ((stl->effects->enabled_effects & EFFECT_REFRACT) != 0);
+
+ float *color_p = &ma->r;
+ float *metal_p = &ma->ray_mirror;
+ float *spec_p = &ma->spec;
+ float *rough_p = &ma->gloss_mir;
+
+ if (ma->use_nodes && ma->nodetree) {
+ static float error_col[3] = {1.0f, 0.0f, 1.0f};
+ static float compile_col[3] = {0.5f, 0.5f, 0.5f};
+ static float half = 0.5f;
+
+ /* Shading */
+ *gpumat = EEVEE_material_mesh_get(scene, ma, vedata, true, (ma->blend_method == MA_BM_MULTIPLY), use_refract,
+ false, false, linfo->shadow_method);
+
+ switch (GPU_material_status(*gpumat)) {
+ case GPU_MAT_SUCCESS:
+ {
+ static int ssr_id = -1; /* TODO transparent SSR */
+ bool use_blend = (ma->blend_method & MA_BM_BLEND) != 0;
+
+ *shgrp = DRW_shgroup_material_create(*gpumat, psl->transparent_pass);
+ add_standard_uniforms(*shgrp, sldata, vedata, &ssr_id, &ma->refract_depth, use_refract, use_blend);
+ break;
+ }
+ case GPU_MAT_QUEUED:
+ {
+ sldata->probes->all_materials_updated = false;
+ /* TODO Bypass probe compilation. */
+ color_p = compile_col;
+ metal_p = spec_p = rough_p = &half;
+ break;
+ }
+ case GPU_MAT_FAILED:
+ default:
+ color_p = error_col;
+ metal_p = spec_p = rough_p = &half;
+ break;
+ }
+ }
+
+ /* Fallback to default shader */
+ if (*shgrp == NULL) {
+ *shgrp = EEVEE_default_shading_group_create(
+ sldata, vedata, psl->transparent_pass,
+ false, use_flat_nor, true, false, linfo->shadow_method);
+ DRW_shgroup_uniform_vec3(*shgrp, "basecol", color_p, 1);
+ DRW_shgroup_uniform_float(*shgrp, "metallic", metal_p, 1);
+ DRW_shgroup_uniform_float(*shgrp, "specular", spec_p, 1);
+ DRW_shgroup_uniform_float(*shgrp, "roughness", rough_p, 1);
+ }
+
+ const bool use_prepass = ((ma->blend_flag & MA_BL_HIDE_BACKSIDE) != 0);
+
+ DRWState all_state = DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_CULL_BACK | DRW_STATE_DEPTH_LESS | DRW_STATE_DEPTH_EQUAL |
+ DRW_STATE_BLEND | DRW_STATE_ADDITIVE | DRW_STATE_MULTIPLY;
+
+ DRWState cur_state = DRW_STATE_WRITE_COLOR;
+ cur_state |= (use_prepass) ? DRW_STATE_DEPTH_EQUAL : DRW_STATE_DEPTH_LESS;
+ cur_state |= (do_cull) ? DRW_STATE_CULL_BACK : 0;
+
+ switch (ma->blend_method) {
+ case MA_BM_ADD:
+ cur_state |= DRW_STATE_ADDITIVE;
+ break;
+ case MA_BM_MULTIPLY:
+ cur_state |= DRW_STATE_MULTIPLY;
+ break;
+ case MA_BM_BLEND:
+ cur_state |= DRW_STATE_BLEND;
+ break;
+ default:
+ BLI_assert(0);
+ break;
+ }
+
+ /* Disable other blend modes and use the one we want. */
+ DRW_shgroup_state_disable(*shgrp, all_state);
+ DRW_shgroup_state_enable(*shgrp, cur_state);
+
+ /* Depth prepass */
+ if (use_prepass) {
+ *shgrp_depth = DRW_shgroup_create(e_data.default_prepass_clip_sh, psl->transparent_pass);
+ DRW_shgroup_uniform_block(*shgrp_depth, "clip_block", sldata->clip_ubo);
+
+ cur_state = DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ cur_state |= (do_cull) ? DRW_STATE_CULL_BACK : 0;
+
+ DRW_shgroup_state_disable(*shgrp_depth, all_state);
+ DRW_shgroup_state_enable(*shgrp_depth, cur_state);
+ }
+}
+
+void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob, bool *cast_shadow)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ GHash *material_hash = stl->g_data->material_hash;
+
+ const bool do_cull = (draw_ctx->v3d && (draw_ctx->v3d->flag2 & V3D_BACKFACE_CULLING));
+ const bool is_active = (ob == draw_ctx->obact);
+ const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0;
+#if 0
+ const bool is_sculpt_mode_draw = is_sculpt_mode && (draw_ctx->v3d->flag2 & V3D_SHOW_MODE_SHADE_OVERRIDE) == 0;
+#else
+ /* For now just force fully shaded with eevee when supported. */
+ const bool is_sculpt_mode_draw =
+ is_sculpt_mode &&
+ ((ob->sculpt && ob->sculpt->pbvh) && (BKE_pbvh_type(ob->sculpt->pbvh) != PBVH_FACES));
+#endif
+ const bool is_default_mode_shader = is_sculpt_mode;
+
+ /* First get materials for this mesh. */
+ if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
+ const int materials_len = MAX2(1, (is_sculpt_mode_draw ? 1 : ob->totcol));
+
+ struct DRWShadingGroup **shgrp_array = BLI_array_alloca(shgrp_array, materials_len);
+ struct DRWShadingGroup **shgrp_depth_array = BLI_array_alloca(shgrp_depth_array, materials_len);
+ struct DRWShadingGroup **shgrp_depth_clip_array = BLI_array_alloca(shgrp_depth_clip_array, materials_len);
+
+ struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
+ struct GPUMaterial **gpumat_depth_array = BLI_array_alloca(gpumat_array, materials_len);
+
+ bool use_flat_nor = false;
+
+ if (is_default_mode_shader) {
+ if (is_sculpt_mode_draw) {
+ use_flat_nor = DRW_object_is_flat_normal(ob);
+ }
+ }
+
+ for (int i = 0; i < materials_len; ++i) {
+ Material *ma;
+
+ if (is_sculpt_mode_draw) {
+ ma = NULL;
+ }
+ else {
+ ma = give_current_material(ob, i + 1);
+ }
+
+ gpumat_array[i] = NULL;
+ gpumat_depth_array[i] = NULL;
+ shgrp_array[i] = NULL;
+ shgrp_depth_array[i] = NULL;
+ shgrp_depth_clip_array[i] = NULL;
+
+ if (ma == NULL)
+ ma = &defmaterial;
+
+ switch (ma->blend_method) {
+ case MA_BM_SOLID:
+ case MA_BM_CLIP:
+ case MA_BM_HASHED:
+ material_opaque(ma, material_hash, sldata, vedata, do_cull, use_flat_nor,
+ &gpumat_array[i], &gpumat_depth_array[i],
+ &shgrp_array[i], &shgrp_depth_array[i], &shgrp_depth_clip_array[i]);
+ break;
+ case MA_BM_ADD:
+ case MA_BM_MULTIPLY:
+ case MA_BM_BLEND:
+ material_transparent(ma, sldata, vedata, do_cull, use_flat_nor,
+ &gpumat_array[i], &shgrp_array[i], &shgrp_depth_array[i]);
+ break;
+ default:
+ BLI_assert(0);
+ break;
+ }
+ }
+
+ if (is_sculpt_mode && is_sculpt_mode_draw == false) {
+ DRW_cache_mesh_sculpt_coords_ensure(ob);
+ }
+
+ /* Only support single volume material for now. */
+ /* XXX We rely on the previously compiled surface shader
+ * to know if the material has a "volume nodetree".
+ */
+ bool use_volume_material = (gpumat_array[0] && GPU_material_use_domain_volume(gpumat_array[0]));
+
+ /* Get per-material split surface */
+ char *auto_layer_names;
+ int *auto_layer_is_srgb;
+ int auto_layer_count;
+ struct Gwn_Batch **mat_geom = DRW_cache_object_surface_material_get(ob, gpumat_array, materials_len,
+ &auto_layer_names,
+ &auto_layer_is_srgb,
+ &auto_layer_count);
+ if (mat_geom) {
+ for (int i = 0; i < materials_len; ++i) {
+ EEVEE_ObjectEngineData *oedata = NULL;
+ Material *ma = give_current_material(ob, i + 1);
+
+ if (ma == NULL)
+ ma = &defmaterial;
+
+ /* Do not render surface if we are rendering a volume object
+ * and do not have a surface closure. */
+ if (use_volume_material &&
+ (gpumat_array[i] && !GPU_material_use_domain_surface(gpumat_array[i])))
+ {
+ continue;
+ }
+
+ /* XXX TODO rewrite this to include the dupli objects.
+ * This means we cannot exclude dupli objects from reflections!!! */
+ if ((ob->base_flag & BASE_FROMDUPLI) == 0) {
+ oedata = EEVEE_object_data_ensure(ob);
+ oedata->ob = ob;
+ oedata->test_data = &sldata->probes->vis_data;
+ }
+
+ /* Shading pass */
+ ADD_SHGROUP_CALL(shgrp_array[i], ob, mat_geom[i], oedata);
+
+ /* Depth Prepass */
+ ADD_SHGROUP_CALL_SAFE(shgrp_depth_array[i], ob, mat_geom[i], oedata);
+ ADD_SHGROUP_CALL_SAFE(shgrp_depth_clip_array[i], ob, mat_geom[i], oedata);
+
+ char *name = auto_layer_names;
+ for (int j = 0; j < auto_layer_count; ++j) {
+ /* TODO don't add these uniform when not needed (default pass shaders). */
+ if (shgrp_array[i]) {
+ DRW_shgroup_uniform_bool(shgrp_array[i], name, &auto_layer_is_srgb[j], 1);
+ }
+ if (shgrp_depth_array[i]) {
+ DRW_shgroup_uniform_bool(shgrp_depth_array[i], name, &auto_layer_is_srgb[j], 1);
+ }
+ if (shgrp_depth_clip_array[i]) {
+ DRW_shgroup_uniform_bool(shgrp_depth_clip_array[i], name, &auto_layer_is_srgb[j], 1);
+ }
+ /* Go to next layer name. */
+ while (*name != '\0') { name++; }
+ name += 1;
+ }
+
+ /* Shadow Pass */
+ if (ma->use_nodes && ma->nodetree && (ma->blend_method != MA_BM_SOLID)) {
+ struct GPUMaterial *gpumat;
+ switch (ma->blend_shadow) {
+ case MA_BS_SOLID:
+ EEVEE_lights_cache_shcaster_add(sldata, stl, mat_geom[i], ob);
+ *cast_shadow = true;
+ break;
+ case MA_BS_CLIP:
+ gpumat = EEVEE_material_mesh_depth_get(scene, ma, false, true);
+ EEVEE_lights_cache_shcaster_material_add(sldata, psl, gpumat, mat_geom[i], ob, &ma->alpha_threshold);
+ *cast_shadow = true;
+ break;
+ case MA_BS_HASHED:
+ gpumat = EEVEE_material_mesh_depth_get(scene, ma, true, true);
+ EEVEE_lights_cache_shcaster_material_add(sldata, psl, gpumat, mat_geom[i], ob, NULL);
+ *cast_shadow = true;
+ break;
+ case MA_BS_NONE:
+ default:
+ break;
+ }
+ }
+ else {
+ EEVEE_lights_cache_shcaster_add(sldata, stl, mat_geom[i], ob);
+ *cast_shadow = true;
+ }
+ }
+ }
+
+ /* Volumetrics */
+ if (((stl->effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) && use_volume_material) {
+ EEVEE_volumes_cache_object_add(sldata, vedata, scene, ob);
+ }
+ }
+
+ if (ob->type == OB_MESH) {
+ if (ob != draw_ctx->object_edit) {
+ material_hash = stl->g_data->hair_material_hash;
+
+ for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
+ if (md->type == eModifierType_ParticleSystem) {
+ ParticleSystem *psys = ((ParticleSystemModifierData *)md)->psys;
+
+ if (psys_check_enabled(ob, psys, false)) {
+ ParticleSettings *part = psys->part;
+ int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
+
+ if (draw_as == PART_DRAW_PATH && (psys->pathcache || psys->childcache)) {
+ struct Gwn_Batch *hair_geom = DRW_cache_particles_get_hair(psys, md);
+ DRWShadingGroup *shgrp = NULL;
+ Material *ma = give_current_material(ob, part->omat);
+ static float mat[4][4];
+
+ unit_m4(mat);
+
+ if (ma == NULL) {
+ ma = &defmaterial;
+ }
+
+ float *color_p = &ma->r;
+ float *metal_p = &ma->ray_mirror;
+ float *spec_p = &ma->spec;
+ float *rough_p = &ma->gloss_mir;
+
+ DRW_shgroup_call_add(stl->g_data->depth_shgrp, hair_geom, mat);
+ DRW_shgroup_call_add(stl->g_data->depth_shgrp_clip, hair_geom, mat);
+
+ shgrp = BLI_ghash_lookup(material_hash, (const void *)ma);
+
+ if (shgrp) {
+ DRW_shgroup_call_add(shgrp, hair_geom, mat);
+ }
+ else {
+ if (ma->use_nodes && ma->nodetree) {
+ static float half = 0.5f;
+ static float error_col[3] = {1.0f, 0.0f, 1.0f};
+ static float compile_col[3] = {0.5f, 0.5f, 0.5f};
+ struct GPUMaterial *gpumat = EEVEE_material_hair_get(scene, ma, sldata->lamps->shadow_method);
+
+ switch (GPU_material_status(gpumat)) {
+ case GPU_MAT_SUCCESS:
+ {
+ shgrp = DRW_shgroup_material_create(gpumat, psl->material_pass);
+ add_standard_uniforms(shgrp, sldata, vedata, NULL, NULL, false, false);
+ break;
+ }
+ case GPU_MAT_QUEUED:
+ {
+ sldata->probes->all_materials_updated = false;
+ color_p = compile_col;
+ metal_p = spec_p = rough_p = &half;
+ break;
+ }
+ case GPU_MAT_FAILED:
+ default:
+ color_p = error_col;
+ metal_p = spec_p = rough_p = &half;
+ break;
+ }
+ }
+
+ /* Fallback to default shader */
+ if (shgrp == NULL) {
+ bool use_ssr = ((stl->effects->enabled_effects & EFFECT_SSR) != 0);
+ shgrp = EEVEE_default_shading_group_get(sldata, vedata, true, false, use_ssr,
+ sldata->lamps->shadow_method);
+ DRW_shgroup_uniform_vec3(shgrp, "basecol", color_p, 1);
+ DRW_shgroup_uniform_float(shgrp, "metallic", metal_p, 1);
+ DRW_shgroup_uniform_float(shgrp, "specular", spec_p, 1);
+ DRW_shgroup_uniform_float(shgrp, "roughness", rough_p, 1);
+ }
+
+ DRW_shgroup_call_add(shgrp, hair_geom, NULL);
+ BLI_ghash_insert(material_hash, ma, shgrp);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void EEVEE_materials_cache_finish(EEVEE_Data *vedata)
+{
+ EEVEE_StorageList *stl = ((EEVEE_Data *)vedata)->stl;
+
+ BLI_ghash_free(stl->g_data->material_hash, NULL, MEM_freeN);
+ BLI_ghash_free(stl->g_data->hair_material_hash, NULL, NULL);
+}
+
+void EEVEE_materials_free(void)
+{
+ for (int i = 0; i < VAR_MAT_MAX; ++i) {
+ DRW_SHADER_FREE_SAFE(e_data.default_lit[i]);
+ }
+ MEM_SAFE_FREE(e_data.frag_shader_lib);
+ MEM_SAFE_FREE(e_data.frag_shader_lib);
+ MEM_SAFE_FREE(e_data.volume_shader_lib);
+ DRW_SHADER_FREE_SAFE(e_data.default_prepass_sh);
+ DRW_SHADER_FREE_SAFE(e_data.default_prepass_clip_sh);
+ DRW_SHADER_FREE_SAFE(e_data.default_background);
+ DRW_SHADER_FREE_SAFE(e_data.update_noise_sh);
+ DRW_TEXTURE_FREE_SAFE(e_data.util_tex);
+ DRW_TEXTURE_FREE_SAFE(e_data.noise_tex);
+}
+
+void EEVEE_draw_default_passes(EEVEE_PassList *psl)
+{
+ for (int i = 0; i < VAR_MAT_MAX; ++i) {
+ if (psl->default_pass[i]) {
+ DRW_draw_pass(psl->default_pass[i]);
+ }
+ }
+}
diff --git a/source/blender/draw/engines/eevee/eevee_mist.c b/source/blender/draw/engines/eevee/eevee_mist.c
new file mode 100644
index 00000000000..de9582611ec
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_mist.c
@@ -0,0 +1,139 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_mist.c
+ * \ingroup draw_engine
+ *
+ * Implementation of Blender Mist pass.
+ * IMPORTANT: This is a "post process" of the Z depth so it will lack any transparent objects.
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_world_types.h"
+
+#include "BLI_string_utils.h"
+
+#include "eevee_private.h"
+
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_effect_mist_frag_glsl[];
+
+static struct {
+ struct GPUShader *mist_sh;
+} e_data = {NULL}; /* Engine data */
+
+void EEVEE_mist_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_PrivateData *g_data = stl->g_data;
+ Scene *scene = draw_ctx->scene;
+
+ float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ if (e_data.mist_sh == NULL) {
+ char *frag_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_effect_mist_frag_glsl);
+
+ e_data.mist_sh = DRW_shader_create_fullscreen(frag_str, "#define FIRST_PASS\n");
+
+ MEM_freeN(frag_str);
+ }
+
+ /* Create FrameBuffer. */
+ DRW_texture_ensure_fullscreen_2D(&txl->mist_accum, GPU_R32F, 0); /* Should be enough precision for many samples. */
+
+ GPU_framebuffer_ensure_config(&fbl->mist_accum_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->mist_accum)
+ });
+
+ /* Clear texture. */
+ GPU_framebuffer_bind(fbl->mist_accum_fb);
+ GPU_framebuffer_clear_color(fbl->mist_accum_fb, clear);
+
+ /* Mist settings. */
+ if (scene && scene->world) {
+ g_data->mist_start = scene->world->miststa;
+ g_data->mist_inv_dist = (scene->world->mistdist > 0.0f) ? 1.0f / scene->world->mistdist : 0.0f;
+
+ switch (scene->world->mistype) {
+ case WO_MIST_QUADRATIC:
+ g_data->mist_falloff = 2.0f;
+ break;
+ case WO_MIST_LINEAR:
+ g_data->mist_falloff = 1.0f;
+ break;
+ case WO_MIST_INVERSE_QUADRATIC:
+ g_data->mist_falloff = 0.5f;
+ break;
+ }
+ }
+ else {
+ float near = -sldata->common_data.view_vecs[0][2];
+ float range = sldata->common_data.view_vecs[1][2];
+ /* Fallback */
+ g_data->mist_start = near;
+ g_data->mist_inv_dist = 1.0f / fabsf(range);
+ g_data->mist_falloff = 1.0f;
+ }
+
+ /* XXX ??!! WHY? If not it does not match cycles. */
+ g_data->mist_falloff *= 0.5f;
+
+ /* Create Pass and shgroup. */
+ psl->mist_accum_ps = DRW_pass_create("Mist Accum", DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.mist_sh, psl->mist_accum_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_uniform_vec3(grp, "mistSettings", &g_data->mist_start, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+}
+
+void EEVEE_mist_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_PassList *psl = vedata->psl;
+
+ if (fbl->mist_accum_fb != NULL) {
+ GPU_framebuffer_bind(fbl->mist_accum_fb);
+ DRW_draw_pass(psl->mist_accum_ps);
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+ }
+}
+
+void EEVEE_mist_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.mist_sh);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_motion_blur.c b/source/blender/draw/engines/eevee/eevee_motion_blur.c
new file mode 100644
index 00000000000..0c8f929ec0e
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_motion_blur.c
@@ -0,0 +1,214 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_motion_blur.c
+ * \ingroup draw_engine
+ *
+ * Gather all screen space effects technique such as Bloom, Motion Blur, DoF, SSAO, SSR, ...
+ */
+
+#include "DRW_render.h"
+
+#include "BKE_global.h" /* for G.debug_value */
+#include "BKE_camera.h"
+#include "BKE_object.h"
+#include "BKE_animsys.h"
+#include "BKE_screen.h"
+
+#include "DNA_anim_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_screen_types.h"
+
+#include "ED_screen.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "eevee_private.h"
+#include "GPU_texture.h"
+
+static struct {
+ /* Motion Blur */
+ struct GPUShader *motion_blur_sh;
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_effect_motion_blur_frag_glsl[];
+
+static void eevee_motion_blur_camera_get_matrix_at_time(
+ Scene *scene,
+ ARegion *ar, RegionView3D *rv3d, View3D *v3d,
+ Object *camera,
+ float time,
+ float r_mat[4][4])
+{
+ float obmat[4][4];
+
+ /* HACK */
+ Object cam_cpy; Camera camdata_cpy;
+ memcpy(&cam_cpy, camera, sizeof(cam_cpy));
+ memcpy(&camdata_cpy, camera->data, sizeof(camdata_cpy));
+ cam_cpy.data = &camdata_cpy;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ /* Past matrix */
+ /* FIXME : This is a temporal solution that does not take care of parent animations */
+ /* Recalc Anim manualy */
+ BKE_animsys_evaluate_animdata(scene, &cam_cpy.id, cam_cpy.adt, time, ADT_RECALC_ALL);
+ BKE_animsys_evaluate_animdata(scene, &camdata_cpy.id, camdata_cpy.adt, time, ADT_RECALC_ALL);
+ BKE_object_where_is_calc_time(draw_ctx->depsgraph, scene, &cam_cpy, time);
+
+ /* Compute winmat */
+ CameraParams params;
+ BKE_camera_params_init(&params);
+
+ if (v3d != NULL) {
+ BKE_camera_params_from_view3d(&params, draw_ctx->depsgraph, v3d, rv3d);
+ BKE_camera_params_compute_viewplane(&params, ar->winx, ar->winy, 1.0f, 1.0f);
+ }
+ else {
+ BKE_camera_params_from_object(&params, &cam_cpy);
+ BKE_camera_params_compute_viewplane(&params, scene->r.xsch, scene->r.ysch, scene->r.xasp, scene->r.yasp);
+ }
+
+ BKE_camera_params_compute_matrix(&params);
+
+ /* FIXME Should be done per view (MULTIVIEW) */
+ normalize_m4_m4(obmat, cam_cpy.obmat);
+ invert_m4(obmat);
+ mul_m4_m4m4(r_mat, params.winmat, obmat);
+}
+
+static void eevee_create_shader_motion_blur(void)
+{
+ e_data.motion_blur_sh = DRW_shader_create_fullscreen(datatoc_effect_motion_blur_frag_glsl, NULL);
+}
+
+int EEVEE_motion_blur_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, Object *camera)
+{
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ Scene *scene = draw_ctx->scene;
+ View3D *v3d = draw_ctx->v3d;
+ RegionView3D *rv3d = draw_ctx->rv3d;
+ ARegion *ar = draw_ctx->ar;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer,
+ RE_engine_id_BLENDER_EEVEE);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "motion_blur_enable")) {
+ /* Update Motion Blur Matrices */
+ if (camera) {
+ float persmat[4][4];
+ float ctime = BKE_scene_frame_get(scene);
+ float delta = BKE_collection_engine_property_value_get_float(props, "motion_blur_shutter");
+ Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, camera);
+
+ /* Current matrix */
+ eevee_motion_blur_camera_get_matrix_at_time(scene,
+ ar, rv3d, v3d,
+ camera_object,
+ ctime,
+ effects->current_ndc_to_world);
+
+ /* Viewport Matrix */
+ DRW_viewport_matrix_get(persmat, DRW_MAT_PERS);
+
+ /* Only continue if camera is not being keyed */
+ if (DRW_state_is_image_render() ||
+ compare_m4m4(persmat, effects->current_ndc_to_world, 0.0001f))
+ {
+ /* Past matrix */
+ eevee_motion_blur_camera_get_matrix_at_time(scene,
+ ar, rv3d, v3d,
+ camera_object,
+ ctime - delta,
+ effects->past_world_to_ndc);
+
+#if 0 /* for future high quality blur */
+ /* Future matrix */
+ eevee_motion_blur_camera_get_matrix_at_time(scene,
+ ar, rv3d, v3d,
+ camera_object,
+ ctime + delta,
+ effects->future_world_to_ndc);
+#endif
+ invert_m4(effects->current_ndc_to_world);
+
+ effects->motion_blur_samples = BKE_collection_engine_property_value_get_int(props,
+ "motion_blur_samples");
+
+ if (!e_data.motion_blur_sh) {
+ eevee_create_shader_motion_blur();
+ }
+
+ return EFFECT_MOTION_BLUR | EFFECT_POST_BUFFER;
+ }
+ }
+ }
+
+ return 0;
+}
+
+void EEVEE_motion_blur_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ if ((effects->enabled_effects & EFFECT_MOTION_BLUR) != 0) {
+ psl->motion_blur = DRW_pass_create("Motion Blur", DRW_STATE_WRITE_COLOR);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.motion_blur_sh, psl->motion_blur);
+ DRW_shgroup_uniform_int(grp, "samples", &effects->motion_blur_samples, 1);
+ DRW_shgroup_uniform_mat4(grp, "currInvViewProjMatrix", effects->current_ndc_to_world);
+ DRW_shgroup_uniform_mat4(grp, "pastViewProjMatrix", effects->past_world_to_ndc);
+ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &effects->source_buffer);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+}
+
+void EEVEE_motion_blur_draw(EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ /* Motion Blur */
+ if ((effects->enabled_effects & EFFECT_MOTION_BLUR) != 0) {
+ GPU_framebuffer_bind(effects->target_buffer);
+ DRW_draw_pass(psl->motion_blur);
+ SWAP_BUFFERS();
+ }
+}
+
+void EEVEE_motion_blur_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.motion_blur_sh);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_occlusion.c b/source/blender/draw/engines/eevee/eevee_occlusion.c
new file mode 100644
index 00000000000..7ad56327251
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_occlusion.c
@@ -0,0 +1,306 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_occlusion.c
+ * \ingroup draw_engine
+ *
+ * Implementation of the screen space Ground Truth Ambient Occlusion.
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_string_utils.h"
+
+#include "DNA_anim_types.h"
+
+#include "BKE_global.h" /* for G.debug_value */
+
+#include "eevee_private.h"
+
+static struct {
+ /* Ground Truth Ambient Occlusion */
+ struct GPUShader *gtao_sh;
+ struct GPUShader *gtao_layer_sh;
+ struct GPUShader *gtao_debug_sh;
+ struct GPUTexture *src_depth;
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_ambient_occlusion_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_effect_gtao_frag_glsl[];
+
+static void eevee_create_shader_occlusion(void)
+{
+ char *frag_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_ambient_occlusion_lib_glsl,
+ datatoc_effect_gtao_frag_glsl);
+
+ e_data.gtao_sh = DRW_shader_create_fullscreen(frag_str, NULL);
+ e_data.gtao_layer_sh = DRW_shader_create_fullscreen(frag_str, "#define LAYERED_DEPTH\n");
+ e_data.gtao_debug_sh = DRW_shader_create_fullscreen(frag_str, "#define DEBUG_AO\n");
+
+ MEM_freeN(frag_str);
+}
+
+int EEVEE_occlusion_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer,
+ RE_engine_id_BLENDER_EEVEE);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "gtao_enable")) {
+ const float *viewport_size = DRW_viewport_size_get();
+ const int fs_size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+
+ /* Shaders */
+ if (!e_data.gtao_sh) {
+ eevee_create_shader_occlusion();
+ }
+
+ common_data->ao_dist = BKE_collection_engine_property_value_get_float(props, "gtao_distance");
+ common_data->ao_factor = BKE_collection_engine_property_value_get_float(props, "gtao_factor");
+ common_data->ao_quality = 1.0f - BKE_collection_engine_property_value_get_float(props, "gtao_quality");
+
+ common_data->ao_settings = 1.0; /* USE_AO */
+ if (BKE_collection_engine_property_value_get_bool(props, "gtao_use_bent_normals")) {
+ common_data->ao_settings += 2.0; /* USE_BENT_NORMAL */
+ }
+ if (BKE_collection_engine_property_value_get_bool(props, "gtao_denoise")) {
+ common_data->ao_settings += 4.0; /* USE_DENOISE */
+ }
+
+ common_data->ao_bounce_fac = (float)BKE_collection_engine_property_value_get_bool(props, "gtao_bounce");
+
+ effects->gtao_horizons = DRW_texture_pool_query_2D(fs_size[0], fs_size[1], GPU_RGBA8,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->gtao_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->gtao_horizons)
+ });
+
+ if (G.debug_value == 6) {
+ effects->gtao_horizons_debug = DRW_texture_pool_query_2D(fs_size[0], fs_size[1], GPU_RGBA8,
+ &draw_engine_eevee_type);
+ GPU_framebuffer_ensure_config(&fbl->gtao_debug_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->gtao_horizons_debug)
+ });
+ }
+ else {
+ effects->gtao_horizons_debug = NULL;
+ }
+
+ return EFFECT_GTAO | EFFECT_NORMAL_BUFFER;
+ }
+
+ /* Cleanup */
+ effects->gtao_horizons = NULL;
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->gtao_fb);
+ common_data->ao_settings = 0.0f;
+
+ return 0;
+}
+
+void EEVEE_occlusion_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "gtao_enable")) {
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ DRW_texture_ensure_fullscreen_2D(&txl->ao_accum, GPU_R32F, 0); /* Should be enough precision for many samples. */
+
+ GPU_framebuffer_ensure_config(&fbl->ao_accum_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->ao_accum)
+ });
+
+ /* Clear texture. */
+ GPU_framebuffer_bind(fbl->ao_accum_fb);
+ GPU_framebuffer_clear_color(fbl->ao_accum_fb, clear);
+
+ /* Accumulation pass */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE;
+ psl->ao_accum_ps = DRW_pass_create("AO Accum", state);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.gtao_debug_sh, psl->ao_accum_ps);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "maxzBuffer", &txl->maxzbuffer);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_texture_ref(grp, "normalBuffer", &effects->ssr_normal_input);
+ DRW_shgroup_uniform_texture_ref(grp, "horizonBuffer", &effects->gtao_horizons);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+ else {
+ /* Cleanup to release memory */
+ DRW_TEXTURE_FREE_SAFE(txl->ao_accum);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->ao_accum_fb);
+ }
+}
+
+void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ if ((effects->enabled_effects & EFFECT_GTAO) != 0) {
+ /** Occlusion algorithm overview
+ *
+ * We separate the computation into 2 steps.
+ *
+ * - First we scan the neighborhood pixels to find the maximum horizon angle.
+ * We save this angle in a RG8 array texture.
+ *
+ * - Then we use this angle to compute occlusion with the shading normal at
+ * the shading stage. This let us do correct shadowing for each diffuse / specular
+ * lobe present in the shader using the correct normal.
+ **/
+ psl->ao_horizon_search = DRW_pass_create("GTAO Horizon Search", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.gtao_sh, psl->ao_horizon_search);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "maxzBuffer", &txl->maxzbuffer);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &effects->ao_src_depth);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ psl->ao_horizon_search_layer = DRW_pass_create("GTAO Horizon Search Layer", DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_create(e_data.gtao_layer_sh, psl->ao_horizon_search_layer);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "maxzBuffer", &txl->maxzbuffer);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBufferLayered", &effects->ao_src_depth);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_uniform_int(grp, "layer", &stl->effects->ao_depth_layer, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ if (G.debug_value == 6) {
+ psl->ao_horizon_debug = DRW_pass_create("GTAO Horizon Debug", DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_create(e_data.gtao_debug_sh, psl->ao_horizon_debug);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "maxzBuffer", &txl->maxzbuffer);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_texture_ref(grp, "normalBuffer", &effects->ssr_normal_input);
+ DRW_shgroup_uniform_texture_ref(grp, "horizonBuffer", &effects->gtao_horizons);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+ }
+}
+
+void EEVEE_occlusion_compute(
+ EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata, struct GPUTexture *depth_src, int layer)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & EFFECT_GTAO) != 0) {
+ DRW_stats_group_start("GTAO Horizon Scan");
+ effects->ao_src_depth = depth_src;
+ effects->ao_depth_layer = layer;
+
+ GPU_framebuffer_bind(fbl->gtao_fb);
+
+ if (layer >= 0) {
+ DRW_draw_pass(psl->ao_horizon_search_layer);
+ }
+ else {
+ DRW_draw_pass(psl->ao_horizon_search);
+ }
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+
+ DRW_stats_group_end();
+ }
+}
+
+void EEVEE_occlusion_draw_debug(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if (((effects->enabled_effects & EFFECT_GTAO) != 0) && (G.debug_value == 6)) {
+ DRW_stats_group_start("GTAO Debug");
+
+ GPU_framebuffer_bind(fbl->gtao_debug_fb);
+ DRW_draw_pass(psl->ao_horizon_debug);
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+
+ DRW_stats_group_end();
+ }
+}
+
+void EEVEE_occlusion_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_PassList *psl = vedata->psl;
+
+ if (fbl->ao_accum_fb != NULL) {
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ /* Update the min_max/horizon buffers so the refracion materials appear in it. */
+ EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1);
+ EEVEE_occlusion_compute(sldata, vedata, dtxl->depth, -1);
+
+ GPU_framebuffer_bind(fbl->ao_accum_fb);
+ DRW_draw_pass(psl->ao_accum_ps);
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+ }
+}
+
+void EEVEE_occlusion_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.gtao_sh);
+ DRW_SHADER_FREE_SAFE(e_data.gtao_layer_sh);
+ DRW_SHADER_FREE_SAFE(e_data.gtao_debug_sh);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_private.h b/source/blender/draw/engines/eevee/eevee_private.h
new file mode 100644
index 00000000000..7086351b408
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_private.h
@@ -0,0 +1,978 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_private.h
+ * \ingroup DNA
+ */
+
+#ifndef __EEVEE_PRIVATE_H__
+#define __EEVEE_PRIVATE_H__
+
+struct Object;
+struct EEVEE_BoundSphere;
+struct EEVEE_ShadowCasterBuffer;
+struct RenderLayer;
+struct RenderResult;
+
+extern struct DrawEngineType draw_engine_eevee_type;
+
+/* Minimum UBO is 16384 bytes */
+#define MAX_PROBE 128 /* TODO : find size by dividing UBO max size by probe data size */
+#define MAX_GRID 64 /* TODO : find size by dividing UBO max size by grid data size */
+#define MAX_PLANAR 16 /* TODO : find size by dividing UBO max size by grid data size */
+#define MAX_LIGHT 128 /* TODO : find size by dividing UBO max size by light data size */
+#define MAX_CASCADE_NUM 4
+#define MAX_SHADOW 256 /* TODO : Make this depends on GL_MAX_ARRAY_TEXTURE_LAYERS */
+#define MAX_SHADOW_CASCADE 8
+#define MAX_SHADOW_CUBE (MAX_SHADOW - MAX_CASCADE_NUM * MAX_SHADOW_CASCADE)
+#define MAX_BLOOM_STEP 16
+
+/* Only define one of these. */
+// #define IRRADIANCE_SH_L2
+// #define IRRADIANCE_CUBEMAP
+#define IRRADIANCE_HL2
+
+#if defined(IRRADIANCE_SH_L2)
+# define SHADER_IRRADIANCE "#define IRRADIANCE_SH_L2\n"
+#elif defined(IRRADIANCE_CUBEMAP)
+# define SHADER_IRRADIANCE "#define IRRADIANCE_CUBEMAP\n"
+#elif defined(IRRADIANCE_HL2)
+# define SHADER_IRRADIANCE "#define IRRADIANCE_HL2\n"
+#endif
+
+#define SHADER_DEFINES \
+ "#define EEVEE_ENGINE\n" \
+ "#define MAX_PROBE " STRINGIFY(MAX_PROBE) "\n" \
+ "#define MAX_GRID " STRINGIFY(MAX_GRID) "\n" \
+ "#define MAX_PLANAR " STRINGIFY(MAX_PLANAR) "\n" \
+ "#define MAX_LIGHT " STRINGIFY(MAX_LIGHT) "\n" \
+ "#define MAX_SHADOW " STRINGIFY(MAX_SHADOW) "\n" \
+ "#define MAX_SHADOW_CUBE " STRINGIFY(MAX_SHADOW_CUBE) "\n" \
+ "#define MAX_SHADOW_CASCADE " STRINGIFY(MAX_SHADOW_CASCADE) "\n" \
+ "#define MAX_CASCADE_NUM " STRINGIFY(MAX_CASCADE_NUM) "\n" \
+ SHADER_IRRADIANCE
+
+#define SWAP_DOUBLE_BUFFERS() { \
+ if (effects->swap_double_buffer) { \
+ SWAP(struct GPUFrameBuffer *, fbl->main_fb, fbl->double_buffer_fb); \
+ SWAP(struct GPUFrameBuffer *, fbl->main_color_fb, fbl->double_buffer_color_fb); \
+ SWAP(GPUTexture *, txl->color, txl->color_double_buffer); \
+ effects->swap_double_buffer = false; \
+ } \
+} ((void)0)
+
+#define SWAP_BUFFERS() { \
+ if (effects->target_buffer == fbl->effect_color_fb) { \
+ SWAP_DOUBLE_BUFFERS(); \
+ effects->source_buffer = txl->color_post; \
+ effects->target_buffer = fbl->main_color_fb; \
+ } \
+ else { \
+ SWAP_DOUBLE_BUFFERS(); \
+ effects->source_buffer = txl->color; \
+ effects->target_buffer = fbl->effect_color_fb; \
+ } \
+} ((void)0)
+
+/* World shader variations */
+enum {
+ VAR_WORLD_BACKGROUND = 0,
+ VAR_WORLD_PROBE = 1,
+ VAR_WORLD_VOLUME = 2,
+};
+
+/* Material shader variations */
+enum {
+ VAR_MAT_MESH = (1 << 0),
+ VAR_MAT_PROBE = (1 << 1),
+ VAR_MAT_HAIR = (1 << 2),
+ VAR_MAT_FLAT = (1 << 3),
+ VAR_MAT_BLEND = (1 << 4),
+ VAR_MAT_VSM = (1 << 5),
+ VAR_MAT_ESM = (1 << 6),
+ VAR_MAT_VOLUME = (1 << 7),
+ /* Max number of variation */
+ /* IMPORTANT : Leave it last and set
+ * it's value accordingly. */
+ VAR_MAT_MAX = (1 << 8),
+ /* These are options that are not counted in VAR_MAT_MAX
+ * because they are not cumulative with the others above. */
+ VAR_MAT_CLIP = (1 << 9),
+ VAR_MAT_HASH = (1 << 10),
+ VAR_MAT_MULT = (1 << 11),
+ VAR_MAT_SHADOW = (1 << 12),
+ VAR_MAT_REFRACT = (1 << 13),
+ VAR_MAT_SSS = (1 << 14),
+ VAR_MAT_TRANSLUC = (1 << 15),
+ VAR_MAT_SSSALBED = (1 << 16),
+};
+
+/* Shadow Technique */
+enum {
+ SHADOW_ESM = 1,
+ SHADOW_VSM = 2,
+ SHADOW_METHOD_MAX = 3,
+};
+
+typedef struct EEVEE_BoundSphere {
+ float center[3], radius;
+} EEVEE_BoundSphere;
+
+typedef struct EEVEE_BoundBox {
+ float center[3], halfdim[3];
+} EEVEE_BoundBox;
+
+typedef struct EEVEE_PassList {
+ /* Shadows */
+ struct DRWPass *shadow_pass;
+ struct DRWPass *shadow_cube_copy_pass;
+ struct DRWPass *shadow_cube_store_pass;
+ struct DRWPass *shadow_cascade_copy_pass;
+ struct DRWPass *shadow_cascade_store_pass;
+
+ /* Probes */
+ struct DRWPass *probe_background;
+ struct DRWPass *probe_glossy_compute;
+ struct DRWPass *probe_diffuse_compute;
+ struct DRWPass *probe_visibility_compute;
+ struct DRWPass *probe_grid_fill;
+ struct DRWPass *probe_display;
+ struct DRWPass *probe_planar_downsample_ps;
+
+ /* Effects */
+ struct DRWPass *ao_horizon_search;
+ struct DRWPass *ao_horizon_search_layer;
+ struct DRWPass *ao_horizon_debug;
+ struct DRWPass *ao_accum_ps;
+ struct DRWPass *mist_accum_ps;
+ struct DRWPass *motion_blur;
+ struct DRWPass *bloom_blit;
+ struct DRWPass *bloom_downsample_first;
+ struct DRWPass *bloom_downsample;
+ struct DRWPass *bloom_upsample;
+ struct DRWPass *bloom_resolve;
+ struct DRWPass *dof_down;
+ struct DRWPass *dof_scatter;
+ struct DRWPass *dof_resolve;
+ struct DRWPass *volumetric_world_ps;
+ struct DRWPass *volumetric_objects_ps;
+ struct DRWPass *volumetric_scatter_ps;
+ struct DRWPass *volumetric_integration_ps;
+ struct DRWPass *volumetric_resolve_ps;
+ struct DRWPass *ssr_raytrace;
+ struct DRWPass *ssr_resolve;
+ struct DRWPass *sss_blur_ps;
+ struct DRWPass *sss_resolve_ps;
+ struct DRWPass *sss_accum_ps;
+ struct DRWPass *color_downsample_ps;
+ struct DRWPass *color_downsample_cube_ps;
+ struct DRWPass *velocity_resolve;
+ struct DRWPass *taa_resolve;
+
+ /* HiZ */
+ struct DRWPass *minz_downlevel_ps;
+ struct DRWPass *maxz_downlevel_ps;
+ struct DRWPass *minz_downdepth_ps;
+ struct DRWPass *maxz_downdepth_ps;
+ struct DRWPass *minz_downdepth_layer_ps;
+ struct DRWPass *maxz_downdepth_layer_ps;
+ struct DRWPass *minz_copydepth_ps;
+ struct DRWPass *maxz_copydepth_ps;
+
+ struct DRWPass *depth_pass;
+ struct DRWPass *depth_pass_cull;
+ struct DRWPass *depth_pass_clip;
+ struct DRWPass *depth_pass_clip_cull;
+ struct DRWPass *refract_depth_pass;
+ struct DRWPass *refract_depth_pass_cull;
+ struct DRWPass *refract_depth_pass_clip;
+ struct DRWPass *refract_depth_pass_clip_cull;
+ struct DRWPass *default_pass[VAR_MAT_MAX];
+ struct DRWPass *sss_pass;
+ struct DRWPass *material_pass;
+ struct DRWPass *refract_pass;
+ struct DRWPass *transparent_pass;
+ struct DRWPass *background_pass;
+ struct DRWPass *update_noise_pass;
+} EEVEE_PassList;
+
+typedef struct EEVEE_FramebufferList {
+ /* Effects */
+ struct GPUFrameBuffer *gtao_fb;
+ struct GPUFrameBuffer *gtao_debug_fb;
+ struct GPUFrameBuffer *downsample_fb;
+ struct GPUFrameBuffer *bloom_blit_fb;
+ struct GPUFrameBuffer *bloom_down_fb[MAX_BLOOM_STEP];
+ struct GPUFrameBuffer *bloom_accum_fb[MAX_BLOOM_STEP - 1];
+ struct GPUFrameBuffer *sss_blur_fb;
+ struct GPUFrameBuffer *sss_resolve_fb;
+ struct GPUFrameBuffer *sss_clear_fb;
+ struct GPUFrameBuffer *sss_accum_fb;
+ struct GPUFrameBuffer *dof_down_fb;
+ struct GPUFrameBuffer *dof_scatter_far_fb;
+ struct GPUFrameBuffer *dof_scatter_near_fb;
+ struct GPUFrameBuffer *volumetric_fb;
+ struct GPUFrameBuffer *volumetric_scat_fb;
+ struct GPUFrameBuffer *volumetric_integ_fb;
+ struct GPUFrameBuffer *screen_tracing_fb;
+ struct GPUFrameBuffer *refract_fb;
+ struct GPUFrameBuffer *mist_accum_fb;
+ struct GPUFrameBuffer *ao_accum_fb;
+ struct GPUFrameBuffer *velocity_resolve_fb;
+
+ struct GPUFrameBuffer *update_noise_fb;
+
+ struct GPUFrameBuffer *planarref_fb;
+ struct GPUFrameBuffer *planar_downsample_fb;
+
+ struct GPUFrameBuffer *main_fb;
+ struct GPUFrameBuffer *main_color_fb;
+ struct GPUFrameBuffer *effect_fb;
+ struct GPUFrameBuffer *effect_color_fb;
+ struct GPUFrameBuffer *double_buffer_fb;
+ struct GPUFrameBuffer *double_buffer_color_fb;
+ struct GPUFrameBuffer *double_buffer_depth_fb;
+} EEVEE_FramebufferList;
+
+typedef struct EEVEE_TextureList {
+ /* Effects */
+ struct GPUTexture *color_post; /* R16_G16_B16 */
+ struct GPUTexture *mist_accum;
+ struct GPUTexture *ao_accum;
+ struct GPUTexture *sss_dir_accum;
+ struct GPUTexture *sss_col_accum;
+ struct GPUTexture *refract_color;
+
+ struct GPUTexture *volume_prop_scattering;
+ struct GPUTexture *volume_prop_extinction;
+ struct GPUTexture *volume_prop_emission;
+ struct GPUTexture *volume_prop_phase;
+ struct GPUTexture *volume_scatter;
+ struct GPUTexture *volume_transmittance;
+ struct GPUTexture *volume_scatter_history;
+ struct GPUTexture *volume_transmittance_history;
+
+ struct GPUTexture *planar_pool;
+ struct GPUTexture *planar_depth;
+
+ struct GPUTexture *maxzbuffer;
+
+ struct GPUTexture *color; /* R16_G16_B16 */
+ struct GPUTexture *color_double_buffer;
+ struct GPUTexture *depth_double_buffer;
+} EEVEE_TextureList;
+
+typedef struct EEVEE_StorageList {
+ /* Effects */
+ struct EEVEE_EffectsInfo *effects;
+
+ struct EEVEE_PrivateData *g_data;
+} EEVEE_StorageList;
+
+/* ************ LIGHT UBO ************* */
+typedef struct EEVEE_Light {
+ float position[3], dist;
+ float color[3], spec;
+ float spotsize, spotblend, radius, shadowid;
+ float rightvec[3], sizex;
+ float upvec[3], sizey;
+ float forwardvec[3], lamptype;
+} EEVEE_Light;
+
+typedef struct EEVEE_Shadow {
+ float near, far, bias, exp;
+ float shadow_start, data_start, multi_shadow_count, shadow_blur;
+ float contact_dist, contact_bias, contact_spread, contact_thickness;
+} EEVEE_Shadow;
+
+typedef struct EEVEE_ShadowCube {
+ float position[3], pad;
+} EEVEE_ShadowCube;
+
+typedef struct EEVEE_ShadowCascade {
+ float shadowmat[MAX_CASCADE_NUM][4][4]; /* World->Lamp->NDC->Tex : used for sampling the shadow map. */
+ float split_start[4];
+ float split_end[4];
+} EEVEE_ShadowCascade;
+
+typedef struct EEVEE_ShadowRender {
+ float position[3], pad;
+ float cube_texel_size;
+ float stored_texel_size;
+ float clip_near;
+ float clip_far;
+ int shadow_samples_ct;
+ float shadow_inv_samples_ct;
+} EEVEE_ShadowRender;
+
+/* This is just a really long bitflag with special function to access it. */
+#define MAX_LIGHTBITS_FIELDS (MAX_LIGHT / 8)
+typedef struct EEVEE_LightBits {
+ unsigned char fields[MAX_LIGHTBITS_FIELDS];
+} EEVEE_LightBits;
+
+typedef struct EEVEE_ShadowCaster {
+ struct EEVEE_LightBits bits;
+ struct EEVEE_BoundBox bbox;
+} EEVEE_ShadowCaster;
+
+typedef struct EEVEE_ShadowCasterBuffer {
+ struct EEVEE_ShadowCaster *shadow_casters;
+ char *flags;
+ unsigned int alloc_count;
+ unsigned int count;
+} EEVEE_ShadowCasterBuffer;
+
+/* ************ LIGHT DATA ************* */
+typedef struct EEVEE_LampsInfo {
+ int num_light, cache_num_light;
+ int num_cube_layer, cache_num_cube_layer;
+ int num_cascade_layer, cache_num_cascade_layer;
+ int gpu_cube_ct, gpu_cascade_ct, gpu_shadow_ct;
+ int cpu_cube_ct, cpu_cascade_ct;
+ int update_flag;
+ int shadow_cube_size, shadow_cascade_size, shadow_method;
+ bool shadow_high_bitdepth;
+ int shadow_cube_store_size;
+ int current_shadow_cascade;
+ int current_shadow_face;
+ unsigned int shadow_instance_count;
+ float filter_size;
+ /* List of lights in the scene. */
+ /* XXX This is fragile, can get out of sync quickly. */
+ struct Object *light_ref[MAX_LIGHT];
+ struct Object *shadow_cube_ref[MAX_SHADOW_CUBE];
+ struct Object *shadow_cascade_ref[MAX_SHADOW_CASCADE];
+ /* UBO Storage : data used by UBO */
+ struct EEVEE_Light light_data[MAX_LIGHT];
+ struct EEVEE_ShadowRender shadow_render_data;
+ struct EEVEE_Shadow shadow_data[MAX_SHADOW];
+ struct EEVEE_ShadowCube shadow_cube_data[MAX_SHADOW_CUBE];
+ struct EEVEE_ShadowCascade shadow_cascade_data[MAX_SHADOW_CASCADE];
+ /* Lights tracking */
+ int new_shadow_id[MAX_LIGHT]; /* To be able to convert old bitfield to new bitfield */
+ struct EEVEE_BoundSphere shadow_bounds[MAX_LIGHT]; /* Tighly packed light bounds */
+ /* Pointers only. */
+ struct EEVEE_ShadowCasterBuffer *shcaster_frontbuffer;
+ struct EEVEE_ShadowCasterBuffer *shcaster_backbuffer;
+} EEVEE_LampsInfo;
+
+/* EEVEE_LampsInfo->shadow_casters_flag */
+enum {
+ SHADOW_CASTER_PRUNED = (1 << 0),
+ SHADOW_CASTER_UPDATED = (1 << 1),
+};
+
+/* EEVEE_LampsInfo->update_flag */
+enum {
+ LIGHT_UPDATE_SHADOW_CUBE = (1 << 0),
+};
+
+/* ************ PROBE UBO ************* */
+typedef struct EEVEE_LightProbe {
+ float position[3], parallax_type;
+ float attenuation_fac;
+ float attenuation_type;
+ float pad3[2];
+ float attenuationmat[4][4];
+ float parallaxmat[4][4];
+} EEVEE_LightProbe;
+
+typedef struct EEVEE_LightGrid {
+ float mat[4][4];
+ int resolution[3], offset;
+ float corner[3], attenuation_scale;
+ float increment_x[3], attenuation_bias; /* world space vector between 2 opposite cells */
+ float increment_y[3], level_bias;
+ float increment_z[3], pad4;
+ float visibility_bias, visibility_bleed, visibility_range, pad5;
+} EEVEE_LightGrid;
+
+typedef struct EEVEE_PlanarReflection {
+ float plane_equation[4];
+ float clip_vec_x[3], attenuation_scale;
+ float clip_vec_y[3], attenuation_bias;
+ float clip_edge_x_pos, clip_edge_x_neg;
+ float clip_edge_y_pos, clip_edge_y_neg;
+ float facing_scale, facing_bias, pad[2];
+ float reflectionmat[4][4];
+} EEVEE_PlanarReflection;
+
+/* ************ PROBE DATA ************* */
+
+typedef struct EEVEE_LightProbeVisTest {
+ bool invert;
+ bool cached; /* Reuse last test results */
+ struct Group *group; /* Skip test if NULL */
+} EEVEE_LightProbeVisTest;
+
+typedef struct EEVEE_LightProbesInfo {
+ int num_cube, cache_num_cube;
+ int num_grid, cache_num_grid;
+ int num_planar, cache_num_planar;
+ int total_irradiance_samples; /* Total for all grids */
+ int cache_irradiance_size[3];
+ int update_flag;
+ int updated_bounce;
+ int num_bounce;
+ int cubemap_res;
+ int target_size;
+ int grid_initialized;
+ struct World *prev_world;
+ int update_world;
+ bool prev_wo_sh_compiled;
+ bool do_cube_update;
+ bool all_materials_updated;
+ /* For rendering probes */
+ float probemat[6][4][4];
+ int layer;
+ float texel_size;
+ float padding_size;
+ float samples_ct;
+ float invsamples_ct;
+ float near_clip;
+ float far_clip;
+ float roughness;
+ float lodfactor;
+ float lod_rt_max, lod_cube_max, lod_planar_max;
+ float visibility_range;
+ float visibility_blur;
+ float intensity_fac;
+ int shres;
+ /* List of probes in the scene. */
+ /* XXX This is fragile, can get out of sync quickly. */
+ struct Object *probes_cube_ref[MAX_PROBE];
+ struct Object *probes_grid_ref[MAX_GRID];
+ struct Object *probes_planar_ref[MAX_PLANAR];
+ /* UBO Storage : data used by UBO */
+ struct EEVEE_LightProbe probe_data[MAX_PROBE];
+ struct EEVEE_LightGrid grid_data[MAX_GRID];
+ struct EEVEE_PlanarReflection planar_data[MAX_PLANAR];
+ /* Probe Visibility Group */
+ EEVEE_LightProbeVisTest vis_data;
+} EEVEE_LightProbesInfo;
+
+/* EEVEE_LightProbesInfo->update_flag */
+enum {
+ PROBE_UPDATE_CUBE = (1 << 0),
+ PROBE_UPDATE_GRID = (1 << 1),
+ PROBE_UPDATE_ALL = 0xFFFFFF,
+};
+
+/* ************ EFFECTS DATA ************* */
+
+typedef enum EEVEE_EffectsFlag {
+ EFFECT_MOTION_BLUR = (1 << 0),
+ EFFECT_BLOOM = (1 << 1),
+ EFFECT_DOF = (1 << 2),
+ EFFECT_VOLUMETRIC = (1 << 3),
+ EFFECT_SSR = (1 << 4),
+ EFFECT_DOUBLE_BUFFER = (1 << 5), /* Not really an effect but a feature */
+ EFFECT_REFRACT = (1 << 6),
+ EFFECT_GTAO = (1 << 7),
+ EFFECT_TAA = (1 << 8),
+ EFFECT_POST_BUFFER = (1 << 9), /* Not really an effect but a feature */
+ EFFECT_NORMAL_BUFFER = (1 << 10), /* Not really an effect but a feature */
+ EFFECT_SSS = (1 << 11),
+ EFFECT_VELOCITY_BUFFER = (1 << 12), /* Not really an effect but a feature */
+ EFFECT_TAA_REPROJECT = (1 << 13), /* should be mutually exclusive with EFFECT_TAA */
+ EFFECT_DEPTH_DOUBLE_BUFFER = (1 << 14), /* Not really an effect but a feature */
+} EEVEE_EffectsFlag;
+
+typedef struct EEVEE_EffectsInfo {
+ EEVEE_EffectsFlag enabled_effects;
+ bool swap_double_buffer;
+ /* SSSS */
+ int sss_sample_count;
+ bool sss_separate_albedo;
+ struct GPUTexture *sss_data; /* Textures from pool */
+ struct GPUTexture *sss_albedo;
+ struct GPUTexture *sss_blur;
+ struct GPUTexture *sss_stencil;
+ /* Volumetrics */
+ int volume_current_sample;
+ /* SSR */
+ bool reflection_trace_full;
+ int ssr_neighbor_ofs;
+ int ssr_halfres_ofs[2];
+ struct GPUTexture *ssr_normal_input; /* Textures from pool */
+ struct GPUTexture *ssr_specrough_input;
+ struct GPUTexture *ssr_hit_output;
+ struct GPUTexture *ssr_pdf_output;
+ /* Temporal Anti Aliasing */
+ int taa_reproject_sample;
+ int taa_current_sample;
+ int taa_render_sample;
+ int taa_total_sample;
+ float taa_alpha;
+ bool prev_drw_support;
+ float prev_drw_persmat[4][4];
+ float overide_persmat[4][4];
+ float overide_persinv[4][4];
+ float overide_winmat[4][4];
+ float overide_wininv[4][4];
+ /* Ambient Occlusion */
+ int ao_depth_layer;
+ struct GPUTexture *ao_src_depth; /* pointer copy */
+ struct GPUTexture *gtao_horizons; /* Textures from pool */
+ struct GPUTexture *gtao_horizons_debug;
+ /* Motion Blur */
+ float current_ndc_to_world[4][4];
+ float past_world_to_ndc[4][4];
+ int motion_blur_samples;
+ /* Velocity Pass */
+ float velocity_curr_persinv[4][4];
+ float velocity_past_persmat[4][4];
+ struct GPUTexture *velocity_tx; /* Texture from pool */
+ /* Depth Of Field */
+ float dof_near_far[2];
+ float dof_params[3];
+ float dof_bokeh[4];
+ float dof_layer_select[2];
+ int dof_target_size[2];
+ struct GPUTexture *dof_down_near; /* Textures from pool */
+ struct GPUTexture *dof_down_far;
+ struct GPUTexture *dof_coc;
+ struct GPUTexture *dof_near_blur;
+ struct GPUTexture *dof_far_blur;
+ /* Other */
+ float prev_persmat[4][4];
+ /* Bloom */
+ int bloom_iteration_ct;
+ float source_texel_size[2];
+ float blit_texel_size[2];
+ float downsamp_texel_size[MAX_BLOOM_STEP][2];
+ float bloom_color[3];
+ float bloom_clamp;
+ float bloom_sample_scale;
+ float bloom_curve_threshold[4];
+ float unf_source_texel_size[2];
+ struct GPUTexture *bloom_blit; /* Textures from pool */
+ struct GPUTexture *bloom_downsample[MAX_BLOOM_STEP];
+ struct GPUTexture *bloom_upsample[MAX_BLOOM_STEP - 1];
+ struct GPUTexture *unf_source_buffer; /* pointer copy */
+ struct GPUTexture *unf_base_buffer; /* pointer copy */
+ /* Not alloced, just a copy of a *GPUtexture in EEVEE_TextureList. */
+ struct GPUTexture *source_buffer; /* latest updated texture */
+ struct GPUFrameBuffer *target_buffer; /* next target to render to */
+ struct GPUTexture *final_tx; /* Final color to transform to display color space. */
+ struct GPUFrameBuffer *final_fb; /* Framebuffer with final_tx as attachement. */
+} EEVEE_EffectsInfo;
+
+/* ***************** COMMON DATA **************** */
+
+/* Common uniform buffer containing all "constant" data over the whole drawing pipeline. */
+/* !! CAUTION !!
+ * - [i]vec3 need to be paded to [i]vec4 (even in ubo declaration).
+ * - Make sure that [i]vec4 start at a multiple of 16 bytes.
+ * - Arrays of vec2/vec3 are padded as arrays of vec4.
+ * - sizeof(bool) == sizeof(int) in GLSL so use int in C */
+typedef struct EEVEE_CommonUniformBuffer {
+ float prev_persmat[4][4]; /* mat4 */
+ float view_vecs[2][4]; /* vec4[2] */
+ float mip_ratio[10][4]; /* vec2[10] */
+ /* Ambient Occlusion */
+ /* -- 16 byte aligned -- */
+ float ao_dist, pad1, ao_factor, pad2; /* vec4 */
+ float ao_offset, ao_bounce_fac, ao_quality, ao_settings; /* vec4 */
+ /* Volumetric */
+ /* -- 16 byte aligned -- */
+ int vol_tex_size[3], pad3; /* ivec3 */
+ float vol_depth_param[3], pad4; /* vec3 */
+ float vol_inv_tex_size[3], pad5; /* vec3 */
+ float vol_jitter[3], pad6; /* vec3 */
+ float vol_coord_scale[2], pad7[2]; /* vec2 */
+ /* -- 16 byte aligned -- */
+ float vol_history_alpha; /* float */
+ float vol_light_clamp; /* float */
+ float vol_shadow_steps; /* float */
+ int vol_use_lights; /* bool */
+ /* Screen Space Reflections */
+ /* -- 16 byte aligned -- */
+ float ssr_quality, ssr_thickness, ssr_pixelsize[2]; /* vec4 */
+ float ssr_border_fac; /* float */
+ float ssr_max_roughness; /* float */
+ float ssr_firefly_fac; /* float */
+ float ssr_brdf_bias; /* float */
+ int ssr_toggle; /* bool */
+ /* SubSurface Scattering */
+ float sss_jitter_threshold; /* float */
+ int sss_toggle; /* bool */
+ /* Specular */
+ int spec_toggle; /* bool */
+ /* Lamps */
+ int la_num_light; /* int */
+ /* Probes */
+ int prb_num_planar; /* int */
+ int prb_num_render_cube; /* int */
+ int prb_num_render_grid; /* int */
+ int prb_irradiance_vis_size; /* int */
+ float prb_lod_cube_max; /* float */
+ float prb_lod_planar_max; /* float */
+} EEVEE_CommonUniformBuffer;
+
+/* ***************** CLIP PLANES DATA **************** */
+
+typedef struct EEVEE_ClipPlanesUniformBuffer {
+ float clip_planes[1][4]; /* must be less than MAX_CLIP_PLANES */
+} EEVEE_ClipPlanesUniformBuffer;
+
+/* ************** SCENE LAYER DATA ************** */
+typedef struct EEVEE_ViewLayerData {
+ /* Lamps */
+ struct EEVEE_LampsInfo *lamps;
+
+ struct GPUUniformBuffer *light_ubo;
+ struct GPUUniformBuffer *shadow_ubo;
+ struct GPUUniformBuffer *shadow_render_ubo;
+ struct GPUUniformBuffer *shadow_samples_ubo;
+
+ struct GPUFrameBuffer *shadow_cube_target_fb;
+ struct GPUFrameBuffer *shadow_cube_store_fb;
+ struct GPUFrameBuffer *shadow_cascade_target_fb;
+ struct GPUFrameBuffer *shadow_cascade_store_fb;
+
+ struct GPUTexture *shadow_cube_target;
+ struct GPUTexture *shadow_cube_blur;
+ struct GPUTexture *shadow_cascade_target;
+ struct GPUTexture *shadow_cascade_blur;
+ struct GPUTexture *shadow_cube_pool;
+ struct GPUTexture *shadow_cascade_pool;
+
+ struct EEVEE_ShadowCasterBuffer shcasters_buffers[2];
+
+ /* Probes */
+ struct EEVEE_LightProbesInfo *probes;
+
+ struct GPUUniformBuffer *probe_ubo;
+ struct GPUUniformBuffer *grid_ubo;
+ struct GPUUniformBuffer *planar_ubo;
+
+ struct GPUFrameBuffer *probe_filter_fb;
+ struct GPUFrameBuffer *probe_face_fb[6];
+
+ struct GPUTexture *probe_rt;
+ struct GPUTexture *probe_depth_rt;
+ struct GPUTexture *probe_pool;
+ struct GPUTexture *irradiance_pool;
+ struct GPUTexture *irradiance_rt;
+
+ /* Common Uniform Buffer */
+ struct EEVEE_CommonUniformBuffer common_data;
+ struct GPUUniformBuffer *common_ubo;
+
+ struct EEVEE_ClipPlanesUniformBuffer clip_data;
+ struct GPUUniformBuffer *clip_ubo;
+} EEVEE_ViewLayerData;
+
+/* ************ OBJECT DATA ************ */
+typedef struct EEVEE_LightData {
+ short light_id, shadow_id;
+} EEVEE_LightData;
+
+typedef struct EEVEE_ShadowCubeData {
+ short light_id, shadow_id, cube_id, layer_id;
+} EEVEE_ShadowCubeData;
+
+typedef struct EEVEE_ShadowCascadeData {
+ short light_id, shadow_id, cascade_id, layer_id;
+ float viewprojmat[MAX_CASCADE_NUM][4][4]; /* World->Lamp->NDC : used for rendering the shadow map. */
+ float projmat[MAX_CASCADE_NUM][4][4];
+ float viewmat[4][4], viewinv[4][4];
+ float radius[MAX_CASCADE_NUM];
+} EEVEE_ShadowCascadeData;
+
+/* Theses are the structs stored inside Objects.
+ * It works with even if the object is in multiple layers
+ * because we don't get the same "Object *" for each layer. */
+typedef struct EEVEE_LampEngineData {
+ ObjectEngineData engine_data;
+
+ bool need_update;
+ /* This needs to be out of the union to avoid undefined behaviour. */
+ short prev_cube_shadow_id;
+ union {
+ struct EEVEE_LightData ld;
+ struct EEVEE_ShadowCubeData scd;
+ struct EEVEE_ShadowCascadeData scad;
+ } data;
+} EEVEE_LampEngineData;
+
+typedef struct EEVEE_LightProbeEngineData {
+ ObjectEngineData engine_data;
+
+ /* NOTE: need_full_update is set by dependency graph when the probe or it's
+ * object is updated. This triggers full probe update, including it's
+ * "progressive" GI refresh.
+ *
+ * need_update is always set to truth when need_full_update is tagged, but
+ * might also be forced to be kept truth during GI refresh stages.
+ *
+ * TODO(sergey): Is there a way to avoid two flags here, or at least make
+ * it more clear what's going on here?
+ */
+ bool need_full_update;
+ bool need_update;
+
+ bool ready_to_shade;
+ int updated_cells;
+ int updated_lvl;
+ int num_cell;
+ int max_lvl;
+ int probe_id; /* Only used for display data */
+ float probe_size; /* Only used for display data */
+ DRWMatrixState mats; /* For planar probes */
+ float planer_eq_offset[4];
+ struct ListBase captured_object_list;
+} EEVEE_LightProbeEngineData;
+
+typedef struct EEVEE_ObjectEngineData {
+ ObjectEngineData engine_data;
+
+ Object *ob; /* self reference */
+ EEVEE_LightProbeVisTest *test_data;
+ bool ob_vis, ob_vis_dirty;
+
+ bool need_update;
+ unsigned int shadow_caster_id;
+} EEVEE_ObjectEngineData;
+
+/* *********************************** */
+
+typedef struct EEVEE_Data {
+ void *engine_type;
+ EEVEE_FramebufferList *fbl;
+ EEVEE_TextureList *txl;
+ EEVEE_PassList *psl;
+ EEVEE_StorageList *stl;
+} EEVEE_Data;
+
+typedef struct EEVEE_PrivateData {
+ struct DRWShadingGroup *shadow_shgrp;
+ struct DRWShadingGroup *depth_shgrp;
+ struct DRWShadingGroup *depth_shgrp_cull;
+ struct DRWShadingGroup *depth_shgrp_clip;
+ struct DRWShadingGroup *depth_shgrp_clip_cull;
+ struct DRWShadingGroup *refract_depth_shgrp;
+ struct DRWShadingGroup *refract_depth_shgrp_cull;
+ struct DRWShadingGroup *refract_depth_shgrp_clip;
+ struct DRWShadingGroup *refract_depth_shgrp_clip_cull;
+ struct DRWShadingGroup *cube_display_shgrp;
+ struct DRWShadingGroup *planar_display_shgrp;
+ struct GHash *material_hash;
+ struct GHash *hair_material_hash;
+ float background_alpha; /* TODO find a better place for this. */
+ /* For planar probes */
+ float planar_texel_size[2];
+ /* For double buffering */
+ bool view_updated;
+ bool valid_double_buffer;
+ /* Render Matrices */
+ float persmat[4][4], persinv[4][4];
+ float viewmat[4][4], viewinv[4][4];
+ float winmat[4][4], wininv[4][4];
+ /* Mist Settings */
+ float mist_start, mist_inv_dist, mist_falloff;
+} EEVEE_PrivateData; /* Transient data */
+
+/* eevee_data.c */
+EEVEE_ViewLayerData *EEVEE_view_layer_data_get(void);
+EEVEE_ViewLayerData *EEVEE_view_layer_data_ensure(void);
+EEVEE_ObjectEngineData *EEVEE_object_data_get(Object *ob);
+EEVEE_ObjectEngineData *EEVEE_object_data_ensure(Object *ob);
+EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_get(Object *ob);
+EEVEE_LightProbeEngineData *EEVEE_lightprobe_data_ensure(Object *ob);
+EEVEE_LampEngineData *EEVEE_lamp_data_get(Object *ob);
+EEVEE_LampEngineData *EEVEE_lamp_data_ensure(Object *ob);
+
+/* eevee_materials.c */
+struct GPUTexture *EEVEE_materials_get_util_tex(void); /* XXX */
+void EEVEE_materials_init(EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, EEVEE_FramebufferList *fbl);
+void EEVEE_materials_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_materials_cache_populate(EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob, bool *cast_shadow);
+void EEVEE_materials_cache_finish(EEVEE_Data *vedata);
+struct GPUMaterial *EEVEE_material_world_lightprobe_get(struct Scene *scene, struct World *wo);
+struct GPUMaterial *EEVEE_material_world_background_get(struct Scene *scene, struct World *wo);
+struct GPUMaterial *EEVEE_material_world_volume_get(struct Scene *scene, struct World *wo);
+struct GPUMaterial *EEVEE_material_mesh_get(
+ struct Scene *scene, Material *ma, EEVEE_Data *vedata,
+ bool use_blend, bool use_multiply, bool use_refract, bool use_sss, bool use_translucency, int shadow_method);
+struct GPUMaterial *EEVEE_material_mesh_volume_get(struct Scene *scene, Material *ma);
+struct GPUMaterial *EEVEE_material_mesh_depth_get(struct Scene *scene, Material *ma, bool use_hashed_alpha, bool is_shadow);
+struct GPUMaterial *EEVEE_material_hair_get(struct Scene *scene, Material *ma, int shadow_method);
+void EEVEE_materials_free(void);
+void EEVEE_draw_default_passes(EEVEE_PassList *psl);
+void EEVEE_update_noise(EEVEE_PassList *psl, EEVEE_FramebufferList *fbl, const double offsets[3]);
+
+/* eevee_lights.c */
+void EEVEE_lights_init(EEVEE_ViewLayerData *sldata);
+void EEVEE_lights_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_lights_cache_add(EEVEE_ViewLayerData *sldata, struct Object *ob);
+void EEVEE_lights_cache_shcaster_add(
+ EEVEE_ViewLayerData *sldata, EEVEE_StorageList *stl, struct Gwn_Batch *geom, Object *ob);
+void EEVEE_lights_cache_shcaster_material_add(
+ EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl,
+ struct GPUMaterial *gpumat, struct Gwn_Batch *geom, struct Object *ob,
+ float *alpha_threshold);
+void EEVEE_lights_cache_shcaster_object_add(EEVEE_ViewLayerData *sldata, struct Object *ob);
+void EEVEE_lights_cache_finish(EEVEE_ViewLayerData *sldata);
+void EEVEE_lights_update(EEVEE_ViewLayerData *sldata);
+void EEVEE_draw_shadows(EEVEE_ViewLayerData *sldata, EEVEE_PassList *psl);
+void EEVEE_lights_free(void);
+
+/* eevee_lightprobes.c */
+bool EEVEE_lightprobes_obj_visibility_cb(bool vis_in, void *user_data);
+bool EEVEE_lightprobes_all_probes_ready(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_lightprobes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_lightprobes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_lightprobes_cache_add(EEVEE_ViewLayerData *sldata, Object *ob);
+void EEVEE_lightprobes_cache_finish(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_lightprobes_refresh(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_lightprobes_refresh_planar(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_lightprobes_free(void);
+
+/* eevee_depth_of_field.c */
+int EEVEE_depth_of_field_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Object *camera);
+void EEVEE_depth_of_field_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_depth_of_field_draw(EEVEE_Data *vedata);
+void EEVEE_depth_of_field_free(void);
+
+/* eevee_bloom.c */
+int EEVEE_bloom_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_bloom_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_bloom_draw(EEVEE_Data *vedata);
+void EEVEE_bloom_free(void);
+
+/* eevee_occlusion.c */
+int EEVEE_occlusion_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_occlusion_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_occlusion_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_occlusion_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_occlusion_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, struct GPUTexture *depth_src, int layer);
+void EEVEE_occlusion_draw_debug(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_occlusion_free(void);
+
+/* eevee_screen_raytrace.c */
+int EEVEE_screen_raytrace_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_refraction_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_reflection_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_screen_raytrace_free(void);
+
+/* eevee_subsurface.c */
+int EEVEE_subsurface_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_subsurface_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_subsurface_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_subsurface_add_pass(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, unsigned int sss_id, struct GPUUniformBuffer *sss_profile);
+void EEVEE_subsurface_data_render(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_subsurface_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_subsurface_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_subsurface_free(void);
+
+/* eevee_motion_blur.c */
+int EEVEE_motion_blur_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Object *camera);
+void EEVEE_motion_blur_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_motion_blur_draw(EEVEE_Data *vedata);
+void EEVEE_motion_blur_free(void);
+
+/* eevee_mist.c */
+void EEVEE_mist_output_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_mist_output_accumulate(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);;
+void EEVEE_mist_free(void);
+
+/* eevee_temporal_sampling.c */
+int EEVEE_temporal_sampling_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_temporal_sampling_matrices_calc(
+ EEVEE_EffectsInfo *effects, float viewmat[4][4], float persmat[4][4], const double ht_point[2]);
+void EEVEE_temporal_sampling_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_temporal_sampling_draw(EEVEE_Data *vedata);
+void EEVEE_temporal_sampling_free(void);
+
+/* eevee_volumes.c */
+int EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_volumes_set_jitter(EEVEE_ViewLayerData *sldata, unsigned int current_sample);
+void EEVEE_volumes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, struct Scene *scene, Object *ob);
+void EEVEE_volumes_compute(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_volumes_resolve(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_volumes_free_smoke_textures(void);
+void EEVEE_volumes_free(void);
+
+/* eevee_effects.c */
+void EEVEE_effects_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Object *camera);
+void EEVEE_effects_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_create_minmax_buffer(EEVEE_Data *vedata, struct GPUTexture *depth_src, int layer);
+void EEVEE_downsample_buffer(EEVEE_Data *vedata, struct GPUTexture *texture_src, int level);
+void EEVEE_downsample_cube_buffer(EEVEE_Data *vedata, struct GPUTexture *texture_src, int level);
+void EEVEE_effects_do_gtao(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_draw_effects(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata);
+void EEVEE_effects_free(void);
+
+/* eevee_render.c */
+void EEVEE_render_init(EEVEE_Data *vedata, struct RenderEngine *engine, struct Depsgraph *depsgraph);
+void EEVEE_render_cache(void *vedata, struct Object *ob, struct RenderEngine *engine, struct Depsgraph *depsgraph);
+void EEVEE_render_draw(EEVEE_Data *vedata, struct RenderEngine *engine, struct RenderLayer *render_layer, const struct rcti *rect);
+void EEVEE_render_update_passes(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer);
+
+/* Shadow Matrix */
+static const float texcomat[4][4] = { /* From NDC to TexCo */
+ {0.5f, 0.0f, 0.0f, 0.0f},
+ {0.0f, 0.5f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 0.5f, 0.0f},
+ {0.5f, 0.5f, 0.5f, 1.0f}
+};
+
+/* Cubemap Matrices */
+static const float cubefacemat[6][4][4] = {
+ /* Pos X */
+ {{0.0f, 0.0f, -1.0f, 0.0f},
+ {0.0f, -1.0f, 0.0f, 0.0f},
+ {-1.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 1.0f}},
+ /* Neg X */
+ {{0.0f, 0.0f, 1.0f, 0.0f},
+ {0.0f, -1.0f, 0.0f, 0.0f},
+ {1.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 1.0f}},
+ /* Pos Y */
+ {{1.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, -1.0f, 0.0f},
+ {0.0f, 1.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 1.0f}},
+ /* Neg Y */
+ {{1.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 1.0f, 0.0f},
+ {0.0f, -1.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 1.0f}},
+ /* Pos Z */
+ {{1.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, -1.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, -1.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 1.0f}},
+ /* Neg Z */
+ {{-1.0f, 0.0f, 0.0f, 0.0f},
+ {0.0f, -1.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, 1.0f, 0.0f},
+ {0.0f, 0.0f, 0.0f, 1.0f}},
+};
+
+#endif /* __EEVEE_PRIVATE_H__ */
diff --git a/source/blender/draw/engines/eevee/eevee_render.c b/source/blender/draw/engines/eevee/eevee_render.c
new file mode 100644
index 00000000000..da42f84baa2
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_render.c
@@ -0,0 +1,563 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_render.c
+ * \ingroup draw_engine
+ */
+
+/**
+ * Render functions for final render outputs.
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_node_types.h"
+#include "DNA_object_types.h"
+
+#include "BLI_rand.h"
+#include "BLI_rect.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "GPU_framebuffer.h"
+#include "GPU_glew.h"
+
+#include "RE_pipeline.h"
+
+#include "eevee_private.h"
+
+void EEVEE_render_init(EEVEE_Data *ved, RenderEngine *engine, struct Depsgraph *depsgraph)
+{
+ EEVEE_Data *vedata = (EEVEE_Data *)ved;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+
+ /* Init default FB and render targets:
+ * In render mode the default framebuffer is not generated
+ * because there is no viewport. So we need to manually create it or
+ * not use it. For code clarity we just allocate it make use of it. */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ /* TODO 32 bit depth */
+ DRW_texture_ensure_fullscreen_2D(&dtxl->depth, GPU_DEPTH24_STENCIL8, 0);
+ DRW_texture_ensure_fullscreen_2D(&txl->color, GPU_RGBA32F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
+
+ GPU_framebuffer_ensure_config(&dfbl->default_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(txl->color)
+ });
+ GPU_framebuffer_ensure_config(&fbl->main_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(txl->color)
+ });
+ GPU_framebuffer_ensure_config(&fbl->main_color_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->color)
+ });
+
+ /* Alloc transient data. */
+ if (!stl->g_data) {
+ stl->g_data = MEM_callocN(sizeof(*stl->g_data), __func__);
+ }
+ EEVEE_PrivateData *g_data = stl->g_data;
+ g_data->background_alpha = DRW_state_draw_background() ? 1.0f : 0.0f;
+ g_data->valid_double_buffer = 0;
+
+ /* Alloc common ubo data. */
+ if (sldata->common_ubo == NULL) {
+ sldata->common_ubo = DRW_uniformbuffer_create(sizeof(sldata->common_data), &sldata->common_data);
+ }
+ if (sldata->clip_ubo == NULL) {
+ sldata->clip_ubo = DRW_uniformbuffer_create(sizeof(sldata->clip_data), &sldata->clip_data);
+ }
+
+ /* Set the pers & view matrix. */
+ /* TODO(sergey): Shall render hold pointer to an evaluated camera instead? */
+ struct Object *camera = DEG_get_evaluated_object(depsgraph, RE_GetCamera(engine->re));
+ float frame = BKE_scene_frame_get(scene);
+ RE_GetCameraWindow(engine->re, camera, frame, g_data->winmat);
+ RE_GetCameraModelMatrix(engine->re, camera, g_data->viewinv);
+
+ invert_m4_m4(g_data->viewmat, g_data->viewinv);
+ mul_m4_m4m4(g_data->persmat, g_data->winmat, g_data->viewmat);
+ invert_m4_m4(g_data->persinv, g_data->persmat);
+ invert_m4_m4(g_data->wininv, g_data->winmat);
+
+ DRW_viewport_matrix_override_set(g_data->persmat, DRW_MAT_PERS);
+ DRW_viewport_matrix_override_set(g_data->persinv, DRW_MAT_PERSINV);
+ DRW_viewport_matrix_override_set(g_data->winmat, DRW_MAT_WIN);
+ DRW_viewport_matrix_override_set(g_data->wininv, DRW_MAT_WININV);
+ DRW_viewport_matrix_override_set(g_data->viewmat, DRW_MAT_VIEW);
+ DRW_viewport_matrix_override_set(g_data->viewinv, DRW_MAT_VIEWINV);
+
+ /* EEVEE_effects_init needs to go first for TAA */
+ EEVEE_effects_init(sldata, vedata, camera);
+ EEVEE_materials_init(sldata, stl, fbl);
+ EEVEE_lights_init(sldata);
+ EEVEE_lightprobes_init(sldata, vedata);
+
+ /* INIT CACHE */
+ EEVEE_bloom_cache_init(sldata, vedata);
+ EEVEE_depth_of_field_cache_init(sldata, vedata);
+ EEVEE_effects_cache_init(sldata, vedata);
+ EEVEE_lightprobes_cache_init(sldata, vedata);
+ EEVEE_lights_cache_init(sldata, vedata);
+ EEVEE_materials_cache_init(sldata, vedata);
+ EEVEE_motion_blur_cache_init(sldata, vedata);
+ EEVEE_occlusion_cache_init(sldata, vedata);
+ EEVEE_screen_raytrace_cache_init(sldata, vedata);
+ EEVEE_subsurface_cache_init(sldata, vedata);
+ EEVEE_temporal_sampling_cache_init(sldata, vedata);
+ EEVEE_volumes_cache_init(sldata, vedata);
+}
+
+void EEVEE_render_cache(
+ void *vedata, struct Object *ob,
+ struct RenderEngine *engine, struct Depsgraph *UNUSED(depsgraph))
+{
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+
+ char info[42];
+ BLI_snprintf(info, sizeof(info), "Syncing %s", ob->id.name + 2);
+ RE_engine_update_stats(engine, NULL, info);
+
+ if (DRW_check_object_visible_within_active_context(ob) == false) {
+ return;
+ }
+
+ if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
+ bool cast_shadow;
+
+ EEVEE_materials_cache_populate(vedata, sldata, ob, &cast_shadow);
+
+ if (cast_shadow) {
+ EEVEE_lights_cache_shcaster_object_add(sldata, ob);
+ }
+ }
+ else if (ob->type == OB_LIGHTPROBE) {
+ EEVEE_lightprobes_cache_add(sldata, ob);
+ }
+ else if (ob->type == OB_LAMP) {
+ EEVEE_lights_cache_add(sldata, ob);
+ }
+}
+
+static void eevee_render_result_combined(
+ RenderLayer *rl, const char *viewname, const rcti *rect,
+ EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata))
+{
+ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_COMBINED, viewname);
+
+ GPU_framebuffer_bind(vedata->stl->effects->final_fb);
+ GPU_framebuffer_read_color(vedata->stl->effects->final_fb,
+ rect->xmin, rect->ymin,
+ BLI_rcti_size_x(rect), BLI_rcti_size_y(rect),
+ 4, 0, rp->rect);
+}
+
+static void eevee_render_result_subsurface(
+ RenderLayer *rl, const char *viewname, const rcti *rect,
+ EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata), int render_samples)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+
+ if (vedata->fbl->sss_accum_fb == NULL) {
+ /* SSS is not enabled. */
+ return;
+ }
+
+ if ((view_layer->passflag & SCE_PASS_SUBSURFACE_COLOR) != 0) {
+ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_SUBSURFACE_COLOR, viewname);
+
+ GPU_framebuffer_bind(vedata->fbl->sss_accum_fb);
+ GPU_framebuffer_read_color(vedata->fbl->sss_accum_fb,
+ rect->xmin, rect->ymin,
+ BLI_rcti_size_x(rect), BLI_rcti_size_y(rect),
+ 3, 1, rp->rect);
+
+ /* This is the accumulated color. Divide by the number of samples. */
+ for (int i = 0; i < rp->rectx * rp->recty * 3; i++) {
+ rp->rect[i] /= (float)render_samples;
+ }
+ }
+
+ if ((view_layer->passflag & SCE_PASS_SUBSURFACE_DIRECT) != 0) {
+ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_SUBSURFACE_DIRECT, viewname);
+
+ GPU_framebuffer_bind(vedata->fbl->sss_accum_fb);
+ GPU_framebuffer_read_color(vedata->fbl->sss_accum_fb,
+ rect->xmin, rect->ymin,
+ BLI_rcti_size_x(rect), BLI_rcti_size_y(rect),
+ 3, 0, rp->rect);
+
+ /* This is the accumulated color. Divide by the number of samples. */
+ for (int i = 0; i < rp->rectx * rp->recty * 3; i++) {
+ rp->rect[i] /= (float)render_samples;
+ }
+ }
+
+ if ((view_layer->passflag & SCE_PASS_SUBSURFACE_INDIRECT) != 0) {
+ /* Do nothing as all the lighting is in the direct pass.
+ * TODO : Separate Direct from indirect lighting. */
+ }
+}
+
+static void eevee_render_result_normal(
+ RenderLayer *rl, const char *viewname, const rcti *rect,
+ EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata))
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_PrivateData *g_data = stl->g_data;
+
+ /* Only read the center texel. */
+ if (stl->effects->taa_current_sample > 1)
+ return;
+
+ if ((view_layer->passflag & SCE_PASS_NORMAL) != 0) {
+ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_NORMAL, viewname);
+
+ GPU_framebuffer_bind(vedata->fbl->main_fb);
+ GPU_framebuffer_read_color(vedata->fbl->main_fb,
+ rect->xmin, rect->ymin,
+ BLI_rcti_size_x(rect), BLI_rcti_size_y(rect),
+ 3, 1, rp->rect);
+
+ /* Convert Eevee encoded normals to Blender normals. */
+ for (int i = 0; i < rp->rectx * rp->recty * 3; i += 3) {
+ if (rp->rect[i] == 0.0f && rp->rect[i + 1] == 0.0f) {
+ /* If normal is not correct then do not produce NANs. */
+ continue;
+ }
+
+ float fenc[2];
+ fenc[0] = rp->rect[i + 0] * 4.0f - 2.0f;
+ fenc[1] = rp->rect[i + 1] * 4.0f - 2.0f;
+
+ float f = dot_v2v2(fenc, fenc);
+ float g = sqrtf(1.0f - f / 4.0f);
+
+ rp->rect[i + 0] = fenc[0] * g;
+ rp->rect[i + 1] = fenc[1] * g;
+ rp->rect[i + 2] = 1.0f - f / 2.0f;
+
+ mul_mat3_m4_v3(g_data->viewinv, &rp->rect[i]);
+ }
+ }
+}
+
+static void eevee_render_result_z(
+ RenderLayer *rl, const char *viewname, const rcti *rect,
+ EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_PrivateData *g_data = stl->g_data;
+
+ /* Only read the center texel. */
+ if (stl->effects->taa_current_sample > 1)
+ return;
+
+ if ((view_layer->passflag & SCE_PASS_Z) != 0) {
+ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_Z, viewname);
+
+ GPU_framebuffer_bind(vedata->fbl->main_fb);
+ GPU_framebuffer_read_depth(vedata->fbl->main_fb,
+ rect->xmin, rect->ymin,
+ BLI_rcti_size_x(rect), BLI_rcti_size_y(rect),
+ rp->rect);
+
+ bool is_persp = DRW_viewport_is_persp_get();
+
+ /* Convert ogl depth [0..1] to view Z [near..far] */
+ for (int i = 0; i < rp->rectx * rp->recty; ++i) {
+ if (rp->rect[i] == 1.0f ) {
+ rp->rect[i] = 1e10f; /* Background */
+ }
+ else {
+ if (is_persp) {
+ rp->rect[i] = rp->rect[i] * 2.0f - 1.0f;
+ rp->rect[i] = g_data->winmat[3][2] / (rp->rect[i] + g_data->winmat[2][2]);
+ }
+ else {
+ rp->rect[i] = -common_data->view_vecs[0][2] + rp->rect[i] * -common_data->view_vecs[1][2];
+ }
+ }
+ }
+ }
+}
+
+static void eevee_render_result_mist(
+ RenderLayer *rl, const char *viewname, const rcti *rect,
+ EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata), int render_samples)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+
+ if ((view_layer->passflag & SCE_PASS_MIST) != 0) {
+ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_MIST, viewname);
+
+ GPU_framebuffer_bind(vedata->fbl->mist_accum_fb);
+ GPU_framebuffer_read_color(vedata->fbl->mist_accum_fb,
+ rect->xmin, rect->ymin,
+ BLI_rcti_size_x(rect), BLI_rcti_size_y(rect),
+ 1, 0, rp->rect);
+
+ /* This is the accumulated color. Divide by the number of samples. */
+ for (int i = 0; i < rp->rectx * rp->recty; i++) {
+ rp->rect[i] /= (float)render_samples;
+ }
+ }
+}
+
+static void eevee_render_result_occlusion(
+ RenderLayer *rl, const char *viewname, const rcti *rect,
+ EEVEE_Data *vedata, EEVEE_ViewLayerData *UNUSED(sldata), int render_samples)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+
+ if (vedata->fbl->ao_accum_fb == NULL) {
+ /* AO is not enabled. */
+ return;
+ }
+
+ if ((view_layer->passflag & SCE_PASS_AO) != 0) {
+ RenderPass *rp = RE_pass_find_by_name(rl, RE_PASSNAME_AO, viewname);
+
+ GPU_framebuffer_bind(vedata->fbl->ao_accum_fb);
+ GPU_framebuffer_read_color(vedata->fbl->ao_accum_fb,
+ rect->xmin, rect->ymin,
+ BLI_rcti_size_x(rect), BLI_rcti_size_y(rect),
+ 3, 0, rp->rect);
+
+ /* This is the accumulated color. Divide by the number of samples. */
+ for (int i = 0; i < rp->rectx * rp->recty * 3; i += 3) {
+ rp->rect[i] = rp->rect[i + 1] = rp->rect[i + 2] = min_ff(1.0f, rp->rect[i] / (float)render_samples);
+ }
+ }
+}
+
+static void eevee_render_draw_background(EEVEE_Data *vedata)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_PassList *psl = vedata->psl;
+
+ /* Prevent background to write to data buffers.
+ * NOTE : This also make sure the textures are bound
+ * to the right double buffer. */
+ GPU_framebuffer_ensure_config(&fbl->main_fb, {
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_NONE
+ });
+ GPU_framebuffer_bind(fbl->main_fb);
+
+ DRW_draw_pass(psl->background_pass);
+
+ GPU_framebuffer_ensure_config(&fbl->main_fb, {
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_TEXTURE(stl->effects->ssr_normal_input),
+ GPU_ATTACHMENT_TEXTURE(stl->effects->ssr_specrough_input),
+ GPU_ATTACHMENT_TEXTURE(stl->effects->sss_data),
+ GPU_ATTACHMENT_TEXTURE(stl->effects->sss_albedo)
+ });
+ GPU_framebuffer_bind(fbl->main_fb);
+}
+
+void EEVEE_render_draw(EEVEE_Data *vedata, RenderEngine *engine, RenderLayer *rl, const rcti *rect)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ const char *viewname = RE_GetActiveRenderView(engine->re);
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ EEVEE_ViewLayerData *sldata = EEVEE_view_layer_data_ensure();
+ EEVEE_PrivateData *g_data = stl->g_data;
+
+ /* FINISH CACHE */
+ EEVEE_materials_cache_finish(vedata);
+ EEVEE_lights_cache_finish(sldata);
+ EEVEE_lightprobes_cache_finish(sldata, vedata);
+
+ /* Sort transparents before the loop. */
+ DRW_pass_sort_shgroup_z(psl->transparent_pass);
+
+ /* Push instances attribs to the GPU. */
+ DRW_render_instance_buffer_finish();
+
+ if ((view_layer->passflag & (SCE_PASS_SUBSURFACE_COLOR |
+ SCE_PASS_SUBSURFACE_DIRECT |
+ SCE_PASS_SUBSURFACE_INDIRECT)) != 0)
+ {
+ EEVEE_subsurface_output_init(sldata, vedata);
+ }
+
+ if ((view_layer->passflag & SCE_PASS_MIST) != 0) {
+ EEVEE_mist_output_init(sldata, vedata);
+ }
+
+ if ((view_layer->passflag & SCE_PASS_AO) != 0) {
+ EEVEE_occlusion_output_init(sldata, vedata);
+ }
+
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+ unsigned int tot_sample = BKE_collection_engine_property_value_get_int(props, "taa_render_samples");
+ unsigned int render_samples = 0;
+
+ if (RE_engine_test_break(engine)) {
+ return;
+ }
+
+ while (render_samples < tot_sample && !RE_engine_test_break(engine)) {
+ float clear_col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ float clear_depth = 1.0f;
+ unsigned int clear_stencil = 0xFF;
+ unsigned int primes[3] = {2, 3, 7};
+ double offset[3] = {0.0, 0.0, 0.0};
+ double r[3];
+
+ /* Restore winmat before jittering again. */
+ copy_m4_m4(stl->effects->overide_winmat, g_data->winmat);
+ /* Copy previous persmat to UBO data */
+ copy_m4_m4(sldata->common_data.prev_persmat, stl->effects->prev_persmat);
+
+ BLI_halton_3D(primes, offset, stl->effects->taa_current_sample, r);
+ EEVEE_update_noise(psl, fbl, r);
+ EEVEE_temporal_sampling_matrices_calc(stl->effects, g_data->viewmat, g_data->persmat, r);
+ EEVEE_volumes_set_jitter(sldata, stl->effects->taa_current_sample - 1);
+ EEVEE_materials_init(sldata, stl, fbl);
+
+ /* Set matrices. */
+ DRW_viewport_matrix_override_set(stl->effects->overide_persmat, DRW_MAT_PERS);
+ DRW_viewport_matrix_override_set(stl->effects->overide_persinv, DRW_MAT_PERSINV);
+ DRW_viewport_matrix_override_set(stl->effects->overide_winmat, DRW_MAT_WIN);
+ DRW_viewport_matrix_override_set(stl->effects->overide_wininv, DRW_MAT_WININV);
+ DRW_viewport_matrix_override_set(g_data->viewmat, DRW_MAT_VIEW);
+ DRW_viewport_matrix_override_set(g_data->viewinv, DRW_MAT_VIEWINV);
+
+ /* Refresh Probes */
+ while (EEVEE_lightprobes_all_probes_ready(sldata, vedata) == false) {
+ RE_engine_update_stats(engine, NULL, "Updating Probes");
+ EEVEE_lightprobes_refresh(sldata, vedata);
+ /* Refreshing probes can take some times, allow exit. */
+ if (RE_engine_test_break(engine)) {
+ return;
+ }
+ }
+ EEVEE_lightprobes_refresh_planar(sldata, vedata);
+ DRW_uniformbuffer_update(sldata->common_ubo, &sldata->common_data);
+
+ char info[42];
+ BLI_snprintf(info, sizeof(info), "Rendering %u / %u samples", render_samples + 1, tot_sample);
+ RE_engine_update_stats(engine, NULL, info);
+
+ /* Refresh Shadows */
+ EEVEE_draw_shadows(sldata, psl);
+
+ GPU_framebuffer_bind(fbl->main_fb);
+ GPU_framebuffer_clear_color_depth_stencil(fbl->main_fb, clear_col, clear_depth, clear_stencil);
+ /* Depth prepass */
+ DRW_draw_pass(psl->depth_pass);
+ DRW_draw_pass(psl->depth_pass_cull);
+ /* Create minmax texture */
+ EEVEE_create_minmax_buffer(vedata, dtxl->depth, -1);
+ EEVEE_occlusion_compute(sldata, vedata, dtxl->depth, -1);
+ EEVEE_volumes_compute(sldata, vedata);
+ /* Shading pass */
+ eevee_render_draw_background(vedata);
+ GPU_framebuffer_bind(fbl->main_fb);
+ EEVEE_draw_default_passes(psl);
+ DRW_draw_pass(psl->material_pass);
+ EEVEE_subsurface_data_render(sldata, vedata);
+ /* Effects pre-transparency */
+ EEVEE_subsurface_compute(sldata, vedata);
+ EEVEE_reflection_compute(sldata, vedata);
+ EEVEE_refraction_compute(sldata, vedata);
+ /* Opaque refraction */
+ DRW_draw_pass(psl->refract_depth_pass);
+ DRW_draw_pass(psl->refract_depth_pass_cull);
+ DRW_draw_pass(psl->refract_pass);
+ /* Subsurface output */
+ EEVEE_subsurface_output_accumulate(sldata, vedata);
+ /* Occlusion output */
+ EEVEE_occlusion_output_accumulate(sldata, vedata);
+ /* Result NORMAL */
+ eevee_render_result_normal(rl, viewname, rect, vedata, sldata);
+ /* Volumetrics Resolve Opaque */
+ EEVEE_volumes_resolve(sldata, vedata);
+ /* Mist output */
+ EEVEE_mist_output_accumulate(sldata, vedata);
+ /* Transparent */
+ DRW_draw_pass(psl->transparent_pass);
+ /* Result Z */
+ eevee_render_result_z(rl, viewname, rect, vedata, sldata);
+ /* Post Process */
+ EEVEE_draw_effects(sldata, vedata);
+
+ RE_engine_update_progress(engine, (float)(render_samples++) / (float)tot_sample);
+ }
+
+ eevee_render_result_combined(rl, viewname, rect, vedata, sldata);
+ eevee_render_result_subsurface(rl, viewname, rect, vedata, sldata, render_samples);
+ eevee_render_result_mist(rl, viewname, rect, vedata, sldata, render_samples);
+ eevee_render_result_occlusion(rl, viewname, rect, vedata, sldata, render_samples);
+}
+
+void EEVEE_render_update_passes(RenderEngine *engine, Scene *scene, ViewLayer *view_layer)
+{
+ int type;
+
+ RE_engine_register_pass(engine, scene, view_layer, RE_PASSNAME_COMBINED, 4, "RGBA", SOCK_RGBA);
+
+#define CHECK_PASS(name, channels, chanid) \
+ if (view_layer->passflag & (SCE_PASS_ ## name)) { \
+ if (channels == 4) type = SOCK_RGBA; \
+ else if (channels == 3) type = SOCK_VECTOR; \
+ else type = SOCK_FLOAT; \
+ RE_engine_register_pass(engine, scene, view_layer, RE_PASSNAME_ ## name, channels, chanid, type); \
+ }
+
+ CHECK_PASS(Z, 1, "Z");
+ CHECK_PASS(MIST, 1, "Z");
+ CHECK_PASS(NORMAL, 3, "XYZ");
+ CHECK_PASS(AO, 3, "RGB");
+ CHECK_PASS(SUBSURFACE_COLOR, 3, "RGB");
+ CHECK_PASS(SUBSURFACE_DIRECT, 3, "RGB");
+
+#undef CHECK_PASS
+}
diff --git a/source/blender/draw/engines/eevee/eevee_screen_raytrace.c b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c
new file mode 100644
index 00000000000..56cc905d701
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_screen_raytrace.c
@@ -0,0 +1,325 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_screen_raytrace.c
+ * \ingroup draw_engine
+ *
+ * Screen space reflections and refractions techniques.
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_dynstr.h"
+#include "BLI_string_utils.h"
+
+#include "eevee_private.h"
+#include "GPU_texture.h"
+
+/* SSR shader variations */
+enum {
+ SSR_RESOLVE = (1 << 0),
+ SSR_FULL_TRACE = (1 << 1),
+ SSR_AO = (1 << 3),
+ SSR_MAX_SHADER = (1 << 4),
+};
+
+static struct {
+ /* Screen Space Reflection */
+ struct GPUShader *ssr_sh[SSR_MAX_SHADER];
+
+ /* Theses are just references, not actually allocated */
+ struct GPUTexture *depth_src;
+ struct GPUTexture *color_src;
+} e_data = {{NULL}}; /* Engine data */
+
+extern char datatoc_ambient_occlusion_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_bsdf_sampling_lib_glsl[];
+extern char datatoc_octahedron_lib_glsl[];
+extern char datatoc_effect_ssr_frag_glsl[];
+extern char datatoc_lightprobe_lib_glsl[];
+extern char datatoc_raytrace_lib_glsl[];
+
+static struct GPUShader *eevee_effects_screen_raytrace_shader_get(int options)
+{
+ if (e_data.ssr_sh[options] == NULL) {
+ char *ssr_shader_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_sampling_lib_glsl,
+ datatoc_octahedron_lib_glsl,
+ datatoc_lightprobe_lib_glsl,
+ datatoc_ambient_occlusion_lib_glsl,
+ datatoc_raytrace_lib_glsl,
+ datatoc_effect_ssr_frag_glsl);
+
+ DynStr *ds_defines = BLI_dynstr_new();
+ BLI_dynstr_appendf(ds_defines, SHADER_DEFINES);
+ if (options & SSR_RESOLVE) {
+ BLI_dynstr_appendf(ds_defines, "#define STEP_RESOLVE\n");
+ }
+ else {
+ BLI_dynstr_appendf(ds_defines, "#define STEP_RAYTRACE\n");
+ BLI_dynstr_appendf(ds_defines, "#define PLANAR_PROBE_RAYTRACE\n");
+ }
+ if (options & SSR_FULL_TRACE) {
+ BLI_dynstr_appendf(ds_defines, "#define FULLRES\n");
+ }
+ if (options & SSR_AO) {
+ BLI_dynstr_appendf(ds_defines, "#define SSR_AO\n");
+ }
+ char *ssr_define_str = BLI_dynstr_get_cstring(ds_defines);
+ BLI_dynstr_free(ds_defines);
+
+ e_data.ssr_sh[options] = DRW_shader_create_fullscreen(ssr_shader_str, ssr_define_str);
+
+ MEM_freeN(ssr_shader_str);
+ MEM_freeN(ssr_define_str);
+ }
+
+ return e_data.ssr_sh[options];
+}
+
+int EEVEE_screen_raytrace_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ const float *viewport_size = DRW_viewport_size_get();
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer,
+ RE_engine_id_BLENDER_EEVEE);
+
+ /* Compute pixel size, (shared with contact shadows) */
+ copy_v2_v2(common_data->ssr_pixelsize, viewport_size);
+ invert_v2(common_data->ssr_pixelsize);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "ssr_enable")) {
+ const bool use_refraction = BKE_collection_engine_property_value_get_bool(props, "ssr_refraction");
+
+ if (use_refraction) {
+ /* TODO: Opti: Could be shared. */
+ DRW_texture_ensure_fullscreen_2D(&txl->refract_color, GPU_R11F_G11F_B10F, DRW_TEX_FILTER | DRW_TEX_MIPMAP);
+
+ GPU_framebuffer_ensure_config(&fbl->refract_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->refract_color)
+ });
+ }
+
+ effects->reflection_trace_full = !BKE_collection_engine_property_value_get_bool(props, "ssr_halfres");
+ common_data->ssr_thickness = BKE_collection_engine_property_value_get_float(props, "ssr_thickness");
+ common_data->ssr_border_fac = BKE_collection_engine_property_value_get_float(props, "ssr_border_fade");
+ common_data->ssr_firefly_fac = BKE_collection_engine_property_value_get_float(props, "ssr_firefly_fac");
+ common_data->ssr_max_roughness = BKE_collection_engine_property_value_get_float(props, "ssr_max_roughness");
+ common_data->ssr_quality = 1.0f - 0.95f * BKE_collection_engine_property_value_get_float(props, "ssr_quality");
+ common_data->ssr_brdf_bias = 0.1f + common_data->ssr_quality * 0.6f; /* Range [0.1, 0.7]. */
+
+ if (common_data->ssr_firefly_fac < 1e-8f) {
+ common_data->ssr_firefly_fac = FLT_MAX;
+ }
+
+ const int divisor = (effects->reflection_trace_full) ? 1 : 2;
+ int tracing_res[2] = {(int)viewport_size[0] / divisor, (int)viewport_size[1] / divisor};
+ int size_fs[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+ const bool high_qual_input = true; /* TODO dither low quality input */
+ const GPUTextureFormat format = (high_qual_input) ? GPU_RGBA16F : GPU_RGBA8;
+
+ /* MRT for the shading pass in order to output needed data for the SSR pass. */
+ effects->ssr_specrough_input = DRW_texture_pool_query_2D(size_fs[0], size_fs[1], format,
+ &draw_engine_eevee_type);
+
+ GPU_framebuffer_texture_attach(fbl->main_fb, effects->ssr_specrough_input, 2, 0);
+
+ /* Raytracing output */
+ effects->ssr_hit_output = DRW_texture_pool_query_2D(tracing_res[0], tracing_res[1], GPU_RG16I,
+ &draw_engine_eevee_type);
+ effects->ssr_pdf_output = DRW_texture_pool_query_2D(tracing_res[0], tracing_res[1], GPU_R16F,
+ &draw_engine_eevee_type);
+
+ GPU_framebuffer_ensure_config(&fbl->screen_tracing_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->ssr_hit_output),
+ GPU_ATTACHMENT_TEXTURE(effects->ssr_pdf_output)
+ });
+
+ /* Enable double buffering to be able to read previous frame color */
+ return EFFECT_SSR | EFFECT_NORMAL_BUFFER | EFFECT_DOUBLE_BUFFER | ((use_refraction) ? EFFECT_REFRACT : 0);
+ }
+
+ /* Cleanup to release memory */
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->screen_tracing_fb);
+ effects->ssr_specrough_input = NULL;
+ effects->ssr_hit_output = NULL;
+ effects->ssr_pdf_output = NULL;
+
+ return 0;
+}
+
+void EEVEE_screen_raytrace_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ if ((effects->enabled_effects & EFFECT_SSR) != 0) {
+ int options = (effects->reflection_trace_full) ? SSR_FULL_TRACE : 0;
+ options |= ((effects->enabled_effects & EFFECT_GTAO) != 0) ? SSR_AO : 0;
+
+ struct GPUShader *trace_shader = eevee_effects_screen_raytrace_shader_get(options);
+ struct GPUShader *resolve_shader = eevee_effects_screen_raytrace_shader_get(SSR_RESOLVE | options);
+
+ /** Screen space raytracing overview
+ *
+ * Following Frostbite stochastic SSR.
+ *
+ * - First pass Trace rays accross the depth buffer. The hit position and pdf are
+ * recorded in a RGBA16F render target for each ray (sample).
+ *
+ * - We downsample the previous frame color buffer.
+ *
+ * - For each final pixel, we gather neighboors rays and choose a color buffer
+ * mipmap for each ray using its pdf. (filtered importance sampling)
+ * We then evaluate the lighting from the probes and mix the results together.
+ */
+ psl->ssr_raytrace = DRW_pass_create("SSR Raytrace", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(trace_shader, psl->ssr_raytrace);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data.depth_src);
+ DRW_shgroup_uniform_texture_ref(grp, "normalBuffer", &effects->ssr_normal_input);
+ DRW_shgroup_uniform_texture_ref(grp, "specroughBuffer", &effects->ssr_specrough_input);
+ DRW_shgroup_uniform_texture_ref(grp, "maxzBuffer", &txl->maxzbuffer);
+ DRW_shgroup_uniform_texture_ref(grp, "planarDepth", &vedata->txl->planar_depth);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ if (!effects->reflection_trace_full) {
+ DRW_shgroup_uniform_ivec2(grp, "halfresOffset", effects->ssr_halfres_ofs, 1);
+ }
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ psl->ssr_resolve = DRW_pass_create("SSR Resolve", DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE);
+ grp = DRW_shgroup_create(resolve_shader, psl->ssr_resolve);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &e_data.depth_src);
+ DRW_shgroup_uniform_texture_ref(grp, "normalBuffer", &effects->ssr_normal_input);
+ DRW_shgroup_uniform_texture_ref(grp, "specroughBuffer", &effects->ssr_specrough_input);
+ DRW_shgroup_uniform_texture_ref(grp, "probeCubes", &sldata->probe_pool);
+ DRW_shgroup_uniform_texture_ref(grp, "probePlanars", &vedata->txl->planar_pool);
+ DRW_shgroup_uniform_texture_ref(grp, "planarDepth", &vedata->txl->planar_depth);
+ DRW_shgroup_uniform_texture_ref(grp, "hitBuffer", &effects->ssr_hit_output);
+ DRW_shgroup_uniform_texture_ref(grp, "pdfBuffer", &effects->ssr_pdf_output);
+ DRW_shgroup_uniform_texture_ref(grp, "prevColorBuffer", &txl->color_double_buffer);
+ DRW_shgroup_uniform_block(grp, "probe_block", sldata->probe_ubo);
+ DRW_shgroup_uniform_block(grp, "planar_block", sldata->planar_ubo);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_uniform_int(grp, "neighborOffset", &effects->ssr_neighbor_ofs, 1);
+ if ((effects->enabled_effects & EFFECT_GTAO) != 0) {
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "horizonBuffer", &effects->gtao_horizons);
+ }
+
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+}
+
+void EEVEE_refraction_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & EFFECT_REFRACT) != 0) {
+ GPU_framebuffer_blit(fbl->main_fb, 0, fbl->refract_fb, 0, GPU_COLOR_BIT);
+ EEVEE_downsample_buffer(vedata, txl->refract_color, 9);
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+ }
+}
+
+void EEVEE_reflection_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if (((effects->enabled_effects & EFFECT_SSR) != 0) && stl->g_data->valid_double_buffer) {
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ e_data.depth_src = dtxl->depth;
+
+ DRW_stats_group_start("SSR");
+
+ /* Raytrace. */
+ GPU_framebuffer_bind(fbl->screen_tracing_fb);
+ DRW_draw_pass(psl->ssr_raytrace);
+
+ EEVEE_downsample_buffer(vedata, txl->color_double_buffer, 9);
+
+ /* Resolve at fullres */
+ int sample = (DRW_state_is_image_render()) ? effects->taa_render_sample : effects->taa_current_sample;
+ /* Doing a neighbor shift only after a few iteration. We wait for a prime number of cycles to avoid
+ * noise correlation. This reduces variance faster. */
+ effects->ssr_neighbor_ofs = ((sample / 5) % 8) * 4;
+ switch ((sample / 11) % 4) {
+ case 0:
+ effects->ssr_halfres_ofs[0] = 0;
+ effects->ssr_halfres_ofs[1] = 0;
+ break;
+ case 1:
+ effects->ssr_halfres_ofs[0] = 0;
+ effects->ssr_halfres_ofs[1] = 1;
+ break;
+ case 2:
+ effects->ssr_halfres_ofs[0] = 1;
+ effects->ssr_halfres_ofs[1] = 0;
+ break;
+ case 4:
+ effects->ssr_halfres_ofs[0] = 1;
+ effects->ssr_halfres_ofs[1] = 1;
+ break;
+ }
+ GPU_framebuffer_bind(fbl->main_color_fb);
+ DRW_draw_pass(psl->ssr_resolve);
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+ DRW_stats_group_end();
+ }
+}
+
+void EEVEE_screen_raytrace_free(void)
+{
+ for (int i = 0; i < SSR_MAX_SHADER; ++i) {
+ DRW_SHADER_FREE_SAFE(e_data.ssr_sh[i]);
+ }
+}
diff --git a/source/blender/draw/engines/eevee/eevee_subsurface.c b/source/blender/draw/engines/eevee/eevee_subsurface.c
new file mode 100644
index 00000000000..5ccc182a54a
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_subsurface.c
@@ -0,0 +1,339 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_subsurface.c
+ * \ingroup draw_engine
+ *
+ * Screen space subsurface scattering technique.
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_string_utils.h"
+
+#include "eevee_private.h"
+#include "GPU_texture.h"
+
+static struct {
+ struct GPUShader *sss_sh[4];
+} e_data = {{NULL}}; /* Engine data */
+
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_effect_subsurface_frag_glsl[];
+
+static void eevee_create_shader_subsurface(void)
+{
+ char *frag_str = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_effect_subsurface_frag_glsl);
+
+ e_data.sss_sh[0] = DRW_shader_create_fullscreen(frag_str, "#define FIRST_PASS\n");
+ e_data.sss_sh[1] = DRW_shader_create_fullscreen(frag_str, "#define SECOND_PASS\n");
+ e_data.sss_sh[2] = DRW_shader_create_fullscreen(frag_str, "#define SECOND_PASS\n"
+ "#define USE_SEP_ALBEDO\n");
+ e_data.sss_sh[3] = DRW_shader_create_fullscreen(frag_str, "#define SECOND_PASS\n"
+ "#define USE_SEP_ALBEDO\n"
+ "#define RESULT_ACCUM\n");
+
+ MEM_freeN(frag_str);
+}
+
+int EEVEE_subsurface_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ const float *viewport_size = DRW_viewport_size_get();
+ const int fs_size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "sss_enable")) {
+ effects->sss_sample_count = 1 + BKE_collection_engine_property_value_get_int(props, "sss_samples") * 2;
+ effects->sss_separate_albedo = BKE_collection_engine_property_value_get_bool(props, "sss_separate_albedo");
+ common_data->sss_jitter_threshold = BKE_collection_engine_property_value_get_float(props, "sss_jitter_threshold");
+
+ /* Force separate albedo for final render */
+ if (DRW_state_is_image_render()) {
+ effects->sss_separate_albedo = true;
+ }
+
+ /* Shaders */
+ if (!e_data.sss_sh[0]) {
+ eevee_create_shader_subsurface();
+ }
+
+ /* NOTE : we need another stencil because the stencil buffer is on the same texture
+ * as the depth buffer we are sampling from. This could be avoided if the stencil is
+ * a separate texture but that needs OpenGL 4.4 or ARB_texture_stencil8.
+ * OR OpenGL 4.3 / ARB_ES3_compatibility if using a renderbuffer instead */
+ effects->sss_stencil = DRW_texture_pool_query_2D(fs_size[0], fs_size[1], GPU_DEPTH24_STENCIL8,
+ &draw_engine_eevee_type);
+ effects->sss_blur = DRW_texture_pool_query_2D(fs_size[0], fs_size[1], GPU_RGBA16F,
+ &draw_engine_eevee_type);
+ effects->sss_data = DRW_texture_pool_query_2D(fs_size[0], fs_size[1], GPU_RGBA16F,
+ &draw_engine_eevee_type);
+
+ GPU_framebuffer_ensure_config(&fbl->sss_blur_fb, {
+ GPU_ATTACHMENT_TEXTURE(effects->sss_stencil),
+ GPU_ATTACHMENT_TEXTURE(effects->sss_blur)
+ });
+
+ GPU_framebuffer_ensure_config(&fbl->sss_resolve_fb, {
+ GPU_ATTACHMENT_TEXTURE(effects->sss_stencil),
+ GPU_ATTACHMENT_TEXTURE(txl->color)
+ });
+
+ GPU_framebuffer_ensure_config(&fbl->sss_clear_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(effects->sss_data)
+ });
+
+ if (effects->sss_separate_albedo) {
+ effects->sss_albedo = DRW_texture_pool_query_2D(fs_size[0], fs_size[1], GPU_R11F_G11F_B10F,
+ &draw_engine_eevee_type);
+ }
+ else {
+ effects->sss_albedo = NULL;
+ }
+ return EFFECT_SSS;
+ }
+
+ /* Cleanup to release memory */
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->sss_blur_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->sss_resolve_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->sss_clear_fb);
+ effects->sss_stencil = NULL;
+ effects->sss_blur = NULL;
+ effects->sss_data = NULL;
+
+ return 0;
+}
+
+static void set_shgrp_stencil(void *UNUSED(userData), DRWShadingGroup *shgrp)
+{
+ DRW_shgroup_stencil_mask(shgrp, 255);
+}
+
+void EEVEE_subsurface_output_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "sss_enable")) {
+ DRW_texture_ensure_fullscreen_2D(&txl->sss_dir_accum, GPU_RGBA16F, 0);
+ DRW_texture_ensure_fullscreen_2D(&txl->sss_col_accum, GPU_RGBA16F, 0);
+
+ GPU_framebuffer_ensure_config(&fbl->sss_accum_fb, {
+ GPU_ATTACHMENT_TEXTURE(effects->sss_stencil),
+ GPU_ATTACHMENT_TEXTURE(txl->sss_dir_accum),
+ GPU_ATTACHMENT_TEXTURE(txl->sss_col_accum)
+ });
+
+ /* Clear texture. */
+ float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ GPU_framebuffer_bind(fbl->sss_accum_fb);
+ GPU_framebuffer_clear_color(fbl->sss_accum_fb, clear);
+
+ /* Make the opaque refraction pass mask the sss. */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_CLIP_PLANES |
+ DRW_STATE_WIRE | DRW_STATE_WRITE_STENCIL;
+ DRW_pass_state_set(vedata->psl->refract_pass, state);
+ DRW_pass_foreach_shgroup(vedata->psl->refract_pass, &set_shgrp_stencil, NULL);
+ }
+ else {
+ /* Cleanup to release memory */
+ DRW_TEXTURE_FREE_SAFE(txl->sss_dir_accum);
+ DRW_TEXTURE_FREE_SAFE(txl->sss_col_accum);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->sss_accum_fb);
+ }
+}
+
+void EEVEE_subsurface_cache_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & EFFECT_SSS) != 0) {
+ /** Screen Space SubSurface Scattering overview
+ * TODO
+ */
+ psl->sss_blur_ps = DRW_pass_create("Blur Horiz", DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL);
+
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_ADDITIVE | DRW_STATE_STENCIL_EQUAL;
+ psl->sss_resolve_ps = DRW_pass_create("Blur Vert", state);
+ psl->sss_accum_ps = DRW_pass_create("Resolve Accum", state);
+ }
+}
+
+void EEVEE_subsurface_add_pass(
+ EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, unsigned int sss_id, struct GPUUniformBuffer *sss_profile)
+{
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.sss_sh[0], psl->sss_blur_ps);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_texture_ref(grp, "sssData", &effects->sss_data);
+ DRW_shgroup_uniform_block(grp, "sssProfile", sss_profile);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_stencil_mask(grp, sss_id);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ struct GPUShader *sh = (effects->sss_separate_albedo) ? e_data.sss_sh[2] : e_data.sss_sh[1];
+ grp = DRW_shgroup_create(sh, psl->sss_resolve_ps);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_texture_ref(grp, "sssData", &effects->sss_blur);
+ DRW_shgroup_uniform_block(grp, "sssProfile", sss_profile);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_stencil_mask(grp, sss_id);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ if (effects->sss_separate_albedo) {
+ DRW_shgroup_uniform_texture_ref(grp, "sssAlbedo", &effects->sss_albedo);
+ }
+
+ if (DRW_state_is_image_render()) {
+ grp = DRW_shgroup_create(e_data.sss_sh[3], psl->sss_accum_ps);
+ DRW_shgroup_uniform_texture(grp, "utilTex", EEVEE_materials_get_util_tex());
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_uniform_texture_ref(grp, "sssData", &effects->sss_blur);
+ DRW_shgroup_uniform_texture_ref(grp, "sssAlbedo", &effects->sss_albedo);
+ DRW_shgroup_uniform_block(grp, "sssProfile", sss_profile);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_stencil_mask(grp, sss_id);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+}
+
+void EEVEE_subsurface_data_render(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & EFFECT_SSS) != 0) {
+ float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ /* Clear sss_data texture only... can this be done in a more clever way? */
+ GPU_framebuffer_bind(fbl->sss_clear_fb);
+ GPU_framebuffer_clear_color(fbl->sss_clear_fb, clear);
+
+ GPU_framebuffer_ensure_config(&fbl->main_fb, {
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_TEXTURE(effects->sss_data),
+ GPU_ATTACHMENT_TEXTURE(effects->sss_albedo)
+ });
+
+ GPU_framebuffer_bind(fbl->main_fb);
+ DRW_draw_pass(psl->sss_pass);
+
+ /* Restore */
+ GPU_framebuffer_ensure_config(&fbl->main_fb, {
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_LEAVE,
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_NONE
+ });
+ }
+}
+
+void EEVEE_subsurface_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & EFFECT_SSS) != 0) {
+ float clear[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+ DRW_stats_group_start("SSS");
+
+ /* Copy stencil channel, could be avoided (see EEVEE_subsurface_init) */
+ GPU_framebuffer_blit(fbl->main_fb, 0, fbl->sss_blur_fb, 0, GPU_STENCIL_BIT);
+
+ /* 1. horizontal pass */
+ GPU_framebuffer_bind(fbl->sss_blur_fb);
+ GPU_framebuffer_clear_color(fbl->sss_blur_fb, clear);
+ DRW_draw_pass(psl->sss_blur_ps);
+
+ /* 2. vertical pass + Resolve */
+ GPU_framebuffer_texture_attach(fbl->sss_resolve_fb, txl->color, 0, 0);
+ GPU_framebuffer_bind(fbl->sss_resolve_fb);
+ DRW_draw_pass(psl->sss_resolve_ps);
+
+ GPU_framebuffer_bind(fbl->main_fb);
+ DRW_stats_group_end();
+ }
+}
+
+void EEVEE_subsurface_output_accumulate(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if (((effects->enabled_effects & EFFECT_SSS) != 0) && (fbl->sss_accum_fb != NULL)) {
+ /* Copy stencil channel, could be avoided (see EEVEE_subsurface_init) */
+ GPU_framebuffer_blit(fbl->main_fb, 0, fbl->sss_blur_fb, 0, GPU_STENCIL_BIT);
+
+ /* Only do vertical pass + Resolve */
+ GPU_framebuffer_bind(fbl->sss_accum_fb);
+ DRW_draw_pass(psl->sss_accum_ps);
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+ }
+}
+
+void EEVEE_subsurface_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.sss_sh[0]);
+ DRW_SHADER_FREE_SAFE(e_data.sss_sh[1]);
+ DRW_SHADER_FREE_SAFE(e_data.sss_sh[2]);
+ DRW_SHADER_FREE_SAFE(e_data.sss_sh[3]);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_temporal_sampling.c b/source/blender/draw/engines/eevee/eevee_temporal_sampling.c
new file mode 100644
index 00000000000..d9db7e45400
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_temporal_sampling.c
@@ -0,0 +1,386 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_temporal_sampling.c
+ * \ingroup draw_engine
+ *
+ * Temporal super sampling technique
+ */
+
+#include "DRW_render.h"
+
+#include "ED_screen.h"
+
+#include "BLI_rand.h"
+#include "BLI_string_utils.h"
+
+#include "eevee_private.h"
+#include "GPU_texture.h"
+
+#define FILTER_CDF_TABLE_SIZE 512
+
+static struct {
+ /* Temporal Anti Aliasing */
+ struct GPUShader *taa_resolve_sh;
+ struct GPUShader *taa_resolve_reproject_sh;
+
+ /* Pixel filter table: Only blackman-harris for now. */
+ float inverted_cdf[FILTER_CDF_TABLE_SIZE];
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_effect_temporal_aa_glsl[];
+
+static void eevee_create_shader_temporal_sampling(void)
+{
+ char *frag_str = BLI_string_joinN(
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_common_view_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_effect_temporal_aa_glsl);
+
+ e_data.taa_resolve_sh = DRW_shader_create_fullscreen(frag_str, NULL);
+ e_data.taa_resolve_reproject_sh = DRW_shader_create_fullscreen(frag_str, "#define USE_REPROJECTION\n");
+
+ MEM_freeN(frag_str);
+}
+
+static float UNUSED_FUNCTION(filter_box)(float UNUSED(x))
+{
+ return 1.0f;
+}
+
+static float filter_blackman_harris(float x)
+{
+ /* Hardcoded 1px footprint [-0.5..0.5]. We resize later. */
+ const float width = 1.0f;
+ x = 2.0f * M_PI * (x / width + 0.5f);
+ return 0.35875f - 0.48829f * cosf(x) + 0.14128f * cosf(2.0f * x) - 0.01168f * cosf(3.0f * x);
+}
+
+/* Compute cumulative distribution function of a discrete function. */
+static void compute_cdf(float (*func)(float x), float cdf[FILTER_CDF_TABLE_SIZE])
+{
+ cdf[0] = 0.0f;
+ /* Actual CDF evaluation. */
+ for (int u = 0; u < FILTER_CDF_TABLE_SIZE - 1; ++u) {
+ float x = (float)(u + 1) / (float)(FILTER_CDF_TABLE_SIZE - 1);
+ cdf[u + 1] = cdf[u] + func(x - 0.5f); /* [-0.5..0.5]. We resize later. */
+ }
+ /* Normalize the CDF. */
+ for (int u = 0; u < FILTER_CDF_TABLE_SIZE - 1; u++) {
+ cdf[u] /= cdf[FILTER_CDF_TABLE_SIZE - 1];
+ }
+ /* Just to make sure. */
+ cdf[FILTER_CDF_TABLE_SIZE - 1] = 1.0f;
+}
+
+static void invert_cdf(const float cdf[FILTER_CDF_TABLE_SIZE], float invert_cdf[FILTER_CDF_TABLE_SIZE])
+{
+ for (int u = 0; u < FILTER_CDF_TABLE_SIZE; u++) {
+ float x = (float)u / (float)(FILTER_CDF_TABLE_SIZE - 1);
+ for (int i = 0; i < FILTER_CDF_TABLE_SIZE; ++i) {
+ if (cdf[i] >= x) {
+ if (i == FILTER_CDF_TABLE_SIZE - 1) {
+ invert_cdf[u] = 1.0f;
+ }
+ else {
+ float t = (x - cdf[i]) / (cdf[i + 1] - cdf[i]);
+ invert_cdf[u] = ((float)i + t) / (float)(FILTER_CDF_TABLE_SIZE - 1);
+ }
+ break;
+ }
+ }
+ }
+}
+
+/* Evaluate a discrete function table with linear interpolation. */
+static float eval_table(float *table, float x)
+{
+ CLAMP(x, 0.0f, 1.0f);
+ x = x * (FILTER_CDF_TABLE_SIZE - 1);
+
+ int index = min_ii((int)(x), FILTER_CDF_TABLE_SIZE - 1);
+ int nindex = min_ii(index + 1, FILTER_CDF_TABLE_SIZE - 1);
+ float t = x - index;
+
+ return (1.0f - t) * table[index] + t * table[nindex];
+}
+
+static void eevee_create_cdf_table_temporal_sampling(void)
+{
+ float *cdf_table = MEM_mallocN(sizeof(float) * FILTER_CDF_TABLE_SIZE, "Eevee Filter CDF table");
+
+ float filter_width = 2.0f; /* Use a 2 pixel footprint by default. */
+
+ {
+ /* Use blackman-harris filter. */
+ filter_width *= 2.0f;
+ compute_cdf(filter_blackman_harris, cdf_table);
+ }
+
+ invert_cdf(cdf_table, e_data.inverted_cdf);
+
+ /* Scale and offset table. */
+ for (int i = 0; i < FILTER_CDF_TABLE_SIZE; ++i) {
+ e_data.inverted_cdf[i] = (e_data.inverted_cdf[i] - 0.5f) * filter_width;
+ }
+
+ MEM_freeN(cdf_table);
+}
+
+void EEVEE_temporal_sampling_matrices_calc(
+ EEVEE_EffectsInfo *effects, float viewmat[4][4], float persmat[4][4], const double ht_point[2])
+{
+ const float *viewport_size = DRW_viewport_size_get();
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ RenderData *rd = &scene->r;
+
+ float filter_size = rd->gauss; /* Sigh.. Stupid legacy naming. */
+
+ float ofs_x = eval_table(e_data.inverted_cdf, (float)(ht_point[0])) * filter_size;
+ float ofs_y = eval_table(e_data.inverted_cdf, (float)(ht_point[1])) * filter_size;
+
+ window_translate_m4(
+ effects->overide_winmat, persmat,
+ ofs_x / viewport_size[0],
+ ofs_y / viewport_size[1]);
+
+ mul_m4_m4m4(effects->overide_persmat, effects->overide_winmat, viewmat);
+ invert_m4_m4(effects->overide_persinv, effects->overide_persmat);
+ invert_m4_m4(effects->overide_wininv, effects->overide_winmat);
+}
+
+int EEVEE_temporal_sampling_init(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_StorageList *stl = vedata->stl;
+ // EEVEE_FramebufferList *fbl = vedata->fbl;
+ // EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ int repro_flag = 0;
+
+ if (!e_data.taa_resolve_sh) {
+ eevee_create_shader_temporal_sampling();
+ eevee_create_cdf_table_temporal_sampling();
+ }
+
+ /* Reset for each "redraw". When rendering using ogl render,
+ * we accumulate the redraw inside the drawing loop in eevee_draw_background().
+ * But we do NOT accumulate between "redraw" (as in full draw manager drawloop)
+ * because the opengl render already does that. */
+ effects->taa_render_sample = 1;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ if ((BKE_collection_engine_property_value_get_int(props, "taa_samples") != 1 &&
+ /* FIXME the motion blur camera evaluation is tagging view_updated
+ * thus making the TAA always reset and never stopping rendering. */
+ (effects->enabled_effects & EFFECT_MOTION_BLUR) == 0) ||
+ DRW_state_is_image_render())
+ {
+ float persmat[4][4], viewmat[4][4];
+
+ if (!DRW_state_is_image_render() &&
+ BKE_collection_engine_property_value_get_bool(props, "taa_reprojection"))
+ {
+ repro_flag = EFFECT_TAA_REPROJECT | EFFECT_VELOCITY_BUFFER | EFFECT_DEPTH_DOUBLE_BUFFER | EFFECT_DOUBLE_BUFFER | EFFECT_POST_BUFFER;
+ effects->taa_reproject_sample = ((effects->taa_reproject_sample + 1) % 16);
+ }
+
+ /* Until we support reprojection, we need to make sure
+ * that the history buffer contains correct information. */
+ bool view_is_valid = stl->g_data->valid_double_buffer;
+
+ view_is_valid = view_is_valid && (stl->g_data->view_updated == false);
+
+ if (draw_ctx->evil_C != NULL) {
+ struct wmWindowManager *wm = CTX_wm_manager(draw_ctx->evil_C);
+ view_is_valid = view_is_valid && (ED_screen_animation_no_scrub(wm) == NULL);
+ }
+
+ effects->taa_total_sample = BKE_collection_engine_property_value_get_int(props, "taa_samples");
+ MAX2(effects->taa_total_sample, 0);
+
+ DRW_viewport_matrix_get(persmat, DRW_MAT_PERS);
+ DRW_viewport_matrix_get(viewmat, DRW_MAT_VIEW);
+ DRW_viewport_matrix_get(effects->overide_winmat, DRW_MAT_WIN);
+ /* The view is jittered by the oglrenderer. So avoid testing in this case. */
+ if (!DRW_state_is_image_render()) {
+ view_is_valid = view_is_valid && compare_m4m4(persmat, effects->prev_drw_persmat, FLT_MIN);
+ copy_m4_m4(effects->prev_drw_persmat, persmat);
+ }
+
+ /* Prevent ghosting from probe data. */
+ view_is_valid = view_is_valid && (effects->prev_drw_support == DRW_state_draw_support());
+ effects->prev_drw_support = DRW_state_draw_support();
+
+ if (((effects->taa_total_sample == 0) || (effects->taa_current_sample < effects->taa_total_sample)) ||
+ DRW_state_is_image_render())
+ {
+ if (view_is_valid) {
+ /* OGL render already jitter the camera. */
+ if (!DRW_state_is_image_render()) {
+ effects->taa_current_sample += 1;
+ repro_flag = 0;
+
+ double ht_point[2];
+ double ht_offset[2] = {0.0, 0.0};
+ unsigned int ht_primes[2] = {2, 3};
+
+ BLI_halton_2D(ht_primes, ht_offset, effects->taa_current_sample - 1, ht_point);
+
+ EEVEE_temporal_sampling_matrices_calc(effects, viewmat, persmat, ht_point);
+
+ DRW_viewport_matrix_override_set(effects->overide_persmat, DRW_MAT_PERS);
+ DRW_viewport_matrix_override_set(effects->overide_persinv, DRW_MAT_PERSINV);
+ DRW_viewport_matrix_override_set(effects->overide_winmat, DRW_MAT_WIN);
+ DRW_viewport_matrix_override_set(effects->overide_wininv, DRW_MAT_WININV);
+ }
+ }
+ else {
+ effects->taa_current_sample = 1;
+ }
+ }
+ else {
+ effects->taa_current_sample = 1;
+ }
+
+ return repro_flag | EFFECT_TAA | EFFECT_DOUBLE_BUFFER | EFFECT_DEPTH_DOUBLE_BUFFER | EFFECT_POST_BUFFER;
+ }
+
+ effects->taa_current_sample = 1;
+
+ return repro_flag;
+}
+
+void EEVEE_temporal_sampling_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & (EFFECT_TAA | EFFECT_TAA_REPROJECT)) != 0) {
+ struct GPUShader *sh = (effects->enabled_effects & EFFECT_TAA_REPROJECT)
+ ? e_data.taa_resolve_reproject_sh
+ : e_data.taa_resolve_sh;
+
+ psl->taa_resolve = DRW_pass_create("Temporal AA Resolve", DRW_STATE_WRITE_COLOR);
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, psl->taa_resolve);
+
+ DRW_shgroup_uniform_texture_ref(grp, "colorHistoryBuffer", &txl->color_double_buffer);
+ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &txl->color);
+
+ if (effects->enabled_effects & EFFECT_TAA_REPROJECT) {
+ // DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ DRW_shgroup_uniform_texture_ref(grp, "velocityBuffer", &effects->velocity_tx);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ }
+ else {
+ DRW_shgroup_uniform_float(grp, "alpha", &effects->taa_alpha, 1);
+ }
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+}
+
+/* Special Swap */
+#define SWAP_BUFFER_TAA() do { \
+ SWAP(struct GPUFrameBuffer *, fbl->effect_fb, fbl->double_buffer_fb); \
+ SWAP(struct GPUFrameBuffer *, fbl->effect_color_fb, fbl->double_buffer_color_fb); \
+ SWAP(GPUTexture *, txl->color_post, txl->color_double_buffer); \
+ effects->swap_double_buffer = false; \
+ effects->source_buffer = txl->color_double_buffer; \
+ effects->target_buffer = fbl->main_color_fb; \
+} while (0);
+
+void EEVEE_temporal_sampling_draw(EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & (EFFECT_TAA | EFFECT_TAA_REPROJECT)) != 0) {
+ if ((effects->enabled_effects & EFFECT_TAA) != 0 && effects->taa_current_sample != 1) {
+ if (DRW_state_is_image_render()) {
+ /* See EEVEE_temporal_sampling_init() for more details. */
+ effects->taa_alpha = 1.0f / (float)(effects->taa_render_sample);
+ }
+ else {
+ effects->taa_alpha = 1.0f / (float)(effects->taa_current_sample);
+ }
+
+ GPU_framebuffer_bind(fbl->effect_color_fb);
+ DRW_draw_pass(psl->taa_resolve);
+
+ /* Restore the depth from sample 1. */
+ if (!DRW_state_is_image_render()) {
+ GPU_framebuffer_blit(fbl->double_buffer_depth_fb, 0, fbl->main_fb, 0, GPU_DEPTH_BIT);
+ }
+
+ SWAP_BUFFER_TAA();
+ }
+ else {
+ if (!DRW_state_is_image_render()) {
+ /* Do reprojection for noise reduction */
+ /* TODO : do AA jitter if in only render view. */
+ if ((effects->enabled_effects & EFFECT_TAA_REPROJECT) != 0 &&
+ stl->g_data->valid_double_buffer)
+ {
+ GPU_framebuffer_bind(fbl->effect_color_fb);
+ DRW_draw_pass(psl->taa_resolve);
+
+ SWAP_BUFFER_TAA();
+ }
+
+ /* Save the depth buffer for the next frame.
+ * This saves us from doing anything special
+ * in the other mode engines. */
+ GPU_framebuffer_blit(fbl->main_fb, 0, fbl->double_buffer_depth_fb, 0, GPU_DEPTH_BIT);
+ }
+ }
+
+ /* Make each loop count when doing a render. */
+ if (DRW_state_is_image_render()) {
+ effects->taa_render_sample += 1;
+ effects->taa_current_sample += 1;
+ }
+ else {
+ if ((effects->taa_total_sample == 0) ||
+ (effects->taa_current_sample < effects->taa_total_sample))
+ {
+ DRW_viewport_request_redraw();
+ }
+ }
+ }
+}
+
+void EEVEE_temporal_sampling_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.taa_resolve_sh);
+ DRW_SHADER_FREE_SAFE(e_data.taa_resolve_reproject_sh);
+}
diff --git a/source/blender/draw/engines/eevee/eevee_volumes.c b/source/blender/draw/engines/eevee/eevee_volumes.c
new file mode 100644
index 00000000000..9b039345fce
--- /dev/null
+++ b/source/blender/draw/engines/eevee/eevee_volumes.c
@@ -0,0 +1,599 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file eevee_volumes.c
+ * \ingroup draw_engine
+ *
+ * Volumetric effects rendering using frostbite approach.
+ */
+
+#include "DRW_render.h"
+
+#include "BLI_rand.h"
+#include "BLI_string_utils.h"
+
+#include "DNA_object_force_types.h"
+#include "DNA_smoke_types.h"
+#include "DNA_world_types.h"
+
+#include "BKE_global.h" /* for G.debug_value */
+#include "BKE_modifier.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+
+#include "ED_screen.h"
+
+#include "eevee_private.h"
+#include "GPU_draw.h"
+#include "GPU_texture.h"
+
+static struct {
+ char *volumetric_common_lib;
+ char *volumetric_common_lamps_lib;
+
+ struct GPUShader *volumetric_clear_sh;
+ struct GPUShader *volumetric_scatter_sh;
+ struct GPUShader *volumetric_scatter_with_lamps_sh;
+ struct GPUShader *volumetric_integration_sh;
+ struct GPUShader *volumetric_resolve_sh;
+
+ GPUTexture *color_src;
+ GPUTexture *depth_src;
+
+ /* List of all smoke domains rendered within this frame. */
+ ListBase smoke_domains;
+} e_data = {NULL}; /* Engine data */
+
+extern char datatoc_bsdf_common_lib_glsl[];
+extern char datatoc_bsdf_direct_lib_glsl[];
+extern char datatoc_common_uniforms_lib_glsl[];
+extern char datatoc_common_view_lib_glsl[];
+extern char datatoc_octahedron_lib_glsl[];
+extern char datatoc_irradiance_lib_glsl[];
+extern char datatoc_lamps_lib_glsl[];
+extern char datatoc_volumetric_frag_glsl[];
+extern char datatoc_volumetric_geom_glsl[];
+extern char datatoc_volumetric_vert_glsl[];
+extern char datatoc_volumetric_resolve_frag_glsl[];
+extern char datatoc_volumetric_scatter_frag_glsl[];
+extern char datatoc_volumetric_integration_frag_glsl[];
+extern char datatoc_volumetric_lib_glsl[];
+extern char datatoc_common_fullscreen_vert_glsl[];
+
+static void eevee_create_shader_volumes(void)
+{
+ e_data.volumetric_common_lib = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_volumetric_lib_glsl);
+
+ e_data.volumetric_common_lamps_lib = BLI_string_joinN(
+ datatoc_common_view_lib_glsl,
+ datatoc_common_uniforms_lib_glsl,
+ datatoc_bsdf_common_lib_glsl,
+ datatoc_bsdf_direct_lib_glsl,
+ datatoc_octahedron_lib_glsl,
+ datatoc_irradiance_lib_glsl,
+ datatoc_lamps_lib_glsl,
+ datatoc_volumetric_lib_glsl);
+
+ e_data.volumetric_clear_sh = DRW_shader_create_with_lib(
+ datatoc_volumetric_vert_glsl,
+ datatoc_volumetric_geom_glsl,
+ datatoc_volumetric_frag_glsl,
+ e_data.volumetric_common_lib,
+ "#define VOLUMETRICS\n"
+ "#define CLEAR\n");
+ e_data.volumetric_scatter_sh = DRW_shader_create_with_lib(
+ datatoc_volumetric_vert_glsl,
+ datatoc_volumetric_geom_glsl,
+ datatoc_volumetric_scatter_frag_glsl,
+ e_data.volumetric_common_lamps_lib,
+ SHADER_DEFINES
+ "#define VOLUMETRICS\n"
+ "#define VOLUME_SHADOW\n");
+ e_data.volumetric_scatter_with_lamps_sh = DRW_shader_create_with_lib(
+ datatoc_volumetric_vert_glsl,
+ datatoc_volumetric_geom_glsl,
+ datatoc_volumetric_scatter_frag_glsl,
+ e_data.volumetric_common_lamps_lib,
+ SHADER_DEFINES
+ "#define VOLUMETRICS\n"
+ "#define VOLUME_LIGHTING\n"
+ "#define VOLUME_SHADOW\n");
+ e_data.volumetric_integration_sh = DRW_shader_create_with_lib(
+ datatoc_volumetric_vert_glsl,
+ datatoc_volumetric_geom_glsl,
+ datatoc_volumetric_integration_frag_glsl,
+ e_data.volumetric_common_lib, NULL);
+ e_data.volumetric_resolve_sh = DRW_shader_create_with_lib(
+ datatoc_common_fullscreen_vert_glsl, NULL,
+ datatoc_volumetric_resolve_frag_glsl,
+ e_data.volumetric_common_lib, NULL);
+}
+
+void EEVEE_volumes_set_jitter(EEVEE_ViewLayerData *sldata, unsigned int current_sample)
+{
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+
+ double ht_point[3];
+ double ht_offset[3] = {0.0, 0.0};
+ unsigned int ht_primes[3] = {3, 7, 2};
+
+ BLI_halton_3D(ht_primes, ht_offset, current_sample, ht_point);
+
+ common_data->vol_jitter[0] = (float)ht_point[0];
+ common_data->vol_jitter[1] = (float)ht_point[1];
+ common_data->vol_jitter[2] = (float)ht_point[2];
+}
+
+int EEVEE_volumes_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_EEVEE);
+
+ const float *viewport_size = DRW_viewport_size_get();
+
+ BLI_listbase_clear(&e_data.smoke_domains);
+
+ if (BKE_collection_engine_property_value_get_bool(props, "volumetric_enable")) {
+
+ /* Shaders */
+ if (!e_data.volumetric_scatter_sh) {
+ eevee_create_shader_volumes();
+ }
+
+ int tile_size = BKE_collection_engine_property_value_get_int(props, "volumetric_tile_size");
+
+ /* Find Froxel Texture resolution. */
+ int tex_size[3];
+
+ tex_size[0] = (int)ceilf(fmaxf(1.0f, viewport_size[0] / (float)tile_size));
+ tex_size[1] = (int)ceilf(fmaxf(1.0f, viewport_size[1] / (float)tile_size));
+ tex_size[2] = max_ii(BKE_collection_engine_property_value_get_int(props, "volumetric_samples"), 1);
+
+ common_data->vol_coord_scale[0] = viewport_size[0] / (float)(tile_size * tex_size[0]);
+ common_data->vol_coord_scale[1] = viewport_size[1] / (float)(tile_size * tex_size[1]);
+
+ /* TODO compute snap to maxZBuffer for clustered rendering */
+
+ if ((common_data->vol_tex_size[0] != tex_size[0]) ||
+ (common_data->vol_tex_size[1] != tex_size[1]) ||
+ (common_data->vol_tex_size[2] != tex_size[2]))
+ {
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_scattering);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_extinction);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_emission);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_phase);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_scatter);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_scatter_history);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance_history);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_scat_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_integ_fb);
+ common_data->vol_tex_size[0] = tex_size[0];
+ common_data->vol_tex_size[1] = tex_size[1];
+ common_data->vol_tex_size[2] = tex_size[2];
+
+ common_data->vol_inv_tex_size[0] = 1.0f / (float)(tex_size[0]);
+ common_data->vol_inv_tex_size[1] = 1.0f / (float)(tex_size[1]);
+ common_data->vol_inv_tex_size[2] = 1.0f / (float)(tex_size[2]);
+ }
+
+ /* Like frostbite's paper, 5% blend of the new frame. */
+ common_data->vol_history_alpha = (txl->volume_prop_scattering == NULL) ? 0.0f : 0.95f;
+
+ if (txl->volume_prop_scattering == NULL) {
+ /* Volume properties: We evaluate all volumetric objects
+ * and store their final properties into each froxel */
+ txl->volume_prop_scattering = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
+ txl->volume_prop_extinction = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
+ txl->volume_prop_emission = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
+ txl->volume_prop_phase = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_RG16F, DRW_TEX_FILTER, NULL);
+
+ /* Volume scattering: We compute for each froxel the
+ * Scattered light towards the view. We also resolve temporal
+ * super sampling during this stage. */
+ txl->volume_scatter = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
+ txl->volume_transmittance = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
+
+ /* Final integration: We compute for each froxel the
+ * amount of scattered light and extinction coef at this
+ * given depth. We use theses textures as double buffer
+ * for the volumetric history. */
+ txl->volume_scatter_history = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
+ txl->volume_transmittance_history = DRW_texture_create_3D(tex_size[0], tex_size[1], tex_size[2],
+ GPU_R11F_G11F_B10F, DRW_TEX_FILTER, NULL);
+ }
+
+ /* Temporal Super sampling jitter */
+ unsigned int ht_primes[3] = {3, 7, 2};
+ unsigned int current_sample = 0;
+
+ /* If TAA is in use do not use the history buffer. */
+ bool do_taa = ((effects->enabled_effects & EFFECT_TAA) != 0);
+
+ if (draw_ctx->evil_C != NULL) {
+ struct wmWindowManager *wm = CTX_wm_manager(draw_ctx->evil_C);
+ do_taa = do_taa && (ED_screen_animation_no_scrub(wm) == NULL);
+ }
+
+ if (do_taa) {
+ common_data->vol_history_alpha = 0.0f;
+ current_sample = effects->taa_current_sample - 1;
+ effects->volume_current_sample = -1;
+ }
+ else {
+ const unsigned int max_sample = (ht_primes[0] * ht_primes[1] * ht_primes[2]);
+ current_sample = effects->volume_current_sample = (effects->volume_current_sample + 1) % max_sample;
+ if (current_sample != max_sample - 1) {
+ DRW_viewport_request_redraw();
+ }
+ }
+
+ EEVEE_volumes_set_jitter(sldata, current_sample);
+
+ /* Framebuffer setup */
+ GPU_framebuffer_ensure_config(&fbl->volumetric_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->volume_prop_scattering),
+ GPU_ATTACHMENT_TEXTURE(txl->volume_prop_extinction),
+ GPU_ATTACHMENT_TEXTURE(txl->volume_prop_emission),
+ GPU_ATTACHMENT_TEXTURE(txl->volume_prop_phase)
+ });
+ GPU_framebuffer_ensure_config(&fbl->volumetric_scat_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->volume_scatter),
+ GPU_ATTACHMENT_TEXTURE(txl->volume_transmittance)
+ });
+ GPU_framebuffer_ensure_config(&fbl->volumetric_integ_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(txl->volume_scatter_history),
+ GPU_ATTACHMENT_TEXTURE(txl->volume_transmittance_history)
+ });
+
+ float integration_start = BKE_collection_engine_property_value_get_float(props, "volumetric_start");
+ float integration_end = BKE_collection_engine_property_value_get_float(props, "volumetric_end");
+ common_data->vol_light_clamp = BKE_collection_engine_property_value_get_float(props, "volumetric_light_clamp");
+
+ common_data->vol_shadow_steps = (float)BKE_collection_engine_property_value_get_int(props, "volumetric_shadow_samples");
+ if (BKE_collection_engine_property_value_get_bool(props, "volumetric_shadows")) {
+ }
+ else {
+ common_data->vol_shadow_steps = 0;
+ }
+
+ if (DRW_viewport_is_persp_get()) {
+ float sample_distribution = BKE_collection_engine_property_value_get_float(props, "volumetric_sample_distribution");
+ sample_distribution = 4.0f * (1.00001f - sample_distribution);
+
+ const float clip_start = common_data->view_vecs[0][2];
+ /* Negate */
+ float near = integration_start = min_ff(-integration_start, clip_start - 1e-4f);
+ float far = integration_end = min_ff(-integration_end, near - 1e-4f);
+
+ common_data->vol_depth_param[0] = (far - near * exp2(1.0f / sample_distribution)) / (far - near);
+ common_data->vol_depth_param[1] = (1.0f - common_data->vol_depth_param[0]) / near;
+ common_data->vol_depth_param[2] = sample_distribution;
+ }
+ else {
+ const float clip_start = common_data->view_vecs[0][2];
+ const float clip_end = clip_start + common_data->view_vecs[1][2];
+ integration_start = min_ff(integration_end, clip_start);
+ integration_end = max_ff(-integration_end, clip_end);
+
+ common_data->vol_depth_param[0] = integration_start;
+ common_data->vol_depth_param[1] = integration_end;
+ common_data->vol_depth_param[2] = 1.0f / (integration_end - integration_start);
+ }
+
+ /* Disable clamp if equal to 0. */
+ if (common_data->vol_light_clamp == 0.0) {
+ common_data->vol_light_clamp = FLT_MAX;
+ }
+
+ common_data->vol_use_lights = BKE_collection_engine_property_value_get_bool(props, "volumetric_lights");
+
+ return EFFECT_VOLUMETRIC | EFFECT_POST_BUFFER;
+ }
+
+ /* Cleanup to release memory */
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_scattering);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_extinction);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_emission);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_prop_phase);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_scatter);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_scatter_history);
+ DRW_TEXTURE_FREE_SAFE(txl->volume_transmittance_history);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_scat_fb);
+ GPU_FRAMEBUFFER_FREE_SAFE(fbl->volumetric_integ_fb);
+
+ return 0;
+}
+
+void EEVEE_volumes_cache_init(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ EEVEE_CommonUniformBuffer *common_data = &sldata->common_data;
+
+ if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ DRWShadingGroup *grp = NULL;
+
+ /* Quick breakdown of the Volumetric rendering:
+ *
+ * The rendering is separated in 4 stages:
+ *
+ * - Material Parameters : we collect volume properties of
+ * all participating media in the scene and store them in
+ * a 3D texture aligned with the 3D frustum.
+ * This is done in 2 passes, one that clear the texture
+ * and/or evaluate the world volumes, and the 2nd one that
+ * additively render object volumes.
+ *
+ * - Light Scattering : the volume properties then are sampled
+ * and light scattering is evaluated for each cell of the
+ * volume texture. Temporal supersampling (if enabled) occurs here.
+ *
+ * - Volume Integration : the scattered light and extinction is
+ * integrated (accumulated) along the viewrays. The result is stored
+ * for every cell in another texture.
+ *
+ * - Fullscreen Resolve : From the previous stage, we get two
+ * 3D textures that contains integrated scatered light and extinction
+ * for "every" positions in the frustum. We only need to sample
+ * them and blend the scene color with thoses factors. This also
+ * work for alpha blended materials.
+ **/
+
+ /* World pass is not additive as it also clear the buffer. */
+ psl->volumetric_world_ps = DRW_pass_create("Volumetric World", DRW_STATE_WRITE_COLOR);
+
+ /* World Volumetric */
+ struct World *wo = scene->world;
+ if (wo != NULL && wo->use_nodes && wo->nodetree) {
+ struct GPUMaterial *mat = EEVEE_material_world_volume_get(scene, wo);
+
+ grp = DRW_shgroup_material_empty_tri_batch_create(mat,
+ psl->volumetric_world_ps,
+ common_data->vol_tex_size[2]);
+
+ if (grp) {
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ }
+ }
+
+ if (grp == NULL) {
+ /* If no world or volume material is present just clear the buffer with this drawcall */
+ grp = DRW_shgroup_empty_tri_batch_create(e_data.volumetric_clear_sh,
+ psl->volumetric_world_ps,
+ common_data->vol_tex_size[2]);
+
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ }
+
+ /* Volumetric Objects */
+ psl->volumetric_objects_ps = DRW_pass_create("Volumetric Properties", DRW_STATE_WRITE_COLOR |
+ DRW_STATE_ADDITIVE);
+
+ struct GPUShader *scatter_sh = (common_data->vol_use_lights) ? e_data.volumetric_scatter_with_lamps_sh
+ : e_data.volumetric_scatter_sh;
+ psl->volumetric_scatter_ps = DRW_pass_create("Volumetric Scattering", DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_empty_tri_batch_create(scatter_sh, psl->volumetric_scatter_ps,
+ common_data->vol_tex_size[2]);
+ DRW_shgroup_uniform_texture_ref(grp, "irradianceGrid", &sldata->irradiance_pool);
+ DRW_shgroup_uniform_texture_ref(grp, "shadowCubeTexture", &sldata->shadow_cube_pool);
+ DRW_shgroup_uniform_texture_ref(grp, "shadowCascadeTexture", &sldata->shadow_cascade_pool);
+ DRW_shgroup_uniform_texture_ref(grp, "volumeScattering", &txl->volume_prop_scattering);
+ DRW_shgroup_uniform_texture_ref(grp, "volumeExtinction", &txl->volume_prop_extinction);
+ DRW_shgroup_uniform_texture_ref(grp, "volumeEmission", &txl->volume_prop_emission);
+ DRW_shgroup_uniform_texture_ref(grp, "volumePhase", &txl->volume_prop_phase);
+ DRW_shgroup_uniform_texture_ref(grp, "historyScattering", &txl->volume_scatter_history);
+ DRW_shgroup_uniform_texture_ref(grp, "historyTransmittance", &txl->volume_transmittance_history);
+ DRW_shgroup_uniform_block(grp, "light_block", sldata->light_ubo);
+ DRW_shgroup_uniform_block(grp, "shadow_block", sldata->shadow_ubo);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+
+ psl->volumetric_integration_ps = DRW_pass_create("Volumetric Integration", DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_empty_tri_batch_create(e_data.volumetric_integration_sh,
+ psl->volumetric_integration_ps,
+ common_data->vol_tex_size[2]);
+ DRW_shgroup_uniform_texture_ref(grp, "volumeScattering", &txl->volume_scatter);
+ DRW_shgroup_uniform_texture_ref(grp, "volumeExtinction", &txl->volume_transmittance);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+
+ psl->volumetric_resolve_ps = DRW_pass_create("Volumetric Resolve", DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_create(e_data.volumetric_resolve_sh, psl->volumetric_resolve_ps);
+ DRW_shgroup_uniform_texture_ref(grp, "inScattering", &txl->volume_scatter);
+ DRW_shgroup_uniform_texture_ref(grp, "inTransmittance", &txl->volume_transmittance);
+ DRW_shgroup_uniform_texture_ref(grp, "inSceneColor", &e_data.color_src);
+ DRW_shgroup_uniform_texture_ref(grp, "inSceneDepth", &e_data.depth_src);
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+}
+
+void EEVEE_volumes_cache_object_add(EEVEE_ViewLayerData *sldata, EEVEE_Data *vedata, Scene *scene, Object *ob)
+{
+ float *texcoloc = NULL;
+ float *texcosize = NULL;
+ struct ModifierData *md = NULL;
+ Material *ma = give_current_material(ob, 1);
+
+ if (ma == NULL) {
+ return;
+ }
+
+ struct GPUMaterial *mat = EEVEE_material_mesh_volume_get(scene, ma);
+
+ DRWShadingGroup *grp = DRW_shgroup_material_empty_tri_batch_create(mat, vedata->psl->volumetric_objects_ps, sldata->common_data.vol_tex_size[2]);
+
+ /* If shader failed to compile or is currently compiling. */
+ if (grp == NULL) {
+ return;
+ }
+
+ /* Making sure it's updated. */
+ invert_m4_m4(ob->imat, ob->obmat);
+
+ BKE_mesh_texspace_get_reference((struct Mesh *)ob->data, NULL, &texcoloc, NULL, &texcosize);
+
+ DRW_shgroup_uniform_block(grp, "common_block", sldata->common_ubo);
+ DRW_shgroup_uniform_mat4(grp, "volumeObjectMatrix", ob->imat);
+ DRW_shgroup_uniform_vec3(grp, "volumeOrcoLoc", texcoloc, 1);
+ DRW_shgroup_uniform_vec3(grp, "volumeOrcoSize", texcosize, 1);
+
+ /* Smoke Simulation */
+ if (((ob->base_flag & BASE_FROMDUPLI) == 0) &&
+ (md = modifiers_findByType(ob, eModifierType_Smoke)) &&
+ (modifier_isEnabled(scene, md, eModifierMode_Realtime)))
+ {
+ SmokeModifierData *smd = (SmokeModifierData *)md;
+ SmokeDomainSettings *sds = smd->domain;
+ /* Don't show smoke before simulation starts, this could be made an option in the future. */
+ const bool show_smoke = (CFRA >= sds->point_cache[0]->startframe);
+
+ if (sds->fluid && show_smoke) {
+ if (!sds->wt || !(sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
+ GPU_create_smoke(smd, 0);
+ }
+ else if (sds->wt && (sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
+ GPU_create_smoke(smd, 1);
+ }
+ BLI_addtail(&e_data.smoke_domains, BLI_genericNodeN(smd));
+ }
+
+ if (sds->tex != NULL) {
+ DRW_shgroup_uniform_texture_ref(grp, "sampdensity", &sds->tex);
+ }
+ if (sds->tex_flame != NULL) {
+ DRW_shgroup_uniform_texture_ref(grp, "sampflame", &sds->tex_flame);
+ }
+
+ /* Output is such that 0..1 maps to 0..1000K */
+ DRW_shgroup_uniform_vec2(grp, "unftemperature", &sds->flame_ignition, 1);
+ }
+}
+
+void EEVEE_volumes_compute(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+ if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
+ DRW_stats_group_start("Volumetrics");
+
+ /* Step 1: Participating Media Properties */
+ GPU_framebuffer_bind(fbl->volumetric_fb);
+ DRW_draw_pass(psl->volumetric_world_ps);
+ DRW_draw_pass(psl->volumetric_objects_ps);
+
+ /* Step 2: Scatter Light */
+ GPU_framebuffer_bind(fbl->volumetric_scat_fb);
+ DRW_draw_pass(psl->volumetric_scatter_ps);
+
+ /* Step 3: Integration */
+ GPU_framebuffer_bind(fbl->volumetric_integ_fb);
+ DRW_draw_pass(psl->volumetric_integration_ps);
+
+ /* Swap volume history buffers */
+ SWAP(struct GPUFrameBuffer *, fbl->volumetric_scat_fb, fbl->volumetric_integ_fb);
+ SWAP(GPUTexture *, txl->volume_scatter, txl->volume_scatter_history);
+ SWAP(GPUTexture *, txl->volume_transmittance, txl->volume_transmittance_history);
+
+ /* Restore */
+ GPU_framebuffer_bind(fbl->main_fb);
+
+ DRW_stats_group_end();
+ }
+}
+
+void EEVEE_volumes_resolve(EEVEE_ViewLayerData *UNUSED(sldata), EEVEE_Data *vedata)
+{
+ EEVEE_PassList *psl = vedata->psl;
+ EEVEE_TextureList *txl = vedata->txl;
+ EEVEE_FramebufferList *fbl = vedata->fbl;
+ EEVEE_StorageList *stl = vedata->stl;
+ EEVEE_EffectsInfo *effects = stl->effects;
+
+ if ((effects->enabled_effects & EFFECT_VOLUMETRIC) != 0) {
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ e_data.color_src = txl->color;
+ e_data.depth_src = dtxl->depth;
+
+ /* Step 4: Apply for opaque */
+ GPU_framebuffer_bind(fbl->effect_color_fb);
+ DRW_draw_pass(psl->volumetric_resolve_ps);
+
+ /* Swap the buffers and rebind depth to the current buffer */
+ SWAP(GPUFrameBuffer *, fbl->main_fb, fbl->effect_fb);
+ SWAP(GPUFrameBuffer *, fbl->main_color_fb, fbl->effect_color_fb);
+ SWAP(GPUTexture *, txl->color, txl->color_post);
+ GPU_framebuffer_texture_attach(fbl->main_fb, dtxl->depth, 0, 0);
+ }
+}
+
+void EEVEE_volumes_free_smoke_textures(void)
+{
+ /* Free Smoke Textures after rendering */
+ for (LinkData *link = e_data.smoke_domains.first; link; link = link->next) {
+ SmokeModifierData *smd = (SmokeModifierData *)link->data;
+ GPU_free_smoke(smd);
+ }
+ BLI_freelistN(&e_data.smoke_domains);
+}
+
+void EEVEE_volumes_free(void)
+{
+ MEM_SAFE_FREE(e_data.volumetric_common_lib);
+ MEM_SAFE_FREE(e_data.volumetric_common_lamps_lib);
+
+ DRW_SHADER_FREE_SAFE(e_data.volumetric_clear_sh);
+ DRW_SHADER_FREE_SAFE(e_data.volumetric_scatter_sh);
+ DRW_SHADER_FREE_SAFE(e_data.volumetric_scatter_with_lamps_sh);
+ DRW_SHADER_FREE_SAFE(e_data.volumetric_integration_sh);
+ DRW_SHADER_FREE_SAFE(e_data.volumetric_resolve_sh);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl b/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl
new file mode 100644
index 00000000000..55f66f5500a
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/ambient_occlusion_lib.glsl
@@ -0,0 +1,281 @@
+
+/* Based on Practical Realtime Strategies for Accurate Indirect Occlusion
+ * http://blog.selfshadow.com/publications/s2016-shading-course/activision/s2016_pbs_activision_occlusion.pdf
+ * http://blog.selfshadow.com/publications/s2016-shading-course/activision/s2016_pbs_activision_occlusion.pptx */
+
+#if defined(MESH_SHADER)
+# if !defined(USE_ALPHA_HASH)
+# if !defined(USE_ALPHA_CLIP)
+# if !defined(SHADOW_SHADER)
+# if !defined(USE_MULTIPLY)
+# if !defined(USE_ALPHA_BLEND)
+# define ENABLE_DEFERED_AO
+# endif
+# endif
+# endif
+# endif
+# endif
+#endif
+
+#ifndef ENABLE_DEFERED_AO
+# if defined(STEP_RESOLVE)
+# define ENABLE_DEFERED_AO
+# endif
+#endif
+
+#define MAX_PHI_STEP 32
+#define MAX_SEARCH_ITER 32
+#define MAX_LOD 6.0
+
+#ifndef UTIL_TEX
+#define UTIL_TEX
+uniform sampler2DArray utilTex;
+#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
+#endif /* UTIL_TEX */
+
+uniform sampler2D horizonBuffer;
+
+/* aoSettings flags */
+#define USE_AO 1
+#define USE_BENT_NORMAL 2
+#define USE_DENOISE 4
+
+vec4 pack_horizons(vec4 v) { return v * 0.5 + 0.5; }
+vec4 unpack_horizons(vec4 v) { return v * 2.0 - 1.0; }
+
+/* Returns maximum screen distance an AO ray can travel for a given view depth */
+vec2 get_max_dir(float view_depth)
+{
+ float homcco = ProjectionMatrix[2][3] * view_depth + ProjectionMatrix[3][3];
+ float max_dist = aoDistance / homcco;
+ return vec2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) * max_dist;
+}
+
+vec2 get_ao_dir(float jitter)
+{
+ /* Only half a turn because we integrate in slices. */
+ jitter *= M_PI;
+ return vec2(cos(jitter), sin(jitter));
+}
+
+void get_max_horizon_grouped(vec4 co1, vec4 co2, vec3 x, float lod, inout float h)
+{
+ co1 *= mipRatio[int(lod + 1.0)].xyxy; /* +1 because we are using half res top level */
+ co2 *= mipRatio[int(lod + 1.0)].xyxy; /* +1 because we are using half res top level */
+
+ float depth1 = textureLod(maxzBuffer, co1.xy, floor(lod)).r;
+ float depth2 = textureLod(maxzBuffer, co1.zw, floor(lod)).r;
+ float depth3 = textureLod(maxzBuffer, co2.xy, floor(lod)).r;
+ float depth4 = textureLod(maxzBuffer, co2.zw, floor(lod)).r;
+
+ vec4 len, s_h;
+
+ vec3 s1 = get_view_space_from_depth(co1.xy, depth1); /* s View coordinate */
+ vec3 omega_s1 = s1 - x;
+ len.x = length(omega_s1);
+ s_h.x = omega_s1.z / len.x;
+
+ vec3 s2 = get_view_space_from_depth(co1.zw, depth2); /* s View coordinate */
+ vec3 omega_s2 = s2 - x;
+ len.y = length(omega_s2);
+ s_h.y = omega_s2.z / len.y;
+
+ vec3 s3 = get_view_space_from_depth(co2.xy, depth3); /* s View coordinate */
+ vec3 omega_s3 = s3 - x;
+ len.z = length(omega_s3);
+ s_h.z = omega_s3.z / len.z;
+
+ vec3 s4 = get_view_space_from_depth(co2.zw, depth4); /* s View coordinate */
+ vec3 omega_s4 = s4 - x;
+ len.w = length(omega_s4);
+ s_h.w = omega_s4.z / len.w;
+
+ /* Blend weight after half the aoDistance to fade artifacts */
+ vec4 blend = saturate((1.0 - len / aoDistance) * 2.0);
+
+ h = mix(h, max(h, s_h.x), blend.x);
+ h = mix(h, max(h, s_h.y), blend.y);
+ h = mix(h, max(h, s_h.z), blend.z);
+ h = mix(h, max(h, s_h.w), blend.w);
+}
+
+vec2 search_horizon_sweep(vec2 t_phi, vec3 pos, vec2 uvs, float jitter, vec2 max_dir)
+{
+ max_dir *= max_v2(abs(t_phi));
+
+ /* Convert to pixel space. */
+ t_phi /= vec2(textureSize(maxzBuffer, 0));
+
+ /* Avoid division by 0 */
+ t_phi += vec2(1e-5);
+
+ jitter *= 0.25;
+
+ /* Compute end points */
+ vec2 corner1 = min(vec2(1.0) - uvs, max_dir); /* Top right */
+ vec2 corner2 = max(vec2(0.0) - uvs, -max_dir); /* Bottom left */
+ vec2 iter1 = corner1 / t_phi;
+ vec2 iter2 = corner2 / t_phi;
+
+ vec2 min_iter = max(-iter1, -iter2);
+ vec2 max_iter = max( iter1, iter2);
+
+ vec2 times = vec2(-min_v2(min_iter), min_v2(max_iter));
+
+ vec2 h = vec2(-1.0); /* init at cos(pi) */
+
+ /* This is freaking sexy optimized. */
+ for (float i = 0.0, ofs = 4.0, time = -1.0;
+ i < MAX_SEARCH_ITER && time > times.x;
+ i++, time -= ofs, ofs = min(exp2(MAX_LOD) * 4.0, ofs + ofs * aoQuality))
+ {
+ vec4 t = max(times.xxxx, vec4(time) - (vec4(0.25, 0.5, 0.75, 1.0) - jitter) * ofs);
+ vec4 cos1 = uvs.xyxy + t_phi.xyxy * t.xxyy;
+ vec4 cos2 = uvs.xyxy + t_phi.xyxy * t.zzww;
+ float lod = min(MAX_LOD, max(i - jitter * 4.0, 0.0) * aoQuality);
+ get_max_horizon_grouped(cos1, cos2, pos, lod, h.y);
+ }
+
+ for (float i = 0.0, ofs = 4.0, time = 1.0;
+ i < MAX_SEARCH_ITER && time < times.y;
+ i++, time += ofs, ofs = min(exp2(MAX_LOD) * 4.0, ofs + ofs * aoQuality))
+ {
+ vec4 t = min(times.yyyy, vec4(time) + (vec4(0.25, 0.5, 0.75, 1.0) - jitter) * ofs);
+ vec4 cos1 = uvs.xyxy + t_phi.xyxy * t.xxyy;
+ vec4 cos2 = uvs.xyxy + t_phi.xyxy * t.zzww;
+ float lod = min(MAX_LOD, max(i - jitter * 4.0, 0.0) * aoQuality);
+ get_max_horizon_grouped(cos1, cos2, pos, lod, h.x);
+ }
+
+ return h;
+}
+
+void integrate_slice(vec3 normal, vec2 t_phi, vec2 horizons, inout float visibility, inout vec3 bent_normal)
+{
+ /* Projecting Normal to Plane P defined by t_phi and omega_o */
+ vec3 np = vec3(t_phi.y, -t_phi.x, 0.0); /* Normal vector to Integration plane */
+ vec3 t = vec3(-t_phi, 0.0);
+ vec3 n_proj = normal - np * dot(np, normal);
+ float n_proj_len = max(1e-16, length(n_proj));
+
+ float cos_n = clamp(n_proj.z / n_proj_len, -1.0, 1.0);
+ float n = sign(dot(n_proj, t)) * fast_acos(cos_n); /* Angle between view vec and normal */
+
+ /* (Slide 54) */
+ vec2 h = fast_acos(horizons);
+ h.x = -h.x;
+
+ /* Clamping thetas (slide 58) */
+ h.x = n + max(h.x - n, -M_PI_2);
+ h.y = n + min(h.y - n, M_PI_2);
+
+ /* Solving inner integral */
+ vec2 h_2 = 2.0 * h;
+ vec2 vd = -cos(h_2 - n) + cos_n + h_2 * sin(n);
+ float vis = (vd.x + vd.y) * 0.25 * n_proj_len;
+
+ visibility += vis;
+
+ /* Finding Bent normal */
+ float b_angle = (h.x + h.y) * 0.5;
+ /* The 0.5 factor below is here to equilibrate the accumulated vectors.
+ * (sin(b_angle) * -t_phi) will accumulate to (phi_step * result_nor.xy * 0.5).
+ * (cos(b_angle) * 0.5) will accumulate to (phi_step * result_nor.z * 0.5). */
+ bent_normal += vec3(sin(b_angle) * -t_phi, cos(b_angle) * 0.5);
+}
+
+void gtao_deferred(vec3 normal, vec3 position, vec4 noise, float frag_depth, out float visibility, out vec3 bent_normal)
+{
+ /* Fetch early, hide latency! */
+ vec4 horizons = texelFetch(horizonBuffer, ivec2(gl_FragCoord.xy), 0);
+
+ vec4 dirs;
+ dirs.xy = get_ao_dir(noise.x * 0.5);
+ dirs.zw = get_ao_dir(noise.x * 0.5 + 0.5);
+ vec2 uvs = get_uvs_from_view(position);
+
+ bent_normal = vec3(0.0);
+ visibility = 0.0;
+
+ horizons = unpack_horizons(horizons);
+
+ integrate_slice(normal, dirs.xy, horizons.xy, visibility, bent_normal);
+ integrate_slice(normal, dirs.zw, horizons.zw, visibility, bent_normal);
+
+ visibility *= 0.5; /* We integrated 2 slices. */
+
+ bent_normal = normalize(bent_normal);
+}
+
+void gtao(vec3 normal, vec3 position, vec4 noise, out float visibility, out vec3 bent_normal)
+{
+ vec2 uvs = get_uvs_from_view(position);
+ vec2 max_dir = get_max_dir(position.z);
+ vec2 dir = get_ao_dir(noise.x);
+
+ bent_normal = vec3(0.0);
+ visibility = 0.0;
+
+ /* Only trace in 2 directions. May lead to a darker result but since it's mostly for
+ * alpha blended objects that will have overdraw, we limit the performance impact. */
+ vec2 horizons = search_horizon_sweep(dir, position, uvs, noise.y, max_dir);
+ integrate_slice(normal, dir, horizons, visibility, bent_normal);
+
+ bent_normal = normalize(bent_normal);
+}
+
+/* Multibounce approximation base on surface albedo.
+ * Page 78 in the .pdf version. */
+float gtao_multibounce(float visibility, vec3 albedo)
+{
+ if (aoBounceFac == 0.0) return visibility;
+
+ /* Median luminance. Because Colored multibounce looks bad. */
+ float lum = dot(albedo, vec3(0.3333));
+
+ float a = 2.0404 * lum - 0.3324;
+ float b = -4.7951 * lum + 0.6417;
+ float c = 2.7552 * lum + 0.6903;
+
+ float x = visibility;
+ return max(x, ((x * a + b) * x + c) * x);
+}
+
+/* Use the right occlusion */
+float occlusion_compute(vec3 N, vec3 vpos, float user_occlusion, vec4 rand, out vec3 bent_normal)
+{
+#ifndef USE_REFRACTION
+ if ((int(aoSettings) & USE_AO) > 0) {
+ float visibility;
+ vec3 vnor = mat3(ViewMatrix) * N;
+
+#ifdef ENABLE_DEFERED_AO
+ gtao_deferred(vnor, vpos, rand, gl_FragCoord.z, visibility, bent_normal);
+#else
+ gtao(vnor, vpos, rand, visibility, bent_normal);
+#endif
+
+ /* Prevent some problems down the road. */
+ visibility = max(1e-3, visibility);
+
+ if ((int(aoSettings) & USE_BENT_NORMAL) != 0) {
+ /* The bent normal will show the facet look of the mesh. Try to minimize this. */
+ float mix_fac = visibility * visibility;
+ bent_normal = normalize(mix(bent_normal, vnor, mix_fac));
+
+ bent_normal = transform_direction(ViewMatrixInverse, bent_normal);
+ }
+ else {
+ bent_normal = N;
+ }
+
+ /* Scale by user factor */
+ visibility = pow(visibility, aoFactor);
+
+ return min(visibility, user_occlusion);
+ }
+#endif
+
+ bent_normal = N;
+ return user_occlusion;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/background_vert.glsl b/source/blender/draw/engines/eevee/shaders/background_vert.glsl
new file mode 100644
index 00000000000..b81aae9bcda
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/background_vert.glsl
@@ -0,0 +1,20 @@
+
+in vec2 pos;
+
+out vec3 varposition;
+out vec3 varnormal;
+out vec3 viewPosition;
+
+#ifndef VOLUMETRICS
+/* necessary for compilation*/
+out vec3 worldPosition;
+out vec3 worldNormal;
+out vec3 viewNormal;
+#endif
+
+void main()
+{
+ gl_Position = vec4(pos, 1.0, 1.0);
+ varposition = viewPosition = vec3(pos, -1.0);
+ varnormal = normalize(-varposition);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
new file mode 100644
index 00000000000..80d305cb1e8
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_common_lib.glsl
@@ -0,0 +1,826 @@
+
+#define M_PI 3.14159265358979323846 /* pi */
+#define M_2PI 6.28318530717958647692 /* 2*pi */
+#define M_PI_2 1.57079632679489661923 /* pi/2 */
+#define M_1_PI 0.318309886183790671538 /* 1/pi */
+#define M_1_2PI 0.159154943091895335768 /* 1/(2*pi) */
+#define M_1_PI2 0.101321183642337771443 /* 1/(pi^2) */
+
+#define LUT_SIZE 64
+
+/* Buffers */
+uniform sampler2D colorBuffer;
+uniform sampler2D depthBuffer;
+uniform sampler2D maxzBuffer;
+uniform sampler2D minzBuffer;
+uniform sampler2DArray planarDepth;
+
+#define cameraForward normalize(ViewMatrixInverse[2].xyz)
+#define cameraPos ViewMatrixInverse[3].xyz
+#define cameraVec ((ProjectionMatrix[3][3] == 0.0) ? normalize(cameraPos - worldPosition) : cameraForward)
+#define viewCameraVec ((ProjectionMatrix[3][3] == 0.0) ? normalize(-viewPosition) : vec3(0.0, 0.0, 1.0))
+
+/* ------- Structures -------- */
+
+/* ------ Lights ----- */
+struct LightData {
+ vec4 position_influence; /* w : InfluenceRadius */
+ vec4 color_spec; /* w : Spec Intensity */
+ vec4 spotdata_radius_shadow; /* x : spot size, y : spot blend, z : radius, w: shadow id */
+ vec4 rightvec_sizex; /* xyz: Normalized up vector, w: area size X or spot scale X */
+ vec4 upvec_sizey; /* xyz: Normalized right vector, w: area size Y or spot scale Y */
+ vec4 forwardvec_type; /* xyz: Normalized forward vector, w: Lamp Type */
+};
+
+/* convenience aliases */
+#define l_color color_spec.rgb
+#define l_spec color_spec.a
+#define l_position position_influence.xyz
+#define l_influence position_influence.w
+#define l_sizex rightvec_sizex.w
+#define l_sizey upvec_sizey.w
+#define l_right rightvec_sizex.xyz
+#define l_up upvec_sizey.xyz
+#define l_forward forwardvec_type.xyz
+#define l_type forwardvec_type.w
+#define l_spot_size spotdata_radius_shadow.x
+#define l_spot_blend spotdata_radius_shadow.y
+#define l_radius spotdata_radius_shadow.z
+#define l_shadowid spotdata_radius_shadow.w
+
+/* ------ Shadows ----- */
+#ifndef MAX_CASCADE_NUM
+#define MAX_CASCADE_NUM 4
+#endif
+
+struct ShadowData {
+ vec4 near_far_bias_exp;
+ vec4 shadow_data_start_end;
+ vec4 contact_shadow_data;
+};
+
+struct ShadowCubeData {
+ vec4 position;
+};
+
+struct ShadowCascadeData {
+ mat4 shadowmat[MAX_CASCADE_NUM];
+ vec4 split_start_distances;
+ vec4 split_end_distances;
+};
+
+/* convenience aliases */
+#define sh_near near_far_bias_exp.x
+#define sh_far near_far_bias_exp.y
+#define sh_bias near_far_bias_exp.z
+#define sh_exp near_far_bias_exp.w
+#define sh_bleed near_far_bias_exp.w
+#define sh_tex_start shadow_data_start_end.x
+#define sh_data_start shadow_data_start_end.y
+#define sh_multi_nbr shadow_data_start_end.z
+#define sh_blur shadow_data_start_end.w
+#define sh_contact_dist contact_shadow_data.x
+#define sh_contact_offset contact_shadow_data.y
+#define sh_contact_spread contact_shadow_data.z
+#define sh_contact_thickness contact_shadow_data.w
+
+/* ------- Convenience functions --------- */
+
+vec3 mul(mat3 m, vec3 v) { return m * v; }
+mat3 mul(mat3 m1, mat3 m2) { return m1 * m2; }
+vec3 transform_direction(mat4 m, vec3 v) { return mat3(m) * v; }
+vec3 transform_point(mat4 m, vec3 v) { return (m * vec4(v, 1.0)).xyz; }
+vec3 project_point(mat4 m, vec3 v) {
+ vec4 tmp = m * vec4(v, 1.0);
+ return tmp.xyz / tmp.w;
+}
+
+#define min3(a, b, c) min(a, min(b, c))
+#define min4(a, b, c, d) min(a, min3(b, c, d))
+#define min5(a, b, c, d, e) min(a, min4(b, c, d, e))
+#define min6(a, b, c, d, e, f) min(a, min5(b, c, d, e, f))
+#define min7(a, b, c, d, e, f, g) min(a, min6(b, c, d, e, f, g))
+#define min8(a, b, c, d, e, f, g, h) min(a, min7(b, c, d, e, f, g, h))
+#define min9(a, b, c, d, e, f, g, h, i) min(a, min8(b, c, d, e, f, g, h, i))
+
+#define max3(a, b, c) max(a, max(b, c))
+#define max4(a, b, c, d) max(a, max3(b, c, d))
+#define max5(a, b, c, d, e) max(a, max4(b, c, d, e))
+#define max6(a, b, c, d, e, f) max(a, max5(b, c, d, e, f))
+#define max7(a, b, c, d, e, f, g) max(a, max6(b, c, d, e, f, g))
+#define max8(a, b, c, d, e, f, g, h) max(a, max7(b, c, d, e, f, g, h))
+#define max9(a, b, c, d, e, f, g, h, i) max(a, max8(b, c, d, e, f, g, h, i))
+
+#define avg3(a, b, c) (a + b + c) * (1.0 / 3.0)
+#define avg4(a, b, c, d) (a + b + c + d) * (1.0 / 4.0)
+#define avg5(a, b, c, d, e) (a + b + c + d + e) * (1.0 / 5.0)
+#define avg6(a, b, c, d, e, f) (a + b + c + d + e + f) * (1.0 / 6.0)
+#define avg7(a, b, c, d, e, f, g) (a + b + c + d + e + f + g) * (1.0 / 7.0)
+#define avg8(a, b, c, d, e, f, g, h) (a + b + c + d + e + f + g + h) * (1.0 / 8.0)
+#define avg9(a, b, c, d, e, f, g, h, i) (a + b + c + d + e + f + g + h + i) * (1.0 / 9.0)
+
+float min_v2(vec2 v) { return min(v.x, v.y); }
+float min_v3(vec3 v) { return min(v.x, min(v.y, v.z)); }
+float max_v2(vec2 v) { return max(v.x, v.y); }
+float max_v3(vec3 v) { return max(v.x, max(v.y, v.z)); }
+
+float sum(vec2 v) { return dot(vec2(1.0), v); }
+float sum(vec3 v) { return dot(vec3(1.0), v); }
+float sum(vec4 v) { return dot(vec4(1.0), v); }
+
+float saturate(float a) { return clamp(a, 0.0, 1.0); }
+vec2 saturate(vec2 a) { return clamp(a, 0.0, 1.0); }
+vec3 saturate(vec3 a) { return clamp(a, 0.0, 1.0); }
+vec4 saturate(vec4 a) { return clamp(a, 0.0, 1.0); }
+
+float distance_squared(vec2 a, vec2 b) { a -= b; return dot(a, a); }
+float distance_squared(vec3 a, vec3 b) { a -= b; return dot(a, a); }
+float len_squared(vec3 a) { return dot(a, a); }
+
+float inverse_distance(vec3 V) { return max( 1 / length(V), 1e-8); }
+
+vec2 mip_ratio_interp(float mip) {
+ float low_mip = floor(mip);
+ return mix(mipRatio[int(low_mip)], mipRatio[int(low_mip + 1.0)], mip - low_mip);
+}
+/* ------- Fast Math ------- */
+
+/* [Drobot2014a] Low Level Optimizations for GCN */
+float fast_sqrt(float v)
+{
+ return intBitsToFloat(0x1fbd1df5 + (floatBitsToInt(v) >> 1));
+}
+
+vec2 fast_sqrt(vec2 v)
+{
+ return intBitsToFloat(0x1fbd1df5 + (floatBitsToInt(v) >> 1));
+}
+
+/* [Eberly2014] GPGPU Programming for Games and Science */
+float fast_acos(float v)
+{
+ float res = -0.156583 * abs(v) + M_PI_2;
+ res *= fast_sqrt(1.0 - abs(v));
+ return (v >= 0) ? res : M_PI - res;
+}
+
+vec2 fast_acos(vec2 v)
+{
+ vec2 res = -0.156583 * abs(v) + M_PI_2;
+ res *= fast_sqrt(1.0 - abs(v));
+ v.x = (v.x >= 0) ? res.x : M_PI - res.x;
+ v.y = (v.y >= 0) ? res.y : M_PI - res.y;
+ return v;
+}
+
+float point_plane_projection_dist(vec3 lineorigin, vec3 planeorigin, vec3 planenormal)
+{
+ return dot(planenormal, planeorigin - lineorigin);
+}
+
+float line_plane_intersect_dist(vec3 lineorigin, vec3 linedirection, vec3 planeorigin, vec3 planenormal)
+{
+ return dot(planenormal, planeorigin - lineorigin) / dot(planenormal, linedirection);
+}
+
+float line_plane_intersect_dist(vec3 lineorigin, vec3 linedirection, vec4 plane)
+{
+ vec3 plane_co = plane.xyz * (-plane.w / len_squared(plane.xyz));
+ vec3 h = lineorigin - plane_co;
+ return -dot(plane.xyz, h) / dot(plane.xyz, linedirection);
+}
+
+vec3 line_plane_intersect(vec3 lineorigin, vec3 linedirection, vec3 planeorigin, vec3 planenormal)
+{
+ float dist = line_plane_intersect_dist(lineorigin, linedirection, planeorigin, planenormal);
+ return lineorigin + linedirection * dist;
+}
+
+vec3 line_plane_intersect(vec3 lineorigin, vec3 linedirection, vec4 plane)
+{
+ float dist = line_plane_intersect_dist(lineorigin, linedirection, plane);
+ return lineorigin + linedirection * dist;
+}
+
+float line_aligned_plane_intersect_dist(vec3 lineorigin, vec3 linedirection, vec3 planeorigin)
+{
+ /* aligned plane normal */
+ vec3 L = planeorigin - lineorigin;
+ float diskdist = length(L);
+ vec3 planenormal = -normalize(L);
+ return -diskdist / dot(planenormal, linedirection);
+}
+
+vec3 line_aligned_plane_intersect(vec3 lineorigin, vec3 linedirection, vec3 planeorigin)
+{
+ float dist = line_aligned_plane_intersect_dist(lineorigin, linedirection, planeorigin);
+ if (dist < 0) {
+ /* if intersection is behind we fake the intersection to be
+ * really far and (hopefully) not inside the radius of interest */
+ dist = 1e16;
+ }
+ return lineorigin + linedirection * dist;
+}
+
+float line_unit_sphere_intersect_dist(vec3 lineorigin, vec3 linedirection)
+{
+ float a = dot(linedirection, linedirection);
+ float b = dot(linedirection, lineorigin);
+ float c = dot(lineorigin, lineorigin) - 1;
+
+ float dist = 1e15;
+ float determinant = b * b - a * c;
+ if (determinant >= 0)
+ dist = (sqrt(determinant) - b) / a;
+
+ return dist;
+}
+
+float line_unit_box_intersect_dist(vec3 lineorigin, vec3 linedirection)
+{
+ /* https://seblagarde.wordpress.com/2012/09/29/image-based-lighting-approaches-and-parallax-corrected-cubemap/ */
+ vec3 firstplane = (vec3( 1.0) - lineorigin) / linedirection;
+ vec3 secondplane = (vec3(-1.0) - lineorigin) / linedirection;
+ vec3 furthestplane = max(firstplane, secondplane);
+
+ return min_v3(furthestplane);
+}
+
+
+/* Return texture coordinates to sample Surface LUT */
+vec2 lut_coords(float cosTheta, float roughness)
+{
+ float theta = acos(cosTheta);
+ vec2 coords = vec2(roughness, theta / M_PI_2);
+
+ /* scale and bias coordinates, for correct filtered lookup */
+ return coords * (LUT_SIZE - 1.0) / LUT_SIZE + 0.5 / LUT_SIZE;
+}
+
+/* -- Tangent Space conversion -- */
+vec3 tangent_to_world(vec3 vector, vec3 N, vec3 T, vec3 B)
+{
+ return T * vector.x + B * vector.y + N * vector.z;
+}
+
+vec3 world_to_tangent(vec3 vector, vec3 N, vec3 T, vec3 B)
+{
+ return vec3( dot(T, vector), dot(B, vector), dot(N, vector));
+}
+
+void make_orthonormal_basis(vec3 N, out vec3 T, out vec3 B)
+{
+ vec3 UpVector = abs(N.z) < 0.99999 ? vec3(0.0,0.0,1.0) : vec3(1.0,0.0,0.0);
+ T = normalize( cross(UpVector, N) );
+ B = cross(N, T);
+}
+
+/* ---- Opengl Depth conversion ---- */
+
+float linear_depth(bool is_persp, float z, float zf, float zn)
+{
+ if (is_persp) {
+ return (zn * zf) / (z * (zn - zf) + zf);
+ }
+ else {
+ return (z * 2.0 - 1.0) * zf;
+ }
+}
+
+float buffer_depth(bool is_persp, float z, float zf, float zn)
+{
+ if (is_persp) {
+ return (zf * (zn - z)) / (z * (zn - zf));
+ }
+ else {
+ return (z / (zf * 2.0)) + 0.5;
+ }
+}
+
+float get_view_z_from_depth(float depth)
+{
+ if (ProjectionMatrix[3][3] == 0.0) {
+ float d = 2.0 * depth - 1.0;
+ return -ProjectionMatrix[3][2] / (d + ProjectionMatrix[2][2]);
+ }
+ else {
+ return viewVecs[0].z + depth * viewVecs[1].z;
+ }
+}
+
+float get_depth_from_view_z(float z)
+{
+ if (ProjectionMatrix[3][3] == 0.0) {
+ float d = (-ProjectionMatrix[3][2] / z) - ProjectionMatrix[2][2];
+ return d * 0.5 + 0.5;
+ }
+ else {
+ return (z - viewVecs[0].z) / viewVecs[1].z;
+ }
+}
+
+vec2 get_uvs_from_view(vec3 view)
+{
+ vec3 ndc = project_point(ProjectionMatrix, view);
+ return ndc.xy * 0.5 + 0.5;
+}
+
+vec3 get_view_space_from_depth(vec2 uvcoords, float depth)
+{
+ if (ProjectionMatrix[3][3] == 0.0) {
+ return vec3(viewVecs[0].xy + uvcoords * viewVecs[1].xy, 1.0) * get_view_z_from_depth(depth);
+ }
+ else {
+ return viewVecs[0].xyz + vec3(uvcoords, depth) * viewVecs[1].xyz;
+ }
+}
+
+vec3 get_world_space_from_depth(vec2 uvcoords, float depth)
+{
+ return (ViewMatrixInverse * vec4(get_view_space_from_depth(uvcoords, depth), 1.0)).xyz;
+}
+
+vec3 get_specular_reflection_dominant_dir(vec3 N, vec3 V, float roughness)
+{
+ vec3 R = -reflect(V, N);
+ float smoothness = 1.0 - roughness;
+ float fac = smoothness * (sqrt(smoothness) + roughness);
+ return normalize(mix(N, R, fac));
+}
+
+float specular_occlusion(float NV, float AO, float roughness)
+{
+ return saturate(pow(NV + AO, roughness) - 1.0 + AO);
+}
+
+/* --- Refraction utils --- */
+
+float ior_from_f0(float f0)
+{
+ float f = sqrt(f0);
+ return (-f - 1.0) / (f - 1.0);
+}
+
+float f0_from_ior(float eta)
+{
+ float A = (eta - 1.0) / (eta + 1.0);
+ return A * A;
+}
+
+vec3 get_specular_refraction_dominant_dir(vec3 N, vec3 V, float roughness, float ior)
+{
+ /* TODO: This a bad approximation. Better approximation should fit
+ * the refracted vector and roughness into the best prefiltered reflection
+ * lobe. */
+ /* Correct the IOR for ior < 1.0 to not see the abrupt delimitation or the TIR */
+ ior = (ior < 1.0) ? mix(ior, 1.0, roughness) : ior;
+ float eta = 1.0 / ior;
+
+ float NV = dot(N, -V);
+
+ /* Custom Refraction. */
+ float k = 1.0 - eta * eta * (1.0 - NV * NV);
+ k = max(0.0, k); /* Only this changes. */
+ vec3 R = eta * -V - (eta * NV + sqrt(k)) * N;
+
+ return R;
+}
+
+float get_btdf_lut(sampler2DArray btdf_lut_tex, float NV, float roughness, float ior)
+{
+ const vec3 lut_scale_bias_texel_size = vec3((LUT_SIZE - 1.0), 0.5, 1.5) / LUT_SIZE;
+
+ vec3 coords;
+ /* Try to compensate for the low resolution and interpolation error. */
+ coords.x = (ior > 1.0)
+ ? (0.9 + lut_scale_bias_texel_size.z) + (0.1 - lut_scale_bias_texel_size.z) * f0_from_ior(ior)
+ : (0.9 + lut_scale_bias_texel_size.z) * ior * ior;
+ coords.y = 1.0 - saturate(NV);
+ coords.xy *= lut_scale_bias_texel_size.x;
+ coords.xy += lut_scale_bias_texel_size.y;
+
+ const float lut_lvl_ofs = 4.0; /* First texture lvl of roughness. */
+ const float lut_lvl_scale = 16.0; /* How many lvl of roughness in the lut. */
+
+ float mip = roughness * lut_lvl_scale;
+ float mip_floor = floor(mip);
+
+ coords.z = lut_lvl_ofs + mip_floor + 1.0;
+ float btdf_high = textureLod(btdf_lut_tex, coords, 0.0).r;
+
+ coords.z -= 1.0;
+ float btdf_low = textureLod(btdf_lut_tex, coords, 0.0).r;
+
+ float btdf = (ior == 1.0) ? 1.0 : mix(btdf_low, btdf_high, mip - coords.z);
+
+ return btdf;
+}
+
+/* ---- Encode / Decode Normal buffer data ---- */
+/* From http://aras-p.info/texts/CompactNormalStorage.html
+ * Using Method #4: Spheremap Transform */
+vec2 normal_encode(vec3 n, vec3 view)
+{
+ float p = sqrt(n.z * 8.0 + 8.0);
+ return n.xy / p + 0.5;
+}
+
+vec3 normal_decode(vec2 enc, vec3 view)
+{
+ vec2 fenc = enc * 4.0 - 2.0;
+ float f = dot(fenc, fenc);
+ float g = sqrt(1.0 - f / 4.0);
+ vec3 n;
+ n.xy = fenc*g;
+ n.z = 1 - f / 2;
+ return n;
+}
+
+/* ---- RGBM (shared multiplier) encoding ---- */
+/* From http://iwasbeingirony.blogspot.fr/2010/06/difference-between-rgbm-and-rgbd.html */
+
+/* Higher RGBM_MAX_RANGE gives imprecision issues in low intensity. */
+#define RGBM_MAX_RANGE 512.0
+
+vec4 rgbm_encode(vec3 rgb)
+{
+ float maxRGB = max_v3(rgb);
+ float M = maxRGB / RGBM_MAX_RANGE;
+ M = ceil(M * 255.0) / 255.0;
+ return vec4(rgb / (M * RGBM_MAX_RANGE), M);
+}
+
+vec3 rgbm_decode(vec4 data)
+{
+ return data.rgb * (data.a * RGBM_MAX_RANGE);
+}
+
+/* ---- RGBE (shared exponent) encoding ---- */
+vec4 rgbe_encode(vec3 rgb)
+{
+ float maxRGB = max_v3(rgb);
+ float fexp = ceil(log2(maxRGB));
+ return vec4(rgb / exp2(fexp), (fexp + 128.0) / 255.0);
+}
+
+vec3 rgbe_decode(vec4 data)
+{
+ float fexp = data.a * 255.0 - 128.0;
+ return data.rgb * exp2(fexp);
+}
+
+#if 1
+#define irradiance_encode rgbe_encode
+#define irradiance_decode rgbe_decode
+#else /* No ecoding (when using floating point format) */
+#define irradiance_encode(X) (X).rgbb
+#define irradiance_decode(X) (X).rgb
+#endif
+
+/* Irradiance Visibility Encoding */
+#if 1
+vec4 visibility_encode(vec2 accum, float range)
+{
+ accum /= range;
+
+ vec4 data;
+ data.x = fract(accum.x);
+ data.y = floor(accum.x) / 255.0;
+ data.z = fract(accum.y);
+ data.w = floor(accum.y) / 255.0;
+
+ return data;
+}
+
+vec2 visibility_decode(vec4 data, float range)
+{
+ return (data.xz + data.yw * 255.0) * range;
+}
+#else /* No ecoding (when using floating point format) */
+vec4 visibility_encode(vec2 accum, float range)
+{
+ return accum.xyxy;
+}
+
+vec2 visibility_decode(vec4 data, float range)
+{
+ return data.xy;
+}
+#endif
+
+/* Fresnel monochromatic, perfect mirror */
+float F_eta(float eta, float cos_theta)
+{
+ /* compute fresnel reflectance without explicitly computing
+ * the refracted direction */
+ float c = abs(cos_theta);
+ float g = eta * eta - 1.0 + c * c;
+ float result;
+
+ if (g > 0.0) {
+ g = sqrt(g);
+ vec2 g_c = vec2(g) + vec2(c, -c);
+ float A = g_c.y / g_c.x;
+ A *= A;
+ g_c *= c;
+ float B = (g_c.y - 1.0) / (g_c.x + 1.0);
+ B *= B;
+ result = 0.5 * A * (1.0 + B);
+ }
+ else {
+ result = 1.0; /* TIR (no refracted component) */
+ }
+
+ return result;
+}
+
+/* Fresnel */
+vec3 F_schlick(vec3 f0, float cos_theta)
+{
+ float fac = 1.0 - cos_theta;
+ float fac2 = fac * fac;
+ fac = fac2 * fac2 * fac;
+
+ /* Unreal specular matching : if specular color is below 2% intensity,
+ * (using green channel for intensity) treat as shadowning */
+ return saturate(50.0 * dot(f0, vec3(0.3, 0.6, 0.1))) * fac + (1.0 - fac) * f0;
+}
+
+/* Fresnel approximation for LTC area lights (not MRP) */
+vec3 F_area(vec3 f0, vec2 lut)
+{
+ vec2 fac = normalize(lut.xy); /* XXX FIXME this does not work!!! */
+
+ /* Unreal specular matching : if specular color is below 2% intensity,
+ * treat as shadowning */
+ return saturate(50.0 * dot(f0, vec3(0.3, 0.6, 0.1))) * fac.y + fac.x * f0;
+}
+
+/* Fresnel approximation for IBL */
+vec3 F_ibl(vec3 f0, vec2 lut)
+{
+ /* Unreal specular matching : if specular color is below 2% intensity,
+ * treat as shadowning */
+ return saturate(50.0 * dot(f0, vec3(0.3, 0.6, 0.1))) * lut.y + lut.x * f0;
+}
+
+/* GGX */
+float D_ggx_opti(float NH, float a2)
+{
+ float tmp = (NH * a2 - NH) * NH + 1.0;
+ return M_PI * tmp*tmp; /* Doing RCP and mul a2 at the end */
+}
+
+float G1_Smith_GGX(float NX, float a2)
+{
+ /* Using Brian Karis approach and refactoring by NX/NX
+ * this way the (2*NL)*(2*NV) in G = G1(V) * G1(L) gets canceled by the brdf denominator 4*NL*NV
+ * Rcp is done on the whole G later
+ * Note that this is not convenient for the transmition formula */
+ return NX + sqrt(NX * (NX - NX * a2) + a2);
+ /* return 2 / (1 + sqrt(1 + a2 * (1 - NX*NX) / (NX*NX) ) ); /* Reference function */
+}
+
+float bsdf_ggx(vec3 N, vec3 L, vec3 V, float roughness)
+{
+ float a = roughness;
+ float a2 = a * a;
+
+ vec3 H = normalize(L + V);
+ float NH = max(dot(N, H), 1e-8);
+ float NL = max(dot(N, L), 1e-8);
+ float NV = max(dot(N, V), 1e-8);
+
+ float G = G1_Smith_GGX(NV, a2) * G1_Smith_GGX(NL, a2); /* Doing RCP at the end */
+ float D = D_ggx_opti(NH, a2);
+
+ /* Denominator is canceled by G1_Smith */
+ /* bsdf = D * G / (4.0 * NL * NV); /* Reference function */
+ return NL * a2 / (D * G); /* NL to Fit cycles Equation : line. 345 in bsdf_microfacet.h */
+}
+
+void accumulate_light(vec3 light, float fac, inout vec4 accum)
+{
+ accum += vec4(light, 1.0) * min(fac, (1.0 - accum.a));
+}
+
+/* ----------- Cone Apperture Approximation --------- */
+
+/* Return a fitted cone angle given the input roughness */
+float cone_cosine(float r)
+{
+ /* Using phong gloss
+ * roughness = sqrt(2/(gloss+2)) */
+ float gloss = -2 + 2 / (r * r);
+ /* Drobot 2014 in GPUPro5 */
+ // return cos(2.0 * sqrt(2.0 / (gloss + 2)));
+ /* Uludag 2014 in GPUPro5 */
+ // return pow(0.244, 1 / (gloss + 1));
+ /* Jimenez 2016 in Practical Realtime Strategies for Accurate Indirect Occlusion*/
+ return exp2(-3.32193 * r * r);
+}
+
+/* --------- Closure ---------- */
+#ifdef VOLUMETRICS
+
+struct Closure {
+ vec3 absorption;
+ vec3 scatter;
+ vec3 emission;
+ float anisotropy;
+};
+
+#define CLOSURE_DEFAULT Closure(vec3(0.0), vec3(0.0), vec3(0.0), 0.0)
+
+Closure closure_mix(Closure cl1, Closure cl2, float fac)
+{
+ Closure cl;
+ cl.absorption = mix(cl1.absorption, cl2.absorption, fac);
+ cl.scatter = mix(cl1.scatter, cl2.scatter, fac);
+ cl.emission = mix(cl1.emission, cl2.emission, fac);
+ cl.anisotropy = mix(cl1.anisotropy, cl2.anisotropy, fac);
+ return cl;
+}
+
+Closure closure_add(Closure cl1, Closure cl2)
+{
+ Closure cl;
+ cl.absorption = cl1.absorption + cl2.absorption;
+ cl.scatter = cl1.scatter + cl2.scatter;
+ cl.emission = cl1.emission + cl2.emission;
+ cl.anisotropy = (cl1.anisotropy + cl2.anisotropy) / 2.0; /* Average phase (no multi lobe) */
+ return cl;
+}
+
+#else /* VOLUMETRICS */
+
+struct Closure {
+ vec3 radiance;
+ float opacity;
+# ifdef USE_SSS
+ vec4 sss_data;
+# ifdef USE_SSS_ALBEDO
+ vec3 sss_albedo;
+# endif
+# endif
+ vec4 ssr_data;
+ vec2 ssr_normal;
+ int ssr_id;
+};
+
+/* This is hacking ssr_id to tag transparent bsdf */
+#define TRANSPARENT_CLOSURE_FLAG -2
+#define REFRACT_CLOSURE_FLAG -3
+
+# ifdef USE_SSS
+# ifdef USE_SSS_ALBEDO
+#define CLOSURE_DEFAULT Closure(vec3(0.0), 1.0, vec4(0.0), vec3(0.0), vec4(0.0), vec2(0.0), -1)
+# else
+#define CLOSURE_DEFAULT Closure(vec3(0.0), 1.0, vec4(0.0), vec4(0.0), vec2(0.0), -1)
+# endif
+# else
+#define CLOSURE_DEFAULT Closure(vec3(0.0), 1.0, vec4(0.0), vec2(0.0), -1)
+# endif
+
+uniform int outputSsrId;
+
+Closure closure_mix(Closure cl1, Closure cl2, float fac)
+{
+ Closure cl;
+
+ if (cl1.ssr_id == TRANSPARENT_CLOSURE_FLAG) {
+ cl1.radiance = cl2.radiance;
+ cl1.ssr_normal = cl2.ssr_normal;
+ cl1.ssr_data = cl2.ssr_data;
+ cl1.ssr_id = cl2.ssr_id;
+# ifdef USE_SSS
+ cl1.sss_data = cl2.sss_data;
+# ifdef USE_SSS_ALBEDO
+ cl1.sss_albedo = cl2.sss_albedo;
+# endif
+# endif
+ }
+ if (cl2.ssr_id == TRANSPARENT_CLOSURE_FLAG) {
+ cl2.radiance = cl1.radiance;
+ cl2.ssr_normal = cl1.ssr_normal;
+ cl2.ssr_data = cl1.ssr_data;
+ cl2.ssr_id = cl1.ssr_id;
+# ifdef USE_SSS
+ cl2.sss_data = cl1.sss_data;
+# ifdef USE_SSS_ALBEDO
+ cl2.sss_albedo = cl1.sss_albedo;
+# endif
+# endif
+ }
+ if (cl1.ssr_id == outputSsrId) {
+ cl.ssr_data = mix(cl1.ssr_data.xyzw, vec4(vec3(0.0), cl1.ssr_data.w), fac); /* do not blend roughness */
+ cl.ssr_normal = cl1.ssr_normal;
+ cl.ssr_id = cl1.ssr_id;
+ }
+ else {
+ cl.ssr_data = mix(vec4(vec3(0.0), cl2.ssr_data.w), cl2.ssr_data.xyzw, fac); /* do not blend roughness */
+ cl.ssr_normal = cl2.ssr_normal;
+ cl.ssr_id = cl2.ssr_id;
+ }
+ cl.radiance = mix(cl1.radiance, cl2.radiance, fac);
+ cl.opacity = mix(cl1.opacity, cl2.opacity, fac);
+
+# ifdef USE_SSS
+ cl.sss_data.rgb = mix(cl1.sss_data.rgb, cl2.sss_data.rgb, fac);
+ cl.sss_data.a = (cl1.sss_data.a > 0.0) ? cl1.sss_data.a : cl2.sss_data.a;
+# ifdef USE_SSS_ALBEDO
+ /* TODO Find a solution to this. Dither? */
+ cl.sss_albedo = (cl1.sss_data.a > 0.0) ? cl1.sss_albedo : cl2.sss_albedo;
+# endif
+# endif
+
+ return cl;
+}
+
+Closure closure_add(Closure cl1, Closure cl2)
+{
+ Closure cl = (cl1.ssr_id == outputSsrId) ? cl1 : cl2;
+# ifdef USE_SSS
+ cl.sss_data = (cl1.sss_data.a > 0.0) ? cl1.sss_data : cl2.sss_data;
+# ifdef USE_SSS_ALBEDO
+ /* TODO Find a solution to this. Dither? */
+ cl.sss_albedo = (cl1.sss_data.a > 0.0) ? cl1.sss_albedo : cl2.sss_albedo;
+# endif
+# endif
+ cl.radiance = cl1.radiance + cl2.radiance;
+ cl.opacity = saturate(cl1.opacity + cl2.opacity);
+ return cl;
+}
+
+# if defined(MESH_SHADER) && !defined(USE_ALPHA_HASH) && !defined(USE_ALPHA_CLIP) && !defined(SHADOW_SHADER) && !defined(USE_MULTIPLY)
+layout(location = 0) out vec4 fragColor;
+layout(location = 1) out vec4 ssrNormals;
+layout(location = 2) out vec4 ssrData;
+# ifdef USE_SSS
+layout(location = 3) out vec4 sssData;
+# ifdef USE_SSS_ALBEDO
+layout(location = 4) out vec4 sssAlbedo;
+# endif /* USE_SSS_ALBEDO */
+# endif /* USE_SSS */
+
+Closure nodetree_exec(void); /* Prototype */
+
+# if defined(USE_ALPHA_BLEND_VOLUMETRICS)
+/* Prototype because this file is included before volumetric_lib.glsl */
+vec4 volumetric_resolve(vec4 scene_color, vec2 frag_uvs, float frag_depth);
+# endif
+
+#define NODETREE_EXEC
+void main()
+{
+ Closure cl = nodetree_exec();
+# ifndef USE_ALPHA_BLEND
+ /* Prevent alpha hash material writing into alpha channel. */
+ cl.opacity = 1.0;
+# endif
+
+# if defined(USE_ALPHA_BLEND_VOLUMETRICS)
+ /* XXX fragile, better use real viewport resolution */
+ vec2 uvs = gl_FragCoord.xy / vec2(2 * textureSize(maxzBuffer, 0).xy);
+ fragColor = volumetric_resolve(vec4(cl.radiance, cl.opacity), uvs, gl_FragCoord.z);
+# else
+ fragColor = vec4(cl.radiance, cl.opacity);
+# endif
+
+ ssrNormals = cl.ssr_normal.xyyy;
+ ssrData = cl.ssr_data;
+# ifdef USE_SSS
+ sssData = cl.sss_data;
+# ifdef USE_SSS_ALBEDO
+ sssAlbedo = cl.sss_albedo.rgbb;
+# endif
+# endif
+
+ /* For Probe capture */
+# ifdef USE_SSS
+# ifdef USE_SSS_ALBEDO
+ fragColor.rgb += cl.sss_data.rgb * cl.sss_albedo.rgb * float(!sssToggle);
+# else
+ fragColor.rgb += cl.sss_data.rgb * float(!sssToggle);
+# endif
+# endif
+}
+
+# endif /* MESH_SHADER && !SHADOW_SHADER */
+
+#endif /* VOLUMETRICS */
+
+Closure nodetree_exec(void); /* Prototype */
+
+/* TODO find a better place */
+#ifdef USE_MULTIPLY
+
+out vec4 fragColor;
+
+#define NODETREE_EXEC
+void main()
+{
+ Closure cl = nodetree_exec();
+ fragColor = vec4(mix(vec3(1.0), cl.radiance, cl.opacity), 1.0);
+}
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl
new file mode 100644
index 00000000000..d5b54097638
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_direct_lib.glsl
@@ -0,0 +1,156 @@
+/* Bsdf direct light function */
+/* in other word, how materials react to scene lamps */
+
+/* Naming convention
+ * V View vector (normalized)
+ * N World Normal (normalized)
+ * L Outgoing Light Vector (Surface to Light in World Space) (normalized)
+ * Ldist Distance from surface to the light
+ * W World Pos
+ */
+
+/* ------------ Diffuse ------------- */
+
+float direct_diffuse_point(vec3 N, vec4 l_vector)
+{
+ float dist = l_vector.w;
+ vec3 L = l_vector.xyz / dist;
+ float bsdf = max(0.0, dot(N, L));
+ bsdf /= dist * dist;
+ return bsdf;
+}
+
+/* infinitly far away point source, no decay */
+float direct_diffuse_sun(LightData ld, vec3 N)
+{
+ float bsdf = max(0.0, dot(N, -ld.l_forward));
+ bsdf *= M_1_PI; /* Normalize */
+ return bsdf;
+}
+
+#ifdef USE_LTC
+float direct_diffuse_sphere(LightData ld, vec3 N, vec4 l_vector)
+{
+ float NL = dot(N, l_vector.xyz / l_vector.w);
+
+ return ltc_evaluate_disk_simple(ld.l_radius / l_vector.w, NL);
+}
+
+float direct_diffuse_rectangle(LightData ld, vec3 N, vec3 V, vec4 l_vector)
+{
+ vec3 corners[4];
+ corners[0] = normalize(l_vector.xyz + ld.l_right * -ld.l_sizex + ld.l_up * ld.l_sizey);
+ corners[1] = normalize(l_vector.xyz + ld.l_right * -ld.l_sizex + ld.l_up * -ld.l_sizey);
+ corners[2] = normalize(l_vector.xyz + ld.l_right * ld.l_sizex + ld.l_up * -ld.l_sizey);
+ corners[3] = normalize(l_vector.xyz + ld.l_right * ld.l_sizex + ld.l_up * ld.l_sizey);
+
+ return ltc_evaluate_quad(corners, N);
+}
+
+float direct_diffuse_unit_disc(LightData ld, vec3 N, vec3 V)
+{
+ float NL = dot(N, -ld.l_forward);
+
+ return ltc_evaluate_disk_simple(ld.l_radius, NL);
+}
+#endif
+
+/* ----------- GGx ------------ */
+vec3 direct_ggx_point(vec3 N, vec3 V, vec4 l_vector, float roughness, vec3 f0)
+{
+ roughness = max(1e-3, roughness);
+ float dist = l_vector.w;
+ vec3 L = l_vector.xyz / dist;
+ float bsdf = bsdf_ggx(N, L, V, roughness);
+ bsdf /= dist * dist;
+
+ /* Fresnel */
+ float VH = max(dot(V, normalize(V + L)), 0.0);
+ return F_schlick(f0, VH) * bsdf;
+}
+
+vec3 direct_ggx_sun(LightData ld, vec3 N, vec3 V, float roughness, vec3 f0)
+{
+ roughness = max(1e-3, roughness);
+ float bsdf = bsdf_ggx(N, -ld.l_forward, V, roughness);
+ float VH = dot(V, -ld.l_forward) * 0.5 + 0.5;
+ return F_schlick(f0, VH) * bsdf;
+}
+
+#ifdef USE_LTC
+vec3 direct_ggx_sphere(LightData ld, vec3 N, vec3 V, vec4 l_vector, float roughness, vec3 f0)
+{
+ roughness = clamp(roughness, 0.0008, 0.999); /* Fix low roughness artifacts. */
+
+ vec2 uv = lut_coords(dot(N, V), sqrt(roughness));
+ vec3 brdf_lut = texture(utilTex, vec3(uv, 1.0)).rgb;
+ vec4 ltc_lut = texture(utilTex, vec3(uv, 0.0)).rgba;
+ mat3 ltc_mat = ltc_matrix(ltc_lut);
+
+ /* Make orthonormal basis. */
+ vec3 L = l_vector.xyz / l_vector.w;
+ vec3 Px, Py;
+ make_orthonormal_basis(L, Px, Py);
+ Px *= ld.l_radius;
+ Py *= ld.l_radius;
+
+ vec3 points[3];
+ points[0] = l_vector.xyz - Px - Py;
+ points[1] = l_vector.xyz + Px - Py;
+ points[2] = l_vector.xyz + Px + Py;
+
+ float bsdf = ltc_evaluate_disk(N, V, ltc_mat, points);
+ bsdf *= brdf_lut.b; /* Bsdf intensity */
+
+ vec3 spec = F_area(f0, brdf_lut.xy) * bsdf;
+
+ return spec;
+}
+
+vec3 direct_ggx_rectangle(LightData ld, vec3 N, vec3 V, vec4 l_vector, float roughness, vec3 f0)
+{
+ vec3 corners[4];
+ corners[0] = l_vector.xyz + ld.l_right * -ld.l_sizex + ld.l_up * ld.l_sizey;
+ corners[1] = l_vector.xyz + ld.l_right * -ld.l_sizex + ld.l_up * -ld.l_sizey;
+ corners[2] = l_vector.xyz + ld.l_right * ld.l_sizex + ld.l_up * -ld.l_sizey;
+ corners[3] = l_vector.xyz + ld.l_right * ld.l_sizex + ld.l_up * ld.l_sizey;
+
+ vec2 uv = lut_coords(dot(N, V), sqrt(roughness));
+ vec3 brdf_lut = texture(utilTex, vec3(uv, 1.0)).rgb;
+ vec4 ltc_lut = texture(utilTex, vec3(uv, 0.0)).rgba;
+ mat3 ltc_mat = ltc_matrix(ltc_lut);
+
+ ltc_transform_quad(N, V, ltc_mat, corners);
+ float bsdf = ltc_evaluate_quad(corners, vec3(0.0, 0.0, 1.0));
+ bsdf *= brdf_lut.b; /* Bsdf intensity */
+
+ vec3 spec = F_area(f0, brdf_lut.xy) * bsdf;
+
+ return spec;
+}
+
+vec3 direct_ggx_unit_disc(LightData ld, vec3 N, vec3 V, float roughness, vec3 f0)
+{
+ roughness = clamp(roughness, 0.0004, 0.999); /* Fix low roughness artifacts. */
+
+ vec2 uv = lut_coords(dot(N, V), sqrt(roughness));
+ vec3 brdf_lut = texture(utilTex, vec3(uv, 1.0)).rgb;
+ vec4 ltc_lut = texture(utilTex, vec3(uv, 0.0)).rgba;
+ mat3 ltc_mat = ltc_matrix(ltc_lut);
+
+ vec3 Px = ld.l_right * ld.l_radius;
+ vec3 Py = ld.l_up * ld.l_radius;
+
+ vec3 points[3];
+ points[0] = -ld.l_forward - Px - Py;
+ points[1] = -ld.l_forward + Px - Py;
+ points[2] = -ld.l_forward + Px + Py;
+
+ float bsdf = ltc_evaluate_disk(N, V, ltc_mat, points);
+ bsdf *= brdf_lut.b; /* Bsdf intensity */
+
+ vec3 spec = F_area(f0, brdf_lut.xy) * bsdf;
+
+ return spec;
+}
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl
new file mode 100644
index 00000000000..7fb4ee51a96
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_lut_frag.glsl
@@ -0,0 +1,46 @@
+
+out vec4 FragColor;
+
+void main() {
+ vec3 N, T, B, V;
+
+ float NV = ( 1.0 - (clamp(gl_FragCoord.y / BRDF_LUT_SIZE, 1e-4, 0.9999)));
+ float sqrtRoughness = clamp(gl_FragCoord.x / BRDF_LUT_SIZE, 1e-4, 0.9999);
+ float a = sqrtRoughness * sqrtRoughness;
+ float a2 = a * a;
+
+ N = vec3(0.0, 0.0, 1.0);
+ T = vec3(1.0, 0.0, 0.0);
+ B = vec3(0.0, 1.0, 0.0);
+ V = vec3(sqrt(1.0 - NV * NV), 0.0, NV);
+
+ setup_noise();
+
+ /* Integrating BRDF */
+ float brdf_accum = 0.0;
+ float fresnel_accum = 0.0;
+ for (float i = 0; i < sampleCount; i++) {
+ vec3 H = sample_ggx(i, a2, N, T, B); /* Microfacet normal */
+ vec3 L = -reflect(V, H);
+ float NL = L.z;
+
+ if (NL > 0.0) {
+ float NH = max(H.z, 0.0);
+ float VH = max(dot(V, H), 0.0);
+
+ float G1_v = G1_Smith_GGX(NV, a2);
+ float G1_l = G1_Smith_GGX(NL, a2);
+ float G_smith = 4.0 * NV * NL / (G1_v * G1_l); /* See G1_Smith_GGX for explanations. */
+
+ float brdf = (G_smith * VH) / (NH * NV);
+ float Fc = pow(1.0 - VH, 5.0);
+
+ brdf_accum += (1.0 - Fc) * brdf;
+ fresnel_accum += Fc * brdf;
+ }
+ }
+ brdf_accum /= sampleCount;
+ fresnel_accum /= sampleCount;
+
+ FragColor = vec4(brdf_accum, fresnel_accum, 0.0, 1.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl b/source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl
new file mode 100644
index 00000000000..cce9d59dc12
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/bsdf_sampling_lib.glsl
@@ -0,0 +1,107 @@
+
+uniform sampler1D texHammersley;
+uniform sampler2D texJitter;
+uniform float sampleCount;
+uniform float invSampleCount;
+
+vec2 jitternoise = vec2(0.0);
+
+#ifndef UTIL_TEX
+#define UTIL_TEX
+uniform sampler2DArray utilTex;
+#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
+#endif /* UTIL_TEX */
+
+void setup_noise(void)
+{
+ jitternoise = texelfetch_noise_tex(gl_FragCoord.xy).rg; /* Global variable */
+}
+
+#ifdef HAMMERSLEY_SIZE
+vec3 hammersley_3d(float i, float invsamplenbr)
+{
+ vec3 Xi; /* Theta, cos(Phi), sin(Phi) */
+
+ Xi.x = i * invsamplenbr; /* i/samples */
+ Xi.x = fract(Xi.x + jitternoise.x);
+
+ int u = int(mod(i + jitternoise.y * HAMMERSLEY_SIZE, HAMMERSLEY_SIZE));
+
+ Xi.yz = texelFetch(texHammersley, u, 0).rg;
+
+ return Xi;
+}
+
+vec3 hammersley_3d(float i)
+{
+ return hammersley_3d(i, invSampleCount);
+}
+#endif
+
+/* -------------- BSDFS -------------- */
+
+float pdf_ggx_reflect(float NH, float a2)
+{
+ return NH * a2 / D_ggx_opti(NH, a2);
+}
+
+float pdf_hemisphere()
+{
+ return 0.5 * M_1_PI;
+}
+
+vec3 sample_ggx(vec3 rand, float a2)
+{
+ /* Theta is the aperture angle of the cone */
+ float z = sqrt( (1.0 - rand.x) / ( 1.0 + a2 * rand.x - rand.x ) ); /* cos theta */
+ float r = sqrt(max(0.0, 1.0f - z*z)); /* sin theta */
+ float x = r * rand.y;
+ float y = r * rand.z;
+
+ /* Microfacet Normal */
+ return vec3(x, y, z);
+}
+
+vec3 sample_ggx(vec3 rand, float a2, vec3 N, vec3 T, vec3 B, out float NH)
+{
+ vec3 Ht = sample_ggx(rand, a2);
+ NH = Ht.z;
+ return tangent_to_world(Ht, N, T, B);
+}
+
+#ifdef HAMMERSLEY_SIZE
+vec3 sample_ggx(float nsample, float a2, vec3 N, vec3 T, vec3 B)
+{
+ vec3 Xi = hammersley_3d(nsample);
+ vec3 Ht = sample_ggx(Xi, a2);
+ return tangent_to_world(Ht, N, T, B);
+}
+
+vec3 sample_hemisphere(float nsample, vec3 N, vec3 T, vec3 B)
+{
+ vec3 Xi = hammersley_3d(nsample);
+
+ float z = Xi.x; /* cos theta */
+ float r = sqrt(max(0.0, 1.0f - z*z)); /* sin theta */
+ float x = r * Xi.y;
+ float y = r * Xi.z;
+
+ vec3 Ht = vec3(x, y, z);
+
+ return tangent_to_world(Ht, N, T, B);
+}
+
+vec3 sample_cone(float nsample, float angle, vec3 N, vec3 T, vec3 B)
+{
+ vec3 Xi = hammersley_3d(nsample);
+
+ float z = cos(angle * Xi.x); /* cos theta */
+ float r = sqrt(max(0.0, 1.0f - z*z)); /* sin theta */
+ float x = r * Xi.y;
+ float y = r * Xi.z;
+
+ vec3 Ht = vec3(x, y, z);
+
+ return tangent_to_world(Ht, N, T, B);
+}
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/btdf_lut_frag.glsl b/source/blender/draw/engines/eevee/shaders/btdf_lut_frag.glsl
new file mode 100644
index 00000000000..5f0af6a6f5b
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/btdf_lut_frag.glsl
@@ -0,0 +1,59 @@
+
+uniform float a2;
+
+out vec4 FragColor;
+
+void main() {
+ vec3 N, T, B, V;
+
+ float x = gl_FragCoord.x / BRDF_LUT_SIZE;
+ float y = gl_FragCoord.y / BRDF_LUT_SIZE;
+ /* There is little variation if ior > 1.0 so we
+ * maximize LUT precision for ior < 1.0 */
+ x = x * 1.1;
+ float ior = (x > 1.0) ? ior_from_f0((x-1.0) * 10.0) : sqrt(x);
+ float NV = (1.0 - (clamp(y, 1e-4, 0.9999)));
+
+ N = vec3(0.0, 0.0, 1.0);
+ T = vec3(1.0, 0.0, 0.0);
+ B = vec3(0.0, 1.0, 0.0);
+ V = vec3(sqrt(1.0 - NV * NV), 0.0, NV);
+
+ setup_noise();
+
+ /* Integrating BTDF */
+ float btdf_accum = 0.0;
+ for (float i = 0.0; i < sampleCount; i++) {
+ vec3 H = sample_ggx(i, a2, N, T, B); /* Microfacet normal */
+
+ float VH = dot(V, H);
+
+ /* Check if there is total internal reflections. */
+ float c = abs(VH);
+ float g = ior * ior - 1.0 + c * c;
+
+ float eta = 1.0/ior;
+ if (dot(H, V) < 0.0) {
+ H = -H;
+ eta = ior;
+ }
+
+ vec3 L = refract(-V, H, eta);
+ float NL = -dot(N, L);
+
+ if ((NL > 0.0) && (g > 0.0)) {
+ float LH = dot(L, H);
+
+ float G1_l = NL * 2.0 / G1_Smith_GGX(NL, a2); /* Balancing the adjustments made in G1_Smith */
+
+ /* btdf = abs(VH*LH) * (ior*ior) * D * G(V) * G(L) / (Ht2 * NV)
+ * pdf = (VH * abs(LH)) * (ior*ior) * D * G(V) / (Ht2 * NV) */
+ float btdf = G1_l * abs(VH*LH) / (VH * abs(LH));
+
+ btdf_accum += btdf;
+ }
+ }
+ btdf_accum /= sampleCount;
+
+ FragColor = vec4(btdf_accum, 0.0, 0.0, 1.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl
new file mode 100644
index 00000000000..d6abb7dc175
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/common_uniforms_lib.glsl
@@ -0,0 +1,55 @@
+
+layout(std140) uniform common_block {
+ mat4 pastViewProjectionMatrix;
+ vec4 viewVecs[2];
+ vec2 mipRatio[10]; /* To correct mip level texel mis-alignement */
+ /* Ambient Occlusion */
+ vec4 aoParameters[2];
+ /* Volumetric */
+ ivec4 volTexSize;
+ vec4 volDepthParameters; /* Parameters to the volume Z equation */
+ vec4 volInvTexSize;
+ vec4 volJitter;
+ vec4 volCoordScale; /* To convert volume uvs to screen uvs */
+ float volHistoryAlpha;
+ float volLightClamp;
+ float volShadowSteps;
+ bool volUseLights;
+ /* Screen Space Reflections */
+ vec4 ssrParameters;
+ float ssrBorderFac;
+ float ssrMaxRoughness;
+ float ssrFireflyFac;
+ float ssrBrdfBias;
+ bool ssrToggle;
+ /* SubSurface Scattering */
+ float sssJitterThreshold;
+ bool sssToggle;
+ /* Specular */
+ bool specToggle;
+ /* Lamps */
+ int laNumLight;
+ /* Probes */
+ int prbNumPlanar;
+ int prbNumRenderCube;
+ int prbNumRenderGrid;
+ int prbIrradianceVisSize;
+ float prbLodCubeMax;
+ float prbLodPlanarMax;
+};
+
+/* aoParameters */
+#define aoDistance aoParameters[0].x
+#define aoSamples aoParameters[0].y /* UNUSED */
+#define aoFactor aoParameters[0].z
+#define aoInvSamples aoParameters[0].w /* UNUSED */
+
+#define aoOffset aoParameters[1].x /* UNUSED */
+#define aoBounceFac aoParameters[1].y
+#define aoQuality aoParameters[1].z
+#define aoSettings aoParameters[1].w
+
+/* ssrParameters */
+#define ssrQuality ssrParameters.x
+#define ssrThickness ssrParameters.y
+#define ssrPixelSize ssrParameters.zw
diff --git a/source/blender/draw/engines/eevee/shaders/concentric_samples_lib.glsl b/source/blender/draw/engines/eevee/shaders/concentric_samples_lib.glsl
new file mode 100644
index 00000000000..7de27a9fda9
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/concentric_samples_lib.glsl
@@ -0,0 +1,267 @@
+/* Precomputed table of concentric samples.
+ * Generated using this algorithm http://l2program.co.uk/900/concentric-disk-sampling
+ * Sorted by radius then by rotation angle.
+ * This way it's better for cache usage and for
+ * easily restricting to a certain number of
+ * sample while still having a circular kernel. */
+
+#define CONCENTRIC_SAMPLE_NUM 256
+const vec2 concentric[CONCENTRIC_SAMPLE_NUM] =
+vec2[CONCENTRIC_SAMPLE_NUM](
+ vec2(0.0441941738242, 0.0441941738242),
+ vec2(-0.0441941738242, -0.0441941738242),
+ vec2(-0.0441941738242, 0.0441941738242),
+ vec2(0.0441941738242, -0.0441941738242),
+ vec2(0.181111092429, 0.0485285709567),
+ vec2(0.132582521472, 0.132582521472),
+ vec2(-0.181111092429, 0.0485285709567),
+ vec2(0.0485285709567, 0.181111092429),
+ vec2(-0.181111092429, -0.0485285709567),
+ vec2(-0.0485285709567, 0.181111092429),
+ vec2(-0.132582521472, -0.132582521472),
+ vec2(-0.132582521472, 0.132582521472),
+ vec2(-0.0485285709567, -0.181111092429),
+ vec2(0.0485285709567, -0.181111092429),
+ vec2(0.132582521472, -0.132582521472),
+ vec2(0.181111092429, -0.0485285709567),
+ vec2(0.308652606436, 0.0488857703251),
+ vec2(0.278439538809, 0.141872031169),
+ vec2(0.220970869121, 0.220970869121),
+ vec2(-0.278439538809, 0.141872031169),
+ vec2(0.141872031169, 0.278439538809),
+ vec2(-0.308652606436, 0.0488857703251),
+ vec2(0.0488857703251, 0.308652606436),
+ vec2(-0.308652606436, -0.0488857703251),
+ vec2(-0.0488857703251, 0.308652606436),
+ vec2(-0.278439538809, -0.141872031169),
+ vec2(-0.141872031169, 0.278439538809),
+ vec2(-0.220970869121, -0.220970869121),
+ vec2(-0.220970869121, 0.220970869121),
+ vec2(-0.141872031169, -0.278439538809),
+ vec2(-0.0488857703251, -0.308652606436),
+ vec2(0.0488857703251, -0.308652606436),
+ vec2(0.141872031169, -0.278439538809),
+ vec2(0.220970869121, -0.220970869121),
+ vec2(0.278439538809, -0.141872031169),
+ vec2(0.308652606436, -0.0488857703251),
+ vec2(0.434749091828, 0.0489844582952),
+ vec2(0.41294895701, 0.144497089605),
+ vec2(0.370441837162, 0.232764033475),
+ vec2(0.309359216769, 0.309359216769),
+ vec2(-0.370441837162, 0.232764033475),
+ vec2(0.232764033475, 0.370441837162),
+ vec2(-0.41294895701, 0.144497089605),
+ vec2(0.144497089605, 0.41294895701),
+ vec2(-0.434749091828, 0.0489844582952),
+ vec2(0.0489844582952, 0.434749091828),
+ vec2(-0.434749091828, -0.0489844582952),
+ vec2(-0.0489844582952, 0.434749091828),
+ vec2(-0.41294895701, -0.144497089605),
+ vec2(-0.144497089605, 0.41294895701),
+ vec2(-0.370441837162, -0.232764033475),
+ vec2(-0.232764033475, 0.370441837162),
+ vec2(-0.309359216769, -0.309359216769),
+ vec2(-0.309359216769, 0.309359216769),
+ vec2(-0.232764033475, -0.370441837162),
+ vec2(-0.144497089605, -0.41294895701),
+ vec2(-0.0489844582952, -0.434749091828),
+ vec2(0.0489844582952, -0.434749091828),
+ vec2(0.144497089605, -0.41294895701),
+ vec2(0.232764033475, -0.370441837162),
+ vec2(0.309359216769, -0.309359216769),
+ vec2(0.370441837162, -0.232764033475),
+ vec2(0.41294895701, -0.144497089605),
+ vec2(0.434749091828, -0.0489844582952),
+ vec2(0.560359517677, 0.0490251052956),
+ vec2(0.543333277288, 0.14558571287),
+ vec2(0.509798130208, 0.237722772229),
+ vec2(0.460773024913, 0.322636745447),
+ vec2(0.397747564417, 0.397747564417),
+ vec2(-0.460773024913, 0.322636745447),
+ vec2(0.322636745447, 0.460773024913),
+ vec2(-0.509798130208, 0.237722772229),
+ vec2(0.237722772229, 0.509798130208),
+ vec2(-0.543333277288, 0.14558571287),
+ vec2(0.14558571287, 0.543333277288),
+ vec2(-0.560359517677, 0.0490251052956),
+ vec2(0.0490251052956, 0.560359517677),
+ vec2(-0.560359517677, -0.0490251052956),
+ vec2(-0.0490251052956, 0.560359517677),
+ vec2(-0.543333277288, -0.14558571287),
+ vec2(-0.14558571287, 0.543333277288),
+ vec2(-0.509798130208, -0.237722772229),
+ vec2(-0.237722772229, 0.509798130208),
+ vec2(-0.460773024913, -0.322636745447),
+ vec2(-0.322636745447, 0.460773024913),
+ vec2(-0.397747564417, -0.397747564417),
+ vec2(-0.397747564417, 0.397747564417),
+ vec2(-0.322636745447, -0.460773024913),
+ vec2(-0.237722772229, -0.509798130208),
+ vec2(-0.14558571287, -0.543333277288),
+ vec2(-0.0490251052956, -0.560359517677),
+ vec2(0.0490251052956, -0.560359517677),
+ vec2(0.14558571287, -0.543333277288),
+ vec2(0.237722772229, -0.509798130208),
+ vec2(0.322636745447, -0.460773024913),
+ vec2(0.397747564417, -0.397747564417),
+ vec2(0.460773024913, -0.322636745447),
+ vec2(0.509798130208, -0.237722772229),
+ vec2(0.543333277288, -0.14558571287),
+ vec2(0.560359517677, -0.0490251052956),
+ vec2(0.685748328795, 0.0490456884495),
+ vec2(0.671788470355, 0.146138636568),
+ vec2(0.644152935937, 0.240256623474),
+ vec2(0.603404305327, 0.32948367837),
+ vec2(0.550372103135, 0.412003395727),
+ vec2(0.486135912066, 0.486135912066),
+ vec2(-0.550372103135, 0.412003395727),
+ vec2(0.412003395727, 0.550372103135),
+ vec2(-0.603404305327, 0.32948367837),
+ vec2(0.32948367837, 0.603404305327),
+ vec2(-0.644152935937, 0.240256623474),
+ vec2(0.240256623474, 0.644152935937),
+ vec2(-0.671788470355, 0.146138636568),
+ vec2(0.146138636568, 0.671788470355),
+ vec2(-0.685748328795, 0.0490456884495),
+ vec2(0.0490456884495, 0.685748328795),
+ vec2(-0.685748328795, -0.0490456884495),
+ vec2(-0.0490456884495, 0.685748328795),
+ vec2(-0.671788470355, -0.146138636568),
+ vec2(-0.146138636568, 0.671788470355),
+ vec2(-0.644152935937, -0.240256623474),
+ vec2(-0.240256623474, 0.644152935937),
+ vec2(-0.603404305327, -0.32948367837),
+ vec2(-0.32948367837, 0.603404305327),
+ vec2(-0.550372103135, -0.412003395727),
+ vec2(-0.412003395727, 0.550372103135),
+ vec2(-0.486135912066, -0.486135912066),
+ vec2(-0.486135912066, 0.486135912066),
+ vec2(-0.412003395727, -0.550372103135),
+ vec2(-0.32948367837, -0.603404305327),
+ vec2(-0.240256623474, -0.644152935937),
+ vec2(-0.146138636568, -0.671788470355),
+ vec2(-0.0490456884495, -0.685748328795),
+ vec2(0.0490456884495, -0.685748328795),
+ vec2(0.146138636568, -0.671788470355),
+ vec2(0.240256623474, -0.644152935937),
+ vec2(0.32948367837, -0.603404305327),
+ vec2(0.412003395727, -0.550372103135),
+ vec2(0.486135912066, -0.486135912066),
+ vec2(0.550372103135, -0.412003395727),
+ vec2(0.603404305327, -0.32948367837),
+ vec2(0.644152935937, -0.240256623474),
+ vec2(0.671788470355, -0.146138636568),
+ vec2(0.685748328795, -0.0490456884495),
+ vec2(0.811017637806, 0.0490575291556),
+ vec2(0.799191174395, 0.146457218224),
+ vec2(0.775710704038, 0.241721231257),
+ vec2(0.740918624869, 0.33346040443),
+ vec2(0.695322283745, 0.420336974019),
+ vec2(0.639586577995, 0.501084084011),
+ vec2(0.574524259714, 0.574524259714),
+ vec2(-0.639586577995, 0.501084084011),
+ vec2(0.501084084011, 0.639586577995),
+ vec2(-0.695322283745, 0.420336974019),
+ vec2(0.420336974019, 0.695322283745),
+ vec2(-0.740918624869, 0.33346040443),
+ vec2(0.33346040443, 0.740918624869),
+ vec2(-0.775710704038, 0.241721231257),
+ vec2(0.241721231257, 0.775710704038),
+ vec2(-0.799191174395, 0.146457218224),
+ vec2(0.146457218224, 0.799191174395),
+ vec2(-0.811017637806, 0.0490575291556),
+ vec2(0.0490575291556, 0.811017637806),
+ vec2(-0.811017637806, -0.0490575291556),
+ vec2(-0.0490575291556, 0.811017637806),
+ vec2(-0.799191174395, -0.146457218224),
+ vec2(-0.146457218224, 0.799191174395),
+ vec2(-0.775710704038, -0.241721231257),
+ vec2(-0.241721231257, 0.775710704038),
+ vec2(-0.740918624869, -0.33346040443),
+ vec2(-0.33346040443, 0.740918624869),
+ vec2(-0.695322283745, -0.420336974019),
+ vec2(-0.420336974019, 0.695322283745),
+ vec2(-0.639586577995, -0.501084084011),
+ vec2(-0.501084084011, 0.639586577995),
+ vec2(-0.574524259714, -0.574524259714),
+ vec2(-0.574524259714, 0.574524259714),
+ vec2(-0.501084084011, -0.639586577995),
+ vec2(-0.420336974019, -0.695322283745),
+ vec2(-0.33346040443, -0.740918624869),
+ vec2(-0.241721231257, -0.775710704038),
+ vec2(-0.146457218224, -0.799191174395),
+ vec2(-0.0490575291556, -0.811017637806),
+ vec2(0.0490575291556, -0.811017637806),
+ vec2(0.146457218224, -0.799191174395),
+ vec2(0.241721231257, -0.775710704038),
+ vec2(0.33346040443, -0.740918624869),
+ vec2(0.420336974019, -0.695322283745),
+ vec2(0.501084084011, -0.639586577995),
+ vec2(0.574524259714, -0.574524259714),
+ vec2(0.639586577995, -0.501084084011),
+ vec2(0.695322283745, -0.420336974019),
+ vec2(0.740918624869, -0.33346040443),
+ vec2(0.775710704038, -0.241721231257),
+ vec2(0.799191174395, -0.146457218224),
+ vec2(0.811017637806, -0.0490575291556),
+ vec2(0.936215188832, 0.0490649589778),
+ vec2(0.925957819308, 0.146657310975),
+ vec2(0.905555462146, 0.242642854784),
+ vec2(0.875231649841, 0.335969952699),
+ vec2(0.835318616427, 0.425616093506),
+ vec2(0.786253657449, 0.510599095327),
+ vec2(0.728574338866, 0.589987866609),
+ vec2(0.662912607362, 0.662912607362),
+ vec2(-0.728574338866, 0.589987866609),
+ vec2(0.589987866609, 0.728574338866),
+ vec2(-0.786253657449, 0.510599095327),
+ vec2(0.510599095327, 0.786253657449),
+ vec2(-0.835318616427, 0.425616093506),
+ vec2(0.425616093506, 0.835318616427),
+ vec2(-0.875231649841, 0.335969952699),
+ vec2(0.335969952699, 0.875231649841),
+ vec2(-0.905555462146, 0.242642854784),
+ vec2(0.242642854784, 0.905555462146),
+ vec2(-0.925957819308, 0.146657310975),
+ vec2(0.146657310975, 0.925957819308),
+ vec2(-0.936215188832, 0.0490649589778),
+ vec2(0.0490649589778, 0.936215188832),
+ vec2(-0.936215188832, -0.0490649589778),
+ vec2(-0.0490649589778, 0.936215188832),
+ vec2(-0.925957819308, -0.146657310975),
+ vec2(-0.146657310975, 0.925957819308),
+ vec2(-0.905555462146, -0.242642854784),
+ vec2(-0.242642854784, 0.905555462146),
+ vec2(-0.875231649841, -0.335969952699),
+ vec2(-0.335969952699, 0.875231649841),
+ vec2(-0.835318616427, -0.425616093506),
+ vec2(-0.425616093506, 0.835318616427),
+ vec2(-0.786253657449, -0.510599095327),
+ vec2(-0.510599095327, 0.786253657449),
+ vec2(-0.728574338866, -0.589987866609),
+ vec2(-0.589987866609, 0.728574338866),
+ vec2(-0.662912607362, -0.662912607362),
+ vec2(-0.662912607362, 0.662912607362),
+ vec2(-0.589987866609, -0.728574338866),
+ vec2(-0.510599095327, -0.786253657449),
+ vec2(-0.425616093506, -0.835318616427),
+ vec2(-0.335969952699, -0.875231649841),
+ vec2(-0.242642854784, -0.905555462146),
+ vec2(-0.146657310975, -0.925957819308),
+ vec2(-0.0490649589778, -0.936215188832),
+ vec2(0.0490649589778, -0.936215188832),
+ vec2(0.146657310975, -0.925957819308),
+ vec2(0.242642854784, -0.905555462146),
+ vec2(0.335969952699, -0.875231649841),
+ vec2(0.425616093506, -0.835318616427),
+ vec2(0.510599095327, -0.786253657449),
+ vec2(0.589987866609, -0.728574338866),
+ vec2(0.662912607362, -0.662912607362),
+ vec2(0.728574338866, -0.589987866609),
+ vec2(0.786253657449, -0.510599095327),
+ vec2(0.835318616427, -0.425616093506),
+ vec2(0.875231649841, -0.335969952699),
+ vec2(0.905555462146, -0.242642854784),
+ vec2(0.925957819308, -0.146657310975),
+ vec2(0.936215188832, -0.0490649589778)
+);
diff --git a/source/blender/draw/engines/eevee/shaders/default_frag.glsl b/source/blender/draw/engines/eevee/shaders/default_frag.glsl
new file mode 100644
index 00000000000..6d941ae6ec3
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/default_frag.glsl
@@ -0,0 +1,19 @@
+
+uniform vec3 basecol;
+uniform float metallic;
+uniform float specular;
+uniform float roughness;
+
+Closure nodetree_exec(void)
+{
+ vec3 dielectric = vec3(0.034) * specular * 2.0;
+ vec3 albedo = mix(basecol, vec3(0.0), metallic);
+ vec3 f0 = mix(dielectric, basecol, metallic);
+ vec3 N = (gl_FrontFacing) ? worldNormal : -worldNormal;
+ vec3 out_diff, out_spec, ssr_spec;
+ eevee_closure_default(N, albedo, f0, 1, roughness, 1.0, out_diff, out_spec, ssr_spec);
+
+ Closure result = Closure(out_spec + out_diff * albedo, 1.0, vec4(ssr_spec, roughness), normal_encode(normalize(viewNormal), viewCameraVec), 0);
+
+ return result;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl b/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl
new file mode 100644
index 00000000000..90af87756f0
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/default_world_frag.glsl
@@ -0,0 +1,9 @@
+
+uniform float backgroundAlpha;
+uniform vec3 color;
+
+out vec4 FragColor;
+
+void main() {
+ FragColor = vec4(color, backgroundAlpha);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
new file mode 100644
index 00000000000..c3674c8f74c
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_bloom_frag.glsl
@@ -0,0 +1,218 @@
+/* Original implementation by Keijiro Takahashi
+ * Blender integration by Clément Foucault
+ *
+ * Original License :
+ *
+ * Kino/Bloom v2 - Bloom filter for Unity
+ *
+ * Copyright (C) 2015, 2016 Keijiro Takahashi
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ **/
+
+uniform sampler2D sourceBuffer; /* Buffer to filter */
+uniform vec2 sourceBufferTexelSize;
+
+/* Step Blit */
+uniform vec4 curveThreshold;
+uniform float clampIntensity;
+
+/* Step Upsample */
+uniform sampler2D baseBuffer; /* Previous accumulation buffer */
+uniform vec2 baseBufferTexelSize;
+uniform float sampleScale;
+
+/* Step Resolve */
+uniform vec3 bloomColor;
+
+in vec4 uvcoordsvar;
+
+out vec4 FragColor;
+
+/* -------------- Utils ------------- */
+
+vec3 safe_color(vec3 c)
+{
+ /* Clamp to avoid black square artifacts if a pixel goes NaN. */
+ return clamp(c, vec3(0.0), vec3(1e20)); /* 1e20 arbitrary. */
+}
+
+float brightness(vec3 c)
+{
+ return max(max(c.r, c.g), c.b);
+}
+
+/* 3-tap median filter */
+vec3 median(vec3 a, vec3 b, vec3 c)
+{
+ return a + b + c - min(min(a, b), c) - max(max(a, b), c);
+}
+
+/* ------------- Filters ------------ */
+
+vec3 downsample_filter_high(sampler2D tex, vec2 uv, vec2 texelSize)
+{
+ /* Downsample with a 4x4 box filter + anti-flicker filter */
+ vec4 d = texelSize.xyxy * vec4(-1, -1, +1, +1);
+
+ vec3 s1 = textureLod(tex, uv + d.xy, 0.0).rgb;
+ vec3 s2 = textureLod(tex, uv + d.zy, 0.0).rgb;
+ vec3 s3 = textureLod(tex, uv + d.xw, 0.0).rgb;
+ vec3 s4 = textureLod(tex, uv + d.zw, 0.0).rgb;
+
+ /* Karis's luma weighted average (using brightness instead of luma) */
+ float s1w = 1.0 / (brightness(s1) + 1.0);
+ float s2w = 1.0 / (brightness(s2) + 1.0);
+ float s3w = 1.0 / (brightness(s3) + 1.0);
+ float s4w = 1.0 / (brightness(s4) + 1.0);
+ float one_div_wsum = 1.0 / (s1w + s2w + s3w + s4w);
+
+ return (s1 * s1w + s2 * s2w + s3 * s3w + s4 * s4w) * one_div_wsum;
+}
+
+vec3 downsample_filter(sampler2D tex, vec2 uv, vec2 texelSize)
+{
+ /* Downsample with a 4x4 box filter */
+ vec4 d = texelSize.xyxy * vec4(-1, -1, +1, +1);
+
+ vec3 s;
+ s = textureLod(tex, uv + d.xy, 0.0).rgb;
+ s += textureLod(tex, uv + d.zy, 0.0).rgb;
+ s += textureLod(tex, uv + d.xw, 0.0).rgb;
+ s += textureLod(tex, uv + d.zw, 0.0).rgb;
+
+ return s * (1.0 / 4);
+}
+
+vec3 upsample_filter_high(sampler2D tex, vec2 uv, vec2 texelSize)
+{
+ /* 9-tap bilinear upsampler (tent filter) */
+ vec4 d = texelSize.xyxy * vec4(1, 1, -1, 0) * sampleScale;
+
+ vec3 s;
+ s = textureLod(tex, uv - d.xy, 0.0).rgb;
+ s += textureLod(tex, uv - d.wy, 0.0).rgb * 2;
+ s += textureLod(tex, uv - d.zy, 0.0).rgb;
+
+ s += textureLod(tex, uv + d.zw, 0.0).rgb * 2;
+ s += textureLod(tex, uv , 0.0).rgb * 4;
+ s += textureLod(tex, uv + d.xw, 0.0).rgb * 2;
+
+ s += textureLod(tex, uv + d.zy, 0.0).rgb;
+ s += textureLod(tex, uv + d.wy, 0.0).rgb * 2;
+ s += textureLod(tex, uv + d.xy, 0.0).rgb;
+
+ return s * (1.0 / 16.0);
+}
+
+vec3 upsample_filter(sampler2D tex, vec2 uv, vec2 texelSize)
+{
+ /* 4-tap bilinear upsampler */
+ vec4 d = texelSize.xyxy * vec4(-1, -1, +1, +1) * (sampleScale * 0.5);
+
+ vec3 s;
+ s = textureLod(tex, uv + d.xy, 0.0).rgb;
+ s += textureLod(tex, uv + d.zy, 0.0).rgb;
+ s += textureLod(tex, uv + d.xw, 0.0).rgb;
+ s += textureLod(tex, uv + d.zw, 0.0).rgb;
+
+ return s * (1.0 / 4.0);
+}
+
+/* ----------- Steps ----------- */
+
+vec4 step_blit(void)
+{
+ vec2 uv = uvcoordsvar.xy + sourceBufferTexelSize.xy * 0.5;
+
+#ifdef HIGH_QUALITY /* Anti flicker */
+ vec3 d = sourceBufferTexelSize.xyx * vec3(1, 1, 0);
+ vec3 s0 = safe_color(textureLod(sourceBuffer, uvcoordsvar.xy, 0.0).rgb);
+ vec3 s1 = safe_color(textureLod(sourceBuffer, uvcoordsvar.xy - d.xz, 0.0).rgb);
+ vec3 s2 = safe_color(textureLod(sourceBuffer, uvcoordsvar.xy + d.xz, 0.0).rgb);
+ vec3 s3 = safe_color(textureLod(sourceBuffer, uvcoordsvar.xy - d.zy, 0.0).rgb);
+ vec3 s4 = safe_color(textureLod(sourceBuffer, uvcoordsvar.xy + d.zy, 0.0).rgb);
+ vec3 m = median(median(s0.rgb, s1, s2), s3, s4);
+#else
+ vec3 s0 = safe_color(textureLod(sourceBuffer, uvcoordsvar.xy, 0.0).rgb);
+ vec3 m = s0.rgb;
+#endif
+
+ /* Pixel brightness */
+ float br = brightness(m);
+
+ /* Under-threshold part: quadratic curve */
+ float rq = clamp(br - curveThreshold.x, 0, curveThreshold.y);
+ rq = curveThreshold.z * rq * rq;
+
+ /* Combine and apply the brightness response curve. */
+ m *= max(rq, br - curveThreshold.w) / max(1e-5, br);
+
+ /* Clamp pixel intensity */
+ br = max(1e-5, brightness(m));
+ m *= 1.0 - max(0.0, br - clampIntensity) / br;
+
+ return vec4(m, 1.0);
+}
+
+vec4 step_downsample(void)
+{
+#ifdef HIGH_QUALITY /* Anti flicker */
+ vec3 sample = downsample_filter_high(sourceBuffer, uvcoordsvar.xy, sourceBufferTexelSize);
+#else
+ vec3 sample = downsample_filter(sourceBuffer, uvcoordsvar.xy, sourceBufferTexelSize);
+#endif
+ return vec4(sample, 1.0);
+}
+
+vec4 step_upsample(void)
+{
+#ifdef HIGH_QUALITY
+ vec3 blur = upsample_filter_high(sourceBuffer, uvcoordsvar.xy, sourceBufferTexelSize);
+#else
+ vec3 blur = upsample_filter(sourceBuffer, uvcoordsvar.xy, sourceBufferTexelSize);
+#endif
+ vec3 base = textureLod(baseBuffer, uvcoordsvar.xy, 0.0).rgb;
+ return vec4(base + blur, 1.0);
+}
+
+vec4 step_resolve(void)
+{
+#ifdef HIGH_QUALITY
+ vec3 blur = upsample_filter_high(sourceBuffer, uvcoordsvar.xy, sourceBufferTexelSize);
+#else
+ vec3 blur = upsample_filter(sourceBuffer, uvcoordsvar.xy, sourceBufferTexelSize);
+#endif
+ vec4 base = textureLod(baseBuffer, uvcoordsvar.xy, 0.0);
+ vec3 cout = base.rgb + blur * bloomColor;
+ return vec4(cout, base.a);
+}
+
+void main(void)
+{
+#if defined(STEP_BLIT)
+ FragColor = step_blit();
+#elif defined(STEP_DOWNSAMPLE)
+ FragColor = step_downsample();
+#elif defined(STEP_UPSAMPLE)
+ FragColor = step_upsample();
+#elif defined(STEP_RESOLVE)
+ FragColor = step_resolve();
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl
new file mode 100644
index 00000000000..04648f62688
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_dof_frag.glsl
@@ -0,0 +1,261 @@
+
+uniform mat4 ProjectionMatrix;
+
+uniform sampler2D colorBuffer;
+uniform sampler2D depthBuffer;
+
+uniform vec3 dofParams;
+
+#define dof_aperturesize dofParams.x
+#define dof_distance dofParams.y
+#define dof_invsensorsize dofParams.z
+
+uniform vec4 bokehParams;
+
+#define bokeh_sides bokehParams.x /* Polygon Bokeh shape number of sides */
+#define bokeh_rotation bokehParams.y
+#define bokeh_ratio bokehParams.z
+#define bokeh_maxsize bokehParams.w
+
+uniform vec2 nearFar; /* Near & far view depths values */
+
+/* initial uv coordinate */
+in vec2 uvcoord;
+
+layout(location = 0) out vec4 fragData0;
+layout(location = 1) out vec4 fragData1;
+layout(location = 2) out vec4 fragData2;
+
+#define M_PI 3.1415926535897932384626433832795
+#define M_2PI 6.2831853071795864769252868
+
+/* -------------- Utils ------------- */
+
+/* calculate 4 samples at once */
+float calculate_coc(in float zdepth)
+{
+ float coc = dof_aperturesize * (dof_distance / zdepth - 1.0);
+
+ /* multiply by 1.0 / sensor size to get the normalized size */
+ return coc * dof_invsensorsize;
+}
+
+vec4 calculate_coc(in vec4 zdepth)
+{
+ vec4 coc = dof_aperturesize * (vec4(dof_distance) / zdepth - vec4(1.0));
+
+ /* multiply by 1.0 / sensor size to get the normalized size */
+ return coc * dof_invsensorsize;
+}
+
+float max4(vec4 x)
+{
+ return max(max(x.x, x.y), max(x.z, x.w));
+}
+
+float linear_depth(float z)
+{
+ /* if persp */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ return (nearFar.x * nearFar.y) / (z * (nearFar.x - nearFar.y) + nearFar.y);
+ }
+ else {
+ return (z * 2.0 - 1.0) * nearFar.y;
+ }
+}
+
+vec4 linear_depth(vec4 z)
+{
+ /* if persp */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ return (nearFar.xxxx * nearFar.yyyy) / (z * (nearFar.xxxx - nearFar.yyyy) + nearFar.yyyy);
+ }
+ else {
+ return (z * 2.0 - 1.0) * nearFar.yyyy;
+ }
+}
+
+#define THRESHOLD 0.0
+
+/* ----------- Steps ----------- */
+
+/* Downsample the color buffer to half resolution.
+ * Weight color samples by
+ * Compute maximum CoC for near and far blur. */
+void step_downsample(void)
+{
+ ivec4 uvs = ivec4(gl_FragCoord.xyxy) * 2 + ivec4(0, 0, 1, 1);
+
+ /* custom downsampling */
+ vec4 color1 = texelFetch(colorBuffer, uvs.xy, 0);
+ vec4 color2 = texelFetch(colorBuffer, uvs.zw, 0);
+ vec4 color3 = texelFetch(colorBuffer, uvs.zy, 0);
+ vec4 color4 = texelFetch(colorBuffer, uvs.xw, 0);
+
+ /* Leverage SIMD by combining 4 depth samples into a vec4 */
+ vec4 depth;
+ depth.r = texelFetch(depthBuffer, uvs.xy, 0).r;
+ depth.g = texelFetch(depthBuffer, uvs.zw, 0).r;
+ depth.b = texelFetch(depthBuffer, uvs.zy, 0).r;
+ depth.a = texelFetch(depthBuffer, uvs.xw, 0).r;
+
+ vec4 zdepth = linear_depth(depth);
+
+ /* Compute signed CoC for each depth samples */
+ vec4 coc_near = calculate_coc(zdepth);
+ vec4 coc_far = -coc_near;
+
+ /* now we need to write the near-far fields premultiplied by the coc */
+ vec4 near_weights = step(THRESHOLD, coc_near);
+ vec4 far_weights = step(THRESHOLD, coc_far);
+
+ /* now write output to weighted buffers. */
+ fragData0 = color1 * near_weights.x +
+ color2 * near_weights.y +
+ color3 * near_weights.z +
+ color4 * near_weights.w;
+
+ fragData1 = color1 * far_weights.x +
+ color2 * far_weights.y +
+ color3 * far_weights.z +
+ color4 * far_weights.w;
+
+ float norm_near = dot(near_weights, near_weights);
+ float norm_far = dot(far_weights, far_weights);
+
+ if (norm_near > 0.0) {
+ fragData0 /= norm_near;
+ }
+
+ if (norm_far > 0.0) {
+ fragData1 /= norm_far;
+ }
+
+ float max_near_coc = max(max4(coc_near), 0.0);
+ float max_far_coc = max(max4(coc_far), 0.0);
+
+ fragData2 = vec4(max_near_coc, max_far_coc, 0.0, 1.0);
+}
+
+/* coordinate used for calculating radius et al set in geometry shader */
+in vec2 particlecoord;
+flat in vec4 color;
+
+/* accumulate color in the near/far blur buffers */
+void step_scatter(void)
+{
+ /* Early out */
+ float dist_sqrd = dot(particlecoord, particlecoord);
+
+ /* Circle Dof */
+ if (dist_sqrd > 1.0) {
+ discard;
+ }
+
+ /* Regular Polygon Dof */
+ if (bokeh_sides > 0.0) {
+ /* Circle parametrization */
+ float theta = atan(particlecoord.y, particlecoord.x) + bokeh_rotation;
+ float r;
+
+ r = cos(M_PI / bokeh_sides) /
+ (cos(theta - (M_2PI / bokeh_sides) * floor((bokeh_sides * theta + M_PI) / M_2PI)));
+
+ if (dist_sqrd > r * r) {
+ discard;
+ }
+ }
+
+ fragData0 = color;
+}
+
+#define MERGE_THRESHOLD 4.0
+
+uniform sampler2D farBuffer;
+uniform sampler2D nearBuffer;
+
+vec4 upsample_filter_high(sampler2D tex, vec2 uv, vec2 texelSize)
+{
+ /* 9-tap bilinear upsampler (tent filter) */
+ vec4 d = texelSize.xyxy * vec4(1, 1, -1, 0);
+
+ vec4 s;
+ s = textureLod(tex, uv - d.xy, 0.0);
+ s += textureLod(tex, uv - d.wy, 0.0) * 2;
+ s += textureLod(tex, uv - d.zy, 0.0);
+
+ s += textureLod(tex, uv + d.zw, 0.0) * 2;
+ s += textureLod(tex, uv , 0.0) * 4;
+ s += textureLod(tex, uv + d.xw, 0.0) * 2;
+
+ s += textureLod(tex, uv + d.zy, 0.0);
+ s += textureLod(tex, uv + d.wy, 0.0) * 2;
+ s += textureLod(tex, uv + d.xy, 0.0);
+
+ return s * (1.0 / 16.0);
+}
+
+vec4 upsample_filter(sampler2D tex, vec2 uv, vec2 texelSize)
+{
+ /* 4-tap bilinear upsampler */
+ vec4 d = texelSize.xyxy * vec4(-1, -1, +1, +1) * 0.5;
+
+ vec4 s;
+ s = textureLod(tex, uv + d.xy, 0.0);
+ s += textureLod(tex, uv + d.zy, 0.0);
+ s += textureLod(tex, uv + d.xw, 0.0);
+ s += textureLod(tex, uv + d.zw, 0.0);
+
+ return s * (1.0 / 4.0);
+}
+
+/* Combine the Far and Near color buffers */
+void step_resolve(void)
+{
+ /* Recompute Near / Far CoC */
+ float depth = textureLod(depthBuffer, uvcoord, 0.0).r;
+ float zdepth = linear_depth(depth);
+ float coc_signed = calculate_coc(zdepth);
+ float coc_far = max(-coc_signed, 0.0);
+ float coc_near = max(coc_signed, 0.0);
+
+ /* Recompute Near / Far CoC */
+ vec2 texelSize = 1.0 / vec2(textureSize(farBuffer, 0));
+ vec4 srccolor = textureLod(colorBuffer, uvcoord, 0.0);
+ vec4 farcolor = upsample_filter_high(farBuffer, uvcoord, texelSize);
+ vec4 nearcolor = upsample_filter_high(nearBuffer, uvcoord, texelSize);
+
+ float farweight = farcolor.a;
+ if (farweight > 0.0)
+ farcolor /= farweight;
+
+ float mixfac = smoothstep(1.0, MERGE_THRESHOLD, coc_far);
+
+ farweight = mix(1.0, farweight, mixfac);
+
+ float nearweight = nearcolor.a;
+ if (nearweight > 0.0) {
+ nearcolor /= nearweight;
+ }
+
+ if (coc_near > 1.0) {
+ mixfac = smoothstep(1.0, MERGE_THRESHOLD, coc_near);
+ fragData0 = mix(srccolor, nearcolor, mixfac);
+ }
+ else {
+ float totalweight = nearweight + farweight;
+ vec4 finalcolor = mix(srccolor, farcolor, mixfac);
+ fragData0 = mix(finalcolor, nearcolor, nearweight / totalweight);
+ }
+}
+
+void main()
+{
+#ifdef STEP_DOWNSAMPLE
+ step_downsample();
+#elif defined(STEP_SCATTER)
+ step_scatter();
+#elif defined(STEP_RESOLVE)
+ step_resolve();
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_geom.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_geom.glsl
new file mode 100644
index 00000000000..1c774885a32
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_dof_geom.glsl
@@ -0,0 +1,55 @@
+uniform ivec2 targetBufferSize;
+
+uniform vec2 layerSelection;
+
+uniform sampler2D colorBuffer;
+uniform sampler2D cocBuffer;
+
+layout(points) in;
+layout(triangle_strip, max_vertices = 4) out;
+
+#define POS gl_in[0].gl_Position
+
+in vec2 uvcoord[];
+out vec2 particlecoord;
+flat out vec4 color;
+
+#define M_PI 3.1415926535897932384626433832795
+
+void main()
+{
+ vec4 coc = textureLod(cocBuffer, uvcoord[0], 0.0);
+
+ float offset_val = dot(coc.rg, layerSelection);
+ if (offset_val < 1.0)
+ return;
+
+ vec4 colortex = textureLod(colorBuffer, uvcoord[0], 0.0);
+
+ /* find the area the pixel will cover and divide the color by it */
+ float alpha = 1.0 / (offset_val * offset_val * M_PI);
+ colortex *= alpha;
+ colortex.a = alpha;
+
+ vec2 offset_far = vec2(offset_val * 0.5) / vec2(targetBufferSize.x, targetBufferSize.y);
+
+ color = colortex;
+
+ gl_Position = POS + vec4(-offset_far.x, -offset_far.y, 0.0, 0.0);
+ particlecoord = vec2(-1.0, -1.0);
+ EmitVertex();
+
+ gl_Position = POS + vec4(-offset_far.x, offset_far.y, 0.0, 0.0);
+ particlecoord = vec2(-1.0, 1.0);
+ EmitVertex();
+
+ gl_Position = POS + vec4(offset_far.x, -offset_far.y, 0.0, 0.0);
+ particlecoord = vec2(1.0, -1.0);
+ EmitVertex();
+
+ gl_Position = POS + vec4(offset_far.x, offset_far.y, 0.0, 0.0);
+ particlecoord = vec2(1.0, 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl b/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl
new file mode 100644
index 00000000000..05f5eb78253
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_dof_vert.glsl
@@ -0,0 +1,99 @@
+
+in vec2 pos;
+in vec2 uvs;
+
+uniform vec2 layerSelection;
+
+uniform vec4 bokehParams;
+
+#define bokeh_sides bokehParams.x /* Polygon Bokeh shape number of sides */
+#define bokeh_rotation bokehParams.y
+#define bokeh_ratio bokehParams.z
+#define bokeh_maxsize bokehParams.w
+
+uniform sampler2D colorBuffer;
+uniform sampler2D cocBuffer;
+
+flat out vec4 color;
+out vec2 particlecoord;
+
+#define M_PI 3.1415926535897932384626433832795
+
+/* geometry shading pass, calculate a texture coordinate based on the indexed id */
+void step_scatter()
+{
+ ivec2 tex_size = textureSize(cocBuffer, 0);
+ vec2 texel_size = 1.0 / vec2(tex_size);
+
+ int t_id = gl_VertexID / 3; /* Triangle Id */
+
+ ivec2 texelco = ivec2(0);
+ /* some math to get the target pixel */
+ texelco.x = t_id % tex_size.x;
+ texelco.y = t_id / tex_size.x;
+
+ float coc = dot(layerSelection, texelFetch(cocBuffer, texelco, 0).rg);
+
+ /* Clamp to max size for performance */
+ coc = min(coc, bokeh_maxsize);
+
+ if (coc >= 1.0) {
+ color = texelFetch(colorBuffer, texelco, 0);
+ /* find the area the pixel will cover and divide the color by it */
+ float alpha = 1.0 / (coc * coc * M_PI);
+ color *= alpha;
+ color.a = alpha;
+ }
+ else {
+ color = vec4(0.0);
+ }
+
+ /* Generate Triangle : less memory fetches from a VBO */
+ int v_id = gl_VertexID % 3; /* Vertex Id */
+
+ /* Extend to cover at least the unit circle */
+ const float extend = (cos(M_PI / 4.0) + 1.0) * 2.0;
+ /* Crappy diagram
+ * ex 1
+ * | \
+ * | \
+ * 1 | \
+ * | \
+ * | \
+ * 0 | x \
+ * | Circle \
+ * | Origin \
+ * -1 0 --------------- 2
+ * -1 0 1 ex
+ **/
+ gl_Position.x = float(v_id / 2) * extend - 1.0; /* int divisor round down */
+ gl_Position.y = float(v_id % 2) * extend - 1.0;
+ gl_Position.z = 0.0;
+ gl_Position.w = 1.0;
+
+ /* Generate Triangle */
+ particlecoord = gl_Position.xy;
+
+ gl_Position.xy *= coc * texel_size * vec2(bokeh_ratio, 1.0);
+ gl_Position.xy -= 1.0 - 0.5 * texel_size; /* NDC Bottom left */
+ gl_Position.xy += (0.5 + vec2(texelco) * 2.0) * texel_size;
+}
+
+out vec2 uvcoord;
+
+void passthrough()
+{
+ uvcoord = uvs;
+ gl_Position = vec4(pos, 0.0, 1.0);
+}
+
+void main()
+{
+#if defined(STEP_DOWNSAMPLE)
+ passthrough();
+#elif defined(STEP_SCATTER)
+ step_scatter();
+#elif defined(STEP_RESOLVE)
+ passthrough();
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_downsample_cube_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_downsample_cube_frag.glsl
new file mode 100644
index 00000000000..79f86cfae58
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_downsample_cube_frag.glsl
@@ -0,0 +1,30 @@
+/**
+ * Simple downsample shader. Takes the average of the 4 texels of lower mip.
+ **/
+
+uniform samplerCube source;
+uniform float texelSize;
+
+flat in int fFace;
+
+out vec4 FragColor;
+
+const vec3 maj_axes[6] = vec3[6](vec3(1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, -1.0, 0.0), vec3( 0.0, 0.0, 1.0), vec3( 0.0, 0.0, -1.0));
+const vec3 x_axis[6] = vec3[6](vec3(0.0, 0.0, -1.0), vec3( 0.0, 0.0, 1.0), vec3(1.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), vec3( 1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0));
+const vec3 y_axis[6] = vec3[6](vec3(0.0, -1.0, 0.0), vec3( 0.0, -1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, -1.0), vec3( 0.0, -1.0, 0.0), vec3( 0.0, -1.0, 0.0));
+
+float brightness(vec3 c)
+{
+ return max(max(c.r, c.g), c.b);
+}
+
+void main()
+{
+ vec2 uvs = gl_FragCoord.xy * texelSize;
+
+ uvs = 2.0 * uvs - 1.0;
+
+ vec3 cubevec = x_axis[fFace] * uvs.x + y_axis[fFace] * uvs.y + maj_axes[fFace];
+
+ FragColor = textureLod(source, cubevec, 0.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_downsample_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_downsample_frag.glsl
new file mode 100644
index 00000000000..8f06e161a20
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_downsample_frag.glsl
@@ -0,0 +1,37 @@
+/**
+ * Simple downsample shader. Takes the average of the 4 texels of lower mip.
+ **/
+
+uniform sampler2D source;
+uniform float fireflyFactor;
+
+out vec4 FragColor;
+
+float brightness(vec3 c)
+{
+ return max(max(c.r, c.g), c.b);
+}
+
+void main()
+{
+#if 0
+ /* Reconstructing Target uvs like this avoid missing pixels if NPO2 */
+ vec2 uvs = gl_FragCoord.xy * 2.0 / vec2(textureSize(source, 0));
+
+ FragColor = textureLod(source, uvs, 0.0);
+#else
+ vec2 texel_size = 1.0 / vec2(textureSize(source, 0));
+ vec2 uvs = gl_FragCoord.xy * 2.0 * texel_size;
+ vec4 ofs = texel_size.xyxy * vec4(0.75, 0.75, -0.75, -0.75);
+
+ FragColor = textureLod(source, uvs + ofs.xy, 0.0);
+ FragColor += textureLod(source, uvs + ofs.xw, 0.0);
+ FragColor += textureLod(source, uvs + ofs.zy, 0.0);
+ FragColor += textureLod(source, uvs + ofs.zw, 0.0);
+ FragColor *= 0.25;
+
+ /* Clamped brightness. */
+ float luma = max(1e-8, brightness(FragColor.rgb));
+ FragColor *= 1.0 - max(0.0, luma - fireflyFactor) / luma;
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl
new file mode 100644
index 00000000000..b7bcf5c8a8b
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_gtao_frag.glsl
@@ -0,0 +1,77 @@
+/**
+ * This shader only compute maximum horizon angles for each directions.
+ * The final integration is done at the resolve stage with the shading normal.
+ **/
+
+uniform float rotationOffset;
+
+out vec4 FragColor;
+
+#ifdef DEBUG_AO
+uniform sampler2D normalBuffer;
+
+void main()
+{
+ vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy;
+ vec2 uvs = saturate(gl_FragCoord.xy * texel_size);
+
+ float depth = textureLod(depthBuffer, uvs, 0.0).r;
+
+ vec3 viewPosition = get_view_space_from_depth(uvs, depth);
+ vec3 V = viewCameraVec;
+ vec3 normal = normal_decode(texture(normalBuffer, uvs).rg, V);
+
+ vec3 bent_normal;
+ float visibility;
+
+ vec4 noise = texelfetch_noise_tex(gl_FragCoord.xy);
+
+ gtao_deferred(normal, viewPosition, noise, depth, visibility, bent_normal);
+
+ /* Handle Background case. Prevent artifact due to uncleared Horizon Render Target. */
+ FragColor = vec4((depth == 1.0) ? 0.0 : visibility);
+}
+
+#else
+
+#ifdef LAYERED_DEPTH
+uniform sampler2DArray depthBufferLayered;
+uniform int layer;
+# define gtao_depthBuffer depthBufferLayered
+# define gtao_textureLod(a, b, c) textureLod(a, vec3(b, layer), c)
+
+#else
+# define gtao_depthBuffer depthBuffer
+# define gtao_textureLod(a, b, c) textureLod(a, b, c)
+
+#endif
+
+void main()
+{
+ vec2 uvs = saturate(gl_FragCoord.xy / vec2(textureSize(gtao_depthBuffer, 0).xy));
+ float depth = gtao_textureLod(gtao_depthBuffer, uvs, 0.0).r;
+
+ if (depth == 1.0) {
+ /* Do not trace for background */
+ FragColor = vec4(0.0);
+ return;
+ }
+
+ /* Avoid self shadowing. */
+ depth = saturate(depth - 3e-6); /* Tweaked for 24bit depth buffer. */
+
+ vec3 viewPosition = get_view_space_from_depth(uvs, depth);
+ vec4 noise = texelfetch_noise_tex(gl_FragCoord.xy);
+ vec2 max_dir = get_max_dir(viewPosition.z);
+ vec4 dirs;
+ dirs.xy = get_ao_dir(noise.x * 0.5);
+ dirs.zw = get_ao_dir(noise.x * 0.5 + 0.5);
+
+ /* Search in 4 directions. */
+ FragColor.xy = search_horizon_sweep(dirs.xy, viewPosition, uvs, noise.y, max_dir);
+ FragColor.zw = search_horizon_sweep(dirs.zw, viewPosition, uvs, noise.y, max_dir);
+
+ /* Resize output for integer texture. */
+ FragColor = pack_horizons(FragColor);
+}
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl
new file mode 100644
index 00000000000..24dbb5436d9
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_minmaxz_frag.glsl
@@ -0,0 +1,96 @@
+/**
+ * Shader that downsample depth buffer,
+ * saving min and max value of each texel in the above mipmaps.
+ * Adapted from http://rastergrid.com/blog/2010/10/hierarchical-z-map-based-occlusion-culling/
+ **/
+
+#extension GL_ARB_texture_gather : enable
+
+#ifdef LAYERED
+uniform sampler2DArray depthBuffer;
+uniform int depthLayer;
+#else
+uniform sampler2D depthBuffer;
+#endif
+
+#ifdef LAYERED
+# define sampleLowerMip(t) texelFetch(depthBuffer, ivec3(t, depthLayer), 0).r
+# define gatherLowerMip(t) textureGather(depthBuffer, vec3(t, depthLayer))
+#else
+# define sampleLowerMip(t) texelFetch(depthBuffer, t, 0).r
+# define gatherLowerMip(t) textureGather(depthBuffer, t)
+#endif
+
+#ifdef MIN_PASS
+#define minmax2(a, b) min(a, b)
+#define minmax3(a, b, c) min(min(a, b), c)
+#define minmax4(a, b, c, d) min(min(min(a, b), c), d)
+#else /* MAX_PASS */
+#define minmax2(a, b) max(a, b)
+#define minmax3(a, b, c) max(max(a, b), c)
+#define minmax4(a, b, c, d) max(max(max(a, b), c), d)
+#endif
+
+/* On some AMD card / driver conbination, it is needed otherwise,
+ * the shader does not write anything. */
+#if defined(GPU_INTEL) || defined(GPU_ATI)
+out vec4 fragColor;
+#endif
+
+void main()
+{
+ ivec2 texelPos = ivec2(gl_FragCoord.xy);
+ ivec2 mipsize = textureSize(depthBuffer, 0).xy;
+
+#ifndef COPY_DEPTH
+ texelPos *= 2;
+#endif
+
+#ifdef COPY_DEPTH
+ float val = sampleLowerMip(texelPos);
+#else
+ vec4 samp;
+# ifdef GL_ARB_texture_gather
+ samp = gatherLowerMip(vec2(texelPos) / vec2(mipsize));
+# else
+ samp.x = sampleLowerMip(texelPos);
+ samp.y = sampleLowerMip(texelPos + ivec2(1, 0));
+ samp.z = sampleLowerMip(texelPos + ivec2(1, 1));
+ samp.w = sampleLowerMip(texelPos + ivec2(0, 1));
+# endif
+
+ float val = minmax4(samp.x, samp.y, samp.z, samp.w);
+
+ /* if we are reducing an odd-width texture then fetch the edge texels */
+ if (((mipsize.x & 1) != 0) && (texelPos.x == mipsize.x - 3)) {
+ /* if both edges are odd, fetch the top-left corner texel */
+ if (((mipsize.y & 1) != 0) && (texelPos.y == mipsize.y - 3)) {
+ samp.x = sampleLowerMip(texelPos + ivec2(2, 2));
+ val = minmax2(val, samp.x);
+ }
+# ifdef GL_ARB_texture_gather
+ samp = gatherLowerMip((vec2(texelPos) + vec2(1.0, 0.0)) / vec2(mipsize));
+# else
+ samp.y = sampleLowerMip(texelPos + ivec2(2, 0));
+ samp.z = sampleLowerMip(texelPos + ivec2(2, 1));
+# endif
+ val = minmax3(val, samp.y, samp.z);
+ }
+ /* if we are reducing an odd-height texture then fetch the edge texels */
+ if (((mipsize.y & 1) != 0) && (texelPos.y == mipsize.y - 3)) {
+# ifdef GL_ARB_texture_gather
+ samp = gatherLowerMip((vec2(texelPos) + vec2(0.0, 1.0)) / vec2(mipsize));
+# else
+ samp.x = sampleLowerMip(texelPos + ivec2(0, 2));
+ samp.y = sampleLowerMip(texelPos + ivec2(1, 2));
+# endif
+ val = minmax3(val, samp.x, samp.y);
+ }
+#endif
+
+#if defined(GPU_INTEL) || defined(GPU_ATI)
+ /* Use color format instead of 24bit depth texture */
+ fragColor = vec4(val);
+#endif
+ gl_FragDepth = val;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_mist_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_mist_frag.glsl
new file mode 100644
index 00000000000..fe38b2e9aac
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_mist_frag.glsl
@@ -0,0 +1,31 @@
+/* Convert depth to Mist factor */
+uniform vec3 mistSettings;
+
+#define mistStart mistSettings.x
+#define mistInvDistance mistSettings.y
+#define mistFalloff mistSettings.z
+
+out vec4 fragColor;
+
+void main()
+{
+ vec2 texel_size = 1.0 / vec2(textureSize(depthBuffer, 0)).xy;
+ vec2 uvs = gl_FragCoord.xy * texel_size;
+
+ float depth = textureLod(depthBuffer, uvs, 0.0).r;
+ vec3 co = get_view_space_from_depth(uvs, depth);
+
+ float zcor = (ProjectionMatrix[3][3] == 0.0) ? length(co) : -co.z;
+
+ /* bring depth into 0..1 range */
+ float mist = saturate((zcor - mistStart) * mistInvDistance);
+
+ /* falloff */
+ mist = pow(mist, mistFalloff);
+
+ fragColor = vec4(mist);
+
+ // if (mist > 0.999) fragColor = vec4(1.0);
+ // else if (mist > 0.0001) fragColor = vec4(0.5);
+ // else fragColor = vec4(0.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl
new file mode 100644
index 00000000000..73e284570cd
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_motion_blur_frag.glsl
@@ -0,0 +1,65 @@
+
+uniform sampler2D colorBuffer;
+uniform sampler2D depthBuffer;
+
+
+/* current frame */
+uniform mat4 currInvViewProjMatrix;
+
+/* past frame frame */
+uniform mat4 pastViewProjMatrix;
+
+in vec4 uvcoordsvar;
+
+out vec4 FragColor;
+
+#define MAX_SAMPLE 64
+
+uniform int samples;
+
+float wang_hash_noise(uint s)
+{
+ uint seed = (uint(gl_FragCoord.x) * 1664525u + uint(gl_FragCoord.y)) + s;
+
+ seed = (seed ^ 61u) ^ (seed >> 16u);
+ seed *= 9u;
+ seed = seed ^ (seed >> 4u);
+ seed *= 0x27d4eb2du;
+ seed = seed ^ (seed >> 15u);
+
+ float value = float(seed);
+ value *= 1.0 / 4294967296.0;
+ return fract(value);
+}
+
+void main()
+{
+ vec3 ndc_pos;
+ ndc_pos.xy = uvcoordsvar.xy;
+ ndc_pos.z = texture(depthBuffer, uvcoordsvar.xy).x;
+
+ float inv_samples = 1.0 / float(samples);
+ float noise = 2.0 * wang_hash_noise(0u) * inv_samples;
+
+ /* Normalize Device Coordinates are [-1, +1]. */
+ ndc_pos = ndc_pos * 2.0 - 1.0;
+
+ vec4 p = currInvViewProjMatrix * vec4(ndc_pos, 1.0);
+ vec3 world_pos = p.xyz / p.w; /* Perspective divide */
+
+ /* Now find where was this pixel position
+ * inside the past camera viewport */
+ vec4 old_ndc = pastViewProjMatrix * vec4(world_pos, 1.0);
+ old_ndc.xyz /= old_ndc.w; /* Perspective divide */
+
+ vec2 motion = (ndc_pos.xy - old_ndc.xy) * 0.25; /* 0.25 fit cycles ref */
+
+ float inc = 2.0 * inv_samples;
+ float i = -1.0 + noise;
+
+ FragColor = vec4(0.0);
+ for (int j = 0; j < samples && j < MAX_SAMPLE; j++) {
+ FragColor += textureLod(colorBuffer, uvcoordsvar.xy + motion * i, 0.0) * inv_samples;
+ i += inc;
+ }
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
new file mode 100644
index 00000000000..6c21d7d6fef
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_ssr_frag.glsl
@@ -0,0 +1,517 @@
+
+/* Based on Stochastic Screen Space Reflections
+ * https://www.ea.com/frostbite/news/stochastic-screen-space-reflections */
+
+#ifndef UTIL_TEX
+#define UTIL_TEX
+uniform sampler2DArray utilTex;
+#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
+#endif /* UTIL_TEX */
+
+#define MAX_MIP 9.0
+
+uniform ivec2 halfresOffset;
+
+ivec2 encode_hit_data(vec2 hit_pos, bool has_hit, bool is_planar)
+{
+ ivec2 hit_data = ivec2(saturate(hit_pos) * 32767.0); /* 16bit signed int limit */
+ hit_data.x *= (is_planar) ? -1 : 1;
+ hit_data.y *= (has_hit) ? 1 : -1;
+ return hit_data;
+}
+
+vec2 decode_hit_data(vec2 hit_data, out bool has_hit, out bool is_planar)
+{
+ is_planar = (hit_data.x < 0);
+ has_hit = (hit_data.y > 0);
+ return vec2(abs(hit_data)) / 32767.0; /* 16bit signed int limit */
+}
+
+#ifdef STEP_RAYTRACE
+
+uniform sampler2D normalBuffer;
+uniform sampler2D specroughBuffer;
+
+layout(location = 0) out ivec2 hitData;
+layout(location = 1) out float pdfData;
+
+void do_planar_ssr(int index, vec3 V, vec3 N, vec3 T, vec3 B, vec3 planeNormal, vec3 viewPosition, float a2, vec4 rand)
+{
+ float NH;
+ vec3 H = sample_ggx(rand.xzw, a2, N, T, B, NH); /* Microfacet normal */
+ float pdf = pdf_ggx_reflect(NH, a2);
+
+ vec3 R = reflect(-V, H);
+ R = reflect(R, planeNormal);
+
+ /* If ray is bad (i.e. going below the plane) regenerate. */
+ if (dot(R, planeNormal) > 0.0) {
+ vec3 H = sample_ggx(rand.xzw * vec3(1.0, -1.0, -1.0), a2, N, T, B, NH); /* Microfacet normal */
+ pdf = pdf_ggx_reflect(NH, a2);
+
+ R = reflect(-V, H);
+ R = reflect(R, planeNormal);
+ }
+
+ pdfData = min(1024e32, pdf); /* Theoretical limit of 16bit float */
+
+ /* Since viewspace hit position can land behind the camera in this case,
+ * we save the reflected view position (visualize it as the hit position
+ * below the reflection plane). This way it's garanted that the hit will
+ * be in front of the camera. That let us tag the bad rays with a negative
+ * sign in the Z component. */
+ vec3 hit_pos = raycast(index, viewPosition, R * 1e16, 1e16, rand.y, ssrQuality, a2, false);
+
+ hitData = encode_hit_data(hit_pos.xy, (hit_pos.z > 0.0), true);
+}
+
+void do_ssr(vec3 V, vec3 N, vec3 T, vec3 B, vec3 viewPosition, float a2, vec4 rand)
+{
+ float NH;
+ vec3 H = sample_ggx(rand.xzw, a2, N, T, B, NH); /* Microfacet normal */
+ float pdf = pdf_ggx_reflect(NH, a2);
+
+ vec3 R = reflect(-V, H);
+ pdfData = min(1024e32, pdf); /* Theoretical limit of 16bit float */
+
+ vec3 hit_pos = raycast(-1, viewPosition, R * 1e16, ssrThickness, rand.y, ssrQuality, a2, true);
+
+ hitData = encode_hit_data(hit_pos.xy, (hit_pos.z > 0.0), false);
+}
+
+void main()
+{
+#ifdef FULLRES
+ ivec2 fullres_texel = ivec2(gl_FragCoord.xy);
+ ivec2 halfres_texel = fullres_texel;
+#else
+ ivec2 fullres_texel = ivec2(gl_FragCoord.xy) * 2 + halfresOffset;
+ ivec2 halfres_texel = ivec2(gl_FragCoord.xy);
+#endif
+
+ float depth = texelFetch(depthBuffer, fullres_texel, 0).r;
+
+ /* Default: not hits. */
+ hitData = encode_hit_data(vec2(0.5), false, false);
+ pdfData = 0.0;
+
+ /* Early out */
+ /* We can't do discard because we don't clear the render target. */
+ if (depth == 1.0)
+ return;
+
+ vec2 uvs = vec2(fullres_texel) / vec2(textureSize(depthBuffer, 0));
+
+ /* Using view space */
+ vec3 viewPosition = get_view_space_from_depth(uvs, depth);
+ vec3 V = viewCameraVec;
+ vec3 N = normal_decode(texelFetch(normalBuffer, fullres_texel, 0).rg, V);
+
+ /* Retrieve pixel data */
+ vec4 speccol_roughness = texelFetch(specroughBuffer, fullres_texel, 0).rgba;
+
+ /* Early out */
+ if (dot(speccol_roughness.rgb, vec3(1.0)) == 0.0)
+ return;
+
+ float roughness = speccol_roughness.a;
+ float roughnessSquared = max(1e-3, roughness * roughness);
+ float a2 = roughnessSquared * roughnessSquared;
+
+ /* Early out */
+ if (roughness > ssrMaxRoughness + 0.2)
+ return;
+
+ vec4 rand = texelFetch(utilTex, ivec3(halfres_texel % LUT_SIZE, 2), 0);
+
+ /* Gives *perfect* reflection for very small roughness */
+ if (roughness < 0.04) {
+ rand.xzw *= 0.0;
+ }
+ /* Importance sampling bias */
+ rand.x = mix(rand.x, 0.0, ssrBrdfBias);
+
+ vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition);
+ vec3 wN = transform_direction(ViewMatrixInverse, N);
+
+ vec3 T, B;
+ make_orthonormal_basis(N, T, B); /* Generate tangent space */
+
+ /* Planar Reflections */
+ for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar; ++i) {
+ PlanarData pd = planars_data[i];
+
+ float fade = probe_attenuation_planar(pd, worldPosition, wN, 0.0);
+
+ if (fade > 0.5) {
+ /* Find view vector / reflection plane intersection. */
+ /* TODO optimize, use view space for all. */
+ vec3 tracePosition = line_plane_intersect(worldPosition, cameraVec, pd.pl_plane_eq);
+ tracePosition = transform_point(ViewMatrix, tracePosition);
+ vec3 planeNormal = transform_direction(ViewMatrix, pd.pl_normal);
+
+ do_planar_ssr(i, V, N, T, B, planeNormal, tracePosition, a2, rand);
+ return;
+ }
+ }
+
+ do_ssr(V, N, T, B, viewPosition, a2, rand);
+}
+
+#else /* STEP_RESOLVE */
+
+uniform sampler2D prevColorBuffer; /* previous frame */
+uniform sampler2D normalBuffer;
+uniform sampler2D specroughBuffer;
+
+uniform isampler2D hitBuffer;
+uniform sampler2D pdfBuffer;
+
+uniform int neighborOffset;
+
+const ivec2 neighbors[32] = ivec2[32](
+ ivec2( 0, 0), ivec2( 1, 1), ivec2(-2, 0), ivec2( 0, -2),
+ ivec2( 0, 0), ivec2( 1, -1), ivec2(-2, 0), ivec2( 0, 2),
+ ivec2( 0, 0), ivec2(-1, -1), ivec2( 2, 0), ivec2( 0, 2),
+ ivec2( 0, 0), ivec2(-1, 1), ivec2( 2, 0), ivec2( 0, -2),
+
+ ivec2( 0, 0), ivec2( 2, 2), ivec2(-2, 2), ivec2( 0, -1),
+ ivec2( 0, 0), ivec2( 2, -2), ivec2(-2, -2), ivec2( 0, 1),
+ ivec2( 0, 0), ivec2(-2, -2), ivec2(-2, 2), ivec2( 1, 0),
+ ivec2( 0, 0), ivec2( 2, 2), ivec2( 2, -2), ivec2(-1, 0)
+);
+
+out vec4 fragColor;
+
+void fallback_cubemap(
+ vec3 N, vec3 V, vec3 W, vec3 viewPosition, float roughness, float roughnessSquared, inout vec4 spec_accum)
+{
+ /* Specular probes */
+ vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughnessSquared);
+
+ vec4 rand = texelfetch_noise_tex(gl_FragCoord.xy);
+ vec3 bent_normal;
+#ifdef SSR_AO
+ float final_ao = occlusion_compute(N, viewPosition, 1.0, rand, bent_normal);
+ final_ao = specular_occlusion(dot(N, V), final_ao, roughness);
+#else
+ const float final_ao = 1.0;
+#endif
+
+ /* Starts at 1 because 0 is world probe */
+ for (int i = 1; i < MAX_PROBE && i < prbNumRenderCube && spec_accum.a < 0.999; ++i) {
+ CubeData cd = probes_data[i];
+
+ float fade = probe_attenuation_cube(cd, W);
+
+ if (fade > 0.0) {
+ vec3 spec = final_ao * probe_evaluate_cube(float(i), cd, W, spec_dir, roughness);
+ accumulate_light(spec, fade, spec_accum);
+ }
+ }
+
+ /* World Specular */
+ if (spec_accum.a < 0.999) {
+ vec3 spec = final_ao * probe_evaluate_world_spec(spec_dir, roughness);
+ accumulate_light(spec, 1.0, spec_accum);
+ }
+}
+
+#if 0 /* Finish reprojection with motion vectors */
+vec3 get_motion_vector(vec3 pos)
+{
+}
+
+/* http://bitsquid.blogspot.fr/2017/06/reprojecting-reflections_22.html */
+vec3 find_reflection_incident_point(vec3 cam, vec3 hit, vec3 pos, vec3 N)
+{
+ float d_cam = point_plane_projection_dist(cam, pos, N);
+ float d_hit = point_plane_projection_dist(hit, pos, N);
+
+ if (d_hit < d_cam) {
+ /* Swap */
+ float tmp = d_cam;
+ d_cam = d_hit;
+ d_hit = tmp;
+ }
+
+ vec3 proj_cam = cam - (N * d_cam);
+ vec3 proj_hit = hit - (N * d_hit);
+
+ return (proj_hit - proj_cam) * d_cam / (d_cam + d_hit) + proj_cam;
+}
+#endif
+
+float brightness(vec3 c)
+{
+ return max(max(c.r, c.g), c.b);
+}
+
+vec2 get_reprojected_reflection(vec3 hit, vec3 pos, vec3 N)
+{
+ /* TODO real reprojection with motion vectors, etc... */
+ return project_point(pastViewProjectionMatrix, hit).xy * 0.5 + 0.5;
+}
+
+float get_sample_depth(vec2 hit_co, bool is_planar, float planar_index)
+{
+ if (is_planar) {
+ return textureLod(planarDepth, vec3(hit_co, planar_index), 0.0).r;
+ }
+ else {
+ return textureLod(depthBuffer, hit_co, 0.0).r;
+ }
+}
+
+vec3 get_hit_vector(
+ vec3 hit_pos, PlanarData pd, vec3 worldPosition, vec3 N, vec3 V, bool is_planar,
+ inout vec2 hit_co, inout float mask)
+{
+ vec3 hit_vec;
+
+ if (is_planar) {
+ /* Reflect back the hit position to have it in non-reflected world space */
+ vec3 trace_pos = line_plane_intersect(worldPosition, V, pd.pl_plane_eq);
+ hit_vec = hit_pos - trace_pos;
+ hit_vec = reflect(hit_vec, pd.pl_normal);
+ }
+ else {
+ /* Find hit position in previous frame. */
+ mask = screen_border_mask(gl_FragCoord.xy / vec2(textureSize(depthBuffer, 0)));
+ hit_co = get_reprojected_reflection(hit_pos, worldPosition, N);
+ hit_vec = hit_pos - worldPosition;
+ }
+
+ mask = min(mask, screen_border_mask(hit_co));
+ return hit_vec;
+}
+
+vec3 get_scene_color(vec2 ref_uvs, float mip, float planar_index, bool is_planar)
+{
+ if (is_planar) {
+ return textureLod(probePlanars, vec3(ref_uvs, planar_index), min(mip, prbLodPlanarMax)).rgb;
+ }
+ else {
+ return textureLod(prevColorBuffer, ref_uvs, mip).rgb;
+ }
+}
+
+vec4 get_ssr_samples(
+ vec4 hit_pdf, ivec4 hit_data[2],
+ PlanarData pd, float planar_index, vec3 worldPosition, vec3 N, vec3 V,
+ float roughnessSquared, float cone_tan, vec2 source_uvs,
+ inout float weight_acc)
+{
+ bvec4 is_planar, has_hit;
+ vec4 hit_co[2];
+ hit_co[0].xy = decode_hit_data(hit_data[0].xy, has_hit.x, is_planar.x);
+ hit_co[0].zw = decode_hit_data(hit_data[0].zw, has_hit.y, is_planar.y);
+ hit_co[1].xy = decode_hit_data(hit_data[1].xy, has_hit.z, is_planar.z);
+ hit_co[1].zw = decode_hit_data(hit_data[1].zw, has_hit.w, is_planar.w);
+
+ vec4 hit_depth;
+ hit_depth.x = get_sample_depth(hit_co[0].xy, is_planar.x, planar_index);
+ hit_depth.y = get_sample_depth(hit_co[0].zw, is_planar.y, planar_index);
+ hit_depth.z = get_sample_depth(hit_co[1].xy, is_planar.z, planar_index);
+ hit_depth.w = get_sample_depth(hit_co[1].zw, is_planar.w, planar_index);
+
+ /* Hit position in view space. */
+ vec3 hit_view[4];
+ hit_view[0] = get_view_space_from_depth(hit_co[0].xy, hit_depth.x);
+ hit_view[1] = get_view_space_from_depth(hit_co[0].zw, hit_depth.y);
+ hit_view[2] = get_view_space_from_depth(hit_co[1].xy, hit_depth.z);
+ hit_view[3] = get_view_space_from_depth(hit_co[1].zw, hit_depth.w);
+
+ vec4 homcoord = vec4(hit_view[0].z, hit_view[1].z, hit_view[2].z, hit_view[3].z);
+ homcoord = ProjectionMatrix[2][3] * homcoord + ProjectionMatrix[3][3];
+
+ /* Hit position in world space. */
+ vec3 hit_pos[4];
+ hit_pos[0] = transform_point(ViewMatrixInverse, hit_view[0]);
+ hit_pos[1] = transform_point(ViewMatrixInverse, hit_view[1]);
+ hit_pos[2] = transform_point(ViewMatrixInverse, hit_view[2]);
+ hit_pos[3] = transform_point(ViewMatrixInverse, hit_view[3]);
+
+ /* Get actual hit vector and hit coordinate (from last frame). */
+ vec4 mask = vec4(1.0);
+ hit_pos[0] = get_hit_vector(hit_pos[0], pd, worldPosition, N, V, is_planar.x, hit_co[0].xy, mask.x);
+ hit_pos[1] = get_hit_vector(hit_pos[1], pd, worldPosition, N, V, is_planar.y, hit_co[0].zw, mask.y);
+ hit_pos[2] = get_hit_vector(hit_pos[2], pd, worldPosition, N, V, is_planar.z, hit_co[1].xy, mask.z);
+ hit_pos[3] = get_hit_vector(hit_pos[3], pd, worldPosition, N, V, is_planar.w, hit_co[1].zw, mask.w);
+
+ vec4 hit_dist;
+ hit_dist.x = length(hit_pos[0]);
+ hit_dist.y = length(hit_pos[1]);
+ hit_dist.z = length(hit_pos[2]);
+ hit_dist.w = length(hit_pos[3]);
+ hit_dist = max(vec4(1e-8), hit_dist);
+
+ /* Normalize */
+ hit_pos[0] /= hit_dist.x;
+ hit_pos[1] /= hit_dist.y;
+ hit_pos[2] /= hit_dist.z;
+ hit_pos[3] /= hit_dist.w;
+
+ /* Compute cone footprint in screen space. */
+ vec4 cone_footprint = hit_dist * cone_tan;
+ cone_footprint = ssrBrdfBias * 0.5 * cone_footprint * max(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) / homcoord;
+
+ /* Estimate a cone footprint to sample a corresponding mipmap level. */
+ vec4 mip = log2(cone_footprint * max_v2(vec2(textureSize(depthBuffer, 0))));
+ mip = clamp(mip, 0.0, MAX_MIP);
+
+ /* Correct UVs for mipmaping mis-alignment */
+ hit_co[0].xy *= mip_ratio_interp(mip.x);
+ hit_co[0].zw *= mip_ratio_interp(mip.y);
+ hit_co[1].xy *= mip_ratio_interp(mip.z);
+ hit_co[1].zw *= mip_ratio_interp(mip.w);
+
+ /* Slide 54 */
+ vec4 bsdf;
+ bsdf.x = bsdf_ggx(N, hit_pos[0], V, roughnessSquared);
+ bsdf.y = bsdf_ggx(N, hit_pos[1], V, roughnessSquared);
+ bsdf.z = bsdf_ggx(N, hit_pos[2], V, roughnessSquared);
+ bsdf.w = bsdf_ggx(N, hit_pos[3], V, roughnessSquared);
+
+ vec4 weight = step(1e-8, hit_pdf) * bsdf / max(vec4(1e-8), hit_pdf);
+
+ vec3 sample[4];
+ sample[0] = get_scene_color(hit_co[0].xy, mip.x, planar_index, is_planar.x);
+ sample[1] = get_scene_color(hit_co[0].zw, mip.y, planar_index, is_planar.y);
+ sample[2] = get_scene_color(hit_co[1].xy, mip.z, planar_index, is_planar.z);
+ sample[3] = get_scene_color(hit_co[1].zw, mip.w, planar_index, is_planar.w);
+
+ /* Clamped brightness. */
+ vec4 luma;
+ luma.x = brightness(sample[0]);
+ luma.y = brightness(sample[1]);
+ luma.z = brightness(sample[2]);
+ luma.w = brightness(sample[3]);
+ luma = max(vec4(1e-8), luma);
+ luma = 1.0 - max(vec4(0.0), luma - ssrFireflyFac) / luma;
+
+ sample[0] *= luma.x;
+ sample[1] *= luma.y;
+ sample[2] *= luma.z;
+ sample[3] *= luma.w;
+
+ /* Protection against NaNs in the history buffer.
+ * This could be removed if some previous pass has already
+ * sanitized the input. */
+ if (any(isnan(sample[0]))) {
+ sample[0] = vec3(0.0); weight.x = 0.0;
+ }
+ if (any(isnan(sample[1]))) {
+ sample[1] = vec3(0.0); weight.y = 0.0;
+ }
+ if (any(isnan(sample[2]))) {
+ sample[2] = vec3(0.0); weight.z = 0.0;
+ }
+ if (any(isnan(sample[3]))) {
+ sample[3] = vec3(0.0); weight.w = 0.0;
+ }
+
+ weight_acc += sum(weight);
+
+ /* Do not add light if ray has failed. */
+ vec4 accum;
+ accum = vec4(sample[0], mask.x) * weight.x * float(has_hit.x);
+ accum += vec4(sample[1], mask.y) * weight.y * float(has_hit.y);
+ accum += vec4(sample[2], mask.z) * weight.z * float(has_hit.z);
+ accum += vec4(sample[3], mask.w) * weight.w * float(has_hit.w);
+ return accum;
+}
+
+void main()
+{
+ ivec2 fullres_texel = ivec2(gl_FragCoord.xy);
+#ifdef FULLRES
+ ivec2 halfres_texel = fullres_texel;
+#else
+ ivec2 halfres_texel = ivec2(gl_FragCoord.xy / 2.0);
+#endif
+ vec2 uvs = gl_FragCoord.xy / vec2(textureSize(depthBuffer, 0));
+
+ float depth = textureLod(depthBuffer, uvs, 0.0).r;
+
+ /* Early out */
+ if (depth == 1.0)
+ discard;
+
+ /* Using world space */
+ vec3 viewPosition = get_view_space_from_depth(uvs, depth); /* Needed for viewCameraVec */
+ vec3 worldPosition = transform_point(ViewMatrixInverse, viewPosition);
+ vec3 V = cameraVec;
+ vec3 vN = normal_decode(texelFetch(normalBuffer, fullres_texel, 0).rg, viewCameraVec);
+ vec3 N = transform_direction(ViewMatrixInverse, vN);
+ vec4 speccol_roughness = texelFetch(specroughBuffer, fullres_texel, 0).rgba;
+
+ /* Early out */
+ if (dot(speccol_roughness.rgb, vec3(1.0)) == 0.0)
+ discard;
+
+ /* TODO optimize with textureGather */
+ /* Doing these fetches early to hide latency. */
+ vec4 hit_pdf;
+ hit_pdf.x = texelFetch(pdfBuffer, halfres_texel + neighbors[0 + neighborOffset], 0).r;
+ hit_pdf.y = texelFetch(pdfBuffer, halfres_texel + neighbors[1 + neighborOffset], 0).r;
+ hit_pdf.z = texelFetch(pdfBuffer, halfres_texel + neighbors[2 + neighborOffset], 0).r;
+ hit_pdf.w = texelFetch(pdfBuffer, halfres_texel + neighbors[3 + neighborOffset], 0).r;
+
+ ivec4 hit_data[2];
+ hit_data[0].xy = texelFetch(hitBuffer, halfres_texel + neighbors[0 + neighborOffset], 0).rg;
+ hit_data[0].zw = texelFetch(hitBuffer, halfres_texel + neighbors[1 + neighborOffset], 0).rg;
+ hit_data[1].xy = texelFetch(hitBuffer, halfres_texel + neighbors[2 + neighborOffset], 0).rg;
+ hit_data[1].zw = texelFetch(hitBuffer, halfres_texel + neighbors[3 + neighborOffset], 0).rg;
+
+ /* Find Planar Reflections affecting this pixel */
+ PlanarData pd;
+ float planar_index;
+ for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar; ++i) {
+ pd = planars_data[i];
+
+ float fade = probe_attenuation_planar(pd, worldPosition, N, 0.0);
+
+ if (fade > 0.5) {
+ planar_index = float(i);
+ break;
+ }
+ }
+
+ float roughness = speccol_roughness.a;
+ float roughnessSquared = max(1e-3, roughness * roughness);
+
+ vec4 spec_accum = vec4(0.0);
+
+ /* Resolve SSR */
+ float cone_cos = cone_cosine(roughnessSquared);
+ float cone_tan = sqrt(1 - cone_cos * cone_cos) / cone_cos;
+ cone_tan *= mix(saturate(dot(N, -V) * 2.0), 1.0, roughness); /* Elongation fit */
+
+ vec2 source_uvs = project_point(pastViewProjectionMatrix, worldPosition).xy * 0.5 + 0.5;
+
+ vec4 ssr_accum = vec4(0.0);
+ float weight_acc = 0.0;
+
+ if (roughness < ssrMaxRoughness + 0.2) {
+ ssr_accum += get_ssr_samples(hit_pdf, hit_data, pd, planar_index, worldPosition, N, V,
+ roughnessSquared, cone_tan, source_uvs, weight_acc);
+ }
+
+ /* Compute SSR contribution */
+ if (weight_acc > 0.0) {
+ ssr_accum /= weight_acc;
+ /* fade between 0.5 and 1.0 roughness */
+ ssr_accum.a *= smoothstep(ssrMaxRoughness + 0.2, ssrMaxRoughness, roughness);
+ accumulate_light(ssr_accum.rgb, ssr_accum.a, spec_accum);
+ }
+
+ /* If SSR contribution is not 1.0, blend with cubemaps */
+ if (spec_accum.a < 1.0) {
+ fallback_cubemap(N, V, worldPosition, viewPosition, roughness, roughnessSquared, spec_accum);
+ }
+
+ fragColor = vec4(spec_accum.rgb * speccol_roughness.rgb, 1.0);
+}
+
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl
new file mode 100644
index 00000000000..5ecf6323255
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_subsurface_frag.glsl
@@ -0,0 +1,99 @@
+
+/* Based on Separable SSS. by Jorge Jimenez and Diego Gutierrez */
+
+#define MAX_SSS_SAMPLES 65
+layout(std140) uniform sssProfile {
+ vec4 kernel[MAX_SSS_SAMPLES];
+ vec4 radii_max_radius;
+ int sss_samples;
+};
+
+uniform sampler2D depthBuffer;
+uniform sampler2D sssData;
+uniform sampler2D sssAlbedo;
+
+#ifndef UTIL_TEX
+#define UTIL_TEX
+uniform sampler2DArray utilTex;
+#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
+#endif /* UTIL_TEX */
+
+layout(location = 0) out vec4 FragColor;
+#ifdef RESULT_ACCUM
+layout(location = 1) out vec4 sssColor;
+#endif
+
+float get_view_z_from_depth(float depth)
+{
+ if (ProjectionMatrix[3][3] == 0.0) {
+ float d = 2.0 * depth - 1.0;
+ return -ProjectionMatrix[3][2] / (d + ProjectionMatrix[2][2]);
+ }
+ else {
+ return viewVecs[0].z + depth * viewVecs[1].z;
+ }
+}
+
+#define LUT_SIZE 64
+#define M_PI_2 1.5707963267948966 /* pi/2 */
+#define M_2PI 6.2831853071795865 /* 2*pi */
+
+void main(void)
+{
+ vec2 pixel_size = 1.0 / vec2(textureSize(depthBuffer, 0).xy); /* TODO precompute */
+ vec2 uvs = gl_FragCoord.xy * pixel_size;
+ vec4 sss_data = texture(sssData, uvs).rgba;
+ float depth_view = get_view_z_from_depth(texture(depthBuffer, uvs).r);
+
+ float rand = texelfetch_noise_tex(gl_FragCoord.xy).r;
+#ifdef FIRST_PASS
+ float angle = M_2PI * rand + M_PI_2;
+ vec2 dir = vec2(1.0, 0.0);
+#else /* SECOND_PASS */
+ float angle = M_2PI * rand;
+ vec2 dir = vec2(0.0, 1.0);
+#endif
+ vec2 dir_rand = vec2(cos(angle), sin(angle));
+
+ /* Compute kernel bounds in 2D. */
+ float homcoord = ProjectionMatrix[2][3] * depth_view + ProjectionMatrix[3][3];
+ vec2 scale = vec2(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) * sss_data.aa / homcoord;
+ vec2 finalStep = scale * radii_max_radius.w;
+ finalStep *= 0.5; /* samples range -1..1 */
+
+ /* Center sample */
+ vec3 accum = sss_data.rgb * kernel[0].rgb;
+
+ for (int i = 1; i < sss_samples && i < MAX_SSS_SAMPLES; i++) {
+ vec2 sample_uv = uvs + kernel[i].a * finalStep * ((abs(kernel[i].a) > sssJitterThreshold) ? dir : dir_rand);
+ vec3 color = texture(sssData, sample_uv).rgb;
+ float sample_depth = texture(depthBuffer, sample_uv).r;
+ sample_depth = get_view_z_from_depth(sample_depth);
+
+ /* Depth correction factor. */
+ float depth_delta = depth_view - sample_depth;
+ float s = clamp(1.0 - exp(-(depth_delta * depth_delta) / (2.0 * sss_data.a)), 0.0, 1.0);
+
+ /* Out of view samples. */
+ if (any(lessThan(sample_uv, vec2(0.0))) || any(greaterThan(sample_uv, vec2(1.0)))) {
+ s = 1.0;
+ }
+
+ accum += kernel[i].rgb * mix(color, sss_data.rgb, s);
+ }
+
+#ifdef FIRST_PASS
+ FragColor = vec4(accum, sss_data.a);
+#else /* SECOND_PASS */
+# ifdef USE_SEP_ALBEDO
+# ifdef RESULT_ACCUM
+ FragColor = vec4(accum, 1.0);
+ sssColor = texture(sssAlbedo, uvs);
+# else
+ FragColor = vec4(accum * texture(sssAlbedo, uvs).rgb, 1.0);
+# endif
+# else
+ FragColor = vec4(accum, 1.0);
+# endif
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl b/source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl
new file mode 100644
index 00000000000..e118777f6c8
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_temporal_aa.glsl
@@ -0,0 +1,111 @@
+
+uniform sampler2D colorHistoryBuffer;
+uniform sampler2D velocityBuffer;
+
+out vec4 FragColor;
+
+vec4 safe_color(vec4 c)
+{
+ /* Clamp to avoid black square artifacts if a pixel goes NaN. */
+ return clamp(c, vec4(0.0), vec4(1e20)); /* 1e20 arbitrary. */
+}
+
+#ifdef USE_REPROJECTION
+
+/**
+ * Adapted from https://casual-effects.com/g3d/G3D10/data-files/shader/Film/Film_temporalAA.pix
+ * which is adapted from https://github.com/gokselgoktas/temporal-anti-aliasing/blob/master/Assets/Resources/Shaders/TemporalAntiAliasing.cginc
+ * which is adapted from https://github.com/playdeadgames/temporal
+ * Optimization by Stubbesaurus and epsilon adjustment to avoid division by zero.
+ *
+ * This can cause 3x3 blocks of color when there is a thin edge of a similar color that
+ * is varying in intensity.
+ */
+vec3 clip_to_aabb(vec3 color, vec3 minimum, vec3 maximum, vec3 average)
+{
+ /* note: only clips towards aabb center (but fast!) */
+ vec3 center = 0.5 * (maximum + minimum);
+ vec3 extents = 0.5 * (maximum - minimum);
+ vec3 dist = color - center;
+ vec3 ts = abs(extents) / max(abs(dist), vec3(0.0001));
+ float t = saturate(min_v3(ts));
+ return center + dist * t;
+}
+
+/**
+ * Vastly based on https://github.com/playdeadgames/temporal
+ */
+void main()
+{
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+ float depth = texelFetch(depthBuffer, texel, 0).r;
+ vec2 motion = texelFetch(velocityBuffer, texel, 0).rg;
+
+ /* Decode from unsigned normalized 16bit texture. */
+ motion = motion * 2.0 - 1.0;
+
+ /* Compute pixel position in previous frame. */
+ vec2 screen_res = vec2(textureSize(colorBuffer, 0).xy);
+ vec2 uv = gl_FragCoord.xy / screen_res;
+ vec2 uv_history = uv - motion;
+
+ ivec2 texel_history = ivec2(uv_history * screen_res);
+ vec4 color_history = textureLod(colorHistoryBuffer, uv_history, 0.0);
+
+ /* Color bounding box clamping. 3x3 neighborhood. */
+ vec4 c02 = texelFetchOffset(colorBuffer, texel, 0, ivec2(-1, 1));
+ vec4 c12 = texelFetchOffset(colorBuffer, texel, 0, ivec2( 0, 1));
+ vec4 c22 = texelFetchOffset(colorBuffer, texel, 0, ivec2( 1, 1));
+ vec4 c01 = texelFetchOffset(colorBuffer, texel, 0, ivec2(-1, 0));
+ vec4 c11 = texelFetchOffset(colorBuffer, texel, 0, ivec2( 0, 0));
+ vec4 c21 = texelFetchOffset(colorBuffer, texel, 0, ivec2( 1, 0));
+ vec4 c00 = texelFetchOffset(colorBuffer, texel, 0, ivec2(-1, -1));
+ vec4 c10 = texelFetchOffset(colorBuffer, texel, 0, ivec2( 0, -1));
+ vec4 c20 = texelFetchOffset(colorBuffer, texel, 0, ivec2( 1, -1));
+
+ vec4 color = c11;
+
+ /* AABB minmax */
+ vec4 min_col = min9(c02, c12, c22, c01, c11, c21, c00, c10, c20);
+ vec4 max_col = max9(c02, c12, c22, c01, c11, c21, c00, c10, c20);
+ vec4 avg_col = avg9(c02, c12, c22, c01, c11, c21, c00, c10, c20);
+
+ /* bias the color aabb toward the center (rounding the shape) */
+ vec4 min_center = min5(c12, c01, c11, c21, c10);
+ vec4 max_center = max5(c12, c01, c11, c21, c10);
+ vec4 avg_center = avg5(c12, c01, c11, c21, c10);
+ min_col = (min_col + min_center) * 0.5;
+ max_col = (max_col + max_center) * 0.5;
+ avg_col = (avg_col + avg_center) * 0.5;
+
+ /* Clip color toward the center of the neighborhood colors AABB box. */
+ color_history.rgb = clip_to_aabb(color_history.rgb, min_col.rgb, max_col.rgb, avg_col.rgb);
+
+ /* Luminance weighting. */
+ /* TODO correct luminance */
+ float lum0 = dot(color.rgb, vec3(0.333));
+ float lum1 = dot(color_history.rgb, vec3(0.333));
+ float diff = abs(lum0 - lum1) / max(lum0, max(lum1, 0.2));
+ float weight = 1.0 - diff;
+ float alpha = mix(0.04, 0.12, weight * weight);
+
+ color_history = mix(color_history, color, alpha);
+
+ bool out_of_view = any(greaterThanEqual(abs(uv_history - 0.5), vec2(0.5)));
+ color_history = (out_of_view) ? color : color_history;
+
+ FragColor = safe_color(color_history);
+}
+
+#else
+
+uniform float alpha;
+
+void main()
+{
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+ vec4 color = texelFetch(colorBuffer, texel, 0);
+ vec4 color_history = texelFetch(colorHistoryBuffer, texel, 0);
+ FragColor = safe_color(mix(color_history, color, alpha));
+}
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/effect_velocity_resolve_frag.glsl b/source/blender/draw/engines/eevee/shaders/effect_velocity_resolve_frag.glsl
new file mode 100644
index 00000000000..8324c25225c
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/effect_velocity_resolve_frag.glsl
@@ -0,0 +1,22 @@
+
+uniform mat4 currPersinv;
+uniform mat4 pastPersmat;
+
+out vec2 outData;
+
+void main()
+{
+ /* Extract pixel motion vector from camera movement. */
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+ vec2 uv = gl_FragCoord.xy / vec2(textureSize(depthBuffer, 0).xy);
+
+ float depth = texelFetch(depthBuffer, texel, 0).r;
+
+ vec3 world_position = project_point(currPersinv, vec3(uv, depth) * 2.0 - 1.0);
+ vec2 uv_history = project_point(pastPersmat, world_position).xy * 0.5 + 0.5;
+
+ outData = uv - uv_history;
+
+ /* Encode to unsigned normalized 16bit texture. */
+ outData = outData * 0.5 + 0.5;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl b/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl
new file mode 100644
index 00000000000..132cc16fcbd
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/irradiance_lib.glsl
@@ -0,0 +1,177 @@
+
+uniform sampler2DArray irradianceGrid;
+
+#define IRRADIANCE_LIB
+
+#ifdef IRRADIANCE_CUBEMAP
+struct IrradianceData {
+ vec3 color;
+};
+#elif defined(IRRADIANCE_SH_L2)
+struct IrradianceData {
+ vec3 shcoefs[9];
+};
+#else /* defined(IRRADIANCE_HL2) */
+struct IrradianceData {
+ vec3 cubesides[3];
+};
+#endif
+
+IrradianceData load_irradiance_cell(int cell, vec3 N)
+{
+ /* Keep in sync with diffuse_filter_probe() */
+
+#if defined(IRRADIANCE_CUBEMAP)
+
+ #define AMBIANT_CUBESIZE 8
+ ivec2 cell_co = ivec2(AMBIANT_CUBESIZE);
+ int cell_per_row = textureSize(irradianceGrid, 0).x / cell_co.x;
+ cell_co.x *= cell % cell_per_row;
+ cell_co.y *= cell / cell_per_row;
+
+ vec2 texelSize = 1.0 / vec2(AMBIANT_CUBESIZE);
+
+ vec2 uvs = mapping_octahedron(N, texelSize);
+ uvs *= vec2(AMBIANT_CUBESIZE) / vec2(textureSize(irradianceGrid, 0));
+ uvs += vec2(cell_co) / vec2(textureSize(irradianceGrid, 0));
+
+ IrradianceData ir;
+ ir.color = texture(irradianceGrid, vec3(uvs, 0.0)).rgb;
+
+#elif defined(IRRADIANCE_SH_L2)
+
+ ivec2 cell_co = ivec2(3, 3);
+ int cell_per_row = textureSize(irradianceGrid, 0).x / cell_co.x;
+ cell_co.x *= cell % cell_per_row;
+ cell_co.y *= cell / cell_per_row;
+
+ ivec3 ofs = ivec3(0, 1, 2);
+
+ IrradianceData ir;
+ ir.shcoefs[0] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.xx, 0), 0).rgb;
+ ir.shcoefs[1] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.yx, 0), 0).rgb;
+ ir.shcoefs[2] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.zx, 0), 0).rgb;
+ ir.shcoefs[3] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.xy, 0), 0).rgb;
+ ir.shcoefs[4] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.yy, 0), 0).rgb;
+ ir.shcoefs[5] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.zy, 0), 0).rgb;
+ ir.shcoefs[6] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.xz, 0), 0).rgb;
+ ir.shcoefs[7] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.yz, 0), 0).rgb;
+ ir.shcoefs[8] = texelFetch(irradianceGrid, ivec3(cell_co + ofs.zz, 0), 0).rgb;
+
+#else /* defined(IRRADIANCE_HL2) */
+
+ ivec2 cell_co = ivec2(3, 2);
+ int cell_per_row = textureSize(irradianceGrid, 0).x / cell_co.x;
+ cell_co.x *= cell % cell_per_row;
+ cell_co.y *= cell / cell_per_row;
+
+ ivec3 is_negative = ivec3(step(0.0, -N));
+
+ IrradianceData ir;
+ ir.cubesides[0] = irradiance_decode(texelFetch(irradianceGrid, ivec3(cell_co + ivec2(0, is_negative.x), 0), 0));
+ ir.cubesides[1] = irradiance_decode(texelFetch(irradianceGrid, ivec3(cell_co + ivec2(1, is_negative.y), 0), 0));
+ ir.cubesides[2] = irradiance_decode(texelFetch(irradianceGrid, ivec3(cell_co + ivec2(2, is_negative.z), 0), 0));
+
+#endif
+
+ return ir;
+}
+
+float load_visibility_cell(int cell, vec3 L, float dist, float bias, float bleed_bias, float range)
+{
+ /* Keep in sync with diffuse_filter_probe() */
+ ivec2 cell_co = ivec2(prbIrradianceVisSize);
+ ivec2 cell_per_row_col = textureSize(irradianceGrid, 0).xy / prbIrradianceVisSize;
+ cell_co.x *= (cell % cell_per_row_col.x);
+ cell_co.y *= (cell / cell_per_row_col.x) % cell_per_row_col.y;
+ float layer = 1.0 + float((cell / cell_per_row_col.x) / cell_per_row_col.y);
+
+ vec2 texel_size = 1.0 / vec2(textureSize(irradianceGrid, 0).xy);
+ vec2 co = vec2(cell_co) * texel_size;
+
+ vec2 uv = mapping_octahedron(-L, vec2(1.0 / float(prbIrradianceVisSize)));
+ uv *= vec2(prbIrradianceVisSize) * texel_size;
+
+ vec4 data = texture(irradianceGrid, vec3(co + uv, layer));
+
+ /* Decoding compressed data */
+ vec2 moments = visibility_decode(data, range);
+
+ /* Doing chebishev test */
+ float variance = abs(moments.x * moments.x - moments.y);
+ variance = max(variance, bias / 10.0);
+
+ float d = dist - moments.x;
+ float p_max = variance / (variance + d * d);
+
+ /* Increase contrast in the weight by squaring it */
+ p_max *= p_max;
+
+ /* Now reduce light-bleeding by removing the [0, x] tail and linearly rescaling (x, 1] */
+ p_max = clamp((p_max - bleed_bias) / (1.0 - bleed_bias), 0.0, 1.0);
+
+ return (dist <= moments.x) ? 1.0 : p_max;
+}
+
+/* http://seblagarde.wordpress.com/2012/01/08/pi-or-not-to-pi-in-game-lighting-equation/ */
+vec3 spherical_harmonics_L1(vec3 N, vec3 shcoefs[4])
+{
+ vec3 sh = vec3(0.0);
+
+ sh += 0.282095 * shcoefs[0];
+
+ sh += -0.488603 * N.z * shcoefs[1];
+ sh += 0.488603 * N.y * shcoefs[2];
+ sh += -0.488603 * N.x * shcoefs[3];
+
+ return sh;
+}
+
+vec3 spherical_harmonics_L2(vec3 N, vec3 shcoefs[9])
+{
+ vec3 sh = vec3(0.0);
+
+ sh += 0.282095 * shcoefs[0];
+
+ sh += -0.488603 * N.z * shcoefs[1];
+ sh += 0.488603 * N.y * shcoefs[2];
+ sh += -0.488603 * N.x * shcoefs[3];
+
+ sh += 1.092548 * N.x * N.z * shcoefs[4];
+ sh += -1.092548 * N.z * N.y * shcoefs[5];
+ sh += 0.315392 * (3.0 * N.y * N.y - 1.0) * shcoefs[6];
+ sh += -1.092548 * N.x * N.y * shcoefs[7];
+ sh += 0.546274 * (N.x * N.x - N.z * N.z) * shcoefs[8];
+
+ return sh;
+}
+
+vec3 hl2_basis(vec3 N, vec3 cubesides[3])
+{
+ vec3 irradiance = vec3(0.0);
+
+ vec3 n_squared = N * N;
+
+ irradiance += n_squared.x * cubesides[0];
+ irradiance += n_squared.y * cubesides[1];
+ irradiance += n_squared.z * cubesides[2];
+
+ return irradiance;
+}
+
+vec3 compute_irradiance(vec3 N, IrradianceData ird)
+{
+#if defined(IRRADIANCE_CUBEMAP)
+ return ird.color;
+#elif defined(IRRADIANCE_SH_L2)
+ return spherical_harmonics_L2(N, ird.shcoefs);
+#else /* defined(IRRADIANCE_HL2) */
+ return hl2_basis(N, ird.cubesides);
+#endif
+}
+
+vec3 irradiance_from_cell_get(int cell, vec3 ir_dir)
+{
+ IrradianceData ir_data = load_irradiance_cell(cell, ir_dir);
+ return compute_irradiance(ir_dir, ir_data);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
new file mode 100644
index 00000000000..62f4c0c1c93
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lamps_lib.glsl
@@ -0,0 +1,453 @@
+
+uniform sampler2DArray shadowCubeTexture;
+uniform sampler2DArray shadowCascadeTexture;
+
+#define LAMPS_LIB
+
+layout(std140) uniform shadow_block {
+ ShadowData shadows_data[MAX_SHADOW];
+ ShadowCubeData shadows_cube_data[MAX_SHADOW_CUBE];
+ ShadowCascadeData shadows_cascade_data[MAX_SHADOW_CASCADE];
+};
+
+layout(std140) uniform light_block {
+ LightData lights_data[MAX_LIGHT];
+};
+
+/* type */
+#define POINT 0.0
+#define SUN 1.0
+#define SPOT 2.0
+#define HEMI 3.0
+#define AREA 4.0
+
+#if defined(SHADOW_VSM)
+#define ShadowSample vec2
+#define sample_cube(vec, id) texture_octahedron(shadowCubeTexture, vec4(vec, id)).rg
+#define sample_cascade(vec, id) texture(shadowCascadeTexture, vec3(vec, id)).rg
+#elif defined(SHADOW_ESM)
+#define ShadowSample float
+#define sample_cube(vec, id) texture_octahedron(shadowCubeTexture, vec4(vec, id)).r
+#define sample_cascade(vec, id) texture(shadowCascadeTexture, vec3(vec, id)).r
+#else
+#define ShadowSample float
+#define sample_cube(vec, id) texture_octahedron(shadowCubeTexture, vec4(vec, id)).r
+#define sample_cascade(vec, id) texture(shadowCascadeTexture, vec3(vec, id)).r
+#endif
+
+#if defined(SHADOW_VSM)
+#define get_depth_delta(s) (dist - s.x)
+#else
+#define get_depth_delta(s) (dist - s)
+#endif
+
+/* ----------------------------------------------------------- */
+/* ----------------------- Shadow tests ---------------------- */
+/* ----------------------------------------------------------- */
+
+#if defined(SHADOW_VSM)
+
+float shadow_test(ShadowSample moments, float dist, ShadowData sd)
+{
+ float p = 0.0;
+
+ if (dist <= moments.x)
+ p = 1.0;
+
+ float variance = moments.y - (moments.x * moments.x);
+ variance = max(variance, sd.sh_bias / 10.0);
+
+ float d = moments.x - dist;
+ float p_max = variance / (variance + d * d);
+
+ /* Now reduce light-bleeding by removing the [0, x] tail and linearly rescaling (x, 1] */
+ p_max = clamp((p_max - sd.sh_bleed) / (1.0 - sd.sh_bleed), 0.0, 1.0);
+
+ return max(p, p_max);
+}
+
+#elif defined(SHADOW_ESM)
+
+float shadow_test(ShadowSample z, float dist, ShadowData sd)
+{
+ return saturate(exp(sd.sh_exp * (z - dist + sd.sh_bias)));
+}
+
+#else
+
+float shadow_test(ShadowSample z, float dist, ShadowData sd)
+{
+ return step(0, z - dist + sd.sh_bias);
+}
+
+#endif
+
+/* ----------------------------------------------------------- */
+/* ----------------------- Shadow types ---------------------- */
+/* ----------------------------------------------------------- */
+
+float shadow_cubemap(ShadowData sd, ShadowCubeData scd, float texid, vec3 W)
+{
+ vec3 cubevec = W - scd.position.xyz;
+ float dist = length(cubevec);
+
+ /* If fragment is out of shadowmap range, do not occlude */
+ /* XXX : we check radial distance against a cubeface distance.
+ * We loose quite a bit of valid area. */
+ if (dist > sd.sh_far)
+ return 1.0;
+
+ cubevec /= dist;
+
+ ShadowSample s = sample_cube(cubevec, texid);
+ return shadow_test(s, dist, sd);
+}
+
+float evaluate_cascade(ShadowData sd, mat4 shadowmat, vec3 W, float range, float texid)
+{
+ vec4 shpos = shadowmat * vec4(W, 1.0);
+ float dist = shpos.z * range;
+
+ ShadowSample s = sample_cascade(shpos.xy, texid);
+ float vis = shadow_test(s, dist, sd);
+
+ /* If fragment is out of shadowmap range, do not occlude */
+ if (shpos.z < 1.0 && shpos.z > 0.0) {
+ return vis;
+ }
+ else {
+ return 1.0;
+ }
+}
+
+float shadow_cascade(ShadowData sd, ShadowCascadeData scd, float texid, vec3 W)
+{
+ vec4 view_z = vec4(dot(W - cameraPos, cameraForward));
+ vec4 weights = smoothstep(scd.split_end_distances, scd.split_start_distances.yzwx, view_z);
+ weights.yzw -= weights.xyz;
+
+ vec4 vis = vec4(1.0);
+ float range = abs(sd.sh_far - sd.sh_near); /* Same factor as in get_cascade_world_distance(). */
+
+ /* Branching using (weights > 0.0) is reaally slooow on intel so avoid it for now. */
+ /* TODO OPTI: Only do 2 samples and blend. */
+ vis.x = evaluate_cascade(sd, scd.shadowmat[0], W, range, texid + 0);
+ vis.y = evaluate_cascade(sd, scd.shadowmat[1], W, range, texid + 1);
+ vis.z = evaluate_cascade(sd, scd.shadowmat[2], W, range, texid + 2);
+ vis.w = evaluate_cascade(sd, scd.shadowmat[3], W, range, texid + 3);
+
+ float weight_sum = dot(vec4(1.0), weights);
+ if (weight_sum > 0.9999) {
+ float vis_sum = dot(vec4(1.0), vis * weights);
+ return vis_sum / weight_sum;
+ }
+ else {
+ float vis_sum = dot(vec4(1.0), vis * step(0.001, weights));
+ return mix(1.0, vis_sum, weight_sum);
+ }
+}
+
+/* ----------------------------------------------------------- */
+/* --------------------- Light Functions --------------------- */
+/* ----------------------------------------------------------- */
+#define MAX_MULTI_SHADOW 4
+
+float light_visibility(LightData ld, vec3 W,
+#ifndef VOLUMETRICS
+ vec3 viewPosition,
+ vec3 viewNormal,
+#endif
+ vec4 l_vector)
+{
+ float vis = 1.0;
+
+ if (ld.l_type == SPOT) {
+ float z = dot(ld.l_forward, l_vector.xyz);
+ vec3 lL = l_vector.xyz / z;
+ float x = dot(ld.l_right, lL) / ld.l_sizex;
+ float y = dot(ld.l_up, lL) / ld.l_sizey;
+
+ float ellipse = inversesqrt(1.0 + x * x + y * y);
+
+ float spotmask = smoothstep(0.0, 1.0, (ellipse - ld.l_spot_size) / ld.l_spot_blend);
+
+ vis *= spotmask;
+ vis *= step(0.0, -dot(l_vector.xyz, ld.l_forward));
+ }
+ else if (ld.l_type == AREA) {
+ vis *= step(0.0, -dot(l_vector.xyz, ld.l_forward));
+ }
+
+#if !defined(VOLUMETRICS) || defined(VOLUME_SHADOW)
+ /* shadowing */
+ if (ld.l_shadowid >= 0.0) {
+ ShadowData data = shadows_data[int(ld.l_shadowid)];
+
+ if (ld.l_type == SUN) {
+ /* TODO : MSM */
+ // for (int i = 0; i < MAX_MULTI_SHADOW; ++i) {
+ vis *= shadow_cascade(
+ data, shadows_cascade_data[int(data.sh_data_start)],
+ data.sh_tex_start, W);
+ // }
+ }
+ else {
+ /* TODO : MSM */
+ // for (int i = 0; i < MAX_MULTI_SHADOW; ++i) {
+ vis *= shadow_cubemap(
+ data, shadows_cube_data[int(data.sh_data_start)],
+ data.sh_tex_start, W);
+ // }
+ }
+
+#ifndef VOLUMETRICS
+ /* Only compute if not already in shadow. */
+ if ((vis > 0.001) && (data.sh_contact_dist > 0.0)) {
+ vec4 L = (ld.l_type != SUN) ? l_vector : vec4(-ld.l_forward, 1.0);
+ float trace_distance = (ld.l_type != SUN) ? min(data.sh_contact_dist, l_vector.w) : data.sh_contact_dist;
+
+ vec3 T, B;
+ make_orthonormal_basis(L.xyz / L.w, T, B);
+
+ vec4 rand = texelfetch_noise_tex(gl_FragCoord.xy);
+ rand.zw *= fast_sqrt(rand.y) * data.sh_contact_spread;
+
+ /* We use the full l_vector.xyz so that the spread is minimize
+ * if the shading point is further away from the light source */
+ vec3 ray_dir = L.xyz + T * rand.z + B * rand.w;
+ ray_dir = transform_direction(ViewMatrix, ray_dir);
+ ray_dir = normalize(ray_dir);
+
+ vec3 ray_ori = viewPosition;
+
+ float bias = 0.5; /* Constant Bias */
+ bias += 1.0 - abs(dot(viewNormal, ray_dir)); /* Angle dependant bias */
+ bias *= gl_FrontFacing ? data.sh_contact_offset : -data.sh_contact_offset;
+
+ vec3 nor_bias = viewNormal * bias;
+ ray_ori += nor_bias;
+
+ ray_dir *= trace_distance;
+ ray_dir -= nor_bias;
+
+ vec3 hit_pos = raycast(-1, ray_ori, ray_dir, data.sh_contact_thickness, rand.x,
+ 0.1, 0.001, false);
+
+ if (hit_pos.z > 0.0) {
+ hit_pos = get_view_space_from_depth(hit_pos.xy, hit_pos.z);
+ float hit_dist = distance(viewPosition, hit_pos);
+ float dist_ratio = hit_dist / trace_distance;
+ return vis * saturate(dist_ratio * dist_ratio * dist_ratio);
+ }
+ }
+#endif
+ }
+#endif
+
+ return vis;
+}
+
+float light_diffuse(LightData ld, vec3 N, vec3 V, vec4 l_vector)
+{
+#ifdef USE_LTC
+ if (ld.l_type == SUN) {
+ return direct_diffuse_unit_disc(ld, N, V);
+ }
+ else if (ld.l_type == AREA) {
+ return direct_diffuse_rectangle(ld, N, V, l_vector);
+ }
+ else {
+ return direct_diffuse_sphere(ld, N, l_vector);
+ }
+#else
+ if (ld.l_type == SUN) {
+ return direct_diffuse_sun(ld, N);
+ }
+ else {
+ return direct_diffuse_point(N, l_vector);
+ }
+#endif
+}
+
+vec3 light_specular(LightData ld, vec3 N, vec3 V, vec4 l_vector, float roughness, vec3 f0)
+{
+#ifdef USE_LTC
+ if (ld.l_type == SUN) {
+ return direct_ggx_unit_disc(ld, N, V, roughness, f0);
+ }
+ else if (ld.l_type == AREA) {
+ return direct_ggx_rectangle(ld, N, V, l_vector, roughness, f0);
+ }
+ else {
+ return direct_ggx_sphere(ld, N, V, l_vector, roughness, f0);
+ }
+#else
+ if (ld.l_type == SUN) {
+ return direct_ggx_sun(ld, N, V, roughness, f0);
+ }
+ else {
+ return direct_ggx_point(N, V, l_vector, roughness, f0);
+ }
+#endif
+}
+
+#define MAX_SSS_SAMPLES 65
+#define SSS_LUT_SIZE 64.0
+#define SSS_LUT_SCALE ((SSS_LUT_SIZE - 1.0) / float(SSS_LUT_SIZE))
+#define SSS_LUT_BIAS (0.5 / float(SSS_LUT_SIZE))
+layout(std140) uniform sssProfile {
+ vec4 kernel[MAX_SSS_SAMPLES];
+ vec4 radii_max_radius;
+ int sss_samples;
+};
+
+uniform sampler1D sssTexProfile;
+
+vec3 sss_profile(float s) {
+ s /= radii_max_radius.w;
+ return texture(sssTexProfile, saturate(s) * SSS_LUT_SCALE + SSS_LUT_BIAS).rgb;
+}
+
+vec3 light_translucent(LightData ld, vec3 W, vec3 N, vec4 l_vector, float scale)
+{
+#if !defined(USE_TRANSLUCENCY) || defined(VOLUMETRICS)
+ return vec3(0.0);
+#else
+ vec3 vis = vec3(1.0);
+
+ /* Only shadowed light can produce translucency */
+ if (ld.l_shadowid >= 0.0) {
+ ShadowData data = shadows_data[int(ld.l_shadowid)];
+ float delta;
+
+ vec4 L = (ld.l_type != SUN) ? l_vector : vec4(-ld.l_forward, 1.0);
+
+ vec3 T, B;
+ make_orthonormal_basis(L.xyz / L.w, T, B);
+
+ vec4 rand = texelfetch_noise_tex(gl_FragCoord.xy);
+ rand.zw *= fast_sqrt(rand.y) * data.sh_blur;
+
+ /* We use the full l_vector.xyz so that the spread is minimize
+ * if the shading point is further away from the light source */
+ W = W + T * rand.z + B * rand.w;
+
+ if (ld.l_type == SUN) {
+ ShadowCascadeData scd = shadows_cascade_data[int(data.sh_data_start)];
+ vec4 view_z = vec4(dot(W - cameraPos, cameraForward));
+
+ vec4 weights = step(scd.split_end_distances, view_z);
+ float id = abs(4.0 - dot(weights, weights));
+
+ if (id > 3.0) {
+ return vec3(0.0);
+ }
+
+ float range = abs(data.sh_far - data.sh_near); /* Same factor as in get_cascade_world_distance(). */
+
+ vec4 shpos = scd.shadowmat[int(id)] * vec4(W, 1.0);
+ float dist = shpos.z * range;
+
+ if (shpos.z > 1.0 || shpos.z < 0.0) {
+ return vec3(0.0);
+ }
+
+ ShadowSample s = sample_cascade(shpos.xy, data.sh_tex_start + id);
+ delta = get_depth_delta(s);
+ }
+ else {
+ vec3 cubevec = W - shadows_cube_data[int(data.sh_data_start)].position.xyz;
+ float dist = length(cubevec);
+
+ /* If fragment is out of shadowmap range, do not occlude */
+ /* XXX : we check radial distance against a cubeface distance.
+ * We loose quite a bit of valid area. */
+ if (dist < data.sh_far) {
+ cubevec /= dist;
+
+ ShadowSample s = sample_cube(cubevec, data.sh_tex_start);
+ delta = get_depth_delta(s);
+ }
+ }
+
+ /* XXX : Removing Area Power. */
+ /* TODO : put this out of the shader. */
+ float falloff;
+ if (ld.l_type == AREA) {
+ vis *= (ld.l_sizex * ld.l_sizey * 4.0 * M_PI) * (1.0 / 80.0);
+ vis *= 0.3 * 20.0 * max(0.0, dot(-ld.l_forward, l_vector.xyz / l_vector.w)); /* XXX ad hoc, empirical */
+ vis /= (l_vector.w * l_vector.w);
+ falloff = dot(N, l_vector.xyz / l_vector.w);
+ }
+ else if (ld.l_type == SUN) {
+ vis *= (4.0f * ld.l_radius * ld.l_radius * M_2PI) * (1.0 / 12.5); /* Removing area light power*/
+ vis *= M_2PI * 0.78; /* Matching cycles with point light. */
+ vis *= 0.082; /* XXX ad hoc, empirical */
+ falloff = dot(N, -ld.l_forward);
+ }
+ else {
+ vis *= (4.0 * ld.l_radius * ld.l_radius) * (1.0 /10.0);
+ vis *= 1.5; /* XXX ad hoc, empirical */
+ vis /= (l_vector.w * l_vector.w);
+ falloff = dot(N, l_vector.xyz / l_vector.w);
+ }
+ // vis *= M_1_PI; /* Normalize */
+
+ /* Applying profile */
+ vis *= sss_profile(abs(delta) / scale);
+
+ /* No transmittance at grazing angle (hide artifacts) */
+ vis *= saturate(falloff * 2.0);
+
+ if (ld.l_type == SPOT) {
+ float z = dot(ld.l_forward, l_vector.xyz);
+ vec3 lL = l_vector.xyz / z;
+ float x = dot(ld.l_right, lL) / ld.l_sizex;
+ float y = dot(ld.l_up, lL) / ld.l_sizey;
+
+ float ellipse = inversesqrt(1.0 + x * x + y * y);
+
+ float spotmask = smoothstep(0.0, 1.0, (ellipse - ld.l_spot_size) / ld.l_spot_blend);
+
+ vis *= spotmask;
+ vis *= step(0.0, -dot(l_vector.xyz, ld.l_forward));
+ }
+ else if (ld.l_type == AREA) {
+ vis *= step(0.0, -dot(l_vector.xyz, ld.l_forward));
+ }
+ }
+ else {
+ vis = vec3(0.0);
+ }
+
+ return vis;
+#endif
+}
+
+#ifdef HAIR_SHADER
+void light_hair_common(
+ LightData ld, vec3 N, vec3 V, vec4 l_vector, vec3 norm_view,
+ out float occlu_trans, out float occlu,
+ out vec3 norm_lamp, out vec3 view_vec)
+{
+ const float transmission = 0.3; /* Uniform internal scattering factor */
+
+ vec3 lamp_vec;
+
+ if (ld.l_type == SUN || ld.l_type == AREA) {
+ lamp_vec = ld.l_forward;
+ }
+ else {
+ lamp_vec = -l_vector.xyz;
+ }
+
+ norm_lamp = cross(lamp_vec, N);
+ norm_lamp = normalize(cross(N, norm_lamp)); /* Normal facing lamp */
+
+ /* Rotate view vector onto the cross(tangent, light) plane */
+ view_vec = normalize(norm_lamp * dot(norm_view, V) + N * dot(N, V));
+
+ occlu = (dot(norm_view, norm_lamp) * 0.5 + 0.5);
+ occlu_trans = transmission + (occlu * (1.0 - transmission)); /* Includes transmission component */
+}
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
new file mode 100644
index 00000000000..d10f4bc0d42
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_frag.glsl
@@ -0,0 +1,15 @@
+
+flat in int pid;
+in vec3 worldNormal;
+in vec3 worldPosition;
+
+out vec4 FragColor;
+
+void main()
+{
+ vec3 V = (ProjectionMatrix[3][3] == 0.0) /* if perspective */
+ ? normalize(cameraPos - worldPosition)
+ : cameraForward;
+ vec3 N = normalize(worldNormal);
+ FragColor = vec4(textureLod_octahedron(probeCubes, vec4(reflect(-V, N), pid), 0.0, prbLodCubeMax).rgb, 1.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
new file mode 100644
index 00000000000..b0a6cbe1707
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_cube_display_vert.glsl
@@ -0,0 +1,26 @@
+
+in vec3 pos;
+
+/* Instance attrib */
+in int probe_id;
+in vec3 probe_location;
+in float sphere_size;
+
+flat out int pid;
+out vec3 worldNormal;
+out vec3 worldPosition;
+
+void main()
+{
+ pid = probe_id;
+
+ /* While this is not performant, we do this to
+ * match the object mode engine instancing shader. */
+ mat4 offsetmat = mat4(1.0); /* Identity */
+ offsetmat[3].xyz = probe_location;
+
+ vec4 wpos = offsetmat * vec4(pos * sphere_size, 1.0);
+ worldPosition = wpos.xyz;
+ gl_Position = ViewProjectionMatrix * wpos;
+ worldNormal = normalize(pos);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl
new file mode 100644
index 00000000000..14fd6d3dff5
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_diffuse_frag.glsl
@@ -0,0 +1,198 @@
+
+uniform samplerCube probeHdr;
+uniform int probeSize;
+uniform float lodFactor;
+uniform float lodMax;
+uniform float intensityFac;
+
+in vec3 worldPosition;
+
+out vec4 FragColor;
+
+#define M_4PI 12.5663706143591729
+
+const mat3 CUBE_ROTATIONS[6] = mat3[](
+ mat3(vec3( 0.0, 0.0, -1.0),
+ vec3( 0.0, -1.0, 0.0),
+ vec3(-1.0, 0.0, 0.0)),
+ mat3(vec3( 0.0, 0.0, 1.0),
+ vec3( 0.0, -1.0, 0.0),
+ vec3( 1.0, 0.0, 0.0)),
+ mat3(vec3( 1.0, 0.0, 0.0),
+ vec3( 0.0, 0.0, 1.0),
+ vec3( 0.0, -1.0, 0.0)),
+ mat3(vec3( 1.0, 0.0, 0.0),
+ vec3( 0.0, 0.0, -1.0),
+ vec3( 0.0, 1.0, 0.0)),
+ mat3(vec3( 1.0, 0.0, 0.0),
+ vec3( 0.0, -1.0, 0.0),
+ vec3( 0.0, 0.0, -1.0)),
+ mat3(vec3(-1.0, 0.0, 0.0),
+ vec3( 0.0, -1.0, 0.0),
+ vec3( 0.0, 0.0, 1.0)));
+
+vec3 get_cubemap_vector(vec2 co, int face)
+{
+ return normalize(CUBE_ROTATIONS[face] * vec3(co * 2.0 - 1.0, 1.0));
+}
+
+float area_element(float x, float y)
+{
+ return atan(x * y, sqrt(x * x + y * y + 1));
+}
+
+float texel_solid_angle(vec2 co, float halfpix)
+{
+ vec2 v1 = (co - vec2(halfpix)) * 2.0 - 1.0;
+ vec2 v2 = (co + vec2(halfpix)) * 2.0 - 1.0;
+
+ return area_element(v1.x, v1.y) - area_element(v1.x, v2.y) - area_element(v2.x, v1.y) + area_element(v2.x, v2.y);
+}
+
+vec3 octahedral_to_cubemap_proj(vec2 co)
+{
+ co = co * 2.0 - 1.0;
+
+ vec2 abs_co = abs(co);
+ vec3 v = vec3(co, 1.0 - (abs_co.x + abs_co.y));
+
+ if ( abs_co.x + abs_co.y > 1.0 ) {
+ v.xy = (abs(co.yx) - 1.0) * -sign(co.xy);
+ }
+
+ return v;
+}
+
+void main()
+{
+#if defined(IRRADIANCE_SH_L2)
+ float pixstep = 1.0 / probeSize;
+ float halfpix = pixstep / 2.0;
+
+ /* Downside: leaks negative values, very bandwidth consuming */
+ int comp = int(gl_FragCoord.x) % 3 + (int(gl_FragCoord.y) % 3) * 3;
+
+ float weight_accum = 0.0;
+ vec3 sh = vec3(0.0);
+
+ for (int face = 0; face < 6; ++face) {
+ for (float x = halfpix; x < 1.0; x += pixstep) {
+ for (float y = halfpix; y < 1.0; y += pixstep) {
+ float weight, coef;
+ vec2 facecoord = vec2(x,y);
+ vec3 cubevec = get_cubemap_vector(facecoord, face);
+
+ if (comp == 0) {
+ coef = 0.282095;
+ }
+ else if (comp == 1) {
+ coef = -0.488603 * cubevec.z * 2.0 / 3.0;
+ }
+ else if (comp == 2) {
+ coef = 0.488603 * cubevec.y * 2.0 / 3.0;
+ }
+ else if (comp == 3) {
+ coef = -0.488603 * cubevec.x * 2.0 / 3.0;
+ }
+ else if (comp == 4) {
+ coef = 1.092548 * cubevec.x * cubevec.z * 1.0 / 4.0;
+ }
+ else if (comp == 5) {
+ coef = -1.092548 * cubevec.z * cubevec.y * 1.0 / 4.0;
+ }
+ else if (comp == 6) {
+ coef = 0.315392 * (3.0 * cubevec.y * cubevec.y - 1.0) * 1.0 / 4.0;
+ }
+ else if (comp == 7) {
+ coef = 1.092548 * cubevec.x * cubevec.y * 1.0 / 4.0;
+ }
+ else { /* (comp == 8) */
+ coef = 0.546274 * (cubevec.x * cubevec.x - cubevec.z * cubevec.z) * 1.0 / 4.0;
+ }
+
+ weight = texel_solid_angle(facecoord, halfpix);
+
+ vec4 sample = textureLod(probeHdr, cubevec, lodMax);
+ sh += sample.rgb * coef * weight;
+ weight_accum += weight;
+ }
+ }
+ }
+ sh *= M_4PI / weight_accum;
+
+ FragColor = vec4(sh, 1.0);
+#else
+#if defined(IRRADIANCE_CUBEMAP)
+ /* Downside: Need lots of memory for storage, distortion due to octahedral mapping */
+ const vec2 map_size = vec2(16.0);
+ const vec2 texelSize = 1.0 / map_size;
+ vec2 uvs = mod(gl_FragCoord.xy, map_size) * texelSize;
+ const float paddingSize = 1.0;
+
+ /* Add a N pixel border to ensure filtering is correct
+ * for N mipmap levels. */
+ uvs += uvs * texelSize * paddingSize * 2.0;
+ uvs -= texelSize * paddingSize;
+
+ /* edge mirroring : only mirror if directly adjacent
+ * (not diagonally adjacent) */
+ vec2 m = abs(uvs - 0.5) + 0.5;
+ vec2 f = floor(m);
+ if (f.x - f.y != 0.0) {
+ uvs = 1.0 - uvs;
+ }
+
+ /* clamp to [0-1] */
+ uvs = fract(uvs);
+
+ /* get cubemap vector */
+ vec3 cubevec = octahedral_to_cubemap_proj(uvs);
+
+#elif defined(IRRADIANCE_HL2)
+ /* Downside: very very low resolution (6 texels), bleed lighting because of interpolation */
+ int x = int(gl_FragCoord.x) % 3;
+ int y = int(gl_FragCoord.y) % 2;
+
+ vec3 cubevec = vec3(1.0, 0.0, 0.0);
+
+ if (x == 1) {
+ cubevec = cubevec.yxy;
+ }
+ else if (x == 2) {
+ cubevec = cubevec.yyx;
+ }
+
+ if (y == 1) {
+ cubevec = -cubevec;
+ }
+#endif
+
+ vec3 N, T, B, V;
+
+ N = normalize(cubevec);
+
+ make_orthonormal_basis(N, T, B); /* Generate tangent space */
+
+ /* Integrating Envmap */
+ float weight = 0.0;
+ vec3 out_radiance = vec3(0.0);
+ for (float i = 0; i < sampleCount; i++) {
+ vec3 L = sample_hemisphere(i, N, T, B); /* Microfacet normal */
+ float NL = dot(N, L);
+
+ if (NL > 0.0) {
+ /* Coarse Approximation of the mapping distortion
+ * Unit Sphere -> Cubemap Face */
+ const float dist = 4.0 * M_PI / 6.0;
+ float pdf = pdf_hemisphere();
+ /* http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html : Equation 13 */
+ float lod = clamp(lodFactor - 0.5 * log2(pdf * dist), 0.0, lodMax) ;
+
+ out_radiance += textureLod(probeHdr, L, lod).rgb * NL;
+ weight += NL;
+ }
+ }
+
+ FragColor = irradiance_encode(intensityFac * out_radiance / weight);
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl
new file mode 100644
index 00000000000..e4199e6a5ed
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_glossy_frag.glsl
@@ -0,0 +1,87 @@
+
+uniform samplerCube probeHdr;
+uniform float roughnessSquared;
+uniform float texelSize;
+uniform float lodFactor;
+uniform float lodMax;
+uniform float paddingSize;
+uniform float intensityFac;
+
+in vec3 worldPosition;
+
+out vec4 FragColor;
+
+vec3 octahedral_to_cubemap_proj(vec2 co)
+{
+ co = co * 2.0 - 1.0;
+
+ vec2 abs_co = abs(co);
+ vec3 v = vec3(co, 1.0 - (abs_co.x + abs_co.y));
+
+ if ( abs_co.x + abs_co.y > 1.0 ) {
+ v.xy = (abs(co.yx) - 1.0) * -sign(co.xy);
+ }
+
+ return v;
+}
+
+void main() {
+ vec2 uvs = gl_FragCoord.xy * texelSize;
+
+ /* Add a N pixel border to ensure filtering is correct
+ * for N mipmap levels. */
+ uvs += uvs * texelSize * paddingSize * 2.0;
+ uvs -= texelSize * paddingSize;
+
+ /* edge mirroring : only mirror if directly adjacent
+ * (not diagonally adjacent) */
+ vec2 m = abs(uvs - 0.5) + 0.5;
+ vec2 f = floor(m);
+ if (f.x - f.y != 0.0) {
+ uvs = 1.0 - uvs;
+ }
+
+ /* clamp to [0-1] */
+ uvs = fract(uvs);
+
+ /* get cubemap vector */
+ vec3 cubevec = octahedral_to_cubemap_proj(uvs);
+
+ vec3 N, T, B, V;
+
+ vec3 R = normalize(cubevec);
+
+ /* Isotropic assumption */
+ N = V = R;
+
+ make_orthonormal_basis(N, T, B); /* Generate tangent space */
+
+ /* Noise to dither the samples */
+ /* Note : ghosting is better looking than noise. */
+ // setup_noise();
+
+ /* Integrating Envmap */
+ float weight = 0.0;
+ vec3 out_radiance = vec3(0.0);
+ for (float i = 0; i < sampleCount; i++) {
+ vec3 H = sample_ggx(i, roughnessSquared, N, T, B); /* Microfacet normal */
+ vec3 L = -reflect(V, H);
+ float NL = dot(N, L);
+
+ if (NL > 0.0) {
+ float NH = max(1e-8, dot(N, H)); /* cosTheta */
+
+ /* Coarse Approximation of the mapping distortion
+ * Unit Sphere -> Cubemap Face */
+ const float dist = 4.0 * M_PI / 6.0;
+ float pdf = pdf_ggx_reflect(NH, roughnessSquared);
+ /* http://http.developer.nvidia.com/GPUGems3/gpugems3_ch20.html : Equation 13 */
+ float lod = clamp(lodFactor - 0.5 * log2(pdf * dist), 0.0, lodMax) ;
+
+ out_radiance += textureLod(probeHdr, L, lod).rgb * NL;
+ weight += NL;
+ }
+ }
+
+ FragColor = vec4(intensityFac * out_radiance / weight, 1.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl
new file mode 100644
index 00000000000..211fa8f0ce8
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_filter_visibility_frag.glsl
@@ -0,0 +1,88 @@
+
+uniform samplerCube probeDepth;
+uniform int outputSize;
+uniform float lodFactor;
+uniform float storedTexelSize;
+uniform float lodMax;
+uniform float nearClip;
+uniform float farClip;
+uniform float visibilityRange;
+uniform float visibilityBlur;
+
+out vec4 FragColor;
+
+vec3 octahedral_to_cubemap_proj(vec2 co)
+{
+ co = co * 2.0 - 1.0;
+
+ vec2 abs_co = abs(co);
+ vec3 v = vec3(co, 1.0 - (abs_co.x + abs_co.y));
+
+ if ( abs_co.x + abs_co.y > 1.0 ) {
+ v.xy = (abs(co.yx) - 1.0) * -sign(co.xy);
+ }
+
+ return v;
+}
+
+float linear_depth(float z)
+{
+ return (nearClip * farClip) / (z * (nearClip - farClip) + farClip);
+}
+
+float get_world_distance(float depth, vec3 cos)
+{
+ float is_background = step(1.0, depth);
+ depth = linear_depth(depth);
+ depth += 1e1 * is_background;
+ cos = normalize(abs(cos));
+ float cos_vec = max(cos.x, max(cos.y, cos.z));
+ return depth / cos_vec;
+}
+
+void main()
+{
+ ivec2 texel = ivec2(gl_FragCoord.xy) % ivec2(outputSize);
+
+ vec3 cos;
+
+ cos.xy = (vec2(texel) + 0.5) * storedTexelSize;
+
+ /* add a 2 pixel border to ensure filtering is correct */
+ cos.xy *= 1.0 + storedTexelSize * 2.0;
+ cos.xy -= storedTexelSize;
+
+ float pattern = 1.0;
+
+ /* edge mirroring : only mirror if directly adjacent
+ * (not diagonally adjacent) */
+ vec2 m = abs(cos.xy - 0.5) + 0.5;
+ vec2 f = floor(m);
+ if (f.x - f.y != 0.0) {
+ cos.xy = 1.0 - cos.xy;
+ }
+
+ /* clamp to [0-1] */
+ cos.xy = fract(cos.xy);
+
+ /* get cubemap vector */
+ cos = normalize(octahedral_to_cubemap_proj(cos.xy));
+
+ vec3 T, B;
+ make_orthonormal_basis(cos, T, B); /* Generate tangent space */
+
+ vec2 accum = vec2(0.0);
+
+ for (float i = 0; i < sampleCount; i++) {
+ vec3 sample = sample_cone(i, M_PI_2 * visibilityBlur, cos, T, B);
+ float depth = texture(probeDepth, sample).r;
+ depth = get_world_distance(depth, sample);
+ accum += vec2(depth, depth * depth);
+ }
+
+ accum *= invSampleCount;
+ accum = abs(accum);
+
+ /* Encode to normalized RGBA 8 */
+ FragColor = visibility_encode(accum, visibilityRange);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_geom.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_geom.glsl
new file mode 100644
index 00000000000..2ce37d867b7
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_geom.glsl
@@ -0,0 +1,34 @@
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices=3) out;
+
+uniform int Layer;
+
+in vec4 vPos[];
+flat in int face[];
+flat out int fFace;
+
+out vec3 worldPosition;
+out vec3 viewPosition; /* Required. otherwise generate linking error. */
+out vec3 worldNormal; /* Required. otherwise generate linking error. */
+out vec3 viewNormal; /* Required. otherwise generate linking error. */
+
+const vec3 maj_axes[6] = vec3[6](vec3(1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0), vec3(0.0, 1.0, 0.0), vec3(0.0, -1.0, 0.0), vec3( 0.0, 0.0, 1.0), vec3( 0.0, 0.0, -1.0));
+const vec3 x_axis[6] = vec3[6](vec3(0.0, 0.0, -1.0), vec3( 0.0, 0.0, 1.0), vec3(1.0, 0.0, 0.0), vec3(1.0, 0.0, 0.0), vec3( 1.0, 0.0, 0.0), vec3(-1.0, 0.0, 0.0));
+const vec3 y_axis[6] = vec3[6](vec3(0.0, -1.0, 0.0), vec3( 0.0, -1.0, 0.0), vec3(0.0, 0.0, 1.0), vec3(0.0, 0.0, -1.0), vec3( 0.0, -1.0, 0.0), vec3( 0.0, -1.0, 0.0));
+
+void main() {
+ fFace = face[0];
+ gl_Layer = Layer + fFace;
+
+ for (int v = 0; v < 3; ++v) {
+ gl_Position = vPos[v];
+ worldPosition = x_axis[fFace] * vPos[v].x + y_axis[fFace] * vPos[v].y + maj_axes[fFace];
+#ifdef ATTRIB
+ pass_attrib(v);
+#endif
+ EmitVertex();
+ }
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl
new file mode 100644
index 00000000000..d333ad34bb0
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_frag.glsl
@@ -0,0 +1,11 @@
+
+flat in int cellOffset;
+in vec3 worldNormal;
+
+out vec4 FragColor;
+
+void main()
+{
+ IrradianceData ir_data = load_irradiance_cell(cellOffset, worldNormal);
+ FragColor = vec4(compute_irradiance(worldNormal, ir_data), 1.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl
new file mode 100644
index 00000000000..a017a791e41
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_display_vert.glsl
@@ -0,0 +1,32 @@
+
+in vec3 pos;
+
+uniform float sphere_size;
+uniform int offset;
+uniform ivec3 grid_resolution;
+uniform vec3 corner;
+uniform vec3 increment_x;
+uniform vec3 increment_y;
+uniform vec3 increment_z;
+
+flat out int cellOffset;
+out vec3 worldNormal;
+
+void main()
+{
+ vec3 ls_cell_location;
+ /* Keep in sync with update_irradiance_probe */
+ ls_cell_location.z = float(gl_InstanceID % grid_resolution.z);
+ ls_cell_location.y = float((gl_InstanceID / grid_resolution.z) % grid_resolution.y);
+ ls_cell_location.x = float(gl_InstanceID / (grid_resolution.z * grid_resolution.y));
+
+ cellOffset = offset + gl_InstanceID;
+
+ vec3 ws_cell_location = corner +
+ (increment_x * ls_cell_location.x +
+ increment_y * ls_cell_location.y +
+ increment_z * ls_cell_location.z);
+
+ gl_Position = ViewProjectionMatrix * vec4(pos * 0.02 * sphere_size + ws_cell_location, 1.0);
+ worldNormal = normalize(pos);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_grid_fill_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_fill_frag.glsl
new file mode 100644
index 00000000000..ced8e7f4f01
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_grid_fill_frag.glsl
@@ -0,0 +1,20 @@
+uniform sampler2DArray irradianceGrid;
+
+out vec4 FragColor;
+
+void main()
+{
+#if defined(IRRADIANCE_SH_L2)
+ const ivec2 data_size = ivec2(3, 3);
+#elif defined(IRRADIANCE_CUBEMAP)
+ const ivec2 data_size = ivec2(8, 8);
+#elif defined(IRRADIANCE_HL2)
+ const ivec2 data_size = ivec2(3, 2);
+#endif
+ ivec2 coord = ivec2(gl_FragCoord.xy) % data_size;
+ FragColor = texelFetch(irradianceGrid, ivec3(coord, 0), 0);
+
+ if (any(greaterThanEqual(ivec2(gl_FragCoord.xy), data_size))) {
+ FragColor = vec4(0.0, 0.0, 0.0, 1.0);
+ }
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
new file mode 100644
index 00000000000..429f6ea92e4
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_lib.glsl
@@ -0,0 +1,259 @@
+/* ----------- Uniforms --------- */
+
+uniform sampler2DArray probePlanars;
+uniform sampler2DArray probeCubes;
+
+/* ----------- Structures --------- */
+
+struct CubeData {
+ vec4 position_type;
+ vec4 attenuation_fac_type;
+ mat4 influencemat;
+ mat4 parallaxmat;
+};
+
+#define PROBE_PARALLAX_BOX 1.0
+#define PROBE_ATTENUATION_BOX 1.0
+
+#define p_position position_type.xyz
+#define p_parallax_type position_type.w
+#define p_atten_fac attenuation_fac_type.x
+#define p_atten_type attenuation_fac_type.y
+
+struct PlanarData {
+ vec4 plane_equation;
+ vec4 clip_vec_x_fade_scale;
+ vec4 clip_vec_y_fade_bias;
+ vec4 clip_edges;
+ vec4 facing_scale_bias;
+ mat4 reflectionmat; /* transform world space into reflection texture space */
+};
+
+#define pl_plane_eq plane_equation
+#define pl_normal plane_equation.xyz
+#define pl_facing_scale facing_scale_bias.x
+#define pl_facing_bias facing_scale_bias.y
+#define pl_fade_scale clip_vec_x_fade_scale.w
+#define pl_fade_bias clip_vec_y_fade_bias.w
+#define pl_clip_pos_x clip_vec_x_fade_scale.xyz
+#define pl_clip_pos_y clip_vec_y_fade_bias.xyz
+#define pl_clip_edges clip_edges
+
+struct GridData {
+ mat4 localmat;
+ ivec4 resolution_offset;
+ vec4 ws_corner_atten_scale; /* world space corner position */
+ vec4 ws_increment_x_atten_bias; /* world space vector between 2 opposite cells */
+ vec4 ws_increment_y_lvl_bias;
+ vec4 ws_increment_z;
+ vec4 vis_bias_bleed_range;
+};
+
+#define g_corner ws_corner_atten_scale.xyz
+#define g_atten_scale ws_corner_atten_scale.w
+#define g_atten_bias ws_increment_x_atten_bias.w
+#define g_level_bias ws_increment_y_lvl_bias.w
+#define g_increment_x ws_increment_x_atten_bias.xyz
+#define g_increment_y ws_increment_y_lvl_bias.xyz
+#define g_increment_z ws_increment_z.xyz
+#define g_resolution resolution_offset.xyz
+#define g_offset resolution_offset.w
+#define g_vis_bias vis_bias_bleed_range.x
+#define g_vis_bleed vis_bias_bleed_range.y
+#define g_vis_range vis_bias_bleed_range.z
+
+#ifndef MAX_PROBE
+#define MAX_PROBE 1
+#endif
+#ifndef MAX_GRID
+#define MAX_GRID 1
+#endif
+#ifndef MAX_PLANAR
+#define MAX_PLANAR 1
+#endif
+
+layout(std140) uniform probe_block {
+ CubeData probes_data[MAX_PROBE];
+};
+
+layout(std140) uniform grid_block {
+ GridData grids_data[MAX_GRID];
+};
+
+layout(std140) uniform planar_block {
+ PlanarData planars_data[MAX_PLANAR];
+};
+
+/* ----------- Functions --------- */
+
+float probe_attenuation_cube(CubeData pd, vec3 W)
+{
+ vec3 localpos = transform_point(pd.influencemat, W);
+
+ float fac;
+ if (pd.p_atten_type == PROBE_ATTENUATION_BOX) {
+ vec3 axes_fac = saturate(pd.p_atten_fac - pd.p_atten_fac * abs(localpos));
+ fac = min_v3(axes_fac);
+ }
+ else {
+ fac = saturate(pd.p_atten_fac - pd.p_atten_fac * length(localpos));
+ }
+
+ return fac;
+}
+
+float probe_attenuation_planar(PlanarData pd, vec3 W, vec3 N, float roughness)
+{
+ /* Normal Facing */
+ float fac = saturate(dot(pd.pl_normal, N) * pd.pl_facing_scale + pd.pl_facing_bias);
+
+ /* Distance from plane */
+ fac *= saturate(abs(dot(pd.pl_plane_eq, vec4(W, 1.0))) * pd.pl_fade_scale + pd.pl_fade_bias);
+
+ /* Fancy fast clipping calculation */
+ vec2 dist_to_clip;
+ dist_to_clip.x = dot(pd.pl_clip_pos_x, W);
+ dist_to_clip.y = dot(pd.pl_clip_pos_y, W);
+ fac *= step(2.0, dot(step(pd.pl_clip_edges, dist_to_clip.xxyy), vec2(-1.0, 1.0).xyxy)); /* compare and add all tests */
+
+ /* Decrease influence for high roughness */
+ fac *= saturate(1.0 - roughness * 10.0);
+
+ return fac;
+}
+
+float probe_attenuation_grid(GridData gd, vec3 W, out vec3 localpos)
+{
+ localpos = transform_point(gd.localmat, W);
+
+ float fade = min(1.0, min_v3(1.0 - abs(localpos)));
+ return saturate(fade * gd.g_atten_scale + gd.g_atten_bias);
+}
+
+vec3 probe_evaluate_cube(float id, CubeData cd, vec3 W, vec3 R, float roughness)
+{
+ /* Correct reflection ray using parallax volume intersection. */
+ vec3 localpos = transform_point(cd.parallaxmat, W);
+ vec3 localray = transform_direction(cd.parallaxmat, R);
+
+ float dist;
+ if (cd.p_parallax_type == PROBE_PARALLAX_BOX) {
+ dist = line_unit_box_intersect_dist(localpos, localray);
+ }
+ else {
+ dist = line_unit_sphere_intersect_dist(localpos, localray);
+ }
+
+ /* Use Distance in WS directly to recover intersection */
+ vec3 intersection = W + R * dist - cd.p_position;
+
+ /* From Frostbite PBR Course
+ * Distance based roughness
+ * http://www.frostbite.com/wp-content/uploads/2014/11/course_notes_moving_frostbite_to_pbr.pdf */
+ float original_roughness = roughness;
+ float linear_roughness = sqrt(roughness);
+ float distance_roughness = saturate(dist * linear_roughness / length(intersection));
+ linear_roughness = mix(distance_roughness, linear_roughness, linear_roughness);
+ roughness = linear_roughness * linear_roughness;
+
+ float fac = saturate(original_roughness * 2.0 - 1.0);
+ R = mix(intersection, R, fac * fac);
+
+ return textureLod_octahedron(probeCubes, vec4(R, id), roughness * prbLodCubeMax, prbLodCubeMax).rgb;
+}
+
+vec3 probe_evaluate_world_spec(vec3 R, float roughness)
+{
+ return textureLod_octahedron(probeCubes, vec4(R, 0.0), roughness * prbLodCubeMax, prbLodCubeMax).rgb;
+}
+
+vec3 probe_evaluate_planar(
+ float id, PlanarData pd, vec3 W, vec3 N, vec3 V,
+ float roughness, inout float fade)
+{
+ /* Find view vector / reflection plane intersection. */
+ vec3 point_on_plane = line_plane_intersect(W, V, pd.pl_plane_eq);
+
+ /* How far the pixel is from the plane. */
+ float ref_depth = 1.0; /* TODO parameter */
+
+ /* Compute distorded reflection vector based on the distance to the reflected object.
+ * In other words find intersection between reflection vector and the sphere center
+ * around point_on_plane. */
+ vec3 proj_ref = reflect(reflect(-V, N) * ref_depth, pd.pl_normal);
+
+ /* Final point in world space. */
+ vec3 ref_pos = point_on_plane + proj_ref;
+
+ /* Reproject to find texture coords. */
+ vec4 refco = ViewProjectionMatrix * vec4(ref_pos, 1.0);
+ refco.xy /= refco.w;
+
+ /* TODO: If we support non-ssr planar reflection, we should blur them with gaussian
+ * and chose the right mip depending on the cone footprint after projection */
+ vec3 sample = textureLod(probePlanars, vec3(refco.xy * 0.5 + 0.5, id), 0.0).rgb;
+
+ return sample;
+}
+
+#ifdef IRRADIANCE_LIB
+vec3 probe_evaluate_grid(GridData gd, vec3 W, vec3 N, vec3 localpos)
+{
+ localpos = localpos * 0.5 + 0.5;
+ localpos = localpos * vec3(gd.g_resolution) - 0.5;
+
+ vec3 localpos_floored = floor(localpos);
+ vec3 trilinear_weight = fract(localpos);
+
+ float weight_accum = 0.0;
+ vec3 irradiance_accum = vec3(0.0);
+
+ /* For each neighboor cells */
+ for (int i = 0; i < 8; ++i) {
+ ivec3 offset = ivec3(i, i >> 1, i >> 2) & ivec3(1);
+ vec3 cell_cos = clamp(localpos_floored + vec3(offset), vec3(0.0), vec3(gd.g_resolution) - 1.0);
+
+ /* Keep in sync with update_irradiance_probe */
+ ivec3 icell_cos = ivec3(gd.g_level_bias * floor(cell_cos / gd.g_level_bias));
+ int cell = gd.g_offset + icell_cos.z
+ + icell_cos.y * gd.g_resolution.z
+ + icell_cos.x * gd.g_resolution.z * gd.g_resolution.y;
+
+ vec3 color = irradiance_from_cell_get(cell, N);
+
+ /* We need this because we render probes in world space (so we need light vector in WS).
+ * And rendering them in local probe space is too much problem. */
+ vec3 ws_cell_location = gd.g_corner +
+ (gd.g_increment_x * cell_cos.x +
+ gd.g_increment_y * cell_cos.y +
+ gd.g_increment_z * cell_cos.z);
+
+ vec3 ws_point_to_cell = ws_cell_location - W;
+ float ws_dist_point_to_cell = length(ws_point_to_cell);
+ vec3 ws_light = ws_point_to_cell / ws_dist_point_to_cell;
+
+ vec3 trilinear = mix(1 - trilinear_weight, trilinear_weight, offset);
+ float weight = trilinear.x * trilinear.y * trilinear.z;
+
+ /* Precomputed visibility */
+ weight *= load_visibility_cell(cell, ws_light, ws_dist_point_to_cell, gd.g_vis_bias, gd.g_vis_bleed, gd.g_vis_range);
+
+ /* Smooth backface test */
+ weight *= sqrt(max(0.002, dot(ws_light, N)));
+
+ /* Avoid zero weight */
+ weight = max(0.00001, weight);
+
+ weight_accum += weight;
+ irradiance_accum += color * weight;
+ }
+
+ return irradiance_accum / weight_accum;
+}
+
+vec3 probe_evaluate_world_diff(vec3 N)
+{
+ return irradiance_from_cell_get(0, N);
+}
+
+#endif /* IRRADIANCE_LIB */
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
new file mode 100644
index 00000000000..3808b59761f
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_frag.glsl
@@ -0,0 +1,14 @@
+
+uniform sampler2DArray probePlanars;
+
+in vec3 worldPosition;
+flat in int probeIdx;
+
+out vec4 FragColor;
+
+void main()
+{
+ vec4 refco = ViewProjectionMatrix * vec4(worldPosition, 1.0);
+ refco.xy /= refco.w;
+ FragColor = vec4(textureLod(probePlanars, vec3(refco.xy * 0.5 + 0.5, float(probeIdx)), 0.0).rgb, 1.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl
new file mode 100644
index 00000000000..a71a3bef1e1
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_display_vert.glsl
@@ -0,0 +1,15 @@
+
+in vec3 pos;
+
+in int probe_id;
+in mat4 probe_mat;
+
+out vec3 worldPosition;
+flat out int probeIdx;
+
+void main()
+{
+ gl_Position = ViewProjectionMatrix * probe_mat * vec4(pos, 1.0);
+ worldPosition = (probe_mat * vec4(pos, 1.0)).xyz;
+ probeIdx = probe_id;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl
new file mode 100644
index 00000000000..d629195b815
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_frag.glsl
@@ -0,0 +1,40 @@
+/**
+ * Simple downsample shader. Takes the average of the 4 texels of lower mip.
+ **/
+
+uniform sampler2DArray source;
+uniform float fireflyFactor;
+
+in vec2 uvs;
+flat in float layer;
+
+out vec4 FragColor;
+
+float brightness(vec3 c)
+{
+ return max(max(c.r, c.g), c.b);
+}
+
+void main()
+{
+#if 0
+ /* Reconstructing Target uvs like this avoid missing pixels if NPO2 */
+ vec2 uvs = gl_FragCoord.xy * 2.0 / vec2(textureSize(source, 0));
+
+ FragColor = textureLod(source, vec3(uvs, layer), 0.0);
+#else
+ vec2 texel_size = 1.0 / vec2(textureSize(source, 0));
+ vec2 uvs = gl_FragCoord.xy * 2.0 * texel_size;
+ vec4 ofs = texel_size.xyxy * vec4(0.75, 0.75, -0.75, -0.75);
+
+ FragColor = textureLod(source, vec3(uvs + ofs.xy, layer), 0.0);
+ FragColor += textureLod(source, vec3(uvs + ofs.xw, layer), 0.0);
+ FragColor += textureLod(source, vec3(uvs + ofs.zy, layer), 0.0);
+ FragColor += textureLod(source, vec3(uvs + ofs.zw, layer), 0.0);
+ FragColor *= 0.25;
+
+ /* Clamped brightness. */
+ float luma = max(1e-8, brightness(FragColor.rgb));
+ FragColor *= 1.0 - max(0.0, luma - fireflyFactor) / luma;
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl
new file mode 100644
index 00000000000..721cc8789a0
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_geom.glsl
@@ -0,0 +1,24 @@
+
+layout(triangles) in;
+layout(triangle_strip, max_vertices=3) out;
+
+in int instance[];
+in vec2 vPos[];
+
+flat out float layer;
+
+void main() {
+ gl_Layer = instance[0];
+ layer = float(instance[0]);
+
+ gl_Position = vec4(vPos[0], 0.0, 1.0);
+ EmitVertex();
+
+ gl_Position = vec4(vPos[1], 0.0, 1.0);
+ EmitVertex();
+
+ gl_Position = vec4(vPos[2], 0.0, 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl
new file mode 100644
index 00000000000..d682e39d8ad
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_planar_downsample_vert.glsl
@@ -0,0 +1,10 @@
+
+in vec2 pos;
+
+out int instance;
+out vec2 vPos;
+
+void main() {
+ instance = gl_InstanceID;
+ vPos = pos;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lightprobe_vert.glsl b/source/blender/draw/engines/eevee/shaders/lightprobe_vert.glsl
new file mode 100644
index 00000000000..bbb77af673a
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lightprobe_vert.glsl
@@ -0,0 +1,10 @@
+
+in vec3 pos;
+
+out vec4 vPos;
+flat out int face;
+
+void main() {
+ vPos = vec4(pos, 1.0);
+ face = gl_InstanceID;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
new file mode 100644
index 00000000000..88fde8929cb
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_frag.glsl
@@ -0,0 +1,486 @@
+
+#ifndef LIT_SURFACE_UNIFORM
+#define LIT_SURFACE_UNIFORM
+
+uniform float refractionDepth;
+
+#ifndef UTIL_TEX
+#define UTIL_TEX
+uniform sampler2DArray utilTex;
+#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
+#endif /* UTIL_TEX */
+
+in vec3 worldPosition;
+in vec3 viewPosition;
+
+#ifdef USE_FLAT_NORMAL
+flat in vec3 worldNormal;
+flat in vec3 viewNormal;
+#else
+in vec3 worldNormal;
+in vec3 viewNormal;
+#endif
+
+#endif /* LIT_SURFACE_UNIFORM */
+
+/** AUTO CONFIG
+ * We include the file multiple times each time with a different configuration.
+ * This leads to a lot of deadcode. Better idea would be to only generate the one needed.
+ */
+#if !defined(SURFACE_DEFAULT)
+ #define SURFACE_DEFAULT
+ #define CLOSURE_NAME eevee_closure_default
+ #define CLOSURE_DIFFUSE
+ #define CLOSURE_GLOSSY
+#endif /* SURFACE_DEFAULT */
+
+#if !defined(SURFACE_PRINCIPLED) && !defined(CLOSURE_NAME)
+ #define SURFACE_PRINCIPLED
+ #define CLOSURE_NAME eevee_closure_principled
+ #define CLOSURE_DIFFUSE
+ #define CLOSURE_GLOSSY
+ #define CLOSURE_CLEARCOAT
+ #define CLOSURE_REFRACTION
+ #define CLOSURE_SUBSURFACE
+#endif /* SURFACE_PRINCIPLED */
+
+#if !defined(SURFACE_DIFFUSE) && !defined(CLOSURE_NAME)
+ #define SURFACE_DIFFUSE
+ #define CLOSURE_NAME eevee_closure_diffuse
+ #define CLOSURE_DIFFUSE
+#endif /* SURFACE_DIFFUSE */
+
+#if !defined(SURFACE_SUBSURFACE) && !defined(CLOSURE_NAME)
+ #define SURFACE_SUBSURFACE
+ #define CLOSURE_NAME eevee_closure_subsurface
+ #define CLOSURE_DIFFUSE
+ #define CLOSURE_SUBSURFACE
+#endif /* SURFACE_SUBSURFACE */
+
+#if !defined(SURFACE_GLOSSY) && !defined(CLOSURE_NAME)
+ #define SURFACE_GLOSSY
+ #define CLOSURE_NAME eevee_closure_glossy
+ #define CLOSURE_GLOSSY
+#endif /* SURFACE_GLOSSY */
+
+#if !defined(SURFACE_REFRACT) && !defined(CLOSURE_NAME)
+ #define SURFACE_REFRACT
+ #define CLOSURE_NAME eevee_closure_refraction
+ #define CLOSURE_REFRACTION
+#endif /* SURFACE_REFRACT */
+
+#if !defined(SURFACE_GLASS) && !defined(CLOSURE_NAME)
+ #define SURFACE_GLASS
+ #define CLOSURE_NAME eevee_closure_glass
+ #define CLOSURE_GLOSSY
+ #define CLOSURE_REFRACTION
+#endif /* SURFACE_GLASS */
+
+/* Safety : CLOSURE_CLEARCOAT implies CLOSURE_GLOSSY */
+#ifdef CLOSURE_CLEARCOAT
+ #ifndef CLOSURE_GLOSSY
+ #define CLOSURE_GLOSSY
+ #endif
+#endif /* CLOSURE_CLEARCOAT */
+
+void CLOSURE_NAME(
+ vec3 N
+#ifdef CLOSURE_DIFFUSE
+ , vec3 albedo
+#endif
+#ifdef CLOSURE_GLOSSY
+ , vec3 f0, int ssr_id
+#endif
+#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_REFRACTION)
+ , float roughness
+#endif
+#ifdef CLOSURE_CLEARCOAT
+ , vec3 C_N, float C_intensity, float C_roughness
+#endif
+#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_DIFFUSE)
+ , float ao
+#endif
+#ifdef CLOSURE_SUBSURFACE
+ , float sss_scale
+#endif
+#ifdef CLOSURE_REFRACTION
+ , float ior
+#endif
+#ifdef CLOSURE_DIFFUSE
+ , out vec3 out_diff
+#endif
+#ifdef CLOSURE_SUBSURFACE
+ , out vec3 out_trans
+#endif
+#ifdef CLOSURE_GLOSSY
+ , out vec3 out_spec
+#endif
+#ifdef CLOSURE_REFRACTION
+ , out vec3 out_refr
+#endif
+#ifdef CLOSURE_GLOSSY
+ , out vec3 ssr_spec
+#endif
+ )
+{
+#ifdef CLOSURE_DIFFUSE
+ out_diff = vec3(0.0);
+#endif
+
+#ifdef CLOSURE_SUBSURFACE
+ out_trans = vec3(0.0);
+#endif
+
+#ifdef CLOSURE_GLOSSY
+ out_spec = vec3(0.0);
+#endif
+
+#ifdef CLOSURE_REFRACTION
+ out_refr = vec3(0.0);
+#endif
+
+ /* Zero length vectors cause issues, see: T51979. */
+ float len = length(N);
+ if (isnan(len)) {
+ return;
+ }
+ N /= len;
+
+#ifdef CLOSURE_CLEARCOAT
+ len = length(C_N);
+ if (isnan(len)) {
+ return;
+ }
+ C_N /= len;
+#endif
+
+#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_REFRACTION)
+ roughness = clamp(roughness, 1e-8, 0.9999);
+ float roughnessSquared = roughness * roughness;
+#endif
+
+#ifdef CLOSURE_CLEARCOAT
+ C_roughness = clamp(C_roughness, 1e-8, 0.9999);
+ float C_roughnessSquared = C_roughness * C_roughness;
+#endif
+
+ vec3 V = cameraVec;
+
+ vec4 rand = texelFetch(utilTex, ivec3(ivec2(gl_FragCoord.xy) % LUT_SIZE, 2.0), 0);
+
+ /* ---------------------------------------------------------------- */
+ /* -------------------- SCENE LAMPS LIGHTING ---------------------- */
+ /* ---------------------------------------------------------------- */
+
+#ifdef HAIR_SHADER
+ vec3 norm_view = cross(V, N);
+ norm_view = normalize(cross(norm_view, N)); /* Normal facing view */
+#endif
+
+ for (int i = 0; i < MAX_LIGHT && i < laNumLight; ++i) {
+ LightData ld = lights_data[i];
+
+ vec4 l_vector; /* Non-Normalized Light Vector with length in last component. */
+ l_vector.xyz = ld.l_position - worldPosition;
+ l_vector.w = length(l_vector.xyz);
+
+ vec3 l_color_vis = ld.l_color * light_visibility(ld, worldPosition, viewPosition, viewNormal, l_vector);
+
+#ifdef HAIR_SHADER
+ vec3 norm_lamp, view_vec;
+ float occlu_trans, occlu;
+ light_hair_common(ld, N, V, l_vector, norm_view, occlu_trans, occlu, norm_lamp, view_vec);
+
+ #ifdef CLOSURE_DIFFUSE
+ out_diff += l_color_vis * light_diffuse(ld, -norm_lamp, V, l_vector) * occlu_trans;
+ #endif
+
+ #ifdef CLOSURE_SUBSURFACE
+ out_trans += ld.l_color * light_translucent(ld, worldPosition, -norm_lamp, l_vector, sss_scale) * occlu_trans;
+ #endif
+
+ #ifdef CLOSURE_GLOSSY
+ out_spec += l_color_vis * light_specular(ld, N, view_vec, l_vector, roughnessSquared, f0) * occlu * ld.l_spec;
+ #endif
+
+ #ifdef CLOSURE_CLEARCOAT
+ out_spec += l_color_vis * light_specular(ld, C_N, view_vec, l_vector, C_roughnessSquared, f0) * C_intensity * occlu * ld.l_spec;
+ #endif
+
+#else /* HAIR_SHADER */
+
+ #ifdef CLOSURE_DIFFUSE
+ out_diff += l_color_vis * light_diffuse(ld, N, V, l_vector);
+ #endif
+
+ #ifdef CLOSURE_SUBSURFACE
+ out_trans += ld.l_color * light_translucent(ld, worldPosition, -N, l_vector, sss_scale);
+ #endif
+
+ #ifdef CLOSURE_GLOSSY
+ out_spec += l_color_vis * light_specular(ld, N, V, l_vector, roughnessSquared, f0) * ld.l_spec;
+ #endif
+
+ #ifdef CLOSURE_CLEARCOAT
+ out_spec += l_color_vis * light_specular(ld, C_N, V, l_vector, C_roughnessSquared, f0) * C_intensity * ld.l_spec;
+ #endif
+
+#endif /* HAIR_SHADER */
+ }
+
+#ifdef HAIR_SHADER
+ N = -norm_view;
+#endif
+
+
+
+ /* ---------------------------------------------------------------- */
+ /* ---------------- SPECULAR ENVIRONMENT LIGHTING ----------------- */
+ /* ---------------------------------------------------------------- */
+
+ /* Accumulate incomming light from all sources until accumulator is full. Then apply Occlusion and BRDF. */
+#ifdef CLOSURE_GLOSSY
+ vec4 spec_accum = vec4(0.0);
+#endif
+
+#ifdef CLOSURE_CLEARCOAT
+ vec4 C_spec_accum = vec4(0.0);
+#endif
+
+#ifdef CLOSURE_REFRACTION
+ vec4 refr_accum = vec4(0.0);
+#endif
+
+#ifdef CLOSURE_GLOSSY
+ /* ---------------------------- */
+ /* Planar Reflections */
+ /* ---------------------------- */
+
+ for (int i = 0; i < MAX_PLANAR && i < prbNumPlanar && spec_accum.a < 0.999; ++i) {
+ PlanarData pd = planars_data[i];
+
+ /* Fade on geometric normal. */
+ float fade = probe_attenuation_planar(pd, worldPosition, worldNormal, roughness);
+
+ if (fade > 0.0) {
+ if (!(ssrToggle && ssr_id == outputSsrId)) {
+ vec3 spec = probe_evaluate_planar(float(i), pd, worldPosition, N, V, roughness, fade);
+ accumulate_light(spec, fade, spec_accum);
+ }
+
+ #ifdef CLOSURE_CLEARCOAT
+ vec3 C_spec = probe_evaluate_planar(float(i), pd, worldPosition, C_N, V, C_roughness, fade);
+ accumulate_light(C_spec, fade, C_spec_accum);
+ #endif
+
+ }
+ }
+#endif
+
+
+#ifdef CLOSURE_GLOSSY
+ vec3 spec_dir = get_specular_reflection_dominant_dir(N, V, roughnessSquared);
+#endif
+
+#ifdef CLOSURE_CLEARCOAT
+ vec3 C_spec_dir = get_specular_reflection_dominant_dir(C_N, V, C_roughnessSquared);
+#endif
+
+#ifdef CLOSURE_REFRACTION
+ /* Refract the view vector using the depth heuristic.
+ * Then later Refract a second time the already refracted
+ * ray using the inverse ior. */
+ float final_ior = (refractionDepth > 0.0) ? 1.0 / ior : ior;
+ vec3 refr_V = (refractionDepth > 0.0) ? -refract(-V, N, final_ior) : V;
+ vec3 refr_pos = (refractionDepth > 0.0) ? line_plane_intersect(worldPosition, refr_V, worldPosition - N * refractionDepth, N) : worldPosition;
+ vec3 refr_dir = get_specular_refraction_dominant_dir(N, refr_V, roughness, final_ior);
+#endif
+
+
+#ifdef CLOSURE_REFRACTION
+ /* ---------------------------- */
+ /* Screen Space Refraction */
+ /* ---------------------------- */
+ #ifdef USE_REFRACTION
+ if (ssrToggle && roughness < ssrMaxRoughness + 0.2) {
+ /* Find approximated position of the 2nd refraction event. */
+ vec3 refr_vpos = (refractionDepth > 0.0) ? transform_point(ViewMatrix, refr_pos) : viewPosition;
+ vec4 trans = screen_space_refraction(refr_vpos, N, refr_V, final_ior, roughnessSquared, rand);
+ trans.a *= smoothstep(ssrMaxRoughness + 0.2, ssrMaxRoughness, roughness);
+ accumulate_light(trans.rgb, trans.a, refr_accum);
+ }
+ #endif
+
+#endif
+
+
+ /* ---------------------------- */
+ /* Specular probes */
+ /* ---------------------------- */
+#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_REFRACTION)
+
+ #ifdef CLOSURE_REFRACTION
+ #define ACCUM refr_accum
+ #else
+ #define ACCUM spec_accum
+ #endif
+
+ /* Starts at 1 because 0 is world probe */
+ for (int i = 1; ACCUM.a < 0.999 && i < prbNumRenderCube && i < MAX_PROBE; ++i) {
+ CubeData cd = probes_data[i];
+
+ float fade = probe_attenuation_cube(cd, worldPosition);
+
+ if (fade > 0.0) {
+
+ #ifdef CLOSURE_GLOSSY
+ if (!(ssrToggle && ssr_id == outputSsrId)) {
+ vec3 spec = probe_evaluate_cube(float(i), cd, worldPosition, spec_dir, roughness);
+ accumulate_light(spec, fade, spec_accum);
+ }
+ #endif
+
+ #ifdef CLOSURE_CLEARCOAT
+ vec3 C_spec = probe_evaluate_cube(float(i), cd, worldPosition, C_spec_dir, C_roughness);
+ accumulate_light(C_spec, fade, C_spec_accum);
+ #endif
+
+ #ifdef CLOSURE_REFRACTION
+ vec3 trans = probe_evaluate_cube(float(i), cd, refr_pos, refr_dir, roughnessSquared);
+ accumulate_light(trans, fade, refr_accum);
+ #endif
+ }
+ }
+
+ #undef ACCUM
+
+ /* ---------------------------- */
+ /* World Probe */
+ /* ---------------------------- */
+ #ifdef CLOSURE_GLOSSY
+ if (spec_accum.a < 0.999) {
+ if (!(ssrToggle && ssr_id == outputSsrId)) {
+ vec3 spec = probe_evaluate_world_spec(spec_dir, roughness);
+ accumulate_light(spec, 1.0, spec_accum);
+ }
+
+ #ifdef CLOSURE_CLEARCOAT
+ vec3 C_spec = probe_evaluate_world_spec(C_spec_dir, C_roughness);
+ accumulate_light(C_spec, 1.0, C_spec_accum);
+ #endif
+
+ }
+ #endif
+
+ #ifdef CLOSURE_REFRACTION
+ if (refr_accum.a < 0.999) {
+ vec3 trans = probe_evaluate_world_spec(refr_dir, roughnessSquared);
+ accumulate_light(trans, 1.0, refr_accum);
+ }
+ #endif
+#endif /* Specular probes */
+
+
+ /* ---------------------------- */
+ /* Ambient Occlusion */
+ /* ---------------------------- */
+#if defined(CLOSURE_GLOSSY) || defined(CLOSURE_DIFFUSE)
+ vec3 bent_normal;
+ float final_ao = occlusion_compute(N, viewPosition, ao, rand, bent_normal);
+#endif
+
+
+ /* ---------------------------- */
+ /* Specular Output */
+ /* ---------------------------- */
+ float NV = dot(N, V);
+#ifdef CLOSURE_GLOSSY
+ vec2 uv = lut_coords(NV, roughness);
+ vec2 brdf_lut = texture(utilTex, vec3(uv, 1.0)).rg;
+
+ /* This factor is outputed to be used by SSR in order
+ * to match the intensity of the regular reflections. */
+ ssr_spec = F_ibl(f0, brdf_lut);
+ float spec_occlu = specular_occlusion(NV, final_ao, roughness);
+
+ /* The SSR pass recompute the occlusion to not apply it to the SSR */
+ if (ssrToggle && ssr_id == outputSsrId) {
+ spec_occlu = 1.0;
+ }
+
+ out_spec += spec_accum.rgb * ssr_spec * spec_occlu * float(specToggle);
+#endif
+
+#ifdef CLOSURE_REFRACTION
+ float btdf = get_btdf_lut(utilTex, NV, roughness, ior);
+
+ out_refr += refr_accum.rgb * btdf;
+#endif
+
+#ifdef CLOSURE_CLEARCOAT
+ NV = dot(C_N, V);
+ vec2 C_uv = lut_coords(NV, C_roughness);
+ vec2 C_brdf_lut = texture(utilTex, vec3(C_uv, 1.0)).rg;
+ vec3 C_fresnel = F_ibl(vec3(0.04), brdf_lut) * specular_occlusion(NV, final_ao, C_roughness);
+
+ out_spec += C_spec_accum.rgb * C_fresnel * float(specToggle) * C_intensity;
+#endif
+
+ /* ---------------------------------------------------------------- */
+ /* ---------------- DIFFUSE ENVIRONMENT LIGHTING ------------------ */
+ /* ---------------------------------------------------------------- */
+
+ /* Accumulate light from all sources until accumulator is full. Then apply Occlusion and BRDF. */
+#ifdef CLOSURE_DIFFUSE
+ vec4 diff_accum = vec4(0.0);
+
+ /* ---------------------------- */
+ /* Irradiance Grids */
+ /* ---------------------------- */
+ /* Start at 1 because 0 is world irradiance */
+ for (int i = 1; i < MAX_GRID && i < prbNumRenderGrid && diff_accum.a < 0.999; ++i) {
+ GridData gd = grids_data[i];
+
+ vec3 localpos;
+ float fade = probe_attenuation_grid(gd, worldPosition, localpos);
+
+ if (fade > 0.0) {
+ vec3 diff = probe_evaluate_grid(gd, worldPosition, bent_normal, localpos);
+ accumulate_light(diff, fade, diff_accum);
+ }
+ }
+
+ /* ---------------------------- */
+ /* World Diffuse */
+ /* ---------------------------- */
+ if (diff_accum.a < 0.999 && prbNumRenderGrid > 0) {
+ vec3 diff = probe_evaluate_world_diff(bent_normal);
+ accumulate_light(diff, 1.0, diff_accum);
+ }
+
+ out_diff += diff_accum.rgb * gtao_multibounce(final_ao, albedo);
+#endif
+}
+
+/* Cleanup for next configuration */
+#undef CLOSURE_NAME
+
+#ifdef CLOSURE_DIFFUSE
+ #undef CLOSURE_DIFFUSE
+#endif
+
+#ifdef CLOSURE_GLOSSY
+ #undef CLOSURE_GLOSSY
+#endif
+
+#ifdef CLOSURE_CLEARCOAT
+ #undef CLOSURE_CLEARCOAT
+#endif
+
+#ifdef CLOSURE_REFRACTION
+ #undef CLOSURE_REFRACTION
+#endif
+
+#ifdef CLOSURE_SUBSURFACE
+ #undef CLOSURE_SUBSURFACE
+#endif \ No newline at end of file
diff --git a/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
new file mode 100644
index 00000000000..cbc4c80e59b
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/lit_surface_vert.glsl
@@ -0,0 +1,43 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ModelMatrix;
+uniform mat4 ModelViewMatrix;
+uniform mat3 WorldNormalMatrix;
+#ifndef ATTRIB
+uniform mat3 NormalMatrix;
+#endif
+
+in vec3 pos;
+in vec3 nor;
+
+out vec3 worldPosition;
+out vec3 viewPosition;
+
+/* Used for planar reflections */
+/* keep in sync with EEVEE_ClipPlanesUniformBuffer */
+layout(std140) uniform clip_block {
+ vec4 ClipPlanes[1];
+};
+
+#ifdef USE_FLAT_NORMAL
+flat out vec3 worldNormal;
+flat out vec3 viewNormal;
+#else
+out vec3 worldNormal;
+out vec3 viewNormal;
+#endif
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
+ worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
+ viewNormal = normalize(NormalMatrix * nor);
+ worldNormal = normalize(WorldNormalMatrix * nor);
+
+ /* Used for planar reflections */
+ gl_ClipDistance[0] = dot(vec4(worldPosition, 1.0), ClipPlanes[0]);
+
+#ifdef ATTRIB
+ pass_attrib(pos);
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl b/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl
new file mode 100644
index 00000000000..5c62cb19152
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/ltc_lib.glsl
@@ -0,0 +1,322 @@
+/**
+ * Adapted from :
+ * Real-Time Polygonal-Light Shading with Linearly Transformed Cosines.
+ * Eric Heitz, Jonathan Dupuy, Stephen Hill and David Neubelt.
+ * ACM Transactions on Graphics (Proceedings of ACM SIGGRAPH 2016) 35(4), 2016.
+ * Project page: https://eheitzresearch.wordpress.com/415-2/
+ **/
+
+#define USE_LTC
+
+#ifndef UTIL_TEX
+#define UTIL_TEX
+uniform sampler2DArray utilTex;
+#define texelfetch_noise_tex(coord) texelFetch(utilTex, ivec3(ivec2(coord) % LUT_SIZE, 2.0), 0)
+#endif /* UTIL_TEX */
+
+/* Diffuse *clipped* sphere integral. */
+float diffuse_sphere_integral_lut(float avg_dir_z, float form_factor)
+{
+ vec2 uv = vec2(avg_dir_z * 0.5 + 0.5, form_factor);
+ uv = uv * (LUT_SIZE - 1.0) / LUT_SIZE + 0.5 / LUT_SIZE;
+
+ return texture(utilTex, vec3(uv, 1.0)).w;
+}
+
+float diffuse_sphere_integral_cheap(float avg_dir_z, float form_factor)
+{
+ return max((form_factor * form_factor + avg_dir_z) / (form_factor + 1.0), 0.0);
+}
+
+/**
+ * An extended version of the implementation from
+ * "How to solve a cubic equation, revisited"
+ * http://momentsingraphics.de/?p=105
+ **/
+vec3 solve_cubic(vec4 coefs)
+{
+ /* Normalize the polynomial */
+ coefs.xyz /= coefs.w;
+ /* Divide middle coefficients by three */
+ coefs.yz /= 3.0;
+
+ float A = coefs.w;
+ float B = coefs.z;
+ float C = coefs.y;
+ float D = coefs.x;
+
+ /* Compute the Hessian and the discriminant */
+ vec3 delta = vec3(
+ -coefs.z*coefs.z + coefs.y,
+ -coefs.y*coefs.z + coefs.x,
+ dot(vec2(coefs.z, -coefs.y), coefs.xy)
+ );
+
+ /* Discriminant */
+ float discr = dot(vec2(4.0 * delta.x, -delta.y), delta.zy);
+
+ vec2 xlc, xsc;
+
+ /* Algorithm A */
+ {
+ float A_a = 1.0;
+ float C_a = delta.x;
+ float D_a = -2.0 * B * delta.x + delta.y;
+
+ /* Take the cubic root of a normalized complex number */
+ float theta = atan(sqrt(discr), -D_a) / 3.0;
+
+ float x_1a = 2.0 * sqrt(-C_a) * cos(theta);
+ float x_3a = 2.0 * sqrt(-C_a) * cos(theta + (2.0 / 3.0) * M_PI);
+
+ float xl;
+ if ((x_1a + x_3a) > 2.0 * B) {
+ xl = x_1a;
+ }
+ else {
+ xl = x_3a;
+ }
+
+ xlc = vec2(xl - B, A);
+ }
+
+ /* Algorithm D */
+ {
+ float A_d = D;
+ float C_d = delta.z;
+ float D_d = -D * delta.y + 2.0 * C * delta.z;
+
+ /* Take the cubic root of a normalized complex number */
+ float theta = atan(D * sqrt(discr), -D_d) / 3.0;
+
+ float x_1d = 2.0 * sqrt(-C_d) * cos(theta);
+ float x_3d = 2.0 * sqrt(-C_d) * cos(theta + (2.0 / 3.0) * M_PI);
+
+ float xs;
+ if (x_1d + x_3d < 2.0 * C)
+ xs = x_1d;
+ else
+ xs = x_3d;
+
+ xsc = vec2(-D, xs + C);
+ }
+
+ float E = xlc.y * xsc.y;
+ float F = -xlc.x * xsc.y - xlc.y * xsc.x;
+ float G = xlc.x * xsc.x;
+
+ vec2 xmc = vec2(C * F - B * G, -B * F + C * E);
+
+ vec3 root = vec3(xsc.x / xsc.y,
+ xmc.x / xmc.y,
+ xlc.x / xlc.y);
+
+ if (root.x < root.y && root.x < root.z) {
+ root.xyz = root.yxz;
+ }
+ else if (root.z < root.x && root.z < root.y) {
+ root.xyz = root.xzy;
+ }
+
+ return root;
+}
+
+/* from Real-Time Area Lighting: a Journey from Research to Production
+ * Stephen Hill and Eric Heitz */
+vec3 edge_integral_vec(vec3 v1, vec3 v2)
+{
+ float x = dot(v1, v2);
+ float y = abs(x);
+
+ float a = 0.8543985 + (0.4965155 + 0.0145206 * y) * y;
+ float b = 3.4175940 + (4.1616724 + y) * y;
+ float v = a / b;
+
+ float theta_sintheta = (x > 0.0) ? v : 0.5 * inversesqrt(max(1.0 - x * x, 1e-7)) - v;
+
+ return cross(v1, v2) * theta_sintheta;
+}
+
+mat3 ltc_matrix(vec4 lut)
+{
+ /* load inverse matrix */
+ mat3 Minv = mat3(
+ vec3( 1, 0, lut.y),
+ vec3( 0, lut.z, 0),
+ vec3(lut.w, 0, lut.x)
+ );
+
+ return Minv;
+}
+
+void ltc_transform_quad(vec3 N, vec3 V, mat3 Minv, inout vec3 corners[4])
+{
+ /* Avoid dot(N, V) == 1 in ortho mode, leading T1 normalize to fail. */
+ V = normalize(V + 1e-8);
+
+ /* construct orthonormal basis around N */
+ vec3 T1, T2;
+ T1 = normalize(V - N * dot(N, V));
+ T2 = cross(N, T1);
+
+ /* rotate area light in (T1, T2, R) basis */
+ Minv = Minv * transpose(mat3(T1, T2, N));
+
+ /* Apply LTC inverse matrix. */
+ corners[0] = normalize(Minv * corners[0]);
+ corners[1] = normalize(Minv * corners[1]);
+ corners[2] = normalize(Minv * corners[2]);
+ corners[3] = normalize(Minv * corners[3]);
+}
+
+/* If corners have already pass through ltc_transform_quad(), then N **MUST** be vec3(0.0, 0.0, 1.0),
+ * corresponding to the Up axis of the shading basis. */
+float ltc_evaluate_quad(vec3 corners[4], vec3 N)
+{
+ /* Approximation using a sphere of the same solid angle than the quad.
+ * Finding the clipped sphere diffuse integral is easier than clipping the quad. */
+ vec3 avg_dir;
+ avg_dir = edge_integral_vec(corners[0], corners[1]);
+ avg_dir += edge_integral_vec(corners[1], corners[2]);
+ avg_dir += edge_integral_vec(corners[2], corners[3]);
+ avg_dir += edge_integral_vec(corners[3], corners[0]);
+
+ float form_factor = length(avg_dir);
+ float avg_dir_z = dot(N, avg_dir / form_factor);
+
+#if 1 /* use tabulated horizon-clipped sphere */
+ return form_factor * diffuse_sphere_integral_lut(avg_dir_z, form_factor);
+#else /* Less accurate version, a bit cheaper. */
+ return form_factor * diffuse_sphere_integral_cheap(avg_dir_z, form_factor);
+#endif
+}
+
+/* If disk does not need to be transformed and is already front facing. */
+float ltc_evaluate_disk_simple(float disk_radius, float NL)
+{
+ float r_sqr = disk_radius * disk_radius;
+ float one_r_sqr = 1.0 + r_sqr;
+ float form_factor = r_sqr * inversesqrt(one_r_sqr * one_r_sqr);
+
+#if 1 /* use tabulated horizon-clipped sphere */
+ return form_factor * diffuse_sphere_integral_lut(NL, form_factor);
+#else /* Less accurate version, a bit cheaper. */
+ return form_factor * diffuse_sphere_integral_cheap(NL, form_factor);
+#endif
+}
+
+/* disk_points are WS vectors from the shading point to the disk "bounding domain" */
+float ltc_evaluate_disk(vec3 N, vec3 V, mat3 Minv, vec3 disk_points[3])
+{
+ /* Avoid dot(N, V) == 1 in ortho mode, leading T1 normalize to fail. */
+ V = normalize(V + 1e-8);
+
+ /* construct orthonormal basis around N */
+ vec3 T1, T2;
+ T1 = normalize(V - N * dot(V, N));
+ T2 = cross(N, T1);
+
+ /* rotate area light in (T1, T2, R) basis */
+ mat3 R = transpose(mat3(T1, T2, N));
+
+ /* Intermediate step: init ellipse. */
+ vec3 L_[3];
+ L_[0] = mul(R, disk_points[0]);
+ L_[1] = mul(R, disk_points[1]);
+ L_[2] = mul(R, disk_points[2]);
+
+ vec3 C = 0.5 * (L_[0] + L_[2]);
+ vec3 V1 = 0.5 * (L_[1] - L_[2]);
+ vec3 V2 = 0.5 * (L_[1] - L_[0]);
+
+ /* Transform ellipse by Minv. */
+ C = Minv * C;
+ V1 = Minv * V1;
+ V2 = Minv * V2;
+
+ /* Compute eigenvectors of new ellipse. */
+
+ float d11 = dot(V1, V1);
+ float d22 = dot(V2, V2);
+ float d12 = dot(V1, V2);
+ float a, b; /* Eigenvalues */
+ const float threshold = 0.0007; /* Can be adjusted. Fix artifacts. */
+ if (abs(d12) / sqrt(d11 * d22) > threshold) {
+ float tr = d11 + d22;
+ float det = -d12 * d12 + d11 * d22;
+
+ /* use sqrt matrix to solve for eigenvalues */
+ det = sqrt(det);
+ float u = 0.5 * sqrt(tr - 2.0 * det);
+ float v = 0.5 * sqrt(tr + 2.0 * det);
+ float e_max = (u + v);
+ float e_min = (u - v);
+ e_max *= e_max;
+ e_min *= e_min;
+
+ vec3 V1_, V2_;
+ if (d11 > d22) {
+ V1_ = d12 * V1 + (e_max - d11) * V2;
+ V2_ = d12 * V1 + (e_min - d11) * V2;
+ }
+ else {
+ V1_ = d12 * V2 + (e_max - d22) * V1;
+ V2_ = d12 * V2 + (e_min - d22) * V1;
+ }
+
+ a = 1.0 / e_max;
+ b = 1.0 / e_min;
+ V1 = normalize(V1_);
+ V2 = normalize(V2_);
+ }
+ else {
+ a = 1.0 / d11;
+ b = 1.0 / d22;
+ V1 *= sqrt(a);
+ V2 *= sqrt(b);
+ }
+
+ /* Now find front facing ellipse with same solid angle. */
+
+ vec3 V3 = normalize(cross(V1, V2));
+ if (dot(C, V3) < 0.0)
+ V3 *= -1.0;
+
+ float L = dot(V3, C);
+ float x0 = dot(V1, C) / L;
+ float y0 = dot(V2, C) / L;
+
+ a *= L*L;
+ b *= L*L;
+
+ float c0 = a * b;
+ float c1 = a * b * (1.0 + x0 * x0 + y0 * y0) - a - b;
+ float c2 = 1.0 - a * (1.0 + x0 * x0) - b * (1.0 + y0 * y0);
+ float c3 = 1.0;
+
+ vec3 roots = solve_cubic(vec4(c0, c1, c2, c3));
+ float e1 = roots.x;
+ float e2 = roots.y;
+ float e3 = roots.z;
+
+ vec3 avg_dir = vec3(a * x0 / (a - e2), b * y0 / (b - e2), 1.0);
+
+ mat3 rotate = mat3(V1, V2, V3);
+
+ avg_dir = rotate * avg_dir;
+ avg_dir = normalize(avg_dir);
+
+ /* L1, L2 are the extends of the front facing ellipse. */
+ float L1 = sqrt(-e2/e3);
+ float L2 = sqrt(-e2/e1);
+
+ /* Find the sphere and compute lighting. */
+ float form_factor = max(0.0, L1 * L2 * inversesqrt((1.0 + L1 * L1) * (1.0 + L2 * L2)));
+
+#if 1 /* use tabulated horizon-clipped sphere */
+ return form_factor * diffuse_sphere_integral_lut(avg_dir.z, form_factor);
+#else /* Less accurate version, a bit cheaper. */
+ return form_factor * diffuse_sphere_integral_cheap(avg_dir.z, form_factor);
+#endif
+}
+
diff --git a/source/blender/draw/engines/eevee/shaders/octahedron_lib.glsl b/source/blender/draw/engines/eevee/shaders/octahedron_lib.glsl
new file mode 100644
index 00000000000..631b325ae37
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/octahedron_lib.glsl
@@ -0,0 +1,38 @@
+
+vec2 mapping_octahedron(vec3 cubevec, vec2 texel_size)
+{
+ /* projection onto octahedron */
+ cubevec /= dot( vec3(1), abs(cubevec) );
+
+ /* out-folding of the downward faces */
+ if ( cubevec.z < 0.0 ) {
+ cubevec.xy = (1.0 - abs(cubevec.yx)) * sign(cubevec.xy);
+ }
+
+ /* mapping to [0;1]ˆ2 texture space */
+ vec2 uvs = cubevec.xy * (0.5) + 0.5;
+
+ /* edge filtering fix */
+ uvs *= 1.0 - 2.0 * texel_size;
+ uvs += texel_size;
+
+ return uvs;
+}
+
+vec4 textureLod_octahedron(sampler2DArray tex, vec4 cubevec, float lod, float lod_max)
+{
+ vec2 texelSize = 1.0 / vec2(textureSize(tex, int(lod_max)));
+
+ vec2 uvs = mapping_octahedron(cubevec.xyz, texelSize);
+
+ return textureLod(tex, vec3(uvs, cubevec.w), lod);
+}
+
+vec4 texture_octahedron(sampler2DArray tex, vec4 cubevec)
+{
+ vec2 texelSize = 1.0 / vec2(textureSize(tex, 0));
+
+ vec2 uvs = mapping_octahedron(cubevec.xyz, texelSize);
+
+ return texture(tex, vec3(uvs, cubevec.w));
+}
diff --git a/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl b/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl
new file mode 100644
index 00000000000..1c0e65f0613
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/prepass_frag.glsl
@@ -0,0 +1,87 @@
+
+#ifdef USE_ALPHA_HASH
+
+/* From the paper "Hashed Alpha Testing" by Chris Wyman and Morgan McGuire */
+float hash(vec2 a) {
+ return fract(1e4 * sin(17.0 * a.x + 0.1 * a.y) * (0.1 + abs(sin(13.0 * a.y + a.x))));
+}
+
+float hash3d(vec3 a) {
+ return hash(vec2(hash(a.xy), a.z));
+}
+
+uniform float hashAlphaOffset;
+
+float hashed_alpha_threshold(vec3 co)
+{
+ const float hash_scale = 1.0; /* Roughly in pixel */
+
+ /* Find the discretized derivatives of our coordinates. */
+ float max_deriv = max(length(dFdx(co)), length(dFdy(co)));
+ float pix_scale = 1.0 / (hash_scale * max_deriv);
+
+ /* Find two nearest log-discretized noise scales. */
+ float pix_scale_log = log2(pix_scale);
+ vec2 pix_scales;
+ pix_scales.x = exp2(floor(pix_scale_log));
+ pix_scales.y = exp2(ceil(pix_scale_log));
+
+ /* Compute alpha thresholds at our two noise scales. */
+ vec2 alpha;
+ alpha.x = hash3d(floor(pix_scales.x * co));
+ alpha.y = hash3d(floor(pix_scales.y * co));
+
+ /* Factor to interpolate lerp with. */
+ float fac = fract(log2(pix_scale));
+
+ /* Interpolate alpha threshold from noise at two scales. */
+ float x = mix(alpha.x, alpha.y, fac);
+
+ /* Pass into CDF to compute uniformly distrib threshold. */
+ float a = min(fac, 1.0 - fac);
+ float one_a = 1.0 - a;
+ float denom = 1.0 / (2 * a * one_a);
+ float one_x = (1 - x);
+ vec3 cases = vec3(
+ (x * x) * denom,
+ (x - 0.5 * a) / one_a,
+ 1.0 - (one_x * one_x * denom)
+ );
+
+ /* Find our final, uniformly distributed alpha threshold. */
+ float threshold = (x < one_a) ? ((x < a) ? cases.x : cases.y) : cases.z;
+
+ /* Avoids threshold == 0. */
+ threshold = clamp(threshold, 1.0e-6, 1.0);
+
+ /* Jitter the threshold for TAA accumulation. */
+ return fract(threshold + hashAlphaOffset);
+}
+
+#endif
+
+#ifdef USE_ALPHA_CLIP
+uniform float alphaThreshold;
+#endif
+
+void main()
+{
+ /* For now do nothing.
+ * In the future, output object motion blur. */
+
+#if defined(USE_ALPHA_HASH) || defined(USE_ALPHA_CLIP)
+#define NODETREE_EXEC
+
+ Closure cl = nodetree_exec();
+
+#if defined(USE_ALPHA_HASH)
+ /* Hashed Alpha Testing */
+ if (cl.opacity < hashed_alpha_threshold(worldPosition))
+ discard;
+#elif defined(USE_ALPHA_CLIP)
+ /* Alpha clip */
+ if (cl.opacity <= alphaThreshold)
+ discard;
+#endif
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl b/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl
new file mode 100644
index 00000000000..c756e061d70
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/prepass_vert.glsl
@@ -0,0 +1,20 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ModelMatrix;
+
+/* keep in sync with DRWManager.view_data */
+layout(std140) uniform clip_block {
+ vec4 ClipPlanes[1];
+};
+
+in vec3 pos;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+#ifdef CLIP_PLANES
+ vec4 worldPosition = (ModelMatrix * vec4(pos, 1.0));
+ gl_ClipDistance[0] = dot(vec4(worldPosition.xyz, 1.0), ClipPlanes[0]);
+#endif
+ /* TODO motion vectors */
+}
diff --git a/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
new file mode 100644
index 00000000000..aa1dda6b3b5
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/raytrace_lib.glsl
@@ -0,0 +1,239 @@
+#define MAX_STEP 256
+
+float sample_depth(vec2 uv, int index, float lod)
+{
+#ifdef PLANAR_PROBE_RAYTRACE
+ if (index > -1) {
+ return textureLod(planarDepth, vec3(uv, index), 0.0).r;
+ }
+ else {
+#endif
+ /* Correct UVs for mipmaping mis-alignment */
+ /* + 1.0 because we are using half res maxzBuffer
+ * and mipRatio starts at on mip 0. */
+ int mip = int(lod + 1.0);
+ uv *= mipRatio[mip];
+ return textureLod(maxzBuffer, uv, lod).r;
+#ifdef PLANAR_PROBE_RAYTRACE
+ }
+#endif
+}
+
+vec4 sample_depth_grouped(vec4 uv1, vec4 uv2, int index, float lod)
+{
+ vec4 depths;
+#ifdef PLANAR_PROBE_RAYTRACE
+ if (index > -1) {
+ depths.x = textureLod(planarDepth, vec3(uv1.xy, index), 0.0).r;
+ depths.y = textureLod(planarDepth, vec3(uv1.zw, index), 0.0).r;
+ depths.z = textureLod(planarDepth, vec3(uv2.xy, index), 0.0).r;
+ depths.w = textureLod(planarDepth, vec3(uv2.zw, index), 0.0).r;
+ }
+ else {
+#endif
+ depths.x = textureLod(maxzBuffer, uv1.xy, lod).r;
+ depths.y = textureLod(maxzBuffer, uv1.zw, lod).r;
+ depths.z = textureLod(maxzBuffer, uv2.xy, lod).r;
+ depths.w = textureLod(maxzBuffer, uv2.zw, lod).r;
+#ifdef PLANAR_PROBE_RAYTRACE
+ }
+#endif
+ return depths;
+}
+
+float refine_isect(float prev_delta, float curr_delta)
+{
+ /**
+ * Simplification of 2D intersection :
+ * r0 = (0.0, prev_ss_ray.z);
+ * r1 = (1.0, curr_ss_ray.z);
+ * d0 = (0.0, prev_hit_depth_sample);
+ * d1 = (1.0, curr_hit_depth_sample);
+ * vec2 r = r1 - r0;
+ * vec2 d = d1 - d0;
+ * vec2 isect = ((d * cross(r1, r0)) - (r * cross(d1, d0))) / cross(r,d);
+ *
+ * We only want isect.x to know how much stride we need. So it simplifies :
+ *
+ * isect_x = (cross(r1, r0) - cross(d1, d0)) / cross(r,d);
+ * isect_x = (prev_ss_ray.z - prev_hit_depth_sample.z) / cross(r,d);
+ */
+ return saturate(prev_delta / (prev_delta - curr_delta));
+}
+
+void prepare_raycast(vec3 ray_origin, vec3 ray_dir, float thickness, out vec4 ss_step, out vec4 ss_ray, out float max_time)
+{
+ /* Negate the ray direction if it goes towards the camera.
+ * This way we don't need to care if the projected point
+ * is behind the near plane. */
+ float z_sign = -sign(ray_dir.z);
+ vec3 ray_end = ray_origin + z_sign * ray_dir;
+
+ /* Project into screen space. */
+ vec4 ss_start, ss_end;
+ ss_start.xyz = project_point(ProjectionMatrix, ray_origin);
+ ss_end.xyz = project_point(ProjectionMatrix, ray_end);
+
+ /* We interpolate the ray Z + thickness values to check if depth is within threshold. */
+ ray_origin.z -= thickness;
+ ray_end.z -= thickness;
+ ss_start.w = project_point(ProjectionMatrix, ray_origin).z;
+ ss_end.w = project_point(ProjectionMatrix, ray_end).z;
+
+ /* XXX This is a hack a better method is welcome ! */
+ /* We take the delta between the offseted depth and the depth and substract it from the ray depth.
+ * This will change the world space thickness appearance a bit but we can have negative
+ * values without worries. We cannot do this in viewspace because of the perspective division. */
+ ss_start.w = 2.0 * ss_start.z - ss_start.w;
+ ss_end.w = 2.0 * ss_end.z - ss_end.w;
+
+ ss_step = ss_end - ss_start;
+ max_time = length(ss_step.xyz);
+ ss_step = z_sign * ss_step / length(ss_step.xyz);
+
+ /* If the line is degenerate, make it cover at least one pixel
+ * to not have to handle zero-pixel extent as a special case later */
+ ss_step.xy += vec2((dot(ss_step.xy, ss_step.xy) < 0.000001) ? 0.001 : 0.0);
+
+ /* Make ss_step cover one pixel. */
+ ss_step /= max(abs(ss_step.x), abs(ss_step.y));
+ ss_step *= (abs(ss_step.x) > abs(ss_step.y)) ? ssrPixelSize.x : ssrPixelSize.y;
+
+ /* Clip to segment's end. */
+ max_time /= length(ss_step.xyz);
+
+ /* Clipping to frustum sides. */
+ max_time = min(max_time, line_unit_box_intersect_dist(ss_start.xyz, ss_step.xyz));
+
+ /* Convert to texture coords. Z component included
+ * since this is how it's stored in the depth buffer.
+ * 4th component how far we are on the ray */
+ ss_ray = ss_start * 0.5 + 0.5;
+ ss_step *= 0.5;
+
+ ss_ray.xy += 0.5 * ssrPixelSize * 2.0; /* take the center of the texel. * 2 because halfres. */
+}
+
+/* See times_and_deltas. */
+#define curr_time times_and_deltas.x
+#define prev_time times_and_deltas.y
+#define curr_delta times_and_deltas.z
+#define prev_delta times_and_deltas.w
+
+// #define GROUPED_FETCHES /* is still slower, need to see where is the bottleneck. */
+/* Return the hit position, and negate the z component (making it positive) if not hit occured. */
+/* __ray_dir__ is the ray direction premultiplied by it's maximum length */
+vec3 raycast(
+ int index, vec3 ray_origin, vec3 ray_dir, float thickness, float ray_jitter,
+ float trace_quality, float roughness, const bool discard_backface)
+{
+ vec4 ss_step, ss_start;
+ float max_time;
+ prepare_raycast(ray_origin, ray_dir, thickness, ss_step, ss_start, max_time);
+
+ float max_trace_time = max(0.001, max_time - 0.01);
+
+#ifdef GROUPED_FETCHES
+ ray_jitter *= 0.25;
+#endif
+
+ /* x : current_time, y: previous_time, z: current_delta, w: previous_delta */
+ vec4 times_and_deltas = vec4(0.0);
+
+ float ray_time = 0.0;
+ float depth_sample = sample_depth(ss_start.xy, index, 0.0);
+ curr_delta = depth_sample - ss_start.z;
+
+ float lod_fac = saturate(fast_sqrt(roughness) * 2.0 - 0.4);
+ bool hit = false;
+ float iter;
+ for (iter = 1.0; !hit && (ray_time < max_time) && (iter < MAX_STEP); iter++) {
+ /* Minimum stride of 2 because we are using half res minmax zbuffer. */
+ float stride = max(1.0, iter * trace_quality) * 2.0;
+ float lod = log2(stride * 0.5 * trace_quality) * lod_fac;
+ ray_time += stride;
+
+ /* Save previous values. */
+ times_and_deltas.xyzw = times_and_deltas.yxwz;
+
+#ifdef GROUPED_FETCHES
+ stride *= 4.0;
+ vec4 jit_stride = mix(vec4(2.0), vec4(stride), vec4(0.0, 0.25, 0.5, 0.75) + ray_jitter);
+
+ vec4 times = min(vec4(ray_time) + jit_stride, vec4(max_trace_time));
+
+ vec4 uv1 = ss_start.xyxy + ss_step.xyxy * times.xxyy;
+ vec4 uv2 = ss_start.xyxy + ss_step.xyxy * times.zzww;
+
+ vec4 depth_samples = sample_depth_grouped(uv1, uv2, index, lod);
+
+ vec4 ray_z = ss_start.zzzz + ss_step.zzzz * times.xyzw;
+ vec4 ray_w = ss_start.wwww + ss_step.wwww * vec4(prev_time, times.xyz);
+
+ vec4 deltas = depth_samples - ray_z;
+ /* Same as component wise (curr_delta <= 0.0) && (prev_w <= depth_sample). */
+ bvec4 test = equal(step(deltas, vec4(0.0)) * step(ray_w, depth_samples), vec4(1.0));
+ hit = any(test);
+
+ if (hit) {
+ vec2 m = vec2(1.0, 0.0); /* Mask */
+
+ vec4 ret_times_and_deltas = times.wzzz * m.xxyy + deltas.wwwz * m.yyxx;
+ ret_times_and_deltas = (test.z) ? times.zyyy * m.xxyy + deltas.zzzy * m.yyxx : ret_times_and_deltas;
+ ret_times_and_deltas = (test.y) ? times.yxxx * m.xxyy + deltas.yyyx * m.yyxx : ret_times_and_deltas;
+ times_and_deltas = (test.x) ? times.xxxx * m.xyyy + deltas.xxxx * m.yyxy + times_and_deltas.yyww * m.yxyx : ret_times_and_deltas;
+
+ depth_sample = depth_samples.w;
+ depth_sample = (test.z) ? depth_samples.z : depth_sample;
+ depth_sample = (test.y) ? depth_samples.y : depth_sample;
+ depth_sample = (test.x) ? depth_samples.x : depth_sample;
+ }
+ else {
+ curr_time = times.w;
+ curr_delta = deltas.w;
+ }
+#else
+ float jit_stride = mix(2.0, stride, ray_jitter);
+
+ curr_time = min(ray_time + jit_stride, max_trace_time);
+ vec4 ss_ray = ss_start + ss_step * curr_time;
+
+ depth_sample = sample_depth(ss_ray.xy, index, lod);
+
+ float prev_w = ss_start.w + ss_step.w * prev_time;
+ curr_delta = depth_sample - ss_ray.z;
+ hit = (curr_delta <= 0.0) && (prev_w <= depth_sample);
+#endif
+ }
+
+ if (discard_backface) {
+ /* Discard backface hits */
+ hit = hit && (prev_delta > 0.0);
+ }
+
+ /* Reject hit if background. */
+ hit = hit && (depth_sample != 1.0);
+
+ curr_time = (hit) ? mix(prev_time, curr_time, refine_isect(prev_delta, curr_delta)) : curr_time;
+ ray_time = (hit) ? curr_time : ray_time;
+
+ /* Clip to frustum. */
+ ray_time = max(0.001, min(ray_time, max_time - 1.5));
+
+ vec4 ss_ray = ss_start + ss_step * ray_time;
+
+ /* Tag Z if ray failed. */
+ ss_ray.z *= (hit) ? 1.0 : -1.0;
+ return ss_ray.xyz;
+}
+
+float screen_border_mask(vec2 hit_co)
+{
+ const float margin = 0.003;
+ float atten = ssrBorderFac + margin; /* Screen percentage */
+ hit_co = smoothstep(margin, atten, hit_co) * (1 - smoothstep(1.0 - atten, 1.0 - margin, hit_co));
+
+ float screenfade = hit_co.x * hit_co.y;
+
+ return screenfade;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl
new file mode 100644
index 00000000000..4ae22b480f1
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/shadow_copy_frag.glsl
@@ -0,0 +1,208 @@
+/* Copy the depth only shadowmap into another texture while converting
+ * to linear depth (or other storage method) and doing a 3x3 box filter. */
+
+layout(std140) uniform shadow_render_block {
+ vec4 lampPosition;
+ float cubeTexelSize;
+ float storedTexelSize;
+ float nearClip;
+ float farClip;
+ int shadowSampleCount;
+ float shadowInvSampleCount;
+};
+
+#ifdef CSM
+uniform sampler2DArray shadowTexture;
+uniform int cascadeId;
+#else
+uniform samplerCube shadowTexture;
+uniform int faceId;
+#endif
+uniform float shadowFilterSize;
+
+out vec4 FragColor;
+
+float linear_depth(float z)
+{
+ return (nearClip * farClip) / (z * (nearClip - farClip) + farClip);
+}
+
+vec4 linear_depth(vec4 z)
+{
+ return (nearClip * farClip) / (z * (nearClip - farClip) + farClip);
+}
+
+#ifdef CSM
+vec4 get_world_distance(vec4 depths, vec3 cos[4])
+{
+ /* Background case */
+ vec4 is_background = step(vec4(0.99999), depths);
+ depths *= abs(farClip - nearClip); /* Same factor as in shadow_cascade(). */
+ depths += 1e1 * is_background;
+ return depths;
+}
+
+float get_world_distance(float depth, vec3 cos)
+{
+ /* Background case */
+ float is_background = step(0.9999, depth);
+ depth *= abs(farClip - nearClip); /* Same factor as in shadow_cascade(). */
+ depth += 1e1 * is_background;
+ return depth;
+}
+#else /* CUBEMAP */
+vec4 get_world_distance(vec4 depths, vec3 cos[4])
+{
+ vec4 is_background = step(vec4(1.0), depths);
+ depths = linear_depth(depths);
+ depths += vec4(1e1) * is_background;
+ cos[0] = normalize(abs(cos[0]));
+ cos[1] = normalize(abs(cos[1]));
+ cos[2] = normalize(abs(cos[2]));
+ cos[3] = normalize(abs(cos[3]));
+ vec4 cos_vec;
+ cos_vec.x = max(cos[0].x, max(cos[0].y, cos[0].z));
+ cos_vec.y = max(cos[1].x, max(cos[1].y, cos[1].z));
+ cos_vec.z = max(cos[2].x, max(cos[2].y, cos[2].z));
+ cos_vec.w = max(cos[3].x, max(cos[3].y, cos[3].z));
+ return depths / cos_vec;
+}
+
+float get_world_distance(float depth, vec3 cos)
+{
+ float is_background = step(1.0, depth);
+ depth = linear_depth(depth);
+ depth += 1e1 * is_background;
+ cos = normalize(abs(cos));
+ float cos_vec = max(cos.x, max(cos.y, cos.z));
+ return depth / cos_vec;
+}
+#endif
+
+/* Marco Salvi's GDC 2008 presentation about shadow maps pre-filtering techniques slide 24 */
+float ln_space_prefilter(float w0, float x, float w1, float y)
+{
+ return x + log(w0 + w1 * exp(y - x));
+}
+
+#define SAMPLE_WEIGHT 0.11111
+
+#ifdef ESM
+void prefilter(vec4 depths, inout float accum)
+{
+ accum = ln_space_prefilter(1.0, accum, SAMPLE_WEIGHT, depths.x);
+ accum = ln_space_prefilter(1.0, accum, SAMPLE_WEIGHT, depths.y);
+ accum = ln_space_prefilter(1.0, accum, SAMPLE_WEIGHT, depths.z);
+ accum = ln_space_prefilter(1.0, accum, SAMPLE_WEIGHT, depths.w);
+}
+#else /* VSM */
+void prefilter(vec4 depths, inout vec2 accum)
+{
+ vec4 depths_sqr = depths * depths;
+ accum += vec2(dot(vec4(1.0), depths), dot(vec4(1.0), depths_sqr)) * SAMPLE_WEIGHT;
+}
+#endif
+
+#ifdef CSM
+vec3 get_texco(vec2 uvs, vec2 ofs)
+{
+ return vec3(uvs + ofs, float(cascadeId));
+}
+#else /* CUBEMAP */
+const vec3 minorAxisX[6] = vec3[6](
+ vec3(0.0f, 0.0f, -1.0f),
+ vec3(0.0f, 0.0f, 1.0f),
+ vec3(1.0f, 0.0f, 0.0f),
+ vec3(1.0f, 0.0f, 0.0f),
+ vec3(1.0f, 0.0f, 0.0f),
+ vec3(-1.0f, 0.0f, 0.0f)
+);
+
+const vec3 minorAxisY[6] = vec3[6](
+ vec3(0.0f, -1.0f, 0.0f),
+ vec3(0.0f, -1.0f, 0.0f),
+ vec3(0.0f, 0.0f, 1.0f),
+ vec3(0.0f, 0.0f, -1.0f),
+ vec3(0.0f, -1.0f, 0.0f),
+ vec3(0.0f, -1.0f, 0.0f)
+);
+
+const vec3 majorAxis[6] = vec3[6](
+ vec3(1.0f, 0.0f, 0.0f),
+ vec3(-1.0f, 0.0f, 0.0f),
+ vec3(0.0f, 1.0f, 0.0f),
+ vec3(0.0f, -1.0f, 0.0f),
+ vec3(0.0f, 0.0f, 1.0f),
+ vec3(0.0f, 0.0f, -1.0f)
+);
+
+vec3 get_texco(vec2 uvs, vec2 ofs)
+{
+ uvs += ofs;
+ return majorAxis[faceId] + uvs.x * minorAxisX[faceId] + uvs.y * minorAxisY[faceId];
+}
+#endif
+
+void main() {
+ /* Copy the depth only shadowmap into another texture while converting
+ * to linear depth and do a 3x3 box blur. */
+
+#ifdef CSM
+ vec2 uvs = gl_FragCoord.xy * storedTexelSize;
+#else /* CUBEMAP */
+ vec2 uvs = gl_FragCoord.xy * cubeTexelSize * 2.0 - 1.0;
+#endif
+
+ /* Center texel */
+ vec3 co = get_texco(uvs, vec2(0.0));
+ float depth = texture(shadowTexture, co).r;
+ depth = get_world_distance(depth, co);
+
+ if (shadowFilterSize == 0.0) {
+#ifdef ESM
+ FragColor = vec4(depth);
+#else /* VSM */
+ FragColor = vec2(depth, depth * depth).xyxy;
+#endif
+ return;
+ }
+
+#ifdef ESM
+ float accum = ln_space_prefilter(0.0, 0.0, SAMPLE_WEIGHT, depth);
+#else /* VSM */
+ vec2 accum = vec2(depth, depth * depth) * SAMPLE_WEIGHT;
+#endif
+
+#ifdef CSM
+ vec3 ofs = vec3(1.0, 0.0, -1.0) * shadowFilterSize;
+#else /* CUBEMAP */
+ vec3 ofs = vec3(1.0, 0.0, -1.0) * shadowFilterSize;
+#endif
+
+ vec3 cos[4];
+ cos[0] = get_texco(uvs, ofs.zz);
+ cos[1] = get_texco(uvs, ofs.yz);
+ cos[2] = get_texco(uvs, ofs.xz);
+ cos[3] = get_texco(uvs, ofs.zy);
+
+ vec4 depths;
+ depths.x = texture(shadowTexture, cos[0]).r;
+ depths.y = texture(shadowTexture, cos[1]).r;
+ depths.z = texture(shadowTexture, cos[2]).r;
+ depths.w = texture(shadowTexture, cos[3]).r;
+ depths = get_world_distance(depths, cos);
+ prefilter(depths, accum);
+
+ cos[0] = get_texco(uvs, ofs.xy);
+ cos[1] = get_texco(uvs, ofs.zx);
+ cos[2] = get_texco(uvs, ofs.yx);
+ cos[3] = get_texco(uvs, ofs.xx);
+ depths.x = texture(shadowTexture, cos[0]).r;
+ depths.y = texture(shadowTexture, cos[1]).r;
+ depths.z = texture(shadowTexture, cos[2]).r;
+ depths.w = texture(shadowTexture, cos[3]).r;
+ depths = get_world_distance(depths, cos);
+ prefilter(depths, accum);
+
+ FragColor = vec2(accum).xyxy;
+}
diff --git a/source/blender/draw/engines/eevee/shaders/shadow_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_frag.glsl
new file mode 100644
index 00000000000..160fcee4c73
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/shadow_frag.glsl
@@ -0,0 +1,4 @@
+
+void main() {
+ /* Do nothing */
+}
diff --git a/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl b/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl
new file mode 100644
index 00000000000..b40155be454
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/shadow_store_frag.glsl
@@ -0,0 +1,243 @@
+
+layout(std140) uniform shadow_render_block {
+ vec4 lampPosition;
+ float cubeTexelSize;
+ float storedTexelSize;
+ float nearClip;
+ float farClip;
+ int shadowSampleCount;
+ float shadowInvSampleCount;
+};
+
+#ifdef CSM
+uniform sampler2DArray shadowTexture;
+uniform int cascadeId;
+#else
+uniform samplerCube shadowTexture;
+#endif
+uniform float shadowFilterSize;
+
+out vec4 FragColor;
+
+vec3 octahedral_to_cubemap_proj(vec2 co)
+{
+ co = co * 2.0 - 1.0;
+
+ vec2 abs_co = abs(co);
+ vec3 v = vec3(co, 1.0 - (abs_co.x + abs_co.y));
+
+ if ( abs_co.x + abs_co.y > 1.0 ) {
+ v.xy = (abs(co.yx) - 1.0) * -sign(co.xy);
+ }
+
+ return v;
+}
+
+/* Marco Salvi's GDC 2008 presentation about shadow maps pre-filtering techniques slide 24 */
+float ln_space_prefilter(float w0, float x, float w1, float y)
+{
+ return x + log(w0 + w1 * exp(y - x));
+}
+
+vec4 ln_space_prefilter(float w0, vec4 x, float w1, vec4 y)
+{
+ return x + log(w0 + w1 * exp(y - x));
+}
+
+#ifdef CSM
+vec3 get_texco(vec3 cos, const vec2 ofs)
+{
+ cos.xy += ofs * shadowFilterSize;
+ return cos;
+}
+#else /* CUBEMAP */
+/* global vars */
+vec3 T = vec3(0.0);
+vec3 B = vec3(0.0);
+
+void make_orthonormal_basis(vec3 N)
+{
+ vec3 UpVector = (abs(N.z) < 0.999) ? vec3(0.0, 0.0, 1.0) : vec3(1.0, 0.0, 0.0);
+ T = normalize(cross(UpVector, N));
+ B = cross(N, T);
+}
+
+vec3 get_texco(vec3 cos, const vec2 ofs)
+{
+ return cos + ofs.x * T + ofs.y * B;
+}
+
+#endif
+
+#ifdef ESM
+void grouped_samples_accum(
+ vec3 cos,
+ const vec2 co1, const vec2 co2, const vec2 co3, const vec2 co4,
+ inout vec4 accum)
+{
+ vec4 depths;
+ depths.x = texture(shadowTexture, get_texco(cos, co1)).r;
+ depths.y = texture(shadowTexture, get_texco(cos, co2)).r;
+ depths.z = texture(shadowTexture, get_texco(cos, co3)).r;
+ depths.w = texture(shadowTexture, get_texco(cos, co4)).r;
+
+ accum = ln_space_prefilter(1.0, accum, shadowInvSampleCount, depths);
+}
+#else /* VSM */
+void grouped_samples_accum(
+ vec3 cos,
+ const vec2 co1, const vec2 co2, const vec2 co3, const vec2 co4,
+ inout vec2 accum)
+{
+ vec4 depths1, depths2;
+ depths1.xy = texture(shadowTexture, get_texco(cos, co1)).rg;
+ depths1.zw = texture(shadowTexture, get_texco(cos, co2)).rg;
+ depths2.xy = texture(shadowTexture, get_texco(cos, co3)).rg;
+ depths2.zw = texture(shadowTexture, get_texco(cos, co4)).rg;
+
+ accum += depths1.xy + depths1.zw + depths2.xy + depths2.zw;
+}
+#endif
+
+void main() {
+ vec3 cos;
+
+ cos.xy = gl_FragCoord.xy * storedTexelSize;
+
+#ifdef CSM
+ cos.z = float(cascadeId);
+#else /* CUBEMAP */
+ /* add a 2 pixel border to ensure filtering is correct */
+ cos.xy *= 1.0 + storedTexelSize * 2.0;
+ cos.xy -= storedTexelSize;
+
+ float pattern = 1.0;
+
+ /* edge mirroring : only mirror if directly adjacent
+ * (not diagonally adjacent) */
+ vec2 m = abs(cos.xy - 0.5) + 0.5;
+ vec2 f = floor(m);
+ if (f.x - f.y != 0.0) {
+ cos.xy = 1.0 - cos.xy;
+ }
+
+ /* clamp to [0-1] */
+ cos.xy = fract(cos.xy);
+
+ /* get cubemap vector */
+ cos = normalize(octahedral_to_cubemap_proj(cos.xy));
+ make_orthonormal_basis(cos);
+
+ T *= shadowFilterSize;
+ B *= shadowFilterSize;
+#endif
+
+#ifdef ESM
+ /* disc blur in log space. */
+ vec4 accum = vec4(0.0);
+ vec4 depths;
+ depths.x = texture(shadowTexture, get_texco(cos, concentric[0])).r;
+ depths.y = texture(shadowTexture, get_texco(cos, concentric[1])).r;
+ depths.z = texture(shadowTexture, get_texco(cos, concentric[2])).r;
+ depths.w = texture(shadowTexture, get_texco(cos, concentric[3])).r;
+ accum = ln_space_prefilter(0.0, accum, shadowInvSampleCount, depths);
+
+#else /* VSM */
+ vec2 accum = vec2(0.0);
+ grouped_samples_accum(cos, concentric[0], concentric[1], concentric[2], concentric[3], accum);
+#endif
+
+ /**
+ * Making the `grouped_samples_accum` be called within a loop would be
+ * the most conventional solution, however in some older gpus, transverse the huge
+ * `const vec2 concentric[]` array with variable indices is extremely slow.
+ * The solution is to use constant indices to access the array.
+ */
+ if (shadowSampleCount > 4) {
+ grouped_samples_accum(cos, concentric[4], concentric[5], concentric[6], concentric[7], accum);
+ grouped_samples_accum(cos, concentric[8], concentric[9], concentric[10], concentric[11], accum);
+ grouped_samples_accum(cos, concentric[12], concentric[13], concentric[14], concentric[15], accum);
+ }
+ if (shadowSampleCount > 16) {
+ grouped_samples_accum(cos, concentric[16], concentric[17], concentric[18], concentric[19], accum);
+ grouped_samples_accum(cos, concentric[20], concentric[21], concentric[22], concentric[23], accum);
+ grouped_samples_accum(cos, concentric[24], concentric[25], concentric[26], concentric[27], accum);
+ grouped_samples_accum(cos, concentric[28], concentric[29], concentric[30], concentric[31], accum);
+ grouped_samples_accum(cos, concentric[32], concentric[33], concentric[34], concentric[35], accum);
+ }
+ if (shadowSampleCount > 36) {
+ grouped_samples_accum(cos, concentric[36], concentric[37], concentric[38], concentric[39], accum);
+ grouped_samples_accum(cos, concentric[40], concentric[41], concentric[42], concentric[43], accum);
+ grouped_samples_accum(cos, concentric[44], concentric[45], concentric[46], concentric[47], accum);
+ grouped_samples_accum(cos, concentric[48], concentric[49], concentric[50], concentric[51], accum);
+ grouped_samples_accum(cos, concentric[52], concentric[53], concentric[54], concentric[55], accum);
+ grouped_samples_accum(cos, concentric[56], concentric[57], concentric[58], concentric[59], accum);
+ grouped_samples_accum(cos, concentric[60], concentric[61], concentric[62], concentric[63], accum);
+ }
+ if (shadowSampleCount > 64) {
+ grouped_samples_accum(cos, concentric[64], concentric[65], concentric[66], concentric[67], accum);
+ grouped_samples_accum(cos, concentric[68], concentric[69], concentric[70], concentric[71], accum);
+ grouped_samples_accum(cos, concentric[72], concentric[73], concentric[74], concentric[75], accum);
+ grouped_samples_accum(cos, concentric[76], concentric[77], concentric[78], concentric[79], accum);
+ grouped_samples_accum(cos, concentric[80], concentric[81], concentric[82], concentric[83], accum);
+ grouped_samples_accum(cos, concentric[84], concentric[85], concentric[86], concentric[87], accum);
+ grouped_samples_accum(cos, concentric[88], concentric[89], concentric[90], concentric[91], accum);
+ grouped_samples_accum(cos, concentric[92], concentric[93], concentric[94], concentric[95], accum);
+ grouped_samples_accum(cos, concentric[96], concentric[97], concentric[98], concentric[99], accum);
+ }
+ if (shadowSampleCount > 100) {
+ grouped_samples_accum(cos, concentric[100], concentric[101], concentric[102], concentric[103], accum);
+ grouped_samples_accum(cos, concentric[104], concentric[105], concentric[106], concentric[107], accum);
+ grouped_samples_accum(cos, concentric[108], concentric[109], concentric[110], concentric[111], accum);
+ grouped_samples_accum(cos, concentric[112], concentric[113], concentric[114], concentric[115], accum);
+ grouped_samples_accum(cos, concentric[116], concentric[117], concentric[118], concentric[119], accum);
+ grouped_samples_accum(cos, concentric[120], concentric[121], concentric[122], concentric[123], accum);
+ grouped_samples_accum(cos, concentric[124], concentric[125], concentric[126], concentric[127], accum);
+ grouped_samples_accum(cos, concentric[128], concentric[129], concentric[130], concentric[131], accum);
+ grouped_samples_accum(cos, concentric[132], concentric[133], concentric[134], concentric[135], accum);
+ grouped_samples_accum(cos, concentric[136], concentric[137], concentric[138], concentric[139], accum);
+ grouped_samples_accum(cos, concentric[140], concentric[141], concentric[142], concentric[143], accum);
+ }
+ if (shadowSampleCount > 144) {
+ grouped_samples_accum(cos, concentric[144], concentric[145], concentric[146], concentric[147], accum);
+ grouped_samples_accum(cos, concentric[148], concentric[149], concentric[150], concentric[151], accum);
+ grouped_samples_accum(cos, concentric[152], concentric[153], concentric[154], concentric[155], accum);
+ grouped_samples_accum(cos, concentric[156], concentric[157], concentric[158], concentric[159], accum);
+ grouped_samples_accum(cos, concentric[160], concentric[161], concentric[162], concentric[163], accum);
+ grouped_samples_accum(cos, concentric[164], concentric[165], concentric[166], concentric[167], accum);
+ grouped_samples_accum(cos, concentric[168], concentric[169], concentric[170], concentric[171], accum);
+ grouped_samples_accum(cos, concentric[172], concentric[173], concentric[174], concentric[175], accum);
+ grouped_samples_accum(cos, concentric[176], concentric[177], concentric[178], concentric[179], accum);
+ grouped_samples_accum(cos, concentric[180], concentric[181], concentric[182], concentric[183], accum);
+ grouped_samples_accum(cos, concentric[184], concentric[185], concentric[186], concentric[187], accum);
+ grouped_samples_accum(cos, concentric[188], concentric[189], concentric[190], concentric[191], accum);
+ grouped_samples_accum(cos, concentric[192], concentric[193], concentric[194], concentric[195], accum);
+ }
+ if (shadowSampleCount > 196) {
+ grouped_samples_accum(cos, concentric[196], concentric[197], concentric[198], concentric[199], accum);
+ grouped_samples_accum(cos, concentric[200], concentric[201], concentric[202], concentric[203], accum);
+ grouped_samples_accum(cos, concentric[204], concentric[205], concentric[206], concentric[207], accum);
+ grouped_samples_accum(cos, concentric[208], concentric[209], concentric[210], concentric[211], accum);
+ grouped_samples_accum(cos, concentric[212], concentric[213], concentric[114], concentric[215], accum);
+ grouped_samples_accum(cos, concentric[216], concentric[217], concentric[218], concentric[219], accum);
+ grouped_samples_accum(cos, concentric[220], concentric[221], concentric[222], concentric[223], accum);
+ grouped_samples_accum(cos, concentric[224], concentric[225], concentric[226], concentric[227], accum);
+ grouped_samples_accum(cos, concentric[228], concentric[229], concentric[230], concentric[231], accum);
+ grouped_samples_accum(cos, concentric[232], concentric[233], concentric[234], concentric[235], accum);
+ grouped_samples_accum(cos, concentric[236], concentric[237], concentric[238], concentric[239], accum);
+ grouped_samples_accum(cos, concentric[240], concentric[241], concentric[242], concentric[243], accum);
+ grouped_samples_accum(cos, concentric[244], concentric[245], concentric[246], concentric[247], accum);
+ grouped_samples_accum(cos, concentric[248], concentric[249], concentric[250], concentric[251], accum);
+ grouped_samples_accum(cos, concentric[252], concentric[253], concentric[254], concentric[255], accum);
+ }
+
+#ifdef ESM
+ accum.x = ln_space_prefilter(1.0, accum.x, 1.0, accum.y);
+ accum.x = ln_space_prefilter(1.0, accum.x, 1.0, accum.z);
+ accum.x = ln_space_prefilter(1.0, accum.x, 1.0, accum.w);
+ FragColor = accum.xxxx;
+
+#else /* VSM */
+ FragColor = accum.xyxy * shadowInvSampleCount;
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl
new file mode 100644
index 00000000000..6b6479089f6
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/shadow_vert.glsl
@@ -0,0 +1,33 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+#ifdef MESH_SHADER
+uniform mat4 ModelMatrix;
+uniform mat4 ModelViewMatrix;
+uniform mat3 WorldNormalMatrix;
+# ifndef ATTRIB
+uniform mat3 NormalMatrix;
+# endif
+#endif
+
+in vec3 pos;
+in vec3 nor;
+
+#ifdef MESH_SHADER
+out vec3 worldPosition;
+out vec3 viewPosition;
+out vec3 worldNormal;
+out vec3 viewNormal;
+#endif
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+#ifdef MESH_SHADER
+ viewPosition = (ModelViewMatrix * vec4(pos, 1.0)).xyz;
+ worldPosition = (ModelMatrix * vec4(pos, 1.0)).xyz;
+ viewNormal = normalize(NormalMatrix * nor);
+ worldNormal = normalize(WorldNormalMatrix * nor);
+#ifdef ATTRIB
+ pass_attrib(pos);
+#endif
+#endif
+}
diff --git a/source/blender/draw/engines/eevee/shaders/ssr_lib.glsl b/source/blender/draw/engines/eevee/shaders/ssr_lib.glsl
new file mode 100644
index 00000000000..6c7bfeb6b82
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/ssr_lib.glsl
@@ -0,0 +1,72 @@
+/* ------------ Refraction ------------ */
+
+#define BTDF_BIAS 0.85
+
+vec4 screen_space_refraction(vec3 viewPosition, vec3 N, vec3 V, float ior, float roughnessSquared, vec4 rand)
+{
+ float a2 = max(5e-6, roughnessSquared * roughnessSquared);
+
+ /* Importance sampling bias */
+ rand.x = mix(rand.x, 0.0, BTDF_BIAS);
+
+ vec3 T, B;
+ float NH;
+ make_orthonormal_basis(N, T, B);
+ vec3 H = sample_ggx(rand.xzw, a2, N, T, B, NH); /* Microfacet normal */
+ float pdf = pdf_ggx_reflect(NH, a2);
+
+ /* If ray is bad (i.e. going below the plane) regenerate. */
+ if (F_eta(ior, dot(H, V)) < 1.0) {
+ H = sample_ggx(rand.xzw * vec3(1.0, -1.0, -1.0), a2, N, T, B, NH); /* Microfacet normal */
+ pdf = pdf_ggx_reflect(NH, a2);
+ }
+
+ vec3 vV = viewCameraVec;
+ float eta = 1.0/ior;
+ if (dot(H, V) < 0.0) {
+ H = -H;
+ eta = ior;
+ }
+
+ vec3 R = refract(-V, H, 1.0 / ior);
+
+ R = transform_direction(ViewMatrix, R);
+
+ vec3 hit_pos = raycast(-1, viewPosition, R * 1e16, ssrThickness, rand.y, ssrQuality, roughnessSquared, false);
+
+ if ((hit_pos.z > 0.0) && (F_eta(ior, dot(H, V)) < 1.0)) {
+ hit_pos = get_view_space_from_depth(hit_pos.xy, hit_pos.z);
+ float hit_dist = distance(hit_pos, viewPosition);
+
+ float cone_cos = cone_cosine(roughnessSquared);
+ float cone_tan = sqrt(1 - cone_cos * cone_cos) / cone_cos;
+
+ /* Empirical fit for refraction. */
+ /* TODO find a better fit or precompute inside the LUT. */
+ cone_tan *= 0.5 * fast_sqrt(f0_from_ior((ior < 1.0) ? 1.0 / ior : ior));
+
+ float cone_footprint = hit_dist * cone_tan;
+
+ /* find the offset in screen space by multiplying a point
+ * in camera space at the depth of the point by the projection matrix. */
+ float homcoord = ProjectionMatrix[2][3] * hit_pos.z + ProjectionMatrix[3][3];
+ /* UV space footprint */
+ cone_footprint = BTDF_BIAS * 0.5 * max(ProjectionMatrix[0][0], ProjectionMatrix[1][1]) * cone_footprint / homcoord;
+
+ vec2 hit_uvs = project_point(ProjectionMatrix, hit_pos).xy * 0.5 + 0.5;
+
+ /* Texel footprint */
+ vec2 texture_size = vec2(textureSize(colorBuffer, 0).xy);
+ float mip = clamp(log2(cone_footprint * max(texture_size.x, texture_size.y)), 0.0, 9.0);
+
+ /* Correct UVs for mipmaping mis-alignment */
+ hit_uvs *= mip_ratio_interp(mip);
+
+ vec3 spec = textureLod(colorBuffer, hit_uvs, mip).xyz;
+ float mask = screen_border_mask(hit_uvs);
+
+ return vec4(spec, mask);
+ }
+
+ return vec4(0.0);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/update_noise_frag.glsl b/source/blender/draw/engines/eevee/shaders/update_noise_frag.glsl
new file mode 100644
index 00000000000..2907f25782f
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/update_noise_frag.glsl
@@ -0,0 +1,18 @@
+
+uniform sampler2D blueNoise;
+uniform vec3 offsets;
+
+out vec4 FragColor;
+
+#define M_2PI 6.28318530717958647692
+
+void main(void)
+{
+ vec3 blue_noise = texelFetch(blueNoise, ivec2(gl_FragCoord.xy), 0).xyz;
+
+ float noise = fract(blue_noise.y + offsets.z);
+ FragColor.x = fract(blue_noise.x + offsets.x);
+ FragColor.y = fract(blue_noise.z + offsets.y);
+ FragColor.z = cos(noise * M_2PI);
+ FragColor.w = sin(noise * M_2PI);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl
new file mode 100644
index 00000000000..3a293647f84
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_frag.glsl
@@ -0,0 +1,63 @@
+
+/* Based on Frosbite Unified Volumetric.
+ * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */
+
+#define NODETREE_EXEC
+
+#ifdef MESH_SHADER
+uniform mat4 volumeObjectMatrix;
+uniform vec3 volumeOrcoLoc;
+uniform vec3 volumeOrcoSize;
+#endif
+
+flat in int slice;
+
+/* Warning: theses are not attributes, theses are global vars. */
+vec3 worldPosition = vec3(0.0);
+vec3 viewPosition = vec3(0.0);
+vec3 viewNormal = vec3(0.0);
+#ifdef MESH_SHADER
+vec3 volumeObjectLocalCoord = vec3(0.0);
+#endif
+
+layout(location = 0) out vec4 volumeScattering;
+layout(location = 1) out vec4 volumeExtinction;
+layout(location = 2) out vec4 volumeEmissive;
+layout(location = 3) out vec4 volumePhase;
+
+/* Store volumetric properties into the froxel textures. */
+
+void main()
+{
+ ivec3 volume_cell = ivec3(gl_FragCoord.xy, slice);
+ vec3 ndc_cell = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz);
+
+ viewPosition = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z);
+ worldPosition = transform_point(ViewMatrixInverse, viewPosition);
+#ifdef MESH_SHADER
+ volumeObjectLocalCoord = transform_point(volumeObjectMatrix, worldPosition);
+ volumeObjectLocalCoord = (volumeObjectLocalCoord - volumeOrcoLoc + volumeOrcoSize) / (volumeOrcoSize * 2.0);
+
+ if (any(lessThan(volumeObjectLocalCoord, vec3(0.0))) ||
+ any(greaterThan(volumeObjectLocalCoord, vec3(1.0))))
+ discard;
+#endif
+
+#ifdef CLEAR
+ Closure cl = CLOSURE_DEFAULT;
+#else
+ Closure cl = nodetree_exec();
+#endif
+
+ volumeScattering = vec4(cl.scatter, 1.0);
+ volumeExtinction = vec4(max(vec3(1e-4), cl.absorption + cl.scatter), 1.0);
+ volumeEmissive = vec4(cl.emission, 1.0);
+
+ /* Do not add phase weight if no scattering. */
+ if (all(equal(cl.scatter, vec3(0.0)))) {
+ volumePhase = vec4(0.0);
+ }
+ else {
+ volumePhase = vec4(cl.anisotropy, vec3(1.0));
+ }
+}
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl
new file mode 100644
index 00000000000..208e8165689
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_geom.glsl
@@ -0,0 +1,52 @@
+
+#ifdef MESH_SHADER
+/* TODO tight slices */
+layout(triangles) in;
+layout(triangle_strip, max_vertices=3) out;
+#else /* World */
+layout(triangles) in;
+layout(triangle_strip, max_vertices=3) out;
+#endif
+
+in vec4 vPos[];
+
+flat out int slice;
+
+#ifdef MESH_SHADER
+/* TODO tight slices */
+void main() {
+ gl_Layer = slice = int(vPos[0].z);
+
+ gl_Position = vPos[0].xyww;
+ EmitVertex();
+
+ gl_Position = vPos[1].xyww;
+ EmitVertex();
+
+ gl_Position = vPos[2].xyww;
+ EmitVertex();
+
+ EndPrimitive();
+}
+
+#else /* World */
+
+/* This is just a pass-through geometry shader that send the geometry
+ * to the layer corresponding to it's depth. */
+
+void main() {
+ gl_Layer = slice = int(vPos[0].z);
+
+ gl_Position = vPos[0].xyww;
+ EmitVertex();
+
+ gl_Position = vPos[1].xyww;
+ EmitVertex();
+
+ gl_Position = vPos[2].xyww;
+ EmitVertex();
+
+ EndPrimitive();
+}
+
+#endif
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_integration_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_integration_frag.glsl
new file mode 100644
index 00000000000..c5c97b97734
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_integration_frag.glsl
@@ -0,0 +1,63 @@
+
+/* Based on Frosbite Unified Volumetric.
+ * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */
+
+/* Step 3 : Integrate for each froxel the final amount of light
+ * scattered back to the viewer and the amout of transmittance. */
+
+uniform sampler3D volumeScattering; /* Result of the scatter step */
+uniform sampler3D volumeExtinction;
+
+flat in int slice;
+
+layout(location = 0) out vec4 finalScattering;
+layout(location = 1) out vec4 finalTransmittance;
+
+void main()
+{
+ /* Start with full transmittance and no scattered light. */
+ finalScattering = vec4(0.0);
+ finalTransmittance = vec4(1.0);
+
+ vec3 tex_size = vec3(textureSize(volumeScattering, 0).xyz);
+
+ /* Compute view ray. */
+ vec2 uvs = gl_FragCoord.xy / tex_size.xy;
+ vec3 ndc_cell = volume_to_ndc(vec3(uvs, 1e-5));
+ vec3 view_cell = get_view_space_from_depth(ndc_cell.xy, ndc_cell.z);
+
+ /* Ortho */
+ float prev_ray_len = view_cell.z;
+ float orig_ray_len = 1.0;
+
+ /* Persp */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ prev_ray_len = length(view_cell);
+ orig_ray_len = prev_ray_len / view_cell.z;
+ }
+
+ /* Without compute shader and arbitrary write we need to
+ * accumulate from the beginning of the ray for each cell. */
+ float integration_end = float(slice);
+ for (int i = 0; i < slice; ++i) {
+ ivec3 volume_cell = ivec3(gl_FragCoord.xy, i);
+
+ vec4 Lscat = texelFetch(volumeScattering, volume_cell, 0);
+ vec4 s_extinction = texelFetch(volumeExtinction, volume_cell, 0);
+
+ float cell_depth = volume_z_to_view_z((float(i) + 1.0) / tex_size.z);
+ float ray_len = orig_ray_len * cell_depth;
+
+ /* Evaluate Scattering */
+ float s_len = abs(ray_len - prev_ray_len);
+ prev_ray_len = ray_len;
+ vec4 Tr = exp(-s_extinction * s_len);
+
+ /* integrate along the current step segment */
+ Lscat = (Lscat - Lscat * Tr) / s_extinction;
+ /* accumulate and also take into account the transmittance from previous steps */
+ finalScattering += finalTransmittance * Lscat;
+
+ finalTransmittance *= Tr;
+ }
+}
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
new file mode 100644
index 00000000000..1a8167c2830
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_lib.glsl
@@ -0,0 +1,150 @@
+
+/* Based on Frosbite Unified Volumetric.
+ * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */
+
+/* Volume slice to view space depth. */
+float volume_z_to_view_z(float z)
+{
+ if (ProjectionMatrix[3][3] == 0.0) {
+ /* Exponential distribution */
+ return (exp2(z / volDepthParameters.z) - volDepthParameters.x) / volDepthParameters.y;
+ }
+ else {
+ /* Linear distribution */
+ return mix(volDepthParameters.x, volDepthParameters.y, z);
+ }
+}
+
+float view_z_to_volume_z(float depth)
+{
+ if (ProjectionMatrix[3][3] == 0.0) {
+ /* Exponential distribution */
+ return volDepthParameters.z * log2(depth * volDepthParameters.y + volDepthParameters.x);
+ }
+ else {
+ /* Linear distribution */
+ return (depth - volDepthParameters.x) * volDepthParameters.z;
+ }
+}
+
+/* Volume texture normalized coordinates to NDC (special range [0, 1]). */
+vec3 volume_to_ndc(vec3 cos)
+{
+ cos.z = volume_z_to_view_z(cos.z);
+ cos.z = get_depth_from_view_z(cos.z);
+ cos.xy /= volCoordScale.xy;
+ return cos;
+}
+
+vec3 ndc_to_volume(vec3 cos)
+{
+ cos.z = get_view_z_from_depth(cos.z);
+ cos.z = view_z_to_volume_z(cos.z);
+ cos.xy *= volCoordScale.xy;
+ return cos;
+}
+
+float phase_function_isotropic()
+{
+ return 1.0 / (4.0 * M_PI);
+}
+
+float phase_function(vec3 v, vec3 l, float g)
+{
+ /* Henyey-Greenstein */
+ float cos_theta = dot(v, l);
+ g = clamp(g, -1.0 + 1e-3, 1.0 - 1e-3);
+ float sqr_g = g * g;
+ return (1- sqr_g) / max(1e-8, 4.0 * M_PI * pow(1 + sqr_g - 2 * g * cos_theta, 3.0 / 2.0));
+}
+
+#ifdef LAMPS_LIB
+vec3 light_volume(LightData ld, vec4 l_vector)
+{
+ float power;
+ /* TODO : Area lighting ? */
+ /* XXX : Removing Area Power. */
+ /* TODO : put this out of the shader. */
+ /* See eevee_light_setup(). */
+ if (ld.l_type == AREA) {
+ power = (ld.l_sizex * ld.l_sizey * 4.0 * M_PI) * (1.0 / 80.0);
+ power *= 20.0 * max(0.0, dot(-ld.l_forward, l_vector.xyz / l_vector.w)); /* XXX ad hoc, empirical */
+ }
+ else if (ld.l_type == SUN) {
+ power = (4.0f * ld.l_radius * ld.l_radius * M_2PI) * (1.0 / 12.5); /* Removing area light power*/
+ power *= M_2PI * 0.78; /* Matching cycles with point light. */
+ }
+ else {
+ power = (4.0 * ld.l_radius * ld.l_radius) * (1.0 /10.0);
+ }
+
+ /* OPTI: find a better way than calculating this on the fly */
+ float lum = dot(ld.l_color, vec3(0.3, 0.6, 0.1)); /* luminance approx. */
+ vec3 tint = (lum > 0.0) ? ld.l_color / lum : vec3(1.0); /* normalize lum. to isolate hue+sat */
+
+ power /= (l_vector.w * l_vector.w);
+
+ lum = min(lum * power, volLightClamp);
+
+ return tint * lum;
+}
+
+#define VOLUMETRIC_SHADOW_MAX_STEP 32.0
+
+vec3 participating_media_extinction(vec3 wpos, sampler3D volume_extinction)
+{
+ /* Waiting for proper volume shadowmaps and out of frustum shadow map. */
+ vec3 ndc = project_point(ViewProjectionMatrix, wpos);
+ vec3 volume_co = ndc_to_volume(ndc * 0.5 + 0.5);
+
+ /* Let the texture be clamped to edge. This reduce visual glitches. */
+ return texture(volume_extinction, volume_co).rgb;
+}
+
+vec3 light_volume_shadow(LightData ld, vec3 ray_wpos, vec4 l_vector, sampler3D volume_extinction)
+{
+#if defined(VOLUME_SHADOW)
+ /* Heterogeneous volume shadows */
+ float dd = l_vector.w / volShadowSteps;
+ vec3 L = l_vector.xyz * l_vector.w;
+ vec3 shadow = vec3(1.0);
+ for (float s = 0.5; s < VOLUMETRIC_SHADOW_MAX_STEP && s < (volShadowSteps - 0.1); s += 1.0) {
+ vec3 pos = ray_wpos + L * (s / volShadowSteps);
+ vec3 s_extinction = participating_media_extinction(pos, volume_extinction);
+ shadow *= exp(-s_extinction * dd);
+ }
+ return shadow;
+#else
+ return vec3(1.0);
+#endif /* VOLUME_SHADOW */
+}
+#endif
+
+#ifdef IRRADIANCE_LIB
+vec3 irradiance_volumetric(vec3 wpos)
+{
+#ifdef IRRADIANCE_HL2
+ IrradianceData ir_data = load_irradiance_cell(0, vec3(1.0));
+ vec3 irradiance = ir_data.cubesides[0] + ir_data.cubesides[1] + ir_data.cubesides[2];
+ ir_data = load_irradiance_cell(0, vec3(-1.0));
+ irradiance += ir_data.cubesides[0] + ir_data.cubesides[1] + ir_data.cubesides[2];
+ irradiance *= 0.16666666; /* 1/6 */
+ return irradiance;
+#else
+ return vec3(0.0);
+#endif
+}
+#endif
+
+uniform sampler3D inScattering;
+uniform sampler3D inTransmittance;
+
+vec4 volumetric_resolve(vec4 scene_color, vec2 frag_uvs, float frag_depth)
+{
+ vec3 volume_cos = ndc_to_volume(vec3(frag_uvs, frag_depth));
+
+ vec3 scattering = texture(inScattering, volume_cos).rgb;
+ vec3 transmittance = texture(inTransmittance, volume_cos).rgb;
+
+ return vec4(scene_color.rgb * transmittance + scattering, scene_color.a);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_resolve_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_resolve_frag.glsl
new file mode 100644
index 00000000000..0115b2cb99e
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_resolve_frag.glsl
@@ -0,0 +1,21 @@
+
+/* Based on Frosbite Unified Volumetric.
+ * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */
+
+/* Step 4 : Apply final integration on top of the scene color.
+ * Note that we do the blending ourself instead of relying
+ * on hardware blending which would require 2 pass. */
+
+uniform sampler2D inSceneColor;
+uniform sampler2D inSceneDepth;
+
+out vec4 FragColor;
+
+void main()
+{
+ vec2 uvs = gl_FragCoord.xy / vec2(textureSize(inSceneDepth, 0));
+ vec4 scene_color = texture(inSceneColor, uvs);
+ float scene_depth = texture(inSceneDepth, uvs).r;
+
+ FragColor = volumetric_resolve(scene_color, uvs, scene_depth);
+}
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl
new file mode 100644
index 00000000000..fcbb6661b14
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_scatter_frag.glsl
@@ -0,0 +1,75 @@
+
+/* Based on Frosbite Unified Volumetric.
+ * https://www.ea.com/frostbite/news/physically-based-unified-volumetric-rendering-in-frostbite */
+
+/* Step 2 : Evaluate all light scattering for each froxels.
+ * Also do the temporal reprojection to fight aliasing artifacts. */
+
+uniform sampler3D volumeScattering;
+uniform sampler3D volumeExtinction;
+uniform sampler3D volumeEmission;
+uniform sampler3D volumePhase;
+
+uniform sampler3D historyScattering;
+uniform sampler3D historyTransmittance;
+
+flat in int slice;
+
+layout(location = 0) out vec4 outScattering;
+layout(location = 1) out vec4 outTransmittance;
+
+void main()
+{
+ ivec3 volume_cell = ivec3(gl_FragCoord.xy, slice);
+
+ /* Emission */
+ outScattering = texelFetch(volumeEmission, volume_cell, 0);
+ outTransmittance = texelFetch(volumeExtinction, volume_cell, 0);
+ vec3 s_scattering = texelFetch(volumeScattering, volume_cell, 0).rgb;
+ vec3 volume_ndc = volume_to_ndc((vec3(volume_cell) + volJitter.xyz) * volInvTexSize.xyz);
+ vec3 worldPosition = get_world_space_from_depth(volume_ndc.xy, volume_ndc.z);
+ vec3 wdir = cameraVec;
+
+ vec2 phase = texelFetch(volumePhase, volume_cell, 0).rg;
+ float s_anisotropy = phase.x / max(1.0, phase.y);
+
+ /* Environment : Average color. */
+ outScattering.rgb += irradiance_volumetric(worldPosition) * s_scattering * phase_function_isotropic();
+
+#ifdef VOLUME_LIGHTING /* Lights */
+ for (int i = 0; i < MAX_LIGHT && i < laNumLight; ++i) {
+
+ LightData ld = lights_data[i];
+
+ vec4 l_vector;
+ l_vector.xyz = (ld.l_type == SUN) ? -ld.l_forward : ld.l_position - worldPosition;
+ l_vector.w = length(l_vector.xyz);
+
+ float Vis = light_visibility(ld, worldPosition, l_vector);
+
+ vec3 Li = light_volume(ld, l_vector) * light_volume_shadow(ld, worldPosition, l_vector, volumeExtinction);
+
+ outScattering.rgb += Li * Vis * s_scattering * phase_function(-wdir, l_vector.xyz / l_vector.w, s_anisotropy);
+ }
+#endif
+
+ /* Temporal supersampling */
+ /* Note : this uses the cell non-jittered position (texel center). */
+ vec3 curr_ndc = volume_to_ndc(vec3(gl_FragCoord.xy, float(slice) + 0.5) * volInvTexSize.xyz);
+ vec3 wpos = get_world_space_from_depth(curr_ndc.xy, curr_ndc.z);
+ vec3 prev_ndc = project_point(pastViewProjectionMatrix, wpos);
+ vec3 prev_volume = ndc_to_volume(prev_ndc * 0.5 + 0.5);
+
+ if ((volHistoryAlpha > 0.0) && all(greaterThan(prev_volume, vec3(0.0))) && all(lessThan(prev_volume, vec3(1.0)))) {
+ vec4 h_Scattering = texture(historyScattering, prev_volume);
+ vec4 h_Transmittance = texture(historyTransmittance, prev_volume);
+ outScattering = mix(outScattering, h_Scattering, volHistoryAlpha);
+ outTransmittance = mix(outTransmittance, h_Transmittance, volHistoryAlpha);
+ }
+
+ /* Catch NaNs */
+ if (any(isnan(outScattering)) || any(isnan(outTransmittance))) {
+ outScattering = vec4(0.0);
+ outTransmittance = vec4(1.0);
+ }
+}
diff --git a/source/blender/draw/engines/eevee/shaders/volumetric_vert.glsl b/source/blender/draw/engines/eevee/shaders/volumetric_vert.glsl
new file mode 100644
index 00000000000..a99acd41fbd
--- /dev/null
+++ b/source/blender/draw/engines/eevee/shaders/volumetric_vert.glsl
@@ -0,0 +1,27 @@
+
+out vec4 vPos;
+
+void main()
+{
+ /* Generate Triangle : less memory fetches from a VBO */
+ int v_id = gl_VertexID % 3; /* Vertex Id */
+ int t_id = gl_VertexID / 3; /* Triangle Id */
+
+ /* Crappy diagram
+ * ex 1
+ * | \
+ * | \
+ * 1 | \
+ * | \
+ * | \
+ * 0 | \
+ * | \
+ * | \
+ * -1 0 --------------- 2
+ * -1 0 1 ex
+ **/
+ vPos.x = float(v_id / 2) * 4.0 - 1.0; /* int divisor round down */
+ vPos.y = float(v_id % 2) * 4.0 - 1.0;
+ vPos.z = float(t_id);
+ vPos.w = 1.0;
+}
diff --git a/source/blender/draw/engines/external/external_engine.c b/source/blender/draw/engines/external/external_engine.c
new file mode 100644
index 00000000000..ec0141953fe
--- /dev/null
+++ b/source/blender/draw/engines/external/external_engine.c
@@ -0,0 +1,234 @@
+/*
+ * Copyright 2017, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file external_engine.c
+ * \ingroup draw_engine
+ *
+ * Base engine for external render engines.
+ * We use it for depth and non-mesh objects.
+ */
+
+#include "DRW_render.h"
+
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_icons.h"
+#include "BKE_idprop.h"
+#include "BKE_main.h"
+
+#include "ED_view3d.h"
+#include "ED_screen.h"
+
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
+#include "GPU_shader.h"
+#include "GPU_viewport.h"
+
+#include "external_engine.h"
+/* Shaders */
+
+#define EXTERNAL_ENGINE "BLENDER_EXTERNAL"
+
+/* *********** LISTS *********** */
+
+/* GPUViewport.storage
+ * Is freed everytime the viewport engine changes */
+typedef struct EXTERNAL_Storage {
+ int dummy;
+} EXTERNAL_Storage;
+
+typedef struct EXTERNAL_StorageList {
+ struct EXTERNAL_Storage *storage;
+ struct EXTERNAL_PrivateData *g_data;
+} EXTERNAL_StorageList;
+
+typedef struct EXTERNAL_FramebufferList {
+ struct GPUFrameBuffer *default_fb;
+} EXTERNAL_FramebufferList;
+
+typedef struct EXTERNAL_TextureList {
+ /* default */
+ struct GPUTexture *depth;
+} EXTERNAL_TextureList;
+
+typedef struct EXTERNAL_PassList {
+ struct DRWPass *depth_pass;
+} EXTERNAL_PassList;
+
+typedef struct EXTERNAL_Data {
+ void *engine_type;
+ EXTERNAL_FramebufferList *fbl;
+ EXTERNAL_TextureList *txl;
+ EXTERNAL_PassList *psl;
+ EXTERNAL_StorageList *stl;
+ char info[GPU_INFO_SIZE];
+} EXTERNAL_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Depth Pre Pass */
+ struct GPUShader *depth_sh;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct EXTERNAL_PrivateData {
+ DRWShadingGroup *depth_shgrp;
+} EXTERNAL_PrivateData; /* Transient data */
+
+/* Functions */
+
+static void external_engine_init(void *UNUSED(vedata))
+{
+ /* Depth prepass */
+ if (!e_data.depth_sh) {
+ e_data.depth_sh = DRW_shader_create_3D_depth_only();
+ }
+}
+
+static void external_cache_init(void *vedata)
+{
+ EXTERNAL_PassList *psl = ((EXTERNAL_Data *)vedata)->psl;
+ EXTERNAL_StorageList *stl = ((EXTERNAL_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ /* Depth Pass */
+ {
+ psl->depth_pass = DRW_pass_create("Depth Pass", DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+ stl->g_data->depth_shgrp = DRW_shgroup_create(e_data.depth_sh, psl->depth_pass);
+ }
+}
+
+static void external_cache_populate(void *vedata, Object *ob)
+{
+ EXTERNAL_StorageList *stl = ((EXTERNAL_Data *)vedata)->stl;
+
+ if (!DRW_object_is_renderable(ob))
+ return;
+
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
+ if (geom) {
+ /* Depth Prepass */
+ DRW_shgroup_call_add(stl->g_data->depth_shgrp, geom, ob->obmat);
+ }
+}
+
+static void external_cache_finish(void *UNUSED(vedata))
+{
+}
+
+static void external_draw_scene_do(void *vedata)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ RegionView3D *rv3d = draw_ctx->rv3d;
+ ARegion *ar = draw_ctx->ar;
+ RenderEngineType *type;
+
+ DRW_state_reset_ex(DRW_STATE_DEFAULT & ~DRW_STATE_DEPTH_LESS);
+
+ /* Create render engine. */
+ if (!rv3d->render_engine) {
+ RenderEngineType *engine_type = draw_ctx->engine_type;
+
+ if (!(engine_type->view_update && engine_type->render_to_view)) {
+ return;
+ }
+
+ RenderEngine *engine = RE_engine_create_ex(engine_type, true);
+ engine->tile_x = scene->r.tilex;
+ engine->tile_y = scene->r.tiley;
+ engine_type->view_update(engine, draw_ctx->evil_C);
+ rv3d->render_engine = engine;
+ }
+
+ /* Rendered draw. */
+ gpuPushProjectionMatrix();
+ ED_region_pixelspace(ar);
+
+ /* Render result draw. */
+ type = rv3d->render_engine->type;
+ type->render_to_view(rv3d->render_engine, draw_ctx->evil_C);
+
+ gpuPopProjectionMatrix();
+
+ /* Set render info. */
+ EXTERNAL_Data *data = vedata;
+ if (rv3d->render_engine->text[0] != '\0') {
+ BLI_strncpy(data->info, rv3d->render_engine->text, sizeof(data->info));
+ }
+ else {
+ data->info[0] = '\0';
+ }
+}
+
+static void external_draw_scene(void *vedata)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ EXTERNAL_PassList *psl = ((EXTERNAL_Data *)vedata)->psl;
+
+ /* Will be NULL during OpenGL render.
+ * OpenGL render is used for quick preview (thumbnails or sequencer preview)
+ * where using the rendering engine to preview doesn't make so much sense. */
+ if (draw_ctx->evil_C) {
+ external_draw_scene_do(vedata);
+ }
+ DRW_draw_pass(psl->depth_pass);
+}
+
+static void external_engine_free(void)
+{
+ /* All shaders are builtin. */
+}
+
+static const DrawEngineDataSize external_data_size = DRW_VIEWPORT_DATA_SIZE(EXTERNAL_Data);
+
+DrawEngineType draw_engine_external_type = {
+ NULL, NULL,
+ N_("External"),
+ &external_data_size,
+ &external_engine_init,
+ &external_engine_free,
+ &external_cache_init,
+ &external_cache_populate,
+ &external_cache_finish,
+ NULL,
+ &external_draw_scene,
+ NULL,
+ NULL,
+ NULL,
+};
+
+/* Note: currently unused, we should not register unless we want to see this when debugging the view. */
+
+RenderEngineType DRW_engine_viewport_external_type = {
+ NULL, NULL,
+ EXTERNAL_ENGINE, N_("External"), RE_INTERNAL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
+ &draw_engine_external_type,
+ {NULL, NULL, NULL}
+};
+
+#undef EXTERNAL_ENGINE
diff --git a/source/blender/draw/engines/external/external_engine.h b/source/blender/draw/engines/external/external_engine.h
new file mode 100644
index 00000000000..1789fb67efe
--- /dev/null
+++ b/source/blender/draw/engines/external/external_engine.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2017, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file external_engine.h
+ * \ingroup draw_engine
+ */
+
+#ifndef __EXTERNAL_ENGINE_H__
+#define __EXTERNAL_ENGINE_H__
+
+extern RenderEngineType DRW_engine_viewport_external_type;
+
+#endif /* __EXTERNAL_ENGINE_H__ */
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl
new file mode 100644
index 00000000000..fda2fc85460
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_background_lib.glsl
@@ -0,0 +1,3 @@
+vec3 background_color(WorldData world_data, float y) {
+ return mix(world_data.background_color_low, world_data.background_color_high, y).xyz + bayer_dither_noise();
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
new file mode 100644
index 00000000000..5b646f8e911
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_common_lib.glsl
@@ -0,0 +1,37 @@
+#define NO_OBJECT_ID uint(0)
+
+/* 4x4 bayer matrix prepared for 8bit UNORM precision error. */
+#define P(x) (((x + 0.5) * (1.0 / 16.0) - 0.5) * (1.0 / 255.0))
+const vec4 dither_mat4x4[4] = vec4[4](
+ vec4( P(0.0), P(8.0), P(2.0), P(10.0)),
+ vec4(P(12.0), P(4.0), P(14.0), P(6.0)),
+ vec4( P(3.0), P(11.0), P(1.0), P(9.0)),
+ vec4(P(15.0), P(7.0), P(13.0), P(5.0))
+);
+
+float bayer_dither_noise() {
+ ivec2 tx1 = ivec2(gl_FragCoord.xy) % 4;
+ ivec2 tx2 = ivec2(gl_FragCoord.xy) % 2;
+ return dither_mat4x4[tx1.x][tx1.y];
+}
+
+/* From http://aras-p.info/texts/CompactNormalStorage.html
+ * Using Method #4: Spheremap Transform */
+vec3 normal_decode(vec2 enc)
+{
+ vec2 fenc = enc.xy * 4.0 - 2.0;
+ float f = dot(fenc, fenc);
+ float g = sqrt(1.0 - f / 4.0);
+ vec3 n;
+ n.xy = fenc*g;
+ n.z = 1 - f / 2;
+ return n;
+}
+
+/* From http://aras-p.info/texts/CompactNormalStorage.html
+ * Using Method #4: Spheremap Transform */
+vec2 normal_encode(vec3 n)
+{
+ float p = sqrt(n.z * 8.0 + 8.0);
+ return vec2(n.xy / p + 0.5);
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl
new file mode 100644
index 00000000000..f96f5ff0af7
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_composite_frag.glsl
@@ -0,0 +1,65 @@
+out vec4 fragColor;
+
+uniform usampler2D objectId;
+uniform sampler2D colorBuffer;
+uniform sampler2D normalBuffer;
+/* normalBuffer contains viewport normals */
+uniform vec2 invertedViewportSize;
+uniform vec3 objectOverlapColor = vec3(0.0);
+uniform float shadowMultiplier;
+
+layout(std140) uniform world_block {
+ WorldData world_data;
+};
+
+void main()
+{
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+ vec2 uv_viewport = gl_FragCoord.xy * invertedViewportSize;
+ uint object_id = texelFetch(objectId, texel, 0).r;
+
+#ifndef V3D_SHADING_OBJECT_OVERLAP
+ if (object_id == NO_OBJECT_ID) {
+ fragColor = vec4(background_color(world_data, uv_viewport.y), 0.0);
+ return;
+ }
+#else /* !V3D_SHADING_OBJECT_OVERLAP */
+ float object_overlap = calculate_object_overlap(objectId, texel, object_id);
+
+ if (object_id == NO_OBJECT_ID) {
+ vec3 background = background_color(world_data, uv_viewport.y);
+ if (object_overlap == 0.0) {
+ fragColor = vec4(background, 0.0);
+ } else {
+ fragColor = vec4(mix(objectOverlapColor, background, object_overlap), 1.0-object_overlap);
+ }
+ return;
+ }
+#endif /* !V3D_SHADING_OBJECT_OVERLAP */
+
+
+#ifdef V3D_LIGHTING_STUDIO
+ vec4 diffuse_color = texelFetch(colorBuffer, texel, 0);
+#ifdef WORKBENCH_ENCODE_NORMALS
+ vec3 normal_viewport = normal_decode(texelFetch(normalBuffer, texel, 0).rg);
+ if (diffuse_color.a == 1.0) {
+ normal_viewport = - normal_viewport;
+ }
+#else /* WORKBENCH_ENCODE_NORMALS */
+ vec3 normal_viewport = texelFetch(normalBuffer, texel, 0).rgb;
+#endif /* WORKBENCH_ENCODE_NORMALS */
+ vec3 diffuse_light = get_world_diffuse_light(world_data, normal_viewport);
+ vec3 shaded_color = diffuse_light * diffuse_color.rgb * (1.0 - shadowMultiplier);
+
+#else /* V3D_LIGHTING_STUDIO */
+ vec3 diffuse_color = texelFetch(colorBuffer, texel, 0).rgb;
+ vec3 shaded_color = diffuse_color * (1.0 - shadowMultiplier);
+#endif /* V3D_LIGHTING_STUDIO */
+
+
+#ifdef V3D_SHADING_OBJECT_OVERLAP
+ shaded_color = mix(objectOverlapColor, shaded_color, object_overlap);
+#endif /* V3D_SHADING_OBJECT_OVERLAP */
+
+ fragColor = vec4(shaded_color, 1.0);
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
new file mode 100644
index 00000000000..a698a5afeaa
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_data_lib.glsl
@@ -0,0 +1,10 @@
+struct WorldData {
+ vec4 diffuse_light_x_pos;
+ vec4 diffuse_light_x_neg;
+ vec4 diffuse_light_y_pos;
+ vec4 diffuse_light_y_neg;
+ vec4 diffuse_light_z_pos;
+ vec4 diffuse_light_z_neg;
+ vec4 background_color_low;
+ vec4 background_color_high;
+};
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_object_overlap_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_object_overlap_lib.glsl
new file mode 100644
index 00000000000..e1ae9b93144
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_object_overlap_lib.glsl
@@ -0,0 +1,12 @@
+#define OBJECT_OVERLAP_OFFSET 1
+
+float calculate_object_overlap(usampler2D objectId, ivec2 texel, uint object_id)
+{
+ uvec4 oid_offset = uvec4(
+ texelFetchOffset(objectId, texel, 0, ivec2(0, OBJECT_OVERLAP_OFFSET)).r,
+ texelFetchOffset(objectId, texel, 0, ivec2(0, -OBJECT_OVERLAP_OFFSET)).r,
+ texelFetchOffset(objectId, texel, 0, ivec2(-OBJECT_OVERLAP_OFFSET, 0)).r,
+ texelFetchOffset(objectId, texel, 0, ivec2( OBJECT_OVERLAP_OFFSET, 0)).r);
+
+ return dot(vec4(equal(uvec4(object_id), oid_offset)), vec4(0.25));
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
new file mode 100644
index 00000000000..7853e361172
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_frag.glsl
@@ -0,0 +1,47 @@
+uniform int object_id = 0;
+uniform vec3 object_color = vec3(1.0, 0.0, 1.0);
+#ifdef OB_TEXTURE
+uniform sampler2D image;
+#endif
+
+#ifdef V3D_LIGHTING_STUDIO
+in vec3 normal_viewport;
+#endif /* V3D_LIGHTING_STUDIO */
+#ifdef OB_TEXTURE
+in vec2 uv_interp;
+#endif /* OB_TEXTURE */
+
+layout(location=0) out uint objectId;
+layout(location=1) out vec4 diffuseColor;
+#ifdef V3D_LIGHTING_STUDIO
+#ifdef WORKBENCH_ENCODE_NORMALS
+layout(location=2) out vec2 normalViewport;
+#else /* WORKBENCH_ENCODE_NORMALS */
+layout(location=2) out vec3 normalViewport;
+#endif /* WORKBENCH_ENCODE_NORMALS */
+#endif /* V3D_LIGHTING_STUDIO */
+
+void main()
+{
+ objectId = uint(object_id);
+#ifdef OB_SOLID
+ diffuseColor = vec4(object_color, 0.0);
+#endif /* OB_SOLID */
+#ifdef OB_TEXTURE
+ diffuseColor = texture(image, uv_interp);
+#endif /* OB_TEXTURE */
+
+#ifdef V3D_LIGHTING_STUDIO
+#ifdef WORKBENCH_ENCODE_NORMALS
+ if (!gl_FrontFacing) {
+ normalViewport = normal_encode(-normal_viewport);
+ diffuseColor.a = 1.0;
+ } else {
+ normalViewport = normal_encode(normal_viewport);
+ diffuseColor.a = 0.0;
+ }
+#else /* WORKBENCH_ENCODE_NORMALS */
+ normalViewport = normal_viewport;
+#endif /* WORKBENCH_ENCODE_NORMALS */
+#endif /* V3D_LIGHTING_STUDIO */
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
new file mode 100644
index 00000000000..22b16bf1d6a
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_prepass_vert.glsl
@@ -0,0 +1,30 @@
+uniform mat4 ModelViewProjectionMatrix;
+#ifdef V3D_LIGHTING_STUDIO
+uniform mat3 NormalMatrix;
+#endif /* V3D_LIGHTING_STUDIO */
+
+in vec3 pos;
+#ifdef V3D_LIGHTING_STUDIO
+in vec3 nor;
+#endif /* V3D_LIGHTING_STUDIO */
+#ifdef OB_TEXTURE
+in vec2 uv;
+#endif
+
+#ifdef V3D_LIGHTING_STUDIO
+out vec3 normal_viewport;
+#endif /* V3D_LIGHTING_STUDIO */
+#ifdef OB_TEXTURE
+out vec2 uv_interp;
+#endif
+
+void main()
+{
+#ifdef OB_TEXTURE
+ uv_interp = uv;
+#endif
+#ifdef V3D_LIGHTING_STUDIO
+ normal_viewport = normalize(NormalMatrix * nor);
+#endif /* V3D_LIGHTING_STUDIO */
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl
new file mode 100644
index 00000000000..854cbee571d
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_geom.glsl
@@ -0,0 +1,51 @@
+layout(triangles) in;
+layout(triangle_strip, max_vertices=9) out;
+
+uniform mat4 ModelMatrix;
+uniform mat4 ModelViewProjectionMatrix;
+
+uniform vec3 lightDirection = vec3(0.57, 0.57, -0.57);
+
+in VertexData {
+ flat vec4 lightDirectionMS;
+ vec4 frontPosition;
+ vec4 backPosition;
+} vertexData[];
+
+vec3 face_normal(vec3 v1, vec3 v2, vec3 v3) {
+ return normalize(cross(v2 - v1, v3 - v1));
+}
+void main()
+{
+ vec4 light_direction = vertexData[0].lightDirectionMS;
+ vec4 v1 = gl_in[0].gl_Position;
+ vec4 v2 = gl_in[1].gl_Position;
+ vec4 v3 = gl_in[2].gl_Position;
+ bool backface = dot(face_normal(v1.xyz, v2.xyz, v3.xyz), light_direction.xyz) > 0.0;
+
+ int index0 = backface?0:2;
+ int index2 = backface?2:0;
+
+ /* back cap */
+ gl_Position = vertexData[index0].backPosition;
+ EmitVertex();
+ gl_Position = vertexData[1].backPosition;
+ EmitVertex();
+ gl_Position = vertexData[index2].backPosition;
+ EmitVertex();
+
+ /* sides */
+ gl_Position = vertexData[index2].frontPosition;
+ EmitVertex();
+ gl_Position = vertexData[index0].backPosition;
+ EmitVertex();
+ gl_Position = vertexData[index0].frontPosition;
+ EmitVertex();
+ gl_Position = vertexData[1].backPosition;
+ EmitVertex();
+ gl_Position = vertexData[1].frontPosition;
+ EmitVertex();
+ gl_Position = vertexData[index2].frontPosition;
+ EmitVertex();
+ EndPrimitive();
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl
new file mode 100644
index 00000000000..7322266a956
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_shadow_vert.glsl
@@ -0,0 +1,23 @@
+#define EPSILON 0.000001
+#define INFINITE 100.0
+
+uniform mat4 ModelMatrixInverse;
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec3 lightDirection = vec3(0.57, 0.57, -0.57);
+
+in vec4 pos;
+
+out VertexData {
+ flat vec4 lightDirectionMS;
+ vec4 frontPosition;
+ vec4 backPosition;
+} vertexData;
+
+void main()
+{
+ gl_Position = pos;
+ vertexData.lightDirectionMS = normalize(ModelMatrixInverse * vec4(lightDirection, 0.0));
+ vertexData.lightDirectionMS.w = 0.0;
+ vertexData.frontPosition = ModelViewProjectionMatrix * (pos + vertexData.lightDirectionMS * EPSILON);
+ vertexData.backPosition = ModelViewProjectionMatrix * (pos + vertexData.lightDirectionMS * INFINITE);
+}
diff --git a/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl
new file mode 100644
index 00000000000..b6b13a117c5
--- /dev/null
+++ b/source/blender/draw/engines/workbench/shaders/workbench_world_light_lib.glsl
@@ -0,0 +1,9 @@
+vec3 get_world_diffuse_light(WorldData world_data, vec3 N)
+{
+ vec4 result = world_data.diffuse_light_x_pos * clamp(N.x, 0.0, 1.0);
+ result = mix(result, world_data.diffuse_light_x_neg, clamp(-N.x, 0.0, 1.0));
+ result = mix(result, world_data.diffuse_light_y_pos, clamp( N.y, 0.0, 1.0));
+ result = mix(result, world_data.diffuse_light_y_neg, clamp(-N.y, 0.0, 1.0));
+ result = mix(result, world_data.diffuse_light_z_pos, clamp( N.z, 0.0, 1.0));
+ return mix(result, world_data.diffuse_light_z_neg, clamp(-N.z, 0.0, 1.0)).xyz;
+}
diff --git a/source/blender/draw/engines/workbench/solid_mode.c b/source/blender/draw/engines/workbench/solid_mode.c
new file mode 100644
index 00000000000..c001cd13bb8
--- /dev/null
+++ b/source/blender/draw/engines/workbench/solid_mode.c
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file solid_mode.c
+ * \ingroup draw_engine
+ *
+ * Simple engine for drawing color and/or depth.
+ * When we only need simple studio shaders.
+ */
+
+#include "DRW_render.h"
+
+#include "GPU_shader.h"
+
+#include "workbench_private.h"
+
+/* Functions */
+
+static void workbench_solid_engine_init(void *vedata)
+{
+ WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
+ workbench_materials_engine_init(data);
+}
+
+static void workbench_solid_cache_init(void *vedata)
+{
+
+ WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
+ workbench_materials_cache_init(data);
+}
+
+static void workbench_solid_cache_populate(void *vedata, Object *ob)
+{
+ WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
+ workbench_materials_solid_cache_populate(data, ob);
+}
+
+static void workbench_solid_cache_finish(void *vedata)
+{
+ WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
+ workbench_materials_cache_finish(data);
+}
+
+static void workbench_solid_draw_background(void *vedata)
+{
+ WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
+ workbench_materials_draw_background(data);
+}
+
+static void workbench_solid_draw_scene(void *vedata)
+{
+ WORKBENCH_Data * data = (WORKBENCH_Data *)vedata;
+ workbench_materials_draw_scene(data);
+}
+
+static void workbench_solid_engine_free(void)
+{
+ workbench_materials_engine_free();
+}
+
+static const DrawEngineDataSize workbench_data_size = DRW_VIEWPORT_DATA_SIZE(WORKBENCH_Data);
+
+DrawEngineType draw_engine_workbench_solid = {
+ NULL, NULL,
+ N_("Workbench"),
+ &workbench_data_size,
+ &workbench_solid_engine_init,
+ &workbench_solid_engine_free,
+ &workbench_solid_cache_init,
+ &workbench_solid_cache_populate,
+ &workbench_solid_cache_finish,
+ &workbench_solid_draw_background,
+ &workbench_solid_draw_scene,
+ NULL,
+ NULL,
+ NULL,
+};
+
diff --git a/source/blender/draw/engines/workbench/workbench_engine.c b/source/blender/draw/engines/workbench/workbench_engine.c
new file mode 100644
index 00000000000..40d5c2b12f9
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_engine.c
@@ -0,0 +1,77 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file workbench_engine.c
+ * \ingroup draw_engine
+ *
+ * Simple engine for drawing color and/or depth.
+ * When we only need simple flat shaders.
+ */
+
+#include "DRW_render.h"
+
+#include "BKE_icons.h"
+#include "BKE_idprop.h"
+#include "BKE_main.h"
+
+#include "GPU_shader.h"
+
+#include "workbench_engine.h"
+#include "workbench_private.h"
+/* Shaders */
+
+#define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
+
+
+/* Functions */
+
+static void workbench_layer_collection_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
+{
+ BLI_assert(props &&
+ props->type == IDP_GROUP &&
+ props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
+
+ BKE_collection_engine_property_add_float(props, "random_object_color_saturation", 0.5f);
+ BKE_collection_engine_property_add_float(props, "random_object_color_value", 0.9f);
+}
+
+static void workbench_view_layer_settings_create(RenderEngine *UNUSED(engine), IDProperty *props)
+{
+ BLI_assert(props &&
+ props->type == IDP_GROUP &&
+ props->subtype == IDP_GROUP_SUB_ENGINE_RENDER);
+
+ const float light_direction[3] = {-0.577350269, -0.577350269, 0.577350269};
+ BKE_collection_engine_property_add_float_array(props, "light_direction", light_direction, 3); UNUSED_VARS_NDEBUG(props);
+}
+
+/* Note: currently unused, we may want to register so we can see this when debugging the view. */
+
+RenderEngineType DRW_engine_viewport_workbench_type = {
+ NULL, NULL,
+ WORKBENCH_ENGINE, N_("Workbench"), RE_INTERNAL,
+ NULL, NULL, NULL, NULL, NULL, NULL, NULL, &workbench_layer_collection_settings_create, &workbench_view_layer_settings_create,
+ &draw_engine_workbench_solid,
+ {NULL, NULL, NULL}
+};
+
+
+#undef WORKBENCH_ENGINE
diff --git a/source/blender/draw/engines/workbench/workbench_engine.h b/source/blender/draw/engines/workbench/workbench_engine.h
new file mode 100644
index 00000000000..0cbbe8df4af
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_engine.h
@@ -0,0 +1,32 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file workbench_engine.h
+ * \ingroup draw_engine
+ */
+
+#ifndef __WORKBENCH_ENGINE_H__
+#define __WORKBENCH_ENGINE_H__
+
+extern DrawEngineType draw_engine_workbench_solid;
+extern RenderEngineType DRW_engine_viewport_workbench_type;
+
+#endif /* __WORKBENCH_ENGINE_H__ */
diff --git a/source/blender/draw/engines/workbench/workbench_materials.c b/source/blender/draw/engines/workbench/workbench_materials.c
new file mode 100644
index 00000000000..b9c51552b50
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_materials.c
@@ -0,0 +1,627 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file workbench_materials.c
+ * \ingroup draw_engine
+ */
+
+#include "workbench_private.h"
+
+#include "BIF_gl.h"
+
+#include "BLI_alloca.h"
+#include "BLI_dynstr.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_node.h"
+#include "BKE_particle.h"
+
+#include "DNA_image_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_node_types.h"
+
+#include "ED_uvedit.h"
+
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "UI_resources.h"
+
+/* *********** STATIC *********** */
+
+// #define DEBUG_SHADOW_VOLUME
+#define MAX_SHADERS 255
+
+static struct {
+ struct GPUShader *prepass_sh_cache[MAX_SHADERS];
+ struct GPUShader *composite_sh_cache[MAX_SHADERS];
+ struct GPUShader *shadow_sh;
+
+ struct GPUTexture *object_id_tx; /* ref only, not alloced */
+ struct GPUTexture *color_buffer_tx; /* ref only, not alloced */
+ struct GPUTexture *normal_buffer_tx; /* ref only, not alloced */
+ struct GPUTexture *composite_buffer_tx; /* ref only, not alloced */
+
+ float light_direction[3]; /* world light direction for shadows */
+ int next_object_id;
+} e_data = {{NULL}};
+
+/* Shaders */
+extern char datatoc_workbench_prepass_vert_glsl[];
+extern char datatoc_workbench_prepass_frag_glsl[];
+extern char datatoc_workbench_composite_frag_glsl[];
+
+extern char datatoc_workbench_shadow_vert_glsl[];
+extern char datatoc_workbench_shadow_geom_glsl[];
+
+extern char datatoc_workbench_background_lib_glsl[];
+extern char datatoc_workbench_common_lib_glsl[];
+extern char datatoc_workbench_data_lib_glsl[];
+extern char datatoc_workbench_object_overlap_lib_glsl[];
+extern char datatoc_workbench_world_light_lib_glsl[];
+
+extern DrawEngineType draw_engine_workbench_solid;
+
+#define OBJECT_ID_PASS_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_OBJECT_OVERLAP)
+#define NORMAL_VIEWPORT_PASS_ENABLED(wpd) (wpd->shading.light & V3D_LIGHTING_STUDIO)
+#define SHADOW_ENABLED(wpd) (wpd->shading.flag & V3D_SHADING_SHADOW)
+static char *workbench_build_defines(WORKBENCH_PrivateData *wpd, int drawtype)
+{
+ char *str = NULL;
+
+ DynStr *ds = BLI_dynstr_new();
+
+ if (wpd->shading.flag & V3D_SHADING_OBJECT_OVERLAP) {
+ BLI_dynstr_appendf(ds, "#define V3D_SHADING_OBJECT_OVERLAP\n");
+ }
+ if (wpd->shading.light & V3D_LIGHTING_STUDIO) {
+ BLI_dynstr_appendf(ds, "#define V3D_LIGHTING_STUDIO\n");
+ }
+ switch(drawtype) {
+ case OB_SOLID:
+ BLI_dynstr_appendf(ds, "#define OB_SOLID\n");
+ break;
+ case OB_TEXTURE:
+ BLI_dynstr_appendf(ds, "#define OB_TEXTURE\n");
+ break;
+ }
+
+#ifdef WORKBENCH_ENCODE_NORMALS
+ BLI_dynstr_appendf(ds, "#define WORKBENCH_ENCODE_NORMALS\n");
+#endif
+
+ str = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+ return str;
+}
+
+static char *workbench_build_composite_frag(WORKBENCH_PrivateData *wpd)
+{
+ char *str = NULL;
+
+ DynStr *ds = BLI_dynstr_new();
+
+ BLI_dynstr_append(ds, datatoc_workbench_data_lib_glsl);
+ BLI_dynstr_append(ds, datatoc_workbench_common_lib_glsl);
+ BLI_dynstr_append(ds, datatoc_workbench_background_lib_glsl);
+
+ if (wpd->shading.light & V3D_LIGHTING_STUDIO) {
+ BLI_dynstr_append(ds, datatoc_workbench_world_light_lib_glsl);
+ }
+ if (wpd->shading.flag & V3D_SHADING_OBJECT_OVERLAP) {
+ BLI_dynstr_append(ds, datatoc_workbench_object_overlap_lib_glsl);
+ }
+
+ BLI_dynstr_append(ds, datatoc_workbench_composite_frag_glsl);
+
+ str = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+ return str;
+}
+
+static char *workbench_build_prepass_frag(void)
+{
+ char *str = NULL;
+
+ DynStr *ds = BLI_dynstr_new();
+
+ BLI_dynstr_append(ds, datatoc_workbench_common_lib_glsl);
+ BLI_dynstr_append(ds, datatoc_workbench_prepass_frag_glsl);
+
+ str = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
+ return str;
+}
+
+static int get_shader_index(WORKBENCH_PrivateData *wpd, int drawtype)
+{
+ const int DRAWOPTIONS_MASK = V3D_SHADING_OBJECT_OVERLAP;
+ int index = (wpd->shading.flag & DRAWOPTIONS_MASK);
+ index = (index << 2) + wpd->shading.light;
+ /* set the drawtype flag
+ 0 = OB_SOLID,
+ 1 = OB_TEXTURE */
+ index = index << 1;
+ SET_FLAG_FROM_TEST(index, drawtype == OB_TEXTURE, 1);
+ return index;
+}
+
+static void ensure_deferred_shaders(WORKBENCH_PrivateData *wpd, int index, int drawtype) {
+ if (e_data.prepass_sh_cache[index] == NULL) {
+ char *defines = workbench_build_defines(wpd, drawtype);
+ char *composite_frag = workbench_build_composite_frag(wpd);
+ char *prepass_frag = workbench_build_prepass_frag();
+ e_data.prepass_sh_cache[index] = DRW_shader_create(datatoc_workbench_prepass_vert_glsl, NULL, prepass_frag, defines);
+ if (drawtype == OB_SOLID) {
+ e_data.composite_sh_cache[index] = DRW_shader_create_fullscreen(composite_frag, defines);
+ }
+ MEM_freeN(prepass_frag);
+ MEM_freeN(composite_frag);
+ MEM_freeN(defines);
+ }
+}
+
+static void select_deferred_shaders(WORKBENCH_PrivateData *wpd)
+{
+ int index_solid = get_shader_index(wpd, OB_SOLID);
+ int index_texture = get_shader_index(wpd, OB_TEXTURE);
+
+ ensure_deferred_shaders(wpd, index_solid, OB_SOLID);
+ ensure_deferred_shaders(wpd, index_texture, OB_TEXTURE);
+
+ wpd->prepass_solid_sh = e_data.prepass_sh_cache[index_solid];
+ wpd->prepass_texture_sh = e_data.prepass_sh_cache[index_texture];
+ wpd->composite_sh = e_data.composite_sh_cache[index_solid];
+}
+
+/* Functions */
+static uint get_material_hash(WORKBENCH_MaterialData *material_template)
+{
+ /* TODO: make a C-string with settings and hash the string */
+ uint input[4];
+ uint result;
+ float *color = material_template->color;
+ input[0] = (uint)(color[0] * 512);
+ input[1] = (uint)(color[1] * 512);
+ input[2] = (uint)(color[2] * 512);
+ input[3] = material_template->object_id;
+ result = BLI_ghashutil_uinthash_v4_murmur(input);
+
+ if (material_template->drawtype == OB_TEXTURE) {
+ /* add texture reference */
+ result += BLI_ghashutil_inthash_p_murmur(material_template->ima);
+ }
+ return result;
+}
+
+static void workbench_init_object_data(ObjectEngineData *engine_data)
+{
+ WORKBENCH_ObjectData *data = (WORKBENCH_ObjectData *)engine_data;
+ data->object_id = e_data.next_object_id++;
+}
+
+static void get_material_solid_color(WORKBENCH_PrivateData *wpd, Object *ob, Material *mat, float *color, float hsv_saturation, float hsv_value)
+{
+ /* When in OB_TEXTURE always uyse V3D_SHADING_MATERIAL_COLOR as fallback when no texture could be determined */
+ int color_type = wpd->drawtype == OB_SOLID? wpd->shading.color_type:V3D_SHADING_MATERIAL_COLOR;
+ static float default_color[] = {0.8f, 0.8f, 0.8f};
+ if (DRW_object_is_paint_mode(ob) || color_type == V3D_SHADING_SINGLE_COLOR) {
+ copy_v3_v3(color, wpd->shading.single_color);
+ }
+ else if (color_type == V3D_SHADING_RANDOM_COLOR) {
+ uint hash = BLI_ghashutil_strhash_p_murmur(ob->id.name);
+ if (ob->id.lib) {
+ hash = (hash * 13) ^ BLI_ghashutil_strhash_p_murmur(ob->id.lib->name);
+ }
+ float offset = fmodf((hash / 100000.0) * M_GOLDEN_RATION_CONJUGATE, 1.0);
+
+ float hsv[3] = {offset, hsv_saturation, hsv_value};
+ hsv_to_rgb_v(hsv, color);
+ }
+ else if (color_type == V3D_SHADING_OBJECT_COLOR) {
+ copy_v3_v3(color, ob->col);
+ }
+ else {
+ /* V3D_SHADING_MATERIAL_COLOR */
+ if (mat) {
+ copy_v3_v3(color, &mat->r);
+ }
+ else {
+ copy_v3_v3(color, default_color);
+ }
+ }
+}
+
+void workbench_materials_engine_init(WORKBENCH_Data *vedata)
+{
+ WORKBENCH_FramebufferList *fbl = vedata->fbl;
+ WORKBENCH_StorageList *stl = vedata->stl;
+ WORKBENCH_PassList *psl = vedata->psl;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ if (!e_data.next_object_id) {
+ memset(e_data.prepass_sh_cache, 0x00, sizeof(struct GPUShader *) * MAX_SHADERS);
+ memset(e_data.composite_sh_cache, 0x00, sizeof(struct GPUShader *) * MAX_SHADERS);
+ e_data.next_object_id = 1;
+ e_data.shadow_sh = DRW_shader_create(datatoc_workbench_shadow_vert_glsl, datatoc_workbench_shadow_geom_glsl, NULL, NULL);
+ }
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ const float *viewport_size = DRW_viewport_size_get();
+ const int size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+ e_data.object_id_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_R32UI, &draw_engine_workbench_solid);
+ e_data.color_buffer_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8, &draw_engine_workbench_solid);
+ e_data.composite_buffer_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA16F, &draw_engine_workbench_solid);
+#ifdef WORKBENCH_ENCODE_NORMALS
+ e_data.normal_buffer_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RG8, &draw_engine_workbench_solid);
+#else
+ e_data.normal_buffer_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA32F, &draw_engine_workbench_solid);
+#endif
+
+ GPU_framebuffer_ensure_config(&fbl->prepass_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(e_data.object_id_tx),
+ GPU_ATTACHMENT_TEXTURE(e_data.color_buffer_tx),
+ GPU_ATTACHMENT_TEXTURE(e_data.normal_buffer_tx),
+ });
+ GPU_framebuffer_ensure_config(&fbl->composite_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(e_data.composite_buffer_tx),
+ });
+ }
+
+ /* Prepass */
+ {
+ int state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ psl->prepass_pass = DRW_pass_create("Prepass", state);
+ }
+}
+
+void workbench_materials_engine_free()
+{
+ for (int index = 0; index < MAX_SHADERS; index ++) {
+ DRW_SHADER_FREE_SAFE(e_data.prepass_sh_cache[index]);
+ DRW_SHADER_FREE_SAFE(e_data.composite_sh_cache[index]);
+ }
+ DRW_SHADER_FREE_SAFE(e_data.shadow_sh);
+}
+
+static void workbench_composite_uniforms(WORKBENCH_PrivateData *wpd, DRWShadingGroup *grp)
+{
+ DRW_shgroup_uniform_texture_ref(grp, "colorBuffer", &e_data.color_buffer_tx);
+ DRW_shgroup_uniform_texture_ref(grp, "objectId", &e_data.object_id_tx);
+ if (NORMAL_VIEWPORT_PASS_ENABLED(wpd)) {
+ DRW_shgroup_uniform_texture_ref(grp, "normalBuffer", &e_data.normal_buffer_tx);
+ }
+ DRW_shgroup_uniform_block(grp, "world_block", wpd->world_ubo);
+ DRW_shgroup_uniform_vec2(grp, "invertedViewportSize", DRW_viewport_invert_size_get(), 1);
+}
+
+void workbench_materials_cache_init(WORKBENCH_Data *vedata)
+{
+ WORKBENCH_StorageList *stl = vedata->stl;
+ WORKBENCH_PassList *psl = vedata->psl;
+ WORKBENCH_PrivateData *wpd = stl->g_data;
+ DRWShadingGroup *grp;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ IDProperty *props = BKE_view_layer_engine_evaluated_get(view_layer, RE_engine_id_BLENDER_WORKBENCH);
+ static float shadow_multiplier = 0.0f;
+
+ const DRWContextState *DCS = DRW_context_state_get();
+
+ wpd->material_hash = BLI_ghash_ptr_new(__func__);
+
+ View3D *v3d = DCS->v3d;
+ if (v3d) {
+ wpd->shading = v3d->shading;
+ wpd->drawtype = v3d->drawtype;
+ }
+ else {
+ /* XXX: We should get the default shading from the view layer, after we implemented the render callback */
+ memset(&wpd->shading, 0, sizeof(wpd->shading));
+ wpd->shading.light = V3D_LIGHTING_STUDIO;
+ wpd->shading.shadow_intensity = 0.5;
+ copy_v3_fl(wpd->shading.single_color, 0.8f);
+ wpd->drawtype = OB_SOLID;
+ }
+
+ select_deferred_shaders(wpd);
+ /* Deferred Mix Pass */
+ {
+ WORKBENCH_UBO_World *wd = &wpd->world_data;
+ UI_GetThemeColor3fv(UI_GetThemeValue(TH_SHOW_BACK_GRAD) ? TH_LOW_GRAD:TH_HIGH_GRAD, wd->background_color_low);
+ UI_GetThemeColor3fv(TH_HIGH_GRAD, wd->background_color_high);
+
+ /* XXX: Really quick conversion to avoid washed out background.
+ * Needs to be adressed properly (color managed using ocio). */
+ srgb_to_linearrgb_v3_v3(wd->background_color_high, wd->background_color_high);
+ srgb_to_linearrgb_v3_v3(wd->background_color_low, wd->background_color_low);
+
+ studiolight_update_world(wpd->shading.studio_light, wd);
+
+ wpd->world_ubo = DRW_uniformbuffer_create(sizeof(WORKBENCH_UBO_World), NULL);
+ DRW_uniformbuffer_update(wpd->world_ubo, &wpd->world_data);
+
+ copy_v3_v3(e_data.light_direction, BKE_collection_engine_property_value_get_float_array(props, "light_direction"));
+ negate_v3(e_data.light_direction);
+
+ if (SHADOW_ENABLED(wpd)) {
+ psl->composite_pass = DRW_pass_create("Composite", DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_EQUAL);
+ grp = DRW_shgroup_create(wpd->composite_sh, psl->composite_pass);
+ workbench_composite_uniforms(wpd, grp);
+ DRW_shgroup_stencil_mask(grp, 0x00);
+ DRW_shgroup_uniform_float(grp, "shadowMultiplier", &shadow_multiplier, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+
+#ifdef DEBUG_SHADOW_VOLUME
+ psl->shadow_pass = DRW_pass_create("Shadow", DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK | DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_create(e_data.shadow_sh, psl->shadow_pass);
+ DRW_shgroup_uniform_vec3(grp, "lightDirection", e_data.light_direction, 1);
+ DRW_shgroup_stencil_mask(grp, 0xFF);
+ wpd->shadow_shgrp = grp;
+#else
+ psl->shadow_pass = DRW_pass_create("Shadow", DRW_STATE_DEPTH_GREATER | DRW_STATE_WRITE_STENCIL_SHADOW);
+ grp = DRW_shgroup_create(e_data.shadow_sh, psl->shadow_pass);
+ DRW_shgroup_uniform_vec3(grp, "lightDirection", e_data.light_direction, 1);
+ DRW_shgroup_stencil_mask(grp, 0xFF);
+ wpd->shadow_shgrp = grp;
+
+ psl->composite_shadow_pass = DRW_pass_create("Composite Shadow", DRW_STATE_WRITE_COLOR | DRW_STATE_STENCIL_NEQUAL);
+ grp = DRW_shgroup_create(wpd->composite_sh, psl->composite_shadow_pass);
+ DRW_shgroup_stencil_mask(grp, 0x00);
+ workbench_composite_uniforms(wpd, grp);
+ DRW_shgroup_uniform_float(grp, "shadowMultiplier", &wpd->shading.shadow_intensity, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+#endif
+ }
+ else {
+ psl->composite_pass = DRW_pass_create("Composite", DRW_STATE_WRITE_COLOR);
+ grp = DRW_shgroup_create(wpd->composite_sh, psl->composite_pass);
+ workbench_composite_uniforms(wpd, grp);
+ DRW_shgroup_uniform_float(grp, "shadowMultiplier", &shadow_multiplier, 1);
+ DRW_shgroup_call_add(grp, DRW_cache_fullscreen_quad_get(), NULL);
+ }
+ }
+}
+static WORKBENCH_MaterialData *get_or_create_material_data(WORKBENCH_Data *vedata, IDProperty *props, Object *ob, Material *mat, Image *ima, int drawtype)
+{
+ WORKBENCH_StorageList *stl = vedata->stl;
+ WORKBENCH_PassList *psl = vedata->psl;
+ WORKBENCH_PrivateData *wpd = stl->g_data;
+ WORKBENCH_MaterialData *material;
+ WORKBENCH_ObjectData *engine_object_data = (WORKBENCH_ObjectData *)DRW_object_engine_data_ensure(
+ ob, &draw_engine_workbench_solid, sizeof(WORKBENCH_ObjectData), &workbench_init_object_data, NULL);
+ WORKBENCH_MaterialData material_template;
+ const float hsv_saturation = BKE_collection_engine_property_value_get_float(props, "random_object_color_saturation");
+ const float hsv_value = BKE_collection_engine_property_value_get_float(props, "random_object_color_value");
+
+ /* Solid */
+ get_material_solid_color(wpd, ob, mat, material_template.color, hsv_saturation, hsv_value);
+ material_template.object_id = engine_object_data->object_id;
+ material_template.drawtype = drawtype;
+ material_template.ima = ima;
+ unsigned int hash = get_material_hash(&material_template);
+
+ material = BLI_ghash_lookup(wpd->material_hash, SET_UINT_IN_POINTER(hash));
+ if (material == NULL) {
+ material = MEM_mallocN(sizeof(WORKBENCH_MaterialData), __func__);
+ material->shgrp = DRW_shgroup_create(drawtype == OB_SOLID?wpd->prepass_solid_sh:wpd->prepass_texture_sh, psl->prepass_pass);
+ DRW_shgroup_stencil_mask(material->shgrp, 0xFF);
+ material->object_id = engine_object_data->object_id;
+ copy_v3_v3(material->color, material_template.color);
+ switch(drawtype) {
+ case OB_SOLID:
+ DRW_shgroup_uniform_vec3(material->shgrp, "object_color", material->color, 1);
+ break;
+
+ case OB_TEXTURE:
+ {
+ GPUTexture *tex = GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, false, false);
+ DRW_shgroup_uniform_texture(material->shgrp, "image", tex);
+ break;
+ }
+ }
+ DRW_shgroup_uniform_int(material->shgrp, "object_id", &material->object_id, 1);
+ BLI_ghash_insert(wpd->material_hash, SET_UINT_IN_POINTER(hash), material);
+ }
+ return material;
+}
+
+static void workbench_cache_populate_particles(WORKBENCH_Data *vedata, IDProperty *props, Object *ob)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ if (ob != draw_ctx->object_edit) {
+ for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
+ if (md->type == eModifierType_ParticleSystem) {
+ ParticleSystem *psys = ((ParticleSystemModifierData *)md)->psys;
+
+ if (psys_check_enabled(ob, psys, false)) {
+ ParticleSettings *part = psys->part;
+ int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
+
+ if (draw_as == PART_DRAW_PATH && !psys->pathcache && !psys->childcache) {
+ draw_as = PART_DRAW_DOT;
+ }
+
+ static float mat[4][4];
+ unit_m4(mat);
+
+ if (draw_as == PART_DRAW_PATH) {
+ struct Gwn_Batch *geom = DRW_cache_particles_get_hair(psys, NULL);
+ WORKBENCH_MaterialData *material = get_or_create_material_data(vedata, props, ob, NULL, NULL, OB_SOLID);
+ DRW_shgroup_call_add(material->shgrp, geom, mat);
+ }
+ }
+ }
+ }
+ }
+}
+
+void workbench_materials_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob)
+{
+ WORKBENCH_StorageList *stl = vedata->stl;
+ WORKBENCH_PrivateData *wpd = stl->g_data;
+
+ if (!DRW_object_is_renderable(ob))
+ return;
+
+ IDProperty *props = BKE_layer_collection_engine_evaluated_get(ob, RE_engine_id_BLENDER_WORKBENCH);
+ if (ob->type == OB_MESH) {
+ workbench_cache_populate_particles(vedata, props, ob);
+ }
+
+ WORKBENCH_MaterialData *material;
+ if (ELEM(ob->type, OB_MESH, OB_CURVE, OB_SURF, OB_FONT)) {
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const bool is_active = (ob == draw_ctx->obact);
+ const bool is_sculpt_mode = is_active && (draw_ctx->object_mode & OB_MODE_SCULPT) != 0;
+ bool is_drawn = false;
+
+ if (!is_sculpt_mode && wpd->drawtype == OB_TEXTURE && ob->type == OB_MESH)
+ {
+ const Mesh *me = ob->data;
+ if (me->mloopuv) {
+ struct Gwn_Batch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
+ const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
+ struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
+ if (materials_len > 0 && geom_array) {
+ for (int i = 0; i < materials_len; i++) {
+ Material *mat = give_current_material(ob, i + 1);
+ Image *image;
+ ED_object_get_active_image(ob, i + 1, &image, NULL, NULL, NULL);
+ /* use OB_SOLID when no texture could be determined */
+ int mat_drawtype = OB_SOLID;
+ if (image) {
+ mat_drawtype = OB_TEXTURE;
+ }
+ material = get_or_create_material_data(vedata, props, ob, mat, image, mat_drawtype);
+ DRW_shgroup_call_add(material->shgrp, geom_array[i], ob->obmat);
+ }
+ is_drawn = true;
+ }
+ }
+ }
+
+ /* Fallback from not drawn OB_TEXTURE mode or just OB_SOLID mode */
+ if (!is_drawn) {
+ if ((wpd->shading.color_type != V3D_SHADING_MATERIAL_COLOR) || is_sculpt_mode) {
+ /* No material split needed */
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
+ if (geom) {
+ material = get_or_create_material_data(vedata, props, ob, NULL, NULL, OB_SOLID);
+ if (is_sculpt_mode) {
+ DRW_shgroup_call_sculpt_add(material->shgrp, ob, ob->obmat);
+ }
+ else {
+ DRW_shgroup_call_object_add(material->shgrp, geom, ob);
+ }
+ }
+ }
+ else { /* MATERIAL colors */
+ const int materials_len = MAX2(1, (is_sculpt_mode ? 1 : ob->totcol));
+ struct GPUMaterial **gpumat_array = BLI_array_alloca(gpumat_array, materials_len);
+ for (int i = 0; i < materials_len; i ++) {
+ gpumat_array[i] = NULL;
+ }
+
+ struct Gwn_Batch **mat_geom = DRW_cache_object_surface_material_get(ob, gpumat_array, materials_len, NULL, NULL, NULL);
+ if (mat_geom) {
+ for (int i = 0; i < materials_len; ++i) {
+ Material *mat = give_current_material(ob, i + 1);
+ material = get_or_create_material_data(vedata, props, ob, mat, NULL, OB_SOLID);
+ DRW_shgroup_call_object_add(material->shgrp, mat_geom[i], ob);
+ }
+ }
+ }
+ }
+
+ if (SHADOW_ENABLED(wpd)) {
+ struct Gwn_Batch *geom_shadow = DRW_cache_object_surface_get(ob);
+ if (geom_shadow) {
+ DRW_shgroup_call_object_add(wpd->shadow_shgrp, geom_shadow, ob);
+ }
+ }
+ }
+}
+
+void workbench_materials_cache_finish(WORKBENCH_Data *UNUSED(vedata))
+{
+}
+
+void workbench_materials_draw_background(WORKBENCH_Data *vedata)
+{
+ WORKBENCH_StorageList *stl = vedata->stl;
+ WORKBENCH_FramebufferList *fbl = vedata->fbl;
+ WORKBENCH_PrivateData *wpd = stl->g_data;
+ const float clear_depth = 1.0f;
+ const float clear_color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ unsigned int clear_stencil = 0xFF;
+
+ GPU_framebuffer_bind(fbl->prepass_fb);
+ int clear_bits = GPU_DEPTH_BIT | GPU_COLOR_BIT;
+ SET_FLAG_FROM_TEST(clear_bits, SHADOW_ENABLED(wpd), GPU_STENCIL_BIT);
+ GPU_framebuffer_clear(fbl->prepass_fb, clear_bits, clear_color, clear_depth, clear_stencil);
+}
+
+void workbench_materials_draw_scene(WORKBENCH_Data *vedata)
+{
+ WORKBENCH_PassList *psl = vedata->psl;
+ WORKBENCH_StorageList *stl = vedata->stl;
+ WORKBENCH_FramebufferList *fbl = vedata->fbl;
+ WORKBENCH_PrivateData *wpd = stl->g_data;
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+
+ /* clear in background */
+ GPU_framebuffer_bind(fbl->prepass_fb);
+ DRW_draw_pass(psl->prepass_pass);
+ if (SHADOW_ENABLED(wpd)) {
+#ifdef DEBUG_SHADOW_VOLUME
+ GPU_framebuffer_bind(dfbl->default_fb);
+ DRW_draw_pass(psl->composite_pass);
+ DRW_draw_pass(psl->shadow_pass);
+#else
+ GPU_framebuffer_bind(dfbl->depth_only_fb);
+ DRW_draw_pass(psl->shadow_pass);
+ GPU_framebuffer_bind(fbl->composite_fb);
+ DRW_draw_pass(psl->composite_pass);
+ DRW_draw_pass(psl->composite_shadow_pass);
+#endif
+ }
+ else {
+ GPU_framebuffer_bind(fbl->composite_fb);
+ DRW_draw_pass(psl->composite_pass);
+ }
+
+ GPU_framebuffer_bind(dfbl->color_only_fb);
+ DRW_transform_to_display(e_data.composite_buffer_tx);
+
+ BLI_ghash_free(wpd->material_hash, NULL, MEM_freeN);
+ DRW_UBO_FREE_SAFE(wpd->world_ubo);
+
+}
diff --git a/source/blender/draw/engines/workbench/workbench_private.h b/source/blender/draw/engines/workbench/workbench_private.h
new file mode 100644
index 00000000000..76f8f7bfd05
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_private.h
@@ -0,0 +1,132 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file workbench_private.h
+ * \ingroup draw_engine
+ */
+
+#ifndef __WORKBENCH_PRIVATE_H__
+#define __WORKBENCH_PRIVATE_H__
+
+
+#include "DNA_image_types.h"
+#include "DNA_view3d_types.h"
+
+#include "DRW_render.h"
+
+
+#define WORKBENCH_ENGINE "BLENDER_WORKBENCH"
+#define M_GOLDEN_RATION_CONJUGATE 0.618033988749895
+#define WORKBENCH_ENCODE_NORMALS
+
+
+typedef struct WORKBENCH_FramebufferList {
+ struct GPUFrameBuffer *prepass_fb;
+ struct GPUFrameBuffer *composite_fb;
+} WORKBENCH_FramebufferList;
+
+typedef struct WORKBENCH_StorageList {
+ struct WORKBENCH_PrivateData *g_data;
+} WORKBENCH_StorageList;
+
+typedef struct WORKBENCH_PassList {
+ struct DRWPass *prepass_pass;
+ struct DRWPass *shadow_pass;
+ struct DRWPass *composite_pass;
+ struct DRWPass *composite_shadow_pass;
+ struct DRWPass *composite_light_pass;
+} WORKBENCH_PassList;
+
+typedef struct WORKBENCH_Data {
+ void *engine_type;
+ WORKBENCH_FramebufferList *fbl;
+ DRWViewportEmptyList *txl;
+ WORKBENCH_PassList *psl;
+ WORKBENCH_StorageList *stl;
+} WORKBENCH_Data;
+
+typedef struct WORKBENCH_UBO_World {
+ float diffuse_light_x_pos[4];
+ float diffuse_light_x_neg[4];
+ float diffuse_light_y_pos[4];
+ float diffuse_light_y_neg[4];
+ float diffuse_light_z_pos[4];
+ float diffuse_light_z_neg[4];
+ float background_color_low[4];
+ float background_color_high[4];
+} WORKBENCH_UBO_World;
+BLI_STATIC_ASSERT_ALIGN(WORKBENCH_UBO_World, 16)
+
+typedef struct WORKBENCH_PrivateData {
+ struct GHash *material_hash;
+ struct GPUShader *prepass_solid_sh;
+ struct GPUShader *prepass_texture_sh;
+ struct GPUShader *composite_sh;
+ View3DShading shading;
+ int drawtype;
+ struct GPUUniformBuffer *world_ubo;
+ struct DRWShadingGroup *shadow_shgrp;
+ WORKBENCH_UBO_World world_data;
+} WORKBENCH_PrivateData; /* Transient data */
+
+typedef struct WORKBENCH_MaterialData {
+ /* Solid color */
+ float color[3];
+ int object_id;
+ int drawtype;
+ Image* ima;
+
+ /* Linked shgroup for drawing */
+ DRWShadingGroup *shgrp;
+} WORKBENCH_MaterialData;
+
+typedef struct WORKBENCH_ObjectData {
+ struct ObjectEngineData *next, *prev;
+ struct DrawEngineType *engine_type;
+ /* Only nested data, NOT the engine data itself. */
+ ObjectEngineDataFreeCb free;
+ /* Accumulated recalc flags, which corresponds to ID->recalc flags. */
+ int recalc;
+
+ int object_id;
+} WORKBENCH_ObjectData;
+
+/* workbench_engine.c */
+void workbench_solid_materials_init(WORKBENCH_Data *vedata);
+void workbench_solid_materials_cache_init(WORKBENCH_Data *vedata);
+void workbench_solid_materials_cache_populate(WORKBENCH_Data *vedata, Object *ob);
+void workbench_solid_materials_cache_finish(WORKBENCH_Data *vedata);
+void workbench_solid_materials_draw_scene(WORKBENCH_Data *vedata);
+void workbench_solid_materials_free(void);
+
+/* workbench_materials.c */
+void workbench_materials_engine_init(WORKBENCH_Data *vedata);
+void workbench_materials_engine_free(void);
+void workbench_materials_draw_background(WORKBENCH_Data *vedata);
+void workbench_materials_draw_scene(WORKBENCH_Data *vedata);
+void workbench_materials_cache_init(WORKBENCH_Data *vedata);
+void workbench_materials_solid_cache_populate(WORKBENCH_Data *vedata, Object *ob);
+void workbench_materials_cache_finish(WORKBENCH_Data *vedata);
+
+/* workbench_studiolight.c */
+void studiolight_update_world(int studio_light, WORKBENCH_UBO_World* wd);
+
+#endif
diff --git a/source/blender/draw/engines/workbench/workbench_studiolight.c b/source/blender/draw/engines/workbench/workbench_studiolight.c
new file mode 100644
index 00000000000..bb75d12f10f
--- /dev/null
+++ b/source/blender/draw/engines/workbench/workbench_studiolight.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file workbench_studiolight.h
+ * \ingroup draw_engine
+ */
+ #include "DRW_engine.h"
+#include "workbench_private.h"
+
+#include "BLI_math.h"
+
+
+#define STUDIOLIGHT_X_POS 0
+#define STUDIOLIGHT_X_NEG 1
+#define STUDIOLIGHT_Y_POS 2
+#define STUDIOLIGHT_Y_NEG 3
+#define STUDIOLIGHT_Z_POS 4
+#define STUDIOLIGHT_Z_NEG 5
+
+const float studiolights[][6][3] = {
+ {
+ {1.0, 0.8, 0.6},
+ {1.0, 0.6, 0.6},
+ {0.9, 0.9, 1.0},
+ {0.05, 0.025, 0.025},
+ {0.8, 0.8, 0.75},
+ {1.0, 0.95, 0.8},
+ },
+ {
+ {0.0, 0.0, 0.0},
+ {0.0, 0.0, 0.0},
+ {0.0, 0.0, 0.0},
+ {0.0, 0.0, 0.0},
+ {0.8, 0.8, 1.0},
+ {0.0, 0.0, 0.0},
+ },
+ {
+ {0.4, 0.3, 0.8},
+ {0.4, 0.3, 0.8},
+ {0.8, 0.8, 0.2},
+ {0.0, 0.0, 0.0},
+ {0.4, 0.4, 0.8},
+ {0.0, 0.0, 0.0},
+ },
+ {
+ {0.2, 0.2, 0.0},
+ {0.8, 0.2, 0.0},
+ {0.8, 0.2, 0.0},
+ {0.2, 0.2, 0.0},
+ {0.8, 0.6, 0.4},
+ {0.0, 0.0, 0.0},
+ },
+ {
+ {0.8, 0.2, 0.0},
+ {0.8, 0.2, 0.0},
+ {0.8, 0.6, 0.0},
+ {0.2, 0.2, 0.0},
+ {1.0, 0.5, 0.0},
+ {0.0, 0.0, 0.0},
+ },
+};
+
+void studiolight_update_world(int studio_light, WORKBENCH_UBO_World* wd) {
+ copy_v3_v3(wd->diffuse_light_x_pos, studiolights[studio_light][STUDIOLIGHT_X_POS]);
+ copy_v3_v3(wd->diffuse_light_x_neg, studiolights[studio_light][STUDIOLIGHT_X_NEG]);
+ copy_v3_v3(wd->diffuse_light_y_pos, studiolights[studio_light][STUDIOLIGHT_Y_POS]);
+ copy_v3_v3(wd->diffuse_light_y_neg, studiolights[studio_light][STUDIOLIGHT_Y_NEG]);
+ copy_v3_v3(wd->diffuse_light_z_pos, studiolights[studio_light][STUDIOLIGHT_Z_POS]);
+ copy_v3_v3(wd->diffuse_light_z_neg, studiolights[studio_light][STUDIOLIGHT_Z_NEG]);
+}
+
+unsigned int *WORKBENCH_generate_studiolight_preview(int studiolight_id, int icon_size) {
+ unsigned int* rect = MEM_mallocN(icon_size * icon_size * sizeof(unsigned int), __func__);
+ int icon_center = icon_size / 2;
+ float sphere_radius = icon_center * 0.9;
+
+ int offset = 0;
+ for (int y = 0 ; y < icon_size ; y ++) {
+ float dy = y - icon_center;
+ for (int x = 0 ; x < icon_size ; x ++) {
+ float dx = x - icon_center;
+ /* calculate aliasing */
+ float alias = 0;
+ const float alias_step = 0.2;
+ for (float ay = dy - 0.5; ay < dy + 0.5 ; ay += alias_step) {
+ for (float ax = dx - 0.5; ax < dx + 0.5 ; ax += alias_step) {
+ if (sqrt(ay*ay + ax*ax) < sphere_radius) {
+ alias += alias_step*alias_step;
+ }
+ }
+ }
+ unsigned int pixelresult = 0x0;
+ unsigned int alias_i = clamp_i(alias * 256, 0, 255);
+ if (alias_i != 0) {
+ /* calculate normal */
+ unsigned int alias_mask = alias_i << 24;
+ float normal[3];
+ normal[0] = dx / sphere_radius;
+ normal[1] = dy / sphere_radius;
+ normal[2] = sqrt(-(normal[0]*normal[0])-(normal[1]*normal[1]) + 1);
+ normalize_v3(normal);
+
+ float color[3];
+ mul_v3_v3fl(color, studiolights[studiolight_id][STUDIOLIGHT_X_POS], clamp_f(normal[0], 0.0, 1.0));
+ interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_X_NEG], clamp_f(-normal[0], 0.0, 1.0));
+ interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_Y_POS], clamp_f(normal[1], 0.0, 1.0));
+ interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_Y_NEG], clamp_f(-normal[1], 0.0, 1.0));
+ interp_v3_v3v3(color, color, studiolights[studiolight_id][STUDIOLIGHT_Z_POS], clamp_f(normal[2], 0.0, 1.0));
+
+ pixelresult = rgb_to_cpack(
+ linearrgb_to_srgb(color[0]),
+ linearrgb_to_srgb(color[1]),
+ linearrgb_to_srgb(color[2])
+ ) | alias_mask;
+ }
+ rect[offset++] = pixelresult;
+ }
+ }
+ return rect;
+}
diff --git a/source/blender/draw/intern/DRW_render.h b/source/blender/draw/intern/DRW_render.h
new file mode 100644
index 00000000000..75562a8d4d6
--- /dev/null
+++ b/source/blender/draw/intern/DRW_render.h
@@ -0,0 +1,528 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file DRW_render.h
+ * \ingroup draw
+ */
+
+/* This is the Render Functions used by Realtime engines to draw with OpenGL */
+
+#ifndef __DRW_RENDER_H__
+#define __DRW_RENDER_H__
+
+#include "BLI_listbase.h"
+#include "BLI_math_matrix.h"
+#include "BLI_math_vector.h"
+#include "BLI_string.h"
+
+#include "BKE_context.h"
+#include "BKE_layer.h"
+#include "BKE_material.h"
+#include "BKE_scene.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_object_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_material_types.h"
+#include "DNA_scene_types.h"
+
+#include "GPU_framebuffer.h"
+#include "GPU_texture.h"
+
+#include "draw_common.h"
+#include "draw_cache.h"
+#include "draw_view.h"
+
+#include "draw_manager_profiling.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RE_engine.h"
+
+#include "DEG_depsgraph.h"
+
+struct rcti;
+struct bContext;
+struct GPUFrameBuffer;
+struct GPUShader;
+struct GPUMaterial;
+struct GPUTexture;
+struct GPUUniformBuffer;
+struct Object;
+struct Gwn_Batch;
+struct DefaultFramebufferList;
+struct DefaultTextureList;
+struct DRWTextStore;
+struct LampEngineData;
+struct RenderEngineType;
+struct ViewportEngineData;
+struct ViewportEngineData_Info;
+
+typedef struct DRWUniform DRWUniform;
+typedef struct DRWInterface DRWInterface;
+typedef struct DRWPass DRWPass;
+typedef struct DRWShadingGroup DRWShadingGroup;
+
+/* TODO Put it somewhere else? */
+typedef struct BoundSphere {
+ float center[3], radius;
+} BoundSphere;
+
+/* declare members as empty (unused) */
+typedef char DRWViewportEmptyList;
+
+#define DRW_VIEWPORT_LIST_SIZE(list) \
+ (sizeof(list) == sizeof(DRWViewportEmptyList) ? 0 : ((sizeof(list)) / sizeof(void *)))
+
+/* Unused members must be either pass list or 'char *' when not usd. */
+#define DRW_VIEWPORT_DATA_SIZE(ty) { \
+ DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->fbl)), \
+ DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->txl)), \
+ DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->psl)), \
+ DRW_VIEWPORT_LIST_SIZE(*(((ty *)NULL)->stl)) \
+}
+
+/* Use of multisample framebuffers. */
+#define MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl) { \
+ if (dfbl->multisample_fb != NULL) { \
+ DRW_stats_query_start("Multisample Blit"); \
+ GPU_framebuffer_bind(dfbl->multisample_fb); \
+ /* TODO clear only depth but need to do alpha to coverage for transparencies. */ \
+ GPU_framebuffer_clear_color_depth(dfbl->multisample_fb, (const float[4]){0.0f}, 1.0f); \
+ DRW_stats_query_end(); \
+ } \
+}
+
+#define MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl) { \
+ if (dfbl->multisample_fb != NULL) { \
+ DRW_stats_query_start("Multisample Resolve"); \
+ GPU_framebuffer_bind(dfbl->default_fb); \
+ DRW_multisamples_resolve(dtxl->multisample_depth, dtxl->multisample_color); \
+ DRW_stats_query_end(); \
+ } \
+}
+
+
+
+typedef struct DrawEngineDataSize {
+ int fbl_len;
+ int txl_len;
+ int psl_len;
+ int stl_len;
+} DrawEngineDataSize;
+
+typedef struct DrawEngineType {
+ struct DrawEngineType *next, *prev;
+
+ char idname[32];
+
+ const DrawEngineDataSize *vedata_size;
+
+ void (*engine_init)(void *vedata);
+ void (*engine_free)(void);
+
+ void (*cache_init)(void *vedata);
+ void (*cache_populate)(void *vedata, struct Object *ob);
+ void (*cache_finish)(void *vedata);
+
+ void (*draw_background)(void *vedata);
+ void (*draw_scene)(void *vedata);
+
+ void (*view_update)(void *vedata);
+ void (*id_update)(void *vedata, struct ID *id);
+
+ void (*render_to_image)(void *vedata, struct RenderEngine *engine, struct RenderLayer *layer, const struct rcti *rect);
+} DrawEngineType;
+
+#ifndef __DRW_ENGINE_H__
+/* Buffer and textures used by the viewport by default */
+typedef struct DefaultFramebufferList {
+ struct GPUFrameBuffer *default_fb;
+ struct GPUFrameBuffer *color_only_fb;
+ struct GPUFrameBuffer *depth_only_fb;
+ struct GPUFrameBuffer *multisample_fb;
+} DefaultFramebufferList;
+
+typedef struct DefaultTextureList {
+ struct GPUTexture *color;
+ struct GPUTexture *depth;
+ struct GPUTexture *multisample_color;
+ struct GPUTexture *multisample_depth;
+} DefaultTextureList;
+#endif
+
+/* Textures */
+typedef enum {
+ DRW_TEX_FILTER = (1 << 0),
+ DRW_TEX_WRAP = (1 << 1),
+ DRW_TEX_COMPARE = (1 << 2),
+ DRW_TEX_MIPMAP = (1 << 3),
+} DRWTextureFlag;
+
+/* Textures from DRW_texture_pool_query_* have the options
+ * DRW_TEX_FILTER for color float textures, and no options
+ * for depth textures and integer textures. */
+struct GPUTexture *DRW_texture_pool_query_2D(int w, int h, GPUTextureFormat format, DrawEngineType *engine_type);
+
+struct GPUTexture *DRW_texture_create_1D(
+ int w, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
+struct GPUTexture *DRW_texture_create_2D(
+ int w, int h, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
+struct GPUTexture *DRW_texture_create_2D_array(
+ int w, int h, int d, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
+struct GPUTexture *DRW_texture_create_3D(
+ int w, int h, int d, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
+struct GPUTexture *DRW_texture_create_cube(
+ int w, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels);
+
+void DRW_texture_ensure_fullscreen_2D(
+ struct GPUTexture **tex, GPUTextureFormat format, DRWTextureFlag flags);
+void DRW_texture_ensure_2D(
+ struct GPUTexture **tex, int w, int h, GPUTextureFormat format, DRWTextureFlag flags);
+
+void DRW_texture_generate_mipmaps(struct GPUTexture *tex);
+void DRW_texture_free(struct GPUTexture *tex);
+#define DRW_TEXTURE_FREE_SAFE(tex) do { \
+ if (tex != NULL) { \
+ DRW_texture_free(tex); \
+ tex = NULL; \
+ } \
+} while (0)
+
+/* UBOs */
+struct GPUUniformBuffer *DRW_uniformbuffer_create(int size, const void *data);
+void DRW_uniformbuffer_update(struct GPUUniformBuffer *ubo, const void *data);
+void DRW_uniformbuffer_free(struct GPUUniformBuffer *ubo);
+#define DRW_UBO_FREE_SAFE(ubo) do { \
+ if (ubo != NULL) { \
+ DRW_uniformbuffer_free(ubo); \
+ ubo = NULL; \
+ } \
+} while (0)
+
+void DRW_transform_to_display(struct GPUTexture *tex);
+void DRW_multisamples_resolve(
+ struct GPUTexture *src_depth, struct GPUTexture *src_color);
+
+/* Shaders */
+struct GPUShader *DRW_shader_create(
+ const char *vert, const char *geom, const char *frag, const char *defines);
+struct GPUShader *DRW_shader_create_with_lib(
+ const char *vert, const char *geom, const char *frag, const char *lib, const char *defines);
+struct GPUShader *DRW_shader_create_2D(const char *frag, const char *defines);
+struct GPUShader *DRW_shader_create_3D(const char *frag, const char *defines);
+struct GPUShader *DRW_shader_create_fullscreen(const char *frag, const char *defines);
+struct GPUShader *DRW_shader_create_3D_depth_only(void);
+struct GPUMaterial *DRW_shader_find_from_world(struct World *wo, const void *engine_type, int options);
+struct GPUMaterial *DRW_shader_find_from_material(struct Material *ma, const void *engine_type, int options);
+struct GPUMaterial *DRW_shader_create_from_world(
+ struct Scene *scene, struct World *wo, const void *engine_type, int options,
+ const char *vert, const char *geom, const char *frag_lib, const char *defines);
+struct GPUMaterial *DRW_shader_create_from_material(
+ struct Scene *scene, struct Material *ma, const void *engine_type, int options,
+ const char *vert, const char *geom, const char *frag_lib, const char *defines);
+void DRW_shader_free(struct GPUShader *shader);
+#define DRW_SHADER_FREE_SAFE(shader) do { \
+ if (shader != NULL) { \
+ DRW_shader_free(shader); \
+ shader = NULL; \
+ } \
+} while (0)
+
+/* Batches */
+
+typedef enum {
+ DRW_STATE_WRITE_DEPTH = (1 << 0),
+ DRW_STATE_WRITE_COLOR = (1 << 1),
+ DRW_STATE_DEPTH_LESS = (1 << 2),
+ DRW_STATE_DEPTH_EQUAL = (1 << 3),
+ DRW_STATE_DEPTH_GREATER = (1 << 4),
+ DRW_STATE_DEPTH_ALWAYS = (1 << 5),
+ DRW_STATE_CULL_BACK = (1 << 6),
+ DRW_STATE_CULL_FRONT = (1 << 7),
+ DRW_STATE_WIRE = (1 << 8),
+// DRW_STATE_WIRE_LARGE = (1 << 9), /* Removed from ogl in 3.0 */
+ DRW_STATE_POINT = (1 << 10),
+ DRW_STATE_STIPPLE_2 = (1 << 11),
+ DRW_STATE_STIPPLE_3 = (1 << 12),
+ DRW_STATE_STIPPLE_4 = (1 << 13),
+ DRW_STATE_BLEND = (1 << 14),
+ DRW_STATE_ADDITIVE = (1 << 15),
+ DRW_STATE_MULTIPLY = (1 << 16),
+ DRW_STATE_TRANSMISSION = (1 << 17),
+ DRW_STATE_CLIP_PLANES = (1 << 18),
+ DRW_STATE_ADDITIVE_FULL = (1 << 19), /* Same as DRW_STATE_ADDITIVE but let alpha accumulate without premult. */
+ DRW_STATE_BLEND_PREMUL = (1 << 20), /* Use that if color is already premult by alpha. */
+ DRW_STATE_WIRE_SMOOTH = (1 << 21),
+
+ DRW_STATE_WRITE_STENCIL = (1 << 27),
+ DRW_STATE_WRITE_STENCIL_SHADOW = (1 << 28),
+ DRW_STATE_STENCIL_EQUAL = (1 << 29),
+ DRW_STATE_STENCIL_NEQUAL = (1 << 30),
+} DRWState;
+#define DRW_STATE_DEFAULT (DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS)
+
+typedef enum {
+ DRW_ATTRIB_INT,
+ DRW_ATTRIB_FLOAT,
+} DRWAttribType;
+
+typedef struct DRWInstanceAttribFormat {
+ char name[32];
+ DRWAttribType type;
+ int components;
+} DRWInstanceAttribFormat;
+
+struct Gwn_VertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttribFormat attribs[], int arraysize);
+#define DRW_shgroup_instance_format(format, ...) do { \
+ if (format == NULL) { \
+ DRWInstanceAttribFormat drw_format[] = __VA_ARGS__;\
+ format = DRW_shgroup_instance_format_array(drw_format, (sizeof(drw_format) / sizeof(DRWInstanceAttribFormat))); \
+ } \
+} while (0)
+
+DRWShadingGroup *DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass);
+DRWShadingGroup *DRW_shgroup_material_create(struct GPUMaterial *material, DRWPass *pass);
+DRWShadingGroup *DRW_shgroup_material_instance_create(
+ struct GPUMaterial *material, DRWPass *pass, struct Gwn_Batch *geom, struct Object *ob,
+ struct Gwn_VertFormat *format);
+DRWShadingGroup *DRW_shgroup_material_empty_tri_batch_create(struct GPUMaterial *material, DRWPass *pass, int size);
+DRWShadingGroup *DRW_shgroup_instance_create(
+ struct GPUShader *shader, DRWPass *pass, struct Gwn_Batch *geom, struct Gwn_VertFormat *format);
+DRWShadingGroup *DRW_shgroup_point_batch_create(struct GPUShader *shader, DRWPass *pass);
+DRWShadingGroup *DRW_shgroup_line_batch_create(struct GPUShader *shader, DRWPass *pass);
+DRWShadingGroup *DRW_shgroup_empty_tri_batch_create(struct GPUShader *shader, DRWPass *pass, int size);
+
+typedef void (DRWCallGenerateFn)(
+ DRWShadingGroup *shgroup,
+ void (*draw_fn)(DRWShadingGroup *shgroup, struct Gwn_Batch *geom),
+ void *user_data);
+
+/* return final visibility */
+typedef bool (DRWCallVisibilityFn)(
+ bool vis_in,
+ void *user_data);
+
+void DRW_shgroup_instance_batch(DRWShadingGroup *shgroup, struct Gwn_Batch *batch);
+
+void DRW_shgroup_free(struct DRWShadingGroup *shgroup);
+void DRW_shgroup_call_add(DRWShadingGroup *shgroup, struct Gwn_Batch *geom, float (*obmat)[4]);
+void DRW_shgroup_call_object_add(DRWShadingGroup *shgroup, struct Gwn_Batch *geom, struct Object *ob);
+void DRW_shgroup_call_object_add_with_callback(
+ DRWShadingGroup *shgroup, struct Gwn_Batch *geom, struct Object *ob,
+ DRWCallVisibilityFn *callback, void *user_data);
+/* Used for drawing a batch with instancing without instance attribs. */
+void DRW_shgroup_call_instances_add(
+ DRWShadingGroup *shgroup, struct Gwn_Batch *geom, float (*obmat)[4], unsigned int *count);
+void DRW_shgroup_call_object_instances_add(
+ DRWShadingGroup *shgroup, struct Gwn_Batch *geom, struct Object *ob, unsigned int *count);
+void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shgroup, struct Object *ob, float (*obmat)[4]);
+void DRW_shgroup_call_generate_add(
+ DRWShadingGroup *shgroup, DRWCallGenerateFn *geometry_fn, void *user_data, float (*obmat)[4]);
+void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *attr[], unsigned int attr_len);
+#define DRW_shgroup_call_dynamic_add(shgroup, ...) do { \
+ const void *array[] = {__VA_ARGS__}; \
+ DRW_shgroup_call_dynamic_add_array(shgroup, array, (sizeof(array) / sizeof(*array))); \
+} while (0)
+
+unsigned int DRW_shgroup_get_instance_count(const DRWShadingGroup *shgroup);
+
+void DRW_shgroup_state_enable(DRWShadingGroup *shgroup, DRWState state);
+void DRW_shgroup_state_disable(DRWShadingGroup *shgroup, DRWState state);
+void DRW_shgroup_stencil_mask(DRWShadingGroup *shgroup, unsigned int mask);
+
+void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const struct GPUTexture *tex);
+void DRW_shgroup_uniform_texture_persistent(DRWShadingGroup *shgroup, const char *name, const struct GPUTexture *tex);
+void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const struct GPUUniformBuffer *ubo);
+void DRW_shgroup_uniform_block_persistent(DRWShadingGroup *shgroup, const char *name, const struct GPUUniformBuffer *ubo);
+void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, struct GPUTexture **tex);
+void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
+void DRW_shgroup_uniform_vec2(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
+void DRW_shgroup_uniform_vec3(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
+void DRW_shgroup_uniform_vec4(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize);
+void DRW_shgroup_uniform_short_to_int(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize);
+void DRW_shgroup_uniform_short_to_float(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize);
+/* Boolean are expected to be 4bytes longs for opengl! */
+void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
+void DRW_shgroup_uniform_int(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
+void DRW_shgroup_uniform_ivec2(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
+void DRW_shgroup_uniform_ivec3(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize);
+void DRW_shgroup_uniform_mat3(DRWShadingGroup *shgroup, const char *name, const float (*value)[3]);
+void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const float (*value)[4]);
+/* Store value instead of referencing it. */
+void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value);
+
+/* Passes */
+DRWPass *DRW_pass_create(const char *name, DRWState state);
+void DRW_pass_state_set(DRWPass *pass, DRWState state);
+void DRW_pass_state_add(DRWPass *pass, DRWState state);
+void DRW_pass_state_remove(DRWPass *pass, DRWState state);
+void DRW_pass_foreach_shgroup(DRWPass *pass, void (*callback)(void *userData, DRWShadingGroup *shgrp), void *userData);
+void DRW_pass_sort_shgroup_z(DRWPass *pass);
+
+/* Viewport */
+typedef enum {
+ DRW_MAT_PERS = 0,
+ DRW_MAT_PERSINV,
+ DRW_MAT_VIEW,
+ DRW_MAT_VIEWINV,
+ DRW_MAT_WIN,
+ DRW_MAT_WININV,
+
+ DRW_MAT_COUNT, // Don't use this.
+} DRWViewportMatrixType;
+
+typedef struct DRWMatrixState {
+ float mat[DRW_MAT_COUNT][4][4];
+} DRWMatrixState;
+
+void DRW_viewport_init(const bContext *C);
+void DRW_viewport_matrix_get(float mat[4][4], DRWViewportMatrixType type);
+void DRW_viewport_matrix_get_all(DRWMatrixState *state);
+void DRW_viewport_matrix_override_set(const float mat[4][4], DRWViewportMatrixType type);
+void DRW_viewport_matrix_override_set_all(DRWMatrixState *state);
+void DRW_viewport_matrix_override_unset(DRWViewportMatrixType type);
+void DRW_viewport_matrix_override_unset_all(void);
+
+/* Thoses are in viewspace so negative if in persp.
+ * Extract near and far clip distance from the projection matrix. */
+float DRW_viewport_near_distance_get(void);
+float DRW_viewport_far_distance_get(void);
+
+const float *DRW_viewport_size_get(void);
+const float *DRW_viewport_invert_size_get(void);
+const float *DRW_viewport_screenvecs_get(void);
+const float *DRW_viewport_pixelsize_get(void);
+bool DRW_viewport_is_persp_get(void);
+
+struct DefaultFramebufferList *DRW_viewport_framebuffer_list_get(void);
+struct DefaultTextureList *DRW_viewport_texture_list_get(void);
+
+void DRW_viewport_request_redraw(void);
+
+void DRW_render_to_image(struct RenderEngine *engine, struct Depsgraph *graph);
+void DRW_render_object_iter(
+ void *vedata, struct RenderEngine *engine, struct Depsgraph *graph,
+ void (*callback)(void *vedata, struct Object *ob, struct RenderEngine *engine, struct Depsgraph *graph));
+void DRW_render_instance_buffer_finish(void);
+
+/* ViewLayers */
+void *DRW_view_layer_engine_data_get(DrawEngineType *engine_type);
+void **DRW_view_layer_engine_data_ensure(DrawEngineType *engine_type, void (*callback)(void *storage));
+
+/* Objects */
+ObjectEngineData *DRW_object_engine_data_get(Object *ob, DrawEngineType *engine_type);
+ObjectEngineData *DRW_object_engine_data_ensure(
+ Object *ob,
+ DrawEngineType *engine_type,
+ size_t size,
+ ObjectEngineDataInitCb init_cb,
+ ObjectEngineDataFreeCb free_cb);
+struct LampEngineData *DRW_lamp_engine_data_ensure(Object *ob, struct RenderEngineType *engine_type);
+void DRW_lamp_engine_data_free(struct LampEngineData *led);
+
+/* Settings */
+bool DRW_object_is_renderable(struct Object *ob);
+bool DRW_check_object_visible_within_active_context(struct Object *ob);
+bool DRW_object_is_flat_normal(const struct Object *ob);
+int DRW_object_is_mode_shade(const struct Object *ob);
+int DRW_object_is_paint_mode(const struct Object *ob);
+
+/* Draw commands */
+void DRW_draw_pass(DRWPass *pass);
+void DRW_draw_pass_subset(DRWPass *pass, DRWShadingGroup *start_group, DRWShadingGroup *end_group);
+
+void DRW_draw_text_cache_queue(struct DRWTextStore *dt);
+
+void DRW_draw_callbacks_pre_scene(void);
+void DRW_draw_callbacks_post_scene(void);
+
+int DRW_draw_region_engine_info_offset(void);
+void DRW_draw_region_engine_info(void);
+
+void DRW_state_reset_ex(DRWState state);
+void DRW_state_reset(void);
+void DRW_state_lock(DRWState state);
+
+void DRW_state_invert_facing(void);
+
+void DRW_state_clip_planes_count_set(unsigned int plane_ct);
+void DRW_state_clip_planes_reset(void);
+
+/* Culling, return true if object is inside view frustum. */
+bool DRW_culling_sphere_test(BoundSphere *bsphere);
+bool DRW_culling_box_test(BoundBox *bbox);
+bool DRW_culling_plane_test(float plane[4]);
+
+/* Selection */
+void DRW_select_load_id(unsigned int id);
+
+/* Draw State */
+void DRW_state_dfdy_factors_get(float dfdyfac[2]);
+bool DRW_state_is_fbo(void);
+bool DRW_state_is_select(void);
+bool DRW_state_is_depth(void);
+bool DRW_state_is_image_render(void);
+bool DRW_state_is_scene_render(void);
+bool DRW_state_is_opengl_render(void);
+bool DRW_state_show_text(void);
+bool DRW_state_draw_support(void);
+bool DRW_state_draw_background(void);
+
+enum eDepsObjectIteratorMode DRW_iterator_mode_get(void);
+
+struct DRWTextStore *DRW_state_text_cache_get(void);
+
+/* Avoid too many lookups while drawing */
+typedef struct DRWContextState {
+
+ struct ARegion *ar; /* 'CTX_wm_region(C)' */
+ struct RegionView3D *rv3d; /* 'CTX_wm_region_view3d(C)' */
+ struct View3D *v3d; /* 'CTX_wm_view3d(C)' */
+
+ struct Scene *scene; /* 'CTX_data_scene(C)' */
+ struct ViewLayer *view_layer; /* 'CTX_data_view_layer(C)' */
+
+ /* Use 'object_edit' for edit-mode */
+ struct Object *obact; /* 'OBACT' */
+
+ struct RenderEngineType *engine_type;
+
+ struct Depsgraph *depsgraph;
+
+ eObjectMode object_mode;
+
+ /* Last resort (some functions take this as an arg so we can't easily avoid).
+ * May be NULL when used for selection or depth buffer. */
+ const struct bContext *evil_C;
+
+ /* ---- */
+
+ /* Cache: initialized by 'drw_context_state_init'. */
+ struct Object *object_pose;
+ struct Object *object_edit;
+
+} DRWContextState;
+
+const DRWContextState *DRW_context_state_get(void);
+
+#endif /* __DRW_RENDER_H__ */
diff --git a/source/blender/draw/intern/draw_armature.c b/source/blender/draw/intern/draw_armature.c
new file mode 100644
index 00000000000..1a2ff70624b
--- /dev/null
+++ b/source/blender/draw/intern/draw_armature.c
@@ -0,0 +1,1636 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_armature.c
+ * \ingroup draw
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+#include "DNA_anim_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_object_types.h"
+
+#include "DRW_render.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_dlrbTree.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_animsys.h"
+#include "BKE_action.h"
+#include "BKE_armature.h"
+#include "BKE_global.h"
+#include "BKE_modifier.h"
+#include "BKE_nla.h"
+#include "BKE_curve.h"
+
+#include "BIF_gl.h"
+
+#include "ED_armature.h"
+#include "ED_keyframes_draw.h"
+
+#include "GPU_select.h"
+
+#include "UI_resources.h"
+
+#include "draw_common.h"
+#include "draw_manager_text.h"
+
+#define BONE_VAR(eBone, pchan, var) ((eBone) ? (eBone->var) : (pchan->var))
+#define BONE_FLAG(eBone, pchan) ((eBone) ? (eBone->flag) : (pchan->bone->flag))
+
+#define PT_DEFAULT_RAD 0.05f /* radius of the point batch. */
+
+/* For now just match 2.7x where possible. */
+// #define USE_SOLID_COLOR
+
+/* Reset for drawing each armature object */
+static struct {
+ /* Current armature object */
+ Object *ob;
+ /* Reset when changing current_armature */
+ DRWShadingGroup *bone_octahedral_solid;
+ DRWShadingGroup *bone_octahedral_wire;
+ DRWShadingGroup *bone_octahedral_outline;
+ DRWShadingGroup *bone_box_solid;
+ DRWShadingGroup *bone_box_wire;
+ DRWShadingGroup *bone_box_outline;
+ DRWShadingGroup *bone_wire_wire;
+ DRWShadingGroup *bone_envelope_solid;
+ DRWShadingGroup *bone_envelope_distance;
+ DRWShadingGroup *bone_envelope_wire;
+ DRWShadingGroup *bone_point_solid;
+ DRWShadingGroup *bone_point_wire;
+ DRWShadingGroup *bone_axes;
+ DRWShadingGroup *lines_relationship;
+ DRWShadingGroup *lines_ik;
+ DRWShadingGroup *lines_ik_no_target;
+ DRWShadingGroup *lines_ik_spline;
+
+ DRWArmaturePasses passes;
+} g_data = {NULL};
+
+
+/**
+ * Follow `TH_*` naming except for mixed colors.
+ */
+static struct {
+ float select_color[4];
+ float edge_select_color[4];
+ float bone_select_color[4]; /* tint */
+ float wire_color[4];
+ float wire_edit_color[4];
+ float bone_solid_color[4];
+ float bone_active_unselect_color[4]; /* mix */
+ float bone_pose_color[4];
+ float bone_pose_active_color[4];
+ float bone_pose_active_unselect_color[4]; /* mix */
+ float text_hi_color[4];
+ float text_color[4];
+ float vertex_select_color[4];
+ float vertex_color[4];
+
+ /* not a theme, this is an override */
+ const float *const_color;
+ float const_wire;
+} g_theme;
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Shader Groups (DRW_shgroup)
+ * \{ */
+
+/* Octahedral */
+static void drw_shgroup_bone_octahedral(
+ const float (*bone_mat)[4],
+ const float bone_color[4], const float hint_color[4], const float outline_color[4])
+{
+ if (g_data.bone_octahedral_outline == NULL) {
+ struct Gwn_Batch *geom = DRW_cache_bone_octahedral_get();
+ g_data.bone_octahedral_outline = shgroup_instance_bone_shape_outline(g_data.passes.bone_outline, geom);
+ }
+ if (g_data.bone_octahedral_solid == NULL) {
+ struct Gwn_Batch *geom = DRW_cache_bone_octahedral_get();
+ g_data.bone_octahedral_solid = shgroup_instance_bone_shape_solid(g_data.passes.bone_solid, geom);
+ }
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ DRW_shgroup_call_dynamic_add(g_data.bone_octahedral_solid, final_bonemat, bone_color, hint_color);
+ if (outline_color[3] > 0.0f) {
+ DRW_shgroup_call_dynamic_add(g_data.bone_octahedral_outline, final_bonemat, outline_color);
+ }
+}
+
+/* Box / B-Bone */
+static void drw_shgroup_bone_box(
+ const float (*bone_mat)[4],
+ const float bone_color[4], const float hint_color[4], const float outline_color[4])
+{
+ if (g_data.bone_box_wire == NULL) {
+ struct Gwn_Batch *geom = DRW_cache_bone_box_get();
+ g_data.bone_box_outline = shgroup_instance_bone_shape_outline(g_data.passes.bone_outline, geom);
+ }
+ if (g_data.bone_box_solid == NULL) {
+ struct Gwn_Batch *geom = DRW_cache_bone_box_get();
+ g_data.bone_box_solid = shgroup_instance_bone_shape_solid(g_data.passes.bone_solid, geom);
+ }
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ DRW_shgroup_call_dynamic_add(g_data.bone_box_solid, final_bonemat, bone_color, hint_color);
+ if (outline_color[3] > 0.0f) {
+ DRW_shgroup_call_dynamic_add(g_data.bone_box_outline, final_bonemat, outline_color);
+ }
+}
+
+/* Wire */
+static void drw_shgroup_bone_wire_wire(const float (*bone_mat)[4], const float color[4])
+{
+ if (g_data.bone_wire_wire == NULL) {
+ struct Gwn_Batch *geom = DRW_cache_bone_wire_wire_outline_get();
+ g_data.bone_wire_wire = shgroup_instance_wire(g_data.passes.bone_wire, geom);
+ }
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ DRW_shgroup_call_dynamic_add(g_data.bone_wire_wire, final_bonemat, color);
+}
+
+/* Envelope */
+static void drw_shgroup_bone_envelope_distance(
+ const float (*bone_mat)[4],
+ const float *radius_head, const float *radius_tail, const float *distance)
+{
+ if (g_data.passes.bone_envelope != NULL) {
+ if (g_data.bone_envelope_distance == NULL) {
+ g_data.bone_envelope_distance = shgroup_instance_bone_envelope_distance(g_data.passes.bone_envelope);
+ /* passes.bone_envelope should have the DRW_STATE_CULL_FRONT state enabled. */
+ }
+ float head_sphere[4] = {0.0f, 0.0f, 0.0f, 1.0f}, tail_sphere[4] = {0.0f, 1.0f, 0.0f, 1.0f};
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ /* We need matrix mul because we need shear applied. */
+ /* NOTE: could be done in shader if that becomes a bottleneck. */
+ mul_m4_v4(final_bonemat, head_sphere);
+ mul_m4_v4(final_bonemat, tail_sphere);
+ head_sphere[3] = *radius_head;
+ head_sphere[3] += *distance;
+ tail_sphere[3] = *radius_tail;
+ tail_sphere[3] += *distance;
+ DRW_shgroup_call_dynamic_add(g_data.bone_envelope_distance, head_sphere, tail_sphere, final_bonemat[0]);
+ }
+}
+
+static void drw_shgroup_bone_envelope(
+ const float (*bone_mat)[4],
+ const float bone_color[4], const float hint_color[4], const float outline_color[4],
+ const float *radius_head, const float *radius_tail)
+{
+ if (g_data.bone_point_wire == NULL) {
+ g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire);
+ }
+ if (g_data.bone_point_solid == NULL) {
+ g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.passes.bone_solid);
+ }
+ if (g_data.bone_envelope_wire == NULL) {
+ g_data.bone_envelope_wire = shgroup_instance_bone_envelope_outline(g_data.passes.bone_wire);
+ }
+ if (g_data.bone_envelope_solid == NULL) {
+ g_data.bone_envelope_solid = shgroup_instance_bone_envelope_solid(g_data.passes.bone_solid);
+ /* We can have a lot of overdraw if we don't do this. Also envelope are not subject to
+ * inverted matrix. */
+ DRW_shgroup_state_enable(g_data.bone_envelope_solid, DRW_STATE_CULL_BACK);
+ }
+
+ float head_sphere[4] = {0.0f, 0.0f, 0.0f, 1.0f}, tail_sphere[4] = {0.0f, 1.0f, 0.0f, 1.0f};
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ mul_m4_v4(final_bonemat, head_sphere);
+ mul_m4_v4(final_bonemat, tail_sphere);
+ head_sphere[3] = *radius_head;
+ tail_sphere[3] = *radius_tail;
+
+ if (head_sphere[3] < 0.0f) {
+ /* Draw Tail only */
+ float tmp[4][4] = {{0.0f}};
+ tmp[0][0] = tmp[1][1] = tmp[2][2] = tail_sphere[3] / PT_DEFAULT_RAD;
+ tmp[3][3] = 1.0f;
+ copy_v3_v3(tmp[3], tail_sphere);
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
+ if (outline_color[3] > 0.0f) {
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, tmp, outline_color);
+ }
+ }
+ else if (tail_sphere[3] < 0.0f) {
+ /* Draw Head only */
+ float tmp[4][4] = {{0.0f}};
+ tmp[0][0] = tmp[1][1] = tmp[2][2] = head_sphere[3] / PT_DEFAULT_RAD;
+ tmp[3][3] = 1.0f;
+ copy_v3_v3(tmp[3], head_sphere);
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
+ if (outline_color[3] > 0.0f) {
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, tmp, outline_color);
+ }
+ }
+ else {
+ /* Draw Body */
+ float tmp_sphere[4];
+ float len = len_v3v3(tail_sphere, head_sphere);
+ float fac_head = (len - head_sphere[3]) / len;
+ float fac_tail = (len - tail_sphere[3]) / len;
+
+ /* Small epsilon to avoid problem with float precison in shader. */
+ if (len > (tail_sphere[3] + head_sphere[3]) + 1e-8f) {
+
+ copy_v4_v4(tmp_sphere, head_sphere);
+ interp_v4_v4v4(head_sphere, tail_sphere, head_sphere, fac_head);
+ interp_v4_v4v4(tail_sphere, tmp_sphere, tail_sphere, fac_tail);
+ DRW_shgroup_call_dynamic_add(
+ g_data.bone_envelope_solid, head_sphere, tail_sphere, bone_color, hint_color, final_bonemat[0]);
+ if (outline_color[3] > 0.0f) {
+ DRW_shgroup_call_dynamic_add(
+ g_data.bone_envelope_wire, head_sphere, tail_sphere, outline_color, final_bonemat[0]);
+ }
+ }
+ else {
+ float tmp[4][4] = {{0.0f}};
+ float fac = max_ff(fac_head, 1.0f - fac_tail);
+ interp_v4_v4v4(tmp_sphere, tail_sphere, head_sphere, clamp_f(fac, 0.0f, 1.0f));
+ tmp[0][0] = tmp[1][1] = tmp[2][2] = tmp_sphere[3] / PT_DEFAULT_RAD;
+ tmp[3][3] = 1.0f;
+ copy_v3_v3(tmp[3], tmp_sphere);
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, tmp, bone_color, hint_color);
+ if (outline_color[3] > 0.0f) {
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, tmp, outline_color);
+ }
+ }
+ }
+}
+
+/* Custom (geometry) */
+
+static void drw_shgroup_bone_custom_solid(const float (*bone_mat)[4], const float color[4], Object *custom)
+{
+ /* grr, not re-using instances! */
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(custom);
+ if (geom) {
+ DRWShadingGroup *shgrp_geom_solid = shgroup_instance_solid(g_data.passes.bone_solid, geom);
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ DRW_shgroup_call_dynamic_add(shgrp_geom_solid, final_bonemat, color);
+ }
+}
+
+static void drw_shgroup_bone_custom_wire(const float (*bone_mat)[4], const float color[4], Object *custom)
+{
+ /* grr, not re-using instances! */
+ struct Gwn_Batch *geom = DRW_cache_object_wire_outline_get(custom);
+ if (geom) {
+ DRWShadingGroup *shgrp_geom_wire = shgroup_instance_wire(g_data.passes.bone_wire, geom);
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ DRW_shgroup_call_dynamic_add(shgrp_geom_wire, final_bonemat, color);
+ }
+}
+
+/* Head and tail sphere */
+static void drw_shgroup_bone_point(
+ const float (*bone_mat)[4],
+ const float bone_color[4], const float hint_color[4], const float outline_color[4])
+{
+ if (g_data.bone_point_wire == NULL) {
+ g_data.bone_point_wire = shgroup_instance_bone_sphere_outline(g_data.passes.bone_wire);
+ }
+ if (g_data.bone_point_solid == NULL) {
+ g_data.bone_point_solid = shgroup_instance_bone_sphere_solid(g_data.passes.bone_solid);
+ }
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_solid, final_bonemat, bone_color, hint_color);
+ if (outline_color[3] > 0.0f) {
+ DRW_shgroup_call_dynamic_add(g_data.bone_point_wire, final_bonemat, outline_color);
+ }
+}
+
+/* Axes */
+static void drw_shgroup_bone_axes(const float (*bone_mat)[4], const float color[4])
+{
+ if (g_data.bone_axes == NULL) {
+ g_data.bone_axes = shgroup_instance_bone_axes(g_data.passes.bone_axes);
+ }
+ float final_bonemat[4][4];
+ mul_m4_m4m4(final_bonemat, g_data.ob->obmat, bone_mat);
+ DRW_shgroup_call_dynamic_add(g_data.bone_axes, final_bonemat, color);
+}
+
+/* Relationship lines */
+static void drw_shgroup_bone_relationship_lines(const float start[3], const float end[3])
+{
+ if (g_data.lines_relationship == NULL) {
+ g_data.lines_relationship = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, g_theme.wire_color);
+ }
+ /* reverse order to have less stipple overlap */
+ DRW_shgroup_call_dynamic_add(g_data.lines_relationship, end);
+ DRW_shgroup_call_dynamic_add(g_data.lines_relationship, start);
+}
+
+static void drw_shgroup_bone_ik_lines(const float start[3], const float end[3])
+{
+ if (g_data.lines_ik == NULL) {
+ static float fcolor[4] = {0.8f, 0.5f, 0.0f, 1.0f}; /* add theme! */
+ g_data.lines_ik = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor);
+ }
+ /* reverse order to have less stipple overlap */
+ DRW_shgroup_call_dynamic_add(g_data.lines_ik, end);
+ DRW_shgroup_call_dynamic_add(g_data.lines_ik, start);
+}
+
+static void drw_shgroup_bone_ik_no_target_lines(const float start[3], const float end[3])
+{
+ if (g_data.lines_ik_no_target == NULL) {
+ static float fcolor[4] = {0.8f, 0.8f, 0.2f, 1.0f}; /* add theme! */
+ g_data.lines_ik_no_target = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor);
+ }
+ /* reverse order to have less stipple overlap */
+ DRW_shgroup_call_dynamic_add(g_data.lines_ik_no_target, end);
+ DRW_shgroup_call_dynamic_add(g_data.lines_ik_no_target, start);
+}
+
+static void drw_shgroup_bone_ik_spline_lines(const float start[3], const float end[3])
+{
+ if (g_data.lines_ik_spline == NULL) {
+ static float fcolor[4] = {0.8f, 0.8f, 0.2f, 1.0f}; /* add theme! */
+ g_data.lines_ik_spline = shgroup_dynlines_dashed_uniform_color(g_data.passes.relationship_lines, fcolor);
+ }
+ /* reverse order to have less stipple overlap */
+ DRW_shgroup_call_dynamic_add(g_data.lines_ik_spline, end);
+ DRW_shgroup_call_dynamic_add(g_data.lines_ik_spline, start);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Drawing Theme Helpers
+ *
+ * Note, this section is duplicate of code in 'drawarmature.c'.
+ *
+ * \{ */
+
+/* global here is reset before drawing each bone */
+struct {
+ const ThemeWireColor *bcolor;
+} g_color;
+
+/* values of colCode for set_pchan_color */
+enum {
+ PCHAN_COLOR_NORMAL = 0, /* normal drawing */
+ PCHAN_COLOR_SOLID, /* specific case where "solid" color is needed */
+ PCHAN_COLOR_CONSTS, /* "constraint" colors (which may/may-not be suppressed) */
+
+ PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */
+ PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */
+ PCHAN_COLOR_LINEBONE /* for the middle of line-bones */
+};
+
+/* This function sets the color-set for coloring a certain bone */
+static void set_pchan_colorset(Object *ob, bPoseChannel *pchan)
+{
+ bPose *pose = (ob) ? ob->pose : NULL;
+ bArmature *arm = (ob) ? ob->data : NULL;
+ bActionGroup *grp = NULL;
+ short color_index = 0;
+
+ /* sanity check */
+ if (ELEM(NULL, ob, arm, pose, pchan)) {
+ g_color.bcolor = NULL;
+ return;
+ }
+
+ /* only try to set custom color if enabled for armature */
+ if (arm->flag & ARM_COL_CUSTOM) {
+ /* currently, a bone can only use a custom color set if it's group (if it has one),
+ * has been set to use one
+ */
+ if (pchan->agrp_index) {
+ grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
+ if (grp)
+ color_index = grp->customCol;
+ }
+ }
+
+ /* bcolor is a pointer to the color set to use. If NULL, then the default
+ * color set (based on the theme colors for 3d-view) is used.
+ */
+ if (color_index > 0) {
+ bTheme *btheme = UI_GetTheme();
+ g_color.bcolor = &btheme->tarm[(color_index - 1)];
+ }
+ else if (color_index == -1) {
+ /* use the group's own custom color set (grp is always != NULL here) */
+ g_color.bcolor = &grp->cs;
+ }
+ else {
+ g_color.bcolor = NULL;
+ }
+}
+
+/* This function is for brightening/darkening a given color (like UI_GetThemeColorShade3ubv()) */
+static void cp_shade_color3ub(unsigned char cp[3], const int offset)
+{
+ int r, g, b;
+
+ r = offset + (int) cp[0];
+ CLAMP(r, 0, 255);
+ g = offset + (int) cp[1];
+ CLAMP(g, 0, 255);
+ b = offset + (int) cp[2];
+ CLAMP(b, 0, 255);
+
+ cp[0] = r;
+ cp[1] = g;
+ cp[2] = b;
+}
+
+static void cp_shade_color3f(float cp[3], const float offset)
+{
+ add_v3_fl(cp, offset);
+ CLAMP(cp[0], 0, 255);
+ CLAMP(cp[1], 0, 255);
+ CLAMP(cp[2], 0, 255);
+}
+
+
+/* This function sets the gl-color for coloring a certain bone (based on bcolor) */
+static bool set_pchan_color(short colCode, const int boneflag, const short constflag, float r_color[4])
+{
+ float *fcolor = r_color;
+ const ThemeWireColor *bcolor = g_color.bcolor;
+
+ switch (colCode) {
+ case PCHAN_COLOR_NORMAL:
+ {
+ if (bcolor) {
+ unsigned char cp[4] = {255};
+
+ if (boneflag & BONE_DRAW_ACTIVE) {
+ copy_v3_v3_char((char *)cp, bcolor->active);
+ if (!(boneflag & BONE_SELECTED)) {
+ cp_shade_color3ub(cp, -80);
+ }
+ }
+ else if (boneflag & BONE_SELECTED) {
+ copy_v3_v3_char((char *)cp, bcolor->select);
+ }
+ else {
+ /* a bit darker than solid */
+ copy_v3_v3_char((char *)cp, bcolor->solid);
+ cp_shade_color3ub(cp, -50);
+ }
+
+ rgb_uchar_to_float(fcolor, cp);
+ }
+ else {
+ if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) {
+ UI_GetThemeColor4fv(TH_BONE_POSE_ACTIVE, fcolor);
+ }
+ else if (boneflag & BONE_DRAW_ACTIVE) {
+ UI_GetThemeColorBlendShade4fv(TH_WIRE, TH_BONE_POSE, 0.15f, 0, fcolor);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ UI_GetThemeColor4fv(TH_BONE_POSE, fcolor);
+ }
+ else {
+ UI_GetThemeColor4fv(TH_WIRE, fcolor);
+ }
+ }
+
+ return true;
+ }
+ case PCHAN_COLOR_SOLID:
+ {
+ UI_GetThemeColor4fv(TH_BONE_SOLID, fcolor);
+
+ if (bcolor) {
+ float solid_bcolor[3];
+ rgb_uchar_to_float(solid_bcolor, (unsigned char *)bcolor->solid);
+ interp_v3_v3v3(fcolor, fcolor, solid_bcolor, 1.0f);
+ }
+
+ return true;
+ }
+ case PCHAN_COLOR_CONSTS:
+ {
+ if ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) {
+ unsigned char cp[4];
+ if (constflag & PCHAN_HAS_TARGET) rgba_char_args_set((char *)cp, 255, 150, 0, 80);
+ else if (constflag & PCHAN_HAS_IK) rgba_char_args_set((char *)cp, 255, 255, 0, 80);
+ else if (constflag & PCHAN_HAS_SPLINEIK) rgba_char_args_set((char *)cp, 200, 255, 0, 80);
+ else if (constflag & PCHAN_HAS_CONST) rgba_char_args_set((char *)cp, 0, 255, 120, 80);
+ else {
+ return false;
+ }
+
+ rgba_uchar_to_float(fcolor, cp);
+
+ return true;
+ }
+ return false;
+ }
+ case PCHAN_COLOR_SPHEREBONE_BASE:
+ {
+ if (bcolor) {
+ unsigned char cp[4] = {255};
+
+ if (boneflag & BONE_DRAW_ACTIVE) {
+ copy_v3_v3_char((char *)cp, bcolor->active);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ copy_v3_v3_char((char *)cp, bcolor->select);
+ }
+ else {
+ copy_v3_v3_char((char *)cp, bcolor->solid);
+ }
+
+ rgb_uchar_to_float(fcolor, cp);
+ }
+ else {
+ if (boneflag & BONE_DRAW_ACTIVE) {
+ UI_GetThemeColorShade4fv(TH_BONE_POSE, 40, fcolor);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ UI_GetThemeColor4fv(TH_BONE_POSE, fcolor);
+ }
+ else {
+ UI_GetThemeColor4fv(TH_BONE_SOLID, fcolor);
+ }
+ }
+
+ return true;
+ }
+ case PCHAN_COLOR_SPHEREBONE_END:
+ {
+ if (bcolor) {
+ unsigned char cp[4] = {255};
+
+ if (boneflag & BONE_DRAW_ACTIVE) {
+ copy_v3_v3_char((char *)cp, bcolor->active);
+ cp_shade_color3ub(cp, 10);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ copy_v3_v3_char((char *)cp, bcolor->select);
+ cp_shade_color3ub(cp, -30);
+ }
+ else {
+ copy_v3_v3_char((char *)cp, bcolor->solid);
+ cp_shade_color3ub(cp, -30);
+ }
+
+ rgb_uchar_to_float(fcolor, cp);
+ }
+ else {
+ if (boneflag & BONE_DRAW_ACTIVE) {
+ UI_GetThemeColorShade4fv(TH_BONE_POSE, 10, fcolor);
+ }
+ else if (boneflag & BONE_SELECTED) {
+ UI_GetThemeColorShade4fv(TH_BONE_POSE, -30, fcolor);
+ }
+ else {
+ UI_GetThemeColorShade4fv(TH_BONE_SOLID, -30, fcolor);
+ }
+ }
+ break;
+ }
+ case PCHAN_COLOR_LINEBONE:
+ {
+ /* inner part in background color or constraint */
+ if ((constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS))) {
+ unsigned char cp[4];
+ if (constflag & PCHAN_HAS_TARGET) rgba_char_args_set((char *)cp, 255, 150, 0, 255);
+ else if (constflag & PCHAN_HAS_IK) rgba_char_args_set((char *)cp, 255, 255, 0, 255);
+ else if (constflag & PCHAN_HAS_SPLINEIK) rgba_char_args_set((char *)cp, 200, 255, 0, 255);
+ else if (constflag & PCHAN_HAS_CONST) rgba_char_args_set((char *)cp, 0, 255, 120, 255);
+ else if (constflag) UI_GetThemeColor4ubv(TH_BONE_POSE, cp); /* PCHAN_HAS_ACTION */
+
+ rgb_uchar_to_float(fcolor, cp);
+ }
+ else {
+ if (bcolor) {
+ const char *cp = bcolor->solid;
+ rgb_uchar_to_float(fcolor, (unsigned char *)cp);
+ fcolor[3] = 204.f / 255.f;
+ }
+ else {
+ UI_GetThemeColorShade4fv(TH_BACK, -30, fcolor);
+ }
+ }
+
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Drawing Color Helpers
+ * \{ */
+
+/** See: 'set_pchan_color'*/
+static void update_color(const Object *ob, const float const_color[4])
+{
+ g_theme.const_color = const_color;
+ g_theme.const_wire = ((ob->base_flag & BASE_SELECTED) != 0) ? 1.5f : 0.0f;
+
+#define NO_ALPHA(c) (((c)[3] = 1.0f), (c))
+
+ UI_GetThemeColor3fv(TH_SELECT, NO_ALPHA(g_theme.select_color));
+ UI_GetThemeColor3fv(TH_EDGE_SELECT, NO_ALPHA(g_theme.edge_select_color));
+ UI_GetThemeColorShade3fv(TH_EDGE_SELECT, -20, NO_ALPHA(g_theme.bone_select_color));
+ UI_GetThemeColor3fv(TH_WIRE, NO_ALPHA(g_theme.wire_color));
+ UI_GetThemeColor3fv(TH_WIRE_EDIT, NO_ALPHA(g_theme.wire_edit_color));
+ UI_GetThemeColor3fv(TH_BONE_SOLID, NO_ALPHA(g_theme.bone_solid_color));
+ UI_GetThemeColorBlendShade3fv(TH_WIRE_EDIT, TH_EDGE_SELECT, 0.15f, 0, NO_ALPHA(g_theme.bone_active_unselect_color));
+ UI_GetThemeColor3fv(TH_BONE_POSE, NO_ALPHA(g_theme.bone_pose_color));
+ UI_GetThemeColor3fv(TH_BONE_POSE_ACTIVE, NO_ALPHA(g_theme.bone_pose_active_color));
+ UI_GetThemeColorBlendShade3fv(TH_WIRE, TH_BONE_POSE, 0.15f, 0, NO_ALPHA(g_theme.bone_pose_active_unselect_color));
+ UI_GetThemeColor3fv(TH_TEXT_HI, NO_ALPHA(g_theme.text_hi_color));
+ UI_GetThemeColor3fv(TH_TEXT, NO_ALPHA(g_theme.text_color));
+ UI_GetThemeColor3fv(TH_VERTEX_SELECT, NO_ALPHA(g_theme.vertex_select_color));
+ UI_GetThemeColor3fv(TH_VERTEX, NO_ALPHA(g_theme.vertex_color));
+
+#undef NO_ALPHA
+}
+
+static const float *get_bone_solid_color(
+ const EditBone *UNUSED(eBone), const bPoseChannel *pchan, const bArmature *arm,
+ const int boneflag, const short constflag)
+{
+ if (g_theme.const_color)
+ return g_theme.bone_solid_color;
+
+ if (arm->flag & ARM_POSEMODE) {
+ static float disp_color[4];
+ copy_v4_v4(disp_color, pchan->draw_data->solid_color);
+ set_pchan_color(PCHAN_COLOR_SOLID, boneflag, constflag, disp_color);
+ return disp_color;
+ }
+
+ return g_theme.bone_solid_color;
+}
+
+static const float *get_bone_solid_with_consts_color(
+ const EditBone *eBone, const bPoseChannel *pchan, const bArmature *arm,
+ const int boneflag, const short constflag)
+{
+ if (g_theme.const_color)
+ return g_theme.bone_solid_color;
+
+ const float *col = get_bone_solid_color(eBone, pchan, arm, boneflag, constflag);
+
+ static float consts_color[4];
+ if (set_pchan_color(PCHAN_COLOR_CONSTS, boneflag, constflag, consts_color)) {
+ interp_v3_v3v3(consts_color, col, consts_color, 0.5f);
+ }
+ else {
+ copy_v4_v4(consts_color, col);
+ }
+ return consts_color;
+}
+
+static float get_bone_wire_thickness(int boneflag)
+{
+ if (g_theme.const_color)
+ return g_theme.const_wire;
+ else if (boneflag & (BONE_DRAW_ACTIVE | BONE_SELECTED))
+ return 2.0f;
+ else
+ return 1.0f;
+}
+
+static const float *get_bone_wire_color(
+ const EditBone *eBone, const bPoseChannel *pchan, const bArmature *arm,
+ const int boneflag, const short constflag)
+{
+ static float disp_color[4];
+
+ if (g_theme.const_color) {
+ copy_v3_v3(disp_color, g_theme.const_color);
+ }
+ else if (eBone) {
+ if (boneflag & BONE_SELECTED) {
+ if (boneflag & BONE_DRAW_ACTIVE) {
+ copy_v3_v3(disp_color, g_theme.edge_select_color);
+ }
+ else {
+ copy_v3_v3(disp_color, g_theme.bone_select_color);
+ }
+ }
+ else {
+ if (boneflag & BONE_DRAW_ACTIVE) {
+ copy_v3_v3(disp_color, g_theme.bone_active_unselect_color);
+ }
+ else {
+ copy_v3_v3(disp_color, g_theme.wire_edit_color);
+ }
+ }
+ }
+ else if (arm->flag & ARM_POSEMODE) {
+ copy_v4_v4(disp_color, pchan->draw_data->wire_color);
+ set_pchan_color(PCHAN_COLOR_NORMAL, boneflag, constflag, disp_color);
+ }
+ else {
+ copy_v3_v3(disp_color, g_theme.vertex_color);
+ }
+
+ disp_color[3] = get_bone_wire_thickness(boneflag);
+
+ return disp_color;
+}
+
+#define HINT_MUL 0.5f
+#define HINT_SHADE 0.2f
+
+static void bone_hint_color_shade(float hint_color[4], const float color[4])
+{
+ mul_v3_v3fl(hint_color, color, HINT_MUL);
+ cp_shade_color3f(hint_color, -HINT_SHADE);
+ hint_color[3] = 1.0f;
+}
+
+static const float *get_bone_hint_color(
+ const EditBone *eBone, const bPoseChannel *pchan, const bArmature *arm,
+ const int boneflag, const short constflag)
+{
+ static float hint_color[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+
+ if (g_theme.const_color) {
+ bone_hint_color_shade(hint_color, g_theme.bone_solid_color);
+ }
+ else {
+ const float *wire_color = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
+ bone_hint_color_shade(hint_color, wire_color);
+ }
+
+ return hint_color;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Helper Utils
+ * \{ */
+
+static void pchan_draw_data_init(bPoseChannel *pchan)
+{
+ if (pchan->draw_data != NULL) {
+ if (pchan->draw_data->bbone_matrix_len != pchan->bone->segments) {
+ MEM_SAFE_FREE(pchan->draw_data);
+ }
+ }
+
+ if (pchan->draw_data == NULL) {
+ pchan->draw_data = MEM_mallocN(sizeof(*pchan->draw_data) + sizeof(Mat4) * pchan->bone->segments, __func__);
+ pchan->draw_data->bbone_matrix_len = pchan->bone->segments;
+ }
+}
+
+static void draw_bone_update_disp_matrix_default(EditBone *eBone, bPoseChannel *pchan)
+{
+ float s[4][4], ebmat[4][4];
+ float length;
+ float (*bone_mat)[4];
+ float (*disp_mat)[4];
+ float (*disp_tail_mat)[4];
+
+ /* TODO : This should be moved to depsgraph or armature refresh
+ * and not be tight to the draw pass creation.
+ * This would refresh armature without invalidating the draw cache */
+ if (pchan) {
+ length = pchan->bone->length;
+ bone_mat = pchan->pose_mat;
+ disp_mat = pchan->disp_mat;
+ disp_tail_mat = pchan->disp_tail_mat;
+ }
+ else {
+ eBone->length = len_v3v3(eBone->tail, eBone->head);
+ ED_armature_ebone_to_mat4(eBone, ebmat);
+
+ length = eBone->length;
+ bone_mat = ebmat;
+ disp_mat = eBone->disp_mat;
+ disp_tail_mat = eBone->disp_tail_mat;
+ }
+
+ scale_m4_fl(s, length);
+ mul_m4_m4m4(disp_mat, bone_mat, s);
+ copy_m4_m4(disp_tail_mat, disp_mat);
+ translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f);
+}
+
+/* XXX Direct copy from drawarmature.c... This is ugly! */
+/* A partial copy of b_bone_spline_setup(), with just the parts for previewing editmode curve settings
+ *
+ * This assumes that prev/next bones don't have any impact (since they should all still be in the "straight"
+ * position here anyway), and that we can simply apply the bbone settings to get the desired effect...
+ */
+static void ebone_spline_preview(EditBone *ebone, float result_array[MAX_BBONE_SUBDIV][4][4])
+{
+ float h1[3], h2[3], length, hlength1, hlength2, roll1 = 0.0f, roll2 = 0.0f;
+ float mat3[3][3];
+ float data[MAX_BBONE_SUBDIV + 1][4], *fp;
+ int a;
+
+ length = ebone->length;
+
+ hlength1 = ebone->ease1 * length * 0.390464f; /* 0.5f * sqrt(2) * kappa, the handle length for near-perfect circles */
+ hlength2 = ebone->ease2 * length * 0.390464f;
+
+ /* find the handle points, since this is inside bone space, the
+ * first point = (0, 0, 0)
+ * last point = (0, length, 0)
+ *
+ * we also just apply all the "extra effects", since they're the whole reason we're doing this...
+ */
+ h1[0] = ebone->curveInX;
+ h1[1] = hlength1;
+ h1[2] = ebone->curveInY;
+ roll1 = ebone->roll1;
+
+ h2[0] = ebone->curveOutX;
+ h2[1] = -hlength2;
+ h2[2] = ebone->curveOutY;
+ roll2 = ebone->roll2;
+
+ /* make curve */
+ if (ebone->segments > MAX_BBONE_SUBDIV)
+ ebone->segments = MAX_BBONE_SUBDIV;
+
+ BKE_curve_forward_diff_bezier(0.0f, h1[0], h2[0], 0.0f, data[0], MAX_BBONE_SUBDIV, 4 * sizeof(float));
+ BKE_curve_forward_diff_bezier(0.0f, h1[1], length + h2[1], length, data[0] + 1, MAX_BBONE_SUBDIV, 4 * sizeof(float));
+ BKE_curve_forward_diff_bezier(0.0f, h1[2], h2[2], 0.0f, data[0] + 2, MAX_BBONE_SUBDIV, 4 * sizeof(float));
+ BKE_curve_forward_diff_bezier(roll1, roll1 + 0.390464f * (roll2 - roll1), roll2 - 0.390464f * (roll2 - roll1), roll2, data[0] + 3, MAX_BBONE_SUBDIV, 4 * sizeof(float));
+
+ equalize_bbone_bezier(data[0], ebone->segments); /* note: does stride 4! */
+
+ /* make transformation matrices for the segments for drawing */
+ for (a = 0, fp = data[0]; a < ebone->segments; a++, fp += 4) {
+ sub_v3_v3v3(h1, fp + 4, fp);
+ vec_roll_to_mat3(h1, fp[3], mat3); /* fp[3] is roll */
+
+ copy_m4_m3(result_array[a], mat3);
+ copy_v3_v3(result_array[a][3], fp);
+
+ /* "extra" scale facs... */
+ {
+ const int num_segments = ebone->segments;
+
+ const float scaleFactorIn = 1.0f + (ebone->scaleIn - 1.0f) * ((float)(num_segments - a) / (float)num_segments);
+ const float scaleFactorOut = 1.0f + (ebone->scaleOut - 1.0f) * ((float)(a + 1) / (float)num_segments);
+
+ const float scalefac = scaleFactorIn * scaleFactorOut;
+ float bscalemat[4][4], bscale[3];
+
+ bscale[0] = scalefac;
+ bscale[1] = 1.0f;
+ bscale[2] = scalefac;
+
+ size_to_mat4(bscalemat, bscale);
+
+ /* Note: don't multiply by inverse scale mat here, as it causes problems with scaling shearing and breaking segment chains */
+ mul_m4_series(result_array[a], result_array[a], bscalemat);
+ }
+ }
+}
+
+static void draw_bone_update_disp_matrix_bbone(EditBone *eBone, bPoseChannel *pchan)
+{
+ float s[4][4], ebmat[4][4];
+ float length, xwidth, zwidth;
+ float (*bone_mat)[4];
+ short bbone_segments;
+
+ /* TODO : This should be moved to depsgraph or armature refresh
+ * and not be tight to the draw pass creation.
+ * This would refresh armature without invalidating the draw cache */
+ if (pchan) {
+ length = pchan->bone->length;
+ xwidth = pchan->bone->xwidth;
+ zwidth = pchan->bone->zwidth;
+ bone_mat = pchan->pose_mat;
+ bbone_segments = pchan->bone->segments;
+ }
+ else {
+ eBone->length = len_v3v3(eBone->tail, eBone->head);
+ ED_armature_ebone_to_mat4(eBone, ebmat);
+
+ length = eBone->length;
+ xwidth = eBone->xwidth;
+ zwidth = eBone->zwidth;
+ bone_mat = ebmat;
+ bbone_segments = eBone->segments;
+ }
+
+ size_to_mat4(s, (const float[3]){xwidth, length / bbone_segments, zwidth});
+
+ /* Compute BBones segment matrices... */
+ /* Note that we need this even for one-segment bones, because box drawing need specific weirdo matrix for the box,
+ * that we cannot use to draw end points & co. */
+ if (pchan) {
+ Mat4 *bbones_mat = (Mat4 *)pchan->draw_data->bbone_matrix;
+ if (bbone_segments > 1) {
+ b_bone_spline_setup(pchan, 0, bbones_mat);
+
+ for (int i = bbone_segments; i--; bbones_mat++) {
+ mul_m4_m4m4(bbones_mat->mat, bbones_mat->mat, s);
+ mul_m4_m4m4(bbones_mat->mat, bone_mat, bbones_mat->mat);
+ }
+ }
+ else {
+ mul_m4_m4m4(bbones_mat->mat, bone_mat, s);
+ }
+ }
+ else {
+ float (*bbones_mat)[4][4] = eBone->disp_bbone_mat;
+
+ if (bbone_segments > 1) {
+ ebone_spline_preview(eBone, bbones_mat);
+
+ for (int i = bbone_segments; i--; bbones_mat++) {
+ mul_m4_m4m4(*bbones_mat, *bbones_mat, s);
+ mul_m4_m4m4(*bbones_mat, bone_mat, *bbones_mat);
+ }
+ }
+ else {
+ mul_m4_m4m4(*bbones_mat, bone_mat, s);
+ }
+ }
+
+ /* Grrr... We need default display matrix to draw end points, axes, etc. :( */
+ draw_bone_update_disp_matrix_default(eBone, pchan);
+}
+
+static void draw_bone_update_disp_matrix_custom(bPoseChannel *pchan)
+{
+ float s[4][4];
+ float length;
+ float (*bone_mat)[4];
+ float (*disp_mat)[4];
+ float (*disp_tail_mat)[4];
+
+ /* See TODO above */
+ length = PCHAN_CUSTOM_DRAW_SIZE(pchan);
+ bone_mat = pchan->custom_tx ? pchan->custom_tx->pose_mat : pchan->pose_mat;
+ disp_mat = pchan->disp_mat;
+ disp_tail_mat = pchan->disp_tail_mat;
+
+ scale_m4_fl(s, length);
+ mul_m4_m4m4(disp_mat, bone_mat, s);
+ copy_m4_m4(disp_tail_mat, disp_mat);
+ translate_m4(disp_tail_mat, 0.0f, 1.0f, 0.0f);
+}
+
+static void draw_axes(EditBone *eBone, bPoseChannel *pchan)
+{
+ float final_col[4];
+ const float *col = (g_theme.const_color) ? g_theme.const_color :
+ (BONE_FLAG(eBone, pchan) & BONE_SELECTED) ? g_theme.text_hi_color : g_theme.text_color;
+ copy_v4_v4(final_col, col);
+ final_col[3] = (g_theme.const_color) ? 1.0 : (BONE_FLAG(eBone, pchan) & BONE_SELECTED) ? 0.3 : 0.8; /* Mix with axes color. */
+ drw_shgroup_bone_axes(BONE_VAR(eBone, pchan, disp_mat), final_col);
+}
+
+static void draw_points(
+ const EditBone *eBone, const bPoseChannel *pchan, const bArmature *arm,
+ const int boneflag, const short constflag,
+ const int select_id)
+{
+ float col_solid_root[4], col_solid_tail[4], col_wire_root[4], col_wire_tail[4];
+ float col_hint_root[4], col_hint_tail[4];
+
+ copy_v4_v4(col_solid_root, g_theme.bone_solid_color);
+ copy_v4_v4(col_solid_tail, g_theme.bone_solid_color);
+ copy_v4_v4(col_wire_root, (g_theme.const_color) ? g_theme.const_color : g_theme.vertex_color);
+ copy_v4_v4(col_wire_tail, (g_theme.const_color) ? g_theme.const_color : g_theme.vertex_color);
+
+ const bool is_envelope_draw = (arm->drawtype == ARM_ENVELOPE);
+ static const float envelope_ignore = -1.0f;
+
+ col_wire_tail[3] = col_wire_root[3] = get_bone_wire_thickness(boneflag);
+
+ /* Edit bone points can be selected */
+ if (eBone) {
+ if (eBone->flag & BONE_ROOTSEL) {
+ copy_v3_v3(col_wire_root, g_theme.vertex_select_color);
+ }
+ if (eBone->flag & BONE_TIPSEL) {
+ copy_v3_v3(col_wire_tail, g_theme.vertex_select_color);
+ }
+ }
+ else if (arm->flag & ARM_POSEMODE) {
+ const float *solid_color = get_bone_solid_color(eBone, pchan, arm, boneflag, constflag);
+ const float *wire_color = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
+ copy_v4_v4(col_wire_tail, wire_color);
+ copy_v4_v4(col_wire_root, wire_color);
+ copy_v4_v4(col_solid_tail, solid_color);
+ copy_v4_v4(col_solid_root, solid_color);
+ }
+
+ bone_hint_color_shade(col_hint_root, (g_theme.const_color) ? col_solid_root : col_wire_root);
+ bone_hint_color_shade(col_hint_tail, (g_theme.const_color) ? col_solid_tail : col_wire_tail);
+
+ /* Draw root point if we are not connected and parent are not hidden */
+ if ((BONE_FLAG(eBone, pchan) & BONE_CONNECTED) == 0) {
+ if (select_id != -1) {
+ DRW_select_load_id(select_id | BONESEL_ROOT);
+ }
+
+ if (eBone) {
+ if (!((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent))) {
+ if (is_envelope_draw) {
+ drw_shgroup_bone_envelope(eBone->disp_mat, col_solid_root, col_hint_root, col_wire_root,
+ &eBone->rad_head, &envelope_ignore);
+ }
+ else {
+ drw_shgroup_bone_point(eBone->disp_mat, col_solid_root, col_hint_root, col_wire_root);
+ }
+ }
+ }
+ else {
+ Bone *bone = pchan->bone;
+ if (!((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)))) {
+ if (is_envelope_draw) {
+ drw_shgroup_bone_envelope(pchan->disp_mat, col_solid_root, col_hint_root, col_wire_root,
+ &bone->rad_head, &envelope_ignore);
+ }
+ else {
+ drw_shgroup_bone_point(pchan->disp_mat, col_solid_root, col_hint_root, col_wire_root);
+ }
+ }
+ }
+ }
+
+ /* Draw tip point */
+ if (select_id != -1) {
+ DRW_select_load_id(select_id | BONESEL_TIP);
+ }
+
+ if (is_envelope_draw) {
+ const float *rad_tail = eBone ? &eBone->rad_tail : &pchan->bone->rad_tail;
+ drw_shgroup_bone_envelope(
+ BONE_VAR(eBone, pchan, disp_mat), col_solid_tail, col_hint_tail, col_wire_tail, &envelope_ignore, rad_tail);
+ }
+ else {
+ drw_shgroup_bone_point(BONE_VAR(eBone, pchan, disp_tail_mat), col_solid_tail, col_hint_tail, col_wire_tail);
+ }
+
+ if (select_id != -1) {
+ DRW_select_load_id(-1);
+ }
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Draw Bones
+ * \{ */
+
+static void draw_bone_custom_shape(
+ EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
+ const int boneflag, const short constflag,
+ const int select_id)
+{
+ const float *col_solid = get_bone_solid_color(eBone, pchan, arm, boneflag, constflag);
+ const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
+ const float (*disp_mat)[4] = pchan->disp_mat;
+
+ if (select_id != -1) {
+ DRW_select_load_id(select_id | BONESEL_BONE);
+ }
+
+ drw_shgroup_bone_custom_solid(disp_mat, col_solid, pchan->custom);
+ drw_shgroup_bone_custom_wire(disp_mat, col_wire, pchan->custom);
+
+ if (select_id != -1) {
+ DRW_select_load_id(-1);
+ }
+}
+
+static void draw_bone_envelope(
+ EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
+ const int boneflag, const short constflag,
+ const int select_id)
+{
+ const float *col_solid = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag);
+ const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
+ const float *col_hint = get_bone_hint_color(eBone, pchan, arm, boneflag, constflag);
+
+ float *rad_head, *rad_tail, *distance;
+ if (eBone) {
+ rad_tail = &eBone->rad_tail;
+ distance = &eBone->dist;
+ rad_head = (eBone->parent && (boneflag & BONE_CONNECTED)) ? &eBone->parent->rad_tail : &eBone->rad_head;
+ }
+ else {
+ rad_tail = &pchan->bone->rad_tail;
+ distance = &pchan->bone->dist;
+ rad_head = (pchan->parent && (boneflag & BONE_CONNECTED)) ? &pchan->parent->bone->rad_tail : &pchan->bone->rad_head;
+ }
+
+ if ((select_id == -1) &&
+ (boneflag & BONE_NO_DEFORM) == 0 &&
+ ((boneflag & BONE_SELECTED) || (eBone && (boneflag & (BONE_ROOTSEL | BONE_TIPSEL)))))
+ {
+ drw_shgroup_bone_envelope_distance(BONE_VAR(eBone, pchan, disp_mat), rad_head, rad_tail, distance);
+ }
+
+ if (select_id != -1) {
+ DRW_select_load_id(select_id | BONESEL_BONE);
+ }
+
+ drw_shgroup_bone_envelope(BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire, rad_head, rad_tail);
+
+ if (select_id != -1) {
+ DRW_select_load_id(-1);
+ }
+
+ draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
+}
+
+static void draw_bone_line(
+ EditBone *UNUSED(eBone), bPoseChannel *UNUSED(pchan), bArmature *UNUSED(arm),
+ const int UNUSED(boneflag), const short UNUSED(constflag),
+ const int UNUSED(select_id))
+{
+ /* work in progress -- fclem */
+}
+
+static void draw_bone_wire(
+ EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
+ const int boneflag, const short constflag,
+ const int select_id)
+{
+ const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
+
+ if (select_id != -1) {
+ DRW_select_load_id(select_id | BONESEL_BONE);
+ }
+
+ if (pchan) {
+ Mat4 *bbones_mat = (Mat4 *)pchan->draw_data->bbone_matrix;
+ BLI_assert(bbones_mat != NULL);
+
+ for (int i = pchan->bone->segments; i--; bbones_mat++) {
+ drw_shgroup_bone_wire_wire(bbones_mat->mat, col_wire);
+ }
+ }
+ else if (eBone) {
+ for (int i = 0; i < eBone->segments; i++) {
+ drw_shgroup_bone_wire_wire(eBone->disp_bbone_mat[i], col_wire);
+ }
+ }
+
+ if (select_id != -1) {
+ DRW_select_load_id(-1);
+ }
+
+ if (eBone) {
+ draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
+ }
+}
+
+static void draw_bone_box(
+ EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
+ const int boneflag, const short constflag,
+ const int select_id)
+{
+ const float *col_solid = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag);
+ const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
+ const float *col_hint = get_bone_hint_color(eBone, pchan, arm, boneflag, constflag);
+
+ if (select_id != -1) {
+ DRW_select_load_id(select_id | BONESEL_BONE);
+ }
+
+ if (pchan) {
+ Mat4 *bbones_mat = (Mat4 *)pchan->draw_data->bbone_matrix;
+ BLI_assert(bbones_mat != NULL);
+
+ for (int i = pchan->bone->segments; i--; bbones_mat++) {
+ drw_shgroup_bone_box(bbones_mat->mat, col_solid, col_hint, col_wire);
+ }
+ }
+ else if (eBone) {
+ for (int i = 0; i < eBone->segments; i++) {
+ drw_shgroup_bone_box(eBone->disp_bbone_mat[i], col_solid, col_hint, col_wire);
+ }
+ }
+
+ if (select_id != -1) {
+ DRW_select_load_id(-1);
+ }
+
+ if (eBone) {
+ draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
+ }
+}
+
+static void draw_bone_octahedral(
+ EditBone *eBone, bPoseChannel *pchan, bArmature *arm,
+ const int boneflag, const short constflag,
+ const int select_id)
+{
+ const float *col_solid = get_bone_solid_with_consts_color(eBone, pchan, arm, boneflag, constflag);
+ const float *col_wire = get_bone_wire_color(eBone, pchan, arm, boneflag, constflag);
+ const float *col_hint = get_bone_hint_color(eBone, pchan, arm, boneflag, constflag);
+
+ if (select_id != -1) {
+ DRW_select_load_id(select_id | BONESEL_BONE);
+ }
+
+ drw_shgroup_bone_octahedral(BONE_VAR(eBone, pchan, disp_mat), col_solid, col_hint, col_wire);
+
+ if (select_id != -1) {
+ DRW_select_load_id(-1);
+ }
+
+ draw_points(eBone, pchan, arm, boneflag, constflag, select_id);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Draw Relationships
+ * \{ */
+
+static void pchan_draw_ik_lines(bPoseChannel *pchan, const bool only_temp, const int constflag)
+{
+ bConstraint *con;
+ bPoseChannel *parchan;
+ float *line_start = NULL, *line_end = NULL;
+
+ for (con = pchan->constraints.first; con; con = con->next) {
+ if (con->enforce == 0.0f)
+ continue;
+
+ switch (con->type) {
+ case CONSTRAINT_TYPE_KINEMATIC:
+ {
+ bKinematicConstraint *data = (bKinematicConstraint *)con->data;
+ int segcount = 0;
+
+ /* if only_temp, only draw if it is a temporary ik-chain */
+ if (only_temp && !(data->flag & CONSTRAINT_IK_TEMP))
+ continue;
+
+ /* exclude tip from chain? */
+ parchan = ((data->flag & CONSTRAINT_IK_TIP) == 0) ? pchan->parent : pchan;
+ line_start = parchan->pose_tail;
+
+ /* Find the chain's root */
+ while (parchan->parent) {
+ segcount++;
+ if (segcount == data->rootbone || segcount > 255) {
+ break; /* 255 is weak */
+ }
+ parchan = parchan->parent;
+ }
+
+ if (parchan) {
+ line_end = parchan->pose_head;
+
+ if (constflag & PCHAN_HAS_TARGET)
+ drw_shgroup_bone_ik_lines(line_start, line_end);
+ else
+ drw_shgroup_bone_ik_no_target_lines(line_start, line_end);
+ }
+ break;
+ }
+ case CONSTRAINT_TYPE_SPLINEIK:
+ {
+ bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
+ int segcount = 0;
+
+ parchan = pchan;
+ line_start = parchan->pose_tail;
+
+ /* Find the chain's root */
+ while (parchan->parent) {
+ segcount++;
+ /* FIXME: revise the breaking conditions */
+ if (segcount == data->chainlen || segcount > 255) break; /* 255 is weak */
+ parchan = parchan->parent;
+ }
+ /* Only draw line in case our chain is more than one bone long! */
+ if (parchan != pchan) { /* XXX revise the breaking conditions to only stop at the tail? */
+ line_end = parchan->pose_head;
+ drw_shgroup_bone_ik_spline_lines(line_start, line_end);
+ }
+ break;
+ }
+ }
+ }
+}
+
+static void draw_bone_relations(
+ EditBone *ebone, bPoseChannel *pchan, bArmature *arm,
+ const int boneflag, const short constflag, const bool do_relations)
+{
+ if (g_data.passes.relationship_lines) {
+ if (ebone && ebone->parent) {
+ if ((boneflag & BONE_CONNECTED) == 0) {
+ drw_shgroup_bone_relationship_lines(ebone->head, ebone->parent->tail);
+ }
+ }
+ else if (pchan && pchan->parent) {
+ if ((boneflag & BONE_CONNECTED) == 0) {
+ drw_shgroup_bone_relationship_lines(pchan->pose_head, pchan->parent->pose_tail);
+ }
+
+ /* Draw a line to IK root bone if bone is selected. */
+ if (arm->flag & ARM_POSEMODE) {
+ if (constflag & (PCHAN_HAS_IK | PCHAN_HAS_SPLINEIK)) {
+ if (boneflag & BONE_SELECTED) {
+ pchan_draw_ik_lines(pchan, !do_relations, constflag);
+ }
+ }
+ }
+ }
+ }
+}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Main Draw Loops
+ * \{ */
+
+static void draw_armature_edit(Object *ob)
+{
+ EditBone *eBone;
+ bArmature *arm = ob->data;
+ int index;
+ const bool is_select = DRW_state_is_select();
+
+ update_color(ob, NULL);
+
+ const bool show_text = DRW_state_show_text();
+ const bool show_relations = true; /* TODO get value from overlays settings. */
+
+ for (eBone = arm->edbo->first, index = ob->select_color; eBone; eBone = eBone->next, index += 0x10000) {
+ if (eBone->layer & arm->layer) {
+ if ((eBone->flag & BONE_HIDDEN_A) == 0) {
+ const int select_id = is_select ? index : (unsigned int)-1;
+
+ const short constflag = 0;
+
+ /* catch exception for bone with hidden parent */
+ int boneflag = eBone->flag;
+ if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) {
+ boneflag &= ~BONE_CONNECTED;
+ }
+
+ /* set temporary flag for drawing bone as active, but only if selected */
+ if (eBone == arm->act_edbone) {
+ boneflag |= BONE_DRAW_ACTIVE;
+ }
+
+ draw_bone_relations(eBone, NULL, arm, boneflag, constflag, show_relations);
+
+ if (arm->drawtype == ARM_ENVELOPE) {
+ draw_bone_update_disp_matrix_default(eBone, NULL);
+ draw_bone_envelope(eBone, NULL, arm, boneflag, constflag, select_id);
+ }
+ else if (arm->drawtype == ARM_LINE) {
+ draw_bone_update_disp_matrix_default(eBone, NULL);
+ draw_bone_line(eBone, NULL, arm, boneflag, constflag, select_id);
+ }
+ else if (arm->drawtype == ARM_WIRE) {
+ draw_bone_update_disp_matrix_bbone(eBone, NULL);
+ draw_bone_wire(eBone, NULL, arm, boneflag, constflag, select_id);
+ }
+ else if (arm->drawtype == ARM_B_BONE) {
+ draw_bone_update_disp_matrix_bbone(eBone, NULL);
+ draw_bone_box(eBone, NULL, arm, boneflag, constflag, select_id);
+ }
+ else {
+ draw_bone_update_disp_matrix_default(eBone, NULL);
+ draw_bone_octahedral(eBone, NULL, arm, boneflag, constflag, select_id);
+ }
+
+ /* Draw names of bone */
+ if (show_text && (arm->flag & ARM_DRAWNAMES)) {
+ unsigned char color[4];
+ UI_GetThemeColor4ubv((eBone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, color);
+
+ float vec[3];
+ mid_v3_v3v3(vec, eBone->head, eBone->tail);
+ mul_m4_v3(ob->obmat, vec);
+
+ struct DRWTextStore *dt = DRW_text_cache_ensure();
+ DRW_text_cache_add(
+ dt, vec, eBone->name, strlen(eBone->name),
+ 10, DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, color);
+ }
+
+ /* Draw additional axes */
+ if (arm->flag & ARM_DRAWAXES) {
+ draw_axes(eBone, NULL);
+ }
+ }
+ }
+ }
+}
+
+/* if const_color is NULL do pose mode coloring */
+static void draw_armature_pose(Object *ob, const float const_color[4])
+{
+ bArmature *arm = ob->data;
+ bPoseChannel *pchan;
+ int index = -1;
+ Bone *bone;
+
+ update_color(ob, const_color);
+
+ /* We can't safely draw non-updated pose, might contain NULL bone pointers... */
+ if (ob->pose->flag & POSE_RECALC) {
+ BKE_pose_rebuild(ob, arm);
+ }
+
+ // if (!(base->flag & OB_FROMDUPLI)) // TODO
+ {
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ if ((draw_ctx->object_mode & OB_MODE_POSE) || (ob == draw_ctx->object_pose)) {
+ arm->flag |= ARM_POSEMODE;
+ }
+
+ if (arm->flag & ARM_POSEMODE) {
+ index = ob->select_color;
+ }
+ }
+
+ const bool is_pose_select = (arm->flag & ARM_POSEMODE) && DRW_state_is_select();
+ const bool show_text = DRW_state_show_text();
+ const bool show_relations = true; /* TODO get value from overlays settings. */
+
+ /* being set below */
+ arm->layer_used = 0;
+
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ bone = pchan->bone;
+ arm->layer_used |= bone->layer;
+
+ /* bone must be visible */
+ if ((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) {
+ if (bone->layer & arm->layer) {
+ const int select_id = is_pose_select ? index : (unsigned int)-1;
+
+ const short constflag = pchan->constflag;
+
+ pchan_draw_data_init(pchan);
+
+ if (const_color) {
+ /* keep color */
+ }
+ else {
+ /* set color-set to use */
+ set_pchan_colorset(ob, pchan);
+ }
+
+ int boneflag = bone->flag;
+ /* catch exception for bone with hidden parent */
+ boneflag = bone->flag;
+ if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
+ boneflag &= ~BONE_CONNECTED;
+ }
+
+ /* set temporary flag for drawing bone as active, but only if selected */
+ if (bone == arm->act_bone)
+ boneflag |= BONE_DRAW_ACTIVE;
+
+ draw_bone_relations(NULL, pchan, arm, boneflag, constflag, show_relations);
+
+ if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
+ draw_bone_update_disp_matrix_custom(pchan);
+ draw_bone_custom_shape(NULL, pchan, arm, boneflag, constflag, select_id);
+ }
+ else if (arm->drawtype == ARM_ENVELOPE) {
+ draw_bone_update_disp_matrix_default(NULL, pchan);
+ draw_bone_envelope(NULL, pchan, arm, boneflag, constflag, select_id);
+ }
+ else if (arm->drawtype == ARM_LINE) {
+ draw_bone_update_disp_matrix_default(NULL, pchan);
+ draw_bone_line(NULL, pchan, arm, boneflag, constflag, select_id);
+ }
+ else if (arm->drawtype == ARM_WIRE) {
+ draw_bone_update_disp_matrix_bbone(NULL, pchan);
+ draw_bone_wire(NULL, pchan, arm, boneflag, constflag, select_id);
+ }
+ else if (arm->drawtype == ARM_B_BONE) {
+ draw_bone_update_disp_matrix_bbone(NULL, pchan);
+ draw_bone_box(NULL, pchan, arm, boneflag, constflag, select_id);
+ }
+ else {
+ draw_bone_update_disp_matrix_default(NULL, pchan);
+ draw_bone_octahedral(NULL, pchan, arm, boneflag, constflag, select_id);
+ }
+
+ /* Draw names of bone */
+ if (show_text && (arm->flag & ARM_DRAWNAMES)) {
+ unsigned char color[4];
+ UI_GetThemeColor4ubv((arm->flag & ARM_POSEMODE) &&
+ (bone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, color);
+ float vec[3];
+ mid_v3_v3v3(vec, pchan->pose_head, pchan->pose_tail);
+ mul_m4_v3(ob->obmat, vec);
+
+ struct DRWTextStore *dt = DRW_text_cache_ensure();
+ DRW_text_cache_add(
+ dt, vec, pchan->name, strlen(pchan->name),
+ 10, DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, color);
+ }
+
+ /* Draw additional axes */
+ if (arm->flag & ARM_DRAWAXES) {
+ draw_axes(NULL, pchan);
+ }
+ }
+ }
+ if (is_pose_select) {
+ index += 0x10000;
+ }
+ }
+
+ arm->flag &= ~ARM_POSEMODE;
+}
+
+/**
+ * This function set the object space to use for all subsequent `DRW_shgroup_bone_*` calls.
+ */
+static void drw_shgroup_armature(Object *ob, DRWArmaturePasses passes)
+{
+ memset(&g_data, 0x0, sizeof(g_data));
+ g_data.ob = ob;
+ g_data.passes = passes;
+ memset(&g_color, 0x0, sizeof(g_color));
+}
+
+void DRW_shgroup_armature_object(Object *ob, ViewLayer *view_layer, DRWArmaturePasses passes)
+{
+ float *color;
+ DRW_object_wire_theme_get(ob, view_layer, &color);
+ passes.bone_envelope = NULL; /* Don't do envelope distance in object mode. */
+ drw_shgroup_armature(ob, passes);
+ draw_armature_pose(ob, color);
+}
+
+void DRW_shgroup_armature_pose(Object *ob, DRWArmaturePasses passes)
+{
+ drw_shgroup_armature(ob, passes);
+ draw_armature_pose(ob, NULL);
+}
+
+void DRW_shgroup_armature_edit(Object *ob, DRWArmaturePasses passes)
+{
+ drw_shgroup_armature(ob, passes);
+ draw_armature_edit(ob);
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/draw_cache.c b/source/blender/draw/intern/draw_cache.c
new file mode 100644
index 00000000000..1a4a9be00bd
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache.c
@@ -0,0 +1,3032 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_cache.c
+ * \ingroup draw
+ */
+
+
+#include "DNA_scene_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_object_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_lattice_types.h"
+
+#include "UI_resources.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+
+#include "GPU_batch.h"
+
+#include "draw_cache.h"
+#include "draw_cache_impl.h"
+
+/* Batch's only (free'd as an array) */
+static struct DRWShapeCache {
+ Gwn_Batch *drw_single_vertice;
+ Gwn_Batch *drw_cursor;
+ Gwn_Batch *drw_fullscreen_quad;
+ Gwn_Batch *drw_quad;
+ Gwn_Batch *drw_sphere;
+ Gwn_Batch *drw_screenspace_circle;
+ Gwn_Batch *drw_plain_axes;
+ Gwn_Batch *drw_single_arrow;
+ Gwn_Batch *drw_cube;
+ Gwn_Batch *drw_circle;
+ Gwn_Batch *drw_square;
+ Gwn_Batch *drw_line;
+ Gwn_Batch *drw_line_endpoints;
+ Gwn_Batch *drw_empty_sphere;
+ Gwn_Batch *drw_empty_cone;
+ Gwn_Batch *drw_arrows;
+ Gwn_Batch *drw_axis_names;
+ Gwn_Batch *drw_image_plane;
+ Gwn_Batch *drw_image_plane_wire;
+ Gwn_Batch *drw_field_wind;
+ Gwn_Batch *drw_field_force;
+ Gwn_Batch *drw_field_vortex;
+ Gwn_Batch *drw_field_tube_limit;
+ Gwn_Batch *drw_field_cone_limit;
+ Gwn_Batch *drw_lamp;
+ Gwn_Batch *drw_lamp_shadows;
+ Gwn_Batch *drw_lamp_sunrays;
+ Gwn_Batch *drw_lamp_area;
+ Gwn_Batch *drw_lamp_hemi;
+ Gwn_Batch *drw_lamp_spot;
+ Gwn_Batch *drw_lamp_spot_square;
+ Gwn_Batch *drw_speaker;
+ Gwn_Batch *drw_lightprobe_cube;
+ Gwn_Batch *drw_lightprobe_planar;
+ Gwn_Batch *drw_lightprobe_grid;
+ Gwn_Batch *drw_bone_octahedral;
+ Gwn_Batch *drw_bone_octahedral_wire;
+ Gwn_Batch *drw_bone_box;
+ Gwn_Batch *drw_bone_box_wire;
+ Gwn_Batch *drw_bone_wire_wire;
+ Gwn_Batch *drw_bone_envelope;
+ Gwn_Batch *drw_bone_envelope_outline;
+ Gwn_Batch *drw_bone_point;
+ Gwn_Batch *drw_bone_point_wire;
+ Gwn_Batch *drw_bone_arrows;
+ Gwn_Batch *drw_camera;
+ Gwn_Batch *drw_camera_frame;
+ Gwn_Batch *drw_camera_tria;
+ Gwn_Batch *drw_camera_focus;
+ Gwn_Batch *drw_particle_cross;
+ Gwn_Batch *drw_particle_circle;
+ Gwn_Batch *drw_particle_axis;
+} SHC = {NULL};
+
+void DRW_shape_cache_free(void)
+{
+ uint i = sizeof(SHC) / sizeof(Gwn_Batch *);
+ Gwn_Batch **batch = (Gwn_Batch **)&SHC;
+ while (i--) {
+ GWN_BATCH_DISCARD_SAFE(*batch);
+ batch++;
+ }
+}
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Helper functions
+ * \{ */
+
+static void add_fancy_edge(
+ Gwn_VertBuf *vbo, unsigned int pos_id, unsigned int n1_id, unsigned int n2_id,
+ unsigned int *v_idx, const float co1[3], const float co2[3],
+const float n1[3], const float n2[3])
+{
+ GWN_vertbuf_attr_set(vbo, n1_id, *v_idx, n1);
+ GWN_vertbuf_attr_set(vbo, n2_id, *v_idx, n2);
+ GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++, co1);
+
+ GWN_vertbuf_attr_set(vbo, n1_id, *v_idx, n1);
+ GWN_vertbuf_attr_set(vbo, n2_id, *v_idx, n2);
+ GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++, co2);
+}
+
+#if 0 /* UNUSED */
+static void add_lat_lon_vert(
+ Gwn_VertBuf *vbo, unsigned int pos_id, unsigned int nor_id,
+ unsigned int *v_idx, const float rad, const float lat, const float lon)
+{
+ float pos[3], nor[3];
+ nor[0] = sinf(lat) * cosf(lon);
+ nor[1] = cosf(lat);
+ nor[2] = sinf(lat) * sinf(lon);
+ mul_v3_v3fl(pos, nor, rad);
+
+ GWN_vertbuf_attr_set(vbo, nor_id, *v_idx, nor);
+ GWN_vertbuf_attr_set(vbo, pos_id, (*v_idx)++, pos);
+}
+#endif
+
+static Gwn_VertBuf *fill_arrows_vbo(const float scale)
+{
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Line */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 6 * 3);
+
+ float v1[3] = {0.0, 0.0, 0.0};
+ float v2[3] = {0.0, 0.0, 0.0};
+ float vtmp1[3], vtmp2[3];
+
+ for (int axis = 0; axis < 3; axis++) {
+ const int arrow_axis = (axis == 0) ? 1 : 0;
+
+ v2[axis] = 1.0f;
+ mul_v3_v3fl(vtmp1, v1, scale);
+ mul_v3_v3fl(vtmp2, v2, scale);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 0, vtmp1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 1, vtmp2);
+
+ v1[axis] = 0.85f;
+ v1[arrow_axis] = -0.08f;
+ mul_v3_v3fl(vtmp1, v1, scale);
+ mul_v3_v3fl(vtmp2, v2, scale);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 2, vtmp1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 3, vtmp2);
+
+ v1[arrow_axis] = 0.08f;
+ mul_v3_v3fl(vtmp1, v1, scale);
+ mul_v3_v3fl(vtmp2, v2, scale);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 4, vtmp1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 6 + 5, vtmp2);
+
+ /* reset v1 & v2 to zero */
+ v1[arrow_axis] = v1[axis] = v2[axis] = 0.0f;
+ }
+
+ return vbo;
+}
+
+static Gwn_VertBuf *sphere_wire_vbo(const float rad)
+{
+#define NSEGMENTS 32
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 2 * 3);
+
+ /* a single ring of vertices */
+ float p[NSEGMENTS][2];
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
+ p[i][0] = rad * cosf(angle);
+ p[i][1] = rad * sinf(angle);
+ }
+
+ for (int axis = 0; axis < 3; ++axis) {
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ for (int j = 0; j < 2; ++j) {
+ float cv[2], v[3];
+
+ cv[0] = p[(i + j) % NSEGMENTS][0];
+ cv[1] = p[(i + j) % NSEGMENTS][1];
+
+ if (axis == 0)
+ v[0] = cv[0], v[1] = cv[1], v[2] = 0.0f;
+ else if (axis == 1)
+ v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
+ else
+ v[0] = 0.0f, v[1] = cv[0], v[2] = cv[1];
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 2 + j + (NSEGMENTS * 2 * axis), v);
+ }
+ }
+ }
+
+ return vbo;
+#undef NSEGMENTS
+}
+
+/* Quads */
+/* Use this one for rendering fullscreen passes. For 3D objects use DRW_cache_quad_get(). */
+Gwn_Batch *DRW_cache_fullscreen_quad_get(void)
+{
+ if (!SHC.drw_fullscreen_quad) {
+ /* Use a triangle instead of a real quad */
+ /* https://www.slideshare.net/DevCentralAMD/vertex-shader-tricks-bill-bilodeau - slide 14 */
+ float pos[3][2] = {{-1.0f, -1.0f}, { 3.0f, -1.0f}, {-1.0f, 3.0f}};
+ float uvs[3][2] = {{ 0.0f, 0.0f}, { 2.0f, 0.0f}, { 0.0f, 2.0f}};
+
+ /* Position Only 2D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, uvs; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.uvs = GWN_vertformat_attr_add(&format, "uvs", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 3);
+
+ for (int i = 0; i < 3; ++i) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i, pos[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.uvs, i, uvs[i]);
+ }
+
+ SHC.drw_fullscreen_quad = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_fullscreen_quad;
+}
+
+/* Just a regular quad with 4 vertices. */
+Gwn_Batch *DRW_cache_quad_get(void)
+{
+ if (!SHC.drw_quad) {
+ float pos[4][2] = {{-1.0f, -1.0f}, { 1.0f, -1.0f}, {1.0f, 1.0f}, {-1.0f, 1.0f}};
+ float uvs[4][2] = {{ 0.0f, 0.0f}, { 1.0f, 0.0f}, {1.0f, 1.0f}, { 0.0f, 1.0f}};
+
+ /* Position Only 2D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, uvs; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.uvs = GWN_vertformat_attr_add(&format, "uvs", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 4);
+
+ for (int i = 0; i < 4; ++i) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i, pos[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.uvs, i, uvs[i]);
+ }
+
+ SHC.drw_quad = GWN_batch_create_ex(GWN_PRIM_TRI_FAN, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_quad;
+}
+
+/* Sphere */
+Gwn_Batch *DRW_cache_sphere_get(void)
+{
+ if (!SHC.drw_sphere) {
+ SHC.drw_sphere = gpu_batch_sphere(32, 24);
+ }
+ return SHC.drw_sphere;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Common
+ * \{ */
+
+Gwn_Batch *DRW_cache_cube_get(void)
+{
+ if (!SHC.drw_cube) {
+ const GLfloat verts[8][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}
+ };
+
+ const GLubyte indices[24] = {0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 4, 5, 5, 7, 7, 6, 6, 4, 1, 5, 3, 7, 2, 6};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 24);
+
+ for (int i = 0; i < 24; ++i) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i, verts[indices[i]]);
+ }
+
+ SHC.drw_cube = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_cube;
+}
+
+Gwn_Batch *DRW_cache_circle_get(void)
+{
+#define CIRCLE_RESOL 64
+ if (!SHC.drw_circle) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL);
+
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[2] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a, v);
+ }
+
+ SHC.drw_circle = GWN_batch_create_ex(GWN_PRIM_LINE_LOOP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_circle;
+#undef CIRCLE_RESOL
+}
+
+Gwn_Batch *DRW_cache_square_get(void)
+{
+ if (!SHC.drw_square) {
+ float p[4][3] = {{ 1.0f, 0.0f, 1.0f},
+ { 1.0f, 0.0f, -1.0f},
+ {-1.0f, 0.0f, -1.0f},
+ {-1.0f, 0.0f, 1.0f}};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 8);
+
+ for (int i = 0; i < 4; i++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 2, p[i % 4]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 2 + 1, p[(i + 1) % 4]);
+ }
+
+ SHC.drw_square = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_square;
+}
+
+Gwn_Batch *DRW_cache_single_line_get(void)
+{
+ /* Z axis line */
+ if (!SHC.drw_line) {
+ float v1[3] = {0.0f, 0.0f, 0.0f};
+ float v2[3] = {0.0f, 0.0f, 1.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 2);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v2);
+
+ SHC.drw_line = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_line;
+}
+
+Gwn_Batch *DRW_cache_single_line_endpoints_get(void)
+{
+ /* Z axis line */
+ if (!SHC.drw_line_endpoints) {
+ float v1[3] = {0.0f, 0.0f, 0.0f};
+ float v2[3] = {0.0f, 0.0f, 1.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 2);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v2);
+
+ SHC.drw_line_endpoints = GWN_batch_create_ex(GWN_PRIM_POINTS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_line_endpoints;
+}
+
+Gwn_Batch *DRW_cache_screenspace_circle_get(void)
+{
+#define CIRCLE_RESOL 32
+ if (!SHC.drw_screenspace_circle) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL + 1);
+
+ for (int a = 0; a <= CIRCLE_RESOL; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a, v);
+ }
+
+ SHC.drw_screenspace_circle = GWN_batch_create_ex(GWN_PRIM_LINE_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_screenspace_circle;
+#undef CIRCLE_RESOL
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Common Object API
+ * \{ */
+
+Gwn_Batch *DRW_cache_object_wire_outline_get(Object *ob)
+{
+ switch (ob->type) {
+ case OB_MESH:
+ return DRW_cache_mesh_wire_outline_get(ob);
+
+ /* TODO, should match 'DRW_cache_object_surface_get' */
+ default:
+ return NULL;
+ }
+}
+
+Gwn_Batch *DRW_cache_object_surface_get(Object *ob)
+{
+ switch (ob->type) {
+ case OB_MESH:
+ return DRW_cache_mesh_surface_get(ob);
+ case OB_CURVE:
+ return DRW_cache_curve_surface_get(ob);
+ case OB_SURF:
+ return DRW_cache_surf_surface_get(ob);
+ case OB_FONT:
+ return DRW_cache_text_surface_get(ob);
+ case OB_MBALL:
+ return DRW_cache_mball_surface_get(ob);
+ default:
+ return NULL;
+ }
+}
+
+Gwn_Batch **DRW_cache_object_surface_material_get(
+ struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
+ char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count)
+{
+ if (auto_layer_names != NULL) {
+ *auto_layer_names = NULL;
+ *auto_layer_is_srgb = NULL;
+ *auto_layer_count = 0;
+ }
+
+ switch (ob->type) {
+ case OB_MESH:
+ return DRW_cache_mesh_surface_shaded_get(ob, gpumat_array, gpumat_array_len,
+ auto_layer_names, auto_layer_is_srgb, auto_layer_count);
+ case OB_CURVE:
+ return DRW_cache_curve_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
+ case OB_SURF:
+ return DRW_cache_surf_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
+ case OB_FONT:
+ return DRW_cache_text_surface_shaded_get(ob, gpumat_array, gpumat_array_len);
+ default:
+ return NULL;
+ }
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Empties
+ * \{ */
+
+Gwn_Batch *DRW_cache_plain_axes_get(void)
+{
+ if (!SHC.drw_plain_axes) {
+ int axis;
+ float v1[3] = {0.0f, 0.0f, 0.0f};
+ float v2[3] = {0.0f, 0.0f, 0.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 6);
+
+ for (axis = 0; axis < 3; axis++) {
+ v1[axis] = 1.0f;
+ v2[axis] = -1.0f;
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 2, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, axis * 2 + 1, v2);
+
+ /* reset v1 & v2 to zero for next axis */
+ v1[axis] = v2[axis] = 0.0f;
+ }
+
+ SHC.drw_plain_axes = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_plain_axes;
+}
+
+Gwn_Batch *DRW_cache_single_arrow_get(void)
+{
+ if (!SHC.drw_single_arrow) {
+ float v1[3] = {0.0f, 0.0f, 1.0f}, v2[3], v3[3];
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Square Pyramid */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 12);
+
+ v2[0] = 0.035f; v2[1] = 0.035f;
+ v3[0] = -0.035f; v3[1] = 0.035f;
+ v2[2] = v3[2] = 0.75f;
+
+ for (int sides = 0; sides < 4; sides++) {
+ if (sides % 2 == 1) {
+ v2[0] = -v2[0];
+ v3[1] = -v3[1];
+ }
+ else {
+ v2[1] = -v2[1];
+ v3[0] = -v3[0];
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, sides * 3 + 0, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, sides * 3 + 1, v2);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, sides * 3 + 2, v3);
+ }
+
+ SHC.drw_single_arrow = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_single_arrow;
+}
+
+Gwn_Batch *DRW_cache_empty_sphere_get(void)
+{
+ if (!SHC.drw_empty_sphere) {
+ Gwn_VertBuf *vbo = sphere_wire_vbo(1.0f);
+ SHC.drw_empty_sphere = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_empty_sphere;
+}
+
+Gwn_Batch *DRW_cache_empty_cone_get(void)
+{
+#define NSEGMENTS 8
+ if (!SHC.drw_empty_cone) {
+ /* a single ring of vertices */
+ float p[NSEGMENTS][2];
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
+ p[i][0] = cosf(angle);
+ p[i][1] = sinf(angle);
+ }
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 4);
+
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ float cv[2], v[3];
+ cv[0] = p[(i) % NSEGMENTS][0];
+ cv[1] = p[(i) % NSEGMENTS][1];
+
+ /* cone sides */
+ v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4, v);
+ v[0] = 0.0f, v[1] = 2.0f, v[2] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 1, v);
+
+ /* end ring */
+ v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 2, v);
+ cv[0] = p[(i + 1) % NSEGMENTS][0];
+ cv[1] = p[(i + 1) % NSEGMENTS][1];
+ v[0] = cv[0], v[1] = 0.0f, v[2] = cv[1];
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 3, v);
+ }
+
+ SHC.drw_empty_cone = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_empty_cone;
+#undef NSEGMENTS
+}
+
+Gwn_Batch *DRW_cache_arrows_get(void)
+{
+ if (!SHC.drw_arrows) {
+ Gwn_VertBuf *vbo = fill_arrows_vbo(1.0f);
+
+ SHC.drw_arrows = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_arrows;
+}
+
+Gwn_Batch *DRW_cache_axis_names_get(void)
+{
+ if (!SHC.drw_axis_names) {
+ const float size = 0.1f;
+ float v1[3], v2[3];
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ /* Using 3rd component as axis indicator */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Line */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 14);
+
+ /* X */
+ copy_v3_fl3(v1, -size, size, 0.0f);
+ copy_v3_fl3(v2, size, -size, 0.0f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v2);
+
+ copy_v3_fl3(v1, size, size, 0.0f);
+ copy_v3_fl3(v2, -size, -size, 0.0f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 2, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 3, v2);
+
+ /* Y */
+ copy_v3_fl3(v1, -size + 0.25f * size, size, 1.0f);
+ copy_v3_fl3(v2, 0.0f, 0.0f, 1.0f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 4, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 5, v2);
+
+ copy_v3_fl3(v1, size - 0.25f * size, size, 1.0f);
+ copy_v3_fl3(v2, -size + 0.25f * size, -size, 1.0f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 6, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 7, v2);
+
+ /* Z */
+ copy_v3_fl3(v1, -size, size, 2.0f);
+ copy_v3_fl3(v2, size, size, 2.0f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 8, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 9, v2);
+
+ copy_v3_fl3(v1, size, size, 2.0f);
+ copy_v3_fl3(v2, -size, -size, 2.0f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 10, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 11, v2);
+
+ copy_v3_fl3(v1, -size, -size, 2.0f);
+ copy_v3_fl3(v2, size, -size, 2.0f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 12, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 13, v2);
+
+ SHC.drw_axis_names = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_axis_names;
+}
+
+Gwn_Batch *DRW_cache_image_plane_get(void)
+{
+ if (!SHC.drw_image_plane) {
+ const float quad[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, texCoords; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.texCoords = GWN_vertformat_attr_add(&format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 4);
+ for (uint j = 0; j < 4; j++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, j, quad[j]);
+ GWN_vertbuf_attr_set(vbo, attr_id.texCoords, j, quad[j]);
+ }
+ SHC.drw_image_plane = GWN_batch_create_ex(GWN_PRIM_TRI_FAN, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_image_plane;
+}
+
+Gwn_Batch *DRW_cache_image_plane_wire_get(void)
+{
+ if (!SHC.drw_image_plane_wire) {
+ const float quad[4][2] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 4);
+ for (uint j = 0; j < 4; j++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, j, quad[j]);
+ }
+ SHC.drw_image_plane_wire = GWN_batch_create_ex(GWN_PRIM_LINE_LOOP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_image_plane_wire;
+}
+
+/* Force Field */
+Gwn_Batch *DRW_cache_field_wind_get(void)
+{
+#define CIRCLE_RESOL 32
+ if (!SHC.drw_field_wind) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 4);
+
+ for (int i = 0; i < 4; i++) {
+ float z = 0.05f * (float)i;
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2, v);
+
+ v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2 + 1, v);
+ }
+ }
+
+ SHC.drw_field_wind = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_field_wind;
+#undef CIRCLE_RESOL
+}
+
+Gwn_Batch *DRW_cache_field_force_get(void)
+{
+#define CIRCLE_RESOL 32
+ if (!SHC.drw_field_force) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 3);
+
+ for (int i = 0; i < 3; i++) {
+ float radius = 1.0f + 0.5f * (float)i;
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[0] = radius * sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = radius * cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[2] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2, v);
+
+ v[0] = radius * sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[1] = radius * cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[2] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * CIRCLE_RESOL * 2 + a * 2 + 1, v);
+ }
+ }
+
+ SHC.drw_field_force = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_field_force;
+#undef CIRCLE_RESOL
+}
+
+Gwn_Batch *DRW_cache_field_vortex_get(void)
+{
+#define SPIRAL_RESOL 32
+ if (!SHC.drw_field_vortex) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+ unsigned int v_idx = 0;
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, SPIRAL_RESOL * 2 + 1);
+
+ for (int a = SPIRAL_RESOL; a > -1; a--) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
+ v[1] = cosf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+ }
+
+ for (int a = 1; a <= SPIRAL_RESOL; a++) {
+ v[0] = -sinf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
+ v[1] = -cosf((2.0f * M_PI * a) / ((float)SPIRAL_RESOL)) * (a / (float)SPIRAL_RESOL);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+ }
+
+ SHC.drw_field_vortex = GWN_batch_create_ex(GWN_PRIM_LINE_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_field_vortex;
+#undef SPIRAL_RESOL
+}
+
+Gwn_Batch *DRW_cache_field_tube_limit_get(void)
+{
+#define CIRCLE_RESOL 32
+ if (!SHC.drw_field_tube_limit) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+ unsigned int v_idx = 0;
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 2 + 8);
+
+ /* Caps */
+ for (int i = 0; i < 2; i++) {
+ float z = (float)i * 2.0f - 1.0f;
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+
+ v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+ }
+ }
+ /* Side Edges */
+ for (int a = 0; a < 4; a++) {
+ for (int i = 0; i < 2; i++) {
+ float z = (float)i * 2.0f - 1.0f;
+ v[0] = sinf((2.0f * M_PI * a) / 4.0f);
+ v[1] = cosf((2.0f * M_PI * a) / 4.0f);
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+ }
+ }
+
+ SHC.drw_field_tube_limit = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_field_tube_limit;
+#undef CIRCLE_RESOL
+}
+
+Gwn_Batch *DRW_cache_field_cone_limit_get(void)
+{
+#define CIRCLE_RESOL 32
+ if (!SHC.drw_field_cone_limit) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+ unsigned int v_idx = 0;
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 2 + 8);
+
+ /* Caps */
+ for (int i = 0; i < 2; i++) {
+ float z = (float)i * 2.0f - 1.0f;
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+
+ v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+ }
+ }
+ /* Side Edges */
+ for (int a = 0; a < 4; a++) {
+ for (int i = 0; i < 2; i++) {
+ float z = (float)i * 2.0f - 1.0f;
+ v[0] = z * sinf((2.0f * M_PI * a) / 4.0f);
+ v[1] = z * cosf((2.0f * M_PI * a) / 4.0f);
+ v[2] = z;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v);
+ }
+ }
+
+ SHC.drw_field_cone_limit = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_field_cone_limit;
+#undef CIRCLE_RESOL
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Lamps
+ * \{ */
+
+Gwn_Batch *DRW_cache_lamp_get(void)
+{
+#define NSEGMENTS 8
+ if (!SHC.drw_lamp) {
+ float v[2];
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 2);
+
+ for (int a = 0; a < NSEGMENTS * 2; a += 2) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)NSEGMENTS * 2));
+ v[1] = cosf((2.0f * M_PI * a) / ((float)NSEGMENTS * 2));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a, v);
+
+ v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)NSEGMENTS * 2));
+ v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)NSEGMENTS * 2));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a + 1, v);
+ }
+
+ SHC.drw_lamp = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp;
+#undef NSEGMENTS
+}
+
+Gwn_Batch *DRW_cache_lamp_shadows_get(void)
+{
+#define NSEGMENTS 10
+ if (!SHC.drw_lamp_shadows) {
+ float v[2];
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 2);
+
+ for (int a = 0; a < NSEGMENTS * 2; a += 2) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)NSEGMENTS * 2));
+ v[1] = cosf((2.0f * M_PI * a) / ((float)NSEGMENTS * 2));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a, v);
+
+ v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)NSEGMENTS * 2));
+ v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)NSEGMENTS * 2));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a + 1, v);
+ }
+
+ SHC.drw_lamp_shadows = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_shadows;
+#undef NSEGMENTS
+}
+
+Gwn_Batch *DRW_cache_lamp_sunrays_get(void)
+{
+ if (!SHC.drw_lamp_sunrays) {
+ float v[2], v1[2], v2[2];
+
+ /* Position Only 2D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 32);
+
+ for (int a = 0; a < 8; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / 8.0f);
+ v[1] = cosf((2.0f * M_PI * a) / 8.0f);
+
+ mul_v2_v2fl(v1, v, 1.6f);
+ mul_v2_v2fl(v2, v, 1.9f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 4, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 4 + 1, v2);
+
+ mul_v2_v2fl(v1, v, 2.2f);
+ mul_v2_v2fl(v2, v, 2.5f);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 4 + 2, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a * 4 + 3, v2);
+ }
+
+ SHC.drw_lamp_sunrays = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_sunrays;
+}
+
+Gwn_Batch *DRW_cache_lamp_area_get(void)
+{
+ if (!SHC.drw_lamp_area) {
+ float v1[3] = {0.0f, 0.0f, 0.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 8);
+
+ v1[0] = v1[1] = 0.5f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
+ v1[0] = -0.5f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 1, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 2, v1);
+ v1[1] = -0.5f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 3, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 4, v1);
+ v1[0] = 0.5f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 5, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 6, v1);
+ v1[1] = 0.5f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 7, v1);
+
+ SHC.drw_lamp_area = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_area;
+}
+
+Gwn_Batch *DRW_cache_lamp_hemi_get(void)
+{
+#define CIRCLE_RESOL 32
+ if (!SHC.drw_lamp_hemi) {
+ float v[3];
+ int vidx = 0;
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL * 2 * 2 - 6 * 2 * 2);
+
+ /* XZ plane */
+ for (int a = 3; a < CIRCLE_RESOL / 2 - 3; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL) - M_PI / 2);
+ v[2] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL) - M_PI / 2) - 1.0f;
+ v[1] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+
+ v[0] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL) - M_PI / 2);
+ v[2] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL) - M_PI / 2) - 1.0f;
+ v[1] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ }
+
+ /* XY plane */
+ for (int a = 3; a < CIRCLE_RESOL / 2 - 3; a++) {
+ v[2] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL)) - 1.0f;
+ v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[0] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+
+ v[2] = sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL)) - 1.0f;
+ v[1] = cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[0] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ }
+
+ /* YZ plane full circle */
+ /* lease v[2] as it is */
+ const float rad = cosf((2.0f * M_PI * 3) / ((float)CIRCLE_RESOL));
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[1] = rad * sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[0] = rad * cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+
+ v[1] = rad * sinf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ v[0] = rad * cosf((2.0f * M_PI * (a + 1)) / ((float)CIRCLE_RESOL));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ }
+
+
+ SHC.drw_lamp_hemi = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_hemi;
+#undef CIRCLE_RESOL
+}
+
+
+Gwn_Batch *DRW_cache_lamp_spot_get(void)
+{
+#define NSEGMENTS 32
+ if (!SHC.drw_lamp_spot) {
+ /* a single ring of vertices */
+ float p[NSEGMENTS][2];
+ float n[NSEGMENTS][3];
+ float neg[NSEGMENTS][3];
+ float half_angle = 2 * M_PI / ((float)NSEGMENTS * 2);
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ float angle = 2 * M_PI * ((float)i / (float)NSEGMENTS);
+ p[i][0] = cosf(angle);
+ p[i][1] = sinf(angle);
+
+ n[i][0] = cosf(angle - half_angle);
+ n[i][1] = sinf(angle - half_angle);
+ n[i][2] = cosf(M_PI / 16.0f); /* slope of the cone */
+ normalize_v3(n[i]); /* necessary ? */
+ negate_v3_v3(neg[i], n[i]);
+ }
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, n1, n2; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, NSEGMENTS * 4);
+
+ for (int i = 0; i < NSEGMENTS; ++i) {
+ float cv[2], v[3];
+ cv[0] = p[i % NSEGMENTS][0];
+ cv[1] = p[i % NSEGMENTS][1];
+
+ /* cone sides */
+ v[0] = cv[0], v[1] = cv[1], v[2] = -1.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4, v);
+ v[0] = 0.0f, v[1] = 0.0f, v[2] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 1, v);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4, n[(i) % NSEGMENTS]);
+ GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4 + 1, n[(i) % NSEGMENTS]);
+ GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4, n[(i + 1) % NSEGMENTS]);
+ GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4 + 1, n[(i + 1) % NSEGMENTS]);
+
+ /* end ring */
+ v[0] = cv[0], v[1] = cv[1], v[2] = -1.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 2, v);
+ cv[0] = p[(i + 1) % NSEGMENTS][0];
+ cv[1] = p[(i + 1) % NSEGMENTS][1];
+ v[0] = cv[0], v[1] = cv[1], v[2] = -1.0f;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i * 4 + 3, v);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4 + 2, n[(i) % NSEGMENTS]);
+ GWN_vertbuf_attr_set(vbo, attr_id.n1, i * 4 + 3, n[(i) % NSEGMENTS]);
+ GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4 + 2, neg[(i) % NSEGMENTS]);
+ GWN_vertbuf_attr_set(vbo, attr_id.n2, i * 4 + 3, neg[(i) % NSEGMENTS]);
+ }
+
+ SHC.drw_lamp_spot = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_spot;
+#undef NSEGMENTS
+}
+
+Gwn_Batch *DRW_cache_lamp_spot_square_get(void)
+{
+ if (!SHC.drw_lamp_spot_square) {
+ float p[5][3] = {{ 0.0f, 0.0f, 0.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}};
+
+ unsigned int v_idx = 0;
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 16);
+
+ /* piramid sides */
+ for (int i = 1; i <= 4; ++i) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[0]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[i]);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[(i % 4) + 1]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, p[((i + 1) % 4) + 1]);
+ }
+
+ SHC.drw_lamp_spot_square = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lamp_spot_square;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Speaker
+ * \{ */
+
+Gwn_Batch *DRW_cache_speaker_get(void)
+{
+ if (!SHC.drw_speaker) {
+ float v[3];
+ const int segments = 16;
+ int vidx = 0;
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 3 * segments * 2 + 4 * 4);
+
+ for (int j = 0; j < 3; j++) {
+ float z = 0.25f * j - 0.125f;
+ float r = (j == 0 ? 0.5f : 0.25f);
+
+ copy_v3_fl3(v, r, 0.0f, z);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ for (int i = 1; i < segments; i++) {
+ float x = cosf(2.f * (float)M_PI * i / segments) * r;
+ float y = sinf(2.f * (float)M_PI * i / segments) * r;
+ copy_v3_fl3(v, x, y, z);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ }
+ copy_v3_fl3(v, r, 0.0f, z);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ }
+
+ for (int j = 0; j < 4; j++) {
+ float x = (((j + 1) % 2) * (j - 1)) * 0.5f;
+ float y = ((j % 2) * (j - 2)) * 0.5f;
+ for (int i = 0; i < 3; i++) {
+ if (i == 1) {
+ x *= 0.5f;
+ y *= 0.5f;
+ }
+
+ float z = 0.25f * i - 0.125f;
+ copy_v3_fl3(v, x, y, z);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ if (i == 1) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, v);
+ }
+ }
+ }
+
+ SHC.drw_speaker = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_speaker;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Probe
+ * \{ */
+
+Gwn_Batch *DRW_cache_lightprobe_cube_get(void)
+{
+ if (!SHC.drw_lightprobe_cube) {
+ int v_idx = 0;
+ const float sin_pi_3 = 0.86602540378f;
+ const float cos_pi_3 = 0.5f;
+ float v[7][3] = {
+ {0.0f, 1.0f, 0.0f},
+ {sin_pi_3, cos_pi_3, 0.0f},
+ {sin_pi_3, -cos_pi_3, 0.0f},
+ {0.0f, -1.0f, 0.0f},
+ {-sin_pi_3, -cos_pi_3, 0.0f},
+ {-sin_pi_3, cos_pi_3, 0.0f},
+ {0.0f, 0.0f, 0.0f},
+ };
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, (6 + 3) * 2);
+
+ for (int i = 0; i < 6; ++i) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[(i + 1) % 6]);
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[1]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[5]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[3]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
+
+ SHC.drw_lightprobe_cube = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lightprobe_cube;
+}
+
+Gwn_Batch *DRW_cache_lightprobe_grid_get(void)
+{
+ if (!SHC.drw_lightprobe_grid) {
+ int v_idx = 0;
+ const float sin_pi_3 = 0.86602540378f;
+ const float cos_pi_3 = 0.5f;
+ const float v[7][3] = {
+ {0.0f, 1.0f, 0.0f},
+ {sin_pi_3, cos_pi_3, 0.0f},
+ {sin_pi_3, -cos_pi_3, 0.0f},
+ {0.0f, -1.0f, 0.0f},
+ {-sin_pi_3, -cos_pi_3, 0.0f},
+ {-sin_pi_3, cos_pi_3, 0.0f},
+ {0.0f, 0.0f, 0.0f},
+ };
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, (6 * 2 + 3) * 2);
+
+ for (int i = 0; i < 6; ++i) {
+ float tmp_v1[3], tmp_v2[3], tmp_tr[3];
+ copy_v3_v3(tmp_v1, v[i]);
+ copy_v3_v3(tmp_v2, v[(i + 1) % 6]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v2);
+
+ /* Internal wires. */
+ for (int j = 1; j < 2; ++j) {
+ mul_v3_v3fl(tmp_tr, v[(i / 2) * 2 + 1], -0.5f * j);
+ add_v3_v3v3(tmp_v1, v[i], tmp_tr);
+ add_v3_v3v3(tmp_v2, v[(i + 1) % 6], tmp_tr);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, tmp_v2);
+ }
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[1]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[5]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[3]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[6]);
+
+ SHC.drw_lightprobe_grid = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lightprobe_grid;
+}
+
+Gwn_Batch *DRW_cache_lightprobe_planar_get(void)
+{
+ if (!SHC.drw_lightprobe_planar) {
+ int v_idx = 0;
+ const float sin_pi_3 = 0.86602540378f;
+ float v[4][3] = {
+ {0.0f, 0.5f, 0.0f},
+ {sin_pi_3, 0.0f, 0.0f},
+ {0.0f, -0.5f, 0.0f},
+ {-sin_pi_3, 0.0f, 0.0f},
+ };
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 4 * 2);
+
+ for (int i = 0; i < 4; ++i) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, v[(i + 1) % 4]);
+ }
+
+ SHC.drw_lightprobe_planar = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_lightprobe_planar;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Armature Bones
+ * \{ */
+
+static const float bone_octahedral_verts[6][3] = {
+ { 0.0f, 0.0f, 0.0f},
+ { 0.1f, 0.1f, 0.1f},
+ { 0.1f, 0.1f, -0.1f},
+ {-0.1f, 0.1f, -0.1f},
+ {-0.1f, 0.1f, 0.1f},
+ { 0.0f, 1.0f, 0.0f}
+};
+
+static const float bone_octahedral_smooth_normals[6][3] = {
+ { 0.0f, -1.0f, 0.0f},
+#if 0 /* creates problems for outlines when scaled */
+ { 0.943608f * M_SQRT1_2, -0.331048f, 0.943608f * M_SQRT1_2},
+ { 0.943608f * M_SQRT1_2, -0.331048f, -0.943608f * M_SQRT1_2},
+ {-0.943608f * M_SQRT1_2, -0.331048f, -0.943608f * M_SQRT1_2},
+ {-0.943608f * M_SQRT1_2, -0.331048f, 0.943608f * M_SQRT1_2},
+#else
+ { M_SQRT1_2, 0.0f, M_SQRT1_2},
+ { M_SQRT1_2, 0.0f, -M_SQRT1_2},
+ {-M_SQRT1_2, 0.0f, -M_SQRT1_2},
+ {-M_SQRT1_2, 0.0f, M_SQRT1_2},
+#endif
+ { 0.0f, 1.0f, 0.0f}
+};
+
+static const unsigned int bone_octahedral_wire[24] = {
+ 0, 1, 1, 5, 5, 3, 3, 0,
+ 0, 4, 4, 5, 5, 2, 2, 0,
+ 1, 2, 2, 3, 3, 4, 4, 1,
+};
+
+/* aligned with bone_octahedral_wire
+ * Contains adjacent normal index */
+static const unsigned int bone_octahedral_wire_adjacent_face[24] = {
+ 0, 3, 4, 7, 5, 6, 1, 2,
+ 2, 3, 6, 7, 4, 5, 0, 1,
+ 0, 4, 1, 5, 2, 6, 3, 7,
+};
+
+static const unsigned int bone_octahedral_solid_tris[8][3] = {
+ {2, 1, 0}, /* bottom */
+ {3, 2, 0},
+ {4, 3, 0},
+ {1, 4, 0},
+
+ {5, 1, 2}, /* top */
+ {5, 2, 3},
+ {5, 3, 4},
+ {5, 4, 1}
+};
+
+/**
+ * Store indices of generated verts from bone_octahedral_solid_tris to define adjacency infos.
+ * Example: triangle {2, 1, 0} is adjacent to {3, 2, 0}, {1, 4, 0} and {5, 1, 2}.
+ * {2, 1, 0} becomes {0, 1, 2}
+ * {3, 2, 0} becomes {3, 4, 5}
+ * {1, 4, 0} becomes {9, 10, 11}
+ * {5, 1, 2} becomes {12, 13, 14}
+ * According to opengl specification it becomes (starting from
+ * the first vertex of the first face aka. vertex 2):
+ * {0, 12, 1, 10, 2, 3}
+ **/
+static const unsigned int bone_octahedral_solid_tris_adjacency[8][6] = {
+ { 0, 12, 1, 10, 2, 3},
+ { 3, 15, 4, 1, 5, 6},
+ { 6, 18, 7, 4, 8, 9},
+ { 9, 21, 10, 7, 11, 0},
+
+ {12, 22, 13, 2, 14, 17},
+ {15, 13, 16, 5, 17, 20},
+ {18, 16, 19, 8, 20, 23},
+ {21, 19, 22, 11, 23, 14},
+};
+
+/* aligned with bone_octahedral_solid_tris */
+static const float bone_octahedral_solid_normals[8][3] = {
+ { M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
+ {-0.00000000f, -M_SQRT1_2, -M_SQRT1_2},
+ {-M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
+ { 0.00000000f, -M_SQRT1_2, M_SQRT1_2},
+ { 0.99388373f, 0.11043154f, -0.00000000f},
+ { 0.00000000f, 0.11043154f, -0.99388373f},
+ {-0.99388373f, 0.11043154f, 0.00000000f},
+ { 0.00000000f, 0.11043154f, 0.99388373f}
+};
+
+Gwn_Batch *DRW_cache_bone_octahedral_get(void)
+{
+ if (!SHC.drw_bone_octahedral) {
+ unsigned int v_idx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, nor, snor; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.snor = GWN_vertformat_attr_add(&format, "snor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 24);
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init_ex(&elb, GWN_PRIM_TRIS_ADJ, 6 * 8, 24, false);
+
+ for (int i = 0; i < 8; i++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_octahedral_solid_normals[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.snor, v_idx, bone_octahedral_smooth_normals[bone_octahedral_solid_tris[i][0]]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_octahedral_verts[bone_octahedral_solid_tris[i][0]]);
+ GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_octahedral_solid_normals[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.snor, v_idx, bone_octahedral_smooth_normals[bone_octahedral_solid_tris[i][1]]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_octahedral_verts[bone_octahedral_solid_tris[i][1]]);
+ GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_octahedral_solid_normals[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.snor, v_idx, bone_octahedral_smooth_normals[bone_octahedral_solid_tris[i][2]]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_octahedral_verts[bone_octahedral_solid_tris[i][2]]);
+ for (int j = 0; j < 6; ++j) {
+ GWN_indexbuf_add_generic_vert(&elb, bone_octahedral_solid_tris_adjacency[i][j]);
+ }
+ }
+
+ SHC.drw_bone_octahedral = GWN_batch_create_ex(GWN_PRIM_TRIS_ADJ, vbo, GWN_indexbuf_build(&elb),
+ GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+ }
+ return SHC.drw_bone_octahedral;
+}
+
+Gwn_Batch *DRW_cache_bone_octahedral_wire_outline_get(void)
+{
+ if (!SHC.drw_bone_octahedral_wire) {
+ unsigned int v_idx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, n1, n2; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 12 * 2);
+
+ for (int i = 0; i < 12; i++) {
+ const float *co1 = bone_octahedral_verts[bone_octahedral_wire[i * 2]];
+ const float *co2 = bone_octahedral_verts[bone_octahedral_wire[i * 2 + 1]];
+ const float *n1 = bone_octahedral_solid_normals[bone_octahedral_wire_adjacent_face[i * 2]];
+ const float *n2 = bone_octahedral_solid_normals[bone_octahedral_wire_adjacent_face[i * 2 + 1]];
+ add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n1, n2);
+ }
+
+ SHC.drw_bone_octahedral_wire = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_bone_octahedral_wire;
+}
+
+
+/* XXX TODO move that 1 unit cube to more common/generic place? */
+static const float bone_box_verts[8][3] = {
+ { 1.0f, 0.0f, 1.0f},
+ { 1.0f, 0.0f, -1.0f},
+ {-1.0f, 0.0f, -1.0f},
+ {-1.0f, 0.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}
+};
+
+static const float bone_box_smooth_normals[8][3] = {
+ { M_SQRT3, -M_SQRT3, M_SQRT3},
+ { M_SQRT3, -M_SQRT3, -M_SQRT3},
+ {-M_SQRT3, -M_SQRT3, -M_SQRT3},
+ {-M_SQRT3, -M_SQRT3, M_SQRT3},
+ { M_SQRT3, M_SQRT3, M_SQRT3},
+ { M_SQRT3, M_SQRT3, -M_SQRT3},
+ {-M_SQRT3, M_SQRT3, -M_SQRT3},
+ {-M_SQRT3, M_SQRT3, M_SQRT3},
+};
+
+static const unsigned int bone_box_wire[24] = {
+ 0, 1, 1, 2, 2, 3, 3, 0,
+ 4, 5, 5, 6, 6, 7, 7, 4,
+ 0, 4, 1, 5, 2, 6, 3, 7,
+};
+
+/* aligned with bone_octahedral_wire
+ * Contains adjacent normal index */
+static const unsigned int bone_box_wire_adjacent_face[24] = {
+ 0, 2, 0, 4, 1, 6, 1, 8,
+ 3, 10, 5, 10, 7, 11, 9, 11,
+ 3, 8, 2, 5, 4, 7, 6, 9,
+};
+
+static const unsigned int bone_box_solid_tris[12][3] = {
+ {0, 2, 1}, /* bottom */
+ {0, 3, 2},
+
+ {0, 1, 5}, /* sides */
+ {0, 5, 4},
+
+ {1, 2, 6},
+ {1, 6, 5},
+
+ {2, 3, 7},
+ {2, 7, 6},
+
+ {3, 0, 4},
+ {3, 4, 7},
+
+ {4, 5, 6}, /* top */
+ {4, 6, 7},
+};
+
+/**
+ * Store indices of generated verts from bone_box_solid_tris to define adjacency infos.
+ * See bone_octahedral_solid_tris for more infos.
+ **/
+static const unsigned int bone_box_solid_tris_adjacency[12][6] = {
+ { 0, 5, 1, 14, 2, 8},
+ { 3, 26, 4, 20, 5, 1},
+
+ { 6, 2, 7, 16, 8, 11},
+ { 9, 7, 10, 32, 11, 24},
+
+ {12, 0, 13, 22, 14, 17},
+ {15, 13, 16, 30, 17, 6},
+
+ {18, 3, 19, 28, 20, 23},
+ {21, 19, 22, 33, 23, 12},
+
+ {24, 4, 25, 10, 26, 29},
+ {27, 25, 28, 34, 29, 18},
+
+ {30, 9, 31, 15, 32, 35},
+ {33, 31, 34, 21, 35, 27},
+};
+
+/* aligned with bone_box_solid_tris */
+static const float bone_box_solid_normals[12][3] = {
+ { 0.0f, -1.0f, 0.0f},
+ { 0.0f, -1.0f, 0.0f},
+
+ { 1.0f, 0.0f, 0.0f},
+ { 1.0f, 0.0f, 0.0f},
+
+ { 0.0f, 0.0f, -1.0f},
+ { 0.0f, 0.0f, -1.0f},
+
+ {-1.0f, 0.0f, 0.0f},
+ {-1.0f, 0.0f, 0.0f},
+
+ { 0.0f, 0.0f, 1.0f},
+ { 0.0f, 0.0f, 1.0f},
+
+ { 0.0f, 1.0f, 0.0f},
+ { 0.0f, 1.0f, 0.0f},
+};
+
+Gwn_Batch *DRW_cache_bone_box_get(void)
+{
+ if (!SHC.drw_bone_box) {
+ unsigned int v_idx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, nor, snor; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.snor = GWN_vertformat_attr_add(&format, "snor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 36);
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init_ex(&elb, GWN_PRIM_TRIS_ADJ, 6 * 12, 36, false);
+
+ for (int i = 0; i < 12; i++) {
+ for (int j = 0; j < 3; j++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.nor, v_idx, bone_box_solid_normals[i]);
+ GWN_vertbuf_attr_set(vbo, attr_id.snor, v_idx, bone_box_smooth_normals[bone_box_solid_tris[i][j]]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, bone_box_verts[bone_box_solid_tris[i][j]]);
+ }
+ for (int j = 0; j < 6; ++j) {
+ GWN_indexbuf_add_generic_vert(&elb, bone_box_solid_tris_adjacency[i][j]);
+ }
+ }
+
+ SHC.drw_bone_box = GWN_batch_create_ex(GWN_PRIM_TRIS_ADJ, vbo, GWN_indexbuf_build(&elb),
+ GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+ }
+ return SHC.drw_bone_box;
+}
+
+Gwn_Batch *DRW_cache_bone_box_wire_outline_get(void)
+{
+ if (!SHC.drw_bone_box_wire) {
+ unsigned int v_idx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, n1, n2; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 12 * 2);
+
+ for (int i = 0; i < 12; i++) {
+ const float *co1 = bone_box_verts[bone_box_wire[i * 2]];
+ const float *co2 = bone_box_verts[bone_box_wire[i * 2 + 1]];
+ const float *n1 = bone_box_solid_normals[bone_box_wire_adjacent_face[i * 2]];
+ const float *n2 = bone_box_solid_normals[bone_box_wire_adjacent_face[i * 2 + 1]];
+ add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n1, n2);
+ }
+
+ SHC.drw_bone_box_wire = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_bone_box_wire;
+}
+
+
+Gwn_Batch *DRW_cache_bone_wire_wire_outline_get(void)
+{
+ if (!SHC.drw_bone_wire_wire) {
+ unsigned int v_idx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, n1, n2; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 2);
+
+ const float co1[3] = {0.0f, 0.0f, 0.0f};
+ const float co2[3] = {0.0f, 1.0f, 0.0f};
+ const float n[3] = {1.0f, 0.0f, 0.0f};
+ add_fancy_edge(vbo, attr_id.pos, attr_id.n1, attr_id.n2, &v_idx, co1, co2, n, n);
+
+ SHC.drw_bone_wire_wire = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_bone_wire_wire;
+}
+
+/* Helpers for envelope bone's solid sphere-with-hidden-equatorial-cylinder.
+ * Note that here we only encode head/tail in forth component of the vector. */
+static void benv_lat_lon_to_co(const float lat, const float lon, float r_nor[3])
+{
+ r_nor[0] = sinf(lat) * cosf(lon);
+ r_nor[1] = sinf(lat) * sinf(lon);
+ r_nor[2] = cosf(lat);
+}
+
+Gwn_Batch *DRW_cache_bone_envelope_solid_get(void)
+{
+ if (!SHC.drw_bone_envelope) {
+ const int lon_res = 24;
+ const int lat_res = 24;
+ const float lon_inc = 2.0f * M_PI / lon_res;
+ const float lat_inc = M_PI / lat_res;
+ unsigned int v_idx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, ((lat_res + 1) * 2) * lon_res * 1);
+
+ float lon = 0.0f;
+ for (int i = 0; i < lon_res; i++, lon += lon_inc) {
+ float lat = 0.0f;
+ float co1[3], co2[3];
+
+ /* Note: the poles are duplicated on purpose, to restart the strip. */
+
+ /* 1st sphere */
+ for (int j = 0; j < lat_res; j++, lat += lat_inc) {
+ benv_lat_lon_to_co(lat, lon, co1);
+ benv_lat_lon_to_co(lat, lon + lon_inc, co2);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, co1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, co2);
+ }
+
+ /* Closing the loop */
+ benv_lat_lon_to_co(M_PI, lon, co1);
+ benv_lat_lon_to_co(M_PI, lon + lon_inc, co2);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, co1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v_idx++, co2);
+ }
+
+ SHC.drw_bone_envelope = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_bone_envelope;
+}
+
+Gwn_Batch *DRW_cache_bone_envelope_outline_get(void)
+{
+ if (!SHC.drw_bone_envelope_outline) {
+# define CIRCLE_RESOL 64
+ float v0[2], v1[2], v2[2];
+ const float radius = 1.0f;
+
+ /* Position Only 2D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos0, pos1, pos2; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos0 = GWN_vertformat_attr_add(&format, "pos0", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.pos1 = GWN_vertformat_attr_add(&format, "pos1", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.pos2 = GWN_vertformat_attr_add(&format, "pos2", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, (CIRCLE_RESOL + 1) * 2);
+
+ v0[0] = radius * sinf((2.0f * M_PI * -2) / ((float)CIRCLE_RESOL));
+ v0[1] = radius * cosf((2.0f * M_PI * -2) / ((float)CIRCLE_RESOL));
+ v1[0] = radius * sinf((2.0f * M_PI * -1) / ((float)CIRCLE_RESOL));
+ v1[1] = radius * cosf((2.0f * M_PI * -1) / ((float)CIRCLE_RESOL));
+
+ /* Output 4 verts for each position. See shader for explanation. */
+ unsigned int v = 0;
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v2[0] = radius * sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v2[1] = radius * cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v , v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos2, v++, v2);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v , v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos2, v++, v2);
+ copy_v2_v2(v0, v1);
+ copy_v2_v2(v1, v2);
+ }
+ v2[0] = 0.0f;
+ v2[1] = radius;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v , v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos2, v++, v2);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v , v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos2, v++, v2);
+
+ SHC.drw_bone_envelope_outline = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+# undef CIRCLE_RESOL
+ }
+ return SHC.drw_bone_envelope_outline;
+}
+
+Gwn_Batch *DRW_cache_bone_point_get(void)
+{
+ if (!SHC.drw_bone_point) {
+#if 0 /* old style geometry sphere */
+ const int lon_res = 16;
+ const int lat_res = 8;
+ const float rad = 0.05f;
+ const float lon_inc = 2 * M_PI / lon_res;
+ const float lat_inc = M_PI / lat_res;
+ unsigned int v_idx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, nor; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, (lat_res - 1) * lon_res * 6);
+
+ float lon = 0.0f;
+ for (int i = 0; i < lon_res; i++, lon += lon_inc) {
+ float lat = 0.0f;
+ for (int j = 0; j < lat_res; j++, lat += lat_inc) {
+ if (j != lat_res - 1) { /* Pole */
+ add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat + lat_inc, lon + lon_inc);
+ add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat + lat_inc, lon);
+ add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat, lon);
+ }
+
+ if (j != 0) { /* Pole */
+ add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat, lon + lon_inc);
+ add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat + lat_inc, lon + lon_inc);
+ add_lat_lon_vert(vbo, attr_id.pos, attr_id.nor, &v_idx, rad, lat, lon);
+ }
+ }
+ }
+
+ SHC.drw_bone_point = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+#else
+# define CIRCLE_RESOL 64
+ float v[2];
+ const float radius = 0.05f;
+
+ /* Position Only 2D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL);
+
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[0] = radius * sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = radius * cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, a, v);
+ }
+
+ SHC.drw_bone_point = GWN_batch_create_ex(GWN_PRIM_TRI_FAN, vbo, NULL, GWN_BATCH_OWNS_VBO);
+# undef CIRCLE_RESOL
+#endif
+ }
+ return SHC.drw_bone_point;
+}
+
+Gwn_Batch *DRW_cache_bone_point_wire_outline_get(void)
+{
+ if (!SHC.drw_bone_point_wire) {
+#if 0 /* old style geometry sphere */
+ Gwn_VertBuf *vbo = sphere_wire_vbo(0.05f);
+ SHC.drw_bone_point_wire = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+#else
+# define CIRCLE_RESOL 64
+ float v0[2], v1[2];
+ const float radius = 0.05f;
+
+ /* Position Only 2D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos0, pos1; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos0 = GWN_vertformat_attr_add(&format, "pos0", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.pos1 = GWN_vertformat_attr_add(&format, "pos1", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, (CIRCLE_RESOL + 1) * 2);
+
+ v0[0] = radius * sinf((2.0f * M_PI * -1) / ((float)CIRCLE_RESOL));
+ v0[1] = radius * cosf((2.0f * M_PI * -1) / ((float)CIRCLE_RESOL));
+
+ unsigned int v = 0;
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v1[0] = radius * sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v1[1] = radius * cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v++, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v++, v1);
+ copy_v2_v2(v0, v1);
+ }
+ v1[0] = 0.0f;
+ v1[1] = radius;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v++, v1);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos0, v , v0);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos1, v++, v1);
+
+ SHC.drw_bone_point_wire = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+# undef CIRCLE_RESOL
+#endif
+ }
+ return SHC.drw_bone_point_wire;
+}
+
+static void set_bone_axis_vert(
+ Gwn_VertBuf *vbo, uint axis, uint pos, uint col,
+ unsigned int *v, const float *a, const float *p, const float *c)
+{
+ GWN_vertbuf_attr_set(vbo, axis, *v, a);
+ GWN_vertbuf_attr_set(vbo, pos, *v, p);
+ GWN_vertbuf_attr_set(vbo, col, *v, c);
+ *v += 1;
+}
+
+#define S_X 0.0215f
+#define S_Y 0.025f
+static float x_axis_name[4][2] = {
+ { 0.9f * S_X, 1.0f * S_Y}, {-1.0f * S_X, -1.0f * S_Y},
+ {-0.9f * S_X, 1.0f * S_Y}, { 1.0f * S_X, -1.0f * S_Y}
+};
+#define X_LEN (sizeof(x_axis_name) / (sizeof(float) * 2))
+#undef S_X
+#undef S_Y
+
+#define S_X 0.0175f
+#define S_Y 0.025f
+static float y_axis_name[6][2] = {
+ {-1.0f * S_X, 1.0f * S_Y}, { 0.0f * S_X, -0.1f * S_Y},
+ { 1.0f * S_X, 1.0f * S_Y}, { 0.0f * S_X, -0.1f * S_Y},
+ { 0.0f * S_X, -0.1f * S_Y}, { 0.0f * S_X, -1.0f * S_Y}
+};
+#define Y_LEN (sizeof(y_axis_name) / (sizeof(float) * 2))
+#undef S_X
+#undef S_Y
+
+#define S_X 0.02f
+#define S_Y 0.025f
+static float z_axis_name[10][2] = {
+ {-0.95f * S_X, 1.00f * S_Y}, { 0.95f * S_X, 1.00f * S_Y},
+ { 0.95f * S_X, 1.00f * S_Y}, { 0.95f * S_X, 0.90f * S_Y},
+ { 0.95f * S_X, 0.90f * S_Y}, {-1.00f * S_X, -0.90f * S_Y},
+ {-1.00f * S_X, -0.90f * S_Y}, {-1.00f * S_X, -1.00f * S_Y},
+ {-1.00f * S_X, -1.00f * S_Y}, { 1.00f * S_X, -1.00f * S_Y}
+};
+#define Z_LEN (sizeof(z_axis_name) / (sizeof(float) * 2))
+#undef S_X
+#undef S_Y
+
+#define S_X 0.007f
+#define S_Y 0.007f
+static float axis_marker[8][2] = {
+#if 0 /* square */
+ {-1.0f * S_X, 1.0f * S_Y}, { 1.0f * S_X, 1.0f * S_Y},
+ { 1.0f * S_X, 1.0f * S_Y}, { 1.0f * S_X, -1.0f * S_Y},
+ { 1.0f * S_X, -1.0f * S_Y}, {-1.0f * S_X, -1.0f * S_Y},
+ {-1.0f * S_X, -1.0f * S_Y}, {-1.0f * S_X, 1.0f * S_Y}
+#else /* diamond */
+ {-S_X, 0.f}, { 0.f, S_Y},
+ { 0.f, S_Y}, { S_X, 0.f},
+ { S_X, 0.f}, { 0.f, -S_Y},
+ { 0.f, -S_Y}, {-S_X, 0.f}
+#endif
+};
+#define MARKER_LEN (sizeof(axis_marker) / (sizeof(float) * 2))
+#define MARKER_FILL_LAYER 6
+#undef S_X
+#undef S_Y
+
+#define S_X 0.0007f
+#define S_Y 0.0007f
+#define O_X 0.001f
+#define O_Y -0.001f
+static float axis_name_shadow[8][2] = {
+ {-S_X + O_X, S_Y + O_Y}, { S_X + O_X, S_Y + O_Y},
+ { S_X + O_X, S_Y + O_Y}, { S_X + O_X, -S_Y + O_Y},
+ { S_X + O_X, -S_Y + O_Y}, {-S_X + O_X, -S_Y + O_Y},
+ {-S_X + O_X, -S_Y + O_Y}, {-S_X + O_X, S_Y + O_Y}
+};
+// #define SHADOW_RES (sizeof(axis_name_shadow) / (sizeof(float) * 2))
+#define SHADOW_RES 0
+#undef O_X
+#undef O_Y
+#undef S_X
+#undef S_Y
+
+Gwn_Batch *DRW_cache_bone_arrows_get(void)
+{
+ if (!SHC.drw_bone_arrows) {
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint axis, pos, col; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.axis = GWN_vertformat_attr_add(&format, "axis", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ attr_id.pos = GWN_vertformat_attr_add(&format, "screenPos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.col = GWN_vertformat_attr_add(&format, "colorAxis", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ /* Line */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, (2 + MARKER_LEN * MARKER_FILL_LAYER) * 3 +
+ (X_LEN + Y_LEN + Z_LEN) * (1 + SHADOW_RES));
+
+ unsigned int v = 0;
+
+ for (int axis = 0; axis < 3; axis++) {
+ float pos[2] = {0.0f, 0.0f};
+ float c[3] = {0.0f, 0.0f, 0.0f};
+ float a = 0.0f;
+ /* center to axis line */
+ set_bone_axis_vert(vbo, attr_id.axis, attr_id.pos, attr_id.col, &v, &a, pos, c);
+ c[axis] = 0.5f;
+ a = axis + 0.25f;
+ set_bone_axis_vert(vbo, attr_id.axis, attr_id.pos, attr_id.col, &v, &a, pos, c);
+
+ /* Axis end marker */
+ for (int j = 1; j < MARKER_FILL_LAYER + 1; ++j) {
+ for (int i = 0; i < MARKER_LEN; ++i) {
+ float tmp[2];
+ mul_v2_v2fl(tmp, axis_marker[i], j / (float)MARKER_FILL_LAYER);
+ set_bone_axis_vert(vbo, attr_id.axis, attr_id.pos, attr_id.col,
+ &v, &a, tmp, c);
+ }
+ }
+
+ a = axis + 0.31f;
+ /* Axis name */
+ int axis_v_ct;
+ float (*axis_verts)[2];
+ if (axis == 0) {
+ axis_verts = x_axis_name;
+ axis_v_ct = X_LEN;
+ }
+ else if (axis == 1) {
+ axis_verts = y_axis_name;
+ axis_v_ct = Y_LEN;
+ }
+ else {
+ axis_verts = z_axis_name;
+ axis_v_ct = Z_LEN;
+ }
+
+ /* Axis name shadows */
+ copy_v3_fl(c, 0.0f);
+ c[axis] = 0.3f;
+ for (int j = 0; j < SHADOW_RES; ++j) {
+ for (int i = 0; i < axis_v_ct; ++i) {
+ float tmp[2];
+ add_v2_v2v2(tmp, axis_verts[i], axis_name_shadow[j]);
+ set_bone_axis_vert(vbo, attr_id.axis, attr_id.pos, attr_id.col,
+ &v, &a, tmp, c);
+ }
+ }
+
+ /* Axis name */
+ copy_v3_fl(c, 0.1f);
+ c[axis] = 1.0f;
+ for (int i = 0; i < axis_v_ct; ++i) {
+ set_bone_axis_vert(vbo, attr_id.axis, attr_id.pos, attr_id.col,
+ &v, &a, axis_verts[i], c);
+ }
+ }
+
+ SHC.drw_bone_arrows = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_bone_arrows;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Camera
+ * \{ */
+
+/**
+ * We could make these more generic functions.
+ * although filling 1d lines is not common.
+ *
+ * \note Use x coordinate to identify the vertex the vertex shader take care to place it appropriately.
+ */
+
+static const float camera_coords_frame_bounds[5] = {
+ 0.0f, /* center point */
+ 1.0f, /* + X + Y */
+ 2.0f, /* + X - Y */
+ 3.0f, /* - X - Y */
+ 4.0f, /* - X + Y */
+};
+
+static const float camera_coords_frame_tri[3] = {
+ 5.0f, /* tria + X */
+ 6.0f, /* tria - X */
+ 7.0f, /* tria + Y */
+};
+
+/** Draw a loop of lines. */
+static void camera_fill_lines_loop_fl_v1(
+ Gwn_VertBufRaw *pos_step,
+ const float *coords, const uint coords_len)
+{
+ for (uint i = 0, i_prev = coords_len - 1; i < coords_len; i_prev = i++) {
+ *((float *)GWN_vertbuf_raw_step(pos_step)) = coords[i_prev];
+ *((float *)GWN_vertbuf_raw_step(pos_step)) = coords[i];
+ }
+}
+
+/** Fan lines out from the first vertex. */
+static void camera_fill_lines_fan_fl_v1(
+ Gwn_VertBufRaw *pos_step,
+ const float *coords, const uint coords_len)
+{
+ for (uint i = 1; i < coords_len; i++) {
+ *((float *)GWN_vertbuf_raw_step(pos_step)) = coords[0];
+ *((float *)GWN_vertbuf_raw_step(pos_step)) = coords[i];
+ }
+}
+
+/** Simply fill the array. */
+static void camera_fill_array_fl_v1(
+ Gwn_VertBufRaw *pos_step,
+ const float *coords, const uint coords_len)
+{
+ for (uint i = 0; i < coords_len; i++) {
+ *((float *)GWN_vertbuf_raw_step(pos_step)) = coords[i];
+ }
+}
+
+
+Gwn_Batch *DRW_cache_camera_get(void)
+{
+ if (!SHC.drw_camera) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const int vbo_len_capacity = 22;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ Gwn_VertBufRaw pos_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step);
+
+ /* camera cone (from center to frame) */
+ camera_fill_lines_fan_fl_v1(&pos_step, camera_coords_frame_bounds, ARRAY_SIZE(camera_coords_frame_bounds));
+
+ /* camera frame (skip center) */
+ camera_fill_lines_loop_fl_v1(&pos_step, &camera_coords_frame_bounds[1], ARRAY_SIZE(camera_coords_frame_bounds) - 1);
+
+ /* camera triangle (above the frame) */
+ camera_fill_lines_loop_fl_v1(&pos_step, camera_coords_frame_tri, ARRAY_SIZE(camera_coords_frame_tri));
+
+ BLI_assert(vbo_len_capacity == GWN_vertbuf_raw_used(&pos_step));
+
+ SHC.drw_camera = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_camera;
+}
+
+Gwn_Batch *DRW_cache_camera_frame_get(void)
+{
+ if (!SHC.drw_camera_frame) {
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const int vbo_len_capacity = 8;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ Gwn_VertBufRaw pos_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step);
+
+ /* camera frame (skip center) */
+ camera_fill_lines_loop_fl_v1(&pos_step, &camera_coords_frame_bounds[1], ARRAY_SIZE(camera_coords_frame_bounds) - 1);
+
+ BLI_assert(vbo_len_capacity == GWN_vertbuf_raw_used(&pos_step));
+
+ SHC.drw_camera_frame = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_camera_frame;
+}
+
+Gwn_Batch *DRW_cache_camera_tria_get(void)
+{
+ if (!SHC.drw_camera_tria) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ }
+
+ /* Vertices */
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const int vbo_len_capacity = 3;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ Gwn_VertBufRaw pos_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step);
+
+ /* camera triangle (above the frame) */
+ camera_fill_array_fl_v1(&pos_step, camera_coords_frame_tri, ARRAY_SIZE(camera_coords_frame_tri));
+
+ BLI_assert(vbo_len_capacity == GWN_vertbuf_raw_used(&pos_step));
+
+ SHC.drw_camera_tria = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_camera_tria;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Object Mode Helpers
+ * \{ */
+
+/* Object Center */
+Gwn_Batch *DRW_cache_single_vert_get(void)
+{
+ if (!SHC.drw_single_vertice) {
+ float v1[3] = {0.0f, 0.0f, 0.0f};
+
+ /* Position Only 3D format */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 1);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 0, v1);
+
+ SHC.drw_single_vertice = GWN_batch_create_ex(GWN_PRIM_POINTS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return SHC.drw_single_vertice;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Meshes
+ * \{ */
+
+Gwn_Batch *DRW_cache_mesh_surface_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_all_triangles(me);
+}
+
+void DRW_cache_mesh_wire_overlay_get(
+ Object *ob,
+ Gwn_Batch **r_tris, Gwn_Batch **r_ledges, Gwn_Batch **r_lverts)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+
+ *r_tris = DRW_mesh_batch_cache_get_overlay_triangles(me);
+ *r_ledges = DRW_mesh_batch_cache_get_overlay_loose_edges(me);
+ *r_lverts = DRW_mesh_batch_cache_get_overlay_loose_verts(me);
+}
+
+void DRW_cache_mesh_normals_overlay_get(
+ Object *ob,
+ Gwn_Batch **r_tris, Gwn_Batch **r_ledges, Gwn_Batch **r_lverts)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+
+ *r_tris = DRW_mesh_batch_cache_get_overlay_triangles_nor(me);
+ *r_ledges = DRW_mesh_batch_cache_get_overlay_loose_edges_nor(me);
+ *r_lverts = DRW_mesh_batch_cache_get_overlay_loose_verts(me);
+}
+
+Gwn_Batch *DRW_cache_face_centers_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+
+ return DRW_mesh_batch_cache_get_overlay_facedots(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_wire_outline_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_fancy_edges(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_surface_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_triangles_with_normals(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_surface_weights_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(me, ob->actdef - 1);
+}
+
+Gwn_Batch *DRW_cache_mesh_surface_vert_colors_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(me);
+}
+
+/* Return list of batches */
+Gwn_Batch **DRW_cache_mesh_surface_shaded_get(
+ Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
+ char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_surface_shaded(me, gpumat_array, gpumat_array_len,
+ auto_layer_names, auto_layer_is_srgb, auto_layer_count);
+}
+
+/* Return list of batches */
+Gwn_Batch **DRW_cache_mesh_surface_texpaint_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_surface_texpaint(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_surface_texpaint_single_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_surface_texpaint_single(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_surface_verts_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_points_with_normals(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_edges_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_all_edges(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_verts_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_all_verts(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_edges_paint_overlay_get(Object *ob, bool use_wire, bool use_sel)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_weight_overlay_edges(me, use_wire, use_sel);
+}
+
+Gwn_Batch *DRW_cache_mesh_faces_weight_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_weight_overlay_faces(me);
+}
+
+Gwn_Batch *DRW_cache_mesh_verts_weight_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ return DRW_mesh_batch_cache_get_weight_overlay_verts(me);
+}
+
+void DRW_cache_mesh_sculpt_coords_ensure(Object *ob)
+{
+ BLI_assert(ob->type == OB_MESH);
+
+ Mesh *me = ob->data;
+ DRW_mesh_cache_sculpt_coords_ensure(me);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Curve
+ * \{ */
+
+Gwn_Batch *DRW_cache_curve_edge_wire_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_CURVE);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_wire_edge(cu, ob->curve_cache);
+}
+
+Gwn_Batch *DRW_cache_curve_edge_normal_get(Object *ob, float normal_size)
+{
+ BLI_assert(ob->type == OB_CURVE);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_normal_edge(cu, ob->curve_cache, normal_size);
+}
+
+Gwn_Batch *DRW_cache_curve_edge_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_CURVE);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_overlay_edges(cu);
+}
+
+Gwn_Batch *DRW_cache_curve_vert_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_CURVE);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_overlay_verts(cu);
+}
+
+Gwn_Batch *DRW_cache_curve_surface_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_CURVE);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->curve_cache);
+}
+
+/* Return list of batches */
+Gwn_Batch **DRW_cache_curve_surface_shaded_get(
+ Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len)
+{
+ BLI_assert(ob->type == OB_CURVE);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_surface_shaded(cu, ob->curve_cache, gpumat_array, gpumat_array_len);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name MetaBall
+ * \{ */
+
+Gwn_Batch *DRW_cache_mball_surface_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_MBALL);
+ return DRW_metaball_batch_cache_get_triangles_with_normals(ob);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Font
+ * \{ */
+
+Gwn_Batch *DRW_cache_text_edge_wire_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_FONT);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_wire_edge(cu, ob->curve_cache);
+}
+
+Gwn_Batch *DRW_cache_text_surface_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_FONT);
+ struct Curve *cu = ob->data;
+ if (cu->editfont && (cu->flag & CU_FAST)) {
+ return NULL;
+ }
+ return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->curve_cache);
+}
+
+Gwn_Batch **DRW_cache_text_surface_shaded_get(
+ Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len)
+{
+ BLI_assert(ob->type == OB_FONT);
+ struct Curve *cu = ob->data;
+ if (cu->editfont && (cu->flag & CU_FAST)) {
+ return NULL;
+ }
+ return DRW_curve_batch_cache_get_surface_shaded(cu, ob->curve_cache, gpumat_array, gpumat_array_len);
+}
+
+Gwn_Batch *DRW_cache_text_cursor_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_FONT);
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_overlay_cursor(cu);
+}
+
+Gwn_Batch *DRW_cache_text_select_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_FONT);
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_overlay_select(cu);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Surface
+ * \{ */
+
+Gwn_Batch *DRW_cache_surf_surface_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_SURF);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_triangles_with_normals(cu, ob->curve_cache);
+}
+
+/* Return list of batches */
+Gwn_Batch **DRW_cache_surf_surface_shaded_get(
+ Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len)
+{
+ BLI_assert(ob->type == OB_SURF);
+
+ struct Curve *cu = ob->data;
+ return DRW_curve_batch_cache_get_surface_shaded(cu, ob->curve_cache, gpumat_array, gpumat_array_len);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Lattice
+ * \{ */
+
+Gwn_Batch *DRW_cache_lattice_verts_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_LATTICE);
+
+ struct Lattice *lt = ob->data;
+ return DRW_lattice_batch_cache_get_all_verts(lt);
+}
+
+Gwn_Batch *DRW_cache_lattice_wire_get(Object *ob, bool use_weight)
+{
+ BLI_assert(ob->type == OB_LATTICE);
+
+ Lattice *lt = ob->data;
+ int actdef = -1;
+
+ if (use_weight && ob->defbase.first && lt->editlatt->latt->dvert) {
+ actdef = ob->actdef - 1;
+ }
+
+ return DRW_lattice_batch_cache_get_all_edges(lt, use_weight, actdef);
+}
+
+Gwn_Batch *DRW_cache_lattice_vert_overlay_get(Object *ob)
+{
+ BLI_assert(ob->type == OB_LATTICE);
+
+ struct Lattice *lt = ob->data;
+ return DRW_lattice_batch_cache_get_overlay_verts(lt);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Particles
+ * \{ */
+
+Gwn_Batch *DRW_cache_particles_get_hair(ParticleSystem *psys, ModifierData *md)
+{
+ return DRW_particles_batch_cache_get_hair(psys, md);
+}
+
+Gwn_Batch *DRW_cache_particles_get_dots(Object *object, ParticleSystem *psys)
+{
+ return DRW_particles_batch_cache_get_dots(object, psys);
+}
+
+Gwn_Batch *DRW_cache_particles_get_prim(int type)
+{
+ switch (type) {
+ case PART_DRAW_CROSS:
+ if (!SHC.drw_particle_cross) {
+ static Gwn_VertFormat format = { 0 };
+ static unsigned pos_id, axis_id;
+
+ if (format.attrib_ct == 0) {
+ pos_id = GWN_vertformat_attr_add(&format, "inst_pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ axis_id = GWN_vertformat_attr_add(&format, "axis", GWN_COMP_I32, 1, GWN_FETCH_INT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 6);
+
+ /* X axis */
+ float co[3] = {-1.0f, 0.0f, 0.0f};
+ int axis = -1;
+ GWN_vertbuf_attr_set(vbo, pos_id, 0, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 0, &axis);
+
+ co[0] = 1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 1, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 1, &axis);
+
+ /* Y axis */
+ co[0] = 0.0f;
+ co[1] = -1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 2, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 2, &axis);
+
+ co[1] = 1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 3, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 3, &axis);
+
+ /* Z axis */
+ co[1] = 0.0f;
+ co[2] = -1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 4, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 4, &axis);
+
+ co[2] = 1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 5, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 5, &axis);
+
+ SHC.drw_particle_cross = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+ return SHC.drw_particle_cross;
+ case PART_DRAW_AXIS:
+ if (!SHC.drw_particle_axis) {
+ static Gwn_VertFormat format = { 0 };
+ static unsigned pos_id, axis_id;
+
+ if (format.attrib_ct == 0) {
+ pos_id = GWN_vertformat_attr_add(&format, "inst_pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ axis_id = GWN_vertformat_attr_add(&format, "axis", GWN_COMP_I32, 1, GWN_FETCH_INT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, 6);
+
+ /* X axis */
+ float co[3] = {0.0f, 0.0f, 0.0f};
+ int axis = 0;
+ GWN_vertbuf_attr_set(vbo, pos_id, 0, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 0, &axis);
+
+ co[0] = 1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 1, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 1, &axis);
+
+ /* Y axis */
+ co[0] = 0.0f;
+ axis = 1;
+ GWN_vertbuf_attr_set(vbo, pos_id, 2, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 2, &axis);
+
+ co[1] = 1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 3, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 3, &axis);
+
+ /* Z axis */
+ co[1] = 0.0f;
+ axis = 2;
+ GWN_vertbuf_attr_set(vbo, pos_id, 4, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 4, &axis);
+
+ co[2] = 1.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, 5, co);
+ GWN_vertbuf_attr_set(vbo, axis_id, 5, &axis);
+
+ SHC.drw_particle_axis = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+ return SHC.drw_particle_axis;
+ case PART_DRAW_CIRC:
+#define CIRCLE_RESOL 32
+ if (!SHC.drw_particle_circle) {
+ float v[3] = {0.0f, 0.0f, 0.0f};
+ int axis = -1;
+
+ static Gwn_VertFormat format = { 0 };
+ static unsigned pos_id, axis_id;
+
+ if (format.attrib_ct == 0) {
+ pos_id = GWN_vertformat_attr_add(&format, "inst_pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ axis_id = GWN_vertformat_attr_add(&format, "axis", GWN_COMP_I32, 1, GWN_FETCH_INT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, CIRCLE_RESOL);
+
+ for (int a = 0; a < CIRCLE_RESOL; a++) {
+ v[0] = sinf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[1] = cosf((2.0f * M_PI * a) / ((float)CIRCLE_RESOL));
+ v[2] = 0.0f;
+ GWN_vertbuf_attr_set(vbo, pos_id, a, v);
+ GWN_vertbuf_attr_set(vbo, axis_id, a, &axis);
+ }
+
+ SHC.drw_particle_circle = GWN_batch_create_ex(GWN_PRIM_LINE_LOOP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+ return SHC.drw_particle_circle;
+#undef CIRCLE_RESOL
+ default:
+ BLI_assert(false);
+ break;
+ }
+
+ return NULL;
+}
+
+/* 3D cursor */
+Gwn_Batch *DRW_cache_cursor_get(void)
+{
+ if (!SHC.drw_cursor) {
+ const float f5 = 0.25f;
+ const float f10 = 0.5f;
+ const float f20 = 1.0f;
+
+ const int segments = 16;
+ const int vert_ct = segments + 8;
+ const int index_ct = vert_ct + 5;
+
+ unsigned char red[3] = {255, 0, 0};
+ unsigned char white[3] = {255, 255, 255};
+ unsigned char crosshair_color[3];
+ UI_GetThemeColor3ubv(TH_VIEW_OVERLAY, crosshair_color);
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, color; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ attr_id.color = GWN_vertformat_attr_add(&format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init_ex(&elb, GWN_PRIM_LINE_STRIP, index_ct, vert_ct, true);
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vert_ct);
+
+ int v = 0;
+ for (int i = 0; i < segments; ++i) {
+ float angle = (float)(2 * M_PI) * ((float)i / (float)segments);
+ float x = f10 * cosf(angle);
+ float y = f10 * sinf(angle);
+
+ if (i % 2 == 0)
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, red);
+ else
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, white);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){x, y});
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+ }
+ GWN_indexbuf_add_generic_vert(&elb, 0);
+ GWN_indexbuf_add_primitive_restart(&elb);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){-f20, 0});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){-f5, 0});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+
+ GWN_indexbuf_add_primitive_restart(&elb);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){+f5, 0});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){+f20, 0});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+
+ GWN_indexbuf_add_primitive_restart(&elb);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, -f20});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, -f5});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+
+ GWN_indexbuf_add_primitive_restart(&elb);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, +f5});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, v, (const float[2]){0, +f20});
+ GWN_vertbuf_attr_set(vbo, attr_id.color, v, crosshair_color);
+ GWN_indexbuf_add_generic_vert(&elb, v++);
+
+ Gwn_IndexBuf *ibo = GWN_indexbuf_build(&elb);
+
+ SHC.drw_cursor = GWN_batch_create_ex(GWN_PRIM_LINE_STRIP, vbo, ibo, GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+ }
+ return SHC.drw_cursor;
+}
diff --git a/source/blender/draw/intern/draw_cache.h b/source/blender/draw/intern/draw_cache.h
new file mode 100644
index 00000000000..22a5588599f
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache.h
@@ -0,0 +1,175 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_cache.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_CACHE_H__
+#define __DRAW_CACHE_H__
+
+struct Gwn_Batch;
+struct GPUMaterial;
+struct Object;
+struct ModifierData;
+
+void DRW_shape_cache_free(void);
+
+/* 3D cursor */
+struct Gwn_Batch *DRW_cache_cursor_get(void);
+
+/* Common Shapes */
+struct Gwn_Batch *DRW_cache_fullscreen_quad_get(void);
+struct Gwn_Batch *DRW_cache_quad_get(void);
+struct Gwn_Batch *DRW_cache_sphere_get(void);
+struct Gwn_Batch *DRW_cache_single_vert_get(void);
+struct Gwn_Batch *DRW_cache_single_line_get(void);
+struct Gwn_Batch *DRW_cache_single_line_endpoints_get(void);
+struct Gwn_Batch *DRW_cache_screenspace_circle_get(void);
+
+/* Common Object */
+struct Gwn_Batch *DRW_cache_object_wire_outline_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_object_surface_get(struct Object *ob);
+struct Gwn_Batch **DRW_cache_object_surface_material_get(
+ struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
+ char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count);
+
+/* Empties */
+struct Gwn_Batch *DRW_cache_plain_axes_get(void);
+struct Gwn_Batch *DRW_cache_single_arrow_get(void);
+struct Gwn_Batch *DRW_cache_cube_get(void);
+struct Gwn_Batch *DRW_cache_circle_get(void);
+struct Gwn_Batch *DRW_cache_square_get(void);
+struct Gwn_Batch *DRW_cache_empty_sphere_get(void);
+struct Gwn_Batch *DRW_cache_empty_cone_get(void);
+struct Gwn_Batch *DRW_cache_arrows_get(void);
+struct Gwn_Batch *DRW_cache_axis_names_get(void);
+struct Gwn_Batch *DRW_cache_image_plane_get(void);
+struct Gwn_Batch *DRW_cache_image_plane_wire_get(void);
+
+/* Force Field */
+struct Gwn_Batch *DRW_cache_field_wind_get(void);
+struct Gwn_Batch *DRW_cache_field_force_get(void);
+struct Gwn_Batch *DRW_cache_field_vortex_get(void);
+struct Gwn_Batch *DRW_cache_field_tube_limit_get(void);
+struct Gwn_Batch *DRW_cache_field_cone_limit_get(void);
+
+/* Lamps */
+struct Gwn_Batch *DRW_cache_lamp_get(void);
+struct Gwn_Batch *DRW_cache_lamp_shadows_get(void);
+struct Gwn_Batch *DRW_cache_lamp_sunrays_get(void);
+struct Gwn_Batch *DRW_cache_lamp_area_get(void);
+struct Gwn_Batch *DRW_cache_lamp_hemi_get(void);
+struct Gwn_Batch *DRW_cache_lamp_spot_get(void);
+struct Gwn_Batch *DRW_cache_lamp_spot_square_get(void);
+
+/* Camera */
+struct Gwn_Batch *DRW_cache_camera_get(void);
+struct Gwn_Batch *DRW_cache_camera_frame_get(void);
+struct Gwn_Batch *DRW_cache_camera_tria_get(void);
+
+/* Speaker */
+struct Gwn_Batch *DRW_cache_speaker_get(void);
+
+/* Probe */
+struct Gwn_Batch *DRW_cache_lightprobe_cube_get(void);
+struct Gwn_Batch *DRW_cache_lightprobe_grid_get(void);
+struct Gwn_Batch *DRW_cache_lightprobe_planar_get(void);
+
+/* Bones */
+struct Gwn_Batch *DRW_cache_bone_octahedral_get(void);
+struct Gwn_Batch *DRW_cache_bone_octahedral_wire_outline_get(void);
+struct Gwn_Batch *DRW_cache_bone_box_get(void);
+struct Gwn_Batch *DRW_cache_bone_box_wire_outline_get(void);
+struct Gwn_Batch *DRW_cache_bone_wire_wire_outline_get(void);
+struct Gwn_Batch *DRW_cache_bone_envelope_solid_get(void);
+struct Gwn_Batch *DRW_cache_bone_envelope_outline_get(void);
+struct Gwn_Batch *DRW_cache_bone_envelope_head_wire_outline_get(void);
+struct Gwn_Batch *DRW_cache_bone_point_get(void);
+struct Gwn_Batch *DRW_cache_bone_point_wire_outline_get(void);
+struct Gwn_Batch *DRW_cache_bone_arrows_get(void);
+
+/* Meshes */
+struct Gwn_Batch *DRW_cache_mesh_surface_overlay_get(struct Object *ob);
+void DRW_cache_mesh_wire_overlay_get(
+ struct Object *ob,
+ struct Gwn_Batch **r_tris, struct Gwn_Batch **r_ledges, struct Gwn_Batch **r_lverts);
+void DRW_cache_mesh_normals_overlay_get(
+ struct Object *ob,
+ struct Gwn_Batch **r_tris, struct Gwn_Batch **r_ledges, struct Gwn_Batch **r_lverts);
+struct Gwn_Batch *DRW_cache_face_centers_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_wire_outline_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_surface_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_surface_weights_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_surface_vert_colors_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_surface_verts_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_edges_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_verts_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_edges_paint_overlay_get(struct Object *ob, bool use_wire, bool use_sel);
+struct Gwn_Batch *DRW_cache_mesh_faces_weight_overlay_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_verts_weight_overlay_get(struct Object *ob);
+struct Gwn_Batch **DRW_cache_mesh_surface_shaded_get(
+ struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
+ char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count);
+struct Gwn_Batch **DRW_cache_mesh_surface_texpaint_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_mesh_surface_texpaint_single_get(struct Object *ob);
+
+void DRW_cache_mesh_sculpt_coords_ensure(struct Object *ob);
+
+/* Curve */
+struct Gwn_Batch *DRW_cache_curve_surface_get(struct Object *ob);
+struct Gwn_Batch **DRW_cache_curve_surface_shaded_get(
+ struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
+struct Gwn_Batch *DRW_cache_curve_surface_verts_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_curve_edge_wire_get(struct Object *ob);
+/* edit-mode */
+struct Gwn_Batch *DRW_cache_curve_edge_normal_get(struct Object *ob, float normal_size);
+struct Gwn_Batch *DRW_cache_curve_edge_overlay_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_curve_vert_overlay_get(struct Object *ob);
+
+/* Font */
+struct Gwn_Batch *DRW_cache_text_edge_wire_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_text_surface_get(struct Object *ob);
+struct Gwn_Batch **DRW_cache_text_surface_shaded_get(
+ struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
+/* edit-mode */
+struct Gwn_Batch *DRW_cache_text_cursor_overlay_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_text_select_overlay_get(struct Object *ob);
+
+/* Surface */
+struct Gwn_Batch *DRW_cache_surf_surface_get(struct Object *ob);
+struct Gwn_Batch **DRW_cache_surf_surface_shaded_get(
+ struct Object *ob, struct GPUMaterial **gpumat_array, uint gpumat_array_len);
+
+/* Lattice */
+struct Gwn_Batch *DRW_cache_lattice_verts_get(struct Object *ob);
+struct Gwn_Batch *DRW_cache_lattice_wire_get(struct Object *ob, bool use_weight);
+struct Gwn_Batch *DRW_cache_lattice_vert_overlay_get(struct Object *ob);
+
+/* Particles */
+struct Gwn_Batch *DRW_cache_particles_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
+struct Gwn_Batch *DRW_cache_particles_get_dots(struct Object *object, struct ParticleSystem *psys);
+struct Gwn_Batch *DRW_cache_particles_get_prim(int type);
+
+/* Metaball */
+struct Gwn_Batch *DRW_cache_mball_surface_get(struct Object *ob);
+
+#endif /* __DRAW_CACHE_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl.h b/source/blender/draw/intern/draw_cache_impl.h
new file mode 100644
index 00000000000..cfc57dd6e40
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl.h
@@ -0,0 +1,128 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_cache_impl.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_CACHE_IMPL_H__
+#define __DRAW_CACHE_IMPL_H__
+
+struct CurveCache;
+struct GPUMaterial;
+struct Gwn_Batch;
+struct Gwn_IndexBuf;
+struct Gwn_VertBuf;
+struct ListBase;
+struct ModifierData;
+struct ParticleSystem;
+
+struct Curve;
+struct Lattice;
+struct Mesh;
+struct MetaBall;
+
+/* Expose via BKE callbacks */
+void DRW_mball_batch_cache_dirty(struct MetaBall *mb, int mode);
+void DRW_mball_batch_cache_free(struct MetaBall *mb);
+
+void DRW_curve_batch_cache_dirty(struct Curve *cu, int mode);
+void DRW_curve_batch_cache_free(struct Curve *cu);
+
+void DRW_mesh_batch_cache_dirty(struct Mesh *me, int mode);
+void DRW_mesh_batch_cache_free(struct Mesh *me);
+
+void DRW_lattice_batch_cache_dirty(struct Lattice *lt, int mode);
+void DRW_lattice_batch_cache_free(struct Lattice *lt);
+
+void DRW_particle_batch_cache_dirty(struct ParticleSystem *psys, int mode);
+void DRW_particle_batch_cache_free(struct ParticleSystem *psys);
+
+/* Curve */
+struct Gwn_Batch *DRW_curve_batch_cache_get_wire_edge(struct Curve *cu, struct CurveCache *ob_curve_cache);
+struct Gwn_Batch *DRW_curve_batch_cache_get_normal_edge(
+ struct Curve *cu, struct CurveCache *ob_curve_cache, float normal_size);
+struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_edges(struct Curve *cu);
+struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_verts(struct Curve *cu);
+
+struct Gwn_Batch *DRW_curve_batch_cache_get_triangles_with_normals(struct Curve *cu, struct CurveCache *ob_curve_cache);
+struct Gwn_Batch **DRW_curve_batch_cache_get_surface_shaded(
+ struct Curve *cu, struct CurveCache *ob_curve_cache,
+ struct GPUMaterial **gpumat_array, uint gpumat_array_len);
+
+/* Metaball */
+struct Gwn_Batch *DRW_metaball_batch_cache_get_triangles_with_normals(struct Object *ob);
+
+/* Curve (Font) */
+struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_cursor(struct Curve *cu);
+struct Gwn_Batch *DRW_curve_batch_cache_get_overlay_select(struct Curve *cu);
+
+/* DispList */
+struct Gwn_VertBuf *DRW_displist_vertbuf_calc_pos_with_normals(struct ListBase *lb);
+struct Gwn_IndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(struct ListBase *lb);
+struct Gwn_IndexBuf **DRW_displist_indexbuf_calc_triangles_in_order_split_by_material(
+ struct ListBase *lb, uint gpumat_array_len);
+struct Gwn_Batch **DRW_displist_batch_calc_tri_pos_normals_and_uv_split_by_material(
+ struct ListBase *lb, uint gpumat_array_len);
+
+/* Lattice */
+struct Gwn_Batch *DRW_lattice_batch_cache_get_all_edges(struct Lattice *lt, bool use_weight, const int actdef);
+struct Gwn_Batch *DRW_lattice_batch_cache_get_all_verts(struct Lattice *lt);
+struct Gwn_Batch *DRW_lattice_batch_cache_get_overlay_verts(struct Lattice *lt);
+
+/* Mesh */
+
+struct Gwn_Batch **DRW_mesh_batch_cache_get_surface_shaded(
+ struct Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
+ char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count);
+struct Gwn_Batch **DRW_mesh_batch_cache_get_surface_texpaint(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_surface_texpaint_single(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(struct Mesh *me, bool use_wire, bool use_sel);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_weight_overlay_faces(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_weight_overlay_verts(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_all_edges(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_all_triangles(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_normals(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(struct Mesh *me, int defgroup);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_select_id(struct Mesh *me, bool use_hide, uint select_id_offset);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_select_mask(struct Mesh *me, bool use_hide);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_points_with_normals(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_all_verts(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_fancy_edges(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_overlay_triangles(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_overlay_triangles_nor(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_overlay_loose_edges(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_overlay_loose_edges_nor(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_overlay_loose_verts(struct Mesh *me);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_overlay_facedots(struct Mesh *me);
+/* edit-mesh selection (use generic function for faces) */
+struct Gwn_Batch *DRW_mesh_batch_cache_get_facedots_with_select_id(struct Mesh *me, uint select_id_offset);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_edges_with_select_id(struct Mesh *me, uint select_id_offset);
+struct Gwn_Batch *DRW_mesh_batch_cache_get_verts_with_select_id(struct Mesh *me, uint select_id_offset);
+
+void DRW_mesh_cache_sculpt_coords_ensure(struct Mesh *me);
+
+/* Particles */
+struct Gwn_Batch *DRW_particles_batch_cache_get_hair(struct ParticleSystem *psys, struct ModifierData *md);
+struct Gwn_Batch *DRW_particles_batch_cache_get_dots(struct Object *object, struct ParticleSystem *psys);
+
+#endif /* __DRAW_CACHE_IMPL_H__ */
diff --git a/source/blender/draw/intern/draw_cache_impl_curve.c b/source/blender/draw/intern/draw_cache_impl_curve.c
new file mode 100644
index 00000000000..3939ea062e9
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_curve.c
@@ -0,0 +1,1118 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file draw_cache_impl_curve.c
+ * \ingroup draw
+ *
+ * \brief Curve API for render engines
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+
+#include "DNA_curve_types.h"
+
+#include "BKE_curve.h"
+
+#include "BKE_font.h"
+
+#include "GPU_batch.h"
+
+#include "UI_resources.h"
+
+#include "draw_cache_impl.h" /* own include */
+
+#define SELECT 1
+#define ACTIVE_NURB 1 << 7 /* last char bite */
+#define HANDLE_SEL_OFFSET (TH_HANDLE_SEL_FREE - TH_HANDLE_FREE)
+
+/* Used as values of `color_id` in `edit_curve_overlay_handle_geom.glsl` */
+enum {
+ COLOR_NURB_ULINE_ID = TH_HANDLE_SEL_AUTOCLAMP - TH_HANDLE_FREE + 1,
+ COLOR_NURB_SEL_ULINE_ID,
+ COLOR_ACTIVE_SPLINE,
+
+ TOT_HANDLE_COL,
+};
+
+/**
+ * TODO
+ * - Ensure `CurveCache`, `SEQUENCER_DAG_WORKAROUND`.
+ * - Check number of verts/edges to see if cache is valid.
+ * - Check if 'overlay.edges' can use single attribyte per edge, not 2 (for selection drawing).
+ */
+
+static void curve_batch_cache_clear(Curve *cu);
+
+/* ---------------------------------------------------------------------- */
+/* Curve Interface, direct access to basic data. */
+
+static void curve_render_overlay_verts_edges_len_get(
+ ListBase *lb, bool hide_handles,
+ int *r_vert_len, int *r_edge_len)
+{
+ BLI_assert(r_vert_len || r_edge_len);
+ int vert_len = 0;
+ int edge_len = 0;
+ for (Nurb *nu = lb->first; nu; nu = nu->next) {
+ if (nu->bezt) {
+ vert_len += hide_handles ? nu->pntsu : (nu->pntsu * 3);
+ /* 2x handles per point*/
+ edge_len += 2 * nu->pntsu;
+ }
+ else if (nu->bp) {
+ vert_len += nu->pntsu;
+ /* segments between points */
+ edge_len += nu->pntsu - 1;
+ }
+ }
+ if (r_vert_len) {
+ *r_vert_len = vert_len;
+ }
+ if (r_edge_len) {
+ *r_edge_len = edge_len;
+ }
+}
+
+static void curve_render_wire_verts_edges_len_get(
+ const CurveCache *ob_curve_cache,
+ int *r_vert_len, int *r_edge_len)
+{
+ BLI_assert(r_vert_len || r_edge_len);
+ int vert_len = 0;
+ int edge_len = 0;
+ for (const BevList *bl = ob_curve_cache->bev.first; bl; bl = bl->next) {
+ if (bl->nr > 0) {
+ const bool is_cyclic = bl->poly != -1;
+
+ /* verts */
+ vert_len += bl->nr;
+
+ /* edges */
+ edge_len += bl->nr;
+ if (!is_cyclic) {
+ edge_len -= 1;
+ }
+ }
+ }
+ if (r_vert_len) {
+ *r_vert_len = vert_len;
+ }
+ if (r_edge_len) {
+ *r_edge_len = edge_len;
+ }
+}
+
+static int curve_render_normal_len_get(const ListBase *lb, const CurveCache *ob_curve_cache)
+{
+ int normal_len = 0;
+ const BevList *bl;
+ const Nurb *nu;
+ for (bl = ob_curve_cache->bev.first, nu = lb->first; nu && bl; bl = bl->next, nu = nu->next) {
+ int nr = bl->nr;
+ int skip = nu->resolu / 16;
+#if 0
+ while (nr-- > 0) { /* accounts for empty bevel lists */
+ normal_len += 1;
+ nr -= skip;
+ }
+#else
+ /* Same as loop above */
+ normal_len += (nr / (skip + 1)) + ((nr % (skip + 1)) != 0);
+#endif
+ }
+ return normal_len;
+}
+
+/* ---------------------------------------------------------------------- */
+/* Curve Interface, indirect, partially cached access to complex data. */
+
+typedef struct CurveRenderData {
+ int types;
+
+ struct {
+ int vert_len;
+ int edge_len;
+ } overlay;
+
+ struct {
+ int vert_len;
+ int edge_len;
+ } wire;
+
+ /* edit mode normal's */
+ struct {
+ /* 'edge_len == len * 2'
+ * 'vert_len == len * 3' */
+ int len;
+ } normal;
+
+ struct {
+ EditFont *edit_font;
+ } text;
+
+ bool hide_handles;
+ bool hide_normals;
+
+ /* borrow from 'Object' */
+ CurveCache *ob_curve_cache;
+
+ /* borrow from 'Curve' */
+ ListBase *nurbs;
+
+ /* edit, index in nurb list */
+ int actnu;
+ /* edit, index in active nurb (BPoint or BezTriple) */
+ int actvert;
+} CurveRenderData;
+
+enum {
+ /* Wire center-line */
+ CU_DATATYPE_WIRE = 1 << 0,
+ /* Edit-mode verts and optionally handles */
+ CU_DATATYPE_OVERLAY = 1 << 1,
+ /* Edit-mode normals */
+ CU_DATATYPE_NORMAL = 1 << 2,
+ /* Geometry */
+ CU_DATATYPE_SURFACE = 1 << 3,
+ /* Text */
+ CU_DATATYPE_TEXT_SELECT = 1 << 4,
+};
+
+/*
+ * ob_curve_cache can be NULL, only needed for CU_DATATYPE_WIRE
+ */
+static CurveRenderData *curve_render_data_create(Curve *cu, CurveCache *ob_curve_cache, const int types)
+{
+ CurveRenderData *rdata = MEM_callocN(sizeof(*rdata), __func__);
+ rdata->types = types;
+ ListBase *nurbs;
+
+ rdata->hide_handles = (cu->drawflag & CU_HIDE_HANDLES) != 0;
+ rdata->hide_normals = (cu->drawflag & CU_HIDE_NORMALS) != 0;
+
+ rdata->actnu = cu->actnu;
+ rdata->actvert = cu->actvert;
+
+ rdata->ob_curve_cache = ob_curve_cache;
+
+ if (types & CU_DATATYPE_WIRE) {
+ curve_render_wire_verts_edges_len_get(
+ rdata->ob_curve_cache,
+ &rdata->wire.vert_len, &rdata->wire.edge_len);
+ }
+
+ if (cu->editnurb) {
+ EditNurb *editnurb = cu->editnurb;
+ nurbs = &editnurb->nurbs;
+
+ if (types & CU_DATATYPE_OVERLAY) {
+ curve_render_overlay_verts_edges_len_get(
+ nurbs, rdata->hide_handles,
+ &rdata->overlay.vert_len,
+ rdata->hide_handles ? NULL : &rdata->overlay.edge_len);
+
+ rdata->actnu = cu->actnu;
+ rdata->actvert = cu->actvert;
+ }
+ if (types & CU_DATATYPE_NORMAL) {
+ rdata->normal.len = curve_render_normal_len_get(nurbs, rdata->ob_curve_cache);
+ }
+ }
+ else {
+ nurbs = &cu->nurb;
+ }
+
+ rdata->nurbs = nurbs;
+
+ rdata->text.edit_font = cu->editfont;
+
+ return rdata;
+}
+
+static void curve_render_data_free(CurveRenderData *rdata)
+{
+#if 0
+ if (rdata->loose_verts) {
+ MEM_freeN(rdata->loose_verts);
+ }
+#endif
+ MEM_freeN(rdata);
+}
+
+static int curve_render_data_overlay_verts_len_get(const CurveRenderData *rdata)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_OVERLAY);
+ return rdata->overlay.vert_len;
+}
+
+static int curve_render_data_overlay_edges_len_get(const CurveRenderData *rdata)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_OVERLAY);
+ return rdata->overlay.edge_len;
+}
+
+static int curve_render_data_wire_verts_len_get(const CurveRenderData *rdata)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_WIRE);
+ return rdata->wire.vert_len;
+}
+
+static int curve_render_data_wire_edges_len_get(const CurveRenderData *rdata)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_WIRE);
+ return rdata->wire.edge_len;
+}
+
+static int curve_render_data_normal_len_get(const CurveRenderData *rdata)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_NORMAL);
+ return rdata->normal.len;
+}
+
+enum {
+ VFLAG_VERTEX_SELECTED = 1 << 0,
+ VFLAG_VERTEX_ACTIVE = 1 << 1,
+};
+
+/* ---------------------------------------------------------------------- */
+/* Curve Gwn_Batch Cache */
+
+typedef struct CurveBatchCache {
+ /* center-line */
+ struct {
+ Gwn_VertBuf *verts;
+ Gwn_VertBuf *edges;
+ Gwn_Batch *batch;
+ Gwn_IndexBuf *elem;
+ } wire;
+
+ /* normals */
+ struct {
+ Gwn_VertBuf *verts;
+ Gwn_VertBuf *edges;
+ Gwn_Batch *batch;
+ Gwn_IndexBuf *elem;
+ } normal;
+
+ /* control handles and vertices */
+ struct {
+ Gwn_Batch *edges;
+ Gwn_Batch *verts;
+ } overlay;
+
+ struct {
+ Gwn_VertBuf *verts;
+ Gwn_IndexBuf *triangles_in_order;
+ Gwn_Batch **shaded_triangles;
+ Gwn_Batch *batch;
+ int mat_len;
+ } surface;
+
+ /* 3d text */
+ struct {
+ Gwn_Batch *select;
+ Gwn_Batch *cursor;
+ } text;
+
+ /* settings to determine if cache is invalid */
+ bool is_dirty;
+
+ bool hide_handles;
+ bool hide_normals;
+
+ float normal_size;
+
+ bool is_editmode;
+} CurveBatchCache;
+
+/* Gwn_Batch cache management. */
+
+static bool curve_batch_cache_valid(Curve *cu)
+{
+ CurveBatchCache *cache = cu->batch_cache;
+
+ if (cache == NULL) {
+ return false;
+ }
+
+ if (cache->is_dirty) {
+ return false;
+ }
+
+ if (cache->is_editmode != ((cu->editnurb != NULL) || (cu->editfont != NULL))) {
+ return false;
+ }
+
+ if (cache->is_editmode) {
+ if (cu->editnurb) {
+ if ((cache->hide_handles != ((cu->drawflag & CU_HIDE_HANDLES) != 0))) {
+ return false;
+ }
+ else if ((cache->hide_normals != ((cu->drawflag & CU_HIDE_NORMALS) != 0))) {
+ return false;
+ }
+ }
+ else if (cu->editfont) {
+ /* TODO */
+ }
+ }
+
+ return true;
+}
+
+static void curve_batch_cache_init(Curve *cu)
+{
+ CurveBatchCache *cache = cu->batch_cache;
+
+ if (!cache) {
+ cache = cu->batch_cache = MEM_callocN(sizeof(*cache), __func__);
+ }
+ else {
+ memset(cache, 0, sizeof(*cache));
+ }
+
+ cache->hide_handles = (cu->drawflag & CU_HIDE_HANDLES) != 0;
+ cache->hide_normals = (cu->drawflag & CU_HIDE_NORMALS) != 0;
+
+#if 0
+ ListBase *nurbs;
+ if (cu->editnurb) {
+ EditNurb *editnurb = cu->editnurb;
+ nurbs = &editnurb->nurbs;
+ }
+ else {
+ nurbs = &cu->nurb;
+ }
+#endif
+
+ cache->is_editmode = (cu->editnurb != NULL) || (cu->editfont != NULL);
+
+ cache->is_dirty = false;
+}
+
+static CurveBatchCache *curve_batch_cache_get(Curve *cu)
+{
+ if (!curve_batch_cache_valid(cu)) {
+ curve_batch_cache_clear(cu);
+ curve_batch_cache_init(cu);
+ }
+ return cu->batch_cache;
+}
+
+void DRW_curve_batch_cache_dirty(Curve *cu, int mode)
+{
+ CurveBatchCache *cache = cu->batch_cache;
+ if (cache == NULL) {
+ return;
+ }
+ switch (mode) {
+ case BKE_CURVE_BATCH_DIRTY_ALL:
+ cache->is_dirty = true;
+ break;
+ case BKE_CURVE_BATCH_DIRTY_SELECT:
+ /* editnurb */
+ GWN_BATCH_DISCARD_SAFE(cache->overlay.verts);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay.edges);
+
+ /* editfont */
+ GWN_BATCH_DISCARD_SAFE(cache->text.select);
+ GWN_BATCH_DISCARD_SAFE(cache->text.cursor);
+ break;
+ default:
+ BLI_assert(0);
+ }
+}
+
+static void curve_batch_cache_clear(Curve *cu)
+{
+ CurveBatchCache *cache = cu->batch_cache;
+ if (!cache) {
+ return;
+ }
+
+ GWN_BATCH_DISCARD_SAFE(cache->overlay.verts);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay.edges);
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->surface.verts);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->surface.triangles_in_order);
+ if (cache->surface.shaded_triangles) {
+ for (int i = 0; i < cache->surface.mat_len; ++i) {
+ GWN_BATCH_DISCARD_SAFE(cache->surface.shaded_triangles[i]);
+ }
+ }
+ MEM_SAFE_FREE(cache->surface.shaded_triangles);
+ GWN_BATCH_DISCARD_SAFE(cache->surface.batch);
+
+ /* don't own vbo & elems */
+ GWN_BATCH_DISCARD_SAFE(cache->wire.batch);
+ GWN_VERTBUF_DISCARD_SAFE(cache->wire.verts);
+ GWN_VERTBUF_DISCARD_SAFE(cache->wire.edges);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->wire.elem);
+
+ /* don't own vbo & elems */
+ GWN_BATCH_DISCARD_SAFE(cache->normal.batch);
+ GWN_VERTBUF_DISCARD_SAFE(cache->normal.verts);
+ GWN_VERTBUF_DISCARD_SAFE(cache->normal.edges);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->normal.elem);
+
+ /* 3d text */
+ GWN_BATCH_DISCARD_SAFE(cache->text.cursor);
+ GWN_BATCH_DISCARD_SAFE(cache->text.select);
+}
+
+void DRW_curve_batch_cache_free(Curve *cu)
+{
+ curve_batch_cache_clear(cu);
+ MEM_SAFE_FREE(cu->batch_cache);
+}
+
+/* -------------------------------------------------------------------- */
+
+/** \name Private Curve Cache API
+ * \{ */
+
+/* Gwn_Batch cache usage. */
+static Gwn_VertBuf *curve_batch_cache_get_wire_verts(CurveRenderData *rdata, CurveBatchCache *cache)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_WIRE);
+ BLI_assert(rdata->ob_curve_cache != NULL);
+
+ if (cache->wire.verts == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ const int vert_len = curve_render_data_wire_verts_len_get(rdata);
+
+ Gwn_VertBuf *vbo = cache->wire.verts = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vert_len);
+ int vbo_len_used = 0;
+ for (const BevList *bl = rdata->ob_curve_cache->bev.first; bl; bl = bl->next) {
+ if (bl->nr > 0) {
+ const int i_end = vbo_len_used + bl->nr;
+ for (const BevPoint *bevp = bl->bevpoints; vbo_len_used < i_end; vbo_len_used++, bevp++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bevp->vec);
+ }
+ }
+ }
+ BLI_assert(vbo_len_used == vert_len);
+ }
+
+ return cache->wire.verts;
+}
+
+static Gwn_IndexBuf *curve_batch_cache_get_wire_edges(CurveRenderData *rdata, CurveBatchCache *cache)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_WIRE);
+ BLI_assert(rdata->ob_curve_cache != NULL);
+
+ if (cache->wire.edges == NULL) {
+ const int vert_len = curve_render_data_wire_verts_len_get(rdata);
+ const int edge_len = curve_render_data_wire_edges_len_get(rdata);
+ int edge_len_used = 0;
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_LINES, edge_len, vert_len);
+
+ int i = 0;
+ for (const BevList *bl = rdata->ob_curve_cache->bev.first; bl; bl = bl->next) {
+ if (bl->nr > 0) {
+ const bool is_cyclic = bl->poly != -1;
+ const int i_end = i + (bl->nr);
+ int i_prev;
+ if (is_cyclic) {
+ i_prev = i + (bl->nr - 1);
+ }
+ else {
+ i_prev = i;
+ i += 1;
+ }
+ for (; i < i_end; i_prev = i++) {
+ GWN_indexbuf_add_line_verts(&elb, i_prev, i);
+ edge_len_used += 1;
+ }
+ }
+ }
+
+ if (rdata->hide_handles) {
+ BLI_assert(edge_len_used <= edge_len);
+ }
+ else {
+ BLI_assert(edge_len_used == edge_len);
+ }
+
+ cache->wire.elem = GWN_indexbuf_build(&elb);
+ }
+
+ return cache->wire.elem;
+}
+
+static Gwn_VertBuf *curve_batch_cache_get_normal_verts(CurveRenderData *rdata, CurveBatchCache *cache)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_NORMAL);
+ BLI_assert(rdata->ob_curve_cache != NULL);
+
+ if (cache->normal.verts == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ const int normal_len = curve_render_data_normal_len_get(rdata);
+ const int vert_len = normal_len * 3;
+
+ Gwn_VertBuf *vbo = cache->normal.verts = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vert_len);
+ int vbo_len_used = 0;
+
+ const BevList *bl;
+ const Nurb *nu;
+
+ for (bl = rdata->ob_curve_cache->bev.first, nu = rdata->nurbs->first;
+ nu && bl;
+ bl = bl->next, nu = nu->next)
+ {
+ const BevPoint *bevp = bl->bevpoints;
+ int nr = bl->nr;
+ int skip = nu->resolu / 16;
+
+ while (nr-- > 0) { /* accounts for empty bevel lists */
+ const float fac = bevp->radius * cache->normal_size;
+ float vec_a[3]; /* Offset perpendicular to the curve */
+ float vec_b[3]; /* Delta along the curve */
+
+ vec_a[0] = fac;
+ vec_a[1] = 0.0f;
+ vec_a[2] = 0.0f;
+
+ mul_qt_v3(bevp->quat, vec_a);
+ madd_v3_v3fl(vec_a, bevp->dir, -fac);
+
+ reflect_v3_v3v3(vec_b, vec_a, bevp->dir);
+ negate_v3(vec_b);
+
+ add_v3_v3(vec_a, bevp->vec);
+ add_v3_v3(vec_b, bevp->vec);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, vec_a);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, bevp->vec);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, vec_b);
+
+ bevp += skip + 1;
+ nr -= skip;
+ }
+ }
+ BLI_assert(vbo_len_used == vert_len);
+ }
+
+ return cache->normal.verts;
+}
+
+static Gwn_IndexBuf *curve_batch_cache_get_normal_edges(CurveRenderData *rdata, CurveBatchCache *cache)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_NORMAL);
+ BLI_assert(rdata->ob_curve_cache != NULL);
+
+ if (cache->normal.edges == NULL) {
+ const int normal_len = curve_render_data_normal_len_get(rdata);
+ const int vert_len = normal_len * 3;
+ const int edge_len = normal_len * 2;
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_LINES, edge_len, vert_len);
+
+ int vbo_len_used = 0;
+ for (int i = 0; i < normal_len; i++) {
+ GWN_indexbuf_add_line_verts(&elb, vbo_len_used + 0, vbo_len_used + 1);
+ GWN_indexbuf_add_line_verts(&elb, vbo_len_used + 1, vbo_len_used + 2);
+ vbo_len_used += 3;
+ }
+
+ BLI_assert(vbo_len_used == vert_len);
+
+ cache->normal.elem = GWN_indexbuf_build(&elb);
+ }
+
+ return cache->normal.elem;
+}
+
+static void curve_batch_cache_create_overlay_batches(Curve *cu)
+{
+ /* Since CU_DATATYPE_OVERLAY is slow to generate, generate them all at once */
+ int options = CU_DATATYPE_OVERLAY;
+
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+ CurveRenderData *rdata = curve_render_data_create(cu, NULL, options);
+
+ if (cache->overlay.verts == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, data; } attr_id;
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.data = GWN_vertformat_attr_add(&format, "data", GWN_COMP_U8, 1, GWN_FETCH_INT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const int vbo_len_capacity = curve_render_data_overlay_verts_len_get(rdata);
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ int i = 0;
+ for (Nurb *nu = rdata->nurbs->first; nu; nu = nu->next) {
+ if (nu->bezt) {
+ int a = 0;
+ for (const BezTriple *bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
+ if (bezt->hide == false) {
+ const bool is_active = (i == rdata->actvert);
+ char vflag;
+
+ if (rdata->hide_handles) {
+ vflag = (bezt->f2 & SELECT) ?
+ (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED) : 0;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[1]);
+ GWN_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
+ vbo_len_used += 1;
+ }
+ else {
+ for (int j = 0; j < 3; j++) {
+ vflag = ((&bezt->f1)[j] & SELECT) ?
+ (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED) : 0;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[j]);
+ GWN_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
+ vbo_len_used += 1;
+ }
+ }
+ }
+ i += 1;
+ }
+ }
+ else if (nu->bp) {
+ int a = 0;
+ for (const BPoint *bp = nu->bp; a < nu->pntsu; a++, bp++) {
+ if (bp->hide == false) {
+ const bool is_active = (i == rdata->actvert);
+ char vflag;
+ vflag = (bp->f1 & SELECT) ? (is_active ? VFLAG_VERTEX_ACTIVE : VFLAG_VERTEX_SELECTED) : 0;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bp->vec);
+ GWN_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &vflag);
+ vbo_len_used += 1;
+ }
+ i += 1;
+ }
+ }
+ i += nu->pntsu;
+ }
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+
+ cache->overlay.verts = GWN_batch_create_ex(GWN_PRIM_POINTS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+
+ if ((cache->overlay.edges == NULL) && (rdata->hide_handles == false)) {
+ /* Note: we could reference indices to vertices (above) */
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, data; } attr_id;
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.data = GWN_vertformat_attr_add(&format, "data", GWN_COMP_U8, 1, GWN_FETCH_INT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const int edge_len = curve_render_data_overlay_edges_len_get(rdata);
+ const int vbo_len_capacity = edge_len * 2;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ int i = 0;
+ for (Nurb *nu = rdata->nurbs->first; nu; nu = nu->next, i++) {
+ const bool is_active_nurb = (i == cu->actnu);
+
+ if (nu->bezt) {
+ int a = 0;
+ for (const BezTriple *bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
+ if (bezt->hide == false) {
+ char col_id;
+
+ for (int j = 0; j < 2; j += 1) {
+ /* same vertex twice, only check different selection */
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[1]);
+ vbo_len_used += 1;
+
+ col_id = (&bezt->h1)[j];
+ if ((&bezt->f1)[j * 2] & SELECT) {
+ col_id += HANDLE_SEL_OFFSET;
+ }
+ if (is_active_nurb) {
+ col_id |= ACTIVE_NURB;
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bezt->vec[j * 2]);
+ GWN_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &col_id);
+ vbo_len_used += 1;
+ }
+ }
+ }
+ }
+ else if (nu->bp) {
+ int a = 1;
+ for (const BPoint *bp_prev = nu->bp, *bp_curr = &nu->bp[1]; a < nu->pntsu; a++, bp_prev = bp_curr++) {
+ if ((bp_prev->hide == false) && (bp_curr->hide == false)) {
+ char col_id = ((bp_prev->f1 & SELECT) && (bp_curr->f1 & SELECT)) ? COLOR_NURB_SEL_ULINE_ID : COLOR_NURB_ULINE_ID;
+
+ if (is_active_nurb) {
+ col_id |= ACTIVE_NURB;
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bp_prev->vec);
+ vbo_len_used += 1;
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, bp_curr->vec);
+ GWN_vertbuf_attr_set(vbo, attr_id.data, vbo_len_used, &col_id);
+ vbo_len_used += 1;
+
+ }
+ }
+ }
+ }
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+
+ cache->overlay.edges = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+ curve_render_data_free(rdata);
+}
+
+static Gwn_Batch *curve_batch_cache_get_pos_and_normals(CurveRenderData *rdata, CurveBatchCache *cache)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_SURFACE);
+ if (cache->surface.batch == NULL) {
+ ListBase *lb = &rdata->ob_curve_cache->disp;
+
+ if (cache->surface.verts == NULL) {
+ cache->surface.verts = DRW_displist_vertbuf_calc_pos_with_normals(lb);
+ }
+ if (cache->surface.triangles_in_order == NULL) {
+ cache->surface.triangles_in_order = DRW_displist_indexbuf_calc_triangles_in_order(lb);
+ }
+ cache->surface.batch = GWN_batch_create(
+ GWN_PRIM_TRIS, cache->surface.verts, cache->surface.triangles_in_order);
+ }
+
+ return cache->surface.batch;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Private Object/Font Cache API
+ * \{ */
+
+
+static Gwn_Batch *curve_batch_cache_get_overlay_select(CurveRenderData *rdata, CurveBatchCache *cache)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_TEXT_SELECT);
+ if (cache->text.select == NULL) {
+ EditFont *ef = rdata->text.edit_font;
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const int vbo_len_capacity = ef->selboxes_len * 6;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ float box[4][3];
+
+ /* fill in xy below */
+ box[0][2] = box[1][2] = box[2][2] = box[3][2] = 0.001;
+
+ for (int i = 0; i < ef->selboxes_len; i++) {
+ EditFontSelBox *sb = &ef->selboxes[i];
+
+ float selboxw;
+ if (i + 1 != ef->selboxes_len) {
+ if (ef->selboxes[i + 1].y == sb->y)
+ selboxw = ef->selboxes[i + 1].x - sb->x;
+ else
+ selboxw = sb->w;
+ }
+ else {
+ selboxw = sb->w;
+ }
+
+ if (sb->rot == 0.0f) {
+ copy_v2_fl2(box[0], sb->x, sb->y);
+ copy_v2_fl2(box[1], sb->x + selboxw, sb->y);
+ copy_v2_fl2(box[2], sb->x + selboxw, sb->y + sb->h);
+ copy_v2_fl2(box[3], sb->x, sb->y + sb->h);
+ }
+ else {
+ float mat[2][2];
+
+ angle_to_mat2(mat, sb->rot);
+
+ copy_v2_fl2(box[0], sb->x, sb->y);
+
+ copy_v2_fl2(box[1], selboxw, 0.0f);
+ mul_m2v2(mat, box[1]);
+ add_v2_v2(box[1], &sb->x);
+
+ copy_v2_fl2(box[2], selboxw, sb->h);
+ mul_m2v2(mat, box[2]);
+ add_v2_v2(box[2], &sb->x);
+
+ copy_v2_fl2(box[3], 0.0f, sb->h);
+ mul_m2v2(mat, box[3]);
+ add_v2_v2(box[3], &sb->x);
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, box[0]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, box[1]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, box[2]);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, box[0]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, box[2]);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used++, box[3]);
+ }
+ BLI_assert(vbo_len_used == vbo_len_capacity);
+ cache->text.select = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return cache->text.select;
+}
+
+static Gwn_Batch *curve_batch_cache_get_overlay_cursor(CurveRenderData *rdata, CurveBatchCache *cache)
+{
+ BLI_assert(rdata->types & CU_DATATYPE_TEXT_SELECT);
+ if (cache->text.cursor == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const int vbo_len_capacity = 4;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ for (int i = 0; i < 4; i++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i, rdata->text.edit_font->textcurs[i]);
+ }
+ cache->text.cursor = GWN_batch_create_ex(GWN_PRIM_TRI_FAN, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ return cache->text.cursor;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Public Object/Curve API
+ * \{ */
+
+Gwn_Batch *DRW_curve_batch_cache_get_wire_edge(Curve *cu, CurveCache *ob_curve_cache)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->wire.batch == NULL) {
+ /* create batch from Curve */
+ CurveRenderData *rdata = curve_render_data_create(cu, ob_curve_cache, CU_DATATYPE_WIRE);
+
+ cache->wire.batch = GWN_batch_create(
+ GWN_PRIM_LINES,
+ curve_batch_cache_get_wire_verts(rdata, cache),
+ curve_batch_cache_get_wire_edges(rdata, cache));
+
+ curve_render_data_free(rdata);
+ }
+ return cache->wire.batch;
+}
+
+Gwn_Batch *DRW_curve_batch_cache_get_normal_edge(Curve *cu, CurveCache *ob_curve_cache, float normal_size)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->normal.batch != NULL) {
+ cache->normal_size = normal_size;
+ if (cache->normal_size != normal_size) {
+ GWN_BATCH_DISCARD_SAFE(cache->normal.batch);
+ GWN_VERTBUF_DISCARD_SAFE(cache->normal.edges);
+ }
+ }
+ cache->normal_size = normal_size;
+
+ if (cache->normal.batch == NULL) {
+ /* create batch from Curve */
+ CurveRenderData *rdata = curve_render_data_create(cu, ob_curve_cache, CU_DATATYPE_NORMAL);
+
+ cache->normal.batch = GWN_batch_create(
+ GWN_PRIM_LINES,
+ curve_batch_cache_get_normal_verts(rdata, cache),
+ curve_batch_cache_get_normal_edges(rdata, cache));
+
+ curve_render_data_free(rdata);
+ cache->normal_size = normal_size;
+ }
+ return cache->normal.batch;
+}
+
+Gwn_Batch *DRW_curve_batch_cache_get_overlay_edges(Curve *cu)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->overlay.edges == NULL) {
+ curve_batch_cache_create_overlay_batches(cu);
+ }
+
+ return cache->overlay.edges;
+}
+
+Gwn_Batch *DRW_curve_batch_cache_get_overlay_verts(Curve *cu)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->overlay.verts == NULL) {
+ curve_batch_cache_create_overlay_batches(cu);
+ }
+
+ return cache->overlay.verts;
+}
+
+Gwn_Batch *DRW_curve_batch_cache_get_triangles_with_normals(
+ struct Curve *cu, struct CurveCache *ob_curve_cache)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->surface.batch == NULL) {
+ CurveRenderData *rdata = curve_render_data_create(cu, ob_curve_cache, CU_DATATYPE_SURFACE);
+
+ curve_batch_cache_get_pos_and_normals(rdata, cache);
+
+ curve_render_data_free(rdata);
+ }
+
+ return cache->surface.batch;
+}
+
+Gwn_Batch **DRW_curve_batch_cache_get_surface_shaded(
+ struct Curve *cu, struct CurveCache *ob_curve_cache,
+ struct GPUMaterial **UNUSED(gpumat_array), uint gpumat_array_len)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->surface.mat_len != gpumat_array_len) {
+ /* TODO: deduplicate code */
+ if (cache->surface.shaded_triangles) {
+ for (int i = 0; i < cache->surface.mat_len; ++i) {
+ GWN_BATCH_DISCARD_SAFE(cache->surface.shaded_triangles[i]);
+ }
+ }
+ MEM_SAFE_FREE(cache->surface.shaded_triangles);
+ }
+
+ if (cache->surface.shaded_triangles == NULL) {
+ CurveRenderData *rdata = curve_render_data_create(cu, ob_curve_cache, CU_DATATYPE_SURFACE);
+ ListBase *lb = &rdata->ob_curve_cache->disp;
+
+ cache->surface.mat_len = gpumat_array_len;
+ if (cu->flag & CU_UV_ORCO) {
+ cache->surface.shaded_triangles = DRW_displist_batch_calc_tri_pos_normals_and_uv_split_by_material(
+ lb, gpumat_array_len);
+ }
+ else {
+ cache->surface.shaded_triangles = MEM_mallocN(
+ sizeof(*cache->surface.shaded_triangles) * gpumat_array_len, __func__);
+ Gwn_IndexBuf **el = DRW_displist_indexbuf_calc_triangles_in_order_split_by_material(
+ lb, gpumat_array_len);
+
+ if (cache->surface.verts == NULL) {
+ cache->surface.verts = DRW_displist_vertbuf_calc_pos_with_normals(lb);
+ }
+
+ for (int i = 0; i < gpumat_array_len; ++i) {
+ cache->surface.shaded_triangles[i] = GWN_batch_create_ex(
+ GWN_PRIM_TRIS, cache->surface.verts, el[i], GWN_BATCH_OWNS_INDEX);
+ }
+
+ MEM_freeN(el); /* Save `el` in cache? */
+ }
+
+ curve_render_data_free(rdata);
+ }
+
+ return cache->surface.shaded_triangles;
+}
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Public Object/Font API
+ * \{ */
+
+Gwn_Batch *DRW_curve_batch_cache_get_overlay_select(Curve *cu)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->text.select == NULL) {
+ CurveRenderData *rdata = curve_render_data_create(cu, NULL, CU_DATATYPE_TEXT_SELECT);
+
+ curve_batch_cache_get_overlay_select(rdata, cache);
+
+ curve_render_data_free(rdata);
+ }
+
+ return cache->text.select;
+}
+
+Gwn_Batch *DRW_curve_batch_cache_get_overlay_cursor(Curve *cu)
+{
+ CurveBatchCache *cache = curve_batch_cache_get(cu);
+
+ if (cache->text.cursor == NULL) {
+ CurveRenderData *rdata = curve_render_data_create(cu, NULL, CU_DATATYPE_TEXT_SELECT);
+
+ curve_batch_cache_get_overlay_cursor(rdata, cache);
+
+ curve_render_data_free(rdata);
+ }
+
+ return cache->text.cursor;
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/draw_cache_impl_displist.c b/source/blender/draw/intern/draw_cache_impl_displist.c
new file mode 100644
index 00000000000..627fb38d9d6
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_displist.c
@@ -0,0 +1,398 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file draw_cache_impl_displist.c
+ * \ingroup draw
+ *
+ * \brief DispList API for render engines
+ *
+ * \note DispList may be removed soon! This is a utility for object types that use render.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_alloca.h"
+#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+
+#include "DNA_curve_types.h"
+
+#include "BKE_displist.h"
+
+#include "GPU_batch.h"
+
+#include "draw_cache_impl.h" /* own include */
+
+static int dl_vert_len(const DispList *dl)
+{
+ switch (dl->type) {
+ case DL_INDEX3:
+ case DL_INDEX4:
+ return dl->nr;
+ case DL_SURF:
+ return dl->parts * dl->nr;
+ }
+ return 0;
+}
+
+static int dl_tri_len(const DispList *dl)
+{
+ switch (dl->type) {
+ case DL_INDEX3:
+ return dl->parts;
+ case DL_INDEX4:
+ return dl->parts * 2;
+ case DL_SURF:
+ return dl->totindex * 2;
+ }
+ return 0;
+}
+
+/* see: displist_get_allverts */
+static int curve_render_surface_vert_len_get(const ListBase *lb)
+{
+ int vert_len = 0;
+ for (const DispList *dl = lb->first; dl; dl = dl->next) {
+ vert_len += dl_vert_len(dl);
+ }
+ return vert_len;
+}
+
+static int curve_render_surface_tri_len_get(const ListBase *lb)
+{
+ int tri_len = 0;
+ for (const DispList *dl = lb->first; dl; dl = dl->next) {
+ tri_len += dl_tri_len(dl);
+ }
+ return tri_len;
+}
+
+static void displist_indexbufbuilder_set(Gwn_IndexBufBuilder *elb, const DispList *dl, const int ofs)
+{
+ if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
+ const int *idx = dl->index;
+ if (dl->type == DL_INDEX3) {
+ const int i_end = dl->parts;
+ for (int i = 0; i < i_end; i++, idx += 3) {
+ GWN_indexbuf_add_tri_verts(elb, idx[0] + ofs, idx[2] + ofs, idx[1] + ofs);
+ }
+ }
+ else if (dl->type == DL_SURF) {
+ const int i_end = dl->totindex;
+ for (int i = 0; i < i_end; i++, idx += 4) {
+ GWN_indexbuf_add_tri_verts(elb, idx[0] + ofs, idx[2] + ofs, idx[1] + ofs);
+ GWN_indexbuf_add_tri_verts(elb, idx[0] + ofs, idx[3] + ofs, idx[2] + ofs);
+ }
+ }
+ else {
+ BLI_assert(dl->type == DL_INDEX4);
+ const int i_end = dl->parts;
+ for (int i = 0; i < i_end; i++, idx += 4) {
+ GWN_indexbuf_add_tri_verts(elb, idx[0] + ofs, idx[1] + ofs, idx[2] + ofs);
+
+ if (idx[2] != idx[3]) {
+ GWN_indexbuf_add_tri_verts(elb, idx[0] + ofs, idx[2] + ofs, idx[3] + ofs);
+ }
+ }
+ }
+ }
+}
+
+Gwn_VertBuf *DRW_displist_vertbuf_calc_pos_with_normals(ListBase *lb)
+{
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, nor; } attr_id;
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, curve_render_surface_vert_len_get(lb));
+
+ BKE_displist_normals_add(lb);
+
+ int vbo_len_used = 0;
+ for (const DispList *dl = lb->first; dl; dl = dl->next) {
+ const bool ndata_is_single = dl->type == DL_INDEX3;
+ if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
+ const float *fp_co = dl->verts;
+ const float *fp_no = dl->nors;
+ const int vbo_end = vbo_len_used + dl_vert_len(dl);
+ while (vbo_len_used < vbo_end) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vbo_len_used, fp_co);
+ if (fp_no) {
+ GWN_vertbuf_attr_set(vbo, attr_id.nor, vbo_len_used, fp_no);
+ if (ndata_is_single == false) {
+ fp_no += 3;
+ }
+ }
+ fp_co += 3;
+ vbo_len_used += 1;
+ }
+ }
+ }
+
+ return vbo;
+}
+
+Gwn_IndexBuf *DRW_displist_indexbuf_calc_triangles_in_order(ListBase *lb)
+{
+ const int tri_len = curve_render_surface_tri_len_get(lb);
+ const int vert_len = curve_render_surface_vert_len_get(lb);
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tri_len, vert_len);
+
+ int ofs = 0;
+ for (const DispList *dl = lb->first; dl; dl = dl->next) {
+ displist_indexbufbuilder_set(&elb, dl, ofs);
+ ofs += dl_vert_len(dl);
+ }
+
+ return GWN_indexbuf_build(&elb);
+}
+
+Gwn_IndexBuf **DRW_displist_indexbuf_calc_triangles_in_order_split_by_material(ListBase *lb, uint gpumat_array_len)
+{
+ Gwn_IndexBuf **shaded_triangles_in_order = MEM_callocN(sizeof(*shaded_triangles_in_order) * gpumat_array_len, __func__);
+ Gwn_IndexBufBuilder *elb = BLI_array_alloca(elb, gpumat_array_len);
+
+ const int tri_len = curve_render_surface_tri_len_get(lb);
+ const int vert_len = curve_render_surface_vert_len_get(lb);
+ int i;
+
+ /* Init each index buffer builder */
+ for (i = 0; i < gpumat_array_len; i++) {
+ GWN_indexbuf_init(&elb[i], GWN_PRIM_TRIS, tri_len, vert_len);
+ }
+
+ /* calc each index buffer builder */
+ int ofs = 0;
+ for (const DispList *dl = lb->first; dl; dl = dl->next) {
+ displist_indexbufbuilder_set(&elb[dl->col], dl, ofs);
+ ofs += dl_vert_len(dl);
+ }
+
+ /* build each indexbuf */
+ for (i = 0; i < gpumat_array_len; i++) {
+ shaded_triangles_in_order[i] = GWN_indexbuf_build(&elb[i]);
+ }
+
+ return shaded_triangles_in_order;
+}
+
+static void displist_vertbuf_attr_set_tri_pos_normals_and_uv(
+ Gwn_VertBufRaw *pos_step, Gwn_VertBufRaw *nor_step, Gwn_VertBufRaw *uv_step,
+ const float v1[3], const float v2[3], const float v3[3],
+ const float n1[3], const float n2[3], const float n3[3],
+ const float uv1[2], const float uv2[2], const float uv3[2])
+{
+ copy_v3_v3(GWN_vertbuf_raw_step(pos_step), v1);
+ copy_v3_v3(GWN_vertbuf_raw_step(nor_step), n1);
+ copy_v2_v2(GWN_vertbuf_raw_step(uv_step), uv1);
+
+ copy_v3_v3(GWN_vertbuf_raw_step(pos_step), v2);
+ copy_v3_v3(GWN_vertbuf_raw_step(nor_step), n2);
+ copy_v2_v2(GWN_vertbuf_raw_step(uv_step), uv2);
+
+ copy_v3_v3(GWN_vertbuf_raw_step(pos_step), v3);
+ copy_v3_v3(GWN_vertbuf_raw_step(nor_step), n3);
+ copy_v2_v2(GWN_vertbuf_raw_step(uv_step), uv3);
+}
+
+Gwn_Batch **DRW_displist_batch_calc_tri_pos_normals_and_uv_split_by_material(ListBase *lb, uint gpumat_array_len)
+{
+ static Gwn_VertFormat shaded_triangles_format = { 0 };
+ static struct { uint pos, nor, uv; } attr_id;
+
+ if (shaded_triangles_format.attrib_ct == 0) {
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&shaded_triangles_format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.nor = GWN_vertformat_attr_add(&shaded_triangles_format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.uv = GWN_vertformat_attr_add(&shaded_triangles_format, "u", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_Batch **shaded_triangles = MEM_mallocN(sizeof(*shaded_triangles) * gpumat_array_len, __func__);
+
+ Gwn_VertBuf **vbo = BLI_array_alloca(vbo, gpumat_array_len);
+ uint *vbo_len_capacity = BLI_array_alloca(vbo_len_capacity, gpumat_array_len);
+
+ Gwn_VertBufRaw *pos_step, *nor_step, *uv_step;
+ pos_step = BLI_array_alloca(pos_step, gpumat_array_len);
+ nor_step = BLI_array_alloca(nor_step, gpumat_array_len);
+ uv_step = BLI_array_alloca(uv_step, gpumat_array_len);
+
+ /* Create each vertex buffer */
+ for (int i = 0; i < gpumat_array_len; i++) {
+ vbo[i] = GWN_vertbuf_create_with_format(&shaded_triangles_format);
+ vbo_len_capacity[i] = 0;
+ }
+
+ /* Calc `vbo_len_capacity` */
+ for (const DispList *dl = lb->first; dl; dl = dl->next) {
+ vbo_len_capacity[dl->col] += dl_tri_len(dl) * 3;
+ }
+
+ /* Alloc each vertex buffer and get each raw data */
+ for (int i = 0; i < gpumat_array_len; i++) {
+ GWN_vertbuf_data_alloc(vbo[i], vbo_len_capacity[i]);
+ GWN_vertbuf_attr_get_raw_data(vbo[i], attr_id.pos, &pos_step[i]);
+ GWN_vertbuf_attr_get_raw_data(vbo[i], attr_id.nor, &nor_step[i]);
+ GWN_vertbuf_attr_get_raw_data(vbo[i], attr_id.uv, &uv_step[i]);
+ }
+
+ BKE_displist_normals_add(lb);
+
+ for (const DispList *dl = lb->first; dl; dl = dl->next) {
+ if (ELEM(dl->type, DL_INDEX3, DL_INDEX4, DL_SURF)) {
+ const int col = dl->col;
+ const float(*verts)[3] = (float(*)[3])dl->verts;
+ const float(*nors)[3] = (float(*)[3])dl->nors;
+ const int *idx = dl->index;
+ float uv[4][2];
+
+ if (dl->type == DL_INDEX3) {
+ const float x_max = (float)(dl->nr - 1);
+ uv[0][1] = uv[1][1] = uv[2][1] = 0.0f;
+ const int i_end = dl->parts;
+ for (int i = 0; i < i_end; i++, idx += 3) {
+ uv[0][0] = idx[0] / x_max;
+ uv[1][0] = idx[2] / x_max;
+ uv[2][0] = idx[1] / x_max;
+
+ displist_vertbuf_attr_set_tri_pos_normals_and_uv(
+ &pos_step[col], &nor_step[col], &uv_step[col],
+ verts[idx[0]], verts[idx[2]], verts[idx[1]],
+ nors[idx[0]], nors[idx[2]], nors[idx[1]],
+ uv[0], uv[1], uv[2]);
+ }
+ }
+ else if (dl->type == DL_SURF) {
+ uint quad[4];
+ for (int a = 0; a < dl->parts; a++) {
+ if ((dl->flag & DL_CYCL_V) == 0 && a == dl->parts - 1) {
+ break;
+ }
+
+ int b;
+ if (dl->flag & DL_CYCL_U) {
+ quad[0] = dl->nr * a;
+ quad[3] = quad[0] + dl->nr - 1;
+ quad[1] = quad[0] + dl->nr;
+ quad[2] = quad[3] + dl->nr;
+ b = 0;
+ }
+ else {
+ quad[3] = dl->nr * a;
+ quad[0] = quad[3] + 1;
+ quad[2] = quad[3] + dl->nr;
+ quad[1] = quad[0] + dl->nr;
+ b = 1;
+ }
+ if ((dl->flag & DL_CYCL_V) && a == dl->parts - 1) {
+ quad[1] -= dl->parts * dl->nr;
+ quad[2] -= dl->parts * dl->nr;
+ }
+
+ for (; b < dl->nr; b++) {
+ int orco_sizeu = dl->nr - 1;
+ int orco_sizev = dl->parts - 1;
+
+ /* exception as handled in convertblender.c too */
+ if (dl->flag & DL_CYCL_U) {
+ orco_sizeu++;
+ }
+ if (dl->flag & DL_CYCL_V) {
+ orco_sizev++;
+ }
+
+ for (int i = 0; i < 4; i++) {
+ /* find uv based on vertex index into grid array */
+ uv[i][0] = (quad[i] / dl->nr) / (float)orco_sizev;
+ uv[i][1] = (quad[i] % dl->nr) / (float)orco_sizeu;
+
+ /* cyclic correction */
+ if ((i == 1 || i == 2) && uv[i][0] == 0.0f) {
+ uv[i][0] = 1.0f;
+ }
+ if ((i == 0 || i == 1) && uv[i][1] == 0.0f) {
+ uv[i][1] = 1.0f;
+ }
+ }
+
+ displist_vertbuf_attr_set_tri_pos_normals_and_uv(
+ &pos_step[col], &nor_step[col], &uv_step[col],
+ verts[quad[0]], verts[quad[1]], verts[quad[2]],
+ nors[quad[0]], nors[quad[1]], nors[quad[2]],
+ uv[0], uv[1], uv[2]);
+
+ displist_vertbuf_attr_set_tri_pos_normals_and_uv(
+ &pos_step[col], &nor_step[col], &uv_step[col],
+ verts[quad[0]], verts[quad[2]], verts[quad[3]],
+ nors[quad[0]], nors[quad[2]], nors[quad[3]],
+ uv[0], uv[2], uv[3]);
+
+ quad[2] = quad[1];
+ quad[1]++;
+ quad[3] = quad[0];
+ quad[0]++;
+ }
+ }
+ }
+ else {
+ BLI_assert(dl->type == DL_INDEX4);
+ uv[0][0] = uv[0][1] = uv[1][0] = uv[3][1] = 0.0f;
+ uv[1][1] = uv[2][0] = uv[2][1] = uv[3][0] = 1.0f;
+
+ const int i_end = dl->parts;
+ for (int i = 0; i < i_end; i++, idx += 4) {
+ displist_vertbuf_attr_set_tri_pos_normals_and_uv(
+ &pos_step[col], &nor_step[col], &uv_step[col],
+ verts[idx[0]], verts[idx[1]], verts[idx[2]],
+ nors[idx[0]], nors[idx[1]], nors[idx[2]],
+ uv[0], uv[1], uv[2]);
+
+ if (idx[2] != idx[3]) {
+ displist_vertbuf_attr_set_tri_pos_normals_and_uv(
+ &pos_step[col], &nor_step[col], &uv_step[col],
+ verts[idx[0]], verts[idx[2]], verts[idx[3]],
+ nors[idx[0]], nors[idx[2]], nors[idx[3]],
+ uv[0], uv[2], uv[3]);
+ }
+ }
+ }
+ }
+ }
+
+ for (int i = 0; i < gpumat_array_len; i++) {
+ uint vbo_len_used = GWN_vertbuf_raw_used(&pos_step[i]);
+ if (vbo_len_capacity[i] != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo[i], vbo_len_used);
+ }
+ shaded_triangles[i] = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo[i], NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+ return shaded_triangles;
+}
diff --git a/source/blender/draw/intern/draw_cache_impl_lattice.c b/source/blender/draw/intern/draw_cache_impl_lattice.c
new file mode 100644
index 00000000000..1cb55039b16
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_lattice.c
@@ -0,0 +1,587 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, Mike Erwin, Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file draw_cache_impl_lattice.c
+ * \ingroup draw
+ *
+ * \brief Lattice API for render engines
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_userdef_types.h"
+
+#include "BKE_lattice.h"
+#include "BKE_deform.h"
+#include "BKE_colorband.h"
+
+#include "GPU_batch.h"
+
+#include "draw_cache_impl.h" /* own include */
+
+#define SELECT 1
+
+/**
+ * TODO
+ * - 'DispList' is currently not used
+ * (we could avoid using since it will be removed)
+ */
+
+static void lattice_batch_cache_clear(Lattice *lt);
+
+/* ---------------------------------------------------------------------- */
+/* Lattice Interface, direct access to basic data. */
+
+static int vert_len_calc(int u, int v, int w)
+{
+ if (u <= 0 || v <= 0 || w <= 0) {
+ return 0;
+ }
+ return u * v * w;
+}
+
+static int edge_len_calc(int u, int v, int w)
+{
+ if (u <= 0 || v <= 0 || w <= 0) {
+ return 0;
+ }
+ return (((((u - 1) * v) +
+ ((v - 1) * u)) * w) +
+ ((w - 1) * (u * v)));
+}
+
+static int lattice_render_verts_len_get(Lattice *lt)
+{
+ if (lt->editlatt) {
+ lt = lt->editlatt->latt;
+ }
+
+ const int u = lt->pntsu;
+ const int v = lt->pntsv;
+ const int w = lt->pntsw;
+
+ if ((lt->flag & LT_OUTSIDE) == 0) {
+ return vert_len_calc(u, v, w);
+ }
+ else {
+ /* TODO remove internal coords */
+ return vert_len_calc(u, v, w);
+ }
+}
+
+static int lattice_render_edges_len_get(Lattice *lt)
+{
+ if (lt->editlatt) {
+ lt = lt->editlatt->latt;
+ }
+
+ const int u = lt->pntsu;
+ const int v = lt->pntsv;
+ const int w = lt->pntsw;
+
+ if ((lt->flag & LT_OUTSIDE) == 0) {
+ return edge_len_calc(u, v, w);
+ }
+ else {
+ /* TODO remove internal coords */
+ return edge_len_calc(u, v, w);
+ }
+}
+
+/* ---------------------------------------------------------------------- */
+/* Lattice Interface, indirect, partially cached access to complex data. */
+
+typedef struct LatticeRenderData {
+ int types;
+
+ int vert_len;
+ int edge_len;
+
+ struct {
+ int u_len, v_len, w_len;
+ } dims;
+ bool show_only_outside;
+
+ struct EditLatt *edit_latt;
+ BPoint *bp;
+
+ int actbp;
+
+ struct MDeformVert *dvert;
+} LatticeRenderData;
+
+enum {
+ LR_DATATYPE_VERT = 1 << 0,
+ LR_DATATYPE_EDGE = 1 << 1,
+ LR_DATATYPE_OVERLAY = 1 << 2,
+};
+
+static LatticeRenderData *lattice_render_data_create(Lattice *lt, const int types)
+{
+ LatticeRenderData *rdata = MEM_callocN(sizeof(*rdata), __func__);
+ rdata->types = types;
+
+ if (lt->editlatt) {
+ EditLatt *editlatt = lt->editlatt;
+ lt = editlatt->latt;
+
+ rdata->edit_latt = editlatt;
+
+ rdata->dvert = lt->dvert;
+
+ if (types & (LR_DATATYPE_VERT)) {
+ rdata->vert_len = lattice_render_verts_len_get(lt);
+ }
+ if (types & (LR_DATATYPE_EDGE)) {
+ rdata->edge_len = lattice_render_edges_len_get(lt);
+ }
+ if (types & LR_DATATYPE_OVERLAY) {
+ rdata->actbp = lt->actbp;
+ }
+ }
+ else {
+ rdata->dvert = NULL;
+
+ if (types & (LR_DATATYPE_VERT)) {
+ rdata->vert_len = lattice_render_verts_len_get(lt);
+ }
+ if (types & (LR_DATATYPE_EDGE)) {
+ rdata->edge_len = lattice_render_edges_len_get(lt);
+ /*no edge data */
+ }
+ }
+
+ rdata->bp = lt->def;
+
+ rdata->dims.u_len = lt->pntsu;
+ rdata->dims.v_len = lt->pntsv;
+ rdata->dims.w_len = lt->pntsw;
+
+ rdata->show_only_outside = (lt->flag & LT_OUTSIDE) != 0;
+ rdata->actbp = lt->actbp;
+
+ return rdata;
+}
+
+static void lattice_render_data_free(LatticeRenderData *rdata)
+{
+#if 0
+ if (rdata->loose_verts) {
+ MEM_freeN(rdata->loose_verts);
+ }
+#endif
+ MEM_freeN(rdata);
+}
+
+static int lattice_render_data_verts_len_get(const LatticeRenderData *rdata)
+{
+ BLI_assert(rdata->types & LR_DATATYPE_VERT);
+ return rdata->vert_len;
+}
+
+static int lattice_render_data_edges_len_get(const LatticeRenderData *rdata)
+{
+ BLI_assert(rdata->types & LR_DATATYPE_EDGE);
+ return rdata->edge_len;
+}
+
+static const BPoint *lattice_render_data_vert_bpoint(const LatticeRenderData *rdata, const int vert_idx)
+{
+ BLI_assert(rdata->types & LR_DATATYPE_VERT);
+ return &rdata->bp[vert_idx];
+}
+
+/* TODO, move into shader? */
+static void rgb_from_weight(float r_rgb[3], const float weight)
+{
+ const float blend = ((weight / 2.0f) + 0.5f);
+
+ if (weight <= 0.25f) { /* blue->cyan */
+ r_rgb[0] = 0.0f;
+ r_rgb[1] = blend * weight * 4.0f;
+ r_rgb[2] = blend;
+ }
+ else if (weight <= 0.50f) { /* cyan->green */
+ r_rgb[0] = 0.0f;
+ r_rgb[1] = blend;
+ r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f));
+ }
+ else if (weight <= 0.75f) { /* green->yellow */
+ r_rgb[0] = blend * ((weight - 0.50f) * 4.0f);
+ r_rgb[1] = blend;
+ r_rgb[2] = 0.0f;
+ }
+ else if (weight <= 1.0f) { /* yellow->red */
+ r_rgb[0] = blend;
+ r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f));
+ r_rgb[2] = 0.0f;
+ }
+ else {
+ /* exceptional value, unclamped or nan,
+ * avoid uninitialized memory use */
+ r_rgb[0] = 1.0f;
+ r_rgb[1] = 0.0f;
+ r_rgb[2] = 1.0f;
+ }
+}
+
+static void lattice_render_data_weight_col_get(const LatticeRenderData *rdata, const int vert_idx,
+ const int actdef, float r_col[4])
+{
+ if (actdef > -1) {
+ float weight = defvert_find_weight(rdata->dvert + vert_idx, actdef);
+
+ if (U.flag & USER_CUSTOM_RANGE) {
+ BKE_colorband_evaluate(&U.coba_weight, weight, r_col);
+ }
+ else {
+ rgb_from_weight(r_col, weight);
+ }
+
+ r_col[3] = 1.0f;
+ }
+ else {
+ zero_v4(r_col);
+ }
+}
+
+enum {
+ VFLAG_VERTEX_SELECTED = 1 << 0,
+ VFLAG_VERTEX_ACTIVE = 1 << 1,
+};
+
+/* ---------------------------------------------------------------------- */
+/* Lattice Gwn_Batch Cache */
+
+typedef struct LatticeBatchCache {
+ Gwn_VertBuf *pos;
+ Gwn_IndexBuf *edges;
+
+ Gwn_Batch *all_verts;
+ Gwn_Batch *all_edges;
+
+ Gwn_Batch *overlay_verts;
+
+ /* settings to determine if cache is invalid */
+ bool is_dirty;
+
+ struct {
+ int u_len, v_len, w_len;
+ } dims;
+ bool show_only_outside;
+
+ bool is_editmode;
+} LatticeBatchCache;
+
+/* Gwn_Batch cache management. */
+
+static bool lattice_batch_cache_valid(Lattice *lt)
+{
+ LatticeBatchCache *cache = lt->batch_cache;
+
+ if (cache == NULL) {
+ return false;
+ }
+
+ if (cache->is_editmode != (lt->editlatt != NULL)) {
+ return false;
+ }
+
+ if (cache->is_dirty == false) {
+ return true;
+ }
+ else {
+ if (cache->is_editmode) {
+ return false;
+ }
+ else if ((cache->dims.u_len != lt->pntsu) ||
+ (cache->dims.v_len != lt->pntsv) ||
+ (cache->dims.w_len != lt->pntsw) ||
+ ((cache->show_only_outside != ((lt->flag & LT_OUTSIDE) != 0))))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static void lattice_batch_cache_init(Lattice *lt)
+{
+ LatticeBatchCache *cache = lt->batch_cache;
+
+ if (!cache) {
+ cache = lt->batch_cache = MEM_callocN(sizeof(*cache), __func__);
+ }
+ else {
+ memset(cache, 0, sizeof(*cache));
+ }
+
+ cache->dims.u_len = lt->pntsu;
+ cache->dims.v_len = lt->pntsv;
+ cache->dims.w_len = lt->pntsw;
+ cache->show_only_outside = (lt->flag & LT_OUTSIDE) != 0;
+
+ cache->is_editmode = lt->editlatt != NULL;
+
+ cache->is_dirty = false;
+}
+
+static LatticeBatchCache *lattice_batch_cache_get(Lattice *lt)
+{
+ if (!lattice_batch_cache_valid(lt)) {
+ lattice_batch_cache_clear(lt);
+ lattice_batch_cache_init(lt);
+ }
+ return lt->batch_cache;
+}
+
+void DRW_lattice_batch_cache_dirty(Lattice *lt, int mode)
+{
+ LatticeBatchCache *cache = lt->batch_cache;
+ if (cache == NULL) {
+ return;
+ }
+ switch (mode) {
+ case BKE_LATTICE_BATCH_DIRTY_ALL:
+ cache->is_dirty = true;
+ break;
+ case BKE_LATTICE_BATCH_DIRTY_SELECT:
+ /* TODO Separate Flag vbo */
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_verts);
+ break;
+ default:
+ BLI_assert(0);
+ }
+}
+
+static void lattice_batch_cache_clear(Lattice *lt)
+{
+ LatticeBatchCache *cache = lt->batch_cache;
+ if (!cache) {
+ return;
+ }
+
+ GWN_BATCH_DISCARD_SAFE(cache->all_verts);
+ GWN_BATCH_DISCARD_SAFE(cache->all_edges);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_verts);
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->pos);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->edges);
+}
+
+void DRW_lattice_batch_cache_free(Lattice *lt)
+{
+ lattice_batch_cache_clear(lt);
+ MEM_SAFE_FREE(lt->batch_cache);
+}
+
+/* Gwn_Batch cache usage. */
+static Gwn_VertBuf *lattice_batch_cache_get_pos(LatticeRenderData *rdata, LatticeBatchCache *cache,
+ bool use_weight, const int actdef)
+{
+ BLI_assert(rdata->types & LR_DATATYPE_VERT);
+
+ if (cache->pos == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, col; } attr_id;
+
+ GWN_vertformat_clear(&format);
+
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ if (use_weight) {
+ attr_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ }
+
+ const int vert_len = lattice_render_data_verts_len_get(rdata);
+
+ cache->pos = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(cache->pos, vert_len);
+ for (int i = 0; i < vert_len; ++i) {
+ const BPoint *bp = lattice_render_data_vert_bpoint(rdata, i);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.pos, i, bp->vec);
+
+ if (use_weight) {
+ float w_col[4];
+ lattice_render_data_weight_col_get(rdata, i, actdef, w_col);
+
+ GWN_vertbuf_attr_set(cache->pos, attr_id.col, i, w_col);
+ }
+ }
+ }
+
+ return cache->pos;
+}
+
+static Gwn_IndexBuf *lattice_batch_cache_get_edges(LatticeRenderData *rdata, LatticeBatchCache *cache)
+{
+ BLI_assert(rdata->types & (LR_DATATYPE_VERT | LR_DATATYPE_EDGE));
+
+ if (cache->edges == NULL) {
+ const int vert_len = lattice_render_data_verts_len_get(rdata);
+ const int edge_len = lattice_render_data_edges_len_get(rdata);
+ int edge_len_real = 0;
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_LINES, edge_len, vert_len);
+
+#define LATT_INDEX(u, v, w) \
+ ((((w) * rdata->dims.v_len + (v)) * rdata->dims.u_len) + (u))
+
+ for (int w = 0; w < rdata->dims.w_len; w++) {
+ int wxt = (w == 0 || w == rdata->dims.w_len - 1);
+ for (int v = 0; v < rdata->dims.v_len; v++) {
+ int vxt = (v == 0 || v == rdata->dims.v_len - 1);
+ for (int u = 0; u < rdata->dims.u_len; u++) {
+ int uxt = (u == 0 || u == rdata->dims.u_len - 1);
+
+ if (w && ((uxt || vxt) || !rdata->show_only_outside)) {
+ GWN_indexbuf_add_line_verts(&elb, LATT_INDEX(u, v, w - 1), LATT_INDEX(u, v, w));
+ BLI_assert(edge_len_real <= edge_len);
+ edge_len_real++;
+ }
+ if (v && ((uxt || wxt) || !rdata->show_only_outside)) {
+ GWN_indexbuf_add_line_verts(&elb, LATT_INDEX(u, v - 1, w), LATT_INDEX(u, v, w));
+ BLI_assert(edge_len_real <= edge_len);
+ edge_len_real++;
+ }
+ if (u && ((vxt || wxt) || !rdata->show_only_outside)) {
+ GWN_indexbuf_add_line_verts(&elb, LATT_INDEX(u - 1, v, w), LATT_INDEX(u, v, w));
+ BLI_assert(edge_len_real <= edge_len);
+ edge_len_real++;
+ }
+ }
+ }
+ }
+
+#undef LATT_INDEX
+
+ if (rdata->show_only_outside) {
+ BLI_assert(edge_len_real <= edge_len);
+ }
+ else {
+ BLI_assert(edge_len_real == edge_len);
+ }
+
+ cache->edges = GWN_indexbuf_build(&elb);
+ }
+
+ return cache->edges;
+}
+
+static void lattice_batch_cache_create_overlay_batches(Lattice *lt)
+{
+ /* Since LR_DATATYPE_OVERLAY is slow to generate, generate them all at once */
+ int options = LR_DATATYPE_VERT | LR_DATATYPE_OVERLAY;
+
+ LatticeBatchCache *cache = lattice_batch_cache_get(lt);
+ LatticeRenderData *rdata = lattice_render_data_create(lt, options);
+
+ if (cache->overlay_verts == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, data; } attr_id;
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.data = GWN_vertformat_attr_add(&format, "data", GWN_COMP_U8, 1, GWN_FETCH_INT);
+ }
+
+ const int vert_len = lattice_render_data_verts_len_get(rdata);
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vert_len);
+ for (int i = 0; i < vert_len; ++i) {
+ const BPoint *bp = lattice_render_data_vert_bpoint(rdata, i);
+
+ char vflag = 0;
+ if (bp->f1 & SELECT) {
+ if (i == rdata->actbp) {
+ vflag |= VFLAG_VERTEX_ACTIVE;
+ }
+ else {
+ vflag |= VFLAG_VERTEX_SELECTED;
+ }
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i, bp->vec);
+ GWN_vertbuf_attr_set(vbo, attr_id.data, i, &vflag);
+ }
+
+ cache->overlay_verts = GWN_batch_create_ex(GWN_PRIM_POINTS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+ lattice_render_data_free(rdata);
+}
+
+Gwn_Batch *DRW_lattice_batch_cache_get_all_edges(Lattice *lt, bool use_weight, const int actdef)
+{
+ LatticeBatchCache *cache = lattice_batch_cache_get(lt);
+
+ if (cache->all_edges == NULL) {
+ /* create batch from Lattice */
+ LatticeRenderData *rdata = lattice_render_data_create(lt, LR_DATATYPE_VERT | LR_DATATYPE_EDGE);
+
+ cache->all_edges = GWN_batch_create(GWN_PRIM_LINES, lattice_batch_cache_get_pos(rdata, cache, use_weight, actdef),
+ lattice_batch_cache_get_edges(rdata, cache));
+
+ lattice_render_data_free(rdata);
+ }
+
+ return cache->all_edges;
+}
+
+Gwn_Batch *DRW_lattice_batch_cache_get_all_verts(Lattice *lt)
+{
+ LatticeBatchCache *cache = lattice_batch_cache_get(lt);
+
+ if (cache->all_verts == NULL) {
+ LatticeRenderData *rdata = lattice_render_data_create(lt, LR_DATATYPE_VERT);
+
+ cache->all_verts = GWN_batch_create(GWN_PRIM_POINTS, lattice_batch_cache_get_pos(rdata, cache, false, -1), NULL);
+
+ lattice_render_data_free(rdata);
+ }
+
+ return cache->all_verts;
+}
+
+Gwn_Batch *DRW_lattice_batch_cache_get_overlay_verts(Lattice *lt)
+{
+ LatticeBatchCache *cache = lattice_batch_cache_get(lt);
+
+ if (cache->overlay_verts == NULL) {
+ lattice_batch_cache_create_overlay_batches(lt);
+ }
+
+ return cache->overlay_verts;
+}
diff --git a/source/blender/draw/intern/draw_cache_impl_mesh.c b/source/blender/draw/intern/draw_cache_impl_mesh.c
new file mode 100644
index 00000000000..3c75b78976d
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_mesh.c
@@ -0,0 +1,4022 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, Mike Erwin, Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file draw_cache_impl_mesh.c
+ * \ingroup draw
+ *
+ * \brief Mesh API for render engines
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+#include "BLI_math_bits.h"
+#include "BLI_string.h"
+#include "BLI_alloca.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_customdata.h"
+#include "BKE_deform.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_editmesh.h"
+#include "BKE_editmesh_tangent.h"
+#include "BKE_mesh.h"
+#include "BKE_mesh_tangent.h"
+#include "BKE_colorband.h"
+
+#include "bmesh.h"
+
+#include "GPU_batch.h"
+#include "GPU_draw.h"
+#include "GPU_material.h"
+
+#include "draw_cache_impl.h" /* own include */
+
+static void mesh_batch_cache_clear(Mesh *me);
+
+/* ---------------------------------------------------------------------- */
+
+/** \name Mesh/BMesh Interface (direct access to basic data).
+ * \{ */
+
+static int mesh_render_verts_len_get(Mesh *me)
+{
+ return me->edit_btmesh ? me->edit_btmesh->bm->totvert : me->totvert;
+}
+
+static int mesh_render_edges_len_get(Mesh *me)
+{
+ return me->edit_btmesh ? me->edit_btmesh->bm->totedge : me->totedge;
+}
+
+static int mesh_render_looptri_len_get(Mesh *me)
+{
+ return me->edit_btmesh ? me->edit_btmesh->tottri : poly_to_tri_count(me->totpoly, me->totloop);
+}
+
+static int mesh_render_polys_len_get(Mesh *me)
+{
+ return me->edit_btmesh ? me->edit_btmesh->bm->totface : me->totpoly;
+}
+
+static int mesh_render_mat_len_get(Mesh *me)
+{
+ return MAX2(1, me->totcol);
+}
+
+static int UNUSED_FUNCTION(mesh_render_loops_len_get)(Mesh *me)
+{
+ return me->edit_btmesh ? me->edit_btmesh->bm->totloop : me->totloop;
+}
+
+/** \} */
+
+
+/* ---------------------------------------------------------------------- */
+
+/** \name Mesh/BMesh Interface (indirect, partially cached access to complex data).
+ * \{ */
+
+typedef struct EdgeAdjacentPolys {
+ int count;
+ int face_index[2];
+} EdgeAdjacentPolys;
+
+typedef struct EdgeDrawAttr {
+ unsigned char v_flag;
+ unsigned char e_flag;
+ unsigned char crease;
+ unsigned char bweight;
+} EdgeDrawAttr;
+
+typedef struct MeshRenderData {
+ int types;
+
+ int vert_len;
+ int edge_len;
+ int tri_len;
+ int loop_len;
+ int poly_len;
+ int mat_len;
+ int loose_vert_len;
+ int loose_edge_len;
+
+ BMEditMesh *edit_bmesh;
+ struct EditMeshData *edit_data;
+
+ MVert *mvert;
+ MEdge *medge;
+ MLoop *mloop;
+ MPoly *mpoly;
+ float (*orco)[3]; /* vertex coordinates normalized to bounding box */
+ MDeformVert *dvert;
+ MLoopUV *mloopuv;
+ MLoopCol *mloopcol;
+ float (*loop_normals)[3];
+
+ /* CustomData 'cd' cache for efficient access. */
+ struct {
+ struct {
+ MLoopUV **uv;
+ int uv_len;
+ int uv_active;
+
+ MLoopCol **vcol;
+ int vcol_len;
+ int vcol_active;
+
+ float (**tangent)[4];
+ int tangent_len;
+ int tangent_active;
+
+ bool *auto_vcol;
+ } layers;
+
+ /* Custom-data offsets (only needed for BMesh access) */
+ struct {
+ int crease;
+ int bweight;
+ int *uv;
+ int *vcol;
+ } offset;
+
+ struct {
+ char (*auto_mix)[32];
+ char (*uv)[32];
+ char (*vcol)[32];
+ char (*tangent)[32];
+ } uuid;
+
+ /* for certain cases we need an output loop-data storage (bmesh tangents) */
+ struct {
+ CustomData ldata;
+ /* grr, special case variable (use in place of 'dm->tangent_mask') */
+ short tangent_mask;
+ } output;
+ } cd;
+
+ BMVert *eve_act;
+ BMEdge *eed_act;
+ BMFace *efa_act;
+
+ /* Data created on-demand (usually not for bmesh-based data). */
+ EdgeAdjacentPolys *edges_adjacent_polys;
+ MLoopTri *mlooptri;
+ int *loose_edges;
+ int *loose_verts;
+
+ float (*poly_normals)[3];
+ float (*vert_weight_color)[3];
+ char (*vert_color)[3];
+ Gwn_PackedNormal *poly_normals_pack;
+ Gwn_PackedNormal *vert_normals_pack;
+ bool *edge_select_bool;
+} MeshRenderData;
+
+enum {
+ MR_DATATYPE_VERT = 1 << 0,
+ MR_DATATYPE_EDGE = 1 << 1,
+ MR_DATATYPE_LOOPTRI = 1 << 2,
+ MR_DATATYPE_LOOP = 1 << 3,
+ MR_DATATYPE_POLY = 1 << 4,
+ MR_DATATYPE_OVERLAY = 1 << 5,
+ MR_DATATYPE_SHADING = 1 << 6,
+ MR_DATATYPE_DVERT = 1 << 7,
+ MR_DATATYPE_LOOPCOL = 1 << 8,
+ MR_DATATYPE_LOOPUV = 1 << 9,
+};
+
+/**
+ * These functions look like they would be slow but they will typically return true on the first iteration.
+ * Only false when all attached elements are hidden.
+ */
+static bool bm_vert_has_visible_edge(const BMVert *v)
+{
+ const BMEdge *e_iter, *e_first;
+
+ e_iter = e_first = v->e;
+ do {
+ if (!BM_elem_flag_test(e_iter, BM_ELEM_HIDDEN)) {
+ return true;
+ }
+ } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, v)) != e_first);
+ return false;
+}
+
+static bool bm_edge_has_visible_face(const BMEdge *e)
+{
+ const BMLoop *l_iter, *l_first;
+ l_iter = l_first = e->l;
+ do {
+ if (!BM_elem_flag_test(l_iter->f, BM_ELEM_HIDDEN)) {
+ return true;
+ }
+ } while ((l_iter = l_iter->radial_next) != l_first);
+ return false;
+}
+
+
+static void mesh_cd_calc_used_gpu_layers(
+ CustomData *UNUSED(cd_vdata), uchar cd_vused[CD_NUMTYPES],
+ CustomData *cd_ldata, ushort cd_lused[CD_NUMTYPES],
+ struct GPUMaterial **gpumat_array, int gpumat_array_len)
+{
+ /* See: DM_vertex_attributes_from_gpu for similar logic */
+ GPUVertexAttribs gattribs = {{{0}}};
+
+ for (int i = 0; i < gpumat_array_len; i++) {
+ GPUMaterial *gpumat = gpumat_array[i];
+ if (gpumat) {
+ GPU_material_vertex_attributes(gpumat, &gattribs);
+ for (int j = 0; j < gattribs.totlayer; j++) {
+ const char *name = gattribs.layer[j].name;
+ int type = gattribs.layer[j].type;
+ int layer = -1;
+
+ if (type == CD_AUTO_FROM_NAME) {
+ /* We need to deduct what exact layer is used.
+ *
+ * We do it based on the specified name.
+ */
+ if (name[0] != '\0') {
+ layer = CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name);
+ type = CD_MTFACE;
+
+ if (layer == -1) {
+ layer = CustomData_get_named_layer(cd_ldata, CD_MLOOPCOL, name);
+ type = CD_MCOL;
+ }
+#if 0 /* Tangents are always from UV's - this will never happen. */
+ if (layer == -1) {
+ layer = CustomData_get_named_layer(cd_ldata, CD_TANGENT, name);
+ type = CD_TANGENT;
+ }
+#endif
+ if (layer == -1) {
+ continue;
+ }
+ }
+ else {
+ /* Fall back to the UV layer, which matches old behavior. */
+ type = CD_MTFACE;
+ }
+ }
+
+ switch (type) {
+ case CD_MTFACE:
+ {
+ if (layer == -1) {
+ layer = (name[0] != '\0') ?
+ CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) :
+ CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
+ }
+ if (layer != -1) {
+ cd_lused[CD_MLOOPUV] |= (1 << layer);
+ }
+ break;
+ }
+ case CD_TANGENT:
+ {
+ if (layer == -1) {
+ layer = (name[0] != '\0') ?
+ CustomData_get_named_layer(cd_ldata, CD_MLOOPUV, name) :
+ CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
+ }
+ if (layer != -1) {
+ cd_lused[CD_TANGENT] |= (1 << layer);
+ }
+ else {
+ /* no UV layers at all => requesting orco */
+ cd_lused[CD_TANGENT] |= DM_TANGENT_MASK_ORCO;
+ cd_vused[CD_ORCO] |= 1;
+ }
+ break;
+ }
+ case CD_MCOL:
+ {
+ if (layer == -1) {
+ layer = (name[0] != '\0') ?
+ CustomData_get_named_layer(cd_ldata, CD_MLOOPCOL, name) :
+ CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL);
+ }
+ if (layer != -1) {
+ cd_lused[CD_MLOOPCOL] |= (1 << layer);
+ }
+ break;
+ }
+ case CD_ORCO:
+ {
+ cd_vused[CD_ORCO] |= 1;
+ break;
+ }
+ }
+ }
+ }
+ }
+}
+
+
+static void mesh_render_calc_normals_loop_and_poly(const Mesh *me, const float split_angle, MeshRenderData *rdata)
+{
+ BLI_assert((me->flag & ME_AUTOSMOOTH) != 0);
+
+ int totloop = me->totloop;
+ int totpoly = me->totpoly;
+ float (*loop_normals)[3] = MEM_mallocN(sizeof(*loop_normals) * totloop, __func__);
+ float (*poly_normals)[3] = MEM_mallocN(sizeof(*poly_normals) * totpoly, __func__);
+ short (*clnors)[2] = CustomData_get_layer(&me->ldata, CD_CUSTOMLOOPNORMAL);
+
+ BKE_mesh_calc_normals_poly(
+ me->mvert, NULL, me->totvert,
+ me->mloop, me->mpoly, totloop, totpoly, poly_normals, false);
+
+ BKE_mesh_normals_loop_split(
+ me->mvert, me->totvert, me->medge, me->totedge,
+ me->mloop, loop_normals, totloop, me->mpoly, poly_normals, totpoly,
+ true, split_angle, NULL, clnors, NULL);
+
+ rdata->loop_len = totloop;
+ rdata->poly_len = totpoly;
+ rdata->loop_normals = loop_normals;
+ rdata->poly_normals = poly_normals;
+}
+
+
+/**
+ * TODO(campbell): 'gpumat_array' may include materials linked to the object.
+ * While not default, object materials should be supported.
+ * Although this only impacts the data thats generated, not the materials that display.
+ */
+static MeshRenderData *mesh_render_data_create_ex(
+ Mesh *me, const int types,
+ struct GPUMaterial **gpumat_array, uint gpumat_array_len)
+{
+ MeshRenderData *rdata = MEM_callocN(sizeof(*rdata), __func__);
+ rdata->types = types;
+ rdata->mat_len = mesh_render_mat_len_get(me);
+
+ CustomData_reset(&rdata->cd.output.ldata);
+
+ const bool is_auto_smooth = (me->flag & ME_AUTOSMOOTH) != 0;
+ const float split_angle = is_auto_smooth ? me->smoothresh : (float)M_PI;
+
+ if (me->edit_btmesh) {
+ BMEditMesh *embm = me->edit_btmesh;
+ BMesh *bm = embm->bm;
+
+ rdata->edit_bmesh = embm;
+ rdata->edit_data = me->runtime.edit_data;
+
+ int bm_ensure_types = 0;
+ if (types & (MR_DATATYPE_VERT)) {
+ rdata->vert_len = bm->totvert;
+ bm_ensure_types |= BM_VERT;
+ }
+ if (types & (MR_DATATYPE_EDGE)) {
+ rdata->edge_len = bm->totedge;
+ bm_ensure_types |= BM_EDGE;
+ }
+ if (types & MR_DATATYPE_LOOPTRI) {
+ BKE_editmesh_tessface_calc(embm);
+ rdata->tri_len = embm->tottri;
+ }
+ if (types & MR_DATATYPE_LOOP) {
+ int totloop = bm->totloop;
+ if (is_auto_smooth) {
+ rdata->loop_normals = MEM_mallocN(sizeof(*rdata->loop_normals) * totloop, __func__);
+ BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, split_angle, rdata->loop_normals, NULL, NULL, -1);
+ }
+ rdata->loop_len = totloop;
+ bm_ensure_types |= BM_LOOP;
+ }
+ if (types & MR_DATATYPE_POLY) {
+ rdata->poly_len = bm->totface;
+ bm_ensure_types |= BM_FACE;
+ }
+ if (types & MR_DATATYPE_OVERLAY) {
+ rdata->efa_act = BM_mesh_active_face_get(bm, false, true);
+ rdata->eed_act = BM_mesh_active_edge_get(bm);
+ rdata->eve_act = BM_mesh_active_vert_get(bm);
+ rdata->cd.offset.crease = CustomData_get_offset(&bm->edata, CD_CREASE);
+ rdata->cd.offset.bweight = CustomData_get_offset(&bm->edata, CD_BWEIGHT);
+ }
+ if (types & (MR_DATATYPE_DVERT)) {
+ bm_ensure_types |= BM_VERT;
+ }
+ if (rdata->edit_data != NULL) {
+ bm_ensure_types |= BM_VERT;
+ }
+
+ BM_mesh_elem_index_ensure(bm, bm_ensure_types);
+ BM_mesh_elem_table_ensure(bm, bm_ensure_types & ~BM_LOOP);
+ if (types & MR_DATATYPE_OVERLAY) {
+ rdata->loose_vert_len = rdata->loose_edge_len = 0;
+
+ int *lverts = rdata->loose_verts = MEM_mallocN(rdata->vert_len * sizeof(int), "Loose Vert");
+ int *ledges = rdata->loose_edges = MEM_mallocN(rdata->edge_len * sizeof(int), "Loose Edges");
+
+ {
+ BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
+ BMVert **vtable = bm->vtable;
+ for (int i = 0; i < bm->totvert; i++) {
+ const BMVert *eve = vtable[i];
+ if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+ /* Loose vert */
+ if (eve->e == NULL || !bm_vert_has_visible_edge(eve)) {
+ lverts[rdata->loose_vert_len++] = i;
+ }
+ }
+ }
+ }
+
+ {
+ BLI_assert((bm->elem_table_dirty & BM_EDGE) == 0);
+ BMEdge **etable = bm->etable;
+ for (int i = 0; i < bm->totedge; i++) {
+ const BMEdge *eed = etable[i];
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ /* Loose edge */
+ if (eed->l == NULL || !bm_edge_has_visible_face(eed)) {
+ ledges[rdata->loose_edge_len++] = i;
+ }
+ }
+ }
+ }
+
+ rdata->loose_verts = MEM_reallocN(rdata->loose_verts, rdata->loose_vert_len * sizeof(int));
+ rdata->loose_edges = MEM_reallocN(rdata->loose_edges, rdata->loose_edge_len * sizeof(int));
+ }
+ }
+ else {
+ if (types & (MR_DATATYPE_VERT)) {
+ rdata->vert_len = me->totvert;
+ rdata->mvert = CustomData_get_layer(&me->vdata, CD_MVERT);
+ }
+ if (types & (MR_DATATYPE_EDGE)) {
+ rdata->edge_len = me->totedge;
+ rdata->medge = CustomData_get_layer(&me->edata, CD_MEDGE);
+ }
+ if (types & MR_DATATYPE_LOOPTRI) {
+ const int tri_len = rdata->tri_len = poly_to_tri_count(me->totpoly, me->totloop);
+ rdata->mlooptri = MEM_mallocN(sizeof(*rdata->mlooptri) * tri_len, __func__);
+ BKE_mesh_recalc_looptri(me->mloop, me->mpoly, me->mvert, me->totloop, me->totpoly, rdata->mlooptri);
+ }
+ if (types & MR_DATATYPE_LOOP) {
+ rdata->loop_len = me->totloop;
+ rdata->mloop = CustomData_get_layer(&me->ldata, CD_MLOOP);
+
+ if (is_auto_smooth) {
+ mesh_render_calc_normals_loop_and_poly(me, split_angle, rdata);
+ }
+ }
+ if (types & MR_DATATYPE_POLY) {
+ rdata->poly_len = me->totpoly;
+ rdata->mpoly = CustomData_get_layer(&me->pdata, CD_MPOLY);
+ }
+ if (types & MR_DATATYPE_DVERT) {
+ rdata->vert_len = me->totvert;
+ rdata->dvert = CustomData_get_layer(&me->vdata, CD_MDEFORMVERT);
+ }
+ if (types & MR_DATATYPE_LOOPCOL) {
+ rdata->loop_len = me->totloop;
+ rdata->mloopcol = CustomData_get_layer(&me->ldata, CD_MLOOPCOL);
+ }
+ if (types & MR_DATATYPE_LOOPUV) {
+ rdata->loop_len = me->totloop;
+ rdata->mloopuv = CustomData_get_layer(&me->ldata, CD_MLOOPUV);
+ }
+ }
+
+ if (types & MR_DATATYPE_SHADING) {
+ CustomData *cd_vdata, *cd_ldata;
+
+ if (me->edit_btmesh) {
+ BMesh *bm = me->edit_btmesh->bm;
+ cd_vdata = &bm->vdata;
+ cd_ldata = &bm->ldata;
+ }
+ else {
+ cd_vdata = &me->vdata;
+ cd_ldata = &me->ldata;
+ }
+
+ /* Add edge/poly if we need them */
+ uchar cd_vused[CD_NUMTYPES] = {0};
+ ushort cd_lused[CD_NUMTYPES] = {0};
+
+ mesh_cd_calc_used_gpu_layers(
+ cd_vdata, cd_vused,
+ cd_ldata, cd_lused,
+ gpumat_array, gpumat_array_len);
+
+
+ rdata->cd.layers.uv_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPUV);
+ rdata->cd.layers.vcol_active = CustomData_get_active_layer(cd_ldata, CD_MLOOPCOL);
+ rdata->cd.layers.tangent_active = rdata->cd.layers.uv_active;
+
+#define CD_VALIDATE_ACTIVE_LAYER(active_index, used) \
+ if ((active_index != -1) && (used & (1 << active_index)) == 0) { \
+ active_index = -1; \
+ } ((void)0)
+
+ CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.uv_active, cd_lused[CD_MLOOPUV]);
+ CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.tangent_active, cd_lused[CD_TANGENT]);
+ CD_VALIDATE_ACTIVE_LAYER(rdata->cd.layers.vcol_active, cd_lused[CD_MLOOPCOL]);
+
+#undef CD_VALIDATE_ACTIVE_LAYER
+
+ if (cd_vused[CD_ORCO] & 1) {
+ rdata->orco = CustomData_get_layer(cd_vdata, CD_ORCO);
+ /* If orco is not available compute it ourselves */
+ if (!rdata->orco) {
+ if (me->edit_btmesh) {
+ BMesh *bm = me->edit_btmesh->bm;
+ rdata->orco = MEM_mallocN(sizeof(*rdata->orco) * rdata->vert_len, "orco mesh");
+ BLI_assert((bm->elem_table_dirty & BM_VERT) == 0);
+ BMVert **vtable = bm->vtable;
+ for (int i = 0; i < bm->totvert; i++) {
+ copy_v3_v3(rdata->orco[i], vtable[i]->co);
+ }
+ BKE_mesh_orco_verts_transform(me, rdata->orco, rdata->vert_len, 0);
+ }
+ else {
+ rdata->orco = MEM_mallocN(sizeof(*rdata->orco) * rdata->vert_len, "orco mesh");
+ MVert *mvert = rdata->mvert;
+ for (int a = 0; a < rdata->vert_len; a++, mvert++) {
+ copy_v3_v3(rdata->orco[a], mvert->co);
+ }
+ BKE_mesh_orco_verts_transform(me, rdata->orco, rdata->vert_len, 0);
+ }
+ }
+ }
+ else {
+ rdata->orco = NULL;
+ }
+
+ /* don't access mesh directly, instead use vars taken from BMesh or Mesh */
+#define me DONT_USE_THIS
+#ifdef me /* quiet warning */
+#endif
+ struct {
+ uint uv_len;
+ uint vcol_len;
+ } cd_layers_src = {
+ .uv_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPUV),
+ .vcol_len = CustomData_number_of_layers(cd_ldata, CD_MLOOPCOL),
+ };
+
+ rdata->cd.layers.uv_len = count_bits_i(cd_lused[CD_MLOOPUV]);
+ rdata->cd.layers.tangent_len = count_bits_i(cd_lused[CD_TANGENT]);
+ rdata->cd.layers.vcol_len = count_bits_i(cd_lused[CD_MLOOPCOL]);
+
+ rdata->cd.layers.uv = MEM_mallocN(sizeof(*rdata->cd.layers.uv) * rdata->cd.layers.uv_len, __func__);
+ rdata->cd.layers.vcol = MEM_mallocN(sizeof(*rdata->cd.layers.vcol) * rdata->cd.layers.vcol_len, __func__);
+ rdata->cd.layers.tangent = MEM_mallocN(sizeof(*rdata->cd.layers.tangent) * rdata->cd.layers.tangent_len, __func__);
+
+ rdata->cd.uuid.uv = MEM_mallocN(sizeof(*rdata->cd.uuid.uv) * rdata->cd.layers.uv_len, __func__);
+ rdata->cd.uuid.vcol = MEM_mallocN(sizeof(*rdata->cd.uuid.vcol) * rdata->cd.layers.vcol_len, __func__);
+ rdata->cd.uuid.tangent = MEM_mallocN(sizeof(*rdata->cd.uuid.tangent) * rdata->cd.layers.tangent_len, __func__);
+
+ rdata->cd.offset.uv = MEM_mallocN(sizeof(*rdata->cd.offset.uv) * rdata->cd.layers.uv_len, __func__);
+ rdata->cd.offset.vcol = MEM_mallocN(sizeof(*rdata->cd.offset.vcol) * rdata->cd.layers.vcol_len, __func__);
+
+ /* Allocate max */
+ rdata->cd.layers.auto_vcol = MEM_callocN(
+ sizeof(*rdata->cd.layers.auto_vcol) * rdata->cd.layers.vcol_len, __func__);
+ rdata->cd.uuid.auto_mix = MEM_mallocN(
+ sizeof(*rdata->cd.uuid.auto_mix) * (rdata->cd.layers.vcol_len + rdata->cd.layers.uv_len), __func__);
+
+ /* XXX FIXME XXX */
+ /* We use a hash to identify each data layer based on its name.
+ * Gawain then search for this name in the current shader and bind if it exists.
+ * NOTE : This is prone to hash collision.
+ * One solution to hash collision would be to format the cd layer name
+ * to a safe glsl var name, but without name clash.
+ * NOTE 2 : Replicate changes to code_generate_vertex_new() in gpu_codegen.c */
+ if (rdata->cd.layers.vcol_len != 0) {
+ for (int i_src = 0, i_dst = 0; i_src < cd_layers_src.vcol_len; i_src++, i_dst++) {
+ if ((cd_lused[CD_MLOOPCOL] & (1 << i_src)) == 0) {
+ i_dst--;
+ if (rdata->cd.layers.vcol_active >= i_src) {
+ rdata->cd.layers.vcol_active--;
+ }
+ }
+ else {
+ const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPCOL, i_src);
+ unsigned int hash = BLI_ghashutil_strhash_p(name);
+ BLI_snprintf(rdata->cd.uuid.vcol[i_dst], sizeof(*rdata->cd.uuid.vcol), "c%u", hash);
+ rdata->cd.layers.vcol[i_dst] = CustomData_get_layer_n(cd_ldata, CD_MLOOPCOL, i_src);
+ if (rdata->edit_bmesh) {
+ rdata->cd.offset.vcol[i_dst] = CustomData_get_n_offset(
+ &rdata->edit_bmesh->bm->ldata, CD_MLOOPCOL, i_src);
+ }
+
+ /* Gather number of auto layers. */
+ /* We only do vcols that are not overridden by uvs */
+ if (CustomData_get_named_layer_index(cd_ldata, CD_MLOOPUV, name) == -1) {
+ BLI_snprintf(
+ rdata->cd.uuid.auto_mix[rdata->cd.layers.uv_len + i_dst],
+ sizeof(*rdata->cd.uuid.auto_mix), "a%u", hash);
+ rdata->cd.layers.auto_vcol[i_dst] = true;
+ }
+ }
+ }
+ }
+
+ /* Start Fresh */
+ CustomData_free_layers(cd_ldata, CD_TANGENT, rdata->loop_len);
+ CustomData_free_layers(cd_ldata, CD_MLOOPTANGENT, rdata->loop_len);
+
+ if (rdata->cd.layers.uv_len != 0) {
+ for (int i_src = 0, i_dst = 0; i_src < cd_layers_src.uv_len; i_src++, i_dst++) {
+ if ((cd_lused[CD_MLOOPUV] & (1 << i_src)) == 0) {
+ i_dst--;
+ if (rdata->cd.layers.uv_active >= i_src) {
+ rdata->cd.layers.uv_active--;
+ }
+ }
+ else {
+ const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i_src);
+ unsigned int hash = BLI_ghashutil_strhash_p(name);
+
+ BLI_snprintf(rdata->cd.uuid.uv[i_dst], sizeof(*rdata->cd.uuid.uv), "u%u", hash);
+ rdata->cd.layers.uv[i_dst] = CustomData_get_layer_n(cd_ldata, CD_MLOOPUV, i_src);
+ if (rdata->edit_bmesh) {
+ rdata->cd.offset.uv[i_dst] = CustomData_get_n_offset(
+ &rdata->edit_bmesh->bm->ldata, CD_MLOOPUV, i_src);
+ }
+ BLI_snprintf(rdata->cd.uuid.auto_mix[i_dst], sizeof(*rdata->cd.uuid.auto_mix), "a%u", hash);
+ }
+ }
+ }
+
+ if (rdata->cd.layers.tangent_len != 0) {
+
+ /* -------------------------------------------------------------------- */
+ /* Pre-calculate tangents into 'rdata->cd.output.ldata' */
+
+ BLI_assert(!CustomData_has_layer(&rdata->cd.output.ldata, CD_TANGENT));
+
+ /* Tangent Names */
+ char tangent_names[MAX_MTFACE][MAX_NAME];
+ for (int i_src = 0, i_dst = 0; i_src < cd_layers_src.uv_len; i_src++, i_dst++) {
+ if ((cd_lused[CD_TANGENT] & (1 << i_src)) == 0) {
+ i_dst--;
+ }
+ else {
+ BLI_strncpy(
+ tangent_names[i_dst],
+ CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i_src), MAX_NAME);
+ }
+ }
+
+ /* If tangent from orco is requested, decrement tangent_len */
+ int actual_tangent_len = (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) ?
+ rdata->cd.layers.tangent_len - 1 : rdata->cd.layers.tangent_len;
+ if (rdata->edit_bmesh) {
+ BMEditMesh *em = rdata->edit_bmesh;
+ BMesh *bm = em->bm;
+
+ if (is_auto_smooth && rdata->loop_normals == NULL) {
+ /* Should we store the previous array of `loop_normals` in somewhere? */
+ rdata->loop_len = bm->totloop;
+ rdata->loop_normals = MEM_mallocN(sizeof(*rdata->loop_normals) * rdata->loop_len, __func__);
+ BM_loops_calc_normal_vcos(bm, NULL, NULL, NULL, true, split_angle, rdata->loop_normals, NULL, NULL, -1);
+ }
+
+ bool calc_active_tangent = false;
+
+ BKE_editmesh_loop_tangent_calc(
+ em, calc_active_tangent,
+ tangent_names, actual_tangent_len,
+ rdata->poly_normals, rdata->loop_normals,
+ rdata->orco,
+ &rdata->cd.output.ldata, bm->totloop,
+ &rdata->cd.output.tangent_mask);
+ }
+ else {
+#undef me
+
+ if (is_auto_smooth && rdata->loop_normals == NULL) {
+ /* Should we store the previous array of `loop_normals` in CustomData? */
+ mesh_render_calc_normals_loop_and_poly(me, split_angle, rdata);
+ }
+
+ bool calc_active_tangent = false;
+
+ BKE_mesh_calc_loop_tangent_ex(
+ me->mvert,
+ me->mpoly, me->totpoly,
+ me->mloop,
+ rdata->mlooptri, rdata->tri_len,
+ cd_ldata,
+ calc_active_tangent,
+ tangent_names, actual_tangent_len,
+ rdata->poly_normals, rdata->loop_normals,
+ rdata->orco,
+ &rdata->cd.output.ldata, me->totloop,
+ &rdata->cd.output.tangent_mask);
+
+ /* If we store tangents in the mesh, set temporary. */
+#if 0
+ CustomData_set_layer_flag(cd_ldata, CD_TANGENT, CD_FLAG_TEMPORARY);
+#endif
+
+#define me DONT_USE_THIS
+#ifdef me /* quiet warning */
+#endif
+ }
+
+ /* End tangent calculation */
+ /* -------------------------------------------------------------------- */
+
+ BLI_assert(CustomData_number_of_layers(&rdata->cd.output.ldata, CD_TANGENT) == rdata->cd.layers.tangent_len);
+
+ int i_dst = 0;
+ for (int i_src = 0; i_src < cd_layers_src.uv_len; i_src++, i_dst++) {
+ if ((cd_lused[CD_TANGENT] & (1 << i_src)) == 0) {
+ i_dst--;
+ if (rdata->cd.layers.tangent_active >= i_src) {
+ rdata->cd.layers.tangent_active--;
+ }
+ }
+ else {
+ const char *name = CustomData_get_layer_name(cd_ldata, CD_MLOOPUV, i_src);
+ unsigned int hash = BLI_ghashutil_strhash_p(name);
+
+ BLI_snprintf(rdata->cd.uuid.tangent[i_dst], sizeof(*rdata->cd.uuid.tangent), "t%u", hash);
+
+ /* Done adding tangents. */
+
+ /* note: BKE_editmesh_loop_tangent_calc calculates 'CD_TANGENT',
+ * not 'CD_MLOOPTANGENT' (as done below). It's OK, they're compatible. */
+
+ /* note: normally we'd use 'i_src' here, but 'i_dst' is in sync with 'rdata->cd.output' */
+ rdata->cd.layers.tangent[i_dst] = CustomData_get_layer_n(&rdata->cd.output.ldata, CD_TANGENT, i_dst);
+ if (rdata->tri_len != 0) {
+ BLI_assert(rdata->cd.layers.tangent[i_dst] != NULL);
+ }
+ }
+ }
+ if (cd_lused[CD_TANGENT] & DM_TANGENT_MASK_ORCO) {
+ const char *name = CustomData_get_layer_name(&rdata->cd.output.ldata, CD_TANGENT, i_dst);
+ unsigned int hash = BLI_ghashutil_strhash_p(name);
+ BLI_snprintf(rdata->cd.uuid.tangent[i_dst], sizeof(*rdata->cd.uuid.tangent), "t%u", hash);
+
+ rdata->cd.layers.tangent[i_dst] = CustomData_get_layer_n(&rdata->cd.output.ldata, CD_TANGENT, i_dst);
+ }
+ }
+
+#undef me
+ }
+
+ return rdata;
+}
+
+static void mesh_render_data_free(MeshRenderData *rdata)
+{
+ MEM_SAFE_FREE(rdata->orco);
+ MEM_SAFE_FREE(rdata->cd.offset.uv);
+ MEM_SAFE_FREE(rdata->cd.offset.vcol);
+ MEM_SAFE_FREE(rdata->cd.uuid.auto_mix);
+ MEM_SAFE_FREE(rdata->cd.uuid.uv);
+ MEM_SAFE_FREE(rdata->cd.uuid.vcol);
+ MEM_SAFE_FREE(rdata->cd.uuid.tangent);
+ MEM_SAFE_FREE(rdata->cd.layers.uv);
+ MEM_SAFE_FREE(rdata->cd.layers.vcol);
+ MEM_SAFE_FREE(rdata->cd.layers.tangent);
+ MEM_SAFE_FREE(rdata->cd.layers.auto_vcol);
+ MEM_SAFE_FREE(rdata->loose_verts);
+ MEM_SAFE_FREE(rdata->loose_edges);
+ MEM_SAFE_FREE(rdata->edges_adjacent_polys);
+ MEM_SAFE_FREE(rdata->mlooptri);
+ MEM_SAFE_FREE(rdata->loop_normals);
+ MEM_SAFE_FREE(rdata->poly_normals);
+ MEM_SAFE_FREE(rdata->poly_normals_pack);
+ MEM_SAFE_FREE(rdata->vert_normals_pack);
+ MEM_SAFE_FREE(rdata->vert_weight_color);
+ MEM_SAFE_FREE(rdata->edge_select_bool);
+ MEM_SAFE_FREE(rdata->vert_color);
+
+ CustomData_free(&rdata->cd.output.ldata, rdata->loop_len);
+
+ MEM_freeN(rdata);
+}
+
+static MeshRenderData *mesh_render_data_create(Mesh *me, const int types)
+{
+ return mesh_render_data_create_ex(me, types, NULL, 0);
+}
+
+/** \} */
+
+
+/* ---------------------------------------------------------------------- */
+
+/** \name Accessor Functions
+ * \{ */
+
+static const char *mesh_render_data_uv_auto_layer_uuid_get(const MeshRenderData *rdata, int layer)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_SHADING);
+ return rdata->cd.uuid.auto_mix[layer];
+}
+
+static const char *mesh_render_data_vcol_auto_layer_uuid_get(const MeshRenderData *rdata, int layer)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_SHADING);
+ return rdata->cd.uuid.auto_mix[rdata->cd.layers.uv_len + layer];
+}
+
+static const char *mesh_render_data_uv_layer_uuid_get(const MeshRenderData *rdata, int layer)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_SHADING);
+ return rdata->cd.uuid.uv[layer];
+}
+
+static const char *mesh_render_data_vcol_layer_uuid_get(const MeshRenderData *rdata, int layer)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_SHADING);
+ return rdata->cd.uuid.vcol[layer];
+}
+
+static const char *mesh_render_data_tangent_layer_uuid_get(const MeshRenderData *rdata, int layer)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_SHADING);
+ return rdata->cd.uuid.tangent[layer];
+}
+
+static int mesh_render_data_verts_len_get(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+ return rdata->vert_len;
+}
+
+static int mesh_render_data_loose_verts_len_get(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_OVERLAY);
+ return rdata->loose_vert_len;
+}
+
+static int mesh_render_data_edges_len_get(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_EDGE);
+ return rdata->edge_len;
+}
+
+static int mesh_render_data_loose_edges_len_get(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_OVERLAY);
+ return rdata->loose_edge_len;
+}
+
+static int mesh_render_data_looptri_len_get(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_LOOPTRI);
+ return rdata->tri_len;
+}
+
+static int mesh_render_data_mat_len_get(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_POLY);
+ return rdata->mat_len;
+}
+
+static int UNUSED_FUNCTION(mesh_render_data_loops_len_get)(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_LOOP);
+ return rdata->loop_len;
+}
+
+static int mesh_render_data_polys_len_get(const MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_POLY);
+ return rdata->poly_len;
+}
+
+/** \} */
+
+
+/* ---------------------------------------------------------------------- */
+
+/** \name Internal Cache (Lazy Initialization)
+ * \{ */
+
+/** Ensure #MeshRenderData.poly_normals_pack */
+static void mesh_render_data_ensure_poly_normals_pack(MeshRenderData *rdata)
+{
+ Gwn_PackedNormal *pnors_pack = rdata->poly_normals_pack;
+ if (pnors_pack == NULL) {
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter fiter;
+ BMFace *efa;
+ int i;
+
+ pnors_pack = rdata->poly_normals_pack = MEM_mallocN(sizeof(*pnors_pack) * rdata->poly_len, __func__);
+ BM_ITER_MESH_INDEX(efa, &fiter, bm, BM_FACES_OF_MESH, i) {
+ pnors_pack[i] = GWN_normal_convert_i10_v3(efa->no);
+ }
+ }
+ else {
+ float (*pnors)[3] = rdata->poly_normals;
+
+ if (!pnors) {
+ pnors = rdata->poly_normals = MEM_mallocN(sizeof(*pnors) * rdata->poly_len, __func__);
+ BKE_mesh_calc_normals_poly(
+ rdata->mvert, NULL, rdata->vert_len,
+ rdata->mloop, rdata->mpoly, rdata->loop_len, rdata->poly_len, pnors, true);
+ }
+
+ pnors_pack = rdata->poly_normals_pack = MEM_mallocN(sizeof(*pnors_pack) * rdata->poly_len, __func__);
+ for (int i = 0; i < rdata->poly_len; i++) {
+ pnors_pack[i] = GWN_normal_convert_i10_v3(pnors[i]);
+ }
+ }
+ }
+}
+
+/** Ensure #MeshRenderData.vert_normals_pack */
+static void mesh_render_data_ensure_vert_normals_pack(MeshRenderData *rdata)
+{
+ Gwn_PackedNormal *vnors_pack = rdata->vert_normals_pack;
+ if (vnors_pack == NULL) {
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter viter;
+ BMVert *eve;
+ int i;
+
+ vnors_pack = rdata->vert_normals_pack = MEM_mallocN(sizeof(*vnors_pack) * rdata->vert_len, __func__);
+ BM_ITER_MESH_INDEX(eve, &viter, bm, BM_VERT, i) {
+ vnors_pack[i] = GWN_normal_convert_i10_v3(eve->no);
+ }
+ }
+ else {
+ /* data from mesh used directly */
+ BLI_assert(0);
+ }
+ }
+}
+
+
+/** Ensure #MeshRenderData.vert_color */
+static void mesh_render_data_ensure_vert_color(MeshRenderData *rdata)
+{
+ char (*vcol)[3] = rdata->vert_color;
+ if (vcol == NULL) {
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ const int cd_loop_color_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPCOL);
+ if (cd_loop_color_offset == -1) {
+ goto fallback;
+ }
+
+ vcol = rdata->vert_color = MEM_mallocN(sizeof(*vcol) * rdata->loop_len, __func__);
+
+ BMIter fiter;
+ BMFace *efa;
+ int i = 0;
+
+ BM_ITER_MESH(efa, &fiter, bm, BM_FACES_OF_MESH) {
+ BMLoop *l_iter, *l_first;
+ l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
+ do {
+ const MLoopCol *lcol = BM_ELEM_CD_GET_VOID_P(l_iter, cd_loop_color_offset);
+ vcol[i][0] = lcol->r;
+ vcol[i][1] = lcol->g;
+ vcol[i][2] = lcol->b;
+ i += 1;
+ } while ((l_iter = l_iter->next) != l_first);
+ }
+ BLI_assert(i == rdata->loop_len);
+ }
+ else {
+ if (rdata->mloopcol == NULL) {
+ goto fallback;
+ }
+
+ vcol = rdata->vert_color = MEM_mallocN(sizeof(*vcol) * rdata->loop_len, __func__);
+
+ for (int i = 0; i < rdata->loop_len; i++) {
+ vcol[i][0] = rdata->mloopcol[i].r;
+ vcol[i][1] = rdata->mloopcol[i].g;
+ vcol[i][2] = rdata->mloopcol[i].b;
+ }
+ }
+ }
+ return;
+
+fallback:
+ vcol = rdata->vert_color = MEM_mallocN(sizeof(*vcol) * rdata->loop_len, __func__);
+
+ for (int i = 0; i < rdata->loop_len; i++) {
+ vcol[i][0] = 255;
+ vcol[i][1] = 255;
+ vcol[i][2] = 255;
+ }
+}
+
+/* TODO, move into shader? */
+static void rgb_from_weight(float r_rgb[3], const float weight)
+{
+ const float blend = ((weight / 2.0f) + 0.5f);
+
+ if (weight <= 0.25f) { /* blue->cyan */
+ r_rgb[0] = 0.0f;
+ r_rgb[1] = blend * weight * 4.0f;
+ r_rgb[2] = blend;
+ }
+ else if (weight <= 0.50f) { /* cyan->green */
+ r_rgb[0] = 0.0f;
+ r_rgb[1] = blend;
+ r_rgb[2] = blend * (1.0f - ((weight - 0.25f) * 4.0f));
+ }
+ else if (weight <= 0.75f) { /* green->yellow */
+ r_rgb[0] = blend * ((weight - 0.50f) * 4.0f);
+ r_rgb[1] = blend;
+ r_rgb[2] = 0.0f;
+ }
+ else if (weight <= 1.0f) { /* yellow->red */
+ r_rgb[0] = blend;
+ r_rgb[1] = blend * (1.0f - ((weight - 0.75f) * 4.0f));
+ r_rgb[2] = 0.0f;
+ }
+ else {
+ /* exceptional value, unclamped or nan,
+ * avoid uninitialized memory use */
+ r_rgb[0] = 1.0f;
+ r_rgb[1] = 0.0f;
+ r_rgb[2] = 1.0f;
+ }
+}
+
+
+/** Ensure #MeshRenderData.vert_weight_color */
+static void mesh_render_data_ensure_vert_weight_color(MeshRenderData *rdata, const int defgroup)
+{
+ float (*vweight)[3] = rdata->vert_weight_color;
+ if (vweight == NULL) {
+ if (defgroup == -1) {
+ goto fallback;
+ }
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT);
+ if (cd_dvert_offset == -1) {
+ goto fallback;
+ }
+
+ BMIter viter;
+ BMVert *eve;
+ int i;
+
+ vweight = rdata->vert_weight_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__);
+ BM_ITER_MESH_INDEX(eve, &viter, bm, BM_VERT, i) {
+ const MDeformVert *dvert = BM_ELEM_CD_GET_VOID_P(eve, cd_dvert_offset);
+ float weight = defvert_find_weight(dvert, defgroup);
+ if (U.flag & USER_CUSTOM_RANGE) {
+ BKE_colorband_evaluate(&U.coba_weight, weight, vweight[i]);
+ }
+ else {
+ rgb_from_weight(vweight[i], weight);
+ }
+ }
+ }
+ else {
+ if (rdata->dvert == NULL) {
+ goto fallback;
+ }
+
+ vweight = rdata->vert_weight_color = MEM_mallocN(sizeof(*vweight) * rdata->vert_len, __func__);
+ for (int i = 0; i < rdata->vert_len; i++) {
+ float weight = defvert_find_weight(&rdata->dvert[i], defgroup);
+ if (U.flag & USER_CUSTOM_RANGE) {
+ BKE_colorband_evaluate(&U.coba_weight, weight, vweight[i]);
+ }
+ else {
+ rgb_from_weight(vweight[i], weight);
+ }
+ }
+ }
+ }
+ return;
+
+fallback:
+ vweight = rdata->vert_weight_color = MEM_callocN(sizeof(*vweight) * rdata->vert_len, __func__);
+
+ for (int i = 0; i < rdata->vert_len; i++) {
+ vweight[i][2] = 0.5f;
+ }
+}
+
+/** Ensure #MeshRenderData.edge_select_bool */
+static void mesh_render_data_ensure_edge_select_bool(MeshRenderData *rdata, bool use_wire)
+{
+ bool *edge_select_bool = rdata->edge_select_bool;
+ if (edge_select_bool == NULL) {
+ edge_select_bool = rdata->edge_select_bool =
+ MEM_callocN(sizeof(*edge_select_bool) * rdata->edge_len, __func__);
+
+ for (int i = 0; i < rdata->poly_len; i++) {
+ MPoly *poly = &rdata->mpoly[i];
+
+ if (poly->flag & ME_FACE_SEL) {
+ for (int j = 0; j < poly->totloop; j++) {
+ MLoop *loop = &rdata->mloop[poly->loopstart + j];
+ if (use_wire) {
+ edge_select_bool[loop->e] = true;
+ }
+ else {
+ /* Not totally correct, will cause problems for edges with 3x faces. */
+ edge_select_bool[loop->e] = !edge_select_bool[loop->e];
+ }
+ }
+ }
+ }
+ }
+}
+
+/** \} */
+
+/* ---------------------------------------------------------------------- */
+
+/** \name Internal Cache Generation
+ * \{ */
+
+static bool mesh_render_data_pnors_pcenter_select_get(
+ MeshRenderData *rdata, const int poly,
+ float r_pnors[3], float r_center[3], bool *r_selected)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+
+ if (rdata->edit_bmesh) {
+ const BMFace *efa = BM_face_at_index(rdata->edit_bmesh->bm, poly);
+ if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ return false;
+ }
+ BM_face_calc_center_mean(efa, r_center);
+ copy_v3_v3(r_pnors, efa->no);
+ *r_selected = (BM_elem_flag_test(efa, BM_ELEM_SELECT) != 0) ? true : false;
+ }
+ else {
+ MVert *mvert = rdata->mvert;
+ const MPoly *mpoly = rdata->mpoly + poly;
+ const MLoop *mloop = rdata->mloop + mpoly->loopstart;
+
+ BKE_mesh_calc_poly_center(mpoly, mloop, mvert, r_center);
+ BKE_mesh_calc_poly_normal(mpoly, mloop, mvert, r_pnors);
+
+ *r_selected = false; /* No selection if not in edit mode */
+ }
+
+ return true;
+}
+
+static bool mesh_render_data_edge_vcos_manifold_pnors(
+ MeshRenderData *rdata, const int edge_index,
+ float **r_vco1, float **r_vco2, float **r_pnor1, float **r_pnor2, bool *r_is_manifold)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMEdge *eed = BM_edge_at_index(bm, edge_index);
+ if (BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ return false;
+ }
+ *r_vco1 = eed->v1->co;
+ *r_vco2 = eed->v2->co;
+ if (BM_edge_is_manifold(eed)) {
+ *r_pnor1 = eed->l->f->no;
+ *r_pnor2 = eed->l->radial_next->f->no;
+ *r_is_manifold = true;
+ }
+ else {
+ *r_is_manifold = false;
+ }
+ }
+ else {
+ MVert *mvert = rdata->mvert;
+ MEdge *medge = rdata->medge;
+ EdgeAdjacentPolys *eap = rdata->edges_adjacent_polys;
+ float (*pnors)[3] = rdata->poly_normals;
+
+ if (!eap) {
+ const MLoop *mloop = rdata->mloop;
+ const MPoly *mpoly = rdata->mpoly;
+ const int poly_len = rdata->poly_len;
+ const bool do_pnors = (pnors == NULL);
+
+ eap = rdata->edges_adjacent_polys = MEM_callocN(sizeof(*eap) * rdata->edge_len, __func__);
+ if (do_pnors) {
+ pnors = rdata->poly_normals = MEM_mallocN(sizeof(*pnors) * poly_len, __func__);
+ }
+
+ for (int i = 0; i < poly_len; i++, mpoly++) {
+ if (do_pnors) {
+ BKE_mesh_calc_poly_normal(mpoly, mloop + mpoly->loopstart, mvert, pnors[i]);
+ }
+
+ const int loopend = mpoly->loopstart + mpoly->totloop;
+ for (int j = mpoly->loopstart; j < loopend; j++) {
+ const int edge_idx = mloop[j].e;
+ if (eap[edge_idx].count < 2) {
+ eap[edge_idx].face_index[eap[edge_idx].count] = i;
+ }
+ eap[edge_idx].count++;
+ }
+ }
+ }
+ BLI_assert(eap && pnors);
+
+ *r_vco1 = mvert[medge[edge_index].v1].co;
+ *r_vco2 = mvert[medge[edge_index].v2].co;
+ if (eap[edge_index].count == 2) {
+ *r_pnor1 = pnors[eap[edge_index].face_index[0]];
+ *r_pnor2 = pnors[eap[edge_index].face_index[1]];
+ *r_is_manifold = true;
+ }
+ else {
+ *r_is_manifold = false;
+ }
+ }
+
+ return true;
+}
+
+
+/* First 2 bytes are bit flags
+ * 3rd is for sharp edges
+ * 4rd is for creased edges */
+enum {
+ VFLAG_VERTEX_ACTIVE = 1 << 0,
+ VFLAG_VERTEX_SELECTED = 1 << 1,
+ VFLAG_FACE_ACTIVE = 1 << 2,
+ VFLAG_FACE_SELECTED = 1 << 3,
+};
+
+enum {
+ VFLAG_EDGE_EXISTS = 1 << 0,
+ VFLAG_EDGE_ACTIVE = 1 << 1,
+ VFLAG_EDGE_SELECTED = 1 << 2,
+ VFLAG_EDGE_SEAM = 1 << 3,
+ VFLAG_EDGE_SHARP = 1 << 4,
+ /* Beware to not go over 1 << 7
+ * (see gpu_shader_edit_mesh_overlay_geom.glsl) */
+};
+
+static unsigned char mesh_render_data_looptri_flag(MeshRenderData *rdata, const BMFace *efa)
+{
+ unsigned char fflag = 0;
+
+ if (efa == rdata->efa_act)
+ fflag |= VFLAG_FACE_ACTIVE;
+
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT))
+ fflag |= VFLAG_FACE_SELECTED;
+
+ return fflag;
+}
+
+static void mesh_render_data_edge_flag(
+ const MeshRenderData *rdata, const BMEdge *eed,
+ EdgeDrawAttr *eattr)
+{
+ eattr->e_flag |= VFLAG_EDGE_EXISTS;
+
+ if (eed == rdata->eed_act)
+ eattr->e_flag |= VFLAG_EDGE_ACTIVE;
+
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT))
+ eattr->e_flag |= VFLAG_EDGE_SELECTED;
+
+ if (BM_elem_flag_test(eed, BM_ELEM_SEAM))
+ eattr->e_flag |= VFLAG_EDGE_SEAM;
+
+ if (!BM_elem_flag_test(eed, BM_ELEM_SMOOTH))
+ eattr->e_flag |= VFLAG_EDGE_SHARP;
+
+ /* Use a byte for value range */
+ if (rdata->cd.offset.crease != -1) {
+ float crease = BM_ELEM_CD_GET_FLOAT(eed, rdata->cd.offset.crease);
+ if (crease > 0) {
+ eattr->crease = (char)(crease * 255.0f);
+ }
+ }
+
+ /* Use a byte for value range */
+ if (rdata->cd.offset.bweight != -1) {
+ float bweight = BM_ELEM_CD_GET_FLOAT(eed, rdata->cd.offset.bweight);
+ if (bweight > 0) {
+ eattr->bweight = (char)(bweight * 255.0f);
+ }
+ }
+}
+
+static unsigned char mesh_render_data_vertex_flag(MeshRenderData *rdata, const BMVert *eve)
+{
+
+ unsigned char vflag = 0;
+
+ /* Current vertex */
+ if (eve == rdata->eve_act)
+ vflag |= VFLAG_VERTEX_ACTIVE;
+
+ if (BM_elem_flag_test(eve, BM_ELEM_SELECT))
+ vflag |= VFLAG_VERTEX_SELECTED;
+
+ return vflag;
+}
+
+static void add_overlay_tri(
+ MeshRenderData *rdata, Gwn_VertBuf *vbo_pos, Gwn_VertBuf *vbo_nor, Gwn_VertBuf *vbo_data,
+ const unsigned int pos_id, const unsigned int vnor_id, const unsigned int lnor_id, const unsigned int data_id,
+ const BMLoop **bm_looptri, const int base_vert_idx)
+{
+ unsigned char fflag;
+ unsigned char vflag;
+
+ if (vbo_pos) {
+ /* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
+ if (rdata->edit_data && rdata->edit_data->vertexCos) {
+ for (uint i = 0; i < 3; i++) {
+ int vidx = BM_elem_index_get(bm_looptri[i]->v);
+ const float *pos = rdata->edit_data->vertexCos[vidx];
+ GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
+ }
+ }
+ else {
+ for (uint i = 0; i < 3; i++) {
+ const float *pos = bm_looptri[i]->v->co;
+ GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
+ }
+ }
+ }
+
+ if (vbo_nor) {
+ /* TODO real loop normal */
+ Gwn_PackedNormal lnor = GWN_normal_convert_i10_v3(bm_looptri[0]->f->no);
+ for (uint i = 0; i < 3; i++) {
+ Gwn_PackedNormal vnor = GWN_normal_convert_i10_v3(bm_looptri[i]->v->no);
+ GWN_vertbuf_attr_set(vbo_nor, vnor_id, base_vert_idx + i, &vnor);
+ GWN_vertbuf_attr_set(vbo_nor, lnor_id, base_vert_idx + i, &lnor);
+ }
+ }
+
+ if (vbo_data) {
+ fflag = mesh_render_data_looptri_flag(rdata, bm_looptri[0]->f);
+ uint i_prev = 1, i = 2;
+ for (uint i_next = 0; i_next < 3; i_next++) {
+ vflag = mesh_render_data_vertex_flag(rdata, bm_looptri[i]->v);
+ EdgeDrawAttr eattr = {0};
+ if (bm_looptri[i_next] == bm_looptri[i_prev]->prev) {
+ mesh_render_data_edge_flag(rdata, bm_looptri[i_next]->e, &eattr);
+ }
+ eattr.v_flag = fflag | vflag;
+ GWN_vertbuf_attr_set(vbo_data, data_id, base_vert_idx + i, &eattr);
+
+ i_prev = i;
+ i = i_next;
+ }
+ }
+}
+
+static void add_overlay_loose_edge(
+ MeshRenderData *rdata, Gwn_VertBuf *vbo_pos, Gwn_VertBuf *vbo_nor, Gwn_VertBuf *vbo_data,
+ const unsigned int pos_id, const unsigned int vnor_id, const unsigned int data_id,
+ const BMEdge *eed, const int base_vert_idx)
+{
+ if (vbo_pos) {
+ /* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
+ if (rdata->edit_data && rdata->edit_data->vertexCos) {
+ for (uint i = 0; i < 2; i++) {
+ int vidx = BM_elem_index_get((&eed->v1)[i]);
+ const float *pos = rdata->edit_data->vertexCos[vidx];
+ GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
+ }
+ }
+ else {
+ for (int i = 0; i < 2; ++i) {
+ const float *pos = (&eed->v1)[i]->co;
+ GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx + i, pos);
+ }
+ }
+ }
+
+ if (vbo_nor) {
+ for (int i = 0; i < 2; ++i) {
+ Gwn_PackedNormal vnor = GWN_normal_convert_i10_v3((&eed->v1)[i]->no);
+ GWN_vertbuf_attr_set(vbo_nor, vnor_id, base_vert_idx + i, &vnor);
+ }
+ }
+
+ if (vbo_data) {
+ EdgeDrawAttr eattr = {0};
+ mesh_render_data_edge_flag(rdata, eed, &eattr);
+ for (int i = 0; i < 2; ++i) {
+ eattr.v_flag = mesh_render_data_vertex_flag(rdata, (&eed->v1)[i]);
+ GWN_vertbuf_attr_set(vbo_data, data_id, base_vert_idx + i, &eattr);
+ }
+ }
+}
+
+static void add_overlay_loose_vert(
+ MeshRenderData *rdata, Gwn_VertBuf *vbo_pos, Gwn_VertBuf *vbo_nor, Gwn_VertBuf *vbo_data,
+ const unsigned int pos_id, const unsigned int vnor_id, const unsigned int data_id,
+ const BMVert *eve, const int base_vert_idx)
+{
+ if (vbo_pos) {
+ /* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
+ if (rdata->edit_data && rdata->edit_data->vertexCos) {
+ int vidx = BM_elem_index_get(eve);
+ const float *pos = rdata->edit_data->vertexCos[vidx];
+ GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx, pos);
+ }
+ else {
+ const float *pos = eve->co;
+ GWN_vertbuf_attr_set(vbo_pos, pos_id, base_vert_idx, pos);
+ }
+ }
+
+ if (vbo_nor) {
+ Gwn_PackedNormal vnor = GWN_normal_convert_i10_v3(eve->no);
+ GWN_vertbuf_attr_set(vbo_nor, vnor_id, base_vert_idx, &vnor);
+ }
+
+ if (vbo_data) {
+ unsigned char vflag[4] = {0, 0, 0, 0};
+ vflag[0] = mesh_render_data_vertex_flag(rdata, eve);
+ GWN_vertbuf_attr_set(vbo_data, data_id, base_vert_idx, vflag);
+ }
+}
+
+/** \} */
+
+
+/* ---------------------------------------------------------------------- */
+
+/** \name Mesh Gwn_Batch Cache
+ * \{ */
+
+typedef struct MeshBatchCache {
+ Gwn_VertBuf *pos_in_order;
+ Gwn_VertBuf *nor_in_order;
+ Gwn_IndexBuf *edges_in_order;
+ Gwn_IndexBuf *triangles_in_order;
+
+ Gwn_Batch *all_verts;
+ Gwn_Batch *all_edges;
+ Gwn_Batch *all_triangles;
+
+ Gwn_VertBuf *pos_with_normals;
+ Gwn_VertBuf *tri_aligned_uv; /* Active UV layer (mloopuv) */
+
+ /**
+ * Other uses are all positions or loose elements.
+ * This stores all visible elements, needed for selection.
+ */
+ Gwn_VertBuf *ed_fcenter_pos_with_nor_and_sel;
+ Gwn_VertBuf *ed_edge_pos;
+ Gwn_VertBuf *ed_vert_pos;
+
+ Gwn_Batch *triangles_with_normals;
+
+ /* Skip hidden (depending on paint select mode) */
+ Gwn_Batch *triangles_with_weights;
+ Gwn_Batch *triangles_with_vert_colors;
+ /* Always skip hidden */
+ Gwn_Batch *triangles_with_select_mask;
+ Gwn_Batch *triangles_with_select_id;
+ uint triangles_with_select_id_offset;
+
+ Gwn_Batch *facedot_with_select_id; /* shares vbo with 'overlay_facedots' */
+ Gwn_Batch *edges_with_select_id;
+ Gwn_Batch *verts_with_select_id;
+
+ uint facedot_with_select_id_offset;
+ uint edges_with_select_id_offset;
+ uint verts_with_select_id_offset;
+
+ Gwn_Batch *points_with_normals;
+ Gwn_Batch *fancy_edges; /* owns its vertex buffer (not shared) */
+
+ /* Maybe have shaded_triangles_data split into pos_nor and uv_tangent
+ * to minimise data transfer for skinned mesh. */
+ Gwn_VertFormat shaded_triangles_format;
+ Gwn_VertBuf *shaded_triangles_data;
+ Gwn_IndexBuf **shaded_triangles_in_order;
+ Gwn_Batch **shaded_triangles;
+
+ /* Texture Paint.*/
+ /* per-texture batch */
+ Gwn_Batch **texpaint_triangles;
+ Gwn_Batch *texpaint_triangles_single;
+
+ /* Edit Cage Mesh buffers */
+ Gwn_VertBuf *ed_tri_pos;
+ Gwn_VertBuf *ed_tri_nor; /* LoopNor, VertNor */
+ Gwn_VertBuf *ed_tri_data;
+
+ Gwn_VertBuf *ed_ledge_pos;
+ Gwn_VertBuf *ed_ledge_nor; /* VertNor */
+ Gwn_VertBuf *ed_ledge_data;
+
+ Gwn_VertBuf *ed_lvert_pos;
+ Gwn_VertBuf *ed_lvert_nor; /* VertNor */
+ Gwn_VertBuf *ed_lvert_data;
+
+ Gwn_Batch *overlay_triangles;
+ Gwn_Batch *overlay_triangles_nor; /* GWN_PRIM_POINTS */
+ Gwn_Batch *overlay_loose_edges;
+ Gwn_Batch *overlay_loose_edges_nor; /* GWN_PRIM_POINTS */
+ Gwn_Batch *overlay_loose_verts;
+ Gwn_Batch *overlay_facedots;
+
+ Gwn_Batch *overlay_weight_faces;
+ Gwn_Batch *overlay_weight_verts;
+ Gwn_Batch *overlay_paint_edges;
+
+ /* arrays of bool uniform names (and value) that will be use to
+ * set srgb conversion for auto attribs.*/
+ char *auto_layer_names;
+ int *auto_layer_is_srgb;
+ int auto_layer_ct;
+
+ /* settings to determine if cache is invalid */
+ bool is_maybe_dirty;
+ bool is_dirty; /* Instantly invalidates cache, skipping mesh check */
+ int edge_len;
+ int tri_len;
+ int poly_len;
+ int vert_len;
+ int mat_len;
+ bool is_editmode;
+
+ /* XXX, only keep for as long as sculpt mode uses shaded drawing. */
+ bool is_sculpt_points_tag;
+} MeshBatchCache;
+
+/* Gwn_Batch cache management. */
+
+static bool mesh_batch_cache_valid(Mesh *me)
+{
+ MeshBatchCache *cache = me->runtime.batch_cache;
+
+ if (cache == NULL) {
+ return false;
+ }
+
+ /* XXX find another place for this */
+ if (cache->mat_len != mesh_render_mat_len_get(me)) {
+ cache->is_maybe_dirty = true;
+ }
+
+ if (cache->is_editmode != (me->edit_btmesh != NULL)) {
+ return false;
+ }
+
+ if (cache->is_dirty) {
+ return false;
+ }
+
+ if (cache->is_maybe_dirty == false) {
+ return true;
+ }
+ else {
+ if (cache->is_editmode) {
+ return false;
+ }
+ else if ((cache->vert_len != mesh_render_verts_len_get(me)) ||
+ (cache->edge_len != mesh_render_edges_len_get(me)) ||
+ (cache->tri_len != mesh_render_looptri_len_get(me)) ||
+ (cache->poly_len != mesh_render_polys_len_get(me)) ||
+ (cache->mat_len != mesh_render_mat_len_get(me)))
+ {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+static void mesh_batch_cache_init(Mesh *me)
+{
+ MeshBatchCache *cache = me->runtime.batch_cache;
+
+ if (!cache) {
+ cache = me->runtime.batch_cache = MEM_callocN(sizeof(*cache), __func__);
+ }
+ else {
+ memset(cache, 0, sizeof(*cache));
+ }
+
+ cache->is_editmode = me->edit_btmesh != NULL;
+
+ if (cache->is_editmode == false) {
+ cache->edge_len = mesh_render_edges_len_get(me);
+ cache->tri_len = mesh_render_looptri_len_get(me);
+ cache->poly_len = mesh_render_polys_len_get(me);
+ cache->vert_len = mesh_render_verts_len_get(me);
+ }
+
+ cache->mat_len = mesh_render_mat_len_get(me);
+
+ cache->is_maybe_dirty = false;
+ cache->is_dirty = false;
+}
+
+static MeshBatchCache *mesh_batch_cache_get(Mesh *me)
+{
+ if (!mesh_batch_cache_valid(me)) {
+ mesh_batch_cache_clear(me);
+ mesh_batch_cache_init(me);
+ }
+ return me->runtime.batch_cache;
+}
+
+void DRW_mesh_batch_cache_dirty(Mesh *me, int mode)
+{
+ MeshBatchCache *cache = me->runtime.batch_cache;
+ if (cache == NULL) {
+ return;
+ }
+ switch (mode) {
+ case BKE_MESH_BATCH_DIRTY_MAYBE_ALL:
+ cache->is_maybe_dirty = true;
+ break;
+ case BKE_MESH_BATCH_DIRTY_SELECT:
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_tri_data);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_ledge_data);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_lvert_data);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_fcenter_pos_with_nor_and_sel); /* Contains select flag */
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_edge_pos);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_vert_pos);
+
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_triangles);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_loose_verts);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_loose_edges);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_facedots);
+ /* Edit mode selection. */
+ GWN_BATCH_DISCARD_SAFE(cache->facedot_with_select_id);
+ GWN_BATCH_DISCARD_SAFE(cache->edges_with_select_id);
+ GWN_BATCH_DISCARD_SAFE(cache->verts_with_select_id);
+ break;
+ case BKE_MESH_BATCH_DIRTY_ALL:
+ cache->is_dirty = true;
+ break;
+ case BKE_MESH_BATCH_DIRTY_SHADING:
+ /* TODO: This should only update UV and tangent data,
+ * and not free the entire cache. */
+ cache->is_dirty = true;
+ break;
+ case BKE_MESH_BATCH_DIRTY_SCULPT_COORDS:
+ cache->is_sculpt_points_tag = true;
+ break;
+ default:
+ BLI_assert(0);
+ }
+}
+
+/**
+ * This only clear the batches associated to the given vertex buffer.
+ **/
+static void mesh_batch_cache_clear_selective(Mesh *me, Gwn_VertBuf *vert)
+{
+ MeshBatchCache *cache = me->runtime.batch_cache;
+ if (!cache) {
+ return;
+ }
+
+ BLI_assert(vert != NULL);
+
+ if (cache->pos_with_normals == vert) {
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_normals);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_weights);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_vert_colors);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_select_id);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_select_mask);
+ GWN_BATCH_DISCARD_SAFE(cache->points_with_normals);
+ if (cache->shaded_triangles) {
+ for (int i = 0; i < cache->mat_len; ++i) {
+ GWN_BATCH_DISCARD_SAFE(cache->shaded_triangles[i]);
+ }
+ }
+ MEM_SAFE_FREE(cache->shaded_triangles);
+ if (cache->texpaint_triangles) {
+ for (int i = 0; i < cache->mat_len; ++i) {
+ GWN_BATCH_DISCARD_SAFE(cache->texpaint_triangles[i]);
+ }
+ }
+ MEM_SAFE_FREE(cache->texpaint_triangles);
+ GWN_BATCH_DISCARD_SAFE(cache->texpaint_triangles_single);
+ }
+ /* TODO: add the other ones if needed. */
+ else {
+ /* Does not match any vertbuf in the batch cache! */
+ BLI_assert(0);
+ }
+}
+
+static void mesh_batch_cache_clear(Mesh *me)
+{
+ MeshBatchCache *cache = me->runtime.batch_cache;
+ if (!cache) {
+ return;
+ }
+
+ GWN_BATCH_DISCARD_SAFE(cache->all_verts);
+ GWN_BATCH_DISCARD_SAFE(cache->all_edges);
+ GWN_BATCH_DISCARD_SAFE(cache->all_triangles);
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->pos_in_order);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->edges_in_order);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->triangles_in_order);
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_tri_pos);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_tri_nor);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_tri_data);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_ledge_pos);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_ledge_nor);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_ledge_data);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_lvert_pos);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_lvert_nor);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_lvert_data);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_triangles);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_triangles_nor);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_loose_verts);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_loose_edges);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_loose_edges_nor);
+
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_weight_faces);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_weight_verts);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_paint_edges);
+ GWN_BATCH_DISCARD_SAFE(cache->overlay_facedots);
+
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_normals);
+ GWN_BATCH_DISCARD_SAFE(cache->points_with_normals);
+ GWN_VERTBUF_DISCARD_SAFE(cache->pos_with_normals);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_weights);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_vert_colors);
+ GWN_VERTBUF_DISCARD_SAFE(cache->tri_aligned_uv);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_fcenter_pos_with_nor_and_sel);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_edge_pos);
+ GWN_VERTBUF_DISCARD_SAFE(cache->ed_vert_pos);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_select_mask);
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_select_id);
+ GWN_BATCH_DISCARD_SAFE(cache->facedot_with_select_id);
+ GWN_BATCH_DISCARD_SAFE(cache->edges_with_select_id);
+ GWN_BATCH_DISCARD_SAFE(cache->verts_with_select_id);
+
+ GWN_BATCH_DISCARD_SAFE(cache->fancy_edges);
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->shaded_triangles_data);
+ if (cache->shaded_triangles_in_order) {
+ for (int i = 0; i < cache->mat_len; ++i) {
+ GWN_INDEXBUF_DISCARD_SAFE(cache->shaded_triangles_in_order[i]);
+ }
+ }
+ if (cache->shaded_triangles) {
+ for (int i = 0; i < cache->mat_len; ++i) {
+ GWN_BATCH_DISCARD_SAFE(cache->shaded_triangles[i]);
+ }
+ }
+
+ MEM_SAFE_FREE(cache->shaded_triangles_in_order);
+ MEM_SAFE_FREE(cache->shaded_triangles);
+
+ MEM_SAFE_FREE(cache->auto_layer_names);
+ MEM_SAFE_FREE(cache->auto_layer_is_srgb);
+
+ if (cache->texpaint_triangles) {
+ for (int i = 0; i < cache->mat_len; ++i) {
+ GWN_BATCH_DISCARD_SAFE(cache->texpaint_triangles[i]);
+ }
+ }
+ MEM_SAFE_FREE(cache->texpaint_triangles);
+
+ GWN_BATCH_DISCARD_SAFE(cache->texpaint_triangles_single);
+
+}
+
+void DRW_mesh_batch_cache_free(Mesh *me)
+{
+ mesh_batch_cache_clear(me);
+ MEM_SAFE_FREE(me->runtime.batch_cache);
+}
+
+/* Gwn_Batch cache usage. */
+
+static Gwn_VertBuf *mesh_batch_cache_get_tri_shading_data(MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+#define USE_COMP_MESH_DATA
+
+ if (cache->shaded_triangles_data == NULL) {
+ const uint uv_len = rdata->cd.layers.uv_len;
+ const uint tangent_len = rdata->cd.layers.tangent_len;
+ const uint vcol_len = rdata->cd.layers.vcol_len;
+ const uint layers_combined_len = uv_len + vcol_len + tangent_len;
+
+ if (layers_combined_len == 0) {
+ return NULL;
+ }
+
+ Gwn_VertFormat *format = &cache->shaded_triangles_format;
+
+ GWN_vertformat_clear(format);
+
+ /* initialize vertex format */
+ uint *layers_combined_id = BLI_array_alloca(layers_combined_id, layers_combined_len);
+ uint *uv_id = layers_combined_id;
+ uint *tangent_id = uv_id + uv_len;
+ uint *vcol_id = tangent_id + tangent_len;
+
+ /* Not needed, just for sanity. */
+ if (uv_len == 0) { uv_id = NULL; }
+ if (tangent_len == 0) { tangent_id = NULL; }
+ if (vcol_len == 0) { vcol_id = NULL; }
+
+ /* Count number of auto layer and allocate big enough name buffer. */
+ uint auto_names_len = 0;
+ uint auto_ofs = 0;
+ uint auto_id = 0;
+ cache->auto_layer_ct = 0;
+ for (uint i = 0; i < uv_len; i++) {
+ const char *attrib_name = mesh_render_data_uv_auto_layer_uuid_get(rdata, i);
+ auto_names_len += strlen(attrib_name) + 2; /* include null terminator and b prefix. */
+ cache->auto_layer_ct++;
+ }
+ for (uint i = 0; i < vcol_len; i++) {
+ if (rdata->cd.layers.auto_vcol[i]) {
+ const char *attrib_name = mesh_render_data_vcol_auto_layer_uuid_get(rdata, i);
+ auto_names_len += strlen(attrib_name) + 2; /* include null terminator and b prefix. */
+ cache->auto_layer_ct++;
+ }
+ }
+ auto_names_len += 1; /* add an ultimate '\0' terminator */
+ cache->auto_layer_names = MEM_callocN(auto_names_len * sizeof(char), "Auto layer name buf");
+ cache->auto_layer_is_srgb = MEM_mallocN(cache->auto_layer_ct * sizeof(int), "Auto layer value buf");
+
+ for (uint i = 0; i < uv_len; i++) {
+ /* UV */
+ const char *attrib_name = mesh_render_data_uv_layer_uuid_get(rdata, i);
+#if defined(USE_COMP_MESH_DATA) && 0 /* these are clamped. Maybe use them as an option in the future */
+ uv_id[i] = GWN_vertformat_attr_add(format, attrib_name, GWN_COMP_I16, 2, GWN_FETCH_INT_TO_FLOAT_UNIT);
+#else
+ uv_id[i] = GWN_vertformat_attr_add(format, attrib_name, GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+#endif
+
+ /* Auto Name */
+ attrib_name = mesh_render_data_uv_auto_layer_uuid_get(rdata, i);
+ GWN_vertformat_alias_add(format, attrib_name);
+
+ /* +1 include null terminator. */
+ auto_ofs += 1 + BLI_snprintf_rlen(cache->auto_layer_names + auto_ofs, auto_names_len - auto_ofs, "b%s", attrib_name);
+ cache->auto_layer_is_srgb[auto_id++] = 0; /* tag as not srgb */
+
+ if (i == rdata->cd.layers.uv_active) {
+ GWN_vertformat_alias_add(format, "u");
+ }
+ }
+
+ for (uint i = 0; i < tangent_len; i++) {
+ const char *attrib_name = mesh_render_data_tangent_layer_uuid_get(rdata, i);
+ /* WATCH IT : only specifying 3 component instead of 4 (4th is sign).
+ * That may cause some problem but I could not make it to fail (fclem) */
+#ifdef USE_COMP_MESH_DATA
+ /* Tangents need more precision than 10_10_10 */
+ tangent_id[i] = GWN_vertformat_attr_add(format, attrib_name, GWN_COMP_I16, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+#else
+ tangent_id[i] = GWN_vertformat_attr_add(format, attrib_name, GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+#endif
+
+ if (i == rdata->cd.layers.tangent_active) {
+ GWN_vertformat_alias_add(format, "t");
+ }
+ }
+
+ for (uint i = 0; i < vcol_len; i++) {
+ const char *attrib_name = mesh_render_data_vcol_layer_uuid_get(rdata, i);
+ vcol_id[i] = GWN_vertformat_attr_add(format, attrib_name, GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ /* Auto layer */
+ if (rdata->cd.layers.auto_vcol[i]) {
+ attrib_name = mesh_render_data_vcol_auto_layer_uuid_get(rdata, i);
+
+ GWN_vertformat_alias_add(format, attrib_name);
+
+ /* +1 include null terminator. */
+ auto_ofs += 1 + BLI_snprintf_rlen(cache->auto_layer_names + auto_ofs, auto_names_len - auto_ofs, "b%s", attrib_name);
+ cache->auto_layer_is_srgb[auto_id++] = 1; /* tag as srgb */
+ }
+
+ if (i == rdata->cd.layers.vcol_active) {
+ GWN_vertformat_alias_add(format, "c");
+ }
+ }
+
+ const uint tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ Gwn_VertBuf *vbo = cache->shaded_triangles_data = GWN_vertbuf_create_with_format(format);
+
+ const int vbo_len_capacity = tri_len * 3;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ Gwn_VertBufRaw *layers_combined_step = BLI_array_alloca(layers_combined_step, layers_combined_len);
+
+ Gwn_VertBufRaw *uv_step = layers_combined_step;
+ Gwn_VertBufRaw *tangent_step = uv_step + uv_len;
+ Gwn_VertBufRaw *vcol_step = tangent_step + tangent_len;
+
+ /* Not needed, just for sanity. */
+ if (uv_len == 0) { uv_step = NULL; }
+ if (tangent_len == 0) { tangent_step = NULL; }
+ if (vcol_len == 0) { vcol_step = NULL; }
+
+ for (uint i = 0; i < uv_len; i++) {
+ GWN_vertbuf_attr_get_raw_data(vbo, uv_id[i], &uv_step[i]);
+ }
+ for (uint i = 0; i < tangent_len; i++) {
+ GWN_vertbuf_attr_get_raw_data(vbo, tangent_id[i], &tangent_step[i]);
+ }
+ for (uint i = 0; i < vcol_len; i++) {
+ GWN_vertbuf_attr_get_raw_data(vbo, vcol_id[i], &vcol_step[i]);
+ }
+
+ /* TODO deduplicate all verts and make use of Gwn_IndexBuf in
+ * mesh_batch_cache_get_triangles_in_order_split_by_material. */
+ if (rdata->edit_bmesh) {
+ for (uint i = 0; i < tri_len; i++) {
+ const BMLoop **bm_looptri = (const BMLoop **)rdata->edit_bmesh->looptris[i];
+ if (BM_elem_flag_test(bm_looptri[0]->f, BM_ELEM_HIDDEN)) {
+ continue;
+ }
+ /* UVs */
+ for (uint j = 0; j < uv_len; j++) {
+ const uint layer_offset = rdata->cd.offset.uv[j];
+ for (uint t = 0; t < 3; t++) {
+ const float *elem = ((MLoopUV *)BM_ELEM_CD_GET_VOID_P(bm_looptri[t], layer_offset))->uv;
+ copy_v2_v2(GWN_vertbuf_raw_step(&uv_step[j]), elem);
+ }
+ }
+ /* TANGENTs */
+ for (uint j = 0; j < tangent_len; j++) {
+ float (*layer_data)[4] = rdata->cd.layers.tangent[j];
+ for (uint t = 0; t < 3; t++) {
+ const float *elem = layer_data[BM_elem_index_get(bm_looptri[t])];
+ normal_float_to_short_v3(GWN_vertbuf_raw_step(&tangent_step[j]), elem);
+ }
+ }
+ /* VCOLs */
+ for (uint j = 0; j < vcol_len; j++) {
+ const uint layer_offset = rdata->cd.offset.vcol[j];
+ for (uint t = 0; t < 3; t++) {
+ const uchar *elem = &((MLoopCol *)BM_ELEM_CD_GET_VOID_P(bm_looptri[t], layer_offset))->r;
+ copy_v3_v3_uchar(GWN_vertbuf_raw_step(&vcol_step[j]), elem);
+ }
+ }
+ }
+ }
+ else {
+ for (uint i = 0; i < tri_len; i++) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+
+ /* UVs */
+ for (uint j = 0; j < uv_len; j++) {
+ const MLoopUV *layer_data = rdata->cd.layers.uv[j];
+ for (uint t = 0; t < 3; t++) {
+ const float *elem = layer_data[mlt->tri[t]].uv;
+ copy_v2_v2(GWN_vertbuf_raw_step(&uv_step[j]), elem);
+ }
+ }
+ /* TANGENTs */
+ for (uint j = 0; j < tangent_len; j++) {
+ float (*layer_data)[4] = rdata->cd.layers.tangent[j];
+ for (uint t = 0; t < 3; t++) {
+ const float *elem = layer_data[mlt->tri[t]];
+#ifdef USE_COMP_MESH_DATA
+ normal_float_to_short_v3(GWN_vertbuf_raw_step(&tangent_step[j]), elem);
+#else
+ copy_v3_v3(GWN_vertbuf_raw_step(&tangent_step[j]), elem);
+#endif
+ }
+ }
+ /* VCOLs */
+ for (uint j = 0; j < vcol_len; j++) {
+ const MLoopCol *layer_data = rdata->cd.layers.vcol[j];
+ for (uint t = 0; t < 3; t++) {
+ const uchar *elem = &layer_data[mlt->tri[t]].r;
+ copy_v3_v3_uchar(GWN_vertbuf_raw_step(&vcol_step[j]), elem);
+ }
+ }
+ }
+ }
+
+ vbo_len_used = GWN_vertbuf_raw_used(&layers_combined_step[0]);
+
+#ifndef NDEBUG
+ /* Check all layers are write aligned. */
+ if (layers_combined_len > 1) {
+ for (uint i = 1; i < layers_combined_len; i++) {
+ BLI_assert(vbo_len_used == GWN_vertbuf_raw_used(&layers_combined_step[i]));
+ }
+ }
+#endif
+
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+#undef USE_COMP_MESH_DATA
+
+ return cache->shaded_triangles_data;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_tri_uv_active(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_LOOPUV));
+ BLI_assert(rdata->edit_bmesh == NULL);
+
+ if (cache->tri_aligned_uv == NULL) {
+ unsigned int vidx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint uv; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.uv = GWN_vertformat_attr_add(&format, "uv", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ Gwn_VertBuf *vbo = cache->tri_aligned_uv = GWN_vertbuf_create_with_format(&format);
+
+ const int vbo_len_capacity = tri_len * 3;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ const MLoopUV *mloopuv = rdata->mloopuv;
+
+ for (int i = 0; i < tri_len; i++) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+ GWN_vertbuf_attr_set(vbo, attr_id.uv, vidx++, mloopuv[mlt->tri[0]].uv);
+ GWN_vertbuf_attr_set(vbo, attr_id.uv, vidx++, mloopuv[mlt->tri[1]].uv);
+ GWN_vertbuf_attr_set(vbo, attr_id.uv, vidx++, mloopuv[mlt->tri[2]].uv);
+ }
+ vbo_len_used = vidx;
+
+ BLI_assert(vbo_len_capacity == vbo_len_used);
+ UNUSED_VARS_NDEBUG(vbo_len_used);
+ }
+
+ return cache->tri_aligned_uv;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_tri_pos_and_normals_ex(
+ MeshRenderData *rdata, const bool use_hide,
+ Gwn_VertBuf **r_vbo)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+
+ if (*r_vbo == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, nor; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_I10, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ Gwn_VertBuf *vbo = *r_vbo = GWN_vertbuf_create_with_format(&format);
+
+ const int vbo_len_capacity = tri_len * 3;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ Gwn_VertBufRaw pos_step, nor_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step);
+ GWN_vertbuf_attr_get_raw_data(vbo, attr_id.nor, &nor_step);
+
+ float (*lnors)[3] = rdata->loop_normals;
+
+ if (rdata->edit_bmesh) {
+ Gwn_PackedNormal *pnors_pack, *vnors_pack;
+
+ if (lnors == NULL) {
+ mesh_render_data_ensure_poly_normals_pack(rdata);
+ mesh_render_data_ensure_vert_normals_pack(rdata);
+
+ pnors_pack = rdata->poly_normals_pack;
+ vnors_pack = rdata->vert_normals_pack;
+ }
+
+ for (int i = 0; i < tri_len; i++) {
+ const BMLoop **bm_looptri = (const BMLoop **)rdata->edit_bmesh->looptris[i];
+ const BMFace *bm_face = bm_looptri[0]->f;
+
+ /* use_hide always for edit-mode */
+ if (BM_elem_flag_test(bm_face, BM_ELEM_HIDDEN)) {
+ continue;
+ }
+
+ if (lnors) {
+ for (uint t = 0; t < 3; t++) {
+ const float *nor = lnors[BM_elem_index_get(bm_looptri[t])];
+ *((Gwn_PackedNormal *)GWN_vertbuf_raw_step(&nor_step)) = GWN_normal_convert_i10_v3(nor);
+ }
+ }
+ else if (BM_elem_flag_test(bm_face, BM_ELEM_SMOOTH)) {
+ for (uint t = 0; t < 3; t++) {
+ *((Gwn_PackedNormal *)GWN_vertbuf_raw_step(&nor_step)) = vnors_pack[BM_elem_index_get(bm_looptri[t]->v)];
+ }
+ }
+ else {
+ const Gwn_PackedNormal *snor_pack = &pnors_pack[BM_elem_index_get(bm_face)];
+ for (uint t = 0; t < 3; t++) {
+ *((Gwn_PackedNormal *)GWN_vertbuf_raw_step(&nor_step)) = *snor_pack;
+ }
+ }
+
+ /* TODO(sybren): deduplicate this and all the other places it's pasted to in this file. */
+ if (rdata->edit_data && rdata->edit_data->vertexCos) {
+ for (uint t = 0; t < 3; t++) {
+ int vidx = BM_elem_index_get(bm_looptri[t]->v);
+ const float *pos = rdata->edit_data->vertexCos[vidx];
+ copy_v3_v3(GWN_vertbuf_raw_step(&pos_step), pos);
+ }
+ }
+ else {
+ for (uint t = 0; t < 3; t++) {
+ copy_v3_v3(GWN_vertbuf_raw_step(&pos_step), bm_looptri[t]->v->co);
+ }
+ }
+ }
+ }
+ else {
+ if (lnors == NULL) {
+ /* Use normals from vertex. */
+ mesh_render_data_ensure_poly_normals_pack(rdata);
+ }
+
+ for (int i = 0; i < tri_len; i++) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+ const MPoly *mp = &rdata->mpoly[mlt->poly];
+
+ if (use_hide && (mp->flag & ME_HIDE)) {
+ continue;
+ }
+
+ const uint vtri[3] = {
+ rdata->mloop[mlt->tri[0]].v,
+ rdata->mloop[mlt->tri[1]].v,
+ rdata->mloop[mlt->tri[2]].v,
+ };
+
+ if (lnors) {
+ for (uint t = 0; t < 3; t++) {
+ const float *nor = lnors[mlt->tri[t]];
+ *((Gwn_PackedNormal *)GWN_vertbuf_raw_step(&nor_step)) = GWN_normal_convert_i10_v3(nor);
+ }
+ }
+ else if (mp->flag & ME_SMOOTH) {
+ for (uint t = 0; t < 3; t++) {
+ const MVert *mv = &rdata->mvert[vtri[t]];
+ *((Gwn_PackedNormal *)GWN_vertbuf_raw_step(&nor_step)) = GWN_normal_convert_i10_s3(mv->no);
+ }
+ }
+ else {
+ const Gwn_PackedNormal *pnors_pack = &rdata->poly_normals_pack[mlt->poly];
+ for (uint t = 0; t < 3; t++) {
+ *((Gwn_PackedNormal *)GWN_vertbuf_raw_step(&nor_step)) = *pnors_pack;
+ }
+ }
+
+ for (uint t = 0; t < 3; t++) {
+ const MVert *mv = &rdata->mvert[vtri[t]];
+ copy_v3_v3(GWN_vertbuf_raw_step(&pos_step), mv->co);
+ }
+ }
+ }
+
+ vbo_len_used = GWN_vertbuf_raw_used(&pos_step);
+ BLI_assert(vbo_len_used == GWN_vertbuf_raw_used(&nor_step));
+
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+ return *r_vbo;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_tri_pos_and_normals(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ return mesh_batch_cache_get_tri_pos_and_normals_ex(
+ rdata, false,
+ &cache->pos_with_normals);
+}
+static Gwn_VertBuf *mesh_create_tri_pos_and_normals_visible_only(
+ MeshRenderData *rdata)
+{
+ Gwn_VertBuf *vbo_dummy = NULL;
+ return mesh_batch_cache_get_tri_pos_and_normals_ex(
+ rdata, true,
+ &vbo_dummy);
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_facedot_pos_with_normals_and_flag(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+
+ if (cache->ed_fcenter_pos_with_nor_and_sel == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, data; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.data = GWN_vertformat_attr_add(&format, "norAndFlag", GWN_COMP_I10, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+
+ const int vbo_len_capacity = mesh_render_data_polys_len_get(rdata);
+ int vidx = 0;
+
+ Gwn_VertBuf *vbo = cache->ed_fcenter_pos_with_nor_and_sel = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ for (int i = 0; i < vbo_len_capacity; ++i) {
+ float pcenter[3], pnor[3];
+ bool selected = false;
+
+ if (mesh_render_data_pnors_pcenter_select_get(rdata, i, pnor, pcenter, &selected)) {
+
+ Gwn_PackedNormal nor = { .x = 0, .y = 0, .z = -511 };
+ nor = GWN_normal_convert_i10_v3(pnor);
+ nor.w = selected ? 1 : 0;
+ GWN_vertbuf_attr_set(vbo, attr_id.data, vidx, &nor);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx, pcenter);
+
+ vidx += 1;
+ }
+ }
+ const int vbo_len_used = vidx;
+ BLI_assert(vbo_len_used <= vbo_len_capacity);
+ if (vbo_len_used != vbo_len_capacity) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+ return cache->ed_fcenter_pos_with_nor_and_sel;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_edges_visible(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE));
+
+ if (cache->ed_edge_pos == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, data; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ const int vbo_len_capacity = mesh_render_data_edges_len_get(rdata) * 2;
+ int vidx = 0;
+
+ Gwn_VertBuf *vbo = cache->ed_edge_pos = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter iter;
+ BMEdge *eed;
+
+ BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx, eed->v1->co);
+ vidx += 1;
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx, eed->v2->co);
+ vidx += 1;
+ }
+ }
+ }
+ else {
+ /* not yet done! */
+ BLI_assert(0);
+ }
+ const int vbo_len_used = vidx;
+ if (vbo_len_used != vbo_len_capacity) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ UNUSED_VARS_NDEBUG(vbo_len_used);
+ }
+
+ return cache->ed_edge_pos;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_verts_visible(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_vert_pos == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, data; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ const int vbo_len_capacity = mesh_render_data_verts_len_get(rdata);
+ uint vidx = 0;
+
+ Gwn_VertBuf *vbo = cache->ed_vert_pos = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter iter;
+ BMVert *eve;
+
+ BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
+ if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx, eve->co);
+ vidx += 1;
+ }
+ }
+ }
+ else {
+ for (int i = 0; i < vbo_len_capacity; i++) {
+ const MVert *mv = &rdata->mvert[i];
+ if (!(mv->flag & ME_HIDE)) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx, mv->co);
+ vidx += 1;
+ }
+ }
+ }
+ const uint vbo_len_used = vidx;
+ if (vbo_len_used != vbo_len_capacity) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+
+ UNUSED_VARS_NDEBUG(vbo_len_used);
+ }
+
+ return cache->ed_vert_pos;
+}
+
+static Gwn_VertBuf *mesh_create_facedot_select_id(
+ MeshRenderData *rdata, uint select_id_offset)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+
+ Gwn_VertBuf *vbo;
+ {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, col; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_I32, 1, GWN_FETCH_INT);
+ }
+
+ const int vbo_len_capacity = mesh_render_data_polys_len_get(rdata);
+ int vidx = 0;
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ uint select_index = select_id_offset;
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter iter;
+ BMEdge *efa;
+
+ BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ int select_id;
+ GPU_select_index_get(select_index, &select_id);
+ GWN_vertbuf_attr_set(vbo, attr_id.col, vidx, &select_id);
+ vidx += 1;
+ }
+ select_index += 1;
+ }
+ }
+ else {
+ /* not yet done! */
+ BLI_assert(0);
+ }
+ const int vbo_len_used = vidx;
+ if (vbo_len_used != vbo_len_capacity) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+ return vbo;
+}
+
+static Gwn_VertBuf *mesh_create_edges_select_id(
+ MeshRenderData *rdata, uint select_id_offset)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE));
+
+ Gwn_VertBuf *vbo;
+ {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, col; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_I32, 1, GWN_FETCH_INT);
+ }
+
+ const int vbo_len_capacity = mesh_render_data_edges_len_get(rdata) * 2;
+ int vidx = 0;
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ uint select_index = select_id_offset;
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter iter;
+ BMEdge *eed;
+
+ BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ int select_id;
+ GPU_select_index_get(select_index, &select_id);
+ GWN_vertbuf_attr_set(vbo, attr_id.col, vidx, &select_id);
+ vidx += 1;
+ GWN_vertbuf_attr_set(vbo, attr_id.col, vidx, &select_id);
+ vidx += 1;
+ }
+ select_index += 1;
+ }
+ }
+ else {
+ /* not yet done! */
+ BLI_assert(0);
+ }
+ const int vbo_len_used = vidx;
+ if (vbo_len_used != vbo_len_capacity) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+ return vbo;
+}
+
+static Gwn_VertBuf *mesh_create_verts_select_id(
+ MeshRenderData *rdata, uint select_id_offset)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+
+ Gwn_VertBuf *vbo;
+ {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, col; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_I32, 1, GWN_FETCH_INT);
+ }
+
+ const int vbo_len_capacity = mesh_render_data_verts_len_get(rdata);
+ int vidx = 0;
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ uint select_index = select_id_offset;
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter iter;
+ BMVert *eve;
+
+ BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
+ if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+ int select_id;
+ GPU_select_index_get(select_index, &select_id);
+ GWN_vertbuf_attr_set(vbo, attr_id.col, vidx, &select_id);
+ vidx += 1;
+ }
+ select_index += 1;
+ }
+ }
+ else {
+ for (int i = 0; i < vbo_len_capacity; i++) {
+ const MVert *mv = &rdata->mvert[i];
+ if (!(mv->flag & ME_HIDE)) {
+ int select_id;
+ GPU_select_index_get(select_index, &select_id);
+ GWN_vertbuf_attr_set(vbo, attr_id.col, vidx, &select_id);
+ vidx += 1;
+ }
+ select_index += 1;
+ }
+ }
+ const int vbo_len_used = vidx;
+ if (vbo_len_used != vbo_len_capacity) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+ return vbo;
+}
+
+static Gwn_VertBuf *mesh_create_tri_weights(
+ MeshRenderData *rdata, bool use_hide, int defgroup)
+{
+ BLI_assert(
+ rdata->types &
+ (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_DVERT));
+
+ Gwn_VertBuf *vbo;
+ {
+ unsigned int cidx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint col; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+ const int vbo_len_capacity = tri_len * 3;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ mesh_render_data_ensure_vert_weight_color(rdata, defgroup);
+ const float (*vert_weight_color)[3] = rdata->vert_weight_color;
+
+ if (rdata->edit_bmesh) {
+ for (int i = 0; i < tri_len; i++) {
+ const BMLoop **ltri = (const BMLoop **)rdata->edit_bmesh->looptris[i];
+ /* Assume 'use_hide' */
+ if (!BM_elem_flag_test(ltri[0]->f, BM_ELEM_HIDDEN)) {
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ const int v_index = BM_elem_index_get(ltri[tri_corner]->v);
+ GWN_vertbuf_attr_set(vbo, attr_id.col, cidx++, vert_weight_color[v_index]);
+ }
+ }
+ }
+ }
+ else {
+ for (int i = 0; i < tri_len; i++) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+ if (!(use_hide && (rdata->mpoly[mlt->poly].flag & ME_HIDE))) {
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ const uint v_index = rdata->mloop[mlt->tri[tri_corner]].v;
+ GWN_vertbuf_attr_set(vbo, attr_id.col, cidx++, vert_weight_color[v_index]);
+ }
+ }
+ }
+ }
+ vbo_len_used = cidx;
+
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+ return vbo;
+}
+
+static Gwn_VertBuf *mesh_create_tri_vert_colors(
+ MeshRenderData *rdata, bool use_hide)
+{
+ BLI_assert(
+ rdata->types &
+ (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPCOL));
+
+ Gwn_VertBuf *vbo;
+ {
+ unsigned int cidx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint col; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+
+ const uint vbo_len_capacity = tri_len * 3;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ mesh_render_data_ensure_vert_color(rdata);
+ const char (*vert_color)[3] = rdata->vert_color;
+
+ if (rdata->edit_bmesh) {
+ for (int i = 0; i < tri_len; i++) {
+ const BMLoop **ltri = (const BMLoop **)rdata->edit_bmesh->looptris[i];
+ /* Assume 'use_hide' */
+ if (!BM_elem_flag_test(ltri[0]->f, BM_ELEM_HIDDEN)) {
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ const int l_index = BM_elem_index_get(ltri[tri_corner]);
+ GWN_vertbuf_attr_set(vbo, attr_id.col, cidx++, vert_color[l_index]);
+ }
+ }
+ }
+ }
+ else {
+ for (int i = 0; i < tri_len; i++) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+ if (!(use_hide && (rdata->mpoly[mlt->poly].flag & ME_HIDE))) {
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ const uint l_index = mlt->tri[tri_corner];
+ GWN_vertbuf_attr_set(vbo, attr_id.col, cidx++, vert_color[l_index]);
+ }
+ }
+ }
+ }
+ const uint vbo_len_used = cidx;
+
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+ return vbo;
+}
+
+static Gwn_VertBuf *mesh_create_tri_select_id(
+ MeshRenderData *rdata, bool use_hide, uint select_id_offset)
+{
+ BLI_assert(
+ rdata->types &
+ (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY));
+
+ Gwn_VertBuf *vbo;
+ {
+ unsigned int cidx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint col; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_I32, 1, GWN_FETCH_INT);
+ }
+
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+
+ const int vbo_len_capacity = tri_len * 3;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ if (rdata->edit_bmesh) {
+ for (int i = 0; i < tri_len; i++) {
+ const BMLoop **ltri = (const BMLoop **)rdata->edit_bmesh->looptris[i];
+ /* Assume 'use_hide' */
+ if (!BM_elem_flag_test(ltri[0]->f, BM_ELEM_HIDDEN)) {
+ const int poly_index = BM_elem_index_get(ltri[0]->f);
+ int select_id;
+ GPU_select_index_get(poly_index + select_id_offset, &select_id);
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.col, cidx++, &select_id);
+ }
+ }
+ }
+ }
+ else {
+ for (int i = 0; i < tri_len; i++) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+ const int poly_index = mlt->poly;
+ if (!(use_hide && (rdata->mpoly[poly_index].flag & ME_HIDE))) {
+ int select_id;
+ GPU_select_index_get(poly_index + select_id_offset, &select_id);
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ GWN_vertbuf_attr_set(vbo, attr_id.col, cidx++, &select_id);
+ }
+ }
+ }
+ }
+ vbo_len_used = cidx;
+
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+ return vbo;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_vert_pos_and_nor_in_order(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->pos_in_order == NULL) {
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, nor; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_I16, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+
+ Gwn_VertBuf *vbo = cache->pos_in_order = GWN_vertbuf_create_with_format(&format);
+ const int vbo_len_capacity = mesh_render_data_verts_len_get(rdata);
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter iter;
+ BMVert *eve;
+ uint i;
+
+ BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, i) {
+ static short no_short[3];
+ normal_float_to_short_v3(no_short, eve->no);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i, eve->co);
+ GWN_vertbuf_attr_set(vbo, attr_id.nor, i, no_short);
+ }
+ BLI_assert(i == vbo_len_capacity);
+ }
+ else {
+ for (int i = 0; i < vbo_len_capacity; ++i) {
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, i, rdata->mvert[i].co);
+ GWN_vertbuf_attr_set(vbo, attr_id.nor, i, rdata->mvert[i].no);
+ }
+ }
+ }
+
+ return cache->pos_in_order;
+}
+
+static Gwn_VertFormat *edit_mesh_overlay_pos_format(unsigned int *r_pos_id)
+{
+ static Gwn_VertFormat format_pos = { 0 };
+ static unsigned pos_id;
+ if (format_pos.attrib_ct == 0) {
+ pos_id = GWN_vertformat_attr_add(&format_pos, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+ *r_pos_id = pos_id;
+ return &format_pos;
+}
+
+static Gwn_VertFormat *edit_mesh_overlay_nor_format(unsigned int *r_vnor_id, unsigned int *r_lnor_id)
+{
+ static Gwn_VertFormat format_nor = { 0 };
+ static Gwn_VertFormat format_nor_loop = { 0 };
+ static unsigned vnor_id, vnor_loop_id, lnor_id;
+ if (format_nor.attrib_ct == 0) {
+ vnor_id = GWN_vertformat_attr_add(&format_nor, "vnor", GWN_COMP_I10, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ vnor_loop_id = GWN_vertformat_attr_add(&format_nor_loop, "vnor", GWN_COMP_I10, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ lnor_id = GWN_vertformat_attr_add(&format_nor_loop, "lnor", GWN_COMP_I10, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+ if (r_lnor_id) {
+ *r_vnor_id = vnor_loop_id;
+ *r_lnor_id = lnor_id;
+ return &format_nor_loop;
+ }
+ else {
+ *r_vnor_id = vnor_id;
+ return &format_nor;
+ }
+}
+
+static Gwn_VertFormat *edit_mesh_overlay_data_format(unsigned int *r_data_id)
+{
+ static Gwn_VertFormat format_flag = { 0 };
+ static unsigned data_id;
+ if (format_flag.attrib_ct == 0) {
+ data_id = GWN_vertformat_attr_add(&format_flag, "data", GWN_COMP_U8, 4, GWN_FETCH_INT);
+ }
+ *r_data_id = data_id;
+ return &format_flag;
+}
+
+static void mesh_batch_cache_create_overlay_tri_buffers(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI));
+
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ const int vbo_len_capacity = tri_len * 3;
+ int vbo_len_used = 0;
+
+ /* Positions */
+ Gwn_VertBuf *vbo_pos = NULL;
+ static struct { uint pos, vnor, lnor, data; } attr_id;
+ if (cache->ed_tri_pos == NULL) {
+ vbo_pos = cache->ed_tri_pos =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_pos_format(&attr_id.pos));
+ GWN_vertbuf_data_alloc(vbo_pos, vbo_len_capacity);
+ }
+
+ /* Normals */
+ Gwn_VertBuf *vbo_nor = NULL;
+ if (cache->ed_tri_nor == NULL) {
+ vbo_nor = cache->ed_tri_nor =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_nor_format(&attr_id.vnor, &attr_id.lnor));
+ GWN_vertbuf_data_alloc(vbo_nor, vbo_len_capacity);
+ }
+
+ /* Data */
+ Gwn_VertBuf *vbo_data = NULL;
+ if (cache->ed_tri_data == NULL) {
+ vbo_data = cache->ed_tri_data =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_data_format(&attr_id.data));
+ GWN_vertbuf_data_alloc(vbo_data, vbo_len_capacity);
+ }
+
+ for (int i = 0; i < tri_len; i++) {
+ const BMLoop **bm_looptri = (const BMLoop **)rdata->edit_bmesh->looptris[i];
+ if (!BM_elem_flag_test(bm_looptri[0]->f, BM_ELEM_HIDDEN)) {
+ add_overlay_tri(
+ rdata, vbo_pos, vbo_nor, vbo_data,
+ attr_id.pos, attr_id.vnor, attr_id.lnor, attr_id.data,
+ bm_looptri, vbo_len_used);
+
+ vbo_len_used += 3;
+ }
+ }
+
+ /* Finish */
+ if (vbo_len_used != vbo_len_capacity) {
+ if (vbo_pos != NULL) {
+ GWN_vertbuf_data_resize(vbo_pos, vbo_len_used);
+ }
+ if (vbo_nor != NULL) {
+ GWN_vertbuf_data_resize(vbo_nor, vbo_len_used);
+ }
+ if (vbo_data != NULL) {
+ GWN_vertbuf_data_resize(vbo_data, vbo_len_used);
+ }
+ }
+}
+
+static void mesh_batch_cache_create_overlay_ledge_buffers(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI));
+
+ const int ledge_len = mesh_render_data_loose_edges_len_get(rdata);
+
+ const int vbo_len_capacity = ledge_len * 2;
+ int vbo_len_used = 0;
+
+ /* Positions */
+ Gwn_VertBuf *vbo_pos = NULL;
+ static struct { uint pos, vnor, data; } attr_id;
+ if (cache->ed_ledge_pos == NULL) {
+ vbo_pos = cache->ed_ledge_pos =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_pos_format(&attr_id.pos));
+ GWN_vertbuf_data_alloc(vbo_pos, vbo_len_capacity);
+ }
+
+ /* Normals */
+ Gwn_VertBuf *vbo_nor = NULL;
+ if (cache->ed_ledge_nor == NULL) {
+ vbo_nor = cache->ed_ledge_nor =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_nor_format(&attr_id.vnor, NULL));
+ GWN_vertbuf_data_alloc(vbo_nor, vbo_len_capacity);
+ }
+
+ /* Data */
+ Gwn_VertBuf *vbo_data = NULL;
+ if (cache->ed_ledge_data == NULL) {
+ vbo_data = cache->ed_ledge_data =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_data_format(&attr_id.data));
+ GWN_vertbuf_data_alloc(vbo_data, vbo_len_capacity);
+ }
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ for (uint i = 0; i < ledge_len; i++) {
+ const BMEdge *eed = BM_edge_at_index(bm, rdata->loose_edges[i]);
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ add_overlay_loose_edge(
+ rdata, vbo_pos, vbo_nor, vbo_data,
+ attr_id.pos, attr_id.vnor, attr_id.data,
+ eed, vbo_len_used);
+ vbo_len_used += 2;
+ }
+ }
+ }
+
+ /* Finish */
+ if (vbo_len_used != vbo_len_capacity) {
+ if (vbo_pos != NULL) {
+ GWN_vertbuf_data_resize(vbo_pos, vbo_len_used);
+ }
+ if (vbo_nor != NULL) {
+ GWN_vertbuf_data_resize(vbo_nor, vbo_len_used);
+ }
+ if (vbo_data != NULL) {
+ GWN_vertbuf_data_resize(vbo_data, vbo_len_used);
+ }
+ }
+}
+
+static void mesh_batch_cache_create_overlay_lvert_buffers(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI));
+
+ BMesh *bm = rdata->edit_bmesh->bm;
+ const int lvert_len = mesh_render_data_loose_verts_len_get(rdata);
+
+ const int vbo_len_capacity = lvert_len;
+ int vbo_len_used = 0;
+
+ static struct { uint pos, vnor, data; } attr_id;
+
+ /* Positions */
+ Gwn_VertBuf *vbo_pos = NULL;
+ if (cache->ed_lvert_pos == NULL) {
+ vbo_pos = cache->ed_lvert_pos =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_pos_format(&attr_id.pos));
+ GWN_vertbuf_data_alloc(vbo_pos, vbo_len_capacity);
+ }
+
+ /* Normals */
+ Gwn_VertBuf *vbo_nor = NULL;
+ if (cache->ed_lvert_nor == NULL) {
+ vbo_nor = cache->ed_lvert_nor =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_nor_format(&attr_id.vnor, NULL));
+ GWN_vertbuf_data_alloc(vbo_nor, vbo_len_capacity);
+ }
+
+ /* Data */
+ Gwn_VertBuf *vbo_data = NULL;
+ if (cache->ed_lvert_data == NULL) {
+ vbo_data = cache->ed_lvert_data =
+ GWN_vertbuf_create_with_format(edit_mesh_overlay_data_format(&attr_id.data));
+ GWN_vertbuf_data_alloc(vbo_data, vbo_len_capacity);
+ }
+
+ for (uint i = 0; i < lvert_len; i++) {
+ BMVert *eve = BM_vert_at_index(bm, rdata->loose_verts[i]);
+ add_overlay_loose_vert(
+ rdata, vbo_pos, vbo_nor, vbo_data,
+ attr_id.pos, attr_id.vnor, attr_id.data,
+ eve, vbo_len_used);
+ vbo_len_used += 1;
+ }
+
+ /* Finish */
+ if (vbo_len_used != vbo_len_capacity) {
+ if (vbo_pos != NULL) {
+ GWN_vertbuf_data_resize(vbo_pos, vbo_len_used);
+ }
+ if (vbo_nor != NULL) {
+ GWN_vertbuf_data_resize(vbo_nor, vbo_len_used);
+ }
+ if (vbo_data != NULL) {
+ GWN_vertbuf_data_resize(vbo_data, vbo_len_used);
+ }
+ }
+}
+
+/* Position */
+static Gwn_VertBuf *mesh_batch_cache_get_edit_tri_pos(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_tri_pos == NULL) {
+ mesh_batch_cache_create_overlay_tri_buffers(rdata, cache);
+ }
+
+ return cache->ed_tri_pos;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_edit_ledge_pos(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_ledge_pos == NULL) {
+ mesh_batch_cache_create_overlay_ledge_buffers(rdata, cache);
+ }
+
+ return cache->ed_ledge_pos;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_edit_lvert_pos(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_lvert_pos == NULL) {
+ mesh_batch_cache_create_overlay_lvert_buffers(rdata, cache);
+ }
+
+ return cache->ed_lvert_pos;
+}
+
+/* Normal */
+static Gwn_VertBuf *mesh_batch_cache_get_edit_tri_nor(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_tri_nor == NULL) {
+ mesh_batch_cache_create_overlay_tri_buffers(rdata, cache);
+ }
+
+ return cache->ed_tri_nor;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_edit_ledge_nor(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_ledge_nor == NULL) {
+ mesh_batch_cache_create_overlay_ledge_buffers(rdata, cache);
+ }
+
+ return cache->ed_ledge_nor;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_edit_lvert_nor(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_lvert_nor == NULL) {
+ mesh_batch_cache_create_overlay_lvert_buffers(rdata, cache);
+ }
+
+ return cache->ed_lvert_nor;
+}
+
+/* Data */
+static Gwn_VertBuf *mesh_batch_cache_get_edit_tri_data(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_tri_data == NULL) {
+ mesh_batch_cache_create_overlay_tri_buffers(rdata, cache);
+ }
+
+ return cache->ed_tri_data;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_edit_ledge_data(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_ledge_data == NULL) {
+ mesh_batch_cache_create_overlay_ledge_buffers(rdata, cache);
+ }
+
+ return cache->ed_ledge_data;
+}
+
+static Gwn_VertBuf *mesh_batch_cache_get_edit_lvert_data(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & MR_DATATYPE_VERT);
+
+ if (cache->ed_lvert_data == NULL) {
+ mesh_batch_cache_create_overlay_lvert_buffers(rdata, cache);
+ }
+
+ return cache->ed_lvert_data;
+}
+
+static Gwn_IndexBuf *mesh_batch_cache_get_edges_in_order(MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE));
+
+ if (cache->edges_in_order == NULL) {
+ const int vert_len = mesh_render_data_verts_len_get(rdata);
+ const int edge_len = mesh_render_data_edges_len_get(rdata);
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_LINES, edge_len, vert_len);
+
+ BLI_assert(rdata->types & MR_DATATYPE_EDGE);
+
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter eiter;
+ BMEdge *eed;
+ BM_ITER_MESH(eed, &eiter, bm, BM_EDGES_OF_MESH) {
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ GWN_indexbuf_add_line_verts(&elb, BM_elem_index_get(eed->v1), BM_elem_index_get(eed->v2));
+ }
+ }
+ }
+ else {
+ const MEdge *ed = rdata->medge;
+ for (int i = 0; i < edge_len; i++, ed++) {
+ GWN_indexbuf_add_line_verts(&elb, ed->v1, ed->v2);
+ }
+ }
+ cache->edges_in_order = GWN_indexbuf_build(&elb);
+ }
+
+ return cache->edges_in_order;
+}
+
+static Gwn_IndexBuf *mesh_batch_cache_get_triangles_in_order(MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI));
+
+ if (cache->triangles_in_order == NULL) {
+ const int vert_len = mesh_render_data_verts_len_get(rdata);
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tri_len, vert_len);
+
+ if (rdata->edit_bmesh) {
+ for (int i = 0; i < tri_len; ++i) {
+ const BMLoop **ltri = (const BMLoop **)rdata->edit_bmesh->looptris[i];
+ if (!BM_elem_flag_test(ltri[0]->f, BM_ELEM_HIDDEN)) {
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ GWN_indexbuf_add_generic_vert(&elb, BM_elem_index_get(ltri[tri_corner]->v));
+ }
+ }
+ }
+ }
+ else {
+ for (int i = 0; i < tri_len; ++i) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ GWN_indexbuf_add_generic_vert(&elb, mlt->tri[tri_corner]);
+ }
+ }
+ }
+ cache->triangles_in_order = GWN_indexbuf_build(&elb);
+ }
+
+ return cache->triangles_in_order;
+}
+
+static Gwn_IndexBuf **mesh_batch_cache_get_triangles_in_order_split_by_material(
+ MeshRenderData *rdata, MeshBatchCache *cache)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_POLY));
+
+ if (cache->shaded_triangles_in_order == NULL) {
+ const int poly_len = mesh_render_data_polys_len_get(rdata);
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+ const int mat_len = mesh_render_data_mat_len_get(rdata);
+
+ int *mat_tri_len = MEM_callocN(sizeof(*mat_tri_len) * mat_len, __func__);
+ cache->shaded_triangles_in_order = MEM_callocN(sizeof(*cache->shaded_triangles) * mat_len, __func__);
+ Gwn_IndexBufBuilder *elb = MEM_callocN(sizeof(*elb) * mat_len, __func__);
+
+ /* Note that polygons (not triangles) are used here.
+ * This OK because result is _guaranteed_ to be the same. */
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter fiter;
+ BMFace *efa;
+
+ BM_ITER_MESH(efa, &fiter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ const short ma_id = efa->mat_nr < mat_len ? efa->mat_nr : 0;
+ mat_tri_len[ma_id] += (efa->len - 2);
+ }
+ }
+ }
+ else {
+ for (uint i = 0; i < poly_len; i++) {
+ const MPoly *mp = &rdata->mpoly[i]; ;
+ const short ma_id = mp->mat_nr < mat_len ? mp->mat_nr : 0;
+ mat_tri_len[ma_id] += (mp->totloop - 2);
+ }
+ }
+
+ /* Init ELBs. */
+ for (int i = 0; i < mat_len; ++i) {
+ GWN_indexbuf_init(&elb[i], GWN_PRIM_TRIS, mat_tri_len[i], tri_len * 3);
+ }
+
+ /* Populate ELBs. */
+ uint nidx = 0;
+ if (rdata->edit_bmesh) {
+ BMesh *bm = rdata->edit_bmesh->bm;
+ BMIter fiter;
+ BMFace *efa;
+
+ BM_ITER_MESH(efa, &fiter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ const short ma_id = efa->mat_nr < mat_len ? efa->mat_nr : 0;
+ for (int j = 2; j < efa->len; j++) {
+ GWN_indexbuf_add_tri_verts(&elb[ma_id], nidx + 0, nidx + 1, nidx + 2);
+ nidx += 3;
+ }
+ }
+ }
+ }
+ else {
+ for (uint i = 0; i < poly_len; i++) {
+ const MPoly *mp = &rdata->mpoly[i]; ;
+ const short ma_id = mp->mat_nr < mat_len ? mp->mat_nr : 0;
+ for (int j = 2; j < mp->totloop; j++) {
+ GWN_indexbuf_add_tri_verts(&elb[ma_id], nidx + 0, nidx + 1, nidx + 2);
+ nidx += 3;
+ }
+ }
+ }
+
+ /* Build ELBs. */
+ for (int i = 0; i < mat_len; ++i) {
+ cache->shaded_triangles_in_order[i] = GWN_indexbuf_build(&elb[i]);
+ }
+
+ MEM_freeN(mat_tri_len);
+ MEM_freeN(elb);
+ }
+
+ return cache->shaded_triangles_in_order;
+}
+
+static Gwn_VertBuf *mesh_create_edge_pos_with_sel(
+ MeshRenderData *rdata, bool use_wire, bool use_select_bool)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_POLY | MR_DATATYPE_LOOP));
+ BLI_assert(rdata->edit_bmesh == NULL);
+
+ Gwn_VertBuf *vbo;
+ {
+ unsigned int vidx = 0, cidx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, sel; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.sel = GWN_vertformat_attr_add(&format, "select", GWN_COMP_U8, 1, GWN_FETCH_INT);
+ }
+
+ const int edge_len = mesh_render_data_edges_len_get(rdata);
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+
+ const int vbo_len_capacity = edge_len * 2;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ if (use_select_bool) {
+ mesh_render_data_ensure_edge_select_bool(rdata, use_wire);
+ }
+ bool *edge_select_bool = use_select_bool ? rdata->edge_select_bool : NULL;
+
+ for (int i = 0; i < edge_len; i++) {
+ const MEdge *ed = &rdata->medge[i];
+
+ uchar edge_vert_sel;
+ if (use_select_bool && edge_select_bool[i]) {
+ edge_vert_sel = true;
+ }
+ else if (use_wire) {
+ edge_vert_sel = false;
+ }
+ else {
+ continue;
+ }
+
+ GWN_vertbuf_attr_set(vbo, attr_id.sel, cidx++, &edge_vert_sel);
+ GWN_vertbuf_attr_set(vbo, attr_id.sel, cidx++, &edge_vert_sel);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, rdata->mvert[ed->v1].co);
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, vidx++, rdata->mvert[ed->v2].co);
+ }
+ vbo_len_used = vidx;
+
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+
+ return vbo;
+}
+
+static Gwn_IndexBuf *mesh_create_tri_overlay_weight_faces(
+ MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI));
+
+ {
+ const int vert_len = mesh_render_data_verts_len_get(rdata);
+ const int tri_len = mesh_render_data_looptri_len_get(rdata);
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tri_len, vert_len);
+
+ for (int i = 0; i < tri_len; ++i) {
+ const MLoopTri *mlt = &rdata->mlooptri[i];
+ if (!(rdata->mpoly[mlt->poly].flag & (ME_FACE_SEL | ME_HIDE))) {
+ for (uint tri_corner = 0; tri_corner < 3; tri_corner++) {
+ GWN_indexbuf_add_generic_vert(&elb, rdata->mloop[mlt->tri[tri_corner]].v);
+ }
+ }
+ }
+ return GWN_indexbuf_build(&elb);
+ }
+}
+
+/**
+ * Non-edit mode vertices (only used for weight-paint mode).
+ */
+static Gwn_VertBuf *mesh_create_vert_pos_with_overlay_data(
+ MeshRenderData *rdata)
+{
+ BLI_assert(rdata->types & (MR_DATATYPE_VERT));
+ BLI_assert(rdata->edit_bmesh == NULL);
+
+ Gwn_VertBuf *vbo;
+ {
+ unsigned int cidx = 0;
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint data; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.data = GWN_vertformat_attr_add(&format, "data", GWN_COMP_I8, 1, GWN_FETCH_INT);
+ }
+
+ const int vert_len = mesh_render_data_verts_len_get(rdata);
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+
+ const int vbo_len_capacity = vert_len;
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ for (int i = 0; i < vert_len; i++) {
+ const MVert *mv = &rdata->mvert[i];
+ const char data = mv->flag & (SELECT | ME_HIDE);
+ GWN_vertbuf_attr_set(vbo, attr_id.data, cidx++, &data);
+ }
+ vbo_len_used = cidx;
+
+ if (vbo_len_capacity != vbo_len_used) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+ }
+ return vbo;
+}
+
+/** \} */
+
+
+/* ---------------------------------------------------------------------- */
+
+/** \name Public API
+ * \{ */
+
+Gwn_Batch *DRW_mesh_batch_cache_get_all_edges(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->all_edges == NULL) {
+ /* create batch from Mesh */
+ const int datatype = MR_DATATYPE_VERT | MR_DATATYPE_EDGE;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->all_edges = GWN_batch_create(
+ GWN_PRIM_LINES, mesh_batch_cache_get_vert_pos_and_nor_in_order(rdata, cache),
+ mesh_batch_cache_get_edges_in_order(rdata, cache));
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->all_edges;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_all_triangles(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->all_triangles == NULL) {
+ /* create batch from DM */
+ const int datatype = MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->all_triangles = GWN_batch_create(
+ GWN_PRIM_TRIS, mesh_batch_cache_get_vert_pos_and_nor_in_order(rdata, cache),
+ mesh_batch_cache_get_triangles_in_order(rdata, cache));
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->all_triangles;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_normals(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->triangles_with_normals == NULL) {
+ const int datatype = MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->triangles_with_normals = GWN_batch_create(
+ GWN_PRIM_TRIS, mesh_batch_cache_get_tri_pos_and_normals(rdata, cache), NULL);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->triangles_with_normals;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_weights(Mesh *me, int defgroup)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->triangles_with_weights == NULL) {
+ const bool use_hide = (me->editflag & (ME_EDIT_PAINT_VERT_SEL | ME_EDIT_PAINT_FACE_SEL)) != 0;
+ const int datatype =
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_DVERT;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->triangles_with_weights = GWN_batch_create_ex(
+ GWN_PRIM_TRIS, mesh_create_tri_weights(rdata, use_hide, defgroup), NULL, GWN_BATCH_OWNS_VBO);
+
+ Gwn_VertBuf *vbo_tris = use_hide ?
+ mesh_create_tri_pos_and_normals_visible_only(rdata) :
+ mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
+
+ GWN_batch_vertbuf_add_ex(cache->triangles_with_weights, vbo_tris, use_hide);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->triangles_with_weights;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_normals_and_vert_colors(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->triangles_with_vert_colors == NULL) {
+ const bool use_hide = (me->editflag & (ME_EDIT_PAINT_VERT_SEL | ME_EDIT_PAINT_FACE_SEL)) != 0;
+ const int datatype =
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPCOL;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->triangles_with_vert_colors = GWN_batch_create_ex(
+ GWN_PRIM_TRIS, mesh_create_tri_vert_colors(rdata, use_hide), NULL, GWN_BATCH_OWNS_VBO);
+
+ Gwn_VertBuf *vbo_tris = use_hide ?
+ mesh_create_tri_pos_and_normals_visible_only(rdata) :
+ mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
+ GWN_batch_vertbuf_add_ex(cache->triangles_with_vert_colors, vbo_tris, use_hide);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->triangles_with_vert_colors;
+}
+
+
+struct Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_select_id(
+ struct Mesh *me, bool use_hide, uint select_id_offset)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->triangles_with_select_id_offset != select_id_offset) {
+ cache->triangles_with_select_id_offset = select_id_offset;
+ GWN_BATCH_DISCARD_SAFE(cache->triangles_with_select_id);
+ }
+
+ if (cache->triangles_with_select_id == NULL) {
+ const int datatype =
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->triangles_with_select_id = GWN_batch_create_ex(
+ GWN_PRIM_TRIS, mesh_create_tri_select_id(rdata, use_hide, select_id_offset), NULL, GWN_BATCH_OWNS_VBO);
+
+ Gwn_VertBuf *vbo_tris = use_hide ?
+ mesh_create_tri_pos_and_normals_visible_only(rdata) :
+ mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
+ GWN_batch_vertbuf_add_ex(cache->triangles_with_select_id, vbo_tris, use_hide);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->triangles_with_select_id;
+}
+
+/**
+ * Same as #DRW_mesh_batch_cache_get_triangles_with_select_id
+ * without the ID's, use to mask out geometry, eg - dont select face-dots behind other faces.
+ */
+struct Gwn_Batch *DRW_mesh_batch_cache_get_triangles_with_select_mask(struct Mesh *me, bool use_hide)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+ if (cache->triangles_with_select_mask == NULL) {
+ const int datatype =
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ Gwn_VertBuf *vbo_tris = use_hide ?
+ mesh_create_tri_pos_and_normals_visible_only(rdata) :
+ mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
+
+ cache->triangles_with_select_mask = GWN_batch_create_ex(
+ GWN_PRIM_TRIS, vbo_tris, NULL, use_hide ? GWN_BATCH_OWNS_VBO : 0);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->triangles_with_select_mask;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_points_with_normals(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->points_with_normals == NULL) {
+ const int datatype = MR_DATATYPE_VERT | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOP | MR_DATATYPE_POLY;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->points_with_normals = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_tri_pos_and_normals(rdata, cache), NULL);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->points_with_normals;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_all_verts(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->all_verts == NULL) {
+ /* create batch from DM */
+ MeshRenderData *rdata = mesh_render_data_create(me, MR_DATATYPE_VERT);
+
+ cache->all_verts = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_vert_pos_and_nor_in_order(rdata, cache), NULL);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->all_verts;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_fancy_edges(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->fancy_edges == NULL) {
+ /* create batch from DM */
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, n1, n2; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ attr_id.n1 = GWN_vertformat_attr_add(&format, "N1", GWN_COMP_I10, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ attr_id.n2 = GWN_vertformat_attr_add(&format, "N2", GWN_COMP_I10, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+
+ MeshRenderData *rdata = mesh_render_data_create(
+ me, MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_LOOP | MR_DATATYPE_POLY);
+
+ const int edge_len = mesh_render_data_edges_len_get(rdata);
+
+ const int vbo_len_capacity = edge_len * 2; /* these are PRIM_LINE verts, not mesh verts */
+ int vbo_len_used = 0;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+ for (int i = 0; i < edge_len; ++i) {
+ float *vcos1, *vcos2;
+ float *pnor1 = NULL, *pnor2 = NULL;
+ bool is_manifold;
+
+ if (mesh_render_data_edge_vcos_manifold_pnors(rdata, i, &vcos1, &vcos2, &pnor1, &pnor2, &is_manifold)) {
+
+ Gwn_PackedNormal n1value = { .x = 0, .y = 0, .z = +511 };
+ Gwn_PackedNormal n2value = { .x = 0, .y = 0, .z = -511 };
+
+ if (is_manifold) {
+ n1value = GWN_normal_convert_i10_v3(pnor1);
+ n2value = GWN_normal_convert_i10_v3(pnor2);
+ }
+
+ const Gwn_PackedNormal *n1 = &n1value;
+ const Gwn_PackedNormal *n2 = &n2value;
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 2 * i, vcos1);
+ GWN_vertbuf_attr_set(vbo, attr_id.n1, 2 * i, n1);
+ GWN_vertbuf_attr_set(vbo, attr_id.n2, 2 * i, n2);
+
+ GWN_vertbuf_attr_set(vbo, attr_id.pos, 2 * i + 1, vcos2);
+ GWN_vertbuf_attr_set(vbo, attr_id.n1, 2 * i + 1, n1);
+ GWN_vertbuf_attr_set(vbo, attr_id.n2, 2 * i + 1, n2);
+
+ vbo_len_used += 2;
+ }
+ }
+ if (vbo_len_used != vbo_len_capacity) {
+ GWN_vertbuf_data_resize(vbo, vbo_len_used);
+ }
+
+ cache->fancy_edges = GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->fancy_edges;
+}
+
+static void mesh_batch_cache_create_overlay_batches(Mesh *me)
+{
+ BLI_assert(me->edit_btmesh != NULL);
+
+ /* Since MR_DATATYPE_OVERLAY is slow to generate, generate them all at once */
+ const int options =
+ MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_LOOP | MR_DATATYPE_POLY |
+ MR_DATATYPE_LOOPTRI | MR_DATATYPE_OVERLAY;
+
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+ MeshRenderData *rdata = mesh_render_data_create(me, options);
+
+ if (cache->overlay_triangles == NULL) {
+ cache->overlay_triangles = GWN_batch_create(
+ GWN_PRIM_TRIS, mesh_batch_cache_get_edit_tri_pos(rdata, cache), NULL);
+ GWN_batch_vertbuf_add(cache->overlay_triangles, mesh_batch_cache_get_edit_tri_nor(rdata, cache));
+ GWN_batch_vertbuf_add(cache->overlay_triangles, mesh_batch_cache_get_edit_tri_data(rdata, cache));
+ }
+
+ if (cache->overlay_loose_edges == NULL) {
+ cache->overlay_loose_edges = GWN_batch_create(
+ GWN_PRIM_LINES, mesh_batch_cache_get_edit_ledge_pos(rdata, cache), NULL);
+ GWN_batch_vertbuf_add(cache->overlay_loose_edges, mesh_batch_cache_get_edit_ledge_nor(rdata, cache));
+ GWN_batch_vertbuf_add(cache->overlay_loose_edges, mesh_batch_cache_get_edit_ledge_data(rdata, cache));
+ }
+
+ if (cache->overlay_loose_verts == NULL) {
+ cache->overlay_loose_verts = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_edit_lvert_pos(rdata, cache), NULL);
+ GWN_batch_vertbuf_add(cache->overlay_loose_verts, mesh_batch_cache_get_edit_lvert_nor(rdata, cache));
+ GWN_batch_vertbuf_add(cache->overlay_loose_verts, mesh_batch_cache_get_edit_lvert_data(rdata, cache));
+ }
+
+ if (cache->overlay_triangles_nor == NULL) {
+ cache->overlay_triangles_nor = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_edit_tri_pos(rdata, cache), NULL);
+ GWN_batch_vertbuf_add(cache->overlay_triangles_nor, mesh_batch_cache_get_edit_tri_nor(rdata, cache));
+ }
+
+ if (cache->overlay_loose_edges_nor == NULL) {
+ cache->overlay_loose_edges_nor = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_edit_ledge_pos(rdata, cache), NULL);
+ GWN_batch_vertbuf_add(cache->overlay_loose_edges_nor, mesh_batch_cache_get_edit_ledge_nor(rdata, cache));
+ }
+
+ mesh_render_data_free(rdata);
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_overlay_triangles(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_triangles == NULL) {
+ mesh_batch_cache_create_overlay_batches(me);
+ }
+
+ return cache->overlay_triangles;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_overlay_loose_edges(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_loose_edges == NULL) {
+ mesh_batch_cache_create_overlay_batches(me);
+ }
+
+ return cache->overlay_loose_edges;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_overlay_loose_verts(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_loose_verts == NULL) {
+ mesh_batch_cache_create_overlay_batches(me);
+ }
+
+ return cache->overlay_loose_verts;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_overlay_triangles_nor(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_triangles_nor == NULL) {
+ mesh_batch_cache_create_overlay_batches(me);
+ }
+
+ return cache->overlay_triangles_nor;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_overlay_loose_edges_nor(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_loose_edges_nor == NULL) {
+ mesh_batch_cache_create_overlay_batches(me);
+ }
+
+ return cache->overlay_loose_edges_nor;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_overlay_facedots(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_facedots == NULL) {
+ MeshRenderData *rdata = mesh_render_data_create(me, MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY);
+
+ cache->overlay_facedots = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_facedot_pos_with_normals_and_flag(rdata, cache), NULL);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->overlay_facedots;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_facedots_with_select_id(Mesh *me, uint select_id_offset)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->facedot_with_select_id_offset != select_id_offset) {
+ cache->facedot_with_select_id_offset = select_id_offset;
+ GWN_BATCH_DISCARD_SAFE(cache->edges_with_select_id);
+ }
+
+ if (cache->facedot_with_select_id == NULL) {
+ MeshRenderData *rdata = mesh_render_data_create(me, MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY);
+
+ /* We only want the 'pos', not the normals or flag.
+ * Use since this is almost certainly already created. */
+ cache->facedot_with_select_id = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_facedot_pos_with_normals_and_flag(rdata, cache), NULL);
+
+ GWN_batch_vertbuf_add_ex(
+ cache->facedot_with_select_id,
+ mesh_create_facedot_select_id(rdata, select_id_offset), true);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->facedot_with_select_id;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_edges_with_select_id(Mesh *me, uint select_id_offset)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->edges_with_select_id_offset != select_id_offset) {
+ cache->edges_with_select_id_offset = select_id_offset;
+ GWN_BATCH_DISCARD_SAFE(cache->edges_with_select_id);
+ }
+
+ if (cache->edges_with_select_id == NULL) {
+ MeshRenderData *rdata = mesh_render_data_create(me, MR_DATATYPE_VERT | MR_DATATYPE_EDGE);
+
+ cache->edges_with_select_id = GWN_batch_create(
+ GWN_PRIM_LINES, mesh_batch_cache_get_edges_visible(rdata, cache), NULL);
+
+ GWN_batch_vertbuf_add_ex(
+ cache->edges_with_select_id,
+ mesh_create_edges_select_id(rdata, select_id_offset), true);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->edges_with_select_id;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_verts_with_select_id(Mesh *me, uint select_id_offset)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->verts_with_select_id_offset != select_id_offset) {
+ cache->verts_with_select_id_offset = select_id_offset;
+ GWN_BATCH_DISCARD_SAFE(cache->verts_with_select_id);
+ }
+
+ if (cache->verts_with_select_id == NULL) {
+ MeshRenderData *rdata = mesh_render_data_create(me, MR_DATATYPE_VERT);
+
+ cache->verts_with_select_id = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_verts_visible(rdata, cache), NULL);
+
+ GWN_batch_vertbuf_add_ex(
+ cache->verts_with_select_id,
+ mesh_create_verts_select_id(rdata, select_id_offset), true);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->verts_with_select_id;
+}
+
+Gwn_Batch **DRW_mesh_batch_cache_get_surface_shaded(
+ Mesh *me, struct GPUMaterial **gpumat_array, uint gpumat_array_len,
+ char **auto_layer_names, int **auto_layer_is_srgb, int *auto_layer_count)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->shaded_triangles == NULL) {
+ /* create batch from DM */
+ const int datatype =
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_LOOPTRI |
+ MR_DATATYPE_POLY | MR_DATATYPE_SHADING;
+ MeshRenderData *rdata = mesh_render_data_create_ex(me, datatype, gpumat_array, gpumat_array_len);
+
+ const int mat_len = mesh_render_data_mat_len_get(rdata);
+
+ cache->shaded_triangles = MEM_callocN(sizeof(*cache->shaded_triangles) * mat_len, __func__);
+
+ Gwn_IndexBuf **el = mesh_batch_cache_get_triangles_in_order_split_by_material(rdata, cache);
+
+ Gwn_VertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
+ Gwn_VertBuf *vbo_shading = mesh_batch_cache_get_tri_shading_data(rdata, cache);
+
+ for (int i = 0; i < mat_len; ++i) {
+ cache->shaded_triangles[i] = GWN_batch_create(
+ GWN_PRIM_TRIS, vbo, el[i]);
+ if (vbo_shading) {
+ GWN_batch_vertbuf_add(cache->shaded_triangles[i], vbo_shading);
+ }
+ }
+
+ mesh_render_data_free(rdata);
+ }
+
+ if (auto_layer_names) {
+ *auto_layer_names = cache->auto_layer_names;
+ *auto_layer_is_srgb = cache->auto_layer_is_srgb;
+ *auto_layer_count = cache->auto_layer_ct;
+ }
+
+ return cache->shaded_triangles;
+}
+
+Gwn_Batch **DRW_mesh_batch_cache_get_surface_texpaint(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->texpaint_triangles == NULL) {
+ /* create batch from DM */
+ const int datatype =
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOPUV;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ const int mat_len = mesh_render_data_mat_len_get(rdata);
+
+ cache->texpaint_triangles = MEM_callocN(sizeof(*cache->texpaint_triangles) * mat_len, __func__);
+
+ Gwn_IndexBuf **el = mesh_batch_cache_get_triangles_in_order_split_by_material(rdata, cache);
+
+ Gwn_VertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
+ for (int i = 0; i < mat_len; ++i) {
+ cache->texpaint_triangles[i] = GWN_batch_create(
+ GWN_PRIM_TRIS, vbo, el[i]);
+ Gwn_VertBuf *vbo_uv = mesh_batch_cache_get_tri_uv_active(rdata, cache);
+ if (vbo_uv) {
+ GWN_batch_vertbuf_add(cache->texpaint_triangles[i], vbo_uv);
+ }
+ }
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->texpaint_triangles;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_surface_texpaint_single(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->texpaint_triangles_single == NULL) {
+ /* create batch from DM */
+ const int datatype =
+ MR_DATATYPE_VERT | MR_DATATYPE_LOOP | MR_DATATYPE_POLY | MR_DATATYPE_LOOPTRI | MR_DATATYPE_LOOPUV;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ Gwn_VertBuf *vbo = mesh_batch_cache_get_tri_pos_and_normals(rdata, cache);
+
+ cache->texpaint_triangles_single = GWN_batch_create(
+ GWN_PRIM_TRIS, vbo, NULL);
+ Gwn_VertBuf *vbo_uv = mesh_batch_cache_get_tri_uv_active(rdata, cache);
+ if (vbo_uv) {
+ GWN_batch_vertbuf_add(cache->texpaint_triangles_single, vbo_uv);
+ }
+ mesh_render_data_free(rdata);
+ }
+ return cache->texpaint_triangles_single;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_weight_overlay_edges(Mesh *me, bool use_wire, bool use_sel)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_paint_edges == NULL) {
+ /* create batch from Mesh */
+ const int datatype = MR_DATATYPE_VERT | MR_DATATYPE_EDGE | MR_DATATYPE_POLY | MR_DATATYPE_LOOP;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->overlay_paint_edges = GWN_batch_create_ex(
+ GWN_PRIM_LINES, mesh_create_edge_pos_with_sel(rdata, use_wire, use_sel), NULL, GWN_BATCH_OWNS_VBO);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->overlay_paint_edges;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_weight_overlay_faces(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_weight_faces == NULL) {
+ /* create batch from Mesh */
+ const int datatype = MR_DATATYPE_VERT | MR_DATATYPE_POLY | MR_DATATYPE_LOOP | MR_DATATYPE_LOOPTRI;
+ MeshRenderData *rdata = mesh_render_data_create(me, datatype);
+
+ cache->overlay_weight_faces = GWN_batch_create_ex(
+ GWN_PRIM_TRIS, mesh_batch_cache_get_vert_pos_and_nor_in_order(rdata, cache),
+ mesh_create_tri_overlay_weight_faces(rdata), GWN_BATCH_OWNS_INDEX);
+
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->overlay_weight_faces;
+}
+
+Gwn_Batch *DRW_mesh_batch_cache_get_weight_overlay_verts(Mesh *me)
+{
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+
+ if (cache->overlay_weight_verts == NULL) {
+ /* create batch from Mesh */
+ MeshRenderData *rdata = mesh_render_data_create(me, MR_DATATYPE_VERT);
+
+ cache->overlay_weight_verts = GWN_batch_create(
+ GWN_PRIM_POINTS, mesh_batch_cache_get_vert_pos_and_nor_in_order(rdata, cache), NULL);
+
+ GWN_batch_vertbuf_add_ex(
+ cache->overlay_weight_verts,
+ mesh_create_vert_pos_with_overlay_data(rdata), true);
+ mesh_render_data_free(rdata);
+ }
+
+ return cache->overlay_weight_verts;
+}
+
+/**
+ * Needed for when we draw with shaded data.
+ */
+void DRW_mesh_cache_sculpt_coords_ensure(Mesh *me)
+{
+ if (me->runtime.batch_cache) {
+ MeshBatchCache *cache = mesh_batch_cache_get(me);
+ if (cache && cache->pos_with_normals && cache->is_sculpt_points_tag) {
+ /* XXX Force update of all the batches that contains the pos_with_normals buffer.
+ * TODO(fclem): Ideally, Gawain should provide a way to update a buffer without destroying it. */
+ mesh_batch_cache_clear_selective(me, cache->pos_with_normals);
+ GWN_VERTBUF_DISCARD_SAFE(cache->pos_with_normals);
+ }
+ cache->is_sculpt_points_tag = false;
+ }
+}
+
+/** \} */
+
+#undef MESH_RENDER_FUNCTION
diff --git a/source/blender/draw/intern/draw_cache_impl_metaball.c b/source/blender/draw/intern/draw_cache_impl_metaball.c
new file mode 100644
index 00000000000..f01e7b929f8
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_metaball.c
@@ -0,0 +1,144 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file draw_cache_impl_metaball.c
+ * \ingroup draw
+ *
+ * \brief MetaBall API for render engines
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "DNA_meta_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_curve.h"
+#include "BKE_mball.h"
+
+#include "GPU_batch.h"
+
+#include "draw_cache_impl.h" /* own include */
+
+
+static void metaball_batch_cache_clear(MetaBall *mb);
+
+/* ---------------------------------------------------------------------- */
+/* MetaBall Gwn_Batch Cache */
+
+typedef struct MetaBallBatchCache {
+ Gwn_Batch *batch;
+
+ /* settings to determine if cache is invalid */
+ bool is_dirty;
+} MetaBallBatchCache;
+
+/* Gwn_Batch cache management. */
+
+static bool metaball_batch_cache_valid(MetaBall *mb)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+
+ if (cache == NULL) {
+ return false;
+ }
+
+ return cache->is_dirty == false;
+}
+
+static void metaball_batch_cache_init(MetaBall *mb)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+
+ if (!cache) {
+ cache = mb->batch_cache = MEM_mallocN(sizeof(*cache), __func__);
+ }
+ cache->batch = NULL;
+ cache->is_dirty = false;
+}
+
+static MetaBallBatchCache *metaball_batch_cache_get(MetaBall *mb)
+{
+ if (!metaball_batch_cache_valid(mb)) {
+ metaball_batch_cache_clear(mb);
+ metaball_batch_cache_init(mb);
+ }
+ return mb->batch_cache;
+}
+
+void DRW_mball_batch_cache_dirty(MetaBall *mb, int mode)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+ if (cache == NULL) {
+ return;
+ }
+ switch (mode) {
+ case BKE_MBALL_BATCH_DIRTY_ALL:
+ cache->is_dirty = true;
+ break;
+ default:
+ BLI_assert(0);
+ }
+}
+
+static void metaball_batch_cache_clear(MetaBall *mb)
+{
+ MetaBallBatchCache *cache = mb->batch_cache;
+ if (!cache) {
+ return;
+ }
+
+ GWN_BATCH_DISCARD_SAFE(cache->batch);
+}
+
+void DRW_mball_batch_cache_free(MetaBall *mb)
+{
+ metaball_batch_cache_clear(mb);
+ MEM_SAFE_FREE(mb->batch_cache);
+}
+
+/* -------------------------------------------------------------------- */
+
+/** \name Public Object/MetaBall API
+ * \{ */
+
+Gwn_Batch *DRW_metaball_batch_cache_get_triangles_with_normals(Object *ob)
+{
+ if (!BKE_mball_is_basis(ob))
+ return NULL;
+
+ MetaBall *mb = ob->data;
+ MetaBallBatchCache *cache = metaball_batch_cache_get(mb);
+
+ if (cache->batch == NULL) {
+ ListBase *lb = &ob->curve_cache->disp;
+ cache->batch = GWN_batch_create_ex(
+ GWN_PRIM_TRIS,
+ DRW_displist_vertbuf_calc_pos_with_normals(lb),
+ DRW_displist_indexbuf_calc_triangles_in_order(lb),
+ GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+ }
+
+ return cache->batch;
+}
diff --git a/source/blender/draw/intern/draw_cache_impl_particles.c b/source/blender/draw/intern/draw_cache_impl_particles.c
new file mode 100644
index 00000000000..d7e8a6b71df
--- /dev/null
+++ b/source/blender/draw/intern/draw_cache_impl_particles.c
@@ -0,0 +1,554 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 by Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation, Mike Erwin, Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file draw_cache_impl_particles.c
+ * \ingroup draw
+ *
+ * \brief Particle API for render engines
+ */
+
+#include "DRW_render.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_math_vector.h"
+#include "BLI_string.h"
+#include "BLI_ghash.h"
+
+#include "DNA_modifier_types.h"
+#include "DNA_particle_types.h"
+
+#include "BKE_particle.h"
+#include "BKE_DerivedMesh.h"
+
+#include "GPU_batch.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "draw_cache_impl.h" /* own include */
+
+static void particle_batch_cache_clear(ParticleSystem *psys);
+
+/* ---------------------------------------------------------------------- */
+/* Particle Gwn_Batch Cache */
+
+typedef struct ParticleBatchCache {
+ Gwn_VertBuf *pos;
+ Gwn_IndexBuf *indices;
+
+ Gwn_Batch *hairs;
+
+ int elems_count;
+ int point_count;
+
+ /* settings to determine if cache is invalid */
+ bool is_dirty;
+} ParticleBatchCache;
+
+/* Gwn_Batch cache management. */
+
+static bool particle_batch_cache_valid(ParticleSystem *psys)
+{
+ ParticleBatchCache *cache = psys->batch_cache;
+
+ if (cache == NULL) {
+ return false;
+ }
+
+ if (cache->is_dirty == false) {
+ return true;
+ }
+ else {
+ return false;
+ }
+
+ return true;
+}
+
+static void particle_batch_cache_init(ParticleSystem *psys)
+{
+ ParticleBatchCache *cache = psys->batch_cache;
+
+ if (!cache) {
+ cache = psys->batch_cache = MEM_callocN(sizeof(*cache), __func__);
+ }
+ else {
+ memset(cache, 0, sizeof(*cache));
+ }
+
+ cache->is_dirty = false;
+}
+
+static ParticleBatchCache *particle_batch_cache_get(ParticleSystem *psys)
+{
+ if (!particle_batch_cache_valid(psys)) {
+ particle_batch_cache_clear(psys);
+ particle_batch_cache_init(psys);
+ }
+ return psys->batch_cache;
+}
+
+void DRW_particle_batch_cache_dirty(ParticleSystem *psys, int mode)
+{
+ ParticleBatchCache *cache = psys->batch_cache;
+ if (cache == NULL) {
+ return;
+ }
+ switch (mode) {
+ case BKE_PARTICLE_BATCH_DIRTY_ALL:
+ cache->is_dirty = true;
+ break;
+ default:
+ BLI_assert(0);
+ }
+}
+
+static void particle_batch_cache_clear(ParticleSystem *psys)
+{
+ ParticleBatchCache *cache = psys->batch_cache;
+ if (!cache) {
+ return;
+ }
+
+ GWN_BATCH_DISCARD_SAFE(cache->hairs);
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->pos);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->indices);
+}
+
+void DRW_particle_batch_cache_free(ParticleSystem *psys)
+{
+ particle_batch_cache_clear(psys);
+ MEM_SAFE_FREE(psys->batch_cache);
+}
+
+static void ensure_seg_pt_count(ParticleSystem *psys, ParticleBatchCache *cache)
+{
+ if (cache->pos == NULL || cache->indices == NULL) {
+ cache->elems_count = 0;
+ cache->point_count = 0;
+
+ if (psys->pathcache && (!psys->childcache || (psys->part->draw & PART_DRAW_PARENT))) {
+ for (int i = 0; i < psys->totpart; i++) {
+ ParticleCacheKey *path = psys->pathcache[i];
+
+ if (path->segments > 0) {
+ cache->elems_count += path->segments + 2;
+ cache->point_count += path->segments + 1;
+ }
+ }
+ }
+
+ if (psys->childcache) {
+ int child_count = psys->totchild * psys->part->disp / 100;
+
+ for (int i = 0; i < child_count; i++) {
+ ParticleCacheKey *path = psys->childcache[i];
+
+ if (path->segments > 0) {
+ cache->elems_count += path->segments + 2;
+ cache->point_count += path->segments + 1;
+ }
+ }
+ }
+ }
+}
+
+/* Gwn_Batch cache usage. */
+static void particle_batch_cache_ensure_pos_and_seg(ParticleSystem *psys, ModifierData *md, ParticleBatchCache *cache)
+{
+ if (cache->pos != NULL && cache->indices != NULL) {
+ return;
+ }
+
+ int curr_point = 0;
+ ParticleSystemModifierData *psmd = (ParticleSystemModifierData *)md;
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->pos);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->indices);
+
+ static Gwn_VertFormat format = { 0 };
+ static struct { uint pos, tan, ind; } attr_id;
+ unsigned int *uv_id = NULL;
+ int uv_layers = 0;
+ MTFace **mtfaces = NULL;
+ float (**parent_uvs)[2] = NULL;
+ bool simple = psys->part->childtype == PART_CHILD_PARTICLES;
+
+ if (psmd) {
+ if (CustomData_has_layer(&psmd->dm_final->loopData, CD_MLOOPUV)) {
+ uv_layers = CustomData_number_of_layers(&psmd->dm_final->loopData, CD_MLOOPUV);
+ }
+ }
+
+ GWN_vertformat_clear(&format);
+
+ /* initialize vertex format */
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.tan = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ attr_id.ind = GWN_vertformat_attr_add(&format, "ind", GWN_COMP_I32, 1, GWN_FETCH_INT);
+
+ if (psmd) {
+ uv_id = MEM_mallocN(sizeof(*uv_id) * uv_layers, "UV attrib format");
+
+ for (int i = 0; i < uv_layers; i++) {
+ const char *name = CustomData_get_layer_name(&psmd->dm_final->loopData, CD_MLOOPUV, i);
+ char uuid[32];
+
+ BLI_snprintf(uuid, sizeof(uuid), "u%u", BLI_ghashutil_strhash_p(name));
+ uv_id[i] = GWN_vertformat_attr_add(&format, uuid, GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+ }
+
+ cache->pos = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(cache->pos, cache->point_count);
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init_ex(&elb, GWN_PRIM_LINE_STRIP, cache->elems_count, cache->point_count, true);
+
+ if (uv_layers) {
+ DM_ensure_tessface(psmd->dm_final);
+
+ mtfaces = MEM_mallocN(sizeof(*mtfaces) * uv_layers, "Faces UV layers");
+
+ for (int i = 0; i < uv_layers; i++) {
+ mtfaces[i] = (MTFace *)CustomData_get_layer_n(&psmd->dm_final->faceData, CD_MTFACE, i);
+ }
+ }
+
+ if (psys->pathcache && (!psys->childcache || (psys->part->draw & PART_DRAW_PARENT))) {
+ if (simple) {
+ parent_uvs = MEM_callocN(sizeof(*parent_uvs) * psys->totpart, "Parent particle UVs");
+ }
+
+ for (int i = 0; i < psys->totpart; i++) {
+ ParticleCacheKey *path = psys->pathcache[i];
+
+ if (path->segments > 0) {
+ float tangent[3];
+ int from = psmd ? psmd->psys->part->from : 0;
+ float (*uv)[2] = NULL;
+
+ if (psmd) {
+ uv = MEM_callocN(sizeof(*uv) * uv_layers, "Particle UVs");
+
+ if (simple) {
+ parent_uvs[i] = uv;
+ }
+ }
+
+ if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) {
+ ParticleData *particle = &psys->particles[i];
+ int num = particle->num_dmcache;
+
+ if (num == DMCACHE_NOTFOUND) {
+ if (particle->num < psmd->dm_final->getNumTessFaces(psmd->dm_final)) {
+ num = particle->num;
+ }
+ }
+
+ if (num != DMCACHE_NOTFOUND) {
+ MFace *mface = psmd->dm_final->getTessFaceData(psmd->dm_final, num, CD_MFACE);
+
+ for (int j = 0; j < uv_layers; j++) {
+ psys_interpolate_uvs(mtfaces[j] + num, mface->v4, particle->fuv, uv[j]);
+ }
+ }
+ }
+
+ for (int j = 0; j < path->segments; j++) {
+ if (j == 0) {
+ sub_v3_v3v3(tangent, path[j + 1].co, path[j].co);
+ }
+ else {
+ sub_v3_v3v3(tangent, path[j + 1].co, path[j - 1].co);
+ }
+
+ GWN_vertbuf_attr_set(cache->pos, attr_id.pos, curr_point, path[j].co);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.tan, curr_point, tangent);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.ind, curr_point, &i);
+
+ if (psmd) {
+ for (int k = 0; k < uv_layers; k++) {
+ GWN_vertbuf_attr_set(cache->pos, uv_id[k], curr_point, uv[k]);
+ }
+ }
+
+ GWN_indexbuf_add_generic_vert(&elb, curr_point);
+
+ curr_point++;
+ }
+
+ sub_v3_v3v3(tangent, path[path->segments].co, path[path->segments - 1].co);
+
+ GWN_vertbuf_attr_set(cache->pos, attr_id.pos, curr_point, path[path->segments].co);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.tan, curr_point, tangent);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.ind, curr_point, &i);
+
+ if (psmd) {
+ for (int k = 0; k < uv_layers; k++) {
+ GWN_vertbuf_attr_set(cache->pos, uv_id[k], curr_point, uv[k]);
+ }
+
+ if (!simple) {
+ MEM_freeN(uv);
+ }
+ }
+
+ /* finish the segment and add restart primitive */
+ GWN_indexbuf_add_generic_vert(&elb, curr_point);
+ GWN_indexbuf_add_primitive_restart(&elb);
+
+ curr_point++;
+ }
+ }
+ }
+
+ if (psys->childcache) {
+ int child_count = psys->totchild * psys->part->disp / 100;
+
+ if (simple && !parent_uvs) {
+ parent_uvs = MEM_callocN(sizeof(*parent_uvs) * psys->totpart, "Parent particle UVs");
+ }
+
+ for (int i = 0, x = psys->totpart; i < child_count; i++, x++) {
+ ParticleCacheKey *path = psys->childcache[i];
+ float tangent[3];
+
+ if (path->segments > 0) {
+ int from = psmd ? psmd->psys->part->from : 0;
+ float (*uv)[2] = NULL;
+
+ if (!simple) {
+ if (psmd) {
+ uv = MEM_callocN(sizeof(*uv) * uv_layers, "Particle UVs");
+ }
+
+ if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) {
+ ChildParticle *particle = &psys->child[i];
+ int num = particle->num;
+
+ if (num != DMCACHE_NOTFOUND) {
+ MFace *mface = psmd->dm_final->getTessFaceData(psmd->dm_final, num, CD_MFACE);
+
+ for (int j = 0; j < uv_layers; j++) {
+ psys_interpolate_uvs(mtfaces[j] + num, mface->v4, particle->fuv, uv[j]);
+ }
+ }
+ }
+ }
+ else if (!parent_uvs[psys->child[i].parent]) {
+ if (psmd) {
+ parent_uvs[psys->child[i].parent] = MEM_callocN(sizeof(*uv) * uv_layers, "Particle UVs");
+ }
+
+ if (ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) {
+ ParticleData *particle = &psys->particles[psys->child[i].parent];
+ int num = particle->num_dmcache;
+
+ if (num == DMCACHE_NOTFOUND) {
+ if (particle->num < psmd->dm_final->getNumTessFaces(psmd->dm_final)) {
+ num = particle->num;
+ }
+ }
+
+ if (num != DMCACHE_NOTFOUND) {
+ MFace *mface = psmd->dm_final->getTessFaceData(psmd->dm_final, num, CD_MFACE);
+
+ for (int j = 0; j < uv_layers; j++) {
+ psys_interpolate_uvs(mtfaces[j] + num, mface->v4, particle->fuv, parent_uvs[psys->child[i].parent][j]);
+ }
+ }
+ }
+ }
+
+ for (int j = 0; j < path->segments; j++) {
+ if (j == 0) {
+ sub_v3_v3v3(tangent, path[j + 1].co, path[j].co);
+ }
+ else {
+ sub_v3_v3v3(tangent, path[j + 1].co, path[j - 1].co);
+ }
+
+ GWN_vertbuf_attr_set(cache->pos, attr_id.pos, curr_point, path[j].co);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.tan, curr_point, tangent);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.ind, curr_point, &x);
+
+ if (psmd) {
+ for (int k = 0; k < uv_layers; k++) {
+ GWN_vertbuf_attr_set(cache->pos, uv_id[k], curr_point,
+ simple ? parent_uvs[psys->child[i].parent][k] : uv[k]);
+ }
+ }
+
+ GWN_indexbuf_add_generic_vert(&elb, curr_point);
+
+ curr_point++;
+ }
+
+ sub_v3_v3v3(tangent, path[path->segments].co, path[path->segments - 1].co);
+
+ GWN_vertbuf_attr_set(cache->pos, attr_id.pos, curr_point, path[path->segments].co);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.tan, curr_point, tangent);
+ GWN_vertbuf_attr_set(cache->pos, attr_id.ind, curr_point, &x);
+
+ if (psmd) {
+ for (int k = 0; k < uv_layers; k++) {
+ GWN_vertbuf_attr_set(cache->pos, uv_id[k], curr_point,
+ simple ? parent_uvs[psys->child[i].parent][k] : uv[k]);
+ }
+
+ if (!simple) {
+ MEM_freeN(uv);
+ }
+ }
+
+ /* finish the segment and add restart primitive */
+ GWN_indexbuf_add_generic_vert(&elb, curr_point);
+ GWN_indexbuf_add_primitive_restart(&elb);
+
+ curr_point++;
+ }
+ }
+ }
+
+ if (parent_uvs) {
+ for (int i = 0; i < psys->totpart; i++) {
+ MEM_SAFE_FREE(parent_uvs[i]);
+ }
+
+ MEM_freeN(parent_uvs);
+ }
+
+ if (uv_layers) {
+ MEM_freeN(mtfaces);
+ }
+
+ if (psmd) {
+ MEM_freeN(uv_id);
+ }
+
+ cache->indices = GWN_indexbuf_build(&elb);
+}
+
+static void particle_batch_cache_ensure_pos(Object *object, ParticleSystem *psys, ParticleBatchCache *cache)
+{
+ if (cache->pos != NULL) {
+ return;
+ }
+
+ static Gwn_VertFormat format = { 0 };
+ static unsigned pos_id, rot_id, val_id;
+ int i, curr_point;
+ ParticleData *pa;
+ ParticleKey state;
+ ParticleSimulationData sim = {NULL};
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ sim.depsgraph = draw_ctx->depsgraph;
+ sim.scene = draw_ctx->scene;
+ sim.ob = object;
+ sim.psys = psys;
+ sim.psmd = psys_get_modifier(object, psys);
+
+ if (psys->part->phystype == PART_PHYS_KEYED) {
+ if (psys->flag & PSYS_KEYED) {
+ psys_count_keyed_targets(&sim);
+ if (psys->totkeyed == 0)
+ return;
+ }
+ }
+
+ GWN_VERTBUF_DISCARD_SAFE(cache->pos);
+ GWN_INDEXBUF_DISCARD_SAFE(cache->indices);
+
+ if (format.attrib_ct == 0) {
+ /* initialize vertex format */
+ pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ rot_id = GWN_vertformat_attr_add(&format, "rot", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ val_id = GWN_vertformat_attr_add(&format, "val", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ }
+
+ cache->pos = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(cache->pos, psys->totpart);
+
+ for (curr_point = 0, i = 0, pa = psys->particles; i < psys->totpart; i++, pa++) {
+ state.time = DEG_get_ctime(draw_ctx->depsgraph);
+ if (!psys_get_particle_state(&sim, curr_point, &state, 0)) {
+ continue;
+ }
+
+ float val;
+
+ GWN_vertbuf_attr_set(cache->pos, pos_id, curr_point, pa->state.co);
+ GWN_vertbuf_attr_set(cache->pos, rot_id, curr_point, pa->state.rot);
+
+ switch (psys->part->draw_col) {
+ case PART_DRAW_COL_VEL:
+ val = len_v3(pa->state.vel) / psys->part->color_vec_max;
+ break;
+ case PART_DRAW_COL_ACC:
+ val = len_v3v3(pa->state.vel, pa->prev_state.vel) / ((pa->state.time - pa->prev_state.time) * psys->part->color_vec_max);
+ break;
+ default:
+ val = -1.0f;
+ break;
+ }
+
+ GWN_vertbuf_attr_set(cache->pos, val_id, curr_point, &val);
+
+ curr_point++;
+ }
+
+ if (curr_point != psys->totpart) {
+ GWN_vertbuf_data_resize(cache->pos, curr_point);
+ }
+}
+
+Gwn_Batch *DRW_particles_batch_cache_get_hair(ParticleSystem *psys, ModifierData *md)
+{
+ ParticleBatchCache *cache = particle_batch_cache_get(psys);
+
+ if (cache->hairs == NULL) {
+ ensure_seg_pt_count(psys, cache);
+ particle_batch_cache_ensure_pos_and_seg(psys, md, cache);
+ cache->hairs = GWN_batch_create(GWN_PRIM_LINE_STRIP, cache->pos, cache->indices);
+ }
+
+ return cache->hairs;
+}
+
+Gwn_Batch *DRW_particles_batch_cache_get_dots(Object *object, ParticleSystem *psys)
+{
+ ParticleBatchCache *cache = particle_batch_cache_get(psys);
+
+ if (cache->hairs == NULL) {
+ particle_batch_cache_ensure_pos(object, psys, cache);
+ cache->hairs = GWN_batch_create(GWN_PRIM_POINTS, cache->pos, NULL);
+ }
+
+ return cache->hairs;
+}
diff --git a/source/blender/draw/intern/draw_common.c b/source/blender/draw/intern/draw_common.c
new file mode 100644
index 00000000000..2c606aa57d7
--- /dev/null
+++ b/source/blender/draw/intern/draw_common.c
@@ -0,0 +1,719 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_common.c
+ * \ingroup draw
+ */
+
+#include "DRW_render.h"
+
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "UI_resources.h"
+
+#include "BKE_global.h"
+#include "BKE_colorband.h"
+
+#include "draw_common.h"
+
+#if 0
+#define UI_COLOR_RGB_FROM_U8(r, g, b, v4) \
+ ARRAY_SET_ITEMS(v4, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, 1.0)
+#endif
+#define UI_COLOR_RGBA_FROM_U8(r, g, b, a, v4) \
+ ARRAY_SET_ITEMS(v4, (float)r / 255.0f, (float)g / 255.0f, (float)b / 255.0f, (float)a / 255.0f)
+
+/* Colors & Constant */
+GlobalsUboStorage ts;
+struct GPUUniformBuffer *globals_ubo = NULL;
+struct GPUTexture *globals_ramp = NULL;
+
+void DRW_globals_update(void)
+{
+ UI_GetThemeColor4fv(TH_WIRE, ts.colorWire);
+ UI_GetThemeColor4fv(TH_WIRE_EDIT, ts.colorWireEdit);
+ UI_GetThemeColor4fv(TH_ACTIVE, ts.colorActive);
+ UI_GetThemeColor4fv(TH_SELECT, ts.colorSelect);
+ UI_GetThemeColor4fv(TH_TRANSFORM, ts.colorTransform);
+ UI_COLOR_RGBA_FROM_U8(0x88, 0xFF, 0xFF, 155, ts.colorLibrarySelect);
+ UI_COLOR_RGBA_FROM_U8(0x55, 0xCC, 0xCC, 155, ts.colorLibrary);
+ UI_GetThemeColor4fv(TH_LAMP, ts.colorLamp);
+ UI_GetThemeColor4fv(TH_SPEAKER, ts.colorSpeaker);
+ UI_GetThemeColor4fv(TH_CAMERA, ts.colorCamera);
+ UI_GetThemeColor4fv(TH_EMPTY, ts.colorEmpty);
+ UI_GetThemeColor4fv(TH_VERTEX, ts.colorVertex);
+ UI_GetThemeColor4fv(TH_VERTEX_SELECT, ts.colorVertexSelect);
+ UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, ts.colorEditMeshActive);
+ UI_GetThemeColor4fv(TH_EDGE_SELECT, ts.colorEdgeSelect);
+ UI_GetThemeColor4fv(TH_EDGE_SEAM, ts.colorEdgeSeam);
+ UI_GetThemeColor4fv(TH_EDGE_SHARP, ts.colorEdgeSharp);
+ UI_GetThemeColor4fv(TH_EDGE_CREASE, ts.colorEdgeCrease);
+ UI_GetThemeColor4fv(TH_EDGE_BEVEL, ts.colorEdgeBWeight);
+ UI_GetThemeColor4fv(TH_EDGE_FACESEL, ts.colorEdgeFaceSelect);
+ UI_GetThemeColor4fv(TH_FACE, ts.colorFace);
+ UI_GetThemeColor4fv(TH_FACE_SELECT, ts.colorFaceSelect);
+ UI_GetThemeColor4fv(TH_NORMAL, ts.colorNormal);
+ UI_GetThemeColor4fv(TH_VNORMAL, ts.colorVNormal);
+ UI_GetThemeColor4fv(TH_LNORMAL, ts.colorLNormal);
+ UI_GetThemeColor4fv(TH_FACE_DOT, ts.colorFaceDot);
+ UI_GetThemeColor4fv(TH_BACK, ts.colorBackground);
+
+ /* Curve */
+ UI_GetThemeColor4fv(TH_HANDLE_FREE, ts.colorHandleFree);
+ UI_GetThemeColor4fv(TH_HANDLE_AUTO, ts.colorHandleAuto);
+ UI_GetThemeColor4fv(TH_HANDLE_VECT, ts.colorHandleVect);
+ UI_GetThemeColor4fv(TH_HANDLE_ALIGN, ts.colorHandleAlign);
+ UI_GetThemeColor4fv(TH_HANDLE_AUTOCLAMP, ts.colorHandleAutoclamp);
+ UI_GetThemeColor4fv(TH_HANDLE_SEL_FREE, ts.colorHandleSelFree);
+ UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTO, ts.colorHandleSelAuto);
+ UI_GetThemeColor4fv(TH_HANDLE_SEL_VECT, ts.colorHandleSelVect);
+ UI_GetThemeColor4fv(TH_HANDLE_SEL_ALIGN, ts.colorHandleSelAlign);
+ UI_GetThemeColor4fv(TH_HANDLE_SEL_AUTOCLAMP, ts.colorHandleSelAutoclamp);
+ UI_GetThemeColor4fv(TH_NURB_ULINE, ts.colorNurbUline);
+ UI_GetThemeColor4fv(TH_NURB_SEL_ULINE, ts.colorNurbSelUline);
+ UI_GetThemeColor4fv(TH_ACTIVE_SPLINE, ts.colorActiveSpline);
+
+ /* Grid */
+ UI_GetThemeColorShade4fv(TH_GRID, 10, ts.colorGrid);
+ /* emphasise division lines lighter instead of darker, if background is darker than grid */
+ UI_GetThemeColorShade4fv(
+ TH_GRID,
+ (ts.colorGrid[0] + ts.colorGrid[1] + ts.colorGrid[2] + 0.12f >
+ ts.colorBackground[0] + ts.colorBackground[1] + ts.colorBackground[2]) ?
+ 20 : -10, ts.colorGridEmphasise);
+ /* Grid Axis */
+ UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_X, 0.5f, -10, ts.colorGridAxisX);
+ UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Y, 0.5f, -10, ts.colorGridAxisY);
+ UI_GetThemeColorBlendShade4fv(TH_GRID, TH_AXIS_Z, 0.5f, -10, ts.colorGridAxisZ);
+
+ UI_GetThemeColorShadeAlpha4fv(TH_TRANSFORM, 0, -80, ts.colorDeselect);
+ UI_GetThemeColorShadeAlpha4fv(TH_WIRE, 0, -30, ts.colorOutline);
+ UI_GetThemeColorShadeAlpha4fv(TH_LAMP, 0, 255, ts.colorLampNoAlpha);
+
+ ts.sizeLampCenter = (U.obcenter_dia + 1.5f) * U.pixelsize;
+ ts.sizeLampCircle = U.pixelsize * 9.0f;
+ ts.sizeLampCircleShadow = ts.sizeLampCircle + U.pixelsize * 3.0f;
+
+ /* M_SQRT2 to be at least the same size of the old square */
+ ts.sizeVertex = ceilf(UI_GetThemeValuef(TH_VERTEX_SIZE) * (float)M_SQRT2 / 2.0f);
+ ts.sizeFaceDot = ceilf(UI_GetThemeValuef(TH_FACEDOT_SIZE) * (float)M_SQRT2);
+ ts.sizeEdge = 1.0f / 2.0f; /* TODO Theme */
+ ts.sizeEdgeFix = 0.5f + 2.0f * (2.0f * (MAX2(ts.sizeVertex, ts.sizeEdge)) * (float)M_SQRT1_2);
+
+
+ if (globals_ubo == NULL) {
+ globals_ubo = DRW_uniformbuffer_create(sizeof(GlobalsUboStorage), &ts);
+ }
+
+ DRW_uniformbuffer_update(globals_ubo, &ts);
+
+ ColorBand ramp = {0};
+ float *colors;
+ int col_size;
+
+ ramp.tot = 3;
+ ramp.data[0].a = 1.0f;
+ ramp.data[0].b = 1.0f;
+ ramp.data[0].pos = 0.0f;
+ ramp.data[1].a = 1.0f;
+ ramp.data[1].g = 1.0f;
+ ramp.data[1].pos = 0.5f;
+ ramp.data[2].a = 1.0f;
+ ramp.data[2].r = 1.0f;
+ ramp.data[2].pos = 1.0f;
+
+ BKE_colorband_evaluate_table_rgba(&ramp, &colors, &col_size);
+
+ if (globals_ramp) {
+ GPU_texture_free(globals_ramp);
+ }
+ globals_ramp = GPU_texture_create_1D(col_size, GPU_RGBA8, colors, NULL);
+
+ MEM_freeN(colors);
+}
+
+/* ********************************* SHGROUP ************************************* */
+
+extern char datatoc_armature_axes_vert_glsl[];
+extern char datatoc_armature_sphere_solid_vert_glsl[];
+extern char datatoc_armature_sphere_solid_frag_glsl[];
+extern char datatoc_armature_sphere_outline_vert_glsl[];
+extern char datatoc_armature_envelope_solid_vert_glsl[];
+extern char datatoc_armature_envelope_solid_frag_glsl[];
+extern char datatoc_armature_envelope_outline_vert_glsl[];
+extern char datatoc_armature_envelope_distance_frag_glsl[];
+extern char datatoc_armature_shape_solid_vert_glsl[];
+extern char datatoc_armature_shape_solid_frag_glsl[];
+extern char datatoc_armature_shape_outline_vert_glsl[];
+extern char datatoc_armature_shape_outline_geom_glsl[];
+extern char datatoc_gpu_shader_flat_color_frag_glsl[];
+
+extern char datatoc_object_mball_handles_vert_glsl[];
+
+static struct {
+ struct GPUShader *shape_outline;
+ struct GPUShader *shape_solid;
+ struct GPUShader *bone_axes;
+ struct GPUShader *bone_envelope;
+ struct GPUShader *bone_envelope_distance;
+ struct GPUShader *bone_envelope_outline;
+ struct GPUShader *bone_sphere;
+ struct GPUShader *bone_sphere_outline;
+
+ struct GPUShader *mball_handles;
+} g_shaders = {NULL};
+
+static struct {
+ struct Gwn_VertFormat *instance_screenspace;
+ struct Gwn_VertFormat *instance_color;
+ struct Gwn_VertFormat *instance_screen_aligned;
+ struct Gwn_VertFormat *instance_scaled;
+ struct Gwn_VertFormat *instance_sized;
+ struct Gwn_VertFormat *instance_outline;
+ struct Gwn_VertFormat *instance;
+ struct Gwn_VertFormat *instance_camera;
+ struct Gwn_VertFormat *instance_distance_lines;
+ struct Gwn_VertFormat *instance_spot;
+ struct Gwn_VertFormat *instance_bone;
+ struct Gwn_VertFormat *instance_bone_outline;
+ struct Gwn_VertFormat *instance_bone_envelope;
+ struct Gwn_VertFormat *instance_bone_envelope_distance;
+ struct Gwn_VertFormat *instance_bone_envelope_outline;
+ struct Gwn_VertFormat *instance_mball_handles;
+} g_formats = {NULL};
+
+void DRW_globals_free(void)
+{
+ struct Gwn_VertFormat **format = &g_formats.instance_screenspace;
+ for (int i = 0; i < sizeof(g_formats) / sizeof(void *); ++i, ++format) {
+ MEM_SAFE_FREE(*format);
+ }
+
+ struct GPUShader **shader = &g_shaders.shape_outline;
+ for (int i = 0; i < sizeof(g_shaders) / sizeof(void *); ++i, ++shader) {
+ DRW_SHADER_FREE_SAFE(*shader);
+ }
+}
+
+DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(DRWPass *pass, float color[4])
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
+
+ static float dash_width = 12.0f;
+ static float dash_factor = 0.5f;
+ DRWShadingGroup *grp = DRW_shgroup_line_batch_create(sh, pass);
+ DRW_shgroup_uniform_vec4(grp, "color", color, 1);
+ DRW_shgroup_uniform_vec2(grp, "viewport_size", DRW_viewport_size_get(), 1);
+ DRW_shgroup_uniform_float(grp, "dash_width", &dash_width, 1);
+ DRW_shgroup_uniform_float(grp, "dash_factor", &dash_factor, 1);
+ DRW_shgroup_uniform_int_copy(grp, "num_colors", 0); /* "simple" mode */
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_dynpoints_uniform_color(DRWPass *pass, float color[4], float *size)
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
+
+ DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
+ DRW_shgroup_uniform_vec4(grp, "color", color, 1);
+ DRW_shgroup_uniform_float(grp, "size", size, 1);
+ DRW_shgroup_state_enable(grp, DRW_STATE_POINT);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_groundlines_uniform_color(DRWPass *pass, float color[4])
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDLINE);
+
+ DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
+ DRW_shgroup_uniform_vec4(grp, "color", color, 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_groundpoints_uniform_color(DRWPass *pass, float color[4])
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_GROUNDPOINT);
+
+ DRWShadingGroup *grp = DRW_shgroup_point_batch_create(sh, pass);
+ DRW_shgroup_uniform_vec4(grp, "color", color, 1);
+ DRW_shgroup_state_enable(grp, DRW_STATE_POINT);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_screenspace(DRWPass *pass, struct Gwn_Batch *geom, float *size)
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR);
+
+ DRW_shgroup_instance_format(g_formats.instance_screenspace, {
+ {"world_pos", DRW_ATTRIB_FLOAT, 3},
+ {"color" , DRW_ATTRIB_FLOAT, 3}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screenspace);
+ DRW_shgroup_uniform_float(grp, "size", size, 1);
+ DRW_shgroup_uniform_float(grp, "pixel_size", DRW_viewport_pixelsize_get(), 1);
+ DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
+ DRW_shgroup_state_enable(grp, DRW_STATE_STIPPLE_3);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_solid(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ static float light[3] = {0.0f, 0.0f, 1.0f};
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR);
+
+ DRW_shgroup_instance_format(g_formats.instance_color, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"color" , DRW_ATTRIB_FLOAT, 4}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_color);
+ DRW_shgroup_uniform_vec3(grp, "light", light, 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_wire(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR);
+
+ DRW_shgroup_instance_format(g_formats.instance_color, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"color" , DRW_ATTRIB_FLOAT, 4}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_color);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_screen_aligned(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED);
+
+ DRW_shgroup_instance_format(g_formats.instance_screen_aligned, {
+ {"color" , DRW_ATTRIB_FLOAT, 3},
+ {"size" , DRW_ATTRIB_FLOAT, 1},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screen_aligned);
+ DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_axis_names(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS);
+
+ DRW_shgroup_instance_format(g_formats.instance_screen_aligned, {
+ {"color" , DRW_ATTRIB_FLOAT, 3},
+ {"size" , DRW_ATTRIB_FLOAT, 1},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh, pass, geom, g_formats.instance_screen_aligned);
+ DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_scaled(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE);
+
+ DRW_shgroup_instance_format(g_formats.instance_scaled, {
+ {"color" , DRW_ATTRIB_FLOAT, 3},
+ {"size" , DRW_ATTRIB_FLOAT, 3},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_scaled);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE);
+
+ DRW_shgroup_instance_format(g_formats.instance_sized, {
+ {"color" , DRW_ATTRIB_FLOAT, 3},
+ {"size" , DRW_ATTRIB_FLOAT, 1},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_sized);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_outline(DRWPass *pass, struct Gwn_Batch *geom, int *baseid)
+{
+ GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE);
+
+ DRW_shgroup_instance_format(g_formats.instance_outline, {
+ {"callId" , DRW_ATTRIB_INT, 1},
+ {"size" , DRW_ATTRIB_FLOAT, 1},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_outline);
+ DRW_shgroup_uniform_int(grp, "baseId", baseid, 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_camera_instance(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_CAMERA);
+
+ DRW_shgroup_instance_format(g_formats.instance_camera, {
+ {"color" , DRW_ATTRIB_FLOAT, 3},
+ {"corners" , DRW_ATTRIB_FLOAT, 8},
+ {"depth" , DRW_ATTRIB_FLOAT, 1},
+ {"tria" , DRW_ATTRIB_FLOAT, 4},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_camera);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_distance_lines_instance(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_DISTANCE_LINES);
+ static float point_size = 4.0f;
+
+ DRW_shgroup_instance_format(g_formats.instance_distance_lines, {
+ {"color" , DRW_ATTRIB_FLOAT, 3},
+ {"start" , DRW_ATTRIB_FLOAT, 1},
+ {"end" , DRW_ATTRIB_FLOAT, 1},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_distance_lines);
+ DRW_shgroup_uniform_float(grp, "size", &point_size, 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_spot_instance(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ GPUShader *sh_inst = GPU_shader_get_builtin_shader(GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR);
+ static const int True = true;
+ static const int False = false;
+
+ DRW_shgroup_instance_format(g_formats.instance_spot, {
+ {"color" , DRW_ATTRIB_FLOAT, 3},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(sh_inst, pass, geom, g_formats.instance_spot);
+ DRW_shgroup_uniform_bool(grp, "drawFront", &False, 1);
+ DRW_shgroup_uniform_bool(grp, "drawBack", &False, 1);
+ DRW_shgroup_uniform_bool(grp, "drawSilhouette", &True, 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_bone_axes(DRWPass *pass)
+{
+ if (g_shaders.bone_axes == NULL) {
+ g_shaders.bone_axes = DRW_shader_create(
+ datatoc_armature_axes_vert_glsl, NULL,
+ datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_color, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"color" , DRW_ATTRIB_FLOAT, 4}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_axes,
+ pass, DRW_cache_bone_arrows_get(),
+ g_formats.instance_color);
+ DRW_shgroup_uniform_vec3(grp, "screenVecs[0]", DRW_viewport_screenvecs_get(), 2);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_bone_envelope_outline(DRWPass *pass)
+{
+ if (g_shaders.bone_envelope_outline == NULL) {
+ g_shaders.bone_envelope_outline = DRW_shader_create(
+ datatoc_armature_envelope_outline_vert_glsl, NULL,
+ datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_bone_envelope_outline, {
+ {"headSphere" , DRW_ATTRIB_FLOAT, 4},
+ {"tailSphere" , DRW_ATTRIB_FLOAT, 4},
+ {"outlineColorSize" , DRW_ATTRIB_FLOAT, 4},
+ {"xAxis" , DRW_ATTRIB_FLOAT, 3}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_envelope_outline,
+ pass, DRW_cache_bone_envelope_outline_get(),
+ g_formats.instance_bone_envelope_outline);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_bone_envelope_distance(DRWPass *pass)
+{
+ if (g_shaders.bone_envelope_distance == NULL) {
+ g_shaders.bone_envelope_distance = DRW_shader_create(
+ datatoc_armature_envelope_solid_vert_glsl, NULL,
+ datatoc_armature_envelope_distance_frag_glsl, NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_bone_envelope_distance, {
+ {"headSphere" , DRW_ATTRIB_FLOAT, 4},
+ {"tailSphere" , DRW_ATTRIB_FLOAT, 4},
+ {"xAxis" , DRW_ATTRIB_FLOAT, 3}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_envelope_distance,
+ pass, DRW_cache_bone_envelope_solid_get(),
+ g_formats.instance_bone_envelope_distance);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_bone_envelope_solid(DRWPass *pass)
+{
+ if (g_shaders.bone_envelope == NULL) {
+ g_shaders.bone_envelope = DRW_shader_create(
+ datatoc_armature_envelope_solid_vert_glsl, NULL,
+ datatoc_armature_envelope_solid_frag_glsl, "#define SMOOTH_ENVELOPE\n");
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_bone_envelope, {
+ {"headSphere" , DRW_ATTRIB_FLOAT, 4},
+ {"tailSphere" , DRW_ATTRIB_FLOAT, 4},
+ {"boneColor" , DRW_ATTRIB_FLOAT, 3},
+ {"stateColor" , DRW_ATTRIB_FLOAT, 3},
+ {"xAxis" , DRW_ATTRIB_FLOAT, 3}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_envelope,
+ pass, DRW_cache_bone_envelope_solid_get(),
+ g_formats.instance_bone_envelope);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_mball_handles(DRWPass *pass)
+{
+ if (g_shaders.mball_handles == NULL) {
+ g_shaders.mball_handles = DRW_shader_create(
+ datatoc_object_mball_handles_vert_glsl, NULL,
+ datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_mball_handles, {
+ {"ScaleTranslationMatrix" , DRW_ATTRIB_FLOAT, 12},
+ {"radius" , DRW_ATTRIB_FLOAT, 1},
+ {"color" , DRW_ATTRIB_FLOAT, 3}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.mball_handles, pass,
+ DRW_cache_screenspace_circle_get(),
+ g_formats.instance_mball_handles);
+ DRW_shgroup_uniform_vec3(grp, "screen_vecs[0]", DRW_viewport_screenvecs_get(), 2);
+
+ return grp;
+}
+
+/* Only works with batches with adjacency infos. */
+DRWShadingGroup *shgroup_instance_bone_shape_outline(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ if (g_shaders.shape_outline == NULL) {
+ g_shaders.shape_outline = DRW_shader_create(
+ datatoc_armature_shape_outline_vert_glsl,
+ datatoc_armature_shape_outline_geom_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl,
+ NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"outlineColorSize" , DRW_ATTRIB_FLOAT, 4}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.shape_outline,
+ pass, geom, g_formats.instance_bone_outline);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_bone_shape_solid(DRWPass *pass, struct Gwn_Batch *geom)
+{
+ if (g_shaders.shape_solid == NULL) {
+ g_shaders.shape_solid = DRW_shader_create(
+ datatoc_armature_shape_solid_vert_glsl, NULL,
+ datatoc_armature_shape_solid_frag_glsl, NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_bone, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"boneColor" , DRW_ATTRIB_FLOAT, 3},
+ {"stateColor" , DRW_ATTRIB_FLOAT, 3}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.shape_solid,
+ pass, geom, g_formats.instance_bone);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_bone_sphere_solid(DRWPass *pass)
+{
+ if (g_shaders.bone_sphere == NULL) {
+ g_shaders.bone_sphere = DRW_shader_create(
+ datatoc_armature_sphere_solid_vert_glsl, NULL,
+ datatoc_armature_sphere_solid_frag_glsl, NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_bone, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"boneColor" , DRW_ATTRIB_FLOAT, 3},
+ {"stateColor" , DRW_ATTRIB_FLOAT, 3}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_sphere,
+ pass, DRW_cache_bone_point_get(), g_formats.instance_bone);
+
+ return grp;
+}
+
+DRWShadingGroup *shgroup_instance_bone_sphere_outline(DRWPass *pass)
+{
+ if (g_shaders.bone_sphere_outline == NULL) {
+ g_shaders.bone_sphere_outline = DRW_shader_create(
+ datatoc_armature_sphere_outline_vert_glsl, NULL,
+ datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+ }
+
+ DRW_shgroup_instance_format(g_formats.instance_bone_outline, {
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ {"outlineColorSize" , DRW_ATTRIB_FLOAT, 4}
+ });
+
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(g_shaders.bone_sphere_outline,
+ pass, DRW_cache_bone_point_wire_outline_get(),
+ g_formats.instance_bone_outline);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+
+ return grp;
+}
+
+
+/* ******************************************** COLOR UTILS *********************************************** */
+
+/* TODO FINISH */
+/**
+ * Get the wire color theme_id of an object based on it's state
+ * \a r_color is a way to get a pointer to the static color var associated
+ */
+int DRW_object_wire_theme_get(Object *ob, ViewLayer *view_layer, float **r_color)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const bool is_edit = (draw_ctx->object_mode & OB_MODE_EDIT) != 0;
+ const bool active = (view_layer->basact && view_layer->basact->object == ob);
+ /* confusing logic here, there are 2 methods of setting the color
+ * 'colortab[colindex]' and 'theme_id', colindex overrides theme_id.
+ *
+ * note: no theme yet for 'colindex' */
+ int theme_id = is_edit ? TH_WIRE_EDIT : TH_WIRE;
+
+ if (//(scene->obedit == NULL) &&
+ ((G.moving & G_TRANSFORM_OBJ) != 0) &&
+ ((ob->base_flag & BASE_SELECTED) != 0))
+ {
+ theme_id = TH_TRANSFORM;
+ }
+ else {
+ /* Sets the 'theme_id' or fallback to wire */
+ if ((ob->base_flag & BASE_SELECTED) != 0) {
+ theme_id = (active) ? TH_ACTIVE : TH_SELECT;
+ }
+ else {
+ if (ob->type == OB_LAMP) theme_id = TH_LAMP;
+ else if (ob->type == OB_SPEAKER) theme_id = TH_SPEAKER;
+ else if (ob->type == OB_CAMERA) theme_id = TH_CAMERA;
+ else if (ob->type == OB_EMPTY) theme_id = TH_EMPTY;
+ else if (ob->type == OB_LIGHTPROBE) theme_id = TH_EMPTY; /* TODO add lightprobe color */
+ /* fallback to TH_WIRE */
+ }
+ }
+
+ if (r_color != NULL) {
+ switch (theme_id) {
+ case TH_WIRE_EDIT: *r_color = ts.colorWireEdit; break;
+ case TH_ACTIVE: *r_color = ts.colorActive; break;
+ case TH_SELECT: *r_color = ts.colorSelect; break;
+ case TH_TRANSFORM: *r_color = ts.colorTransform; break;
+ case OB_SPEAKER: *r_color = ts.colorSpeaker; break;
+ case OB_CAMERA: *r_color = ts.colorCamera; break;
+ case OB_EMPTY: *r_color = ts.colorEmpty; break;
+ case OB_LAMP: *r_color = ts.colorLamp; break;
+ default: *r_color = ts.colorWire; break;
+ }
+ }
+
+ return theme_id;
+}
+
+/* XXX This is utter shit, better find something more general */
+float *DRW_color_background_blend_get(int theme_id)
+{
+ static float colors[11][4];
+ float *ret;
+
+ switch (theme_id) {
+ case TH_WIRE_EDIT: ret = colors[0]; break;
+ case TH_ACTIVE: ret = colors[1]; break;
+ case TH_SELECT: ret = colors[2]; break;
+ case TH_TRANSFORM: ret = colors[5]; break;
+ case OB_SPEAKER: ret = colors[6]; break;
+ case OB_CAMERA: ret = colors[7]; break;
+ case OB_EMPTY: ret = colors[8]; break;
+ case OB_LAMP: ret = colors[9]; break;
+ default: ret = colors[10]; break;
+ }
+
+ UI_GetThemeColorBlendShade4fv(theme_id, TH_BACK, 0.5, 0, ret);
+
+ return ret;
+}
diff --git a/source/blender/draw/intern/draw_common.h b/source/blender/draw/intern/draw_common.h
new file mode 100644
index 00000000000..8730be54d93
--- /dev/null
+++ b/source/blender/draw/intern/draw_common.h
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_common.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_COMMON_H__
+#define __DRAW_COMMON_H__
+
+struct DRWPass;
+struct DRWShadingGroup;
+struct Gwn_Batch;
+struct Object;
+struct ViewLayer;
+
+/* Used as ubo but colors can be directly referenced as well */
+/* Keep in sync with: common_globals_lib.glsl (globalsBlock) */
+typedef struct GlobalsUboStorage {
+ /* UBOs data needs to be 16 byte aligned (size of vec4) */
+ float colorWire[4];
+ float colorWireEdit[4];
+ float colorActive[4];
+ float colorSelect[4];
+ float colorTransform[4];
+ float colorLibrarySelect[4];
+ float colorLibrary[4];
+ float colorLamp[4];
+ float colorSpeaker[4];
+ float colorCamera[4];
+ float colorEmpty[4];
+ float colorVertex[4];
+ float colorVertexSelect[4];
+ float colorEditMeshActive[4];
+ float colorEdgeSelect[4];
+ float colorEdgeSeam[4];
+ float colorEdgeSharp[4];
+ float colorEdgeCrease[4];
+ float colorEdgeBWeight[4];
+ float colorEdgeFaceSelect[4];
+ float colorFace[4];
+ float colorFaceSelect[4];
+ float colorNormal[4];
+ float colorVNormal[4];
+ float colorLNormal[4];
+ float colorFaceDot[4];
+
+ float colorDeselect[4];
+ float colorOutline[4];
+ float colorLampNoAlpha[4];
+
+ float colorBackground[4];
+
+ float colorHandleFree[4];
+ float colorHandleAuto[4];
+ float colorHandleVect[4];
+ float colorHandleAlign[4];
+ float colorHandleAutoclamp[4];
+ float colorHandleSelFree[4];
+ float colorHandleSelAuto[4];
+ float colorHandleSelVect[4];
+ float colorHandleSelAlign[4];
+ float colorHandleSelAutoclamp[4];
+ float colorNurbUline[4];
+ float colorNurbSelUline[4];
+ float colorActiveSpline[4];
+
+ float colorGrid[4];
+ float colorGridEmphasise[4];
+ float colorGridAxisX[4];
+ float colorGridAxisY[4];
+ float colorGridAxisZ[4];
+
+ /* Pack individual float at the end of the buffer to avoid alignement errors */
+ float sizeLampCenter, sizeLampCircle, sizeLampCircleShadow;
+ float sizeVertex, sizeEdge, sizeEdgeFix, sizeFaceDot;
+ float gridDistance, gridResolution, gridSubdivisions, gridScale;
+} GlobalsUboStorage;
+/* Keep in sync with globalsBlock in shaders */
+
+void DRW_globals_update(void);
+void DRW_globals_free(void);
+
+struct DRWShadingGroup *shgroup_dynlines_dashed_uniform_color(struct DRWPass *pass, float color[4]);
+struct DRWShadingGroup *shgroup_dynpoints_uniform_color(struct DRWPass *pass, float color[4], float *size);
+struct DRWShadingGroup *shgroup_groundlines_uniform_color(struct DRWPass *pass, float color[4]);
+struct DRWShadingGroup *shgroup_groundpoints_uniform_color(struct DRWPass *pass, float color[4]);
+struct DRWShadingGroup *shgroup_instance_screenspace(struct DRWPass *pass, struct Gwn_Batch *geom, float *size);
+struct DRWShadingGroup *shgroup_instance_solid(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_wire(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_screen_aligned(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_axis_names(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_image_plane(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_scaled(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_outline(struct DRWPass *pass, struct Gwn_Batch *geom, int *baseid);
+struct DRWShadingGroup *shgroup_camera_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_distance_lines_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_spot_instance(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_mball_handles(struct DRWPass *pass);
+struct DRWShadingGroup *shgroup_instance_bone_axes(struct DRWPass *pass);
+struct DRWShadingGroup *shgroup_instance_bone_envelope_distance(struct DRWPass *pass);
+struct DRWShadingGroup *shgroup_instance_bone_envelope_outline(struct DRWPass *pass);
+struct DRWShadingGroup *shgroup_instance_bone_envelope_solid(struct DRWPass *pass);
+struct DRWShadingGroup *shgroup_instance_bone_shape_outline(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_bone_shape_solid(struct DRWPass *pass, struct Gwn_Batch *geom);
+struct DRWShadingGroup *shgroup_instance_bone_sphere_outline(struct DRWPass *pass);
+struct DRWShadingGroup *shgroup_instance_bone_sphere_solid(struct DRWPass *pass);
+
+int DRW_object_wire_theme_get(
+ struct Object *ob, struct ViewLayer *view_layer, float **r_color);
+float *DRW_color_background_blend_get(int theme_id);
+
+/* draw_armature.c */
+typedef struct DRWArmaturePasses{
+ struct DRWPass *bone_solid;
+ struct DRWPass *bone_outline;
+ struct DRWPass *bone_wire;
+ struct DRWPass *bone_envelope;
+ struct DRWPass *bone_axes;
+ struct DRWPass *relationship_lines;
+} DRWArmaturePasses;
+
+void DRW_shgroup_armature_object(struct Object *ob, struct ViewLayer *view_layer, struct DRWArmaturePasses passes);
+void DRW_shgroup_armature_pose(struct Object *ob, struct DRWArmaturePasses passes);
+void DRW_shgroup_armature_edit(struct Object *ob, struct DRWArmaturePasses passes);
+
+/* pose_mode.c */
+bool DRW_pose_mode_armature(
+ struct Object *ob, struct Object *active_ob);
+
+#endif /* __DRAW_COMMON_H__ */
diff --git a/source/blender/draw/intern/draw_instance_data.c b/source/blender/draw/intern/draw_instance_data.c
new file mode 100644
index 00000000000..350d4a0c20d
--- /dev/null
+++ b/source/blender/draw/intern/draw_instance_data.c
@@ -0,0 +1,469 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_instance_data.c
+ * \ingroup draw
+ */
+
+/**
+ * DRW Instance Data Manager
+ * This is a special memory manager that keeps memory blocks ready to send as vbo data in one continuous allocation.
+ * This way we avoid feeding gawain each instance data one by one and unecessary memcpy.
+ * Since we loose which memory block was used each DRWShadingGroup we need to redistribute them in the same order/size
+ * to avoid to realloc each frame.
+ * This is why DRWInstanceDatas are sorted in a list for each different data size.
+ **/
+
+#include "draw_instance_data.h"
+#include "DRW_engine.h"
+#include "DRW_render.h" /* For DRW_shgroup_get_instance_count() */
+
+#include "MEM_guardedalloc.h"
+#include "BLI_utildefines.h"
+
+#define BUFFER_CHUNK_SIZE 32
+#define BUFFER_VERTS_CHUNK 32
+
+typedef struct DRWBatchingBuffer {
+ struct DRWShadingGroup *shgroup; /* Link back to the owning shGroup. Also tells if it's used */
+ Gwn_VertFormat *format; /* Identifier. */
+ Gwn_VertBuf *vert; /* Gwn_VertBuf contained in the Gwn_Batch. */
+ Gwn_Batch *batch; /* Gwn_Batch containing the Gwn_VertBuf. */
+} DRWBatchingBuffer;
+
+typedef struct DRWInstancingBuffer {
+ struct DRWShadingGroup *shgroup; /* Link back to the owning shGroup. Also tells if it's used */
+ Gwn_VertFormat *format; /* Identifier. */
+ Gwn_Batch *instance; /* Identifier. */
+ Gwn_VertBuf *vert; /* Gwn_VertBuf contained in the Gwn_Batch. */
+ Gwn_Batch *batch; /* Gwn_Batch containing the Gwn_VertBuf. */
+} DRWInstancingBuffer;
+
+typedef struct DRWInstanceChunk {
+ size_t cursor; /* Offset to the next instance data. */
+ size_t alloc_size; /* Number of DRWBatchingBuffer/Batches alloc'd in ibufs/btchs. */
+ union {
+ DRWBatchingBuffer *bbufs;
+ DRWInstancingBuffer *ibufs;
+ };
+} DRWInstanceChunk;
+
+struct DRWInstanceData {
+ struct DRWInstanceData *next;
+ bool used; /* If this data is used or not. */
+ size_t chunk_size; /* Current size of the whole chunk. */
+ size_t data_size; /* Size of one instance data. */
+ size_t instance_group; /* How many instance to allocate at a time. */
+ size_t offset; /* Offset to the next instance data. */
+ float *memchunk; /* Should be float no matter what. */
+};
+
+struct DRWInstanceDataList {
+ struct DRWInstanceDataList *next, *prev;
+ /* Linked lists for all possible data pool size */
+ /* Not entirely sure if we should separate them in the first place.
+ * This is done to minimize the reattribution misses. */
+ DRWInstanceData *idata_head[MAX_INSTANCE_DATA_SIZE];
+ DRWInstanceData *idata_tail[MAX_INSTANCE_DATA_SIZE];
+
+ DRWInstanceChunk instancing;
+ DRWInstanceChunk batching;
+};
+
+static ListBase g_idatalists = {NULL, NULL};
+
+/* -------------------------------------------------------------------- */
+
+/** \name Instance Buffer Management
+ * \{ */
+
+/**
+ * This manager allows to distribute existing batches for instancing
+ * attributes. This reduce the number of batches creation.
+ * Querying a batch is done with a vertex format. This format should
+ * be static so that it's pointer never changes (because we are using
+ * this pointer as identifier [we don't want to check the full format
+ * that would be too slow]).
+ **/
+
+static void instance_batch_free(Gwn_Batch *batch, void *UNUSED(user_data))
+{
+ /* Free all batches that have the same key before they are reused. */
+ /* TODO: Make it thread safe! Batch freeing can happen from another thread. */
+ /* XXX we need to iterate over all idatalists unless we make some smart
+ * data structure to store the locations to update. */
+ for (DRWInstanceDataList *idatalist = g_idatalists.first; idatalist; idatalist = idatalist->next) {
+ DRWInstancingBuffer *ibuf = idatalist->instancing.ibufs;
+ for (int i = 0; i < idatalist->instancing.alloc_size; i++, ibuf++) {
+ if (ibuf->instance == batch) {
+ BLI_assert(ibuf->shgroup == NULL); /* Make sure it has no other users. */
+ GWN_VERTBUF_DISCARD_SAFE(ibuf->vert);
+ GWN_BATCH_DISCARD_SAFE(ibuf->batch);
+ /* Tag as non alloced. */
+ ibuf->format = NULL;
+ }
+ }
+ }
+}
+
+void DRW_batching_buffer_request(
+ DRWInstanceDataList *idatalist, Gwn_VertFormat *format, Gwn_PrimType type, struct DRWShadingGroup *shgroup,
+ Gwn_Batch **r_batch, Gwn_VertBuf **r_vert)
+{
+ DRWInstanceChunk *chunk = &idatalist->batching;
+ DRWBatchingBuffer *bbuf = idatalist->batching.bbufs;
+ BLI_assert(format);
+ /* Search for an unused batch. */
+ for (int i = 0; i < idatalist->batching.alloc_size; i++, bbuf++) {
+ if (bbuf->shgroup == NULL) {
+ if (bbuf->format == format) {
+ bbuf->shgroup = shgroup;
+ *r_batch = bbuf->batch;
+ *r_vert = bbuf->vert;
+ return;
+ }
+ }
+ }
+ int new_id = 0; /* Find insertion point. */
+ for (; new_id < chunk->alloc_size; ++new_id) {
+ if (chunk->bbufs[new_id].format == NULL)
+ break;
+ }
+ /* If there is no batch left. Allocate more. */
+ if (new_id == chunk->alloc_size) {
+ new_id = chunk->alloc_size;
+ chunk->alloc_size += BUFFER_CHUNK_SIZE;
+ chunk->bbufs = MEM_reallocN(chunk->bbufs, chunk->alloc_size * sizeof(DRWBatchingBuffer));
+ memset(chunk->bbufs + new_id, 0, sizeof(DRWBatchingBuffer) * BUFFER_CHUNK_SIZE);
+ }
+ /* Create the batch. */
+ bbuf = chunk->bbufs + new_id;
+ bbuf->vert = *r_vert = GWN_vertbuf_create_with_format_ex(format, GWN_USAGE_DYNAMIC);
+ bbuf->batch = *r_batch = GWN_batch_create_ex(type, bbuf->vert, NULL, 0);
+ bbuf->format = format;
+ bbuf->shgroup = shgroup;
+ GWN_vertbuf_data_alloc(*r_vert, BUFFER_VERTS_CHUNK);
+}
+
+void DRW_instancing_buffer_request(
+ DRWInstanceDataList *idatalist, Gwn_VertFormat *format, Gwn_Batch *instance, struct DRWShadingGroup *shgroup,
+ Gwn_Batch **r_batch, Gwn_VertBuf **r_vert)
+{
+ DRWInstanceChunk *chunk = &idatalist->instancing;
+ DRWInstancingBuffer *ibuf = idatalist->instancing.ibufs;
+ BLI_assert(format);
+ /* Search for an unused batch. */
+ for (int i = 0; i < idatalist->instancing.alloc_size; i++, ibuf++) {
+ if (ibuf->shgroup == NULL) {
+ if (ibuf->format == format) {
+ if (ibuf->instance == instance) {
+ ibuf->shgroup = shgroup;
+ *r_batch = ibuf->batch;
+ *r_vert = ibuf->vert;
+ return;
+ }
+ }
+ }
+ }
+ int new_id = 0; /* Find insertion point. */
+ for (; new_id < chunk->alloc_size; ++new_id) {
+ if (chunk->ibufs[new_id].format == NULL)
+ break;
+ }
+ /* If there is no batch left. Allocate more. */
+ if (new_id == chunk->alloc_size) {
+ new_id = chunk->alloc_size;
+ chunk->alloc_size += BUFFER_CHUNK_SIZE;
+ chunk->ibufs = MEM_reallocN(chunk->ibufs, chunk->alloc_size * sizeof(DRWInstancingBuffer));
+ memset(chunk->ibufs + new_id, 0, sizeof(DRWInstancingBuffer) * BUFFER_CHUNK_SIZE);
+ }
+ /* Create the batch. */
+ ibuf = chunk->ibufs + new_id;
+ ibuf->vert = *r_vert = GWN_vertbuf_create_with_format_ex(format, GWN_USAGE_DYNAMIC);
+ ibuf->batch = *r_batch = GWN_batch_duplicate(instance);
+ ibuf->format = format;
+ ibuf->shgroup = shgroup;
+ ibuf->instance = instance;
+ GWN_vertbuf_data_alloc(*r_vert, BUFFER_VERTS_CHUNK);
+ GWN_batch_instbuf_set(ibuf->batch, ibuf->vert, false);
+ /* Make sure to free this ibuf if the instance batch gets free. */
+ GWN_batch_callback_free_set(instance, &instance_batch_free, NULL);
+}
+
+void DRW_instance_buffer_finish(DRWInstanceDataList *idatalist)
+{
+ size_t realloc_size = 1; /* Avoid 0 size realloc. */
+ /* Resize down buffers in use and send data to GPU & free unused buffers. */
+ DRWInstanceChunk *batching = &idatalist->batching;
+ DRWBatchingBuffer *bbuf = batching->bbufs;
+ for (int i = 0; i < batching->alloc_size; i++, bbuf++) {
+ if (bbuf->shgroup != NULL) {
+ realloc_size = i + 1;
+ unsigned int vert_ct = DRW_shgroup_get_instance_count(bbuf->shgroup);
+ vert_ct += (vert_ct == 0) ? 1 : 0; /* Do not realloc to 0 size buffer */
+ if (vert_ct + BUFFER_VERTS_CHUNK <= bbuf->vert->vertex_ct) {
+ unsigned int size = vert_ct + BUFFER_VERTS_CHUNK - 1;
+ size = size - size % BUFFER_VERTS_CHUNK;
+ GWN_vertbuf_data_resize(bbuf->vert, size);
+ }
+ GWN_vertbuf_use(bbuf->vert); /* Send data. */
+ bbuf->shgroup = NULL; /* Set as non used for the next round. */
+ }
+ else {
+ GWN_VERTBUF_DISCARD_SAFE(bbuf->vert);
+ GWN_BATCH_DISCARD_SAFE(bbuf->batch);
+ bbuf->format = NULL; /* Tag as non alloced. */
+ }
+ }
+ /* Rounding up to nearest chunk size. */
+ realloc_size += BUFFER_CHUNK_SIZE - 1;
+ realloc_size -= realloc_size % BUFFER_CHUNK_SIZE;
+ /* Resize down if necessary. */
+ if (realloc_size < batching->alloc_size) {
+ batching->alloc_size = realloc_size;
+ batching->ibufs = MEM_reallocN(batching->ibufs, realloc_size * sizeof(DRWBatchingBuffer));
+ }
+
+ realloc_size = 1;
+ /* Resize down buffers in use and send data to GPU & free unused buffers. */
+ DRWInstanceChunk *instancing = &idatalist->instancing;
+ DRWInstancingBuffer *ibuf = instancing->ibufs;
+ for (int i = 0; i < instancing->alloc_size; i++, ibuf++) {
+ if (ibuf->shgroup != NULL) {
+ realloc_size = i + 1;
+ unsigned int vert_ct = DRW_shgroup_get_instance_count(ibuf->shgroup);
+ vert_ct += (vert_ct == 0) ? 1 : 0; /* Do not realloc to 0 size buffer */
+ if (vert_ct + BUFFER_VERTS_CHUNK <= ibuf->vert->vertex_ct) {
+ unsigned int size = vert_ct + BUFFER_VERTS_CHUNK - 1;
+ size = size - size % BUFFER_VERTS_CHUNK;
+ GWN_vertbuf_data_resize(ibuf->vert, size);
+ }
+ GWN_vertbuf_use(ibuf->vert); /* Send data. */
+ ibuf->shgroup = NULL; /* Set as non used for the next round. */
+ }
+ else {
+ GWN_VERTBUF_DISCARD_SAFE(ibuf->vert);
+ GWN_BATCH_DISCARD_SAFE(ibuf->batch);
+ ibuf->format = NULL; /* Tag as non alloced. */
+ }
+ }
+ /* Rounding up to nearest chunk size. */
+ realloc_size += BUFFER_CHUNK_SIZE - 1;
+ realloc_size -= realloc_size % BUFFER_CHUNK_SIZE;
+ /* Resize down if necessary. */
+ if (realloc_size < instancing->alloc_size) {
+ instancing->alloc_size = realloc_size;
+ instancing->ibufs = MEM_reallocN(instancing->ibufs, realloc_size * sizeof(DRWInstancingBuffer));
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Instance Data (DRWInstanceData)
+ * \{ */
+
+static DRWInstanceData *drw_instance_data_create(
+ DRWInstanceDataList *idatalist, unsigned int attrib_size, unsigned int instance_group)
+{
+ DRWInstanceData *idata = MEM_callocN(sizeof(DRWInstanceData), "DRWInstanceData");
+ idata->next = NULL;
+ idata->used = true;
+ idata->data_size = attrib_size;
+ idata->instance_group = instance_group;
+ idata->chunk_size = idata->data_size * instance_group;
+ idata->offset = 0;
+ idata->memchunk = MEM_mallocN(idata->chunk_size * sizeof(float), "DRWInstanceData memchunk");
+
+ BLI_assert(attrib_size > 0);
+
+ /* Push to linked list. */
+ if (idatalist->idata_head[attrib_size - 1] == NULL) {
+ idatalist->idata_head[attrib_size - 1] = idata;
+ }
+ else {
+ idatalist->idata_tail[attrib_size - 1]->next = idata;
+ }
+ idatalist->idata_tail[attrib_size - 1] = idata;
+
+ return idata;
+}
+
+static void DRW_instance_data_free(DRWInstanceData *idata)
+{
+ MEM_freeN(idata->memchunk);
+}
+
+/**
+ * Return a pointer to the next instance data space.
+ * DO NOT SAVE/REUSE THIS POINTER after the next call
+ * to this function since the chunk may have been
+ * reallocated.
+ **/
+void *DRW_instance_data_next(DRWInstanceData *idata)
+{
+ idata->offset += idata->data_size;
+
+ /* Check if chunk is large enough. realloc otherwise. */
+ if (idata->offset > idata->chunk_size) {
+ idata->chunk_size += idata->data_size * idata->instance_group;
+ idata->memchunk = MEM_reallocN(idata->memchunk, idata->chunk_size * sizeof(float));
+ }
+
+ return idata->memchunk + (idata->offset - idata->data_size);
+}
+
+void *DRW_instance_data_get(DRWInstanceData *idata)
+{
+ return (void *)idata->memchunk;
+}
+
+DRWInstanceData *DRW_instance_data_request(
+ DRWInstanceDataList *idatalist, unsigned int attrib_size, unsigned int instance_group)
+{
+ BLI_assert(attrib_size > 0 && attrib_size <= MAX_INSTANCE_DATA_SIZE);
+
+ DRWInstanceData *idata = idatalist->idata_head[attrib_size - 1];
+
+ /* Search for an unused data chunk. */
+ for (; idata; idata = idata->next) {
+ if (idata->used == false) {
+ idata->used = true;
+ return idata;
+ }
+ }
+
+ return drw_instance_data_create(idatalist, attrib_size, instance_group);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Instance Data List (DRWInstanceDataList)
+ * \{ */
+
+DRWInstanceDataList *DRW_instance_data_list_create(void)
+{
+ DRWInstanceDataList *idatalist = MEM_callocN(sizeof(DRWInstanceDataList), "DRWInstanceDataList");
+ idatalist->batching.bbufs = MEM_callocN(sizeof(DRWBatchingBuffer) * BUFFER_CHUNK_SIZE, "DRWBatchingBuffers");
+ idatalist->batching.alloc_size = BUFFER_CHUNK_SIZE;
+ idatalist->instancing.ibufs = MEM_callocN(sizeof(DRWInstancingBuffer) * BUFFER_CHUNK_SIZE, "DRWInstancingBuffers");
+ idatalist->instancing.alloc_size = BUFFER_CHUNK_SIZE;
+
+ BLI_addtail(&g_idatalists, idatalist);
+
+ return idatalist;
+}
+
+void DRW_instance_data_list_free(DRWInstanceDataList *idatalist)
+{
+ DRWInstanceData *idata, *next_idata;
+
+ for (int i = 0; i < MAX_INSTANCE_DATA_SIZE; ++i) {
+ for (idata = idatalist->idata_head[i]; idata; idata = next_idata) {
+ next_idata = idata->next;
+ DRW_instance_data_free(idata);
+ MEM_freeN(idata);
+ }
+ idatalist->idata_head[i] = NULL;
+ idatalist->idata_tail[i] = NULL;
+ }
+
+ DRWBatchingBuffer *bbuf = idatalist->batching.bbufs;
+ for (int i = 0; i < idatalist->batching.alloc_size; i++, bbuf++) {
+ GWN_VERTBUF_DISCARD_SAFE(bbuf->vert);
+ GWN_BATCH_DISCARD_SAFE(bbuf->batch);
+ }
+ MEM_freeN(idatalist->batching.bbufs);
+
+ DRWInstancingBuffer *ibuf = idatalist->instancing.ibufs;
+ for (int i = 0; i < idatalist->instancing.alloc_size; i++, ibuf++) {
+ GWN_VERTBUF_DISCARD_SAFE(ibuf->vert);
+ GWN_BATCH_DISCARD_SAFE(ibuf->batch);
+ }
+ MEM_freeN(idatalist->instancing.ibufs);
+
+ BLI_remlink(&g_idatalists, idatalist);
+}
+
+void DRW_instance_data_list_reset(DRWInstanceDataList *idatalist)
+{
+ DRWInstanceData *idata;
+
+ for (int i = 0; i < MAX_INSTANCE_DATA_SIZE; ++i) {
+ for (idata = idatalist->idata_head[i]; idata; idata = idata->next) {
+ idata->used = false;
+ idata->offset = 0;
+ }
+ }
+}
+
+void DRW_instance_data_list_free_unused(DRWInstanceDataList *idatalist)
+{
+ DRWInstanceData *idata, *next_idata;
+
+ /* Remove unused data blocks and sanitize each list. */
+ for (int i = 0; i < MAX_INSTANCE_DATA_SIZE; ++i) {
+ idatalist->idata_tail[i] = NULL;
+ for (idata = idatalist->idata_head[i]; idata; idata = next_idata) {
+ next_idata = idata->next;
+ if (idata->used == false) {
+ if (idatalist->idata_head[i] == idata) {
+ idatalist->idata_head[i] = next_idata;
+ }
+ else {
+ /* idatalist->idata_tail[i] is garanteed not to be null in this case. */
+ idatalist->idata_tail[i]->next = next_idata;
+ }
+ DRW_instance_data_free(idata);
+ MEM_freeN(idata);
+ }
+ else {
+ if (idatalist->idata_tail[i] != NULL) {
+ idatalist->idata_tail[i]->next = idata;
+ }
+ idatalist->idata_tail[i] = idata;
+ }
+ }
+ }
+}
+
+void DRW_instance_data_list_resize(DRWInstanceDataList *idatalist)
+{
+ DRWInstanceData *idata;
+
+ for (int i = 0; i < MAX_INSTANCE_DATA_SIZE; ++i) {
+ for (idata = idatalist->idata_head[i]; idata; idata = idata->next) {
+ /* Rounding up to nearest chunk size to compare. */
+ size_t fac = idata->data_size * idata->instance_group;
+ size_t tmp = idata->offset + fac - 1;
+ size_t rounded_offset = tmp - tmp % fac;
+ if (rounded_offset < idata->chunk_size) {
+ idata->chunk_size = rounded_offset;
+ idata->memchunk = MEM_reallocN(idata->memchunk, idata->chunk_size * sizeof(float));
+ }
+ }
+ }
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/draw_instance_data.h b/source/blender/draw/intern/draw_instance_data.h
new file mode 100644
index 00000000000..3b0f7839277
--- /dev/null
+++ b/source/blender/draw/intern/draw_instance_data.h
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_instance_data.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_INSTANCE_DATA_H__
+#define __DRAW_INSTANCE_DATA_H__
+
+#include "BLI_compiler_attrs.h"
+#include "BLI_sys_types.h"
+
+#include "GPU_batch.h"
+
+#define MAX_INSTANCE_DATA_SIZE 42 /* Can be adjusted for more */
+
+typedef struct DRWInstanceData DRWInstanceData;
+typedef struct DRWInstanceDataList DRWInstanceDataList;
+
+struct DRWShadingGroup;
+
+void *DRW_instance_data_next(DRWInstanceData *idata);
+void *DRW_instance_data_get(DRWInstanceData *idata);
+DRWInstanceData *DRW_instance_data_request(
+ DRWInstanceDataList *idatalist, unsigned int attrib_size, unsigned int instance_group);
+
+void DRW_batching_buffer_request(
+ DRWInstanceDataList *idatalist, Gwn_VertFormat *format, Gwn_PrimType type, struct DRWShadingGroup *shgroup,
+ Gwn_Batch **r_batch, Gwn_VertBuf **r_vert);
+void DRW_instancing_buffer_request(
+ DRWInstanceDataList *idatalist, Gwn_VertFormat *format, Gwn_Batch *instance, struct DRWShadingGroup *shgroup,
+ Gwn_Batch **r_batch, Gwn_VertBuf **r_vert);
+
+/* Upload all instance data to the GPU as soon as possible. */
+void DRW_instance_buffer_finish(DRWInstanceDataList *idatalist);
+
+void DRW_instance_data_list_reset(DRWInstanceDataList *idatalist);
+void DRW_instance_data_list_free_unused(DRWInstanceDataList *idatalist);
+void DRW_instance_data_list_resize(DRWInstanceDataList *idatalist);
+
+#endif /* __DRAW_INSTANCE_DATA_H__ */
diff --git a/source/blender/draw/intern/draw_manager.c b/source/blender/draw/intern/draw_manager.c
new file mode 100644
index 00000000000..fcc8e73b626
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager.c
@@ -0,0 +1,2157 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_manager.c
+ * \ingroup draw
+ */
+
+#include <stdio.h>
+
+#include "BLI_listbase.h"
+#include "BLI_mempool.h"
+#include "BLI_rect.h"
+#include "BLI_string.h"
+#include "BLI_threads.h"
+
+#include "BLF_api.h"
+
+#include "BKE_global.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_workspace.h"
+
+#include "draw_manager.h"
+#include "DNA_camera_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "ED_space_api.h"
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "GPU_draw.h"
+#include "GPU_extensions.h"
+#include "GPU_framebuffer.h"
+#include "GPU_immediate.h"
+#include "GPU_uniformbuffer.h"
+#include "GPU_viewport.h"
+#include "GPU_matrix.h"
+
+#include "IMB_colormanagement.h"
+
+#include "RE_engine.h"
+#include "RE_pipeline.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "wm_window.h"
+
+#include "draw_manager_text.h"
+#include "draw_manager_profiling.h"
+
+/* only for callbacks */
+#include "draw_cache_impl.h"
+
+#include "draw_mode_engines.h"
+#include "engines/clay/clay_engine.h"
+#include "engines/eevee/eevee_engine.h"
+#include "engines/basic/basic_engine.h"
+#include "engines/workbench/workbench_engine.h"
+#include "engines/external/external_engine.h"
+
+#include "../../../intern/gawain/gawain/gwn_context.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#ifdef USE_GPU_SELECT
+# include "GPU_select.h"
+#endif
+
+/** Render State: No persistent data between draw calls. */
+DRWManager DST = {NULL};
+
+ListBase DRW_engines = {NULL, NULL};
+
+extern struct GPUUniformBuffer *view_ubo; /* draw_manager_exec.c */
+
+static void drw_state_prepare_clean_for_draw(DRWManager *dst)
+{
+ memset(dst, 0x0, offsetof(DRWManager, ogl_context));
+}
+
+/* This function is used to reset draw manager to a state
+ * where we don't re-use data by accident across different
+ * draw calls.
+ */
+#ifdef DEBUG
+static void drw_state_ensure_not_reused(DRWManager *dst)
+{
+ memset(dst, 0xff, offsetof(DRWManager, ogl_context));
+}
+#endif
+
+/* -------------------------------------------------------------------- */
+
+void DRW_draw_callbacks_pre_scene(void)
+{
+ RegionView3D *rv3d = DST.draw_ctx.rv3d;
+
+ gpuLoadProjectionMatrix(rv3d->winmat);
+ gpuLoadMatrix(rv3d->viewmat);
+}
+
+void DRW_draw_callbacks_post_scene(void)
+{
+ RegionView3D *rv3d = DST.draw_ctx.rv3d;
+
+ gpuLoadProjectionMatrix(rv3d->winmat);
+ gpuLoadMatrix(rv3d->viewmat);
+}
+
+struct DRWTextStore *DRW_text_cache_ensure(void)
+{
+ BLI_assert(DST.text_store_p);
+ if (*DST.text_store_p == NULL) {
+ *DST.text_store_p = DRW_text_cache_create();
+ }
+ return *DST.text_store_p;
+}
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Settings
+ * \{ */
+
+bool DRW_object_is_renderable(Object *ob)
+{
+ BLI_assert(BKE_object_is_visible(ob, OB_VISIBILITY_CHECK_UNKNOWN_RENDER_MODE));
+
+ if (ob->type == OB_MESH) {
+ if (ob == DST.draw_ctx.object_edit) {
+ View3D *v3d = DST.draw_ctx.v3d;
+ const int mask = (V3D_OVERLAY_EDIT_OCCLUDE_WIRE | V3D_OVERLAY_EDIT_WEIGHT);
+
+ if (v3d && v3d->overlay.edit_flag & mask) {
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+/**
+ * Return whether this object is visible depending if
+ * we are rendering or drawing in the viewport.
+ */
+bool DRW_check_object_visible_within_active_context(Object *ob)
+{
+ const eObjectVisibilityCheck mode = DRW_state_is_scene_render() ?
+ OB_VISIBILITY_CHECK_FOR_RENDER :
+ OB_VISIBILITY_CHECK_FOR_VIEWPORT;
+ return BKE_object_is_visible(ob, mode);
+}
+
+bool DRW_object_is_flat_normal(const Object *ob)
+{
+ if (ob->type == OB_MESH) {
+ const Mesh *me = ob->data;
+ if (me->mpoly && me->mpoly[0].flag & ME_SMOOTH) {
+ return false;
+ }
+ }
+ return true;
+}
+
+/**
+ * Return true if the object has its own draw mode.
+ * Caller must check this is active */
+int DRW_object_is_mode_shade(const Object *ob)
+{
+ BLI_assert(ob == DST.draw_ctx.obact);
+ UNUSED_VARS_NDEBUG(ob);
+ if ((DST.draw_ctx.object_mode & OB_MODE_EDIT) == 0) {
+ if ((DST.draw_ctx.object_mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) > 0) {
+ if (ELEM(DST.draw_ctx.v3d->drawtype, OB_MATERIAL, OB_RENDER)) {
+ return false;
+ }
+ else if ((DST.draw_ctx.v3d->flag2 & V3D_SHOW_MODE_SHADE_OVERRIDE) == 0) {
+ return true;
+ }
+ else {
+ return false;
+ }
+ }
+ }
+ return -1;
+}
+
+int DRW_object_is_paint_mode(const Object *ob)
+{
+ if (ob == DST.draw_ctx.obact) {
+ if ((DST.draw_ctx.object_mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) > 0) {
+ return true;
+ }
+ }
+ return false;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Color Management
+ * \{ */
+
+/* Use color management profile to draw texture to framebuffer */
+void DRW_transform_to_display(GPUTexture *tex)
+{
+ drw_state_set(DRW_STATE_WRITE_COLOR);
+
+ Gwn_VertFormat *vert_format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(vert_format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int texco = GWN_vertformat_attr_add(vert_format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ const float dither = 1.0f;
+
+ bool use_ocio = false;
+
+ /* View transform is already applied for offscreen, don't apply again, see: T52046 */
+ if (!(DST.options.is_image_render && !DST.options.is_scene_render)) {
+ Scene *scene = DST.draw_ctx.scene;
+ use_ocio = IMB_colormanagement_setup_glsl_draw_from_space(
+ &scene->view_settings, &scene->display_settings, NULL, dither, false);
+ }
+
+ if (!use_ocio) {
+ /* View transform is already applied for offscreen, don't apply again, see: T52046 */
+ if (DST.options.is_image_render && !DST.options.is_scene_render) {
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ }
+ else {
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB);
+ }
+ immUniform1i("image", 0);
+ }
+
+ GPU_texture_bind(tex, 0); /* OCIO texture bind point is 0 */
+
+ float mat[4][4];
+ unit_m4(mat);
+ immUniformMatrix4fv("ModelViewProjectionMatrix", mat);
+
+ /* Full screen triangle */
+ immBegin(GWN_PRIM_TRIS, 3);
+ immAttrib2f(texco, 0.0f, 0.0f);
+ immVertex2f(pos, -1.0f, -1.0f);
+
+ immAttrib2f(texco, 2.0f, 0.0f);
+ immVertex2f(pos, 3.0f, -1.0f);
+
+ immAttrib2f(texco, 0.0f, 2.0f);
+ immVertex2f(pos, -1.0f, 3.0f);
+ immEnd();
+
+ GPU_texture_unbind(tex);
+
+ if (use_ocio) {
+ IMB_colormanagement_finish_glsl_draw();
+ }
+ else {
+ immUnbindProgram();
+ }
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Multisample Resolve
+ * \{ */
+
+/* Use manual multisample resolve pass.
+ * Much quicker than blitting back and forth.
+ * Assume destination fb is bound*/
+void DRW_multisamples_resolve(GPUTexture *src_depth, GPUTexture *src_color)
+{
+ drw_state_set(DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND_PREMUL |
+ DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+ int samples = GPU_texture_samples(src_depth);
+
+ BLI_assert(samples > 0);
+ BLI_assert(GPU_texture_samples(src_color) == samples);
+
+ Gwn_Batch *geom = DRW_cache_fullscreen_quad_get();
+
+ int builtin;
+ switch (samples) {
+ case 2: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2; break;
+ case 4: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_4; break;
+ case 8: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_8; break;
+ case 16: builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_16; break;
+ default:
+ BLI_assert(0);
+ builtin = GPU_SHADER_2D_IMAGE_MULTISAMPLE_2;
+ break;
+ }
+
+ GWN_batch_program_set_builtin(geom, builtin);
+
+ GPU_texture_bind(src_depth, 0);
+ GPU_texture_bind(src_color, 1);
+ GWN_batch_uniform_1i(geom, "depthMulti", 0);
+ GWN_batch_uniform_1i(geom, "colorMulti", 1);
+
+ float mat[4][4];
+ unit_m4(mat);
+ GWN_batch_uniform_mat4(geom, "ModelViewProjectionMatrix", mat);
+
+ /* avoid gpuMatrix calls */
+ GWN_batch_program_use_begin(geom);
+ GWN_batch_draw_range_ex(geom, 0, 0, false);
+ GWN_batch_program_use_end(geom);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Viewport (DRW_viewport)
+ * \{ */
+
+void *drw_viewport_engine_data_ensure(void *engine_type)
+{
+ void *data = GPU_viewport_engine_data_get(DST.viewport, engine_type);
+
+ if (data == NULL) {
+ data = GPU_viewport_engine_data_create(DST.viewport, engine_type);
+ }
+ return data;
+}
+
+void DRW_engine_viewport_data_size_get(
+ const void *engine_type_v,
+ int *r_fbl_len, int *r_txl_len, int *r_psl_len, int *r_stl_len)
+{
+ const DrawEngineType *engine_type = engine_type_v;
+
+ if (r_fbl_len) {
+ *r_fbl_len = engine_type->vedata_size->fbl_len;
+ }
+ if (r_txl_len) {
+ *r_txl_len = engine_type->vedata_size->txl_len;
+ }
+ if (r_psl_len) {
+ *r_psl_len = engine_type->vedata_size->psl_len;
+ }
+ if (r_stl_len) {
+ *r_stl_len = engine_type->vedata_size->stl_len;
+ }
+}
+
+const float *DRW_viewport_size_get(void)
+{
+ return DST.size;
+}
+
+const float *DRW_viewport_invert_size_get(void)
+{
+ return DST.inv_size;
+}
+
+const float *DRW_viewport_screenvecs_get(void)
+{
+ return &DST.screenvecs[0][0];
+}
+
+const float *DRW_viewport_pixelsize_get(void)
+{
+ return &DST.pixsize;
+}
+
+static void drw_viewport_cache_resize(void)
+{
+ /* Release the memiter before clearing the mempools that references them */
+ GPU_viewport_cache_release(DST.viewport);
+
+ if (DST.vmempool != NULL) {
+ BLI_mempool_clear_ex(DST.vmempool->calls, BLI_mempool_len(DST.vmempool->calls));
+ BLI_mempool_clear_ex(DST.vmempool->states, BLI_mempool_len(DST.vmempool->states));
+ BLI_mempool_clear_ex(DST.vmempool->shgroups, BLI_mempool_len(DST.vmempool->shgroups));
+ BLI_mempool_clear_ex(DST.vmempool->uniforms, BLI_mempool_len(DST.vmempool->uniforms));
+ BLI_mempool_clear_ex(DST.vmempool->passes, BLI_mempool_len(DST.vmempool->passes));
+ }
+
+ DRW_instance_data_list_free_unused(DST.idatalist);
+ DRW_instance_data_list_resize(DST.idatalist);
+}
+
+/* Not a viewport variable, we could split this out. */
+static void drw_context_state_init(void)
+{
+ if (DST.draw_ctx.obact) {
+ DST.draw_ctx.object_mode = DST.draw_ctx.obact->mode;
+ }
+ else {
+ DST.draw_ctx.object_mode = OB_MODE_OBJECT;
+ }
+
+ /* Edit object. */
+ if (DST.draw_ctx.object_mode & OB_MODE_EDIT) {
+ DST.draw_ctx.object_edit = DST.draw_ctx.obact;
+ }
+ else {
+ DST.draw_ctx.object_edit = NULL;
+ }
+
+ /* Pose object. */
+ if (DST.draw_ctx.object_mode & OB_MODE_POSE) {
+ DST.draw_ctx.object_pose = DST.draw_ctx.obact;
+ }
+ else if (DST.draw_ctx.object_mode & OB_MODE_WEIGHT_PAINT) {
+ DST.draw_ctx.object_pose = BKE_object_pose_armature_get(DST.draw_ctx.obact);
+ }
+ else {
+ DST.draw_ctx.object_pose = NULL;
+ }
+}
+
+/* It also stores viewport variable to an immutable place: DST
+ * This is because a cache uniform only store reference
+ * to its value. And we don't want to invalidate the cache
+ * if this value change per viewport */
+static void drw_viewport_var_init(void)
+{
+ RegionView3D *rv3d = DST.draw_ctx.rv3d;
+ /* Refresh DST.size */
+ if (DST.viewport) {
+ int size[2];
+ GPU_viewport_size_get(DST.viewport, size);
+ DST.size[0] = size[0];
+ DST.size[1] = size[1];
+ DST.inv_size[0] = 1.0f / size[0];
+ DST.inv_size[1] = 1.0f / size[1];
+
+ DefaultFramebufferList *fbl = (DefaultFramebufferList *)GPU_viewport_framebuffer_list_get(DST.viewport);
+ DST.default_framebuffer = fbl->default_fb;
+
+ DST.vmempool = GPU_viewport_mempool_get(DST.viewport);
+
+ if (DST.vmempool->calls == NULL) {
+ DST.vmempool->calls = BLI_mempool_create(sizeof(DRWCall), 0, 512, 0);
+ }
+ if (DST.vmempool->states == NULL) {
+ DST.vmempool->states = BLI_mempool_create(sizeof(DRWCallState), 0, 512, BLI_MEMPOOL_ALLOW_ITER);
+ }
+ if (DST.vmempool->shgroups == NULL) {
+ DST.vmempool->shgroups = BLI_mempool_create(sizeof(DRWShadingGroup), 0, 256, 0);
+ }
+ if (DST.vmempool->uniforms == NULL) {
+ DST.vmempool->uniforms = BLI_mempool_create(sizeof(DRWUniform), 0, 512, 0);
+ }
+ if (DST.vmempool->passes == NULL) {
+ DST.vmempool->passes = BLI_mempool_create(sizeof(DRWPass), 0, 64, 0);
+ }
+
+ DST.idatalist = GPU_viewport_instance_data_list_get(DST.viewport);
+ DRW_instance_data_list_reset(DST.idatalist);
+ }
+ else {
+ DST.size[0] = 0;
+ DST.size[1] = 0;
+
+ DST.inv_size[0] = 0;
+ DST.inv_size[1] = 0;
+
+ DST.default_framebuffer = NULL;
+ DST.vmempool = NULL;
+ }
+
+ if (rv3d != NULL) {
+ /* Refresh DST.screenvecs */
+ copy_v3_v3(DST.screenvecs[0], rv3d->viewinv[0]);
+ copy_v3_v3(DST.screenvecs[1], rv3d->viewinv[1]);
+ normalize_v3(DST.screenvecs[0]);
+ normalize_v3(DST.screenvecs[1]);
+
+ /* Refresh DST.pixelsize */
+ DST.pixsize = rv3d->pixsize;
+
+ copy_m4_m4(DST.original_mat.mat[DRW_MAT_PERS], rv3d->persmat);
+ copy_m4_m4(DST.original_mat.mat[DRW_MAT_PERSINV], rv3d->persinv);
+ copy_m4_m4(DST.original_mat.mat[DRW_MAT_VIEW], rv3d->viewmat);
+ copy_m4_m4(DST.original_mat.mat[DRW_MAT_VIEWINV], rv3d->viewinv);
+ copy_m4_m4(DST.original_mat.mat[DRW_MAT_WIN], rv3d->winmat);
+ invert_m4_m4(DST.original_mat.mat[DRW_MAT_WININV], rv3d->winmat);
+
+ memcpy(DST.view_data.matstate.mat, DST.original_mat.mat, sizeof(DST.original_mat.mat));
+
+ copy_v4_v4(DST.view_data.viewcamtexcofac, rv3d->viewcamtexcofac);
+ }
+ else {
+ copy_v4_fl4(DST.view_data.viewcamtexcofac, 1.0f, 1.0f, 0.0f, 0.0f);
+ }
+
+ /* Reset facing */
+ DST.frontface = GL_CCW;
+ DST.backface = GL_CW;
+ glFrontFace(DST.frontface);
+
+ if (DST.draw_ctx.object_edit) {
+ ED_view3d_init_mats_rv3d(DST.draw_ctx.object_edit, rv3d);
+ }
+
+ /* Alloc array of texture reference. */
+ if (DST.RST.bound_texs == NULL) {
+ DST.RST.bound_texs = MEM_callocN(sizeof(GPUTexture *) * GPU_max_textures(), "Bound GPUTexture refs");
+ }
+ if (DST.RST.bound_tex_slots == NULL) {
+ DST.RST.bound_tex_slots = MEM_callocN(sizeof(char) * GPU_max_textures(), "Bound Texture Slots");
+ }
+ if (DST.RST.bound_ubos == NULL) {
+ DST.RST.bound_ubos = MEM_callocN(sizeof(GPUUniformBuffer *) * GPU_max_ubo_binds(), "Bound GPUUniformBuffer refs");
+ }
+ if (DST.RST.bound_ubo_slots == NULL) {
+ DST.RST.bound_ubo_slots = MEM_callocN(sizeof(char) * GPU_max_ubo_binds(), "Bound Ubo Slots");
+ }
+
+ if (view_ubo == NULL) {
+ view_ubo = DRW_uniformbuffer_create(sizeof(ViewUboStorage), NULL);
+ }
+
+ DST.override_mat = 0;
+ DST.dirty_mat = true;
+ DST.state_cache_id = 1;
+
+ DST.clipping.updated = false;
+
+ memset(DST.common_instance_data, 0x0, sizeof(DST.common_instance_data));
+}
+
+void DRW_viewport_matrix_get(float mat[4][4], DRWViewportMatrixType type)
+{
+ BLI_assert(type >= 0 && type < DRW_MAT_COUNT);
+ BLI_assert(((DST.override_mat & (1 << type)) != 0) || DST.draw_ctx.rv3d != NULL); /* Can't use this in render mode. */
+
+ copy_m4_m4(mat, DST.view_data.matstate.mat[type]);
+}
+
+void DRW_viewport_matrix_get_all(DRWMatrixState *state)
+{
+ memcpy(state, DST.view_data.matstate.mat, sizeof(DRWMatrixState));
+}
+
+void DRW_viewport_matrix_override_set(const float mat[4][4], DRWViewportMatrixType type)
+{
+ BLI_assert(type < DRW_MAT_COUNT);
+ copy_m4_m4(DST.view_data.matstate.mat[type], mat);
+ DST.override_mat |= (1 << type);
+ DST.dirty_mat = true;
+ DST.clipping.updated = false;
+}
+
+void DRW_viewport_matrix_override_unset(DRWViewportMatrixType type)
+{
+ BLI_assert(type < DRW_MAT_COUNT);
+ copy_m4_m4(DST.view_data.matstate.mat[type], DST.original_mat.mat[type]);
+ DST.override_mat &= ~(1 << type);
+ DST.dirty_mat = true;
+ DST.clipping.updated = false;
+}
+
+void DRW_viewport_matrix_override_set_all(DRWMatrixState *state)
+{
+ memcpy(DST.view_data.matstate.mat, state, sizeof(DRWMatrixState));
+ DST.override_mat = 0xFFFFFF;
+ DST.dirty_mat = true;
+ DST.clipping.updated = false;
+}
+
+void DRW_viewport_matrix_override_unset_all(void)
+{
+ memcpy(DST.view_data.matstate.mat, DST.original_mat.mat, sizeof(DRWMatrixState));
+ DST.override_mat = 0;
+ DST.dirty_mat = true;
+ DST.clipping.updated = false;
+}
+
+bool DRW_viewport_is_persp_get(void)
+{
+ RegionView3D *rv3d = DST.draw_ctx.rv3d;
+ if (rv3d) {
+ return rv3d->is_persp;
+ }
+ else {
+ return DST.view_data.matstate.mat[DRW_MAT_WIN][3][3] == 0.0f;
+ }
+}
+
+float DRW_viewport_near_distance_get(void)
+{
+ float projmat[4][4];
+ DRW_viewport_matrix_get(projmat, DRW_MAT_WIN);
+
+ if (DRW_viewport_is_persp_get()) {
+ return -projmat[3][2] / (projmat[2][2] - 1.0f);
+ }
+ else {
+ return -(projmat[3][2] + 1.0f) / projmat[2][2];
+ }
+}
+
+float DRW_viewport_far_distance_get(void)
+{
+ float projmat[4][4];
+ DRW_viewport_matrix_get(projmat, DRW_MAT_WIN);
+
+ if (DRW_viewport_is_persp_get()) {
+ return -projmat[3][2] / (projmat[2][2] + 1.0f);
+ }
+ else {
+ return -(projmat[3][2] - 1.0f) / projmat[2][2];
+ }
+}
+
+DefaultFramebufferList *DRW_viewport_framebuffer_list_get(void)
+{
+ return GPU_viewport_framebuffer_list_get(DST.viewport);
+}
+
+DefaultTextureList *DRW_viewport_texture_list_get(void)
+{
+ return GPU_viewport_texture_list_get(DST.viewport);
+}
+
+void DRW_viewport_request_redraw(void)
+{
+ GPU_viewport_tag_update(DST.viewport);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name ViewLayers (DRW_scenelayer)
+ * \{ */
+
+void *DRW_view_layer_engine_data_get(DrawEngineType *engine_type)
+{
+ for (ViewLayerEngineData *sled = DST.draw_ctx.view_layer->drawdata.first; sled; sled = sled->next) {
+ if (sled->engine_type == engine_type) {
+ return sled->storage;
+ }
+ }
+ return NULL;
+}
+
+void **DRW_view_layer_engine_data_ensure(DrawEngineType *engine_type, void (*callback)(void *storage))
+{
+ ViewLayerEngineData *sled;
+
+ for (sled = DST.draw_ctx.view_layer->drawdata.first; sled; sled = sled->next) {
+ if (sled->engine_type == engine_type) {
+ return &sled->storage;
+ }
+ }
+
+ sled = MEM_callocN(sizeof(ViewLayerEngineData), "ViewLayerEngineData");
+ sled->engine_type = engine_type;
+ sled->free = callback;
+ BLI_addtail(&DST.draw_ctx.view_layer->drawdata, sled);
+
+ return &sled->storage;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Objects (DRW_object)
+ * \{ */
+
+ObjectEngineData *DRW_object_engine_data_get(Object *ob, DrawEngineType *engine_type)
+{
+ for (ObjectEngineData *oed = ob->drawdata.first; oed; oed = oed->next) {
+ if (oed->engine_type == engine_type) {
+ return oed;
+ }
+ }
+ return NULL;
+}
+
+ObjectEngineData *DRW_object_engine_data_ensure(
+ Object *ob,
+ DrawEngineType *engine_type,
+ size_t size,
+ ObjectEngineDataInitCb init_cb,
+ ObjectEngineDataFreeCb free_cb)
+{
+ BLI_assert(size >= sizeof(ObjectEngineData));
+ /* Try to re-use existing data. */
+ ObjectEngineData *oed = DRW_object_engine_data_get(ob, engine_type);
+ if (oed != NULL) {
+ return oed;
+ }
+ /* Allocate new data. */
+ if ((ob->base_flag & BASE_FROMDUPLI) != 0) {
+ /* NOTE: data is not persistent in this case. It is reset each redraw. */
+ BLI_assert(free_cb == NULL); /* No callback allowed. */
+ /* Round to sizeof(float) for DRW_instance_data_request(). */
+ const size_t t = sizeof(float) - 1;
+ size = (size + t) & ~t;
+ size_t fsize = size / sizeof(float);
+ if (DST.common_instance_data[fsize] == NULL) {
+ DST.common_instance_data[fsize] = DRW_instance_data_request(DST.idatalist, fsize, 16);
+ }
+ oed = (ObjectEngineData *)DRW_instance_data_next(DST.common_instance_data[fsize]);
+ memset(oed, 0, size);
+ }
+ else {
+ oed = MEM_callocN(size, "ObjectEngineData");
+ }
+ oed->engine_type = engine_type;
+ oed->free = free_cb;
+ /* Perform user-side initialization, if needed. */
+ if (init_cb != NULL) {
+ init_cb(oed);
+ }
+ /* Register in the list. */
+ BLI_addtail(&ob->drawdata, oed);
+ return oed;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Rendering (DRW_engines)
+ * \{ */
+
+static void drw_engines_init(void)
+{
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+ PROFILE_START(stime);
+
+ if (engine->engine_init) {
+ engine->engine_init(data);
+ }
+
+ PROFILE_END_UPDATE(data->init_time, stime);
+ }
+}
+
+static void drw_engines_cache_init(void)
+{
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+
+ if (data->text_draw_cache) {
+ DRW_text_cache_destroy(data->text_draw_cache);
+ data->text_draw_cache = NULL;
+ }
+ if (DST.text_store_p == NULL) {
+ DST.text_store_p = &data->text_draw_cache;
+ }
+
+ if (engine->cache_init) {
+ engine->cache_init(data);
+ }
+ }
+}
+
+static void drw_engines_cache_populate(Object *ob)
+{
+ DST.ob_state = NULL;
+
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+
+ if (engine->id_update) {
+ engine->id_update(data, &ob->id);
+ }
+
+ if (engine->cache_populate) {
+ engine->cache_populate(data, ob);
+ }
+ }
+}
+
+static void drw_engines_cache_finish(void)
+{
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+
+ if (engine->cache_finish) {
+ engine->cache_finish(data);
+ }
+ }
+}
+
+static void drw_engines_draw_background(void)
+{
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+
+ if (engine->draw_background) {
+ PROFILE_START(stime);
+
+ DRW_stats_group_start(engine->idname);
+ engine->draw_background(data);
+ DRW_stats_group_end();
+
+ PROFILE_END_UPDATE(data->background_time, stime);
+ return;
+ }
+ }
+
+ /* No draw_background found, doing default background */
+ if (DRW_state_draw_background()) {
+ DRW_draw_background();
+ }
+}
+
+static void drw_engines_draw_scene(void)
+{
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+ PROFILE_START(stime);
+
+ if (engine->draw_scene) {
+ DRW_stats_group_start(engine->idname);
+ engine->draw_scene(data);
+ /* Restore for next engine */
+ if (DRW_state_is_fbo()) {
+ GPU_framebuffer_bind(DST.default_framebuffer);
+ }
+ DRW_stats_group_end();
+ }
+
+ PROFILE_END_UPDATE(data->render_time, stime);
+ }
+}
+
+static void drw_engines_draw_text(void)
+{
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+ PROFILE_START(stime);
+
+ if (data->text_draw_cache) {
+ DRW_text_cache_draw(data->text_draw_cache, DST.draw_ctx.v3d, DST.draw_ctx.ar, false);
+ }
+
+ PROFILE_END_UPDATE(data->render_time, stime);
+ }
+}
+
+#define MAX_INFO_LINES 10
+
+/**
+ * Returns the offset required for the drawing of engines info.
+ */
+int DRW_draw_region_engine_info_offset(void)
+{
+ int lines = 0;
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+
+ /* Count the number of lines. */
+ if (data->info[0] != '\0') {
+ lines++;
+ char *c = data->info;
+ while (*c++ != '\0') {
+ if (*c == '\n') {
+ lines++;
+ }
+ }
+ }
+ }
+ return MIN2(MAX_INFO_LINES, lines) * UI_UNIT_Y;
+}
+
+/**
+ * Actual drawing;
+ */
+void DRW_draw_region_engine_info(void)
+{
+ const char *info_array_final[MAX_INFO_LINES + 1];
+ /* This should be maxium number of engines running at the same time. */
+ char info_array[MAX_INFO_LINES][GPU_INFO_SIZE];
+ int i = 0;
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ARegion *ar = draw_ctx->ar;
+ float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
+
+ UI_GetThemeColor3fv(TH_HIGH_GRAD, fill_color);
+ mul_v3_fl(fill_color, fill_color[3]);
+
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+
+ if (data->info[0] != '\0') {
+ char *chr_current = data->info;
+ char *chr_start = chr_current;
+ int line_len = 0;
+
+ while (*chr_current++ != '\0') {
+ line_len++;
+ if (*chr_current == '\n') {
+ BLI_strncpy(info_array[i++], chr_start, line_len + 1);
+ /* Re-start counting. */
+ chr_start = chr_current + 1;
+ line_len = -1;
+ }
+ }
+
+ BLI_strncpy(info_array[i++], chr_start, line_len + 1);
+
+ if (i >= MAX_INFO_LINES) {
+ break;
+ }
+ }
+ }
+
+ for (int j = 0; j < i; j++) {
+ info_array_final[j] = info_array[j];
+ }
+ info_array_final[i] = NULL;
+
+ if (info_array[0] != NULL) {
+ ED_region_info_draw_multiline(ar, info_array_final, fill_color, true);
+ }
+}
+
+#undef MAX_INFO_LINES
+
+static void use_drw_engine(DrawEngineType *engine)
+{
+ LinkData *ld = MEM_callocN(sizeof(LinkData), "enabled engine link data");
+ ld->data = engine;
+ BLI_addtail(&DST.enabled_engines, ld);
+}
+
+/**
+ * Use for external render engines.
+ */
+static void drw_engines_enable_external(void)
+{
+ use_drw_engine(DRW_engine_viewport_external_type.draw_engine);
+}
+
+/* TODO revisit this when proper layering is implemented */
+/* Gather all draw engines needed and store them in DST.enabled_engines
+ * That also define the rendering order of engines */
+static void drw_engines_enable_from_engine(RenderEngineType *engine_type, int drawtype)
+{
+ switch (drawtype) {
+ case OB_WIRE:
+ break;
+
+ case OB_SOLID:
+ case OB_TEXTURE:
+ use_drw_engine(&draw_engine_workbench_solid);
+ break;
+
+ case OB_MATERIAL:
+ case OB_RENDER:
+ default:
+ /* TODO layers */
+ if (engine_type->draw_engine != NULL) {
+ use_drw_engine(engine_type->draw_engine);
+ }
+
+ if ((engine_type->flag & RE_INTERNAL) == 0) {
+ drw_engines_enable_external();
+ }
+ break;
+ }
+}
+
+static void drw_engines_enable_from_object_mode(void)
+{
+ use_drw_engine(&draw_engine_object_type);
+}
+
+static void drw_engines_enable_from_mode(int mode)
+{
+ switch (mode) {
+ case CTX_MODE_EDIT_MESH:
+ use_drw_engine(&draw_engine_edit_mesh_type);
+ break;
+ case CTX_MODE_EDIT_CURVE:
+ use_drw_engine(&draw_engine_edit_curve_type);
+ break;
+ case CTX_MODE_EDIT_SURFACE:
+ use_drw_engine(&draw_engine_edit_surface_type);
+ break;
+ case CTX_MODE_EDIT_TEXT:
+ use_drw_engine(&draw_engine_edit_text_type);
+ break;
+ case CTX_MODE_EDIT_ARMATURE:
+ use_drw_engine(&draw_engine_edit_armature_type);
+ break;
+ case CTX_MODE_EDIT_METABALL:
+ use_drw_engine(&draw_engine_edit_metaball_type);
+ break;
+ case CTX_MODE_EDIT_LATTICE:
+ use_drw_engine(&draw_engine_edit_lattice_type);
+ break;
+ case CTX_MODE_POSE:
+ use_drw_engine(&draw_engine_pose_type);
+ break;
+ case CTX_MODE_SCULPT:
+ use_drw_engine(&draw_engine_sculpt_type);
+ break;
+ case CTX_MODE_PAINT_WEIGHT:
+ use_drw_engine(&draw_engine_pose_type);
+ use_drw_engine(&draw_engine_paint_weight_type);
+ break;
+ case CTX_MODE_PAINT_VERTEX:
+ use_drw_engine(&draw_engine_paint_vertex_type);
+ break;
+ case CTX_MODE_PAINT_TEXTURE:
+ use_drw_engine(&draw_engine_paint_texture_type);
+ break;
+ case CTX_MODE_PARTICLE:
+ use_drw_engine(&draw_engine_particle_type);
+ break;
+ case CTX_MODE_OBJECT:
+ break;
+ default:
+ BLI_assert(!"Draw mode invalid");
+ break;
+ }
+}
+
+static void drw_engines_enable_from_overlays(int overlay_flag)
+{
+ if (overlay_flag) {
+ use_drw_engine(&draw_engine_overlay_type);
+ }
+}
+/**
+ * Use for select and depth-drawing.
+ */
+static void drw_engines_enable_basic(void)
+{
+ use_drw_engine(DRW_engine_viewport_basic_type.draw_engine);
+}
+
+static void drw_engines_enable(ViewLayer *view_layer, RenderEngineType *engine_type)
+{
+ Object *obact = OBACT(view_layer);
+ const int mode = CTX_data_mode_enum_ex(DST.draw_ctx.object_edit, obact, DST.draw_ctx.object_mode);
+ View3D * v3d = DST.draw_ctx.v3d;
+ const int drawtype = v3d->drawtype;
+
+ drw_engines_enable_from_engine(engine_type, drawtype);
+
+ if (DRW_state_draw_support()) {
+ drw_engines_enable_from_overlays(v3d->overlay.flag);
+ drw_engines_enable_from_object_mode();
+ drw_engines_enable_from_mode(mode);
+ }
+}
+
+static void drw_engines_disable(void)
+{
+ BLI_freelistN(&DST.enabled_engines);
+}
+
+static unsigned int DRW_engines_get_hash(void)
+{
+ unsigned int hash = 0;
+ /* The cache depends on enabled engines */
+ /* FIXME : if collision occurs ... segfault */
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *engine = link->data;
+ hash += BLI_ghashutil_strhash_p(engine->idname);
+ }
+
+ return hash;
+}
+
+/* -------------------------------------------------------------------- */
+
+/** \name View Update
+ * \{ */
+
+void DRW_notify_view_update(const DRWUpdateContext *update_ctx)
+{
+ RenderEngineType *engine_type = update_ctx->engine_type;
+ ARegion *ar = update_ctx->ar;
+ View3D *v3d = update_ctx->v3d;
+ RegionView3D *rv3d = ar->regiondata;
+ Depsgraph *depsgraph = update_ctx->depsgraph;
+ Scene *scene = update_ctx->scene;
+ ViewLayer *view_layer = update_ctx->view_layer;
+
+ /* Separate update for each stereo view. */
+ for (int view = 0; view < 2; view++) {
+ GPUViewport *viewport = WM_draw_region_get_viewport(ar, view);
+ if (!viewport) {
+ continue;
+ }
+
+ /* XXX Really nasty locking. But else this could
+ * be executed by the material previews thread
+ * while rendering a viewport. */
+ BLI_mutex_lock(&DST.ogl_context_mutex);
+
+ /* Reset before using it. */
+ drw_state_prepare_clean_for_draw(&DST);
+
+ DST.viewport = viewport;
+ DST.draw_ctx = (DRWContextState){
+ .ar = ar, .rv3d = rv3d, .v3d = v3d,
+ .scene = scene, .view_layer = view_layer, .obact = OBACT(view_layer),
+ .engine_type = engine_type,
+ .depsgraph = depsgraph, .object_mode = OB_MODE_OBJECT,
+ };
+
+ drw_engines_enable(view_layer, engine_type);
+
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ DrawEngineType *draw_engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(draw_engine);
+
+ if (draw_engine->view_update) {
+ draw_engine->view_update(data);
+ }
+ }
+
+ DST.viewport = NULL;
+
+ drw_engines_disable();
+
+ BLI_mutex_unlock(&DST.ogl_context_mutex);
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Main Draw Loops (DRW_draw)
+ * \{ */
+
+/* Everything starts here.
+ * This function takes care of calling all cache and rendering functions
+ * for each relevant engine / mode engine. */
+void DRW_draw_view(const bContext *C)
+{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ARegion *ar = CTX_wm_region(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+ RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype);
+ GPUViewport *viewport = WM_draw_region_get_bound_viewport(ar);
+
+ /* Reset before using it. */
+ drw_state_prepare_clean_for_draw(&DST);
+ DRW_draw_render_loop_ex(depsgraph, engine_type, ar, v3d, viewport, C);
+}
+
+/**
+ * Used for both regular and off-screen drawing.
+ * Need to reset DST before calling this function
+ */
+void DRW_draw_render_loop_ex(
+ struct Depsgraph *depsgraph,
+ RenderEngineType *engine_type,
+ ARegion *ar, View3D *v3d,
+ GPUViewport *viewport,
+ const bContext *evil_C)
+{
+
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ RegionView3D *rv3d = ar->regiondata;
+
+ DST.draw_ctx.evil_C = evil_C;
+
+ DST.viewport = viewport;
+ v3d->zbuf = true;
+
+ /* Setup viewport */
+ GPU_viewport_engines_data_validate(DST.viewport, DRW_engines_get_hash());
+
+ DST.draw_ctx = (DRWContextState){
+ .ar = ar, .rv3d = rv3d, .v3d = v3d,
+ .scene = scene, .view_layer = view_layer, .obact = OBACT(view_layer),
+ .engine_type = engine_type,
+ .depsgraph = depsgraph,
+
+ /* reuse if caller sets */
+ .evil_C = DST.draw_ctx.evil_C,
+ };
+ drw_context_state_init();
+ drw_viewport_var_init();
+
+ /* Get list of enabled engines */
+ drw_engines_enable(view_layer, engine_type);
+
+ /* Update ubos */
+ DRW_globals_update();
+
+ /* No framebuffer allowed before drawing. */
+ BLI_assert(GPU_framebuffer_current_get() == 0);
+
+ /* Init engines */
+ drw_engines_init();
+
+ /* Cache filling */
+ {
+ PROFILE_START(stime);
+ drw_engines_cache_init();
+
+ DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob, DRW_iterator_mode_get())
+ {
+ drw_engines_cache_populate(ob);
+ }
+ DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END;
+
+ drw_engines_cache_finish();
+
+ DRW_render_instance_buffer_finish();
+
+#ifdef USE_PROFILE
+ double *cache_time = GPU_viewport_cache_time_get(DST.viewport);
+ PROFILE_END_UPDATE(*cache_time, stime);
+#endif
+ }
+
+ DRW_stats_begin();
+
+ GPU_framebuffer_bind(DST.default_framebuffer);
+
+ /* Start Drawing */
+ DRW_state_reset();
+
+ drw_engines_draw_background();
+
+ /* WIP, single image drawn over the camera view (replace) */
+ bool do_bg_image = false;
+ if (rv3d->persp == RV3D_CAMOB) {
+ Object *cam_ob = v3d->camera;
+ if (cam_ob && cam_ob->type == OB_CAMERA) {
+ Camera *cam = cam_ob->data;
+ if (!BLI_listbase_is_empty(&cam->bg_images)) {
+ do_bg_image = true;
+ }
+ }
+ }
+
+ if (do_bg_image) {
+ ED_view3d_draw_bgpic_test(scene, depsgraph, ar, v3d, false, true);
+ }
+
+
+ DRW_draw_callbacks_pre_scene();
+ if (DST.draw_ctx.evil_C) {
+ ED_region_draw_cb_draw(DST.draw_ctx.evil_C, DST.draw_ctx.ar, REGION_DRAW_PRE_VIEW);
+ }
+
+ drw_engines_draw_scene();
+
+ DRW_draw_callbacks_post_scene();
+ if (DST.draw_ctx.evil_C) {
+ ED_region_draw_cb_draw(DST.draw_ctx.evil_C, DST.draw_ctx.ar, REGION_DRAW_POST_VIEW);
+ }
+
+ DRW_state_reset();
+
+ drw_engines_draw_text();
+
+ if (DST.draw_ctx.evil_C) {
+ /* needed so manipulator isn't obscured */
+ glDisable(GL_DEPTH_TEST);
+ DRW_draw_manipulator_3d();
+
+ DRW_draw_region_info();
+
+ /* Draw 2D after region info so we can draw on top of the camera passepartout overlay.
+ * 'DRW_draw_region_info' sets the projection in pixel-space. */
+ DRW_draw_manipulator_2d();
+ glEnable(GL_DEPTH_TEST);
+ }
+
+ DRW_stats_reset();
+
+ if (do_bg_image) {
+ ED_view3d_draw_bgpic_test(scene, depsgraph, ar, v3d, true, true);
+ }
+
+ if (G.debug_value > 20) {
+ glDisable(GL_DEPTH_TEST);
+ rcti rect; /* local coordinate visible rect inside region, to accomodate overlapping ui */
+ ED_region_visible_rect(DST.draw_ctx.ar, &rect);
+ DRW_stats_draw(&rect);
+ glEnable(GL_DEPTH_TEST);
+ }
+
+ if (WM_draw_region_get_bound_viewport(ar)) {
+ /* Don't unbind the framebuffer yet in this case and let
+ * GPU_viewport_unbind do it, so that we can still do further
+ * drawing of action zones on top. */
+ }
+ else {
+ GPU_framebuffer_restore();
+ }
+
+ DRW_state_reset();
+ drw_engines_disable();
+
+ drw_viewport_cache_resize();
+
+#ifdef DEBUG
+ /* Avoid accidental reuse. */
+ drw_state_ensure_not_reused(&DST);
+#endif
+}
+
+void DRW_draw_render_loop(
+ struct Depsgraph *depsgraph,
+ ARegion *ar, View3D *v3d,
+ GPUViewport *viewport)
+{
+ /* Reset before using it. */
+ drw_state_prepare_clean_for_draw(&DST);
+
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+ RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype);
+
+ DRW_draw_render_loop_ex(depsgraph, engine_type, ar, v3d, viewport, NULL);
+}
+
+/* @viewport CAN be NULL, in this case we create one. */
+void DRW_draw_render_loop_offscreen(
+ struct Depsgraph *depsgraph, RenderEngineType *engine_type,
+ ARegion *ar, View3D *v3d,
+ const bool draw_background, GPUOffScreen *ofs,
+ GPUViewport *viewport)
+{
+ /* Create temporary viewport if needed. */
+ GPUViewport *render_viewport = viewport;
+ if (viewport == NULL) {
+ render_viewport = GPU_viewport_create_from_offscreen(ofs);
+ }
+
+ GPU_framebuffer_restore();
+
+ /* Reset before using it. */
+ drw_state_prepare_clean_for_draw(&DST);
+ DST.options.is_image_render = true;
+ DST.options.draw_background = draw_background;
+ DRW_draw_render_loop_ex(depsgraph, engine_type, ar, v3d, render_viewport, NULL);
+
+ /* Free temporary viewport. */
+ if (viewport == NULL) {
+ /* don't free data owned by 'ofs' */
+ GPU_viewport_clear_from_offscreen(render_viewport);
+ GPU_viewport_free(render_viewport);
+ }
+
+ /* we need to re-bind (annoying!) */
+ GPU_offscreen_bind(ofs, false);
+}
+
+void DRW_render_to_image(RenderEngine *engine, struct Depsgraph *depsgraph)
+{
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ RenderEngineType *engine_type = engine->type;
+ DrawEngineType *draw_engine_type = engine_type->draw_engine;
+ RenderData *r = &scene->r;
+ Render *render = engine->re;
+
+ if (G.background && DST.ogl_context == NULL) {
+ WM_init_opengl();
+ }
+
+ /* Changing Context */
+ DRW_opengl_context_enable();
+ /* IMPORTANT: We dont support immediate mode in render mode!
+ * This shall remain in effect until immediate mode supports
+ * multiple threads. */
+
+ /* Reset before using it. */
+ drw_state_prepare_clean_for_draw(&DST);
+ DST.options.is_image_render = true;
+ DST.options.is_scene_render = true;
+ DST.options.draw_background = scene->r.alphamode == R_ADDSKY;
+
+ DST.draw_ctx = (DRWContextState){
+ .scene = scene, .view_layer = view_layer,
+ .engine_type = engine_type,
+ .depsgraph = depsgraph, .object_mode = OB_MODE_OBJECT,
+ };
+ drw_context_state_init();
+
+ DST.viewport = GPU_viewport_create();
+ const int size[2] = {(r->size * r->xsch) / 100, (r->size * r->ysch) / 100};
+ GPU_viewport_size_set(DST.viewport, size);
+
+ drw_viewport_var_init();
+
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(draw_engine_type);
+
+ /* set default viewport */
+ glViewport(0, 0, size[0], size[1]);
+
+ /* Main rendering. */
+ rctf view_rect;
+ rcti render_rect;
+ RE_GetViewPlane(render, &view_rect, &render_rect);
+ if (BLI_rcti_is_empty(&render_rect)) {
+ BLI_rcti_init(&render_rect, 0, size[0], 0, size[1]);
+ }
+
+ /* Init render result. */
+ RenderResult *render_result = RE_engine_begin_result(
+ engine,
+ 0,
+ 0,
+ (int)size[0],
+ (int)size[1],
+ view_layer->name,
+ /* RR_ALL_VIEWS */ NULL);
+
+ RenderLayer *render_layer = render_result->layers.first;
+ for (RenderView *render_view = render_result->views.first;
+ render_view != NULL;
+ render_view = render_view->next)
+ {
+ RE_SetActiveRenderView(render, render_view->name);
+ engine_type->draw_engine->render_to_image(data, engine, render_layer, &render_rect);
+ DST.buffer_finish_called = false;
+ }
+
+ RE_engine_end_result(engine, render_result, false, false, false);
+
+ /* Force cache to reset. */
+ drw_viewport_cache_resize();
+
+ /* TODO grease pencil */
+
+ GPU_viewport_free(DST.viewport);
+ GPU_framebuffer_restore();
+
+ /* Changing Context */
+ DRW_opengl_context_disable();
+
+#ifdef DEBUG
+ /* Avoid accidental reuse. */
+ drw_state_ensure_not_reused(&DST);
+#endif
+}
+
+void DRW_render_object_iter(
+ void *vedata, RenderEngine *engine, struct Depsgraph *depsgraph,
+ void (*callback)(void *vedata, Object *ob, RenderEngine *engine, struct Depsgraph *depsgraph))
+{
+ DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob, DRW_iterator_mode_get())
+ {
+ DST.ob_state = NULL;
+ callback(vedata, ob, engine, depsgraph);
+ }
+ DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END
+}
+
+static struct DRWSelectBuffer {
+ struct GPUFrameBuffer *framebuffer;
+ struct GPUTexture *texture_depth;
+} g_select_buffer = {NULL};
+
+static void draw_select_framebuffer_setup(const rcti *rect)
+{
+ if (g_select_buffer.framebuffer == NULL) {
+ g_select_buffer.framebuffer = GPU_framebuffer_create();
+ }
+
+ /* If size mismatch recreate the texture. */
+ if ((g_select_buffer.texture_depth != NULL) &&
+ ((GPU_texture_width(g_select_buffer.texture_depth) != BLI_rcti_size_x(rect)) ||
+ (GPU_texture_height(g_select_buffer.texture_depth) != BLI_rcti_size_y(rect))))
+ {
+ GPU_texture_free(g_select_buffer.texture_depth);
+ g_select_buffer.texture_depth = NULL;
+ }
+
+ if (g_select_buffer.texture_depth == NULL) {
+ g_select_buffer.texture_depth = GPU_texture_create_2D(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect), GPU_DEPTH_COMPONENT24, NULL, NULL);
+
+ GPU_framebuffer_texture_attach(g_select_buffer.framebuffer, g_select_buffer.texture_depth, 0, 0);
+
+ if (!GPU_framebuffer_check_valid(g_select_buffer.framebuffer, NULL)) {
+ printf("Error invalid selection framebuffer\n");
+ }
+ }
+}
+
+/* Must run after all instance datas have been added. */
+void DRW_render_instance_buffer_finish(void)
+{
+ BLI_assert(!DST.buffer_finish_called && "DRW_render_instance_buffer_finish called twice!");
+ DST.buffer_finish_called = true;
+ DRW_instance_buffer_finish(DST.idatalist);
+}
+
+/**
+ * object mode select-loop, see: ED_view3d_draw_select_loop (legacy drawing).
+ */
+void DRW_draw_select_loop(
+ struct Depsgraph *depsgraph,
+ ARegion *ar, View3D *v3d,
+ bool UNUSED(use_obedit_skip), bool UNUSED(use_nearest), const rcti *rect,
+ DRW_SelectPassFn select_pass_fn, void *select_pass_user_data)
+{
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+ RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype);
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ Object *obact = OBACT(view_layer);
+ Object *obedit = OBEDIT_FROM_OBACT(obact);
+#ifndef USE_GPU_SELECT
+ UNUSED_VARS(vc, scene, view_layer, v3d, ar, rect);
+#else
+ RegionView3D *rv3d = ar->regiondata;
+
+ /* Reset before using it. */
+ drw_state_prepare_clean_for_draw(&DST);
+
+ bool use_obedit = false;
+ int obedit_mode = 0;
+ if (obedit != NULL) {
+ if (obedit->type == OB_MBALL) {
+ use_obedit = true;
+ obedit_mode = CTX_MODE_EDIT_METABALL;
+ }
+ else if (obedit->type == OB_ARMATURE) {
+ use_obedit = true;
+ obedit_mode = CTX_MODE_EDIT_ARMATURE;
+ }
+ }
+
+ struct GPUViewport *viewport = GPU_viewport_create();
+ GPU_viewport_size_set(viewport, (const int[2]){BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)});
+
+ DST.viewport = viewport;
+ v3d->zbuf = true;
+
+ DST.options.is_select = true;
+
+ /* Get list of enabled engines */
+ if (use_obedit) {
+ drw_engines_enable_from_mode(obedit_mode);
+ }
+ else {
+ drw_engines_enable_basic();
+ drw_engines_enable_from_object_mode();
+ }
+
+ /* Setup viewport */
+
+ /* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */
+ DST.draw_ctx = (DRWContextState){
+ .ar = ar, .rv3d = rv3d, .v3d = v3d,
+ .scene = scene, .view_layer = view_layer, .obact = obact,
+ .engine_type = engine_type,
+ .depsgraph = depsgraph,
+ };
+ drw_context_state_init();
+ drw_viewport_var_init();
+
+ /* Update ubos */
+ DRW_globals_update();
+
+ /* Init engines */
+ drw_engines_init();
+
+ {
+ drw_engines_cache_init();
+
+ if (use_obedit) {
+#if 0
+ drw_engines_cache_populate(obact);
+#else
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, obact->mode, ob_iter) {
+ drw_engines_cache_populate(ob_iter);
+ }
+ FOREACH_OBJECT_IN_MODE_END;
+#endif
+ }
+ else {
+ DEG_OBJECT_ITER_BEGIN(
+ depsgraph, ob, DRW_iterator_mode_get(),
+ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
+ DEG_ITER_OBJECT_FLAG_VISIBLE |
+ DEG_ITER_OBJECT_FLAG_DUPLI)
+ {
+ if ((ob->base_flag & BASE_SELECTABLED) != 0) {
+ DRW_select_load_id(ob->select_color);
+ drw_engines_cache_populate(ob);
+ }
+ }
+ DEG_OBJECT_ITER_END;
+ }
+
+ drw_engines_cache_finish();
+
+ DRW_render_instance_buffer_finish();
+ }
+
+ /* Setup framebuffer */
+ draw_select_framebuffer_setup(rect);
+ GPU_framebuffer_bind(g_select_buffer.framebuffer);
+ GPU_framebuffer_clear_depth(g_select_buffer.framebuffer, 1.0f);
+
+ /* Start Drawing */
+ DRW_state_reset();
+ DRW_draw_callbacks_pre_scene();
+
+ DRW_state_lock(
+ DRW_STATE_WRITE_DEPTH |
+ DRW_STATE_DEPTH_ALWAYS |
+ DRW_STATE_DEPTH_LESS |
+ DRW_STATE_DEPTH_EQUAL |
+ DRW_STATE_DEPTH_GREATER |
+ DRW_STATE_DEPTH_ALWAYS);
+
+ /* Only 1-2 passes. */
+ while (true) {
+ if (!select_pass_fn(DRW_SELECT_PASS_PRE, select_pass_user_data)) {
+ break;
+ }
+
+ drw_engines_draw_scene();
+
+ if (!select_pass_fn(DRW_SELECT_PASS_POST, select_pass_user_data)) {
+ break;
+ }
+ }
+
+ DRW_state_lock(0);
+
+ DRW_draw_callbacks_post_scene();
+
+ DRW_state_reset();
+ drw_engines_disable();
+
+#ifdef DEBUG
+ /* Avoid accidental reuse. */
+ drw_state_ensure_not_reused(&DST);
+#endif
+ GPU_framebuffer_restore();
+
+ /* Cleanup for selection state */
+ GPU_viewport_free(viewport);
+#endif /* USE_GPU_SELECT */
+}
+
+static void draw_depth_texture_to_screen(GPUTexture *texture)
+{
+ const float w = (float)GPU_texture_width(texture);
+ const float h = (float)GPU_texture_height(texture);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_IMAGE_DEPTH_COPY);
+
+ GPU_texture_bind(texture, 0);
+
+ immUniform1i("image", 0); /* default GL_TEXTURE0 unit */
+
+ immBegin(GWN_PRIM_TRI_STRIP, 4);
+
+ immAttrib2f(texcoord, 0.0f, 0.0f);
+ immVertex2f(pos, 0.0f, 0.0f);
+
+ immAttrib2f(texcoord, 1.0f, 0.0f);
+ immVertex2f(pos, w, 0.0f);
+
+ immAttrib2f(texcoord, 0.0f, 1.0f);
+ immVertex2f(pos, 0.0f, h);
+
+ immAttrib2f(texcoord, 1.0f, 1.0f);
+ immVertex2f(pos, w, h);
+
+ immEnd();
+
+ GPU_texture_unbind(texture);
+
+ immUnbindProgram();
+}
+
+/**
+ * object mode select-loop, see: ED_view3d_draw_depth_loop (legacy drawing).
+ */
+void DRW_draw_depth_loop(
+ Depsgraph *depsgraph,
+ ARegion *ar, View3D *v3d)
+{
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+ RenderEngineType *engine_type = ED_view3d_engine_type(scene, v3d->drawtype);
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ RegionView3D *rv3d = ar->regiondata;
+
+ DRW_opengl_context_enable();
+
+ /* Reset before using it. */
+ drw_state_prepare_clean_for_draw(&DST);
+
+ struct GPUViewport *viewport = GPU_viewport_create();
+ GPU_viewport_size_set(viewport, (const int[2]){ar->winx, ar->winy});
+
+ /* Setup framebuffer */
+ draw_select_framebuffer_setup(&ar->winrct);
+ GPU_framebuffer_bind(g_select_buffer.framebuffer);
+ GPU_framebuffer_clear_depth(g_select_buffer.framebuffer, 1.0f);
+
+ bool cache_is_dirty;
+ DST.viewport = viewport;
+ v3d->zbuf = true;
+
+ DST.options.is_depth = true;
+
+ /* Get list of enabled engines */
+ {
+ drw_engines_enable_basic();
+ drw_engines_enable_from_object_mode();
+ }
+
+ /* Setup viewport */
+ cache_is_dirty = true;
+
+ /* Instead of 'DRW_context_state_init(C, &DST.draw_ctx)', assign from args */
+ DST.draw_ctx = (DRWContextState){
+ .ar = ar, .rv3d = rv3d, .v3d = v3d,
+ .scene = scene, .view_layer = view_layer, .obact = OBACT(view_layer),
+ .engine_type = engine_type,
+ .depsgraph = depsgraph,
+ };
+ drw_context_state_init();
+ drw_viewport_var_init();
+
+ /* Update ubos */
+ DRW_globals_update();
+
+ /* Init engines */
+ drw_engines_init();
+
+ /* TODO : tag to refresh by the dependency graph */
+ /* ideally only refresh when objects are added/removed */
+ /* or render properties / materials change */
+ if (cache_is_dirty) {
+ drw_engines_cache_init();
+
+ DEG_OBJECT_ITER_FOR_RENDER_ENGINE_BEGIN(depsgraph, ob, DRW_iterator_mode_get())
+ {
+ drw_engines_cache_populate(ob);
+ }
+ DEG_OBJECT_ITER_FOR_RENDER_ENGINE_END;
+
+ drw_engines_cache_finish();
+
+ DRW_render_instance_buffer_finish();
+ }
+
+ /* Start Drawing */
+ DRW_state_reset();
+ DRW_draw_callbacks_pre_scene();
+ drw_engines_draw_scene();
+ DRW_draw_callbacks_post_scene();
+
+ DRW_state_reset();
+ drw_engines_disable();
+
+#ifdef DEBUG
+ /* Avoid accidental reuse. */
+ drw_state_ensure_not_reused(&DST);
+#endif
+
+ /* TODO: Reading depth for operators should be done here. */
+
+ GPU_framebuffer_restore();
+
+ /* Cleanup for selection state */
+ GPU_viewport_free(viewport);
+
+ /* Changin context */
+ DRW_opengl_context_disable();
+
+ /* XXX Drawing the resulting buffer to the BACK_BUFFER */
+ gpuPushMatrix();
+ gpuPushProjectionMatrix();
+ wmOrtho2_region_pixelspace(ar);
+ gpuLoadIdentity();
+
+ glEnable(GL_DEPTH_TEST); /* Cannot write to depth buffer without testing */
+ glDepthFunc(GL_ALWAYS);
+ draw_depth_texture_to_screen(g_select_buffer.texture_depth);
+ glDepthFunc(GL_LEQUAL);
+
+ gpuPopMatrix();
+ gpuPopProjectionMatrix();
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Draw Manager State (DRW_state)
+ * \{ */
+
+void DRW_state_dfdy_factors_get(float dfdyfac[2])
+{
+ GPU_get_dfdy_factors(dfdyfac);
+}
+
+/**
+ * When false, drawing doesn't output to a pixel buffer
+ * eg: Occlusion queries, or when we have setup a context to draw in already.
+ */
+bool DRW_state_is_fbo(void)
+{
+ return ((DST.default_framebuffer != NULL) || DST.options.is_image_render);
+}
+
+/**
+ * For when engines need to know if this is drawing for selection or not.
+ */
+bool DRW_state_is_select(void)
+{
+ return DST.options.is_select;
+}
+
+bool DRW_state_is_depth(void)
+{
+ return DST.options.is_depth;
+}
+
+/**
+ * Whether we are rendering for an image
+ */
+bool DRW_state_is_image_render(void)
+{
+ return DST.options.is_image_render;
+}
+
+/**
+ * Whether we are rendering only the render engine,
+ * or if we should also render the mode engines.
+ */
+bool DRW_state_is_scene_render(void)
+{
+ BLI_assert(DST.options.is_scene_render ?
+ DST.options.is_image_render : true);
+ return DST.options.is_scene_render;
+}
+
+/**
+* Whether we are rendering simple opengl render
+*/
+bool DRW_state_is_opengl_render(void)
+{
+ return DST.options.is_image_render && !DST.options.is_scene_render;
+}
+
+/**
+ * Gives you the iterator mode to use for depsgraph.
+ */
+eDepsObjectIteratorMode DRW_iterator_mode_get(void)
+{
+ return DRW_state_is_scene_render() ? DEG_ITER_OBJECT_MODE_RENDER :
+ DEG_ITER_OBJECT_MODE_VIEWPORT;
+}
+
+/**
+ * Should text draw in this mode?
+ */
+bool DRW_state_show_text(void)
+{
+ return (DST.options.is_select) == 0 &&
+ (DST.options.is_depth) == 0 &&
+ (DST.options.is_scene_render) == 0;
+}
+
+/**
+ * Should draw support elements
+ * Objects center, selection outline, probe data, ...
+ */
+bool DRW_state_draw_support(void)
+{
+ View3D *v3d = DST.draw_ctx.v3d;
+ return (DRW_state_is_scene_render() == false) &&
+ (v3d != NULL) &&
+ ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0);
+}
+
+/**
+ * Whether we should render the background
+ */
+bool DRW_state_draw_background(void)
+{
+ if (DRW_state_is_image_render() == false) {
+ return true;
+ }
+ return DST.options.draw_background;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Context State (DRW_context_state)
+ * \{ */
+
+const DRWContextState *DRW_context_state_get(void)
+{
+ return &DST.draw_ctx;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Init/Exit (DRW_engines)
+ * \{ */
+
+bool DRW_engine_render_support(DrawEngineType *draw_engine_type)
+{
+ return draw_engine_type->render_to_image;
+}
+
+void DRW_engine_register(DrawEngineType *draw_engine_type)
+{
+ BLI_addtail(&DRW_engines, draw_engine_type);
+}
+
+void DRW_engines_register(void)
+{
+#ifdef WITH_CLAY_ENGINE
+ RE_engines_register(NULL, &DRW_engine_viewport_clay_type);
+#endif
+ RE_engines_register(NULL, &DRW_engine_viewport_eevee_type);
+ RE_engines_register(NULL, &DRW_engine_viewport_workbench_type);
+
+ DRW_engine_register(&draw_engine_workbench_solid);
+
+ DRW_engine_register(&draw_engine_object_type);
+ DRW_engine_register(&draw_engine_edit_armature_type);
+ DRW_engine_register(&draw_engine_edit_curve_type);
+ DRW_engine_register(&draw_engine_edit_lattice_type);
+ DRW_engine_register(&draw_engine_edit_mesh_type);
+ DRW_engine_register(&draw_engine_edit_metaball_type);
+ DRW_engine_register(&draw_engine_edit_surface_type);
+ DRW_engine_register(&draw_engine_edit_text_type);
+ DRW_engine_register(&draw_engine_overlay_type);
+ DRW_engine_register(&draw_engine_paint_texture_type);
+ DRW_engine_register(&draw_engine_paint_vertex_type);
+ DRW_engine_register(&draw_engine_paint_weight_type);
+ DRW_engine_register(&draw_engine_particle_type);
+ DRW_engine_register(&draw_engine_pose_type);
+ DRW_engine_register(&draw_engine_sculpt_type);
+
+ /* setup callbacks */
+ {
+ /* BKE: mball.c */
+ extern void *BKE_mball_batch_cache_dirty_cb;
+ extern void *BKE_mball_batch_cache_free_cb;
+ /* BKE: curve.c */
+ extern void *BKE_curve_batch_cache_dirty_cb;
+ extern void *BKE_curve_batch_cache_free_cb;
+ /* BKE: mesh.c */
+ extern void *BKE_mesh_batch_cache_dirty_cb;
+ extern void *BKE_mesh_batch_cache_free_cb;
+ /* BKE: lattice.c */
+ extern void *BKE_lattice_batch_cache_dirty_cb;
+ extern void *BKE_lattice_batch_cache_free_cb;
+ /* BKE: particle.c */
+ extern void *BKE_particle_batch_cache_dirty_cb;
+ extern void *BKE_particle_batch_cache_free_cb;
+
+ BKE_mball_batch_cache_dirty_cb = DRW_mball_batch_cache_dirty;
+ BKE_mball_batch_cache_free_cb = DRW_mball_batch_cache_free;
+
+ BKE_curve_batch_cache_dirty_cb = DRW_curve_batch_cache_dirty;
+ BKE_curve_batch_cache_free_cb = DRW_curve_batch_cache_free;
+
+ BKE_mesh_batch_cache_dirty_cb = DRW_mesh_batch_cache_dirty;
+ BKE_mesh_batch_cache_free_cb = DRW_mesh_batch_cache_free;
+
+ BKE_lattice_batch_cache_dirty_cb = DRW_lattice_batch_cache_dirty;
+ BKE_lattice_batch_cache_free_cb = DRW_lattice_batch_cache_free;
+
+ BKE_particle_batch_cache_dirty_cb = DRW_particle_batch_cache_dirty;
+ BKE_particle_batch_cache_free_cb = DRW_particle_batch_cache_free;
+ }
+}
+
+extern struct Gwn_VertFormat *g_pos_format; /* draw_shgroup.c */
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GPUTexture *globals_ramp; /* draw_common.c */
+void DRW_engines_free(void)
+{
+ DRW_opengl_context_enable();
+
+ DRW_TEXTURE_FREE_SAFE(g_select_buffer.texture_depth);
+ GPU_FRAMEBUFFER_FREE_SAFE(g_select_buffer.framebuffer);
+
+ DRW_shape_cache_free();
+ DRW_stats_free();
+ DRW_globals_free();
+
+ DrawEngineType *next;
+ for (DrawEngineType *type = DRW_engines.first; type; type = next) {
+ next = type->next;
+ BLI_remlink(&R_engines, type);
+
+ if (type->engine_free) {
+ type->engine_free();
+ }
+ }
+
+ DRW_UBO_FREE_SAFE(globals_ubo);
+ DRW_UBO_FREE_SAFE(view_ubo);
+ DRW_TEXTURE_FREE_SAFE(globals_ramp);
+ MEM_SAFE_FREE(g_pos_format);
+
+ MEM_SAFE_FREE(DST.RST.bound_texs);
+ MEM_SAFE_FREE(DST.RST.bound_tex_slots);
+ MEM_SAFE_FREE(DST.RST.bound_ubos);
+ MEM_SAFE_FREE(DST.RST.bound_ubo_slots);
+
+ DRW_opengl_context_disable();
+
+#ifdef WITH_CLAY_ENGINE
+ BLI_remlink(&R_engines, &DRW_engine_viewport_clay_type);
+#endif
+}
+
+/** \} */
+
+/** \name Init/Exit (DRW_opengl_ctx)
+ * \{ */
+
+void DRW_opengl_context_create(void)
+{
+ BLI_assert(DST.ogl_context == NULL); /* Ensure it's called once */
+
+ BLI_mutex_init(&DST.ogl_context_mutex);
+ if (!G.background) {
+ immDeactivate();
+ }
+ /* This changes the active context. */
+ DST.ogl_context = WM_opengl_context_create();
+ /* Be sure to create gawain.context too. */
+ DST.gwn_context = GWN_context_create();
+ if (!G.background) {
+ immActivate();
+ }
+ /* Set default Blender OpenGL state */
+ GPU_state_init();
+ /* So we activate the window's one afterwards. */
+ wm_window_reset_drawable();
+}
+
+void DRW_opengl_context_destroy(void)
+{
+ BLI_assert(BLI_thread_is_main());
+ if (DST.ogl_context != NULL) {
+ WM_opengl_context_activate(DST.ogl_context);
+ GWN_context_active_set(DST.gwn_context);
+ GWN_context_discard(DST.gwn_context);
+ WM_opengl_context_dispose(DST.ogl_context);
+ BLI_mutex_end(&DST.ogl_context_mutex);
+ }
+}
+
+void DRW_opengl_context_enable(void)
+{
+ if (DST.ogl_context != NULL) {
+ /* IMPORTANT: We dont support immediate mode in render mode!
+ * This shall remain in effect until immediate mode supports
+ * multiple threads. */
+ BLI_mutex_lock(&DST.ogl_context_mutex);
+ if (BLI_thread_is_main()) {
+ if (!G.background) {
+ immDeactivate();
+ }
+ }
+ WM_opengl_context_activate(DST.ogl_context);
+ GWN_context_active_set(DST.gwn_context);
+ if (BLI_thread_is_main()) {
+ if (!G.background) {
+ immActivate();
+ }
+ BLF_batch_reset();
+ }
+ }
+}
+
+void DRW_opengl_context_disable(void)
+{
+ if (DST.ogl_context != NULL) {
+#ifdef __APPLE__
+ /* Need to flush before disabling draw context, otherwise it does not
+ * always finish drawing and viewport can be empty or partially drawn */
+ glFlush();
+#endif
+
+ if (BLI_thread_is_main()) {
+ wm_window_reset_drawable();
+ }
+ else {
+ WM_opengl_context_release(DST.ogl_context);
+ GWN_context_active_set(NULL);
+ }
+
+ BLI_mutex_unlock(&DST.ogl_context_mutex);
+ }
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/draw_manager.h b/source/blender/draw/intern/draw_manager.h
new file mode 100644
index 00000000000..7a45b808651
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager.h
@@ -0,0 +1,364 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_manager.h
+ * \ingroup draw
+ */
+
+/* Private functions / structs of the draw manager */
+
+#ifndef __DRAW_MANAGER_H__
+#define __DRAW_MANAGER_H__
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "BLI_linklist.h"
+#include "BLI_threads.h"
+
+#include "GPU_batch.h"
+#include "GPU_framebuffer.h"
+#include "GPU_shader.h"
+#include "GPU_uniformbuffer.h"
+#include "GPU_viewport.h"
+
+#include "draw_instance_data.h"
+
+/* Use draw manager to call GPU_select, see: DRW_draw_select_loop */
+#define USE_GPU_SELECT
+
+/* ------------ Profiling --------------- */
+
+#define USE_PROFILE
+
+#ifdef USE_PROFILE
+# include "PIL_time.h"
+
+# define PROFILE_TIMER_FALLOFF 0.04
+
+# define PROFILE_START(time_start) \
+ double time_start = PIL_check_seconds_timer();
+
+# define PROFILE_END_ACCUM(time_accum, time_start) { \
+ time_accum += (PIL_check_seconds_timer() - time_start) * 1e3; \
+} ((void)0)
+
+/* exp average */
+# define PROFILE_END_UPDATE(time_update, time_start) { \
+ double _time_delta = (PIL_check_seconds_timer() - time_start) * 1e3; \
+ time_update = (time_update * (1.0 - PROFILE_TIMER_FALLOFF)) + \
+ (_time_delta * PROFILE_TIMER_FALLOFF); \
+} ((void)0)
+
+#else /* USE_PROFILE */
+
+# define PROFILE_START(time_start) ((void)0)
+# define PROFILE_END_ACCUM(time_accum, time_start) ((void)0)
+# define PROFILE_END_UPDATE(time_update, time_start) ((void)0)
+
+#endif /* USE_PROFILE */
+
+/* ------------ Data Structure --------------- */
+/**
+ * Data structure containing all drawcalls organized by passes and materials.
+ * DRWPass > DRWShadingGroup > DRWCall > DRWCallState
+ * > DRWUniform
+ **/
+
+/* Used by DRWCallState.flag */
+enum {
+ DRW_CALL_CULLED = (1 << 0),
+ DRW_CALL_NEGSCALE = (1 << 1),
+};
+
+/* Used by DRWCallState.matflag */
+enum {
+ DRW_CALL_MODELINVERSE = (1 << 0),
+ DRW_CALL_MODELVIEW = (1 << 1),
+ DRW_CALL_MODELVIEWINVERSE = (1 << 2),
+ DRW_CALL_MODELVIEWPROJECTION = (1 << 3),
+ DRW_CALL_NORMALVIEW = (1 << 4),
+ DRW_CALL_NORMALWORLD = (1 << 5),
+ DRW_CALL_ORCOTEXFAC = (1 << 6),
+ DRW_CALL_EYEVEC = (1 << 7),
+};
+
+typedef struct DRWCallState {
+ DRWCallVisibilityFn *visibility_cb;
+ void *user_data;
+
+ unsigned char flag;
+ unsigned char cache_id; /* Compared with DST.state_cache_id to see if matrices are still valid. */
+ uint16_t matflag; /* Which matrices to compute. */
+ /* Culling: Using Bounding Sphere for now for faster culling.
+ * Not ideal for planes. */
+ BoundSphere bsphere;
+ /* Matrices */
+ float model[4][4];
+ float modelinverse[4][4];
+ float modelview[4][4];
+ float modelviewinverse[4][4];
+ float modelviewprojection[4][4];
+ float normalview[3][3];
+ float normalworld[3][3]; /* Not view dependant */
+ float orcotexfac[2][3]; /* Not view dependant */
+ float eyevec[3];
+} DRWCallState;
+
+typedef enum {
+ DRW_CALL_SINGLE, /* A single batch */
+ DRW_CALL_INSTANCES, /* Draw instances without any instancing attribs. */
+ DRW_CALL_GENERATE, /* Uses a callback to draw with any number of batches. */
+} DRWCallType;
+
+typedef struct DRWCall {
+ struct DRWCall *next;
+ DRWCallState *state;
+
+ union {
+ struct { /* type == DRW_CALL_SINGLE */
+ Gwn_Batch *geometry;
+ } single;
+ struct { /* type == DRW_CALL_INSTANCES */
+ Gwn_Batch *geometry;
+ /* Count can be adjusted between redraw. If needed, we can add fixed count. */
+ unsigned int *count;
+ } instances;
+ struct { /* type == DRW_CALL_GENERATE */
+ DRWCallGenerateFn *geometry_fn;
+ void *user_data;
+ } generate;
+ };
+
+ DRWCallType type;
+#ifdef USE_GPU_SELECT
+ int select_id;
+#endif
+} DRWCall;
+
+/* Used by DRWUniform.type */
+typedef enum {
+ DRW_UNIFORM_BOOL,
+ DRW_UNIFORM_SHORT_TO_INT,
+ DRW_UNIFORM_SHORT_TO_FLOAT,
+ DRW_UNIFORM_INT,
+ DRW_UNIFORM_INT_COPY,
+ DRW_UNIFORM_FLOAT,
+ DRW_UNIFORM_TEXTURE,
+ DRW_UNIFORM_TEXTURE_PERSIST,
+ DRW_UNIFORM_TEXTURE_REF,
+ DRW_UNIFORM_BLOCK,
+ DRW_UNIFORM_BLOCK_PERSIST
+} DRWUniformType;
+
+struct DRWUniform {
+ DRWUniform *next; /* single-linked list */
+ const void *value;
+ int location;
+ char type; /* DRWUniformType */
+ char length; /* cannot be more than 16 */
+ char arraysize; /* cannot be more than 16 too */
+};
+
+typedef enum {
+ DRW_SHG_NORMAL,
+ DRW_SHG_POINT_BATCH,
+ DRW_SHG_LINE_BATCH,
+ DRW_SHG_TRIANGLE_BATCH,
+ DRW_SHG_INSTANCE,
+ DRW_SHG_INSTANCE_EXTERNAL,
+} DRWShadingGroupType;
+
+struct DRWShadingGroup {
+ DRWShadingGroup *next;
+
+ GPUShader *shader; /* Shader to bind */
+ DRWUniform *uniforms; /* Uniforms pointers */
+
+ /* Watch this! Can be nasty for debugging. */
+ union {
+ struct { /* DRW_SHG_NORMAL */
+ DRWCall *first, *last; /* Linked list of DRWCall or DRWCallDynamic depending of type */
+ } calls;
+ struct { /* DRW_SHG_***_BATCH */
+ struct Gwn_Batch *batch_geom; /* Result of call batching */
+ struct Gwn_VertBuf *batch_vbo;
+ unsigned int primitive_count;
+ };
+ struct { /* DRW_SHG_INSTANCE[_EXTERNAL] */
+ struct Gwn_Batch *instance_geom;
+ struct Gwn_VertBuf *instance_vbo;
+ unsigned int instance_count;
+ float instance_orcofac[2][3]; /* TODO find a better place. */
+ };
+ };
+
+ DRWState state_extra; /* State changes for this batch only (or'd with the pass's state) */
+ DRWState state_extra_disable; /* State changes for this batch only (and'd with the pass's state) */
+ unsigned int stencil_mask; /* Stencil mask to use for stencil test / write operations */
+ DRWShadingGroupType type;
+
+ /* Builtin matrices locations */
+ int model;
+ int modelinverse;
+ int modelview;
+ int modelviewinverse;
+ int modelviewprojection;
+ int normalview;
+ int normalworld;
+ int orcotexfac;
+ int eye;
+ int callid;
+ uint16_t matflag; /* Matrices needed, same as DRWCall.flag */
+
+#ifndef NDEBUG
+ char attribs_count;
+#endif
+
+#ifdef USE_GPU_SELECT
+ DRWInstanceData *inst_selectid;
+ DRWPass *pass_parent; /* backlink to pass we're in */
+ int override_selectid; /* Override for single object instances. */
+#endif
+};
+
+#define MAX_PASS_NAME 32
+
+struct DRWPass {
+ /* Linked list */
+ struct {
+ DRWShadingGroup *first;
+ DRWShadingGroup *last;
+ } shgroups;
+
+ DRWState state;
+ char name[MAX_PASS_NAME];
+};
+
+typedef struct ViewUboStorage {
+ DRWMatrixState matstate;
+ float viewcamtexcofac[4];
+ float clipplanes[2][4];
+} ViewUboStorage;
+
+/* ------------- DRAW MANAGER ------------ */
+
+#define MAX_CLIP_PLANES 6 /* GL_MAX_CLIP_PLANES is at least 6 */
+#define STENCIL_UNDEFINED 256
+typedef struct DRWManager {
+ /* TODO clean up this struct a bit */
+ /* Cache generation */
+ ViewportMemoryPool *vmempool;
+ DRWInstanceDataList *idatalist;
+ DRWInstanceData *common_instance_data[MAX_INSTANCE_DATA_SIZE];
+ /* State of the object being evaluated if already allocated. */
+ DRWCallState *ob_state;
+ unsigned char state_cache_id; /* Could be larger but 254 view changes is already a lot! */
+
+ /* Rendering state */
+ GPUShader *shader;
+
+ /* Managed by `DRW_state_set`, `DRW_state_reset` */
+ DRWState state;
+ DRWState state_lock;
+ unsigned int stencil_mask;
+
+ /* Per viewport */
+ GPUViewport *viewport;
+ struct GPUFrameBuffer *default_framebuffer;
+ float size[2];
+ float inv_size[2];
+ float screenvecs[2][3];
+ float pixsize;
+
+ GLenum backface, frontface;
+
+ struct {
+ unsigned int is_select : 1;
+ unsigned int is_depth : 1;
+ unsigned int is_image_render : 1;
+ unsigned int is_scene_render : 1;
+ unsigned int draw_background : 1;
+ } options;
+
+ /* Current rendering context */
+ DRWContextState draw_ctx;
+
+ /* Convenience pointer to text_store owned by the viewport */
+ struct DRWTextStore **text_store_p;
+
+ ListBase enabled_engines; /* RenderEngineType */
+
+ bool buffer_finish_called; /* Avoid bad usage of DRW_render_instance_buffer_finish */
+
+ /* View dependant uniforms. */
+ DRWMatrixState original_mat; /* Original rv3d matrices. */
+ int override_mat; /* Bitflag of which matrices are overriden. */
+ int num_clip_planes; /* Number of active clipplanes. */
+ bool dirty_mat;
+
+ /* keep in sync with viewBlock */
+ ViewUboStorage view_data;
+
+ struct {
+ float frustum_planes[6][4];
+ BoundBox frustum_corners;
+ BoundSphere frustum_bsphere;
+ bool updated;
+ } clipping;
+
+#ifdef USE_GPU_SELECT
+ unsigned int select_id;
+#endif
+
+ /* ---------- Nothing after this point is cleared after use ----------- */
+
+ /* ogl_context serves as the offset for clearing only
+ * the top portion of the struct so DO NOT MOVE IT! */
+ void *ogl_context; /* Unique ghost context used by the draw manager. */
+ Gwn_Context *gwn_context;
+ ThreadMutex ogl_context_mutex; /* Mutex to lock the drw manager and avoid concurent context usage. */
+
+ /** GPU Resource State: Memory storage between drawing. */
+ struct {
+ GPUTexture **bound_texs;
+ char *bound_tex_slots;
+ int bind_tex_inc;
+ GPUUniformBuffer **bound_ubos;
+ char *bound_ubo_slots;
+ int bind_ubo_inc;
+ } RST;
+} DRWManager;
+
+extern DRWManager DST; /* TODO : get rid of this and allow multithreaded rendering */
+
+/* --------------- FUNCTIONS ------------- */
+
+void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags);
+void drw_texture_get_format(
+ GPUTextureFormat format, bool is_framebuffer,
+ GPUTextureFormat *r_data_type, int *r_channels, bool *r_is_depth);
+
+void *drw_viewport_engine_data_ensure(void *engine_type);
+
+void drw_state_set(DRWState state);
+
+#endif /* __DRAW_MANAGER_H__ */
diff --git a/source/blender/draw/intern/draw_manager_data.c b/source/blender/draw/intern/draw_manager_data.c
new file mode 100644
index 00000000000..26b4e23faf1
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_data.c
@@ -0,0 +1,973 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_manager_data.c
+ * \ingroup draw
+ */
+
+#include "draw_manager.h"
+
+#include "BKE_curve.h"
+#include "BKE_global.h"
+#include "BKE_mesh.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_pbvh.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meta_types.h"
+
+#include "BLI_link_utils.h"
+#include "BLI_mempool.h"
+
+#include "intern/gpu_codegen.h"
+
+struct Gwn_VertFormat *g_pos_format = NULL;
+
+extern struct GPUUniformBuffer *view_ubo; /* draw_manager_exec.c */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Uniform Buffer Object (DRW_uniformbuffer)
+ * \{ */
+
+GPUUniformBuffer *DRW_uniformbuffer_create(int size, const void *data)
+{
+ return GPU_uniformbuffer_create(size, data, NULL);
+}
+
+void DRW_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data)
+{
+ GPU_uniformbuffer_update(ubo, data);
+}
+
+void DRW_uniformbuffer_free(GPUUniformBuffer *ubo)
+{
+ GPU_uniformbuffer_free(ubo);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Uniforms (DRW_shgroup_uniform)
+ * \{ */
+
+static void drw_shgroup_uniform_create_ex(DRWShadingGroup *shgroup, int loc,
+ DRWUniformType type, const void *value, int length, int arraysize)
+{
+ DRWUniform *uni = BLI_mempool_alloc(DST.vmempool->uniforms);
+ uni->location = loc;
+ uni->type = type;
+ uni->value = value;
+ uni->length = length;
+ uni->arraysize = arraysize;
+
+ BLI_LINKS_PREPEND(shgroup->uniforms, uni);
+}
+
+static void drw_shgroup_builtin_uniform(
+ DRWShadingGroup *shgroup, int builtin, const void *value, int length, int arraysize)
+{
+ int loc = GPU_shader_get_builtin_uniform(shgroup->shader, builtin);
+
+ if (loc != -1) {
+ drw_shgroup_uniform_create_ex(shgroup, loc, DRW_UNIFORM_FLOAT, value, length, arraysize);
+ }
+}
+
+static void drw_shgroup_uniform(DRWShadingGroup *shgroup, const char *name,
+ DRWUniformType type, const void *value, int length, int arraysize)
+{
+ int location;
+ if (ELEM(type, DRW_UNIFORM_BLOCK, DRW_UNIFORM_BLOCK_PERSIST)) {
+ location = GPU_shader_get_uniform_block(shgroup->shader, name);
+ }
+ else {
+ location = GPU_shader_get_uniform(shgroup->shader, name);
+ }
+
+ if (location == -1) {
+ if (G.debug & G_DEBUG)
+ fprintf(stderr, "Uniform '%s' not found!\n", name);
+ /* Nice to enable eventually, for now eevee uses uniforms that might not exist. */
+ // BLI_assert(0);
+ return;
+ }
+
+ BLI_assert(arraysize > 0 && arraysize <= 16);
+ BLI_assert(length >= 0 && length <= 16);
+
+ drw_shgroup_uniform_create_ex(shgroup, location, type, value, length, arraysize);
+}
+
+void DRW_shgroup_uniform_texture(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
+{
+ BLI_assert(tex != NULL);
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_TEXTURE, tex, 0, 1);
+}
+
+/* Same as DRW_shgroup_uniform_texture but is garanteed to be bound if shader does not change between shgrp. */
+void DRW_shgroup_uniform_texture_persistent(DRWShadingGroup *shgroup, const char *name, const GPUTexture *tex)
+{
+ BLI_assert(tex != NULL);
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_TEXTURE_PERSIST, tex, 0, 1);
+}
+
+void DRW_shgroup_uniform_block(DRWShadingGroup *shgroup, const char *name, const GPUUniformBuffer *ubo)
+{
+ BLI_assert(ubo != NULL);
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_BLOCK, ubo, 0, 1);
+}
+
+/* Same as DRW_shgroup_uniform_block but is garanteed to be bound if shader does not change between shgrp. */
+void DRW_shgroup_uniform_block_persistent(DRWShadingGroup *shgroup, const char *name, const GPUUniformBuffer *ubo)
+{
+ BLI_assert(ubo != NULL);
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_BLOCK_PERSIST, ubo, 0, 1);
+}
+
+void DRW_shgroup_uniform_texture_ref(DRWShadingGroup *shgroup, const char *name, GPUTexture **tex)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_TEXTURE_REF, tex, 0, 1);
+}
+
+void DRW_shgroup_uniform_bool(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_BOOL, value, 1, arraysize);
+}
+
+void DRW_shgroup_uniform_float(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 1, arraysize);
+}
+
+void DRW_shgroup_uniform_vec2(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 2, arraysize);
+}
+
+void DRW_shgroup_uniform_vec3(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 3, arraysize);
+}
+
+void DRW_shgroup_uniform_vec4(DRWShadingGroup *shgroup, const char *name, const float *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT, value, 4, arraysize);
+}
+
+void DRW_shgroup_uniform_short_to_int(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_SHORT_TO_INT, value, 1, arraysize);
+}
+
+void DRW_shgroup_uniform_short_to_float(DRWShadingGroup *shgroup, const char *name, const short *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_SHORT_TO_FLOAT, value, 1, arraysize);
+}
+
+void DRW_shgroup_uniform_int(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT, value, 1, arraysize);
+}
+
+void DRW_shgroup_uniform_ivec2(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT, value, 2, arraysize);
+}
+
+void DRW_shgroup_uniform_ivec3(DRWShadingGroup *shgroup, const char *name, const int *value, int arraysize)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT, value, 3, arraysize);
+}
+
+void DRW_shgroup_uniform_mat3(DRWShadingGroup *shgroup, const char *name, const float (*value)[3])
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT, (float *)value, 9, 1);
+}
+
+void DRW_shgroup_uniform_mat4(DRWShadingGroup *shgroup, const char *name, const float (*value)[4])
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_FLOAT, (float *)value, 16, 1);
+}
+
+/* Stores the int instead of a pointer. */
+void DRW_shgroup_uniform_int_copy(DRWShadingGroup *shgroup, const char *name, const int value)
+{
+ drw_shgroup_uniform(shgroup, name, DRW_UNIFORM_INT_COPY, SET_INT_IN_POINTER(value), 1, 1);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Draw Call (DRW_calls)
+ * \{ */
+
+static void drw_call_calc_orco(Object *ob, float (*r_orcofacs)[3])
+{
+ ID *ob_data = (ob) ? ob->data : NULL;
+ float *texcoloc = NULL;
+ float *texcosize = NULL;
+ if (ob_data != NULL) {
+ switch (GS(ob_data->name)) {
+ case ID_ME:
+ BKE_mesh_texspace_get_reference((Mesh *)ob_data, NULL, &texcoloc, NULL, &texcosize);
+ break;
+ case ID_CU:
+ {
+ Curve *cu = (Curve *)ob_data;
+ if (cu->bb == NULL || (cu->bb->flag & BOUNDBOX_DIRTY)) {
+ BKE_curve_texspace_calc(cu);
+ }
+ texcoloc = cu->loc;
+ texcosize = cu->size;
+ break;
+ }
+ case ID_MB:
+ {
+ MetaBall *mb = (MetaBall *)ob_data;
+ texcoloc = mb->loc;
+ texcosize = mb->size;
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ if ((texcoloc != NULL) && (texcosize != NULL)) {
+ mul_v3_v3fl(r_orcofacs[1], texcosize, 2.0f);
+ invert_v3(r_orcofacs[1]);
+ sub_v3_v3v3(r_orcofacs[0], texcoloc, texcosize);
+ negate_v3(r_orcofacs[0]);
+ mul_v3_v3(r_orcofacs[0], r_orcofacs[1]); /* result in a nice MADD in the shader */
+ }
+ else {
+ copy_v3_fl(r_orcofacs[0], 0.0f);
+ copy_v3_fl(r_orcofacs[1], 1.0f);
+ }
+}
+
+static DRWCallState *drw_call_state_create(DRWShadingGroup *shgroup, float (*obmat)[4], Object *ob)
+{
+ DRWCallState *state = BLI_mempool_alloc(DST.vmempool->states);
+ state->flag = 0;
+ state->cache_id = 0;
+ state->visibility_cb = NULL;
+ state->matflag = shgroup->matflag;
+
+ /* Matrices */
+ if (obmat != NULL) {
+ copy_m4_m4(state->model, obmat);
+
+ if (is_negative_m4(state->model)) {
+ state->flag |= DRW_CALL_NEGSCALE;
+ }
+ }
+ else {
+ unit_m4(state->model);
+ }
+
+ if (ob != NULL) {
+ float corner[3];
+ BoundBox *bbox = BKE_object_boundbox_get(ob);
+ /* Get BoundSphere center and radius from the BoundBox. */
+ mid_v3_v3v3(state->bsphere.center, bbox->vec[0], bbox->vec[6]);
+ mul_v3_m4v3(corner, obmat, bbox->vec[0]);
+ mul_m4_v3(obmat, state->bsphere.center);
+ state->bsphere.radius = len_v3v3(state->bsphere.center, corner);
+ }
+ else {
+ /* Bypass test. */
+ state->bsphere.radius = -1.0f;
+ }
+
+ /* Orco factors: We compute this at creation to not have to save the *ob_data */
+ if ((state->matflag & DRW_CALL_ORCOTEXFAC) != 0) {
+ drw_call_calc_orco(ob, state->orcotexfac);
+ state->matflag &= ~DRW_CALL_ORCOTEXFAC;
+ }
+
+ return state;
+}
+
+static DRWCallState *drw_call_state_object(DRWShadingGroup *shgroup, float (*obmat)[4], Object *ob)
+{
+ if (DST.ob_state == NULL) {
+ DST.ob_state = drw_call_state_create(shgroup, obmat, ob);
+ }
+ else {
+ /* If the DRWCallState is reused, add necessary matrices. */
+ DST.ob_state->matflag |= shgroup->matflag;
+ }
+
+ return DST.ob_state;
+}
+
+void DRW_shgroup_call_add(DRWShadingGroup *shgroup, Gwn_Batch *geom, float (*obmat)[4])
+{
+ BLI_assert(geom != NULL);
+ BLI_assert(shgroup->type == DRW_SHG_NORMAL);
+
+ DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+ call->state = drw_call_state_create(shgroup, obmat, NULL);
+ call->type = DRW_CALL_SINGLE;
+ call->single.geometry = geom;
+#ifdef USE_GPU_SELECT
+ call->select_id = DST.select_id;
+#endif
+
+ BLI_LINKS_APPEND(&shgroup->calls, call);
+}
+
+/* These calls can be culled and are optimized for redraw */
+void DRW_shgroup_call_object_add(DRWShadingGroup *shgroup, Gwn_Batch *geom, Object *ob)
+{
+ BLI_assert(geom != NULL);
+ BLI_assert(shgroup->type == DRW_SHG_NORMAL);
+
+ DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+ call->state = drw_call_state_object(shgroup, ob->obmat, ob);
+ call->type = DRW_CALL_SINGLE;
+ call->single.geometry = geom;
+#ifdef USE_GPU_SELECT
+ call->select_id = DST.select_id;
+#endif
+
+ BLI_LINKS_APPEND(&shgroup->calls, call);
+}
+
+void DRW_shgroup_call_object_add_with_callback(
+ DRWShadingGroup *shgroup, Gwn_Batch *geom, Object *ob,
+ DRWCallVisibilityFn *callback, void *user_data)
+{
+ BLI_assert(geom != NULL);
+ BLI_assert(shgroup->type == DRW_SHG_NORMAL);
+
+ DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+ call->state = drw_call_state_object(shgroup, ob->obmat, ob);
+ call->state->visibility_cb = callback;
+ call->state->user_data = user_data;
+ call->type = DRW_CALL_SINGLE;
+ call->single.geometry = geom;
+#ifdef USE_GPU_SELECT
+ call->select_id = DST.select_id;
+#endif
+
+ BLI_LINKS_APPEND(&shgroup->calls, call);
+}
+
+void DRW_shgroup_call_instances_add(DRWShadingGroup *shgroup, Gwn_Batch *geom, float (*obmat)[4], unsigned int *count)
+{
+ BLI_assert(geom != NULL);
+ BLI_assert(shgroup->type == DRW_SHG_NORMAL);
+
+ DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+ call->state = drw_call_state_create(shgroup, obmat, NULL);
+ call->type = DRW_CALL_INSTANCES;
+ call->instances.geometry = geom;
+ call->instances.count = count;
+#ifdef USE_GPU_SELECT
+ call->select_id = DST.select_id;
+#endif
+
+ BLI_LINKS_APPEND(&shgroup->calls, call);
+}
+
+/* These calls can be culled and are optimized for redraw */
+void DRW_shgroup_call_object_instances_add(DRWShadingGroup *shgroup, Gwn_Batch *geom, Object *ob, unsigned int *count)
+{
+ BLI_assert(geom != NULL);
+ BLI_assert(shgroup->type == DRW_SHG_NORMAL);
+
+ DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+ call->state = drw_call_state_object(shgroup, ob->obmat, ob);
+ call->type = DRW_CALL_INSTANCES;
+ call->instances.geometry = geom;
+ call->instances.count = count;
+#ifdef USE_GPU_SELECT
+ call->select_id = DST.select_id;
+#endif
+
+ BLI_LINKS_APPEND(&shgroup->calls, call);
+}
+
+void DRW_shgroup_call_generate_add(
+ DRWShadingGroup *shgroup,
+ DRWCallGenerateFn *geometry_fn, void *user_data,
+ float (*obmat)[4])
+{
+ BLI_assert(geometry_fn != NULL);
+ BLI_assert(shgroup->type == DRW_SHG_NORMAL);
+
+ DRWCall *call = BLI_mempool_alloc(DST.vmempool->calls);
+ call->state = drw_call_state_create(shgroup, obmat, NULL);
+ call->type = DRW_CALL_GENERATE;
+ call->generate.geometry_fn = geometry_fn;
+ call->generate.user_data = user_data;
+#ifdef USE_GPU_SELECT
+ call->select_id = DST.select_id;
+#endif
+
+ BLI_LINKS_APPEND(&shgroup->calls, call);
+}
+
+static void sculpt_draw_cb(
+ DRWShadingGroup *shgroup,
+ void (*draw_fn)(DRWShadingGroup *shgroup, Gwn_Batch *geom),
+ void *user_data)
+{
+ Object *ob = user_data;
+ PBVH *pbvh = ob->sculpt->pbvh;
+
+ if (pbvh) {
+ BKE_pbvh_draw_cb(
+ pbvh, NULL, NULL, false,
+ (void (*)(void *, Gwn_Batch *))draw_fn, shgroup);
+ }
+}
+
+void DRW_shgroup_call_sculpt_add(DRWShadingGroup *shgroup, Object *ob, float (*obmat)[4])
+{
+ DRW_shgroup_call_generate_add(shgroup, sculpt_draw_cb, ob, obmat);
+}
+
+void DRW_shgroup_call_dynamic_add_array(DRWShadingGroup *shgroup, const void *attr[], unsigned int attr_len)
+{
+#ifdef USE_GPU_SELECT
+ if (G.f & G_PICKSEL) {
+ if (shgroup->inst_selectid == NULL) {
+ shgroup->inst_selectid = DRW_instance_data_request(DST.idatalist, 1, 128);
+ }
+
+ int *select_id = DRW_instance_data_next(shgroup->inst_selectid);
+ *select_id = DST.select_id;
+ }
+#endif
+
+ BLI_assert(attr_len == shgroup->attribs_count);
+ UNUSED_VARS_NDEBUG(attr_len);
+
+ for (int i = 0; i < attr_len; ++i) {
+ if (shgroup->instance_count == shgroup->instance_vbo->vertex_ct) {
+ GWN_vertbuf_data_resize(shgroup->instance_vbo, shgroup->instance_count + 32);
+ }
+ GWN_vertbuf_attr_set(shgroup->instance_vbo, i, shgroup->instance_count, attr[i]);
+ }
+
+ shgroup->instance_count += 1;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Shading Groups (DRW_shgroup)
+ * \{ */
+
+static void drw_shgroup_init(DRWShadingGroup *shgroup, GPUShader *shader)
+{
+ shgroup->instance_geom = NULL;
+ shgroup->instance_vbo = NULL;
+ shgroup->instance_count = 0;
+ shgroup->uniforms = NULL;
+#ifdef USE_GPU_SELECT
+ shgroup->inst_selectid = NULL;
+ shgroup->override_selectid = -1;
+#endif
+#ifndef NDEBUG
+ shgroup->attribs_count = 0;
+#endif
+
+ int view_ubo_location = GPU_shader_get_uniform_block(shader, "viewBlock");
+
+ if (view_ubo_location != -1) {
+ drw_shgroup_uniform_create_ex(shgroup, view_ubo_location, DRW_UNIFORM_BLOCK_PERSIST, view_ubo, 0, 1);
+ }
+ else {
+ /* Only here to support builtin shaders. This should not be used by engines. */
+ drw_shgroup_builtin_uniform(shgroup, GWN_UNIFORM_VIEW, DST.view_data.matstate.mat[DRW_MAT_VIEW], 16, 1);
+ drw_shgroup_builtin_uniform(shgroup, GWN_UNIFORM_VIEW_INV, DST.view_data.matstate.mat[DRW_MAT_VIEWINV], 16, 1);
+ drw_shgroup_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION, DST.view_data.matstate.mat[DRW_MAT_PERS], 16, 1);
+ drw_shgroup_builtin_uniform(shgroup, GWN_UNIFORM_VIEWPROJECTION_INV, DST.view_data.matstate.mat[DRW_MAT_PERSINV], 16, 1);
+ drw_shgroup_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION, DST.view_data.matstate.mat[DRW_MAT_WIN], 16, 1);
+ drw_shgroup_builtin_uniform(shgroup, GWN_UNIFORM_PROJECTION_INV, DST.view_data.matstate.mat[DRW_MAT_WININV], 16, 1);
+ drw_shgroup_builtin_uniform(shgroup, GWN_UNIFORM_CAMERATEXCO, DST.view_data.viewcamtexcofac, 3, 2);
+ }
+
+ shgroup->model = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_MODEL);
+ shgroup->modelinverse = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_MODEL_INV);
+ shgroup->modelview = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_MODELVIEW);
+ shgroup->modelviewinverse = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_MODELVIEW_INV);
+ shgroup->modelviewprojection = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_MVP);
+ shgroup->normalview = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_NORMAL);
+ shgroup->normalworld = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_WORLDNORMAL);
+ shgroup->orcotexfac = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_ORCO);
+ shgroup->eye = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_EYE);
+ shgroup->callid = GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_CALLID);
+
+ shgroup->matflag = 0;
+ if (shgroup->modelinverse > -1)
+ shgroup->matflag |= DRW_CALL_MODELINVERSE;
+ if (shgroup->modelview > -1)
+ shgroup->matflag |= DRW_CALL_MODELVIEW;
+ if (shgroup->modelviewinverse > -1)
+ shgroup->matflag |= DRW_CALL_MODELVIEWINVERSE;
+ if (shgroup->modelviewprojection > -1)
+ shgroup->matflag |= DRW_CALL_MODELVIEWPROJECTION;
+ if (shgroup->normalview > -1)
+ shgroup->matflag |= DRW_CALL_NORMALVIEW;
+ if (shgroup->normalworld > -1)
+ shgroup->matflag |= DRW_CALL_NORMALWORLD;
+ if (shgroup->orcotexfac > -1)
+ shgroup->matflag |= DRW_CALL_ORCOTEXFAC;
+ if (shgroup->eye > -1)
+ shgroup->matflag |= DRW_CALL_EYEVEC;
+}
+
+static void drw_shgroup_instance_init(
+ DRWShadingGroup *shgroup, GPUShader *shader, Gwn_Batch *batch, Gwn_VertFormat *format)
+{
+ BLI_assert(shgroup->type == DRW_SHG_INSTANCE);
+ BLI_assert(batch != NULL);
+ BLI_assert(format != NULL);
+
+ drw_shgroup_init(shgroup, shader);
+
+ shgroup->instance_geom = batch;
+#ifndef NDEBUG
+ shgroup->attribs_count = format->attrib_ct;
+#endif
+
+ DRW_instancing_buffer_request(DST.idatalist, format, batch, shgroup,
+ &shgroup->instance_geom, &shgroup->instance_vbo);
+}
+
+static void drw_shgroup_batching_init(
+ DRWShadingGroup *shgroup, GPUShader *shader, Gwn_VertFormat *format)
+{
+ drw_shgroup_init(shgroup, shader);
+
+#ifndef NDEBUG
+ shgroup->attribs_count = (format != NULL) ? format->attrib_ct : 0;
+#endif
+ BLI_assert(format != NULL);
+
+ Gwn_PrimType type;
+ switch (shgroup->type) {
+ case DRW_SHG_POINT_BATCH: type = GWN_PRIM_POINTS; break;
+ case DRW_SHG_LINE_BATCH: type = GWN_PRIM_LINES; break;
+ case DRW_SHG_TRIANGLE_BATCH: type = GWN_PRIM_TRIS; break;
+ default: type = GWN_PRIM_NONE; BLI_assert(0); break;
+ }
+
+ DRW_batching_buffer_request(DST.idatalist, format, type, shgroup,
+ &shgroup->batch_geom, &shgroup->batch_vbo);
+}
+
+static DRWShadingGroup *drw_shgroup_create_ex(struct GPUShader *shader, DRWPass *pass)
+{
+ DRWShadingGroup *shgroup = BLI_mempool_alloc(DST.vmempool->shgroups);
+
+ BLI_LINKS_APPEND(&pass->shgroups, shgroup);
+
+ shgroup->type = DRW_SHG_NORMAL;
+ shgroup->shader = shader;
+ shgroup->state_extra = 0;
+ shgroup->state_extra_disable = ~0x0;
+ shgroup->stencil_mask = 0;
+ shgroup->calls.first = NULL;
+ shgroup->calls.last = NULL;
+#if 0 /* All the same in the union! */
+ shgroup->batch_geom = NULL;
+ shgroup->batch_vbo = NULL;
+
+ shgroup->instance_geom = NULL;
+ shgroup->instance_vbo = NULL;
+#endif
+
+#ifdef USE_GPU_SELECT
+ shgroup->pass_parent = pass;
+#endif
+
+ return shgroup;
+}
+
+static DRWShadingGroup *drw_shgroup_material_create_ex(GPUPass *gpupass, DRWPass *pass)
+{
+ if (!gpupass) {
+ /* Shader compilation error */
+ return NULL;
+ }
+
+ DRWShadingGroup *grp = drw_shgroup_create_ex(GPU_pass_shader(gpupass), pass);
+ return grp;
+}
+
+static DRWShadingGroup *drw_shgroup_material_inputs(DRWShadingGroup *grp, struct GPUMaterial *material)
+{
+ /* TODO : Ideally we should not convert. But since the whole codegen
+ * is relying on GPUPass we keep it as is for now. */
+
+ ListBase *inputs = GPU_material_get_inputs(material);
+
+ /* Converting dynamic GPUInput to DRWUniform */
+ for (GPUInput *input = inputs->first; input; input = input->next) {
+ /* Textures */
+ if (input->ima) {
+ double time = 0.0; /* TODO make time variable */
+ GPUTexture *tex = GPU_texture_from_blender(
+ input->ima, input->iuser, input->textarget, input->image_isdata, time, 1);
+
+ if (input->bindtex) {
+ DRW_shgroup_uniform_texture(grp, input->shadername, tex);
+ }
+ }
+ /* Color Ramps */
+ else if (input->tex) {
+ DRW_shgroup_uniform_texture(grp, input->shadername, input->tex);
+ }
+ /* Floats */
+ else {
+ switch (input->type) {
+ case GPU_FLOAT:
+ case GPU_VEC2:
+ case GPU_VEC3:
+ case GPU_VEC4:
+ /* Should already be in the material ubo. */
+ break;
+ case GPU_MAT3:
+ DRW_shgroup_uniform_mat3(grp, input->shadername, (float (*)[3])input->dynamicvec);
+ break;
+ case GPU_MAT4:
+ DRW_shgroup_uniform_mat4(grp, input->shadername, (float (*)[4])input->dynamicvec);
+ break;
+ default:
+ break;
+ }
+ }
+ }
+
+ GPUUniformBuffer *ubo = GPU_material_get_uniform_buffer(material);
+ if (ubo != NULL) {
+ DRW_shgroup_uniform_block(grp, GPU_UBO_BLOCK_NAME, ubo);
+ }
+
+ return grp;
+}
+
+Gwn_VertFormat *DRW_shgroup_instance_format_array(const DRWInstanceAttribFormat attribs[], int arraysize)
+{
+ Gwn_VertFormat *format = MEM_callocN(sizeof(Gwn_VertFormat), "Gwn_VertFormat");
+
+ for (int i = 0; i < arraysize; ++i) {
+ GWN_vertformat_attr_add(format, attribs[i].name,
+ (attribs[i].type == DRW_ATTRIB_INT) ? GWN_COMP_I32 : GWN_COMP_F32,
+ attribs[i].components,
+ (attribs[i].type == DRW_ATTRIB_INT) ? GWN_FETCH_INT : GWN_FETCH_FLOAT);
+ }
+ return format;
+}
+
+DRWShadingGroup *DRW_shgroup_material_create(
+ struct GPUMaterial *material, DRWPass *pass)
+{
+ GPUPass *gpupass = GPU_material_get_pass(material);
+ DRWShadingGroup *shgroup = drw_shgroup_material_create_ex(gpupass, pass);
+
+ if (shgroup) {
+ drw_shgroup_init(shgroup, GPU_pass_shader(gpupass));
+ drw_shgroup_material_inputs(shgroup, material);
+ }
+
+ return shgroup;
+}
+
+DRWShadingGroup *DRW_shgroup_material_instance_create(
+ struct GPUMaterial *material, DRWPass *pass, Gwn_Batch *geom, Object *ob, Gwn_VertFormat *format)
+{
+ GPUPass *gpupass = GPU_material_get_pass(material);
+ DRWShadingGroup *shgroup = drw_shgroup_material_create_ex(gpupass, pass);
+
+ if (shgroup) {
+ shgroup->type = DRW_SHG_INSTANCE;
+ shgroup->instance_geom = geom;
+ drw_call_calc_orco(ob, shgroup->instance_orcofac);
+ drw_shgroup_instance_init(shgroup, GPU_pass_shader(gpupass), geom, format);
+ drw_shgroup_material_inputs(shgroup, material);
+ }
+
+ return shgroup;
+}
+
+DRWShadingGroup *DRW_shgroup_material_empty_tri_batch_create(
+ struct GPUMaterial *material, DRWPass *pass, int tri_count)
+{
+#ifdef USE_GPU_SELECT
+ BLI_assert((G.f & G_PICKSEL) == 0);
+#endif
+ GPUPass *gpupass = GPU_material_get_pass(material);
+ DRWShadingGroup *shgroup = drw_shgroup_material_create_ex(gpupass, pass);
+
+ if (shgroup) {
+ /* Calling drw_shgroup_init will cause it to call GWN_draw_primitive(). */
+ drw_shgroup_init(shgroup, GPU_pass_shader(gpupass));
+ shgroup->type = DRW_SHG_TRIANGLE_BATCH;
+ shgroup->instance_count = tri_count * 3;
+ drw_shgroup_material_inputs(shgroup, material);
+ }
+
+ return shgroup;
+}
+
+DRWShadingGroup *DRW_shgroup_create(struct GPUShader *shader, DRWPass *pass)
+{
+ DRWShadingGroup *shgroup = drw_shgroup_create_ex(shader, pass);
+ drw_shgroup_init(shgroup, shader);
+ return shgroup;
+}
+
+DRWShadingGroup *DRW_shgroup_instance_create(
+ struct GPUShader *shader, DRWPass *pass, Gwn_Batch *geom, Gwn_VertFormat *format)
+{
+ DRWShadingGroup *shgroup = drw_shgroup_create_ex(shader, pass);
+ shgroup->type = DRW_SHG_INSTANCE;
+ shgroup->instance_geom = geom;
+ drw_call_calc_orco(NULL, shgroup->instance_orcofac);
+ drw_shgroup_instance_init(shgroup, shader, geom, format);
+
+ return shgroup;
+}
+
+DRWShadingGroup *DRW_shgroup_point_batch_create(struct GPUShader *shader, DRWPass *pass)
+{
+ DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTRIB_FLOAT, 3}});
+
+ DRWShadingGroup *shgroup = drw_shgroup_create_ex(shader, pass);
+ shgroup->type = DRW_SHG_POINT_BATCH;
+
+ drw_shgroup_batching_init(shgroup, shader, g_pos_format);
+
+ return shgroup;
+}
+
+DRWShadingGroup *DRW_shgroup_line_batch_create(struct GPUShader *shader, DRWPass *pass)
+{
+ DRW_shgroup_instance_format(g_pos_format, {{"pos", DRW_ATTRIB_FLOAT, 3}});
+
+ DRWShadingGroup *shgroup = drw_shgroup_create_ex(shader, pass);
+ shgroup->type = DRW_SHG_LINE_BATCH;
+
+ drw_shgroup_batching_init(shgroup, shader, g_pos_format);
+
+ return shgroup;
+}
+
+/* Very special batch. Use this if you position
+ * your vertices with the vertex shader
+ * and dont need any VBO attrib */
+DRWShadingGroup *DRW_shgroup_empty_tri_batch_create(struct GPUShader *shader, DRWPass *pass, int tri_count)
+{
+#ifdef USE_GPU_SELECT
+ BLI_assert((G.f & G_PICKSEL) == 0);
+#endif
+ DRWShadingGroup *shgroup = drw_shgroup_create_ex(shader, pass);
+
+ /* Calling drw_shgroup_init will cause it to call GWN_draw_primitive(). */
+ drw_shgroup_init(shgroup, shader);
+
+ shgroup->type = DRW_SHG_TRIANGLE_BATCH;
+ shgroup->instance_count = tri_count * 3;
+
+ return shgroup;
+}
+
+/* Specify an external batch instead of adding each attrib one by one. */
+void DRW_shgroup_instance_batch(DRWShadingGroup *shgroup, struct Gwn_Batch *batch)
+{
+ BLI_assert(shgroup->type == DRW_SHG_INSTANCE);
+ BLI_assert(shgroup->instance_count == 0);
+ /* You cannot use external instancing batch without a dummy format. */
+ BLI_assert(shgroup->attribs_count != 0);
+
+ shgroup->type = DRW_SHG_INSTANCE_EXTERNAL;
+ drw_call_calc_orco(NULL, shgroup->instance_orcofac);
+ /* PERF : This destroys the vaos cache so better check if it's necessary. */
+ /* Note: This WILL break if batch->verts[0] is destroyed and reallocated
+ * at the same adress. Bindings/VAOs would remain obsolete. */
+ //if (shgroup->instancing_geom->inst != batch->verts[0])
+ GWN_batch_instbuf_set(shgroup->instance_geom, batch->verts[0], false);
+
+#ifdef USE_GPU_SELECT
+ shgroup->override_selectid = DST.select_id;
+#endif
+}
+
+unsigned int DRW_shgroup_get_instance_count(const DRWShadingGroup *shgroup)
+{
+ return shgroup->instance_count;
+}
+
+/**
+ * State is added to #Pass.state while drawing.
+ * Use to temporarily enable draw options.
+ */
+void DRW_shgroup_state_enable(DRWShadingGroup *shgroup, DRWState state)
+{
+ shgroup->state_extra |= state;
+}
+
+void DRW_shgroup_state_disable(DRWShadingGroup *shgroup, DRWState state)
+{
+ shgroup->state_extra_disable &= ~state;
+}
+
+void DRW_shgroup_stencil_mask(DRWShadingGroup *shgroup, unsigned int mask)
+{
+ BLI_assert(mask <= 255);
+ shgroup->stencil_mask = mask;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Passes (DRW_pass)
+ * \{ */
+
+DRWPass *DRW_pass_create(const char *name, DRWState state)
+{
+ DRWPass *pass = BLI_mempool_alloc(DST.vmempool->passes);
+ pass->state = state;
+ if (G.debug_value > 20) {
+ BLI_strncpy(pass->name, name, MAX_PASS_NAME);
+ }
+
+ pass->shgroups.first = NULL;
+ pass->shgroups.last = NULL;
+
+ return pass;
+}
+
+void DRW_pass_state_set(DRWPass *pass, DRWState state)
+{
+ pass->state = state;
+}
+
+void DRW_pass_state_add(DRWPass *pass, DRWState state)
+{
+ pass->state |= state;
+}
+
+void DRW_pass_state_remove(DRWPass *pass, DRWState state)
+{
+ pass->state &= ~state;
+}
+
+void DRW_pass_free(DRWPass *pass)
+{
+ pass->shgroups.first = NULL;
+ pass->shgroups.last = NULL;
+}
+
+void DRW_pass_foreach_shgroup(DRWPass *pass, void (*callback)(void *userData, DRWShadingGroup *shgrp), void *userData)
+{
+ for (DRWShadingGroup *shgroup = pass->shgroups.first; shgroup; shgroup = shgroup->next) {
+ callback(userData, shgroup);
+ }
+}
+
+typedef struct ZSortData {
+ float *axis;
+ float *origin;
+} ZSortData;
+
+static int pass_shgroup_dist_sort(void *thunk, const void *a, const void *b)
+{
+ const ZSortData *zsortdata = (ZSortData *)thunk;
+ const DRWShadingGroup *shgrp_a = (const DRWShadingGroup *)a;
+ const DRWShadingGroup *shgrp_b = (const DRWShadingGroup *)b;
+
+ const DRWCall *call_a = (DRWCall *)shgrp_a->calls.first;
+ const DRWCall *call_b = (DRWCall *)shgrp_b->calls.first;
+
+ if (call_a == NULL) return -1;
+ if (call_b == NULL) return -1;
+
+ float tmp[3];
+ sub_v3_v3v3(tmp, zsortdata->origin, call_a->state->model[3]);
+ const float a_sq = dot_v3v3(zsortdata->axis, tmp);
+ sub_v3_v3v3(tmp, zsortdata->origin, call_b->state->model[3]);
+ const float b_sq = dot_v3v3(zsortdata->axis, tmp);
+
+ if (a_sq < b_sq) return 1;
+ else if (a_sq > b_sq) return -1;
+ else {
+ /* If there is a depth prepass put it before */
+ if ((shgrp_a->state_extra & DRW_STATE_WRITE_DEPTH) != 0) {
+ return -1;
+ }
+ else if ((shgrp_b->state_extra & DRW_STATE_WRITE_DEPTH) != 0) {
+ return 1;
+ }
+ else return 0;
+ }
+}
+
+/* ------------------ Shading group sorting --------------------- */
+
+#define SORT_IMPL_LINKTYPE DRWShadingGroup
+
+#define SORT_IMPL_USE_THUNK
+#define SORT_IMPL_FUNC shgroup_sort_fn_r
+#include "../../blenlib/intern/list_sort_impl.h"
+#undef SORT_IMPL_FUNC
+#undef SORT_IMPL_USE_THUNK
+
+#undef SORT_IMPL_LINKTYPE
+
+/**
+ * Sort Shading groups by decreasing Z of their first draw call.
+ * This is usefull for order dependant effect such as transparency.
+ **/
+void DRW_pass_sort_shgroup_z(DRWPass *pass)
+{
+ float (*viewinv)[4];
+ viewinv = DST.view_data.matstate.mat[DRW_MAT_VIEWINV];
+
+ ZSortData zsortdata = {viewinv[2], viewinv[3]};
+
+ if (pass->shgroups.first && pass->shgroups.first->next) {
+ pass->shgroups.first = shgroup_sort_fn_r(pass->shgroups.first, pass_shgroup_dist_sort, &zsortdata);
+
+ /* Find the next last */
+ DRWShadingGroup *last = pass->shgroups.first;
+ while ((last = last->next)) {
+ /* Do nothing */
+ }
+ pass->shgroups.last = last;
+ }
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/draw_manager_exec.c b/source/blender/draw/intern/draw_manager_exec.c
new file mode 100644
index 00000000000..b95fdab79e7
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_exec.c
@@ -0,0 +1,1193 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_manager_exec.c
+ * \ingroup draw
+ */
+
+#include "draw_manager.h"
+
+#include "BLI_mempool.h"
+
+#include "BIF_glutil.h"
+
+#include "BKE_global.h"
+#include "BKE_object.h"
+
+#include "GPU_draw.h"
+#include "GPU_extensions.h"
+
+#ifdef USE_GPU_SELECT
+# include "ED_view3d.h"
+# include "ED_armature.h"
+# include "GPU_select.h"
+#endif
+
+#ifdef USE_GPU_SELECT
+void DRW_select_load_id(unsigned int id)
+{
+ BLI_assert(G.f & G_PICKSEL);
+ DST.select_id = id;
+}
+#endif
+
+struct GPUUniformBuffer *view_ubo;
+
+/* -------------------------------------------------------------------- */
+
+/** \name Draw State (DRW_state)
+ * \{ */
+
+void drw_state_set(DRWState state)
+{
+ if (DST.state == state) {
+ return;
+ }
+
+#define CHANGED_TO(f) \
+ ((DST.state_lock & (f)) ? 0 : \
+ (((DST.state & (f)) ? \
+ ((state & (f)) ? 0 : -1) : \
+ ((state & (f)) ? 1 : 0))))
+
+#define CHANGED_ANY(f) \
+ (((DST.state & (f)) != (state & (f))) && \
+ ((DST.state_lock & (f)) == 0))
+
+#define CHANGED_ANY_STORE_VAR(f, enabled) \
+ (((DST.state & (f)) != (enabled = (state & (f)))) && \
+ (((DST.state_lock & (f)) == 0)))
+
+ /* Depth Write */
+ {
+ int test;
+ if ((test = CHANGED_TO(DRW_STATE_WRITE_DEPTH))) {
+ if (test == 1) {
+ glDepthMask(GL_TRUE);
+ }
+ else {
+ glDepthMask(GL_FALSE);
+ }
+ }
+ }
+
+ /* Color Write */
+ {
+ int test;
+ if ((test = CHANGED_TO(DRW_STATE_WRITE_COLOR))) {
+ if (test == 1) {
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ }
+ else {
+ glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
+ }
+ }
+ }
+
+ /* Cull */
+ {
+ DRWState test;
+ if (CHANGED_ANY_STORE_VAR(
+ DRW_STATE_CULL_BACK | DRW_STATE_CULL_FRONT,
+ test))
+ {
+ if (test) {
+ glEnable(GL_CULL_FACE);
+
+ if ((state & DRW_STATE_CULL_BACK) != 0) {
+ glCullFace(GL_BACK);
+ }
+ else if ((state & DRW_STATE_CULL_FRONT) != 0) {
+ glCullFace(GL_FRONT);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ glDisable(GL_CULL_FACE);
+ }
+ }
+ }
+
+ /* Depth Test */
+ {
+ DRWState test;
+ if (CHANGED_ANY_STORE_VAR(
+ DRW_STATE_DEPTH_LESS | DRW_STATE_DEPTH_EQUAL | DRW_STATE_DEPTH_GREATER | DRW_STATE_DEPTH_ALWAYS,
+ test))
+ {
+ if (test) {
+ glEnable(GL_DEPTH_TEST);
+
+ if (state & DRW_STATE_DEPTH_LESS) {
+ glDepthFunc(GL_LEQUAL);
+ }
+ else if (state & DRW_STATE_DEPTH_EQUAL) {
+ glDepthFunc(GL_EQUAL);
+ }
+ else if (state & DRW_STATE_DEPTH_GREATER) {
+ glDepthFunc(GL_GREATER);
+ }
+ else if (state & DRW_STATE_DEPTH_ALWAYS) {
+ glDepthFunc(GL_ALWAYS);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ glDisable(GL_DEPTH_TEST);
+ }
+ }
+ }
+
+ /* Wire Width */
+ {
+ if (CHANGED_ANY(DRW_STATE_WIRE | DRW_STATE_WIRE_SMOOTH)) {
+ if ((state & DRW_STATE_WIRE_SMOOTH) != 0) {
+ glLineWidth(2.0f);
+ glEnable(GL_LINE_SMOOTH);
+ }
+ else if ((state & DRW_STATE_WIRE) != 0) {
+ glLineWidth(1.0f);
+ }
+ else {
+ glDisable(GL_LINE_SMOOTH);
+ }
+ }
+ }
+
+ /* Points Size */
+ {
+ int test;
+ if ((test = CHANGED_TO(DRW_STATE_POINT))) {
+ if (test == 1) {
+ GPU_enable_program_point_size();
+ glPointSize(5.0f);
+ }
+ else {
+ GPU_disable_program_point_size();
+ }
+ }
+ }
+
+ /* Blending (all buffer) */
+ {
+ int test;
+ if (CHANGED_ANY_STORE_VAR(
+ DRW_STATE_BLEND | DRW_STATE_BLEND_PREMUL | DRW_STATE_ADDITIVE |
+ DRW_STATE_MULTIPLY | DRW_STATE_TRANSMISSION | DRW_STATE_ADDITIVE_FULL,
+ test))
+ {
+ if (test) {
+ glEnable(GL_BLEND);
+
+ if ((state & DRW_STATE_BLEND) != 0) {
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, /* RGB */
+ GL_ONE, GL_ONE_MINUS_SRC_ALPHA); /* Alpha */
+ }
+ else if ((state & DRW_STATE_BLEND_PREMUL) != 0) {
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ else if ((state & DRW_STATE_MULTIPLY) != 0) {
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
+ }
+ else if ((state & DRW_STATE_TRANSMISSION) != 0) {
+ glBlendFunc(GL_ONE, GL_SRC_ALPHA);
+ }
+ else if ((state & DRW_STATE_ADDITIVE) != 0) {
+ /* Do not let alpha accumulate but premult the source RGB by it. */
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, /* RGB */
+ GL_ZERO, GL_ONE); /* Alpha */
+ }
+ else if ((state & DRW_STATE_ADDITIVE_FULL) != 0) {
+ /* Let alpha accumulate. */
+ glBlendFunc(GL_ONE, GL_ONE);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ glDisable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ONE); /* Don't multiply incoming color by alpha. */
+ }
+ }
+ }
+
+ /* Clip Planes */
+ {
+ int test;
+ if ((test = CHANGED_TO(DRW_STATE_CLIP_PLANES))) {
+ if (test == 1) {
+ for (int i = 0; i < DST.num_clip_planes; ++i) {
+ glEnable(GL_CLIP_DISTANCE0 + i);
+ }
+ }
+ else {
+ for (int i = 0; i < MAX_CLIP_PLANES; ++i) {
+ glDisable(GL_CLIP_DISTANCE0 + i);
+ }
+ }
+ }
+ }
+
+ /* Line Stipple */
+ {
+ int test;
+ if (CHANGED_ANY_STORE_VAR(
+ DRW_STATE_STIPPLE_2 | DRW_STATE_STIPPLE_3 | DRW_STATE_STIPPLE_4,
+ test))
+ {
+ if (test) {
+ if ((state & DRW_STATE_STIPPLE_2) != 0) {
+ setlinestyle(2);
+ }
+ else if ((state & DRW_STATE_STIPPLE_3) != 0) {
+ setlinestyle(3);
+ }
+ else if ((state & DRW_STATE_STIPPLE_4) != 0) {
+ setlinestyle(4);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ setlinestyle(0);
+ }
+ }
+ }
+
+ /* Stencil */
+ {
+ DRWState test;
+ if (CHANGED_ANY_STORE_VAR(
+ DRW_STATE_WRITE_STENCIL |
+ DRW_STATE_WRITE_STENCIL_SHADOW |
+ DRW_STATE_STENCIL_EQUAL |
+ DRW_STATE_STENCIL_NEQUAL,
+ test))
+ {
+ if (test) {
+ glEnable(GL_STENCIL_TEST);
+ /* Stencil Write */
+ if ((state & DRW_STATE_WRITE_STENCIL) != 0) {
+ glStencilMask(0xFF);
+ glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
+ }
+ else if ((state & DRW_STATE_WRITE_STENCIL_SHADOW) != 0) {
+ glStencilMask(0xFF);
+ glStencilOpSeparate(GL_BACK, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
+ glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_DECR_WRAP, GL_KEEP);
+ }
+ /* Stencil Test */
+ else if ((state & (DRW_STATE_STENCIL_EQUAL | DRW_STATE_STENCIL_NEQUAL)) != 0) {
+ glStencilMask(0x00); /* disable write */
+ DST.stencil_mask = STENCIL_UNDEFINED;
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ /* disable write & test */
+ DST.stencil_mask = 0;
+ glStencilMask(0x00);
+ glStencilFunc(GL_ALWAYS, 1, 0xFF);
+ glDisable(GL_STENCIL_TEST);
+ }
+ }
+ }
+
+#undef CHANGED_TO
+#undef CHANGED_ANY
+#undef CHANGED_ANY_STORE_VAR
+
+ DST.state = state;
+}
+
+static void drw_stencil_set(unsigned int mask)
+{
+ if (DST.stencil_mask != mask) {
+ DST.stencil_mask = mask;
+ /* Stencil Write */
+ if ((DST.state & DRW_STATE_WRITE_STENCIL) != 0) {
+ glStencilFunc(GL_ALWAYS, mask, 0xFF);
+ }
+ /* Stencil Test */
+ else if ((DST.state & DRW_STATE_STENCIL_EQUAL) != 0) {
+ glStencilFunc(GL_EQUAL, mask, 0xFF);
+ }
+ else if ((DST.state & DRW_STATE_STENCIL_NEQUAL) != 0) {
+ glStencilFunc(GL_NOTEQUAL, mask, 0xFF);
+ }
+ }
+}
+
+/* Reset state to not interfer with other UI drawcall */
+void DRW_state_reset_ex(DRWState state)
+{
+ DST.state = ~state;
+ drw_state_set(state);
+}
+
+/**
+ * Use with care, intended so selection code can override passes depth settings,
+ * which is important for selection to work properly.
+ *
+ * Should be set in main draw loop, cleared afterwards
+ */
+void DRW_state_lock(DRWState state)
+{
+ DST.state_lock = state;
+}
+
+void DRW_state_reset(void)
+{
+ /* Reset blending function */
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ DRW_state_reset_ex(DRW_STATE_DEFAULT);
+}
+
+/* NOTE : Make sure to reset after use! */
+void DRW_state_invert_facing(void)
+{
+ SWAP(GLenum, DST.backface, DST.frontface);
+ glFrontFace(DST.frontface);
+}
+
+/**
+ * This only works if DRWPasses have been tagged with DRW_STATE_CLIP_PLANES,
+ * and if the shaders have support for it (see usage of gl_ClipDistance).
+ * Be sure to call DRW_state_clip_planes_reset() after you finish drawing.
+ **/
+void DRW_state_clip_planes_count_set(unsigned int plane_ct)
+{
+ BLI_assert(plane_ct <= MAX_CLIP_PLANES);
+ DST.num_clip_planes = plane_ct;
+}
+
+void DRW_state_clip_planes_reset(void)
+{
+ DST.num_clip_planes = 0;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Clipping (DRW_clipping)
+ * \{ */
+
+/* Extract the 8 corners from a Projection Matrix.
+ * Although less accurate, this solution can be simplified as follows:
+ * BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, -1.0f}, (const float[3]){1.0f, 1.0f, 1.0f});
+ * for (int i = 0; i < 8; i++) {mul_project_m4_v3(projinv, bbox.vec[i]);}
+ */
+static void draw_frustum_boundbox_calc(const float(*projmat)[4], BoundBox *r_bbox)
+{
+ float near, far, left, right, bottom, top;
+ bool is_persp = projmat[3][3] == 0.0f;
+
+ if (is_persp) {
+ near = projmat[3][2] / (projmat[2][2] - 1.0f);
+ far = projmat[3][2] / (projmat[2][2] + 1.0f);
+ left = near * (projmat[2][0] - 1.0f) / projmat[0][0];
+ right = near * (projmat[2][0] + 1.0f) / projmat[0][0];
+ bottom = near * (projmat[2][1] - 1.0f) / projmat[1][1];
+ top = near * (projmat[2][1] + 1.0f) / projmat[1][1];
+ }
+ else {
+ near = ( projmat[3][2] + 1.0f) / projmat[2][2];
+ far = ( projmat[3][2] - 1.0f) / projmat[2][2];
+ left = (-projmat[3][0] - 1.0f) / projmat[0][0];
+ right = (-projmat[3][0] + 1.0f) / projmat[0][0];
+ bottom = (-projmat[3][1] - 1.0f) / projmat[1][1];
+ top = (-projmat[3][1] + 1.0f) / projmat[1][1];
+ }
+
+ r_bbox->vec[0][2] = r_bbox->vec[3][2] = r_bbox->vec[7][2] = r_bbox->vec[4][2] = -near;
+ r_bbox->vec[0][0] = r_bbox->vec[3][0] = left;
+ r_bbox->vec[4][0] = r_bbox->vec[7][0] = right;
+ r_bbox->vec[0][1] = r_bbox->vec[4][1] = bottom;
+ r_bbox->vec[7][1] = r_bbox->vec[3][1] = top;
+
+ /* Get the coordinates of the far plane. */
+ if (is_persp) {
+ float sca_far = far / near;
+ left *= sca_far;
+ bottom *= sca_far;
+ right *= sca_far;
+ top *= sca_far;
+ }
+
+ r_bbox->vec[1][2] = r_bbox->vec[2][2] = r_bbox->vec[6][2] = r_bbox->vec[5][2] = -far;
+ r_bbox->vec[1][0] = r_bbox->vec[2][0] = left;
+ r_bbox->vec[6][0] = r_bbox->vec[5][0] = right;
+ r_bbox->vec[1][1] = r_bbox->vec[5][1] = bottom;
+ r_bbox->vec[2][1] = r_bbox->vec[6][1] = top;
+}
+
+static void draw_clipping_setup_from_view(void)
+{
+ if (DST.clipping.updated)
+ return;
+
+ float (*viewinv)[4] = DST.view_data.matstate.mat[DRW_MAT_VIEWINV];
+ float (*projmat)[4] = DST.view_data.matstate.mat[DRW_MAT_WIN];
+ float (*projinv)[4] = DST.view_data.matstate.mat[DRW_MAT_WININV];
+ BoundSphere *bsphere = &DST.clipping.frustum_bsphere;
+
+ /* Extract Clipping Planes */
+ BoundBox bbox;
+#if 0 /* It has accuracy problems. */
+ BKE_boundbox_init_from_minmax(&bbox, (const float[3]){-1.0f, -1.0f, -1.0f}, (const float[3]){1.0f, 1.0f, 1.0f});
+ for (int i = 0; i < 8; i++) {
+ mul_project_m4_v3(projinv, bbox.vec[i]);
+ }
+#else
+ draw_frustum_boundbox_calc(projmat, &bbox);
+#endif
+ /* Transform into world space. */
+ for (int i = 0; i < 8; i++) {
+ mul_m4_v3(viewinv, bbox.vec[i]);
+ }
+
+ memcpy(&DST.clipping.frustum_corners, &bbox, sizeof(BoundBox));
+
+ /* Compute clip planes using the world space frustum corners. */
+ for (int p = 0; p < 6; p++) {
+ int q, r;
+ switch (p) {
+ case 0: q = 1; r = 2; break;
+ case 1: q = 0; r = 5; break;
+ case 2: q = 1; r = 5; break;
+ case 3: q = 2; r = 6; break;
+ case 4: q = 0; r = 3; break;
+ default: q = 4; r = 7; break;
+ }
+ if (DST.frontface == GL_CW) {
+ SWAP(int, q, r);
+ }
+
+ normal_tri_v3(DST.clipping.frustum_planes[p], bbox.vec[p], bbox.vec[q], bbox.vec[r]);
+ DST.clipping.frustum_planes[p][3] = -dot_v3v3(DST.clipping.frustum_planes[p], bbox.vec[p]);
+ }
+
+ /* Extract Bounding Sphere */
+ if (projmat[3][3] != 0.0f) {
+ /* Orthographic */
+ /* The most extreme points on the near and far plane. (normalized device coords). */
+ float *nearpoint = bbox.vec[0];
+ float *farpoint = bbox.vec[6];
+
+ /* just use median point */
+ mid_v3_v3v3(bsphere->center, farpoint, nearpoint);
+ bsphere->radius = len_v3v3(bsphere->center, farpoint);
+ }
+ else if (projmat[2][0] == 0.0f && projmat[2][1] == 0.0f) {
+ /* Perspective with symmetrical frustum. */
+
+ /* We obtain the center and radius of the circumscribed circle of the
+ * isosceles trapezoid composed by the diagonals of the near and far clipping plane */
+
+ /* center of each clipping plane */
+ float mid_min[3], mid_max[3];
+ mid_v3_v3v3(mid_min, bbox.vec[3], bbox.vec[4]);
+ mid_v3_v3v3(mid_max, bbox.vec[2], bbox.vec[5]);
+
+ /* square length of the diagonals of each clipping plane */
+ float a_sq = len_squared_v3v3(bbox.vec[3], bbox.vec[4]);
+ float b_sq = len_squared_v3v3(bbox.vec[2], bbox.vec[5]);
+
+ /* distance squared between clipping planes */
+ float h_sq = len_squared_v3v3(mid_min, mid_max);
+
+ float fac = (4 * h_sq + b_sq - a_sq) / (8 * h_sq);
+
+ /* The goal is to get the smallest sphere,
+ * not the sphere that passes through each corner */
+ CLAMP(fac, 0.0f, 1.0f);
+
+ interp_v3_v3v3(bsphere->center, mid_min, mid_max, fac);
+
+ /* distance from the center to one of the points of the far plane (1, 2, 5, 6) */
+ bsphere->radius = len_v3v3(bsphere->center, bbox.vec[1]);
+ }
+ else {
+ /* Perspective with asymmetrical frustum. */
+
+ /* We put the sphere center on the line that goes from origin
+ * to the center of the far clipping plane. */
+
+ /* Detect which of the corner of the far clipping plane is the farthest to the origin */
+ float nfar[4]; /* most extreme far point in NDC space */
+ float farxy[2]; /* farpoint projection onto the near plane */
+ float farpoint[3] = {0.0f}; /* most extreme far point in camera coordinate */
+ float nearpoint[3]; /* most extreme near point in camera coordinate */
+ float farcenter[3] = {0.0f}; /* center of far cliping plane in camera coordinate */
+ float F = -1.0f, N; /* square distance of far and near point to origin */
+ float f, n; /* distance of far and near point to z axis. f is always > 0 but n can be < 0 */
+ float e, s; /* far and near clipping distance (<0) */
+ float c; /* slope of center line = distance of far clipping center to z axis / far clipping distance */
+ float z; /* projection of sphere center on z axis (<0) */
+
+ /* Find farthest corner and center of far clip plane. */
+ float corner[3] = {1.0f, 1.0f, 1.0f}; /* in clip space */
+ for (int i = 0; i < 4; i++) {
+ float point[3];
+ mul_v3_project_m4_v3(point, projinv, corner);
+ float len = len_squared_v3(point);
+ if (len > F) {
+ copy_v3_v3(nfar, corner);
+ copy_v3_v3(farpoint, point);
+ F = len;
+ }
+ add_v3_v3(farcenter, point);
+ /* rotate by 90 degree to walk through the 4 points of the far clip plane */
+ float tmp = corner[0];
+ corner[0] = -corner[1];
+ corner[1] = tmp;
+ }
+
+ /* the far center is the average of the far clipping points */
+ mul_v3_fl(farcenter, 0.25f);
+ /* the extreme near point is the opposite point on the near clipping plane */
+ copy_v3_fl3(nfar, -nfar[0], -nfar[1], -1.0f);
+ mul_v3_project_m4_v3(nearpoint, projinv, nfar);
+ /* this is a frustum projection */
+ N = len_squared_v3(nearpoint);
+ e = farpoint[2];
+ s = nearpoint[2];
+ /* distance to view Z axis */
+ f = len_v2(farpoint);
+ /* get corresponding point on the near plane */
+ mul_v2_v2fl(farxy, farpoint, s / e);
+ /* this formula preserve the sign of n */
+ sub_v2_v2(nearpoint, farxy);
+ n = f * s / e - len_v2(nearpoint);
+ c = len_v2(farcenter) / e;
+ /* the big formula, it simplifies to (F-N)/(2(e-s)) for the symmetric case */
+ z = (F - N) / (2.0f * (e - s + c * (f - n)));
+
+ bsphere->center[0] = farcenter[0] * z / e;
+ bsphere->center[1] = farcenter[1] * z / e;
+ bsphere->center[2] = z;
+ bsphere->radius = len_v3v3(bsphere->center, farpoint);
+
+ /* Transform to world space. */
+ mul_m4_v3(viewinv, bsphere->center);
+ }
+
+ DST.clipping.updated = true;
+}
+
+/* Return True if the given BoundSphere intersect the current view frustum */
+bool DRW_culling_sphere_test(BoundSphere *bsphere)
+{
+ draw_clipping_setup_from_view();
+
+ /* Bypass test if radius is negative. */
+ if (bsphere->radius < 0.0f)
+ return true;
+
+ /* Do a rough test first: Sphere VS Sphere intersect. */
+ BoundSphere *frustum_bsphere = &DST.clipping.frustum_bsphere;
+ float center_dist = len_squared_v3v3(bsphere->center, frustum_bsphere->center);
+ if (center_dist > SQUARE(bsphere->radius + frustum_bsphere->radius))
+ return false;
+
+ /* Test against the 6 frustum planes. */
+ for (int p = 0; p < 6; p++) {
+ float dist = plane_point_side_v3(DST.clipping.frustum_planes[p], bsphere->center);
+ if (dist < -bsphere->radius) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
+/* Return True if the given BoundBox intersect the current view frustum.
+ * bbox must be in world space. */
+bool DRW_culling_box_test(BoundBox *bbox)
+{
+ draw_clipping_setup_from_view();
+
+ /* 6 view frustum planes */
+ for (int p = 0; p < 6; p++) {
+ /* 8 box vertices. */
+ for (int v = 0; v < 8 ; v++) {
+ float dist = plane_point_side_v3(DST.clipping.frustum_planes[p], bbox->vec[v]);
+ if (dist > 0.0f) {
+ /* At least one point in front of this plane.
+ * Go to next plane. */
+ break;
+ }
+ else if (v == 7) {
+ /* 8 points behind this plane. */
+ return false;
+ }
+ }
+ }
+
+ return true;
+}
+
+/* Return True if the current view frustum is inside or intersect the given plane */
+bool DRW_culling_plane_test(float plane[4])
+{
+ draw_clipping_setup_from_view();
+
+ /* Test against the 8 frustum corners. */
+ for (int c = 0; c < 8; c++) {
+ float dist = plane_point_side_v3(plane, DST.clipping.frustum_corners.vec[c]);
+ if (dist < 0.0f) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Draw (DRW_draw)
+ * \{ */
+
+static void draw_visibility_eval(DRWCallState *st)
+{
+ bool culled = st->flag & DRW_CALL_CULLED;
+
+ if (st->cache_id != DST.state_cache_id) {
+ /* Update culling result for this view. */
+ culled = !DRW_culling_sphere_test(&st->bsphere);
+ }
+
+ if (st->visibility_cb) {
+ culled = !st->visibility_cb(!culled, st->user_data);
+ }
+
+ SET_FLAG_FROM_TEST(st->flag, culled, DRW_CALL_CULLED);
+}
+
+static void draw_matrices_model_prepare(DRWCallState *st)
+{
+ if (st->cache_id == DST.state_cache_id) {
+ /* Values are already updated for this view. */
+ return;
+ }
+ else {
+ st->cache_id = DST.state_cache_id;
+ }
+
+ /* No need to go further the call will not be used. */
+ if (st->flag & DRW_CALL_CULLED)
+ return;
+
+ /* Order matters */
+ if (st->matflag & (DRW_CALL_MODELVIEW | DRW_CALL_MODELVIEWINVERSE |
+ DRW_CALL_NORMALVIEW | DRW_CALL_EYEVEC))
+ {
+ mul_m4_m4m4(st->modelview, DST.view_data.matstate.mat[DRW_MAT_VIEW], st->model);
+ }
+ if (st->matflag & DRW_CALL_MODELVIEWINVERSE) {
+ invert_m4_m4(st->modelviewinverse, st->modelview);
+ }
+ if (st->matflag & DRW_CALL_MODELVIEWPROJECTION) {
+ mul_m4_m4m4(st->modelviewprojection, DST.view_data.matstate.mat[DRW_MAT_PERS], st->model);
+ }
+ if (st->matflag & (DRW_CALL_NORMALVIEW | DRW_CALL_EYEVEC)) {
+ copy_m3_m4(st->normalview, st->modelview);
+ invert_m3(st->normalview);
+ transpose_m3(st->normalview);
+ }
+ if (st->matflag & DRW_CALL_EYEVEC) {
+ /* Used by orthographic wires */
+ float tmp[3][3];
+ copy_v3_fl3(st->eyevec, 0.0f, 0.0f, 1.0f);
+ invert_m3_m3(tmp, st->normalview);
+ /* set eye vector, transformed to object coords */
+ mul_m3_v3(tmp, st->eyevec);
+ }
+ /* Non view dependant */
+ if (st->matflag & DRW_CALL_MODELINVERSE) {
+ invert_m4_m4(st->modelinverse, st->model);
+ st->matflag &= ~DRW_CALL_MODELINVERSE;
+ }
+ if (st->matflag & DRW_CALL_NORMALWORLD) {
+ copy_m3_m4(st->normalworld, st->model);
+ invert_m3(st->normalworld);
+ transpose_m3(st->normalworld);
+ st->matflag &= ~DRW_CALL_NORMALWORLD;
+ }
+}
+
+static void draw_geometry_prepare(DRWShadingGroup *shgroup, DRWCallState *state)
+{
+ /* step 1 : bind object dependent matrices */
+ if (state != NULL) {
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)state->model);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelinverse, 16, 1, (float *)state->modelinverse);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelview, 16, 1, (float *)state->modelview);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)state->modelviewinverse);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)state->modelviewprojection);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->normalview, 9, 1, (float *)state->normalview);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->normalworld, 9, 1, (float *)state->normalworld);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)state->orcotexfac);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->eye, 3, 1, (float *)state->eyevec);
+ }
+ else {
+ BLI_assert((shgroup->normalview == -1) && (shgroup->normalworld == -1) && (shgroup->eye == -1));
+ /* For instancing and batching. */
+ float unitmat[4][4];
+ unit_m4(unitmat);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->model, 16, 1, (float *)unitmat);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelinverse, 16, 1, (float *)unitmat);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelview, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEW]);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewinverse, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_VIEWINV]);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->modelviewprojection, 16, 1, (float *)DST.view_data.matstate.mat[DRW_MAT_PERS]);
+ GPU_shader_uniform_vector(shgroup->shader, shgroup->orcotexfac, 3, 2, (float *)shgroup->instance_orcofac);
+ }
+}
+
+static void draw_geometry_execute_ex(
+ DRWShadingGroup *shgroup, Gwn_Batch *geom, unsigned int start, unsigned int count, bool draw_instance)
+{
+ /* Special case: empty drawcall, placement is done via shader, don't bind anything. */
+ if (geom == NULL) {
+ BLI_assert(shgroup->type == DRW_SHG_TRIANGLE_BATCH); /* Add other type if needed. */
+ /* Shader is already bound. */
+ GWN_draw_primitive(GWN_PRIM_TRIS, count);
+ return;
+ }
+
+ /* step 2 : bind vertex array & draw */
+ GWN_batch_program_set_no_use(geom, GPU_shader_get_program(shgroup->shader), GPU_shader_get_interface(shgroup->shader));
+ /* XXX hacking gawain. we don't want to call glUseProgram! (huge performance loss) */
+ geom->program_in_use = true;
+
+ GWN_batch_draw_range_ex(geom, start, count, draw_instance);
+
+ geom->program_in_use = false; /* XXX hacking gawain */
+}
+
+static void draw_geometry_execute(DRWShadingGroup *shgroup, Gwn_Batch *geom)
+{
+ draw_geometry_execute_ex(shgroup, geom, 0, 0, false);
+}
+
+enum {
+ BIND_NONE = 0,
+ BIND_TEMP = 1, /* Release slot after this shading group. */
+ BIND_PERSIST = 2, /* Release slot only after the next shader change. */
+};
+
+static void bind_texture(GPUTexture *tex, char bind_type)
+{
+ int index;
+ char *slot_flags = DST.RST.bound_tex_slots;
+ int bind_num = GPU_texture_bound_number(tex);
+ if (bind_num == -1) {
+ for (int i = 0; i < GPU_max_textures(); ++i) {
+ index = DST.RST.bind_tex_inc = (DST.RST.bind_tex_inc + 1) % GPU_max_textures();
+ if (slot_flags[index] == BIND_NONE) {
+ if (DST.RST.bound_texs[index] != NULL) {
+ GPU_texture_unbind(DST.RST.bound_texs[index]);
+ }
+ GPU_texture_bind(tex, index);
+ DST.RST.bound_texs[index] = tex;
+ slot_flags[index] = bind_type;
+ // printf("Binds Texture %d %p\n", DST.RST.bind_tex_inc, tex);
+ return;
+ }
+ }
+ printf("Not enough texture slots! Reduce number of textures used by your shader.\n");
+ }
+ slot_flags[bind_num] = bind_type;
+}
+
+static void bind_ubo(GPUUniformBuffer *ubo, char bind_type)
+{
+ int index;
+ char *slot_flags = DST.RST.bound_ubo_slots;
+ int bind_num = GPU_uniformbuffer_bindpoint(ubo);
+ if (bind_num == -1) {
+ for (int i = 0; i < GPU_max_ubo_binds(); ++i) {
+ index = DST.RST.bind_ubo_inc = (DST.RST.bind_ubo_inc + 1) % GPU_max_ubo_binds();
+ if (slot_flags[index] == BIND_NONE) {
+ if (DST.RST.bound_ubos[index] != NULL) {
+ GPU_uniformbuffer_unbind(DST.RST.bound_ubos[index]);
+ }
+ GPU_uniformbuffer_bind(ubo, index);
+ DST.RST.bound_ubos[index] = ubo;
+ slot_flags[index] = bind_type;
+ return;
+ }
+ }
+ /* printf so user can report bad behaviour */
+ printf("Not enough ubo slots! This should not happen!\n");
+ /* This is not depending on user input.
+ * It is our responsability to make sure there is enough slots. */
+ BLI_assert(0);
+ }
+ slot_flags[bind_num] = bind_type;
+}
+
+static void release_texture_slots(bool with_persist)
+{
+ if (with_persist) {
+ memset(DST.RST.bound_tex_slots, 0x0, sizeof(*DST.RST.bound_tex_slots) * GPU_max_textures());
+ }
+ else {
+ for (int i = 0; i < GPU_max_textures(); ++i) {
+ if (DST.RST.bound_tex_slots[i] != BIND_PERSIST)
+ DST.RST.bound_tex_slots[i] = BIND_NONE;
+ }
+ }
+
+ /* Reset so that slots are consistenly assigned for different shader
+ * draw calls, to avoid shader specialization/patching by the driver. */
+ DST.RST.bind_tex_inc = 0;
+}
+
+static void release_ubo_slots(bool with_persist)
+{
+ if (with_persist) {
+ memset(DST.RST.bound_ubo_slots, 0x0, sizeof(*DST.RST.bound_ubo_slots) * GPU_max_ubo_binds());
+ }
+ else {
+ for (int i = 0; i < GPU_max_ubo_binds(); ++i) {
+ if (DST.RST.bound_ubo_slots[i] != BIND_PERSIST)
+ DST.RST.bound_ubo_slots[i] = BIND_NONE;
+ }
+ }
+
+ /* Reset so that slots are consistenly assigned for different shader
+ * draw calls, to avoid shader specialization/patching by the driver. */
+ DST.RST.bind_ubo_inc = 0;
+}
+
+static void draw_shgroup(DRWShadingGroup *shgroup, DRWState pass_state)
+{
+ BLI_assert(shgroup->shader);
+
+ GPUTexture *tex;
+ GPUUniformBuffer *ubo;
+ int val;
+ float fval;
+ const bool shader_changed = (DST.shader != shgroup->shader);
+
+ if (shader_changed) {
+ if (DST.shader) GPU_shader_unbind();
+ GPU_shader_bind(shgroup->shader);
+ DST.shader = shgroup->shader;
+ }
+
+ release_ubo_slots(shader_changed);
+ release_texture_slots(shader_changed);
+
+ drw_state_set((pass_state & shgroup->state_extra_disable) | shgroup->state_extra);
+ drw_stencil_set(shgroup->stencil_mask);
+
+ /* Binding Uniform */
+ /* Don't check anything, Interface should already contain the least uniform as possible */
+ for (DRWUniform *uni = shgroup->uniforms; uni; uni = uni->next) {
+ switch (uni->type) {
+ case DRW_UNIFORM_SHORT_TO_INT:
+ val = (int)*((short *)uni->value);
+ GPU_shader_uniform_vector_int(
+ shgroup->shader, uni->location, uni->length, uni->arraysize, &val);
+ break;
+ case DRW_UNIFORM_INT_COPY:
+ val = GET_INT_FROM_POINTER(uni->value);
+ GPU_shader_uniform_vector_int(
+ shgroup->shader, uni->location, uni->length, uni->arraysize, &val);
+ break;
+ case DRW_UNIFORM_SHORT_TO_FLOAT:
+ fval = (float)*((short *)uni->value);
+ GPU_shader_uniform_vector(
+ shgroup->shader, uni->location, uni->length, uni->arraysize, (float *)&fval);
+ break;
+ case DRW_UNIFORM_BOOL:
+ case DRW_UNIFORM_INT:
+ GPU_shader_uniform_vector_int(
+ shgroup->shader, uni->location, uni->length, uni->arraysize, (int *)uni->value);
+ break;
+ case DRW_UNIFORM_FLOAT:
+ GPU_shader_uniform_vector(
+ shgroup->shader, uni->location, uni->length, uni->arraysize, (float *)uni->value);
+ break;
+ case DRW_UNIFORM_TEXTURE:
+ tex = (GPUTexture *)uni->value;
+ BLI_assert(tex);
+ bind_texture(tex, BIND_TEMP);
+ GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
+ break;
+ case DRW_UNIFORM_TEXTURE_PERSIST:
+ tex = (GPUTexture *)uni->value;
+ BLI_assert(tex);
+ bind_texture(tex, BIND_PERSIST);
+ GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
+ break;
+ case DRW_UNIFORM_TEXTURE_REF:
+ tex = *((GPUTexture **)uni->value);
+ BLI_assert(tex);
+ bind_texture(tex, BIND_TEMP);
+ GPU_shader_uniform_texture(shgroup->shader, uni->location, tex);
+ break;
+ case DRW_UNIFORM_BLOCK:
+ ubo = (GPUUniformBuffer *)uni->value;
+ bind_ubo(ubo, BIND_TEMP);
+ GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
+ break;
+ case DRW_UNIFORM_BLOCK_PERSIST:
+ ubo = (GPUUniformBuffer *)uni->value;
+ bind_ubo(ubo, BIND_PERSIST);
+ GPU_shader_uniform_buffer(shgroup->shader, uni->location, ubo);
+ break;
+ }
+ }
+
+#ifdef USE_GPU_SELECT
+# define GPU_SELECT_LOAD_IF_PICKSEL(_select_id) \
+ if (G.f & G_PICKSEL) { \
+ GPU_select_load_id(_select_id); \
+ } ((void)0)
+
+# define GPU_SELECT_LOAD_IF_PICKSEL_CALL(_call) \
+ if ((G.f & G_PICKSEL) && (_call)) { \
+ GPU_select_load_id((_call)->select_id); \
+ } ((void)0)
+
+# define GPU_SELECT_LOAD_IF_PICKSEL_LIST(_shgroup, _start, _count) \
+ _start = 0; \
+ _count = _shgroup->instance_count; \
+ int *select_id = NULL; \
+ if (G.f & G_PICKSEL) { \
+ if (_shgroup->override_selectid == -1) { \
+ select_id = DRW_instance_data_get(_shgroup->inst_selectid); \
+ switch (_shgroup->type) { \
+ case DRW_SHG_TRIANGLE_BATCH: _count = 3; break; \
+ case DRW_SHG_LINE_BATCH: _count = 2; break; \
+ default: _count = 1; break; \
+ } \
+ } \
+ else { \
+ GPU_select_load_id(_shgroup->override_selectid); \
+ } \
+ } \
+ while (_start < _shgroup->instance_count) { \
+ if (select_id) { \
+ GPU_select_load_id(select_id[_start]); \
+ }
+
+# define GPU_SELECT_LOAD_IF_PICKSEL_LIST_END(_start, _count) \
+ _start += _count; \
+ }
+
+#else
+# define GPU_SELECT_LOAD_IF_PICKSEL(select_id)
+# define GPU_SELECT_LOAD_IF_PICKSEL_CALL(call)
+# define GPU_SELECT_LOAD_IF_PICKSEL_LIST_END(start, count)
+# define GPU_SELECT_LOAD_IF_PICKSEL_LIST(_shgroup, _start, _count) \
+ _start = 0; \
+ _count = _shgroup->instance_count;
+
+#endif
+
+ /* Rendering Calls */
+ if (!ELEM(shgroup->type, DRW_SHG_NORMAL)) {
+ /* Replacing multiple calls with only one */
+ if (ELEM(shgroup->type, DRW_SHG_INSTANCE, DRW_SHG_INSTANCE_EXTERNAL)) {
+ if (shgroup->type == DRW_SHG_INSTANCE_EXTERNAL) {
+ if (shgroup->instance_geom != NULL) {
+ GPU_SELECT_LOAD_IF_PICKSEL(shgroup->override_selectid);
+ draw_geometry_prepare(shgroup, NULL);
+ draw_geometry_execute_ex(shgroup, shgroup->instance_geom, 0, 0, true);
+ }
+ }
+ else {
+ if (shgroup->instance_count > 0) {
+ unsigned int count, start;
+ draw_geometry_prepare(shgroup, NULL);
+ GPU_SELECT_LOAD_IF_PICKSEL_LIST(shgroup, start, count)
+ {
+ draw_geometry_execute_ex(shgroup, shgroup->instance_geom, start, count, true);
+ }
+ GPU_SELECT_LOAD_IF_PICKSEL_LIST_END(start, count)
+ }
+ }
+ }
+ else { /* DRW_SHG_***_BATCH */
+ /* Some dynamic batch can have no geom (no call to aggregate) */
+ if (shgroup->instance_count > 0) {
+ unsigned int count, start;
+ draw_geometry_prepare(shgroup, NULL);
+ GPU_SELECT_LOAD_IF_PICKSEL_LIST(shgroup, start, count)
+ {
+ draw_geometry_execute_ex(shgroup, shgroup->batch_geom, start, count, false);
+ }
+ GPU_SELECT_LOAD_IF_PICKSEL_LIST_END(start, count)
+ }
+ }
+ }
+ else {
+ bool prev_neg_scale = false;
+ int callid = 0;
+ for (DRWCall *call = shgroup->calls.first; call; call = call->next) {
+
+ /* OPTI/IDEA(clem): Do this preparation in another thread. */
+ draw_visibility_eval(call->state);
+ draw_matrices_model_prepare(call->state);
+
+ if ((call->state->flag & DRW_CALL_CULLED) != 0)
+ continue;
+
+ /* XXX small exception/optimisation for outline rendering. */
+ if (shgroup->callid != -1) {
+ GPU_shader_uniform_vector_int(shgroup->shader, shgroup->callid, 1, 1, &callid);
+ callid += 1;
+ }
+
+ /* Negative scale objects */
+ bool neg_scale = call->state->flag & DRW_CALL_NEGSCALE;
+ if (neg_scale != prev_neg_scale) {
+ glFrontFace((neg_scale) ? DST.backface : DST.frontface);
+ prev_neg_scale = neg_scale;
+ }
+
+ GPU_SELECT_LOAD_IF_PICKSEL_CALL(call);
+ draw_geometry_prepare(shgroup, call->state);
+
+ switch (call->type) {
+ case DRW_CALL_SINGLE:
+ draw_geometry_execute(shgroup, call->single.geometry);
+ break;
+ case DRW_CALL_INSTANCES:
+ draw_geometry_execute_ex(shgroup, call->instances.geometry, 0, *call->instances.count, true);
+ break;
+ case DRW_CALL_GENERATE:
+ call->generate.geometry_fn(shgroup, draw_geometry_execute, call->generate.user_data);
+ break;
+ default:
+ BLI_assert(0);
+ }
+ }
+ /* Reset state */
+ glFrontFace(DST.frontface);
+ }
+
+ /* TODO: remove, (currently causes alpha issue with sculpt, need to investigate) */
+ DRW_state_reset();
+}
+
+static void drw_update_view(void)
+{
+ if (DST.dirty_mat) {
+ DST.state_cache_id++;
+ DST.dirty_mat = false;
+
+ DRW_uniformbuffer_update(view_ubo, &DST.view_data);
+
+ /* Catch integer wrap around. */
+ if (UNLIKELY(DST.state_cache_id == 0)) {
+ DST.state_cache_id = 1;
+ /* We must reset all CallStates to ensure that not
+ * a single one stayed with cache_id equal to 1. */
+ BLI_mempool_iter iter;
+ DRWCallState *state;
+ BLI_mempool_iternew(DST.vmempool->states, &iter);
+ while ((state = BLI_mempool_iterstep(&iter))) {
+ state->cache_id = 0;
+ }
+ }
+
+ /* TODO dispatch threads to compute matrices/culling */
+ }
+
+ draw_clipping_setup_from_view();
+}
+
+static void drw_draw_pass_ex(DRWPass *pass, DRWShadingGroup *start_group, DRWShadingGroup *end_group)
+{
+ if (start_group == NULL)
+ return;
+
+ DST.shader = NULL;
+
+ BLI_assert(DST.buffer_finish_called && "DRW_render_instance_buffer_finish had not been called before drawing");
+
+ drw_update_view();
+
+ drw_state_set(pass->state);
+
+ DRW_stats_query_start(pass->name);
+
+ for (DRWShadingGroup *shgroup = start_group; shgroup; shgroup = shgroup->next) {
+ draw_shgroup(shgroup, pass->state);
+ /* break if upper limit */
+ if (shgroup == end_group) {
+ break;
+ }
+ }
+
+ /* Clear Bound textures */
+ for (int i = 0; i < GPU_max_textures(); i++) {
+ if (DST.RST.bound_texs[i] != NULL) {
+ GPU_texture_unbind(DST.RST.bound_texs[i]);
+ DST.RST.bound_texs[i] = NULL;
+ }
+ }
+
+ /* Clear Bound Ubos */
+ for (int i = 0; i < GPU_max_ubo_binds(); i++) {
+ if (DST.RST.bound_ubos[i] != NULL) {
+ GPU_uniformbuffer_unbind(DST.RST.bound_ubos[i]);
+ DST.RST.bound_ubos[i] = NULL;
+ }
+ }
+
+ if (DST.shader) {
+ GPU_shader_unbind();
+ DST.shader = NULL;
+ }
+
+ DRW_stats_query_end();
+}
+
+void DRW_draw_pass(DRWPass *pass)
+{
+ drw_draw_pass_ex(pass, pass->shgroups.first, pass->shgroups.last);
+}
+
+/* Draw only a subset of shgroups. Used in special situations as grease pencil strokes */
+void DRW_draw_pass_subset(DRWPass *pass, DRWShadingGroup *start_group, DRWShadingGroup *end_group)
+{
+ drw_draw_pass_ex(pass, start_group, end_group);
+}
+
+/** \} */
diff --git a/source/blender/draw/intern/draw_manager_profiling.c b/source/blender/draw/intern/draw_manager_profiling.c
new file mode 100644
index 00000000000..d2ed22c57b7
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_profiling.c
@@ -0,0 +1,363 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_manager_profiling.c
+ * \ingroup draw
+ */
+
+#include "BLI_rect.h"
+#include "BLI_string.h"
+
+#include "BKE_global.h"
+
+#include "BLF_api.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "draw_manager.h"
+
+#include "GPU_glew.h"
+#include "GPU_texture.h"
+
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "draw_manager_profiling.h"
+
+#define MAX_TIMER_NAME 32
+#define MAX_NESTED_TIMER 8
+#define CHUNK_SIZE 8
+#define GPU_TIMER_FALLOFF 0.1
+
+typedef struct DRWTimer {
+ GLuint query[2];
+ GLuint64 time_average;
+ char name[MAX_TIMER_NAME];
+ int lvl; /* Hierarchy level for nested timer. */
+ bool is_query; /* Does this timer actually perform queries or is it just a group. */
+} DRWTimer;
+
+static struct DRWTimerPool {
+ DRWTimer *timers;
+ int chunk_count; /* Number of chunk allocated. */
+ int timer_count; /* chunk_count * CHUNK_SIZE */
+ int timer_increment; /* Keep track of where we are in the stack. */
+ int end_increment; /* Keep track of bad usage. */
+ bool is_recording; /* Are we in the render loop? */
+ bool is_querying; /* Keep track of bad usage. */
+} DTP = {NULL};
+
+void DRW_stats_free(void)
+{
+ if (DTP.timers != NULL) {
+ for (int i = 0; i < DTP.timer_count; ++i) {
+ DRWTimer *timer = &DTP.timers[i];
+ glDeleteQueries(2, timer->query);
+ }
+ MEM_freeN(DTP.timers);
+ DTP.timers = NULL;
+ }
+}
+
+void DRW_stats_begin(void)
+{
+ if (G.debug_value > 20) {
+ DTP.is_recording = true;
+ }
+
+ if (DTP.is_recording && DTP.timers == NULL) {
+ DTP.chunk_count = 1;
+ DTP.timer_count = DTP.chunk_count * CHUNK_SIZE;
+ DTP.timers = MEM_callocN(sizeof(DRWTimer) * DTP.timer_count, "DRWTimer stack");
+ }
+ else if (!DTP.is_recording && DTP.timers != NULL) {
+ DRW_stats_free();
+ }
+
+ DTP.is_querying = false;
+ DTP.timer_increment = 0;
+ DTP.end_increment = 0;
+}
+
+static DRWTimer *drw_stats_timer_get(void)
+{
+ if (UNLIKELY(DTP.timer_increment >= DTP.timer_count)) {
+ /* Resize the stack. */
+ DTP.chunk_count++;
+ DTP.timer_count = DTP.chunk_count * CHUNK_SIZE;
+ DTP.timers = MEM_recallocN(DTP.timers, sizeof(DRWTimer) * DTP.timer_count);
+ }
+
+ return &DTP.timers[DTP.timer_increment++];
+}
+
+static void drw_stats_timer_start_ex(const char *name, const bool is_query)
+{
+ if (DTP.is_recording) {
+ DRWTimer *timer = drw_stats_timer_get();
+ BLI_strncpy(timer->name, name, MAX_TIMER_NAME);
+ timer->lvl = DTP.timer_increment - DTP.end_increment - 1;
+ timer->is_query = is_query;
+
+ /* Queries cannot be nested or interleaved. */
+ BLI_assert(!DTP.is_querying);
+ if (timer->is_query) {
+ if (timer->query[0] == 0) {
+ glGenQueries(1, timer->query);
+ }
+
+ /* Issue query for the next frame */
+ glBeginQuery(GL_TIME_ELAPSED, timer->query[0]);
+ DTP.is_querying = true;
+ }
+ }
+}
+
+/* Use this to group the queries. It does NOT keep track
+ * of the time, it only sum what the queries inside it. */
+void DRW_stats_group_start(const char *name)
+{
+ drw_stats_timer_start_ex(name, false);
+}
+
+void DRW_stats_group_end(void)
+{
+ if (DTP.is_recording) {
+ BLI_assert(!DTP.is_querying);
+ DTP.end_increment++;
+ }
+}
+
+/* NOTE: Only call this when no sub timer will be called. */
+void DRW_stats_query_start(const char *name)
+{
+ drw_stats_timer_start_ex(name, true);
+}
+
+void DRW_stats_query_end(void)
+{
+ if (DTP.is_recording) {
+ DTP.end_increment++;
+ BLI_assert(DTP.is_querying);
+ glEndQuery(GL_TIME_ELAPSED);
+ DTP.is_querying = false;
+ }
+}
+
+void DRW_stats_reset(void)
+{
+ BLI_assert((DTP.timer_increment - DTP.end_increment) <= 0 && "You forgot a DRW_stats_group/query_end somewhere!");
+ BLI_assert((DTP.timer_increment - DTP.end_increment) >= 0 && "You forgot a DRW_stats_group/query_start somewhere!");
+
+ if (DTP.is_recording) {
+ GLuint64 lvl_time[MAX_NESTED_TIMER] = {0};
+
+ /* Swap queries for the next frame and sum up each lvl time. */
+ for (int i = DTP.timer_increment - 1; i >= 0; --i) {
+ DRWTimer *timer = &DTP.timers[i];
+ SWAP(GLuint, timer->query[0], timer->query[1]);
+
+ BLI_assert(timer->lvl < MAX_NESTED_TIMER);
+
+ if (timer->is_query) {
+ GLuint64 time;
+ if (timer->query[0] != 0) {
+ glGetQueryObjectui64v(timer->query[0], GL_QUERY_RESULT, &time);
+ }
+ else {
+ time = 1000000000; /* 1ms default */
+ }
+
+ timer->time_average = timer->time_average * (1.0 - GPU_TIMER_FALLOFF) + time * GPU_TIMER_FALLOFF;
+ timer->time_average = MIN2(timer->time_average, 1000000000);
+ }
+ else {
+ timer->time_average = lvl_time[timer->lvl + 1];
+ lvl_time[timer->lvl + 1] = 0;
+ }
+
+ lvl_time[timer->lvl] += timer->time_average;
+ }
+
+ DTP.is_recording = false;
+ }
+}
+
+static void draw_stat_5row(rcti *rect, int u, int v, const char *txt, const int size)
+{
+ BLF_draw_default_ascii(rect->xmin + (1 + u * 5) * U.widget_unit,
+ rect->ymax - (3 + v) * U.widget_unit, 0.0f,
+ txt, size);
+}
+
+static void draw_stat(rcti *rect, int u, int v, const char *txt, const int size)
+{
+ BLF_draw_default_ascii(rect->xmin + (1 + u) * U.widget_unit,
+ rect->ymax - (3 + v) * U.widget_unit, 0.0f,
+ txt, size);
+}
+
+void DRW_stats_draw(rcti *rect)
+{
+ char stat_string[64];
+ int lvl_index[MAX_NESTED_TIMER];
+ int v = 0, u = 0;
+
+ double init_tot_time = 0.0, background_tot_time = 0.0, render_tot_time = 0.0, tot_time = 0.0;
+
+ int fontid = BLF_default();
+ UI_FontThemeColor(fontid, TH_TEXT_HI);
+ BLF_enable(fontid, BLF_SHADOW);
+ BLF_shadow(fontid, 5, (const float[4]){0.0f, 0.0f, 0.0f, 0.75f});
+ BLF_shadow_offset(fontid, 0, -1);
+
+ BLF_batch_draw_begin();
+
+ /* ------------------------------------------ */
+ /* ---------------- CPU stats --------------- */
+ /* ------------------------------------------ */
+ /* Label row */
+ char col_label[32];
+ sprintf(col_label, "Engine");
+ draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
+ sprintf(col_label, "Init");
+ draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
+ sprintf(col_label, "Background");
+ draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
+ sprintf(col_label, "Render");
+ draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
+ sprintf(col_label, "Total (w/o cache)");
+ draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
+ v++;
+
+ /* Engines rows */
+ char time_to_txt[16];
+ for (LinkData *link = DST.enabled_engines.first; link; link = link->next) {
+ u = 0;
+ DrawEngineType *engine = link->data;
+ ViewportEngineData *data = drw_viewport_engine_data_ensure(engine);
+
+ draw_stat_5row(rect, u++, v, engine->idname, sizeof(engine->idname));
+
+ init_tot_time += data->init_time;
+ sprintf(time_to_txt, "%.2fms", data->init_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+
+ background_tot_time += data->background_time;
+ sprintf(time_to_txt, "%.2fms", data->background_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+
+ render_tot_time += data->render_time;
+ sprintf(time_to_txt, "%.2fms", data->render_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+
+ tot_time += data->init_time + data->background_time + data->render_time;
+ sprintf(time_to_txt, "%.2fms", data->init_time + data->background_time + data->render_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+ v++;
+ }
+
+ /* Totals row */
+ u = 0;
+ sprintf(col_label, "Sub Total");
+ draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
+ sprintf(time_to_txt, "%.2fms", init_tot_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+ sprintf(time_to_txt, "%.2fms", background_tot_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+ sprintf(time_to_txt, "%.2fms", render_tot_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+ sprintf(time_to_txt, "%.2fms", tot_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+ v += 2;
+
+ u = 0;
+ double *cache_time = GPU_viewport_cache_time_get(DST.viewport);
+ sprintf(col_label, "Cache Time");
+ draw_stat_5row(rect, u++, v, col_label, sizeof(col_label));
+ sprintf(time_to_txt, "%.2fms", *cache_time);
+ draw_stat_5row(rect, u++, v, time_to_txt, sizeof(time_to_txt));
+ v += 2;
+
+ /* ------------------------------------------ */
+ /* ---------------- GPU stats --------------- */
+ /* ------------------------------------------ */
+
+ /* Memory Stats */
+ unsigned int tex_mem = GPU_texture_memory_usage_get();
+ unsigned int vbo_mem = GWN_vertbuf_get_memory_usage();
+
+ sprintf(stat_string, "GPU Memory");
+ draw_stat(rect, 0, v, stat_string, sizeof(stat_string));
+ sprintf(stat_string, "%.2fMB", (double)(tex_mem + vbo_mem) / 1000000.0);
+ draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string));
+ sprintf(stat_string, "Textures");
+ draw_stat(rect, 1, v, stat_string, sizeof(stat_string));
+ sprintf(stat_string, "%.2fMB", (double)tex_mem / 1000000.0);
+ draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string));
+ sprintf(stat_string, "Meshes");
+ draw_stat(rect, 1, v, stat_string, sizeof(stat_string));
+ sprintf(stat_string, "%.2fMB", (double)vbo_mem / 1000000.0);
+ draw_stat_5row(rect, 1, v++, stat_string, sizeof(stat_string));
+ v += 1;
+
+ /* GPU Timings */
+ BLI_snprintf(stat_string, sizeof(stat_string), "GPU Render Timings");
+ draw_stat(rect, 0, v++, stat_string, sizeof(stat_string));
+
+ for (int i = 0; i < DTP.timer_increment; ++i) {
+ double time_ms, time_percent;
+ DRWTimer *timer = &DTP.timers[i];
+ DRWTimer *timer_parent = (timer->lvl > 0) ? &DTP.timers[lvl_index[timer->lvl - 1]] : NULL;
+
+ /* Only display a number of lvl at a time */
+ if ((G.debug_value - 21) < timer->lvl) continue;
+
+ BLI_assert(timer->lvl < MAX_NESTED_TIMER);
+ lvl_index[timer->lvl] = i;
+
+ time_ms = timer->time_average / 1000000.0;
+
+ if (timer_parent != NULL) {
+ time_percent = ((double)timer->time_average / (double)timer_parent->time_average) * 100.0;
+ }
+ else {
+ time_percent = 100.0;
+ }
+
+ /* avoid very long number */
+ time_ms = MIN2(time_ms, 999.0);
+ time_percent = MIN2(time_percent, 100.0);
+
+ BLI_snprintf(stat_string, sizeof(stat_string), "%s", timer->name);
+ draw_stat(rect, 0 + timer->lvl, v, stat_string, sizeof(stat_string));
+ BLI_snprintf(stat_string, sizeof(stat_string), "%.2fms", time_ms);
+ draw_stat(rect, 12 + timer->lvl, v, stat_string, sizeof(stat_string));
+ BLI_snprintf(stat_string, sizeof(stat_string), "%.0f", time_percent);
+ draw_stat(rect, 16 + timer->lvl, v, stat_string, sizeof(stat_string));
+ v++;
+ }
+
+ BLF_batch_draw_end();
+ BLF_disable(fontid, BLF_SHADOW);
+}
diff --git a/source/blender/draw/intern/draw_manager_profiling.h b/source/blender/draw/intern/draw_manager_profiling.h
new file mode 100644
index 00000000000..233cd3878d2
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_profiling.h
@@ -0,0 +1,43 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_manager_profiling.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_MANAGER_PROFILING_H__
+#define __DRAW_MANAGER_PROFILING_H__
+
+struct rcti;
+
+void DRW_stats_free(void);
+void DRW_stats_begin(void);
+void DRW_stats_reset(void);
+
+void DRW_stats_group_start(const char *name);
+void DRW_stats_group_end(void);
+
+void DRW_stats_query_start(const char *name);
+void DRW_stats_query_end(void);
+
+void DRW_stats_draw(rcti *rect);
+
+#endif /* __DRAW_MANAGER_PROFILING_H__ */
diff --git a/source/blender/draw/intern/draw_manager_shader.c b/source/blender/draw/intern/draw_manager_shader.c
new file mode 100644
index 00000000000..06a579c2208
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_shader.c
@@ -0,0 +1,385 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_manager_shader.c
+ * \ingroup draw
+ */
+
+#include "draw_manager.h"
+
+#include "DNA_world_types.h"
+#include "DNA_material_types.h"
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+#include "BLI_threads.h"
+#include "BLI_task.h"
+
+#include "BKE_global.h"
+#include "BKE_main.h"
+
+#include "GPU_shader.h"
+#include "GPU_material.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+extern char datatoc_gpu_shader_2D_vert_glsl[];
+extern char datatoc_gpu_shader_3D_vert_glsl[];
+extern char datatoc_common_fullscreen_vert_glsl[];
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Deferred Compilation (DRW_deferred)
+ *
+ * Since compiling shader can take a long time, we do it in a non blocking
+ * manner in another thread.
+ *
+ * \{ */
+
+typedef struct DRWDeferredShader {
+ struct DRWDeferredShader *prev, *next;
+
+ GPUMaterial *mat;
+ char *vert, *geom, *frag, *defs;
+} DRWDeferredShader;
+
+typedef struct DRWShaderCompiler {
+ ListBase queue; /* DRWDeferredShader */
+ SpinLock list_lock;
+
+ DRWDeferredShader *mat_compiling;
+ ThreadMutex compilation_lock;
+
+ void *ogl_context;
+
+ int shaders_done; /* To compute progress. */
+} DRWShaderCompiler;
+
+static void drw_deferred_shader_free(DRWDeferredShader *dsh)
+{
+ /* Make sure it is not queued before freeing. */
+ MEM_SAFE_FREE(dsh->vert);
+ MEM_SAFE_FREE(dsh->geom);
+ MEM_SAFE_FREE(dsh->frag);
+ MEM_SAFE_FREE(dsh->defs);
+
+ MEM_freeN(dsh);
+}
+
+static void drw_deferred_shader_queue_free(ListBase *queue)
+{
+ DRWDeferredShader *dsh;
+ while ((dsh = BLI_pophead(queue))) {
+ drw_deferred_shader_free(dsh);
+ }
+}
+
+static void drw_deferred_shader_compilation_exec(void *custom_data, short *stop, short *do_update, float *progress)
+{
+ DRWShaderCompiler *comp = (DRWShaderCompiler *)custom_data;
+ void *ogl_context = comp->ogl_context;
+
+ WM_opengl_context_activate(ogl_context);
+
+ while (true) {
+ BLI_spin_lock(&comp->list_lock);
+
+ if (*stop != 0) {
+ /* We don't want user to be able to cancel the compilation
+ * but wm can kill the task if we are closing blender. */
+ BLI_spin_unlock(&comp->list_lock);
+ break;
+ }
+
+ /* Pop tail because it will be less likely to lock the main thread
+ * if all GPUMaterials are to be freed (see DRW_deferred_shader_remove()). */
+ comp->mat_compiling = BLI_poptail(&comp->queue);
+ if (comp->mat_compiling == NULL) {
+ /* No more Shader to compile. */
+ BLI_spin_unlock(&comp->list_lock);
+ break;
+ }
+
+ comp->shaders_done++;
+ int total = BLI_listbase_count(&comp->queue) + comp->shaders_done;
+
+ BLI_mutex_lock(&comp->compilation_lock);
+ BLI_spin_unlock(&comp->list_lock);
+
+ /* Do the compilation. */
+ GPU_material_generate_pass(
+ comp->mat_compiling->mat,
+ comp->mat_compiling->vert,
+ comp->mat_compiling->geom,
+ comp->mat_compiling->frag,
+ comp->mat_compiling->defs);
+
+ *progress = (float)comp->shaders_done / (float)total;
+ *do_update = true;
+
+ glFlush();
+ BLI_mutex_unlock(&comp->compilation_lock);
+
+ drw_deferred_shader_free(comp->mat_compiling);
+ }
+
+ WM_opengl_context_release(ogl_context);
+}
+
+static void drw_deferred_shader_compilation_free(void *custom_data)
+{
+ DRWShaderCompiler *comp = (DRWShaderCompiler *)custom_data;
+
+ drw_deferred_shader_queue_free(&comp->queue);
+
+ BLI_spin_end(&comp->list_lock);
+ BLI_mutex_end(&comp->compilation_lock);
+
+ if (comp->ogl_context) {
+ /* Only destroy if the job owns the context. */
+ WM_opengl_context_dispose(comp->ogl_context);
+ }
+
+ MEM_freeN(comp);
+}
+
+static void drw_deferred_shader_add(
+ GPUMaterial *mat, const char *vert, const char *geom, const char *frag_lib, const char *defines)
+{
+ /* Do not deferre the compilation if we are rendering for image. */
+ if (DRW_state_is_image_render()) {
+ /* Double checking that this GPUMaterial is not going to be
+ * compiled by another thread. */
+ DRW_deferred_shader_remove(mat);
+ GPU_material_generate_pass(mat, vert, geom, frag_lib, defines);
+ return;
+ }
+
+ DRWDeferredShader *dsh = MEM_callocN(sizeof(DRWDeferredShader), "Deferred Shader");
+
+ dsh->mat = mat;
+ if (vert) dsh->vert = BLI_strdup(vert);
+ if (geom) dsh->geom = BLI_strdup(geom);
+ if (frag_lib) dsh->frag = BLI_strdup(frag_lib);
+ if (defines) dsh->defs = BLI_strdup(defines);
+
+ BLI_assert(DST.draw_ctx.evil_C);
+ wmWindowManager *wm = CTX_wm_manager(DST.draw_ctx.evil_C);
+ wmWindow *win = CTX_wm_window(DST.draw_ctx.evil_C);
+ Scene *scene = DST.draw_ctx.scene;
+
+ /* Get the running job or a new one if none is running. Can only have one job per type & owner. */
+ wmJob *wm_job = WM_jobs_get(wm, win, scene, "Shaders Compilation",
+ WM_JOB_PROGRESS | WM_JOB_SUSPEND, WM_JOB_TYPE_SHADER_COMPILATION);
+
+ DRWShaderCompiler *old_comp = (DRWShaderCompiler *)WM_jobs_customdata_get(wm_job);
+
+ DRWShaderCompiler *comp = MEM_callocN(sizeof(DRWShaderCompiler), "DRWShaderCompiler");
+ BLI_spin_init(&comp->list_lock);
+ BLI_mutex_init(&comp->compilation_lock);
+
+ if (old_comp) {
+ BLI_spin_lock(&old_comp->list_lock);
+ BLI_movelisttolist(&comp->queue, &old_comp->queue);
+ BLI_spin_unlock(&old_comp->list_lock);
+ /* Do not recreate context, just pass ownership. */
+ comp->ogl_context = old_comp->ogl_context;
+ old_comp->ogl_context = NULL;
+ }
+
+ BLI_addtail(&comp->queue, dsh);
+
+ /* Create only one context. */
+ if (comp->ogl_context == NULL) {
+ comp->ogl_context = WM_opengl_context_create();
+ WM_opengl_context_activate(DST.ogl_context);
+ }
+
+ WM_jobs_customdata_set(wm_job, comp, drw_deferred_shader_compilation_free);
+ WM_jobs_timer(wm_job, 0.1, NC_MATERIAL | ND_SHADING_DRAW, 0);
+ WM_jobs_callbacks(wm_job, drw_deferred_shader_compilation_exec, NULL, NULL, NULL);
+ WM_jobs_start(wm, wm_job);
+}
+
+void DRW_deferred_shader_remove(GPUMaterial *mat)
+{
+ Scene *scene = GPU_material_scene(mat);
+
+ for (wmWindowManager *wm = G.main->wm.first; wm; wm = wm->id.next) {
+ if (WM_jobs_test(wm, scene, WM_JOB_TYPE_SHADER_COMPILATION) == false) {
+ /* No job running, do not create a new one by calling WM_jobs_get. */
+ continue;
+ }
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ wmJob *wm_job = WM_jobs_get(wm, win, scene, "Shaders Compilation",
+ WM_JOB_PROGRESS | WM_JOB_SUSPEND, WM_JOB_TYPE_SHADER_COMPILATION);
+
+ DRWShaderCompiler *comp = (DRWShaderCompiler *)WM_jobs_customdata_get(wm_job);
+ if (comp != NULL) {
+ BLI_spin_lock(&comp->list_lock);
+ DRWDeferredShader *dsh;
+ dsh = (DRWDeferredShader *)BLI_findptr(&comp->queue, mat, offsetof(DRWDeferredShader, mat));
+ if (dsh) {
+ BLI_remlink(&comp->queue, dsh);
+ }
+
+ /* Wait for compilation to finish */
+ if (comp->mat_compiling != NULL) {
+ if (comp->mat_compiling->mat == mat) {
+ BLI_mutex_lock(&comp->compilation_lock);
+ BLI_mutex_unlock(&comp->compilation_lock);
+ }
+ }
+ BLI_spin_unlock(&comp->list_lock);
+
+ if (dsh) {
+ drw_deferred_shader_free(dsh);
+ }
+ }
+ }
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+GPUShader *DRW_shader_create(const char *vert, const char *geom, const char *frag, const char *defines)
+{
+ return GPU_shader_create(vert, frag, geom, NULL, defines);
+}
+
+GPUShader *DRW_shader_create_with_lib(
+ const char *vert, const char *geom, const char *frag, const char *lib, const char *defines)
+{
+ GPUShader *sh;
+ char *vert_with_lib = NULL;
+ char *frag_with_lib = NULL;
+ char *geom_with_lib = NULL;
+
+ vert_with_lib = BLI_string_joinN(lib, vert);
+ frag_with_lib = BLI_string_joinN(lib, frag);
+ if (geom) {
+ geom_with_lib = BLI_string_joinN(lib, geom);
+ }
+
+ sh = GPU_shader_create(vert_with_lib, frag_with_lib, geom_with_lib, NULL, defines);
+
+ MEM_freeN(vert_with_lib);
+ MEM_freeN(frag_with_lib);
+ if (geom) {
+ MEM_freeN(geom_with_lib);
+ }
+
+ return sh;
+}
+
+GPUShader *DRW_shader_create_2D(const char *frag, const char *defines)
+{
+ return GPU_shader_create(datatoc_gpu_shader_2D_vert_glsl, frag, NULL, NULL, defines);
+}
+
+GPUShader *DRW_shader_create_3D(const char *frag, const char *defines)
+{
+ return GPU_shader_create(datatoc_gpu_shader_3D_vert_glsl, frag, NULL, NULL, defines);
+}
+
+GPUShader *DRW_shader_create_fullscreen(const char *frag, const char *defines)
+{
+ return GPU_shader_create(datatoc_common_fullscreen_vert_glsl, frag, NULL, NULL, defines);
+}
+
+GPUShader *DRW_shader_create_3D_depth_only(void)
+{
+ return GPU_shader_get_builtin_shader(GPU_SHADER_3D_DEPTH_ONLY);
+}
+
+GPUMaterial *DRW_shader_find_from_world(World *wo, const void *engine_type, int options)
+{
+ GPUMaterial *mat = GPU_material_from_nodetree_find(&wo->gpumaterial, engine_type, options);
+ if (DRW_state_is_image_render()) {
+ if (mat != NULL && GPU_material_status(mat) == GPU_MAT_QUEUED) {
+ /* XXX Hack : we return NULL so that the engine will call DRW_shader_create_from_XXX
+ * with the shader code and we will resume the compilation from there. */
+ return NULL;
+ }
+ }
+ return mat;
+}
+
+GPUMaterial *DRW_shader_find_from_material(Material *ma, const void *engine_type, int options)
+{
+ GPUMaterial *mat = GPU_material_from_nodetree_find(&ma->gpumaterial, engine_type, options);
+ if (DRW_state_is_image_render()) {
+ if (mat != NULL && GPU_material_status(mat) == GPU_MAT_QUEUED) {
+ /* XXX Hack : we return NULL so that the engine will call DRW_shader_create_from_XXX
+ * with the shader code and we will resume the compilation from there. */
+ return NULL;
+ }
+ }
+ return mat;
+}
+
+GPUMaterial *DRW_shader_create_from_world(
+ struct Scene *scene, World *wo, const void *engine_type, int options,
+ const char *vert, const char *geom, const char *frag_lib, const char *defines)
+{
+ GPUMaterial *mat = NULL;
+ if (DRW_state_is_image_render()) {
+ mat = GPU_material_from_nodetree_find(&wo->gpumaterial, engine_type, options);
+ }
+
+ if (mat == NULL) {
+ mat = GPU_material_from_nodetree(
+ scene, wo->nodetree, &wo->gpumaterial, engine_type, options);
+ }
+
+ drw_deferred_shader_add(mat, vert, geom, frag_lib, defines);
+
+ return mat;
+}
+
+GPUMaterial *DRW_shader_create_from_material(
+ struct Scene *scene, Material *ma, const void *engine_type, int options,
+ const char *vert, const char *geom, const char *frag_lib, const char *defines)
+{
+ GPUMaterial *mat = NULL;
+ if (DRW_state_is_image_render()) {
+ mat = GPU_material_from_nodetree_find(&ma->gpumaterial, engine_type, options);
+ }
+
+ if (mat == NULL) {
+ mat = GPU_material_from_nodetree(
+ scene, ma->nodetree, &ma->gpumaterial, engine_type, options);
+ }
+
+ drw_deferred_shader_add(mat, vert, geom, frag_lib, defines);
+
+ return mat;
+}
+
+void DRW_shader_free(GPUShader *shader)
+{
+ GPU_shader_free(shader);
+}
diff --git a/source/blender/draw/intern/draw_manager_text.c b/source/blender/draw/intern/draw_manager_text.c
new file mode 100644
index 00000000000..56255af98ce
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_text.c
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/** \file blender/draw/intern/draw_manager_text.c
+ * \ingroup draw
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_math.h"
+
+#include "BIF_gl.h"
+
+#include "GPU_matrix.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "UI_resources.h"
+#include "UI_interface.h"
+
+#include "WM_api.h"
+#include "BLF_api.h"
+
+#include "draw_manager_text.h"
+
+typedef struct ViewCachedString {
+ struct ViewCachedString *next, *prev;
+ float vec[3];
+ union {
+ unsigned char ub[4];
+ int pack;
+ } col;
+ short sco[2];
+ short xoffs;
+ short flag;
+ int str_len;
+
+ /* str is allocated past the end */
+ char str[0];
+} ViewCachedString;
+
+typedef struct DRWTextStore {
+ ListBase list;
+} DRWTextStore;
+
+DRWTextStore *DRW_text_cache_create(void)
+{
+ DRWTextStore *dt = MEM_callocN(sizeof(*dt), __func__);
+ return dt;
+}
+
+void DRW_text_cache_destroy(struct DRWTextStore *dt)
+{
+ BLI_freelistN(&dt->list);
+ MEM_freeN(dt);
+}
+
+void DRW_text_cache_add(
+ DRWTextStore *dt,
+ const float co[3],
+ const char *str, const int str_len,
+ short xoffs, short flag,
+ const unsigned char col[4])
+{
+ int alloc_len;
+ ViewCachedString *vos;
+
+ if (flag & DRW_TEXT_CACHE_STRING_PTR) {
+ BLI_assert(str_len == strlen(str));
+ alloc_len = sizeof(void *);
+ }
+ else {
+ alloc_len = str_len + 1;
+ }
+
+ vos = MEM_mallocN(sizeof(ViewCachedString) + alloc_len, __func__);
+
+ BLI_addtail(&dt->list, vos);
+
+ copy_v3_v3(vos->vec, co);
+ copy_v4_v4_uchar(vos->col.ub, col);
+ vos->xoffs = xoffs;
+ vos->flag = flag;
+ vos->str_len = str_len;
+
+ /* allocate past the end */
+ if (flag & DRW_TEXT_CACHE_STRING_PTR) {
+ memcpy(vos->str, &str, alloc_len);
+ }
+ else {
+ memcpy(vos->str, str, alloc_len);
+ }
+}
+
+void DRW_text_cache_draw(
+ DRWTextStore *dt,
+ View3D *v3d, ARegion *ar, bool depth_write)
+{
+ RegionView3D *rv3d = ar->regiondata;
+ ViewCachedString *vos;
+ int tot = 0;
+
+ /* project first and test */
+ for (vos = dt->list.first; vos; vos = vos->next) {
+ if (ED_view3d_project_short_ex(
+ ar,
+ (vos->flag & DRW_TEXT_CACHE_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob,
+ (vos->flag & DRW_TEXT_CACHE_LOCALCLIP) != 0,
+ vos->vec, vos->sco,
+ V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
+ {
+ tot++;
+ }
+ else {
+ vos->sco[0] = IS_CLIPPED;
+ }
+ }
+
+ if (tot) {
+ int col_pack_prev = 0;
+
+ if (rv3d->rflag & RV3D_CLIPPING) {
+ ED_view3d_clipping_disable();
+ }
+
+ float original_proj[4][4];
+ gpuGetProjectionMatrix(original_proj);
+ wmOrtho2_region_pixelspace(ar);
+
+ gpuPushMatrix();
+ gpuLoadIdentity();
+
+ if (depth_write) {
+ if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
+ }
+ else {
+ glDepthMask(GL_FALSE);
+ }
+
+ const int font_id = BLF_default();
+
+ const uiStyle *style = UI_style_get();
+
+ BLF_size(font_id, style->widget.points * U.pixelsize, U.dpi);
+
+ for (vos = dt->list.first; vos; vos = vos->next) {
+ if (vos->sco[0] != IS_CLIPPED) {
+ if (col_pack_prev != vos->col.pack) {
+ BLF_color4ubv(font_id, vos->col.ub);
+ col_pack_prev = vos->col.pack;
+ }
+
+ BLF_position(
+ font_id,
+ (float)(vos->sco[0] + vos->xoffs), (float)(vos->sco[1]), (depth_write) ? 0.0f : 2.0f);
+
+ ((vos->flag & DRW_TEXT_CACHE_ASCII) ?
+ BLF_draw_ascii :
+ BLF_draw
+ )(font_id,
+ (vos->flag & DRW_TEXT_CACHE_STRING_PTR) ? *((const char **)vos->str) : vos->str,
+ vos->str_len);
+ }
+ }
+
+ if (depth_write) {
+ if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
+ }
+ else {
+ glDepthMask(GL_TRUE);
+ }
+
+ gpuPopMatrix();
+ gpuLoadProjectionMatrix(original_proj);
+
+ if (rv3d->rflag & RV3D_CLIPPING) {
+ ED_view3d_clipping_enable();
+ }
+ }
+}
diff --git a/source/blender/draw/intern/draw_manager_text.h b/source/blender/draw/intern/draw_manager_text.h
new file mode 100644
index 00000000000..a58e167be0d
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_text.h
@@ -0,0 +1,54 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+/** \file blender/draw/intern/draw_manager_text.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_MANAGER_TEXT_H__
+#define __DRAW_MANAGER_TEXT_H__
+
+struct DRWTextStore;
+
+struct DRWTextStore *DRW_text_cache_create(void);
+void DRW_text_cache_destroy(struct DRWTextStore *dt);
+
+void DRW_text_cache_add(
+ struct DRWTextStore *dt,
+ const float co[3],
+ const char *str, const int str_len,
+ short xoffs, short flag,
+ const unsigned char col[4]);
+
+void DRW_text_cache_draw(
+ struct DRWTextStore *dt,
+ struct View3D *v3d, struct ARegion *ar, bool depth_write);
+
+enum {
+ DRW_TEXT_CACHE_ASCII = (1 << 0),
+ DRW_TEXT_CACHE_GLOBALSPACE = (1 << 1),
+ DRW_TEXT_CACHE_LOCALCLIP = (1 << 2),
+ /* reference the string by pointer */
+ DRW_TEXT_CACHE_STRING_PTR = (1 << 3),
+};
+
+/* draw_manager.c */
+struct DRWTextStore *DRW_text_cache_ensure(void);
+
+#endif /* __DRAW_MANAGER_TEXT_H__ */
diff --git a/source/blender/draw/intern/draw_manager_texture.c b/source/blender/draw/intern/draw_manager_texture.c
new file mode 100644
index 00000000000..607b5e19745
--- /dev/null
+++ b/source/blender/draw/intern/draw_manager_texture.c
@@ -0,0 +1,151 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_manager_texture.c
+ * \ingroup draw
+ */
+
+#include "draw_manager.h"
+
+#ifndef NDEBUG
+/* Maybe gpu_texture.c is a better place for this. */
+static bool drw_texture_format_supports_framebuffer(GPUTextureFormat format)
+{
+ /* Some formats do not work with framebuffers. */
+ switch (format) {
+ /* Only add formats that are COMPATIBLE with FB.
+ * Generally they are multiple of 16bit. */
+ case GPU_R16F:
+ case GPU_R16I:
+ case GPU_R16UI:
+ case GPU_R32F:
+ case GPU_R32UI:
+ case GPU_RG8:
+ case GPU_RG16:
+ case GPU_RG16F:
+ case GPU_RG16I:
+ case GPU_RG32F:
+ case GPU_R11F_G11F_B10F:
+ case GPU_RGBA8:
+ case GPU_RGBA16F:
+ case GPU_RGBA32F:
+ case GPU_DEPTH_COMPONENT16:
+ case GPU_DEPTH_COMPONENT24:
+ case GPU_DEPTH24_STENCIL8:
+ case GPU_DEPTH_COMPONENT32F:
+ return true;
+ default:
+ return false;
+ }
+}
+#endif
+
+void drw_texture_set_parameters(GPUTexture *tex, DRWTextureFlag flags)
+{
+ GPU_texture_bind(tex, 0);
+ if (flags & DRW_TEX_MIPMAP) {
+ GPU_texture_mipmap_mode(tex, true, flags & DRW_TEX_FILTER);
+ GPU_texture_generate_mipmap(tex);
+ }
+ else {
+ GPU_texture_filter_mode(tex, flags & DRW_TEX_FILTER);
+ }
+ GPU_texture_wrap_mode(tex, flags & DRW_TEX_WRAP);
+ GPU_texture_compare_mode(tex, flags & DRW_TEX_COMPARE);
+ GPU_texture_unbind(tex);
+}
+
+GPUTexture *DRW_texture_create_1D(int w, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
+{
+ GPUTexture *tex = GPU_texture_create_1D(w, format, fpixels, NULL);
+ drw_texture_set_parameters(tex, flags);
+
+ return tex;
+}
+
+GPUTexture *DRW_texture_create_2D(int w, int h, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
+{
+ GPUTexture *tex = GPU_texture_create_2D(w, h, format, fpixels, NULL);
+ drw_texture_set_parameters(tex, flags);
+
+ return tex;
+}
+
+GPUTexture *DRW_texture_create_2D_array(
+ int w, int h, int d, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
+{
+ GPUTexture *tex = GPU_texture_create_2D_array(w, h, d, format, fpixels, NULL);
+ drw_texture_set_parameters(tex, flags);
+
+ return tex;
+}
+
+GPUTexture *DRW_texture_create_3D(
+ int w, int h, int d, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
+{
+ GPUTexture *tex = GPU_texture_create_3D(w, h, d, format, fpixels, NULL);
+ drw_texture_set_parameters(tex, flags);
+
+ return tex;
+}
+
+GPUTexture *DRW_texture_create_cube(int w, GPUTextureFormat format, DRWTextureFlag flags, const float *fpixels)
+{
+ GPUTexture *tex = GPU_texture_create_cube(w, format, fpixels, NULL);
+ drw_texture_set_parameters(tex, flags);
+
+ return tex;
+}
+
+GPUTexture *DRW_texture_pool_query_2D(int w, int h, GPUTextureFormat format, DrawEngineType *engine_type)
+{
+ BLI_assert(drw_texture_format_supports_framebuffer(format));
+ GPUTexture *tex = GPU_viewport_texture_pool_query(DST.viewport, engine_type, w, h, format);
+
+ return tex;
+}
+
+void DRW_texture_ensure_fullscreen_2D(GPUTexture **tex, GPUTextureFormat format, DRWTextureFlag flags)
+{
+ if (*(tex) == NULL) {
+ const float *size = DRW_viewport_size_get();
+ *(tex) = DRW_texture_create_2D((int)size[0], (int)size[1], format, flags, NULL);
+ }
+}
+
+void DRW_texture_ensure_2D(GPUTexture **tex, int w, int h, GPUTextureFormat format, DRWTextureFlag flags)
+{
+ if (*(tex) == NULL) {
+ *(tex) = DRW_texture_create_2D(w, h, format, flags, NULL);
+ }
+}
+
+void DRW_texture_generate_mipmaps(GPUTexture *tex)
+{
+ GPU_texture_bind(tex, 0);
+ GPU_texture_generate_mipmap(tex);
+ GPU_texture_unbind(tex);
+}
+
+void DRW_texture_free(GPUTexture *tex)
+{
+ GPU_texture_free(tex);
+}
diff --git a/source/blender/draw/intern/draw_view.c b/source/blender/draw/intern/draw_view.c
new file mode 100644
index 00000000000..be43f0d8c0c
--- /dev/null
+++ b/source/blender/draw/intern/draw_view.c
@@ -0,0 +1,712 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/intern/draw_view.c
+ * \ingroup draw
+ *
+ * Contains dynamic drawing using immediate mode
+ */
+
+#include "DNA_brush_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+
+#include "ED_screen.h"
+#include "ED_transform.h"
+#include "ED_view3d.h"
+
+#include "GPU_draw.h"
+#include "GPU_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BKE_global.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
+#include "BKE_unit.h"
+
+#include "DRW_render.h"
+
+#include "view3d_intern.h"
+
+#include "draw_view.h"
+
+/* ******************** region info ***************** */
+
+void DRW_draw_region_info(void)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ARegion *ar = draw_ctx->ar;
+ int offset;
+
+ DRW_draw_cursor();
+
+ offset = DRW_draw_region_engine_info_offset();
+
+ view3d_draw_region_info(draw_ctx->evil_C, ar, offset);
+
+ if (offset > 0) {
+ DRW_draw_region_engine_info();
+ }
+}
+
+/* ************************* Grid ************************** */
+
+static void gridline_range(double x0, double dx, double max, int *r_first, int *r_count)
+{
+ /* determine range of gridlines that appear in this Area -- similar calc but separate ranges for x & y
+ * x0 is gridline 0, the axis in screen space
+ * Area covers [0 .. max) pixels */
+
+ int first = (int)ceil(-x0 / dx);
+ int last = (int)floor((max - x0) / dx);
+
+ if (first <= last) {
+ *r_first = first;
+ *r_count = last - first + 1;
+ }
+ else {
+ *r_first = 0;
+ *r_count = 0;
+ }
+}
+
+static int gridline_count(ARegion *ar, double x0, double y0, double dx)
+{
+ /* x0 & y0 establish the "phase" of the grid within this 2D region
+ * dx is the frequency, shared by x & y directions
+ * pass in dx of smallest (highest precision) grid we want to draw */
+
+ int first, x_ct, y_ct;
+
+ gridline_range(x0, dx, ar->winx, &first, &x_ct);
+ gridline_range(y0, dx, ar->winy, &first, &y_ct);
+
+ int total_ct = x_ct + y_ct;
+
+ return total_ct;
+}
+
+static bool drawgrid_draw(
+ ARegion *ar, double x0, double y0, double dx, int skip_mod,
+ unsigned pos, unsigned col, GLubyte col_value[3])
+{
+ /* skip every skip_mod lines relative to each axis; they will be overlaid by another drawgrid_draw
+ * always skip exact x0 & y0 axes; they will be drawn later in color
+ *
+ * set grid color once, just before the first line is drawn
+ * it's harmless to set same color for every line, or every vertex
+ * but if no lines are drawn, color must not be set! */
+
+ const float x_max = (float)ar->winx;
+ const float y_max = (float)ar->winy;
+
+ int first, ct;
+ int x_ct = 0, y_ct = 0; /* count of lines actually drawn */
+ int lines_skipped_for_next_unit = 0;
+
+ /* draw vertical lines */
+ gridline_range(x0, dx, x_max, &first, &ct);
+
+ for (int i = first; i < first + ct; ++i) {
+ if (i == 0)
+ continue;
+ else if (skip_mod && (i % skip_mod) == 0) {
+ ++lines_skipped_for_next_unit;
+ continue;
+ }
+
+ if (x_ct == 0)
+ immAttrib3ub(col, col_value[0], col_value[1], col_value[2]);
+
+ float x = (float)(x0 + i * dx);
+ immVertex2f(pos, x, 0.0f);
+ immVertex2f(pos, x, y_max);
+ ++x_ct;
+ }
+
+ /* draw horizontal lines */
+ gridline_range(y0, dx, y_max, &first, &ct);
+
+ for (int i = first; i < first + ct; ++i) {
+ if (i == 0)
+ continue;
+ else if (skip_mod && (i % skip_mod) == 0) {
+ ++lines_skipped_for_next_unit;
+ continue;
+ }
+
+ if (x_ct + y_ct == 0)
+ immAttrib3ub(col, col_value[0], col_value[1], col_value[2]);
+
+ float y = (float)(y0 + i * dx);
+ immVertex2f(pos, 0.0f, y);
+ immVertex2f(pos, x_max, y);
+ ++y_ct;
+ }
+
+ return lines_skipped_for_next_unit > 0;
+}
+
+#define GRID_MIN_PX_D 6.0
+#define GRID_MIN_PX_F 6.0f
+
+static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit)
+{
+ RegionView3D *rv3d = ar->regiondata;
+
+ double fx = rv3d->persmat[3][0];
+ double fy = rv3d->persmat[3][1];
+ double fw = rv3d->persmat[3][3];
+
+ const double wx = 0.5 * ar->winx; /* use double precision to avoid rounding errors */
+ const double wy = 0.5 * ar->winy;
+
+ double x = wx * fx / fw;
+ double y = wy * fy / fw;
+
+ double vec4[4] = { v3d->grid, v3d->grid, 0.0, 1.0 };
+ mul_m4_v4d(rv3d->persmat, vec4);
+ fx = vec4[0];
+ fy = vec4[1];
+ fw = vec4[3];
+
+ double dx = fabs(x - wx * fx / fw);
+ if (dx == 0) dx = fabs(y - wy * fy / fw);
+
+ x += wx;
+ y += wy;
+
+ /* now x, y, and dx have their final values
+ * (x,y) is the world origin (0,0,0) mapped to Area-relative screen space
+ * dx is the distance in pixels between grid lines -- same for horiz or vert grid lines */
+
+ glLineWidth(1.0f);
+
+#if 0 /* TODO: write to UI/widget depth buffer, not scene depth */
+ glDepthMask(GL_FALSE); /* disable write in zbuffer */
+#endif
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ unsigned char col[3], col2[3];
+ UI_GetThemeColor3ubv(TH_GRID, col);
+
+ if (unit->system) {
+ const void *usys;
+ int len;
+
+ bUnit_GetSystem(unit->system, B_UNIT_LENGTH, &usys, &len);
+
+ bool first = true;
+
+ if (usys) {
+ int i = len;
+ while (i--) {
+ double scalar = bUnit_GetScaler(usys, i);
+
+ double dx_scalar = dx * scalar / (double)unit->scale_length;
+ if (dx_scalar < (GRID_MIN_PX_D * 2.0)) {
+ /* very very small grid items are less useful when dealing with units */
+ continue;
+ }
+
+ if (first) {
+ first = false;
+
+ /* Store the smallest drawn grid size units name so users know how big each grid cell is */
+ *grid_unit = bUnit_GetNameDisplay(usys, i);
+ rv3d->gridview = (float)((scalar * (double)v3d->grid) / (double)unit->scale_length);
+
+ int gridline_ct = gridline_count(ar, x, y, dx_scalar);
+ if (gridline_ct == 0)
+ goto drawgrid_cleanup; /* nothing to draw */
+
+ immBegin(GWN_PRIM_LINES, gridline_ct * 2);
+ }
+
+ float blend_fac = 1.0f - ((GRID_MIN_PX_F * 2.0f) / (float)dx_scalar);
+ /* tweak to have the fade a bit nicer */
+ blend_fac = (blend_fac * blend_fac) * 2.0f;
+ CLAMP(blend_fac, 0.3f, 1.0f);
+
+ UI_GetThemeColorBlend3ubv(TH_HIGH_GRAD, TH_GRID, blend_fac, col2);
+
+ const int skip_mod = (i == 0) ? 0 : (int)round(bUnit_GetScaler(usys, i - 1) / scalar);
+ if (!drawgrid_draw(ar, x, y, dx_scalar, skip_mod, pos, color, col2))
+ break;
+ }
+ }
+ }
+ else {
+ const double sublines = v3d->gridsubdiv;
+ const float sublines_fl = v3d->gridsubdiv;
+
+ int grids_to_draw = 2; /* first the faint fine grid, then the bold coarse grid */
+
+ if (dx < GRID_MIN_PX_D) {
+ rv3d->gridview *= sublines_fl;
+ dx *= sublines;
+ if (dx < GRID_MIN_PX_D) {
+ rv3d->gridview *= sublines_fl;
+ dx *= sublines;
+ if (dx < GRID_MIN_PX_D) {
+ rv3d->gridview *= sublines_fl;
+ dx *= sublines;
+ grids_to_draw = (dx < GRID_MIN_PX_D) ? 0 : 1;
+ }
+ }
+ }
+ else {
+ if (dx > (GRID_MIN_PX_D * 10.0)) { /* start blending in */
+ rv3d->gridview /= sublines_fl;
+ dx /= sublines;
+ if (dx > (GRID_MIN_PX_D * 10.0)) { /* start blending in */
+ rv3d->gridview /= sublines_fl;
+ dx /= sublines;
+ if (dx > (GRID_MIN_PX_D * 10.0)) {
+ grids_to_draw = 1;
+ }
+ }
+ }
+ }
+
+ int gridline_ct = gridline_count(ar, x, y, dx);
+ if (gridline_ct == 0)
+ goto drawgrid_cleanup; /* nothing to draw */
+
+ immBegin(GWN_PRIM_LINES, gridline_ct * 2);
+
+ if (grids_to_draw == 2) {
+ UI_GetThemeColorBlend3ubv(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0), col2);
+ if (drawgrid_draw(ar, x, y, dx, v3d->gridsubdiv, pos, color, col2)) {
+ drawgrid_draw(ar, x, y, dx * sublines, 0, pos, color, col);
+ }
+ }
+ else if (grids_to_draw == 1) {
+ drawgrid_draw(ar, x, y, dx, 0, pos, color, col);
+ }
+ }
+
+ /* draw visible axes */
+ /* horizontal line */
+ if (0 <= y && y < ar->winy) {
+ UI_make_axis_color(col, col2, ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT) ? 'Y' : 'X');
+ immAttrib3ub(color, col2[0], col2[1], col2[2]);
+ immVertex2f(pos, 0.0f, y);
+ immVertex2f(pos, (float)ar->winx, y);
+ }
+
+ /* vertical line */
+ if (0 <= x && x < ar->winx) {
+ UI_make_axis_color(col, col2, ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM) ? 'Y' : 'Z');
+ immAttrib3ub(color, col2[0], col2[1], col2[2]);
+ immVertex2f(pos, x, 0.0f);
+ immVertex2f(pos, x, (float)ar->winy);
+ }
+
+ immEnd();
+
+drawgrid_cleanup:
+ immUnbindProgram();
+
+#if 0 /* depth write is left enabled above */
+ glDepthMask(GL_TRUE); /* enable write in zbuffer */
+#endif
+}
+
+#undef DEBUG_GRID
+#undef GRID_MIN_PX_D
+#undef GRID_MIN_PX_F
+
+static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit)
+{
+ /* draw only if there is something to draw */
+ if (v3d->gridflag & (V3D_SHOW_FLOOR | V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) {
+ /* draw how many lines?
+ * trunc(v3d->gridlines / 2) * 4
+ * + 2 for xy axes (possibly with special colors)
+ * + 1 for z axis (the only line not in xy plane)
+ * even v3d->gridlines are honored, odd rounded down */
+ const int gridlines = v3d->gridlines / 2;
+ const float grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit);
+ const float grid = gridlines * grid_scale;
+
+ const bool show_floor = (v3d->gridflag & V3D_SHOW_FLOOR) && gridlines >= 1;
+
+ bool show_axis_x = (v3d->gridflag & V3D_SHOW_X) != 0;
+ bool show_axis_y = (v3d->gridflag & V3D_SHOW_Y) != 0;
+ bool show_axis_z = (v3d->gridflag & V3D_SHOW_Z) != 0;
+
+ unsigned char col_grid[3], col_axis[3];
+
+ glLineWidth(1.0f);
+
+ UI_GetThemeColor3ubv(TH_GRID, col_grid);
+
+ if (show_floor) {
+ const unsigned vertex_ct = 2 * (gridlines * 4 + 2);
+ const int sublines = v3d->gridsubdiv;
+
+ unsigned char col_bg[3], col_grid_emphasise[3], col_grid_light[3];
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
+
+ immBegin(GWN_PRIM_LINES, vertex_ct);
+
+ /* draw normal grid lines */
+ UI_GetColorPtrShade3ubv(col_grid, col_grid_light, 10);
+
+ for (int a = 1; a <= gridlines; a++) {
+ /* skip emphasised divider lines */
+ if (a % sublines != 0) {
+ const float line = a * grid_scale;
+
+ immAttrib3ubv(color, col_grid_light);
+
+ immVertex2f(pos, -grid, -line);
+ immVertex2f(pos, +grid, -line);
+ immVertex2f(pos, -grid, +line);
+ immVertex2f(pos, +grid, +line);
+
+ immVertex2f(pos, -line, -grid);
+ immVertex2f(pos, -line, +grid);
+ immVertex2f(pos, +line, -grid);
+ immVertex2f(pos, +line, +grid);
+ }
+ }
+
+ /* draw emphasised grid lines */
+ UI_GetThemeColor3ubv(TH_BACK, col_bg);
+ /* emphasise division lines lighter instead of darker, if background is darker than grid */
+ UI_GetColorPtrShade3ubv(col_grid, col_grid_emphasise,
+ (col_grid[0] + col_grid[1] + col_grid[2] + 30 >
+ col_bg[0] + col_bg[1] + col_bg[2]) ? 20 : -10);
+
+ if (sublines <= gridlines) {
+ immAttrib3ubv(color, col_grid_emphasise);
+
+ for (int a = sublines; a <= gridlines; a += sublines) {
+ const float line = a * grid_scale;
+
+ immVertex2f(pos, -grid, -line);
+ immVertex2f(pos, +grid, -line);
+ immVertex2f(pos, -grid, +line);
+ immVertex2f(pos, +grid, +line);
+
+ immVertex2f(pos, -line, -grid);
+ immVertex2f(pos, -line, +grid);
+ immVertex2f(pos, +line, -grid);
+ immVertex2f(pos, +line, +grid);
+ }
+ }
+
+ /* draw X axis */
+ if (show_axis_x) {
+ show_axis_x = false; /* drawing now, won't need to draw later */
+ UI_make_axis_color(col_grid, col_axis, 'X');
+ immAttrib3ubv(color, col_axis);
+ }
+ else
+ immAttrib3ubv(color, col_grid_emphasise);
+
+ immVertex2f(pos, -grid, 0.0f);
+ immVertex2f(pos, +grid, 0.0f);
+
+ /* draw Y axis */
+ if (show_axis_y) {
+ show_axis_y = false; /* drawing now, won't need to draw later */
+ UI_make_axis_color(col_grid, col_axis, 'Y');
+ immAttrib3ubv(color, col_axis);
+ }
+ else
+ immAttrib3ubv(color, col_grid_emphasise);
+
+ immVertex2f(pos, 0.0f, -grid);
+ immVertex2f(pos, 0.0f, +grid);
+
+ immEnd();
+ immUnbindProgram();
+
+ /* done with XY plane */
+ }
+
+ if (show_axis_x || show_axis_y || show_axis_z) {
+ /* draw axis lines -- sometimes grid floor is off, other times we still need to draw the Z axis */
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR);
+ immBegin(GWN_PRIM_LINES, (show_axis_x + show_axis_y + show_axis_z) * 2);
+
+ if (show_axis_x) {
+ UI_make_axis_color(col_grid, col_axis, 'X');
+ immAttrib3ubv(color, col_axis);
+ immVertex3f(pos, -grid, 0.0f, 0.0f);
+ immVertex3f(pos, +grid, 0.0f, 0.0f);
+ }
+
+ if (show_axis_y) {
+ UI_make_axis_color(col_grid, col_axis, 'Y');
+ immAttrib3ubv(color, col_axis);
+ immVertex3f(pos, 0.0f, -grid, 0.0f);
+ immVertex3f(pos, 0.0f, +grid, 0.0f);
+ }
+
+ if (show_axis_z) {
+ UI_make_axis_color(col_grid, col_axis, 'Z');
+ immAttrib3ubv(color, col_axis);
+ immVertex3f(pos, 0.0f, 0.0f, -grid);
+ immVertex3f(pos, 0.0f, 0.0f, +grid);
+ }
+
+ immEnd();
+ immUnbindProgram();
+ }
+ }
+}
+
+void DRW_draw_grid(void)
+{
+ /* TODO viewport
+ * Missing is the flags to check whether to draw it
+ * for now now we are using the flags in v3d itself.
+ *
+ * Also for now always assume depth is there, so we
+ * draw on top of it.
+ */
+ /**
+ * Calculate pixel-size factor once, is used for lamps and object centers.
+ * Used by #ED_view3d_pixel_size and typically not accessed directly.
+ *
+ * \note #BKE_camera_params_compute_viewplane' also calculates a pixel-size value,
+ * passed to #RE_SetPixelSize, in ortho mode this is compatible with this value,
+ * but in perspective mode its offset by the near-clip.
+ *
+ * 'RegionView3D.pixsize' is used for viewport drawing, not rendering.
+ */
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Scene *scene = draw_ctx->scene;
+ View3D *v3d = draw_ctx->v3d;
+ ARegion *ar = draw_ctx->ar;
+ RegionView3D *rv3d = draw_ctx->rv3d;
+
+ const bool draw_floor = (rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO);
+ const char *grid_unit = NULL;
+
+ /* ortho grid goes first, does not write to depth buffer and doesn't need depth test so it will override
+ * objects if done last
+ * needs to be done always, gridview is adjusted in drawgrid() now, but only for ortho views.
+ */
+ rv3d->gridview = ED_view3d_grid_scale(scene, v3d, &grid_unit);
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthFunc(GL_LESS);
+
+ if (!draw_floor) {
+ /* Do not get in front of overlays */
+ glDepthMask(GL_FALSE);
+
+ ED_region_pixelspace(ar);
+ *(&grid_unit) = NULL; /* drawgrid need this to detect/affect smallest valid unit... */
+ drawgrid(&scene->unit, ar, v3d, &grid_unit);
+
+ gpuLoadProjectionMatrix(rv3d->winmat);
+ gpuLoadMatrix(rv3d->viewmat);
+ }
+ else {
+ glDepthMask(GL_TRUE);
+ drawfloor(scene, v3d, &grid_unit);
+ }
+}
+
+/* ************************* Background ************************** */
+
+void DRW_draw_background(void)
+{
+ /* Just to make sure */
+ glDepthMask(GL_TRUE);
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glStencilMask(0xFF);
+
+ if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
+ float m[4][4];
+ unit_m4(m);
+
+ /* Gradient background Color */
+ glDisable(GL_DEPTH_TEST);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ unsigned char col_hi[3], col_lo[3];
+
+ gpuPushMatrix();
+ gpuLoadIdentity();
+ gpuLoadProjectionMatrix(m);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR_DITHER);
+
+ UI_GetThemeColor3ubv(TH_LOW_GRAD, col_lo);
+ UI_GetThemeColor3ubv(TH_HIGH_GRAD, col_hi);
+
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+ immAttrib3ubv(color, col_lo);
+ immVertex2f(pos, -1.0f, -1.0f);
+ immVertex2f(pos, 1.0f, -1.0f);
+
+ immAttrib3ubv(color, col_hi);
+ immVertex2f(pos, 1.0f, 1.0f);
+ immVertex2f(pos, -1.0f, 1.0f);
+ immEnd();
+
+ immUnbindProgram();
+
+ gpuPopMatrix();
+
+ glClear(GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+
+ glEnable(GL_DEPTH_TEST);
+ }
+ else {
+ /* Solid background Color */
+ UI_ThemeClearColorAlpha(TH_HIGH_GRAD, 1.0f);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
+ }
+}
+
+/* **************************** 3D Cursor ******************************** */
+
+static bool is_cursor_visible(const DRWContextState *draw_ctx, Scene *scene, ViewLayer *view_layer)
+{
+ Object *ob = OBACT(view_layer);
+ View3D *v3d = draw_ctx->v3d;
+ if ((v3d->flag2 & V3D_RENDER_OVERRIDE) > 0 || (v3d->overlay.flag & V3D_OVERLAY_HIDE_CURSOR)) {
+ return false;
+ }
+
+ /* don't draw cursor in paint modes, but with a few exceptions */
+ if (ob && draw_ctx->object_mode & OB_MODE_ALL_PAINT) {
+ /* exception: object is in weight paint and has deforming armature in pose mode */
+ if (draw_ctx->object_mode & OB_MODE_WEIGHT_PAINT) {
+ if (BKE_object_pose_armature_get(ob) != NULL) {
+ return true;
+ }
+ }
+ /* exception: object in texture paint mode, clone brush, use_clone_layer disabled */
+ else if (draw_ctx->object_mode & OB_MODE_TEXTURE_PAINT) {
+ const Paint *p = BKE_paint_get_active(scene, view_layer);
+
+ if (p && p->brush && p->brush->imagepaint_tool == PAINT_TOOL_CLONE) {
+ if ((scene->toolsettings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) == 0) {
+ return true;
+ }
+ }
+ }
+
+ /* no exception met? then don't draw cursor! */
+ return false;
+ }
+
+ return true;
+}
+
+void DRW_draw_cursor(void)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ ARegion *ar = draw_ctx->ar;
+ Scene *scene = draw_ctx->scene;
+ ViewLayer *view_layer = draw_ctx->view_layer;
+
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glDepthMask(GL_FALSE);
+ glDisable(GL_DEPTH_TEST);
+
+ if (is_cursor_visible(draw_ctx, scene, view_layer)) {
+ int co[2];
+ if (ED_view3d_project_int_global(ar, ED_view3d_cursor3d_get(scene, v3d), co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+
+ ED_region_pixelspace(ar);
+ gpuTranslate2f(co[0] + 0.5f, co[1] + 0.5f);
+ gpuScale2f(U.widget_unit, U.widget_unit);
+
+ Gwn_Batch *cursor_batch = DRW_cache_cursor_get();
+ GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_FLAT_COLOR);
+ GWN_batch_program_set(cursor_batch, GPU_shader_get_program(shader), GPU_shader_get_interface(shader));
+
+ /* Draw nice Anti Aliased cursor. */
+ glLineWidth(1.0f);
+ glEnable(GL_BLEND);
+ glEnable(GL_LINE_SMOOTH);
+
+ GWN_batch_draw(cursor_batch);
+ }
+ }
+}
+
+/* **************************** 3D Manipulator ******************************** */
+
+void DRW_draw_manipulator_3d(void)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ v3d->zbuf = false;
+ ARegion *ar = draw_ctx->ar;
+
+ /* draw depth culled manipulators - manipulators need to be updated *after* view matrix was set up */
+ /* TODO depth culling manipulators is not yet supported, just drawing _3D here, should
+ * later become _IN_SCENE (and draw _3D separate) */
+ WM_manipulatormap_draw(
+ ar->manipulator_map, draw_ctx->evil_C,
+ WM_MANIPULATORMAP_DRAWSTEP_3D);
+
+}
+
+void DRW_draw_manipulator_2d(void)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ v3d->zbuf = false;
+ ARegion *ar = draw_ctx->ar;
+
+ WM_manipulatormap_draw(
+ ar->manipulator_map, draw_ctx->evil_C,
+ WM_MANIPULATORMAP_DRAWSTEP_2D);
+
+ glDepthMask(GL_TRUE);
+}
diff --git a/source/blender/draw/intern/draw_view.h b/source/blender/draw/intern/draw_view.h
new file mode 100644
index 00000000000..203420483a7
--- /dev/null
+++ b/source/blender/draw/intern/draw_view.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file draw_view.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_VIEW_H__
+#define __DRAW_VIEW_H__
+
+void DRW_draw_grid(void);
+void DRW_draw_region_info(void);
+void DRW_draw_background(void);
+void DRW_draw_cursor(void);
+void DRW_draw_manipulator_3d(void);
+void DRW_draw_manipulator_2d(void);
+
+#endif /* __DRAW_VIEW_H__ */
diff --git a/source/blender/draw/modes/draw_mode_engines.h b/source/blender/draw/modes/draw_mode_engines.h
new file mode 100644
index 00000000000..9522e3cddc6
--- /dev/null
+++ b/source/blender/draw/modes/draw_mode_engines.h
@@ -0,0 +1,45 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/draw_mode_engines.h
+ * \ingroup draw
+ */
+
+#ifndef __DRAW_MODE_ENGINES_H__
+#define __DRAW_MODE_ENGINES_H__
+
+extern DrawEngineType draw_engine_object_type;
+extern DrawEngineType draw_engine_edit_armature_type;
+extern DrawEngineType draw_engine_edit_curve_type;
+extern DrawEngineType draw_engine_edit_lattice_type;
+extern DrawEngineType draw_engine_edit_mesh_type;
+extern DrawEngineType draw_engine_edit_metaball_type;
+extern DrawEngineType draw_engine_edit_surface_type;
+extern DrawEngineType draw_engine_edit_text_type;
+extern DrawEngineType draw_engine_paint_texture_type;
+extern DrawEngineType draw_engine_paint_vertex_type;
+extern DrawEngineType draw_engine_paint_weight_type;
+extern DrawEngineType draw_engine_particle_type;
+extern DrawEngineType draw_engine_pose_type;
+extern DrawEngineType draw_engine_sculpt_type;
+extern DrawEngineType draw_engine_overlay_type;
+
+#endif /* __DRAW_MODE_ENGINES_H__ */
diff --git a/source/blender/draw/modes/edit_armature_mode.c b/source/blender/draw/modes/edit_armature_mode.c
new file mode 100644
index 00000000000..0288a027b7c
--- /dev/null
+++ b/source/blender/draw/modes/edit_armature_mode.c
@@ -0,0 +1,191 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_armature_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_armature_types.h"
+#include "DNA_view3d_types.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+extern GlobalsUboStorage ts;
+
+/* *********** LISTS *********** */
+typedef struct EDIT_ARMATURE_PassList {
+ struct DRWPass *bone_solid;
+ struct DRWPass *bone_wire;
+ struct DRWPass *bone_outline;
+ struct DRWPass *bone_envelope;
+ struct DRWPass *bone_axes;
+ struct DRWPass *relationship;
+} EDIT_ARMATURE_PassList;
+
+typedef struct EDIT_ARMATURE_StorageList {
+ struct EDIT_ARMATURE_PrivateData *g_data;
+} EDIT_ARMATURE_StorageList;
+
+typedef struct EDIT_ARMATURE_Data {
+ void *engine_type;
+ DRWViewportEmptyList *fbl;
+ DRWViewportEmptyList *txl;
+ EDIT_ARMATURE_PassList *psl;
+ EDIT_ARMATURE_StorageList *stl;
+} EDIT_ARMATURE_Data;
+
+/* *********** STATIC *********** */
+
+typedef struct EDIT_ARMATURE_PrivateData {
+ char pad; /* UNUSED */
+} EDIT_ARMATURE_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+static void EDIT_ARMATURE_cache_init(void *vedata)
+{
+ EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl;
+ EDIT_ARMATURE_StorageList *stl = ((EDIT_ARMATURE_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Solid bones */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
+ psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
+ }
+
+ {
+ /* Bones Outline */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ psl->bone_outline = DRW_pass_create("Bone Outline Pass", state);
+ }
+
+ {
+ /* Wire bones */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND;
+ psl->bone_wire = DRW_pass_create("Bone Wire Pass", state);
+ }
+
+ {
+ /* distance outline around envelope bones */
+ DRWState state = DRW_STATE_ADDITIVE | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_FRONT;
+ psl->bone_envelope = DRW_pass_create("Bone Envelope Outline Pass", state);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WIRE_SMOOTH | DRW_STATE_BLEND;
+ psl->bone_axes = DRW_pass_create("Bone Axes Pass", state);
+ }
+
+ {
+ /* Non Meshes Pass (Camera, empties, lamps ...) */
+ DRWState state =
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
+ DRW_STATE_BLEND | DRW_STATE_WIRE;
+ psl->relationship = DRW_pass_create("Bone Relationship Pass", state);
+ }
+}
+
+static void EDIT_ARMATURE_cache_populate(void *vedata, Object *ob)
+{
+ bArmature *arm = ob->data;
+ EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl;
+
+ if (ob->type == OB_ARMATURE) {
+ if (arm->edbo) {
+ DRWArmaturePasses passes = {
+ .bone_solid = psl->bone_solid,
+ .bone_outline = psl->bone_outline,
+ .bone_wire = psl->bone_wire,
+ .bone_envelope = psl->bone_envelope,
+ .bone_axes = psl->bone_axes,
+ .relationship_lines = psl->relationship,
+ };
+ DRW_shgroup_armature_edit(ob, passes);
+ }
+ }
+}
+
+static void EDIT_ARMATURE_draw_scene(void *vedata)
+{
+ EDIT_ARMATURE_PassList *psl = ((EDIT_ARMATURE_Data *)vedata)->psl;
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const bool transparent_bones = (draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
+
+ DRW_draw_pass(psl->bone_envelope);
+
+ if (transparent_bones) {
+ DRW_pass_state_add(psl->bone_solid, DRW_STATE_BLEND);
+ DRW_pass_state_remove(psl->bone_solid, DRW_STATE_WRITE_DEPTH);
+ DRW_draw_pass(psl->bone_solid);
+ }
+
+ MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
+
+ if (!transparent_bones) {
+ DRW_draw_pass(psl->bone_solid);
+ }
+
+ DRW_draw_pass(psl->bone_outline);
+ DRW_draw_pass(psl->bone_wire);
+ DRW_draw_pass(psl->relationship);
+
+ MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl)
+
+ /* Draw axes with linesmooth and outside of multisample buffer. */
+ DRW_draw_pass(psl->bone_axes);
+}
+
+#if 0
+void EDIT_ARMATURE_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ //BKE_collection_engine_property_add_int(ces, "show_occlude_wire", false);
+}
+#endif
+
+static const DrawEngineDataSize EDIT_ARMATURE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_ARMATURE_Data);
+
+DrawEngineType draw_engine_edit_armature_type = {
+ NULL, NULL,
+ N_("EditArmatureMode"),
+ &EDIT_ARMATURE_data_size,
+ NULL,
+ NULL,
+ &EDIT_ARMATURE_cache_init,
+ &EDIT_ARMATURE_cache_populate,
+ NULL,
+ NULL,
+ &EDIT_ARMATURE_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/edit_curve_mode.c b/source/blender/draw/modes/edit_curve_mode.c
new file mode 100644
index 00000000000..2a383530523
--- /dev/null
+++ b/source/blender/draw/modes/edit_curve_mode.c
@@ -0,0 +1,358 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_curve_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_curve_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_object.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+#include "GPU_batch.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+/* If needed, contains all global/Theme colors
+ * Add needed theme colors / values to DRW_globals_update() and update UBO
+ * Not needed for constant color. */
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_edit_curve_overlay_loosevert_vert_glsl[];
+extern char datatoc_edit_curve_overlay_frag_glsl[];
+extern char datatoc_edit_curve_overlay_handle_geom_glsl[];
+
+extern char datatoc_gpu_shader_3D_vert_glsl[];
+extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_point_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_flat_color_frag_glsl[];
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use EDIT_CURVE_engine_init() to
+ * initialize most of them and EDIT_CURVE_cache_init()
+ * for EDIT_CURVE_PassList */
+
+typedef struct EDIT_CURVE_PassList {
+ /* Declare all passes here and init them in
+ * EDIT_CURVE_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *wire_pass;
+ struct DRWPass *overlay_edge_pass;
+ struct DRWPass *overlay_vert_pass;
+} EDIT_CURVE_PassList;
+
+typedef struct EDIT_CURVE_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} EDIT_CURVE_FramebufferList;
+
+typedef struct EDIT_CURVE_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} EDIT_CURVE_TextureList;
+
+typedef struct EDIT_CURVE_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ struct CustomStruct *block;
+ struct EDIT_CURVE_PrivateData *g_data;
+} EDIT_CURVE_StorageList;
+
+typedef struct EDIT_CURVE_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ EDIT_CURVE_FramebufferList *fbl;
+ EDIT_CURVE_TextureList *txl;
+ EDIT_CURVE_PassList *psl;
+ EDIT_CURVE_StorageList *stl;
+} EDIT_CURVE_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Custom shaders :
+ * Add sources to source/blender/draw/modes/shaders
+ * init in EDIT_CURVE_engine_init();
+ * free in EDIT_CURVE_engine_free(); */
+
+ GPUShader *wire_sh;
+
+ GPUShader *overlay_edge_sh; /* handles and nurbs control cage */
+ GPUShader *overlay_vert_sh;
+
+} e_data = {NULL}; /* Engine data */
+
+typedef struct EDIT_CURVE_PrivateData {
+ /* This keeps the references of the shading groups for
+ * easy access in EDIT_CURVE_cache_populate() */
+
+ /* resulting curve as 'wire' for curves (and optionally normals) */
+ DRWShadingGroup *wire_shgrp;
+
+ DRWShadingGroup *overlay_edge_shgrp;
+ DRWShadingGroup *overlay_vert_shgrp;
+} EDIT_CURVE_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Init Textures, Framebuffers, Storage and Shaders.
+ * It is called for every frames.
+ * (Optional) */
+static void EDIT_CURVE_engine_init(void *vedata)
+{
+ EDIT_CURVE_TextureList *txl = ((EDIT_CURVE_Data *)vedata)->txl;
+ EDIT_CURVE_FramebufferList *fbl = ((EDIT_CURVE_Data *)vedata)->fbl;
+ EDIT_CURVE_StorageList *stl = ((EDIT_CURVE_Data *)vedata)->stl;
+
+ UNUSED_VARS(txl, fbl, stl);
+
+ /* Init Framebuffers like this: order is attachment order (for color texs) */
+ /*
+ * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
+ * {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
+ */
+
+ /* DRW_framebuffer_init takes care of checking if
+ * the framebuffer is valid and has the right size*/
+ /*
+ * float *viewport_size = DRW_viewport_size_get();
+ * DRW_framebuffer_init(&fbl->occlude_wire_fb,
+ * (int)viewport_size[0], (int)viewport_size[1],
+ * tex, 2);
+ */
+
+ if (!e_data.wire_sh) {
+ e_data.wire_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+
+ if (!e_data.overlay_edge_sh) {
+ e_data.overlay_edge_sh = DRW_shader_create_with_lib(
+ datatoc_edit_curve_overlay_loosevert_vert_glsl,
+ datatoc_edit_curve_overlay_handle_geom_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+ }
+
+ if (!e_data.overlay_vert_sh) {
+ e_data.overlay_vert_sh = DRW_shader_create_with_lib(
+ datatoc_edit_curve_overlay_loosevert_vert_glsl, NULL,
+ datatoc_edit_curve_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+ }
+}
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void EDIT_CURVE_cache_init(void *vedata)
+{
+ EDIT_CURVE_PassList *psl = ((EDIT_CURVE_Data *)vedata)->psl;
+ EDIT_CURVE_StorageList *stl = ((EDIT_CURVE_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ DRWShadingGroup *grp;
+
+ /* Center-Line (wire) */
+ psl->wire_pass = DRW_pass_create(
+ "Curve Wire",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE);
+
+ grp = DRW_shgroup_create(e_data.wire_sh, psl->wire_pass);
+ DRW_shgroup_uniform_vec4(grp, "color", ts.colorWireEdit, 1);
+ stl->g_data->wire_shgrp = grp;
+
+
+ psl->overlay_edge_pass = DRW_pass_create(
+ "Curve Handle Overlay",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_WIRE);
+
+ grp = DRW_shgroup_create(e_data.overlay_edge_sh, psl->overlay_edge_pass);
+ DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+ stl->g_data->overlay_edge_shgrp = grp;
+
+
+ psl->overlay_vert_pass = DRW_pass_create(
+ "Curve Vert Overlay",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_POINT);
+
+ grp = DRW_shgroup_create(e_data.overlay_vert_sh, psl->overlay_vert_pass);
+ DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+ stl->g_data->overlay_vert_shgrp = grp;
+ }
+
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void EDIT_CURVE_cache_populate(void *vedata, Object *ob)
+{
+ EDIT_CURVE_PassList *psl = ((EDIT_CURVE_Data *)vedata)->psl;
+ EDIT_CURVE_StorageList *stl = ((EDIT_CURVE_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+
+ UNUSED_VARS(psl, stl);
+
+ if (ob->type == OB_CURVE) {
+#if 0
+ if (ob == draw_ctx->object_edit)
+#else
+ if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob))
+#endif
+ {
+ Curve *cu = ob->data;
+ /* Get geometry cache */
+ struct Gwn_Batch *geom;
+
+ geom = DRW_cache_curve_edge_wire_get(ob);
+ DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
+
+ if ((cu->flag & CU_3D) && (cu->drawflag & CU_HIDE_NORMALS) == 0) {
+ geom = DRW_cache_curve_edge_normal_get(ob, v3d->overlay.normals_length);
+ DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
+ }
+
+ /* Add geom to a shading group */
+ geom = DRW_cache_curve_edge_overlay_get(ob);
+ if (geom) {
+ DRW_shgroup_call_add(stl->g_data->overlay_edge_shgrp, geom, ob->obmat);
+ }
+
+ geom = DRW_cache_curve_vert_overlay_get(ob);
+ DRW_shgroup_call_add(stl->g_data->overlay_vert_shgrp, geom, ob->obmat);
+ }
+ }
+}
+
+/* Optional: Post-cache_populate callback */
+static void EDIT_CURVE_cache_finish(void *vedata)
+{
+ EDIT_CURVE_PassList *psl = ((EDIT_CURVE_Data *)vedata)->psl;
+ EDIT_CURVE_StorageList *stl = ((EDIT_CURVE_Data *)vedata)->stl;
+
+ /* Do something here! dependant on the objects gathered */
+ UNUSED_VARS(psl, stl);
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void EDIT_CURVE_draw_scene(void *vedata)
+{
+ EDIT_CURVE_PassList *psl = ((EDIT_CURVE_Data *)vedata)->psl;
+ EDIT_CURVE_FramebufferList *fbl = ((EDIT_CURVE_Data *)vedata)->fbl;
+
+ /* Default framebuffer and texture */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ UNUSED_VARS(fbl);
+
+ MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
+
+ /* Show / hide entire passes, swap framebuffers ... whatever you fancy */
+ /*
+ * DRW_framebuffer_texture_detach(dtxl->depth);
+ * DRW_framebuffer_bind(fbl->custom_fb);
+ * DRW_draw_pass(psl->pass);
+ * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
+ * DRW_framebuffer_bind(dfbl->default_fb);
+ */
+
+ /* ... or just render passes on default framebuffer. */
+ DRW_draw_pass(psl->wire_pass);
+ DRW_draw_pass(psl->overlay_edge_pass);
+ DRW_draw_pass(psl->overlay_vert_pass);
+
+ MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl)
+
+ /* If you changed framebuffer, double check you rebind
+ * the default one with its textures attached before finishing */
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void EDIT_CURVE_engine_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.overlay_edge_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_vert_sh);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void EDIT_CURVE_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize EDIT_CURVE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_CURVE_Data);
+
+DrawEngineType draw_engine_edit_curve_type = {
+ NULL, NULL,
+ N_("EditCurveMode"),
+ &EDIT_CURVE_data_size,
+ &EDIT_CURVE_engine_init,
+ &EDIT_CURVE_engine_free,
+ &EDIT_CURVE_cache_init,
+ &EDIT_CURVE_cache_populate,
+ &EDIT_CURVE_cache_finish,
+ NULL, /* draw_background but not needed by mode engines */
+ &EDIT_CURVE_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/edit_lattice_mode.c b/source/blender/draw/modes/edit_lattice_mode.c
new file mode 100644
index 00000000000..13c0d6660c7
--- /dev/null
+++ b/source/blender/draw/modes/edit_lattice_mode.c
@@ -0,0 +1,298 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_lattice_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "BKE_object.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+/* If needed, contains all global/Theme colors
+ * Add needed theme colors / values to DRW_globals_update() and update UBO
+ * Not needed for constant color. */
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_edit_lattice_overlay_loosevert_vert_glsl[];
+extern char datatoc_edit_lattice_overlay_frag_glsl[];
+
+extern char datatoc_gpu_shader_3D_vert_glsl[];
+extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_point_uniform_color_frag_glsl[];
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use EDIT_LATTICE_engine_init() to
+ * initialize most of them and EDIT_LATTICE_cache_init()
+ * for EDIT_LATTICE_PassList */
+
+typedef struct EDIT_LATTICE_PassList {
+ /* Declare all passes here and init them in
+ * EDIT_LATTICE_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *wire_pass;
+ struct DRWPass *vert_pass;
+} EDIT_LATTICE_PassList;
+
+typedef struct EDIT_LATTICE_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} EDIT_LATTICE_FramebufferList;
+
+typedef struct EDIT_LATTICE_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} EDIT_LATTICE_TextureList;
+
+typedef struct EDIT_LATTICE_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ struct CustomStruct *block;
+ struct EDIT_LATTICE_PrivateData *g_data;
+} EDIT_LATTICE_StorageList;
+
+typedef struct EDIT_LATTICE_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ EDIT_LATTICE_FramebufferList *fbl;
+ EDIT_LATTICE_TextureList *txl;
+ EDIT_LATTICE_PassList *psl;
+ EDIT_LATTICE_StorageList *stl;
+} EDIT_LATTICE_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Custom shaders :
+ * Add sources to source/blender/draw/modes/shaders
+ * init in EDIT_LATTICE_engine_init();
+ * free in EDIT_LATTICE_engine_free(); */
+ GPUShader *wire_sh;
+
+ GPUShader *overlay_vert_sh;
+
+} e_data = {NULL}; /* Engine data */
+
+typedef struct EDIT_LATTICE_PrivateData {
+ /* This keeps the references of the shading groups for
+ * easy access in EDIT_LATTICE_cache_populate() */
+ DRWShadingGroup *wire_shgrp;
+ DRWShadingGroup *vert_shgrp;
+} EDIT_LATTICE_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Init Textures, Framebuffers, Storage and Shaders.
+ * It is called for every frames.
+ * (Optional) */
+static void EDIT_LATTICE_engine_init(void *vedata)
+{
+ EDIT_LATTICE_TextureList *txl = ((EDIT_LATTICE_Data *)vedata)->txl;
+ EDIT_LATTICE_FramebufferList *fbl = ((EDIT_LATTICE_Data *)vedata)->fbl;
+ EDIT_LATTICE_StorageList *stl = ((EDIT_LATTICE_Data *)vedata)->stl;
+
+ UNUSED_VARS(txl, fbl, stl);
+
+ /* Init Framebuffers like this: order is attachment order (for color texs) */
+ /*
+ * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
+ * {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
+ */
+
+ /* DRW_framebuffer_init takes care of checking if
+ * the framebuffer is valid and has the right size*/
+ /*
+ * float *viewport_size = DRW_viewport_size_get();
+ * DRW_framebuffer_init(&fbl->occlude_wire_fb,
+ * (int)viewport_size[0], (int)viewport_size[1],
+ * tex, 2);
+ */
+
+ if (!e_data.wire_sh) {
+ e_data.wire_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SMOOTH_COLOR);
+ }
+
+ if (!e_data.overlay_vert_sh) {
+ e_data.overlay_vert_sh = DRW_shader_create_with_lib(
+ datatoc_edit_lattice_overlay_loosevert_vert_glsl, NULL,
+ datatoc_edit_lattice_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+ }
+}
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void EDIT_LATTICE_cache_init(void *vedata)
+{
+ EDIT_LATTICE_PassList *psl = ((EDIT_LATTICE_Data *)vedata)->psl;
+ EDIT_LATTICE_StorageList *stl = ((EDIT_LATTICE_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ psl->wire_pass = DRW_pass_create(
+ "Lattice Wire",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE);
+ stl->g_data->wire_shgrp = DRW_shgroup_create(e_data.wire_sh, psl->wire_pass);
+
+ psl->vert_pass = DRW_pass_create(
+ "Lattice Verts",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_POINT);
+ stl->g_data->vert_shgrp = DRW_shgroup_create(e_data.overlay_vert_sh, psl->vert_pass);
+
+ DRW_shgroup_uniform_block(stl->g_data->vert_shgrp, "globalsBlock", globals_ubo);
+ }
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void EDIT_LATTICE_cache_populate(void *vedata, Object *ob)
+{
+ EDIT_LATTICE_PassList *psl = ((EDIT_LATTICE_Data *)vedata)->psl;
+ EDIT_LATTICE_StorageList *stl = ((EDIT_LATTICE_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ UNUSED_VARS(psl);
+
+ if (ob->type == OB_LATTICE) {
+ if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) {
+ /* Get geometry cache */
+ struct Gwn_Batch *geom;
+
+ geom = DRW_cache_lattice_wire_get(ob, true);
+ DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
+
+ geom = DRW_cache_lattice_vert_overlay_get(ob);
+ DRW_shgroup_call_add(stl->g_data->vert_shgrp, geom, ob->obmat);
+ }
+ }
+}
+
+/* Optional: Post-cache_populate callback */
+static void EDIT_LATTICE_cache_finish(void *vedata)
+{
+ EDIT_LATTICE_PassList *psl = ((EDIT_LATTICE_Data *)vedata)->psl;
+ EDIT_LATTICE_StorageList *stl = ((EDIT_LATTICE_Data *)vedata)->stl;
+
+ /* Do something here! dependant on the objects gathered */
+ UNUSED_VARS(psl, stl);
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void EDIT_LATTICE_draw_scene(void *vedata)
+{
+ EDIT_LATTICE_PassList *psl = ((EDIT_LATTICE_Data *)vedata)->psl;
+ EDIT_LATTICE_FramebufferList *fbl = ((EDIT_LATTICE_Data *)vedata)->fbl;
+
+ /* Default framebuffer and texture */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ UNUSED_VARS(fbl);
+
+ MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
+
+ /* Show / hide entire passes, swap framebuffers ... whatever you fancy */
+ /*
+ * DRW_framebuffer_texture_detach(dtxl->depth);
+ * DRW_framebuffer_bind(fbl->custom_fb);
+ * DRW_draw_pass(psl->pass);
+ * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
+ * DRW_framebuffer_bind(dfbl->default_fb);
+ */
+
+ /* ... or just render passes on default framebuffer. */
+ DRW_draw_pass(psl->wire_pass);
+ DRW_draw_pass(psl->vert_pass);
+
+ MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl)
+
+ /* If you changed framebuffer, double check you rebind
+ * the default one with its textures attached before finishing */
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void EDIT_LATTICE_engine_free(void)
+{
+ // Currently built-in, dont free
+ DRW_SHADER_FREE_SAFE(e_data.overlay_vert_sh);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void EDIT_LATTICE_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize EDIT_LATTICE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_LATTICE_Data);
+
+DrawEngineType draw_engine_edit_lattice_type = {
+ NULL, NULL,
+ N_("EditLatticeMode"),
+ &EDIT_LATTICE_data_size,
+ &EDIT_LATTICE_engine_init,
+ &EDIT_LATTICE_engine_free,
+ &EDIT_LATTICE_cache_init,
+ &EDIT_LATTICE_cache_populate,
+ &EDIT_LATTICE_cache_finish,
+ NULL, /* draw_background but not needed by mode engines */
+ &EDIT_LATTICE_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/edit_mesh_mode.c b/source/blender/draw/modes/edit_mesh_mode.c
new file mode 100644
index 00000000000..cf5d36bded6
--- /dev/null
+++ b/source/blender/draw/modes/edit_mesh_mode.c
@@ -0,0 +1,587 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_mesh_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "GPU_shader.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_view3d_types.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+#include "edit_mesh_mode_intern.h" /* own include */
+
+#include "BKE_object.h"
+
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+extern char datatoc_edit_mesh_overlay_frag_glsl[];
+extern char datatoc_edit_mesh_overlay_vert_glsl[];
+extern char datatoc_edit_mesh_overlay_geom_tri_glsl[];
+extern char datatoc_edit_mesh_overlay_geom_edge_glsl[];
+extern char datatoc_edit_mesh_overlay_loosevert_vert_glsl[];
+extern char datatoc_edit_mesh_overlay_facedot_frag_glsl[];
+extern char datatoc_edit_mesh_overlay_facedot_vert_glsl[];
+extern char datatoc_edit_mesh_overlay_mix_vert_glsl[];
+extern char datatoc_edit_mesh_overlay_mix_frag_glsl[];
+extern char datatoc_edit_mesh_overlay_facefill_vert_glsl[];
+extern char datatoc_edit_mesh_overlay_facefill_frag_glsl[];
+extern char datatoc_edit_normals_vert_glsl[];
+extern char datatoc_edit_normals_geom_glsl[];
+extern char datatoc_common_globals_lib_glsl[];
+
+extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
+
+/* *********** LISTS *********** */
+typedef struct EDIT_MESH_PassList {
+ struct DRWPass *vcolor_faces;
+ struct DRWPass *depth_hidden_wire;
+ struct DRWPass *edit_face_overlay;
+ struct DRWPass *edit_face_occluded;
+ struct DRWPass *mix_occlude;
+ struct DRWPass *facefill_occlude;
+ struct DRWPass *normals;
+} EDIT_MESH_PassList;
+
+typedef struct EDIT_MESH_FramebufferList {
+ struct GPUFrameBuffer *occlude_wire_fb;
+} EDIT_MESH_FramebufferList;
+
+typedef struct EDIT_MESH_StorageList {
+ struct EDIT_MESH_PrivateData *g_data;
+} EDIT_MESH_StorageList;
+
+typedef struct EDIT_MESH_Data {
+ void *engine_type;
+ EDIT_MESH_FramebufferList *fbl;
+ DRWViewportEmptyList *txl;
+ EDIT_MESH_PassList *psl;
+ EDIT_MESH_StorageList *stl;
+} EDIT_MESH_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* weight/vert-color */
+ GPUShader *vcolor_face_shader;
+ GPUShader *overlay_tri_sh;
+ GPUShader *overlay_tri_fast_sh;
+ GPUShader *overlay_tri_vcol_sh;
+ GPUShader *overlay_tri_vcol_fast_sh;
+ GPUShader *overlay_edge_sh;
+ GPUShader *overlay_edge_vcol_sh;
+ GPUShader *overlay_vert_sh;
+ GPUShader *overlay_facedot_sh;
+ GPUShader *overlay_mix_sh;
+ GPUShader *overlay_facefill_sh;
+ GPUShader *normals_face_sh;
+ GPUShader *normals_loop_sh;
+ GPUShader *normals_sh;
+ GPUShader *depth_sh;
+ /* temp buffer texture */
+ struct GPUTexture *occlude_wire_depth_tx;
+ struct GPUTexture *occlude_wire_color_tx;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct EDIT_MESH_PrivateData {
+ /* weight/vert-color */
+ DRWShadingGroup *fvcolor_shgrp;
+ DRWShadingGroup *depth_shgrp_hidden_wire;
+
+ DRWShadingGroup *fnormals_shgrp;
+ DRWShadingGroup *vnormals_shgrp;
+ DRWShadingGroup *lnormals_shgrp;
+
+ DRWShadingGroup *face_overlay_shgrp;
+ DRWShadingGroup *ledges_overlay_shgrp;
+ DRWShadingGroup *lverts_overlay_shgrp;
+ DRWShadingGroup *facedot_overlay_shgrp;
+
+ DRWShadingGroup *face_occluded_shgrp;
+ DRWShadingGroup *ledges_occluded_shgrp;
+ DRWShadingGroup *lverts_occluded_shgrp;
+ DRWShadingGroup *facedot_occluded_shgrp;
+ DRWShadingGroup *facefill_occluded_shgrp;
+
+} EDIT_MESH_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+static void EDIT_MESH_engine_init(void *vedata)
+{
+ EDIT_MESH_FramebufferList *fbl = ((EDIT_MESH_Data *)vedata)->fbl;
+
+ const float *viewport_size = DRW_viewport_size_get();
+ const int size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+
+ e_data.occlude_wire_depth_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH_COMPONENT24,
+ &draw_engine_edit_mesh_type);
+ e_data.occlude_wire_color_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8,
+ &draw_engine_edit_mesh_type);
+
+ GPU_framebuffer_ensure_config(&fbl->occlude_wire_fb, {
+ GPU_ATTACHMENT_TEXTURE(e_data.occlude_wire_depth_tx),
+ GPU_ATTACHMENT_TEXTURE(e_data.occlude_wire_color_tx)
+ });
+
+ if (!e_data.vcolor_face_shader) {
+ e_data.vcolor_face_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR_ALPHA);
+ }
+
+ if (!e_data.overlay_tri_sh) {
+ e_data.overlay_tri_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_vert_glsl,
+ datatoc_edit_mesh_overlay_geom_tri_glsl,
+ datatoc_edit_mesh_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define EDGE_FIX\n"
+ "#define ANTI_ALIASING\n"
+ "#define VERTEX_FACING");
+ }
+ if (!e_data.overlay_tri_fast_sh) {
+ e_data.overlay_tri_fast_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_vert_glsl,
+ datatoc_edit_mesh_overlay_geom_tri_glsl,
+ datatoc_edit_mesh_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define ANTI_ALIASING\n"
+ "#define VERTEX_FACING\n");
+ }
+ if (!e_data.overlay_tri_vcol_sh) {
+ e_data.overlay_tri_vcol_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_vert_glsl,
+ datatoc_edit_mesh_overlay_geom_tri_glsl,
+ datatoc_edit_mesh_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define EDGE_FIX\n"
+ "#define VERTEX_SELECTION\n"
+ "#define ANTI_ALIASING\n"
+ "#define VERTEX_FACING\n");
+ }
+ if (!e_data.overlay_tri_vcol_fast_sh) {
+ e_data.overlay_tri_vcol_fast_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_vert_glsl,
+ datatoc_edit_mesh_overlay_geom_tri_glsl,
+ datatoc_edit_mesh_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define VERTEX_SELECTION\n"
+ "#define ANTI_ALIASING\n"
+ "#define VERTEX_FACING\n");
+ }
+ if (!e_data.overlay_edge_sh) {
+ e_data.overlay_edge_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_vert_glsl,
+ datatoc_edit_mesh_overlay_geom_edge_glsl,
+ datatoc_edit_mesh_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define ANTI_ALIASING\n"
+ "#define VERTEX_FACING\n");
+ }
+ if (!e_data.overlay_edge_vcol_sh) {
+ e_data.overlay_edge_vcol_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_vert_glsl,
+ datatoc_edit_mesh_overlay_geom_edge_glsl,
+ datatoc_edit_mesh_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define VERTEX_SELECTION\n"
+ "#define VERTEX_FACING\n");
+ }
+ if (!e_data.overlay_vert_sh) {
+ e_data.overlay_vert_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_loosevert_vert_glsl, NULL,
+ datatoc_edit_mesh_overlay_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define VERTEX_SELECTION\n");
+ }
+ if (!e_data.overlay_facedot_sh) {
+ e_data.overlay_facedot_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_facedot_vert_glsl, NULL,
+ datatoc_edit_mesh_overlay_facedot_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define VERTEX_FACING\n");
+ }
+ if (!e_data.overlay_mix_sh) {
+ e_data.overlay_mix_sh = DRW_shader_create_fullscreen(datatoc_edit_mesh_overlay_mix_frag_glsl, NULL);
+ }
+ if (!e_data.overlay_facefill_sh) {
+ e_data.overlay_facefill_sh = DRW_shader_create_with_lib(
+ datatoc_edit_mesh_overlay_facefill_vert_glsl, NULL,
+ datatoc_edit_mesh_overlay_facefill_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+ }
+ if (!e_data.normals_face_sh) {
+ e_data.normals_face_sh = DRW_shader_create(
+ datatoc_edit_normals_vert_glsl,
+ datatoc_edit_normals_geom_glsl,
+ datatoc_gpu_shader_uniform_color_frag_glsl,
+ "#define FACE_NORMALS\n");
+ }
+ if (!e_data.normals_loop_sh) {
+ e_data.normals_loop_sh = DRW_shader_create(
+ datatoc_edit_normals_vert_glsl,
+ datatoc_edit_normals_geom_glsl,
+ datatoc_gpu_shader_uniform_color_frag_glsl,
+ "#define LOOP_NORMALS\n");
+ }
+ if (!e_data.normals_sh) {
+ e_data.normals_sh = DRW_shader_create(
+ datatoc_edit_normals_vert_glsl,
+ datatoc_edit_normals_geom_glsl,
+ datatoc_gpu_shader_uniform_color_frag_glsl, NULL);
+ }
+ if (!e_data.depth_sh) {
+ e_data.depth_sh = DRW_shader_create_3D_depth_only();
+ }
+}
+
+static DRWPass *edit_mesh_create_overlay_pass(
+ float *faceAlpha, DRWState statemod,
+ DRWShadingGroup **r_face_shgrp, DRWShadingGroup **r_ledges_shgrp,
+ DRWShadingGroup **r_lverts_shgrp, DRWShadingGroup **r_facedot_shgrp)
+{
+ GPUShader *tri_sh, *ledge_sh;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ RegionView3D *rv3d = draw_ctx->rv3d;
+ Scene *scene = draw_ctx->scene;
+ ToolSettings *tsettings = scene->toolsettings;
+
+ if ((tsettings->selectmode & SCE_SELECT_VERTEX) != 0) {
+ ledge_sh = e_data.overlay_edge_vcol_sh;
+
+ if ((rv3d->rflag & RV3D_NAVIGATING) != 0)
+ tri_sh = e_data.overlay_tri_vcol_fast_sh;
+ else
+ tri_sh = e_data.overlay_tri_vcol_sh;
+ }
+ else {
+ ledge_sh = e_data.overlay_edge_sh;
+
+ if ((rv3d->rflag & RV3D_NAVIGATING) != 0)
+ tri_sh = e_data.overlay_tri_fast_sh;
+ else
+ tri_sh = e_data.overlay_tri_sh;
+ }
+
+ DRWPass *pass = DRW_pass_create(
+ "Edit Mesh Face Overlay Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_POINT | statemod);
+
+ *r_face_shgrp = DRW_shgroup_create(tri_sh, pass);
+ DRW_shgroup_uniform_block(*r_face_shgrp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_vec2(*r_face_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
+ DRW_shgroup_uniform_float(*r_face_shgrp, "faceAlphaMod", faceAlpha, 1);
+
+ *r_ledges_shgrp = DRW_shgroup_create(ledge_sh, pass);
+ DRW_shgroup_uniform_block(*r_ledges_shgrp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_vec2(*r_ledges_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
+
+ if ((tsettings->selectmode & (SCE_SELECT_VERTEX)) != 0) {
+ *r_lverts_shgrp = DRW_shgroup_create(e_data.overlay_vert_sh, pass);
+ DRW_shgroup_uniform_block(*r_lverts_shgrp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_vec2(*r_lverts_shgrp, "viewportSize", DRW_viewport_size_get(), 1);
+ }
+
+ if ((tsettings->selectmode & (SCE_SELECT_FACE)) != 0) {
+ *r_facedot_shgrp = DRW_shgroup_create(e_data.overlay_facedot_sh, pass);
+ DRW_shgroup_uniform_block(*r_facedot_shgrp, "globalsBlock", globals_ubo);
+ }
+
+ return pass;
+}
+
+static float backwire_opacity;
+static float face_mod;
+static float size_normal;
+
+static void EDIT_MESH_cache_init(void *vedata)
+{
+ EDIT_MESH_PassList *psl = ((EDIT_MESH_Data *)vedata)->psl;
+ EDIT_MESH_StorageList *stl = ((EDIT_MESH_Data *)vedata)->stl;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+
+ bool do_zbufclip = ((v3d->flag & V3D_ZBUF_SELECT) == 0);
+
+ static float zero = 0.0f;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ psl->vcolor_faces = DRW_pass_create(
+ "Vert Color Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+ stl->g_data->fvcolor_shgrp = DRW_shgroup_create(e_data.vcolor_face_shader, psl->vcolor_faces);
+
+ static float light[3] = {-0.3f, 0.5f, 1.0f};
+ static float alpha = 1.0f;
+ static float world_light = 1.0f; /* XXX, see: paint_vertex_mode.c */
+ DRW_shgroup_uniform_vec3(stl->g_data->fvcolor_shgrp, "light", light, 1);
+ DRW_shgroup_uniform_float(stl->g_data->fvcolor_shgrp, "alpha", &alpha, 1);
+ DRW_shgroup_uniform_float(stl->g_data->fvcolor_shgrp, "global", &world_light, 1);
+ }
+
+ {
+ /* Complementary Depth Pass */
+ psl->depth_hidden_wire = DRW_pass_create(
+ "Depth Pass Hidden Wire",
+ DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK);
+ stl->g_data->depth_shgrp_hidden_wire = DRW_shgroup_create(e_data.depth_sh, psl->depth_hidden_wire);
+ }
+
+ {
+ /* Normals */
+ psl->normals = DRW_pass_create(
+ "Edit Mesh Normals Pass",
+ DRW_STATE_WRITE_DEPTH | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS);
+
+ stl->g_data->fnormals_shgrp = DRW_shgroup_create(e_data.normals_face_sh, psl->normals);
+ DRW_shgroup_uniform_float(stl->g_data->fnormals_shgrp, "normalSize", &size_normal, 1);
+ DRW_shgroup_uniform_vec4(stl->g_data->fnormals_shgrp, "color", ts.colorNormal, 1);
+
+ stl->g_data->vnormals_shgrp = DRW_shgroup_create(e_data.normals_sh, psl->normals);
+ DRW_shgroup_uniform_float(stl->g_data->vnormals_shgrp, "normalSize", &size_normal, 1);
+ DRW_shgroup_uniform_vec4(stl->g_data->vnormals_shgrp, "color", ts.colorVNormal, 1);
+
+ stl->g_data->lnormals_shgrp = DRW_shgroup_create(e_data.normals_loop_sh, psl->normals);
+ DRW_shgroup_uniform_float(stl->g_data->lnormals_shgrp, "normalSize", &size_normal, 1);
+ DRW_shgroup_uniform_vec4(stl->g_data->lnormals_shgrp, "color", ts.colorLNormal, 1);
+ }
+
+ if (!do_zbufclip) {
+ psl->edit_face_overlay = edit_mesh_create_overlay_pass(
+ &face_mod, DRW_STATE_DEPTH_LESS | DRW_STATE_WRITE_DEPTH | DRW_STATE_BLEND,
+ &stl->g_data->face_overlay_shgrp, &stl->g_data->ledges_overlay_shgrp,
+ &stl->g_data->lverts_overlay_shgrp, &stl->g_data->facedot_overlay_shgrp);
+ }
+ else {
+ /* We render all wires with depth and opaque to a new fbo and blend the result based on depth values */
+ psl->edit_face_occluded = edit_mesh_create_overlay_pass(
+ &zero, DRW_STATE_DEPTH_LESS | DRW_STATE_WRITE_DEPTH,
+ &stl->g_data->face_occluded_shgrp, &stl->g_data->ledges_occluded_shgrp,
+ &stl->g_data->lverts_occluded_shgrp, &stl->g_data->facedot_occluded_shgrp);
+
+ /* however we loose the front faces value (because we need the depth of occluded wires and
+ * faces are alpha blended ) so we recover them in a new pass. */
+ psl->facefill_occlude = DRW_pass_create(
+ "Front Face Color",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
+ stl->g_data->facefill_occluded_shgrp = DRW_shgroup_create(e_data.overlay_facefill_sh, psl->facefill_occlude);
+ DRW_shgroup_uniform_block(stl->g_data->facefill_occluded_shgrp, "globalsBlock", globals_ubo);
+
+ /* we need a full screen pass to combine the result */
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+
+ psl->mix_occlude = DRW_pass_create(
+ "Mix Occluded Wires",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND);
+ DRWShadingGroup *mix_shgrp = DRW_shgroup_create(e_data.overlay_mix_sh, psl->mix_occlude);
+ DRW_shgroup_call_add(mix_shgrp, quad, NULL);
+ DRW_shgroup_uniform_float(mix_shgrp, "alpha", &backwire_opacity, 1);
+ DRW_shgroup_uniform_texture_ref(mix_shgrp, "wireColor", &e_data.occlude_wire_color_tx);
+ DRW_shgroup_uniform_texture_ref(mix_shgrp, "wireDepth", &e_data.occlude_wire_depth_tx);
+ DRW_shgroup_uniform_texture_ref(mix_shgrp, "sceneDepth", &dtxl->depth);
+ }
+}
+
+static void edit_mesh_add_ob_to_pass(
+ Scene *scene, Object *ob, DRWShadingGroup *face_shgrp, DRWShadingGroup *ledges_shgrp,
+ DRWShadingGroup *lverts_shgrp, DRWShadingGroup *facedot_shgrp, DRWShadingGroup *facefill_shgrp)
+{
+ struct Gwn_Batch *geo_ovl_tris, *geo_ovl_ledges, *geo_ovl_lverts, *geo_ovl_fcenter;
+ ToolSettings *tsettings = scene->toolsettings;
+
+ DRW_cache_mesh_wire_overlay_get(ob, &geo_ovl_tris, &geo_ovl_ledges, &geo_ovl_lverts);
+ DRW_shgroup_call_add(face_shgrp, geo_ovl_tris, ob->obmat);
+ DRW_shgroup_call_add(ledges_shgrp, geo_ovl_ledges, ob->obmat);
+
+ if (facefill_shgrp) {
+ DRW_shgroup_call_add(facefill_shgrp, geo_ovl_tris, ob->obmat);
+ }
+
+ if ((tsettings->selectmode & SCE_SELECT_VERTEX) != 0) {
+ DRW_shgroup_call_add(lverts_shgrp, geo_ovl_lverts, ob->obmat);
+ }
+
+ if ((tsettings->selectmode & SCE_SELECT_FACE) != 0) {
+ geo_ovl_fcenter = DRW_cache_face_centers_get(ob);
+ DRW_shgroup_call_add(facedot_shgrp, geo_ovl_fcenter, ob->obmat);
+ }
+}
+
+static void EDIT_MESH_cache_populate(void *vedata, Object *ob)
+{
+ EDIT_MESH_StorageList *stl = ((EDIT_MESH_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ Scene *scene = draw_ctx->scene;
+ struct Gwn_Batch *geom;
+
+ if (ob->type == OB_MESH) {
+ if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) {
+ const Mesh *me = ob->data;
+ bool do_occlude_wire = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_OCCLUDE_WIRE) != 0;
+ bool do_show_weight = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_WEIGHT) != 0;
+
+ /* Updating uniform */
+ backwire_opacity = v3d->overlay.backwire_opacity;
+
+ bool fnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_FACE_NORMALS) != 0;
+ bool vnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_VERT_NORMALS) != 0;
+ bool lnormals_do = (v3d->overlay.edit_flag & V3D_OVERLAY_EDIT_LOOP_NORMALS) != 0;
+ /* Updating uniform */
+ size_normal = v3d->overlay.normals_length;
+
+ face_mod = (do_occlude_wire) ? 0.0f : 1.0f;
+
+ if (do_show_weight) {
+ geom = DRW_cache_mesh_surface_weights_get(ob);
+ DRW_shgroup_call_add(stl->g_data->fvcolor_shgrp, geom, ob->obmat);
+ }
+
+ if (do_occlude_wire) {
+ geom = DRW_cache_mesh_surface_get(ob);
+ DRW_shgroup_call_add(stl->g_data->depth_shgrp_hidden_wire, geom, ob->obmat);
+ }
+
+ if (fnormals_do) {
+ geom = DRW_cache_face_centers_get(ob);
+ DRW_shgroup_call_add(stl->g_data->fnormals_shgrp, geom, ob->obmat);
+ }
+
+ if (vnormals_do || lnormals_do) {
+ struct Gwn_Batch *geo_ovl_tris, *geo_ovl_ledges, *geo_ovl_lverts;
+ DRW_cache_mesh_normals_overlay_get(ob, &geo_ovl_tris, &geo_ovl_ledges, &geo_ovl_lverts);
+
+ if (vnormals_do) {
+ DRW_shgroup_call_add(stl->g_data->vnormals_shgrp, geo_ovl_tris, ob->obmat);
+ DRW_shgroup_call_add(stl->g_data->vnormals_shgrp, geo_ovl_ledges, ob->obmat);
+ DRW_shgroup_call_add(stl->g_data->vnormals_shgrp, geo_ovl_lverts, ob->obmat);
+ }
+
+ if (lnormals_do) {
+ DRW_shgroup_call_add(stl->g_data->lnormals_shgrp, geo_ovl_tris, ob->obmat);
+ }
+ }
+
+ if ((v3d->flag & V3D_ZBUF_SELECT) == 0) {
+ edit_mesh_add_ob_to_pass(
+ scene, ob, stl->g_data->face_occluded_shgrp, stl->g_data->ledges_occluded_shgrp,
+ stl->g_data->lverts_occluded_shgrp, stl->g_data->facedot_occluded_shgrp,
+ stl->g_data->facefill_occluded_shgrp);
+ }
+ else {
+ edit_mesh_add_ob_to_pass(
+ scene, ob, stl->g_data->face_overlay_shgrp, stl->g_data->ledges_overlay_shgrp,
+ stl->g_data->lverts_overlay_shgrp, stl->g_data->facedot_overlay_shgrp, NULL);
+ }
+
+ /* 3D text overlay */
+ if (me->drawflag & (ME_DRAWEXTRA_EDGELEN |
+ ME_DRAWEXTRA_FACEAREA |
+ ME_DRAWEXTRA_FACEANG |
+ ME_DRAWEXTRA_EDGEANG))
+ {
+ DRW_edit_mesh_mode_text_measure_stats(
+ draw_ctx->ar, v3d, ob, &scene->unit);
+ }
+ }
+ }
+}
+
+static void EDIT_MESH_draw_scene(void *vedata)
+{
+ EDIT_MESH_PassList *psl = ((EDIT_MESH_Data *)vedata)->psl;
+ EDIT_MESH_FramebufferList *fbl = ((EDIT_MESH_Data *)vedata)->fbl;
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+
+ DRW_draw_pass(psl->vcolor_faces);
+
+ DRW_draw_pass(psl->depth_hidden_wire);
+
+ if (psl->edit_face_occluded) {
+ float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+ /* render facefill */
+ DRW_draw_pass(psl->facefill_occlude);
+
+ /* Render wires on a separate framebuffer */
+ GPU_framebuffer_bind(fbl->occlude_wire_fb);
+ GPU_framebuffer_clear_color_depth(fbl->occlude_wire_fb, clearcol, 1.0f);
+ DRW_draw_pass(psl->normals);
+ DRW_draw_pass(psl->edit_face_occluded);
+
+ /* Combine with scene buffer */
+ GPU_framebuffer_bind(dfbl->color_only_fb);
+ DRW_draw_pass(psl->mix_occlude);
+ }
+ else {
+ DRW_draw_pass(psl->normals);
+ DRW_draw_pass(psl->edit_face_overlay);
+ }
+}
+
+static void EDIT_MESH_engine_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.overlay_tri_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_tri_fast_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_tri_vcol_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_tri_vcol_fast_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_edge_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_edge_vcol_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_vert_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_facedot_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_mix_sh);
+ DRW_SHADER_FREE_SAFE(e_data.overlay_facefill_sh);
+ DRW_SHADER_FREE_SAFE(e_data.normals_loop_sh);
+ DRW_SHADER_FREE_SAFE(e_data.normals_face_sh);
+ DRW_SHADER_FREE_SAFE(e_data.normals_sh);
+}
+
+static const DrawEngineDataSize EDIT_MESH_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_MESH_Data);
+
+DrawEngineType draw_engine_edit_mesh_type = {
+ NULL, NULL,
+ N_("EditMeshMode"),
+ &EDIT_MESH_data_size,
+ &EDIT_MESH_engine_init,
+ &EDIT_MESH_engine_free,
+ &EDIT_MESH_cache_init,
+ &EDIT_MESH_cache_populate,
+ NULL,
+ NULL,
+ &EDIT_MESH_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/edit_mesh_mode_intern.h b/source/blender/draw/modes/edit_mesh_mode_intern.h
new file mode 100644
index 00000000000..99298bd41f4
--- /dev/null
+++ b/source/blender/draw/modes/edit_mesh_mode_intern.h
@@ -0,0 +1,38 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/draw/modes/edit_mesh_mode_intern.h
+ * \ingroup draw
+ */
+
+#ifndef __EDIT_MESH_MODE_INTERN_H__
+#define __EDIT_MESH_MODE_INTERN_H__
+
+struct ARegion;
+struct Object;
+struct UnitSettings;
+struct View3D;
+
+/* edit_mesh_mode_text.c */
+void DRW_edit_mesh_mode_text_measure_stats(
+ struct ARegion *ar, struct View3D *v3d,
+ struct Object *ob, const UnitSettings *unit);
+
+#endif /* __EDIT_MESH_MODE_INTERN_H__ */
diff --git a/source/blender/draw/modes/edit_mesh_mode_text.c b/source/blender/draw/modes/edit_mesh_mode_text.c
new file mode 100644
index 00000000000..a832c61cab5
--- /dev/null
+++ b/source/blender/draw/modes/edit_mesh_mode_text.c
@@ -0,0 +1,301 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_mesh_mode_text.c
+ * \ingroup draw
+ */
+
+#include "BLI_math.h"
+#include "BLI_string.h"
+
+#include "BKE_editmesh.h"
+#include "BKE_global.h"
+#include "BKE_unit.h"
+
+#include "ED_view3d.h"
+
+#include "GPU_shader.h"
+#include "GPU_viewport.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_view3d_types.h"
+
+#include "UI_resources.h"
+
+#include "draw_manager_text.h"
+
+#include "edit_mesh_mode_intern.h" /* own include */
+
+/* Copied from drawobject.c */
+void DRW_edit_mesh_mode_text_measure_stats(
+ ARegion *ar, View3D *v3d,
+ Object *ob, const UnitSettings *unit)
+{
+ /* Do not use ascii when using non-default unit system, some unit chars are utf8 (micro, square, etc.).
+ * See bug #36090.
+ */
+ struct DRWTextStore *dt = DRW_text_cache_ensure();
+ const short txt_flag = DRW_TEXT_CACHE_LOCALCLIP | (unit->system ? 0 : DRW_TEXT_CACHE_ASCII);
+ Mesh *me = ob->data;
+ BMEditMesh *em = me->edit_btmesh;
+ float v1[3], v2[3], v3[3], vmid[3], fvec[3];
+ char numstr[32]; /* Stores the measurement display text here */
+ size_t numstr_len;
+ const char *conv_float; /* Use a float conversion matching the grid size */
+ unsigned char col[4] = {0, 0, 0, 255}; /* color of the text to draw */
+ float area; /* area of the face */
+ float grid = unit->system ? unit->scale_length : v3d->grid;
+ const bool do_split = (unit->flag & USER_UNIT_OPT_SPLIT) != 0;
+ const bool do_global = (v3d->flag & V3D_GLOBAL_STATS) != 0;
+ const bool do_moving = (G.moving & G_TRANSFORM_EDIT) != 0;
+ /* when 2 edge-info options are enabled, space apart */
+ const bool do_edge_textpair = (me->drawflag & ME_DRAWEXTRA_EDGELEN) && (me->drawflag & ME_DRAWEXTRA_EDGEANG);
+ const float edge_texpair_sep = 0.4f;
+ float clip_planes[4][4];
+ /* allow for displaying shape keys and deform mods */
+ BMIter iter;
+
+ /* make the precision of the display value proportionate to the gridsize */
+
+ if (grid <= 0.01f) conv_float = "%.6g";
+ else if (grid <= 0.1f) conv_float = "%.5g";
+ else if (grid <= 1.0f) conv_float = "%.4g";
+ else if (grid <= 10.0f) conv_float = "%.3g";
+ else conv_float = "%.2g";
+
+ if (me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_EDGEANG)) {
+ BoundBox bb;
+ const rcti rect = {0, ar->winx, 0, ar->winy};
+
+ ED_view3d_clipping_calc(&bb, clip_planes, ar, em->ob, &rect);
+ }
+
+ if (me->drawflag & ME_DRAWEXTRA_EDGELEN) {
+ BMEdge *eed;
+
+ UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGELEN, col);
+
+ BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+ /* draw selected edges, or edges next to selected verts while dragging */
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT) ||
+ (do_moving && (BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))))
+ {
+ float v1_clip[3], v2_clip[3];
+
+ copy_v3_v3(v1, eed->v1->co);
+ copy_v3_v3(v2, eed->v2->co);
+
+ if (clip_segment_v3_plane_n(v1, v2, clip_planes, 4, v1_clip, v2_clip)) {
+
+ if (do_edge_textpair) {
+ interp_v3_v3v3(vmid, v1, v2, edge_texpair_sep);
+ }
+ else {
+ mid_v3_v3v3(vmid, v1_clip, v2_clip);
+ }
+
+ if (do_global) {
+ mul_mat3_m4_v3(ob->obmat, v1);
+ mul_mat3_m4_v3(ob->obmat, v2);
+ }
+
+ if (unit->system) {
+ numstr_len = bUnit_AsString(
+ numstr, sizeof(numstr), len_v3v3(v1, v2) * unit->scale_length, 3,
+ unit->system, B_UNIT_LENGTH, do_split, false);
+ }
+ else {
+ numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, len_v3v3(v1, v2));
+ }
+
+ DRW_text_cache_add(dt, vmid, numstr, numstr_len, 0, txt_flag, col);
+ }
+ }
+ }
+ }
+
+ if (me->drawflag & ME_DRAWEXTRA_EDGEANG) {
+ const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
+ BMEdge *eed;
+
+ UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGEANG, col);
+
+ BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+ BMLoop *l_a, *l_b;
+ if (BM_edge_loop_pair(eed, &l_a, &l_b)) {
+ /* draw selected edges, or edges next to selected verts while dragging */
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT) ||
+ (do_moving &&
+ (BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(eed->v2, BM_ELEM_SELECT) ||
+ /* special case, this is useful to show when verts connected to
+ * this edge via a face are being transformed */
+ BM_elem_flag_test(l_a->next->next->v, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(l_a->prev->v, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(l_b->next->next->v, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(l_b->prev->v, BM_ELEM_SELECT)
+ )))
+ {
+ float v1_clip[3], v2_clip[3];
+
+ copy_v3_v3(v1, eed->v1->co);
+ copy_v3_v3(v2, eed->v2->co);
+
+ if (clip_segment_v3_plane_n(v1, v2, clip_planes, 4, v1_clip, v2_clip)) {
+ float no_a[3], no_b[3];
+ float angle;
+
+ if (do_edge_textpair) {
+ interp_v3_v3v3(vmid, v2_clip, v1_clip, edge_texpair_sep);
+ }
+ else {
+ mid_v3_v3v3(vmid, v1_clip, v2_clip);
+ }
+
+ copy_v3_v3(no_a, l_a->f->no);
+ copy_v3_v3(no_b, l_b->f->no);
+
+ if (do_global) {
+ mul_mat3_m4_v3(ob->imat, no_a);
+ mul_mat3_m4_v3(ob->imat, no_b);
+ normalize_v3(no_a);
+ normalize_v3(no_b);
+ }
+
+ angle = angle_normalized_v3v3(no_a, no_b);
+
+ numstr_len = BLI_snprintf_rlen(
+ numstr, sizeof(numstr), "%.3f", is_rad ? angle : RAD2DEGF(angle));
+
+ DRW_text_cache_add(dt, vmid, numstr, numstr_len, 0, txt_flag, col);
+ }
+ }
+ }
+ }
+ }
+
+ if (me->drawflag & ME_DRAWEXTRA_FACEAREA) {
+ /* would be nice to use BM_face_calc_area, but that is for 2d faces
+ * so instead add up tessellation triangle areas */
+
+ UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
+
+ int i, n, numtri;
+ BMFace *f = NULL;
+ BM_ITER_MESH_INDEX(f, &iter, em->bm, BM_FACES_OF_MESH, i) {
+ if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
+ n = 0;
+ numtri = f->len - 2;
+ area = 0;
+ zero_v3(vmid);
+ BMLoop *(*l)[3] = &em->looptris[poly_to_tri_count(i, BM_elem_index_get(f->l_first))];
+ for (int j = 0; j < numtri; j++) {
+ copy_v3_v3(v1, l[j][0]->v->co);
+ copy_v3_v3(v2, l[j][1]->v->co);
+ copy_v3_v3(v3, l[j][2]->v->co);
+
+ add_v3_v3(vmid, v1);
+ add_v3_v3(vmid, v2);
+ add_v3_v3(vmid, v3);
+ n += 3;
+
+ if (do_global) {
+ mul_mat3_m4_v3(ob->obmat, v1);
+ mul_mat3_m4_v3(ob->obmat, v2);
+ mul_mat3_m4_v3(ob->obmat, v3);
+ }
+
+ area += area_tri_v3(v1, v2, v3);
+ }
+
+ mul_v3_fl(vmid, 1.0f / (float)n);
+
+ if (unit->system) {
+ numstr_len = bUnit_AsString(
+ numstr, sizeof(numstr),
+ (double)(area * unit->scale_length * unit->scale_length),
+ 3, unit->system, B_UNIT_AREA, do_split, false);
+ }
+ else {
+ numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, area);
+ }
+
+ DRW_text_cache_add(dt, vmid, numstr, numstr_len, 0, txt_flag, col);
+ }
+ }
+ }
+
+ if (me->drawflag & ME_DRAWEXTRA_FACEANG) {
+ BMFace *efa;
+ const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
+
+ UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
+
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ const bool is_face_sel = BM_elem_flag_test_bool(efa, BM_ELEM_SELECT);
+
+ if (is_face_sel || do_moving) {
+ BMIter liter;
+ BMLoop *loop;
+ bool is_first = true;
+
+ BM_ITER_ELEM (loop, &liter, efa, BM_LOOPS_OF_FACE) {
+ if (is_face_sel ||
+ (do_moving &&
+ (BM_elem_flag_test(loop->v, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(loop->prev->v, BM_ELEM_SELECT) ||
+ BM_elem_flag_test(loop->next->v, BM_ELEM_SELECT))))
+ {
+ float v2_local[3];
+
+ /* lazy init center calc */
+ if (is_first) {
+ BM_face_calc_center_bounds(efa, vmid);
+ is_first = false;
+ }
+ copy_v3_v3(v1, loop->prev->v->co);
+ copy_v3_v3(v2, loop->v->co);
+ copy_v3_v3(v3, loop->next->v->co);
+
+ copy_v3_v3(v2_local, v2);
+
+ if (do_global) {
+ mul_mat3_m4_v3(ob->obmat, v1);
+ mul_mat3_m4_v3(ob->obmat, v2);
+ mul_mat3_m4_v3(ob->obmat, v3);
+ }
+
+ float angle = angle_v3v3v3(v1, v2, v3);
+
+ numstr_len = BLI_snprintf_rlen(
+ numstr, sizeof(numstr), "%.3f", is_rad ? angle : RAD2DEGF(angle));
+ interp_v3_v3v3(fvec, vmid, v2_local, 0.8f);
+ DRW_text_cache_add(dt, fvec, numstr, numstr_len, 0, txt_flag, col);
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/source/blender/draw/modes/edit_metaball_mode.c b/source/blender/draw/modes/edit_metaball_mode.c
new file mode 100644
index 00000000000..e7b07c36882
--- /dev/null
+++ b/source/blender/draw/modes/edit_metaball_mode.c
@@ -0,0 +1,254 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_metaball_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_meta_types.h"
+
+#include "BKE_object.h"
+#include "BKE_mball.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+#include "GPU_select.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+/* If needed, contains all global/Theme colors
+ * Add needed theme colors / values to DRW_globals_update() and update UBO
+ * Not needed for constant color. */
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use EDIT_METABALL_engine_init() to
+ * initialize most of them and EDIT_METABALL_cache_init()
+ * for EDIT_METABALL_PassList */
+
+typedef struct EDIT_METABALL_PassList {
+ /* Declare all passes here and init them in
+ * EDIT_METABALL_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *pass;
+} EDIT_METABALL_PassList;
+
+typedef struct EDIT_METABALL_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} EDIT_METABALL_FramebufferList;
+
+typedef struct EDIT_METABALL_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} EDIT_METABALL_TextureList;
+
+typedef struct EDIT_METABALL_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ // struct CustomStruct *block;
+ struct EDIT_METABALL_PrivateData *g_data;
+} EDIT_METABALL_StorageList;
+
+typedef struct EDIT_METABALL_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ EDIT_METABALL_FramebufferList *fbl;
+ EDIT_METABALL_TextureList *txl;
+ EDIT_METABALL_PassList *psl;
+ EDIT_METABALL_StorageList *stl;
+} EDIT_METABALL_Data;
+
+/* *********** STATIC *********** */
+
+typedef struct EDIT_METABALL_PrivateData {
+ /* This keeps the references of the shading groups for
+ * easy access in EDIT_METABALL_cache_populate() */
+ DRWShadingGroup *group;
+} EDIT_METABALL_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void EDIT_METABALL_cache_init(void *vedata)
+{
+ EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
+ EDIT_METABALL_StorageList *stl = ((EDIT_METABALL_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Create a pass */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE;
+ psl->pass = DRW_pass_create("My Pass", state);
+
+ /* Create a shadingGroup using a function in draw_common.c or custom one */
+ stl->g_data->group = shgroup_instance_mball_handles(psl->pass);
+ }
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void EDIT_METABALL_cache_populate(void *vedata, Object *ob)
+{
+ //EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
+ EDIT_METABALL_StorageList *stl = ((EDIT_METABALL_Data *)vedata)->stl;
+
+ if (ob->type == OB_MBALL) {
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ DRWShadingGroup *group = stl->g_data->group;
+
+ if ((ob == draw_ctx->object_edit) || BKE_object_is_in_editmode_and_selected(ob)) {
+ MetaBall *mb = ob->data;
+
+ const float *color;
+ const float col_radius[3] = {0.63, 0.19, 0.19}; /* 0x3030A0 */
+ const float col_radius_select[3] = {0.94, 0.63, 0.63}; /* 0xA0A0F0 */
+ const float col_stiffness[3] = {0.19, 0.63, 0.19}; /* 0x30A030 */
+ const float col_stiffness_select[3] = {0.63, 0.94, 0.63}; /* 0xA0F0A0 */
+
+ const bool is_select = DRW_state_is_select();
+
+ int selection_id = 0;
+
+ float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
+ {
+ float scamat[3][3];
+ copy_m3_m4(scamat, ob->obmat);
+ /* Get the normalized inverse matrix to extract only
+ * the scale of Scamat */
+ float iscamat[3][3];
+ invert_m3_m3(iscamat, scamat);
+ normalize_m3(iscamat);
+ mul_m3_m3_post(scamat, iscamat);
+
+ copy_v3_v3(draw_scale_xform[0], scamat[0]);
+ copy_v3_v3(draw_scale_xform[1], scamat[1]);
+ copy_v3_v3(draw_scale_xform[2], scamat[2]);
+ }
+
+ for (MetaElem *ml = mb->editelems->first; ml != NULL; ml = ml->next) {
+ float world_pos[3];
+ mul_v3_m4v3(world_pos, ob->obmat, &ml->x);
+ draw_scale_xform[0][3] = world_pos[0];
+ draw_scale_xform[1][3] = world_pos[1];
+ draw_scale_xform[2][3] = world_pos[2];
+
+ float draw_stiffness_radius = ml->rad * atanf(ml->s) / (float)M_PI_2;
+
+ if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) color = col_radius_select;
+ else color = col_radius;
+
+ if (is_select) {
+ ml->selcol1 = ++selection_id;
+ DRW_select_load_id(selection_id);
+ }
+
+ DRW_shgroup_call_dynamic_add(group, draw_scale_xform, &ml->rad, color);
+
+ if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) color = col_stiffness_select;
+ else color = col_stiffness;
+
+ if (is_select) {
+ ml->selcol2 = ++selection_id;
+ DRW_select_load_id(selection_id);
+ }
+
+ DRW_shgroup_call_dynamic_add(group, draw_scale_xform, &draw_stiffness_radius, color);
+ }
+ }
+ }
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void EDIT_METABALL_draw_scene(void *vedata)
+{
+ EDIT_METABALL_PassList *psl = ((EDIT_METABALL_Data *)vedata)->psl;
+ /* render passes on default framebuffer. */
+ DRW_draw_pass(psl->pass);
+
+ /* If you changed framebuffer, double check you rebind
+ * the default one with its textures attached before finishing */
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void EDIT_METABALL_engine_free(void)
+{
+ // DRW_SHADER_FREE_SAFE(custom_shader);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void EDIT_METABALL_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize EDIT_METABALL_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_METABALL_Data);
+
+DrawEngineType draw_engine_edit_metaball_type = {
+ NULL, NULL,
+ N_("EditMetaballMode"),
+ &EDIT_METABALL_data_size,
+ NULL,
+ &EDIT_METABALL_engine_free,
+ &EDIT_METABALL_cache_init,
+ &EDIT_METABALL_cache_populate,
+ NULL,
+ NULL, /* draw_background but not needed by mode engines */
+ &EDIT_METABALL_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/edit_surface_mode.c b/source/blender/draw/modes/edit_surface_mode.c
new file mode 100644
index 00000000000..2856ec81053
--- /dev/null
+++ b/source/blender/draw/modes/edit_surface_mode.c
@@ -0,0 +1,270 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_surface_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+/* If needed, contains all global/Theme colors
+ * Add needed theme colors / values to DRW_globals_update() and update UBO
+ * Not needed for constant color. */
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use EDIT_SURFACE_engine_init() to
+ * initialize most of them and EDIT_SURFACE_cache_init()
+ * for EDIT_SURFACE_PassList */
+
+typedef struct EDIT_SURFACE_PassList {
+ /* Declare all passes here and init them in
+ * EDIT_SURFACE_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *pass;
+} EDIT_SURFACE_PassList;
+
+typedef struct EDIT_SURFACE_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} EDIT_SURFACE_FramebufferList;
+
+typedef struct EDIT_SURFACE_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} EDIT_SURFACE_TextureList;
+
+typedef struct EDIT_SURFACE_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ struct CustomStruct *block;
+ struct EDIT_SURFACE_PrivateData *g_data;
+} EDIT_SURFACE_StorageList;
+
+typedef struct EDIT_SURFACE_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ EDIT_SURFACE_FramebufferList *fbl;
+ EDIT_SURFACE_TextureList *txl;
+ EDIT_SURFACE_PassList *psl;
+ EDIT_SURFACE_StorageList *stl;
+} EDIT_SURFACE_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Custom shaders :
+ * Add sources to source/blender/draw/modes/shaders
+ * init in EDIT_SURFACE_engine_init();
+ * free in EDIT_SURFACE_engine_free(); */
+ struct GPUShader *custom_shader;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct EDIT_SURFACE_PrivateData {
+ /* This keeps the references of the shading groups for
+ * easy access in EDIT_SURFACE_cache_populate() */
+ DRWShadingGroup *group;
+} EDIT_SURFACE_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Init Textures, Framebuffers, Storage and Shaders.
+ * It is called for every frames.
+ * (Optional) */
+static void EDIT_SURFACE_engine_init(void *vedata)
+{
+ EDIT_SURFACE_TextureList *txl = ((EDIT_SURFACE_Data *)vedata)->txl;
+ EDIT_SURFACE_FramebufferList *fbl = ((EDIT_SURFACE_Data *)vedata)->fbl;
+ EDIT_SURFACE_StorageList *stl = ((EDIT_SURFACE_Data *)vedata)->stl;
+
+ UNUSED_VARS(txl, fbl, stl);
+
+ /* Init Framebuffers like this: order is attachment order (for color texs) */
+ /*
+ * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
+ * {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
+ */
+
+ /* DRW_framebuffer_init takes care of checking if
+ * the framebuffer is valid and has the right size*/
+ /*
+ * float *viewport_size = DRW_viewport_size_get();
+ * DRW_framebuffer_init(&fbl->occlude_wire_fb,
+ * (int)viewport_size[0], (int)viewport_size[1],
+ * tex, 2);
+ */
+
+ if (!e_data.custom_shader) {
+ e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+}
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void EDIT_SURFACE_cache_init(void *vedata)
+{
+ EDIT_SURFACE_PassList *psl = ((EDIT_SURFACE_Data *)vedata)->psl;
+ EDIT_SURFACE_StorageList *stl = ((EDIT_SURFACE_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Create a pass */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE;
+ psl->pass = DRW_pass_create("My Pass", state);
+
+ /* Create a shadingGroup using a function in draw_common.c or custom one */
+ /*
+ * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire);
+ * -- or --
+ * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
+ */
+ stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
+
+ /* Uniforms need a pointer to it's value so be sure it's accessible at
+ * any given time (i.e. use static vars) */
+ static float color[4] = {0.0f, 0.0f, 1.0f, 1.0};
+ DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1);
+ }
+
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void EDIT_SURFACE_cache_populate(void *vedata, Object *ob)
+{
+ EDIT_SURFACE_PassList *psl = ((EDIT_SURFACE_Data *)vedata)->psl;
+ EDIT_SURFACE_StorageList *stl = ((EDIT_SURFACE_Data *)vedata)->stl;
+
+ UNUSED_VARS(psl, stl);
+
+ if (ob->type == OB_MESH) {
+ /* Get geometry cache */
+ struct Gwn_Batch *geom = DRW_cache_mesh_surface_get(ob);
+
+ /* Add geom to a shading group */
+ DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat);
+ }
+}
+
+/* Optional: Post-cache_populate callback */
+static void EDIT_SURFACE_cache_finish(void *vedata)
+{
+ EDIT_SURFACE_PassList *psl = ((EDIT_SURFACE_Data *)vedata)->psl;
+ EDIT_SURFACE_StorageList *stl = ((EDIT_SURFACE_Data *)vedata)->stl;
+
+ /* Do something here! dependant on the objects gathered */
+ UNUSED_VARS(psl, stl);
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void EDIT_SURFACE_draw_scene(void *vedata)
+{
+ EDIT_SURFACE_PassList *psl = ((EDIT_SURFACE_Data *)vedata)->psl;
+ EDIT_SURFACE_FramebufferList *fbl = ((EDIT_SURFACE_Data *)vedata)->fbl;
+
+ /* Default framebuffer and texture */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ UNUSED_VARS(fbl, dfbl, dtxl);
+
+ /* Show / hide entire passes, swap framebuffers ... whatever you fancy */
+ /*
+ * DRW_framebuffer_texture_detach(dtxl->depth);
+ * DRW_framebuffer_bind(fbl->custom_fb);
+ * DRW_draw_pass(psl->pass);
+ * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
+ * DRW_framebuffer_bind(dfbl->default_fb);
+ */
+
+ /* ... or just render passes on default framebuffer. */
+ DRW_draw_pass(psl->pass);
+
+ /* If you changed framebuffer, double check you rebind
+ * the default one with its textures attached before finishing */
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void EDIT_SURFACE_engine_free(void)
+{
+ // DRW_SHADER_FREE_SAFE(custom_shader);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void EDIT_SURFACE_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize EDIT_SURFACE_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_SURFACE_Data);
+
+DrawEngineType draw_engine_edit_surface_type = {
+ NULL, NULL,
+ N_("EditSurfaceMode"),
+ &EDIT_SURFACE_data_size,
+ &EDIT_SURFACE_engine_init,
+ &EDIT_SURFACE_engine_free,
+ &EDIT_SURFACE_cache_init,
+ &EDIT_SURFACE_cache_populate,
+ &EDIT_SURFACE_cache_finish,
+ NULL, /* draw_background but not needed by mode engines */
+ &EDIT_SURFACE_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/edit_text_mode.c b/source/blender/draw/modes/edit_text_mode.c
new file mode 100644
index 00000000000..bbe253b7982
--- /dev/null
+++ b/source/blender/draw/modes/edit_text_mode.c
@@ -0,0 +1,311 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/edit_text_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_curve_types.h"
+
+#include "BIF_glutil.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+#include "GPU_batch.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+/* If needed, contains all global/Theme colors
+ * Add needed theme colors / values to DRW_globals_update() and update UBO
+ * Not needed for constant color. */
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use EDIT_TEXT_engine_init() to
+ * initialize most of them and EDIT_TEXT_cache_init()
+ * for EDIT_TEXT_PassList */
+
+typedef struct EDIT_TEXT_PassList {
+ /* Declare all passes here and init them in
+ * EDIT_TEXT_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *wire_pass;
+ struct DRWPass *overlay_select_pass;
+ struct DRWPass *overlay_cursor_pass;
+} EDIT_TEXT_PassList;
+
+typedef struct EDIT_TEXT_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} EDIT_TEXT_FramebufferList;
+
+typedef struct EDIT_TEXT_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} EDIT_TEXT_TextureList;
+
+typedef struct EDIT_TEXT_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ struct CustomStruct *block;
+ struct EDIT_TEXT_PrivateData *g_data;
+} EDIT_TEXT_StorageList;
+
+typedef struct EDIT_TEXT_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ EDIT_TEXT_FramebufferList *fbl;
+ EDIT_TEXT_TextureList *txl;
+ EDIT_TEXT_PassList *psl;
+ EDIT_TEXT_StorageList *stl;
+} EDIT_TEXT_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Custom shaders :
+ * Add sources to source/blender/draw/modes/shaders
+ * init in EDIT_TEXT_engine_init();
+ * free in EDIT_TEXT_engine_free(); */
+ GPUShader *wire_sh;
+ GPUShader *overlay_select_sh;
+ GPUShader *overlay_cursor_sh;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct EDIT_TEXT_PrivateData {
+ /* resulting curve as 'wire' for fast editmode drawing */
+ DRWShadingGroup *wire_shgrp;
+ DRWShadingGroup *overlay_select_shgrp;
+ DRWShadingGroup *overlay_cursor_shgrp;
+} EDIT_TEXT_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Init Textures, Framebuffers, Storage and Shaders.
+ * It is called for every frames.
+ * (Optional) */
+static void EDIT_TEXT_engine_init(void *vedata)
+{
+ EDIT_TEXT_TextureList *txl = ((EDIT_TEXT_Data *)vedata)->txl;
+ EDIT_TEXT_FramebufferList *fbl = ((EDIT_TEXT_Data *)vedata)->fbl;
+ EDIT_TEXT_StorageList *stl = ((EDIT_TEXT_Data *)vedata)->stl;
+
+ UNUSED_VARS(txl, fbl, stl);
+
+ /* Init Framebuffers like this: order is attachment order (for color texs) */
+ /*
+ * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
+ * {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
+ */
+
+ /* DRW_framebuffer_init takes care of checking if
+ * the framebuffer is valid and has the right size*/
+ /*
+ * float *viewport_size = DRW_viewport_size_get();
+ * DRW_framebuffer_init(&fbl->occlude_wire_fb,
+ * (int)viewport_size[0], (int)viewport_size[1],
+ * tex, 2);
+ */
+
+ if (!e_data.wire_sh) {
+ e_data.wire_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+
+ if (!e_data.overlay_select_sh) {
+ e_data.overlay_select_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+
+ if (!e_data.overlay_cursor_sh) {
+ e_data.overlay_cursor_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+}
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void EDIT_TEXT_cache_init(void *vedata)
+{
+ EDIT_TEXT_PassList *psl = ((EDIT_TEXT_Data *)vedata)->psl;
+ EDIT_TEXT_StorageList *stl = ((EDIT_TEXT_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Text outline (fast drawing!) */
+ psl->wire_pass = DRW_pass_create(
+ "Font Wire",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE);
+ stl->g_data->wire_shgrp = DRW_shgroup_create(e_data.wire_sh, psl->wire_pass);
+
+ psl->overlay_select_pass = DRW_pass_create(
+ "Font Select",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH);
+ stl->g_data->overlay_select_shgrp = DRW_shgroup_create(e_data.overlay_select_sh, psl->overlay_select_pass);
+
+ psl->overlay_cursor_pass = DRW_pass_create(
+ "Font Cursor",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH);
+ stl->g_data->overlay_cursor_shgrp = DRW_shgroup_create(e_data.overlay_cursor_sh, psl->overlay_cursor_pass);
+ }
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void EDIT_TEXT_cache_populate(void *vedata, Object *ob)
+{
+ EDIT_TEXT_PassList *psl = ((EDIT_TEXT_Data *)vedata)->psl;
+ EDIT_TEXT_StorageList *stl = ((EDIT_TEXT_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ UNUSED_VARS(psl, stl);
+
+ if (ob->type == OB_FONT) {
+ if (ob == draw_ctx->object_edit) {
+ const Curve *cu = ob->data;
+ /* Get geometry cache */
+ struct Gwn_Batch *geom;
+
+ if (cu->flag & CU_FAST) {
+ geom = DRW_cache_text_edge_wire_get(ob);
+ if (geom) {
+ DRW_shgroup_call_add(stl->g_data->wire_shgrp, geom, ob->obmat);
+ }
+ }
+ else {
+ /* object mode draws */
+ }
+
+ geom = DRW_cache_text_select_overlay_get(ob);
+ if (geom) {
+ DRW_shgroup_call_add(stl->g_data->overlay_select_shgrp, geom, ob->obmat);
+ }
+
+ geom = DRW_cache_text_cursor_overlay_get(ob);
+ if (geom) {
+ DRW_shgroup_call_add(stl->g_data->overlay_cursor_shgrp, geom, ob->obmat);
+ }
+ }
+ }
+}
+
+/* Optional: Post-cache_populate callback */
+static void EDIT_TEXT_cache_finish(void *vedata)
+{
+ EDIT_TEXT_PassList *psl = ((EDIT_TEXT_Data *)vedata)->psl;
+ EDIT_TEXT_StorageList *stl = ((EDIT_TEXT_Data *)vedata)->stl;
+
+ /* Do something here! dependant on the objects gathered */
+ UNUSED_VARS(psl, stl);
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void EDIT_TEXT_draw_scene(void *vedata)
+{
+ EDIT_TEXT_PassList *psl = ((EDIT_TEXT_Data *)vedata)->psl;
+ EDIT_TEXT_FramebufferList *fbl = ((EDIT_TEXT_Data *)vedata)->fbl;
+
+ /* Default framebuffer and texture */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ UNUSED_VARS(fbl, dfbl, dtxl);
+
+ /* Show / hide entire passes, swap framebuffers ... whatever you fancy */
+ /*
+ * DRW_framebuffer_texture_detach(dtxl->depth);
+ * DRW_framebuffer_bind(fbl->custom_fb);
+ * DRW_draw_pass(psl->pass);
+ * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
+ * DRW_framebuffer_bind(dfbl->default_fb);
+ */
+
+ DRW_draw_pass(psl->wire_pass);
+
+ set_inverted_drawing(1);
+ DRW_draw_pass(psl->overlay_select_pass);
+ DRW_draw_pass(psl->overlay_cursor_pass);
+ set_inverted_drawing(0);
+
+ /* If you changed framebuffer, double check you rebind
+ * the default one with its textures attached before finishing */
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void EDIT_TEXT_engine_free(void)
+{
+ // DRW_SHADER_FREE_SAFE(custom_shader);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void EDIT_TEXT_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize EDIT_TEXT_data_size = DRW_VIEWPORT_DATA_SIZE(EDIT_TEXT_Data);
+
+DrawEngineType draw_engine_edit_text_type = {
+ NULL, NULL,
+ N_("EditTextMode"),
+ &EDIT_TEXT_data_size,
+ &EDIT_TEXT_engine_init,
+ &EDIT_TEXT_engine_free,
+ &EDIT_TEXT_cache_init,
+ &EDIT_TEXT_cache_populate,
+ &EDIT_TEXT_cache_finish,
+ NULL, /* draw_background but not needed by mode engines */
+ &EDIT_TEXT_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/object_mode.c b/source/blender/draw/modes/object_mode.c
new file mode 100644
index 00000000000..312928c57f6
--- /dev/null
+++ b/source/blender/draw/modes/object_mode.c
@@ -0,0 +1,2265 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/object_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_userdef_types.h"
+#include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meta_types.h"
+#include "DNA_object_force_types.h"
+#include "DNA_lightprobe_types.h"
+#include "DNA_particle_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_world_types.h"
+
+#include "BIF_gl.h"
+
+#include "BLI_string_utils.h"
+
+#include "BKE_anim.h"
+#include "BKE_camera.h"
+#include "BKE_curve.h"
+#include "BKE_global.h"
+#include "BKE_mball.h"
+#include "BKE_object.h"
+#include "BKE_particle.h"
+#include "BKE_image.h"
+#include "BKE_texture.h"
+
+#include "ED_view3d.h"
+
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "UI_resources.h"
+
+#include "draw_mode_engines.h"
+#include "draw_manager_text.h"
+#include "draw_common.h"
+
+#include "DEG_depsgraph_query.h"
+
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GPUTexture *globals_ramp; /* draw_common.c */
+extern GlobalsUboStorage ts;
+
+extern char datatoc_object_outline_prepass_frag_glsl[];
+extern char datatoc_object_outline_resolve_frag_glsl[];
+extern char datatoc_object_outline_detect_frag_glsl[];
+extern char datatoc_object_outline_expand_frag_glsl[];
+extern char datatoc_object_grid_frag_glsl[];
+extern char datatoc_object_grid_vert_glsl[];
+extern char datatoc_object_empty_image_frag_glsl[];
+extern char datatoc_object_empty_image_vert_glsl[];
+extern char datatoc_object_lightprobe_grid_vert_glsl[];
+extern char datatoc_object_particle_prim_vert_glsl[];
+extern char datatoc_object_particle_dot_vert_glsl[];
+extern char datatoc_object_particle_dot_frag_glsl[];
+extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_common_fxaa_lib_glsl[];
+extern char datatoc_gpu_shader_flat_color_frag_glsl[];
+extern char datatoc_gpu_shader_flat_id_frag_glsl[];
+extern char datatoc_common_fullscreen_vert_glsl[];
+extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
+
+/* *********** LISTS *********** */
+typedef struct OBJECT_PassList {
+ struct DRWPass *non_meshes;
+ struct DRWPass *ob_center;
+ struct DRWPass *outlines;
+ struct DRWPass *outlines_search;
+ struct DRWPass *outlines_expand;
+ struct DRWPass *outlines_bleed;
+ struct DRWPass *outlines_resolve;
+ struct DRWPass *grid;
+ struct DRWPass *bone_solid;
+ struct DRWPass *bone_outline;
+ struct DRWPass *bone_wire;
+ struct DRWPass *bone_envelope;
+ struct DRWPass *bone_axes;
+ struct DRWPass *particle;
+ struct DRWPass *lightprobes;
+ /* use for empty/background images */
+ struct DRWPass *reference_image;
+} OBJECT_PassList;
+
+typedef struct OBJECT_FramebufferList {
+ struct GPUFrameBuffer *outlines_fb;
+ struct GPUFrameBuffer *blur_fb;
+ struct GPUFrameBuffer *expand_fb;
+} OBJECT_FramebufferList;
+
+typedef struct OBJECT_StorageList {
+ struct OBJECT_PrivateData *g_data;
+} OBJECT_StorageList;
+
+typedef struct OBJECT_Data {
+ void *engine_type;
+ OBJECT_FramebufferList *fbl;
+ DRWViewportEmptyList *txl;
+ OBJECT_PassList *psl;
+ OBJECT_StorageList *stl;
+} OBJECT_Data;
+
+/* *********** STATIC *********** */
+
+typedef struct OBJECT_PrivateData {
+ /* Empties */
+ DRWShadingGroup *plain_axes;
+ DRWShadingGroup *cube;
+ DRWShadingGroup *circle;
+ DRWShadingGroup *sphere;
+ DRWShadingGroup *cone;
+ DRWShadingGroup *single_arrow;
+ DRWShadingGroup *single_arrow_line;
+ DRWShadingGroup *arrows;
+ DRWShadingGroup *axis_names;
+ /* GPUTexture -> EmptyImageShadingGroupData */
+ GHash *image_plane_map;
+
+ /* Force Field */
+ DRWShadingGroup *field_wind;
+ DRWShadingGroup *field_force;
+ DRWShadingGroup *field_vortex;
+ DRWShadingGroup *field_curve_sta;
+ DRWShadingGroup *field_curve_end;
+ DRWShadingGroup *field_tube_limit;
+ DRWShadingGroup *field_cone_limit;
+
+ /* Speaker */
+ DRWShadingGroup *speaker;
+
+ /* Probe */
+ DRWShadingGroup *probe_cube;
+ DRWShadingGroup *probe_planar;
+ DRWShadingGroup *probe_grid;
+
+ /* MetaBalls */
+ DRWShadingGroup *mball_handle;
+
+ /* Lamps */
+ DRWShadingGroup *lamp_center;
+ DRWShadingGroup *lamp_groundpoint;
+ DRWShadingGroup *lamp_groundline;
+ DRWShadingGroup *lamp_circle;
+ DRWShadingGroup *lamp_circle_shadow;
+ DRWShadingGroup *lamp_sunrays;
+ DRWShadingGroup *lamp_distance;
+ DRWShadingGroup *lamp_buflimit;
+ DRWShadingGroup *lamp_buflimit_points;
+ DRWShadingGroup *lamp_area;
+ DRWShadingGroup *lamp_hemi;
+ DRWShadingGroup *lamp_spot_cone;
+ DRWShadingGroup *lamp_spot_blend;
+ DRWShadingGroup *lamp_spot_pyramid;
+ DRWShadingGroup *lamp_spot_blend_rect;
+
+ /* Helpers */
+ DRWShadingGroup *relationship_lines;
+
+ /* Objects Centers */
+ DRWShadingGroup *center_active;
+ DRWShadingGroup *center_selected;
+ DRWShadingGroup *center_deselected;
+ DRWShadingGroup *center_selected_lib;
+ DRWShadingGroup *center_deselected_lib;
+
+ /* Camera */
+ DRWShadingGroup *camera;
+ DRWShadingGroup *camera_frame;
+ DRWShadingGroup *camera_tria;
+ DRWShadingGroup *camera_focus;
+ DRWShadingGroup *camera_clip;
+ DRWShadingGroup *camera_clip_points;
+ DRWShadingGroup *camera_mist;
+ DRWShadingGroup *camera_mist_points;
+
+ /* Outlines */
+ DRWShadingGroup *outlines_active;
+ DRWShadingGroup *outlines_select;
+ DRWShadingGroup *outlines_transform;
+
+ /* Lightprobes */
+ DRWShadingGroup *lightprobes_cube_select;
+ DRWShadingGroup *lightprobes_cube_active;
+ DRWShadingGroup *lightprobes_cube_transform;
+
+ DRWShadingGroup *lightprobes_planar_select;
+ DRWShadingGroup *lightprobes_planar_active;
+ DRWShadingGroup *lightprobes_planar_transform;
+
+ /* Wire */
+ DRWShadingGroup *wire;
+ DRWShadingGroup *wire_active;
+ DRWShadingGroup *wire_select;
+ DRWShadingGroup *wire_transform;
+
+ /* Points */
+ DRWShadingGroup *points;
+ DRWShadingGroup *points_active;
+ DRWShadingGroup *points_select;
+ DRWShadingGroup *points_transform;
+
+ /* Outlines id offset */
+ int id_ofs_active;
+ int id_ofs_select;
+ int id_ofs_transform;
+ int id_ofs_prb_active;
+ int id_ofs_prb_select;
+ int id_ofs_prb_transform;
+} OBJECT_PrivateData; /* Transient data */
+
+static struct {
+ /* Instance Data format */
+ struct Gwn_VertFormat *particle_format;
+ struct Gwn_VertFormat *empty_image_format;
+ struct Gwn_VertFormat *empty_image_wire_format;
+
+ /* fullscreen shaders */
+ GPUShader *outline_prepass_sh;
+ GPUShader *outline_resolve_sh;
+ GPUShader *outline_resolve_aa_sh;
+ GPUShader *outline_detect_sh;
+ GPUShader *outline_fade_sh;
+
+ /* regular shaders */
+ GPUShader *object_empty_image_sh;
+ GPUShader *object_empty_image_wire_sh;
+ GPUShader *grid_sh;
+ GPUShader *part_dot_sh;
+ GPUShader *part_prim_sh;
+ GPUShader *part_axis_sh;
+ GPUShader *lightprobe_grid_sh;
+ float camera_pos[3];
+ float screenvecs[3][4];
+ float grid_settings[5];
+ int grid_flag;
+ float grid_normal[3];
+ float grid_axes[3];
+ int zpos_flag;
+ int zneg_flag;
+ float zplane_normal[3];
+ float zplane_axes[3];
+ float inv_viewport_size[2];
+ bool draw_grid;
+ /* Temp buffer textures */
+ struct GPUTexture *outlines_depth_tx;
+ struct GPUTexture *outlines_id_tx;
+ struct GPUTexture *outlines_color_tx;
+ struct GPUTexture *outlines_blur_tx;
+} e_data = {NULL}; /* Engine data */
+
+
+enum {
+ SHOW_AXIS_X = (1 << 0),
+ SHOW_AXIS_Y = (1 << 1),
+ SHOW_AXIS_Z = (1 << 2),
+ SHOW_GRID = (1 << 3),
+ PLANE_XY = (1 << 4),
+ PLANE_XZ = (1 << 5),
+ PLANE_YZ = (1 << 6),
+ CLIP_ZPOS = (1 << 7),
+ CLIP_ZNEG = (1 << 8),
+};
+
+/* *********** FUNCTIONS *********** */
+
+static void OBJECT_engine_init(void *vedata)
+{
+ OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl;
+
+ const float *viewport_size = DRW_viewport_size_get();
+ const int size[2] = {(int)viewport_size[0], (int)viewport_size[1]};
+
+ if (DRW_state_is_fbo()) {
+ e_data.outlines_depth_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_DEPTH_COMPONENT24,
+ &draw_engine_object_type);
+ /* XXX TODO GPU_R16UI can overflow, it would cause no harm
+ * (only bad colored or missing outlines) but we should
+ * use 32bits only if the scene have that many objects */
+ e_data.outlines_id_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_R16UI,
+ &draw_engine_object_type);
+
+ GPU_framebuffer_ensure_config(&fbl->outlines_fb, {
+ GPU_ATTACHMENT_TEXTURE(e_data.outlines_depth_tx),
+ GPU_ATTACHMENT_TEXTURE(e_data.outlines_id_tx)
+ });
+
+ e_data.outlines_color_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8,
+ &draw_engine_object_type);
+
+ GPU_framebuffer_ensure_config(&fbl->expand_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(e_data.outlines_color_tx)
+ });
+
+ e_data.outlines_blur_tx = DRW_texture_pool_query_2D(size[0], size[1], GPU_RGBA8,
+ &draw_engine_object_type);
+
+ GPU_framebuffer_ensure_config(&fbl->blur_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(e_data.outlines_blur_tx)
+ });
+ }
+
+ /* Shaders */
+ if (!e_data.outline_resolve_sh) {
+ /* Outline */
+ e_data.outline_prepass_sh = DRW_shader_create_3D(datatoc_object_outline_prepass_frag_glsl, NULL);
+
+ e_data.outline_resolve_sh = DRW_shader_create_fullscreen(datatoc_object_outline_resolve_frag_glsl, NULL);
+
+ e_data.outline_resolve_aa_sh = DRW_shader_create_with_lib(
+ datatoc_common_fullscreen_vert_glsl, NULL,
+ datatoc_object_outline_resolve_frag_glsl,
+ datatoc_common_fxaa_lib_glsl,
+ "#define FXAA_ALPHA\n"
+ "#define USE_FXAA\n");
+
+ e_data.outline_detect_sh = DRW_shader_create_with_lib(
+ datatoc_common_fullscreen_vert_glsl, NULL,
+ datatoc_object_outline_detect_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#extension GL_ARB_texture_gather : enable\n");
+
+ e_data.outline_fade_sh = DRW_shader_create_fullscreen(datatoc_object_outline_expand_frag_glsl, NULL);
+
+ /* Empty images */
+ e_data.object_empty_image_sh = DRW_shader_create_with_lib(
+ datatoc_object_empty_image_vert_glsl, NULL,
+ datatoc_object_empty_image_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+
+ e_data.object_empty_image_wire_sh = DRW_shader_create_with_lib(
+ datatoc_object_empty_image_vert_glsl, NULL,
+ datatoc_object_empty_image_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define USE_WIRE\n");
+
+ /* Grid */
+ e_data.grid_sh = DRW_shader_create_with_lib(
+ datatoc_object_grid_vert_glsl, NULL,
+ datatoc_object_grid_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+
+ /* Particles */
+ e_data.part_prim_sh = DRW_shader_create(
+ datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl, NULL);
+
+ e_data.part_axis_sh = DRW_shader_create(
+ datatoc_object_particle_prim_vert_glsl, NULL, datatoc_gpu_shader_flat_color_frag_glsl,
+ "#define USE_AXIS\n");
+
+ e_data.part_dot_sh = DRW_shader_create(
+ datatoc_object_particle_dot_vert_glsl, NULL, datatoc_object_particle_dot_frag_glsl, NULL);
+
+ /* Lightprobes */
+ e_data.lightprobe_grid_sh = DRW_shader_create(
+ datatoc_object_lightprobe_grid_vert_glsl, NULL, datatoc_gpu_shader_flat_id_frag_glsl, NULL);
+ }
+
+ {
+ /* Grid precompute */
+ float invviewmat[4][4], invwinmat[4][4];
+ float viewmat[4][4], winmat[4][4];
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ Scene *scene = draw_ctx->scene;
+ RegionView3D *rv3d = draw_ctx->rv3d;
+ float grid_scale = ED_view3d_grid_scale(scene, v3d, NULL);
+ float grid_res;
+
+ const bool show_axis_x = (v3d->gridflag & V3D_SHOW_X) != 0;
+ const bool show_axis_y = (v3d->gridflag & V3D_SHOW_Y) != 0;
+ const bool show_axis_z = (v3d->gridflag & V3D_SHOW_Z) != 0;
+ const bool show_floor = (v3d->gridflag & V3D_SHOW_FLOOR) != 0;
+ e_data.draw_grid = show_axis_x || show_axis_y || show_axis_z || show_floor;
+
+ DRW_viewport_matrix_get(winmat, DRW_MAT_WIN);
+ DRW_viewport_matrix_get(viewmat, DRW_MAT_VIEW);
+ DRW_viewport_matrix_get(invwinmat, DRW_MAT_WININV);
+ DRW_viewport_matrix_get(invviewmat, DRW_MAT_VIEWINV);
+
+ /* Setup camera pos */
+ copy_v3_v3(e_data.camera_pos, invviewmat[3]);
+
+ /* if perps */
+ if (winmat[3][3] == 0.0f) {
+ float fov;
+ float viewvecs[2][4] = {
+ {1.0f, -1.0f, -1.0f, 1.0f},
+ {-1.0f, 1.0f, -1.0f, 1.0f}
+ };
+
+ /* convert the view vectors to view space */
+ for (int i = 0; i < 2; i++) {
+ mul_m4_v4(invwinmat, viewvecs[i]);
+ mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]); /* perspective divide */
+ }
+
+ fov = angle_v3v3(viewvecs[0], viewvecs[1]) / 2.0f;
+ grid_res = fabsf(tanf(fov)) / grid_scale;
+
+ e_data.grid_flag = (1 << 4); /* XY plane */
+ if (show_axis_x)
+ e_data.grid_flag |= SHOW_AXIS_X;
+ if (show_axis_y)
+ e_data.grid_flag |= SHOW_AXIS_Y;
+ if (show_floor)
+ e_data.grid_flag |= SHOW_GRID;
+
+ }
+ else {
+ float viewdist = 1.0f / max_ff(fabsf(winmat[0][0]), fabsf(winmat[1][1]));
+ grid_res = viewdist / grid_scale;
+
+ if (ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT)) {
+ e_data.grid_flag = PLANE_YZ;
+ e_data.grid_flag |= SHOW_AXIS_Y;
+ e_data.grid_flag |= SHOW_AXIS_Z;
+ e_data.grid_flag |= SHOW_GRID;
+ }
+ else if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM)) {
+ e_data.grid_flag = PLANE_XY;
+ e_data.grid_flag |= SHOW_AXIS_X;
+ e_data.grid_flag |= SHOW_AXIS_Y;
+ e_data.grid_flag |= SHOW_GRID;
+ }
+ else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK)) {
+ e_data.grid_flag = PLANE_XZ;
+ e_data.grid_flag |= SHOW_AXIS_X;
+ e_data.grid_flag |= SHOW_AXIS_Z;
+ e_data.grid_flag |= SHOW_GRID;
+ }
+ else { /* RV3D_VIEW_USER */
+ e_data.grid_flag = PLANE_XY;
+ if (show_axis_x)
+ e_data.grid_flag |= SHOW_AXIS_X;
+ if (show_axis_y)
+ e_data.grid_flag |= SHOW_AXIS_Y;
+ if (show_floor)
+ e_data.grid_flag |= SHOW_GRID;
+ }
+ }
+
+ e_data.grid_normal[0] = (float)((e_data.grid_flag & PLANE_YZ) != 0);
+ e_data.grid_normal[1] = (float)((e_data.grid_flag & PLANE_XZ) != 0);
+ e_data.grid_normal[2] = (float)((e_data.grid_flag & PLANE_XY) != 0);
+
+ e_data.grid_axes[0] = (float)((e_data.grid_flag & (PLANE_XZ | PLANE_XY)) != 0);
+ e_data.grid_axes[1] = (float)((e_data.grid_flag & (PLANE_YZ | PLANE_XY)) != 0);
+ e_data.grid_axes[2] = (float)((e_data.grid_flag & (PLANE_YZ | PLANE_XZ)) != 0);
+
+ /* Vectors to recover pixel world position. Fix grid precision issue. */
+ /* Using pixel at z = 0.0f in ndc space : gives average precision between
+ * near and far plane. Note that it might not be the best choice. */
+ copy_v4_fl4(e_data.screenvecs[0], 1.0f, -1.0f, 0.0f, 1.0f);
+ copy_v4_fl4(e_data.screenvecs[1], -1.0f, 1.0f, 0.0f, 1.0f);
+ copy_v4_fl4(e_data.screenvecs[2], -1.0f, -1.0f, 0.0f, 1.0f);
+
+ for (int i = 0; i < 3; i++) {
+ /* Doing 2 steps to recover world position of the corners of the frustum.
+ * Using the inverse perspective matrix is giving very low precision output. */
+ mul_m4_v4(invwinmat, e_data.screenvecs[i]);
+ e_data.screenvecs[i][0] /= e_data.screenvecs[i][3]; /* perspective divide */
+ e_data.screenvecs[i][1] /= e_data.screenvecs[i][3]; /* perspective divide */
+ e_data.screenvecs[i][2] /= e_data.screenvecs[i][3]; /* perspective divide */
+ e_data.screenvecs[i][3] = 1.0f;
+ /* main instability come from this one */
+ /* TODO : to make things even more stable, don't use
+ * invviewmat and derive vectors from camera properties */
+ mul_m4_v4(invviewmat, e_data.screenvecs[i]);
+ }
+
+ sub_v3_v3(e_data.screenvecs[0], e_data.screenvecs[2]);
+ sub_v3_v3(e_data.screenvecs[1], e_data.screenvecs[2]);
+
+ /* Z axis if needed */
+ if (((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) && show_axis_z) {
+ e_data.zpos_flag = SHOW_AXIS_Z;
+
+ float zvec[4] = {0.0f, 0.0f, -1.0f, 0.0f};
+ mul_m4_v4(invviewmat, zvec);
+
+ /* z axis : chose the most facing plane */
+ if (fabsf(zvec[0]) < fabsf(zvec[1])) {
+ e_data.zpos_flag |= PLANE_XZ;
+ }
+ else {
+ e_data.zpos_flag |= PLANE_YZ;
+ }
+
+ e_data.zneg_flag = e_data.zpos_flag;
+
+ /* Persp : If camera is below floor plane, we switch clipping
+ * Ortho : If eye vector is looking up, we switch clipping */
+ if (((winmat[3][3] == 0.0f) && (e_data.camera_pos[2] > 0.0f)) ||
+ ((winmat[3][3] != 0.0f) && (zvec[2] < 0.0f)))
+ {
+ e_data.zpos_flag |= CLIP_ZPOS;
+ e_data.zneg_flag |= CLIP_ZNEG;
+ }
+ else {
+ e_data.zpos_flag |= CLIP_ZNEG;
+ e_data.zneg_flag |= CLIP_ZPOS;
+ }
+
+ e_data.zplane_normal[0] = (float)((e_data.zpos_flag & PLANE_YZ) != 0);
+ e_data.zplane_normal[1] = (float)((e_data.zpos_flag & PLANE_XZ) != 0);
+ e_data.zplane_normal[2] = (float)((e_data.zpos_flag & PLANE_XY) != 0);
+
+ e_data.zplane_axes[0] = (float)((e_data.zpos_flag & (PLANE_XZ | PLANE_XY)) != 0);
+ e_data.zplane_axes[1] = (float)((e_data.zpos_flag & (PLANE_YZ | PLANE_XY)) != 0);
+ e_data.zplane_axes[2] = (float)((e_data.zpos_flag & (PLANE_YZ | PLANE_XZ)) != 0);
+
+ }
+ else {
+ e_data.zneg_flag = e_data.zpos_flag = CLIP_ZNEG | CLIP_ZPOS;
+ }
+
+ float dist;
+ if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
+ Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera);
+ dist = ((Camera *)camera_object)->clipend;
+ }
+ else {
+ dist = v3d->far;
+ }
+
+ e_data.grid_settings[0] = dist / 2.0f; /* gridDistance */
+ e_data.grid_settings[1] = grid_res; /* gridResolution */
+ e_data.grid_settings[2] = grid_scale; /* gridScale */
+ e_data.grid_settings[3] = v3d->gridsubdiv; /* gridSubdiv */
+ e_data.grid_settings[4] = (v3d->gridsubdiv > 1) ? 1.0f / logf(v3d->gridsubdiv) : 0.0f; /* 1/log(gridSubdiv) */
+ }
+
+ copy_v2_v2(e_data.inv_viewport_size, DRW_viewport_size_get());
+ invert_v2(e_data.inv_viewport_size);
+}
+
+static void OBJECT_engine_free(void)
+{
+ MEM_SAFE_FREE(e_data.particle_format);
+ MEM_SAFE_FREE(e_data.empty_image_format);
+ MEM_SAFE_FREE(e_data.empty_image_wire_format);
+ DRW_SHADER_FREE_SAFE(e_data.outline_prepass_sh);
+ DRW_SHADER_FREE_SAFE(e_data.outline_resolve_sh);
+ DRW_SHADER_FREE_SAFE(e_data.outline_resolve_aa_sh);
+ DRW_SHADER_FREE_SAFE(e_data.outline_detect_sh);
+ DRW_SHADER_FREE_SAFE(e_data.outline_fade_sh);
+ DRW_SHADER_FREE_SAFE(e_data.object_empty_image_sh);
+ DRW_SHADER_FREE_SAFE(e_data.object_empty_image_wire_sh);
+ DRW_SHADER_FREE_SAFE(e_data.grid_sh);
+ DRW_SHADER_FREE_SAFE(e_data.part_prim_sh);
+ DRW_SHADER_FREE_SAFE(e_data.part_axis_sh);
+ DRW_SHADER_FREE_SAFE(e_data.part_dot_sh);
+ DRW_SHADER_FREE_SAFE(e_data.lightprobe_grid_sh);
+}
+
+static DRWShadingGroup *shgroup_outline(DRWPass *pass, const int *ofs, GPUShader *sh)
+{
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
+ DRW_shgroup_uniform_int(grp, "baseId", ofs, 1);
+
+ return grp;
+}
+
+/* currently same as 'shgroup_outline', new function to avoid confustion */
+static DRWShadingGroup *shgroup_wire(DRWPass *pass, const float col[4], GPUShader *sh)
+{
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
+ DRW_shgroup_uniform_vec4(grp, "color", col, 1);
+
+ return grp;
+}
+
+/* currently same as 'shgroup_outline', new function to avoid confustion */
+static DRWShadingGroup *shgroup_points(DRWPass *pass, const float col[4], GPUShader *sh)
+{
+ DRWShadingGroup *grp = DRW_shgroup_create(sh, pass);
+ DRW_shgroup_uniform_vec4(grp, "color", col, 1);
+
+ return grp;
+}
+
+static int *shgroup_theme_id_to_probe_outline_counter(
+ OBJECT_StorageList *stl, int theme_id)
+{
+ switch (theme_id) {
+ case TH_ACTIVE:
+ return &stl->g_data->id_ofs_prb_active;
+ case TH_SELECT:
+ return &stl->g_data->id_ofs_prb_select;
+ case TH_TRANSFORM:
+ default:
+ return &stl->g_data->id_ofs_prb_transform;
+ }
+}
+
+static int *shgroup_theme_id_to_outline_counter(
+ OBJECT_StorageList *stl, int theme_id)
+{
+ switch (theme_id) {
+ case TH_ACTIVE:
+ return &stl->g_data->id_ofs_active;
+ case TH_SELECT:
+ return &stl->g_data->id_ofs_select;
+ case TH_TRANSFORM:
+ default:
+ return &stl->g_data->id_ofs_transform;
+ }
+}
+
+static DRWShadingGroup *shgroup_theme_id_to_probe_planar_outline_shgrp(
+ OBJECT_StorageList *stl, int theme_id)
+{
+ /* does not increment counter */
+ switch (theme_id) {
+ case TH_ACTIVE:
+ return stl->g_data->lightprobes_planar_active;
+ case TH_SELECT:
+ return stl->g_data->lightprobes_planar_select;
+ case TH_TRANSFORM:
+ default:
+ return stl->g_data->lightprobes_planar_transform;
+ }
+}
+
+static DRWShadingGroup *shgroup_theme_id_to_probe_cube_outline_shgrp(
+ OBJECT_StorageList *stl, int theme_id)
+{
+ /* does not increment counter */
+ switch (theme_id) {
+ case TH_ACTIVE:
+ return stl->g_data->lightprobes_cube_active;
+ case TH_SELECT:
+ return stl->g_data->lightprobes_cube_select;
+ case TH_TRANSFORM:
+ default:
+ return stl->g_data->lightprobes_cube_transform;
+ }
+}
+
+static DRWShadingGroup *shgroup_theme_id_to_outline_or(
+ OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
+{
+ int *counter = shgroup_theme_id_to_outline_counter(stl, theme_id);
+ *counter += 1;
+
+ switch (theme_id) {
+ case TH_ACTIVE:
+ return stl->g_data->outlines_active;
+ case TH_SELECT:
+ return stl->g_data->outlines_select;
+ case TH_TRANSFORM:
+ return stl->g_data->outlines_transform;
+ default:
+ return fallback;
+ }
+}
+
+static DRWShadingGroup *shgroup_theme_id_to_wire_or(
+ OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
+{
+ switch (theme_id) {
+ case TH_ACTIVE:
+ return stl->g_data->wire_active;
+ case TH_SELECT:
+ return stl->g_data->wire_select;
+ case TH_TRANSFORM:
+ return stl->g_data->wire_transform;
+ default:
+ return fallback;
+ }
+}
+
+static DRWShadingGroup *shgroup_theme_id_to_point_or(
+ OBJECT_StorageList *stl, int theme_id, DRWShadingGroup *fallback)
+{
+ switch (theme_id) {
+ case TH_ACTIVE:
+ return stl->g_data->points_active;
+ case TH_SELECT:
+ return stl->g_data->points_select;
+ case TH_TRANSFORM:
+ return stl->g_data->points_transform;
+ default:
+ return fallback;
+ }
+}
+
+static void image_calc_aspect(Image *ima, ImageUser *iuser, float r_image_aspect[2])
+{
+ float ima_x, ima_y;
+ if (ima) {
+ int w, h;
+ BKE_image_get_size(ima, iuser, &w, &h);
+ ima_x = w;
+ ima_y = h;
+ }
+ else {
+ /* if no image, make it a 1x1 empty square, honor scale & offset */
+ ima_x = ima_y = 1.0f;
+ }
+ /* Get the image aspect even if the buffer is invalid */
+ float sca_x = 1.0f, sca_y = 1.0f;
+ if (ima) {
+ if (ima->aspx > ima->aspy) {
+ sca_y = ima->aspy / ima->aspx;
+ }
+ else if (ima->aspx < ima->aspy) {
+ sca_x = ima->aspx / ima->aspy;
+ }
+ }
+
+ const float scale_x_inv = ima_x * sca_x;
+ const float scale_y_inv = ima_y * sca_y;
+ if (scale_x_inv > scale_y_inv) {
+ r_image_aspect[0] = 1.0f;
+ r_image_aspect[1] = scale_y_inv / scale_x_inv;
+ }
+ else {
+ r_image_aspect[0] = scale_x_inv / scale_y_inv;
+ r_image_aspect[1] = 1.0f;
+ }
+}
+
+/* per-image shading groups for image-type empty objects */
+struct EmptyImageShadingGroupData {
+ DRWShadingGroup *shgrp_image;
+ DRWShadingGroup *shgrp_wire;
+ float image_aspect[2];
+};
+
+static void DRW_shgroup_empty_image(
+ OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, const float color[3])
+{
+ /* TODO: 'StereoViews', see draw_empty_image. */
+
+ if (stl->g_data->image_plane_map == NULL) {
+ stl->g_data->image_plane_map = BLI_ghash_ptr_new(__func__);
+ }
+
+ struct EmptyImageShadingGroupData *empty_image_data;
+
+ GPUTexture *tex = ob->data ?
+ GPU_texture_from_blender(ob->data, ob->iuser, GL_TEXTURE_2D, false, false, false) : NULL;
+ void **val_p;
+
+ /* Create on demand, 'tex' may be NULL. */
+ if (BLI_ghash_ensure_p(stl->g_data->image_plane_map, tex, &val_p)) {
+ empty_image_data = *val_p;
+ }
+ else {
+ empty_image_data = MEM_mallocN(sizeof(*empty_image_data), __func__);
+
+ image_calc_aspect(ob->data, ob->iuser, empty_image_data->image_aspect);
+
+ if (tex) {
+ DRW_shgroup_instance_format(e_data.empty_image_format, {
+ {"objectColor", DRW_ATTRIB_FLOAT, 4},
+ {"size", DRW_ATTRIB_FLOAT, 1},
+ {"offset", DRW_ATTRIB_FLOAT, 2},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16},
+ });
+
+ struct Gwn_Batch *geom = DRW_cache_image_plane_get();
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(
+ e_data.object_empty_image_sh, psl->non_meshes, geom, e_data.empty_image_format);
+ DRW_shgroup_uniform_texture(grp, "image", tex);
+ DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
+
+ empty_image_data->shgrp_image = grp;
+ }
+ else {
+ empty_image_data->shgrp_image = NULL;
+ }
+
+ {
+ DRW_shgroup_instance_format(e_data.empty_image_wire_format, {
+ {"objectColor", DRW_ATTRIB_FLOAT, 4},
+ {"size", DRW_ATTRIB_FLOAT, 1},
+ {"offset", DRW_ATTRIB_FLOAT, 2},
+ {"InstanceModelMatrix", DRW_ATTRIB_FLOAT, 16}
+ });
+
+ struct Gwn_Batch *geom = DRW_cache_image_plane_wire_get();
+ DRWShadingGroup *grp = DRW_shgroup_instance_create(
+ e_data.object_empty_image_wire_sh, psl->non_meshes, geom, e_data.empty_image_wire_format);
+ DRW_shgroup_uniform_vec2(grp, "aspect", empty_image_data->image_aspect, 1);
+
+ empty_image_data->shgrp_wire = grp;
+ }
+
+ *val_p = empty_image_data;
+ }
+
+ if (empty_image_data->shgrp_image != NULL) {
+ DRW_shgroup_call_dynamic_add(
+ empty_image_data->shgrp_image,
+ ob->col,
+ &ob->empty_drawsize,
+ ob->ima_ofs,
+ ob->obmat);
+ }
+
+ DRW_shgroup_call_dynamic_add(
+ empty_image_data->shgrp_wire,
+ color,
+ &ob->empty_drawsize,
+ ob->ima_ofs,
+ ob->obmat);
+}
+
+static void OBJECT_cache_init(void *vedata)
+{
+ OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
+ OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ OBJECT_PrivateData *g_data;
+ /* TODO : use dpi setting for enabling the second pass */
+ const bool do_outline_expand = false;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ g_data = stl->g_data;
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE;
+ psl->outlines = DRW_pass_create("Outlines Depth Pass", state);
+
+ GPUShader *sh = e_data.outline_prepass_sh;
+
+ /* Select */
+ g_data->outlines_select = shgroup_outline(psl->outlines, &g_data->id_ofs_select, sh);
+
+ /* Transform */
+ g_data->outlines_transform = shgroup_outline(psl->outlines, &g_data->id_ofs_transform, sh);
+
+ /* Active */
+ g_data->outlines_active = shgroup_outline(psl->outlines, &g_data->id_ofs_active, sh);
+
+ g_data->id_ofs_select = 0;
+ g_data->id_ofs_active = 0;
+ g_data->id_ofs_transform = 0;
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ DRWPass *pass = psl->lightprobes = DRW_pass_create("Object Probe Pass", state);
+ struct Gwn_Batch *sphere = DRW_cache_sphere_get();
+ struct Gwn_Batch *quad = DRW_cache_quad_get();
+
+ /* Cubemap */
+ g_data->lightprobes_cube_select = shgroup_instance_outline(pass, sphere, &g_data->id_ofs_prb_select);
+ g_data->lightprobes_cube_active = shgroup_instance_outline(pass, sphere, &g_data->id_ofs_prb_active);
+ g_data->lightprobes_cube_transform = shgroup_instance_outline(pass, sphere, &g_data->id_ofs_prb_transform);
+
+ /* Planar */
+ g_data->lightprobes_planar_select = shgroup_instance_outline(pass, quad, &g_data->id_ofs_prb_select);
+ g_data->lightprobes_planar_active = shgroup_instance_outline(pass, quad, &g_data->id_ofs_prb_active);
+ g_data->lightprobes_planar_transform = shgroup_instance_outline(pass, quad, &g_data->id_ofs_prb_transform);
+
+ g_data->id_ofs_prb_select = 0;
+ g_data->id_ofs_prb_active = 0;
+ g_data->id_ofs_prb_transform = 0;
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR;
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+ static float alphaOcclu = 0.35f;
+ /* Reminder : bool uniforms need to be 4 bytes. */
+ static const int bTrue = true;
+ static const int bFalse = false;
+
+ psl->outlines_search = DRW_pass_create("Outlines Detect Pass", state);
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.outline_detect_sh, psl->outlines_search);
+ DRW_shgroup_uniform_texture_ref(grp, "outlineId", &e_data.outlines_id_tx);
+ DRW_shgroup_uniform_texture_ref(grp, "outlineDepth", &e_data.outlines_depth_tx);
+ DRW_shgroup_uniform_texture_ref(grp, "sceneDepth", &dtxl->depth);
+ DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_float(grp, "alphaOcclu", &alphaOcclu, 1);
+ DRW_shgroup_uniform_int(grp, "idOffsets", &stl->g_data->id_ofs_active, 3);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ psl->outlines_expand = DRW_pass_create("Outlines Expand Pass", state);
+
+ grp = DRW_shgroup_create(e_data.outline_fade_sh, psl->outlines_expand);
+ DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &e_data.outlines_blur_tx);
+ DRW_shgroup_uniform_bool(grp, "doExpand", (do_outline_expand) ? &bTrue : &bFalse, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+
+ psl->outlines_bleed = DRW_pass_create("Outlines Bleed Pass", state);
+
+ if (do_outline_expand) {
+ grp = DRW_shgroup_create(e_data.outline_fade_sh, psl->outlines_bleed);
+ DRW_shgroup_uniform_texture_ref(grp, "outlineColor", &e_data.outlines_color_tx);
+ DRW_shgroup_uniform_bool(grp, "doExpand", &bFalse, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND;
+ psl->outlines_resolve = DRW_pass_create("Outlines Resolve Pass", state);
+
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+ GPUTexture **outline_tx = (do_outline_expand) ? &e_data.outlines_blur_tx : &e_data.outlines_color_tx;
+
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.outline_resolve_aa_sh, psl->outlines_resolve);
+ DRW_shgroup_uniform_texture_ref(grp, "outlineBluredColor", outline_tx);
+ DRW_shgroup_uniform_vec2(grp, "rcpDimensions", e_data.inv_viewport_size, 1);
+ DRW_shgroup_call_add(grp, quad, NULL);
+ }
+
+ {
+ /* Grid pass */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND;
+ psl->grid = DRW_pass_create("Infinite Grid Pass", state);
+
+ struct Gwn_Batch *quad = DRW_cache_fullscreen_quad_get();
+ static float mat[4][4];
+ unit_m4(mat);
+
+ /* Create 3 quads to render ordered transparency Z axis */
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
+ DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zneg_flag, 1);
+ DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.zplane_normal, 1);
+ DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1);
+ DRW_shgroup_uniform_vec3(grp, "cameraPos", e_data.camera_pos, 1);
+ DRW_shgroup_uniform_vec4(grp, "screenvecs[0]", e_data.screenvecs[0], 3);
+ DRW_shgroup_uniform_vec4(grp, "gridSettings", e_data.grid_settings, 1);
+ DRW_shgroup_uniform_float(grp, "gridOneOverLogSubdiv", &e_data.grid_settings[4], 1);
+ DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_vec2(grp, "viewportSize", DRW_viewport_size_get(), 1);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_call_add(grp, quad, mat);
+
+ grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
+ DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.grid_flag, 1);
+ DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.grid_normal, 1);
+ DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.grid_axes, 1);
+ DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_call_add(grp, quad, mat);
+
+ grp = DRW_shgroup_create(e_data.grid_sh, psl->grid);
+ DRW_shgroup_uniform_int(grp, "gridFlag", &e_data.zpos_flag, 1);
+ DRW_shgroup_uniform_vec3(grp, "planeNormal", e_data.zplane_normal, 1);
+ DRW_shgroup_uniform_vec3(grp, "planeAxes", e_data.zplane_axes, 1);
+ DRW_shgroup_uniform_block(grp, "globalsBlock", globals_ubo);
+ DRW_shgroup_uniform_texture_ref(grp, "depthBuffer", &dtxl->depth);
+ DRW_shgroup_call_add(grp, quad, mat);
+ }
+
+ {
+ /* Solid bones */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
+ psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
+ psl->bone_outline = DRW_pass_create("Bone Outline Pass", state);
+ }
+
+ {
+ /* Wire bones */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND;
+ psl->bone_wire = DRW_pass_create("Bone Wire Pass", state);
+ }
+
+ {
+ /* distance outline around envelope bones */
+ DRWState state = DRW_STATE_ADDITIVE | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_FRONT;
+ psl->bone_envelope = DRW_pass_create("Bone Envelope Outline Pass", state);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_WIRE;
+ psl->bone_axes = DRW_pass_create("Bone Axes Pass", state);
+ }
+
+ {
+ /* Non Meshes Pass (Camera, empties, lamps ...) */
+ struct Gwn_Batch *geom;
+
+ DRWState state =
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH |
+ DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_POINT;
+ state |= DRW_STATE_WIRE;
+ psl->non_meshes = DRW_pass_create("Non Meshes Pass", state);
+
+ /* Empties */
+ geom = DRW_cache_plain_axes_get();
+ stl->g_data->plain_axes = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_cube_get();
+ stl->g_data->cube = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_circle_get();
+ stl->g_data->circle = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_empty_sphere_get();
+ stl->g_data->sphere = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_empty_cone_get();
+ stl->g_data->cone = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_single_arrow_get();
+ stl->g_data->single_arrow = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_single_line_get();
+ stl->g_data->single_arrow_line = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_arrows_get();
+ stl->g_data->arrows = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_axis_names_get();
+ stl->g_data->axis_names = shgroup_instance_axis_names(psl->non_meshes, geom);
+
+ /* initialize on first use */
+ stl->g_data->image_plane_map = NULL;
+
+ /* Force Field */
+ geom = DRW_cache_field_wind_get();
+ stl->g_data->field_wind = shgroup_instance_scaled(psl->non_meshes, geom);
+
+ geom = DRW_cache_field_force_get();
+ stl->g_data->field_force = shgroup_instance_screen_aligned(psl->non_meshes, geom);
+
+ geom = DRW_cache_field_vortex_get();
+ stl->g_data->field_vortex = shgroup_instance_scaled(psl->non_meshes, geom);
+
+ geom = DRW_cache_screenspace_circle_get();
+ stl->g_data->field_curve_sta = shgroup_instance_screen_aligned(psl->non_meshes, geom);
+
+ /* Speaker */
+ geom = DRW_cache_speaker_get();
+ stl->g_data->speaker = shgroup_instance(psl->non_meshes, geom);
+
+ /* Probe */
+ static float probeSize = 14.0f;
+ geom = DRW_cache_lightprobe_cube_get();
+ stl->g_data->probe_cube = shgroup_instance_screenspace(psl->non_meshes, geom, &probeSize);
+
+ geom = DRW_cache_lightprobe_grid_get();
+ stl->g_data->probe_grid = shgroup_instance_screenspace(psl->non_meshes, geom, &probeSize);
+
+ static float probePlanarSize = 20.0f;
+ geom = DRW_cache_lightprobe_planar_get();
+ stl->g_data->probe_planar = shgroup_instance_screenspace(psl->non_meshes, geom, &probePlanarSize);
+
+ /* Camera */
+ geom = DRW_cache_camera_get();
+ stl->g_data->camera = shgroup_camera_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_camera_frame_get();
+ stl->g_data->camera_frame = shgroup_camera_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_camera_tria_get();
+ stl->g_data->camera_tria = shgroup_camera_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_plain_axes_get();
+ stl->g_data->camera_focus = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_single_line_get();
+ stl->g_data->camera_clip = shgroup_distance_lines_instance(psl->non_meshes, geom);
+ stl->g_data->camera_mist = shgroup_distance_lines_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_single_line_endpoints_get();
+ stl->g_data->camera_clip_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
+ stl->g_data->camera_mist_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
+
+ }
+
+ {
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ /* Unselected */
+ stl->g_data->wire = shgroup_wire(psl->non_meshes, ts.colorWire, sh);
+
+ /* Select */
+ stl->g_data->wire_select = shgroup_wire(psl->non_meshes, ts.colorSelect, sh);
+
+ /* Transform */
+ stl->g_data->wire_transform = shgroup_wire(psl->non_meshes, ts.colorTransform, sh);
+
+ /* Active */
+ stl->g_data->wire_active = shgroup_wire(psl->non_meshes, ts.colorActive, sh);
+ }
+
+
+ {
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR);
+
+ /* Unselected */
+ stl->g_data->points = shgroup_points(psl->non_meshes, ts.colorWire, sh);
+
+ /* Select */
+ stl->g_data->points_select = shgroup_points(psl->non_meshes, ts.colorSelect, sh);
+
+ /* Transform */
+ stl->g_data->points_transform = shgroup_points(psl->non_meshes, ts.colorTransform, sh);
+
+ /* Active */
+ stl->g_data->points_active = shgroup_points(psl->non_meshes, ts.colorActive, sh);
+ }
+
+ {
+ /* Metaballs Handles */
+ stl->g_data->mball_handle = shgroup_instance_mball_handles(psl->non_meshes);
+ }
+
+ {
+ /* Lamps */
+ /* TODO
+ * for now we create multiple times the same VBO with only lamp center coordinates
+ * but ideally we would only create it once */
+ struct Gwn_Batch *geom;
+
+ /* start with buflimit because we don't want stipples */
+ geom = DRW_cache_single_line_get();
+ stl->g_data->lamp_buflimit = shgroup_distance_lines_instance(psl->non_meshes, geom);
+
+ stl->g_data->lamp_center = shgroup_dynpoints_uniform_color(psl->non_meshes, ts.colorLampNoAlpha, &ts.sizeLampCenter);
+
+ geom = DRW_cache_lamp_get();
+ stl->g_data->lamp_circle = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircle);
+ geom = DRW_cache_lamp_shadows_get();
+ stl->g_data->lamp_circle_shadow = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircleShadow);
+
+ geom = DRW_cache_lamp_sunrays_get();
+ stl->g_data->lamp_sunrays = shgroup_instance_screenspace(psl->non_meshes, geom, &ts.sizeLampCircle);
+
+ stl->g_data->lamp_groundline = shgroup_groundlines_uniform_color(psl->non_meshes, ts.colorLamp);
+ stl->g_data->lamp_groundpoint = shgroup_groundpoints_uniform_color(psl->non_meshes, ts.colorLamp);
+
+ geom = DRW_cache_lamp_area_get();
+ stl->g_data->lamp_area = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_lamp_hemi_get();
+ stl->g_data->lamp_hemi = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_single_line_get();
+ stl->g_data->lamp_distance = shgroup_distance_lines_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_single_line_endpoints_get();
+ stl->g_data->lamp_buflimit_points = shgroup_distance_lines_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_lamp_spot_get();
+ stl->g_data->lamp_spot_cone = shgroup_spot_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_circle_get();
+ stl->g_data->lamp_spot_blend = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_lamp_spot_square_get();
+ stl->g_data->lamp_spot_pyramid = shgroup_instance(psl->non_meshes, geom);
+
+ geom = DRW_cache_square_get();
+ stl->g_data->lamp_spot_blend_rect = shgroup_instance(psl->non_meshes, geom);
+ }
+
+ {
+ /* -------- STIPPLES ------- */
+ struct Gwn_Batch *geom;
+
+ /* Relationship Lines */
+ stl->g_data->relationship_lines = shgroup_dynlines_dashed_uniform_color(psl->non_meshes, ts.colorWire);
+
+ /* Force Field Curve Guide End (here because of stipple) */
+ /* TODO port to shader stipple */
+ geom = DRW_cache_screenspace_circle_get();
+ stl->g_data->field_curve_end = shgroup_instance_screen_aligned(psl->non_meshes, geom);
+
+ /* Force Field Limits */
+ /* TODO port to shader stipple */
+ geom = DRW_cache_field_tube_limit_get();
+ stl->g_data->field_tube_limit = shgroup_instance_scaled(psl->non_meshes, geom);
+
+ /* TODO port to shader stipple */
+ geom = DRW_cache_field_cone_limit_get();
+ stl->g_data->field_cone_limit = shgroup_instance_scaled(psl->non_meshes, geom);
+ }
+
+ {
+ /* Object Center pass grouped by State */
+ DRWShadingGroup *grp;
+ static float outlineWidth, size;
+
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_BLEND | DRW_STATE_POINT;
+ psl->ob_center = DRW_pass_create("Obj Center Pass", state);
+
+ outlineWidth = 1.0f * U.pixelsize;
+ size = U.obcenter_dia * U.pixelsize + outlineWidth;
+
+ GPUShader *sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA);
+
+ /* Active */
+ grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
+ DRW_shgroup_uniform_float(grp, "size", &size, 1);
+ DRW_shgroup_uniform_float(grp, "outlineWidth", &outlineWidth, 1);
+ DRW_shgroup_uniform_vec4(grp, "color", ts.colorActive, 1);
+ DRW_shgroup_uniform_vec4(grp, "outlineColor", ts.colorOutline, 1);
+ stl->g_data->center_active = grp;
+
+ /* Select */
+ grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
+ DRW_shgroup_uniform_vec4(grp, "color", ts.colorSelect, 1);
+ stl->g_data->center_selected = grp;
+
+ /* Deselect */
+ grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
+ DRW_shgroup_uniform_vec4(grp, "color", ts.colorDeselect, 1);
+ stl->g_data->center_deselected = grp;
+
+ /* Select (library) */
+ grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
+ DRW_shgroup_uniform_vec4(grp, "color", ts.colorLibrarySelect, 1);
+ stl->g_data->center_selected_lib = grp;
+
+ /* Deselect (library) */
+ grp = DRW_shgroup_point_batch_create(sh, psl->ob_center);
+ DRW_shgroup_uniform_vec4(grp, "color", ts.colorLibrary, 1);
+ stl->g_data->center_deselected_lib = grp;
+ }
+
+ {
+ /* Particle Pass */
+ psl->particle = DRW_pass_create(
+ "Particle Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
+ DRW_STATE_POINT | DRW_STATE_BLEND);
+ }
+
+ {
+ /* Empty/Background Image Pass */
+ psl->reference_image = DRW_pass_create(
+ "Refrence Image Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
+ }
+}
+
+static void DRW_shgroup_mball_handles(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
+{
+ MetaBall *mb = ob->data;
+
+ float *color;
+ DRW_object_wire_theme_get(ob, view_layer, &color);
+
+ float draw_scale_xform[3][4]; /* Matrix of Scale and Translation */
+ {
+ float scamat[3][3];
+ copy_m3_m4(scamat, ob->obmat);
+ /* Get the normalized inverse matrix to extract only
+ * the scale of Scamat */
+ float iscamat[3][3];
+ invert_m3_m3(iscamat, scamat);
+ normalize_m3(iscamat);
+ mul_m3_m3_post(scamat, iscamat);
+
+ copy_v3_v3(draw_scale_xform[0], scamat[0]);
+ copy_v3_v3(draw_scale_xform[1], scamat[1]);
+ copy_v3_v3(draw_scale_xform[2], scamat[2]);
+ }
+
+ for (MetaElem *ml = mb->elems.first; ml != NULL; ml = ml->next) {
+ /* draw radius */
+ float world_pos[3];
+ mul_v3_m4v3(world_pos, ob->obmat, &ml->x);
+ draw_scale_xform[0][3] = world_pos[0];
+ draw_scale_xform[1][3] = world_pos[1];
+ draw_scale_xform[2][3] = world_pos[2];
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->mball_handle, draw_scale_xform, &ml->rad, color);
+ }
+}
+
+static void DRW_shgroup_lamp(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
+{
+ Lamp *la = ob->data;
+ float *color;
+ int theme_id = DRW_object_wire_theme_get(ob, view_layer, &color);
+ static float zero = 0.0f;
+
+ typedef struct LampEngineData {
+ ObjectEngineData engine_data;
+ float shape_mat[4][4];
+ float spot_blend_mat[4][4];
+ } LampEngineData;
+
+ LampEngineData *lamp_engine_data =
+ (LampEngineData *)DRW_object_engine_data_ensure(
+ ob,
+ &draw_engine_object_type,
+ sizeof(LampEngineData),
+ NULL,
+ NULL);
+
+ float (*shapemat)[4] = lamp_engine_data->shape_mat;
+ float (*spotblendmat)[4] = lamp_engine_data->spot_blend_mat;
+
+ /* Don't draw the center if it's selected or active */
+ if (theme_id == TH_LAMP)
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_center, ob->obmat[3]);
+
+ /* First circle */
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_circle, ob->obmat[3], color);
+
+ /* draw dashed outer circle for shadow */
+ if (la->type != LA_HEMI) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_circle_shadow, ob->obmat[3], color);
+ }
+
+ /* Distance */
+ if (ELEM(la->type, LA_HEMI, LA_SUN, LA_AREA)) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_distance, color, &zero, &la->dist, ob->obmat);
+ }
+
+ copy_m4_m4(shapemat, ob->obmat);
+
+ if (la->type == LA_SUN) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_sunrays, ob->obmat[3], color);
+ }
+ else if (la->type == LA_SPOT) {
+ float size[3], sizemat[4][4];
+ static float one = 1.0f;
+ float blend = 1.0f - pow2f(la->spotblend);
+
+ size[0] = size[1] = sinf(la->spotsize * 0.5f) * la->dist;
+ size[2] = cosf(la->spotsize * 0.5f) * la->dist;
+
+ size_to_mat4(sizemat, size);
+ mul_m4_m4m4(shapemat, ob->obmat, sizemat);
+
+ size[0] = size[1] = blend; size[2] = 1.0f;
+ size_to_mat4(sizemat, size);
+ translate_m4(sizemat, 0.0f, 0.0f, -1.0f);
+ rotate_m4(sizemat, 'X', (float)(M_PI / 2));
+ mul_m4_m4m4(spotblendmat, shapemat, sizemat);
+
+ if (la->mode & LA_SQUARE) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_pyramid, color, &one, shapemat);
+
+ /* hide line if it is zero size or overlaps with outer border,
+ * previously it adjusted to always to show it but that seems
+ * confusing because it doesn't show the actual blend size */
+ if (blend != 0.0f && blend != 1.0f) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_blend_rect, color, &one, spotblendmat);
+ }
+ }
+ else {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_cone, color, shapemat);
+
+ /* hide line if it is zero size or overlaps with outer border,
+ * previously it adjusted to always to show it but that seems
+ * confusing because it doesn't show the actual blend size */
+ if (blend != 0.0f && blend != 1.0f) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_spot_blend, color, &one, spotblendmat);
+ }
+ }
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit, color, &la->clipsta, &la->clipend, ob->obmat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit_points, color, &la->clipsta, &la->clipend, ob->obmat);
+ }
+ else if (la->type == LA_HEMI) {
+ static float hemisize = 2.0f;
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_hemi, color, &hemisize, shapemat);
+ }
+ else if (la->type == LA_AREA) {
+ float size[3] = {1.0f, 1.0f, 1.0f}, sizemat[4][4];
+
+ if (la->area_shape == LA_AREA_RECT) {
+ size[1] = la->area_sizey / la->area_size;
+ size_to_mat4(sizemat, size);
+ mul_m4_m4m4(shapemat, shapemat, sizemat);
+ }
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_area, color, &la->area_size, shapemat);
+ }
+
+ /* Line and point going to the ground */
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundline, ob->obmat[3]);
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundpoint, ob->obmat[3]);
+}
+
+static void DRW_shgroup_camera(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ View3D *v3d = draw_ctx->v3d;
+ Scene *scene = draw_ctx->scene;
+ RegionView3D *rv3d = draw_ctx->rv3d;
+
+ Camera *cam = ob->data;
+ const Object *camera_object = DEG_get_evaluated_object(draw_ctx->depsgraph, v3d->camera);
+ const bool is_active = (ob == camera_object);
+ const bool look_through = (is_active && (rv3d->persp == RV3D_CAMOB));
+ float *color;
+ DRW_object_wire_theme_get(ob, view_layer, &color);
+
+ float vec[4][3], asp[2], shift[2], scale[3], drawsize;
+
+ scale[0] = 1.0f / len_v3(ob->obmat[0]);
+ scale[1] = 1.0f / len_v3(ob->obmat[1]);
+ scale[2] = 1.0f / len_v3(ob->obmat[2]);
+
+ BKE_camera_view_frame_ex(scene, cam, cam->drawsize, false, scale,
+ asp, shift, &drawsize, vec);
+
+ /* Frame coords */
+ copy_v2_v2(cam->drwcorners[0], vec[0]);
+ copy_v2_v2(cam->drwcorners[1], vec[1]);
+ copy_v2_v2(cam->drwcorners[2], vec[2]);
+ copy_v2_v2(cam->drwcorners[3], vec[3]);
+
+ /* depth */
+ cam->drwdepth = vec[0][2];
+
+ /* tria */
+ cam->drwtria[0][0] = shift[0] + ((0.7f * drawsize) * scale[0]);
+ cam->drwtria[0][1] = shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]);
+ cam->drwtria[1][0] = shift[0];
+ cam->drwtria[1][1] = shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]);
+
+ if (look_through) {
+ /* Only draw the frame. */
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera_frame, color, cam->drwcorners,
+ &cam->drwdepth, cam->drwtria, ob->obmat);
+ }
+ else {
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera, color, cam->drwcorners,
+ &cam->drwdepth, cam->drwtria, ob->obmat);
+
+ /* Active cam */
+ if (is_active) {
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera_tria, color,
+ cam->drwcorners, &cam->drwdepth, cam->drwtria, ob->obmat);
+ }
+ }
+
+ /* draw the rest in normalize object space */
+ copy_m4_m4(cam->drwnormalmat, ob->obmat);
+ normalize_m4(cam->drwnormalmat);
+
+ if (cam->flag & CAM_SHOWLIMITS) {
+ static float col[3] = {0.5f, 0.5f, 0.25f}, col_hi[3] = {1.0f, 1.0f, 0.5f};
+ float sizemat[4][4], size[3] = {1.0f, 1.0f, 0.0f};
+ float focusdist = BKE_camera_object_dof_distance(ob);
+
+ copy_m4_m4(cam->drwfocusmat, cam->drwnormalmat);
+ translate_m4(cam->drwfocusmat, 0.0f, 0.0f, -focusdist);
+ size_to_mat4(sizemat, size);
+ mul_m4_m4m4(cam->drwfocusmat, cam->drwfocusmat, sizemat);
+
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera_focus, (is_active ? col_hi : col),
+ &cam->drawsize, cam->drwfocusmat);
+
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera_clip, color,
+ &cam->clipsta, &cam->clipend, cam->drwnormalmat);
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera_clip_points, (is_active ? col_hi : col),
+ &cam->clipsta, &cam->clipend, cam->drwnormalmat);
+ }
+
+ if (cam->flag & CAM_SHOWMIST) {
+ World *world = scene->world;
+
+ if (world) {
+ static float col[3] = {0.5f, 0.5f, 0.5f}, col_hi[3] = {1.0f, 1.0f, 1.0f};
+ world->mistend = world->miststa + world->mistdist;
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera_mist, color,
+ &world->miststa, &world->mistend, cam->drwnormalmat);
+ DRW_shgroup_call_dynamic_add(
+ stl->g_data->camera_mist_points, (is_active ? col_hi : col),
+ &world->miststa, &world->mistend, cam->drwnormalmat);
+ }
+ }
+}
+
+static void DRW_shgroup_empty(OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, ViewLayer *view_layer)
+{
+ float *color;
+ DRW_object_wire_theme_get(ob, view_layer, &color);
+
+ switch (ob->empty_drawtype) {
+ case OB_PLAINAXES:
+ DRW_shgroup_call_dynamic_add(stl->g_data->plain_axes, color, &ob->empty_drawsize, ob->obmat);
+ break;
+ case OB_SINGLE_ARROW:
+ DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow, color, &ob->empty_drawsize, ob->obmat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow_line, color, &ob->empty_drawsize, ob->obmat);
+ break;
+ case OB_CUBE:
+ DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &ob->empty_drawsize, ob->obmat);
+ break;
+ case OB_CIRCLE:
+ DRW_shgroup_call_dynamic_add(stl->g_data->circle, color, &ob->empty_drawsize, ob->obmat);
+ break;
+ case OB_EMPTY_SPHERE:
+ DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &ob->empty_drawsize, ob->obmat);
+ break;
+ case OB_EMPTY_CONE:
+ DRW_shgroup_call_dynamic_add(stl->g_data->cone, color, &ob->empty_drawsize, ob->obmat);
+ break;
+ case OB_ARROWS:
+ DRW_shgroup_call_dynamic_add(stl->g_data->arrows, color, &ob->empty_drawsize, ob->obmat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->axis_names, color, &ob->empty_drawsize, ob->obmat);
+ break;
+ case OB_EMPTY_IMAGE:
+ DRW_shgroup_empty_image(stl, psl, ob, color);
+ break;
+ }
+}
+
+static void DRW_shgroup_forcefield(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
+{
+ int theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
+ float *color = DRW_color_background_blend_get(theme_id);
+ PartDeflect *pd = ob->pd;
+ Curve *cu = (ob->type == OB_CURVE) ? ob->data : NULL;
+
+ /* TODO Move this to depsgraph */
+ float tmp[3];
+ copy_v3_fl(pd->drawvec1, ob->empty_drawsize);
+
+ switch (pd->forcefield) {
+ case PFIELD_WIND:
+ pd->drawvec1[2] = pd->f_strength;
+ break;
+ case PFIELD_VORTEX:
+ if (pd->f_strength < 0.0f) {
+ pd->drawvec1[1] = -pd->drawvec1[1];
+ }
+ break;
+ case PFIELD_GUIDE:
+ if (cu && (cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
+ where_on_path(ob, 0.0f, pd->drawvec1, tmp, NULL, NULL, NULL);
+ where_on_path(ob, 1.0f, pd->drawvec2, tmp, NULL, NULL, NULL);
+ }
+ break;
+ }
+
+ if (pd->falloff == PFIELD_FALL_TUBE) {
+ pd->drawvec_falloff_max[0] = pd->drawvec_falloff_max[1] = (pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f;
+ pd->drawvec_falloff_max[2] = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
+
+ pd->drawvec_falloff_min[0] = pd->drawvec_falloff_min[1] = (pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f;
+ pd->drawvec_falloff_min[2] = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
+ }
+ else if (pd->falloff == PFIELD_FALL_CONE) {
+ float radius, distance;
+
+ radius = DEG2RADF((pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f);
+ distance = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
+ pd->drawvec_falloff_max[0] = pd->drawvec_falloff_max[1] = distance * sinf(radius);
+ pd->drawvec_falloff_max[2] = distance * cosf(radius);
+
+ radius = DEG2RADF((pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f);
+ distance = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
+
+ pd->drawvec_falloff_min[0] = pd->drawvec_falloff_min[1] = distance * sinf(radius);
+ pd->drawvec_falloff_min[2] = distance * cosf(radius);
+ }
+ /* End of things that should go to depthgraph */
+
+ switch (pd->forcefield) {
+ case PFIELD_WIND:
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_wind, color, &pd->drawvec1, ob->obmat);
+ break;
+ case PFIELD_FORCE:
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_force, color, &pd->drawvec1, ob->obmat);
+ break;
+ case PFIELD_VORTEX:
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_vortex, color, &pd->drawvec1, ob->obmat);
+ break;
+ case PFIELD_GUIDE:
+ if (cu && (cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_sta, color, &pd->f_strength, ob->obmat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->f_strength, ob->obmat);
+ }
+ break;
+ }
+
+ if (pd->falloff == PFIELD_FALL_SPHERE) {
+ /* as last, guide curve alters it */
+ if ((pd->flag & PFIELD_USEMAX) != 0) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->maxdist, ob->obmat);
+ }
+
+ if ((pd->flag & PFIELD_USEMIN) != 0) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_curve_end, color, &pd->mindist, ob->obmat);
+ }
+ }
+ else if (pd->falloff == PFIELD_FALL_TUBE) {
+ if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR)) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_tube_limit, color, &pd->drawvec_falloff_max, ob->obmat);
+ }
+
+ if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR)) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_tube_limit, color, &pd->drawvec_falloff_min, ob->obmat);
+ }
+ }
+ else if (pd->falloff == PFIELD_FALL_CONE) {
+ if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR)) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_cone_limit, color, &pd->drawvec_falloff_max, ob->obmat);
+ }
+
+ if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR)) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->field_cone_limit, color, &pd->drawvec_falloff_min, ob->obmat);
+ }
+ }
+}
+
+static void DRW_shgroup_speaker(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer)
+{
+ float *color;
+ static float one = 1.0f;
+ DRW_object_wire_theme_get(ob, view_layer, &color);
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->speaker, color, &one, ob->obmat);
+}
+
+typedef struct OBJECT_LightProbeEngineData {
+ ObjectEngineData engine_data;
+
+ float prb_mats[6][4][4];
+ float probe_cube_mat[4][4];
+ float draw_size;
+ float increment_x[3];
+ float increment_y[3];
+ float increment_z[3];
+ float corner[3];
+ unsigned int cell_count;
+} OBJECT_LightProbeEngineData;
+
+static void DRW_shgroup_lightprobe(OBJECT_StorageList *stl, OBJECT_PassList *psl, Object *ob, ViewLayer *view_layer)
+{
+ float *color;
+ static float one = 1.0f;
+ LightProbe *prb = (LightProbe *)ob->data;
+ bool do_outlines = ((ob->base_flag & BASE_SELECTED) != 0);
+ int theme_id = DRW_object_wire_theme_get(ob, view_layer, &color);
+
+ OBJECT_LightProbeEngineData *prb_data =
+ (OBJECT_LightProbeEngineData *)DRW_object_engine_data_ensure(
+ ob,
+ &draw_engine_object_type,
+ sizeof(OBJECT_LightProbeEngineData),
+ NULL,
+ NULL);
+
+ if ((DRW_state_is_select() || do_outlines) && ((prb->flag & LIGHTPROBE_FLAG_SHOW_DATA) != 0)) {
+ int *call_id = shgroup_theme_id_to_probe_outline_counter(stl, theme_id);
+
+ if (prb->type == LIGHTPROBE_TYPE_GRID) {
+ /* Update transforms */
+ float cell_dim[3], half_cell_dim[3];
+ cell_dim[0] = 2.0f / (float)(prb->grid_resolution_x);
+ cell_dim[1] = 2.0f / (float)(prb->grid_resolution_y);
+ cell_dim[2] = 2.0f / (float)(prb->grid_resolution_z);
+
+ mul_v3_v3fl(half_cell_dim, cell_dim, 0.5f);
+
+ /* First cell. */
+ copy_v3_fl(prb_data->corner, -1.0f);
+ add_v3_v3(prb_data->corner, half_cell_dim);
+ mul_m4_v3(ob->obmat, prb_data->corner);
+
+ /* Opposite neighbor cell. */
+ copy_v3_fl3(prb_data->increment_x, cell_dim[0], 0.0f, 0.0f);
+ add_v3_v3(prb_data->increment_x, half_cell_dim);
+ add_v3_fl(prb_data->increment_x, -1.0f);
+ mul_m4_v3(ob->obmat, prb_data->increment_x);
+ sub_v3_v3(prb_data->increment_x, prb_data->corner);
+
+ copy_v3_fl3(prb_data->increment_y, 0.0f, cell_dim[1], 0.0f);
+ add_v3_v3(prb_data->increment_y, half_cell_dim);
+ add_v3_fl(prb_data->increment_y, -1.0f);
+ mul_m4_v3(ob->obmat, prb_data->increment_y);
+ sub_v3_v3(prb_data->increment_y, prb_data->corner);
+
+ copy_v3_fl3(prb_data->increment_z, 0.0f, 0.0f, cell_dim[2]);
+ add_v3_v3(prb_data->increment_z, half_cell_dim);
+ add_v3_fl(prb_data->increment_z, -1.0f);
+ mul_m4_v3(ob->obmat, prb_data->increment_z);
+ sub_v3_v3(prb_data->increment_z, prb_data->corner);
+
+ prb_data->cell_count = prb->grid_resolution_x * prb->grid_resolution_y * prb->grid_resolution_z;
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.lightprobe_grid_sh, psl->lightprobes);
+ DRW_shgroup_uniform_int_copy(grp, "call_id", *call_id);
+ DRW_shgroup_uniform_int(grp, "baseId", call_id, 1); /* that's correct */
+ DRW_shgroup_uniform_vec3(grp, "corner", prb_data->corner, 1);
+ DRW_shgroup_uniform_vec3(grp, "increment_x", prb_data->increment_x, 1);
+ DRW_shgroup_uniform_vec3(grp, "increment_y", prb_data->increment_y, 1);
+ DRW_shgroup_uniform_vec3(grp, "increment_z", prb_data->increment_z, 1);
+ DRW_shgroup_uniform_ivec3(grp, "grid_resolution", &prb->grid_resolution_x, 1);
+ DRW_shgroup_uniform_float(grp, "sphere_size", &prb->data_draw_size, 1);
+ DRW_shgroup_call_instances_add(grp, DRW_cache_sphere_get(), NULL, &prb_data->cell_count);
+ }
+ else if (prb->type == LIGHTPROBE_TYPE_CUBE) {
+ prb_data->draw_size = prb->data_draw_size * 0.1f;
+ unit_m4(prb_data->probe_cube_mat);
+ copy_v3_v3(prb_data->probe_cube_mat[3], ob->obmat[3]);
+
+ DRWShadingGroup *grp = shgroup_theme_id_to_probe_cube_outline_shgrp(stl, theme_id);
+ DRW_shgroup_call_dynamic_add(grp, call_id, &prb_data->draw_size, prb_data->probe_cube_mat);
+ }
+ else {
+ prb_data->draw_size = 1.0f;
+
+ DRWShadingGroup *grp = shgroup_theme_id_to_probe_planar_outline_shgrp(stl, theme_id);
+ DRW_shgroup_call_dynamic_add(grp, call_id, &prb_data->draw_size, ob->obmat);
+ }
+
+ *call_id += 1;
+ }
+
+ switch (prb->type) {
+ case LIGHTPROBE_TYPE_PLANAR:
+ DRW_shgroup_call_dynamic_add(stl->g_data->probe_planar, ob->obmat[3], color);
+ break;
+ case LIGHTPROBE_TYPE_GRID:
+ DRW_shgroup_call_dynamic_add(stl->g_data->probe_grid, ob->obmat[3], color);
+ break;
+ case LIGHTPROBE_TYPE_CUBE:
+ default:
+ DRW_shgroup_call_dynamic_add(stl->g_data->probe_cube, ob->obmat[3], color);
+ break;
+ }
+
+
+
+ if (prb->type == LIGHTPROBE_TYPE_PLANAR) {
+ float (*mat)[4];
+ mat = (float (*)[4])(prb_data->prb_mats[0]);
+ copy_m4_m4(mat, ob->obmat);
+ normalize_m4(mat);
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow, color, &ob->empty_drawsize, mat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->single_arrow_line, color, &ob->empty_drawsize, mat);
+
+ mat = (float (*)[4])(prb_data->prb_mats[1]);
+ copy_m4_m4(mat, ob->obmat);
+ zero_v3(mat[2]);
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, mat);
+ }
+
+ if ((prb->flag & LIGHTPROBE_FLAG_SHOW_INFLUENCE) != 0) {
+
+ prb->distfalloff = (1.0f - prb->falloff) * prb->distinf;
+ prb->distgridinf = prb->distinf;
+
+ if (prb->type == LIGHTPROBE_TYPE_GRID) {
+ prb->distfalloff += 1.0f;
+ prb->distgridinf += 1.0f;
+ }
+
+ if (prb->type == LIGHTPROBE_TYPE_GRID ||
+ prb->attenuation_type == LIGHTPROBE_SHAPE_BOX)
+ {
+ DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distgridinf, ob->obmat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &prb->distfalloff, ob->obmat);
+ }
+ else if (prb->type == LIGHTPROBE_TYPE_PLANAR) {
+ float (*rangemat)[4];
+ rangemat = (float (*)[4])(prb_data->prb_mats[2]);
+ copy_m4_m4(rangemat, ob->obmat);
+ normalize_v3(rangemat[2]);
+ mul_v3_fl(rangemat[2], prb->distinf);
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, rangemat);
+
+ rangemat = (float (*)[4])(prb_data->prb_mats[3]);
+ copy_m4_m4(rangemat, ob->obmat);
+ normalize_v3(rangemat[2]);
+ mul_v3_fl(rangemat[2], prb->distfalloff);
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, &one, rangemat);
+ }
+ else {
+ DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &prb->distgridinf, ob->obmat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, &prb->distfalloff, ob->obmat);
+ }
+ }
+
+ if ((prb->flag & LIGHTPROBE_FLAG_SHOW_PARALLAX) != 0) {
+ if (prb->type != LIGHTPROBE_TYPE_PLANAR) {
+ float (*obmat)[4], *dist;
+
+ if ((prb->flag & LIGHTPROBE_FLAG_CUSTOM_PARALLAX) != 0) {
+ dist = &prb->distpar;
+ /* TODO object parallax */
+ obmat = ob->obmat;
+ }
+ else {
+ dist = &prb->distinf;
+ obmat = ob->obmat;
+ }
+
+ if (prb->parallax_type == LIGHTPROBE_SHAPE_BOX) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->cube, color, dist, obmat);
+ }
+ else {
+ DRW_shgroup_call_dynamic_add(stl->g_data->sphere, color, dist, obmat);
+ }
+ }
+ }
+
+ if ((prb->flag & LIGHTPROBE_FLAG_SHOW_CLIP_DIST) != 0) {
+ if (prb->type != LIGHTPROBE_TYPE_PLANAR) {
+ static const float cubefacemat[6][4][4] = {
+ {{0.0, 0.0, -1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {-1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
+ {{0.0, 0.0, 1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
+ {{1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
+ {{1.0, 0.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
+ {{1.0, 0.0, 0.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, -1.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
+ {{-1.0, 0.0, 0.0, 0.0}, {0.0, -1.0, 0.0, 0.0}, {0.0, 0.0, 1.0, 0.0}, {0.0, 0.0, 0.0, 1.0}},
+ };
+
+ for (int i = 0; i < 6; ++i) {
+ float (*clipmat)[4];
+ clipmat = (float (*)[4])(prb_data->prb_mats[i]);
+
+ normalize_m4_m4(clipmat, ob->obmat);
+ mul_m4_m4m4(clipmat, clipmat, cubefacemat[i]);
+
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit, color, &prb->clipsta, &prb->clipend, clipmat);
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_buflimit_points, color, &prb->clipsta, &prb->clipend, clipmat);
+ }
+ }
+ }
+
+ /* Line and point going to the ground */
+ if (prb->type == LIGHTPROBE_TYPE_CUBE) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundline, ob->obmat[3]);
+ DRW_shgroup_call_dynamic_add(stl->g_data->lamp_groundpoint, ob->obmat[3]);
+ }
+}
+
+static void DRW_shgroup_relationship_lines(OBJECT_StorageList *stl, Object *ob)
+{
+ if (ob->parent && DRW_check_object_visible_within_active_context(ob->parent)) {
+ DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->parent->obmat[3]);
+ DRW_shgroup_call_dynamic_add(stl->g_data->relationship_lines, ob->obmat[3]);
+ }
+}
+
+static void DRW_shgroup_object_center(OBJECT_StorageList *stl, Object *ob, ViewLayer *view_layer, View3D *v3d)
+{
+ const bool is_library = ob->id.us > 1 || ID_IS_LINKED(ob);
+ DRWShadingGroup *shgroup;
+
+ if (ob == OBACT(view_layer)) {
+ shgroup = stl->g_data->center_active;
+ }
+ else if (ob->base_flag & BASE_SELECTED) {
+ if (is_library) {
+ shgroup = stl->g_data->center_selected_lib;
+ }
+ else {
+ shgroup = stl->g_data->center_selected;
+ }
+ }
+ else if (v3d->flag & V3D_DRAW_CENTERS) {
+ if (is_library) {
+ shgroup = stl->g_data->center_deselected_lib;
+ }
+ else {
+ shgroup = stl->g_data->center_deselected;
+ }
+ }
+ else {
+ return;
+ }
+
+ DRW_shgroup_call_dynamic_add(shgroup, ob->obmat[3]);
+}
+
+static void OBJECT_cache_populate_particles(Object *ob,
+ OBJECT_PassList *psl)
+{
+ for (ParticleSystem *psys = ob->particlesystem.first; psys; psys = psys->next) {
+ if (psys_check_enabled(ob, psys, false)) {
+ ParticleSettings *part = psys->part;
+ int draw_as = (part->draw_as == PART_DRAW_REND) ? part->ren_as : part->draw_as;
+
+ if (draw_as == PART_DRAW_PATH && !psys->pathcache && !psys->childcache) {
+ draw_as = PART_DRAW_DOT;
+ }
+
+ static float mat[4][4];
+ unit_m4(mat);
+
+ if (draw_as != PART_DRAW_PATH) {
+ struct Gwn_Batch *geom = DRW_cache_particles_get_dots(ob, psys);
+ DRWShadingGroup *shgrp = NULL;
+ static int screen_space[2] = {0, 1};
+ static float def_prim_col[3] = {0.5f, 0.5f, 0.5f};
+ static float def_sec_col[3] = {1.0f, 1.0f, 1.0f};
+
+ /* Dummy particle format for instancing to work. */
+ DRW_shgroup_instance_format(e_data.particle_format, {{"dummy", DRW_ATTRIB_FLOAT, 1}});
+
+ Material *ma = give_current_material(ob, part->omat);
+
+ switch (draw_as) {
+ case PART_DRAW_DOT:
+ shgrp = DRW_shgroup_create(e_data.part_dot_sh, psl->particle);
+ DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
+ DRW_shgroup_uniform_vec3(shgrp, "outlineColor", ma ? &ma->specr : def_sec_col, 1);
+ DRW_shgroup_uniform_float(shgrp, "pixel_size", DRW_viewport_pixelsize_get(), 1);
+ DRW_shgroup_uniform_float(shgrp, "size", &part->draw_size, 1);
+ DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
+ DRW_shgroup_call_add(shgrp, geom, mat);
+ break;
+ case PART_DRAW_CROSS:
+ shgrp = DRW_shgroup_instance_create(
+ e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CROSS),
+ e_data.particle_format);
+ DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
+ DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
+ DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
+ break;
+ case PART_DRAW_CIRC:
+ shgrp = DRW_shgroup_instance_create(
+ e_data.part_prim_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_CIRC),
+ e_data.particle_format);
+ DRW_shgroup_uniform_texture(shgrp, "ramp", globals_ramp);
+ DRW_shgroup_uniform_vec3(shgrp, "color", ma ? &ma->r : def_prim_col, 1);
+ DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[1], 1);
+ break;
+ case PART_DRAW_AXIS:
+ shgrp = DRW_shgroup_instance_create(
+ e_data.part_axis_sh, psl->particle, DRW_cache_particles_get_prim(PART_DRAW_AXIS),
+ e_data.particle_format);
+ DRW_shgroup_uniform_int(shgrp, "screen_space", &screen_space[0], 1);
+ break;
+ default:
+ break;
+ }
+
+ if (shgrp) {
+ if (draw_as != PART_DRAW_DOT) {
+ DRW_shgroup_uniform_float(shgrp, "draw_size", &part->draw_size, 1);
+ DRW_shgroup_instance_batch(shgrp, geom);
+ }
+ }
+ }
+ }
+ }
+}
+
+static void OBJECT_cache_populate(void *vedata, Object *ob)
+{
+ OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
+ OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ ViewLayer *view_layer = draw_ctx->view_layer;
+ View3D *v3d = draw_ctx->v3d;
+ int theme_id = TH_UNDEFINED;
+
+ /* Handle particles first in case the emitter itself shouldn't be rendered. */
+ if (ob->type == OB_MESH) {
+ OBJECT_cache_populate_particles(ob, psl);
+ }
+
+ if (DRW_check_object_visible_within_active_context(ob) == false) {
+ return;
+ }
+
+ bool do_outlines = ((ob->base_flag & BASE_SELECTED) != 0);
+
+ if (do_outlines) {
+ if ((ob != draw_ctx->object_edit) && !((ob == draw_ctx->obact) && (draw_ctx->object_mode & OB_MODE_ALL_PAINT))) {
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
+ if (geom) {
+ theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
+ DRWShadingGroup *shgroup = shgroup_theme_id_to_outline_or(stl, theme_id, NULL);
+ if (shgroup != NULL) {
+ DRW_shgroup_call_object_add(shgroup, geom, ob);
+ }
+ }
+ }
+ }
+
+ switch (ob->type) {
+ case OB_MESH:
+ {
+ if (ob != draw_ctx->object_edit) {
+ Mesh *me = ob->data;
+ if (me->totpoly == 0) {
+ if (me->totedge == 0) {
+ struct Gwn_Batch *geom = DRW_cache_mesh_verts_get(ob);
+ if (geom) {
+ if (theme_id == TH_UNDEFINED) {
+ theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
+ }
+
+ DRWShadingGroup *shgroup = shgroup_theme_id_to_point_or(stl, theme_id, stl->g_data->points);
+ DRW_shgroup_call_object_add(shgroup, geom, ob);
+ }
+ }
+ else {
+ struct Gwn_Batch *geom = DRW_cache_mesh_edges_get(ob);
+ if (geom) {
+ if (theme_id == TH_UNDEFINED) {
+ theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
+ }
+
+ DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
+ DRW_shgroup_call_object_add(shgroup, geom, ob);
+ }
+ }
+ }
+ }
+ break;
+ }
+ case OB_SURF:
+ break;
+ case OB_LATTICE:
+ {
+ if (ob != draw_ctx->object_edit) {
+ struct Gwn_Batch *geom = DRW_cache_lattice_wire_get(ob, false);
+ if (theme_id == TH_UNDEFINED) {
+ theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
+ }
+
+ DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
+ DRW_shgroup_call_object_add(shgroup, geom, ob);
+ }
+ break;
+ }
+
+ case OB_CURVE:
+ {
+ if (ob != draw_ctx->object_edit) {
+ struct Gwn_Batch *geom = DRW_cache_curve_edge_wire_get(ob);
+ if (theme_id == TH_UNDEFINED) {
+ theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
+ }
+ DRWShadingGroup *shgroup = shgroup_theme_id_to_wire_or(stl, theme_id, stl->g_data->wire);
+ DRW_shgroup_call_object_add(shgroup, geom, ob);
+ }
+ break;
+ }
+ case OB_MBALL:
+ {
+ if (ob != draw_ctx->object_edit) {
+ DRW_shgroup_mball_handles(stl, ob, view_layer);
+ }
+ break;
+ }
+ case OB_LAMP:
+ DRW_shgroup_lamp(stl, ob, view_layer);
+ break;
+ case OB_CAMERA:
+ DRW_shgroup_camera(stl, ob, view_layer);
+ break;
+ case OB_EMPTY:
+ DRW_shgroup_empty(stl, psl, ob, view_layer);
+ break;
+ case OB_SPEAKER:
+ DRW_shgroup_speaker(stl, ob, view_layer);
+ break;
+ case OB_LIGHTPROBE:
+ DRW_shgroup_lightprobe(stl, psl, ob, view_layer);
+ break;
+ case OB_ARMATURE:
+ {
+ bArmature *arm = ob->data;
+ if (arm->edbo == NULL) {
+ if (DRW_state_is_select() || !DRW_pose_mode_armature(ob, draw_ctx->obact)) {
+ DRWArmaturePasses passes = {
+ .bone_solid = psl->bone_solid,
+ .bone_outline = psl->bone_outline,
+ .bone_wire = psl->bone_wire,
+ .bone_envelope = psl->bone_envelope,
+ .bone_axes = psl->bone_axes,
+ .relationship_lines = NULL, /* Don't draw relationship lines */
+ };
+ DRW_shgroup_armature_object(ob, view_layer, passes);
+ }
+ }
+ break;
+ }
+ default:
+ break;
+ }
+
+ if (ob->pd && ob->pd->forcefield) {
+ DRW_shgroup_forcefield(stl, ob, view_layer);
+ }
+
+ /* don't show object extras in set's */
+ if ((ob->base_flag & (BASE_FROM_SET | BASE_FROMDUPLI)) == 0) {
+
+ DRW_shgroup_object_center(stl, ob, view_layer, v3d);
+
+ DRW_shgroup_relationship_lines(stl, ob);
+
+ if ((ob->dtx & OB_DRAWNAME) && DRW_state_show_text()) {
+ struct DRWTextStore *dt = DRW_text_cache_ensure();
+ if (theme_id == TH_UNDEFINED) {
+ theme_id = DRW_object_wire_theme_get(ob, view_layer, NULL);
+ }
+
+ unsigned char color[4];
+ UI_GetThemeColor4ubv(theme_id, color);
+
+ DRW_text_cache_add(
+ dt, ob->obmat[3],
+ ob->id.name + 2, strlen(ob->id.name + 2),
+ 10, DRW_TEXT_CACHE_GLOBALSPACE | DRW_TEXT_CACHE_STRING_PTR, color);
+ }
+ }
+}
+
+static void OBJECT_draw_scene(void *vedata)
+{
+
+ OBJECT_PassList *psl = ((OBJECT_Data *)vedata)->psl;
+ OBJECT_StorageList *stl = ((OBJECT_Data *)vedata)->stl;
+ OBJECT_FramebufferList *fbl = ((OBJECT_Data *)vedata)->fbl;
+ OBJECT_PrivateData *g_data = stl->g_data;
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ int id_ct_select = g_data->id_ofs_select;
+ int id_ct_active = g_data->id_ofs_active;
+ int id_ct_transform = g_data->id_ofs_transform;
+
+ int id_ct_prb_select = g_data->id_ofs_prb_select;
+ int id_ct_prb_active = g_data->id_ofs_prb_active;
+ int id_ct_prb_transform = g_data->id_ofs_prb_transform;
+
+ int outline_calls = id_ct_select + id_ct_active + id_ct_transform;
+ outline_calls += id_ct_prb_select + id_ct_prb_active + id_ct_prb_transform;
+
+ float clearcol[4] = {0.0f, 0.0f, 0.0f, 0.0f};
+
+// DRW_draw_pass(psl->bone_envelope); /* Never drawn in Object mode currently. */
+
+ MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
+
+ /* This needs to be drawn after the oultine */
+ DRW_draw_pass(psl->bone_solid);
+ DRW_draw_pass(psl->bone_wire);
+ DRW_draw_pass(psl->bone_outline);
+ DRW_draw_pass(psl->non_meshes);
+ DRW_draw_pass(psl->particle);
+ DRW_draw_pass(psl->reference_image);
+ DRW_draw_pass(psl->bone_axes);
+
+ MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl)
+
+ if (DRW_state_is_fbo() && outline_calls > 0) {
+ DRW_stats_group_start("Outlines");
+
+ g_data->id_ofs_active = 1;
+ g_data->id_ofs_select = g_data->id_ofs_active + id_ct_active + id_ct_prb_active + 1;
+ g_data->id_ofs_transform = g_data->id_ofs_select + id_ct_select + id_ct_prb_select + 1;
+
+ g_data->id_ofs_prb_active = g_data->id_ofs_active + id_ct_active;
+ g_data->id_ofs_prb_select = g_data->id_ofs_select + id_ct_select;
+ g_data->id_ofs_prb_transform = g_data->id_ofs_transform + id_ct_transform;
+
+ /* Render filled polygon on a separate framebuffer */
+ GPU_framebuffer_bind(fbl->outlines_fb);
+ GPU_framebuffer_clear_color_depth(fbl->outlines_fb, clearcol, 1.0f);
+ DRW_draw_pass(psl->outlines);
+ DRW_draw_pass(psl->lightprobes);
+
+ /* Search outline pixels */
+ GPU_framebuffer_bind(fbl->blur_fb);
+ DRW_draw_pass(psl->outlines_search);
+
+ /* Expand outline to form a 3px wide line */
+ GPU_framebuffer_bind(fbl->expand_fb);
+ DRW_draw_pass(psl->outlines_expand);
+
+ /* Bleed color so the AA can do it's stuff */
+ GPU_framebuffer_bind(fbl->blur_fb);
+ DRW_draw_pass(psl->outlines_bleed);
+
+ /* restore main framebuffer */
+ GPU_framebuffer_bind(dfbl->default_fb);
+ DRW_stats_group_end();
+ }
+ else if (DRW_state_is_select()) {
+ /* Render probes spheres/planes so we can select them. */
+ DRW_draw_pass(psl->lightprobes);
+ }
+
+ DRW_draw_pass(psl->ob_center);
+
+ if (DRW_state_is_fbo()) {
+ if (e_data.draw_grid) {
+ GPU_framebuffer_bind(dfbl->color_only_fb);
+ DRW_draw_pass(psl->grid);
+ }
+
+ /* Combine with scene buffer last */
+ if (outline_calls > 0) {
+ DRW_draw_pass(psl->outlines_resolve);
+ }
+ }
+
+ /* This has to be freed only after drawing empties! */
+ if (stl->g_data->image_plane_map) {
+ BLI_ghash_free(stl->g_data->image_plane_map, NULL, MEM_freeN);
+ stl->g_data->image_plane_map = NULL;
+ }
+}
+
+static const DrawEngineDataSize OBJECT_data_size = DRW_VIEWPORT_DATA_SIZE(OBJECT_Data);
+
+DrawEngineType draw_engine_object_type = {
+ NULL, NULL,
+ N_("ObjectMode"),
+ &OBJECT_data_size,
+ &OBJECT_engine_init,
+ &OBJECT_engine_free,
+ &OBJECT_cache_init,
+ &OBJECT_cache_populate,
+ NULL,
+ NULL,
+ &OBJECT_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/overlay_mode.c b/source/blender/draw/modes/overlay_mode.c
new file mode 100644
index 00000000000..e2b381347ff
--- /dev/null
+++ b/source/blender/draw/modes/overlay_mode.c
@@ -0,0 +1,163 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file overlay_mode.c
+ * \ingroup draw_engine
+ */
+
+#include "DNA_view3d_types.h"
+
+#include "GPU_shader.h"
+#include "DRW_render.h"
+
+#include "draw_mode_engines.h"
+
+/* Structures */
+typedef struct OVERLAY_StorageList {
+ struct OVERLAY_PrivateData *g_data;
+} OVERLAY_StorageList;
+
+typedef struct OVERLAY_PassList {
+ struct DRWPass *face_orientation_pass;
+} OVERLAY_PassList;
+
+typedef struct OVERLAY_Data {
+ void *engine_type;
+ DRWViewportEmptyList *fbl;
+ DRWViewportEmptyList *txl;
+ OVERLAY_PassList *psl;
+ OVERLAY_StorageList *stl;
+} OVERLAY_Data;
+
+typedef struct OVERLAY_PrivateData {
+ DRWShadingGroup *face_orientation_shgrp;
+ View3DOverlay overlay;
+} OVERLAY_PrivateData; /* Transient data */
+
+/* *********** STATIC *********** */
+static struct {
+ /* Face orientation shader */
+ struct GPUShader *face_orientation_sh;
+} e_data = {NULL};
+
+/* Shaders */
+extern char datatoc_overlay_face_orientation_frag_glsl[];
+extern char datatoc_overlay_face_orientation_vert_glsl[];
+
+
+/* Functions */
+static void overlay_engine_init(void *vedata)
+{
+ OVERLAY_Data * data = (OVERLAY_Data *)vedata;
+ OVERLAY_StorageList *stl = data->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ if (!e_data.face_orientation_sh) {
+ /* Face orientation */
+ e_data.face_orientation_sh = DRW_shader_create(datatoc_overlay_face_orientation_vert_glsl, NULL, datatoc_overlay_face_orientation_frag_glsl, "\n");
+ }
+}
+
+static void overlay_cache_init(void *vedata)
+{
+ OVERLAY_Data * data = (OVERLAY_Data *)vedata;
+ OVERLAY_PassList *psl = data->psl;
+ OVERLAY_StorageList *stl = data->stl;
+
+ const DRWContextState *DCS = DRW_context_state_get();
+
+ View3D *v3d = DCS->v3d;
+ if (v3d) {
+ stl->g_data->overlay = v3d->overlay;
+ }
+ else {
+ memset(&stl->g_data->overlay, 0, sizeof(stl->g_data->overlay));
+ }
+
+ /* Face Orientation Pass */
+ if (stl->g_data->overlay.flag & V3D_OVERLAY_FACE_ORIENTATION) {
+ int state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_BLEND;
+ psl->face_orientation_pass = DRW_pass_create("Face Orientation", state);
+ stl->g_data->face_orientation_shgrp = DRW_shgroup_create(e_data.face_orientation_sh, psl->face_orientation_pass);
+ }
+}
+
+static void overlay_cache_populate(void *vedata, Object *ob)
+{
+ OVERLAY_Data * data = (OVERLAY_Data *)vedata;
+ OVERLAY_StorageList *stl = data->stl;
+ OVERLAY_PrivateData *pd = stl->g_data;
+
+ if (!DRW_object_is_renderable(ob))
+ return;
+
+ struct Gwn_Batch *geom = DRW_cache_object_surface_get(ob);
+ if (geom) {
+ /* Face Orientation */
+ if (stl->g_data->overlay.flag & V3D_OVERLAY_FACE_ORIENTATION) {
+ DRW_shgroup_call_add(pd->face_orientation_shgrp, geom, ob->obmat);
+ }
+ }
+}
+
+static void overlay_cache_finish(void *UNUSED(vedata))
+{
+}
+
+static void overlay_draw_scene(void *vedata)
+{
+ OVERLAY_Data * data = (OVERLAY_Data *)vedata;
+ OVERLAY_PassList *psl = data->psl;
+ OVERLAY_StorageList *stl = data->stl;
+ OVERLAY_PrivateData *pd = stl->g_data;
+
+ if (pd->overlay.flag & V3D_OVERLAY_FACE_ORIENTATION) {
+ DRW_draw_pass(psl->face_orientation_pass);
+ }
+}
+
+static void overlay_engine_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.face_orientation_sh);
+}
+
+static const DrawEngineDataSize overlay_data_size = DRW_VIEWPORT_DATA_SIZE(OVERLAY_Data);
+
+DrawEngineType draw_engine_overlay_type = {
+ NULL, NULL,
+ N_("OverlayEngine"),
+ &overlay_data_size,
+ &overlay_engine_init,
+ &overlay_engine_free,
+ &overlay_cache_init,
+ &overlay_cache_populate,
+ &overlay_cache_finish,
+ NULL,
+ &overlay_draw_scene,
+ NULL,
+ NULL,
+ NULL,
+};
+
diff --git a/source/blender/draw/modes/paint_texture_mode.c b/source/blender/draw/modes/paint_texture_mode.c
new file mode 100644
index 00000000000..9f25818b272
--- /dev/null
+++ b/source/blender/draw/modes/paint_texture_mode.c
@@ -0,0 +1,418 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/paint_texture_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "BIF_gl.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+#include "GPU_texture.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+#include "DNA_mesh_types.h"
+
+extern char datatoc_common_globals_lib_glsl[];
+extern char datatoc_paint_texture_vert_glsl[];
+extern char datatoc_paint_texture_frag_glsl[];
+extern char datatoc_paint_wire_vert_glsl[];
+extern char datatoc_paint_wire_frag_glsl[];
+
+/* If needed, contains all global/Theme colors
+ * Add needed theme colors / values to DRW_globals_update() and update UBO
+ * Not needed for constant color. */
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use PAINT_TEXTURE_engine_init() to
+ * initialize most of them and PAINT_TEXTURE_cache_init()
+ * for PAINT_TEXTURE_PassList */
+
+typedef struct PAINT_TEXTURE_PassList {
+ /* Declare all passes here and init them in
+ * PAINT_TEXTURE_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *image_faces;
+
+ struct DRWPass *wire_overlay;
+ struct DRWPass *face_overlay;
+} PAINT_TEXTURE_PassList;
+
+typedef struct PAINT_TEXTURE_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} PAINT_TEXTURE_FramebufferList;
+
+typedef struct PAINT_TEXTURE_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} PAINT_TEXTURE_TextureList;
+
+typedef struct PAINT_TEXTURE_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ struct CustomStruct *block;
+ struct PAINT_TEXTURE_PrivateData *g_data;
+} PAINT_TEXTURE_StorageList;
+
+typedef struct PAINT_TEXTURE_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ PAINT_TEXTURE_FramebufferList *fbl;
+ PAINT_TEXTURE_TextureList *txl;
+ PAINT_TEXTURE_PassList *psl;
+ PAINT_TEXTURE_StorageList *stl;
+} PAINT_TEXTURE_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Custom shaders :
+ * Add sources to source/blender/draw/modes/shaders
+ * init in PAINT_TEXTURE_engine_init();
+ * free in PAINT_TEXTURE_engine_free(); */
+ struct GPUShader *fallback_sh;
+ struct GPUShader *image_sh;
+
+ struct GPUShader *wire_overlay_shader;
+ struct GPUShader *face_overlay_shader;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct PAINT_TEXTURE_PrivateData {
+ /* This keeps the references of the shading groups for
+ * easy access in PAINT_TEXTURE_cache_populate() */
+ DRWShadingGroup *shgroup_fallback;
+ DRWShadingGroup **shgroup_image_array;
+
+ /* face-mask */
+ DRWShadingGroup *lwire_shgrp;
+ DRWShadingGroup *face_shgrp;
+} PAINT_TEXTURE_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Init Textures, Framebuffers, Storage and Shaders.
+ * It is called for every frames.
+ * (Optional) */
+static void PAINT_TEXTURE_engine_init(void *vedata)
+{
+ PAINT_TEXTURE_TextureList *txl = ((PAINT_TEXTURE_Data *)vedata)->txl;
+ PAINT_TEXTURE_FramebufferList *fbl = ((PAINT_TEXTURE_Data *)vedata)->fbl;
+ PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
+
+ UNUSED_VARS(txl, fbl, stl);
+
+ /* Init Framebuffers like this: order is attachment order (for color texs) */
+ /*
+ * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
+ * {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
+ */
+
+ /* DRW_framebuffer_init takes care of checking if
+ * the framebuffer is valid and has the right size*/
+ /*
+ * float *viewport_size = DRW_viewport_size_get();
+ * DRW_framebuffer_init(&fbl->occlude_wire_fb,
+ * (int)viewport_size[0], (int)viewport_size[1],
+ * tex, 2);
+ */
+
+ if (!e_data.fallback_sh) {
+ e_data.fallback_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+ if (!e_data.image_sh) {
+ e_data.image_sh = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ e_data.image_sh = DRW_shader_create_with_lib(
+ datatoc_paint_texture_vert_glsl, NULL,
+ datatoc_paint_texture_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+
+ }
+
+ if (!e_data.wire_overlay_shader) {
+ e_data.wire_overlay_shader = DRW_shader_create_with_lib(
+ datatoc_paint_wire_vert_glsl, NULL,
+ datatoc_paint_wire_frag_glsl,
+ datatoc_common_globals_lib_glsl,
+ "#define VERTEX_MODE\n");
+ }
+
+ if (!e_data.face_overlay_shader) {
+ e_data.face_overlay_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+}
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void PAINT_TEXTURE_cache_init(void *vedata)
+{
+ PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
+ PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ stl->g_data->shgroup_image_array = NULL;
+ }
+
+ {
+ /* Create a pass */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
+ DRW_STATE_MULTIPLY | DRW_STATE_WIRE;
+ psl->image_faces = DRW_pass_create("Image Color Pass", state);
+
+ stl->g_data->shgroup_fallback = DRW_shgroup_create(e_data.fallback_sh, psl->image_faces);
+
+ /* Uniforms need a pointer to it's value so be sure it's accessible at
+ * any given time (i.e. use static vars) */
+ static float color[4] = {1.0f, 0.0f, 1.0f, 1.0};
+ DRW_shgroup_uniform_vec4(stl->g_data->shgroup_fallback, "color", color, 1);
+
+ MEM_SAFE_FREE(stl->g_data->shgroup_image_array);
+
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ Object *ob = draw_ctx->obact;
+ if (ob && ob->type == OB_MESH) {
+ Scene *scene = draw_ctx->scene;
+ const bool use_material_slots = (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_MATERIAL);
+ const Mesh *me = ob->data;
+
+ stl->g_data->shgroup_image_array = MEM_mallocN(
+ sizeof(*stl->g_data->shgroup_image_array) * (use_material_slots ? me->totcol : 1), __func__);
+
+ if (use_material_slots) {
+ for (int i = 0; i < me->totcol; i++) {
+ Material *ma = give_current_material(ob, i + 1);
+ Image *ima = (ma && ma->texpaintslot) ? ma->texpaintslot[ma->paint_active_slot].ima : NULL;
+ GPUTexture *tex = ima ?
+ GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, false, false) : NULL;
+
+ if (tex) {
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.image_sh, psl->image_faces);
+ DRW_shgroup_uniform_texture(grp, "image", tex);
+ stl->g_data->shgroup_image_array[i] = grp;
+ }
+ else {
+ stl->g_data->shgroup_image_array[i] = NULL;
+ }
+ }
+ }
+ else {
+ Image *ima = scene->toolsettings->imapaint.canvas;
+ GPUTexture *tex = ima ?
+ GPU_texture_from_blender(ima, NULL, GL_TEXTURE_2D, false, false, false) : NULL;
+
+ if (tex) {
+ DRWShadingGroup *grp = DRW_shgroup_create(e_data.image_sh, psl->image_faces);
+ DRW_shgroup_uniform_texture(grp, "image", tex);
+ stl->g_data->shgroup_image_array[0] = grp;
+ }
+ else {
+ stl->g_data->shgroup_image_array[0] = NULL;
+ }
+ }
+ }
+ }
+
+ /* Face Mask */
+ {
+ psl->wire_overlay = DRW_pass_create(
+ "Wire Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+ stl->g_data->lwire_shgrp = DRW_shgroup_create(e_data.wire_overlay_shader, psl->wire_overlay);
+ }
+
+ {
+ psl->face_overlay = DRW_pass_create(
+ "Face Mask Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
+
+ stl->g_data->face_shgrp = DRW_shgroup_create(e_data.face_overlay_shader, psl->face_overlay);
+
+ static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
+ DRW_shgroup_uniform_vec4(stl->g_data->face_shgrp, "color", col, 1);
+ }
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void PAINT_TEXTURE_cache_populate(void *vedata, Object *ob)
+{
+ PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
+ PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ UNUSED_VARS(psl, stl);
+
+ if ((ob->type == OB_MESH) && (draw_ctx->obact == ob)) {
+ /* Get geometry cache */
+ const Mesh *me = ob->data;
+ Scene *scene = draw_ctx->scene;
+ const bool use_surface = DRW_object_is_mode_shade(ob) == true;
+ const bool use_material_slots = (scene->toolsettings->imapaint.mode == IMAGEPAINT_MODE_MATERIAL);
+ bool ok = false;
+
+ if (use_surface) {
+ if (me->mloopuv != NULL) {
+ if (use_material_slots) {
+ struct Gwn_Batch **geom_array = me->totcol ? DRW_cache_mesh_surface_texpaint_get(ob) : NULL;
+ if ((me->totcol == 0) || (geom_array == NULL)) {
+ struct Gwn_Batch *geom = DRW_cache_mesh_surface_get(ob);
+ DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom, ob->obmat);
+ ok = true;
+ }
+ else {
+ for (int i = 0; i < me->totcol; i++) {
+ if (stl->g_data->shgroup_image_array[i]) {
+ DRW_shgroup_call_add(stl->g_data->shgroup_image_array[i], geom_array[i], ob->obmat);
+ }
+ else {
+ DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom_array[i], ob->obmat);
+ }
+ ok = true;
+ }
+ }
+ }
+ else {
+ struct Gwn_Batch *geom = DRW_cache_mesh_surface_texpaint_single_get(ob);
+ if (geom && stl->g_data->shgroup_image_array[0]) {
+ DRW_shgroup_call_add(stl->g_data->shgroup_image_array[0], geom, ob->obmat);
+ ok = true;
+ }
+ }
+ }
+
+ if (!ok) {
+ struct Gwn_Batch *geom = DRW_cache_mesh_surface_get(ob);
+ DRW_shgroup_call_add(stl->g_data->shgroup_fallback, geom, ob->obmat);
+ }
+ }
+
+ /* Face Mask */
+ const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
+ if (use_face_sel) {
+ struct Gwn_Batch *geom;
+ /* Note: ideally selected faces wouldn't show interior wire. */
+ const bool use_wire = true;
+ geom = DRW_cache_mesh_edges_paint_overlay_get(ob, use_wire, use_face_sel);
+ DRW_shgroup_call_add(stl->g_data->lwire_shgrp, geom, ob->obmat);
+
+ geom = DRW_cache_mesh_faces_weight_overlay_get(ob);
+ DRW_shgroup_call_add(stl->g_data->face_shgrp, geom, ob->obmat);
+ }
+ }
+}
+
+/* Optional: Post-cache_populate callback */
+static void PAINT_TEXTURE_cache_finish(void *vedata)
+{
+ PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
+ PAINT_TEXTURE_StorageList *stl = ((PAINT_TEXTURE_Data *)vedata)->stl;
+
+ /* Do something here! dependant on the objects gathered */
+ UNUSED_VARS(psl);
+
+ MEM_SAFE_FREE(stl->g_data->shgroup_image_array);
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void PAINT_TEXTURE_draw_scene(void *vedata)
+{
+ PAINT_TEXTURE_PassList *psl = ((PAINT_TEXTURE_Data *)vedata)->psl;
+ PAINT_TEXTURE_FramebufferList *fbl = ((PAINT_TEXTURE_Data *)vedata)->fbl;
+
+ /* Default framebuffer and texture */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ UNUSED_VARS(fbl, dfbl, dtxl);
+
+ DRW_draw_pass(psl->image_faces);
+
+ DRW_draw_pass(psl->face_overlay);
+ DRW_draw_pass(psl->wire_overlay);
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void PAINT_TEXTURE_engine_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.image_sh);
+ DRW_SHADER_FREE_SAFE(e_data.wire_overlay_shader);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void PAINT_TEXTURE_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize PAINT_TEXTURE_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_TEXTURE_Data);
+
+DrawEngineType draw_engine_paint_texture_type = {
+ NULL, NULL,
+ N_("PaintTextureMode"),
+ &PAINT_TEXTURE_data_size,
+ &PAINT_TEXTURE_engine_init,
+ &PAINT_TEXTURE_engine_free,
+ &PAINT_TEXTURE_cache_init,
+ &PAINT_TEXTURE_cache_populate,
+ &PAINT_TEXTURE_cache_finish,
+ NULL, /* draw_background but not needed by mode engines */
+ &PAINT_TEXTURE_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/paint_vertex_mode.c b/source/blender/draw/modes/paint_vertex_mode.c
new file mode 100644
index 00000000000..7efa13f1312
--- /dev/null
+++ b/source/blender/draw/modes/paint_vertex_mode.c
@@ -0,0 +1,199 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/paint_vertex_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_view3d_types.h"
+
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+extern char datatoc_paint_vertex_vert_glsl[];
+extern char datatoc_paint_vertex_frag_glsl[];
+extern char datatoc_paint_wire_vert_glsl[];
+extern char datatoc_paint_wire_frag_glsl[];
+extern char datatoc_common_globals_lib_glsl[];
+
+/* *********** LISTS *********** */
+
+typedef struct PAINT_VERTEX_PassList {
+ struct DRWPass *vcolor_faces;
+ struct DRWPass *wire_overlay;
+ struct DRWPass *face_overlay;
+} PAINT_VERTEX_PassList;
+
+typedef struct PAINT_VERTEX_StorageList {
+ struct PAINT_VERTEX_PrivateData *g_data;
+} PAINT_VERTEX_StorageList;
+
+typedef struct PAINT_VERTEX_Data {
+ void *engine_type; /* Required */
+ DRWViewportEmptyList *fbl;
+ DRWViewportEmptyList *txl;
+ PAINT_VERTEX_PassList *psl;
+ PAINT_VERTEX_StorageList *stl;
+} PAINT_VERTEX_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ struct GPUShader *vcolor_face_shader;
+ struct GPUShader *wire_overlay_shader;
+ struct GPUShader *face_overlay_shader;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct PAINT_VERTEX_PrivateData {
+ DRWShadingGroup *fvcolor_shgrp;
+ DRWShadingGroup *lwire_shgrp;
+ DRWShadingGroup *face_shgrp;
+} PAINT_VERTEX_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+static void PAINT_VERTEX_engine_init(void *UNUSED(vedata))
+{
+ if (!e_data.vcolor_face_shader) {
+ e_data.vcolor_face_shader = DRW_shader_create(
+ datatoc_paint_vertex_vert_glsl, NULL,
+ datatoc_paint_vertex_frag_glsl, NULL);
+
+ e_data.wire_overlay_shader = DRW_shader_create_with_lib(
+ datatoc_paint_wire_vert_glsl, NULL,
+ datatoc_paint_wire_frag_glsl,
+ datatoc_common_globals_lib_glsl, "#define VERTEX_MODE\n");
+
+ e_data.face_overlay_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+}
+
+static void PAINT_VERTEX_cache_init(void *vedata)
+{
+ PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl;
+ PAINT_VERTEX_StorageList *stl = ((PAINT_VERTEX_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Create a pass */
+ psl->vcolor_faces = DRW_pass_create(
+ "Vert Color Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_MULTIPLY);
+
+ stl->g_data->fvcolor_shgrp = DRW_shgroup_create(e_data.vcolor_face_shader, psl->vcolor_faces);
+ }
+
+ {
+ psl->wire_overlay = DRW_pass_create(
+ "Wire Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+ stl->g_data->lwire_shgrp = DRW_shgroup_create(e_data.wire_overlay_shader, psl->wire_overlay);
+ }
+
+ {
+ psl->face_overlay = DRW_pass_create(
+ "Face Mask Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
+
+ stl->g_data->face_shgrp = DRW_shgroup_create(e_data.face_overlay_shader, psl->face_overlay);
+
+ static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
+ DRW_shgroup_uniform_vec4(stl->g_data->face_shgrp, "color", col, 1);
+ }
+}
+
+static void PAINT_VERTEX_cache_populate(void *vedata, Object *ob)
+{
+ PAINT_VERTEX_StorageList *stl = ((PAINT_VERTEX_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const View3D *v3d = draw_ctx->v3d;
+
+ if ((ob->type == OB_MESH) && (ob == draw_ctx->obact)) {
+ const Mesh *me = ob->data;
+ const bool use_wire = (v3d->overlay.paint_flag & V3D_OVERLAY_PAINT_WIRE) != 0;
+ const bool use_surface = DRW_object_is_mode_shade(ob) == true;
+ const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
+ struct Gwn_Batch *geom;
+
+ if (use_surface) {
+ geom = DRW_cache_mesh_surface_vert_colors_get(ob);
+ DRW_shgroup_call_add(stl->g_data->fvcolor_shgrp, geom, ob->obmat);
+ }
+
+ if (use_face_sel || use_wire) {
+ geom = DRW_cache_mesh_edges_paint_overlay_get(ob, use_wire, use_face_sel);
+ DRW_shgroup_call_add(stl->g_data->lwire_shgrp, geom, ob->obmat);
+ }
+
+ if (use_face_sel) {
+ geom = DRW_cache_mesh_faces_weight_overlay_get(ob);
+ DRW_shgroup_call_add(stl->g_data->face_shgrp, geom, ob->obmat);
+ }
+ }
+}
+
+static void PAINT_VERTEX_draw_scene(void *vedata)
+{
+ PAINT_VERTEX_PassList *psl = ((PAINT_VERTEX_Data *)vedata)->psl;
+
+ DRW_draw_pass(psl->vcolor_faces);
+ DRW_draw_pass(psl->face_overlay);
+ DRW_draw_pass(psl->wire_overlay);
+}
+
+static void PAINT_VERTEX_engine_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.vcolor_face_shader);
+ DRW_SHADER_FREE_SAFE(e_data.wire_overlay_shader);
+}
+
+static const DrawEngineDataSize PAINT_VERTEX_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_VERTEX_Data);
+
+DrawEngineType draw_engine_paint_vertex_type = {
+ NULL, NULL,
+ N_("PaintVertexMode"),
+ &PAINT_VERTEX_data_size,
+ &PAINT_VERTEX_engine_init,
+ &PAINT_VERTEX_engine_free,
+ &PAINT_VERTEX_cache_init,
+ &PAINT_VERTEX_cache_populate,
+ NULL,
+ NULL,
+ &PAINT_VERTEX_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/paint_weight_mode.c b/source/blender/draw/modes/paint_weight_mode.c
new file mode 100644
index 00000000000..d7ad3e93af7
--- /dev/null
+++ b/source/blender/draw/modes/paint_weight_mode.c
@@ -0,0 +1,243 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/paint_weight_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+#include "DNA_mesh_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_mesh.h"
+
+extern struct GPUUniformBuffer *globals_ubo; /* draw_common.c */
+extern struct GlobalsUboStorage ts; /* draw_common.c */
+
+extern char datatoc_paint_wire_vert_glsl[];
+extern char datatoc_paint_wire_frag_glsl[];
+extern char datatoc_paint_vert_frag_glsl[];
+extern char datatoc_common_globals_lib_glsl[];
+
+/* *********** LISTS *********** */
+
+typedef struct PAINT_WEIGHT_PassList {
+ struct DRWPass *weight_faces;
+ struct DRWPass *wire_overlay;
+ struct DRWPass *face_overlay;
+ struct DRWPass *vert_overlay;
+} PAINT_WEIGHT_PassList;
+
+typedef struct PAINT_WEIGHT_StorageList {
+ struct PAINT_WEIGHT_PrivateData *g_data;
+} PAINT_WEIGHT_StorageList;
+
+typedef struct PAINT_WEIGHT_Data {
+ void *engine_type;
+ DRWViewportEmptyList *fbl;
+ DRWViewportEmptyList *txl;
+ PAINT_WEIGHT_PassList *psl;
+ PAINT_WEIGHT_StorageList *stl;
+} PAINT_WEIGHT_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ struct GPUShader *weight_face_shader;
+ struct GPUShader *wire_overlay_shader;
+ struct GPUShader *face_overlay_shader;
+ struct GPUShader *vert_overlay_shader;
+ int actdef;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct PAINT_WEIGHT_PrivateData {
+ DRWShadingGroup *fweights_shgrp;
+ DRWShadingGroup *lwire_shgrp;
+ DRWShadingGroup *face_shgrp;
+ DRWShadingGroup *vert_shgrp;
+} PAINT_WEIGHT_PrivateData;
+
+/* *********** FUNCTIONS *********** */
+
+static void PAINT_WEIGHT_engine_init(void *UNUSED(vedata))
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ if (e_data.actdef != draw_ctx->obact->actdef) {
+ e_data.actdef = draw_ctx->obact->actdef;
+
+ BKE_mesh_batch_cache_dirty(draw_ctx->obact->data, BKE_MESH_BATCH_DIRTY_ALL);
+ }
+
+ if (!e_data.weight_face_shader) {
+ e_data.weight_face_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR_ALPHA);
+ }
+
+ if (!e_data.wire_overlay_shader) {
+ e_data.wire_overlay_shader = DRW_shader_create_with_lib(
+ datatoc_paint_wire_vert_glsl, NULL,
+ datatoc_paint_wire_frag_glsl,
+ datatoc_common_globals_lib_glsl, "#define WEIGHT_MODE\n");
+ }
+
+ if (!e_data.face_overlay_shader) {
+ e_data.face_overlay_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+
+ if (!e_data.vert_overlay_shader) {
+ e_data.vert_overlay_shader = DRW_shader_create_with_lib(
+ datatoc_paint_wire_vert_glsl, NULL,
+ datatoc_paint_vert_frag_glsl,
+ datatoc_common_globals_lib_glsl, NULL);
+ }
+}
+
+static void PAINT_WEIGHT_cache_init(void *vedata)
+{
+ PAINT_WEIGHT_PassList *psl = ((PAINT_WEIGHT_Data *)vedata)->psl;
+ PAINT_WEIGHT_StorageList *stl = ((PAINT_WEIGHT_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Create a pass */
+ psl->weight_faces = DRW_pass_create(
+ "Weight Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_MULTIPLY);
+
+ stl->g_data->fweights_shgrp = DRW_shgroup_create(e_data.weight_face_shader, psl->weight_faces);
+
+ static float light[3] = {-0.3f, 0.5f, 1.0f};
+ static float alpha = 1.0f;
+ static float world_light = 1.0f;
+ DRW_shgroup_uniform_vec3(stl->g_data->fweights_shgrp, "light", light, 1);
+ DRW_shgroup_uniform_float(stl->g_data->fweights_shgrp, "alpha", &alpha, 1);
+ DRW_shgroup_uniform_float(stl->g_data->fweights_shgrp, "global", &world_light, 1);
+ }
+
+ {
+ psl->wire_overlay = DRW_pass_create(
+ "Wire Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+ stl->g_data->lwire_shgrp = DRW_shgroup_create(e_data.wire_overlay_shader, psl->wire_overlay);
+ }
+
+ {
+ psl->face_overlay = DRW_pass_create(
+ "Face Mask Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND);
+
+ stl->g_data->face_shgrp = DRW_shgroup_create(e_data.face_overlay_shader, psl->face_overlay);
+
+ static float col[4] = {1.0f, 1.0f, 1.0f, 0.2f};
+ DRW_shgroup_uniform_vec4(stl->g_data->face_shgrp, "color", col, 1);
+ }
+
+ {
+ psl->vert_overlay = DRW_pass_create(
+ "Vert Mask Pass",
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS);
+
+ stl->g_data->vert_shgrp = DRW_shgroup_create(e_data.vert_overlay_shader, psl->vert_overlay);
+ }
+}
+
+static void PAINT_WEIGHT_cache_populate(void *vedata, Object *ob)
+{
+ PAINT_WEIGHT_StorageList *stl = ((PAINT_WEIGHT_Data *)vedata)->stl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const View3D *v3d = draw_ctx->v3d;
+
+ if ((ob->type == OB_MESH) && (ob == draw_ctx->obact)) {
+ const Mesh *me = ob->data;
+ const bool use_wire = (v3d->overlay.paint_flag & V3D_OVERLAY_PAINT_WIRE) != 0;
+ const bool use_surface = DRW_object_is_mode_shade(ob) == true;
+ const bool use_face_sel = (me->editflag & ME_EDIT_PAINT_FACE_SEL) != 0;
+ const bool use_vert_sel = (me->editflag & ME_EDIT_PAINT_VERT_SEL) != 0;
+ struct Gwn_Batch *geom;
+
+ if (use_surface) {
+ geom = DRW_cache_mesh_surface_weights_get(ob);
+ DRW_shgroup_call_add(stl->g_data->fweights_shgrp, geom, ob->obmat);
+ }
+
+ if (use_face_sel || use_wire) {
+ geom = DRW_cache_mesh_edges_paint_overlay_get(ob, use_wire, use_face_sel);
+ DRW_shgroup_call_add(stl->g_data->lwire_shgrp, geom, ob->obmat);
+ }
+
+ if (use_face_sel) {
+ geom = DRW_cache_mesh_faces_weight_overlay_get(ob);
+ DRW_shgroup_call_add(stl->g_data->face_shgrp, geom, ob->obmat);
+ }
+
+ if (use_vert_sel) {
+ geom = DRW_cache_mesh_verts_weight_overlay_get(ob);
+ DRW_shgroup_call_add(stl->g_data->vert_shgrp, geom, ob->obmat);
+ }
+ }
+}
+
+static void PAINT_WEIGHT_draw_scene(void *vedata)
+{
+ PAINT_WEIGHT_PassList *psl = ((PAINT_WEIGHT_Data *)vedata)->psl;
+
+ DRW_draw_pass(psl->weight_faces);
+ DRW_draw_pass(psl->face_overlay);
+ DRW_draw_pass(psl->wire_overlay);
+ DRW_draw_pass(psl->vert_overlay);
+}
+
+static void PAINT_WEIGHT_engine_free(void)
+{
+ DRW_SHADER_FREE_SAFE(e_data.wire_overlay_shader);
+ DRW_SHADER_FREE_SAFE(e_data.vert_overlay_shader);
+}
+
+static const DrawEngineDataSize PAINT_WEIGHT_data_size = DRW_VIEWPORT_DATA_SIZE(PAINT_WEIGHT_Data);
+
+DrawEngineType draw_engine_paint_weight_type = {
+ NULL, NULL,
+ N_("PaintWeightMode"),
+ &PAINT_WEIGHT_data_size,
+ &PAINT_WEIGHT_engine_init,
+ &PAINT_WEIGHT_engine_free,
+ &PAINT_WEIGHT_cache_init,
+ &PAINT_WEIGHT_cache_populate,
+ NULL,
+ NULL,
+ &PAINT_WEIGHT_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/particle_mode.c b/source/blender/draw/modes/particle_mode.c
new file mode 100644
index 00000000000..f022a68aa8a
--- /dev/null
+++ b/source/blender/draw/modes/particle_mode.c
@@ -0,0 +1,265 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/particle_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use PARTICLE_engine_init() to
+ * initialize most of them and PARTICLE_cache_init()
+ * for PARTICLE_PassList */
+
+typedef struct PARTICLE_PassList {
+ /* Declare all passes here and init them in
+ * PARTICLE_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *pass;
+} PARTICLE_PassList;
+
+typedef struct PARTICLE_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} PARTICLE_FramebufferList;
+
+typedef struct PARTICLE_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} PARTICLE_TextureList;
+
+typedef struct PARTICLE_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ struct CustomStruct *block;
+ struct PARTICLE_PrivateData *g_data;
+} PARTICLE_StorageList;
+
+typedef struct PARTICLE_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ PARTICLE_FramebufferList *fbl;
+ PARTICLE_TextureList *txl;
+ PARTICLE_PassList *psl;
+ PARTICLE_StorageList *stl;
+} PARTICLE_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Custom shaders :
+ * Add sources to source/blender/draw/modes/shaders
+ * init in PARTICLE_engine_init();
+ * free in PARTICLE_engine_free(); */
+ struct GPUShader *custom_shader;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct PARTICLE_PrivateData {
+ /* This keeps the references of the shading groups for
+ * easy access in PARTICLE_cache_populate() */
+ DRWShadingGroup *group;
+} PARTICLE_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Init Textures, Framebuffers, Storage and Shaders.
+ * It is called for every frames.
+ * (Optional) */
+static void PARTICLE_engine_init(void *vedata)
+{
+ PARTICLE_TextureList *txl = ((PARTICLE_Data *)vedata)->txl;
+ PARTICLE_FramebufferList *fbl = ((PARTICLE_Data *)vedata)->fbl;
+ PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
+
+ UNUSED_VARS(txl, fbl, stl);
+
+ /* Init Framebuffers like this: order is attachment order (for color texs) */
+ /*
+ * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
+ * {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
+ */
+
+ /* DRW_framebuffer_init takes care of checking if
+ * the framebuffer is valid and has the right size*/
+ /*
+ * float *viewport_size = DRW_viewport_size_get();
+ * DRW_framebuffer_init(&fbl->occlude_wire_fb,
+ * (int)viewport_size[0], (int)viewport_size[1],
+ * tex, 2);
+ */
+
+ if (!e_data.custom_shader) {
+ e_data.custom_shader = GPU_shader_get_builtin_shader(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+}
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void PARTICLE_cache_init(void *vedata)
+{
+ PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
+ PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Create a pass */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND | DRW_STATE_WIRE;
+ psl->pass = DRW_pass_create("My Pass", state);
+
+ /* Create a shadingGroup using a function in draw_common.c or custom one */
+ /*
+ * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire);
+ * -- or --
+ * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
+ */
+ stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
+
+ /* Uniforms need a pointer to it's value so be sure it's accessible at
+ * any given time (i.e. use static vars) */
+ static float color[4] = {0.2f, 0.5f, 0.3f, 1.0};
+ DRW_shgroup_uniform_vec4(stl->g_data->group, "color", color, 1);
+ }
+
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void PARTICLE_cache_populate(void *vedata, Object *ob)
+{
+ PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
+ PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
+
+ UNUSED_VARS(psl, stl);
+
+ if (ob->type == OB_MESH) {
+ /* Get geometry cache */
+ struct Gwn_Batch *geom = DRW_cache_mesh_surface_get(ob);
+
+ /* Add geom to a shading group */
+ DRW_shgroup_call_add(stl->g_data->group, geom, ob->obmat);
+ }
+}
+
+/* Optional: Post-cache_populate callback */
+static void PARTICLE_cache_finish(void *vedata)
+{
+ PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
+ PARTICLE_StorageList *stl = ((PARTICLE_Data *)vedata)->stl;
+
+ /* Do something here! dependant on the objects gathered */
+ UNUSED_VARS(psl, stl);
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void PARTICLE_draw_scene(void *vedata)
+{
+
+ PARTICLE_PassList *psl = ((PARTICLE_Data *)vedata)->psl;
+ PARTICLE_FramebufferList *fbl = ((PARTICLE_Data *)vedata)->fbl;
+
+ /* Default framebuffer and texture */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ UNUSED_VARS(fbl, dfbl, dtxl, psl);
+
+ /* Show / hide entire passes, swap framebuffers ... whatever you fancy */
+ /*
+ * DRW_framebuffer_texture_detach(dtxl->depth);
+ * DRW_framebuffer_bind(fbl->custom_fb);
+ * DRW_draw_pass(psl->pass);
+ * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
+ * DRW_framebuffer_bind(dfbl->default_fb);
+ */
+
+ /* ... or just render passes on default framebuffer. */
+ //DRW_draw_pass(psl->pass);
+
+ /* If you changed framebuffer, double check you rebind
+ * the default one with its textures attached before finishing */
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void PARTICLE_engine_free(void)
+{
+ // DRW_SHADER_FREE_SAFE(custom_shader);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void PARTICLE_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize PARTICLE_data_size = DRW_VIEWPORT_DATA_SIZE(PARTICLE_Data);
+
+DrawEngineType draw_engine_particle_type = {
+ NULL, NULL,
+ N_("ParticleMode"),
+ &PARTICLE_data_size,
+ &PARTICLE_engine_init,
+ &PARTICLE_engine_free,
+ &PARTICLE_cache_init,
+ &PARTICLE_cache_populate,
+ &PARTICLE_cache_finish,
+ NULL, /* draw_background but not needed by mode engines */
+ &PARTICLE_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/pose_mode.c b/source/blender/draw/modes/pose_mode.c
new file mode 100644
index 00000000000..a7fc1da959b
--- /dev/null
+++ b/source/blender/draw/modes/pose_mode.c
@@ -0,0 +1,240 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/pose_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+#include "DNA_view3d_types.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+extern GlobalsUboStorage ts;
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use POSE_engine_init() to
+ * initialize most of them and POSE_cache_init()
+ * for POSE_PassList */
+
+typedef struct POSE_PassList {
+ struct DRWPass *bone_solid;
+ struct DRWPass *bone_outline;
+ struct DRWPass *bone_wire;
+ struct DRWPass *bone_envelope;
+ struct DRWPass *bone_axes;
+ struct DRWPass *relationship;
+} POSE_PassList;
+
+typedef struct POSE_StorageList {
+ struct POSE_PrivateData *g_data;
+} POSE_StorageList;
+
+typedef struct POSE_Data {
+ void *engine_type;
+ DRWViewportEmptyList *fbl;
+ DRWViewportEmptyList *txl;
+ POSE_PassList *psl;
+ POSE_StorageList *stl;
+} POSE_Data;
+
+/* *********** STATIC *********** */
+
+typedef struct POSE_PrivateData {
+ char pad; /* UNUSED */
+} POSE_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void POSE_cache_init(void *vedata)
+{
+ POSE_PassList *psl = ((POSE_Data *)vedata)->psl;
+ POSE_StorageList *stl = ((POSE_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Solid bones */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_BACK;
+ psl->bone_solid = DRW_pass_create("Bone Solid Pass", state);
+ }
+
+ {
+ /* Bones Outline */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS;
+ psl->bone_outline = DRW_pass_create("Bone Outline Pass", state);
+ }
+
+ {
+ /* Wire bones */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS | DRW_STATE_BLEND;
+ psl->bone_wire = DRW_pass_create("Bone Wire Pass", state);
+ }
+
+ {
+ /* distance outline around envelope bones */
+ DRWState state = DRW_STATE_ADDITIVE | DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_LESS | DRW_STATE_CULL_FRONT;
+ psl->bone_envelope = DRW_pass_create("Bone Envelope Outline Pass", state);
+ }
+
+ {
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_WIRE_SMOOTH | DRW_STATE_BLEND;
+ psl->bone_axes = DRW_pass_create("Bone Axes Pass", state);
+ }
+
+ {
+ /* Non Meshes Pass (Camera, empties, lamps ...) */
+ DRWState state =
+ DRW_STATE_WRITE_COLOR | DRW_STATE_WRITE_DEPTH | DRW_STATE_DEPTH_LESS |
+ DRW_STATE_BLEND | DRW_STATE_WIRE;
+ psl->relationship = DRW_pass_create("Bone Relationship Pass", state);
+ }
+}
+
+/* Add geometry to shading groups. Execute for each objects */
+static void POSE_cache_populate(void *vedata, Object *ob)
+{
+ POSE_PassList *psl = ((POSE_Data *)vedata)->psl;
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ /* In the future this will allow us to implement face manipulators,
+ * and similar functionalities. For now we handle only pose bones. */
+
+ if (ob->type == OB_ARMATURE) {
+ if (DRW_pose_mode_armature(ob, draw_ctx->obact)) {
+ DRWArmaturePasses passes = {
+ .bone_solid = psl->bone_solid,
+ .bone_outline = psl->bone_outline,
+ .bone_wire = psl->bone_wire,
+ .bone_envelope = psl->bone_envelope,
+ .bone_axes = psl->bone_axes,
+ .relationship_lines = psl->relationship,
+ };
+ DRW_shgroup_armature_pose(ob, passes);
+ }
+ }
+}
+
+/**
+ * Return true if armature should be handled by the pose mode engine.
+ */
+bool DRW_pose_mode_armature(Object *ob, Object *active_ob)
+{
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ /* Pose armature is handled by pose mode engine. */
+ if (((ob == active_ob) || (ob->base_flag & BASE_SELECTED)) &&
+ ((draw_ctx->object_mode & OB_MODE_POSE) != 0))
+ {
+ return true;
+ }
+
+ /* Armature parent is also handled by pose mode engine. */
+ if ((active_ob != NULL) && ((draw_ctx->object_mode & OB_MODE_WEIGHT_PAINT) != 0)) {
+ if (ob == draw_ctx->object_pose) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void POSE_draw_scene(void *vedata)
+{
+ POSE_PassList *psl = ((POSE_Data *)vedata)->psl;
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+ const bool transparent_bones = (draw_ctx->v3d->overlay.arm_flag & V3D_OVERLAY_ARM_TRANSP_BONES) != 0;
+
+ DRW_draw_pass(psl->bone_envelope);
+
+ if (transparent_bones) {
+ DRW_pass_state_add(psl->bone_solid, DRW_STATE_BLEND);
+ DRW_pass_state_remove(psl->bone_solid, DRW_STATE_WRITE_DEPTH);
+ DRW_draw_pass(psl->bone_solid);
+ }
+
+ MULTISAMPLE_SYNC_ENABLE(dfbl, dtxl)
+
+ if (!transparent_bones) {
+ DRW_draw_pass(psl->bone_solid);
+ }
+
+ DRW_draw_pass(psl->bone_outline);
+ DRW_draw_pass(psl->bone_wire);
+ DRW_draw_pass(psl->relationship);
+
+ MULTISAMPLE_SYNC_DISABLE(dfbl, dtxl)
+
+ /* Draw axes with linesmooth and outside of multisample buffer. */
+ DRW_draw_pass(psl->bone_axes);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void POSE_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "foo", 37);
+}
+#endif
+
+static const DrawEngineDataSize POSE_data_size = DRW_VIEWPORT_DATA_SIZE(POSE_Data);
+
+DrawEngineType draw_engine_pose_type = {
+ NULL, NULL,
+ N_("PoseMode"),
+ &POSE_data_size,
+ NULL,
+ NULL,
+ &POSE_cache_init,
+ &POSE_cache_populate,
+ NULL,
+ NULL,
+ &POSE_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/sculpt_mode.c b/source/blender/draw/modes/sculpt_mode.c
new file mode 100644
index 00000000000..70e40a83539
--- /dev/null
+++ b/source/blender/draw/modes/sculpt_mode.c
@@ -0,0 +1,302 @@
+/*
+ * Copyright 2016, Blender Foundation.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Institute
+ *
+ */
+
+/** \file blender/draw/modes/sculpt_mode.c
+ * \ingroup draw
+ */
+
+#include "DRW_engine.h"
+#include "DRW_render.h"
+
+#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_meshdata_types.h"
+
+#include "BKE_pbvh.h"
+#include "BKE_paint.h"
+
+#include "DEG_depsgraph.h"
+
+/* If builtin shaders are needed */
+#include "GPU_shader.h"
+#include "GPU_matrix.h"
+
+#include "draw_common.h"
+
+#include "draw_mode_engines.h"
+
+/* *********** LISTS *********** */
+/* All lists are per viewport specific datas.
+ * They are all free when viewport changes engines
+ * or is free itself. Use SCULPT_engine_init() to
+ * initialize most of them and SCULPT_cache_init()
+ * for SCULPT_PassList */
+
+typedef struct SCULPT_PassList {
+ /* Declare all passes here and init them in
+ * SCULPT_cache_init().
+ * Only contains (DRWPass *) */
+ struct DRWPass *pass;
+} SCULPT_PassList;
+
+typedef struct SCULPT_FramebufferList {
+ /* Contains all framebuffer objects needed by this engine.
+ * Only contains (GPUFrameBuffer *) */
+ struct GPUFrameBuffer *fb;
+} SCULPT_FramebufferList;
+
+typedef struct SCULPT_TextureList {
+ /* Contains all framebuffer textures / utility textures
+ * needed by this engine. Only viewport specific textures
+ * (not per object). Only contains (GPUTexture *) */
+ struct GPUTexture *texture;
+} SCULPT_TextureList;
+
+typedef struct SCULPT_StorageList {
+ /* Contains any other memory block that the engine needs.
+ * Only directly MEM_(m/c)allocN'ed blocks because they are
+ * free with MEM_freeN() when viewport is freed.
+ * (not per object) */
+ struct CustomStruct *block;
+ struct SCULPT_PrivateData *g_data;
+} SCULPT_StorageList;
+
+typedef struct SCULPT_Data {
+ /* Struct returned by DRW_viewport_engine_data_ensure.
+ * If you don't use one of these, just make it a (void *) */
+ // void *fbl;
+ void *engine_type; /* Required */
+ SCULPT_FramebufferList *fbl;
+ SCULPT_TextureList *txl;
+ SCULPT_PassList *psl;
+ SCULPT_StorageList *stl;
+} SCULPT_Data;
+
+/* *********** STATIC *********** */
+
+static struct {
+ /* Custom shaders :
+ * Add sources to source/blender/draw/modes/shaders
+ * init in SCULPT_engine_init();
+ * free in SCULPT_engine_free(); */
+ struct GPUShader *shader_flat;
+ struct GPUShader *shader_smooth;
+} e_data = {NULL}; /* Engine data */
+
+typedef struct SCULPT_PrivateData {
+ /* This keeps the references of the shading groups for
+ * easy access in SCULPT_cache_populate() */
+ DRWShadingGroup *group_flat;
+ DRWShadingGroup *group_smooth;
+} SCULPT_PrivateData; /* Transient data */
+
+/* *********** FUNCTIONS *********** */
+
+/* Init Textures, Framebuffers, Storage and Shaders.
+ * It is called for every frames.
+ * (Optional) */
+static void SCULPT_engine_init(void *vedata)
+{
+ SCULPT_TextureList *txl = ((SCULPT_Data *)vedata)->txl;
+ SCULPT_FramebufferList *fbl = ((SCULPT_Data *)vedata)->fbl;
+ SCULPT_StorageList *stl = ((SCULPT_Data *)vedata)->stl;
+
+ UNUSED_VARS(txl, fbl, stl);
+
+ /* Init Framebuffers like this: order is attachment order (for color texs) */
+ /*
+ * DRWFboTexture tex[2] = {{&txl->depth, GPU_DEPTH_COMPONENT24, 0},
+ * {&txl->color, GPU_RGBA8, DRW_TEX_FILTER}};
+ */
+
+ /* DRW_framebuffer_init takes care of checking if
+ * the framebuffer is valid and has the right size*/
+ /*
+ * float *viewport_size = DRW_viewport_size_get();
+ * DRW_framebuffer_init(&fbl->occlude_wire_fb,
+ * (int)viewport_size[0], (int)viewport_size[1],
+ * tex, 2);
+ */
+
+ if (!e_data.shader_flat) {
+ e_data.shader_flat = GPU_shader_get_builtin_shader(GPU_SHADER_3D_FLAT_COLOR);
+ }
+ if (!e_data.shader_smooth) {
+ e_data.shader_smooth = GPU_shader_get_builtin_shader(GPU_SHADER_3D_SMOOTH_COLOR);
+ }
+}
+
+/* Here init all passes and shading groups
+ * Assume that all Passes are NULL */
+static void SCULPT_cache_init(void *vedata)
+{
+ SCULPT_PassList *psl = ((SCULPT_Data *)vedata)->psl;
+ SCULPT_StorageList *stl = ((SCULPT_Data *)vedata)->stl;
+
+ if (!stl->g_data) {
+ /* Alloc transient pointers */
+ stl->g_data = MEM_mallocN(sizeof(*stl->g_data), __func__);
+ }
+
+ {
+ /* Create a pass */
+ DRWState state = DRW_STATE_WRITE_COLOR | DRW_STATE_DEPTH_EQUAL | DRW_STATE_MULTIPLY;
+ psl->pass = DRW_pass_create("Sculpt Pass", state);
+
+ /* Create a shadingGroup using a function in draw_common.c or custom one */
+ /*
+ * stl->g_data->group = shgroup_dynlines_uniform_color(psl->pass, ts.colorWire);
+ * -- or --
+ * stl->g_data->group = DRW_shgroup_create(e_data.custom_shader, psl->pass);
+ */
+ stl->g_data->group_flat = DRW_shgroup_create(e_data.shader_flat, psl->pass);
+ stl->g_data->group_smooth = DRW_shgroup_create(e_data.shader_smooth, psl->pass);
+ }
+}
+
+static bool object_is_flat(const Object *ob)
+{
+ Mesh *me = ob->data;
+ if (me->mpoly && me->mpoly[0].flag & ME_SMOOTH) {
+ return false;
+ }
+ else {
+ return true;
+ }
+}
+
+/* Add geometry to shadingGroups. Execute for each objects */
+static void SCULPT_cache_populate(void *vedata, Object *ob)
+{
+ SCULPT_PassList *psl = ((SCULPT_Data *)vedata)->psl;
+ SCULPT_StorageList *stl = ((SCULPT_Data *)vedata)->stl;
+
+ UNUSED_VARS(psl, stl);
+
+ if (ob->type == OB_MESH) {
+ const DRWContextState *draw_ctx = DRW_context_state_get();
+
+ if (ob->sculpt && (ob == draw_ctx->obact)) {
+ /* XXX, needed for dyntopo-undo (which clears).
+ * probably depsgraph should handlle? in 2.7x getting derived-mesh does this (mesh_build_data) */
+ if (ob->sculpt->pbvh == NULL) {
+ /* create PBVH immediately (would be created on the fly too,
+ * but this avoids waiting on first stroke) */
+ Scene *scene = draw_ctx->scene;
+
+ BKE_sculpt_update_mesh_elements(draw_ctx->depsgraph, scene, scene->toolsettings->sculpt, ob, false, false);
+ }
+
+ PBVH *pbvh = ob->sculpt->pbvh;
+ if (pbvh && pbvh_has_mask(pbvh)) {
+ /* Get geometry cache */
+ DRWShadingGroup *shgroup = object_is_flat(ob) ? stl->g_data->group_flat : stl->g_data->group_smooth;
+
+ /* Add geom to a shading group */
+ DRW_shgroup_call_sculpt_add(shgroup, ob, ob->obmat);
+ }
+ }
+ }
+}
+
+/* Optional: Post-cache_populate callback */
+static void SCULPT_cache_finish(void *vedata)
+{
+ SCULPT_PassList *psl = ((SCULPT_Data *)vedata)->psl;
+ SCULPT_StorageList *stl = ((SCULPT_Data *)vedata)->stl;
+
+ /* Do something here! dependant on the objects gathered */
+ UNUSED_VARS(psl, stl);
+}
+
+/* Draw time ! Control rendering pipeline from here */
+static void SCULPT_draw_scene(void *vedata)
+{
+ SCULPT_PassList *psl = ((SCULPT_Data *)vedata)->psl;
+ SCULPT_FramebufferList *fbl = ((SCULPT_Data *)vedata)->fbl;
+
+ /* Default framebuffer and texture */
+ DefaultFramebufferList *dfbl = DRW_viewport_framebuffer_list_get();
+ DefaultTextureList *dtxl = DRW_viewport_texture_list_get();
+
+ UNUSED_VARS(fbl, dfbl, dtxl);
+
+ /* Show / hide entire passes, swap framebuffers ... whatever you fancy */
+ /*
+ * DRW_framebuffer_texture_detach(dtxl->depth);
+ * DRW_framebuffer_bind(fbl->custom_fb);
+ * DRW_draw_pass(psl->pass);
+ * DRW_framebuffer_texture_attach(dfbl->default_fb, dtxl->depth, 0, 0);
+ * DRW_framebuffer_bind(dfbl->default_fb);
+ */
+
+ /* ... or just render passes on default framebuffer. */
+ DRW_draw_pass(psl->pass);
+
+ /* If you changed framebuffer, double check you rebind
+ * the default one with its textures attached before finishing */
+}
+
+/* Cleanup when destroying the engine.
+ * This is not per viewport ! only when quitting blender.
+ * Mostly used for freeing shaders */
+static void SCULPT_engine_free(void)
+{
+ // DRW_SHADER_FREE_SAFE(custom_shader);
+}
+
+/* Create collection settings here.
+ *
+ * Be sure to add this function there :
+ * source/blender/draw/DRW_engine.h
+ * source/blender/blenkernel/intern/layer.c
+ * source/blenderplayer/bad_level_call_stubs/stubs.c
+ *
+ * And relevant collection settings to :
+ * source/blender/makesrna/intern/rna_scene.c
+ * source/blender/blenkernel/intern/layer.c
+ */
+#if 0
+void SCULPT_collection_settings_create(CollectionEngineSettings *ces)
+{
+ BLI_assert(ces);
+ // BKE_collection_engine_property_add_int(ces, "my_bool_prop", false);
+ // BKE_collection_engine_property_add_int(ces, "my_int_prop", 0);
+ // BKE_collection_engine_property_add_float(ces, "my_float_prop", 0.0f);
+}
+#endif
+
+static const DrawEngineDataSize SCULPT_data_size = DRW_VIEWPORT_DATA_SIZE(SCULPT_Data);
+
+DrawEngineType draw_engine_sculpt_type = {
+ NULL, NULL,
+ N_("SculptMode"),
+ &SCULPT_data_size,
+ &SCULPT_engine_init,
+ &SCULPT_engine_free,
+ &SCULPT_cache_init,
+ &SCULPT_cache_populate,
+ &SCULPT_cache_finish,
+ NULL, /* draw_background but not needed by mode engines */
+ &SCULPT_draw_scene,
+ NULL,
+ NULL,
+};
diff --git a/source/blender/draw/modes/shaders/armature_axes_vert.glsl b/source/blender/draw/modes/shaders/armature_axes_vert.glsl
new file mode 100644
index 00000000000..fe6edba1316
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_axes_vert.glsl
@@ -0,0 +1,30 @@
+
+uniform mat4 ViewProjectionMatrix;
+uniform vec3 screenVecs[3];
+
+/* ---- Instanciated Attribs ---- */
+in float axis; /* position on the axis. [0.0-1.0] is X axis, [1.0-2.0] is Y, etc... */
+in vec2 screenPos;
+in vec3 colorAxis;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec4 color;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ vec3 chosen_axis = InstanceModelMatrix[int(axis)].xyz;
+ vec3 y_axis = InstanceModelMatrix[1].xyz;
+ vec3 bone_loc = InstanceModelMatrix[3].xyz;
+ vec3 wpos = bone_loc + y_axis + chosen_axis * fract(axis);
+ vec3 spos = screenVecs[0].xyz * screenPos.x + screenVecs[1].xyz * screenPos.y;
+ /* Scale uniformly by axis length */
+ spos *= length(chosen_axis);
+
+ gl_Position = ViewProjectionMatrix * vec4(wpos + spos, 1.0);
+
+ finalColor.rgb = mix(colorAxis, color.rgb, color.a);
+ finalColor.a = 1.0;
+}
diff --git a/source/blender/draw/modes/shaders/armature_envelope_distance_frag.glsl b/source/blender/draw/modes/shaders/armature_envelope_distance_frag.glsl
new file mode 100644
index 00000000000..cecc5447c7c
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_envelope_distance_frag.glsl
@@ -0,0 +1,15 @@
+
+flat in vec3 finalStateColor; /* UNUSED */
+flat in vec3 finalBoneColor; /* UNUSED */
+in vec3 normalView;
+
+out vec4 fragColor;
+
+uniform vec4 color = vec4(1.0, 1.0, 1.0, 0.2);
+
+void main()
+{
+ float n = normalize(normalView).z;
+ n = 1.0 - clamp(-n, 0.0, 1.0);
+ fragColor = color * n;
+}
diff --git a/source/blender/draw/modes/shaders/armature_envelope_outline_vert.glsl b/source/blender/draw/modes/shaders/armature_envelope_outline_vert.glsl
new file mode 100644
index 00000000000..a836d7fa9e1
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_envelope_outline_vert.glsl
@@ -0,0 +1,156 @@
+
+uniform mat4 ViewMatrix;
+uniform mat4 ViewMatrixInverse;
+uniform mat4 ViewProjectionMatrix;
+uniform mat4 ProjectionMatrix;
+
+uniform vec2 viewportSize;
+uniform float lineThickness = 2.0;
+
+/* ---- Instanciated Attribs ---- */
+in vec2 pos0;
+in vec2 pos1;
+in vec2 pos2;
+
+/* ---- Per instance Attribs ---- */
+/* Assumed to be in world coordinate already. */
+in vec4 headSphere;
+in vec4 tailSphere;
+in vec4 outlineColorSize;
+in vec3 xAxis;
+
+flat out vec4 finalColor;
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+vec2 compute_dir(vec2 v0, vec2 v1, vec2 v2)
+{
+ vec2 dir = normalize(v2 - v0);
+ dir = vec2(dir.y, -dir.x);
+ return dir;
+}
+
+mat3 compute_mat(vec4 sphere, vec3 bone_vec, out float z_ofs)
+{
+ bool is_persp = (ProjectionMatrix[3][3] == 0.0);
+ vec3 cam_ray = (is_persp) ? sphere.xyz - ViewMatrixInverse[3].xyz
+ : -ViewMatrixInverse[2].xyz;
+
+ /* Sphere center distance from the camera (persp) in world space. */
+ float cam_dist = length(cam_ray);
+
+ /* Compute view aligned orthonormal space. */
+ vec3 z_axis = cam_ray / cam_dist;
+ vec3 x_axis = normalize(cross(bone_vec, z_axis));
+ vec3 y_axis = cross(z_axis, x_axis);
+ z_ofs = 0.0;
+
+ if (is_persp) {
+ /* For perspective, the projected sphere radius
+ * can be bigger than the center disc. Compute the
+ * max angular size and compensate by sliding the disc
+ * towards the camera and scale it accordingly. */
+ const float half_pi = 3.1415926 * 0.5;
+ float rad = sphere.w;
+ /* Let be :
+ * V the view vector origin.
+ * O the sphere origin.
+ * T the point on the target circle.
+ * We compute the angle between (OV) and (OT). */
+ float a = half_pi - asin(rad / cam_dist);
+ float cos_b = cos(a);
+ float sin_b = sqrt(clamp(1.0 - cos_b * cos_b, 0.0, 1.0));
+
+ x_axis *= sin_b;
+ y_axis *= sin_b;
+ z_ofs = -rad * cos_b;
+ }
+
+ return mat3(x_axis, y_axis, z_axis);
+}
+
+struct Bone { vec3 vec; float sinb; };
+
+bool bone_blend_starts(vec3 p, Bone b)
+{
+ /* we just want to know when the head sphere starts interpolating. */
+ return dot(p, b.vec) > -b.sinb;
+}
+
+vec3 get_outline_point(
+ vec2 pos, vec4 sph_near, vec4 sph_far,
+ mat3 mat_near, mat3 mat_far, float z_ofs_near, float z_ofs_far, Bone b)
+{
+ /* Compute outline position on the nearest sphere and check
+ * if it penetrates the capsule body. If it does, put this
+ * vertex on the farthest sphere. */
+ vec3 wpos = mat_near * vec3(pos * sph_near.w, z_ofs_near);
+ if (bone_blend_starts(wpos, b)) {
+ wpos = sph_far.xyz + mat_far * vec3(pos * sph_far.w, z_ofs_far);
+ }
+ else {
+ wpos += sph_near.xyz;
+ }
+ return wpos;
+}
+
+void main()
+{
+ float dst_head = distance(headSphere.xyz, ViewMatrixInverse[3].xyz);
+ float dst_tail = distance(tailSphere.xyz, ViewMatrixInverse[3].xyz);
+ // float dst_head = -dot(headSphere.xyz, ViewMatrix[2].xyz);
+ // float dst_tail = -dot(tailSphere.xyz, ViewMatrix[2].xyz);
+
+ vec4 sph_near, sph_far;
+ if ((dst_head > dst_tail) && (ProjectionMatrix[3][3] == 0.0)) {
+ sph_near = tailSphere;
+ sph_far = headSphere;
+ }
+ else {
+ sph_near = headSphere;
+ sph_far = tailSphere;
+ }
+
+ vec3 bone_vec = (sph_far.xyz - sph_near.xyz) + 1e-8;
+
+ Bone b;
+ float bone_lenrcp = 1.0 / max(1e-8, sqrt(dot(bone_vec, bone_vec)));
+ b.sinb = (sph_far.w - sph_near.w) * bone_lenrcp * sph_near.w;
+ b.vec = bone_vec * bone_lenrcp;
+
+ float z_ofs_near, z_ofs_far;
+ mat3 mat_near = compute_mat(sph_near, bone_vec, z_ofs_near);
+ mat3 mat_far = compute_mat(sph_far, bone_vec, z_ofs_far);
+
+ vec3 wpos0 = get_outline_point(pos0, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
+ vec3 wpos1 = get_outline_point(pos1, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
+ vec3 wpos2 = get_outline_point(pos2, sph_near, sph_far, mat_near, mat_far, z_ofs_near, z_ofs_far, b);
+
+ vec4 V = ViewMatrix * vec4(wpos1, 1.0);
+ float pres_fac = (ProjectionMatrix[3][3] == 0.0) ? abs(V.z) : 1.0;
+
+ vec4 p0 = ViewProjectionMatrix * vec4(wpos0, 1.0);
+ vec4 p1 = ProjectionMatrix * V;
+ vec4 p2 = ViewProjectionMatrix * vec4(wpos2, 1.0);
+
+ /* compute position from 3 vertex because the change in direction
+ * can happen very quicky and lead to very thin edges. */
+ vec2 ss0 = proj(p0);
+ vec2 ss1 = proj(p1);
+ vec2 ss2 = proj(p2);
+ vec2 edge_dir = compute_dir(ss0, ss1, ss2);
+
+ bool outer = ((gl_VertexID & 1) == 1);
+ vec2 t = outlineColorSize.w * (lineThickness / viewportSize);
+ t *= pres_fac;
+ t = (outer) ? t : vec2(0.0);
+
+ gl_Position = p1;
+ gl_Position.xy += t * edge_dir;
+
+ finalColor = vec4(outlineColorSize.rgb, 1.0);
+}
diff --git a/source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl b/source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl
new file mode 100644
index 00000000000..b20656ff326
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_envelope_solid_frag.glsl
@@ -0,0 +1,16 @@
+
+flat in vec3 finalStateColor;
+flat in vec3 finalBoneColor;
+in vec3 normalView;
+
+out vec4 fragColor;
+
+void main()
+{
+ /* Smooth lighting factor. */
+ const float s = 0.2; /* [0.0-0.5] range */
+ float n = normalize(normalView).z;
+ float fac = clamp((n * (1.0 - s)) + s, 0.0, 1.0);
+ fragColor.rgb = mix(finalStateColor, finalBoneColor, fac);
+ fragColor.a = 0.6; /* Hardcoded transparency factor. */
+}
diff --git a/source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl b/source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl
new file mode 100644
index 00000000000..83ae720e70a
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_envelope_solid_vert.glsl
@@ -0,0 +1,55 @@
+
+uniform mat4 ViewMatrix;
+uniform mat4 ViewMatrixInverse;
+uniform mat4 ViewProjectionMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+
+/* ---- Per instance Attribs ---- */
+/* Assumed to be in world coordinate already. */
+in vec4 headSphere;
+in vec4 tailSphere;
+in vec3 xAxis;
+in vec3 stateColor;
+in vec3 boneColor;
+
+flat out vec3 finalStateColor;
+flat out vec3 finalBoneColor;
+out vec3 normalView;
+
+void main()
+{
+ vec3 bone_vec = tailSphere.xyz - headSphere.xyz;
+ float bone_len = max(1e-8, sqrt(dot(bone_vec, bone_vec)));
+ float bone_lenrcp = 1.0 / bone_len;
+#ifdef SMOOTH_ENVELOPE
+ float sinb = (tailSphere.w - headSphere.w) * bone_lenrcp;
+#else
+ const float sinb = 0.0;
+#endif
+
+ vec3 y_axis = bone_vec * bone_lenrcp;
+ vec3 z_axis = normalize(cross(xAxis, -y_axis));
+ vec3 x_axis = cross(y_axis, z_axis); /* cannot trust xAxis to be orthogonal. */
+
+ vec3 sp, nor;
+ nor = sp = pos.xyz;
+
+ /* In bone space */
+ bool is_head = (pos.z < -sinb);
+ sp *= (is_head) ? headSphere.w : tailSphere.w;
+ sp.z += (is_head) ? 0.0 : bone_len;
+
+ /* Convert to world space */
+ mat3 bone_mat = mat3(x_axis, y_axis, z_axis);
+ sp = bone_mat * sp.xzy + headSphere.xyz;
+ nor = bone_mat * nor.xzy;
+
+ normalView = mat3(ViewMatrix) * nor;
+
+ gl_Position = ViewProjectionMatrix * vec4(sp, 1.0);
+
+ finalStateColor = stateColor;
+ finalBoneColor = boneColor;
+}
diff --git a/source/blender/draw/modes/shaders/armature_shape_outline_geom.glsl b/source/blender/draw/modes/shaders/armature_shape_outline_geom.glsl
new file mode 100644
index 00000000000..dc7ed5e202a
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_shape_outline_geom.glsl
@@ -0,0 +1,95 @@
+
+/* TODO: See perf with multiple invocations. */
+layout(triangles_adjacency) in;
+layout(triangle_strip, max_vertices = 16) out;
+
+in vec4 pPos[];
+in float vZ[];
+in float vFacing[];
+in vec2 ssPos[];
+in vec2 ssNor[];
+in vec4 vColSize[];
+
+flat out vec4 finalColor;
+uniform mat4 ProjectionMatrix;
+uniform vec2 viewportSize;
+uniform float lineThickness = 2.0;
+
+vec2 compute_dir(vec2 v0, vec2 v1)
+{
+ vec2 dir = normalize(v1 - v0);
+ dir = vec2(-dir.y, dir.x);
+ return dir;
+}
+
+void emit_edge(const ivec3 edges, vec2 thick, bool is_persp)
+{
+ vec2 edge_dir = compute_dir(ssPos[edges.x], ssPos[edges.y]);
+ vec2 hidden_dir = normalize(ssPos[edges.z] - ssPos[edges.x]);
+
+ float fac = dot(-hidden_dir, edge_dir);
+
+ vec2 t = thick * (is_persp ? vZ[edges.x] : 1.0);
+ gl_Position = pPos[edges.x];
+ EmitVertex();
+ gl_Position.xy += t * edge_dir * sign(fac);
+ EmitVertex();
+
+ t = thick * (is_persp ? vZ[edges.y] : 1.0);
+ gl_Position = pPos[edges.y];
+ EmitVertex();
+ gl_Position.xy += t * edge_dir * sign(fac);
+ EmitVertex();
+}
+
+void emit_corner(const int e, vec2 thick, bool is_persp)
+{
+ vec2 corner_dir = ssNor[e];
+ vec2 t = thick * (is_persp ? vZ[e] : 1.0);
+
+ gl_Position = pPos[e] + vec4(t * corner_dir, 0.0, 0.0);
+ EmitVertex();
+}
+
+void main(void)
+{
+ finalColor = vec4(vColSize[0].rgb, 1.0);
+
+ vec2 thick = vColSize[0].w * (lineThickness / viewportSize);
+ bool is_persp = (ProjectionMatrix[3][3] == 0.0);
+
+ const ivec3 edges = ivec3(0, 2, 4);
+ vec4 facing = vec4(vFacing[1], vFacing[3], vFacing[5], vFacing[0]);
+ bvec4 do_edge = greaterThanEqual(facing, vec4(0.0));
+
+ /* Only generate outlines from backfaces. */
+ if (do_edge.w)
+ return;
+
+ if (do_edge.x) {
+ emit_corner(edges.x, thick, is_persp);
+ emit_edge(edges.xyz, thick, is_persp);
+ }
+
+ if (any(do_edge.xy)) {
+ emit_corner(edges.y, thick, is_persp);
+ }
+
+ if (do_edge.y) {
+ emit_edge(edges.yzx, thick, is_persp);
+ }
+ else {
+ EndPrimitive();
+ }
+
+ if (any(do_edge.yz)) {
+ emit_corner(edges.z, thick, is_persp);
+ }
+
+ if (do_edge.z) {
+ emit_edge(edges.zxy, thick, is_persp);
+ emit_corner(edges.x, thick, is_persp);
+ }
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl b/source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl
new file mode 100644
index 00000000000..0d09114579c
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_shape_outline_vert.glsl
@@ -0,0 +1,59 @@
+
+uniform mat3 NormalMatrix;
+
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform vec2 viewportSize;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+in vec3 nor;
+in vec3 snor;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec4 outlineColorSize;
+
+out vec4 pPos;
+out float vZ;
+out float vFacing;
+out vec2 ssPos;
+out vec2 ssNor;
+out vec4 vColSize;
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+void main()
+{
+ /* This is slow and run per vertex, but it's still faster than
+ * doing it per instance on CPU and sending it on via instance attrib */
+ mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
+
+ vec4 viewpos = ViewMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
+ pPos = ProjectionMatrix * viewpos;
+ vZ = abs(viewpos.z);
+
+ /* if perspective */
+ vec3 V = (ProjectionMatrix[3][3] == 0.0) ? normalize(-viewpos.xyz) : vec3(0.0, 0.0, 1.0);
+
+ /* TODO FIX: there is still a problem with this vector
+ * when the bone is scaled or in persp mode. But it's
+ * barelly visible at the outline corners. */
+ ssNor = normalize((NormalMatrix * snor).xy);
+
+ vec3 normal = normalize(NormalMatrix * nor);
+ /* Add a small bias to avoid loosing outline
+ * on faces orthogonal to the view.
+ * (test case: octahedral bone without rotation in front view.) */
+ normal.z += 1e-6;
+
+ vFacing = dot(V, normal);
+
+ ssPos = proj(pPos);
+
+ vColSize = outlineColorSize;
+}
diff --git a/source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl b/source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl
new file mode 100644
index 00000000000..248281f4e79
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_shape_solid_frag.glsl
@@ -0,0 +1,9 @@
+
+flat in vec4 finalColor;
+
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = vec4(finalColor.rgb, 0.6); /* Hardcoded transparency factor. */
+}
diff --git a/source/blender/draw/modes/shaders/armature_shape_solid_vert.glsl b/source/blender/draw/modes/shaders/armature_shape_solid_vert.glsl
new file mode 100644
index 00000000000..701fc9c38ab
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_shape_solid_vert.glsl
@@ -0,0 +1,37 @@
+
+uniform mat3 NormalMatrix;
+uniform mat4 ViewMatrixInverse;
+uniform mat4 ViewProjectionMatrix;
+
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform vec2 viewportSize;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+in vec3 nor;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec3 boneColor;
+in vec3 stateColor;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
+ vec3 normal = normalize(NormalMatrix * nor);
+
+ /* Do lighting at an angle to avoid flat shading on front facing bone. */
+ const vec3 light = vec3(0.1, 0.1, 0.8);
+ float n = dot(normal, light);
+
+ /* Smooth lighting factor. */
+ const float s = 0.2; /* [0.0-0.5] range */
+ float fac = clamp((n * (1.0 - s)) + s, 0.0, 1.0);
+ finalColor.rgb = mix(stateColor, boneColor, fac);
+ finalColor.a = 1.0;
+
+ gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(pos, 1.0));
+}
diff --git a/source/blender/draw/modes/shaders/armature_sphere_outline_vert.glsl b/source/blender/draw/modes/shaders/armature_sphere_outline_vert.glsl
new file mode 100644
index 00000000000..a169facd45a
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_sphere_outline_vert.glsl
@@ -0,0 +1,102 @@
+
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform vec2 viewportSize;
+uniform float lineThickness = 2.0;
+
+/* ---- Instanciated Attribs ---- */
+in vec2 pos0;
+in vec2 pos1;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec4 outlineColorSize;
+
+flat out vec4 finalColor;
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+vec2 compute_dir(vec2 v0, vec2 v1, vec2 c)
+{
+ vec2 dir = normalize(v1 - v0);
+ dir = vec2(dir.y, -dir.x);
+ /* The model matrix can be scaled negativly.
+ * Use projected sphere center to determine
+ * the outline direction. */
+ vec2 cv = c - v0;
+ dir = (dot(dir, cv) > 0.0) ? -dir : dir;
+ return dir;
+}
+
+void main()
+{
+ mat4 model_view_matrix = ViewMatrix * InstanceModelMatrix;
+ mat4 sphereMatrix = inverse(model_view_matrix);
+
+ bool is_persp = (ProjectionMatrix[3][3] == 0.0);
+
+ /* This is the local space camera ray (not normalize).
+ * In perspective mode it's also the viewspace position
+ * of the sphere center. */
+ vec3 cam_ray = (is_persp) ? model_view_matrix[3].xyz : vec3(0.0, 0.0, -1.0);
+ cam_ray = mat3(sphereMatrix) * cam_ray;
+
+ /* Sphere center distance from the camera (persp) in local space. */
+ float cam_dist = length(cam_ray);
+
+ /* Compute view aligned orthonormal space. */
+ vec3 z_axis = cam_ray / cam_dist;
+ vec3 x_axis = normalize(cross(sphereMatrix[1].xyz, z_axis));
+ vec3 y_axis = cross(z_axis, x_axis);
+ float z_ofs = 0.0;
+
+ if (is_persp) {
+ /* For perspective, the projected sphere radius
+ * can be bigger than the center disc. Compute the
+ * max angular size and compensate by sliding the disc
+ * towards the camera and scale it accordingly. */
+ const float half_pi = 3.1415926 * 0.5;
+ const float rad = 0.05;
+ /* Let be (in local space):
+ * V the view vector origin.
+ * O the sphere origin.
+ * T the point on the target circle.
+ * We compute the angle between (OV) and (OT). */
+ float a = half_pi - asin(rad / cam_dist);
+ float cos_b = cos(a);
+ float sin_b = sqrt(clamp(1.0 - cos_b * cos_b, 0.0, 1.0));
+
+ x_axis *= sin_b;
+ y_axis *= sin_b;
+ z_ofs = -rad * cos_b;
+ }
+
+ /* Camera oriented position (but still in local space) */
+ vec3 cam_pos0 = x_axis * pos0.x + y_axis * pos0.y + z_axis * z_ofs;
+ vec3 cam_pos1 = x_axis * pos1.x + y_axis * pos1.y + z_axis * z_ofs;
+
+ vec4 V = model_view_matrix * vec4(cam_pos0, 1.0);
+ vec4 p0 = ProjectionMatrix * V;
+ vec4 p1 = ProjectionMatrix * (model_view_matrix * vec4(cam_pos1, 1.0));
+ vec4 c = ProjectionMatrix * vec4(model_view_matrix[3].xyz, 1.0);
+
+ vec2 ssc = proj(c);
+ vec2 ss0 = proj(p0);
+ vec2 ss1 = proj(p1);
+ vec2 edge_dir = compute_dir(ss0, ss1, ssc);
+
+ bool outer = ((gl_VertexID & 1) == 1);
+
+ vec2 t = outlineColorSize.w * (lineThickness / viewportSize);
+ t *= (is_persp) ? abs(V.z) : 1.0;
+ t = (outer) ? t : vec2(0.0);
+
+ gl_Position = p0;
+ gl_Position.xy += t * edge_dir;
+
+ finalColor = vec4(outlineColorSize.rgb, 1.0);
+}
diff --git a/source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl b/source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl
new file mode 100644
index 00000000000..3c80f629d79
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_sphere_solid_frag.glsl
@@ -0,0 +1,81 @@
+
+#extension GL_ARB_conservative_depth : enable
+
+uniform mat4 ViewMatrixInverse;
+uniform mat4 ProjectionMatrix;
+
+flat in vec3 finalStateColor;
+flat in vec3 finalBoneColor;
+flat in mat4 sphereMatrix;
+in vec3 viewPosition;
+
+#ifdef GL_ARB_conservative_depth
+/* Saves a lot of overdraw! */
+layout(depth_greater) out float gl_FragDepth;
+#endif
+
+out vec4 fragColor;
+
+#define cameraPos ViewMatrixInverse[3].xyz
+
+float get_depth_from_view_z(float z)
+{
+ if (ProjectionMatrix[3][3] == 0.0) {
+ z = (-ProjectionMatrix[3][2] / z) - ProjectionMatrix[2][2];
+ }
+ else {
+ z = z * ProjectionMatrix[2][2] / (1.0 - ProjectionMatrix[3][2]);
+ }
+ return z * 0.5 + 0.5;
+}
+
+void main()
+{
+ const float sphere_radius = 0.05;
+
+ bool is_perp = (ProjectionMatrix[3][3] == 0.0);
+ vec3 ray_ori_view = (is_perp) ? vec3(0.0) : viewPosition.xyz;
+ vec3 ray_dir_view = (is_perp) ? viewPosition : vec3(0.0, 0.0, -1.0);
+
+ /* Single matrix mul without branch. */
+ vec4 mul_vec = (is_perp) ? vec4(ray_dir_view, 0.0) : vec4(ray_ori_view, 1.0);
+ vec3 mul_res = (sphereMatrix * mul_vec).xyz;
+
+ /* Reminder :
+ * sphereMatrix[3] is the view space origin in sphere space (sph_ori -> view_ori).
+ * sphereMatrix[2] is the view space Z axis in sphere space. */
+
+ /* convert to sphere local space */
+ vec3 ray_ori = (is_perp) ? sphereMatrix[3].xyz : mul_res;
+ vec3 ray_dir = (is_perp) ? mul_res : -sphereMatrix[2].xyz;
+ float ray_len = length(ray_dir);
+ ray_dir /= ray_len;
+
+ /* Line to sphere intersect */
+ const float sphere_radius_sqr = sphere_radius * sphere_radius;
+ float b = dot(ray_ori, ray_dir);
+ float c = dot(ray_ori, ray_ori) - sphere_radius_sqr;
+ float h = b * b - c;
+ float t = -sqrt(max(0.0, h)) - b;
+
+ /* Compute dot product for lighting */
+ vec3 p = ray_dir * t + ray_ori; /* Point on sphere */
+ vec3 n = normalize(p); /* Normal is just the point in sphere space, normalized. */
+ vec3 l = normalize(sphereMatrix[2].xyz); /* Just the view Z axis in the sphere space. */
+
+
+ /* Smooth lighting factor. */
+ const float s = 0.2; /* [0.0-0.5] range */
+ float fac = clamp((dot(n, l) * (1.0 - s)) + s, 0.0, 1.0);
+ fragColor.rgb = mix(finalStateColor, finalBoneColor, fac);
+
+ /* 2x2 dither pattern to smooth the lighting. */
+ float dither = (0.5 + dot(vec2(ivec2(gl_FragCoord.xy) & ivec2(1)), vec2(1.0, 2.0))) * 0.25;
+ dither *= (1.0 / 255.0); /* Assume 8bit per color buffer. */
+
+ /* Hardcoded transparency factor. Less than shape to be less distractive. */
+ fragColor = vec4(fragColor.rgb + dither, 0.4);
+
+ t /= ray_len;
+ gl_FragDepth = get_depth_from_view_z(ray_dir_view.z * t + ray_ori_view.z);
+}
diff --git a/source/blender/draw/modes/shaders/armature_sphere_solid_vert.glsl b/source/blender/draw/modes/shaders/armature_sphere_solid_vert.glsl
new file mode 100644
index 00000000000..1e06047054e
--- /dev/null
+++ b/source/blender/draw/modes/shaders/armature_sphere_solid_vert.glsl
@@ -0,0 +1,82 @@
+
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in vec2 pos;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec3 stateColor;
+in vec3 boneColor;
+
+flat out vec3 finalStateColor;
+flat out vec3 finalBoneColor;
+flat out mat4 sphereMatrix;
+out vec3 viewPosition;
+
+/* Sphere radius */
+const float rad = 0.05;
+
+void main()
+{
+ mat4 model_view_matrix = ViewMatrix * InstanceModelMatrix;
+ sphereMatrix = inverse(model_view_matrix);
+
+ bool is_persp = (ProjectionMatrix[3][3] == 0.0);
+
+ /* This is the local space camera ray (not normalize).
+ * In perspective mode it's also the viewspace position
+ * of the sphere center. */
+ vec3 cam_ray = (is_persp) ? model_view_matrix[3].xyz : vec3(0.0, 0.0, -1.0);
+ cam_ray = mat3(sphereMatrix) * cam_ray;
+
+ /* Sphere center distance from the camera (persp) in local space. */
+ float cam_dist = length(cam_ray);
+
+ /* Compute view aligned orthonormal space. */
+ vec3 z_axis = cam_ray / cam_dist;
+ vec3 x_axis = normalize(cross(sphereMatrix[1].xyz, z_axis));
+ vec3 y_axis = cross(z_axis, x_axis);
+
+ float z_ofs = -rad - 1e-8; /* offset to the front of the sphere */
+ if (is_persp) {
+ /* For perspective, the projected sphere radius
+ * can be bigger than the center disc. Compute the
+ * max angular size and compensate by sliding the disc
+ * towards the camera and scale it accordingly. */
+ const float half_pi = 3.1415926 * 0.5;
+ /* Let be (in local space):
+ * V the view vector origin.
+ * O the sphere origin.
+ * T the point on the target circle.
+ * We compute the angle between (OV) and (OT). */
+ float a = half_pi - asin(rad / cam_dist);
+ float cos_b = cos(a);
+ float sin_b = sqrt(clamp(1.0 - cos_b * cos_b, 0.0, 1.0));
+#if 1
+ /* Instead of choosing the biggest circle in screenspace,
+ * we choose the nearest with the same angular size. This
+ * permit us to leverage GL_ARB_conservative_depth in the
+ * fragment shader. */
+ float minor = cam_dist - rad;
+ float major = cam_dist - cos_b * rad;
+ float fac = minor / major;
+ sin_b *= fac;
+#else
+ z_ofs = -rad * cos_b;
+#endif
+ x_axis *= sin_b;
+ y_axis *= sin_b;
+ }
+
+ /* Camera oriented position (but still in local space) */
+ vec3 cam_pos = x_axis * pos.x + y_axis * pos.y + z_axis * z_ofs;
+
+ vec4 V = model_view_matrix * vec4(cam_pos, 1.0);
+ gl_Position = ProjectionMatrix * V;
+ viewPosition = V.xyz;
+
+ finalStateColor = stateColor;
+ finalBoneColor = boneColor;
+}
diff --git a/source/blender/draw/modes/shaders/common_fullscreen_vert.glsl b/source/blender/draw/modes/shaders/common_fullscreen_vert.glsl
new file mode 100644
index 00000000000..fc5cc1cdcc3
--- /dev/null
+++ b/source/blender/draw/modes/shaders/common_fullscreen_vert.glsl
@@ -0,0 +1,10 @@
+
+in vec2 pos;
+in vec2 uvs;
+out vec4 uvcoordsvar;
+
+void main()
+{
+ uvcoordsvar = vec4(uvs, 0.0, 0.0);
+ gl_Position = vec4(pos, 0.0, 1.0);
+}
diff --git a/source/blender/draw/modes/shaders/common_fxaa_lib.glsl b/source/blender/draw/modes/shaders/common_fxaa_lib.glsl
new file mode 100644
index 00000000000..8158437b943
--- /dev/null
+++ b/source/blender/draw/modes/shaders/common_fxaa_lib.glsl
@@ -0,0 +1,678 @@
+//----------------------------------------------------------------------------------
+// File: es3-kepler\FXAA/FXAA3_11.h
+// SDK Version: v3.00
+// Email: gameworks@nvidia.com
+// Site: http://developer.nvidia.com/
+//
+// Copyright (c) 2014-2015, NVIDIA CORPORATION. All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+// * Redistributions of source code must retain the above copyright
+// notice, this list of conditions and the following disclaimer.
+// * Redistributions in binary form must reproduce the above copyright
+// notice, this list of conditions and the following disclaimer in the
+// documentation and/or other materials provided with the distribution.
+// * Neither the name of NVIDIA CORPORATION nor the names of its
+// contributors may be used to endorse or promote products derived
+// from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY
+// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+// OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+//----------------------------------------------------------------------------------
+
+/* BLENDER MODIFICATIONS:
+ *
+ * - (#B1#) Compute luma on the fly using BT. 709 luma function
+ * - (#B2#) main function instead of #include, due to lack of
+ * ARB_shading_language_include in 3.3
+ * - (#B3#) version and extension directives
+ * - removed "FXAA Console" algorithm support and shader parameters
+ * - removed HLSL support shims
+ * - (#B4#) change luma sampling to compute, not use A channel
+ * (this also removes GATHER4_ALPHA support)
+ * - removed all the console shaders (only remaining algorithm is "FXAA PC
+ * Quality")
+ *
+ * Note that this file doesn't follow the coding style guidelines.
+ */
+
+/*============================================================================
+ FXAA QUALITY - TUNING KNOBS
+------------------------------------------------------------------------------
+NOTE the other tuning knobs are now in the shader function inputs!
+============================================================================*/
+#ifndef FXAA_QUALITY__PRESET
+ //
+ // Choose the quality preset.
+ // This needs to be compiled into the shader as it effects code.
+ // Best option to include multiple presets is to
+ // in each shader define the preset, then include this file.
+ //
+ // OPTIONS
+ // -----------------------------------------------------------------------
+ // 10 to 15 - default medium dither (10=fastest, 15=highest quality)
+ // 20 to 29 - less dither, more expensive (20=fastest, 29=highest quality)
+ // 39 - no dither, very expensive
+ //
+ // NOTES
+ // -----------------------------------------------------------------------
+ // 12 = slightly faster then FXAA 3.9 and higher edge quality (default)
+ // 13 = about same speed as FXAA 3.9 and better than 12
+ // 23 = closest to FXAA 3.9 visually and performance wise
+ // _ = the lowest digit is directly related to performance
+ // _ = the highest digit is directly related to style
+ //
+ #define FXAA_QUALITY__PRESET 12
+#endif
+
+/*============================================================================
+
+ FXAA QUALITY - PRESETS
+
+============================================================================*/
+
+/*============================================================================
+ FXAA QUALITY - MEDIUM DITHER PRESETS
+============================================================================*/
+#if (FXAA_QUALITY__PRESET == 10)
+ #define FXAA_QUALITY__PS 3
+ #define FXAA_QUALITY__P0 1.5
+ #define FXAA_QUALITY__P1 3.0
+ #define FXAA_QUALITY__P2 12.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 11)
+ #define FXAA_QUALITY__PS 4
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 3.0
+ #define FXAA_QUALITY__P3 12.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 12)
+ #define FXAA_QUALITY__PS 5
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 4.0
+ #define FXAA_QUALITY__P4 12.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 13)
+ #define FXAA_QUALITY__PS 6
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 4.0
+ #define FXAA_QUALITY__P5 12.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 14)
+ #define FXAA_QUALITY__PS 7
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 4.0
+ #define FXAA_QUALITY__P6 12.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 15)
+ #define FXAA_QUALITY__PS 8
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 2.0
+ #define FXAA_QUALITY__P6 4.0
+ #define FXAA_QUALITY__P7 12.0
+#endif
+
+/*============================================================================
+ FXAA QUALITY - LOW DITHER PRESETS
+============================================================================*/
+#if (FXAA_QUALITY__PRESET == 20)
+ #define FXAA_QUALITY__PS 3
+ #define FXAA_QUALITY__P0 1.5
+ #define FXAA_QUALITY__P1 2.0
+ #define FXAA_QUALITY__P2 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 21)
+ #define FXAA_QUALITY__PS 4
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 22)
+ #define FXAA_QUALITY__PS 5
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 23)
+ #define FXAA_QUALITY__PS 6
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 24)
+ #define FXAA_QUALITY__PS 7
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 3.0
+ #define FXAA_QUALITY__P6 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 25)
+ #define FXAA_QUALITY__PS 8
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 2.0
+ #define FXAA_QUALITY__P6 4.0
+ #define FXAA_QUALITY__P7 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 26)
+ #define FXAA_QUALITY__PS 9
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 2.0
+ #define FXAA_QUALITY__P6 2.0
+ #define FXAA_QUALITY__P7 4.0
+ #define FXAA_QUALITY__P8 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 27)
+ #define FXAA_QUALITY__PS 10
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 2.0
+ #define FXAA_QUALITY__P6 2.0
+ #define FXAA_QUALITY__P7 2.0
+ #define FXAA_QUALITY__P8 4.0
+ #define FXAA_QUALITY__P9 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 28)
+ #define FXAA_QUALITY__PS 11
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 2.0
+ #define FXAA_QUALITY__P6 2.0
+ #define FXAA_QUALITY__P7 2.0
+ #define FXAA_QUALITY__P8 2.0
+ #define FXAA_QUALITY__P9 4.0
+ #define FXAA_QUALITY__P10 8.0
+#endif
+/*--------------------------------------------------------------------------*/
+#if (FXAA_QUALITY__PRESET == 29)
+ #define FXAA_QUALITY__PS 12
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.5
+ #define FXAA_QUALITY__P2 2.0
+ #define FXAA_QUALITY__P3 2.0
+ #define FXAA_QUALITY__P4 2.0
+ #define FXAA_QUALITY__P5 2.0
+ #define FXAA_QUALITY__P6 2.0
+ #define FXAA_QUALITY__P7 2.0
+ #define FXAA_QUALITY__P8 2.0
+ #define FXAA_QUALITY__P9 2.0
+ #define FXAA_QUALITY__P10 4.0
+ #define FXAA_QUALITY__P11 8.0
+#endif
+
+/*============================================================================
+ FXAA QUALITY - EXTREME QUALITY
+============================================================================*/
+#if (FXAA_QUALITY__PRESET == 39)
+ #define FXAA_QUALITY__PS 12
+ #define FXAA_QUALITY__P0 1.0
+ #define FXAA_QUALITY__P1 1.0
+ #define FXAA_QUALITY__P2 1.0
+ #define FXAA_QUALITY__P3 1.0
+ #define FXAA_QUALITY__P4 1.0
+ #define FXAA_QUALITY__P5 1.5
+ #define FXAA_QUALITY__P6 2.0
+ #define FXAA_QUALITY__P7 2.0
+ #define FXAA_QUALITY__P8 2.0
+ #define FXAA_QUALITY__P9 2.0
+ #define FXAA_QUALITY__P10 4.0
+ #define FXAA_QUALITY__P11 8.0
+#endif
+
+#define FxaaSat(x) clamp(x, 0.0, 1.0)
+
+#ifdef FXAA_ALPHA
+
+#define FxaaTexTop(t, p) textureLod(t, p, 0.0).aaaa
+#define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o).aaaa
+#define FxaaLuma(rgba) rgba.a
+
+#else
+
+#define FxaaTexTop(t, p) textureLod(t, p, 0.0)
+#define FxaaTexOff(t, p, o, r) textureLodOffset(t, p, 0.0, o)
+
+/* (#B1#) */
+float FxaaLuma(vec4 rgba) {
+ // note: sqrt because the sampled colors are in a linear colorspace!
+ // this approximates a perceptual conversion, which is good enough for the
+ // algorithm
+ return sqrt(dot(rgba.rgb, vec3(0.2126, 0.7152, 0.0722)));
+}
+
+#endif
+
+/*============================================================================
+
+ FXAA3 QUALITY - PC
+
+============================================================================*/
+/*--------------------------------------------------------------------------*/
+vec4 FxaaPixelShader(
+ //
+ // Use noperspective interpolation here (turn off perspective interpolation).
+ // {xy} = center of pixel
+ vec2 pos,
+ //
+ // Input color texture.
+ // {rgb_} = color in linear or perceptual color space
+ sampler2D tex,
+ //
+ // Only used on FXAA Quality.
+ // This must be from a constant/uniform.
+ // {x_} = 1.0/screenWidthInPixels
+ // {_y} = 1.0/screenHeightInPixels
+ vec2 fxaaQualityRcpFrame,
+ //
+ // Only used on FXAA Quality.
+ // This used to be the FXAA_QUALITY__SUBPIX define.
+ // It is here now to allow easier tuning.
+ // Choose the amount of sub-pixel aliasing removal.
+ // This can effect sharpness.
+ // 1.00 - upper limit (softer)
+ // 0.75 - default amount of filtering
+ // 0.50 - lower limit (sharper, less sub-pixel aliasing removal)
+ // 0.25 - almost off
+ // 0.00 - completely off
+ float fxaaQualitySubpix,
+ //
+ // Only used on FXAA Quality.
+ // This used to be the FXAA_QUALITY__EDGE_THRESHOLD define.
+ // It is here now to allow easier tuning.
+ // The minimum amount of local contrast required to apply algorithm.
+ // 0.333 - too little (faster)
+ // 0.250 - low quality
+ // 0.166 - default
+ // 0.125 - high quality
+ // 0.063 - overkill (slower)
+ float fxaaQualityEdgeThreshold,
+ //
+ // Only used on FXAA Quality.
+ // This used to be the FXAA_QUALITY__EDGE_THRESHOLD_MIN define.
+ // It is here now to allow easier tuning.
+ // Trims the algorithm from processing darks.
+ // 0.0833 - upper limit (default, the start of visible unfiltered edges)
+ // 0.0625 - high quality (faster)
+ // 0.0312 - visible limit (slower)
+ float fxaaQualityEdgeThresholdMin
+) {
+/*--------------------------------------------------------------------------*/
+ vec2 posM;
+ posM.x = pos.x;
+ posM.y = pos.y;
+ vec4 rgbyM = FxaaTexTop(tex, posM);
+ float lumaM = FxaaLuma(rgbyM); // (#B4#)
+ float lumaS = FxaaLuma(FxaaTexOff(tex, posM, ivec2( 0, 1), fxaaQualityRcpFrame.xy));
+ float lumaE = FxaaLuma(FxaaTexOff(tex, posM, ivec2( 1, 0), fxaaQualityRcpFrame.xy));
+ float lumaN = FxaaLuma(FxaaTexOff(tex, posM, ivec2( 0,-1), fxaaQualityRcpFrame.xy));
+ float lumaW = FxaaLuma(FxaaTexOff(tex, posM, ivec2(-1, 0), fxaaQualityRcpFrame.xy));
+/*--------------------------------------------------------------------------*/
+ float maxSM = max(lumaS, lumaM);
+ float minSM = min(lumaS, lumaM);
+ float maxESM = max(lumaE, maxSM);
+ float minESM = min(lumaE, minSM);
+ float maxWN = max(lumaN, lumaW);
+ float minWN = min(lumaN, lumaW);
+ float rangeMax = max(maxWN, maxESM);
+ float rangeMin = min(minWN, minESM);
+ float rangeMaxScaled = rangeMax * fxaaQualityEdgeThreshold;
+ float range = rangeMax - rangeMin;
+ float rangeMaxClamped = max(fxaaQualityEdgeThresholdMin, rangeMaxScaled);
+ bool earlyExit = range < rangeMaxClamped;
+/*--------------------------------------------------------------------------*/
+ if(earlyExit) {
+ return rgbyM;
+ }
+/*--------------------------------------------------------------------------*/
+ float lumaNW = FxaaLuma(FxaaTexOff(tex, posM, ivec2(-1,-1), fxaaQualityRcpFrame.xy));
+ float lumaSE = FxaaLuma(FxaaTexOff(tex, posM, ivec2( 1, 1), fxaaQualityRcpFrame.xy));
+ float lumaNE = FxaaLuma(FxaaTexOff(tex, posM, ivec2( 1,-1), fxaaQualityRcpFrame.xy));
+ float lumaSW = FxaaLuma(FxaaTexOff(tex, posM, ivec2(-1, 1), fxaaQualityRcpFrame.xy));
+/*--------------------------------------------------------------------------*/
+ float lumaNS = lumaN + lumaS;
+ float lumaWE = lumaW + lumaE;
+ float subpixRcpRange = 1.0/range;
+ float subpixNSWE = lumaNS + lumaWE;
+ float edgeHorz1 = (-2.0 * lumaM) + lumaNS;
+ float edgeVert1 = (-2.0 * lumaM) + lumaWE;
+/*--------------------------------------------------------------------------*/
+ float lumaNESE = lumaNE + lumaSE;
+ float lumaNWNE = lumaNW + lumaNE;
+ float edgeHorz2 = (-2.0 * lumaE) + lumaNESE;
+ float edgeVert2 = (-2.0 * lumaN) + lumaNWNE;
+/*--------------------------------------------------------------------------*/
+ float lumaNWSW = lumaNW + lumaSW;
+ float lumaSWSE = lumaSW + lumaSE;
+ float edgeHorz4 = (abs(edgeHorz1) * 2.0) + abs(edgeHorz2);
+ float edgeVert4 = (abs(edgeVert1) * 2.0) + abs(edgeVert2);
+ float edgeHorz3 = (-2.0 * lumaW) + lumaNWSW;
+ float edgeVert3 = (-2.0 * lumaS) + lumaSWSE;
+ float edgeHorz = abs(edgeHorz3) + edgeHorz4;
+ float edgeVert = abs(edgeVert3) + edgeVert4;
+/*--------------------------------------------------------------------------*/
+ float subpixNWSWNESE = lumaNWSW + lumaNESE;
+ float lengthSign = fxaaQualityRcpFrame.x;
+ bool horzSpan = edgeHorz >= edgeVert;
+ float subpixA = subpixNSWE * 2.0 + subpixNWSWNESE;
+/*--------------------------------------------------------------------------*/
+ if(!horzSpan) lumaN = lumaW;
+ if(!horzSpan) lumaS = lumaE;
+ if(horzSpan) lengthSign = fxaaQualityRcpFrame.y;
+ float subpixB = (subpixA * (1.0/12.0)) - lumaM;
+/*--------------------------------------------------------------------------*/
+ float gradientN = lumaN - lumaM;
+ float gradientS = lumaS - lumaM;
+ float lumaNN = lumaN + lumaM;
+ float lumaSS = lumaS + lumaM;
+ bool pairN = abs(gradientN) >= abs(gradientS);
+ float gradient = max(abs(gradientN), abs(gradientS));
+ if(pairN) lengthSign = -lengthSign;
+ float subpixC = FxaaSat(abs(subpixB) * subpixRcpRange);
+/*--------------------------------------------------------------------------*/
+ vec2 posB;
+ posB.x = posM.x;
+ posB.y = posM.y;
+ vec2 offNP;
+ offNP.x = (!horzSpan) ? 0.0 : fxaaQualityRcpFrame.x;
+ offNP.y = ( horzSpan) ? 0.0 : fxaaQualityRcpFrame.y;
+ if(!horzSpan) posB.x += lengthSign * 0.5;
+ if( horzSpan) posB.y += lengthSign * 0.5;
+/*--------------------------------------------------------------------------*/
+ vec2 posN;
+ posN.x = posB.x - offNP.x * FXAA_QUALITY__P0;
+ posN.y = posB.y - offNP.y * FXAA_QUALITY__P0;
+ vec2 posP;
+ posP.x = posB.x + offNP.x * FXAA_QUALITY__P0;
+ posP.y = posB.y + offNP.y * FXAA_QUALITY__P0;
+ float subpixD = ((-2.0)*subpixC) + 3.0;
+ float lumaEndN = FxaaLuma(FxaaTexTop(tex, posN));
+ float subpixE = subpixC * subpixC;
+ float lumaEndP = FxaaLuma(FxaaTexTop(tex, posP));
+/*--------------------------------------------------------------------------*/
+ if(!pairN) lumaNN = lumaSS;
+ float gradientScaled = gradient * 1.0/4.0;
+ float lumaMM = lumaM - lumaNN * 0.5;
+ float subpixF = subpixD * subpixE;
+ bool lumaMLTZero = lumaMM < 0.0;
+/*--------------------------------------------------------------------------*/
+ lumaEndN -= lumaNN * 0.5;
+ lumaEndP -= lumaNN * 0.5;
+ bool doneN = abs(lumaEndN) >= gradientScaled;
+ bool doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P1;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P1;
+ bool doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P1;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P1;
+/*--------------------------------------------------------------------------*/
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P2;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P2;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P2;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P2;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 3)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P3;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P3;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P3;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P3;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 4)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P4;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P4;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P4;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P4;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 5)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P5;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P5;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P5;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P5;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 6)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P6;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P6;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P6;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P6;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 7)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P7;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P7;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P7;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P7;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 8)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P8;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P8;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P8;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P8;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 9)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P9;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P9;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P9;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P9;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 10)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P10;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P10;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P10;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P10;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 11)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P11;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P11;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P11;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P11;
+/*--------------------------------------------------------------------------*/
+ #if (FXAA_QUALITY__PS > 12)
+ if(doneNP) {
+ if(!doneN) lumaEndN = FxaaLuma(FxaaTexTop(tex, posN.xy));
+ if(!doneP) lumaEndP = FxaaLuma(FxaaTexTop(tex, posP.xy));
+ if(!doneN) lumaEndN = lumaEndN - lumaNN * 0.5;
+ if(!doneP) lumaEndP = lumaEndP - lumaNN * 0.5;
+ doneN = abs(lumaEndN) >= gradientScaled;
+ doneP = abs(lumaEndP) >= gradientScaled;
+ if(!doneN) posN.x -= offNP.x * FXAA_QUALITY__P12;
+ if(!doneN) posN.y -= offNP.y * FXAA_QUALITY__P12;
+ doneNP = (!doneN) || (!doneP);
+ if(!doneP) posP.x += offNP.x * FXAA_QUALITY__P12;
+ if(!doneP) posP.y += offNP.y * FXAA_QUALITY__P12;
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+ #endif
+/*--------------------------------------------------------------------------*/
+ }
+/*--------------------------------------------------------------------------*/
+ float dstN = posM.x - posN.x;
+ float dstP = posP.x - posM.x;
+ if(!horzSpan) dstN = posM.y - posN.y;
+ if(!horzSpan) dstP = posP.y - posM.y;
+/*--------------------------------------------------------------------------*/
+ bool goodSpanN = (lumaEndN < 0.0) != lumaMLTZero;
+ float spanLength = (dstP + dstN);
+ bool goodSpanP = (lumaEndP < 0.0) != lumaMLTZero;
+ float spanLengthRcp = 1.0/spanLength;
+/*--------------------------------------------------------------------------*/
+ bool directionN = dstN < dstP;
+ float dst = min(dstN, dstP);
+ bool goodSpan = directionN ? goodSpanN : goodSpanP;
+ float subpixG = subpixF * subpixF;
+ float pixelOffset = (dst * (-spanLengthRcp)) + 0.5;
+ float subpixH = subpixG * fxaaQualitySubpix;
+/*--------------------------------------------------------------------------*/
+ float pixelOffsetGood = goodSpan ? pixelOffset : 0.0;
+ float pixelOffsetSubpix = max(pixelOffsetGood, subpixH);
+ if(!horzSpan) posM.x += pixelOffsetSubpix * lengthSign;
+ if( horzSpan) posM.y += pixelOffsetSubpix * lengthSign;
+ return vec4(FxaaTexTop(tex, posM).xyz, lumaM);
+}
+/*==========================================================================*/
+
diff --git a/source/blender/draw/modes/shaders/common_globals_lib.glsl b/source/blender/draw/modes/shaders/common_globals_lib.glsl
new file mode 100644
index 00000000000..4a0104e2cf2
--- /dev/null
+++ b/source/blender/draw/modes/shaders/common_globals_lib.glsl
@@ -0,0 +1,69 @@
+
+/* keep in sync with GlobalsUboStorage */
+layout(std140) uniform globalsBlock {
+ vec4 colorWire;
+ vec4 colorWireEdit;
+ vec4 colorActive;
+ vec4 colorSelect;
+ vec4 colorTransform;
+ vec4 colorLibrarySelect;
+ vec4 colorLibrary;
+ vec4 colorLamp;
+ vec4 colorSpeaker;
+ vec4 colorCamera;
+ vec4 colorEmpty;
+ vec4 colorVertex;
+ vec4 colorVertexSelect;
+ vec4 colorEditMeshActive;
+ vec4 colorEdgeSelect;
+ vec4 colorEdgeSeam;
+ vec4 colorEdgeSharp;
+ vec4 colorEdgeCrease;
+ vec4 colorEdgeBWeight;
+ vec4 colorEdgeFaceSelect;
+ vec4 colorFace;
+ vec4 colorFaceSelect;
+ vec4 colorNormal;
+ vec4 colorVNormal;
+ vec4 colorLNormal;
+ vec4 colorFaceDot;
+
+ vec4 colorDeselect;
+ vec4 colorOutline;
+ vec4 colorLampNoAlpha;
+
+ vec4 colorBackground;
+
+ vec4 colorHandleFree;
+ vec4 colorHandleAuto;
+ vec4 colorHandleVect;
+ vec4 colorHandleAlign;
+ vec4 colorHandleAutoclamp;
+ vec4 colorHandleSelFree;
+ vec4 colorHandleSelAuto;
+ vec4 colorHandleSelVect;
+ vec4 colorHandleSelAlign;
+ vec4 colorHandleSelAutoclamp;
+ vec4 colorNurbUline;
+ vec4 colorNurbSelUline;
+ vec4 colorActiveSpline;
+
+ vec4 colorGrid;
+ vec4 colorGridEmphasise;
+ vec4 colorGridAxisX;
+ vec4 colorGridAxisY;
+ vec4 colorGridAxisZ;
+
+ float sizeLampCenter;
+ float sizeLampCircle;
+ float sizeLampCircleShadow;
+ float sizeVertex;
+ float sizeEdge;
+ float sizeEdgeFix;
+ float sizeFaceDot;
+
+ float gridDistance;
+ float gridResolution;
+ float gridSubdivisions;
+ float gridScale;
+};
diff --git a/source/blender/draw/modes/shaders/common_view_lib.glsl b/source/blender/draw/modes/shaders/common_view_lib.glsl
new file mode 100644
index 00000000000..d261d263a6f
--- /dev/null
+++ b/source/blender/draw/modes/shaders/common_view_lib.glsl
@@ -0,0 +1,14 @@
+/* keep in sync with DRWManager.view_data */
+layout(std140) uniform viewBlock {
+ /* Same order as DRWViewportMatrixType */
+ mat4 ViewProjectionMatrix;
+ mat4 ViewProjectionMatrixInverse;
+ mat4 ViewMatrix;
+ mat4 ViewMatrixInverse;
+ mat4 ProjectionMatrix;
+ mat4 ProjectionMatrixInverse;
+
+ vec4 CameraTexCoFactors;
+
+ vec4 clipPlanes[2];
+};
diff --git a/source/blender/draw/modes/shaders/edit_curve_overlay_frag.glsl b/source/blender/draw/modes/shaders/edit_curve_overlay_frag.glsl
new file mode 100644
index 00000000000..e78462b6915
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_curve_overlay_frag.glsl
@@ -0,0 +1,22 @@
+
+flat in int vertFlag;
+
+#define VERTEX_SELECTED (1 << 0)
+#define VERTEX_ACTIVE (1 << 1)
+
+out vec4 FragColor;
+
+void main()
+{
+ /* TODO: vertex size */
+
+ if ((vertFlag & VERTEX_SELECTED) != 0) {
+ FragColor = colorVertexSelect;
+ }
+ else if ((vertFlag & VERTEX_ACTIVE) != 0) {
+ FragColor = colorEditMeshActive;
+ }
+ else {
+ FragColor = colorVertex;
+ }
+}
diff --git a/source/blender/draw/modes/shaders/edit_curve_overlay_handle_geom.glsl b/source/blender/draw/modes/shaders/edit_curve_overlay_handle_geom.glsl
new file mode 100644
index 00000000000..9da8d9b50d7
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_curve_overlay_handle_geom.glsl
@@ -0,0 +1,79 @@
+
+#define ACTIVE_NURB 1 << 7 /* Keep the same value of `ACTIVE_NURB` in `draw_cache_imp_curve.c` */
+
+layout(lines) in;
+layout(line_strip, max_vertices = 6) out;
+
+uniform vec2 viewportSize;
+
+flat in int vertFlag[];
+
+flat out vec4 finalColor;
+
+void main()
+{
+ /* TODO: vertex size */
+
+ vec4 v1 = gl_in[0].gl_Position;
+ vec4 v2 = gl_in[1].gl_Position;
+
+ int is_active_nurb = vertFlag[1] & ACTIVE_NURB;
+ int color_id = vertFlag[1] ^ is_active_nurb;
+
+ if (is_active_nurb != 0) {
+ /* draw the outline. */
+ vec2 v1_2 = (v2.xy/v2.w - v1.xy/v1.w);
+ vec2 offset;
+
+ if (abs(v1_2.x * viewportSize.x) < abs(v1_2.y * viewportSize.y)) {
+ offset = vec2(2.0 / viewportSize.x, 0.0);
+ }
+ else {
+ offset = vec2(0.0, 2.0 / viewportSize.y);
+ }
+
+ finalColor = colorActiveSpline;
+
+ gl_Position = v1;
+ gl_Position.xy += offset * v1.w;
+ EmitVertex();
+
+ gl_Position = v2;
+ gl_Position.xy += offset * v2.w;
+ EmitVertex();
+
+ EndPrimitive();
+
+ gl_Position = v1;
+ gl_Position.xy -= offset * v1.w;
+ EmitVertex();
+
+ gl_Position = v2;
+ gl_Position.xy -= offset * v2.w;
+ EmitVertex();
+
+ EndPrimitive();
+ }
+
+ if (color_id == 0) finalColor = colorHandleFree;
+ else if (color_id == 1) finalColor = colorHandleAuto;
+ else if (color_id == 2) finalColor = colorHandleVect;
+ else if (color_id == 3) finalColor = colorHandleAlign;
+ else if (color_id == 4) finalColor = colorHandleAutoclamp;
+ else if (color_id == 5) finalColor = colorHandleSelFree;
+ else if (color_id == 6) finalColor = colorHandleSelAuto;
+ else if (color_id == 7) finalColor = colorHandleSelVect;
+ else if (color_id == 8) finalColor = colorHandleSelAlign;
+ else if (color_id == 9) finalColor = colorHandleSelAutoclamp;
+ else if (color_id == 10) finalColor = colorNurbUline;
+ else if (color_id == 11) finalColor = colorNurbSelUline;
+ else finalColor = colorVertexSelect;
+
+ gl_Position = v1;
+ EmitVertex();
+
+ gl_Position = v2;
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl b/source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl
new file mode 100644
index 00000000000..9150ef8cd63
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_curve_overlay_loosevert_vert.glsl
@@ -0,0 +1,39 @@
+
+/* Draw Curve Vertices */
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec2 viewportSize;
+
+in vec3 pos;
+in int data;
+
+/* these are the same for all vertices
+ * and does not need interpolation */
+flat out int vertFlag;
+flat out int clipCase;
+
+/* See fragment shader */
+noperspective out vec4 eData1;
+flat out vec4 eData2;
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+void main()
+{
+ clipCase = 0;
+
+ vec4 pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ /* only vertex position 0 is used */
+ eData1 = eData2 = vec4(1e10);
+ eData2.zw = proj(pPos);
+
+ vertFlag = data;
+
+ gl_Position = pPos;
+ gl_PointSize = sizeVertex;
+}
diff --git a/source/blender/draw/modes/shaders/edit_lattice_overlay_frag.glsl b/source/blender/draw/modes/shaders/edit_lattice_overlay_frag.glsl
new file mode 100644
index 00000000000..e78462b6915
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_lattice_overlay_frag.glsl
@@ -0,0 +1,22 @@
+
+flat in int vertFlag;
+
+#define VERTEX_SELECTED (1 << 0)
+#define VERTEX_ACTIVE (1 << 1)
+
+out vec4 FragColor;
+
+void main()
+{
+ /* TODO: vertex size */
+
+ if ((vertFlag & VERTEX_SELECTED) != 0) {
+ FragColor = colorVertexSelect;
+ }
+ else if ((vertFlag & VERTEX_ACTIVE) != 0) {
+ FragColor = colorEditMeshActive;
+ }
+ else {
+ FragColor = colorVertex;
+ }
+}
diff --git a/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl b/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl
new file mode 100644
index 00000000000..0cbc66a2b1f
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_lattice_overlay_loosevert_vert.glsl
@@ -0,0 +1,39 @@
+
+/* Draw Lattice Vertices */
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec2 viewportSize;
+
+in vec3 pos;
+in int data;
+
+/* these are the same for all vertices
+ * and does not need interpolation */
+flat out int vertFlag;
+flat out int clipCase;
+
+/* See fragment shader */
+noperspective out vec4 eData1;
+flat out vec4 eData2;
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+void main()
+{
+ clipCase = 0;
+
+ vec4 pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ /* only vertex position 0 is used */
+ eData1 = eData2 = vec4(1e10);
+ eData2.zw = proj(pPos);
+
+ vertFlag = data;
+
+ gl_PointSize = sizeVertex;
+ gl_Position = pPos;
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl
new file mode 100644
index 00000000000..07b36079884
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_frag.glsl
@@ -0,0 +1,19 @@
+
+flat in int isSelected;
+#ifdef VERTEX_FACING
+flat in float facing;
+#endif
+
+out vec4 FragColor;
+
+void main()
+{
+ if (isSelected != 0)
+ FragColor = colorFaceDot;
+ else
+ FragColor = colorWireEdit;
+
+#ifdef VERTEX_FACING
+ FragColor.a *= 1.0 - abs(facing) * 0.4;
+#endif
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl
new file mode 100644
index 00000000000..fa3934c4b77
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facedot_vert.glsl
@@ -0,0 +1,31 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in vec4 norAndFlag;
+
+flat out int isSelected;
+
+#ifdef VERTEX_FACING
+uniform mat4 ProjectionMatrix;
+uniform mat4 ModelViewMatrix;
+uniform mat3 NormalMatrix;
+
+flat out float facing;
+#endif
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ /* Bias Facedot Z position in clipspace. */
+ gl_Position.z -= 0.0002;
+ gl_PointSize = sizeFaceDot;
+ isSelected = int(norAndFlag.w);
+#ifdef VERTEX_FACING
+ vec3 view_normal = normalize(NormalMatrix * norAndFlag.xyz);
+ vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)
+ ? normalize((ModelViewMatrix * vec4(pos, 1.0)).xyz)
+ : vec3(0.0, 0.0, 1.0);
+ facing = dot(view_vec, view_normal);
+#endif
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_frag.glsl
new file mode 100644
index 00000000000..23b794d9b8b
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_frag.glsl
@@ -0,0 +1,29 @@
+
+/* Solid Wirefram implementation
+ * Mike Erwin, Clément Foucault */
+
+/* This shader follows the principles of
+ * http://developer.download.nvidia.com/SDK/10/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf */
+
+flat in vec4 faceColor;
+flat in int faceActive;
+
+out vec4 FragColor;
+
+const vec4 stipple_matrix[4] = vec4[4](
+ vec4(1.0, 0.0, 0.0, 0.0),
+ vec4(0.0, 0.0, 0.0, 0.0),
+ vec4(0.0, 0.0, 1.0, 0.0),
+ vec4(0.0, 0.0, 0.0, 0.0)
+);
+
+void main()
+{
+ FragColor = faceColor;
+
+ if (faceActive == 1) {
+ int x = int(gl_FragCoord.x) & 0x3; /* mod 4 */
+ int y = int(gl_FragCoord.y) & 0x3; /* mod 4 */
+ FragColor *= stipple_matrix[x][y];
+ }
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl
new file mode 100644
index 00000000000..3b9aa77306f
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_facefill_vert.glsl
@@ -0,0 +1,29 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in ivec4 data;
+
+flat out vec4 faceColor;
+flat out int faceActive;
+
+#define FACE_ACTIVE (1 << 2)
+#define FACE_SELECTED (1 << 3)
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ if ((data.x & FACE_ACTIVE) != 0) {
+ faceColor = colorEditMeshActive;
+ faceActive = 1;
+ }
+ else if ((data.x & FACE_SELECTED) != 0) {
+ faceColor = colorFaceSelect;
+ faceActive = 0;
+ }
+ else {
+ faceColor = colorFace;
+ faceActive = 0;
+ }
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
new file mode 100644
index 00000000000..cf1051b70b3
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_frag.glsl
@@ -0,0 +1,212 @@
+
+/* Solid Wirefram implementation
+ * Mike Erwin, Clément Foucault */
+
+/* This shader follows the principles of
+ * http://developer.download.nvidia.com/SDK/10/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf */
+
+/* This is not perfect. Only a subset of intel gpus are affected.
+ * This fix have some performance impact.
+ * TODO Refine the range to only affect GPUs. */
+
+uniform float faceAlphaMod;
+
+flat in vec3 edgesCrease;
+flat in vec3 edgesBweight;
+flat in vec4 faceColor;
+flat in ivec3 flag;
+flat in int clipCase;
+#ifdef VERTEX_SELECTION
+in vec3 vertexColor;
+#endif
+#ifdef VERTEX_FACING
+in float facing;
+#endif
+
+/* We use a vec4[2] interface to pass edge data
+ * (without fragmenting memory accesses)
+ *
+ * There are 2 cases :
+ *
+ * - Simple case : geometry shader return edge distances
+ * in the first 2 components of the first vec4.
+ * This needs noperspective interpolation.
+ * The rest is filled with vertex screen positions.
+ * eData2[0] actually contain v2
+ * eData2[1] actually contain v1
+ * eData2[2] actually contain v0
+ *
+ * - Hard case : two 2d edge corner are described by each
+ * vec4 as origin and direction. This is constant over
+ * the triangle and use to detect the correct case. */
+
+noperspective in vec2 eData1;
+flat in vec2 eData2[3];
+
+out vec4 FragColor;
+
+#define EDGE_EXISTS (1 << 0)
+#define EDGE_ACTIVE (1 << 1)
+#define EDGE_SELECTED (1 << 2)
+#define EDGE_SEAM (1 << 3)
+#define EDGE_SHARP (1 << 4)
+/* Vertex flag is shifted and combined with the edge flag */
+#define VERTEX_ACTIVE (1 << (0 + 8))
+#define VERTEX_SELECTED (1 << (1 + 8))
+#define FACE_ACTIVE (1 << (2 + 8))
+
+/* Style Parameters in pixel */
+
+/* Array to retrieve vert/edge indices */
+const ivec3 clipEdgeIdx[6] = ivec3[6](
+ ivec3(1, 0, 2),
+ ivec3(2, 0, 1),
+ ivec3(2, 1, 0),
+ ivec3(2, 1, 0),
+ ivec3(2, 0, 1),
+ ivec3(1, 0, 2)
+);
+
+const ivec3 clipPointIdx[6] = ivec3[6](
+ ivec3(0, 1, 2),
+ ivec3(0, 2, 1),
+ ivec3(0, 2, 1),
+ ivec3(1, 2, 0),
+ ivec3(1, 2, 0),
+ ivec3(2, 1, 0)
+);
+
+const vec4 stipple_matrix[4] = vec4[4](
+ vec4(1.0, 0.0, 0.0, 0.0),
+ vec4(0.0, 0.0, 0.0, 0.0),
+ vec4(0.0, 0.0, 1.0, 0.0),
+ vec4(0.0, 0.0, 0.0, 0.0)
+);
+
+void colorDist(vec4 color, float dist)
+{
+ FragColor = (dist < 0) ? color : FragColor;
+}
+
+float distToEdge(vec2 o, vec2 dir)
+{
+ vec2 af = gl_FragCoord.xy - o;
+ float daf = dot(dir, af);
+ return sqrt(abs(dot(af, af) - daf * daf));
+}
+
+#ifdef ANTI_ALIASING
+void colorDistEdge(vec4 color, float dist)
+{
+ FragColor = mix(color, FragColor, clamp(dist, 0.0, 1.0));
+}
+#else
+#define colorDistEdge colorDist
+#endif
+
+void main()
+{
+ vec3 e, p;
+
+ /* Step 1 : Computing Distances */
+
+ if (clipCase == 0) {
+ e.xy = eData1;
+
+ /* computing missing distance */
+ vec2 dir = normalize(eData2[2] - eData2[1]);
+ e.z = distToEdge(eData2[2], dir);
+
+ p.x = distance(eData2[2], gl_FragCoord.xy);
+ p.y = distance(eData2[1], gl_FragCoord.xy);
+ p.z = distance(eData2[0], gl_FragCoord.xy);
+ }
+ else {
+ ivec3 eidxs = clipEdgeIdx[clipCase - 1];
+ ivec3 pidxs = clipPointIdx[clipCase - 1];
+
+ e[eidxs.x] = distToEdge(eData1, eData2[0]);
+ e[eidxs.y] = distToEdge(eData2[1], eData2[2]);
+
+ /* Three edges visible cases */
+ if (clipCase == 1 || clipCase == 2 || clipCase == 4) {
+ e[eidxs.z] = distToEdge(eData1, normalize(eData2[1] - eData1));
+ p[pidxs.y] = distance(eData2[1], gl_FragCoord.xy);
+ }
+ else {
+ e[eidxs.z] = 1e10; /* off screen */
+ p[pidxs.y] = 1e10; /* off screen */
+ }
+
+ p[pidxs.x] = distance(eData1, gl_FragCoord.xy);
+ p[pidxs.z] = 1e10; /* off screen */
+ }
+
+ /* Step 2 : coloring (order dependant) */
+
+ /* First */
+ FragColor = faceColor;
+
+ if ((flag[0] & FACE_ACTIVE) != 0) {
+ int x = int(gl_FragCoord.x) & 0x3; /* mod 4 */
+ int y = int(gl_FragCoord.y) & 0x3; /* mod 4 */
+ FragColor *= stipple_matrix[x][y];
+ }
+ else {
+ FragColor.a *= faceAlphaMod;
+ }
+
+ /* Edges */
+ for (int v = 0; v < 3; ++v) {
+ if ((flag[v] & EDGE_EXISTS) != 0) {
+ /* Outer large edge */
+ float largeEdge = e[v] - sizeEdge * 3.0;
+
+ vec4 large_edge_color = vec4(0.0);
+ large_edge_color = ((flag[v] & EDGE_SHARP) != 0) ? colorEdgeSharp : large_edge_color;
+ large_edge_color = (edgesCrease[v] > 0.0) ? vec4(colorEdgeCrease.rgb, edgesCrease[v]) : large_edge_color;
+ large_edge_color = (edgesBweight[v] > 0.0) ? vec4(colorEdgeBWeight.rgb, edgesBweight[v]) : large_edge_color;
+ large_edge_color = ((flag[v] & EDGE_SEAM) != 0) ? colorEdgeSeam : large_edge_color;
+
+ if (large_edge_color.a != 0.0) {
+ colorDistEdge(large_edge_color, largeEdge);
+ }
+
+ /* Inner thin edge */
+ float innerEdge = e[v] - sizeEdge;
+#ifdef ANTI_ALIASING
+ innerEdge += 0.125;
+#endif
+
+#ifdef VERTEX_SELECTION
+ colorDistEdge(vec4(vertexColor, 1.0), innerEdge);
+#else
+ vec4 inner_edge_color = colorWireEdit;
+ inner_edge_color = ((flag[v] & EDGE_SELECTED) != 0) ? colorEdgeSelect : inner_edge_color;
+ inner_edge_color = ((flag[v] & EDGE_ACTIVE) != 0) ? vec4(colorEditMeshActive.xyz, 1.0) : inner_edge_color;
+
+ colorDistEdge(inner_edge_color, innerEdge);
+#endif
+ }
+ }
+
+ /* Points */
+#ifdef VERTEX_SELECTION
+ for (int v = 0; v < 3; ++v) {
+ float size = p[v] - sizeVertex;
+
+ vec4 point_color = colorVertex;
+ point_color = ((flag[v] & VERTEX_SELECTED) != 0) ? colorVertexSelect : point_color;
+ point_color = ((flag[v] & VERTEX_ACTIVE) != 0) ? vec4(colorEditMeshActive.xyz, 1.0) : point_color;
+
+ colorDist(point_color, size);
+ }
+#endif
+
+#ifdef VERTEX_FACING
+ FragColor.a *= 1.0 - abs(facing) * 0.4;
+#endif
+
+ /* don't write depth if not opaque */
+ if (FragColor.a == 0.0) discard;
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl
new file mode 100644
index 00000000000..77bc8a25695
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_edge.glsl
@@ -0,0 +1,154 @@
+
+/* Solid Wirefram implementation
+ * Mike Erwin, Clément Foucault */
+
+/* This shader follows the principles of
+ * http://developer.download.nvidia.com/SDK/10/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf */
+
+layout(lines) in;
+layout(triangle_strip, max_vertices=6) out;
+
+uniform mat4 ProjectionMatrix;
+uniform vec2 viewportSize;
+
+in vec4 vPos[];
+in vec4 pPos[];
+in ivec4 vData[];
+#ifdef VERTEX_FACING
+in float vFacing[];
+#endif
+
+/* these are the same for all vertices
+ * and does not need interpolation */
+flat out vec3 edgesCrease;
+flat out vec3 edgesBweight;
+flat out vec4 faceColor;
+flat out ivec3 flag;
+flat out int clipCase;
+#ifdef VERTEX_SELECTION
+out vec3 vertexColor;
+#endif
+#ifdef VERTEX_FACING
+out float facing;
+#endif
+
+/* See fragment shader */
+noperspective out vec2 eData1;
+flat out vec2 eData2[3];
+
+#define VERTEX_ACTIVE (1 << 0)
+#define VERTEX_SELECTED (1 << 1)
+
+#define FACE_ACTIVE (1 << 2)
+#define FACE_SELECTED (1 << 3)
+
+/* Table 1. Triangle Projection Cases */
+const ivec4 clipPointsIdx[6] = ivec4[6](
+ ivec4(0, 1, 2, 2),
+ ivec4(0, 2, 1, 1),
+ ivec4(0, 0, 1, 2),
+ ivec4(1, 2, 0, 0),
+ ivec4(1, 1, 0, 2),
+ ivec4(2, 2, 0, 1)
+);
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+float dist(vec2 pos[3], vec2 vpos, int v)
+{
+ /* endpoints of opposite edge */
+ vec2 e1 = pos[(v + 1) % 3];
+ vec2 e2 = pos[(v + 2) % 3];
+ /* Edge normalized vector */
+ vec2 dir = normalize(e2 - e1);
+ /* perpendicular to dir */
+ vec2 orthogonal = vec2(-dir.y, dir.x);
+
+ return abs(dot(vpos - e1, orthogonal));
+}
+
+vec3 getVertexColor(int v)
+{
+ if ((vData[v].x & (VERTEX_ACTIVE | VERTEX_SELECTED)) != 0)
+ return colorEdgeSelect.rgb;
+ else
+ return colorWireEdit.rgb;
+}
+
+void doVertex(int v, vec4 pos)
+{
+#ifdef VERTEX_SELECTION
+ vertexColor = getVertexColor(v);
+#endif
+
+#ifdef VERTEX_FACING
+ facing = vFacing[v];
+#endif
+
+ gl_Position = pos;
+
+ EmitVertex();
+}
+
+void main()
+{
+ clipCase = 0;
+
+ /* Face */
+ faceColor = vec4(0.0);
+
+ /* Proj Vertex */
+ vec2 pos[2] = vec2[2](proj(pPos[0]), proj(pPos[1]));
+
+ /* little optimization use a vec4 to vectorize
+ * following operations */
+ vec4 dirs1, dirs2;
+
+ /* Edge normalized vector */
+ dirs1.xy = normalize(pos[1] - pos[0]);
+
+ /* perpendicular to dir */
+ dirs1.zw = vec2(-dirs1.y, dirs1.x);
+
+ /* Make it view independent */
+ dirs1 *= sizeEdgeFix / viewportSize.xyxy;
+
+ dirs2 = dirs1;
+
+ /* Perspective */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ /* vPos[i].z is negative and we don't want
+ * our fixvec to be flipped */
+ dirs1 *= -vPos[0].z;
+ dirs2 *= -vPos[1].z;
+ }
+
+ /* Edge / Vert data */
+ eData1 = vec2(1e10);
+ eData2[0] = vec2(1e10);
+ eData2[2] = pos[0];
+ eData2[1] = pos[1];
+ flag[0] = (vData[0].x << 8);
+ flag[1] = (vData[1].x << 8);
+ flag[2] = 0;
+
+ doVertex(0, pPos[0] + vec4(-dirs1.xy, 0.0, 0.0));
+ doVertex(0, pPos[0] + vec4( dirs1.zw, 0.0, 0.0));
+ doVertex(0, pPos[0] + vec4(-dirs1.zw, 0.0, 0.0));
+
+ flag[2] = vData[0].y | (vData[0].x << 8);
+ edgesCrease[2] = vData[0].z / 255.0;
+ edgesBweight[2] = vData[0].w / 255.0;
+
+ doVertex(1, pPos[1] + vec4( dirs2.zw, 0.0, 0.0));
+ doVertex(1, pPos[1] + vec4(-dirs2.zw, 0.0, 0.0));
+
+ flag[2] = 0;
+ doVertex(1, pPos[1] + vec4( dirs2.xy, 0.0, 0.0));
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl
new file mode 100644
index 00000000000..d9c902697b6
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_geom_tri.glsl
@@ -0,0 +1,307 @@
+
+/* Solid Wirefram implementation
+ * Mike Erwin, Clément Foucault */
+
+/* This shader follows the principles of
+ * http://developer.download.nvidia.com/SDK/10/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf */
+
+layout(triangles) in;
+
+/* This is not perfect. Only a subset of intel gpus are affected.
+ * This fix have some performance impact.
+ * TODO Refine the range to only affect GPUs. */
+
+#ifdef EDGE_FIX
+/* To fix the edge artifacts, we render
+ * an outline strip around the screenspace
+ * triangle. Order is important.
+ * TODO diagram
+ */
+
+#ifdef VERTEX_SELECTION
+layout(triangle_strip, max_vertices=23) out;
+#else
+layout(triangle_strip, max_vertices=17) out;
+#endif
+#else
+layout(triangle_strip, max_vertices=3) out;
+#endif
+
+uniform mat4 ProjectionMatrix;
+uniform vec2 viewportSize;
+
+in vec4 vPos[];
+in vec4 pPos[];
+in ivec4 vData[];
+#ifdef VERTEX_FACING
+in float vFacing[];
+#endif
+
+/* these are the same for all vertices
+ * and does not need interpolation */
+flat out vec3 edgesCrease;
+flat out vec3 edgesBweight;
+flat out vec4 faceColor;
+flat out ivec3 flag;
+flat out int clipCase;
+#ifdef VERTEX_SELECTION
+out vec3 vertexColor;
+#endif
+#ifdef VERTEX_FACING
+out float facing;
+#endif
+
+/* See fragment shader */
+noperspective out vec2 eData1;
+flat out vec2 eData2[3];
+
+#define VERTEX_ACTIVE (1 << 0)
+#define VERTEX_SELECTED (1 << 1)
+
+#define FACE_ACTIVE (1 << 2)
+#define FACE_SELECTED (1 << 3)
+
+/* Table 1. Triangle Projection Cases */
+const ivec4 clipPointsIdx[6] = ivec4[6](
+ ivec4(0, 1, 2, 2),
+ ivec4(0, 2, 1, 1),
+ ivec4(0, 0, 1, 2),
+ ivec4(1, 2, 0, 0),
+ ivec4(1, 1, 0, 2),
+ ivec4(2, 2, 0, 1)
+);
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+float dist(vec2 pos[3], vec2 vpos, int v)
+{
+ /* endpoints of opposite edge */
+ vec2 e1 = pos[(v + 1) % 3];
+ vec2 e2 = pos[(v + 2) % 3];
+ /* Edge normalized vector */
+ vec2 dir = normalize(e2 - e1);
+ /* perpendicular to dir */
+ vec2 orthogonal = vec2(-dir.y, dir.x);
+
+ return abs(dot(vpos - e1, orthogonal));
+}
+
+vec3 getVertexColor(int v)
+{
+ if ((vData[v].x & (VERTEX_ACTIVE | VERTEX_SELECTED)) != 0)
+ return colorEdgeSelect.rgb;
+ else
+ return colorWireEdit.rgb;
+}
+
+vec4 getClipData(vec2 pos[3], ivec2 vidx)
+{
+ vec2 A = pos[vidx.x];
+ vec2 Adir = normalize(A - pos[vidx.y]);
+
+ return vec4(A, Adir);
+}
+
+void doVertex(int v)
+{
+#ifdef VERTEX_SELECTION
+ vertexColor = getVertexColor(v);
+#endif
+
+#ifdef VERTEX_FACING
+ facing = vFacing[v];
+#endif
+
+ gl_Position = pPos[v];
+
+ EmitVertex();
+}
+
+void doLoopStrip(int v, vec3 offset)
+{
+ doVertex(v);
+
+ gl_Position.xyz += offset;
+
+ EmitVertex();
+}
+
+#ifdef ANTI_ALIASING
+#define Z_OFFSET 0.008
+#else
+#define Z_OFFSET 0.0
+#endif
+
+void main()
+{
+ /* First we detect which case we are in */
+ clipCase = 0;
+
+ /* if perspective */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ /* See Table 1. Triangle Projection Cases */
+ clipCase += int(pPos[0].z / pPos[0].w < -1 || vPos[0].z > 0.0) * 4;
+ clipCase += int(pPos[1].z / pPos[1].w < -1 || vPos[1].z > 0.0) * 2;
+ clipCase += int(pPos[2].z / pPos[2].w < -1 || vPos[2].z > 0.0) * 1;
+ }
+
+ /* If triangle is behind nearplane, early out */
+ if (clipCase == 7)
+ return;
+
+ /* Edge */
+ ivec3 eflag; vec3 ecrease, ebweight;
+ for (int v = 0; v < 3; ++v) {
+ flag[v] = eflag[v] = vData[v].y | (vData[v].x << 8);
+ edgesCrease[v] = ecrease[v] = vData[v].z / 255.0;
+ edgesBweight[v] = ebweight[v] = vData[v].w / 255.0;
+ }
+
+ /* Face */
+ if ((vData[0].x & FACE_ACTIVE) != 0)
+ faceColor = colorEditMeshActive;
+ else if ((vData[0].x & FACE_SELECTED) != 0)
+ faceColor = colorFaceSelect;
+ else
+ faceColor = colorFace;
+
+ /* Vertex */
+ vec2 pos[3] = vec2[3](proj(pPos[0]), proj(pPos[1]), proj(pPos[2]));
+
+ /* Simple case : compute edge distances in geometry shader */
+ if (clipCase == 0) {
+
+ /* Packing screen positions and 2 distances */
+ eData2[0] = pos[2];
+ eData2[1] = pos[1];
+ eData2[2] = pos[0];
+
+ /* Only pass the first 2 distances */
+ for (int v = 0; v < 2; ++v) {
+ eData1[v] = dist(pos, pos[v], v);
+ doVertex(v);
+ eData1[v] = 0.0;
+ }
+
+ /* and the last vertex */
+ doVertex(2);
+
+#ifdef EDGE_FIX
+ vec2 fixvec[6];
+ vec2 fixvecaf[6];
+ vec2 cornervec[3];
+
+ /* This fix the case when 2 vertices are perfectly aligned
+ * and corner vectors have nowhere to go.
+ * ie: length(cornervec[i]) == 0 */
+ const float epsilon = 1e-2; /* in pixel so not that much */
+ const vec2 bias[3] = vec2[3](
+ vec2( epsilon, epsilon),
+ vec2(-epsilon, epsilon),
+ vec2( 0.0, -epsilon)
+ );
+
+ for (int i = 0; i < 3; ++i) {
+ int i1 = (i + 1) % 3;
+ int i2 = (i + 2) % 3;
+
+ vec2 v1 = pos[i] + bias[i];
+ vec2 v2 = pos[i1] + bias[i1];
+ vec2 v3 = pos[i2] + bias[i2];
+
+ /* Edge normalized vector */
+ vec2 dir = normalize(v2 - v1);
+ vec2 dir2 = normalize(v3 - v1);
+
+ cornervec[i] = -normalize(dir + dir2);
+
+ /* perpendicular to dir */
+ vec2 perp = vec2(-dir.y, dir.x);
+
+ /* Backface case */
+ if (dot(perp, dir2) > 0) {
+ perp = -perp;
+ }
+
+ /* Make it view independent */
+ perp *= sizeEdgeFix / viewportSize;
+ cornervec[i] *= sizeEdgeFix / viewportSize;
+ fixvec[i] = fixvecaf[i] = perp;
+
+ /* Perspective */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ /* vPos[i].z is negative and we don't want
+ * our fixvec to be flipped */
+ fixvec[i] *= -vPos[i].z;
+ fixvecaf[i] *= -vPos[i1].z;
+ cornervec[i] *= -vPos[i].z;
+ }
+ }
+
+ /* to not let face color bleed */
+ faceColor.a = 0.0;
+
+ /* we don't want other edges : make them far */
+ eData1 = vec2(1e10);
+ eData2[0] = vec2(1e10);
+
+ /* Start with the same last vertex to create a
+ * degenerate triangle in order to "create"
+ * a new triangle strip */
+ for (int i = 2; i < 5; ++i) {
+ int vbe = (i - 1) % 3;
+ int vaf = (i + 1) % 3;
+ int v = i % 3;
+
+ /* Position of the "hidden" third vertex */
+ eData2[0] = pos[vbe];
+ doLoopStrip(v, vec3(fixvec[v], Z_OFFSET));
+
+ /* Now one triangle only shade one edge
+ * so we use the edge distance calculated
+ * in the fragment shader, the third edge;
+ * we do this because we need flat interp to
+ * draw a continuous triangle strip */
+ eData2[1] = pos[vaf];
+ eData2[2] = pos[v];
+ flag[0] = (vData[v].x << 8);
+ flag[1] = (vData[vaf].x << 8);
+ flag[2] = eflag[vbe];
+ edgesCrease[2] = ecrease[vbe];
+ edgesBweight[2] = ebweight[vbe];
+
+ doLoopStrip(vaf, vec3(fixvecaf[v], Z_OFFSET));
+
+ /* corner vertices should not draw edges but draw point only */
+ flag[2] = (vData[vbe].x << 8);
+#ifdef VERTEX_SELECTION
+ doLoopStrip(vaf, vec3(cornervec[vaf], Z_OFFSET));
+#endif
+ }
+
+ /* finish the loop strip */
+ doLoopStrip(2, vec3(fixvec[2], Z_OFFSET));
+#endif
+ }
+ /* Harder case : compute visible edges vectors */
+ else {
+ ivec4 vindices = clipPointsIdx[clipCase - 1];
+
+ vec4 tmp;
+ tmp = getClipData(pos, vindices.xz);
+ eData1 = tmp.xy;
+ eData2[0] = tmp.zw;
+ tmp = getClipData(pos, vindices.yw);
+ eData2[1] = tmp.xy;
+ eData2[2] = tmp.zw;
+
+ for (int v = 0; v < 3; ++v)
+ doVertex(v);
+ }
+
+ EndPrimitive();
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_loosevert_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_loosevert_vert.glsl
new file mode 100644
index 00000000000..53e5b09cb70
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_loosevert_vert.glsl
@@ -0,0 +1,61 @@
+
+/* Solid Wirefram implementation
+ * Mike Erwin, Clément Foucault */
+
+/* This shader follows the principles of
+ * http://developer.download.nvidia.com/SDK/10/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf */
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec2 viewportSize;
+
+in vec3 pos;
+in ivec4 data;
+
+/* these are the same for all vertices
+ * and does not need interpolation */
+flat out vec3 edgesCrease;
+flat out vec3 edgesBweight;
+flat out vec4 faceColor;
+flat out ivec3 flag;
+flat out int clipCase;
+#ifdef VERTEX_SELECTION
+out vec3 vertexColor;
+#endif
+
+/* See fragment shader */
+noperspective out vec2 eData1;
+flat out vec2 eData2[3];
+
+/* project to screen space */
+vec2 proj(vec4 pos)
+{
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+void main()
+{
+ clipCase = 0;
+ edgesCrease = vec3(0.0);
+ edgesBweight = vec3(0.0);
+
+ vec4 pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ /* there is no face */
+ faceColor = vec4(0.0);
+
+#ifdef VERTEX_SELECTION
+ vertexColor = vec3(0.0);
+#endif
+
+ /* only vertex position 0 is used */
+ eData1 = vec2(1e10);
+ eData2[0] = vec2(1e10);
+ eData2[1] = vec2(1e10);
+ eData2[2] = proj(pPos);
+
+ flag[0] = (data.x << 8);
+ flag[1] = flag[2] = 0;
+
+ gl_PointSize = sizeEdgeFix;
+ gl_Position = pPos;
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_mix_frag.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_mix_frag.glsl
new file mode 100644
index 00000000000..8f94a105332
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_mix_frag.glsl
@@ -0,0 +1,22 @@
+
+out vec4 FragColor;
+
+uniform sampler2D wireColor;
+uniform sampler2D wireDepth;
+uniform sampler2D sceneDepth;
+uniform float alpha;
+
+void main()
+{
+ ivec2 uv = ivec2(gl_FragCoord.xy);
+ float wire_depth = texelFetch(wireDepth, uv, 0).r;
+ float scene_depth = texelFetch(sceneDepth, uv, 0).r;
+ vec4 wire_color = texelFetch(wireColor, uv, 0).rgba;
+
+ FragColor = wire_color;
+
+ /* Modulate alpha if occluded */
+ if (wire_depth > scene_depth) {
+ FragColor.a *= alpha;
+ }
+}
diff --git a/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
new file mode 100644
index 00000000000..8ebfa4376f0
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_mesh_overlay_vert.glsl
@@ -0,0 +1,38 @@
+
+/* Solid Wirefram implementation
+ * Mike Erwin, Clément Foucault */
+
+/* This shader follows the principles of
+ * http://developer.download.nvidia.com/SDK/10/direct3d/Source/SolidWireframe/Doc/SolidWireframe.pdf */
+
+uniform mat4 ModelViewMatrix;
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in ivec4 data;
+
+out vec4 vPos;
+out vec4 pPos;
+out ivec4 vData;
+
+#ifdef VERTEX_FACING
+uniform mat4 ProjectionMatrix;
+uniform mat3 NormalMatrix;
+
+in vec3 vnor;
+out float vFacing;
+#endif
+
+void main()
+{
+ vPos = ModelViewMatrix * vec4(pos, 1.0);
+ pPos = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ vData = data;
+#ifdef VERTEX_FACING
+ vec3 view_normal = normalize(NormalMatrix * vnor);
+ vec3 view_vec = (ProjectionMatrix[3][3] == 0.0)
+ ? normalize(vPos.xyz)
+ : vec3(0.0, 0.0, 1.0);
+ vFacing = dot(view_vec, view_normal);
+#endif
+}
diff --git a/source/blender/draw/modes/shaders/edit_normals_geom.glsl b/source/blender/draw/modes/shaders/edit_normals_geom.glsl
new file mode 100644
index 00000000000..d17823f2f5a
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_normals_geom.glsl
@@ -0,0 +1,15 @@
+
+layout(points) in;
+layout(line_strip, max_vertices=2) out;
+
+flat in vec4 v1[1];
+flat in vec4 v2[1];
+
+void main()
+{
+ gl_Position = v1[0];
+ EmitVertex();
+ gl_Position = v2[0];
+ EmitVertex();
+ EndPrimitive();
+}
diff --git a/source/blender/draw/modes/shaders/edit_normals_vert.glsl b/source/blender/draw/modes/shaders/edit_normals_vert.glsl
new file mode 100644
index 00000000000..3ce7e618511
--- /dev/null
+++ b/source/blender/draw/modes/shaders/edit_normals_vert.glsl
@@ -0,0 +1,30 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat3 NormalMatrix;
+uniform mat4 ProjectionMatrix;
+uniform float normalSize;
+
+in vec3 pos;
+
+#ifdef LOOP_NORMALS
+in vec3 lnor;
+#define nor lnor
+
+#elif defined(FACE_NORMALS)
+in vec4 norAndFlag;
+#define nor norAndFlag.xyz
+#else
+
+in vec3 vnor;
+#define nor vnor
+#endif
+
+flat out vec4 v1;
+flat out vec4 v2;
+
+void main()
+{
+ v1 = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ vec3 n = normalize(NormalMatrix * nor); /* viewspace */
+ v2 = v1 + ProjectionMatrix * vec4(n * normalSize, 0.0);
+}
diff --git a/source/blender/draw/modes/shaders/object_empty_image_frag.glsl b/source/blender/draw/modes/shaders/object_empty_image_frag.glsl
new file mode 100644
index 00000000000..eab107354d1
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_empty_image_frag.glsl
@@ -0,0 +1,21 @@
+
+flat in vec4 finalColor;
+
+#ifndef USE_WIRE
+in vec2 texCoord_interp;
+#endif
+
+out vec4 fragColor;
+
+#ifndef USE_WIRE
+uniform sampler2D image;
+#endif
+
+void main()
+{
+#ifdef USE_WIRE
+ fragColor = finalColor;
+#else
+ fragColor = finalColor * texture(image, texCoord_interp);
+#endif
+}
diff --git a/source/blender/draw/modes/shaders/object_empty_image_vert.glsl b/source/blender/draw/modes/shaders/object_empty_image_vert.glsl
new file mode 100644
index 00000000000..c629fdcb7ef
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_empty_image_vert.glsl
@@ -0,0 +1,38 @@
+
+uniform mat4 ViewProjectionMatrix;
+uniform vec2 aspect;
+
+/* ---- Instanciated Attribs ---- */
+in vec2 texCoord;
+in vec2 pos;
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+
+#ifdef USE_WIRE
+in vec3 color;
+#else
+in vec4 objectColor;
+#endif
+
+in float size;
+in vec2 offset;
+
+flat out vec4 finalColor;
+
+#ifndef USE_WIRE
+out vec2 texCoord_interp;
+#endif
+
+void main()
+{
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(
+ (pos[0] + offset[0]) * (size * aspect[0]),
+ (pos[1] + offset[1]) * (size * aspect[1]),
+ 0.0, 1.0);
+#ifdef USE_WIRE
+ finalColor = vec4(color, 1.0);
+#else
+ texCoord_interp = texCoord;
+ finalColor = objectColor;
+#endif
+}
diff --git a/source/blender/draw/modes/shaders/object_grid_frag.glsl b/source/blender/draw/modes/shaders/object_grid_frag.glsl
new file mode 100644
index 00000000000..baf508fd854
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_grid_frag.glsl
@@ -0,0 +1,207 @@
+
+/* Infinite grid
+ * Clément Foucault */
+
+out vec4 FragColor;
+
+uniform mat4 ProjectionMatrix;
+uniform vec3 cameraPos;
+uniform vec3 planeNormal;
+uniform vec3 planeAxes;
+uniform vec3 eye;
+uniform vec4 gridSettings;
+uniform vec2 viewportSize;
+uniform vec4 screenvecs[3];
+uniform float gridOneOverLogSubdiv;
+uniform sampler2D depthBuffer;
+
+#define gridDistance gridSettings.x
+#define gridResolution gridSettings.y
+#define gridScale gridSettings.z
+#define gridSubdiv gridSettings.w
+
+uniform int gridFlag;
+
+#define AXIS_X (1 << 0)
+#define AXIS_Y (1 << 1)
+#define AXIS_Z (1 << 2)
+#define GRID (1 << 3)
+#define PLANE_XY (1 << 4)
+#define PLANE_XZ (1 << 5)
+#define PLANE_YZ (1 << 6)
+
+#define GRID_LINE_SMOOTH 1.15
+
+float get_grid(vec3 co, vec3 fwidthCos, float grid_size)
+{
+ float half_size = grid_size / 2.0;
+ /* triangular wave pattern, amplitude is [0, grid_size] */
+ vec3 grid_domain = abs(mod(co + half_size, grid_size) - half_size);
+ /* modulate by the absolute rate of change of the coordinates
+ * (make lines have the same width under perspective) */
+ grid_domain /= fwidthCos;
+
+ /* collapse waves and normalize */
+ grid_domain.x = min(grid_domain.x, min(grid_domain.y, grid_domain.z)) / grid_size;
+
+ return 1.0 - smoothstep(0.0, GRID_LINE_SMOOTH / grid_size, grid_domain.x);
+}
+
+vec3 get_axes(vec3 co, vec3 fwidthCos, float line_size)
+{
+ vec3 axes_domain = abs(co);
+ /* modulate by the absolute rate of change of the coordinates
+ * (make line have the same width under perspective) */
+ axes_domain /= fwidthCos;
+
+ return 1.0 - smoothstep(0.0, GRID_LINE_SMOOTH, axes_domain - line_size);
+}
+
+vec3 get_floor_pos(vec2 uv, out vec3 wPos)
+{
+ vec3 camera_vec, camera_pos, corner_pos;
+ vec3 floored_pos = planeAxes * floor(screenvecs[2].xyz);
+ corner_pos = screenvecs[2].xyz - floored_pos;
+
+ vec3 pixel_pos = corner_pos + uv.x * screenvecs[0].xyz + uv.y * screenvecs[1].xyz;
+
+ /* if perspective */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ camera_pos = cameraPos - floored_pos;
+ camera_vec = normalize(pixel_pos - camera_pos);
+ }
+ else {
+ camera_pos = pixel_pos;
+ camera_vec = normalize(eye);
+ }
+
+ float plane_normal_dot_camera_vec = dot(planeNormal, camera_vec);
+ float p = -dot(planeNormal, camera_pos);
+ if (plane_normal_dot_camera_vec != 0) {
+ p /= plane_normal_dot_camera_vec;
+ }
+ vec3 plane = camera_pos + camera_vec * p;
+
+ /* fix residual imprecision */
+ plane *= planeAxes;
+
+ /* Recover non-offseted world position */
+ wPos = plane + floored_pos;
+
+ return plane;
+}
+
+void main()
+{
+ vec2 sPos = gl_FragCoord.xy / viewportSize; /* Screen [0,1] position */
+
+ /* To reduce artifacts, use a local version of the positions
+ * to compute derivatives since they are not position dependant.
+ * This gets rid of the blocky artifacts. Unfortunately we still
+ * need the world position for the grid to scale properly from the origin. */
+ vec3 gPos, wPos; /* Grid pos., World pos. */
+ gPos = get_floor_pos(sPos, wPos);
+
+ vec3 fwidthPos = fwidth(gPos);
+
+ float dist, fade;
+ /* if persp */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ vec3 viewvec = cameraPos - wPos;
+ dist = length(viewvec);
+ viewvec /= dist;
+
+ float angle;
+ if ((gridFlag & PLANE_XZ) > 0)
+ angle = viewvec.y;
+ else if ((gridFlag & PLANE_YZ) > 0)
+ angle = viewvec.x;
+ else
+ angle = viewvec.z;
+
+ angle = 1.0 - abs(angle);
+ angle *= angle;
+ fade = 1.0 - angle * angle;
+ fade *= 1.0 - smoothstep(0.0, gridDistance, dist - gridDistance);
+ }
+ else {
+ dist = abs(gl_FragCoord.z * 2.0 - 1.0);
+ fade = 1.0 - smoothstep(0.0, 0.5, dist - 0.5);
+ dist = 1.0; /* avoid branch after */
+
+ if ((gridFlag & PLANE_XY) > 0) {
+ float angle = 1.0 - abs(eye.z);
+ dist = 1.0 + angle * 2.0;
+ angle *= angle;
+ fade *= 1.0 - angle * angle;
+ }
+ }
+
+ /* Manual, non hard, depth test:
+ * Progressively fade the grid below occluders
+ * (avoids poping visuals due to depth buffer precision) */
+ float scene_depth = texture(depthBuffer, sPos).r;
+ /* Add a small bias so the grid will always
+ * be on top of a mesh with the same depth. */
+ float grid_depth = gl_FragCoord.z - 1e-8;
+ /* Harder settings tend to flicker more,
+ * but have less "see through" appearance. */
+ const float test_hardness = 1e4;
+ fade *= 1.0 - clamp((grid_depth - scene_depth) * test_hardness, 0.0, 1.0);
+
+ if ((gridFlag & GRID) > 0) {
+ float grid_res = log(dist * gridResolution) * gridOneOverLogSubdiv;
+
+ float blend = fract(-max(grid_res, 0.0));
+ float lvl = floor(grid_res);
+
+ /* from biggest to smallest */
+ float scaleA = gridScale * pow(gridSubdiv, max(lvl - 1.0, 0.0));
+ float scaleB = gridScale * pow(gridSubdiv, max(lvl + 0.0, 0.0));
+ float scaleC = gridScale * pow(gridSubdiv, max(lvl + 1.0, 1.0));
+
+ float gridA = get_grid(wPos, fwidthPos, scaleA);
+ float gridB = get_grid(wPos, fwidthPos, scaleB);
+ float gridC = get_grid(wPos, fwidthPos, scaleC);
+
+ FragColor = vec4(colorGrid.rgb, gridA * blend);
+ FragColor = mix(FragColor, vec4(mix(colorGrid.rgb, colorGridEmphasise.rgb, blend), 1.0), gridB);
+ FragColor = mix(FragColor, vec4(colorGridEmphasise.rgb, 1.0), gridC);
+ }
+ else {
+ FragColor = vec4(colorGrid.rgb, 0.0);
+ }
+
+ if ((gridFlag & (AXIS_X | AXIS_Y | AXIS_Z)) > 0) {
+ /* Setup axes 'domains' */
+ vec3 axes_dist, axes_fwidth;
+
+ if ((gridFlag & AXIS_X) > 0) {
+ axes_dist.x = dot(wPos.yz, planeAxes.yz);
+ axes_fwidth.x = dot(fwidthPos.yz, planeAxes.yz);
+ }
+ if ((gridFlag & AXIS_Y) > 0) {
+ axes_dist.y = dot(wPos.xz, planeAxes.xz);
+ axes_fwidth.y = dot(fwidthPos.xz, planeAxes.xz);
+ }
+ if ((gridFlag & AXIS_Z) > 0) {
+ axes_dist.z = dot(wPos.xy, planeAxes.xy);
+ axes_fwidth.z = dot(fwidthPos.xy, planeAxes.xy);
+ }
+
+ /* Computing all axes at once using vec3 */
+ vec3 axes = get_axes(axes_dist, axes_fwidth, 0.1);
+
+ if ((gridFlag & AXIS_X) > 0) {
+ FragColor = mix(FragColor, colorGridAxisX, axes.x);
+ }
+ if ((gridFlag & AXIS_Y) > 0) {
+ FragColor = mix(FragColor, colorGridAxisY, axes.y);
+ }
+ if ((gridFlag & AXIS_Z) > 0) {
+ FragColor = mix(FragColor, colorGridAxisZ, axes.z);
+ }
+ }
+
+ FragColor.a *= fade;
+}
diff --git a/source/blender/draw/modes/shaders/object_grid_vert.glsl b/source/blender/draw/modes/shaders/object_grid_vert.glsl
new file mode 100644
index 00000000000..3f99d8b5d0a
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_grid_vert.glsl
@@ -0,0 +1,63 @@
+
+/* Infinite grid
+ * Clément Foucault */
+
+uniform mat4 ViewProjectionMatrix;
+uniform mat4 ProjectionMatrix;
+uniform vec3 cameraPos;
+uniform vec4 gridSettings;
+
+#define gridDistance gridSettings.x
+#define gridResolution gridSettings.y
+#define gridScale gridSettings.z
+#define gridSubdiv gridSettings.w
+
+uniform int gridFlag;
+
+#define PLANE_XY (1 << 4)
+#define PLANE_XZ (1 << 5)
+#define PLANE_YZ (1 << 6)
+#define CLIP_Z_POS (1 << 7)
+#define CLIP_Z_NEG (1 << 8)
+
+in vec3 pos;
+
+void main()
+{
+ vec3 vert_pos, proj_camera_pos;
+
+ /* Project camera pos to the needed plane */
+ if ((gridFlag & PLANE_XY) > 0) {
+ vert_pos = vec3(pos.x, pos.y, 0.0);
+ proj_camera_pos = vec3(cameraPos.x, cameraPos.y, 0.0);
+ }
+ else if ((gridFlag & PLANE_XZ) > 0) {
+ vert_pos = vec3(pos.x, 0.0, pos.y);
+ proj_camera_pos = vec3(cameraPos.x, 0.0, cameraPos.z);
+ }
+ else {
+ vert_pos = vec3(0.0, pos.x, pos.y);
+ proj_camera_pos = vec3(0.0, cameraPos.y, cameraPos.z);
+ }
+
+ /* if persp */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ vert_pos *= gridDistance * 2.0;
+ }
+ else {
+ float viewdist = 1.0 / min(abs(ProjectionMatrix[0][0]), abs(ProjectionMatrix[1][1]));
+ vert_pos *= viewdist * gridDistance * 2.0;
+ }
+
+ vec3 realPos = proj_camera_pos + vert_pos;
+
+ /* Used for additional Z axis */
+ if ((gridFlag & CLIP_Z_POS) > 0) {
+ realPos.z = max(realPos.z, 0.0);
+ }
+ if ((gridFlag & CLIP_Z_NEG) > 0) {
+ realPos.z = min(-realPos.z, 0.0);
+ }
+
+ gl_Position = ViewProjectionMatrix * vec4(realPos, 1.0);
+}
diff --git a/source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl b/source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl
new file mode 100644
index 00000000000..d9616076dbf
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_lightprobe_grid_vert.glsl
@@ -0,0 +1,35 @@
+
+in vec3 pos;
+in vec3 nor;
+
+uniform mat4 ViewProjectionMatrix;
+
+uniform float sphere_size;
+uniform ivec3 grid_resolution;
+uniform vec3 corner;
+uniform vec3 increment_x;
+uniform vec3 increment_y;
+uniform vec3 increment_z;
+
+uniform int call_id; /* we don't want the builtin callId which would be 0. */
+uniform int baseId;
+
+flat out uint finalId;
+
+void main()
+{
+ vec3 ls_cell_location;
+ /* Keep in sync with update_irradiance_probe */
+ ls_cell_location.z = float(gl_InstanceID % grid_resolution.z);
+ ls_cell_location.y = float((gl_InstanceID / grid_resolution.z) % grid_resolution.y);
+ ls_cell_location.x = float(gl_InstanceID / (grid_resolution.z * grid_resolution.y));
+
+ vec3 ws_cell_location = corner +
+ (increment_x * ls_cell_location.x +
+ increment_y * ls_cell_location.y +
+ increment_z * ls_cell_location.z);
+
+ gl_Position = ViewProjectionMatrix * vec4(pos * 0.02 * sphere_size + ws_cell_location, 1.0);
+
+ finalId = uint(baseId + call_id);
+}
diff --git a/source/blender/draw/modes/shaders/object_mball_handles_vert.glsl b/source/blender/draw/modes/shaders/object_mball_handles_vert.glsl
new file mode 100644
index 00000000000..baa3ecb804c
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_mball_handles_vert.glsl
@@ -0,0 +1,34 @@
+
+/* This shader takes a 2D shape, puts it in 3D Object space such that is stays aligned with view,
+ * and scales the shape according to per-instance attributes
+ * Note that if the stiffness is zero, it assumes the scale is directly multiplied by the radius */
+
+
+uniform mat4 ViewProjectionMatrix;
+uniform vec3 screen_vecs[2];
+
+/* ---- Instanciated Attribs ---- */
+in vec2 pos;
+
+/* ---- Per instance Attribs ---- */
+in mat3x4 ScaleTranslationMatrix;
+in float radius;
+in vec3 color;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ mat3 Scamat = mat3(ScaleTranslationMatrix);
+ vec4 world_pos = vec4(
+ ScaleTranslationMatrix[0][3],
+ ScaleTranslationMatrix[1][3],
+ ScaleTranslationMatrix[2][3],
+ 1.0);
+
+ vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
+ world_pos.xyz += Scamat * (screen_pos * radius);
+
+ gl_Position = ViewProjectionMatrix * world_pos;
+ finalColor = vec4(color, 1.0);
+}
diff --git a/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl
new file mode 100644
index 00000000000..45bbdb18340
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_outline_detect_frag.glsl
@@ -0,0 +1,82 @@
+
+in vec4 uvcoordsvar;
+
+out vec4 FragColor;
+
+uniform usampler2D outlineId;
+uniform sampler2D outlineDepth;
+uniform sampler2D sceneDepth;
+
+uniform int idOffsets[3];
+
+uniform float alphaOcclu;
+uniform vec2 viewportSize;
+
+vec4 convert_id_to_color(int id)
+{
+ if (id == 0) {
+ return vec4(0.0);
+ }
+ if (id < idOffsets[1]) {
+ return colorActive;
+ }
+ else if (id < idOffsets[2]) {
+ return colorSelect;
+ }
+ else {
+ return colorTransform;
+ }
+}
+
+void main()
+{
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+
+#ifdef GL_ARB_texture_gather
+ vec2 texel_size = 1.0 / vec2(textureSize(outlineId, 0).xy);
+ vec2 uv = ceil(gl_FragCoord.xy) * texel_size;
+
+ /* Samples order is CW starting from top left. */
+ uvec4 tmp1 = textureGather(outlineId, uv - texel_size);
+ uvec4 tmp2 = textureGather(outlineId, uv);
+
+ uint ref_id = tmp1.y;
+ uvec4 id = uvec4(tmp1.xz, tmp2.xz);
+#else
+ uvec4 id;
+ uint ref_id = texelFetch(outlineId, texel, 0).r;
+ id.x = texelFetchOffset(outlineId, texel, 0, ivec2(-1, 0)).r;
+ id.y = texelFetchOffset(outlineId, texel, 0, ivec2( 0, -1)).r;
+ id.z = texelFetchOffset(outlineId, texel, 0, ivec2( 0, 1)).r;
+ id.w = texelFetchOffset(outlineId, texel, 0, ivec2( 1, 0)).r;
+#endif
+
+ bool outline = any(notEqual(id, uvec4(ref_id)));
+
+ ivec2 depth_texel = texel;
+ /* If texel is an outline but has no valid id ...
+ * replace id and depth texel by a valid one.
+ * This keeps the outline thickness consistent everywhere. */
+ if (ref_id == 0u && outline) {
+ depth_texel = (id.x != 0u) ? texel + ivec2(-1, 0) : depth_texel;
+ depth_texel = (id.y != 0u) ? texel + ivec2( 0, -1) : depth_texel;
+ depth_texel = (id.z != 0u) ? texel + ivec2( 0, 1) : depth_texel;
+ depth_texel = (id.w != 0u) ? texel + ivec2( 1, 0) : depth_texel;
+
+ ref_id = (id.x != 0u) ? id.x : ref_id;
+ ref_id = (id.y != 0u) ? id.y : ref_id;
+ ref_id = (id.z != 0u) ? id.z : ref_id;
+ ref_id = (id.w != 0u) ? id.w : ref_id;
+ }
+
+ float ref_depth = texelFetch(outlineDepth, depth_texel, 0).r;
+ float scene_depth = texelFetch(sceneDepth, depth_texel, 0).r;
+
+ /* Avoid bad cases of zfighting for occlusion only. */
+ const float epsilon = 3.0 / 8388608.0;
+ bool occluded = (ref_depth > scene_depth + epsilon);
+
+ FragColor = convert_id_to_color(int(ref_id));
+ FragColor.a *= (occluded) ? alphaOcclu : 1.0;
+ FragColor.a = (outline) ? FragColor.a : 0.0;
+}
diff --git a/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl b/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
new file mode 100644
index 00000000000..7e288cde236
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_outline_expand_frag.glsl
@@ -0,0 +1,37 @@
+
+in vec4 uvcoordsvar;
+
+out vec4 FragColor;
+
+uniform sampler2D outlineColor;
+
+uniform float alpha;
+uniform bool doExpand;
+
+void main()
+{
+ ivec2 uv = ivec2(gl_FragCoord.xy);
+ FragColor = texelFetch(outlineColor, uv, 0).rgba;
+
+ vec4 color[4];
+ color[0] = texelFetchOffset(outlineColor, uv, 0, ivec2( 1, 0)).rgba;
+ color[1] = texelFetchOffset(outlineColor, uv, 0, ivec2( 0, 1)).rgba;
+ color[2] = texelFetchOffset(outlineColor, uv, 0, ivec2(-1, 0)).rgba;
+ color[3] = texelFetchOffset(outlineColor, uv, 0, ivec2( 0, -1)).rgba;
+
+ vec4 values = vec4(color[0].a, color[1].a, color[2].a, color[3].a);
+
+ vec4 tests = step(vec4(1e-6), values); /* (color.a != 0.0) */
+ bvec4 btests = equal(tests, vec4(1.0));
+
+ if (FragColor.a != 0.0) {
+ return;
+ }
+
+ FragColor = (btests.x) ? color[0] : FragColor;
+ FragColor = (btests.y) ? color[1] : FragColor;
+ FragColor = (btests.z) ? color[2] : FragColor;
+ FragColor = (btests.w) ? color[3] : FragColor;
+
+ FragColor.a *= (!doExpand) ? 0.0 : 1.0;
+}
diff --git a/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl b/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl
new file mode 100644
index 00000000000..776adb787ad
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_outline_prepass_frag.glsl
@@ -0,0 +1,10 @@
+uniform int callId;
+uniform int baseId;
+
+/* using uint because 16bit uint can contain more ids than int. */
+out uint outId;
+
+void main()
+{
+ outId = uint(baseId + callId);
+}
diff --git a/source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl b/source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl
new file mode 100644
index 00000000000..964ebe72e81
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_outline_resolve_frag.glsl
@@ -0,0 +1,27 @@
+
+in vec4 uvcoordsvar;
+
+out vec4 FragColor;
+
+uniform sampler2D outlineBluredColor;
+uniform vec2 rcpDimensions;
+
+void main()
+{
+#ifdef USE_FXAA
+ float aa_alpha = FxaaPixelShader(
+ uvcoordsvar.st,
+ outlineBluredColor,
+ rcpDimensions,
+ 1.0,
+ 0.166,
+ 0.0833
+ ).r;
+#endif
+
+ FragColor = texture(outlineBluredColor, uvcoordsvar.st).rgba;
+
+#ifdef USE_FXAA
+ FragColor.a = aa_alpha;
+#endif
+}
diff --git a/source/blender/draw/modes/shaders/object_particle_dot_frag.glsl b/source/blender/draw/modes/shaders/object_particle_dot_frag.glsl
new file mode 100644
index 00000000000..e8bf7884701
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_particle_dot_frag.glsl
@@ -0,0 +1,52 @@
+
+uniform vec3 color;
+uniform vec3 outlineColor;
+uniform sampler1D ramp;
+
+in vec4 radii;
+flat in float finalVal;
+
+out vec4 fragColor;
+
+void main() {
+ float dist = length(gl_PointCoord - vec2(0.5));
+
+// transparent outside of point
+// --- 0 ---
+// smooth transition
+// --- 1 ---
+// pure outline color
+// --- 2 ---
+// smooth transition
+// --- 3 ---
+// pure point color
+// ...
+// dist = 0 at center of point
+
+ float midStroke = 0.5 * (radii[1] + radii[2]);
+
+ if (dist > midStroke) {
+ if (finalVal < 0.0) {
+ fragColor.rgb = outlineColor;
+ }
+ else {
+ fragColor.rgb = texture(ramp, finalVal).rgb;
+ }
+
+ fragColor.a = mix(1.0, 0.0, smoothstep(radii[1], radii[0], dist));
+ }
+ else {
+ if (finalVal < 0.0) {
+ fragColor.rgb = mix(color, outlineColor, smoothstep(radii[3], radii[2], dist));
+ }
+ else {
+ fragColor.rgb = texture(ramp, finalVal).rgb;
+ }
+
+ fragColor.a = 1.0;
+ }
+
+ if (fragColor.a == 0.0) {
+ discard;
+ }
+}
diff --git a/source/blender/draw/modes/shaders/object_particle_dot_vert.glsl b/source/blender/draw/modes/shaders/object_particle_dot_vert.glsl
new file mode 100644
index 00000000000..6dfc212a776
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_particle_dot_vert.glsl
@@ -0,0 +1,35 @@
+
+uniform mat4 ModelViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform float pixel_size;
+uniform float size;
+
+in vec3 pos;
+in float val;
+
+out vec4 radii;
+flat out float finalVal;
+
+void main() {
+ gl_Position = ModelViewMatrix * vec4(pos, 1.0);
+
+ float psize = (ProjectionMatrix[3][3] == 0.0) ? (size / (-gl_Position.z * pixel_size)) : (size / pixel_size);
+
+ gl_PointSize = psize;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * psize;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - 1.0;
+ radii[3] = radius - 2.0;
+
+ // convert to PointCoord units
+ radii /= psize;
+
+ gl_Position = ProjectionMatrix * gl_Position;
+
+ finalVal = val;
+}
diff --git a/source/blender/draw/modes/shaders/object_particle_prim_vert.glsl b/source/blender/draw/modes/shaders/object_particle_prim_vert.glsl
new file mode 100644
index 00000000000..54ae319307a
--- /dev/null
+++ b/source/blender/draw/modes/shaders/object_particle_prim_vert.glsl
@@ -0,0 +1,56 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ViewProjectionMatrix;
+uniform mat4 ModelViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform int screen_space;
+uniform float draw_size;
+uniform vec3 color;
+uniform sampler1D ramp;
+
+in vec3 pos;
+in vec4 rot;
+in float val;
+in vec3 inst_pos;
+in int axis;
+
+flat out vec4 finalColor;
+
+vec3 rotate(vec3 vec, vec4 quat)
+{
+ /* The quaternion representation here stores the w component in the first index */
+ return vec + 2.0 * cross(quat.yzw, cross(quat.yzw, vec) + quat.x * vec);
+}
+
+void main()
+{
+ if (screen_space == 1) {
+ gl_Position = ModelViewMatrix * vec4(pos, 1.0) + vec4(inst_pos * draw_size, 0.0);
+ gl_Position = ProjectionMatrix * gl_Position;
+ }
+ else {
+ float size = draw_size;
+
+ if (axis > -1) {
+ size *= 2;
+ }
+
+ gl_Position = ModelViewProjectionMatrix * vec4(pos + rotate(inst_pos * size, rot), 1.0);
+ }
+
+#ifdef USE_AXIS
+ if (axis == 0)
+ finalColor = vec4(1.0, 0.0, 0.0, 1.0);
+ else if (axis == 1)
+ finalColor = vec4(0.0, 1.0, 0.0, 1.0);
+ else
+ finalColor = vec4(0.0, 0.0, 1.0, 1.0);
+#else
+ if (val < 0.0) {
+ finalColor = vec4(color, 1.0);
+ }
+ else {
+ finalColor = vec4(texture(ramp, val).rgb, 1.0);
+ }
+#endif
+}
diff --git a/source/blender/draw/modes/shaders/overlay_face_orientation_frag.glsl b/source/blender/draw/modes/shaders/overlay_face_orientation_frag.glsl
new file mode 100644
index 00000000000..5b0ad7863d1
--- /dev/null
+++ b/source/blender/draw/modes/shaders/overlay_face_orientation_frag.glsl
@@ -0,0 +1,10 @@
+uniform vec3 color_towards = vec3(0.0, 0.0, 1.0);
+uniform vec3 color_outwards = vec3(1.0, 0.0, 0.0);
+
+out vec4 fragColor;
+
+
+void main()
+{
+ fragColor = vec4(gl_FrontFacing ? color_towards: color_outwards, 0.7);
+}
diff --git a/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl b/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl
new file mode 100644
index 00000000000..d8a72f28eee
--- /dev/null
+++ b/source/blender/draw/modes/shaders/overlay_face_orientation_vert.glsl
@@ -0,0 +1,7 @@
+uniform mat4 ModelViewProjectionMatrix;
+in vec3 pos;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/draw/modes/shaders/paint_texture_frag.glsl b/source/blender/draw/modes/shaders/paint_texture_frag.glsl
new file mode 100644
index 00000000000..18c58a54dca
--- /dev/null
+++ b/source/blender/draw/modes/shaders/paint_texture_frag.glsl
@@ -0,0 +1,11 @@
+
+in vec2 uv_interp;
+out vec4 fragColor;
+
+uniform sampler2D image;
+
+
+void main()
+{
+ fragColor = texture(image, uv_interp);
+}
diff --git a/source/blender/draw/modes/shaders/paint_texture_vert.glsl b/source/blender/draw/modes/shaders/paint_texture_vert.glsl
new file mode 100644
index 00000000000..4ce12e048fa
--- /dev/null
+++ b/source/blender/draw/modes/shaders/paint_texture_vert.glsl
@@ -0,0 +1,15 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec2 uv;
+in vec3 pos;
+
+out vec2 uv_interp;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ uv_interp = uv;
+
+}
diff --git a/source/blender/draw/modes/shaders/paint_vert_frag.glsl b/source/blender/draw/modes/shaders/paint_vert_frag.glsl
new file mode 100644
index 00000000000..c22e1c04b96
--- /dev/null
+++ b/source/blender/draw/modes/shaders/paint_vert_frag.glsl
@@ -0,0 +1,26 @@
+
+flat in int finalFlag;
+out vec4 fragColor;
+
+#define VERTEX_SELECTED (1 << 0)
+#define VERTEX_HIDE (1 << 4)
+
+void main()
+{
+ if (bool(finalFlag & VERTEX_HIDE)) {
+ discard;
+ }
+
+ vec2 centered = gl_PointCoord - vec2(0.5);
+ float dist_squared = dot(centered, centered);
+ const float rad_squared = 0.25;
+ const vec4 colSel = vec4(1.0, 1.0, 1.0, 1.0);
+ const vec4 colUnsel = vec4(0.5, 0.5, 0.5, 1.0);
+
+ // round point with jaggy edges
+ if (dist_squared > rad_squared) {
+ discard;
+ }
+
+ fragColor = bool(finalFlag & VERTEX_SELECTED) ? colSel : colUnsel;
+}
diff --git a/source/blender/draw/modes/shaders/paint_vertex_frag.glsl b/source/blender/draw/modes/shaders/paint_vertex_frag.glsl
new file mode 100644
index 00000000000..5a00fec9c43
--- /dev/null
+++ b/source/blender/draw/modes/shaders/paint_vertex_frag.glsl
@@ -0,0 +1,17 @@
+
+in vec3 finalColor;
+
+out vec4 fragColor;
+
+vec3 linear_to_srgb_attrib(vec3 c) {
+ c = max(c, vec3(0.0));
+ vec3 c1 = c * 12.92;
+ vec3 c2 = 1.055 * pow(c, vec3(1.0 / 2.4)) - 0.055;
+ return mix(c1, c2, step(vec3(0.0031308), c));
+}
+
+void main()
+{
+ fragColor.rgb = linear_to_srgb_attrib(finalColor);
+ fragColor.a = 1.0;
+}
diff --git a/source/blender/draw/modes/shaders/paint_vertex_vert.glsl b/source/blender/draw/modes/shaders/paint_vertex_vert.glsl
new file mode 100644
index 00000000000..178f77c6b9c
--- /dev/null
+++ b/source/blender/draw/modes/shaders/paint_vertex_vert.glsl
@@ -0,0 +1,21 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in vec3 color;
+
+out vec3 finalColor;
+
+vec3 srgb_to_linear_attrib(vec3 c) {
+ c = max(c, vec3(0.0));
+ vec3 c1 = c * (1.0 / 12.92);
+ vec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));
+ return mix(c1, c2, step(vec3(0.04045), c));
+}
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ finalColor = srgb_to_linear_attrib(color);
+}
diff --git a/source/blender/draw/modes/shaders/paint_wire_frag.glsl b/source/blender/draw/modes/shaders/paint_wire_frag.glsl
new file mode 100644
index 00000000000..e4214a4c6d1
--- /dev/null
+++ b/source/blender/draw/modes/shaders/paint_wire_frag.glsl
@@ -0,0 +1,24 @@
+
+flat in int finalFlag;
+out vec4 fragColor;
+
+#define VERTEX_SELECTED (1 << 0)
+#define VERTEX_HIDE (1 << 4)
+
+void main()
+{
+ if (bool(finalFlag & VERTEX_HIDE)) {
+ discard;
+ }
+
+#ifdef VERTEX_MODE
+ vec4 colSel = colorEdgeSelect;
+ colSel.rgb = clamp(colSel.rgb - 0.2, 0.0, 1.0);
+#else
+ const vec4 colSel = vec4(1.0, 1.0, 1.0, 1.0);
+#endif
+
+ const vec4 colUnsel = vec4(0.5, 0.5, 0.5, 1.0);
+
+ fragColor = bool(finalFlag & VERTEX_SELECTED) ? colSel : colUnsel;
+}
diff --git a/source/blender/draw/modes/shaders/paint_wire_vert.glsl b/source/blender/draw/modes/shaders/paint_wire_vert.glsl
new file mode 100644
index 00000000000..6a800e56d94
--- /dev/null
+++ b/source/blender/draw/modes/shaders/paint_wire_vert.glsl
@@ -0,0 +1,17 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in int data;
+
+flat out int finalFlag;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ /* Temp hack for william to start using blender 2.8 for icons. Will be removed by T54910 */
+ gl_Position.z -= 0.0001;
+
+ finalFlag = data;
+}
diff --git a/source/blender/editors/CMakeLists.txt b/source/blender/editors/CMakeLists.txt
index 17a8eef1bdb..358f82499c2 100644
--- a/source/blender/editors/CMakeLists.txt
+++ b/source/blender/editors/CMakeLists.txt
@@ -30,13 +30,14 @@ if(WITH_BLENDER)
add_subdirectory(interface)
add_subdirectory(io)
add_subdirectory(lattice)
+ add_subdirectory(manipulator_library)
add_subdirectory(mask)
add_subdirectory(mesh)
add_subdirectory(metaball)
add_subdirectory(object)
add_subdirectory(physics)
add_subdirectory(render)
- add_subdirectory(screen)
+ add_subdirectory(scene)
add_subdirectory(sculpt_paint)
add_subdirectory(sound)
add_subdirectory(space_action)
@@ -48,20 +49,20 @@ if(WITH_BLENDER)
add_subdirectory(space_graph)
add_subdirectory(space_image)
add_subdirectory(space_info)
- add_subdirectory(space_logic)
add_subdirectory(space_nla)
add_subdirectory(space_node)
add_subdirectory(space_outliner)
add_subdirectory(space_script)
add_subdirectory(space_sequencer)
add_subdirectory(space_text)
- add_subdirectory(space_time)
+ add_subdirectory(space_topbar)
add_subdirectory(space_userpref)
add_subdirectory(space_view3d)
add_subdirectory(transform)
add_subdirectory(undo)
add_subdirectory(util)
add_subdirectory(uvedit)
+ add_subdirectory(screen)
endif()
add_subdirectory(datafiles)
diff --git a/source/blender/editors/animation/CMakeLists.txt b/source/blender/editors/animation/CMakeLists.txt
index 1bf1bb2a474..13432e38669 100644
--- a/source/blender/editors/animation/CMakeLists.txt
+++ b/source/blender/editors/animation/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../gpu
../../makesdna
../../makesrna
diff --git a/source/blender/editors/animation/anim_channels_defines.c b/source/blender/editors/animation/anim_channels_defines.c
index dba060bfb29..87fe002e536 100644
--- a/source/blender/editors/animation/anim_channels_defines.c
+++ b/source/blender/editors/animation/anim_channels_defines.c
@@ -68,6 +68,8 @@
#include "BKE_nla.h"
#include "BKE_context.h"
+#include "GPU_immediate.h"
+
#include "UI_interface.h"
#include "UI_interface_icons.h"
#include "UI_resources.h"
@@ -76,7 +78,6 @@
#include "ED_keyframing.h"
#include "BIF_gl.h"
-#include "BIF_glutil.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -119,11 +120,10 @@ static void acf_generic_root_backdrop(bAnimContext *ac, bAnimListElem *ale, floa
/* set backdrop drawing color */
acf->get_backdrop_color(ac, ale, color);
- glColor3fv(color);
/* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */
UI_draw_roundbox_corner_set((expanded) ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT));
- UI_draw_roundbox_gl_mode(GL_POLYGON, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8);
+ UI_draw_roundbox_3fvAlpha(true, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
}
@@ -141,13 +141,19 @@ static void acf_generic_dataexpand_backdrop(bAnimContext *ac, bAnimListElem *ale
View2D *v2d = &ac->ar->v2d;
short offset = (acf->get_offset) ? acf->get_offset(ac, ale) : 0;
float color[3];
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
/* set backdrop drawing color */
acf->get_backdrop_color(ac, ale, color);
- glColor3fv(color);
-
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
/* no rounded corner - just rectangular box */
- glRectf(offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc);
+ immRectf(pos, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc);
+
+ immUnbindProgram();
}
/* helper method to test if group colors should be drawn */
@@ -224,13 +230,19 @@ static void acf_generic_channel_backdrop(bAnimContext *ac, bAnimListElem *ale, f
View2D *v2d = &ac->ar->v2d;
short offset = (acf->get_offset) ? acf->get_offset(ac, ale) : 0;
float color[3];
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
/* set backdrop drawing color */
acf->get_backdrop_color(ac, ale, color);
- glColor3fv(color);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
/* no rounded corners - just rectangular box */
- glRectf(offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc);
+ immRectf(pos, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc);
+
+ immUnbindProgram();
}
/* Indention + Offset ------------------------------------------- */
@@ -421,14 +433,13 @@ static void acf_summary_backdrop(bAnimContext *ac, bAnimListElem *ale, float ymi
/* set backdrop drawing color */
acf->get_backdrop_color(ac, ale, color);
- glColor3fv(color);
/* rounded corners on LHS only
* - top and bottom
* - special hack: make the top a bit higher, since we are first...
*/
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
- UI_draw_roundbox_gl_mode(GL_POLYGON, 0, yminc - 2, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8);
+ UI_draw_roundbox_3fvAlpha(true, 0, yminc - 2, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
}
/* name for summary entries */
@@ -814,11 +825,10 @@ static void acf_group_backdrop(bAnimContext *ac, bAnimListElem *ale, float yminc
/* set backdrop drawing color */
acf->get_backdrop_color(ac, ale, color);
- glColor3fv(color);
/* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */
UI_draw_roundbox_corner_set(expanded ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT));
- UI_draw_roundbox_gl_mode(GL_POLYGON, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8);
+ UI_draw_roundbox_3fvAlpha(true, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 8, color, 1.0f);
}
/* name for group entries */
@@ -1071,11 +1081,10 @@ static void acf_nla_controls_backdrop(bAnimContext *ac, bAnimListElem *ale, floa
/* set backdrop drawing color */
acf->get_backdrop_color(ac, ale, color);
- glColor3fv(color);
- /* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */
+ /* rounded corners on LHS only - top only when expanded, but bottom too when collapsed */
UI_draw_roundbox_corner_set(expanded ? UI_CNR_TOP_LEFT : (UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT));
- UI_draw_roundbox_gl_mode(GL_POLYGON, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 5);
+ UI_draw_roundbox_3fvAlpha(true, offset, yminc, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc, 5, color, 1.0f);
}
/* name for nla controls expander entries */
@@ -2018,7 +2027,7 @@ static int acf_dspart_setting_flag(bAnimContext *UNUSED(ac), eAnimChannel_Settin
switch (setting) {
case ACHANNEL_SETTING_EXPAND: /* expanded */
- return PART_DS_EXPAND;
+ return 0;
case ACHANNEL_SETTING_MUTE: /* mute (only in NLA) */
return ADT_NLA_EVAL_OFF;
@@ -2036,22 +2045,18 @@ static int acf_dspart_setting_flag(bAnimContext *UNUSED(ac), eAnimChannel_Settin
}
/* get pointer to the setting */
-static void *acf_dspart_setting_ptr(bAnimListElem *ale, eAnimChannel_Settings setting, short *type)
+static void *acf_dspart_setting_ptr(bAnimListElem *UNUSED(ale), eAnimChannel_Settings setting, short *type)
{
- ParticleSettings *part = (ParticleSettings *)ale->data;
-
/* clear extra return data first */
*type = 0;
switch (setting) {
case ACHANNEL_SETTING_EXPAND: /* expanded */
- return GET_ACF_FLAG_PTR(part->flag, type);
+ return NULL;
case ACHANNEL_SETTING_SELECT: /* selected */
case ACHANNEL_SETTING_MUTE: /* muted (for NLA only) */
case ACHANNEL_SETTING_VISIBLE: /* visible (for Graph Editor only) */
- if (part->adt)
- return GET_ACF_FLAG_PTR(part->adt->flag, type);
return NULL;
default: /* unsupported */
@@ -3420,24 +3425,20 @@ static void acf_nlaaction_backdrop(bAnimContext *ac, bAnimListElem *ale, float y
*/
nla_action_get_color(adt, (bAction *)ale->data, color);
- if (adt && (adt->flag & ADT_NLA_EDIT_ON)) {
- /* Yes, the color vector has 4 components, BUT we only want to be using 3 of them! */
- glColor3fv(color);
- }
- else {
- float alpha = (adt && (adt->flag & ADT_NLA_SOLO_TRACK)) ? 0.3f : 1.0f;
- glColor4f(color[0], color[1], color[2], alpha);
- }
-
- /* only on top left corner, to show that this channel sits on top of the preceding ones
+ if (adt && (adt->flag & ADT_NLA_EDIT_ON))
+ color[3] = 1.0f;
+ else
+ color[3] = (adt && (adt->flag & ADT_NLA_SOLO_TRACK)) ? 0.3f : 1.0f;
+
+ /* only on top left corner, to show that this channel sits on top of the preceding ones
* while still linking into the action line strip to the right
*/
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT);
-
+
/* draw slightly shifted up vertically to look like it has more separation from other channels,
* but we then need to slightly shorten it so that it doesn't look like it overlaps
*/
- UI_draw_roundbox_gl_mode(GL_POLYGON, offset, yminc + NLACHANNEL_SKIP, (float)v2d->cur.xmax, ymaxc + NLACHANNEL_SKIP - 1, 8);
+ UI_draw_roundbox_4fv(true, offset, yminc + NLACHANNEL_SKIP, (float)v2d->cur.xmax, ymaxc + NLACHANNEL_SKIP - 1, 8, color);
}
/* name for nla action entries */
@@ -3826,7 +3827,7 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float
selected = 0;
/* set blending again, as may not be set in previous step */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
/* step 1) draw backdrop ........................................... */
@@ -3861,15 +3862,20 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float
/* for F-Curves, draw color-preview of curve behind checkbox */
if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE)) {
FCurve *fcu = (FCurve *)ale->data;
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* F-Curve channels need to have a special 'color code' box drawn, which is colored with whatever
* color the curve has stored
*/
- glColor3fv(fcu->color);
+ immUniformColor3fv(fcu->color);
/* just a solid color rect
*/
- glRectf(offset, yminc, offset + ICON_WIDTH, ymaxc);
+ immRectf(pos, offset, yminc, offset + ICON_WIDTH, ymaxc);
+
+ immUnbindProgram();
}
/* icon is drawn as widget now... */
if (acf->has_setting(ac, ale, ACHANNEL_SETTING_VISIBLE)) {
@@ -3894,27 +3900,39 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float
if (acf->name && !achannel_is_being_renamed(ac, acf, channel_index)) {
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
char name[ANIM_CHAN_NAME_SIZE]; /* hopefully this will be enough! */
-
+ unsigned char col[4];
+
/* set text color */
/* XXX: if active, highlight differently? */
+
if (selected)
- UI_ThemeColor(TH_TEXT_HI);
+ UI_GetThemeColor4ubv(TH_TEXT_HI, col);
else
- UI_ThemeColor(TH_TEXT);
-
+ UI_GetThemeColor4ubv(TH_TEXT, col);
+
/* get name */
acf->name(ale, name);
offset += 3;
- UI_fontstyle_draw_simple(fstyle, offset, ytext, name);
+ UI_fontstyle_draw_simple(fstyle, offset, ytext, name, col);
/* draw red underline if channel is disabled */
if (ELEM(ale->type, ANIMTYPE_FCURVE, ANIMTYPE_NLACURVE) && (ale->flag & FCURVE_DISABLED)) {
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* FIXME: replace hardcoded color here, and check on extents! */
- glColor3f(1.0f, 0.0f, 0.0f);
- glLineWidth(2.0);
- fdrawline((float)(offset), yminc,
- (float)(v2d->cur.xmax), yminc);
+ immUniformColor3f(1.0f, 0.0f, 0.0f);
+
+ glLineWidth(2.0f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, (float)offset, yminc);
+ immVertex2f(pos, (float)v2d->cur.xmax, yminc);
+ immEnd();
+
+ immUnbindProgram();
}
}
@@ -3928,10 +3946,13 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float
short draw_sliders = 0;
float ymin_ofs = 0.0f;
float color[3];
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* get and set backdrop color */
acf->get_backdrop_color(ac, ale, color);
- glColor3fv(color);
+ immUniformColor3fv(color);
/* check if we need to show the sliders */
if ((ac->sl) && ELEM(ac->spacetype, SPACE_ACTION, SPACE_IPO)) {
@@ -3989,7 +4010,9 @@ void ANIM_channel_draw(bAnimContext *ac, bAnimListElem *ale, float yminc, float
* - starts from the point where the first toggle/slider starts,
* - ends past the space that might be reserved for a scroller
*/
- glRectf(v2d->cur.xmax - (float)offset, yminc + ymin_ofs, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc);
+ immRectf(pos, v2d->cur.xmax - (float)offset, yminc + ymin_ofs, v2d->cur.xmax + EXTRA_SCROLL_PAD, ymaxc);
+
+ immUnbindProgram();
}
}
diff --git a/source/blender/editors/animation/anim_channels_edit.c b/source/blender/editors/animation/anim_channels_edit.c
index 20904ed0263..36402b82cbf 100644
--- a/source/blender/editors/animation/anim_channels_edit.c
+++ b/source/blender/editors/animation/anim_channels_edit.c
@@ -50,13 +50,15 @@
#include "BKE_animsys.h"
#include "BKE_action.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_gpencil.h"
#include "BKE_context.h"
+#include "BKE_library.h"
#include "BKE_mask.h"
#include "BKE_global.h"
-#include "BKE_library.h"
+#include "BKE_scene.h"
+
+#include "DEG_depsgraph_build.h"
#include "UI_view2d.h"
@@ -1747,7 +1749,7 @@ static int animchannels_delete_exec(bContext *C, wmOperator *UNUSED(op))
/* send notifier that things have changed */
WM_event_add_notifier(C, NC_ANIMATION | ND_ANIMCHAN | NA_EDITED, NULL);
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
return OPERATOR_FINISHED;
}
@@ -2681,18 +2683,21 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index,
}
case ANIMTYPE_OBJECT:
{
+#if 0
bDopeSheet *ads = (bDopeSheet *)ac->data;
Scene *sce = (Scene *)ads->source;
+#endif
+ ViewLayer *view_layer = ac->view_layer;
Base *base = (Base *)ale->data;
Object *ob = base->object;
AnimData *adt = ob->adt;
/* set selection status */
- if ((ob->restrictflag & OB_RESTRICT_SELECT) == 0) {
+ if (base->flag & BASE_SELECTABLED) {
if (selectmode == SELECT_INVERT) {
/* swap select */
- base->flag ^= SELECT;
- ob->flag = base->flag;
+ ED_object_base_select(base, BA_INVERT);
+ BKE_scene_object_base_flag_sync_from_base(base);
if (adt) adt->flag ^= ADT_UI_SELECTED;
}
@@ -2701,26 +2706,26 @@ static int mouse_anim_channels(bContext *C, bAnimContext *ac, int channel_index,
/* deselect all */
/* TODO: should this deselect all other types of channels too? */
- for (b = sce->base.first; b; b = b->next) {
- b->flag &= ~SELECT;
- b->object->flag = b->flag;
+ for (b = view_layer->object_bases.first; b; b = b->next) {
+ ED_object_base_select(b, BA_DESELECT);
+ BKE_scene_object_base_flag_sync_from_base(b);
if (b->object->adt) b->object->adt->flag &= ~(ADT_UI_SELECTED | ADT_UI_ACTIVE);
}
/* select object now */
- base->flag |= SELECT;
- ob->flag |= SELECT;
+ ED_object_base_select(base, BA_SELECT);
+ BKE_scene_object_base_flag_sync_from_base(base);
if (adt) adt->flag |= ADT_UI_SELECTED;
}
/* change active object - regardless of whether it is now selected [T37883] */
- ED_base_object_activate(C, base); /* adds notifier */
+ ED_object_base_activate(C, base); /* adds notifier */
if ((adt) && (adt->flag & ADT_UI_SELECTED))
adt->flag |= ADT_UI_ACTIVE;
/* ensure we exit editmode on whatever object was active before to avoid getting stuck there - T48747 */
- if (ob != sce->obedit)
+ if (ob != CTX_data_edit_object(C))
ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
notifierFlags |= (ND_ANIMCHAN | NA_SELECTED);
diff --git a/source/blender/editors/animation/anim_deps.c b/source/blender/editors/animation/anim_deps.c
index cc77a321a89..abdc6450abd 100644
--- a/source/blender/editors/animation/anim_deps.c
+++ b/source/blender/editors/animation/anim_deps.c
@@ -49,11 +49,12 @@
#include "BKE_fcurve.h"
#include "BKE_gpencil.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_node.h"
#include "BKE_sequencer.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "ED_anim_api.h"
@@ -77,7 +78,7 @@ void ANIM_list_elem_update(Scene *scene, bAnimListElem *ale)
adt = BKE_animdata_from_id(id);
if (adt) {
adt->recalc |= ADT_RECALC_ANIM;
- DAG_id_tag_update(id, OB_RECALC_TIME);
+ DEG_id_tag_update(id, OB_RECALC_TIME);
}
/* update data */
@@ -98,7 +99,7 @@ void ANIM_list_elem_update(Scene *scene, bAnimListElem *ale)
else {
/* in other case we do standard depsgraph update, ideally
* we'd be calling property update functions here too ... */
- DAG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); // XXX or do we want something more restrictive?
+ DEG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); // XXX or do we want something more restrictive?
}
}
@@ -114,7 +115,7 @@ void ANIM_id_update(Scene *UNUSED(scene), ID *id)
adt->recalc |= ADT_RECALC_ANIM;
/* set recalc flags */
- DAG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); // XXX or do we want something more restrictive?
+ DEG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); // XXX or do we want something more restrictive?
}
}
diff --git a/source/blender/editors/animation/anim_draw.c b/source/blender/editors/animation/anim_draw.c
index a6febdb575e..ff39a3baee5 100644
--- a/source/blender/editors/animation/anim_draw.c
+++ b/source/blender/editors/animation/anim_draw.c
@@ -58,55 +58,76 @@
#include "RNA_access.h"
-#include "BIF_gl.h"
-
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
/* *************************************************** */
/* CURRENT FRAME DRAWING */
/* Draw current frame number in a little green box beside the current frame indicator */
-static void draw_cfra_number(Scene *scene, View2D *v2d, const float cfra, const bool time)
+void ANIM_draw_cfra_number(const bContext *C, View2D *v2d, short flag)
{
+ Scene *scene = CTX_data_scene(C);
+ const float time = scene->r.cfra + scene->r.subframe;
+ const float cfra = (float)(time * scene->r.framelen);
+ const bool show_time = (flag & DRAWCFRA_UNIT_SECONDS) != 0;
+
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
- float xscale, yscale, x, y;
- char numstr[32] = " t"; /* t is the character to start replacing from */
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned char col[4];
+ float xscale, x, y;
+ char numstr[32] = " t "; /* t is the character to start replacing from */
+ float hlen;
int slen;
/* because the frame number text is subject to the same scaling as the contents of the view */
- UI_view2d_scale_get(v2d, &xscale, &yscale);
- glScalef(1.0f / xscale, 1.0f, 1.0f);
+ UI_view2d_scale_get(v2d, &xscale, NULL);
+ gpuPushMatrix();
+ gpuScale2f(1.0f / xscale, 1.0f);
/* get timecode string
* - padding on str-buf passed so that it doesn't sit on the frame indicator
- * - power = 0, gives 'standard' behavior for time
- * but power = 1 is required for frames (to get integer frames)
*/
- if (time) {
- BLI_timecode_string_from_time(&numstr[4], sizeof(numstr) - 4, 0, FRA2TIME(cfra), FPS, U.timecode_style);
+ if (show_time) {
+ BLI_timecode_string_from_time(&numstr[2], sizeof(numstr) - 2, 0, FRA2TIME(cfra), FPS, U.timecode_style);
}
else {
- BLI_timecode_string_from_time_seconds(&numstr[4], sizeof(numstr) - 4, 1, cfra);
+ BLI_timecode_string_from_time_seconds(&numstr[2], sizeof(numstr) - 2, 1, cfra);
}
slen = UI_fontstyle_string_width(fstyle, numstr) - 1;
+ hlen = slen * 0.5f;
/* get starting coordinates for drawing */
x = cfra * xscale;
- y = 0.9f * U.widget_unit;
-
+ y = 0.02f * U.widget_unit;
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* draw green box around/behind text */
- UI_ThemeColorShade(TH_CFRAME, 0);
- glRectf(x, y, x + slen, y + 0.75f * U.widget_unit);
-
- /* draw current frame number - black text */
- UI_ThemeColor(TH_TEXT);
- UI_fontstyle_draw_simple(fstyle, x - 0.25f * U.widget_unit, y + 0.15f * U.widget_unit, numstr);
-
+ immUniformThemeColorShade(TH_CFRAME, 0);
+
+ immRectf(pos,
+ x - hlen - 0.20f * U.widget_unit,
+ y,
+ x + hlen + 0.2f * U.widget_unit,
+ y + U.widget_unit);
+ immUnbindProgram();
+
+ /* draw current frame number */
+ UI_GetThemeColor4ubv(TH_TEXT_HI, col);
+ UI_fontstyle_draw_simple(fstyle,
+ x - hlen - 0.15f * U.widget_unit,
+ y + 0.28f * U.widget_unit,
+ numstr, col);
+
/* restore view transform */
- glScalef(xscale, 1.0, 1.0);
+ gpuPopMatrix();
}
/* General call for drawing current frame indicator in animation editor */
@@ -114,24 +135,24 @@ void ANIM_draw_cfra(const bContext *C, View2D *v2d, short flag)
{
Scene *scene = CTX_data_scene(C);
- /* Draw a light green line to indicate current frame */
- UI_ThemeColor(TH_CFRAME);
-
const float time = scene->r.cfra + scene->r.subframe;
const float x = (float)(time * scene->r.framelen);
glLineWidth((flag & DRAWCFRA_WIDE) ? 3.0 : 2.0);
- glBegin(GL_LINES);
- glVertex2f(x, v2d->cur.ymin - 500.0f); /* XXX arbitrary... want it go to bottom */
- glVertex2f(x, v2d->cur.ymax);
- glEnd();
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- /* Draw current frame number in a little box */
- if (flag & DRAWCFRA_SHOW_NUMBOX) {
- UI_view2d_view_orthoSpecial(CTX_wm_region(C), v2d, 1);
- draw_cfra_number(scene, v2d, x, (flag & DRAWCFRA_UNIT_SECONDS) != 0);
- }
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* Draw a light green line to indicate current frame */
+ immUniformThemeColor(TH_CFRAME);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, x, v2d->cur.ymin - 500.0f); /* XXX arbitrary... want it go to bottom */
+ immVertex2f(pos, x, v2d->cur.ymax);
+ immEnd();
+ immUnbindProgram();
}
/* *************************************************** */
@@ -145,24 +166,74 @@ void ANIM_draw_previewrange(const bContext *C, View2D *v2d, int end_frame_width)
/* only draw this if preview range is set */
if (PRVRANGEON) {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
-
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShadeAlpha(TH_ANIM_ACTIVE, -25, -30);
+ //immUniformColor4f(0.8f, 0.44f, 0.1f, 0.2f); /* XXX: Fix this hardcoded color (anim_active) */
+
/* only draw two separate 'curtains' if there's no overlap between them */
if (PSFRA < PEFRA + end_frame_width) {
- glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
- glRectf((float)(PEFRA + end_frame_width), v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
+ immRectf(pos, (float)(PEFRA + end_frame_width), v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
}
else {
- glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
}
-
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
}
/* *************************************************** */
+/* SCENE FRAME RANGE */
+
+/* Draw frame range guides (for scene frame range) in background */
+// TODO: Should we still show these when preview range is enabled?
+void ANIM_draw_framerange(Scene *scene, View2D *v2d)
+{
+ /* draw darkened area outside of active timeline frame range */
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShadeAlpha(TH_BACK, -25, -100);
+
+ if (SFRA < EFRA) {
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, (float)SFRA, v2d->cur.ymax);
+ immRectf(pos, (float)EFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ }
+ else {
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ }
+
+ glDisable(GL_BLEND);
+
+ /* thin lines where the actual frames are */
+ immUniformThemeColorShade(TH_BACK, -60);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, (float)SFRA, v2d->cur.ymin);
+ immVertex2f(pos, (float)SFRA, v2d->cur.ymax);
+
+ immVertex2f(pos, (float)EFRA, v2d->cur.ymin);
+ immVertex2f(pos, (float)EFRA, v2d->cur.ymax);
+
+ immEnd();
+ immUnbindProgram();
+}
+
+/* *************************************************** */
/* NLA-MAPPING UTILITIES (required for drawing and also editing keyframes) */
/* Obtain the AnimData block providing NLA-mapping for the given channel (if applicable) */
diff --git a/source/blender/editors/animation/anim_filter.c b/source/blender/editors/animation/anim_filter.c
index aa31458aa5b..b7eaa1a4a5f 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -74,6 +74,7 @@
#include "DNA_gpencil_types.h"
#include "DNA_object_types.h"
#include "DNA_userdef_types.h"
+#include "DNA_layer_types.h"
#include "MEM_guardedalloc.h"
@@ -90,6 +91,7 @@
#include "BKE_global.h"
#include "BKE_group.h"
#include "BKE_key.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_modifier.h"
@@ -130,11 +132,11 @@ static void animedit_get_yscale_factor(bAnimContext *ac)
/* Note: there's a similar function in key.c (BKE_key_from_object) */
static Key *actedit_get_shapekeys(bAnimContext *ac)
{
- Scene *scene = ac->scene;
+ ViewLayer *view_layer = ac->view_layer;
Object *ob;
Key *key;
- ob = OBACT;
+ ob = OBACT(view_layer);
if (ob == NULL)
return NULL;
@@ -228,6 +230,7 @@ static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction)
ac->mode = saction->mode;
return true;
}
+
case SACTCONT_DOPESHEET: /* DopeSheet */
/* update scene-pointer (no need to check for pinning yet, as not implemented) */
saction->ads.source = (ID *)ac->scene;
@@ -238,6 +241,16 @@ static bool actedit_get_context(bAnimContext *ac, SpaceAction *saction)
ac->mode = saction->mode;
return true;
+ case SACTCONT_TIMELINE: /* Timeline */
+ /* update scene-pointer (no need to check for pinning yet, as not implemented) */
+ saction->ads.source = (ID *)ac->scene;
+
+ ac->datatype = ANIMCONT_TIMELINE;
+ ac->data = &saction->ads;
+
+ ac->mode = saction->mode;
+ return true;
+
default: /* unhandled yet */
ac->datatype = ANIMCONT_NONE;
ac->data = NULL;
@@ -378,8 +391,9 @@ bool ANIM_animdata_get_context(const bContext *C, bAnimContext *ac)
ac->scene = scene;
if (scene) {
ac->markers = ED_context_get_markers(C);
- ac->obact = (scene->basact) ? scene->basact->object : NULL;
}
+ ac->view_layer = CTX_data_view_layer(C);
+ ac->obact = (ac->view_layer->basact) ? ac->view_layer->basact->object : NULL;
ac->sa = sa;
ac->ar = ar;
ac->sl = sl;
@@ -1671,15 +1685,16 @@ static size_t animdata_filter_gpencil(bAnimContext *ac, ListBase *anim_data, voi
if (ads->filterflag & ADS_FILTER_GP_3DONLY) {
Scene *scene = (Scene *)ads->source;
+ ViewLayer *view_layer = (ViewLayer *)ac->view_layer;
Base *base;
-
+
/* Active scene's GPencil block first - No parent item needed... */
if (scene->gpd) {
items += animdata_filter_gpencil_data(anim_data, ads, scene->gpd, filter_mode);
}
/* Objects in the scene */
- for (base = scene->base.first; base; base = base->next) {
+ for (base = view_layer->object_bases.first; base; base = base->next) {
/* Only consider this object if it has got some GP data (saving on all the other tests) */
if (base->object && base->object->gpd) {
Object *ob = base->object;
@@ -1695,14 +1710,14 @@ static size_t animdata_filter_gpencil(bAnimContext *ac, ListBase *anim_data, voi
*/
if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
/* layer visibility - we check both object and base, since these may not be in sync yet */
- if ((scene->lay & (ob->lay | base->lay)) == 0) continue;
+ if ((base->flag & BASE_VISIBLED) == 0) continue;
/* outliner restrict-flag */
if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
}
/* check selection and object type filters */
- if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) /*|| (base == scene->basact)*/) ) {
+ if ( (ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED) /*|| (base == scene->basact)*/) ) {
/* only selected should be shown */
continue;
}
@@ -1942,25 +1957,26 @@ static size_t animdata_filter_ds_nodetree(bAnimContext *ac, ListBase *anim_data,
static size_t animdata_filter_ds_linestyle(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, Scene *sce, int filter_mode)
{
- SceneRenderLayer *srl;
+ ViewLayer *view_layer;
FreestyleLineSet *lineset;
size_t items = 0;
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
- for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
+ for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
if (lineset->linestyle) {
lineset->linestyle->id.tag |= LIB_TAG_DOIT;
}
}
}
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
+ for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
/* skip render layers without Freestyle enabled */
- if (!(srl->layflag & SCE_LAY_FRS))
+ if ((view_layer->flag & VIEW_LAYER_FREESTYLE) == 0) {
continue;
-
+ }
+
/* loop over linesets defined in the render layer */
- for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
+ for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
FreestyleLineStyle *linestyle = lineset->linestyle;
ListBase tmp_data = {NULL, NULL};
size_t tmp_items = 0;
@@ -2045,7 +2061,9 @@ static size_t animdata_filter_ds_texture(bAnimContext *ac, ListBase *anim_data,
return items;
}
-/* NOTE: owner_id is either material, lamp, or world block, which is the direct owner of the texture stack in question */
+/* NOTE: owner_id is the direct owner of the texture stack in question
+ * It used to be Material/Lamp/World before the Blender Internal removal for 2.8
+ */
static size_t animdata_filter_ds_textures(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, ID *owner_id, int filter_mode)
{
MTex **mtex = NULL;
@@ -2057,24 +2075,6 @@ static size_t animdata_filter_ds_textures(bAnimContext *ac, ListBase *anim_data,
return 0;
switch (GS(owner_id->name)) {
- case ID_MA:
- {
- Material *ma = (Material *)owner_id;
- mtex = (MTex **)(&ma->mtex);
- break;
- }
- case ID_LA:
- {
- Lamp *la = (Lamp *)owner_id;
- mtex = (MTex **)(&la->mtex);
- break;
- }
- case ID_WO:
- {
- World *wo = (World *)owner_id;
- mtex = (MTex **)(&wo->mtex);
- break;
- }
case ID_PA:
{
ParticleSettings *part = (ParticleSettings *)owner_id;
@@ -2119,10 +2119,6 @@ static size_t animdata_filter_ds_material(bAnimContext *ac, ListBase *anim_data,
/* material's animation data */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)ma, filter_mode);
- /* textures */
- if (!(ads->filterflag & ADS_FILTER_NOTEX))
- tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)ma, filter_mode);
-
/* nodes */
if ((ma->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)ma, ma->nodetree, filter_mode);
@@ -2441,10 +2437,6 @@ static size_t animdata_filter_ds_obdata(bAnimContext *ac, ListBase *anim_data, b
/* nodetree */
if ((ntree) && !(ads->filterflag & ADS_FILTER_NONTREE))
tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, &la->id, ntree, filter_mode);
-
- /* textures */
- if (!(ads->filterflag & ADS_FILTER_NOTEX))
- tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, &la->id, filter_mode);
break;
}
}
@@ -2619,7 +2611,7 @@ static size_t animdata_filter_dopesheet_ob(bAnimContext *ac, ListBase *anim_data
if (filter_mode & ANIMFILTER_LIST_CHANNELS) {
/* check if filtering by selection */
// XXX: double-check on this - most of the time, a lot of tools need to filter out these channels!
- if (ANIMCHANNEL_SELOK((base->flag & SELECT))) {
+ if (ANIMCHANNEL_SELOK((base->flag & BASE_SELECTED))) {
/* check if filtering by active status */
if (ANIMCHANNEL_ACTIVEOK(ob)) {
ANIMCHANNEL_NEW_CHANNEL(base, ANIMTYPE_OBJECT, ob);
@@ -2649,10 +2641,6 @@ static size_t animdata_filter_ds_world(bAnimContext *ac, ListBase *anim_data, bD
/* animation data filtering */
tmp_items += animfilter_block_data(ac, &tmp_data, ads, (ID *)wo, filter_mode);
- /* textures for world */
- if (!(ads->filterflag & ADS_FILTER_NOTEX))
- tmp_items += animdata_filter_ds_textures(ac, &tmp_data, ads, (ID *)wo, filter_mode);
-
/* nodes */
if ((wo->nodetree) && !(ads->filterflag & ADS_FILTER_NONTREE))
tmp_items += animdata_filter_ds_nodetree(ac, &tmp_data, ads, (ID *)wo, wo->nodetree, filter_mode);
@@ -2843,7 +2831,7 @@ static size_t animdata_filter_dopesheet_movieclips(bAnimContext *ac, ListBase *a
}
/* Helper for animdata_filter_dopesheet() - For checking if an object should be included or not */
-static bool animdata_filter_base_is_ok(bDopeSheet *ads, Scene *scene, Base *base, int filter_mode)
+static bool animdata_filter_base_is_ok(bDopeSheet *ads, Base *base, int filter_mode)
{
Object *ob = base->object;
@@ -2861,7 +2849,7 @@ static bool animdata_filter_base_is_ok(bDopeSheet *ads, Scene *scene, Base *base
*/
if ((filter_mode & ANIMFILTER_DATA_VISIBLE) && !(ads->filterflag & ADS_FILTER_INCL_HIDDEN)) {
/* layer visibility - we check both object and base, since these may not be in sync yet */
- if ((scene->lay & (ob->lay | base->lay)) == 0)
+ if ((base->flag & BASE_VISIBLED) == 0)
return false;
/* outliner restrict-flag */
@@ -2896,7 +2884,7 @@ static bool animdata_filter_base_is_ok(bDopeSheet *ads, Scene *scene, Base *base
}
/* check selection and object type filters */
- if ((ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & SELECT) /*|| (base == sce->basact)*/)) {
+ if ((ads->filterflag & ADS_FILTER_ONLYSEL) && !((base->flag & BASE_SELECTED) /*|| (base == sce->basact)*/)) {
/* only selected should be shown */
return false;
}
@@ -2924,15 +2912,15 @@ static int ds_base_sorting_cmp(const void *base1_ptr, const void *base2_ptr)
}
/* Get a sorted list of all the bases - for inclusion in dopesheet (when drawing channels) */
-static Base **animdata_filter_ds_sorted_bases(bDopeSheet *ads, Scene *scene, int filter_mode, size_t *r_usable_bases)
+static Base **animdata_filter_ds_sorted_bases(bDopeSheet *ads, ViewLayer *view_layer, int filter_mode, size_t *r_usable_bases)
{
/* Create an array with space for all the bases, but only containing the usable ones */
- size_t tot_bases = BLI_listbase_count(&scene->base);
+ size_t tot_bases = BLI_listbase_count(&view_layer->object_bases);
size_t num_bases = 0;
Base **sorted_bases = MEM_mallocN(sizeof(Base *) * tot_bases, "Dopesheet Usable Sorted Bases");
- for (Base *base = scene->base.first; base; base = base->next) {
- if (animdata_filter_base_is_ok(ads, scene, base, filter_mode)) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (animdata_filter_base_is_ok(ads, base, filter_mode)) {
sorted_bases[num_bases++] = base;
}
}
@@ -2950,8 +2938,9 @@ static Base **animdata_filter_ds_sorted_bases(bDopeSheet *ads, Scene *scene, int
static size_t animdata_filter_dopesheet(bAnimContext *ac, ListBase *anim_data, bDopeSheet *ads, int filter_mode)
{
Scene *scene = (Scene *)ads->source;
+ ViewLayer *view_layer = (ViewLayer *)ac->view_layer;
size_t items = 0;
-
+
/* check that we do indeed have a scene */
if ((ads->source == NULL) || (GS(ads->source->name) != ID_SCE)) {
printf("Dope Sheet Error: No scene!\n");
@@ -2988,14 +2977,14 @@ static size_t animdata_filter_dopesheet(bAnimContext *ac, ListBase *anim_data, b
* - Don't do this if there's just a single object
*/
if ((filter_mode & ANIMFILTER_LIST_CHANNELS) && !(ads->flag & ADS_FLAG_NO_DB_SORT) &&
- (scene->base.first != scene->base.last))
+ (view_layer->object_bases.first != view_layer->object_bases.last))
{
/* Filter list of bases (i.e. objects), sort them, then add their contents normally... */
// TODO: Cache the old sorted order - if the set of bases hasn't changed, don't re-sort...
Base **sorted_bases;
size_t num_bases;
- sorted_bases = animdata_filter_ds_sorted_bases(ads, scene, filter_mode, &num_bases);
+ sorted_bases = animdata_filter_ds_sorted_bases(ads, view_layer, filter_mode, &num_bases);
if (sorted_bases) {
/* Add the necessary channels for these bases... */
for (size_t i = 0; i < num_bases; i++) {
@@ -3012,8 +3001,8 @@ static size_t animdata_filter_dopesheet(bAnimContext *ac, ListBase *anim_data, b
/* Filter and add contents of each base (i.e. object) without them sorting first
* NOTE: This saves performance in cases where order doesn't matter
*/
- for (Base *base = scene->base.first; base; base = base->next) {
- if (animdata_filter_base_is_ok(ads, scene, base, filter_mode)) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (animdata_filter_base_is_ok(ads, base, filter_mode)) {
/* since we're still here, this object should be usable */
items += animdata_filter_dopesheet_ob(ac, anim_data, ads, base, filter_mode);
}
@@ -3256,6 +3245,15 @@ size_t ANIM_animdata_filter(bAnimContext *ac, ListBase *anim_data, eAnimFilter_F
}
+ /* Timeline Mode - Basically the same as dopesheet, except we only have the summary for now */
+ case ANIMCONT_TIMELINE:
+ {
+ /* the DopeSheet editor is the primary place where the DopeSheet summaries are useful */
+ if (animdata_filter_dopesheet_summary(ac, anim_data, filter_mode, &items))
+ items += animdata_filter_dopesheet(ac, anim_data, data, filter_mode);
+ break;
+ }
+
/* Special/Internal Use */
case ANIMCONT_CHANNEL: /* animation channel */
{
diff --git a/source/blender/editors/animation/anim_markers.c b/source/blender/editors/animation/anim_markers.c
index 031102c9f35..091346921dc 100644
--- a/source/blender/editors/animation/anim_markers.c
+++ b/source/blender/editors/animation/anim_markers.c
@@ -36,13 +36,14 @@
#include "DNA_object_types.h"
#include "BLI_blenlib.h"
-#include "BLI_math_base.h"
+#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLT_translation.h"
#include "BKE_context.h"
#include "BKE_fcurve.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_scene.h"
@@ -56,9 +57,11 @@
#include "WM_api.h"
#include "WM_types.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
#include "UI_interface.h"
#include "UI_interface_icons.h"
#include "UI_view2d.h"
@@ -332,6 +335,44 @@ void debug_markers_print_list(ListBase *markers)
/* ************* Marker Drawing ************ */
+static void draw_marker_name(
+ const uiFontStyle *fstyle, TimeMarker *marker, const char *name,
+ int cfra, const float xpos, const float ypixels)
+{
+ unsigned char text_col[4];
+ float x, y;
+
+ /* minimal y coordinate which wouldn't be occluded by scroll */
+ int min_y = 17.0f * UI_DPI_FAC;
+
+ if (marker->flag & SELECT) {
+ UI_GetThemeColor4ubv(TH_TEXT_HI, text_col);
+ x = xpos + 4.0f * UI_DPI_FAC;
+ y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC;
+ y = max_ii(y, min_y);
+ }
+ else {
+ UI_GetThemeColor4ubv(TH_TEXT, text_col);
+ if ((marker->frame <= cfra) && (marker->frame + 5 > cfra)) {
+ x = xpos + 8.0f * UI_DPI_FAC;
+ y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC;
+ y = max_ii(y, min_y);
+ }
+ else {
+ x = xpos + 8.0f * UI_DPI_FAC;
+ y = 17.0f * UI_DPI_FAC;
+ }
+ }
+
+#ifdef DURIAN_CAMERA_SWITCH
+ if (marker->camera && (marker->camera->restrictflag & OB_RESTRICT_RENDER)) {
+ text_col[3] = 100;
+ }
+#endif
+
+ UI_fontstyle_draw_simple(fstyle, x, y, name, text_col);
+}
+
/* function to draw markers */
static void draw_marker(
View2D *v2d, const uiFontStyle *fstyle, TimeMarker *marker, int cfra, int flag,
@@ -339,11 +380,16 @@ static void draw_marker(
const float ypixels, const float xscale, const float yscale)
{
const float xpos = marker->frame * xscale;
+#ifdef DURIAN_CAMERA_SWITCH
+ const float yoffs = (marker->camera) ? 0.2f * UI_DPI_ICON_SIZE : 0.0f;
+#else
+ const float yoffs = 0.0f;
+#endif
int icon_id;
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
/* vertical line - dotted */
#ifdef DURIAN_CAMERA_SWITCH
if ((marker->camera) || (flag & DRAW_MARKERS_LINES))
@@ -351,19 +397,30 @@ static void draw_marker(
if (flag & DRAW_MARKERS_LINES)
#endif
{
- setlinestyle(3);
-
- if (marker->flag & SELECT)
- glColor4ub(255, 255, 255, 96);
- else
- glColor4ub(0, 0, 0, 96);
-
- glBegin(GL_LINES);
- glVertex2f(xpos + 0.5f, 12.0f);
- glVertex2f(xpos + 0.5f, (v2d->cur.ymax + 12.0f) * yscale);
- glEnd();
-
- setlinestyle(0);
+ Gwn_VertFormat *format = immVertexFormat();
+ uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ if (marker->flag & SELECT) {
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.38f);
+ }
+ else {
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.38f);
+ }
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, xpos + 0.5f, 12.0f);
+ immVertex2f(pos, xpos + 0.5f, (v2d->cur.ymax + 12.0f) * yscale);
+ immEnd();
+
+ immUnbindProgram();
}
/* 5 px to offset icon to align properly, space / pixels corrects for zoom */
@@ -372,52 +429,35 @@ static void draw_marker(
(marker->flag & SELECT) ? ICON_PMARKER_SEL :
ICON_PMARKER;
}
+#ifdef DURIAN_CAMERA_SWITCH
+ else if (marker->camera) {
+ icon_id = (marker->flag & SELECT) ? ICON_OUTLINER_OB_CAMERA :
+ ICON_OUTLINER_DATA_CAMERA;
+ }
+#endif
else {
icon_id = (marker->flag & SELECT) ? ICON_MARKER_HLT :
ICON_MARKER;
}
- UI_icon_draw(xpos - 0.45f * UI_DPI_ICON_SIZE, UI_DPI_ICON_SIZE, icon_id);
+ UI_icon_draw(xpos - 0.45f * UI_DPI_ICON_SIZE, yoffs + UI_DPI_ICON_SIZE, icon_id);
glDisable(GL_BLEND);
/* and the marker name too, shifted slightly to the top-right */
- if (marker->name[0]) {
- float x, y;
-
- /* minimal y coordinate which wouldn't be occluded by scroll */
- int min_y = 17.0f * UI_DPI_FAC;
-
- if (marker->flag & SELECT) {
- UI_ThemeColor(TH_TEXT_HI);
- x = xpos + 4.0f * UI_DPI_FAC;
- y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC;
- y = max_ii(y, min_y);
- }
- else {
- UI_ThemeColor(TH_TEXT);
- if ((marker->frame <= cfra) && (marker->frame + 5 > cfra)) {
- x = xpos + 8.0f * UI_DPI_FAC;
- y = (ypixels <= 39.0f * UI_DPI_FAC) ? (ypixels - 10.0f * UI_DPI_FAC) : 29.0f * UI_DPI_FAC;
- y = max_ii(y, min_y);
- }
- else {
- x = xpos + 8.0f * UI_DPI_FAC;
- y = 17.0f * UI_DPI_FAC;
- }
- }
-
#ifdef DURIAN_CAMERA_SWITCH
- if (marker->camera && (marker->camera->restrictflag & OB_RESTRICT_RENDER)) {
- float col[4];
- glGetFloatv(GL_CURRENT_COLOR, col);
- col[3] = 0.4;
- glColor4fv(col);
- }
-#endif
+ if (marker->camera) {
+ draw_marker_name(fstyle, marker, marker->camera->id.name + 2, cfra, xpos, ypixels);
+ }
+ else if (marker->name[0]) {
+ draw_marker_name(fstyle, marker, marker->name, cfra, xpos, ypixels);
+ }
+#else
+ if (marker->name[0]) {
+ draw_marker_name(fstyle, marker, marker->name, cfra, xpos, ypixels);
- UI_fontstyle_draw_simple(fstyle, x, y, marker->name);
}
+#endif
}
/* Draw Scene-Markers in time window */
@@ -443,21 +483,27 @@ void ED_markers_draw(const bContext *C, int flag)
v2d = UI_view2d_fromcontext(C);
if (flag & DRAW_MARKERS_MARGIN) {
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
const unsigned char shade[4] = {0, 0, 0, 16};
- glColor4ubv(shade);
+ immUniformColor4ubv(shade);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- glRectf(v2d->cur.xmin, 0, v2d->cur.xmax, UI_MARKER_MARGIN_Y);
+ immRectf(pos, v2d->cur.xmin, 0, v2d->cur.xmax, UI_MARKER_MARGIN_Y);
glDisable(GL_BLEND);
+
+ immUnbindProgram();
}
/* no time correction for framelen! space is drawn with old values */
ypixels = BLI_rcti_size_y(&v2d->mask);
UI_view2d_scale_get(v2d, &xscale, &yscale);
- glScalef(1.0f / xscale, 1.0f, 1.0f);
+ gpuPushMatrix();
+ gpuScale2f(1.0f / xscale, 1.0f);
/* x-bounds with offset for text (adjust for long string, avoid checking string width) */
font_width_max = (10 * UI_DPI_FAC) / xscale;
@@ -480,7 +526,7 @@ void ED_markers_draw(const bContext *C, int flag)
}
}
- glScalef(xscale, 1.0f, 1.0f);
+ gpuPopMatrix();
}
/* ************************ Marker Wrappers API ********************* */
@@ -552,11 +598,10 @@ static int ed_markers_poll_markers_exist(bContext *C)
static int ed_markers_opwrap_invoke_custom(bContext *C, wmOperator *op, const wmEvent *event,
int (*invoke_func)(bContext *, wmOperator *, const wmEvent *))
{
- ScrArea *sa = CTX_wm_area(C);
int retval = OPERATOR_PASS_THROUGH;
-
+
/* removed check for Y coord of event, keymap has bounbox now */
-
+
/* allow operator to run now */
if (invoke_func)
retval = invoke_func(C, op, event);
@@ -564,15 +609,13 @@ static int ed_markers_opwrap_invoke_custom(bContext *C, wmOperator *op, const wm
retval = op->type->exec(C, op);
else
BKE_report(op->reports, RPT_ERROR, "Programming error: operator does not actually have code to do anything!");
-
- /* return status modifications - for now, make this spacetype dependent as above */
- if (sa->spacetype != SPACE_TIME) {
- /* unless successful, must add "pass-through" to let normal operator's have a chance at tackling this event */
- if ((retval & (OPERATOR_FINISHED | OPERATOR_INTERFACE)) == 0) {
- retval |= OPERATOR_PASS_THROUGH;
- }
+
+
+ /* unless successful, must add "pass-through" to let normal operator's have a chance at tackling this event */
+ if ((retval & (OPERATOR_FINISHED | OPERATOR_INTERFACE)) == 0) {
+ retval |= OPERATOR_PASS_THROUGH;
}
-
+
return retval;
}
@@ -672,8 +715,7 @@ typedef struct MarkerMove {
static bool ed_marker_move_use_time(MarkerMove *mm)
{
- if (((mm->slink->spacetype == SPACE_TIME) && !(((SpaceTime *)mm->slink)->flag & TIME_DRAWFRAMES)) ||
- ((mm->slink->spacetype == SPACE_SEQ) && !(((SpaceSeq *)mm->slink)->flag & SEQ_DRAWFRAMES)) ||
+ if (((mm->slink->spacetype == SPACE_SEQ) && !(((SpaceSeq *)mm->slink)->flag & SEQ_DRAWFRAMES)) ||
((mm->slink->spacetype == SPACE_ACTION) && (((SpaceAction *)mm->slink)->flag & SACTION_DRAWTIME)) ||
((mm->slink->spacetype == SPACE_IPO) && !(((SpaceIpo *)mm->slink)->flag & SIPO_DRAWTIME)) ||
((mm->slink->spacetype == SPACE_NLA) && !(((SpaceNla *)mm->slink)->flag & SNLA_DRAWTIME)))
@@ -844,7 +886,7 @@ static void ed_marker_move_apply(bContext *C, wmOperator *op)
BKE_scene_camera_switch_update(scene);
if (camera != scene->camera) {
- BKE_screen_view3d_scene_sync(sc);
+ BKE_screen_view3d_scene_sync(sc, scene);
WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
}
#endif
@@ -917,10 +959,7 @@ static int ed_marker_move_modal(bContext *C, wmOperator *op, const wmEvent *even
mm->evtx = event->x;
fac = ((float)(event->x - mm->firstx) * dx);
- if (mm->slink->spacetype == SPACE_TIME)
- apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, FPS, 0.1 * FPS, 0);
- else
- apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/);
+ apply_keyb_grid(event->shift, event->ctrl, &fac, 0.0, 1.0, 0.1, 0 /*was: U.flag & USER_AUTOGRABGRID*/);
RNA_int_set(op->ptr, "frames", (int)fac);
ed_marker_move_apply(C, op);
@@ -1129,12 +1168,13 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool
if (camera) {
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Base *base;
TimeMarker *marker;
int sel = 0;
if (!extend)
- BKE_scene_base_deselect_all(scene);
+ BKE_view_layer_base_deselect_all(view_layer);
for (marker = markers->first; marker; marker = marker->next) {
if (marker->frame == cfra) {
@@ -1146,11 +1186,11 @@ static int ed_marker_select(bContext *C, const wmEvent *event, bool extend, bool
for (marker = markers->first; marker; marker = marker->next) {
if (marker->camera) {
if (marker->frame == cfra) {
- base = BKE_scene_base_find(scene, marker->camera);
+ base = BKE_view_layer_base_find(view_layer, marker->camera);
if (base) {
- ED_base_object_select(base, sel);
+ ED_object_base_select(base, sel);
if (sel)
- ED_base_object_activate(C, base);
+ ED_object_base_activate(C, base);
}
}
}
@@ -1517,7 +1557,7 @@ static void MARKER_OT_make_links_scene(wmOperatorType *ot)
#ifdef DURIAN_CAMERA_SWITCH
/* ******************************* camera bind marker ***************** */
-static int ed_marker_camera_bind_exec(bContext *C, wmOperator *UNUSED(op))
+static int ed_marker_camera_bind_exec(bContext *C, wmOperator *op)
{
bScreen *sc = CTX_wm_screen(C);
Scene *scene = CTX_data_scene(C);
@@ -1525,15 +1565,37 @@ static int ed_marker_camera_bind_exec(bContext *C, wmOperator *UNUSED(op))
ListBase *markers = ED_context_get_markers(C);
TimeMarker *marker;
- marker = ED_markers_get_first_selected(markers);
- if (marker == NULL)
+ /* Don't do anything if we don't have a camera selected */
+ if (ob == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Select a camera to bind to a marker on this frame");
return OPERATOR_CANCELLED;
+ }
+
+ /* add new marker, unless we already have one on this frame, in which case, replace it */
+ if (markers == NULL)
+ return OPERATOR_CANCELLED;
+
+ marker = ED_markers_find_nearest_marker(markers, CFRA);
+ if ((marker == NULL) || (marker->frame != CFRA)) {
+ marker = MEM_callocN(sizeof(TimeMarker), "Camera TimeMarker");
+ marker->flag = SELECT;
+ marker->frame = CFRA;
+ BLI_addtail(markers, marker);
+
+ /* deselect all others, so that the user can then move it without problems */
+ for (TimeMarker *m = markers->first; m; m = m->next) {
+ if (m != marker) {
+ m->flag &= ~SELECT;
+ }
+ }
+ }
+ /* bind to the nominated camera (as set in operator props) */
marker->camera = ob;
/* camera may have changes */
BKE_scene_camera_switch_update(scene);
- BKE_screen_view3d_scene_sync(sc);
+ BKE_screen_view3d_scene_sync(sc, scene);
WM_event_add_notifier(C, NC_SCENE | ND_MARKERS, NULL);
WM_event_add_notifier(C, NC_ANIMATION | ND_MARKERS, NULL);
@@ -1546,13 +1608,13 @@ static void MARKER_OT_camera_bind(wmOperatorType *ot)
{
/* identifiers */
ot->name = "Bind Camera to Markers";
- ot->description = "Bind the active camera to selected marker(s)";
+ ot->description = "Bind the selected camera to a marker on the current frame";
ot->idname = "MARKER_OT_camera_bind";
/* api callbacks */
ot->exec = ed_marker_camera_bind_exec;
ot->invoke = ed_markers_opwrap_invoke;
- ot->poll = ed_markers_poll_selected_no_locked_markers;
+ ot->poll = ED_operator_animview_active;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
diff --git a/source/blender/editors/animation/anim_ops.c b/source/blender/editors/animation/anim_ops.c
index f22c8c5b403..eace5af4701 100644
--- a/source/blender/editors/animation/anim_ops.c
+++ b/source/blender/editors/animation/anim_ops.c
@@ -75,7 +75,7 @@ static int change_frame_poll(bContext *C)
* this shouldn't show up in 3D editor (or others without 2D timeline view) via search
*/
if (sa) {
- if (ELEM(sa->spacetype, SPACE_TIME, SPACE_ACTION, SPACE_NLA, SPACE_SEQ, SPACE_CLIP)) {
+ if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_NLA, SPACE_SEQ, SPACE_CLIP)) {
return true;
}
else if (sa->spacetype == SPACE_IPO) {
@@ -86,7 +86,7 @@ static int change_frame_poll(bContext *C)
}
}
- CTX_wm_operator_poll_msg_set(C, "Expected an timeline/animation area to be active");
+ CTX_wm_operator_poll_msg_set(C, "Expected an animation area to be active");
return false;
}
@@ -276,6 +276,116 @@ static void ANIM_OT_change_frame(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
+
+/* ****************** Start/End Frame Operators *******************************/
+
+static int anim_set_end_frames_poll(bContext *C)
+{
+ ScrArea *sa = CTX_wm_area(C);
+
+ /* XXX temp? prevent changes during render */
+ if (G.is_rendering) return false;
+
+ /* although it's only included in keymaps for regions using ED_KEYMAP_ANIMATION,
+ * this shouldn't show up in 3D editor (or others without 2D timeline view) via search
+ */
+ if (sa) {
+ if (ELEM(sa->spacetype, SPACE_ACTION, SPACE_IPO, SPACE_NLA, SPACE_SEQ, SPACE_CLIP)) {
+ return true;
+ }
+ }
+
+ CTX_wm_operator_poll_msg_set(C, "Expected an animation area to be active");
+ return false;
+}
+
+static int anim_set_sfra_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Scene *scene = CTX_data_scene(C);
+ int frame;
+
+ if (scene == NULL)
+ return OPERATOR_CANCELLED;
+
+ frame = CFRA;
+
+ /* if Preview Range is defined, set the 'start' frame for that */
+ if (PRVRANGEON)
+ scene->r.psfra = frame;
+ else
+ scene->r.sfra = frame;
+
+ if (PEFRA < frame) {
+ if (PRVRANGEON)
+ scene->r.pefra = frame;
+ else
+ scene->r.efra = frame;
+ }
+
+ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ANIM_OT_start_frame_set(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Set Start Frame";
+ ot->idname = "ANIM_OT_start_frame_set";
+ ot->description = "Set the start frame";
+
+ /* api callbacks */
+ ot->exec = anim_set_sfra_exec;
+ ot->poll = anim_set_end_frames_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+
+static int anim_set_efra_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Scene *scene = CTX_data_scene(C);
+ int frame;
+
+ if (scene == NULL)
+ return OPERATOR_CANCELLED;
+
+ frame = CFRA;
+
+ /* if Preview Range is defined, set the 'end' frame for that */
+ if (PRVRANGEON)
+ scene->r.pefra = frame;
+ else
+ scene->r.efra = frame;
+
+ if (PSFRA > frame) {
+ if (PRVRANGEON)
+ scene->r.psfra = frame;
+ else
+ scene->r.sfra = frame;
+ }
+
+ WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
+
+ return OPERATOR_FINISHED;
+}
+
+static void ANIM_OT_end_frame_set(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Set End Frame";
+ ot->idname = "ANIM_OT_end_frame_set";
+ ot->description = "Set the end frame";
+
+ /* api callbacks */
+ ot->exec = anim_set_efra_exec;
+ ot->poll = anim_set_end_frames_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
/* ****************** set preview range operator ****************************/
static int previewrange_define_exec(bContext *C, wmOperator *op)
@@ -383,6 +493,9 @@ void ED_operatortypes_anim(void)
/* Animation Editors only -------------------------- */
WM_operatortype_append(ANIM_OT_change_frame);
+ WM_operatortype_append(ANIM_OT_start_frame_set);
+ WM_operatortype_append(ANIM_OT_end_frame_set);
+
WM_operatortype_append(ANIM_OT_previewrange_set);
WM_operatortype_append(ANIM_OT_previewrange_clear);
diff --git a/source/blender/editors/animation/drivers.c b/source/blender/editors/animation/drivers.c
index 24eb6451c5d..2d04f73c4ac 100644
--- a/source/blender/editors/animation/drivers.c
+++ b/source/blender/editors/animation/drivers.c
@@ -44,11 +44,13 @@
#include "DNA_texture_types.h"
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_context.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_keyframing.h"
#include "UI_interface.h"
@@ -843,7 +845,7 @@ static int add_driver_button_none(bContext *C, wmOperator *op, short mapping_typ
if (success) {
/* send updates */
UI_context_update_anim_flag(C);
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX
return OPERATOR_FINISHED;
@@ -941,7 +943,7 @@ static int remove_driver_button_exec(bContext *C, wmOperator *op)
if (success) {
/* send updates */
UI_context_update_anim_flag(C);
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX
}
@@ -1031,8 +1033,8 @@ static int paste_driver_button_exec(bContext *C, wmOperator *op)
UI_context_update_anim_flag(C);
- DAG_relations_tag_update(CTX_data_main(C));
- DAG_id_tag_update(ptr.id.data, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_relations_tag_update(CTX_data_main(C));
+ DEG_id_tag_update(ptr.id.data, OB_RECALC_OB | OB_RECALC_DATA);
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME_PROP, NULL); // XXX
diff --git a/source/blender/editors/animation/keyframes_draw.c b/source/blender/editors/animation/keyframes_draw.c
index f25dbf2381c..98ad2041018 100644
--- a/source/blender/editors/animation/keyframes_draw.c
+++ b/source/blender/editors/animation/keyframes_draw.c
@@ -52,7 +52,8 @@
#include "BKE_fcurve.h"
-#include "BIF_gl.h"
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -463,49 +464,15 @@ bool actkeyblock_is_valid(ActKeyBlock *ab, DLRBT_Tree *keys)
/* *************************** Keyframe Drawing *************************** */
-/* coordinates for diamond shape */
-static const float _unit_diamond_shape[4][2] = {
- {0.0f, 1.0f}, /* top vert */
- {1.0f, 0.0f}, /* mid-right */
- {0.0f, -1.0f}, /* bottom vert */
- {-1.0f, 0.0f} /* mid-left */
-};
-
-/* draw a simple diamond shape with OpenGL */
-void draw_keyframe_shape(float x, float y, float xscale, float hsize, short sel, short key_type, short mode, float alpha)
+void draw_keyframe_shape(float x, float y, float size, bool sel, short key_type, short mode, float alpha,
+ unsigned int pos_id, unsigned int size_id, unsigned int color_id, unsigned int outline_color_id)
{
- static GLuint displist1 = 0;
- static GLuint displist2 = 0;
-
- /* initialize 2 display lists for diamond shape - one empty, one filled */
- if (displist1 == 0) {
- displist1 = glGenLists(1);
- glNewList(displist1, GL_COMPILE);
-
- glBegin(GL_LINE_LOOP);
- glVertex2fv(_unit_diamond_shape[0]);
- glVertex2fv(_unit_diamond_shape[1]);
- glVertex2fv(_unit_diamond_shape[2]);
- glVertex2fv(_unit_diamond_shape[3]);
- glEnd();
-
- glEndList();
- }
- if (displist2 == 0) {
- displist2 = glGenLists(1);
- glNewList(displist2, GL_COMPILE);
-
- glBegin(GL_QUADS);
- glVertex2fv(_unit_diamond_shape[0]);
- glVertex2fv(_unit_diamond_shape[1]);
- glVertex2fv(_unit_diamond_shape[2]);
- glVertex2fv(_unit_diamond_shape[3]);
- glEnd();
-
- glEndList();
- }
-
- /* tweak size of keyframe shape according to type of keyframe
+ bool draw_fill = ELEM(mode, KEYFRAME_SHAPE_INSIDE, KEYFRAME_SHAPE_BOTH);
+ bool draw_outline = ELEM(mode, KEYFRAME_SHAPE_FRAME, KEYFRAME_SHAPE_BOTH);
+
+ BLI_assert(draw_fill || draw_outline);
+
+ /* tweak size of keyframe shape according to type of keyframe
* - 'proper' keyframes have key_type = 0, so get drawn at full size
*/
switch (key_type) {
@@ -513,120 +480,92 @@ void draw_keyframe_shape(float x, float y, float xscale, float hsize, short sel,
break;
case BEZT_KEYTYPE_BREAKDOWN: /* slightly smaller than normal keyframe */
- hsize *= 0.85f;
+ size *= 0.85f;
break;
case BEZT_KEYTYPE_MOVEHOLD: /* slightly smaller than normal keyframes (but by less than for breakdowns) */
- //hsize *= 0.72f;
- hsize *= 0.95f;
+ size *= 0.925f;
break;
case BEZT_KEYTYPE_EXTREME: /* slightly larger */
- hsize *= 1.2f;
+ size *= 1.2f;
break;
default:
- hsize -= 0.5f * key_type;
- break;
+ size -= 0.8f * key_type;
}
-
- /* adjust view transform before starting */
- glTranslatef(x, y, 0.0f);
- glScalef(1.0f / xscale * hsize, hsize, 1.0f);
-
- /* anti-aliased lines for more consistent appearance */
- glEnable(GL_LINE_SMOOTH);
-
+
+ unsigned char fill_col[4];
+ unsigned char outline_col[4];
+
/* draw! */
- if (ELEM(mode, KEYFRAME_SHAPE_INSIDE, KEYFRAME_SHAPE_BOTH)) {
- float inner_col[4];
-
+ if (draw_fill) {
/* get interior colors from theme (for selected and unselected only) */
switch (key_type) {
case BEZT_KEYTYPE_BREAKDOWN: /* bluish frames (default theme) */
- {
- if (sel) UI_GetThemeColor4fv(TH_KEYTYPE_BREAKDOWN_SELECT, inner_col);
- else UI_GetThemeColor4fv(TH_KEYTYPE_BREAKDOWN, inner_col);
+ UI_GetThemeColor4ubv(sel ? TH_KEYTYPE_BREAKDOWN_SELECT : TH_KEYTYPE_BREAKDOWN, fill_col);
break;
- }
case BEZT_KEYTYPE_EXTREME: /* reddish frames (default theme) */
- {
- if (sel) UI_GetThemeColor4fv(TH_KEYTYPE_EXTREME_SELECT, inner_col);
- else UI_GetThemeColor4fv(TH_KEYTYPE_EXTREME, inner_col);
+ UI_GetThemeColor4ubv(sel ? TH_KEYTYPE_EXTREME_SELECT : TH_KEYTYPE_EXTREME, fill_col);
break;
- }
case BEZT_KEYTYPE_JITTER: /* greenish frames (default theme) */
- {
- if (sel) UI_GetThemeColor4fv(TH_KEYTYPE_JITTER_SELECT, inner_col);
- else UI_GetThemeColor4fv(TH_KEYTYPE_JITTER, inner_col);
+ UI_GetThemeColor4ubv(sel ? TH_KEYTYPE_JITTER_SELECT : TH_KEYTYPE_JITTER, fill_col);
break;
- }
case BEZT_KEYTYPE_MOVEHOLD: /* similar to traditional keyframes, but different... */
- {
/* XXX: Should these get their own theme options instead? */
- if (sel) UI_GetThemeColorShade4fv(TH_STRIP_SELECT, 35, inner_col);
- else UI_GetThemeColorShade4fv(TH_STRIP, 50, inner_col);
-
- inner_col[3] = 1.0f; /* full opacity, to avoid problems with visual glitches */
+ if (sel) UI_GetThemeColorShade3ubv(TH_STRIP_SELECT, 35, fill_col);
+ else UI_GetThemeColorShade3ubv(TH_STRIP, 50, fill_col);
+ fill_col[3] = 255; /* full opacity, to avoid problems with visual glitches */
break;
- }
case BEZT_KEYTYPE_KEYFRAME: /* traditional yellowish frames (default theme) */
default:
- {
- if (sel) UI_GetThemeColor4fv(TH_KEYTYPE_KEYFRAME_SELECT, inner_col);
- else UI_GetThemeColor4fv(TH_KEYTYPE_KEYFRAME, inner_col);
- break;
- }
+ UI_GetThemeColor4ubv(sel ? TH_KEYTYPE_KEYFRAME_SELECT : TH_KEYTYPE_KEYFRAME, fill_col);
}
/* NOTE: we don't use the straight alpha from the theme, or else effects such as
* graying out protected/muted channels doesn't work correctly!
*/
- inner_col[3] *= alpha;
- glColor4fv(inner_col);
-
- /* draw the "filled in" interior poly now */
- glCallList(displist2);
+ fill_col[3] *= alpha;
+
+ if (!draw_outline) {
+ /* force outline color to match */
+ outline_col[0] = fill_col[0];
+ outline_col[1] = fill_col[1];
+ outline_col[2] = fill_col[2];
+ outline_col[3] = fill_col[3];
+ }
}
-
- if (ELEM(mode, KEYFRAME_SHAPE_FRAME, KEYFRAME_SHAPE_BOTH)) {
- float border_col[4];
-
+
+ if (draw_outline) {
/* exterior - black frame */
- if (sel) UI_GetThemeColor4fv(TH_KEYBORDER_SELECT, border_col);
- else UI_GetThemeColor4fv(TH_KEYBORDER, border_col);
-
- border_col[3] *= alpha;
- glColor4fv(border_col);
-
- glCallList(displist1);
+ UI_GetThemeColor4ubv(sel ? TH_KEYBORDER_SELECT : TH_KEYBORDER, outline_col);
+ outline_col[3] *= alpha;
+
+ if (!draw_fill) {
+ /* fill color needs to be (outline.rgb, 0) */
+ fill_col[0] = outline_col[0];
+ fill_col[1] = outline_col[1];
+ fill_col[2] = outline_col[2];
+ fill_col[3] = 0;
+ }
}
-
- glDisable(GL_LINE_SMOOTH);
-
- /* restore view transform */
- glScalef(xscale / hsize, 1.0f / hsize, 1.0f);
- glTranslatef(-x, -y, 0.0f);
+
+ immAttrib1f(size_id, size);
+ immAttrib4ubv(color_id, fill_col);
+ immAttrib4ubv(outline_color_id, outline_col);
+ immVertex2f(pos_id, x, y);
}
static void draw_keylist(View2D *v2d, DLRBT_Tree *keys, DLRBT_Tree *blocks, float ypos, float yscale_fac, bool channelLocked)
{
- ActKeyColumn *ak;
- ActKeyBlock *ab;
- float alpha;
- float xscale;
-
- const float iconsize = (U.widget_unit / 4.0f) * yscale_fac;
- const float mhsize = iconsize * 0.7f;
+ const float icon_sz = U.widget_unit * 0.5f * yscale_fac;
+ const float half_icon_sz = 0.5f * icon_sz;
glEnable(GL_BLEND);
- /* get View2D scaling factor */
- UI_view2d_scale_get(v2d, &xscale, NULL);
-
/* locked channels are less strongly shown, as feedback for locked channels in DopeSheet */
/* TODO: allow this opacity factor to be themed? */
- alpha = (channelLocked) ? 0.25f : 1.0f;
+ float alpha = channelLocked ? 0.25f : 1.0f;
/* draw keyblocks */
if (blocks) {
@@ -644,45 +583,74 @@ static void draw_keylist(View2D *v2d, DLRBT_Tree *keys, DLRBT_Tree *blocks, floa
sel_mhcol[3] *= 0.8f;
copy_v4_v4(unsel_mhcol, unsel_color);
unsel_mhcol[3] *= 0.8f;
-
- /* NOTE: the tradeoff for changing colors between each draw is dwarfed by the cost of checking validity */
- for (ab = blocks->first; ab; ab = ab->next) {
+
+ unsigned int block_ct = 0;
+ for (ActKeyBlock *ab = blocks->first; ab; ab = ab->next) {
if (actkeyblock_is_valid(ab, keys)) {
- if (ab->flag & ACTKEYBLOCK_FLAG_MOVING_HOLD) {
- /* draw "moving hold" long-keyframe block - slightly smaller */
- if (ab->sel)
- glColor4fv(sel_mhcol);
- else
- glColor4fv(unsel_mhcol);
-
- glRectf(ab->start, ypos - mhsize, ab->end, ypos + mhsize);
- }
- else {
- /* draw standard long-keyframe block */
- if (ab->sel)
- glColor4fv(sel_color);
- else
- glColor4fv(unsel_color);
-
- glRectf(ab->start, ypos - iconsize, ab->end, ypos + iconsize);
+ block_ct++;
+ }
+ }
+
+ if (block_ct > 0) {
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color_id = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ immBegin(GWN_PRIM_TRIS, 6 * block_ct);
+ for (ActKeyBlock *ab = blocks->first; ab; ab = ab->next) {
+ if (actkeyblock_is_valid(ab, keys)) {
+ if (ab->flag & ACTKEYBLOCK_FLAG_MOVING_HOLD) {
+ /* draw "moving hold" long-keyframe block - slightly smaller */
+ immRectf_fast_with_color(pos_id, color_id,
+ ab->start, ypos - half_icon_sz, ab->end, ypos + half_icon_sz,
+ (ab->sel) ? sel_mhcol : unsel_mhcol);
+ }
+ else {
+ /* draw standard long-keyframe block */
+ immRectf_fast_with_color(pos_id, color_id,
+ ab->start, ypos - half_icon_sz, ab->end, ypos + half_icon_sz,
+ (ab->sel) ? sel_color : unsel_color);
+ }
}
}
+ immEnd();
+ immUnbindProgram();
}
}
- /* draw keys */
if (keys) {
- for (ak = keys->first; ak; ak = ak->next) {
+ /* count keys */
+ unsigned int key_ct = 0;
+ for (ActKeyColumn *ak = keys->first; ak; ak = ak->next) {
/* optimization: if keyframe doesn't appear within 5 units (screenspace) in visible area, don't draw
* - this might give some improvements, since we current have to flip between view/region matrices
*/
- if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax) == 0)
- continue;
-
- /* draw using OpenGL - uglier but faster */
- /* NOTE1: a previous version of this didn't work nice for some intel cards
- * NOTE2: if we wanted to go back to icons, these are icon = (ak->sel & SELECT) ? ICON_SPACE2 : ICON_SPACE3; */
- draw_keyframe_shape(ak->cfra, ypos, xscale, iconsize, (ak->sel & SELECT), ak->key_type, KEYFRAME_SHAPE_BOTH, alpha);
+ if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax))
+ key_ct++;
+ }
+
+ if (key_ct > 0) {
+ /* draw keys */
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int size_id = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color_id = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ unsigned int outline_color_id = GWN_vertformat_attr_add(format, "outlineColor", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
+ GPU_enable_program_point_size();
+ immBegin(GWN_PRIM_POINTS, key_ct);
+
+ for (ActKeyColumn *ak = keys->first; ak; ak = ak->next) {
+ if (IN_RANGE_INCL(ak->cfra, v2d->cur.xmin, v2d->cur.xmax)) {
+ draw_keyframe_shape(ak->cfra, ypos, icon_sz, (ak->sel & SELECT), ak->key_type, KEYFRAME_SHAPE_BOTH, alpha,
+ pos_id, size_id, color_id, outline_color_id);
+ }
+ }
+
+ immEnd();
+ GPU_disable_program_point_size();
+ immUnbindProgram();
}
}
diff --git a/source/blender/editors/animation/keyframing.c b/source/blender/editors/animation/keyframing.c
index c2a0b6579bb..7b637e5b725 100644
--- a/source/blender/editors/animation/keyframing.c
+++ b/source/blender/editors/animation/keyframing.c
@@ -56,7 +56,6 @@
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_armature.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_idcode.h"
#include "BKE_nla.h"
@@ -66,6 +65,9 @@
#include "BKE_key.h"
#include "BKE_material.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_anim_api.h"
#include "ED_keyframing.h"
#include "ED_keyframes_edit.h"
@@ -155,9 +157,11 @@ bAction *verify_adt_action(ID *id, short add)
/* tag depsgraph to be rebuilt to include time dependency */
/* XXX: we probably should have bmain passed down, but that involves altering too many API's */
- DAG_relations_tag_update(G.main);
+ DEG_relations_tag_update(G.main);
}
-
+
+ DEG_id_tag_update(&adt->action->id, DEG_TAG_COPY_ON_WRITE);
+
/* return the action */
return adt->action;
}
@@ -1618,7 +1622,7 @@ static int clear_anim_v3d_exec(bContext *C, wmOperator *UNUSED(op))
/* delete F-Curve completely */
if (can_delete) {
ANIM_fcurve_delete_from_animdata(NULL, adt, fcu);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
changed = true;
}
}
@@ -1725,7 +1729,7 @@ static int delete_key_v3d_exec(bContext *C, wmOperator *op)
else
BKE_reportf(op->reports, RPT_ERROR, "No keyframes removed from Object '%s'", id->name + 2);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
CTX_DATA_END;
diff --git a/source/blender/editors/animation/keyingsets.c b/source/blender/editors/animation/keyingsets.c
index ad08caba799..a3c7a23f8ee 100644
--- a/source/blender/editors/animation/keyingsets.c
+++ b/source/blender/editors/animation/keyingsets.c
@@ -48,9 +48,10 @@
#include "BKE_main.h"
#include "BKE_animsys.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "ED_keyframing.h"
#include "ED_screen.h"
@@ -1049,10 +1050,11 @@ int ANIM_apply_keyingset(bContext *C, ListBase *dsources, bAction *act, KeyingSe
Object *ob = (Object *)ksp->id;
// XXX: only object transforms?
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
break;
}
default:
+ DEG_id_tag_update(ksp->id, DEG_TAG_COPY_ON_WRITE);
break;
}
diff --git a/source/blender/editors/armature/BIF_generate.h b/source/blender/editors/armature/BIF_generate.h
deleted file mode 100644
index 71109574fe0..00000000000
--- a/source/blender/editors/armature/BIF_generate.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/armature/BIF_generate.h
- * \ingroup edarmature
- */
-
-
-#ifndef __BIF_GENERATE_H__
-#define __BIF_GENERATE_H__
-
-struct ToolSettings;
-struct EditBone;
-struct BArcIterator;
-struct bArmature;
-struct ListBase;
-
-typedef int (NextSubdivisionFunc)(struct ToolSettings *, struct BArcIterator *, int, int, float[3], float[3]);
-
-float calcArcCorrelation(struct BArcIterator *iter, int start, int end, float v0[3], float n[3]);
-
-int nextFixedSubdivision(struct ToolSettings *toolsettings, struct BArcIterator *iter, int start, int end, float head[3], float p[3]);
-int nextLengthSubdivision(struct ToolSettings *toolsettings, struct BArcIterator *iter, int start, int end, float head[3], float p[3]);
-int nextAdaptativeSubdivision(struct ToolSettings *toolsettings, struct BArcIterator *iter, int start, int end, float head[3], float p[3]);
-
-struct EditBone *subdivideArcBy(struct ToolSettings *toolsettings, struct bArmature *arm, ListBase *editbones, struct BArcIterator *iter,
- float invmat[4][4], float tmat[3][3], NextSubdivisionFunc next_subdividion);
-
-void setBoneRollFromNormal(struct EditBone *bone, const float no[3], float invmat[4][4], float tmat[3][3]);
-
-
-#endif /* __BIF_GENERATE_H__ */
diff --git a/source/blender/editors/armature/BIF_retarget.h b/source/blender/editors/armature/BIF_retarget.h
deleted file mode 100644
index aa56f847f00..00000000000
--- a/source/blender/editors/armature/BIF_retarget.h
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/armature/BIF_retarget.h
- * \ingroup edarmature
- */
-
-#ifndef __BIF_RETARGET_H__
-#define __BIF_RETARGET_H__
-
-#include "DNA_listBase.h"
-
-#include "BLI_graph.h"
-#include "BLI_ghash.h"
-#include "BLI_task.h"
-#include "BLI_threads.h"
-
-#include "reeb.h"
-
-struct Object;
-struct bArmature;
-struct bContext;
-
-struct EditBone;
-
-struct RigGraph;
-struct RigNode;
-struct RigArc;
-struct RigEdge;
-
-#define USE_THREADS
-
-typedef struct RigGraph {
- ListBase arcs;
- ListBase nodes;
-
- float length;
-
- FreeArc free_arc;
- FreeNode free_node;
- RadialSymmetry radial_symmetry;
- AxialSymmetry axial_symmetry;
- /*********************************/
-
- int flag;
-
- ListBase controls;
- ListBase *editbones;
-
- struct RigNode *head;
- ReebGraph *link_mesh;
-
-
- TaskScheduler *task_scheduler;
- TaskPool *task_pool;
-
- GHash *bones_map; /* map of editbones by name */
- GHash *controls_map; /* map of rigcontrols by bone pointer */
-
- struct Object *ob;
-} RigGraph;
-
-typedef struct RigNode {
- void *next, *prev;
- float p[3];
- int flag;
-
- int degree;
- struct BArc **arcs;
-
- int subgraph_index;
-
- int symmetry_level;
- int symmetry_flag;
- float symmetry_axis[3];
- /*********************************/
-
- ReebNode *link_mesh;
-} RigNode;
-
-typedef struct RigArc {
- void *next, *prev;
- RigNode *head, *tail;
- int flag;
-
- float length;
-
- int symmetry_level;
- int symmetry_group;
- int symmetry_flag;
- /*********************************/
-
- ListBase edges;
- int count;
- ReebArc *link_mesh;
-} RigArc;
-
-typedef struct RigEdge {
- struct RigEdge *next, *prev;
- float head[3], tail[3];
- float length;
- float angle; /* angle to next edge */
- float up_angle; /* angle between up_axis and the joint normal (defined as Previous edge CrossProduct Current edge */
- struct EditBone *bone;
- float up_axis[3];
-} RigEdge;
-
-/* Graph flags */
-#define RIG_FREE_BONELIST 1
-
-/* Control flags */
-#define RIG_CTRL_HEAD_DONE 1
-#define RIG_CTRL_TAIL_DONE 2
-#define RIG_CTRL_PARENT_DEFORM 4
-#define RIG_CTRL_FIT_ROOT 8
-#define RIG_CTRL_FIT_BONE 16
-
-#define RIG_CTRL_DONE (RIG_CTRL_HEAD_DONE | RIG_CTRL_TAIL_DONE)
-
-/* Control tail flags */
-typedef enum {
- TL_NONE = 0,
- TL_TAIL,
- TL_HEAD
-} LinkTailMode;
-
-typedef struct RigControl {
- struct RigControl *next, *prev;
- float head[3], tail[3];
- struct EditBone *bone;
- struct EditBone *link;
- struct EditBone *link_tail;
- float up_axis[3];
- float offset[3];
- float qrot[4]; /* for dual linked bones, store the rotation of the linked bone for the finalization */
- int flag;
- LinkTailMode tail_mode;
-} RigControl;
-
-void BIF_retargetArc(struct bContext *C, ReebArc *earc, RigGraph *template_rigg);
-RigGraph *RIG_graphFromArmature(const struct bContext *C, struct Object *ob, struct bArmature *arm);
-int RIG_nbJoints(RigGraph *rg);
-const char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index);
-void RIG_freeRigGraph(BGraph *rg);
-
-/* UNUSED */
-void BIF_retargetArmature(bContext *C);
-void BIF_adjustRetarget(bContext *C);
-/* UNUSED / print funcs */
-void RIG_printArc(struct RigGraph *rg, struct RigArc *arc);
-void RIG_printGraph(struct RigGraph *rg);
-void RIG_printArcBones(struct RigArc *arc);
-
-#endif /* __BIF_RETARGET_H__ */
diff --git a/source/blender/editors/armature/CMakeLists.txt b/source/blender/editors/armature/CMakeLists.txt
index 4c394d7836a..96467ee2c2a 100644
--- a/source/blender/editors/armature/CMakeLists.txt
+++ b/source/blender/editors/armature/CMakeLists.txt
@@ -23,10 +23,12 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../gpu
../../makesdna
../../makesrna
../../windowmanager
+ ../../../../intern/clog
../../../../intern/guardedalloc
../../../../intern/eigen
../../../../intern/glew-mx
@@ -45,9 +47,6 @@ set(SRC
armature_select.c
armature_skinning.c
armature_utils.c
- editarmature_generate.c
- editarmature_retarget.c
- editarmature_sketch.c
editarmature_undo.c
meshlaplacian.c
pose_edit.c
@@ -57,13 +56,9 @@ set(SRC
pose_slide.c
pose_transform.c
pose_utils.c
- reeb.c
- BIF_generate.h
- BIF_retarget.h
armature_intern.h
meshlaplacian.h
- reeb.h
)
if(WITH_INTERNATIONAL)
diff --git a/source/blender/editors/armature/armature_add.c b/source/blender/editors/armature/armature_add.c
index cb072bee345..8109fc27cea 100644
--- a/source/blender/editors/armature/armature_add.c
+++ b/source/blender/editors/armature/armature_add.c
@@ -829,7 +829,7 @@ static int armature_extrude_exec(bContext *C, wmOperator *op)
{
Object *obedit;
bArmature *arm;
- EditBone *newbone, *ebone, *flipbone, *first = NULL;
+ EditBone *newbone = NULL, *ebone, *flipbone, *first = NULL;
int a, totbone = 0, do_extrude;
bool forked = RNA_boolean_get(op->ptr, "forked");
@@ -1074,7 +1074,6 @@ void ARMATURE_OT_bone_primitive_add(wmOperatorType *ot)
static int armature_subdivide_exec(bContext *C, wmOperator *op)
{
Object *obedit = CTX_data_edit_object(C);
- bArmature *arm = obedit->data;
EditBone *newbone, *tbone;
int cuts, i;
@@ -1083,7 +1082,7 @@ static int armature_subdivide_exec(bContext *C, wmOperator *op)
/* loop over all editable bones */
// XXX the old code did this in reverse order though!
- CTX_DATA_BEGIN(C, EditBone *, ebone, selected_editable_bones)
+ CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, selected_editable_bones, bArmature *, arm)
{
for (i = cuts + 1; i > 1; i--) {
/* compute cut ratio first */
diff --git a/source/blender/editors/armature/armature_edit.c b/source/blender/editors/armature/armature_edit.c
index 4562329706f..6a94443660b 100644
--- a/source/blender/editors/armature/armature_edit.c
+++ b/source/blender/editors/armature/armature_edit.c
@@ -48,8 +48,10 @@
#include "BKE_armature.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_global.h"
#include "BKE_report.h"
+#include "BKE_object.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -138,17 +140,16 @@ void ED_armature_transform(struct bArmature *arm, float mat[4][4], const bool do
/* exported for use in editors/object/ */
/* 0 == do center, 1 == center new, 2 == center cursor */
-void ED_armature_origin_set(Scene *scene, Object *ob, float cursor[3], int centermode, int around)
+void ED_armature_origin_set(Object *ob, float cursor[3], int centermode, int around)
{
- Object *obedit = scene->obedit; // XXX get from context
+ const bool is_editmode = BKE_object_is_in_editmode(ob);
EditBone *ebone;
bArmature *arm = ob->data;
float cent[3];
/* Put the armature into editmode */
- if (ob != obedit) {
+ if (is_editmode == false) {
ED_armature_to_edit(arm);
- obedit = NULL; /* we cant use this so behave as if there is no obedit */
}
/* Find the centerpoint */
@@ -188,13 +189,13 @@ void ED_armature_origin_set(Scene *scene, Object *ob, float cursor[3], int cente
}
/* Turn the list into an armature */
- if (obedit == NULL) {
+ if (is_editmode == false) {
ED_armature_from_edit(arm);
ED_armature_edit_free(arm);
}
/* Adjust object location for new centerpoint */
- if (centermode && obedit == NULL) {
+ if (centermode && (is_editmode == false)) {
mul_mat3_m4_v3(ob->obmat, cent); /* omit translation part */
add_v3_v3(ob->loc, cent);
}
@@ -630,25 +631,39 @@ static void fill_add_joint(EditBone *ebo, short eb_tail, ListBase *points)
/* bone adding between selected joints */
static int armature_fill_bones_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- bArmature *arm = (obedit) ? obedit->data : NULL;
+ Object *obedit_active = CTX_data_edit_object(C);
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
ListBase points = {NULL, NULL};
EditBone *newbone = NULL;
int count;
+ bool mixed_object_error = false;
/* sanity checks */
- if (ELEM(NULL, obedit, arm))
+ if (ELEM(NULL, obedit_active, obedit_active->data)) {
return OPERATOR_CANCELLED;
+ }
/* loop over all bones, and only consider if visible */
- CTX_DATA_BEGIN(C, EditBone *, ebone, visible_bones)
+ bArmature *arm = NULL;
+ CTX_DATA_BEGIN_WITH_ID(C, EditBone *, ebone, visible_bones, bArmature *, arm_iter)
{
- if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL))
+ bool check = false;
+ if (!(ebone->flag & BONE_CONNECTED) && (ebone->flag & BONE_ROOTSEL)) {
fill_add_joint(ebone, 0, &points);
- if (ebone->flag & BONE_TIPSEL)
+ check = true;
+ }
+ if (ebone->flag & BONE_TIPSEL) {
fill_add_joint(ebone, 1, &points);
+ check = true;
+ }
+
+ if (check) {
+ if (arm && (arm != arm_iter)) {
+ mixed_object_error = true;
+ }
+ arm = arm_iter;
+ }
}
CTX_DATA_END;
@@ -658,12 +673,30 @@ static int armature_fill_bones_exec(bContext *C, wmOperator *op)
* 3+) error (a smarter method involving finding chains needs to be worked out
*/
count = BLI_listbase_count(&points);
-
+
if (count == 0) {
BKE_report(op->reports, RPT_ERROR, "No joints selected");
return OPERATOR_CANCELLED;
}
- else if (count == 1) {
+ else if (mixed_object_error) {
+ BKE_report(op->reports, RPT_ERROR, "Bones for different objects selected");
+ BLI_freelistN(&points);
+ return OPERATOR_CANCELLED;
+ }
+
+ Object *obedit = NULL;
+ {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_EDIT, ob_iter) {
+ if (ob_iter->data == arm) {
+ obedit = ob_iter;
+ }
+ }
+ FOREACH_OBJECT_IN_MODE_END;
+ }
+ BLI_assert(obedit != NULL);
+
+ if (count == 1) {
EditBonePoint *ebp;
float curs[3];
@@ -1301,38 +1334,49 @@ static bool armature_delete_ebone_cb(const char *bone_name, void *arm_p)
/* only editmode! */
static int armature_delete_selected_exec(bContext *C, wmOperator *UNUSED(op))
{
- bArmature *arm;
EditBone *curBone, *ebone_next;
- Object *obedit = CTX_data_edit_object(C);
- bool changed = false;
- arm = obedit->data;
+ bool changed_multi = false;
/* cancel if nothing selected */
if (CTX_DATA_COUNT(C, selected_bones) == 0)
return OPERATOR_CANCELLED;
-
- armature_select_mirrored(arm);
-
- BKE_pose_channels_remove(obedit, armature_delete_ebone_cb, arm);
-
- for (curBone = arm->edbo->first; curBone; curBone = ebone_next) {
- ebone_next = curBone->next;
- if (arm->layer & curBone->layer) {
- if (curBone->flag & BONE_SELECTED) {
- if (curBone == arm->act_edbone) arm->act_edbone = NULL;
- ED_armature_ebone_remove(arm, curBone);
- changed = true;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ bArmature *arm = obedit->data;
+ bool changed = false;
+
+ armature_select_mirrored(arm);
+
+ BKE_pose_channels_remove(obedit, armature_delete_ebone_cb, arm);
+
+ for (curBone = arm->edbo->first; curBone; curBone = ebone_next) {
+ ebone_next = curBone->next;
+ if (arm->layer & curBone->layer) {
+ if (curBone->flag & BONE_SELECTED) {
+ if (curBone == arm->act_edbone) arm->act_edbone = NULL;
+ ED_armature_ebone_remove(arm, curBone);
+ changed = true;
+ }
}
}
+
+ if (changed) {
+ changed_multi = true;
+
+ ED_armature_edit_sync_selection(arm->edbo);
+ BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
+ }
}
-
- if (!changed)
- return OPERATOR_CANCELLED;
-
- ED_armature_edit_sync_selection(arm->edbo);
- BKE_pose_tag_recalc(CTX_data_main(C), obedit->pose);
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
+ if (!changed_multi) {
+ return OPERATOR_CANCELLED;
+ }
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/armature/armature_intern.h b/source/blender/editors/armature/armature_intern.h
index 192bb8eea61..7bc8764443f 100644
--- a/source/blender/editors/armature/armature_intern.h
+++ b/source/blender/editors/armature/armature_intern.h
@@ -139,18 +139,6 @@ void POSE_OT_quaternions_flip(struct wmOperatorType *ot);
void POSE_OT_bone_layers(struct wmOperatorType *ot);
/* ******************************************************* */
-/* Etch-A-Ton (Skeleton Sketching) Operators */
-
-void SKETCH_OT_gesture(struct wmOperatorType *ot);
-void SKETCH_OT_delete(struct wmOperatorType *ot);
-void SKETCH_OT_draw_stroke(struct wmOperatorType *ot);
-void SKETCH_OT_draw_preview(struct wmOperatorType *ot);
-void SKETCH_OT_finish_stroke(struct wmOperatorType *ot);
-void SKETCH_OT_cancel_stroke(struct wmOperatorType *ot);
-void SKETCH_OT_convert(struct wmOperatorType *ot);
-void SKETCH_OT_select(struct wmOperatorType *ot);
-
-/* ******************************************************* */
/* Pose Tool Utilities (for PoseLib, Pose Sliding, etc.) */
/* pose_utils.c */
@@ -225,7 +213,6 @@ void POSE_OT_propagate(struct wmOperatorType *ot);
*/
EditBone *make_boneList(struct ListBase *edbo, struct ListBase *bones, struct EditBone *parent, struct Bone *actBone);
-bool BIF_sk_selectStroke(struct bContext *C, const int mval[2], const bool extend);
/* duplicate method */
void preEditBoneDuplicate(struct ListBase *editbones);
@@ -248,10 +235,15 @@ void armature_select_mirrored_ex(struct bArmature *arm, const int flag);
void armature_select_mirrored(struct bArmature *arm);
void armature_tag_unselect(struct bArmature *arm);
-void *get_nearest_bone(struct bContext *C, const int xy[2], bool findunsel);
+void *get_nearest_bone(
+ struct bContext *C, const int xy[2], bool findunsel,
+ struct Base **r_base);
+
void *get_bone_from_selectbuffer(
- struct Scene *scene, struct Base *base, const unsigned int *buffer, short hits,
- bool findunsel, bool do_nearest);
+ struct Base **bases, uint bases_len,
+ bool is_editmode, const unsigned int *buffer, short hits,
+ bool findunsel, bool do_nearest,
+ struct Base **r_base);
int bone_looper(struct Object *ob, struct Bone *bone, void *data,
int (*bone_func)(struct Object *, struct Bone *, void *));
diff --git a/source/blender/editors/armature/armature_naming.c b/source/blender/editors/armature/armature_naming.c
index d5ed1380a7e..e8d45f72f89 100644
--- a/source/blender/editors/armature/armature_naming.c
+++ b/source/blender/editors/armature/armature_naming.c
@@ -48,11 +48,12 @@
#include "BKE_constraint.h"
#include "BKE_context.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -378,7 +379,7 @@ static int armature_flip_names_exec(bContext *C, wmOperator *op)
BLI_freelistN(&bones_names);
/* since we renamed stuff... */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* copied from #rna_Bone_update_renamed */
/* redraw view */
@@ -432,7 +433,7 @@ static int armature_autoside_names_exec(bContext *C, wmOperator *op)
CTX_DATA_END;
/* since we renamed stuff... */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* note, notifier might evolve */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
diff --git a/source/blender/editors/armature/armature_ops.c b/source/blender/editors/armature/armature_ops.c
index 5622cd0437d..c9cebadb47d 100644
--- a/source/blender/editors/armature/armature_ops.c
+++ b/source/blender/editors/armature/armature_ops.c
@@ -85,16 +85,6 @@ void ED_operatortypes_armature(void)
WM_operatortype_append(ARMATURE_OT_armature_layers);
WM_operatortype_append(ARMATURE_OT_bone_layers);
- /* SKETCH */
- WM_operatortype_append(SKETCH_OT_gesture);
- WM_operatortype_append(SKETCH_OT_delete);
- WM_operatortype_append(SKETCH_OT_draw_stroke);
- WM_operatortype_append(SKETCH_OT_draw_preview);
- WM_operatortype_append(SKETCH_OT_finish_stroke);
- WM_operatortype_append(SKETCH_OT_cancel_stroke);
- WM_operatortype_append(SKETCH_OT_convert);
- WM_operatortype_append(SKETCH_OT_select);
-
/* POSE */
WM_operatortype_append(POSE_OT_hide);
WM_operatortype_append(POSE_OT_reveal);
@@ -203,23 +193,6 @@ void ED_keymap_armature(wmKeyConfig *keyconf)
/* Armature ------------------------ */
keymap = WM_keymap_find(keyconf, "Armature", 0, 0);
keymap->poll = ED_operator_editarmature;
-
- /* Armature -> Etch-A-Ton ------------------------ */
- WM_keymap_add_item(keymap, "SKETCH_OT_delete", XKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "SKETCH_OT_delete", DELKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "SKETCH_OT_finish_stroke", RIGHTMOUSE, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "SKETCH_OT_cancel_stroke", ESCKEY, KM_PRESS, 0, 0);
- /* Already part of view3d select */
- //WM_keymap_add_item(keymap, "SKETCH_OT_select", SELECTMOUSE, KM_PRESS, 0, 0);
-
- /* sketch poll checks mode */
- WM_keymap_add_item(keymap, "SKETCH_OT_gesture", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
- WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, 0, 0);
- kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_stroke", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "snap", true);
- WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, 0, 0);
- kmi = WM_keymap_add_item(keymap, "SKETCH_OT_draw_preview", MOUSEMOVE, KM_ANY, KM_CTRL, 0);
- RNA_boolean_set(kmi->ptr, "snap", true);
/* only set in editmode armature, by space_view3d listener */
kmi = WM_keymap_add_item(keymap, "ARMATURE_OT_hide", HKEY, KM_PRESS, 0, 0);
diff --git a/source/blender/editors/armature/armature_relations.c b/source/blender/editors/armature/armature_relations.c
index 3c272d52d1c..91f8a8713bc 100644
--- a/source/blender/editors/armature/armature_relations.c
+++ b/source/blender/editors/armature/armature_relations.c
@@ -47,12 +47,15 @@
#include "BKE_animsys.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -370,7 +373,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
if (base->object->adt) {
if (ob->adt == NULL) {
/* no animdata, so just use a copy of the whole thing */
- ob->adt = BKE_animdata_copy(bmain, base->object->adt, false);
+ ob->adt = BKE_animdata_copy(bmain, base->object->adt, false, true);
}
else {
/* merge in data - we'll fix the drivers manually */
@@ -381,7 +384,7 @@ int join_armature_exec(bContext *C, wmOperator *op)
if (curarm->adt) {
if (arm->adt == NULL) {
/* no animdata, so just use a copy of the whole thing */
- arm->adt = BKE_animdata_copy(bmain, curarm->adt, false);
+ arm->adt = BKE_animdata_copy(bmain, curarm->adt, false, true);
}
else {
/* merge in data - we'll fix the drivers manually */
@@ -390,12 +393,12 @@ int join_armature_exec(bContext *C, wmOperator *op)
}
/* Free the old object data */
- ED_base_object_free_and_unlink(bmain, scene, base);
+ ED_object_base_free_and_unlink(bmain, scene, base->object);
}
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain); /* because we removed object(s) */
+ DEG_relations_tag_update(bmain); /* because we removed object(s) */
ED_armature_from_edit(arm);
ED_armature_edit_free(arm);
@@ -569,6 +572,7 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
Object *oldob, *newob;
Base *oldbase, *newbase;
@@ -592,14 +596,18 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
/* TODO: use context iterators for this? */
CTX_DATA_BEGIN(C, Base *, base, visible_bases)
{
- if (base->object == obedit) base->flag |= SELECT;
- else base->flag &= ~SELECT;
+ if (base->object == obedit) {
+ ED_object_base_select(base, BA_SELECT);
+ }
+ else {
+ ED_object_base_select(base, BA_DESELECT);
+ }
}
CTX_DATA_END;
/* 1) store starting settings and exit editmode */
oldob = obedit;
- oldbase = BASACT;
+ oldbase = view_layer->basact;
oldob->mode &= ~OB_MODE_POSE;
//oldbase->flag &= ~OB_POSEMODE;
@@ -607,13 +615,13 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
ED_armature_edit_free(obedit->data);
/* 2) duplicate base */
- newbase = ED_object_add_duplicate(bmain, scene, oldbase, USER_DUP_ARM); /* only duplicate linked armature */
- DAG_relations_tag_update(bmain);
+ newbase = ED_object_add_duplicate(bmain, scene, view_layer, oldbase, USER_DUP_ARM); /* only duplicate linked armature */
+ DEG_relations_tag_update(bmain);
newob = newbase->object;
- newbase->flag &= ~SELECT;
-
-
+ newbase->flag &= ~BASE_SELECTED;
+
+
/* 3) remove bones that shouldn't still be around on both armatures */
separate_armature_bones(oldob, 1);
separate_armature_bones(newob, 0);
@@ -622,8 +630,8 @@ static int separate_armature_exec(bContext *C, wmOperator *op)
/* 4) fix links before depsgraph flushes */ // err... or after?
separated_armature_fix_links(oldob, newob);
- DAG_id_tag_update(&oldob->id, OB_RECALC_DATA); /* this is the original one */
- DAG_id_tag_update(&newob->id, OB_RECALC_DATA); /* this is the separated one */
+ DEG_id_tag_update(&oldob->id, OB_RECALC_DATA); /* this is the original one */
+ DEG_id_tag_update(&newob->id, OB_RECALC_DATA); /* this is the separated one */
/* 5) restore original conditions */
diff --git a/source/blender/editors/armature/armature_select.c b/source/blender/editors/armature/armature_select.c
index ba856d4e964..65f845ce34c 100644
--- a/source/blender/editors/armature/armature_select.c
+++ b/source/blender/editors/armature/armature_select.c
@@ -29,6 +29,8 @@
* \ingroup edarmature
*/
+#include "MEM_guardedalloc.h"
+
#include "DNA_armature_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -39,7 +41,9 @@
#include "BKE_context.h"
#include "BKE_action.h"
+#include "BKE_object.h"
#include "BKE_report.h"
+#include "BKE_layer.h"
#include "BIF_gl.h"
@@ -53,6 +57,8 @@
#include "ED_screen.h"
#include "ED_view3d.h"
+#include "DEG_depsgraph.h"
+
#include "armature_intern.h"
/* utility macros for storing a temp int in the bone (selection flag) */
@@ -61,27 +67,84 @@
/* **************** PoseMode & EditMode Selection Buffer Queries *************************** */
-/* only for opengl selection indices */
-Bone *ED_armature_bone_find_index(Object *ob, int index)
+Base *ED_armature_base_and_ebone_from_select_buffer(
+ Base **bases, uint bases_len, int hit, EditBone **r_ebone)
{
- bPoseChannel *pchan;
- if (ob->pose == NULL) return NULL;
- index >>= 16; // bone selection codes use left 2 bytes
-
- pchan = BLI_findlink(&ob->pose->chanbase, index);
- return pchan ? pchan->bone : NULL;
+ const uint hit_object = hit & 0xFFFF;
+ Base *base = NULL;
+ EditBone *ebone = NULL;
+ /* TODO(campbell): optimize, eg: sort & binary search. */
+ for (uint base_index = 0; base_index < bases_len; base_index++) {
+ if (bases[base_index]->object->select_color == hit_object) {
+ base = bases[base_index];
+ break;
+ }
+ }
+ if (base != NULL) {
+ const uint hit_bone = (hit & ~BONESEL_ANY) >> 16;
+ bArmature *arm = base->object->data;
+ ebone = BLI_findlink(arm->edbo, hit_bone);
+ }
+ *r_ebone = ebone;
+ return base;
+}
+
+Object *ED_armature_object_and_ebone_from_select_buffer(
+ Object **objects, uint objects_len, int hit, EditBone **r_ebone)
+{
+ const uint hit_object = hit & 0xFFFF;
+ Object *ob = NULL;
+ EditBone *ebone = NULL;
+ /* TODO(campbell): optimize, eg: sort & binary search. */
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ if (objects[ob_index]->select_color == hit_object) {
+ ob = objects[ob_index];
+ break;
+ }
+ }
+ if (ob != NULL) {
+ const uint hit_bone = (hit & ~BONESEL_ANY) >> 16;
+ bArmature *arm = ob->data;
+ ebone = BLI_findlink(arm->edbo, hit_bone);
+ }
+ *r_ebone = ebone;
+ return ob;
+}
+
+Base *ED_armature_base_and_bone_from_select_buffer(
+ Base **bases, uint bases_len, int hit, Bone **r_bone)
+{
+ const uint hit_object = hit & 0xFFFF;
+ Base *base = NULL;
+ Bone *bone = NULL;
+ /* TODO(campbell): optimize, eg: sort & binary search. */
+ for (uint base_index = 0; base_index < bases_len; base_index++) {
+ if (bases[base_index]->object->select_color == hit_object) {
+ base = bases[base_index];
+ break;
+ }
+ }
+ if (base != NULL) {
+ if (base->object->pose != NULL) {
+ const uint hit_bone = (hit & ~BONESEL_ANY) >> 16;
+ bPoseChannel *pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone);;
+ bone = pchan ? pchan->bone : NULL;
+ }
+ }
+ *r_bone = bone;
+ return base;
}
/* See if there are any selected bones in this buffer */
/* only bones from base are checked on */
void *get_bone_from_selectbuffer(
- Scene *scene, Base *base, const unsigned int *buffer, short hits,
- bool findunsel, bool do_nearest)
+ Base **bases, uint bases_len, bool is_editmode, const unsigned int *buffer, short hits,
+ bool findunsel, bool do_nearest, Base **r_base)
{
- Object *obedit = scene->obedit; // XXX get from context
Bone *bone;
EditBone *ebone;
void *firstunSel = NULL, *firstSel = NULL, *data;
+ Base *firstunSel_base = NULL, *firstSel_base = NULL;
unsigned int hitresult;
short i;
bool takeNext = false;
@@ -92,15 +155,14 @@ void *get_bone_from_selectbuffer(
if (!(hitresult & BONESEL_NOSEL)) {
if (hitresult & BONESEL_ANY) { /* to avoid including objects in selection */
+ Base *base = NULL;
bool sel;
-
+
hitresult &= ~(BONESEL_ANY);
/* Determine what the current bone is */
- if (obedit == NULL || base->object != obedit) {
- /* no singular posemode, so check for correct object */
- if (base->selcol == (hitresult & 0xFFFF)) {
- bone = ED_armature_bone_find_index(base->object, hitresult);
-
+ if (is_editmode == false) {
+ base = ED_armature_base_and_bone_from_select_buffer(bases, bases_len, hitresult, &bone);
+ if (bone != NULL) {
if (findunsel)
sel = (bone->flag & BONE_SELECTED);
else
@@ -114,14 +176,12 @@ void *get_bone_from_selectbuffer(
}
}
else {
- bArmature *arm = obedit->data;
-
- ebone = BLI_findlink(arm->edbo, hitresult);
+ base = ED_armature_base_and_ebone_from_select_buffer(bases, bases_len, hitresult, &ebone);
if (findunsel)
sel = (ebone->flag & BONE_SELECTED);
else
sel = !(ebone->flag & BONE_SELECTED);
-
+
data = ebone;
}
@@ -130,11 +190,15 @@ void *get_bone_from_selectbuffer(
if (do_nearest) {
if (minsel > buffer[4 * i + 1]) {
firstSel = data;
+ firstSel_base = base;
minsel = buffer[4 * i + 1];
}
}
else {
- if (!firstSel) firstSel = data;
+ if (!firstSel) {
+ firstSel = data;
+ firstSel_base = base;
+ }
takeNext = 1;
}
}
@@ -142,12 +206,19 @@ void *get_bone_from_selectbuffer(
if (do_nearest) {
if (minunsel > buffer[4 * i + 1]) {
firstunSel = data;
+ firstunSel_base = base;
minunsel = buffer[4 * i + 1];
}
}
else {
- if (!firstunSel) firstunSel = data;
- if (takeNext) return data;
+ if (!firstunSel) {
+ firstunSel = data;
+ firstunSel_base = base;
+ }
+ if (takeNext) {
+ *r_base = base;
+ return data;
+ }
}
}
}
@@ -155,22 +226,28 @@ void *get_bone_from_selectbuffer(
}
}
- if (firstunSel)
+ if (firstunSel) {
+ *r_base = firstunSel_base;
return firstunSel;
- else
+ }
+ else {
+ *r_base = firstSel_base;
return firstSel;
+ }
}
/* used by posemode as well editmode */
/* only checks scene->basact! */
/* x and y are mouse coords (area space) */
-void *get_nearest_bone(bContext *C, const int xy[2], bool findunsel)
+void *get_nearest_bone(
+ bContext *C, const int xy[2], bool findunsel,
+ Base **r_base)
{
ViewContext vc;
rcti rect;
unsigned int buffer[MAXPICKBUF];
short hits;
-
+
ED_view3d_viewcontext_init(C, &vc);
// rect.xmin = ... mouseco!
@@ -179,9 +256,27 @@ void *get_nearest_bone(bContext *C, const int xy[2], bool findunsel)
hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST);
- if (hits > 0)
- return get_bone_from_selectbuffer(vc.scene, vc.scene->basact, buffer, hits, findunsel, true);
-
+ *r_base = NULL;
+
+ if (hits > 0) {
+ uint bases_len = 0;
+ Base **bases;
+
+ if (vc.obedit != NULL) {
+ bases = BKE_view_layer_array_from_bases_in_mode(
+ vc.view_layer, &bases_len, {
+ .object_mode = OB_MODE_EDIT});
+ }
+ else {
+ bases = BKE_object_pose_base_array_get(vc.view_layer, &bases_len);
+ }
+
+ void *bone = get_bone_from_selectbuffer(
+ bases, bases_len, vc.obedit != NULL, buffer, hits, findunsel, true, r_base);
+
+ MEM_freeN(bases);
+ return bone;
+ }
return NULL;
}
@@ -194,16 +289,17 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv
bArmature *arm;
EditBone *bone, *curBone, *next;
const bool extend = RNA_boolean_get(op->ptr, "extend");
- Object *obedit = CTX_data_edit_object(C);
- arm = obedit->data;
view3d_operator_needs_opengl(C);
- bone = get_nearest_bone(C, event->mval, !extend);
+ Base *base = NULL;
+ bone = get_nearest_bone(C, event->mval, !extend, &base);
if (!bone)
return OPERATOR_CANCELLED;
+ arm = base->object->data;
+
/* Select parents */
for (curBone = bone; curBone; curBone = next) {
if ((curBone->flag & BONE_UNSELECTABLE) == 0) {
@@ -246,7 +342,7 @@ static int armature_select_linked_invoke(bContext *C, wmOperator *op, const wmEv
ED_armature_edit_sync_selection(arm->edbo);
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, obedit);
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, base->object);
return OPERATOR_FINISHED;
}
@@ -292,36 +388,42 @@ static int selectbuffer_ret_hits_5(unsigned int *buffer, const int hits12, const
/* note that BONE ROOT only gets drawn for root bones (or without IK) */
static EditBone *get_nearest_editbonepoint(
ViewContext *vc,
- bool findunsel, bool use_cycle, int *r_selmask)
+ bool findunsel, bool use_cycle,
+ Base **r_base, int *r_selmask)
{
- bArmature *arm = (bArmature *)vc->obedit->data;
- EditBone *ebone_next_act = arm->act_edbone;
-
- EditBone *ebone;
- rcti rect;
- unsigned int buffer[MAXPICKBUF];
- unsigned int hitresult, besthitresult = BONESEL_NOSEL;
- int i, mindep = 5;
- int hits12, hits5 = 0;
-
- static int last_mval[2] = {-100, -100};
+ uint buffer[MAXPICKBUF];
+ struct {
+ uint hitresult;
+ Base *base;
+ EditBone *ebone;
+ } best = {
+ .hitresult = BONESEL_NOSEL,
+ .base = NULL,
+ .ebone = NULL,
+ };
/* find the bone after the current active bone, so as to bump up its chances in selection.
* this way overlapping bones will cycle selection state as with objects. */
- if (ebone_next_act &&
- EBONE_VISIBLE(arm, ebone_next_act) &&
- ebone_next_act->flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL))
+ EditBone *ebone_next_act = ((bArmature *)vc->obedit->data)->act_edbone;
{
- ebone_next_act = ebone_next_act->next ? ebone_next_act->next : arm->edbo->first;
- }
- else {
- ebone_next_act = NULL;
+ bArmature *arm = (bArmature *)vc->obedit->data;
+ if (ebone_next_act &&
+ EBONE_VISIBLE(arm, ebone_next_act) &&
+ ebone_next_act->flag & (BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL))
+ {
+ ebone_next_act = ebone_next_act->next ? ebone_next_act->next : arm->edbo->first;
+ }
+ else {
+ ebone_next_act = NULL;
+ }
}
bool do_nearest = false;
/* define if we use solid nearest select or not */
if (use_cycle) {
+ static int last_mval[2] = {-100, -100};
+
if (vc->v3d->drawtype > OB_WIRE) {
do_nearest = true;
if (len_manhattan_v2v2_int(vc->mval, last_mval) < 3) {
@@ -337,52 +439,64 @@ static EditBone *get_nearest_editbonepoint(
}
/* matching logic from 'mixed_bones_object_selectbuffer' */
- const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_NEAREST : VIEW3D_SELECT_PICK_ALL);
int hits = 0;
/* we _must_ end cache before return, use 'goto cache_end' */
view3d_opengl_select_cache_begin();
- BLI_rcti_init_pt_radius(&rect, vc->mval, 12);
- hits12 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
- if (hits12 == 1) {
- hits = selectbuffer_ret_hits_12(buffer, hits12);
- goto cache_end;
- }
- else if (hits12 > 0) {
- int offs;
-
- offs = 4 * hits12;
- BLI_rcti_init_pt_radius(&rect, vc->mval, 5);
- hits5 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode);
-
- if (hits5 == 1) {
- hits = selectbuffer_ret_hits_5(buffer, hits12, hits5);
+ {
+ const int select_mode = (do_nearest ? VIEW3D_SELECT_PICK_NEAREST : VIEW3D_SELECT_PICK_ALL);
+ rcti rect;
+ BLI_rcti_init_pt_radius(&rect, vc->mval, 12);
+ const int hits12 = view3d_opengl_select(vc, buffer, MAXPICKBUF, &rect, select_mode);
+ if (hits12 == 1) {
+ hits = selectbuffer_ret_hits_12(buffer, hits12);
goto cache_end;
}
+ else if (hits12 > 0) {
+ int offs;
+
+ offs = 4 * hits12;
+ BLI_rcti_init_pt_radius(&rect, vc->mval, 5);
+ const int hits5 = view3d_opengl_select(vc, buffer + offs, MAXPICKBUF - offs, &rect, select_mode);
- if (hits5 > 0) { hits = selectbuffer_ret_hits_5(buffer, hits12, hits5); goto cache_end; }
- else { hits = selectbuffer_ret_hits_12(buffer, hits12); goto cache_end; }
+ if (hits5 == 1) {
+ hits = selectbuffer_ret_hits_5(buffer, hits12, hits5);
+ goto cache_end;
+ }
+
+ if (hits5 > 0) { hits = selectbuffer_ret_hits_5(buffer, hits12, hits5); goto cache_end; }
+ else { hits = selectbuffer_ret_hits_12(buffer, hits12); goto cache_end; }
+ }
}
cache_end:
view3d_opengl_select_cache_end();
+ uint bases_len;
+ Base **bases = BKE_view_layer_array_from_bases_in_edit_mode_unique_data(vc->view_layer, &bases_len);
+
/* See if there are any selected bones in this group */
if (hits > 0) {
-
if (hits == 1) {
- if (!(buffer[3] & BONESEL_NOSEL))
- besthitresult = buffer[3];
+ if (!(buffer[3] & BONESEL_NOSEL)) {
+ best.hitresult = buffer[3];
+ best.base = ED_armature_base_and_ebone_from_select_buffer(
+ bases, bases_len, best.hitresult, &best.ebone);
+ }
}
else {
- for (i = 0; i < hits; i++) {
- hitresult = buffer[3 + (i * 4)];
+ int dep_min = 5;
+ for (int i = 0; i < hits; i++) {
+ const uint hitresult = buffer[3 + (i * 4)];
if (!(hitresult & BONESEL_NOSEL)) {
+ Base *base = NULL;
+ EditBone *ebone;
+ base = ED_armature_base_and_ebone_from_select_buffer(bases, bases_len, hitresult, &ebone);
+ /* If this fails, selection code is setting the selection ID's incorrectly. */
+ BLI_assert(base && ebone);
+
int dep;
-
- ebone = BLI_findlink(arm->edbo, hitresult & ~BONESEL_ANY);
-
/* clicks on bone points get advantage */
if (hitresult & (BONESEL_ROOT | BONESEL_TIP)) {
/* but also the unselected one */
@@ -415,29 +529,36 @@ cache_end:
dep -= 1;
}
- if (dep < mindep) {
- mindep = dep;
- besthitresult = hitresult;
+ if (dep < dep_min) {
+ dep_min = dep;
+ best.hitresult = hitresult;
+ best.base = base;
+ best.ebone = ebone;
}
}
}
}
-
- if (!(besthitresult & BONESEL_NOSEL)) {
-
- ebone = BLI_findlink(arm->edbo, besthitresult & ~BONESEL_ANY);
-
+
+ if (!(best.hitresult & BONESEL_NOSEL)) {
+ *r_base = best.base;
+
*r_selmask = 0;
- if (besthitresult & BONESEL_ROOT)
+ if (best.hitresult & BONESEL_ROOT) {
*r_selmask |= BONE_ROOTSEL;
- if (besthitresult & BONESEL_TIP)
+ }
+ if (best.hitresult & BONESEL_TIP) {
*r_selmask |= BONE_TIPSEL;
- if (besthitresult & BONESEL_BONE)
+ }
+ if (best.hitresult & BONESEL_BONE) {
*r_selmask |= BONE_SELECTED;
- return ebone;
+ }
+ MEM_freeN(bases);
+ return best.ebone;
}
}
*r_selmask = 0;
+ *r_base = NULL;
+ MEM_freeN(bases);
return NULL;
}
@@ -466,6 +587,23 @@ void ED_armature_edit_deselect_all_visible(Object *obedit)
ED_armature_edit_sync_selection(arm->edbo);
}
+
+void ED_armature_edit_deselect_all_multi(struct Object **objects, uint objects_len)
+{
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ ED_armature_edit_deselect_all(obedit);
+ }
+}
+
+void ED_armature_edit_deselect_all_visible_multi(struct Object **objects, uint objects_len)
+{
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ ED_armature_edit_deselect_all_visible(obedit);
+ }
+}
+
/* accounts for connected parents */
static int ebone_select_flag(EditBone *ebone)
{
@@ -480,25 +618,25 @@ static int ebone_select_flag(EditBone *ebone)
/* context: editmode armature in view3d */
bool ED_armature_edit_select_pick(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
{
- Object *obedit = CTX_data_edit_object(C);
ViewContext vc;
EditBone *nearBone = NULL;
int selmask;
+ Base *basact = NULL;
ED_view3d_viewcontext_init(C, &vc);
vc.mval[0] = mval[0];
vc.mval[1] = mval[1];
- if (BIF_sk_selectStroke(C, mval, extend)) {
- return true;
- }
-
- nearBone = get_nearest_editbonepoint(&vc, true, true, &selmask);
+ nearBone = get_nearest_editbonepoint(&vc, true, true, &basact, &selmask);
if (nearBone) {
- bArmature *arm = obedit->data;
+ ED_view3d_viewcontext_init_object(&vc, basact->object);
+ bArmature *arm = vc.obedit->data;
if (!extend && !deselect && !toggle) {
- ED_armature_edit_deselect_all(obedit);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc.view_layer, &objects_len);
+ ED_armature_edit_deselect_all_multi(objects, objects_len);
+ MEM_freeN(objects);
}
/* by definition the non-root connected bones have no root point drawn,
@@ -576,9 +714,14 @@ bool ED_armature_edit_select_pick(bContext *C, const int mval[2], bool extend, b
if (ebone_select_flag(nearBone)) {
arm->act_edbone = nearBone;
}
+
+ if (vc.view_layer->basact != basact) {
+ vc.view_layer->basact = basact;
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, vc.scene);
+ }
}
-
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, vc.obedit);
+
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, basact->object);
return true;
}
@@ -1291,17 +1434,23 @@ static int armature_shortest_path_pick_invoke(bContext *C, wmOperator *op, const
EditBone *ebone_isect_parent = NULL;
EditBone *ebone_isect_child[2];
bool changed;
+ Base *base_dst = NULL;
view3d_operator_needs_opengl(C);
ebone_src = arm->act_edbone;
- ebone_dst = get_nearest_bone(C, event->mval, false);
+ ebone_dst = get_nearest_bone(C, event->mval, false, &base_dst);
/* fallback to object selection */
if (ELEM(NULL, ebone_src, ebone_dst) || (ebone_src == ebone_dst)) {
return OPERATOR_PASS_THROUGH;
}
+ if (base_dst && base_dst->object != obedit) {
+ /* Disconnected, ignore. */
+ return OPERATOR_CANCELLED;
+ }
+
ebone_isect_child[0] = ebone_src;
ebone_isect_child[1] = ebone_dst;
diff --git a/source/blender/editors/armature/armature_skinning.c b/source/blender/editors/armature/armature_skinning.c
index 0458fc4ed1b..1722cbd5c5c 100644
--- a/source/blender/editors/armature/armature_skinning.c
+++ b/source/blender/editors/armature/armature_skinning.c
@@ -43,12 +43,15 @@
#include "BKE_action.h"
#include "BKE_armature.h"
+#include "BKE_context.h"
#include "BKE_deform.h"
#include "BKE_object_deform.h"
#include "BKE_report.h"
#include "BKE_subsurf.h"
#include "BKE_modifier.h"
+#include "DEG_depsgraph.h"
+
#include "ED_armature.h"
#include "ED_mesh.h"
@@ -57,13 +60,9 @@
#include "armature_intern.h"
#include "meshlaplacian.h"
-#if 0
-#include "reeb.h"
-#endif
-
/* ********************************** Bone Skinning *********************************************** */
-static int bone_skinnable_cb(Object *ob, Bone *bone, void *datap)
+static int bone_skinnable_cb(Object *UNUSED(ob), Bone *bone, void *datap)
{
/* Bones that are deforming
* are regarded to be "skinnable" and are eligible for
@@ -89,9 +88,9 @@ static int bone_skinnable_cb(Object *ob, Bone *bone, void *datap)
*/
Bone ***hbone;
int a, segments;
- struct { Object *armob; void *list; int heat; } *data = datap;
+ struct { Object *armob; void *list; int heat; bool is_weight_paint; } *data = datap;
- if (!(ob->mode & OB_MODE_WEIGHT_PAINT) || !(bone->flag & BONE_HIDDEN_P)) {
+ if (!(data->is_weight_paint) || !(bone->flag & BONE_HIDDEN_P)) {
if (!(bone->flag & BONE_NO_DEFORM)) {
if (data->heat && data->armob->pose && BKE_pose_channel_find_name(data->armob->pose, bone->name))
segments = bone->segments;
@@ -154,18 +153,17 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
*/
bDeformGroup ***hgroup, *defgroup = NULL;
int a, segments;
- struct { Object *armob; void *list; int heat; } *data = datap;
- int wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT);
+ struct { Object *armob; void *list; int heat; bool is_weight_paint; } *data = datap;
bArmature *arm = data->armob->data;
- if (!wpmode || !(bone->flag & BONE_HIDDEN_P)) {
+ if (!data->is_weight_paint || !(bone->flag & BONE_HIDDEN_P)) {
if (!(bone->flag & BONE_NO_DEFORM)) {
if (data->heat && data->armob->pose && BKE_pose_channel_find_name(data->armob->pose, bone->name))
segments = bone->segments;
else
segments = 1;
- if (!wpmode || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))) {
+ if (!data->is_weight_paint || ((arm->layer & bone->layer) && (bone->flag & BONE_SELECTED))) {
if (!(defgroup = defgroup_find_name(ob, bone->name))) {
defgroup = BKE_object_defgroup_add_name(ob, bone->name);
}
@@ -189,9 +187,10 @@ static int dgroup_skinnable_cb(Object *ob, Bone *bone, void *datap)
return 0;
}
-static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], int numbones, Bone **bonelist,
- bDeformGroup **dgrouplist, bDeformGroup **dgroupflip,
- float (*root)[3], float (*tip)[3], const int *selected, float scale)
+static void envelope_bone_weighting(
+ Object *ob, Mesh *mesh, float (*verts)[3], int numbones, Bone **bonelist,
+ bDeformGroup **dgrouplist, bDeformGroup **dgroupflip,
+ float (*root)[3], float (*tip)[3], const int *selected, float scale)
{
/* Create vertex group weights from envelopes */
@@ -247,8 +246,9 @@ static void envelope_bone_weighting(Object *ob, Mesh *mesh, float (*verts)[3], i
}
}
-static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob, Object *par,
- int heat, const bool mirror)
+static void add_verts_to_dgroups(
+ ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par,
+ int heat, const bool mirror)
{
/* This functions implements the automatic computation of vertex group
* weights, either through envelopes or using a heat equilibrium.
@@ -272,12 +272,13 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
float (*root)[3], (*tip)[3], (*verts)[3];
int *selected;
int numbones, vertsfilled = 0, i, j, segments = 0;
- int wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT);
- struct { Object *armob; void *list; int heat; } looper_data;
+ const bool wpmode = (ob->mode & OB_MODE_WEIGHT_PAINT);
+ struct { Object *armob; void *list; int heat; bool is_weight_paint; } looper_data;
looper_data.armob = par;
looper_data.heat = heat;
looper_data.list = NULL;
+ looper_data.is_weight_paint = wpmode;
/* count the number of skinnable bones */
numbones = bone_looper(ob, arm->bonebase.first, &looper_data, bone_skinnable_cb);
@@ -372,7 +373,7 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
if (wpmode) {
/* if in weight paint mode, use final verts from derivedmesh */
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+ DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
if (dm->foreachMappedVert) {
mesh_get_mapped_verts_coords(dm, verts, mesh->totvert);
@@ -400,15 +401,17 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
if (heat) {
const char *error = NULL;
- heat_bone_weighting(ob, mesh, verts, numbones, dgrouplist, dgroupflip,
- root, tip, selected, &error);
+ heat_bone_weighting(
+ ob, mesh, verts, numbones, dgrouplist, dgroupflip,
+ root, tip, selected, &error);
if (error) {
BKE_report(reports, RPT_WARNING, error);
}
}
else {
- envelope_bone_weighting(ob, mesh, verts, numbones, bonelist, dgrouplist,
- dgroupflip, root, tip, selected, mat4_to_scale(par->obmat));
+ envelope_bone_weighting(
+ ob, mesh, verts, numbones, bonelist, dgrouplist,
+ dgroupflip, root, tip, selected, mat4_to_scale(par->obmat));
}
/* only generated in some cases but can call anyway */
@@ -424,8 +427,9 @@ static void add_verts_to_dgroups(ReportList *reports, Scene *scene, Object *ob,
MEM_freeN(verts);
}
-void ED_object_vgroup_calc_from_armature(ReportList *reports, Scene *scene, Object *ob, Object *par,
- const int mode, const bool mirror)
+void ED_object_vgroup_calc_from_armature(
+ ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, Object *par,
+ const int mode, const bool mirror)
{
/* Lets try to create some vertex groups
* based on the bones of the parent armature.
@@ -451,6 +455,6 @@ void ED_object_vgroup_calc_from_armature(ReportList *reports, Scene *scene, Obje
* that are populated with the vertices for which the
* bone is closest.
*/
- add_verts_to_dgroups(reports, scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror);
+ add_verts_to_dgroups(reports, depsgraph, scene, ob, par, (mode == ARM_GROUPS_AUTO), mirror);
}
}
diff --git a/source/blender/editors/armature/armature_utils.c b/source/blender/editors/armature/armature_utils.c
index 8867189baef..ffa8b9f5007 100644
--- a/source/blender/editors/armature/armature_utils.c
+++ b/source/blender/editors/armature/armature_utils.c
@@ -39,11 +39,12 @@
#include "BKE_armature.h"
#include "BKE_context.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_main.h"
+#include "DEG_depsgraph.h"
+
#include "ED_armature.h"
#include "ED_util.h"
@@ -684,7 +685,7 @@ void ED_armature_from_edit(bArmature *arm)
}
}
- DAG_id_tag_update(&arm->id, 0);
+ DEG_id_tag_update(&arm->id, 0);
}
void ED_armature_edit_free(struct bArmature *arm)
@@ -715,8 +716,6 @@ void ED_armature_to_edit(bArmature *arm)
ED_armature_edit_free(arm);
arm->edbo = MEM_callocN(sizeof(ListBase), "edbo armature");
arm->act_edbone = make_boneList(arm->edbo, &arm->bonebase, NULL, arm->act_bone);
-
-// BIF_freeTemplates(); /* force template update when entering editmode */
}
/* *************************************************************** */
diff --git a/source/blender/editors/armature/editarmature_generate.c b/source/blender/editors/armature/editarmature_generate.c
deleted file mode 100644
index 57843265496..00000000000
--- a/source/blender/editors/armature/editarmature_generate.c
+++ /dev/null
@@ -1,305 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/armature/editarmature_generate.c
- * \ingroup edarmature
- */
-
-#include "DNA_scene_types.h"
-#include "DNA_armature_types.h"
-
-#include "BLI_math.h"
-#include "BLI_graph.h"
-
-#include "ED_armature.h"
-#include "BIF_generate.h"
-
-void setBoneRollFromNormal(EditBone *bone, const float no[3], float UNUSED(invmat[4][4]), float tmat[3][3])
-{
- if (no != NULL && !is_zero_v3(no)) {
- float normal[3];
-
- copy_v3_v3(normal, no);
- mul_m3_v3(tmat, normal);
-
- bone->roll = ED_armature_ebone_roll_to_vector(bone, normal, false);
- }
-}
-
-float calcArcCorrelation(BArcIterator *iter, int start, int end, float v0[3], float n[3])
-{
- int len = 2 + abs(end - start);
-
- if (len > 2) {
- float avg_t = 0.0f;
- float s_t = 0.0f;
- float s_xyz = 0.0f;
- int i;
-
- /* First pass, calculate average */
- for (i = start; i <= end; i++) {
- float v[3];
-
- IT_peek(iter, i);
- sub_v3_v3v3(v, iter->p, v0);
- avg_t += dot_v3v3(v, n);
- }
-
- avg_t /= dot_v3v3(n, n);
- avg_t += 1.0f; /* adding start (0) and end (1) values */
- avg_t /= len;
-
- /* Second pass, calculate s_xyz and s_t */
- for (i = start; i <= end; i++) {
- float v[3], d[3];
- float dt;
-
- IT_peek(iter, i);
- sub_v3_v3v3(v, iter->p, v0);
- project_v3_v3v3(d, v, n);
- sub_v3_v3(v, d);
-
- dt = len_v3(d) - avg_t;
-
- s_t += dt * dt;
- s_xyz += dot_v3v3(v, v);
- }
-
- /* adding start(0) and end(1) values to s_t */
- s_t += (avg_t * avg_t) + (1 - avg_t) * (1 - avg_t);
-
- return 1.0f - s_xyz / s_t;
- }
- else {
- return 1.0f;
- }
-}
-
-int nextFixedSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int start, int end, float UNUSED(head[3]), float p[3])
-{
- static float stroke_length = 0;
- static float current_length;
- static char n;
- float *v1, *v2;
- float length_threshold;
- int i;
-
- if (stroke_length == 0) {
- current_length = 0;
-
- IT_peek(iter, start);
- v1 = iter->p;
-
- for (i = start + 1; i <= end; i++) {
- IT_peek(iter, i);
- v2 = iter->p;
-
- stroke_length += len_v3v3(v1, v2);
-
- v1 = v2;
- }
-
- n = 0;
- current_length = 0;
- }
-
- n++;
-
- length_threshold = n * stroke_length / toolsettings->skgen_subdivision_number;
-
- IT_peek(iter, start);
- v1 = iter->p;
-
- /* < and not <= because we don't care about end, it is P_EXACT anyway */
- for (i = start + 1; i < end; i++) {
- IT_peek(iter, i);
- v2 = iter->p;
-
- current_length += len_v3v3(v1, v2);
-
- if (current_length >= length_threshold) {
- copy_v3_v3(p, v2);
- return i;
- }
-
- v1 = v2;
- }
-
- stroke_length = 0;
-
- return -1;
-}
-int nextAdaptativeSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int start, int end, float head[3], float p[3])
-{
- float correlation_threshold = toolsettings->skgen_correlation_limit;
- float *start_p;
- float n[3];
- int i;
-
- IT_peek(iter, start);
- start_p = iter->p;
-
- for (i = start + 2; i <= end; i++) {
- /* Calculate normal */
- IT_peek(iter, i);
- sub_v3_v3v3(n, iter->p, head);
-
- if (calcArcCorrelation(iter, start, i, start_p, n) < correlation_threshold) {
- IT_peek(iter, i - 1);
- copy_v3_v3(p, iter->p);
- return i - 1;
- }
- }
-
- return -1;
-}
-
-int nextLengthSubdivision(ToolSettings *toolsettings, BArcIterator *iter, int start, int end, float head[3], float p[3])
-{
- float lengthLimit = toolsettings->skgen_length_limit;
- int same = 1;
- int i;
-
- i = start + 1;
- while (i <= end) {
- float *vec0;
- float *vec1;
-
- IT_peek(iter, i - 1);
- vec0 = iter->p;
-
- IT_peek(iter, i);
- vec1 = iter->p;
-
- /* If lengthLimit hits the current segment */
- if (len_v3v3(vec1, head) > lengthLimit) {
- if (same == 0) {
- float dv[3], off[3];
- float a, b, c, f;
-
- /* Solve quadratic distance equation */
- sub_v3_v3v3(dv, vec1, vec0);
- a = dot_v3v3(dv, dv);
-
- sub_v3_v3v3(off, vec0, head);
- b = 2 * dot_v3v3(dv, off);
-
- c = dot_v3v3(off, off) - (lengthLimit * lengthLimit);
-
- f = (-b + sqrtf(b * b - 4 * a * c)) / (2 * a);
-
- //printf("a %f, b %f, c %f, f %f\n", a, b, c, f);
-
- if (isnan(f) == 0 && f < 1.0f) {
- copy_v3_v3(p, dv);
- mul_v3_fl(p, f);
- add_v3_v3(p, vec0);
- }
- else {
- copy_v3_v3(p, vec1);
- }
- }
- else {
- float dv[3];
-
- sub_v3_v3v3(dv, vec1, vec0);
- normalize_v3(dv);
-
- copy_v3_v3(p, dv);
- mul_v3_fl(p, lengthLimit);
- add_v3_v3(p, head);
- }
-
- return i - 1; /* restart at lower bound */
- }
- else {
- i++;
- same = 0; // Reset same
- }
- }
-
- return -1;
-}
-
-EditBone *subdivideArcBy(ToolSettings *toolsettings, bArmature *arm, ListBase *UNUSED(editbones), BArcIterator *iter,
- float invmat[4][4], float tmat[3][3], NextSubdivisionFunc next_subdividion)
-{
- EditBone *lastBone = NULL;
- EditBone *child = NULL;
- EditBone *parent = NULL;
- float *normal = NULL;
- float size_buffer = 1.2;
- int bone_start = 0;
- int end = iter->length;
- int index;
-
- IT_head(iter);
-
- parent = ED_armature_ebone_add(arm, "Bone");
- copy_v3_v3(parent->head, iter->p);
-
- if (iter->size > FLT_EPSILON) {
- parent->rad_head = iter->size * size_buffer;
- }
-
- normal = iter->no;
-
- index = next_subdividion(toolsettings, iter, bone_start, end, parent->head, parent->tail);
- while (index != -1) {
- IT_peek(iter, index);
-
- child = ED_armature_ebone_add(arm, "Bone");
- copy_v3_v3(child->head, parent->tail);
- child->parent = parent;
- child->flag |= BONE_CONNECTED;
-
- if (iter->size > FLT_EPSILON) {
- child->rad_head = iter->size * size_buffer;
- parent->rad_tail = iter->size * size_buffer;
- }
-
- /* going to next bone, fix parent */
- mul_m4_v3(invmat, parent->tail);
- mul_m4_v3(invmat, parent->head);
- setBoneRollFromNormal(parent, normal, invmat, tmat);
-
- parent = child; // new child is next parent
- bone_start = index; // start next bone from current index
-
- normal = iter->no; /* use normal at head, not tail */
-
- index = next_subdividion(toolsettings, iter, bone_start, end, parent->head, parent->tail);
- }
-
- iter->tail(iter);
-
- copy_v3_v3(parent->tail, iter->p);
- if (iter->size > FLT_EPSILON) {
- parent->rad_tail = iter->size * size_buffer;
- }
-
- /* fix last bone */
- mul_m4_v3(invmat, parent->tail);
- mul_m4_v3(invmat, parent->head);
- setBoneRollFromNormal(parent, iter->no, invmat, tmat);
- lastBone = parent;
-
- return lastBone;
-}
diff --git a/source/blender/editors/armature/editarmature_retarget.c b/source/blender/editors/armature/editarmature_retarget.c
deleted file mode 100644
index 6b2893780d7..00000000000
--- a/source/blender/editors/armature/editarmature_retarget.c
+++ /dev/null
@@ -1,2641 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Martin Poirier
- *
- * ***** END GPL LICENSE BLOCK *****
- * autoarmature.c: Interface for automagically manipulating armature (retarget, created, ...)
- */
-
-/** \file blender/editors/armature/editarmature_retarget.c
- * \ingroup edarmature
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "PIL_time.h"
-
-#include "DNA_armature_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-#include "BKE_constraint.h"
-#include "BKE_armature.h"
-#include "BKE_context.h"
-
-#include "ED_armature.h"
-#include "ED_undo.h"
-
-#include "BIF_retarget.h"
-
-#include "armature_intern.h"
-
-/************ RIG RETARGET DATA STRUCTURES ***************/
-
-typedef struct MemoNode {
- float weight;
- int next;
-} MemoNode;
-
-typedef struct RetargetParam {
- RigGraph *rigg;
- RigArc *iarc;
- RigNode *inode_start;
- bContext *context;
-} RetargetParam;
-
-typedef enum {
- RETARGET_LENGTH,
- RETARGET_AGGRESSIVE
-} RetargetMode;
-
-typedef enum {
- METHOD_BRUTE_FORCE = 0,
- METHOD_MEMOIZE = 1
-} RetargetMethod;
-
-typedef enum {
- ARC_FREE = 0,
- ARC_TAKEN = 1,
- ARC_USED = 2
-} ArcUsageFlags;
-
-static RigGraph *GLOBAL_RIGG = NULL;
-
-/*******************************************************************************************************/
-
-void exec_retargetArctoArc(TaskPool * __restrict pool, void *taskdata, int threadid);
-
-static void RIG_calculateEdgeAngles(RigEdge *edge_first, RigEdge *edge_second);
-float rollBoneByQuat(EditBone *bone, float old_up_axis[3], float qrot[4]);
-
-/* two levels */
-#define SHAPE_LEVELS (SHAPE_RADIX * SHAPE_RADIX)
-
-/*********************************** EDITBONE UTILS ****************************************************/
-
-static int countEditBoneChildren(ListBase *list, EditBone *parent)
-{
- EditBone *ebone;
- int count = 0;
-
- for (ebone = list->first; ebone; ebone = ebone->next) {
- if (ebone->parent == parent) {
- count++;
- }
- }
-
- return count;
-}
-
-static EditBone *nextEditBoneChild(ListBase *list, EditBone *parent, int n)
-{
- EditBone *ebone;
-
- for (ebone = list->first; ebone; ebone = ebone->next) {
- if (ebone->parent == parent) {
- if (n == 0) {
- return ebone;
- }
- n--;
- }
- }
-
- return NULL;
-}
-
-static void getEditBoneRollUpAxis(EditBone *bone, float roll, float up_axis[3])
-{
- float mat[3][3], nor[3];
-
- sub_v3_v3v3(nor, bone->tail, bone->head);
-
- vec_roll_to_mat3(nor, roll, mat);
- copy_v3_v3(up_axis, mat[2]);
-}
-
-static float rollBoneByQuatAligned(EditBone *bone, float old_up_axis[3], float qrot[4], float qroll[4], float aligned_axis[3])
-{
- float nor[3], new_up_axis[3], x_axis[3], z_axis[3];
-
- copy_v3_v3(new_up_axis, old_up_axis);
- mul_qt_v3(qrot, new_up_axis);
-
- sub_v3_v3v3(nor, bone->tail, bone->head);
-
- cross_v3_v3v3(x_axis, nor, aligned_axis);
- cross_v3_v3v3(z_axis, x_axis, nor);
-
- normalize_v3(new_up_axis);
- normalize_v3(x_axis);
- normalize_v3(z_axis);
-
- if (dot_v3v3(new_up_axis, x_axis) < 0) {
- negate_v3(x_axis);
- }
-
- if (dot_v3v3(new_up_axis, z_axis) < 0) {
- negate_v3(z_axis);
- }
-
- if (angle_normalized_v3v3(x_axis, new_up_axis) < angle_normalized_v3v3(z_axis, new_up_axis)) {
- rotation_between_vecs_to_quat(qroll, new_up_axis, x_axis); /* set roll rotation quat */
- return ED_armature_ebone_roll_to_vector(bone, x_axis, false);
- }
- else {
- rotation_between_vecs_to_quat(qroll, new_up_axis, z_axis); /* set roll rotation quat */
- return ED_armature_ebone_roll_to_vector(bone, z_axis, false);
- }
-}
-
-static float rollBoneByQuatJoint(RigEdge *edge, RigEdge *previous, float qrot[4], float qroll[4], float up_axis[3])
-{
- if (previous == NULL) {
- /* default to up_axis if no previous */
- return rollBoneByQuatAligned(edge->bone, edge->up_axis, qrot, qroll, up_axis);
- }
- else {
- float new_up_axis[3];
- float vec_first[3], vec_second[3], normal[3];
-
- if (previous->bone) {
- sub_v3_v3v3(vec_first, previous->bone->tail, previous->bone->head);
- }
- else if (previous->prev->bone) {
- sub_v3_v3v3(vec_first, edge->bone->head, previous->prev->bone->tail);
- }
- else {
- /* default to up_axis if first bone in the chain is an offset */
- return rollBoneByQuatAligned(edge->bone, edge->up_axis, qrot, qroll, up_axis);
- }
-
- sub_v3_v3v3(vec_second, edge->bone->tail, edge->bone->head);
-
- normalize_v3(vec_first);
- normalize_v3(vec_second);
-
- cross_v3_v3v3(normal, vec_first, vec_second);
- normalize_v3(normal);
-
- axis_angle_to_quat(qroll, vec_second, edge->up_angle);
-
- mul_qt_v3(qroll, normal);
-
- copy_v3_v3(new_up_axis, edge->up_axis);
- mul_qt_v3(qrot, new_up_axis);
-
- normalize_v3(new_up_axis);
-
- /* real qroll between normal and up_axis */
- rotation_between_vecs_to_quat(qroll, new_up_axis, normal);
-
- return ED_armature_ebone_roll_to_vector(edge->bone, normal, false);
- }
-}
-
-float rollBoneByQuat(EditBone *bone, float old_up_axis[3], float qrot[4])
-{
- float new_up_axis[3];
-
- copy_v3_v3(new_up_axis, old_up_axis);
- mul_qt_v3(qrot, new_up_axis);
-
- return ED_armature_ebone_roll_to_vector(bone, new_up_axis, false);
-}
-
-/************************************ DESTRUCTORS ******************************************************/
-
-static void RIG_freeRigArc(BArc *arc)
-{
- BLI_freelistN(&((RigArc *)arc)->edges);
-}
-
-void RIG_freeRigGraph(BGraph *rg)
-{
- RigGraph *rigg = (RigGraph *)rg;
- BNode *node;
- BArc *arc;
-
- BLI_task_pool_free(rigg->task_pool);
- BLI_task_scheduler_free(rigg->task_scheduler);
-
- if (rigg->link_mesh) {
- REEB_freeGraph(rigg->link_mesh);
- }
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- RIG_freeRigArc(arc);
- }
- BLI_freelistN(&rg->arcs);
-
- for (node = rg->nodes.first; node; node = node->next) {
- BLI_freeNode(rg, (BNode *)node);
- }
- BLI_freelistN(&rg->nodes);
-
- BLI_freelistN(&rigg->controls);
-
- BLI_ghash_free(rigg->bones_map, NULL, NULL);
- BLI_ghash_free(rigg->controls_map, NULL, NULL);
-
- if (rigg->flag & RIG_FREE_BONELIST) {
- BLI_freelistN(rigg->editbones);
- MEM_freeN(rigg->editbones);
- }
-
- MEM_freeN(rg);
-}
-
-/************************************* ALLOCATORS ******************************************************/
-
-static RigGraph *newRigGraph(void)
-{
- RigGraph *rg;
- int totthread;
-
- rg = MEM_callocN(sizeof(RigGraph), "rig graph");
-
- rg->head = NULL;
-
- rg->bones_map = BLI_ghash_str_new("newRigGraph bones gh");
- rg->controls_map = BLI_ghash_str_new("newRigGraph cont gh");
-
- rg->free_arc = RIG_freeRigArc;
- rg->free_node = NULL;
-
-#ifdef USE_THREADS
- totthread = TASK_SCHEDULER_AUTO_THREADS;
-#else
- totthread = TASK_SCHEDULER_SINGLE_THREAD;
-#endif
-
- rg->task_scheduler = BLI_task_scheduler_create(totthread);
- rg->task_pool = BLI_task_pool_create(rg->task_scheduler, NULL);
-
- return rg;
-}
-
-static RigArc *newRigArc(RigGraph *rg)
-{
- RigArc *arc;
-
- arc = MEM_callocN(sizeof(RigArc), "rig arc");
- arc->count = 0;
- BLI_addtail(&rg->arcs, arc);
-
- return arc;
-}
-
-static RigControl *newRigControl(RigGraph *rg)
-{
- RigControl *ctrl;
-
- ctrl = MEM_callocN(sizeof(RigControl), "rig control");
-
- BLI_addtail(&rg->controls, ctrl);
-
- return ctrl;
-}
-
-static RigNode *newRigNodeHead(RigGraph *rg, RigArc *arc, float p[3])
-{
- RigNode *node;
- node = MEM_callocN(sizeof(RigNode), "rig node");
- BLI_addtail(&rg->nodes, node);
-
- copy_v3_v3(node->p, p);
- node->degree = 1;
- node->arcs = NULL;
-
- arc->head = node;
-
- return node;
-}
-
-static void addRigNodeHead(RigGraph *UNUSED(rg), RigArc *arc, RigNode *node)
-{
- node->degree++;
-
- arc->head = node;
-}
-
-static RigNode *newRigNode(RigGraph *rg, float p[3])
-{
- RigNode *node;
- node = MEM_callocN(sizeof(RigNode), "rig node");
- BLI_addtail(&rg->nodes, node);
-
- copy_v3_v3(node->p, p);
- node->degree = 0;
- node->arcs = NULL;
-
- return node;
-}
-
-static RigNode *newRigNodeTail(RigGraph *rg, RigArc *arc, float p[3])
-{
- RigNode *node = newRigNode(rg, p);
-
- node->degree = 1;
- arc->tail = node;
-
- return node;
-}
-
-static void RIG_appendEdgeToArc(RigArc *arc, RigEdge *edge)
-{
- BLI_addtail(&arc->edges, edge);
-
- if (edge->prev == NULL) {
- copy_v3_v3(edge->head, arc->head->p);
- }
- else {
- RigEdge *last_edge = edge->prev;
- copy_v3_v3(edge->head, last_edge->tail);
- RIG_calculateEdgeAngles(last_edge, edge);
- }
-
- edge->length = len_v3v3(edge->head, edge->tail);
-
- arc->length += edge->length;
-
- arc->count += 1;
-}
-
-static void RIG_addEdgeToArc(RigArc *arc, float tail[3], EditBone *bone)
-{
- RigEdge *edge;
-
- edge = MEM_callocN(sizeof(RigEdge), "rig edge");
-
- copy_v3_v3(edge->tail, tail);
- edge->bone = bone;
-
- if (bone) {
- getEditBoneRollUpAxis(bone, bone->roll, edge->up_axis);
- }
-
- RIG_appendEdgeToArc(arc, edge);
-}
-/************************************** CLONING TEMPLATES **********************************************/
-
-static void renameTemplateBone(char *name, char *template_name, ListBase *editbones, char *side_string, char *num_string)
-{
- int i, j;
-
- for (i = 0, j = 0; i < (MAXBONENAME - 1) && j < (MAXBONENAME - 1) && template_name[i] != '\0'; i++) {
- if (template_name[i] == '&') {
- if (template_name[i + 1] == 'S' || template_name[i + 1] == 's') {
- j += BLI_strncpy_rlen(name + j, side_string, MAXBONENAME);
- i++;
- }
- else if (template_name[i + 1] == 'N' || template_name[i + 1] == 'n') {
- j += BLI_strncpy_rlen(name + j, num_string, MAXBONENAME);
- i++;
- }
- else {
- name[j] = template_name[i];
- j++;
- }
- }
- else {
- name[j] = template_name[i];
- j++;
- }
- }
-
- name[j] = '\0';
-
- ED_armature_ebone_unique_name(editbones, name, NULL);
-}
-
-static RigControl *cloneControl(RigGraph *rg, RigGraph *src_rg, RigControl *src_ctrl, GHash *ptr_hash, char *side_string, char *num_string)
-{
- RigControl *ctrl;
- char name[MAXBONENAME];
-
- ctrl = newRigControl(rg);
-
- copy_v3_v3(ctrl->head, src_ctrl->head);
- copy_v3_v3(ctrl->tail, src_ctrl->tail);
- copy_v3_v3(ctrl->up_axis, src_ctrl->up_axis);
- copy_v3_v3(ctrl->offset, src_ctrl->offset);
-
- ctrl->tail_mode = src_ctrl->tail_mode;
- ctrl->flag = src_ctrl->flag;
-
- renameTemplateBone(name, src_ctrl->bone->name, rg->editbones, side_string, num_string);
- ctrl->bone = duplicateEditBoneObjects(src_ctrl->bone, name, rg->editbones, src_rg->ob, rg->ob);
- ctrl->bone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
- BLI_ghash_insert(ptr_hash, src_ctrl->bone, ctrl->bone);
-
- ctrl->link = src_ctrl->link;
- ctrl->link_tail = src_ctrl->link_tail;
-
- return ctrl;
-}
-
-static RigArc *cloneArc(RigGraph *rg, RigGraph *src_rg, RigArc *src_arc, GHash *ptr_hash, char *side_string, char *num_string)
-{
- RigEdge *src_edge;
- RigArc *arc;
-
- arc = newRigArc(rg);
-
- arc->head = BLI_ghash_lookup(ptr_hash, src_arc->head);
- arc->tail = BLI_ghash_lookup(ptr_hash, src_arc->tail);
-
- arc->head->degree++;
- arc->tail->degree++;
-
- arc->length = src_arc->length;
-
- arc->count = src_arc->count;
-
- for (src_edge = src_arc->edges.first; src_edge; src_edge = src_edge->next) {
- RigEdge *edge;
-
- edge = MEM_callocN(sizeof(RigEdge), "rig edge");
-
- copy_v3_v3(edge->head, src_edge->head);
- copy_v3_v3(edge->tail, src_edge->tail);
- copy_v3_v3(edge->up_axis, src_edge->up_axis);
-
- edge->length = src_edge->length;
- edge->angle = src_edge->angle;
- edge->up_angle = src_edge->up_angle;
-
- if (src_edge->bone != NULL) {
- char name[MAXBONENAME];
- renameTemplateBone(name, src_edge->bone->name, rg->editbones, side_string, num_string);
- edge->bone = duplicateEditBoneObjects(src_edge->bone, name, rg->editbones, src_rg->ob, rg->ob);
- edge->bone->flag &= ~(BONE_TIPSEL | BONE_SELECTED | BONE_ROOTSEL);
- BLI_ghash_insert(ptr_hash, src_edge->bone, edge->bone);
- }
-
- BLI_addtail(&arc->edges, edge);
- }
-
- return arc;
-}
-
-static RigGraph *cloneRigGraph(RigGraph *src, ListBase *editbones, Object *ob, char *side_string, char *num_string)
-{
- GHash *ptr_hash;
- RigNode *node;
- RigArc *arc;
- RigControl *ctrl;
- RigGraph *rg;
-
- ptr_hash = BLI_ghash_ptr_new("cloneRigGraph gh");
-
- rg = newRigGraph();
-
- rg->ob = ob;
- rg->editbones = editbones;
-
- preEditBoneDuplicate(rg->editbones); /* prime bones for duplication */
- preEditBoneDuplicate(src->editbones); /* prime bones for duplication */
-
- /* Clone nodes */
- for (node = src->nodes.first; node; node = node->next) {
- RigNode *cloned_node = newRigNode(rg, node->p);
- BLI_ghash_insert(ptr_hash, node, cloned_node);
- }
-
- rg->head = BLI_ghash_lookup(ptr_hash, src->head);
-
- /* Clone arcs */
- for (arc = src->arcs.first; arc; arc = arc->next) {
- cloneArc(rg, src, arc, ptr_hash, side_string, num_string);
- }
-
- /* Clone controls */
- for (ctrl = src->controls.first; ctrl; ctrl = ctrl->next) {
- cloneControl(rg, src, ctrl, ptr_hash, side_string, num_string);
- }
-
- /* Relink bones properly */
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- RigEdge *edge;
-
- for (edge = arc->edges.first; edge; edge = edge->next) {
- if (edge->bone != NULL) {
- EditBone *bone;
-
- updateDuplicateSubtargetObjects(edge->bone, src->editbones, src->ob, rg->ob);
-
- if (edge->bone->parent) {
- bone = BLI_ghash_lookup(ptr_hash, edge->bone->parent);
-
- if (bone != NULL) {
- edge->bone->parent = bone;
- }
- else {
- /* disconnect since parent isn't cloned
- * this will only happen when cloning from selected bones
- * */
- edge->bone->flag &= ~BONE_CONNECTED;
- }
- }
- }
- }
- }
-
- for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) {
- EditBone *bone;
-
- updateDuplicateSubtargetObjects(ctrl->bone, src->editbones, src->ob, rg->ob);
-
- if (ctrl->bone->parent) {
- bone = BLI_ghash_lookup(ptr_hash, ctrl->bone->parent);
-
- if (bone != NULL) {
- ctrl->bone->parent = bone;
- }
- else {
- /* disconnect since parent isn't cloned
- * this will only happen when cloning from selected bones
- * */
- ctrl->bone->flag &= ~BONE_CONNECTED;
- }
- }
-
- ctrl->link = BLI_ghash_lookup(ptr_hash, ctrl->link);
- ctrl->link_tail = BLI_ghash_lookup(ptr_hash, ctrl->link_tail);
- }
-
- BLI_ghash_free(ptr_hash, NULL, NULL);
-
- return rg;
-}
-
-
-/*******************************************************************************************************/
-
-static void RIG_calculateEdgeAngles(RigEdge *edge_first, RigEdge *edge_second)
-{
- float vec_first[3], vec_second[3];
-
- sub_v3_v3v3(vec_first, edge_first->tail, edge_first->head);
- sub_v3_v3v3(vec_second, edge_second->tail, edge_second->head);
-
- normalize_v3(vec_first);
- normalize_v3(vec_second);
-
- edge_first->angle = angle_normalized_v3v3(vec_first, vec_second);
-
- if (edge_second->bone != NULL) {
- float normal[3];
-
- cross_v3_v3v3(normal, vec_first, vec_second);
- normalize_v3(normal);
-
- edge_second->up_angle = angle_normalized_v3v3(normal, edge_second->up_axis);
- }
-}
-
-/************************************ CONTROL BONES ****************************************************/
-
-static void RIG_addControlBone(RigGraph *rg, EditBone *bone)
-{
- RigControl *ctrl = newRigControl(rg);
- ctrl->bone = bone;
- copy_v3_v3(ctrl->head, bone->head);
- copy_v3_v3(ctrl->tail, bone->tail);
- getEditBoneRollUpAxis(bone, bone->roll, ctrl->up_axis);
- ctrl->tail_mode = TL_NONE;
-
- BLI_ghash_insert(rg->controls_map, bone->name, ctrl);
-}
-
-static int RIG_parentControl(RigControl *ctrl, EditBone *link)
-{
- if (link) {
- float offset[3];
- int flag = 0;
-
- sub_v3_v3v3(offset, ctrl->bone->head, link->head);
-
- /* if root matches, check for direction too */
- if (dot_v3v3(offset, offset) < 0.0001f) {
- float vbone[3], vparent[3];
-
- flag |= RIG_CTRL_FIT_ROOT;
-
- sub_v3_v3v3(vbone, ctrl->bone->tail, ctrl->bone->head);
- sub_v3_v3v3(vparent, link->tail, link->head);
-
- /* test for opposite direction */
- if (dot_v3v3(vbone, vparent) > 0) {
- float nor[3];
- float len;
-
- cross_v3_v3v3(nor, vbone, vparent);
-
- len = dot_v3v3(nor, nor);
- if (len < 0.0001f) {
- flag |= RIG_CTRL_FIT_BONE;
- }
- }
- }
-
- /* Bail out if old one is automatically better */
- if (flag < ctrl->flag) {
- return 0;
- }
-
- /* if there's already a link
- * overwrite only if new link is higher in the chain */
- if (ctrl->link && flag == ctrl->flag) {
- EditBone *bone = NULL;
-
- for (bone = ctrl->link; bone; bone = bone->parent) {
- /* if link is in the chain, break and use that one */
- if (bone == link) {
- break;
- }
- }
-
- /* not in chain, don't update link */
- if (bone == NULL) {
- return 0;
- }
- }
-
-
- ctrl->link = link;
- ctrl->flag = flag;
-
- copy_v3_v3(ctrl->offset, offset);
-
- return 1;
- }
-
- return 0;
-}
-
-static void RIG_reconnectControlBones(RigGraph *rg)
-{
- RigControl *ctrl;
- bool changed = true;
-
- /* first pass, link to deform bones */
- for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) {
- bPoseChannel *pchan;
- bConstraint *con;
- int found = 0;
-
- /* DO SOME MAGIC HERE */
- for (pchan = rg->ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- for (con = pchan->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
- bConstraintTarget *ct;
-
- /* constraint targets */
- if (cti && cti->get_constraint_targets) {
- int target_index;
-
- cti->get_constraint_targets(con, &targets);
-
- for (target_index = 0, ct = targets.first; ct; target_index++, ct = ct->next) {
- if ((ct->tar == rg->ob) && STREQ(ct->subtarget, ctrl->bone->name)) {
- /* SET bone link to bone corresponding to pchan */
- EditBone *link = BLI_ghash_lookup(rg->bones_map, pchan->name);
-
- /* Making sure bone is in this armature */
- if (link != NULL) {
- /* for pole targets, link to parent bone instead, if possible */
- if (con->type == CONSTRAINT_TYPE_KINEMATIC && target_index == 1) {
- if (link->parent && BLI_ghash_haskey(rg->bones_map, link->parent->name)) {
- link = link->parent;
- }
- }
-
- found = RIG_parentControl(ctrl, link);
- }
- }
- }
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 0);
- }
- }
- }
-
- /* if not found yet, check parent */
- if (found == 0) {
- if (ctrl->bone->parent) {
- /* make sure parent is a deforming bone
- * NULL if not
- * */
- EditBone *link = BLI_ghash_lookup(rg->bones_map, ctrl->bone->parent->name);
-
- found = RIG_parentControl(ctrl, link);
- }
-
- /* check if bone is not superposed on another one */
- {
- RigArc *arc;
- RigArc *best_arc = NULL;
- EditBone *link = NULL;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- RigEdge *edge;
- for (edge = arc->edges.first; edge; edge = edge->next) {
- if (edge->bone) {
- int fit = 0;
-
- fit = len_v3v3(ctrl->bone->head, edge->bone->head) < 0.0001f;
- fit = fit || len_v3v3(ctrl->bone->tail, edge->bone->tail) < 0.0001f;
-
- if (fit) {
- /* pick the bone on the arc with the lowest symmetry level
- * means you connect control to the trunk of the skeleton */
- if (best_arc == NULL || arc->symmetry_level < best_arc->symmetry_level) {
- best_arc = arc;
- link = edge->bone;
- }
- }
- }
- }
- }
-
- found = RIG_parentControl(ctrl, link);
- }
- }
-
- /* if not found yet, check child */
- if (found == 0) {
- RigArc *arc;
- RigArc *best_arc = NULL;
- EditBone *link = NULL;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- RigEdge *edge;
- for (edge = arc->edges.first; edge; edge = edge->next) {
- if (edge->bone && edge->bone->parent == ctrl->bone) {
- /* pick the bone on the arc with the lowest symmetry level
- * means you connect control to the trunk of the skeleton */
- if (best_arc == NULL || arc->symmetry_level < best_arc->symmetry_level) {
- best_arc = arc;
- link = edge->bone;
- }
- }
- }
- }
-
- found = RIG_parentControl(ctrl, link);
- }
-
- }
-
-
- /* second pass, make chains in control bones */
- while (changed) {
- changed = false;
-
- for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) {
- /* if control is not linked yet */
- if (ctrl->link == NULL) {
- bPoseChannel *pchan;
- bConstraint *con;
- RigControl *ctrl_parent = NULL;
- RigControl *ctrl_child;
- int found = 0;
-
- if (ctrl->bone->parent) {
- ctrl_parent = BLI_ghash_lookup(rg->controls_map, ctrl->bone->parent->name);
- }
-
- /* check constraints first */
-
- /* DO SOME MAGIC HERE */
- for (pchan = rg->ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- for (con = pchan->constraints.first; con; con = con->next) {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
- ListBase targets = {NULL, NULL};
- bConstraintTarget *ct;
-
- /* constraint targets */
- if (cti && cti->get_constraint_targets) {
- cti->get_constraint_targets(con, &targets);
-
- for (ct = targets.first; ct; ct = ct->next) {
- if ((ct->tar == rg->ob) && STREQ(ct->subtarget, ctrl->bone->name)) {
- /* SET bone link to ctrl corresponding to pchan */
- RigControl *link = BLI_ghash_lookup(rg->controls_map, pchan->name);
-
- /* if owner is a control bone, link with it */
- if (link && link->link) {
- RIG_parentControl(ctrl, link->bone);
- found = 1;
- break;
- }
- }
- }
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(con, &targets, 0);
- }
- }
- }
-
- if (found == 0) {
- /* check if parent is already linked */
- if (ctrl_parent && ctrl_parent->link) {
- RIG_parentControl(ctrl, ctrl_parent->bone);
- changed = true;
- }
- else {
- /* check childs */
- for (ctrl_child = rg->controls.first; ctrl_child; ctrl_child = ctrl_child->next) {
- /* if a child is linked, link to that one */
- if (ctrl_child->link && ctrl_child->bone->parent == ctrl->bone) {
- RIG_parentControl(ctrl, ctrl_child->bone);
- changed = true;
- break;
- }
- }
- }
- }
- }
- }
- }
-
- /* third pass, link control tails */
- for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) {
- /* fit bone already means full match, so skip those */
- if ((ctrl->flag & RIG_CTRL_FIT_BONE) == 0) {
- GHashIterator ghi;
-
- /* look on deform bones first */
- BLI_ghashIterator_init(&ghi, rg->bones_map);
-
- for (; !BLI_ghashIterator_done(&ghi); BLI_ghashIterator_step(&ghi)) {
- EditBone *bone = (EditBone *)BLI_ghashIterator_getValue(&ghi);
-
- /* don't link with parent */
- if (bone->parent != ctrl->bone) {
- if (len_v3v3(ctrl->bone->tail, bone->head) < 0.01f) {
- ctrl->tail_mode = TL_HEAD;
- ctrl->link_tail = bone;
- break;
- }
- else if (len_v3v3(ctrl->bone->tail, bone->tail) < 0.01f) {
- ctrl->tail_mode = TL_TAIL;
- ctrl->link_tail = bone;
- break;
- }
- }
- }
-
- /* if we haven't found one yet, look in control bones */
- if (ctrl->tail_mode == TL_NONE) {
- /* pass */
- }
- }
- }
-
-}
-
-/*******************************************************************************************************/
-
-static void RIG_joinArcs(RigGraph *rg, RigNode *node, RigArc *joined_arc1, RigArc *joined_arc2)
-{
- RigEdge *edge, *next_edge;
-
- /* ignore cases where joint is at start or end */
- if (joined_arc1->head == joined_arc2->head || joined_arc1->tail == joined_arc2->tail) {
- return;
- }
-
- /* swap arcs to make sure arc1 is before arc2 */
- if (joined_arc1->head == joined_arc2->tail) {
- RigArc *tmp = joined_arc1;
- joined_arc1 = joined_arc2;
- joined_arc2 = tmp;
- }
-
- for (edge = joined_arc2->edges.first; edge; edge = next_edge) {
- next_edge = edge->next;
-
- RIG_appendEdgeToArc(joined_arc1, edge);
- }
-
- joined_arc1->tail = joined_arc2->tail;
-
- BLI_listbase_clear(&joined_arc2->edges);
-
- BLI_removeArc((BGraph *)rg, (BArc *)joined_arc2);
-
- BLI_removeNode((BGraph *)rg, (BNode *)node);
-}
-
-static void RIG_removeNormalNodes(RigGraph *rg)
-{
- RigNode *node, *next_node;
-
- for (node = rg->nodes.first; node; node = next_node) {
- next_node = node->next;
-
- if (node->degree == 2) {
- RigArc *arc, *joined_arc1 = NULL, *joined_arc2 = NULL;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- if (arc->head == node || arc->tail == node) {
- if (joined_arc1 == NULL) {
- joined_arc1 = arc;
- }
- else {
- joined_arc2 = arc;
- break;
- }
- }
- }
-
- RIG_joinArcs(rg, node, joined_arc1, joined_arc2);
- }
- }
-}
-
-static void RIG_removeUneededOffsets(RigGraph *rg)
-{
- RigArc *arc;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- RigEdge *first_edge, *last_edge;
-
- first_edge = arc->edges.first;
- last_edge = arc->edges.last;
-
- if (first_edge->bone == NULL) {
- if (first_edge->bone == NULL && len_v3v3(first_edge->tail, arc->head->p) <= 0.001f) {
- BLI_remlink(&arc->edges, first_edge);
- MEM_freeN(first_edge);
- }
- else if (arc->head->degree == 1) {
- RigNode *new_node = (RigNode *)BLI_FindNodeByPosition((BGraph *)rg, first_edge->tail, 0.001f);
-
- if (new_node) {
- BLI_remlink(&arc->edges, first_edge);
- MEM_freeN(first_edge);
- BLI_replaceNodeInArc((BGraph *)rg, (BArc *)arc, (BNode *)new_node, (BNode *)arc->head);
- }
- else {
- RigEdge *next_edge = first_edge->next;
-
- if (next_edge) {
- BLI_remlink(&arc->edges, first_edge);
- MEM_freeN(first_edge);
-
- copy_v3_v3(arc->head->p, next_edge->head);
- }
- }
- }
- else {
- /* check if all arc connected start with a null edge */
- RigArc *other_arc;
- for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) {
- if (other_arc != arc) {
- RigEdge *test_edge;
- if (other_arc->head == arc->head) {
- test_edge = other_arc->edges.first;
-
- if (test_edge->bone != NULL) {
- break;
- }
- }
- else if (other_arc->tail == arc->head) {
- test_edge = other_arc->edges.last;
-
- if (test_edge->bone != NULL) {
- break;
- }
- }
- }
- }
-
- if (other_arc == NULL) {
- RigNode *new_node = (RigNode *)BLI_FindNodeByPosition((BGraph *)rg, first_edge->tail, 0.001);
-
- if (new_node) {
- /* remove null edge in other arcs too */
- for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) {
- if (other_arc != arc) {
- RigEdge *test_edge;
- if (other_arc->head == arc->head) {
- BLI_replaceNodeInArc((BGraph *)rg, (BArc *)other_arc, (BNode *)new_node, (BNode *)other_arc->head);
- test_edge = other_arc->edges.first;
- BLI_remlink(&other_arc->edges, test_edge);
- MEM_freeN(test_edge);
- }
- else if (other_arc->tail == arc->head) {
- BLI_replaceNodeInArc((BGraph *)rg, (BArc *)other_arc, (BNode *)new_node, (BNode *)other_arc->tail);
- test_edge = other_arc->edges.last;
- BLI_remlink(&other_arc->edges, test_edge);
- MEM_freeN(test_edge);
- }
- }
- }
-
- BLI_remlink(&arc->edges, first_edge);
- MEM_freeN(first_edge);
- BLI_replaceNodeInArc((BGraph *)rg, (BArc *)arc, (BNode *)new_node, (BNode *)arc->head);
- }
- else {
- RigEdge *next_edge = first_edge->next;
-
- if (next_edge) {
- BLI_remlink(&arc->edges, first_edge);
- MEM_freeN(first_edge);
-
- copy_v3_v3(arc->head->p, next_edge->head);
-
- /* remove null edge in other arcs too */
- for (other_arc = rg->arcs.first; other_arc; other_arc = other_arc->next) {
- if (other_arc != arc) {
- RigEdge *test_edge;
- if (other_arc->head == arc->head) {
- test_edge = other_arc->edges.first;
- BLI_remlink(&other_arc->edges, test_edge);
- MEM_freeN(test_edge);
- }
- else if (other_arc->tail == arc->head) {
- test_edge = other_arc->edges.last;
- BLI_remlink(&other_arc->edges, test_edge);
- MEM_freeN(test_edge);
- }
- }
- }
- }
- }
- }
- }
- }
-
- if (last_edge->bone == NULL) {
- if (len_v3v3(last_edge->head, arc->tail->p) <= 0.001f) {
- BLI_remlink(&arc->edges, last_edge);
- MEM_freeN(last_edge);
- }
- else if (arc->tail->degree == 1) {
- RigNode *new_node = (RigNode *)BLI_FindNodeByPosition((BGraph *)rg, last_edge->head, 0.001f);
-
- if (new_node) {
- RigEdge *previous_edge = last_edge->prev;
-
- BLI_remlink(&arc->edges, last_edge);
- MEM_freeN(last_edge);
- BLI_replaceNodeInArc((BGraph *)rg, (BArc *)arc, (BNode *)new_node, (BNode *)arc->tail);
-
- /* set previous angle to 0, since there's no following edges */
- if (previous_edge) {
- previous_edge->angle = 0;
- }
- }
- else {
- RigEdge *previous_edge = last_edge->prev;
-
- if (previous_edge) {
- BLI_remlink(&arc->edges, last_edge);
- MEM_freeN(last_edge);
-
- copy_v3_v3(arc->tail->p, previous_edge->tail);
- previous_edge->angle = 0;
- }
- }
- }
- }
- }
-}
-
-static void RIG_arcFromBoneChain(RigGraph *rg, ListBase *list, EditBone *root_bone, RigNode *starting_node, bool selected)
-{
- EditBone *bone, *last_bone = root_bone;
- RigArc *arc = NULL;
- int contain_head = 0;
-
- for (bone = root_bone; bone; bone = nextEditBoneChild(list, bone, 0)) {
- int nb_children;
-
- if (selected == 0 || (bone->flag & BONE_SELECTED)) {
- if ((bone->flag & BONE_NO_DEFORM) == 0) {
- BLI_ghash_insert(rg->bones_map, bone->name, bone);
-
- if (arc == NULL) {
- arc = newRigArc(rg);
-
- if (starting_node == NULL) {
- starting_node = newRigNodeHead(rg, arc, root_bone->head);
- }
- else {
- addRigNodeHead(rg, arc, starting_node);
- }
- }
-
- if (bone->parent && (bone->flag & BONE_CONNECTED) == 0) {
- RIG_addEdgeToArc(arc, bone->head, NULL);
- }
-
- RIG_addEdgeToArc(arc, bone->tail, bone);
-
- last_bone = bone;
-
- if (STREQ(bone->name, "head")) {
- contain_head = 1;
- }
- }
- else if ((bone->flag & BONE_EDITMODE_LOCKED) == 0) { /* ignore locked bones */
- RIG_addControlBone(rg, bone);
- }
- }
-
- nb_children = countEditBoneChildren(list, bone);
- if (nb_children > 1) {
- RigNode *end_node = NULL;
- int i;
-
- if (arc != NULL) {
- end_node = newRigNodeTail(rg, arc, bone->tail);
- }
- else {
- end_node = newRigNode(rg, bone->tail);
- }
-
- for (i = 0; i < nb_children; i++) {
- root_bone = nextEditBoneChild(list, bone, i);
- RIG_arcFromBoneChain(rg, list, root_bone, end_node, selected);
- }
-
- /* arc ends here, break */
- break;
- }
- }
-
- /* If the loop exited without forking */
- if (arc != NULL && bone == NULL) {
- newRigNodeTail(rg, arc, last_bone->tail);
- }
-
- if (contain_head) {
- rg->head = arc->tail;
- }
-}
-
-/*******************************************************************************************************/
-static void RIG_findHead(RigGraph *rg)
-{
- if (rg->head == NULL) {
- if (BLI_listbase_is_single(&rg->arcs)) {
- RigArc *arc = rg->arcs.first;
-
- rg->head = (RigNode *)arc->head;
- }
- else {
- RigArc *arc;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- RigEdge *edge = arc->edges.last;
-
- if (edge->bone->flag & (BONE_TIPSEL | BONE_SELECTED)) {
- rg->head = arc->tail;
- break;
- }
- }
- }
-
- if (rg->head == NULL) {
- rg->head = rg->nodes.first;
- }
- }
-}
-
-/*******************************************************************************************************/
-
-static void RIG_printNode(RigNode *node, const char name[])
-{
- printf("%s %p %i <%0.3f, %0.3f, %0.3f>\n", name, (void *)node, node->degree, node->p[0], node->p[1], node->p[2]);
-
- if (node->symmetry_flag & SYM_TOPOLOGICAL) {
- if (node->symmetry_flag & SYM_AXIAL)
- printf("Symmetry AXIAL\n");
- else if (node->symmetry_flag & SYM_RADIAL)
- printf("Symmetry RADIAL\n");
-
- print_v3("symmetry axis", node->symmetry_axis);
- }
-}
-
-void RIG_printArcBones(RigArc *arc)
-{
- RigEdge *edge;
-
- for (edge = arc->edges.first; edge; edge = edge->next) {
- if (edge->bone)
- printf("%s ", edge->bone->name);
- else
- printf("---- ");
- }
- printf("\n");
-}
-
-static void RIG_printCtrl(RigControl *ctrl, char *indent)
-{
- char text[128];
-
- printf("%sBone: %s\n", indent, ctrl->bone->name);
- printf("%sLink: %s\n", indent, ctrl->link ? ctrl->link->name : "!NONE!");
-
- BLI_snprintf(text, sizeof(text), "%soffset", indent);
- print_v3(text, ctrl->offset);
-
- printf("%sFlag: %i\n", indent, ctrl->flag);
-}
-
-static void RIG_printLinkedCtrl(RigGraph *rg, EditBone *bone, int tabs)
-{
- RigControl *ctrl;
- char indent[64];
- char *s = indent;
- int i;
-
- for (i = 0; i < tabs; i++) {
- s[0] = '\t';
- s++;
- }
- s[0] = 0;
-
- for (ctrl = rg->controls.first; ctrl; ctrl = ctrl->next) {
- if (ctrl->link == bone) {
- RIG_printCtrl(ctrl, indent);
- RIG_printLinkedCtrl(rg, ctrl->bone, tabs + 1);
- }
- }
-}
-
-void RIG_printArc(RigGraph *rg, RigArc *arc)
-{
- RigEdge *edge;
-
- RIG_printNode((RigNode *)arc->head, "head");
-
- for (edge = arc->edges.first; edge; edge = edge->next) {
- printf("\tinner joints %0.3f %0.3f %0.3f\n", edge->tail[0], edge->tail[1], edge->tail[2]);
- printf("\t\tlength %f\n", edge->length);
- printf("\t\tangle %f\n", edge->angle * (float)(180 / M_PI));
- if (edge->bone) {
- printf("\t\t%s\n", edge->bone->name);
- RIG_printLinkedCtrl(rg, edge->bone, 3);
- }
- }
- printf("symmetry level: %i flag: %i group %i\n", arc->symmetry_level, arc->symmetry_flag, arc->symmetry_group);
-
- RIG_printNode((RigNode *)arc->tail, "tail");
-}
-
-void RIG_printGraph(RigGraph *rg)
-{
- RigArc *arc;
-
- printf("---- ARCS ----\n");
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- RIG_printArc(rg, arc);
- printf("\n");
- }
-
- if (rg->head) {
- RIG_printNode(rg->head, "HEAD NODE:");
- }
- else {
- printf("HEAD NODE: NONE\n");
- }
-}
-
-/*******************************************************************************************************/
-
-RigGraph *RIG_graphFromArmature(const bContext *C, Object *ob, bArmature *arm)
-{
- Object *obedit = CTX_data_edit_object(C);
- Scene *scene = CTX_data_scene(C);
- EditBone *ebone;
- RigGraph *rg;
-
- rg = newRigGraph();
-
- if (obedit == ob) {
- rg->editbones = ((bArmature *)obedit->data)->edbo;
- }
- else {
- rg->editbones = MEM_callocN(sizeof(ListBase), "EditBones");
- make_boneList(rg->editbones, &arm->bonebase, NULL, NULL);
- rg->flag |= RIG_FREE_BONELIST;
- }
-
- rg->ob = ob;
-
- /* Do the rotations */
- for (ebone = rg->editbones->first; ebone; ebone = ebone->next) {
- if (ebone->parent == NULL) {
- RIG_arcFromBoneChain(rg, rg->editbones, ebone, NULL, 0);
- }
- }
-
- BLI_removeDoubleNodes((BGraph *)rg, 0.001);
-
- RIG_removeNormalNodes(rg);
-
- RIG_removeUneededOffsets(rg);
-
- BLI_buildAdjacencyList((BGraph *)rg);
-
- RIG_findHead(rg);
-
- BLI_markdownSymmetry((BGraph *)rg, (BNode *)rg->head, scene->toolsettings->skgen_symmetry_limit);
-
- RIG_reconnectControlBones(rg); /* after symmetry, because we use levels to find best match */
-
- if (BLI_isGraphCyclic((BGraph *)rg)) {
- printf("armature cyclic\n");
- }
-
- return rg;
-}
-
-static RigGraph *armatureSelectedToGraph(bContext *C, Object *ob, bArmature *arm)
-{
- Object *obedit = CTX_data_edit_object(C);
- Scene *scene = CTX_data_scene(C);
- EditBone *ebone;
- RigGraph *rg;
-
- rg = newRigGraph();
-
- if (obedit == ob) {
- rg->editbones = arm->edbo;
- }
- else {
- rg->editbones = MEM_callocN(sizeof(ListBase), "EditBones");
- make_boneList(rg->editbones, &arm->bonebase, NULL, NULL);
- rg->flag |= RIG_FREE_BONELIST;
- }
-
- rg->ob = ob;
-
- /* Do the rotations */
- for (ebone = rg->editbones->first; ebone; ebone = ebone->next) {
- if (ebone->parent == NULL) {
- RIG_arcFromBoneChain(rg, rg->editbones, ebone, NULL, 1);
- }
- }
-
- BLI_removeDoubleNodes((BGraph *)rg, 0.001);
-
- RIG_removeNormalNodes(rg);
-
- RIG_removeUneededOffsets(rg);
-
- BLI_buildAdjacencyList((BGraph *)rg);
-
- RIG_findHead(rg);
-
- BLI_markdownSymmetry((BGraph *)rg, (BNode *)rg->head, scene->toolsettings->skgen_symmetry_limit);
-
- RIG_reconnectControlBones(rg); /* after symmetry, because we use levels to find best match */
-
- if (BLI_isGraphCyclic((BGraph *)rg)) {
- printf("armature cyclic\n");
- }
-
- return rg;
-}
-/************************************ GENERATING *****************************************************/
-
-#if 0
-static EditBone *add_editbonetolist(char *name, ListBase *list)
-{
- EditBone *bone = MEM_callocN(sizeof(EditBone), "eBone");
-
- BLI_strncpy(bone->name, name, sizeof(bone->name));
- ED_armature_ebone_unique_name(list, bone->name, NULL);
-
- BLI_addtail(list, bone);
-
- bone->flag |= BONE_TIPSEL;
- bone->weight = 1.0F;
- bone->dist = 0.25F;
- bone->xwidth = 0.1;
- bone->zwidth = 0.1;
- bone->rad_head = 0.10;
- bone->rad_tail = 0.05;
- bone->segments = 1;
- bone->layer = 1; //arm->layer;
-
- /* Bendy-Bone parameters */
- bone->roll1 = 0.0f;
- bone->roll2 = 0.0f;
- bone->curveInX = 0.0f;
- bone->curveInY = 0.0f;
- bone->curveOutX = 0.0f;
- bone->curveOutY = 0.0f;
- bone->ease1 = 1.0f;
- bone->ease2 = 1.0f;
- bone->scaleIn = 1.0f;
- bone->scaleOut = 1.0f;
-
- return bone;
-}
-#endif
-
-#if 0 /* UNUSED */
-static void generateMissingArcsFromNode(RigGraph *rigg, ReebNode *node, int multi_level_limit)
-{
- while (node->multi_level > multi_level_limit && node->link_up)
- {
- node = node->link_up;
- }
-
- while (node->multi_level < multi_level_limit && node->link_down)
- {
- node = node->link_down;
- }
-
- if (node->multi_level == multi_level_limit)
- {
- int i;
-
- for (i = 0; i < node->degree; i++)
- {
- ReebArc *earc = node->arcs[i];
-
- if (earc->flag == ARC_FREE && earc->head == node)
- {
- ReebNode *other = BIF_otherNodeFromIndex(earc, node);
-
- earc->flag = ARC_USED;
-
- //generateBonesForArc(rigg, earc, node, other);
- generateMissingArcsFromNode(rigg, other, multi_level_limit);
- }
- }
- }
-}
-
-static void generateMissingArcs(RigGraph *rigg)
-{
- ReebGraph *reebg;
- int multi_level_limit = 5;
-
- for (reebg = rigg->link_mesh; reebg; reebg = reebg->link_up)
- {
- ReebArc *earc;
-
- for (earc = reebg->arcs.first; earc; earc = earc->next)
- {
- if (earc->flag == ARC_USED)
- {
- generateMissingArcsFromNode(rigg, earc->head, multi_level_limit);
- generateMissingArcsFromNode(rigg, earc->tail, multi_level_limit);
- }
- }
- }
-}
-#endif
-
-/************************************ RETARGETTING *****************************************************/
-
-static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], float tail[3], float qrot[4], float resize);
-
-static void repositionTailControl(RigGraph *rigg, RigControl *ctrl);
-
-static void finalizeControl(RigGraph *rigg, RigControl *ctrl, float resize)
-{
- if ((ctrl->flag & RIG_CTRL_DONE) == RIG_CTRL_DONE) {
- RigControl *ctrl_child;
-
-#if 0
- printf("CTRL: %s LINK: %s", ctrl->bone->name, ctrl->link->name);
-
- if (ctrl->link_tail)
- {
- printf(" TAIL: %s", ctrl->link_tail->name);
- }
-
- printf("\n");
-#endif
-
- /* if there was a tail link: apply link, recalc resize factor and qrot */
- if (ctrl->tail_mode != TL_NONE) {
- float *tail_vec = NULL;
- float v1[3], v2[3], qtail[4];
-
- if (ctrl->tail_mode == TL_TAIL) {
- tail_vec = ctrl->link_tail->tail;
- }
- else if (ctrl->tail_mode == TL_HEAD) {
- tail_vec = ctrl->link_tail->head;
- }
-
- sub_v3_v3v3(v1, ctrl->bone->tail, ctrl->bone->head);
- sub_v3_v3v3(v2, tail_vec, ctrl->bone->head);
-
- copy_v3_v3(ctrl->bone->tail, tail_vec);
-
- rotation_between_vecs_to_quat(qtail, v1, v2);
- mul_qt_qtqt(ctrl->qrot, qtail, ctrl->qrot);
-
- resize = len_v3(v2) / len_v3v3(ctrl->head, ctrl->tail);
- }
-
- ctrl->bone->roll = rollBoneByQuat(ctrl->bone, ctrl->up_axis, ctrl->qrot);
-
- /* Cascade to connected control bones */
- for (ctrl_child = rigg->controls.first; ctrl_child; ctrl_child = ctrl_child->next) {
- if (ctrl_child->link == ctrl->bone) {
- repositionControl(rigg, ctrl_child, ctrl->bone->head, ctrl->bone->tail, ctrl->qrot, resize);
- }
- if (ctrl_child->link_tail == ctrl->bone) {
- repositionTailControl(rigg, ctrl_child);
- }
- }
- }
-}
-
-static void repositionTailControl(RigGraph *rigg, RigControl *ctrl)
-{
- ctrl->flag |= RIG_CTRL_TAIL_DONE;
-
- finalizeControl(rigg, ctrl, 1); /* resize will be recalculated anyway so we don't need it */
-}
-
-static void repositionControl(RigGraph *rigg, RigControl *ctrl, float head[3], float UNUSED(tail[3]), float qrot[4], float resize)
-{
- float parent_offset[3], tail_offset[3];
-
- copy_v3_v3(parent_offset, ctrl->offset);
- mul_v3_fl(parent_offset, resize);
- mul_qt_v3(qrot, parent_offset);
-
- add_v3_v3v3(ctrl->bone->head, head, parent_offset);
-
- ctrl->flag |= RIG_CTRL_HEAD_DONE;
-
- copy_qt_qt(ctrl->qrot, qrot);
-
- if (ctrl->tail_mode == TL_NONE) {
- sub_v3_v3v3(tail_offset, ctrl->tail, ctrl->head);
- mul_v3_fl(tail_offset, resize);
- mul_qt_v3(qrot, tail_offset);
-
- add_v3_v3v3(ctrl->bone->tail, ctrl->bone->head, tail_offset);
-
- ctrl->flag |= RIG_CTRL_TAIL_DONE;
- }
-
- finalizeControl(rigg, ctrl, resize);
-}
-
-static void repositionBone(bContext *C, RigGraph *rigg, RigEdge *edge, float vec0[3], float vec1[3], float up_axis[3])
-{
- Scene *scene = CTX_data_scene(C);
- EditBone *bone;
- RigControl *ctrl;
- float qrot[4], resize;
- float v1[3], v2[3];
- float l1, l2;
-
- bone = edge->bone;
-
- sub_v3_v3v3(v1, edge->tail, edge->head);
- sub_v3_v3v3(v2, vec1, vec0);
-
- l1 = normalize_v3(v1);
- l2 = normalize_v3(v2);
-
- resize = l2 / l1;
-
- rotation_between_vecs_to_quat(qrot, v1, v2);
-
- copy_v3_v3(bone->head, vec0);
- copy_v3_v3(bone->tail, vec1);
-
- if (!is_zero_v3(up_axis)) {
- float qroll[4];
-
- if (scene->toolsettings->skgen_retarget_roll == SK_RETARGET_ROLL_VIEW) {
- bone->roll = rollBoneByQuatAligned(bone, edge->up_axis, qrot, qroll, up_axis);
- }
- else if (scene->toolsettings->skgen_retarget_roll == SK_RETARGET_ROLL_JOINT) {
- bone->roll = rollBoneByQuatJoint(edge, edge->prev, qrot, qroll, up_axis);
- }
- else {
- unit_qt(qroll);
- }
-
- mul_qt_qtqt(qrot, qroll, qrot);
- }
- else {
- bone->roll = rollBoneByQuat(bone, edge->up_axis, qrot);
- }
-
- for (ctrl = rigg->controls.first; ctrl; ctrl = ctrl->next) {
- if (ctrl->link == bone) {
- repositionControl(rigg, ctrl, vec0, vec1, qrot, resize);
- }
- if (ctrl->link_tail == bone) {
- repositionTailControl(rigg, ctrl);
- }
- }
-}
-
-static RetargetMode detectArcRetargetMode(RigArc *arc);
-static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, RigNode *inode_start);
-
-
-static RetargetMode detectArcRetargetMode(RigArc *iarc)
-{
- RetargetMode mode = RETARGET_AGGRESSIVE;
- ReebArc *earc = iarc->link_mesh;
- RigEdge *edge;
- int large_angle = 0;
- float avg_angle = 0;
- /* float avg_length = 0; */ /* UNUSED */
- int nb_edges = 0;
-
-
- for (edge = iarc->edges.first; edge; edge = edge->next) {
- avg_angle += edge->angle;
- nb_edges++;
- }
-
- avg_angle /= nb_edges - 1; /* -1 because last edge doesn't have an angle */
-
- /* avg_length = iarc->length / nb_edges; */ /* UNUSED */
-
-
- if (nb_edges > 2) {
- for (edge = iarc->edges.first; edge; edge = edge->next) {
- if (fabsf(edge->angle - avg_angle) > (float)(M_PI / 6)) {
- large_angle = 1;
- }
- }
- }
- else if (nb_edges == 2 && avg_angle > 0) {
- large_angle = 1;
- }
-
-
- if (large_angle == 0) {
- mode = RETARGET_LENGTH;
- }
-
- if (earc->bcount <= (iarc->count - 1)) {
- mode = RETARGET_LENGTH;
- }
-
- return mode;
-}
-
-#ifndef USE_THREADS
-static void printMovesNeeded(int *positions, int nb_positions)
-{
- int moves = 0;
- int i;
-
- for (i = 0; i < nb_positions; i++) {
- moves += positions[i] - (i + 1);
- }
-
- printf("%i moves needed\n", moves);
-}
-
-static void printPositions(int *positions, int nb_positions)
-{
- int i;
-
- for (i = 0; i < nb_positions; i++) {
- printf("%i ", positions[i]);
- }
- printf("\n");
-}
-#endif
-
-#define MAX_COST FLT_MAX /* FIX ME */
-
-static float costDistance(BArcIterator *iter, float *vec0, float *vec1, int i0, int i1, float distance_weight)
-{
- EmbedBucket *bucket = NULL;
- float max_dist = 0;
- float v1[3], v2[3], c[3];
- float v1_inpf;
-
- if (distance_weight > 0) {
- sub_v3_v3v3(v1, vec0, vec1);
-
- v1_inpf = dot_v3v3(v1, v1);
-
- if (v1_inpf > 0) {
- int j;
- for (j = i0 + 1; j < i1 - 1; j++) {
- float dist;
-
- bucket = IT_peek(iter, j);
-
- sub_v3_v3v3(v2, bucket->p, vec1);
-
- cross_v3_v3v3(c, v1, v2);
-
- dist = dot_v3v3(c, c) / v1_inpf;
-
- max_dist = dist > max_dist ? dist : max_dist;
- }
-
- return distance_weight * max_dist;
- }
- else {
- return MAX_COST;
- }
- }
- else {
- return 0;
- }
-}
-
-static float costAngle(float original_angle, float vec_first[3], float vec_second[3], float angle_weight)
-{
- if (angle_weight > 0) {
- float current_angle;
-
- if (!is_zero_v3(vec_first) && !is_zero_v3(vec_second)) {
- current_angle = saacos(dot_v3v3(vec_first, vec_second));
-
- return angle_weight * fabsf(current_angle - original_angle);
- }
- else {
- return angle_weight * (float)M_PI;
- }
- }
- else {
- return 0;
- }
-}
-
-static float costLength(float original_length, float current_length, float length_weight)
-{
- if (current_length == 0) {
- return MAX_COST;
- }
- else {
- float length_ratio = fabsf((current_length - original_length) / original_length);
- return length_weight * length_ratio * length_ratio;
- }
-}
-
-#if 0
-static float calcCostLengthDistance(BArcIterator *iter, float **vec_cache, RigEdge *edge, float *vec1, float *vec2, int i1, int i2)
-{
- float vec[3];
- float length;
-
- sub_v3_v3v3(vec, vec2, vec1);
- length = normalize_v3(vec);
-
- return costLength(edge->length, length) + costDistance(iter, vec1, vec2, i1, i2);
-}
-#endif
-
-static float calcCostAngleLengthDistance(BArcIterator *iter, float **UNUSED(vec_cache), RigEdge *edge,
- float *vec0, float *vec1, float *vec2, int i1, int i2,
- float angle_weight, float length_weight, float distance_weight)
-{
- float vec_second[3], vec_first[3];
- float length2;
- float new_cost = 0;
-
- sub_v3_v3v3(vec_second, vec2, vec1);
- length2 = normalize_v3(vec_second);
-
-
- /* Angle cost */
- if (edge->prev) {
- sub_v3_v3v3(vec_first, vec1, vec0);
- normalize_v3(vec_first);
-
- new_cost += costAngle(edge->prev->angle, vec_first, vec_second, angle_weight);
- }
-
- /* Length cost */
- new_cost += costLength(edge->length, length2, length_weight);
-
- /* Distance cost */
- new_cost += costDistance(iter, vec1, vec2, i1, i2, distance_weight);
-
- return new_cost;
-}
-
-static int indexMemoNode(int nb_positions, int previous, int current, int joints_left)
-{
- return joints_left * nb_positions * nb_positions + current * nb_positions + previous;
-}
-
-static void copyMemoPositions(int *positions, MemoNode *table, int nb_positions, int joints_left)
-{
- int previous = 0, current = 0;
- int i = 0;
-
- for (i = 0; joints_left > 0; joints_left--, i++) {
- MemoNode *node;
- node = table + indexMemoNode(nb_positions, previous, current, joints_left);
-
- positions[i] = node->next;
-
- previous = current;
- current = node->next;
- }
-}
-
-static MemoNode *solveJoints(MemoNode *table, BArcIterator *iter, float **vec_cache,
- int nb_joints, int nb_positions, int previous, int current, RigEdge *edge,
- int joints_left, float angle_weight, float length_weight, float distance_weight)
-{
- MemoNode *node;
- int index = indexMemoNode(nb_positions, previous, current, joints_left);
-
- node = table + index;
-
- if (node->weight != 0) {
- return node;
- }
- else if (joints_left == 0) {
- float *vec0 = vec_cache[previous];
- float *vec1 = vec_cache[current];
- float *vec2 = vec_cache[nb_positions + 1];
-
- node->weight = calcCostAngleLengthDistance(iter, vec_cache, edge, vec0, vec1, vec2, current, iter->length, angle_weight, length_weight, distance_weight);
-
- return node;
- }
- else {
- MemoNode *min_node = NULL;
- float *vec0 = vec_cache[previous];
- float *vec1 = vec_cache[current];
- float min_weight = 0.0f;
- int min_next = 0;
- int next;
-
- for (next = current + 1; next <= nb_positions - (joints_left - 1); next++) {
- MemoNode *next_node;
- float *vec2 = vec_cache[next];
- float weight = 0.0f;
-
- /* ADD WEIGHT OF PREVIOUS - CURRENT - NEXT triple */
- weight = calcCostAngleLengthDistance(iter, vec_cache, edge, vec0, vec1, vec2, current, next, angle_weight, length_weight, distance_weight);
-
- if (weight >= MAX_COST) {
- continue;
- }
-
- /* add node weight */
- next_node = solveJoints(table, iter, vec_cache, nb_joints, nb_positions, current, next, edge->next, joints_left - 1, angle_weight, length_weight, distance_weight);
- weight += next_node->weight;
-
- if (min_node == NULL || weight < min_weight) {
- min_weight = weight;
- min_node = next_node;
- min_next = next;
- }
- }
-
- if (min_node) {
- node->weight = min_weight;
- node->next = min_next;
- return node;
- }
- else {
- node->weight = MAX_COST;
- return node;
- }
- }
-
-}
-
-static int testFlipArc(RigArc *iarc, RigNode *inode_start)
-{
- ReebArc *earc = iarc->link_mesh;
- ReebNode *enode_start = BIF_NodeFromIndex(earc, inode_start->link_mesh);
-
- /* no flip needed if both nodes are the same */
- if ((enode_start == earc->head && inode_start == iarc->head) ||
- (enode_start == earc->tail && inode_start == iarc->tail))
- {
- return 0;
- }
- else {
- return 1;
- }
-}
-
-static void retargetArctoArcAggresive(bContext *C, RigGraph *rigg, RigArc *iarc, RigNode *inode_start)
-{
- ReebArcIterator arc_iter;
- BArcIterator *iter = (BArcIterator *)&arc_iter;
- RigEdge *edge;
- ReebNode *node_start, *node_end;
- ReebArc *earc = iarc->link_mesh;
- float angle_weight = 1.0; // GET FROM CONTEXT
- float length_weight = 1.0;
- float distance_weight = 1.0;
-#ifndef USE_THREADS
- float min_cost = FLT_MAX;
-#endif
- float *vec0, *vec1;
- int *best_positions;
- int nb_edges = BLI_listbase_count(&iarc->edges);
- int nb_joints = nb_edges - 1;
- RetargetMethod method = METHOD_MEMOIZE;
- int i;
-
- if (nb_joints > earc->bcount) {
- printf("NOT ENOUGH BUCKETS!\n");
- return;
- }
-
- best_positions = MEM_callocN(sizeof(int) * nb_joints, "Best positions");
-
- if (testFlipArc(iarc, inode_start)) {
- node_start = earc->tail;
- node_end = earc->head;
- }
- else {
- node_start = earc->head;
- node_end = earc->tail;
- }
-
- /* equal number of joints and potential position, just fill them in */
- if (nb_joints == earc->bcount) {
- /* init with first values */
- for (i = 0; i < nb_joints; i++) {
- best_positions[i] = i + 1;
- }
- }
- if (method == METHOD_MEMOIZE) {
- int nb_positions = earc->bcount;
- int nb_memo_nodes = nb_positions * nb_positions * (nb_joints + 1);
- MemoNode *table = MEM_callocN(nb_memo_nodes * sizeof(MemoNode), "memoization table");
-#ifndef USE_THREADS
- MemoNode *result;
-#endif
- float **positions_cache = MEM_callocN(sizeof(float *) * (nb_positions + 2), "positions cache");
-
- positions_cache[0] = node_start->p;
- positions_cache[nb_positions + 1] = node_end->p;
-
- initArcIterator(iter, earc, node_start);
-
- for (i = 1; i <= nb_positions; i++) {
- EmbedBucket *bucket = IT_peek(iter, i);
- positions_cache[i] = bucket->p;
- }
-
-#ifndef USE_THREADS
- result = solveJoints(table, iter, positions_cache, nb_joints, earc->bcount, 0, 0, iarc->edges.first, nb_joints, angle_weight, length_weight, distance_weight);
- min_cost = result->weight;
-#else
- solveJoints(table, iter, positions_cache, nb_joints, earc->bcount, 0, 0, iarc->edges.first, nb_joints, angle_weight, length_weight, distance_weight);
-#endif
-
- copyMemoPositions(best_positions, table, earc->bcount, nb_joints);
-
- MEM_freeN(table);
- MEM_freeN(positions_cache);
- }
-
- vec0 = node_start->p;
- initArcIterator(iter, earc, node_start);
-
-#ifndef USE_THREADS
- printPositions(best_positions, nb_joints);
- printMovesNeeded(best_positions, nb_joints);
- printf("min_cost %f\n", min_cost);
- printf("buckets: %i\n", earc->bcount);
-#endif
-
- /* set joints to best position */
- for (edge = iarc->edges.first, i = 0;
- edge;
- edge = edge->next, i++)
- {
- float *no = NULL;
- if (i < nb_joints) {
- EmbedBucket *bucket = IT_peek(iter, best_positions[i]);
- vec1 = bucket->p;
- no = bucket->no;
- }
- else {
- vec1 = node_end->p;
- no = node_end->no;
- }
-
- if (edge->bone) {
- repositionBone(C, rigg, edge, vec0, vec1, no);
- }
-
- vec0 = vec1;
- }
-
- MEM_freeN(best_positions);
-}
-
-static void retargetArctoArcLength(bContext *C, RigGraph *rigg, RigArc *iarc, RigNode *inode_start)
-{
- ReebArcIterator arc_iter;
- BArcIterator *iter = (BArcIterator *)&arc_iter;
- ReebArc *earc = iarc->link_mesh;
- ReebNode *node_start, *node_end;
- RigEdge *edge;
- EmbedBucket *bucket = NULL;
- float embedding_length = 0;
- float *vec0 = NULL;
- float *vec1 = NULL;
- float *previous_vec = NULL;
-
-
- if (testFlipArc(iarc, inode_start)) {
- node_start = (ReebNode *)earc->tail;
- node_end = (ReebNode *)earc->head;
- }
- else {
- node_start = (ReebNode *)earc->head;
- node_end = (ReebNode *)earc->tail;
- }
-
- initArcIterator(iter, earc, node_start);
-
- bucket = IT_next(iter);
-
- vec0 = node_start->p;
-
- while (bucket != NULL) {
- vec1 = bucket->p;
-
- embedding_length += len_v3v3(vec0, vec1);
-
- vec0 = vec1;
- bucket = IT_next(iter);
- }
-
- embedding_length += len_v3v3(node_end->p, vec1);
-
- /* fit bones */
- initArcIterator(iter, earc, node_start);
-
- bucket = IT_next(iter);
-
- vec0 = node_start->p;
- previous_vec = vec0;
- vec1 = bucket->p;
-
- for (edge = iarc->edges.first; edge; edge = edge->next) {
- float new_bone_length = edge->length / iarc->length * embedding_length;
- float *no = NULL;
- float length = 0;
-
- while (bucket && new_bone_length > length) {
- length += len_v3v3(previous_vec, vec1);
- bucket = IT_next(iter);
- previous_vec = vec1;
- vec1 = bucket->p;
- no = bucket->no;
- }
-
- if (bucket == NULL) {
- vec1 = node_end->p;
- no = node_end->no;
- }
-
- /* no need to move virtual edges (space between unconnected bones) */
- if (edge->bone) {
- repositionBone(C, rigg, edge, vec0, vec1, no);
- }
-
- vec0 = vec1;
- previous_vec = vec1;
- }
-}
-
-static void retargetArctoArc(bContext *C, RigGraph *rigg, RigArc *iarc, RigNode *inode_start)
-{
- RetargetParam *p = MEM_callocN(sizeof(RetargetParam), "RetargetParam");
-
- p->rigg = rigg;
- p->iarc = iarc;
- p->inode_start = inode_start;
- p->context = C;
-
- BLI_task_pool_push(rigg->task_pool, exec_retargetArctoArc, p, true, TASK_PRIORITY_HIGH);
-}
-
-void exec_retargetArctoArc(TaskPool * __restrict UNUSED(pool), void *taskdata, int UNUSED(threadid))
-{
- RetargetParam *p = (RetargetParam *)taskdata;
- RigGraph *rigg = p->rigg;
- RigArc *iarc = p->iarc;
- bContext *C = p->context;
- RigNode *inode_start = p->inode_start;
- ReebArc *earc = iarc->link_mesh;
-
- if (BLI_listbase_is_single(&iarc->edges)) {
- RigEdge *edge = iarc->edges.first;
-
- if (testFlipArc(iarc, inode_start)) {
- repositionBone(C, rigg, edge, earc->tail->p, earc->head->p, earc->head->no);
- }
- else {
- repositionBone(C, rigg, edge, earc->head->p, earc->tail->p, earc->tail->no);
- }
- }
- else {
- RetargetMode mode = detectArcRetargetMode(iarc);
-
- if (mode == RETARGET_AGGRESSIVE) {
- retargetArctoArcAggresive(C, rigg, iarc, inode_start);
- }
- else {
- retargetArctoArcLength(C, rigg, iarc, inode_start);
- }
- }
-}
-
-static void matchMultiResolutionNode(RigGraph *rigg, RigNode *inode, ReebNode *top_node)
-{
- ReebNode *enode = top_node;
- ReebGraph *reebg = BIF_graphForMultiNode(rigg->link_mesh, enode);
- int ishape, eshape;
-
- ishape = BLI_subtreeShape((BGraph *)rigg, (BNode *)inode, NULL, 0) % SHAPE_LEVELS;
- eshape = BLI_subtreeShape((BGraph *)reebg, (BNode *)enode, NULL, 0) % SHAPE_LEVELS;
-
- inode->link_mesh = enode;
-
- while (ishape == eshape && enode->link_down) {
- inode->link_mesh = enode;
-
- enode = enode->link_down;
- reebg = BIF_graphForMultiNode(rigg->link_mesh, enode); /* replace with call to link_down once that exists */
- eshape = BLI_subtreeShape((BGraph *)reebg, (BNode *)enode, NULL, 0) % SHAPE_LEVELS;
- }
-}
-
-static void markMultiResolutionChildArc(ReebNode *end_enode, ReebNode *enode)
-{
- int i;
-
- for (i = 0; i < enode->degree; i++) {
- ReebArc *earc = (ReebArc *)enode->arcs[i];
-
- if (earc->flag == ARC_FREE) {
- earc->flag = ARC_TAKEN;
-
- if (earc->tail->degree > 1 && earc->tail != end_enode) {
- markMultiResolutionChildArc(end_enode, earc->tail);
- }
- break;
- }
- }
-}
-
-static void markMultiResolutionArc(ReebArc *start_earc)
-{
- if (start_earc->link_up) {
- ReebArc *earc;
- for (earc = start_earc->link_up; earc; earc = earc->link_up) {
- earc->flag = ARC_TAKEN;
-
- if (earc->tail->index != start_earc->tail->index) {
- markMultiResolutionChildArc(earc->tail, earc->tail);
- }
- }
- }
-}
-
-static void matchMultiResolutionArc(RigGraph *rigg, RigNode *start_node, RigArc *next_iarc, ReebArc *next_earc)
-{
- ReebNode *enode = next_earc->head;
- ReebGraph *reebg = BIF_graphForMultiNode(rigg->link_mesh, enode);
- int ishape, eshape;
-
- ishape = BLI_subtreeShape((BGraph *)rigg, (BNode *)start_node, (BArc *)next_iarc, 1) % SHAPE_LEVELS;
- eshape = BLI_subtreeShape((BGraph *)reebg, (BNode *)enode, (BArc *)next_earc, 1) % SHAPE_LEVELS;
-
- while (ishape != eshape && next_earc->link_up) {
- next_earc->flag = ARC_TAKEN; // mark previous as taken, to prevent backtrack on lower levels
-
- next_earc = next_earc->link_up;
- reebg = reebg->link_up;
- enode = next_earc->head;
- eshape = BLI_subtreeShape((BGraph *)reebg, (BNode *)enode, (BArc *)next_earc, 1) % SHAPE_LEVELS;
- }
-
- next_earc->flag = ARC_USED;
- next_iarc->link_mesh = next_earc;
-
- /* mark all higher levels as taken too */
- markMultiResolutionArc(next_earc);
-// while (next_earc->link_up)
-// {
-// next_earc = next_earc->link_up;
-// next_earc->flag = ARC_TAKEN;
-// }
-}
-
-static void matchMultiResolutionStartingNode(RigGraph *rigg, ReebGraph *reebg, RigNode *inode)
-{
- ReebNode *enode;
- int ishape, eshape;
-
- enode = reebg->nodes.first;
-
- ishape = BLI_subtreeShape((BGraph *)rigg, (BNode *)inode, NULL, 0) % SHAPE_LEVELS;
- eshape = BLI_subtreeShape((BGraph *)rigg->link_mesh, (BNode *)enode, NULL, 0) % SHAPE_LEVELS;
-
- while (ishape != eshape && reebg->link_up) {
- reebg = reebg->link_up;
-
- enode = reebg->nodes.first;
-
- eshape = BLI_subtreeShape((BGraph *)reebg, (BNode *)enode, NULL, 0) % SHAPE_LEVELS;
- }
-
- inode->link_mesh = enode;
-}
-
-static void findCorrespondingArc(RigGraph *rigg, RigArc *start_arc, RigNode *start_node, RigArc *next_iarc, int root)
-{
- ReebNode *enode = start_node->link_mesh;
- ReebArc *next_earc;
- int symmetry_level = next_iarc->symmetry_level;
- int symmetry_group = next_iarc->symmetry_group;
- int symmetry_flag = next_iarc->symmetry_flag;
- int i;
-
- next_iarc->link_mesh = NULL;
-
-// if (root)
-// {
-// printf("-----------------------\n");
-// printf("MATCHING LIMB\n");
-// RIG_printArcBones(next_iarc);
-// }
-
- for (i = 0; i < enode->degree; i++) {
- next_earc = (ReebArc *)enode->arcs[i];
-
-// if (next_earc->flag == ARC_FREE)
-// {
-// printf("candidate (level %i ?= %i) (flag %i ?= %i) (group %i ?= %i)\n",
-// symmetry_level, next_earc->symmetry_level,
-// symmetry_flag, next_earc->symmetry_flag,
-// symmetry_group, next_earc->symmetry_flag);
-// }
-
- if (next_earc->flag == ARC_FREE &&
- next_earc->symmetry_flag == symmetry_flag &&
- next_earc->symmetry_group == symmetry_group &&
- next_earc->symmetry_level == symmetry_level)
- {
-// printf("CORRESPONDING ARC FOUND\n");
-// printf("flag %i -- level %i -- flag %i -- group %i\n", next_earc->flag, next_earc->symmetry_level, next_earc->symmetry_flag, next_earc->symmetry_group);
-
- matchMultiResolutionArc(rigg, start_node, next_iarc, next_earc);
- break;
- }
- }
-
- /* not found, try at higher nodes (lower node might have filtered internal arcs, messing shape of tree */
- if (next_iarc->link_mesh == NULL) {
-// printf("NO CORRESPONDING ARC FOUND - GOING TO HIGHER LEVELS\n");
-
- if (enode->link_up) {
- start_node->link_mesh = enode->link_up;
- findCorrespondingArc(rigg, start_arc, start_node, next_iarc, 0);
- }
- }
-
- /* still not found, print debug info */
- if (root && next_iarc->link_mesh == NULL) {
- start_node->link_mesh = enode; /* linking back with root node */
-
-// printf("NO CORRESPONDING ARC FOUND\n");
-// RIG_printArcBones(next_iarc);
-//
-// printf("ON NODE %i, multilevel %i\n", enode->index, enode->multi_level);
-//
-// printf("LOOKING FOR\n");
-// printf("flag %i -- level %i -- flag %i -- group %i\n", ARC_FREE, symmetry_level, symmetry_flag, symmetry_group);
-//
-// printf("CANDIDATES\n");
-// for (i = 0; i < enode->degree; i++)
-// {
-// next_earc = (ReebArc *)enode->arcs[i];
-// printf("flag %i -- level %i -- flag %i -- group %i\n", next_earc->flag, next_earc->symmetry_level, next_earc->symmetry_flag, next_earc->symmetry_group);
-// }
-
- /* Emergency matching */
- for (i = 0; i < enode->degree; i++) {
- next_earc = (ReebArc *)enode->arcs[i];
-
- if (next_earc->flag == ARC_FREE && next_earc->symmetry_level == symmetry_level) {
-// printf("USING:\n");
-// printf("flag %i -- level %i -- flag %i -- group %i\n", next_earc->flag, next_earc->symmetry_level, next_earc->symmetry_flag, next_earc->symmetry_group);
- matchMultiResolutionArc(rigg, start_node, next_iarc, next_earc);
- break;
- }
- }
- }
-
-}
-
-static void retargetSubgraph(bContext *C, RigGraph *rigg, RigArc *start_arc, RigNode *start_node)
-{
- RigNode *inode = start_node;
- int i;
-
- /* no start arc on first node */
- if (start_arc) {
- ReebNode *enode = start_node->link_mesh;
- ReebArc *earc = start_arc->link_mesh;
-
- retargetArctoArc(C, rigg, start_arc, start_node);
-
- enode = BIF_otherNodeFromIndex(earc, enode);
- inode = (RigNode *)BLI_otherNode((BArc *)start_arc, (BNode *)inode);
-
- /* match with lowest node with correct shape */
- matchMultiResolutionNode(rigg, inode, enode);
- }
-
- for (i = 0; i < inode->degree; i++) {
- RigArc *next_iarc = (RigArc *)inode->arcs[i];
-
- /* no back tracking */
- if (next_iarc != start_arc) {
- findCorrespondingArc(rigg, start_arc, inode, next_iarc, 1);
- if (next_iarc->link_mesh) {
- retargetSubgraph(C, rigg, next_iarc, inode);
- }
- }
- }
-}
-
-static void finishRetarget(RigGraph *rigg)
-{
- BLI_task_pool_work_and_wait(rigg->task_pool);
-}
-
-static void adjustGraphs(bContext *C, RigGraph *rigg)
-{
- bArmature *arm = rigg->ob->data;
- RigArc *arc;
-
- for (arc = rigg->arcs.first; arc; arc = arc->next) {
- if (arc->link_mesh) {
- retargetArctoArc(C, rigg, arc, arc->head);
- }
- }
-
- finishRetarget(rigg);
-
- /* Turn the list into an armature */
- arm->edbo = rigg->editbones;
- ED_armature_from_edit(arm);
-
- ED_undo_push(C, "Retarget Skeleton");
-}
-
-static void retargetGraphs(bContext *C, RigGraph *rigg)
-{
- bArmature *arm = rigg->ob->data;
- ReebGraph *reebg = rigg->link_mesh;
- RigNode *inode;
-
- /* flag all ReebArcs as free */
- BIF_flagMultiArcs(reebg, ARC_FREE);
-
- /* return to first level */
- inode = rigg->head;
-
- matchMultiResolutionStartingNode(rigg, reebg, inode);
-
- retargetSubgraph(C, rigg, NULL, inode);
-
- //generateMissingArcs(rigg);
-
- finishRetarget(rigg);
-
- /* Turn the list into an armature */
- arm->edbo = rigg->editbones;
- ED_armature_from_edit(arm);
-}
-
-const char *RIG_nameBone(RigGraph *rg, int arc_index, int bone_index)
-{
- RigArc *arc = BLI_findlink(&rg->arcs, arc_index);
- RigEdge *iedge;
-
- if (arc == NULL) {
- return "None";
- }
-
- if (bone_index == BLI_listbase_count(&arc->edges)) {
- return "Last joint";
- }
-
- iedge = BLI_findlink(&arc->edges, bone_index);
-
- if (iedge == NULL) {
- return "Done";
- }
-
- if (iedge->bone == NULL) {
- return "Bone offset";
- }
-
- return iedge->bone->name;
-}
-
-int RIG_nbJoints(RigGraph *rg)
-{
- RigArc *arc;
- int total = 0;
-
- total += BLI_listbase_count(&rg->nodes);
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- total += BLI_listbase_count(&arc->edges) - 1; /* -1 because end nodes are already counted */
- }
-
- return total;
-}
-
-static void BIF_freeRetarget(void)
-{
- if (GLOBAL_RIGG) {
- RIG_freeRigGraph((BGraph *)GLOBAL_RIGG);
- GLOBAL_RIGG = NULL;
- }
-}
-
-void BIF_retargetArmature(bContext *C)
-{
- ReebGraph *reebg;
- double start_time, end_time;
- double gstart_time, gend_time;
- double reeb_time, rig_time = 0.0, retarget_time = 0.0, total_time;
-
- gstart_time = start_time = PIL_check_seconds_timer();
-
- reebg = BIF_ReebGraphMultiFromEditMesh(C);
-
- end_time = PIL_check_seconds_timer();
- reeb_time = end_time - start_time;
-
- printf("Reeb Graph created\n");
-
- CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
- {
- Object *ob = base->object;
-
- if (ob->type == OB_ARMATURE) {
- RigGraph *rigg;
- bArmature *arm;
-
- arm = ob->data;
-
- /* Put the armature into editmode */
-
-
- start_time = PIL_check_seconds_timer();
-
- rigg = RIG_graphFromArmature(C, ob, arm);
-
- end_time = PIL_check_seconds_timer();
- rig_time = end_time - start_time;
-
- printf("Armature graph created\n");
-
- //RIG_printGraph(rigg);
-
- rigg->link_mesh = reebg;
-
- printf("retargetting %s\n", ob->id.name);
-
- start_time = PIL_check_seconds_timer();
-
- retargetGraphs(C, rigg);
-
- end_time = PIL_check_seconds_timer();
- retarget_time = end_time - start_time;
-
- BIF_freeRetarget();
-
- GLOBAL_RIGG = rigg;
-
- break; /* only one armature at a time */
- }
- }
- CTX_DATA_END;
-
-
- gend_time = PIL_check_seconds_timer();
-
- total_time = gend_time - gstart_time;
-
- printf("-----------\n");
- printf("runtime: \t%.3f\n", total_time);
- printf("reeb: \t\t%.3f (%.1f%%)\n", reeb_time, reeb_time / total_time * 100);
- printf("rig: \t\t%.3f (%.1f%%)\n", rig_time, rig_time / total_time * 100);
- printf("retarget: \t%.3f (%.1f%%)\n", retarget_time, retarget_time / total_time * 100);
- printf("-----------\n");
-
- ED_undo_push(C, "Retarget Skeleton");
-
- // XXX
-// allqueue(REDRAWVIEW3D, 0);
-}
-
-void BIF_retargetArc(bContext *C, ReebArc *earc, RigGraph *template_rigg)
-{
- Object *obedit = CTX_data_edit_object(C);
- Scene *scene = CTX_data_scene(C);
- bArmature *armedit = obedit->data;
- Object *ob;
- RigGraph *rigg;
- RigArc *iarc;
- char *side_string = scene->toolsettings->skgen_side_string;
- char *num_string = scene->toolsettings->skgen_num_string;
- int free_template = 0;
-
- if (template_rigg) {
- ob = template_rigg->ob;
- }
- else {
- free_template = 1;
- ob = obedit;
- template_rigg = armatureSelectedToGraph(C, ob, ob->data);
- }
-
- if (BLI_listbase_is_empty(&template_rigg->arcs)) {
-// XXX
-// error("No Template and no deforming bones selected");
- return;
- }
-
- rigg = cloneRigGraph(template_rigg, armedit->edbo, obedit, side_string, num_string);
-
- iarc = rigg->arcs.first;
-
- iarc->link_mesh = earc;
- iarc->head->link_mesh = earc->head;
- iarc->tail->link_mesh = earc->tail;
-
- retargetArctoArc(C, rigg, iarc, iarc->head);
-
- finishRetarget(rigg);
-
- /* free template if it comes from the edit armature */
- if (free_template) {
- RIG_freeRigGraph((BGraph *)template_rigg);
- }
- RIG_freeRigGraph((BGraph *)rigg);
-
- ED_armature_edit_validate_active(armedit);
-
-// XXX
-// allqueue(REDRAWVIEW3D, 0);
-}
-
-void BIF_adjustRetarget(bContext *C)
-{
- if (GLOBAL_RIGG) {
- adjustGraphs(C, GLOBAL_RIGG);
- }
-}
diff --git a/source/blender/editors/armature/editarmature_sketch.c b/source/blender/editors/armature/editarmature_sketch.c
deleted file mode 100644
index a08898a37f6..00000000000
--- a/source/blender/editors/armature/editarmature_sketch.c
+++ /dev/null
@@ -1,2664 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/armature/editarmature_sketch.c
- * \ingroup edarmature
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_armature_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-#include "BKE_context.h"
-#include "BKE_sketch.h"
-
-#include "RNA_define.h"
-#include "RNA_access.h"
-
-#include "ED_view3d.h"
-#include "ED_screen.h"
-
-#include "BIF_gl.h"
-#include "ED_armature.h"
-#include "armature_intern.h"
-#include "BIF_retarget.h"
-#include "BIF_generate.h"
-
-#include "ED_transform.h"
-#include "ED_transform_snap_object_context.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "GPU_select.h"
-
-typedef int (*GestureDetectFct)(bContext *, SK_Gesture *, SK_Sketch *);
-typedef void (*GestureApplyFct)(bContext *, SK_Gesture *, SK_Sketch *);
-
-typedef struct SK_GestureAction {
- char name[64];
- GestureDetectFct detect;
- GestureApplyFct apply;
-} SK_GestureAction;
-
-#if 0 /* UNUSED 2.5 */
-static SK_Point boneSnap;
-#endif
-
-static int LAST_SNAP_POINT_VALID = 0;
-static float LAST_SNAP_POINT[3];
-
-
-typedef struct SK_StrokeIterator {
- HeadFct head;
- TailFct tail;
- PeekFct peek;
- NextFct next;
- NextNFct nextN;
- PreviousFct previous;
- StoppedFct stopped;
-
- float *p, *no;
- float size;
-
- int length;
- int index;
- /*********************************/
- SK_Stroke *stroke;
- int start;
- int end;
- int stride;
-} SK_StrokeIterator;
-
-/******************** PROTOTYPES ******************************/
-
-void initStrokeIterator(BArcIterator *iter, SK_Stroke *stk, int start, int end);
-
-int sk_detectCutGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-void sk_applyCutGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-int sk_detectTrimGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-void sk_applyTrimGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-int sk_detectCommandGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-void sk_applyCommandGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-int sk_detectDeleteGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-void sk_applyDeleteGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-int sk_detectMergeGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-void sk_applyMergeGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-int sk_detectReverseGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-void sk_applyReverseGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-int sk_detectConvertGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-void sk_applyConvertGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch);
-
-SK_Sketch *contextSketch(const bContext *c, int create);
-SK_Sketch *viewcontextSketch(ViewContext *vc, int create);
-
-void sk_resetOverdraw(SK_Sketch *sketch);
-int sk_hasOverdraw(SK_Sketch *sketch, SK_Stroke *stk);
-
-/******************** GESTURE ACTIONS ******************************/
-
-static SK_GestureAction GESTURE_ACTIONS[] = {
- {"Cut", sk_detectCutGesture, sk_applyCutGesture},
- {"Trim", sk_detectTrimGesture, sk_applyTrimGesture},
- {"Command", sk_detectCommandGesture, sk_applyCommandGesture},
- {"Delete", sk_detectDeleteGesture, sk_applyDeleteGesture},
- {"Merge", sk_detectMergeGesture, sk_applyMergeGesture},
- {"Reverse", sk_detectReverseGesture, sk_applyReverseGesture},
- {"Convert", sk_detectConvertGesture, sk_applyConvertGesture},
- {"", NULL, NULL}
-};
-
-/******************** TEMPLATES UTILS *************************/
-
-static char *TEMPLATES_MENU = NULL;
-static int TEMPLATES_CURRENT = 0;
-static GHash *TEMPLATES_HASH = NULL;
-static RigGraph *TEMPLATE_RIGG = NULL;
-
-void BIF_makeListTemplates(const bContext *C)
-{
- Object *obedit = CTX_data_edit_object(C);
- Scene *scene = CTX_data_scene(C);
- ToolSettings *ts = CTX_data_tool_settings(C);
- Base *base;
- int index = 0;
-
- if (TEMPLATES_HASH != NULL) {
- BLI_ghash_free(TEMPLATES_HASH, NULL, NULL);
- }
-
- TEMPLATES_HASH = BLI_ghash_int_new("makeListTemplates gh");
- TEMPLATES_CURRENT = 0;
-
- for (base = FIRSTBASE; base; base = base->next) {
- Object *ob = base->object;
-
- if (ob != obedit && ob->type == OB_ARMATURE) {
- index++;
- BLI_ghash_insert(TEMPLATES_HASH, SET_INT_IN_POINTER(index), ob);
-
- if (ob == ts->skgen_template) {
- TEMPLATES_CURRENT = index;
- }
- }
- }
-}
-
-#if 0 /* UNUSED */
-const char *BIF_listTemplates(const bContext *UNUSED(C))
-{
- GHashIterator ghi;
- const char *menu_header = IFACE_("Template %t|None %x0|");
- char *p;
- const size_t template_size = (BLI_ghash_len(TEMPLATES_HASH) * 32 + 30);
-
- if (TEMPLATES_MENU != NULL) {
- MEM_freeN(TEMPLATES_MENU);
- }
-
- TEMPLATES_MENU = MEM_callocN(sizeof(char) * template_size, "skeleton template menu");
-
- p = TEMPLATES_MENU;
- p += BLI_strncpy_rlen(p, menu_header, template_size);
-
- BLI_ghashIterator_init(&ghi, TEMPLATES_HASH);
-
- while (!BLI_ghashIterator_done(&ghi)) {
- Object *ob = BLI_ghashIterator_getValue(&ghi);
- int key = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(&ghi));
-
- p += sprintf(p, "|%s %%x%i", ob->id.name + 2, key);
-
- BLI_ghashIterator_step(&ghi);
- }
-
- return TEMPLATES_MENU;
-}
-#endif
-
-int BIF_currentTemplate(const bContext *C)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
-
- if (TEMPLATES_CURRENT == 0 && ts->skgen_template != NULL) {
- GHashIterator ghi;
- BLI_ghashIterator_init(&ghi, TEMPLATES_HASH);
-
- while (!BLI_ghashIterator_done(&ghi)) {
- Object *ob = BLI_ghashIterator_getValue(&ghi);
- int key = GET_INT_FROM_POINTER(BLI_ghashIterator_getKey(&ghi));
-
- if (ob == ts->skgen_template) {
- TEMPLATES_CURRENT = key;
- break;
- }
-
- BLI_ghashIterator_step(&ghi);
- }
- }
-
- return TEMPLATES_CURRENT;
-}
-
-static RigGraph *sk_makeTemplateGraph(const bContext *C, Object *ob)
-{
- Object *obedit = CTX_data_edit_object(C);
- if (ob == obedit) {
- return NULL;
- }
-
- if (ob != NULL) {
- if (TEMPLATE_RIGG && TEMPLATE_RIGG->ob != ob) {
- RIG_freeRigGraph((BGraph *)TEMPLATE_RIGG);
- TEMPLATE_RIGG = NULL;
- }
-
- if (TEMPLATE_RIGG == NULL) {
- bArmature *arm;
-
- arm = ob->data;
-
- TEMPLATE_RIGG = RIG_graphFromArmature(C, ob, arm);
- }
- }
-
- return TEMPLATE_RIGG;
-}
-
-int BIF_nbJointsTemplate(const bContext *C)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- RigGraph *rg = sk_makeTemplateGraph(C, ts->skgen_template);
-
- if (rg) {
- return RIG_nbJoints(rg);
- }
- else {
- return -1;
- }
-}
-
-const char *BIF_nameBoneTemplate(const bContext *C)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- SK_Sketch *stk = contextSketch(C, 1);
- RigGraph *rg;
- int index = 0;
-
- if (stk && stk->active_stroke != NULL) {
- index = stk->active_stroke->nb_points;
- }
-
- rg = sk_makeTemplateGraph(C, ts->skgen_template);
-
- if (rg == NULL) {
- return "";
- }
-
- return RIG_nameBone(rg, 0, index);
-}
-
-void BIF_freeTemplates(bContext *UNUSED(C))
-{
- if (TEMPLATES_MENU != NULL) {
- MEM_freeN(TEMPLATES_MENU);
- TEMPLATES_MENU = NULL;
- }
-
- if (TEMPLATES_HASH != NULL) {
- BLI_ghash_free(TEMPLATES_HASH, NULL, NULL);
- TEMPLATES_HASH = NULL;
- }
-
- if (TEMPLATE_RIGG != NULL) {
- RIG_freeRigGraph((BGraph *)TEMPLATE_RIGG);
- TEMPLATE_RIGG = NULL;
- }
-}
-
-void BIF_setTemplate(bContext *C, int index)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- if (index > 0) {
- ts->skgen_template = BLI_ghash_lookup(TEMPLATES_HASH, SET_INT_IN_POINTER(index));
- }
- else {
- ts->skgen_template = NULL;
-
- if (TEMPLATE_RIGG != NULL) {
- RIG_freeRigGraph((BGraph *)TEMPLATE_RIGG);
- }
- TEMPLATE_RIGG = NULL;
- }
-}
-
-/*********************** CONVERSION ***************************/
-
-static void sk_autoname(bContext *C, ReebArc *arc)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- if (ts->skgen_retarget_options & SK_RETARGET_AUTONAME) {
- if (arc == NULL) {
- char *num = ts->skgen_num_string;
- int i = atoi(num);
- i++;
- BLI_snprintf(num, 8, "%i", i);
- }
- else {
- char *side = ts->skgen_side_string;
- int valid = 0;
- int caps = 0;
-
- if (side[0] == '\0') {
- valid = 1;
- }
- else if (STREQ(side, "R") || STREQ(side, "L")) {
- valid = 1;
- caps = 1;
- }
- else if (STREQ(side, "r") || STREQ(side, "l")) {
- valid = 1;
- caps = 0;
- }
-
- if (valid) {
- if (arc->head->p[0] < 0) {
- BLI_snprintf(side, 8, caps ? "R" : "r");
- }
- else {
- BLI_snprintf(side, 8, caps ? "L" : "l");
- }
- }
- }
- }
-}
-
-static ReebNode *sk_pointToNode(SK_Point *pt, float imat[4][4], float tmat[3][3])
-{
- ReebNode *node;
-
- node = MEM_callocN(sizeof(ReebNode), "reeb node");
- copy_v3_v3(node->p, pt->p);
- mul_m4_v3(imat, node->p);
-
- copy_v3_v3(node->no, pt->no);
- mul_m3_v3(tmat, node->no);
-
- return node;
-}
-
-static ReebArc *sk_strokeToArc(SK_Stroke *stk, float imat[4][4], float tmat[3][3])
-{
- ReebArc *arc;
- int i;
-
- arc = MEM_callocN(sizeof(ReebArc), "reeb arc");
- arc->head = sk_pointToNode(stk->points, imat, tmat);
- arc->tail = sk_pointToNode(sk_lastStrokePoint(stk), imat, tmat);
-
- arc->bcount = stk->nb_points - 2; /* first and last are nodes, don't count */
- arc->buckets = MEM_callocN(sizeof(EmbedBucket) * arc->bcount, "Buckets");
-
- for (i = 0; i < arc->bcount; i++) {
- copy_v3_v3(arc->buckets[i].p, stk->points[i + 1].p);
- mul_m4_v3(imat, arc->buckets[i].p);
-
- copy_v3_v3(arc->buckets[i].no, stk->points[i + 1].no);
- mul_m3_v3(tmat, arc->buckets[i].no);
- }
-
- return arc;
-}
-
-static void sk_retargetStroke(bContext *C, SK_Stroke *stk)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- Object *obedit = CTX_data_edit_object(C);
- float imat[4][4];
- float tmat[3][3];
- ReebArc *arc;
- RigGraph *rg;
-
- invert_m4_m4(imat, obedit->obmat);
- transpose_m3_m4(tmat, obedit->obmat);
-
- arc = sk_strokeToArc(stk, imat, tmat);
-
- sk_autoname(C, arc);
-
- rg = sk_makeTemplateGraph(C, ts->skgen_template);
-
- BIF_retargetArc(C, arc, rg);
-
- sk_autoname(C, NULL);
-
- MEM_freeN(arc->head);
- MEM_freeN(arc->tail);
- REEB_freeArc((BArc *)arc);
-}
-
-/**************************************************************/
-
-static void sk_cancelStroke(SK_Sketch *sketch)
-{
- if (sketch->active_stroke != NULL) {
- sk_resetOverdraw(sketch);
- sk_removeStroke(sketch, sketch->active_stroke);
- }
-}
-
-
-static float sk_clampPointSize(SK_Point *pt, float size)
-{
- return max_ff(size * pt->size, size / 2);
-}
-
-static void sk_drawPoint(GLUquadric *quad, SK_Point *pt, float size)
-{
- glTranslate3fv(pt->p);
- gluSphere(quad, sk_clampPointSize(pt, size), 8, 8);
-}
-
-static void sk_drawEdge(GLUquadric *quad, SK_Point *pt0, SK_Point *pt1, float size)
-{
- float vec1[3], vec2[3] = {0, 0, 1}, axis[3];
- float angle, length;
-
- sub_v3_v3v3(vec1, pt1->p, pt0->p);
- length = normalize_v3(vec1);
- cross_v3_v3v3(axis, vec2, vec1);
-
- if (is_zero_v3(axis)) {
- axis[1] = 1;
- }
-
- angle = angle_normalized_v3v3(vec2, vec1);
-
- glRotate3fv(angle * (float)(180.0 / M_PI) + 180.0f, axis);
-
- gluCylinder(quad, sk_clampPointSize(pt1, size), sk_clampPointSize(pt0, size), length, 8, 8);
-}
-
-static void sk_drawNormal(GLUquadric *quad, SK_Point *pt, float size, float height)
-{
- float vec2[3] = {0, 0, 1}, axis[3];
- float angle;
-
- glPushMatrix();
-
- cross_v3_v3v3(axis, vec2, pt->no);
-
- if (is_zero_v3(axis)) {
- axis[1] = 1;
- }
-
- angle = angle_normalized_v3v3(vec2, pt->no);
-
- glRotate3fv(angle * (float)(180.0 / M_PI), axis);
-
- glColor3f(0, 1, 1);
- gluCylinder(quad, sk_clampPointSize(pt, size), 0, sk_clampPointSize(pt, height), 10, 2);
-
- glPopMatrix();
-}
-
-static void sk_drawStroke(SK_Stroke *stk, int id, float color[3], int start, int end)
-{
- float rgb[3];
- int i;
- GLUquadric *quad = gluNewQuadric();
- gluQuadricNormals(quad, GLU_SMOOTH);
-
- if (id != -1) {
- GPU_select_load_id(id);
-
- for (i = 0; i < stk->nb_points; i++) {
- glPushMatrix();
-
- sk_drawPoint(quad, stk->points + i, 0.1);
-
- if (i > 0) {
- sk_drawEdge(quad, stk->points + i - 1, stk->points + i, 0.1);
- }
-
- glPopMatrix();
- }
-
- }
- else {
- float d_rgb[3] = {1, 1, 1};
-
- copy_v3_v3(rgb, color);
- sub_v3_v3(d_rgb, rgb);
- mul_v3_fl(d_rgb, 1.0f / (float)stk->nb_points);
-
- for (i = 0; i < stk->nb_points; i++) {
- SK_Point *pt = stk->points + i;
-
- glPushMatrix();
-
- if (pt->type == PT_EXACT) {
- glColor3f(0, 0, 0);
- sk_drawPoint(quad, pt, 0.15);
- sk_drawNormal(quad, pt, 0.05, 0.9);
- }
-
- if (i >= start && i <= end) {
- glColor3f(0.3, 0.3, 0.3);
- }
- else {
- glColor3fv(rgb);
- }
-
- if (pt->type != PT_EXACT) {
-
- sk_drawPoint(quad, pt, 0.1);
- }
-
- if (i > 0) {
- sk_drawEdge(quad, pt - 1, pt, 0.1);
- }
-
- glPopMatrix();
-
- add_v3_v3(rgb, d_rgb);
- }
- }
-
- gluDeleteQuadric(quad);
-}
-
-static void drawSubdividedStrokeBy(ToolSettings *toolsettings, BArcIterator *iter, NextSubdivisionFunc next_subdividion)
-{
- SK_Stroke *stk = ((SK_StrokeIterator *)iter)->stroke;
- float head[3], tail[3];
- int bone_start = 0;
- int end = iter->length;
- int index;
- GLUquadric *quad = gluNewQuadric();
- gluQuadricNormals(quad, GLU_SMOOTH);
-
- iter->head(iter);
- copy_v3_v3(head, iter->p);
-
- index = next_subdividion(toolsettings, iter, bone_start, end, head, tail);
- while (index != -1) {
- SK_Point *pt = stk->points + index;
-
- glPushMatrix();
-
- glColor3f(0, 1, 0);
- sk_drawPoint(quad, pt, 0.15);
-
- sk_drawNormal(quad, pt, 0.05, 0.9);
-
- glPopMatrix();
-
- copy_v3_v3(head, tail);
- bone_start = index; // start next bone from current index
-
- index = next_subdividion(toolsettings, iter, bone_start, end, head, tail);
- }
-
- gluDeleteQuadric(quad);
-}
-
-static void sk_drawStrokeSubdivision(ToolSettings *toolsettings, SK_Stroke *stk)
-{
- int head_index = -1;
- int i;
-
- if (toolsettings->bone_sketching_convert == SK_CONVERT_RETARGET) {
- return;
- }
-
-
- for (i = 0; i < stk->nb_points; i++) {
- SK_Point *pt = stk->points + i;
-
- if (pt->type == PT_EXACT || i == stk->nb_points - 1) /* stop on exact or on last point */ {
- if (head_index == -1) {
- head_index = i;
- }
- else {
- if (i - head_index > 1) {
- SK_StrokeIterator sk_iter;
- BArcIterator *iter = (BArcIterator *)&sk_iter;
-
- initStrokeIterator(iter, stk, head_index, i);
-
- if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_ADAPTATIVE) {
- drawSubdividedStrokeBy(toolsettings, iter, nextAdaptativeSubdivision);
- }
- else if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_LENGTH) {
- drawSubdividedStrokeBy(toolsettings, iter, nextLengthSubdivision);
- }
- else if (toolsettings->bone_sketching_convert == SK_CONVERT_CUT_FIXED) {
- drawSubdividedStrokeBy(toolsettings, iter, nextFixedSubdivision);
- }
-
- }
-
- head_index = i;
- }
- }
- }
-}
-
-static SK_Point *sk_snapPointStroke(bContext *C, SK_Stroke *stk, int mval[2], float *r_dist_px, int *index, int all_pts)
-{
- ARegion *ar = CTX_wm_region(C);
- SK_Point *pt = NULL;
- int i;
-
- for (i = 0; i < stk->nb_points; i++) {
- if (all_pts || stk->points[i].type == PT_EXACT) {
- short pval[2];
- int pdist;
-
- if (ED_view3d_project_short_global(ar, stk->points[i].p, pval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-
- pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
-
- if (pdist < *r_dist_px) {
- *r_dist_px = pdist;
- pt = stk->points + i;
-
- if (index != NULL) {
- *index = i;
- }
- }
- }
- }
- }
-
- return pt;
-}
-
-#if 0 /* UNUSED 2.5 */
-static SK_Point *sk_snapPointArmature(bContext *C, Object *ob, ListBase *ebones, int mval[2], int *dist)
-{
- ARegion *ar = CTX_wm_region(C);
- SK_Point *pt = NULL;
- EditBone *bone;
-
- for (bone = ebones->first; bone; bone = bone->next)
- {
- float vec[3];
- short pval[2];
- int pdist;
-
- if ((bone->flag & BONE_CONNECTED) == 0)
- {
- copy_v3_v3(vec, bone->head);
- mul_m4_v3(ob->obmat, vec);
- if (ED_view3d_project_short_noclip(ar, vec, pval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-
- pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
-
- if (pdist < *dist)
- {
- *dist = pdist;
- pt = &boneSnap;
- copy_v3_v3(pt->p, vec);
- pt->type = PT_EXACT;
- }
- }
- }
-
-
- copy_v3_v3(vec, bone->tail);
- mul_m4_v3(ob->obmat, vec);
- if (ED_view3d_project_short_noclip(ar, vec, pval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
-
- pdist = ABS(pval[0] - mval[0]) + ABS(pval[1] - mval[1]);
-
- if (pdist < *dist)
- {
- *dist = pdist;
- pt = &boneSnap;
- copy_v3_v3(pt->p, vec);
- pt->type = PT_EXACT;
- }
- }
- }
-
- return pt;
-}
-#endif
-
-void sk_resetOverdraw(SK_Sketch *sketch)
-{
- sketch->over.target = NULL;
- sketch->over.start = -1;
- sketch->over.end = -1;
- sketch->over.count = 0;
-}
-
-int sk_hasOverdraw(SK_Sketch *sketch, SK_Stroke *stk)
-{
- return sketch->over.target &&
- sketch->over.count >= SK_OVERDRAW_LIMIT &&
- (sketch->over.target == stk || stk == NULL) &&
- (sketch->over.start != -1 || sketch->over.end != -1);
-}
-
-static void sk_updateOverdraw(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd)
-{
- if (sketch->over.target == NULL) {
- SK_Stroke *target;
- int closest_index = -1;
- float dist_px = SNAP_MIN_DISTANCE * 2;
-
- for (target = sketch->strokes.first; target; target = target->next) {
- if (target != stk) {
- int index;
-
- SK_Point *spt = sk_snapPointStroke(C, target, dd->mval, &dist_px, &index, 1);
-
- if (spt != NULL) {
- sketch->over.target = target;
- closest_index = index;
- }
- }
- }
-
- if (sketch->over.target != NULL) {
- if (closest_index > -1) {
- if (sk_lastStrokePoint(stk)->type == PT_EXACT) {
- sketch->over.count = SK_OVERDRAW_LIMIT;
- }
- else {
- sketch->over.count++;
- }
- }
-
- if (stk->nb_points == 1) {
- sketch->over.start = closest_index;
- }
- else {
- sketch->over.end = closest_index;
- }
- }
- }
- else if (sketch->over.target != NULL) {
- SK_Point *closest_pt = NULL;
- float dist_px = SNAP_MIN_DISTANCE * 2;
- int index;
-
- closest_pt = sk_snapPointStroke(C, sketch->over.target, dd->mval, &dist_px, &index, 1);
-
- if (closest_pt != NULL) {
- if (sk_lastStrokePoint(stk)->type == PT_EXACT) {
- sketch->over.count = SK_OVERDRAW_LIMIT;
- }
- else {
- sketch->over.count++;
- }
-
- sketch->over.end = index;
- }
- else {
- sketch->over.end = -1;
- }
- }
-}
-
-/* return 1 on reverse needed */
-static int sk_adjustIndexes(SK_Sketch *sketch, int *start, int *end)
-{
- int retval = 0;
-
- *start = sketch->over.start;
- *end = sketch->over.end;
-
- if (*start == -1) {
- *start = 0;
- }
-
- if (*end == -1) {
- *end = sketch->over.target->nb_points - 1;
- }
-
- if (*end < *start) {
- int tmp = *start;
- *start = *end;
- *end = tmp;
- retval = 1;
- }
-
- return retval;
-}
-
-static void sk_endOverdraw(SK_Sketch *sketch)
-{
- SK_Stroke *stk = sketch->active_stroke;
-
- if (sk_hasOverdraw(sketch, NULL)) {
- int start;
- int end;
-
- if (sk_adjustIndexes(sketch, &start, &end)) {
- sk_reverseStroke(stk);
- }
-
- if (stk->nb_points > 1) {
- stk->points->type = sketch->over.target->points[start].type;
- sk_lastStrokePoint(stk)->type = sketch->over.target->points[end].type;
- }
-
- sk_insertStrokePoints(sketch->over.target, stk->points, stk->nb_points, start, end);
-
- sk_removeStroke(sketch, stk);
-
- sk_resetOverdraw(sketch);
- }
-}
-
-
-static void sk_startStroke(SK_Sketch *sketch)
-{
- SK_Stroke *stk = sk_createStroke();
-
- BLI_addtail(&sketch->strokes, stk);
- sketch->active_stroke = stk;
-
- sk_resetOverdraw(sketch);
-}
-
-static void sk_endStroke(bContext *C, SK_Sketch *sketch)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- sk_shrinkStrokeBuffer(sketch->active_stroke);
-
- if (ts->bone_sketching & BONE_SKETCHING_ADJUST) {
- sk_endOverdraw(sketch);
- }
-
- sketch->active_stroke = NULL;
-}
-
-static void sk_updateDrawData(SK_DrawData *dd)
-{
- dd->type = PT_CONTINUOUS;
-
- dd->previous_mval[0] = dd->mval[0];
- dd->previous_mval[1] = dd->mval[1];
-}
-
-static float sk_distanceDepth(bContext *C, float p1[3], float p2[3])
-{
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
- float vec[3];
- float distance;
-
- sub_v3_v3v3(vec, p1, p2);
-
- project_v3_v3v3(vec, vec, rv3d->viewinv[2]);
-
- distance = len_v3(vec);
-
- if (dot_v3v3(rv3d->viewinv[2], vec) > 0) {
- distance *= -1;
- }
-
- return distance;
-}
-
-static void sk_interpolateDepth(bContext *C, SK_Stroke *stk, int start, int end, float length, float distance)
-{
- ARegion *ar = CTX_wm_region(C);
- ScrArea *sa = CTX_wm_area(C);
- View3D *v3d = sa->spacedata.first;
-
- float progress = 0;
- int i;
-
- progress = len_v3v3(stk->points[start].p, stk->points[start - 1].p);
-
- for (i = start; i <= end; i++) {
- float ray_start[3], ray_normal[3];
- float delta = len_v3v3(stk->points[i].p, stk->points[i + 1].p);
- float pval[2] = {0, 0};
-
- ED_view3d_project_float_global(ar, stk->points[i].p, pval, V3D_PROJ_TEST_NOP);
- ED_view3d_win_to_ray(ar, v3d, pval, ray_start, ray_normal, false);
-
- mul_v3_fl(ray_normal, distance * progress / length);
- add_v3_v3(stk->points[i].p, ray_normal);
-
- progress += delta;
- }
-}
-
-static void sk_projectDrawPoint(bContext *C, float vec[3], SK_Stroke *stk, SK_DrawData *dd)
-{
- ARegion *ar = CTX_wm_region(C);
- /* copied from grease pencil, need fixing */
- SK_Point *last = sk_lastStrokePoint(stk);
- short cval[2];
- float fp[3] = {0, 0, 0};
- float dvec[3];
- float mval_f[2];
- float zfac;
-
- if (last != NULL) {
- copy_v3_v3(fp, last->p);
- }
-
- zfac = ED_view3d_calc_zfac(ar->regiondata, fp, NULL);
-
- if (ED_view3d_project_short_global(ar, fp, cval, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
- VECSUB2D(mval_f, cval, dd->mval);
- ED_view3d_win_to_delta(ar, mval_f, dvec, zfac);
- sub_v3_v3v3(vec, fp, dvec);
- }
- else {
- zero_v3(vec);
- }
-}
-
-static int sk_getStrokeDrawPoint(bContext *C, SK_Point *pt, SK_Sketch *UNUSED(sketch), SK_Stroke *stk, SK_DrawData *dd)
-{
- pt->type = dd->type;
- pt->mode = PT_PROJECT;
- sk_projectDrawPoint(C, pt->p, stk, dd);
-
- return 1;
-}
-
-static int sk_addStrokeDrawPoint(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd)
-{
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
- SK_Point pt;
-
- sk_initPoint(&pt, dd, rv3d->viewinv[2]);
-
- sk_getStrokeDrawPoint(C, &pt, sketch, stk, dd);
-
- sk_appendStrokePoint(stk, &pt);
-
- return 1;
-}
-
-static int sk_getStrokeSnapPoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- int point_added = 0;
-
- /* TODO: Since the function `ED_transform_snap_object_context_create_view3d` creates a cache,
- * the ideal would be to call this function only at the beginning of the snap operation,
- * or at the beginning of the operator itself */
- struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
- CTX_data_main(C), CTX_data_scene(C), 0,
- CTX_wm_region(C), CTX_wm_view3d(C));
-
- float mvalf[2] = {UNPACK2(dd->mval)};
- float loc[3], dummy_no[3];
-
- if (ts->snap_mode == SCE_SNAP_MODE_VOLUME) {
- float size;
- if (peelObjectsSnapContext(
- snap_context, mvalf,
- &(const struct SnapObjectParams){
- .snap_select = SNAP_NOT_SELECTED,
- .use_object_edit_cage = false,
- },
- (ts->snap_flag & SCE_SNAP_PEEL_OBJECT) != 0,
- loc, dummy_no, &size))
- {
- pt->type = dd->type;
- pt->mode = PT_SNAP;
- pt->size = size / 2;
- copy_v3_v3(pt->p, loc);
-
- point_added = 1;
- }
- }
- else {
- SK_Stroke *snap_stk;
- float dist_px = SNAP_MIN_DISTANCE; // Use a user defined value here
-
- /* snap to strokes */
- // if (ts->snap_mode == SCE_SNAP_MODE_VERTEX) /* snap all the time to strokes */
- for (snap_stk = sketch->strokes.first; snap_stk; snap_stk = snap_stk->next) {
- SK_Point *spt = NULL;
- if (snap_stk == stk) {
- spt = sk_snapPointStroke(C, snap_stk, dd->mval, &dist_px, NULL, 0);
- }
- else {
- spt = sk_snapPointStroke(C, snap_stk, dd->mval, &dist_px, NULL, 1);
- }
-
- if (spt != NULL) {
- copy_v3_v3(pt->p, spt->p);
- point_added = 1;
- }
- }
-
- /* try to snap to closer object */
- {
- if (ED_transform_snap_object_project_view3d(
- snap_context,
- ts->snap_mode,
- &(const struct SnapObjectParams){
- .snap_select = SNAP_NOT_SELECTED,
- .use_object_edit_cage = false,
- },
- mvalf, &dist_px, NULL,
- loc, dummy_no))
- {
- pt->type = dd->type;
- pt->mode = PT_SNAP;
- copy_v3_v3(pt->p, loc);
-
- point_added = 1;
- }
- }
- }
-
- /* TODO: The ideal would be to call this function only once.
- * At the end of the operator */
- ED_transform_snap_object_context_destroy(snap_context);
- return point_added;
-}
-
-static int sk_addStrokeSnapPoint(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd)
-{
- int point_added;
- ARegion *ar = CTX_wm_region(C);
- RegionView3D *rv3d = ar->regiondata;
- SK_Point pt;
-
- sk_initPoint(&pt, dd, rv3d->viewinv[2]);
-
- point_added = sk_getStrokeSnapPoint(C, &pt, sketch, stk, dd);
-
- if (point_added) {
- float final_p[3];
- float length, distance;
- int total;
- int i;
-
- copy_v3_v3(final_p, pt.p);
-
- sk_projectDrawPoint(C, pt.p, stk, dd);
- sk_appendStrokePoint(stk, &pt);
-
- /* update all previous point to give smooth Z progresion */
- total = 0;
- length = 0;
- for (i = stk->nb_points - 2; i > 0; i--) {
- length += len_v3v3(stk->points[i].p, stk->points[i + 1].p);
- total++;
- if (stk->points[i].mode == PT_SNAP || stk->points[i].type == PT_EXACT) {
- break;
- }
- }
-
- if (total > 1) {
- distance = sk_distanceDepth(C, final_p, stk->points[i].p);
-
- sk_interpolateDepth(C, stk, i + 1, stk->nb_points - 2, length, distance);
- }
-
- copy_v3_v3(stk->points[stk->nb_points - 1].p, final_p);
-
- point_added = 1;
- }
-
- return point_added;
-}
-
-static void sk_addStrokePoint(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd, const bool snap)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- int point_added = 0;
-
- if (snap) {
- point_added = sk_addStrokeSnapPoint(C, sketch, stk, dd);
- }
-
- if (point_added == 0) {
- point_added = sk_addStrokeDrawPoint(C, sketch, stk, dd);
- }
-
- if (stk == sketch->active_stroke && ts->bone_sketching & BONE_SKETCHING_ADJUST) {
- sk_updateOverdraw(C, sketch, stk, dd);
- }
-}
-
-static void sk_getStrokePoint(bContext *C, SK_Point *pt, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd, const bool snap)
-{
- int point_added = 0;
-
- if (snap) {
- point_added = sk_getStrokeSnapPoint(C, pt, sketch, stk, dd);
- LAST_SNAP_POINT_VALID = 1;
- copy_v3_v3(LAST_SNAP_POINT, pt->p);
- }
- else {
- LAST_SNAP_POINT_VALID = 0;
- }
-
- if (point_added == 0) {
- point_added = sk_getStrokeDrawPoint(C, pt, sketch, stk, dd);
- }
-}
-
-/********************************************/
-
-static void *headPoint(void *arg);
-static void *tailPoint(void *arg);
-static void *nextPoint(void *arg);
-static void *nextNPoint(void *arg, int n);
-static void *peekPoint(void *arg, int n);
-static void *previousPoint(void *arg);
-static int iteratorStopped(void *arg);
-
-static void initIteratorFct(SK_StrokeIterator *iter)
-{
- iter->head = headPoint;
- iter->tail = tailPoint;
- iter->peek = peekPoint;
- iter->next = nextPoint;
- iter->nextN = nextNPoint;
- iter->previous = previousPoint;
- iter->stopped = iteratorStopped;
-}
-
-static SK_Point *setIteratorValues(SK_StrokeIterator *iter, int index)
-{
- SK_Point *pt = NULL;
-
- if (index >= 0 && index < iter->length) {
- pt = &(iter->stroke->points[iter->start + (iter->stride * index)]);
- iter->p = pt->p;
- iter->no = pt->no;
- iter->size = pt->size;
- }
- else {
- iter->p = NULL;
- iter->no = NULL;
- iter->size = 0;
- }
-
- return pt;
-}
-
-void initStrokeIterator(BArcIterator *arg, SK_Stroke *stk, int start, int end)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
-
- initIteratorFct(iter);
- iter->stroke = stk;
-
- if (start < end) {
- iter->start = start + 1;
- iter->end = end - 1;
- iter->stride = 1;
- }
- else {
- iter->start = start - 1;
- iter->end = end + 1;
- iter->stride = -1;
- }
-
- iter->length = iter->stride * (iter->end - iter->start + 1);
-
- iter->index = -1;
-}
-
-
-static void *headPoint(void *arg)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
- SK_Point *result = NULL;
-
- result = &(iter->stroke->points[iter->start - iter->stride]);
- iter->p = result->p;
- iter->no = result->no;
- iter->size = result->size;
-
- return result;
-}
-
-static void *tailPoint(void *arg)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
- SK_Point *result = NULL;
-
- result = &(iter->stroke->points[iter->end + iter->stride]);
- iter->p = result->p;
- iter->no = result->no;
- iter->size = result->size;
-
- return result;
-}
-
-static void *nextPoint(void *arg)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
- SK_Point *result = NULL;
-
- iter->index++;
- if (iter->index < iter->length) {
- result = setIteratorValues(iter, iter->index);
- }
-
- return result;
-}
-
-static void *nextNPoint(void *arg, int n)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
- SK_Point *result = NULL;
-
- iter->index += n;
-
- /* check if passed end */
- if (iter->index < iter->length) {
- result = setIteratorValues(iter, iter->index);
- }
-
- return result;
-}
-
-static void *peekPoint(void *arg, int n)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
- SK_Point *result = NULL;
- int index = iter->index + n;
-
- /* check if passed end */
- if (index < iter->length) {
- result = setIteratorValues(iter, index);
- }
-
- return result;
-}
-
-static void *previousPoint(void *arg)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
- SK_Point *result = NULL;
-
- if (iter->index > 0) {
- iter->index--;
- result = setIteratorValues(iter, iter->index);
- }
-
- return result;
-}
-
-static int iteratorStopped(void *arg)
-{
- SK_StrokeIterator *iter = (SK_StrokeIterator *)arg;
-
- if (iter->index >= iter->length) {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-static void sk_convertStroke(bContext *C, SK_Stroke *stk)
-{
- Object *obedit = CTX_data_edit_object(C);
- ToolSettings *ts = CTX_data_tool_settings(C);
- bArmature *arm = obedit->data;
- SK_Point *head;
- EditBone *parent = NULL;
- float invmat[4][4]; /* move in caller function */
- float tmat[3][3];
- int head_index = 0;
- int i;
-
- head = NULL;
-
- invert_m4_m4(invmat, obedit->obmat);
- transpose_m3_m4(tmat, obedit->obmat);
-
- for (i = 0; i < stk->nb_points; i++) {
- SK_Point *pt = stk->points + i;
-
- if (pt->type == PT_EXACT) {
- if (head == NULL) {
- head_index = i;
- head = pt;
- }
- else {
- EditBone *bone = NULL;
- EditBone *new_parent;
-
- if (i - head_index > 1) {
- SK_StrokeIterator sk_iter;
- BArcIterator *iter = (BArcIterator *)&sk_iter;
-
- initStrokeIterator(iter, stk, head_index, i);
-
- if (ts->bone_sketching_convert == SK_CONVERT_CUT_ADAPTATIVE) {
- bone = subdivideArcBy(ts, arm, arm->edbo, iter, invmat, tmat, nextAdaptativeSubdivision);
- }
- else if (ts->bone_sketching_convert == SK_CONVERT_CUT_LENGTH) {
- bone = subdivideArcBy(ts, arm, arm->edbo, iter, invmat, tmat, nextLengthSubdivision);
- }
- else if (ts->bone_sketching_convert == SK_CONVERT_CUT_FIXED) {
- bone = subdivideArcBy(ts, arm, arm->edbo, iter, invmat, tmat, nextFixedSubdivision);
- }
- }
-
- if (bone == NULL) {
- bone = ED_armature_ebone_add(arm, "Bone");
-
- copy_v3_v3(bone->head, head->p);
- copy_v3_v3(bone->tail, pt->p);
-
- mul_m4_v3(invmat, bone->head);
- mul_m4_v3(invmat, bone->tail);
- setBoneRollFromNormal(bone, head->no, invmat, tmat);
- }
-
- new_parent = bone;
- bone->flag |= BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL;
-
- /* move to end of chain */
- while (bone->parent != NULL) {
- bone = bone->parent;
- bone->flag |= BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL;
- }
-
- if (parent != NULL) {
- bone->parent = parent;
- bone->flag |= BONE_CONNECTED;
- }
-
- parent = new_parent;
- head_index = i;
- head = pt;
- }
- }
- }
-}
-
-static void sk_convert(bContext *C, SK_Sketch *sketch)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- SK_Stroke *stk;
-
- for (stk = sketch->strokes.first; stk; stk = stk->next) {
- if (stk->selected == 1) {
- if (ts->bone_sketching_convert == SK_CONVERT_RETARGET) {
- sk_retargetStroke(C, stk);
- }
- else {
- sk_convertStroke(C, stk);
- }
-// XXX
-// allqueue(REDRAWBUTSEDIT, 0);
- }
- }
-}
-/******************* GESTURE *************************/
-
-
-/* returns the number of self intersections */
-static int sk_getSelfIntersections(bContext *C, ListBase *list, SK_Stroke *gesture)
-{
- ARegion *ar = CTX_wm_region(C);
- int added = 0;
- int s_i;
-
- for (s_i = 0; s_i < gesture->nb_points - 1; s_i++) {
- float s_p1[3] = {0, 0, 0};
- float s_p2[3] = {0, 0, 0};
- int g_i;
-
- ED_view3d_project_float_global(ar, gesture->points[s_i].p, s_p1, V3D_PROJ_TEST_NOP);
- ED_view3d_project_float_global(ar, gesture->points[s_i + 1].p, s_p2, V3D_PROJ_TEST_NOP);
-
- /* start checking from second next, because two consecutive cannot intersect */
- for (g_i = s_i + 2; g_i < gesture->nb_points - 1; g_i++) {
- float g_p1[3] = {0, 0, 0};
- float g_p2[3] = {0, 0, 0};
- float vi[3];
- float lambda;
-
- ED_view3d_project_float_global(ar, gesture->points[g_i].p, g_p1, V3D_PROJ_TEST_NOP);
- ED_view3d_project_float_global(ar, gesture->points[g_i + 1].p, g_p2, V3D_PROJ_TEST_NOP);
-
- if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) {
- SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection");
-
- isect->gesture_index = g_i;
- isect->before = s_i;
- isect->after = s_i + 1;
- isect->stroke = gesture;
-
- sub_v3_v3v3(isect->p, gesture->points[s_i + 1].p, gesture->points[s_i].p);
- mul_v3_fl(isect->p, lambda);
- add_v3_v3(isect->p, gesture->points[s_i].p);
-
- BLI_addtail(list, isect);
-
- added++;
- }
- }
- }
-
- return added;
-}
-
-static int cmpIntersections(const void *i1, const void *i2)
-{
- const SK_Intersection *isect1 = i1, *isect2 = i2;
-
- if (isect1->stroke == isect2->stroke) {
- if (isect1->before < isect2->before) {
- return -1;
- }
- else if (isect1->before > isect2->before) {
- return 1;
- }
- else {
- if (isect1->lambda < isect2->lambda) {
- return -1;
- }
- else if (isect1->lambda > isect2->lambda) {
- return 1;
- }
- }
- }
-
- return 0;
-}
-
-
-/* returns the maximum number of intersections per stroke */
-static int sk_getIntersections(bContext *C, ListBase *list, SK_Sketch *sketch, SK_Stroke *gesture)
-{
- ARegion *ar = CTX_wm_region(C);
- ScrArea *sa = CTX_wm_area(C);
- View3D *v3d = sa->spacedata.first;
- SK_Stroke *stk;
- int added = 0;
-
- for (stk = sketch->strokes.first; stk; stk = stk->next) {
- int s_added = 0;
- int s_i;
-
- for (s_i = 0; s_i < stk->nb_points - 1; s_i++) {
- float s_p1[3] = {0, 0, 0};
- float s_p2[3] = {0, 0, 0};
- int g_i;
-
- ED_view3d_project_float_global(ar, stk->points[s_i].p, s_p1, V3D_PROJ_TEST_NOP);
- ED_view3d_project_float_global(ar, stk->points[s_i + 1].p, s_p2, V3D_PROJ_TEST_NOP);
-
- for (g_i = 0; g_i < gesture->nb_points - 1; g_i++) {
- float g_p1[3] = {0, 0, 0};
- float g_p2[3] = {0, 0, 0};
- float vi[3];
- float lambda;
-
- ED_view3d_project_float_global(ar, gesture->points[g_i].p, g_p1, V3D_PROJ_TEST_NOP);
- ED_view3d_project_float_global(ar, gesture->points[g_i + 1].p, g_p2, V3D_PROJ_TEST_NOP);
-
- if (isect_line_line_strict_v3(s_p1, s_p2, g_p1, g_p2, vi, &lambda)) {
- SK_Intersection *isect = MEM_callocN(sizeof(SK_Intersection), "Intersection");
- float ray_start[3], ray_end[3];
- float mval[2];
-
- isect->gesture_index = g_i;
- isect->before = s_i;
- isect->after = s_i + 1;
- isect->stroke = stk;
- isect->lambda = lambda;
-
- mval[0] = vi[0];
- mval[1] = vi[1];
- ED_view3d_win_to_segment(ar, v3d, mval, ray_start, ray_end, true);
-
- isect_line_line_v3(stk->points[s_i].p,
- stk->points[s_i + 1].p,
- ray_start,
- ray_end,
- isect->p,
- vi);
-
- BLI_addtail(list, isect);
-
- s_added++;
- }
- }
- }
-
- added = MAX2(s_added, added);
- }
-
- BLI_listbase_sort(list, cmpIntersections);
-
- return added;
-}
-
-static int sk_getSegments(SK_Stroke *segments, SK_Stroke *gesture)
-{
- SK_StrokeIterator sk_iter;
- BArcIterator *iter = (BArcIterator *)&sk_iter;
-
- float CORRELATION_THRESHOLD = 0.99f;
- float *vec;
- int i, j;
-
- sk_appendStrokePoint(segments, &gesture->points[0]);
- vec = segments->points[segments->nb_points - 1].p;
-
- initStrokeIterator(iter, gesture, 0, gesture->nb_points - 1);
-
- for (i = 1, j = 0; i < gesture->nb_points; i++) {
- float n[3];
-
- /* Calculate normal */
- sub_v3_v3v3(n, gesture->points[i].p, vec);
-
- if (calcArcCorrelation(iter, j, i, vec, n) < CORRELATION_THRESHOLD) {
- j = i - 1;
- sk_appendStrokePoint(segments, &gesture->points[j]);
- vec = segments->points[segments->nb_points - 1].p;
- segments->points[segments->nb_points - 1].type = PT_EXACT;
- }
- }
-
- sk_appendStrokePoint(segments, &gesture->points[gesture->nb_points - 1]);
-
- return segments->nb_points - 1;
-}
-
-int sk_detectCutGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- if (gest->nb_segments == 1 && gest->nb_intersections == 1) {
- return 1;
- }
-
- return 0;
-}
-
-void sk_applyCutGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- SK_Intersection *isect;
-
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- SK_Point pt;
-
- pt.type = PT_EXACT;
- pt.mode = PT_PROJECT; /* take mode from neighboring points */
- copy_v3_v3(pt.p, isect->p);
- copy_v3_v3(pt.no, isect->stroke->points[isect->before].no);
-
- sk_insertStrokePoint(isect->stroke, &pt, isect->after);
- }
-}
-
-int sk_detectTrimGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- if (gest->nb_segments == 2 && gest->nb_intersections == 1 && gest->nb_self_intersections == 0) {
- float s1[3], s2[3];
- float angle;
-
- sub_v3_v3v3(s1, gest->segments->points[1].p, gest->segments->points[0].p);
- sub_v3_v3v3(s2, gest->segments->points[2].p, gest->segments->points[1].p);
-
- angle = RAD2DEGF(angle_v2v2(s1, s2));
-
- if (angle > 60 && angle < 120) {
- return 1;
- }
- }
-
- return 0;
-}
-
-void sk_applyTrimGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- SK_Intersection *isect;
- float trim_dir[3];
-
- sub_v3_v3v3(trim_dir, gest->segments->points[2].p, gest->segments->points[1].p);
-
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- SK_Point pt;
- float stroke_dir[3];
-
- pt.type = PT_EXACT;
- pt.mode = PT_PROJECT; /* take mode from neighboring points */
- copy_v3_v3(pt.p, isect->p);
- copy_v3_v3(pt.no, isect->stroke->points[isect->before].no);
-
- sub_v3_v3v3(stroke_dir, isect->stroke->points[isect->after].p, isect->stroke->points[isect->before].p);
-
- /* same direction, trim end */
- if (dot_v3v3(stroke_dir, trim_dir) > 0) {
- sk_replaceStrokePoint(isect->stroke, &pt, isect->after);
- sk_trimStroke(isect->stroke, 0, isect->after);
- }
- /* else, trim start */
- else {
- sk_replaceStrokePoint(isect->stroke, &pt, isect->before);
- sk_trimStroke(isect->stroke, isect->before, isect->stroke->nb_points - 1);
- }
-
- }
-}
-
-int sk_detectCommandGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- if (gest->nb_segments > 2 && gest->nb_intersections == 2 && gest->nb_self_intersections == 1) {
- SK_Intersection *isect, *self_isect;
-
- /* get the last intersection of the first pair */
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- if (isect->stroke == isect->next->stroke) {
- isect = isect->next;
- break;
- }
- }
-
- self_isect = gest->self_intersections.first;
-
- if (isect && isect->gesture_index < self_isect->gesture_index) {
- return 1;
- }
- }
-
- return 0;
-}
-
-void sk_applyCommandGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- SK_Intersection *isect;
- int command = 1;
-
-/* XXX */
-/* command = pupmenu("Action %t|Flatten %x1|Straighten %x2|Polygonize %x3"); */
- if (command < 1) return;
-
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- SK_Intersection *i2;
-
- i2 = isect->next;
-
- if (i2 && i2->stroke == isect->stroke) {
- switch (command) {
- case 1:
- sk_flattenStroke(isect->stroke, isect->before, i2->after);
- break;
- case 2:
- sk_straightenStroke(isect->stroke, isect->before, i2->after, isect->p, i2->p);
- break;
- case 3:
- sk_polygonizeStroke(isect->stroke, isect->before, i2->after);
- break;
- }
-
- isect = i2;
- }
- }
-}
-
-int sk_detectDeleteGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- if (gest->nb_segments == 2 && gest->nb_intersections == 2) {
- float s1[3], s2[3];
- float angle;
-
- sub_v3_v3v3(s1, gest->segments->points[1].p, gest->segments->points[0].p);
- sub_v3_v3v3(s2, gest->segments->points[2].p, gest->segments->points[1].p);
-
- angle = RAD2DEGF(angle_v2v2(s1, s2));
-
- if (angle > 120) {
- return 1;
- }
- }
-
- return 0;
-}
-
-void sk_applyDeleteGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *sketch)
-{
- SK_Intersection *isect;
-
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- /* only delete strokes that are crossed twice */
- if (isect->next && isect->next->stroke == isect->stroke) {
- isect = isect->next;
-
- sk_removeStroke(sketch, isect->stroke);
- }
- }
-}
-
-int sk_detectMergeGesture(bContext *C, SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- ARegion *ar = CTX_wm_region(C);
- if (gest->nb_segments > 2 && gest->nb_intersections == 2) {
- int start_val[2], end_val[2];
- int dist;
-
- if ((ED_view3d_project_int_global(ar, gest->stk->points[0].p, start_val, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) &&
- (ED_view3d_project_int_global(ar, sk_lastStrokePoint(gest->stk)->p, end_val, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK))
- {
- dist = len_manhattan_v2v2_int(start_val, end_val);
-
- /* if gesture is a circle */
- if (dist <= 20) {
- SK_Intersection *isect;
-
- /* check if it circled around an exact point */
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- /* only delete strokes that are crossed twice */
- if (isect->next && isect->next->stroke == isect->stroke) {
- int start_index, end_index;
- int i;
-
- start_index = MIN2(isect->after, isect->next->after);
- end_index = MAX2(isect->before, isect->next->before);
-
- for (i = start_index; i <= end_index; i++) {
- if (isect->stroke->points[i].type == PT_EXACT) {
- return 1; /* at least one exact point found, stop detect here */
- }
- }
-
- /* skip next */
- isect = isect->next;
- }
- }
- }
- }
- }
-
- return 0;
-}
-
-void sk_applyMergeGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- SK_Intersection *isect;
-
- /* check if it circled around an exact point */
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- /* only merge strokes that are crossed twice */
- if (isect->next && isect->next->stroke == isect->stroke) {
- int start_index, end_index;
- int i;
-
- start_index = MIN2(isect->after, isect->next->after);
- end_index = MAX2(isect->before, isect->next->before);
-
- for (i = start_index; i <= end_index; i++) {
- /* if exact, switch to continuous */
- if (isect->stroke->points[i].type == PT_EXACT) {
- isect->stroke->points[i].type = PT_CONTINUOUS;
- }
- }
-
- /* skip next */
- isect = isect->next;
- }
- }
-}
-
-int sk_detectReverseGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- if (gest->nb_segments > 2 && gest->nb_intersections == 2 && gest->nb_self_intersections == 0) {
- SK_Intersection *isect;
-
- /* check if it circled around an exact point */
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- /* only delete strokes that are crossed twice */
- if (isect->next && isect->next->stroke == isect->stroke) {
- float start_v[3], end_v[3];
- float angle;
-
- if (isect->gesture_index < isect->next->gesture_index) {
- sub_v3_v3v3(start_v, isect->p, gest->stk->points[0].p);
- sub_v3_v3v3(end_v, sk_lastStrokePoint(gest->stk)->p, isect->next->p);
- }
- else {
- sub_v3_v3v3(start_v, isect->next->p, gest->stk->points[0].p);
- sub_v3_v3v3(end_v, sk_lastStrokePoint(gest->stk)->p, isect->p);
- }
-
- angle = RAD2DEGF(angle_v2v2(start_v, end_v));
-
- if (angle > 120) {
- return 1;
- }
-
- /* skip next */
- isect = isect->next;
- }
- }
- }
-
- return 0;
-}
-
-void sk_applyReverseGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- SK_Intersection *isect;
-
- for (isect = gest->intersections.first; isect; isect = isect->next) {
- /* only reverse strokes that are crossed twice */
- if (isect->next && isect->next->stroke == isect->stroke) {
- sk_reverseStroke(isect->stroke);
-
- /* skip next */
- isect = isect->next;
- }
- }
-}
-
-int sk_detectConvertGesture(bContext *UNUSED(C), SK_Gesture *gest, SK_Sketch *UNUSED(sketch))
-{
- if (gest->nb_segments == 3 && gest->nb_self_intersections == 1) {
- return 1;
- }
- return 0;
-}
-
-void sk_applyConvertGesture(bContext *C, SK_Gesture *UNUSED(gest), SK_Sketch *sketch)
-{
- sk_convert(C, sketch);
-}
-
-static void sk_initGesture(bContext *C, SK_Gesture *gest, SK_Sketch *sketch)
-{
- BLI_listbase_clear(&gest->intersections);
- BLI_listbase_clear(&gest->self_intersections);
-
- gest->segments = sk_createStroke();
- gest->stk = sketch->gesture;
-
- gest->nb_self_intersections = sk_getSelfIntersections(C, &gest->self_intersections, gest->stk);
- gest->nb_intersections = sk_getIntersections(C, &gest->intersections, sketch, gest->stk);
- gest->nb_segments = sk_getSegments(gest->segments, gest->stk);
-}
-
-static void sk_freeGesture(SK_Gesture *gest)
-{
- sk_freeStroke(gest->segments);
- BLI_freelistN(&gest->intersections);
- BLI_freelistN(&gest->self_intersections);
-}
-
-static void sk_applyGesture(bContext *C, SK_Sketch *sketch)
-{
- SK_Gesture gest;
- SK_GestureAction *act;
-
- sk_initGesture(C, &gest, sketch);
-
- /* detect and apply */
- for (act = GESTURE_ACTIONS; act->apply != NULL; act++) {
- if (act->detect(C, &gest, sketch)) {
- act->apply(C, &gest, sketch);
- break;
- }
- }
-
- sk_freeGesture(&gest);
-}
-
-/********************************************/
-
-
-static bool sk_selectStroke(bContext *C, SK_Sketch *sketch, const int mval[2], const bool extend)
-{
- ViewContext vc;
- rcti rect;
- unsigned int buffer[MAXPICKBUF];
- short hits;
-
- ED_view3d_viewcontext_init(C, &vc);
-
- BLI_rcti_init_pt_radius(&rect, mval, 5);
-
- hits = view3d_opengl_select(&vc, buffer, MAXPICKBUF, &rect, VIEW3D_SELECT_PICK_NEAREST);
-
- if (hits > 0) {
- int besthitresult = -1;
-
- if (hits == 1) {
- besthitresult = buffer[3];
- }
- else {
- besthitresult = buffer[3];
- /* loop and get best hit */
- }
-
- if (besthitresult > 0) {
- SK_Stroke *selected_stk = BLI_findlink(&sketch->strokes, besthitresult - 1);
-
- if (extend == 0) {
- sk_selectAllSketch(sketch, -1);
-
- selected_stk->selected = 1;
- }
- else {
- selected_stk->selected ^= 1;
- }
-
-
- }
- return 1;
- }
-
- return 0;
-}
-
-#if 0 /* UNUSED 2.5 */
-static void sk_queueRedrawSketch(SK_Sketch *sketch)
-{
- if (sketch->active_stroke != NULL)
- {
- SK_Point *last = sk_lastStrokePoint(sketch->active_stroke);
-
- if (last != NULL)
- {
-// XXX
-// allqueue(REDRAWVIEW3D, 0);
- }
- }
-}
-#endif
-
-static void sk_drawSketch(Scene *scene, View3D *UNUSED(v3d), SK_Sketch *sketch, int with_names)
-{
- ToolSettings *ts = scene->toolsettings;
- SK_Stroke *stk;
-
- glClear(GL_DEPTH_BUFFER_BIT);
- glEnable(GL_DEPTH_TEST);
-
- if (with_names) {
- int id;
- for (id = 1, stk = sketch->strokes.first; stk; id++, stk = stk->next) {
- sk_drawStroke(stk, id, NULL, -1, -1);
- }
-
- GPU_select_load_id(-1);
- }
- else {
- float selected_rgb[3] = {1, 0, 0};
- float unselected_rgb[3] = {1, 0.5, 0};
-
- for (stk = sketch->strokes.first; stk; stk = stk->next) {
- int start = -1;
- int end = -1;
-
- if (sk_hasOverdraw(sketch, stk)) {
- sk_adjustIndexes(sketch, &start, &end);
- }
-
- sk_drawStroke(stk, -1, (stk->selected == 1 ? selected_rgb : unselected_rgb), start, end);
-
- if (stk->selected == 1) {
- sk_drawStrokeSubdivision(ts, stk);
- }
- }
-
- if (sketch->active_stroke != NULL) {
- SK_Point *last = sk_lastStrokePoint(sketch->active_stroke);
-
- if (ts->bone_sketching & BONE_SKETCHING_QUICK) {
- sk_drawStrokeSubdivision(ts, sketch->active_stroke);
- }
-
- if (last != NULL) {
- GLUquadric *quad = gluNewQuadric();
- gluQuadricNormals(quad, GLU_SMOOTH);
-
- glPushMatrix();
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- switch (sketch->next_point.mode) {
- case PT_SNAP:
- glColor3f(0, 1, 0);
- break;
- case PT_PROJECT:
- glColor3f(0, 0, 0);
- break;
- }
-
- sk_drawPoint(quad, &sketch->next_point, 0.1);
-
- glColor4f(selected_rgb[0], selected_rgb[1], selected_rgb[2], 0.3);
-
- sk_drawEdge(quad, last, &sketch->next_point, 0.1);
-
- glDisable(GL_BLEND);
-
- glPopMatrix();
-
- gluDeleteQuadric(quad);
- }
- }
- }
-
-#if 0
- if (BLI_listbase_is_empty(&sketch->depth_peels) == false) {
- float colors[8][3] = {
- {1, 0, 0},
- {0, 1, 0},
- {0, 0, 1},
- {1, 1, 0},
- {1, 0, 1},
- {0, 1, 1},
- {1, 1, 1},
- {0, 0, 0}
- };
- DepthPeel *p;
- GLUquadric *quad = gluNewQuadric();
- gluQuadricNormals(quad, GLU_SMOOTH);
-
- for (p = sketch->depth_peels.first; p; p = p->next)
- {
- int index = GET_INT_FROM_POINTER(p->ob);
- index = (index >> 5) & 7;
-
- glColor3fv(colors[index]);
- glPushMatrix();
- glTranslate3fv(p->p);
- gluSphere(quad, 0.02, 8, 8);
- glPopMatrix();
- }
-
- gluDeleteQuadric(quad);
- }
-#endif
-
- glDisable(GL_DEPTH_TEST);
-
- /* only draw gesture in active area */
- if (sketch->gesture != NULL /* && area_is_active_area(G.vd->area) */) {
- float gesture_rgb[3] = {0, 0.5, 1};
- sk_drawStroke(sketch->gesture, -1, gesture_rgb, -1, -1);
- }
-}
-
-static int sk_finish_stroke(bContext *C, SK_Sketch *sketch)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
-
- if (sketch->active_stroke != NULL) {
- SK_Stroke *stk = sketch->active_stroke;
-
- sk_endStroke(C, sketch);
-
- if (ts->bone_sketching & BONE_SKETCHING_QUICK) {
- if (ts->bone_sketching_convert == SK_CONVERT_RETARGET) {
- sk_retargetStroke(C, stk);
- }
- else {
- sk_convertStroke(C, stk);
- }
-// XXX
-// BIF_undo_push("Convert Sketch");
- sk_removeStroke(sketch, stk);
-// XXX
-// allqueue(REDRAWBUTSEDIT, 0);
- }
-
-// XXX
-// allqueue(REDRAWVIEW3D, 0);
- return 1;
- }
-
- return 0;
-}
-
-static void sk_start_draw_stroke(SK_Sketch *sketch)
-{
- if (sketch->active_stroke == NULL) {
- sk_startStroke(sketch);
- sk_selectAllSketch(sketch, -1);
-
- sketch->active_stroke->selected = 1;
- }
-}
-
-static void sk_start_draw_gesture(SK_Sketch *sketch)
-{
- sketch->gesture = sk_createStroke();
-}
-
-static int sk_draw_stroke(bContext *C, SK_Sketch *sketch, SK_Stroke *stk, SK_DrawData *dd, bool snap)
-{
- if (sk_stroke_filtermval(dd)) {
- sk_addStrokePoint(C, sketch, stk, dd, snap);
- sk_updateDrawData(dd);
- sk_updateNextPoint(sketch, stk);
-
- return 1;
- }
-
- return 0;
-}
-
-static int ValidSketchViewContext(ViewContext *vc)
-{
- Object *obedit = vc->obedit;
- Scene *scene = vc->scene;
-
- if (obedit &&
- obedit->type == OB_ARMATURE &&
- scene->toolsettings->bone_sketching & BONE_SKETCHING)
- {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-int BDR_drawSketchNames(ViewContext *vc)
-{
- if (ValidSketchViewContext(vc)) {
- SK_Sketch *sketch = viewcontextSketch(vc, 0);
- if (sketch) {
- sk_drawSketch(vc->scene, vc->v3d, sketch, 1);
- return 1;
- }
- }
-
- return 0;
-}
-
-void BDR_drawSketch(const bContext *C)
-{
- if (ED_operator_sketch_mode(C)) {
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch) {
- sk_drawSketch(CTX_data_scene(C), CTX_wm_view3d(C), sketch, 0);
- }
- }
-}
-
-static int sketch_delete(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
-{
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch) {
- sk_deleteSelectedStrokes(sketch);
-// allqueue(REDRAWVIEW3D, 0);
- }
- WM_event_add_notifier(C, NC_SCREEN | ND_SKETCH | NA_REMOVED, NULL);
- return OPERATOR_FINISHED;
-}
-
-bool BIF_sk_selectStroke(bContext *C, const int mval[2], const bool extend)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- SK_Sketch *sketch = contextSketch(C, 0);
-
- if (sketch != NULL && ts->bone_sketching & BONE_SKETCHING) {
- if (sk_selectStroke(C, sketch, mval, extend)) {
- ED_area_tag_redraw(CTX_wm_area(C));
- return true;
- }
- }
-
- return false;
-}
-
-void BIF_convertSketch(bContext *C)
-{
- if (ED_operator_sketch_full_mode(C)) {
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch) {
- sk_convert(C, sketch);
-// BIF_undo_push("Convert Sketch");
-// allqueue(REDRAWVIEW3D, 0);
-// allqueue(REDRAWBUTSEDIT, 0);
- }
- }
-}
-
-void BIF_deleteSketch(bContext *C)
-{
- if (ED_operator_sketch_full_mode(C)) {
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch) {
- sk_deleteSelectedStrokes(sketch);
-// BIF_undo_push("Convert Sketch");
-// allqueue(REDRAWVIEW3D, 0);
- }
- }
-}
-
-#if 0
-void BIF_selectAllSketch(bContext *C, int mode)
-{
- if (BIF_validSketchMode(C))
- {
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch)
- {
- sk_selectAllSketch(sketch, mode);
-// XXX
-// allqueue(REDRAWVIEW3D, 0);
- }
- }
-}
-#endif
-
-SK_Sketch *contextSketch(const bContext *C, int create)
-{
- Object *obedit = CTX_data_edit_object(C);
- SK_Sketch *sketch = NULL;
-
- if (obedit && obedit->type == OB_ARMATURE) {
- bArmature *arm = obedit->data;
-
- if (arm->sketch == NULL && create) {
- arm->sketch = createSketch();
- }
- sketch = arm->sketch;
- }
-
- return sketch;
-}
-
-SK_Sketch *viewcontextSketch(ViewContext *vc, int create)
-{
- Object *obedit = vc->obedit;
- SK_Sketch *sketch = NULL;
-
- if (obedit && obedit->type == OB_ARMATURE) {
- bArmature *arm = obedit->data;
-
- if (arm->sketch == NULL && create) {
- arm->sketch = createSketch();
- }
- sketch = arm->sketch;
- }
-
- return sketch;
-}
-
-static int sketch_convert(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
-{
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch != NULL) {
- sk_convert(C, sketch);
- ED_area_tag_redraw(CTX_wm_area(C));
- }
- return OPERATOR_FINISHED;
-}
-
-static int sketch_cancel_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
-{
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch != NULL) {
- sk_cancelStroke(sketch);
- ED_area_tag_redraw(CTX_wm_area(C));
- return OPERATOR_FINISHED;
- }
- return OPERATOR_PASS_THROUGH;
-}
-
-static int sketch_finish(bContext *C, wmOperator *UNUSED(op), const wmEvent *UNUSED(event))
-{
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch != NULL) {
- if (sk_finish_stroke(C, sketch)) {
- ED_area_tag_redraw(CTX_wm_area(C));
- return OPERATOR_FINISHED;
- }
- }
- return OPERATOR_PASS_THROUGH;
-}
-
-static int sketch_select(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
-{
- SK_Sketch *sketch = contextSketch(C, 0);
- if (sketch) {
- short extend = 0;
- if (sk_selectStroke(C, sketch, event->mval, extend))
- ED_area_tag_redraw(CTX_wm_area(C));
- }
-
- return OPERATOR_FINISHED;
-}
-
-static void sketch_draw_stroke_cancel(bContext *C, wmOperator *op)
-{
- SK_Sketch *sketch = contextSketch(C, 1); /* create just to be sure */
- sk_cancelStroke(sketch);
- MEM_freeN(op->customdata);
-}
-
-static int sketch_draw_stroke(bContext *C, wmOperator *op, const wmEvent *event)
-{
- const bool snap = RNA_boolean_get(op->ptr, "snap");
- SK_DrawData *dd;
- SK_Sketch *sketch = contextSketch(C, 1);
-
- op->customdata = dd = MEM_callocN(sizeof(SK_DrawData), "SketchDrawData");
- sk_initDrawData(dd, event->mval);
-
- sk_start_draw_stroke(sketch);
-
- sk_draw_stroke(C, sketch, sketch->active_stroke, dd, snap);
-
- WM_event_add_modal_handler(C, op);
-
- return OPERATOR_RUNNING_MODAL;
-}
-
-static void sketch_draw_gesture_cancel(bContext *C, wmOperator *op)
-{
- SK_Sketch *sketch = contextSketch(C, 1); /* create just to be sure */
- sk_cancelStroke(sketch);
- MEM_freeN(op->customdata);
-}
-
-static int sketch_draw_gesture(bContext *C, wmOperator *op, const wmEvent *event)
-{
- const bool snap = RNA_boolean_get(op->ptr, "snap");
- SK_DrawData *dd;
- SK_Sketch *sketch = contextSketch(C, 1); /* create just to be sure */
- sk_cancelStroke(sketch);
-
- op->customdata = dd = MEM_callocN(sizeof(SK_DrawData), "SketchDrawData");
- sk_initDrawData(dd, event->mval);
-
- sk_start_draw_gesture(sketch);
- sk_draw_stroke(C, sketch, sketch->gesture, dd, snap);
-
- WM_event_add_modal_handler(C, op);
-
- return OPERATOR_RUNNING_MODAL;
-}
-
-static int sketch_draw_modal(bContext *C, wmOperator *op, const wmEvent *event, short gesture, SK_Stroke *stk)
-{
- bool snap = RNA_boolean_get(op->ptr, "snap");
- SK_DrawData *dd = op->customdata;
- SK_Sketch *sketch = contextSketch(C, 1); /* create just to be sure */
- int retval = OPERATOR_RUNNING_MODAL;
-
- switch (event->type) {
- case LEFTCTRLKEY:
- case RIGHTCTRLKEY:
- snap = event->ctrl != 0;
- RNA_boolean_set(op->ptr, "snap", snap);
- break;
- case MOUSEMOVE:
- case INBETWEEN_MOUSEMOVE:
- dd->mval[0] = event->mval[0];
- dd->mval[1] = event->mval[1];
- sk_draw_stroke(C, sketch, stk, dd, snap);
- ED_area_tag_redraw(CTX_wm_area(C));
- break;
- case ESCKEY:
- op->type->cancel(C, op);
- ED_area_tag_redraw(CTX_wm_area(C));
- retval = OPERATOR_CANCELLED;
- break;
- case LEFTMOUSE:
- if (event->val == KM_RELEASE) {
- if (gesture == 0) {
- sk_endContinuousStroke(stk);
- sk_filterLastContinuousStroke(stk);
- sk_updateNextPoint(sketch, stk);
- ED_area_tag_redraw(CTX_wm_area(C));
- MEM_freeN(op->customdata);
- retval = OPERATOR_FINISHED;
- }
- else {
- sk_endContinuousStroke(stk);
- sk_filterLastContinuousStroke(stk);
-
- if (stk->nb_points > 1) {
- /* apply gesture here */
- sk_applyGesture(C, sketch);
- }
-
- sk_freeStroke(stk);
- sketch->gesture = NULL;
-
- ED_area_tag_redraw(CTX_wm_area(C));
- MEM_freeN(op->customdata);
- retval = OPERATOR_FINISHED;
- }
- }
- break;
- }
-
- return retval;
-}
-
-static int sketch_draw_stroke_modal(bContext *C, wmOperator *op, const wmEvent *event)
-{
- SK_Sketch *sketch = contextSketch(C, 1); /* create just to be sure */
- return sketch_draw_modal(C, op, event, 0, sketch->active_stroke);
-}
-
-static int sketch_draw_gesture_modal(bContext *C, wmOperator *op, const wmEvent *event)
-{
- SK_Sketch *sketch = contextSketch(C, 1); /* create just to be sure */
- return sketch_draw_modal(C, op, event, 1, sketch->gesture);
-}
-
-static int sketch_draw_preview(bContext *C, wmOperator *op, const wmEvent *event)
-{
- const bool snap = RNA_boolean_get(op->ptr, "snap");
- SK_Sketch *sketch = contextSketch(C, 0);
-
- if (sketch) {
- SK_DrawData dd;
-
- sk_initDrawData(&dd, event->mval);
- sk_getStrokePoint(C, &sketch->next_point, sketch, sketch->active_stroke, &dd, snap);
- ED_area_tag_redraw(CTX_wm_area(C));
- }
-
- return OPERATOR_FINISHED | OPERATOR_PASS_THROUGH;
-}
-
-/* ============================================== Poll Functions ============================================= */
-
-int ED_operator_sketch_mode_active_stroke(bContext *C)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- SK_Sketch *sketch = contextSketch(C, 0);
-
- if (ts->bone_sketching & BONE_SKETCHING &&
- sketch != NULL &&
- sketch->active_stroke != NULL)
- {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-static int ED_operator_sketch_mode_gesture(bContext *C)
-{
- ToolSettings *ts = CTX_data_tool_settings(C);
- SK_Sketch *sketch = contextSketch(C, 0);
-
- if (ts->bone_sketching & BONE_SKETCHING &&
- (ts->bone_sketching & BONE_SKETCHING_QUICK) == 0 &&
- sketch != NULL &&
- sketch->active_stroke == NULL)
- {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-int ED_operator_sketch_full_mode(bContext *C)
-{
- Object *obedit = CTX_data_edit_object(C);
- ToolSettings *ts = CTX_data_tool_settings(C);
-
- if (obedit &&
- obedit->type == OB_ARMATURE &&
- ts->bone_sketching & BONE_SKETCHING &&
- (ts->bone_sketching & BONE_SKETCHING_QUICK) == 0)
- {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-int ED_operator_sketch_mode(const bContext *C)
-{
- Object *obedit = CTX_data_edit_object(C);
- ToolSettings *ts = CTX_data_tool_settings(C);
-
- if (obedit &&
- obedit->type == OB_ARMATURE &&
- ts->bone_sketching & BONE_SKETCHING)
- {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-/* ================================================ Operators ================================================ */
-
-void SKETCH_OT_delete(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Delete";
- ot->idname = "SKETCH_OT_delete";
- ot->description = "Delete a sketch stroke";
-
- /* api callbacks */
- ot->invoke = sketch_delete;
-
- ot->poll = ED_operator_sketch_full_mode;
-
- /* flags */
-// ot->flag = OPTYPE_UNDO;
-}
-
-void SKETCH_OT_select(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Select";
- ot->idname = "SKETCH_OT_select";
- ot->description = "Select a sketch stroke";
-
- /* api callbacks */
- ot->invoke = sketch_select;
-
- ot->poll = ED_operator_sketch_full_mode;
-
- /* flags */
-// ot->flag = OPTYPE_UNDO;
-}
-
-void SKETCH_OT_cancel_stroke(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Cancel Stroke";
- ot->idname = "SKETCH_OT_cancel_stroke";
- ot->description = "Cancel the current sketch stroke";
-
- /* api callbacks */
- ot->invoke = sketch_cancel_invoke;
-
- ot->poll = ED_operator_sketch_mode_active_stroke;
-
- /* flags */
-// ot->flag = OPTYPE_UNDO;
-}
-
-void SKETCH_OT_convert(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Convert";
- ot->idname = "SKETCH_OT_convert";
- ot->description = "Convert the selected sketch strokes to bone chains";
-
- /* api callbacks */
- ot->invoke = sketch_convert;
-
- ot->poll = ED_operator_sketch_full_mode;
-
- /* flags */
- ot->flag = OPTYPE_UNDO;
-}
-
-void SKETCH_OT_finish_stroke(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "End Stroke";
- ot->idname = "SKETCH_OT_finish_stroke";
- ot->description = "End and keep the current sketch stroke";
-
- /* api callbacks */
- ot->invoke = sketch_finish;
-
- ot->poll = ED_operator_sketch_mode_active_stroke;
-
- /* flags */
-// ot->flag = OPTYPE_UNDO;
-}
-
-void SKETCH_OT_draw_preview(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Draw Preview";
- ot->idname = "SKETCH_OT_draw_preview";
- ot->description = "Draw preview of current sketch stroke (internal use)";
-
- /* api callbacks */
- ot->invoke = sketch_draw_preview;
-
- ot->poll = ED_operator_sketch_mode_active_stroke;
-
- RNA_def_boolean(ot->srna, "snap", 0, "Snap", "");
-
- /* flags */
-// ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
-}
-
-void SKETCH_OT_draw_stroke(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Draw Stroke";
- ot->idname = "SKETCH_OT_draw_stroke";
- ot->description = "Start to draw a sketch stroke";
-
- /* api callbacks */
- ot->invoke = sketch_draw_stroke;
- ot->modal = sketch_draw_stroke_modal;
- ot->cancel = sketch_draw_stroke_cancel;
-
- ot->poll = (int (*)(bContext *))ED_operator_sketch_mode;
-
- RNA_def_boolean(ot->srna, "snap", 0, "Snap", "");
-
- /* flags */
- ot->flag = OPTYPE_BLOCKING; // OPTYPE_REGISTER|OPTYPE_UNDO
-}
-
-void SKETCH_OT_gesture(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Gesture";
- ot->idname = "SKETCH_OT_gesture";
- ot->description = "Start to draw a gesture stroke";
-
- /* api callbacks */
- ot->invoke = sketch_draw_gesture;
- ot->modal = sketch_draw_gesture_modal;
- ot->cancel = sketch_draw_gesture_cancel;
-
- ot->poll = ED_operator_sketch_mode_gesture;
-
- RNA_def_boolean(ot->srna, "snap", 0, "Snap", "");
-
- /* flags */
- ot->flag = OPTYPE_BLOCKING; // OPTYPE_UNDO
-}
-
diff --git a/source/blender/editors/armature/editarmature_undo.c b/source/blender/editors/armature/editarmature_undo.c
index f27d68d0634..f6f97af32b9 100644
--- a/source/blender/editors/armature/editarmature_undo.c
+++ b/source/blender/editors/armature/editarmature_undo.c
@@ -27,25 +27,34 @@
* \ingroup edarmature
*/
+#include "MEM_guardedalloc.h"
+
+
+#include "CLG_log.h"
+
#include "DNA_armature_types.h"
#include "DNA_object_types.h"
-#include "MEM_guardedalloc.h"
-
#include "BLI_math.h"
#include "BLI_array_utils.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_armature.h"
#include "ED_object.h"
+#include "ED_undo.h"
#include "ED_util.h"
#include "WM_types.h"
#include "WM_api.h"
+/** We only need this locally. */
+static CLG_LogRef LOG = {"ed.undo.armature"};
+
/* -------------------------------------------------------------------- */
/** \name Undo Conversion
* \{ */
@@ -120,13 +129,20 @@ static Object *editarm_object_from_context(bContext *C)
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
+ *
+ * \note This is similar for all edit-mode types.
* \{ */
-typedef struct ArmatureUndoStep {
- UndoStep step;
- /* note: will split out into list for multi-object-editmode. */
+typedef struct ArmatureUndoStep_Elem {
+ struct ArmatureUndoStep_Elem *next, *prev;
UndoRefID_Object obedit_ref;
UndoArmature data;
+} ArmatureUndoStep_Elem;
+
+typedef struct ArmatureUndoStep {
+ UndoStep step;
+ ArmatureUndoStep_Elem *elems;
+ uint elems_len;
} ArmatureUndoStep;
static bool armature_undosys_poll(bContext *C)
@@ -137,10 +153,24 @@ static bool armature_undosys_poll(bContext *C)
static bool armature_undosys_step_encode(struct bContext *C, UndoStep *us_p)
{
ArmatureUndoStep *us = (ArmatureUndoStep *)us_p;
- us->obedit_ref.ptr = editarm_object_from_context(C);
- bArmature *arm = us->obedit_ref.ptr->data;
- undoarm_from_editarm(&us->data, arm);
- us->step.data_size = us->data.undo_size;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__);
+ us->elems_len = objects_len;
+
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ ArmatureUndoStep_Elem *elem = &us->elems[i];
+
+ elem->obedit_ref.ptr = ob;
+ bArmature *arm = elem->obedit_ref.ptr->data;
+ undoarm_from_editarm(&elem->data, arm);
+ us->step.data_size += elem->data.undo_size;
+ }
+ MEM_freeN(objects);
return true;
}
@@ -151,24 +181,46 @@ static void armature_undosys_step_decode(struct bContext *C, UndoStep *us_p, int
BLI_assert(armature_undosys_poll(C));
ArmatureUndoStep *us = (ArmatureUndoStep *)us_p;
- Object *obedit = us->obedit_ref.ptr;
- bArmature *arm = obedit->data;
- undoarm_to_editarm(&us->data, arm);
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ ArmatureUndoStep_Elem *elem = &us->elems[i];
+ Object *obedit = elem->obedit_ref.ptr;
+ bArmature *arm = obedit->data;
+ if (arm->edbo == NULL) {
+ /* Should never fail, may not crash but can give odd behavior. */
+ CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", us_p->name, obedit->id.name);
+ continue;
+ }
+ undoarm_to_editarm(&elem->data, arm);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ }
+
+ /* The first element is always active */
+ ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
+
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
static void armature_undosys_step_free(UndoStep *us_p)
{
ArmatureUndoStep *us = (ArmatureUndoStep *)us_p;
- undoarm_free_data(&us->data);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ ArmatureUndoStep_Elem *elem = &us->elems[i];
+ undoarm_free_data(&elem->data);
+ }
+ MEM_freeN(us->elems);
}
static void armature_undosys_foreach_ID_ref(
UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
{
ArmatureUndoStep *us = (ArmatureUndoStep *)us_p;
- foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref));
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ ArmatureUndoStep_Elem *elem = &us->elems[i];
+ foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref));
+ }
}
/* Export for ED_undo_sys. */
diff --git a/source/blender/editors/armature/meshlaplacian.c b/source/blender/editors/armature/meshlaplacian.c
index 1c8e547b961..eaae7dacbba 100644
--- a/source/blender/editors/armature/meshlaplacian.c
+++ b/source/blender/editors/armature/meshlaplacian.c
@@ -46,6 +46,8 @@
#include "ED_mesh.h"
#include "ED_armature.h"
+#include "DEG_depsgraph.h"
+
#include "eigen_capi.h"
#include "meshlaplacian.h"
@@ -600,9 +602,10 @@ static float heat_limit_weight(float weight)
return weight;
}
-void heat_bone_weighting(Object *ob, Mesh *me, float (*verts)[3], int numsource,
- bDeformGroup **dgrouplist, bDeformGroup **dgroupflip,
- float (*root)[3], float (*tip)[3], int *selected, const char **err_str)
+void heat_bone_weighting(
+ Object *ob, Mesh *me, float (*verts)[3], int numsource,
+ bDeformGroup **dgrouplist, bDeformGroup **dgroupflip,
+ float (*root)[3], float (*tip)[3], int *selected, const char **err_str)
{
LaplacianSystem *sys;
MLoopTri *mlooptri;
diff --git a/source/blender/editors/armature/meshlaplacian.h b/source/blender/editors/armature/meshlaplacian.h
index 202ac8e9b70..9c4ceacbee6 100644
--- a/source/blender/editors/armature/meshlaplacian.h
+++ b/source/blender/editors/armature/meshlaplacian.h
@@ -52,10 +52,11 @@ float laplacian_system_get_solution(LaplacianSystem *sys, int v);
/* Heat Weighting */
-void heat_bone_weighting(struct Object *ob, struct Mesh *me, float (*verts)[3],
- int numbones, struct bDeformGroup **dgrouplist,
- struct bDeformGroup **dgroupflip, float (*root)[3], float (*tip)[3],
- int *selected, const char **error);
+void heat_bone_weighting(
+ struct Object *ob, struct Mesh *me, float (*verts)[3],
+ int numbones, struct bDeformGroup **dgrouplist,
+ struct bDeformGroup **dgroupflip, float (*root)[3], float (*tip)[3],
+ int *selected, const char **error);
#ifdef RIGID_DEFORM
/* As-Rigid-As-Possible Deformation */
diff --git a/source/blender/editors/armature/pose_edit.c b/source/blender/editors/armature/pose_edit.c
index d0c467b2d2c..4d29bef63ee 100644
--- a/source/blender/editors/armature/pose_edit.c
+++ b/source/blender/editors/armature/pose_edit.c
@@ -31,6 +31,8 @@
* \ingroup edarmature
*/
+#include "MEM_guardedalloc.h"
+
#include "BLI_math.h"
#include "BLI_blenlib.h"
@@ -39,13 +41,16 @@
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
+#include "BKE_action.h"
#include "BKE_anim.h"
#include "BKE_armature.h"
#include "BKE_context.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_object.h"
#include "BKE_report.h"
+#include "BKE_layer.h"
+
+#include "DEG_depsgraph.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -81,7 +86,7 @@ Object *ED_pose_object_from_context(bContext *C)
}
/* This function is used to process the necessary updates for */
-bool ED_object_posemode_enter_ex(Object *ob)
+bool ED_object_posemode_enter_ex(struct Main *bmain, Object *ob)
{
BLI_assert(!ID_IS_LINKED(ob));
bool ok = false;
@@ -90,6 +95,8 @@ bool ED_object_posemode_enter_ex(Object *ob)
case OB_ARMATURE:
ob->restore_mode = ob->mode;
ob->mode |= OB_MODE_POSE;
+ /* Inform all CoW versions that we changed the mode. */
+ DEG_id_tag_update_ex(bmain, &ob->id, DEG_TAG_COPY_ON_WRITE);
ok = true;
break;
@@ -106,26 +113,31 @@ bool ED_object_posemode_enter(bContext *C, Object *ob)
BKE_report(reports, RPT_WARNING, "Cannot pose libdata");
return false;
}
- bool ok = ED_object_posemode_enter_ex(ob);
+ struct Main *bmain = CTX_data_main(C);
+ bool ok = ED_object_posemode_enter_ex(bmain, ob);
if (ok) {
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_POSE, NULL);
}
return ok;
}
-bool ED_object_posemode_exit_ex(Object *ob)
+bool ED_object_posemode_exit_ex(struct Main *bmain, Object *ob)
{
bool ok = false;
if (ob) {
ob->restore_mode = ob->mode;
ob->mode &= ~OB_MODE_POSE;
+
+ /* Inform all CoW versions that we changed the mode. */
+ DEG_id_tag_update_ex(bmain, &ob->id, DEG_TAG_COPY_ON_WRITE);
ok = true;
}
return ok;
}
bool ED_object_posemode_exit(bContext *C, Object *ob)
{
- bool ok = ED_object_posemode_exit_ex(ob);
+ struct Main *bmain = CTX_data_main(C);
+ bool ok = ED_object_posemode_exit_ex(bmain, ob);
if (ok) {
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL);
}
@@ -167,8 +179,10 @@ static bool pose_has_protected_selected(Object *ob, short warn)
*
* To be called from various tools that do incremental updates
*/
-void ED_pose_recalculate_paths(Scene *scene, Object *ob)
+void ED_pose_recalculate_paths(bContext *C, Scene *scene, Object *ob)
{
+ struct Main *bmain = CTX_data_main(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
ListBase targets = {NULL, NULL};
/* set flag to force recalc, then grab the relevant bones to target */
@@ -176,7 +190,7 @@ void ED_pose_recalculate_paths(Scene *scene, Object *ob)
animviz_get_object_motionpaths(ob, &targets);
/* recalculate paths, then free */
- animviz_calc_motionpaths(scene, &targets);
+ animviz_calc_motionpaths(depsgraph, bmain, scene, &targets);
BLI_freelistN(&targets);
}
@@ -239,7 +253,7 @@ static int pose_calculate_paths_exec(bContext *C, wmOperator *op)
/* calculate the bones that now have motionpaths... */
/* TODO: only make for the selected bones? */
- ED_pose_recalculate_paths(scene, ob);
+ ED_pose_recalculate_paths(C, scene, ob);
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
@@ -295,7 +309,7 @@ static int pose_update_paths_exec(bContext *C, wmOperator *UNUSED(op))
/* calculate the bones that now have motionpaths... */
/* TODO: only make for the selected bones? */
- ED_pose_recalculate_paths(scene, ob);
+ ED_pose_recalculate_paths(C, scene, ob);
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
@@ -593,7 +607,7 @@ static void pose_copy_menu(Scene *scene)
BKE_pose_tag_recalc(bmain, ob->pose);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA); // and all its relations
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA); // and all its relations
BIF_undo_push("Copy Pose Attributes");
@@ -604,34 +618,31 @@ static void pose_copy_menu(Scene *scene)
static int pose_flip_names_exec(bContext *C, wmOperator *op)
{
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
- bArmature *arm;
-
- /* paranoia checks */
- if (ELEM(NULL, ob, ob->pose))
- return OPERATOR_CANCELLED;
-
+ ViewLayer *view_layer = CTX_data_view_layer(C);
const bool do_strip_numbers = RNA_boolean_get(op->ptr, "do_strip_numbers");
-
- arm = ob->data;
-
- ListBase bones_names = {NULL};
-
- CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones)
+
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob)
{
- BLI_addtail(&bones_names, BLI_genericNodeN(pchan->name));
- }
- CTX_DATA_END;
+ bArmature *arm = ob->data;
+ ListBase bones_names = {NULL};
- ED_armature_bones_flip_names(arm, &bones_names, do_strip_numbers);
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob, pchan)
+ {
+ BLI_addtail(&bones_names, BLI_genericNodeN(pchan->name));
+ }
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
- BLI_freelistN(&bones_names);
-
- /* since we renamed stuff... */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ ED_armature_bones_flip_names(arm, &bones_names, do_strip_numbers);
- /* note, notifier might evolve */
- WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ BLI_freelistN(&bones_names);
+
+ /* since we renamed stuff... */
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+
+ /* note, notifier might evolve */
+ WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ }
+ FOREACH_OBJECT_IN_MODE_END;
return OPERATOR_FINISHED;
}
@@ -679,7 +690,7 @@ static int pose_autoside_names_exec(bContext *C, wmOperator *op)
CTX_DATA_END;
/* since we renamed stuff... */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* note, notifier might evolve */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
@@ -728,7 +739,7 @@ static int pose_bone_rotmode_exec(bContext *C, wmOperator *op)
CTX_DATA_END;
/* notifiers and updates */
- DAG_id_tag_update((ID *)ob, OB_RECALC_DATA);
+ DEG_id_tag_update((ID *)ob, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
return OPERATOR_FINISHED;
@@ -1004,7 +1015,6 @@ static int armature_bone_layers_invoke(bContext *C, wmOperator *op, const wmEven
static int armature_bone_layers_exec(bContext *C, wmOperator *op)
{
Object *ob = CTX_data_edit_object(C);
- bArmature *arm = (ob) ? ob->data : NULL;
PointerRNA ptr;
int layers[32]; /* hardcoded for now - we can only have 32 armature layers, so this should be fine... */
@@ -1012,7 +1022,7 @@ static int armature_bone_layers_exec(bContext *C, wmOperator *op)
RNA_boolean_get_array(op->ptr, "layers", layers);
/* set layers of pchans based on the values set in the operator props */
- CTX_DATA_BEGIN (C, EditBone *, ebone, selected_editable_bones)
+ CTX_DATA_BEGIN_WITH_ID (C, EditBone *, ebone, selected_editable_bones, bArmature *, arm)
{
/* get pointer for pchan, and write flags this way */
RNA_pointer_create((ID *)arm, &RNA_EditBone, ebone, &ptr);
@@ -1048,55 +1058,54 @@ void ARMATURE_OT_bone_layers(wmOperatorType *ot)
/* ********************************************** */
/* Show/Hide Bones */
-static int hide_selected_pose_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr))
+static int hide_pose_bone_fn(Object *ob, Bone *bone, void *ptr)
{
bArmature *arm = ob->data;
-
+ const bool hide_select = (bool)GET_INT_FROM_POINTER(ptr);
+ int count = 0;
if (arm->layer & bone->layer) {
- if (bone->flag & BONE_SELECTED) {
+ if (((bone->flag & BONE_SELECTED) != 0) == hide_select) {
bone->flag |= BONE_HIDDEN_P;
+ /* only needed when 'hide_select' is true, but harmless. */
bone->flag &= ~BONE_SELECTED;
- if (arm->act_bone == bone)
- arm->act_bone = NULL;
- }
- }
- return 0;
-}
-
-static int hide_unselected_pose_bone_cb(Object *ob, Bone *bone, void *UNUSED(ptr))
-{
- bArmature *arm = ob->data;
-
- if (arm->layer & bone->layer) {
- /* hrm... typo here? */
- if ((bone->flag & BONE_SELECTED) == 0) {
- bone->flag |= BONE_HIDDEN_P;
- if (arm->act_bone == bone)
+ if (arm->act_bone == bone) {
arm->act_bone = NULL;
+ }
+ count += 1;
}
}
- return 0;
+ return count;
}
/* active object is armature in posemode, poll checked */
-static int pose_hide_exec(bContext *C, wmOperator *op)
+static int pose_hide_exec(bContext *C, wmOperator *op)
{
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
- bArmature *arm = ob->data;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len;
+ Object **objects = BKE_object_pose_array_get_unique(view_layer, &objects_len);
+ bool changed_multi = false;
+
+ const int hide_select = !RNA_boolean_get(op->ptr, "unselected");
+ void *hide_select_p = SET_INT_IN_POINTER(hide_select);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ bArmature *arm = ob_iter->data;
+
+ if (ob_iter->proxy != NULL) {
+ BKE_report(op->reports, RPT_INFO, "Undo of hiding can only be done with Reveal Selected");
+ }
- if (ob->proxy != NULL) {
- BKE_report(op->reports, RPT_INFO, "Undo of hiding can only be done with Reveal Selected");
+ bool changed = bone_looper(ob_iter, arm->bonebase.first, hide_select_p, hide_pose_bone_fn) != 0;
+ if (changed) {
+ changed_multi = true;
+ /* note, notifier might evolve */
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob_iter);
+ }
}
+ MEM_freeN(objects);
- if (RNA_boolean_get(op->ptr, "unselected"))
- bone_looper(ob, arm->bonebase.first, NULL, hide_unselected_pose_bone_cb);
- else
- bone_looper(ob, arm->bonebase.first, NULL, hide_selected_pose_bone_cb);
-
- /* note, notifier might evolve */
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
-
- return OPERATOR_FINISHED;
+ return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
void POSE_OT_hide(wmOperatorType *ot)
@@ -1122,32 +1131,44 @@ static int show_pose_bone_cb(Object *ob, Bone *bone, void *data)
const bool select = GET_INT_FROM_POINTER(data);
bArmature *arm = ob->data;
-
+ int count = 0;
if (arm->layer & bone->layer) {
if (bone->flag & BONE_HIDDEN_P) {
if (!(bone->flag & BONE_UNSELECTABLE)) {
SET_FLAG_FROM_TEST(bone->flag, select, BONE_SELECTED);
}
bone->flag &= ~BONE_HIDDEN_P;
+ count += 1;
}
}
-
- return 0;
+
+ return count;
}
/* active object is armature in posemode, poll checked */
-static int pose_reveal_exec(bContext *C, wmOperator *op)
+static int pose_reveal_exec(bContext *C, wmOperator *op)
{
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
- bArmature *arm = ob->data;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len;
+ Object **objects = BKE_object_pose_array_get_unique(view_layer, &objects_len);
+ bool changed_multi = false;
const bool select = RNA_boolean_get(op->ptr, "select");
-
- bone_looper(ob, arm->bonebase.first, SET_INT_IN_POINTER(select), show_pose_bone_cb);
-
- /* note, notifier might evolve */
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
+ void *select_p = SET_INT_IN_POINTER(select);
- return OPERATOR_FINISHED;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ bArmature *arm = ob_iter->data;
+
+ bool changed = bone_looper(ob_iter, arm->bonebase.first, select_p, show_pose_bone_cb);
+ if (changed) {
+ changed_multi = true;
+ /* note, notifier might evolve */
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob_iter);
+ }
+ }
+ MEM_freeN(objects);
+
+ return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
void POSE_OT_reveal(wmOperatorType *ot)
@@ -1173,27 +1194,34 @@ void POSE_OT_reveal(wmOperatorType *ot)
static int pose_flip_quats_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
KeyingSet *ks = ANIM_builtin_keyingset_get_named(NULL, ANIM_KS_LOC_ROT_SCALE_ID);
-
- /* loop through all selected pchans, flipping and keying (as needed) */
- CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones)
- {
- /* only if bone is using quaternion rotation */
- if (pchan->rotmode == ROT_MODE_QUAT) {
- /* quaternions have 720 degree range */
- negate_v4(pchan->quat);
- ED_autokeyframe_pchan(C, scene, ob, pchan, ks);
+ bool changed_multi = false;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob_iter) {
+ bool changed = false;
+ /* loop through all selected pchans, flipping and keying (as needed) */
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan) {
+ /* only if bone is using quaternion rotation */
+ if (pchan->rotmode == ROT_MODE_QUAT) {
+ changed = true;
+ /* quaternions have 720 degree range */
+ negate_v4(pchan->quat);
+
+ ED_autokeyframe_pchan(C, scene, ob_iter, pchan, ks);
+ }
+ } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
+
+ if (changed) {
+ changed_multi = true;
+ /* notifiers and updates */
+ DEG_id_tag_update(&ob_iter->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob_iter);
}
- }
- CTX_DATA_END;
-
- /* notifiers and updates */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
-
- return OPERATOR_FINISHED;
+ } FOREACH_OBJECT_IN_MODE_END;
+
+ return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
void POSE_OT_quaternions_flip(wmOperatorType *ot)
diff --git a/source/blender/editors/armature/pose_group.c b/source/blender/editors/armature/pose_group.c
index c9b1d8613a9..449383fb0b8 100644
--- a/source/blender/editors/armature/pose_group.c
+++ b/source/blender/editors/armature/pose_group.c
@@ -38,9 +38,12 @@
#include "DNA_armature_types.h"
#include "DNA_object_types.h"
+#include "BKE_armature.h"
#include "BKE_action.h"
#include "BKE_context.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -104,6 +107,7 @@ static int pose_group_remove_exec(bContext *C, wmOperator *UNUSED(op))
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
return OPERATOR_FINISHED;
}
@@ -204,15 +208,16 @@ static int pose_group_assign_exec(bContext *C, wmOperator *op)
BKE_pose_add_group(ob->pose, NULL);
/* add selected bones to group then */
- CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones)
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob, pchan)
{
pchan->agrp_index = pose->active_group;
done = true;
}
- CTX_DATA_END;
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
/* report done status */
if (done)
@@ -251,17 +256,18 @@ static int pose_group_unassign_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED;
/* find selected bones to remove from all bone groups */
- CTX_DATA_BEGIN (C, bPoseChannel *, pchan, selected_pose_bones)
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob, pchan)
{
if (pchan->agrp_index) {
pchan->agrp_index = 0;
done = true;
}
}
- CTX_DATA_END;
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
/* report done status */
if (done)
@@ -413,6 +419,7 @@ static int group_sort_exec(bContext *C, wmOperator *UNUSED(op))
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ DEG_id_tag_update(&ob->id, DEG_TAG_COPY_ON_WRITE);
return OPERATOR_FINISHED;
}
@@ -432,11 +439,11 @@ void POSE_OT_group_sort(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-static void pose_group_select(bContext *C, Object *ob, bool select)
+static void pose_group_select(Object *ob, bool select)
{
bPose *pose = ob->pose;
- CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones)
+ FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob, pchan)
{
if ((pchan->bone->flag & BONE_UNSELECTABLE) == 0) {
if (select) {
@@ -449,7 +456,7 @@ static void pose_group_select(bContext *C, Object *ob, bool select)
}
}
}
- CTX_DATA_END;
+ FOREACH_PCHAN_VISIBLE_IN_OBJECT_END;
}
static int pose_group_select_exec(bContext *C, wmOperator *UNUSED(op))
@@ -460,7 +467,7 @@ static int pose_group_select_exec(bContext *C, wmOperator *UNUSED(op))
if (ELEM(NULL, ob, ob->pose))
return OPERATOR_CANCELLED;
- pose_group_select(C, ob, 1);
+ pose_group_select(ob, 1);
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
@@ -491,7 +498,7 @@ static int pose_group_deselect_exec(bContext *C, wmOperator *UNUSED(op))
if (ELEM(NULL, ob, ob->pose))
return OPERATOR_CANCELLED;
- pose_group_select(C, ob, 0);
+ pose_group_select(ob, 0);
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
diff --git a/source/blender/editors/armature/pose_lib.c b/source/blender/editors/armature/pose_lib.c
index d9d5fa395d6..609281a7bf2 100644
--- a/source/blender/editors/armature/pose_lib.c
+++ b/source/blender/editors/armature/pose_lib.c
@@ -46,7 +46,6 @@
#include "BKE_animsys.h"
#include "BKE_action.h"
#include "BKE_armature.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_library.h"
@@ -55,6 +54,8 @@
#include "BKE_context.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -1101,9 +1102,9 @@ static void poselib_preview_apply(bContext *C, wmOperator *op)
*/
// FIXME: shouldn't this use the builtin stuff?
if ((pld->arm->flag & ARM_DELAYDEFORM) == 0)
- DAG_id_tag_update(&pld->ob->id, OB_RECALC_DATA); /* sets recalc flags */
+ DEG_id_tag_update(&pld->ob->id, OB_RECALC_DATA); /* sets recalc flags */
else
- BKE_pose_where_is(pld->scene, pld->ob);
+ BKE_pose_where_is(CTX_data_depsgraph(C), pld->scene, pld->ob);
}
/* do header print - if interactively previewing */
@@ -1609,9 +1610,9 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op)
* - note: code copied from transform_generics.c -> recalcData()
*/
if ((arm->flag & ARM_DELAYDEFORM) == 0)
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
else
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob);
}
else if (pld->state == PL_PREVIEW_CONFIRM) {
/* tag poses as appropriate */
@@ -1622,14 +1623,14 @@ static void poselib_preview_cleanup(bContext *C, wmOperator *op)
action_set_activemarker(act, marker, NULL);
/* Update event for pose and deformation children */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* updates */
if (IS_AUTOKEY_MODE(scene, NORMAL)) {
//remake_action_ipos(ob->action);
}
else
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(CTX_data_depsgraph(C), scene, ob);
}
/* Request final redraw of the view. */
diff --git a/source/blender/editors/armature/pose_select.c b/source/blender/editors/armature/pose_select.c
index 4b62fd15c04..9207a55b380 100644
--- a/source/blender/editors/armature/pose_select.c
+++ b/source/blender/editors/armature/pose_select.c
@@ -43,9 +43,11 @@
#include "BKE_armature.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_object.h"
#include "BKE_report.h"
+#include "BKE_layer.h"
+
+#include "DEG_depsgraph.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -122,18 +124,21 @@ void ED_pose_bone_select(Object *ob, bPoseChannel *pchan, bool select)
* (see rna_Bone_select_update() in rna_armature.c for details)
*/
if (arm->flag & ARM_HAS_VIZ_DEPS) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
/* send necessary notifiers */
WM_main_add_notifier(NC_GEOM | ND_DATA, ob);
+
+ /* tag armature for copy-on-write update (since act_bone is in armature not object) */
+ DEG_id_tag_update(&arm->id, DEG_TAG_COPY_ON_WRITE);
}
}
/* called from editview.c, for mode-less pose selection */
/* assumes scene obact and basact is still on old situation */
bool ED_armature_pose_select_pick_with_buffer(
- Scene *scene, Base *base, const unsigned int *buffer, short hits,
+ ViewLayer *view_layer, Base *base, const unsigned int *buffer, short hits,
bool extend, bool deselect, bool toggle, bool do_nearest)
{
Object *ob = base->object;
@@ -141,11 +146,15 @@ bool ED_armature_pose_select_pick_with_buffer(
if (!ob || !ob->pose) return 0;
- nearBone = get_bone_from_selectbuffer(scene, base, buffer, hits, 1, do_nearest);
+ Object *ob_act = OBACT(view_layer);
+ Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
+
+ /* Callers happen to already get the active base */
+ Base *base_dummy = NULL;
+ nearBone = get_bone_from_selectbuffer(&base, 1, obedit != NULL, buffer, hits, 1, do_nearest, &base_dummy);
/* if the bone cannot be affected, don't do anything */
if ((nearBone) && !(nearBone->flag & BONE_UNSELECTABLE)) {
- Object *ob_act = OBACT;
bArmature *arm = ob->data;
/* since we do unified select, we don't shift+select a bone if the
@@ -163,7 +172,12 @@ bool ED_armature_pose_select_pick_with_buffer(
}
if (!extend && !deselect && !toggle) {
- ED_pose_deselect_all(ob, SEL_DESELECT, true);
+ {
+ uint objects_len = 0;
+ Object **objects = BKE_object_pose_array_get_unique(view_layer, &objects_len);
+ ED_pose_deselect_all_multi(objects, objects_len, SEL_DESELECT, true);
+ MEM_SAFE_FREE(objects);
+ }
nearBone->flag |= (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
arm->act_bone = nearBone;
}
@@ -197,7 +211,7 @@ bool ED_armature_pose_select_pick_with_buffer(
if (ob_act->mode & OB_MODE_WEIGHT_PAINT) {
if (nearBone == arm->act_bone) {
ED_vgroup_select_by_name(ob_act, nearBone->name);
- DAG_id_tag_update(&ob_act->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_act->id, OB_RECALC_DATA);
}
}
/* if there are some dependencies for visualizing armature state
@@ -207,8 +221,11 @@ bool ED_armature_pose_select_pick_with_buffer(
/* NOTE: ob not ob_act here is intentional - it's the source of the
* bones being selected [T37247]
*/
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
+
+ /* tag armature for copy-on-write update (since act_bone is in armature not object) */
+ DEG_id_tag_update(&arm->id, DEG_TAG_COPY_ON_WRITE);
}
}
@@ -249,6 +266,43 @@ void ED_pose_deselect_all(Object *ob, int select_mode, const bool ignore_visibil
}
}
+static bool ed_pose_is_any_selected(Object *ob, bool ignore_visibility)
+{
+ bArmature *arm = ob->data;
+ for (bPoseChannel *pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ if (ignore_visibility || PBONE_VISIBLE(arm, pchan->bone)) {
+ if (pchan->bone->flag & BONE_SELECTED) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+static bool ed_pose_is_any_selected_multi(Object **objects, uint objects_len, bool ignore_visibility)
+{
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ if (ed_pose_is_any_selected(ob_iter, ignore_visibility)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+void ED_pose_deselect_all_multi(Object **objects, uint objects_len, int select_mode, const bool ignore_visibility)
+{
+ if (select_mode == SEL_TOGGLE) {
+ select_mode = ed_pose_is_any_selected_multi(
+ objects, objects_len, ignore_visibility) ? SEL_DESELECT : SEL_SELECT;
+ }
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ ED_pose_deselect_all(ob_iter, select_mode, ignore_visibility);
+ }
+}
+
/* ***************** Selections ********************** */
static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend)
@@ -259,9 +313,6 @@ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend)
if (!(bone->flag & BONE_CONNECTED) || (bone->flag & BONE_UNSELECTABLE))
return;
- /* XXX old cruft! use notifiers instead */
- //select_actionchannel_by_name (ob->action, bone->name, !(shift));
-
if (extend)
bone->flag &= ~BONE_SELECTED;
else
@@ -275,17 +326,18 @@ static void selectconnected_posebonechildren(Object *ob, Bone *bone, int extend)
/* previously known as "selectconnected_posearmature" */
static int pose_select_connected_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
- bArmature *arm = (bArmature *)ob->data;
Bone *bone, *curBone, *next = NULL;
const bool extend = RNA_boolean_get(op->ptr, "extend");
view3d_operator_needs_opengl(C);
- bone = get_nearest_bone(C, event->mval, !extend);
+ Base *base = NULL;
+ bone = get_nearest_bone(C, event->mval, !extend, &base);
if (!bone)
return OPERATOR_CANCELLED;
+
+ bArmature *arm = base->object->data;
/* Select parents */
for (curBone = bone; curBone; curBone = next) {
@@ -307,14 +359,14 @@ static int pose_select_connected_invoke(bContext *C, wmOperator *op, const wmEve
/* Select children */
for (curBone = bone->childbase.first; curBone; curBone = next)
- selectconnected_posebonechildren(ob, curBone, extend);
+ selectconnected_posebonechildren(base->object, curBone, extend);
/* updates */
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, base->object);
if (arm->flag & ARM_HAS_VIZ_DEPS) {
/* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
}
return OPERATOR_FINISHED;
@@ -332,7 +384,7 @@ void POSE_OT_select_linked(wmOperatorType *ot)
ot->idname = "POSE_OT_select_linked";
ot->description = "Select bones related to selected ones by parent/child relationships";
- /* api callbacks */
+ /* callbacks */
/* leave 'exec' unset */
ot->invoke = pose_select_connected_invoke;
ot->poll = pose_select_linked_poll;
@@ -351,27 +403,31 @@ static int pose_de_select_all_exec(bContext *C, wmOperator *op)
int action = RNA_enum_get(op->ptr, "action");
Scene *scene = CTX_data_scene(C);
- Object *ob = ED_object_context(C);
- bArmature *arm = ob->data;
int multipaint = scene->toolsettings->multipaint;
if (action == SEL_TOGGLE) {
action = CTX_DATA_COUNT(C, selected_pose_bones) ? SEL_DESELECT : SEL_SELECT;
}
+
+ Object *ob_prev = NULL;
/* Set the flags */
- CTX_DATA_BEGIN(C, bPoseChannel *, pchan, visible_pose_bones)
+ CTX_DATA_BEGIN_WITH_ID(C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob)
{
+ bArmature *arm = ob->data;
pose_do_bone_select(pchan, action);
+
+ if (ob_prev != ob) {
+ /* weightpaint or mask modifiers need depsgraph updates */
+ if (multipaint || (arm->flag & ARM_HAS_VIZ_DEPS)) {
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
+ ob_prev = ob;
+ }
}
CTX_DATA_END;
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, NULL);
-
- /* weightpaint or mask modifiers need depsgraph updates */
- if (multipaint || (arm->flag & ARM_HAS_VIZ_DEPS)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- }
return OPERATOR_FINISHED;
}
@@ -422,8 +478,11 @@ static int pose_select_parent_exec(bContext *C, wmOperator *UNUSED(op))
if (arm->flag & ARM_HAS_VIZ_DEPS) {
/* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
+
+ /* tag armature for copy-on-write update (since act_bone is in armature not object) */
+ DEG_id_tag_update(&arm->id, DEG_TAG_COPY_ON_WRITE);
return OPERATOR_FINISHED;
}
@@ -447,13 +506,13 @@ void POSE_OT_select_parent(wmOperatorType *ot)
static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op))
{
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
- bArmature *arm = (bArmature *)ob->data;
bConstraint *con;
int found = 0;
-
- CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones)
+ Object *ob_prev = NULL;
+
+ CTX_DATA_BEGIN_WITH_ID (C, bPoseChannel *, pchan, visible_pose_bones, Object *, ob)
{
+ bArmature *arm = ob->data;
if (pchan->bone->flag & BONE_SELECTED) {
for (con = pchan->constraints.first; con; con = con->next) {
const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(con);
@@ -469,6 +528,16 @@ static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op
if ((pchanc) && !(pchanc->bone->flag & BONE_UNSELECTABLE)) {
pchanc->bone->flag |= BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL;
found = 1;
+
+ if (ob != ob_prev) {
+ /* updates */
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
+ if (arm->flag & ARM_HAS_VIZ_DEPS) {
+ /* mask modifier ('armature' mode), etc. */
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
+ ob_prev = ob;
+ }
}
}
}
@@ -484,14 +553,6 @@ static int pose_select_constraint_target_exec(bContext *C, wmOperator *UNUSED(op
if (!found)
return OPERATOR_CANCELLED;
- /* updates */
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
-
- if (arm->flag & ARM_HAS_VIZ_DEPS) {
- /* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- }
-
return OPERATOR_FINISHED;
}
@@ -583,9 +644,12 @@ static int pose_select_hierarchy_exec(bContext *C, wmOperator *op)
if (arm->flag & ARM_HAS_VIZ_DEPS) {
/* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
-
+
+ /* tag armature for copy-on-write update (since act_bone is in armature not object) */
+ DEG_id_tag_update(&arm->id, DEG_TAG_COPY_ON_WRITE);
+
return OPERATOR_FINISHED;
}
@@ -828,7 +892,7 @@ static int pose_select_grouped_exec(bContext *C, wmOperator *op)
if (arm->flag & ARM_HAS_VIZ_DEPS) {
/* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
/* report done status */
@@ -873,59 +937,60 @@ void POSE_OT_select_grouped(wmOperatorType *ot)
static int pose_select_mirror_exec(bContext *C, wmOperator *op)
{
Object *ob_act = CTX_data_active_object(C);
- Object *ob = BKE_object_pose_armature_get(ob_act);
- bArmature *arm;
- bPoseChannel *pchan, *pchan_mirror_act = NULL;
- const bool active_only = RNA_boolean_get(op->ptr, "only_active");
- const bool extend = RNA_boolean_get(op->ptr, "extend");
-
- if ((ob && (ob->mode & OB_MODE_POSE)) == 0) {
- return OPERATOR_CANCELLED;
- }
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- arm = ob->data;
+ FOREACH_OBJECT_IN_MODE_BEGIN(view_layer, OB_MODE_POSE, ob)
+ {
+ bArmature *arm;
+ bPoseChannel *pchan, *pchan_mirror_act = NULL;
+ const bool active_only = RNA_boolean_get(op->ptr, "only_active");
+ const bool extend = RNA_boolean_get(op->ptr, "extend");
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- const int flag = (pchan->bone->flag & BONE_SELECTED);
- PBONE_PREV_FLAG_SET(pchan, flag);
- }
+ arm = ob->data;
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- if (PBONE_SELECTABLE(arm, pchan->bone)) {
- bPoseChannel *pchan_mirror;
- int flag_new = extend ? PBONE_PREV_FLAG_GET(pchan) : 0;
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ const int flag = (pchan->bone->flag & BONE_SELECTED);
+ PBONE_PREV_FLAG_SET(pchan, flag);
+ }
- if ((pchan_mirror = BKE_pose_channel_get_mirrored(ob->pose, pchan->name)) &&
- (PBONE_VISIBLE(arm, pchan_mirror->bone)))
- {
- const int flag_mirror = PBONE_PREV_FLAG_GET(pchan_mirror);
- flag_new |= flag_mirror;
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ if (PBONE_SELECTABLE(arm, pchan->bone)) {
+ bPoseChannel *pchan_mirror;
+ int flag_new = extend ? PBONE_PREV_FLAG_GET(pchan) : 0;
+
+ if ((pchan_mirror = BKE_pose_channel_get_mirrored(ob->pose, pchan->name)) &&
+ (PBONE_VISIBLE(arm, pchan_mirror->bone)))
+ {
+ const int flag_mirror = PBONE_PREV_FLAG_GET(pchan_mirror);
+ flag_new |= flag_mirror;
+
+ if (pchan->bone == arm->act_bone) {
+ pchan_mirror_act = pchan_mirror;
+ }
- if (pchan->bone == arm->act_bone) {
- pchan_mirror_act = pchan_mirror;
+ /* skip all but the active or its mirror */
+ if (active_only && !ELEM(arm->act_bone, pchan->bone, pchan_mirror->bone)) {
+ continue;
+ }
}
- /* skip all but the active or its mirror */
- if (active_only && !ELEM(arm->act_bone, pchan->bone, pchan_mirror->bone)) {
- continue;
- }
+ pchan->bone->flag = (pchan->bone->flag & ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL)) | flag_new;
}
-
- pchan->bone->flag = (pchan->bone->flag & ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL)) | flag_new;
}
- }
- if (pchan_mirror_act) {
- arm->act_bone = pchan_mirror_act->bone;
+ if (pchan_mirror_act) {
+ arm->act_bone = pchan_mirror_act->bone;
- /* in weightpaint we select the associated vertex group too */
- if (ob_act->mode & OB_MODE_WEIGHT_PAINT) {
- ED_vgroup_select_by_name(ob_act, pchan_mirror_act->name);
- DAG_id_tag_update(&ob_act->id, OB_RECALC_DATA);
+ /* in weightpaint we select the associated vertex group too */
+ if (ob_act->mode & OB_MODE_WEIGHT_PAINT) {
+ ED_vgroup_select_by_name(ob_act, pchan_mirror_act->name);
+ DEG_id_tag_update(&ob_act->id, OB_RECALC_DATA);
+ }
}
- }
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, ob);
+ }
+ FOREACH_OBJECT_IN_MODE_END;
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/armature/pose_transform.c b/source/blender/editors/armature/pose_transform.c
index 446bab00b70..deed786944b 100644
--- a/source/blender/editors/armature/pose_transform.c
+++ b/source/blender/editors/armature/pose_transform.c
@@ -45,13 +45,15 @@
#include "BKE_blender_copybuffer.h"
#include "BKE_context.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_main.h"
#include "BKE_object.h"
+#include "BKE_layer.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -70,8 +72,9 @@
/* Pose Apply */
/* helper for apply_armature_pose2bones - fixes parenting of objects that are bone-parented to armature */
-static void applyarmature_fix_boneparents(Scene *scene, Object *armob)
+static void applyarmature_fix_boneparents(const bContext *C, Scene *scene, Object *armob)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Object workob, *ob;
/* go through all objects in database */
@@ -83,7 +86,7 @@ static void applyarmature_fix_boneparents(Scene *scene, Object *armob)
*/
BKE_object_apply_mat4(ob, ob->obmat, false, false);
- BKE_object_workob_calc_parent(scene, ob, &workob);
+ BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
}
}
@@ -92,13 +95,14 @@ static void applyarmature_fix_boneparents(Scene *scene, Object *armob)
/* set the current pose as the restpose */
static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); // must be active object, not edit-object
bArmature *arm = BKE_armature_from_object(ob);
bPose *pose;
bPoseChannel *pchan;
EditBone *curbone;
-
+
/* don't check if editmode (should be done by caller) */
if (ob->type != OB_ARMATURE)
return OPERATOR_CANCELLED;
@@ -189,10 +193,10 @@ static int apply_armature_pose2bones_exec(bContext *C, wmOperator *op)
ED_armature_edit_free(arm);
/* flush positions of posebones */
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
/* fix parenting of objects which are bone-parented */
- applyarmature_fix_boneparents(scene, ob);
+ applyarmature_fix_boneparents(C, scene, ob);
/* note, notifier might evolve */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
@@ -219,38 +223,38 @@ void POSE_OT_armature_apply(wmOperatorType *ot)
/* set the current pose as the restpose */
static int pose_visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op))
{
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C)); // must be active object, not edit-object
-
- /* don't check if editmode (should be done by caller) */
- if (ob->type != OB_ARMATURE)
- return OPERATOR_CANCELLED;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- /* loop over all selected pchans
- *
- * TODO, loop over children before parents if multiple bones
- * at once are to be predictable*/
- CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones)
+ FOREACH_OBJECT_IN_MODE_BEGIN(view_layer, OB_MODE_POSE, ob_iter)
{
- float delta_mat[4][4];
-
- /* chan_mat already contains the delta transform from rest pose to pose-mode pose
- * as that is baked into there so that B-Bones will work. Once we've set this as the
- * new raw-transform components, don't recalc the poses yet, otherwise IK result will
- * change, thus changing the result we may be trying to record.
- */
- /* XXX For some reason, we can't use pchan->chan_mat here, gives odd rotation/offset (see T38251).
- * Using pchan->pose_mat and bringing it back in bone space seems to work as expected!
- */
- BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, delta_mat);
+ /* loop over all selected pchans
+ *
+ * TODO, loop over children before parents if multiple bones
+ * at once are to be predictable*/
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan)
+ {
+ float delta_mat[4][4];
+
+ /* chan_mat already contains the delta transform from rest pose to pose-mode pose
+ * as that is baked into there so that B-Bones will work. Once we've set this as the
+ * new raw-transform components, don't recalc the poses yet, otherwise IK result will
+ * change, thus changing the result we may be trying to record.
+ */
+ /* XXX For some reason, we can't use pchan->chan_mat here, gives odd rotation/offset (see T38251).
+ * Using pchan->pose_mat and bringing it back in bone space seems to work as expected!
+ */
+ BKE_armature_mat_pose_to_bone(pchan, pchan->pose_mat, delta_mat);
+
+ BKE_pchan_apply_mat4(pchan, delta_mat, true);
+ }
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
- BKE_pchan_apply_mat4(pchan, delta_mat, true);
- }
- CTX_DATA_END;
-
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_iter->id, OB_RECALC_DATA);
- /* note, notifier might evolve */
- WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
+ /* note, notifier might evolve */
+ WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob_iter);
+ }
+ FOREACH_OBJECT_IN_MODE_END;
return OPERATOR_FINISHED;
}
@@ -565,11 +569,11 @@ static int pose_paste_exec(bContext *C, wmOperator *op)
BKE_main_free(tmp_bmain);
/* Update event for pose and deformation children. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* Recalculate paths if any of the bones have paths... */
if ((ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS)) {
- ED_pose_recalculate_paths(scene, ob);
+ ED_pose_recalculate_paths(C, scene, ob);
}
/* Notifiers for updates, */
@@ -754,57 +758,73 @@ static int pose_clear_transform_generic_exec(bContext *C, wmOperator *op,
void (*clear_func)(bPoseChannel *), const char default_ksName[])
{
Scene *scene = CTX_data_scene(C);
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
- short autokey = 0;
-
+ bool changed_multi = false;
+
/* sanity checks */
if (ELEM(NULL, clear_func, default_ksName)) {
BKE_report(op->reports, RPT_ERROR, "Programming error: missing clear transform function or keying set name");
return OPERATOR_CANCELLED;
}
-
+
/* only clear relevant transforms for selected bones */
- CTX_DATA_BEGIN(C, bPoseChannel *, pchan, selected_pose_bones)
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob_iter)
{
- /* run provided clearing function */
- clear_func(pchan);
-
- /* do auto-keyframing as appropriate */
- if (autokeyframe_cfra_can_key(scene, &ob->id)) {
- /* clear any unkeyed tags */
- if (pchan->bone)
- pchan->bone->flag &= ~BONE_UNKEYED;
-
- /* tag for autokeying later */
- autokey = 1;
+ ListBase dsources = {NULL, NULL};
+ bool changed = false;
+
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan)
+ {
+ /* run provided clearing function */
+ clear_func(pchan);
+ changed = true;
+
+ /* do auto-keyframing as appropriate */
+ if (autokeyframe_cfra_can_key(scene, &ob_iter->id)) {
+ /* clear any unkeyed tags */
+ if (pchan->bone) {
+ pchan->bone->flag &= ~BONE_UNKEYED;
+ }
+ /* tag for autokeying later */
+ ANIM_relative_keyingset_add_source(&dsources, &ob_iter->id, &RNA_PoseBone, pchan);
+ }
+ else {
+ /* add unkeyed tags */
+ if (pchan->bone) {
+ pchan->bone->flag |= BONE_UNKEYED;
+ }
+ }
}
- else {
- /* add unkeyed tags */
- if (pchan->bone)
- pchan->bone->flag |= BONE_UNKEYED;
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
+
+ if (changed) {
+ changed_multi = true;
+
+ /* perform autokeying on the bones if needed */
+ if (!BLI_listbase_is_empty(&dsources)) {
+ /* get KeyingSet to use */
+ KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, default_ksName);
+
+ /* insert keyframes */
+ ANIM_apply_keyingset(C, &dsources, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
+
+ /* now recalculate paths */
+ if ((ob_iter->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS)) {
+ ED_pose_recalculate_paths(C, scene, ob_iter);
+ }
+
+ BLI_freelistN(&dsources);
+ }
+
+ DEG_id_tag_update(&ob_iter->id, OB_RECALC_DATA);
+
+ /* note, notifier might evolve */
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob_iter);
}
}
- CTX_DATA_END;
-
- /* perform autokeying on the bones if needed */
- if (autokey) {
- /* get KeyingSet to use */
- KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, default_ksName);
-
- /* insert keyframes */
- ANIM_apply_keyingset(C, NULL, NULL, ks, MODIFYKEY_MODE_INSERT, (float)CFRA);
-
- /* now recalculate paths */
- if ((ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS))
- ED_pose_recalculate_paths(scene, ob);
- }
-
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ FOREACH_OBJECT_IN_MODE_END;
- /* note, notifier might evolve */
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
-
- return OPERATOR_FINISHED;
+ return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
/* --------------- */
@@ -897,57 +917,61 @@ void POSE_OT_transforms_clear(wmOperatorType *ot)
static int pose_clear_user_transforms_exec(bContext *C, wmOperator *op)
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Scene *scene = CTX_data_scene(C);
- Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
float cframe = (float)CFRA;
const bool only_select = RNA_boolean_get(op->ptr, "only_selected");
- if ((ob->adt) && (ob->adt->action)) {
- /* XXX: this is just like this to avoid contaminating anything else;
- * just pose values should change, so this should be fine
- */
- bPose *dummyPose = NULL;
- Object workob = {{NULL}};
- bPoseChannel *pchan;
-
- /* execute animation step for current frame using a dummy copy of the pose */
- BKE_pose_copy_data(&dummyPose, ob->pose, 0);
-
- BLI_strncpy(workob.id.name, "OB<ClearTfmWorkOb>", sizeof(workob.id.name));
- workob.type = OB_ARMATURE;
- workob.data = ob->data;
- workob.adt = ob->adt;
- workob.pose = dummyPose;
-
- BKE_animsys_evaluate_animdata(scene, &workob.id, workob.adt, cframe, ADT_RECALC_ANIM);
-
- /* copy back values, but on selected bones only */
- for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) {
- pose_bone_do_paste(ob, pchan, only_select, 0);
- }
-
- /* free temp data - free manually as was copied without constraints */
- for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) {
- if (pchan->prop) {
- IDP_FreeProperty(pchan->prop);
- MEM_freeN(pchan->prop);
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob)
+ {
+ if ((ob->adt) && (ob->adt->action)) {
+ /* XXX: this is just like this to avoid contaminating anything else;
+ * just pose values should change, so this should be fine
+ */
+ bPose *dummyPose = NULL;
+ Object workob = {{NULL}};
+ bPoseChannel *pchan;
+
+ /* execute animation step for current frame using a dummy copy of the pose */
+ BKE_pose_copy_data(&dummyPose, ob->pose, 0);
+
+ BLI_strncpy(workob.id.name, "OB<ClearTfmWorkOb>", sizeof(workob.id.name));
+ workob.type = OB_ARMATURE;
+ workob.data = ob->data;
+ workob.adt = ob->adt;
+ workob.pose = dummyPose;
+
+ BKE_animsys_evaluate_animdata(scene, &workob.id, workob.adt, cframe, ADT_RECALC_ANIM);
+
+ /* copy back values, but on selected bones only */
+ for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) {
+ pose_bone_do_paste(ob, pchan, only_select, 0);
+ }
+
+ /* free temp data - free manually as was copied without constraints */
+ for (pchan = dummyPose->chanbase.first; pchan; pchan = pchan->next) {
+ if (pchan->prop) {
+ IDP_FreeProperty(pchan->prop);
+ MEM_freeN(pchan->prop);
+ }
}
+
+ /* was copied without constraints */
+ BLI_freelistN(&dummyPose->chanbase);
+ MEM_freeN(dummyPose);
+ }
+ else {
+ /* no animation, so just reset whole pose to rest pose
+ * (cannot just restore for selected though)
+ */
+ BKE_pose_rest(ob->pose);
}
- /* was copied without constraints */
- BLI_freelistN(&dummyPose->chanbase);
- MEM_freeN(dummyPose);
+ /* notifiers and updates */
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
}
- else {
- /* no animation, so just reset whole pose to rest pose
- * (cannot just restore for selected though)
- */
- BKE_pose_rest(ob->pose);
- }
-
- /* notifiers and updates */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
+ FOREACH_OBJECT_IN_MODE_END;
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/armature/pose_utils.c b/source/blender/editors/armature/pose_utils.c
index f80afdd169e..0dc89aa4716 100644
--- a/source/blender/editors/armature/pose_utils.c
+++ b/source/blender/editors/armature/pose_utils.c
@@ -39,11 +39,12 @@
#include "BKE_action.h"
#include "BKE_armature.h"
-#include "BKE_depsgraph.h"
#include "BKE_idprop.h"
#include "BKE_context.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "WM_api.h"
@@ -182,6 +183,7 @@ void poseAnim_mapping_free(ListBase *pfLinks)
/* helper for apply() / reset() - refresh the data */
void poseAnim_mapping_refresh(bContext *C, Scene *scene, Object *ob)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
bArmature *arm = (bArmature *)ob->data;
/* old optimize trick... this enforces to bypass the depgraph
@@ -189,9 +191,9 @@ void poseAnim_mapping_refresh(bContext *C, Scene *scene, Object *ob)
*/
/* FIXME: shouldn't this use the builtin stuff? */
if ((arm->flag & ARM_DELAYDEFORM) == 0)
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
else
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
/* note, notifier might evolve */
WM_event_add_notifier(C, NC_OBJECT | ND_POSE, ob);
@@ -266,7 +268,7 @@ void poseAnim_mapping_autoKeyframe(bContext *C, Scene *scene, Object *ob, ListBa
*/
if (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS) {
//ED_pose_clear_paths(C, ob); // XXX for now, don't need to clear
- ED_pose_recalculate_paths(scene, ob);
+ ED_pose_recalculate_paths(C, scene, ob);
}
}
}
diff --git a/source/blender/editors/armature/reeb.c b/source/blender/editors/armature/reeb.c
deleted file mode 100644
index 63a255806b8..00000000000
--- a/source/blender/editors/armature/reeb.c
+++ /dev/null
@@ -1,3435 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Martin Poirier
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/armature/reeb.c
- * \ingroup edarmature
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_edgehash.h"
-#include "BLI_ghash.h"
-
-#include "BKE_context.h"
-
-#include "reeb.h"
-
-#if 0 /* UNUSED 2.5 */
-static ReebGraph *GLOBAL_RG = NULL;
-static ReebGraph *FILTERED_RG = NULL;
-#endif
-
-/*
- * Skeleton generation algorithm based on:
- * "Harmonic Skeleton for Realistic Character Animation"
- * Gregoire Aujay, Franck Hetroy, Francis Lazarus and Christine Depraz
- * SIGGRAPH 2007
- *
- * Reeb graph generation algorithm based on:
- * "Robust On-line Computation of Reeb Graphs: Simplicity and Speed"
- * Valerio Pascucci, Giorgio Scorzelli, Peer-Timo Bremer and Ajith Mascarenhas
- * SIGGRAPH 2007
- *
- * */
-
-#if 0
-#define DEBUG_REEB
-#define DEBUG_REEB_NODE
-#endif
-
-/* place-holders! */
-typedef struct EditEdge {
- void *fake;
-} EditEdge;
-
-typedef struct EditFace {
- void *fake;
-} EditFace;
-/* end place-holders! */
-
-typedef struct VertexData {
- float w; /* weight */
- int i; /* index */
- ReebNode *n;
-} VertexData;
-
-typedef struct EdgeIndex {
- EditEdge **edges;
- int *offset;
-} EdgeIndex;
-
-typedef enum {
- MERGE_LOWER,
- MERGE_HIGHER,
- MERGE_APPEND
-} MergeDirection;
-
-int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1);
-void mergeArcEdges(ReebGraph *rg, ReebArc *aDst, ReebArc *aSrc, MergeDirection direction);
-int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1);
-EditEdge *NextEdgeForVert(EdgeIndex *indexed_edges, int index);
-void mergeArcFaces(ReebGraph *rg, ReebArc *aDst, ReebArc *aSrc);
-void addFacetoArc(ReebArc *arc, EditFace *efa);
-
-void REEB_RadialSymmetry(BNode *root_node, RadialArc *ring, int count);
-void REEB_AxialSymmetry(BNode *root_node, BNode *node1, BNode *node2, struct BArc *barc1, BArc *barc2);
-
-void flipArcBuckets(ReebArc *arc);
-
-
-/***************************************** UTILS **********************************************/
-
-#if 0 /* UNUSED */
-static VertexData *allocVertexData(EditMesh *em)
-{
- VertexData *data;
- EditVert *eve;
- int totvert, index;
-
- totvert = BLI_listbase_count(&em->verts);
-
- data = MEM_callocN(sizeof(VertexData) * totvert, "VertexData");
-
- for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next)
- {
- data[index].i = index;
- data[index].w = 0;
- eve->tmp.p = data + index;
- }
-
- return data;
-}
-
-static int indexData(EditVert *eve)
-{
- return ((VertexData *)eve->tmp.p)->i;
-}
-
-static float weightData(EditVert *eve)
-{
- return ((VertexData *)eve->tmp.p)->w;
-}
-
-static void weightSetData(EditVert *eve, float w)
-{
- ((VertexData *)eve->tmp.p)->w = w;
-}
-
-static ReebNode *nodeData(EditVert *eve)
-{
- return ((VertexData *)eve->tmp.p)->n;
-}
-
-static void nodeSetData(EditVert *eve, ReebNode *n)
-{
- ((VertexData *)eve->tmp.p)->n = n;
-}
-
-#endif
-
-void REEB_freeArc(BArc *barc)
-{
- ReebArc *arc = (ReebArc *)barc;
- BLI_freelistN(&arc->edges);
-
- if (arc->buckets)
- MEM_freeN(arc->buckets);
-
- if (arc->faces)
- BLI_ghash_free(arc->faces, NULL, NULL);
-
- MEM_freeN(arc);
-}
-
-void REEB_freeGraph(ReebGraph *rg)
-{
- ReebArc *arc;
- ReebNode *node;
-
- // free nodes
- for (node = rg->nodes.first; node; node = node->next) {
- BLI_freeNode((BGraph *)rg, (BNode *)node);
- }
- BLI_freelistN(&rg->nodes);
-
- // free arcs
- arc = rg->arcs.first;
- while (arc) {
- ReebArc *next = arc->next;
- REEB_freeArc((BArc *)arc);
- arc = next;
- }
-
- // free edge map
- BLI_edgehash_free(rg->emap, NULL);
-
- /* free linked graph */
- if (rg->link_up) {
- REEB_freeGraph(rg->link_up);
- }
-
- MEM_freeN(rg);
-}
-
-ReebGraph *newReebGraph(void)
-{
- ReebGraph *rg;
- rg = MEM_callocN(sizeof(ReebGraph), "reeb graph");
-
- rg->totnodes = 0;
- rg->emap = BLI_edgehash_new(__func__);
-
-
- rg->free_arc = REEB_freeArc;
- rg->free_node = NULL;
- rg->radial_symmetry = REEB_RadialSymmetry;
- rg->axial_symmetry = REEB_AxialSymmetry;
-
- return rg;
-}
-
-void BIF_flagMultiArcs(ReebGraph *rg, int flag)
-{
- for (; rg; rg = rg->link_up) {
- BLI_flagArcs((BGraph *)rg, flag);
- }
-}
-
-#if 0 /* UNUSED */
-static ReebNode *addNode(ReebGraph *rg, EditVert *eve)
-{
- float weight;
- ReebNode *node = NULL;
-
- weight = weightData(eve);
-
- node = MEM_callocN(sizeof(ReebNode), "reeb node");
-
- node->flag = 0; // clear flag on init
- node->symmetry_level = 0;
- node->arcs = NULL;
- node->degree = 0;
- node->weight = weight;
- node->index = rg->totnodes;
- copy_v3_v3(node->p, eve->co);
-
- BLI_addtail(&rg->nodes, node);
- rg->totnodes++;
-
- nodeSetData(eve, node);
-
- return node;
-}
-
-static ReebNode *copyNode(ReebGraph *rg, ReebNode *node)
-{
- ReebNode *cp_node = NULL;
-
- cp_node = MEM_callocN(sizeof(ReebNode), "reeb node copy");
-
- memcpy(cp_node, node, sizeof(ReebNode));
-
- cp_node->prev = NULL;
- cp_node->next = NULL;
- cp_node->arcs = NULL;
-
- cp_node->link_up = NULL;
- cp_node->link_down = NULL;
-
- BLI_addtail(&rg->nodes, cp_node);
- rg->totnodes++;
-
- return cp_node;
-}
-
-static void relinkNodes(ReebGraph *low_rg, ReebGraph *high_rg)
-{
- ReebNode *low_node, *high_node;
-
- if (low_rg == NULL || high_rg == NULL)
- {
- return;
- }
-
- for (low_node = low_rg->nodes.first; low_node; low_node = low_node->next)
- {
- for (high_node = high_rg->nodes.first; high_node; high_node = high_node->next)
- {
- if (low_node->index == high_node->index)
- {
- high_node->link_down = low_node;
- low_node->link_up = high_node;
- break;
- }
- }
- }
-}
-#endif
-
-ReebNode *BIF_otherNodeFromIndex(ReebArc *arc, ReebNode *node)
-{
- return (arc->head->index == node->index) ? arc->tail : arc->head;
-}
-
-ReebNode *BIF_NodeFromIndex(ReebArc *arc, ReebNode *node)
-{
- return (arc->head->index == node->index) ? arc->head : arc->tail;
-}
-
-ReebNode *BIF_lowestLevelNode(ReebNode *node)
-{
- while (node->link_down) {
- node = node->link_down;
- }
-
- return node;
-}
-
-#if 0 /* UNUSED */
-static ReebArc *copyArc(ReebGraph *rg, ReebArc *arc)
-{
- ReebArc *cp_arc;
- ReebNode *node;
-
- cp_arc = MEM_callocN(sizeof(ReebArc), "reeb arc copy");
-
- memcpy(cp_arc, arc, sizeof(ReebArc));
-
- cp_arc->link_up = arc;
-
- cp_arc->head = NULL;
- cp_arc->tail = NULL;
-
- cp_arc->prev = NULL;
- cp_arc->next = NULL;
-
- cp_arc->edges.first = NULL;
- cp_arc->edges.last = NULL;
-
- /* copy buckets */
- cp_arc->buckets = MEM_callocN(sizeof(EmbedBucket) * cp_arc->bcount, "embed bucket");
- memcpy(cp_arc->buckets, arc->buckets, sizeof(EmbedBucket) * cp_arc->bcount);
-
- /* copy faces map */
- cp_arc->faces = BLI_ghash_ptr_new("copyArc gh");
- mergeArcFaces(rg, cp_arc, arc);
-
- /* find corresponding head and tail */
- for (node = rg->nodes.first; node && (cp_arc->head == NULL || cp_arc->tail == NULL); node = node->next)
- {
- if (node->index == arc->head->index)
- {
- cp_arc->head = node;
- }
- else if (node->index == arc->tail->index)
- {
- cp_arc->tail = node;
- }
- }
-
- BLI_addtail(&rg->arcs, cp_arc);
-
- return cp_arc;
-}
-
-static ReebGraph *copyReebGraph(ReebGraph *rg, int level)
-{
- ReebNode *node;
- ReebArc *arc;
- ReebGraph *cp_rg = newReebGraph();
-
- cp_rg->resolution = rg->resolution;
- cp_rg->length = rg->length;
- cp_rg->link_up = rg;
- cp_rg->multi_level = level;
-
- /* Copy nodes */
- for (node = rg->nodes.first; node; node = node->next)
- {
- ReebNode *cp_node = copyNode(cp_rg, node);
- cp_node->multi_level = level;
- }
-
- /* Copy arcs */
- for (arc = rg->arcs.first; arc; arc = arc->next)
- {
- copyArc(cp_rg, arc);
- }
-
- BLI_buildAdjacencyList((BGraph *)cp_rg);
-
- return cp_rg;
-}
-#endif
-
-ReebGraph *BIF_graphForMultiNode(ReebGraph *rg, ReebNode *node)
-{
- ReebGraph *multi_rg = rg;
-
- while (multi_rg && multi_rg->multi_level != node->multi_level) {
- multi_rg = multi_rg->link_up;
- }
-
- return multi_rg;
-}
-
-#if 0 /* UNUSED */
-static ReebEdge *copyEdge(ReebEdge *edge)
-{
- ReebEdge *newEdge = NULL;
-
- newEdge = MEM_callocN(sizeof(ReebEdge), "reeb edge");
- memcpy(newEdge, edge, sizeof(ReebEdge));
-
- newEdge->next = NULL;
- newEdge->prev = NULL;
-
- return newEdge;
-}
-
-static void printArc(ReebArc *arc)
-{
- ReebEdge *edge;
- ReebNode *head = (ReebNode *)arc->head;
- ReebNode *tail = (ReebNode *)arc->tail;
- printf("arc: (%i) %f -> (%i) %f\n", head->index, head->weight, tail->index, tail->weight);
-
- for (edge = arc->edges.first; edge; edge = edge->next)
- {
- printf("\tedge (%i, %i)\n", edge->v1->index, edge->v2->index);
- }
-}
-
-static void flipArc(ReebArc *arc)
-{
- ReebNode *tmp;
- tmp = arc->head;
- arc->head = arc->tail;
- arc->tail = tmp;
-
- flipArcBuckets(arc);
-}
-
-#ifdef DEBUG_REEB_NODE
-static void NodeDegreeDecrement(ReebGraph *UNUSED(rg), ReebNode *node)
-{
- node->degree--;
-
-// if (node->degree == 0)
-// {
-// printf("would remove node %i\n", node->index);
-// }
-}
-
-static void NodeDegreeIncrement(ReebGraph *UNUSED(rg), ReebNode *node)
-{
-// if (node->degree == 0)
-// {
-// printf("first connect node %i\n", node->index);
-// }
-
- node->degree++;
-}
-
-#else
-# define NodeDegreeDecrement(rg, node) {node->degree--; } (void)0
-# define NodeDegreeIncrement(rg, node) {node->degree++; } (void)0
-#endif
-
-void repositionNodes(ReebGraph *rg)
-{
- BArc *arc = NULL;
- BNode *node = NULL;
-
- // Reset node positions
- for (node = rg->nodes.first; node; node = node->next) {
- node->p[0] = node->p[1] = node->p[2] = 0;
- }
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- if (((ReebArc *)arc)->bcount > 0) {
- float p[3];
-
- copy_v3_v3(p, ((ReebArc *)arc)->buckets[0].p);
- mul_v3_fl(p, 1.0f / arc->head->degree);
- add_v3_v3(arc->head->p, p);
-
- copy_v3_v3(p, ((ReebArc *)arc)->buckets[((ReebArc *)arc)->bcount - 1].p);
- mul_v3_fl(p, 1.0f / arc->tail->degree);
- add_v3_v3(arc->tail->p, p);
- }
- }
-}
-
-void verifyNodeDegree(ReebGraph *rg)
-{
-#ifdef DEBUG_REEB
- ReebNode *node = NULL;
- ReebArc *arc = NULL;
-
- for (node = rg->nodes.first; node; node = node->next) {
- int count = 0;
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- if (arc->head == node || arc->tail == node) {
- count++;
- }
- }
- if (count != node->degree) {
- printf("degree error in node %i: expected %i got %i\n", node->index, count, node->degree);
- }
- if (node->degree == 0) {
- printf("zero degree node %i with weight %f\n", node->index, node->weight);
- }
- }
-#endif
-}
-
-static void verifyBucketsArc(ReebGraph *UNUSED(rg), ReebArc *arc)
-{
- ReebNode *head = (ReebNode *)arc->head;
- ReebNode *tail = (ReebNode *)arc->tail;
-
- if (arc->bcount > 0) {
- int i;
- for (i = 0; i < arc->bcount; i++) {
- if (arc->buckets[i].nv == 0) {
- printArc(arc);
- printf("count error in bucket %i/%i\n", i + 1, arc->bcount);
- }
- }
-
- if (ceilf(head->weight) != arc->buckets[0].val) {
- printArc(arc);
- printf("alloc error in first bucket: %f should be %f\n", arc->buckets[0].val, ceil(head->weight));
- }
- if (floorf(tail->weight) != arc->buckets[arc->bcount - 1].val) {
- printArc(arc);
- printf("alloc error in last bucket: %f should be %f\n", arc->buckets[arc->bcount - 1].val, floor(tail->weight));
- }
- }
-}
-
-void verifyBuckets(ReebGraph *rg)
-{
-#ifdef DEBUG_REEB
- ReebArc *arc = NULL;
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- verifyBucketsArc(rg, arc);
- }
-#endif
-}
-
-void verifyFaces(ReebGraph *rg)
-{
-#ifdef DEBUG_REEB
- int total = 0;
- ReebArc *arc = NULL;
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- total += BLI_ghash_len(arc->faces);
- }
-
-#endif
-}
-
-void verifyArcs(ReebGraph *rg)
-{
- ReebArc *arc;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- if (arc->head->weight > arc->tail->weight) {
- printf("FLIPPED ARC!\n");
- }
- }
-}
-
-static void verifyMultiResolutionLinks(ReebGraph *rg, int level)
-{
-#ifdef DEBUG_REEB
- ReebGraph *lower_rg = rg->link_up;
-
- if (lower_rg) {
- ReebArc *arc;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- if (BLI_findindex(&lower_rg->arcs, arc->link_up) == -1) {
- printf("missing arc %p for level %i\n", (void *)arc->link_up, level);
- printf("Source arc was ---\n");
- printArc(arc);
-
- arc->link_up = NULL;
- }
- }
-
-
- verifyMultiResolutionLinks(lower_rg, level + 1);
- }
-#endif
-}
-/***************************************** BUCKET UTILS **********************************************/
-
-static void addVertToBucket(EmbedBucket *b, float co[3])
-{
- b->nv++;
- interp_v3_v3v3(b->p, b->p, co, 1.0f / b->nv);
-}
-
-#if 0 /* UNUSED 2.5 */
-static void removeVertFromBucket(EmbedBucket *b, float co[3])
-{
- mul_v3_fl(b->p, (float)b->nv);
- sub_v3_v3(b->p, co);
- b->nv--;
- mul_v3_fl(b->p, 1.0f / (float)b->nv);
-}
-#endif
-
-static void mergeBuckets(EmbedBucket *bDst, EmbedBucket *bSrc)
-{
- if (bDst->nv > 0 && bSrc->nv > 0) {
- bDst->nv += bSrc->nv;
- interp_v3_v3v3(bDst->p, bDst->p, bSrc->p, (float)bSrc->nv / (float)(bDst->nv));
- }
- else if (bSrc->nv > 0) {
- bDst->nv = bSrc->nv;
- copy_v3_v3(bDst->p, bSrc->p);
- }
-}
-
-static void mergeArcBuckets(ReebArc *aDst, ReebArc *aSrc, float start, float end)
-{
- if (aDst->bcount > 0 && aSrc->bcount > 0) {
- int indexDst = 0, indexSrc = 0;
-
- start = max_fff(start, aDst->buckets[0].val, aSrc->buckets[0].val);
-
- while (indexDst < aDst->bcount && aDst->buckets[indexDst].val < start) {
- indexDst++;
- }
-
- while (indexSrc < aSrc->bcount && aSrc->buckets[indexSrc].val < start) {
- indexSrc++;
- }
-
- for (; indexDst < aDst->bcount &&
- indexSrc < aSrc->bcount &&
- aDst->buckets[indexDst].val <= end &&
- aSrc->buckets[indexSrc].val <= end
-
- ; indexDst++, indexSrc++)
- {
- mergeBuckets(aDst->buckets + indexDst, aSrc->buckets + indexSrc);
- }
- }
-}
-
-void flipArcBuckets(ReebArc *arc)
-{
- int i, j;
-
- for (i = 0, j = arc->bcount - 1; i < j; i++, j--) {
- EmbedBucket tmp;
-
- tmp = arc->buckets[i];
- arc->buckets[i] = arc->buckets[j];
- arc->buckets[j] = tmp;
- }
-}
-
-static int countArcBuckets(ReebArc *arc)
-{
- return (int)(floor(arc->tail->weight) - ceil(arc->head->weight)) + 1;
-}
-
-static void allocArcBuckets(ReebArc *arc)
-{
- int i;
- float start = ceil(arc->head->weight);
- arc->bcount = countArcBuckets(arc);
-
- if (arc->bcount > 0) {
- arc->buckets = MEM_callocN(sizeof(EmbedBucket) * arc->bcount, "embed bucket");
-
- for (i = 0; i < arc->bcount; i++) {
- arc->buckets[i].val = start + i;
- }
- }
- else {
- arc->buckets = NULL;
- }
-}
-
-static void resizeArcBuckets(ReebArc *arc)
-{
- EmbedBucket *oldBuckets = arc->buckets;
- int oldBCount = arc->bcount;
-
- if (countArcBuckets(arc) == oldBCount) {
- return;
- }
-
- allocArcBuckets(arc);
-
- if (oldBCount != 0 && arc->bcount != 0) {
- int oldStart = (int)oldBuckets[0].val;
- int oldEnd = (int)oldBuckets[oldBCount - 1].val;
- int newStart = (int)arc->buckets[0].val;
- int newEnd = (int)arc->buckets[arc->bcount - 1].val;
- int oldOffset = 0;
- int newOffset = 0;
- int len;
-
- if (oldStart < newStart) {
- oldOffset = newStart - oldStart;
- }
- else {
- newOffset = oldStart - newStart;
- }
-
- len = MIN2(oldEnd - (oldStart + oldOffset) + 1, newEnd - (newStart - newOffset) + 1);
-
- memcpy(arc->buckets + newOffset, oldBuckets + oldOffset, len * sizeof(EmbedBucket));
- }
-
- if (oldBuckets != NULL) {
- MEM_freeN(oldBuckets);
- }
-}
-
-static void reweightBuckets(ReebArc *arc)
-{
- int i;
- float start = ceil((arc->head)->weight);
-
- if (arc->bcount > 0) {
- for (i = 0; i < arc->bcount; i++) {
- arc->buckets[i].val = start + i;
- }
- }
-}
-
-static void interpolateBuckets(ReebArc *arc, float *start_p, float *end_p, int start_index, int end_index)
-{
- int total;
- int j;
-
- total = end_index - start_index + 2;
-
- for (j = start_index; j <= end_index; j++) {
- EmbedBucket *empty = arc->buckets + j;
- empty->nv = 1;
- interp_v3_v3v3(empty->p, start_p, end_p, (float)(j - start_index + 1) / total);
- }
-}
-
-static void fillArcEmptyBuckets(ReebArc *arc)
-{
- float *start_p, *end_p;
- int start_index = 0, end_index = 0;
- int missing = 0;
- int i;
-
- start_p = arc->head->p;
-
- for (i = 0; i < arc->bcount; i++) {
- EmbedBucket *bucket = arc->buckets + i;
-
- if (missing) {
- if (bucket->nv > 0) {
- missing = 0;
-
- end_p = bucket->p;
- end_index = i - 1;
-
- interpolateBuckets(arc, start_p, end_p, start_index, end_index);
- }
- }
- else {
- if (bucket->nv == 0) {
- missing = 1;
-
- if (i > 0) {
- start_p = arc->buckets[i - 1].p;
- }
- start_index = i;
- }
- }
- }
-
- if (missing) {
- end_p = arc->tail->p;
- end_index = arc->bcount - 1;
-
- interpolateBuckets(arc, start_p, end_p, start_index, end_index);
- }
-}
-
-static void ExtendArcBuckets(ReebArc *arc)
-{
- ReebArcIterator arc_iter;
- BArcIterator *iter = (BArcIterator *)&arc_iter;
- EmbedBucket *last_bucket, *first_bucket;
- float *previous = NULL;
- float average_length = 0, length;
- int padding_head = 0, padding_tail = 0;
-
- if (arc->bcount == 0) {
- return; /* failsafe, shouldn't happen */
- }
-
- initArcIterator(iter, arc, arc->head);
- IT_next(iter);
- previous = iter->p;
-
- for (IT_next(iter);
- IT_stopped(iter) == 0;
- previous = iter->p, IT_next(iter)
- )
- {
- average_length += len_v3v3(previous, iter->p);
- }
- average_length /= (arc->bcount - 1);
-
- first_bucket = arc->buckets;
- last_bucket = arc->buckets + (arc->bcount - 1);
-
- length = len_v3v3(first_bucket->p, arc->head->p);
- if (length > 2 * average_length) {
- padding_head = (int)floor(length / average_length);
- }
-
- length = len_v3v3(last_bucket->p, arc->tail->p);
- if (length > 2 * average_length) {
- padding_tail = (int)floor(length / average_length);
- }
-
- if (padding_head + padding_tail > 0) {
- EmbedBucket *old_buckets = arc->buckets;
-
- arc->buckets = MEM_callocN(sizeof(EmbedBucket) * (padding_head + arc->bcount + padding_tail), "embed bucket");
- memcpy(arc->buckets + padding_head, old_buckets, arc->bcount * sizeof(EmbedBucket));
-
- arc->bcount = padding_head + arc->bcount + padding_tail;
-
- MEM_freeN(old_buckets);
- }
-
- if (padding_head > 0) {
- interpolateBuckets(arc, arc->head->p, first_bucket->p, 0, padding_head);
- }
-
- if (padding_tail > 0) {
- interpolateBuckets(arc, last_bucket->p, arc->tail->p, arc->bcount - padding_tail, arc->bcount - 1);
- }
-}
-
-/* CALL THIS ONLY AFTER FILTERING, SINCE IT MESSES UP WEIGHT DISTRIBUTION */
-static void extendGraphBuckets(ReebGraph *rg)
-{
- ReebArc *arc;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- ExtendArcBuckets(arc);
- }
-}
-
-/**************************************** LENGTH CALCULATIONS ****************************************/
-
-static void calculateArcLength(ReebArc *arc)
-{
- ReebArcIterator arc_iter;
- BArcIterator *iter = (BArcIterator *)&arc_iter;
- float *vec0, *vec1;
-
- arc->length = 0;
-
- initArcIterator(iter, arc, arc->head);
-
- vec0 = arc->head->p;
- vec1 = arc->head->p; /* in case there's no embedding */
-
- while (IT_next(iter)) {
- vec1 = iter->p;
-
- arc->length += len_v3v3(vec0, vec1);
-
- vec0 = vec1;
- }
-
- arc->length += len_v3v3(arc->tail->p, vec1);
-}
-
-static void calculateGraphLength(ReebGraph *rg)
-{
- ReebArc *arc;
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- calculateArcLength(arc);
- }
-}
-#endif
-
-/**************************************** SYMMETRY HANDLING ******************************************/
-
-void REEB_RadialSymmetry(BNode *root_node, RadialArc *ring, int count)
-{
- ReebNode *node = (ReebNode *)root_node;
- float axis[3];
- int i;
-
- copy_v3_v3(axis, root_node->symmetry_axis);
-
- /* first pass, merge incrementally */
- for (i = 0; i < count - 1; i++) {
- ReebNode *node1, *node2;
- ReebArc *arc1, *arc2;
- float tangent[3];
- float normal[3];
- int j = i + 1;
-
- add_v3_v3v3(tangent, ring[i].n, ring[j].n);
- cross_v3_v3v3(normal, tangent, axis);
-
- node1 = (ReebNode *)BLI_otherNode(ring[i].arc, root_node);
- node2 = (ReebNode *)BLI_otherNode(ring[j].arc, root_node);
-
- arc1 = (ReebArc *)ring[i].arc;
- arc2 = (ReebArc *)ring[j].arc;
-
- /* mirror first node and mix with the second */
- BLI_mirrorAlongAxis(node1->p, root_node->p, normal);
- interp_v3_v3v3(node2->p, node2->p, node1->p, 1.0f / (j + 1));
-
- /* Merge buckets
- * there shouldn't be any null arcs here, but just to be safe
- * */
- if (arc1->bcount > 0 && arc2->bcount > 0) {
- ReebArcIterator arc_iter1, arc_iter2;
- BArcIterator *iter1 = (BArcIterator *)&arc_iter1;
- BArcIterator *iter2 = (BArcIterator *)&arc_iter2;
- EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
-
- initArcIterator(iter1, arc1, (ReebNode *)root_node);
- initArcIterator(iter2, arc2, (ReebNode *)root_node);
-
- bucket1 = IT_next(iter1);
- bucket2 = IT_next(iter2);
-
- /* Make sure they both start at the same value */
- while (bucket1 && bucket2 && bucket1->val < bucket2->val) {
- bucket1 = IT_next(iter1);
- }
-
- while (bucket1 && bucket2 && bucket2->val < bucket1->val) {
- bucket2 = IT_next(iter2);
- }
-
-
- for (; bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) {
- bucket2->nv += bucket1->nv; /* add counts */
-
- /* mirror on axis */
- BLI_mirrorAlongAxis(bucket1->p, root_node->p, normal);
- /* add bucket2 in bucket1 */
- interp_v3_v3v3(bucket2->p, bucket2->p, bucket1->p, (float)bucket1->nv / (float)(bucket2->nv));
- }
- }
- }
-
- /* second pass, mirror back on previous arcs */
- for (i = count - 1; i > 0; i--) {
- ReebNode *node1, *node2;
- ReebArc *arc1, *arc2;
- float tangent[3];
- float normal[3];
- int j = i - 1;
-
- add_v3_v3v3(tangent, ring[i].n, ring[j].n);
- cross_v3_v3v3(normal, tangent, axis);
-
- node1 = (ReebNode *)BLI_otherNode(ring[i].arc, root_node);
- node2 = (ReebNode *)BLI_otherNode(ring[j].arc, root_node);
-
- arc1 = (ReebArc *)ring[i].arc;
- arc2 = (ReebArc *)ring[j].arc;
-
- /* copy first node than mirror */
- copy_v3_v3(node2->p, node1->p);
- BLI_mirrorAlongAxis(node2->p, root_node->p, normal);
-
- /* Copy buckets
- * there shouldn't be any null arcs here, but just to be safe
- * */
- if (arc1->bcount > 0 && arc2->bcount > 0) {
- ReebArcIterator arc_iter1, arc_iter2;
- BArcIterator *iter1 = (BArcIterator *)&arc_iter1;
- BArcIterator *iter2 = (BArcIterator *)&arc_iter2;
- EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
-
- initArcIterator(iter1, arc1, node);
- initArcIterator(iter2, arc2, node);
-
- bucket1 = IT_next(iter1);
- bucket2 = IT_next(iter2);
-
- /* Make sure they both start at the same value */
- while (bucket1 && bucket1->val < bucket2->val) {
- bucket1 = IT_next(iter1);
- }
-
- while (bucket2 && bucket2->val < bucket1->val) {
- bucket2 = IT_next(iter2);
- }
-
-
- for (; bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) {
- /* copy and mirror back to bucket2 */
- bucket2->nv = bucket1->nv;
- copy_v3_v3(bucket2->p, bucket1->p);
- BLI_mirrorAlongAxis(bucket2->p, node->p, normal);
- }
- }
- }
-}
-
-void REEB_AxialSymmetry(BNode *root_node, BNode *node1, BNode *node2, struct BArc *barc1, BArc *barc2)
-{
- ReebArc *arc1, *arc2;
- float nor[3], p[3];
-
- arc1 = (ReebArc *)barc1;
- arc2 = (ReebArc *)barc2;
-
- copy_v3_v3(nor, root_node->symmetry_axis);
-
- /* mirror node2 along axis */
- copy_v3_v3(p, node2->p);
- BLI_mirrorAlongAxis(p, root_node->p, nor);
-
- /* average with node1 */
- add_v3_v3(node1->p, p);
- mul_v3_fl(node1->p, 0.5f);
-
- /* mirror back on node2 */
- copy_v3_v3(node2->p, node1->p);
- BLI_mirrorAlongAxis(node2->p, root_node->p, nor);
-
- /* Merge buckets
- * there shouldn't be any null arcs here, but just to be safe
- * */
- if (arc1->bcount > 0 && arc2->bcount > 0) {
- ReebArcIterator arc_iter1, arc_iter2;
- BArcIterator *iter1 = (BArcIterator *)&arc_iter1;
- BArcIterator *iter2 = (BArcIterator *)&arc_iter2;
- EmbedBucket *bucket1 = NULL, *bucket2 = NULL;
-
- initArcIterator(iter1, arc1, (ReebNode *)root_node);
- initArcIterator(iter2, arc2, (ReebNode *)root_node);
-
- bucket1 = IT_next(iter1);
- bucket2 = IT_next(iter2);
-
- /* Make sure they both start at the same value */
- while (bucket1 && bucket1->val < bucket2->val) {
- bucket1 = IT_next(iter1);
- }
-
- while (bucket2 && bucket2->val < bucket1->val) {
- bucket2 = IT_next(iter2);
- }
-
-
- for (; bucket1 && bucket2; bucket1 = IT_next(iter1), bucket2 = IT_next(iter2)) {
- bucket1->nv += bucket2->nv; /* add counts */
-
- /* mirror on axis */
- BLI_mirrorAlongAxis(bucket2->p, root_node->p, nor);
- /* add bucket2 in bucket1 */
- interp_v3_v3v3(bucket1->p, bucket1->p, bucket2->p, (float)bucket2->nv / (float)(bucket1->nv));
-
- /* copy and mirror back to bucket2 */
- bucket2->nv = bucket1->nv;
- copy_v3_v3(bucket2->p, bucket1->p);
- BLI_mirrorAlongAxis(bucket2->p, root_node->p, nor);
- }
- }
-}
-
-/************************************** ADJACENCY LIST *************************************************/
-
-
-/****************************************** SMOOTHING **************************************************/
-
-#if 0 /* UNUSED */
-void postprocessGraph(ReebGraph *rg, char mode)
-{
- ReebArc *arc;
- float fac1 = 0, fac2 = 1, fac3 = 0;
-
- switch (mode)
- {
- case SKGEN_AVERAGE:
- fac1 = fac2 = fac3 = 1.0f / 3.0f;
- break;
- case SKGEN_SMOOTH:
- fac1 = fac3 = 0.25f;
- fac2 = 0.5f;
- break;
- case SKGEN_SHARPEN:
- fac1 = fac3 = -0.25f;
- fac2 = 1.5f;
- break;
- default:
-// XXX
-// error("Unknown post processing mode");
- return;
- }
-
- for (arc = rg->arcs.first; arc; arc = arc->next)
- {
- EmbedBucket *buckets = arc->buckets;
- int bcount = arc->bcount;
- int index;
-
- for (index = 1; index < bcount - 1; index++)
- {
- interp_v3_v3v3(buckets[index].p, buckets[index].p, buckets[index - 1].p, fac1 / (fac1 + fac2));
- interp_v3_v3v3(buckets[index].p, buckets[index].p, buckets[index + 1].p, fac3 / (fac1 + fac2 + fac3));
- }
- }
-}
-
-/********************************************SORTING****************************************************/
-
-static int compareNodesWeight(void *vnode1, void *vnode2)
-{
- ReebNode *node1 = (ReebNode *)vnode1;
- ReebNode *node2 = (ReebNode *)vnode2;
-
- if (node1->weight < node2->weight)
- {
- return -1;
- }
- if (node1->weight > node2->weight)
- {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-void sortNodes(ReebGraph *rg)
-{
- BLI_listbase_sort(&rg->nodes, compareNodesWeight);
-}
-
-static int compareArcsWeight(void *varc1, void *varc2)
-{
- ReebArc *arc1 = (ReebArc *)varc1;
- ReebArc *arc2 = (ReebArc *)varc2;
- ReebNode *node1 = (ReebNode *)arc1->head;
- ReebNode *node2 = (ReebNode *)arc2->head;
-
- if (node1->weight < node2->weight)
- {
- return -1;
- }
- if (node1->weight > node2->weight)
- {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-void sortArcs(ReebGraph *rg)
-{
- BLI_listbase_sort(&rg->arcs, compareArcsWeight);
-}
-/******************************************* JOINING ***************************************************/
-
-static void reweightArc(ReebGraph *rg, ReebArc *arc, ReebNode *start_node, float start_weight)
-{
- ReebNode *node;
- float old_weight;
- float end_weight = start_weight + ABS(arc->tail->weight - arc->head->weight);
- int i;
-
- node = (ReebNode *)BLI_otherNode((BArc *)arc, (BNode *)start_node);
-
- /* prevent backtracking */
- if (node->flag == 1)
- {
- return;
- }
-
- if (arc->tail == start_node)
- {
- flipArc(arc);
- }
-
- start_node->flag = 1;
-
- for (i = 0; i < node->degree; i++)
- {
- ReebArc *next_arc = node->arcs[i];
-
- reweightArc(rg, next_arc, node, end_weight);
- }
-
- /* update only if needed */
- if (arc->head->weight != start_weight || arc->tail->weight != end_weight)
- {
- old_weight = arc->head->weight; /* backup head weight, other arcs need it intact, it will be fixed by the source arc */
-
- arc->head->weight = start_weight;
- arc->tail->weight = end_weight;
-
- reweightBuckets(arc);
- resizeArcBuckets(arc);
- fillArcEmptyBuckets(arc);
-
- arc->head->weight = old_weight;
- }
-}
-
-static void reweightSubgraph(ReebGraph *rg, ReebNode *start_node, float start_weight)
-{
- int i;
-
- BLI_flagNodes((BGraph *)rg, 0);
-
- for (i = 0; i < start_node->degree; i++)
- {
- ReebArc *next_arc = start_node->arcs[i];
-
- reweightArc(rg, next_arc, start_node, start_weight);
- }
- start_node->weight = start_weight;
-}
-
-static int joinSubgraphsEnds(ReebGraph *rg, float threshold, int nb_subgraphs)
-{
- int joined = 0;
- int subgraph;
-
- for (subgraph = 1; subgraph <= nb_subgraphs; subgraph++)
- {
- ReebNode *start_node, *end_node;
- ReebNode *min_node_start = NULL, *min_node_end = NULL;
- float min_distance = FLT_MAX;
-
- for (start_node = rg->nodes.first; start_node; start_node = start_node->next)
- {
- if (start_node->subgraph_index == subgraph && start_node->degree == 1)
- {
-
- for (end_node = rg->nodes.first; end_node; end_node = end_node->next)
- {
- if (end_node->subgraph_index != subgraph)
- {
- float distance = len_v3v3(start_node->p, end_node->p);
-
- if (distance < threshold && distance < min_distance)
- {
- min_distance = distance;
- min_node_end = end_node;
- min_node_start = start_node;
- }
- }
- }
- }
- }
-
- end_node = min_node_end;
- start_node = min_node_start;
-
- if (end_node && start_node)
- {
- ReebArc *start_arc /* , *end_arc */ /* UNUSED */;
- int merging = 0;
-
- start_arc = start_node->arcs[0];
- /* end_arc = end_node->arcs[0]; */ /* UNUSED */
-
- if (start_arc->tail == start_node)
- {
- reweightSubgraph(rg, end_node, start_node->weight);
-
- start_arc->tail = end_node;
-
- merging = 1;
- }
- else if (start_arc->head == start_node)
- {
- reweightSubgraph(rg, start_node, end_node->weight);
-
- start_arc->head = end_node;
-
- merging = 2;
- }
-
- if (merging)
- {
- BLI_ReflagSubgraph((BGraph *)rg, end_node->flag, subgraph);
-
- resizeArcBuckets(start_arc);
- fillArcEmptyBuckets(start_arc);
-
- NodeDegreeIncrement(rg, end_node);
- BLI_rebuildAdjacencyListForNode((BGraph *)rg, (BNode *)end_node);
-
- BLI_removeNode((BGraph *)rg, (BNode *)start_node);
- }
-
- joined = 1;
- }
- }
-
- return joined;
-}
-
-/* Reweight graph from smallest node, fix fliped arcs */
-static void fixSubgraphsOrientation(ReebGraph *rg, int nb_subgraphs)
-{
- int subgraph;
-
- for (subgraph = 1; subgraph <= nb_subgraphs; subgraph++)
- {
- ReebNode *node;
- ReebNode *start_node = NULL;
-
- for (node = rg->nodes.first; node; node = node->next)
- {
- if (node->subgraph_index == subgraph)
- {
- if (start_node == NULL || node->weight < start_node->weight)
- {
- start_node = node;
- }
- }
- }
-
- if (start_node)
- {
- reweightSubgraph(rg, start_node, start_node->weight);
- }
- }
-}
-
-static int joinSubgraphs(ReebGraph *rg, float threshold)
-{
- int nb_subgraphs;
- int joined = 0;
-
- BLI_buildAdjacencyList((BGraph *)rg);
-
- if (BLI_isGraphCyclic((BGraph *)rg)) {
- /* don't deal with cyclic graphs YET */
- return 0;
- }
-
- /* sort nodes before flagging subgraphs to make sure root node is subgraph 0 */
- sortNodes(rg);
-
- nb_subgraphs = BLI_FlagSubgraphs((BGraph *)rg);
-
- /* Harmonic function can create flipped arcs, take the occasion to fix them */
-// XXX
-// if (G.scene->toolsettings->skgen_options & SKGEN_HARMONIC)
-// {
- fixSubgraphsOrientation(rg, nb_subgraphs);
-// }
-
- if (nb_subgraphs > 1)
- {
- joined |= joinSubgraphsEnds(rg, threshold, nb_subgraphs);
-
- if (joined)
- {
- removeNormalNodes(rg);
- BLI_buildAdjacencyList((BGraph *)rg);
- }
- }
-
- return joined;
-}
-
-/****************************************** FILTERING **************************************************/
-
-static float lengthArc(ReebArc *arc)
-{
-#if 0
- ReebNode *head = (ReebNode *)arc->head;
- ReebNode *tail = (ReebNode *)arc->tail;
-
- return tail->weight - head->weight;
-#else
- return arc->length;
-#endif
-}
-
-static int compareArcs(void *varc1, void *varc2)
-{
- ReebArc *arc1 = (ReebArc *)varc1;
- ReebArc *arc2 = (ReebArc *)varc2;
- float len1 = lengthArc(arc1);
- float len2 = lengthArc(arc2);
-
- if (len1 < len2) {
- return -1;
- }
- if (len1 > len2) {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-static void filterArc(ReebGraph *rg, ReebNode *newNode, ReebNode *removedNode, ReebArc *srcArc, int merging)
-{
- ReebArc *arc = NULL, *nextArc = NULL;
-
- if (merging) {
- /* first pass, merge buckets for arcs that spawned the two nodes into the source arc*/
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- if (arc->head == srcArc->head && arc->tail == srcArc->tail && arc != srcArc) {
- ReebNode *head = srcArc->head;
- ReebNode *tail = srcArc->tail;
- mergeArcBuckets(srcArc, arc, head->weight, tail->weight);
- }
- }
- }
-
- /* second pass, replace removedNode by newNode, remove arcs that are collapsed in a loop */
- arc = rg->arcs.first;
- while (arc) {
- nextArc = arc->next;
-
- if (arc->head == removedNode || arc->tail == removedNode) {
- if (arc->head == removedNode) {
- arc->head = newNode;
- }
- else {
- arc->tail = newNode;
- }
-
- // Remove looped arcs
- if (arc->head == arc->tail) {
- // v1 or v2 was already newNode, since we're removing an arc, decrement degree
- NodeDegreeDecrement(rg, newNode);
-
- // If it's srcArc, it'll be removed later, so keep it for now
- if (arc != srcArc) {
- BLI_remlink(&rg->arcs, arc);
- REEB_freeArc((BArc *)arc);
- }
- }
- else {
- /* flip arcs that flipped, can happen on diamond shapes, mostly on null arcs */
- if (arc->head->weight > arc->tail->weight) {
- flipArc(arc);
- }
- //newNode->degree++; // incrementing degree since we're adding an arc
- NodeDegreeIncrement(rg, newNode);
- mergeArcFaces(rg, arc, srcArc);
-
- if (merging) {
- ReebNode *head = arc->head;
- ReebNode *tail = arc->tail;
-
- // resize bucket list
- resizeArcBuckets(arc);
- mergeArcBuckets(arc, srcArc, head->weight, tail->weight);
-
- /* update length */
- arc->length += srcArc->length;
- }
- }
- }
-
- arc = nextArc;
- }
-}
-
-void filterNullReebGraph(ReebGraph *rg)
-{
- ReebArc *arc = NULL, *nextArc = NULL;
-
- arc = rg->arcs.first;
- while (arc) {
- nextArc = arc->next;
- // Only collapse arcs too short to have any embed bucket
- if (arc->bcount == 0) {
- ReebNode *newNode = (ReebNode *)arc->head;
- ReebNode *removedNode = (ReebNode *)arc->tail;
- float blend;
-
- blend = (float)newNode->degree / (float)(newNode->degree + removedNode->degree); // blending factors
-
- interp_v3_v3v3(newNode->p, removedNode->p, newNode->p, blend);
-
- filterArc(rg, newNode, removedNode, arc, 0);
-
- // Reset nextArc, it might have changed
- nextArc = arc->next;
-
- BLI_remlink(&rg->arcs, arc);
- REEB_freeArc((BArc *)arc);
-
- BLI_removeNode((BGraph *)rg, (BNode *)removedNode);
- }
-
- arc = nextArc;
- }
-}
-
-static int filterInternalExternalReebGraph(ReebGraph *rg, float threshold_internal, float threshold_external)
-{
- ReebArc *arc = NULL, *nextArc = NULL;
- int value = 0;
-
- BLI_listbase_sort(&rg->arcs, compareArcs);
-
- for (arc = rg->arcs.first; arc; arc = nextArc) {
- nextArc = arc->next;
-
- /* Only collapse non-terminal arcs that are shorter than threshold */
- if ((threshold_internal > 0) &&
- (arc->head->degree > 1) &&
- (arc->tail->degree > 1) &&
- (lengthArc(arc) < threshold_internal))
- {
- ReebNode *newNode = NULL;
- ReebNode *removedNode = NULL;
-
- /* Always remove lower node, so arcs don't flip */
- newNode = arc->head;
- removedNode = arc->tail;
-
- filterArc(rg, newNode, removedNode, arc, 1);
-
- // Reset nextArc, it might have changed
- nextArc = arc->next;
-
- BLI_remlink(&rg->arcs, arc);
- REEB_freeArc((BArc *)arc);
-
- BLI_removeNode((BGraph *)rg, (BNode *)removedNode);
- value = 1;
- }
-
- // Only collapse terminal arcs that are shorter than threshold
- else if ((threshold_external > 0) &&
- (arc->head->degree == 1 || arc->tail->degree == 1) &&
- (lengthArc(arc) < threshold_external))
- {
- ReebNode *terminalNode = NULL;
- ReebNode *middleNode = NULL;
- ReebNode *removedNode = NULL;
-
- // Assign terminal and middle nodes
- if (arc->head->degree == 1) {
- terminalNode = arc->head;
- middleNode = arc->tail;
- }
- else {
- terminalNode = arc->tail;
- middleNode = arc->head;
- }
-
- if (middleNode->degree == 2 && middleNode != rg->nodes.first) {
-#if 1
- // If middle node is a normal node, it will be removed later
- // Only if middle node is not the root node
- /* USE THIS IF YOU WANT TO PROLONG ARCS TO THEIR TERMINAL NODES
- * FOR HANDS, THIS IS NOT THE BEST RESULT
- * */
- continue;
-#else
- removedNode = terminalNode;
-
- // removing arc, so we need to decrease the degree of the remaining node
- NodeDegreeDecrement(rg, middleNode);
-#endif
- }
- // Otherwise, just plain remove of the arc
- else {
- removedNode = terminalNode;
-
- // removing arc, so we need to decrease the degree of the remaining node
- NodeDegreeDecrement(rg, middleNode);
- }
-
- // Reset nextArc, it might have changed
- nextArc = arc->next;
-
- BLI_remlink(&rg->arcs, arc);
- REEB_freeArc((BArc *)arc);
-
- BLI_removeNode((BGraph *)rg, (BNode *)removedNode);
- value = 1;
- }
- }
-
- return value;
-}
-
-static int filterCyclesReebGraph(ReebGraph *rg, float UNUSED(distance_threshold))
-{
- ReebArc *arc1, *arc2;
- ReebArc *next2;
- int filtered = 0;
-
- for (arc1 = rg->arcs.first; arc1; arc1 = arc1->next) {
- for (arc2 = arc1->next; arc2; arc2 = next2) {
- next2 = arc2->next;
- if (arc1 != arc2 && arc1->head == arc2->head && arc1->tail == arc2->tail) {
- mergeArcEdges(rg, arc1, arc2, MERGE_APPEND);
- mergeArcFaces(rg, arc1, arc2);
- mergeArcBuckets(arc1, arc2, arc1->head->weight, arc1->tail->weight);
-
- NodeDegreeDecrement(rg, arc1->head);
- NodeDegreeDecrement(rg, arc1->tail);
-
- BLI_remlink(&rg->arcs, arc2);
- REEB_freeArc((BArc *)arc2);
-
- filtered = 1;
- }
- }
- }
-
- return filtered;
-}
-
-int filterSmartReebGraph(ReebGraph *UNUSED(rg), float UNUSED(threshold))
-{
- int value = 0;
-#if 0 //XXX
- ReebArc *arc = NULL, *nextArc = NULL;
-
- BLI_listbase_sort(&rg->arcs, compareArcs);
-
-#ifdef DEBUG_REEB
- {
- EditFace *efa;
- for (efa = G.editMesh->faces.first; efa; efa = efa->next) {
- efa->tmp.fp = -1;
- }
- }
-#endif
-
- arc = rg->arcs.first;
- while (arc)
- {
- nextArc = arc->next;
-
- /* need correct normals and center */
- recalc_editnormals();
-
- // Only test terminal arcs
- if (arc->head->degree == 1 || arc->tail->degree == 1)
- {
- GHashIterator ghi;
- int merging = 0;
- int total = BLI_ghash_len(arc->faces);
- float avg_angle = 0;
- float avg_vec[3] = {0, 0, 0};
-
- for (BLI_ghashIterator_init(&ghi, arc->faces);
- BLI_ghashIterator_done(&ghi) == false;
- BLI_ghashIterator_step(&ghi))
- {
- EditFace *efa = BLI_ghashIterator_getValue(&ghi);
-
-#if 0
- ReebArcIterator arc_iter;
- BArcIterator *iter = (BArcIterator *)&arc_iter;
- EmbedBucket *bucket = NULL;
- EmbedBucket *previous = NULL;
- float min_distance = -1;
- float angle = 0;
-
- initArcIterator(iter, arc, arc->head);
-
- bucket = nextBucket(iter);
-
- while (bucket != NULL)
- {
- float *vec0 = NULL;
- float *vec1 = bucket->p;
- float midpoint[3], tangent[3];
- float distance;
-
- /* first bucket. Previous is head */
- if (previous == NULL)
- {
- vec0 = arc->head->p;
- }
- /* Previous is a valid bucket */
- else {
- vec0 = previous->p;
- }
-
- copy_v3_v3(midpoint, vec1);
-
- distance = len_v3v3(midpoint, efa->cent);
-
- if (min_distance == -1 || distance < min_distance)
- {
- min_distance = distance;
-
- sub_v3_v3v3(tangent, vec1, vec0);
- normalize_v3(tangent);
-
- angle = dot_v3v3(tangent, efa->n);
- }
-
- previous = bucket;
- bucket = nextBucket(iter);
- }
-
- avg_angle += saacos(fabs(angle));
-#ifdef DEBUG_REEB
- efa->tmp.fp = saacos(fabs(angle));
-#endif
-#else
- add_v3_v3(avg_vec, efa->n);
-#endif
- }
-
-
-#if 0
- avg_angle /= total;
-#else
- mul_v3_fl(avg_vec, 1.0 / total);
- avg_angle = dot_v3v3(avg_vec, avg_vec);
-#endif
-
- arc->angle = avg_angle;
-
- if (avg_angle > threshold)
- merging = 1;
-
- if (merging) {
- ReebNode *terminalNode = NULL;
- ReebNode *middleNode = NULL;
- ReebNode *newNode = NULL;
- ReebNode *removedNode = NULL;
- int merging = 0;
-
- /* Assign terminal and middle nodes */
- if (arc->head->degree == 1) {
- terminalNode = arc->head;
- middleNode = arc->tail;
- }
- else {
- terminalNode = arc->tail;
- middleNode = arc->head;
- }
-
- /* If middle node is a normal node, merge to terminal node */
- if (middleNode->degree == 2) {
- merging = 1;
- newNode = terminalNode;
- removedNode = middleNode;
- }
- /* Otherwise, just plain remove of the arc */
- else {
- merging = 0;
- newNode = middleNode;
- removedNode = terminalNode;
- }
-
- /* Merging arc */
- if (merging) {
- filterArc(rg, newNode, removedNode, arc, 1);
- }
- else {
- /* removing arc, so we need to decrease the degree of the remaining node
- *newNode->degree--; */
- NodeDegreeDecrement(rg, newNode);
- }
-
- /* Reset nextArc, it might have changed */
- nextArc = arc->next;
-
- BLI_remlink(&rg->arcs, arc);
- REEB_freeArc((BArc *)arc);
-
- BLI_freelinkN(&rg->nodes, removedNode);
- value = 1;
- }
- }
-
- arc = nextArc;
- }
-
-#endif
-
- return value;
-}
-
-static void filterGraph(ReebGraph *rg, short options, float threshold_internal, float threshold_external)
-{
- bool done = true;
-
- calculateGraphLength(rg);
-
- if ((options & SKGEN_FILTER_EXTERNAL) == 0) {
- threshold_external = 0;
- }
-
- if ((options & SKGEN_FILTER_INTERNAL) == 0) {
- threshold_internal = 0;
- }
-
- if (threshold_internal > 0 || threshold_external > 0) {
- /* filter until there's nothing more to do */
- while (done == true) {
- done = false; /* no work done yet */
-
- done = filterInternalExternalReebGraph(rg, threshold_internal, threshold_external);
- }
- }
-
- if (options & SKGEN_FILTER_SMART) {
- filterSmartReebGraph(rg, 0.5);
- filterCyclesReebGraph(rg, 0.5);
- }
-
- repositionNodes(rg);
-
- /* Filtering might have created degree 2 nodes, so remove them */
- removeNormalNodes(rg);
-}
-
-static void finalizeGraph(ReebGraph *rg, char passes, char method)
-{
- int i;
-
- BLI_buildAdjacencyList((BGraph *)rg);
-
- sortNodes(rg);
-
- sortArcs(rg);
-
- for (i = 0; i < passes; i++) {
- postprocessGraph(rg, method);
- }
-
- extendGraphBuckets(rg);
-}
-
-/************************************** WEIGHT SPREADING ***********************************************/
-
-static int compareVerts(const void *a, const void *b)
-{
- EditVert *va = *(EditVert **)a;
- EditVert *vb = *(EditVert **)b;
- int value = 0;
-
- if (weightData(va) < weightData(vb)) {
- value = -1;
- }
- else if (weightData(va) > weightData(vb)) {
- value = 1;
- }
-
- return value;
-}
-
-static void spreadWeight(EditMesh *em)
-{
- EditVert **verts, *eve;
- float lastWeight = 0.0f;
- int totvert = BLI_listbase_count(&em->verts);
- int i;
- int work_needed = 1;
-
- verts = MEM_callocN(sizeof(EditVert *) * totvert, "verts array");
-
- for (eve = em->verts.first, i = 0; eve; eve = eve->next, i++) {
- verts[i] = eve;
- }
-
- while (work_needed == 1) {
- work_needed = 0;
- qsort(verts, totvert, sizeof(EditVert *), compareVerts);
-
- for (i = 0; i < totvert; i++) {
- eve = verts[i];
-
- if (i == 0 || (weightData(eve) - lastWeight) > FLT_EPSILON) {
- lastWeight = weightData(eve);
- }
- else {
- work_needed = 1;
- weightSetData(eve, lastWeight + FLT_EPSILON * 2);
- lastWeight = weightData(eve);
- }
- }
- }
-
- MEM_freeN(verts);
-}
-
-/******************************************** EXPORT ***************************************************/
-
-static void exportNode(FILE *f, const char *text, ReebNode *node)
-{
- fprintf(f, "%s i:%i w:%f d:%i %f %f %f\n", text, node->index, node->weight, node->degree, node->p[0], node->p[1], node->p[2]);
-}
-
-void REEB_exportGraph(ReebGraph *rg, int count)
-{
- ReebArc *arc;
- char filename[128];
- FILE *f;
-
- if (count == -1) {
- strcpy(filename, "test.txt");
- }
- else {
- sprintf(filename, "test%05i.txt", count);
- }
- f = BLI_fopen(filename, "w");
-
- for (arc = rg->arcs.first; arc; arc = arc->next) {
- int i;
- float p[3];
-
- exportNode(f, "v1", arc->head);
-
- for (i = 0; i < arc->bcount; i++) {
- fprintf(f, "b nv:%i %f %f %f\n", arc->buckets[i].nv, arc->buckets[i].p[0], arc->buckets[i].p[1], arc->buckets[i].p[2]);
- }
-
- add_v3_v3v3(p, arc->tail->p, arc->head->p);
- mul_v3_fl(p, 0.5f);
-
- fprintf(f, "angle %0.3f %0.3f %0.3f %0.3f %i\n", p[0], p[1], p[2], arc->angle, BLI_ghash_len(arc->faces));
- exportNode(f, "v2", arc->tail);
- }
-
- fclose(f);
-}
-
-/***************************************** MAIN ALGORITHM **********************************************/
-
-/* edges alone will create zero degree nodes, use this function to remove them */
-static void removeZeroNodes(ReebGraph *rg)
-{
- ReebNode *node, *next_node;
-
- for (node = rg->nodes.first; node; node = next_node) {
- next_node = node->next;
-
- if (node->degree == 0) {
- BLI_removeNode((BGraph *)rg, (BNode *)node);
- }
- }
-}
-
-void removeNormalNodes(ReebGraph *rg)
-{
- ReebArc *arc, *nextArc;
-
- // Merge degree 2 nodes
- for (arc = rg->arcs.first; arc; arc = nextArc) {
- nextArc = arc->next;
-
- while (arc->head->degree == 2 || arc->tail->degree == 2) {
- // merge at v1
- if (arc->head->degree == 2) {
- ReebArc *connectedArc = (ReebArc *)BLI_findConnectedArc((BGraph *)rg, (BArc *)arc, (BNode *)arc->head);
-
- /* If arcs are one after the other */
- if (arc->head == connectedArc->tail) {
- /* remove furthest arc */
- if (arc->tail->weight < connectedArc->head->weight) {
- mergeConnectedArcs(rg, arc, connectedArc);
- nextArc = arc->next;
- }
- else {
- mergeConnectedArcs(rg, connectedArc, arc);
- break; /* arc was removed, move to next */
- }
- }
- /* Otherwise, arcs are side by side */
- else {
- /* Don't do anything, we need to keep the lowest node, even if degree 2 */
- break;
- }
- }
-
- /* merge at v2 */
- if (arc->tail->degree == 2) {
- ReebArc *connectedArc = (ReebArc *)BLI_findConnectedArc((BGraph *)rg, (BArc *)arc, (BNode *)arc->tail);
-
- /* If arcs are one after the other */
- if (arc->tail == connectedArc->head) {
- /* remove furthest arc */
- if (arc->head->weight < connectedArc->tail->weight) {
- mergeConnectedArcs(rg, arc, connectedArc);
- nextArc = arc->next;
- }
- else {
- mergeConnectedArcs(rg, connectedArc, arc);
- break; /* arc was removed, move to next */
- }
- }
- /* Otherwise, arcs are side by side */
- else {
- /* Don't do anything, we need to keep the lowest node, even if degree 2 */
- break;
- }
- }
- }
- }
-
-}
-
-static int edgeEquals(ReebEdge *e1, ReebEdge *e2)
-{
- return (e1->v1 == e2->v1 && e1->v2 == e2->v2);
-}
-
-static ReebArc *nextArcMappedToEdge(ReebArc *arc, ReebEdge *e)
-{
- ReebEdge *nextEdge = NULL;
- ReebEdge *edge = NULL;
- ReebArc *result = NULL;
-
- /* Find the ReebEdge in the edge list */
- for (edge = arc->edges.first; edge && !edgeEquals(edge, e); edge = edge->next) { }
-
- nextEdge = edge->nextEdge;
-
- if (nextEdge != NULL) {
- result = nextEdge->arc;
- }
-
- return result;
-}
-
-void addFacetoArc(ReebArc *arc, EditFace *efa)
-{
- BLI_ghash_insert(arc->faces, efa, efa);
-}
-
-void mergeArcFaces(ReebGraph *UNUSED(rg), ReebArc *aDst, ReebArc *aSrc)
-{
- GHashIterator ghi;
-
- for (BLI_ghashIterator_init(&ghi, aSrc->faces);
- BLI_ghashIterator_done(&ghi) == false;
- BLI_ghashIterator_step(&ghi))
- {
- EditFace *efa = BLI_ghashIterator_getValue(&ghi);
- BLI_ghash_insert(aDst->faces, efa, efa);
- }
-}
-
-void mergeArcEdges(ReebGraph *rg, ReebArc *aDst, ReebArc *aSrc, MergeDirection direction)
-{
- ReebEdge *e = NULL;
-
- if (direction == MERGE_APPEND) {
- for (e = aSrc->edges.first; e; e = e->next) {
- e->arc = aDst; // Edge is stolen by new arc
- }
-
- BLI_movelisttolist(&aDst->edges, &aSrc->edges);
- }
- else {
- for (e = aSrc->edges.first; e; e = e->next) {
- ReebEdge *newEdge = copyEdge(e);
-
- newEdge->arc = aDst;
-
- BLI_addtail(&aDst->edges, newEdge);
-
- if (direction == MERGE_LOWER) {
- void **p = BLI_edgehash_lookup_p(rg->emap, e->v1->index, e->v2->index);
-
- newEdge->nextEdge = e;
-
- // if edge was the first in the list, point the edit edge to the new reeb edge instead.
- if (*p == e) {
- *p = (void *)newEdge;
- }
- // otherwise, advance in the list until the predecessor is found then insert it there
- else {
- ReebEdge *previous = (ReebEdge *)*p;
-
- while (previous->nextEdge != e) {
- previous = previous->nextEdge;
- }
-
- previous->nextEdge = newEdge;
- }
- }
- else {
- newEdge->nextEdge = e->nextEdge;
- e->nextEdge = newEdge;
- }
- }
- }
-}
-
-// return 1 on full merge
-int mergeConnectedArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1)
-{
- int result = 0;
- ReebNode *removedNode = NULL;
-
- a0->length += a1->length;
-
- mergeArcEdges(rg, a0, a1, MERGE_APPEND);
- mergeArcFaces(rg, a0, a1);
-
- // Bring a0 to the combine length of both arcs
- if (a0->tail == a1->head) {
- removedNode = a0->tail;
- a0->tail = a1->tail;
- }
- else if (a0->head == a1->tail) {
- removedNode = a0->head;
- a0->head = a1->head;
- }
-
- resizeArcBuckets(a0);
- // Merge a1 in a0
- mergeArcBuckets(a0, a1, a0->head->weight, a0->tail->weight);
-
- // remove a1 from graph
- BLI_remlink(&rg->arcs, a1);
- REEB_freeArc((BArc *)a1);
-
- BLI_removeNode((BGraph *)rg, (BNode *)removedNode);
- result = 1;
-
- return result;
-}
-// return 1 on full merge
-int mergeArcs(ReebGraph *rg, ReebArc *a0, ReebArc *a1)
-{
- int result = 0;
- /* TRIANGLE POINTS DOWN */
- if (a0->head->weight == a1->head->weight) { /* heads are the same */
- if (a0->tail->weight == a1->tail->weight) { /* tails also the same, arcs can be totally merge together */
- mergeArcEdges(rg, a0, a1, MERGE_APPEND);
- mergeArcFaces(rg, a0, a1);
-
- mergeArcBuckets(a0, a1, a0->head->weight, a0->tail->weight);
-
- // Adjust node degree
- //a1->head->degree--;
- NodeDegreeDecrement(rg, a1->head);
- //a1->tail->degree--;
- NodeDegreeDecrement(rg, a1->tail);
-
- // remove a1 from graph
- BLI_remlink(&rg->arcs, a1);
-
- REEB_freeArc((BArc *)a1);
- result = 1;
- }
- else if (a0->tail->weight > a1->tail->weight) { /* a1->tail->weight is in the middle */
- mergeArcEdges(rg, a1, a0, MERGE_LOWER);
- mergeArcFaces(rg, a1, a0);
-
- // Adjust node degree
- //a0->head->degree--;
- NodeDegreeDecrement(rg, a0->head);
- //a1->tail->degree++;
- NodeDegreeIncrement(rg, a1->tail);
-
- mergeArcBuckets(a1, a0, a1->head->weight, a1->tail->weight);
- a0->head = a1->tail;
- resizeArcBuckets(a0);
- }
- else { /* a0>n2 is in the middle */
- mergeArcEdges(rg, a0, a1, MERGE_LOWER);
- mergeArcFaces(rg, a0, a1);
-
- // Adjust node degree
- //a1->head->degree--;
- NodeDegreeDecrement(rg, a1->head);
- //a0->tail->degree++;
- NodeDegreeIncrement(rg, a0->tail);
-
- mergeArcBuckets(a0, a1, a0->head->weight, a0->tail->weight);
- a1->head = a0->tail;
- resizeArcBuckets(a1);
- }
- }
- /* TRIANGLE POINTS UP */
- else if (a0->tail->weight == a1->tail->weight) { /* tails are the same */
- if (a0->head->weight > a1->head->weight) { /* a0->head->weight is in the middle */
- mergeArcEdges(rg, a0, a1, MERGE_HIGHER);
- mergeArcFaces(rg, a0, a1);
-
- // Adjust node degree
- //a1->tail->degree--;
- NodeDegreeDecrement(rg, a1->tail);
- //a0->head->degree++;
- NodeDegreeIncrement(rg, a0->head);
-
- mergeArcBuckets(a0, a1, a0->head->weight, a0->tail->weight);
- a1->tail = a0->head;
- resizeArcBuckets(a1);
- }
- else { /* a1->head->weight is in the middle */
- mergeArcEdges(rg, a1, a0, MERGE_HIGHER);
- mergeArcFaces(rg, a1, a0);
-
- // Adjust node degree
- //a0->tail->degree--;
- NodeDegreeDecrement(rg, a0->tail);
- //a1->head->degree++;
- NodeDegreeIncrement(rg, a1->head);
-
- mergeArcBuckets(a1, a0, a1->head->weight, a1->tail->weight);
- a0->tail = a1->head;
- resizeArcBuckets(a0);
- }
- }
- else {
- /* Need something here (OR NOT) */
- }
-
- return result;
-}
-
-static void glueByMergeSort(ReebGraph *rg, ReebArc *a0, ReebArc *a1, ReebEdge *e0, ReebEdge *e1)
-{
- int total = 0;
- while (total == 0 && a0 != a1 && a0 != NULL && a1 != NULL) {
- total = mergeArcs(rg, a0, a1);
-
- if (total == 0) // if it wasn't a total merge, go forward {
- if (a0->tail->weight < a1->tail->weight) {
- a0 = nextArcMappedToEdge(a0, e0);
- }
- else {
- a1 = nextArcMappedToEdge(a1, e1);
- }
- }
- }
-}
-
-static void mergePaths(ReebGraph *rg, ReebEdge *e0, ReebEdge *e1, ReebEdge *e2)
-{
- ReebArc *a0, *a1, *a2;
- a0 = e0->arc;
- a1 = e1->arc;
- a2 = e2->arc;
-
- glueByMergeSort(rg, a0, a1, e0, e1);
- glueByMergeSort(rg, a0, a2, e0, e2);
-}
-
-static ReebEdge *createArc(ReebGraph *rg, ReebNode *node1, ReebNode *node2)
-{
- ReebEdge *edge;
-
- edge = BLI_edgehash_lookup(rg->emap, node1->index, node2->index);
-
- // Only add existing edges that haven't been added yet
- if (edge == NULL) {
- ReebArc *arc;
- ReebNode *v1, *v2;
- float len, offset;
- int i;
-
- arc = MEM_callocN(sizeof(ReebArc), "reeb arc");
- edge = MEM_callocN(sizeof(ReebEdge), "reeb edge");
-
- arc->flag = 0; // clear flag on init
- arc->symmetry_level = 0;
- arc->faces = BLI_ghash_ptr_new("createArc gh");
-
- if (node1->weight <= node2->weight) {
- v1 = node1;
- v2 = node2;
- }
- else {
- v1 = node2;
- v2 = node1;
- }
-
- arc->head = v1;
- arc->tail = v2;
-
- // increase node degree
- //v1->degree++;
- NodeDegreeIncrement(rg, v1);
- //v2->degree++;
- NodeDegreeIncrement(rg, v2);
-
- BLI_edgehash_insert(rg->emap, node1->index, node2->index, edge);
-
- edge->arc = arc;
- edge->nextEdge = NULL;
- edge->v1 = v1;
- edge->v2 = v2;
-
- BLI_addtail(&rg->arcs, arc);
- BLI_addtail(&arc->edges, edge);
-
- /* adding buckets for embedding */
- allocArcBuckets(arc);
-
- offset = arc->head->weight;
- len = arc->tail->weight - arc->head->weight;
-
-#if 0
- /* This is the actual embedding filling described in the paper
- * the problem is that it only works with really dense meshes
- */
- if (arc->bcount > 0)
- {
- addVertToBucket(&(arc->buckets[0]), arc->head->co);
- addVertToBucket(&(arc->buckets[arc->bcount - 1]), arc->tail->co);
- }
-#else
- for (i = 0; i < arc->bcount; i++) {
- float co[3];
- float f = (arc->buckets[i].val - offset) / len;
-
- interp_v3_v3v3(co, v1->p, v2->p, f);
- addVertToBucket(&(arc->buckets[i]), co);
- }
-#endif
-
- }
-
- return edge;
-}
-
-static void addTriangleToGraph(ReebGraph *rg, ReebNode *n1, ReebNode *n2, ReebNode *n3, EditFace *efa)
-{
- ReebEdge *re1, *re2, *re3;
- ReebEdge *e1, *e2, *e3;
- float len1, len2, len3;
-
- re1 = createArc(rg, n1, n2);
- re2 = createArc(rg, n2, n3);
- re3 = createArc(rg, n3, n1);
-
- addFacetoArc(re1->arc, efa);
- addFacetoArc(re2->arc, efa);
- addFacetoArc(re3->arc, efa);
-
- len1 = (float)fabs(n1->weight - n2->weight);
- len2 = (float)fabs(n2->weight - n3->weight);
- len3 = (float)fabs(n3->weight - n1->weight);
-
- /* The rest of the algorithm assumes that e1 is the longest edge */
-
- if (len1 >= len2 && len1 >= len3) {
- e1 = re1;
- e2 = re2;
- e3 = re3;
- }
- else if (len2 >= len1 && len2 >= len3) {
- e1 = re2;
- e2 = re1;
- e3 = re3;
- }
- else {
- e1 = re3;
- e2 = re2;
- e3 = re1;
- }
-
- /* And e2 is the lowest edge
- * If e3 is lower than e2, swap them
- */
- if (e3->v1->weight < e2->v1->weight) {
- ReebEdge *etmp = e2;
- e2 = e3;
- e3 = etmp;
- }
-
-
- mergePaths(rg, e1, e2, e3);
-}
-
-ReebGraph *generateReebGraph(EditMesh *em, int subdivisions)
-{
- ReebGraph *rg;
- EditVert *eve;
- EditFace *efa;
- int index;
- /*int totvert;*/
-
-#ifdef DEBUG_REEB
- int totfaces;
- int countfaces = 0;
-#endif
-
- rg = newReebGraph();
-
- rg->resolution = subdivisions;
-
- /*totvert = BLI_listbase_count(&em->verts);*/ /*UNUSED*/
-#ifdef DEBUG_REEB
- totfaces = BLI_listbase_count(&em->faces);
-#endif
-
- renormalizeWeight(em, 1.0f);
-
- /* Spread weight to minimize errors */
- spreadWeight(em);
-
- renormalizeWeight(em, (float)rg->resolution);
-
- /* Adding vertice */
- for (index = 0, eve = em->verts.first; eve; eve = eve->next) {
- if (eve->h == 0) {
- addNode(rg, eve);
- eve->f2 = 0;
- index++;
- }
- }
-
- /* Adding face, edge per edge */
- for (efa = em->faces.first; efa; efa = efa->next) {
- if (efa->h == 0) {
- ReebNode *n1, *n2, *n3;
-
- n1 = nodeData(efa->v1);
- n2 = nodeData(efa->v2);
- n3 = nodeData(efa->v3);
-
- addTriangleToGraph(rg, n1, n2, n3, efa);
-
- if (efa->v4) {
- ReebNode *n4 = nodeData(efa->v4);
- addTriangleToGraph(rg, n1, n3, n4, efa);
- }
-#ifdef DEBUG_REEB
- countfaces++;
- if (countfaces % 100 == 0) {
- printf("\rface %i of %i", countfaces, totfaces);
- }
-#endif
- }
- }
-
- printf("\n");
-
- removeZeroNodes(rg);
-
- removeNormalNodes(rg);
-
- return rg;
-}
-
-/***************************************** WEIGHT UTILS **********************************************/
-
-void renormalizeWeight(EditMesh *em, float newmax)
-{
- EditVert *eve;
- float minimum, maximum, range;
-
- if (em == NULL || BLI_listbase_is_empty(&em->verts))
- return;
-
- /* First pass, determine maximum and minimum */
- eve = em->verts.first;
- minimum = weightData(eve);
- maximum = minimum;
- for (; eve; eve = eve->next) {
- maximum = MAX2(maximum, weightData(eve));
- minimum = MIN2(minimum, weightData(eve));
- }
-
- range = maximum - minimum;
-
- /* Normalize weights */
- for (eve = em->verts.first; eve; eve = eve->next) {
- float weight = (weightData(eve) - minimum) / range * newmax;
- weightSetData(eve, weight);
- }
-}
-
-
-int weightFromLoc(EditMesh *em, int axis)
-{
- EditVert *eve;
-
- if (em == NULL || BLI_listbase_is_empty(&em->verts) || axis < 0 || axis > 2)
- return 0;
-
- /* Copy coordinate in weight */
- for (eve = em->verts.first; eve; eve = eve->next) {
- weightSetData(eve, eve->co[axis]);
- }
-
- return 1;
-}
-
-static void addTriangle(LinearSolver *context, EditVert *v1, EditVert *v2, EditVert *v3, int e1, int e2, int e3)
-{
- /* Angle opposite e1 */
- float t1 = cotangent_tri_weight_v3(v1->co, v2->co, v3->co) / e2;
-
- /* Angle opposite e2 */
- float t2 = cotangent_tri_weight_v3(v2->co, v3->co, v1->co) / e3;
-
- /* Angle opposite e3 */
- float t3 = cotangent_tri_weight_v3(v3->co, v1->co, v2->co) / e1;
-
- int i1 = indexData(v1);
- int i2 = indexData(v2);
- int i3 = indexData(v3);
-
- EIG_linear_solver_matrix_add(context, i1, i1, t2 + t3);
- EIG_linear_solver_matrix_add(context, i2, i2, t1 + t3);
- EIG_linear_solver_matrix_add(context, i3, i3, t1 + t2);
-
- EIG_linear_solver_matrix_add(context, i1, i2, -t3);
- EIG_linear_solver_matrix_add(context, i2, i1, -t3);
-
- EIG_linear_solver_matrix_add(context, i2, i3, -t1);
- EIG_linear_solver_matrix_add(context, i3, i2, -t1);
-
- EIG_linear_solver_matrix_add(context, i3, i1, -t2);
- EIG_linear_solver_matrix_add(context, i1, i3, -t2);
-}
-
-int weightToHarmonic(EditMesh *em, EdgeIndex *indexed_edges)
-{
- LinearSolver *context;
- NLboolean success;
- EditVert *eve;
- EditEdge *eed;
- EditFace *efa;
- int totvert = 0;
- int index;
- int rval;
-
- /* Find local extrema */
- for (eve = em->verts.first; eve; eve = eve->next) {
- totvert++;
- }
-
- /* Solve */
-
- context = EIG_linear_solver_new(, 0, totvert, 1);
-
- /* Find local extrema */
- for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) {
- if (eve->h == 0) {
- EditEdge *eed;
- int maximum = 1;
- int minimum = 1;
-
- NextEdgeForVert(indexed_edges, -1); /* Reset next edge */
- for (eed = NextEdgeForVert(indexed_edges, index); eed && (maximum || minimum); eed = NextEdgeForVert(indexed_edges, index)) {
- EditVert *eve2;
-
- if (eed->v1 == eve) {
- eve2 = eed->v2;
- }
- else {
- eve2 = eed->v1;
- }
-
- if (eve2->h == 0) {
- /* Adjacent vertex is bigger, not a local maximum */
- if (weightData(eve2) > weightData(eve)) {
- maximum = 0;
- }
- /* Adjacent vertex is smaller, not a local minimum */
- else if (weightData(eve2) < weightData(eve)) {
- minimum = 0;
- }
- }
- }
-
- if (maximum || minimum) {
- float w = weightData(eve);
- eve->f1 = 0;
- EIG_linear_solver_variable_set(context, 0, index, w);
- EIG_linear_solver_variable_lock(context, index);
- }
- else {
- eve->f1 = 1;
- }
- }
- }
-
- /* Zero edge weight */
- for (eed = em->edges.first; eed; eed = eed->next) {
- eed->tmp.l = 0;
- }
-
- /* Add faces count to the edge weight */
- for (efa = em->faces.first; efa; efa = efa->next) {
- if (efa->h == 0) {
- efa->e1->tmp.l++;
- efa->e2->tmp.l++;
- efa->e3->tmp.l++;
-
- if (efa->e4) {
- efa->e4->tmp.l++;
- }
- }
- }
-
- /* Add faces angle to the edge weight */
- for (efa = em->faces.first; efa; efa = efa->next) {
- if (efa->h == 0) {
- if (efa->v4 == NULL) {
- addTriangle(context, efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, efa->e3->tmp.l);
- }
- else {
- addTriangle(context, efa->v1, efa->v2, efa->v3, efa->e1->tmp.l, efa->e2->tmp.l, 2);
- addTriangle(context, efa->v3, efa->v4, efa->v1, efa->e3->tmp.l, efa->e4->tmp.l, 2);
- }
- }
- }
-
- success = EIG_linear_solver_solve(context);
-
- if (success) {
- rval = 1;
- for (index = 0, eve = em->verts.first; eve; index++, eve = eve->next) {
- weightSetData(eve, EIG_linear_solver_variable_get(context, 0, index));
- }
- }
- else {
- rval = 0;
- }
-
- EIG_linear_solver_delete(context);
-
- return rval;
-}
-
-
-EditEdge *NextEdgeForVert(EdgeIndex *indexed_edges, int index)
-{
- static int offset = -1;
-
- /* Reset method, call with NULL mesh pointer */
- if (index == -1) {
- offset = -1;
- return NULL;
- }
-
- /* first pass, start at the head of the list */
- if (offset == -1) {
- offset = indexed_edges->offset[index];
- }
- /* subsequent passes, start on the next edge */
- else {
- offset++;
- }
-
- return indexed_edges->edges[offset];
-}
-
-static void shortestPathsFromVert(EditMesh *em, EditVert *starting_vert, EdgeIndex *indexed_edges)
-{
- Heap *edge_heap;
- EditVert *current_eve = NULL;
- EditEdge *eed = NULL;
- EditEdge *select_eed = NULL;
-
- edge_heap = BLI_heap_new();
-
- current_eve = starting_vert;
-
- /* insert guard in heap, when that is returned, no more edges */
- BLI_heap_insert(edge_heap, FLT_MAX, NULL);
-
- /* Initialize edge flag */
- for (eed = em->edges.first; eed; eed = eed->next) {
- eed->f1 = 0;
- }
-
- while (BLI_heap_len(edge_heap) > 0) {
- float current_weight;
-
- current_eve->f1 = 1; /* mark vertex as selected */
-
- /* Add all new edges connected to current_eve to the list */
- NextEdgeForVert(indexed_edges, -1); // Reset next edge
- for (eed = NextEdgeForVert(indexed_edges, indexData(current_eve)); eed; eed = NextEdgeForVert(indexed_edges, indexData(current_eve))) {
- if (eed->f1 == 0) {
- BLI_heap_insert(edge_heap, weightData(current_eve) + eed->tmp.fp, eed);
- eed->f1 = 1;
- }
- }
-
- /* Find next shortest edge with unselected verts */
- do {
- current_weight = BLI_heap_node_value(BLI_heap_top(edge_heap));
- select_eed = BLI_heap_pop_min(edge_heap);
- } while (select_eed != NULL && select_eed->v1->f1 != 0 && select_eed->v2->f1);
-
- if (select_eed != NULL) {
- select_eed->f1 = 2;
-
- if (select_eed->v1->f1 == 0) /* v1 is the new vertex */ {
- current_eve = select_eed->v1;
- }
- else { /* otherwise, it's v2 */
- current_eve = select_eed->v2;
- }
-
- weightSetData(current_eve, current_weight);
- }
- }
-
- BLI_heap_free(edge_heap, NULL);
-}
-
-static void freeEdgeIndex(EdgeIndex *indexed_edges)
-{
- MEM_freeN(indexed_edges->offset);
- MEM_freeN(indexed_edges->edges);
-}
-
-static void buildIndexedEdges(EditMesh *em, EdgeIndex *indexed_edges)
-{
- EditVert *eve;
- EditEdge *eed;
- int totvert = 0;
- int tot_indexed = 0;
- int offset = 0;
-
- totvert = BLI_listbase_count(&em->verts);
-
- indexed_edges->offset = MEM_callocN(totvert * sizeof(int), "EdgeIndex offset");
-
- for (eed = em->edges.first; eed; eed = eed->next) {
- if (eed->v1->h == 0 && eed->v2->h == 0) {
- tot_indexed += 2;
- indexed_edges->offset[indexData(eed->v1)]++;
- indexed_edges->offset[indexData(eed->v2)]++;
- }
- }
-
- tot_indexed += totvert;
-
- indexed_edges->edges = MEM_callocN(tot_indexed * sizeof(EditEdge *), "EdgeIndex edges");
-
- /* setting vert offsets */
- for (eve = em->verts.first; eve; eve = eve->next) {
- if (eve->h == 0) {
- int d = indexed_edges->offset[indexData(eve)];
- indexed_edges->offset[indexData(eve)] = offset;
- offset += d + 1;
- }
- }
-
- /* adding edges in array */
- for (eed = em->edges.first; eed; eed = eed->next) {
- if (eed->v1->h == 0 && eed->v2->h == 0) {
- int i;
- for (i = indexed_edges->offset[indexData(eed->v1)]; i < tot_indexed; i++) {
- if (indexed_edges->edges[i] == NULL) {
- indexed_edges->edges[i] = eed;
- break;
- }
- }
-
- for (i = indexed_edges->offset[indexData(eed->v2)]; i < tot_indexed; i++) {
- if (indexed_edges->edges[i] == NULL) {
- indexed_edges->edges[i] = eed;
- break;
- }
- }
- }
- }
-}
-
-int weightFromDistance(EditMesh *em, EdgeIndex *indexed_edges)
-{
- EditVert *eve;
- int totedge = 0;
- int totvert = 0;
- int vCount = 0;
-
- totvert = BLI_listbase_count(&em->verts);
-
- if (em == NULL || totvert == 0) {
- return 0;
- }
-
- totedge = BLI_listbase_count(&em->edges);
-
- if (totedge == 0) {
- return 0;
- }
-
- /* Initialize vertice flag and find at least one selected vertex */
- for (eve = em->verts.first; eve; eve = eve->next) {
- eve->f1 = 0;
- if (eve->f & SELECT) {
- vCount = 1;
- }
- }
-
- if (vCount == 0) {
- return 0; /* no selected vert, failure */
- }
- else {
- EditEdge *eed;
- int allDone = 0;
-
- /* Calculate edge weight */
- for (eed = em->edges.first; eed; eed = eed->next) {
- if (eed->v1->h == 0 && eed->v2->h == 0) {
- eed->tmp.fp = len_v3v3(eed->v1->co, eed->v2->co);
- }
- }
-
- /* Apply dijkstra spf for each selected vert */
- for (eve = em->verts.first; eve; eve = eve->next) {
- if (eve->f & SELECT) {
- shortestPathsFromVert(em, eve, indexed_edges);
- }
- }
-
- /* connect unselected islands */
- while (allDone == 0) {
- EditVert *selected_eve = NULL;
- float selected_weight = 0;
- float min_distance = FLT_MAX;
-
- allDone = 1;
-
- for (eve = em->verts.first; eve; eve = eve->next) {
- /* for every vertex visible that hasn't been processed yet */
- if (eve->h == 0 && eve->f1 != 1) {
- EditVert *closest_eve;
-
- /* find the closest processed vertex */
- for (closest_eve = em->verts.first; closest_eve; closest_eve = closest_eve->next) {
- /* vertex is already processed and distance is smaller than current minimum */
- if (closest_eve->f1 == 1) {
- float distance = len_v3v3(closest_eve->co, eve->co);
- if (distance < min_distance) {
- min_distance = distance;
- selected_eve = eve;
- selected_weight = weightData(closest_eve);
- }
- }
- }
- }
- }
-
- if (selected_eve) {
- allDone = 0;
-
- weightSetData(selected_eve, selected_weight + min_distance);
- shortestPathsFromVert(em, selected_eve, indexed_edges);
- }
- }
- }
-
- for (eve = em->verts.first; eve && vCount == 0; eve = eve->next) {
- if (eve->f1 == 0) {
- printf("vertex not reached\n");
- break;
- }
- }
-
- return 1;
-}
-#endif
-
-/****************************************** BUCKET ITERATOR **************************************************/
-
-static void *headNode(void *arg);
-static void *tailNode(void *arg);
-static void *nextBucket(void *arg);
-static void *nextNBucket(void *arg, int n);
-static void *peekBucket(void *arg, int n);
-static void *previousBucket(void *arg);
-static int iteratorStopped(void *arg);
-
-static void initIteratorFct(ReebArcIterator *iter)
-{
- iter->head = headNode;
- iter->tail = tailNode;
- iter->peek = peekBucket;
- iter->next = nextBucket;
- iter->nextN = nextNBucket;
- iter->previous = previousBucket;
- iter->stopped = iteratorStopped;
-}
-
-static void setIteratorValues(ReebArcIterator *iter, EmbedBucket *bucket)
-{
- if (bucket) {
- iter->p = bucket->p;
- iter->no = bucket->no;
- }
- else {
- iter->p = NULL;
- iter->no = NULL;
- }
- iter->size = 0;
-}
-
-void initArcIterator(BArcIterator *arg, ReebArc *arc, ReebNode *head)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
-
- initIteratorFct(iter);
- iter->arc = arc;
-
- if (head == arc->head) {
- iter->start = 0;
- iter->end = arc->bcount - 1;
- iter->stride = 1;
- }
- else {
- iter->start = arc->bcount - 1;
- iter->end = 0;
- iter->stride = -1;
- }
-
- iter->length = arc->bcount;
-
- iter->index = -1;
-}
-
-void initArcIteratorStart(BArcIterator *arg, struct ReebArc *arc, struct ReebNode *head, int start)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
-
- initIteratorFct(iter);
- iter->arc = arc;
-
- if (head == arc->head) {
- iter->start = start;
- iter->end = arc->bcount - 1;
- iter->stride = 1;
- }
- else {
- iter->start = arc->bcount - 1 - start;
- iter->end = 0;
- iter->stride = -1;
- }
-
- iter->index = -1;
-
- iter->length = arc->bcount - start;
-
- if (start >= arc->bcount) {
- iter->start = iter->end; /* stop iterator since it's past its end */
- }
-}
-
-void initArcIterator2(BArcIterator *arg, ReebArc *arc, int start, int end)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
-
- initIteratorFct(iter);
- iter->arc = arc;
-
- iter->start = start;
- iter->end = end;
-
- if (end > start) {
- iter->stride = 1;
- }
- else {
- iter->stride = -1;
- }
-
- iter->index = -1;
-
- iter->length = abs(iter->end - iter->start) + 1;
-}
-
-static void *headNode(void *arg)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
- ReebNode *node;
-
- if (iter->start < iter->end) {
- node = iter->arc->head;
- }
- else {
- node = iter->arc->tail;
- }
-
- iter->p = node->p;
- iter->no = node->no;
- iter->size = 0;
-
- return node;
-}
-
-static void *tailNode(void *arg)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
- ReebNode *node;
-
- if (iter->start < iter->end) {
- node = iter->arc->tail;
- }
- else {
- node = iter->arc->head;
- }
-
- iter->p = node->p;
- iter->no = node->no;
- iter->size = 0;
-
- return node;
-}
-
-static void *nextBucket(void *arg)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
- EmbedBucket *result = NULL;
-
- iter->index++;
-
- if (iter->index < iter->length) {
- result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]);
- }
-
- setIteratorValues(iter, result);
- return result;
-}
-
-static void *nextNBucket(void *arg, int n)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
- EmbedBucket *result = NULL;
-
- iter->index += n;
-
- /* check if passed end */
- if (iter->index < iter->length) {
- result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]);
- }
-
- setIteratorValues(iter, result);
- return result;
-}
-
-static void *peekBucket(void *arg, int n)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
- EmbedBucket *result = NULL;
- int index = iter->index + n;
-
- /* check if passed end */
- if (index < iter->length) {
- result = &(iter->arc->buckets[iter->start + (iter->stride * index)]);
- }
-
- setIteratorValues(iter, result);
- return result;
-}
-
-static void *previousBucket(void *arg)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
- EmbedBucket *result = NULL;
-
- if (iter->index > 0) {
- iter->index--;
- result = &(iter->arc->buckets[iter->start + (iter->stride * iter->index)]);
- }
-
- setIteratorValues(iter, result);
- return result;
-}
-
-static int iteratorStopped(void *arg)
-{
- ReebArcIterator *iter = (ReebArcIterator *)arg;
-
- if (iter->index >= iter->length) {
- return 1;
- }
- else {
- return 0;
- }
-}
-
-/************************ PUBLIC FUNCTIONS *********************************************/
-
-ReebGraph *BIF_ReebGraphMultiFromEditMesh(bContext *C)
-{
- (void)C;
- return NULL;
-#if 0
- Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- EditMesh *em = BKE_mesh_get_editmesh(((Mesh *)obedit->data));
- EdgeIndex indexed_edges;
- VertexData *data;
- ReebGraph *rg = NULL;
- ReebGraph *rgi, *previous;
- int i, nb_levels = REEB_MAX_MULTI_LEVEL;
-
- if (em == NULL)
- return NULL;
-
- data = allocVertexData(em);
-
- buildIndexedEdges(em, &indexed_edges);
-
- if (weightFromDistance(em, &indexed_edges) == 0)
- {
- // XXX error("No selected vertex\n");
- freeEdgeIndex(&indexed_edges);
- return NULL;
- }
-
- renormalizeWeight(em, 1.0f);
-
- if (scene->toolsettings->skgen_options & SKGEN_HARMONIC)
- {
- weightToHarmonic(em, &indexed_edges);
- }
-
- freeEdgeIndex(&indexed_edges);
-
- rg = generateReebGraph(em, scene->toolsettings->skgen_resolution);
-
- /* Remove arcs without embedding */
- filterNullReebGraph(rg);
-
- /* smart filter and loop filter on basic level */
- filterGraph(rg, SKGEN_FILTER_SMART, 0, 0);
-
- repositionNodes(rg);
-
- /* Filtering might have created degree 2 nodes, so remove them */
- removeNormalNodes(rg);
-
- joinSubgraphs(rg, 1.0);
-
- BLI_buildAdjacencyList((BGraph *)rg);
-
- /* calc length before copy, so we have same length on all levels */
- BLI_calcGraphLength((BGraph *)rg);
-
- previous = NULL;
- for (i = 0; i <= nb_levels; i++)
- {
- rgi = rg;
-
- /* don't filter last level */
- if (i > 0)
- {
- float internal_threshold;
- float external_threshold;
-
- /* filter internal progressively in second half only*/
- if (i > nb_levels / 2)
- {
- internal_threshold = rg->length * scene->toolsettings->skgen_threshold_internal;
- }
- else {
- internal_threshold = rg->length * scene->toolsettings->skgen_threshold_internal * (2 * i / (float)nb_levels);
- }
-
- external_threshold = rg->length * scene->toolsettings->skgen_threshold_external * (i / (float)nb_levels);
-
- filterGraph(rgi, scene->toolsettings->skgen_options, internal_threshold, external_threshold);
- }
-
- if (i < nb_levels)
- {
- rg = copyReebGraph(rgi, i + 1);
- }
-
- finalizeGraph(rgi, scene->toolsettings->skgen_postpro_passes, scene->toolsettings->skgen_postpro);
-
- BLI_markdownSymmetry((BGraph *)rgi, rgi->nodes.first, scene->toolsettings->skgen_symmetry_limit);
-
- if (previous != NULL)
- {
- relinkNodes(rgi, previous);
- }
- previous = rgi;
- }
-
- verifyMultiResolutionLinks(rg, 0);
-
- MEM_freeN(data);
-
- /* no need to load the editmesh back into the object, just
- * free it (avoids ngon conversion issues too going back the other way) */
- free_editMesh(em);
- MEM_freeN(em);
-
- return rg;
-#endif
-}
-
-#if 0
-
-ReebGraph *BIF_ReebGraphFromEditMesh(void)
-{
- EditMesh *em = G.editMesh;
- EdgeIndex indexed_edges;
- VertexData *data;
- ReebGraph *rg = NULL;
-
- if (em == NULL)
- return NULL;
-
- data = allocVertexData(em);
-
- buildIndexedEdges(em, &indexed_edges);
-
- if (weightFromDistance(em, &indexed_edges) == 0)
- {
- error("No selected vertex\n");
- freeEdgeIndex(&indexed_edges);
- freeEdgeIndex(&indexed_edges);
- return NULL;
- }
-
- renormalizeWeight(em, 1.0f);
-
- if (G.scene->toolsettings->skgen_options & SKGEN_HARMONIC)
- {
- weightToHarmonic(em, &indexed_edges);
- }
-
- freeEdgeIndex(&indexed_edges);
-
-#ifdef DEBUG_REEB
-// weightToVCol(em, 1);
-#endif
-
- rg = generateReebGraph(em, G.scene->toolsettings->skgen_resolution);
-
-
- /* Remove arcs without embedding */
- filterNullReebGraph(rg);
-
- /* smart filter and loop filter on basic level */
- filterGraph(rg, SKGEN_FILTER_SMART, 0, 0);
-
- repositionNodes(rg);
-
- /* Filtering might have created degree 2 nodes, so remove them */
- removeNormalNodes(rg);
-
- joinSubgraphs(rg, 1.0);
-
- BLI_buildAdjacencyList((BGraph *)rg);
-
- /* calc length before copy, so we have same length on all levels */
- BLI_calcGraphLength((BGraph *)rg);
-
- filterGraph(rg, G.scene->toolsettings->skgen_options, G.scene->toolsettings->skgen_threshold_internal, G.scene->toolsettings->skgen_threshold_external);
-
- finalizeGraph(rg, G.scene->toolsettings->skgen_postpro_passes, G.scene->toolsettings->skgen_postpro);
-
-#ifdef DEBUG_REEB
- REEB_exportGraph(rg, -1);
-
- arcToVCol(rg, em, 0);
- //angleToVCol(em, 1);
-#endif
-
- printf("DONE\n");
- printf("%i subgraphs\n", BLI_FlagSubgraphs((BGraph *)rg));
-
- MEM_freeN(data);
-
- return rg;
-}
-
-void BIF_GlobalReebFree()
-{
- if (GLOBAL_RG != NULL)
- {
- REEB_freeGraph(GLOBAL_RG);
- GLOBAL_RG = NULL;
- }
-}
-
-void BIF_GlobalReebGraphFromEditMesh(void)
-{
- ReebGraph *rg;
-
- BIF_GlobalReebFree();
-
- rg = BIF_ReebGraphMultiFromEditMesh();
-
- GLOBAL_RG = rg;
-}
-
-void REEB_draw()
-{
- ReebGraph *rg;
- ReebArc *arc;
- int i = 0;
-
- if (GLOBAL_RG == NULL)
- {
- return;
- }
-
- if (GLOBAL_RG->link_up && G.scene->toolsettings->skgen_options & SKGEN_DISP_ORIG)
- {
- for (rg = GLOBAL_RG; rg->link_up; rg = rg->link_up) ;
- }
- else {
- i = G.scene->toolsettings->skgen_multi_level;
-
- for (rg = GLOBAL_RG; rg->multi_level != i && rg->link_up; rg = rg->link_up) ;
- }
-
- glPointSize(BIF_GetThemeValuef(TH_VERTEX_SIZE));
-
- glDisable(GL_DEPTH_TEST);
- for (arc = rg->arcs.first; arc; arc = arc->next, i++)
- {
- ReebArcIterator arc_iter;
- BArcIterator *iter = (BArcIterator *)&arc_iter;
- float vec[3];
- char text[128];
- char *s = text;
-
- glLineWidth(BIF_GetThemeValuef(TH_VERTEX_SIZE) + 2);
- glColor3f(0, 0, 0);
- glBegin(GL_LINE_STRIP);
- glVertex3fv(arc->head->p);
-
- if (arc->bcount)
- {
- initArcIterator(iter, arc, arc->head);
- for (IT_next(iter); IT_stopped(iter) == 0; IT_next(iter))
- {
- glVertex3fv(iter->p);
- }
- }
-
- glVertex3fv(arc->tail->p);
- glEnd();
-
- glLineWidth(BIF_GetThemeValuef(TH_VERTEX_SIZE));
-
- if (arc->symmetry_level == 1)
- {
- glColor3f(1, 0, 0);
- }
- else if (arc->symmetry_flag == SYM_SIDE_POSITIVE || arc->symmetry_flag == SYM_SIDE_NEGATIVE)
- {
- glColor3f(1, 0.5f, 0);
- }
- else if (arc->symmetry_flag >= SYM_SIDE_RADIAL)
- {
- glColor3f(0.5f, 1, 0);
- }
- else {
- glColor3f(1, 1, 0);
- }
- glBegin(GL_LINE_STRIP);
- glVertex3fv(arc->head->p);
-
- if (arc->bcount)
- {
- initArcIterator(iter, arc, arc->head);
- for (iter->next(iter); IT_stopped(iter) == 0; iter->next(iter))
- {
- glVertex3fv(iter->p);
- }
- }
-
- glVertex3fv(arc->tail->p);
- glEnd();
-
-
- if (G.scene->toolsettings->skgen_options & SKGEN_DISP_EMBED)
- {
- glColor3f(1, 1, 1);
- glBegin(GL_POINTS);
- glVertex3fv(arc->head->p);
- glVertex3fv(arc->tail->p);
-
- glColor3f(0.5f, 0.5f, 1);
- if (arc->bcount)
- {
- initArcIterator(iter, arc, arc->head);
- for (iter->next(iter); IT_stopped(iter) == 0; iter->next(iter))
- {
- glVertex3fv(iter->p);
- }
- }
- glEnd();
- }
-
- if (G.scene->toolsettings->skgen_options & SKGEN_DISP_INDEX)
- {
- mid_v3_v3v3(vec, arc->head->p, arc->tail->p);
- s += sprintf(s, "%i (%i-%i-%i) ", i, arc->symmetry_level, arc->symmetry_flag, arc->symmetry_group);
-
- if (G.scene->toolsettings->skgen_options & SKGEN_DISP_WEIGHT)
- {
- s += sprintf(s, "w:%0.3f ", arc->tail->weight - arc->head->weight);
- }
-
- if (G.scene->toolsettings->skgen_options & SKGEN_DISP_LENGTH)
- {
- s += sprintf(s, "l:%0.3f", arc->length);
- }
-
- glColor3f(0, 1, 0);
- glRasterPos3fv(vec);
- BMF_DrawString(G.fonts, text);
- }
-
- if (G.scene->toolsettings->skgen_options & SKGEN_DISP_INDEX)
- {
- sprintf(text, " %i", arc->head->index);
- glRasterPos3fv(arc->head->p);
- BMF_DrawString(G.fonts, text);
-
- sprintf(text, " %i", arc->tail->index);
- glRasterPos3fv(arc->tail->p);
- BMF_DrawString(G.fonts, text);
- }
- }
- glEnable(GL_DEPTH_TEST);
-}
-
-#endif
diff --git a/source/blender/editors/armature/reeb.h b/source/blender/editors/armature/reeb.h
deleted file mode 100644
index a6ef16fed67..00000000000
--- a/source/blender/editors/armature/reeb.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Martin Poirier
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/armature/reeb.h
- * \ingroup edarmature
- */
-
-
-#ifndef __REEB_H__
-#define __REEB_H__
-
-#define WITH_BF_REEB
-
-#include "DNA_listBase.h"
-
-#include "BLI_graph.h"
-
-struct GHash;
-struct EdgeHash;
-struct ReebArc;
-struct ReebEdge;
-struct ReebNode;
-
-typedef struct ReebGraph {
- ListBase arcs;
- ListBase nodes;
-
- float length;
-
- FreeArc free_arc;
- FreeNode free_node;
- RadialSymmetry radial_symmetry;
- AxialSymmetry axial_symmetry;
- /*********************************/
-
- int resolution;
- int totnodes;
- struct EdgeHash *emap;
- int multi_level;
- struct ReebGraph *link_up; /* for multi resolution filtering, points to higher levels */
-} ReebGraph;
-
-typedef struct EmbedBucket {
- float val;
- int nv;
- float p[3];
- float no[3]; /* if non-null, normal of the bucket */
-} EmbedBucket;
-
-typedef struct ReebNode {
- void *next, *prev;
- float p[3];
- int flag;
-
- int degree;
- struct ReebArc **arcs;
-
- int subgraph_index;
-
- int symmetry_level;
- int symmetry_flag;
- float symmetry_axis[3];
- /*********************************/
-
- float no[3];
-
- int index;
- float weight;
- int multi_level;
- struct ReebNode *link_down; /* for multi resolution filtering, points to lower levels, if present */
- struct ReebNode *link_up;
-} ReebNode;
-
-typedef struct ReebEdge {
- struct ReebEdge *next, *prev;
- struct ReebArc *arc;
- struct ReebNode *v1, *v2;
- struct ReebEdge *nextEdge;
- int flag;
-} ReebEdge;
-
-typedef struct ReebArc {
- void *next, *prev;
- struct ReebNode *head, *tail;
- int flag;
-
- float length;
-
- int symmetry_level;
- int symmetry_group;
- int symmetry_flag;
- /*********************************/
-
- ListBase edges;
- int bcount;
- struct EmbedBucket *buckets;
-
- struct GHash *faces;
- float angle;
- struct ReebArc *link_up; /* for multi resolution filtering, points to higher levels */
-} ReebArc;
-
-typedef struct ReebArcIterator {
- HeadFct head;
- TailFct tail;
- PeekFct peek;
- NextFct next;
- NextNFct nextN;
- PreviousFct previous;
- StoppedFct stopped;
-
- float *p, *no;
- float size;
-
- int length;
- int index;
- /*********************************/
- struct ReebArc *arc;
- int start;
- int end;
- int stride;
-} ReebArcIterator;
-
-#if 0
-struct EditMesh;
-struct EdgeIndex;
-
-int weightToHarmonic(struct EditMesh *em, struct EdgeIndex *indexed_edges);
-int weightFromDistance(struct EditMesh *em, struct EdgeIndex *indexed_edges);
-int weightFromLoc(struct EditMesh *me, int axis);
-//void weightToVCol(struct EditMesh *em, int index);
-void arcToVCol(struct ReebGraph *rg, struct EditMesh *em, int index);
-//void angleToVCol(struct EditMesh *em, int index);
-void renormalizeWeight(struct EditMesh *em, float newmax);
-
-ReebGraph *generateReebGraph(struct EditMesh *me, int subdivisions);
-#endif
-
-ReebGraph *newReebGraph(void);
-
-void initArcIterator(BArcIterator *iter, struct ReebArc *arc, struct ReebNode *head);
-void initArcIterator2(BArcIterator *iter, struct ReebArc *arc, int start, int end);
-void initArcIteratorStart(BArcIterator *iter, struct ReebArc *arc, struct ReebNode *head, int start);
-
-/* Filtering */
-void filterNullReebGraph(ReebGraph *rg);
-int filterSmartReebGraph(ReebGraph *rg, float threshold);
-
-/* Post-Build processing */
-void repositionNodes(ReebGraph *rg);
-void postprocessGraph(ReebGraph *rg, char mode);
-void removeNormalNodes(ReebGraph *rg);
-
-void sortNodes(ReebGraph *rg);
-void sortArcs(ReebGraph *rg);
-
-/*------------ Sanity check ------------*/
-void verifyBuckets(ReebGraph *rg);
-void verifyFaces(ReebGraph *rg);
-void verifyArcs(ReebGraph *rg);
-void verifyNodeDegree(ReebGraph *rg);
-
-/*********************** PUBLIC *********************************/
-
-#define REEB_MAX_MULTI_LEVEL 10
-
-struct bContext;
-
-ReebGraph *BIF_ReebGraphFromEditMesh(void);
-ReebGraph *BIF_ReebGraphMultiFromEditMesh(struct bContext *C);
-void BIF_flagMultiArcs(ReebGraph *rg, int flag);
-
-void BIF_GlobalReebGraphFromEditMesh(void);
-void BIF_GlobalReebFree(void);
-
-ReebNode *BIF_otherNodeFromIndex(ReebArc *arc, ReebNode *node);
-ReebNode *BIF_NodeFromIndex(ReebArc *arc, ReebNode *node);
-ReebNode *BIF_lowestLevelNode(ReebNode *node);
-
-ReebGraph *BIF_graphForMultiNode(ReebGraph *rg, ReebNode *node);
-
-void REEB_freeGraph(ReebGraph *rg);
-void REEB_freeArc(BArc *barc);
-void REEB_exportGraph(ReebGraph *rg, int count);
-void REEB_draw(void);
-
-
-#endif /*__REEB_H__*/
diff --git a/source/blender/editors/curve/CMakeLists.txt b/source/blender/editors/curve/CMakeLists.txt
index 13f12f62d95..301d333ebdb 100644
--- a/source/blender/editors/curve/CMakeLists.txt
+++ b/source/blender/editors/curve/CMakeLists.txt
@@ -23,10 +23,12 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../gpu
../../makesdna
../../makesrna
../../windowmanager
+ ../../../../intern/clog
../../../../intern/guardedalloc
../../../../intern/glew-mx
../../../../extern/curve_fit_nd
diff --git a/source/blender/editors/curve/editcurve.c b/source/blender/editors/curve/editcurve.c
index ebf2b63bb49..5cfdec4d5ad 100644
--- a/source/blender/editors/curve/editcurve.c
+++ b/source/blender/editors/curve/editcurve.c
@@ -45,11 +45,11 @@
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_displist.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_key.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_report.h"
@@ -57,6 +57,9 @@
#include "BKE_action.h"
#include "BKE_modifier.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -1278,6 +1281,7 @@ static int separate_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *oldob, *newob;
Base *oldbase, *newbase;
Curve *oldcu, *newcu;
@@ -1305,8 +1309,8 @@ static int separate_exec(bContext *C, wmOperator *op)
}
/* 2. duplicate the object and data */
- newbase = ED_object_add_duplicate(bmain, scene, oldbase, 0); /* 0 = fully linked */
- DAG_relations_tag_update(bmain);
+ newbase = ED_object_add_duplicate(bmain, scene, view_layer, oldbase, 0); /* 0 = fully linked */
+ DEG_relations_tag_update(bmain);
newob = newbase->object;
newcu = newob->data = BKE_curve_copy(bmain, oldcu);
@@ -1325,8 +1329,8 @@ static int separate_exec(bContext *C, wmOperator *op)
ED_curve_editnurb_free(newob);
curve_delete_segments(oldob, true);
- DAG_id_tag_update(&oldob->id, OB_RECALC_DATA); /* this is the original one */
- DAG_id_tag_update(&newob->id, OB_RECALC_DATA); /* this is the separated one */
+ DEG_id_tag_update(&oldob->id, OB_RECALC_DATA); /* this is the original one */
+ DEG_id_tag_update(&newob->id, OB_RECALC_DATA); /* this is the separated one */
WM_event_add_notifier(C, NC_GEOM | ND_DATA, oldob->data);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, newob);
@@ -1374,7 +1378,7 @@ static int curve_split_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
else {
BKE_report(op->reports, RPT_ERROR, "Cannot split current selection");
@@ -2320,7 +2324,7 @@ static int switch_direction_exec(bContext *C, wmOperator *UNUSED(op))
if (ED_curve_updateAnimPaths(obedit->data))
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -2368,7 +2372,7 @@ static int set_goal_weight_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -2421,7 +2425,7 @@ static int set_radius_exec(bContext *C, wmOperator *op)
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -2573,7 +2577,7 @@ static int smooth_exec(bContext *C, wmOperator *UNUSED(op))
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -2764,7 +2768,7 @@ static int curve_smooth_weight_exec(bContext *C, wmOperator *UNUSED(op))
curve_smooth_value(editnurb, offsetof(BezTriple, weight), offsetof(BPoint, weight));
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -2792,7 +2796,7 @@ static int curve_smooth_radius_exec(bContext *C, wmOperator *UNUSED(op))
curve_smooth_value(editnurb, offsetof(BezTriple, radius), offsetof(BPoint, radius));
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -2820,7 +2824,7 @@ static int curve_smooth_tilt_exec(bContext *C, wmOperator *UNUSED(op))
curve_smooth_value(editnurb, offsetof(BezTriple, alfa), offsetof(BPoint, alfa));
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -2892,7 +2896,7 @@ static int hide_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
BKE_curve_nurb_vert_active_validate(obedit->data);
@@ -2955,7 +2959,7 @@ static int reveal_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
return OPERATOR_FINISHED;
@@ -3376,7 +3380,7 @@ static int subdivide_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -3571,7 +3575,7 @@ static int set_spline_type_exec(bContext *C, wmOperator *op)
if (ED_curve_updateAnimPaths(obedit->data))
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
if (changed_size) {
@@ -3625,7 +3629,7 @@ static int set_handle_type_exec(bContext *C, wmOperator *op)
BKE_nurbList_handles_set(editnurb, RNA_enum_get(op->ptr, "type"));
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -3670,7 +3674,7 @@ static int curve_normals_make_consistent_exec(bContext *C, wmOperator *op)
BKE_nurbList_handles_recalculate(editnurb, calc_length, SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -4058,7 +4062,7 @@ static int merge_nurb(bContext *C, wmOperator *op)
BKE_curve_nurb_active_set(obedit->data, NULL);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -4265,7 +4269,7 @@ static int make_segment_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -4509,7 +4513,7 @@ static int spin_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -4964,7 +4968,7 @@ static int add_vertex_exec(bContext *C, wmOperator *op)
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -5009,14 +5013,13 @@ static int add_vertex_invoke(bContext *C, wmOperator *op, const wmEvent *event)
const float mval[2] = {UNPACK2(event->mval)};
struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
- CTX_data_main(C), vc.scene, 0,
- vc.ar, vc.v3d);
+ CTX_data_main(C), vc.scene, CTX_data_depsgraph(C), 0, vc.ar, vc.v3d);
ED_transform_snap_object_project_view3d_mixed(
snap_context,
SCE_SELECT_FACE,
&(const struct SnapObjectParams){
- .snap_select = (vc.scene->obedit != NULL) ? SNAP_NOT_ACTIVE : SNAP_ALL,
+ .snap_select = (vc.obedit != NULL) ? SNAP_NOT_ACTIVE : SNAP_ALL,
.use_object_edit_cage = false,
},
mval, NULL, true,
@@ -5119,7 +5122,7 @@ static int curve_extrude_exec(bContext *C, wmOperator *UNUSED(op))
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
return OPERATOR_FINISHED;
@@ -5218,7 +5221,7 @@ static int toggle_cyclic_exec(bContext *C, wmOperator *op)
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -5736,7 +5739,7 @@ static int curve_delete_exec(bContext *C, wmOperator *op)
if (ED_curve_updateAnimPaths(obedit->data)) WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return retval;
}
@@ -5880,7 +5883,7 @@ static int curve_dissolve_exec(bContext *C, wmOperator *UNUSED(op))
if (ED_curve_updateAnimPaths(obedit->data)) WM_event_add_notifier(C, NC_OBJECT | ND_KEYS, obedit);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
return OPERATOR_FINISHED;
@@ -5956,7 +5959,7 @@ static int curve_decimate_exec(bContext *C, wmOperator *op)
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
return OPERATOR_FINISHED;
@@ -6001,7 +6004,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op)
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -6115,7 +6118,7 @@ int join_curve_exec(bContext *C, wmOperator *op)
}
}
- ED_base_object_free_and_unlink(bmain, scene, base);
+ ED_object_base_free_and_unlink(bmain, scene, base->object);
}
}
}
@@ -6129,9 +6132,9 @@ int join_curve_exec(bContext *C, wmOperator *op)
BKE_curve_curve_dimension_update(cu);
}
- DAG_relations_tag_update(bmain); // because we removed object(s), call before editmode!
+ DEG_relations_tag_update(bmain); // because we removed object(s), call before editmode!
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
@@ -6171,7 +6174,7 @@ static int clear_tilt_exec(bContext *C, wmOperator *UNUSED(op))
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_FINISHED;
}
@@ -6234,6 +6237,7 @@ static int match_texture_space_poll(bContext *C)
static int match_texture_space_exec(bContext *C, wmOperator *UNUSED(op))
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *object = CTX_data_active_object(C);
Curve *curve = (Curve *) object->data;
@@ -6241,7 +6245,7 @@ static int match_texture_space_exec(bContext *C, wmOperator *UNUSED(op))
int a;
if (object->curve_cache == NULL) {
- BKE_displist_make_curveTypes(scene, object, false);
+ BKE_displist_make_curveTypes(depsgraph, scene, object, false);
}
INIT_MINMAX(min, max);
diff --git a/source/blender/editors/curve/editcurve_add.c b/source/blender/editors/curve/editcurve_add.c
index b23f0f967ec..f269799973f 100644
--- a/source/blender/editors/curve/editcurve_add.c
+++ b/source/blender/editors/curve/editcurve_add.c
@@ -42,9 +42,10 @@
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_library.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "WM_api.h"
@@ -502,7 +503,7 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
cu->flag |= CU_PATH | CU_3D;
}
else {
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
}
}
else { /* adding surface */
@@ -512,7 +513,7 @@ static int curvesurf_prim_add(bContext *C, wmOperator *op, int type, int isSurf)
newob = true;
}
else {
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
}
}
diff --git a/source/blender/editors/curve/editcurve_paint.c b/source/blender/editors/curve/editcurve_paint.c
index 0d7cb089c4f..669c6283856 100644
--- a/source/blender/editors/curve/editcurve_paint.c
+++ b/source/blender/editors/curve/editcurve_paint.c
@@ -33,10 +33,11 @@
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -46,7 +47,11 @@
#include "ED_curve.h"
#include "BIF_gl.h"
-#include "BIF_glutil.h"
+
+#include "GPU_batch.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
#include "curve_intern.h"
@@ -88,6 +93,8 @@ struct StrokeElem {
};
struct CurveDrawData {
+ Depsgraph *depsgraph;
+
short init_event_type;
short curve_type;
@@ -128,7 +135,6 @@ struct CurveDrawData {
} prev;
ViewContext vc;
- bglMats mats;
enum {
CURVE_DRAW_IDLE = 0,
CURVE_DRAW_PAINTING = 1,
@@ -195,7 +201,7 @@ static bool stroke_elem_project(
if (cdd->project.use_plane) {
/* get the view vector to 'location' */
float ray_origin[3], ray_direction[3];
- ED_view3d_win_to_ray(cdd->vc.ar, v3d, mval_fl, ray_origin, ray_direction, false);
+ ED_view3d_win_to_ray(cdd->depsgraph, cdd->vc.ar, v3d, mval_fl, ray_origin, ray_direction, false);
float lambda;
if (isect_ray_plane_v3(ray_origin, ray_direction, cdd->project.plane, &lambda, true)) {
@@ -214,7 +220,7 @@ static bool stroke_elem_project(
{
const double depth = (double)ED_view3d_depth_read_cached(&cdd->vc, mval_i);
if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
- if (ED_view3d_depth_unproject(ar, &cdd->mats, mval_i, depth, r_location_world)) {
+ if (ED_view3d_depth_unproject(ar, mval_i, depth, r_location_world)) {
is_location_world_set = true;
if (r_normal_world) {
zero_v3(r_normal_world);
@@ -223,7 +229,7 @@ static bool stroke_elem_project(
if (surface_offset != 0.0f) {
const float offset = cdd->project.use_surface_offset_absolute ? 1.0f : radius;
float normal[3];
- if (ED_view3d_depth_read_cached_normal(&cdd->vc, &cdd->mats, mval_i, normal)) {
+ if (ED_view3d_depth_read_cached_normal(&cdd->vc, mval_i, normal)) {
madd_v3_v3fl(r_location_world, normal, offset * surface_offset);
if (r_normal_world) {
copy_v3_v3(r_normal_world, normal);
@@ -369,39 +375,43 @@ static void curve_draw_stroke_3d(const struct bContext *UNUSED(C), ARegion *UNUS
Object *obedit = cdd->vc.obedit;
Curve *cu = obedit->data;
- UI_ThemeColor(TH_WIRE);
-
if (cu->ext2 > 0.0f) {
- GLUquadricObj *qobj = gluNewQuadric();
-
- gluQuadricDrawStyle(qobj, GLU_FILL);
-
BLI_mempool_iter iter;
const struct StrokeElem *selem;
const float location_zero[3] = {0};
const float *location_prev = location_zero;
+ float color[3];
+ UI_GetThemeColor3fv(TH_WIRE, color);
+
+ Gwn_Batch *sphere = GPU_batch_preset_sphere(0);
+ GWN_batch_program_set_builtin(sphere, GPU_SHADER_3D_UNIFORM_COLOR);
+ GWN_batch_uniform_3fv(sphere, "color", color);
+
/* scale to edit-mode space */
- glPushMatrix();
- glMultMatrixf(obedit->obmat);
+ gpuPushMatrix();
+ gpuMultMatrix(obedit->obmat);
BLI_mempool_iternew(cdd->stroke_elem_pool, &iter);
for (selem = BLI_mempool_iterstep(&iter); selem; selem = BLI_mempool_iterstep(&iter)) {
- glTranslatef(
+ gpuTranslate3f(
selem->location_local[0] - location_prev[0],
selem->location_local[1] - location_prev[1],
selem->location_local[2] - location_prev[2]);
location_prev = selem->location_local;
+
const float radius = stroke_elem_radius(cdd, selem);
- gluSphere(qobj, radius, 12, 8);
+
+ gpuPushMatrix();
+ gpuScaleUniform(radius);
+ GWN_batch_draw(sphere);
+ gpuPopMatrix();
location_prev = selem->location_local;
}
- glPopMatrix();
-
- gluDeleteQuadric(qobj);
+ gpuPopMatrix();
}
if (stroke_len > 1) {
@@ -418,30 +428,45 @@ static void curve_draw_stroke_3d(const struct bContext *UNUSED(C), ARegion *UNUS
}
{
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, coord_array);
-
- cpack(0x0);
+ imm_cpack(0x0);
+ immBegin(GWN_PRIM_LINE_STRIP, stroke_len);
glLineWidth(3.0f);
- glDrawArrays(GL_LINE_STRIP, 0, stroke_len);
- if (v3d->zbuf)
+ if (v3d->zbuf) {
glDisable(GL_DEPTH_TEST);
+ }
+
+ for (int i = 0; i < stroke_len; i++) {
+ immVertex3fv(pos, coord_array[i]);
+ }
+
+ immEnd();
- cpack(0xffffffff);
+ imm_cpack(0xffffffff);
+ immBegin(GWN_PRIM_LINE_STRIP, stroke_len);
glLineWidth(1.0f);
- glDrawArrays(GL_LINE_STRIP, 0, stroke_len);
- if (v3d->zbuf)
- glEnable(GL_DEPTH_TEST);
+ for (int i = 0; i < stroke_len; i++) {
+ immVertex3fv(pos, coord_array[i]);
+ }
- glDisableClientState(GL_VERTEX_ARRAY);
+ immEnd();
+
+ if (v3d->zbuf) {
+ glEnable(GL_DEPTH_TEST);
+ }
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
+
+ immUnbindProgram();
}
MEM_freeN(coord_array);
@@ -531,7 +556,7 @@ static void curve_draw_event_add_first(wmOperator *op, const wmEvent *event)
CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW,
CURVE_PAINT_SURFACE_PLANE_NORMAL_SURFACE))
{
- if (ED_view3d_depth_read_cached_normal(&cdd->vc, &cdd->mats, event->mval, normal)) {
+ if (ED_view3d_depth_read_cached_normal(&cdd->vc, event->mval, normal)) {
if (cps->surface_plane == CURVE_PAINT_SURFACE_PLANE_NORMAL_VIEW) {
float cross_a[3], cross_b[3];
cross_v3_v3v3(cross_a, rv3d->viewinv[2], normal);
@@ -580,6 +605,8 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
struct CurveDrawData *cdd = MEM_callocN(sizeof(*cdd), __func__);
+ cdd->depsgraph = CTX_data_depsgraph(C);
+
if (is_invoke) {
ED_view3d_viewcontext_init(C, &cdd->vc);
if (ELEM(NULL, cdd->vc.ar, cdd->vc.rv3d, cdd->vc.v3d, cdd->vc.win, cdd->vc.scene)) {
@@ -589,7 +616,9 @@ static bool curve_draw_init(bContext *C, wmOperator *op, bool is_invoke)
}
}
else {
+ cdd->vc.depsgraph = CTX_data_depsgraph(C);
cdd->vc.scene = CTX_data_scene(C);
+ cdd->vc.view_layer = CTX_data_view_layer(C);
cdd->vc.obedit = CTX_data_edit_object(C);
}
@@ -682,7 +711,7 @@ static void curve_draw_exec_precalc(wmOperator *op)
const struct StrokeElem *selem, *selem_first, *selem_last;
BLI_mempool_iternew(cdd->stroke_elem_pool, &iter);
- selem_first = BLI_mempool_iterstep(&iter);
+ selem_first = selem_last = BLI_mempool_iterstep(&iter);
for (selem = BLI_mempool_iterstep(&iter); selem; selem = BLI_mempool_iterstep(&iter)) {
selem_last = selem;
}
@@ -759,7 +788,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
struct CurveDrawData *cdd = op->customdata;
const CurvePaintSettings *cps = &cdd->vc.scene->toolsettings->curve_paint_settings;
- Object *obedit = cdd->vc.scene->obedit;
+ Object *obedit = cdd->vc.obedit;
Curve *cu = obedit->data;
ListBase *nurblist = object_editcurve_get(obedit);
@@ -1011,7 +1040,7 @@ static int curve_draw_exec(bContext *C, wmOperator *op)
cu->actvert = nu->pntsu - 1;
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
curve_draw_exit(op);
@@ -1066,12 +1095,10 @@ static int curve_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event)
if ((cps->depth_mode == CURVE_PAINT_PROJECT_SURFACE) &&
(v3d->drawtype > OB_WIRE))
{
- view3d_get_transformation(cdd->vc.ar, cdd->vc.rv3d, NULL, &cdd->mats);
-
/* needed or else the draw matrix can be incorrect */
view3d_operator_needs_opengl(C);
- ED_view3d_autodist_init(cdd->vc.scene, cdd->vc.ar, cdd->vc.v3d, 0);
+ ED_view3d_autodist_init(cdd->vc.depsgraph, cdd->vc.ar, cdd->vc.v3d, 0);
if (cdd->vc.rv3d->depths) {
cdd->vc.rv3d->depths->damaged = true;
diff --git a/source/blender/editors/curve/editcurve_select.c b/source/blender/editors/curve/editcurve_select.c
index 673faa37f2a..4d87503fd69 100644
--- a/source/blender/editors/curve/editcurve_select.c
+++ b/source/blender/editors/curve/editcurve_select.c
@@ -1599,6 +1599,7 @@ static void curve_select_shortest_path_surf(Nurb *nu, int vert_src, int vert_dst
/* init heap */
heap = BLI_heap_new();
+ vert_curr = data[vert_src].vert;
BLI_heap_insert(heap, 0.0f, &data[vert_src].vert);
data[vert_src].cost = 0.0f;
data[vert_src].vert_prev = vert_src; /* nop */
diff --git a/source/blender/editors/curve/editcurve_undo.c b/source/blender/editors/curve/editcurve_undo.c
index 4ced6ce506c..ad17331853b 100644
--- a/source/blender/editors/curve/editcurve_undo.c
+++ b/source/blender/editors/curve/editcurve_undo.c
@@ -22,12 +22,14 @@
* \ingroup edcurve
*/
+#include "MEM_guardedalloc.h"
+
+#include "CLG_log.h"
+
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "DNA_anim_types.h"
-#include "MEM_guardedalloc.h"
-
#include "BLI_blenlib.h"
#include "BLI_ghash.h"
#include "BLI_array_utils.h"
@@ -35,12 +37,15 @@
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_fcurve.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_object.h"
+#include "ED_undo.h"
#include "ED_util.h"
#include "ED_curve.h"
@@ -49,6 +54,9 @@
#include "curve_intern.h"
+/** We only need this locally. */
+static CLG_LogRef LOG = {"ed.undo.curve"};
+
/* -------------------------------------------------------------------- */
/** \name Undo Conversion
* \{ */
@@ -186,13 +194,19 @@ static Object *editcurve_object_from_context(bContext *C)
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
+ *
+ * \note This is similar for all edit-mode types.
* \{ */
-typedef struct CurveUndoStep {
- UndoStep step;
- /* note: will split out into list for multi-object-editmode. */
+typedef struct CurveUndoStep_Elem {
UndoRefID_Object obedit_ref;
UndoCurve data;
+} CurveUndoStep_Elem;
+
+typedef struct CurveUndoStep {
+ UndoStep step;
+ CurveUndoStep_Elem *elems;
+ uint elems_len;
} CurveUndoStep;
static bool curve_undosys_poll(bContext *C)
@@ -204,9 +218,23 @@ static bool curve_undosys_poll(bContext *C)
static bool curve_undosys_step_encode(struct bContext *C, UndoStep *us_p)
{
CurveUndoStep *us = (CurveUndoStep *)us_p;
- us->obedit_ref.ptr = editcurve_object_from_context(C);
- undocurve_from_editcurve(&us->data, us->obedit_ref.ptr->data, us->obedit_ref.ptr->shapenr);
- us->step.data_size = us->data.undo_size;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__);
+ us->elems_len = objects_len;
+
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ CurveUndoStep_Elem *elem = &us->elems[i];
+
+ elem->obedit_ref.ptr = ob;
+ undocurve_from_editcurve(&elem->data, ob->data, ob->shapenr);
+ us->step.data_size += elem->data.undo_size;
+ }
+ MEM_freeN(objects);
return true;
}
@@ -217,23 +245,47 @@ static void curve_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UN
BLI_assert(curve_undosys_poll(C));
CurveUndoStep *us = (CurveUndoStep *)us_p;
- Object *obedit = us->obedit_ref.ptr;
- undocurve_to_editcurve(&us->data, obedit->data, &obedit->shapenr);
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ CurveUndoStep_Elem *elem = &us->elems[i];
+ Object *obedit = elem->obedit_ref.ptr;
+ Curve *cu = obedit->data;
+ if (cu->editnurb == NULL) {
+ /* Should never fail, may not crash but can give odd behavior. */
+ CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid",
+ us_p->name, obedit->id.name);
+ continue;
+ }
+ undocurve_to_editcurve(&elem->data, obedit->data, &obedit->shapenr);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ }
+
+ /* The first element is always active */
+ ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
+
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
static void curve_undosys_step_free(UndoStep *us_p)
{
CurveUndoStep *us = (CurveUndoStep *)us_p;
- undocurve_free_data(&us->data);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ CurveUndoStep_Elem *elem = &us->elems[i];
+ undocurve_free_data(&elem->data);
+ }
+ MEM_freeN(us->elems);
}
static void curve_undosys_foreach_ID_ref(
UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
{
CurveUndoStep *us = (CurveUndoStep *)us_p;
- foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref));
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ CurveUndoStep_Elem *elem = &us->elems[i];
+ foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref));
+ }
}
/* Export for ED_undo_sys. */
diff --git a/source/blender/editors/curve/editfont.c b/source/blender/editors/curve/editfont.c
index d651f673a7f..a9a8901acc6 100644
--- a/source/blender/editors/curve/editfont.c
+++ b/source/blender/editors/curve/editfont.c
@@ -49,13 +49,14 @@
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_font.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -254,7 +255,7 @@ static void text_update_edited(bContext *C, Object *obedit, int mode)
/* run update first since it can move the cursor */
if (mode == FO_EDIT) {
/* re-tesselllate */
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
else {
/* depsgraph runs above, but since we're not tagging for update, call direct */
@@ -273,6 +274,8 @@ static void text_update_edited(bContext *C, Object *obedit, int mode)
}
}
+ BKE_curve_batch_cache_dirty(cu, BKE_CURVE_BATCH_DIRTY_SELECT);
+
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
@@ -419,7 +422,9 @@ void FONT_OT_text_paste_from_file(wmOperatorType *ot)
static void txt_add_object(bContext *C, TextLine *firstline, int totline, const float offset[3])
{
Main *bmain = CTX_data_main(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Curve *cu;
Object *obedit;
Base *base;
@@ -429,13 +434,13 @@ static void txt_add_object(bContext *C, TextLine *firstline, int totline, const
int a;
float rot[3] = {0.f, 0.f, 0.f};
- obedit = BKE_object_add(bmain, scene, OB_FONT, NULL);
- base = scene->basact;
+ obedit = BKE_object_add(bmain, scene, view_layer, OB_FONT, NULL);
+ base = view_layer->basact;
/* seems to assume view align ? TODO - look into this, could be an operator option */
ED_object_base_init_transform(C, base, NULL, rot);
- BKE_object_where_is_calc(scene, obedit);
+ BKE_object_where_is_calc(depsgraph, scene, obedit);
add_v3_v3(obedit->loc, offset);
@@ -582,7 +587,7 @@ static int set_style(bContext *C, const int style, const bool clear)
ef->textbufinfo[i].flag |= style;
}
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/curve/editfont_undo.c b/source/blender/editors/curve/editfont_undo.c
index 3a76d0333f9..d4d48e93f43 100644
--- a/source/blender/editors/curve/editfont_undo.c
+++ b/source/blender/editors/curve/editfont_undo.c
@@ -38,9 +38,10 @@
#include "BKE_context.h"
#include "BKE_font.h"
-#include "BKE_depsgraph.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_object.h"
#include "ED_curve.h"
#include "ED_util.h"
@@ -358,7 +359,7 @@ static void font_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNU
Object *obedit = us->obedit_ref.ptr;
Curve *cu = obedit->data;
undofont_to_editfont(&us->data, cu);
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
diff --git a/source/blender/editors/datafiles/CMakeLists.txt b/source/blender/editors/datafiles/CMakeLists.txt
index 3f6de14180a..3ebf3c60ab2 100644
--- a/source/blender/editors/datafiles/CMakeLists.txt
+++ b/source/blender/editors/datafiles/CMakeLists.txt
@@ -152,6 +152,7 @@ set(ICON_NAMES
pose_hlt
particlemode
lightpaint
+ greasepencil_stroke_paint
scene_data
renderlayers
world_data
@@ -194,6 +195,7 @@ set(ICON_NAMES
library_data_indirect
greasepencil
line_data
+ library_data_override
group_bone
group_vertex
group_vcol
@@ -213,6 +215,7 @@ set(ICON_NAMES
outliner_ob_speaker
outliner_ob_force_field
outliner_ob_group_instance
+ outliner_ob_greasepencil
restrict_color_off
restrict_color_on
restrict_view_off
@@ -233,6 +236,7 @@ set(ICON_NAMES
outliner_data_surface
outliner_data_speaker
outliner_data_pose
+ outliner_data_greasepencil
mesh_plane
mesh_cube
mesh_circle
@@ -422,6 +426,7 @@ set(ICON_NAMES
clipuv_hlt
snap_peel_object
grid
+ object_origin
pastedown
copydown
pasteflipup
@@ -520,6 +525,88 @@ set(ICON_NAMES
imagefile
)
+# This section is maintained by the updating script, keep BEGIN/END comments.
+set_property(GLOBAL PROPERTY ICON_GEOM_NAMES
+ # BEGIN ICON_GEOM_NAMES
+ brush.paint_texture.airbrush
+ brush.paint_texture.clone
+ brush.paint_texture.draw
+ brush.paint_texture.fill
+ brush.paint_texture.mask
+ brush.paint_texture.multiply
+ brush.paint_texture.smear
+ brush.paint_texture.soften
+ brush.paint_vertex.alpha
+ brush.paint_vertex.blur
+ brush.paint_vertex.mix
+ brush.paint_vertex.smear
+ brush.paint_weight.blur
+ brush.paint_weight.darken
+ brush.paint_weight.draw
+ brush.paint_weight.lighten
+ brush.paint_weight.mix
+ brush.paint_weight.multiply
+ brush.sculpt.blob
+ brush.sculpt.clay
+ brush.sculpt.clay_strips
+ brush.sculpt.crease
+ brush.sculpt.draw
+ brush.sculpt.fill
+ brush.sculpt.flatten
+ brush.sculpt.grab
+ brush.sculpt.inflate
+ brush.sculpt.layer
+ brush.sculpt.mask
+ brush.sculpt.nudge
+ brush.sculpt.pinch
+ brush.sculpt.rotate
+ brush.sculpt.scrape
+ brush.sculpt.smooth
+ brush.sculpt.snake_hook
+ brush.sculpt.thumb
+ brush.vertex.average
+ brush.weight.add
+ brush.weight.subtract
+ none
+ ops.armature.bone.roll
+ ops.armature.extrude.cursor
+ ops.armature.extrude
+ ops.generic.cursor
+ ops.generic.select_border
+ ops.generic.select_circle
+ ops.generic.select_lasso
+ ops.mesh.bevel
+ ops.mesh.bisect
+ ops.mesh.dupli_extrude_cursor
+ ops.mesh.extrude_faces_move
+ ops.mesh.extrude_region_move
+ ops.mesh.inset
+ ops.mesh.knife_tool
+ ops.mesh.loopcut_slide
+ ops.mesh.offset_edge_loops_slide
+ ops.mesh.polybuild_hover
+ ops.mesh.rip
+ ops.mesh.rip_edge
+ ops.mesh.spin
+ ops.mesh.spin.duplicate
+ ops.mesh.vertices_smooth
+ ops.paint.vertex_color_fill
+ ops.paint.weight_fill
+ ops.paint.weight_gradient
+ ops.transform.edge_slide
+ ops.transform.push_pull
+ ops.transform.resize.cage
+ ops.transform.resize
+ ops.transform.rotate
+ ops.transform.shrink_fatten
+ ops.transform.transform
+ ops.transform.translate
+ ops.transform.vert_slide
+ ops.transform.vertex_random
+ ops.view3d.ruler
+ # END ICON_GEOM_NAMES
+)
+
data_to_c_simple(../../../../release/datafiles/bfont.pfb SRC)
data_to_c_simple(../../../../release/datafiles/bfont.ttf SRC)
data_to_c_simple(../../../../release/datafiles/bmonofont.ttf SRC)
diff --git a/source/blender/editors/gpencil/CMakeLists.txt b/source/blender/editors/gpencil/CMakeLists.txt
index 3d5317b2ebd..587c25031ab 100644
--- a/source/blender/editors/gpencil/CMakeLists.txt
+++ b/source/blender/editors/gpencil/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../imbuf
../../gpu
../../makesdna
diff --git a/source/blender/editors/gpencil/drawgpencil.c b/source/blender/editors/gpencil/drawgpencil.c
index b23b9a06fbb..50a6e9125a0 100644
--- a/source/blender/editors/gpencil/drawgpencil.c
+++ b/source/blender/editors/gpencil/drawgpencil.c
@@ -60,9 +60,11 @@
#include "WM_api.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_draw.h"
+
#include "ED_gpencil.h"
#include "ED_screen.h"
#include "ED_view3d.h"
@@ -92,99 +94,194 @@ typedef enum eDrawStrokeFlags {
/* thickness above which we should use special drawing */
+#if 0
#define GP_DRAWTHICKNESS_SPECIAL 3
+#endif
+
+/* conversion utility (float --> normalized unsigned byte) */
+#define F2UB(x) (unsigned char)(255.0f * x)
/* ----- Tool Buffer Drawing ------ */
-/* helper function to set color of buffer point */
-static void gp_set_tpoint_color(tGPspoint *pt, float ink[4])
+/* helper functions to set color of buffer point */
+
+static void gp_set_tpoint_varying_color(const tGPspoint *pt, const float ink[4], unsigned attrib_id)
{
float alpha = ink[3] * pt->strength;
CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
- glColor4f(ink[0], ink[1], ink[2], alpha);
+ immAttrib4ub(attrib_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha));
}
-/* helper function to set color of point */
-static void gp_set_point_color(bGPDspoint *pt, float ink[4])
+static void gp_set_point_uniform_color(const bGPDspoint *pt, const float ink[4])
{
float alpha = ink[3] * pt->strength;
CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
- glColor4f(ink[0], ink[1], ink[2], alpha);
+ immUniformColor3fvAlpha(ink, alpha);
}
-/* helper function to set color and point */
-static void gp_set_color_and_tpoint(tGPspoint *pt, float ink[4])
+static void gp_set_point_varying_color(const bGPDspoint *pt, const float ink[4], unsigned attrib_id)
{
- gp_set_tpoint_color(pt, ink);
- glVertex2iv(&pt->x);
+ float alpha = ink[3] * pt->strength;
+ CLAMP(alpha, GPENCIL_STRENGTH_MIN, 1.0f);
+ immAttrib4ub(attrib_id, F2UB(ink[0]), F2UB(ink[1]), F2UB(ink[2]), F2UB(alpha));
+}
+
+/* draw fills for buffer stroke */
+static void gp_draw_stroke_buffer_fill(const tGPspoint *points, int totpoints, float ink[4])
+{
+ if (totpoints < 3) {
+ return;
+ }
+ int tot_triangles = totpoints - 2;
+ /* allocate memory for temporary areas */
+ unsigned int(*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * tot_triangles, "GP Stroke buffer temp triangulation");
+ float(*points2d)[2] = MEM_mallocN(sizeof(*points2d) * totpoints, "GP Stroke buffer temp 2d points");
+
+ /* Convert points to array and triangulate
+ * Here a cache is not used because while drawing the information changes all the time, so the cache
+ * would be recalculated constantly, so it is better to do direct calculation for each function call
+ */
+ for (int i = 0; i < totpoints; i++) {
+ const tGPspoint *pt = &points[i];
+ points2d[i][0] = pt->x;
+ points2d[i][1] = pt->y;
+ }
+ BLI_polyfill_calc((const float(*)[2])points2d, (unsigned int)totpoints, 0, (unsigned int(*)[3])tmp_triangles);
+
+ /* draw triangulation data */
+ if (tot_triangles > 0) {
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+
+ /* Draw all triangles for filling the polygon */
+ immBegin(GWN_PRIM_TRIS, tot_triangles * 3);
+ /* TODO: use batch instead of immediate mode, to share vertices */
+
+ const tGPspoint *pt;
+ for (int i = 0; i < tot_triangles; i++) {
+ /* vertex 1 */
+ pt = &points[tmp_triangles[i][0]];
+ gp_set_tpoint_varying_color(pt, ink, color);
+ immVertex2iv(pos, &pt->x);
+ /* vertex 2 */
+ pt = &points[tmp_triangles[i][1]];
+ gp_set_tpoint_varying_color(pt, ink, color);
+ immVertex2iv(pos, &pt->x);
+ /* vertex 3 */
+ pt = &points[tmp_triangles[i][2]];
+ gp_set_tpoint_varying_color(pt, ink, color);
+ immVertex2iv(pos, &pt->x);
+ }
+
+ immEnd();
+ immUnbindProgram();
+ }
+
+ /* clear memory */
+ if (tmp_triangles) {
+ MEM_freeN(tmp_triangles);
+ }
+ if (points2d) {
+ MEM_freeN(points2d);
+ }
}
/* draw stroke defined in buffer (simple ogl lines/points for now, as dotted lines) */
-static void gp_draw_stroke_buffer(tGPspoint *points, int totpoints, short thickness,
- short dflag, short sflag, float ink[4])
+static void gp_draw_stroke_buffer(const tGPspoint *points, int totpoints, short thickness,
+ short dflag, short sflag, float ink[4], float fill_ink[4])
{
- tGPspoint *pt;
- int i;
-
+ int draw_points = 0;
+
/* error checking */
if ((points == NULL) || (totpoints <= 0))
return;
-
+
/* check if buffer can be drawn */
if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D))
return;
-
+
+ if (sflag & GP_STROKE_ERASER) {
+ /* don't draw stroke at all! */
+ return;
+ }
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ const tGPspoint *pt = points;
+
if (totpoints == 1) {
/* if drawing a single point, draw it larger */
glPointSize((float)(thickness + 2) * points->pressure);
- glBegin(GL_POINTS);
-
- gp_set_color_and_tpoint(points, ink);
- glEnd();
- }
- else if (sflag & GP_STROKE_ERASER) {
- /* don't draw stroke at all! */
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR);
+ immBegin(GWN_PRIM_POINTS, 1);
+ gp_set_tpoint_varying_color(pt, ink, color);
+ immVertex2iv(pos, &pt->x);
}
else {
float oldpressure = points[0].pressure;
-
+
/* draw stroke curve */
- if (G.debug & G_DEBUG) setlinestyle(2);
-
glLineWidth(max_ff(oldpressure * thickness, 1.0));
- glBegin(GL_LINE_STRIP);
-
- for (i = 0, pt = points; i < totpoints && pt; i++, pt++) {
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints);
+
+ /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */
+
+ for (int i = 0; i < totpoints; i++, pt++) {
/* if there was a significant pressure change, stop the curve, change the thickness of the stroke,
* and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP)
*/
if (fabsf(pt->pressure - oldpressure) > 0.2f) {
- glEnd();
+ /* need to have 2 points to avoid immEnd assert error */
+ if (draw_points < 2) {
+ gp_set_tpoint_varying_color(pt - 1, ink, color);
+ immVertex2iv(pos, &(pt - 1)->x);
+ }
+
+ immEnd();
+ draw_points = 0;
+
glLineWidth(max_ff(pt->pressure * thickness, 1.0f));
- glBegin(GL_LINE_STRIP);
-
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints - i + 1);
+
/* need to roll-back one point to ensure that there are no gaps in the stroke */
if (i != 0) {
- gp_set_color_and_tpoint((pt - 1), ink);
+ gp_set_tpoint_varying_color(pt - 1, ink, color);
+ immVertex2iv(pos, &(pt - 1)->x);
+ ++draw_points;
}
-
- /* now the point we want... */
- gp_set_color_and_tpoint(pt, ink);
-
- oldpressure = pt->pressure;
- }
- else {
- gp_set_color_and_tpoint(pt, ink);
+
+ oldpressure = pt->pressure; /* reset our threshold */
}
+
+ /* now the point we want */
+ gp_set_tpoint_varying_color(pt, ink, color);
+ immVertex2iv(pos, &pt->x);
+ ++draw_points;
+ }
+ /* need to have 2 points to avoid immEnd assert error */
+ if (draw_points < 2) {
+ gp_set_tpoint_varying_color(pt - 1, ink, color);
+ immVertex2iv(pos, &(pt - 1)->x);
}
- glEnd();
+ }
+
+ immEnd();
+ immUnbindProgram();
- if (G.debug & G_DEBUG) setlinestyle(0);
+ // draw fill
+ if (fill_ink[3] > GPENCIL_ALPHA_OPACITY_THRESH) {
+ gp_draw_stroke_buffer_fill(points, totpoints, fill_ink);
}
}
/* --------- 2D Stroke Drawing Helpers --------- */
/* change in parameter list */
-static void gp_calc_2d_stroke_fxy(float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2])
+static void gp_calc_2d_stroke_fxy(const float pt[3], short sflag, int offsx, int offsy, int winx, int winy, float r_co[2])
{
if (sflag & GP_STROKE_2DSPACE) {
r_co[0] = pt[0];
@@ -210,203 +307,141 @@ static void gp_calc_2d_stroke_fxy(float pt[3], short sflag, int offsx, int offsy
/* draw a 2D buffer stroke in "volumetric" style
* NOTE: the stroke buffer doesn't have any coordinate offsets/transforms
*/
-static void gp_draw_stroke_volumetric_buffer(tGPspoint *points, int totpoints, short thickness,
- short dflag, short UNUSED(sflag), float ink[4])
+static void gp_draw_stroke_volumetric_buffer(const tGPspoint *points, int totpoints, short thickness,
+ short dflag, const float ink[4])
{
- GLUquadricObj *qobj = gluNewQuadric();
- float modelview[4][4];
-
- tGPspoint *pt;
- int i;
-
/* error checking */
if ((points == NULL) || (totpoints <= 0))
return;
-
+
/* check if buffer can be drawn */
if (dflag & (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_ONLYV2D))
return;
-
- /* get basic matrix - should be camera space (i.e "identity") */
- glGetFloatv(GL_MODELVIEW_MATRIX, (float *)modelview);
-
- /* draw points */
- glPushMatrix();
-
- for (i = 0, pt = points; i < totpoints; i++, pt++) {
- /* set the transformed position */
- // TODO: scale should change based on zoom level, which requires proper translation mult too!
- modelview[3][0] = pt->x;
- modelview[3][1] = pt->y;
-
- glLoadMatrixf((float *)modelview);
-
- /* draw the disk using the current state... */
- gp_set_tpoint_color(pt, ink);
- gluDisk(qobj, 0.0, pt->pressure * thickness, 32, 1);
-
-
- modelview[3][0] = modelview[3][1] = 0.0f;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int size = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+ GPU_enable_program_point_size();
+ immBegin(GWN_PRIM_POINTS, totpoints);
+
+ const tGPspoint *pt = points;
+ for (int i = 0; i < totpoints; i++, pt++) {
+ gp_set_tpoint_varying_color(pt, ink, color);
+ immAttrib1f(size, pt->pressure * thickness); /* TODO: scale based on view transform (zoom level) */
+ immVertex2f(pos, pt->x, pt->y);
}
- glPopMatrix();
- gluDeleteQuadric(qobj);
+ immEnd();
+ immUnbindProgram();
+ GPU_disable_program_point_size();
}
/* draw a 2D strokes in "volumetric" style */
-static void gp_draw_stroke_volumetric_2d(bGPDspoint *points, int totpoints, short thickness,
- short dflag, short sflag,
+static void gp_draw_stroke_volumetric_2d(const bGPDspoint *points, int totpoints, short thickness,
+ short UNUSED(dflag), short sflag,
int offsx, int offsy, int winx, int winy,
- float diff_mat[4][4], float ink[4])
+ const float diff_mat[4][4], const float ink[4])
{
- GLUquadricObj *qobj = gluNewQuadric();
- float modelview[4][4];
- float baseloc[3];
- float scalefac = 1.0f;
-
- bGPDspoint *pt;
- int i;
- float fpt[3];
-
- /* HACK: We need a scale factor for the drawing in the image editor,
- * which seems to use 1 unit as it's maximum size, whereas everything
- * else assumes 1 unit = 1 pixel. Otherwise, we only get a massive blob.
- */
- if ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D)) {
- scalefac = 0.001f;
- }
-
- /* get basic matrix */
- glGetFloatv(GL_MODELVIEW_MATRIX, (float *)modelview);
- copy_v3_v3(baseloc, modelview[3]);
-
- /* draw points */
- glPushMatrix();
-
- for (i = 0, pt = points; i < totpoints; i++, pt++) {
- /* color of point */
- gp_set_point_color(pt, ink);
-
- /* set the transformed position */
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int size = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+ GPU_enable_program_point_size();
+ immBegin(GWN_PRIM_POINTS, totpoints);
+
+ const bGPDspoint *pt = points;
+ for (int i = 0; i < totpoints; i++, pt++) {
+ /* transform position to 2D */
float co[2];
-
+ float fpt[3];
+
mul_v3_m4v3(fpt, diff_mat, &pt->x);
gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co);
- translate_m4(modelview, co[0], co[1], 0.0f);
-
- glLoadMatrixf((float *)modelview);
-
- /* draw the disk using the current state... */
- gluDisk(qobj, 0.0, pt->pressure * thickness * scalefac, 32, 1);
-
- /* restore matrix */
- copy_v3_v3(modelview[3], baseloc);
+
+ gp_set_point_varying_color(pt, ink, color);
+ immAttrib1f(size, pt->pressure * thickness); /* TODO: scale based on view transform */
+ immVertex2f(pos, co[0], co[1]);
}
-
- glPopMatrix();
- gluDeleteQuadric(qobj);
+
+ immEnd();
+ immUnbindProgram();
+ GPU_disable_program_point_size();
}
/* draw a 3D stroke in "volumetric" style */
static void gp_draw_stroke_volumetric_3d(
- bGPDspoint *points, int totpoints, short thickness,
- short UNUSED(dflag), short UNUSED(sflag), float diff_mat[4][4], float ink[4])
+ const bGPDspoint *points, int totpoints, short thickness,
+ const float ink[4])
{
- GLUquadricObj *qobj = gluNewQuadric();
-
- float base_modelview[4][4], modelview[4][4];
- float base_loc[3];
-
- bGPDspoint *pt;
- int i;
- float fpt[3];
-
- /* Get the basic modelview matrix we use for performing calculations */
- glGetFloatv(GL_MODELVIEW_MATRIX, (float *)base_modelview);
- copy_v3_v3(base_loc, base_modelview[3]);
-
- /* Create the basic view-aligned billboard matrix we're going to actually draw qobj with:
- * - We need to knock out the rotation so that we are
- * simply left with a camera-facing billboard
- * - The scale factors here are chosen so that the thickness
- * is relatively reasonable. Otherwise, it gets far too
- * large!
- */
- scale_m4_fl(modelview, 0.1f);
-
- /* draw each point as a disk... */
- glPushMatrix();
-
- for (i = 0, pt = points; i < totpoints && pt; i++, pt++) {
- /* color of point */
- gp_set_point_color(pt, ink);
-
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
-
- /* apply translation to base_modelview, so that the translated point is put in the right place */
- translate_m4(base_modelview, fpt[0], fpt[1], fpt[2]);
-
- /* copy the translation component to the billboard matrix we're going to use,
- * then reset the base matrix to the original values so that we can do the same
- * for the next point without accumulation/pollution effects
- */
- copy_v3_v3(modelview[3], base_modelview[3]); /* copy offset value */
- copy_v3_v3(base_modelview[3], base_loc); /* restore */
-
- /* apply our billboard matrix for drawing... */
- glLoadMatrixf((float *)modelview);
-
- /* draw the disk using the current state... */
- gluDisk(qobj, 0.0, pt->pressure * thickness, 32, 1);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ unsigned int size = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+ GPU_enable_program_point_size();
+ immBegin(GWN_PRIM_POINTS, totpoints);
+
+ const bGPDspoint *pt = points;
+ for (int i = 0; i < totpoints && pt; i++, pt++) {
+ gp_set_point_varying_color(pt, ink, color);
+ immAttrib1f(size, pt->pressure * thickness); /* TODO: scale based on view transform */
+ immVertex3fv(pos, &pt->x); /* we can adjust size in vertex shader based on view/projection! */
}
-
- glPopMatrix();
- gluDeleteQuadric(qobj);
+
+ immEnd();
+ immUnbindProgram();
+ GPU_disable_program_point_size();
}
/* --------------- Stroke Fills ----------------- */
/* Get points of stroke always flat to view not affected by camera view or view position */
-static void gp_stroke_2d_flat(bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction)
+static void gp_stroke_2d_flat(const bGPDspoint *points, int totpoints, float(*points2d)[2], int *r_direction)
{
- bGPDspoint *pt0 = &points[0];
- bGPDspoint *pt1 = &points[1];
- bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)];
-
+ const bGPDspoint *pt0 = &points[0];
+ const bGPDspoint *pt1 = &points[1];
+ const bGPDspoint *pt3 = &points[(int)(totpoints * 0.75)];
+
float locx[3];
float locy[3];
float loc3[3];
float normal[3];
-
+
/* local X axis (p0 -> p1) */
sub_v3_v3v3(locx, &pt1->x, &pt0->x);
-
+
/* point vector at 3/4 */
sub_v3_v3v3(loc3, &pt3->x, &pt0->x);
-
+
/* vector orthogonal to polygon plane */
cross_v3_v3v3(normal, locx, loc3);
-
+
/* local Y axis (cross to normal/x axis) */
cross_v3_v3v3(locy, normal, locx);
-
+
/* Normalize vectors */
normalize_v3(locx);
normalize_v3(locy);
-
+
/* Get all points in local space */
for (int i = 0; i < totpoints; i++) {
- bGPDspoint *pt = &points[i];
+ const bGPDspoint *pt = &points[i];
float loc[3];
-
+
/* Get local space using first point as origin */
sub_v3_v3v3(loc, &pt->x, &pt0->x);
-
+
points2d[i][0] = dot_v3v3(loc, locx);
points2d[i][1] = dot_v3v3(loc, locy);
}
-
+
/* Concave (-1), Convex (1), or Autodetect (0)? */
*r_direction = (int)locy[2];
}
@@ -416,14 +451,14 @@ static void gp_stroke_2d_flat(bGPDspoint *points, int totpoints, float(*points2d
static void gp_triangulate_stroke_fill(bGPDstroke *gps)
{
BLI_assert(gps->totpoints >= 3);
-
+
/* allocate memory for temporary areas */
gps->tot_triangles = gps->totpoints - 2;
unsigned int (*tmp_triangles)[3] = MEM_mallocN(sizeof(*tmp_triangles) * gps->tot_triangles, "GP Stroke temp triangulation");
float (*points2d)[2] = MEM_mallocN(sizeof(*points2d) * gps->totpoints, "GP Stroke temp 2d points");
-
+
int direction = 0;
-
+
/* convert to 2d and triangulate */
gp_stroke_2d_flat(gps->points, gps->totpoints, points2d, &direction);
BLI_polyfill_calc(points2d, (unsigned int)gps->totpoints, direction, tmp_triangles);
@@ -438,25 +473,24 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps)
else {
gps->triangles = MEM_recallocN(gps->triangles, sizeof(*gps->triangles) * gps->tot_triangles);
}
-
+
for (int i = 0; i < gps->tot_triangles; i++) {
- bGPDtriangle *stroke_triangle = &gps->triangles[i];
- memcpy(stroke_triangle->verts, tmp_triangles[i], sizeof(uint[3]));
+ memcpy(gps->triangles[i].verts, tmp_triangles[i], sizeof(uint[3]));
}
}
else {
/* No triangles needed - Free anything allocated previously */
if (gps->triangles)
MEM_freeN(gps->triangles);
-
+
gps->triangles = NULL;
}
-
+
/* disable recalculation flag */
if (gps->flag & GP_STROKE_RECALC_CACHES) {
gps->flag &= ~GP_STROKE_RECALC_CACHES;
}
-
+
/* clear memory */
if (tmp_triangles) MEM_freeN(tmp_triangles);
if (points2d) MEM_freeN(points2d);
@@ -466,78 +500,64 @@ static void gp_triangulate_stroke_fill(bGPDstroke *gps)
/* draw fills for shapes */
static void gp_draw_stroke_fill(
bGPdata *gpd, bGPDstroke *gps,
- int offsx, int offsy, int winx, int winy, float diff_mat[4][4])
+ int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float color[4])
{
- bGPDpalettecolor *palcolor;
- int i;
float fpt[3];
BLI_assert(gps->totpoints >= 3);
- palcolor = ED_gpencil_stroke_getcolor(gpd, gps);
+ bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps);
/* Triangulation fill if high quality flag is enabled */
if (palcolor->flag & PC_COLOR_HQ_FILL) {
- bGPDtriangle *stroke_triangle;
- bGPDspoint *pt;
-
/* Calculate triangles cache for filling area (must be done only after changes) */
if ((gps->flag & GP_STROKE_RECALC_CACHES) || (gps->tot_triangles == 0) || (gps->triangles == NULL)) {
gp_triangulate_stroke_fill(gps);
}
- /* Draw all triangles for filling the polygon (cache must be calculated before) */
BLI_assert(gps->tot_triangles >= 1);
- glBegin(GL_TRIANGLES);
+
+ unsigned int pos;
if (gps->flag & GP_STROKE_3DSPACE) {
- for (i = 0, stroke_triangle = gps->triangles; i < gps->tot_triangles; i++, stroke_triangle++) {
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+ else {
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ }
+
+ immUniformColor4fv(color);
+
+ /* Draw all triangles for filling the polygon (cache must be calculated before) */
+ immBegin(GWN_PRIM_TRIS, gps->tot_triangles * 3);
+ /* TODO: use batch instead of immediate mode, to share vertices */
+
+ bGPDtriangle *stroke_triangle = gps->triangles;
+ bGPDspoint *pt;
+
+ if (gps->flag & GP_STROKE_3DSPACE) {
+ for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
for (int j = 0; j < 3; j++) {
pt = &gps->points[stroke_triangle->verts[j]];
mul_v3_m4v3(fpt, diff_mat, &pt->x);
- glVertex3fv(fpt);
+ immVertex3fv(pos, fpt);
}
}
}
else {
- for (i = 0, stroke_triangle = gps->triangles; i < gps->tot_triangles; i++, stroke_triangle++) {
+ for (int i = 0; i < gps->tot_triangles; i++, stroke_triangle++) {
for (int j = 0; j < 3; j++) {
float co[2];
pt = &gps->points[stroke_triangle->verts[j]];
mul_v3_m4v3(fpt, diff_mat, &pt->x);
gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
- glVertex2fv(co);
+ immVertex3fv(pos, fpt);
}
}
}
- glEnd();
- }
- else {
- /* As an initial implementation, we use the OpenGL filled polygon drawing
- * here since it's the easiest option to implement for this case. It does
- * come with limitations (notably for concave shapes), though it shouldn't
- * be much of an issue in most cases.
- *
- * We keep this legacy implementation around despite now having the high quality
- * fills, as this is necessary for keeping everything working nicely for files
- * created using old versions of Blender which may have depended on the artifacts
- * the old fills created.
- */
- bGPDspoint *pt;
-
- glBegin(GL_POLYGON);
- for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
- if (gps->flag & GP_STROKE_3DSPACE) {
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- glVertex3fv(fpt);
- }
- else {
- float co[2];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
- glVertex2fv(co);
- }
- }
- glEnd();
+ immEnd();
+ immUnbindProgram();
}
}
@@ -545,153 +565,162 @@ static void gp_draw_stroke_fill(
/* draw a given stroke - just a single dot (only one point) */
static void gp_draw_stroke_point(
- bGPDspoint *points, short thickness, short dflag, short sflag,
- int offsx, int offsy, int winx, int winy, float diff_mat[4][4], float ink[4])
+ const bGPDspoint *points, short thickness, short UNUSED(dflag), short sflag,
+ int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float ink[4])
{
- float fpt[3];
- bGPDspoint *pt = &points[0];
-
- /* color of point */
- gp_set_point_color(pt, ink);
+ const bGPDspoint *pt = points;
- /* set point thickness (since there's only one of these) */
- glPointSize((float)(thickness + 2) * points->pressure);
-
/* get final position using parent matrix */
+ float fpt[3];
mul_v3_m4v3(fpt, diff_mat, &pt->x);
- /* draw point */
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
if (sflag & GP_STROKE_3DSPACE) {
- glBegin(GL_POINTS);
- glVertex3fv(fpt);
- glEnd();
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
}
else {
- float co[2];
-
- /* get coordinates of point */
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
+
+ /* get 2D coordinates of point */
+ float co[3] = { 0.0f };
gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co);
-
- /* if thickness is less than GP_DRAWTHICKNESS_SPECIAL, simple dot looks ok
- * - also mandatory in if Image Editor 'image-based' dot
- */
- if ((thickness < GP_DRAWTHICKNESS_SPECIAL) ||
- ((dflag & GP_DRAWDATA_IEDITHACK) && (sflag & GP_STROKE_2DSPACE)))
- {
- glBegin(GL_POINTS);
- glVertex2fv(co);
- glEnd();
- }
- else {
- /* draw filled circle as is done in circf (but without the matrix push/pops which screwed things up) */
- GLUquadricObj *qobj = gluNewQuadric();
-
- gluQuadricDrawStyle(qobj, GLU_FILL);
-
- /* need to translate drawing position, but must reset after too! */
- glTranslate2fv(co);
- gluDisk(qobj, 0.0, thickness, 32, 1);
- glTranslatef(-co[0], -co[1], 0.0);
-
- gluDeleteQuadric(qobj);
- }
+ copy_v3_v3(fpt, co);
}
+
+ gp_set_point_uniform_color(pt, ink);
+ /* set point thickness (since there's only one of these) */
+ immUniform1f("size", (float)(thickness + 2) * pt->pressure);
+
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex3fv(pos, fpt);
+ immEnd();
+
+ immUnbindProgram();
}
/* draw a given stroke in 3d (i.e. in 3d-space), using simple ogl lines */
-static void gp_draw_stroke_3d(bGPDspoint *points, int totpoints, short thickness, bool debug,
- short UNUSED(sflag), float diff_mat[4][4], float ink[4], bool cyclic)
+static void gp_draw_stroke_3d(const bGPDspoint *points, int totpoints, short thickness, bool UNUSED(debug),
+ short UNUSED(sflag), const float diff_mat[4][4], const float ink[4], bool cyclic)
{
- bGPDspoint *pt, *pt2;
float curpressure = points[0].pressure;
- int i;
float fpt[3];
float cyclic_fpt[3];
+ int draw_points = 0;
+
+ /* if cyclic needs one vertex more */
+ int cyclic_add = 0;
+ if (cyclic) {
+ ++cyclic_add;
+ }
+
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR);
+
+ /* TODO: implement this with a geometry shader to draw one continuous tapered stroke */
/* draw stroke curve */
glLineWidth(max_ff(curpressure * thickness, 1.0f));
- glBegin(GL_LINE_STRIP);
- for (i = 0, pt = points; i < totpoints && pt; i++, pt++) {
- gp_set_point_color(pt, ink);
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints + cyclic_add);
+ const bGPDspoint *pt = points;
+ for (int i = 0; i < totpoints; i++, pt++) {
+ gp_set_point_varying_color(pt, ink, color);
/* if there was a significant pressure change, stop the curve, change the thickness of the stroke,
* and continue drawing again (since line-width cannot change in middle of GL_LINE_STRIP)
* Note: we want more visible levels of pressures when thickness is bigger.
*/
if (fabsf(pt->pressure - curpressure) > 0.2f / (float)thickness) {
- glEnd();
+ /* if the pressure changes before get at least 2 vertices, need to repeat last point to avoid assert in immEnd() */
+ if (draw_points < 2) {
+ const bGPDspoint *pt2 = pt - 1;
+ mul_v3_m4v3(fpt, diff_mat, &pt2->x);
+ immVertex3fv(pos, fpt);
+ }
+ immEnd();
+ draw_points = 0;
+
curpressure = pt->pressure;
glLineWidth(max_ff(curpressure * thickness, 1.0f));
- glBegin(GL_LINE_STRIP);
-
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, totpoints - i + 1 + cyclic_add);
+
/* need to roll-back one point to ensure that there are no gaps in the stroke */
if (i != 0) {
- pt2 = pt - 1;
+ const bGPDspoint *pt2 = pt - 1;
mul_v3_m4v3(fpt, diff_mat, &pt2->x);
- glVertex3fv(fpt);
+ gp_set_point_varying_color(pt2, ink, color);
+ immVertex3fv(pos, fpt);
+ ++draw_points;
}
-
- /* now the point we want... */
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- glVertex3fv(fpt);
- }
- else {
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- glVertex3fv(fpt);
}
- /* saves first point to use in cyclic */
- if (i == 0) {
+
+ /* now the point we want */
+ mul_v3_m4v3(fpt, diff_mat, &pt->x);
+ immVertex3fv(pos, fpt);
+ ++draw_points;
+
+ if (cyclic && i == 0) {
+ /* save first point to use in cyclic */
copy_v3_v3(cyclic_fpt, fpt);
}
}
- /* if cyclic draw line to first point */
+
if (cyclic) {
- glVertex3fv(cyclic_fpt);
+ /* draw line to first point to complete the cycle */
+ immVertex3fv(pos, cyclic_fpt);
+ ++draw_points;
}
- glEnd();
-
- /* draw debug points of curve on top? */
- /* XXX: for now, we represent "selected" strokes in the same way as debug, which isn't used anymore */
- if (debug) {
- glPointSize((float)(thickness + 2));
-
- glBegin(GL_POINTS);
- for (i = 0, pt = points; i < totpoints && pt; i++, pt++) {
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- glVertex3fv(fpt);
- }
- glEnd();
+ /* if less of two points, need to repeat last point to avoid assert in immEnd() */
+ if (draw_points < 2) {
+ const bGPDspoint *pt2 = pt - 1;
+ mul_v3_m4v3(fpt, diff_mat, &pt2->x);
+ gp_set_point_varying_color(pt2, ink, color);
+ immVertex3fv(pos, fpt);
}
+
+ immEnd();
+ immUnbindProgram();
}
/* ----- Fancy 2D-Stroke Drawing ------ */
/* draw a given stroke in 2d */
-static void gp_draw_stroke_2d(bGPDspoint *points, int totpoints, short thickness_s, short dflag, short sflag,
- bool debug, int offsx, int offsy, int winx, int winy, float diff_mat[4][4], float ink[4])
+static void gp_draw_stroke_2d(const bGPDspoint *points, int totpoints, short thickness_s, short dflag, short sflag,
+ bool UNUSED(debug), int offsx, int offsy, int winx, int winy, const float diff_mat[4][4], const float ink[4])
{
/* otherwise thickness is twice that of the 3D view */
float thickness = (float)thickness_s * 0.5f;
-
+
/* strokes in Image Editor need a scale factor, since units there are not pixels! */
float scalefac = 1.0f;
if ((dflag & GP_DRAWDATA_IEDITHACK) && (dflag & GP_DRAWDATA_ONLYV2D)) {
scalefac = 0.001f;
}
-
- /* tessellation code - draw stroke as series of connected quads with connection
+
+ /* TODO: fancy++ with the magic of shaders */
+
+ /* tessellation code - draw stroke as series of connected quads (triangle strips in fact) with connection
* edges rotated to minimize shrinking artifacts, and rounded endcaps
*/
{
- bGPDspoint *pt1, *pt2;
+ const bGPDspoint *pt1, *pt2;
float s0[2], s1[2]; /* segment 'center' points */
float pm[2]; /* normal from previous segment. */
int i;
float fpt[3];
-
- glShadeModel(GL_FLAT);
- glBegin(GL_QUADS);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GWN_PRIM_TRI_STRIP, totpoints * 2 + 4);
/* get x and y coordinates from first point */
mul_v3_m4v3(fpt, diff_mat, &points->x);
@@ -706,19 +735,19 @@ static void gp_draw_stroke_2d(bGPDspoint *points, int totpoints, short thickness
/* get x and y coordinates from point2 (point1 has already been computed in previous iteration). */
mul_v3_m4v3(fpt, diff_mat, &pt2->x);
gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, s1);
-
+
/* calculate gradient and normal - 'angle'=(ny/nx) */
m1[1] = s1[1] - s0[1];
m1[0] = s1[0] - s0[0];
normalize_v2(m1);
m2[1] = -m1[0];
m2[0] = m1[1];
-
+
/* always use pressure from first point here */
pthick = (pt1->pressure * thickness * scalefac);
-
+
/* color of point */
- gp_set_point_color(pt1, ink);
+ gp_set_point_varying_color(pt1, ink, color);
/* if the first segment, start of segment is segment's normal */
if (i == 0) {
@@ -729,40 +758,39 @@ static void gp_draw_stroke_2d(bGPDspoint *points, int totpoints, short thickness
mt[1] = m2[1] * pthick * 0.5f;
sc[0] = s0[0] - (m1[0] * pthick * 0.75f);
sc[1] = s0[1] - (m1[1] * pthick * 0.75f);
-
+
t0[0] = sc[0] - mt[0];
t0[1] = sc[1] - mt[1];
t1[0] = sc[0] + mt[0];
t1[1] = sc[1] + mt[1];
-
- glVertex2fv(t0);
- glVertex2fv(t1);
-
+
+ /* First two points of cap. */
+ immVertex2fv(pos, t0);
+ immVertex2fv(pos, t1);
+
/* calculate points for start of segment */
mt[0] = m2[0] * pthick;
mt[1] = m2[1] * pthick;
-
+
t0[0] = s0[0] - mt[0];
t0[1] = s0[1] - mt[1];
t1[0] = s0[0] + mt[0];
t1[1] = s0[1] + mt[1];
-
- /* draw this line twice (first to finish off start cap, then for stroke) */
- glVertex2fv(t1);
- glVertex2fv(t0);
- glVertex2fv(t0);
- glVertex2fv(t1);
+
+ /* Last two points of start cap (and first two points of first segment). */
+ immVertex2fv(pos, t0);
+ immVertex2fv(pos, t1);
}
/* if not the first segment, use bisector of angle between segments */
else {
float mb[2]; /* bisector normal */
float athick, dfac; /* actual thickness, difference between thicknesses */
-
+
/* calculate gradient of bisector (as average of normals) */
mb[0] = (pm[0] + m2[0]) / 2;
mb[1] = (pm[1] + m2[1]) / 2;
normalize_v2(mb);
-
+
/* calculate gradient to apply
* - as basis, use just pthick * bisector gradient
* - if cross-section not as thick as it should be, add extra padding to fix it
@@ -771,49 +799,44 @@ static void gp_draw_stroke_2d(bGPDspoint *points, int totpoints, short thickness
mt[1] = mb[1] * pthick;
athick = len_v2(mt);
dfac = pthick - (athick * 2);
-
+
if (((athick * 2.0f) < pthick) && (IS_EQF(athick, pthick) == 0)) {
mt[0] += (mb[0] * dfac);
mt[1] += (mb[1] * dfac);
}
-
+
/* calculate points for start of segment */
t0[0] = s0[0] - mt[0];
t0[1] = s0[1] - mt[1];
t1[0] = s0[0] + mt[0];
t1[1] = s0[1] + mt[1];
-
- /* draw this line twice (once for end of current segment, and once for start of next) */
- glVertex2fv(t1);
- glVertex2fv(t0);
- glVertex2fv(t0);
- glVertex2fv(t1);
+
+ /* Last two points of previous segment, and first two points of current segment. */
+ immVertex2fv(pos, t0);
+ immVertex2fv(pos, t1);
}
-
+
/* if last segment, also draw end of segment (defined as segment's normal) */
if (i == totpoints - 2) {
/* for once, we use second point's pressure (otherwise it won't be drawn) */
pthick = (pt2->pressure * thickness * scalefac);
-
+
/* color of point */
- gp_set_point_color(pt2, ink);
+ gp_set_point_varying_color(pt2, ink, color);
/* calculate points for end of segment */
mt[0] = m2[0] * pthick;
mt[1] = m2[1] * pthick;
-
+
t0[0] = s1[0] - mt[0];
t0[1] = s1[1] - mt[1];
t1[0] = s1[0] + mt[0];
t1[1] = s1[1] + mt[1];
-
- /* draw this line twice (once for end of stroke, and once for endcap)*/
- glVertex2fv(t1);
- glVertex2fv(t0);
- glVertex2fv(t0);
- glVertex2fv(t1);
-
-
+
+ /* Last two points of last segment (and first two points of end cap). */
+ immVertex2fv(pos, t0);
+ immVertex2fv(pos, t1);
+
/* draw end cap as last step
* - make points slightly closer to center (about halfway across)
*/
@@ -821,42 +844,25 @@ static void gp_draw_stroke_2d(bGPDspoint *points, int totpoints, short thickness
mt[1] = m2[1] * pthick * 0.5f;
sc[0] = s1[0] + (m1[0] * pthick * 0.75f);
sc[1] = s1[1] + (m1[1] * pthick * 0.75f);
-
+
t0[0] = sc[0] - mt[0];
t0[1] = sc[1] - mt[1];
t1[0] = sc[0] + mt[0];
t1[1] = sc[1] + mt[1];
-
- glVertex2fv(t1);
- glVertex2fv(t0);
+
+ /* Last two points of end cap. */
+ immVertex2fv(pos, t0);
+ immVertex2fv(pos, t1);
}
-
+
/* store computed point2 coordinates as point1 ones of next segment. */
copy_v2_v2(s0, s1);
/* store stroke's 'natural' normal for next stroke to use */
copy_v2_v2(pm, m2);
}
-
- glEnd();
- glShadeModel(GL_SMOOTH);
- }
-
- /* draw debug points of curve on top? (original stroke points) */
- if (debug) {
- bGPDspoint *pt;
- int i;
- float fpt[3];
- glPointSize((float)(thickness_s + 2));
-
- glBegin(GL_POINTS);
- for (i = 0, pt = points; i < totpoints && pt; i++, pt++) {
- float co[2];
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- gp_calc_2d_stroke_fxy(fpt, sflag, offsx, offsy, winx, winy, co);
- glVertex2fv(co);
- }
- glEnd();
+ immEnd();
+ immUnbindProgram();
}
}
@@ -871,41 +877,41 @@ static bool gp_can_draw_stroke(const bGPDstroke *gps, const int dflag)
return false;
if (!(dflag & GP_DRAWDATA_ONLY3D) && (gps->flag & GP_STROKE_3DSPACE))
return false;
-
+
/* 2) Screen Space 2D Strokes */
if ((dflag & GP_DRAWDATA_ONLYV2D) && !(gps->flag & GP_STROKE_2DSPACE))
return false;
if (!(dflag & GP_DRAWDATA_ONLYV2D) && (gps->flag & GP_STROKE_2DSPACE))
return false;
-
+
/* 3) Image Space (2D) */
if ((dflag & GP_DRAWDATA_ONLYI2D) && !(gps->flag & GP_STROKE_2DIMAGE))
return false;
if (!(dflag & GP_DRAWDATA_ONLYI2D) && (gps->flag & GP_STROKE_2DIMAGE))
return false;
-
-
+
/* skip stroke if it doesn't have any valid data */
if ((gps->points == NULL) || (gps->totpoints < 1))
return false;
-
+
/* stroke can be drawn */
return true;
}
/* draw a set of strokes */
static void gp_draw_strokes(
- bGPdata *gpd, bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag,
+ bGPdata *gpd, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, int dflag,
bool debug, short lthick, const float opacity, const float tintcolor[4],
- const bool onion, const bool custonion, float diff_mat[4][4])
+ const bool onion, const bool custonion, const float diff_mat[4][4])
{
- bGPDstroke *gps;
float tcolor[4];
float tfill[4];
short sthickness;
float ink[4];
- for (gps = gpf->strokes.first; gps; gps = gps->next) {
+ GPU_enable_program_point_size();
+
+ for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* check if stroke can be drawn */
if (gp_can_draw_stroke(gps, dflag) == false) {
continue;
@@ -923,6 +929,10 @@ static void gp_draw_strokes(
/* calculate thickness */
sthickness = gps->thickness + lthick;
+ if (sthickness <= 0) {
+ continue;
+ }
+
/* check which stroke-drawer to use */
if (dflag & GP_DRAWDATA_ONLY3D) {
const int no_xray = (dflag & GP_DRAWDATA_NO_XRAY);
@@ -936,10 +946,6 @@ static void gp_draw_strokes(
/* first arg is normally rv3d->dist, but this isn't
* available here and seems to work quite well without */
bglPolygonOffset(1.0f, 1.0f);
-#if 0
- glEnable(GL_POLYGON_OFFSET_LINE);
- glPolygonOffset(-1.0f, -1.0f);
-#endif
}
/* 3D Fill */
@@ -949,19 +955,20 @@ static void gp_draw_strokes(
interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]);
tfill[3] = palcolor->fill[3] * opacity;
if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) {
+ const float *color;
if (!onion) {
- glColor4fv(tfill);
+ color = tfill;
}
else {
if (custonion) {
- glColor4fv(tintcolor);
+ color = tintcolor;
}
else {
ARRAY_SET_ITEMS(tfill, UNPACK3(palcolor->fill), tintcolor[3]);
- glColor4fv(tfill);
+ color = tfill;
}
}
- gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat);
+ gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat, color);
}
}
@@ -983,7 +990,7 @@ static void gp_draw_strokes(
}
if (palcolor->flag & PC_COLOR_VOLUMETRIC) {
/* volumetric stroke drawing */
- gp_draw_stroke_volumetric_3d(gps->points, gps->totpoints, sthickness, dflag, gps->flag, diff_mat, ink);
+ gp_draw_stroke_volumetric_3d(gps->points, gps->totpoints, sthickness, ink);
}
else {
/* 3D Lines - OpenGL primitives-based */
@@ -1001,10 +1008,6 @@ static void gp_draw_strokes(
glDisable(GL_DEPTH_TEST);
bglPolygonOffset(0.0, 0.0);
-#if 0
- glDisable(GL_POLYGON_OFFSET_LINE);
- glPolygonOffset(0, 0);
-#endif
}
}
else {
@@ -1014,20 +1017,21 @@ static void gp_draw_strokes(
interp_v3_v3v3(tfill, palcolor->fill, tintcolor, tintcolor[3]);
tfill[3] = palcolor->fill[3] * opacity;
if (tfill[3] > GPENCIL_ALPHA_OPACITY_THRESH) {
+ const float *color;
if (!onion) {
- glColor4fv(tfill);
+ color = tfill;
}
else {
if (custonion) {
- glColor4fv(tintcolor);
+ color = tintcolor;
}
else {
ARRAY_SET_ITEMS(tfill, palcolor->fill[0], palcolor->fill[1], palcolor->fill[2],
tintcolor[3]);
- glColor4fv(tfill);
+ color = tfill;
}
}
- gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat);
+ gp_draw_stroke_fill(gpd, gps, offsx, offsy, winx, winy, diff_mat, color);
}
}
@@ -1065,15 +1069,15 @@ static void gp_draw_strokes(
}
}
}
+
+ GPU_disable_program_point_size();
}
/* Draw selected verts for strokes being edited */
static void gp_draw_strokes_edit(
- bGPdata *gpd, bGPDframe *gpf, int offsx, int offsy, int winx, int winy, short dflag,
- short lflag, float diff_mat[4][4], float alpha)
+ bGPdata *gpd, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy, short dflag,
+ short lflag, const float diff_mat[4][4], float alpha)
{
- bGPDstroke *gps;
-
/* if alpha 0 do not draw */
if (alpha == 0.0f)
return;
@@ -1087,36 +1091,28 @@ static void gp_draw_strokes_edit(
glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig);
glDepthMask(0);
glEnable(GL_DEPTH_TEST);
-
+
/* first arg is normally rv3d->dist, but this isn't
* available here and seems to work quite well without */
bglPolygonOffset(1.0f, 1.0f);
-#if 0
- glEnable(GL_POLYGON_OFFSET_LINE);
- glPolygonOffset(-1.0f, -1.0f);
-#endif
}
}
-
-
- /* draw stroke verts */
- for (gps = gpf->strokes.first; gps; gps = gps->next) {
- bGPDspoint *pt;
- float vsize, bsize;
- int i;
- float fpt[3];
+ GPU_enable_program_point_size();
+
+ /* draw stroke verts */
+ for (bGPDstroke *gps = gpf->strokes.first; gps; gps = gps->next) {
/* check if stroke can be drawn */
if (gp_can_draw_stroke(gps, dflag) == false)
continue;
-
+
/* Optimisation: only draw points for selected strokes
* We assume that selected points can only occur in
* strokes that are selected too.
*/
if ((gps->flag & GP_STROKE_SELECT) == 0)
continue;
-
+
/* verify palette color lock */
{
bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps);
@@ -1135,7 +1131,8 @@ static void gp_draw_strokes_edit(
* they stand out more.
* - We use the theme setting for size of the unselected verts
*/
- bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE);
+ float bsize = UI_GetThemeValuef(TH_GP_VERTEX_SIZE);
+ float vsize;
if ((int)bsize > 8) {
vsize = 10.0f;
bsize = 8.0f;
@@ -1143,89 +1140,83 @@ static void gp_draw_strokes_edit(
else {
vsize = bsize + 2;
}
-
- /* First Pass: Draw all the verts (i.e. these become the unselected state) */
+
/* for now, we assume that the base color of the points is not too close to the real color */
/* set color using palette */
bGPDpalettecolor *palcolor = ED_gpencil_stroke_getcolor(gpd, gps);
- glColor3fv(palcolor->color);
- glPointSize(bsize);
-
- glBegin(GL_POINTS);
- for (i = 0, pt = gps->points; i < gps->totpoints && pt; i++, pt++) {
+ float selectColor[4];
+ UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, selectColor);
+ selectColor[3] = alpha;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos; /* specified later */
+ unsigned int size = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ if (gps->flag & GP_STROKE_3DSPACE) {
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR);
+ }
+ else {
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR);
+ }
+
+ immBegin(GWN_PRIM_POINTS, gps->totpoints);
+
+ /* Draw start and end point differently if enabled stroke direction hint */
+ bool show_direction_hint = (gpd->flag & GP_DATA_SHOW_DIRECTION) && (gps->totpoints > 1);
+
+ /* Draw all the stroke points (selected or not) */
+ bGPDspoint *pt = gps->points;
+ float fpt[3];
+ for (int i = 0; i < gps->totpoints; i++, pt++) {
+ /* size and color first */
+ if (show_direction_hint && i == 0) {
+ /* start point in green bigger */
+ immAttrib3f(color, 0.0f, 1.0f, 0.0f);
+ immAttrib1f(size, vsize + 4);
+ }
+ else if (show_direction_hint && (i == gps->totpoints - 1)) {
+ /* end point in red smaller */
+ immAttrib3f(color, 1.0f, 0.0f, 0.0f);
+ immAttrib1f(size, vsize + 1);
+ }
+ else if (pt->flag & GP_SPOINT_SELECT) {
+ immAttrib3fv(color, selectColor);
+ immAttrib1f(size, vsize);
+ }
+ else {
+ immAttrib3fv(color, palcolor->color);
+ immAttrib1f(size, bsize);
+ }
+
+ /* then position */
if (gps->flag & GP_STROKE_3DSPACE) {
mul_v3_m4v3(fpt, diff_mat, &pt->x);
- glVertex3fv(fpt);
+ immVertex3fv(pos, fpt);
}
else {
float co[2];
mul_v3_m4v3(fpt, diff_mat, &pt->x);
gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
- glVertex2fv(co);
+ immVertex2fv(pos, co);
}
}
- glEnd();
-
-
- /* Second Pass: Draw only verts which are selected */
- float curColor[4];
- UI_GetThemeColor3fv(TH_GP_VERTEX_SELECT, curColor);
- glColor4f(curColor[0], curColor[1], curColor[2], alpha);
- glPointSize(vsize);
-
- glBegin(GL_POINTS);
- for (i = 0, pt = gps->points; i < gps->totpoints && pt; i++, pt++) {
- if (pt->flag & GP_SPOINT_SELECT) {
- if (gps->flag & GP_STROKE_3DSPACE) {
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- glVertex3fv(fpt);
- }
- else {
- float co[2];
-
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- gp_calc_2d_stroke_fxy(fpt, gps->flag, offsx, offsy, winx, winy, co);
- glVertex2fv(co);
- }
- }
- }
- glEnd();
-
- /* Draw start and end point if enabled stroke direction hint */
- if ((gpd->flag & GP_DATA_SHOW_DIRECTION) && (gps->totpoints > 1)) {
- bGPDspoint *p;
-
- glPointSize(vsize + 4);
- glBegin(GL_POINTS);
-
- /* start point in green bigger */
- glColor3f(0.0f, 1.0f, 0.0f);
- p = &gps->points[0];
- mul_v3_m4v3(fpt, diff_mat, &p->x);
- glVertex3fv(fpt);
- glEnd();
-
- /* end point in red smaller */
- glPointSize(vsize + 1);
- glBegin(GL_POINTS);
-
- glColor3f(1.0f, 0.0f, 0.0f);
- p = &gps->points[gps->totpoints - 1];
- mul_v3_m4v3(fpt, diff_mat, &p->x);
- glVertex3fv(fpt);
- glEnd();
- }
+ immEnd();
+ immUnbindProgram();
}
-
-
+
+ GPU_disable_program_point_size();
+
/* clear depth mask */
if (dflag & GP_DRAWDATA_ONLY3D) {
if (no_xray) {
glDepthMask(mask_orig);
glDisable(GL_DEPTH_TEST);
-
+
bglPolygonOffset(0.0, 0.0);
#if 0
glDisable(GL_POLYGON_OFFSET_LINE);
@@ -1239,8 +1230,8 @@ static void gp_draw_strokes_edit(
/* draw onion-skinning for a layer */
static void gp_draw_onionskins(
- bGPdata *gpd, bGPDlayer *gpl, bGPDframe *gpf, int offsx, int offsy, int winx, int winy,
- int UNUSED(cfra), int dflag, bool debug, float diff_mat[4][4])
+ bGPdata *gpd, const bGPDlayer *gpl, const bGPDframe *gpf, int offsx, int offsy, int winx, int winy,
+ int UNUSED(cfra), int dflag, bool debug, const float diff_mat[4][4])
{
const float default_color[3] = {UNPACK3(U.gpencil_new_layer_col)};
const float alpha = 1.0f;
@@ -1253,17 +1244,14 @@ static void gp_draw_onionskins(
else {
copy_v3_v3(color, default_color);
}
-
+
if (gpl->gstep > 0) {
- bGPDframe *gf;
- float fac;
-
/* draw previous frames first */
- for (gf = gpf->prev; gf; gf = gf->prev) {
+ for (bGPDframe *gf = gpf->prev; gf; gf = gf->prev) {
/* check if frame is drawable */
if ((gpf->framenum - gf->framenum) <= gpl->gstep) {
/* alpha decreases with distance from curframe index */
- fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(gpl->gstep + 1));
+ float fac = 1.0f - ((float)(gpf->framenum - gf->framenum) / (float)(gpl->gstep + 1));
color[3] = alpha * fac * 0.66f;
gp_draw_strokes(gpd, gf, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, 1.0f, color,
true, gpl->flag & GP_LAYER_GHOST_PREVCOL, diff_mat);
@@ -1283,8 +1271,7 @@ static void gp_draw_onionskins(
else {
/* don't draw - disabled */
}
-
-
+
/* 2) Now draw next frames */
if (gpl->flag & GP_LAYER_GHOST_NEXTCOL) {
copy_v3_v3(color, gpl->gcolor_next);
@@ -1292,17 +1279,14 @@ static void gp_draw_onionskins(
else {
copy_v3_v3(color, default_color);
}
-
+
if (gpl->gstep_next > 0) {
- bGPDframe *gf;
- float fac;
-
/* now draw next frames */
- for (gf = gpf->next; gf; gf = gf->next) {
+ for (bGPDframe *gf = gpf->next; gf; gf = gf->next) {
/* check if frame is drawable */
if ((gf->framenum - gpf->framenum) <= gpl->gstep_next) {
/* alpha decreases with distance from curframe index */
- fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1));
+ float fac = 1.0f - ((float)(gf->framenum - gpf->framenum) / (float)(gpl->gstep_next + 1));
color[3] = alpha * fac * 0.66f;
gp_draw_strokes(gpd, gf, offsx, offsy, winx, winy, dflag, debug, gpl->thickness, 1.0f, color,
true, gpl->flag & GP_LAYER_GHOST_NEXTCOL, diff_mat);
@@ -1322,7 +1306,6 @@ static void gp_draw_onionskins(
else {
/* don't draw - disabled */
}
-
}
/* draw interpolate strokes (used only while operator is running) */
@@ -1360,29 +1343,27 @@ void ED_gp_draw_interpolation(tGPDinterpolate *tgpi, const int type)
/* loop over gpencil data layers, drawing them */
static void gp_draw_data_layers(
- bGPDbrush *brush, float alpha, bGPdata *gpd,
+ const bGPDbrush *brush, float alpha, bGPdata *gpd,
int offsx, int offsy, int winx, int winy, int cfra, int dflag)
{
- bGPDlayer *gpl;
float diff_mat[4][4];
- for (gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- bGPDframe *gpf;
+ for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
/* calculate parent position */
ED_gpencil_parent_location(gpl, diff_mat);
- bool debug = (gpl->flag & GP_LAYER_DRAWDEBUG) ? true : false;
+ bool debug = (gpl->flag & GP_LAYER_DRAWDEBUG);
short lthick = brush->thickness + gpl->thickness;
-
+
/* don't draw layer if hidden */
if (gpl->flag & GP_LAYER_HIDE)
continue;
-
+
/* get frame to draw */
- gpf = BKE_gpencil_layer_getframe(gpl, cfra, 0);
+ bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, cfra, 0);
if (gpf == NULL)
continue;
-
+
/* set basic stroke thickness */
glLineWidth(lthick);
@@ -1394,10 +1375,10 @@ static void gp_draw_data_layers(
if (condition) dflag |= (draw_flag_value); \
else dflag &= ~(draw_flag_value); \
} (void)0
-
+
/* xray... */
GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_NO_XRAY), GP_DRAWDATA_NO_XRAY);
-
+
/* volumetric strokes... */
GP_DRAWFLAG_APPLY((gpl->flag & GP_LAYER_VOLUMETRIC), GP_DRAWDATA_VOLUMETRIC);
@@ -1421,11 +1402,11 @@ static void gp_draw_data_layers(
*/
gp_draw_onionskins(gpd, gpl, gpf, offsx, offsy, winx, winy, cfra, dflag, debug, diff_mat);
}
-
+
/* draw the strokes already in active frame */
gp_draw_strokes(gpd, gpf, offsx, offsy, winx, winy, dflag, debug, gpl->thickness,
gpl->opacity, gpl->tintcolor, false, false, diff_mat);
-
+
/* Draw verts of selected strokes
* - when doing OpenGL renders, we don't want to be showing these, as that ends up flickering
* - locked layers can't be edited, so there's no point showing these verts
@@ -1440,16 +1421,13 @@ static void gp_draw_data_layers(
{
gp_draw_strokes_edit(gpd, gpf, offsx, offsy, winx, winy, dflag, gpl->flag, diff_mat, alpha);
}
-
+
/* Check if may need to draw the active stroke cache, only if this layer is the active layer
* that is being edited. (Stroke buffer is currently stored in gp-data)
*/
if (ED_gpencil_session_active() && (gpl->flag & GP_LAYER_ACTIVE) &&
(gpf->flag & GP_FRAME_PAINT))
{
- /* Set color for drawing buffer stroke - since this may not be set yet */
- // glColor4fv(gpl->color);
-
/* Buffer stroke needs to be drawn with a different linestyle
* to help differentiate them from normal strokes.
*
@@ -1458,89 +1436,84 @@ static void gp_draw_data_layers(
*/
if (gpd->sflag & PC_COLOR_VOLUMETRIC) {
gp_draw_stroke_volumetric_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick,
- dflag, gpd->sbuffer_sflag, gpd->scolor);
+ dflag, gpd->scolor);
}
else {
- gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag, gpd->scolor);
+ gp_draw_stroke_buffer(gpd->sbuffer, gpd->sbuffer_size, lthick, dflag, gpd->sbuffer_sflag, gpd->scolor, gpd->sfill);
}
}
}
}
/* draw a short status message in the top-right corner */
-static void gp_draw_status_text(bGPdata *gpd, ARegion *ar)
+static void gp_draw_status_text(const bGPdata *gpd, ARegion *ar)
{
rcti rect;
-
+
/* Cannot draw any status text when drawing OpenGL Renders */
if (G.f & G_RENDER_OGL)
return;
-
+
/* Get bounds of region - Necessary to avoid problems with region overlap */
ED_region_visible_rect(ar, &rect);
-
+
/* for now, this should only be used to indicate when we are in stroke editmode */
if (gpd->flag & GP_DATA_STROKE_EDITMODE) {
const char *printable = IFACE_("GPencil Stroke Editing");
float printable_size[2];
- int xco, yco;
-
- BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
-
- xco = (rect.xmax - U.widget_unit) - (int)printable_size[0];
- yco = (rect.ymax - U.widget_unit);
+
+ int font_id = BLF_default();
+
+ BLF_width_and_height(font_id, printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
+ int xco = (rect.xmax - U.widget_unit) - (int)printable_size[0];
+ int yco = (rect.ymax - U.widget_unit);
+
/* text label */
- UI_ThemeColor(TH_TEXT_HI);
+ UI_FontThemeColor(font_id, TH_TEXT_HI);
#ifdef WITH_INTERNATIONAL
BLF_draw_default(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
#else
BLF_draw_default_ascii(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
#endif
-
+
/* grease pencil icon... */
// XXX: is this too intrusive?
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
-
+
xco -= U.widget_unit;
yco -= (int)printable_size[1] / 2;
UI_icon_draw(xco, yco, ICON_GREASEPENCIL);
-
+
glDisable(GL_BLEND);
}
}
/* draw grease-pencil datablock */
static void gp_draw_data(
- bGPDbrush *brush, float alpha, bGPdata *gpd,
+ const bGPDbrush *brush, float alpha, bGPdata *gpd,
int offsx, int offsy, int winx, int winy, int cfra, int dflag)
{
- /* reset line drawing style (in case previous user didn't reset) */
- setlinestyle(0);
-
/* turn on smooth lines (i.e. anti-aliasing) */
glEnable(GL_LINE_SMOOTH);
-
+
/* XXX: turn on some way of ensuring that the polygon edges get smoothed
* GL_POLYGON_SMOOTH is nasty and shouldn't be used, as it ends up
* creating internal white rays due to the ways it accumulates stuff
*/
-
+
/* turn on alpha-blending */
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
-
+
/* draw! */
gp_draw_data_layers(brush, alpha, gpd, offsx, offsy, winx, winy, cfra, dflag);
-
+
/* turn off alpha blending, then smooth lines */
glDisable(GL_BLEND); // alpha blending
glDisable(GL_LINE_SMOOTH); // smooth lines
-
- /* restore initial gl conditions */
- glColor4f(0, 0, 0, 1);
}
/* if we have strokes for scenes (3d view)/clips (movie clip editor)
@@ -1575,7 +1548,7 @@ static void gp_draw_data_all(Scene *scene, bGPdata *gpd, int offsx, int offsy, i
}
}
}
-
+
/* scene/clip data has already been drawn, only object/track data is drawn here
* if gpd_source == gpd, we don't have any object/track data and we can skip */
if (gpd_source == NULL || (gpd_source && gpd_source != gpd)) {
@@ -1601,28 +1574,27 @@ void ED_gpencil_draw_2dimage(const bContext *C)
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
- bGPdata *gpd;
+
int offsx, offsy, sizex, sizey;
int dflag = GP_DRAWDATA_NOSTATUS;
-
- gpd = ED_gpencil_data_get_active(C); // XXX
+
+ bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX
if (gpd == NULL) return;
-
+
/* calculate rect */
switch (sa->spacetype) {
case SPACE_IMAGE: /* image */
case SPACE_CLIP: /* clip */
{
-
/* just draw using standard scaling (settings here are currently ignored anyways) */
/* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */
offsx = 0;
offsy = 0;
sizex = ar->winx;
sizey = ar->winy;
-
+
wmOrtho2(ar->v2d.cur.xmin, ar->v2d.cur.xmax, ar->v2d.cur.ymin, ar->v2d.cur.ymax);
-
+
dflag |= GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_IEDITHACK;
break;
}
@@ -1633,7 +1605,7 @@ void ED_gpencil_draw_2dimage(const bContext *C)
offsy = 0;
sizex = ar->winx;
sizey = ar->winy;
-
+
/* NOTE: I2D was used in 2.4x, but the old settings for that have been deprecated
* and everything moved to standard View2d
*/
@@ -1645,77 +1617,80 @@ void ED_gpencil_draw_2dimage(const bContext *C)
offsy = 0;
sizex = ar->winx;
sizey = ar->winy;
-
+
dflag |= GP_DRAWDATA_ONLYI2D;
break;
}
-
+
if (ED_screen_animation_playing(wm)) {
/* don't show onionskins during animation playback/scrub (i.e. it obscures the poses)
* OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes)
*/
dflag |= GP_DRAWDATA_NO_ONIONS;
}
-
-
+
/* draw it! */
gp_draw_data_all(scene, gpd, offsx, offsy, sizex, sizey, CFRA, dflag, sa->spacetype);
}
/* draw grease-pencil sketches to specified 2d-view assuming that matrices are already set correctly
- * Note: this gets called twice - first time with onlyv2d=1 to draw 'canvas' strokes,
- * second time with onlyv2d=0 for screen-aligned strokes */
+ * Note: this gets called twice - first time with onlyv2d=true to draw 'canvas' strokes,
+ * second time with onlyv2d=false for screen-aligned strokes */
void ED_gpencil_draw_view2d(const bContext *C, bool onlyv2d)
{
wmWindowManager *wm = CTX_wm_manager(C);
ScrArea *sa = CTX_wm_area(C);
ARegion *ar = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
- bGPdata *gpd;
int dflag = 0;
/* check that we have grease-pencil stuff to draw */
if (sa == NULL) return;
- gpd = ED_gpencil_data_get_active(C); // XXX
+ bGPdata *gpd = ED_gpencil_data_get_active(C); // XXX
if (gpd == NULL) return;
-
+
/* special hack for Image Editor */
/* FIXME: the opengl poly-strokes don't draw at right thickness when done this way, so disabled */
if (ELEM(sa->spacetype, SPACE_IMAGE, SPACE_CLIP))
dflag |= GP_DRAWDATA_IEDITHACK;
-
+
/* draw it! */
if (onlyv2d) dflag |= (GP_DRAWDATA_ONLYV2D | GP_DRAWDATA_NOSTATUS);
if (ED_screen_animation_playing(wm)) dflag |= GP_DRAWDATA_NO_ONIONS;
-
+
gp_draw_data_all(scene, gpd, 0, 0, ar->winx, ar->winy, CFRA, dflag, sa->spacetype);
-
+
/* draw status text (if in screen/pixel-space) */
- if (onlyv2d == false) {
+ if (!onlyv2d) {
gp_draw_status_text(gpd, ar);
}
}
/* draw grease-pencil sketches to specified 3d-view assuming that matrices are already set correctly
- * Note: this gets called twice - first time with only3d=1 to draw 3d-strokes,
- * second time with only3d=0 for screen-aligned strokes */
-void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, View3D *v3d, ARegion *ar, bool only3d)
+ * Note: this gets called twice - first time with only3d=true to draw 3d-strokes,
+ * second time with only3d=false for screen-aligned strokes */
+void ED_gpencil_draw_view3d(wmWindowManager *wm,
+ Scene *scene,
+ ViewLayer *view_layer,
+ struct Depsgraph *depsgraph,
+ View3D *v3d,
+ ARegion *ar,
+ bool only3d)
{
- bGPdata *gpd;
int dflag = 0;
RegionView3D *rv3d = ar->regiondata;
int offsx, offsy, winx, winy;
-
+
/* check that we have grease-pencil stuff to draw */
- gpd = ED_gpencil_data_get_active_v3d(scene, v3d);
+ bGPdata *gpd = ED_gpencil_data_get_active_v3d(scene, view_layer);
if (gpd == NULL) return;
-
+
/* when rendering to the offscreen buffer we don't want to
* deal with the camera border, otherwise map the coords to the camera border. */
if ((rv3d->persp == RV3D_CAMOB) && !(G.f & G_RENDER_OGL)) {
rctf rectf;
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &rectf, true); /* no shift */
-
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &rectf, true); /* no shift */
+
offsx = round_fl_to_int(rectf.xmin);
offsy = round_fl_to_int(rectf.ymin);
winx = round_fl_to_int(rectf.xmax - rectf.xmin);
@@ -1727,7 +1702,7 @@ void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, View3D *v3d, AReg
winx = ar->winx;
winy = ar->winy;
}
-
+
/* set flags */
if (only3d) {
/* 3D strokes/3D space:
@@ -1736,28 +1711,27 @@ void ED_gpencil_draw_view3d(wmWindowManager *wm, Scene *scene, View3D *v3d, AReg
*/
dflag |= (GP_DRAWDATA_ONLY3D | GP_DRAWDATA_NOSTATUS);
}
-
+
if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
/* don't draw status text when "only render" flag is set */
dflag |= GP_DRAWDATA_NOSTATUS;
}
-
+
if ((wm == NULL) || ED_screen_animation_playing(wm)) {
/* don't show onionskins during animation playback/scrub (i.e. it obscures the poses)
* OpenGL Renders (i.e. final output), or depth buffer (i.e. not real strokes)
*/
dflag |= GP_DRAWDATA_NO_ONIONS;
}
-
+
/* draw it! */
- gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype);
-
+ gp_draw_data_all(scene, gpd, offsx, offsy, winx, winy, CFRA, dflag, v3d->spacetype);
}
void ED_gpencil_draw_ex(Scene *scene, bGPdata *gpd, int winx, int winy, const int cfra, const char spacetype)
{
int dflag = GP_DRAWDATA_NOSTATUS | GP_DRAWDATA_ONLYV2D;
-
+
gp_draw_data_all(scene, gpd, 0, 0, winx, winy, cfra, dflag, spacetype);
}
diff --git a/source/blender/editors/gpencil/gpencil_brush.c b/source/blender/editors/gpencil/gpencil_brush.c
index 5fe16226421..533ab21dbb6 100644
--- a/source/blender/editors/gpencil/gpencil_brush.c
+++ b/source/blender/editors/gpencil/gpencil_brush.c
@@ -74,8 +74,8 @@
#include "ED_screen.h"
#include "ED_view3d.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
#include "gpencil_intern.h"
@@ -978,28 +978,28 @@ static bool gpsculpt_brush_apply_clone(bContext *C, tGP_BrushEditData *gso)
static void gp_brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata))
{
GP_EditBrush_Data *brush = gpsculpt_get_brush(CTX_data_scene(C));
-
+
if (brush) {
- glPushMatrix();
-
- glTranslatef((float)x, (float)y, 0.0f);
-
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
-
+
/* Inner Ring: Light color for action of the brush */
/* TODO: toggle between add and remove? */
- glColor4ub(255, 255, 255, 200);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, brush->size, 40);
-
+ immUniformColor4ub(255, 255, 255, 200);
+ imm_draw_circle_wire_2d(pos, x, y, brush->size, 40);
+
/* Outer Ring: Dark color for contrast on light backgrounds (e.g. gray on white) */
- glColor3ub(30, 30, 30);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, brush->size + 1, 40);
-
+ immUniformColor3ub(30, 30, 30);
+ imm_draw_circle_wire_2d(pos, x, y, brush->size + 1, 40);
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
-
- glPopMatrix();
}
}
diff --git a/source/blender/editors/gpencil/gpencil_convert.c b/source/blender/editors/gpencil/gpencil_convert.c
index 7d455f214db..19663b66f92 100644
--- a/source/blender/editors/gpencil/gpencil_convert.c
+++ b/source/blender/editors/gpencil/gpencil_convert.c
@@ -55,13 +55,15 @@
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
#include "DNA_gpencil_types.h"
+#include "DNA_workspace_types.h"
+#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_gpencil.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_object.h"
#include "BKE_report.h"
@@ -69,6 +71,8 @@
#include "BKE_screen.h"
#include "BKE_tracking.h"
+#include "DEG_depsgraph.h"
+
#include "UI_interface.h"
#include "WM_api.h"
@@ -546,7 +550,7 @@ static void gp_stroke_path_animation(bContext *C, ReportList *reports, Curve *cu
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL);
/* send updates */
- DAG_id_tag_update(&cu->id, 0);
+ DEG_id_tag_update(&cu->id, 0);
}
#undef MIN_TIME_DELTA
@@ -1108,7 +1112,8 @@ static int gp_camera_view_subrect(bContext *C, rctf *subrect)
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
Scene *scene = CTX_data_scene(C);
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, subrect, true); /* no shift */
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, subrect, true); /* no shift */
return 1;
}
}
@@ -1121,14 +1126,15 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
const bool norm_weights, const float rad_fac, const bool link_strokes, tGpTimingData *gtd)
{
struct Main *bmain = CTX_data_main(C);
- View3D *v3d = CTX_wm_view3d(C); /* may be NULL */
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ SceneCollection *sc = CTX_data_scene_collection(C);
bGPDframe *gpf = BKE_gpencil_layer_getframe(gpl, CFRA, 0);
bGPDstroke *gps, *prev_gps = NULL;
Object *ob;
Curve *cu;
Nurb *nu = NULL;
- Base *base_orig = BASACT, *base_new = NULL;
+ Base *base_new = NULL;
float minmax_weights[2] = {1.0f, 0.0f};
/* camera framing */
@@ -1152,7 +1158,8 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
*/
ob = BKE_object_add_only_object(bmain, OB_CURVE, gpl->info);
cu = ob->data = BKE_curve_add(bmain, gpl->info, OB_CURVE);
- base_new = BKE_scene_base_add(scene, ob);
+ BKE_collection_object_add(&scene->id, sc, ob);
+ base_new = BKE_view_layer_base_find(view_layer, ob);
cu->flag |= CU_3D;
@@ -1216,8 +1223,8 @@ static void gp_layer_to_curve(bContext *C, ReportList *reports, bGPdata *gpd, bG
}
/* set the layer and select */
- base_new->lay = ob->lay = base_orig ? base_orig->lay : BKE_screen_view3d_layer_active(v3d, scene);
- base_new->flag = ob->flag = base_new->flag | SELECT;
+ base_new->flag |= SELECT;
+ BKE_scene_object_base_flag_sync_from_base(base_new);
}
/* --- */
@@ -1287,6 +1294,7 @@ static int gp_convert_poll(bContext *C)
bGPDframe *gpf = NULL;
ScrArea *sa = CTX_wm_area(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
/* only if the current view is 3D View, if there's valid data (i.e. at least one stroke!),
* and if we are not in edit mode!
@@ -1295,7 +1303,7 @@ static int gp_convert_poll(bContext *C)
(gpl = BKE_gpencil_layer_getactive(gpd)) &&
(gpf = BKE_gpencil_layer_getframe(gpl, CFRA, 0)) &&
(gpf->strokes.first) &&
- (scene->obedit == NULL));
+ (OBEDIT_FROM_VIEW_LAYER(view_layer) == NULL));
}
static int gp_convert_layer_exec(bContext *C, wmOperator *op)
@@ -1442,7 +1450,7 @@ static void gp_convert_ui(bContext *C, wmOperator *op)
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
/* Main auto-draw call */
- uiDefAutoButsRNA(layout, &ptr, gp_convert_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, gp_convert_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
}
void GPENCIL_OT_convert(wmOperatorType *ot)
diff --git a/source/blender/editors/gpencil/gpencil_edit.c b/source/blender/editors/gpencil/gpencil_edit.c
index bc54bd89958..4f9abff292a 100644
--- a/source/blender/editors/gpencil/gpencil_edit.c
+++ b/source/blender/editors/gpencil/gpencil_edit.c
@@ -78,6 +78,8 @@
#include "ED_view3d.h"
#include "ED_space_api.h"
+#include "DEG_depsgraph.h"
+
#include "gpencil_intern.h"
/* ************************************************ */
@@ -2107,8 +2109,9 @@ static int gp_strokes_reproject_exec(bContext *C, wmOperator *op)
/* init autodist for geometry projection */
if (mode == GP_REPROJECT_SURFACE) {
+ struct Depsgraph *graph = CTX_data_depsgraph(C);
view3d_region_operator_needs_opengl(CTX_wm_window(C), gsc.ar);
- ED_view3d_autodist_init(scene, gsc.ar, CTX_wm_view3d(C), 0);
+ ED_view3d_autodist_init(graph, gsc.ar, CTX_wm_view3d(C), 0);
}
// TODO: For deforming geometry workflow, create new frames?
diff --git a/source/blender/editors/gpencil/gpencil_paint.c b/source/blender/editors/gpencil/gpencil_paint.c
index 84b3ddccf77..ccd47463a9c 100644
--- a/source/blender/editors/gpencil/gpencil_paint.c
+++ b/source/blender/editors/gpencil/gpencil_paint.c
@@ -68,15 +68,19 @@
#include "ED_view3d.h"
#include "ED_clip.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "DEG_depsgraph.h"
+
#include "gpencil_intern.h"
/* ******************************************* */
@@ -112,6 +116,7 @@ typedef enum eGPencil_PaintFlags {
*/
typedef struct tGPsdata {
Scene *scene; /* current scene from context */
+ struct Depsgraph *graph;
wmWindow *win; /* window where painting originated */
ScrArea *sa; /* area where painting originated */
@@ -480,7 +485,8 @@ static void gp_brush_angle(bGPdata *gpd, bGPDbrush *brush, tGPspoint *pt, const
}
/* add current stroke-point to buffer (returns whether point was successfully added) */
-static short gp_stroke_addpoint(tGPsdata *p, const int mval[2], float pressure, double curtime)
+static short gp_stroke_addpoint(
+ tGPsdata *p, const int mval[2], float pressure, double curtime)
{
bGPdata *gpd = p->gpd;
bGPDbrush *brush = p->brush;
@@ -638,7 +644,8 @@ static short gp_stroke_addpoint(tGPsdata *p, const int mval[2], float pressure,
View3D *v3d = p->sa->spacedata.first;
view3d_region_operator_needs_opengl(p->win, p->ar);
- ED_view3d_autodist_init(p->scene, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0);
+ ED_view3d_autodist_init(
+ p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0);
}
/* convert screen-coordinates to appropriate coordinates (and store them) */
@@ -672,7 +679,7 @@ static short gp_stroke_addpoint(tGPsdata *p, const int mval[2], float pressure,
/* simplify a stroke (in buffer) before storing it
* - applies a reverse Chaikin filter
- * - code adapted from etch-a-ton branch (editarmature_sketch.c)
+ * - code adapted from etch-a-ton branch
*/
static void gp_stroke_simplify(tGPsdata *p)
{
@@ -734,7 +741,7 @@ static void gp_stroke_simplify(tGPsdata *p)
/* ignore return values on this... assume to be ok for now */
gp_stroke_addpoint(p, mco, pressure, p->inittime + (double)time);
-
+
j += 2;
}
}
@@ -1238,9 +1245,8 @@ static void gp_stroke_doeraser(tGPsdata *p)
if (p->sa->spacetype == SPACE_VIEW3D) {
if (p->flags & GP_PAINTFLAG_V3D_ERASER_DEPTH) {
View3D *v3d = p->sa->spacedata.first;
-
view3d_region_operator_needs_opengl(p->win, p->ar);
- ED_view3d_autodist_init(p->scene, p->ar, v3d, 0);
+ ED_view3d_autodist_init(p->graph, p->ar, v3d, 0);
}
}
@@ -1394,6 +1400,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
/* pass on current scene and window */
p->scene = CTX_data_scene(C);
+ p->graph = CTX_data_depsgraph(C);
p->win = CTX_wm_window(C);
unit_m4(p->imat);
@@ -1548,6 +1555,7 @@ static bool gp_session_initdata(bContext *C, tGPsdata *p)
bGPDpalettecolor *palcolor = p->palettecolor;
bGPdata *pdata = p->gpd;
copy_v4_v4(pdata->scolor, palcolor->color);
+ copy_v4_v4(pdata->sfill, palcolor->fill);
pdata->sflag = palcolor->flag;
/* lock axis */
p->lock_axis = ts->gp_sculpt.lock_axis;
@@ -1598,7 +1606,7 @@ static void gp_session_cleanup(tGPsdata *p)
}
/* init new stroke */
-static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode)
+static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode, Depsgraph *depsgraph)
{
Scene *scene = p->scene;
ToolSettings *ts = scene->toolsettings;
@@ -1727,7 +1735,7 @@ static void gp_paint_initstroke(tGPsdata *p, eGPencil_PaintModes paintmode)
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
- ED_view3d_calc_camera_border(p->scene, p->ar, v3d, rv3d, &p->subrect_data, true); /* no shift */
+ ED_view3d_calc_camera_border(p->scene, depsgraph, p->ar, v3d, rv3d, &p->subrect_data, true); /* no shift */
p->subrect = &p->subrect_data;
}
}
@@ -1805,14 +1813,14 @@ static void gp_paint_strokeend(tGPsdata *p)
/* need to restore the original projection settings before packing up */
view3d_region_operator_needs_opengl(p->win, p->ar);
- ED_view3d_autodist_init(p->scene, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0);
+ ED_view3d_autodist_init(p->graph, p->ar, v3d, (ts->gpencil_v3d_align & GP_PROJECT_DEPTH_STROKE) ? 1 : 0);
}
/* check if doing eraser or not */
if ((p->gpd->sbuffer_sflag & GP_STROKE_ERASER) == 0) {
/* simplify stroke before transferring? */
gp_stroke_simplify(p);
-
+
/* transfer stroke to frame */
gp_stroke_newfrombuffer(p);
}
@@ -1843,28 +1851,41 @@ static void gp_paint_cleanup(tGPsdata *p)
static void gpencil_draw_eraser(bContext *UNUSED(C), int x, int y, void *p_ptr)
{
tGPsdata *p = (tGPsdata *)p_ptr;
-
+
if (p->paintmode == GP_PAINTMODE_ERASER) {
- glPushMatrix();
-
- glTranslatef((float)x, (float)y, 0.0f);
-
+ Gwn_VertFormat *format = immVertexFormat();
+ const uint shdr_pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
-
- glColor4ub(255, 100, 100, 20);
- glutil_draw_filled_arc(0.0, M_PI * 2.0, p->radius, 40);
-
- setlinestyle(6);
-
- glColor4ub(255, 100, 100, 200);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, p->radius, 40);
-
- setlinestyle(0);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ immUniformColor4ub(255, 100, 100, 20);
+ imm_draw_circle_fill_2d(shdr_pos, x, y, p->radius, 40);
+
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniformColor4f(1.0f, 0.39f, 0.39f, 0.78f);
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniform1f("dash_width", 12.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ imm_draw_circle_wire_2d(shdr_pos, x, y, p->radius,
+ /* XXX Dashed shader gives bad results with sets of small segments currently,
+ * temp hack around the issue. :( */
+ max_ii(8, p->radius / 2)); /* was fixed 40 */
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
-
- glPopMatrix();
}
}
@@ -1955,7 +1976,7 @@ static int gpencil_draw_init(bContext *C, wmOperator *op, const wmEvent *event)
}
/* init painting data */
- gp_paint_initstroke(p, paintmode);
+ gp_paint_initstroke(p, paintmode, CTX_data_depsgraph(C));
if (p->status == GP_STATUS_ERROR) {
gpencil_draw_exit(C, op);
return 0;
@@ -2032,13 +2053,13 @@ static void gpencil_draw_status_indicators(tGPsdata *p)
/* ------------------------------- */
/* create a new stroke point at the point indicated by the painting context */
-static void gpencil_draw_apply(wmOperator *op, tGPsdata *p)
+static void gpencil_draw_apply(wmOperator *op, tGPsdata *p, Depsgraph *depsgraph)
{
/* handle drawing/erasing -> test for erasing first */
if (p->paintmode == GP_PAINTMODE_ERASER) {
/* do 'live' erasing now */
gp_stroke_doeraser(p);
-
+
/* store used values */
p->mvalo[0] = p->mval[0];
p->mvalo[1] = p->mval[1];
@@ -2048,13 +2069,13 @@ static void gpencil_draw_apply(wmOperator *op, tGPsdata *p)
else if (gp_stroke_filtermval(p, p->mval, p->mvalo)) {
/* try to add point */
short ok = gp_stroke_addpoint(p, p->mval, p->pressure, p->curtime);
-
+
/* handle errors while adding point */
if ((ok == GP_STROKEADD_FULL) || (ok == GP_STROKEADD_OVERFLOW)) {
/* finish off old stroke */
gp_paint_strokeend(p);
/* And start a new one!!! Else, projection errors! */
- gp_paint_initstroke(p, p->paintmode);
+ gp_paint_initstroke(p, p->paintmode, depsgraph);
/* start a new stroke, starting from previous point */
/* XXX Must manually reset inittime... */
@@ -2087,7 +2108,7 @@ static void gpencil_draw_apply(wmOperator *op, tGPsdata *p)
}
/* handle draw event */
-static void gpencil_draw_apply_event(wmOperator *op, const wmEvent *event)
+static void gpencil_draw_apply_event(wmOperator *op, const wmEvent *event, Depsgraph *depsgraph)
{
tGPsdata *p = op->customdata;
PointerRNA itemptr;
@@ -2192,8 +2213,8 @@ static void gpencil_draw_apply_event(wmOperator *op, const wmEvent *event)
RNA_float_set(&itemptr, "time", p->curtime - p->inittime);
/* apply the current latest drawing point */
- gpencil_draw_apply(op, p);
-
+ gpencil_draw_apply(op, p, depsgraph);
+
/* force refresh */
ED_region_tag_redraw(p->ar); /* just active area for now, since doing whole screen is too slow */
}
@@ -2204,6 +2225,7 @@ static void gpencil_draw_apply_event(wmOperator *op, const wmEvent *event)
static int gpencil_draw_exec(bContext *C, wmOperator *op)
{
tGPsdata *p = NULL;
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
/* printf("GPencil - Starting Re-Drawing\n"); */
@@ -2241,7 +2263,7 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
if ((p->flags & GP_PAINTFLAG_FIRSTRUN) == 0) {
/* TODO: both of these ops can set error-status, but we probably don't need to worry */
gp_paint_strokeend(p);
- gp_paint_initstroke(p, p->paintmode);
+ gp_paint_initstroke(p, p->paintmode, depsgraph);
}
}
@@ -2256,7 +2278,7 @@ static int gpencil_draw_exec(bContext *C, wmOperator *op)
}
/* apply this data as necessary now (as per usual) */
- gpencil_draw_apply(op, p);
+ gpencil_draw_apply(op, p, depsgraph);
}
RNA_END;
@@ -2315,7 +2337,7 @@ static int gpencil_draw_invoke(bContext *C, wmOperator *op, const wmEvent *event
p->status = GP_STATUS_PAINTING;
/* handle the initial drawing - i.e. for just doing a simple dot */
- gpencil_draw_apply_event(op, event);
+ gpencil_draw_apply_event(op, event, CTX_data_depsgraph(C));
op->flag |= OP_IS_MODAL_CURSOR_REGION;
}
else {
@@ -2356,7 +2378,7 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
* it'd be nice to allow changing paint-mode when in sketching-sessions */
if (gp_session_initdata(C, p))
- gp_paint_initstroke(p, p->paintmode);
+ gp_paint_initstroke(p, p->paintmode, CTX_data_depsgraph(C));
if (p->status != GP_STATUS_ERROR) {
p->status = GP_STATUS_PAINTING;
@@ -2369,9 +2391,9 @@ static tGPsdata *gpencil_stroke_begin(bContext *C, wmOperator *op)
static void gpencil_stroke_end(wmOperator *op)
{
tGPsdata *p = op->customdata;
-
+
gp_paint_cleanup(p);
-
+
gpencil_undo_push(p->gpd);
gp_session_cleanup(p);
@@ -2505,7 +2527,7 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* end stroke only, and then wait to resume painting soon */
/* printf("\t\tGP - end stroke only\n"); */
gpencil_stroke_end(op);
-
+
/* If eraser mode is on, turn it off after the stroke finishes
* NOTE: This just makes it nicer to work with drawing sessions
*/
@@ -2647,8 +2669,8 @@ static int gpencil_draw_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE) || (p->flags & GP_PAINTFLAG_FIRSTRUN)) {
/* handle drawing event */
/* printf("\t\tGP - add point\n"); */
- gpencil_draw_apply_event(op, event);
-
+ gpencil_draw_apply_event(op, event, CTX_data_depsgraph(C));
+
/* finish painting operation if anything went wrong just now */
if (p->status == GP_STATUS_ERROR) {
printf("\t\t\t\tGP - add error done!\n");
diff --git a/source/blender/editors/gpencil/gpencil_utils.c b/source/blender/editors/gpencil/gpencil_utils.c
index 672c87ed6fd..d7e5b5a92aa 100644
--- a/source/blender/editors/gpencil/gpencil_utils.c
+++ b/source/blender/editors/gpencil/gpencil_utils.c
@@ -65,6 +65,8 @@
#include "ED_clip.h"
#include "ED_view3d.h"
+#include "DEG_depsgraph.h"
+
#include "gpencil_intern.h"
/* ******************************************************** */
@@ -202,15 +204,15 @@ bGPdata *ED_gpencil_data_get_active(const bContext *C)
/* -------------------------------------------------------- */
// XXX: this should be removed... We really shouldn't duplicate logic like this!
-bGPdata *ED_gpencil_data_get_active_v3d(Scene *scene, View3D *v3d)
+bGPdata *ED_gpencil_data_get_active_v3d(Scene *scene, ViewLayer *view_layer)
{
- Base *base = scene->basact;
+ Base *base = view_layer->basact;
bGPdata *gpd = NULL;
/* We have to make sure active object is actually visible and selected, else we must use default scene gpd,
* to be consistent with ED_gpencil_data_get_active's behavior.
*/
- if (base && TESTBASE(v3d, base)) {
+ if (base && TESTBASE(base)) {
gpd = base->object->gpd;
}
return gpd ? gpd : scene->gpd;
@@ -536,6 +538,7 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc)
if (sa->spacetype == SPACE_VIEW3D) {
wmWindow *win = CTX_wm_window(C);
Scene *scene = CTX_data_scene(C);
+ struct Depsgraph *graph = CTX_data_depsgraph(C);
View3D *v3d = (View3D *)CTX_wm_space_data(C);
RegionView3D *rv3d = ar->regiondata;
@@ -543,11 +546,11 @@ void gp_point_conversion_init(bContext *C, GP_SpaceConversion *r_gsc)
view3d_operator_needs_opengl(C);
view3d_region_operator_needs_opengl(win, ar);
- ED_view3d_autodist_init(scene, ar, v3d, 0);
+ ED_view3d_autodist_init(graph, ar, v3d, 0);
/* for camera view set the subrect */
if (rv3d->persp == RV3D_CAMOB) {
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &r_gsc->subrect_data, true); /* no shift */
+ ED_view3d_calc_camera_border(scene, CTX_data_depsgraph(C), ar, v3d, rv3d, &r_gsc->subrect_data, true); /* no shift */
r_gsc->subrect = &r_gsc->subrect_data;
}
}
@@ -912,8 +915,8 @@ bool gp_smooth_stroke_thickness(bGPDstroke *gps, int i, float inf)
ptc = &gps->points[after];
/* the optimal value is the corresponding to the interpolation of the pressure
- * at the distance of point b
- */
+ * at the distance of point b
+ */
float fac = line_point_factor_v3(&ptb->x, &pta->x, &ptc->x);
float optimal = (1.0f - fac) * pta->pressure + fac * ptc->pressure;
diff --git a/source/blender/editors/include/BIF_gl.h b/source/blender/editors/include/BIF_gl.h
index e264d9e16a3..f91e7d42bca 100644
--- a/source/blender/editors/include/BIF_gl.h
+++ b/source/blender/editors/include/BIF_gl.h
@@ -36,45 +36,6 @@
#include "GPU_glew.h"
#include "BLI_utildefines.h"
-/*
- * these should be phased out. cpack should be replaced in
- * code with calls to glColor3ub. - zr
- */
-/*
- *
- * This define converts a numerical value to the equivalent 24-bit
- * color, while not being endian-sensitive. On little-endians, this
- * is the same as doing a 'naive' indexing, on big-endian, it is not!
- * */
-void cpack(unsigned int x);
-
-#ifdef WITH_GL_PROFILE_COMPAT
-#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
-# define glMultMatrixf(x) \
- glMultMatrixf(_Generic((x), \
- float *: (float *)(x), \
- float [16]: (float *)(x), \
- float (*)[4]: (float *)(x), \
- float [4][4]: (float *)(x), \
- const float *: (float *)(x), \
- const float [16]: (float *)(x), \
- const float (*)[4]: (float *)(x), \
- const float [4][4]: (float *)(x)) \
-)
-# define glLoadMatrixf(x) \
- glLoadMatrixf(_Generic((x), \
- float *: (float *)(x), \
- float [16]: (float *)(x), \
- float (*)[4]: (float *)(x), \
- float [4][4]: (float *)(x)) \
-)
-#else
-# define glMultMatrixf(x) glMultMatrixf((float *)(x))
-# define glLoadMatrixf(x) glLoadMatrixf((float *)(x))
-#endif /* C11 */
-#endif /* WITH_GL_PROFILE_COMPAT */
-
-
/* hacking pointsize and linewidth */
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
# define glPointSize(f) glPointSize(U.pixelsize * _Generic((f), double: (float)(f), default: (f)))
@@ -86,19 +47,5 @@ void cpack(unsigned int x);
#define GLA_PIXEL_OFS 0.375f
-
-BLI_INLINE void glTranslate3iv(const int vec[3]) { glTranslatef(UNPACK3_EX((const float), vec, )); }
-BLI_INLINE void glTranslate2iv(const int vec[2]) { glTranslatef(UNPACK2_EX((const float), vec, ), 0.0f); }
-BLI_INLINE void glTranslate3fv(const float vec[3]) { glTranslatef(UNPACK3(vec)); }
-BLI_INLINE void glTranslate2fv(const float vec[2]) { glTranslatef(UNPACK2(vec), 0.0f); }
-
-BLI_INLINE void glScale3iv(const int vec[3]) { glTranslatef(UNPACK3_EX((const float), vec, )); }
-BLI_INLINE void glScale2iv(const int vec[2]) { glTranslatef(UNPACK2_EX((const float), vec, ), 0.0f); }
-BLI_INLINE void glScale3fv(const float vec[3]) { glScalef(UNPACK3(vec)); }
-BLI_INLINE void glScale2fv(const float vec[2]) { glScalef(UNPACK2(vec), 0.0); }
-
-/* v2 versions don't make much sense for rotation */
-BLI_INLINE void glRotate3fv(const float angle, const float vec[3]) { glRotatef(angle, UNPACK3(vec)); }
-
#endif /* #ifdef __BIF_GL_H__ */
diff --git a/source/blender/editors/include/BIF_glutil.h b/source/blender/editors/include/BIF_glutil.h
index d3d2c465d46..863d817d19a 100644
--- a/source/blender/editors/include/BIF_glutil.h
+++ b/source/blender/editors/include/BIF_glutil.h
@@ -38,56 +38,14 @@ struct bContext;
struct ColorManagedViewSettings;
struct ColorManagedDisplaySettings;
-void fdrawbezier(float vec[4][3]);
-void fdrawline(float x1, float y1, float x2, float y2);
-void fdrawbox(float x1, float y1, float x2, float y2);
-void sdrawline(int x1, int y1, int x2, int y2);
-#if 0
-void sdrawtri(int x1, int y1, int x2, int y2);
-void sdrawtrifill(int x1, int y1, int x2, int y2);
-#endif
-void sdrawbox(int x1, int y1, int x2, int y2);
-
-void sdrawXORline(int x0, int y0, int x1, int y1);
-void sdrawXORline4(int nr, int x0, int y0, int x1, int y1);
-
-void fdrawXORellipse(float xofs, float yofs, float hw, float hh);
-void fdrawXORcirc(float xofs, float yofs, float rad);
-
-void fdrawcheckerboard(float x1, float y1, float x2, float y2);
-
-/* OpenGL stipple defines */
-extern const unsigned char stipple_halftone[128];
-extern const unsigned char stipple_quarttone[128];
-extern const unsigned char stipple_diag_stripes_pos[128];
-extern const unsigned char stipple_diag_stripes_neg[128];
-extern const unsigned char stipple_checker_8px[128];
-
-/**
- * Draw a lined (non-looping) arc with the given
- * \a radius, starting at angle \a start and arcing
- * through \a angle. The arc is centered at the origin
- * and drawn in the XY plane.
+/* A few functions defined here are being DEPRECATED for Blender 2.8
*
- * \param start The initial angle (in radians).
- * \param angle The length of the arc (in radians).
- * \param radius The arc radius.
- * \param nsegments The number of segments to use in drawing the arc.
- */
-void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments);
-
-/**
- * Draw a filled arc with the given \a radius,
- * starting at angle \a start and arcing through
- * \a angle. The arc is centered at the origin
- * and drawn in the XY plane.
+ * Do not use them in new code, and you are encouraged to
+ * convert existing code to draw without these.
*
- * \param start The initial angle (in radians).
- * \param angle The length of the arc (in radians).
- * \param radius The arc radius.
- * \param nsegments The number of segments to use in drawing the arc.
+ * These will be deleted before we ship 2.8!
+ * - merwin
*/
-void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments);
/**
* Returns a float value as obtained by glGetFloatv.
@@ -109,88 +67,46 @@ int glaGetOneInt(int param);
*/
void glaRasterPosSafe2f(float x, float y, float known_good_x, float known_good_y);
-/**
- * Functions like a limited glDrawPixels, except ensures that
- * the image is displayed onscreen even if the \a x and \a y
- * coordinates for would be clipped. The routine respects the
- * glPixelZoom values, pixel unpacking parameters are _not_
- * respected.
- *
- * \attention This routine makes many assumptions: the rect data
- * is expected to be in RGBA unsigned byte format, the coordinate
- * (GLA_PIXEL_OFS, GLA_PIXEL_OFS) is assumed to be within the view frustum,
- * and the modelview and projection matrices are assumed to define a
- * 1-to-1 mapping to screen space.
- * \attention Furthermore, in the case of zoomed or unpixel aligned
- * images extending outside the view frustum, but still within the
- * window, some portion of the image may be visible left and/or
- * below of the given \a x and \a y coordinates. It is recommended
- * to use the glScissor functionality if images are to be drawn
- * with an inset view matrix.
- */
-void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect);
+typedef struct IMMDrawPixelsTexState {
+ struct GPUShader *shader;
+ unsigned int pos;
+ unsigned int texco;
+ bool do_shader_unbind;
+} IMMDrawPixelsTexState;
+
+/* To be used before calling immDrawPixelsTex
+ * Default shader is GPU_SHADER_2D_IMAGE_COLOR
+ * Returns a shader to be able to set uniforms */
+IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin);
/**
- * glaDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the
+ * immDrawPixelsTex - Functions like a limited glDrawPixels, but actually draws the
* image using textures, which can be tremendously faster on low-end
* cards, and also avoids problems with the raster position being
- * clipped when offscreen. The routine respects the glPixelZoom values,
- * pixel unpacking parameters are _not_ respected.
+ * clipped when offscreen. Pixel unpacking parameters and
+ * the glPixelZoom values are _not_ respected.
+ *
+ * \attention Use immDrawPixelsTexSetup before calling this function.
*
* \attention This routine makes many assumptions: the rect data
* is expected to be in RGBA byte or float format, and the
* modelview and projection matrices are assumed to define a
* 1-to-1 mapping to screen space.
*/
-
-void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect);
-void glaDrawPixelsTex_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
- float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y);
-
-/**
- * glaDrawPixelsAuto - Switches between texture or pixel drawing using UserDef.
- * only RGBA
- * needs glaDefine2DArea to be set.
- */
-void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect);
-void glaDrawPixelsAuto_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
- float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y);
-
-
-void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY);
-void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY,
- float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y);
-
-/* 2D Drawing Assistance */
-
-/** Define a 2D area (viewport, scissor, matrices) for OpenGL rendering.
- *
- * glaDefine2DArea and glaBegin2DDraw set up an OpenGL state appropriate
- * for drawing using both vertex (Vertex, etc) and raster (RasterPos, Rect)
- * commands. All coordinates should be at integer positions. There is little
- * to no reason to use glVertex2f etc. functions during 2D rendering, and
- * thus no reason to +-0.5 the coordinates or perform other silly
- * tricks.
- *
- * \param screen_rect The screen rectangle to be defined for 2D drawing.
- */
-void glaDefine2DArea(struct rcti *screen_rect);
-
-typedef struct gla2DDrawInfo gla2DDrawInfo;
-
-/* UNUSED */
-#if 0
-
-gla2DDrawInfo *glaBegin2DDraw(struct rcti *screen_rect, struct rctf *world_rect);
-void gla2DDrawTranslatePt(gla2DDrawInfo *di, float wo_x, float wo_y, int *r_sc_x, int *r_sc_y);
-void gla2DDrawTranslatePtv(gla2DDrawInfo *di, float world[2], int r_screen[2]);
-
-void glaEnd2DDraw(gla2DDrawInfo *di);
-
-/** Adjust the transformation mapping of a 2d area */
-void gla2DGetMap(gla2DDrawInfo *di, struct rctf *rect);
-void gla2DSetMap(gla2DDrawInfo *di, struct rctf *rect);
-#endif
+void immDrawPixelsTex(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
+ float xzoom, float yzoom, float color[4]);
+void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
+ float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y,
+ float xzoom, float yzoom, float color[4]);
+void immDrawPixelsTexScaled(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY,
+ float xzoom, float yzoom, float color[4]);
+void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect, float scaleX, float scaleY,
+ float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y,
+ float xzoom, float yzoom, float color[4]);
void set_inverted_drawing(int enable);
void setlinestyle(int nr);
@@ -198,37 +114,32 @@ void setlinestyle(int nr);
/* own working polygon offset */
void bglPolygonOffset(float viewdist, float dist);
-/* For caching opengl matrices (gluProject/gluUnProject) */
-typedef struct bglMats {
- double modelview[16];
- double projection[16];
- int viewport[4];
-} bglMats;
-void bgl_get_mats(bglMats *mats);
-
/* **** Color management helper functions for GLSL display/transform ***** */
/* Draw imbuf on a screen, preferably using GLSL display transform */
void glaDrawImBuf_glsl(struct ImBuf *ibuf, float x, float y, int zoomfilter,
struct ColorManagedViewSettings *view_settings,
- struct ColorManagedDisplaySettings *display_settings);
+ struct ColorManagedDisplaySettings *display_settings,
+ float zoom_x, float zoom_y);
void glaDrawImBuf_glsl_clipping(struct ImBuf *ibuf, float x, float y, int zoomfilter,
struct ColorManagedViewSettings *view_settings,
struct ColorManagedDisplaySettings *display_settings,
float clip_min_x, float clip_min_y,
- float clip_max_x, float clip_max_y);
+ float clip_max_x, float clip_max_y,
+ float zoom_x, float zoom_y);
/* Draw imbuf on a screen, preferably using GLSL display transform */
-void glaDrawImBuf_glsl_ctx(const struct bContext *C, struct ImBuf *ibuf, float x, float y, int zoomfilter);
+void glaDrawImBuf_glsl_ctx(const struct bContext *C, struct ImBuf *ibuf, float x, float y, int zoomfilter,
+ float zoom_x, float zoom_y);
void glaDrawImBuf_glsl_ctx_clipping(const struct bContext *C,
struct ImBuf *ibuf,
float x, float y,
int zoomfilter,
float clip_min_x, float clip_min_y,
- float clip_max_x, float clip_max_y);
+ float clip_max_x, float clip_max_y,
+ float zoom_x, float zoom_y);
-void glaDrawBorderCorners(const struct rcti *border, float zoomx, float zoomy);
+void immDrawBorderCorners(unsigned int pos, const struct rcti *border, float zoomx, float zoomy);
#endif /* __BIF_GLUTIL_H__ */
-
diff --git a/source/blender/editors/include/ED_anim_api.h b/source/blender/editors/include/ED_anim_api.h
index ab02fd1ccc8..2165402b6d3 100644
--- a/source/blender/editors/include/ED_anim_api.h
+++ b/source/blender/editors/include/ED_anim_api.h
@@ -82,6 +82,7 @@ typedef struct bAnimContext {
struct bDopeSheet *ads; /* dopesheet data for editor (or which is being used) */
struct Scene *scene; /* active scene */
+ struct ViewLayer *view_layer; /* active scene layer */
struct Object *obact; /* active object */
ListBase *markers; /* active set of markers */
@@ -101,7 +102,8 @@ typedef enum eAnimCont_Types {
ANIMCONT_DRIVERS = 6, /* drivers (bDopesheet) */
ANIMCONT_NLA = 7, /* nla (bDopesheet) */
ANIMCONT_CHANNEL = 8, /* animation channel (bAnimListElem) */
- ANIMCONT_MASK = 9 /* mask dopesheet */
+ ANIMCONT_MASK = 9, /* mask dopesheet */
+ ANIMCONT_TIMELINE = 10, /* "timeline" editor (bDopeSheet) */
} eAnimCont_Types;
/* --------------- Channels -------------------- */
@@ -533,22 +535,29 @@ void ANIM_fcurve_delete_from_animdata(bAnimContext *ac, struct AnimData *adt, st
enum eAnimEditDraw_CurrentFrame {
/* plain time indicator with no special indicators */
DRAWCFRA_PLAIN = 0,
- /* draw box indicating current frame number */
- DRAWCFRA_SHOW_NUMBOX = (1 << 0),
/* time indication in seconds or frames */
- DRAWCFRA_UNIT_SECONDS = (1 << 1),
+ DRAWCFRA_UNIT_SECONDS = (1 << 0),
/* draw indicator extra wide (for timeline) */
- DRAWCFRA_WIDE = (1 << 2)
+ DRAWCFRA_WIDE = (1 << 1)
};
/* main call to draw current-frame indicator in an Animation Editor */
void ANIM_draw_cfra(const struct bContext *C, struct View2D *v2d, short flag);
+/* main call to draw "number box" in scrollbar for current frame indicator */
+void ANIM_draw_cfra_number(const struct bContext *C, struct View2D *v2d, short flag);
+
/* ------------- Preview Range Drawing -------------- */
/* main call to draw preview range curtains */
void ANIM_draw_previewrange(const struct bContext *C, struct View2D *v2d, int end_frame_width);
+
+/* -------------- Frame Range Drawing --------------- */
+
+/* main call to draw normal frame range indicators */
+void ANIM_draw_framerange(struct Scene *scene, struct View2D *v2d);
+
/* ************************************************* */
/* F-MODIFIER TOOLS */
diff --git a/source/blender/editors/include/ED_armature.h b/source/blender/editors/include/ED_armature.h
index 567e477ec6c..8b5886d65f1 100644
--- a/source/blender/editors/include/ED_armature.h
+++ b/source/blender/editors/include/ED_armature.h
@@ -39,6 +39,7 @@ struct Base;
struct bContext;
struct Bone;
struct bPoseChannel;
+struct Depsgraph;
struct IDProperty;
struct ListBase;
struct MeshDeformModifierData;
@@ -46,9 +47,11 @@ struct DerivedMesh;
struct Object;
struct ReportList;
struct Scene;
+struct ViewLayer;
struct ViewContext;
struct wmKeyConfig;
struct wmOperator;
+struct Main;
struct UndoType;
typedef struct EditBone {
@@ -86,6 +89,12 @@ typedef struct EditBone {
short segments;
+ /* Used for display */
+ float disp_mat[4][4]; /* in Armature space, rest pos matrix */
+ float disp_tail_mat[4][4]; /* in Armature space, rest pos matrix */
+ /* 32 == MAX_BBONE_SUBDIV */
+ float disp_bbone_mat[32][4][4]; /* in Armature space, rest pos matrix */
+
/* Used to store temporary data */
union {
struct EditBone *ebone;
@@ -133,19 +142,29 @@ void ED_armature_edit_free(struct bArmature *arm);
void ED_armature_edit_deselect_all(struct Object *obedit);
void ED_armature_edit_deselect_all_visible(struct Object *obedit);
+void ED_armature_edit_deselect_all_multi(struct Object **objects, uint objects_len);
+void ED_armature_edit_deselect_all_visible_multi(struct Object **objects, uint objects_len);
+
bool ED_armature_pose_select_pick_with_buffer(
- struct Scene *scene, struct Base *base, const unsigned int *buffer, short hits,
+ struct ViewLayer *view_layer, struct Base *base, const unsigned int *buffer, short hits,
bool extend, bool deselect, bool toggle, bool do_nearest);
bool ED_armature_edit_select_pick(
struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle);
int join_armature_exec(struct bContext *C, struct wmOperator *op);
-struct Bone *ED_armature_bone_find_index(struct Object *ob, int index);
float ED_armature_ebone_roll_to_vector(const EditBone *bone, const float new_up_axis[3], const bool axis_only);
EditBone *ED_armature_ebone_find_name(const struct ListBase *edbo, const char *name);
EditBone *ED_armature_ebone_get_mirrored(const struct ListBase *edbo, EditBone *ebo);
void ED_armature_edit_sync_selection(struct ListBase *edbo);
void ED_armature_edit_validate_active(struct bArmature *arm);
+struct Base *ED_armature_base_and_ebone_from_select_buffer(
+ struct Base **bases, uint bases_len, int hit, struct EditBone **r_ebone);
+struct Object *ED_armature_object_and_ebone_from_select_buffer(
+ struct Object **objects, uint objects_len, int hit, struct EditBone **r_ebone);
+
+struct Base *ED_armature_base_and_bone_from_select_buffer(
+ struct Base **bases, uint bases_len, int hit, struct Bone **r_bone);
+
EditBone *ED_armature_ebone_add_primitive(struct Object *obedit_arm, float length, bool view_aligned);
EditBone *ED_armature_ebone_add(struct bArmature *arm, const char *name);
@@ -162,7 +181,7 @@ void ED_armature_ebone_from_mat3(EditBone *ebone, float mat[3][3]);
void ED_armature_ebone_from_mat4(EditBone *ebone, float mat[4][4]);
void ED_armature_edit_transform_mirror_update(struct Object *obedit);
-void ED_armature_origin_set(struct Scene *scene, struct Object *ob, float cursor[3], int centermode, int around);
+void ED_armature_origin_set(struct Object *ob, float cursor[3], int centermode, int around);
void ED_armature_transform_bones(struct bArmature *arm, float mat[4][4], const bool do_props);
void ED_armature_transform_apply(struct Object *ob, float mat[4][4], const bool do_props);
@@ -172,8 +191,9 @@ void ED_armature_transform(struct bArmature *arm, float mat[4][4], const bool do
#define ARM_GROUPS_ENVELOPE 2
#define ARM_GROUPS_AUTO 3
-void ED_object_vgroup_calc_from_armature(struct ReportList *reports, struct Scene *scene, struct Object *ob,
- struct Object *par, const int mode, const bool mirror);
+void ED_object_vgroup_calc_from_armature(
+ struct ReportList *reports, struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, struct Object *par, const int mode, const bool mirror);
/* if bone is already in list, pass it as param to ignore it */
void ED_armature_ebone_unique_name(struct ListBase *ebones, char *name, EditBone *bone);
@@ -196,41 +216,23 @@ void ED_armature_ebone_listbase_free(struct ListBase *lb);
void ED_armature_ebone_listbase_copy(struct ListBase *lb_dst, struct ListBase *lb_src);
/* poseobject.c */
-bool ED_object_posemode_exit_ex(struct Object *ob);
+bool ED_object_posemode_exit_ex(struct Main *bmain, struct Object *ob);
bool ED_object_posemode_exit(struct bContext *C, struct Object *ob);
-bool ED_object_posemode_enter_ex(struct Object *ob);
+bool ED_object_posemode_enter_ex(struct Main *bmain, struct Object *ob);
bool ED_object_posemode_enter(struct bContext *C, struct Object *ob);
void ED_pose_deselect_all(struct Object *ob, int select_mode, const bool ignore_visibility);
+void ED_pose_deselect_all_multi(struct Object **objects, uint objects_len, int select_mode, const bool ignore_visibility);
void ED_pose_bone_select(struct Object *ob, struct bPoseChannel *pchan, bool select);
-void ED_pose_recalculate_paths(struct Scene *scene, struct Object *ob);
+void ED_pose_recalculate_paths(struct bContext *C, struct Scene *scene, struct Object *ob);
struct Object *ED_pose_object_from_context(struct bContext *C);
-/* sketch */
-
-int ED_operator_sketch_mode_active_stroke(struct bContext *C);
-int ED_operator_sketch_full_mode(struct bContext *C);
-int ED_operator_sketch_mode(const struct bContext *C);
-
-void BIF_convertSketch(struct bContext *C);
-void BIF_deleteSketch(struct bContext *C);
-void BIF_selectAllSketch(struct bContext *C, int mode); /* -1: deselect, 0: select, 1: toggle */
-
-void BIF_makeListTemplates(const struct bContext *C);
-int BIF_currentTemplate(const struct bContext *C);
-void BIF_freeTemplates(struct bContext *C);
-void BIF_setTemplate(struct bContext *C, int index);
-int BIF_nbJointsTemplate(const struct bContext *C);
-const char *BIF_nameBoneTemplate(const struct bContext *C);
-
-void BDR_drawSketch(const struct bContext *vc);
-int BDR_drawSketchNames(struct ViewContext *vc);
-
/* meshlaplacian.c */
-void ED_mesh_deform_bind_callback(struct Scene *scene,
- struct MeshDeformModifierData *mmd,
- struct DerivedMesh *cagedm,
- float *vertexcos, int totvert, float cagemat[4][4]);
-
+void ED_mesh_deform_bind_callback(
+ struct Scene *scene,
+ struct MeshDeformModifierData *mmd,
+ struct DerivedMesh *cagedm,
+ float *vertexcos, int totvert, float cagemat[4][4]);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/editors/include/ED_buttons.h b/source/blender/editors/include/ED_buttons.h
index 64c16605dec..5cc695b6ce8 100644
--- a/source/blender/editors/include/ED_buttons.h
+++ b/source/blender/editors/include/ED_buttons.h
@@ -27,14 +27,4 @@
#ifndef __ED_BUTTONS_H__
#define __ED_BUTTONS_H__
-#include "BLI_utildefines.h"
-
-/* Used to check whether a given texture context is valid in current context. */
-bool ED_texture_context_check_world(const struct bContext *C);
-bool ED_texture_context_check_material(const struct bContext *C);
-bool ED_texture_context_check_lamp(const struct bContext *C);
-bool ED_texture_context_check_particles(const struct bContext *C);
-bool ED_texture_context_check_linestyle(const struct bContext *C);
-bool ED_texture_context_check_others(const struct bContext *C);
-
#endif /* __ED_BUTTONS_H__ */
diff --git a/source/blender/editors/include/ED_gpencil.h b/source/blender/editors/include/ED_gpencil.h
index 74d9ad0886d..57ca1f04c0a 100644
--- a/source/blender/editors/include/ED_gpencil.h
+++ b/source/blender/editors/include/ED_gpencil.h
@@ -35,6 +35,7 @@
struct ID;
struct ListBase;
struct bContext;
+struct Depsgraph;
struct ScrArea;
struct ARegion;
struct View3D;
@@ -48,6 +49,8 @@ struct bGPDpalettecolor;
struct bAnimContext;
struct KeyframeEditData;
struct PointerRNA;
+struct Scene;
+struct ViewLayer;
struct wmWindowManager;
struct wmKeyConfig;
@@ -113,7 +116,7 @@ struct bGPdata *ED_gpencil_data_get_active_direct(struct ID *screen_id, struct S
struct ScrArea *sa, struct Object *ob);
/* 3D View */
-struct bGPdata *ED_gpencil_data_get_active_v3d(struct Scene *scene, struct View3D *v3d);
+struct bGPdata *ED_gpencil_data_get_active_v3d(struct Scene *scene, struct ViewLayer *view_layer);
bool ED_gpencil_has_keyframe_v3d(struct Scene *scene, struct Object *ob, int cfra);
@@ -147,7 +150,13 @@ void ED_gpencil_strokes_copybuf_free(void);
void ED_gpencil_draw_2dimage(const struct bContext *C);
void ED_gpencil_draw_view2d(const struct bContext *C, bool onlyv2d);
-void ED_gpencil_draw_view3d(struct wmWindowManager *wm, struct Scene *scene, struct View3D *v3d, struct ARegion *ar, bool only3d);
+void ED_gpencil_draw_view3d(struct wmWindowManager *wm,
+ struct Scene *scene,
+ struct ViewLayer *view_layer,
+ struct Depsgraph *depsgraph,
+ struct View3D *v3d,
+ struct ARegion *ar,
+ bool only3d);
void ED_gpencil_draw_ex(struct Scene *scene, struct bGPdata *gpd, int winx, int winy,
const int cfra, const char spacetype);
void ED_gp_draw_interpolation(struct tGPDinterpolate *tgpi, const int type);
diff --git a/source/blender/editors/include/ED_image.h b/source/blender/editors/include/ED_image.h
index 9de550a20ce..cb824b3c9b7 100644
--- a/source/blender/editors/include/ED_image.h
+++ b/source/blender/editors/include/ED_image.h
@@ -39,6 +39,7 @@ struct ToolSettings;
struct wmWindowManager;
struct ARegion;
struct Scene;
+struct ViewLayer;
/* image_edit.c, exported for transform */
struct Image *ED_space_image(struct SpaceImage *sima);
@@ -74,7 +75,7 @@ bool ED_space_image_show_uvedit(struct SpaceImage *sima, struct Object *obedit);
bool ED_space_image_paint_curve(const struct bContext *C);
-bool ED_space_image_check_show_maskedit(struct Scene *scene, struct SpaceImage *sima);
+bool ED_space_image_check_show_maskedit(struct SpaceImage *sima, struct ViewLayer *view_layer);
int ED_space_image_maskedit_poll(struct bContext *C);
int ED_space_image_maskedit_mask_poll(struct bContext *C);
diff --git a/source/blender/editors/include/ED_info.h b/source/blender/editors/include/ED_info.h
index 6970abaa633..072b1a135a3 100644
--- a/source/blender/editors/include/ED_info.h
+++ b/source/blender/editors/include/ED_info.h
@@ -28,7 +28,7 @@
#define __ED_INFO_H__
/* info_stats.c */
-void ED_info_stats_clear(struct Scene *scene);
-const char *ED_info_stats_string(struct Scene *scene);
+void ED_info_stats_clear(struct ViewLayer *view_layer);
+const char *ED_info_stats_string(struct Scene *scene, struct ViewLayer *view_layer);
#endif /* __ED_INFO_H__ */
diff --git a/source/blender/editors/include/ED_keyframes_draw.h b/source/blender/editors/include/ED_keyframes_draw.h
index c478a8b17e5..62f1a617fcb 100644
--- a/source/blender/editors/include/ED_keyframes_draw.h
+++ b/source/blender/editors/include/ED_keyframes_draw.h
@@ -108,8 +108,10 @@ typedef enum eKeyframeShapeDrawOpts {
KEYFRAME_SHAPE_BOTH
} eKeyframeShapeDrawOpts;
-/* draw simple diamond-shape keyframe (with OpenGL) */
-void draw_keyframe_shape(float x, float y, float xscale, float hsize, short sel, short key_type, short mode, float alpha);
+/* draw simple diamond-shape keyframe */
+/* caller should set up vertex format, bind GPU_SHADER_KEYFRAME_DIAMOND, immBegin(GWN_PRIM_POINTS, n), then call this n times */
+void draw_keyframe_shape(float x, float y, float size, bool sel, short key_type, short mode, float alpha,
+ unsigned int pos_id, unsigned int size_id, unsigned int color_id, unsigned int outline_color_id);
/* ******************************* Methods ****************************** */
diff --git a/source/blender/editors/include/ED_manipulator_library.h b/source/blender/editors/include/ED_manipulator_library.h
new file mode 100644
index 00000000000..7166292147e
--- /dev/null
+++ b/source/blender/editors/include/ED_manipulator_library.h
@@ -0,0 +1,203 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ED_manipulator_library.h
+ * \ingroup wm
+ *
+ * \name Generic Manipulators.
+ *
+ * This is exposes pre-defined manipulators for re-use.
+ */
+
+
+#ifndef __ED_MANIPULATOR_LIBRARY_H__
+#define __ED_MANIPULATOR_LIBRARY_H__
+
+/* initialize manipulators */
+void ED_manipulatortypes_arrow_2d(void);
+void ED_manipulatortypes_arrow_3d(void);
+void ED_manipulatortypes_button_2d(void);
+void ED_manipulatortypes_cage_2d(void);
+void ED_manipulatortypes_cage_3d(void);
+void ED_manipulatortypes_dial_3d(void);
+void ED_manipulatortypes_grab_3d(void);
+void ED_manipulatortypes_facemap_3d(void);
+void ED_manipulatortypes_primitive_3d(void);
+
+struct wmManipulator;
+struct wmManipulatorGroup;
+
+
+/* -------------------------------------------------------------------- */
+/* Shape Presets
+ *
+ * Intended to be called by custom draw functions.
+ */
+
+/* manipulator_library_presets.c */
+void ED_manipulator_draw_preset_box(
+ const struct wmManipulator *mpr, float mat[4][4], int select_id);
+void ED_manipulator_draw_preset_arrow(
+ const struct wmManipulator *mpr, float mat[4][4], int axis, int select_id);
+void ED_manipulator_draw_preset_circle(
+ const struct wmManipulator *mpr, float mat[4][4], int axis, int select_id);
+void ED_manipulator_draw_preset_facemap(
+ const struct bContext *C, const struct wmManipulator *mpr, struct Scene *scene,
+ struct Object *ob, const int facemap, int select_id);
+
+
+/* -------------------------------------------------------------------- */
+/* 3D Arrow Manipulator */
+
+enum {
+ ED_MANIPULATOR_ARROW_STYLE_NORMAL = 0,
+ ED_MANIPULATOR_ARROW_STYLE_CROSS = 1,
+ ED_MANIPULATOR_ARROW_STYLE_BOX = 2,
+ ED_MANIPULATOR_ARROW_STYLE_CONE = 3,
+};
+
+enum {
+ /* inverted offset during interaction - if set it also sets constrained below */
+ ED_MANIPULATOR_ARROW_STYLE_INVERTED = (1 << 3),
+ /* clamp arrow interaction to property width */
+ ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED = (1 << 4),
+};
+
+void ED_manipulator_arrow3d_set_ui_range(struct wmManipulator *mpr, const float min, const float max);
+void ED_manipulator_arrow3d_set_range_fac(struct wmManipulator *mpr, const float range_fac);
+
+/* -------------------------------------------------------------------- */
+/* 2D Arrow Manipulator */
+
+/* none */
+
+/* -------------------------------------------------------------------- */
+/* Cage Manipulator */
+
+enum {
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE = (1 << 0), /* Translates */
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE = (1 << 1), /* Rotates */
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE = (1 << 2), /* Scales */
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM = (1 << 3), /* Scales uniformly */
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_SIGNED = (1 << 4), /* Negative scale allowed */
+};
+
+/* draw_style */
+enum {
+ ED_MANIPULATOR_CAGE2D_STYLE_BOX = 0,
+ ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE = 1,
+};
+
+/* draw_options */
+enum {
+ /** Draw a central handle (instead of having the entire area selectable)
+ * Needed for large rectangles that we don't want to swallow all events. */
+ ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE = (1 << 0),
+};
+
+/** #wmManipulator.highlight_part */
+enum {
+ ED_MANIPULATOR_CAGE2D_PART_TRANSLATE = 0,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X = 1,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X = 2,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y = 3,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y = 4,
+ /* Corners */
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y = 5,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y = 6,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y = 7,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y = 8,
+
+ ED_MANIPULATOR_CAGE2D_PART_ROTATE = 9,
+};
+
+/** #wmManipulator.highlight_part */
+enum {
+ /* ordered min/mid/max so we can loop over values (MIN/MID/MAX) on each axis. */
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z = 0,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MID_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MID_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MID_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MAX_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MAX_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MAX_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MIN_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MIN_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MIN_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MID_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MID_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MID_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MAX_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MAX_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MAX_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MIN_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MIN_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MIN_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MID_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MID_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MID_Y_MAX_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MIN_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MID_Z,
+ ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z,
+
+ ED_MANIPULATOR_CAGE3D_PART_TRANSLATE,
+
+ ED_MANIPULATOR_CAGE3D_PART_ROTATE,
+};
+
+/* -------------------------------------------------------------------- */
+/* Dial Manipulator */
+
+/* draw_options */
+enum {
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_NOP = 0,
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_CLIP = (1 << 0),
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_FILL = (1 << 1),
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_MIRROR = (1 << 2),
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_START_Y = (1 << 3),
+};
+
+/* -------------------------------------------------------------------- */
+/* Grab Manipulator */
+
+/* draw_options */
+enum {
+ ED_MANIPULATOR_GRAB_DRAW_FLAG_NOP = 0,
+ /* only for solid shapes */
+ ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL = (1 << 0),
+ ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW = (1 << 1),
+};
+
+enum {
+ ED_MANIPULATOR_GRAB_STYLE_RING_2D = 0,
+ ED_MANIPULATOR_GRAB_STYLE_CROSS_2D = 1,
+};
+
+
+/* -------------------------------------------------------------------- */
+/* Primitive Manipulator */
+
+enum {
+ ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE = 0,
+};
+
+#endif /* __ED_MANIPULATOR_LIBRARY_H__ */
diff --git a/source/blender/editors/include/ED_mesh.h b/source/blender/editors/include/ED_mesh.h
index 349a1944a23..787cf7f0524 100644
--- a/source/blender/editors/include/ED_mesh.h
+++ b/source/blender/editors/include/ED_mesh.h
@@ -39,6 +39,7 @@ struct ID;
struct View3D;
struct ARegion;
struct bContext;
+struct Depsgraph;
struct wmOperator;
struct wmKeyConfig;
struct ReportList;
@@ -47,7 +48,6 @@ struct bDeformGroup;
struct MDeformVert;
struct Scene;
struct Mesh;
-struct MTexPoly;
struct UvVertMap;
struct UvMapVert;
struct BMEditMesh;
@@ -114,8 +114,7 @@ struct UvElement *BM_uv_element_get(struct UvElementMap *map, struct BMFace *
bool EDBM_uv_check(struct BMEditMesh *em);
struct BMFace *EDBM_uv_active_face_get(
- struct BMEditMesh *em, const bool sloppy, const bool selected,
- struct MTexPoly **r_tf);
+ struct BMEditMesh *em, const bool sloppy, const bool selected);
void BM_uv_vert_map_free(struct UvVertMap *vmap);
struct UvMapVert *BM_uv_vert_map_at_index(struct UvVertMap *vmap, unsigned int v);
@@ -127,6 +126,7 @@ void EDBM_flag_enable_all(struct BMEditMesh *em, const char hflag);
void EDBM_flag_disable_all(struct BMEditMesh *em, const char hflag);
bool BMBVH_EdgeVisible(struct BMBVHTree *tree, struct BMEdge *e,
+ struct Depsgraph *depsgraph,
struct ARegion *ar, struct View3D *v3d, struct Object *obedit);
/* editmesh_undo.c */
@@ -221,13 +221,13 @@ typedef struct MirrTopoStore_t {
intptr_t *index_lookup;
int prev_vert_tot;
int prev_edge_tot;
- int prev_ob_mode;
+ bool prev_is_editmode;
} MirrTopoStore_t;
bool ED_mesh_mirrtopo_recalc_check(
- struct Mesh *me, struct DerivedMesh *dm, const int ob_mode, MirrTopoStore_t *mesh_topo_store);
+ struct Mesh *me, struct DerivedMesh *dm, MirrTopoStore_t *mesh_topo_store);
void ED_mesh_mirrtopo_init(
- struct Mesh *me, struct DerivedMesh *dm, const int ob_mode, MirrTopoStore_t *mesh_topo_store,
+ struct Mesh *me, struct DerivedMesh *dm, MirrTopoStore_t *mesh_topo_store,
const bool skip_em_vert_array_init);
void ED_mesh_mirrtopo_free(MirrTopoStore_t *mesh_topo_store);
@@ -266,7 +266,6 @@ void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGrou
float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum);
void ED_vgroup_vert_active_mirror(struct Object *ob, int def_nr);
-
/* mesh_data.c */
// void ED_mesh_geometry_add(struct Mesh *mesh, struct ReportList *reports, int verts, int edges, int faces);
void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int count);
@@ -341,6 +340,9 @@ struct MDeformVert *ED_mesh_active_dvert_get_em(struct Object *ob, struct BMVert
struct MDeformVert *ED_mesh_active_dvert_get_ob(struct Object *ob, int *r_index);
struct MDeformVert *ED_mesh_active_dvert_get_only(struct Object *ob);
+void EDBM_mesh_stats_multi(struct Object **objects, const uint objects_len, int totelem[3], int totelem_sel[3]);
+void EDBM_mesh_elem_index_ensure_multi(struct Object **objects, const uint objects_len, const char htype);
+
#define ED_MESH_PICK_DEFAULT_VERT_SIZE 50
#define ED_MESH_PICK_DEFAULT_FACE_SIZE 3
diff --git a/source/blender/editors/include/ED_node.h b/source/blender/editors/include/ED_node.h
index e3c382382a9..20363c69fa0 100644
--- a/source/blender/editors/include/ED_node.h
+++ b/source/blender/editors/include/ED_node.h
@@ -75,7 +75,7 @@ void ED_init_custom_node_socket_type(struct bNodeSocketType *stype);
void ED_init_standard_node_socket_type(struct bNodeSocketType *stype);
void ED_init_node_socket_type_virtual(struct bNodeSocketType *stype);
void ED_node_sample_set(const float col[4]);
-void ED_node_draw_snap(struct View2D *v2d, const float cent[2], float size, NodeBorder border);
+void ED_node_draw_snap(struct View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos);
/* node_draw.c */
void ED_node_tree_update(const struct bContext *C);
diff --git a/source/blender/editors/include/ED_object.h b/source/blender/editors/include/ED_object.h
index 2087394b6f6..0775c2b953b 100644
--- a/source/blender/editors/include/ED_object.h
+++ b/source/blender/editors/include/ED_object.h
@@ -35,6 +35,7 @@
extern "C" {
#endif
+struct bFaceMap;
struct Base;
struct EnumPropertyItem;
struct ID;
@@ -43,6 +44,7 @@ struct ModifierData;
struct Object;
struct ReportList;
struct Scene;
+struct ViewLayer;
struct bConstraint;
struct bContext;
struct bPoseChannel;
@@ -50,9 +52,12 @@ struct wmKeyConfig;
struct wmKeyMap;
struct wmOperator;
struct wmOperatorType;
+struct wmWindow;
+struct wmWindowManager;
struct PointerRNA;
struct PropertyRNA;
struct EnumPropertyItem;
+struct Depsgraph;
#include "DNA_object_enums.h"
@@ -82,16 +87,21 @@ typedef enum eParentType {
PAR_VERTEX_TRI,
} eParentType;
+typedef enum eObjectSelect_Mode {
+ BA_DESELECT = 0,
+ BA_SELECT = 1,
+ BA_INVERT = 2,
+} eObjectSelect_Mode;
+
#ifdef __RNA_TYPES_H__
extern struct EnumPropertyItem prop_clear_parent_types[];
extern struct EnumPropertyItem prop_make_parent_types[];
#endif
-bool ED_object_parent_set(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct Object *ob,
+bool ED_object_parent_set(struct ReportList *reports, const struct bContext *C, struct Scene *scene, struct Object *ob,
struct Object *par, int partype, const bool xmirror, const bool keep_transform,
const int vert_par[3]);
void ED_object_parent_clear(struct Object *ob, const int type);
-struct Base *ED_object_scene_link(struct Scene *scene, struct Object *ob);
void ED_keymap_proportional_cycle(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap);
void ED_keymap_proportional_obmode(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap);
@@ -99,15 +109,12 @@ void ED_keymap_proportional_maskmode(struct wmKeyConfig *keyconf, struct wmKeyMa
void ED_keymap_proportional_editmode(struct wmKeyConfig *keyconf, struct wmKeyMap *keymap,
const bool do_connected);
-/* send your own notifier for select! */
-void ED_base_object_select(struct Base *base, short mode);
-/* includes notifier */
-void ED_base_object_activate(struct bContext *C, struct Base *base);
-
-void ED_base_object_free_and_unlink(struct Main *bmain, struct Scene *scene, struct Base *base);
+void ED_object_base_select(struct Base *base, eObjectSelect_Mode mode);
+void ED_object_base_activate(struct bContext *C, struct Base *base);
+void ED_object_base_free_and_unlink(struct Main *bmain, struct Scene *scene, struct Object *ob);
/* single object duplicate, if (dupflag == 0), fully linked, else it uses the flags given */
-struct Base *ED_object_add_duplicate(struct Main *bmain, struct Scene *scene, struct Base *base, int dupflag);
+struct Base *ED_object_add_duplicate(struct Main *bmain, struct Scene *scene, struct ViewLayer *view_layer, struct Base *base, int dupflag);
void ED_object_parent(struct Object *ob, struct Object *parent, const int type, const char *substr);
@@ -117,9 +124,13 @@ enum {
EM_WAITCURSOR = (1 << 1),
EM_DO_UNDO = (1 << 2),
EM_IGNORE_LAYER = (1 << 3),
+ EM_NO_CONTEXT = (1 << 4),
};
-void ED_object_editmode_exit_ex(struct bContext *C, struct Scene *scene, struct Object *obedit, int flag);
+void ED_object_editmode_exit_ex(
+ struct bContext *C, struct Scene *scene, struct Object *obedit, int flag);
void ED_object_editmode_exit(struct bContext *C, int flag);
+
+void ED_object_editmode_enter_ex(struct Scene *scene, struct Object *ob, int flag);
void ED_object_editmode_enter(struct bContext *C, int flag);
bool ED_object_editmode_load(struct Object *obedit);
@@ -127,11 +138,11 @@ bool ED_object_editmode_calc_active_center(struct Object *obedit, const bool sel
void ED_object_vpaintmode_enter_ex(
- struct wmWindowManager *wm,
+ struct Depsgraph *depsgraph, struct wmWindowManager *wm,
struct Scene *scene, struct Object *ob);
void ED_object_vpaintmode_enter(struct bContext *C);
void ED_object_wpaintmode_enter_ex(
- struct wmWindowManager *wm,
+ struct Depsgraph *depsgraph, struct wmWindowManager *wm,
struct Scene *scene, struct Object *ob);
void ED_object_wpaintmode_enter(struct bContext *C);
@@ -141,10 +152,12 @@ void ED_object_wpaintmode_exit_ex(struct Object *ob);
void ED_object_wpaintmode_exit(struct bContext *C);
void ED_object_sculptmode_enter_ex(
+ struct Depsgraph *depsgraph,
struct Scene *scene, struct Object *ob,
struct ReportList *reports);
void ED_object_sculptmode_enter(struct bContext *C, struct ReportList *reports);
void ED_object_sculptmode_exit_ex(
+ struct Depsgraph *depsgraph,
struct Scene *scene, struct Object *ob);
void ED_object_sculptmode_exit(struct bContext *C);
@@ -200,24 +213,36 @@ bool ED_object_mode_compat_set(struct bContext *C, struct Object *ob, eObjectMod
void ED_object_mode_toggle(struct bContext *C, eObjectMode mode);
void ED_object_mode_set(struct bContext *C, eObjectMode mode);
+bool ED_object_mode_generic_enter(
+ struct bContext *C,
+ eObjectMode object_mode);
+void ED_object_mode_generic_exit(
+ struct Depsgraph *depsgraph,
+ struct Scene *scene, struct Object *ob);
+bool ED_object_mode_generic_has_data(
+ struct Depsgraph *depsgraph,
+ struct Object *ob);
+
+bool ED_object_mode_generic_exists(
+ struct wmWindowManager *wm, struct Object *ob,
+ eObjectMode object_mode);
+
/* object_modifier.c */
enum {
MODIFIER_APPLY_DATA = 1,
MODIFIER_APPLY_SHAPE
};
-struct ModifierData *ED_object_modifier_add(
- struct ReportList *reports, struct Main *bmain, struct Scene *scene,
- struct Object *ob, const char *name, int type);
+struct ModifierData *ED_object_modifier_add(struct ReportList *reports, struct Main *bmain, struct Scene *scene,
+ struct Object *ob, const char *name, int type);
bool ED_object_modifier_remove(struct ReportList *reports, struct Main *bmain,
struct Object *ob, struct ModifierData *md);
void ED_object_modifier_clear(struct Main *bmain, struct Object *ob);
int ED_object_modifier_move_down(struct ReportList *reports, struct Object *ob, struct ModifierData *md);
int ED_object_modifier_move_up(struct ReportList *reports, struct Object *ob, struct ModifierData *md);
-int ED_object_modifier_convert(
- struct ReportList *reports, struct Main *bmain, struct Scene *scene,
- struct Object *ob, struct ModifierData *md);
-int ED_object_modifier_apply(struct ReportList *reports, struct Scene *scene,
+int ED_object_modifier_convert(struct ReportList *reports, struct Main *bmain, struct Scene *scene,
+ struct ViewLayer *view_layer, struct Object *ob, struct ModifierData *md);
+int ED_object_modifier_apply(struct ReportList *reports, struct Depsgraph *depsgraph, struct Scene *scene,
struct Object *ob, struct ModifierData *md, int mode);
int ED_object_modifier_copy(struct ReportList *reports, struct Object *ob, struct ModifierData *md);
@@ -238,8 +263,11 @@ const struct EnumPropertyItem *ED_object_vgroup_selection_itemf_helper(
bool *r_free,
const unsigned int selection_mask);
-void ED_object_check_force_modifiers(
- struct Main *bmain, struct Scene *scene, struct Object *object);
+void ED_object_check_force_modifiers(struct Main *bmain, struct Scene *scene, struct Object *object);
+
+/* object_facemap_ops.c */
+void ED_object_facemap_face_add(struct Object *ob, struct bFaceMap *fmap, int facenum);
+void ED_object_facemap_face_remove(struct Object *ob, struct bFaceMap *fmap, int facenum);
#ifdef __cplusplus
}
diff --git a/source/blender/editors/include/ED_particle.h b/source/blender/editors/include/ED_particle.h
index 4f6aa1cc702..f84015c53ee 100644
--- a/source/blender/editors/include/ED_particle.h
+++ b/source/blender/editors/include/ED_particle.h
@@ -38,6 +38,7 @@ struct ParticleEditSettings;
struct rcti;
struct PTCacheEdit;
struct Scene;
+struct ViewLayer;
struct UndoType;
/* particle edit mode */
@@ -46,14 +47,16 @@ int PE_start_edit(struct PTCacheEdit *edit);
/* access */
struct PTCacheEdit *PE_get_current(struct Scene *scene, struct Object *ob);
-struct PTCacheEdit *PE_create_current(struct Scene *scene, struct Object *ob);
-void PE_current_changed(struct Scene *scene, struct Object *ob);
-int PE_minmax(struct Scene *scene, float min[3], float max[3]);
+struct PTCacheEdit *PE_create_current(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
+void PE_current_changed(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob);
+int PE_minmax(struct Scene *scene, struct ViewLayer *view_layer, float min[3], float max[3]);
struct ParticleEditSettings *PE_settings(struct Scene *scene);
/* update calls */
void PE_hide_keys_time(struct Scene *scene, struct PTCacheEdit *edit, float cfra);
-void PE_update_object(struct Scene *scene, struct Object *ob, int useflag);
+void PE_update_object(
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, int useflag);
/* selection tools */
int PE_mouse_particles(struct bContext *C, const int mval[2], bool extend, bool deselect, bool toggle);
diff --git a/source/blender/editors/include/ED_render.h b/source/blender/editors/include/ED_render.h
index 707d7c6c693..2615847e90a 100644
--- a/source/blender/editors/include/ED_render.h
+++ b/source/blender/editors/include/ED_render.h
@@ -31,6 +31,7 @@
#include "DNA_vec_types.h"
struct bContext;
+struct DEGEditorUpdateContext;
struct ID;
struct Main;
struct MTex;
@@ -43,15 +44,16 @@ struct wmWindowManager;
void ED_operatortypes_render(void);
-/* render_shading.c */
+/* render_update.c */
-void ED_render_id_flush_update(struct Main *bmain, struct ID *id);
void ED_render_engine_changed(struct Main *bmain);
void ED_render_engine_area_exit(struct Main *bmain, struct ScrArea *sa);
-void ED_render_scene_update(struct Main *bmain, struct Scene *scene, int updated);
-void ED_render_scene_update_pre(struct Main *bmain, struct Scene *scene, bool time);
-void ED_viewport_render_kill_jobs(struct wmWindowManager *wm, struct Main *bmain, bool free_database);
+/* Callbacks handling data update events coming from depsgraph. */
+
+void ED_render_id_flush_update(const struct DEGEditorUpdateContext *update_ctx, struct ID *id);
+void ED_render_scene_update(const struct DEGEditorUpdateContext *update_ctx, int updated);
+
struct Scene *ED_render_job_get_scene(const struct bContext *C);
struct Scene *ED_render_job_get_current_scene(const struct bContext *C);
diff --git a/source/blender/editors/include/ED_scene.h b/source/blender/editors/include/ED_scene.h
new file mode 100644
index 00000000000..9b48187e541
--- /dev/null
+++ b/source/blender/editors/include/ED_scene.h
@@ -0,0 +1,44 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file ED_scene.h
+ * \ingroup editors
+ */
+
+#ifndef __ED_SCENE_H__
+#define __ED_SCENE_H__
+
+#include "BLI_compiler_attrs.h"
+
+enum eSceneCopyMethod;
+
+struct Scene *ED_scene_add(struct Main *bmain, struct bContext *C, struct wmWindow *win, enum eSceneCopyMethod method) ATTR_NONNULL();
+bool ED_scene_delete(struct bContext *C, struct Main *bmain, struct wmWindow *win, struct Scene *scene) ATTR_NONNULL();
+void ED_scene_change_update(
+ struct Main *bmain, struct bContext *C,
+ struct wmWindow *win, const struct bScreen *screen,
+ struct Scene *scene_old, struct Scene *scene_new) ATTR_NONNULL();
+bool ED_scene_view_layer_delete(
+ struct Main *bmain, struct Scene *scene, struct ViewLayer *layer,
+ struct ReportList *reports) ATTR_NONNULL(1, 2, 3);
+
+void ED_operatortypes_scene(void);
+
+#endif /* __ED_SCENE_H__ */
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index af4abc60a23..5bfa73f6271 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -35,26 +35,40 @@
#include "DNA_space_types.h"
#include "DNA_view2d_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_workspace_types.h"
+#include "DNA_object_enums.h"
+
+#include "BLI_compiler_attrs.h"
+
+struct Depsgraph;
struct wmWindowManager;
struct wmWindow;
struct wmNotifier;
struct wmEvent;
struct wmKeyConfig;
+struct WorkSpace;
+struct WorkSpaceInstanceHook;
struct bContext;
struct Scene;
+struct ViewLayer;
struct bScreen;
struct ARegion;
struct uiBlock;
struct rcti;
struct Main;
+struct wmMsgBus;
+struct wmMsgSubscribeKey;
+struct wmMsgSubscribeValue;
/* regions */
-void ED_region_do_listen(struct bScreen *sc, struct ScrArea *sa, struct ARegion *ar, struct wmNotifier *note);
+void ED_region_do_listen(
+ struct bScreen *sc, struct ScrArea *sa, struct ARegion *ar,
+ struct wmNotifier *note, const Scene *scene);
+void ED_region_do_layout(struct bContext *C, struct ARegion *ar);
void ED_region_do_draw(struct bContext *C, struct ARegion *ar);
void ED_region_exit(struct bContext *C, struct ARegion *ar);
void ED_region_pixelspace(struct ARegion *ar);
-void ED_region_set(const struct bContext *C, struct ARegion *ar);
void ED_region_update_rect(struct bContext *C, struct ARegion *ar);
void ED_region_init(struct bContext *C, struct ARegion *ar);
void ED_region_tag_redraw(struct ARegion *ar);
@@ -68,14 +82,33 @@ void ED_region_panels(
const bool vertical);
void ED_region_header_init(struct ARegion *ar);
void ED_region_header(const struct bContext *C, struct ARegion *ar);
+void ED_region_header_layout(const struct bContext *C, struct ARegion *ar);
+void ED_region_header_draw(const struct bContext *C, struct ARegion *ar);
void ED_region_cursor_set(struct wmWindow *win, struct ScrArea *sa, struct ARegion *ar);
void ED_region_toggle_hidden(struct bContext *C, struct ARegion *ar);
+void ED_region_visibility_change_update(struct bContext *C, struct ARegion *ar);
void ED_region_info_draw(struct ARegion *ar, const char *text, float fill_color[4], const bool full_redraw);
+void ED_region_info_draw_multiline(ARegion *ar, const char *text_array[], float fill_color[4], const bool full_redraw);
void ED_region_image_metadata_draw(int x, int y, struct ImBuf *ibuf, const rctf *frame, float zoomx, float zoomy);
void ED_region_grid_draw(struct ARegion *ar, float zoomx, float zoomy);
-float ED_region_blend_factor(struct ARegion *ar);
+float ED_region_blend_alpha(struct ARegion *ar);
void ED_region_visible_rect(struct ARegion *ar, struct rcti *rect);
+int ED_region_snap_size_test(const struct ARegion *ar);
+bool ED_region_snap_size_apply(struct ARegion *ar, int snap_flag);
+
+/* message_bus callbacks */
+void ED_region_do_msg_notify_tag_redraw(
+ struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val);
+void ED_area_do_msg_notify_tag_refresh(
+ struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val);
+
+/* message bus */
+void ED_region_message_subscribe(
+ struct bContext *C,
+ struct WorkSpace *workspace, struct Scene *scene,
+ struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus);
/* spaces */
void ED_spacetypes_keymap(struct wmKeyConfig *keyconf);
@@ -85,7 +118,13 @@ int ED_area_header_switchbutton(const struct bContext *C, struct uiBlock *bl
void ED_area_initialize(struct wmWindowManager *wm, struct wmWindow *win, struct ScrArea *sa);
void ED_area_exit(struct bContext *C, struct ScrArea *sa);
int ED_screen_area_active(const struct bContext *C);
-void ED_area_do_listen(struct bScreen *sc, ScrArea *sa, struct wmNotifier *note);
+void ED_screen_global_topbar_area_create(
+ struct wmWindow *win,
+ const struct bScreen *screen);
+void ED_screen_global_areas_create(
+ struct wmWindow *win);
+void ED_area_do_listen(struct bScreen *sc, ScrArea *sa, struct wmNotifier *note, Scene *scene,
+ struct WorkSpace *workspace);
void ED_area_tag_redraw(ScrArea *sa);
void ED_area_tag_redraw_regiontype(ScrArea *sa, int type);
void ED_area_tag_refresh(ScrArea *sa);
@@ -96,6 +135,29 @@ void ED_area_newspace(struct bContext *C, ScrArea *sa, int type, const bool s
void ED_area_prevspace(struct bContext *C, ScrArea *sa);
void ED_area_swapspace(struct bContext *C, ScrArea *sa1, ScrArea *sa2);
int ED_area_headersize(void);
+int ED_area_header_alignment(const ScrArea *area);
+int ED_area_global_size_y(const ScrArea *area);
+bool ED_area_is_global(const ScrArea *area);
+int ED_region_global_size_y(void);
+void ED_area_update_region_sizes(struct wmWindowManager *wm, struct wmWindow *win, struct ScrArea *area);
+
+ScrArea *ED_screen_areas_iter_first(const struct wmWindow *win, const bScreen *screen);
+ScrArea *ED_screen_areas_iter_next(const bScreen *screen, const ScrArea *area);
+/**
+ * Iterate over all areas visible in the screen (screen as in everything
+ * visible in the window, not just bScreen).
+ * \note Skips global areas with flag GLOBAL_AREA_IS_HIDDEN.
+ */
+#define ED_screen_areas_iter(win, screen, area_name) \
+ for (ScrArea *area_name = ED_screen_areas_iter_first(win, screen); \
+ area_name != NULL; \
+ area_name = ED_screen_areas_iter_next(screen, area_name))
+#define ED_screen_verts_iter(win, screen, vert_name) \
+ for (ScrVert *vert_name = (win)->global_areas.vertbase.first ? \
+ (win)->global_areas.vertbase.first : \
+ screen->vertbase.first; \
+ vert_name != NULL; \
+ vert_name = (vert_name == (win)->global_areas.vertbase.last) ? (screen)->vertbase.first : vert_name->next)
/* screens */
void ED_screens_initialize(struct wmWindowManager *wm);
@@ -103,14 +165,14 @@ void ED_screen_draw_edges(struct wmWindow *win);
void ED_screen_draw_join_shape(struct ScrArea *sa1, struct ScrArea *sa2);
void ED_screen_draw_split_preview(struct ScrArea *sa, const int dir, const float fac);
void ED_screen_refresh(struct wmWindowManager *wm, struct wmWindow *win);
+void ED_screen_ensure_updated(struct wmWindowManager *wm, struct wmWindow *win, struct bScreen *screen);
void ED_screen_do_listen(struct bContext *C, struct wmNotifier *note);
-bScreen *ED_screen_duplicate(struct wmWindow *win, struct bScreen *sc);
-bScreen *ED_screen_add(struct wmWindow *win, struct Scene *scene, const char *name);
-bool ED_screen_set(struct bContext *C, struct bScreen *sc);
-bool ED_screen_delete(struct bContext *C, struct bScreen *sc);
-void ED_screen_set_scene(struct bContext *C, struct bScreen *screen, struct Scene *scene);
-bool ED_screen_delete_scene(struct bContext *C, struct Scene *scene);
-void ED_screen_set_subwinactive(struct bContext *C, const struct wmEvent *event);
+bool ED_screen_change(struct bContext *C, struct bScreen *sc);
+void ED_screen_update_after_scene_change(
+ const struct bScreen *screen,
+ struct Scene *scene_new,
+ struct ViewLayer *view_layer);
+void ED_screen_set_active_region(struct bContext *C, const int xy[2]);
void ED_screen_exit(struct bContext *C, struct wmWindow *window, struct bScreen *screen);
void ED_screen_animation_timer(struct bContext *C, int redraws, int refresh, int sync, int enable);
void ED_screen_animation_timer_update(struct bScreen *screen, int redraws, int refresh);
@@ -120,10 +182,55 @@ void ED_screen_full_prevspace(struct bContext *C, ScrArea *sa);
void ED_screen_full_restore(struct bContext *C, ScrArea *sa);
struct ScrArea *ED_screen_state_toggle(struct bContext *C, struct wmWindow *win, struct ScrArea *sa, const short state);
void ED_screens_header_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
-bool ED_screen_stereo3d_required(struct bScreen *screen);
+bool ED_screen_stereo3d_required(const struct bScreen *screen, const struct Scene *scene);
+Scene *ED_screen_scene_find(const struct bScreen *screen, const struct wmWindowManager *wm);
+Scene *ED_screen_scene_find_with_window(const struct bScreen *screen, const struct wmWindowManager *wm, struct wmWindow **r_window);
+struct wmWindow *ED_screen_window_find(const struct bScreen *screen, const struct wmWindowManager *wm);
+void ED_screen_preview_render(const struct bScreen *screen, int size_x, int size_y, unsigned int *r_rect) ATTR_NONNULL();
+
+/* workspaces */
+struct WorkSpace *ED_workspace_add(
+ struct Main *bmain,
+ const char *name,
+ Scene *scene,
+ ViewLayer *act_render_layer) ATTR_NONNULL();
+bool ED_workspace_change(
+ struct WorkSpace *workspace_new,
+ struct bContext *C,
+ struct wmWindowManager *wm, struct wmWindow *win) ATTR_NONNULL();
+struct WorkSpace *ED_workspace_duplicate(
+ struct WorkSpace *workspace_old,
+ struct Main *bmain, struct wmWindow *win);
+bool ED_workspace_delete(
+ struct WorkSpace *workspace,
+ struct Main *bmain, struct bContext *C,
+ struct wmWindowManager *wm) ATTR_NONNULL();
+void ED_workspace_scene_data_sync(
+ struct WorkSpaceInstanceHook *hook, Scene *scene) ATTR_NONNULL();
+void ED_workspace_view_layer_unset(
+ const struct Main *bmain, struct Scene *scene,
+ const ViewLayer *layer_unset, ViewLayer *layer_new) ATTR_NONNULL(1, 2);
+struct WorkSpaceLayout *ED_workspace_layout_add(
+ struct WorkSpace *workspace,
+ struct wmWindow *win,
+ const char *name) ATTR_NONNULL();
+struct WorkSpaceLayout *ED_workspace_layout_duplicate(
+ struct WorkSpace *workspace, const struct WorkSpaceLayout *layout_old,
+ struct wmWindow *win) ATTR_NONNULL();
+bool ED_workspace_layout_delete(
+ struct WorkSpace *workspace, struct WorkSpaceLayout *layout_old,
+ struct bContext *C) ATTR_NONNULL();
+bool ED_workspace_layout_cycle(
+ struct WorkSpace *workspace, const short direction,
+ struct bContext *C) ATTR_NONNULL();
+
+void ED_workspace_object_mode_sync_from_object(
+ struct wmWindowManager *wm, WorkSpace *workspace, struct Object *obact);
+void ED_workspace_object_mode_sync_from_scene(
+ struct wmWindowManager *wm, WorkSpace *workspace, struct Scene *scene);
/* anim */
-void ED_update_for_newframe(struct Main *bmain, struct Scene *scene, int mute);
+void ED_update_for_newframe(struct Main *bmain, struct Depsgraph *depsgraph);
void ED_refresh_viewport_fps(struct bContext *C);
int ED_screen_animation_play(struct bContext *C, int sync, int mode);
@@ -133,6 +240,8 @@ bScreen *ED_screen_animation_no_scrub(const struct wmWindowManager *wm);
/* screen keymaps */
void ED_operatortypes_screen(void);
void ED_keymap_screen(struct wmKeyConfig *keyconf);
+/* workspace keymaps */
+void ED_operatortypes_workspace(void);
/* operators; context poll callbacks */
int ED_operator_screenactive(struct bContext *C);
@@ -146,7 +255,6 @@ int ED_operator_objectmode(struct bContext *C);
int ED_operator_view3d_active(struct bContext *C);
int ED_operator_region_view3d_active(struct bContext *C);
int ED_operator_animview_active(struct bContext *C);
-int ED_operator_timeline_active(struct bContext *C);
int ED_operator_outliner_active(struct bContext *C);
int ED_operator_outliner_active_no_editobject(struct bContext *C);
int ED_operator_file_active(struct bContext *C);
@@ -159,7 +267,6 @@ int ED_operator_sequencer_active(struct bContext *C);
int ED_operator_sequencer_active_editable(struct bContext *C);
int ED_operator_image_active(struct bContext *C);
int ED_operator_nla_active(struct bContext *C);
-int ED_operator_logic_active(struct bContext *C);
int ED_operator_info_active(struct bContext *C);
int ED_operator_console_active(struct bContext *C);
@@ -188,6 +295,7 @@ int ED_operator_posemode_context(struct bContext *C);
int ED_operator_posemode(struct bContext *C);
int ED_operator_posemode_local(struct bContext *C);
int ED_operator_mask(struct bContext *C);
+int ED_operator_camera(struct bContext *C);
/* Cache display helpers */
diff --git a/source/blender/editors/include/ED_screen_types.h b/source/blender/editors/include/ED_screen_types.h
index 1c41b14a874..0fed5eb03fd 100644
--- a/source/blender/editors/include/ED_screen_types.h
+++ b/source/blender/editors/include/ED_screen_types.h
@@ -83,13 +83,22 @@ typedef enum {
AE_BOTTOM_TO_TOPLEFT /* Region located at the top, _bottom_ edge is action zone. Region minimized to the top left */
} AZEdge;
+typedef enum {
+ AZ_SCROLL_VERT,
+ AZ_SCROLL_HOR,
+} AZScrollDirection;
+
/* for editing areas/regions */
typedef struct AZone {
struct AZone *next, *prev;
ARegion *ar;
int type;
- /* region-azone, which of the edges (only for AZONE_REGION) */
- AZEdge edge;
+
+ union {
+ /* region-azone, which of the edges (only for AZONE_REGION) */
+ AZEdge edge;
+ AZScrollDirection direction;
+ };
/* for draw */
short x1, y1, x2, y2;
/* for clip */
@@ -99,8 +108,15 @@ typedef struct AZone {
} AZone;
/* actionzone type */
-#define AZONE_AREA 1 /* corner widgets for splitting areas */
-#define AZONE_REGION 2 /* when a region is collapsed, draw a handle to expose */
-#define AZONE_FULLSCREEN 3 /* when in editor fullscreen draw a corner to go to normal mode */
+enum {
+ /* corner widgets for splitting areas */
+ AZONE_AREA = 1,
+ /* when a region is collapsed, draw a handle to expose */
+ AZONE_REGION,
+ /* when in editor fullscreen draw a corner to go to normal mode */
+ AZONE_FULLSCREEN,
+ /* Hotspot azone around scrollbars to show/hide them. */
+ AZONE_REGION_SCROLL,
+};
#endif /* __ED_SCREEN_TYPES_H__ */
diff --git a/source/blender/editors/include/ED_sculpt.h b/source/blender/editors/include/ED_sculpt.h
index 7c17e7b68c3..574523696f5 100644
--- a/source/blender/editors/include/ED_sculpt.h
+++ b/source/blender/editors/include/ED_sculpt.h
@@ -42,8 +42,7 @@ struct ListBase;
/* sculpt.c */
void ED_operatortypes_sculpt(void);
-void ED_sculpt_redraw_planes_get(float planes[4][4], struct ARegion *ar,
- struct RegionView3D *rv3d, struct Object *ob);
+void ED_sculpt_redraw_planes_get(float planes[4][4], struct ARegion *ar, struct Object *ob);
int ED_sculpt_mask_box_select(struct bContext *C, struct ViewContext *vc, const struct rcti *rect, bool select, bool extend);
/* sculpt_undo.c */
diff --git a/source/blender/editors/include/ED_space_api.h b/source/blender/editors/include/ED_space_api.h
index d268c578cf2..0cb23514867 100644
--- a/source/blender/editors/include/ED_space_api.h
+++ b/source/blender/editors/include/ED_space_api.h
@@ -41,7 +41,6 @@ void ED_spacemacros_init(void);
/* calls for registering default spaces */
void ED_spacetype_outliner(void);
-void ED_spacetype_time(void);
void ED_spacetype_view3d(void);
void ED_spacetype_ipo(void);
void ED_spacetype_image(void);
@@ -58,6 +57,7 @@ void ED_spacetype_logic(void);
void ED_spacetype_console(void);
void ED_spacetype_userpref(void);
void ED_spacetype_clip(void);
+void ED_spacetype_topbar(void);
/* calls for instancing and freeing spacetype static data
* called in WM_init_exit */
diff --git a/source/blender/editors/include/ED_transform.h b/source/blender/editors/include/ED_transform.h
index 9a0a7f8f1bb..601315e6124 100644
--- a/source/blender/editors/include/ED_transform.h
+++ b/source/blender/editors/include/ED_transform.h
@@ -43,6 +43,7 @@ struct wmEvent;
struct wmKeyConfig;
struct wmKeyMap;
struct wmOperatorType;
+struct WorkSpace;
struct Main;
struct SnapObjectContext;
struct SnapObjectParams;
@@ -109,9 +110,10 @@ enum TfmMode {
bool calculateTransformCenter(struct bContext *C, int centerMode, float cent3d[3], float cent2d[2]);
struct TransInfo;
-struct Base;
struct Scene;
struct Object;
+struct wmManipulatorGroup;
+struct wmManipulatorGroupType;
struct wmOperator;
/* UNUSED */
@@ -128,7 +130,7 @@ void BIF_createTransformOrientation(struct bContext *C, struct ReportList *repor
const char *name, const bool use_view,
const bool activate, const bool overwrite);
void BIF_selectTransformOrientation(struct bContext *C, struct TransformOrientation *ts);
-void BIF_selectTransformOrientationValue(struct bContext *C, int orientation);
+void BIF_selectTransformOrientationValue(struct Scene *scene, int orientation);
void ED_getTransformOrientationMatrix(const struct bContext *C, float orientation_mat[3][3], const short around);
@@ -153,10 +155,16 @@ int BIF_countTransformOrientation(const struct bContext *C);
void Transform_Properties(struct wmOperatorType *ot, int flags);
-/* view3d manipulators */
+/* transform manipulators */
+
+void TRANSFORM_WGT_manipulator(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_xform_cage(struct wmManipulatorGroupType *wgt);
+
+bool ED_widgetgroup_manipulator2d_poll(const struct bContext *C, struct wmManipulatorGroupType *wgt);
+void ED_widgetgroup_manipulator2d_setup(const struct bContext *C, struct wmManipulatorGroup *mgroup);
+void ED_widgetgroup_manipulator2d_refresh(const struct bContext *C, struct wmManipulatorGroup *mgroup);
+void ED_widgetgroup_manipulator2d_draw_prepare(const struct bContext *C, struct wmManipulatorGroup *mgroup);
-int BIF_do_manipulator(struct bContext *C, const struct wmEvent *event, struct wmOperator *op);
-void BIF_draw_manipulator(const struct bContext *C);
/* Snapping */
@@ -186,4 +194,17 @@ bool snapNodesTransform(
/* return args */
float r_loc[2], float *r_dist_px, char *r_node_border);
+struct TransformBounds {
+ float center[3]; /* Center for transform widget. */
+ float min[3], max[3]; /* Boundbox of selection for transform widget. */
+
+ /* Normalized axis */
+ float axis[3][3];
+ float axis_min[3], axis_max[3];
+};
+
+int ED_transform_calc_manipulator_stats(
+ const struct bContext *C, bool use_only_center,
+ struct TransformBounds *tbounds);
+
#endif /* __ED_TRANSFORM_H__ */
diff --git a/source/blender/editors/include/ED_transform_snap_object_context.h b/source/blender/editors/include/ED_transform_snap_object_context.h
index c20d92963a9..f1d47911cdd 100644
--- a/source/blender/editors/include/ED_transform_snap_object_context.h
+++ b/source/blender/editors/include/ED_transform_snap_object_context.h
@@ -29,12 +29,15 @@ struct BMVert;
struct BMEdge;
struct BMFace;
+struct Depsgraph;
struct ListBase;
struct Scene;
+struct ViewLayer;
struct Main;
struct Object;
struct ARegion;
struct View3D;
+struct bContext;
/* transform_snap_object.c */
@@ -73,9 +76,9 @@ struct SnapObjectParams {
typedef struct SnapObjectContext SnapObjectContext;
SnapObjectContext *ED_transform_snap_object_context_create(
- struct Main *bmain, struct Scene *scene, int flag);
+ struct Main *bmain, struct Scene *scene, struct Depsgraph *depsgraph, int flag);
SnapObjectContext *ED_transform_snap_object_context_create_view3d(
- struct Main *bmain, struct Scene *scene, int flag,
+ struct Main *bmain, struct Scene *scene, struct Depsgraph *depsgraph, int flag,
/* extra args for view3d */
const struct ARegion *ar, const struct View3D *v3d);
void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx);
diff --git a/source/blender/editors/include/ED_undo.h b/source/blender/editors/include/ED_undo.h
index b3814ab5899..6df568a6bc9 100644
--- a/source/blender/editors/include/ED_undo.h
+++ b/source/blender/editors/include/ED_undo.h
@@ -25,7 +25,10 @@
#ifndef __ED_UNDO_H__
#define __ED_UNDO_H__
+#include "BLI_compiler_attrs.h"
+
struct bContext;
+struct CLG_LogRef;
struct wmOperator;
struct wmOperatorType;
struct UndoStack;
@@ -49,10 +52,22 @@ int ED_undo_operator_repeat(struct bContext *C, struct wmOperator *op);
void ED_undo_operator_repeat_cb(struct bContext *C, void *arg_op, void *arg_unused);
void ED_undo_operator_repeat_cb_evt(struct bContext *C, void *arg_op, int arg_unused);
+/* Context sanity helpers for operator repeat. */
+typedef struct OperatorRepeatContextHandle OperatorRepeatContextHandle;
+
+const OperatorRepeatContextHandle *ED_operator_repeat_prepare_context(
+ struct bContext *C, struct wmOperator *op) ATTR_WARN_UNUSED_RESULT;
+void ED_operator_repeat_reset_context(
+ struct bContext *C, const OperatorRepeatContextHandle *context_info);
+
bool ED_undo_is_valid(const struct bContext *C, const char *undoname);
struct UndoStack *ED_undo_stack_get(void);
+/* helpers */
+void ED_undo_object_set_active_or_warn(
+ struct ViewLayer *view_layer, struct Object *ob, const char *info, struct CLG_LogRef *log);
+
/* undo_system_types.c */
void ED_undosys_type_init(void);
void ED_undosys_type_free(void);
diff --git a/source/blender/editors/include/ED_util.h b/source/blender/editors/include/ED_util.h
index 2653585dacc..69e80f60d0a 100644
--- a/source/blender/editors/include/ED_util.h
+++ b/source/blender/editors/include/ED_util.h
@@ -31,11 +31,10 @@
#ifndef __ED_UTIL_H__
#define __ED_UTIL_H__
+#include "BLI_compiler_attrs.h"
+
struct bContext;
struct wmOperatorType;
-struct ScrArea;
-struct SpaceLink;
-struct PackedFile;
/* ed_util.c */
diff --git a/source/blender/editors/include/ED_uvedit.h b/source/blender/editors/include/ED_uvedit.h
index d2d4732eedb..d6e8b6e9504 100644
--- a/source/blender/editors/include/ED_uvedit.h
+++ b/source/blender/editors/include/ED_uvedit.h
@@ -35,12 +35,13 @@ struct BMesh;
struct BMEditMesh;
struct BMFace;
struct BMLoop;
+struct Depsgraph;
struct Image;
struct ImageUser;
-struct MTexPoly;
struct Main;
struct Object;
struct Scene;
+struct ViewLayer;
struct SpaceImage;
struct bNode;
struct wmKeyConfig;
@@ -49,9 +50,8 @@ struct wmKeyConfig;
void ED_operatortypes_uvedit(void);
void ED_keymap_uvedit(struct wmKeyConfig *keyconf);
-void ED_uvedit_assign_image(
- struct Main *bmain, struct Scene *scene, struct Object *obedit, struct Image *ima, struct Image *previma);
bool ED_uvedit_minmax(struct Scene *scene, struct Image *ima, struct Object *obedit, float min[2], float max[2]);
+bool ED_uvedit_center(Scene *scene, Image *ima, struct Object *obedit, float cent[2], char mode);
void ED_uvedit_select_all(struct BMesh *bm);
bool ED_object_get_active_image(
@@ -62,7 +62,8 @@ void ED_object_assign_active_image(struct Main *bmain, struct Object *ob, int ma
bool ED_uvedit_test(struct Object *obedit);
/* visibility and selection */
-bool uvedit_face_visible_test(struct Scene *scene, struct Image *ima, struct BMFace *efa, struct MTexPoly *tf);
+bool uvedit_face_visible_test(
+ struct Scene *scene, struct Object *obedit, struct Image *ima, struct BMFace *efa);
bool uvedit_face_select_test(
struct Scene *scene, struct BMFace *efa,
const int cd_loop_uv_offset);
@@ -116,21 +117,24 @@ void ED_uvedit_live_unwrap_end(short cancel);
void ED_uvedit_live_unwrap(struct Scene *scene, struct Object *obedit);
void ED_uvedit_pack_islands(
- struct Scene *scene, struct Object *ob, struct BMesh *bm,
+ struct Scene *scene, struct Object *ob, struct BMesh *bm, bool selected, bool correct_aspect, bool do_rotate);
+void ED_uvedit_pack_islands_multi(
+ struct Scene *scene, struct Object **objects, const uint objects_len,
bool selected, bool correct_aspect, bool do_rotate);
void ED_uvedit_unwrap_cube_project(
struct BMesh *bm, float cube_size, bool use_select, const float center[3]);
/* single call up unwrap using scene settings, used for edge tag unwrapping */
-void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel);
+void ED_unwrap_lscm(struct Scene *scene, struct Object *obedit, const short sel, const bool pack);
/* uvedit_draw.c */
void ED_image_draw_cursor(
- struct ARegion *ar, const float cursor[2]);
+ struct ARegion *ar, const float cursor[2]);
void ED_uvedit_draw_main(
- struct SpaceImage *sima, struct ARegion *ar, struct Scene *scene,
- struct Object *obedit, struct Object *obact);
+ struct SpaceImage *sima,
+ struct ARegion *ar, struct Scene *scene, struct ViewLayer *view_layer,
+ struct Object *obedit, struct Object *obact, struct Depsgraph *depsgraph);
/* uvedit_buttons.c */
void ED_uvedit_buttons_register(struct ARegionType *art);
diff --git a/source/blender/editors/include/ED_view3d.h b/source/blender/editors/include/ED_view3d.h
index 2767e041627..3ab08967a0d 100644
--- a/source/blender/editors/include/ED_view3d.h
+++ b/source/blender/editors/include/ED_view3d.h
@@ -40,6 +40,8 @@ struct BPoint;
struct Base;
struct BezTriple;
struct BoundBox;
+struct Camera;
+struct Depsgraph;
struct EditBone;
struct ImBuf;
struct MVert;
@@ -49,14 +51,15 @@ struct Nurb;
struct Object;
struct RV3DMatrixStore;
struct RegionView3D;
+struct RenderEngineType;
struct Scene;
+struct ViewLayer;
struct ScrArea;
struct View3D;
struct ViewContext;
struct bContext;
struct bPoseChannel;
struct bScreen;
-struct bglMats;
struct rctf;
struct rcti;
struct wmOperator;
@@ -66,11 +69,15 @@ struct wmWindowManager;
struct GPUFX;
struct GPUOffScreen;
struct GPUFXSettings;
+struct GPUViewport;
+struct WorkSpace;
enum eGPUFXFlags;
/* for derivedmesh drawing callbacks, for view3d_select, .... */
typedef struct ViewContext {
+ struct Depsgraph *depsgraph;
struct Scene *scene;
+ struct ViewLayer *view_layer;
struct Object *obact;
struct Object *obedit;
struct ARegion *ar;
@@ -108,10 +115,10 @@ void ED_view3d_lastview_store(struct RegionView3D *rv3d);
void ED_view3d_depth_update(struct ARegion *ar);
float ED_view3d_depth_read_cached(const struct ViewContext *vc, const int mval[2]);
bool ED_view3d_depth_read_cached_normal(
- const ViewContext *vc, const struct bglMats *mats, const int mval[2],
+ const ViewContext *vc, const int mval[2],
float r_normal[3]);
bool ED_view3d_depth_unproject(
- const struct ARegion *ar, const struct bglMats *mats,
+ const struct ARegion *ar,
const int mval[2], const double depth,
float r_location_world[3]);
void ED_view3d_depth_tag_update(struct RegionView3D *rv3d);
@@ -220,9 +227,11 @@ float ED_view3d_pixel_size(const struct RegionView3D *rv3d, const float co[3]);
float ED_view3d_calc_zfac(const struct RegionView3D *rv3d, const float co[3], bool *r_flip);
bool ED_view3d_clip_segment(const struct RegionView3D *rv3d, float ray_start[3], float ray_end[3]);
bool ED_view3d_win_to_ray(
+ struct Depsgraph *depsgraph,
const struct ARegion *ar, const struct View3D *v3d, const float mval[2],
float ray_start[3], float ray_normal[3], const bool do_clip);
bool ED_view3d_win_to_ray_ex(
+ struct Depsgraph *depsgraph,
const struct ARegion *ar, const struct View3D *v3d, const float mval[2],
float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip);
void ED_view3d_global_to_vector(const struct RegionView3D *rv3d, const float coord[3], float vec[3]);
@@ -237,11 +246,14 @@ void ED_view3d_win_to_3d_int(
void ED_view3d_win_to_delta(const struct ARegion *ar, const float mval[2], float out[3], const float zfac);
void ED_view3d_win_to_origin(const struct ARegion *ar, const float mval[2], float out[3]);
void ED_view3d_win_to_vector(const struct ARegion *ar, const float mval[2], float out[3]);
-bool ED_view3d_win_to_segment(const struct ARegion *ar, struct View3D *v3d, const float mval[2],
+bool ED_view3d_win_to_segment(struct Depsgraph *depsgraph,
+ const struct ARegion *ar, struct View3D *v3d, const float mval[2],
float r_ray_start[3], float r_ray_end[3], const bool do_clip);
void ED_view3d_ob_project_mat_get(const struct RegionView3D *v3d, struct Object *ob, float pmat[4][4]);
void ED_view3d_ob_project_mat_get_from_obmat(const struct RegionView3D *rv3d, float obmat[4][4], float pmat[4][4]);
-void ED_view3d_unproject(struct bglMats *mats, float out[3], const float x, const float y, const float z);
+
+void ED_view3d_project(const struct ARegion *ar, const float world[3], float region[3]);
+bool ED_view3d_unproject(const struct ARegion *ar, float regionx, float regiony, float regionz, float world[3]);
/* end */
@@ -250,28 +262,34 @@ void ED_view3d_dist_range_get(
const struct View3D *v3d,
float r_dist_range[2]);
bool ED_view3d_clip_range_get(
+ struct Depsgraph *depsgraph,
const struct View3D *v3d, const struct RegionView3D *rv3d,
float *r_clipsta, float *r_clipend, const bool use_ortho_factor);
bool ED_view3d_viewplane_get(
+ struct Depsgraph *depsgraph,
const struct View3D *v3d, const struct RegionView3D *rv3d, int winxi, int winyi,
struct rctf *r_viewplane, float *r_clipsta, float *r_clipend, float *r_pixsize);
void ED_view3d_polygon_offset(const struct RegionView3D *rv3d, const float dist);
void ED_view3d_calc_camera_border(
- const struct Scene *scene, const struct ARegion *ar,
+ const struct Scene *scene, struct Depsgraph *depsgraph,
+ const struct ARegion *ar,
const struct View3D *v3d, const struct RegionView3D *rv3d,
struct rctf *r_viewborder, const bool no_shift);
void ED_view3d_calc_camera_border_size(
- const struct Scene *scene, const struct ARegion *ar,
+ const struct Scene *scene, struct Depsgraph *depsgraph,
+ const struct ARegion *ar,
const struct View3D *v3d, const struct RegionView3D *rv3d,
float r_size[2]);
bool ED_view3d_calc_render_border(
- const struct Scene *scene, const struct View3D *v3d,
- const struct ARegion *ar, struct rcti *rect);
+ const struct Scene *scene, struct Depsgraph *depsgraph,
+ struct View3D *v3d,
+ struct ARegion *ar, struct rcti *rect);
void ED_view3d_clipping_calc_from_boundbox(float clip[6][4], const struct BoundBox *clipbb, const bool is_flip);
-void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4], struct bglMats *mats, const struct rcti *rect);
+void ED_view3d_clipping_calc(struct BoundBox *bb, float planes[4][4],
+ const struct ARegion *ar, const struct Object *ob, const struct rcti *rect);
void ED_view3d_clipping_local(struct RegionView3D *rv3d, float mat[4][4]);
bool ED_view3d_clipping_test(const struct RegionView3D *rv3d, const float co[3], const bool is_local);
void ED_view3d_clipping_set(struct RegionView3D *rv3d);
@@ -285,24 +303,26 @@ float ED_view3d_radius_to_dist(
const char persp, const bool use_aspect,
const float radius);
-void drawcircball(int mode, const float cent[3], float rad, const float tmat[4][4]);
+void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned pos);
/* backbuffer select and draw support */
void ED_view3d_backbuf_validate(struct ViewContext *vc);
-struct ImBuf *ED_view3d_backbuf_read(struct ViewContext *vc, int xmin, int ymin, int xmax, int ymax);
+struct ImBuf *ED_view3d_backbuf_read(
+ struct ViewContext *vc, int xmin, int ymin, int xmax, int ymax);
unsigned int ED_view3d_backbuf_sample_rect(
struct ViewContext *vc, const int mval[2], int size,
unsigned int min, unsigned int max, float *r_dist);
int ED_view3d_backbuf_sample_size_clamp(struct ARegion *ar, const float dist);
-unsigned int ED_view3d_backbuf_sample(struct ViewContext *vc, int x, int y);
+unsigned int ED_view3d_backbuf_sample(
+ struct ViewContext *vc, int x, int y);
bool ED_view3d_autodist(
- struct Scene *scene, struct ARegion *ar, struct View3D *v3d,
+ struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d,
const int mval[2], float mouse_worldloc[3],
const bool alphaoverride, const float fallback_depth_pt[3]);
/* only draw so ED_view3d_autodist_simple can be called many times after */
-void ED_view3d_autodist_init(struct Scene *scene, struct ARegion *ar, struct View3D *v3d, int mode);
+void ED_view3d_autodist_init(struct Depsgraph *graph, struct ARegion *ar, struct View3D *v3d, int mode);
bool ED_view3d_autodist_simple(struct ARegion *ar, const int mval[2], float mouse_worldloc[3], int margin, float *force_depth);
bool ED_view3d_autodist_depth(struct ARegion *ar, const int mval[2], int margin, float *depth);
bool ED_view3d_autodist_depth_seg(struct ARegion *ar, const int mval_sta[2], const int mval_end[2], int margin, float *depth);
@@ -330,10 +350,10 @@ int view3d_opengl_select(
/* view3d_select.c */
float ED_view3d_select_dist_px(void);
void ED_view3d_viewcontext_init(struct bContext *C, struct ViewContext *vc);
+void ED_view3d_viewcontext_init_object(struct ViewContext *vc, struct Object *obact);
void view3d_operator_needs_opengl(const struct bContext *C);
void view3d_region_operator_needs_opengl(struct wmWindow *win, struct ARegion *ar);
void view3d_opengl_read_pixels(struct ARegion *ar, int x, int y, int w, int h, int format, int type, void *data);
-void view3d_get_transformation(const struct ARegion *ar, struct RegionView3D *rv3d, struct Object *ob, struct bglMats *mats);
/* XXX should move to BLI_math */
bool edge_inside_circle(const float cent[2], float radius, const float screen_co_a[2], const float screen_co_b[2]);
@@ -352,49 +372,57 @@ void ED_view3d_check_mats_rv3d(struct RegionView3D *rv3d);
# define ED_view3d_clear_mats_rv3d(rv3d) (void)(rv3d)
# define ED_view3d_check_mats_rv3d(rv3d) (void)(rv3d)
#endif
-int ED_view3d_scene_layer_set(int lay, const int *values, int *active);
+int ED_view3d_view_layer_set(int lay, const int *values, int *active);
struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d);
void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat);
+void ED_draw_object_facemap(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, const float col[4], const int facemap);
+
+struct RenderEngineType *ED_view3d_engine_type(struct Scene *scene, int drawtype);
+
bool ED_view3d_context_activate(struct bContext *C);
-void ED_view3d_draw_offscreen_init(struct Scene *scene, struct View3D *v3d);
void ED_view3d_draw_offscreen(
- struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[4][4],
- float winmat[4][4], bool do_bgpic, bool do_sky, bool is_persp, const char *viewname,
- struct GPUFX *fx, struct GPUFXSettings *fx_settings,
- struct GPUOffScreen *ofs);
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ int drawtype,
+ struct View3D *v3d, struct ARegion *ar, int winx, int winy, float viewmat[4][4],
+ float winmat[4][4], bool do_sky, bool is_persp, const char *viewname,
+ struct GPUFXSettings *fx_settings,
+ struct GPUOffScreen *ofs, struct GPUViewport *viewport);
void ED_view3d_draw_setup_view(
- struct wmWindow *win, struct Scene *scene, struct ARegion *ar, struct View3D *v3d,
+ struct wmWindow *win, struct Depsgraph *depsgraph, struct Scene *scene, struct ARegion *ar, struct View3D *v3d,
float viewmat[4][4], float winmat[4][4], const struct rcti *rect);
enum {
V3D_OFSDRAW_NONE = (0),
- V3D_OFSDRAW_USE_BACKGROUND = (1 << 0),
- V3D_OFSDRAW_USE_FULL_SAMPLE = (1 << 1),
+ V3D_OFSDRAW_USE_FULL_SAMPLE = (1 << 0),
/* Only works with ED_view3d_draw_offscreen_imbuf_simple(). */
- V3D_OFSDRAW_USE_GPENCIL = (1 << 2),
+ V3D_OFSDRAW_USE_GPENCIL = (1 << 1),
V3D_OFSDRAW_USE_SOLID_TEX = (1 << 2),
V3D_OFSDRAW_USE_CAMERA_DOF = (1 << 3),
};
struct ImBuf *ED_view3d_draw_offscreen_imbuf(
- struct Scene *scene, struct View3D *v3d, struct ARegion *ar, int sizex, int sizey,
- unsigned int flag, unsigned int draw_flags,
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ int drawtype,
+ struct View3D *v3d, struct ARegion *ar,
+ int sizex, int sizey, unsigned int flag, unsigned int draw_flags,
int alpha_mode, int samples, const char *viewname,
- struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
+ struct GPUOffScreen *ofs, char err_out[256]);
struct ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
- struct Scene *scene, struct Object *camera, int width, int height,
- unsigned int flag, unsigned int draw_flags, int drawtype, int alpha_mode,
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ int drawtype,
+ struct Object *camera, int width, int height,
+ unsigned int flag, unsigned int draw_flags, int alpha_mode,
int samples, const char *viewname,
- struct GPUFX *fx, struct GPUOffScreen *ofs, char err_out[256]);
+ struct GPUOffScreen *ofs, char err_out[256]);
struct Base *ED_view3d_give_base_under_cursor(struct bContext *C, const int mval[2]);
void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip);
void ED_view3d_update_viewmat(
- struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct View3D *v3d, struct ARegion *ar,
float viewmat[4][4], float winmat[4][4], const struct rcti *rect);
bool ED_view3d_quat_from_axis_view(const char view, float quat[4]);
char ED_view3d_quat_to_axis_view(const float quat[4], const float epsilon);
@@ -403,7 +431,7 @@ char ED_view3d_axis_view_opposite(char view);
bool ED_view3d_lock(struct RegionView3D *rv3d);
uint64_t ED_view3d_datamask(const struct Scene *scene, const struct View3D *v3d);
-uint64_t ED_view3d_screen_datamask(const struct bScreen *screen);
+uint64_t ED_view3d_screen_datamask(const struct Scene *scene, const struct bScreen *screen);
bool ED_view3d_offset_lock_check(const struct View3D *v3d, const struct RegionView3D *rv3d);
void ED_view3d_persp_switch_from_camera(struct View3D *v3d, struct RegionView3D *rv3d, const char persp);
@@ -427,10 +455,6 @@ bool ED_view3d_camera_lock_autokey(
void ED_view3d_lock_clear(struct View3D *v3d);
-struct BGpic *ED_view3d_background_image_new(struct View3D *v3d);
-void ED_view3d_background_image_remove(struct View3D *v3d, struct BGpic *bgpic);
-void ED_view3d_background_image_clear(struct View3D *v3d);
-
#define VIEW3D_MARGIN 1.4f
#define VIEW3D_DIST_FALLBACK 1.0f
@@ -459,4 +483,11 @@ void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrAr
void ED_view3d_id_remap(struct View3D *v3d, const struct ID *old_id, struct ID *new_id);
+/* view3d_draw_legacy.c */
+/* Try avoid using these more move out of legacy. */
+void ED_view3d_draw_bgpic_test(
+ struct Scene *scene, struct Depsgraph *depsgraph,
+ struct ARegion *ar, struct View3D *v3d,
+ const bool do_foreground, const bool do_camera_frame);
+
#endif /* __ED_VIEW3D_H__ */
diff --git a/source/blender/editors/include/UI_icons.h b/source/blender/editors/include/UI_icons.h
index 0c83038b7a3..a87f23c42a8 100644
--- a/source/blender/editors/include/UI_icons.h
+++ b/source/blender/editors/include/UI_icons.h
@@ -190,8 +190,8 @@ DEF_ICON(SCULPTMODE_HLT)
DEF_ICON(POSE_HLT)
DEF_ICON(PARTICLEMODE)
DEF_ICON(LIGHTPAINT)
+DEF_ICON(GREASEPENCIL_STROKE_PAINT)
#ifndef DEF_ICON_BLANK_SKIP
- DEF_ICON(BLANK063)
DEF_ICON(BLANK064)
DEF_ICON(BLANK065)
DEF_ICON(BLANK066)
@@ -257,9 +257,7 @@ DEF_ICON(STRANDS)
DEF_ICON(LIBRARY_DATA_INDIRECT)
DEF_ICON(GREASEPENCIL)
DEF_ICON(LINE_DATA)
-#ifndef DEF_ICON_BLANK_SKIP
- DEF_ICON(BLANK084)
-#endif
+DEF_ICON(LIBRARY_DATA_OVERRIDE)
DEF_ICON(GROUP_BONE)
DEF_ICON(GROUP_VERTEX)
DEF_ICON(GROUP_VCOL)
@@ -315,8 +313,8 @@ DEF_ICON(OUTLINER_OB_SURFACE)
DEF_ICON(OUTLINER_OB_SPEAKER)
DEF_ICON(OUTLINER_OB_FORCE_FIELD)
DEF_ICON(OUTLINER_OB_GROUP_INSTANCE)
+DEF_ICON(OUTLINER_OB_GREASEPENCIL)
#ifndef DEF_ICON_BLANK_SKIP
- DEF_ICON(BLANK122)
DEF_ICON(BLANK123)
DEF_ICON(BLANK124)
DEF_ICON(BLANK125)
@@ -346,8 +344,8 @@ DEF_ICON(OUTLINER_DATA_FONT)
DEF_ICON(OUTLINER_DATA_SURFACE)
DEF_ICON(OUTLINER_DATA_SPEAKER)
DEF_ICON(OUTLINER_DATA_POSE)
+DEF_ICON(OUTLINER_DATA_GREASEPENCIL)
#ifndef DEF_ICON_BLANK_SKIP
- DEF_ICON(BLANK130)
DEF_ICON(BLANK131)
DEF_ICON(BLANK132)
DEF_ICON(BLANK133)
@@ -715,8 +713,8 @@ DEF_ICON(CLIPUV_DEHLT)
DEF_ICON(CLIPUV_HLT)
DEF_ICON(SNAP_PEEL_OBJECT)
DEF_ICON(GRID)
+DEF_ICON(OBJECT_ORIGIN)
#ifndef DEF_ICON_BLANK_SKIP
- DEF_ICON(BLANK221)
DEF_ICON(BLANK222)
DEF_ICON(BLANK224)
DEF_ICON(BLANK225)
@@ -1034,3 +1032,9 @@ DEF_VICO(COLORSET_18_VEC)
DEF_VICO(COLORSET_19_VEC)
DEF_VICO(COLORSET_20_VEC)
+ /* Studio lighting presets */
+DEF_ICON(STUDIOLIGHT_01)
+DEF_ICON(STUDIOLIGHT_02)
+DEF_ICON(STUDIOLIGHT_03)
+DEF_ICON(STUDIOLIGHT_04)
+DEF_ICON(STUDIOLIGHT_05)
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index d6c6f0a2eb6..5830a8ea811 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -64,7 +64,6 @@ struct Image;
struct ImageUser;
struct wmKeyConfig;
struct wmOperatorType;
-struct uiWidgetColors;
struct MTex;
struct ImBuf;
struct bNodeTree;
@@ -73,6 +72,8 @@ struct bNodeSocket;
struct wmDropBox;
struct wmDrag;
struct wmEvent;
+struct wmManipulator;
+struct wmMsgBus;
typedef struct uiBut uiBut;
typedef struct uiBlock uiBlock;
@@ -107,7 +108,8 @@ enum {
UI_DIR_DOWN = (1 << 1),
UI_DIR_LEFT = (1 << 2),
UI_DIR_RIGHT = (1 << 3),
- UI_DIR_CENTER_Y = (1 << 4),
+ UI_DIR_CENTER_X = (1 << 4),
+ UI_DIR_CENTER_Y = (1 << 5),
UI_DIR_ALL = (UI_DIR_UP | UI_DIR_DOWN | UI_DIR_LEFT | UI_DIR_RIGHT),
};
@@ -139,6 +141,7 @@ enum {
#define UI_BLOCK_POPUP_HOLD (1 << 18)
#define UI_BLOCK_LIST_ITEM (1 << 19)
#define UI_BLOCK_RADIAL (1 << 20)
+#define UI_BLOCK_POPOVER (1 << 21)
/* uiPopupBlockHandle->menuretval */
#define UI_RETURN_CANCEL (1 << 0) /* cancel all menus cascading */
@@ -178,11 +181,13 @@ enum {
UI_BUT_COLOR_CUBIC = (1 << 23), /* cubic saturation for the color wheel */
UI_BUT_LIST_ITEM = (1 << 24), /* This but is "inside" a list item (currently used to change theme colors). */
UI_BUT_DRAG_MULTI = (1 << 25), /* edit this button as well as the active button (not just dragging) */
- UI_BUT_SCA_LINK_GREY = (1 << 26), /* used to flag if sca links shoud be gray out */
+
UI_BUT_HAS_SEP_CHAR = (1 << 27), /* but->str contains UI_SEP_CHAR, used for key shortcuts */
UI_BUT_UPDATE_DELAY = (1 << 28), /* don't run updates while dragging (needed in rare cases). */
UI_BUT_TEXTEDIT_UPDATE = (1 << 29), /* when widget is in textedit mode, update value on each char stroke */
UI_BUT_VALUE_CLEAR = (1 << 30), /* show 'x' icon to clear/unlink value of text or search button */
+
+ UI_BUT_OVERRIDEN = (1 << 31), /* RNA property of the button is overriden from linked reference data. */
};
#define UI_PANEL_WIDTH 340
@@ -218,11 +223,14 @@ enum {
UI_BUT_ALIGN_ALL = (UI_BUT_ALIGN | UI_BUT_ALIGN_STITCH_TOP | UI_BUT_ALIGN_STITCH_LEFT),
UI_BUT_BOX_ITEM = (1 << 20), /* This but is "inside" a box item (currently used to change theme colors). */
+
+ UI_BUT_ACTIVE_LEFT = (1 << 21), /* Active left part of number button */
+ UI_BUT_ACTIVE_RIGHT = (1 << 22), /* Active right part of number button */
};
/* scale fixed button widths by this to account for DPI */
-#define UI_DPI_FAC ((U.pixelsize * (float)U.dpi) / 72.0f)
+#define UI_DPI_FAC (U.dpi_fac)
/* 16 to copy ICON_DEFAULT_HEIGHT */
#define UI_DPI_ICON_SIZE ((float)16 * UI_DPI_FAC)
@@ -261,11 +269,11 @@ typedef enum {
UI_BTYPE_CHECKBOX = (13 << 9), /* similar to toggle, display a 'tick' */
UI_BTYPE_CHECKBOX_N = (14 << 9),
UI_BTYPE_COLOR = (15 << 9),
+ UI_BTYPE_TAB = (16 << 9),
+ UI_BTYPE_POPOVER = (17 << 9),
UI_BTYPE_SCROLL = (18 << 9),
UI_BTYPE_BLOCK = (19 << 9),
UI_BTYPE_LABEL = (20 << 9),
- UI_BTYPE_LINK = (22 << 9),
- UI_BTYPE_INLINK = (23 << 9),
UI_BTYPE_KEY_EVENT = (24 << 9),
UI_BTYPE_HSVCUBE = (26 << 9),
UI_BTYPE_PULLDOWN = (27 << 9), /* menu (often used in headers), **_MENU /w different draw-type */
@@ -313,18 +321,25 @@ typedef enum {
* Functions to draw various shapes, taking theme settings into account.
* Used for code that draws its own UI style elements. */
-void UI_draw_roundbox(float minx, float miny, float maxx, float maxy, float rad);
+void UI_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3, const float color[4]);
+void UI_draw_anti_fan(float tri_array[][2], unsigned int length, const float color[4]);
+
void UI_draw_roundbox_corner_set(int type);
+void UI_draw_roundbox_aa(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float color[4]);
+void UI_draw_roundbox_4fv(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[4]);
+void UI_draw_roundbox_3ubAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const unsigned char col[3], unsigned char alpha);
+void UI_draw_roundbox_3fvAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[3], float alpha);
+void UI_draw_roundbox_shade_x(bool filled, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown, const float col[4]);
+
+#if 0 /* unused */
int UI_draw_roundbox_corner_get(void);
-void UI_draw_roundbox_unfilled(float minx, float miny, float maxx, float maxy, float rad);
+void UI_draw_roundbox_shade_y(bool filled, float minx, float miny, float maxx, float maxy, float rad, float shadeleft, float shaderight, const float col[4]);
+#endif
+
void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx, float maxy);
-void UI_draw_roundbox_gl_mode(int mode, float minx, float miny, float maxx, float maxy, float rad);
-void UI_draw_roundbox_shade_x(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadetop, float shadedown);
-void UI_draw_roundbox_shade_y(int mode, float minx, float miny, float maxx, float maxy, float rad, float shadeLeft, float shadeRight);
-void UI_draw_text_underline(int pos_x, int pos_y, int len, int height);
+void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4]);
-void UI_draw_safe_areas(
- float x1, float x2, float y1, float y2,
+void UI_draw_safe_areas(uint pos, float x1, float x2, float y1, float y2,
const float title_aspect[2], const float action_aspect[2]);
/* state for scrolldrawing */
@@ -403,6 +418,14 @@ int UI_popup_menu_invoke(struct bContext *C, const char *idname, struct ReportLi
void UI_popup_menu_retval_set(const uiBlock *block, const int retval, const bool enable);
void UI_popup_menu_but_set(uiPopupMenu *pup, struct ARegion *butregion, uiBut *but);
+/* interface_region_popover.c */
+
+typedef struct uiPopover uiPopover;
+
+uiPopover *UI_popover_begin(struct bContext *C) ATTR_NONNULL();
+void UI_popover_end(struct bContext *C, struct uiPopover *head);
+struct uiLayout *UI_popover_layout(uiPopover *head);
+
/* interface_region_menu_pie.c */
/* Pie menus */
typedef struct uiPieMenu uiPieMenu;
@@ -452,6 +475,8 @@ uiBlock *UI_block_begin(const struct bContext *C, struct ARegion *region, const
void UI_block_end_ex(const struct bContext *C, uiBlock *block, const int xy[2], int r_xy[2]);
void UI_block_end(const struct bContext *C, uiBlock *block);
void UI_block_draw(const struct bContext *C, struct uiBlock *block);
+void UI_blocklist_update_window_matrix(const struct bContext *C, const struct ListBase *lb);
+void UI_blocklist_draw(const struct bContext *C, const struct ListBase *lb);
void UI_block_update_from_old(const struct bContext *C, struct uiBlock *block);
uiBlock *UI_block_find_in_region(const char *name, struct ARegion *ar);
@@ -659,6 +684,7 @@ void UI_but_string_info_get(struct bContext *C, uiBut *but, ...) ATTR_SENTINEL(0
#define UI_ID_FAKE_USER (1 << 8)
#define UI_ID_PIN (1 << 9)
#define UI_ID_PREVIEWS (1 << 10)
+#define UI_ID_OVERRIDE (1 << 11)
#define UI_ID_FULL (UI_ID_RENAME | UI_ID_BROWSE | UI_ID_ADD_NEW | UI_ID_OPEN | UI_ID_ALONE | UI_ID_DELETE | UI_ID_LOCAL)
/**
@@ -692,18 +718,30 @@ uiBut *uiDefSearchButO_ptr(uiBlock *block, struct wmOperatorType *ot, struct IDP
void *arg, int retval, int icon, int maxlen, int x, int y,
short width, short height, float a1, float a2, const char *tip);
-uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, const char *name, int icon, int x1, int y1, int x2, int y2);
-int uiDefAutoButsRNA(uiLayout *layout, struct PointerRNA *ptr, bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *), const char label_align);
-
-/* Links
- *
- * Game engine logic brick links. Non-functional currently in 2.5,
- * code to handle and draw these is disabled internally. */
-void UI_but_link_set(struct uiBut *but, void **poin, void ***ppoin, short *tot, int from, int to);
+/* For uiDefAutoButsRNA */
+typedef enum {
+ /* Keep current layout for aligning label with property button. */
+ UI_BUT_LABEL_ALIGN_NONE,
+ /* Align label and property button vertically. */
+ UI_BUT_LABEL_ALIGN_COLUMN,
+ /* Split layout into a column for the label and one for property button. */
+ UI_BUT_LABEL_ALIGN_SPLIT_COLUMN,
+} eButLabelAlign;
+
+/* Return info for uiDefAutoButsRNA */
+typedef enum {
+ /* Returns when no buttons were added */
+ UI_PROP_BUTS_NONE_ADDED = (1 << 0),
+ /* Returned when any property failed the custom check callback (check_prop) */
+ UI_PROP_BUTS_ANY_FAILED_CHECK = (1 << 1),
+} eAutoPropButsReturn;
-void UI_block_links_compose(uiBlock *block);
-uiBut *UI_block_links_find_inlink(uiBlock *block, void *poin);
+uiBut *uiDefAutoButR(uiBlock *block, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, const char *name, int icon, int x1, int y1, int x2, int y2);
+eAutoPropButsReturn uiDefAutoButsRNA(
+ uiLayout *layout, struct PointerRNA *ptr,
+ bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *),
+ eButLabelAlign label_align, const bool compact);
/* use inside searchfunc to add items */
bool UI_search_item_add(uiSearchItems *items, const char *name, void *poin, int iconid);
@@ -809,7 +847,6 @@ void UI_popup_handlers_remove_all(struct bContext *C, struct ListBase *handlers)
void UI_init(void);
void UI_init_userdef(void);
void UI_reinit_font(void);
-void UI_reinit_gl_state(void);
void UI_exit(void);
/* Layout
@@ -840,6 +877,7 @@ void UI_exit(void);
#define UI_LAYOUT_ALIGN_CENTER 2
#define UI_LAYOUT_ALIGN_RIGHT 3
+#define UI_ITEM_O_RETURN_PROPS (1 << 0)
#define UI_ITEM_R_EXPAND (1 << 1)
#define UI_ITEM_R_SLIDER (1 << 2)
#define UI_ITEM_R_TOGGLE (1 << 3)
@@ -849,10 +887,15 @@ void UI_exit(void);
#define UI_ITEM_R_NO_BG (1 << 7)
#define UI_ITEM_R_IMMEDIATE (1 << 8)
#define UI_ITEM_O_DEPRESS (1 << 9)
+#define UI_ITEM_R_COMPACT (1 << 10)
-/* uiTemplateOperatorPropertyButs flags */
-#define UI_TEMPLATE_OP_PROPS_SHOW_TITLE 1
-#define UI_TEMPLATE_OP_PROPS_SHOW_EMPTY 2
+
+/* uiLayoutOperatorButs flags */
+enum {
+ UI_TEMPLATE_OP_PROPS_SHOW_TITLE = (1 << 0),
+ UI_TEMPLATE_OP_PROPS_SHOW_EMPTY = (1 << 1),
+ UI_TEMPLATE_OP_PROPS_COMPACT = (1 << 2),
+};
/* used for transp checkers */
#define UI_ALPHA_CHECKER_DARK 100
@@ -874,13 +917,12 @@ enum {
UI_CNR_ALL = (UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT)
};
-/* not apart of the corner flags but mixed in some functions */
-#define UI_RB_ALPHA (UI_CNR_ALL + 1)
-
uiLayout *UI_block_layout(uiBlock *block, int dir, int type, int x, int y, int size, int em, int padding, struct uiStyle *style);
void UI_block_layout_set_current(uiBlock *block, uiLayout *layout);
void UI_block_layout_resolve(uiBlock *block, int *x, int *y);
+void UI_region_message_subscribe(struct ARegion *ar, struct wmMsgBus *mbus);
+
uiBlock *uiLayoutGetBlock(uiLayout *layout);
void uiLayoutSetFunc(uiLayout *layout, uiMenuHandleFunc handlefunc, void *argv);
@@ -888,6 +930,7 @@ void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct Pointe
void uiLayoutContextCopy(uiLayout *layout, struct bContextStore *context);
const char *uiLayoutIntrospect(uiLayout *layout); // XXX - testing
struct MenuType *UI_but_menutype_get(uiBut *but);
+struct PanelType *UI_but_paneltype_get(uiBut *but);
void UI_menutype_draw(struct bContext *C, struct MenuType *mt, struct uiLayout *layout);
/* Only for convenience. */
@@ -936,11 +979,30 @@ void uiTemplateIDBrowse(
void uiTemplateIDPreview(
uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname,
const char *newop, const char *openop, const char *unlinkop, int rows, int cols, int filter);
+void uiTemplateIDTabs(
+ uiLayout *layout, struct bContext *C,
+ PointerRNA *ptr, const char *propname,
+ const char *newop, const char *openop, const char *unlinkop,
+ int filter);
void uiTemplateAnyID(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
const char *proptypename, const char *text);
+void uiTemplateSearch(
+ uiLayout *layout, struct bContext *C,
+ struct PointerRNA *ptr, const char *propname,
+ struct PointerRNA *searchptr, const char *searchpropname,
+ const char *newop, const char *unlinkop);
+void uiTemplateSearchPreview(
+ uiLayout *layout, struct bContext *C,
+ struct PointerRNA *ptr, const char *propname,
+ struct PointerRNA *searchptr, const char *searchpropname,
+ const char *newop, const char *unlinkop,
+ const int rows, const int cols);
void uiTemplatePathBuilder(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
struct PointerRNA *root_ptr, const char *text);
uiLayout *uiTemplateModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
+
+void uiTemplateOperatorRedoProperties(uiLayout *layout, const struct bContext *C);
+
uiLayout *uiTemplateConstraint(uiLayout *layout, struct PointerRNA *ptr);
void uiTemplatePreview(uiLayout *layout, struct bContext *C, struct ID *id, int show_buttons, struct ID *parent,
struct MTex *slot, const char *preview_id);
@@ -955,8 +1017,6 @@ void uiTemplateColorPicker(uiLayout *layout, struct PointerRNA *ptr, const char
void uiTemplatePalette(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int color);
void uiTemplateLayers(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
PointerRNA *used_ptr, const char *used_propname, int active_layer);
-void uiTemplateGameStates(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
- PointerRNA *used_ptr, const char *used_propname, int active_state);
void uiTemplateImage(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *userptr, int compact, int multiview);
void uiTemplateImageSettings(uiLayout *layout, struct PointerRNA *imfptr, int color_management);
void uiTemplateImageStereo3d(uiLayout *layout, struct PointerRNA *stereo3d_format_ptr);
@@ -967,13 +1027,20 @@ void uiTemplateImageInfo(uiLayout *layout, struct bContext *C, struct Image *ima
void uiTemplateRunningJobs(uiLayout *layout, struct bContext *C);
void UI_but_func_operator_search(uiBut *but);
void uiTemplateOperatorSearch(uiLayout *layout);
-void uiTemplateOperatorPropertyButs(const struct bContext *C, uiLayout *layout, struct wmOperator *op,
- bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *),
- const char label_align, const short flag);
+eAutoPropButsReturn uiTemplateOperatorPropertyButs(
+ const struct bContext *C, uiLayout *layout, struct wmOperator *op,
+ bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *),
+ const eButLabelAlign label_align, const short flag);
+void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C);
void uiTemplateHeader3D(uiLayout *layout, struct bContext *C);
void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C);
void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C);
void uiTemplateKeymapItemProperties(uiLayout *layout, struct PointerRNA *ptr);
+void uiTemplateOverrideProperty(
+ uiLayout *layout, struct PointerRNA *collection_props_ptr, struct PointerRNA *scene_props_ptr,
+ const char *propname,
+ const char *name, const char *text_ctxt, int translate, int icon,
+ const char *custom_template);
void uiTemplateComponentMenu(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name);
void uiTemplateNodeSocket(uiLayout *layout, struct bContext *C, float *color);
void uiTemplateCacheFile(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname);
@@ -1044,6 +1111,19 @@ void uiItemM(uiLayout *layout, struct bContext *C, const char *menuname, const c
void uiItemV(uiLayout *layout, const char *name, int icon, int argval); /* value */
void uiItemS(uiLayout *layout); /* separator */
+void uiItemPopoverPanel_ptr(
+ uiLayout *layout, struct bContext *C,
+ struct PanelType *pt,
+ const char *name, int icon);
+void uiItemPopoverPanel(
+ uiLayout *layout, struct bContext *C,
+ int space_id, int region_id, const char *panelname,
+ const char *name, int icon);
+void uiItemPopoverPanelFromGroup(
+ uiLayout *layout, struct bContext *C,
+ int space_id, int region_id,
+ const char *context, const char *category);
+
void uiItemMenuF(uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg);
void uiItemMenuEnumO_ptr(uiLayout *layout, struct bContext *C, struct wmOperatorType *ot, const char *propname, const char *name, int icon);
void uiItemMenuEnumO(uiLayout *layout, struct bContext *C, const char *opname, const char *propname, const char *name, int icon);
@@ -1085,20 +1165,22 @@ uiBut *UI_region_active_but_get(struct ARegion *ar);
/* Styled text draw */
void UI_fontstyle_set(const struct uiFontStyle *fs);
-void UI_fontstyle_draw_ex(
- const struct uiFontStyle *fs, const struct rcti *rect, const char *str,
- size_t len, float *r_xofs, float *r_yofs);
-void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str);
-void UI_fontstyle_draw_rotated(const struct uiFontStyle *fs, const struct rcti *rect, const char *str);
-void UI_fontstyle_draw_simple(const struct uiFontStyle *fs, float x, float y, const char *str);
+void UI_fontstyle_draw_ex(const struct uiFontStyle *fs, const struct rcti *rect, const char *str,
+ const unsigned char col[4], size_t len, float *r_xofs, float *r_yofs);
+void UI_fontstyle_draw(const struct uiFontStyle *fs, const struct rcti *rect, const char *str,
+ const unsigned char col[4]);
+void UI_fontstyle_draw_rotated(const struct uiFontStyle *fs, const struct rcti *rect, const char *str,
+ const unsigned char col[4]);
+void UI_fontstyle_draw_simple(const struct uiFontStyle *fs, float x, float y, const char *str,
+ const unsigned char col[4]);
void UI_fontstyle_draw_simple_backdrop(
const struct uiFontStyle *fs, float x, float y, const char *str,
- const unsigned char fg[4], const unsigned char bg[4]);
+ const float col_fg[4], const float col_bg[4]);
int UI_fontstyle_string_width(const struct uiFontStyle *fs, const char *str);
int UI_fontstyle_height_max(const struct uiFontStyle *fs);
-void UI_draw_icon_tri(float x, float y, char dir);
+void UI_draw_icon_tri(float x, float y, char dir, const float[4]);
struct uiStyle *UI_style_get(void); /* use for fonts etc */
struct uiStyle *UI_style_get_dpi(void); /* DPI scaled settings for drawing */
@@ -1126,6 +1208,7 @@ void UI_butstore_unregister(uiButStore *bs_handle, uiBut **but_p);
/* ui_interface_region_tooltip.c */
struct ARegion *UI_tooltip_create_from_button(struct bContext *C, struct ARegion *butregion, uiBut *but);
+struct ARegion *UI_tooltip_create_from_manipulator(struct bContext *C, struct wmManipulator *mpr);
void UI_tooltip_free(struct bContext *C, struct bScreen *sc, struct ARegion *ar);
/* How long before a tool-tip shows. */
@@ -1141,4 +1224,14 @@ void UI_tooltip_free(struct bContext *C, struct bScreen *sc, struct ARegion *ar)
int UI_calc_float_precision(int prec, double value);
+/* widget batched drawing */
+void UI_widgetbase_draw_cache_begin(void);
+void UI_widgetbase_draw_cache_flush(void);
+void UI_widgetbase_draw_cache_end(void);
+
+/* Special drawing for toolbar, mainly workarounds for inflexible icon sizing. */
+#define USE_TOOLBAR_HACK
+
+bool UI_but_is_tool(const uiBut *but);
+
#endif /* __UI_INTERFACE_H__ */
diff --git a/source/blender/editors/include/UI_interface_icons.h b/source/blender/editors/include/UI_interface_icons.h
index 945ac1b6db9..a3be887bf5b 100644
--- a/source/blender/editors/include/UI_interface_icons.h
+++ b/source/blender/editors/include/UI_interface_icons.h
@@ -49,6 +49,8 @@ typedef struct IconFile {
#define ICON_DEFAULT_HEIGHT 16
#define ICON_DEFAULT_WIDTH 16
+#define ICON_DEFAULT_HEIGHT_TOOLBAR 38
+
#define ICON_DEFAULT_HEIGHT_SCALE ((int)(UI_UNIT_Y * 0.8f))
#define ICON_DEFAULT_WIDTH_SCALE ((int)(UI_UNIT_X * 0.8f))
@@ -66,6 +68,7 @@ void UI_id_icon_render(
int UI_preview_render_size(enum eIconSizes size);
void UI_icon_draw(float x, float y, int icon_id);
+void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha);
void UI_icon_draw_preview(float x, float y, int icon_id);
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect);
void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspect, float alpha, int size);
@@ -73,9 +76,13 @@ void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspec
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha);
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3]);
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha);
+void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha, float desaturate);
void UI_icons_free(void);
void UI_icons_free_drawinfo(void *drawinfo);
+void UI_icon_draw_cache_begin(void);
+void UI_icon_draw_cache_end(void);
+
struct ListBase *UI_iconfile_list(void);
int UI_iconfile_get_index(const char *filename);
diff --git a/source/blender/editors/include/UI_resources.h b/source/blender/editors/include/UI_resources.h
index a0efd586af5..2fc9b2946fb 100644
--- a/source/blender/editors/include/UI_resources.h
+++ b/source/blender/editors/include/UI_resources.h
@@ -51,7 +51,7 @@ typedef enum {
/* use to denote intentionally unset theme color */
#define TH_UNDEFINED -1
-enum {
+typedef enum ThemeColorID {
TH_REDALERT,
TH_THEMEUI,
@@ -275,10 +275,18 @@ enum {
TH_WIDGET_EMBOSS,
+ TH_EDITOR_OUTLINE,
+
TH_AXIS_X, /* X/Y/Z Axis */
TH_AXIS_Y,
TH_AXIS_Z,
+ TH_MANIPULATOR_HI,
+ TH_MANIPULATOR_PRIMARY,
+ TH_MANIPULATOR_SECONDARY,
+ TH_MANIPULATOR_A,
+ TH_MANIPULATOR_B,
+
TH_LOW_GRAD,
TH_HIGH_GRAD,
TH_SHOW_BACK_GRAD,
@@ -302,7 +310,7 @@ enum {
TH_EDGE_BEVEL,
TH_VERTEX_BEVEL
-};
+} ThemeColorID;
/* specific defines per space should have higher define values */
@@ -319,13 +327,13 @@ struct bThemeState {
void UI_ThemeColor(int colorid);
// sets the color plus alpha
-void UI_ThemeColor4(int colorid);
+void UI_ThemeColor4(int colorid);
// sets color plus offset for shade
-void UI_ThemeColorShade(int colorid, int offset);
+void UI_ThemeColorShade(int colorid, int offset);
// sets color plus offset for alpha
-void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset);
+void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset);
// sets color, which is blend between two theme colors
void UI_ThemeColorBlend(int colorid1, int colorid2, float fac);
@@ -343,14 +351,27 @@ int UI_GetThemeValueType(int colorid, int spacetype);
// get three color values, scaled to 0.0-1.0 range
void UI_GetThemeColor3fv(int colorid, float col[3]);
void UI_GetThemeColorBlend3ubv(int colorid1, int colorid2, float fac, unsigned char col[3]);
+void UI_GetThemeColorBlend3f(int colorid1, int colorid2, float fac, float r_col[3]);
// get the color, range 0.0-1.0, complete with shading offset
void UI_GetThemeColorShade3fv(int colorid, int offset, float col[3]);
void UI_GetThemeColorShade3ubv(int colorid, int offset, unsigned char col[3]);
+void UI_GetThemeColorShade4ubv(int colorid, int offset, unsigned char col[4]);
+
+// get three color values, range 0-255, complete with shading offset for the RGB components and blending
+void UI_GetThemeColorBlendShade3ubv(int colorid1, int colorid2, float fac, int offset, unsigned char col[3]);
// get four color values, scaled to 0.0-1.0 range
void UI_GetThemeColor4fv(int colorid, float col[4]);
// get four color values, range 0.0-1.0, complete with shading offset for the RGB components
void UI_GetThemeColorShade4fv(int colorid, int offset, float col[4]);
+void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4]);
+
+// get four colour values ranged between 0 and 255; includes the alpha channel
+void UI_GetThemeColorShadeAlpha4ubv(int colorid, int coloffset, int alphaoffset, unsigned char col[4]);
+
+// get four color values, range 0.0-1.0, complete with shading offset for the RGB components and blending
+void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3]);
+void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4]);
// get the 3 or 4 byte values
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3]);
@@ -368,6 +389,10 @@ void UI_GetColorPtrShade3ubv(const unsigned char cp1[3], unsigned char col[3]
// get a 3 byte color, blended and shaded between two other char color pointers
void UI_GetColorPtrBlendShade3ubv(const unsigned char cp1[3], const unsigned char cp2[3], unsigned char col[3], float fac, int offset);
+// sets the font color
+// (for anything fancy use UI_GetThemeColor[Fancy] then BLF_color)
+void UI_FontThemeColor(int fontid, int colorid);
+
// clear the openGL ClearColor using the input colorid
void UI_ThemeClearColor(int colorid);
diff --git a/source/blender/editors/include/UI_view2d.h b/source/blender/editors/include/UI_view2d.h
index f6e31e0bd22..1f106e3f08d 100644
--- a/source/blender/editors/include/UI_view2d.h
+++ b/source/blender/editors/include/UI_view2d.h
@@ -103,8 +103,13 @@ enum eView2D_Gridlines {
/* ------ Defines for Scrollers ----- */
/* scroller area */
-#define V2D_SCROLL_HEIGHT (0.85f * U.widget_unit)
-#define V2D_SCROLL_WIDTH (0.85f * U.widget_unit)
+#define V2D_SCROLL_HEIGHT_MIN (0.25f * U.widget_unit)
+#define V2D_SCROLL_WIDTH_MIN (0.25f * U.widget_unit)
+#define V2D_SCROLL_HEIGHT (0.45f * U.widget_unit)
+#define V2D_SCROLL_WIDTH (0.45f * U.widget_unit)
+/* For scrollers with scale markings (text written onto them) */
+#define V2D_SCROLL_HEIGHT_TEXT (0.79f * U.widget_unit)
+#define V2D_SCROLL_WIDTH_TEXT (0.79f * U.widget_unit)
/* scroller 'handles' hotspot radius for mouse */
#define V2D_SCROLLER_HANDLE_SIZE (0.6f * U.widget_unit)
@@ -219,7 +224,7 @@ void UI_view2d_center_set(struct View2D *v2d, float x, float y);
void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac);
-short UI_view2d_mouse_in_scrollers(const struct bContext *C, struct View2D *v2d, int x, int y);
+short UI_view2d_mouse_in_scrollers(const struct ARegion *ar, struct View2D *v2d, int x, int y);
/* cached text drawing in v2d, to allow pixel-aligned draw as post process */
void UI_view2d_text_cache_add(struct View2D *v2d, float x, float y,
diff --git a/source/blender/editors/interface/CMakeLists.txt b/source/blender/editors/interface/CMakeLists.txt
index 0adc315fd69..49fe6bfb2dc 100644
--- a/source/blender/editors/interface/CMakeLists.txt
+++ b/source/blender/editors/interface/CMakeLists.txt
@@ -24,6 +24,8 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
+ ../../draw
../../gpu
../../imbuf
../../makesdna
@@ -58,6 +60,7 @@ set(SRC
interface_region_color_picker.c
interface_region_menu_pie.c
interface_region_menu_popup.c
+ interface_region_popover.c
interface_region_popup.c
interface_region_search.c
interface_region_tooltip.c
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 5f36c5e21bf..dcd267a90d3 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -41,6 +41,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_userdef_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_math.h"
#include "BLI_listbase.h"
@@ -50,31 +51,38 @@
#include "BLI_utildefines.h"
+#include "BKE_animsys.h"
#include "BKE_context.h"
#include "BKE_unit.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_idprop.h"
-#include "BIF_gl.h"
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
#include "BLF_api.h"
#include "BLT_translation.h"
#include "UI_interface.h"
+#include "UI_interface_icons.h"
#include "IMB_imbuf.h"
#include "WM_api.h"
#include "WM_types.h"
-#include "wm_subwindow.h"
+#include "WM_message.h"
#include "RNA_access.h"
#include "BPY_extern.h"
+#include "ED_screen.h"
+
#include "IMB_colormanagement.h"
+#include "DEG_depsgraph_query.h"
+
#include "interface_intern.h"
/* avoid unneeded calls to ui_but_value_get */
@@ -216,6 +224,26 @@ void ui_region_to_window(const ARegion *ar, int *x, int *y)
*y += ar->winrct.ymin;
}
+static void ui_update_window_matrix(const wmWindow *window, const ARegion *region, uiBlock *block)
+{
+ /* window matrix and aspect */
+ if (region && region->visible) {
+ /* Get projection matrix which includes View2D translation and zoom. */
+ gpuGetProjectionMatrix(block->winmat);
+ block->aspect = 2.0f / fabsf(region->winx * block->winmat[0][0]);
+ }
+ else {
+ /* No subwindow created yet, for menus for example, so we use the main
+ * window instead, since buttons are created there anyway. */
+ int width = WM_window_pixels_x(window);
+ int height = WM_window_pixels_y(window);
+ rcti winrct = {0, width - 1, 0, height - 1};
+
+ wmGetProjectionMatrix(block->winmat, &winrct);
+ block->aspect = 2.0f / fabsf(width * block->winmat[0][0]);
+ }
+}
+
/**
* Popups will add a margin to #ARegion.winrct for shadow,
* for interactivity (point-inside tests for eg), we want the winrct without the margin added.
@@ -502,86 +530,6 @@ static int ui_but_calc_float_precision(uiBut *but, double value)
return UI_calc_float_precision(prec, value);
}
-/* ************** LINK LINE DRAWING ************* */
-
-/* link line drawing is not part of buttons or theme.. so we stick with it here */
-
-static void ui_draw_linkline(uiLinkLine *line, int highlightActiveLines, int dashInactiveLines)
-{
- rcti rect;
-
- if (line->from == NULL || line->to == NULL) return;
-
- rect.xmin = BLI_rctf_cent_x(&line->from->rect);
- rect.ymin = BLI_rctf_cent_y(&line->from->rect);
- rect.xmax = BLI_rctf_cent_x(&line->to->rect);
- rect.ymax = BLI_rctf_cent_y(&line->to->rect);
-
- if (dashInactiveLines)
- UI_ThemeColor(TH_GRID);
- else if (line->flag & UI_SELECT)
- glColor3ub(100, 100, 100);
- else if (highlightActiveLines && ((line->from->flag & UI_ACTIVE) || (line->to->flag & UI_ACTIVE)))
- UI_ThemeColor(TH_TEXT_HI);
- else
- glColor3ub(0, 0, 0);
-
- ui_draw_link_bezier(&rect);
-}
-
-static void ui_draw_links(uiBlock *block)
-{
- uiBut *but;
- uiLinkLine *line;
-
- /* Draw the gray out lines. Do this first so they appear at the
- * bottom of inactive or active lines.
- * As we go, remember if we see any active or selected lines. */
- bool found_selectline = false;
- bool found_activeline = false;
-
- for (but = block->buttons.first; but; but = but->next) {
- if (but->type == UI_BTYPE_LINK && but->link) {
- for (line = but->link->lines.first; line; line = line->next) {
- if (!(line->from->flag & UI_ACTIVE) && !(line->to->flag & UI_ACTIVE)) {
- if (line->deactive)
- ui_draw_linkline(line, 0, true);
- }
- else
- found_activeline = true;
-
- if ((line->from->flag & UI_SELECT) || (line->to->flag & UI_SELECT))
- found_selectline = true;
- }
- }
- }
-
- /* Draw the inactive lines (lines with neither button being hovered over) */
- for (but = block->buttons.first; but; but = but->next) {
- if (but->type == UI_BTYPE_LINK && but->link) {
- for (line = but->link->lines.first; line; line = line->next) {
- if (!(line->from->flag & UI_ACTIVE) && !(line->to->flag & UI_ACTIVE)) {
- if (!line->deactive)
- ui_draw_linkline(line, 0, false);
- }
- }
- }
- }
-
- /* Draw any active lines (lines with either button being hovered over).
- * Do this last so they appear on top of inactive and gray out lines. */
- if (found_activeline) {
- for (but = block->buttons.first; but; but = but->next) {
- if (but->type == UI_BTYPE_LINK && but->link) {
- for (line = but->link->lines.first; line; line = line->next) {
- if ((line->from->flag & UI_ACTIVE) || (line->to->flag & UI_ACTIVE))
- ui_draw_linkline(line, !found_selectline, false);
- }
- }
- }
- }
-}
-
/* ************** BLOCK ENDING FUNCTION ************* */
/* NOTE: if but->poin is allocated memory for every defbut, things fail... */
@@ -624,38 +572,6 @@ uiBut *ui_but_find_new(uiBlock *block_new, const uiBut *but_old)
return but_new;
}
-/* oldbut is being inserted in new block, so we use the lines from new button, and replace button pointers */
-static void ui_but_update_linklines(uiBlock *block, uiBut *oldbut, uiBut *newbut)
-{
- uiLinkLine *line;
- uiBut *but;
-
- /* if active button is UI_BTYPE_LINK */
- if (newbut->type == UI_BTYPE_LINK && newbut->link) {
-
- SWAP(uiLink *, oldbut->link, newbut->link);
-
- for (line = oldbut->link->lines.first; line; line = line->next) {
- if (line->to == newbut)
- line->to = oldbut;
- if (line->from == newbut)
- line->from = oldbut;
- }
- }
-
- /* check all other button links */
- for (but = block->buttons.first; but; but = but->next) {
- if (but != newbut && but->type == UI_BTYPE_LINK && but->link) {
- for (line = but->link->lines.first; line; line = line->next) {
- if (line->to == newbut)
- line->to = oldbut;
- if (line->from == newbut)
- line->from = oldbut;
- }
- }
- }
-}
-
/**
* \return true when \a but_p is set (only done for active buttons).
*/
@@ -712,8 +628,6 @@ static bool ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBu
but->selend = oldbut->selend;
but->softmin = oldbut->softmin;
but->softmax = oldbut->softmax;
- but->linkto[0] = oldbut->linkto[0];
- but->linkto[1] = oldbut->linkto[1];
oldbut->active = NULL;
#endif
@@ -755,8 +669,6 @@ static bool ui_but_update_from_old_block(const bContext *C, uiBlock *block, uiBu
oldbut->a1 = but->a1;
}
- ui_but_update_linklines(block, oldbut, but);
-
if (!BLI_listbase_is_empty(&block->butstore)) {
UI_butstore_register_update(block, oldbut, but);
}
@@ -1214,6 +1126,18 @@ static void ui_menu_block_set_keymaps(const bContext *C, uiBlock *block)
}
}
+void ui_but_override_flag(uiBut *but)
+{
+ const int override_status = RNA_property_override_status(&but->rnapoin, but->rnaprop, but->rnaindex);
+
+ if (override_status & RNA_OVERRIDE_STATUS_OVERRIDDEN) {
+ but->flag |= UI_BUT_OVERRIDEN;
+ }
+ else {
+ but->flag &= ~UI_BUT_OVERRIDEN;
+ }
+}
+
void UI_block_update_from_old(const bContext *C, uiBlock *block)
{
uiBut *but_old;
@@ -1278,6 +1202,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x
}
ui_but_anim_flag(but, (scene) ? scene->r.cfra : 0.0f);
+ ui_but_override_flag(but);
}
@@ -1286,7 +1211,7 @@ void UI_block_end_ex(const bContext *C, uiBlock *block, const int xy[2], int r_x
if (block->layouts.first) {
UI_block_layout_resolve(block, NULL, NULL);
}
- ui_block_align_calc(block);
+ ui_block_align_calc(block, CTX_wm_region(C));
if ((block->flag & UI_BLOCK_LOOP) && (block->flag & UI_BLOCK_NUMSELECT)) {
ui_menu_block_set_keyaccels(block); /* could use a different flag to check */
}
@@ -1372,7 +1297,6 @@ void UI_block_draw(const bContext *C, uiBlock *block)
ARegion *ar;
uiBut *but;
rcti rect;
- int multisample_enabled;
/* get menu region or area region */
ar = CTX_wm_menu(C);
@@ -1382,13 +1306,8 @@ void UI_block_draw(const bContext *C, uiBlock *block)
if (!block->endblock)
UI_block_end(C, block);
- /* disable AA, makes widgets too blurry */
- multisample_enabled = glIsEnabled(GL_MULTISAMPLE);
- if (multisample_enabled)
- glDisable(GL_MULTISAMPLE);
-
/* we set this only once */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* scale fonts */
ui_fontscale(&style.paneltitle.points, block->aspect);
@@ -1400,22 +1319,26 @@ void UI_block_draw(const bContext *C, uiBlock *block)
ui_but_to_pixelrect(&rect, ar, block, NULL);
/* pixel space for AA widgets */
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ gpuPushProjectionMatrix();
+ gpuPushMatrix();
+ gpuLoadIdentity();
wmOrtho2_region_pixelspace(ar);
/* back */
if (block->flag & UI_BLOCK_RADIAL)
ui_draw_pie_center(block);
+ else if (block->flag & UI_BLOCK_POPOVER)
+ ui_draw_popover_back(ar, &style, block, &rect);
else if (block->flag & UI_BLOCK_LOOP)
ui_draw_menu_back(&style, block, &rect);
else if (block->panel)
ui_draw_aligned_panel(&style, block, &rect, UI_panel_category_is_visible(ar));
+ BLF_batch_draw_begin();
+ UI_icon_draw_cache_begin();
+ UI_widgetbase_draw_cache_begin();
+
/* widgets */
for (but = block->buttons.first; but; but = but->next) {
if (!(but->flag & (UI_HIDDEN | UI_SCROLLED))) {
@@ -1427,17 +1350,48 @@ void UI_block_draw(const bContext *C, uiBlock *block)
ui_draw_but(C, ar, &style, but, &rect);
}
}
+
+ UI_widgetbase_draw_cache_end();
+ UI_icon_draw_cache_end();
+ BLF_batch_draw_end();
/* restore matrix */
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
+ gpuPopProjectionMatrix();
+ gpuPopMatrix();
+}
+
+static void ui_block_message_subscribe(ARegion *ar, struct wmMsgBus *mbus, uiBlock *block)
+{
+ uiBut *but_prev = NULL;
+ /* possibly we should keep the region this block is contained in? */
+ for (uiBut *but = block->buttons.first; but; but = but->next) {
+ if (but->rnapoin.type && but->rnaprop) {
+ /* quick check to avoid adding buttons representing a vector, multiple times. */
+ if ((but_prev &&
+ (but_prev->rnaprop == but->rnaprop) &&
+ (but_prev->rnapoin.type == but->rnapoin.type) &&
+ (but_prev->rnapoin.data == but->rnapoin.data) &&
+ (but_prev->rnapoin.id.data == but->rnapoin.id.data)) == false)
+ {
+ /* TODO: could make this into utility function. */
+ WM_msg_subscribe_rna(
+ mbus, &but->rnapoin, but->rnaprop,
+ &(const wmMsgSubscribeValue){
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ }, __func__);
+ but_prev = but;
+ }
+ }
+ }
+}
- if (multisample_enabled)
- glEnable(GL_MULTISAMPLE);
-
- ui_draw_links(block);
+void UI_region_message_subscribe(ARegion *ar, struct wmMsgBus *mbus)
+{
+ for (uiBlock *block = ar->uiblocks.first; block; block = block->next) {
+ ui_block_message_subscribe(ar, mbus, block);
+ }
}
/* ************* EVENTS ************* */
@@ -1495,6 +1449,18 @@ int ui_but_is_pushed_ex(uiBut *but, double *value)
if (*value == (double)but->hardmax) is_push = true;
}
break;
+ case UI_BTYPE_TAB:
+ if (but->rnaprop && but->custom_data) {
+ /* uiBut.custom_data points to data this tab represents (e.g. workspace).
+ * uiBut.rnapoin/prop store an active value (e.g. active workspace). */
+ if (RNA_property_type(but->rnaprop) == PROP_POINTER) {
+ PointerRNA active_ptr = RNA_property_pointer_get(&but->rnapoin, but->rnaprop);
+ if (active_ptr.data == but->custom_data) {
+ is_push = true;
+ }
+ }
+ }
+ break;
default:
is_push = -1;
break;
@@ -1521,83 +1487,6 @@ static void ui_but_update_select_flag(uiBut *but, double *value)
}
}
-static uiBut *ui_linkline_find_inlink(uiBlock *block, void *poin)
-{
- uiBut *but;
-
- but = block->buttons.first;
- while (but) {
- if (but->type == UI_BTYPE_INLINK) {
- if (but->poin == poin) return but;
- }
- but = but->next;
- }
- return NULL;
-}
-
-static void ui_linkline_add(ListBase *listb, uiBut *but, uiBut *bt, short deactive)
-{
- uiLinkLine *line;
-
- line = MEM_callocN(sizeof(uiLinkLine), "linkline");
- BLI_addtail(listb, line);
- line->from = but;
- line->to = bt;
- line->deactive = deactive;
-}
-
-uiBut *UI_block_links_find_inlink(uiBlock *block, void *poin)
-{
- return ui_linkline_find_inlink(block, poin);
-}
-
-void UI_block_links_compose(uiBlock *block)
-{
- uiBut *but, *bt;
- uiLink *link;
- void ***ppoin;
- int a;
-
- but = block->buttons.first;
- while (but) {
- if (but->type == UI_BTYPE_LINK) {
- link = but->link;
-
- /* for all pointers in the array */
- if (link) {
- if (link->ppoin) {
- ppoin = link->ppoin;
- for (a = 0; a < *(link->totlink); a++) {
- bt = ui_linkline_find_inlink(block, (*ppoin)[a]);
- if (bt) {
- if ((but->flag & UI_BUT_SCA_LINK_GREY) || (bt->flag & UI_BUT_SCA_LINK_GREY)) {
- ui_linkline_add(&link->lines, but, bt, true);
- }
- else {
- ui_linkline_add(&link->lines, but, bt, false);
- }
-
- }
- }
- }
- else if (link->poin) {
- bt = ui_linkline_find_inlink(block, *link->poin);
- if (bt) {
- if ((but->flag & UI_BUT_SCA_LINK_GREY) || (bt->flag & UI_BUT_SCA_LINK_GREY)) {
- ui_linkline_add(&link->lines, but, bt, true);
- }
- else {
- ui_linkline_add(&link->lines, but, bt, false);
- }
- }
- }
- }
- }
- but = but->next;
- }
-}
-
-
/* ************************************************ */
void UI_block_lock_set(uiBlock *block, bool val, const char *lockstr)
@@ -1614,48 +1503,78 @@ void UI_block_lock_clear(uiBlock *block)
block->lockstr = NULL;
}
-/* *************************************************************** */
-
-void ui_linkline_remove(uiLinkLine *line, uiBut *but)
-{
- uiLink *link;
- int a, b;
-
- BLI_remlink(&but->link->lines, line);
-
- link = line->from->link;
+/* *********************** data get/set ***********************
+ * this either works with the pointed to data, or can work with
+ * an edit override pointer while dragging for example */
- /* are there more pointers allowed? */
- if (link->ppoin) {
-
- if (*(link->totlink) == 1) {
- *(link->totlink) = 0;
- MEM_freeN(*(link->ppoin));
- *(link->ppoin) = NULL;
- }
- else {
- b = 0;
- for (a = 0; a < (*(link->totlink)); a++) {
- if ((*(link->ppoin))[a] != line->to->poin) {
- (*(link->ppoin))[b] = (*(link->ppoin))[a];
- b++;
- }
- }
- (*(link->totlink))--;
+/* Get PointerRNA which will point to a data inside of an evaluated
+ * ID datablock.
+ */
+static PointerRNA ui_but_evaluated_rnapoin_get(uiBut *but)
+{
+ BLI_assert(but->rnaprop != NULL);
+ /* TODO(sergey): evil_C sounds.. EVIL! Any clear way to avoid this? */
+ PointerRNA rnapoin_eval = but->rnapoin;
+ /* If there is no animation or drivers, it doesn't matter if we read value
+ * from evaluated datablock or from original one.
+ *
+ * Reading from original one is much faster, since we don't need to do any
+ * PointerRNA remapping or hash lookup.
+ */
+ if (BKE_animdata_from_id(but->rnapoin.id.data) == NULL) {
+ return rnapoin_eval;
+ }
+ /* Same goes for the properties which can not be animated. */
+ if (!RNA_property_animateable(&but->rnapoin, but->rnaprop)) {
+ return rnapoin_eval;
+ }
+ Depsgraph *depsgraph = CTX_data_depsgraph(but->block->evil_C);
+ /* ID pointer we can always remap, they are inside of depsgraph. */
+ rnapoin_eval.id.data =
+ DEG_get_evaluated_id(depsgraph, rnapoin_eval.id.data);
+ /* Some of ID datablocks do not have their evaluated copy inside
+ * of dependency graph. If it's such datablock, no need to worry about
+ * data pointer.
+ */
+ if (rnapoin_eval.id.data == but->rnapoin.id.data) {
+ return rnapoin_eval;
+ }
+ /* For the data pointer it's getting a bit more involved, since it can
+ * whether be and ID, or can be a property deep inside of ID.
+ *
+ * We start from checking if it's an ID, since that is the less involved
+ * code path, and probably is executed in most of the cases.
+ */
+ if (but->rnapoin.data == but->rnapoin.id.data) {
+ rnapoin_eval.data = DEG_get_evaluated_id(depsgraph, rnapoin_eval.data);
+ return rnapoin_eval;
+ }
+ /* We aren't as lucky as we thought we are :(
+ *
+ * Since we don't know what the property is, we get it's RNA path
+ * relative to the original ID, and then we decent down from evaluated
+ * ID to the same property.
+ *
+ * This seems to be most straightforward way to get sub-data pointers
+ * which can be buried deep inside of ID block.
+ */
+ const char *rna_path =
+ RNA_path_from_ID_to_property(&but->rnapoin, but->rnaprop);
+ if (rna_path != NULL) {
+ PointerRNA id_ptr;
+ RNA_id_pointer_create(rnapoin_eval.id.data, &id_ptr);
+ if (!RNA_path_resolve_full(&id_ptr,
+ rna_path,
+ &rnapoin_eval,
+ NULL, NULL))
+ {
+ /* TODO(sergey): Anything to do here to recover? */
}
+ MEM_freeN((void *)rna_path);
}
- else {
- *(link->poin) = NULL;
- }
-
- MEM_freeN(line);
- //REDRAW
+ return rnapoin_eval;
}
-/* *********************** data get/set ***********************
- * this either works with the pointed to data, or can work with
- * an edit override pointer while dragging for example */
-
/* for buttons pointing to color for example */
void ui_but_v3_get(uiBut *but, float vec[3])
{
@@ -1671,16 +1590,18 @@ void ui_but_v3_get(uiBut *but, float vec[3])
zero_v3(vec);
+ PointerRNA rnapoin_eval = ui_but_evaluated_rnapoin_get(but);
+
if (RNA_property_type(prop) == PROP_FLOAT) {
- int tot = RNA_property_array_length(&but->rnapoin, prop);
+ int tot = RNA_property_array_length(&rnapoin_eval, prop);
BLI_assert(tot > 0);
if (tot == 3) {
- RNA_property_float_get_array(&but->rnapoin, prop, vec);
+ RNA_property_float_get_array(&rnapoin_eval, prop, vec);
}
else {
tot = min_ii(tot, 3);
for (a = 0; a < tot; a++) {
- vec[a] = RNA_property_float_get_index(&but->rnapoin, prop, a);
+ vec[a] = RNA_property_float_get_index(&rnapoin_eval, prop, a);
}
}
}
@@ -1860,27 +1781,29 @@ double ui_but_value_get(uiBut *but)
BLI_assert(but->rnaindex != -1);
+ PointerRNA rnapoin_eval = ui_but_evaluated_rnapoin_get(but);
+
switch (RNA_property_type(prop)) {
case PROP_BOOLEAN:
if (RNA_property_array_check(prop))
- value = RNA_property_boolean_get_index(&but->rnapoin, prop, but->rnaindex);
+ value = RNA_property_boolean_get_index(&rnapoin_eval, prop, but->rnaindex);
else
- value = RNA_property_boolean_get(&but->rnapoin, prop);
+ value = RNA_property_boolean_get(&rnapoin_eval, prop);
break;
case PROP_INT:
if (RNA_property_array_check(prop))
- value = RNA_property_int_get_index(&but->rnapoin, prop, but->rnaindex);
+ value = RNA_property_int_get_index(&rnapoin_eval, prop, but->rnaindex);
else
- value = RNA_property_int_get(&but->rnapoin, prop);
+ value = RNA_property_int_get(&rnapoin_eval, prop);
break;
case PROP_FLOAT:
if (RNA_property_array_check(prop))
- value = RNA_property_float_get_index(&but->rnapoin, prop, but->rnaindex);
+ value = RNA_property_float_get_index(&rnapoin_eval, prop, but->rnaindex);
else
- value = RNA_property_float_get(&but->rnapoin, prop);
+ value = RNA_property_float_get(&rnapoin_eval, prop);
break;
case PROP_ENUM:
- value = RNA_property_enum_get(&but->rnapoin, prop);
+ value = RNA_property_enum_get(&rnapoin_eval, prop);
break;
default:
value = 0.0;
@@ -2023,7 +1946,7 @@ static bool ui_but_icon_extra_is_visible_text_clear(const uiBut *but)
static bool ui_but_icon_extra_is_visible_search_unlink(const uiBut *but)
{
- BLI_assert(but->type == UI_BTYPE_SEARCH_MENU);
+ BLI_assert(ELEM(but->type, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB));
return ((but->editstr == NULL) &&
(but->drawstr[0] != '\0') &&
(but->flag & UI_BUT_VALUE_CLEAR));
@@ -2066,6 +1989,11 @@ uiButExtraIconType ui_but_icon_extra_get(uiBut *but)
return UI_BUT_ICONEXTRA_EYEDROPPER;
}
break;
+ case UI_BTYPE_TAB:
+ if (ui_but_icon_extra_is_visible_search_unlink(but)) {
+ return UI_BUT_ICONEXTRA_CLEAR;
+ }
+ break;
default:
break;
}
@@ -2179,14 +2107,23 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int
*r_use_exp_float = false;
}
- if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
+ if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU, UI_BTYPE_TAB)) {
PropertyType type;
const char *buf = NULL;
int buf_len;
type = RNA_property_type(but->rnaprop);
- if (type == PROP_STRING) {
+ if ((but->type == UI_BTYPE_TAB) && (but->custom_data)) {
+ StructRNA *ptr_type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop);
+ PointerRNA ptr;
+
+ /* uiBut.custom_data points to data this tab represents (e.g. workspace).
+ * uiBut.rnapoin/prop store an active value (e.g. active workspace). */
+ RNA_pointer_create(but->rnapoin.id.data, ptr_type, but->custom_data, &ptr);
+ buf = RNA_struct_name_get_alloc(&ptr, str, maxlen, &buf_len);
+ }
+ else if (type == PROP_STRING) {
/* RNA string */
buf = RNA_property_string_get_alloc(&but->rnapoin, but->rnaprop, str, maxlen, &buf_len);
}
@@ -2222,12 +2159,7 @@ void ui_but_string_get_ex(uiBut *but, char *str, const size_t maxlen, const int
MEM_freeN((void *)buf);
}
}
- else if (but->type == UI_BTYPE_TEXT) {
- /* string */
- BLI_strncpy(str, but->poin, maxlen);
- return;
- }
- else if (but->type == UI_BTYPE_SEARCH_MENU) {
+ else if (ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
/* string */
BLI_strncpy(str, but->poin, maxlen);
return;
@@ -2425,7 +2357,7 @@ static void ui_but_string_free_internal(uiBut *but)
bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
{
- if (but->rnaprop && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
+ if (but->rnaprop && but->rnapoin.data && ELEM(but->type, UI_BTYPE_TEXT, UI_BTYPE_SEARCH_MENU)) {
if (RNA_property_editable(&but->rnapoin, but->rnaprop)) {
PropertyType type;
@@ -2437,18 +2369,16 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
return true;
}
else if (type == PROP_POINTER) {
- /* RNA pointer */
- PointerRNA ptr, rptr;
- PropertyRNA *prop;
-
if (str[0] == '\0') {
RNA_property_pointer_set(&but->rnapoin, but->rnaprop, PointerRNA_NULL);
return true;
}
else {
- ptr = but->rnasearchpoin;
- prop = but->rnasearchprop;
-
+ /* RNA pointer */
+ PointerRNA rptr;
+ PointerRNA ptr = but->rnasearchpoin;
+ PropertyRNA *prop = but->rnasearchprop;
+
if (prop && RNA_property_collection_lookup_string(&ptr, prop, str, &rptr))
RNA_property_pointer_set(&but->rnapoin, but->rnaprop, rptr);
@@ -2470,10 +2400,32 @@ bool ui_but_string_set(bContext *C, uiBut *but, const char *str)
}
}
}
+ else if (but->type == UI_BTYPE_TAB) {
+ if (but->rnaprop && but->custom_data) {
+ StructRNA *ptr_type = RNA_property_pointer_type(&but->rnapoin, but->rnaprop);
+ PointerRNA ptr;
+ PropertyRNA *prop;
+
+ /* uiBut.custom_data points to data this tab represents (e.g. workspace).
+ * uiBut.rnapoin/prop store an active value (e.g. active workspace). */
+ RNA_pointer_create(but->rnapoin.id.data, ptr_type, but->custom_data, &ptr);
+ prop = RNA_struct_name_property(ptr_type);
+ if (RNA_property_editable(&ptr, prop)) {
+ RNA_property_string_set(&ptr, prop, str);
+ }
+ }
+ }
else if (but->type == UI_BTYPE_TEXT) {
/* string */
- if (ui_but_is_utf8(but)) BLI_strncpy_utf8(but->poin, str, but->hardmax);
- else BLI_strncpy(but->poin, str, but->hardmax);
+ if (!but->poin || (str[0] == '\0')) {
+ str = "";
+ }
+ else if (ui_but_is_utf8(but)) {
+ BLI_strncpy_utf8(but->poin, str, but->hardmax);
+ }
+ else {
+ BLI_strncpy(but->poin, str, but->hardmax);
+ }
return true;
}
@@ -2657,14 +2609,6 @@ static void ui_set_but_soft_range(uiBut *but)
/* ******************* Free ********************/
-static void ui_free_link(uiLink *link)
-{
- if (link) {
- BLI_freelistN(&link->lines);
- MEM_freeN(link);
- }
-}
-
/* can be called with C==NULL */
static void ui_but_free(const bContext *C, uiBut *but)
{
@@ -2685,6 +2629,10 @@ static void ui_but_free(const bContext *C, uiBut *but)
MEM_freeN(but->hold_argN);
}
+ if (!but->editstr && but->free_search_arg) {
+ MEM_SAFE_FREE(but->search_arg);
+ }
+
if (but->active) {
/* XXX solve later, buttons should be free-able without context ideally,
* however they may have open tooltips or popup windows, which need to
@@ -2701,7 +2649,6 @@ static void ui_but_free(const bContext *C, uiBut *but)
if (but->str && but->str != but->strdata) {
MEM_freeN(but->str);
}
- ui_free_link(but->link);
if ((but->type == UI_BTYPE_IMAGE) && but->poin) {
IMB_freeImBuf((struct ImBuf *)but->poin);
@@ -2743,6 +2690,27 @@ void UI_block_free(const bContext *C, uiBlock *block)
MEM_freeN(block);
}
+void UI_blocklist_update_window_matrix(const bContext *C, const ListBase *lb)
+{
+ ARegion *region = CTX_wm_region(C);
+ wmWindow *window = CTX_wm_window(C);
+
+ for (uiBlock *block = lb->first; block; block = block->next) {
+ if (block->active) {
+ ui_update_window_matrix(window, region, block);
+ }
+ }
+}
+
+void UI_blocklist_draw(const bContext *C, const ListBase *lb)
+{
+ for (uiBlock *block = lb->first; block; block = block->next) {
+ if (block->active) {
+ UI_block_draw(C, block);
+ }
+ }
+}
+
/* can be called with C==NULL */
void UI_blocklist_free(const bContext *C, ListBase *lb)
{
@@ -2799,7 +2767,6 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, sh
uiBlock *block;
wmWindow *window;
Scene *scn;
- int getsizex, getsizey;
window = CTX_wm_window(C);
scn = CTX_data_scene(C);
@@ -2829,23 +2796,13 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, sh
if (region)
UI_block_region_set(block, region);
- /* window matrix and aspect */
- if (region && region->swinid) {
- wm_subwindow_matrix_get(window, region->swinid, block->winmat);
- wm_subwindow_size_get(window, region->swinid, &getsizex, &getsizey);
-
- block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
- }
- else {
- /* no subwindow created yet, for menus for example, so we
- * use the main window instead, since buttons are created
- * there anyway */
- wm_subwindow_matrix_get(window, window->screen->mainwin, block->winmat);
- wm_subwindow_size_get(window, window->screen->mainwin, &getsizex, &getsizey);
+ /* Set window matrix and aspect for region and OpenGL state. */
+ ui_update_window_matrix(window, region, block);
- block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
+ /* Tag as popup menu if not created within a region. */
+ if (!(region && region->visible)) {
block->auto_open = true;
- block->flag |= UI_BLOCK_LOOP; /* tag as menu */
+ block->flag |= UI_BLOCK_LOOP;
}
return block;
@@ -3012,6 +2969,7 @@ void ui_but_update_ex(uiBut *but, const bool validate)
case UI_BTYPE_TEXT:
case UI_BTYPE_SEARCH_MENU:
+ case UI_BTYPE_TAB:
if (!but->editstr) {
char str[UI_MAX_DRAW_STR];
@@ -3135,6 +3093,16 @@ void ui_block_cm_to_display_space_range(uiBlock *block, float *min, float *max)
*max = max_fff(UNPACK3(pixel));
}
+static uiBut *ui_but_alloc(const eButType type)
+{
+ switch (type) {
+ case UI_BTYPE_TAB:
+ return MEM_callocN(sizeof(uiButTab), "uiButTab");
+ default:
+ return MEM_callocN(sizeof(uiBut), "uiBut");
+ }
+}
+
/**
* \brief ui_def_but is the function that draws many button types
*
@@ -3168,7 +3136,7 @@ static uiBut *ui_def_but(
}
}
- but = MEM_callocN(sizeof(uiBut), "uiBut");
+ but = ui_but_alloc(type & BUTTYPE);
but->type = type & BUTTYPE;
but->pointype = type & UI_BUT_POIN_TYPES;
@@ -3232,7 +3200,7 @@ static uiBut *ui_def_but(
ELEM(but->type,
UI_BTYPE_MENU, UI_BTYPE_TEXT, UI_BTYPE_LABEL,
UI_BTYPE_BLOCK, UI_BTYPE_BUT_MENU, UI_BTYPE_SEARCH_MENU,
- UI_BTYPE_PROGRESS_BAR))
+ UI_BTYPE_PROGRESS_BAR, UI_BTYPE_POPOVER))
{
but->drawflag |= (UI_BUT_TEXT_LEFT | UI_BUT_ICON_LEFT);
}
@@ -3558,7 +3526,7 @@ static uiBut *ui_def_but_rna(
}
const char *info;
- if (!RNA_property_editable_info(&but->rnapoin, prop, &info)) {
+ if (but->rnapoin.data && !RNA_property_editable_info(&but->rnapoin, prop, &info)) {
ui_def_but_rna__disable(but, info);
}
@@ -3977,19 +3945,6 @@ uiBut *uiDefIconTextButO(uiBlock *block, int type, const char *opname, int opcon
/* END Button containing both string label and icon */
-void UI_but_link_set(uiBut *but, void **poin, void ***ppoin, short *tot, int from, int to)
-{
- uiLink *link;
-
- link = but->link = MEM_callocN(sizeof(uiLink), "new uilink");
-
- link->poin = poin;
- link->ppoin = ppoin;
- link->totlink = tot;
- link->fromcode = from;
- link->tocode = to;
-}
-
/* cruft to make uiBlock and uiBut private */
int UI_blocklist_min_y_get(ListBase *lb)
@@ -4457,7 +4412,7 @@ static void operator_enum_search_cb(const struct bContext *C, void *but, const c
for (item = item_array; item->identifier; item++) {
/* note: need to give the index rather than the identifier because the enum can be freed */
if (BLI_strcasestr(item->name, str)) {
- if (false == UI_search_item_add(items, item->name, SET_INT_IN_POINTER(item->value), 0))
+ if (false == UI_search_item_add(items, item->name, SET_INT_IN_POINTER(item->value), item->icon))
break;
}
}
@@ -4588,7 +4543,7 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
tmp = BLI_strdup(RNA_property_identifier(but->rnaprop));
}
else if (type == BUT_GET_RNASTRUCT_IDENTIFIER) {
- if (but->rnaprop)
+ if (but->rnaprop && but->rnapoin.data)
tmp = BLI_strdup(RNA_struct_identifier(but->rnapoin.type));
else if (but->optype)
tmp = BLI_strdup(but->optype->idname);
@@ -4683,7 +4638,10 @@ void UI_but_string_info_get(bContext *C, uiBut *but, ...)
if (ptr && prop) {
if (!item) {
int i;
-
+
+ /* so the context is passed to itemf functions */
+ WM_operator_properties_sanitize(ptr, false);
+
RNA_property_enum_items_gettexted(C, ptr, prop, &items, &totitems, &free_items);
for (i = 0, item = items; i < totitems; i++, item++) {
if (item->identifier[0] && item->value == value)
diff --git a/source/blender/editors/interface/interface_align.c b/source/blender/editors/interface/interface_align.c
index 500744c366d..1fc38a27303 100644
--- a/source/blender/editors/interface/interface_align.c
+++ b/source/blender/editors/interface/interface_align.c
@@ -110,9 +110,9 @@ enum {
bool ui_but_can_align(const uiBut *but)
{
- return (
- !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_CHECKBOX, UI_BTYPE_CHECKBOX_N, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE) &&
- (BLI_rctf_size_x(&but->rect) > 0.0f) && (BLI_rctf_size_y(&but->rect) > 0.0f));
+ const bool btype_can_align = !ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_CHECKBOX, UI_BTYPE_CHECKBOX_N,
+ UI_BTYPE_TAB, UI_BTYPE_SEPR, UI_BTYPE_SEPR_LINE);
+ return (btype_can_align && (BLI_rctf_size_x(&but->rect) > 0.0f) && (BLI_rctf_size_y(&but->rect) > 0.0f));
}
/**
@@ -320,13 +320,43 @@ static int ui_block_align_butal_cmp(const void *a, const void *b)
return 0;
}
+static void ui_block_align_but_to_region(uiBut *but, const ARegion *region)
+{
+ rctf *rect = &but->rect;
+ const float but_width = BLI_rctf_size_x(rect);
+ const float but_height = BLI_rctf_size_y(rect);
+ const float px = U.pixelsize;
+
+ switch (but->drawflag & UI_BUT_ALIGN) {
+ case UI_BUT_ALIGN_TOP:
+ rect->ymax = region->winy + px;
+ rect->ymin = but->rect.ymax - but_height;
+ break;
+ case UI_BUT_ALIGN_DOWN:
+ rect->ymin = -px;
+ rect->ymax = rect->ymin + but_height;
+ break;
+ case UI_BUT_ALIGN_LEFT:
+ rect->xmin = -px;
+ rect->xmax = rect->xmin + but_width;
+ break;
+ case UI_BUT_ALIGN_RIGHT:
+ rect->xmax = region->winx + px;
+ rect->xmin = rect->xmax - but_width;
+ break;
+ default:
+ BLI_assert(0);
+ break;
+ }
+}
+
/**
* Compute the alignment of all 'align groups' of buttons in given block.
*
* This is using an order-independent algorithm, i.e. alignment of buttons should be OK regardless of order in which
* they are added to the block.
*/
-void ui_block_align_calc(uiBlock *block)
+void ui_block_align_calc(uiBlock *block, const ARegion *region)
{
uiBut *but;
int num_buttons = 0;
@@ -338,10 +368,17 @@ void ui_block_align_calc(uiBlock *block)
int side;
int i, j;
- /* First loop: we count number of buttons belonging to an align group, and clear their align flag. */
+ /* First loop: we count number of buttons belonging to an align group, and clear their align flag.
+ * Tabs get some special treatment here, they get aligned to region border. */
for (but = block->buttons.first; but; but = but->next) {
- /* Clear old align flags. */
- but->drawflag &= ~UI_BUT_ALIGN_ALL;
+ /* special case: tabs need to be aligned to a region border, drawflag tells which one */
+ if (but->type == UI_BTYPE_TAB) {
+ ui_block_align_but_to_region(but, region);
+ }
+ else {
+ /* Clear old align flags. */
+ but->drawflag &= ~UI_BUT_ALIGN_ALL;
+ }
if (but->alignnr != 0) {
num_buttons++;
diff --git a/source/blender/editors/interface/interface_anim.c b/source/blender/editors/interface/interface_anim.c
index a04360b3395..812f4ef0747 100644
--- a/source/blender/editors/interface/interface_anim.c
+++ b/source/blender/editors/interface/interface_anim.c
@@ -39,11 +39,12 @@
#include "BLI_utildefines.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_nla.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_keyframing.h"
#include "UI_interface.h"
@@ -211,7 +212,7 @@ bool ui_but_anim_expression_create(uiBut *but, const char *str)
/* updates */
driver->flag |= DRIVER_FLAG_RECOMPILE;
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME, NULL);
ok = true;
}
diff --git a/source/blender/editors/interface/interface_draw.c b/source/blender/editors/interface/interface_draw.c
index 7583dc654bb..ce22dac9e91 100644
--- a/source/blender/editors/interface/interface_draw.c
+++ b/source/blender/editors/interface/interface_draw.c
@@ -50,19 +50,21 @@
#include "IMB_imbuf_types.h"
#include "IMB_colormanagement.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
#include "BLF_api.h"
-#include "GPU_draw.h"
-#include "GPU_basic_shader.h"
+#include "GPU_batch.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
#include "UI_interface.h"
/* own include */
#include "interface_intern.h"
+
static int roundboxtype = UI_CNR_ALL;
void UI_draw_roundbox_corner_set(int type)
@@ -71,336 +73,558 @@ void UI_draw_roundbox_corner_set(int type)
* if this is undone, it's not that big a deal, only makes curves edges
* square for the */
roundboxtype = type;
-
}
+#if 0 /* unused */
int UI_draw_roundbox_corner_get(void)
{
return roundboxtype;
}
+#endif
+
+void UI_draw_roundbox_3ubAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const unsigned char col[3], unsigned char alpha)
+{
+ float colv[4];
+ colv[0] = ((float)col[0]) / 255;
+ colv[1] = ((float)col[1]) / 255;
+ colv[2] = ((float)col[2]) / 255;
+ colv[3] = ((float)alpha) / 255;
+ UI_draw_roundbox_4fv(filled, minx, miny, maxx, maxy, rad, colv);
+}
-void UI_draw_roundbox_gl_mode(int mode, float minx, float miny, float maxx, float maxy, float rad)
+void UI_draw_roundbox_3fvAlpha(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[3], float alpha)
{
+ float colv[4];
+ colv[0] = col[0];
+ colv[1] = col[1];
+ colv[2] = col[2];
+ colv[3] = alpha;
+ UI_draw_roundbox_4fv(filled, minx, miny, maxx, maxy, rad, colv);
+}
+
+void UI_draw_roundbox_aa(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float color[4])
+{
+ uiWidgetBaseParameters widget_params = {
+ .recti.xmin = minx, .recti.ymin = miny,
+ .recti.xmax = maxx, .recti.ymax = maxy,
+ .radi = rad,
+ .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f,
+ .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f,
+ .color_inner1[0] = color[0], .color_inner2[0] = color[0],
+ .color_inner1[1] = color[1], .color_inner2[1] = color[1],
+ .color_inner1[2] = color[2], .color_inner2[2] = color[2],
+ .color_inner1[3] = color[3], .color_inner2[3] = color[3],
+ .alpha_discard = 1.0f,
+ };
+
+ glEnable(GL_BLEND);
+
+ if (filled) {
+ /* plain antialiased filled box */
+ widget_params.color_inner1[3] *= 0.125f;
+ widget_params.color_inner2[3] *= 0.125f;
+
+ /* WATCH: This is assuming the ModelViewProjectionMatrix is area pixel space.
+ * If it has been scaled, then it's no longer valid. */
+ Gwn_Batch *batch = ui_batch_roundbox_get(filled, true);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
+ GWN_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&widget_params);
+ GWN_batch_draw(batch);
+ }
+ else {
+ /* plain antialiased unfilled box */
+ glEnable(GL_LINE_SMOOTH);
+
+ Gwn_Batch *batch = ui_batch_roundbox_get(filled, false);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
+ GWN_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&widget_params);
+ GWN_batch_draw(batch);
+
+ glDisable(GL_LINE_SMOOTH);
+ }
+
+ glDisable(GL_BLEND);
+}
+
+void UI_draw_roundbox_4fv(bool filled, float minx, float miny, float maxx, float maxy, float rad, const float col[4])
+{
+#if 0
float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
{0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
int a;
-
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
/* mult */
for (a = 0; a < 7; a++) {
mul_v2_fl(vec[a], rad);
}
- glBegin(mode);
+ unsigned int vert_ct = 0;
+ vert_ct += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 9 : 1;
+ vert_ct += (roundboxtype & UI_CNR_TOP_RIGHT) ? 9 : 1;
+ vert_ct += (roundboxtype & UI_CNR_TOP_LEFT) ? 9 : 1;
+ vert_ct += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 9 : 1;
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv(col);
+
+ immBegin(filled ? GWN_PRIM_TRI_FAN : GWN_PRIM_LINE_LOOP, vert_ct);
/* start with corner right-bottom */
if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
- glVertex2f(maxx - rad, miny);
+ immVertex2f(pos, maxx - rad, miny);
for (a = 0; a < 7; a++) {
- glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]);
+ immVertex2f(pos, maxx - rad + vec[a][0], miny + vec[a][1]);
}
- glVertex2f(maxx, miny + rad);
+ immVertex2f(pos, maxx, miny + rad);
}
else {
- glVertex2f(maxx, miny);
+ immVertex2f(pos, maxx, miny);
}
/* corner right-top */
if (roundboxtype & UI_CNR_TOP_RIGHT) {
- glVertex2f(maxx, maxy - rad);
+ immVertex2f(pos, maxx, maxy - rad);
for (a = 0; a < 7; a++) {
- glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]);
+ immVertex2f(pos, maxx - vec[a][1], maxy - rad + vec[a][0]);
}
- glVertex2f(maxx - rad, maxy);
+ immVertex2f(pos, maxx - rad, maxy);
}
else {
- glVertex2f(maxx, maxy);
+ immVertex2f(pos, maxx, maxy);
}
/* corner left-top */
if (roundboxtype & UI_CNR_TOP_LEFT) {
- glVertex2f(minx + rad, maxy);
+ immVertex2f(pos, minx + rad, maxy);
for (a = 0; a < 7; a++) {
- glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]);
+ immVertex2f(pos, minx + rad - vec[a][0], maxy - vec[a][1]);
}
- glVertex2f(minx, maxy - rad);
+ immVertex2f(pos, minx, maxy - rad);
}
else {
- glVertex2f(minx, maxy);
+ immVertex2f(pos, minx, maxy);
}
/* corner left-bottom */
if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
- glVertex2f(minx, miny + rad);
+ immVertex2f(pos, minx, miny + rad);
for (a = 0; a < 7; a++) {
- glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]);
+ immVertex2f(pos, minx + vec[a][1], miny + rad - vec[a][0]);
}
- glVertex2f(minx + rad, miny);
+ immVertex2f(pos, minx + rad, miny);
}
else {
- glVertex2f(minx, miny);
+ immVertex2f(pos, minx, miny);
}
- glEnd();
+ immEnd();
+ immUnbindProgram();
+#endif
+
+ uiWidgetBaseParameters widget_params = {
+ .recti.xmin = minx, .recti.ymin = miny,
+ .recti.xmax = maxx, .recti.ymax = maxy,
+ .radi = rad,
+ .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f,
+ .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f,
+ .color_inner1[0] = col[0], .color_inner2[0] = col[0],
+ .color_inner1[1] = col[1], .color_inner2[1] = col[1],
+ .color_inner1[2] = col[2], .color_inner2[2] = col[2],
+ .color_inner1[3] = col[3], .color_inner2[3] = col[3],
+ .alpha_discard = 1.0f,
+ };
+
+ Gwn_Batch *batch = ui_batch_roundbox_get(filled, false);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
+ GWN_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&widget_params);
+ GWN_batch_draw(batch);
}
-static void round_box_shade_col(const float col1[3], float const col2[3], const float fac)
+#if 0
+static void round_box_shade_col(unsigned attrib, const float col1[3], float const col2[3], const float fac)
{
- float col[3] = {
+ float col[4] = {
fac * col1[0] + (1.0f - fac) * col2[0],
fac * col1[1] + (1.0f - fac) * col2[1],
- fac * col1[2] + (1.0f - fac) * col2[2]
+ fac * col1[2] + (1.0f - fac) * col2[2],
+ 1.0f
};
- glColor3fv(col);
+ immAttrib4fv(attrib, col);
}
+#endif
/* linear horizontal shade within button or in outline */
/* view2d scrollers use it */
void UI_draw_roundbox_shade_x(
- int mode, float minx, float miny, float maxx, float maxy,
- float rad, float shadetop, float shadedown)
+ bool filled, float minx, float miny, float maxx, float maxy,
+ float rad, float shadetop, float shadedown, const float col[4])
{
+#if 0
float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
{0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
const float div = maxy - miny;
const float idiv = 1.0f / div;
- float coltop[3], coldown[3], color[4];
+ float coltop[3], coldown[3];
+ int vert_count = 0;
int a;
-
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+
/* mult */
for (a = 0; a < 7; a++) {
mul_v2_fl(vec[a], rad);
}
- /* get current color, needs to be outside of glBegin/End */
- glGetFloatv(GL_CURRENT_COLOR, color);
/* 'shade' defines strength of shading */
- coltop[0] = min_ff(1.0f, color[0] + shadetop);
- coltop[1] = min_ff(1.0f, color[1] + shadetop);
- coltop[2] = min_ff(1.0f, color[2] + shadetop);
- coldown[0] = max_ff(0.0f, color[0] + shadedown);
- coldown[1] = max_ff(0.0f, color[1] + shadedown);
- coldown[2] = max_ff(0.0f, color[2] + shadedown);
+ coltop[0] = min_ff(1.0f, col[0] + shadetop);
+ coltop[1] = min_ff(1.0f, col[1] + shadetop);
+ coltop[2] = min_ff(1.0f, col[2] + shadetop);
+ coldown[0] = max_ff(0.0f, col[0] + shadedown);
+ coldown[1] = max_ff(0.0f, col[1] + shadedown);
+ coldown[2] = max_ff(0.0f, col[2] + shadedown);
- glBegin(mode);
+ vert_count += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 9 : 1;
+ vert_count += (roundboxtype & UI_CNR_TOP_RIGHT) ? 9 : 1;
+ vert_count += (roundboxtype & UI_CNR_TOP_LEFT) ? 9 : 1;
+ vert_count += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 9 : 1;
+
+ immBegin(filled ? GWN_PRIM_TRI_FAN : GWN_PRIM_LINE_LOOP, vert_count);
/* start with corner right-bottom */
if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
- round_box_shade_col(coltop, coldown, 0.0);
- glVertex2f(maxx - rad, miny);
+ round_box_shade_col(color, coltop, coldown, 0.0);
+ immVertex2f(pos, maxx - rad, miny);
for (a = 0; a < 7; a++) {
- round_box_shade_col(coltop, coldown, vec[a][1] * idiv);
- glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]);
+ round_box_shade_col(color, coltop, coldown, vec[a][1] * idiv);
+ immVertex2f(pos, maxx - rad + vec[a][0], miny + vec[a][1]);
}
- round_box_shade_col(coltop, coldown, rad * idiv);
- glVertex2f(maxx, miny + rad);
+ round_box_shade_col(color, coltop, coldown, rad * idiv);
+ immVertex2f(pos, maxx, miny + rad);
}
else {
- round_box_shade_col(coltop, coldown, 0.0);
- glVertex2f(maxx, miny);
+ round_box_shade_col(color, coltop, coldown, 0.0);
+ immVertex2f(pos, maxx, miny);
}
/* corner right-top */
if (roundboxtype & UI_CNR_TOP_RIGHT) {
- round_box_shade_col(coltop, coldown, (div - rad) * idiv);
- glVertex2f(maxx, maxy - rad);
+ round_box_shade_col(color, coltop, coldown, (div - rad) * idiv);
+ immVertex2f(pos, maxx, maxy - rad);
for (a = 0; a < 7; a++) {
- round_box_shade_col(coltop, coldown, (div - rad + vec[a][1]) * idiv);
- glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]);
+ round_box_shade_col(color, coltop, coldown, (div - rad + vec[a][1]) * idiv);
+ immVertex2f(pos, maxx - vec[a][1], maxy - rad + vec[a][0]);
}
- round_box_shade_col(coltop, coldown, 1.0);
- glVertex2f(maxx - rad, maxy);
+ round_box_shade_col(color, coltop, coldown, 1.0);
+ immVertex2f(pos, maxx - rad, maxy);
}
else {
- round_box_shade_col(coltop, coldown, 1.0);
- glVertex2f(maxx, maxy);
+ round_box_shade_col(color, coltop, coldown, 1.0);
+ immVertex2f(pos, maxx, maxy);
}
/* corner left-top */
if (roundboxtype & UI_CNR_TOP_LEFT) {
- round_box_shade_col(coltop, coldown, 1.0);
- glVertex2f(minx + rad, maxy);
+ round_box_shade_col(color, coltop, coldown, 1.0);
+ immVertex2f(pos, minx + rad, maxy);
for (a = 0; a < 7; a++) {
- round_box_shade_col(coltop, coldown, (div - vec[a][1]) * idiv);
- glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]);
+ round_box_shade_col(color, coltop, coldown, (div - vec[a][1]) * idiv);
+ immVertex2f(pos, minx + rad - vec[a][0], maxy - vec[a][1]);
}
- round_box_shade_col(coltop, coldown, (div - rad) * idiv);
- glVertex2f(minx, maxy - rad);
+ round_box_shade_col(color, coltop, coldown, (div - rad) * idiv);
+ immVertex2f(pos, minx, maxy - rad);
}
else {
- round_box_shade_col(coltop, coldown, 1.0);
- glVertex2f(minx, maxy);
+ round_box_shade_col(color, coltop, coldown, 1.0);
+ immVertex2f(pos, minx, maxy);
}
/* corner left-bottom */
if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
- round_box_shade_col(coltop, coldown, rad * idiv);
- glVertex2f(minx, miny + rad);
+ round_box_shade_col(color, coltop, coldown, rad * idiv);
+ immVertex2f(pos, minx, miny + rad);
for (a = 0; a < 7; a++) {
- round_box_shade_col(coltop, coldown, (rad - vec[a][1]) * idiv);
- glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]);
+ round_box_shade_col(color, coltop, coldown, (rad - vec[a][1]) * idiv);
+ immVertex2f(pos, minx + vec[a][1], miny + rad - vec[a][0]);
}
- round_box_shade_col(coltop, coldown, 0.0);
- glVertex2f(minx + rad, miny);
+ round_box_shade_col(color, coltop, coldown, 0.0);
+ immVertex2f(pos, minx + rad, miny);
}
else {
- round_box_shade_col(coltop, coldown, 0.0);
- glVertex2f(minx, miny);
+ round_box_shade_col(color, coltop, coldown, 0.0);
+ immVertex2f(pos, minx, miny);
}
-
- glEnd();
+
+ immEnd();
+ immUnbindProgram();
+#endif
+
+ uiWidgetBaseParameters widget_params = {
+ .recti.xmin = minx, .recti.ymin = miny,
+ .recti.xmax = maxx, .recti.ymax = maxy,
+ .radi = rad,
+ .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f,
+ .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f,
+ .color_inner1[0] = min_ff(1.0f, col[0] + shadetop),
+ .color_inner2[0] = max_ff(0.0f, col[0] + shadedown),
+ .color_inner1[1] = min_ff(1.0f, col[1] + shadetop),
+ .color_inner2[1] = max_ff(0.0f, col[1] + shadedown),
+ .color_inner1[2] = min_ff(1.0f, col[2] + shadetop),
+ .color_inner2[2] = max_ff(0.0f, col[2] + shadedown),
+ .color_inner1[3] = 1.0f,
+ .color_inner2[3] = 1.0f,
+ .alpha_discard = 1.0f,
+ };
+
+ Gwn_Batch *batch = ui_batch_roundbox_get(filled, false);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
+ GWN_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&widget_params);
+ GWN_batch_draw(batch);
}
+#if 0 /* unused */
/* linear vertical shade within button or in outline */
/* view2d scrollers use it */
void UI_draw_roundbox_shade_y(
- int mode, float minx, float miny, float maxx, float maxy,
- float rad, float shadeLeft, float shadeRight)
+ bool filled, float minx, float miny, float maxx, float maxy,
+ float rad, float shadeleft, float shaderight, const float col[4])
{
float vec[7][2] = {{0.195, 0.02}, {0.383, 0.067}, {0.55, 0.169}, {0.707, 0.293},
{0.831, 0.45}, {0.924, 0.617}, {0.98, 0.805}};
const float div = maxx - minx;
const float idiv = 1.0f / div;
- float colLeft[3], colRight[3], color[4];
+ float colLeft[3], colRight[3];
+ int vert_count = 0;
int a;
/* mult */
for (a = 0; a < 7; a++) {
mul_v2_fl(vec[a], rad);
}
- /* get current color, needs to be outside of glBegin/End */
- glGetFloatv(GL_CURRENT_COLOR, color);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
/* 'shade' defines strength of shading */
- colLeft[0] = min_ff(1.0f, color[0] + shadeLeft);
- colLeft[1] = min_ff(1.0f, color[1] + shadeLeft);
- colLeft[2] = min_ff(1.0f, color[2] + shadeLeft);
- colRight[0] = max_ff(0.0f, color[0] + shadeRight);
- colRight[1] = max_ff(0.0f, color[1] + shadeRight);
- colRight[2] = max_ff(0.0f, color[2] + shadeRight);
+ colLeft[0] = min_ff(1.0f, col[0] + shadeleft);
+ colLeft[1] = min_ff(1.0f, col[1] + shadeleft);
+ colLeft[2] = min_ff(1.0f, col[2] + shadeleft);
+ colRight[0] = max_ff(0.0f, col[0] + shaderight);
+ colRight[1] = max_ff(0.0f, col[1] + shaderight);
+ colRight[2] = max_ff(0.0f, col[2] + shaderight);
+
+
+ vert_count += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 9 : 1;
+ vert_count += (roundboxtype & UI_CNR_TOP_RIGHT) ? 9 : 1;
+ vert_count += (roundboxtype & UI_CNR_TOP_LEFT) ? 9 : 1;
+ vert_count += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 9 : 1;
- glBegin(mode);
+ immBegin(filled ? GWN_PRIM_TRI_FAN : GWN_PRIM_LINE_LOOP, vert_count);
/* start with corner right-bottom */
if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
- round_box_shade_col(colLeft, colRight, 0.0);
- glVertex2f(maxx - rad, miny);
+ round_box_shade_col(color, colLeft, colRight, 0.0);
+ immVertex2f(pos, maxx - rad, miny);
for (a = 0; a < 7; a++) {
- round_box_shade_col(colLeft, colRight, vec[a][0] * idiv);
- glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]);
+ round_box_shade_col(color, colLeft, colRight, vec[a][0] * idiv);
+ immVertex2f(pos, maxx - rad + vec[a][0], miny + vec[a][1]);
}
- round_box_shade_col(colLeft, colRight, rad * idiv);
- glVertex2f(maxx, miny + rad);
+ round_box_shade_col(color, colLeft, colRight, rad * idiv);
+ immVertex2f(pos, maxx, miny + rad);
}
else {
- round_box_shade_col(colLeft, colRight, 0.0);
- glVertex2f(maxx, miny);
+ round_box_shade_col(color, colLeft, colRight, 0.0);
+ immVertex2f(pos, maxx, miny);
}
/* corner right-top */
if (roundboxtype & UI_CNR_TOP_RIGHT) {
- round_box_shade_col(colLeft, colRight, 0.0);
- glVertex2f(maxx, maxy - rad);
+ round_box_shade_col(color, colLeft, colRight, 0.0);
+ immVertex2f(pos, maxx, maxy - rad);
for (a = 0; a < 7; a++) {
- round_box_shade_col(colLeft, colRight, (div - rad - vec[a][0]) * idiv);
- glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]);
+ round_box_shade_col(color, colLeft, colRight, (div - rad - vec[a][0]) * idiv);
+ immVertex2f(pos, maxx - vec[a][1], maxy - rad + vec[a][0]);
}
- round_box_shade_col(colLeft, colRight, (div - rad) * idiv);
- glVertex2f(maxx - rad, maxy);
+ round_box_shade_col(color, colLeft, colRight, (div - rad) * idiv);
+ immVertex2f(pos, maxx - rad, maxy);
}
else {
- round_box_shade_col(colLeft, colRight, 0.0);
- glVertex2f(maxx, maxy);
+ round_box_shade_col(color, colLeft, colRight, 0.0);
+ immVertex2f(pos, maxx, maxy);
}
/* corner left-top */
if (roundboxtype & UI_CNR_TOP_LEFT) {
- round_box_shade_col(colLeft, colRight, (div - rad) * idiv);
- glVertex2f(minx + rad, maxy);
+ round_box_shade_col(color, colLeft, colRight, (div - rad) * idiv);
+ immVertex2f(pos, minx + rad, maxy);
for (a = 0; a < 7; a++) {
- round_box_shade_col(colLeft, colRight, (div - rad + vec[a][0]) * idiv);
- glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]);
+ round_box_shade_col(color, colLeft, colRight, (div - rad + vec[a][0]) * idiv);
+ immVertex2f(pos, minx + rad - vec[a][0], maxy - vec[a][1]);
}
- round_box_shade_col(colLeft, colRight, 1.0);
- glVertex2f(minx, maxy - rad);
+ round_box_shade_col(color, colLeft, colRight, 1.0);
+ immVertex2f(pos, minx, maxy - rad);
}
else {
- round_box_shade_col(colLeft, colRight, 1.0);
- glVertex2f(minx, maxy);
+ round_box_shade_col(color, colLeft, colRight, 1.0);
+ immVertex2f(pos, minx, maxy);
}
/* corner left-bottom */
if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
- round_box_shade_col(colLeft, colRight, 1.0);
- glVertex2f(minx, miny + rad);
+ round_box_shade_col(color, colLeft, colRight, 1.0);
+ immVertex2f(pos, minx, miny + rad);
for (a = 0; a < 7; a++) {
- round_box_shade_col(colLeft, colRight, (vec[a][0]) * idiv);
- glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]);
+ round_box_shade_col(color, colLeft, colRight, (vec[a][0]) * idiv);
+ immVertex2f(pos, minx + vec[a][1], miny + rad - vec[a][0]);
}
- round_box_shade_col(colLeft, colRight, 1.0);
- glVertex2f(minx + rad, miny);
+ round_box_shade_col(color, colLeft, colRight, 1.0);
+ immVertex2f(pos, minx + rad, miny);
}
else {
- round_box_shade_col(colLeft, colRight, 1.0);
- glVertex2f(minx, miny);
+ round_box_shade_col(color, colLeft, colRight, 1.0);
+ immVertex2f(pos, minx, miny);
}
-
- glEnd();
+
+ immEnd();
+ immUnbindProgram();
}
+#endif /* unused */
-/* plain antialiased unfilled rectangle */
-void UI_draw_roundbox_unfilled(float minx, float miny, float maxx, float maxy, float rad)
+void UI_draw_text_underline(int pos_x, int pos_y, int len, int height, const float color[4])
{
- float color[4];
-
- if (roundboxtype & UI_RB_ALPHA) {
- glGetFloatv(GL_CURRENT_COLOR, color);
- color[3] = 0.5;
- glColor4fv(color);
- glEnable(GL_BLEND);
- }
-
- /* set antialias line */
- glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
+ int ofs_y = 4 * U.pixelsize;
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, minx, miny, maxx, maxy, rad);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
-}
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv(color);
-/* (old, used in outliner) plain antialiased filled box */
-void UI_draw_roundbox(float minx, float miny, float maxx, float maxy, float rad)
-{
- ui_draw_anti_roundbox(GL_POLYGON, minx, miny, maxx, maxy, rad, roundboxtype & UI_RB_ALPHA);
+ immRecti(pos, pos_x, pos_y - ofs_y, pos_x + len, pos_y - ofs_y + (height * U.pixelsize));
+ immUnbindProgram();
}
-void UI_draw_text_underline(int pos_x, int pos_y, int len, int height)
+/* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
+
+/* based on UI_draw_roundbox_gl_mode, check on making a version which allows us to skip some sides */
+void ui_draw_but_TAB_outline(const rcti *rect, float rad, unsigned char highlight[3], unsigned char highlight_fade[3])
{
- int ofs_y = 4 * U.pixelsize;
- glRecti(pos_x, pos_y - ofs_y, pos_x + len, pos_y - ofs_y + (height * U.pixelsize));
-}
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ /* add a 1px offset, looks nicer */
+ const int minx = rect->xmin + U.pixelsize, maxx = rect->xmax - U.pixelsize;
+ const int miny = rect->ymin + U.pixelsize, maxy = rect->ymax - U.pixelsize;
+ int a;
+ float vec[4][2] = {
+ {0.195, 0.02},
+ {0.55, 0.169},
+ {0.831, 0.45},
+ {0.98, 0.805},
+ };
-/* ************** SPECIAL BUTTON DRAWING FUNCTIONS ************* */
+
+ /* mult */
+ for (a = 0; a < 4; a++) {
+ mul_v2_fl(vec[a], rad);
+ }
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, 25);
+
+ immAttrib3ubv(col, highlight);
+
+ /* start with corner left-top */
+ if (roundboxtype & UI_CNR_TOP_LEFT) {
+ immVertex2f(pos, minx, maxy - rad);
+ for (a = 0; a < 4; a++) {
+ immVertex2f(pos, minx + vec[a][1], maxy - rad + vec[a][0]);
+ }
+ immVertex2f(pos, minx + rad, maxy);
+ }
+ else {
+ immVertex2f(pos, minx, maxy);
+ }
+
+ /* corner right-top */
+ if (roundboxtype & UI_CNR_TOP_RIGHT) {
+ immVertex2f(pos, maxx - rad, maxy);
+ for (a = 0; a < 4; a++) {
+ immVertex2f(pos, maxx - rad + vec[a][0], maxy - vec[a][1]);
+ }
+ immVertex2f(pos, maxx, maxy - rad);
+ }
+ else {
+ immVertex2f(pos, maxx, maxy);
+ }
+
+ immAttrib3ubv(col, highlight_fade);
+
+ /* corner right-bottom */
+ if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
+ immVertex2f(pos, maxx, miny + rad);
+ for (a = 0; a < 4; a++) {
+ immVertex2f(pos, maxx - vec[a][1], miny + rad - vec[a][0]);
+ }
+ immVertex2f(pos, maxx - rad, miny);
+ }
+ else {
+ immVertex2f(pos, maxx, miny);
+ }
+
+ /* corner left-bottom */
+ if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
+ immVertex2f(pos, minx + rad, miny);
+ for (a = 0; a < 4; a++) {
+ immVertex2f(pos, minx + rad - vec[a][0], miny + vec[a][1]);
+ }
+ immVertex2f(pos, minx, miny + rad);
+ }
+ else {
+ immVertex2f(pos, minx, miny);
+ }
+
+ immAttrib3ubv(col, highlight);
+
+ /* back to corner left-top */
+ immVertex2f(pos, minx, roundboxtype & UI_CNR_TOP_LEFT ? maxy - rad : maxy);
+
+ immEnd();
+ immUnbindProgram();
+}
void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect)
{
@@ -411,32 +635,31 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
ImBuf *ibuf = (ImBuf *)but->poin;
if (!ibuf) return;
+
+ float facx = 1.0f;
+ float facy = 1.0f;
int w = BLI_rcti_size_x(rect);
int h = BLI_rcti_size_y(rect);
/* scissor doesn't seem to be doing the right thing...? */
#if 0
- //glColor4f(1.0, 0.f, 0.f, 1.f);
- //fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax)
-
/* prevent drawing outside widget area */
GLint scissor[4];
glGetIntegerv(GL_SCISSOR_BOX, scissor);
- glScissor(ar->winrct.xmin + rect->xmin, ar->winrct.ymin + rect->ymin, w, h);
+ glScissor(rect->xmin, rect->ymin, w, h);
#endif
glEnable(GL_BLEND);
- glColor4f(0.0, 0.0, 0.0, 0.0);
if (w != ibuf->x || h != ibuf->y) {
- float facx = (float)w / (float)ibuf->x;
- float facy = (float)h / (float)ibuf->y;
- glPixelZoom(facx, facy);
+ facx = (float)w / (float)ibuf->x;
+ facy = (float)h / (float)ibuf->y;
}
- glaDrawPixelsAuto((float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect);
-
- glPixelZoom(1.0f, 1.0f);
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex(&state, (float)rect->xmin, (float)rect->ymin, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, ibuf->rect,
+ facx, facy, NULL);
glDisable(GL_BLEND);
@@ -451,43 +674,34 @@ void ui_draw_but_IMAGE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(w
/**
* Draw title and text safe areas.
*
- * The first 4 parameters are the offsets for the view, not the zones.
+ * \Note This functionn is to be used with the 2D dashed shader enabled.
+ *
+ * \param pos is a PRIM_FLOAT, 2, GWN_FETCH_FLOAT vertex attrib
+ * \param line_origin is a PRIM_FLOAT, 2, GWN_FETCH_FLOAT vertex attrib
+ *
+ * The next 4 parameters are the offsets for the view, not the zones.
*/
void UI_draw_safe_areas(
- float x1, float x2, float y1, float y2,
+ uint pos, float x1, float x2, float y1, float y2,
const float title_aspect[2], const float action_aspect[2])
{
const float size_x_half = (x2 - x1) * 0.5f;
const float size_y_half = (y2 - y1) * 0.5f;
const float *safe_areas[] = {title_aspect, action_aspect};
- int safe_len = ARRAY_SIZE(safe_areas);
- bool is_first = true;
+ const int safe_len = ARRAY_SIZE(safe_areas);
for (int i = 0; i < safe_len; i++) {
if (safe_areas[i][0] || safe_areas[i][1]) {
- float margin_x, margin_y;
- float minx, miny, maxx, maxy;
-
- if (is_first) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25f, 0);
- is_first = false;
- }
-
- margin_x = safe_areas[i][0] * size_x_half;
- margin_y = safe_areas[i][1] * size_y_half;
+ float margin_x = safe_areas[i][0] * size_x_half;
+ float margin_y = safe_areas[i][1] * size_y_half;
- minx = x1 + margin_x;
- miny = y1 + margin_y;
- maxx = x2 - margin_x;
- maxy = y2 - margin_y;
+ float minx = x1 + margin_x;
+ float miny = y1 + margin_y;
+ float maxx = x2 - margin_x;
+ float maxy = y2 - margin_y;
- glBegin(GL_LINE_LOOP);
- glVertex2f(maxx, miny);
- glVertex2f(maxx, maxy);
- glVertex2f(minx, maxy);
- glVertex2f(minx, miny);
- glEnd();
+ imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy);
}
}
}
@@ -498,55 +712,63 @@ static void draw_scope_end(const rctf *rect, GLint *scissor)
/* restore scissortest */
glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* outline */
- glColor4f(0.f, 0.f, 0.f, 0.5f);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, rect->xmin - 1, rect->ymin, rect->xmax + 1, rect->ymax + 1, 3.0f);
+ float color[4] = {0.0f, 0.0f, 0.0f, 0.5f};
+ UI_draw_roundbox_4fv(false, rect->xmin - 1, rect->ymin, rect->xmax + 1, rect->ymax + 1, 3.0f, color);
}
static void histogram_draw_one(
float r, float g, float b, float alpha,
- float x, float y, float w, float h, const float *data, int res, const bool is_line)
+ float x, float y, float w, float h, const float *data, int res, const bool is_line,
+ unsigned int pos_attrib)
{
+ float color[4] = {r, g, b, alpha};
+
+ /* that can happen */
+ if (res == 0)
+ return;
+
glEnable(GL_LINE_SMOOTH);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE);
- glColor4f(r, g, b, alpha);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE, GL_ONE, GL_ONE);
+
+ immUniformColor4fv(color);
if (is_line) {
/* curve outline */
glLineWidth(1.5);
- glBegin(GL_LINE_STRIP);
+ immBegin(GWN_PRIM_LINE_STRIP, res);
for (int i = 0; i < res; i++) {
float x2 = x + i * (w / (float)res);
- glVertex2f(x2, y + (data[i] * h));
+ immVertex2f(pos_attrib, x2, y + (data[i] * h));
}
- glEnd();
+ immEnd();
}
else {
/* under the curve */
- glBegin(GL_TRIANGLE_STRIP);
- glVertex2f(x, y);
- glVertex2f(x, y + (data[0] * h));
+ immBegin(GWN_PRIM_TRI_STRIP, res * 2);
+ immVertex2f(pos_attrib, x, y);
+ immVertex2f(pos_attrib, x, y + (data[0] * h));
for (int i = 1; i < res; i++) {
float x2 = x + i * (w / (float)res);
- glVertex2f(x2, y + (data[i] * h));
- glVertex2f(x2, y);
+ immVertex2f(pos_attrib, x2, y + (data[i] * h));
+ immVertex2f(pos_attrib, x2, y);
}
- glEnd();
+ immEnd();
/* curve outline */
- glColor4f(0.f, 0.f, 0.f, 0.25f);
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.25f);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glBegin(GL_LINE_STRIP);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ immBegin(GWN_PRIM_LINE_STRIP, res);
for (int i = 0; i < res; i++) {
float x2 = x + i * (w / (float)res);
- glVertex2f(x2, y + (data[i] * h));
+ immVertex2f(pos_attrib, x2, y + (data[i] * h));
}
- glEnd();
+ immEnd();
}
glDisable(GL_LINE_SMOOTH);
@@ -554,12 +776,12 @@ static void histogram_draw_one(
#define HISTOGRAM_TOT_GRID_LINES 4
-void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
+void ui_draw_but_HISTOGRAM(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
{
Histogram *hist = (Histogram *)but->poin;
int res = hist->x_resolution;
const bool is_line = (hist->flag & HISTO_FLAG_LINE) != 0;
-
+
rctf rect = {
.xmin = (float)recti->xmin + 1,
.xmax = (float)recti->xmax - 1,
@@ -571,48 +793,63 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
float h = BLI_rctf_size_y(&rect) * hist->ymax;
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- UI_ThemeColor4(TH_PREVIEW_BACK);
+ float color[4];
+ UI_GetThemeColor4fv(TH_PREVIEW_BACK, color);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
+ UI_draw_roundbox_4fv(true, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
/* need scissor test, histogram can draw outside of boundary */
GLint scissor[4];
- glGetIntegerv(GL_VIEWPORT, scissor);
- glScissor(ar->winrct.xmin + (rect.xmin - 1),
- ar->winrct.ymin + (rect.ymin - 1),
+ glGetIntegerv(GL_SCISSOR_BOX, scissor);
+ glScissor((rect.xmin - 1),
+ (rect.ymin - 1),
(rect.xmax + 1) - (rect.xmin - 1),
(rect.ymax + 1) - (rect.ymin - 1));
- glColor4f(1.f, 1.f, 1.f, 0.08f);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f);
/* draw grid lines here */
for (int i = 1; i <= HISTOGRAM_TOT_GRID_LINES; i++) {
const float fac = (float)i / (float)HISTOGRAM_TOT_GRID_LINES;
/* so we can tell the 1.0 color point */
if (i == HISTOGRAM_TOT_GRID_LINES) {
- glColor4f(1.0f, 1.0f, 1.0f, 0.5f);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
}
- fdrawline(rect.xmin, rect.ymin + fac * h, rect.xmax, rect.ymin + fac * h);
- fdrawline(rect.xmin + fac * w, rect.ymin, rect.xmin + fac * w, rect.ymax);
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, rect.xmin, rect.ymin + fac * h);
+ immVertex2f(pos, rect.xmax, rect.ymin + fac * h);
+
+ immVertex2f(pos, rect.xmin + fac * w, rect.ymin);
+ immVertex2f(pos, rect.xmin + fac * w, rect.ymax);
+
+ immEnd();
}
-
+
if (hist->mode == HISTO_MODE_LUMA) {
- histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line);
+ histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_luma, res, is_line, pos);
}
else if (hist->mode == HISTO_MODE_ALPHA) {
- histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line);
+ histogram_draw_one(1.0, 1.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_a, res, is_line, pos);
}
else {
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_R)
- histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line);
+ histogram_draw_one(1.0, 0.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_r, res, is_line, pos);
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_G)
- histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res, is_line);
+ histogram_draw_one(0.0, 1.0, 0.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_g, res, is_line, pos);
if (hist->mode == HISTO_MODE_RGB || hist->mode == HISTO_MODE_B)
- histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line);
+ histogram_draw_one(0.0, 0.0, 1.0, 0.75, rect.xmin, rect.ymin, w, h, hist->data_b, res, is_line, pos);
}
+
+ immUnbindProgram();
/* outline */
draw_scope_end(&rect, scissor);
@@ -620,7 +857,26 @@ void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol)
#undef HISTOGRAM_TOT_GRID_LINES
-void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
+static void waveform_draw_one(float *waveform, int nbr, const float col[3])
+{
+ Gwn_VertFormat format = {0};
+ unsigned int pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, nbr);
+
+ GWN_vertbuf_attr_fill(vbo, pos_id, waveform);
+
+ /* TODO store the Gwn_Batch inside the scope */
+ Gwn_Batch *batch = GWN_batch_create_ex(GWN_PRIM_POINTS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_UNIFORM_COLOR);
+ GWN_batch_uniform_4f(batch, "color", col[0], col[1], col[2], 1.0f);
+ GWN_batch_draw(batch);
+
+ GWN_batch_discard(batch);
+}
+
+void ui_draw_but_WAVEFORM(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
{
Scopes *scopes = (Scopes *)but->poin;
GLint scissor[4];
@@ -642,7 +898,7 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
scopes->wavefrm_yfac = 0.98f;
float w = BLI_rctf_size_x(&rect) - 7;
float h = BLI_rctf_size_y(&rect) * scopes->wavefrm_yfac;
- float yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) / 2.0f;
+ float yofs = rect.ymin + (BLI_rctf_size_y(&rect) - h) * 0.5f;
float w3 = w / 3.0f;
/* log scale for alpha */
@@ -657,108 +913,140 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
}
}
+ /* Flush text cache before changing scissors. */
+ BLF_batch_draw_flush();
+
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- UI_ThemeColor4(TH_PREVIEW_BACK);
+ float color[4];
+ UI_GetThemeColor4fv(TH_PREVIEW_BACK, color);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
+ UI_draw_roundbox_4fv(true, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
/* need scissor test, waveform can draw outside of boundary */
- glGetIntegerv(GL_VIEWPORT, scissor);
- glScissor(ar->winrct.xmin + (rect.xmin - 1),
- ar->winrct.ymin + (rect.ymin - 1),
+ glGetIntegerv(GL_SCISSOR_BOX, scissor);
+ glScissor((rect.xmin - 1),
+ (rect.ymin - 1),
(rect.xmax + 1) - (rect.xmin - 1),
(rect.ymax + 1) - (rect.ymin - 1));
- glColor4f(1.f, 1.f, 1.f, 0.08f);
- /* draw grid lines here */
+ /* draw scale numbers first before binding any shader */
for (int i = 0; i < 6; i++) {
char str[4];
BLI_snprintf(str, sizeof(str), "%-3d", i * 20);
str[3] = '\0';
- fdrawline(rect.xmin + 22, yofs + (i / 5.f) * h, rect.xmax + 1, yofs + (i / 5.f) * h);
- BLF_draw_default(rect.xmin + 1, yofs - 5 + (i / 5.f) * h, 0, str, sizeof(str) - 1);
- /* in the loop because blf_draw reset it */
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ BLF_color4f(BLF_default(), 1.0f, 1.0f, 1.0f, 0.08f);
+ BLF_draw_default(rect.xmin + 1, yofs - 5 + (i * 0.2f) * h, 0, str, sizeof(str) - 1);
}
+
+ /* Flush text cache before drawing things on top. */
+ BLF_batch_draw_flush();
+
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f);
+
+ /* draw grid lines here */
+ immBegin(GWN_PRIM_LINES, 12);
+
+ for (int i = 0; i < 6; i++) {
+ immVertex2f(pos, rect.xmin + 22, yofs + (i * 0.2f) * h);
+ immVertex2f(pos, rect.xmax + 1, yofs + (i * 0.2f) * h);
+ }
+
+ immEnd();
+
/* 3 vertical separation */
if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA) {
+ immBegin(GWN_PRIM_LINES, 4);
+
for (int i = 1; i < 3; i++) {
- fdrawline(rect.xmin + i * w3, rect.ymin, rect.xmin + i * w3, rect.ymax);
+ immVertex2f(pos, rect.xmin + i * w3, rect.ymin);
+ immVertex2f(pos, rect.xmin + i * w3, rect.ymax);
}
+
+ immEnd();
}
/* separate min max zone on the right */
- fdrawline(rect.xmin + w, rect.ymin, rect.xmin + w, rect.ymax);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, rect.xmin + w, rect.ymin);
+ immVertex2f(pos, rect.xmin + w, rect.ymax);
+ immEnd();
+
/* 16-235-240 level in case of ITU-R BT601/709 */
- glColor4f(1.f, 0.4f, 0.f, 0.2f);
+ immUniformColor4f(1.0f, 0.4f, 0.0f, 0.2f);
if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_YCC_601, SCOPES_WAVEFRM_YCC_709)) {
- fdrawline(rect.xmin + 22, yofs + h * 16.0f / 255.0f, rect.xmax + 1, yofs + h * 16.0f / 255.0f);
- fdrawline(rect.xmin + 22, yofs + h * 235.0f / 255.0f, rect.xmin + w3, yofs + h * 235.0f / 255.0f);
- fdrawline(rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f, rect.xmax + 1, yofs + h * 235.0f / 255.0f);
- fdrawline(rect.xmin + w3, yofs + h * 240.0f / 255.0f, rect.xmax + 1, yofs + h * 240.0f / 255.0f);
+ immBegin(GWN_PRIM_LINES, 8);
+
+ immVertex2f(pos, rect.xmin + 22, yofs + h * 16.0f / 255.0f);
+ immVertex2f(pos, rect.xmax + 1, yofs + h * 16.0f / 255.0f);
+
+ immVertex2f(pos, rect.xmin + 22, yofs + h * 235.0f / 255.0f);
+ immVertex2f(pos, rect.xmin + w3, yofs + h * 235.0f / 255.0f);
+
+ immVertex2f(pos, rect.xmin + 3 * w3, yofs + h * 235.0f / 255.0f);
+ immVertex2f(pos, rect.xmax + 1, yofs + h * 235.0f / 255.0f);
+
+ immVertex2f(pos, rect.xmin + w3, yofs + h * 240.0f / 255.0f);
+ immVertex2f(pos, rect.xmax + 1, yofs + h * 240.0f / 255.0f);
+
+ immEnd();
}
/* 7.5 IRE black point level for NTSC */
- if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA)
- fdrawline(rect.xmin, yofs + h * 0.075f, rect.xmax + 1, yofs + h * 0.075f);
+ if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) {
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, rect.xmin, yofs + h * 0.075f);
+ immVertex2f(pos, rect.xmax + 1, yofs + h * 0.075f);
+ immEnd();
+ }
if (scopes->ok && scopes->waveform_1 != NULL) {
-
- /* LUMA (1 channel) */
glBlendFunc(GL_ONE, GL_ONE);
- glColor3f(alpha, alpha, alpha);
glPointSize(1.0);
+ /* LUMA (1 channel) */
if (scopes->wavefrm_mode == SCOPES_WAVEFRM_LUMA) {
+ float col[3] = {alpha, alpha, alpha};
- glBlendFunc(GL_ONE, GL_ONE);
-
- glPushMatrix();
- glEnableClientState(GL_VERTEX_ARRAY);
-
- glTranslatef(rect.xmin, yofs, 0.f);
- glScalef(w, h, 0.f);
- glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
+ gpuPushMatrix();
+ gpuTranslate2f(rect.xmin, yofs);
+ gpuScale2f(w, h);
+
+ waveform_draw_one(scopes->waveform_1, scopes->waveform_tot, col);
- glDisableClientState(GL_VERTEX_ARRAY);
- glPopMatrix();
+ gpuPopMatrix();
/* min max */
- glColor3f(0.5f, 0.5f, 0.5f);
+ immUniformColor3f(0.5f, 0.5f, 0.5f);
min = yofs + scopes->minmax[0][0] * h;
max = yofs + scopes->minmax[0][1] * h;
CLAMP(min, rect.ymin, rect.ymax);
CLAMP(max, rect.ymin, rect.ymax);
- fdrawline(rect.xmax - 3, min, rect.xmax - 3, max);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, rect.xmax - 3, min);
+ immVertex2f(pos, rect.xmax - 3, max);
+ immEnd();
}
/* RGB (3 channel) */
else if (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB) {
- glBlendFunc(GL_ONE, GL_ONE);
-
- glEnableClientState(GL_VERTEX_ARRAY);
-
- glPushMatrix();
-
- glTranslatef(rect.xmin, yofs, 0.f);
- glScalef(w, h, 0.f);
-
- glColor3fv( colors_alpha[0] );
- glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
+ gpuPushMatrix();
+ gpuTranslate2f(rect.xmin, yofs);
+ gpuScale2f(w, h);
- glColor3fv( colors_alpha[1] );
- glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
+ waveform_draw_one(scopes->waveform_1, scopes->waveform_tot, colors_alpha[0]);
+ waveform_draw_one(scopes->waveform_2, scopes->waveform_tot, colors_alpha[1]);
+ waveform_draw_one(scopes->waveform_3, scopes->waveform_tot, colors_alpha[2]);
- glColor3fv( colors_alpha[2] );
- glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glPopMatrix();
+ gpuPopMatrix();
}
/* PARADE / YCC (3 channels) */
else if (ELEM(scopes->wavefrm_mode,
@@ -770,49 +1058,47 @@ void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol),
{
int rgb = (scopes->wavefrm_mode == SCOPES_WAVEFRM_RGB_PARADE);
- glBlendFunc(GL_ONE, GL_ONE);
-
- glPushMatrix();
- glEnableClientState(GL_VERTEX_ARRAY);
+ gpuPushMatrix();
+ gpuTranslate2f(rect.xmin, yofs);
+ gpuScale2f(w3, h);
- glTranslatef(rect.xmin, yofs, 0.f);
- glScalef(w3, h, 0.f);
+ waveform_draw_one(scopes->waveform_1, scopes->waveform_tot, (rgb) ? colors_alpha[0] : colorsycc_alpha[0]);
- glColor3fv((rgb) ? colors_alpha[0] : colorsycc_alpha[0]);
- glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_1);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
+ gpuTranslate2f(1.0f, 0.0f);
+ waveform_draw_one(scopes->waveform_2, scopes->waveform_tot, (rgb) ? colors_alpha[1] : colorsycc_alpha[1]);
- glTranslatef(1.f, 0.f, 0.f);
- glColor3fv((rgb) ? colors_alpha[1] : colorsycc_alpha[1]);
- glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_2);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
+ gpuTranslate2f(1.0f, 0.0f);
+ waveform_draw_one(scopes->waveform_3, scopes->waveform_tot, (rgb) ? colors_alpha[2] : colorsycc_alpha[2]);
- glTranslatef(1.f, 0.f, 0.f);
- glColor3fv((rgb) ? colors_alpha[2] : colorsycc_alpha[2]);
- glVertexPointer(2, GL_FLOAT, 0, scopes->waveform_3);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glPopMatrix();
+ gpuPopMatrix();
}
+
/* min max */
if (scopes->wavefrm_mode != SCOPES_WAVEFRM_LUMA ) {
for (int c = 0; c < 3; c++) {
if (ELEM(scopes->wavefrm_mode, SCOPES_WAVEFRM_RGB_PARADE, SCOPES_WAVEFRM_RGB))
- glColor3f(colors[c][0] * 0.75f, colors[c][1] * 0.75f, colors[c][2] * 0.75f);
+ immUniformColor3f(colors[c][0] * 0.75f, colors[c][1] * 0.75f, colors[c][2] * 0.75f);
else
- glColor3f(colorsycc[c][0] * 0.75f, colorsycc[c][1] * 0.75f, colorsycc[c][2] * 0.75f);
+ immUniformColor3f(colorsycc[c][0] * 0.75f, colorsycc[c][1] * 0.75f, colorsycc[c][2] * 0.75f);
min = yofs + scopes->minmax[c][0] * h;
max = yofs + scopes->minmax[c][1] * h;
CLAMP(min, rect.ymin, rect.ymax);
CLAMP(max, rect.ymin, rect.ymax);
- fdrawline(rect.xmin + w + 2 + c * 2, min, rect.xmin + w + 2 + c * 2, max);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, rect.xmin + w + 2 + c * 2, min);
+ immVertex2f(pos, rect.xmin + w + 2 + c * 2, max);
+ immEnd();
}
}
}
-
+
+ immUnbindProgram();
+
/* outline */
draw_scope_end(&rect, scissor);
+
+ glDisable(GL_BLEND);
}
static float polar_to_x(float center, float diam, float ampli, float angle)
@@ -825,10 +1111,10 @@ static float polar_to_y(float center, float diam, float ampli, float angle)
return center + diam * ampli * sinf(angle);
}
-static void vectorscope_draw_target(float centerx, float centery, float diam, const float colf[3])
+static void vectorscope_draw_target(unsigned int pos, float centerx, float centery, float diam, const float colf[3])
{
float y, u, v;
- float tangle = 0.f, tampli;
+ float tangle = 0.0f, tampli;
float dangle, dampli, dangle2, dampli2;
rgb_to_yuv(colf[0], colf[1], colf[2], &y, &u, &v, BLI_YUV_ITU_BT709);
@@ -840,44 +1126,44 @@ static void vectorscope_draw_target(float centerx, float centery, float diam, co
tampli = sqrtf(u * u + v * v);
/* small target vary by 2.5 degree and 2.5 IRE unit */
- glColor4f(1.0f, 1.0f, 1.0, 0.12f);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.12f);
dangle = DEG2RADF(2.5f);
dampli = 2.5f / 200.0f;
- glBegin(GL_LINE_LOOP);
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle));
- glEnd();
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle));
+ immEnd();
/* big target vary by 10 degree and 20% amplitude */
- glColor4f(1.0f, 1.0f, 1.0, 0.12f);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.12f);
dangle = DEG2RADF(10.0f);
dampli = 0.2f * tampli;
dangle2 = DEG2RADF(5.0f);
dampli2 = 0.5f * dampli;
- glBegin(GL_LINE_STRIP);
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle + dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle + dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli + dampli, tangle + dangle - dangle2));
- glEnd();
- glBegin(GL_LINE_STRIP);
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle + dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle + dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli - dampli, tangle + dangle - dangle2));
- glEnd();
- glBegin(GL_LINE_STRIP);
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle - dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle - dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli - dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli - dampli, tangle - dangle + dangle2));
- glEnd();
- glBegin(GL_LINE_STRIP);
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle - dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle - dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle));
- glVertex2f(polar_to_x(centerx, diam, tampli + dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli + dampli, tangle - dangle + dangle2));
- glEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle + dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle + dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli, tangle + dangle), polar_to_y(centery, diam, tampli + dampli, tangle + dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli + dampli, tangle + dangle - dangle2));
+ immEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle + dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle + dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli, tangle + dangle), polar_to_y(centery, diam, tampli - dampli, tangle + dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli, tangle + dangle - dangle2), polar_to_y(centery, diam, tampli - dampli, tangle + dangle - dangle2));
+ immEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli + dampli2, tangle - dangle), polar_to_y(centery, diam, tampli - dampli + dampli2, tangle - dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli, tangle - dangle), polar_to_y(centery, diam, tampli - dampli, tangle - dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli - dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli - dampli, tangle - dangle + dangle2));
+ immEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli - dampli2, tangle - dangle), polar_to_y(centery, diam, tampli + dampli - dampli2, tangle - dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli, tangle - dangle), polar_to_y(centery, diam, tampli + dampli, tangle - dangle));
+ immVertex2f(pos, polar_to_x(centerx, diam, tampli + dampli, tangle - dangle + dangle2), polar_to_y(centery, diam, tampli + dampli, tangle - dangle + dangle2));
+ immEnd();
}
-void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
+void ui_draw_but_VECTORSCOPE(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
{
const float skin_rad = DEG2RADF(123.0f); /* angle in radians of the skin tone line */
Scopes *scopes = (Scopes *)but->poin;
@@ -895,114 +1181,131 @@ void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wco
float w = BLI_rctf_size_x(&rect);
float h = BLI_rctf_size_y(&rect);
- float centerx = rect.xmin + w / 2;
- float centery = rect.ymin + h / 2;
+ float centerx = rect.xmin + w * 0.5f;
+ float centery = rect.ymin + h * 0.5f;
float diam = (w < h) ? w : h;
float alpha = scopes->vecscope_alpha * scopes->vecscope_alpha * scopes->vecscope_alpha;
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- UI_ThemeColor4(TH_PREVIEW_BACK);
+ float color[4];
+ UI_GetThemeColor4fv(TH_PREVIEW_BACK, color);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f);
+ UI_draw_roundbox_4fv(true, rect.xmin - 1, rect.ymin - 1, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
/* need scissor test, hvectorscope can draw outside of boundary */
GLint scissor[4];
- glGetIntegerv(GL_VIEWPORT, scissor);
- glScissor(ar->winrct.xmin + (rect.xmin - 1),
- ar->winrct.ymin + (rect.ymin - 1),
+ glGetIntegerv(GL_SCISSOR_BOX, scissor);
+ glScissor((rect.xmin - 1),
+ (rect.ymin - 1),
(rect.xmax + 1) - (rect.xmin - 1),
(rect.ymax + 1) - (rect.ymin - 1));
- glColor4f(1.f, 1.f, 1.f, 0.08f);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.08f);
/* draw grid elements */
/* cross */
- fdrawline(centerx - (diam / 2) - 5, centery, centerx + (diam / 2) + 5, centery);
- fdrawline(centerx, centery - (diam / 2) - 5, centerx, centery + (diam / 2) + 5);
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, centerx - (diam * 0.5f) - 5, centery);
+ immVertex2f(pos, centerx + (diam * 0.5f) + 5, centery);
+
+ immVertex2f(pos, centerx, centery - (diam * 0.5f) - 5);
+ immVertex2f(pos, centerx, centery + (diam * 0.5f) + 5);
+
+ immEnd();
+
/* circles */
for (int j = 0; j < 5; j++) {
- glBegin(GL_LINE_LOOP);
const int increment = 15;
+ immBegin(GWN_PRIM_LINE_LOOP, (int)(360 / increment));
for (int i = 0; i <= 360 - increment; i += increment) {
const float a = DEG2RADF((float)i);
- const float r = (j + 1) / 10.0f;
- glVertex2f(polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a));
+ const float r = (j + 1) * 0.1f;
+ immVertex2f(pos, polar_to_x(centerx, diam, r, a), polar_to_y(centery, diam, r, a));
}
- glEnd();
+ immEnd();
}
/* skin tone line */
- glColor4f(1.f, 0.4f, 0.f, 0.2f);
- fdrawline(polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5, skin_rad),
- polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1, skin_rad));
+ immUniformColor4f(1.0f, 0.4f, 0.0f, 0.2f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, polar_to_x(centerx, diam, 0.5f, skin_rad), polar_to_y(centery, diam, 0.5f, skin_rad));
+ immVertex2f(pos, polar_to_x(centerx, diam, 0.1f, skin_rad), polar_to_y(centery, diam, 0.1f, skin_rad));
+ immEnd();
+
/* saturation points */
for (int i = 0; i < 6; i++)
- vectorscope_draw_target(centerx, centery, diam, colors[i]);
+ vectorscope_draw_target(pos, centerx, centery, diam, colors[i]);
if (scopes->ok && scopes->vecscope != NULL) {
/* pixel point cloud */
+ float col[3] = {alpha, alpha, alpha};
+
glBlendFunc(GL_ONE, GL_ONE);
- glColor3f(alpha, alpha, alpha);
+ glPointSize(1.0);
- glPushMatrix();
- glEnableClientState(GL_VERTEX_ARRAY);
+ gpuPushMatrix();
+ gpuTranslate2f(centerx, centery);
+ gpuScaleUniform(diam);
- glTranslatef(centerx, centery, 0.f);
- glScalef(diam, diam, 0.f);
+ waveform_draw_one(scopes->vecscope, scopes->waveform_tot, col);
- glVertexPointer(2, GL_FLOAT, 0, scopes->vecscope);
- glPointSize(1.0);
- glDrawArrays(GL_POINTS, 0, scopes->waveform_tot);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glPopMatrix();
+ gpuPopMatrix();
}
+ immUnbindProgram();
+
/* outline */
draw_scope_end(&rect, scissor);
glDisable(GL_BLEND);
}
-static void ui_draw_colorband_handle_tri_hlight(float x1, float y1, float halfwidth, float height)
+static void ui_draw_colorband_handle_tri_hlight(unsigned int pos, float x1, float y1, float halfwidth, float height)
{
glEnable(GL_LINE_SMOOTH);
- glBegin(GL_LINE_STRIP);
- glVertex2f(x1 + halfwidth, y1);
- glVertex2f(x1, y1 + height);
- glVertex2f(x1 - halfwidth, y1);
- glEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, x1 + halfwidth, y1);
+ immVertex2f(pos, x1, y1 + height);
+ immVertex2f(pos, x1 - halfwidth, y1);
+ immEnd();
glDisable(GL_LINE_SMOOTH);
}
-static void ui_draw_colorband_handle_tri(float x1, float y1, float halfwidth, float height, bool fill)
+static void ui_draw_colorband_handle_tri(unsigned int pos, float x1, float y1, float halfwidth, float height, bool fill)
{
glEnable(fill ? GL_POLYGON_SMOOTH : GL_LINE_SMOOTH);
- glBegin(fill ? GL_TRIANGLES : GL_LINE_LOOP);
- glVertex2f(x1 + halfwidth, y1);
- glVertex2f(x1, y1 + height);
- glVertex2f(x1 - halfwidth, y1);
- glEnd();
+ immBegin(fill ? GWN_PRIM_TRIS : GWN_PRIM_LINE_LOOP, 3);
+ immVertex2f(pos, x1 + halfwidth, y1);
+ immVertex2f(pos, x1, y1 + height);
+ immVertex2f(pos, x1 - halfwidth, y1);
+ immEnd();
glDisable(fill ? GL_POLYGON_SMOOTH : GL_LINE_SMOOTH);
}
-static void ui_draw_colorband_handle_box(float x1, float y1, float x2, float y2, bool fill)
+static void ui_draw_colorband_handle_box(unsigned int pos, float x1, float y1, float x2, float y2, bool fill)
{
- glBegin(fill ? GL_QUADS : GL_LINE_LOOP);
- glVertex2f(x1, y1);
- glVertex2f(x1, y2);
- glVertex2f(x2, y2);
- glVertex2f(x2, y1);
- glEnd();
+ immBegin(fill ? GWN_PRIM_TRI_FAN : GWN_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x1, y2);
+ immVertex2f(pos, x2, y2);
+ immVertex2f(pos, x2, y1);
+ immEnd();
}
static void ui_draw_colorband_handle(
- const rcti *rect, float x,
+ uint shdr_pos, const rcti *rect, float x,
const float rgb[3], struct ColorManagedDisplay *display,
bool active)
{
@@ -1021,18 +1324,26 @@ static void ui_draw_colorband_handle(
y1 = floorf(y1 + 0.5f);
if (active || half_width < min_width) {
- glBegin(GL_LINES);
- glColor3ub(0, 0, 0);
- glVertex2f(x, y1);
- glVertex2f(x, y2);
- glEnd();
- setlinestyle(active ? 2 : 1);
- glBegin(GL_LINES);
- glColor3ub(200, 200, 200);
- glVertex2f(x, y1);
- glVertex2f(x, y2);
- glEnd();
- setlinestyle(0);
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.8f, 0.8f, 0.8f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", active ? 4.0f : 2.0f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(shdr_pos, x, y1);
+ immVertex2f(shdr_pos, x, y2);
+ immEnd();
+
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* hide handles when zoomed out too far */
if (half_width < min_width) {
@@ -1043,45 +1354,46 @@ static void ui_draw_colorband_handle(
/* shift handle down */
y1 -= half_width;
- glColor3ub(0, 0, 0);
- ui_draw_colorband_handle_box(x - half_width, y1 - 1, x + half_width, y1 + height, false);
+ immUniformColor3ub(0, 0, 0);
+ ui_draw_colorband_handle_box(shdr_pos, x - half_width, y1 - 1, x + half_width, y1 + height, false);
/* draw all triangles blended */
glEnable(GL_BLEND);
- ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
+ ui_draw_colorband_handle_tri(shdr_pos, x, y1 + height, half_width, half_width, true);
if (active)
- glColor3ub(196, 196, 196);
+ immUniformColor3ub(196, 196, 196);
else
- glColor3ub(96, 96, 96);
- ui_draw_colorband_handle_tri(x, y1 + height, half_width, half_width, true);
+ immUniformColor3ub(96, 96, 96);
+ ui_draw_colorband_handle_tri(shdr_pos, x, y1 + height, half_width, half_width, true);
if (active)
- glColor3ub(255, 255, 255);
+ immUniformColor3ub(255, 255, 255);
else
- glColor3ub(128, 128, 128);
- ui_draw_colorband_handle_tri_hlight(x, y1 + height - 1, (half_width - 1), (half_width - 1));
+ immUniformColor3ub(128, 128, 128);
+ ui_draw_colorband_handle_tri_hlight(shdr_pos, x, y1 + height - 1, (half_width - 1), (half_width - 1));
- glColor3ub(0, 0, 0);
- ui_draw_colorband_handle_tri_hlight(x, y1 + height, half_width, half_width);
+ immUniformColor3ub(0, 0, 0);
+ ui_draw_colorband_handle_tri_hlight(shdr_pos, x, y1 + height, half_width, half_width);
glDisable(GL_BLEND);
- glColor3ub(128, 128, 128);
- ui_draw_colorband_handle_box(x - (half_width - 1), y1, x + (half_width - 1), y1 + height, true);
+ immUniformColor3ub(128, 128, 128);
+ ui_draw_colorband_handle_box(shdr_pos, x - (half_width - 1), y1, x + (half_width - 1), y1 + height, true);
if (display) {
IMB_colormanagement_scene_linear_to_display_v3(colf, display);
}
- glColor3fv(colf);
- ui_draw_colorband_handle_box(x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true);
+ immUniformColor3fv(colf);
+ ui_draw_colorband_handle_box(shdr_pos, x - (half_width - 2), y1 + 1, x + (half_width - 2), y1 + height - 2, true);
}
void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *rect)
{
struct ColorManagedDisplay *display = NULL;
+ unsigned int position, color;
ColorBand *coba = (ColorBand *)(but->editcoba ? but->editcoba : but->poin);
if (coba == NULL) return;
@@ -1092,20 +1404,25 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
float x1 = rect->xmin;
float sizex = rect->xmax - x1;
float sizey = BLI_rcti_size_y(rect);
- float sizey_solid = sizey / 4;
+ float sizey_solid = sizey * 0.25f;
float y1 = rect->ymin;
- /* Drawing the checkerboard.
- * This could be optimized with a single checkerboard shader,
- * instead of drawing twice and using stippling the second time. */
- /* layer: background, to show tranparency */
- glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
- glRectf(x1, y1, x1 + sizex, rect->ymax);
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
- glRectf(x1, y1, x1 + sizex, rect->ymax);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ Gwn_VertFormat *format = immVertexFormat();
+ position = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_CHECKER);
+
+ /* Drawing the checkerboard. */
+ immUniform4f("color1", UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_DARK / 255.0f, 1.0f);
+ immUniform4f("color2", UI_ALPHA_CHECKER_LIGHT / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 1.0f);
+ immUniform1i("size", 8);
+ immRectf(position, x1, y1, x1 + sizex, rect->ymax);
+ immUnbindProgram();
+
+ /* New format */
+ format = immVertexFormat();
+ position = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
/* layer: color ramp */
glEnable(GL_BLEND);
@@ -1118,7 +1435,7 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
v1[1] = y1 + sizey_solid;
v2[1] = rect->ymax;
- glBegin(GL_TRIANGLE_STRIP);
+ immBegin(GWN_PRIM_TRI_STRIP, (sizex + 1) * 2);
for (int a = 0; a <= sizex; a++) {
float pos = ((float)a) / sizex;
BKE_colorband_evaluate(coba, pos, colf);
@@ -1127,17 +1444,17 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
v1[0] = v2[0] = x1 + a;
- glColor4fv(colf);
- glVertex2fv(v1);
- glVertex2fv(v2);
+ immAttrib4fv(color, colf);
+ immVertex2fv(position, v1);
+ immVertex2fv(position, v2);
}
- glEnd();
+ immEnd();
/* layer: color ramp without alpha for reference when manipulating ramp properties */
v1[1] = y1;
v2[1] = y1 + sizey_solid;
- glBegin(GL_TRIANGLE_STRIP);
+ immBegin(GWN_PRIM_TRI_STRIP, (sizex + 1) * 2);
for (int a = 0; a <= sizex; a++) {
float pos = ((float)a) / sizex;
BKE_colorband_evaluate(coba, pos, colf);
@@ -1146,31 +1463,48 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
v1[0] = v2[0] = x1 + a;
- glColor4f(colf[0], colf[1], colf[2], 1.0f);
- glVertex2fv(v1);
- glVertex2fv(v2);
+ immAttrib4f(color, colf[0], colf[1], colf[2], 1.0f);
+ immVertex2fv(position, v1);
+ immVertex2fv(position, v2);
}
- glEnd();
+ immEnd();
+
+ immUnbindProgram();
glDisable(GL_BLEND);
+ /* New format */
+ format = immVertexFormat();
+ position = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* layer: box outline */
- glColor4f(0.0, 0.0, 0.0, 1.0);
- fdrawbox(x1, y1, x1 + sizex, rect->ymax);
-
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 1.0f);
+ imm_draw_box_wire_2d(position, x1, y1, x1 + sizex, rect->ymax);
+
/* layer: box outline */
glEnable(GL_BLEND);
- glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
- fdrawline(x1, y1, x1 + sizex, y1);
- glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
- fdrawline(x1, y1 - 1, x1 + sizex, y1 - 1);
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(position, x1, y1);
+ immVertex2f(position, x1 + sizex, y1);
+ immEnd();
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.25f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(position, x1, y1 - 1);
+ immVertex2f(position, x1 + sizex, y1 - 1);
+ immEnd();
+
glDisable(GL_BLEND);
/* layer: draw handles */
for (int a = 0; a < coba->tot; a++, cbd++) {
if (a != coba->cur) {
float pos = x1 + cbd->pos * (sizex - 1) + 1;
- ui_draw_colorband_handle(rect, pos, &cbd->r, display, false);
+ ui_draw_colorband_handle(position, rect, pos, &cbd->r, display, false);
}
}
@@ -1178,117 +1512,100 @@ void ui_draw_but_COLORBAND(uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti
if (coba->tot != 0) {
cbd = &coba->data[coba->cur];
float pos = x1 + cbd->pos * (sizex - 1) + 1;
- ui_draw_colorband_handle(rect, pos, &cbd->r, display, true);
+ ui_draw_colorband_handle(position, rect, pos, &cbd->r, display, true);
}
+
+ immUnbindProgram();
}
void ui_draw_but_UNITVEC(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
{
- static GLuint displist = 0;
+ /* sphere color */
float diffuse[3] = {1.0f, 1.0f, 1.0f};
+ float light[3];
float size;
/* backdrop */
- glColor3ubv((unsigned char *)wcol->inner);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f);
+ UI_draw_roundbox_3ubAlpha(true, rect->xmin, rect->ymin, rect->xmax, rect->ymax, 5.0f, (unsigned char *)wcol->inner, 255);
- /* sphere color */
glCullFace(GL_BACK);
glEnable(GL_CULL_FACE);
/* setup lights */
- GPULightData light = {0};
- light.type = GPU_LIGHT_SUN;
- copy_v3_v3(light.diffuse, diffuse);
- zero_v3(light.specular);
- ui_but_v3_get(but, light.direction);
-
- GPU_basic_shader_light_set(0, &light);
- for (int a = 1; a < 8; a++)
- GPU_basic_shader_light_set(a, NULL);
-
- /* setup shader */
- GPU_basic_shader_colors(diffuse, NULL, 0, 1.0f);
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING);
+ ui_but_v3_get(but, light);
/* transform to button */
- glPushMatrix();
- glTranslatef(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect), 0.0f);
+ gpuPushMatrix();
if (BLI_rcti_size_x(rect) < BLI_rcti_size_y(rect))
- size = BLI_rcti_size_x(rect) / 200.f;
+ size = 0.5f * BLI_rcti_size_x(rect);
else
- size = BLI_rcti_size_y(rect) / 200.f;
-
- glScalef(size, size, MIN2(size, 1.0f));
+ size = 0.5f * BLI_rcti_size_y(rect);
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_FILL);
- GPU_basic_shader_bind(GPU_basic_shader_bound_options());
- gluSphere(qobj, 100.0, 32, 24);
- gluDeleteQuadric(qobj);
-
- glEndList();
- }
+ gpuTranslate2f(rect->xmin + 0.5f * BLI_rcti_size_x(rect), rect->ymin + 0.5f * BLI_rcti_size_y(rect));
+ gpuScaleUniform(size);
- glCallList(displist);
+ Gwn_Batch *sphere = GPU_batch_preset_sphere(2);
+ GWN_batch_program_set_builtin(sphere, GPU_SHADER_SIMPLE_LIGHTING);
+ GWN_batch_uniform_4f(sphere, "color", diffuse[0], diffuse[1], diffuse[2], 1.0f);
+ GWN_batch_uniform_3fv(sphere, "light", light);
+ GWN_batch_draw(sphere);
/* restore */
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- GPU_default_lights();
glDisable(GL_CULL_FACE);
/* AA circle */
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3ubv((unsigned char *)wcol->inner);
+
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
- glColor3ubv((unsigned char *)wcol->inner);
- glutil_draw_lined_arc(0.0f, M_PI * 2.0, 100.0f, 32);
+ imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, 1.0f, 32);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
/* matrix after circle */
- glPopMatrix();
+ gpuPopMatrix();
- /* We disabled all blender lights above, so restore them here. */
- GPU_default_lights();
+ immUnbindProgram();
}
-static void ui_draw_but_curve_grid(const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
+static void ui_draw_but_curve_grid(unsigned int pos, const rcti *rect, float zoomx, float zoomy, float offsx, float offsy, float step)
{
- glBegin(GL_LINES);
float dx = step * zoomx;
float fx = rect->xmin + zoomx * (-offsx);
if (fx > rect->xmin) fx -= dx * (floorf(fx - rect->xmin));
- while (fx < rect->xmax) {
- glVertex2f(fx, rect->ymin);
- glVertex2f(fx, rect->ymax);
- fx += dx;
- }
float dy = step * zoomy;
float fy = rect->ymin + zoomy * (-offsy);
if (fy > rect->ymin) fy -= dy * (floorf(fy - rect->ymin));
+
+ float line_count = floorf((rect->xmax - fx) / dx) + 1.0f +
+ floorf((rect->ymax - fy) / dy) + 1.0f;
+
+ immBegin(GWN_PRIM_LINES, (int)line_count * 2);
+ while (fx < rect->xmax) {
+ immVertex2f(pos, fx, rect->ymin);
+ immVertex2f(pos, fx, rect->ymax);
+ fx += dx;
+ }
while (fy < rect->ymax) {
- glVertex2f(rect->xmin, fy);
- glVertex2f(rect->xmax, fy);
+ immVertex2f(pos, rect->xmin, fy);
+ immVertex2f(pos, rect->xmax, fy);
fy += dy;
}
- glEnd();
+ immEnd();
}
static void gl_shaded_color(unsigned char *col, int shade)
{
- glColor3ub(col[0] - shade > 0 ? col[0] - shade : 0,
- col[1] - shade > 0 ? col[1] - shade : 0,
- col[2] - shade > 0 ? col[2] - shade : 0);
+ immUniformColor3ub(col[0] - shade > 0 ? col[0] - shade : 0,
+ col[1] - shade > 0 ? col[1] - shade : 0,
+ col[2] - shade > 0 ? col[2] - shade : 0);
}
void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti *rect)
@@ -1306,14 +1623,15 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti
/* need scissor test, curve can draw outside of boundary */
GLint scissor[4];
- glGetIntegerv(GL_VIEWPORT, scissor);
+ glGetIntegerv(GL_SCISSOR_BOX, scissor);
rcti scissor_new = {
- .xmin = ar->winrct.xmin + rect->xmin,
- .ymin = ar->winrct.ymin + rect->ymin,
- .xmax = ar->winrct.xmin + rect->xmax,
- .ymax = ar->winrct.ymin + rect->ymax
+ .xmin = rect->xmin,
+ .ymin = rect->ymin,
+ .xmax = rect->xmax,
+ .ymax = rect->ymax
};
- BLI_rcti_isect(&scissor_new, &ar->winrct, &scissor_new);
+ rcti scissor_region = {0, ar->winx, 0, ar->winy};
+ BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
glScissor(scissor_new.xmin,
scissor_new.ymin,
BLI_rcti_size_x(&scissor_new),
@@ -1324,10 +1642,8 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti
float zoomy = (BLI_rcti_size_y(rect) - 2.0f) / BLI_rctf_size_y(&cumap->curr);
float offsx = cumap->curr.xmin - (1.0f / zoomx);
float offsy = cumap->curr.ymin - (1.0f / zoomy);
-
- glLineWidth(1.0f);
- /* backdrop */
+ /* Do this first to not mess imm context */
if (but->a1 == UI_GRAD_H) {
/* magic trigger for curve backgrounds */
float col[3] = {0.0f, 0.0f, 0.0f}; /* dummy arg */
@@ -1340,96 +1656,105 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti
};
ui_draw_gradient(&grid, col, UI_GRAD_H, 1.0f);
+ }
+
+ glLineWidth(1.0f);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* backdrop */
+ if (but->a1 == UI_GRAD_H) {
/* grid, hsv uses different grid */
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4ub(0, 0, 0, 48);
- ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.1666666f);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ immUniformColor4ub(0, 0, 0, 48);
+ ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.1666666f);
glDisable(GL_BLEND);
}
else {
if (cumap->flag & CUMA_DO_CLIP) {
gl_shaded_color((unsigned char *)wcol->inner, -20);
- glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
- glColor3ubv((unsigned char *)wcol->inner);
- glRectf(rect->xmin + zoomx * (cumap->clipr.xmin - offsx),
- rect->ymin + zoomy * (cumap->clipr.ymin - offsy),
- rect->xmin + zoomx * (cumap->clipr.xmax - offsx),
- rect->ymin + zoomy * (cumap->clipr.ymax - offsy));
+ immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+ immUniformColor3ubv((unsigned char *)wcol->inner);
+ immRectf(pos, rect->xmin + zoomx * (cumap->clipr.xmin - offsx),
+ rect->ymin + zoomy * (cumap->clipr.ymin - offsy),
+ rect->xmin + zoomx * (cumap->clipr.xmax - offsx),
+ rect->ymin + zoomy * (cumap->clipr.ymax - offsy));
}
else {
- glColor3ubv((unsigned char *)wcol->inner);
- glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+ immUniformColor3ubv((unsigned char *)wcol->inner);
+ immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
}
/* grid, every 0.25 step */
gl_shaded_color((unsigned char *)wcol->inner, -16);
- ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 0.25f);
+ ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 0.25f);
/* grid, every 1.0 step */
gl_shaded_color((unsigned char *)wcol->inner, -24);
- ui_draw_but_curve_grid(rect, zoomx, zoomy, offsx, offsy, 1.0f);
+ ui_draw_but_curve_grid(pos, rect, zoomx, zoomy, offsx, offsy, 1.0f);
/* axes */
gl_shaded_color((unsigned char *)wcol->inner, -50);
- glBegin(GL_LINES);
- glVertex2f(rect->xmin, rect->ymin + zoomy * (-offsy));
- glVertex2f(rect->xmax, rect->ymin + zoomy * (-offsy));
- glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymin);
- glVertex2f(rect->xmin + zoomx * (-offsx), rect->ymax);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, rect->xmin, rect->ymin + zoomy * (-offsy));
+ immVertex2f(pos, rect->xmax, rect->ymin + zoomy * (-offsy));
+ immVertex2f(pos, rect->xmin + zoomx * (-offsx), rect->ymin);
+ immVertex2f(pos, rect->xmin + zoomx * (-offsx), rect->ymax);
+ immEnd();
}
/* cfra option */
/* XXX 2.48 */
#if 0
if (cumap->flag & CUMA_DRAW_CFRA) {
- glColor3ub(0x60, 0xc0, 0x40);
- glBegin(GL_LINES);
- glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin);
- glVertex2f(rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax);
- glEnd();
+ immUniformColor3ub(0x60, 0xc0, 0x40);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymin);
+ immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[0] - offsx), rect->ymax);
+ immEnd();
}
#endif
/* sample option */
if (cumap->flag & CUMA_DRAW_SAMPLE) {
- glBegin(GL_LINES); /* will draw one of the following 3 lines */
+ immBegin(GWN_PRIM_LINES, 2); /* will draw one of the following 3 lines */
if (but->a1 == UI_GRAD_H) {
float tsample[3];
float hsv[3];
linearrgb_to_srgb_v3_v3(tsample, cumap->sample);
rgb_to_hsv_v(tsample, hsv);
- glColor3ub(240, 240, 240);
+ immUniformColor3ub(240, 240, 240);
- glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin);
- glVertex2f(rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax);
+ immVertex2f(pos, rect->xmin + zoomx * (hsv[0] - offsx), rect->ymin);
+ immVertex2f(pos, rect->xmin + zoomx * (hsv[0] - offsx), rect->ymax);
}
else if (cumap->cur == 3) {
float lum = IMB_colormanagement_get_luminance(cumap->sample);
- glColor3ub(240, 240, 240);
+ immUniformColor3ub(240, 240, 240);
- glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymin);
- glVertex2f(rect->xmin + zoomx * (lum - offsx), rect->ymax);
+ immVertex2f(pos, rect->xmin + zoomx * (lum - offsx), rect->ymin);
+ immVertex2f(pos, rect->xmin + zoomx * (lum - offsx), rect->ymax);
}
else {
if (cumap->cur == 0)
- glColor3ub(240, 100, 100);
+ immUniformColor3ub(240, 100, 100);
else if (cumap->cur == 1)
- glColor3ub(100, 240, 100);
+ immUniformColor3ub(100, 240, 100);
else
- glColor3ub(100, 100, 240);
+ immUniformColor3ub(100, 100, 240);
- glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin);
- glVertex2f(rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax);
+ immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymin);
+ immVertex2f(pos, rect->xmin + zoomx * (cumap->sample[cumap->cur] - offsx), rect->ymax);
}
- glEnd();
+ immEnd();
}
/* the curve */
- glColor3ubv((unsigned char *)wcol->item);
+ immUniformColor3ubv((unsigned char *)wcol->item);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
- glBegin(GL_LINE_STRIP);
+ immBegin(GWN_PRIM_LINE_STRIP, (CM_TABLE + 1) + 2);
if (cuma->table == NULL)
curvemapping_changed(cumap, false);
@@ -1438,55 +1763,70 @@ void ui_draw_but_CURVE(ARegion *ar, uiBut *but, uiWidgetColors *wcol, const rcti
/* first point */
if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
- glVertex2f(rect->xmin, rect->ymin + zoomy * (cmp[0].y - offsy));
+ immVertex2f(pos, rect->xmin, rect->ymin + zoomy * (cmp[0].y - offsy));
}
else {
float fx = rect->xmin + zoomx * (cmp[0].x - offsx + cuma->ext_in[0]);
float fy = rect->ymin + zoomy * (cmp[0].y - offsy + cuma->ext_in[1]);
- glVertex2f(fx, fy);
+ immVertex2f(pos, fx, fy);
}
for (int a = 0; a <= CM_TABLE; a++) {
float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
- glVertex2f(fx, fy);
+ immVertex2f(pos, fx, fy);
}
/* last point */
if ((cuma->flag & CUMA_EXTEND_EXTRAPOLATE) == 0) {
- glVertex2f(rect->xmax, rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy));
+ immVertex2f(pos, rect->xmax, rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy));
}
else {
float fx = rect->xmin + zoomx * (cmp[CM_TABLE].x - offsx - cuma->ext_out[0]);
float fy = rect->ymin + zoomy * (cmp[CM_TABLE].y - offsy - cuma->ext_out[1]);
- glVertex2f(fx, fy);
+ immVertex2f(pos, fx, fy);
}
- glEnd();
+ immEnd();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
+ immUnbindProgram();
/* the points, use aspect to make them visible on edges */
+ format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
cmp = cuma->curve;
glPointSize(3.0f);
- glBegin(GL_POINTS);
+ immBegin(GWN_PRIM_POINTS, cuma->totpoint);
for (int a = 0; a < cuma->totpoint; a++) {
+ float color[4];
if (cmp[a].flag & CUMA_SELECT)
- UI_ThemeColor(TH_TEXT_HI);
+ UI_GetThemeColor4fv(TH_TEXT_HI, color);
else
- UI_ThemeColor(TH_TEXT);
+ UI_GetThemeColor4fv(TH_TEXT, color);
float fx = rect->xmin + zoomx * (cmp[a].x - offsx);
float fy = rect->ymin + zoomy * (cmp[a].y - offsy);
- glVertex2f(fx, fy);
+ immAttrib4fv(col, color);
+ immVertex2f(pos, fx, fy);
}
- glEnd();
+ immEnd();
+ immUnbindProgram();
/* restore scissortest */
glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
/* outline */
- glColor3ubv((unsigned char *)wcol->outline);
- fdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+ format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor3ubv((unsigned char *)wcol->outline);
+ imm_draw_box_wire_2d(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+
+ immUnbindProgram();
}
-void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
+void ui_draw_but_TRACKPREVIEW(ARegion *UNUSED(ar), uiBut *but, uiWidgetColors *UNUSED(wcol), const rcti *recti)
{
bool ok = false;
MovieClipScopes *scopes = (MovieClipScopes *)but->poin;
@@ -1502,20 +1842,20 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
int height = BLI_rctf_size_y(&rect);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* need scissor test, preview image can draw outside of boundary */
GLint scissor[4];
- glGetIntegerv(GL_VIEWPORT, scissor);
- glScissor(ar->winrct.xmin + (rect.xmin - 1),
- ar->winrct.ymin + (rect.ymin - 1),
+ glGetIntegerv(GL_SCISSOR_BOX, scissor);
+ glScissor((rect.xmin - 1),
+ (rect.ymin - 1),
(rect.xmax + 1) - (rect.xmin - 1),
(rect.ymax + 1) - (rect.ymin - 1));
if (scopes->track_disabled) {
- glColor4f(0.7f, 0.3f, 0.3f, 0.3f);
+ float color[4] = {0.7f, 0.3f, 0.3f, 0.3f};
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f);
+ UI_draw_roundbox_4fv(true, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
ok = true;
}
@@ -1542,62 +1882,72 @@ void ui_draw_but_TRACKPREVIEW(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wc
}
if (!ok && scopes->track_preview) {
- glPushMatrix();
+ gpuPushMatrix();
/* draw content of pattern area */
- glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin, scissor[2], scissor[3]);
+ glScissor(rect.xmin, rect.ymin, scissor[2], scissor[3]);
if (width > 0 && height > 0) {
ImBuf *drawibuf = scopes->track_preview;
+ float col_sel[4], col_outline[4];
if (scopes->use_track_mask) {
- glColor4f(0.0f, 0.0f, 0.0f, 0.3f);
+ float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f);
+ UI_draw_roundbox_4fv(true, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
}
- glaDrawPixelsSafe(rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y,
- drawibuf->x, GL_RGBA, GL_UNSIGNED_BYTE, drawibuf->rect);
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex(&state, rect.xmin, rect.ymin + 1, drawibuf->x, drawibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, drawibuf->rect, 1.0f, 1.0f, NULL);
/* draw cross for pixel position */
- glTranslatef(rect.xmin + scopes->track_pos[0], rect.ymin + scopes->track_pos[1], 0.f);
- glScissor(ar->winrct.xmin + rect.xmin,
- ar->winrct.ymin + rect.ymin,
+ gpuTranslate2f(rect.xmin + scopes->track_pos[0], rect.ymin + scopes->track_pos[1]);
+ glScissor(rect.xmin,
+ rect.ymin,
BLI_rctf_size_x(&rect),
BLI_rctf_size_y(&rect));
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE);
-
- for (int a = 0; a < 2; a++) {
- if (a == 1) {
- GPU_basic_shader_bind_enable(GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(3, 0xAAAA);
- UI_ThemeColor(TH_SEL_MARKER);
- }
- else {
- UI_ThemeColor(TH_MARKER_OUTLINE);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ UI_GetThemeColor4fv(TH_SEL_MARKER, col_sel);
+ UI_GetThemeColor4fv(TH_MARKER_OUTLINE, col_outline);
+
+ /* Do stipple cross with geometry */
+ immBegin(GWN_PRIM_LINES, 7 * 2 * 2);
+ float pos_sel[8] = {-10.0f, -7.0f, -4.0f, -1.0f, 2.0f, 5.0f, 8.0f, 11.0f};
+ for (int axe = 0; axe < 2; ++axe) {
+ for (int i = 0; i < 7; ++i) {
+ float x1 = pos_sel[i] * (1 - axe);
+ float y1 = pos_sel[i] * axe;
+ float x2 = pos_sel[i + 1] * (1 - axe);
+ float y2 = pos_sel[i + 1] * axe;
+
+ if (i % 2 == 1)
+ immAttrib4fv(col, col_sel);
+ else
+ immAttrib4fv(col, col_outline);
+
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x2, y2);
}
-
- glBegin(GL_LINES);
- glVertex2f(-10.0f, 0.0f);
- glVertex2f(10.0f, 0.0f);
- glVertex2f(0.0f, -10.0f);
- glVertex2f(0.0f, 10.0f);
- glEnd();
}
+ immEnd();
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
+ immUnbindProgram();
}
- glPopMatrix();
+ gpuPopMatrix();
ok = true;
}
if (!ok) {
- glColor4f(0.f, 0.f, 0.f, 0.3f);
+ float color[4] = {0.0f, 0.0f, 0.0f, 0.3f};
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f);
+ UI_draw_roundbox_4fv(true, rect.xmin - 1, rect.ymin, rect.xmax + 1, rect.ymax + 1, 3.0f, color);
}
/* outline */
@@ -1628,41 +1978,48 @@ void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol
GLint scissor[4];
/* need scissor test, can draw outside of boundary */
- glGetIntegerv(GL_VIEWPORT, scissor);
+ glGetIntegerv(GL_SCISSOR_BOX, scissor);
rcti scissor_new = {
- .xmin = ar->winrct.xmin + recti->xmin,
- .ymin = ar->winrct.ymin + recti->ymin,
- .xmax = ar->winrct.xmin + recti->xmax,
- .ymax = ar->winrct.ymin + recti->ymax
+ .xmin = recti->xmin,
+ .ymin = recti->ymin,
+ .xmax = recti->xmax,
+ .ymax = recti->ymax
};
- BLI_rcti_isect(&scissor_new, &ar->winrct, &scissor_new);
+ rcti scissor_region = {0, ar->winx, 0, ar->winy};
+
+ BLI_rcti_isect(&scissor_new, &scissor_region, &scissor_new);
glScissor(scissor_new.xmin,
scissor_new.ymin,
BLI_rcti_size_x(&scissor_new),
BLI_rcti_size_y(&scissor_new));
- glColor4ubv(but->col);
-
float x = 0.5f * (recti->xmin + recti->xmax);
float y = 0.5f * (recti->ymin + recti->ymax);
-
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ubv(but->col);
+
glEnable(GL_BLEND);
- glBegin(GL_POLYGON);
+ immBegin(GWN_PRIM_TRI_FAN, 16);
for (int a = 0; a < 16; a++)
- glVertex2f(x + size * si[a], y + size * co[a]);
- glEnd();
+ immVertex2f(pos, x + size * si[a], y + size * co[a]);
+ immEnd();
- glColor4ub(0, 0, 0, 150);
+ immUniformColor4ub(0, 0, 0, 150);
glLineWidth(1);
glEnable(GL_LINE_SMOOTH);
- glBegin(GL_LINE_LOOP);
+ immBegin(GWN_PRIM_LINE_LOOP, 16);
for (int a = 0; a < 16; a++)
- glVertex2f(x + size * si[a], y + size * co[a]);
- glEnd();
+ immVertex2f(pos, x + size * si[a], y + size * co[a]);
+ immEnd();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
+
+ immUnbindProgram();
/* restore scissortest */
glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
@@ -1670,47 +2027,91 @@ void ui_draw_but_NODESOCKET(ARegion *ar, uiBut *but, uiWidgetColors *UNUSED(wcol
/* ****************************************************** */
+/* TODO: high quality UI drop shadows using GLSL shader and single draw call
+ * would replace / modify the following 3 functions - merwin
+ */
-static void ui_shadowbox(float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
+static void ui_shadowbox(unsigned pos, unsigned color, float minx, float miny, float maxx, float maxy, float shadsize, unsigned char alpha)
{
+ /* v1-_
+ * | -_v2
+ * | |
+ * | |
+ * | |
+ * v7_______v3____v4
+ * \ | /
+ * \ | _v5
+ * v8______v6_-
+ */
+ const float v1[2] = {maxx, maxy - 0.3f * shadsize};
+ const float v2[2] = {maxx + shadsize, maxy - 0.75f * shadsize};
+ const float v3[2] = {maxx, miny};
+ const float v4[2] = {maxx + shadsize, miny};
+
+ const float v5[2] = {maxx + 0.7f * shadsize, miny - 0.7f * shadsize};
+
+ const float v6[2] = {maxx, miny - shadsize};
+ const float v7[2] = {minx + 0.3f * shadsize, miny};
+ const float v8[2] = {minx + 0.5f * shadsize, miny - shadsize};
+
/* right quad */
- glColor4ub(0, 0, 0, alpha);
- glVertex2f(maxx, miny);
- glVertex2f(maxx, maxy - 0.3f * shadsize);
- glColor4ub(0, 0, 0, 0);
- glVertex2f(maxx + shadsize, maxy - 0.75f * shadsize);
- glVertex2f(maxx + shadsize, miny);
-
+ immAttrib4ub(color, 0, 0, 0, alpha);
+ immVertex2fv(pos, v3);
+ immVertex2fv(pos, v1);
+ immAttrib4ub(color, 0, 0, 0, 0);
+ immVertex2fv(pos, v2);
+
+ immVertex2fv(pos, v2);
+ immVertex2fv(pos, v4);
+ immAttrib4ub(color, 0, 0, 0, alpha);
+ immVertex2fv(pos, v3);
+
/* corner shape */
- glColor4ub(0, 0, 0, alpha);
- glVertex2f(maxx, miny);
- glColor4ub(0, 0, 0, 0);
- glVertex2f(maxx + shadsize, miny);
- glVertex2f(maxx + 0.7f * shadsize, miny - 0.7f * shadsize);
- glVertex2f(maxx, miny - shadsize);
-
+ /* immAttrib4ub(color, 0, 0, 0, alpha); */ /* Not needed, done above in previous tri */
+ immVertex2fv(pos, v3);
+ immAttrib4ub(color, 0, 0, 0, 0);
+ immVertex2fv(pos, v4);
+ immVertex2fv(pos, v5);
+
+ immVertex2fv(pos, v5);
+ immVertex2fv(pos, v6);
+ immAttrib4ub(color, 0, 0, 0, alpha);
+ immVertex2fv(pos, v3);
+
/* bottom quad */
- glColor4ub(0, 0, 0, alpha);
- glVertex2f(minx + 0.3f * shadsize, miny);
- glVertex2f(maxx, miny);
- glColor4ub(0, 0, 0, 0);
- glVertex2f(maxx, miny - shadsize);
- glVertex2f(minx + 0.5f * shadsize, miny - shadsize);
+ /* immAttrib4ub(color, 0, 0, 0, alpha); */ /* Not needed, done above in previous tri */
+ immVertex2fv(pos, v3);
+ immAttrib4ub(color, 0, 0, 0, 0);
+ immVertex2fv(pos, v6);
+ immVertex2fv(pos, v8);
+
+ immVertex2fv(pos, v8);
+ immAttrib4ub(color, 0, 0, 0, alpha);
+ immVertex2fv(pos, v7);
+ immVertex2fv(pos, v3);
}
void UI_draw_box_shadow(unsigned char alpha, float minx, float miny, float maxx, float maxy)
{
glEnable(GL_BLEND);
-
- glBegin(GL_QUADS);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+
+ immBegin(GWN_PRIM_TRIS, 54);
/* accumulated outline boxes to make shade not linear, is more pleasant */
- ui_shadowbox(minx, miny, maxx, maxy, 11.0, (20 * alpha) >> 8);
- ui_shadowbox(minx, miny, maxx, maxy, 7.0, (40 * alpha) >> 8);
- ui_shadowbox(minx, miny, maxx, maxy, 5.0, (80 * alpha) >> 8);
-
- glEnd();
+ ui_shadowbox(pos, color, minx, miny, maxx, maxy, 11.0, (20 * alpha) >> 8);
+ ui_shadowbox(pos, color, minx, miny, maxx, maxy, 7.0, (40 * alpha) >> 8);
+ ui_shadowbox(pos, color, minx, miny, maxx, maxy, 5.0, (80 * alpha) >> 8);
+ immEnd();
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
@@ -1719,8 +2120,8 @@ void ui_draw_dropshadow(const rctf *rct, float radius, float aspect, float alpha
{
float rad;
- if (radius > (BLI_rctf_size_y(rct) - 10.0f) / 2.0f)
- rad = (BLI_rctf_size_y(rct) - 10.0f) / 2.0f;
+ if (radius > (BLI_rctf_size_y(rct) - 10.0f) * 0.5f)
+ rad = (BLI_rctf_size_y(rct) - 10.0f) * 0.5f;
else
rad = radius;
@@ -1736,34 +2137,46 @@ void ui_draw_dropshadow(const rctf *rct, float radius, float aspect, float alpha
}
glEnable(GL_BLEND);
-
const float dalpha = alpha * 2.0f / 255.0f;
float calpha = dalpha;
- for (; i--; a -= aspect) {
+ float visibility = 1.0f;
+ for (; i--;) {
/* alpha ranges from 2 to 20 or so */
- glColor4f(0.0f, 0.0f, 0.0f, calpha);
+#if 0 /* Old Method (pre 2.8) */
+ float color[4] = {0.0f, 0.0f, 0.0f, calpha};
+ UI_draw_roundbox_4fv(true, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a, color);
+#endif
+ /* Compute final visibility to match old method result. */
+ /* TODO we could just find a better fit function inside the shader instead of this. */
+ visibility = visibility * (1.0f - calpha);
calpha += dalpha;
-
- UI_draw_roundbox_gl_mode(GL_POLYGON, rct->xmin - a, rct->ymin - a, rct->xmax + a, rct->ymax - 10.0f + a, rad + a);
}
+ uiWidgetBaseParameters widget_params = {
+ .recti.xmin = rct->xmin, .recti.ymin = rct->ymin,
+ .recti.xmax = rct->xmax, .recti.ymax = rct->ymax - 10.0f,
+ .rect.xmin = rct->xmin - a, .rect.ymin = rct->ymin - a,
+ .rect.xmax = rct->xmax + a, .rect.ymax = rct->ymax - 10.0f + a,
+ .radi = rad,
+ .rad = rad + a,
+ .round_corners[0] = (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f,
+ .round_corners[1] = (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[2] = (roundboxtype & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f,
+ .round_corners[3] = (roundboxtype & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f,
+ .alpha_discard = 1.0f,
+ };
+
+ Gwn_Batch *batch = ui_batch_roundbox_shadow_get();
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_SHADOW);
+ GWN_batch_uniform_4fv_array(batch, "parameters", 4, (float *)&widget_params);
+ GWN_batch_uniform_1f(batch, "alpha", 1.0f - visibility);
+ GWN_batch_draw(batch);
+
/* outline emphasis */
glEnable(GL_LINE_SMOOTH);
- glColor4ub(0, 0, 0, 100);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, rct->xmin - 0.5f, rct->ymin - 0.5f, rct->xmax + 0.5f, rct->ymax + 0.5f, radius + 0.5f);
+ float color[4] = {0.0f, 0.0f, 0.0f, 0.4f};
+ UI_draw_roundbox_4fv(false, rct->xmin - 0.5f, rct->ymin - 0.5f, rct->xmax + 0.5f, rct->ymax + 0.5f, radius + 0.5f, color);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
-
-/**
- * Reset GL state (keep minimal).
- *
- * \note Blender's internal code doesn't assume these are reset,
- * but external callbacks may depend on their state.
- */
-void UI_reinit_gl_state(void)
-{
- glLineWidth(1.0f);
- glPointSize(1.0f);
-}
diff --git a/source/blender/editors/interface/interface_eyedropper.c b/source/blender/editors/interface/interface_eyedropper.c
index 381d9f3cc42..8cb55b724fb 100644
--- a/source/blender/editors/interface/interface_eyedropper.c
+++ b/source/blender/editors/interface/interface_eyedropper.c
@@ -135,8 +135,8 @@ void eyedropper_draw_cursor_text(const struct bContext *C, const ARegion *ar, co
wmWindow *win = CTX_wm_window(C);
int x = win->eventstate->x;
int y = win->eventstate->y;
- const unsigned char fg[4] = {255, 255, 255, 255};
- const unsigned char bg[4] = {0, 0, 0, 50};
+ const float col_fg[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ const float col_bg[4] = {0.0f, 0.0f, 0.0f, 0.2f};
if ((name[0] == '\0') ||
@@ -150,7 +150,7 @@ void eyedropper_draw_cursor_text(const struct bContext *C, const ARegion *ar, co
y += U.widget_unit;
- UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, fg, bg);
+ UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, col_fg, col_bg);
}
@@ -165,8 +165,8 @@ void eyedropper_draw_cursor_text(const struct bContext *C, const ARegion *ar, co
*/
uiBut *eyedropper_get_property_button_under_mouse(bContext *C, const wmEvent *event)
{
- wmWindow *win = CTX_wm_window(C);
- ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, event->x, event->y);
+ bScreen *screen = CTX_wm_screen(C);
+ ScrArea *sa = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, event->x, event->y);
ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_ANY, event->x, event->y);
uiBut *but = ui_but_find_mouse_over(ar, event);
diff --git a/source/blender/editors/interface/interface_eyedropper_color.c b/source/blender/editors/interface/interface_eyedropper_color.c
index 052da74623f..f3301d55284 100644
--- a/source/blender/editors/interface/interface_eyedropper_color.c
+++ b/source/blender/editors/interface/interface_eyedropper_color.c
@@ -131,8 +131,8 @@ static void eyedropper_exit(bContext *C, wmOperator *op)
void eyedropper_color_sample_fl(bContext *C, int mx, int my, float r_col[3])
{
/* we could use some clever */
- wmWindow *win = CTX_wm_window(C);
- ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my);
+ bScreen *screen = CTX_wm_screen(C);
+ ScrArea *sa = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my);
const char *display_device = CTX_data_scene(C)->display_settings.display_device;
struct ColorManagedDisplay *display = IMB_colormanagement_display_get_named(display_device);
diff --git a/source/blender/editors/interface/interface_eyedropper_datablock.c b/source/blender/editors/interface/interface_eyedropper_datablock.c
index 416022a9dd0..f814048c0c0 100644
--- a/source/blender/editors/interface/interface_eyedropper_datablock.c
+++ b/source/blender/editors/interface/interface_eyedropper_datablock.c
@@ -150,8 +150,8 @@ static void datadropper_exit(bContext *C, wmOperator *op)
static void datadropper_id_sample_pt(bContext *C, DataDropper *ddr, int mx, int my, ID **r_id)
{
/* we could use some clever */
- wmWindow *win = CTX_wm_window(C);
- ScrArea *sa = BKE_screen_find_area_xy(win->screen, -1, mx, my);
+ bScreen *screen = CTX_wm_screen(C);
+ ScrArea *sa = BKE_screen_find_area_xy(screen, -1, mx, my);
ScrArea *area_prev = CTX_wm_area(C);
ARegion *ar_prev = CTX_wm_region(C);
diff --git a/source/blender/editors/interface/interface_eyedropper_depth.c b/source/blender/editors/interface/interface_eyedropper_depth.c
index b2ba7594fcb..fd9c5f1869d 100644
--- a/source/blender/editors/interface/interface_eyedropper_depth.c
+++ b/source/blender/editors/interface/interface_eyedropper_depth.c
@@ -44,6 +44,8 @@
#include "BKE_screen.h"
#include "BKE_unit.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "UI_interface.h"
@@ -151,9 +153,10 @@ static void depthdropper_exit(bContext *C, wmOperator *op)
static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx, int my, float *r_depth)
{
/* we could use some clever */
- wmWindow *win = CTX_wm_window(C);
- ScrArea *sa = BKE_screen_find_area_xy(win->screen, SPACE_TYPE_ANY, mx, my);
- Scene *scene = win->screen->scene;
+ bScreen *screen = CTX_wm_screen(C);
+ ScrArea *sa = BKE_screen_find_area_xy(screen, SPACE_TYPE_ANY, mx, my);
+ Scene *scene = CTX_data_scene(C);
+
UnitSettings *unit = &scene->unit;
const bool do_split = (unit->flag & USER_UNIT_OPT_SPLIT) != 0;
@@ -166,6 +169,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx,
if (sa->spacetype == SPACE_VIEW3D) {
ARegion *ar = BKE_area_find_region_xy(sa, RGN_TYPE_WINDOW, mx, my);
if (ar) {
+ struct Depsgraph *graph = CTX_data_depsgraph(C);
View3D *v3d = sa->spacedata.first;
RegionView3D *rv3d = ar->regiondata;
/* weak, we could pass in some reference point */
@@ -183,7 +187,7 @@ static void depthdropper_depth_sample_pt(bContext *C, DepthDropper *ddr, int mx,
view3d_operator_needs_opengl(C);
- if (ED_view3d_autodist(scene, ar, v3d, mval, co, true, NULL)) {
+ if (ED_view3d_autodist(graph, ar, v3d, mval, co, true, NULL)) {
const float mval_center_fl[2] = {
(float)ar->winx / 2,
(float)ar->winy / 2};
diff --git a/source/blender/editors/interface/interface_eyedropper_driver.c b/source/blender/editors/interface/interface_eyedropper_driver.c
index 1b7407c87dd..50a8473135a 100644
--- a/source/blender/editors/interface/interface_eyedropper_driver.c
+++ b/source/blender/editors/interface/interface_eyedropper_driver.c
@@ -42,7 +42,9 @@
#include "BKE_context.h"
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -130,8 +132,8 @@ static void driverdropper_sample(bContext *C, wmOperator *op, const wmEvent *eve
if (success) {
/* send updates */
UI_context_update_anim_flag(C);
- DAG_relations_tag_update(CTX_data_main(C));
- DAG_id_tag_update(ddr->ptr.id.data, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_relations_tag_update(CTX_data_main(C));
+ DEG_id_tag_update(ddr->ptr.id.data, OB_RECALC_OB | OB_RECALC_DATA);
WM_event_add_notifier(C, NC_ANIMATION | ND_FCURVES_ORDER, NULL); // XXX
}
}
diff --git a/source/blender/editors/interface/interface_handlers.c b/source/blender/editors/interface/interface_handlers.c
index 9f7cd62227c..704a602f6c1 100644
--- a/source/blender/editors/interface/interface_handlers.c
+++ b/source/blender/editors/interface/interface_handlers.c
@@ -39,9 +39,6 @@
#include "MEM_guardedalloc.h"
#include "DNA_brush_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -78,6 +75,7 @@
#include "ED_keyframing.h"
#include "UI_interface.h"
+#include "UI_view2d.h"
#include "BLF_api.h"
@@ -117,8 +115,6 @@
#define USE_KEYMAP_ADD_HACK
/* proto */
-static void ui_but_smart_controller_add(bContext *C, uiBut *from, uiBut *to);
-static void ui_but_link_add(bContext *C, uiBut *from, uiBut *to);
static int ui_do_but_EXIT(bContext *C, uiBut *but, struct uiHandleButtonData *data, const wmEvent *event);
static bool ui_but_find_select_in_enum__cmp(const uiBut *but_a, const uiBut *but_b);
static void ui_textedit_string_set(uiBut *but, struct uiHandleButtonData *data, const char *str);
@@ -133,7 +129,7 @@ static bool ui_mouse_motion_keynav_test(struct uiKeyNavLock *keynav, const wmEve
#define BUTTON_FLASH_DELAY 0.020
#define MENU_SCROLL_INTERVAL 0.1
#define PIE_MENU_INTERVAL 0.01
-#define BUTTON_AUTO_OPEN_THRESH 0.3
+#define BUTTON_AUTO_OPEN_THRESH 0.2
#define BUTTON_MOUSE_TOWARDS_THRESH 1.0
/* pixels to move the cursor to get out of keyboard navigation */
#define BUTTON_KEYNAV_PX_LIMIT 8
@@ -252,6 +248,9 @@ typedef struct uiHandleButtonMulti {
bool is_proportional;
+ /* In some cases we directly apply the changes to multiple buttons, so we don't want to do it twice. */
+ bool skip;
+
/* before activating, we need to check gesture direction
* accumulate signed cursor movement here so we can tell if this is a vertical motion or not. */
float drag_dir[2];
@@ -281,6 +280,7 @@ typedef struct uiHandleButtonData {
/* booleans (could be made into flags) */
bool cancel, escapecancel;
bool applied, applied_interactive;
+ bool changed_cursor;
wmTimer *flashtimer;
/* edited value */
@@ -639,11 +639,8 @@ PointerRNA *ui_handle_afterfunc_add_operator(wmOperatorType *ot, int opcontext,
static void popup_check(bContext *C, wmOperator *op)
{
- if (op && op->type->check && op->type->check(C, op)) {
- /* check for popup and re-layout buttons */
- ARegion *ar_menu = CTX_wm_menu(C);
- if (ar_menu)
- ED_region_tag_refresh_ui(ar_menu);
+ if (op && op->type->check) {
+ op->type->check(C, op);
}
}
@@ -724,8 +721,7 @@ static void ui_apply_but_undo(uiBut *but)
const char *str = NULL;
/* define which string to use for undo */
- if (ELEM(but->type, UI_BTYPE_LINK, UI_BTYPE_INLINK)) str = "Add button link";
- else if (but->type == UI_BTYPE_MENU) str = but->drawstr;
+ if (but->type == UI_BTYPE_MENU) str = but->drawstr;
else if (but->drawstr[0]) str = but->drawstr;
else str = but->tip;
@@ -784,7 +780,7 @@ static void ui_apply_but_funcs_after(bContext *C)
if (after.popup_op)
popup_check(C, after.popup_op);
-
+
if (after.opptr) {
/* free in advance to avoid leak on exit */
opptr = *after.opptr;
@@ -937,6 +933,20 @@ static void ui_apply_but_TEX(bContext *C, uiBut *but, uiHandleButtonData *data)
data->applied = true;
}
+static void ui_apply_but_TAB(bContext *C, uiBut *but, uiHandleButtonData *data)
+{
+ if (data->str) {
+ ui_but_string_set(C, but, data->str);
+ ui_but_update_edited(but);
+ }
+ else {
+ ui_apply_but_func(C, but);
+ }
+
+ data->retval = but->retval;
+ data->applied = true;
+}
+
static void ui_apply_but_NUM(bContext *C, uiBut *but, uiHandleButtonData *data)
{
if (data->str) {
@@ -1167,6 +1177,7 @@ static void ui_multibut_states_apply(bContext *C, uiHandleButtonData *data, uiBl
uiBut *but;
BLI_assert(data->multi_data.init == BUTTON_MULTI_INIT_ENABLE);
+ BLI_assert(data->multi_data.skip == false);
for (but = block->buttons.first; but; but = but->next) {
if (but->flag & UI_BUT_DRAG_MULTI) {
@@ -1782,223 +1793,6 @@ static bool ui_but_drag_init(
/* ********************** linklines *********************** */
-static void ui_linkline_remove_active(uiBlock *block)
-{
- uiBut *but;
- uiLink *link;
- uiLinkLine *line, *nline;
- int a, b;
-
- for (but = block->buttons.first; but; but = but->next) {
- if (but->type == UI_BTYPE_LINK && but->link) {
- for (line = but->link->lines.first; line; line = nline) {
- nline = line->next;
-
- if (line->flag & UI_SELECT) {
- BLI_remlink(&but->link->lines, line);
-
- link = line->from->link;
-
- /* are there more pointers allowed? */
- if (link->ppoin) {
-
- if (*(link->totlink) == 1) {
- *(link->totlink) = 0;
- MEM_freeN(*(link->ppoin));
- *(link->ppoin) = NULL;
- }
- else {
- b = 0;
- for (a = 0; a < (*(link->totlink)); a++) {
-
- if ((*(link->ppoin))[a] != line->to->poin) {
- (*(link->ppoin))[b] = (*(link->ppoin))[a];
- b++;
- }
- }
- (*(link->totlink))--;
- }
- }
- else {
- *(link->poin) = NULL;
- }
-
- MEM_freeN(line);
- }
- }
- }
- }
-}
-
-
-static uiLinkLine *ui_but_find_link(uiBut *from, uiBut *to)
-{
- uiLinkLine *line;
- uiLink *link;
-
- link = from->link;
- if (link) {
- for (line = link->lines.first; line; line = line->next) {
- if (line->from == from && line->to == to) {
- return line;
- }
- }
- }
- return NULL;
-}
-
-/* XXX BAD BAD HACK, fixme later **************** */
-/* Try to add an AND Controller between the sensor and the actuator logic bricks and to connect them all */
-static void ui_but_smart_controller_add(bContext *C, uiBut *from, uiBut *to)
-{
- Object *ob = NULL;
- bSensor *sens_iter;
- bActuator *act_to, *act_iter;
- bController *cont;
- bController ***sens_from_links;
- uiBut *tmp_but;
-
- uiLink *link = from->link;
-
- PointerRNA props_ptr, object_ptr;
-
- if (link->ppoin)
- sens_from_links = (bController ***)(link->ppoin);
- else return;
-
- act_to = (bActuator *)(to->poin);
-
- /* (1) get the object */
- CTX_DATA_BEGIN (C, Object *, ob_iter, selected_editable_objects)
- {
- for (sens_iter = ob_iter->sensors.first; sens_iter; sens_iter = sens_iter->next) {
- if (&(sens_iter->links) == sens_from_links) {
- ob = ob_iter;
- break;
- }
- }
- if (ob) break;
- } CTX_DATA_END;
-
- if (!ob) return;
-
- /* (2) check if the sensor and the actuator are from the same object */
- for (act_iter = ob->actuators.first; act_iter; act_iter = (bActuator *)act_iter->next) {
- if (act_iter == act_to)
- break;
- }
-
- /* only works if the sensor and the actuator are from the same object */
- if (!act_iter) return;
-
- /* in case the linked controller is not the active one */
- RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
-
- WM_operator_properties_create(&props_ptr, "LOGIC_OT_controller_add");
- RNA_string_set(&props_ptr, "object", ob->id.name + 2);
-
- /* (3) add a new controller */
- if (WM_operator_name_call(C, "LOGIC_OT_controller_add", WM_OP_EXEC_DEFAULT, &props_ptr) & OPERATOR_FINISHED) {
- cont = (bController *)ob->controllers.last;
- /* Quick fix to make sure we always have an AND controller.
- * It might be nicer to make sure the operator gives us the right one though... */
- cont->type = CONT_LOGIC_AND;
-
- /* (4) link the sensor->controller->actuator */
- tmp_but = MEM_callocN(sizeof(uiBut), "uiBut");
- UI_but_link_set(
- tmp_but, (void **)&cont, (void ***)&(cont->links),
- &cont->totlinks, from->link->tocode, (int)to->hardmin);
- tmp_but->hardmin = from->link->tocode;
- tmp_but->poin = (char *)cont;
-
- tmp_but->type = UI_BTYPE_INLINK;
- ui_but_link_add(C, from, tmp_but);
-
- tmp_but->type = UI_BTYPE_LINK;
- ui_but_link_add(C, tmp_but, to);
-
- /* (5) garbage collection */
- MEM_freeN(tmp_but->link);
- MEM_freeN(tmp_but);
- }
- WM_operator_properties_free(&props_ptr);
-}
-
-static void ui_but_link_add(bContext *C, uiBut *from, uiBut *to)
-{
- /* in 'from' we have to add a link to 'to' */
- uiLink *link;
- uiLinkLine *line;
- void **oldppoin;
- int a;
-
- if ((line = ui_but_find_link(from, to))) {
- line->flag |= UI_SELECT;
- ui_linkline_remove_active(from->block);
- return;
- }
-
- if (from->type == UI_BTYPE_INLINK && to->type == UI_BTYPE_INLINK) {
- return;
- }
- else if (from->type == UI_BTYPE_LINK && to->type == UI_BTYPE_INLINK) {
- if (from->link->tocode != (int)to->hardmin) {
- ui_but_smart_controller_add(C, from, to);
- return;
- }
- }
- else if (from->type == UI_BTYPE_INLINK && to->type == UI_BTYPE_LINK) {
- if (to->link->tocode == (int)from->hardmin) {
- return;
- }
- }
-
- link = from->link;
-
- /* are there more pointers allowed? */
- if (link->ppoin) {
- oldppoin = *(link->ppoin);
-
- (*(link->totlink))++;
- *(link->ppoin) = MEM_callocN(*(link->totlink) * sizeof(void *), "new link");
-
- for (a = 0; a < (*(link->totlink)) - 1; a++) {
- (*(link->ppoin))[a] = oldppoin[a];
- }
- (*(link->ppoin))[a] = to->poin;
-
- if (oldppoin) MEM_freeN(oldppoin);
- }
- else {
- *(link->poin) = to->poin;
- }
-
-}
-
-
-static void ui_apply_but_LINK(bContext *C, uiBut *but, uiHandleButtonData *data)
-{
- ARegion *ar = CTX_wm_region(C);
- uiBut *bt;
-
- for (bt = but->block->buttons.first; bt; bt = bt->next) {
- if (ui_but_contains_point_px(ar, bt, but->linkto[0] + ar->winrct.xmin, but->linkto[1] + ar->winrct.ymin) )
- break;
- }
- if (bt && bt != but) {
- if (!ELEM(bt->type, UI_BTYPE_LINK, UI_BTYPE_INLINK) || !ELEM(but->type, UI_BTYPE_LINK, UI_BTYPE_INLINK))
- return;
-
- if (but->type == UI_BTYPE_LINK) ui_but_link_add(C, but, bt);
- else ui_but_link_add(C, bt, but);
-
- ui_apply_but_func(C, but);
- data->retval = but->retval;
- }
- data->applied = true;
-}
-
static void ui_apply_but_IMAGE(bContext *C, uiBut *but, uiHandleButtonData *data)
{
ui_apply_but_func(C, but);
@@ -2117,6 +1911,9 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
case UI_BTYPE_LISTROW:
ui_apply_but_ROW(C, block, but, data);
break;
+ case UI_BTYPE_TAB:
+ ui_apply_but_TAB(C, but, data);
+ break;
case UI_BTYPE_SCROLL:
case UI_BTYPE_GRIP:
case UI_BTYPE_NUM:
@@ -2152,10 +1949,6 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
case UI_BTYPE_HOTKEY_EVENT:
ui_apply_but_BUT(C, but, data);
break;
- case UI_BTYPE_LINK:
- case UI_BTYPE_INLINK:
- ui_apply_but_LINK(C, but, data);
- break;
case UI_BTYPE_IMAGE:
ui_apply_but_IMAGE(C, but, data);
break;
@@ -2174,7 +1967,9 @@ static void ui_apply_but(bContext *C, uiBlock *block, uiBut *but, uiHandleButton
#ifdef USE_DRAG_MULTINUM
if (data->multi_data.has_mbuts) {
- if (data->multi_data.init == BUTTON_MULTI_INIT_ENABLE) {
+ if ((data->multi_data.init == BUTTON_MULTI_INIT_ENABLE) &&
+ (data->multi_data.skip == false))
+ {
if (data->cancel) {
ui_multibut_restore(C, data, block);
}
@@ -3167,6 +2962,9 @@ static void ui_textedit_end(bContext *C, uiBut *but, uiHandleButtonData *data)
ui_searchbox_free(C, data->searchbox);
data->searchbox = NULL;
+ if (but->free_search_arg) {
+ MEM_SAFE_FREE(but->search_arg);
+ }
}
but->editstr = NULL;
@@ -3638,6 +3436,7 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat
uiBlockCreateFunc func = NULL;
uiBlockHandleCreateFunc handlefunc = NULL;
uiMenuCreateFunc menufunc = NULL;
+ uiMenuCreateFunc popoverfunc = NULL;
void *arg = NULL;
switch (but->type) {
@@ -3657,6 +3456,11 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat
menufunc = but->menu_create_func;
arg = but->poin;
break;
+ case UI_BTYPE_POPOVER:
+ BLI_assert(but->menu_create_func);
+ popoverfunc = but->menu_create_func;
+ arg = but->poin;
+ break;
case UI_BTYPE_COLOR:
ui_but_v3_get(but, data->origvec);
copy_v3_v3(data->vec, data->origvec);
@@ -3681,6 +3485,11 @@ static void ui_block_open_begin(bContext *C, uiBut *but, uiHandleButtonData *dat
if (but->block->handle)
data->menu->popup = but->block->handle->popup;
}
+ else if (popoverfunc) {
+ data->menu = ui_popover_panel_create(C, data->region, but, popoverfunc, arg);
+ if (but->block->handle)
+ data->menu->popup = but->block->handle->popup;
+ }
#ifdef USE_ALLSELECT
{
@@ -3887,6 +3696,43 @@ static bool ui_but_is_mouse_over_icon_extra(const ARegion *region, uiBut *but, c
return BLI_rcti_isect_pt(&icon_rect, x, y);
}
+static int ui_do_but_TAB(bContext *C, uiBlock *block, uiBut *but, uiHandleButtonData *data, const wmEvent *event)
+{
+ if (data->state == BUTTON_STATE_HIGHLIGHT) {
+ if ((event->type == LEFTMOUSE) &&
+ ((event->val == KM_DBL_CLICK) || event->ctrl))
+ {
+ button_activate_state(C, but, BUTTON_STATE_TEXT_EDITING);
+ return WM_UI_HANDLER_BREAK;
+ }
+ else if (ELEM(event->type, LEFTMOUSE, PADENTER, RETKEY) && (event->val == KM_CLICK)) {
+ const bool has_icon_extra = ui_but_icon_extra_get(but) == UI_BUT_ICONEXTRA_CLEAR;
+
+ if (has_icon_extra && ui_but_is_mouse_over_icon_extra(data->region, but, &event->x)) {
+ uiButTab *tab = (uiButTab *)but;
+ wmOperatorType *ot_backup = but->optype;
+
+ but->optype = tab->unlink_ot;
+ /* Force calling unlink/delete operator. */
+ ui_apply_but(C, block, but, data, true);
+ but->optype = ot_backup;
+ }
+ button_activate_state(C, but, BUTTON_STATE_EXIT);
+ return WM_UI_HANDLER_BREAK;
+ }
+ }
+ else if (data->state == BUTTON_STATE_TEXT_EDITING) {
+ ui_do_but_textedit(C, block, but, data, event);
+ return WM_UI_HANDLER_BREAK;
+ }
+ else if (data->state == BUTTON_STATE_TEXT_SELECTING) {
+ ui_do_but_textedit_select(C, block, but, data, event);
+ return WM_UI_HANDLER_BREAK;
+ }
+
+ return WM_UI_HANDLER_CONTINUE;
+}
+
static int ui_do_but_TEX(
bContext *C, uiBlock *block, uiBut *but,
uiHandleButtonData *data, const wmEvent *event)
@@ -4326,6 +4172,54 @@ static bool ui_numedit_but_NUM(
return changed;
}
+static void ui_numedit_set_active(uiBut *but)
+{
+ int oldflag = but->drawflag;
+ but->drawflag &= ~(UI_BUT_ACTIVE_LEFT | UI_BUT_ACTIVE_RIGHT);
+
+ uiHandleButtonData *data = but->active;
+ if (!data) {
+ return;
+ }
+
+ /* Ignore once we start dragging. */
+ if (data->dragchange == false) {
+ const float handle_width = min_ff(BLI_rctf_size_x(&but->rect) / 3, BLI_rctf_size_y(&but->rect) * 0.7f);
+ /* we can click on the side arrows to increment/decrement,
+ * or click inside to edit the value directly */
+ int mx = data->window->eventstate->x;
+ int my = data->window->eventstate->x;
+ ui_window_to_block(data->region, but->block, &mx, &my);
+
+ if (mx < (but->rect.xmin + handle_width)) {
+ but->drawflag |= UI_BUT_ACTIVE_LEFT;
+ }
+ else if (mx > (but->rect.xmax - handle_width)) {
+ but->drawflag |= UI_BUT_ACTIVE_RIGHT;
+ }
+ }
+
+ /* Don't change the cursor once pressed. */
+ if ((but->flag & UI_SELECT) == 0) {
+ if ((but->drawflag & (UI_BUT_ACTIVE_LEFT)) || (but->drawflag & (UI_BUT_ACTIVE_RIGHT))) {
+ if (data->changed_cursor) {
+ WM_cursor_modal_restore(data->window);
+ data->changed_cursor = false;
+ }
+ }
+ else {
+ if (data->changed_cursor == false) {
+ WM_cursor_modal_set(data->window, CURSOR_X_MOVE);
+ data->changed_cursor = true;
+ }
+ }
+ }
+
+ if (but->drawflag != oldflag) {
+ ED_region_tag_redraw(data->region);
+ }
+}
+
static int ui_do_but_NUM(
bContext *C, uiBlock *block, uiBut *but,
uiHandleButtonData *data, const wmEvent *event)
@@ -4339,6 +4233,7 @@ static int ui_do_but_NUM(
my = screen_my = event->y;
ui_window_to_block(data->region, block, &mx, &my);
+ ui_numedit_set_active(but);
if (data->state == BUTTON_STATE_HIGHLIGHT) {
int type = event->type, val = event->val;
@@ -4448,16 +4343,13 @@ static int ui_do_but_NUM(
/* we can click on the side arrows to increment/decrement,
* or click inside to edit the value directly */
float tempf, softmin, softmax;
- float handlewidth;
int temp;
softmin = but->softmin;
softmax = but->softmax;
- handlewidth = min_ff(BLI_rctf_size_x(&but->rect) / 3, BLI_rctf_size_y(&but->rect));
-
if (!ui_but_is_float(but)) {
- if (mx < (but->rect.xmin + handlewidth)) {
+ if (but->drawflag & UI_BUT_ACTIVE_LEFT) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
temp = (int)data->value - 1;
@@ -4468,7 +4360,7 @@ static int ui_do_but_NUM(
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
- else if (mx > (but->rect.xmax - handlewidth)) {
+ else if (but->drawflag & UI_BUT_ACTIVE_RIGHT) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
temp = (int)data->value + 1;
@@ -4484,7 +4376,7 @@ static int ui_do_but_NUM(
}
}
else {
- if (mx < (but->rect.xmin + handlewidth)) {
+ if (but->drawflag & UI_BUT_ACTIVE_LEFT) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
tempf = (float)data->value - (UI_PRECISION_FLOAT_SCALE * but->a1);
@@ -4493,7 +4385,7 @@ static int ui_do_but_NUM(
button_activate_state(C, but, BUTTON_STATE_EXIT);
}
- else if (mx > but->rect.xmax - handlewidth) {
+ else if (but->drawflag & UI_BUT_ACTIVE_RIGHT) {
button_activate_state(C, but, BUTTON_STATE_NUM_EDITING);
tempf = (float)data->value + (UI_PRECISION_FLOAT_SCALE * but->a1);
@@ -5216,7 +5108,8 @@ static int ui_do_but_COLOR(
if (!event->ctrl) {
float color[3];
Scene *scene = CTX_data_scene(C);
- Paint *paint = BKE_paint_get_active(scene);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Paint *paint = BKE_paint_get_active(scene, view_layer);
Brush *brush = BKE_paint_brush(paint);
if (brush->flag & BRUSH_USE_GRADIENT) {
@@ -6133,6 +6026,7 @@ static int ui_do_but_CURVE(
int mx, my, a;
bool changed = false;
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
mx = event->x;
my = event->y;
@@ -6261,7 +6155,7 @@ static int ui_do_but_CURVE(
}
else {
curvemapping_changed(cumap, true); /* remove doubles */
- BKE_paint_invalidate_cursor_overlay(scene, cumap);
+ BKE_paint_invalidate_cursor_overlay(scene, view_layer, cumap);
}
}
@@ -6427,35 +6321,6 @@ static int ui_do_but_WAVEFORM(
return WM_UI_HANDLER_CONTINUE;
}
-static int ui_do_but_LINK(
- bContext *C, uiBut *but,
- uiHandleButtonData *data, const wmEvent *event)
-{
- VECCOPY2D(but->linkto, event->mval);
-
- if (data->state == BUTTON_STATE_HIGHLIGHT) {
- if (event->type == LEFTMOUSE && event->val == KM_PRESS) {
- button_activate_state(C, but, BUTTON_STATE_WAIT_RELEASE);
- return WM_UI_HANDLER_BREAK;
- }
- else if (event->type == LEFTMOUSE && but->block->handle) {
- button_activate_state(C, but, BUTTON_STATE_EXIT);
- return WM_UI_HANDLER_BREAK;
- }
- }
- else if (data->state == BUTTON_STATE_WAIT_RELEASE) {
-
- if (event->type == LEFTMOUSE && event->val != KM_PRESS) {
- if (!(but->flag & UI_SELECT))
- data->cancel = true;
- button_activate_state(C, but, BUTTON_STATE_EXIT);
- return WM_UI_HANDLER_BREAK;
- }
- }
-
- return WM_UI_HANDLER_CONTINUE;
-}
-
static bool ui_numedit_but_TRACKPREVIEW(
bContext *C, uiBut *but, uiHandleButtonData *data,
int mx, int my,
@@ -6767,6 +6632,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
MenuType *mt = WM_menutype_find("WM_MT_button_context", true);
bool is_array, is_array_component;
uiStringInfo label = {BUT_GET_LABEL, NULL};
+ wmOperatorType *ot;
+ PointerRNA op_ptr;
/* if ((but->rnapoin.data && but->rnaprop) == 0 && but->optype == NULL)*/
/* return 0;*/
@@ -6796,8 +6663,8 @@ static bool ui_but_menu(bContext *C, uiBut *but)
/*bool is_idprop = RNA_property_is_idprop(prop);*/ /* XXX does not work as expected, not strictly needed */
bool is_set = RNA_property_is_set(ptr, prop);
- /* Set the (button_pointer, button_prop) and pointer data for Python access to the hovered ui element. */
- uiLayoutSetContextFromBut(layout, but);
+ const int override_status = RNA_property_override_status(ptr, prop, -1);
+ const bool is_overridable = (override_status & RNA_OVERRIDE_STATUS_OVERRIDABLE) != 0;
/* second slower test, saved people finding keyframe items in menus when its not possible */
if (is_anim)
@@ -6926,11 +6793,59 @@ static bool ui_but_menu(bContext *C, uiBut *but)
ICON_NONE, "ANIM_OT_keyingset_button_remove");
}
}
-
+
+ if (is_overridable) {
+ /* Override Operators */
+ uiItemS(layout);
+
+ if (but->flag & UI_BUT_OVERRIDEN) {
+ if (is_array_component) {
+#if 0 /* Disabled for now. */
+ ot = WM_operatortype_find("UI_OT_override_type_set_button", false);
+ uiItemFullO_ptr(layout, ot, "Overrides Type", ICON_NONE,
+ NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+ RNA_boolean_set(&op_ptr, "all", true);
+ uiItemFullO_ptr(layout, ot, "Single Override Type", ICON_NONE,
+ NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+ RNA_boolean_set(&op_ptr, "all", false);
+#endif
+ uiItemBooleanO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Overrides"),
+ ICON_X, "UI_OT_override_remove_button", "all", true);
+ uiItemBooleanO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Single Override"),
+ ICON_X, "UI_OT_override_remove_button", "all", false);
+ }
+ else {
+#if 0 /* Disabled for now. */
+ uiItemFullO(layout, "UI_OT_override_type_set_button", "Override Type", ICON_NONE,
+ NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+ RNA_boolean_set(&op_ptr, "all", false);
+#endif
+ uiItemBooleanO(layout, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Remove Override"),
+ ICON_X, "UI_OT_override_remove_button", "all", true);
+ }
+ }
+ else {
+ if (is_array_component) {
+ ot = WM_operatortype_find("UI_OT_override_type_set_button", false);
+ uiItemFullO_ptr(layout, ot, "Define Overrides", ICON_NONE,
+ NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+ RNA_boolean_set(&op_ptr, "all", true);
+ uiItemFullO_ptr(layout, ot, "Define Single Override", ICON_NONE,
+ NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+ RNA_boolean_set(&op_ptr, "all", false);
+ }
+ else {
+ uiItemFullO(layout, "UI_OT_override_type_set_button", "Define Override", ICON_NONE,
+ NULL, WM_OP_INVOKE_DEFAULT, 0, &op_ptr);
+ RNA_boolean_set(&op_ptr, "all", false);
+ }
+ }
+ }
+
uiItemS(layout);
-
+
/* Property Operators */
-
+
/* Copy Property Value
* Paste Property Value */
@@ -7135,6 +7050,9 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
case UI_BTYPE_HOTKEY_EVENT:
retval = ui_do_but_HOTKEYEVT(C, but, data, event);
break;
+ case UI_BTYPE_TAB:
+ retval = ui_do_but_TAB(C, block, but, data, event);
+ break;
case UI_BTYPE_BUT_TOGGLE:
case UI_BTYPE_TOGGLE:
case UI_BTYPE_ICON_TOGGLE:
@@ -7192,6 +7110,7 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
retval = ui_do_but_TEX(C, block, but, data, event);
break;
case UI_BTYPE_MENU:
+ case UI_BTYPE_POPOVER:
case UI_BTYPE_BLOCK:
case UI_BTYPE_PULLDOWN:
retval = ui_do_but_BLOCK(C, but, data, event);
@@ -7220,10 +7139,6 @@ static int ui_do_button(bContext *C, uiBlock *block, uiBut *but, const wmEvent *
case UI_BTYPE_HSVCIRCLE:
retval = ui_do_but_HSVCIRCLE(C, block, but, data, event);
break;
- case UI_BTYPE_LINK:
- case UI_BTYPE_INLINK:
- retval = ui_do_but_LINK(C, but, data, event);
- break;
case UI_BTYPE_TRACK_PREVIEW:
retval = ui_do_but_TRACKPREVIEW(C, block, but, data, event);
break;
@@ -7407,15 +7322,14 @@ bool ui_but_is_active(ARegion *ar)
/* is called by notifier */
void UI_screen_free_active_but(const bContext *C, bScreen *screen)
{
- ScrArea *sa = screen->areabase.first;
-
- for (; sa; sa = sa->next) {
- ARegion *ar = sa->regionbase.first;
- for (; ar; ar = ar->next) {
- uiBut *but = ui_but_find_active_in_region(ar);
+ wmWindow *win = CTX_wm_window(C);
+
+ ED_screen_areas_iter(win, screen, area) {
+ for (ARegion *region = area->regionbase.first; region; region = region->next) {
+ uiBut *but = ui_but_find_active_in_region(region);
if (but) {
uiHandleButtonData *data = but->active;
-
+
if (data->menu == NULL && data->searchbox == NULL)
if (data->state == BUTTON_STATE_HIGHLIGHT)
ui_but_active_free(C, but);
@@ -7498,8 +7412,9 @@ static bool ui_region_contains_point_px(ARegion *ar, int x, int y)
ui_window_to_region(ar, &mx, &my);
/* check if in the rect */
- if (!BLI_rcti_isect_pt(&v2d->mask, mx, my))
+ if (!BLI_rcti_isect_pt(&v2d->mask, mx, my) || UI_view2d_mouse_in_scrollers(ar, &ar->v2d, x, y)) {
return false;
+ }
}
return true;
@@ -7652,7 +7567,7 @@ void UI_but_tooltip_refresh(bContext *C, uiBut *but)
{
uiHandleButtonData *data = but->active;
if (data) {
- bScreen *sc = data->window->screen;
+ bScreen *sc = WM_window_get_active_screen(data->window);
if (sc->tool_tip && sc->tool_tip->region) {
WM_tooltip_refresh(C, data->window);
}
@@ -7721,7 +7636,7 @@ static void button_activate_state(bContext *C, uiBut *but, uiHandleButtonState s
button_tooltip_timer_reset(C, but);
/* automatic open pulldown block timer */
- if (ELEM(but->type, UI_BTYPE_BLOCK, UI_BTYPE_PULLDOWN)) {
+ if (ELEM(but->type, UI_BTYPE_BLOCK, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER)) {
if (data->used_mouse && !data->autoopentimer) {
int time;
@@ -7931,6 +7846,9 @@ static void button_activate_init(bContext *C, ARegion *ar, uiBut *but, uiButtonA
const bool horizontal = (BLI_rctf_size_x(&but->rect) < BLI_rctf_size_y(&but->rect));
WM_cursor_modal_set(data->window, horizontal ? CURSOR_X_MOVE : CURSOR_Y_MOVE);
}
+ else if (but->type == UI_BTYPE_NUM) {
+ ui_numedit_set_active(but);
+ }
}
static void button_activate_exit(
@@ -8024,8 +7942,13 @@ static void button_activate_exit(
ui_selectcontext_end(but, &data->select_others);
#endif
- /* redraw (data is but->active!) */
+ if (data->changed_cursor) {
+ WM_cursor_modal_restore(data->window);
+ }
+
+ /* redraw and refresh (for popups) */
ED_region_tag_redraw(data->region);
+ ED_region_tag_refresh_ui(data->region);
/* clean up button */
if (but->active) {
@@ -8211,6 +8134,7 @@ void UI_context_update_anim_flag(const bContext *C)
for (block = ar->uiblocks.first; block; block = block->next) {
for (but = block->buttons.first; but; but = but->next) {
ui_but_anim_flag(but, (scene) ? scene->r.cfra : 0.0f);
+ ui_but_override_flag(but);
ED_region_tag_redraw(ar);
if (but->active) {
@@ -8348,6 +8272,37 @@ static void ui_handle_button_activate(bContext *C, ARegion *ar, uiBut *but, uiBu
/************ handle events for an activated button ***********/
+static bool ui_button_value_default(uiBut *but, double *r_value)
+{
+ if (but->rnaprop != NULL && ui_but_is_rna_valid(but)) {
+ int type = RNA_property_type(but->rnaprop);
+ if (ELEM(type, PROP_FLOAT, PROP_INT)) {
+ double default_value;
+ switch (type) {
+ case PROP_INT:
+ if (RNA_property_array_check(but->rnaprop)) {
+ default_value = (double)RNA_property_int_get_default_index(&but->rnapoin, but->rnaprop, but->rnaindex);
+ }
+ else {
+ default_value = (double)RNA_property_int_get_default(&but->rnapoin, but->rnaprop);
+ }
+ break;
+ case PROP_FLOAT:
+ if (RNA_property_array_check(but->rnaprop)) {
+ default_value = (double)RNA_property_float_get_default_index(&but->rnapoin, but->rnaprop, but->rnaindex);
+ }
+ else {
+ default_value = (double)RNA_property_float_get_default(&but->rnapoin, but->rnaprop);
+ }
+ break;
+ }
+ *r_value = default_value;
+ return true;
+ }
+ }
+ return false;
+}
+
static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
{
uiHandleButtonData *data = but->active;
@@ -8367,7 +8322,6 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
case EVT_BUT_CANCEL:
data->cancel = true;
button_activate_state(C, but, BUTTON_STATE_EXIT);
- retval = WM_UI_HANDLER_CONTINUE;
break;
case MOUSEMOVE:
{
@@ -8407,7 +8361,6 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
button_activate_state(C, but, BUTTON_STATE_MENU_OPEN);
}
- retval = WM_UI_HANDLER_CONTINUE;
break;
}
/* XXX hardcoded keymap check... but anyway, while view changes, tooltips should be removed */
@@ -8418,10 +8371,11 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
UI_but_tooltip_timer_remove(C, but);
ATTR_FALLTHROUGH;
default:
- /* handle button type specific events */
- retval = ui_do_button(C, block, but, event);
break;
}
+
+ /* handle button type specific events */
+ retval = ui_do_button(C, block, but, event);
}
else if (data->state == BUTTON_STATE_WAIT_RELEASE) {
switch (event->type) {
@@ -8450,15 +8404,23 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
break;
}
case MOUSEMOVE:
- if (ELEM(but->type, UI_BTYPE_LINK, UI_BTYPE_INLINK)) {
- but->flag |= UI_SELECT;
- ui_do_button(C, block, but, event);
- ED_region_tag_redraw(ar);
- }
- else {
+ {
/* deselect the button when moving the mouse away */
/* also de-activate for buttons that only show higlights */
if (ui_but_contains_point_px(ar, but, event->x, event->y)) {
+
+ /* Drag on a hold button (used in the toolbar) now opens it immediately. */
+ if (data->hold_action_timer) {
+ if (but->flag & UI_SELECT) {
+ if ((abs(event->x - event->prevx)) > 2 ||
+ (abs(event->y - event->prevy)) > 2)
+ {
+ WM_event_remove_timer(data->wm, data->window, data->hold_action_timer);
+ data->hold_action_timer = WM_event_add_timer(data->wm, data->window, TIMER, 0.0f);
+ }
+ }
+ }
+
if (!(but->flag & UI_SELECT)) {
but->flag |= (UI_SELECT | UI_ACTIVE);
data->cancel = false;
@@ -8534,6 +8496,29 @@ static int ui_handle_button_event(bContext *C, const wmEvent *event, uiBut *but)
uiBut *post_but = data->postbut;
uiButtonActivateType post_type = data->posttype;
+ /* Reset the button value when empty text is typed. */
+ if ((data->str != NULL) && (data->str[0] == '\0') &&
+ ELEM(RNA_property_type(but->rnaprop), PROP_FLOAT, PROP_INT))
+ {
+ MEM_SAFE_FREE(data->str);
+ ui_button_value_default(but, &data->value);
+
+#ifdef USE_DRAG_MULTINUM
+ if (data->multi_data.mbuts) {
+ for (LinkNode *l = data->multi_data.mbuts; l; l = l->next) {
+ uiButMultiState *state = l->link;
+ uiBut *but_iter = state->but;
+ double default_value;
+
+ if (ui_button_value_default(but_iter, &default_value)) {
+ ui_but_value_set(but_iter, default_value);
+ }
+ }
+ }
+ data->multi_data.skip = true;
+#endif
+ }
+
button_activate_exit(C, but, data, (post_but == NULL), false);
/* for jumping to the next button with tab while text editing */
@@ -8682,13 +8667,8 @@ static int ui_handle_list_event(bContext *C, const wmEvent *event, ARegion *ar,
}
if (redraw) {
- if (listbox->block->flag & UI_BLOCK_POPUP) {
- /* popups need special refreshing */
- ED_region_tag_refresh_ui(ar);
- }
- else {
- ED_region_tag_redraw(ar);
- }
+ ED_region_tag_redraw(ar);
+ ED_region_tag_refresh_ui(ar);
}
return retval;
@@ -10096,15 +10076,17 @@ static int ui_handler_region_menu(bContext *C, const wmEvent *event, void *UNUSE
if ((data->state == BUTTON_STATE_MENU_OPEN) &&
(is_inside_menu == false) && /* make sure mouse isn't inside another menu (see T43247) */
- (but->type == UI_BTYPE_PULLDOWN) &&
+ (ELEM(but->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER)) &&
(but_other = ui_but_find_mouse_over(ar, event)) &&
(but != but_other) &&
- (but->type == but_other->type))
+ (ELEM(but_other->type, UI_BTYPE_PULLDOWN, UI_BTYPE_POPOVER)))
{
/* if mouse moves to a different root-level menu button,
* open it to replace the current menu */
- ui_handle_button_activate(C, ar, but_other, BUTTON_ACTIVATE_OVER);
- button_activate_state(C, but_other, BUTTON_STATE_MENU_OPEN);
+ if ((but_other->flag & UI_BUT_DISABLED) == 0) {
+ ui_handle_button_activate(C, ar, but_other, BUTTON_ACTIVATE_OVER);
+ button_activate_state(C, but_other, BUTTON_STATE_MENU_OPEN);
+ }
}
else if (data->state == BUTTON_STATE_MENU_OPEN) {
int retval;
@@ -10343,3 +10325,18 @@ void ui_but_clipboard_free(void)
{
curvemapping_free_data(&but_copypaste_curve);
}
+
+bool UI_but_is_tool(const uiBut *but)
+{
+ /* very evil! */
+ if (but->optype != NULL) {
+ static wmOperatorType *ot = NULL;
+ if (ot == NULL) {
+ ot = WM_operatortype_find("WM_OT_tool_set", false);
+ }
+ if (but->optype == ot) {
+ return true;
+ }
+ }
+ return false;
+}
diff --git a/source/blender/editors/interface/interface_icons.c b/source/blender/editors/interface/interface_icons.c
index ed57412c05c..12b549e8f8b 100644
--- a/source/blender/editors/interface/interface_icons.c
+++ b/source/blender/editors/interface/interface_icons.c
@@ -33,12 +33,15 @@
#include "MEM_guardedalloc.h"
-#include "GPU_extensions.h"
-#include "GPU_basic_shader.h"
+#include "GPU_draw.h"
+#include "GPU_matrix.h"
+#include "GPU_batch.h"
+#include "GPU_immediate.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
#include "BLI_fileops_types.h"
+#include "BLI_math_vector.h"
#include "DNA_brush_types.h"
#include "DNA_curve_types.h"
@@ -46,6 +49,7 @@
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
+#include "DNA_workspace_types.h"
#include "RNA_access.h"
#include "RNA_enum_types.h"
@@ -59,9 +63,12 @@
#include "IMB_imbuf_types.h"
#include "IMB_thumbs.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "DEG_depsgraph.h"
+
+#include "DRW_engine.h"
+
#include "ED_datafiles.h"
#include "ED_keyframes_draw.h"
#include "ED_render.h"
@@ -94,6 +101,7 @@ typedef void (*VectorDrawFunc)(int x, int y, int w, int h, float alpha);
#define ICON_TYPE_TEXTURE 1
#define ICON_TYPE_BUFFER 2
#define ICON_TYPE_VECTOR 3
+#define ICON_TYPE_GEOM 4
typedef struct DrawInfo {
int type;
@@ -104,6 +112,9 @@ typedef struct DrawInfo {
VectorDrawFunc func;
} vector;
struct {
+ ImBuf *image_cache;
+ } geom;
+ struct {
IconImage *image;
} buffer;
struct {
@@ -224,13 +235,17 @@ static void vicon_small_tri_right_draw(int x, int y, int w, int UNUSED(h), float
viconutil_set_point(pts[1], cx - d2, cy - d);
viconutil_set_point(pts[2], cx + d2, cy);
- glColor4f(0.2f, 0.2f, 0.2f, alpha);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4f(0.2f, 0.2f, 0.2f, alpha);
- glBegin(GL_TRIANGLES);
- glVertex2iv(pts[0]);
- glVertex2iv(pts[1]);
- glVertex2iv(pts[2]);
- glEnd();
+ immBegin(GWN_PRIM_TRIS, 3);
+ immVertex2iv(pos, pts[0]);
+ immVertex2iv(pos, pts[1]);
+ immVertex2iv(pos, pts[2]);
+ immEnd();
+
+ immUnbindProgram();
}
static void vicon_keytype_draw_wrapper(int x, int y, int w, int h, float alpha, short key_type)
@@ -239,7 +254,6 @@ static void vicon_keytype_draw_wrapper(int x, int y, int w, int h, float alpha,
* (since we're doing this offscreen, free from any particular space_id)
*/
struct bThemeState theme_state;
- int xco, yco;
UI_Theme_Store(&theme_state);
UI_SetTheme(SPACE_ACTION, RGN_TYPE_WINDOW);
@@ -248,16 +262,30 @@ static void vicon_keytype_draw_wrapper(int x, int y, int w, int h, float alpha,
* while the draw_keyframe_shape() function needs the midpoint for
* the keyframe
*/
- xco = x + w / 2;
- yco = y + h / 2;
-
+ int xco = x + w / 2;
+ int yco = y + h / 2;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int size_id = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color_id = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ unsigned int outline_color_id = GWN_vertformat_attr_add(format, "outlineColor", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
+ GPU_enable_program_point_size();
+ immBegin(GWN_PRIM_POINTS, 1);
+
/* draw keyframe
- * - xscale: 1.0 (since there's no timeline scaling to compensate for)
- * - yscale: 0.3 * h (found out experimentally... dunno why!)
+ * - size: 0.6 * h (found out experimentally... dunno why!)
* - sel: true (so that "keyframe" state shows the iconic yellow icon)
*/
- draw_keyframe_shape(xco, yco, 1.0f, 0.3f * h, true, key_type, KEYFRAME_SHAPE_BOTH, alpha);
-
+ draw_keyframe_shape(xco, yco, 0.6f * h, true, key_type, KEYFRAME_SHAPE_BOTH, alpha,
+ pos_id, size_id, color_id, outline_color_id);
+
+ immEnd();
+ GPU_disable_program_point_size();
+ immUnbindProgram();
+
UI_Theme_Restore(&theme_state);
}
@@ -290,7 +318,7 @@ static void vicon_colorset_draw(int index, int x, int y, int w, int h, float UNU
{
bTheme *btheme = UI_GetTheme();
ThemeWireColor *cs = &btheme->tarm[index];
-
+
/* Draw three bands of color: One per color
* x-----a-----b-----c
* | N | S | A |
@@ -299,19 +327,24 @@ static void vicon_colorset_draw(int index, int x, int y, int w, int h, float UNU
const int a = x + w / 3;
const int b = x + w / 3 * 2;
const int c = x + w;
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* XXX: Include alpha into this... */
/* normal */
- glColor3ubv((unsigned char *)cs->solid);
- glRecti(x, y, a, y + h);
-
+ immUniformColor3ubv((unsigned char *)cs->solid);
+ immRecti(pos, x, y, a, y + h);
+
/* selected */
- glColor3ubv((unsigned char *)cs->select);
- glRecti(a, y, b, y + h);
-
+ immUniformColor3ubv((unsigned char *)cs->select);
+ immRecti(pos, a, y, b, y + h);
+
/* active */
- glColor3ubv((unsigned char *)cs->active);
- glRecti(b, y, c, y + h);
+ immUniformColor3ubv((unsigned char *)cs->active);
+ immRecti(pos, b, y, c, y + h);
+
+ immUnbindProgram();
}
#define DEF_VICON_COLORSET_DRAW_NTH(prefix, index) \
@@ -460,6 +493,23 @@ static void init_matcap_icons(void)
}
+static void init_studio_light_icons(void)
+{
+ /* dynamic allocation now, tucking datatoc pointers in DrawInfo */
+#define INIT_STUDIOLIGHT_ICON(icon_id, studiolight_id) \
+ { \
+ DrawInfo *di; \
+ di = def_internal_icon(NULL, icon_id, 0, 0, 96, ICON_TYPE_BUFFER); \
+ di->data.buffer.image->rect = WORKBENCH_generate_studiolight_preview(studiolight_id, 96); \
+ } (void)0
+
+ INIT_STUDIOLIGHT_ICON(ICON_STUDIOLIGHT_01, 0);
+ INIT_STUDIOLIGHT_ICON(ICON_STUDIOLIGHT_02, 1);
+ INIT_STUDIOLIGHT_ICON(ICON_STUDIOLIGHT_03, 2);
+ INIT_STUDIOLIGHT_ICON(ICON_STUDIOLIGHT_04, 3);
+ INIT_STUDIOLIGHT_ICON(ICON_STUDIOLIGHT_05, 4);
+
+}
static void init_internal_icons(void)
{
// bTheme *btheme = UI_GetTheme();
@@ -504,8 +554,12 @@ static void init_internal_icons(void)
icongltex.id = 0;
}
+#if 0 /* should be a compile-time check (if needed at all) */
/* we only use a texture for cards with non-power of two */
if (GPU_full_non_power_of_two_support()) {
+#else
+ {
+#endif
glGenTextures(1, &icongltex.id);
if (icongltex.id) {
@@ -533,11 +587,6 @@ static void init_internal_icons(void)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glBindTexture(GL_TEXTURE_2D, 0);
-
- if (glGetError() == GL_OUT_OF_MEMORY) {
- glDeleteTextures(1, &icongltex.id);
- icongltex.id = 0;
- }
}
}
}
@@ -717,21 +766,49 @@ void UI_icons_free_drawinfo(void *drawinfo)
MEM_freeN(di->data.buffer.image);
}
}
+ else if (di->type == ICON_TYPE_GEOM) {
+ if (di->data.geom.image_cache) {
+ IMB_freeImBuf(di->data.geom.image_cache);
+ }
+ }
MEM_freeN(di);
}
}
-static DrawInfo *icon_create_drawinfo(void)
+/**
+ * #Icon.data_type and #Icon.obj
+ */
+static DrawInfo *icon_create_drawinfo(int icon_data_type)
{
DrawInfo *di = NULL;
di = MEM_callocN(sizeof(DrawInfo), "di_icon");
- di->type = ICON_TYPE_PREVIEW;
+
+ if (ELEM(icon_data_type, ICON_DATA_ID, ICON_DATA_PREVIEW)) {
+ di->type = ICON_TYPE_PREVIEW;
+ }
+ else if (icon_data_type == ICON_DATA_GEOM) {
+ di->type = ICON_TYPE_GEOM;
+ }
+ else {
+ BLI_assert(0);
+ }
return di;
}
+static DrawInfo *icon_ensure_drawinfo(Icon *icon)
+{
+ if (icon->drawinfo) {
+ return icon->drawinfo;
+ }
+ DrawInfo *di = icon_create_drawinfo(icon->obj_type);
+ icon->drawinfo = di;
+ icon->drawinfo_free = UI_icons_free_drawinfo;
+ return di;
+}
+
/* note!, returns unscaled by DPI */
int UI_icon_get_width(int icon_id)
{
@@ -746,40 +823,27 @@ int UI_icon_get_width(int icon_id)
return 0;
}
- di = (DrawInfo *)icon->drawinfo;
- if (!di) {
- di = icon_create_drawinfo();
- icon->drawinfo = di;
- }
-
- if (di)
+ di = icon_ensure_drawinfo(icon);
+ if (di) {
return ICON_DEFAULT_WIDTH;
+ }
return 0;
}
int UI_icon_get_height(int icon_id)
{
- Icon *icon = NULL;
- DrawInfo *di = NULL;
-
- icon = BKE_icon_get(icon_id);
-
+ Icon *icon = BKE_icon_get(icon_id);
if (icon == NULL) {
if (G.debug & G_DEBUG)
printf("%s: Internal error, no icon for icon ID: %d\n", __func__, icon_id);
return 0;
}
-
- di = (DrawInfo *)icon->drawinfo;
- if (!di) {
- di = icon_create_drawinfo();
- icon->drawinfo = di;
- }
-
- if (di)
+ DrawInfo *di = icon_ensure_drawinfo(icon);
+ if (di) {
return ICON_DEFAULT_HEIGHT;
+ }
return 0;
}
@@ -792,6 +856,7 @@ void UI_icons_init(int first_dyn_id)
init_internal_icons();
init_brush_icons();
init_matcap_icons();
+ init_studio_light_icons();
#endif
}
@@ -836,14 +901,7 @@ void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool bi
Icon *icon = BKE_icon_get(icon_id);
if (icon) {
- DrawInfo *di = (DrawInfo *)icon->drawinfo;
-
- if (!di) {
- di = icon_create_drawinfo();
-
- icon->drawinfo = di;
- icon->drawinfo_free = UI_icons_free_drawinfo;
- }
+ DrawInfo *di = icon_ensure_drawinfo(icon);
if (di) {
switch (di->type) {
@@ -851,12 +909,15 @@ void ui_icon_ensure_deferred(const bContext *C, const int icon_id, const bool bi
{
ID *id = (icon->id_type != 0) ? icon->obj : NULL;
PreviewImage *prv = id ? BKE_previewimg_id_ensure(id) : icon->obj;
+ /* Using jobs for screen previews crashes due to offscreen rendering.
+ * XXX would be nicer if PreviewImage could store if it supports jobs */
+ const bool use_jobs = !id || (GS(id->name) != ID_SCR);
if (prv) {
const int size = big ? ICON_SIZE_PREVIEW : ICON_SIZE_ICON;
if (id || (prv->tag & PRV_TAG_DEFFERED) != 0) {
- ui_id_preview_image_render_size(C, NULL, id, prv, size, true);
+ ui_id_preview_image_render_size(C, NULL, id, prv, size, use_jobs);
}
}
break;
@@ -936,7 +997,7 @@ PreviewImage *UI_icon_to_preview(int icon_id)
}
static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect), int rw, int rh,
- unsigned int *rect, float alpha, const float rgb[3], const bool is_preview)
+ unsigned int *rect, float alpha, const float rgb[3], const float desaturate)
{
ImBuf *ima = NULL;
int draw_w = w;
@@ -950,15 +1011,13 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
BLI_assert(!"invalid icon size");
return;
}
-
/* modulate color */
- if (alpha != 1.0f)
- glPixelTransferf(GL_ALPHA_SCALE, alpha);
+ float col[4] = {1.0f, 1.0f, 1.0f, alpha};
if (rgb) {
- glPixelTransferf(GL_RED_SCALE, rgb[0]);
- glPixelTransferf(GL_GREEN_SCALE, rgb[1]);
- glPixelTransferf(GL_BLUE_SCALE, rgb[2]);
+ col[0] = rgb[0];
+ col[1] = rgb[1];
+ col[2] = rgb[2];
}
/* rect contains image in 'rendersize', we only scale if needed */
@@ -983,72 +1042,169 @@ static void icon_draw_rect(float x, float y, int w, int h, float UNUSED(aspect),
rect = ima->rect;
}
+ /* We need to flush widget base first to ensure correct ordering. */
+ UI_widgetbase_draw_cache_flush();
+
/* draw */
- if (is_preview) {
- glaDrawPixelsSafe(draw_x, draw_y, draw_w, draw_h, draw_w, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+ GPUBuiltinShader shader;
+ if (desaturate != 0.0f) {
+ shader = GPU_SHADER_2D_IMAGE_DESATURATE_COLOR;
}
else {
- int bound_options;
- GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
-
- glRasterPos2f(draw_x, draw_y);
- glDrawPixels(draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, rect);
+ shader = GPU_SHADER_2D_IMAGE_COLOR;
+ }
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(shader);
- GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
+ if (shader == GPU_SHADER_2D_IMAGE_DESATURATE_COLOR) {
+ immUniform1f("factor", desaturate);
}
+ immDrawPixelsTex(&state, draw_x, draw_y, draw_w, draw_h, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect,
+ 1.0f, 1.0f, col);
+
if (ima)
IMB_freeImBuf(ima);
+}
- /* restore color */
- if (alpha != 0.0f)
- glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
-
- if (rgb) {
- glPixelTransferf(GL_RED_SCALE, 1.0f);
- glPixelTransferf(GL_GREEN_SCALE, 1.0f);
- glPixelTransferf(GL_BLUE_SCALE, 1.0f);
+/* High enough to make a difference, low enough so that
+ * small draws are still efficient with the use of glUniform.
+ * NOTE TODO: We could use UBO but we would need some triple
+ * buffer system + persistent mapping for this to be more
+ * efficient than simple glUniform calls. */
+#define ICON_DRAW_CACHE_SIZE 16
+
+typedef struct IconDrawCall {
+ rctf pos;
+ rctf tex;
+ float color[4];
+} IconDrawCall;
+
+static struct {
+ IconDrawCall drawcall_cache[ICON_DRAW_CACHE_SIZE];
+ int calls; /* Number of calls batched together */
+ bool enabled;
+ float mat[4][4];
+} g_icon_draw_cache = {{{{0}}}};
+
+void UI_icon_draw_cache_begin(void)
+{
+ BLI_assert(g_icon_draw_cache.enabled == false);
+ g_icon_draw_cache.enabled = true;
+}
+
+static void icon_draw_cache_flush_ex(void)
+{
+ if (g_icon_draw_cache.calls == 0)
+ return;
+
+ /* We need to flush widget base first to ensure correct ordering. */
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ UI_widgetbase_draw_cache_flush();
+
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, icongltex.id);
+
+ GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR);
+ GPU_shader_bind(shader);
+
+ int img_loc = GPU_shader_get_uniform(shader, "image");
+ int data_loc = GPU_shader_get_uniform(shader, "calls_data[0]");
+
+ glUniform1i(img_loc, 0);
+ glUniform4fv(data_loc, ICON_DRAW_CACHE_SIZE * 3, (float *)g_icon_draw_cache.drawcall_cache);
+
+ GWN_draw_primitive(GWN_PRIM_TRIS, 6 * g_icon_draw_cache.calls);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ g_icon_draw_cache.calls = 0;
+}
+
+void UI_icon_draw_cache_end(void)
+{
+ BLI_assert(g_icon_draw_cache.enabled == true);
+ g_icon_draw_cache.enabled = false;
+
+ /* Don't change blend state if it's not needed. */
+ if (g_icon_draw_cache.calls == 0)
+ return;
+
+ glEnable(GL_BLEND);
+
+ icon_draw_cache_flush_ex();
+
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glDisable(GL_BLEND);
+}
+
+static void icon_draw_texture_cached(
+ float x, float y, float w, float h, int ix, int iy,
+ int UNUSED(iw), int ih, float alpha, const float rgb[3])
+{
+
+ float mvp[4][4];
+ gpuGetModelViewProjectionMatrix(mvp);
+
+ IconDrawCall *call = &g_icon_draw_cache.drawcall_cache[g_icon_draw_cache.calls];
+ g_icon_draw_cache.calls++;
+
+ /* Manual mat4*vec2 */
+ call->pos.xmin = x * mvp[0][0] + y * mvp[1][0] + mvp[3][0];
+ call->pos.ymin = x * mvp[0][1] + y * mvp[1][1] + mvp[3][1];
+ call->pos.xmax = call->pos.xmin + w * mvp[0][0] + h * mvp[1][0];
+ call->pos.ymax = call->pos.ymin + w * mvp[0][1] + h * mvp[1][1];
+
+ call->tex.xmin = ix * icongltex.invw;
+ call->tex.xmax = (ix + ih) * icongltex.invw;
+ call->tex.ymin = iy * icongltex.invh;
+ call->tex.ymax = (iy + ih) * icongltex.invh;
+
+ if (rgb) copy_v4_fl4(call->color, rgb[0], rgb[1], rgb[2], alpha);
+ else copy_v4_fl(call->color, alpha);
+
+ if (g_icon_draw_cache.calls == ICON_DRAW_CACHE_SIZE) {
+ icon_draw_cache_flush_ex();
}
}
static void icon_draw_texture(
float x, float y, float w, float h, int ix, int iy,
- int UNUSED(iw), int ih, float alpha, const float rgb[3])
+ int iw, int ih, float alpha, const float rgb[3])
{
- float x1, x2, y1, y2;
+ if (g_icon_draw_cache.enabled) {
+ icon_draw_texture_cached(x, y, w, h, ix, iy, iw, ih, alpha, rgb);
+ return;
+ }
- if (rgb) glColor4f(rgb[0], rgb[1], rgb[2], alpha);
- else glColor4f(alpha, alpha, alpha, alpha);
+ /* We need to flush widget base first to ensure correct ordering. */
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ UI_widgetbase_draw_cache_flush();
+
+ float x1, x2, y1, y2;
x1 = ix * icongltex.invw;
x2 = (ix + ih) * icongltex.invw;
y1 = iy * icongltex.invh;
y2 = (iy + ih) * icongltex.invh;
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, icongltex.id);
- /* sharper downscaling, has no effect when scale matches with a mip level */
- glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, -0.5f);
-
- glBegin(GL_QUADS);
- glTexCoord2f(x1, y1);
- glVertex2f(x, y);
+ GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR);
+ GPU_shader_bind(shader);
- glTexCoord2f(x2, y1);
- glVertex2f(x + w, y);
+ if (rgb) glUniform4f(GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_COLOR), rgb[0], rgb[1], rgb[2], alpha);
+ else glUniform4f(GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_COLOR), alpha, alpha, alpha, alpha);
- glTexCoord2f(x2, y2);
- glVertex2f(x + w, y + h);
+ glUniform1i(GPU_shader_get_uniform(shader, "image"), 0);
+ glUniform4f(GPU_shader_get_uniform(shader, "rect_icon"), x1, y1, x2, y2);
+ glUniform4f(GPU_shader_get_uniform(shader, "rect_geom"), x, y, x + w, y + h);
- glTexCoord2f(x1, y2);
- glVertex2f(x, y + h);
- glEnd();
-
- glTexEnvf(GL_TEXTURE_FILTER_CONTROL, GL_TEXTURE_LOD_BIAS, 0.0f);
+ GWN_draw_primitive(GWN_PRIM_TRI_STRIP, 4);
glBindTexture(GL_TEXTURE_2D, 0);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
}
/* Drawing size for preview images */
@@ -1068,11 +1224,10 @@ static int get_draw_size(enum eIconSizes size)
static void icon_draw_size(
float x, float y, int icon_id, float aspect, float alpha, const float rgb[3],
- enum eIconSizes size, int draw_size, const bool UNUSED(nocreate), const bool is_preview)
+ enum eIconSizes size, int draw_size, const float desaturate)
{
bTheme *btheme = UI_GetTheme();
Icon *icon = NULL;
- DrawInfo *di = NULL;
IconImage *iimg;
const float fdraw_size = (float)draw_size;
int w, h;
@@ -1086,30 +1241,56 @@ static void icon_draw_size(
return;
}
- di = (DrawInfo *)icon->drawinfo;
-
- if (!di) {
- di = icon_create_drawinfo();
-
- icon->drawinfo = di;
- icon->drawinfo_free = UI_icons_free_drawinfo;
- }
-
/* scale width and height according to aspect */
w = (int)(fdraw_size / aspect + 0.5f);
h = (int)(fdraw_size / aspect + 0.5f);
-
+
+ DrawInfo *di = icon_ensure_drawinfo(icon);
+
if (di->type == ICON_TYPE_VECTOR) {
+ /* We need to flush widget base first to ensure correct ordering. */
+ UI_widgetbase_draw_cache_flush();
/* vector icons use the uiBlock transformation, they are not drawn
* with untransformed coordinates like the other icons */
di->data.vector.func((int)x, (int)y, w, h, 1.0f);
}
+ else if (di->type == ICON_TYPE_GEOM) {
+ /* We need to flush widget base first to ensure correct ordering. */
+ UI_widgetbase_draw_cache_flush();
+
+#ifdef USE_TOOLBAR_HACK
+ /* TODO(campbell): scale icons up for toolbar, we need a way to detect larger buttons and do this automatic. */
+ {
+ float scale = (float)ICON_DEFAULT_HEIGHT_TOOLBAR / (float)ICON_DEFAULT_HEIGHT;
+ y = (y + (h / 2)) - ((h * scale) / 2);
+ w *= scale;
+ h *= scale;
+ }
+#endif
+
+ /* This could re-generate often if rendered at different sizes in the one interface.
+ * TODO(campbell): support caching multiple sizes. */
+ ImBuf *ibuf = di->data.geom.image_cache;
+ if ((ibuf == NULL) ||
+ (ibuf->x != w) ||
+ (ibuf->y != h))
+ {
+ if (ibuf) {
+ IMB_freeImBuf(ibuf);
+ }
+ ibuf = BKE_icon_geom_rasterize(icon->obj, w, h);
+ di->data.geom.image_cache = ibuf;
+ }
+ glBlendFuncSeparate(GL_ONE, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ icon_draw_rect(x, y, w, h, aspect, w, h, ibuf->rect, alpha, rgb, desaturate);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ }
else if (di->type == ICON_TYPE_TEXTURE) {
/* texture image use premul alpha for correct scaling */
glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
icon_draw_texture(x, y, (float)w, (float)h, di->data.texture.x, di->data.texture.y,
di->data.texture.w, di->data.texture.h, alpha, rgb);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
else if (di->type == ICON_TYPE_BUFFER) {
/* it is a builtin icon */
@@ -1119,9 +1300,9 @@ static void icon_draw_size(
#endif
if (!iimg->rect) return; /* something has gone wrong! */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, is_preview);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ icon_draw_rect(x, y, w, h, aspect, iimg->w, iimg->h, iimg->rect, alpha, rgb, desaturate);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
else if (di->type == ICON_TYPE_PREVIEW) {
PreviewImage *pi = (icon->id_type != 0) ? BKE_previewimg_id_ensure((ID *)icon->obj) : icon->obj;
@@ -1133,8 +1314,8 @@ static void icon_draw_size(
/* preview images use premul alpha ... */
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, rgb, is_preview);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ icon_draw_rect(x, y, w, h, aspect, pi->w[size], pi->h[size], pi->rect[size], alpha, rgb, desaturate);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
}
}
@@ -1162,7 +1343,7 @@ void UI_id_icon_render(const bContext *C, Scene *scene, ID *id, const bool big,
}
}
-static void ui_id_brush_render(const bContext *C, ID *id)
+static void ui_id_icon_render(const bContext *C, ID *id, bool use_jobs)
{
PreviewImage *pi = BKE_previewimg_id_ensure(id);
enum eIconSizes i;
@@ -1174,7 +1355,7 @@ static void ui_id_brush_render(const bContext *C, ID *id)
/* check if rect needs to be created; changed
* only set by dynamic icons */
if (((pi->flag[i] & PRV_CHANGED) || !pi->rect[i])) {
- icon_set_image(C, NULL, id, pi, i, true);
+ icon_set_image(C, NULL, id, pi, i, use_jobs);
pi->flag[i] &= ~PRV_CHANGED;
}
}
@@ -1187,7 +1368,7 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id)
if (br->flag & BRUSH_CUSTOM_ICON) {
BKE_icon_id_ensure(id);
- ui_id_brush_render(C, id);
+ ui_id_icon_render(C, id, true);
}
else {
Object *ob = CTX_data_active_object(C);
@@ -1234,6 +1415,15 @@ static int ui_id_brush_get_icon(const bContext *C, ID *id)
return id->icon_id;
}
+static int ui_id_screen_get_icon(const bContext *C, ID *id)
+{
+ BKE_icon_id_ensure(id);
+ /* Don't use jobs here, offscreen rendering doesn't like this and crashes. */
+ ui_id_icon_render(C, id, false);
+
+ return id->icon_id;
+}
+
int ui_id_icon_get(const bContext *C, ID *id, const bool big)
{
int iconid = 0;
@@ -1252,6 +1442,9 @@ int ui_id_icon_get(const bContext *C, ID *id, const bool big)
/* checks if not exists, or changed */
UI_id_icon_render(C, NULL, id, big, true);
break;
+ case ID_SCR:
+ iconid = ui_id_screen_get_icon(C, id);
+ break;
default:
break;
}
@@ -1344,6 +1537,8 @@ int UI_idcode_icon_get(const int idcode)
return ICON_COLOR; /* TODO! this would need its own icon! */
case ID_PC:
return ICON_CURVE_BEZCURVE; /* TODO! this would need its own icon! */
+ case ID_LP:
+ return ICON_RADIO;
case ID_SCE:
return ICON_SCENE_DATA;
case ID_SPK:
@@ -1365,21 +1560,26 @@ int UI_idcode_icon_get(const int idcode)
static void icon_draw_at_size(
float x, float y, int icon_id, float aspect, float alpha,
- enum eIconSizes size, const bool nocreate)
+ enum eIconSizes size, const float desaturate)
{
int draw_size = get_draw_size(size);
- icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, nocreate, false);
+ icon_draw_size(x, y, icon_id, aspect, alpha, NULL, size, draw_size, desaturate);
}
void UI_icon_draw_aspect(float x, float y, int icon_id, float aspect, float alpha)
{
- icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0);
+ icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, 0.0f);
}
void UI_icon_draw_aspect_color(float x, float y, int icon_id, float aspect, const float rgb[3])
{
int draw_size = get_draw_size(ICON_SIZE_ICON);
- icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false, false);
+ icon_draw_size(x, y, icon_id, aspect, 1.0f, rgb, ICON_SIZE_ICON, draw_size, false);
+}
+
+void UI_icon_draw_desaturate(float x, float y, int icon_id, float aspect, float alpha, float desaturate)
+{
+ icon_draw_at_size(x, y, icon_id, aspect, alpha, ICON_SIZE_ICON, desaturate);
}
/* draws icon with dpi scale factor */
@@ -1388,23 +1588,28 @@ void UI_icon_draw(float x, float y, int icon_id)
UI_icon_draw_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, 1.0f);
}
+void UI_icon_draw_alpha(float x, float y, int icon_id, float alpha)
+{
+ UI_icon_draw_aspect(x, y, icon_id, 1.0f / UI_DPI_FAC, alpha);
+}
+
void UI_icon_draw_size(float x, float y, int size, int icon_id, float alpha)
{
- icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, true, false);
+ icon_draw_size(x, y, icon_id, 1.0f, alpha, NULL, ICON_SIZE_ICON, size, false);
}
void UI_icon_draw_preview(float x, float y, int icon_id)
{
- icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, 0);
+ icon_draw_at_size(x, y, icon_id, 1.0f, 1.0f, ICON_SIZE_PREVIEW, false);
}
void UI_icon_draw_preview_aspect(float x, float y, int icon_id, float aspect)
{
- icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, 0);
+ icon_draw_at_size(x, y, icon_id, aspect, 1.0f, ICON_SIZE_PREVIEW, false);
}
void UI_icon_draw_preview_aspect_size(float x, float y, int icon_id, float aspect, float alpha, int size)
{
- icon_draw_size(x, y, icon_id, aspect, alpha, NULL, ICON_SIZE_PREVIEW, size, false, true);
+ icon_draw_size(x, y, icon_id, aspect, alpha, NULL, ICON_SIZE_PREVIEW, size, false);
}
diff --git a/source/blender/editors/interface/interface_intern.h b/source/blender/editors/interface/interface_intern.h
index d5e89357a9f..de2217a3d3e 100644
--- a/source/blender/editors/interface/interface_intern.h
+++ b/source/blender/editors/interface/interface_intern.h
@@ -72,6 +72,8 @@ typedef enum {
UI_WTYPE_NUMBER,
UI_WTYPE_SLIDER,
UI_WTYPE_EXEC,
+ UI_WTYPE_TOOLBAR_ITEM,
+ UI_WTYPE_TAB,
UI_WTYPE_TOOLTIP,
/* strings */
@@ -103,6 +105,8 @@ typedef enum {
UI_WTYPE_PROGRESSBAR,
} uiWidgetTypeEnum;
+#define UI_MENU_WIDTH_MIN (UI_UNIT_Y * 9)
+
/* menu scrolling */
#define UI_MENU_SCROLL_ARROW 12
#define UI_MENU_SCROLL_MOUSE (UI_MENU_SCROLL_ARROW + 2)
@@ -112,6 +116,9 @@ typedef enum {
#define UI_PANEL_MINX 100
#define UI_PANEL_MINY 70
+/* popover width (multiplied by 'U.widget_unit') */
+#define UI_POPOVER_WIDTH_UNITS 10
+
/* uiBut->flag */
enum {
UI_SELECT = (1 << 0), /* use when the button is pressed */
@@ -187,23 +194,6 @@ enum {
/* max amount of items a radial menu (pie menu) can contain */
#define PIE_MAX_ITEMS 8
-typedef struct uiLinkLine { /* only for draw/edit */
- struct uiLinkLine *next, *prev;
- struct uiBut *from, *to;
- short flag, deactive;
-} uiLinkLine;
-
-typedef struct {
- void **poin; /* pointer to original pointer */
- void ***ppoin; /* pointer to original pointer-array */
- short *totlink; /* if pointer-array, here is the total */
-
- short maxlink, pad;
- short fromcode, tocode;
-
- ListBase lines;
-} uiLink;
-
struct uiBut {
struct uiBut *next, *prev;
int flag, drawflag;
@@ -258,6 +248,7 @@ struct uiBut {
uiButSearchCreateFunc search_create_func;
uiButSearchFunc search_func;
+ bool free_search_arg;
void *search_arg;
uiButHandleRenameFunc rename_func;
@@ -268,9 +259,6 @@ struct uiBut {
uiButHandleHoldFunc hold_func;
void *hold_argN;
- uiLink *link;
- short linkto[2]; /* region relative coords */
-
const char *tip;
uiButToolTipFunc tip_func;
void *tip_argN;
@@ -281,7 +269,7 @@ struct uiBut {
BIFIconID icon;
char dt; /* drawtype: UI_EMBOSS, UI_EMBOSS_NONE ... etc, copied from the block */
signed char pie_dir; /* direction in a pie menu, used for collision detection (RadialDirection) */
- char changed; /* could be made into a single flag */
+ bool changed; /* could be made into a single flag */
unsigned char unit_type; /* so buttons can support unit systems which are not RNA */
short modifier_key;
short iconadd;
@@ -331,6 +319,11 @@ struct uiBut {
uiBlock *block;
};
+typedef struct uiButTab {
+ uiBut but;
+ struct wmOperatorType *unlink_ot;
+} uiButTab;
+
typedef struct ColorPicker {
struct ColorPicker *next, *prev;
float color_data[3]; /* colr data may be HSV or HSL for now */
@@ -449,8 +442,6 @@ typedef struct uiSafetyRct {
/* interface.c */
-extern void ui_linkline_remove(uiLinkLine *line, uiBut *but);
-
void ui_fontscale(short *points, float aspect);
extern bool ui_block_is_menu(const uiBlock *block) ATTR_WARN_UNUSED_RESULT;
@@ -507,6 +498,7 @@ extern bool ui_but_supports_cycling(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
extern int ui_but_is_pushed_ex(uiBut *but, double *value) ATTR_WARN_UNUSED_RESULT;
extern int ui_but_is_pushed(uiBut *but) ATTR_WARN_UNUSED_RESULT;
+void ui_but_override_flag(uiBut *but);
extern void ui_block_bounds_calc(uiBlock *block);
extern void ui_block_translate(uiBlock *block, int x, int y);
@@ -526,16 +518,19 @@ struct uiKeyNavLock {
};
typedef uiBlock * (*uiBlockHandleCreateFunc)(struct bContext *C, struct uiPopupBlockHandle *handle, void *arg1);
+typedef void (*uiBlockHandleFreeFunc)(struct uiPopupBlockHandle *handle, void *arg1);
struct uiPopupBlockCreate {
- uiBlockCreateFunc create_func;
+ uiBlockCreateFunc create_func;
uiBlockHandleCreateFunc handle_create_func;
+ uiBlockHandleFreeFunc free_func;
void *arg;
int event_xy[2];
/* when popup is initialized from a button */
ARegion *butregion;
+ uiBut *but;
};
struct uiPopupBlockHandle {
@@ -556,6 +551,7 @@ struct uiPopupBlockHandle {
struct uiPopupBlockCreate popup_create_vars;
/* true if we can re-create the popup using 'popup_create_vars' */
bool can_refresh;
+ bool refresh;
struct wmTimer *scrolltimer;
@@ -577,6 +573,15 @@ struct uiPopupBlockHandle {
/* menu direction */
int direction;
+ /* Previous values so we don't resize or reposition on refresh. */
+ rctf prev_block_rect;
+ rctf prev_butrct;
+ short prev_dir1, prev_dir2;
+ int prev_mx, prev_my;
+
+ /* Maximum estimated size to avoid having to reposition on refresh. */
+ float max_size_x, max_size_y;
+
/* #ifdef USE_DRAG_POPUP */
bool is_grab;
int grab_xy_prev[2];
@@ -629,6 +634,18 @@ uiPopupBlockHandle *ui_popup_menu_create(
struct bContext *C, struct ARegion *butregion, uiBut *but,
uiMenuCreateFunc create_func, void *arg);
+/* interface_region_popover.c */
+uiBlock *ui_popover_block_refresh(
+ struct bContext *C, uiPopupBlockHandle *handle,
+ ARegion *butregion, uiBut *but);
+uiPopupBlockHandle *ui_popover_block_create(
+ struct bContext *C, struct ARegion *butregion, uiBut *but,
+ uiBlockCreateFunc create_func, uiBlockHandleCreateFunc handle_create_func,
+ void *arg);
+uiPopupBlockHandle *ui_popover_panel_create(
+ struct bContext *C, struct ARegion *butregion, uiBut *but,
+ uiMenuCreateFunc create_func, void *arg);
+
/* interface_region_menu_pie.c */
void ui_pie_menu_level_create(
uiBlock *block, struct wmOperatorType *ot, const char *propname, IDProperty *properties,
@@ -653,6 +670,8 @@ extern void ui_draw_dropshadow(const rctf *rct, float radius, float aspect, floa
void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, const float alpha);
+
+void ui_draw_but_TAB_outline(const rcti *rect, float rad, unsigned char highlight[3], unsigned char highlight_fade[3]);
void ui_draw_but_HISTOGRAM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect);
void ui_draw_but_WAVEFORM(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect);
void ui_draw_but_VECTORSCOPE(ARegion *ar, uiBut *but, struct uiWidgetColors *wcol, const rcti *rect);
@@ -695,15 +714,49 @@ struct wmIMEData *ui_but_ime_data_get(uiBut *but);
#endif
/* interface_widgets.c */
-void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3);
-void ui_draw_anti_roundbox(int mode, float minx, float miny, float maxx, float maxy, float rad, bool use_alpha);
+
+/* Widget shader parameters, must match the shader layout. */
+typedef struct uiWidgetBaseParameters {
+ rctf recti, rect;
+ float radi, rad;
+ float facxi, facyi;
+ float round_corners[4];
+ float color_inner1[4], color_inner2[4];
+ float color_outline[4], color_emboss[4];
+ float color_tria[4];
+ float tria1_center[2], tria2_center[2];
+ float tria1_size, tria2_size;
+ float shade_dir;
+ /* We pack alpha check and discard factor in alpha_discard.
+ * If the value is negative then we do alpha check.
+ * The absolute value itself is the discard factor.
+ * Initialize value to 1.0.f if you don't want discard */
+ float alpha_discard;
+} uiWidgetBaseParameters;
+
+enum {
+ ROUNDBOX_TRIA_NONE = 0,
+ ROUNDBOX_TRIA_ARROWS,
+ ROUNDBOX_TRIA_SCROLL,
+ ROUNDBOX_TRIA_MENU,
+ ROUNDBOX_TRIA_CHECK,
+ ROUNDBOX_TRIA_HOLD_ACTION_ARROW,
+
+ ROUNDBOX_TRIA_MAX, /* don't use */
+};
+
+struct Gwn_Batch *ui_batch_roundbox_get(bool filled, bool antialiased);
+struct Gwn_Batch *ui_batch_roundbox_widget_get(int tria);
+struct Gwn_Batch *ui_batch_roundbox_shadow_get(void);
+
+void ui_draw_anti_roundbox(int mode, float minx, float miny, float maxx, float maxy,
+ float rad, bool use_alpha, const float color[4]);
void ui_draw_menu_back(struct uiStyle *style, uiBlock *block, rcti *rect);
+void ui_draw_popover_back(ARegion *ar, struct uiStyle *style, uiBlock *block, rcti *rect);
void ui_draw_pie_center(uiBlock *block);
uiWidgetColors *ui_tooltip_get_theme(void);
void ui_draw_tooltip_background(uiStyle *UNUSED(style), uiBlock *block, rcti *rect);
void ui_draw_search_back(struct uiStyle *style, uiBlock *block, rcti *rect);
-bool ui_link_bezier_points(const rcti *rect, float coord_array[][2], int resol);
-void ui_draw_link_bezier(const rcti *rect);
extern void ui_draw_but(const struct bContext *C, ARegion *ar, struct uiStyle *style, uiBut *but, rcti *rect);
/* theme color init */
@@ -718,6 +771,9 @@ void ui_draw_preview_item(struct uiFontStyle *fstyle, rcti *rect, const char *na
/* margin at top of screen for popups */
#define UI_POPUP_MENU_TOP (int)(8 * UI_DPI_FAC)
+#define UI_PIXEL_AA_JITTER 8
+const float ui_pixel_jitter[UI_PIXEL_AA_JITTER][2];
+
/* interface_style.c */
void uiStyleInit(void);
@@ -739,7 +795,7 @@ void ui_layout_list_set_labels_active(uiLayout *layout);
/* interface_align.c */
bool ui_but_can_align(const uiBut *but) ATTR_WARN_UNUSED_RESULT;
-void ui_block_align_calc(uiBlock *block);
+void ui_block_align_calc(uiBlock *block, const ARegion *region);
/* interface_anim.c */
void ui_but_anim_flag(uiBut *but, float cfra);
@@ -770,4 +826,20 @@ void UI_OT_eyedropper_depth(struct wmOperatorType *ot);
/* interface_eyedropper_driver.c */
void UI_OT_eyedropper_driver(struct wmOperatorType *ot);
+/* interface_util.c */
+
+/**
+ * For use with #ui_rna_collection_search_cb.
+ */
+typedef struct uiRNACollectionSearch {
+ PointerRNA target_ptr;
+ PropertyRNA *target_prop;
+
+ PointerRNA search_ptr;
+ PropertyRNA *search_prop;
+
+ bool *but_changed; /* pointer to uiBut.changed */
+} uiRNACollectionSearch;
+void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char *str, uiSearchItems *items);
+
#endif /* __INTERFACE_INTERN_H__ */
diff --git a/source/blender/editors/interface/interface_layout.c b/source/blender/editors/interface/interface_layout.c
index ff752ddddba..3a8e53d3e90 100644
--- a/source/blender/editors/interface/interface_layout.c
+++ b/source/blender/editors/interface/interface_layout.c
@@ -238,9 +238,10 @@ static int ui_layout_vary_direction(uiLayout *layout)
static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool compact)
{
bool variable;
+ const int unit_x = UI_UNIT_X * (layout->scale[0] ? layout->scale[0] : 1.0f);
if (icon && !name[0])
- return UI_UNIT_X; /* icon only */
+ return unit_x; /* icon only */
variable = (ui_layout_vary_direction(layout) == UI_ITEM_VARY_X);
@@ -249,14 +250,14 @@ static int ui_text_icon_width(uiLayout *layout, const char *name, int icon, bool
layout->item.flag |= UI_ITEM_MIN;
}
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
- /* it may seem odd that the icon only adds (UI_UNIT_X / 4)
+ /* it may seem odd that the icon only adds (unit_x / 4)
* but taking margins into account its fine */
return (UI_fontstyle_string_width(fstyle, name) +
- (UI_UNIT_X * ((compact ? 1.25f : 1.50f) +
- (icon ? 0.25f : 0.0f))));
+ (unit_x * ((compact ? 1.25f : 1.50f) +
+ (icon ? 0.25f : 0.0f))));
}
else {
- return UI_UNIT_X * 10;
+ return unit_x * 10;
}
}
@@ -392,7 +393,7 @@ static void ui_layer_but_cb(bContext *C, void *arg_but, void *arg_index)
static void ui_item_array(
uiLayout *layout, uiBlock *block, const char *name, int icon,
PointerRNA *ptr, PropertyRNA *prop, int len, int x, int y, int w, int UNUSED(h),
- bool expand, bool slider, bool toggle, bool icon_only)
+ bool expand, bool slider, bool toggle, bool icon_only, bool compact)
{
uiStyle *style = layout->root->style;
uiBut *but;
@@ -541,9 +542,18 @@ static void ui_item_array(
}
for (a = 0; a < len; a++) {
- if (!icon_only) str[0] = RNA_property_array_item_char(prop, a);
- if (boolarr) icon = boolarr[a] ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
- but = uiDefAutoButR(block, ptr, prop, a, str, icon, 0, 0, w, UI_UNIT_Y);
+ int width_item;
+
+ if (!icon_only) {
+ str[0] = RNA_property_array_item_char(prop, a);
+ }
+ if (boolarr) {
+ icon = boolarr[a] ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT;
+ }
+ width_item = (compact && type == PROP_BOOLEAN) ?
+ min_ii(w, ui_text_icon_width(layout, str, icon, false)) : w;
+
+ but = uiDefAutoButR(block, ptr, prop, a, str, icon, 0, 0, width_item, UI_UNIT_Y);
if (slider && but->type == UI_BTYPE_NUM)
but->type = UI_BTYPE_NUM_SLIDER;
if (toggle && but->type == UI_BTYPE_CHECKBOX)
@@ -669,27 +679,38 @@ static void ui_keymap_but_cb(bContext *UNUSED(C), void *but_v, void *UNUSED(key_
RNA_boolean_set(&but->rnapoin, "oskey", (but->modifier_key & KM_OSKEY) != 0);
}
-/* create label + button for RNA property */
-static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *name, int icon, PointerRNA *ptr, PropertyRNA *prop, int index, int x, int y, int w, int h, int flag)
+/**
+ * Create label + button for RNA property
+ *
+ * \param w_hint: For varying width layout, this becomes the label width.
+ * Otherwise it's used to fit both items into it.
+ **/
+static uiBut *ui_item_with_label(
+ uiLayout *layout, uiBlock *block, const char *name, int icon,
+ PointerRNA *ptr, PropertyRNA *prop, int index,
+ int x, int y, int w_hint, int h, int flag)
{
uiLayout *sub;
uiBut *but = NULL;
PropertyType type;
PropertySubType subtype;
- int labelw;
+ int prop_but_width = w_hint;
sub = uiLayoutRow(layout, layout->align);
UI_block_layout_set_current(block, sub);
if (name[0]) {
- /* XXX UI_fontstyle_string_width is not accurate */
-#if 0
- labelw = UI_fontstyle_string_width(fstyle, name);
- CLAMP(labelw, w / 4, 3 * w / 4);
-#endif
- labelw = w / 3;
- uiDefBut(block, UI_BTYPE_LABEL, 0, name, x, y, labelw, h, NULL, 0.0, 0.0, 0, 0, "");
- w = w - labelw;
+ int w_label;
+
+ if (ui_layout_vary_direction(layout) == UI_ITEM_VARY_X) {
+ /* w_hint is width for label in this case. Use a default width for property button(s) */
+ prop_but_width = UI_UNIT_X * 5;
+ w_label = w_hint;
+ }
+ else {
+ w_label = w_hint / 3;
+ }
+ uiDefBut(block, UI_BTYPE_LABEL, 0, name, x, y, w_label, h, NULL, 0.0, 0.0, 0, 0, "");
}
type = RNA_property_type(prop);
@@ -697,14 +718,14 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n
if (subtype == PROP_FILEPATH || subtype == PROP_DIRPATH) {
UI_block_layout_set_current(block, uiLayoutRow(sub, true));
- but = uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, w - UI_UNIT_X, h);
+ but = uiDefAutoButR(block, ptr, prop, index, "", icon, x, y, prop_but_width - UI_UNIT_X, h);
/* BUTTONS_OT_file_browse calls UI_context_active_but_prop_get_filebrowser */
uiDefIconButO(block, UI_BTYPE_BUT, subtype == PROP_DIRPATH ? "BUTTONS_OT_directory_browse" : "BUTTONS_OT_file_browse",
WM_OP_INVOKE_DEFAULT, ICON_FILESEL, x, y, UI_UNIT_X, h, NULL);
}
else if (flag & UI_ITEM_R_EVENT) {
- but = uiDefButR_prop(block, UI_BTYPE_KEY_EVENT, 0, name, x, y, w, h, ptr, prop, index, 0, 0, -1, -1, NULL);
+ but = uiDefButR_prop(block, UI_BTYPE_KEY_EVENT, 0, name, x, y, prop_but_width, h, ptr, prop, index, 0, 0, -1, -1, NULL);
}
else if (flag & UI_ITEM_R_FULL_EVENT) {
if (RNA_struct_is_a(ptr->type, &RNA_KeyMapItem)) {
@@ -712,14 +733,17 @@ static uiBut *ui_item_with_label(uiLayout *layout, uiBlock *block, const char *n
WM_keymap_item_to_string(ptr->data, false, buf, sizeof(buf));
- but = uiDefButR_prop(block, UI_BTYPE_HOTKEY_EVENT, 0, buf, x, y, w, h, ptr, prop, 0, 0, 0, -1, -1, NULL);
+ but = uiDefButR_prop(block, UI_BTYPE_HOTKEY_EVENT, 0, buf, x, y, prop_but_width, h, ptr, prop, 0, 0, 0, -1, -1, NULL);
UI_but_func_set(but, ui_keymap_but_cb, but, NULL);
if (flag & UI_ITEM_R_IMMEDIATE)
UI_but_flag_enable(but, UI_BUT_IMMEDIATE);
}
}
- else
- but = uiDefAutoButR(block, ptr, prop, index, (type == PROP_ENUM && !(flag & UI_ITEM_R_ICON_ONLY)) ? NULL : "", icon, x, y, w, h);
+ else {
+ const char *str = (type == PROP_ENUM && !(flag & UI_ITEM_R_ICON_ONLY)) ? NULL : "";
+ but = uiDefAutoButR(block, ptr, prop, index, str, icon,
+ x, y, prop_but_width, h);
+ }
UI_block_layout_set_current(block, layout);
return but;
@@ -870,7 +894,7 @@ static uiBut *uiItemFullO_ptr_ex(
return but;
}
-static void ui_item_hold_menu(struct bContext *C, ARegion *butregion, uiBut *but)
+static void ui_item_menu_hold(struct bContext *C, ARegion *butregion, uiBut *but)
{
uiPopupMenu *pup = UI_popup_menu_begin(C, "", ICON_NONE);
uiLayout *layout = UI_popup_menu_layout(pup);
@@ -878,6 +902,24 @@ static void ui_item_hold_menu(struct bContext *C, ARegion *butregion, uiBut *but
UI_popup_menu_but_set(pup, butregion, but);
block->flag |= UI_BLOCK_POPUP_HOLD;
+ block->flag |= UI_BLOCK_IS_FLIP;
+
+ char direction = UI_DIR_DOWN;
+ if (!but->drawstr[0]) {
+ if (butregion->alignment == RGN_ALIGN_LEFT) {
+ direction = UI_DIR_RIGHT;
+ }
+ else if (butregion->alignment == RGN_ALIGN_RIGHT) {
+ direction = UI_DIR_LEFT;
+ }
+ else if (butregion->alignment == RGN_ALIGN_BOTTOM) {
+ direction = UI_DIR_UP;
+ }
+ else {
+ direction = UI_DIR_DOWN;
+ }
+ }
+ UI_block_direction_set(block, direction);
const char *menu_id = but->hold_argN;
MenuType *mt = WM_menutype_find(menu_id, true);
@@ -907,7 +949,7 @@ void uiItemFullOMenuHold_ptr(
PointerRNA *r_opptr)
{
uiBut *but = uiItemFullO_ptr_ex(layout, ot, name, icon, properties, context, flag, r_opptr);
- UI_but_func_hold_set(but, ui_item_hold_menu, BLI_strdup(menu_id));
+ UI_but_func_hold_set(but, ui_item_menu_hold, BLI_strdup(menu_id));
}
void uiItemFullO(
@@ -1300,8 +1342,10 @@ void uiItemO(uiLayout *layout, const char *name, int icon, const char *opname)
/* RNA property items */
static void ui_item_rna_size(
- uiLayout *layout, const char *name, int icon, PointerRNA *ptr, PropertyRNA *prop,
- int index, bool icon_only, int *r_w, int *r_h)
+ uiLayout *layout, const char *name, int icon,
+ PointerRNA *ptr, PropertyRNA *prop,
+ int index, bool icon_only, bool compact,
+ int *r_w, int *r_h)
{
PropertyType type;
PropertySubType subtype;
@@ -1327,7 +1371,7 @@ static void ui_item_rna_size(
RNA_property_enum_items_gettexted(layout->root->block->evil_C, ptr, prop, &item_array, NULL, &free);
for (item = item_array; item->identifier; item++) {
if (item->identifier[0]) {
- w = max_ii(w, ui_text_icon_width(layout, item->name, item->icon, 0));
+ w = max_ii(w, ui_text_icon_width(layout, item->name, item->icon, compact));
}
}
if (free) {
@@ -1338,12 +1382,13 @@ static void ui_item_rna_size(
if (!w) {
if (type == PROP_ENUM && icon_only) {
- w = ui_text_icon_width(layout, "", ICON_BLANK1, 0);
+ w = ui_text_icon_width(layout, "", ICON_BLANK1, compact);
if (index != RNA_ENUM_VALUE)
w += 0.6f * UI_UNIT_X;
}
else {
- w = ui_text_icon_width(layout, name, icon, 0);
+ /* not compact for float/int buttons, looks too squashed */
+ w = ui_text_icon_width(layout, name, icon, ELEM(type, PROP_FLOAT, PROP_INT) ? false : compact);
}
}
h = UI_UNIT_Y;
@@ -1380,7 +1425,7 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
PropertyType type;
char namestr[UI_MAX_NAME_STR];
int len, w, h;
- bool slider, toggle, expand, icon_only, no_bg;
+ bool slider, toggle, expand, icon_only, no_bg, compact;
bool is_array;
UI_block_layout_set_current(block, layout);
@@ -1413,7 +1458,12 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
name = ui_item_name_add_colon(name, namestr);
}
else if (type == PROP_ENUM && index != RNA_ENUM_VALUE) {
- name = ui_item_name_add_colon(name, namestr);
+ if (flag & UI_ITEM_R_COMPACT) {
+ name = "";
+ }
+ else {
+ name = ui_item_name_add_colon(name, namestr);
+ }
}
/* menus and pie-menus don't show checkbox without this */
@@ -1441,16 +1491,19 @@ void uiItemFullR(uiLayout *layout, PointerRNA *ptr, PropertyRNA *prop, int index
expand = (flag & UI_ITEM_R_EXPAND) != 0;
icon_only = (flag & UI_ITEM_R_ICON_ONLY) != 0;
no_bg = (flag & UI_ITEM_R_NO_BG) != 0;
+ compact = (flag & UI_ITEM_R_COMPACT) != 0;
/* get size */
- ui_item_rna_size(layout, name, icon, ptr, prop, index, icon_only, &w, &h);
+ ui_item_rna_size(layout, name, icon, ptr, prop, index, icon_only, compact, &w, &h);
if (no_bg)
UI_block_emboss_set(block, UI_EMBOSS_NONE);
/* array property */
if (index == RNA_NO_INDEX && is_array)
- ui_item_array(layout, block, name, icon, ptr, prop, len, 0, 0, w, h, expand, slider, toggle, icon_only);
+ ui_item_array(
+ layout, block, name, icon, ptr, prop, len, 0, 0, w, h,
+ expand, slider, toggle, icon_only, compact);
/* enum item */
else if (type == PROP_ENUM && index == RNA_ENUM_VALUE) {
if (icon && name[0] && !icon_only)
@@ -1639,94 +1692,6 @@ void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname
/* Pointer RNA button with search */
-typedef struct CollItemSearch {
- struct CollItemSearch *next, *prev;
- char *name;
- int index;
- int iconid;
-} CollItemSearch;
-
-static int sort_search_items_list(const void *a, const void *b)
-{
- const CollItemSearch *cis1 = a;
- const CollItemSearch *cis2 = b;
-
- if (BLI_strcasecmp(cis1->name, cis2->name) > 0)
- return 1;
- else
- return 0;
-}
-
-static void rna_search_cb(const struct bContext *C, void *arg_but, const char *str, uiSearchItems *items)
-{
- uiBut *but = arg_but;
- char *name;
- int i = 0, iconid = 0, flag = RNA_property_flag(but->rnaprop);
- ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list");
- CollItemSearch *cis;
- const bool skip_filter = !but->changed;
-
- /* build a temporary list of relevant items first */
- RNA_PROP_BEGIN (&but->rnasearchpoin, itemptr, but->rnasearchprop)
- {
- if (flag & PROP_ID_SELF_CHECK)
- if (itemptr.data == but->rnapoin.id.data)
- continue;
-
- /* use filter */
- if (RNA_property_type(but->rnaprop) == PROP_POINTER) {
- if (RNA_property_pointer_poll(&but->rnapoin, but->rnaprop, &itemptr) == 0)
- continue;
- }
-
- if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
- ID *id = itemptr.data;
- char name_ui[MAX_ID_NAME];
-
-#if 0 /* this name is used for a string comparison and can't be modified, TODO */
- /* if ever enabled, make name_ui be MAX_ID_NAME+1 */
- BKE_id_ui_prefix(name_ui, id);
-#else
- BLI_strncpy(name_ui, id->name + 2, sizeof(name_ui));
-#endif
- name = BLI_strdup(name_ui);
- iconid = ui_id_icon_get(C, id, false);
- }
- else {
- name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
- iconid = 0;
- }
-
- if (name) {
- if (skip_filter || BLI_strcasestr(name, str)) {
- cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch");
- cis->name = MEM_dupallocN(name);
- cis->index = i;
- cis->iconid = iconid;
- BLI_addtail(items_list, cis);
- }
- MEM_freeN(name);
- }
-
- i++;
- }
- RNA_PROP_END;
-
- BLI_listbase_sort(items_list, sort_search_items_list);
-
- /* add search items from temporary list */
- for (cis = items_list->first; cis; cis = cis->next) {
- if (false == UI_search_item_add(items, cis->name, SET_INT_IN_POINTER(cis->index), cis->iconid)) {
- break;
- }
- }
-
- for (cis = items_list->first; cis; cis = cis->next) {
- MEM_freeN(cis->name);
- }
- BLI_freelistN(items_list);
- MEM_freeN(items_list);
-}
static void search_id_collection(StructRNA *ptype, PointerRNA *ptr, PropertyRNA **prop)
{
@@ -1768,6 +1733,8 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
/* turn button into search button */
if (searchprop) {
+ uiRNACollectionSearch *coll_search = MEM_mallocN(sizeof(*coll_search), __func__);
+
but->type = UI_BTYPE_SEARCH_MENU;
but->hardmax = MAX2(but->hardmax, 256.0f);
but->rnasearchpoin = *searchptr;
@@ -1777,13 +1744,22 @@ void ui_but_add_search(uiBut *but, PointerRNA *ptr, PropertyRNA *prop, PointerRN
but->flag |= UI_BUT_VALUE_CLEAR;
}
+ coll_search->target_ptr = *ptr;
+ coll_search->target_prop = prop;
+ coll_search->search_ptr = *searchptr;
+ coll_search->search_prop = searchprop;
+ coll_search->but_changed = &but->changed;
+
if (RNA_property_type(prop) == PROP_ENUM) {
/* XXX, this will have a menu string,
* but in this case we just want the text */
but->str[0] = 0;
}
- UI_but_func_search_set(but, ui_searchbox_create_generic, rna_search_cb, but, NULL, NULL);
+ UI_but_func_search_set(
+ but, ui_searchbox_create_generic, ui_rna_collection_search_cb,
+ coll_search, NULL, NULL);
+ but->free_search_arg = true;
}
else if (but->type == UI_BTYPE_SEARCH_MENU) {
/* In case we fail to find proper searchprop, so other code might have already set but->type to search menu... */
@@ -1847,7 +1823,7 @@ void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propna
/* create button */
block = uiLayoutGetBlock(layout);
- ui_item_rna_size(layout, name, icon, ptr, prop, 0, 0, &w, &h);
+ ui_item_rna_size(layout, name, icon, ptr, prop, 0, 0, false, &w, &h);
w += UI_UNIT_X; /* X icon needs more space */
but = ui_item_with_label(layout, block, name, icon, ptr, prop, 0, 0, 0, w, h, 0);
@@ -1865,6 +1841,35 @@ static void ui_item_menutype_func(bContext *C, uiLayout *layout, void *arg_mt)
layout->root->block->flag ^= UI_BLOCK_IS_FLIP;
}
+static void ui_item_paneltype_func(bContext *C, uiLayout *layout, void *arg_mt)
+{
+ PanelType *pt = (PanelType *)arg_mt;
+
+ /* TODO: move into UI_paneltype_draw */
+ Panel *panel = MEM_callocN(sizeof(Panel), "popover panel");
+ panel->type = pt;
+
+ if (layout->context) {
+ CTX_store_set(C, layout->context);
+ }
+
+ if (pt->draw_header) {
+ panel->layout = uiLayoutRow(layout, false);
+ pt->draw_header(C, panel);
+ panel->layout = NULL;
+ }
+
+ panel->layout = layout;
+ pt->draw(C, panel);
+ panel->layout = NULL;
+
+ if (layout->context) {
+ CTX_store_set(C, NULL);
+ }
+
+ MEM_freeN(panel);
+}
+
static uiBut *ui_item_menu(
uiLayout *layout, const char *name, int icon, uiMenuCreateFunc func, void *arg, void *argN,
const char *tip, bool force_menu)
@@ -1942,6 +1947,82 @@ void uiItemM(uiLayout *layout, bContext *UNUSED(C), const char *menuname, const
ui_item_menu(layout, name, icon, ui_item_menutype_func, mt, NULL, TIP_(mt->description), false);
}
+/* popover */
+void uiItemPopoverPanel_ptr(uiLayout *layout, bContext *C, PanelType *pt, const char *name, int icon)
+{
+ if (!name) {
+ name = CTX_IFACE_(pt->translation_context, pt->label);
+ }
+
+ if (layout->root->type == UI_LAYOUT_MENU && !icon)
+ icon = ICON_BLANK1;
+
+ uiBut *but = ui_item_menu(layout, name, icon, ui_item_paneltype_func, pt, NULL, NULL, true);
+ but->type = UI_BTYPE_POPOVER;
+ if (pt->poll && (pt->poll(C, pt) == false)) {
+ but->flag |= UI_BUT_DISABLED;
+ }
+}
+
+void uiItemPopoverPanel(
+ uiLayout *layout, bContext *C,
+ int space_id, int region_id, const char *panel_type,
+ const char *name, int icon)
+{
+ SpaceType *st = BKE_spacetype_from_id(space_id);
+ if (st == NULL) {
+ RNA_warning("space type not found %d", space_id);
+ return;
+ }
+ ARegionType *art = BKE_regiontype_from_id(st, region_id);
+ if (art == NULL) {
+ RNA_warning("region type not found %d", region_id);
+ return;
+ }
+
+ PanelType *pt;
+ for (pt = art->paneltypes.first; pt; pt = pt->next) {
+ if (STREQ(pt->idname, panel_type)) {
+ break;
+ }
+ }
+
+ if (pt == NULL) {
+ RNA_warning("area type not found %s", panel_type);
+ return;
+ }
+
+ uiItemPopoverPanel_ptr(layout, C, pt, name, icon);
+}
+
+void uiItemPopoverPanelFromGroup(
+ uiLayout *layout, bContext *C,
+ int space_id, int region_id, const char *context, const char *category)
+{
+ SpaceType *st = BKE_spacetype_from_id(space_id);
+ if (st == NULL) {
+ RNA_warning("space type not found %d", space_id);
+ return;
+ }
+ ARegionType *art = BKE_regiontype_from_id(st, region_id);
+ if (art == NULL) {
+ RNA_warning("region type not found %d", region_id);
+ return;
+ }
+
+ for (PanelType *pt = art->paneltypes.first; pt; pt = pt->next) {
+ /* Causes too many panels, check context. */
+ if (/* (*context == '\0') || */ STREQ(pt->context, context)) {
+ if ((*category == '\0') || STREQ(pt->category, category)) {
+ if (pt->poll == NULL || pt->poll(C, pt)) {
+ uiItemPopoverPanel_ptr(layout, C, pt, NULL, ICON_NONE);
+ }
+ }
+ }
+ }
+}
+
+
/* label item */
static uiBut *uiItemL_(uiLayout *layout, const char *name, int icon)
{
@@ -3645,6 +3726,18 @@ MenuType *UI_but_menutype_get(uiBut *but)
}
}
+/* this is a bit of a hack but best keep it in one place at least */
+PanelType *UI_but_paneltype_get(uiBut *but)
+{
+ if (but->menu_create_func == ui_item_paneltype_func) {
+ return (PanelType *)but->poin;
+ }
+ else {
+ return NULL;
+ }
+}
+
+
void UI_menutype_draw(bContext *C, MenuType *mt, struct uiLayout *layout)
{
Menu menu = {
diff --git a/source/blender/editors/interface/interface_ops.c b/source/blender/editors/interface/interface_ops.c
index 046bb114a62..ef328c2cd5e 100644
--- a/source/blender/editors/interface/interface_ops.c
+++ b/source/blender/editors/interface/interface_ops.c
@@ -42,14 +42,20 @@
#include "BLT_lang.h"
#include "BKE_context.h"
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
#include "BKE_screen.h"
#include "BKE_global.h"
+#include "BKE_library_override.h"
#include "BKE_node.h"
#include "BKE_text.h" /* for UI_OT_reports_to_text */
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
+#include "RNA_types.h"
#include "UI_interface.h"
@@ -328,6 +334,337 @@ static void UI_OT_unset_property_button(wmOperatorType *ot)
ot->flag = OPTYPE_UNDO;
}
+/* Use/Unuse Property Button Operator ------------------------ */
+
+static int use_property_button_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ PointerRNA ptr, scene_props_ptr;
+ PropertyRNA *prop;
+ IDProperty *props;
+
+ uiBut *but = UI_context_active_but_get(C);
+
+ prop = but->rnaprop;
+ ptr = but->rnapoin;
+ props = (IDProperty *)ptr.data;
+ /* XXX Using existing data struct to pass another RNAPointer */
+ scene_props_ptr = but->rnasearchpoin;
+
+ const char *identifier = RNA_property_identifier(prop);
+ if (IDP_GetPropertyFromGroup(props, identifier)) {
+ return OPERATOR_CANCELLED;
+ }
+
+ int array_len = RNA_property_array_length(&scene_props_ptr, prop);
+ bool is_array = array_len != 0;
+
+ switch (RNA_property_type(prop)) {
+ case PROP_FLOAT:
+ {
+ if (is_array) {
+ float values[RNA_MAX_ARRAY_LENGTH];
+ RNA_property_float_get_array(&scene_props_ptr, prop, values);
+ BKE_collection_engine_property_add_float_array(props, identifier, values, array_len);
+ }
+ else {
+ float value = RNA_property_float_get(&scene_props_ptr, prop);
+ BKE_collection_engine_property_add_float(props, identifier, value);
+ }
+ break;
+ }
+ case PROP_ENUM:
+ {
+ int value = RNA_enum_get(&scene_props_ptr, identifier);
+ BKE_collection_engine_property_add_int(props, identifier, value);
+ break;
+ }
+ case PROP_INT:
+ {
+ int value = RNA_int_get(&scene_props_ptr, identifier);
+ BKE_collection_engine_property_add_int(props, identifier, value);
+ break;
+ }
+ case PROP_BOOLEAN:
+ {
+ int value = RNA_boolean_get(&scene_props_ptr, identifier);
+ BKE_collection_engine_property_add_bool(props, identifier, value);
+ break;
+ }
+ case PROP_STRING:
+ case PROP_POINTER:
+ case PROP_COLLECTION:
+ default:
+ break;
+ }
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update((ID *)CTX_data_scene(C), 0);
+
+ return OPERATOR_FINISHED;
+}
+
+static void UI_OT_use_property_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Use property";
+ ot->idname = "UI_OT_use_property_button";
+ ot->description = "Create a property";
+
+ /* callbacks */
+ ot->poll = ED_operator_regionactive;
+ ot->exec = use_property_button_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+}
+
+static int unuse_property_button_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ /* try to unset the nominated property */
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+ const char *identifier = RNA_property_identifier(prop);
+
+ IDProperty *props = (IDProperty *)ptr.data;
+ IDProperty *prop_to_remove = IDP_GetPropertyFromGroup(props, identifier);
+ IDP_FreeFromGroup(props, prop_to_remove);
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update((ID *)CTX_data_scene(C), 0);
+
+ return OPERATOR_FINISHED;
+}
+
+static void UI_OT_unuse_property_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Unuse property";
+ ot->idname = "UI_OT_unuse_property_button";
+ ot->description = "Remove a property";
+
+ /* callbacks */
+ ot->poll = ED_operator_regionactive;
+ ot->exec = unuse_property_button_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+}
+
+
+
+
+
+/* Note that we use different values for UI/UX than 'real' override operations, user does not care
+ * whether it's added or removed for the differential operation e.g. */
+enum {
+ UIOverride_Type_NOOP = 0,
+ UIOverride_Type_Replace = 1,
+ UIOverride_Type_Difference = 2, /* Add/subtract */
+ UIOverride_Type_Factor = 3, /* Multiply */
+ /* TODO: should/can we expose insert/remove ones for collections? Doubt it... */
+};
+
+static EnumPropertyItem override_type_items[] = {
+ {UIOverride_Type_NOOP, "NOOP", 0, "NoOp",
+ "'No-Operation', place holder preventing automatic override to ever affect the property"},
+ {UIOverride_Type_Replace, "REPLACE", 0, "Replace", "Completely replace value from linked data by local one"},
+ {UIOverride_Type_Difference, "DIFFERENCE", 0, "Difference", "Store difference to linked data value"},
+ {UIOverride_Type_Factor, "FACTOR", 0, "Factor", "Store factor to linked data value (useful e.g. for scale)"},
+ {0, NULL, 0, NULL, NULL}
+};
+
+
+static int override_type_set_button_poll(bContext *C)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ const int override_status = RNA_property_override_status(&ptr, prop, index);
+
+ return (ptr.data && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDABLE));
+}
+
+static int override_type_set_button_exec(bContext *C, wmOperator *op)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+ bool created;
+ const bool all = RNA_boolean_get(op->ptr, "all");
+ const int op_type = RNA_enum_get(op->ptr, "type");
+
+ short operation;
+
+ switch (op_type) {
+ case UIOverride_Type_NOOP:
+ operation = IDOVERRIDESTATIC_OP_NOOP;
+ break;
+ case UIOverride_Type_Replace:
+ operation = IDOVERRIDESTATIC_OP_REPLACE;
+ break;
+ case UIOverride_Type_Difference:
+ operation = IDOVERRIDESTATIC_OP_ADD; /* override code will automatically switch to subtract if needed. */
+ break;
+ case UIOverride_Type_Factor:
+ operation = IDOVERRIDESTATIC_OP_MULTIPLY;
+ break;
+ default:
+ operation = IDOVERRIDESTATIC_OP_REPLACE;
+ BLI_assert(0);
+ break;
+ }
+
+ /* try to reset the nominated setting to its default value */
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ BLI_assert(ptr.id.data != NULL);
+
+ if (all) {
+ index = -1;
+ }
+
+ IDOverrideStaticPropertyOperation *opop = RNA_property_override_property_operation_get(
+ &ptr, prop, operation, index, true, NULL, &created);
+ if (!created) {
+ opop->operation = operation;
+ }
+
+ return operator_button_property_finish(C, &ptr, prop);
+}
+
+static int override_type_set_button_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+#if 0 /* Disabled for now */
+ return WM_menu_invoke_ex(C, op, WM_OP_INVOKE_DEFAULT);
+#else
+ RNA_enum_set(op->ptr, "type", IDOVERRIDESTATIC_OP_REPLACE);
+ return override_type_set_button_exec(C, op);
+#endif
+}
+
+static void UI_OT_override_type_set_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Define Override Type";
+ ot->idname = "UI_OT_override_type_set_button";
+ ot->description = "Create an override operation, or set the type of an existing one";
+
+ /* callbacks */
+ ot->poll = override_type_set_button_poll;
+ ot->exec = override_type_set_button_exec;
+ ot->invoke = override_type_set_button_invoke;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
+ ot->prop = RNA_def_enum(ot->srna, "type", override_type_items, UIOverride_Type_Replace,
+ "Type", "Type of override operation");
+ /* TODO: add itemf callback, not all options are available for all data types... */
+}
+
+
+static int override_remove_button_poll(bContext *C)
+{
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ const int override_status = RNA_property_override_status(&ptr, prop, index);
+
+ return (ptr.data && ptr.id.data && prop && (override_status & RNA_OVERRIDE_STATUS_OVERRIDDEN));
+}
+
+static int override_remove_button_exec(bContext *C, wmOperator *op)
+{
+ PointerRNA ptr, id_refptr, src;
+ PropertyRNA *prop;
+ int index;
+ const bool all = RNA_boolean_get(op->ptr, "all");
+
+ /* try to reset the nominated setting to its default value */
+ UI_context_active_but_prop_get(C, &ptr, &prop, &index);
+
+ ID *id = ptr.id.data;
+ IDOverrideStaticProperty *oprop = RNA_property_override_property_find(&ptr, prop);
+ BLI_assert(oprop != NULL);
+ BLI_assert(id != NULL && id->override_static != NULL);
+
+ const bool is_template = (id->override_static->reference == NULL);
+
+ /* We need source (i.e. linked data) to restore values of deleted overrides...
+ * If this is an override template, we obviously do not need to restore anything. */
+ if (!is_template) {
+ RNA_id_pointer_create(id->override_static->reference, &id_refptr);
+ if (!RNA_path_resolve(&id_refptr, oprop->rna_path, &src, NULL)) {
+ BLI_assert(0 && "Failed to create matching source (linked data) RNA pointer");
+ }
+ }
+
+ if (!all && index != -1) {
+ bool is_strict_find;
+ /* Remove override operation for given item, add singular operations for the other items as needed. */
+ IDOverrideStaticPropertyOperation *opop = BKE_override_static_property_operation_find(
+ oprop, NULL, NULL, index, index, false, &is_strict_find);
+ BLI_assert(opop != NULL);
+ if (!is_strict_find) {
+ /* No specific override operation, we have to get generic one,
+ * and create item-specific override operations for all but given index, before removing generic one. */
+ for (int idx = RNA_property_array_length(&ptr, prop); idx--; ) {
+ if (idx != index) {
+ BKE_override_static_property_operation_get(oprop, opop->operation, NULL, NULL, idx, idx, true, NULL, NULL);
+ }
+ }
+ }
+ BKE_override_static_property_operation_delete(oprop, opop);
+ if (!is_template) {
+ RNA_property_copy(&ptr, &src, prop, index);
+ }
+ if (BLI_listbase_is_empty(&oprop->operations)) {
+ BKE_override_static_property_delete(id->override_static, oprop);
+ }
+ }
+ else {
+ /* Just remove whole generic override operation of this property. */
+ BKE_override_static_property_delete(id->override_static, oprop);
+ if (!is_template) {
+ RNA_property_copy(&ptr, &src, prop, -1);
+ }
+ }
+
+ return operator_button_property_finish(C, &ptr, prop);
+}
+
+static void UI_OT_override_remove_button(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Remove Override";
+ ot->idname = "UI_OT_override_remove_button";
+ ot->description = "Remove an override operation";
+
+ /* callbacks */
+ ot->poll = override_remove_button_poll;
+ ot->exec = override_remove_button_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "all", 1, "All", "Reset to default values all elements of the array");
+}
+
+
+
+
/* Copy To Selected Operator ------------------------ */
bool UI_context_copy_to_selected_list(
@@ -1118,6 +1455,10 @@ void ED_operatortypes_ui(void)
WM_operatortype_append(UI_OT_copy_python_command_button);
WM_operatortype_append(UI_OT_reset_default_button);
WM_operatortype_append(UI_OT_unset_property_button);
+ WM_operatortype_append(UI_OT_use_property_button);
+ WM_operatortype_append(UI_OT_unuse_property_button);
+ WM_operatortype_append(UI_OT_override_type_set_button);
+ WM_operatortype_append(UI_OT_override_remove_button);
WM_operatortype_append(UI_OT_copy_to_selected_button);
WM_operatortype_append(UI_OT_reports_to_textblock); /* XXX: temp? */
WM_operatortype_append(UI_OT_drop_color);
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index d9685d7281b..f621a906789 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -50,9 +50,6 @@
#include "BKE_context.h"
#include "BKE_screen.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
#include "BLF_api.h"
#include "WM_api.h"
@@ -65,6 +62,8 @@
#include "UI_interface_icons.h"
#include "UI_resources.h"
+#include "GPU_immediate.h"
+
#include "interface_intern.h"
/*********************** defines and structs ************************/
@@ -393,54 +392,42 @@ static void ui_offset_panel_block(uiBlock *block)
/**************************** drawing *******************************/
-/* extern used by previewrender */
-#if 0 /*UNUSED 2.5*/
-static void uiPanelPush(uiBlock *block)
-{
- glPushMatrix();
-
- if (block->panel)
- glTranslatef((float)block->panel->ofsx, (float)block->panel->ofsy, 0.0);
-}
-
-static void uiPanelPop(uiBlock *UNUSED(block))
-{
- glPopMatrix();
-}
-#endif
-
/* triangle 'icon' for panel header */
-void UI_draw_icon_tri(float x, float y, char dir)
+void UI_draw_icon_tri(float x, float y, char dir, const float color[4])
{
float f3 = 0.15 * U.widget_unit;
float f5 = 0.25 * U.widget_unit;
float f7 = 0.35 * U.widget_unit;
if (dir == 'h') {
- ui_draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y);
+ UI_draw_anti_tria(x - f3, y - f5, x - f3, y + f5, x + f7, y, color);
}
else if (dir == 't') {
- ui_draw_anti_tria(x - f5, y - f7, x + f5, y - f7, x, y + f3);
+ UI_draw_anti_tria(x - f5, y - f7, x + f5, y - f7, x, y + f3, color);
}
else { /* 'v' = vertical, down */
- ui_draw_anti_tria(x - f5, y + f3, x + f5, y + f3, x, y - f7);
+ UI_draw_anti_tria(x - f5, y + f3, x + f5, y + f3, x, y - f7, color);
}
}
/* triangle 'icon' inside rect */
static void ui_draw_tria_rect(const rctf *rect, char dir)
{
+ float color[4];
+ UI_GetThemeColor3fv(TH_TITLE, color);
+ color[3] = 1.0f;
+
if (dir == 'h') {
float half = 0.5f * BLI_rctf_size_y(rect);
- ui_draw_anti_tria(rect->xmin, rect->ymin, rect->xmin, rect->ymax, rect->xmax, rect->ymin + half);
+ UI_draw_anti_tria(rect->xmin, rect->ymin, rect->xmin, rect->ymax, rect->xmax, rect->ymin + half, color);
}
else {
float half = 0.5f * BLI_rctf_size_x(rect);
- ui_draw_anti_tria(rect->xmin, rect->ymax, rect->xmax, rect->ymax, rect->xmin + half, rect->ymin);
+ UI_draw_anti_tria(rect->xmin, rect->ymax, rect->xmax, rect->ymax, rect->xmin + half, rect->ymin, color);
}
}
-static void ui_draw_anti_x(float x1, float y1, float x2, float y2)
+static void ui_draw_anti_x(unsigned int pos, float x1, float y1, float x2, float y2)
{
/* set antialias line */
@@ -448,9 +435,16 @@ static void ui_draw_anti_x(float x1, float y1, float x2, float y2)
glEnable(GL_BLEND);
glLineWidth(2.0);
-
- fdrawline(x1, y1, x2, y2);
- fdrawline(x1, y2, x2, y1);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x2, y2);
+
+ immVertex2f(pos, x1, y2);
+ immVertex2f(pos, x2, y1);
+
+ immEnd();
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
@@ -458,16 +452,16 @@ static void ui_draw_anti_x(float x1, float y1, float x2, float y2)
}
/* x 'icon' for panel header */
-static void ui_draw_x_icon(float x, float y)
+static void ui_draw_x_icon(unsigned int pos, float x, float y)
{
- ui_draw_anti_x(x, y, x + 9.375f, y + 9.375f);
+ ui_draw_anti_x(pos, x, y, x + 9.375f, y + 9.375f);
}
#define PNL_ICON UI_UNIT_X /* could be UI_UNIT_Y too */
-static void ui_draw_panel_scalewidget(const rcti *rect)
+static void ui_draw_panel_scalewidget(unsigned int pos, const rcti *rect)
{
float xmin, xmax, dx;
float ymin, ymax, dy;
@@ -481,18 +475,54 @@ static void ui_draw_panel_scalewidget(const rcti *rect)
dy = 0.5f * (ymax - ymin);
glEnable(GL_BLEND);
- glColor4ub(255, 255, 255, 50);
- fdrawline(xmin, ymin, xmax, ymax);
- fdrawline(xmin + dx, ymin, xmax, ymax - dy);
+ immUniformColor4ub(255, 255, 255, 50);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, xmin, ymin);
+ immVertex2f(pos, xmax, ymax);
+
+ immVertex2f(pos, xmin + dx, ymin);
+ immVertex2f(pos, xmax, ymax - dy);
+
+ immEnd();
- glColor4ub(0, 0, 0, 50);
- fdrawline(xmin, ymin + 1, xmax, ymax + 1);
- fdrawline(xmin + dx, ymin + 1, xmax, ymax - dy + 1);
+ immUniformColor4ub(0, 0, 0, 50);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, xmin, ymin + 1);
+ immVertex2f(pos, xmax, ymax + 1);
+
+ immVertex2f(pos, xmin + dx, ymin + 1);
+ immVertex2f(pos, xmax, ymax - dy + 1);
+
+ immEnd();
+
glDisable(GL_BLEND);
}
-static void ui_draw_panel_dragwidget(const rctf *rect)
+
+static void immRectf_tris_color_ex(unsigned int pos, float x1, float y1, float x2, float y2,
+ unsigned int col, const float color[3])
{
- unsigned char col_back[3], col_high[3], col_dark[3];
+ immAttrib4fv(col, color);
+ immVertex2f(pos, x1, y1);
+ immAttrib4fv(col, color);
+ immVertex2f(pos, x2, y1);
+ immAttrib4fv(col, color);
+ immVertex2f(pos, x2, y2);
+
+ immAttrib4fv(col, color);
+ immVertex2f(pos, x1, y1);
+ immAttrib4fv(col, color);
+ immVertex2f(pos, x2, y2);
+ immAttrib4fv(col, color);
+ immVertex2f(pos, x1, y2);
+}
+
+static void ui_draw_panel_dragwidget(unsigned int pos, unsigned int col, const rctf *rect)
+{
+ float col_high[4], col_dark[4];
const int col_tint = 84;
const int px = (int)U.pixelsize;
@@ -507,24 +537,24 @@ static void ui_draw_panel_dragwidget(const rctf *rect)
const int x_ofs = y_ofs;
int i_x, i_y;
-
- UI_GetThemeColor3ubv(UI_GetThemeValue(TH_PANEL_SHOW_HEADER) ? TH_PANEL_HEADER : TH_PANEL_BACK, col_back);
- UI_GetColorPtrShade3ubv(col_back, col_high, col_tint);
- UI_GetColorPtrShade3ubv(col_back, col_dark, -col_tint);
-
+ int col_id = UI_GetThemeValue(TH_PANEL_SHOW_HEADER) ? TH_PANEL_HEADER : TH_PANEL_BACK;
+ UI_GetThemeColorShade4fv(col_id, col_tint, col_high);
+ UI_GetThemeColorShade4fv(col_id, -col_tint, col_dark);
/* draw multiple boxes */
+ immBegin(GWN_PRIM_TRIS, 4 * 2 * (6 * 2));
for (i_x = 0; i_x < 4; i_x++) {
for (i_y = 0; i_y < 2; i_y++) {
const int x_co = (x_min + x_ofs) + (i_x * (box_size + box_margin));
const int y_co = (y_min + y_ofs) + (i_y * (box_size + box_margin));
- glColor3ubv(col_dark);
- glRectf(x_co - box_size, y_co - px_zoom, x_co, (y_co + box_size) - px_zoom);
- glColor3ubv(col_high);
- glRectf(x_co - box_size, y_co, x_co, y_co + box_size);
+ immRectf_tris_color_ex(pos, x_co - box_size, y_co - px_zoom, x_co, (y_co + box_size) - px_zoom,
+ col, col_dark);
+ immRectf_tris_color_ex(pos, x_co - box_size, y_co, x_co, y_co + box_size,
+ col, col_high);
}
}
+ immEnd();
}
@@ -534,29 +564,30 @@ static void ui_draw_aligned_panel_header(uiStyle *style, uiBlock *block, const r
rcti hrect;
int pnl_icons;
const char *activename = panel->drawname[0] ? panel->drawname : panel->panelname;
+ unsigned char col_title[4];
/* + 0.001f to avoid flirting with float inaccuracy */
if (panel->control & UI_PNL_CLOSE)
pnl_icons = (panel->labelofs + 2 * PNL_ICON + 5) / block->aspect + 0.001f;
else
pnl_icons = (panel->labelofs + PNL_ICON + 5) / block->aspect + 0.001f;
-
- /* active tab */
+
/* draw text label */
- UI_ThemeColor(TH_TITLE);
-
+ UI_GetThemeColor3ubv(TH_TITLE, col_title);
+ col_title[3] = 255;
+
hrect = *rect;
if (dir == 'h') {
hrect.xmin = rect->xmin + pnl_icons;
hrect.ymin += 2.0f / block->aspect;
- UI_fontstyle_draw(&style->paneltitle, &hrect, activename);
+ UI_fontstyle_draw(&style->paneltitle, &hrect, activename, col_title);
}
else {
/* ignore 'pnl_icons', otherwise the text gets offset horizontally
* + 0.001f to avoid flirting with float inaccuracy
*/
hrect.xmin = rect->xmin + (PNL_ICON + 5) / block->aspect + 0.001f;
- UI_fontstyle_draw_rotated(&style->paneltitle, &hrect, activename);
+ UI_fontstyle_draw_rotated(&style->paneltitle, &hrect, activename, col_title);
}
}
@@ -566,7 +597,7 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
Panel *panel = block->panel;
rcti headrect;
rctf itemrect;
- int ofsx;
+ float color[4];
const bool is_closed_x = (panel->flag & PNL_CLOSEDX) ? true : false;
const bool is_closed_y = (panel->flag & PNL_CLOSEDY) ? true : false;
@@ -579,6 +610,9 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
headrect.ymin = headrect.ymax;
headrect.ymax = headrect.ymin + floor(PNL_HEADER / block->aspect + 0.001f);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
{
float minx = rect->xmin;
float maxx = is_closed_x ? (minx + PNL_HEADER / block->aspect) : rect->xmax;
@@ -588,11 +622,18 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
if (UI_GetThemeValue(TH_PANEL_SHOW_HEADER)) {
/* draw with background color */
- UI_ThemeColor4(TH_PANEL_HEADER);
- glRectf(minx, headrect.ymin + 1, maxx, y);
+ immUniformThemeColor(TH_PANEL_HEADER);
+ immRectf(pos, minx, headrect.ymin + 1, maxx, y);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, minx, y);
+ immVertex2f(pos, maxx, y);
+
+ immVertex2f(pos, minx, y);
+ immVertex2f(pos, maxx, y);
- fdrawline(minx, y, maxx, y);
- fdrawline(minx, y, maxx, y);
+ immEnd();
}
else if (!(panel->runtime_flag & PNL_FIRST)) {
/* draw embossed separator */
@@ -602,15 +643,26 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
maxx -= 5.0f / block->aspect;
}
- glColor4f(0.0f, 0.0f, 0.0f, 0.5f);
- fdrawline(minx, y, maxx, y);
- glColor4f(1.0f, 1.0f, 1.0f, 0.25f);
- fdrawline(minx, y - 1, maxx, y - 1);
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, minx, y);
+ immVertex2f(pos, maxx, y);
+ immEnd();
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.25f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, minx, y - 1);
+ immVertex2f(pos, maxx, y - 1);
+ immEnd();
}
glDisable(GL_BLEND);
}
+ immUnbindProgram();
+
/* draw optional pin icon */
#ifdef USE_PIN_HIDDEN
@@ -626,9 +678,14 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
glDisable(GL_BLEND);
}
+
/* horizontal title */
if (is_closed_x == false) {
+ unsigned int col;
ui_draw_aligned_panel_header(style, block, &headrect, 'h');
+ Gwn_VertFormat *format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
/* itemrect smaller */
itemrect.xmax = headrect.xmax - 5.0f / block->aspect;
@@ -637,7 +694,12 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
itemrect.ymax = headrect.ymax;
BLI_rctf_scale(&itemrect, 0.7f);
- ui_draw_panel_dragwidget(&itemrect);
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ ui_draw_panel_dragwidget(pos, col, &itemrect);
+ immUnbindProgram();
+
+ /* Restore format for the following draws. */
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
}
/* if the panel is minimized vertically:
@@ -649,6 +711,7 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
else if (is_closed_x) {
/* draw vertical title */
ui_draw_aligned_panel_header(style, block, &headrect, 'v');
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
}
/* an open panel */
else {
@@ -657,33 +720,37 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
if (panel->control & UI_PNL_SOLID) UI_draw_roundbox_corner_set(UI_CNR_ALL);
else UI_draw_roundbox_corner_set(UI_CNR_NONE);
- UI_ThemeColorShade(TH_BACK, -120);
- UI_draw_roundbox_unfilled(0.5f + rect->xmin, 0.5f + rect->ymin, 0.5f + rect->xmax, 0.5f + headrect.ymax + 1, 8);
+ UI_GetThemeColorShade4fv(TH_BACK, -120, color);
+ UI_draw_roundbox_aa(false, 0.5f + rect->xmin, 0.5f + rect->ymin, 0.5f + rect->xmax, 0.5f + headrect.ymax + 1, 8, color);
}
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* panel backdrop */
if (UI_GetThemeValue(TH_PANEL_SHOW_BACK)) {
/* draw with background color */
glEnable(GL_BLEND);
- UI_ThemeColor4(TH_PANEL_BACK);
- glRecti(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+ immUniformThemeColor(TH_PANEL_BACK);
+ immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
}
if (panel->control & UI_PNL_SCALE)
- ui_draw_panel_scalewidget(rect);
+ ui_draw_panel_scalewidget(pos, rect);
+
+ immUnbindProgram();
}
/* draw optional close icon */
- ofsx = 6;
if (panel->control & UI_PNL_CLOSE) {
- UI_ThemeColor(TH_TITLE);
- ui_draw_x_icon(rect->xmin + 2 + ofsx, rect->ymax + 2);
- ofsx = 22;
+ const int ofsx = 6;
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor3(TH_TITLE);
+ ui_draw_x_icon(pos, rect->xmin + 2 + ofsx, rect->ymax + 2);
+ immUnbindProgram();
}
/* draw collapse icon */
- UI_ThemeColor(TH_TITLE);
/* itemrect smaller */
itemrect.xmin = headrect.xmin + 5.0f / block->aspect;
@@ -699,8 +766,6 @@ void ui_draw_aligned_panel(uiStyle *style, uiBlock *block, const rcti *rect, con
ui_draw_tria_rect(&itemrect, 'h');
else
ui_draw_tria_rect(&itemrect, 'v');
-
- (void)ofsx;
}
/************************** panel alignment *************************/
@@ -1513,12 +1578,13 @@ void UI_panel_category_clear_all(ARegion *ar)
BLI_freelistN(&ar->panels_category);
}
-/* based on UI_draw_roundbox_gl_mode, check on making a version which allows us to skip some sides */
+/* based on UI_draw_roundbox, check on making a version which allows us to skip some sides */
static void ui_panel_category_draw_tab(
- int mode, float minx, float miny, float maxx, float maxy, float rad,
+ bool filled, float minx, float miny, float maxx, float maxy, float rad,
int roundboxtype,
- const bool use_highlight, const bool use_shadow,
- const unsigned char highlight_fade[3])
+ bool use_highlight, bool use_shadow,
+ const unsigned char highlight_fade[3],
+ const unsigned char col[3])
{
float vec[4][2] = {
{0.195, 0.02},
@@ -1527,74 +1593,113 @@ static void ui_panel_category_draw_tab(
{0.98, 0.805}};
int a;
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
/* mult */
for (a = 0; a < 4; a++) {
mul_v2_fl(vec[a], rad);
}
- glBegin(mode);
+ unsigned int vert_ct = 0;
+ if (use_highlight) {
+ vert_ct += (roundboxtype & UI_CNR_TOP_RIGHT) ? 6 : 1;
+ vert_ct += (roundboxtype & UI_CNR_TOP_LEFT) ? 6 : 1;
+ }
+ if (use_highlight && !use_shadow) {
+ vert_ct++;
+ }
+ else {
+ vert_ct += (roundboxtype & UI_CNR_BOTTOM_RIGHT) ? 6 : 1;
+ vert_ct += (roundboxtype & UI_CNR_BOTTOM_LEFT) ? 6 : 1;
+ }
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+
+ immBegin(filled ? GWN_PRIM_TRI_FAN : GWN_PRIM_LINE_STRIP, vert_ct);
/* start with corner right-top */
if (use_highlight) {
if (roundboxtype & UI_CNR_TOP_RIGHT) {
- glVertex2f(maxx, maxy - rad);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx, maxy - rad);
for (a = 0; a < 4; a++) {
- glVertex2f(maxx - vec[a][1], maxy - rad + vec[a][0]);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx - vec[a][1], maxy - rad + vec[a][0]);
}
- glVertex2f(maxx - rad, maxy);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx - rad, maxy);
}
else {
- glVertex2f(maxx, maxy);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx, maxy);
}
/* corner left-top */
if (roundboxtype & UI_CNR_TOP_LEFT) {
- glVertex2f(minx + rad, maxy);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx + rad, maxy);
for (a = 0; a < 4; a++) {
- glVertex2f(minx + rad - vec[a][0], maxy - vec[a][1]);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx + rad - vec[a][0], maxy - vec[a][1]);
}
- glVertex2f(minx, maxy - rad);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx, maxy - rad);
}
else {
- glVertex2f(minx, maxy);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx, maxy);
}
}
if (use_highlight && !use_shadow) {
if (highlight_fade) {
- glColor3ubv(highlight_fade);
+ immAttrib3ubv(color, highlight_fade);
+ }
+ else {
+ immAttrib3ubv(color, col);
}
- glVertex2f(minx, miny + rad);
- glEnd();
+ immVertex2f(pos, minx, miny + rad);
+ immEnd();
+ immUnbindProgram();
return;
}
/* corner left-bottom */
if (roundboxtype & UI_CNR_BOTTOM_LEFT) {
- glVertex2f(minx, miny + rad);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx, miny + rad);
for (a = 0; a < 4; a++) {
- glVertex2f(minx + vec[a][1], miny + rad - vec[a][0]);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx + vec[a][1], miny + rad - vec[a][0]);
}
- glVertex2f(minx + rad, miny);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx + rad, miny);
}
else {
- glVertex2f(minx, miny);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, minx, miny);
}
/* corner right-bottom */
-
if (roundboxtype & UI_CNR_BOTTOM_RIGHT) {
- glVertex2f(maxx - rad, miny);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx - rad, miny);
for (a = 0; a < 4; a++) {
- glVertex2f(maxx - rad + vec[a][0], miny + vec[a][1]);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx - rad + vec[a][0], miny + vec[a][1]);
}
- glVertex2f(maxx, miny + rad);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx, miny + rad);
}
else {
- glVertex2f(maxx, miny);
+ immAttrib3ubv(color, col);
+ immVertex2f(pos, maxx, miny);
}
- glEnd();
+ immEnd();
+ immUnbindProgram();
}
@@ -1717,21 +1822,26 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active)
/* begin drawing */
glEnable(GL_LINE_SMOOTH);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* draw the background */
if (is_alpha) {
glEnable(GL_BLEND);
- glColor4ubv(theme_col_tab_bg);
+ immUniformColor4ubv(theme_col_tab_bg);
}
else {
- glColor3ubv(theme_col_tab_bg);
+ immUniformColor3ubv(theme_col_tab_bg);
}
- glRecti(v2d->mask.xmin, v2d->mask.ymin, v2d->mask.xmin + category_tabs_width, v2d->mask.ymax);
+ immRecti(pos, v2d->mask.xmin, v2d->mask.ymin, v2d->mask.xmin + category_tabs_width, v2d->mask.ymax);
if (is_alpha) {
glDisable(GL_BLEND);
}
+ immUnbindProgram();
+
for (pc_dyn = ar->panels_category.first; pc_dyn; pc_dyn = pc_dyn->next) {
const rcti *rct = &pc_dyn->rect;
const char *category_id = pc_dyn->idname;
@@ -1754,28 +1864,33 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active)
if (is_active)
#endif
{
- glColor3ubv(is_active ? theme_col_tab_active : theme_col_tab_inactive);
- ui_panel_category_draw_tab(GL_POLYGON, rct->xmin, rct->ymin, rct->xmax, rct->ymax,
- tab_curve_radius - px, roundboxtype, true, true, NULL);
+ ui_panel_category_draw_tab(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax,
+ tab_curve_radius - px, roundboxtype, true, true, NULL,
+ is_active ? theme_col_tab_active : theme_col_tab_inactive);
/* tab outline */
- glColor3ubv(theme_col_tab_outline);
- ui_panel_category_draw_tab(GL_LINE_STRIP, rct->xmin - px, rct->ymin - px, rct->xmax - px, rct->ymax + px,
- tab_curve_radius, roundboxtype, true, true, NULL);
+ ui_panel_category_draw_tab(false, rct->xmin - px, rct->ymin - px, rct->xmax - px, rct->ymax + px,
+ tab_curve_radius, roundboxtype, true, true, NULL, theme_col_tab_outline);
+
/* tab highlight (3d look) */
- glColor3ubv(is_active ? theme_col_tab_highlight : theme_col_tab_highlight_inactive);
- ui_panel_category_draw_tab(GL_LINE_STRIP, rct->xmin, rct->ymin, rct->xmax, rct->ymax,
+ ui_panel_category_draw_tab(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax,
tab_curve_radius, roundboxtype, true, false,
- is_active ? theme_col_back : theme_col_tab_inactive);
+ is_active ? theme_col_back : theme_col_tab_inactive,
+ is_active ? theme_col_tab_highlight : theme_col_tab_highlight_inactive);
}
/* tab blackline */
if (!is_active) {
- glColor3ubv(theme_col_tab_divider);
- glRecti(v2d->mask.xmin + category_tabs_width - px,
- rct->ymin - tab_v_pad,
- v2d->mask.xmin + category_tabs_width,
- rct->ymax + tab_v_pad);
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor3ubv(theme_col_tab_divider);
+ immRecti(pos, v2d->mask.xmin + category_tabs_width - px,
+ rct->ymin - tab_v_pad,
+ v2d->mask.xmin + category_tabs_width,
+ rct->ymax + tab_v_pad);
+
+ immUnbindProgram();
}
if (do_scaletabs) {
@@ -1788,7 +1903,7 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active)
/* tab titles */
/* draw white shadow to give text more depth */
- glColor3ubv(theme_col_text);
+ BLF_color3ubv(fontid, theme_col_text);
/* main tab title */
BLF_draw(fontid, category_id_draw, category_draw_len);
@@ -1796,33 +1911,36 @@ void UI_panel_category_draw_all(ARegion *ar, const char *category_id_active)
glDisable(GL_BLEND);
/* tab blackline remaining (last tab) */
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
if (pc_dyn->prev == NULL) {
- glColor3ubv(theme_col_tab_divider);
- glRecti(v2d->mask.xmin + category_tabs_width - px,
- rct->ymax + px,
- v2d->mask.xmin + category_tabs_width,
- v2d->mask.ymax);
+ immUniformColor3ubv(theme_col_tab_divider);
+ immRecti(pos, v2d->mask.xmin + category_tabs_width - px,
+ rct->ymax + px,
+ v2d->mask.xmin + category_tabs_width,
+ v2d->mask.ymax);
}
if (pc_dyn->next == NULL) {
- glColor3ubv(theme_col_tab_divider);
- glRecti(v2d->mask.xmin + category_tabs_width - px,
- 0,
- v2d->mask.xmin + category_tabs_width,
- rct->ymin);
+ immUniformColor3ubv(theme_col_tab_divider);
+ immRecti(pos, v2d->mask.xmin + category_tabs_width - px,
+ 0,
+ v2d->mask.xmin + category_tabs_width,
+ rct->ymin);
}
#ifdef USE_FLAT_INACTIVE
/* draw line between inactive tabs */
if (is_active == false && is_active_prev == false && pc_dyn->prev) {
- glColor3ubv(theme_col_tab_divider);
- glRecti(v2d->mask.xmin + (category_tabs_width / 5),
- rct->ymax + px,
- (v2d->mask.xmin + category_tabs_width) - (category_tabs_width / 5),
- rct->ymax + (px * 3));
+ immUniformColor3ubv(theme_col_tab_divider);
+ immRecti(pos, v2d->mask.xmin + (category_tabs_width / 5),
+ rct->ymax + px,
+ (v2d->mask.xmin + category_tabs_width) - (category_tabs_width / 5),
+ rct->ymax + (px * 3));
}
is_active_prev = is_active;
#endif
+ immUnbindProgram();
/* not essential, but allows events to be handled right up until the region edge [#38171] */
pc_dyn->rect.xmin = v2d->mask.xmin;
@@ -1899,6 +2017,11 @@ int ui_handler_panel_region(bContext *C, const wmEvent *event, ARegion *ar, cons
retval = WM_UI_HANDLER_CONTINUE;
+ /* Scrollbars can overlap panels now, they have handling priority. */
+ if (UI_view2d_mouse_in_scrollers(ar, &ar->v2d, event->x, event->y)) {
+ return retval;
+ }
+
/* handle category tabs */
if (has_category_tabs) {
if (event->val == KM_PRESS) {
diff --git a/source/blender/editors/interface/interface_region_menu_pie.c b/source/blender/editors/interface/interface_region_menu_pie.c
index 37a603d967f..0c43b787a84 100644
--- a/source/blender/editors/interface/interface_region_menu_pie.c
+++ b/source/blender/editors/interface/interface_region_menu_pie.c
@@ -76,7 +76,7 @@ static uiBlock *ui_block_func_PIE(bContext *UNUSED(C), uiPopupBlockHandle *handl
uiPieMenu *pie = arg_pie;
int minwidth, width, height;
- minwidth = 50;
+ minwidth = UI_MENU_WIDTH_MIN;
block = pie->block_radial;
/* in some cases we create the block before the region,
@@ -194,7 +194,6 @@ void UI_pie_menu_end(bContext *C, uiPieMenu *pie)
menu, WM_HANDLER_ACCEPT_DBL_CLICK);
WM_event_add_mousemove(C);
- menu->can_refresh = false;
MEM_freeN(pie);
}
diff --git a/source/blender/editors/interface/interface_region_menu_popup.c b/source/blender/editors/interface/interface_region_menu_popup.c
index 9aec955413f..a6046e551c6 100644
--- a/source/blender/editors/interface/interface_region_menu_popup.c
+++ b/source/blender/editors/interface/interface_region_menu_popup.c
@@ -191,7 +191,13 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
if (pup->but) {
/* minimum width to enforece */
- minwidth = BLI_rctf_size_x(&pup->but->rect);
+ if (pup->but->drawstr[0]) {
+ minwidth = BLI_rctf_size_x(&pup->but->rect);
+ }
+ else {
+ /* For buttons with no text, use the minimum (typically icon only). */
+ minwidth = UI_MENU_WIDTH_MIN;
+ }
/* settings (typically rna-enum-popups) show above the button,
* menu's like file-menu, show below */
@@ -209,7 +215,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
}
}
else {
- minwidth = 50;
+ minwidth = UI_MENU_WIDTH_MIN;
direction = UI_DIR_DOWN;
}
@@ -284,7 +290,7 @@ static uiBlock *ui_block_func_POPUP(bContext *C, uiPopupBlockHandle *handle, voi
/* for a header menu we set the direction automatic */
if (!pup->slideout && flip) {
ScrArea *sa = CTX_wm_area(C);
- if (sa && sa->headertype == HEADERDOWN) {
+ if (sa && ED_area_header_alignment(sa) == RGN_ALIGN_BOTTOM) {
ARegion *ar = CTX_wm_region(C);
if (ar && ar->regiontype == RGN_TYPE_HEADER) {
UI_block_direction_set(block, UI_DIR_UP);
@@ -359,7 +365,6 @@ uiPopupBlockHandle *ui_popup_menu_create(
WM_event_add_mousemove(C);
}
- handle->can_refresh = false;
MEM_freeN(pup);
return handle;
@@ -450,7 +455,6 @@ void UI_popup_menu_end(bContext *C, uiPopupMenu *pup)
UI_popup_handlers_add(C, &window->modalhandlers, menu, 0);
WM_event_add_mousemove(C);
- menu->can_refresh = false;
MEM_freeN(pup);
}
@@ -554,6 +558,7 @@ void UI_popup_block_invoke_ex(bContext *C, uiBlockCreateFunc func, void *arg, co
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg);
handle->popup = true;
+ handle->can_refresh = true;
handle->optype = (opname) ? WM_operatortype_find(opname, 0) : NULL;
handle->opcontext = opcontext;
@@ -576,6 +581,7 @@ void UI_popup_block_ex(
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, arg);
handle->popup = true;
handle->retvalue = 1;
+ handle->can_refresh = true;
handle->popup_op = op;
handle->popup_arg = arg;
@@ -596,6 +602,7 @@ void uiPupBlockOperator(bContext *C, uiBlockCreateFunc func, wmOperator *op, int
handle = ui_popup_block_create(C, NULL, NULL, func, NULL, op);
handle->popup = 1;
handle->retvalue = 1;
+ handle->can_refresh = true;
handle->popup_arg = op;
handle->popup_func = operator_cb;
@@ -612,11 +619,13 @@ void UI_popup_block_close(bContext *C, wmWindow *win, uiBlock *block)
/* if loading new .blend while popup is open, window will be NULL */
if (block->handle) {
if (win) {
+ const bScreen *screen = WM_window_get_active_screen(win);
+
UI_popup_handlers_remove(&win->modalhandlers, block->handle);
ui_popup_block_free(C, block->handle);
/* In the case we have nested popups, closing one may need to redraw another, see: T48874 */
- for (ARegion *ar = win->screen->regionbase.first; ar; ar = ar->next) {
+ for (ARegion *ar = screen->regionbase.first; ar; ar = ar->next) {
ED_region_tag_refresh_ui(ar);
}
}
diff --git a/source/blender/editors/interface/interface_region_popover.c b/source/blender/editors/interface/interface_region_popover.c
new file mode 100644
index 00000000000..219a4fc8ed5
--- /dev/null
+++ b/source/blender/editors/interface/interface_region_popover.c
@@ -0,0 +1,264 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/interface/interface_region_popover.c
+ * \ingroup edinterface
+ *
+ * Pop-Over Region
+ *
+ * \note This is very close to 'interface_region_menu_popup.c'
+ *
+ * We could even merge them, however menu logic is already over-loaded.
+ * PopOver's have the following differences.
+ *
+ * - UI is not constrained to a list.
+ * - Pressing a button won't close the pop-over.
+ * - Different draw style (to show this is has different behavior from a menu).
+ * - #PanelType are used instead of #MenuType.
+ * - No menu flipping support.
+ * - No moving the menu to fit the mouse cursor.
+ * - No key accelerators to access menu items
+ * (if we add support they would work differently).
+ * - No arrow key navigation.
+ * - No menu memory.
+ * - No title.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "DNA_userdef_types.h"
+
+#include "BLI_listbase.h"
+
+#include "BLI_rect.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+
+#include "ED_screen.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+
+#include "UI_interface.h"
+
+#include "interface_intern.h"
+#include "interface_regions_intern.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Popup Menu with Callback or String
+ * \{ */
+
+struct uiPopover {
+ uiBlock *block;
+ uiLayout *layout;
+ uiBut *but;
+
+ uiMenuCreateFunc menu_func;
+ void *menu_arg;
+};
+
+static void ui_popover_create_block(bContext *C, uiPopover *pup, int opcontext)
+{
+ uiStyle *style = UI_style_get_dpi();
+
+ pup->block = UI_block_begin(C, NULL, __func__, UI_EMBOSS);
+ pup->layout = UI_block_layout(
+ pup->block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0,
+ U.widget_unit * UI_POPOVER_WIDTH_UNITS, 0, MENU_PADDING, style);
+
+ uiLayoutSetOperatorContext(pup->layout, opcontext);
+
+ if (pup->but) {
+ if (pup->but->context) {
+ uiLayoutContextCopy(pup->layout, pup->but->context);
+ }
+ }
+
+ pup->block->flag |= UI_BLOCK_NO_FLIP;
+}
+
+static uiBlock *ui_block_func_POPOVER(bContext *C, uiPopupBlockHandle *handle, void *arg_pup)
+{
+ uiPopover *pup = arg_pup;
+
+ /* Create UI block and layout now if it wasn't done between begin/end. */
+ if (!pup->layout) {
+ ui_popover_create_block(C, pup, WM_OP_INVOKE_REGION_WIN);
+
+ if (pup->menu_func) {
+ pup->block->handle = handle;
+ pup->menu_func(C, pup->layout, pup->menu_arg);
+ pup->block->handle = NULL;
+ }
+
+ pup->layout = NULL;
+ }
+
+ /* Setup and resolve UI layout for block. */
+ uiBlock *block = pup->block;
+ int width, height;
+
+ UI_block_region_set(block, handle->region);
+ UI_block_layout_resolve(block, &width, &height);
+ UI_block_flag_enable(block, UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_KEEP_OPEN | UI_BLOCK_POPOVER);
+ UI_block_direction_set(block, UI_DIR_DOWN | UI_DIR_CENTER_X);
+
+ const int block_margin = U.widget_unit / 2;
+
+ if (pup->but) {
+ /* For a header menu we set the direction automatic. */
+ block->minbounds = BLI_rctf_size_x(&pup->but->rect);
+ UI_block_bounds_set_normal(block, block_margin);
+
+ /* If menu slides out of other menu, override direction. */
+ bool slideout = false; //ui_block_is_menu(pup->but->block);
+ if (slideout)
+ UI_block_direction_set(block, UI_DIR_RIGHT);
+
+ /* Store the button location for positioning the popover arrow hint. */
+ if (!handle->refresh) {
+ float center[2] = {BLI_rctf_cent_x(&pup->but->rect), BLI_rctf_cent_y(&pup->but->rect)};
+ ui_block_to_window_fl(handle->ctx_region, pup->but->block, &center[0], &center[1]);
+ /* These variables aren't used for popovers, we could add new variables if there is a conflict. */
+ handle->prev_mx = block->mx = (int)center[0];
+ handle->prev_my = block->my = (int)center[1];
+ }
+ else {
+ block->mx = handle->prev_mx;
+ block->my = handle->prev_my;
+ }
+
+ /* Prefer popover from header to be positioned into the editor. */
+ if (!slideout) {
+ ScrArea *sa = CTX_wm_area(C);
+ if (sa && ED_area_header_alignment(sa) == RGN_ALIGN_BOTTOM) {
+ ARegion *ar = CTX_wm_region(C);
+ if (ar && ar->regiontype == RGN_TYPE_HEADER) {
+ UI_block_direction_set(block, UI_DIR_UP | UI_DIR_CENTER_X);
+ }
+ }
+ }
+
+ /* Estimated a maximum size so we don't go offscreen for low height
+ * areas near the bottom of the window on refreshes. */
+ handle->max_size_y = UI_UNIT_Y * 16.0f;
+ }
+ else {
+ /* Not attached to a button. */
+ int offset[2] = {0, 0}; /* Dummy. */
+ UI_block_flag_enable(block, UI_BLOCK_LOOP);
+ UI_block_direction_set(block, block->direction);
+ block->minbounds = UI_MENU_WIDTH_MIN;
+ UI_block_bounds_set_popup(block, block_margin, offset[0], offset[1]);
+ }
+
+ return block;
+}
+
+static void ui_block_free_func_POPOVER(uiPopupBlockHandle *UNUSED(handle), void *arg_pup)
+{
+ uiPopover *pup = arg_pup;
+ MEM_freeN(pup);
+}
+
+uiPopupBlockHandle *ui_popover_panel_create(
+ bContext *C, ARegion *butregion, uiBut *but,
+ uiMenuCreateFunc menu_func, void *arg)
+{
+ /* Create popover, buttons are created from callback. */
+ uiPopover *pup = MEM_callocN(sizeof(uiPopover), __func__);
+ pup->but = but;
+ pup->menu_func = menu_func;
+ pup->menu_arg = arg;
+
+ /* Create popup block. */
+ uiPopupBlockHandle *handle;
+ handle = ui_popup_block_create(C, butregion, but, NULL, ui_block_func_POPOVER, pup);
+ handle->popup_create_vars.free_func = ui_block_free_func_POPOVER;
+ handle->can_refresh = true;
+
+ /* Add handlers. If attached to a button, the button will already
+ * add a modal handler and pass on events. */
+ if (!but) {
+ wmWindow *window = CTX_wm_window(C);
+ UI_popup_handlers_add(C, &window->modalhandlers, handle, 0);
+ WM_event_add_mousemove(C);
+ handle->popup = true;
+ }
+
+ return handle;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Popup Menu API with begin & end
+ * \{ */
+
+/**
+ * Only return handler, and set optional title.
+ */
+uiPopover *UI_popover_begin(bContext *C)
+{
+ uiPopover *pup = MEM_callocN(sizeof(uiPopover), "popover menu");
+
+ /* Opertor context default same as menus, change if needed. */
+ ui_popover_create_block(C, pup, WM_OP_EXEC_REGION_WIN);
+
+ /* create in advance so we can let buttons point to retval already */
+ pup->block->handle = MEM_callocN(sizeof(uiPopupBlockHandle), "uiPopupBlockHandle");
+
+ return pup;
+}
+
+/* set the whole structure to work */
+void UI_popover_end(bContext *C, uiPopover *pup)
+{
+ /* Create popup block. No refresh support since the buttons were created
+ * between begin/end and we have no callback to recreate them. */
+ uiPopupBlockHandle *handle;
+
+ handle = ui_popup_block_create(C, NULL, NULL, NULL, ui_block_func_POPOVER, pup);
+ handle->popup_create_vars.free_func = ui_block_free_func_POPOVER;
+
+ /* Add handlers. */
+ wmWindow *window = CTX_wm_window(C);
+ UI_popup_handlers_add(C, &window->modalhandlers, handle, 0);
+ WM_event_add_mousemove(C);
+ handle->popup = true;
+}
+
+uiLayout *UI_popover_layout(uiPopover *pup)
+{
+ return pup->layout;
+}
+
+/** \} */
+
+/* We may want to support this in future */
+/* Similar to UI_popup_menu_invoke */
+// int UI_popover_panel_invoke(bContext *C, const char *idname, ReportList *reports);
diff --git a/source/blender/editors/interface/interface_region_popup.c b/source/blender/editors/interface/interface_region_popup.c
index 656c59055af..e971edb95cb 100644
--- a/source/blender/editors/interface/interface_region_popup.c
+++ b/source/blender/editors/interface/interface_region_popup.c
@@ -48,7 +48,6 @@
#include "WM_api.h"
#include "WM_types.h"
-#include "wm_subwindow.h"
#include "UI_interface.h"
@@ -85,32 +84,38 @@ void ui_popup_translate(bContext *C, ARegion *ar, const int mdiff[2])
}
/* position block relative to but, result is in window space */
-static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block)
+static void ui_popup_block_position(wmWindow *window, ARegion *butregion, uiBut *but, uiBlock *block)
{
- uiBut *bt;
- uiSafetyRct *saferct;
+ uiPopupBlockHandle *handle = block->handle;
+
+ /* Compute button position in window coordinates using the source
+ * button region/block, to position the popup attached to it. */
rctf butrct;
- /*float aspect;*/ /*UNUSED*/
- int size_x, size_y, offset_x = 0, offset_y = 0;
- short dir1 = 0, dir2 = 0;
- /* transform to window coordinates, using the source button region/block */
- ui_block_to_window_rctf(butregion, but->block, &butrct, &but->rect);
+ if (!handle->refresh) {
+ ui_block_to_window_rctf(butregion, but->block, &butrct, &but->rect);
- /* widget_roundbox_set has this correction too, keep in sync */
- if (but->type != UI_BTYPE_PULLDOWN) {
- if (but->drawflag & UI_BUT_ALIGN_TOP)
- butrct.ymax += U.pixelsize;
- if (but->drawflag & UI_BUT_ALIGN_LEFT)
- butrct.xmin -= U.pixelsize;
+ /* widget_roundbox_set has this correction too, keep in sync */
+ if (but->type != UI_BTYPE_PULLDOWN) {
+ if (but->drawflag & UI_BUT_ALIGN_TOP)
+ butrct.ymax += U.pixelsize;
+ if (but->drawflag & UI_BUT_ALIGN_LEFT)
+ butrct.xmin -= U.pixelsize;
+ }
+
+ handle->prev_butrct = butrct;
+ }
+ else {
+ /* For refreshes, keep same button position so popup doesn't move. */
+ butrct = handle->prev_butrct;
}
- /* calc block rect */
+ /* Compute block size in window space, based on buttons contained in it. */
if (block->rect.xmin == 0.0f && block->rect.xmax == 0.0f) {
if (block->buttons.first) {
BLI_rctf_init_minmax(&block->rect);
- for (bt = block->buttons.first; bt; bt = bt->next) {
+ for (uiBut *bt = block->buttons.first; bt; bt = bt->next) {
BLI_rctf_union(&block->rect, &bt->rect);
}
}
@@ -121,34 +126,34 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
}
}
- /* aspect = (float)(BLI_rcti_size_x(&block->rect) + 4);*/ /*UNUSED*/
ui_block_to_window_rctf(butregion, but->block, &block->rect, &block->rect);
- //block->rect.xmin -= 2.0; block->rect.ymin -= 2.0;
- //block->rect.xmax += 2.0; block->rect.ymax += 2.0;
+ /* Compute direction relative to button, based on available space. */
+ const int size_x = BLI_rctf_size_x(&block->rect) + 0.2f * UI_UNIT_X; /* 4 for shadow */
+ const int size_y = BLI_rctf_size_y(&block->rect) + 0.2f * UI_UNIT_Y;
+ const int center_x = (block->direction & UI_DIR_CENTER_X) ? size_x / 2 : 0;
+ const int center_y = (block->direction & UI_DIR_CENTER_Y) ? size_y / 2 : 0;
- size_x = BLI_rctf_size_x(&block->rect) + 0.2f * UI_UNIT_X; /* 4 for shadow */
- size_y = BLI_rctf_size_y(&block->rect) + 0.2f * UI_UNIT_Y;
- /* aspect /= (float)size_x;*/ /*UNUSED*/
+ short dir1 = 0, dir2 = 0;
- {
+ if (!handle->refresh) {
bool left = 0, right = 0, top = 0, down = 0;
- // int offscreen;
const int win_x = WM_window_pixels_x(window);
const int win_y = WM_window_pixels_y(window);
- // wm_window_get_size(window, &win_x, &win_y);
- const int center_y = (block->direction & UI_DIR_CENTER_Y) ? size_y / 2 : 0;
+ /* Take into account maximum size so we don't have to flip on refresh. */
+ const float max_size_x = max_ff(size_x, handle->max_size_x);
+ const float max_size_y = max_ff(size_y, handle->max_size_y);
/* check if there's space at all */
- if (butrct.xmin - size_x > 0.0f) left = 1;
- if (butrct.xmax + size_x < win_x) right = 1;
- if (butrct.ymin - size_y + center_y > 0.0f) down = 1;
- if (butrct.ymax + size_y - center_y < win_y) top = 1;
+ if (butrct.xmin - max_size_x + center_x > 0.0f) left = 1;
+ if (butrct.xmax + max_size_x - center_x < win_x) right = 1;
+ if (butrct.ymin - max_size_y + center_y > 0.0f) down = 1;
+ if (butrct.ymax + max_size_y - center_y < win_y) top = 1;
if (top == 0 && down == 0) {
- if (butrct.ymin - size_y < win_y - butrct.ymax - size_y)
+ if (butrct.ymin - max_size_y < win_y - butrct.ymax - max_size_y)
top = 1;
else
down = 1;
@@ -182,65 +187,57 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
if (dir2 == UI_DIR_DOWN && down == 0) dir2 = UI_DIR_UP;
}
- if (dir1 == UI_DIR_LEFT) {
- offset_x = butrct.xmin - block->rect.xmax;
- if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - MENU_PADDING;
- else offset_y = butrct.ymax - block->rect.ymax + center_y + MENU_PADDING;
- }
- else if (dir1 == UI_DIR_RIGHT) {
- offset_x = butrct.xmax - block->rect.xmin;
- if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - MENU_PADDING;
- else offset_y = butrct.ymax - block->rect.ymax + center_y + MENU_PADDING;
- }
- else if (dir1 == UI_DIR_UP) {
- offset_y = butrct.ymax - block->rect.ymin;
- if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax;
- else offset_x = butrct.xmin - block->rect.xmin;
- /* changed direction? */
- if ((dir1 & block->direction) == 0) {
- UI_block_order_flip(block);
- }
- }
- else if (dir1 == UI_DIR_DOWN) {
- offset_y = butrct.ymin - block->rect.ymax;
- if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax;
- else offset_x = butrct.xmin - block->rect.xmin;
- /* changed direction? */
- if ((dir1 & block->direction) == 0) {
- UI_block_order_flip(block);
- }
- }
+ handle->prev_dir1 = dir1;
+ handle->prev_dir2 = dir2;
+ }
+ else {
+ /* For refreshes, keep same popup direct so popup doesn't move
+ * to a totally different position while editing in it. */
+ dir1 = handle->prev_dir1;
+ dir2 = handle->prev_dir2;
+ }
- /* and now we handle the exception; no space below or to top */
- if (top == 0 && down == 0) {
- if (dir1 == UI_DIR_LEFT || dir1 == UI_DIR_RIGHT) {
- /* align with bottom of screen */
- // offset_y = size_y; (not with menu scrolls)
- }
- }
+ /* Compute offset based on direction. */
+ int offset_x = 0, offset_y = 0;
-#if 0 /* seems redundant and causes issues with blocks inside big regions */
- /* or no space left or right */
- if (left == 0 && right == 0) {
- if (dir1 == UI_DIR_UP || dir1 == UI_DIR_DOWN) {
- /* align with left size of screen */
- offset_x = -block->rect.xmin + 5;
- }
+ if (dir1 == UI_DIR_LEFT) {
+ offset_x = butrct.xmin - block->rect.xmax;
+ if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - MENU_PADDING;
+ else offset_y = butrct.ymax - block->rect.ymax + center_y + MENU_PADDING;
+ }
+ else if (dir1 == UI_DIR_RIGHT) {
+ offset_x = butrct.xmax - block->rect.xmin;
+ if (dir2 == UI_DIR_UP) offset_y = butrct.ymin - block->rect.ymin - center_y - MENU_PADDING;
+ else offset_y = butrct.ymax - block->rect.ymax + center_y + MENU_PADDING;
+ }
+ else if (dir1 == UI_DIR_UP) {
+ offset_y = butrct.ymax - block->rect.ymin;
+ if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax + center_x;
+ else offset_x = butrct.xmin - block->rect.xmin - center_x;
+ /* changed direction? */
+ if ((dir1 & block->direction) == 0) {
+ /* TODO: still do */
+ UI_block_order_flip(block);
+ }
+ }
+ else if (dir1 == UI_DIR_DOWN) {
+ offset_y = butrct.ymin - block->rect.ymax;
+ if (dir2 == UI_DIR_RIGHT) offset_x = butrct.xmax - block->rect.xmax + center_x;
+ else offset_x = butrct.xmin - block->rect.xmin - center_x;
+ /* changed direction? */
+ if ((dir1 & block->direction) == 0) {
+ /* TODO: still do */
+ UI_block_order_flip(block);
}
-#endif
-
-#if 0
- /* clamp to window bounds, could be made into an option if its ever annoying */
- if ( (offscreen = (block->rect.ymin + offset_y)) < 0) offset_y -= offscreen; /* bottom */
- else if ((offscreen = (block->rect.ymax + offset_y) - winy) > 0) offset_y -= offscreen; /* top */
- if ( (offscreen = (block->rect.xmin + offset_x)) < 0) offset_x -= offscreen; /* left */
- else if ((offscreen = (block->rect.xmax + offset_x) - winx) > 0) offset_x -= offscreen; /* right */
-#endif
}
- /* apply offset, buttons in window coords */
+ /* Center over popovers for eg. */
+ if (block->direction & UI_DIR_CENTER_X) {
+ offset_x += BLI_rctf_size_x(&butrct) / ((dir2 == UI_DIR_LEFT) ? 2 : - 2);
+ }
- for (bt = block->buttons.first; bt; bt = bt->next) {
+ /* Apply offset, buttons in window coords. */
+ for (uiBut *bt = block->buttons.first; bt; bt = bt->next) {
ui_block_to_window_rctf(butregion, but->block, &bt->rect, &bt->rect);
BLI_rctf_translate(&bt->rect, offset_x, offset_y);
@@ -251,7 +248,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
BLI_rctf_translate(&block->rect, offset_x, offset_y);
- /* safety calculus */
+ /* Safety calculus. */
{
const float midx = BLI_rctf_cent_x(&butrct);
const float midy = BLI_rctf_cent_y(&butrct);
@@ -281,7 +278,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
}
/* keep a list of these, needed for pulldown menus */
- saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
+ uiSafetyRct *saferct = MEM_callocN(sizeof(uiSafetyRct), "uiSafetyRct");
saferct->parent = butrct;
saferct->safety = block->safety;
BLI_freelistN(&block->saferct);
@@ -295,7 +292,7 @@ static void ui_block_position(wmWindow *window, ARegion *butregion, uiBut *but,
/** \name Menu Block Creation
* \{ */
-static void ui_block_region_draw(const bContext *C, ARegion *ar)
+static void ui_block_region_refresh(const bContext *C, ARegion *ar)
{
ScrArea *ctx_area = CTX_wm_area(C);
ARegion *ctx_region = CTX_wm_region(C);
@@ -309,9 +306,11 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar)
ar->do_draw &= ~RGN_DRAW_REFRESH_UI;
for (block = ar->uiblocks.first; block; block = block_next) {
block_next = block->next;
- if (block->handle->can_refresh) {
- handle_ctx_area = block->handle->ctx_area;
- handle_ctx_region = block->handle->ctx_region;
+ uiPopupBlockHandle *handle = block->handle;
+
+ if (handle->can_refresh) {
+ handle_ctx_area = handle->ctx_area;
+ handle_ctx_region = handle->ctx_region;
if (handle_ctx_area) {
CTX_wm_area_set((bContext *)C, handle_ctx_area);
@@ -319,13 +318,21 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar)
if (handle_ctx_region) {
CTX_wm_region_set((bContext *)C, handle_ctx_region);
}
- ui_popup_block_refresh((bContext *)C, block->handle, NULL, NULL);
+
+ uiBut *but = handle->popup_create_vars.but;
+ ARegion *butregion = handle->popup_create_vars.butregion;
+ ui_popup_block_refresh((bContext *)C, handle, butregion, but);
}
}
}
CTX_wm_area_set((bContext *)C, ctx_area);
CTX_wm_region_set((bContext *)C, ctx_region);
+}
+
+static void ui_block_region_draw(const bContext *C, ARegion *ar)
+{
+ uiBlock *block;
for (block = ar->uiblocks.first; block; block = block->next)
UI_block_draw(C, block);
@@ -335,7 +342,7 @@ static void ui_block_region_draw(const bContext *C, ARegion *ar)
* Use to refresh centered popups on screen resizing (for splash).
*/
static void ui_block_region_popup_window_listener(
- bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn, const Scene *UNUSED(scene))
{
switch (wmn->category) {
case NC_WINDOW:
@@ -455,8 +462,6 @@ uiBlock *ui_popup_block_refresh(
bContext *C, uiPopupBlockHandle *handle,
ARegion *butregion, uiBut *but)
{
- BLI_assert(handle->can_refresh == true);
-
const int margin = UI_POPUP_MARGIN;
wmWindow *window = CTX_wm_window(C);
ARegion *ar = handle->region;
@@ -468,6 +473,10 @@ uiBlock *ui_popup_block_refresh(
uiBlock *block_old = ar->uiblocks.first;
uiBlock *block;
+ handle->refresh = (block_old != NULL);
+
+ BLI_assert(!handle->refresh || handle->can_refresh);
+
#ifdef DEBUG
wmEvent *event_back = window->eventstate;
#endif
@@ -513,7 +522,7 @@ uiBlock *ui_popup_block_refresh(
/* if this is being created from a button */
if (but) {
block->aspect = but->block->aspect;
- ui_block_position(window, butregion, but, block);
+ ui_popup_block_position(window, butregion, but, block);
handle->direction = block->direction;
}
else {
@@ -576,6 +585,17 @@ uiBlock *ui_popup_block_refresh(
else {
/* clip block with window boundary */
ui_popup_block_clip(window, block);
+
+ /* Avoid menu moving down and losing cursor focus by keeping it at
+ * the same height. */
+ if (handle->refresh && handle->prev_block_rect.ymax > block->rect.ymax) {
+ float offset = handle->prev_block_rect.ymax - block->rect.ymax;
+ ui_block_translate(block, 0, offset);
+ block->rect.ymin = handle->prev_block_rect.ymin;
+ }
+
+ handle->prev_block_rect = block->rect;
+
/* the block and buttons were positioned in window space as in 2.4x, now
* these menu blocks are regions so we bring it back to region space.
* additionally we add some padding for the menu shadow or rounded menus */
@@ -600,9 +620,7 @@ uiBlock *ui_popup_block_refresh(
ED_region_init(C, ar);
/* get winmat now that we actually have the subwindow */
- wmSubWindowSet(window, ar->swinid);
-
- wm_subwindow_matrix_get(window, ar->swinid, block->winmat);
+ wmGetProjectionMatrix(block->winmat, &ar->winrct);
/* notify change and redraw */
ED_region_tag_redraw(ar);
@@ -646,10 +664,12 @@ uiPopupBlockHandle *ui_popup_block_create(
handle->popup_create_vars.create_func = create_func;
handle->popup_create_vars.handle_create_func = handle_create_func;
handle->popup_create_vars.arg = arg;
+ handle->popup_create_vars.but = but;
handle->popup_create_vars.butregion = but ? butregion : NULL;
copy_v2_v2_int(handle->popup_create_vars.event_xy, &window->eventstate->x);
- /* caller may free vars used to create this popup, in that case this variable should be disabled. */
- handle->can_refresh = true;
+
+ /* don't allow by default, only if popup type explicitly supports it */
+ handle->can_refresh = false;
/* create area region */
ar = ui_region_temp_add(CTX_wm_screen(C));
@@ -657,6 +677,7 @@ uiPopupBlockHandle *ui_popup_block_create(
memset(&type, 0, sizeof(ARegionType));
type.draw = ui_block_region_draw;
+ type.layout = ui_block_region_refresh;
type.regionid = RGN_TYPE_TEMPORARY;
ar->type = &type;
@@ -666,7 +687,7 @@ uiPopupBlockHandle *ui_popup_block_create(
handle = block->handle;
/* keep centered on window resizing */
- if ((block->bounds_type == UI_BLOCK_BOUNDS_POPUP_CENTER) && handle->can_refresh) {
+ if (block->bounds_type == UI_BLOCK_BOUNDS_POPUP_CENTER) {
type.listener = ui_block_region_popup_window_listener;
}
@@ -675,6 +696,10 @@ uiPopupBlockHandle *ui_popup_block_create(
void ui_popup_block_free(bContext *C, uiPopupBlockHandle *handle)
{
+ if (handle->popup_create_vars.free_func) {
+ handle->popup_create_vars.free_func(handle, handle->popup_create_vars.arg);
+ }
+
ui_popup_block_remove(C, handle);
MEM_freeN(handle);
diff --git a/source/blender/editors/interface/interface_region_search.c b/source/blender/editors/interface/interface_region_search.c
index c9d313a4bab..f14f9af8785 100644
--- a/source/blender/editors/interface/interface_region_search.c
+++ b/source/blender/editors/interface/interface_region_search.c
@@ -397,7 +397,7 @@ int ui_searchbox_autocomplete(bContext *C, ARegion *ar, uiBut *but, char *str)
return match;
}
-static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
+static void ui_searchbox_region_draw_cb(const bContext *C, ARegion *ar)
{
uiSearchboxData *data = ar->regiondata;
@@ -415,6 +415,9 @@ static void ui_searchbox_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
if (data->preview) {
/* draw items */
for (a = 0; a < data->items.totitem; a++) {
+ /* ensure icon is up-to-date */
+ ui_icon_ensure_deferred(C, data->items.icons[a], data->preview);
+
ui_searchbox_butrect(&rect, data, a);
/* widget itself */
diff --git a/source/blender/editors/interface/interface_region_tooltip.c b/source/blender/editors/interface/interface_region_tooltip.c
index 1eec3737215..d016deb26cb 100644
--- a/source/blender/editors/interface/interface_region_tooltip.c
+++ b/source/blender/editors/interface/interface_region_tooltip.c
@@ -164,6 +164,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
uiWidgetColors *theme = ui_tooltip_get_theme();
rcti bbox = data->bbox;
float tip_colors[UI_TIP_LC_MAX][3];
+ unsigned char drawcol[4] = {0, 0, 0, 255}; /* to store color in while drawing (alpha is always 255) */
float *main_color = tip_colors[UI_TIP_LC_MAIN]; /* the color from the theme */
float *value_color = tip_colors[UI_TIP_LC_VALUE];
@@ -174,12 +175,7 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
float background_color[3];
float tone_bg;
- int i, multisample_enabled;
-
- /* disable AA, makes widgets too blurry */
- multisample_enabled = glIsEnabled(GL_MULTISAMPLE);
- if (multisample_enabled)
- glDisable(GL_MULTISAMPLE);
+ int i;
wmOrtho2_region_pixelspace(ar);
@@ -232,9 +228,9 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
fstyle_header.shadowalpha = 1.0f;
fstyle_header.word_wrap = true;
+ rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_MAIN]);
UI_fontstyle_set(&fstyle_header);
- glColor3fv(tip_colors[UI_TIP_LC_MAIN]);
- UI_fontstyle_draw(&fstyle_header, &bbox, field->text);
+ UI_fontstyle_draw(&fstyle_header, &bbox, field->text, drawcol);
fstyle_header.shadow = 0;
@@ -245,8 +241,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
bbox.xmin += xofs;
bbox.ymax -= yofs;
- glColor3fv(tip_colors[UI_TIP_LC_ACTIVE]);
- UI_fontstyle_draw(&fstyle_header, &bbox, field->text_suffix);
+ rgb_float_to_uchar(drawcol, tip_colors[UI_TIP_LC_ACTIVE]);
+ UI_fontstyle_draw(&fstyle_header, &bbox, field->text_suffix, drawcol);
/* undo offset */
bbox.xmin -= xofs;
@@ -261,8 +257,8 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
UI_fontstyle_set(&fstyle_mono);
/* XXX, needed because we dont have mono in 'U.uifonts' */
BLF_size(fstyle_mono.uifont_id, fstyle_mono.points * U.pixelsize, U.dpi);
- glColor3fv(tip_colors[field->format.color_id]);
- UI_fontstyle_draw(&fstyle_mono, &bbox, field->text);
+ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]);
+ UI_fontstyle_draw(&fstyle_mono, &bbox, field->text, drawcol);
}
else {
uiFontStyle fstyle_normal = data->fstyle;
@@ -270,9 +266,9 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
fstyle_normal.word_wrap = true;
/* draw remaining data */
+ rgb_float_to_uchar(drawcol, tip_colors[field->format.color_id]);
UI_fontstyle_set(&fstyle_normal);
- glColor3fv(tip_colors[field->format.color_id]);
- UI_fontstyle_draw(&fstyle_normal, &bbox, field->text);
+ UI_fontstyle_draw(&fstyle_normal, &bbox, field->text, drawcol);
}
bbox.ymax -= data->lineh * field->geom.lines;
@@ -284,9 +280,6 @@ static void ui_tooltip_region_draw_cb(const bContext *UNUSED(C), ARegion *ar)
BLF_disable(data->fstyle.uifont_id, BLF_WORD_WRAP);
BLF_disable(blf_mono_font, BLF_WORD_WRAP);
-
- if (multisample_enabled)
- glEnable(GL_MULTISAMPLE);
}
static void ui_tooltip_region_free_cb(ARegion *ar)
@@ -313,6 +306,63 @@ static void ui_tooltip_region_free_cb(ARegion *ar)
/** \name ToolTip Creation
* \{ */
+static uiTooltipData *ui_tooltip_data_from_keymap(bContext *C, wmKeyMap *keymap)
+{
+ char buf[512];
+
+ /* create tooltip data */
+ uiTooltipData *data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
+
+ for (wmKeyMapItem *kmi = keymap->items.first; kmi; kmi = kmi->next) {
+ wmOperatorType *ot = WM_operatortype_find(kmi->idname, true);
+ if (ot != NULL) {
+ /* Tip */
+ {
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_NORMAL,
+ .color_id = UI_TIP_LC_MAIN,
+ .is_pad = true,
+ });
+ field->text = BLI_strdup(ot->description[0] ? ot->description : ot->name);
+ }
+ /* Shortcut */
+ {
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_NORMAL,
+ .color_id = UI_TIP_LC_NORMAL,
+ });
+ bool found = false;
+ if (WM_keymap_item_to_string(kmi, false, buf, sizeof(buf))) {
+ found = true;
+ }
+ field->text = BLI_sprintfN(TIP_("Shortcut: %s"), found ? buf : "None");
+ }
+
+ /* Python */
+ {
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_NORMAL,
+ .color_id = UI_TIP_LC_PYTHON,
+ });
+ char *str = WM_operator_pystring_ex(C, NULL, false, false, ot, kmi->ptr);
+ WM_operator_pystring_abbreviate(str, 32);
+ field->text = BLI_sprintfN(TIP_("Python: %s"), str);
+ MEM_freeN(str);
+ }
+ }
+ }
+ if (data->fields_len == 0) {
+ MEM_freeN(data);
+ return NULL;
+ }
+ else {
+ return data;
+ }
+}
+
static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but)
{
uiStringInfo but_tip = {BUT_GET_TIP, NULL};
@@ -565,6 +615,112 @@ static uiTooltipData *ui_tooltip_data_from_button(bContext *C, uiBut *but)
}
}
+static uiTooltipData *ui_tooltip_data_from_manipulator(bContext *C, wmManipulator *mpr)
+{
+ uiTooltipData *data = MEM_callocN(sizeof(uiTooltipData), "uiTooltipData");
+
+ /* TODO(campbell): a way for manipulators to have their own descriptions (low priority). */
+
+ /* Operator Actions */
+ {
+ bool use_drag = mpr->drag_part != -1 && mpr->highlight_part != mpr->drag_part;
+
+ const struct {
+ int part;
+ const char *prefix;
+ } mpop_actions[] = {
+ {
+ .part = mpr->highlight_part,
+ .prefix = use_drag ? TIP_("Click") : NULL,
+ }, {
+ .part = use_drag ? mpr->drag_part : -1,
+ .prefix = use_drag ? TIP_("Drag") : NULL,
+ },
+ };
+
+ for (int i = 0; i < ARRAY_SIZE(mpop_actions); i++) {
+ wmManipulatorOpElem *mpop = (mpop_actions[i].part != -1) ? WM_manipulator_operator_get(mpr, mpop_actions[i].part) : NULL;
+ if (mpop != NULL) {
+ /* Description */
+ const char *info = RNA_struct_ui_description(mpop->type->srna);
+ if (!(info && info[0])) {
+ info = RNA_struct_ui_name(mpop->type->srna);
+ }
+
+ if (info && info[0]) {
+ char *text = NULL;
+ if (mpop_actions[i].prefix != NULL) {
+ text = BLI_sprintfN("%s: %s", mpop_actions[i].prefix, info);
+ }
+ else {
+ text = BLI_strdup(info);
+ }
+
+ if (text != NULL) {
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_HEADER,
+ .color_id = UI_TIP_LC_VALUE,
+ .is_pad = true,
+ });
+ field->text = text;
+ }
+ }
+
+ /* Shortcut */
+ {
+ bool found = false;
+ IDProperty *prop = mpop->ptr.data;
+ char buf[128];
+ if (WM_key_event_operator_string(
+ C, mpop->type->idname, WM_OP_INVOKE_DEFAULT, prop, true,
+ buf, ARRAY_SIZE(buf)))
+ {
+ found = true;
+ }
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_NORMAL,
+ .color_id = UI_TIP_LC_VALUE,
+ .is_pad = true,
+ });
+ field->text = BLI_sprintfN(TIP_("Shortcut: %s"), found ? buf : "None");
+ }
+ }
+ }
+ }
+
+ /* Property Actions */
+ if (mpr->type->target_property_defs_len) {
+ wmManipulatorProperty *mpr_prop_array = WM_manipulator_target_property_array(mpr);
+ for (int i = 0; i < mpr->type->target_property_defs_len; i++) {
+ /* TODO(campbell): function callback descriptions. */
+ wmManipulatorProperty *mpr_prop = &mpr_prop_array[i];
+ if (mpr_prop->prop != NULL) {
+ const char *info = RNA_property_ui_description(mpr_prop->prop);
+ if (info && info[0]) {
+ uiTooltipField *field = text_field_add(
+ data, &(uiTooltipFormat){
+ .style = UI_TIP_STYLE_NORMAL,
+ .color_id = UI_TIP_LC_VALUE,
+ .is_pad = true,
+ });
+ field->text = BLI_strdup(info);
+ }
+ }
+ }
+ }
+
+ if (data->fields_len == 0) {
+ MEM_freeN(data);
+ return NULL;
+ }
+ else {
+ return data;
+ }
+}
+
+
static ARegion *ui_tooltip_create_with_data(
bContext *C, uiTooltipData *data,
const float init_position[2],
@@ -738,6 +894,27 @@ ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *b
}
uiTooltipData *data = NULL;
+ /* custom tips for pre-defined operators */
+ if (but->optype) {
+ if (STREQ(but->optype->idname, "WM_OT_tool_set")) {
+ char keymap[64] = "";
+ RNA_string_get(but->opptr, "keymap", keymap);
+ if (keymap[0]) {
+ ScrArea *sa = CTX_wm_area(C);
+ /* It happens in rare cases, for tooltips originated from the toolbar.
+ * It is hard to reproduce, but it happens when the mouse is nowhere near the actual tool. */
+ if (sa == NULL) {
+ return NULL;
+ }
+ wmKeyMap *km = WM_keymap_find_all(C, keymap, sa->spacetype, RGN_TYPE_WINDOW);
+ if (km != NULL) {
+ data = ui_tooltip_data_from_keymap(C, km);
+ }
+ }
+ }
+ }
+ /* toolsystem exception */
+
if (data == NULL) {
data = ui_tooltip_data_from_button(C, but);
}
@@ -756,6 +933,23 @@ ARegion *UI_tooltip_create_from_button(bContext *C, ARegion *butregion, uiBut *b
return ui_tooltip_create_with_data(C, data, init_position, aspect);
}
+ARegion *UI_tooltip_create_from_manipulator(bContext *C, wmManipulator *mpr)
+{
+ wmWindow *win = CTX_wm_window(C);
+ const float aspect = 1.0f;
+ float init_position[2];
+
+ uiTooltipData *data = ui_tooltip_data_from_manipulator(C, mpr);
+ if (data == NULL) {
+ return NULL;
+ }
+
+ init_position[0] = win->eventstate->x;
+ init_position[1] = win->eventstate->y;
+
+ return ui_tooltip_create_with_data(C, data, init_position, aspect);
+}
+
void UI_tooltip_free(bContext *C, bScreen *sc, ARegion *ar)
{
ui_region_temp_remove(C, sc, ar);
diff --git a/source/blender/editors/interface/interface_regions.c b/source/blender/editors/interface/interface_regions.c
index dd1d38bbe2e..fa25a119ada 100644
--- a/source/blender/editors/interface/interface_regions.c
+++ b/source/blender/editors/interface/interface_regions.c
@@ -61,6 +61,9 @@ ARegion *ui_region_temp_add(bScreen *sc)
void ui_region_temp_remove(bContext *C, bScreen *sc, ARegion *ar)
{
wmWindow *win = CTX_wm_window(C);
+
+ BLI_assert(ar->regiontype == RGN_TYPE_TEMPORARY);
+ BLI_assert(BLI_findindex(&sc->regionbase, ar) != -1);
if (win)
wm_draw_region_clear(win, ar);
diff --git a/source/blender/editors/interface/interface_style.c b/source/blender/editors/interface/interface_style.c
index 8b41302b5bb..01456e2e122 100644
--- a/source/blender/editors/interface/interface_style.c
+++ b/source/blender/editors/interface/interface_style.c
@@ -149,7 +149,7 @@ static uiFont *uifont_to_blfont(int id)
void UI_fontstyle_draw_ex(
- const uiFontStyle *fs, const rcti *rect, const char *str,
+ const uiFontStyle *fs, const rcti *rect, const char *str, const unsigned char col[4],
size_t len, float *r_xofs, float *r_yofs)
{
int xofs = 0, yofs;
@@ -196,6 +196,7 @@ void UI_fontstyle_draw_ex(
/* clip is very strict, so we give it some space */
BLF_clipping(fs->uifont_id, rect->xmin - 2, rect->ymin - 4, rect->xmax + 1, rect->ymax + 4);
BLF_position(fs->uifont_id, rect->xmin + xofs, rect->ymin + yofs, 0.0f);
+ BLF_color4ubv(fs->uifont_id, col);
BLF_draw(fs->uifont_id, str, len);
@@ -205,17 +206,17 @@ void UI_fontstyle_draw_ex(
*r_yofs = yofs;
}
-void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str)
+void UI_fontstyle_draw(const uiFontStyle *fs, const rcti *rect, const char *str, const unsigned char col[4])
{
float xofs, yofs;
UI_fontstyle_draw_ex(
- fs, rect, str,
+ fs, rect, str, col,
BLF_DRAW_STR_DUMMY_MAX, &xofs, &yofs);
}
/* drawn same as above, but at 90 degree angle */
-void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const char *str)
+void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const char *str, const unsigned char col[4])
{
float height;
int xofs, yofs;
@@ -249,6 +250,7 @@ void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const ch
BLF_enable(fs->uifont_id, BLF_ROTATION);
BLF_rotation(fs->uifont_id, angle);
+ BLF_color4ubv(fs->uifont_id, col);
if (fs->shadow) {
BLF_enable(fs->uifont_id, BLF_SHADOW);
@@ -275,13 +277,14 @@ void UI_fontstyle_draw_rotated(const uiFontStyle *fs, const rcti *rect, const ch
*
* For drawing on-screen labels.
*/
-void UI_fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str)
+void UI_fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const char *str, const unsigned char col[4])
{
if (fs->kerning == 1)
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
UI_fontstyle_set(fs);
BLF_position(fs->uifont_id, x, y, 0.0f);
+ BLF_color4ubv(fs->uifont_id, col);
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
if (fs->kerning == 1)
@@ -293,7 +296,7 @@ void UI_fontstyle_draw_simple(const uiFontStyle *fs, float x, float y, const cha
*/
void UI_fontstyle_draw_simple_backdrop(
const uiFontStyle *fs, float x, float y, const char *str,
- const unsigned char fg[4], const unsigned char bg[4])
+ const float col_fg[4], const float col_bg[4])
{
if (fs->kerning == 1)
BLF_enable(fs->uifont_id, BLF_KERNING_DEFAULT);
@@ -307,21 +310,19 @@ void UI_fontstyle_draw_simple_backdrop(
const float margin = height / 4.0f;
/* backdrop */
- glColor4ubv(bg);
+ float color[4] = { col_bg[0], col_bg[1], col_bg[2], 0.5f };
- UI_draw_roundbox_corner_set(UI_CNR_ALL | UI_RB_ALPHA);
- UI_draw_roundbox(
+ UI_draw_roundbox_corner_set(UI_CNR_ALL);
+ UI_draw_roundbox_aa(true,
x - margin,
(y + decent) - margin,
x + width + margin,
(y + decent) + height + margin,
- margin);
-
- glColor4ubv(fg);
+ margin, color);
}
-
BLF_position(fs->uifont_id, x, y, 0.0f);
+ BLF_color4fv(fs->uifont_id, col_fg);
BLF_draw(fs->uifont_id, str, BLF_DRAW_STR_DUMMY_MAX);
if (fs->kerning == 1)
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 5431f210441..857ca0a9d96 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -56,11 +56,12 @@
#include "BKE_colorband.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_idcode.h"
#include "BKE_idprop.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
+#include "BKE_library_override.h"
#include "BKE_linestyle.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
@@ -69,9 +70,11 @@
#include "BKE_particle.h"
#include "BKE_paint.h"
#include "BKE_report.h"
-#include "BKE_sca.h"
#include "BKE_screen.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_screen.h"
#include "ED_object.h"
#include "ED_render.h"
@@ -91,11 +94,128 @@
// #define USE_OP_RESET_BUT // we may want to make this optional, disable for now.
+/* defines for templateID/TemplateSearch */
+#define TEMPLATE_SEARCH_TEXTBUT_WIDTH (UI_UNIT_X * 6)
+#define TEMPLATE_SEARCH_TEXTBUT_HEIGHT UI_UNIT_Y
+
void UI_template_fix_linking(void)
{
}
+/**
+ * Add a block button for the search menu for templateID and templateSearch.
+ */
+static void template_add_button_search_menu(
+ const bContext *C, uiLayout *layout, uiBlock *block,
+ PointerRNA *ptr, PropertyRNA *prop,
+ uiBlockCreateFunc block_func, void *block_argN, const char * const tip,
+ const bool use_previews, const bool editable)
+{
+ PointerRNA active_ptr = RNA_property_pointer_get(ptr, prop);
+ ID *id = (active_ptr.data && RNA_struct_is_ID(active_ptr.type)) ? active_ptr.data : NULL;
+ const ID *idfrom = ptr->id.data;
+ const StructRNA *type = active_ptr.type ? active_ptr.type : RNA_property_pointer_type(ptr, prop);
+ uiBut *but;
+
+ if (use_previews) {
+ ARegion *region = CTX_wm_region(C);
+ ScrArea *area = CTX_wm_area(C);
+ /* XXX ugly top-bar exception */
+ const bool use_big_size = (region->regiontype != RGN_TYPE_HEADER) && (area->spacetype != SPACE_TOPBAR); /* silly check, could be more generic */
+ /* Ugly exception for screens here, drawing their preview in icon size looks ugly/useless */
+ const bool use_preview_icon = use_big_size || (id && (GS(id->name) != ID_SCR));
+ const short width = UI_UNIT_X * (use_big_size ? 6 : 1.6f);
+ const short height = UI_UNIT_Y * (use_big_size ? 6 : 1);
+
+ but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, width, height, tip);
+ if (use_preview_icon) {
+ int icon = id ? ui_id_icon_get(C, id, use_big_size) : RNA_struct_ui_icon(type);
+ ui_def_but_icon(but, icon, UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
+ }
+ else {
+ ui_def_but_icon(but, RNA_struct_ui_icon(type), UI_HAS_ICON);
+ UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT);
+ }
+
+ if ((idfrom && idfrom->lib) || !editable)
+ UI_but_flag_enable(but, UI_BUT_DISABLED);
+ if (use_big_size) {
+ uiLayoutRow(layout, true);
+ }
+ }
+ else {
+ but = uiDefBlockButN(block, block_func, block_argN, "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y, tip);
+ ui_def_but_icon(but, RNA_struct_ui_icon(type), UI_HAS_ICON);
+ if (id) {
+ /* default dragging of icon for id browse buttons */
+ UI_but_drag_set_id(but, id);
+ }
+ UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT);
+
+ if ((idfrom && idfrom->lib) || !editable)
+ UI_but_flag_enable(but, UI_BUT_DISABLED);
+ }
+}
+
+static uiBlock *template_common_search_menu(
+ const bContext *C, ARegion *region,
+ uiButSearchFunc search_func, void *search_arg,
+ uiButHandleFunc handle_func, void *active_item,
+ const int preview_rows, const int preview_cols)
+{
+ static char search[256];
+ wmWindow *win = CTX_wm_window(C);
+ uiBlock *block;
+ uiBut *but;
+
+ /* clear initial search string, then all items show */
+ search[0] = 0;
+
+ block = UI_block_begin(C, region, "_popup", UI_EMBOSS);
+ UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_SEARCH_MENU);
+
+ /* preview thumbnails */
+ if (preview_rows > 0 && preview_cols > 0) {
+ const int w = 4 * U.widget_unit * preview_cols;
+ const int h = 5 * U.widget_unit * preview_rows;
+
+ /* fake button, it holds space for search items */
+ uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 26, w, h, NULL, 0, 0, 0, 0, NULL);
+
+ but = uiDefSearchBut(
+ block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y,
+ preview_rows, preview_cols, "");
+ }
+ /* list view */
+ else {
+ const int searchbox_width = UI_searchbox_size_x();
+ const int searchbox_height = UI_searchbox_size_y();
+
+ /* fake button, it holds space for search items */
+ uiDefBut(
+ block, UI_BTYPE_LABEL, 0, "", 10, 15, searchbox_width, searchbox_height,
+ NULL, 0, 0, 0, 0, NULL);
+ but = uiDefSearchBut(
+ block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0,
+ searchbox_width, UI_UNIT_Y - 1, 0, 0, "");
+ }
+ UI_but_func_search_set(
+ but, ui_searchbox_create_generic, search_func,
+ search_arg, handle_func, active_item);
+
+
+ UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
+ UI_block_direction_set(block, UI_DIR_DOWN);
+
+ /* give search-field focus */
+ UI_but_focus_on_enter_event(win, but);
+ /* this type of search menu requires undo */
+ but->flag |= UI_BUT_UNDO;
+
+ return block;
+}
+
/********************** Header Template *************************/
void uiTemplateHeader(uiLayout *layout, bContext *C)
@@ -120,7 +240,7 @@ typedef struct TemplateID {
} TemplateID;
/* Search browse menu, assign */
-static void id_search_call_cb(bContext *C, void *arg_template, void *item)
+static void template_ID_set_property_cb(bContext *C, void *arg_template, void *item)
{
TemplateID *template_ui = (TemplateID *)arg_template;
@@ -231,30 +351,25 @@ static void id_search_cb_objects_from_scene(const bContext *C, void *arg_templat
}
BKE_main_id_flag_listbase(lb, LIB_TAG_DOIT, false);
- for (Base *base = scene->base.first; base; base = base->next) {
- base->object->id.tag |= LIB_TAG_DOIT;
+
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob_iter)
+ {
+ ob_iter->id.tag |= LIB_TAG_DOIT;
}
+ FOREACH_SCENE_OBJECT_END;
id_search_cb_tagged(C, arg_template, str, items);
}
/* ID Search browse menu, open */
static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
{
- static char search[256];
static TemplateID template_ui;
- PointerRNA idptr;
- wmWindow *win = CTX_wm_window(C);
- uiBlock *block;
- uiBut *but;
+ PointerRNA active_item_ptr;
void (*id_search_cb_p)(const bContext *, void *, const char *, uiSearchItems *) = id_search_cb;
- /* clear initial search string, then all items show */
- search[0] = 0;
/* arg_litem is malloced, can be freed by parent button */
template_ui = *((TemplateID *)arg_litem);
-
- /* get active id for showing first item */
- idptr = RNA_property_pointer_get(&template_ui.ptr, template_ui.prop);
+ active_item_ptr = RNA_property_pointer_get(&template_ui.ptr, template_ui.prop);
if (template_ui.filter) {
/* Currently only used for objects. */
@@ -265,46 +380,9 @@ static uiBlock *id_search_menu(bContext *C, ARegion *ar, void *arg_litem)
}
}
- block = UI_block_begin(C, ar, "_popup", UI_EMBOSS);
- UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_SEARCH_MENU);
-
- /* preview thumbnails */
- if (template_ui.prv_rows > 0 && template_ui.prv_cols > 0) {
- int w = 4 * U.widget_unit * template_ui.prv_cols;
- int h = 5 * U.widget_unit * template_ui.prv_rows;
-
- /* fake button, it holds space for search items */
- uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 26, w, h, NULL, 0, 0, 0, 0, NULL);
-
- but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, w, UI_UNIT_Y,
- template_ui.prv_rows, template_ui.prv_cols, "");
- UI_but_func_search_set(
- but, ui_searchbox_create_generic, id_search_cb_p,
- &template_ui, id_search_call_cb, idptr.data);
- }
- /* list view */
- else {
- const int searchbox_width = UI_searchbox_size_x();
- const int searchbox_height = UI_searchbox_size_y();
-
- /* fake button, it holds space for search items */
- uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 15, searchbox_width, searchbox_height, NULL, 0, 0, 0, 0, NULL);
- but = uiDefSearchBut(block, search, 0, ICON_VIEWZOOM, sizeof(search), 10, 0, searchbox_width, UI_UNIT_Y - 1, 0, 0, "");
- UI_but_func_search_set(
- but, ui_searchbox_create_generic, id_search_cb_p,
- &template_ui, id_search_call_cb, idptr.data);
- }
-
-
- UI_block_bounds_set_normal(block, 0.3f * U.widget_unit);
- UI_block_direction_set(block, UI_DIR_DOWN);
-
- /* give search-field focus */
- UI_but_focus_on_enter_event(win, but);
- /* this type of search menu requires undo */
- but->flag |= UI_BUT_UNDO;
-
- return block;
+ return template_common_search_menu(
+ C, ar, id_search_cb_p, &template_ui, template_ID_set_property_cb, active_item_ptr.data,
+ template_ui.prv_rows, template_ui.prv_cols);
}
/************************ ID Template ***************************/
@@ -382,14 +460,34 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
case UI_ID_LOCAL:
if (id) {
Main *bmain = CTX_data_main(C);
- if (id_make_local(bmain, id, false, false)) {
- BKE_main_id_clear_newpoins(bmain);
+ if (CTX_wm_window(C)->eventstate->shift) {
+ ID *override_id = BKE_override_static_create_from_id(bmain, id);
+ if (override_id != NULL) {
+ BKE_main_id_clear_newpoins(bmain);
- /* reassign to get get proper updates/notifiers */
- idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop);
- RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr);
- RNA_property_update(C, &template_ui->ptr, template_ui->prop);
+ /* Assign new pointer, takes care of updates/notifiers */
+ RNA_id_pointer_create(override_id, &idptr);
+ }
}
+ else {
+ if (id_make_local(bmain, id, false, false)) {
+ BKE_main_id_clear_newpoins(bmain);
+
+ /* reassign to get get proper updates/notifiers */
+ idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop);
+ }
+ }
+ RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr);
+ RNA_property_update(C, &template_ui->ptr, template_ui->prop);
+ }
+ break;
+ case UI_ID_OVERRIDE:
+ if (id && id->override_static) {
+ BKE_override_static_free(&id->override_static);
+ /* reassign to get get proper updates/notifiers */
+ idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop);
+ RNA_property_pointer_set(&template_ui->ptr, template_ui->prop, idptr);
+ RNA_property_update(C, &template_ui->ptr, template_ui->prop);
}
break;
case UI_ID_ALONE:
@@ -403,13 +501,13 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
Scene *scene = CTX_data_scene(C);
ED_object_single_user(bmain, scene, (struct Object *)id);
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
else {
if (id) {
Main *bmain = CTX_data_main(C);
id_single_user(C, id, &template_ui->ptr, template_ui->prop);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
}
}
@@ -421,7 +519,7 @@ static void template_id_cb(bContext *C, void *arg_litem, void *arg_event)
}
}
-static const char *template_id_browse_tip(StructRNA *type)
+static const char *template_id_browse_tip(const StructRNA *type)
{
if (type) {
switch (RNA_type_to_ID_code(type)) {
@@ -453,6 +551,8 @@ static const char *template_id_browse_tip(StructRNA *type)
case ID_PAL: return N_("Browse Palette Data to be linked");
case ID_PC: return N_("Browse Paint Curve Data to be linked");
case ID_CF: return N_("Browse Cache Files to be linked");
+ case ID_WS: return N_("Browse Workspace to be linked");
+ case ID_LP: return N_("Browse LightProbe to be linked");
}
}
return N_("Browse ID data to be linked");
@@ -472,6 +572,68 @@ static const char *template_id_context(StructRNA *type)
}
#endif
+static uiBut *template_id_def_new_but(
+ uiBlock *block, const ID *id, const TemplateID *template_ui, StructRNA *type,
+ const char * const newop, const bool editable, const bool id_open, const bool use_tab_but,
+ int but_height)
+{
+ ID *idfrom = template_ui->ptr.id.data;
+ uiBut *but;
+ const int w = id ? UI_UNIT_X : id_open ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
+ const int but_type = use_tab_but ? UI_BTYPE_TAB : UI_BTYPE_BUT;
+
+ /* i18n markup, does nothing! */
+ BLT_I18N_MSGID_MULTI_CTXT("New", BLT_I18NCONTEXT_DEFAULT,
+ BLT_I18NCONTEXT_ID_SCENE,
+ BLT_I18NCONTEXT_ID_OBJECT,
+ BLT_I18NCONTEXT_ID_MESH,
+ BLT_I18NCONTEXT_ID_CURVE,
+ BLT_I18NCONTEXT_ID_METABALL,
+ BLT_I18NCONTEXT_ID_MATERIAL,
+ BLT_I18NCONTEXT_ID_TEXTURE,
+ BLT_I18NCONTEXT_ID_IMAGE,
+ BLT_I18NCONTEXT_ID_LATTICE,
+ BLT_I18NCONTEXT_ID_LAMP,
+ BLT_I18NCONTEXT_ID_CAMERA,
+ BLT_I18NCONTEXT_ID_WORLD,
+ BLT_I18NCONTEXT_ID_SCREEN,
+ BLT_I18NCONTEXT_ID_TEXT,
+ );
+ BLT_I18N_MSGID_MULTI_CTXT("New", BLT_I18NCONTEXT_ID_SPEAKER,
+ BLT_I18NCONTEXT_ID_SOUND,
+ BLT_I18NCONTEXT_ID_ARMATURE,
+ BLT_I18NCONTEXT_ID_ACTION,
+ BLT_I18NCONTEXT_ID_NODETREE,
+ BLT_I18NCONTEXT_ID_BRUSH,
+ BLT_I18NCONTEXT_ID_PARTICLESETTINGS,
+ BLT_I18NCONTEXT_ID_GPENCIL,
+ BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE,
+ BLT_I18NCONTEXT_ID_WORKSPACE,
+ BLT_I18NCONTEXT_ID_LIGHTPROBE,
+ );
+
+ if (newop) {
+ but = uiDefIconTextButO(block, but_type, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN,
+ (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), 0, 0, w, but_height, NULL);
+ UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
+ }
+ else {
+ but = uiDefIconTextBut(block, but_type, 0, ICON_ZOOMIN, (id) ? "" : CTX_IFACE_(template_id_context(type), "New"),
+ 0, 0, w, but_height, NULL, 0, 0, 0, 0, NULL);
+ UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
+ }
+
+ if ((idfrom && idfrom->lib) || !editable) {
+ UI_but_flag_enable(but, UI_BUT_DISABLED);
+ }
+
+#ifndef WITH_INTERNATIONAL
+ UNUSED_VARS(type);
+#endif
+
+ return but;
+}
+
static void template_ID(
bContext *C, uiLayout *layout, TemplateID *template_ui, StructRNA *type, int flag,
const char *newop, const char *openop, const char *unlinkop)
@@ -482,6 +644,7 @@ static void template_ID(
// ListBase *lb; // UNUSED
ID *id, *idfrom;
const bool editable = RNA_property_editable(&template_ui->ptr, template_ui->prop);
+ const bool use_previews = template_ui->preview = (flag & UI_ID_PREVIEWS) != 0;
idptr = RNA_property_pointer_get(&template_ui->ptr, template_ui->prop);
id = idptr.data;
@@ -494,29 +657,11 @@ static void template_ID(
if (idptr.type)
type = idptr.type;
- if (flag & UI_ID_PREVIEWS) {
- template_ui->preview = true;
-
- but = uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template_ui), "", 0, 0, UI_UNIT_X * 6, UI_UNIT_Y * 6,
- TIP_(template_id_browse_tip(type)));
- ui_def_but_icon(but, id ? ui_id_icon_get(C, id, true) : RNA_struct_ui_icon(type),
- UI_HAS_ICON | UI_BUT_ICON_PREVIEW);
-
- if ((idfrom && idfrom->lib) || !editable)
- UI_but_flag_enable(but, UI_BUT_DISABLED);
-
- uiLayoutRow(layout, true);
- }
- else if (flag & UI_ID_BROWSE) {
- but = uiDefBlockButN(block, id_search_menu, MEM_dupallocN(template_ui), "", 0, 0, UI_UNIT_X * 1.6, UI_UNIT_Y,
- TIP_(template_id_browse_tip(type)));
- ui_def_but_icon(but, RNA_struct_ui_icon(type), UI_HAS_ICON);
- /* default dragging of icon for id browse buttons */
- UI_but_drag_set_id(but, id);
- UI_but_drawflag_enable(but, UI_BUT_ICON_LEFT);
-
- if ((idfrom && idfrom->lib) || !editable)
- UI_but_flag_enable(but, UI_BUT_DISABLED);
+ if (flag & UI_ID_BROWSE) {
+ template_add_button_search_menu(
+ C, layout, block, &template_ui->ptr, template_ui->prop,
+ id_search_menu, MEM_dupallocN(template_ui), TIP_(template_id_browse_tip(type)),
+ use_previews, editable);
}
/* text button with name */
@@ -526,8 +671,9 @@ static void template_ID(
//text_idbutton(id, name);
name[0] = '\0';
- but = uiDefButR(block, UI_BTYPE_TEXT, 0, name, 0, 0, UI_UNIT_X * 6, UI_UNIT_Y,
- &idptr, "name", -1, 0, 0, -1, -1, RNA_struct_ui_description(type));
+ but = uiDefButR(
+ block, UI_BTYPE_TEXT, 0, name, 0, 0, TEMPLATE_SEARCH_TEXTBUT_WIDTH, TEMPLATE_SEARCH_TEXTBUT_HEIGHT,
+ &idptr, "name", -1, 0, 0, -1, -1, RNA_struct_ui_description(type));
UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_RENAME));
if (user_alert) UI_but_flag_enable(but, UI_BUT_REDALERT);
@@ -538,13 +684,25 @@ static void template_ID(
UI_but_flag_enable(but, UI_BUT_DISABLED);
}
else {
+ const bool disabled = (!id_make_local(CTX_data_main(C), id, true /* test */, false) ||
+ (idfrom && idfrom->lib));
but = uiDefIconBut(block, UI_BTYPE_BUT, 0, ICON_LIBRARY_DATA_DIRECT, 0, 0, UI_UNIT_X, UI_UNIT_Y,
- NULL, 0, 0, 0, 0, TIP_("Direct linked library data-block, click to make local"));
- if (!id_make_local(CTX_data_main(C), id, true /* test */, false) || (idfrom && idfrom->lib))
+ NULL, 0, 0, 0, 0,
+ TIP_("Direct linked library data-block, click to make local, "
+ "Shift + Click to create a static override"));
+ if (disabled) {
UI_but_flag_enable(but, UI_BUT_DISABLED);
+ }
+ else {
+ UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_LOCAL));
+ }
}
-
- UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_LOCAL));
+ }
+ else if (ID_IS_STATIC_OVERRIDE(id)) {
+ but = uiDefIconBut(block, UI_BTYPE_BUT, 0, ICON_LIBRARY_DATA_OVERRIDE, 0, 0, UI_UNIT_X, UI_UNIT_Y,
+ NULL, 0, 0, 0, 0,
+ TIP_("Static override of linked library data-block, click to make fully local"));
+ UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_OVERRIDE));
}
if (id->us > 1) {
@@ -572,55 +730,13 @@ static void template_ID(
if (user_alert) UI_but_flag_enable(but, UI_BUT_REDALERT);
- if (id->lib == NULL && !(ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_TXT, ID_OB))) {
+ if (id->lib == NULL && !(ELEM(GS(id->name), ID_GR, ID_SCE, ID_SCR, ID_TXT, ID_OB, ID_WS))) {
uiDefButR(block, UI_BTYPE_TOGGLE, 0, "F", 0, 0, UI_UNIT_X, UI_UNIT_Y, &idptr, "use_fake_user", -1, 0, 0, -1, -1, NULL);
}
}
if (flag & UI_ID_ADD_NEW) {
- int w = id ? UI_UNIT_X : (flag & UI_ID_OPEN) ? UI_UNIT_X * 3 : UI_UNIT_X * 6;
-
- /* i18n markup, does nothing! */
- BLT_I18N_MSGID_MULTI_CTXT("New", BLT_I18NCONTEXT_DEFAULT,
- BLT_I18NCONTEXT_ID_SCENE,
- BLT_I18NCONTEXT_ID_OBJECT,
- BLT_I18NCONTEXT_ID_MESH,
- BLT_I18NCONTEXT_ID_CURVE,
- BLT_I18NCONTEXT_ID_METABALL,
- BLT_I18NCONTEXT_ID_MATERIAL,
- BLT_I18NCONTEXT_ID_TEXTURE,
- BLT_I18NCONTEXT_ID_IMAGE,
- BLT_I18NCONTEXT_ID_LATTICE,
- BLT_I18NCONTEXT_ID_LAMP,
- BLT_I18NCONTEXT_ID_CAMERA,
- BLT_I18NCONTEXT_ID_WORLD,
- BLT_I18NCONTEXT_ID_SCREEN,
- BLT_I18NCONTEXT_ID_TEXT,
- );
- BLT_I18N_MSGID_MULTI_CTXT("New", BLT_I18NCONTEXT_ID_SPEAKER,
- BLT_I18NCONTEXT_ID_SOUND,
- BLT_I18NCONTEXT_ID_ARMATURE,
- BLT_I18NCONTEXT_ID_ACTION,
- BLT_I18NCONTEXT_ID_NODETREE,
- BLT_I18NCONTEXT_ID_BRUSH,
- BLT_I18NCONTEXT_ID_PARTICLESETTINGS,
- BLT_I18NCONTEXT_ID_GPENCIL,
- BLT_I18NCONTEXT_ID_FREESTYLELINESTYLE,
- );
-
- if (newop) {
- but = uiDefIconTextButO(block, UI_BTYPE_BUT, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN,
- (id) ? "" : CTX_IFACE_(template_id_context(type), "New"), 0, 0, w, UI_UNIT_Y, NULL);
- UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
- }
- else {
- but = uiDefIconTextBut(block, UI_BTYPE_BUT, 0, ICON_ZOOMIN, (id) ? "" : CTX_IFACE_(template_id_context(type), "New"),
- 0, 0, w, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
- UI_but_funcN_set(but, template_id_cb, MEM_dupallocN(template_ui), SET_INT_IN_POINTER(UI_ID_ADD_NEW));
- }
-
- if ((idfrom && idfrom->lib) || !editable)
- UI_but_flag_enable(but, UI_BUT_DISABLED);
+ template_id_def_new_but(block, id, template_ui, type, newop, editable, flag & UI_ID_OPEN, false, UI_UNIT_X);
}
/* Due to space limit in UI - skip the "open" icon for packed data, and allow to unpack.
@@ -689,9 +805,58 @@ static void template_ID(
UI_block_align_end(block);
}
+static void template_ID_tabs(
+ bContext *C, uiLayout *layout, TemplateID *template, StructRNA *type, int flag,
+ const char *newop, const char *UNUSED(openop), const char *unlinkop)
+{
+ const ARegion *region = CTX_wm_region(C);
+ const PointerRNA active_ptr = RNA_property_pointer_get(&template->ptr, template->prop);
+ const int but_align = (region->alignment == RGN_ALIGN_TOP) ? UI_BUT_ALIGN_DOWN : UI_BUT_ALIGN_TOP;
+ const int but_height = UI_UNIT_Y * 1.1;
+
+ uiBlock *block = uiLayoutGetBlock(layout);
+ uiStyle *style = UI_style_get_dpi();
+
+
+ for (ID *id = template->idlb->first; id; id = id->next) {
+ wmOperatorType *unlink_ot = WM_operatortype_find(unlinkop, false);
+ const bool is_active = active_ptr.data == id;
+ const unsigned int but_width = UI_fontstyle_string_width(&style->widgetlabel, id->name + 2) + UI_UNIT_X +
+ (is_active ? ICON_DEFAULT_WIDTH_SCALE : 0);
+ uiButTab *tab;
+
+ tab = (uiButTab *)uiDefButR_prop(
+ block, UI_BTYPE_TAB, 0, "", 0, 0, but_width, UI_UNIT_Y * 1.1,
+ &template->ptr, template->prop, 0, 0.0f,
+ sizeof(id->name) - 2, 0.0f, 0.0f, "");
+ UI_but_funcN_set(&tab->but, template_ID_set_property_cb, MEM_dupallocN(template), id);
+ tab->but.custom_data = (void *)id;
+ tab->unlink_ot = unlink_ot;
+
+ if (is_active) {
+ UI_but_flag_enable(&tab->but, UI_BUT_VALUE_CLEAR);
+ }
+ UI_but_drawflag_enable(&tab->but, but_align);
+ }
+
+ if (flag & UI_ID_ADD_NEW) {
+ const bool editable = RNA_property_editable(&template->ptr, template->prop);
+ uiBut *but;
+
+ if (active_ptr.type) {
+ type = active_ptr.type;
+ }
+
+ but = template_id_def_new_but(block, active_ptr.data, template, type, newop, editable, flag & UI_ID_OPEN, true, but_height);
+ UI_but_drawflag_enable(but, but_align);
+ }
+}
+
static void ui_template_id(
- uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
- const char *openop, const char *unlinkop, int flag, int prv_rows, int prv_cols, int filter)
+ uiLayout *layout, bContext *C,
+ PointerRNA *ptr, const char *propname,
+ const char *newop, const char *openop, const char *unlinkop,
+ int flag, int prv_rows, int prv_cols, int filter, bool use_tabs)
{
TemplateID *template_ui;
PropertyRNA *prop;
@@ -732,8 +897,14 @@ static void ui_template_id(
* - template_ID makes a copy of the template data and assigns it to the relevant buttons
*/
if (template_ui->idlb) {
- uiLayoutRow(layout, true);
- template_ID(C, layout, template_ui, type, flag, newop, openop, unlinkop);
+ if (use_tabs) {
+ uiLayoutRow(layout, true);
+ template_ID_tabs(C, layout, template_ui, type, flag, newop, openop, unlinkop);
+ }
+ else {
+ uiLayoutRow(layout, true);
+ template_ID(C, layout, template_ui, type, flag, newop, openop, unlinkop);
+ }
}
MEM_freeN(template_ui);
@@ -743,23 +914,49 @@ void uiTemplateID(
uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
const char *openop, const char *unlinkop, int filter)
{
- ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop,
- UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE, 0, 0, filter);
+ ui_template_id(
+ layout, C, ptr, propname,
+ newop, openop, unlinkop,
+ UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE,
+ 0, 0, filter, false);
}
void uiTemplateIDBrowse(
uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
const char *openop, const char *unlinkop, int filter)
{
- ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop, UI_ID_BROWSE | UI_ID_RENAME, 0, 0, filter);
+ ui_template_id(
+ layout, C, ptr, propname,
+ newop, openop, unlinkop,
+ UI_ID_BROWSE | UI_ID_RENAME,
+ 0, 0, filter, false);
}
void uiTemplateIDPreview(
uiLayout *layout, bContext *C, PointerRNA *ptr, const char *propname, const char *newop,
const char *openop, const char *unlinkop, int rows, int cols, int filter)
{
- ui_template_id(layout, C, ptr, propname, newop, openop, unlinkop,
- UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS, rows, cols, filter);
+ ui_template_id(
+ layout, C, ptr, propname,
+ newop, openop, unlinkop,
+ UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE | UI_ID_PREVIEWS,
+ rows, cols, filter, false);
+}
+
+/**
+ * Version of #uiTemplateID using tabs.
+ */
+void uiTemplateIDTabs(
+ uiLayout *layout, bContext *C,
+ PointerRNA *ptr, const char *propname,
+ const char *newop, const char *openop, const char *unlinkop,
+ int filter)
+{
+ ui_template_id(
+ layout, C, ptr, propname,
+ newop, openop, unlinkop,
+ UI_ID_BROWSE | UI_ID_RENAME | UI_ID_DELETE,
+ 0, 0, filter, true);
}
/************************ ID Chooser Template ***************************/
@@ -821,6 +1018,208 @@ void uiTemplateAnyID(
uiItemFullR(sub, ptr, propID, 0, 0, 0, "", ICON_NONE);
}
+/********************* Search Template ********************/
+
+typedef struct TemplateSearch {
+ uiRNACollectionSearch search_data;
+
+ bool use_previews;
+ int preview_rows, preview_cols;
+} TemplateSearch;
+
+static void template_search_handle_cb(bContext *C, void *arg_template, void *item)
+{
+ TemplateSearch *template_search = arg_template;
+ uiRNACollectionSearch *coll_search = &template_search->search_data;
+ StructRNA *type = RNA_property_pointer_type(&coll_search->target_ptr, coll_search->target_prop);
+ PointerRNA item_ptr;
+
+ RNA_pointer_create(NULL, type, item, &item_ptr);
+ RNA_property_pointer_set(&coll_search->target_ptr, coll_search->target_prop, item_ptr);
+ RNA_property_update(C, &coll_search->target_ptr, coll_search->target_prop);
+}
+
+static uiBlock *template_search_menu(bContext *C, ARegion *region, void *arg_template)
+{
+ static TemplateSearch template_search;
+ PointerRNA active_ptr;
+
+ /* arg_template is malloced, can be freed by parent button */
+ template_search = *((TemplateSearch *)arg_template);
+ active_ptr = RNA_property_pointer_get(&template_search.search_data.target_ptr,
+ template_search.search_data.target_prop);
+
+ return template_common_search_menu(
+ C, region, ui_rna_collection_search_cb, &template_search,
+ template_search_handle_cb, active_ptr.data,
+ template_search.preview_rows, template_search.preview_cols);
+}
+
+static void template_search_add_button_searchmenu(
+ const bContext *C, uiLayout *layout, uiBlock *block,
+ TemplateSearch *template_search, const bool editable)
+{
+ const char *ui_description = RNA_property_ui_description(template_search->search_data.target_prop);
+
+ template_add_button_search_menu(
+ C, layout, block,
+ &template_search->search_data.target_ptr, template_search->search_data.target_prop,
+ template_search_menu, MEM_dupallocN(template_search), ui_description,
+ template_search->use_previews, editable);
+}
+
+static void template_search_add_button_name(
+ uiBlock *block, PointerRNA *active_ptr, const StructRNA *type)
+{
+ uiDefAutoButR(
+ block, active_ptr, RNA_struct_name_property(type), 0, "", ICON_NONE,
+ 0, 0, TEMPLATE_SEARCH_TEXTBUT_WIDTH, TEMPLATE_SEARCH_TEXTBUT_HEIGHT);
+}
+
+static void template_search_add_button_operator(
+ uiBlock *block, const char * const operator_name,
+ const int opcontext, const int icon, const bool editable)
+{
+ if (!operator_name) {
+ return;
+ }
+
+ uiBut *but = uiDefIconButO(
+ block, UI_BTYPE_BUT, operator_name, opcontext, icon,
+ 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+
+ if (!editable) {
+ UI_but_drawflag_enable(but, UI_BUT_DISABLED);
+ }
+}
+
+static void template_search_buttons(
+ const bContext *C, uiLayout *layout, TemplateSearch *template_search,
+ const char *newop, const char *unlinkop)
+{
+ uiBlock *block = uiLayoutGetBlock(layout);
+ uiRNACollectionSearch *search_data = &template_search->search_data;
+ StructRNA *type = RNA_property_pointer_type(&search_data->target_ptr, search_data->target_prop);
+ const bool editable = RNA_property_editable(&search_data->target_ptr, search_data->target_prop);
+ PointerRNA active_ptr = RNA_property_pointer_get(&search_data->target_ptr, search_data->target_prop);
+
+ if (active_ptr.type) {
+ /* can only get correct type when there is an active item */
+ type = active_ptr.type;
+ }
+
+ uiLayoutRow(layout, true);
+ UI_block_align_begin(block);
+
+ template_search_add_button_searchmenu(C, layout, block, template_search, editable);
+ template_search_add_button_name(block, &active_ptr, type);
+ template_search_add_button_operator(block, newop, WM_OP_INVOKE_DEFAULT, ICON_ZOOMIN, editable);
+ template_search_add_button_operator(block, unlinkop, WM_OP_INVOKE_REGION_WIN, ICON_X, editable);
+
+ UI_block_align_end(block);
+}
+
+static PropertyRNA *template_search_get_searchprop(
+ PointerRNA *targetptr, PropertyRNA *targetprop,
+ PointerRNA *searchptr, const char * const searchpropname)
+{
+ PropertyRNA *searchprop;
+
+ if (searchptr && !searchptr->data) {
+ searchptr = NULL;
+ }
+
+ if (!searchptr && !searchpropname) {
+ /* both NULL means we don't use a custom rna collection to search in */
+ }
+ else if (!searchptr && searchpropname) {
+ RNA_warning("searchpropname defined (%s) but searchptr is missing", searchpropname);
+ }
+ else if (searchptr && !searchpropname) {
+ RNA_warning("searchptr defined (%s) but searchpropname is missing", RNA_struct_identifier(searchptr->type));
+ }
+ else if (!(searchprop = RNA_struct_find_property(searchptr, searchpropname))) {
+ RNA_warning("search collection property not found: %s.%s",
+ RNA_struct_identifier(searchptr->type), searchpropname);
+ }
+ else if (RNA_property_type(searchprop) != PROP_COLLECTION) {
+ RNA_warning("search collection property is not a collection type: %s.%s",
+ RNA_struct_identifier(searchptr->type), searchpropname);
+ }
+ /* check if searchprop has same type as targetprop */
+ else if (RNA_property_pointer_type(searchptr, searchprop) != RNA_property_pointer_type(targetptr, targetprop)) {
+ RNA_warning("search collection items from %s.%s are not of type %s",
+ RNA_struct_identifier(searchptr->type), searchpropname,
+ RNA_struct_identifier(RNA_property_pointer_type(targetptr, targetprop)));
+ }
+ else {
+ return searchprop;
+ }
+
+ return NULL;
+}
+
+static TemplateSearch *template_search_setup(
+ PointerRNA *ptr, const char * const propname,
+ PointerRNA *searchptr, const char * const searchpropname)
+{
+ TemplateSearch *template_search;
+ PropertyRNA *prop, *searchprop;
+
+ prop = RNA_struct_find_property(ptr, propname);
+
+ if (!prop || RNA_property_type(prop) != PROP_POINTER) {
+ RNA_warning("pointer property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
+ return NULL;
+ }
+ searchprop = template_search_get_searchprop(ptr, prop, searchptr, searchpropname);
+
+ template_search = MEM_callocN(sizeof(*template_search), __func__);
+ template_search->search_data.target_ptr = *ptr;
+ template_search->search_data.target_prop = prop;
+ template_search->search_data.search_ptr = *searchptr;
+ template_search->search_data.search_prop = searchprop;
+
+ return template_search;
+}
+
+/**
+ * Search menu to pick an item from a collection.
+ * A version of uiTemplateID that works for non-ID types.
+ */
+void uiTemplateSearch(
+ uiLayout *layout, bContext *C,
+ PointerRNA *ptr, const char *propname,
+ PointerRNA *searchptr, const char *searchpropname,
+ const char *newop, const char *unlinkop)
+{
+ TemplateSearch *template_search = template_search_setup(ptr, propname, searchptr, searchpropname);
+ if (template_search != NULL) {
+ template_search_buttons(C, layout, template_search, newop, unlinkop);
+ MEM_freeN(template_search);
+ }
+}
+
+void uiTemplateSearchPreview(
+ uiLayout *layout, bContext *C,
+ PointerRNA *ptr, const char *propname,
+ PointerRNA *searchptr, const char *searchpropname,
+ const char *newop, const char *unlinkop,
+ const int rows, const int cols)
+{
+ TemplateSearch *template_search = template_search_setup(ptr, propname, searchptr, searchpropname);
+
+ if (template_search != NULL) {
+ template_search->use_previews = true;
+ template_search->preview_rows = rows;
+ template_search->preview_cols = cols;
+
+ template_search_buttons(C, layout, template_search, newop, unlinkop);
+
+ MEM_freeN(template_search);
+ }
+}
+
/********************* RNA Path Builder Template ********************/
/* ---------- */
@@ -874,7 +1273,7 @@ static void modifiers_convertToReal(bContext *C, void *ob_v, void *md_v)
ob->partype = PAROBJECT;
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
ED_undo_push(C, "Modifier convert to real");
}
@@ -1017,8 +1416,7 @@ static uiLayout *draw_modifier(
UI_block_emboss_set(block, UI_EMBOSS_NONE);
/* When Modifier is a simulation, show button to switch to context rather than the delete button. */
if (modifier_can_delete(md) &&
- (!modifier_is_simulation(md) ||
- STREQ(scene->r.engine, RE_engine_id_BLENDER_GAME)))
+ !modifier_is_simulation(md))
{
uiItemO(row, "", ICON_X, "OBJECT_OT_modifier_remove");
}
@@ -1132,6 +1530,70 @@ uiLayout *uiTemplateModifier(uiLayout *layout, bContext *C, PointerRNA *ptr)
return NULL;
}
+
+/************************ Redo Buttons Template *************************/
+
+static bool template_operator_redo_property_buts_poll(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
+{
+ return (RNA_property_tags(prop) & OP_PROP_TAG_ADVANCED) == 0;
+}
+
+static void template_operator_redo_property_buts_draw(
+ const bContext *C, wmOperator *op,
+ uiLayout *layout, int layout_flags,
+ bool *r_has_advanced)
+{
+ if (op->type->flag & OPTYPE_MACRO) {
+ for (wmOperator *macro_op = op->macro.first; macro_op; macro_op = macro_op->next) {
+ template_operator_redo_property_buts_draw(C, macro_op, layout, layout_flags, r_has_advanced);
+ }
+ }
+ else {
+ /* Might want to make label_align adjustable somehow. */
+ eAutoPropButsReturn return_info = uiTemplateOperatorPropertyButs(
+ C, layout, op, r_has_advanced ? template_operator_redo_property_buts_poll : NULL,
+ UI_BUT_LABEL_ALIGN_NONE, layout_flags);
+ if (return_info & UI_PROP_BUTS_ANY_FAILED_CHECK) {
+ if (r_has_advanced) {
+ *r_has_advanced = true;
+ }
+ }
+ }
+}
+
+void uiTemplateOperatorRedoProperties(uiLayout *layout, const bContext *C)
+{
+ wmOperator *op = WM_operator_last_redo(C);
+ uiBlock *block = uiLayoutGetBlock(layout);
+
+ if (op == NULL) {
+ return;
+ }
+
+ /* Disable for now, doesn't fit well in popover. */
+#if 0
+ /* Repeat button with operator name as text. */
+ uiItemFullO(layout, "SCREEN_OT_repeat_last", RNA_struct_ui_name(op->type->srna),
+ ICON_NONE, NULL, WM_OP_INVOKE_DEFAULT, 0, NULL);
+#endif
+
+ if (WM_operator_repeat_check(C, op)) {
+#if 0
+ bool has_advanced = false;
+#endif
+
+ UI_block_func_set(block, ED_undo_operator_repeat_cb, op, NULL);
+ template_operator_redo_property_buts_draw(C, op, layout, UI_TEMPLATE_OP_PROPS_COMPACT, NULL /* &has_advanced */ );
+ UI_block_func_set(block, NULL, NULL, NULL); /* may want to reset to old state instead of NULLing all */
+
+#if 0
+ if (has_advanced) {
+ uiItemO(layout, IFACE_("More..."), ICON_NONE, "SCREEN_OT_redo_last");
+ }
+#endif
+ }
+}
+
/************************ Constraint Template *************************/
#include "DNA_constraint_types.h"
@@ -1155,7 +1617,7 @@ static void do_constraint_panels(bContext *C, void *ob_pt, int event)
Main *bmain = CTX_data_main(C);
if (ob->pose)
BKE_pose_tag_recalc(bmain, ob->pose); /* checks & sorts pose channels */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
break;
}
#endif
@@ -1169,8 +1631,8 @@ static void do_constraint_panels(bContext *C, void *ob_pt, int event)
* object_test_constraints(ob);
* if (ob->pose) BKE_pose_update_constraint_flags(ob->pose); */
- if (ob->type == OB_ARMATURE) DAG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
- else DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ if (ob->type == OB_ARMATURE) DEG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
+ else DEG_id_tag_update(&ob->id, OB_RECALC_OB);
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
}
@@ -2628,77 +3090,6 @@ void uiTemplateLayers(
}
}
-void uiTemplateGameStates(
- uiLayout *layout, PointerRNA *ptr, const char *propname,
- PointerRNA *used_ptr, const char *used_propname, int active_state)
-{
- uiLayout *uRow, *uCol;
- PropertyRNA *prop, *used_prop = NULL;
- int groups, cols, states;
- int group, col, state, row;
- int cols_per_group = 5;
- Object *ob = (Object *)ptr->id.data;
-
- prop = RNA_struct_find_property(ptr, propname);
- if (!prop) {
- RNA_warning("states property not found: %s.%s", RNA_struct_identifier(ptr->type), propname);
- return;
- }
-
- /* the number of states determines the way we group them
- * - we want 2 rows only (for now)
- * - the number of columns (cols) is the total number of buttons per row
- * the 'remainder' is added to this, as it will be ok to have first row slightly wider if need be
- * - for now, only split into groups if group will have at least 5 items
- */
- states = RNA_property_array_length(ptr, prop);
- cols = (states / 2) + (states % 2);
- groups = ((cols / 2) < cols_per_group) ? (1) : (cols / cols_per_group);
-
- if (used_ptr && used_propname) {
- used_prop = RNA_struct_find_property(used_ptr, used_propname);
- if (!used_prop) {
- RNA_warning("used layers property not found: %s.%s", RNA_struct_identifier(ptr->type), used_propname);
- return;
- }
-
- if (RNA_property_array_length(used_ptr, used_prop) < states)
- used_prop = NULL;
- }
-
- /* layers are laid out going across rows, with the columns being divided into groups */
-
- for (group = 0; group < groups; group++) {
- uCol = uiLayoutColumn(layout, true);
-
- for (row = 0; row < 2; row++) {
- uiBlock *block;
- uiBut *but;
-
- uRow = uiLayoutRow(uCol, true);
- block = uiLayoutGetBlock(uRow);
- state = groups * cols_per_group * row + cols_per_group * group;
-
- /* add layers as toggle buts */
- for (col = 0; (col < cols_per_group) && (state < states); col++, state++) {
- int icon = 0;
- int butlay = 1 << state;
-
- if (active_state & butlay)
- icon = ICON_LAYER_ACTIVE;
- else if (used_prop && RNA_property_boolean_get_index(used_ptr, used_prop, state))
- icon = ICON_LAYER_USED;
-
- but = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, icon, 0, 0, UI_UNIT_X / 2, UI_UNIT_Y / 2, ptr, prop,
- state, 0, 0, -1, -1, sca_state_name_get(ob, state));
- UI_but_func_set(but, handle_layer_buttons, but, SET_INT_IN_POINTER(state));
- but->type = UI_BTYPE_TOGGLE;
- }
- }
- }
-}
-
-
/************************* List Template **************************/
static void uilist_draw_item_default(
struct uiList *ui_list, struct bContext *UNUSED(C), struct uiLayout *layout,
@@ -3490,11 +3881,14 @@ static void ui_layout_operator_buts__reset_cb(bContext *UNUSED(C), void *op_pt,
* Draw Operator property buttons for redoing execution with different settings.
* This function does not initialize the layout, functions can be called on the layout before and after.
*/
-void uiTemplateOperatorPropertyButs(
+eAutoPropButsReturn uiTemplateOperatorPropertyButs(
const bContext *C, uiLayout *layout, wmOperator *op,
bool (*check_prop)(struct PointerRNA *, struct PropertyRNA *),
- const char label_align, const short flag)
+ const eButLabelAlign label_align, const short flag)
{
+ uiBlock *block = uiLayoutGetBlock(layout);
+ eAutoPropButsReturn return_info = 0;
+
if (!op->properties) {
IDPropertyTemplate val = {0};
op->properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
@@ -3507,14 +3901,14 @@ void uiTemplateOperatorPropertyButs(
/* poll() on this operator may still fail, at the moment there is no nice feedback when this happens
* just fails silently */
if (!WM_operator_repeat_check(C, op)) {
- UI_block_lock_set(uiLayoutGetBlock(layout), true, "Operator can't' redo");
+ UI_block_lock_set(block, true, "Operator can't' redo");
/* XXX, could give some nicer feedback or not show redo panel at all? */
uiItemL(layout, IFACE_("* Redo Unsupported *"), ICON_NONE);
}
else {
/* useful for macros where only one of the steps can't be re-done */
- UI_block_lock_clear(uiLayoutGetBlock(layout));
+ UI_block_lock_clear(block);
}
/* menu */
@@ -3523,7 +3917,7 @@ void uiTemplateOperatorPropertyButs(
PointerRNA op_ptr;
uiLayout *row;
- uiLayoutGetBlock(layout)->ui_operator = op;
+ block->ui_operator = op;
row = uiLayoutRow(layout, true);
uiItemM(row, (bContext *)C, "WM_MT_operator_presets", NULL, ICON_NONE);
@@ -3542,19 +3936,19 @@ void uiTemplateOperatorPropertyButs(
op->type->ui((bContext *)C, op);
op->layout = NULL;
- /* UI_LAYOUT_OP_SHOW_EMPTY ignored */
+ /* UI_LAYOUT_OP_SHOW_EMPTY ignored. return_info is ignored too. We could
+ * allow ot.ui callback to return this, but not needed right now. */
}
else {
wmWindowManager *wm = CTX_wm_manager(C);
PointerRNA ptr;
- int empty;
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
/* main draw call */
- empty = uiDefAutoButsRNA(layout, &ptr, check_prop, label_align) == 0;
+ return_info = uiDefAutoButsRNA(layout, &ptr, check_prop, label_align, (flag & UI_TEMPLATE_OP_PROPS_COMPACT));
- if (empty && (flag & UI_TEMPLATE_OP_PROPS_SHOW_EMPTY)) {
+ if ((return_info & UI_PROP_BUTS_NONE_ADDED) && (flag & UI_TEMPLATE_OP_PROPS_SHOW_EMPTY)) {
uiItemL(layout, IFACE_("No Properties"), ICON_NONE);
}
}
@@ -3564,7 +3958,6 @@ void uiTemplateOperatorPropertyButs(
* but this is not so important if this button is drawn in those cases
* (which isn't all that likely anyway) - campbell */
if (op->properties->len) {
- uiBlock *block;
uiBut *but;
uiLayout *col; /* needed to avoid alignment errors with previous buttons */
@@ -3578,7 +3971,6 @@ void uiTemplateOperatorPropertyButs(
/* set various special settings for buttons */
{
- uiBlock *block = uiLayoutGetBlock(layout);
const bool is_popup = (block->flag & UI_BLOCK_KEEP_OPEN) != 0;
uiBut *but;
@@ -3598,6 +3990,8 @@ void uiTemplateOperatorPropertyButs(
}
}
}
+
+ return return_info;
}
/************************* Running Jobs Template **************************/
@@ -3935,6 +4329,7 @@ void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
if (propptr.data) {
uiBut *but = uiLayoutGetBlock(layout)->buttons.last;
+ WM_operator_properties_sanitize(&propptr, false);
template_keymap_item_properties(layout, NULL, &propptr);
/* attach callbacks to compensate for missing properties update,
@@ -3951,6 +4346,66 @@ void uiTemplateKeymapItemProperties(uiLayout *layout, PointerRNA *ptr)
}
}
+/********************************* Overrides *************************************/
+
+void uiTemplateOverrideProperty(
+ uiLayout *layout, PointerRNA *collection_props_ptr, PointerRNA *scene_props_ptr, const char *propname,
+ const char *name, const char *text_ctxt, int translate, int icon,
+ const char *custom_template)
+{
+ bool is_set = false;
+ uiLayout *row, *col;
+
+ PointerRNA *ptr;
+ PropertyRNA *prop;
+
+ IDProperty *collection_props = collection_props_ptr->data;
+
+ if (IDP_GetPropertyFromGroup(collection_props, propname)) {
+ prop = RNA_struct_find_property(collection_props_ptr, propname);
+ ptr = collection_props_ptr;
+ is_set = RNA_property_is_set(ptr, prop);
+ }
+ else {
+ /* property doesn't exist yet */
+ prop = RNA_struct_find_property(scene_props_ptr, propname);
+ ptr = scene_props_ptr;
+ }
+
+ /* Get translated name (label). */
+ name = RNA_translate_ui_text(name, text_ctxt, NULL, prop, translate);
+
+ row = uiLayoutRow(layout, false);
+ col = uiLayoutColumn(row, false);
+
+ uiLayoutSetEnabled(col, is_set);
+
+ if (custom_template && STREQ(custom_template, "icon_view")) {
+ uiTemplateIconView(col, ptr, propname, false, 5.0f);
+ }
+ else {
+ uiItemFullR(col, ptr, prop, -1, 0, 0, name, icon);
+ }
+
+ col = uiLayoutColumn(row, false);
+ uiBut *but;
+ uiBlock *block = uiLayoutGetBlock(col);
+ UI_block_emboss_set(block, UI_EMBOSS_NONE);
+
+ if (is_set) {
+ but = uiDefIconButO(block, UI_BTYPE_BUT, "UI_OT_unuse_property_button", WM_OP_EXEC_DEFAULT, ICON_X, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+ }
+ else {
+ but = uiDefIconButO(block, UI_BTYPE_BUT, "UI_OT_use_property_button", WM_OP_EXEC_DEFAULT, ICON_ZOOMIN, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL);
+ /* XXX - Using existing data struct to pass another RNAPointer */
+ but->rnasearchpoin = *scene_props_ptr;
+ }
+
+ but->rnapoin = *collection_props_ptr;
+ but->rnaprop = prop;
+ UI_block_emboss_set(block, UI_EMBOSS);
+}
+
/********************************* Color management *************************************/
void uiTemplateColorspaceSettings(uiLayout *layout, PointerRNA *ptr, const char *propname)
diff --git a/source/blender/editors/interface/interface_utils.c b/source/blender/editors/interface/interface_utils.c
index 1927d7280f3..5841a61acc5 100644
--- a/source/blender/editors/interface/interface_utils.c
+++ b/source/blender/editors/interface/interface_utils.c
@@ -157,66 +157,159 @@ uiBut *uiDefAutoButR(uiBlock *block, PointerRNA *ptr, PropertyRNA *prop, int ind
* \a check_prop callback filters functions to avoid drawing certain properties,
* in cases where PROP_HIDDEN flag can't be used for a property.
*/
-int uiDefAutoButsRNA(
+eAutoPropButsReturn uiDefAutoButsRNA(
uiLayout *layout, PointerRNA *ptr,
bool (*check_prop)(PointerRNA *, PropertyRNA *),
- const char label_align)
+ const eButLabelAlign label_align, const bool compact)
{
+ eAutoPropButsReturn return_info = UI_PROP_BUTS_NONE_ADDED;
uiLayout *split, *col;
int flag;
const char *name;
- int tot = 0;
-
- assert(ELEM(label_align, '\0', 'H', 'V'));
RNA_STRUCT_BEGIN (ptr, prop)
{
flag = RNA_property_flag(prop);
- if (flag & PROP_HIDDEN || (check_prop && check_prop(ptr, prop) == 0))
+
+ if (flag & PROP_HIDDEN) {
continue;
+ }
+ if (check_prop && check_prop(ptr, prop) == 0) {
+ return_info |= UI_PROP_BUTS_ANY_FAILED_CHECK;
+ continue;
+ }
- if (label_align != '\0') {
- PropertyType type = RNA_property_type(prop);
- const bool is_boolean = (type == PROP_BOOLEAN && !RNA_property_array_check(prop));
+ switch (label_align) {
+ case UI_BUT_LABEL_ALIGN_COLUMN:
+ case UI_BUT_LABEL_ALIGN_SPLIT_COLUMN:
+ {
+ PropertyType type = RNA_property_type(prop);
+ const bool is_boolean = (type == PROP_BOOLEAN && !RNA_property_array_check(prop));
- name = RNA_property_ui_name(prop);
+ name = RNA_property_ui_name(prop);
- if (label_align == 'V') {
- col = uiLayoutColumn(layout, true);
+ if (label_align == UI_BUT_LABEL_ALIGN_COLUMN) {
+ col = uiLayoutColumn(layout, true);
- if (!is_boolean)
- uiItemL(col, name, ICON_NONE);
- }
- else { /* (label_align == 'H') */
- BLI_assert(label_align == 'H');
- split = uiLayoutSplit(layout, 0.5f, false);
+ if (!is_boolean)
+ uiItemL(col, name, ICON_NONE);
+ }
+ else {
+ BLI_assert(label_align == UI_BUT_LABEL_ALIGN_SPLIT_COLUMN);
+ split = uiLayoutSplit(layout, 0.5f, false);
+
+ col = uiLayoutColumn(split, false);
+ uiItemL(col, (is_boolean) ? "" : name, ICON_NONE);
+ col = uiLayoutColumn(split, false);
+ }
- col = uiLayoutColumn(split, false);
- uiItemL(col, (is_boolean) ? "" : name, ICON_NONE);
- col = uiLayoutColumn(split, false);
+ /* may meed to add more cases here.
+ * don't override enum flag names */
+
+ /* name is shown above, empty name for button below */
+ name = (flag & PROP_ENUM_FLAG || is_boolean) ? NULL : "";
+
+ break;
}
+ case UI_BUT_LABEL_ALIGN_NONE:
+ default:
+ col = layout;
+ name = NULL; /* no smart label alignment, show default name with button */
+ break;
+ }
+
+ uiItemFullR(col, ptr, prop, -1, 0, compact ? UI_ITEM_R_COMPACT : 0, name, ICON_NONE);
+ return_info &= ~UI_PROP_BUTS_NONE_ADDED;
+ }
+ RNA_STRUCT_END;
+
+ return return_info;
+}
- /* may meed to add more cases here.
- * don't override enum flag names */
+/* *** RNA collection search menu *** */
- /* name is shown above, empty name for button below */
- name = (flag & PROP_ENUM_FLAG || is_boolean) ? NULL : "";
+typedef struct CollItemSearch {
+ struct CollItemSearch *next, *prev;
+ void *data;
+ char *name;
+ int index;
+ int iconid;
+} CollItemSearch;
+
+static int sort_search_items_list(const void *a, const void *b)
+{
+ const CollItemSearch *cis1 = a;
+ const CollItemSearch *cis2 = b;
+
+ if (BLI_strcasecmp(cis1->name, cis2->name) > 0)
+ return 1;
+ else
+ return 0;
+}
+
+void ui_rna_collection_search_cb(const struct bContext *C, void *arg, const char *str, uiSearchItems *items)
+{
+ uiRNACollectionSearch *data = arg;
+ char *name;
+ int i = 0, iconid = 0, flag = RNA_property_flag(data->target_prop);
+ ListBase *items_list = MEM_callocN(sizeof(ListBase), "items_list");
+ CollItemSearch *cis;
+ const bool skip_filter = !(data->but_changed && *data->but_changed);
+
+ /* build a temporary list of relevant items first */
+ RNA_PROP_BEGIN (&data->search_ptr, itemptr, data->search_prop)
+ {
+
+ if (flag & PROP_ID_SELF_CHECK)
+ if (itemptr.data == data->target_ptr.id.data)
+ continue;
+
+ /* use filter */
+ if (RNA_property_type(data->target_prop) == PROP_POINTER) {
+ if (RNA_property_pointer_poll(&data->target_ptr, data->target_prop, &itemptr) == 0)
+ continue;
}
- else {
- col = layout;
- name = NULL; /* no smart label alignment, show default name with button */
+
+ name = RNA_struct_name_get_alloc(&itemptr, NULL, 0, NULL); /* could use the string length here */
+ iconid = 0;
+ if (itemptr.type && RNA_struct_is_ID(itemptr.type)) {
+ iconid = ui_id_icon_get(C, itemptr.data, false);
}
- uiItemFullR(col, ptr, prop, -1, 0, 0, name, ICON_NONE);
- tot++;
+ if (name) {
+ if (skip_filter || BLI_strcasestr(name, str)) {
+ cis = MEM_callocN(sizeof(CollItemSearch), "CollectionItemSearch");
+ cis->data = itemptr.data;
+ cis->name = MEM_dupallocN(name);
+ cis->index = i;
+ cis->iconid = iconid;
+ BLI_addtail(items_list, cis);
+ }
+ MEM_freeN(name);
+ }
+
+ i++;
}
- RNA_STRUCT_END;
+ RNA_PROP_END;
- return tot;
+ BLI_listbase_sort(items_list, sort_search_items_list);
+
+ /* add search items from temporary list */
+ for (cis = items_list->first; cis; cis = cis->next) {
+ if (UI_search_item_add(items, cis->name, cis->data, cis->iconid) == false) {
+ break;
+ }
+ }
+
+ for (cis = items_list->first; cis; cis = cis->next) {
+ MEM_freeN(cis->name);
+ }
+ BLI_freelistN(items_list);
+ MEM_freeN(items_list);
}
-/***************************** ID Utilities *******************************/
+/***************************** ID Utilities *******************************/
int UI_icon_from_id(ID *id)
{
Object *ob;
diff --git a/source/blender/editors/interface/interface_widgets.c b/source/blender/editors/interface/interface_widgets.c
index 8c868b81239..b1cacdc5db6 100644
--- a/source/blender/editors/interface/interface_widgets.c
+++ b/source/blender/editors/interface/interface_widgets.c
@@ -43,13 +43,9 @@
#include "BLI_utildefines.h"
#include "BKE_context.h"
-#include "BKE_curve.h"
#include "RNA_access.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
#include "BLF_api.h"
#include "UI_interface.h"
@@ -58,6 +54,10 @@
#include "interface_intern.h"
#include "GPU_basic_shader.h"
+#include "GPU_batch.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
#ifdef WITH_INPUT_IME
# include "WM_types.h"
@@ -72,13 +72,19 @@ enum {
/* Show that holding the button opens a menu. */
UI_STATE_HOLD_ACTION = UI_BUT_UPDATE_DELAY,
UI_STATE_TEXT_INPUT = UI_BUT_UNDO,
+ UI_STATE_ACTIVE_LEFT = UI_BUT_VALUE_CLEAR,
+ UI_STATE_ACTIVE_RIGHT = UI_BUT_TEXTEDIT_UPDATE,
- UI_STATE_FLAGS_ALL = (UI_STATE_HOLD_ACTION | UI_STATE_TEXT_INPUT),
+ UI_STATE_FLAGS_ALL = (UI_STATE_HOLD_ACTION |
+ UI_STATE_TEXT_INPUT |
+ UI_STATE_ACTIVE_LEFT |
+ UI_STATE_ACTIVE_RIGHT),
};
/* Prevent accidental use. */
#define UI_BUT_UPDATE_DELAY ((void)0)
#define UI_BUT_UNDO ((void)0)
+
/* ************** widget base functions ************** */
/**
* - in: roundbox codes for corner types and radius
@@ -98,6 +104,8 @@ enum {
typedef struct uiWidgetTrias {
unsigned int tot;
+ int type;
+ float size, center[2];
float vec[16][2];
const unsigned int (*index)[3];
@@ -105,21 +113,24 @@ typedef struct uiWidgetTrias {
} uiWidgetTrias;
/* max as used by round_box__edges */
+/* Make sure to change widget_base_vert.glsl accordingly. */
#define WIDGET_CURVE_RESOLU 9
#define WIDGET_SIZE_MAX (WIDGET_CURVE_RESOLU * 4)
typedef struct uiWidgetBase {
-
+ /* TODO remove these completely */
int totvert, halfwayvert;
float outer_v[WIDGET_SIZE_MAX][2];
float inner_v[WIDGET_SIZE_MAX][2];
float inner_uv[WIDGET_SIZE_MAX][2];
- bool draw_inner, draw_outline, draw_emboss, draw_shadedir;
+ bool draw_inner, draw_outline, draw_emboss;
uiWidgetTrias tria1;
uiWidgetTrias tria2;
-
+
+ /* Widget shader parameters, must match the shader layout. */
+ uiWidgetBaseParameters uniform_params;
} uiWidgetBase;
/** uiWidgetType: for time being only for visual appearance,
@@ -150,13 +161,15 @@ static const float cornervec[WIDGET_CURVE_RESOLU][2] = {
{0.924, 0.617}, {0.98, 0.805}, {1.0, 1.0}
};
-#define WIDGET_AA_JITTER 8
-static const float jit[WIDGET_AA_JITTER][2] = {
+
+const float ui_pixel_jitter[UI_PIXEL_AA_JITTER][2] = {
{ 0.468813, -0.481430}, {-0.155755, -0.352820},
{ 0.219306, -0.238501}, {-0.393286, -0.110949},
{-0.024699, 0.013908}, { 0.343805, 0.147431},
{-0.272855, 0.269918}, { 0.095909, 0.388710}
};
+#define WIDGET_AA_JITTER UI_PIXEL_AA_JITTER
+#define jit ui_pixel_jitter
/* -------------------------------------------------------------------- */
/** \name Shape Preset Data
@@ -195,8 +208,8 @@ static const uint g_shape_preset_checkmark_face[4][3] = {
{3, 2, 4}, {3, 4, 5}, {1, 0, 3}, {0, 2, 3}
};
-#define OY -0.2
-#define SC 0.35
+#define OY (-0.2 / 2)
+#define SC (0.35 * 2)
static const float g_shape_preset_hold_action_vert[6][2] = {
{-0.5 + SC, 1.0 + OY}, {0.5, 1.0 + OY}, {0.5, 0.0 + OY + SC},
};
@@ -206,52 +219,349 @@ static const uint g_shape_preset_hold_action_face[2][3] = {{2, 0, 1}, {3, 5, 4}}
/** \} */
+/* **************** Batch creations ****************** */
+/**
+ * In order to speed up UI drawing we create some batches that are then
+ * modified by specialized shaders to draw certain elements really fast.
+ * TODO: find a better place. Maybe it's own file?
+ **/
+
+/* offset in triavec[] in shader per type */
+static const int tria_ofs[ROUNDBOX_TRIA_MAX] = {
+ [ROUNDBOX_TRIA_NONE] = 0,
+ [ROUNDBOX_TRIA_ARROWS] = 0,
+ [ROUNDBOX_TRIA_SCROLL] = 6,
+ [ROUNDBOX_TRIA_MENU] = 22,
+ [ROUNDBOX_TRIA_CHECK] = 28,
+ [ROUNDBOX_TRIA_HOLD_ACTION_ARROW] = 34,
+};
+static const int tria_vcount[ROUNDBOX_TRIA_MAX] = {
+ [ROUNDBOX_TRIA_NONE] = 0,
+ [ROUNDBOX_TRIA_ARROWS] = 3,
+ [ROUNDBOX_TRIA_SCROLL] = 16,
+ [ROUNDBOX_TRIA_MENU] = 3,
+ [ROUNDBOX_TRIA_CHECK] = 6,
+ [ROUNDBOX_TRIA_HOLD_ACTION_ARROW] = 3,
+};
+
+static struct {
+ Gwn_Batch *roundbox_widget[ROUNDBOX_TRIA_MAX];
+
+ Gwn_Batch *roundbox_simple;
+ Gwn_Batch *roundbox_simple_aa;
+ Gwn_Batch *roundbox_simple_outline;
+ Gwn_Batch *roundbox_shadow;
+
+ Gwn_VertFormat format;
+ uint vflag_id;
+} g_ui_batch_cache = {{0}};
+
+static Gwn_VertFormat *vflag_format(void)
+{
+ if (g_ui_batch_cache.format.attrib_ct == 0) {
+ Gwn_VertFormat *format = &g_ui_batch_cache.format;
+ g_ui_batch_cache.vflag_id = GWN_vertformat_attr_add(format, "vflag", GWN_COMP_U32, 1, GWN_FETCH_INT);
+ }
+ return &g_ui_batch_cache.format;
+}
+
+#define INNER 0
+#define OUTLINE 1
+#define EMBOSS 2
+#define NO_AA WIDGET_AA_JITTER
+
+static void set_roundbox_vertex_data(
+ Gwn_VertBufRaw *vflag_step, uint32_t d)
+{
+ uint32_t *data = GWN_vertbuf_raw_step(vflag_step);
+ *data = d;
+}
+
+static uint32_t set_roundbox_vertex(
+ Gwn_VertBufRaw *vflag_step,
+ int corner_id, int corner_v, int jit_v, bool inner, bool emboss, int color)
+{
+ uint32_t *data = GWN_vertbuf_raw_step(vflag_step);
+ *data = corner_id;
+ *data |= corner_v << 2;
+ *data |= jit_v << 6;
+ *data |= color << 12;
+ *data |= (inner) ? (1 << 10) : 0; /* is inner vert */
+ *data |= (emboss) ? (1 << 11) : 0; /* is emboss vert */
+ return *data;
+}
+
+static uint32_t set_tria_vertex(
+ Gwn_VertBufRaw *vflag_step,
+ int tria_type, int tria_v, int tria_id, int jit_v)
+{
+ uint32_t *data = GWN_vertbuf_raw_step(vflag_step);
+ if (ELEM(tria_type, ROUNDBOX_TRIA_ARROWS, ROUNDBOX_TRIA_MENU)) {
+ tria_v += tria_id * 3;
+ }
+ *data = tria_ofs[tria_type] + tria_v;
+ *data |= jit_v << 6;
+ *data |= (tria_id == 0) ? (1 << 10) : 0; /* is first tria */
+ *data |= 1 << 14; /* is tria vert */
+ return *data;
+}
+
+static void roundbox_batch_add_tria(Gwn_VertBufRaw *vflag_step, int tria, uint32_t last_data)
+{
+ const int tria_num = ELEM(tria, ROUNDBOX_TRIA_CHECK, ROUNDBOX_TRIA_HOLD_ACTION_ARROW) ? 1 : 2;
+ /* for each tria */
+ for (int t = 0; t < tria_num; ++t) {
+ for (int j = 0; j < WIDGET_AA_JITTER; j++) {
+ /* restart */
+ set_roundbox_vertex_data(vflag_step, last_data);
+ set_tria_vertex(vflag_step, tria, 0, t, j);
+ for (int v = 0; v < tria_vcount[tria]; v++) {
+ last_data = set_tria_vertex(vflag_step, tria, v, t, j);
+ }
+ }
+ }
+}
+
+Gwn_Batch *ui_batch_roundbox_widget_get(int tria)
+{
+ if (g_ui_batch_cache.roundbox_widget[tria] == NULL) {
+ uint32_t last_data;
+ Gwn_VertBufRaw vflag_step;
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(vflag_format());
+ int vcount = WIDGET_SIZE_MAX; /* inner */
+ vcount += 2; /* restart */
+ vcount += ((WIDGET_SIZE_MAX + 1) * 2) * WIDGET_AA_JITTER; /* outline (edges) */
+ vcount += 2; /* restart */
+ vcount += ((WIDGET_CURVE_RESOLU * 2) * 2) * WIDGET_AA_JITTER; /* emboss */
+ if (tria) {
+ vcount += (tria_vcount[tria] + 2) * WIDGET_AA_JITTER; /* tria1 */
+ if (!ELEM(tria, ROUNDBOX_TRIA_CHECK, ROUNDBOX_TRIA_HOLD_ACTION_ARROW)) {
+ vcount += (tria_vcount[tria] + 2) * WIDGET_AA_JITTER; /* tria2 */
+ }
+ }
+ GWN_vertbuf_data_alloc(vbo, vcount);
+ GWN_vertbuf_attr_get_raw_data(vbo, g_ui_batch_cache.vflag_id, &vflag_step);
+ /* Inner */
+ for (int c1 = 0, c2 = 3; c1 < 2; c1++, c2--) {
+ for (int a1 = 0, a2 = WIDGET_CURVE_RESOLU -1; a2 >= 0; a1++, a2--) {
+ last_data = set_roundbox_vertex(&vflag_step, c1, a1, NO_AA, true, false, INNER);
+ last_data = set_roundbox_vertex(&vflag_step, c2, a2, NO_AA, true, false, INNER);
+ }
+ }
+ /* restart */
+ set_roundbox_vertex_data(&vflag_step, last_data);
+ set_roundbox_vertex(&vflag_step, 0, 0, 0, true, false, OUTLINE);
+ /* Outlines */
+ for (int j = 0; j < WIDGET_AA_JITTER; j++) {
+ for (int c = 0; c < 4; c++) {
+ for (int a = 0; a < WIDGET_CURVE_RESOLU; a++) {
+ set_roundbox_vertex(&vflag_step, c, a, j, true, false, OUTLINE);
+ set_roundbox_vertex(&vflag_step, c, a, j, false, false, OUTLINE);
+ }
+ }
+ /* Close the loop. */
+ set_roundbox_vertex(&vflag_step, 0, 0, j, true, false, OUTLINE);
+ last_data = set_roundbox_vertex(&vflag_step, 0, 0, j, false, false, OUTLINE);
+ }
+ /* restart */
+ set_roundbox_vertex_data(&vflag_step, last_data);
+ set_roundbox_vertex(&vflag_step, 0, 0, 0, false, false, EMBOSS);
+ /* Emboss */
+ bool rev = false; /* go back and forth : avoid degenerate triangle (but beware of backface cull) */
+ for (int j = 0; j < WIDGET_AA_JITTER; j++, rev = !rev) {
+ for (int c = (rev) ? 1 : 0; (rev) ? c >= 0 : c < 2; (rev) ? c-- : c++) {
+ int sta = (rev) ? WIDGET_CURVE_RESOLU - 1 : 0;
+ int end = WIDGET_CURVE_RESOLU;
+ for (int a = sta; (rev) ? a >= 0 : a < end; (rev) ? a-- : a++) {
+ set_roundbox_vertex(&vflag_step, c, a, j, false, false, EMBOSS);
+ last_data = set_roundbox_vertex(&vflag_step, c, a, j, false, true, EMBOSS);
+ }
+ }
+ }
+ if (tria) {
+ roundbox_batch_add_tria(&vflag_step, tria, last_data);
+ }
+ g_ui_batch_cache.roundbox_widget[tria] = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ gpu_batch_presets_register(g_ui_batch_cache.roundbox_widget[tria]);
+ }
+ return g_ui_batch_cache.roundbox_widget[tria];
+}
+
+Gwn_Batch *ui_batch_roundbox_get(bool filled, bool antialiased)
+{
+ Gwn_Batch **batch = NULL;
+
+ if (filled) {
+ if (antialiased)
+ batch = &g_ui_batch_cache.roundbox_simple_aa;
+ else
+ batch = &g_ui_batch_cache.roundbox_simple;
+ }
+ else {
+ if (antialiased)
+ BLI_assert(0); /* Use GL_LINE_SMOOTH instead!!: */
+ else
+ batch = &g_ui_batch_cache.roundbox_simple_outline;
+ }
+
+ if (*batch == NULL) {
+ uint32_t last_data;
+ Gwn_VertBufRaw vflag_step;
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(vflag_format());
+ int vcount = WIDGET_SIZE_MAX;
+ vcount += (filled) ? 2 : 0;
+ vcount *= (antialiased) ? WIDGET_AA_JITTER : 1;
+ GWN_vertbuf_data_alloc(vbo, vcount);
+ GWN_vertbuf_attr_get_raw_data(vbo, g_ui_batch_cache.vflag_id, &vflag_step);
+
+ if (filled) {
+ for (int j = 0; j < WIDGET_AA_JITTER; j++) {
+ if (!antialiased) {
+ j = NO_AA;
+ }
+ /* restart */
+ set_roundbox_vertex(&vflag_step, 0, 0, j, true, false, INNER);
+ for (int c1 = 0, c2 = 3; c1 < 2; c1++, c2--) {
+ for (int a1 = 0, a2 = WIDGET_CURVE_RESOLU -1; a2 >= 0; a1++, a2--) {
+ last_data = set_roundbox_vertex(&vflag_step, c1, a1, j, true, false, INNER);
+ last_data = set_roundbox_vertex(&vflag_step, c2, a2, j, true, false, INNER);
+ }
+ }
+ /* restart */
+ set_roundbox_vertex_data(&vflag_step, last_data);
+ if (!antialiased) {
+ break;
+ }
+ }
+ *batch = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+ else {
+ for (int j = 0; j < WIDGET_AA_JITTER; j++) {
+ if (!antialiased) {
+ j = NO_AA;
+ }
+ for (int c = 0; c < 4; c++) {
+ for (int a = 0; a < WIDGET_CURVE_RESOLU; a++) {
+ set_roundbox_vertex(&vflag_step, c, a, j, true, false, INNER);
+ }
+ }
+ if (!antialiased) {
+ break;
+ }
+ }
+ *batch = GWN_batch_create_ex(GWN_PRIM_LINE_LOOP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ }
+
+ gpu_batch_presets_register(*batch);
+ }
+ return *batch;
+}
+
+Gwn_Batch *ui_batch_roundbox_shadow_get(void)
+{
+ if (g_ui_batch_cache.roundbox_shadow == NULL) {
+ uint32_t last_data;
+ Gwn_VertBufRaw vflag_step;
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(vflag_format());
+ int vcount = (WIDGET_SIZE_MAX + 1) * 2 + 2 + WIDGET_SIZE_MAX;
+ GWN_vertbuf_data_alloc(vbo, vcount);
+ GWN_vertbuf_attr_get_raw_data(vbo, g_ui_batch_cache.vflag_id, &vflag_step);
+
+ for (int c = 0; c < 4; c++) {
+ for (int a = 0; a < WIDGET_CURVE_RESOLU; a++) {
+ set_roundbox_vertex(&vflag_step, c, a, NO_AA, true, false, INNER);
+ set_roundbox_vertex(&vflag_step, c, a, NO_AA, false, false, INNER);
+ }
+ }
+ /* close loop */
+ last_data = set_roundbox_vertex(&vflag_step, 0, 0, NO_AA, true, false, INNER);
+ last_data = set_roundbox_vertex(&vflag_step, 0, 0, NO_AA, false, false, INNER);
+ /* restart */
+ set_roundbox_vertex_data(&vflag_step, last_data);
+ set_roundbox_vertex(&vflag_step, 0, 0, NO_AA, true, false, INNER);
+ /* filled */
+ for (int c1 = 0, c2 = 3; c1 < 2; c1++, c2--) {
+ for (int a1 = 0, a2 = WIDGET_CURVE_RESOLU -1; a2 >= 0; a1++, a2--) {
+ set_roundbox_vertex(&vflag_step, c1, a1, NO_AA, true, false, INNER);
+ set_roundbox_vertex(&vflag_step, c2, a2, NO_AA, true, false, INNER);
+ }
+ }
+ g_ui_batch_cache.roundbox_shadow = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ gpu_batch_presets_register(g_ui_batch_cache.roundbox_shadow);
+ }
+ return g_ui_batch_cache.roundbox_shadow;
+}
+
+#undef INNER
+#undef OUTLINE
+#undef EMBOSS
+#undef NO_AA
+
/* ************************************************* */
-void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3)
+void UI_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3,
+ const float color[4])
{
float tri_arr[3][2] = {{x1, y1}, {x2, y2}, {x3, y3}};
- float color[4];
- int j;
-
+ float draw_color[4];
+
+ copy_v4_v4(draw_color, color);
+ /* Note: This won't give back the original color. */
+ draw_color[3] *= 1.0f / WIDGET_AA_JITTER;
+
glEnable(GL_BLEND);
- glGetFloatv(GL_CURRENT_COLOR, color);
- color[3] *= 0.125f;
- glColor4fv(color);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, tri_arr);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4fv(draw_color);
+ immBegin(GWN_PRIM_TRIS, 3 * WIDGET_AA_JITTER);
/* for each AA step */
- for (j = 0; j < WIDGET_AA_JITTER; j++) {
- glTranslate2fv(jit[j]);
- glDrawArrays(GL_TRIANGLES, 0, 3);
- glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
+ for (int j = 0; j < WIDGET_AA_JITTER; j++) {
+ immVertex2f(pos, tri_arr[0][0] + jit[j][0], tri_arr[0][1] + jit[j][1]);
+ immVertex2f(pos, tri_arr[1][0] + jit[j][0], tri_arr[1][1] + jit[j][1]);
+ immVertex2f(pos, tri_arr[2][0] + jit[j][0], tri_arr[2][1] + jit[j][1]);
}
- glDisableClientState(GL_VERTEX_ARRAY);
+ immEnd();
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
-void ui_draw_anti_roundbox(int mode, float minx, float miny, float maxx, float maxy, float rad, bool use_alpha)
+void UI_draw_anti_fan(float tri_array[][2], unsigned int length, const float color[4])
{
- float color[4];
- int j;
-
+ float draw_color[4];
+
+ copy_v4_v4(draw_color, color);
+ draw_color[3] *= 2.0f / WIDGET_AA_JITTER;
+
glEnable(GL_BLEND);
- glGetFloatv(GL_CURRENT_COLOR, color);
- if (use_alpha) {
- color[3] = 0.5f;
- }
- color[3] *= 0.125f;
- glColor4fv(color);
-
- for (j = 0; j < WIDGET_AA_JITTER; j++) {
- glTranslate2fv(jit[j]);
- UI_draw_roundbox_gl_mode(mode, minx, miny, maxx, maxy, rad);
- glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4fv(draw_color);
+
+ /* for each AA step */
+ for (int j = 0; j < WIDGET_AA_JITTER; j++) {
+ immBegin(GWN_PRIM_TRI_FAN, length);
+ immVertex2f(pos, tri_array[0][0], tri_array[0][1]);
+ immVertex2f(pos, tri_array[1][0], tri_array[1][1]);
+
+ /* We jitter only the middle of the fan, the extremes are pinned. */
+ for (int i = 2; i < length - 1; i++) {
+ immVertex2f(pos, tri_array[i][0] + jit[j][0], tri_array[i][1] + jit[j][1]);
+ }
+
+ immVertex2f(pos, tri_array[length - 1][0], tri_array[length - 1][1]);
+ immEnd();
}
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
@@ -260,11 +570,16 @@ static void widget_init(uiWidgetBase *wtb)
wtb->totvert = wtb->halfwayvert = 0;
wtb->tria1.tot = 0;
wtb->tria2.tot = 0;
+ wtb->tria1.type = ROUNDBOX_TRIA_NONE;
+ wtb->tria1.size = 0;
+ wtb->tria2.size = 0;
wtb->draw_inner = true;
wtb->draw_outline = true;
wtb->draw_emboss = true;
- wtb->draw_shadedir = true;
+
+ wtb->uniform_params.shade_dir = 1.0f;
+ wtb->uniform_params.alpha_discard = 1.0f;
}
/* helper call, makes shadow rect, with 'sun' above menu, so only shadow to left/right/bottom */
@@ -371,7 +686,18 @@ static void round_box__edges(uiWidgetBase *wt, int roundboxalign, const rcti *re
if (2.0f * (radi + 1.0f) > minsize)
radi = 0.5f * minsize - U.pixelsize;
-
+
+ wt->uniform_params.rad = rad;
+ wt->uniform_params.radi = radi;
+ wt->uniform_params.facxi = facxi;
+ wt->uniform_params.facyi = facyi;
+ wt->uniform_params.round_corners[0] = (roundboxalign & UI_CNR_BOTTOM_LEFT) ? 1.0f : 0.0f;
+ wt->uniform_params.round_corners[1] = (roundboxalign & UI_CNR_BOTTOM_RIGHT) ? 1.0f : 0.0f;
+ wt->uniform_params.round_corners[2] = (roundboxalign & UI_CNR_TOP_RIGHT) ? 1.0f : 0.0f;
+ wt->uniform_params.round_corners[3] = (roundboxalign & UI_CNR_TOP_LEFT) ? 1.0f : 0.0f;
+ BLI_rctf_rcti_copy(&wt->uniform_params.rect, rect);
+ BLI_rctf_init(&wt->uniform_params.recti, minxi, maxxi, minyi, maxyi);
+
/* mult */
for (a = 0; a < WIDGET_CURVE_RESOLU; a++) {
veci[a][0] = radi * cornervec[a][0];
@@ -516,23 +842,30 @@ static void shape_preset_init_trias_ex(
float centx, centy, sizex, sizey, minsize;
int a, i1 = 0, i2 = 1;
- minsize = min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect));
+ if (where == 'r' || where == 'l') {
+ minsize = BLI_rcti_size_y(rect);
+ }
+ else {
+ minsize = BLI_rcti_size_x(rect);
+ }
/* center position and size */
centx = (float)rect->xmin + 0.4f * minsize;
centy = (float)rect->ymin + 0.5f * minsize;
- sizex = sizey = -0.5f * triasize * minsize;
+ tria->size = sizex = sizey = -0.5f * triasize * minsize;
if (where == 'r') {
centx = (float)rect->xmax - 0.4f * minsize;
sizex = -sizex;
}
else if (where == 't') {
+ centx = (float)rect->xmin + 0.5f * minsize;
centy = (float)rect->ymax - 0.5f * minsize;
sizey = -sizey;
i2 = 0; i1 = 1;
}
else if (where == 'b') {
+ centx = (float)rect->xmin + 0.5f * minsize;
sizex = -sizex;
i2 = 0; i1 = 1;
}
@@ -542,12 +875,16 @@ static void shape_preset_init_trias_ex(
tria->vec[a][1] = sizey * verts[a][i2] + centy;
}
+ tria->center[0] = centx;
+ tria->center[1] = centy;
+
tria->tot = tris_tot;
tria->index = tris;
}
static void shape_preset_init_number_arrows(uiWidgetTrias *tria, const rcti *rect, float triasize, char where)
{
+ tria->type = ROUNDBOX_TRIA_ARROWS;
shape_preset_init_trias_ex(
tria, rect, triasize, where,
g_shape_preset_number_arrow_vert, ARRAY_SIZE(g_shape_preset_number_arrow_vert),
@@ -556,6 +893,12 @@ static void shape_preset_init_number_arrows(uiWidgetTrias *tria, const rcti *rec
static void shape_preset_init_hold_action(uiWidgetTrias *tria, const rcti *rect, float triasize, char where)
{
+ tria->type = ROUNDBOX_TRIA_HOLD_ACTION_ARROW;
+ /* With the current changes to use batches for widget drawing, the code
+ * below is doing almost nothing effectively. 'where' doesn't work either,
+ * shader is currently hardcoded to work for the button triangle pointing
+ * at the lower right. The same limitation applies to other trias as well.
+ * XXX Should be addressed. */
shape_preset_init_trias_ex(
tria, rect, triasize, where,
g_shape_preset_hold_action_vert, ARRAY_SIZE(g_shape_preset_hold_action_vert),
@@ -564,29 +907,37 @@ static void shape_preset_init_hold_action(uiWidgetTrias *tria, const rcti *rect,
static void shape_preset_init_scroll_circle(uiWidgetTrias *tria, const rcti *rect, float triasize, char where)
{
+ tria->type = ROUNDBOX_TRIA_SCROLL;
shape_preset_init_trias_ex(
tria, rect, triasize, where,
g_shape_preset_scroll_circle_vert, ARRAY_SIZE(g_shape_preset_scroll_circle_vert),
g_shape_preset_scroll_circle_face, ARRAY_SIZE(g_shape_preset_scroll_circle_face));
}
-static void shape_preset_draw_trias(uiWidgetTrias *tria)
+static void widget_draw_vertex_buffer(unsigned int pos, unsigned int col, int mode,
+ const float quads_pos[WIDGET_SIZE_MAX][2],
+ const unsigned char quads_col[WIDGET_SIZE_MAX][4],
+ unsigned int totvert)
{
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, tria->vec);
- glDrawElements(GL_TRIANGLES, tria->tot * 3, GL_UNSIGNED_INT, tria->index);
- glDisableClientState(GL_VERTEX_ARRAY);
+ immBegin(mode, totvert);
+ for (int i = 0; i < totvert; ++i) {
+ if (quads_col)
+ immAttrib4ubv(col, quads_col[i]);
+ immVertex2fv(pos, quads_pos[i]);
+ }
+ immEnd();
}
static void shape_preset_trias_from_rect_menu(uiWidgetTrias *tria, const rcti *rect)
{
float centx, centy, size;
int a;
+ tria->type = ROUNDBOX_TRIA_MENU;
/* center position and size */
- centx = rect->xmax - 0.32f * BLI_rcti_size_y(rect);
- centy = rect->ymin + 0.50f * BLI_rcti_size_y(rect);
- size = 0.4f * BLI_rcti_size_y(rect);
+ tria->center[0] = centx = rect->xmax - 0.32f * BLI_rcti_size_y(rect);
+ tria->center[1] = centy = rect->ymin + 0.50f * BLI_rcti_size_y(rect);
+ tria->size = size = 0.4f * BLI_rcti_size_y(rect);
for (a = 0; a < 6; a++) {
tria->vec[a][0] = size * g_shape_preset_menu_arrow_vert[a][0] + centx;
@@ -601,11 +952,12 @@ static void shape_preset_trias_from_rect_checkmark(uiWidgetTrias *tria, const rc
{
float centx, centy, size;
int a;
+ tria->type = ROUNDBOX_TRIA_CHECK;
/* center position and size */
- centx = rect->xmin + 0.5f * BLI_rcti_size_y(rect);
- centy = rect->ymin + 0.5f * BLI_rcti_size_y(rect);
- size = 0.5f * BLI_rcti_size_y(rect);
+ tria->center[0] = centx = rect->xmin + 0.5f * BLI_rcti_size_y(rect);
+ tria->center[1] = centy = rect->ymin + 0.5f * BLI_rcti_size_y(rect);
+ tria->size = size = 0.5f * BLI_rcti_size_y(rect);
for (a = 0; a < 6; a++) {
tria->vec[a][0] = size * g_shape_preset_checkmark_vert[a][0] + centx;
@@ -655,180 +1007,210 @@ static void widget_verts_to_triangle_strip(uiWidgetBase *wtb, const int totvert,
copy_v2_v2(triangle_strip[a * 2 + 1], wtb->inner_v[0]);
}
-static void widget_verts_to_triangle_strip_open(uiWidgetBase *wtb, const int totvert, float triangle_strip[WIDGET_SIZE_MAX * 2][2])
+static void widgetbase_outline(uiWidgetBase *wtb, unsigned int pos)
{
- int a;
- for (a = 0; a < totvert; a++) {
- triangle_strip[a * 2][0] = wtb->outer_v[a][0];
- triangle_strip[a * 2][1] = wtb->outer_v[a][1];
- triangle_strip[a * 2 + 1][0] = wtb->outer_v[a][0];
- triangle_strip[a * 2 + 1][1] = wtb->outer_v[a][1] - 1.0f;
+ float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
+ widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip);
+
+ widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_STRIP, triangle_strip, NULL, wtb->totvert * 2 + 2);
+}
+
+static void widgetbase_set_uniform_alpha_discard(
+ uiWidgetBase *wtb,
+ const bool alpha_check,
+ const float discard_factor)
+{
+ if (alpha_check) {
+ wtb->uniform_params.alpha_discard = -discard_factor;
+ }
+ else {
+ wtb->uniform_params.alpha_discard = discard_factor;
}
}
-static void widgetbase_outline(uiWidgetBase *wtb)
+static void widgetbase_set_uniform_alpha_check(
+ uiWidgetBase *wtb,
+ const bool alpha_check)
{
- float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
- widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip);
+ const float discard_factor = fabs(wtb->uniform_params.alpha_discard);
+ widgetbase_set_uniform_alpha_discard(wtb, alpha_check, discard_factor);
+}
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2);
- glDisableClientState(GL_VERTEX_ARRAY);
+static void widgetbase_set_uniform_discard_factor(
+ uiWidgetBase *wtb,
+ const float discard_factor)
+{
+ bool alpha_check = wtb->uniform_params.alpha_discard < 0.0f;
+ widgetbase_set_uniform_alpha_discard(wtb, alpha_check, discard_factor);
}
-static void widgetbase_draw(uiWidgetBase *wtb, uiWidgetColors *wcol)
+static void widgetbase_set_uniform_colors_ubv(
+ uiWidgetBase *wtb,
+ const unsigned char *col1, const unsigned char *col2,
+ const unsigned char *outline,
+ const unsigned char *emboss,
+ const unsigned char *tria,
+ const bool alpha_check)
{
- int j, a;
-
- glEnable(GL_BLEND);
+ widgetbase_set_uniform_alpha_check(wtb, alpha_check);
+ rgba_float_args_set_ch(wtb->uniform_params.color_inner1, col1[0], col1[1], col1[2], col1[3]);
+ rgba_float_args_set_ch(wtb->uniform_params.color_inner2, col2[0], col2[1], col2[2], col2[3]);
+ rgba_float_args_set_ch(wtb->uniform_params.color_outline, outline[0], outline[1], outline[2], outline[3]);
+ rgba_float_args_set_ch(wtb->uniform_params.color_emboss, emboss[0], emboss[1], emboss[2], emboss[3]);
+ rgba_float_args_set_ch(wtb->uniform_params.color_tria, tria[0], tria[1], tria[2], tria[3]);
+}
- /* backdrop non AA */
- if (wtb->draw_inner) {
- BLI_assert(wtb->totvert != 0);
- if (wcol->shaded == 0) {
- if (wcol->alpha_check) {
- float inner_v_half[WIDGET_SIZE_MAX][2];
- float x_mid = 0.0f; /* used for dumb clamping of values */
+/* keep in sync with shader */
+#define MAX_WIDGET_BASE_BATCH 6
+#define MAX_WIDGET_PARAMETERS 11
- /* dark checkers */
- glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
- glDrawArrays(GL_POLYGON, 0, wtb->totvert);
+struct {
+ Gwn_Batch *batch; /* Batch type */
+ uiWidgetBaseParameters params[MAX_WIDGET_BASE_BATCH];
+ int count;
+ bool enabled;
+} g_widget_base_batch = {0};
- /* light checkers */
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
+void UI_widgetbase_draw_cache_flush(void)
+{
+ float checker_params[3] = {UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 8.0f};
- glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
- glDrawArrays(GL_POLYGON, 0, wtb->totvert);
+ if (g_widget_base_batch.count == 0)
+ return;
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ Gwn_Batch *batch = g_widget_base_batch.batch;
+ if (g_widget_base_batch.count == 1) {
+ /* draw single */
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
+ GWN_batch_uniform_4fv_array(batch, "parameters", MAX_WIDGET_PARAMETERS, (float *)g_widget_base_batch.params);
+ GWN_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
+ GWN_batch_draw(batch);
+ }
+ else {
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE_INST);
+ GWN_batch_uniform_4fv_array(batch, "parameters", MAX_WIDGET_PARAMETERS * MAX_WIDGET_BASE_BATCH,
+ (float *)g_widget_base_batch.params);
+ GWN_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
+ gpuBindMatrices(batch->interface);
+ GWN_batch_draw_range_ex(batch, 0, g_widget_base_batch.count, true);
+ GWN_batch_program_use_end(batch);
+ }
+ g_widget_base_batch.count = 0;
+}
- /* alpha fill */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+void UI_widgetbase_draw_cache_begin(void)
+{
+ BLI_assert(g_widget_base_batch.enabled == false);
+ g_widget_base_batch.enabled = true;
+}
- glColor4ubv((unsigned char *)wcol->inner);
+void UI_widgetbase_draw_cache_end(void)
+{
+ BLI_assert(g_widget_base_batch.enabled == true);
+ g_widget_base_batch.enabled = false;
- for (a = 0; a < wtb->totvert; a++) {
- x_mid += wtb->inner_v[a][0];
- }
- x_mid /= wtb->totvert;
+ glEnable(GL_BLEND);
- glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
- glDrawArrays(GL_POLYGON, 0, wtb->totvert);
+ UI_widgetbase_draw_cache_flush();
- /* 1/2 solid color */
- glColor4ub(wcol->inner[0], wcol->inner[1], wcol->inner[2], 255);
+ glDisable(GL_BLEND);
+}
- for (a = 0; a < wtb->totvert; a++) {
- inner_v_half[a][0] = MIN2(wtb->inner_v[a][0], x_mid);
- inner_v_half[a][1] = wtb->inner_v[a][1];
- }
+static void draw_widgetbase_batch(Gwn_Batch *batch, uiWidgetBase *wtb)
+{
+ wtb->uniform_params.tria1_size = wtb->tria1.size;
+ wtb->uniform_params.tria2_size = wtb->tria2.size;
+ copy_v2_v2(wtb->uniform_params.tria1_center, wtb->tria1.center);
+ copy_v2_v2(wtb->uniform_params.tria2_center, wtb->tria2.center);
+
+ if (g_widget_base_batch.enabled) {
+ if (g_widget_base_batch.batch == NULL) {
+ g_widget_base_batch.batch = ui_batch_roundbox_widget_get(ROUNDBOX_TRIA_ARROWS);
+ }
- glVertexPointer(2, GL_FLOAT, 0, inner_v_half);
- glDrawArrays(GL_POLYGON, 0, wtb->totvert);
- glDisableClientState(GL_VERTEX_ARRAY);
- }
- else {
- /* simple fill */
- glColor4ubv((unsigned char *)wcol->inner);
+ /* draw multi */
+ if (batch != g_ui_batch_cache.roundbox_widget[ROUNDBOX_TRIA_NONE] &&
+ batch != g_widget_base_batch.batch)
+ {
+ /* issue previous calls before changing batch type. */
+ UI_widgetbase_draw_cache_flush();
+ g_widget_base_batch.batch = batch;
+ }
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
- glDrawArrays(GL_POLYGON, 0, wtb->totvert);
- glDisableClientState(GL_VERTEX_ARRAY);
- }
+ /* No need to change batch if tria is not visible. Just scale it to 0. */
+ if (batch == g_ui_batch_cache.roundbox_widget[ROUNDBOX_TRIA_NONE]) {
+ wtb->uniform_params.tria1_size = wtb->uniform_params.tria2_size = 0;
}
- else {
- char col1[4], col2[4];
- unsigned char col_array[WIDGET_SIZE_MAX * 4];
- unsigned char *col_pt = col_array;
-
- shadecolors4(col1, col2, wcol->inner, wcol->shadetop, wcol->shadedown);
- for (a = 0; a < wtb->totvert; a++, col_pt += 4) {
- round_box_shade_col4_r(col_pt, col1, col2, wtb->inner_uv[a][wtb->draw_shadedir ? 1 : 0]);
- }
+ g_widget_base_batch.params[g_widget_base_batch.count] = wtb->uniform_params;
+ g_widget_base_batch.count++;
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, wtb->inner_v);
- glColorPointer(4, GL_UNSIGNED_BYTE, 0, col_array);
- glDrawArrays(GL_POLYGON, 0, wtb->totvert);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
+ if (g_widget_base_batch.count == MAX_WIDGET_BASE_BATCH) {
+ UI_widgetbase_draw_cache_flush();
}
}
-
- /* for each AA step */
- if (wtb->draw_outline) {
- BLI_assert(wtb->totvert != 0);
- float triangle_strip[WIDGET_SIZE_MAX * 2 + 2][2]; /* + 2 because the last pair is wrapped */
- float triangle_strip_emboss[WIDGET_SIZE_MAX * 2][2]; /* only for emboss */
+ else {
+ float checker_params[3] = {UI_ALPHA_CHECKER_DARK / 255.0f, UI_ALPHA_CHECKER_LIGHT / 255.0f, 8.0f};
+ /* draw single */
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_WIDGET_BASE);
+ GWN_batch_uniform_4fv_array(batch, "parameters", 11, (float *)&wtb->uniform_params);
+ GWN_batch_uniform_3fv(batch, "checkerColorAndSize", checker_params);
+ GWN_batch_draw(batch);
+ }
+}
- const unsigned char tcol[4] = {wcol->outline[0],
- wcol->outline[1],
- wcol->outline[2],
- wcol->outline[3] / WIDGET_AA_JITTER};
- unsigned char emboss[4];
+static void widgetbase_draw(uiWidgetBase *wtb, const uiWidgetColors *wcol)
+{
+ unsigned char inner_col1[4] = {0};
+ unsigned char inner_col2[4] = {0};
+ unsigned char emboss_col[4] = {0};
+ unsigned char outline_col[4] = {0};
+ unsigned char tria_col[4] = {0};
+ /* For color widget. */
+ bool alpha_check = (wcol->alpha_check && (wcol->shaded == 0));
- widget_verts_to_triangle_strip(wtb, wtb->totvert, triangle_strip);
+ glEnable(GL_BLEND);
- if (wtb->draw_emboss) {
- widget_verts_to_triangle_strip_open(wtb, wtb->halfwayvert, triangle_strip_emboss);
- UI_GetThemeColor4ubv(TH_WIDGET_EMBOSS, emboss);
+ /* backdrop non AA */
+ if (wtb->draw_inner) {
+ if (wcol->shaded == 0) {
+ /* simple fill */
+ inner_col1[0] = inner_col2[0] = (unsigned char)wcol->inner[0];
+ inner_col1[1] = inner_col2[1] = (unsigned char)wcol->inner[1];
+ inner_col1[2] = inner_col2[2] = (unsigned char)wcol->inner[2];
+ inner_col1[3] = inner_col2[3] = (unsigned char)wcol->inner[3];
+ }
+ else {
+ /* gradient fill */
+ shadecolors4((char *)inner_col1, (char *)inner_col2, wcol->inner, wcol->shadetop, wcol->shadedown);
}
+ }
- glEnableClientState(GL_VERTEX_ARRAY);
+ if (wtb->draw_outline) {
+ outline_col[0] = wcol->outline[0];
+ outline_col[1] = wcol->outline[1];
+ outline_col[2] = wcol->outline[2];
+ outline_col[3] = wcol->outline[3] / WIDGET_AA_JITTER;
- for (j = 0; j < WIDGET_AA_JITTER; j++) {
- glTranslate2fv(jit[j]);
-
- /* outline */
- glColor4ubv(tcol);
-
- glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->totvert * 2 + 2);
-
- /* emboss bottom shadow */
- if (wtb->draw_emboss) {
- if (emboss[3]) {
- glColor4ubv(emboss);
- glVertexPointer(2, GL_FLOAT, 0, triangle_strip_emboss);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, wtb->halfwayvert * 2);
- }
- }
-
- glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
+ /* emboss bottom shadow */
+ if (wtb->draw_emboss) {
+ UI_GetThemeColor4ubv(TH_WIDGET_EMBOSS, emboss_col);
}
+ }
- glDisableClientState(GL_VERTEX_ARRAY);
+ if (wtb->tria1.type != ROUNDBOX_TRIA_NONE) {
+ tria_col[0] = wcol->item[0];
+ tria_col[1] = wcol->item[1];
+ tria_col[2] = wcol->item[2];
+ tria_col[3] = (unsigned char)((float)wcol->item[3] / WIDGET_AA_JITTER);
}
-
- /* decoration */
- if (wtb->tria1.tot || wtb->tria2.tot) {
- const unsigned char tcol[4] = {wcol->item[0],
- wcol->item[1],
- wcol->item[2],
- (unsigned char)((float)wcol->item[3] / WIDGET_AA_JITTER)};
- glColor4ubv(tcol);
-
- /* for each AA step */
- for (j = 0; j < WIDGET_AA_JITTER; j++) {
- glTranslate2fv(jit[j]);
-
- if (wtb->tria1.tot) {
- shape_preset_draw_trias(&wtb->tria1);
- }
- if (wtb->tria2.tot) {
- shape_preset_draw_trias(&wtb->tria2);
- }
- glTranslatef(-jit[j][0], -jit[j][1], 0.0f);
- }
+ /* Draw everything in one drawcall */
+ if (inner_col1[3] || inner_col2[3] || outline_col[3] || emboss_col[3] || tria_col[3] || alpha_check) {
+ widgetbase_set_uniform_colors_ubv(wtb, inner_col1, inner_col2, outline_col, emboss_col, tria_col, alpha_check);
+
+ Gwn_Batch *roundbox_batch = ui_batch_roundbox_widget_get(wtb->tria1.type);
+ draw_widgetbase_batch(roundbox_batch, wtb);
}
glDisable(GL_BLEND);
@@ -913,7 +1295,7 @@ static void widget_draw_icon_ex(
if (but->drawflag & UI_BUT_ICON_LEFT) {
/* special case - icon_only pie buttons */
- if (ui_block_is_pie_menu(but->block) && but->type != UI_BTYPE_MENU && but->str && but->str[0] == '\0')
+ if (ui_block_is_pie_menu(but->block) && !ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_POPOVER) && but->str && but->str[0] == '\0')
xs = rect->xmin + 2.0f * ofs;
else if (but->dt == UI_EMBOSS_NONE || but->type == UI_BTYPE_LABEL)
xs = rect->xmin + 2.0f * ofs;
@@ -930,14 +1312,19 @@ static void widget_draw_icon_ex(
xs = (int)(xs + 0.1f);
ys = (int)(ys + 0.1f);
}
-
+
/* to indicate draggable */
if (but->dragpoin && (but->flag & UI_ACTIVE)) {
float rgb[3] = {1.25f, 1.25f, 1.25f};
UI_icon_draw_aspect_color(xs, ys, icon, aspect, rgb);
}
- else
+ else if ((but->flag & (UI_ACTIVE | UI_SELECT | UI_SELECT_DRAW)) || !UI_but_is_tool(but)) {
UI_icon_draw_aspect(xs, ys, icon, aspect, alpha);
+ }
+ else {
+ const bTheme *btheme = UI_GetTheme();
+ UI_icon_draw_desaturate(xs, ys, icon, aspect, alpha, 1.0 - btheme->tui.icon_saturation);
+ }
}
if (show_menu_icon) {
@@ -1122,7 +1509,7 @@ float UI_text_clip_middle_ex(
static void ui_text_clip_middle(uiFontStyle *fstyle, uiBut *but, const rcti *rect)
{
/* No margin for labels! */
- const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f);
+ const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU, UI_BTYPE_POPOVER) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f);
const float okwidth = (float)max_ii(BLI_rcti_size_x(rect) - border, 0);
const size_t max_len = sizeof(but->drawstr);
const float minwidth = (float)(UI_DPI_ICON_SIZE) / but->block->aspect * 2.0f;
@@ -1138,7 +1525,7 @@ static void ui_text_clip_middle(uiFontStyle *fstyle, uiBut *but, const rcti *rec
static void ui_text_clip_middle_protect_right(uiFontStyle *fstyle, uiBut *but, const rcti *rect, const char rsep)
{
/* No margin for labels! */
- const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f);
+ const int border = ELEM(but->type, UI_BTYPE_LABEL, UI_BTYPE_MENU, UI_BTYPE_POPOVER) ? 0 : (int)(UI_TEXT_CLIP_MARGIN + 0.5f);
const float okwidth = (float)max_ii(BLI_rcti_size_x(rect) - border, 0);
const size_t max_len = sizeof(but->drawstr);
const float minwidth = (float)(UI_DPI_ICON_SIZE) / but->block->aspect * 2.0f;
@@ -1290,6 +1677,7 @@ static void widget_draw_text_ime_underline(
int ofs_x, width;
int rect_x = BLI_rcti_size_x(rect);
int sel_start = ime_data->sel_start, sel_end = ime_data->sel_end;
+ float fcol[4];
if (drawstr[0] != 0) {
if (but->pos >= but->ofs) {
@@ -1302,8 +1690,8 @@ static void widget_draw_text_ime_underline(
width = BLF_width(fstyle->uifont_id, drawstr + but->ofs,
ime_data->composite_len + but->pos - but->ofs);
- glColor4ubv((unsigned char *)wcol->text);
- UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 1);
+ rgba_uchar_to_float(fcol, wcol->text);
+ UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 1, fcol);
/* draw the thick line */
if (sel_start != -1 && sel_end != -1) {
@@ -1320,7 +1708,7 @@ static void widget_draw_text_ime_underline(
width = BLF_width(fstyle->uifont_id, drawstr + but->ofs,
sel_end + sel_start - but->ofs);
- UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 2);
+ UI_draw_text_underline(rect->xmin + ofs_x, rect->ymin + 6 * U.pixelsize, min_ii(width, rect_x - 2) - ofs_x, 2, fcol);
}
}
}
@@ -1394,6 +1782,10 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
int selsta_draw, selwidth_draw;
if (drawstr[0] != 0) {
+ /* We are drawing on top of widget bases. Flush cache. */
+ glEnable(GL_BLEND);
+ UI_widgetbase_draw_cache_flush();
+ glDisable(GL_BLEND);
if (but->selsta >= but->ofs) {
selsta_draw = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but->selsta - but->ofs);
@@ -1404,11 +1796,16 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
selwidth_draw = BLF_width(fstyle->uifont_id, drawstr + but->ofs, but->selend - but->ofs);
- glColor4ubv((unsigned char *)wcol->item);
- glRecti(rect->xmin + selsta_draw,
- rect->ymin + 2,
- min_ii(rect->xmin + selwidth_draw, rect->xmax - 2),
- rect->ymax - 2);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4ubv((unsigned char *)wcol->item);
+ immRecti(pos, rect->xmin + selsta_draw,
+ rect->ymin + 2,
+ min_ii(rect->xmin + selwidth_draw, rect->xmax - 2),
+ rect->ymax - 2);
+
+ immUnbindProgram();
}
}
@@ -1430,14 +1827,23 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
else {
t = 0;
}
+ /* We are drawing on top of widget bases. Flush cache. */
+ glEnable(GL_BLEND);
+ UI_widgetbase_draw_cache_flush();
+ glDisable(GL_BLEND);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glColor3f(0.2, 0.6, 0.9);
+ immUniformColor3f(0.2f, 0.6f, 0.9f);
tx = rect->xmin + t + 2;
ty = rect->ymin + 2;
/* draw cursor */
- glRecti(rect->xmin + t, ty, tx, rect->ymax - 2);
+ immRecti(pos, rect->xmin + t, ty, tx, rect->ymax - 2);
+
+ immUnbindProgram();
}
#ifdef WITH_INPUT_IME
@@ -1496,43 +1902,46 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
}
#endif
- glColor4ubv((unsigned char *)wcol->text);
-
if (!use_right_only) {
/* for underline drawing */
float font_xofs, font_yofs;
- UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs,
- drawstr_left_len - but->ofs, &font_xofs, &font_yofs);
+ int drawlen = (drawstr_left_len == INT_MAX) ? strlen(drawstr + but->ofs) : (drawstr_left_len - but->ofs);
- if (but->menu_key != '\0') {
- char fixedbuf[128];
- const char *str;
+ if (drawlen > 0) {
+ UI_fontstyle_draw_ex(fstyle, rect, drawstr + but->ofs, (unsigned char *)wcol->text,
+ drawlen, &font_xofs, &font_yofs);
- BLI_strncpy(fixedbuf, drawstr + but->ofs, min_ii(sizeof(fixedbuf), drawstr_left_len));
+ if (but->menu_key != '\0') {
+ char fixedbuf[128];
+ const char *str;
- str = strchr(fixedbuf, but->menu_key - 32); /* upper case */
- if (str == NULL)
- str = strchr(fixedbuf, but->menu_key);
+ BLI_strncpy(fixedbuf, drawstr + but->ofs, min_ii(sizeof(fixedbuf), drawlen));
- if (str) {
- int ul_index = -1;
- float ul_advance;
+ str = strchr(fixedbuf, but->menu_key - 32); /* upper case */
+ if (str == NULL)
+ str = strchr(fixedbuf, but->menu_key);
- ul_index = (int)(str - fixedbuf);
+ if (str) {
+ int ul_index = -1;
+ float ul_advance;
- if (fstyle->kerning == 1) {
- BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
- }
+ ul_index = (int)(str - fixedbuf);
+
+ if (fstyle->kerning == 1) {
+ BLF_enable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
+ }
- fixedbuf[ul_index] = '\0';
- ul_advance = BLF_width(fstyle->uifont_id, fixedbuf, ul_index);
+ fixedbuf[ul_index] = '\0';
+ ul_advance = BLF_width(fstyle->uifont_id, fixedbuf, ul_index);
- BLF_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f);
- BLF_draw(fstyle->uifont_id, "_", 2);
+ BLF_position(fstyle->uifont_id, rect->xmin + font_xofs + ul_advance, rect->ymin + font_yofs, 0.0f);
+ BLF_color4ubv(fstyle->uifont_id, (unsigned char *)wcol->text);
+ BLF_draw(fstyle->uifont_id, "_", 2);
- if (fstyle->kerning == 1) {
- BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
+ if (fstyle->kerning == 1) {
+ BLF_disable(fstyle->uifont_id, BLF_KERNING_DEFAULT);
+ }
}
}
}
@@ -1542,7 +1951,7 @@ static void widget_draw_text(uiFontStyle *fstyle, uiWidgetColors *wcol, uiBut *b
if (drawstr_right) {
fstyle->align = UI_STYLE_TEXT_RIGHT;
rect->xmax -= UI_TEXT_CLIP_MARGIN;
- UI_fontstyle_draw(fstyle, rect, drawstr_right);
+ UI_fontstyle_draw(fstyle, rect, drawstr_right, (unsigned char *)wcol->text);
}
}
@@ -1557,7 +1966,7 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
ui_but_text_password_hide(password_str, but, false);
/* check for button text label */
- if (but->type == UI_BTYPE_MENU && (but->flag & UI_BUT_NODE_LINK)) {
+ if (ELEM(but->type, UI_BTYPE_MENU, UI_BTYPE_POPOVER) && (but->flag & UI_BUT_NODE_LINK)) {
rcti temp = *rect;
temp.xmin = rect->xmax - BLI_rcti_size_y(rect) - 1;
widget_draw_icon(but, ICON_LAYER_USED, alpha, &temp, false);
@@ -1595,12 +2004,26 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
}
/* Icons on the left with optional text label on the right */
else if (but->flag & UI_HAS_ICON || show_menu_icon) {
+ const bool is_tool = UI_but_is_tool(but);
+
const BIFIconID icon = (but->flag & UI_HAS_ICON) ? but->icon + but->iconadd : ICON_NONE;
- const float icon_size = ICON_DEFAULT_WIDTH_SCALE;
+ int icon_size_init = is_tool ? ICON_DEFAULT_HEIGHT_TOOLBAR : ICON_DEFAULT_HEIGHT;
+ const float icon_size = icon_size_init / (but->block->aspect / UI_DPI_FAC);
+
+#ifdef USE_TOOLBAR_HACK
+ if (is_tool) {
+ /* pass (even if its a menu toolbar) */
+ but->drawflag |= UI_BUT_TEXT_LEFT;
+ but->drawflag |= UI_BUT_ICON_LEFT;
+ }
+#endif
/* menu item - add some more padding so menus don't feel cramped. it must
* be part of the button so that this area is still clickable */
- if (ui_block_is_pie_menu(but->block)) {
+ if (is_tool) {
+ /* pass (even if its a menu toolbar) */
+ }
+ else if (ui_block_is_pie_menu(but->block)) {
if (but->dt == UI_EMBOSS_RADIAL)
rect->xmin += 0.3f * U.widget_unit;
}
@@ -1666,6 +2089,9 @@ static void widget_draw_text_icon(uiFontStyle *fstyle, uiWidgetColors *wcol, uiB
widget_draw_text(fstyle, wcol, but, rect);
ui_but_text_password_hide(password_str, but, true);
+
+ /* if a widget uses font shadow it has to be deactivated now */
+ BLF_disable(fstyle->uifont_id, BLF_SHADOW);
}
#undef UI_TEXT_CLIP_MARGIN
@@ -1680,6 +2106,8 @@ static struct uiWidgetStateColors wcol_state_colors = {
{215, 211, 75, 255},
{180, 0, 255, 255},
{153, 0, 230, 255},
+ {74, 137, 137, 255},
+ {49, 112, 112, 255},
0.5f, 0.0f
};
@@ -1693,7 +2121,9 @@ static struct uiWidgetColors wcol_num = {
{255, 255, 255, 255},
1,
- -20, 0
+ -20, 0,
+ 0,
+ 0.5f,
};
static struct uiWidgetColors wcol_numslider = {
@@ -1706,7 +2136,9 @@ static struct uiWidgetColors wcol_numslider = {
{255, 255, 255, 255},
1,
- -20, 0
+ -20, 0,
+ 0,
+ 0.5f,
};
static struct uiWidgetColors wcol_text = {
@@ -1719,7 +2151,9 @@ static struct uiWidgetColors wcol_text = {
{255, 255, 255, 255},
1,
- 0, 25
+ 0, 25,
+ 0,
+ 0.2f,
};
static struct uiWidgetColors wcol_option = {
@@ -1732,7 +2166,9 @@ static struct uiWidgetColors wcol_option = {
{255, 255, 255, 255},
1,
- 15, -15
+ 15, -15,
+ 0,
+ 0.3333333f,
};
/* button that shows popup */
@@ -1746,7 +2182,9 @@ static struct uiWidgetColors wcol_menu = {
{204, 204, 204, 255},
1,
- 15, -15
+ 15, -15,
+ 0,
+ 0.2f,
};
/* button that starts pulldown */
@@ -1760,7 +2198,9 @@ static struct uiWidgetColors wcol_pulldown = {
{0, 0, 0, 255},
0,
- 25, -20
+ 25, -20,
+ 0,
+ 0.2f,
};
/* button inside menu */
@@ -1774,7 +2214,9 @@ static struct uiWidgetColors wcol_menu_item = {
{0, 0, 0, 255},
1,
- 38, 0
+ 38, 0,
+ 0,
+ 0.2f,
};
/* backdrop menu + title text color */
@@ -1788,7 +2230,9 @@ static struct uiWidgetColors wcol_menu_back = {
{255, 255, 255, 255},
0,
- 25, -20
+ 25, -20,
+ 0,
+ 0.25f,
};
/* pie menus */
@@ -1802,7 +2246,9 @@ static struct uiWidgetColors wcol_pie_menu = {
{255, 255, 255, 255},
1,
- 10, -10
+ 10, -10,
+ 0,
+ 0.5f,
};
@@ -1817,7 +2263,9 @@ static struct uiWidgetColors wcol_tooltip = {
{255, 255, 255, 255},
0,
- 25, -20
+ 25, -20,
+ 0,
+ 0.25f,
};
static struct uiWidgetColors wcol_radio = {
@@ -1830,7 +2278,9 @@ static struct uiWidgetColors wcol_radio = {
{0, 0, 0, 255},
1,
- 15, -15
+ 15, -15,
+ 0,
+ 0.2f,
};
static struct uiWidgetColors wcol_regular = {
@@ -1843,7 +2293,9 @@ static struct uiWidgetColors wcol_regular = {
{255, 255, 255, 255},
0,
- 0, 0
+ 0, 0,
+ 0,
+ 0.25f,
};
static struct uiWidgetColors wcol_tool = {
@@ -1856,7 +2308,25 @@ static struct uiWidgetColors wcol_tool = {
{255, 255, 255, 255},
1,
- 15, -15
+ 15, -15,
+ 0,
+ 0.2f,
+};
+
+static struct uiWidgetColors wcol_toolbar_item = {
+ .outline = {0x19, 0x19, 0x19, 0xff},
+ .inner = {0x46, 0x46, 0x46, 0xff},
+ .inner_sel = {0xb4, 0xb4, 0xb4, 0xff},
+ .item = {0x19, 0x19, 0x19, 0xff},
+
+ .text = {0xff, 0xff, 0xff, 0xff},
+ .text_sel = {0x33, 0x33, 0x33, 0xff},
+
+ .shaded = 0,
+ .shadetop = 0,
+ .shadedown = 0,
+ .alpha_check = 0,
+ .roundness = 0.3f,
};
static struct uiWidgetColors wcol_box = {
@@ -1869,7 +2339,9 @@ static struct uiWidgetColors wcol_box = {
{255, 255, 255, 255},
0,
- 0, 0
+ 0, 0,
+ 0,
+ 0.2f,
};
static struct uiWidgetColors wcol_toggle = {
@@ -1882,7 +2354,9 @@ static struct uiWidgetColors wcol_toggle = {
{255, 255, 255, 255},
0,
- 0, 0
+ 0, 0,
+ 0,
+ 0.25f,
};
static struct uiWidgetColors wcol_scroll = {
@@ -1895,7 +2369,9 @@ static struct uiWidgetColors wcol_scroll = {
{255, 255, 255, 255},
1,
- 5, -5
+ 5, -5,
+ 0,
+ 0.5f,
};
static struct uiWidgetColors wcol_progress = {
@@ -1908,7 +2384,9 @@ static struct uiWidgetColors wcol_progress = {
{255, 255, 255, 255},
0,
- 0, 0
+ 0, 0,
+ 0,
+ 0.25f,
};
static struct uiWidgetColors wcol_list_item = {
@@ -1921,7 +2399,24 @@ static struct uiWidgetColors wcol_list_item = {
{255, 255, 255, 255},
0,
- 0, 0
+ 0, 0,
+ 0,
+ 0.2f,
+};
+
+struct uiWidgetColors wcol_tab = {
+ {60, 60, 60, 255},
+ {83, 83, 83, 255},
+ {114, 114, 114, 255},
+ {90, 90, 90, 255},
+
+ {0, 0, 0, 255},
+ {0, 0, 0, 255},
+
+ 0,
+ 0, 0,
+ 0,
+ 0.25f,
};
/* free wcol struct to play with */
@@ -1935,7 +2430,9 @@ static struct uiWidgetColors wcol_tmp = {
{255, 255, 255, 255},
0,
- 0, 0
+ 0, 0,
+ 0,
+ 0.25f,
};
@@ -1944,8 +2441,10 @@ void ui_widget_color_init(ThemeUI *tui)
{
tui->wcol_regular = wcol_regular;
tui->wcol_tool = wcol_tool;
+ tui->wcol_toolbar_item = wcol_toolbar_item;
tui->wcol_text = wcol_text;
tui->wcol_radio = wcol_radio;
+ tui->wcol_tab = wcol_tab;
tui->wcol_option = wcol_option;
tui->wcol_toggle = wcol_toggle;
tui->wcol_num = wcol_num;
@@ -1992,6 +2491,13 @@ static void ui_widget_color_disabled(uiWidgetType *wt)
wt->wcol_theme = &wcol_theme_s;
}
+static void widget_active_color(char cp[3])
+{
+ cp[0] = cp[0] >= 240 ? 255 : cp[0] + 15;
+ cp[1] = cp[1] >= 240 ? 255 : cp[1] + 15;
+ cp[2] = cp[2] >= 240 ? 255 : cp[2] + 15;
+}
+
/* copy colors from theme, and set changes in it based on state */
static void widget_state(uiWidgetType *wt, int state)
{
@@ -2018,6 +2524,8 @@ static void widget_state(uiWidgetType *wt, int state)
widget_state_blend(wt->wcol.inner, wcol_state->inner_anim_sel, wcol_state->blend);
else if (state & UI_BUT_DRIVEN)
widget_state_blend(wt->wcol.inner, wcol_state->inner_driven_sel, wcol_state->blend);
+ else if (state & UI_BUT_OVERRIDEN)
+ widget_state_blend(wt->wcol.inner, wcol_state->inner_overridden_sel, wcol_state->blend);
copy_v3_v3_char(wt->wcol.text, wt->wcol.text_sel);
@@ -2031,11 +2539,11 @@ static void widget_state(uiWidgetType *wt, int state)
widget_state_blend(wt->wcol.inner, wcol_state->inner_anim, wcol_state->blend);
else if (state & UI_BUT_DRIVEN)
widget_state_blend(wt->wcol.inner, wcol_state->inner_driven, wcol_state->blend);
+ else if (state & UI_BUT_OVERRIDEN)
+ widget_state_blend(wt->wcol.inner, wcol_state->inner_overridden, wcol_state->blend);
if (state & UI_ACTIVE) { /* mouse over? */
- wt->wcol.inner[0] = wt->wcol.inner[0] >= 240 ? 255 : wt->wcol.inner[0] + 15;
- wt->wcol.inner[1] = wt->wcol.inner[1] >= 240 ? 255 : wt->wcol.inner[1] + 15;
- wt->wcol.inner[2] = wt->wcol.inner[2] >= 240 ? 255 : wt->wcol.inner[2] + 15;
+ widget_active_color(wt->wcol.inner);
}
}
@@ -2076,7 +2584,9 @@ static void widget_state_numslider(uiWidgetType *wt, int state)
widget_state_blend(wt->wcol.item, wcol_state->inner_anim_sel, blend);
else if (state & UI_BUT_DRIVEN)
widget_state_blend(wt->wcol.item, wcol_state->inner_driven_sel, blend);
-
+ else if (state & UI_BUT_OVERRIDEN)
+ widget_state_blend(wt->wcol.item, wcol_state->inner_overridden_sel, blend);
+
if (state & UI_SELECT)
SWAP(short, wt->wcol.shadetop, wt->wcol.shadedown);
}
@@ -2087,6 +2597,8 @@ static void widget_state_numslider(uiWidgetType *wt, int state)
widget_state_blend(wt->wcol.item, wcol_state->inner_anim, blend);
else if (state & UI_BUT_DRIVEN)
widget_state_blend(wt->wcol.item, wcol_state->inner_driven, blend);
+ else if (state & UI_BUT_OVERRIDEN)
+ widget_state_blend(wt->wcol.item, wcol_state->inner_overridden, blend);
}
}
@@ -2204,23 +2716,24 @@ static void widget_softshadow(const rcti *rect, int roundboxalign, const float r
/* we draw a number of increasing size alpha quad strips */
alphastep = 3.0f * btheme->tui.menu_shadow_fac / radout;
-
- glEnableClientState(GL_VERTEX_ARRAY);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
for (step = 1; step <= (int)radout; step++) {
float expfac = sqrtf(step / radout);
round_box_shadow_edges(wtb.outer_v, &rect1, radin, UI_CNR_ALL, (float)step);
- glColor4f(0.0f, 0.0f, 0.0f, alphastep * (1.0f - expfac));
+ immUniformColor4f(0.0f, 0.0f, 0.0f, alphastep * (1.0f - expfac));
widget_verts_to_triangle_strip(&wtb, totvert, triangle_strip);
- glVertexPointer(2, GL_FLOAT, 0, triangle_strip);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, totvert * 2); /* add + 2 for getting a complete soft rect. Now it skips top edge to allow transparent menus */
+ widget_draw_vertex_buffer(pos, 0, GL_TRIANGLE_STRIP, triangle_strip, NULL, totvert * 2);
}
- glDisableClientState(GL_VERTEX_ARRAY);
+ immUnbindProgram();
}
static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int direction)
@@ -2245,32 +2758,32 @@ static void widget_menu_back(uiWidgetColors *wcol, rcti *rect, int flag, int dir
}
glEnable(GL_BLEND);
- widget_softshadow(rect, roundboxalign, 0.25f * U.widget_unit);
+ widget_softshadow(rect, roundboxalign, wcol->roundness * U.widget_unit);
- round_box_edges(&wtb, roundboxalign, rect, 0.25f * U.widget_unit);
+ round_box_edges(&wtb, roundboxalign, rect, wcol->roundness * U.widget_unit);
wtb.draw_emboss = false;
widgetbase_draw(&wtb, wcol);
glDisable(GL_BLEND);
}
-
static void ui_hsv_cursor(float x, float y)
{
- glPushMatrix();
- glTranslatef(x, y, 0.0f);
-
- glColor3f(1.0f, 1.0f, 1.0f);
- glutil_draw_filled_arc(0.0f, M_PI * 2.0, 3.0f * U.pixelsize, 8);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
+ imm_draw_circle_fill_2d(pos, x, y, 3.0f * U.pixelsize, 8);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
- glColor3f(0.0f, 0.0f, 0.0f);
- glutil_draw_lined_arc(0.0f, M_PI * 2.0, 3.0f * U.pixelsize, 12);
+ immUniformColor3f(0.0f, 0.0f, 0.0f);
+ imm_draw_circle_wire_2d(pos, x, y, 3.0f * U.pixelsize, 12);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
-
- glPopMatrix();
+
+ immUnbindProgram();
}
void ui_hsvcircle_vals_from_pos(float *val_rad, float *val_dist, const rcti *rect,
@@ -2310,18 +2823,17 @@ void ui_hsvcircle_pos_from_vals(uiBut *but, const rcti *rect, float *hsv, float
static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *rect)
{
+ /* TODO(merwin): reimplement as shader for pixel-perfect colors */
+
const int tot = 64;
const float radstep = 2.0f * (float)M_PI / (float)tot;
const float centx = BLI_rcti_cent_x_fl(rect);
const float centy = BLI_rcti_cent_y_fl(rect);
float radius = (float)min_ii(BLI_rcti_size_x(rect), BLI_rcti_size_y(rect)) / 2.0f;
- /* gouraud triangle fan */
ColorPicker *cpicker = but->custom_data;
const float *hsv_ptr = cpicker->color_data;
- float xpos, ypos, ang = 0.0f;
float rgb[3], hsvo[3], hsv[3], col[3], colcent[3];
- int a;
bool color_profile = ui_but_is_colorpicker_display_space(but);
/* color */
@@ -2352,11 +2864,18 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
ui_color_picker_to_rgb(0.0f, 0.0f, hsv[2], colcent, colcent + 1, colcent + 2);
- glBegin(GL_TRIANGLE_FAN);
- glColor3fv(colcent);
- glVertex2f(centx, centy);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+
+ immBegin(GWN_PRIM_TRI_FAN, tot + 2);
+ immAttrib3fv(color, colcent);
+ immVertex2f(pos, centx, centy);
- for (a = 0; a <= tot; a++, ang += radstep) {
+ float ang = 0.0f;
+ for (int a = 0; a <= tot; a++, ang += radstep) {
float si = sinf(ang);
float co = cosf(ang);
@@ -2364,25 +2883,32 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
ui_color_picker_to_rgb_v(hsv, col);
- glColor3fv(col);
- glVertex2f(centx + co * radius, centy + si * radius);
+ immAttrib3fv(color, col);
+ immVertex2f(pos, centx + co * radius, centy + si * radius);
}
- glEnd();
-
+ immEnd();
+ immUnbindProgram();
+
/* fully rounded outline */
- glPushMatrix();
- glTranslatef(centx, centy, 0.0f);
+ format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
- glColor3ubv((unsigned char *)wcol->outline);
- glutil_draw_lined_arc(0.0f, M_PI * 2.0, radius, tot + 1);
+
+ immUniformColor3ubv((unsigned char *)wcol->outline);
+ imm_draw_circle_wire_2d(pos, centx, centy, radius, tot);
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
- glPopMatrix();
/* cursor */
+ float xpos, ypos;
ui_hsvcircle_pos_from_vals(but, rect, hsvo, &xpos, &ypos);
-
ui_hsv_cursor(xpos, ypos);
}
@@ -2392,7 +2918,8 @@ static void ui_draw_but_HSVCIRCLE(uiBut *but, uiWidgetColors *wcol, const rcti *
void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, const float alpha)
{
/* allows for 4 steps (red->yellow) */
- const float color_step = 1.0f / 48.0f;
+ const int steps = 48;
+ const float color_step = 1.0f / steps;
int a;
float h = hsv[0], s = hsv[1], v = hsv[2];
float dx, dy, sx1, sx2, sy;
@@ -2446,9 +2973,14 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
copy_v3_v3(col1[3], col1[2]);
break;
}
-
+
/* old below */
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+ immBegin(GWN_PRIM_TRIS, steps * 3 * 6);
for (dx = 0.0f; dx < 0.999f; dx += color_step) { /* 0.999 = prevent float inaccuracy for steps */
const float dx_next = dx + color_step;
@@ -2506,22 +3038,29 @@ void ui_draw_gradient(const rcti *rect, const float hsv[3], const int type, cons
sy = rect->ymin;
dy = (float)BLI_rcti_size_y(rect) / 3.0f;
- glBegin(GL_QUADS);
for (a = 0; a < 3; a++, sy += dy) {
- glColor4f(col0[a][0], col0[a][1], col0[a][2], alpha);
- glVertex2f(sx1, sy);
+ immAttrib4f(col, col0[a][0], col0[a][1], col0[a][2], alpha);
+ immVertex2f(pos, sx1, sy);
- glColor4f(col1[a][0], col1[a][1], col1[a][2], alpha);
- glVertex2f(sx2, sy);
+ immAttrib4f(col, col1[a][0], col1[a][1], col1[a][2], alpha);
+ immVertex2f(pos, sx2, sy);
- glColor4f(col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
- glVertex2f(sx2, sy + dy);
+ immAttrib4f(col, col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
+ immVertex2f(pos, sx2, sy + dy);
+
+ immAttrib4f(col, col0[a][0], col0[a][1], col0[a][2], alpha);
+ immVertex2f(pos, sx1, sy);
+
+ immAttrib4f(col, col1[a + 1][0], col1[a + 1][1], col1[a + 1][2], alpha);
+ immVertex2f(pos, sx2, sy + dy);
- glColor4f(col0[a + 1][0], col0[a + 1][1], col0[a + 1][2], alpha);
- glVertex2f(sx1, sy + dy);
+ immAttrib4f(col, col0[a + 1][0], col0[a + 1][1], col0[a + 1][2], alpha);
+ immVertex2f(pos, sx1, sy + dy);
}
- glEnd();
}
+ immEnd();
+
+ immUnbindProgram();
}
bool ui_but_is_colorpicker_display_space(uiBut *but)
@@ -2597,15 +3136,20 @@ static void ui_draw_but_HSVCUBE(uiBut *but, const rcti *rect)
ui_hsv_cursor(x, y);
/* outline */
- glColor3ub(0, 0, 0);
- fdrawbox((rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3ub(0, 0, 0);
+ imm_draw_box_wire_2d(pos, (rect->xmin), (rect->ymin), (rect->xmax), (rect->ymax));
+ immUnbindProgram();
}
/* vertical 'value' slider, using new widget code */
static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
{
+ bTheme *btheme = UI_GetTheme();
+ uiWidgetColors *wcol = &btheme->tui.wcol_numslider;
uiWidgetBase wtb;
- const float rad = 0.5f * BLI_rcti_size_x(rect);
+ const float rad = wcol->roundness * BLI_rcti_size_x(rect);
float x, y;
float rgb[3], hsv[3], v;
bool color_profile = but->block->color_profile;
@@ -2647,6 +3191,11 @@ static void ui_draw_but_HSV_v(uiBut *but, const rcti *rect)
widgetbase_draw(&wtb, &wcol_tmp);
+ /* We are drawing on top of widget bases. Flush cache. */
+ glEnable(GL_BLEND);
+ UI_widgetbase_draw_cache_flush();
+ glDisable(GL_BLEND);
+
/* cursor */
x = rect->xmin + 0.5f * BLI_rcti_size_x(rect);
y = rect->ymin + v * BLI_rcti_size_y(rect);
@@ -2666,20 +3215,30 @@ static void ui_draw_separator(const rcti *rect, uiWidgetColors *wcol)
wcol->text[2],
30
};
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
glEnable(GL_BLEND);
- glColor4ubv(col);
+ immUniformColor4ubv(col);
glLineWidth(1.0f);
- sdrawline(rect->xmin, y, rect->xmax, y);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, rect->xmin, y);
+ immVertex2f(pos, rect->xmax, y);
+ immEnd();
+
glDisable(GL_BLEND);
+
+ immUnbindProgram();
}
/* ************ button callbacks, draw ***************** */
static void widget_numbut_draw(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign, bool emboss)
{
uiWidgetBase wtb;
- const float rad = 0.5f * BLI_rcti_size_y(rect);
- float textofs = rad * 0.85f;
+ const float rad = wcol->roundness * BLI_rcti_size_y(rect);
+ const int handle_width = min_ii(BLI_rcti_size_x(rect) / 3, BLI_rcti_size_y(rect) * 0.7f);
if (state & UI_SELECT)
SWAP(short, wcol->shadetop, wcol->shadedown);
@@ -2695,14 +3254,80 @@ static void widget_numbut_draw(uiWidgetColors *wcol, rcti *rect, int state, int
}
/* decoration */
- if (!(state & UI_STATE_TEXT_INPUT)) {
- shape_preset_init_number_arrows(&wtb.tria1, rect, 0.6f, 'l');
- shape_preset_init_number_arrows(&wtb.tria2, rect, 0.6f, 'r');
- }
+ if ((state & UI_ACTIVE) && !(state & UI_STATE_TEXT_INPUT)) {
+ uiWidgetColors wcol_zone;
+ uiWidgetBase wtb_zone;
+ rcti rect_zone;
+ int roundboxalign_zone;
+
+ /* left arrow zone */
+ widget_init(&wtb_zone);
+ wtb_zone.draw_outline = false;
+ wtb_zone.draw_emboss = false;
+
+ wcol_zone = *wcol;
+ copy_v3_v3_char(wcol_zone.item, wcol->text);
+ if (state & UI_STATE_ACTIVE_LEFT) {
+ widget_active_color(wcol_zone.inner);
+ }
- widgetbase_draw(&wtb, wcol);
+ rect_zone = *rect;
+ rect_zone.xmax = rect->xmin + handle_width + U.pixelsize;
+ roundboxalign_zone = roundboxalign & ~(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
+ round_box_edges(&wtb_zone, roundboxalign_zone, &rect_zone, rad);
+
+ shape_preset_init_number_arrows(&wtb_zone.tria1, &rect_zone, 0.6f, 'l');
+ widgetbase_draw(&wtb_zone, &wcol_zone);
+
+ /* right arrow zone */
+ widget_init(&wtb_zone);
+ wtb_zone.draw_outline = false;
+ wtb_zone.draw_emboss = false;
+ wtb_zone.tria1.type = ROUNDBOX_TRIA_ARROWS;
+
+ wcol_zone = *wcol;
+ copy_v3_v3_char(wcol_zone.item, wcol->text);
+ if (state & UI_STATE_ACTIVE_RIGHT) {
+ widget_active_color(wcol_zone.inner);
+ }
+
+ rect_zone = *rect;
+ rect_zone.xmin = rect->xmax - handle_width - U.pixelsize;
+ roundboxalign_zone = roundboxalign & ~(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
+ round_box_edges(&wtb_zone, roundboxalign_zone, &rect_zone, rad);
+
+ shape_preset_init_number_arrows(&wtb_zone.tria2, &rect_zone, 0.6f, 'r');
+ widgetbase_draw(&wtb_zone, &wcol_zone);
+
+ /* middle highlight zone */
+ widget_init(&wtb_zone);
+ wtb_zone.draw_outline = false;
+ wtb_zone.draw_emboss = false;
+
+ wcol_zone = *wcol;
+ copy_v3_v3_char(wcol_zone.item, wcol->text);
+ if (!(state & (UI_STATE_ACTIVE_LEFT | UI_STATE_ACTIVE_RIGHT))) {
+ widget_active_color(wcol_zone.inner);
+ }
+
+ rect_zone = *rect;
+ rect_zone.xmin = rect->xmin + handle_width - U.pixelsize;
+ rect_zone.xmax = rect->xmax - handle_width + U.pixelsize;
+ round_box_edges(&wtb_zone, 0, &rect_zone, 0);
+ widgetbase_draw(&wtb_zone, &wcol_zone);
+
+ /* outline */
+ wtb.draw_inner = false;
+ widgetbase_draw(&wtb, wcol);
+ }
+ else {
+ /* inner and outline */
+ widgetbase_draw(&wtb, wcol);
+ }
if (!(state & UI_STATE_TEXT_INPUT)) {
+ const float textofs = 0.425f * BLI_rcti_size_y(rect);
+
/* text space */
rect->xmin += textofs;
rect->xmax -= textofs;
@@ -2722,53 +3347,6 @@ static void widget_numbut_embossn(uiBut *UNUSED(but), uiWidgetColors *wcol, rcti
widget_numbut_draw(wcol, rect, state, roundboxalign, true);
}
-bool ui_link_bezier_points(const rcti *rect, float coord_array[][2], int resol)
-{
- float dist, vec[4][2];
-
- vec[0][0] = rect->xmin;
- vec[0][1] = rect->ymin;
- vec[3][0] = rect->xmax;
- vec[3][1] = rect->ymax;
-
- dist = 0.5f * fabsf(vec[0][0] - vec[3][0]);
-
- vec[1][0] = vec[0][0] + dist;
- vec[1][1] = vec[0][1];
-
- vec[2][0] = vec[3][0] - dist;
- vec[2][1] = vec[3][1];
-
- BKE_curve_forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0], &coord_array[0][0], resol, sizeof(float[2]));
- BKE_curve_forward_diff_bezier(vec[0][1], vec[1][1], vec[2][1], vec[3][1], &coord_array[0][1], resol, sizeof(float[2]));
-
- /* TODO: why return anything if always true? */
- return true;
-}
-
-#define LINK_RESOL 24
-void ui_draw_link_bezier(const rcti *rect)
-{
- float coord_array[LINK_RESOL + 1][2];
-
- if (ui_link_bezier_points(rect, coord_array, LINK_RESOL)) {
-#if 0 /* unused */
- /* we can reuse the dist variable here to increment the GL curve eval amount*/
- const float dist = 1.0f / (float)LINK_RESOL;
-#endif
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, coord_array);
- glDrawArrays(GL_LINE_STRIP, 0, LINK_RESOL + 1);
- glDisableClientState(GL_VERTEX_ARRAY);
-
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
- }
-}
-
/* function in use for buttons and for view2d sliders */
void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *slider, int state)
{
@@ -2783,11 +3361,11 @@ void UI_draw_widget_scroll(uiWidgetColors *wcol, const rcti *rect, const rcti *s
horizontal = (BLI_rcti_size_x(rect) > BLI_rcti_size_y(rect));
if (horizontal)
- rad = 0.5f * BLI_rcti_size_y(rect);
+ rad = wcol->roundness * BLI_rcti_size_y(rect);
else
- rad = 0.5f * BLI_rcti_size_x(rect);
+ rad = wcol->roundness * BLI_rcti_size_x(rect);
- wtb.draw_shadedir = (horizontal) ? true : false;
+ wtb.uniform_params.shade_dir = (horizontal) ? 1.0f : 0.0;
/* draw back part, colors swapped and shading inverted */
if (horizontal)
@@ -2919,7 +3497,7 @@ static void widget_progressbar(uiBut *but, uiWidgetColors *wcol, rcti *rect, int
/* round corners */
float value = but->a1;
- float offs = 0.25f * BLI_rcti_size_y(&rect_prog);
+ float offs = wcol->roundness * BLI_rcti_size_y(&rect_prog);
float w = value * BLI_rcti_size_x(&rect_prog);
/* ensure minimium size */
@@ -2942,96 +3520,85 @@ static void widget_progressbar(uiBut *but, uiWidgetColors *wcol, rcti *rect, int
rect->xmax += (BLI_rcti_size_x(&rect_prog) / 2);
}
-static void widget_link(uiBut *but, uiWidgetColors *UNUSED(wcol), rcti *rect, int UNUSED(state), int UNUSED(roundboxalign))
-{
-
- if (but->flag & UI_SELECT) {
- rcti rectlink;
-
- UI_ThemeColor(TH_TEXT_HI);
-
- rectlink.xmin = BLI_rcti_cent_x(rect);
- rectlink.ymin = BLI_rcti_cent_y(rect);
- rectlink.xmax = but->linkto[0];
- rectlink.ymax = but->linkto[1];
-
- ui_draw_link_bezier(&rectlink);
- }
-}
-
static void widget_numslider(uiBut *but, uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
{
uiWidgetBase wtb, wtb1;
rcti rect1;
- double value;
- float offs, toffs, fac = 0;
+ float offs, toffs;
char outline[3];
widget_init(&wtb);
widget_init(&wtb1);
-
- /* backdrop first */
-
- /* fully rounded */
- offs = 0.5f * BLI_rcti_size_y(rect);
+
+ /* Backdrop first. */
+ offs = wcol->roundness * BLI_rcti_size_y(rect);
toffs = offs * 0.75f;
round_box_edges(&wtb, roundboxalign, rect, offs);
wtb.draw_outline = false;
widgetbase_draw(&wtb, wcol);
-
- /* draw left/right parts only when not in text editing */
+
+ /* Draw slider part only when not in text editing. */
if (!(state & UI_STATE_TEXT_INPUT)) {
- int roundboxalign_slider;
-
- /* slider part */
+ int roundboxalign_slider = roundboxalign;
+
copy_v3_v3_char(outline, wcol->outline);
copy_v3_v3_char(wcol->outline, wcol->item);
copy_v3_v3_char(wcol->inner, wcol->item);
- if (!(state & UI_SELECT))
+ if (!(state & UI_SELECT)) {
SWAP(short, wcol->shadetop, wcol->shadedown);
-
+ }
+
rect1 = *rect;
-
- value = ui_but_value_get(but);
- if ((but->softmax - but->softmin) > 0) {
- fac = ((float)value - but->softmin) * (BLI_rcti_size_x(&rect1) - offs) / (but->softmax - but->softmin);
+ float factor, factor_ui;
+ float factor_discard = 1.0f; /* No discard. */
+ float value = (float)ui_but_value_get(but);
+
+ if (but->rnaprop && (RNA_property_subtype(but->rnaprop) == PROP_PERCENTAGE)) {
+ factor = value / but->softmax;
}
-
- /* left part of slider, always rounded */
- rect1.xmax = rect1.xmin + ceil(offs + U.pixelsize);
- round_box_edges(&wtb1, roundboxalign & ~(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT), &rect1, offs);
- wtb1.draw_outline = false;
- widgetbase_draw(&wtb1, wcol);
-
- /* right part of slider, interpolate roundness */
- rect1.xmax = rect1.xmin + fac + offs;
- rect1.xmin += floor(offs - U.pixelsize);
-
- if (rect1.xmax + offs > rect->xmax) {
- roundboxalign_slider = roundboxalign & ~(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT);
- offs *= (rect1.xmax + offs - rect->xmax) / offs;
+ else {
+ factor = (value - but->softmin) / (but->softmax - but->softmin);
+ }
+
+ float width = (float)BLI_rcti_size_x(rect);
+ factor_ui = factor * width;
+
+ if (factor_ui <= offs) {
+ /* Left part only. */
+ roundboxalign_slider &= ~(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
+ rect1.xmax = rect1.xmin + offs;
+ factor_discard = factor_ui / offs;
+ }
+ else if (factor_ui <= width - offs) {
+ /* Left part + middle part. */
+ roundboxalign_slider &= ~(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT);
+ rect1.xmax = rect1.xmin + factor_ui;
}
else {
- roundboxalign_slider = 0;
- offs = 0.0f;
+ /* Left part + middle part + right part. */
+ factor_discard = factor;
}
+
round_box_edges(&wtb1, roundboxalign_slider, &rect1, offs);
-
+ wtb1.draw_outline = false;
+ widgetbase_set_uniform_discard_factor(&wtb1, factor_discard);
widgetbase_draw(&wtb1, wcol);
+
copy_v3_v3_char(wcol->outline, outline);
-
- if (!(state & UI_SELECT))
+
+ if (!(state & UI_SELECT)) {
SWAP(short, wcol->shadetop, wcol->shadedown);
+ }
}
-
- /* outline */
+
+ /* Outline. */
wtb.draw_outline = true;
wtb.draw_inner = false;
widgetbase_draw(&wtb, wcol);
- /* add space at either side of the button so text aligns with numbuttons (which have arrow icons) */
+ /* Add space at either side of the button so text aligns with numbuttons (which have arrow icons). */
if (!(state & UI_STATE_TEXT_INPUT)) {
rect->xmax -= toffs;
rect->xmin += toffs;
@@ -3062,13 +3629,12 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
widget_init(&wtb);
- /* half rounded */
- rad = 0.25f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
ui_but_v3_get(but, col);
- if (state & (UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN | UI_BUT_REDALERT)) {
+ if (state & (UI_BUT_ANIMATED | UI_BUT_ANIMATED_KEY | UI_BUT_DRIVEN | UI_BUT_OVERRIDEN | UI_BUT_REDALERT)) {
/* draw based on state - color for keyed etc */
widgetbase_draw(&wtb, wcol);
@@ -3099,7 +3665,6 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
}
widgetbase_draw(&wtb, wcol);
-
if (but->a1 == UI_PALETTE_COLOR && ((Palette *)but->rnapoin.id.data)->active_color == (int)but->a2) {
float width = rect->xmax - rect->xmin;
float height = rect->ymax - rect->ymin;
@@ -3107,13 +3672,23 @@ static void widget_swatch(uiBut *but, uiWidgetColors *wcol, rcti *rect, int stat
float bw = rgb_to_grayscale(col);
bw += (bw < 0.5f) ? 0.5f : -0.5f;
-
- glColor4f(bw, bw, bw, 1.0);
- glBegin(GL_TRIANGLES);
- glVertex2f(rect->xmin + 0.1f * width, rect->ymin + 0.9f * height);
- glVertex2f(rect->xmin + 0.1f * width, rect->ymin + 0.5f * height);
- glVertex2f(rect->xmin + 0.5f * width, rect->ymin + 0.9f * height);
- glEnd();
+
+ /* We are drawing on top of widget bases. Flush cache. */
+ glEnable(GL_BLEND);
+ UI_widgetbase_draw_cache_flush();
+ glDisable(GL_BLEND);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor3f(bw, bw, bw);
+ immBegin(GWN_PRIM_TRIS, 3);
+ immVertex2f(pos, rect->xmin + 0.1f * width, rect->ymin + 0.9f * height);
+ immVertex2f(pos, rect->xmin + 0.1f * width, rect->ymin + 0.5f * height);
+ immVertex2f(pos, rect->xmin + 0.5f * width, rect->ymin + 0.9f * height);
+ immEnd();
+
+ immUnbindProgram();
}
}
@@ -3131,8 +3706,7 @@ static void widget_icon_has_anim(uiBut *but, uiWidgetColors *wcol, rcti *rect, i
widget_init(&wtb);
wtb.draw_outline = false;
- /* rounded */
- rad = 0.5f * BLI_rcti_size_y(rect);
+ rad = wcol->roundness * BLI_rcti_size_y(rect);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
widgetbase_draw(&wtb, wcol);
}
@@ -3154,8 +3728,7 @@ static void widget_textbut(uiWidgetColors *wcol, rcti *rect, int state, int roun
widget_init(&wtb);
- /* half rounded */
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol);
@@ -3169,12 +3742,13 @@ static void widget_menubut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state),
widget_init(&wtb);
- /* half rounded */
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
/* decoration */
shape_preset_trias_from_rect_menu(&wtb.tria1, rect);
+ /* copy size and center to 2nd tria */
+ wtb.tria2 = wtb.tria1;
widgetbase_draw(&wtb, wcol);
@@ -3189,8 +3763,7 @@ static void widget_menuiconbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(stat
widget_init(&wtb);
- /* half rounded */
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
/* decoration */
@@ -3206,8 +3779,7 @@ static void widget_menunodebut(uiWidgetColors *wcol, rcti *rect, int UNUSED(stat
widget_init(&wtb);
- /* half rounded */
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
wcol->inner[0] = min_ii(wcol->inner[0] + 15, 255);
@@ -3226,7 +3798,7 @@ static void widget_pulldownbut(uiWidgetColors *wcol, rcti *rect, int state, int
{
if (state & UI_ACTIVE) {
uiWidgetBase wtb;
- const float rad = 0.2f * U.widget_unit;
+ const float rad = wcol->roundness * U.widget_unit;
widget_init(&wtb);
@@ -3260,7 +3832,7 @@ static void widget_menu_radial_itembut(uiBut *but, uiWidgetColors *wcol, rcti *r
wtb.draw_emboss = false;
- rad = 0.5f * BLI_rcti_size_y(rect);
+ rad = wcol->roundness * BLI_rcti_size_y(rect);
round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
wcol->inner[3] *= fac;
@@ -3280,9 +3852,9 @@ static void widget_list_itembut(uiWidgetColors *wcol, rcti *rect, int UNUSED(sta
widget_init(&wtb);
- /* rounded, but no outline */
+ /* no outline */
wtb.draw_outline = false;
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, UI_CNR_ALL, rect, rad);
widgetbase_draw(&wtb, wcol);
@@ -3307,8 +3879,7 @@ static void widget_optionbut(uiWidgetColors *wcol, rcti *rect, int state, int UN
recttemp.xmax -= delta;
recttemp.ymax -= delta;
- /* half rounded */
- rad = BLI_rcti_size_y(&recttemp) / 3;
+ rad = wcol->roundness * BLI_rcti_size_y(&recttemp);
round_box_edges(&wtb, UI_CNR_ALL, &recttemp, rad);
/* decoration */
@@ -3349,8 +3920,7 @@ static void widget_radiobut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state),
widget_init(&wtb);
- /* half rounded */
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol);
@@ -3373,8 +3943,7 @@ static void widget_box(uiBut *but, uiWidgetColors *wcol, rcti *rect, int UNUSED(
wcol->inner[2] = but->col[2];
}
- /* half rounded */
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol);
@@ -3389,8 +3958,7 @@ static void widget_but(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int
widget_init(&wtb);
- /* half rounded */
- rad = 0.2f * U.widget_unit;
+ rad = wcol->roundness * U.widget_unit;
round_box_edges(&wtb, roundboxalign, rect, rad);
widgetbase_draw(&wtb, wcol);
@@ -3400,7 +3968,7 @@ static void widget_but(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int
static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state), int roundboxalign)
{
uiWidgetBase wtb;
- const float rad = 0.25f * U.widget_unit;
+ const float rad = wcol->roundness * U.widget_unit;
widget_init(&wtb);
@@ -3414,7 +3982,7 @@ static void widget_roundbut(uiWidgetColors *wcol, rcti *rect, int UNUSED(state),
static void widget_roundbut_exec(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
{
uiWidgetBase wtb;
- const float rad = 0.25f * U.widget_unit;
+ const float rad = wcol->roundness * U.widget_unit;
widget_init(&wtb);
@@ -3429,12 +3997,70 @@ static void widget_roundbut_exec(uiWidgetColors *wcol, rcti *rect, int state, in
widgetbase_draw(&wtb, wcol);
}
+static void widget_tab(uiWidgetColors *wcol, rcti *rect, int state, int roundboxalign)
+{
+ const uiStyle *style = UI_style_get();
+ const float rad = wcol->roundness * U.widget_unit;
+ const int fontid = style->widget.uifont_id;
+ const bool is_active = (state & UI_SELECT);
+
+/* Draw shaded outline - Disabled for now, seems incorrect and also looks nicer without it imho ;) */
+//#define USE_TAB_SHADED_HIGHLIGHT
+
+ uiWidgetBase wtb;
+ unsigned char theme_col_tab_highlight[3];
+
+#ifdef USE_TAB_SHADED_HIGHLIGHT
+ /* create outline highlight colors */
+ if (is_active) {
+ interp_v3_v3v3_uchar(theme_col_tab_highlight, (unsigned char *)wcol->inner_sel,
+ (unsigned char *)wcol->outline, 0.2f);
+ }
+ else {
+ interp_v3_v3v3_uchar(theme_col_tab_highlight, (unsigned char *)wcol->inner,
+ (unsigned char *)wcol->outline, 0.12f);
+ }
+#endif
+
+ widget_init(&wtb);
+
+ /* half rounded */
+ round_box_edges(&wtb, roundboxalign, rect, rad);
+
+ /* draw inner */
+#ifdef USE_TAB_SHADED_HIGHLIGHT
+ wtb.draw_outline = 0;
+#endif
+ widgetbase_draw(&wtb, wcol);
+
+ /* We are drawing on top of widget bases. Flush cache. */
+ glEnable(GL_BLEND);
+ UI_widgetbase_draw_cache_flush();
+ glDisable(GL_BLEND);
+
+#ifdef USE_TAB_SHADED_HIGHLIGHT
+ /* draw outline (3d look) */
+ ui_draw_but_TAB_outline(rect, rad, theme_col_tab_highlight, (unsigned char *)wcol->inner);
+#endif
+
+ /* text shadow */
+ BLF_enable(fontid, BLF_SHADOW);
+ BLF_shadow(fontid, 3, (const float[4]){1.0f, 1.0f, 1.0f, 0.25f});
+ BLF_shadow_offset(fontid, 0, -1);
+
+#ifndef USE_TAB_SHADED_HIGHLIGHT
+ UNUSED_VARS(is_active, theme_col_tab_highlight);
+#endif
+}
+
static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *wt, rcti *rect)
{
+ bTheme *btheme = UI_GetTheme();
+ uiWidgetColors *wcol = &btheme->tui.wcol_radio;
uiWidgetBase wtb;
- const float rad = 0.25f * U.widget_unit;
+ const float rad = wcol->roundness * U.widget_unit;
unsigned char col[4];
-
+
/* state copy! */
wt->wcol = *(wt->wcol_theme);
@@ -3444,12 +4070,17 @@ static void widget_draw_extra_mask(const bContext *C, uiBut *but, uiWidgetType *
/* note: drawextra can change rect +1 or -1, to match round errors of existing previews */
but->block->drawextra(C, but->poin, but->block->drawextra_arg1, but->block->drawextra_arg2, rect);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* make mask to draw over image */
UI_GetThemeColor3ubv(TH_BACK, col);
- glColor3ubv(col);
-
+ immUniformColor3ubv(col);
+
round_box__edges(&wtb, UI_CNR_ALL, rect, 0.0f, rad);
- widgetbase_outline(&wtb);
+ widgetbase_outline(&wtb, pos);
+
+ immUnbindProgram();
}
/* outline */
@@ -3511,6 +4142,16 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
wt.draw = widget_roundbut_exec;
break;
+ case UI_WTYPE_TOOLBAR_ITEM:
+ wt.wcol_theme = &btheme->tui.wcol_toolbar_item;
+ wt.draw = widget_roundbut_exec;
+ break;
+
+ case UI_WTYPE_TAB:
+ wt.wcol_theme = &btheme->tui.wcol_tab;
+ wt.draw = widget_tab;
+ break;
+
case UI_WTYPE_TOOLTIP:
wt.wcol_theme = &btheme->tui.wcol_tooltip;
wt.draw = widget_menu_back;
@@ -3571,7 +4212,7 @@ static uiWidgetType *widget_type(uiWidgetTypeEnum type)
wt.wcol_theme = &btheme->tui.wcol_menu_back;
wt.draw = widget_menu_back;
break;
-
+
/* specials */
case UI_WTYPE_ICON:
wt.custom = widget_icon_has_anim;
@@ -3633,7 +4274,7 @@ static int widget_roundbox_set(uiBut *but, rcti *rect)
/* alignment */
if ((but->drawflag & UI_BUT_ALIGN) && but->type != UI_BTYPE_PULLDOWN) {
- /* ui_block_position has this correction too, keep in sync */
+ /* ui_popup_block_position has this correction too, keep in sync */
if (but->drawflag & (UI_BUT_ALIGN_TOP | UI_BUT_ALIGN_STITCH_TOP))
rect->ymax += U.pixelsize;
if (but->drawflag & (UI_BUT_ALIGN_LEFT | UI_BUT_ALIGN_STITCH_LEFT))
@@ -3671,7 +4312,7 @@ static int widget_roundbox_set(uiBut *but, rcti *rect)
}
/* align with open menu */
- if (but->active) {
+ if (but->active && (but->type != UI_BTYPE_POPOVER)) {
int direction = ui_but_menu_direction(but);
if (direction == UI_DIR_UP) roundbox &= ~(UI_CNR_TOP_RIGHT | UI_CNR_TOP_LEFT);
@@ -3745,7 +4386,16 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
break;
case UI_BTYPE_BUT:
+#ifdef USE_TOOLBAR_HACK
+ if (UI_but_is_tool(but)) {
+ wt = widget_type(UI_WTYPE_TOOLBAR_ITEM);
+ }
+ else {
+ wt = widget_type(UI_WTYPE_EXEC);
+ }
+#else
wt = widget_type(UI_WTYPE_EXEC);
+#endif
break;
case UI_BTYPE_NUM:
@@ -3773,7 +4423,11 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
if (but->block->flag & UI_BLOCK_LOOP)
wt->wcol_theme = &btheme->tui.wcol_menu_back;
break;
-
+
+ case UI_BTYPE_TAB:
+ wt = widget_type(UI_WTYPE_TAB);
+ break;
+
case UI_BTYPE_BUT_TOGGLE:
case UI_BTYPE_TOGGLE:
case UI_BTYPE_TOGGLE_N:
@@ -3797,6 +4451,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
case UI_BTYPE_MENU:
case UI_BTYPE_BLOCK:
+ case UI_BTYPE_POPOVER:
if (but->flag & UI_BUT_NODE_LINK) {
/* new node-link button, not active yet XXX */
wt = widget_type(UI_WTYPE_MENU_NODE_LINK);
@@ -3818,7 +4473,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
}
}
break;
-
+
case UI_BTYPE_PULLDOWN:
wt = widget_type(UI_WTYPE_PULLDOWN);
break;
@@ -3835,14 +4490,7 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
case UI_BTYPE_LISTBOX:
wt = widget_type(UI_WTYPE_BOX);
break;
-
- case UI_BTYPE_LINK:
- case UI_BTYPE_INLINK:
- wt = widget_type(UI_WTYPE_ICON);
- wt->custom = widget_link;
-
- break;
-
+
case UI_BTYPE_EXTRA:
widget_draw_extra_mask(C, but, widget_type(UI_WTYPE_BOX), rect);
break;
@@ -3939,6 +4587,15 @@ void ui_draw_but(const bContext *C, ARegion *ar, uiStyle *style, uiBut *but, rct
state |= UI_STATE_HOLD_ACTION;
}
+ if (state & UI_ACTIVE) {
+ if (but->drawflag & UI_BUT_ACTIVE_LEFT) {
+ state |= UI_STATE_ACTIVE_LEFT;
+ }
+ else if (but->drawflag & UI_BUT_ACTIVE_RIGHT) {
+ state |= UI_STATE_ACTIVE_RIGHT;
+ }
+ }
+
if (state & (UI_BUT_DISABLED | UI_BUT_INACTIVE))
if (but->dt != UI_EMBOSS_PULLDOWN)
disabled = true;
@@ -3973,21 +4630,97 @@ void ui_draw_menu_back(uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
wt->draw(&wt->wcol, rect, block->flag, block->direction);
else
wt->draw(&wt->wcol, rect, 0, 0);
-
+
if (block) {
+ float draw_color[4];
+ unsigned char *color = (unsigned char *)wt->wcol.text;
+
+ draw_color[0] = ((float)color[0]) / 255.0f;
+ draw_color[1] = ((float)color[1]) / 255.0f;
+ draw_color[2] = ((float)color[2]) / 255.0f;
+ draw_color[3] = 1.0f;
+
if (block->flag & UI_BLOCK_CLIPTOP) {
/* XXX no scaling for UI here yet */
- glColor3ubv((unsigned char *)wt->wcol.text);
- UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 8, 't');
+ UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymax - 8, 't', draw_color);
}
if (block->flag & UI_BLOCK_CLIPBOTTOM) {
/* XXX no scaling for UI here yet */
- glColor3ubv((unsigned char *)wt->wcol.text);
- UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10, 'v');
+ UI_draw_icon_tri(BLI_rcti_cent_x(rect), rect->ymin + 10, 'v', draw_color);
}
}
}
+/**
+ * Similar to 'widget_menu_back', however we can't use the widget preset system
+ * because we need to pass in the original location so we know where to show the arrow.
+ */
+static void ui_draw_popover_back_impl(
+ const uiWidgetColors *wcol, rcti *rect, int direction,
+ const float mval_origin[2])
+{
+ /* tsk, this isn't nice. */
+ const float unit_half = (BLI_rcti_size_x(rect) / UI_POPOVER_WIDTH_UNITS) / 2;
+ const float cent_x = mval_origin ? mval_origin[0] : BLI_rcti_cent_x(rect);
+ rect->ymax -= unit_half;
+ rect->ymin += unit_half;
+
+ glEnable(GL_BLEND);
+
+ /* Extracted from 'widget_menu_back', keep separate to avoid menu changes breaking popovers */
+ {
+ uiWidgetBase wtb;
+ widget_init(&wtb);
+
+ const int roundboxalign = UI_CNR_ALL;
+ widget_softshadow(rect, roundboxalign, wcol->roundness * U.widget_unit);
+
+ round_box_edges(&wtb, roundboxalign, rect, wcol->roundness * U.widget_unit);
+ wtb.draw_emboss = false;
+ widgetbase_draw(&wtb, wcol);
+ }
+
+ /* Draw popover arrow (top/bottom) */
+ if (ELEM(direction, UI_DIR_UP, UI_DIR_DOWN)) {
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ubv((unsigned char *)wcol->inner);
+ glEnable(GL_BLEND);
+ immBegin(GWN_PRIM_TRIS, 3);
+ if (direction == UI_DIR_DOWN) {
+ const float y = rect->ymax;
+ immVertex2f(pos, cent_x - unit_half, y);
+ immVertex2f(pos, cent_x + unit_half, y);
+ immVertex2f(pos, cent_x, y + unit_half);
+ }
+ else {
+ const float y = rect->ymin;
+ immVertex2f(pos, cent_x - unit_half, y);
+ immVertex2f(pos, cent_x + unit_half, y);
+ immVertex2f(pos, cent_x, y - unit_half);
+ }
+ immEnd();
+ immUnbindProgram();
+ }
+
+ glDisable(GL_BLEND);
+}
+
+void ui_draw_popover_back(ARegion *ar, uiStyle *UNUSED(style), uiBlock *block, rcti *rect)
+{
+ if (block) {
+ float mval_origin[2] = {block->mx, block->my};
+ ui_window_to_block_fl(ar, block, &mval_origin[0], &mval_origin[1]);
+ ui_draw_popover_back_impl(&wcol_menu_back, rect, block->direction, mval_origin);
+ }
+ else {
+ uiWidgetType *wt = widget_type(UI_WTYPE_MENU_BACK);
+
+ wt->state(wt, 0);
+ wt->draw(&wt->wcol, rect, 0, 0);
+ }
+}
+
static void draw_disk_shaded(
float start, float angle,
float radius_int, float radius_ext, int subd,
@@ -4001,33 +4734,21 @@ static void draw_disk_shaded(
float y1, y2;
float fac;
unsigned char r_col[4];
+ unsigned int pos, col;
- glBegin(GL_TRIANGLE_STRIP);
-
- s = sinf(start);
- c = cosf(start);
-
- y1 = s * radius_int;
- y2 = s * radius_ext;
-
+ Gwn_VertFormat *format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
if (shaded) {
- fac = (y1 + radius_ext) * radius_ext_scale;
- round_box_shade_col4_r(r_col, col1, col2, fac);
-
- glColor4ubv(r_col);
+ col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
}
-
- glVertex2f(c * radius_int, s * radius_int);
-
- if (shaded) {
- fac = (y2 + radius_ext) * radius_ext_scale;
- round_box_shade_col4_r(r_col, col1, col2, fac);
-
- glColor4ubv(r_col);
+ else {
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ubv((unsigned char *)col1);
}
- glVertex2f(c * radius_ext, s * radius_ext);
- for (i = 1; i < subd; i++) {
+ immBegin(GWN_PRIM_TRI_STRIP, subd * 2);
+ for (i = 0; i < subd; i++) {
float a;
a = start + ((i) / (float)(subd - 1)) * angle;
@@ -4039,20 +4760,20 @@ static void draw_disk_shaded(
if (shaded) {
fac = (y1 + radius_ext) * radius_ext_scale;
round_box_shade_col4_r(r_col, col1, col2, fac);
-
- glColor4ubv(r_col);
+ immAttrib4ubv(col, r_col);
}
- glVertex2f(c * radius_int, s * radius_int);
+ immVertex2f(pos, c * radius_int, s * radius_int);
if (shaded) {
fac = (y2 + radius_ext) * radius_ext_scale;
round_box_shade_col4_r(r_col, col1, col2, fac);
-
- glColor4ubv(r_col);
+ immAttrib4ubv(col, r_col);
}
- glVertex2f(c * radius_ext, s * radius_ext);
+ immVertex2f(pos, c * radius_ext, s * radius_ext);
}
- glEnd();
+ immEnd();
+
+ immUnbindProgram();
}
void ui_draw_pie_center(uiBlock *block)
@@ -4071,8 +4792,8 @@ void ui_draw_pie_center(uiBlock *block)
float angle = atan2f(pie_dir[1], pie_dir[0]);
float range = (block->pie_data.flags & UI_PIE_DEGREES_RANGE_LARGE) ? M_PI_2 : M_PI_4;
- glPushMatrix();
- glTranslatef(cx, cy, 0.0f);
+ gpuPushMatrix();
+ gpuTranslate2f(cx, cy);
glEnable(GL_BLEND);
if (btheme->tui.wcol_pie_menu.shaded) {
@@ -4081,8 +4802,7 @@ void ui_draw_pie_center(uiBlock *block)
draw_disk_shaded(0.0f, (float)(M_PI * 2.0), pie_radius_internal, pie_radius_external, subd, col1, col2, true);
}
else {
- glColor4ubv((GLubyte *)btheme->tui.wcol_pie_menu.inner);
- draw_disk_shaded(0.0f, (float)(M_PI * 2.0), pie_radius_internal, pie_radius_external, subd, NULL, NULL, false);
+ draw_disk_shaded(0.0f, (float)(M_PI * 2.0), pie_radius_internal, pie_radius_external, subd, btheme->tui.wcol_pie_menu.inner, NULL, false);
}
if (!(block->pie_data.flags & UI_PIE_INVALID_DIR)) {
@@ -4092,25 +4812,34 @@ void ui_draw_pie_center(uiBlock *block)
draw_disk_shaded(angle - range / 2.0f, range, pie_radius_internal, pie_radius_external, subd, col1, col2, true);
}
else {
- glColor4ubv((GLubyte *)btheme->tui.wcol_pie_menu.inner_sel);
- draw_disk_shaded(angle - range / 2.0f, range, pie_radius_internal, pie_radius_external, subd, NULL, NULL, false);
+ draw_disk_shaded(angle - range / 2.0f, range, pie_radius_internal, pie_radius_external, subd, btheme->tui.wcol_pie_menu.inner_sel, NULL, false);
}
}
- glColor4ubv((GLubyte *)btheme->tui.wcol_pie_menu.outline);
- glutil_draw_lined_arc(0.0f, (float)M_PI * 2.0f, pie_radius_internal, subd);
- glutil_draw_lined_arc(0.0f, (float)M_PI * 2.0f, pie_radius_external, subd);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ubv((unsigned char *)btheme->tui.wcol_pie_menu.outline);
+
+ imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, pie_radius_internal, subd);
+ imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, pie_radius_external, subd);
+
+ immUnbindProgram();
if (U.pie_menu_confirm > 0 && !(block->pie_data.flags & (UI_PIE_INVALID_DIR | UI_PIE_CLICK_STYLE))) {
float pie_confirm_radius = U.pixelsize * (pie_radius_internal + U.pie_menu_confirm);
float pie_confirm_external = U.pixelsize * (pie_radius_internal + U.pie_menu_confirm + 7.0f);
- glColor4ub(btheme->tui.wcol_pie_menu.text_sel[0], btheme->tui.wcol_pie_menu.text_sel[1], btheme->tui.wcol_pie_menu.text_sel[2], 64);
- draw_disk_shaded(angle - range / 2.0f, range, pie_confirm_radius, pie_confirm_external, subd, NULL, NULL, false);
+ const char col[4] = {btheme->tui.wcol_pie_menu.text_sel[0],
+ btheme->tui.wcol_pie_menu.text_sel[1],
+ btheme->tui.wcol_pie_menu.text_sel[2],
+ 64};
+
+ draw_disk_shaded(angle - range / 2.0f, range, pie_confirm_radius, pie_confirm_external, subd, col, NULL, false);
}
glDisable(GL_BLEND);
- glPopMatrix();
+ gpuPopMatrix();
}
@@ -4194,8 +4923,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic
UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0');
}
- glColor4ubv((unsigned char *)wt->wcol.text);
- UI_fontstyle_draw(fstyle, rect, drawstr);
+ UI_fontstyle_draw(fstyle, rect, drawstr, (unsigned char *)wt->wcol.text);
}
/* part text right aligned */
@@ -4203,7 +4931,7 @@ void ui_draw_menu_item(uiFontStyle *fstyle, rcti *rect, const char *name, int ic
if (cpoin) {
fstyle->align = UI_STYLE_TEXT_RIGHT;
rect->xmax = _rect.xmax - 5;
- UI_fontstyle_draw(fstyle, rect, cpoin + 1);
+ UI_fontstyle_draw(fstyle, rect, cpoin + 1, (unsigned char *)wt->wcol.text);
*cpoin = UI_SEP_CHAR;
}
}
@@ -4261,8 +4989,7 @@ void ui_draw_preview_item(uiFontStyle *fstyle, rcti *rect, const char *name, int
BLI_strncpy(drawstr, name, sizeof(drawstr));
UI_text_clip_middle_ex(fstyle, drawstr, okwidth, minwidth, max_len, '\0');
- glColor4ubv((unsigned char *)wt->wcol.text);
- UI_fontstyle_draw(fstyle, &trect, drawstr);
+ UI_fontstyle_draw(fstyle, &trect, drawstr, (unsigned char *)wt->wcol.text);
}
}
diff --git a/source/blender/editors/interface/resources.c b/source/blender/editors/interface/resources.c
index ce25817c147..c78342a0713 100644
--- a/source/blender/editors/interface/resources.c
+++ b/source/blender/editors/interface/resources.c
@@ -54,6 +54,8 @@
#include "BIF_gl.h"
+#include "BLF_api.h"
+
#include "UI_interface.h"
#include "UI_interface_icons.h"
@@ -154,18 +156,15 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
case SPACE_CONSOLE:
ts = &btheme->tconsole;
break;
- case SPACE_TIME:
- ts = &btheme->ttime;
- break;
case SPACE_NODE:
ts = &btheme->tnode;
break;
- case SPACE_LOGIC:
- ts = &btheme->tlogic;
- break;
case SPACE_CLIP:
ts = &btheme->tclip;
break;
+ case SPACE_TOPBAR:
+ ts = &btheme->ttopbar;
+ break;
default:
ts = &btheme->tv3d;
break;
@@ -231,6 +230,7 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
headerdesel[0] = cp[0] > 10 ? cp[0] - 10 : 0;
headerdesel[1] = cp[1] > 10 ? cp[1] - 10 : 0;
headerdesel[2] = cp[2] > 10 ? cp[2] - 10 : 0;
+ headerdesel[3] = cp[3];
cp = headerdesel;
break;
case TH_HEADER_TEXT:
@@ -659,6 +659,9 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
case TH_WIDGET_EMBOSS:
cp = btheme->tui.widget_emboss; break;
+ case TH_EDITOR_OUTLINE:
+ cp = btheme->tui.editor_outline;
+ break;
case TH_AXIS_X:
cp = btheme->tui.xaxis; break;
case TH_AXIS_Y:
@@ -666,6 +669,17 @@ const unsigned char *UI_ThemeGetColorPtr(bTheme *btheme, int spacetype, int colo
case TH_AXIS_Z:
cp = btheme->tui.zaxis; break;
+ case TH_MANIPULATOR_HI:
+ cp = btheme->tui.manipulator_hi; break;
+ case TH_MANIPULATOR_PRIMARY:
+ cp = btheme->tui.manipulator_primary; break;
+ case TH_MANIPULATOR_SECONDARY:
+ cp = btheme->tui.manipulator_secondary; break;
+ case TH_MANIPULATOR_A:
+ cp = btheme->tui.manipulator_a; break;
+ case TH_MANIPULATOR_B:
+ cp = btheme->tui.manipulator_b; break;
+
case TH_INFO_SELECTED:
cp = ts->info_selected;
break;
@@ -836,6 +850,15 @@ static void ui_theme_space_init_handles_color(ThemeSpace *theme_space)
rgba_char_args_set(theme_space->act_spline, 0xdb, 0x25, 0x12, 255);
}
+static void ui_theme_space_init_manipulator_colors(bTheme *btheme)
+{
+ rgba_char_args_set(btheme->tui.manipulator_hi, 255, 255, 255, 255);
+ rgba_char_args_set(btheme->tui.manipulator_primary, 222, 255, 13, 255);
+ rgba_char_args_set(btheme->tui.manipulator_secondary, 0, 255, 255, 255);
+ rgba_char_args_set(btheme->tui.manipulator_a, 23, 127, 23, 255);
+ rgba_char_args_set(btheme->tui.manipulator_b, 127, 23, 23, 255);
+}
+
/**
* initialize default theme
* \note: when you add new colors, created & saved themes need initialized
@@ -862,6 +885,7 @@ void ui_theme_init_default(void)
btheme->tui.iconfile[0] = 0;
rgba_char_args_set(btheme->tui.wcol_tooltip.text, 255, 255, 255, 255);
rgba_char_args_set_fl(btheme->tui.widget_emboss, 1.0f, 1.0f, 1.0f, 0.02f);
+ rgba_char_args_set_fl(btheme->tui.editor_outline, 0.25f, 0.25f, 0.25f, 1.0f);
rgba_char_args_set(btheme->tui.xaxis, 220, 0, 0, 255);
rgba_char_args_set(btheme->tui.yaxis, 0, 220, 0, 255);
@@ -876,6 +900,9 @@ void ui_theme_init_default(void)
/* common (new) variables */
ui_theme_init_new(btheme);
+ /* Manipulator. */
+ ui_theme_space_init_manipulator_colors(btheme);
+
/* space view3d */
rgba_char_args_set_fl(btheme->tv3d.back, 0.225, 0.225, 0.225, 1.0);
rgba_char_args_set(btheme->tv3d.text, 0, 0, 0, 255);
@@ -1185,10 +1212,6 @@ void ui_theme_init_default(void)
rgba_char_args_set(btheme->tnode.console_output, 223, 202, 53, 255); /* interface nodes */
btheme->tnode.noodle_curving = 5;
- /* space logic */
- btheme->tlogic = btheme->tv3d;
- rgba_char_args_set(btheme->tlogic.back, 100, 100, 100, 255);
-
/* space clip */
btheme->tclip = btheme->tv3d;
@@ -1207,6 +1230,14 @@ void ui_theme_init_default(void)
rgba_char_args_set(btheme->tclip.strip_select, 0xff, 0x8c, 0x00, 0xff);
btheme->tclip.handle_vertex_size = 5;
ui_theme_space_init_handles_color(&btheme->tclip);
+
+ /* space topbar */
+ char tmp[4];
+ btheme->ttopbar = btheme->tv3d;
+ /* swap colors */
+ copy_v4_v4_char(tmp, btheme->ttopbar.header);
+ copy_v4_v4_char(btheme->ttopbar.header, btheme->ttopbar.tab_inactive);
+ copy_v4_v4_char(btheme->ttopbar.back, tmp);
}
void ui_style_init_default(void)
@@ -1273,25 +1304,35 @@ void UI_ThemeColor4(int colorid)
cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
glColor4ubv(cp);
-
}
/* set the color with offset for shades */
void UI_ThemeColorShade(int colorid, int offset)
{
- int r, g, b;
+ unsigned char col[4];
+ UI_GetThemeColorShade4ubv(colorid, offset, col);
+ glColor4ubv(col);
+}
+
+void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
+{
+ int r, g, b, a;
const unsigned char *cp;
cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
- r = offset + (int) cp[0];
+ r = coloffset + (int) cp[0];
CLAMP(r, 0, 255);
- g = offset + (int) cp[1];
+ g = coloffset + (int) cp[1];
CLAMP(g, 0, 255);
- b = offset + (int) cp[2];
+ b = coloffset + (int) cp[2];
CLAMP(b, 0, 255);
- glColor4ub(r, g, b, cp[3]);
+ a = alphaoffset + (int) cp[3];
+ CLAMP(a, 0, 255);
+
+ glColor4ub(r, g, b, a);
}
-void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
+
+void UI_GetThemeColorShadeAlpha4ubv(int colorid, int coloffset, int alphaoffset, unsigned char col[4])
{
int r, g, b, a;
const unsigned char *cp;
@@ -1305,7 +1346,11 @@ void UI_ThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
CLAMP(b, 0, 255);
a = alphaoffset + (int) cp[3];
CLAMP(a, 0, 255);
- glColor4ub(r, g, b, a);
+
+ col[0] = r;
+ col[1] = g;
+ col[2] = b;
+ col[3] = a;
}
void UI_GetThemeColorBlend3ubv(int colorid1, int colorid2, float fac, unsigned char col[3])
@@ -1321,6 +1366,19 @@ void UI_GetThemeColorBlend3ubv(int colorid1, int colorid2, float fac, unsigned c
col[2] = floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
}
+void UI_GetThemeColorBlend3f(int colorid1, int colorid2, float fac, float r_col[3])
+{
+ const unsigned char *cp1, *cp2;
+
+ cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
+ cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
+
+ CLAMP(fac, 0.0f, 1.0f);
+ r_col[0] = ((1.0f - fac) * cp1[0] + fac * cp2[0]) / 255.0f;
+ r_col[1] = ((1.0f - fac) * cp1[1] + fac * cp2[1]) / 255.0f;
+ r_col[2] = ((1.0f - fac) * cp1[2] + fac * cp2[2]) / 255.0f;
+}
+
/* blend between to theme colors, and set it */
void UI_ThemeColorBlend(int colorid1, int colorid2, float fac)
{
@@ -1373,6 +1431,12 @@ void UI_ThemeColorBlendShadeAlpha(int colorid1, int colorid2, float fac, int off
glColor4ub(r, g, b, a);
}
+void UI_FontThemeColor(int fontid, int colorid)
+{
+ unsigned char color[4];
+ UI_GetThemeColor4ubv(colorid, color);
+ BLF_color4ubv(fontid, color);
+}
/* get individual values, not scaled */
float UI_GetThemeValuef(int colorid)
@@ -1471,6 +1535,111 @@ void UI_GetThemeColorShade3ubv(int colorid, int offset, unsigned char col[3])
col[2] = b;
}
+void UI_GetThemeColorBlendShade3ubv(int colorid1, int colorid2, float fac, int offset, unsigned char col[3])
+{
+ const unsigned char *cp1, *cp2;
+
+ cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
+ cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
+
+ CLAMP(fac, 0.0f, 1.0f);
+
+ float blend[3];
+ blend[0] = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
+ blend[1] = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
+ blend[2] = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
+
+ unit_float_to_uchar_clamp_v3(col, blend);
+}
+
+void UI_GetThemeColorShade4ubv(int colorid, int offset, unsigned char col[4])
+{
+ int r, g, b;
+ const unsigned char *cp;
+
+ cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
+ r = offset + (int) cp[0];
+ CLAMP(r, 0, 255);
+ g = offset + (int) cp[1];
+ CLAMP(g, 0, 255);
+ b = offset + (int) cp[2];
+ CLAMP(b, 0, 255);
+
+ col[0] = r;
+ col[1] = g;
+ col[2] = b;
+ col[3] = cp[3];
+}
+
+void UI_GetThemeColorShadeAlpha4fv(int colorid, int coloffset, int alphaoffset, float col[4])
+{
+ int r, g, b, a;
+ const unsigned char *cp;
+
+ cp = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid);
+
+ r = coloffset + (int) cp[0];
+ CLAMP(r, 0, 255);
+ g = coloffset + (int) cp[1];
+ CLAMP(g, 0, 255);
+ b = coloffset + (int) cp[2];
+ CLAMP(b, 0, 255);
+ a = alphaoffset + (int) cp[3];
+ CLAMP(b, 0, 255);
+
+ col[0] = ((float)r) / 255.0f;
+ col[1] = ((float)g) / 255.0f;
+ col[2] = ((float)b) / 255.0f;
+ col[3] = ((float)a) / 255.0f;
+}
+
+void UI_GetThemeColorBlendShade3fv(int colorid1, int colorid2, float fac, int offset, float col[3])
+{
+ int r, g, b;
+ const unsigned char *cp1, *cp2;
+
+ cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
+ cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
+
+ CLAMP(fac, 0.0f, 1.0f);
+
+ r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
+ CLAMP(r, 0, 255);
+ g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
+ CLAMP(g, 0, 255);
+ b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
+ CLAMP(b, 0, 255);
+
+ col[0] = ((float)r) / 255.0f;
+ col[1] = ((float)g) / 255.0f;
+ col[2] = ((float)b) / 255.0f;
+}
+
+void UI_GetThemeColorBlendShade4fv(int colorid1, int colorid2, float fac, int offset, float col[4])
+{
+ int r, g, b, a;
+ const unsigned char *cp1, *cp2;
+
+ cp1 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid1);
+ cp2 = UI_ThemeGetColorPtr(theme_active, theme_spacetype, colorid2);
+
+ CLAMP(fac, 0.0f, 1.0f);
+
+ r = offset + floorf((1.0f - fac) * cp1[0] + fac * cp2[0]);
+ CLAMP(r, 0, 255);
+ g = offset + floorf((1.0f - fac) * cp1[1] + fac * cp2[1]);
+ CLAMP(g, 0, 255);
+ b = offset + floorf((1.0f - fac) * cp1[2] + fac * cp2[2]);
+ CLAMP(b, 0, 255);
+ a = offset + floorf((1.0f - fac) * cp1[3] + fac * cp2[3]);
+ CLAMP(a, 0, 255);
+
+ col[0] = ((float)r) / 255.0f;
+ col[1] = ((float)g) / 255.0f;
+ col[2] = ((float)b) / 255.0f;
+ col[3] = ((float)a) / 255.0f;
+}
+
/* get the color, in char pointer */
void UI_GetThemeColor3ubv(int colorid, unsigned char col[3])
{
@@ -1659,11 +1828,9 @@ void init_userdef_do_versions(void)
U.savetime = 1;
// XXX error(STRINGIFY(BLENDER_STARTUP_FILE)" is buggy, please consider removing it.\n");
}
- /* transform widget settings */
- if (U.tw_hotspot == 0) {
- U.tw_hotspot = 14;
- U.tw_size = 25; /* percentage of window size */
- U.tw_handlesize = 16; /* percentage of widget radius */
+ if (U.manipulator_size == 0) {
+ U.manipulator_size = 75;
+ U.manipulator_flag |= USER_MANIPULATOR_DRAW;
}
if (U.pad_rot_angle == 0.0f)
U.pad_rot_angle = 15.0f;
@@ -1943,13 +2110,6 @@ void init_userdef_do_versions(void)
if (btheme->tui.wcol_num.outline[3] == 0)
ui_widget_color_init(&btheme->tui);
-
- /* Logic editor theme, check for alpha==0 is safe, then color was never set */
- if (btheme->tlogic.syntaxn[3] == 0) {
- /* re-uses syntax color storage */
- btheme->tlogic = btheme->tv3d;
- rgba_char_args_set(btheme->tlogic.back, 100, 100, 100, 255);
- }
rgba_char_args_set_fl(btheme->tinfo.back, 0.45, 0.45, 0.45, 1.0);
rgba_char_args_set_fl(btheme->tuserpref.back, 0.45, 0.45, 0.45, 1.0);
@@ -1986,8 +2146,6 @@ void init_userdef_do_versions(void)
strcpy(km->idname, "3D View Generic");
else if (STREQ(km->idname, "EditMesh"))
strcpy(km->idname, "Mesh");
- else if (STREQ(km->idname, "TimeLine"))
- strcpy(km->idname, "Timeline");
else if (STREQ(km->idname, "UVEdit"))
strcpy(km->idname, "UV Editor");
else if (STREQ(km->idname, "Animation_Channels"))
@@ -2014,10 +2172,6 @@ void init_userdef_do_versions(void)
strcpy(km->idname, "Property Editor");
}
}
- if (!USER_VERSION_ATLEAST(250, 16)) {
- if (U.wmdrawmethod == USER_DRAW_TRIPLE)
- U.wmdrawmethod = USER_DRAW_AUTOMATIC;
- }
if (!USER_VERSION_ATLEAST(252, 3)) {
if (U.flag & USER_LMOUSESELECT)
@@ -2497,9 +2651,6 @@ void init_userdef_do_versions(void)
if (!USER_VERSION_ATLEAST(269, 9)) {
bTheme *btheme;
-
- U.tw_size = U.tw_size * 5.0f;
-
/* Action Editor (and NLA Editor) - Keyframe Colors */
/* Graph Editor - larger vertex size defaults */
for (btheme = U.themes.first; btheme; btheme = btheme->next) {
@@ -2633,10 +2784,6 @@ void init_userdef_do_versions(void)
rgba_char_args_set(btheme->tnode.gp_vertex, 0, 0, 0, 255);
rgba_char_args_set(btheme->tnode.gp_vertex_select, 255, 133, 0, 255);
btheme->tnode.gp_vertex_size = 3;
-
- /* Timeline Keyframe Indicators */
- rgba_char_args_set(btheme->ttime.time_keyframe, 0xDD, 0xD7, 0x00, 0xFF);
- rgba_char_args_set(btheme->ttime.time_gp_keyframe, 0xB5, 0xE6, 0x1D, 0xFF);
}
}
@@ -2766,13 +2913,97 @@ void init_userdef_do_versions(void)
U.transopts &= ~(
USER_TR_DEPRECATED_2 | USER_TR_DEPRECATED_3 | USER_TR_DEPRECATED_4 |
USER_TR_DEPRECATED_6 | USER_TR_DEPRECATED_7);
- U.gameflags &= ~(
- USER_GL_RENDER_DEPRECATED_0 | USER_GL_RENDER_DEPRECATED_1 |
- USER_GL_RENDER_DEPRECATED_3 | USER_GL_RENDER_DEPRECATED_4);
U.uiflag |= USER_LOCK_CURSOR_ADJUST;
}
+ if (!USER_VERSION_ATLEAST(280, 9)) {
+ /* interface_widgets.c */
+ struct uiWidgetColors wcol_tab = {
+ {60, 60, 60, 255},
+ {83, 83, 83, 255},
+ {114, 114, 114, 255},
+ {90, 90, 90, 255},
+
+ {0, 0, 0, 255},
+ {0, 0, 0, 255},
+
+ 0,
+ 0, 0
+ };
+
+ for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) {
+ char tmp[4];
+
+ btheme->tui.wcol_tab = wcol_tab;
+ btheme->ttopbar = btheme->tv3d;
+ /* swap colors */
+ copy_v4_v4_char(tmp, btheme->ttopbar.header);
+ copy_v4_v4_char(btheme->ttopbar.header, btheme->ttopbar.tab_inactive);
+ copy_v4_v4_char(btheme->ttopbar.back, tmp);
+ }
+ }
+
+ if (!USER_VERSION_ATLEAST(280, 9)) {
+ /* Timeline removal */
+ for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) {
+ if (btheme->tipo.anim_active[3] == 0) {
+ rgba_char_args_set(btheme->tipo.anim_active, 204, 112, 26, 102);
+ }
+ if (btheme->tseq.anim_active[3] == 0) {
+ rgba_char_args_set(btheme->tseq.anim_active, 204, 112, 26, 102);
+ }
+ }
+ }
+
+ if (!USER_VERSION_ATLEAST(280, 10)) {
+ /* Roundness */
+ for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) {
+ btheme->tui.wcol_regular.roundness = 0.25f;
+ btheme->tui.wcol_tool.roundness = 0.2f;
+ btheme->tui.wcol_text.roundness = 0.2f;
+ btheme->tui.wcol_radio.roundness = 0.2f;
+ btheme->tui.wcol_option.roundness = 0.333333f;
+ btheme->tui.wcol_toggle.roundness = 0.25f;
+ btheme->tui.wcol_num.roundness = 0.5f;
+ btheme->tui.wcol_numslider.roundness = 0.5f;
+ btheme->tui.wcol_tab.roundness = 0.25f;
+ btheme->tui.wcol_menu.roundness = 0.2f;
+ btheme->tui.wcol_pulldown.roundness = 0.2f;
+ btheme->tui.wcol_menu_back.roundness = 0.25f;
+ btheme->tui.wcol_menu_item.roundness = 0.25f;
+ btheme->tui.wcol_tooltip.roundness = 0.25f;
+ btheme->tui.wcol_box.roundness = 0.2f;
+ btheme->tui.wcol_scroll.roundness = 0.5f;
+ btheme->tui.wcol_progress.roundness = 0.25f;
+ btheme->tui.wcol_list_item.roundness = 0.2f;
+ btheme->tui.wcol_pie_menu.roundness = 0.5f;
+ rgba_char_args_set_fl(btheme->tui.editor_outline, 0.25f, 0.25f, 0.25f, 1.0f);
+ }
+ }
+
+ if (((bTheme *)U.themes.first)->tui.wcol_toolbar_item.text[3] == 0) {
+ struct uiWidgetColors wcol_toolbar_item = {
+ .outline = {0x19, 0x19, 0x19, 0xff},
+ .inner = {0x46, 0x46, 0x46, 0xff},
+ .inner_sel = {0xb4, 0xb4, 0xb4, 0xff},
+ .item = {0x19, 0x19, 0x19, 0xff},
+
+ .text = {0xff, 0xff, 0xff, 0xff},
+ .text_sel = {0x33, 0x33, 0x33, 0xff},
+
+ .shaded = 0,
+ .shadetop = 0,
+ .shadedown = 0,
+ .alpha_check = 0,
+ .roundness = 0.3f,
+ };
+ for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) {
+ btheme->tui.wcol_toolbar_item = wcol_toolbar_item;
+ btheme->tui.icon_saturation = 0.4f;
+ }
+ }
+
/**
* Include next version bump.
*/
@@ -2780,17 +3011,20 @@ void init_userdef_do_versions(void)
/* (keep this block even if it becomes empty). */
}
+ if (((bTheme *)U.themes.first)->tui.manipulator_hi[3] == 0) {
+ for (bTheme *btheme = U.themes.first; btheme; btheme = btheme->next) {
+ ui_theme_space_init_manipulator_colors(btheme);
+ }
+ }
+
if (U.pixelsize == 0.0f)
U.pixelsize = 1.0f;
if (U.image_draw_method == 0)
U.image_draw_method = IMAGE_DRAW_METHOD_2DTEXTURE;
- // keep the following until the new audaspace is default to be built with
-#ifdef WITH_SYSTEM_AUDASPACE
// we default to the first audio device
U.audiodevice = 0;
-#endif
/* Not versioning, just avoid errors. */
#ifndef WITH_CYCLES
diff --git a/source/blender/editors/interface/view2d.c b/source/blender/editors/interface/view2d.c
index f530130025b..c1791998ec7 100644
--- a/source/blender/editors/interface/view2d.c
+++ b/source/blender/editors/interface/view2d.c
@@ -49,11 +49,11 @@
#include "BKE_screen.h"
#include "BKE_global.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "WM_api.h"
-#include "BIF_gl.h"
-
#include "BLF_api.h"
#include "ED_screen.h"
@@ -147,50 +147,51 @@ static void view2d_masks(View2D *v2d, bool check_scrollers)
scroll = view2d_scroll_mapped(v2d->scroll);
- /* scrollers shrink mask area, but should be based off regionsize
+ /* scrollers are based off regionsize
* - they can only be on one to two edges of the region they define
* - if they overlap, they must not occupy the corners (which are reserved for other widgets)
*/
if (scroll) {
+ int scroll_width = (v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) ? V2D_SCROLL_WIDTH_TEXT : v2d->size_vert;
+ int scroll_height = (v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) ? V2D_SCROLL_HEIGHT_TEXT : v2d->size_hor;
+
+ CLAMP_MIN(scroll_width, V2D_SCROLL_WIDTH_MIN);
+ CLAMP_MIN(scroll_height, V2D_SCROLL_HEIGHT_MIN);
+
/* vertical scroller */
if (scroll & V2D_SCROLL_LEFT) {
/* on left-hand edge of region */
v2d->vert = v2d->mask;
- v2d->vert.xmax = V2D_SCROLL_WIDTH;
- v2d->mask.xmin = v2d->vert.xmax + 1;
+ v2d->vert.xmax = scroll_width;
}
else if (scroll & V2D_SCROLL_RIGHT) {
/* on right-hand edge of region */
v2d->vert = v2d->mask;
v2d->vert.xmax++; /* one pixel extra... was leaving a minor gap... */
- v2d->vert.xmin = v2d->vert.xmax - V2D_SCROLL_WIDTH;
- v2d->mask.xmax = v2d->vert.xmin - 1;
+ v2d->vert.xmin = v2d->vert.xmax - scroll_width;
}
/* horizontal scroller */
if (scroll & (V2D_SCROLL_BOTTOM)) {
/* on bottom edge of region */
v2d->hor = v2d->mask;
- v2d->hor.ymax = V2D_SCROLL_HEIGHT;
- v2d->mask.ymin = v2d->hor.ymax + 1;
+ v2d->hor.ymax = scroll_height;
}
else if (scroll & V2D_SCROLL_TOP) {
/* on upper edge of region */
v2d->hor = v2d->mask;
- v2d->hor.ymin = v2d->hor.ymax - V2D_SCROLL_HEIGHT;
- v2d->mask.ymax = v2d->hor.ymin - 1;
+ v2d->hor.ymin = v2d->hor.ymax - scroll_height;
}
/* adjust vertical scroller if there's a horizontal scroller, to leave corner free */
if (scroll & V2D_SCROLL_VERTICAL) {
- /* just set y min/max for vertical scroller to y min/max of mask as appropriate */
if (scroll & (V2D_SCROLL_BOTTOM)) {
/* on bottom edge of region */
- v2d->vert.ymin = v2d->mask.ymin;
+ v2d->vert.ymin = v2d->hor.ymax;
}
else if (scroll & V2D_SCROLL_TOP) {
/* on upper edge of region */
- v2d->vert.ymax = v2d->mask.ymax;
+ v2d->vert.ymax = v2d->hor.ymin;
}
}
}
@@ -357,6 +358,11 @@ void UI_view2d_region_reinit(View2D *v2d, short type, int winx, int winy)
/* set masks (always do), but leave scroller scheck to totrect_set */
view2d_masks(v2d, 0);
+ if (do_init) {
+ /* Visible by default. */
+ v2d->alpha_hor = v2d->alpha_vert = 255;
+ }
+
/* set 'tot' rect before setting cur? */
/* XXX confusing stuff here still - I made this function not check scroller hide - that happens in totrect_set */
if (tot_changed)
@@ -1107,9 +1113,6 @@ void UI_view2d_view_ortho(View2D *v2d)
/* set matrix on all appropriate axes */
wmOrtho2(curmasked.xmin, curmasked.xmax, curmasked.ymin, curmasked.ymax);
-
- /* XXX is this necessary? */
- glLoadIdentity();
}
/**
@@ -1137,9 +1140,6 @@ void UI_view2d_view_orthoSpecial(ARegion *ar, View2D *v2d, const bool xaxis)
wmOrtho2(curmasked.xmin - xofs, curmasked.xmax - xofs, -yofs, ar->winy - yofs);
else
wmOrtho2(-xofs, ar->winx - xofs, curmasked.ymin - yofs, curmasked.ymax - yofs);
-
- /* XXX is this necessary? */
- glLoadIdentity();
}
@@ -1151,7 +1151,7 @@ void UI_view2d_view_restore(const bContext *C)
int height = BLI_rcti_size_y(&ar->winrct) + 1;
wmOrtho2(0.0f, (float)width, 0.0f, (float)height);
- glLoadIdentity();
+ gpuLoadIdentity();
// ED_region_pixelspace(CTX_wm_region(C));
}
@@ -1305,12 +1305,45 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
{
float vec1[2], vec2[2];
int a, step;
+ int vertical_minor_step = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC),
+ horizontal_major_step = (BLI_rcti_size_y(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC);
+ unsigned char grid_line_color[3];
/* check for grid first, as it may not exist */
if (grid == NULL)
return;
- glBegin(GL_LINES);
+ /* Count the needed vertices for the gridlines */
+ unsigned vertex_count = 0;
+ if (flag & V2D_VERTICAL_LINES) {
+ /* vertical lines */
+ vertex_count += 2 * vertical_minor_step; /* minor gridlines */
+ vertex_count += 2 * (vertical_minor_step + 2); /* major gridlines */
+ }
+ if (flag & V2D_HORIZONTAL_LINES) {
+ /* horizontal lines */
+ vertex_count += 2 * (horizontal_major_step + 1); /* major gridlines */
+
+ /* fine lines */
+ if (flag & V2D_HORIZONTAL_FINELINES)
+ vertex_count += 2 * (horizontal_major_step + 1);
+ }
+ /* axes */
+ if (flag & V2D_HORIZONTAL_AXIS)
+ vertex_count += 2;
+ if (flag & V2D_VERTICAL_AXIS)
+ vertex_count += 2;
+
+ /* If there is nothing to render, exit early */
+ if (vertex_count == 0)
+ return;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GWN_PRIM_LINES, vertex_count);
/* vertical lines */
if (flag & V2D_VERTICAL_LINES) {
@@ -1320,24 +1353,31 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
vec2[1] = v2d->cur.ymax;
/* minor gridlines */
- step = (BLI_rcti_size_x(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC);
- UI_ThemeColor(TH_GRID);
-
- for (a = 0; a < step; a++) {
- glVertex2fv(vec1);
- glVertex2fv(vec2);
-
- vec2[0] = vec1[0] += grid->dx;
+ step = vertical_minor_step;
+ if (step != 0) {
+ UI_GetThemeColor3ubv(TH_GRID, grid_line_color);
+
+ for (a = 0; a < step; a++) {
+ immSkipAttrib(color);
+ immVertex2fv(pos, vec1);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2fv(pos, vec2);
+
+ vec2[0] = vec1[0] += grid->dx;
+ }
}
/* major gridlines */
vec2[0] = vec1[0] -= 0.5f * grid->dx;
- UI_ThemeColorShade(TH_GRID, 16);
+
+ UI_GetThemeColorShade3ubv(TH_GRID, 16, grid_line_color);
step++;
for (a = 0; a <= step; a++) {
- glVertex2fv(vec1);
- glVertex2fv(vec2);
+ immSkipAttrib(color);
+ immVertex2fv(pos, vec1);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2fv(pos, vec2);
vec2[0] = vec1[0] -= grid->dx;
}
@@ -1350,12 +1390,15 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
vec1[0] = grid->startx;
vec2[0] = v2d->cur.xmax;
- step = (BLI_rcti_size_y(&v2d->mask) + 1) / (U.v2d_min_gridsize * UI_DPI_FAC);
-
- UI_ThemeColor(TH_GRID);
+ step = horizontal_major_step;
+
+ UI_GetThemeColor3ubv(TH_GRID, grid_line_color);
+
for (a = 0; a <= step; a++) {
- glVertex2fv(vec1);
- glVertex2fv(vec2);
+ immSkipAttrib(color);
+ immVertex2fv(pos, vec1);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2fv(pos, vec2);
vec2[1] = vec1[1] += grid->dy;
}
@@ -1365,10 +1408,12 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
step++;
if (flag & V2D_HORIZONTAL_FINELINES) {
- UI_ThemeColorShade(TH_GRID, 16);
+ UI_GetThemeColorShade3ubv(TH_GRID, 16, grid_line_color);
for (a = 0; a < step; a++) {
- glVertex2fv(vec1);
- glVertex2fv(vec2);
+ immSkipAttrib(color);
+ immVertex2fv(pos, vec1);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2fv(pos, vec2);
vec2[1] = vec1[1] -= grid->dy;
}
@@ -1376,7 +1421,7 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
}
/* Axes are drawn as darker lines */
- UI_ThemeColorShade(TH_GRID, -50);
+ UI_GetThemeColorShade3ubv(TH_GRID, -50, grid_line_color);
/* horizontal axis */
if (flag & V2D_HORIZONTAL_AXIS) {
@@ -1384,8 +1429,10 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
vec2[0] = v2d->cur.xmax;
vec1[1] = vec2[1] = 0.0f;
- glVertex2fv(vec1);
- glVertex2fv(vec2);
+ immSkipAttrib(color);
+ immVertex2fv(pos, vec1);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2fv(pos, vec2);
}
/* vertical axis */
@@ -1394,91 +1441,157 @@ void UI_view2d_grid_draw(View2D *v2d, View2DGrid *grid, int flag)
vec2[1] = v2d->cur.ymax;
vec1[0] = vec2[0] = 0.0f;
- glVertex2fv(vec1);
- glVertex2fv(vec2);
+ immSkipAttrib(color);
+ immVertex2fv(pos, vec1);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2fv(pos, vec2);
}
- glEnd();
+ immEnd();
+ immUnbindProgram();
}
/* Draw a constant grid in given 2d-region */
void UI_view2d_constant_grid_draw(View2D *v2d, float step)
{
- float start;
-
- UI_ThemeColorShade(TH_BACK, -10);
+ float start_x, start_y;
+ int count_x, count_y;
- start = v2d->cur.xmin - (float)fmod(v2d->cur.xmin, step);
+ start_x = v2d->cur.xmin;
+ if (start_x < 0.0)
+ start_x += -(float)fmod(v2d->cur.xmin, step);
+ else
+ start_x += (step - (float)fmod(v2d->cur.xmin, step));
+
+ if (start_x > v2d->cur.xmax)
+ count_x = 0;
+ else
+ count_x = (v2d->cur.xmax - start_x) / step + 1;
+
+ start_y = v2d->cur.ymin;
+ if (start_y < 0.0)
+ start_y += -(float)fmod(v2d->cur.ymin, step);
+ else
+ start_y += (step - (float)fabs(fmod(v2d->cur.ymin, step)));
+
+ if (start_y > v2d->cur.ymax)
+ count_y = 0;
+ else
+ count_y = (v2d->cur.ymax - start_y) / step + 1;
- glBegin(GL_LINES);
- for (; start < v2d->cur.xmax; start += step) {
- glVertex2f(start, v2d->cur.ymin);
- glVertex2f(start, v2d->cur.ymax);
- }
+ if (count_x > 0 || count_y > 0) {
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ float theme_color[3];
- start = v2d->cur.ymin - (float)fmod(v2d->cur.ymin, step);
- for (; start < v2d->cur.ymax; start += step) {
- glVertex2f(v2d->cur.xmin, start);
- glVertex2f(v2d->cur.xmax, start);
- }
+ UI_GetThemeColorShade3fv(TH_BACK, -10, theme_color);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GWN_PRIM_LINES, count_x * 2 + count_y * 2 + 4);
+
+ immAttrib3fv(color, theme_color);
+ for (int i = 0; i < count_x ; start_x += step, i++) {
+ immVertex2f(pos, start_x, v2d->cur.ymin);
+ immVertex2f(pos, start_x, v2d->cur.ymax);
+ }
+
+ for (int i = 0; i < count_y; start_y += step, i++) {
+ immVertex2f(pos, v2d->cur.xmin, start_y);
+ immVertex2f(pos, v2d->cur.xmax, start_y);
+ }
- /* X and Y axis */
- UI_ThemeColorShade(TH_BACK, -18);
- glVertex2f(0.0f, v2d->cur.ymin);
- glVertex2f(0.0f, v2d->cur.ymax);
- glVertex2f(v2d->cur.xmin, 0.0f);
- glVertex2f(v2d->cur.xmax, 0.0f);
+ /* X and Y axis */
+ UI_GetThemeColorShade3fv(TH_BACK, -18, theme_color);
+
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, 0.0f, v2d->cur.ymin);
+ immVertex2f(pos, 0.0f, v2d->cur.ymax);
+ immVertex2f(pos, v2d->cur.xmin, 0.0f);
+ immVertex2f(pos, v2d->cur.xmax, 0.0f);
- glEnd();
+ immEnd();
+ immUnbindProgram();
+ }
}
/* Draw a multi-level grid in given 2d-region */
void UI_view2d_multi_grid_draw(View2D *v2d, int colorid, float step, int level_size, int totlevels)
{
+ /* Exit if there is nothing to draw */
+ if (totlevels == 0)
+ return;
+
int offset = -10;
float lstep = step;
- int level;
+ unsigned char grid_line_color[3];
+
+ /* Make an estimate of at least how many vertices will be needed */
+ unsigned vertex_count = 4;
+ vertex_count += 2 * ((int)((v2d->cur.xmax - v2d->cur.xmin) / lstep) + 1);
+ vertex_count += 2 * ((int)((v2d->cur.ymax - v2d->cur.ymin) / lstep) + 1);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
glLineWidth(1.0f);
- for (level = 0; level < totlevels; ++level) {
- int i;
- float start;
-
- UI_ThemeColorShade(colorid, offset);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBeginAtMost(GWN_PRIM_LINES, vertex_count);
+
+ for (int level = 0; level < totlevels; ++level) {
+ UI_GetThemeColorShade3ubv(colorid, offset, grid_line_color);
- i = (v2d->cur.xmin >= 0.0f ? -(int)(-v2d->cur.xmin / lstep) : (int)(v2d->cur.xmin / lstep));
- start = i * lstep;
+ int i = (int)(v2d->cur.xmin / lstep);
+ if (v2d->cur.xmin > 0.0f)
+ i++;
+ float start = i * lstep;
- glBegin(GL_LINES);
for (; start < v2d->cur.xmax; start += lstep, ++i) {
if (i == 0 || (level < totlevels - 1 && i % level_size == 0))
continue;
- glVertex2f(start, v2d->cur.ymin);
- glVertex2f(start, v2d->cur.ymax);
+
+ immSkipAttrib(color);
+ immVertex2f(pos, start, v2d->cur.ymin);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2f(pos, start, v2d->cur.ymax);
}
- i = (v2d->cur.ymin >= 0.0f ? -(int)(-v2d->cur.ymin / lstep) : (int)(v2d->cur.ymin / lstep));
+ i = (int)(v2d->cur.ymin / lstep);
+ if (v2d->cur.ymin > 0.0f)
+ i++;
start = i * lstep;
for (; start < v2d->cur.ymax; start += lstep, ++i) {
if (i == 0 || (level < totlevels - 1 && i % level_size == 0))
continue;
- glVertex2f(v2d->cur.xmin, start);
- glVertex2f(v2d->cur.xmax, start);
+
+ immSkipAttrib(color);
+ immVertex2f(pos, v2d->cur.xmin, start);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2f(pos, v2d->cur.xmax, start);
}
- /* X and Y axis */
- UI_ThemeColorShade(colorid, offset - 8);
- glVertex2f(0.0f, v2d->cur.ymin);
- glVertex2f(0.0f, v2d->cur.ymax);
- glVertex2f(v2d->cur.xmin, 0.0f);
- glVertex2f(v2d->cur.xmax, 0.0f);
-
- glEnd();
-
lstep *= level_size;
offset -= 6;
}
+
+ /* X and Y axis */
+ UI_GetThemeColorShade3ubv(colorid, -18 + ((totlevels - 1) * -6), grid_line_color);
+
+ immSkipAttrib(color);
+ immVertex2f(pos, 0.0f, v2d->cur.ymin);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2f(pos, 0.0f, v2d->cur.ymax);
+
+ immSkipAttrib(color);
+ immVertex2f(pos, v2d->cur.xmin, 0.0f);
+ immAttrib3ubv(color, grid_line_color);
+ immVertex2f(pos, v2d->cur.xmax, 0.0f);
+
+ immEnd();
+ immUnbindProgram();
}
/* the price we pay for not exposting structs :( */
@@ -1534,11 +1647,14 @@ View2DScrollers *UI_view2d_scrollers_calc(
/* scrollers is allocated here... */
scrollers = MEM_callocN(sizeof(View2DScrollers), "View2DScrollers");
+ /* Always update before drawing (for dynamically sized scrollers). */
+ view2d_masks(v2d, false);
+
vert = v2d->vert;
hor = v2d->hor;
/* slider rects need to be smaller than region */
- smaller = (int)(0.2f * U.widget_unit);
+ smaller = (int)(0.1f * U.widget_unit);
hor.xmin += smaller;
hor.xmax -= smaller;
if (scroll & V2D_SCROLL_BOTTOM)
@@ -1697,9 +1813,15 @@ static void scroll_printstr(Scene *scene, float x, float y, float val, int power
/* Draw scrollbars in the given 2d-region */
void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *vs)
{
+ bTheme *btheme = UI_GetTheme();
Scene *scene = CTX_data_scene(C);
rcti vert, hor;
- int scroll = view2d_scroll_mapped(v2d->scroll);
+ const int scroll = view2d_scroll_mapped(v2d->scroll);
+ const char emboss_alpha = btheme->tui.widget_emboss[3];
+ unsigned char scrollers_back_color[4];
+
+ /* Color for scrollbar backs */
+ UI_GetThemeColor4ubv(TH_BACK, scrollers_back_color);
/* make copies of rects for less typing */
vert = vs->vert;
@@ -1707,11 +1829,10 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
/* horizontal scrollbar */
if (scroll & V2D_SCROLL_HORIZONTAL) {
- bTheme *btheme = UI_GetTheme();
uiWidgetColors wcol = btheme->tui.wcol_scroll;
+ const float alpha_fac = v2d->alpha_hor / 255.0f;
rcti slider;
int state;
- unsigned char col[4];
slider.xmin = vs->hor_min;
slider.xmax = vs->hor_max;
@@ -1720,6 +1841,11 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
state = (v2d->scroll_ui & V2D_SCROLL_H_ACTIVE) ? UI_SCROLL_PRESSED : 0;
+ wcol.inner[3] *= alpha_fac;
+ wcol.item[3] *= alpha_fac;
+ wcol.outline[3] *= alpha_fac;
+ btheme->tui.widget_emboss[3] *= alpha_fac; /* will be reset later */
+
/* show zoom handles if:
* - zooming on x-axis is allowed (no scroll otherwise)
* - slider bubble is large enough (no overdraw confusion)
@@ -1733,18 +1859,12 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
{
state |= UI_SCROLL_ARROWS;
}
-
- /* clean rect behind slider, but not with transparent background */
- UI_GetThemeColor4ubv(TH_BACK, col);
- if (col[3] == 255) {
- glColor3ub(col[0], col[1], col[2]);
- glRecti(v2d->hor.xmin, v2d->hor.ymin, v2d->hor.xmax, v2d->hor.ymax);
- }
-
+
UI_draw_widget_scroll(&wcol, &hor, &slider, state);
/* scale indicators */
if ((scroll & V2D_SCROLL_SCALE_HORIZONTAL) && (vs->grid)) {
+ const int font_id = BLF_default();
View2DGrid *grid = vs->grid;
float fac, dfac, fac2, val;
@@ -1759,7 +1879,7 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
dfac = dfac * BLI_rcti_size_x(&hor);
/* set starting value, and text color */
- UI_ThemeColor(TH_TEXT);
+ UI_FontThemeColor(font_id, TH_TEXT);
val = grid->startx;
/* if we're clamping to whole numbers only, make sure entries won't be repeated */
@@ -1771,11 +1891,13 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
}
if (vs->xunits == V2D_UNIT_FRAMES)
grid->powerx = 1;
-
+
/* draw numbers in the appropriate range */
if (dfac > 0.0f) {
float h = 0.1f * UI_UNIT_Y + (float)(hor.ymin);
-
+
+ BLF_batch_draw_begin();
+
for (; fac < hor.xmax - 0.5f * U.widget_unit; fac += dfac, val += grid->dx) {
/* make prints look nicer for scrollers */
@@ -1802,17 +1924,18 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
break;
}
}
+
+ BLF_batch_draw_end();
}
}
}
/* vertical scrollbar */
if (scroll & V2D_SCROLL_VERTICAL) {
- bTheme *btheme = UI_GetTheme();
uiWidgetColors wcol = btheme->tui.wcol_scroll;
rcti slider;
+ const float alpha_fac = v2d->alpha_vert / 255.0f;
int state;
- unsigned char col[4];
slider.xmin = vert.xmin;
slider.xmax = vert.xmax;
@@ -1821,6 +1944,11 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
state = (v2d->scroll_ui & V2D_SCROLL_V_ACTIVE) ? UI_SCROLL_PRESSED : 0;
+ wcol.inner[3] *= alpha_fac;
+ wcol.item[3] *= alpha_fac;
+ wcol.outline[3] *= alpha_fac;
+ btheme->tui.widget_emboss[3] *= alpha_fac; /* will be reset later */
+
/* show zoom handles if:
* - zooming on y-axis is allowed (no scroll otherwise)
* - slider bubble is large enough (no overdraw confusion)
@@ -1835,13 +1963,6 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
state |= UI_SCROLL_ARROWS;
}
- /* clean rect behind slider, but not with transparent background */
- UI_GetThemeColor4ubv(TH_BACK, col);
- if (col[3] == 255) {
- glColor3ub(col[0], col[1], col[2]);
- glRecti(v2d->vert.xmin, v2d->vert.ymin, v2d->vert.xmax, v2d->vert.ymax);
- }
-
UI_draw_widget_scroll(&wcol, &vert, &slider, state);
@@ -1863,7 +1984,8 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
dfac = dfac * BLI_rcti_size_y(&vert);
/* set starting value, and text color */
- UI_ThemeColor(TH_TEXT);
+ const int font_id = BLF_default();
+ UI_FontThemeColor(font_id, TH_TEXT);
val = grid->starty;
/* if vertical clamping (to whole numbers) is used (i.e. in Sequencer), apply correction */
@@ -1872,9 +1994,8 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
/* draw vertical steps */
if (dfac > 0.0f) {
-
- BLF_rotation_default(M_PI_2);
- BLF_enable_default(BLF_ROTATION);
+ BLF_rotation(font_id, M_PI_2);
+ BLF_enable(font_id, BLF_ROTATION);
for (; fac < vert.ymax - 10; fac += dfac, val += grid->dy) {
@@ -1885,11 +2006,13 @@ void UI_view2d_scrollers_draw(const bContext *C, View2D *v2d, View2DScrollers *v
scroll_printstr(scene, (float)(vert.xmax) - 2.0f, fac, val, grid->powery, vs->yunits, 'v');
}
- BLF_disable_default(BLF_ROTATION);
+ BLF_disable(font_id, BLF_ROTATION);
}
}
}
+ /* Was changed above, so reset. */
+ btheme->tui.widget_emboss[3] = emboss_alpha;
}
/* free temporary memory used for drawing scrollers */
@@ -2296,9 +2419,8 @@ void UI_view2d_offset(struct View2D *v2d, float xfac, float yfac)
* - 'v' = in vertical scroller.
* - 0 = not in scroller.
*/
-short UI_view2d_mouse_in_scrollers(const bContext *C, View2D *v2d, int x, int y)
+short UI_view2d_mouse_in_scrollers(const ARegion *ar, View2D *v2d, int x, int y)
{
- ARegion *ar = CTX_wm_region(C);
int co[2];
int scroll = view2d_scroll_mapped(v2d->scroll);
@@ -2407,7 +2529,8 @@ void UI_view2d_text_cache_draw(ARegion *ar)
int col_pack_prev = 0;
/* investigate using BLF_ascender() */
- const float default_height = g_v2d_strings ? BLF_height_default("28", 3) : 0.0f;
+ const int font_id = BLF_default();
+ const float default_height = g_v2d_strings ? BLF_height(font_id, "28", 3) : 0.0f;
wmOrtho2_region_pixelspace(ar);
@@ -2418,7 +2541,7 @@ void UI_view2d_text_cache_draw(ARegion *ar)
if (yofs < 1) yofs = 1;
if (col_pack_prev != v2s->col.pack) {
- glColor3ubv(v2s->col.ub);
+ BLF_color3ubv(font_id, v2s->col.ub);
col_pack_prev = v2s->col.pack;
}
@@ -2426,11 +2549,11 @@ void UI_view2d_text_cache_draw(ARegion *ar)
BLF_draw_default((float)(v2s->mval[0] + xofs), (float)(v2s->mval[1] + yofs), 0.0,
v2s->str, BLF_DRAW_STR_DUMMY_MAX);
else {
- BLF_clipping_default(v2s->rect.xmin - 4, v2s->rect.ymin - 4, v2s->rect.xmax + 4, v2s->rect.ymax + 4);
- BLF_enable_default(BLF_CLIPPING);
+ BLF_enable(font_id, BLF_CLIPPING);
+ BLF_clipping(font_id, v2s->rect.xmin - 4, v2s->rect.ymin - 4, v2s->rect.xmax + 4, v2s->rect.ymax + 4);
BLF_draw_default(v2s->rect.xmin + xofs, v2s->rect.ymin + yofs, 0.0f,
v2s->str, BLF_DRAW_STR_DUMMY_MAX);
- BLF_disable_default(BLF_CLIPPING);
+ BLF_disable(font_id, BLF_CLIPPING);
}
}
g_v2d_strings = NULL;
@@ -2439,11 +2562,6 @@ void UI_view2d_text_cache_draw(ARegion *ar)
BLI_memarena_free(g_v2d_strings_arena);
g_v2d_strings_arena = NULL;
}
-
- // glMatrixMode(GL_PROJECTION);
- // glPopMatrix();
- // glMatrixMode(GL_MODELVIEW);
- // glPopMatrix();
}
diff --git a/source/blender/editors/interface/view2d_ops.c b/source/blender/editors/interface/view2d_ops.c
index dc68c8b58de..90ef47aa712 100644
--- a/source/blender/editors/interface/view2d_ops.c
+++ b/source/blender/editors/interface/view2d_ops.c
@@ -641,6 +641,7 @@ static void view_zoomstep_apply_ex(
View2D *v2d = &ar->v2d;
const rctf cur_old = v2d->cur;
float dx, dy;
+ const int snap_test = ED_region_snap_size_test(ar);
/* calculate amount to move view by, ensuring symmetry so the
* old zoom level is restored after zooming back the same amount
@@ -725,6 +726,12 @@ static void view_zoomstep_apply_ex(
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
+ if (ED_region_snap_size_apply(ar, snap_test)) {
+ ScrArea *sa = CTX_wm_area(C);
+ ED_area_tag_redraw(sa);
+ WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
+ }
+
/* request updates to be done... */
ED_region_tag_redraw(vzd->ar);
UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
@@ -898,7 +905,8 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
v2dViewZoomData *vzd = op->customdata;
View2D *v2d = vzd->v2d;
float dx, dy;
-
+ const int snap_test = ED_region_snap_size_test(vzd->ar);
+
/* get amount to move view by */
dx = RNA_float_get(op->ptr, "deltax");
dy = RNA_float_get(op->ptr, "deltay");
@@ -961,7 +969,13 @@ static void view_zoomdrag_apply(bContext *C, wmOperator *op)
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
-
+
+ if (ED_region_snap_size_apply(vzd->ar, snap_test)) {
+ ScrArea *sa = CTX_wm_area(C);
+ ED_area_tag_redraw(sa);
+ WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
+ }
+
/* request updates to be done... */
ED_region_tag_redraw(vzd->ar);
UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
@@ -1894,7 +1908,7 @@ static int scroller_activate_invoke(bContext *C, wmOperator *op, const wmEvent *
short in_scroller = 0;
/* check if mouse in scrollbars, if they're enabled */
- in_scroller = UI_view2d_mouse_in_scrollers(C, v2d, event->x, event->y);
+ in_scroller = UI_view2d_mouse_in_scrollers(ar, v2d, event->x, event->y);
/* if in a scroller, init customdata then set modal handler which will catch mousedown to start doing useful stuff */
if (in_scroller) {
@@ -2000,6 +2014,7 @@ static int reset_exec(bContext *C, wmOperator *UNUSED(op))
ARegion *ar = CTX_wm_region(C);
View2D *v2d = &ar->v2d;
int winx, winy;
+ const int snap_test = ED_region_snap_size_test(ar);
/* zoom 1.0 */
winx = (float)(BLI_rcti_size_x(&v2d->mask) + 1);
@@ -2033,7 +2048,13 @@ static int reset_exec(bContext *C, wmOperator *UNUSED(op))
/* validate that view is in valid configuration after this operation */
UI_view2d_curRect_validate(v2d);
-
+
+ if (ED_region_snap_size_apply(ar, snap_test)) {
+ ScrArea *sa = CTX_wm_area(C);
+ ED_area_tag_redraw(sa);
+ WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
+ }
+
/* request updates to be done... */
ED_region_tag_redraw(ar);
UI_view2d_sync(CTX_wm_screen(C), CTX_wm_area(C), v2d, V2D_LOCK_COPY);
diff --git a/source/blender/editors/io/CMakeLists.txt b/source/blender/editors/io/CMakeLists.txt
index b3bbce939a5..4d3f106a5d6 100644
--- a/source/blender/editors/io/CMakeLists.txt
+++ b/source/blender/editors/io/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../blenlib
../../blentranslation
../../bmesh
+ ../../depsgraph
../../makesdna
../../makesrna
../../windowmanager
diff --git a/source/blender/editors/io/io_alembic.c b/source/blender/editors/io/io_alembic.c
index 08181af2ef3..b584782e183 100644
--- a/source/blender/editors/io/io_alembic.c
+++ b/source/blender/editors/io/io_alembic.c
@@ -545,20 +545,10 @@ static int wm_alembic_import_exec(bContext *C, wmOperator *op)
}
}
- /* Switch to object mode to avoid being stuck in other modes (T54326). */
- if (CTX_data_mode_enum(C) != CTX_MODE_OBJECT) {
- Object *obedit = CTX_data_edit_object(C);
-
- if (obedit != NULL) {
- ED_object_mode_toggle(C, obedit->mode);
- }
- else {
- Object *ob = CTX_data_active_object(C);
-
- if (ob) {
- ED_object_mode_toggle(C, ob->mode);
- }
- }
+ /* Switch out of edit mode to avoid being stuck in it (T54326). */
+ Object *obedit = CTX_data_edit_object(C);
+ if (obedit) {
+ ED_object_mode_toggle(C, OB_MODE_EDIT);
}
bool ok = ABC_import(C, filename, scale, is_sequence, set_frame_range,
diff --git a/source/blender/editors/io/io_collada.c b/source/blender/editors/io/io_collada.c
index 42c19c6bc65..a3cbdb57fed 100644
--- a/source/blender/editors/io/io_collada.c
+++ b/source/blender/editors/io/io_collada.c
@@ -28,7 +28,7 @@
* \ingroup collada
*/
#ifdef WITH_COLLADA
-#include "DNA_scene_types.h"
+#include "DNA_space_types.h"
#include "BLT_translation.h"
@@ -36,12 +36,13 @@
#include "BLI_utildefines.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_object.h"
+#include "DEG_depsgraph.h"
+
#include "ED_screen.h"
#include "ED_object.h"
@@ -93,7 +94,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
int sample_animations;
int sampling_rate;
- int export_texture_type;
+ int include_material_textures;
int use_texture_copies;
int active_uv_only;
@@ -149,7 +150,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
deform_bones_only = RNA_boolean_get(op->ptr, "deform_bones_only");
- export_texture_type = RNA_enum_get(op->ptr, "export_texture_type_selection");
+ include_material_textures = RNA_boolean_get(op->ptr, "include_material_textures");
use_texture_copies = RNA_boolean_get(op->ptr, "use_texture_copies");
active_uv_only = RNA_boolean_get(op->ptr, "active_uv_only");
@@ -166,8 +167,8 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
/* get editmode results */
ED_object_editmode_load(CTX_data_edit_object(C));
- EvaluationContext *eval_ctx = G.main->eval_ctx;
Scene *scene = CTX_data_scene(C);
+
ExportSettings export_settings;
export_settings.filepath = filepath;
@@ -183,7 +184,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
export_settings.sampling_rate = sampling_rate;
export_settings.active_uv_only = active_uv_only != 0;
- export_settings.export_texture_type = export_texture_type;
+ export_settings.include_material_textures = include_material_textures != 0;
export_settings.use_texture_copies = use_texture_copies != 0;
export_settings.triangulate = triangulate != 0;
@@ -199,8 +200,7 @@ static int wm_collada_export_exec(bContext *C, wmOperator *op)
if (export_settings.include_armatures) includeFilter |= OB_REL_MOD_ARMATURE;
if (export_settings.include_children) includeFilter |= OB_REL_CHILDREN_RECURSIVE;
-
- export_count = collada_export(eval_ctx,
+ export_count = collada_export(CTX_data_depsgraph(C),
scene,
&export_settings
);
@@ -273,7 +273,7 @@ static void uiCollada_exportSettings(uiLayout *layout, PointerRNA *imfptr)
uiItemR(row, imfptr, "active_uv_only", 0, NULL, ICON_NONE);
row = uiLayoutRow(box, false);
- uiItemR(row, imfptr, "export_texture_type_selection", 0, "", ICON_NONE);
+ uiItemR(row, imfptr, "include_material_textures", 0, NULL, ICON_NONE);
row = uiLayoutRow(box, false);
uiItemR(row, imfptr, "use_texture_copies", 1, NULL, ICON_NONE);
@@ -350,15 +350,9 @@ void WM_OT_collada_export(wmOperatorType *ot)
};
static const EnumPropertyItem prop_bc_export_transformation_type[] = {
- { BC_TRANSFORMATION_TYPE_MATRIX, "matrix", 0, "Matrix", "Use <matrix> to specify transformations" },
- { BC_TRANSFORMATION_TYPE_TRANSROTLOC, "transrotloc", 0, "TransRotLoc", "Use <translate>, <rotate>, <scale> to specify transformations" },
- { 0, NULL, 0, NULL, NULL }
- };
-
- static const EnumPropertyItem prop_bc_export_texture_type[] = {
- { BC_TEXTURE_TYPE_MAT, "mat", 0, "Materials", "Export Materials" },
- { BC_TEXTURE_TYPE_UV, "uv", 0, "UV Textures", "Export UV Textures (Face textures) as materials" },
- { 0, NULL, 0, NULL, NULL }
+ {BC_TRANSFORMATION_TYPE_MATRIX, "matrix", 0, "Matrix", "Use <matrix> to specify transformations"},
+ {BC_TRANSFORMATION_TYPE_TRANSROTLOC, "transrotloc", 0, "TransRotLoc", "Use <translate>, <rotate>, <scale> to specify transformations"},
+ {0, NULL, 0, NULL, NULL}
};
ot->name = "Export COLLADA";
@@ -412,9 +406,13 @@ void WM_OT_collada_export(wmOperatorType *ot)
RNA_def_int(func, "sampling_rate", 1, 1, INT_MAX,
"Sampling Rate", "The distance between 2 keyframes. 1 means: Every frame is keyed", 1, INT_MAX);
+
RNA_def_boolean(func, "active_uv_only", 0, "Only Selected UV Map",
"Export only the selected UV Map");
+ RNA_def_boolean(func, "include_material_textures", 0, "Include Material Textures",
+ "Export textures assigned to the object Materials");
+
RNA_def_boolean(func, "use_texture_copies", 1, "Copy",
"Copy textures to same folder where the .dae file is exported");
@@ -431,20 +429,11 @@ void WM_OT_collada_export(wmOperatorType *ot)
RNA_def_boolean(func, "sort_by_name", 0, "Sort by Object name",
"Sort exported data by Object name");
-
RNA_def_int(func, "export_transformation_type", 0, INT_MIN, INT_MAX,
- "Transform", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX);
+ "Transform", "Transformation type for translation, scale and rotation", INT_MIN, INT_MAX);
RNA_def_enum(func, "export_transformation_type_selection", prop_bc_export_transformation_type, 0,
- "Transform", "Transformation type for translation, scale and rotation");
-
-
- RNA_def_int(func, "export_texture_type", 0, INT_MIN, INT_MAX,
- "Texture Type", "Type for exported Textures (UV or MAT)", INT_MIN, INT_MAX);
-
- RNA_def_enum(func, "export_texture_type_selection", prop_bc_export_texture_type, 0,
- "Texture Type", "Type for exported Textures (UV or MAT)");
-
+ "Transform", "Transformation type for translation, scale and rotation");
RNA_def_boolean(func, "open_sim", 0, "Export to SL/OpenSim",
"Compatibility mode for SL, OpenSim and other compatible online worlds");
@@ -497,6 +486,7 @@ static int wm_collada_import_exec(bContext *C, wmOperator *op)
import_settings.keep_bind_info = keep_bind_info != 0;
if (collada_import(C, &import_settings)) {
+ DEG_id_tag_update(&CTX_data_scene(C)->id, DEG_TAG_BASE_FLAGS_UPDATE);
return OPERATOR_FINISHED;
}
else {
diff --git a/source/blender/editors/lattice/CMakeLists.txt b/source/blender/editors/lattice/CMakeLists.txt
index 3bb954ddf46..2207e0fa736 100644
--- a/source/blender/editors/lattice/CMakeLists.txt
+++ b/source/blender/editors/lattice/CMakeLists.txt
@@ -22,10 +22,12 @@ set(INC
../include
../../blenkernel
../../blenlib
+ ../../depsgraph
../../makesdna
../../makesrna
../../render/extern/include
../../windowmanager
+ ../../../../intern/clog
../../../../intern/guardedalloc
)
diff --git a/source/blender/editors/lattice/editlattice_select.c b/source/blender/editors/lattice/editlattice_select.c
index d0d64b85195..ccf90452b0f 100644
--- a/source/blender/editors/lattice/editlattice_select.c
+++ b/source/blender/editors/lattice/editlattice_select.c
@@ -50,6 +50,7 @@
#include "BKE_context.h"
#include "BKE_lattice.h"
#include "BKE_report.h"
+#include "BKE_layer.h"
#include "ED_screen.h"
#include "ED_lattice.h"
@@ -84,36 +85,43 @@ static void bpoint_select_set(BPoint *bp, bool select)
static int lattice_select_random_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
-
const float randfac = RNA_float_get(op->ptr, "percent") / 100.0f;
const int seed = WM_operator_properties_select_random_seed_increment_get(op);
const bool select = (RNA_enum_get(op->ptr, "action") == SEL_SELECT);
- RNG *rng = BLI_rng_new_srandom(seed);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
- int tot;
- BPoint *bp;
+ RNG *rng = BLI_rng_new_srandom(seed);
- tot = lt->pntsu * lt->pntsv * lt->pntsw;
- bp = lt->def;
- while (tot--) {
- if (!bp->hide) {
- if (BLI_rng_get_float(rng) < randfac) {
- bpoint_select_set(bp, select);
+ int tot;
+ BPoint *bp;
+
+ tot = lt->pntsu * lt->pntsv * lt->pntsw;
+ bp = lt->def;
+ while (tot--) {
+ if (!bp->hide) {
+ if (BLI_rng_get_float(rng) < randfac) {
+ bpoint_select_set(bp, select);
+ }
}
+ bp++;
}
- bp++;
- }
- if (select == false) {
- lt->actbp = LT_ACTBP_NONE;
- }
+ if (select == false) {
+ lt->actbp = LT_ACTBP_NONE;
+ }
- BLI_rng_free(rng);
+ BLI_rng_free(rng);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -183,18 +191,27 @@ static void ed_lattice_select_mirrored(Lattice *lt, const int axis, const bool e
static int lattice_select_mirror_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
const int axis_flag = RNA_enum_get(op->ptr, "axis");
const bool extend = RNA_boolean_get(op->ptr, "extend");
- for (int axis = 0; axis < 3; axis++) {
- if ((1 << axis) & axis_flag) {
- ed_lattice_select_mirrored(lt, axis, extend);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
+
+ for (int axis = 0; axis < 3; axis++) {
+ if ((1 << axis) & axis_flag) {
+ ed_lattice_select_mirrored(lt, axis, extend);
+ }
}
- }
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ /* TODO, only notify changes */
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/lattice/editlattice_tools.c b/source/blender/editors/lattice/editlattice_tools.c
index c39ba44c1dc..bf60c1e7da6 100644
--- a/source/blender/editors/lattice/editlattice_tools.c
+++ b/source/blender/editors/lattice/editlattice_tools.c
@@ -39,9 +39,10 @@
#include "RNA_define.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_lattice.h"
+#include "DEG_depsgraph.h"
+
#include "ED_screen.h"
#include "WM_api.h"
@@ -80,7 +81,7 @@ static int make_regular_exec(bContext *C, wmOperator *UNUSED(op))
BKE_lattice_resize(lt, lt->pntsu, lt->pntsv, lt->pntsw, NULL);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
return OPERATOR_FINISHED;
@@ -306,7 +307,7 @@ static int lattice_flip_exec(bContext *C, wmOperator *op)
}
/* updates */
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/lattice/editlattice_undo.c b/source/blender/editors/lattice/editlattice_undo.c
index 7a7372f5a6a..cbd89016b44 100644
--- a/source/blender/editors/lattice/editlattice_undo.c
+++ b/source/blender/editors/lattice/editlattice_undo.c
@@ -33,6 +33,8 @@
#include "MEM_guardedalloc.h"
+#include "CLG_log.h"
+
#include "BLI_utildefines.h"
#include "BLI_array_utils.h"
@@ -42,11 +44,14 @@
#include "DNA_scene_types.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_object.h"
#include "ED_lattice.h"
+#include "ED_undo.h"
#include "ED_util.h"
#include "WM_types.h"
@@ -54,6 +59,9 @@
#include "lattice_intern.h"
+/** We only need this locally. */
+static CLG_LogRef LOG = {"ed.undo.lattice"};
+
/* -------------------------------------------------------------------- */
/** \name Undo Conversion
* \{ */
@@ -123,13 +131,19 @@ static Object *editlatt_object_from_context(bContext *C)
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
+ *
+ * \note This is similar for all edit-mode types.
* \{ */
-typedef struct LatticeUndoStep {
- UndoStep step;
- /* note: will split out into list for multi-object-editmode. */
+typedef struct LatticeUndoStep_Elem {
UndoRefID_Object obedit_ref;
UndoLattice data;
+} LatticeUndoStep_Elem;
+
+typedef struct LatticeUndoStep {
+ UndoStep step;
+ LatticeUndoStep_Elem *elems;
+ uint elems_len;
} LatticeUndoStep;
static bool lattice_undosys_poll(bContext *C)
@@ -140,10 +154,24 @@ static bool lattice_undosys_poll(bContext *C)
static bool lattice_undosys_step_encode(struct bContext *C, UndoStep *us_p)
{
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- us->obedit_ref.ptr = editlatt_object_from_context(C);
- Lattice *lt = us->obedit_ref.ptr->data;
- undolatt_from_editlatt(&us->data, lt->editlatt);
- us->step.data_size = us->data.undo_size;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__);
+ us->elems_len = objects_len;
+
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+
+ elem->obedit_ref.ptr = ob;
+ Lattice *lt = ob->data;
+ undolatt_from_editlatt(&elem->data, lt->editlatt);
+ us->step.data_size += elem->data.undo_size;
+ }
+ MEM_freeN(objects);
return true;
}
@@ -154,25 +182,47 @@ static void lattice_undosys_step_decode(struct bContext *C, UndoStep *us_p, int
BLI_assert(lattice_undosys_poll(C));
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- Object *obedit = us->obedit_ref.ptr;
- Lattice *lt = obedit->data;
- EditLatt *editlatt = lt->editlatt;
- undolatt_to_editlatt(&us->data, editlatt);
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+ Object *obedit = elem->obedit_ref.ptr;
+ Lattice *lt = obedit->data;
+ if (lt->editlatt == NULL) {
+ /* Should never fail, may not crash but can give odd behavior. */
+ CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid",
+ us_p->name, obedit->id.name);
+ continue;
+ }
+ undolatt_to_editlatt(&elem->data, lt->editlatt);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ }
+
+ /* The first element is always active */
+ ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
+
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
static void lattice_undosys_step_free(UndoStep *us_p)
{
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- undolatt_free_data(&us->data);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+ undolatt_free_data(&elem->data);
+ }
+ MEM_freeN(us->elems);
}
static void lattice_undosys_foreach_ID_ref(
UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
{
LatticeUndoStep *us = (LatticeUndoStep *)us_p;
- foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref));
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ LatticeUndoStep_Elem *elem = &us->elems[i];
+ foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref));
+ }
}
/* Export for ED_undo_sys. */
diff --git a/source/blender/editors/manipulator_library/CMakeLists.txt b/source/blender/editors/manipulator_library/CMakeLists.txt
new file mode 100644
index 00000000000..86e1bb3b6d7
--- /dev/null
+++ b/source/blender/editors/manipulator_library/CMakeLists.txt
@@ -0,0 +1,60 @@
+# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ ../include
+ ../../blenkernel
+ ../../blenlib
+ ../../blentranslation
+ ../../bmesh
+ ../../depsgraph
+ ../../gpu
+ ../../makesdna
+ ../../makesrna
+ ../../windowmanager
+ ../../../../intern/guardedalloc
+ ../../../../intern/eigen
+ ../../../../intern/glew-mx
+)
+
+set(INC_SYS
+ ${GLEW_INCLUDE_PATH}
+)
+
+set(SRC
+ manipulator_draw_utils.c
+ manipulator_geometry.h
+ manipulator_library_intern.h
+ manipulator_library_presets.c
+ manipulator_library_utils.c
+ geometry/geom_arrow_manipulator.c
+ geometry/geom_cube_manipulator.c
+ geometry/geom_dial_manipulator.c
+ manipulator_types/arrow2d_manipulator.c
+ manipulator_types/arrow3d_manipulator.c
+ manipulator_types/button2d_manipulator.c
+ manipulator_types/cage2d_manipulator.c
+ manipulator_types/cage3d_manipulator.c
+ manipulator_types/dial3d_manipulator.c
+ manipulator_types/grab3d_manipulator.c
+ manipulator_types/primitive3d_manipulator.c
+)
+
+add_definitions(${GL_DEFINITIONS})
+
+blender_add_lib(bf_editor_manipulator_library "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/manipulator_library/geometry/geom_arrow_manipulator.c b/source/blender/editors/manipulator_library/geometry/geom_arrow_manipulator.c
new file mode 100644
index 00000000000..34f7d73589c
--- /dev/null
+++ b/source/blender/editors/manipulator_library/geometry/geom_arrow_manipulator.c
@@ -0,0 +1,141 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file geom_arrow_manipulator.c
+ * \ingroup wm
+ */
+
+#include "../manipulator_geometry.h"
+
+static float verts[][3] = {
+ {-0.000000, 0.012320, 0.000000},
+ {-0.000000, 0.012320, 0.974306},
+ {0.008711, 0.008711, 0.000000},
+ {0.008711, 0.008711, 0.974306},
+ {0.012320, -0.000000, 0.000000},
+ {0.012320, -0.000000, 0.974306},
+ {0.008711, -0.008711, 0.000000},
+ {0.008711, -0.008711, 0.974306},
+ {-0.000000, -0.012320, 0.000000},
+ {-0.000000, -0.012320, 0.974306},
+ {-0.008711, -0.008711, 0.000000},
+ {-0.008711, -0.008711, 0.974306},
+ {-0.012320, 0.000000, 0.000000},
+ {-0.012320, 0.000000, 0.974306},
+ {-0.008711, 0.008711, 0.000000},
+ {-0.008711, 0.008711, 0.974306},
+ {0.000000, 0.072555, 0.974306},
+ {0.051304, 0.051304, 0.974306},
+ {0.072555, -0.000000, 0.974306},
+ {0.051304, -0.051304, 0.974306},
+ {-0.000000, -0.072555, 0.974306},
+ {-0.051304, -0.051304, 0.974306},
+ {-0.072555, 0.000000, 0.974306},
+ {-0.051304, 0.051304, 0.974306},
+ {0.000000, -0.000000, 1.268098},
+};
+
+static float normals[][3] = {
+ {0.000000, 0.776360, -0.630238},
+ {0.000000, 0.594348, -0.804163},
+ {0.548967, 0.548967, -0.630238},
+ {0.420270, 0.420270, -0.804163},
+ {0.776360, 0.000000, -0.630238},
+ {0.594378, 0.000000, -0.804163},
+ {0.548967, -0.548967, -0.630238},
+ {0.420270, -0.420270, -0.804163},
+ {0.000000, -0.776360, -0.630238},
+ {0.000000, -0.594378, -0.804163},
+ {-0.548967, -0.548967, -0.630238},
+ {-0.420270, -0.420270, -0.804163},
+ {-0.776360, 0.000000, -0.630238},
+ {-0.594378, 0.000000, -0.804163},
+ {-0.548967, 0.548967, -0.630238},
+ {-0.420270, 0.420270, -0.804163},
+ {0.000000, 0.843226, -0.537492},
+ {0.596271, 0.596271, -0.537492},
+ {0.843226, 0.000000, -0.537492},
+ {0.596271, -0.596271, -0.537492},
+ {0.000000, -0.843226, -0.537492},
+ {-0.596271, -0.596271, -0.537492},
+ {-0.843226, 0.000000, -0.537492},
+ {-0.596271, 0.596271, -0.537492},
+ {0.000000, 0.000000, 1.000000},
+};
+
+static unsigned short indices[] = {
+ 1, 3, 2,
+ 3, 5, 4,
+ 5, 7, 6,
+ 7, 9, 8,
+ 9, 11, 10,
+ 11, 13, 12,
+ 5, 18, 19,
+ 15, 1, 0,
+ 13, 15, 14,
+ 6, 10, 14,
+ 11, 21, 22,
+ 7, 19, 20,
+ 13, 22, 23,
+ 3, 17, 18,
+ 9, 20, 21,
+ 15, 23, 16,
+ 1, 16, 17,
+ 23, 22, 24,
+ 21, 20, 24,
+ 19, 18, 24,
+ 17, 16, 24,
+ 16, 23, 24,
+ 22, 21, 24,
+ 20, 19, 24,
+ 18, 17, 24,
+ 0, 1, 2,
+ 2, 3, 4,
+ 4, 5, 6,
+ 6, 7, 8,
+ 8, 9, 10,
+ 10, 11, 12,
+ 7, 5, 19,
+ 14, 15, 0,
+ 12, 13, 14,
+ 14, 0, 2,
+ 2, 4, 6,
+ 6, 8, 10,
+ 10, 12, 14,
+ 14, 2, 6,
+ 13, 11, 22,
+ 9, 7, 20,
+ 15, 13, 23,
+ 5, 3, 18,
+ 11, 9, 21,
+ 1, 15, 16,
+ 3, 1, 17,
+};
+
+ManipulatorGeomInfo wm_manipulator_geom_data_arrow = {
+ .nverts = 25,
+ .ntris = 46,
+ .verts = verts,
+ .normals = normals,
+ .indices = indices,
+};
diff --git a/source/blender/editors/manipulator_library/geometry/geom_cube_manipulator.c b/source/blender/editors/manipulator_library/geometry/geom_cube_manipulator.c
new file mode 100644
index 00000000000..cee8e1e22ee
--- /dev/null
+++ b/source/blender/editors/manipulator_library/geometry/geom_cube_manipulator.c
@@ -0,0 +1,75 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file geom_cube_manipulator.c
+ * \ingroup wm
+ */
+
+#include "../manipulator_geometry.h"
+
+static const float verts[][3] = {
+ {1.000000, 1.000000, -1.000000},
+ {1.000000, -1.000000, -1.000000},
+ {-1.000000, -1.000000, -1.000000},
+ {-1.000000, 1.000000, -1.000000},
+ {1.000000, 1.000000, 1.000000},
+ {0.999999, -1.000001, 1.000000},
+ {-1.000000, -1.000000, 1.000000},
+ {-1.000000, 1.000000, 1.000000},
+};
+
+static const float normals[][3] = {
+ {0.577349, 0.577349, -0.577349},
+ {0.577349, -0.577349, -0.577349},
+ {-0.577349, -0.577349, -0.577349},
+ {-0.577349, 0.577349, -0.577349},
+ {0.577349, 0.577349, 0.577349},
+ {0.577349, -0.577349, 0.577349},
+ {-0.577349, -0.577349, 0.577349},
+ {-0.577349, 0.577349, 0.577349},
+};
+
+static const unsigned short indices[] = {
+ 1, 2, 3,
+ 7, 6, 5,
+ 4, 5, 1,
+ 5, 6, 2,
+ 2, 6, 7,
+ 0, 3, 7,
+ 0, 1, 3,
+ 4, 7, 5,
+ 0, 4, 1,
+ 1, 5, 2,
+ 3, 2, 7,
+ 4, 0, 7,
+};
+
+ManipulatorGeomInfo wm_manipulator_geom_data_cube = {
+ .nverts = 8,
+ .ntris = 12,
+ .verts = verts,
+ .normals = normals,
+ .indices = indices,
+};
diff --git a/source/blender/editors/manipulator_library/geometry/geom_dial_manipulator.c b/source/blender/editors/manipulator_library/geometry/geom_dial_manipulator.c
new file mode 100644
index 00000000000..811fc872a81
--- /dev/null
+++ b/source/blender/editors/manipulator_library/geometry/geom_dial_manipulator.c
@@ -0,0 +1,813 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file geom_dial_manipulator.c
+ * \ingroup wm
+ */
+
+#include "../manipulator_geometry.h"
+
+static const float verts[][3] = {
+ {1.034000, 0.000000, 0.000000},
+ {1.017000, 0.000000, 0.029445},
+ {0.983000, 0.000000, 0.029445},
+ {0.966000, 0.000000, 0.000000},
+ {0.983000, 0.000000, -0.029445},
+ {1.017000, 0.000000, -0.029445},
+ {1.014132, 0.201723, 0.000000},
+ {0.997459, 0.198407, 0.029445},
+ {0.964112, 0.191774, 0.029445},
+ {0.947439, 0.188457, 0.000000},
+ {0.964112, 0.191774, -0.029445},
+ {0.997459, 0.198407, -0.029445},
+ {0.955292, 0.395695, 0.000000},
+ {0.939586, 0.389189, 0.029445},
+ {0.908174, 0.376178, 0.029445},
+ {0.892468, 0.369672, 0.000000},
+ {0.908174, 0.376178, -0.029445},
+ {0.939586, 0.389189, -0.029445},
+ {0.859740, 0.574460, 0.000000},
+ {0.845605, 0.565015, 0.029445},
+ {0.817335, 0.546126, 0.029445},
+ {0.803200, 0.536681, 0.000000},
+ {0.817335, 0.546126, -0.029445},
+ {0.845605, 0.565015, -0.029445},
+ {0.731148, 0.731148, 0.000000},
+ {0.719128, 0.719128, 0.029445},
+ {0.695086, 0.695086, 0.029445},
+ {0.683065, 0.683065, 0.000000},
+ {0.695086, 0.695086, -0.029445},
+ {0.719128, 0.719128, -0.029445},
+ {0.574460, 0.859740, 0.000000},
+ {0.565015, 0.845605, 0.029445},
+ {0.546125, 0.817335, 0.029445},
+ {0.536681, 0.803200, 0.000000},
+ {0.546125, 0.817335, -0.029445},
+ {0.565015, 0.845605, -0.029445},
+ {0.395695, 0.955291, 0.000000},
+ {0.389189, 0.939585, 0.029445},
+ {0.376178, 0.908173, 0.029445},
+ {0.369672, 0.892467, 0.000000},
+ {0.376178, 0.908173, -0.029445},
+ {0.389189, 0.939585, -0.029445},
+ {0.201724, 1.014132, 0.000000},
+ {0.198407, 0.997459, 0.029445},
+ {0.191774, 0.964112, 0.029445},
+ {0.188457, 0.947439, 0.000000},
+ {0.191774, 0.964112, -0.029445},
+ {0.198407, 0.997459, -0.029445},
+ {0.000000, 1.034000, 0.000000},
+ {0.000000, 1.017000, 0.029445},
+ {0.000000, 0.983000, 0.029445},
+ {0.000000, 0.966000, 0.000000},
+ {0.000000, 0.983000, -0.029445},
+ {0.000000, 1.017000, -0.029445},
+ {-0.201723, 1.014132, 0.000000},
+ {-0.198407, 0.997459, 0.029445},
+ {-0.191774, 0.964112, 0.029445},
+ {-0.188457, 0.947439, 0.000000},
+ {-0.191774, 0.964112, -0.029445},
+ {-0.198407, 0.997459, -0.029445},
+ {-0.395695, 0.955291, 0.000000},
+ {-0.389189, 0.939585, 0.029445},
+ {-0.376178, 0.908174, 0.029445},
+ {-0.369672, 0.892468, 0.000000},
+ {-0.376178, 0.908174, -0.029445},
+ {-0.389189, 0.939585, -0.029445},
+ {-0.574459, 0.859740, 0.000000},
+ {-0.565015, 0.845605, 0.029445},
+ {-0.546125, 0.817335, 0.029445},
+ {-0.536681, 0.803200, 0.000000},
+ {-0.546125, 0.817335, -0.029445},
+ {-0.565015, 0.845605, -0.029445},
+ {-0.731149, 0.731148, 0.000000},
+ {-0.719128, 0.719127, 0.029445},
+ {-0.695086, 0.695086, 0.029445},
+ {-0.683065, 0.683065, 0.000000},
+ {-0.695086, 0.695086, -0.029445},
+ {-0.719128, 0.719127, -0.029445},
+ {-0.859740, 0.574460, 0.000000},
+ {-0.845604, 0.565015, 0.029445},
+ {-0.817335, 0.546126, 0.029445},
+ {-0.803200, 0.536681, 0.000000},
+ {-0.817335, 0.546126, -0.029445},
+ {-0.845604, 0.565015, -0.029445},
+ {-0.955291, 0.395695, 0.000000},
+ {-0.939585, 0.389189, 0.029445},
+ {-0.908173, 0.376178, 0.029445},
+ {-0.892468, 0.369672, 0.000000},
+ {-0.908173, 0.376178, -0.029445},
+ {-0.939585, 0.389189, -0.029445},
+ {-1.014132, 0.201723, 0.000000},
+ {-0.997459, 0.198407, 0.029445},
+ {-0.964112, 0.191774, 0.029445},
+ {-0.947439, 0.188457, 0.000000},
+ {-0.964112, 0.191774, -0.029445},
+ {-0.997459, 0.198407, -0.029445},
+ {-1.034000, 0.000000, 0.000000},
+ {-1.017000, 0.000000, 0.029445},
+ {-0.983000, 0.000000, 0.029445},
+ {-0.966000, 0.000000, 0.000000},
+ {-0.983000, 0.000000, -0.029445},
+ {-1.017000, 0.000000, -0.029445},
+ {-1.014132, -0.201723, 0.000000},
+ {-0.997459, -0.198407, 0.029445},
+ {-0.964112, -0.191774, 0.029445},
+ {-0.947439, -0.188457, 0.000000},
+ {-0.964112, -0.191774, -0.029445},
+ {-0.997459, -0.198407, -0.029445},
+ {-0.955292, -0.395694, 0.000000},
+ {-0.939586, -0.389189, 0.029445},
+ {-0.908174, -0.376177, 0.029445},
+ {-0.892468, -0.369672, 0.000000},
+ {-0.908174, -0.376177, -0.029445},
+ {-0.939586, -0.389189, -0.029445},
+ {-0.859740, -0.574460, 0.000000},
+ {-0.845604, -0.565015, 0.029445},
+ {-0.817335, -0.546126, 0.029445},
+ {-0.803200, -0.536681, 0.000000},
+ {-0.817335, -0.546126, -0.029445},
+ {-0.845604, -0.565015, -0.029445},
+ {-0.731149, -0.731148, 0.000000},
+ {-0.719128, -0.719127, 0.029445},
+ {-0.695086, -0.695086, 0.029445},
+ {-0.683065, -0.683065, 0.000000},
+ {-0.695086, -0.695086, -0.029445},
+ {-0.719128, -0.719127, -0.029445},
+ {-0.574460, -0.859739, 0.000000},
+ {-0.565015, -0.845604, 0.029445},
+ {-0.546126, -0.817334, 0.029445},
+ {-0.536681, -0.803199, 0.000000},
+ {-0.546126, -0.817334, -0.029445},
+ {-0.565015, -0.845604, -0.029445},
+ {-0.395695, -0.955291, 0.000000},
+ {-0.389189, -0.939585, 0.029445},
+ {-0.376178, -0.908174, 0.029445},
+ {-0.369672, -0.892468, 0.000000},
+ {-0.376178, -0.908174, -0.029445},
+ {-0.389189, -0.939585, -0.029445},
+ {-0.201724, -1.014132, 0.000000},
+ {-0.198407, -0.997459, 0.029445},
+ {-0.191774, -0.964112, 0.029445},
+ {-0.188458, -0.947438, 0.000000},
+ {-0.191774, -0.964112, -0.029445},
+ {-0.198407, -0.997459, -0.029445},
+ {0.000000, -1.034000, 0.000000},
+ {0.000000, -1.017000, 0.029445},
+ {0.000000, -0.983000, 0.029445},
+ {0.000000, -0.966000, 0.000000},
+ {0.000000, -0.983000, -0.029445},
+ {0.000000, -1.017000, -0.029445},
+ {0.201723, -1.014132, 0.000000},
+ {0.198407, -0.997459, 0.029445},
+ {0.191773, -0.964112, 0.029445},
+ {0.188457, -0.947439, 0.000000},
+ {0.191773, -0.964112, -0.029445},
+ {0.198407, -0.997459, -0.029445},
+ {0.395695, -0.955291, 0.000000},
+ {0.389189, -0.939585, 0.029445},
+ {0.376178, -0.908173, 0.029445},
+ {0.369672, -0.892467, 0.000000},
+ {0.376178, -0.908173, -0.029445},
+ {0.389189, -0.939585, -0.029445},
+ {0.574460, -0.859740, 0.000000},
+ {0.565015, -0.845605, 0.029445},
+ {0.546125, -0.817335, 0.029445},
+ {0.536681, -0.803200, 0.000000},
+ {0.546125, -0.817335, -0.029445},
+ {0.565015, -0.845605, -0.029445},
+ {0.731148, -0.731149, 0.000000},
+ {0.719127, -0.719128, 0.029445},
+ {0.695086, -0.695086, 0.029445},
+ {0.683065, -0.683066, 0.000000},
+ {0.695086, -0.695086, -0.029445},
+ {0.719127, -0.719128, -0.029445},
+ {0.859740, -0.574460, 0.000000},
+ {0.845605, -0.565015, 0.029445},
+ {0.817335, -0.546126, 0.029445},
+ {0.803200, -0.536681, 0.000000},
+ {0.817335, -0.546126, -0.029445},
+ {0.845605, -0.565015, -0.029445},
+ {0.955291, -0.395695, 0.000000},
+ {0.939585, -0.389189, 0.029445},
+ {0.908173, -0.376178, 0.029445},
+ {0.892467, -0.369673, 0.000000},
+ {0.908173, -0.376178, -0.029445},
+ {0.939585, -0.389189, -0.029445},
+ {1.014132, -0.201723, 0.000000},
+ {0.997459, -0.198407, 0.029445},
+ {0.964112, -0.191774, 0.029445},
+ {0.947439, -0.188457, 0.000000},
+ {0.964112, -0.191774, -0.029445},
+ {0.997459, -0.198407, -0.029445},
+};
+
+static const float normals[][3] = {
+ {1.000000, 0.000000, 0.000000},
+ {0.522691, 0.000000, 0.852504},
+ {-0.475845, 0.000000, 0.879513},
+ {-1.000000, 0.000000, 0.000000},
+ {-0.475845, 0.000000, -0.879513},
+ {0.522691, 0.000000, -0.852504},
+ {0.980773, 0.195074, 0.000000},
+ {0.512650, 0.101962, 0.852504},
+ {-0.466689, -0.092807, 0.879513},
+ {-0.980773, -0.195074, 0.000000},
+ {-0.466689, -0.092807, -0.879513},
+ {0.512650, 0.101962, -0.852504},
+ {0.923856, 0.382672, 0.000000},
+ {0.482894, 0.200018, 0.852504},
+ {-0.439619, -0.182073, 0.879513},
+ {-0.923856, -0.382672, 0.000000},
+ {-0.439619, -0.182073, -0.879513},
+ {0.482894, 0.200018, -0.852504},
+ {0.831446, 0.555559, 0.000000},
+ {0.434614, 0.290384, 0.852504},
+ {-0.395642, -0.264351, 0.879513},
+ {-0.831446, -0.555559, 0.000000},
+ {-0.395642, -0.264351, -0.879513},
+ {0.434614, 0.290384, -0.852504},
+ {0.707083, 0.707083, 0.000000},
+ {0.369610, 0.369610, 0.852504},
+ {-0.336467, -0.336467, 0.879513},
+ {-0.707083, -0.707083, 0.000000},
+ {-0.336467, -0.336467, -0.879513},
+ {0.369610, 0.369610, -0.852504},
+ {0.555559, 0.831446, 0.000000},
+ {0.290384, 0.434614, 0.852504},
+ {-0.264351, -0.395642, 0.879513},
+ {-0.555559, -0.831446, 0.000000},
+ {-0.264351, -0.395642, -0.879513},
+ {0.290384, 0.434614, -0.852504},
+ {0.382672, 0.923856, 0.000000},
+ {0.200018, 0.482894, 0.852504},
+ {-0.182073, -0.439619, 0.879513},
+ {-0.382672, -0.923856, 0.000000},
+ {-0.182073, -0.439619, -0.879513},
+ {0.200018, 0.482894, -0.852504},
+ {0.195074, 0.980773, 0.000000},
+ {0.101962, 0.512650, 0.852504},
+ {-0.092807, -0.466689, 0.879513},
+ {-0.195074, -0.980773, 0.000000},
+ {-0.092807, -0.466689, -0.879513},
+ {0.101962, 0.512650, -0.852504},
+ {0.000000, 1.000000, 0.000000},
+ {0.000000, 0.522691, 0.852504},
+ {0.000000, -0.475845, 0.879513},
+ {0.000000, -1.000000, 0.000000},
+ {0.000000, -0.475845, -0.879513},
+ {0.000000, 0.522691, -0.852504},
+ {-0.195074, 0.980773, 0.000000},
+ {-0.101962, 0.512650, 0.852504},
+ {0.092807, -0.466689, 0.879513},
+ {0.195074, -0.980773, 0.000000},
+ {0.092807, -0.466689, -0.879513},
+ {-0.101962, 0.512650, -0.852504},
+ {-0.382672, 0.923856, 0.000000},
+ {-0.200018, 0.482894, 0.852504},
+ {0.182073, -0.439619, 0.879513},
+ {0.382672, -0.923856, 0.000000},
+ {0.182073, -0.439619, -0.879513},
+ {-0.200018, 0.482894, -0.852504},
+ {-0.555559, 0.831446, 0.000000},
+ {-0.290384, 0.434614, 0.852504},
+ {0.264351, -0.395642, 0.879513},
+ {0.555559, -0.831446, 0.000000},
+ {0.264351, -0.395642, -0.879513},
+ {-0.290384, 0.434614, -0.852504},
+ {-0.707083, 0.707083, 0.000000},
+ {-0.369610, 0.369610, 0.852504},
+ {0.336467, -0.336467, 0.879513},
+ {0.707083, -0.707083, 0.000000},
+ {0.336467, -0.336467, -0.879513},
+ {-0.369610, 0.369610, -0.852504},
+ {-0.831446, 0.555559, 0.000000},
+ {-0.434614, 0.290384, 0.852504},
+ {0.395642, -0.264351, 0.879513},
+ {0.831446, -0.555559, 0.000000},
+ {0.395642, -0.264351, -0.879513},
+ {-0.434614, 0.290384, -0.852504},
+ {-0.923856, 0.382672, 0.000000},
+ {-0.482894, 0.200018, 0.852504},
+ {0.439619, -0.182073, 0.879513},
+ {0.923856, -0.382672, 0.000000},
+ {0.439619, -0.182073, -0.879513},
+ {-0.482894, 0.200018, -0.852504},
+ {-0.980773, 0.195074, 0.000000},
+ {-0.512650, 0.101962, 0.852504},
+ {0.466689, -0.092807, 0.879513},
+ {0.980773, -0.195074, 0.000000},
+ {0.466689, -0.092807, -0.879513},
+ {-0.512650, 0.101962, -0.852504},
+ {-1.000000, 0.000000, 0.000000},
+ {-0.522691, 0.000000, 0.852504},
+ {0.475845, 0.000000, 0.879513},
+ {1.000000, 0.000000, 0.000000},
+ {0.475845, 0.000000, -0.879513},
+ {-0.522691, 0.000000, -0.852504},
+ {-0.980773, -0.195074, 0.000000},
+ {-0.512650, -0.101962, 0.852504},
+ {0.466689, 0.092807, 0.879513},
+ {0.980773, 0.195074, 0.000000},
+ {0.466689, 0.092807, -0.879513},
+ {-0.512650, -0.101962, -0.852504},
+ {-0.923856, -0.382672, 0.000000},
+ {-0.482894, -0.200018, 0.852504},
+ {0.439619, 0.182073, 0.879513},
+ {0.923856, 0.382672, 0.000000},
+ {0.439619, 0.182073, -0.879513},
+ {-0.482894, -0.200018, -0.852504},
+ {-0.831446, -0.555559, 0.000000},
+ {-0.434614, -0.290384, 0.852504},
+ {0.395642, 0.264351, 0.879513},
+ {0.831446, 0.555559, 0.000000},
+ {0.395642, 0.264351, -0.879513},
+ {-0.434614, -0.290384, -0.852504},
+ {-0.707083, -0.707083, 0.000000},
+ {-0.369610, -0.369610, 0.852504},
+ {0.336467, 0.336467, 0.879513},
+ {0.707083, 0.707083, 0.000000},
+ {0.336467, 0.336467, -0.879513},
+ {-0.369610, -0.369610, -0.852504},
+ {-0.555559, -0.831446, 0.000000},
+ {-0.290384, -0.434614, 0.852504},
+ {0.264351, 0.395642, 0.879513},
+ {0.555559, 0.831446, 0.000000},
+ {0.264351, 0.395642, -0.879513},
+ {-0.290384, -0.434614, -0.852504},
+ {-0.382672, -0.923856, 0.000000},
+ {-0.200018, -0.482894, 0.852504},
+ {0.182073, 0.439619, 0.879513},
+ {0.382672, 0.923856, 0.000000},
+ {0.182073, 0.439619, -0.879513},
+ {-0.200018, -0.482894, -0.852504},
+ {-0.195074, -0.980773, 0.000000},
+ {-0.101962, -0.512650, 0.852504},
+ {0.092807, 0.466689, 0.879513},
+ {0.195074, 0.980773, 0.000000},
+ {0.092807, 0.466689, -0.879513},
+ {-0.101962, -0.512650, -0.852504},
+ {0.000000, -1.000000, 0.000000},
+ {0.000000, -0.522691, 0.852504},
+ {0.000000, 0.475845, 0.879513},
+ {0.000000, 1.000000, 0.000000},
+ {0.000000, 0.475845, -0.879513},
+ {0.000000, -0.522691, -0.852504},
+ {0.195074, -0.980773, 0.000000},
+ {0.101962, -0.512650, 0.852504},
+ {-0.092807, 0.466689, 0.879513},
+ {-0.195074, 0.980773, 0.000000},
+ {-0.092807, 0.466689, -0.879513},
+ {0.101962, -0.512650, -0.852504},
+ {0.382672, -0.923856, 0.000000},
+ {0.200018, -0.482894, 0.852504},
+ {-0.182073, 0.439619, 0.879513},
+ {-0.382672, 0.923856, 0.000000},
+ {-0.182073, 0.439619, -0.879513},
+ {0.200018, -0.482894, -0.852504},
+ {0.555559, -0.831446, 0.000000},
+ {0.290384, -0.434614, 0.852504},
+ {-0.264351, 0.395642, 0.879513},
+ {-0.555559, 0.831446, 0.000000},
+ {-0.264351, 0.395642, -0.879513},
+ {0.290384, -0.434614, -0.852504},
+ {0.707083, -0.707083, 0.000000},
+ {0.369610, -0.369610, 0.852504},
+ {-0.336467, 0.336467, 0.879513},
+ {-0.707083, 0.707083, 0.000000},
+ {-0.336467, 0.336467, -0.879513},
+ {0.369610, -0.369610, -0.852504},
+ {0.831446, -0.555559, 0.000000},
+ {0.434614, -0.290384, 0.852504},
+ {-0.395642, 0.264351, 0.879513},
+ {-0.831446, 0.555559, 0.000000},
+ {-0.395642, 0.264351, -0.879513},
+ {0.434614, -0.290384, -0.852504},
+ {0.923856, -0.382672, 0.000000},
+ {0.482894, -0.200018, 0.852504},
+ {-0.439619, 0.182073, 0.879513},
+ {-0.923856, 0.382672, 0.000000},
+ {-0.439619, 0.182073, -0.879513},
+ {0.482894, -0.200018, -0.852504},
+ {0.980773, -0.195074, 0.000000},
+ {0.512650, -0.101962, 0.852504},
+ {-0.466689, 0.092807, 0.879513},
+ {-0.980773, 0.195074, 0.000000},
+ {-0.466689, 0.092807, -0.879513},
+ {0.512650, -0.101962, -0.852504},
+};
+
+static const unsigned short indices[] = {
+ 6, 7, 1,
+ 7, 8, 2,
+ 8, 9, 3,
+ 9, 10, 4,
+ 10, 11, 5,
+ 5, 11, 6,
+ 12, 13, 7,
+ 13, 14, 8,
+ 14, 15, 9,
+ 15, 16, 10,
+ 16, 17, 11,
+ 11, 17, 12,
+ 18, 19, 13,
+ 13, 19, 20,
+ 20, 21, 15,
+ 15, 21, 22,
+ 22, 23, 17,
+ 17, 23, 18,
+ 24, 25, 19,
+ 19, 25, 26,
+ 26, 27, 21,
+ 21, 27, 28,
+ 28, 29, 23,
+ 23, 29, 24,
+ 30, 31, 25,
+ 25, 31, 32,
+ 26, 32, 33,
+ 27, 33, 34,
+ 34, 35, 29,
+ 29, 35, 30,
+ 36, 37, 31,
+ 31, 37, 38,
+ 38, 39, 33,
+ 39, 40, 34,
+ 40, 41, 35,
+ 35, 41, 36,
+ 36, 42, 43,
+ 43, 44, 38,
+ 44, 45, 39,
+ 45, 46, 40,
+ 46, 47, 41,
+ 47, 42, 36,
+ 48, 49, 43,
+ 49, 50, 44,
+ 50, 51, 45,
+ 51, 52, 46,
+ 52, 53, 47,
+ 47, 53, 48,
+ 54, 55, 49,
+ 49, 55, 56,
+ 50, 56, 57,
+ 57, 58, 52,
+ 58, 59, 53,
+ 53, 59, 54,
+ 60, 61, 55,
+ 55, 61, 62,
+ 56, 62, 63,
+ 63, 64, 58,
+ 64, 65, 59,
+ 59, 65, 60,
+ 66, 67, 61,
+ 61, 67, 68,
+ 68, 69, 63,
+ 69, 70, 64,
+ 70, 71, 65,
+ 71, 66, 60,
+ 72, 73, 67,
+ 73, 74, 68,
+ 68, 74, 75,
+ 75, 76, 70,
+ 76, 77, 71,
+ 71, 77, 72,
+ 78, 79, 73,
+ 79, 80, 74,
+ 74, 80, 81,
+ 81, 82, 76,
+ 82, 83, 77,
+ 83, 78, 72,
+ 78, 84, 85,
+ 85, 86, 80,
+ 80, 86, 87,
+ 87, 88, 82,
+ 82, 88, 89,
+ 89, 84, 78,
+ 90, 91, 85,
+ 91, 92, 86,
+ 86, 92, 93,
+ 93, 94, 88,
+ 88, 94, 95,
+ 95, 90, 84,
+ 96, 97, 91,
+ 97, 98, 92,
+ 98, 99, 93,
+ 99, 100, 94,
+ 100, 101, 95,
+ 101, 96, 90,
+ 102, 103, 97,
+ 103, 104, 98,
+ 104, 105, 99,
+ 99, 105, 106,
+ 106, 107, 101,
+ 101, 107, 102,
+ 108, 109, 103,
+ 103, 109, 110,
+ 110, 111, 105,
+ 105, 111, 112,
+ 112, 113, 107,
+ 107, 113, 108,
+ 114, 115, 109,
+ 115, 116, 110,
+ 116, 117, 111,
+ 111, 117, 118,
+ 112, 118, 119,
+ 113, 119, 114,
+ 114, 120, 121,
+ 121, 122, 116,
+ 122, 123, 117,
+ 117, 123, 124,
+ 124, 125, 119,
+ 125, 120, 114,
+ 126, 127, 121,
+ 121, 127, 128,
+ 128, 129, 123,
+ 123, 129, 130,
+ 130, 131, 125,
+ 125, 131, 126,
+ 132, 133, 127,
+ 133, 134, 128,
+ 128, 134, 135,
+ 135, 136, 130,
+ 136, 137, 131,
+ 131, 137, 132,
+ 132, 138, 139,
+ 133, 139, 140,
+ 134, 140, 141,
+ 141, 142, 136,
+ 142, 143, 137,
+ 143, 138, 132,
+ 138, 144, 145,
+ 139, 145, 146,
+ 146, 147, 141,
+ 141, 147, 148,
+ 148, 149, 143,
+ 149, 144, 138,
+ 144, 150, 151,
+ 151, 152, 146,
+ 146, 152, 153,
+ 153, 154, 148,
+ 154, 155, 149,
+ 155, 150, 144,
+ 156, 157, 151,
+ 151, 157, 158,
+ 158, 159, 153,
+ 159, 160, 154,
+ 160, 161, 155,
+ 155, 161, 156,
+ 156, 162, 163,
+ 163, 164, 158,
+ 158, 164, 165,
+ 165, 166, 160,
+ 160, 166, 167,
+ 167, 162, 156,
+ 162, 168, 169,
+ 169, 170, 164,
+ 164, 170, 171,
+ 165, 171, 172,
+ 166, 172, 173,
+ 173, 168, 162,
+ 174, 175, 169,
+ 175, 176, 170,
+ 170, 176, 177,
+ 177, 178, 172,
+ 172, 178, 179,
+ 173, 179, 174,
+ 174, 180, 181,
+ 181, 182, 176,
+ 176, 182, 183,
+ 183, 184, 178,
+ 178, 184, 185,
+ 179, 185, 180,
+ 186, 187, 181,
+ 187, 188, 182,
+ 188, 189, 183,
+ 183, 189, 190,
+ 190, 191, 185,
+ 191, 186, 180,
+ 0, 1, 187,
+ 1, 2, 188,
+ 2, 3, 189,
+ 3, 4, 190,
+ 190, 4, 5,
+ 191, 5, 0,
+ 0, 6, 1,
+ 1, 7, 2,
+ 2, 8, 3,
+ 3, 9, 4,
+ 4, 10, 5,
+ 0, 5, 6,
+ 6, 12, 7,
+ 7, 13, 8,
+ 8, 14, 9,
+ 9, 15, 10,
+ 10, 16, 11,
+ 6, 11, 12,
+ 12, 18, 13,
+ 14, 13, 20,
+ 14, 20, 15,
+ 16, 15, 22,
+ 16, 22, 17,
+ 12, 17, 18,
+ 18, 24, 19,
+ 20, 19, 26,
+ 20, 26, 21,
+ 22, 21, 28,
+ 22, 28, 23,
+ 18, 23, 24,
+ 24, 30, 25,
+ 26, 25, 32,
+ 27, 26, 33,
+ 28, 27, 34,
+ 28, 34, 29,
+ 24, 29, 30,
+ 30, 36, 31,
+ 32, 31, 38,
+ 32, 38, 33,
+ 33, 39, 34,
+ 34, 40, 35,
+ 30, 35, 36,
+ 37, 36, 43,
+ 37, 43, 38,
+ 38, 44, 39,
+ 39, 45, 40,
+ 40, 46, 41,
+ 41, 47, 36,
+ 42, 48, 43,
+ 43, 49, 44,
+ 44, 50, 45,
+ 45, 51, 46,
+ 46, 52, 47,
+ 42, 47, 48,
+ 48, 54, 49,
+ 50, 49, 56,
+ 51, 50, 57,
+ 51, 57, 52,
+ 52, 58, 53,
+ 48, 53, 54,
+ 54, 60, 55,
+ 56, 55, 62,
+ 57, 56, 63,
+ 57, 63, 58,
+ 58, 64, 59,
+ 54, 59, 60,
+ 60, 66, 61,
+ 62, 61, 68,
+ 62, 68, 63,
+ 63, 69, 64,
+ 64, 70, 65,
+ 65, 71, 60,
+ 66, 72, 67,
+ 67, 73, 68,
+ 69, 68, 75,
+ 69, 75, 70,
+ 70, 76, 71,
+ 66, 71, 72,
+ 72, 78, 73,
+ 73, 79, 74,
+ 75, 74, 81,
+ 75, 81, 76,
+ 76, 82, 77,
+ 77, 83, 72,
+ 79, 78, 85,
+ 79, 85, 80,
+ 81, 80, 87,
+ 81, 87, 82,
+ 83, 82, 89,
+ 83, 89, 78,
+ 84, 90, 85,
+ 85, 91, 86,
+ 87, 86, 93,
+ 87, 93, 88,
+ 89, 88, 95,
+ 89, 95, 84,
+ 90, 96, 91,
+ 91, 97, 92,
+ 92, 98, 93,
+ 93, 99, 94,
+ 94, 100, 95,
+ 95, 101, 90,
+ 96, 102, 97,
+ 97, 103, 98,
+ 98, 104, 99,
+ 100, 99, 106,
+ 100, 106, 101,
+ 96, 101, 102,
+ 102, 108, 103,
+ 104, 103, 110,
+ 104, 110, 105,
+ 106, 105, 112,
+ 106, 112, 107,
+ 102, 107, 108,
+ 108, 114, 109,
+ 109, 115, 110,
+ 110, 116, 111,
+ 112, 111, 118,
+ 113, 112, 119,
+ 108, 113, 114,
+ 115, 114, 121,
+ 115, 121, 116,
+ 116, 122, 117,
+ 118, 117, 124,
+ 118, 124, 119,
+ 119, 125, 114,
+ 120, 126, 121,
+ 122, 121, 128,
+ 122, 128, 123,
+ 124, 123, 130,
+ 124, 130, 125,
+ 120, 125, 126,
+ 126, 132, 127,
+ 127, 133, 128,
+ 129, 128, 135,
+ 129, 135, 130,
+ 130, 136, 131,
+ 126, 131, 132,
+ 133, 132, 139,
+ 134, 133, 140,
+ 135, 134, 141,
+ 135, 141, 136,
+ 136, 142, 137,
+ 137, 143, 132,
+ 139, 138, 145,
+ 140, 139, 146,
+ 140, 146, 141,
+ 142, 141, 148,
+ 142, 148, 143,
+ 143, 149, 138,
+ 145, 144, 151,
+ 145, 151, 146,
+ 147, 146, 153,
+ 147, 153, 148,
+ 148, 154, 149,
+ 149, 155, 144,
+ 150, 156, 151,
+ 152, 151, 158,
+ 152, 158, 153,
+ 153, 159, 154,
+ 154, 160, 155,
+ 150, 155, 156,
+ 157, 156, 163,
+ 157, 163, 158,
+ 159, 158, 165,
+ 159, 165, 160,
+ 161, 160, 167,
+ 161, 167, 156,
+ 163, 162, 169,
+ 163, 169, 164,
+ 165, 164, 171,
+ 166, 165, 172,
+ 167, 166, 173,
+ 167, 173, 162,
+ 168, 174, 169,
+ 169, 175, 170,
+ 171, 170, 177,
+ 171, 177, 172,
+ 173, 172, 179,
+ 168, 173, 174,
+ 175, 174, 181,
+ 175, 181, 176,
+ 177, 176, 183,
+ 177, 183, 178,
+ 179, 178, 185,
+ 174, 179, 180,
+ 180, 186, 181,
+ 181, 187, 182,
+ 182, 188, 183,
+ 184, 183, 190,
+ 184, 190, 185,
+ 185, 191, 180,
+ 186, 0, 187,
+ 187, 1, 188,
+ 188, 2, 189,
+ 189, 3, 190,
+ 191, 190, 5,
+ 186, 191, 0,
+};
+
+ManipulatorGeomInfo wm_manipulator_geom_data_dial = {
+ .nverts = 192,
+ .ntris = 384,
+ .verts = verts,
+ .normals = normals,
+ .indices = indices,
+};
diff --git a/source/blender/editors/manipulator_library/manipulator_draw_utils.c b/source/blender/editors/manipulator_library/manipulator_draw_utils.c
new file mode 100644
index 00000000000..430841311aa
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_draw_utils.c
@@ -0,0 +1,131 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file manipulator_draw_utils.c
+ * \ingroup wm
+ */
+
+#include "BLI_listbase.h"
+#include "BLI_ghash.h"
+#include "BLI_math.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_context.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "GPU_batch.h"
+#include "GPU_glew.h"
+#include "GPU_immediate.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/* only for own init/exit calls (wm_manipulatortype_init/wm_manipulatortype_free) */
+#include "wm.h"
+
+/* own includes */
+#include "manipulator_library_intern.h"
+
+/**
+ * Main draw call for ManipulatorGeomInfo data
+ */
+void wm_manipulator_geometryinfo_draw(const ManipulatorGeomInfo *info, const bool select, const float color[4])
+{
+ /* TODO store the Batches inside the ManipulatorGeomInfo and updated it when geom changes
+ * So we don't need to re-created and discard it every time */
+
+ const bool use_lighting = true || (!select && ((U.manipulator_flag & USER_MANIPULATOR_SHADED) != 0));
+ Gwn_VertBuf *vbo;
+ Gwn_IndexBuf *el;
+ Gwn_Batch *batch;
+ Gwn_IndexBufBuilder elb = {0};
+
+ Gwn_VertFormat format = {0};
+ uint pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ uint nor_id;
+
+ if (use_lighting) {
+ nor_id = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_I16, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+
+ /* Elements */
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, info->ntris, info->nverts);
+ for (int i = 0; i < info->ntris; ++i) {
+ const unsigned short *idx = &info->indices[i * 3];
+ GWN_indexbuf_add_tri_verts(&elb, idx[0], idx[1], idx[2]);
+ }
+ el = GWN_indexbuf_build(&elb);
+
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, info->nverts);
+
+ GWN_vertbuf_attr_fill(vbo, pos_id, info->verts);
+
+ if (use_lighting) {
+ /* Normals are expected to be smooth. */
+ GWN_vertbuf_attr_fill(vbo, nor_id, info->normals);
+ }
+
+ batch = GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, el, GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR);
+
+ GWN_batch_uniform_4fv(batch, "color", color);
+
+ /* We may want to re-visit this, for now disable
+ * since it causes issues leaving the GL state modified. */
+#if 0
+ glEnable(GL_CULL_FACE);
+ glEnable(GL_DEPTH_TEST);
+#endif
+
+ GWN_batch_draw(batch);
+
+#if 0
+ glDisable(GL_DEPTH_TEST);
+ glDisable(GL_CULL_FACE);
+#endif
+
+
+ GWN_batch_discard(batch);
+}
+
+void wm_manipulator_vec_draw(
+ const float color[4], const float (*verts)[3], uint vert_count,
+ uint pos, uint primitive_type)
+{
+ immUniformColor4fv(color);
+ immBegin(primitive_type, vert_count);
+ for (int i = 0; i < vert_count; i++) {
+ immVertex3fv(pos, verts[i]);
+ }
+ immEnd();
+}
diff --git a/source/blender/editors/manipulator_library/manipulator_geometry.h b/source/blender/editors/manipulator_library/manipulator_geometry.h
new file mode 100644
index 00000000000..2083f9d4d31
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_geometry.h
@@ -0,0 +1,54 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file manipulator_geometry.h
+ * \ingroup wm
+ *
+ * \name Manipulator Geometry
+ *
+ * \brief Prototypes for arrays defining the manipulator geometry. The actual definitions can be found in files usually
+ * called geom_xxx_manipulator.c
+ */
+
+
+#ifndef __MANIPULATOR_GEOMETRY_H__
+#define __MANIPULATOR_GEOMETRY_H__
+
+typedef struct ManipulatorGeomInfo {
+ int nverts;
+ int ntris;
+ const float (*verts)[3];
+ const float (*normals)[3];
+ const unsigned short *indices;
+} ManipulatorGeomInfo;
+
+/* arrow manipulator */
+extern ManipulatorGeomInfo wm_manipulator_geom_data_arrow;
+
+/* cube manipulator */
+extern ManipulatorGeomInfo wm_manipulator_geom_data_cube;
+
+/* dial manipulator */
+extern ManipulatorGeomInfo wm_manipulator_geom_data_dial;
+
+#endif /* __MANIPULATOR_GEOMETRY_H__ */
diff --git a/source/blender/editors/manipulator_library/manipulator_library_intern.h b/source/blender/editors/manipulator_library/manipulator_library_intern.h
new file mode 100644
index 00000000000..92ca195f21d
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_library_intern.h
@@ -0,0 +1,108 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file manipulator_library_intern.h
+ * \ingroup wm
+ */
+
+#ifndef __MANIPULATOR_LIBRARY_INTERN_H__
+#define __MANIPULATOR_LIBRARY_INTERN_H__
+
+/* distance around which manipulators respond to input (and get highlighted) */
+#define MANIPULATOR_HOTSPOT 14.0f
+
+/**
+ * Data for common interactions. Used in manipulator_library_utils.c functions.
+ */
+typedef struct ManipulatorCommonData {
+ int flag;
+
+ float range_fac; /* factor for arrow min/max distance */
+ float offset;
+
+ /* property range for constrained manipulators */
+ float range;
+ /* min/max value for constrained manipulators */
+ float min, max;
+} ManipulatorCommonData;
+
+typedef struct ManipulatorInteraction {
+ float init_value; /* initial property value */
+ float init_mval[2];
+ float init_offset;
+ float init_matrix_final[4][4];
+ float init_matrix_basis[4][4];
+
+ /* offset of last handling step */
+ float prev_offset;
+ /* Total offset added by precision tweaking.
+ * Needed to allow toggling precision on/off without causing jumps */
+ float precision_offset;
+} ManipulatorInteraction;
+
+/* ManipulatorCommonData->flag */
+enum {
+ MANIPULATOR_CUSTOM_RANGE_SET = (1 << 0),
+};
+
+
+float manipulator_offset_from_value(
+ ManipulatorCommonData *data, const float value,
+ const bool constrained, const bool inverted);
+float manipulator_value_from_offset(
+ ManipulatorCommonData *data, ManipulatorInteraction *inter, const float offset,
+ const bool constrained, const bool inverted, const bool use_precision);
+
+void manipulator_property_data_update(
+ struct wmManipulator *mpr, ManipulatorCommonData *data, wmManipulatorProperty *mpr_prop,
+ const bool constrained, const bool inverted);
+
+void manipulator_property_value_reset(
+ bContext *C, const struct wmManipulator *mpr, ManipulatorInteraction *inter, wmManipulatorProperty *mpr_prop);
+
+
+/* -------------------------------------------------------------------- */
+
+void manipulator_color_get(
+ const struct wmManipulator *mpr, const bool highlight,
+ float r_color[4]);
+
+bool manipulator_window_project_2d(
+ bContext *C, const struct wmManipulator *mpr, const float mval[2], int axis, bool use_offset,
+ float r_co[2]);
+
+/* -------------------------------------------------------------------- */
+/* Manipulator drawing */
+
+#include "manipulator_geometry.h"
+
+void wm_manipulator_geometryinfo_draw(const struct ManipulatorGeomInfo *info, const bool select, const float color[4]);
+void wm_manipulator_vec_draw(
+ const float color[4], const float (*verts)[3], uint vert_count,
+ uint pos, uint primitive_type);
+
+
+#endif /* __MANIPULATOR_LIBRARY_INTERN_H__ */
+
diff --git a/source/blender/editors/manipulator_library/manipulator_library_presets.c b/source/blender/editors/manipulator_library/manipulator_library_presets.c
new file mode 100644
index 00000000000..cccf484f29d
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_library_presets.c
@@ -0,0 +1,151 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/manipulator_library/manipulator_library_presets.c
+ * \ingroup wm
+ *
+ * \name Manipulator Lib Presets
+ *
+ * \brief Preset shapes that can be drawn from any manipulator type.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "DNA_view3d_types.h"
+#include "DNA_object_types.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+
+#include "DEG_depsgraph.h"
+
+#include "RNA_access.h"
+
+#include "WM_types.h"
+#include "WM_api.h"
+
+#include "ED_view3d.h"
+#include "ED_screen.h"
+
+/* own includes */
+#include "ED_manipulator_library.h" /* own include */
+#include "manipulator_library_intern.h" /* own include */
+
+/* TODO, this is to be used by RNA. might move to ED_manipulator_library */
+
+/**
+ * Given a single axis, orient the matrix to a different direction.
+ */
+static void single_axis_convert(
+ int src_axis, float src_mat[4][4],
+ int dst_axis, float dst_mat[4][4])
+{
+ copy_m4_m4(dst_mat, src_mat);
+ if (src_axis == dst_axis) {
+ return;
+ }
+
+ float rotmat[3][3];
+ mat3_from_axis_conversion_single(src_axis, dst_axis, rotmat);
+ transpose_m3(rotmat);
+ mul_m4_m4m3(dst_mat, src_mat, rotmat);
+}
+
+/**
+ * Use for all geometry.
+ */
+static void ed_manipulator_draw_preset_geometry(
+ const struct wmManipulator *mpr, float mat[4][4], int select_id,
+ const ManipulatorGeomInfo *info)
+{
+ const bool is_select = (select_id != -1);
+ const bool is_highlight = is_select && (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+
+ float color[4];
+ manipulator_color_get(mpr, is_highlight, color);
+
+ if (is_select) {
+ GPU_select_load_id(select_id);
+ }
+
+ gpuPushMatrix();
+ gpuMultMatrix(mat);
+ wm_manipulator_geometryinfo_draw(info, is_select, color);
+ gpuPopMatrix();
+
+ if (is_select) {
+ GPU_select_load_id(-1);
+ }
+}
+
+void ED_manipulator_draw_preset_box(
+ const struct wmManipulator *mpr, float mat[4][4], int select_id)
+{
+ ed_manipulator_draw_preset_geometry(mpr, mat, select_id, &wm_manipulator_geom_data_cube);
+}
+
+void ED_manipulator_draw_preset_arrow(
+ const struct wmManipulator *mpr, float mat[4][4], int axis, int select_id)
+{
+ float mat_rotate[4][4];
+ single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
+ ed_manipulator_draw_preset_geometry(mpr, mat_rotate, select_id, &wm_manipulator_geom_data_arrow);
+}
+
+void ED_manipulator_draw_preset_circle(
+ const struct wmManipulator *mpr, float mat[4][4], int axis, int select_id)
+{
+ float mat_rotate[4][4];
+ single_axis_convert(OB_POSZ, mat, axis, mat_rotate);
+ ed_manipulator_draw_preset_geometry(mpr, mat_rotate, select_id, &wm_manipulator_geom_data_dial);
+}
+
+void ED_manipulator_draw_preset_facemap(
+ const bContext *C, const struct wmManipulator *mpr, struct Scene *scene, Object *ob, const int facemap, int select_id)
+{
+ const bool is_select = (select_id != -1);
+ const bool is_highlight = is_select && (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+
+ float color[4];
+ manipulator_color_get(mpr, is_highlight, color);
+
+ if (is_select) {
+ GPU_select_load_id(select_id);
+ }
+
+ gpuPushMatrix();
+ gpuMultMatrix(ob->obmat);
+ ED_draw_object_facemap(CTX_data_depsgraph(C), scene, ob, color, facemap);
+ gpuPopMatrix();
+
+ if (is_select) {
+ GPU_select_load_id(-1);
+ }
+}
+
diff --git a/source/blender/editors/manipulator_library/manipulator_library_utils.c b/source/blender/editors/manipulator_library/manipulator_library_utils.c
new file mode 100644
index 00000000000..12f9d1b48d3
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_library_utils.c
@@ -0,0 +1,221 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2015 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file manipulator_library_utils.c
+ * \ingroup wm
+ *
+ * \name Manipulator Library Utilities
+ *
+ * \brief This file contains functions for common behaviors of manipulators.
+ */
+
+#include "BLI_math.h"
+#include "BLI_listbase.h"
+
+#include "DNA_view3d_types.h"
+#include "DNA_screen_types.h"
+
+#include "BKE_context.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_view3d.h"
+
+/* own includes */
+#include "manipulator_library_intern.h"
+
+/* factor for precision tweaking */
+#define MANIPULATOR_PRECISION_FAC 0.05f
+
+
+BLI_INLINE float manipulator_offset_from_value_constr(
+ const float range_fac, const float min, const float range, const float value,
+ const bool inverted)
+{
+ return inverted ? (range_fac * (min + range - value) / range) : (range_fac * (value / range));
+}
+
+BLI_INLINE float manipulator_value_from_offset_constr(
+ const float range_fac, const float min, const float range, const float value,
+ const bool inverted)
+{
+ return inverted ? (min + range - (value * range / range_fac)) : (value * range / range_fac);
+}
+
+float manipulator_offset_from_value(
+ ManipulatorCommonData *data, const float value, const bool constrained, const bool inverted)
+{
+ if (constrained)
+ return manipulator_offset_from_value_constr(data->range_fac, data->min, data->range, value, inverted);
+
+ return value;
+}
+
+float manipulator_value_from_offset(
+ ManipulatorCommonData *data, ManipulatorInteraction *inter, const float offset,
+ const bool constrained, const bool inverted, const bool use_precision)
+{
+ const float max = data->min + data->range;
+
+ if (use_precision) {
+ /* add delta offset of this step to total precision_offset */
+ inter->precision_offset += offset - inter->prev_offset;
+ }
+ inter->prev_offset = offset;
+
+ float ofs_new = inter->init_offset + offset - inter->precision_offset * (1.0f - MANIPULATOR_PRECISION_FAC);
+ float value;
+
+ if (constrained) {
+ value = manipulator_value_from_offset_constr(data->range_fac, data->min, data->range, ofs_new, inverted);
+ }
+ else {
+ value = ofs_new;
+ }
+
+ /* clamp to custom range */
+ if (data->flag & MANIPULATOR_CUSTOM_RANGE_SET) {
+ CLAMP(value, data->min, max);
+ }
+
+ return value;
+}
+
+void manipulator_property_data_update(
+ wmManipulator *mpr, ManipulatorCommonData *data, wmManipulatorProperty *mpr_prop,
+ const bool constrained, const bool inverted)
+{
+ if (mpr_prop->custom_func.value_get_fn != NULL) {
+ /* pass */
+ }
+ else if (mpr_prop->prop != NULL) {
+ /* pass */
+ }
+ else {
+ data->offset = 0.0f;
+ return;
+ }
+
+ float value = WM_manipulator_target_property_value_get(mpr, mpr_prop);
+
+ if (constrained) {
+ if ((data->flag & MANIPULATOR_CUSTOM_RANGE_SET) == 0) {
+ float range[2];
+ if (WM_manipulator_target_property_range_get(mpr, mpr_prop, range)) {
+ data->range = range[1] - range[0];
+ data->min = range[0];
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ data->offset = manipulator_offset_from_value_constr(data->range_fac, data->min, data->range, value, inverted);
+ }
+ else {
+ data->offset = value;
+ }
+}
+
+void manipulator_property_value_reset(
+ bContext *C, const wmManipulator *mpr, ManipulatorInteraction *inter,
+ wmManipulatorProperty *mpr_prop)
+{
+ WM_manipulator_target_property_value_set(C, mpr, mpr_prop, inter->init_value);
+}
+
+/* -------------------------------------------------------------------- */
+
+void manipulator_color_get(
+ const wmManipulator *mpr, const bool highlight,
+ float r_col[4])
+{
+ if (highlight && !(mpr->flag & WM_MANIPULATOR_DRAW_HOVER)) {
+ copy_v4_v4(r_col, mpr->color_hi);
+ }
+ else {
+ copy_v4_v4(r_col, mpr->color);
+ }
+}
+
+/* -------------------------------------------------------------------- */
+
+/**
+ * Takes mouse coordinates and returns them in relation to the manipulator.
+ * Both 2D & 3D supported, use so we can use 2D manipulators in the 3D view.
+ */
+bool manipulator_window_project_2d(
+ bContext *C, const struct wmManipulator *mpr, const float mval[2], int axis, bool use_offset,
+ float r_co[2])
+{
+ float mat[4][4];
+ {
+ float mat_identity[4][4];
+ struct WM_ManipulatorMatrixParams params = {NULL};
+ if (use_offset == false) {
+ unit_m4(mat_identity);
+ params.matrix_offset = mat_identity;
+ }
+ WM_manipulator_calc_matrix_final_params(mpr, &params, mat);
+ }
+
+ /* rotate mouse in relation to the center and relocate it */
+ if (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) {
+ /* For 3d views, transform 2D mouse pos onto plane. */
+ View3D *v3d = CTX_wm_view3d(C);
+ ARegion *ar = CTX_wm_region(C);
+
+ float plane[4];
+
+ plane_from_point_normal_v3(plane, mat[3], mat[2]);
+
+ float ray_origin[3], ray_direction[3];
+
+ if (ED_view3d_win_to_ray(CTX_data_depsgraph(C), ar, v3d, mval, ray_origin, ray_direction, false)) {
+ float lambda;
+ if (isect_ray_plane_v3(ray_origin, ray_direction, plane, &lambda, true)) {
+ float co[3];
+ madd_v3_v3v3fl(co, ray_origin, ray_direction, lambda);
+ float imat[4][4];
+ invert_m4_m4(imat, mat);
+ mul_m4_v3(imat, co);
+ r_co[0] = co[(axis + 1) % 3];
+ r_co[1] = co[(axis + 2) % 3];
+ return true;
+ }
+ }
+ return false;
+ }
+ else {
+ float co[3] = {mval[0], mval[1], 0.0f};
+ float imat[4][4];
+ invert_m4_m4(imat, mat);
+ mul_m4_v3(imat, co);
+ copy_v2_v2(r_co, co);
+ return true;
+ }
+}
diff --git a/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
new file mode 100644
index 00000000000..749e92e25fb
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow2d_manipulator.c
@@ -0,0 +1,224 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file arrow2d_manipulator.c
+ * \ingroup wm
+ *
+ * \name 2D Arrow Manipulator
+ *
+ * \brief Simple arrow manipulator which is dragged into a certain direction.
+ */
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_rect.h"
+
+#include "DNA_windowmanager_types.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+/* own includes */
+#include "WM_api.h"
+
+#include "../manipulator_library_intern.h"
+
+static void arrow2d_draw_geom(wmManipulator *mpr, const float matrix[4][4], const float color[4])
+{
+ const float size = 0.11f;
+ const float size_breadth = size / 2.0f;
+ const float size_length = size * 1.7f;
+ /* Subtract the length so the arrow fits in the hotspot. */
+ const float arrow_length = RNA_float_get(mpr->ptr, "length") - size_length;
+ const float arrow_angle = RNA_float_get(mpr->ptr, "angle");
+
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix);
+ gpuRotate2D(RAD2DEGF(arrow_angle));
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4fv(color);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, 0.0f, 0.0f);
+ immVertex2f(pos, 0.0f, arrow_length);
+ immEnd();
+
+ immBegin(GWN_PRIM_TRIS, 3);
+ immVertex2f(pos, size_breadth, arrow_length);
+ immVertex2f(pos, -size_breadth, arrow_length);
+ immVertex2f(pos, 0.0f, arrow_length + size_length);
+ immEnd();
+
+ immUnbindProgram();
+
+ gpuPopMatrix();
+}
+
+static void manipulator_arrow2d_draw(const bContext *UNUSED(C), wmManipulator *mpr)
+{
+ float color[4];
+
+ float matrix_final[4][4];
+
+ manipulator_color_get(mpr, mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT, color);
+
+ glLineWidth(mpr->line_width);
+
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+ glEnable(GL_BLEND);
+ arrow2d_draw_geom(mpr, matrix_final, color);
+ glDisable(GL_BLEND);
+
+ if (mpr->interaction_data) {
+ ManipulatorInteraction *inter = mpr->interaction_data;
+
+ glEnable(GL_BLEND);
+ arrow2d_draw_geom(mpr, inter->init_matrix_final, (const float[4]){0.5f, 0.5f, 0.5f, 0.5f});
+ glDisable(GL_BLEND);
+ }
+}
+
+static void manipulator_arrow2d_setup(wmManipulator *mpr)
+{
+ mpr->flag |= WM_MANIPULATOR_DRAW_MODAL;
+}
+
+static int manipulator_arrow2d_invoke(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *UNUSED(event))
+{
+ ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
+
+ copy_m4_m4(inter->init_matrix_basis, mpr->matrix_basis);
+ WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
+
+ mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int manipulator_arrow2d_test_select(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
+{
+ const float mval[2] = {event->mval[0], event->mval[1]};
+ const float arrow_length = RNA_float_get(mpr->ptr, "length");
+ const float arrow_angle = RNA_float_get(mpr->ptr, "angle");
+ const float line_len = arrow_length * mpr->scale_final;
+ float mval_local[2];
+
+ copy_v2_v2(mval_local, mval);
+ sub_v2_v2(mval_local, mpr->matrix_basis[3]);
+
+ float line[2][2];
+ line[0][0] = line[0][1] = line[1][0] = 0.0f;
+ line[1][1] = line_len;
+
+ /* rotate only if needed */
+ if (arrow_angle != 0.0f) {
+ float rot_point[2];
+ copy_v2_v2(rot_point, line[1]);
+ rotate_v2_v2fl(line[1], rot_point, arrow_angle);
+ }
+
+ /* arrow line intersection check */
+ float isect_1[2], isect_2[2];
+ const int isect = isect_line_sphere_v2(
+ line[0], line[1], mval_local, MANIPULATOR_HOTSPOT + mpr->line_width * 0.5f,
+ isect_1, isect_2);
+
+ if (isect > 0) {
+ float line_ext[2][2]; /* extended line for segment check including hotspot */
+ copy_v2_v2(line_ext[0], line[0]);
+ line_ext[1][0] = line[1][0] + MANIPULATOR_HOTSPOT * ((line[1][0] - line[0][0]) / line_len);
+ line_ext[1][1] = line[1][1] + MANIPULATOR_HOTSPOT * ((line[1][1] - line[0][1]) / line_len);
+
+ const float lambda_1 = line_point_factor_v2(isect_1, line_ext[0], line_ext[1]);
+ if (isect == 1) {
+ if (IN_RANGE_INCL(lambda_1, 0.0f, 1.0f)) {
+ return 0;
+ }
+ }
+ else {
+ BLI_assert(isect == 2);
+ const float lambda_2 = line_point_factor_v2(isect_2, line_ext[0], line_ext[1]);
+ if (IN_RANGE_INCL(lambda_1, 0.0f, 1.0f) && IN_RANGE_INCL(lambda_2, 0.0f, 1.0f)) {
+ return 0;
+ }
+ }
+ }
+
+ return -1;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name 2D Arrow Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_arrow_2d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_arrow_2d";
+
+ /* api callbacks */
+ wt->draw = manipulator_arrow2d_draw;
+ wt->setup = manipulator_arrow2d_setup;
+ wt->invoke = manipulator_arrow2d_invoke;
+ wt->test_select = manipulator_arrow2d_test_select;
+
+ wt->struct_size = sizeof(wmManipulator);
+
+ /* rna */
+ RNA_def_float(wt->srna, "length", 1.0f, 0.0f, FLT_MAX, "Arrow Line Length", "", 0.0f, FLT_MAX);
+ RNA_def_float_rotation(
+ wt->srna, "angle", 0, NULL, DEG2RADF(-360.0f), DEG2RADF(360.0f),
+ "Roll", "", DEG2RADF(-360.0f), DEG2RADF(360.0f));
+}
+
+void ED_manipulatortypes_arrow_2d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_arrow_2d);
+}
+
+/** \} */
diff --git a/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
new file mode 100644
index 00000000000..cc8fd72aa03
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/arrow3d_manipulator.c
@@ -0,0 +1,478 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file arrow3d_manipulator.c
+ * \ingroup wm
+ *
+ * \name Arrow Manipulator
+ *
+ * 3D Manipulator
+ *
+ * \brief Simple arrow manipulator which is dragged into a certain direction.
+ * The arrow head can have varying shapes, e.g. cone, box, etc.
+ *
+ * - `matrix[0]` is derived from Y and Z.
+ * - `matrix[1]` is 'up' for manipulator types that have an up.
+ * - `matrix[2]` is the arrow direction (for all arrowes).
+ */
+
+#include "BIF_gl.h"
+
+#include "BLI_math.h"
+
+#include "DNA_view3d_types.h"
+
+#include "BKE_context.h"
+
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_types.h"
+#include "WM_api.h"
+
+#include "ED_view3d.h"
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+/* own includes */
+#include "../manipulator_geometry.h"
+#include "../manipulator_library_intern.h"
+
+/* to use custom arrows exported to geom_arrow_manipulator.c */
+//#define USE_MANIPULATOR_CUSTOM_ARROWS
+
+typedef struct ArrowManipulator3D {
+ wmManipulator manipulator;
+ ManipulatorCommonData data;
+} ArrowManipulator3D;
+
+
+/* -------------------------------------------------------------------- */
+
+static void manipulator_arrow_matrix_basis_get(const wmManipulator *mpr, float r_matrix[4][4])
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+
+ copy_m4_m4(r_matrix, arrow->manipulator.matrix_basis);
+ madd_v3_v3fl(r_matrix[3], arrow->manipulator.matrix_basis[2], arrow->data.offset);
+}
+
+static void arrow_draw_geom(const ArrowManipulator3D *arrow, const bool select, const float color[4])
+{
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ bool unbind_shader = true;
+ const int draw_style = RNA_enum_get(arrow->manipulator.ptr, "draw_style");
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ if (draw_style == ED_MANIPULATOR_ARROW_STYLE_CROSS) {
+ immUniformColor4fv(color);
+
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex3f(pos, -1.0f, 0.0f, 0.0f);
+ immVertex3f(pos, 1.0f, 0.0f, 0.0f);
+ immVertex3f(pos, 0.0f, -1.0f, 0.0f);
+ immVertex3f(pos, 0.0f, 1.0f, 0.0f);
+ immEnd();
+ }
+ else if (draw_style == ED_MANIPULATOR_ARROW_STYLE_CONE) {
+ float aspect[2];
+ RNA_float_get_array(arrow->manipulator.ptr, "aspect", aspect);
+ const float unitx = aspect[0];
+ const float unity = aspect[1];
+ const float vec[4][3] = {
+ {-unitx, -unity, 0},
+ { unitx, -unity, 0},
+ { unitx, unity, 0},
+ {-unitx, unity, 0},
+ };
+
+ glLineWidth(arrow->manipulator.line_width);
+ wm_manipulator_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GWN_PRIM_LINE_LOOP);
+ }
+ else {
+#ifdef USE_MANIPULATOR_CUSTOM_ARROWS
+ wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_arrow, select, color);
+#else
+ const float arrow_length = RNA_float_get(arrow->manipulator.ptr, "length");
+
+ const float vec[2][3] = {
+ {0.0f, 0.0f, 0.0f},
+ {0.0f, 0.0f, arrow_length},
+ };
+
+ glLineWidth(arrow->manipulator.line_width);
+ wm_manipulator_vec_draw(color, vec, ARRAY_SIZE(vec), pos, GWN_PRIM_LINE_STRIP);
+
+
+ /* *** draw arrow head *** */
+
+ gpuPushMatrix();
+
+ if (draw_style == ED_MANIPULATOR_ARROW_STYLE_BOX) {
+ const float size = 0.05f;
+
+ /* translate to line end with some extra offset so box starts exactly where line ends */
+ gpuTranslate3f(0.0f, 0.0f, arrow_length + size);
+ /* scale down to box size */
+ gpuScale3f(size, size, size);
+
+ /* draw cube */
+ immUnbindProgram();
+ unbind_shader = false;
+ wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_cube, select, color);
+ }
+ else {
+ BLI_assert(draw_style == ED_MANIPULATOR_ARROW_STYLE_NORMAL);
+
+ const float len = 0.25f;
+ const float width = 0.06f;
+ const bool use_lighting = (!select && ((U.manipulator_flag & USER_MANIPULATOR_SHADED) != 0));
+
+ /* translate to line end */
+ gpuTranslate3f(0.0f, 0.0f, arrow_length);
+
+ if (use_lighting) {
+ immUnbindProgram();
+ immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR);
+ }
+
+ imm_draw_circle_fill_3d(pos, 0.0, 0.0, width, 8);
+ imm_draw_cylinder_fill_3d(pos, width, 0.0, len, 8, 1);
+ }
+
+ gpuPopMatrix();
+#endif /* USE_MANIPULATOR_CUSTOM_ARROWS */
+ }
+
+ if (unbind_shader) {
+ immUnbindProgram();
+ }
+}
+
+static void arrow_draw_intern(ArrowManipulator3D *arrow, const bool select, const bool highlight)
+{
+ wmManipulator *mpr = &arrow->manipulator;
+ float color[4];
+ float matrix_final[4][4];
+
+ manipulator_color_get(mpr, highlight, color);
+
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+ glEnable(GL_BLEND);
+ arrow_draw_geom(arrow, select, color);
+ glDisable(GL_BLEND);
+
+ gpuPopMatrix();
+
+ if (mpr->interaction_data) {
+ ManipulatorInteraction *inter = mpr->interaction_data;
+
+ gpuPushMatrix();
+ gpuMultMatrix(inter->init_matrix_final);
+
+
+ glEnable(GL_BLEND);
+ arrow_draw_geom(arrow, select, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f});
+ glDisable(GL_BLEND);
+
+ gpuPopMatrix();
+ }
+}
+
+static void manipulator_arrow_draw_select(
+ const bContext *UNUSED(C), wmManipulator *mpr,
+ int select_id)
+{
+ GPU_select_load_id(select_id);
+ arrow_draw_intern((ArrowManipulator3D *)mpr, true, false);
+}
+
+static void manipulator_arrow_draw(const bContext *UNUSED(C), wmManipulator *mpr)
+{
+ arrow_draw_intern((ArrowManipulator3D *)mpr, false, (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0);
+}
+
+/**
+ * Calculate arrow offset independent from prop min value,
+ * meaning the range will not be offset by min value first.
+ */
+static int manipulator_arrow_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak tweak_flag)
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+ ManipulatorInteraction *inter = mpr->interaction_data;
+ View3D *v3d = CTX_wm_view3d(C);
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+
+ float offset[3];
+ float facdir = 1.0f;
+
+ /* (src, dst) */
+ struct {
+ float mval[2];
+ float ray_origin[3], ray_direction[3];
+ float location[3];
+ } proj[2] = {
+ {.mval = {UNPACK2(inter->init_mval)}},
+ {.mval = {UNPACK2(event->mval)}},
+ };
+
+ float arrow_co[3];
+ float arrow_no[3];
+ copy_v3_v3(arrow_co, inter->init_matrix_basis[3]);
+ normalize_v3_v3(arrow_no, arrow->manipulator.matrix_basis[2]);
+
+ int ok = 0;
+
+ for (int j = 0; j < 2; j++) {
+ if (ED_view3d_win_to_ray(
+ CTX_data_depsgraph(C),
+ ar, v3d, proj[j].mval,
+ proj[j].ray_origin, proj[j].ray_direction, false))
+ {
+ /* Force Y axis if we're view aligned */
+ if (j == 0) {
+ if (RAD2DEGF(acosf(dot_v3v3(proj[j].ray_direction, arrow->manipulator.matrix_basis[2]))) < 5.0f) {
+ normalize_v3_v3(arrow_no, rv3d->viewinv[1]);
+ }
+ }
+
+ float arrow_no_proj[3];
+ project_plane_v3_v3v3(arrow_no_proj, arrow_no, proj[j].ray_direction);
+
+ normalize_v3(arrow_no_proj);
+
+ float plane[4];
+ plane_from_point_normal_v3(plane, proj[j].ray_origin, arrow_no_proj);
+
+ float lambda;
+ if (isect_ray_plane_v3(arrow_co, arrow_no, plane, &lambda, false)) {
+ madd_v3_v3v3fl(proj[j].location, arrow_co, arrow_no, lambda);
+ ok++;
+ }
+ }
+ }
+
+ if (ok != 2) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+
+ sub_v3_v3v3(offset, proj[1].location, proj[0].location);
+ facdir = dot_v3v3(arrow_no, offset) < 0.0f ? -1 : 1;
+
+ ManipulatorCommonData *data = &arrow->data;
+ const float ofs_new = facdir * len_v3(offset);
+
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+
+ /* set the property for the operator and call its modal function */
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ const int draw_options = RNA_enum_get(arrow->manipulator.ptr, "draw_options");
+ const bool constrained = (draw_options & ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED) != 0;
+ const bool inverted = (draw_options & ED_MANIPULATOR_ARROW_STYLE_INVERTED) != 0;
+ const bool use_precision = (tweak_flag & WM_MANIPULATOR_TWEAK_PRECISE) != 0;
+ float value = manipulator_value_from_offset(data, inter, ofs_new, constrained, inverted, use_precision);
+
+ WM_manipulator_target_property_value_set(C, mpr, mpr_prop, value);
+ /* get clamped value */
+ value = WM_manipulator_target_property_value_get(mpr, mpr_prop);
+
+ data->offset = manipulator_offset_from_value(data, value, constrained, inverted);
+ }
+ else {
+ data->offset = ofs_new;
+ }
+
+ /* tag the region for redraw */
+ ED_region_tag_redraw(ar);
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void manipulator_arrow_setup(wmManipulator *mpr)
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+
+ arrow->manipulator.flag |= WM_MANIPULATOR_DRAW_MODAL;
+
+ arrow->data.range_fac = 1.0f;
+}
+
+static int manipulator_arrow_invoke(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+ ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+
+ /* Some manipulators don't use properties. */
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ inter->init_value = WM_manipulator_target_property_value_get(mpr, mpr_prop);
+ }
+
+ inter->init_offset = arrow->data.offset;
+
+ inter->init_mval[0] = event->mval[0];
+ inter->init_mval[1] = event->mval[1];
+
+ manipulator_arrow_matrix_basis_get(mpr, inter->init_matrix_basis);
+ WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
+
+ mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void manipulator_arrow_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+ const int draw_options = RNA_enum_get(arrow->manipulator.ptr, "draw_options");
+ const bool constrained = (draw_options & ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED) != 0;
+ const bool inverted = (draw_options & ED_MANIPULATOR_ARROW_STYLE_INVERTED) != 0;
+ manipulator_property_data_update(mpr, &arrow->data, mpr_prop, constrained, inverted);
+}
+
+static void manipulator_arrow_exit(bContext *C, wmManipulator *mpr, const bool cancel)
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+ ManipulatorCommonData *data = &arrow->data;
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+ const bool is_prop_valid = WM_manipulator_target_property_is_valid(mpr_prop);
+
+ if (!cancel) {
+ /* Assign incase applying the opetration needs an updated offset
+ * editmesh bisect needs this. */
+ if (is_prop_valid) {
+ data->offset = WM_manipulator_target_property_value_get(mpr, mpr_prop);
+ }
+ return;
+ }
+
+ ManipulatorInteraction *inter = mpr->interaction_data;
+ if (is_prop_valid) {
+ manipulator_property_value_reset(C, mpr, inter, mpr_prop);
+ }
+ data->offset = inter->init_offset;
+}
+
+
+/* -------------------------------------------------------------------- */
+/** \name Arrow Manipulator API
+ *
+ * \{ */
+
+/**
+ * Define a custom property UI range
+ *
+ * \note Needs to be called before WM_manipulator_target_property_def_rna!
+ */
+void ED_manipulator_arrow3d_set_ui_range(wmManipulator *mpr, const float min, const float max)
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+
+ BLI_assert(min < max);
+ BLI_assert(!(WM_manipulator_target_property_is_valid(WM_manipulator_target_property_find(mpr, "offset")) &&
+ "Make sure this function is called before WM_manipulator_target_property_def_rna"));
+
+ arrow->data.range = max - min;
+ arrow->data.min = min;
+ arrow->data.flag |= MANIPULATOR_CUSTOM_RANGE_SET;
+}
+
+/**
+ * Define a custom factor for arrow min/max distance
+ *
+ * \note Needs to be called before WM_manipulator_target_property_def_rna!
+ */
+void ED_manipulator_arrow3d_set_range_fac(wmManipulator *mpr, const float range_fac)
+{
+ ArrowManipulator3D *arrow = (ArrowManipulator3D *)mpr;
+ BLI_assert(!(WM_manipulator_target_property_is_valid(WM_manipulator_target_property_find(mpr, "offset")) &&
+ "Make sure this function is called before WM_manipulator_target_property_def_rna"));
+
+ arrow->data.range_fac = range_fac;
+}
+
+static void MANIPULATOR_WT_arrow_3d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_arrow_3d";
+
+ /* api callbacks */
+ wt->draw = manipulator_arrow_draw;
+ wt->draw_select = manipulator_arrow_draw_select;
+ wt->matrix_basis_get = manipulator_arrow_matrix_basis_get;
+ wt->modal = manipulator_arrow_modal;
+ wt->setup = manipulator_arrow_setup;
+ wt->invoke = manipulator_arrow_invoke;
+ wt->property_update = manipulator_arrow_property_update;
+ wt->exit = manipulator_arrow_exit;
+
+ wt->struct_size = sizeof(ArrowManipulator3D);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_MANIPULATOR_ARROW_STYLE_NORMAL, "NORMAL", 0, "Normal", ""},
+ {ED_MANIPULATOR_ARROW_STYLE_CROSS, "CROSS", 0, "Cross", ""},
+ {ED_MANIPULATOR_ARROW_STYLE_BOX, "BOX", 0, "Box", ""},
+ {ED_MANIPULATOR_ARROW_STYLE_CONE, "CONE", 0, "Cone", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_MANIPULATOR_ARROW_STYLE_INVERTED, "INVERT", 0, "Inverted", ""},
+ {ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED, "CONSTRAIN", 0, "Constrained", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_ARROW_STYLE_NORMAL, "Draw Style", "");
+ RNA_def_enum_flag(wt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+
+ RNA_def_float(wt->srna, "length", 1.0f, 0.0f, FLT_MAX, "Arrow Line Length", "", 0.0f, FLT_MAX);
+ RNA_def_float_vector(wt->srna, "aspect", 2, NULL, 0, FLT_MAX, "Aspect", "Cone/box style only", 0.0f, FLT_MAX);
+
+ WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 1);
+}
+
+void ED_manipulatortypes_arrow_3d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_arrow_3d);
+}
+
+/** \} */
diff --git a/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
new file mode 100644
index 00000000000..68bddf36b3c
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/button2d_manipulator.c
@@ -0,0 +1,263 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file button2d_manipulator.c
+ * \ingroup wm
+ *
+ * \name Button Manipulator
+ *
+ * 2D Manipulator, also works in 3D views.
+ *
+ * \brief Single click button action for use in manipulator groups.
+ *
+ * \note Currently only basic icon & vector-shape buttons are supported.
+ *
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+#include "GPU_batch.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_interface.h"
+#include "UI_interface_icons.h"
+#include "UI_resources.h"
+
+/* own includes */
+#include "../manipulator_geometry.h"
+#include "../manipulator_library_intern.h"
+
+typedef struct ButtonManipulator2D {
+ wmManipulator manipulator;
+ bool is_init;
+ /* Use an icon or shape */
+ int icon;
+ Gwn_Batch *shape_batch[2];
+} ButtonManipulator2D;
+
+#define CIRCLE_RESOLUTION 32
+
+/* -------------------------------------------------------------------- */
+
+static void button2d_geom_draw_backdrop(
+ const wmManipulator *mpr, const float color[4], const bool select)
+{
+ glLineWidth(mpr->line_width);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ immUniformColor4fv(color);
+
+ /* TODO, other draw styles */
+ imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, CIRCLE_RESOLUTION);
+
+ immUnbindProgram();
+
+ UNUSED_VARS(select);
+}
+
+static void button2d_draw_intern(
+ const bContext *UNUSED(C), wmManipulator *mpr,
+ const bool select, const bool highlight)
+{
+ ButtonManipulator2D *button = (ButtonManipulator2D *)mpr;
+
+ if (button->is_init == false) {
+ button->is_init = true;
+ PropertyRNA *prop = RNA_struct_find_property(mpr->ptr, "icon");
+ if (RNA_property_is_set(mpr->ptr, prop)) {
+ button->icon = RNA_property_enum_get(mpr->ptr, prop);
+ }
+ else {
+ prop = RNA_struct_find_property(mpr->ptr, "shape");
+ const uint polys_len = RNA_property_string_length(mpr->ptr, prop);
+ /* We shouldn't need the +1, but a NULL char is set. */
+ char *polys = MEM_mallocN(polys_len + 1, __func__);
+ RNA_property_string_get(mpr->ptr, prop, polys);
+ button->shape_batch[0] = GPU_batch_wire_from_poly_2d_encoded((uchar *)polys, polys_len, NULL);
+ button->shape_batch[1] = GPU_batch_tris_from_poly_2d_encoded((uchar *)polys, polys_len, NULL);
+ MEM_freeN(polys);
+ }
+ }
+
+ float color[4];
+ float matrix_final[4][4];
+
+ manipulator_color_get(mpr, highlight, color);
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+
+ glEnable(GL_BLEND);
+
+ if (select == false) {
+ if (button->shape_batch[0] != NULL) {
+ glEnable(GL_LINE_SMOOTH);
+ glLineWidth(1.0f);
+ for (uint i = 0; i < ARRAY_SIZE(button->shape_batch) && button->shape_batch[i]; i++) {
+ /* Invert line color for wire. */
+ color[0] = 1.0f - color[0];
+ color[1] = 1.0f - color[1];
+ color[2] = 1.0f - color[2];
+
+ GWN_batch_program_set_builtin(button->shape_batch[i], GPU_SHADER_2D_UNIFORM_COLOR);
+ GWN_batch_uniform_4f(button->shape_batch[i], "color", UNPACK4(color));
+ GWN_batch_draw(button->shape_batch[i]);
+ }
+ glDisable(GL_LINE_SMOOTH);
+ gpuPopMatrix();
+ }
+ else if (button->icon != ICON_NONE) {
+ button2d_geom_draw_backdrop(mpr, color, select);
+ gpuPopMatrix();
+ UI_icon_draw(
+ mpr->matrix_basis[3][0] - (ICON_DEFAULT_WIDTH / 2.0) * UI_DPI_FAC,
+ mpr->matrix_basis[3][1] - (ICON_DEFAULT_HEIGHT / 2.0) * UI_DPI_FAC,
+ button->icon);
+ }
+ else {
+ gpuPopMatrix();
+ }
+ }
+ glDisable(GL_BLEND);
+}
+
+static void manipulator_button2d_draw_select(const bContext *C, wmManipulator *mpr, int select_id)
+{
+ GPU_select_load_id(select_id);
+ button2d_draw_intern(C, mpr, true, false);
+}
+
+static void manipulator_button2d_draw(const bContext *C, wmManipulator *mpr)
+{
+ const bool is_highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+
+ glEnable(GL_BLEND);
+ button2d_draw_intern(C, mpr, false, is_highlight);
+ glDisable(GL_BLEND);
+}
+
+static int manipulator_button2d_test_select(
+ bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+ float point_local[2];
+
+ if (0) {
+ /* correct, but unnecessarily slow. */
+ if (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, true, point_local) == false)
+ {
+ return -1;
+ }
+ }
+ else {
+ copy_v2_v2(point_local, (float [2]){UNPACK2(event->mval)});
+ sub_v2_v2(point_local, mpr->matrix_basis[3]);
+ mul_v2_fl(point_local, 1.0f / (mpr->scale_basis * UI_DPI_FAC));
+ }
+ /* The 'mpr->scale_final' is already applied when projecting. */
+ if (len_squared_v2(point_local) < 1.0f) {
+ return 0;
+ }
+
+ return -1;
+}
+
+static int manipulator_button2d_cursor_get(wmManipulator *mpr)
+{
+ if (RNA_boolean_get(mpr->ptr, "show_drag")) {
+ return BC_NSEW_SCROLLCURSOR;
+ }
+ return CURSOR_STD;
+}
+
+static void manipulator_button2d_free(wmManipulator *mpr)
+{
+ ButtonManipulator2D *shape = (ButtonManipulator2D *)mpr;
+
+ for (uint i = 0; i < ARRAY_SIZE(shape->shape_batch); i++) {
+ GWN_BATCH_DISCARD_SAFE(shape->shape_batch[i]);
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Button Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_button_2d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_button_2d";
+
+ /* api callbacks */
+ wt->draw = manipulator_button2d_draw;
+ wt->draw_select = manipulator_button2d_draw_select;
+ wt->test_select = manipulator_button2d_test_select;
+ wt->cursor_get = manipulator_button2d_cursor_get;
+ wt->free = manipulator_button2d_free;
+
+ wt->struct_size = sizeof(ButtonManipulator2D);
+
+ /* rna */
+ PropertyRNA *prop;
+ prop = RNA_def_property(wt->srna, "icon", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, rna_enum_icon_items);
+
+ /* Passed to 'GPU_batch_from_poly_2d_encoded' */
+ RNA_def_property(wt->srna, "shape", PROP_STRING, PROP_BYTESTRING);
+
+ /* Currently only used for cursor display. */
+ RNA_def_boolean(wt->srna, "show_drag", true, "Show Drag", "");
+}
+
+void ED_manipulatortypes_button_2d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_button_2d);
+}
+
+/** \} */ // Button Manipulator API
diff --git a/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
new file mode 100644
index 00000000000..00eff3654b9
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/cage2d_manipulator.c
@@ -0,0 +1,1109 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file cage2d_manipulator.c
+ * \ingroup wm
+ *
+ * \name Cage Manipulator
+ *
+ * 2D Manipulator
+ *
+ * \brief Rectangular manipulator acting as a 'cage' around its content.
+ * Interacting scales or translates the manipulator.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_dial_2d.h"
+#include "BLI_rect.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+
+#include "GPU_matrix.h"
+#include "GPU_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_select.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+/* own includes */
+#include "../manipulator_library_intern.h"
+
+#define MANIPULATOR_RESIZER_SIZE 10.0f
+#define MANIPULATOR_MARGIN_OFFSET_SCALE 1.5f
+
+static void manipulator_calc_matrix_final_no_offset(
+ const wmManipulator *mpr, float orig_matrix_final_no_offset[4][4])
+{
+ float mat_identity[4][4];
+ struct WM_ManipulatorMatrixParams params = {NULL};
+ unit_m4(mat_identity);
+ params.matrix_offset = mat_identity;
+ WM_manipulator_calc_matrix_final_params(mpr, &params, orig_matrix_final_no_offset);
+}
+
+static void manipulator_calc_rect_view_scale(
+ const wmManipulator *mpr, const float dims[2], float scale[2])
+{
+ float matrix_final_no_offset[4][4];
+ float asp[2] = {1.0f, 1.0f};
+ if (dims[0] > dims[1]) {
+ asp[0] = dims[1] / dims[0];
+ }
+ else {
+ asp[1] = dims[0] / dims[1];
+ }
+ float x_axis[3], y_axis[3];
+ manipulator_calc_matrix_final_no_offset(mpr, matrix_final_no_offset);
+ mul_v3_mat3_m4v3(x_axis, matrix_final_no_offset, mpr->matrix_offset[0]);
+ mul_v3_mat3_m4v3(y_axis, matrix_final_no_offset, mpr->matrix_offset[1]);
+
+ mul_v2_v2(x_axis, asp);
+ mul_v2_v2(y_axis, asp);
+
+ scale[0] = 1.0f / len_v3(x_axis);
+ scale[1] = 1.0f / len_v3(y_axis);
+}
+
+static void manipulator_calc_rect_view_margin(
+ const wmManipulator *mpr, const float dims[2], float margin[2])
+{
+ float handle_size;
+ if (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) {
+ handle_size = 0.15f;
+ }
+ else {
+ handle_size = MANIPULATOR_RESIZER_SIZE;
+ }
+ handle_size *= mpr->scale_final;
+ float scale_xy[2];
+ manipulator_calc_rect_view_scale(mpr, dims, scale_xy);
+ margin[0] = ((handle_size * scale_xy[0]));
+ margin[1] = ((handle_size * scale_xy[1]));
+}
+
+/* -------------------------------------------------------------------- */
+
+static void manipulator_rect_pivot_from_scale_part(int part, float r_pt[2], bool r_constrain_axis[2])
+{
+ bool x = true, y = true;
+ switch (part) {
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X: { ARRAY_SET_ITEMS(r_pt, 0.5, 0.0); x = false; break; }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X: { ARRAY_SET_ITEMS(r_pt, -0.5, 0.0); x = false; break; }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y: { ARRAY_SET_ITEMS(r_pt, 0.0, 0.5); y = false; break; }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y: { ARRAY_SET_ITEMS(r_pt, 0.0, -0.5); y = false; break; }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y: { ARRAY_SET_ITEMS(r_pt, 0.5, 0.5); x = y = false; break; }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y: { ARRAY_SET_ITEMS(r_pt, 0.5, -0.5); x = y = false; break; }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y: { ARRAY_SET_ITEMS(r_pt, -0.5, 0.5); x = y = false; break; }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y: { ARRAY_SET_ITEMS(r_pt, -0.5, -0.5); x = y = false; break; }
+ default: BLI_assert(0);
+ }
+ r_constrain_axis[0] = x;
+ r_constrain_axis[1] = y;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Box Draw Style
+ *
+ * Useful for 3D views, see: #ED_MANIPULATOR_CAGE2D_STYLE_BOX
+ * \{ */
+
+static void cage2d_draw_box_corners(
+ const rctf *r, const float margin[2], const float color[3])
+{
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ immBegin(GWN_PRIM_LINES, 16);
+
+ immVertex2f(pos, r->xmin, r->ymin + margin[1]);
+ immVertex2f(pos, r->xmin, r->ymin);
+ immVertex2f(pos, r->xmin, r->ymin);
+ immVertex2f(pos, r->xmin + margin[0], r->ymin);
+
+ immVertex2f(pos, r->xmax, r->ymin + margin[1]);
+ immVertex2f(pos, r->xmax, r->ymin);
+ immVertex2f(pos, r->xmax, r->ymin);
+ immVertex2f(pos, r->xmax - margin[0], r->ymin);
+
+ immVertex2f(pos, r->xmax, r->ymax - margin[1]);
+ immVertex2f(pos, r->xmax, r->ymax);
+ immVertex2f(pos, r->xmax, r->ymax);
+ immVertex2f(pos, r->xmax - margin[0], r->ymax);
+
+ immVertex2f(pos, r->xmin, r->ymax - margin[1]);
+ immVertex2f(pos, r->xmin, r->ymax);
+ immVertex2f(pos, r->xmin, r->ymax);
+ immVertex2f(pos, r->xmin + margin[0], r->ymax);
+
+ immEnd();
+
+ immUnbindProgram();
+}
+
+static void cage2d_draw_box_interaction(
+ const float color[4], const int highlighted,
+ const float size[2], const float margin[2],
+ const float line_width, const bool is_solid, const int draw_options)
+{
+ /* 4 verts for translate, otherwise only 3 are used. */
+ float verts[4][2];
+ uint verts_len = 0;
+ Gwn_PrimType prim_type = GWN_PRIM_NONE;
+
+ switch (highlighted) {
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X:
+ {
+ rctf r = {
+ .xmin = -size[0], .xmax = -size[0] + margin[0],
+ .ymin = -size[1] + margin[1], .ymax = size[1] - margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
+ verts_len += 2;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X:
+ {
+ rctf r = {
+ .xmin = size[0] - margin[0], .xmax = size[0],
+ .ymin = -size[1] + margin[1], .ymax = size[1] - margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
+ verts_len += 2;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y:
+ {
+ rctf r = {
+ .xmin = -size[0] + margin[0], .xmax = size[0] - margin[0],
+ .ymin = -size[1], .ymax = -size[1] + margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
+ verts_len += 2;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y:
+ {
+ rctf r = {
+ .xmin = -size[0] + margin[0], .xmax = size[0] - margin[0],
+ .ymin = size[1] - margin[1], .ymax = size[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
+ verts_len = 2;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
+ verts_len += 2;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y:
+ {
+ rctf r = {
+ .xmin = -size[0], .xmax = -size[0] + margin[0],
+ .ymin = -size[1], .ymax = -size[1] + margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymax);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymin);
+ verts_len += 1;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y:
+ {
+ rctf r = {
+ .xmin = -size[0], .xmax = -size[0] + margin[0],
+ .ymin = size[1] - margin[1], .ymax = size[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmax, r.ymax);
+ ARRAY_SET_ITEMS(verts[1], r.xmax, r.ymin);
+ ARRAY_SET_ITEMS(verts[2], r.xmin, r.ymin);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmin, r.ymax);
+ verts_len += 1;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y:
+ {
+ rctf r = {
+ .xmin = size[0] - margin[0], .xmax = size[0],
+ .ymin = -size[1], .ymax = -size[1] + margin[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymax);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymin);
+ verts_len += 1;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y:
+ {
+ rctf r = {
+ .xmin = size[0] - margin[0], .xmax = size[0],
+ .ymin = size[1] - margin[1], .ymax = size[1],
+ };
+ ARRAY_SET_ITEMS(verts[0], r.xmin, r.ymax);
+ ARRAY_SET_ITEMS(verts[1], r.xmin, r.ymin);
+ ARRAY_SET_ITEMS(verts[2], r.xmax, r.ymin);
+ verts_len = 3;
+ if (is_solid) {
+ ARRAY_SET_ITEMS(verts[3], r.xmax, r.ymax);
+ verts_len += 1;
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+ case ED_MANIPULATOR_CAGE2D_PART_ROTATE:
+ {
+ const float rotate_pt[2] = {0.0f, size[1] + margin[1]};
+ const rctf r_rotate = {
+ .xmin = rotate_pt[0] - margin[0] / 2.0f,
+ .xmax = rotate_pt[0] + margin[0] / 2.0f,
+ .ymin = rotate_pt[1] - margin[1] / 2.0f,
+ .ymax = rotate_pt[1] + margin[1] / 2.0f,
+ };
+
+ ARRAY_SET_ITEMS(verts[0], r_rotate.xmin, r_rotate.ymin);
+ ARRAY_SET_ITEMS(verts[1], r_rotate.xmin, r_rotate.ymax);
+ ARRAY_SET_ITEMS(verts[2], r_rotate.xmax, r_rotate.ymax);
+ ARRAY_SET_ITEMS(verts[3], r_rotate.xmax, r_rotate.ymin);
+ verts_len = 4;
+ if (is_solid) {
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ break;
+ }
+
+ case ED_MANIPULATOR_CAGE2D_PART_TRANSLATE:
+ if (draw_options & ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ ARRAY_SET_ITEMS(verts[0], -margin[0] / 2, -margin[1] / 2);
+ ARRAY_SET_ITEMS(verts[1], margin[0] / 2, margin[1] / 2);
+ ARRAY_SET_ITEMS(verts[2], -margin[0] / 2, margin[1] / 2);
+ ARRAY_SET_ITEMS(verts[3], margin[0] / 2, -margin[1] / 2);
+ verts_len = 4;
+ if (is_solid) {
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ prim_type = GWN_PRIM_LINES;
+ }
+ }
+ else {
+ /* Only used for 3D view selection, never displayed to the user. */
+ ARRAY_SET_ITEMS(verts[0], -size[0], -size[1]);
+ ARRAY_SET_ITEMS(verts[1], -size[0], size[1]);
+ ARRAY_SET_ITEMS(verts[2], size[0], size[1]);
+ ARRAY_SET_ITEMS(verts[3], size[0], -size[1]);
+ verts_len = 4;
+ if (is_solid) {
+ prim_type = GWN_PRIM_TRI_FAN;
+ }
+ else {
+ /* unreachable */
+ BLI_assert(0);
+ prim_type = GWN_PRIM_LINE_STRIP;
+ }
+ }
+ break;
+ default:
+ return;
+ }
+
+ BLI_assert(prim_type != GWN_PRIM_NONE);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ struct {
+ uint pos, col;
+ } attr_id = {
+ .pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT),
+ .col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT),
+ };
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ {
+ if (is_solid) {
+ BLI_assert(ELEM(prim_type, GWN_PRIM_TRI_FAN));
+ immBegin(prim_type, verts_len);
+ immAttrib3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+ for (uint i = 0; i < verts_len; i++) {
+ immVertex2fv(attr_id.pos, verts[i]);
+ }
+ immEnd();
+ }
+ else {
+ BLI_assert(ELEM(prim_type, GWN_PRIM_LINE_STRIP, GWN_PRIM_LINES));
+ glLineWidth(line_width + 3.0f);
+
+ immBegin(prim_type, verts_len);
+ immAttrib3f(attr_id.col, 0.0f, 0.0f, 0.0f);
+ for (uint i = 0; i < verts_len; i++) {
+ immVertex2fv(attr_id.pos, verts[i]);
+ }
+ immEnd();
+
+ glLineWidth(line_width);
+
+ immBegin(prim_type, verts_len);
+ immAttrib3fv(attr_id.col, color);
+ for (uint i = 0; i < verts_len; i++) {
+ immVertex2fv(attr_id.pos, verts[i]);
+ }
+ immEnd();
+ }
+ }
+
+ immUnbindProgram();
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Circle Draw Style
+ *
+ * Useful for 2D views, see: #ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE
+ * \{ */
+
+static void imm_draw_point_aspect_2d(
+ uint pos, float x, float y, float rad_x, float rad_y, bool solid)
+{
+ immBegin(solid ? GWN_PRIM_TRI_FAN : GWN_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, x - rad_x, y - rad_y);
+ immVertex2f(pos, x - rad_x, y + rad_y);
+ immVertex2f(pos, x + rad_x, y + rad_y);
+ immVertex2f(pos, x + rad_x, y - rad_y);
+ immEnd();
+}
+
+static void cage2d_draw_circle_wire(
+ const rctf *r, const float margin[2], const float color[3],
+ const int transform_flag, const int draw_options)
+{
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, r->xmin, r->ymin);
+ immVertex2f(pos, r->xmax, r->ymin);
+ immVertex2f(pos, r->xmax, r->ymax);
+ immVertex2f(pos, r->xmin, r->ymax);
+ immEnd();
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE) {
+ immBegin(GWN_PRIM_LINE_LOOP, 2);
+ immVertex2f(pos, BLI_rctf_cent_x(r), r->ymax);
+ immVertex2f(pos, BLI_rctf_cent_x(r), r->ymax + margin[1]);
+ immEnd();
+ }
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ if (draw_options & ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ const float rad[2] = {margin[0] / 2, margin[1] / 2};
+ const float center[2] = {BLI_rctf_cent_x(r), BLI_rctf_cent_y(r)};
+
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, center[0] - rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] + rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] - rad[0], center[1] + rad[1]);
+ immEnd();
+ }
+ }
+
+ immUnbindProgram();
+}
+
+static void cage2d_draw_circle_handles(
+ const rctf *r, const float margin[2], const float color[3],
+ const int transform_flag,
+ bool solid)
+{
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ void (*circle_fn)(uint, float, float, float, float, int) =
+ (solid) ? imm_draw_circle_fill_aspect_2d : imm_draw_circle_wire_aspect_2d;
+ const int resolu = 12;
+ const float rad[2] = {margin[0] / 3, margin[1] / 3};
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ /* should really divide by two, but looks too bulky. */
+ {
+ imm_draw_point_aspect_2d(pos, r->xmin, r->ymin, rad[0], rad[1], solid);
+ imm_draw_point_aspect_2d(pos, r->xmax, r->ymin, rad[0], rad[1], solid);
+ imm_draw_point_aspect_2d(pos, r->xmax, r->ymax, rad[0], rad[1], solid);
+ imm_draw_point_aspect_2d(pos, r->xmin, r->ymax, rad[0], rad[1], solid);
+ }
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE) {
+ const float handle[2] = {BLI_rctf_cent_x(r), r->ymax + (margin[1] * MANIPULATOR_MARGIN_OFFSET_SCALE)};
+ circle_fn(pos, handle[0], handle[1], rad[0], rad[1], resolu);
+ }
+
+ immUnbindProgram();
+}
+
+/** \} */
+
+static void manipulator_cage2d_draw_intern(
+ wmManipulator *mpr, const bool select, const bool highlight, const int select_id)
+{
+ // const bool use_clamp = (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) == 0;
+ float dims[2];
+ RNA_float_get_array(mpr->ptr, "dimensions", dims);
+ float matrix_final[4][4];
+
+ const int transform_flag = RNA_enum_get(mpr->ptr, "transform");
+ const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+
+ const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
+
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+
+ float margin[2];
+ manipulator_calc_rect_view_margin(mpr, dims, margin);
+
+ /* Handy for quick testing draw (if it's outside bounds). */
+ if (false) {
+ glEnable(GL_BLEND);
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv((const float[4]){1, 1, 1, 0.5f});
+ float s = 0.5f;
+ immRectf(pos, -s, -s, s, s);
+ immUnbindProgram();
+ glDisable(GL_BLEND);
+ }
+
+ if (select) {
+ /* expand for hotspot */
+ const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE) {
+ int scale_parts[] = {
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y,
+
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y,
+ ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y,
+ };
+ for (int i = 0; i < ARRAY_SIZE(scale_parts); i++) {
+ GPU_select_load_id(select_id | scale_parts[i]);
+ cage2d_draw_box_interaction(
+ mpr->color, scale_parts[i], size, margin, mpr->line_width, true, draw_options);
+ }
+ }
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ const int transform_part = ED_MANIPULATOR_CAGE2D_PART_TRANSLATE;
+ GPU_select_load_id(select_id | transform_part);
+ cage2d_draw_box_interaction(
+ mpr->color, transform_part, size, margin, mpr->line_width, true, draw_options);
+ }
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE) {
+ cage2d_draw_box_interaction(
+ mpr->color, ED_MANIPULATOR_CAGE2D_PART_ROTATE, size_real, margin, mpr->line_width, true, draw_options);
+ }
+ }
+ else {
+ const rctf r = {
+ .xmin = -size_real[0],
+ .ymin = -size_real[1],
+ .xmax = size_real[0],
+ .ymax = size_real[1],
+ };
+ if (draw_style == ED_MANIPULATOR_CAGE2D_STYLE_BOX) {
+ /* corner manipulators */
+ glLineWidth(mpr->line_width + 3.0f);
+ cage2d_draw_box_corners(&r, margin, (const float[3]){0, 0, 0});
+
+ /* corner manipulators */
+ float color[4];
+ manipulator_color_get(mpr, highlight, color);
+ glLineWidth(mpr->line_width);
+ cage2d_draw_box_corners(&r, margin, color);
+
+ bool show = false;
+ if (mpr->highlight_part == ED_MANIPULATOR_CAGE2D_PART_TRANSLATE) {
+ /* Only show if we're drawing the center handle
+ * otherwise the entire rectangle is the hotspot. */
+ if (draw_options & ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ show = true;
+ }
+ }
+ else {
+ show = true;
+ }
+
+ if (show) {
+ cage2d_draw_box_interaction(
+ mpr->color, mpr->highlight_part, size_real, margin, mpr->line_width, false, draw_options);
+ }
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE) {
+ cage2d_draw_box_interaction(
+ mpr->color, ED_MANIPULATOR_CAGE2D_PART_ROTATE, size_real, margin, mpr->line_width, false, draw_options);
+ }
+ }
+ else if (draw_style == ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE) {
+ float color[4];
+ manipulator_color_get(mpr, highlight, color);
+
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_BLEND);
+
+ glLineWidth(mpr->line_width + 3.0f);
+ cage2d_draw_circle_wire(&r, margin, (const float[3]){0, 0, 0}, transform_flag, draw_options);
+ glLineWidth(mpr->line_width);
+ cage2d_draw_circle_wire(&r, margin, color, transform_flag, draw_options);
+
+
+ /* corner manipulators */
+ cage2d_draw_circle_handles(&r, margin, color, transform_flag, true);
+ cage2d_draw_circle_handles(&r, margin, (const float[3]){0, 0, 0}, transform_flag, false);
+
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ glLineWidth(1.0);
+ gpuPopMatrix();
+}
+
+/**
+ * For when we want to draw 2d cage in 3d views.
+ */
+static void manipulator_cage2d_draw_select(const bContext *UNUSED(C), wmManipulator *mpr, int select_id)
+{
+ manipulator_cage2d_draw_intern(mpr, true, false, select_id);
+}
+
+static void manipulator_cage2d_draw(const bContext *UNUSED(C), wmManipulator *mpr)
+{
+ const bool is_highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+ manipulator_cage2d_draw_intern(mpr, false, is_highlight, -1);
+}
+
+static int manipulator_cage2d_get_cursor(wmManipulator *mpr)
+{
+ int highlight_part = mpr->highlight_part;
+
+ if (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) {
+ return BC_NSEW_SCROLLCURSOR;
+ }
+
+ switch (highlight_part) {
+ case ED_MANIPULATOR_CAGE2D_PART_TRANSLATE:
+ return BC_NSEW_SCROLLCURSOR;
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X:
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X:
+ return CURSOR_X_MOVE;
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y:
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y:
+ return CURSOR_Y_MOVE;
+
+ /* TODO diagonal cursor */
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y:
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y:
+ return BC_NSEW_SCROLLCURSOR;
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y:
+ case ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y:
+ return BC_NSEW_SCROLLCURSOR;
+ case ED_MANIPULATOR_CAGE2D_PART_ROTATE:
+ return BC_CROSSCURSOR;
+ default:
+ return CURSOR_STD;
+ }
+}
+
+static int manipulator_cage2d_test_select(
+ bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+ float point_local[2];
+ float dims[2];
+ RNA_float_get_array(mpr->ptr, "dimensions", dims);
+ const float size_real[2] = {dims[0] / 2.0f, dims[1] / 2.0f};
+
+ if (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, true, point_local) == false)
+ {
+ return -1;
+ }
+
+ float margin[2];
+ manipulator_calc_rect_view_margin(mpr, dims, margin);
+ /* expand for hotspot */
+ const float size[2] = {size_real[0] + margin[0] / 2, size_real[1] + margin[1] / 2};
+
+ const int transform_flag = RNA_enum_get(mpr->ptr, "transform");
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ rctf r;
+ if (draw_options & ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ r.xmin = -margin[0] / 2;
+ r.ymin = -margin[1] / 2;
+ r.xmax = margin[0] / 2;
+ r.ymax = margin[1] / 2;
+ }
+ else {
+ r.xmin = -size[0] + margin[0];
+ r.ymin = -size[1] + margin[1];
+ r.xmax = size[0] - margin[0];
+ r.ymax = size[1] - margin[1];
+ };
+ bool isect = BLI_rctf_isect_pt_v(&r, point_local);
+ if (isect) {
+ return ED_MANIPULATOR_CAGE2D_PART_TRANSLATE;
+ }
+ }
+
+ /* if manipulator does not have a scale intersection, don't do it */
+ if (transform_flag & (ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE | ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM)) {
+ const rctf r_xmin = {.xmin = -size[0], .ymin = -size[1], .xmax = -size[0] + margin[0], .ymax = size[1]};
+ const rctf r_xmax = {.xmin = size[0] - margin[0], .ymin = -size[1], .xmax = size[0], .ymax = size[1]};
+ const rctf r_ymin = {.xmin = -size[0], .ymin = -size[1], .xmax = size[0], .ymax = -size[1] + margin[1]};
+ const rctf r_ymax = {.xmin = -size[0], .ymin = size[1] - margin[1], .xmax = size[0], .ymax = size[1]};
+
+ if (BLI_rctf_isect_pt_v(&r_xmin, point_local)) {
+ if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y;
+ }
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X;
+ }
+ if (BLI_rctf_isect_pt_v(&r_xmax, point_local)) {
+ if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y;
+ }
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymin, point_local)) {
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y;
+ }
+ if (BLI_rctf_isect_pt_v(&r_ymax, point_local)) {
+ return ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y;
+ }
+ }
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE) {
+ /* Rotate:
+ * (*) <-- hot spot is here!
+ * +---+
+ * | |
+ * +---+ */
+ const float r_rotate_pt[2] = {0.0f, size_real[1] + (margin[1] * MANIPULATOR_MARGIN_OFFSET_SCALE)};
+ const rctf r_rotate = {
+ .xmin = r_rotate_pt[0] - margin[0] / 2.0f,
+ .xmax = r_rotate_pt[0] + margin[0] / 2.0f,
+ .ymin = r_rotate_pt[1] - margin[1] / 2.0f,
+ .ymax = r_rotate_pt[1] + margin[1] / 2.0f,
+ };
+
+ if (BLI_rctf_isect_pt_v(&r_rotate, point_local)) {
+ return ED_MANIPULATOR_CAGE2D_PART_ROTATE;
+ }
+ }
+
+ return -1;
+}
+
+typedef struct RectTransformInteraction {
+ float orig_mouse[2];
+ float orig_matrix_offset[4][4];
+ float orig_matrix_final_no_offset[4][4];
+ Dial *dial;
+} RectTransformInteraction;
+
+static void manipulator_cage2d_setup(wmManipulator *mpr)
+{
+ mpr->flag |= WM_MANIPULATOR_DRAW_MODAL | WM_MANIPULATOR_DRAW_NO_SCALE;
+}
+
+static int manipulator_cage2d_invoke(
+ bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+ RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction), "cage_interaction");
+
+ copy_m4_m4(data->orig_matrix_offset, mpr->matrix_offset);
+ manipulator_calc_matrix_final_no_offset(mpr, data->orig_matrix_final_no_offset);
+
+ if (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, data->orig_mouse) == 0)
+ {
+ zero_v2(data->orig_mouse);
+ }
+
+ mpr->interaction_data = data;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int manipulator_cage2d_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak UNUSED(tweak_flag))
+{
+ /* For transform logic to be managable we operate in -0.5..0.5 2D space,
+ * no matter the size of the rectangle, mouse coorts are scaled to unit space.
+ * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment.
+ *
+ * - The cursor offset are multiplied by 'dims'.
+ * - Matrix translation is also multiplied by 'dims'.
+ */
+ RectTransformInteraction *data = mpr->interaction_data;
+ float point_local[2];
+
+ float dims[2];
+ RNA_float_get_array(mpr->ptr, "dimensions", dims);
+
+ {
+ float matrix_back[4][4];
+ copy_m4_m4(matrix_back, mpr->matrix_offset);
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+
+ bool ok = manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, point_local);
+ copy_m4_m4(mpr->matrix_offset, matrix_back);
+ if (!ok) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ }
+
+ const int transform_flag = RNA_enum_get(mpr->ptr, "transform");
+ wmManipulatorProperty *mpr_prop;
+
+ mpr_prop = WM_manipulator_target_property_find(mpr, "matrix");
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, &mpr->matrix_offset[0][0]);
+ }
+
+ if (mpr->highlight_part == ED_MANIPULATOR_CAGE2D_PART_TRANSLATE) {
+ /* do this to prevent clamping from changing size */
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+ mpr->matrix_offset[3][0] = data->orig_matrix_offset[3][0] + (point_local[0] - data->orig_mouse[0]);
+ mpr->matrix_offset[3][1] = data->orig_matrix_offset[3][1] + (point_local[1] - data->orig_mouse[1]);
+ }
+ else if (mpr->highlight_part == ED_MANIPULATOR_CAGE2D_PART_ROTATE) {
+
+#define MUL_V2_V3_M4_FINAL(test_co, mouse_co) \
+ mul_v3_m4v3(test_co, data->orig_matrix_final_no_offset, ((const float[3]){UNPACK2(mouse_co), 0.0}))
+
+ float test_co[3];
+
+ if (data->dial == NULL) {
+ MUL_V2_V3_M4_FINAL(test_co, data->orig_matrix_offset[3]);
+
+ data->dial = BLI_dial_initialize(test_co, FLT_EPSILON);
+
+ MUL_V2_V3_M4_FINAL(test_co, data->orig_mouse);
+ BLI_dial_angle(data->dial, test_co);
+ }
+
+ /* rotate */
+ MUL_V2_V3_M4_FINAL(test_co, point_local);
+ const float angle = BLI_dial_angle(data->dial, test_co);
+
+ float matrix_space_inv[4][4];
+ float matrix_rotate[4][4];
+ float pivot[3];
+
+ copy_v3_v3(pivot, data->orig_matrix_offset[3]);
+
+ invert_m4_m4(matrix_space_inv, mpr->matrix_space);
+
+ unit_m4(matrix_rotate);
+ mul_m4_m4m4(matrix_rotate, matrix_rotate, matrix_space_inv);
+ rotate_m4(matrix_rotate, 'Z', -angle);
+ mul_m4_m4m4(matrix_rotate, matrix_rotate, mpr->matrix_space);
+
+ zero_v3(matrix_rotate[3]);
+ transform_pivot_set_m4(matrix_rotate, pivot);
+
+ mul_m4_m4m4(mpr->matrix_offset, matrix_rotate, data->orig_matrix_offset);
+
+#undef MUL_V2_V3_M4_FINAL
+ }
+ else {
+ /* scale */
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+ float pivot[2];
+ bool constrain_axis[2] = {false};
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ manipulator_rect_pivot_from_scale_part(mpr->highlight_part, pivot, constrain_axis);
+ }
+ else {
+ zero_v2(pivot);
+ }
+
+ /* Cursor deltas scaled to (-0.5..0.5). */
+ float delta_orig[2], delta_curr[2];
+ for (int i = 0; i < 2; i++) {
+ delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
+ delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
+ }
+
+ float scale[2] = {1.0f, 1.0f};
+ for (int i = 0; i < 2; i++) {
+ if (constrain_axis[i] == false) {
+ if (delta_orig[i] < 0.0f) {
+ delta_orig[i] *= -1.0f;
+ delta_curr[i] *= -1.0f;
+ }
+ const int sign = signum_i(scale[i]);
+
+ scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
+
+ if ((transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_SIGNED) == 0) {
+ if (sign != signum_i(scale[i])) {
+ scale[i] = 0.0f;
+ }
+ }
+ }
+ }
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM) {
+ if (constrain_axis[0] == false && constrain_axis[1] == false) {
+ scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
+ }
+ else if (constrain_axis[0] == false) {
+ scale[1] = scale[0];
+ }
+ else if (constrain_axis[1] == false) {
+ scale[0] = scale[1];
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ /* scale around pivot */
+ float matrix_scale[4][4];
+ unit_m4(matrix_scale);
+
+ mul_v3_fl(matrix_scale[0], scale[0]);
+ mul_v3_fl(matrix_scale[1], scale[1]);
+
+ transform_pivot_set_m4(matrix_scale, (const float [3]){pivot[0] * dims[0], pivot[1] * dims[1], 0.0f});
+ mul_m4_m4m4(mpr->matrix_offset, data->orig_matrix_offset, matrix_scale);
+ }
+
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, &mpr->matrix_offset[0][0]);
+ }
+
+ /* tag the region for redraw */
+ ED_region_tag_redraw(CTX_wm_region(C));
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void manipulator_cage2d_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
+{
+ if (STREQ(mpr_prop->type->idname, "matrix")) {
+ if (WM_manipulator_target_property_array_length(mpr, mpr_prop) == 16) {
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, &mpr->matrix_offset[0][0]);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ BLI_assert(0);
+ }
+}
+
+static void manipulator_cage2d_exit(bContext *C, wmManipulator *mpr, const bool cancel)
+{
+ RectTransformInteraction *data = mpr->interaction_data;
+
+ MEM_SAFE_FREE(data->dial);
+
+ if (!cancel)
+ return;
+
+ wmManipulatorProperty *mpr_prop;
+
+ /* reset properties */
+ mpr_prop = WM_manipulator_target_property_find(mpr, "matrix");
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, &data->orig_matrix_offset[0][0]);
+ }
+
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+}
+
+
+/* -------------------------------------------------------------------- */
+/** \name Cage Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_cage_2d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_cage_2d";
+
+ /* api callbacks */
+ wt->draw = manipulator_cage2d_draw;
+ wt->draw_select = manipulator_cage2d_draw_select;
+ wt->test_select = manipulator_cage2d_test_select;
+ wt->setup = manipulator_cage2d_setup;
+ wt->invoke = manipulator_cage2d_invoke;
+ wt->property_update = manipulator_cage2d_property_update;
+ wt->modal = manipulator_cage2d_modal;
+ wt->exit = manipulator_cage2d_exit;
+ wt->cursor_get = manipulator_cage2d_get_cursor;
+
+ wt->struct_size = sizeof(wmManipulator);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_MANIPULATOR_CAGE2D_STYLE_BOX, "BOX", 0, "Box", ""},
+ {ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE, "CIRCLE", 0, "Circle", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static EnumPropertyItem rna_enum_transform[] = {
+ {ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
+ {ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE, "ROTATE", 0, "Rotate", ""},
+ {ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE, "SCALE", 0, "Scale", ""},
+ {ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM, "SCALE_UNIFORM", 0, "Scale Uniform", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "XFORM_CENTER_HANDLE", 0, "Center Handle", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static float unit_v2[2] = {1.0f, 1.0f};
+ RNA_def_float_vector(wt->srna, "dimensions", 2, unit_v2, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
+ RNA_def_enum_flag(wt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
+ RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE, "Draw Style", "");
+ RNA_def_enum_flag(
+ wt->srna, "draw_options", rna_enum_draw_options,
+ ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "Draw Options", "");
+
+ WM_manipulatortype_target_property_def(wt, "matrix", PROP_FLOAT, 16);
+}
+
+void ED_manipulatortypes_cage_2d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_cage_2d);
+}
+
+/** \} */
diff --git a/source/blender/editors/manipulator_library/manipulator_types/cage3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/cage3d_manipulator.c
new file mode 100644
index 00000000000..67fb2419931
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/cage3d_manipulator.c
@@ -0,0 +1,735 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file cage3d_manipulator.c
+ * \ingroup wm
+ *
+ * \name Cage Manipulator
+ *
+ * 2D Manipulator
+ *
+ * \brief Rectangular manipulator acting as a 'cage' around its content.
+ * Interacting scales or translates the manipulator.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_dial_2d.h"
+#include "BLI_rect.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+
+#include "GPU_matrix.h"
+#include "GPU_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_select.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+/* own includes */
+#include "../manipulator_library_intern.h"
+
+#define MANIPULATOR_RESIZER_SIZE 10.0f
+#define MANIPULATOR_MARGIN_OFFSET_SCALE 1.5f
+
+static void manipulator_calc_matrix_final_no_offset(
+ const wmManipulator *mpr, float orig_matrix_final_no_offset[4][4], bool use_space)
+{
+ float mat_identity[4][4];
+ struct WM_ManipulatorMatrixParams params = {NULL};
+ unit_m4(mat_identity);
+ if (use_space == false) {
+ params.matrix_basis = mat_identity;
+ }
+ params.matrix_offset = mat_identity;
+ WM_manipulator_calc_matrix_final_params(mpr, &params, orig_matrix_final_no_offset);
+}
+
+static void manipulator_calc_rect_view_scale(
+ const wmManipulator *mpr, const float dims[3], float scale[3])
+{
+ UNUSED_VARS(dims);
+
+ /* Unlike cage2d, no need to correct for aspect. */
+ float matrix_final_no_offset[4][4];
+
+ float x_axis[3], y_axis[3], z_axis[3];
+ manipulator_calc_matrix_final_no_offset(mpr, matrix_final_no_offset, false);
+ mul_v3_mat3_m4v3(x_axis, matrix_final_no_offset, mpr->matrix_offset[0]);
+ mul_v3_mat3_m4v3(y_axis, matrix_final_no_offset, mpr->matrix_offset[1]);
+ mul_v3_mat3_m4v3(z_axis, matrix_final_no_offset, mpr->matrix_offset[2]);
+
+ scale[0] = 1.0f / len_v3(x_axis);
+ scale[1] = 1.0f / len_v3(y_axis);
+ scale[2] = 1.0f / len_v3(z_axis);
+}
+
+static void manipulator_calc_rect_view_margin(
+ const wmManipulator *mpr, const float dims[3], float margin[3])
+{
+ float handle_size;
+ if (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) {
+ handle_size = 0.15f;
+ }
+ else {
+ handle_size = MANIPULATOR_RESIZER_SIZE;
+ }
+ // XXX, the scale isn't taking offset into account, we need to calculate scale per handle!
+ // handle_size *= mpr->scale_final;
+
+ float scale_xyz[3];
+ manipulator_calc_rect_view_scale(mpr, dims, scale_xyz);
+ margin[0] = ((handle_size * scale_xyz[0]));
+ margin[1] = ((handle_size * scale_xyz[1]));
+ margin[2] = ((handle_size * scale_xyz[2]));
+}
+
+/* -------------------------------------------------------------------- */
+
+static void manipulator_rect_pivot_from_scale_part(int part, float r_pt[3], bool r_constrain_axis[3])
+{
+ if (part >= ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z &&
+ part <= ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z)
+ {
+ int index = (part - ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z);
+ int range[3];
+ range[2] = index % 3;
+ index = index / 3;
+ range[1] = index % 3;
+ index = index / 3;
+ range[0] = index % 3;
+
+ const float sign[3] = {-0.5f, 0.0f, 0.5f};
+ for (int i = 0; i < 3; i++) {
+ r_pt[i] = 0.5 * sign[range[i]];
+ r_constrain_axis[i] = (range[i] == 1);
+ }
+ }
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Box Draw Style
+ *
+ * Useful for 3D views, see: #ED_MANIPULATOR_CAGE2D_STYLE_BOX
+ * \{ */
+
+static void cage3d_draw_box_corners(
+ const float r[3], const float margin[3], const float color[3])
+{
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ UNUSED_VARS(margin);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
+
+ immUnbindProgram();
+}
+
+static void cage3d_draw_box_interaction(
+ const float color[4], const int highlighted,
+ const float size[3], const float margin[3])
+{
+ if (highlighted >= ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z &&
+ highlighted <= ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z)
+ {
+ int index = (highlighted - ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z);
+ int range[3];
+ range[2] = index % 3;
+ index = index / 3;
+ range[1] = index % 3;
+ index = index / 3;
+ range[0] = index % 3;
+
+ const float sign[3] = {-1.0f, 0.0f, 1.0f};
+ float co[3];
+
+ for (int i = 0; i < 3; i++) {
+ co[i] = size[i] * sign[range[i]];
+ }
+ const float rad[3] = {margin[0] / 3, margin[1] / 3, margin[2] / 3};
+
+ {
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+ imm_draw_cube_fill_3d(pos, co, rad);
+ immUnbindProgram();
+ }
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Circle Draw Style
+ *
+ * Useful for 2D views, see: #ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE
+ * \{ */
+
+static void imm_draw_point_aspect_3d(
+ uint pos, const float co[3], const float rad[3], bool solid)
+{
+ if (solid) {
+ imm_draw_cube_fill_3d(pos, co, rad);
+ }
+ else {
+ imm_draw_cube_wire_3d(pos, co, rad);
+ }
+}
+
+static void cage3d_draw_circle_wire(
+ const float r[3], const float margin[3], const float color[3],
+ const int transform_flag, const int draw_options)
+{
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ imm_draw_cube_wire_3d(pos, (float[3]){0}, r);
+
+#if 0
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ if (draw_options & ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ const float rad[2] = {margin[0] / 2, margin[1] / 2};
+ const float center[2] = {0.0f, 0.0f};
+
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, center[0] - rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] + rad[1]);
+ immVertex2f(pos, center[0] + rad[0], center[1] - rad[1]);
+ immVertex2f(pos, center[0] - rad[0], center[1] + rad[1]);
+ immEnd();
+ }
+ }
+#else
+ UNUSED_VARS(margin, transform_flag, draw_options);
+#endif
+
+
+ immUnbindProgram();
+}
+
+static void cage3d_draw_circle_handles(
+ const RegionView3D *rv3d, const float matrix_final[4][4],
+ const float r[3], const float margin[3], const float color[3],
+ bool solid, float scale)
+{
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ const float rad[3] = {margin[0] / 3, margin[1] / 3, margin[2] / 3};
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3fv(color);
+
+ float sign[3] = {-1.0f, 0.0f, 1.0f};
+ for (int x = 0; x < 3; x++) {
+ for (int y = 0; y < 3; y++) {
+ for (int z = 0; z < 3; z++) {
+ if (x == 1 && y == 1 && z == 1) {
+ continue;
+ }
+ const float co[3] = {r[0] * sign[x], r[1] * sign[y], r[2] * sign[z]};
+ float co_test[3];
+ mul_v3_m4v3(co_test, matrix_final, co);
+ float rad_scale[3];
+ mul_v3_v3fl(rad_scale, rad, ED_view3d_pixel_size(rv3d, co_test) * scale);
+ imm_draw_point_aspect_3d(pos, co, rad_scale, solid);
+ }
+ }
+ }
+
+ immUnbindProgram();
+}
+
+/** \} */
+
+static void manipulator_cage3d_draw_intern(
+ RegionView3D *rv3d,
+ wmManipulator *mpr, const bool select, const bool highlight, const int select_id)
+{
+ // const bool use_clamp = (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) == 0;
+ float dims[3];
+ RNA_float_get_array(mpr->ptr, "dimensions", dims);
+ float matrix_final[4][4];
+
+ const int transform_flag = RNA_enum_get(mpr->ptr, "transform");
+ const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+
+ const float size_real[3] = {dims[0] / 2.0f, dims[1] / 2.0f, dims[2] / 2.0f};
+
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+
+ float margin[3];
+ manipulator_calc_rect_view_margin(mpr, dims, margin);
+
+ /* Handy for quick testing draw (if it's outside bounds). */
+ if (false) {
+ glEnable(GL_BLEND);
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor4fv((const float[4]){1, 1, 1, 0.5f});
+ float s = 0.5f;
+ immRectf(pos, -s, -s, s, s);
+ immUnbindProgram();
+ glDisable(GL_BLEND);
+ }
+
+ if (select) {
+ /* expand for hotspot */
+#if 0
+ const float size[3] = {
+ size_real[0] + margin[0] / 2,
+ size_real[1] + margin[1] / 2,
+ size_real[2] + margin[2] / 2,
+ };
+#else
+ /* just use same value for now. */
+ const float size[3] = {UNPACK3(size_real)};
+#endif
+
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE) {
+ for (int i = ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z;
+ i <= ED_MANIPULATOR_CAGE3D_PART_SCALE_MAX_X_MAX_Y_MAX_Z;
+ i++)
+ {
+ if (i == ED_MANIPULATOR_CAGE3D_PART_SCALE_MID_X_MID_Y_MID_Z) {
+ continue;
+ }
+ GPU_select_load_id(select_id | i);
+ cage3d_draw_box_interaction(
+ mpr->color, i, size, margin);
+ }
+ }
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ const int transform_part = ED_MANIPULATOR_CAGE3D_PART_TRANSLATE;
+ GPU_select_load_id(select_id | transform_part);
+ cage3d_draw_box_interaction(
+ mpr->color, transform_part, size, margin);
+ }
+ }
+ else {
+#if 0
+ const rctf _r = {
+ .xmin = -size_real[0],
+ .ymin = -size_real[1],
+ .xmax = size_real[0],
+ .ymax = size_real[1],
+ };
+#endif
+ if (draw_style == ED_MANIPULATOR_CAGE2D_STYLE_BOX) {
+ /* corner manipulators */
+ glLineWidth(mpr->line_width + 3.0f);
+ cage3d_draw_box_corners(size_real, margin, (const float[3]){0, 0, 0});
+
+ /* corner manipulators */
+ float color[4];
+ manipulator_color_get(mpr, highlight, color);
+ glLineWidth(mpr->line_width);
+ cage3d_draw_box_corners(size_real, margin, color);
+
+ bool show = false;
+ if (mpr->highlight_part == ED_MANIPULATOR_CAGE3D_PART_TRANSLATE) {
+ /* Only show if we're drawing the center handle
+ * otherwise the entire rectangle is the hotspot. */
+ if (draw_options & ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE) {
+ show = true;
+ }
+ }
+ else {
+ show = true;
+ }
+
+ if (show) {
+ cage3d_draw_box_interaction(
+ mpr->color, mpr->highlight_part, size_real, margin);
+ }
+ }
+ else if (draw_style == ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE) {
+ float color[4];
+ manipulator_color_get(mpr, highlight, color);
+
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_POLYGON_SMOOTH);
+ glEnable(GL_BLEND);
+
+ glLineWidth(mpr->line_width + 3.0f);
+ cage3d_draw_circle_wire(size_real, margin, (const float[3]){0, 0, 0}, transform_flag, draw_options);
+ glLineWidth(mpr->line_width);
+ cage3d_draw_circle_wire(size_real, margin, color, transform_flag, draw_options);
+
+ /* corner manipulators */
+ cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, (const float[3]){0, 0, 0}, true, 60);
+ cage3d_draw_circle_handles(rv3d, matrix_final, size_real, margin, color, true, 40);
+
+ glDisable(GL_BLEND);
+ glDisable(GL_POLYGON_SMOOTH);
+ glDisable(GL_LINE_SMOOTH);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ glLineWidth(1.0);
+ gpuPopMatrix();
+}
+
+/**
+ * For when we want to draw 3d cage in 3d views.
+ */
+static void manipulator_cage3d_draw_select(const bContext *C, wmManipulator *mpr, int select_id)
+{
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+ manipulator_cage3d_draw_intern(rv3d, mpr, true, false, select_id);
+}
+
+static void manipulator_cage3d_draw(const bContext *C, wmManipulator *mpr)
+{
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+ const bool is_highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+ manipulator_cage3d_draw_intern(rv3d, mpr, false, is_highlight, -1);
+}
+
+static int manipulator_cage3d_get_cursor(wmManipulator *mpr)
+{
+ if (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) {
+ return BC_NSEW_SCROLLCURSOR;
+ }
+
+ return CURSOR_STD;
+}
+
+typedef struct RectTransformInteraction {
+ float orig_mouse[2];
+ float orig_matrix_offset[4][4];
+ float orig_matrix_final_no_offset[4][4];
+ Dial *dial;
+} RectTransformInteraction;
+
+static void manipulator_cage3d_setup(wmManipulator *mpr)
+{
+ mpr->flag |= /* WM_MANIPULATOR_DRAW_MODAL | */ /* TODO */
+ WM_MANIPULATOR_DRAW_NO_SCALE;
+}
+
+static int manipulator_cage3d_invoke(
+ bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+ RectTransformInteraction *data = MEM_callocN(sizeof(RectTransformInteraction), "cage_interaction");
+
+ copy_m4_m4(data->orig_matrix_offset, mpr->matrix_offset);
+ manipulator_calc_matrix_final_no_offset(mpr, data->orig_matrix_final_no_offset, true);
+
+ if (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, data->orig_mouse) == 0)
+ {
+ zero_v2(data->orig_mouse);
+ }
+
+ mpr->interaction_data = data;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+/* XXX. this isn't working properly, for now rely on the modal operators. */
+static int manipulator_cage3d_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak UNUSED(tweak_flag))
+{
+ /* For transform logic to be managable we operate in -0.5..0.5 2D space,
+ * no matter the size of the rectangle, mouse coorts are scaled to unit space.
+ * The mouse coords have been projected into the matrix so we don't need to worry about axis alignment.
+ *
+ * - The cursor offset are multiplied by 'dims'.
+ * - Matrix translation is also multiplied by 'dims'.
+ */
+ RectTransformInteraction *data = mpr->interaction_data;
+ float point_local[2];
+
+ float dims[3];
+ RNA_float_get_array(mpr->ptr, "dimensions", dims);
+
+ {
+ float matrix_back[4][4];
+ copy_m4_m4(matrix_back, mpr->matrix_offset);
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+
+ bool ok = manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, point_local);
+ copy_m4_m4(mpr->matrix_offset, matrix_back);
+ if (!ok) {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ }
+
+ const int transform_flag = RNA_enum_get(mpr->ptr, "transform");
+ wmManipulatorProperty *mpr_prop;
+
+ mpr_prop = WM_manipulator_target_property_find(mpr, "matrix");
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, &mpr->matrix_offset[0][0]);
+ }
+
+ if (mpr->highlight_part == ED_MANIPULATOR_CAGE3D_PART_TRANSLATE) {
+ /* do this to prevent clamping from changing size */
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+ mpr->matrix_offset[3][0] = data->orig_matrix_offset[3][0] + (point_local[0] - data->orig_mouse[0]);
+ mpr->matrix_offset[3][1] = data->orig_matrix_offset[3][1] + (point_local[1] - data->orig_mouse[1]);
+ }
+ else if (mpr->highlight_part == ED_MANIPULATOR_CAGE3D_PART_ROTATE) {
+
+#define MUL_V2_V3_M4_FINAL(test_co, mouse_co) \
+ mul_v3_m4v3(test_co, data->orig_matrix_final_no_offset, ((const float[3]){UNPACK2(mouse_co), 0.0}))
+
+ float test_co[3];
+
+ if (data->dial == NULL) {
+ MUL_V2_V3_M4_FINAL(test_co, data->orig_matrix_offset[3]);
+
+ data->dial = BLI_dial_initialize(test_co, FLT_EPSILON);
+
+ MUL_V2_V3_M4_FINAL(test_co, data->orig_mouse);
+ BLI_dial_angle(data->dial, test_co);
+ }
+
+ /* rotate */
+ MUL_V2_V3_M4_FINAL(test_co, point_local);
+ const float angle = BLI_dial_angle(data->dial, test_co);
+
+ float matrix_space_inv[4][4];
+ float matrix_rotate[4][4];
+ float pivot[3];
+
+ copy_v3_v3(pivot, data->orig_matrix_offset[3]);
+
+ invert_m4_m4(matrix_space_inv, mpr->matrix_space);
+
+ unit_m4(matrix_rotate);
+ mul_m4_m4m4(matrix_rotate, matrix_rotate, matrix_space_inv);
+ rotate_m4(matrix_rotate, 'Z', -angle);
+ mul_m4_m4m4(matrix_rotate, matrix_rotate, mpr->matrix_space);
+
+ zero_v3(matrix_rotate[3]);
+ transform_pivot_set_m4(matrix_rotate, pivot);
+
+ mul_m4_m4m4(mpr->matrix_offset, matrix_rotate, data->orig_matrix_offset);
+
+#undef MUL_V2_V3_M4_FINAL
+ }
+ else {
+ /* scale */
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+ float pivot[3];
+ bool constrain_axis[3] = {false};
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE) {
+ manipulator_rect_pivot_from_scale_part(mpr->highlight_part, pivot, constrain_axis);
+ }
+ else {
+ zero_v3(pivot);
+ }
+
+ /* Cursor deltas scaled to (-0.5..0.5). */
+ float delta_orig[3], delta_curr[3];
+
+ delta_orig[2] = 0.0;
+ delta_curr[2] = 0.0;
+
+ for (int i = 0; i < 2; i++) {
+ delta_orig[i] = ((data->orig_mouse[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
+ delta_curr[i] = ((point_local[i] - data->orig_matrix_offset[3][i]) / dims[i]) - pivot[i];
+ }
+
+ float scale[3] = {1.0f, 1.0f, 1.0f};
+ for (int i = 0; i < 3; i++) {
+ if (constrain_axis[i] == false) {
+ if (delta_orig[i] < 0.0f) {
+ delta_orig[i] *= -1.0f;
+ delta_curr[i] *= -1.0f;
+ }
+ const int sign = signum_i(scale[i]);
+
+ scale[i] = 1.0f + ((delta_curr[i] - delta_orig[i]) / len_v3(data->orig_matrix_offset[i]));
+
+ if ((transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_SIGNED) == 0) {
+ if (sign != signum_i(scale[i])) {
+ scale[i] = 0.0f;
+ }
+ }
+ }
+ }
+
+ if (transform_flag & ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM) {
+ if (constrain_axis[0] == false && constrain_axis[1] == false) {
+ scale[1] = scale[0] = (scale[1] + scale[0]) / 2.0f;
+ }
+ else if (constrain_axis[0] == false) {
+ scale[1] = scale[0];
+ }
+ else if (constrain_axis[1] == false) {
+ scale[0] = scale[1];
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+
+ /* scale around pivot */
+ float matrix_scale[4][4];
+ unit_m4(matrix_scale);
+
+ mul_v3_fl(matrix_scale[0], scale[0]);
+ mul_v3_fl(matrix_scale[1], scale[1]);
+ mul_v3_fl(matrix_scale[2], scale[2]);
+
+ transform_pivot_set_m4(
+ matrix_scale,
+ (const float [3]){pivot[0] * dims[0], pivot[1] * dims[1], pivot[2] * dims[2]});
+ mul_m4_m4m4(mpr->matrix_offset, data->orig_matrix_offset, matrix_scale);
+ }
+
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, &mpr->matrix_offset[0][0]);
+ }
+
+ /* tag the region for redraw */
+ ED_region_tag_redraw(CTX_wm_region(C));
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void manipulator_cage3d_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
+{
+ if (STREQ(mpr_prop->type->idname, "matrix")) {
+ if (WM_manipulator_target_property_array_length(mpr, mpr_prop) == 16) {
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, &mpr->matrix_offset[0][0]);
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ else {
+ BLI_assert(0);
+ }
+}
+
+static void manipulator_cage3d_exit(bContext *C, wmManipulator *mpr, const bool cancel)
+{
+ RectTransformInteraction *data = mpr->interaction_data;
+
+ MEM_SAFE_FREE(data->dial);
+
+ if (!cancel)
+ return;
+
+ wmManipulatorProperty *mpr_prop;
+
+ /* reset properties */
+ mpr_prop = WM_manipulator_target_property_find(mpr, "matrix");
+ if (mpr_prop->type != NULL) {
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, &data->orig_matrix_offset[0][0]);
+ }
+
+ copy_m4_m4(mpr->matrix_offset, data->orig_matrix_offset);
+}
+
+
+/* -------------------------------------------------------------------- */
+/** \name Cage Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_cage_3d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_cage_3d";
+
+ /* api callbacks */
+ wt->draw = manipulator_cage3d_draw;
+ wt->draw_select = manipulator_cage3d_draw_select;
+ wt->setup = manipulator_cage3d_setup;
+ wt->invoke = manipulator_cage3d_invoke;
+ wt->property_update = manipulator_cage3d_property_update;
+ wt->modal = manipulator_cage3d_modal;
+ wt->exit = manipulator_cage3d_exit;
+ wt->cursor_get = manipulator_cage3d_get_cursor;
+
+ wt->struct_size = sizeof(wmManipulator);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_MANIPULATOR_CAGE2D_STYLE_BOX, "BOX", 0, "Box", ""},
+ {ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE, "CIRCLE", 0, "Circle", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static EnumPropertyItem rna_enum_transform[] = {
+ {ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE, "TRANSLATE", 0, "Translate", ""},
+ {ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE, "SCALE", 0, "Scale", ""},
+ {ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM, "SCALE_UNIFORM", 0, "Scale Uniform", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "XFORM_CENTER_HANDLE", 0, "Center Handle", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static float unit_v3[3] = {1.0f, 1.0f, 1.0f};
+ RNA_def_float_vector(wt->srna, "dimensions", 3, unit_v3, 0, FLT_MAX, "Dimensions", "", 0.0f, FLT_MAX);
+ RNA_def_enum_flag(wt->srna, "transform", rna_enum_transform, 0, "Transform Options", "");
+ RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_CAGE2D_STYLE_CIRCLE, "Draw Style", "");
+ RNA_def_enum_flag(
+ wt->srna, "draw_options", rna_enum_draw_options,
+ ED_MANIPULATOR_CAGE2D_DRAW_FLAG_XFORM_CENTER_HANDLE, "Draw Options", "");
+
+ WM_manipulatortype_target_property_def(wt, "matrix", PROP_FLOAT, 16);
+}
+
+void ED_manipulatortypes_cage_3d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_cage_3d);
+}
+
+/** \} */
diff --git a/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
new file mode 100644
index 00000000000..0d2f2c2cc24
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/dial3d_manipulator.c
@@ -0,0 +1,482 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file dial3d_manipulator.c
+ * \ingroup wm
+ *
+ * \name Dial Manipulator
+ *
+ * 3D Manipulator
+ *
+ * \brief Circle shaped manipulator for circular interaction.
+ * Currently no own handling, use with operator only.
+ *
+ * - `matrix[0]` is derived from Y and Z.
+ * - `matrix[1]` is 'up' when DialManipulator.use_start_y_axis is set.
+ * - `matrix[2]` is the axis the dial rotates around (all dials).
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+/* own includes */
+#include "../manipulator_geometry.h"
+#include "../manipulator_library_intern.h"
+
+/* to use custom dials exported to geom_dial_manipulator.c */
+// #define USE_MANIPULATOR_CUSTOM_DIAL
+
+static int manipulator_dial_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak tweak_flag);
+
+typedef struct DialInteraction {
+ float init_mval[2];
+
+ /* only for when using properties */
+ float init_prop_angle;
+
+ /* cache the last angle to detect rotations bigger than -/+ PI */
+ float last_angle;
+ /* number of full rotations */
+ int rotations;
+
+ /* final output values, used for drawing */
+ struct {
+ float angle_ofs;
+ float angle_delta;
+ } output;
+} DialInteraction;
+
+#define DIAL_WIDTH 1.0f
+#define DIAL_RESOLUTION 48
+
+/**
+ * We can't use this for the #wmManipulatorType.matrix_basis_get callback, it conflicts with depth picking.
+ */
+static void dial_calc_matrix(const wmManipulator *mpr, float mat[4][4])
+{
+ float rot[3][3];
+ const float up[3] = {0.0f, 0.0f, 1.0f};
+
+ rotation_between_vecs_to_mat3(rot, up, mpr->matrix_basis[2]);
+ copy_m4_m3(mat, rot);
+ copy_v3_v3(mat[3], mpr->matrix_basis[3]);
+}
+
+/* -------------------------------------------------------------------- */
+
+static void dial_geom_draw(
+ const wmManipulator *mpr, const float color[4], const bool select,
+ float axis_modal_mat[4][4], float clip_plane[4])
+{
+#ifdef USE_MANIPULATOR_CUSTOM_DIAL
+ UNUSED_VARS(dial, col, axis_modal_mat, clip_plane);
+ wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_dial, select);
+#else
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+ const bool filled = (draw_options & ED_MANIPULATOR_DIAL_DRAW_FLAG_FILL) != 0;
+
+ glLineWidth(mpr->line_width);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ if (clip_plane) {
+ immBindBuiltinProgram(GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR);
+ float clip_plane_f[4] = {clip_plane[0], clip_plane[1], clip_plane[2], clip_plane[3]};
+ immUniform4fv("ClipPlane", clip_plane_f);
+ immUniformMatrix4fv("ModelMatrix", axis_modal_mat);
+ }
+ else {
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ }
+
+ immUniformColor4fv(color);
+
+ if (filled) {
+ imm_draw_circle_fill_2d(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ }
+ else {
+ imm_draw_circle_wire_2d(pos, 0, 0, 1.0, DIAL_RESOLUTION);
+ }
+
+ immUnbindProgram();
+
+ UNUSED_VARS(select);
+#endif
+}
+
+/**
+ * Draws a line from (0, 0, 0) to \a co_outer, at \a angle.
+ */
+static void dial_ghostarc_draw_helpline(const float angle, const float co_outer[3], const float color[4])
+{
+ glLineWidth(1.0f);
+
+ gpuPushMatrix();
+ gpuRotate3f(RAD2DEGF(angle), 0.0f, 0.0f, -1.0f);
+
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ immUniformColor4fv(color);
+
+ immBegin(GWN_PRIM_LINE_STRIP, 2);
+ immVertex3f(pos, 0.0f, 0.0f, 0.0f);
+ immVertex3fv(pos, co_outer);
+ immEnd();
+
+ immUnbindProgram();
+
+ gpuPopMatrix();
+}
+
+static void dial_ghostarc_draw(
+ const wmManipulator *mpr, const float angle_ofs, const float angle_delta, const float color[4])
+{
+ const float width_inner = DIAL_WIDTH - mpr->line_width * 0.5f / U.manipulator_size;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor4fv(color);
+ imm_draw_disk_partial_fill_2d(
+ pos, 0, 0, 0.0, width_inner, DIAL_RESOLUTION, RAD2DEGF(angle_ofs), RAD2DEGF(angle_delta));
+ immUnbindProgram();
+}
+
+static void dial_ghostarc_get_angles(
+ struct Depsgraph *depsgraph,
+ const wmManipulator *mpr,
+ const wmEvent *event,
+ const ARegion *ar, const View3D *v3d,
+ float mat[4][4], const float co_outer[3],
+ float *r_start, float *r_delta)
+{
+ DialInteraction *inter = mpr->interaction_data;
+ const RegionView3D *rv3d = ar->regiondata;
+ const float mval[2] = {event->x - ar->winrct.xmin, event->y - ar->winrct.ymin};
+
+ /* we might need to invert the direction of the angles */
+ float view_vec[3], axis_vec[3];
+ ED_view3d_global_to_vector(rv3d, mpr->matrix_basis[3], view_vec);
+ normalize_v3_v3(axis_vec, mpr->matrix_basis[2]);
+
+ float proj_outer_rel[3];
+ mul_v3_project_m4_v3(proj_outer_rel, mat, co_outer);
+ sub_v3_v3(proj_outer_rel, mpr->matrix_basis[3]);
+
+ float proj_mval_new_rel[3];
+ float proj_mval_init_rel[3];
+ float dial_plane[4];
+ float ray_co[3], ray_no[3];
+ float ray_lambda;
+
+ plane_from_point_normal_v3(dial_plane, mpr->matrix_basis[3], axis_vec);
+
+ if (!ED_view3d_win_to_ray(depsgraph, ar, v3d, inter->init_mval, ray_co, ray_no, false) ||
+ !isect_ray_plane_v3(ray_co, ray_no, dial_plane, &ray_lambda, false))
+ {
+ goto fail;
+ }
+ madd_v3_v3v3fl(proj_mval_init_rel, ray_co, ray_no, ray_lambda);
+ sub_v3_v3(proj_mval_init_rel, mpr->matrix_basis[3]);
+
+ if (!ED_view3d_win_to_ray(depsgraph, ar, v3d, mval, ray_co, ray_no, false) ||
+ !isect_ray_plane_v3(ray_co, ray_no, dial_plane, &ray_lambda, false))
+ {
+ goto fail;
+ }
+ madd_v3_v3v3fl(proj_mval_new_rel, ray_co, ray_no, ray_lambda);
+ sub_v3_v3(proj_mval_new_rel, mpr->matrix_basis[3]);
+
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+
+ /* Start direction from mouse or set by user */
+ const float *proj_init_rel =
+ (draw_options & ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_START_Y) ?
+ mpr->matrix_basis[1] : proj_mval_init_rel;
+
+ /* return angles */
+ const float start = angle_wrap_rad(angle_signed_on_axis_v3v3_v3(proj_outer_rel, proj_init_rel, axis_vec));
+ const float delta = angle_wrap_rad(angle_signed_on_axis_v3v3_v3(proj_mval_init_rel, proj_mval_new_rel, axis_vec));
+
+ /* Change of sign, we passed the 180 degree threshold. This means we need to add a turn
+ * to distinguish between transition from 0 to -1 and -PI to +PI, use comparison with PI/2.
+ * Logic taken from BLI_dial_angle */
+ if ((delta * inter->last_angle < 0.0f) &&
+ (fabsf(inter->last_angle) > (float)M_PI_2))
+ {
+ if (inter->last_angle < 0.0f)
+ inter->rotations--;
+ else
+ inter->rotations++;
+ }
+ inter->last_angle = delta;
+
+ *r_start = start;
+ *r_delta = fmod(delta + 2.0f * (float)M_PI * inter->rotations, 2 * (float)M_PI);
+ return;
+
+ /* If we can't project (unlikely). */
+fail:
+ *r_start = 0.0;
+ *r_delta = 0.0;
+}
+
+static void dial_draw_intern(
+ const bContext *C, wmManipulator *mpr,
+ const bool select, const bool highlight, float clip_plane[4])
+{
+ float matrix_basis_adjust[4][4];
+ float matrix_final[4][4];
+ float color[4];
+
+ BLI_assert(CTX_wm_area(C)->spacetype == SPACE_VIEW3D);
+
+ manipulator_color_get(mpr, highlight, color);
+
+ dial_calc_matrix(mpr, matrix_basis_adjust);
+
+ WM_manipulator_calc_matrix_final_params(
+ mpr, &((struct WM_ManipulatorMatrixParams) {
+ .matrix_basis = (void *)matrix_basis_adjust,
+ }), matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+
+ /* draw rotation indicator arc first */
+ if ((mpr->flag & WM_MANIPULATOR_DRAW_VALUE) &&
+ (mpr->state & WM_MANIPULATOR_STATE_MODAL))
+ {
+ const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f}; /* coordinate at which the arc drawing will be started */
+
+ DialInteraction *inter = mpr->interaction_data;
+
+ /* XXX, View3D rotation manipulator doesn't call modal. */
+ if (!WM_manipulator_target_property_is_valid_any(mpr)) {
+ wmWindow *win = CTX_wm_window(C);
+ manipulator_dial_modal((bContext *)C, mpr, win->eventstate, 0);
+ }
+
+ float angle_ofs = inter->output.angle_ofs;
+ float angle_delta = inter->output.angle_delta;
+
+ /* draw! */
+ for (int i = 0; i < 2; i++) {
+ glDisable(GL_POLYGON_SMOOTH);
+ dial_ghostarc_draw(mpr, angle_ofs, angle_delta, (const float [4]){0.8f, 0.8f, 0.8f, 0.4f});
+ glEnable(GL_POLYGON_SMOOTH);
+
+ dial_ghostarc_draw_helpline(angle_ofs, co_outer, color); /* starting position */
+ dial_ghostarc_draw_helpline(angle_ofs + angle_delta, co_outer, color); /* starting position + current value */
+
+ if (i == 0) {
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+ if ((draw_options & ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_MIRROR) == 0) {
+ break;
+ }
+ }
+
+ angle_ofs += (float)M_PI;
+ }
+ }
+
+ /* draw actual dial manipulator */
+ dial_geom_draw(mpr, color, select, matrix_basis_adjust, clip_plane);
+
+ gpuPopMatrix();
+}
+
+static void manipulator_dial_draw_select(const bContext *C, wmManipulator *mpr, int select_id)
+{
+ float clip_plane_buf[4];
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+ float *clip_plane = (draw_options & ED_MANIPULATOR_DIAL_DRAW_FLAG_CLIP) ? clip_plane_buf : NULL;
+
+ /* enable clipping if needed */
+ if (clip_plane) {
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+
+ copy_v3_v3(clip_plane, rv3d->viewinv[2]);
+ clip_plane[3] = -dot_v3v3(rv3d->viewinv[2], mpr->matrix_basis[3]);
+ glEnable(GL_CLIP_DISTANCE0);
+ }
+
+ GPU_select_load_id(select_id);
+ dial_draw_intern(C, mpr, true, false, clip_plane);
+
+ if (clip_plane) {
+ glDisable(GL_CLIP_DISTANCE0);
+ }
+}
+
+static void manipulator_dial_draw(const bContext *C, wmManipulator *mpr)
+{
+ const bool is_modal = mpr->state & WM_MANIPULATOR_STATE_MODAL;
+ const bool is_highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+ float clip_plane_buf[4];
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+ float *clip_plane = (!is_modal && (draw_options & ED_MANIPULATOR_DIAL_DRAW_FLAG_CLIP)) ? clip_plane_buf : NULL;
+
+ /* enable clipping if needed */
+ if (clip_plane) {
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+
+ copy_v3_v3(clip_plane, rv3d->viewinv[2]);
+ clip_plane[3] = -dot_v3v3(rv3d->viewinv[2], mpr->matrix_basis[3]);
+ clip_plane[3] -= 0.02f * mpr->scale_final;
+
+ glEnable(GL_CLIP_DISTANCE0);
+ }
+
+ glEnable(GL_BLEND);
+ dial_draw_intern(C, mpr, false, is_highlight, clip_plane);
+ glDisable(GL_BLEND);
+
+ if (clip_plane) {
+ glDisable(GL_CLIP_DISTANCE0);
+ }
+}
+
+static int manipulator_dial_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak UNUSED(tweak_flag))
+{
+ const float co_outer[4] = {0.0f, DIAL_WIDTH, 0.0f}; /* coordinate at which the arc drawing will be started */
+ float angle_ofs, angle_delta;
+
+ float matrix[4][4];
+
+ dial_calc_matrix(mpr, matrix);
+
+ dial_ghostarc_get_angles(
+ CTX_data_depsgraph(C),
+ mpr, event, CTX_wm_region(C), CTX_wm_view3d(C), matrix, co_outer, &angle_ofs, &angle_delta);
+
+ DialInteraction *inter = mpr->interaction_data;
+
+ inter->output.angle_delta = angle_delta;
+ inter->output.angle_ofs = angle_ofs;
+
+ /* set the property for the operator and call its modal function */
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ WM_manipulator_target_property_value_set(C, mpr, mpr_prop, inter->init_prop_angle + angle_delta);
+ }
+ return OPERATOR_RUNNING_MODAL;
+}
+
+
+static void manipulator_dial_setup(wmManipulator *mpr)
+{
+ const float dir_default[3] = {0.0f, 0.0f, 1.0f};
+
+ /* defaults */
+ copy_v3_v3(mpr->matrix_basis[2], dir_default);
+}
+
+static int manipulator_dial_invoke(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
+{
+ DialInteraction *inter = MEM_callocN(sizeof(DialInteraction), __func__);
+
+ inter->init_mval[0] = event->mval[0];
+ inter->init_mval[1] = event->mval[1];
+
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ inter->init_prop_angle = WM_manipulator_target_property_value_get(mpr, mpr_prop);
+ }
+
+ mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Dial Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_dial_3d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_dial_3d";
+
+ /* api callbacks */
+ wt->draw = manipulator_dial_draw;
+ wt->draw_select = manipulator_dial_draw_select;
+ wt->setup = manipulator_dial_setup;
+ wt->invoke = manipulator_dial_invoke;
+ wt->modal = manipulator_dial_modal;
+
+ wt->struct_size = sizeof(wmManipulator);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_MANIPULATOR_DIAL_DRAW_FLAG_CLIP, "CLIP", 0, "Clipped", ""},
+ {ED_MANIPULATOR_DIAL_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
+ {ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_MIRROR, "ANGLE_MIRROR", 0, "Angle Mirror", ""},
+ {ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_START_Y, "ANGLE_START_Y", 0, "Angle Start Y", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ RNA_def_enum_flag(wt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+
+ WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 1);
+}
+
+void ED_manipulatortypes_dial_3d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_dial_3d);
+}
+
+/** \} */
diff --git a/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
new file mode 100644
index 00000000000..9c6c601b7ae
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/grab3d_manipulator.c
@@ -0,0 +1,374 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file grab3d_manipulator.c
+ * \ingroup wm
+ *
+ * \name Grab Manipulator
+ *
+ * 3D Manipulator, also works in 2D views.
+ *
+ * \brief Simple manipulator to grab and translate.
+ *
+ * - `matrix[0]` is derived from Y and Z.
+ * - `matrix[1]` currently not used.
+ * - `matrix[2]` is the widget direction (for all manipulators).
+ *
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+/* own includes */
+#include "../manipulator_geometry.h"
+#include "../manipulator_library_intern.h"
+
+typedef struct GrabManipulator3D {
+ wmManipulator manipulator;
+ /* Added to 'matrix_basis' when calculating the matrix. */
+ float prop_co[3];
+} GrabManipulator3D;
+
+static void manipulator_grab_matrix_basis_get(const wmManipulator *mpr, float r_matrix[4][4])
+{
+ GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
+
+ copy_m4_m4(r_matrix, grab->manipulator.matrix_basis);
+ add_v3_v3(r_matrix[3], grab->prop_co);
+}
+
+static int manipulator_grab_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak tweak_flag);
+
+typedef struct GrabInteraction {
+ float init_mval[2];
+
+ /* only for when using properties */
+ float init_prop_co[3];
+
+ float init_matrix_final[4][4];
+} GrabInteraction;
+
+#define DIAL_RESOLUTION 32
+
+/* -------------------------------------------------------------------- */
+
+static void grab_geom_draw(
+ const wmManipulator *mpr, const float color[4], const bool select, const int draw_options)
+{
+#ifdef USE_MANIPULATOR_CUSTOM_DIAL
+ UNUSED_VARS(grab3d, col, axis_modal_mat);
+ wm_manipulator_geometryinfo_draw(&wm_manipulator_geom_data_grab3d, select);
+#else
+ const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
+ const bool filled = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL) != 0;
+
+ glLineWidth(mpr->line_width);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ uint pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ immUniformColor4fv(color);
+
+ if (draw_style == ED_MANIPULATOR_GRAB_STYLE_RING_2D) {
+ if (filled) {
+ imm_draw_circle_fill_2d(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
+ }
+ else {
+ imm_draw_circle_wire_2d(pos, 0, 0, 1.0f, DIAL_RESOLUTION);
+ }
+ }
+ else if (draw_style == ED_MANIPULATOR_GRAB_STYLE_CROSS_2D) {
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, 1.0f, 1.0f);
+ immVertex2f(pos, -1.0f, -1.0f);
+
+ immVertex2f(pos, -1.0f, 1.0f);
+ immVertex2f(pos, 1.0f, -1.0f);
+ immEnd();
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ immUnbindProgram();
+
+ UNUSED_VARS(select);
+#endif
+}
+
+static void grab3d_get_translate(
+ const wmManipulator *mpr, const wmEvent *event, const ARegion *ar,
+ float co_delta[3])
+{
+ GrabInteraction *inter = mpr->interaction_data;
+ const float mval_delta[2] = {
+ event->mval[0] - inter->init_mval[0],
+ event->mval[1] - inter->init_mval[1],
+ };
+
+ RegionView3D *rv3d = ar->regiondata;
+ float co_ref[3];
+ mul_v3_mat3_m4v3(co_ref, mpr->matrix_space, inter->init_prop_co);
+ const float zfac = ED_view3d_calc_zfac(rv3d, co_ref, NULL);
+
+ ED_view3d_win_to_delta(ar, mval_delta, co_delta, zfac);
+
+ float matrix_space_inv[3][3];
+ copy_m3_m4(matrix_space_inv, mpr->matrix_space);
+ invert_m3(matrix_space_inv);
+ mul_m3_v3(matrix_space_inv, co_delta);
+}
+
+static void grab3d_draw_intern(
+ const bContext *C, wmManipulator *mpr,
+ const bool select, const bool highlight)
+{
+ GrabInteraction *inter = mpr->interaction_data;
+ const int draw_options = RNA_enum_get(mpr->ptr, "draw_options");
+ const bool align_view = (draw_options & ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW) != 0;
+ float color[4];
+ float matrix_final[4][4];
+ float matrix_align[4][4];
+
+ manipulator_color_get(mpr, highlight, color);
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+
+ if (align_view) {
+ float matrix_final_unit[4][4];
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ normalize_m4_m4(matrix_final_unit, matrix_final);
+ mul_m4_m4m4(matrix_align, rv3d->viewmat, matrix_final_unit);
+ zero_v3(matrix_align[3]);
+ transpose_m4(matrix_align);
+ gpuMultMatrix(matrix_align);
+ }
+
+ glEnable(GL_BLEND);
+ grab_geom_draw(mpr, color, select, draw_options);
+ glDisable(GL_BLEND);
+ gpuPopMatrix();
+
+ if (mpr->interaction_data) {
+ gpuPushMatrix();
+ gpuMultMatrix(inter->init_matrix_final);
+
+ if (align_view) {
+ gpuMultMatrix(matrix_align);
+ }
+
+ glEnable(GL_BLEND);
+ grab_geom_draw(mpr, (const float [4]){0.5f, 0.5f, 0.5f, 0.5f}, select, draw_options);
+ glDisable(GL_BLEND);
+ gpuPopMatrix();
+ }
+}
+
+static void manipulator_grab_draw_select(const bContext *C, wmManipulator *mpr, int select_id)
+{
+ GPU_select_load_id(select_id);
+ grab3d_draw_intern(C, mpr, true, false);
+}
+
+static void manipulator_grab_draw(const bContext *C, wmManipulator *mpr)
+{
+ const bool is_modal = mpr->state & WM_MANIPULATOR_STATE_MODAL;
+ const bool is_highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+
+ (void)is_modal;
+
+ glEnable(GL_BLEND);
+ grab3d_draw_intern(C, mpr, false, is_highlight);
+ glDisable(GL_BLEND);
+}
+
+static int manipulator_grab_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak UNUSED(tweak_flag))
+{
+ GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
+ GrabInteraction *inter = mpr->interaction_data;
+ ARegion *ar = CTX_wm_region(C);
+
+ float prop_delta[3];
+ if (CTX_wm_area(C)->spacetype == SPACE_VIEW3D) {
+ grab3d_get_translate(mpr, event, ar, prop_delta);
+ }
+ else {
+ float mval_proj_init[2], mval_proj_curr[2];
+ if ((manipulator_window_project_2d(
+ C, mpr, inter->init_mval, 2, false, mval_proj_init) == false) ||
+ (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, false, mval_proj_curr) == false))
+ {
+ return OPERATOR_RUNNING_MODAL;
+ }
+ sub_v2_v2v2(prop_delta, mval_proj_curr, mval_proj_init);
+ prop_delta[2] = 0.0f;
+ }
+ add_v3_v3v3(grab->prop_co, inter->init_prop_co, prop_delta);
+
+ /* set the property for the operator and call its modal function */
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ WM_manipulator_target_property_value_set_array(C, mpr, mpr_prop, grab->prop_co);
+ }
+ else {
+ zero_v3(grab->prop_co);
+ }
+
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int manipulator_grab_invoke(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
+{
+ GrabInteraction *inter = MEM_callocN(sizeof(GrabInteraction), __func__);
+
+ inter->init_mval[0] = event->mval[0];
+ inter->init_mval[1] = event->mval[1];
+
+#if 0
+ copy_v3_v3(inter->init_prop_co, grab->prop_co);
+#else
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_find(mpr, "offset");
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, inter->init_prop_co);
+ }
+#endif
+
+ WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
+
+ mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+
+static int manipulator_grab_test_select(
+ bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+ float point_local[2];
+
+ if (manipulator_window_project_2d(
+ C, mpr, (const float[2]){UNPACK2(event->mval)}, 2, true, point_local) == false)
+ {
+ return -1;
+ }
+
+ /* The 'mpr->scale_final' is already applied when projecting. */
+ if (len_squared_v2(point_local) < 1.0f) {
+ return 0;
+ }
+
+ return -1;
+}
+
+static void manipulator_grab_property_update(wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
+{
+ GrabManipulator3D *grab = (GrabManipulator3D *)mpr;
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, grab->prop_co);
+ }
+ else {
+ zero_v3(grab->prop_co);
+ }
+}
+
+static int manipulator_grab_cursor_get(wmManipulator *UNUSED(mpr))
+{
+ return BC_NSEW_SCROLLCURSOR;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Grab Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_grab_3d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_grab_3d";
+
+ /* api callbacks */
+ wt->draw = manipulator_grab_draw;
+ wt->draw_select = manipulator_grab_draw_select;
+ wt->test_select = manipulator_grab_test_select;
+ wt->matrix_basis_get = manipulator_grab_matrix_basis_get;
+ wt->invoke = manipulator_grab_invoke;
+ wt->property_update = manipulator_grab_property_update;
+ wt->modal = manipulator_grab_modal;
+ wt->cursor_get = manipulator_grab_cursor_get;
+
+ wt->struct_size = sizeof(GrabManipulator3D);
+
+ /* rna */
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_MANIPULATOR_GRAB_STYLE_RING_2D, "RING_2D", 0, "Ring", ""},
+ {ED_MANIPULATOR_GRAB_STYLE_CROSS_2D, "CROSS_2D", 0, "Ring", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ static EnumPropertyItem rna_enum_draw_options[] = {
+ {ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL, "FILL", 0, "Filled", ""},
+ {ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW, "ALIGN_VIEW", 0, "Align View", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_GRAB_STYLE_RING_2D, "Draw Style", "");
+ RNA_def_enum_flag(wt->srna, "draw_options", rna_enum_draw_options, 0, "Draw Options", "");
+
+ WM_manipulatortype_target_property_def(wt, "offset", PROP_FLOAT, 3);
+}
+
+void ED_manipulatortypes_grab_3d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_grab_3d);
+}
+
+/** \} */ // Grab Manipulator API
diff --git a/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
new file mode 100644
index 00000000000..531cf742e6f
--- /dev/null
+++ b/source/blender/editors/manipulator_library/manipulator_types/primitive3d_manipulator.c
@@ -0,0 +1,190 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file primitive3d_manipulator.c
+ * \ingroup wm
+ *
+ * \name Primitive Manipulator
+ *
+ * 3D Manipulator
+ *
+ * \brief Manipulator with primitive drawing type (plane, cube, etc.).
+ * Currently only plane primitive supported without own handling, use with operator only.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+
+#include "DNA_view3d_types.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_manipulator_library.h"
+
+/* own includes */
+#include "../manipulator_library_intern.h"
+
+static float verts_plane[4][3] = {
+ {-1, -1, 0},
+ { 1, -1, 0},
+ { 1, 1, 0},
+ {-1, 1, 0},
+};
+
+
+/* -------------------------------------------------------------------- */
+
+static void manipulator_primitive_draw_geom(
+ const float col_inner[4], const float col_outer[4], const int draw_style)
+{
+ float (*verts)[3];
+ uint vert_count = 0;
+
+ if (draw_style == ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE) {
+ verts = verts_plane;
+ vert_count = ARRAY_SIZE(verts_plane);
+ }
+
+ if (vert_count > 0) {
+ uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ wm_manipulator_vec_draw(col_inner, verts, vert_count, pos, GWN_PRIM_TRI_FAN);
+ wm_manipulator_vec_draw(col_outer, verts, vert_count, pos, GWN_PRIM_LINE_LOOP);
+ immUnbindProgram();
+ }
+}
+
+static void manipulator_primitive_draw_intern(
+ wmManipulator *mpr, const bool UNUSED(select),
+ const bool highlight)
+{
+ float color_inner[4], color_outer[4];
+ float matrix_final[4][4];
+ const int draw_style = RNA_enum_get(mpr->ptr, "draw_style");
+
+ manipulator_color_get(mpr, highlight, color_outer);
+ copy_v4_v4(color_inner, color_outer);
+ color_inner[3] *= 0.5f;
+
+ WM_manipulator_calc_matrix_final(mpr, matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+
+ glEnable(GL_BLEND);
+ manipulator_primitive_draw_geom(color_inner, color_outer, draw_style);
+ glDisable(GL_BLEND);
+
+ gpuPopMatrix();
+
+ if (mpr->interaction_data) {
+ ManipulatorInteraction *inter = mpr->interaction_data;
+
+ copy_v4_fl(color_inner, 0.5f);
+ copy_v3_fl(color_outer, 0.5f);
+ color_outer[3] = 0.8f;
+
+ gpuPushMatrix();
+ gpuMultMatrix(inter->init_matrix_final);
+
+ glEnable(GL_BLEND);
+ manipulator_primitive_draw_geom(color_inner, color_outer, draw_style);
+ glDisable(GL_BLEND);
+
+ gpuPopMatrix();
+ }
+}
+
+static void manipulator_primitive_draw_select(
+ const bContext *UNUSED(C), wmManipulator *mpr,
+ int select_id)
+{
+ GPU_select_load_id(select_id);
+ manipulator_primitive_draw_intern(mpr, true, false);
+}
+
+static void manipulator_primitive_draw(const bContext *UNUSED(C), wmManipulator *mpr)
+{
+ manipulator_primitive_draw_intern(
+ mpr, false,
+ (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT));
+}
+
+static void manipulator_primitive_setup(wmManipulator *mpr)
+{
+ mpr->flag |= WM_MANIPULATOR_DRAW_MODAL;
+}
+
+static int manipulator_primitive_invoke(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *UNUSED(event))
+{
+ ManipulatorInteraction *inter = MEM_callocN(sizeof(ManipulatorInteraction), __func__);
+
+ WM_manipulator_calc_matrix_final(mpr, inter->init_matrix_final);
+
+ mpr->interaction_data = inter;
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Primitive Manipulator API
+ *
+ * \{ */
+
+static void MANIPULATOR_WT_primitive_3d(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "MANIPULATOR_WT_primitive_3d";
+
+ /* api callbacks */
+ wt->draw = manipulator_primitive_draw;
+ wt->draw_select = manipulator_primitive_draw_select;
+ wt->setup = manipulator_primitive_setup;
+ wt->invoke = manipulator_primitive_invoke;
+
+ wt->struct_size = sizeof(wmManipulator);
+
+ static EnumPropertyItem rna_enum_draw_style[] = {
+ {ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE, "PLANE", 0, "Plane", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ RNA_def_enum(wt->srna, "draw_style", rna_enum_draw_style, ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE, "Draw Style", "");
+}
+
+void ED_manipulatortypes_primitive_3d(void)
+{
+ WM_manipulatortype_append(MANIPULATOR_WT_primitive_3d);
+}
+
+/** \} */
diff --git a/source/blender/editors/mask/CMakeLists.txt b/source/blender/editors/mask/CMakeLists.txt
index 033d034cf4e..d17df344dc9 100644
--- a/source/blender/editors/mask/CMakeLists.txt
+++ b/source/blender/editors/mask/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
../include
../../blenkernel
../../blenlib
+ ../../depsgraph
../../gpu
../../makesdna
../../makesrna
diff --git a/source/blender/editors/mask/mask_add.c b/source/blender/editors/mask/mask_add.c
index 69335195b96..ad1a567f843 100644
--- a/source/blender/editors/mask/mask_add.c
+++ b/source/blender/editors/mask/mask_add.c
@@ -34,9 +34,10 @@
#include "BLI_math.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_mask.h"
+#include "DEG_depsgraph.h"
+
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_mask_types.h"
@@ -692,7 +693,7 @@ static int add_feather_vertex_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mask/mask_draw.c b/source/blender/editors/mask/mask_draw.c
index 407c19a3860..689a96a3dec 100644
--- a/source/blender/editors/mask/mask_draw.c
+++ b/source/blender/editors/mask/mask_draw.c
@@ -36,6 +36,7 @@
#include "BLI_math.h"
#include "BLI_rect.h"
#include "BLI_task.h"
+#include "BLI_listbase.h"
#include "BKE_context.h"
#include "BKE_mask.h"
@@ -48,10 +49,13 @@
#include "ED_clip.h"
#include "ED_mask.h" /* own include */
#include "ED_space_api.h"
-#include "BIF_gl.h"
+
#include "BIF_glutil.h"
-#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_draw.h"
+#include "GPU_shader.h"
+#include "GPU_matrix.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -93,40 +97,6 @@ static void mask_spline_feather_color_get(MaskLayer *UNUSED(masklay), MaskSpline
r_rgb[3] = 255;
}
-#if 0
-static void draw_spline_parents(MaskLayer *UNUSED(masklay), MaskSpline *spline)
-{
- int i;
- MaskSplinePoint *points_array = BKE_mask_spline_point_array(spline);
-
- if (!spline->tot_point)
- return;
-
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(1, 0xAAAA);
-
- glColor3ub(0, 0, 0);
- glBegin(GL_LINES);
-
- for (i = 0; i < spline->tot_point; i++) {
- MaskSplinePoint *point = &points_array[i];
- BezTriple *bezt = &point->bezt;
-
- if (point->parent.id) {
- glVertex2f(bezt->vec[1][0],
- bezt->vec[1][1]);
-
- glVertex2f(bezt->vec[1][0] - point->parent.offset[0],
- bezt->vec[1][1] - point->parent.offset[1]);
- }
- }
-
- glEnd();
-
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
-}
-#endif
-
static void mask_point_undistort_pos(SpaceClip *sc, float r_co[2], const float co[2])
{
BKE_mask_coord_to_movieclip(sc->clip, &sc->user, r_co, co);
@@ -134,46 +104,9 @@ static void mask_point_undistort_pos(SpaceClip *sc, float r_co[2], const float c
BKE_mask_coord_from_movieclip(sc->clip, &sc->user, r_co, r_co);
}
-static void draw_circle(const float x, const float y,
- const float size, const bool fill,
- const float xscale, const float yscale)
-{
- static GLuint wire_displist = 0;
- static GLuint fill_displist = 0;
- GLuint displist = fill ? fill_displist : wire_displist;
-
- /* Initialize round circle shape. */
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, fill ? GLU_FILL : GLU_SILHOUETTE);
- gluDisk(qobj, 0, 0.7, 8, 1);
- gluDeleteQuadric(qobj);
-
- glEndList();
-
- if (fill) {
- fill_displist = displist;
- }
- else {
- wire_displist = displist;
- }
- }
-
- glPushMatrix();
- glTranslatef(x, y, 0.0f);
- glScalef(1.0f / xscale * size, 1.0f / yscale * size, 1.0f);
- glCallList(displist);
- glPopMatrix();
-}
-
static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoint *point,
const eMaskWhichHandle which_handle, const int draw_type,
- const float handle_size, const float xscale, const float yscale,
+ const float handle_size,
const float point_pos[2], const float handle_pos[2])
{
const BezTriple *bezt = &point->bezt;
@@ -190,54 +123,70 @@ static void draw_single_handle(const MaskLayer *mask_layer, const MaskSplinePoin
return;
}
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ const unsigned char rgb_gray[4] = {0x60, 0x60, 0x60, 0xff};
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3ubv(rgb_gray);
+
/* this could be split into its own loop */
if (draw_type == MASK_DT_OUTLINE) {
- const unsigned char rgb_gray[4] = {0x60, 0x60, 0x60, 0xff};
- glLineWidth(3);
- glColor4ubv(rgb_gray);
- glBegin(GL_LINES);
- glVertex2fv(point_pos);
- glVertex2fv(handle_pos);
- glEnd();
+ glLineWidth(3.0f);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(pos, point_pos);
+ immVertex2fv(pos, handle_pos);
+ immEnd();
}
switch (handle_type) {
case HD_FREE:
- UI_ThemeColor(TH_HANDLE_FREE);
+ immUniformThemeColor(TH_HANDLE_FREE);
break;
case HD_AUTO:
- UI_ThemeColor(TH_HANDLE_AUTO);
+ immUniformThemeColor(TH_HANDLE_AUTO);
break;
case HD_ALIGN:
case HD_ALIGN_DOUBLESIDE:
- UI_ThemeColor(TH_HANDLE_ALIGN);
+ immUniformThemeColor(TH_HANDLE_ALIGN);
break;
}
- glLineWidth(1);
- glBegin(GL_LINES);
- glVertex2fv(point_pos);
- glVertex2fv(handle_pos);
- glEnd();
+ glLineWidth(1.0f);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(pos, point_pos);
+ immVertex2fv(pos, handle_pos);
+ immEnd();
+ immUnbindProgram();
/* draw handle points */
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA);
+ immUniform1f("size", handle_size);
+ immUniform1f("outlineWidth", 1.5f);
+
+ float point_color[4] = { 1.0f, 1.0f, 1.0f, 1.0f }; /* active color by default */
if (MASKPOINT_ISSEL_HANDLE(point, which_handle)) {
- if (point == mask_layer->act_point)
- glColor3f(1.0f, 1.0f, 1.0f);
- else
- UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
+ if (point != mask_layer->act_point) {
+ UI_GetThemeColor3fv(TH_HANDLE_VERTEX_SELECT, point_color);
+ }
}
else {
- UI_ThemeColor(TH_HANDLE_VERTEX);
+ UI_GetThemeColor3fv(TH_HANDLE_VERTEX, point_color);
}
- draw_circle(handle_pos[0], handle_pos[1], handle_size, false, xscale, yscale);
+ immUniform4fv("outlineColor", point_color);
+ immUniformColor3fvAlpha(point_color, 0.25f);
+
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2fv(pos, handle_pos);
+ immEnd();
+
+ immUnbindProgram();
}
/* return non-zero if spline is selected */
static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline *spline,
- const char draw_flag, const char draw_type,
- const float xscale, const float yscale)
+ const char draw_flag, const char draw_type)
{
const bool is_spline_sel = (spline->flag & SELECT) && (masklay->restrictflag & MASK_RESTRICT_SELECT) == 0;
const bool is_smooth = (draw_flag & MASK_DRAWFLAG_SMOOTH) != 0;
@@ -247,7 +196,7 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
SpaceClip *sc = CTX_wm_space_clip(C);
bool undistort = false;
- int i, handle_size, tot_feather_point;
+ int tot_feather_point;
float (*feather_points)[2], (*fp)[2];
float min[2], max[2];
@@ -258,22 +207,24 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
undistort = sc->clip && (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT);
/* TODO, add this to sequence editor */
- handle_size = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize;
-
- glPointSize(handle_size);
+ float handle_size = 2.0f * UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize;
mask_spline_color_get(masklay, spline, is_spline_sel, rgb_spline);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
+ immUniform1f("size", 0.7f * handle_size);
+
/* feather points */
feather_points = fp = BKE_mask_spline_feather_points(spline, &tot_feather_point);
- for (i = 0; i < spline->tot_point; i++) {
+ for (int i = 0; i < spline->tot_point; i++) {
/* watch it! this is intentionally not the deform array, only check for sel */
MaskSplinePoint *point = &spline->points[i];
- int j;
-
- for (j = 0; j <= point->tot_uw; j++) {
+ for (int j = 0; j <= point->tot_uw; j++) {
float feather_point[2];
bool sel = false;
@@ -291,32 +242,32 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
if (sel) {
if (point == masklay->act_point)
- glColor3f(1.0f, 1.0f, 1.0f);
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
else
- UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
+ immUniformThemeColor(TH_HANDLE_VERTEX_SELECT);
}
else {
- UI_ThemeColor(TH_HANDLE_VERTEX);
+ immUniformThemeColor(TH_HANDLE_VERTEX);
}
- glBegin(GL_POINTS);
- glVertex2fv(feather_point);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2fv(pos, feather_point);
+ immEnd();
fp++;
}
}
MEM_freeN(feather_points);
+ immUnbindProgram();
+
if (is_smooth) {
glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
/* control points */
INIT_MINMAX2(min, max);
- for (i = 0; i < spline->tot_point; i++) {
+ for (int i = 0; i < spline->tot_point; i++) {
/* watch it! this is intentionally not the deform array, only check for sel */
MaskSplinePoint *point = &spline->points[i];
@@ -339,7 +290,7 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
mask_point_undistort_pos(sc, handle, handle);
}
draw_single_handle(masklay, point, MASK_WHICH_HANDLE_STICK,
- draw_type, handle_size, xscale, yscale, vert, handle);
+ draw_type, handle_size, vert, handle);
}
else {
float handle_left[2], handle_right[2];
@@ -350,53 +301,62 @@ static void draw_spline_points(const bContext *C, MaskLayer *masklay, MaskSpline
mask_point_undistort_pos(sc, handle_left, handle_left);
}
draw_single_handle(masklay, point, MASK_WHICH_HANDLE_LEFT,
- draw_type, handle_size, xscale, yscale, vert, handle_left);
+ draw_type, handle_size, vert, handle_left);
draw_single_handle(masklay, point, MASK_WHICH_HANDLE_RIGHT,
- draw_type, handle_size, xscale, yscale, vert, handle_right);
+ draw_type, handle_size, vert, handle_right);
}
+ /* bind program in loop so it does not interfere with draw_single_handle */
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
+
/* draw CV point */
if (MASKPOINT_ISSEL_KNOT(point)) {
if (point == masklay->act_point)
- glColor3f(1.0f, 1.0f, 1.0f);
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
else
- UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
+ immUniformThemeColor(TH_HANDLE_VERTEX_SELECT);
}
else
- UI_ThemeColor(TH_HANDLE_VERTEX);
+ immUniformThemeColor(TH_HANDLE_VERTEX);
+
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2fv(pos, vert);
+ immEnd();
- glBegin(GL_POINTS);
- glVertex2fv(vert);
- glEnd();
+ immUnbindProgram();
minmax_v2v2_v2(min, max, vert);
}
+ if (is_smooth) {
+ glDisable(GL_LINE_SMOOTH);
+ }
+
if (is_spline_sel) {
- float x = (min[0] + max[0]) / 2.0f;
- float y = (min[1] + max[1]) / 2.0f;
- /* TODO(sergey): Remove hardcoded colors. */
+ float x = (min[0] + max[0]) * 0.5f;
+ float y = (min[1] + max[1]) * 0.5f;
+
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA);
+ immUniform1f("outlineWidth", 1.5f);
+
if (masklay->act_spline == spline) {
- glColor3ub(255, 255, 255);
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
}
else {
- glColor3ub(255, 255, 0);
+ immUniformColor3f(1.0f, 1.0f, 0.0f);
}
- draw_circle(x, y, 6.0f, true, xscale, yscale);
+ immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, 1.0f);
+ immUniform1f("size", 12.0f);
- glColor3ub(0, 0, 0);
- draw_circle(x, y, 6.0f, false, xscale, yscale);
- }
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2f(pos, x, y);
+ immEnd();
- if (is_smooth) {
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
+ immUnbindProgram();
}
}
-/* #define USE_XOR */
-
static void mask_color_active_tint(unsigned char r_rgb[4], const unsigned char rgb[4], const bool is_active)
{
if (!is_active) {
@@ -410,13 +370,21 @@ static void mask_color_active_tint(unsigned char r_rgb[4], const unsigned char r
}
}
+static void mask_draw_array(unsigned int pos, Gwn_PrimType prim_type, const float (*points)[2], unsigned int vertex_ct)
+{
+ immBegin(prim_type, vertex_ct);
+ for (unsigned int i = 0; i < vertex_ct; ++i) {
+ immVertex2fv(pos, points[i]);
+ }
+ immEnd();
+}
+
static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float (*orig_points)[2], int tot_point,
- const bool is_feather, const bool is_smooth, const bool is_active,
+ const bool is_feather, const bool is_active,
const unsigned char rgb_spline[4], const char draw_type)
{
- const int draw_method = (spline->flag & MASK_SPLINE_CYCLIC) ? GL_LINE_LOOP : GL_LINE_STRIP;
+ const Gwn_PrimType draw_method = (spline->flag & MASK_SPLINE_CYCLIC) ? GWN_PRIM_LINE_LOOP : GWN_PRIM_LINE_STRIP;
const unsigned char rgb_black[4] = {0x00, 0x00, 0x00, 0xff};
-// const unsigned char rgb_white[4] = {0xff, 0xff, 0xff, 0xff};
unsigned char rgb_tmp[4];
SpaceClip *sc = CTX_wm_space_clip(C);
float (*points)[2] = orig_points;
@@ -425,65 +393,45 @@ static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float (*
const bool undistort = sc->clip && (sc->user.render_flag & MCLIP_PROXY_RENDER_UNDISTORT);
if (undistort) {
- int i;
-
points = MEM_callocN(2 * tot_point * sizeof(float), "undistorthed mask curve");
- for (i = 0; i < tot_point; i++) {
+ for (int i = 0; i < tot_point; i++) {
mask_point_undistort_pos(sc, points[i], orig_points[i]);
}
}
}
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, points);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
switch (draw_type) {
case MASK_DT_OUTLINE:
- glLineWidth(3);
-
- mask_color_active_tint(rgb_tmp, rgb_black, is_active);
- glColor4ubv(rgb_tmp);
-
- glDrawArrays(draw_method, 0, tot_point);
+ /* TODO(merwin): use fancy line shader here
+ * probably better with geometry shader (after core profile switch)
+ */
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glLineWidth(1);
- mask_color_active_tint(rgb_tmp, rgb_spline, is_active);
- glColor4ubv(rgb_tmp);
- glDrawArrays(draw_method, 0, tot_point);
+ glLineWidth(3.0f);
- break;
+ mask_color_active_tint(rgb_tmp, rgb_black, is_active);
+ immUniformColor4ubv(rgb_tmp);
+ mask_draw_array(pos, draw_method, points, tot_point);
- case MASK_DT_DASH:
- default:
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(3, 0xAAAA);
+ glLineWidth(1.0f);
-#ifdef USE_XOR
- glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(GL_OR);
-#endif
mask_color_active_tint(rgb_tmp, rgb_spline, is_active);
- glColor4ubv(rgb_tmp);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, points);
- glDrawArrays(draw_method, 0, tot_point);
-
-#ifdef USE_XOR
- glDisable(GL_COLOR_LOGIC_OP);
-#endif
- mask_color_active_tint(rgb_tmp, rgb_black, is_active);
- glColor4ubv(rgb_tmp);
- GPU_basic_shader_line_stipple(3, 0x5555);
- glDrawArrays(draw_method, 0, tot_point);
+ immUniformColor4ubv(rgb_tmp);
+ mask_draw_array(pos, draw_method, points, tot_point);
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
+ immUnbindProgram();
break;
-
case MASK_DT_BLACK:
case MASK_DT_WHITE:
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ glLineWidth(1.0f);
+
if (draw_type == MASK_DT_BLACK) { rgb_tmp[0] = rgb_tmp[1] = rgb_tmp[2] = 0; }
else { rgb_tmp[0] = rgb_tmp[1] = rgb_tmp[2] = 255; }
/* alpha values seem too low but gl draws many points that compensate for it */
@@ -496,26 +444,39 @@ static void mask_draw_curve_type(const bContext *C, MaskSpline *spline, float (*
rgb_tmp[2] = (unsigned char)(((short)rgb_tmp[2] + (short)rgb_spline[2]) / 2);
}
- if (is_smooth == false && is_feather) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
-
mask_color_active_tint(rgb_tmp, rgb_tmp, is_active);
- glColor4ubv(rgb_tmp);
+ immUniformColor4ubv(rgb_tmp);
+ mask_draw_array(pos, draw_method, points, tot_point);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, points);
- glDrawArrays(draw_method, 0, tot_point);
+ immUnbindProgram();
+ break;
- if (is_smooth == false && is_feather) {
- glDisable(GL_BLEND);
- }
+ case MASK_DT_DASH:
+ /* TODO(merwin): use dashed line shader here
+ * probably better with geometry shader (after core profile switch)
+ */
+#if 0
+ glLineWidth(1.0f);
+
+ GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
+ GPU_basic_shader_line_stipple(3, 0xAAAA);
+ mask_color_active_tint(rgb_tmp, rgb_spline, is_active);
+ immUniformColor4ubv(rgb_tmp);
+ mask_draw_array(pos, draw_method, points, tot_point);
+
+ mask_color_active_tint(rgb_tmp, rgb_black, is_active);
+ immUniformColor4ubv(rgb_tmp);
+ GPU_basic_shader_line_stipple(3, 0x5555);
+ mask_draw_array(pos, draw_method, points, tot_point);
+
+ GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
+#endif
break;
- }
- glDisableClientState(GL_VERTEX_ARRAY);
+ default:
+ BLI_assert(false);
+ }
if (points != orig_points)
MEM_freeN(points);
@@ -548,8 +509,6 @@ static void draw_spline_curve(const bContext *C, MaskLayer *masklay, MaskSpline
if (is_smooth) {
glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
feather_points = BKE_mask_spline_feather_differentiated_points_with_resolution(spline, &tot_feather_point, resol, (is_fill != false));
@@ -557,26 +516,24 @@ static void draw_spline_curve(const bContext *C, MaskLayer *masklay, MaskSpline
/* draw feather */
mask_spline_feather_color_get(masklay, spline, is_spline_sel, rgb_tmp);
mask_draw_curve_type(C, spline, feather_points, tot_feather_point,
- true, is_smooth, is_active,
+ true, is_active,
rgb_tmp, draw_type);
if (!is_fill) {
-
const float *fp = &diff_points[0][0];
float *fp_feather = &feather_points[0][0];
- float tvec[2];
- int i;
BLI_assert(tot_diff_point == tot_feather_point);
- for (i = 0; i < tot_diff_point; i++, fp += 2, fp_feather += 2) {
+ for (int i = 0; i < tot_diff_point; i++, fp += 2, fp_feather += 2) {
+ float tvec[2];
sub_v2_v2v2(tvec, fp, fp_feather);
add_v2_v2v2(fp_feather, fp, tvec);
}
/* same as above */
mask_draw_curve_type(C, spline, feather_points, tot_feather_point,
- true, is_smooth, is_active,
+ true, is_active,
rgb_tmp, draw_type);
}
@@ -585,21 +542,22 @@ static void draw_spline_curve(const bContext *C, MaskLayer *masklay, MaskSpline
/* draw main curve */
mask_spline_color_get(masklay, spline, is_spline_sel, rgb_tmp);
mask_draw_curve_type(C, spline, diff_points, tot_diff_point,
- false, is_smooth, is_active,
+ false, is_active,
rgb_tmp, draw_type);
MEM_freeN(diff_points);
- if (draw_flag & MASK_DRAWFLAG_SMOOTH) {
+ if (is_smooth) {
glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
}
-
- (void)draw_type;
}
static void draw_masklays(const bContext *C, Mask *mask, const char draw_flag, const char draw_type,
- const int width, const int height, const float xscale, const float yscale)
+ const int width, const int height)
{
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ GPU_enable_program_point_size();
+
MaskLayer *masklay;
int i;
@@ -616,11 +574,9 @@ static void draw_masklays(const bContext *C, Mask *mask, const char draw_flag, c
/* draw curve itself first... */
draw_spline_curve(C, masklay, spline, draw_flag, draw_type, is_active, width, height);
-// draw_spline_parents(masklay, spline);
-
if (!(masklay->restrictflag & MASK_RESTRICT_SELECT)) {
/* ...and then handles over the curve so they're nicely visible */
- draw_spline_points(C, masklay, spline, draw_flag, draw_type, xscale, yscale);
+ draw_spline_points(C, masklay, spline, draw_flag, draw_type);
}
/* show undeform for testing */
@@ -629,33 +585,29 @@ static void draw_masklays(const bContext *C, Mask *mask, const char draw_flag, c
spline->points_deform = NULL;
draw_spline_curve(C, masklay, spline, draw_flag, draw_type, is_active, width, height);
-// draw_spline_parents(masklay, spline);
- draw_spline_points(C, masklay, spline, draw_flag, draw_type, xscale, yscale);
+ draw_spline_points(C, masklay, spline, draw_flag, draw_type);
spline->points_deform = back;
}
}
}
+
+ GPU_disable_program_point_size();
+ glDisable(GL_BLEND);
}
void ED_mask_draw(const bContext *C,
const char draw_flag, const char draw_type)
{
ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
-
Mask *mask = CTX_data_edit_mask(C);
int width, height;
- float aspx, aspy;
- float xscale, yscale;
if (!mask)
return;
ED_mask_get_size(sa, &width, &height);
- ED_mask_get_aspect(sa, ar, &aspx, &aspy);
- UI_view2d_scale_get(&ar->v2d, &xscale, &yscale);
- draw_masklays(C, mask, draw_flag, draw_type, width, height, xscale * aspx, yscale * aspy);
+ draw_masklays(C, mask, draw_flag, draw_type, width, height);
}
static float *mask_rasterize(Mask *mask, const int width, const int height)
@@ -733,28 +685,26 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar,
}
if (draw_flag & MASK_DRAWFLAG_OVERLAY) {
+ float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
float *buffer = mask_rasterize(mask, width, height);
- int format;
- if (overlay_mode == MASK_OVERLAY_ALPHACHANNEL) {
- glColor3f(1.0f, 1.0f, 1.0f);
- format = GL_LUMINANCE;
- }
- else {
+ if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
/* More blending types could be supported in the future. */
glEnable(GL_BLEND);
- glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
- format = GL_ALPHA;
+ glBlendFunc(GL_DST_COLOR, GL_ZERO);
}
- glPushMatrix();
- glTranslatef(x, y, 0);
- glScalef(zoomx, zoomy, 0);
+ gpuPushMatrix();
+ gpuTranslate2f(x, y);
+ gpuScale2f(zoomx, zoomy);
if (stabmat) {
- glMultMatrixf(stabmat);
+ gpuMultMatrix(stabmat);
}
- glaDrawPixelsTex(0.0f, 0.0f, width, height, format, GL_FLOAT, GL_NEAREST, buffer);
- glPopMatrix();
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
+ immDrawPixelsTex(&state, 0.0f, 0.0f, width, height, GL_RED, GL_FLOAT, GL_NEAREST, buffer, 1.0f, 1.0f, NULL);
+
+ gpuPopMatrix();
if (overlay_mode != MASK_OVERLAY_ALPHACHANNEL) {
glDisable(GL_BLEND);
@@ -764,26 +714,26 @@ void ED_mask_draw_region(Mask *mask, ARegion *ar,
}
/* apply transformation so mask editing tools will assume drawing from the origin in normalized space */
- glPushMatrix();
- glTranslatef(x + xofs, y + yofs, 0);
- glScalef(zoomx, zoomy, 0);
+ gpuPushMatrix();
+ gpuTranslate2f(x + xofs, y + yofs);
+ gpuScale2f(zoomx, zoomy);
if (stabmat) {
- glMultMatrixf(stabmat);
+ gpuMultMatrix(stabmat);
}
- glScalef(maxdim, maxdim, 0);
+ gpuScale2f(maxdim, maxdim);
if (do_draw_cb) {
ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
}
/* draw! */
- draw_masklays(C, mask, draw_flag, draw_type, width, height, maxdim * zoomx, maxdim * zoomy);
+ draw_masklays(C, mask, draw_flag, draw_type, width, height);
if (do_draw_cb) {
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
}
- glPopMatrix();
+ gpuPopMatrix();
}
void ED_mask_draw_frames(Mask *mask, ARegion *ar, const int cfra, const int sfra, const int efra)
@@ -792,25 +742,31 @@ void ED_mask_draw_frames(Mask *mask, ARegion *ar, const int cfra, const int sfra
MaskLayer *masklay = BKE_mask_layer_active(mask);
- glBegin(GL_LINES);
- glColor4ub(255, 175, 0, 255);
-
if (masklay) {
- MaskLayerShape *masklay_shape;
-
- for (masklay_shape = masklay->splines_shapes.first;
- masklay_shape;
- masklay_shape = masklay_shape->next)
- {
- int frame = masklay_shape->frame;
-
- /* draw_keyframe(i, CFRA, sfra, framelen, 1); */
- int height = (frame == cfra) ? 22 : 10;
- int x = (frame - sfra) * framelen;
- glVertex2i(x, 0);
- glVertex2i(x, height);
+ unsigned int num_lines = BLI_listbase_count(&masklay->splines_shapes);
+
+ if (num_lines > 0) {
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ub(255, 175, 0, 255);
+
+ immBegin(GWN_PRIM_LINES, 2 * num_lines);
+
+ for (MaskLayerShape *masklay_shape = masklay->splines_shapes.first;
+ masklay_shape;
+ masklay_shape = masklay_shape->next)
+ {
+ int frame = masklay_shape->frame;
+
+ /* draw_keyframe(i, CFRA, sfra, framelen, 1); */
+ int height = (frame == cfra) ? 22 : 10;
+ int x = (frame - sfra) * framelen;
+ immVertex2i(pos, x, 0);
+ immVertex2i(pos, x, height);
+ }
+ immEnd();
+ immUnbindProgram();
}
}
-
- glEnd();
}
diff --git a/source/blender/editors/mask/mask_ops.c b/source/blender/editors/mask/mask_ops.c
index 97d5ee1eff0..b6ac23a37e8 100644
--- a/source/blender/editors/mask/mask_ops.c
+++ b/source/blender/editors/mask/mask_ops.c
@@ -35,10 +35,11 @@
#include "BLI_math.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_mask.h"
+#include "DEG_depsgraph.h"
+
#include "DNA_scene_types.h"
#include "DNA_mask_types.h"
#include "DNA_object_types.h" /* SELECT */
@@ -1062,7 +1063,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
WM_event_add_notifier(C, NC_MASK | NA_EDITED, data->mask);
- DAG_id_tag_update(&data->mask->id, 0);
+ DEG_id_tag_update(&data->mask->id, 0);
break;
}
@@ -1089,7 +1090,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
WM_event_add_notifier(C, NC_MASK | NA_EDITED, data->mask);
- DAG_id_tag_update(&data->mask->id, 0);
+ DEG_id_tag_update(&data->mask->id, 0);
free_slide_point_data(op->customdata); /* keep this last! */
return OPERATOR_FINISHED;
@@ -1105,7 +1106,7 @@ static int slide_point_modal(bContext *C, wmOperator *op, const wmEvent *event)
cancel_slide_point(op->customdata);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, data->mask);
- DAG_id_tag_update(&data->mask->id, 0);
+ DEG_id_tag_update(&data->mask->id, 0);
free_slide_point_data(op->customdata); /* keep this last! */
return OPERATOR_CANCELLED;
@@ -1469,7 +1470,7 @@ static int slide_spline_curvature_modal(bContext *C, wmOperator *op, const wmEve
}
WM_event_add_notifier(C, NC_MASK | NA_EDITED, slide_data->mask);
- DAG_id_tag_update(&slide_data->mask->id, 0);
+ DEG_id_tag_update(&slide_data->mask->id, 0);
break;
}
@@ -1483,7 +1484,7 @@ static int slide_spline_curvature_modal(bContext *C, wmOperator *op, const wmEve
}
WM_event_add_notifier(C, NC_MASK | NA_EDITED, slide_data->mask);
- DAG_id_tag_update(&slide_data->mask->id, 0);
+ DEG_id_tag_update(&slide_data->mask->id, 0);
free_slide_spline_curvature_data(slide_data); /* keep this last! */
return OPERATOR_FINISHED;
@@ -1495,7 +1496,7 @@ static int slide_spline_curvature_modal(bContext *C, wmOperator *op, const wmEve
cancel_slide_spline_curvature(slide_data);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, slide_data->mask);
- DAG_id_tag_update(&slide_data->mask->id, 0);
+ DEG_id_tag_update(&slide_data->mask->id, 0);
free_slide_spline_curvature_data(op->customdata); /* keep this last! */
return OPERATOR_CANCELLED;
@@ -1541,7 +1542,7 @@ static int cyclic_toggle_exec(bContext *C, wmOperator *UNUSED(op))
}
}
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
WM_event_add_notifier(C, NC_MASK | NA_EDITED, mask);
return OPERATOR_FINISHED;
@@ -1900,7 +1901,7 @@ static int set_handle_type_exec(bContext *C, wmOperator *op)
if (changed) {
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
@@ -1955,7 +1956,7 @@ static int mask_hide_view_clear_exec(bContext *C, wmOperator *op)
if (changed) {
WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
@@ -2019,7 +2020,7 @@ static int mask_hide_view_set_exec(bContext *C, wmOperator *op)
if (changed) {
WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
@@ -2079,7 +2080,7 @@ static int mask_feather_weight_clear_exec(bContext *C, wmOperator *UNUSED(op))
BKE_mask_update_display(mask, CFRA);
WM_event_add_notifier(C, NC_MASK | ND_DRAW, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mask/mask_relationships.c b/source/blender/editors/mask/mask_relationships.c
index 4e0aa8f84ae..c500ec75aee 100644
--- a/source/blender/editors/mask/mask_relationships.c
+++ b/source/blender/editors/mask/mask_relationships.c
@@ -34,10 +34,11 @@
#include "BLI_string.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_mask.h"
#include "BKE_tracking.h"
+#include "DEG_depsgraph.h"
+
#include "DNA_mask_types.h"
#include "WM_api.h"
@@ -73,7 +74,7 @@ static int mask_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
}
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
@@ -176,7 +177,7 @@ static int mask_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
}
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mask/mask_shapekey.c b/source/blender/editors/mask/mask_shapekey.c
index 99ffc9cd7d2..3fb1cc87dbd 100644
--- a/source/blender/editors/mask/mask_shapekey.c
+++ b/source/blender/editors/mask/mask_shapekey.c
@@ -36,13 +36,14 @@
#include "BLI_math.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_mask.h"
#include "DNA_object_types.h"
#include "DNA_mask_types.h"
#include "DNA_scene_types.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -75,7 +76,7 @@ static int mask_shape_key_insert_exec(bContext *C, wmOperator *UNUSED(op))
if (changed) {
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
@@ -124,7 +125,7 @@ static int mask_shape_key_clear_exec(bContext *C, wmOperator *UNUSED(op))
if (changed) {
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&mask->id, OB_RECALC_DATA);
return OPERATOR_FINISHED;
}
@@ -216,7 +217,7 @@ static int mask_shape_key_feather_reset_exec(bContext *C, wmOperator *UNUSED(op)
if (changed) {
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
@@ -386,7 +387,7 @@ static int mask_shape_key_rekey_exec(bContext *C, wmOperator *op)
if (changed) {
WM_event_add_notifier(C, NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mesh/CMakeLists.txt b/source/blender/editors/mesh/CMakeLists.txt
index f1f0de3777e..1d861257397 100644
--- a/source/blender/editors/mesh/CMakeLists.txt
+++ b/source/blender/editors/mesh/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../bmesh
../../gpu
../../imbuf
@@ -31,6 +32,7 @@ set(INC
../../makesrna
../../render/extern/include
../../windowmanager
+ ../../../../intern/clog
../../../../intern/guardedalloc
../../../../intern/glew-mx
)
@@ -53,6 +55,7 @@ set(SRC
editmesh_knife_project.c
editmesh_loopcut.c
editmesh_path.c
+ editmesh_polybuild.c
editmesh_rip.c
editmesh_rip_edge.c
editmesh_select.c
@@ -67,18 +70,6 @@ set(SRC
mesh_intern.h
)
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-
- list(APPEND INC
- ../../../../extern/recastnavigation
- )
-
- list(APPEND SRC
- mesh_navmesh.c
- )
-endif()
-
if(WITH_INTERNATIONAL)
add_definitions(-DWITH_INTERNATIONAL)
endif()
diff --git a/source/blender/editors/mesh/editface.c b/source/blender/editors/mesh/editface.c
index c453284a617..6d1f478249a 100644
--- a/source/blender/editors/mesh/editface.c
+++ b/source/blender/editors/mesh/editface.c
@@ -51,7 +51,6 @@
#include "WM_types.h"
#include "GPU_draw.h"
-#include "GPU_buffers.h"
/* own include */
@@ -99,10 +98,7 @@ void paintface_flush_flags(Object *ob, short flag)
}
}
- if (flag & ME_HIDE) {
- /* draw-object caches hidden faces, force re-generation T46867 */
- GPU_drawobject_free(dm);
- }
+ BKE_mesh_batch_cache_dirty(me, BKE_MESH_BATCH_DIRTY_ALL);
}
void paintface_hide(Object *ob, const bool unselected)
@@ -384,7 +380,7 @@ bool paintface_mouse_select(struct bContext *C, Object *ob, const int mval[2], b
}
/* image window redraw */
-
+
paintface_flush_flags(ob, SELECT);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob->data);
ED_region_tag_redraw(CTX_wm_region(C)); // XXX - should redraw all 3D views
@@ -512,6 +508,8 @@ void paintvert_flush_flags(Object *ob)
dm_mv->flag = me->mvert[i].flag;
}
}
+
+ BKE_mesh_batch_cache_dirty(me, BKE_MESH_BATCH_DIRTY_ALL);
}
/* note: if the caller passes false to flush_flags, then they will need to run paintvert_flush_flags(ob) themselves */
void paintvert_deselect_all_visible(Object *ob, int action, bool flush_flags)
diff --git a/source/blender/editors/mesh/editmesh_add.c b/source/blender/editors/mesh/editmesh_add.c
index 22cb28f0b1b..292b28c772c 100644
--- a/source/blender/editors/mesh/editmesh_add.c
+++ b/source/blender/editors/mesh/editmesh_add.c
@@ -60,31 +60,36 @@
/* ********* add primitive operators ************* */
+typedef struct MakePrimitiveData {
+ float mat[4][4];
+ bool was_editmode;
+} MakePrimitiveData;
+
static Object *make_prim_init(
bContext *C, const char *idname,
- float *dia, float mat[4][4],
- bool *was_editmode, const float loc[3], const float rot[3], const unsigned int layer)
+ const float loc[3], const float rot[3], const unsigned int layer,
+ MakePrimitiveData *r_creation_data)
{
Object *obedit = CTX_data_edit_object(C);
- *was_editmode = false;
+ r_creation_data->was_editmode = false;
if (obedit == NULL || obedit->type != OB_MESH) {
obedit = ED_object_add_type(C, OB_MESH, idname, loc, rot, false, layer);
/* create editmode */
ED_object_editmode_enter(C, EM_DO_UNDO | EM_IGNORE_LAYER); /* rare cases the active layer is messed up */
- *was_editmode = true;
+ r_creation_data->was_editmode = true;
}
- *dia = ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
+ ED_object_new_primitive_matrix(C, obedit, loc, rot, r_creation_data->mat);
return obedit;
}
-static void make_prim_finish(bContext *C, Object *obedit, bool was_editmode, int enter_editmode)
+static void make_prim_finish(bContext *C, Object *obedit, const MakePrimitiveData *creation_data, int enter_editmode)
{
BMEditMesh *em = BKE_editmesh_from_object(obedit);
- const bool exit_editmode = ((was_editmode == true) && (enter_editmode == false));
+ const bool exit_editmode = ((creation_data->was_editmode == true) && (enter_editmode == false));
/* Primitive has all verts selected, use vert select flush
* to push this up to edges & faces. */
@@ -102,17 +107,17 @@ static void make_prim_finish(bContext *C, Object *obedit, bool was_editmode, int
static int add_primitive_plane_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
- bool was_editmode;
unsigned int layer;
const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs");
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Plane"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Plane"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -122,12 +127,12 @@ static int add_primitive_plane_exec(bContext *C, wmOperator *op)
if (!EDBM_op_call_and_selectf(
em, op, "verts.out", false,
"create_grid x_segments=%i y_segments=%i size=%f matrix=%m4 calc_uvs=%b",
- 1, 1, RNA_float_get(op->ptr, "radius"), mat, calc_uvs))
+ 1, 1, RNA_float_get(op->ptr, "radius"), creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -153,17 +158,17 @@ void MESH_OT_primitive_plane_add(wmOperatorType *ot)
static int add_primitive_cube_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
- bool was_editmode;
unsigned int layer;
const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs");
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Cube"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Cube"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -173,13 +178,13 @@ static int add_primitive_cube_exec(bContext *C, wmOperator *op)
if (!EDBM_op_call_and_selectf(
em, op, "verts.out", false,
"create_cube matrix=%m4 size=%f calc_uvs=%b",
- mat, RNA_float_get(op->ptr, "radius") * 2.0f, calc_uvs))
+ creation_data.mat, RNA_float_get(op->ptr, "radius") * 2.0f, calc_uvs))
{
return OPERATOR_CANCELLED;
}
/* BMESH_TODO make plane side this: M_SQRT2 - plane (diameter of 1.41 makes it unit size) */
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -211,13 +216,13 @@ static const EnumPropertyItem fill_type_items[] = {
static int add_primitive_circle_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
int cap_end, cap_tri;
unsigned int layer;
- bool was_editmode;
const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs");
cap_end = RNA_enum_get(op->ptr, "fill_type");
@@ -225,7 +230,7 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Circle"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Circle"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -236,12 +241,12 @@ static int add_primitive_circle_exec(bContext *C, wmOperator *op)
em, op, "verts.out", false,
"create_circle segments=%i radius=%f cap_ends=%b cap_tris=%b matrix=%m4 calc_uvs=%b",
RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius"),
- cap_end, cap_tri, mat, calc_uvs))
+ cap_end, cap_tri, creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -271,12 +276,12 @@ void MESH_OT_primitive_circle_add(wmOperatorType *ot)
static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
unsigned int layer;
- bool was_editmode;
const int end_fill_type = RNA_enum_get(op->ptr, "end_fill_type");
const bool cap_end = (end_fill_type != 0);
const bool cap_tri = (end_fill_type == 2);
@@ -284,7 +289,7 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Cylinder"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Cylinder"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -298,12 +303,12 @@ static int add_primitive_cylinder_exec(bContext *C, wmOperator *op)
RNA_float_get(op->ptr, "radius"),
RNA_float_get(op->ptr, "radius"),
cap_end, cap_tri,
- RNA_float_get(op->ptr, "depth"), mat, calc_uvs))
+ RNA_float_get(op->ptr, "depth"), creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -334,12 +339,12 @@ void MESH_OT_primitive_cylinder_add(wmOperatorType *ot)
static int add_primitive_cone_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
unsigned int layer;
- bool was_editmode;
const int end_fill_type = RNA_enum_get(op->ptr, "end_fill_type");
const bool cap_end = (end_fill_type != 0);
const bool cap_tri = (end_fill_type == 2);
@@ -347,7 +352,7 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Cone"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Cone"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -358,12 +363,13 @@ static int add_primitive_cone_exec(bContext *C, wmOperator *op)
em, op, "verts.out", false,
"create_cone segments=%i diameter1=%f diameter2=%f cap_ends=%b cap_tris=%b depth=%f matrix=%m4 calc_uvs=%b",
RNA_int_get(op->ptr, "vertices"), RNA_float_get(op->ptr, "radius1"),
- RNA_float_get(op->ptr, "radius2"), cap_end, cap_tri, RNA_float_get(op->ptr, "depth"), mat, calc_uvs))
+ RNA_float_get(op->ptr, "radius2"), cap_end, cap_tri, RNA_float_get(op->ptr, "depth"),
+ creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -395,17 +401,17 @@ void MESH_OT_primitive_cone_add(wmOperatorType *ot)
static int add_primitive_grid_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
- bool was_editmode;
unsigned int layer;
const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs");
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Grid"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Grid"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -417,12 +423,12 @@ static int add_primitive_grid_exec(bContext *C, wmOperator *op)
"create_grid x_segments=%i y_segments=%i size=%f matrix=%m4 calc_uvs=%b",
RNA_int_get(op->ptr, "x_subdivisions"),
RNA_int_get(op->ptr, "y_subdivisions"),
- RNA_float_get(op->ptr, "radius"), mat, calc_uvs))
+ RNA_float_get(op->ptr, "radius"), creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -454,22 +460,21 @@ void MESH_OT_primitive_grid_add(wmOperatorType *ot)
static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float mat[4][4];
float loc[3], rot[3];
float dia;
bool enter_editmode;
unsigned int layer;
- bool was_editmode;
const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs");
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Y', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Suzanne"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Suzanne"), loc, rot, layer, &creation_data);
dia = RNA_float_get(op->ptr, "radius");
- mul_mat3_m4_fl(mat, dia);
+ mul_mat3_m4_fl(creation_data.mat, dia);
em = BKE_editmesh_from_object(obedit);
@@ -479,12 +484,12 @@ static int add_primitive_monkey_exec(bContext *C, wmOperator *op)
if (!EDBM_op_call_and_selectf(
em, op, "verts.out", false,
- "create_monkey matrix=%m4 calc_uvs=%b", mat, calc_uvs))
+ "create_monkey matrix=%m4 calc_uvs=%b", creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -511,17 +516,17 @@ void MESH_OT_primitive_monkey_add(wmOperatorType *ot)
static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
- bool was_editmode;
unsigned int layer;
const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs");
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Sphere"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Sphere"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -532,12 +537,12 @@ static int add_primitive_uvsphere_exec(bContext *C, wmOperator *op)
em, op, "verts.out", false,
"create_uvsphere u_segments=%i v_segments=%i diameter=%f matrix=%m4 calc_uvs=%b",
RNA_int_get(op->ptr, "segments"), RNA_int_get(op->ptr, "ring_count"),
- RNA_float_get(op->ptr, "size"), mat, calc_uvs))
+ RNA_float_get(op->ptr, "size"), creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
@@ -567,17 +572,17 @@ void MESH_OT_primitive_uv_sphere_add(wmOperatorType *ot)
static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
{
+ MakePrimitiveData creation_data;
Object *obedit;
BMEditMesh *em;
- float loc[3], rot[3], mat[4][4], dia;
+ float loc[3], rot[3];
bool enter_editmode;
- bool was_editmode;
unsigned int layer;
const bool calc_uvs = RNA_boolean_get(op->ptr, "calc_uvs");
WM_operator_view3d_unit_defaults(C, op);
ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL);
- obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Icosphere"), &dia, mat, &was_editmode, loc, rot, layer);
+ obedit = make_prim_init(C, CTX_DATA_(BLT_I18NCONTEXT_ID_MESH, "Icosphere"), loc, rot, layer, &creation_data);
em = BKE_editmesh_from_object(obedit);
if (calc_uvs) {
@@ -588,12 +593,12 @@ static int add_primitive_icosphere_exec(bContext *C, wmOperator *op)
em, op, "verts.out", false,
"create_icosphere subdivisions=%i diameter=%f matrix=%m4 calc_uvs=%b",
RNA_int_get(op->ptr, "subdivisions"),
- RNA_float_get(op->ptr, "size"), mat, calc_uvs))
+ RNA_float_get(op->ptr, "size"), creation_data.mat, calc_uvs))
{
return OPERATOR_CANCELLED;
}
- make_prim_finish(C, obedit, was_editmode, enter_editmode);
+ make_prim_finish(C, obedit, &creation_data, enter_editmode);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mesh/editmesh_bevel.c b/source/blender/editors/mesh/editmesh_bevel.c
index c8d33a9cc60..ca5af7a535d 100644
--- a/source/blender/editors/mesh/editmesh_bevel.c
+++ b/source/blender/editors/mesh/editmesh_bevel.c
@@ -87,7 +87,7 @@ typedef struct {
float mcenter[2];
BMBackup mesh_backup;
void *draw_handle_pixel;
- short twtype;
+ short twflag;
short value_mode; /* Which value does mouse movement and numeric input affect? */
float segments; /* Segments as float so smooth mouse pan works in small increments */
} BevelData;
@@ -180,8 +180,8 @@ static bool edbm_bevel_init(bContext *C, wmOperator *op, const bool is_modal)
G.moving = G_TRANSFORM_EDIT;
if (v3d) {
- opdata->twtype = v3d->twtype;
- v3d->twtype = 0;
+ opdata->twflag = v3d->twflag;
+ v3d->twflag = 0;
}
}
@@ -254,7 +254,7 @@ static void edbm_bevel_exit(bContext *C, wmOperator *op)
EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
if (v3d) {
- v3d->twtype = opdata->twtype;
+ v3d->twflag = opdata->twflag;
}
G.moving = 0;
}
diff --git a/source/blender/editors/mesh/editmesh_bisect.c b/source/blender/editors/mesh/editmesh_bisect.c
index 3a9e278f039..ac8c1f16477 100644
--- a/source/blender/editors/mesh/editmesh_bisect.c
+++ b/source/blender/editors/mesh/editmesh_bisect.c
@@ -50,9 +50,17 @@
#include "ED_screen.h"
#include "ED_view3d.h"
+#include "UI_resources.h"
#include "mesh_intern.h" /* own include */
+#define USE_MANIPULATOR
+
+#ifdef USE_MANIPULATOR
+#include "ED_manipulator_library.h"
+#include "ED_undo.h"
+#endif
+
static int mesh_bisect_exec(bContext *C, wmOperator *op);
/* -------------------------------------------------------------------- */
@@ -62,7 +70,7 @@ typedef struct {
/* modal only */
BMBackup mesh_backup;
bool is_first;
- short twtype;
+ short twflag;
} BisectData;
static bool mesh_bisect_interactive_calc(
@@ -148,8 +156,8 @@ static int mesh_bisect_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* misc other vars */
G.moving = G_TRANSFORM_EDIT;
- opdata->twtype = v3d->twtype;
- v3d->twtype = 0;
+ opdata->twflag = v3d->twflag;
+ v3d->twflag = 0;
/* initialize modal callout */
ED_area_headerprint(CTX_wm_area(C), IFACE_("LMB: Click and drag to draw cut line"));
@@ -161,7 +169,7 @@ static void edbm_bisect_exit(bContext *C, BisectData *opdata)
{
View3D *v3d = CTX_wm_view3d(C);
EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
- v3d->twtype = opdata->twtype;
+ v3d->twflag = opdata->twflag;
G.moving = 0;
}
@@ -186,6 +194,16 @@ static int mesh_bisect_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (ret & (OPERATOR_FINISHED | OPERATOR_CANCELLED)) {
edbm_bisect_exit(C, &opdata_back);
+
+#ifdef USE_MANIPULATOR
+ /* Setup manipulators */
+ {
+ View3D *v3d = CTX_wm_view3d(C);
+ if (v3d && (v3d->twflag & V3D_MANIPULATOR_DRAW)) {
+ WM_manipulator_group_type_ensure("MESH_WGT_bisect");
+ }
+ }
+#endif
}
return ret;
@@ -315,6 +333,9 @@ static int mesh_bisect_exec(bContext *C, wmOperator *op)
}
}
+#ifdef USE_MANIPULATOR
+static void MESH_WGT_bisect(struct wmManipulatorGroupType *wgt);
+#endif
void MESH_OT_bisect(struct wmOperatorType *ot)
{
@@ -350,4 +371,331 @@ void MESH_OT_bisect(struct wmOperatorType *ot)
RNA_def_float(ot->srna, "threshold", 0.0001, 0.0, 10.0, "Axis Threshold", "", 0.00001, 0.1);
WM_operator_properties_gesture_straightline(ot, CURSOR_EDIT);
+
+#ifdef USE_MANIPULATOR
+ WM_manipulatorgrouptype_append(MESH_WGT_bisect);
+#endif
+}
+
+
+#ifdef USE_MANIPULATOR
+
+/* -------------------------------------------------------------------- */
+
+/** \name Bisect Manipulator
+ * \{ */
+
+typedef struct ManipulatorGroup {
+ /* Arrow to change plane depth. */
+ struct wmManipulator *translate_z;
+ /* Translate XYZ */
+ struct wmManipulator *translate_c;
+ /* For grabbing the manipulator and moving freely. */
+ struct wmManipulator *rotate_c;
+
+ /* We could store more vars here! */
+ struct {
+ bContext *context;
+ wmOperator *op;
+ PropertyRNA *prop_plane_co;
+ PropertyRNA *prop_plane_no;
+
+ float rotate_axis[3];
+ float rotate_up[3];
+ } data;
+} ManipulatorGroup;
+
+/**
+ * XXX. calling redo from property updates is not great.
+ * This is needed because changing the RNA doesn't cause a redo
+ * and we're not using operator UI which does just this.
+ */
+static void manipulator_bisect_exec(ManipulatorGroup *man)
+{
+ wmOperator *op = man->data.op;
+ if (op == WM_operator_last_redo((bContext *)man->data.context)) {
+ ED_undo_operator_repeat((bContext *)man->data.context, op);
+ }
+}
+
+static void manipulator_mesh_bisect_update_from_op(ManipulatorGroup *man)
+{
+ wmOperator *op = man->data.op;
+
+ float plane_co[3], plane_no[3];
+
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_co, plane_co);
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_no, plane_no);
+
+ WM_manipulator_set_matrix_location(man->translate_z, plane_co);
+ WM_manipulator_set_matrix_location(man->rotate_c, plane_co);
+ /* translate_c location comes from the property. */
+
+ WM_manipulator_set_matrix_rotation_from_z_axis(man->translate_z, plane_no);
+
+ WM_manipulator_set_scale(man->translate_c, 0.2);
+
+ RegionView3D *rv3d = ED_view3d_context_rv3d(man->data.context);
+ if (rv3d) {
+ normalize_v3_v3(man->data.rotate_axis, rv3d->viewinv[2]);
+ normalize_v3_v3(man->data.rotate_up, rv3d->viewinv[1]);
+
+ /* ensure its orthogonal */
+ project_plane_normalized_v3_v3v3(man->data.rotate_up, man->data.rotate_up, man->data.rotate_axis);
+ normalize_v3(man->data.rotate_up);
+
+ WM_manipulator_set_matrix_rotation_from_z_axis(man->translate_c, plane_no);
+
+ float plane_no_cross[3];
+ cross_v3_v3v3(plane_no_cross, plane_no, man->data.rotate_axis);
+
+ WM_manipulator_set_matrix_offset_rotation_from_yz_axis(man->rotate_c, plane_no_cross, man->data.rotate_axis);
+ RNA_enum_set(man->rotate_c->ptr, "draw_options",
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_MIRROR |
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_START_Y);
+ }
+}
+
+/* depth callbacks */
+static void manipulator_bisect_prop_depth_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ ManipulatorGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_co[3], plane_no[3];
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_co, plane_co);
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_no, plane_no);
+
+ value[0] = dot_v3v3(plane_no, plane_co) - dot_v3v3(plane_no, mpr->matrix_basis[3]);
+}
+
+static void manipulator_bisect_prop_depth_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ ManipulatorGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ const float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_co[3], plane[4];
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_co, plane_co);
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_no, plane);
+ normalize_v3(plane);
+
+ plane[3] = -value[0] - dot_v3v3(plane, mpr->matrix_basis[3]);
+
+ /* Keep our location, may be offset simply to be inside the viewport. */
+ closest_to_plane_normalized_v3(plane_co, plane, plane_co);
+
+ RNA_property_float_set_array(op->ptr, man->data.prop_plane_co, plane_co);
+
+ manipulator_bisect_exec(man);
+}
+
+/* translate callbacks */
+static void manipulator_bisect_prop_translate_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ ManipulatorGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+
+ BLI_assert(mpr_prop->type->array_length == 3);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_co, value_p);
+}
+
+static void manipulator_bisect_prop_translate_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ ManipulatorGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+
+ BLI_assert(mpr_prop->type->array_length == 3);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ RNA_property_float_set_array(op->ptr, man->data.prop_plane_co, value_p);
+
+ manipulator_bisect_exec(man);
+}
+
+/* angle callbacks */
+static void manipulator_bisect_prop_angle_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ ManipulatorGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_no[4];
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_no, plane_no);
+ normalize_v3(plane_no);
+
+ float plane_no_proj[3];
+ project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, man->data.rotate_axis);
+
+ if (!is_zero_v3(plane_no_proj)) {
+ const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, man->data.rotate_up, man->data.rotate_axis);
+ value[0] = angle;
+ }
+ else {
+ value[0] = 0.0f;
+ }
+}
+
+static void manipulator_bisect_prop_angle_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ ManipulatorGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ const float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_no[4];
+ RNA_property_float_get_array(op->ptr, man->data.prop_plane_no, plane_no);
+ normalize_v3(plane_no);
+
+ float plane_no_proj[3];
+ project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, man->data.rotate_axis);
+
+ if (!is_zero_v3(plane_no_proj)) {
+ const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, man->data.rotate_up, man->data.rotate_axis);
+ const float angle_delta = angle - angle_compat_rad(value[0], angle);
+ if (angle_delta != 0.0f) {
+ float mat[3][3];
+ axis_angle_normalized_to_mat3(mat, man->data.rotate_axis, angle_delta);
+ mul_m3_v3(mat, plane_no);
+
+ /* re-normalize - seems acceptable */
+ RNA_property_float_set_array(op->ptr, man->data.prop_plane_no, plane_no);
+
+ manipulator_bisect_exec(man);
+ }
+ }
+}
+
+static bool manipulator_mesh_bisect_poll(const bContext *C, wmManipulatorGroupType *wgt)
+{
+ wmOperator *op = WM_operator_last_redo(C);
+ if (op == NULL || !STREQ(op->type->idname, "MESH_OT_bisect")) {
+ WM_manipulator_group_type_unlink_delayed_ptr(wgt);
+ return false;
+ }
+ return true;
}
+
+static void manipulator_mesh_bisect_setup(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmOperator *op = WM_operator_last_redo(C);
+
+ if (op == NULL || !STREQ(op->type->idname, "MESH_OT_bisect")) {
+ return;
+ }
+
+ struct ManipulatorGroup *man = MEM_callocN(sizeof(ManipulatorGroup), __func__);
+ mgroup->customdata = man;
+
+ const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true);
+ const wmManipulatorType *wt_grab = WM_manipulatortype_find("MANIPULATOR_WT_grab_3d", true);
+ const wmManipulatorType *wt_dial = WM_manipulatortype_find("MANIPULATOR_WT_dial_3d", true);
+
+ man->translate_z = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ man->translate_c = WM_manipulator_new_ptr(wt_grab, mgroup, NULL);
+ man->rotate_c = WM_manipulator_new_ptr(wt_dial, mgroup, NULL);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, man->translate_z->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, man->translate_c->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_SECONDARY, man->rotate_c->color);
+
+ RNA_enum_set(man->translate_z->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_NORMAL);
+ RNA_enum_set(man->translate_c->ptr, "draw_style", ED_MANIPULATOR_GRAB_STYLE_RING_2D);
+
+ WM_manipulator_set_flag(man->translate_c, WM_MANIPULATOR_DRAW_VALUE, true);
+ WM_manipulator_set_flag(man->rotate_c, WM_MANIPULATOR_DRAW_VALUE, true);
+
+ {
+ man->data.context = (bContext *)C;
+ man->data.op = op;
+ man->data.prop_plane_co = RNA_struct_find_property(op->ptr, "plane_co");
+ man->data.prop_plane_no = RNA_struct_find_property(op->ptr, "plane_no");
+ }
+
+ manipulator_mesh_bisect_update_from_op(man);
+
+ /* Setup property callbacks */
+ {
+ WM_manipulator_target_property_def_func(
+ man->translate_z, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_bisect_prop_depth_get,
+ .value_set_fn = manipulator_bisect_prop_depth_set,
+ .range_get_fn = NULL,
+ .user_data = NULL,
+ });
+
+ WM_manipulator_target_property_def_func(
+ man->translate_c, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_bisect_prop_translate_get,
+ .value_set_fn = manipulator_bisect_prop_translate_set,
+ .range_get_fn = NULL,
+ .user_data = NULL,
+ });
+
+ WM_manipulator_target_property_def_func(
+ man->rotate_c, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_bisect_prop_angle_get,
+ .value_set_fn = manipulator_bisect_prop_angle_set,
+ .range_get_fn = NULL,
+ .user_data = NULL,
+ });
+ }
+}
+
+static void manipulator_mesh_bisect_draw_prepare(
+ const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ ManipulatorGroup *man = mgroup->customdata;
+ if (man->data.op->next) {
+ man->data.op = WM_operator_last_redo((bContext *)man->data.context);
+ }
+ manipulator_mesh_bisect_update_from_op(man);
+}
+
+static void MESH_WGT_bisect(struct wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Mesh Bisect";
+ wgt->idname = "MESH_WGT_bisect";
+
+ wgt->flag = WM_MANIPULATORGROUPTYPE_3D;
+
+ wgt->mmap_params.spaceid = SPACE_VIEW3D;
+ wgt->mmap_params.regionid = RGN_TYPE_WINDOW;
+
+ wgt->poll = manipulator_mesh_bisect_poll;
+ wgt->setup = manipulator_mesh_bisect_setup;
+ wgt->draw_prepare = manipulator_mesh_bisect_draw_prepare;
+}
+
+/** \} */
+
+#endif /* USE_MANIPULATOR */
diff --git a/source/blender/editors/mesh/editmesh_extrude.c b/source/blender/editors/mesh/editmesh_extrude.c
index 9467c545bbf..51ee8223f0c 100644
--- a/source/blender/editors/mesh/editmesh_extrude.c
+++ b/source/blender/editors/mesh/editmesh_extrude.c
@@ -35,6 +35,7 @@
#include "BLI_math.h"
#include "BLI_listbase.h"
+#include "BKE_layer.h"
#include "BKE_context.h"
#include "BKE_report.h"
#include "BKE_editmesh.h"
@@ -42,15 +43,23 @@
#include "RNA_define.h"
#include "RNA_access.h"
+#include "WM_api.h"
#include "WM_types.h"
#include "ED_mesh.h"
#include "ED_screen.h"
#include "ED_transform.h"
#include "ED_view3d.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
#include "mesh_intern.h" /* own include */
+#define USE_MANIPULATOR
+
/* -------------------------------------------------------------------- */
/** \name Extrude Internal Utilities
* \{ */
@@ -338,6 +347,146 @@ void MESH_OT_extrude_repeat(wmOperatorType *ot)
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Extrude Manipulator
+ * \{ */
+
+#ifdef USE_MANIPULATOR
+
+typedef struct ManipulatorExtrudeGroup {
+ /* Extrude . */
+ struct wmManipulator *axis_arrow;
+ /* Redo Z-axis translation. */
+ struct wmManipulator *axis_redo;
+} ManipulatorExtrudeGroup;
+
+static bool manipulator_mesh_extrude_poll(const bContext *C, wmManipulatorGroupType *wgt)
+{
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ if (!STREQ(workspace->tool.manipulator_group, "MESH_WGT_extrude") ||
+ !ED_operator_editmesh_view3d((bContext *)C))
+ {
+ WM_manipulator_group_type_unlink_delayed_ptr(wgt);
+ return false;
+ }
+ return true;
+}
+
+static void manipulator_mesh_extrude_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ const int constraint_z[3] = {0, 0, 1};
+
+ struct ManipulatorExtrudeGroup *man = MEM_callocN(sizeof(ManipulatorExtrudeGroup), __func__);
+ mgroup->customdata = man;
+
+ const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true);
+ const wmManipulatorType *wt_grab = WM_manipulatortype_find("MANIPULATOR_WT_grab_3d", true);
+
+ man->axis_arrow = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ man->axis_redo = WM_manipulator_new_ptr(wt_grab, mgroup, NULL);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, man->axis_arrow->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_SECONDARY, man->axis_redo->color);
+
+ WM_manipulator_set_scale(man->axis_arrow, 2.0);
+ WM_manipulator_set_scale(man->axis_redo, 2.0);
+
+ RNA_enum_set(man->axis_arrow->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_NORMAL);
+ RNA_enum_set(man->axis_redo->ptr, "draw_style", ED_MANIPULATOR_GRAB_STYLE_RING_2D);
+
+ WM_manipulator_set_flag(man->axis_redo, WM_MANIPULATOR_DRAW_VALUE, true);
+
+ /* New extrude. */
+ {
+ wmOperatorType *ot = WM_operatortype_find("MESH_OT_extrude_region_move", true);
+ PointerRNA *ptr = WM_manipulator_operator_set(man->axis_arrow, 0, ot, NULL);
+ {
+ PointerRNA macroptr = RNA_pointer_get(ptr, "TRANSFORM_OT_translate");
+ RNA_boolean_set(&macroptr, "release_confirm", true);
+ RNA_boolean_set_array(&macroptr, "constraint_axis", constraint_z);
+ }
+ }
+ /* Adjust extrude. */
+ {
+ wmOperatorType *ot = WM_operatortype_find("MESH_OT_extrude_region_move", true);
+ PointerRNA *ptr = WM_manipulator_operator_set(man->axis_redo, 0, ot, NULL);
+ {
+ PointerRNA macroptr = RNA_pointer_get(ptr, "TRANSFORM_OT_translate");
+ RNA_boolean_set(&macroptr, "release_confirm", true);
+ RNA_boolean_set_array(&macroptr, "constraint_axis", constraint_z);
+ }
+ wmManipulatorOpElem *mpop = WM_manipulator_operator_get(man->axis_redo, 0);
+ mpop->is_redo = true;
+ }
+}
+
+static void manipulator_mesh_extrude_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ManipulatorExtrudeGroup *man = mgroup->customdata;
+
+ WM_manipulator_set_flag(man->axis_arrow, WM_MANIPULATOR_HIDDEN, true);
+ WM_manipulator_set_flag(man->axis_redo, WM_MANIPULATOR_HIDDEN, true);
+
+ struct TransformBounds tbounds;
+ if (!ED_transform_calc_manipulator_stats(C, false, &tbounds)) {
+ return;
+ }
+
+ /* Needed for normal orientation. */
+ copy_m4_m3(man->axis_arrow->matrix_basis, tbounds.axis);
+ copy_m4_m3(man->axis_redo->matrix_basis, tbounds.axis);
+
+ WM_manipulator_set_matrix_location(man->axis_arrow, tbounds.center);
+ WM_manipulator_set_matrix_location(man->axis_redo, tbounds.center);
+
+ wmOperator *op = WM_operator_last_redo(C);
+ bool has_redo = (op && STREQ(op->type->idname, "MESH_OT_extrude_region_move"));
+
+ WM_manipulator_set_flag(man->axis_arrow, WM_MANIPULATOR_HIDDEN, false);
+ WM_manipulator_set_flag(man->axis_redo, WM_MANIPULATOR_HIDDEN, !has_redo);
+
+ /* Redo with current settings. */
+ if (has_redo) {
+ /* We could also access this from 'ot->last_properties' */
+
+ wmOperator *op_transform = op->macro.last;
+ wmManipulatorOpElem *mpop = WM_manipulator_operator_get(man->axis_redo, 0);
+
+ PointerRNA macroptr = RNA_pointer_get(&mpop->ptr, "TRANSFORM_OT_translate");
+
+ float value[4];
+ RNA_float_get_array(op_transform->ptr, "value", value);
+ RNA_float_set_array(&macroptr, "value", value);
+
+ /* Currently has glitch in re-applying. */
+#if 0
+ int constraint_axis[3];
+ RNA_boolean_get_array(op_transform->ptr, "constraint_axis", constraint_axis);
+ RNA_boolean_set_array(&macroptr, "constraint_axis", constraint_axis);
+#endif
+ }
+}
+
+static void MESH_WGT_extrude(struct wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Mesh Extrude";
+ wgt->idname = "MESH_WGT_extrude";
+
+ wgt->flag = WM_MANIPULATORGROUPTYPE_3D;
+
+ wgt->mmap_params.spaceid = SPACE_VIEW3D;
+ wgt->mmap_params.regionid = RGN_TYPE_WINDOW;
+
+ wgt->poll = manipulator_mesh_extrude_poll;
+ wgt->setup = manipulator_mesh_extrude_setup;
+ wgt->refresh = manipulator_mesh_extrude_refresh;
+}
+
+#endif /* USE_MANIPULATOR */
+
+/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Extrude Operator
* \{ */
@@ -391,18 +540,26 @@ static bool edbm_extrude_mesh(Object *obedit, BMEditMesh *em, wmOperator *op)
/* extrude without transform */
static int edbm_extrude_region_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
-
- edbm_extrude_mesh(obedit, em, op);
-
- /* This normally happens when pushing undo but modal operators
- * like this one don't push undo data until after modal mode is
- * done.*/
- EDBM_mesh_normals_update(em);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totvertsel == 0) {
+ continue;
+ }
- EDBM_update_generic(em, true, true);
+ edbm_extrude_mesh(obedit, em, op);
+ /* This normally happens when pushing undo but modal operators
+ * like this one don't push undo data until after modal mode is
+ * done.*/
+ EDBM_mesh_normals_update(em);
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -422,6 +579,10 @@ void MESH_OT_extrude_region(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
Transform_Properties(ot, P_NO_DEFAULTS | P_MIRROR_DUMMY);
+
+#ifdef USE_MANIPULATOR
+ WM_manipulatorgrouptype_append(MESH_WGT_extrude);
+#endif
}
/** \} */
@@ -432,12 +593,22 @@ void MESH_OT_extrude_region(wmOperatorType *ot)
static int edbm_extrude_verts_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totvertsel == 0) {
+ continue;
+ }
- edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT);
+ edbm_extrude_verts_indiv(em, op, BM_ELEM_SELECT);
- EDBM_update_generic(em, true, true);
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -468,12 +639,22 @@ void MESH_OT_extrude_verts_indiv(wmOperatorType *ot)
static int edbm_extrude_edges_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totedgesel == 0) {
+ continue;
+ }
- edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT);
+ edbm_extrude_edges_indiv(em, op, BM_ELEM_SELECT);
- EDBM_update_generic(em, true, true);
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -504,12 +685,22 @@ void MESH_OT_extrude_edges_indiv(wmOperatorType *ot)
static int edbm_extrude_faces_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
- edbm_extrude_discrete_faces(em, op, BM_ELEM_SELECT);
+ edbm_extrude_discrete_faces(em, op, BM_ELEM_SELECT);
- EDBM_update_generic(em, true, true);
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -723,4 +914,3 @@ void MESH_OT_dupli_extrude_cursor(wmOperatorType *ot)
}
/** \} */
-
diff --git a/source/blender/editors/mesh/editmesh_extrude_screw.c b/source/blender/editors/mesh/editmesh_extrude_screw.c
index ffbbae60949..debab7edf21 100644
--- a/source/blender/editors/mesh/editmesh_extrude_screw.c
+++ b/source/blender/editors/mesh/editmesh_extrude_screw.c
@@ -46,6 +46,8 @@
#include "ED_screen.h"
#include "ED_view3d.h"
+
+
#include "mesh_intern.h" /* own include */
/* -------------------------------------------------------------------- */
diff --git a/source/blender/editors/mesh/editmesh_extrude_spin.c b/source/blender/editors/mesh/editmesh_extrude_spin.c
index 4cd3b033ca7..a4106ebcde1 100644
--- a/source/blender/editors/mesh/editmesh_extrude_spin.c
+++ b/source/blender/editors/mesh/editmesh_extrude_spin.c
@@ -40,14 +40,395 @@
#include "RNA_define.h"
#include "RNA_access.h"
+#include "WM_api.h"
#include "WM_types.h"
#include "ED_mesh.h"
#include "ED_screen.h"
#include "ED_view3d.h"
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
+
#include "mesh_intern.h" /* own include */
+#define USE_MANIPULATOR
+
+#ifdef USE_MANIPULATOR
+#include "ED_manipulator_library.h"
+#include "ED_undo.h"
+#endif
+
+/* -------------------------------------------------------------------- */
+/** \name Spin Manipulator
+ * \{ */
+
+#ifdef USE_MANIPULATOR
+typedef struct ManipulatorSpinGroup {
+ /* Arrow to change plane depth. */
+ struct wmManipulator *translate_z;
+ /* Translate XYZ */
+ struct wmManipulator *translate_c;
+ /* For grabbing the manipulator and moving freely. */
+ struct wmManipulator *rotate_c;
+ /* Spin angle */
+ struct wmManipulator *angle_z;
+
+ /* We could store more vars here! */
+ struct {
+ bContext *context;
+ wmOperator *op;
+ PropertyRNA *prop_axis_co;
+ PropertyRNA *prop_axis_no;
+ PropertyRNA *prop_angle;
+
+ float rotate_axis[3];
+ float rotate_up[3];
+ } data;
+} ManipulatorSpinGroup;
+
+/**
+ * XXX. calling redo from property updates is not great.
+ * This is needed because changing the RNA doesn't cause a redo
+ * and we're not using operator UI which does just this.
+ */
+static void manipulator_spin_exec(ManipulatorSpinGroup *man)
+{
+ wmOperator *op = man->data.op;
+ if (op == WM_operator_last_redo((bContext *)man->data.context)) {
+ ED_undo_operator_repeat((bContext *)man->data.context, op);
+ }
+}
+
+static void manipulator_mesh_spin_update_from_op(ManipulatorSpinGroup *man)
+{
+ wmOperator *op = man->data.op;
+
+ float plane_co[3], plane_no[3];
+
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_co, plane_co);
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_no, plane_no);
+
+ WM_manipulator_set_matrix_location(man->translate_z, plane_co);
+ WM_manipulator_set_matrix_location(man->rotate_c, plane_co);
+ WM_manipulator_set_matrix_location(man->angle_z, plane_co);
+ /* translate_c location comes from the property. */
+
+ WM_manipulator_set_matrix_rotation_from_z_axis(man->translate_z, plane_no);
+ WM_manipulator_set_matrix_rotation_from_z_axis(man->angle_z, plane_no);
+
+ WM_manipulator_set_scale(man->translate_c, 0.2);
+
+ RegionView3D *rv3d = ED_view3d_context_rv3d(man->data.context);
+ if (rv3d) {
+ normalize_v3_v3(man->data.rotate_axis, rv3d->viewinv[2]);
+ normalize_v3_v3(man->data.rotate_up, rv3d->viewinv[1]);
+
+ /* ensure its orthogonal */
+ project_plane_normalized_v3_v3v3(man->data.rotate_up, man->data.rotate_up, man->data.rotate_axis);
+ normalize_v3(man->data.rotate_up);
+
+ WM_manipulator_set_matrix_rotation_from_z_axis(man->translate_c, plane_no);
+ WM_manipulator_set_matrix_rotation_from_yz_axis(man->rotate_c, plane_no, man->data.rotate_axis);
+
+ /* show the axis instead of mouse cursor */
+ RNA_enum_set(man->rotate_c->ptr, "draw_options",
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_MIRROR |
+ ED_MANIPULATOR_DIAL_DRAW_FLAG_ANGLE_START_Y);
+
+ }
+}
+
+/* depth callbacks */
+static void manipulator_spin_prop_depth_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_co[3], plane_no[3];
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_co, plane_co);
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_no, plane_no);
+
+ value[0] = dot_v3v3(plane_no, plane_co) - dot_v3v3(plane_no, mpr->matrix_basis[3]);
+}
+
+static void manipulator_spin_prop_depth_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ const float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_co[3], plane[4];
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_co, plane_co);
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_no, plane);
+ normalize_v3(plane);
+
+ plane[3] = -value[0] - dot_v3v3(plane, mpr->matrix_basis[3]);
+
+ /* Keep our location, may be offset simply to be inside the viewport. */
+ closest_to_plane_normalized_v3(plane_co, plane, plane_co);
+
+ RNA_property_float_set_array(op->ptr, man->data.prop_axis_co, plane_co);
+
+ manipulator_spin_exec(man);
+}
+
+/* translate callbacks */
+static void manipulator_spin_prop_translate_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 3);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_co, value);
+}
+
+static void manipulator_spin_prop_translate_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+
+ BLI_assert(mpr_prop->type->array_length == 3);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ RNA_property_float_set_array(op->ptr, man->data.prop_axis_co, value);
+
+ manipulator_spin_exec(man);
+}
+
+/* angle callbacks */
+static void manipulator_spin_prop_axis_angle_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_no[4];
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_no, plane_no);
+ normalize_v3(plane_no);
+
+ float plane_no_proj[3];
+ project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, man->data.rotate_axis);
+
+ if (!is_zero_v3(plane_no_proj)) {
+ const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, man->data.rotate_up, man->data.rotate_axis);
+ value[0] = angle;
+ }
+ else {
+ value[0] = 0.0f;
+ }
+}
+
+static void manipulator_spin_prop_axis_angle_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ const float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+
+ float plane_no[4];
+ RNA_property_float_get_array(op->ptr, man->data.prop_axis_no, plane_no);
+ normalize_v3(plane_no);
+
+ float plane_no_proj[3];
+ project_plane_normalized_v3_v3v3(plane_no_proj, plane_no, man->data.rotate_axis);
+
+ if (!is_zero_v3(plane_no_proj)) {
+ const float angle = -angle_signed_on_axis_v3v3_v3(plane_no_proj, man->data.rotate_up, man->data.rotate_axis);
+ const float angle_delta = angle - angle_compat_rad(value[0], angle);
+ if (angle_delta != 0.0f) {
+ float mat[3][3];
+ axis_angle_normalized_to_mat3(mat, man->data.rotate_axis, angle_delta);
+ mul_m3_v3(mat, plane_no);
+
+ /* re-normalize - seems acceptable */
+ RNA_property_float_set_array(op->ptr, man->data.prop_axis_no, plane_no);
+
+ manipulator_spin_exec(man);
+ }
+ }
+}
+
+/* angle callbacks */
+static void manipulator_spin_prop_angle_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+ value[0] = RNA_property_float_get(op->ptr, man->data.prop_angle);
+}
+
+static void manipulator_spin_prop_angle_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ ManipulatorSpinGroup *man = mpr->parent_mgroup->customdata;
+ wmOperator *op = man->data.op;
+ BLI_assert(mpr_prop->type->array_length == 1);
+ UNUSED_VARS_NDEBUG(mpr_prop);
+ const float *value = value_p;
+ RNA_property_float_set(op->ptr, man->data.prop_angle, value[0]);
+
+ manipulator_spin_exec(man);
+}
+
+static bool manipulator_mesh_spin_poll(const bContext *C, wmManipulatorGroupType *wgt)
+{
+ wmOperator *op = WM_operator_last_redo(C);
+ if (op == NULL || !STREQ(op->type->idname, "MESH_OT_spin")) {
+ WM_manipulator_group_type_unlink_delayed_ptr(wgt);
+ return false;
+ }
+ return true;
+}
+
+static void manipulator_mesh_spin_setup(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmOperator *op = WM_operator_last_redo(C);
+
+ if (op == NULL || !STREQ(op->type->idname, "MESH_OT_spin")) {
+ return;
+ }
+
+ struct ManipulatorSpinGroup *man = MEM_callocN(sizeof(ManipulatorSpinGroup), __func__);
+ mgroup->customdata = man;
+
+ const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true);
+ const wmManipulatorType *wt_grab = WM_manipulatortype_find("MANIPULATOR_WT_grab_3d", true);
+ const wmManipulatorType *wt_dial = WM_manipulatortype_find("MANIPULATOR_WT_dial_3d", true);
+
+ man->translate_z = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ man->translate_c = WM_manipulator_new_ptr(wt_grab, mgroup, NULL);
+ man->rotate_c = WM_manipulator_new_ptr(wt_dial, mgroup, NULL);
+ man->angle_z = WM_manipulator_new_ptr(wt_dial, mgroup, NULL);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, man->translate_z->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, man->translate_c->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_SECONDARY, man->rotate_c->color);
+ UI_GetThemeColor3fv(TH_AXIS_Z, man->angle_z->color);
+
+
+ RNA_enum_set(man->translate_z->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_NORMAL);
+ RNA_enum_set(man->translate_c->ptr, "draw_style", ED_MANIPULATOR_GRAB_STYLE_RING_2D);
+
+ WM_manipulator_set_flag(man->translate_c, WM_MANIPULATOR_DRAW_VALUE, true);
+ WM_manipulator_set_flag(man->rotate_c, WM_MANIPULATOR_DRAW_VALUE, true);
+ WM_manipulator_set_flag(man->angle_z, WM_MANIPULATOR_DRAW_VALUE, true);
+
+ WM_manipulator_set_scale(man->angle_z, 0.5f);
+
+ {
+ man->data.context = (bContext *)C;
+ man->data.op = op;
+ man->data.prop_axis_co = RNA_struct_find_property(op->ptr, "center");
+ man->data.prop_axis_no = RNA_struct_find_property(op->ptr, "axis");
+ man->data.prop_angle = RNA_struct_find_property(op->ptr, "angle");
+ }
+
+ manipulator_mesh_spin_update_from_op(man);
+
+ /* Setup property callbacks */
+ {
+ WM_manipulator_target_property_def_func(
+ man->translate_z, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_spin_prop_depth_get,
+ .value_set_fn = manipulator_spin_prop_depth_set,
+ .range_get_fn = NULL,
+ .user_data = NULL,
+ });
+
+ WM_manipulator_target_property_def_func(
+ man->translate_c, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_spin_prop_translate_get,
+ .value_set_fn = manipulator_spin_prop_translate_set,
+ .range_get_fn = NULL,
+ .user_data = NULL,
+ });
+
+ WM_manipulator_target_property_def_func(
+ man->rotate_c, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_spin_prop_axis_angle_get,
+ .value_set_fn = manipulator_spin_prop_axis_angle_set,
+ .range_get_fn = NULL,
+ .user_data = NULL,
+ });
+
+ WM_manipulator_target_property_def_func(
+ man->angle_z, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_spin_prop_angle_get,
+ .value_set_fn = manipulator_spin_prop_angle_set,
+ .range_get_fn = NULL,
+ .user_data = NULL,
+ });
+
+ }
+}
+
+static void manipulator_mesh_spin_draw_prepare(
+ const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ ManipulatorSpinGroup *man = mgroup->customdata;
+ if (man->data.op->next) {
+ man->data.op = WM_operator_last_redo((bContext *)man->data.context);
+ }
+ manipulator_mesh_spin_update_from_op(man);
+}
+
+static void MESH_WGT_spin(struct wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Mesh Spin";
+ wgt->idname = "MESH_WGT_spin";
+
+ wgt->flag = WM_MANIPULATORGROUPTYPE_3D;
+
+ wgt->mmap_params.spaceid = SPACE_VIEW3D;
+ wgt->mmap_params.regionid = RGN_TYPE_WINDOW;
+
+ wgt->poll = manipulator_mesh_spin_poll;
+ wgt->setup = manipulator_mesh_spin_setup;
+ wgt->draw_prepare = manipulator_mesh_spin_draw_prepare;
+}
+
+/** \} */
+
+#endif /* USE_MANIPULATOR */
/* -------------------------------------------------------------------- */
/** \name Spin Operator
@@ -115,7 +496,18 @@ static int edbm_spin_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(e
}
}
- return edbm_spin_exec(C, op);
+ int ret = edbm_spin_exec(C, op);
+
+#ifdef USE_MANIPULATOR
+ if (ret & OPERATOR_FINISHED) {
+ /* Setup manipulators */
+ if (v3d && (v3d->twflag & V3D_MANIPULATOR_DRAW)) {
+ WM_manipulator_group_type_ensure("MESH_WGT_spin");
+ }
+ }
+#endif
+
+ return ret;
}
void MESH_OT_spin(wmOperatorType *ot)
@@ -146,7 +538,7 @@ void MESH_OT_spin(wmOperatorType *ot)
"Center", "Center in global view space", -1e4f, 1e4f);
RNA_def_float_vector(ot->srna, "axis", 3, NULL, -1.0f, 1.0f, "Axis", "Axis in global view space", -1.0f, 1.0f);
+#ifdef USE_MANIPULATOR
+ WM_manipulatorgrouptype_append(MESH_WGT_spin);
+#endif
}
-
-/** \} */
-
diff --git a/source/blender/editors/mesh/editmesh_inset.c b/source/blender/editors/mesh/editmesh_inset.c
index 3833b84b5d2..58bd1dbd488 100644
--- a/source/blender/editors/mesh/editmesh_inset.c
+++ b/source/blender/editors/mesh/editmesh_inset.c
@@ -72,7 +72,7 @@ typedef struct {
float mcenter[2];
BMBackup mesh_backup;
void *draw_handle_pixel;
- short twtype;
+ short twflag;
} InsetData;
@@ -152,8 +152,8 @@ static bool edbm_inset_init(bContext *C, wmOperator *op, const bool is_modal)
ar->type, ED_region_draw_mouse_line_cb, opdata->mcenter, REGION_DRAW_POST_PIXEL);
G.moving = G_TRANSFORM_EDIT;
if (v3d) {
- opdata->twtype = v3d->twtype;
- v3d->twtype = 0;
+ opdata->twflag = v3d->twflag;
+ v3d->twflag = 0;
}
}
@@ -173,7 +173,7 @@ static void edbm_inset_exit(bContext *C, wmOperator *op)
EDBM_redo_state_free(&opdata->mesh_backup, NULL, false);
ED_region_draw_cb_exit(ar->type, opdata->draw_handle_pixel);
if (v3d) {
- v3d->twtype = opdata->twtype;
+ v3d->twflag = opdata->twflag;
}
G.moving = 0;
}
@@ -378,7 +378,9 @@ static int edbm_inset_modal(bContext *C, wmOperator *op, const wmEvent *event)
case LEFTMOUSE:
case PADENTER:
case RETKEY:
- if (event->val == KM_PRESS) {
+ if ((event->val == KM_PRESS) ||
+ ((event->val == KM_RELEASE) && RNA_boolean_get(op->ptr, "release_confirm")))
+ {
edbm_inset_calc(op);
edbm_inset_exit(C, op);
return OPERATOR_FINISHED;
@@ -540,4 +542,7 @@ void MESH_OT_inset(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "use_select_inset", false, "Select Outer", "Select the new inset faces");
RNA_def_boolean(ot->srna, "use_individual", false, "Individual", "Individual Face Inset");
RNA_def_boolean(ot->srna, "use_interpolate", true, "Interpolate", "Blend face data across the inset");
+
+ prop = RNA_def_boolean(ot->srna, "release_confirm", 0, "Confirm on Release", "");
+ RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
}
diff --git a/source/blender/editors/mesh/editmesh_knife.c b/source/blender/editors/mesh/editmesh_knife.c
index 053e932fe75..80fed05a0b5 100644
--- a/source/blender/editors/mesh/editmesh_knife.c
+++ b/source/blender/editors/mesh/editmesh_knife.c
@@ -54,8 +54,10 @@
#include "BKE_editmesh_bvh.h"
#include "BKE_report.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h" /* for paint cursor */
+#include "DEG_depsgraph.h"
+
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "ED_screen.h"
#include "ED_space_api.h"
@@ -1004,12 +1006,18 @@ static void knifetool_draw_angle_snapping(const KnifeTool_OpData *kcd)
copy_v3_v3(v2, ray_hit_best[1]);
}
- UI_ThemeColor(TH_TRANSFORM);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_TRANSFORM);
glLineWidth(2.0);
- glBegin(GL_LINES);
- glVertex3fv(v1);
- glVertex3fv(v2);
- glEnd();
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex3fv(pos, v1);
+ immVertex3fv(pos, v2);
+ immEnd();
+
+ immUnbindProgram();
}
static void knife_init_colors(KnifeColors *colors)
@@ -1037,66 +1045,69 @@ static void knifetool_draw(const bContext *C, ARegion *UNUSED(ar), void *arg)
glPolygonOffset(1.0f, 1.0f);
- glPushMatrix();
- glMultMatrixf(kcd->ob->obmat);
+ gpuPushMatrix();
+ gpuMultMatrix(kcd->ob->obmat);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
if (kcd->mode == MODE_DRAGGING) {
if (kcd->is_angle_snapping)
knifetool_draw_angle_snapping(kcd);
- glColor3ubv(kcd->colors.line);
-
+ immUniformColor3ubv(kcd->colors.line);
glLineWidth(2.0);
- glBegin(GL_LINES);
- glVertex3fv(kcd->prev.cage);
- glVertex3fv(kcd->curr.cage);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex3fv(pos, kcd->prev.cage);
+ immVertex3fv(pos, kcd->curr.cage);
+ immEnd();
}
if (kcd->prev.vert) {
- glColor3ubv(kcd->colors.point);
+ immUniformColor3ubv(kcd->colors.point);
glPointSize(11);
- glBegin(GL_POINTS);
- glVertex3fv(kcd->prev.cage);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex3fv(pos, kcd->prev.cage);
+ immEnd();
}
if (kcd->prev.bmface) {
- glColor3ubv(kcd->colors.curpoint);
+ immUniformColor3ubv(kcd->colors.curpoint);
glPointSize(9);
- glBegin(GL_POINTS);
- glVertex3fv(kcd->prev.cage);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex3fv(pos, kcd->prev.cage);
+ immEnd();
}
if (kcd->curr.edge) {
- glColor3ubv(kcd->colors.edge);
+ immUniformColor3ubv(kcd->colors.edge);
glLineWidth(2.0);
- glBegin(GL_LINES);
- glVertex3fv(kcd->curr.edge->v1->cageco);
- glVertex3fv(kcd->curr.edge->v2->cageco);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex3fv(pos, kcd->curr.edge->v1->cageco);
+ immVertex3fv(pos, kcd->curr.edge->v2->cageco);
+ immEnd();
}
else if (kcd->curr.vert) {
- glColor3ubv(kcd->colors.point);
+ immUniformColor3ubv(kcd->colors.point);
glPointSize(11);
- glBegin(GL_POINTS);
- glVertex3fv(kcd->curr.cage);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex3fv(pos, kcd->curr.cage);
+ immEnd();
}
if (kcd->curr.bmface) {
- glColor3ubv(kcd->colors.curpoint);
+ immUniformColor3ubv(kcd->colors.curpoint);
glPointSize(9);
- glBegin(GL_POINTS);
- glVertex3fv(kcd->curr.cage);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex3fv(pos, kcd->curr.cage);
+ immEnd();
}
if (kcd->totlinehit > 0) {
@@ -1104,29 +1115,38 @@ static void knifetool_draw(const bContext *C, ARegion *UNUSED(ar), void *arg)
int i;
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* draw any snapped verts first */
- glColor4ubv(kcd->colors.point_a);
+ immUniformColor4ubv(kcd->colors.point_a);
glPointSize(11);
- glBegin(GL_POINTS);
+
+ immBeginAtMost(GWN_PRIM_POINTS, kcd->totlinehit);
+
lh = kcd->linehits;
for (i = 0; i < kcd->totlinehit; i++, lh++) {
- if (lh->v)
- glVertex3fv(lh->cagehit);
+ if (lh->v) {
+ immVertex3fv(pos, lh->cagehit);
+ }
}
- glEnd();
+
+ immEnd();
/* now draw the rest */
- glColor4ubv(kcd->colors.curpoint_a);
+ immUniformColor4ubv(kcd->colors.curpoint_a);
glPointSize(7);
- glBegin(GL_POINTS);
+
+ immBeginAtMost(GWN_PRIM_POINTS, kcd->totlinehit);
+
lh = kcd->linehits;
for (i = 0; i < kcd->totlinehit; i++, lh++) {
- if (!lh->v)
- glVertex3fv(lh->cagehit);
+ if (!lh->v) {
+ immVertex3fv(pos, lh->cagehit);
+ }
}
- glEnd();
+
+ immEnd();
+
glDisable(GL_BLEND);
}
@@ -1134,44 +1154,46 @@ static void knifetool_draw(const bContext *C, ARegion *UNUSED(ar), void *arg)
BLI_mempool_iter iter;
KnifeEdge *kfe;
+ immUniformColor3ubv(kcd->colors.line);
glLineWidth(1.0);
- glBegin(GL_LINES);
+
+ immBeginAtMost(GWN_PRIM_LINES, BLI_mempool_len(kcd->kedges) * 2);
BLI_mempool_iternew(kcd->kedges, &iter);
for (kfe = BLI_mempool_iterstep(&iter); kfe; kfe = BLI_mempool_iterstep(&iter)) {
if (!kfe->is_cut)
continue;
- glColor3ubv(kcd->colors.line);
-
- glVertex3fv(kfe->v1->cageco);
- glVertex3fv(kfe->v2->cageco);
+ immVertex3fv(pos, kfe->v1->cageco);
+ immVertex3fv(pos, kfe->v2->cageco);
}
- glEnd();
+ immEnd();
}
if (kcd->totkvert > 0) {
BLI_mempool_iter iter;
KnifeVert *kfv;
+ immUniformColor3ubv(kcd->colors.point);
glPointSize(5.0);
- glBegin(GL_POINTS);
+ immBeginAtMost(GWN_PRIM_POINTS, BLI_mempool_len(kcd->kverts));
+
BLI_mempool_iternew(kcd->kverts, &iter);
for (kfv = BLI_mempool_iterstep(&iter); kfv; kfv = BLI_mempool_iterstep(&iter)) {
if (!kfv->is_cut)
continue;
- glColor3ubv(kcd->colors.point);
-
- glVertex3fv(kfv->cageco);
+ immVertex3fv(pos, kfv->cageco);
}
- glEnd();
+ immEnd();
}
- glPopMatrix();
+ immUnbindProgram();
+
+ gpuPopMatrix();
if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
}
@@ -1394,7 +1416,7 @@ static bool bm_ray_cast_cb_elem_not_in_face_check(BMFace *f, void *user_data)
* intersecting faces matching this face (or connected when an vert/edge) will be ignored.
*/
static bool point_is_visible(
- KnifeTool_OpData *kcd, const float p[3], const float s[2], bglMats *mats,
+ KnifeTool_OpData *kcd, const float p[3], const float s[2],
BMElem *ele_test)
{
BMFace *f_hit;
@@ -1412,7 +1434,7 @@ static bool point_is_visible(
float view[3], p_ofs[3];
/* TODO: I think there's a simpler way to get the required raycast ray */
- ED_view3d_unproject(mats, view, s[0], s[1], 0.0f);
+ ED_view3d_unproject(kcd->vc.ar, s[0], s[1], 0.0f, view);
mul_m4_v3(kcd->ob->imat, view);
@@ -1485,7 +1507,6 @@ static void set_linehit_depth(KnifeTool_OpData *kcd, KnifeLineHit *lh)
/* Finds visible (or all, if cutting through) edges that intersects the current screen drag line */
static void knife_find_line_hits(KnifeTool_OpData *kcd)
{
- bglMats mats;
SmallHash faces, kfes, kfvs;
float v1[3], v2[3], v3[3], v4[3], s1[2], s2[2];
BVHTree *planetree, *tree;
@@ -1515,8 +1536,6 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
const bool use_hit_prev = true;
const bool use_hit_curr = (kcd->is_drag_hold == false);
- bgl_get_mats(&mats);
-
if (kcd->linehits) {
MEM_freeN(kcd->linehits);
kcd->linehits = NULL;
@@ -1542,8 +1561,8 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
}
/* unproject screen line */
- ED_view3d_win_to_segment(kcd->ar, kcd->vc.v3d, s1, v1, v3, true);
- ED_view3d_win_to_segment(kcd->ar, kcd->vc.v3d, s2, v2, v4, true);
+ ED_view3d_win_to_segment(kcd->vc.depsgraph, kcd->ar, kcd->vc.v3d, s1, v1, v3, true);
+ ED_view3d_win_to_segment(kcd->vc.depsgraph, kcd->ar, kcd->vc.v3d, s2, v2, v4, true);
mul_m4_v3(kcd->ob->imat, v1);
mul_m4_v3(kcd->ob->imat, v2);
@@ -1645,7 +1664,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
knife_project_v2(kcd, v->cageco, s);
d = dist_squared_to_line_segment_v2(s, s1, s2);
if ((d <= vert_tol_sq) &&
- (point_is_visible(kcd, v->cageco, s, &mats, bm_elem_from_knife_vert(v, &kfe_hit))))
+ (point_is_visible(kcd, v->cageco, s, bm_elem_from_knife_vert(v, &kfe_hit))))
{
memset(&hit, 0, sizeof(hit));
hit.v = v;
@@ -1708,7 +1727,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
* Need to find 3d intersection of ray through sint */
knife_input_ray_segment(kcd, sint, 1.0f, r1, r2);
isect_kind = isect_line_line_v3(kfe->v1->cageco, kfe->v2->cageco, r1, r2, p_cage, p_cage_tmp);
- if (isect_kind >= 1 && point_is_visible(kcd, p_cage, sint, &mats, bm_elem_from_knife_edge(kfe))) {
+ if (isect_kind >= 1 && point_is_visible(kcd, p_cage, sint, bm_elem_from_knife_edge(kfe))) {
memset(&hit, 0, sizeof(hit));
if (kcd->snap_midpoints) {
/* choose intermediate point snap too */
@@ -1737,7 +1756,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
float p[3], p_cage[3];
if (use_hit_prev && knife_ray_intersect_face(kcd, s1, v1, v3, f, face_tol_sq, p, p_cage)) {
- if (point_is_visible(kcd, p_cage, s1, &mats, (BMElem *)f)) {
+ if (point_is_visible(kcd, p_cage, s1, (BMElem *)f)) {
memset(&hit, 0, sizeof(hit));
hit.f = f;
copy_v3_v3(hit.hit, p);
@@ -1749,7 +1768,7 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
}
if (use_hit_curr && knife_ray_intersect_face(kcd, s2, v2, v4, f, face_tol_sq, p, p_cage)) {
- if (point_is_visible(kcd, p_cage, s2, &mats, (BMElem *)f)) {
+ if (point_is_visible(kcd, p_cage, s2, (BMElem *)f)) {
memset(&hit, 0, sizeof(hit));
hit.f = f;
copy_v3_v3(hit.hit, p);
@@ -1782,13 +1801,9 @@ static void knife_find_line_hits(KnifeTool_OpData *kcd)
static void knife_input_ray_segment(KnifeTool_OpData *kcd, const float mval[2], const float ofs,
float r_origin[3], float r_origin_ofs[3])
{
- bglMats mats;
-
- bgl_get_mats(&mats);
-
/* unproject to find view ray */
- ED_view3d_unproject(&mats, r_origin, mval[0], mval[1], 0.0f);
- ED_view3d_unproject(&mats, r_origin_ofs, mval[0], mval[1], ofs);
+ ED_view3d_unproject(kcd->vc.ar, mval[0], mval[1], 0.0f, r_origin);
+ ED_view3d_unproject(kcd->vc.ar, mval[0], mval[1], ofs, r_origin_ofs);
/* transform into object space */
invert_m4_m4(kcd->ob->imat, kcd->ob->obmat);
@@ -2503,7 +2518,8 @@ static void knife_recalc_projmat(KnifeTool_OpData *kcd)
mul_v3_mat3_m4v3(kcd->proj_zaxis, kcd->ob->imat, kcd->vc.rv3d->viewinv[2]);
normalize_v3(kcd->proj_zaxis);
- kcd->is_ortho = ED_view3d_clip_range_get(kcd->vc.v3d, kcd->vc.rv3d,
+ kcd->is_ortho = ED_view3d_clip_range_get(kcd->vc.depsgraph,
+ kcd->vc.v3d, kcd->vc.rv3d,
&kcd->clipsta, &kcd->clipend, true);
}
@@ -2574,7 +2590,7 @@ static void knifetool_init_bmbvh(KnifeTool_OpData *kcd)
{
BM_mesh_elem_index_ensure(kcd->em->bm, BM_VERT);
- kcd->cagecos = (const float (*)[3])BKE_editmesh_vertexCos_get(kcd->em, kcd->scene, NULL);
+ kcd->cagecos = (const float (*)[3])BKE_editmesh_vertexCos_get(kcd->vc.depsgraph, kcd->em, kcd->scene, NULL);
kcd->bmbvh = BKE_bmbvh_new_from_editmesh(
kcd->em,
@@ -3008,7 +3024,6 @@ static bool edbm_mesh_knife_point_isect(LinkNode *polys, const float cent_ss[2])
void EDBM_mesh_knife(bContext *C, LinkNode *polys, bool use_tag, bool cut_through)
{
KnifeTool_OpData *kcd;
- bglMats mats;
view3d_operator_needs_opengl(C);
@@ -3027,10 +3042,6 @@ void EDBM_mesh_knife(bContext *C, LinkNode *polys, bool use_tag, bool cut_throug
if (use_tag) {
BM_mesh_elem_hflag_enable_all(kcd->em->bm, BM_EDGE, BM_ELEM_TAG, false);
}
-
- if (kcd->cut_through == false) {
- bgl_get_mats(&mats);
- }
}
/* execute */
@@ -3139,7 +3150,7 @@ void EDBM_mesh_knife(bContext *C, LinkNode *polys, bool use_tag, bool cut_throug
float cent[3], cent_ss[2];
BM_face_calc_point_in_face(f, cent);
knife_project_v2(kcd, cent, cent_ss);
- if ((kcd->cut_through || point_is_visible(kcd, cent, cent_ss, &mats, (BMElem *)f)) &&
+ if ((kcd->cut_through || point_is_visible(kcd, cent, cent_ss, (BMElem *)f)) &&
edbm_mesh_knife_point_isect(polys, cent_ss))
{
BM_elem_flag_enable(f, BM_ELEM_TAG);
diff --git a/source/blender/editors/mesh/editmesh_knife_project.c b/source/blender/editors/mesh/editmesh_knife_project.c
index 0d3cc07589b..ba030c42a04 100644
--- a/source/blender/editors/mesh/editmesh_knife_project.c
+++ b/source/blender/editors/mesh/editmesh_knife_project.c
@@ -42,6 +42,8 @@
#include "BKE_editmesh.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_define.h"
#include "RNA_access.h"
@@ -56,13 +58,15 @@
#include "mesh_intern.h" /* own include */
-static LinkNode *knifeproject_poly_from_object(ARegion *ar, Scene *scene, Object *ob, LinkNode *polys)
+static LinkNode *knifeproject_poly_from_object(const bContext *C, Scene *scene, Object *ob, LinkNode *polys)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ARegion *ar = CTX_wm_region(C);
DerivedMesh *dm;
bool dm_needsFree;
if (ob->type == OB_MESH || ob->derivedFinal) {
- dm = ob->derivedFinal ? ob->derivedFinal : mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+ dm = ob->derivedFinal ? ob->derivedFinal : mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
dm_needsFree = false;
}
else if (ELEM(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
@@ -116,7 +120,6 @@ static LinkNode *knifeproject_poly_from_object(ARegion *ar, Scene *scene, Object
static int knifeproject_exec(bContext *C, wmOperator *op)
{
- ARegion *ar = CTX_wm_region(C);
Scene *scene = CTX_data_scene(C);
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
@@ -127,7 +130,7 @@ static int knifeproject_exec(bContext *C, wmOperator *op)
CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
{
if (ob != obedit) {
- polys = knifeproject_poly_from_object(ar, scene, ob, polys);
+ polys = knifeproject_poly_from_object(C, scene, ob, polys);
}
}
CTX_DATA_END;
diff --git a/source/blender/editors/mesh/editmesh_loopcut.c b/source/blender/editors/mesh/editmesh_loopcut.c
index 5d4f6242e4f..37b85ae9f09 100644
--- a/source/blender/editors/mesh/editmesh_loopcut.c
+++ b/source/blender/editors/mesh/editmesh_loopcut.c
@@ -44,8 +44,10 @@
#include "BKE_editmesh.h"
#include "BKE_DerivedMesh.h"
#include "BKE_unit.h"
+#include "BKE_layer.h"
-#include "BIF_gl.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "UI_interface.h"
@@ -62,6 +64,8 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "DEG_depsgraph.h"
+
#include "mesh_intern.h" /* own include */
#define SUBD_SMOOTH_MAX 4.0f
@@ -82,9 +86,15 @@ typedef struct RingSelOpData {
ViewContext vc;
+ Object **objects;
+ uint objects_len;
+
+ /* These values switch objects based on the object under the cursor. */
+ uint ob_index;
Object *ob;
BMEditMesh *em;
BMEdge *eed;
+
NumInput num;
bool extend;
@@ -104,27 +114,41 @@ static void ringsel_draw(const bContext *C, ARegion *UNUSED(ar), void *arg)
if (v3d && v3d->zbuf)
glDisable(GL_DEPTH_TEST);
- glPushMatrix();
- glMultMatrixf(lcd->ob->obmat);
+ gpuPushMatrix();
+ gpuMultMatrix(lcd->ob->obmat);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3ub(255, 0, 255);
- glColor3ub(255, 0, 255);
if (lcd->totedge > 0) {
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, lcd->edges);
- glDrawArrays(GL_LINES, 0, lcd->totedge * 2);
- glDisableClientState(GL_VERTEX_ARRAY);
+ immBegin(GWN_PRIM_LINES, lcd->totedge * 2);
+
+ for (int i = 0; i < lcd->totedge; i++) {
+ immVertex3fv(pos, lcd->edges[i][0]);
+ immVertex3fv(pos, lcd->edges[i][1]);
+ }
+
+ immEnd();
}
if (lcd->totpoint > 0) {
glPointSize(3.0f);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, lcd->points);
- glDrawArrays(GL_POINTS, 0, lcd->totpoint);
- glDisableClientState(GL_VERTEX_ARRAY);
+ immBegin(GWN_PRIM_POINTS, lcd->totpoint);
+
+ for (int i = 0; i < lcd->totpoint; i++) {
+ immVertex3fv(pos, lcd->points[i]);
+ }
+
+ immEnd();
}
- glPopMatrix();
+ immUnbindProgram();
+
+ gpuPopMatrix();
+
if (v3d && v3d->zbuf)
glEnable(GL_DEPTH_TEST);
}
@@ -367,18 +391,23 @@ static void edgering_preview_calc(RingSelOpData *lcd, const int previewlines)
static void edgering_select(RingSelOpData *lcd)
{
- BMEditMesh *em = lcd->em;
- BMEdge *eed_start = lcd->eed;
- BMWalker walker;
- BMEdge *eed;
-
- if (!eed_start)
+ if (!lcd->eed) {
return;
+ }
if (!lcd->extend) {
- EDBM_flag_disable_all(lcd->em, BM_ELEM_SELECT);
+ for (uint ob_index = 0; ob_index < lcd->objects_len; ob_index++) {
+ Object *ob_iter = lcd->objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(ob_iter);
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ WM_main_add_notifier(NC_GEOM | ND_SELECT, ob_iter->data);
+ }
}
+ BMEditMesh *em = lcd->em;
+ BMEdge *eed_start = lcd->eed;
+ BMWalker walker;
+ BMEdge *eed;
BMW_init(&walker, em->bm, BMW_EDGERING,
BMW_MASK_NOP, BMW_MASK_NOP, BMW_MASK_NOP,
BMW_FLAG_TEST_HIDDEN,
@@ -482,6 +511,8 @@ static void ringsel_exit(bContext *UNUSED(C), wmOperator *op)
edgering_preview_free(lcd);
+ MEM_freeN(lcd->objects);
+
ED_region_tag_redraw(lcd->ar);
/* free the custom data */
@@ -498,17 +529,20 @@ static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
/* alloc new customdata */
lcd = op->customdata = MEM_callocN(sizeof(RingSelOpData), "ringsel Modal Op Data");
-
+
+ em_setup_viewcontext(C, &lcd->vc);
+
/* assign the drawing handle for drawing preview line... */
lcd->ar = CTX_wm_region(C);
lcd->draw_handle = ED_region_draw_cb_activate(lcd->ar->type, ringsel_draw, lcd, REGION_DRAW_POST_VIEW);
- lcd->ob = CTX_data_edit_object(C);
- lcd->em = BKE_editmesh_from_object(lcd->ob);
+ /* Initialize once the cursor is over a mesh. */
+ lcd->ob = NULL;
+ lcd->em = NULL;
lcd->extend = do_cut ? false : RNA_boolean_get(op->ptr, "extend");
lcd->do_cut = do_cut;
lcd->cuts = RNA_int_get(op->ptr, "number_cuts");
lcd->smoothness = RNA_float_get(op->ptr, "smoothness");
-
+
initNumInput(&lcd->num);
lcd->num.idx_max = 1;
lcd->num.val_flag[0] |= NUM_NO_NEGATIVE | NUM_NO_FRACTION;
@@ -517,8 +551,6 @@ static int ringsel_init(bContext *C, wmOperator *op, bool do_cut)
lcd->num.unit_type[0] = B_UNIT_NONE;
lcd->num.unit_type[1] = B_UNIT_NONE;
- em_setup_viewcontext(C, &lcd->vc);
-
ED_region_tag_redraw(lcd->ar);
return 1;
@@ -530,44 +562,102 @@ static void ringcut_cancel(bContext *C, wmOperator *op)
ringsel_exit(C, op);
}
-static void loopcut_update_edge(RingSelOpData *lcd, BMEdge *e, const int previewlines)
+static void loopcut_update_edge(RingSelOpData *lcd, uint ob_index, BMEdge *e, const int previewlines)
{
if (e != lcd->eed) {
lcd->eed = e;
+ lcd->ob = lcd->vc.obedit;
+ lcd->ob_index = ob_index;
+ lcd->em = lcd->vc.em;
ringsel_find_edge(lcd, previewlines);
}
+ else if (e == NULL) {
+ lcd->ob = NULL;
+ lcd->em = NULL;
+ lcd->ob_index = UINT_MAX;
+ }
}
static void loopcut_mouse_move(RingSelOpData *lcd, const int previewlines)
{
- float dist = ED_view3d_select_dist_px();
- BMEdge *e = EDBM_edge_find_nearest(&lcd->vc, &dist);
- loopcut_update_edge(lcd, e, previewlines);
+ struct {
+ Object *ob;
+ BMEdge *eed;
+ float dist;
+ int ob_index;
+ } best = {
+ .dist = ED_view3d_select_dist_px(),
+ };
+
+ for (uint ob_index = 0; ob_index < lcd->objects_len; ob_index++) {
+ Object *ob_iter = lcd->objects[ob_index];
+ ED_view3d_viewcontext_init_object(&lcd->vc, ob_iter);
+ BMEdge *eed_test = EDBM_edge_find_nearest_ex(&lcd->vc, &best.dist, NULL, false, false, NULL);
+ if (eed_test) {
+ best.ob = ob_iter;
+ best.eed = eed_test;
+ best.ob_index = ob_index;
+ }
+ }
+
+ if (best.eed) {
+ ED_view3d_viewcontext_init_object(&lcd->vc, best.ob);
+ }
+
+ loopcut_update_edge(lcd, best.ob_index, best.eed, previewlines);
}
/* called by both init() and exec() */
static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
{
const bool is_interactive = (event != NULL);
- Object *obedit = CTX_data_edit_object(C);
- RingSelOpData *lcd;
- if (modifiers_isDeformedByLattice(obedit) || modifiers_isDeformedByArmature(obedit))
- BKE_report(op->reports, RPT_WARNING, "Loop cut does not work well on deformed edit mesh display");
+ /* Use for redo - intentionally wrap int to uint. */
+ const struct {
+ uint ob_index;
+ uint e_index;
+ } exec_data = {
+ .ob_index = (uint)RNA_int_get(op->ptr, "object_index"),
+ .e_index = (uint)RNA_int_get(op->ptr, "edge_index"),
+ };
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+
+ uint objects_len;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode(view_layer, &objects_len);
+
+ if (is_interactive) {
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ if (modifiers_isDeformedByLattice(ob_iter) || modifiers_isDeformedByArmature(ob_iter)) {
+ BKE_report(op->reports, RPT_WARNING, "Loop cut does not work well on deformed edit mesh display");
+ break;
+ }
+ }
+ }
view3d_operator_needs_opengl(C);
/* for re-execution, check edge index is in range before we setup ringsel */
+ bool ok = true;
if (is_interactive == false) {
- const int e_index = RNA_int_get(op->ptr, "edge_index");
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- if (UNLIKELY((e_index == -1) || (e_index >= em->bm->totedge))) {
+ if (exec_data.ob_index >= objects_len) {
return OPERATOR_CANCELLED;
+ ok = false;
+ }
+ else {
+ Object *ob_iter = objects[exec_data.ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(ob_iter);
+ if (exec_data.e_index >= em->bm->totedge) {
+ ok = false;
+ }
}
}
- if (!ringsel_init(C, op, true))
+ if (!ok || !ringsel_init(C, op, true)) {
+ MEM_freeN(objects);
return OPERATOR_CANCELLED;
+ }
/* add a modal handler for this operator - handles loop selection */
if (is_interactive) {
@@ -575,18 +665,24 @@ static int loopcut_init(bContext *C, wmOperator *op, const wmEvent *event)
WM_event_add_modal_handler(C, op);
}
- lcd = op->customdata;
+ RingSelOpData *lcd = op->customdata;
+
+ lcd->objects = objects;
+ lcd->objects_len = objects_len;
if (is_interactive) {
copy_v2_v2_int(lcd->vc.mval, event->mval);
loopcut_mouse_move(lcd, is_interactive ? 1 : 0);
}
else {
- const int e_index = RNA_int_get(op->ptr, "edge_index");
+
+ Object *ob_iter = objects[exec_data.ob_index];
+ ED_view3d_viewcontext_init_object(&lcd->vc, ob_iter);
+
BMEdge *e;
- BM_mesh_elem_table_ensure(lcd->em->bm, BM_EDGE);
- e = BM_edge_at_index(lcd->em->bm, e_index);
- loopcut_update_edge(lcd, e, 0);
+ BM_mesh_elem_table_ensure(lcd->vc.em->bm, BM_EDGE);
+ e = BM_edge_at_index(lcd->vc.em->bm, exec_data.e_index);
+ loopcut_update_edge(lcd, exec_data.ob_index, e, 0);
}
#ifdef USE_LOOPSLIDE_HACK
@@ -636,6 +732,7 @@ static int loopcut_finish(RingSelOpData *lcd, bContext *C, wmOperator *op)
if (lcd->eed) {
/* set for redo */
BM_mesh_elem_index_ensure(lcd->em->bm, BM_EDGE);
+ RNA_int_set(op->ptr, "object_index", lcd->ob_index);
RNA_int_set(op->ptr, "edge_index", BM_elem_index_get(lcd->eed));
/* execute */
@@ -855,12 +952,17 @@ void MESH_OT_loopcut(wmOperatorType *ot)
"Smoothness", "Smoothness factor", -SUBD_SMOOTH_MAX, SUBD_SMOOTH_MAX);
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ WM_operatortype_props_advanced_begin(ot);
+
prop = RNA_def_property(ot->srna, "falloff", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, rna_enum_proportional_falloff_curve_only_items);
RNA_def_property_enum_default(prop, PROP_INVSQUARE);
RNA_def_property_ui_text(prop, "Falloff", "Falloff type the feather");
RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_CURVE); /* Abusing id_curve :/ */
+ /* For redo only. */
+ prop = RNA_def_int(ot->srna, "object_index", -1, -1, INT_MAX, "Object Index", "", 0, INT_MAX);
+ RNA_def_property_flag(prop, PROP_HIDDEN);
prop = RNA_def_int(ot->srna, "edge_index", -1, -1, INT_MAX, "Edge Index", "", 0, INT_MAX);
RNA_def_property_flag(prop, PROP_HIDDEN);
diff --git a/source/blender/editors/mesh/editmesh_path.c b/source/blender/editors/mesh/editmesh_path.c
index bf5a7e3a053..4081e3b0302 100644
--- a/source/blender/editors/mesh/editmesh_path.c
+++ b/source/blender/editors/mesh/editmesh_path.c
@@ -59,6 +59,8 @@
#include "bmesh.h"
#include "bmesh_tools.h"
+#include "DEG_depsgraph.h"
+
#include "mesh_intern.h" /* own include */
/* -------------------------------------------------------------------- */
@@ -126,10 +128,9 @@ static void verttag_set_cb(BMVert *v, bool val, void *user_data_v)
}
static void mouse_mesh_shortest_path_vert(
- Scene *scene, const struct PathSelectParams *op_params,
+ Scene *UNUSED(scene), Object *obedit, const struct PathSelectParams *op_params,
BMVert *v_act, BMVert *v_dst)
{
- Object *obedit = scene->obedit;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@@ -286,11 +287,11 @@ static void edgetag_set_cb(BMEdge *e, bool val, void *user_data_v)
}
}
-static void edgetag_ensure_cd_flag(Scene *scene, Mesh *me)
+static void edgetag_ensure_cd_flag(Mesh *me, const char edge_mode)
{
BMesh *bm = me->edit_btmesh->bm;
- switch (scene->toolsettings->edge_mode) {
+ switch (edge_mode) {
case EDGE_MODE_TAG_CREASE:
BM_mesh_cd_flag_ensure(bm, me, ME_CDFLAG_EDGE_CREASE);
break;
@@ -313,10 +314,9 @@ static void edgetag_ensure_cd_flag(Scene *scene, Mesh *me)
/* since you want to create paths with multiple selects, it doesn't have extend option */
static void mouse_mesh_shortest_path_edge(
- Scene *scene, const struct PathSelectParams *op_params,
+ Scene *scene, Object *obedit, const struct PathSelectParams *op_params,
BMEdge *e_act, BMEdge *e_dst)
{
- Object *obedit = scene->obedit;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@@ -325,7 +325,7 @@ static void mouse_mesh_shortest_path_edge(
Mesh *me = obedit->data;
bool is_path_ordered = false;
- edgetag_ensure_cd_flag(scene, obedit->data);
+ edgetag_ensure_cd_flag(obedit->data, op_params->edge_mode);
if (e_act && (e_act != e_dst)) {
if (op_params->use_fill) {
@@ -383,7 +383,7 @@ static void mouse_mesh_shortest_path_edge(
}
else {
const bool is_act = !edgetag_test_cb(e_dst, &user_data);
- edgetag_ensure_cd_flag(scene, obedit->data);
+ edgetag_ensure_cd_flag(obedit->data, op_params->edge_mode);
edgetag_set_cb(e_dst, is_act, &user_data); /* switch the edge option */
}
@@ -459,10 +459,9 @@ static void facetag_set_cb(BMFace *f, bool val, void *user_data_v)
}
static void mouse_mesh_shortest_path_face(
- Scene *scene, const struct PathSelectParams *op_params,
+ Scene *UNUSED(scene), Object *obedit, const struct PathSelectParams *op_params,
BMFace *f_act, BMFace *f_dst)
{
- Object *obedit = scene->obedit;
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
@@ -554,7 +553,7 @@ static void mouse_mesh_shortest_path_face(
* \{ */
static bool edbm_shortest_path_pick_ex(
- Scene *scene, const struct PathSelectParams *op_params,
+ Scene *scene, Object *obedit, const struct PathSelectParams *op_params,
BMElem *ele_src, BMElem *ele_dst)
{
@@ -562,15 +561,15 @@ static bool edbm_shortest_path_pick_ex(
/* pass */
}
else if (ele_src->head.htype == BM_VERT) {
- mouse_mesh_shortest_path_vert(scene, op_params, (BMVert *)ele_src, (BMVert *)ele_dst);
+ mouse_mesh_shortest_path_vert(scene, obedit, op_params, (BMVert *)ele_src, (BMVert *)ele_dst);
return true;
}
else if (ele_src->head.htype == BM_EDGE) {
- mouse_mesh_shortest_path_edge(scene, op_params, (BMEdge *)ele_src, (BMEdge *)ele_dst);
+ mouse_mesh_shortest_path_edge(scene, obedit, op_params, (BMEdge *)ele_src, (BMEdge *)ele_dst);
return true;
}
else if (ele_src->head.htype == BM_FACE) {
- mouse_mesh_shortest_path_face(scene, op_params, (BMFace *)ele_src, (BMFace *)ele_dst);
+ mouse_mesh_shortest_path_face(scene, obedit, op_params, (BMFace *)ele_src, (BMFace *)ele_dst);
return true;
}
@@ -649,7 +648,7 @@ static int edbm_shortest_path_pick_invoke(bContext *C, wmOperator *op, const wmE
op_params.track_active = track_active;
op_params.edge_mode = vc.scene->toolsettings->edge_mode;
- if (!edbm_shortest_path_pick_ex(vc.scene, &op_params, ele_src, ele_dst)) {
+ if (!edbm_shortest_path_pick_ex(vc.scene, vc.obedit, &op_params, ele_src, ele_dst)) {
return OPERATOR_PASS_THROUGH;
}
@@ -686,7 +685,7 @@ static int edbm_shortest_path_pick_exec(bContext *C, wmOperator *op)
op_params.track_active = true;
op_params.edge_mode = scene->toolsettings->edge_mode;
- if (!edbm_shortest_path_pick_ex(scene, &op_params, ele_src, ele_dst)) {
+ if (!edbm_shortest_path_pick_ex(scene, obedit, &op_params, ele_src, ele_dst)) {
return OPERATOR_CANCELLED;
}
@@ -727,8 +726,8 @@ void MESH_OT_shortest_path_pick(wmOperatorType *ot)
static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- Object *ob = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(ob);
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
BMIter iter;
BMEditSelection *ese_src, *ese_dst;
@@ -780,7 +779,7 @@ static int edbm_shortest_path_select_exec(bContext *C, wmOperator *op)
struct PathSelectParams op_params;
path_select_params_from_op(op, &op_params);
- edbm_shortest_path_pick_ex(scene, &op_params, ele_src, ele_dst);
+ edbm_shortest_path_pick_ex(scene, obedit, &op_params, ele_src, ele_dst);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mesh/editmesh_polybuild.c b/source/blender/editors/mesh/editmesh_polybuild.c
new file mode 100644
index 00000000000..dff501ece13
--- /dev/null
+++ b/source/blender/editors/mesh/editmesh_polybuild.c
@@ -0,0 +1,542 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/mesh/editmesh_polybuild.c
+ * \ingroup edmesh
+ *
+ * Tools to implement polygon building tool,
+ * an experimental tool for quickly constructing/manipulating faces.
+ */
+
+#include "DNA_object_types.h"
+
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+#include "BKE_report.h"
+#include "BKE_editmesh.h"
+#include "BKE_mesh.h"
+
+#include "WM_types.h"
+
+#include "ED_mesh.h"
+#include "ED_screen.h"
+#include "ED_transform.h"
+#include "ED_view3d.h"
+
+#include "bmesh.h"
+
+#include "mesh_intern.h" /* own include */
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Local Utilities
+ * \{ */
+
+static void edbm_selectmode_ensure(Scene *scene, BMEditMesh *em, short selectmode)
+{
+ if ((scene->toolsettings->selectmode & selectmode) == 0) {
+ scene->toolsettings->selectmode |= selectmode;
+ em->selectmode = scene->toolsettings->selectmode;
+ EDBM_selectmode_set(em);
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Face At Cursor
+ * \{ */
+
+static int edbm_polybuild_face_at_cursor_invoke(
+ bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+{
+ ViewContext vc;
+ float center[3];
+ bool changed = false;
+
+ em_setup_viewcontext(C, &vc);
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ BMElem *ele_act = BM_mesh_active_elem_get(bm);
+
+ invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
+ ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
+
+ edbm_selectmode_ensure(vc.scene, vc.em, SCE_SELECT_VERTEX);
+
+ if (ele_act == NULL || ele_act->head.htype == BM_FACE) {
+ /* Just add vert */
+ copy_v3_v3(center, ED_view3d_cursor3d_get(vc.scene, vc.v3d));
+ mul_v3_m4v3(center, vc.obedit->obmat, center);
+ ED_view3d_win_to_3d_int(vc.v3d, vc.ar, center, event->mval, center);
+ mul_m4_v3(vc.obedit->imat, center);
+
+ BMVert *v_new = BM_vert_create(bm, center, NULL, BM_CREATE_NOP);
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ BM_vert_select_set(bm, v_new, true);
+ changed = true;
+ }
+ else if (ele_act->head.htype == BM_EDGE) {
+ BMEdge *e_act = (BMEdge *)ele_act;
+ BMFace *f_reference = e_act->l ? e_act->l->f : NULL;
+
+ mid_v3_v3v3(center, e_act->v1->co, e_act->v2->co);
+ mul_m4_v3(vc.obedit->obmat, center);
+ ED_view3d_win_to_3d_int(vc.v3d, vc.ar, center, event->mval, center);
+ mul_m4_v3(vc.obedit->imat, center);
+
+ BMVert *v_tri[3];
+ v_tri[0] = e_act->v1;
+ v_tri[1] = e_act->v2;
+ v_tri[2] = BM_vert_create(bm, center, NULL, BM_CREATE_NOP);
+ if (e_act->l && e_act->l->v == v_tri[0]) {
+ SWAP(BMVert *, v_tri[0], v_tri[1]);
+ }
+ // BMFace *f_new =
+ BM_face_create_verts(bm, v_tri, 3, f_reference, BM_CREATE_NOP, true);
+
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ BM_vert_select_set(bm, v_tri[2], true);
+ changed = true;
+ }
+ else if (ele_act->head.htype == BM_VERT) {
+ BMVert *v_act = (BMVert *)ele_act;
+ BMEdge *e_pair[2] = {NULL};
+
+ if (v_act->e != NULL) {
+ for (uint allow_wire = 0; allow_wire < 2 && (e_pair[1] == NULL); allow_wire++) {
+ int i = 0;
+ BMEdge *e_iter = v_act->e;
+ do {
+ if ((BM_elem_flag_test(e_iter, BM_ELEM_HIDDEN) == false) &&
+ (allow_wire ? BM_edge_is_wire(e_iter) : BM_edge_is_boundary(e_iter)))
+ {
+ if (i == 2) {
+ e_pair[0] = e_pair[1] = NULL;
+ break;
+ }
+ e_pair[i++] = e_iter;
+ }
+ } while ((e_iter = BM_DISK_EDGE_NEXT(e_iter, v_act)) != v_act->e);
+ }
+ }
+
+ if (e_pair[1] != NULL) {
+ /* Quad from edge pair. */
+ if (BM_edge_calc_length_squared(e_pair[0]) <
+ BM_edge_calc_length_squared(e_pair[1]))
+ {
+ SWAP(BMEdge *, e_pair[0], e_pair[1]);
+ }
+
+ BMFace *f_reference = e_pair[0]->l ? e_pair[0]->l->f : NULL;
+
+ mul_v3_m4v3(center, vc.obedit->obmat, v_act->co);
+ ED_view3d_win_to_3d_int(vc.v3d, vc.ar, center, event->mval, center);
+ mul_m4_v3(vc.obedit->imat, center);
+
+ BMVert *v_quad[4];
+ v_quad[0] = v_act;
+ v_quad[1] = BM_edge_other_vert(e_pair[0], v_act);
+ v_quad[2] = BM_vert_create(bm, center, NULL, BM_CREATE_NOP);
+ v_quad[3] = BM_edge_other_vert(e_pair[1], v_act);
+ if (e_pair[0]->l && e_pair[0]->l->v == v_quad[0]) {
+ SWAP(BMVert *, v_quad[1], v_quad[3]);
+ }
+ // BMFace *f_new =
+ BM_face_create_verts(bm, v_quad, 4, f_reference, BM_CREATE_NOP, true);
+
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ BM_vert_select_set(bm, v_quad[2], true);
+ changed = true;
+ }
+ else {
+ /* Just add edge */
+ mul_m4_v3(vc.obedit->obmat, center);
+ ED_view3d_win_to_3d_int(vc.v3d, vc.ar, v_act->co, event->mval, center);
+ mul_m4_v3(vc.obedit->imat, center);
+
+ BMVert *v_new = BM_vert_create(bm, center, NULL, BM_CREATE_NOP);
+
+ BM_edge_create(bm, v_act, v_new, NULL, BM_CREATE_NOP);
+
+ BM_vert_select_set(bm, v_new, true);
+ }
+ }
+
+ if (changed) {
+ BM_select_history_clear(bm);
+
+ EDBM_mesh_normals_update(em);
+ EDBM_update_generic(em, true, true);
+
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
+}
+
+void MESH_OT_polybuild_face_at_cursor(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Poly Build Face At Cursor";
+ ot->idname = "MESH_OT_polybuild_face_at_cursor";
+ ot->description = "";
+
+ /* api callbacks */
+ ot->invoke = edbm_polybuild_face_at_cursor_invoke;
+ ot->poll = EDBM_view3d_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* to give to transform */
+ Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR_DUMMY);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Split At Cursor
+ * \{ */
+
+static int edbm_polybuild_split_at_cursor_invoke(
+ bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+{
+ ViewContext vc;
+ float center[3];
+ bool changed = false;
+
+ em_setup_viewcontext(C, &vc);
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+
+ invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
+ ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
+
+ edbm_selectmode_ensure(vc.scene, vc.em, SCE_SELECT_VERTEX);
+
+ BMElem *ele_act = BM_mesh_active_elem_get(bm);
+
+ if (ele_act == NULL || ele_act->head.hflag == BM_FACE) {
+ return OPERATOR_PASS_THROUGH;
+ }
+ else if (ele_act->head.htype == BM_EDGE) {
+ BMEdge *e_act = (BMEdge *)ele_act;
+ mid_v3_v3v3(center, e_act->v1->co, e_act->v2->co);
+ mul_m4_v3(vc.obedit->obmat, center);
+ ED_view3d_win_to_3d_int(vc.v3d, vc.ar, center, event->mval, center);
+ mul_m4_v3(vc.obedit->imat, center);
+
+ const float fac = line_point_factor_v3(center, e_act->v1->co, e_act->v2->co);
+ BMVert *v_new = BM_edge_split(bm, e_act, e_act->v1, NULL, CLAMPIS(fac, 0.0f, 1.0f));
+ copy_v3_v3(v_new->co, center);
+
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ BM_vert_select_set(bm, v_new, true);
+ changed = true;
+ }
+ else if (ele_act->head.htype == BM_VERT) {
+ /* Just do nothing, allow dragging. */
+ return OPERATOR_FINISHED;
+ }
+
+ if (changed) {
+ BM_select_history_clear(bm);
+
+ EDBM_mesh_normals_update(em);
+ EDBM_update_generic(em, true, true);
+
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
+}
+
+void MESH_OT_polybuild_split_at_cursor(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Poly Build Split At Cursor";
+ ot->idname = "MESH_OT_polybuild_split_at_cursor";
+ ot->description = "";
+
+ /* api callbacks */
+ ot->invoke = edbm_polybuild_split_at_cursor_invoke;
+ ot->poll = EDBM_view3d_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* to give to transform */
+ Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR_DUMMY);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Dissolve At Cursor
+ *
+ * \{ */
+
+static int edbm_polybuild_dissolve_at_cursor_invoke(
+ bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ ViewContext vc;
+ em_setup_viewcontext(C, &vc);
+ bool changed = false;
+
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ BMVert *v_act = BM_mesh_active_vert_get(bm);
+ BMEdge *e_act = BM_mesh_active_edge_get(bm);
+
+ invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
+ ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
+
+ edbm_selectmode_ensure(vc.scene, vc.em, SCE_SELECT_VERTEX);
+
+
+ if (e_act) {
+ BMLoop *l_a, *l_b;
+ if (BM_edge_loop_pair(e_act, &l_a, &l_b)) {
+ BMFace *f_new = BM_faces_join_pair(bm, l_a, l_b, true);
+ if (f_new) {
+ changed = true;
+ }
+ }
+ }
+ else if (v_act) {
+ if (BM_vert_is_edge_pair(v_act)) {
+ BM_edge_collapse(
+ bm, v_act->e, v_act,
+ true, true);
+ }
+ else {
+ /* too involved to do inline */
+ if (!EDBM_op_callf(em, op,
+ "dissolve_verts verts=%hv use_face_split=%b use_boundary_tear=%b",
+ BM_ELEM_SELECT, false, true))
+ {
+ return OPERATOR_CANCELLED;
+ }
+ }
+ changed = true;
+ }
+
+ if (changed) {
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+
+ BM_select_history_clear(bm);
+
+ EDBM_mesh_normals_update(em);
+ EDBM_update_generic(em, true, true);
+
+ WM_event_add_mousemove(C);
+
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
+}
+
+void MESH_OT_polybuild_dissolve_at_cursor(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Poly Build Dissolve At Cursor";
+ ot->idname = "MESH_OT_polybuild_dissolve_at_cursor";
+ ot->description = "";
+
+ /* api callbacks */
+ ot->invoke = edbm_polybuild_dissolve_at_cursor_invoke;
+ ot->poll = EDBM_view3d_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Cursor Manipulator
+ *
+ * \note This may need its own file, for now not.
+ * \{ */
+
+static BMElem *edbm_hover_preselect(
+ bContext *C,
+ const int mval[2],
+ bool use_boundary)
+{
+ ViewContext vc;
+
+ em_setup_viewcontext(C, &vc);
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+
+ invert_m4_m4(vc.obedit->imat, vc.obedit->obmat);
+ ED_view3d_init_mats_rv3d(vc.obedit, vc.rv3d);
+
+ const float mval_fl[2] = {UNPACK2(mval)};
+ float ray_origin[3], ray_direction[3];
+
+ BMElem *ele_best = NULL;
+
+ if (ED_view3d_win_to_ray(
+ CTX_data_depsgraph(C),
+ vc.ar, vc.v3d, mval_fl,
+ ray_origin, ray_direction, true))
+ {
+ BMEdge *e;
+
+ BMIter eiter;
+ float dist_sq_best = FLT_MAX;
+
+ BM_ITER_MESH (e, &eiter, bm, BM_EDGES_OF_MESH) {
+ if ((BM_elem_flag_test(e, BM_ELEM_HIDDEN) == false) &&
+ (!use_boundary || BM_edge_is_boundary(e)))
+ {
+ float dist_sq_test;
+ float point[3];
+ float depth;
+#if 0
+ dist_sq_test = dist_squared_ray_to_seg_v3(
+ ray_origin, ray_direction,
+ e->v1->co, e->v2->co,
+ point, &depth);
+#else
+ mid_v3_v3v3(point, e->v1->co, e->v2->co);
+ dist_sq_test = dist_squared_to_ray_v3(
+ ray_origin, ray_direction,
+ point, &depth);
+#endif
+
+ if (dist_sq_test < dist_sq_best) {
+ dist_sq_best = dist_sq_test;
+ ele_best = (BMElem *)e;
+ }
+
+ dist_sq_test = dist_squared_to_ray_v3(
+ ray_origin, ray_direction,
+ e->v1->co, &depth);
+ if (dist_sq_test < dist_sq_best) {
+ dist_sq_best = dist_sq_test;
+ ele_best = (BMElem *)e->v1;
+ }
+ dist_sq_test = dist_squared_to_ray_v3(
+ ray_origin, ray_direction,
+ e->v2->co, &depth);
+ if (dist_sq_test < dist_sq_best) {
+ dist_sq_best = dist_sq_test;
+ ele_best = (BMElem *)e->v2;
+ }
+ }
+ }
+ }
+ return ele_best;
+}
+
+/*
+ * Developer note: this is not advocating pre-selection highlighting.
+ * This is just a quick way to test how a tool for interactively editing polygons may work. */
+static int edbm_polybuild_hover_invoke(
+ bContext *C, wmOperator *op, const wmEvent *event)
+{
+ const bool use_boundary = RNA_boolean_get(op->ptr, "use_boundary");
+ ViewContext vc;
+
+ em_setup_viewcontext(C, &vc);
+
+ /* Vertex selection is needed */
+ if ((vc.scene->toolsettings->selectmode & SCE_SELECT_VERTEX) == 0) {
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ /* Don't overwrite click-drag events. */
+ if (use_boundary == false) {
+ /* pass */
+ }
+ else if (vc.win->tweak ||
+ (vc.win->eventstate->check_click &&
+ vc.win->eventstate->prevval == KM_PRESS &&
+ ISMOUSE(vc.win->eventstate->prevtype)))
+ {
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ BMElem *ele_active = BM_mesh_active_elem_get(bm);
+ BMElem *ele_hover = edbm_hover_preselect(C, event->mval, use_boundary);
+
+ if (ele_hover && (ele_hover != ele_active)) {
+ if (event->shift == 0) {
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ BM_select_history_clear(bm);
+ }
+ BM_elem_select_set(bm, ele_hover, true);
+ BM_select_history_store(em->bm, ele_hover);
+ BKE_mesh_batch_cache_dirty(obedit->data, BKE_MESH_BATCH_DIRTY_SELECT);
+
+ ED_region_tag_redraw(vc.ar);
+
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
+}
+
+void MESH_OT_polybuild_hover(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Poly Build Hover";
+ ot->idname = "MESH_OT_polybuild_hover";
+ ot->description = "";
+
+ /* api callbacks */
+ ot->invoke = edbm_polybuild_hover_invoke;
+ ot->poll = EDBM_view3d_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_INTERNAL;
+
+ /* properties */
+ RNA_def_boolean(ot->srna, "use_boundary", false, "Boundary", "Select only boundary geometry");
+}
+
+/** \} */
diff --git a/source/blender/editors/mesh/editmesh_select.c b/source/blender/editors/mesh/editmesh_select.c
index 019aa6d4201..2c50f5ae189 100644
--- a/source/blender/editors/mesh/editmesh_select.c
+++ b/source/blender/editors/mesh/editmesh_select.c
@@ -45,6 +45,7 @@
#include "BKE_report.h"
#include "BKE_paint.h"
#include "BKE_editmesh.h"
+#include "BKE_layer.h"
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -68,6 +69,9 @@
#include "bmesh_tools.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "mesh_intern.h" /* own include */
/* use bmesh operator flags for a few operators */
@@ -209,7 +213,9 @@ static BLI_bitmap *edbm_backbuf_alloc(const int size)
/* reads rect, and builds selection array for quick lookup */
/* returns if all is OK */
-bool EDBM_backbuf_border_init(ViewContext *vc, short xmin, short ymin, short xmax, short ymax)
+bool EDBM_backbuf_border_init(
+ ViewContext *vc, short xmin,
+ short ymin, short xmax, short ymax)
{
struct ImBuf *buf;
unsigned int *dr;
@@ -332,7 +338,9 @@ bool EDBM_backbuf_border_mask_init(ViewContext *vc, const int mcords[][2], short
}
/* circle shaped sample area */
-bool EDBM_backbuf_circle_init(ViewContext *vc, short xs, short ys, short rads)
+bool EDBM_backbuf_circle_init(
+ ViewContext *vc,
+ short xs, short ys, short rads)
{
struct ImBuf *buf;
unsigned int *dr;
@@ -649,16 +657,20 @@ BMEdge *EDBM_edge_find_nearest_ex(
unsigned int index;
BMEdge *eed;
- /* Make sure that the edges are considered for selection.
- * TODO: cleanup: add `selectmode` as a parameter */
+ /* Make sure that the edges also are considered to find nearest.
+ * TODO: cleanup: add `selectmode` as a parameter
+ * XXX: Without selectmode as parameter we need to resort to this super ugly hack,
+ * because we should never write to evaluate data. */
const short ts_selectmode = vc->scene->toolsettings->selectmode;
- vc->scene->toolsettings->selectmode |= SCE_SELECT_EDGE;
+
+ Scene *scene_eval = (Scene *)DEG_get_evaluated_id(vc->depsgraph, &vc->scene->id);
+ scene_eval->toolsettings->selectmode |= SCE_SELECT_EDGE;
/* No afterqueue (yet), so we check it now, otherwise the bm_xxxofs indices are bad. */
ED_view3d_backbuf_validate(vc);
/* restore `selectmode` */
- vc->scene->toolsettings->selectmode = ts_selectmode;
+ scene_eval->toolsettings->selectmode = ts_selectmode;
index = ED_view3d_backbuf_sample_rect(vc, vc->mval, dist_px, bm_solidoffs, bm_wireoffs, &dist_test);
eed = index ? BM_edge_at_index_find_or_table(bm, index - 1) : NULL;
@@ -909,7 +921,9 @@ BMFace *EDBM_face_find_nearest(ViewContext *vc, float *r_dist)
* selected vertices and edges get disadvantage
* return 1 if found one
*/
-static int unified_findnearest(ViewContext *vc, BMVert **r_eve, BMEdge **r_eed, BMFace **r_efa)
+static bool unified_findnearest(
+ ViewContext *vc,
+ Base **r_base, BMVert **r_eve, BMEdge **r_eed, BMFace **r_efa)
{
BMEditMesh *em = vc->em;
static short mval_prev[2] = {-1, -1};
@@ -919,66 +933,138 @@ static int unified_findnearest(ViewContext *vc, BMVert **r_eve, BMEdge **r_eed,
/* since edges select lines, we give dots advantage of ~20 pix */
const float dist_margin = (dist_init / 2);
float dist = dist_init;
- BMFace *efa_zbuf = NULL;
- BMEdge *eed_zbuf = NULL;
-
- BMVert *eve = NULL;
- BMEdge *eed = NULL;
- BMFace *efa = NULL;
+ struct {
+ struct {
+ BMVert *ele;
+ Base *base;
+ } v;
+ struct {
+ BMEdge *ele;
+ Base *base;
+ } e, e_zbuf;
+ struct {
+ BMFace *ele;
+ Base *base;
+ } f, f_zbuf;
+ } hit = {{NULL}};
+
+ /* TODO(campbell): perform selection as one pass
+ * instead of many smaller passes (which doesn't work for zbuf occlusion). */
+ uint bases_len = 0;
+ Base **bases = BKE_view_layer_array_from_bases_in_edit_mode(vc->view_layer, &bases_len);
/* no afterqueue (yet), so we check it now, otherwise the em_xxxofs indices are bad */
- ED_view3d_backbuf_validate(vc);
if ((dist > 0.0f) && em->selectmode & SCE_SELECT_FACE) {
float dist_center = 0.0f;
float *dist_center_p = (em->selectmode & (SCE_SELECT_EDGE | SCE_SELECT_VERTEX)) ? &dist_center : NULL;
- efa = EDBM_face_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &efa_zbuf);
- if (efa && dist_center_p) {
- dist = min_ff(dist_margin, dist_center);
- }
+
+ for (uint base_index = 0; base_index < bases_len; base_index++) {
+ Base *base_iter = bases[base_index];
+ Object *obedit = base_iter->object;
+ ED_view3d_viewcontext_init_object(vc, obedit);
+ ED_view3d_backbuf_validate(vc);
+ BMFace *efa_zbuf = NULL;
+ BMFace *efa_test = EDBM_face_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &efa_zbuf);
+ if (hit.f.ele && dist_center_p) {
+ dist = min_ff(dist_margin, dist_center);
+ }
+ if (efa_test) {
+ hit.f.base = base_iter;
+ hit.f.ele = efa_test;
+ }
+ if (efa_zbuf) {
+ hit.f_zbuf.base = base_iter;
+ hit.f_zbuf.ele = efa_zbuf;
+ }
+ } /* bases */
}
if ((dist > 0.0f) && (em->selectmode & SCE_SELECT_EDGE)) {
float dist_center = 0.0f;
float *dist_center_p = (em->selectmode & SCE_SELECT_VERTEX) ? &dist_center : NULL;
- eed = EDBM_edge_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &eed_zbuf);
- if (eed && dist_center_p) {
- dist = min_ff(dist_margin, dist_center);
- }
+
+ for (uint base_index = 0; base_index < bases_len; base_index++) {
+ Base *base_iter = bases[base_index];
+ Object *obedit = base_iter->object;
+ ED_view3d_viewcontext_init_object(vc, obedit);
+ ED_view3d_backbuf_validate(vc);
+ BMEdge *eed_zbuf = NULL;
+ BMEdge *eed_test = EDBM_edge_find_nearest_ex(vc, &dist, dist_center_p, true, use_cycle, &eed_zbuf);
+ if (hit.e.ele && dist_center_p) {
+ dist = min_ff(dist_margin, dist_center);
+ }
+ if (eed_test) {
+ hit.e.base = base_iter;
+ hit.e.ele = eed_test;
+ }
+ if (eed_zbuf) {
+ hit.e_zbuf.base = base_iter;
+ hit.e_zbuf.ele = eed_zbuf;
+ }
+ } /* bases */
}
if ((dist > 0.0f) && em->selectmode & SCE_SELECT_VERTEX) {
- eve = EDBM_vert_find_nearest_ex(vc, &dist, true, use_cycle);
+ for (uint base_index = 0; base_index < bases_len; base_index++) {
+ Base *base_iter = bases[base_index];
+ Object *obedit = base_iter->object;
+ ED_view3d_viewcontext_init_object(vc, obedit);
+ ED_view3d_backbuf_validate(vc);
+ BMVert *eve_test = EDBM_vert_find_nearest_ex(vc, &dist, true, use_cycle);
+ if (eve_test) {
+ hit.v.base = base_iter;
+ hit.v.ele = eve_test;
+ }
+ } /* bases */
}
+ MEM_SAFE_FREE(bases);
+
/* return only one of 3 pointers, for frontbuffer redraws */
- if (eve) {
- efa = NULL; eed = NULL;
+ if (hit.v.ele) {
+ hit.f.ele = NULL;
+ hit.e.ele = NULL;
}
- else if (eed) {
- efa = NULL;
+ else if (hit.e.ele) {
+ hit.f.ele = NULL;
}
/* there may be a face under the cursor, who's center if too far away
* use this if all else fails, it makes sense to select this */
- if ((eve || eed || efa) == 0) {
- if (eed_zbuf) {
- eed = eed_zbuf;
+ if ((hit.v.ele || hit.e.ele || hit.f.ele) == 0) {
+ if (hit.e_zbuf.ele) {
+ hit.e.base = hit.e_zbuf.base;
+ hit.e.ele = hit.e_zbuf.ele;
}
- else if (efa_zbuf) {
- efa = efa_zbuf;
+ else if (hit.f_zbuf.ele) {
+ hit.f.base = hit.f_zbuf.base;
+ hit.f.ele = hit.f_zbuf.ele;
}
}
mval_prev[0] = vc->mval[0];
mval_prev[1] = vc->mval[1];
+
+ /* Only one element type will be non-null. */
+ BLI_assert(((hit.v.ele != NULL) + (hit.e.ele != NULL) + (hit.f.ele != NULL)) <= 1);
+
+ if (hit.v.ele) {
+ *r_base = hit.v.base;
+ }
+ if (hit.e.ele) {
+ *r_base = hit.e.base;
+ }
+ if (hit.f.ele) {
+ *r_base = hit.f.base;
+ }
- *r_eve = eve;
- *r_eed = eed;
- *r_efa = efa;
+ *r_eve = hit.v.ele;
+ *r_eed = hit.e.ele;
+ *r_efa = hit.f.ele;
- return (eve || eed || efa);
+ return (hit.v.ele || hit.e.ele || hit.f.ele);
}
/** \} */
@@ -1014,13 +1100,13 @@ static const EnumPropertyItem prop_similar_types[] = {
#endif
{SIMFACE_MATERIAL, "MATERIAL", 0, "Material", ""},
- {SIMFACE_IMAGE, "IMAGE", 0, "Image", ""},
{SIMFACE_AREA, "AREA", 0, "Area", ""},
{SIMFACE_SIDES, "SIDES", 0, "Polygon Sides", ""},
{SIMFACE_PERIMETER, "PERIMETER", 0, "Perimeter", ""},
{SIMFACE_NORMAL, "NORMAL", 0, "Normal", ""},
{SIMFACE_COPLANAR, "COPLANAR", 0, "Co-planar", ""},
{SIMFACE_SMOOTH, "SMOOTH", 0, "Flat/Smooth", ""},
+ {SIMFACE_FACEMAP, "FACE_MAP", 0, "Face-Map", ""},
#ifdef WITH_FREESTYLE
{SIMFACE_FREESTYLE, "FREESTYLE_FACE", 0, "Freestyle Face Marks", ""},
#endif
@@ -1199,7 +1285,7 @@ static const EnumPropertyItem *select_similar_type_itemf(
#ifdef WITH_FREESTYLE
const int a_end = SIMFACE_FREESTYLE;
#else
- const int a_end = SIMFACE_SMOOTH;
+ const int a_end = SIMFACE_FACEMAP;
#endif
for (a = SIMFACE_MATERIAL; a <= a_end; a++) {
RNA_enum_items_add_value(&item, &totitem, prop_similar_types, a);
@@ -1794,27 +1880,43 @@ void MESH_OT_edgering_select(wmOperatorType *ot)
static int edbm_select_all_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- const int action = RNA_enum_get(op->ptr, "action");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ int action = RNA_enum_get(op->ptr, "action");
+
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ if (action == SEL_TOGGLE) {
+ action = SEL_SELECT;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel) {
+ action = SEL_DESELECT;
+ break;
+ }
+ }
+ }
- switch (action) {
- case SEL_TOGGLE:
- EDBM_select_toggle_all(em);
- break;
- case SEL_SELECT:
- EDBM_flag_enable_all(em, BM_ELEM_SELECT);
- break;
- case SEL_DESELECT:
- EDBM_flag_disable_all(em, BM_ELEM_SELECT);
- break;
- case SEL_INVERT:
- EDBM_select_swap(em);
- EDBM_selectmode_flush(em);
- break;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ switch (action) {
+ case SEL_SELECT:
+ EDBM_flag_enable_all(em, BM_ELEM_SELECT);
+ break;
+ case SEL_DESELECT:
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ break;
+ case SEL_INVERT:
+ EDBM_select_swap(em);
+ EDBM_selectmode_flush(em);
+ break;
+ }
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
}
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ MEM_SAFE_FREE(objects);
return OPERATOR_FINISHED;
}
@@ -1885,6 +1987,8 @@ void MESH_OT_select_interior_faces(wmOperatorType *ot)
bool EDBM_select_pick(bContext *C, const int mval[2], bool extend, bool deselect, bool toggle)
{
ViewContext vc;
+
+ Base *basact = NULL;
BMVert *eve = NULL;
BMEdge *eed = NULL;
BMFace *efa = NULL;
@@ -1894,11 +1998,23 @@ bool EDBM_select_pick(bContext *C, const int mval[2], bool extend, bool deselect
vc.mval[0] = mval[0];
vc.mval[1] = mval[1];
- if (unified_findnearest(&vc, &eve, &eed, &efa)) {
+ if (unified_findnearest(&vc, &basact, &eve, &eed, &efa)) {
+ ED_view3d_viewcontext_init_object(&vc, basact->object);
/* Deselect everything */
- if (extend == false && deselect == false && toggle == false)
- EDBM_flag_disable_all(vc.em, BM_ELEM_SELECT);
+ if (extend == false && deselect == false && toggle == false) {
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc.view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ EDBM_flag_disable_all(BKE_editmesh_from_object(ob_iter), BM_ELEM_SELECT);
+ if (basact->object != ob_iter) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data);
+ }
+ }
+ MEM_SAFE_FREE(objects);
+ }
if (efa) {
if (extend) {
@@ -1981,16 +2097,41 @@ bool EDBM_select_pick(bContext *C, const int mval[2], bool extend, bool deselect
EDBM_selectmode_flush(vc.em);
- /* change active material on object */
- if (efa && efa->mat_nr != vc.obedit->actcol - 1) {
- vc.obedit->actcol = efa->mat_nr + 1;
- vc.em->mat_nr = efa->mat_nr;
+ if (efa) {
+ /* Change active material on object. */
+ if (efa->mat_nr != vc.obedit->actcol - 1) {
+ vc.obedit->actcol = efa->mat_nr + 1;
+ vc.em->mat_nr = efa->mat_nr;
+ WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, NULL);
+ }
- WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, NULL);
+ /* Change active face-map on object. */
+ if (!BLI_listbase_is_empty(&vc.obedit->fmaps)) {
+ const int cd_fmap_offset = CustomData_get_offset(&vc.em->bm->pdata, CD_FACEMAP);
+ if (cd_fmap_offset != -1) {
+ int map = *((int *)BM_ELEM_CD_GET_VOID_P(efa, cd_fmap_offset));
+ if ((map < -1) || (map > BLI_listbase_count_at_most(&vc.obedit->fmaps, map))) {
+ map = -1;
+ }
+ map += 1;
+ if (map != vc.obedit->actfmap) {
+ /* We may want to add notifiers later,
+ * currently select update handles redraw. */
+ vc.obedit->actfmap = map;
+ }
+ }
+ }
}
+ /* Changing active object is handy since it allows us to
+ * switch UV layers, vgroups for eg. */
+ if (vc.view_layer->basact != basact) {
+ vc.view_layer->basact = basact;
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, vc.scene);
+ }
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
+
return true;
}
@@ -2212,6 +2353,8 @@ bool EDBM_selectmode_toggle(
bContext *C, const short selectmode_new,
const int action, const bool use_extend, const bool use_expand)
{
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
ToolSettings *ts = CTX_data_tool_settings(C);
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = NULL;
@@ -2225,6 +2368,7 @@ bool EDBM_selectmode_toggle(
return ret;
}
+ bool only_update = false;
switch (action) {
case -1:
/* already set */
@@ -2232,21 +2376,24 @@ bool EDBM_selectmode_toggle(
case 0: /* disable */
/* check we have something to do */
if ((em->selectmode & selectmode_new) == 0) {
- return false;
+ only_update = true;
+ break;
}
em->selectmode &= ~selectmode_new;
break;
case 1: /* enable */
/* check we have something to do */
if ((em->selectmode & selectmode_new) != 0) {
- return false;
+ only_update = true;
+ break;
}
em->selectmode |= selectmode_new;
break;
case 2: /* toggle */
/* can't disable this flag if its the only one set */
if (em->selectmode == selectmode_new) {
- return false;
+ only_update = true;
+ break;
}
em->selectmode ^= selectmode_new;
break;
@@ -2255,10 +2402,30 @@ bool EDBM_selectmode_toggle(
break;
}
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
+ if (em_iter != em) {
+ em_iter->selectmode = em->selectmode;
+ }
+ }
+
+ if (only_update) {
+ MEM_SAFE_FREE(objects);
+ return false;
+ }
+
if (use_extend == 0 || em->selectmode == 0) {
if (use_expand) {
const short selmode_max = highest_order_bit_s(ts->selectmode);
- EDBM_selectmode_convert(em, selmode_max, selectmode_new);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
+ EDBM_selectmode_convert(em_iter, selmode_max, selectmode_new);
+ }
}
}
@@ -2267,24 +2434,18 @@ bool EDBM_selectmode_toggle(
if (use_extend == 0 || em->selectmode == 0) {
em->selectmode = SCE_SELECT_VERTEX;
}
- ts->selectmode = em->selectmode;
- EDBM_selectmode_set(em);
ret = true;
break;
case SCE_SELECT_EDGE:
if (use_extend == 0 || em->selectmode == 0) {
em->selectmode = SCE_SELECT_EDGE;
}
- ts->selectmode = em->selectmode;
- EDBM_selectmode_set(em);
ret = true;
break;
case SCE_SELECT_FACE:
if (use_extend == 0 || em->selectmode == 0) {
em->selectmode = SCE_SELECT_FACE;
}
- ts->selectmode = em->selectmode;
- EDBM_selectmode_set(em);
ret = true;
break;
default:
@@ -2293,10 +2454,20 @@ bool EDBM_selectmode_toggle(
}
if (ret == true) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ ts->selectmode = em->selectmode;
+ em = NULL;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ BMEditMesh *em_iter = BKE_editmesh_from_object(ob_iter);
+ EDBM_selectmode_set(em_iter);
+ DEG_id_tag_update(ob_iter->data, DEG_TAG_COPY_ON_WRITE);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, ob_iter->data);
+ }
WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL);
+ DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
}
+ MEM_SAFE_FREE(objects);
return ret;
}
@@ -2498,7 +2669,7 @@ static bool select_linked_delimit_test(
* Gets the default from the operator fallback to own last-used value
* (selected based on mode)
*/
-static int select_linked_delimit_default_from_op(wmOperator *op, int select_mode)
+static int select_linked_delimit_default_from_op(wmOperator *op, const int select_mode)
{
static char delimit_last_store[2] = {0, BMO_DELIM_SEAM};
int delimit_last_index = (select_mode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) == 0;
@@ -2564,172 +2735,186 @@ static void select_linked_delimit_end(BMEditMesh *em)
static int edbm_select_linked_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMesh *bm = em->bm;
- BMIter iter;
- BMWalker walker;
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
#ifdef USE_LINKED_SELECT_DEFAULT_HACK
- int delimit = select_linked_delimit_default_from_op(op, em->selectmode);
+ const int delimit_init = select_linked_delimit_default_from_op(op, scene->toolsettings->selectmode);
#else
- int delimit = RNA_enum_get(op->ptr, "delimit");
+ const int delimit_init = RNA_enum_get(op->ptr, "delimit");
#endif
- select_linked_delimit_validate(bm, &delimit);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- if (delimit) {
- select_linked_delimit_begin(em->bm, delimit);
- }
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
- if (em->selectmode & SCE_SELECT_VERTEX) {
- BMVert *v;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ BMIter iter;
+ BMWalker walker;
- BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
- BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT));
- }
+ int delimit = delimit_init;
+
+ select_linked_delimit_validate(bm, &delimit);
- /* exclude all delimited verts */
if (delimit) {
- BMEdge *e;
- BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (!BMO_edge_flag_test(bm, e, BMO_ELE_TAG)) {
- BM_elem_flag_disable(e->v1, BM_ELEM_TAG);
- BM_elem_flag_disable(e->v2, BM_ELEM_TAG);
- }
- }
+ select_linked_delimit_begin(em->bm, delimit);
}
- BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL,
- BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP,
- BMW_FLAG_TEST_HIDDEN,
- BMW_NIL_LAY);
+ if (em->selectmode & SCE_SELECT_VERTEX) {
+ BMVert *v;
- if (delimit) {
BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
- BMElem *ele_walk;
- BMW_ITER (ele_walk, &walker, v) {
- if (ele_walk->head.htype == BM_LOOP) {
- BMVert *v_step = ((BMLoop *)ele_walk)->v;
- BM_vert_select_set(em->bm, v_step, true);
- BM_elem_flag_disable(v_step, BM_ELEM_TAG);
- }
- else {
- BMEdge *e_step = (BMEdge *)ele_walk;
- BLI_assert(ele_walk->head.htype == BM_EDGE);
- BM_edge_select_set(em->bm, e_step, true);
- BM_elem_flag_disable(e_step->v1, BM_ELEM_TAG);
- BM_elem_flag_disable(e_step->v2, BM_ELEM_TAG);
+ BM_elem_flag_set(v, BM_ELEM_TAG, BM_elem_flag_test(v, BM_ELEM_SELECT));
+ }
+
+ /* exclude all delimited verts */
+ if (delimit) {
+ BMEdge *e;
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (!BMO_edge_flag_test(bm, e, BMO_ELE_TAG)) {
+ BM_elem_flag_disable(e->v1, BM_ELEM_TAG);
+ BM_elem_flag_disable(e->v2, BM_ELEM_TAG);
+ }
+ }
+ }
+
+ BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL,
+ BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP,
+ BMW_FLAG_TEST_HIDDEN,
+ BMW_NIL_LAY);
+
+ if (delimit) {
+ BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
+ if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
+ BMElem *ele_walk;
+ BMW_ITER (ele_walk, &walker, v) {
+ if (ele_walk->head.htype == BM_LOOP) {
+ BMVert *v_step = ((BMLoop *)ele_walk)->v;
+ BM_vert_select_set(em->bm, v_step, true);
+ BM_elem_flag_disable(v_step, BM_ELEM_TAG);
+ }
+ else {
+ BMEdge *e_step = (BMEdge *)ele_walk;
+ BLI_assert(ele_walk->head.htype == BM_EDGE);
+ BM_edge_select_set(em->bm, e_step, true);
+ BM_elem_flag_disable(e_step->v1, BM_ELEM_TAG);
+ BM_elem_flag_disable(e_step->v2, BM_ELEM_TAG);
+ }
}
}
}
}
- }
- else {
- BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
- BMEdge *e_walk;
- BMW_ITER (e_walk, &walker, v) {
- BM_edge_select_set(em->bm, e_walk, true);
- BM_elem_flag_disable(e_walk, BM_ELEM_TAG);
+ else {
+ BM_ITER_MESH (v, &iter, em->bm, BM_VERTS_OF_MESH) {
+ if (BM_elem_flag_test(v, BM_ELEM_TAG)) {
+ BMEdge *e_walk;
+ BMW_ITER (e_walk, &walker, v) {
+ BM_edge_select_set(em->bm, e_walk, true);
+ BM_elem_flag_disable(e_walk, BM_ELEM_TAG);
+ }
}
}
}
- }
- BMW_end(&walker);
+ BMW_end(&walker);
- EDBM_selectmode_flush(em);
- }
- else if (em->selectmode & SCE_SELECT_EDGE) {
- BMEdge *e;
+ EDBM_selectmode_flush(em);
+ }
+ else if (em->selectmode & SCE_SELECT_EDGE) {
+ BMEdge *e;
- if (delimit) {
- BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
- BM_elem_flag_set(
- e, BM_ELEM_TAG,
- (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_edge_flag_test(bm, e, BMO_ELE_TAG)));
+ if (delimit) {
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ BM_elem_flag_set(
+ e, BM_ELEM_TAG,
+ (BM_elem_flag_test(e, BM_ELEM_SELECT) && BMO_edge_flag_test(bm, e, BMO_ELE_TAG)));
+ }
}
- }
- else {
- BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
- BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT));
+ else {
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ BM_elem_flag_set(e, BM_ELEM_TAG, BM_elem_flag_test(e, BM_ELEM_SELECT));
+ }
}
- }
-
- BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL,
- BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP,
- BMW_FLAG_TEST_HIDDEN,
- BMW_NIL_LAY);
- if (delimit) {
- BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
- BMElem *ele_walk;
- BMW_ITER (ele_walk, &walker, e) {
- if (ele_walk->head.htype == BM_LOOP) {
- BMLoop *l_step = (BMLoop *)ele_walk;
- BM_edge_select_set(em->bm, l_step->e, true);
- BM_edge_select_set(em->bm, l_step->prev->e, true);
- BM_elem_flag_disable(l_step->e, BM_ELEM_TAG);
- }
- else {
- BMEdge *e_step = (BMEdge *)ele_walk;
- BLI_assert(ele_walk->head.htype == BM_EDGE);
- BM_edge_select_set(em->bm, e_step, true);
- BM_elem_flag_disable(e_step, BM_ELEM_TAG);
+ BMW_init(&walker, em->bm, delimit ? BMW_LOOP_SHELL_WIRE : BMW_VERT_SHELL,
+ BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP,
+ BMW_FLAG_TEST_HIDDEN,
+ BMW_NIL_LAY);
+
+ if (delimit) {
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+ BMElem *ele_walk;
+ BMW_ITER (ele_walk, &walker, e) {
+ if (ele_walk->head.htype == BM_LOOP) {
+ BMLoop *l_step = (BMLoop *)ele_walk;
+ BM_edge_select_set(em->bm, l_step->e, true);
+ BM_edge_select_set(em->bm, l_step->prev->e, true);
+ BM_elem_flag_disable(l_step->e, BM_ELEM_TAG);
+ }
+ else {
+ BMEdge *e_step = (BMEdge *)ele_walk;
+ BLI_assert(ele_walk->head.htype == BM_EDGE);
+ BM_edge_select_set(em->bm, e_step, true);
+ BM_elem_flag_disable(e_step, BM_ELEM_TAG);
+ }
}
}
}
}
- }
- else {
- BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
- BMEdge *e_walk;
- BMW_ITER (e_walk, &walker, e) {
- BM_edge_select_set(em->bm, e_walk, true);
- BM_elem_flag_disable(e_walk, BM_ELEM_TAG);
+ else {
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (BM_elem_flag_test(e, BM_ELEM_TAG)) {
+ BMEdge *e_walk;
+ BMW_ITER (e_walk, &walker, e) {
+ BM_edge_select_set(em->bm, e_walk, true);
+ BM_elem_flag_disable(e_walk, BM_ELEM_TAG);
+ }
}
}
}
- }
- BMW_end(&walker);
-
- EDBM_selectmode_flush(em);
- }
- else {
- BMFace *f;
+ BMW_end(&walker);
- BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
- BM_elem_flag_set(f, BM_ELEM_TAG, BM_elem_flag_test(f, BM_ELEM_SELECT));
+ EDBM_selectmode_flush(em);
}
+ else {
+ BMFace *f;
- BMW_init(&walker, bm, BMW_ISLAND,
- BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP,
- BMW_FLAG_TEST_HIDDEN,
- BMW_NIL_LAY);
+ BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
+ BM_elem_flag_set(f, BM_ELEM_TAG, BM_elem_flag_test(f, BM_ELEM_SELECT));
+ }
- BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(f, BM_ELEM_TAG)) {
- BMFace *f_walk;
- BMW_ITER (f_walk, &walker, f) {
- BM_face_select_set(bm, f_walk, true);
- BM_elem_flag_disable(f_walk, BM_ELEM_TAG);
+ BMW_init(&walker, bm, BMW_ISLAND,
+ BMW_MASK_NOP, delimit ? BMO_ELE_TAG : BMW_MASK_NOP, BMW_MASK_NOP,
+ BMW_FLAG_TEST_HIDDEN,
+ BMW_NIL_LAY);
+
+ BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (BM_elem_flag_test(f, BM_ELEM_TAG)) {
+ BMFace *f_walk;
+ BMW_ITER (f_walk, &walker, f) {
+ BM_face_select_set(bm, f_walk, true);
+ BM_elem_flag_disable(f_walk, BM_ELEM_TAG);
+ }
}
}
+
+ BMW_end(&walker);
}
- BMW_end(&walker);
- }
+ if (delimit) {
+ select_linked_delimit_end(em);
+ }
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
- if (delimit) {
- select_linked_delimit_end(em);
}
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ MEM_SAFE_FREE(objects);
return OPERATOR_FINISHED;
}
@@ -2872,10 +3057,8 @@ static void edbm_select_linked_pick_ex(BMEditMesh *em, BMElem *ele, bool sel, in
static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- Object *obedit = CTX_data_edit_object(C);
ViewContext vc;
- BMEditMesh *em;
- BMesh *bm;
+ Base *basact = NULL;
BMVert *eve;
BMEdge *eed;
BMFace *efa;
@@ -2891,25 +3074,37 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmE
/* setup view context for argument to callbacks */
em_setup_viewcontext(C, &vc);
- em = vc.em;
- bm = em->bm;
- if (bm->totedge == 0) {
- return OPERATOR_CANCELLED;
+ {
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc.view_layer, &objects_len);
+ bool has_edges = false;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ ED_view3d_viewcontext_init_object(&vc, ob_iter);
+ if (vc.em->bm->totedge) {
+ has_edges = true;
+ }
+ }
+ MEM_SAFE_FREE(objects);
+ if (has_edges == false) {
+ return OPERATOR_CANCELLED;
+ }
}
vc.mval[0] = event->mval[0];
vc.mval[1] = event->mval[1];
/* return warning! */
- if (unified_findnearest(&vc, &eve, &eed, &efa) == 0) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
-
+ if (unified_findnearest(&vc, &basact, &eve, &eed, &efa) == 0) {
return OPERATOR_CANCELLED;
}
+ ED_view3d_viewcontext_init_object(&vc, basact->object);
+ BMEditMesh *em = vc.em;
+ BMesh *bm = em->bm;
#ifdef USE_LINKED_SELECT_DEFAULT_HACK
- int delimit = select_linked_delimit_default_from_op(op, em->selectmode);
+ int delimit = select_linked_delimit_default_from_op(op, vc.scene->toolsettings->selectmode);
#else
int delimit = RNA_enum_get(op->ptr, "delimit");
#endif
@@ -2922,9 +3117,11 @@ static int edbm_select_linked_pick_invoke(bContext *C, wmOperator *op, const wmE
BM_mesh_elem_index_ensure(bm, ele->head.htype);
index = EDBM_elem_to_index_any(em, ele);
+ /* TODO(MULTI_EDIT), index doesn't know which object,
+ * index selections isn't very common. */
RNA_int_set(op->ptr, "index", index);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, basact->object->data);
return OPERATOR_FINISHED;
}
@@ -3204,13 +3401,28 @@ void MESH_OT_select_mirror(wmOperatorType *ot)
static int edbm_select_more_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
const bool use_face_step = RNA_boolean_get(op->ptr, "use_face_step");
- EDBM_select_more(em, use_face_step);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ if ((bm->totvertsel == 0) &&
+ (bm->totedgesel == 0) &&
+ (bm->totfacesel == 0))
+ {
+ continue;
+ }
+
+ EDBM_select_more(em, use_face_step);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
+
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -3239,13 +3451,28 @@ void MESH_OT_select_more(wmOperatorType *ot)
static int edbm_select_less_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
const bool use_face_step = RNA_boolean_get(op->ptr, "use_face_step");
- EDBM_select_less(em, use_face_step);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ if ((bm->totvertsel == 0) &&
+ (bm->totedgesel == 0) &&
+ (bm->totfacesel == 0))
+ {
+ continue;
+ }
+
+ EDBM_select_less(em, use_face_step);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
+
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mesh/editmesh_tools.c b/source/blender/editors/mesh/editmesh_tools.c
index 683e69a4ff6..90bd6bed47e 100644
--- a/source/blender/editors/mesh/editmesh_tools.c
+++ b/source/blender/editors/mesh/editmesh_tools.c
@@ -47,15 +47,18 @@
#include "BLI_rand.h"
#include "BLI_sort_utils.h"
+#include "BKE_layer.h"
#include "BKE_material.h"
#include "BKE_context.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_report.h"
#include "BKE_texture.h"
#include "BKE_main.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "BLT_translation.h"
#include "RNA_define.h"
@@ -90,10 +93,8 @@
static int edbm_subdivide_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
const int cuts = RNA_int_get(op->ptr, "number_cuts");
- float smooth = RNA_float_get(op->ptr, "smoothness");
+ const float smooth = RNA_float_get(op->ptr, "smoothness");
const float fractal = RNA_float_get(op->ptr, "fractal") / 2.5f;
const float along_normal = RNA_float_get(op->ptr, "fractal_along_normal");
@@ -102,17 +103,35 @@ static int edbm_subdivide_exec(bContext *C, wmOperator *op)
{
RNA_enum_set(op->ptr, "quadcorner", SUBD_CORNER_INNERVERT);
}
+ const int quad_corner_type = RNA_enum_get(op->ptr, "quadcorner");
+ const bool use_quad_tri = RNA_boolean_get(op->ptr, "quadtri");
+ const int seed = RNA_int_get(op->ptr, "seed");
- BM_mesh_esubdivide(
- em->bm, BM_ELEM_SELECT,
- smooth, SUBD_FALLOFF_LIN, false,
- fractal, along_normal,
- cuts,
- SUBDIV_SELECT_ORIG, RNA_enum_get(op->ptr, "quadcorner"),
- RNA_boolean_get(op->ptr, "quadtri"), true, false,
- RNA_int_get(op->ptr, "seed"));
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- EDBM_update_generic(em, true, true);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+
+ if (!(em->bm->totedgesel || em->bm->totfacesel)) {
+ continue;
+ }
+
+ BM_mesh_esubdivide(
+ em->bm, BM_ELEM_SELECT,
+ smooth, SUBD_FALLOFF_LIN, false,
+ fractal, along_normal,
+ cuts,
+ SUBDIV_SELECT_ORIG, quad_corner_type,
+ use_quad_tri, true, false,
+ seed);
+
+ EDBM_update_generic(em, true, true);
+ }
+
+ MEM_SAFE_FREE(objects);
return OPERATOR_FINISHED;
}
@@ -149,6 +168,8 @@ void MESH_OT_subdivide(wmOperatorType *ot)
RNA_def_float(ot->srna, "smoothness", 0.0f, 0.0f, 1e3f, "Smoothness", "Smoothness factor", 0.0f, 1.0f);
+ WM_operatortype_props_advanced_begin(ot);
+
RNA_def_boolean(ot->srna, "quadtri", 0, "Quad/Tri Mode", "Tries to prevent ngons");
RNA_def_enum(ot->srna, "quadcorner", prop_mesh_cornervert_types, SUBD_CORNER_STRAIGHT_CUT,
"Quad Corner Type", "How to subdivide quad corners (anything other than Straight Cut will prevent ngons)");
@@ -269,27 +290,39 @@ void MESH_OT_subdivide_edgering(wmOperatorType *ot)
static int edbm_unsubdivide_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMOperator bmop;
-
const int iterations = RNA_int_get(op->ptr, "iterations");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- EDBM_op_init(em, &bmop, op,
- "unsubdivide verts=%hv iterations=%i", BM_ELEM_SELECT, iterations);
+ if ((em->bm->totvertsel == 0) &&
+ (em->bm->totedgesel == 0) &&
+ (em->bm->totfacesel == 0))
+ {
+ continue;
+ }
- BMO_op_exec(em->bm, &bmop);
+ BMOperator bmop;
+ EDBM_op_init(em, &bmop, op,
+ "unsubdivide verts=%hv iterations=%i", BM_ELEM_SELECT, iterations);
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return 0;
- }
+ BMO_op_exec(em->bm, &bmop);
- if ((em->selectmode & SCE_SELECT_VERTEX) == 0) {
- EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); /* need to flush vert->face first */
- }
- EDBM_selectmode_flush(em);
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
- EDBM_update_generic(em, true, true);
+ if ((em->selectmode & SCE_SELECT_VERTEX) == 0) {
+ EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX); /* need to flush vert->face first */
+ }
+ EDBM_selectmode_flush(em);
+
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -321,7 +354,7 @@ void EMBM_project_snap_verts(bContext *C, ARegion *ar, BMEditMesh *em)
ED_view3d_init_mats_rv3d(obedit, ar->regiondata);
struct SnapObjectContext *snap_context = ED_transform_snap_object_context_create_view3d(
- CTX_data_main(C), CTX_data_scene(C), 0,
+ CTX_data_main(C), CTX_data_scene(C), CTX_data_depsgraph(C), 0,
ar, CTX_wm_view3d(C));
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
@@ -362,52 +395,79 @@ enum {
MESH_DELETE_ONLY_FACE = 4,
};
-static void edbm_report_delete_info(ReportList *reports, BMesh *bm, const int totelem[3])
+static void edbm_report_delete_info(ReportList *reports, const int totelem_old[3], const int totelem_new[3])
{
BKE_reportf(reports, RPT_INFO,
"Removed: %d vertices, %d edges, %d faces",
- totelem[0] - bm->totvert, totelem[1] - bm->totedge, totelem[2] - bm->totface);
+ totelem_old[0] - totelem_new[0], totelem_old[1] - totelem_new[1], totelem_old[2] - totelem_new[2]);
}
static int edbm_delete_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- const int type = RNA_enum_get(op->ptr, "type");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- switch (type) {
- case MESH_DELETE_VERT:
- if (!EDBM_op_callf(em, op, "delete geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)) /* Erase Vertices */
- return OPERATOR_CANCELLED;
- break;
- case MESH_DELETE_EDGE:
- if (!EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_EDGES)) /* Erase Edges */
- return OPERATOR_CANCELLED;
- break;
- case MESH_DELETE_FACE:
- if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)) /* Erase Faces */
- return OPERATOR_CANCELLED;
- break;
- case MESH_DELETE_EDGE_FACE:
- /* Edges and Faces */
- if (!EDBM_op_callf(em, op, "delete geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES))
- return OPERATOR_CANCELLED;
- break;
- case MESH_DELETE_ONLY_FACE:
- /* Only faces. */
- if (!EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_ONLYFACES))
- return OPERATOR_CANCELLED;
- break;
- default:
- BLI_assert(0);
- break;
- }
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ bool changed_multi = false;
- EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ const int type = RNA_enum_get(op->ptr, "type");
- EDBM_update_generic(em, true, true);
+ switch (type) {
+ case MESH_DELETE_VERT: /* Erase Vertices */
+ if (!(em->bm->totvertsel &&
+ EDBM_op_callf(em, op, "delete geom=%hv context=%i", BM_ELEM_SELECT, DEL_VERTS)))
+ {
+ continue;
+ }
+ break;
+ case MESH_DELETE_EDGE: /* Erase Edges */
+ if (!(em->bm->totedgesel &&
+ EDBM_op_callf(em, op, "delete geom=%he context=%i", BM_ELEM_SELECT, DEL_FACES)))
+ {
+ continue;
+ }
+ break;
+ case MESH_DELETE_FACE: /* Erase Faces */
+ if (!(em->bm->totfacesel &&
+ EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_FACES)))
+ {
+ continue;
+ }
+ break;
+ case MESH_DELETE_EDGE_FACE:
+ /* Edges and Faces */
+ if (!((em->bm->totedgesel || em->bm->totfacesel) &&
+ EDBM_op_callf(em, op, "delete geom=%hef context=%i", BM_ELEM_SELECT, DEL_EDGESFACES)))
+ {
+ continue;
+ }
+ break;
+ case MESH_DELETE_ONLY_FACE:
+ /* Only faces. */
+ if (!(em->bm->totfacesel &&
+ EDBM_op_callf(em, op, "delete geom=%hf context=%i", BM_ELEM_SELECT, DEL_ONLYFACES)))
+ {
+ continue;
+ }
+ break;
+ default:
+ BLI_assert(0);
+ break;
+ }
- return OPERATOR_FINISHED;
+ changed_multi = true;
+
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+
+ EDBM_update_generic(em, true, true);
+ }
+
+ MEM_SAFE_FREE(objects);
+
+ return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
void MESH_OT_delete(wmOperatorType *ot)
@@ -462,61 +522,75 @@ static bool bm_face_is_loose(BMFace *f)
static int edbm_delete_loose_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMesh *bm = em->bm;
- BMIter iter;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ int totelem_old_sel[3];
+ int totelem_old[3];
- const bool use_verts = (RNA_boolean_get(op->ptr, "use_verts") && bm->totvertsel);
- const bool use_edges = (RNA_boolean_get(op->ptr, "use_edges") && bm->totedgesel);
- const bool use_faces = (RNA_boolean_get(op->ptr, "use_faces") && bm->totfacesel);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- const int totelem[3] = {bm->totvert, bm->totedge, bm->totface};
+ EDBM_mesh_stats_multi(objects, objects_len, totelem_old, totelem_old_sel);
+ const bool use_verts = (RNA_boolean_get(op->ptr, "use_verts") && totelem_old_sel[0]);
+ const bool use_edges = (RNA_boolean_get(op->ptr, "use_edges") && totelem_old_sel[1]);
+ const bool use_faces = (RNA_boolean_get(op->ptr, "use_faces") && totelem_old_sel[2]);
- BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
- if (use_faces) {
- BMFace *f;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ BMIter iter;
- BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
- BM_elem_flag_set(f, BM_ELEM_TAG, bm_face_is_loose(f));
+ BM_mesh_elem_hflag_disable_all(bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_TAG, false);
+
+ if (use_faces) {
+ BMFace *f;
+
+ BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+ if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
+ BM_elem_flag_set(f, BM_ELEM_TAG, bm_face_is_loose(f));
+ }
}
- }
- BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_FACES);
- }
+ BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_FACES);
+ }
- if (use_edges) {
- BMEdge *e;
+ if (use_edges) {
+ BMEdge *e;
- BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
- if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
- BM_elem_flag_set(e, BM_ELEM_TAG, BM_edge_is_wire(e));
+ BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
+ if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
+ BM_elem_flag_set(e, BM_ELEM_TAG, BM_edge_is_wire(e));
+ }
}
- }
- BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_EDGES);
- }
+ BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_EDGES);
+ }
- if (use_verts) {
- BMVert *v;
+ if (use_verts) {
+ BMVert *v;
- BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
- BM_elem_flag_set(v, BM_ELEM_TAG, (v->e == NULL));
+ BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
+ if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
+ BM_elem_flag_set(v, BM_ELEM_TAG, (v->e == NULL));
+ }
}
+
+ BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_VERTS);
}
- BM_mesh_delete_hflag_context(bm, BM_ELEM_TAG, DEL_VERTS);
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+
+ EDBM_update_generic(em, true, true);
}
- EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ int totelem_new[3];
+ EDBM_mesh_stats_multi(objects, objects_len, totelem_new, NULL);
- EDBM_update_generic(em, true, true);
+ edbm_report_delete_info(op->reports, totelem_old, totelem_new);
- edbm_report_delete_info(op->reports, bm, totelem);
+ MEM_SAFE_FREE(objects);
return OPERATOR_FINISHED;
}
@@ -551,13 +625,24 @@ void MESH_OT_delete_loose(wmOperatorType *ot)
static int edbm_collapse_edge_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- if (!EDBM_op_callf(em, op, "collapse edges=%he uvs=%b", BM_ELEM_SELECT, true))
- return OPERATOR_CANCELLED;
+ if (em->bm->totedgesel == 0) {
+ continue;
+ }
- EDBM_update_generic(em, true, true);
+ if (!EDBM_op_callf(em, op, "collapse edges=%he uvs=%b", BM_ELEM_SELECT, true)) {
+ continue;
+ }
+
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -852,37 +937,51 @@ void MESH_OT_edge_face_add(wmOperatorType *ot)
static int edbm_mark_seam_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- Mesh *me = ((Mesh *)obedit->data);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMesh *bm = em->bm;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
BMEdge *eed;
BMIter iter;
const bool clear = RNA_boolean_get(op->ptr, "clear");
- /* auto-enable seams drawing */
- if (clear == 0) {
- me->drawflag |= ME_DRAWSEAMS;
- }
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
- if (clear) {
- BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
- if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
- continue;
+ if (bm->totedgesel == 0) {
+ continue;
+ }
- BM_elem_flag_disable(eed, BM_ELEM_SEAM);
+ Mesh *me = ((Mesh *)obedit->data);
+
+ /* auto-enable seams drawing */
+ if (clear == 0) {
+ me->drawflag |= ME_DRAWSEAMS;
}
- }
- else {
- BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
- if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN))
- continue;
- BM_elem_flag_enable(eed, BM_ELEM_SEAM);
+
+ if (clear) {
+ BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
+ if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ continue;
+ }
+
+ BM_elem_flag_disable(eed, BM_ELEM_SEAM);
+ }
+ }
+ else {
+ BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
+ if (!BM_elem_flag_test(eed, BM_ELEM_SELECT) || BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ continue;
+ }
+ BM_elem_flag_enable(eed, BM_ELEM_SEAM);
+ }
}
- }
- ED_uvedit_live_unwrap(scene, obedit);
- EDBM_update_generic(em, true, false);
+ ED_uvedit_live_unwrap(scene, obedit);
+ EDBM_update_generic(em, true, false);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -905,6 +1004,8 @@ void MESH_OT_mark_seam(wmOperatorType *ot)
prop = RNA_def_boolean(ot->srna, "clear", 0, "Clear", "");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+
+ WM_operatortype_props_advanced_begin(ot);
}
/** \} */
@@ -915,34 +1016,45 @@ void MESH_OT_mark_seam(wmOperatorType *ot)
static int edbm_mark_sharp_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Mesh *me = ((Mesh *)obedit->data);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMesh *bm = em->bm;
BMEdge *eed;
BMIter iter;
const bool clear = RNA_boolean_get(op->ptr, "clear");
const bool use_verts = RNA_boolean_get(op->ptr, "use_verts");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- /* auto-enable sharp edge drawing */
- if (clear == 0) {
- me->drawflag |= ME_DRAWSHARP;
- }
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ Mesh *me = ((Mesh *)obedit->data);
- BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
- if (use_verts) {
- if (!(BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) || BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))) {
+ if (bm->totedgesel == 0) {
+ continue;
+ }
+
+ /* auto-enable sharp edge drawing */
+ if (clear == 0) {
+ me->drawflag |= ME_DRAWSHARP;
+ }
+
+ BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
+ if (use_verts) {
+ if (!(BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) || BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))) {
+ continue;
+ }
+ }
+ else if (!BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
continue;
}
- }
- else if (!BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
- continue;
+
+ BM_elem_flag_set(eed, BM_ELEM_SMOOTH, clear);
}
- BM_elem_flag_set(eed, BM_ELEM_SMOOTH, clear);
+ EDBM_update_generic(em, true, false);
}
-
- EDBM_update_generic(em, true, false);
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -1430,19 +1542,31 @@ void MESH_OT_vert_connect_nonplanar(wmOperatorType *ot)
static int edbm_face_make_planar_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
const int repeat = RNA_int_get(op->ptr, "repeat");
const float fac = RNA_float_get(op->ptr, "factor");
- if (!EDBM_op_callf(
- em, op, "planar_faces faces=%hf iterations=%i factor=%f",
- BM_ELEM_SELECT, repeat, fac))
- {
- return OPERATOR_CANCELLED;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
+
+ if (!EDBM_op_callf(
+ em, op, "planar_faces faces=%hf iterations=%i factor=%f",
+ BM_ELEM_SELECT, repeat, fac))
+ {
+ continue;
+ }
+
+ EDBM_update_generic(em, true, true);
}
+ MEM_freeN(objects);
- EDBM_update_generic(em, true, true);
return OPERATOR_FINISHED;
}
@@ -1473,23 +1597,32 @@ void MESH_OT_face_make_planar(wmOperatorType *ot)
static int edbm_edge_split_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totedgesel == 0) {
+ continue;
+ }
- if (!EDBM_op_call_and_selectf(
- em, op,
- "edges.out", false,
- "split_edges edges=%he",
- BM_ELEM_SELECT))
- {
- return OPERATOR_CANCELLED;
- }
+ if (!EDBM_op_call_and_selectf(
+ em, op,
+ "edges.out", false,
+ "split_edges edges=%he",
+ BM_ELEM_SELECT))
+ {
+ continue;
+ }
- if (em->selectmode == SCE_SELECT_FACE) {
- EDBM_select_flush(em);
- }
+ if (em->selectmode == SCE_SELECT_FACE) {
+ EDBM_select_flush(em);
+ }
- EDBM_update_generic(em, true, true);
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -1517,33 +1650,43 @@ void MESH_OT_edge_split(wmOperatorType *ot)
static int edbm_duplicate_exec(bContext *C, wmOperator *op)
{
- Object *ob = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(ob);
- BMesh *bm = em->bm;
- BMOperator bmop;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- EDBM_op_init(
- em, &bmop, op,
- "duplicate geom=%hvef use_select_history=%b",
- BM_ELEM_SELECT, true);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (em->bm->totvertsel == 0) {
+ continue;
+ }
- BMO_op_exec(bm, &bmop);
+ BMOperator bmop;
+ BMesh *bm = em->bm;
- /* de-select all would clear otherwise */
- BM_SELECT_HISTORY_BACKUP(bm);
+ EDBM_op_init(
+ em, &bmop, op,
+ "duplicate geom=%hvef use_select_history=%b",
+ BM_ELEM_SELECT, true);
- EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ BMO_op_exec(bm, &bmop);
- BMO_slot_buffer_hflag_enable(bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
+ /* de-select all would clear otherwise */
+ BM_SELECT_HISTORY_BACKUP(bm);
- /* rebuild editselection */
- BM_SELECT_HISTORY_RESTORE(bm);
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
- }
+ BMO_slot_buffer_hflag_enable(bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
- EDBM_update_generic(em, true, true);
+ /* rebuild editselection */
+ BM_SELECT_HISTORY_RESTORE(bm);
+
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -1581,18 +1724,29 @@ void MESH_OT_duplicate(wmOperatorType *ot)
* \{ */
static int edbm_flip_normals_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- if (!EDBM_op_callf(
- em, op, "reverse_faces faces=%hf flip_multires=%b",
- BM_ELEM_SELECT, true))
- {
- return OPERATOR_CANCELLED;
- }
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- EDBM_update_generic(em, true, false);
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
+
+ if (!EDBM_op_callf(
+ em, op, "reverse_faces faces=%hf flip_multires=%b",
+ BM_ELEM_SELECT, true))
+ {
+ continue;
+ }
+ EDBM_update_generic(em, true, false);
+ }
+
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -1622,71 +1776,99 @@ void MESH_OT_flip_normals(wmOperatorType *ot)
*/
static int edbm_edge_rotate_selected_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMOperator bmop;
BMEdge *eed;
BMIter iter;
const bool use_ccw = RNA_boolean_get(op->ptr, "use_ccw");
- int tot = 0;
- if (em->bm->totedgesel == 0) {
- BKE_report(op->reports, RPT_ERROR, "Select edges or face pairs for edge loops to rotate about");
- return OPERATOR_CANCELLED;
- }
+ int tot_rotate_all = 0, tot_failed_all = 0;
+ bool no_selected_edges = true, invalid_selected_edges = true;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ int tot = 0;
- /* first see if we have two adjacent faces */
- BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
- BM_elem_flag_disable(eed, BM_ELEM_TAG);
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
- BMFace *fa, *fb;
- if (BM_edge_face_pair(eed, &fa, &fb)) {
- /* if both faces are selected we rotate between them,
- * otherwise - rotate between 2 unselected - but not mixed */
- if (BM_elem_flag_test(fa, BM_ELEM_SELECT) == BM_elem_flag_test(fb, BM_ELEM_SELECT)) {
- BM_elem_flag_enable(eed, BM_ELEM_TAG);
- tot++;
+ if (em->bm->totedgesel == 0) {
+ continue;
+ }
+ no_selected_edges = false;
+
+ /* first see if we have two adjacent faces */
+ BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+ BM_elem_flag_disable(eed, BM_ELEM_TAG);
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
+ BMFace *fa, *fb;
+ if (BM_edge_face_pair(eed, &fa, &fb)) {
+ /* if both faces are selected we rotate between them,
+ * otherwise - rotate between 2 unselected - but not mixed */
+ if (BM_elem_flag_test(fa, BM_ELEM_SELECT) == BM_elem_flag_test(fb, BM_ELEM_SELECT)) {
+ BM_elem_flag_enable(eed, BM_ELEM_TAG);
+ tot++;
+ }
}
}
}
- }
- /* ok, we don't have two adjacent faces, but we do have two selected ones.
- * that's an error condition.*/
- if (tot == 0) {
- BKE_report(op->reports, RPT_ERROR, "Could not find any selected edges that can be rotated");
- return OPERATOR_CANCELLED;
- }
+ /* ok, we don't have two adjacent faces, but we do have two selected ones.
+ * that's an error condition.*/
+ if (tot == 0) {
+ continue;
+ }
+ invalid_selected_edges = false;
- EDBM_op_init(em, &bmop, op, "rotate_edges edges=%he use_ccw=%b", BM_ELEM_TAG, use_ccw);
+ BMOperator bmop;
+ EDBM_op_init(em, &bmop, op, "rotate_edges edges=%he use_ccw=%b", BM_ELEM_TAG, use_ccw);
- /* avoids leaving old verts selected which can be a problem running multiple times,
- * since this means the edges become selected around the face which then attempt to rotate */
- BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_in, "edges", BM_EDGE, BM_ELEM_SELECT, true);
+ /* avoids leaving old verts selected which can be a problem running multiple times,
+ * since this means the edges become selected around the face which then attempt to rotate */
+ BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_in, "edges", BM_EDGE, BM_ELEM_SELECT, true);
- BMO_op_exec(em->bm, &bmop);
- /* edges may rotate into hidden vertices, if this does _not_ run we get an ilogical state */
- BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_HIDDEN, true);
- BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_SELECT, true);
+ BMO_op_exec(em->bm, &bmop);
+ /* edges may rotate into hidden vertices, if this does _not_ run we get an ilogical state */
+ BMO_slot_buffer_hflag_disable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_HIDDEN, true);
+ BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "edges.out", BM_EDGE, BM_ELEM_SELECT, true);
- const int tot_rotate = BMO_slot_buffer_count(bmop.slots_out, "edges.out");
- const int tot_failed = tot - tot_rotate;
- if (tot_failed != 0) {
- /* If some edges fail to rotate, we need to re-select them,
- * otherwise we can end up with invalid selection
- * (unselected edge between 2 selected faces). */
- BM_mesh_elem_hflag_enable_test(em->bm, BM_EDGE, BM_ELEM_SELECT, true, false, BM_ELEM_TAG);
+ const int tot_rotate = BMO_slot_buffer_count(bmop.slots_out, "edges.out");
+ const int tot_failed = tot - tot_rotate;
+
+ tot_rotate_all += tot_rotate;
+ tot_failed_all += tot_failed;
+
+ if (tot_failed != 0) {
+ /* If some edges fail to rotate, we need to re-select them,
+ * otherwise we can end up with invalid selection
+ * (unselected edge between 2 selected faces). */
+ BM_mesh_elem_hflag_enable_test(em->bm, BM_EDGE, BM_ELEM_SELECT, true, false, BM_ELEM_TAG);
+ }
+
+ EDBM_selectmode_flush(em);
+
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
- BKE_reportf(op->reports, RPT_WARNING, "Unable to rotate %d edge(s)", tot_failed);
+ EDBM_update_generic(em, true, true);
}
+ MEM_freeN(objects);
- EDBM_selectmode_flush(em);
+ if (no_selected_edges) {
+ BKE_report(op->reports, RPT_ERROR, "Select edges or face pairs for edge loops to rotate about");
+ return OPERATOR_CANCELLED;
+ }
- if (!EDBM_op_finish(em, &bmop, op, true)) {
+ /* Ok, we don't have two adjacent faces, but we do have two selected ones.
+ * that's an error condition. */
+ if (invalid_selected_edges) {
+ BKE_report(op->reports, RPT_ERROR, "Could not find any selected edges that can be rotated");
return OPERATOR_CANCELLED;
}
- EDBM_update_generic(em, true, true);
+ if (tot_failed_all != 0) {
+ BKE_reportf(op->reports, RPT_WARNING, "Unable to rotate %d edge(s)", tot_failed_all);
+ }
return OPERATOR_FINISHED;
}
@@ -1717,13 +1899,28 @@ void MESH_OT_edge_rotate(wmOperatorType *ot)
static int edbm_hide_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ const bool unselected = RNA_boolean_get(op->ptr, "unselected");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
- EDBM_mesh_hide(em, RNA_boolean_get(op->ptr, "unselected"));
+ if ((bm->totvertsel == 0) &&
+ (bm->totedgesel == 0) &&
+ (bm->totfacesel == 0))
+ {
+ continue;
+ }
- EDBM_update_generic(em, true, false);
+ EDBM_mesh_hide(em, unselected);
+ EDBM_update_generic(em, true, false);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -1753,13 +1950,19 @@ void MESH_OT_hide(wmOperatorType *ot)
static int edbm_reveal_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
const bool select = RNA_boolean_get(op->ptr, "select");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- EDBM_mesh_reveal(em, select);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- EDBM_update_generic(em, true, false);
+ EDBM_mesh_reveal(em, select);
+ EDBM_update_generic(em, true, false);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -1913,6 +2116,9 @@ void MESH_OT_vertices_smooth(wmOperatorType *ot)
RNA_def_float(ot->srna, "factor", 0.5f, -10.0f, 10.0f, "Smoothing", "Smoothing factor", 0.0f, 1.0f);
RNA_def_int(ot->srna, "repeat", 1, 1, 1000, "Repeat", "Number of times to smooth the mesh", 1, 100);
+
+ WM_operatortype_props_advanced_begin(ot);
+
RNA_def_boolean(ot->srna, "xaxis", true, "X-Axis", "Smooth along the X axis");
RNA_def_boolean(ot->srna, "yaxis", true, "Y-Axis", "Smooth along the Y axis");
RNA_def_boolean(ot->srna, "zaxis", true, "Z-Axis", "Smooth along the Z axis");
@@ -2003,6 +2209,9 @@ void MESH_OT_vertices_smooth_laplacian(wmOperatorType *ot)
"Lambda factor", "", 1e-7f, 1000.0f);
RNA_def_float(ot->srna, "lambda_border", 5e-5f, 1e-7f, 1000.0f,
"Lambda factor in border", "", 1e-7f, 1000.0f);
+
+ WM_operatortype_props_advanced_begin(ot);
+
RNA_def_boolean(ot->srna, "use_x", true, "Smooth X Axis", "Smooth object along X axis");
RNA_def_boolean(ot->srna, "use_y", true, "Smooth Y Axis", "Smooth object along Y axis");
RNA_def_boolean(ot->srna, "use_z", true, "Smooth Z Axis", "Smooth object along Z axis");
@@ -2144,26 +2353,38 @@ static int edbm_reverse_uvs_exec(bContext *C, wmOperator *op)
static int edbm_rotate_colors_exec(bContext *C, wmOperator *op)
{
- Object *ob = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(ob);
- BMOperator bmop;
-
- /* get the direction from RNA */
+ /* get the direction from RNA */
const bool use_ccw = RNA_boolean_get(op->ptr, "use_ccw");
- /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */
- EDBM_op_init(em, &bmop, op, "rotate_colors faces=%hf use_ccw=%b", BM_ELEM_SELECT, use_ccw);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- /* execute the operator */
- BMO_op_exec(em->bm, &bmop);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(ob);
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
- /* finish the operator */
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
+ BMOperator bmop;
+
+ /* initialize the bmop using EDBM api, which does various ui error reporting and other stuff */
+ EDBM_op_init(em, &bmop, op, "rotate_colors faces=%hf use_ccw=%b", BM_ELEM_SELECT, use_ccw);
+
+ /* execute the operator */
+ BMO_op_exec(em->bm, &bmop);
+
+ /* finish the operator */
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
+
+ /* dependencies graph and notification stuff */
+ EDBM_update_generic(em, false, false);
}
- /* dependencies graph and notification stuff */
- EDBM_update_generic(em, false, false);
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -2478,6 +2699,9 @@ void MESH_OT_merge(wmOperatorType *ot)
/* properties */
ot->prop = RNA_def_enum(ot->srna, "type", merge_type_items, MESH_MERGE_CENTER, "Type", "Merge method to use");
RNA_def_enum_funcs(ot->prop, merge_type_itemf);
+
+ WM_operatortype_props_advanced_begin(ot);
+
RNA_def_boolean(ot->srna, "uvs", false, "UVs", "Move UVs according to merge");
}
@@ -2489,60 +2713,79 @@ void MESH_OT_merge(wmOperatorType *ot)
static int edbm_remove_doubles_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMOperator bmop;
const float threshold = RNA_float_get(op->ptr, "threshold");
const bool use_unselected = RNA_boolean_get(op->ptr, "use_unselected");
- const int totvert_orig = em->bm->totvert;
- int count;
- char htype_select;
+ int count_multi = 0;
- /* avoid loosing selection state (select -> tags) */
- if (em->selectmode & SCE_SELECT_VERTEX) htype_select = BM_VERT;
- else if (em->selectmode & SCE_SELECT_EDGE) htype_select = BM_EDGE;
- else htype_select = BM_FACE;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- /* store selection as tags */
- BM_mesh_elem_hflag_enable_test(em->bm, htype_select, BM_ELEM_TAG, true, true, BM_ELEM_SELECT);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ /* Selection used as target with 'use_unselected'. */
+ if (em->bm->totvertsel == 0) {
+ continue;
+ }
- if (use_unselected) {
- EDBM_op_init(
- em, &bmop, op,
- "automerge verts=%hv dist=%f",
- BM_ELEM_SELECT, threshold);
- BMO_op_exec(em->bm, &bmop);
+ BMOperator bmop;
+ const int totvert_orig = em->bm->totvert;
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
- }
- }
- else {
- EDBM_op_init(
- em, &bmop, op,
- "find_doubles verts=%hv dist=%f",
- BM_ELEM_SELECT, threshold);
- BMO_op_exec(em->bm, &bmop);
+ /* avoid loosing selection state (select -> tags) */
+ char htype_select;
+ if (em->selectmode & SCE_SELECT_VERTEX) htype_select = BM_VERT;
+ else if (em->selectmode & SCE_SELECT_EDGE) htype_select = BM_EDGE;
+ else htype_select = BM_FACE;
- if (!EDBM_op_callf(em, op, "weld_verts targetmap=%S", &bmop, "targetmap.out")) {
- BMO_op_finish(em->bm, &bmop);
- return OPERATOR_CANCELLED;
+ /* store selection as tags */
+ BM_mesh_elem_hflag_enable_test(em->bm, htype_select, BM_ELEM_TAG, true, true, BM_ELEM_SELECT);
+
+
+ if (use_unselected) {
+ EDBM_op_init(
+ em, &bmop, op,
+ "automerge verts=%hv dist=%f",
+ BM_ELEM_SELECT, threshold);
+ BMO_op_exec(em->bm, &bmop);
+
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
}
+ else {
+ EDBM_op_init(
+ em, &bmop, op,
+ "find_doubles verts=%hv dist=%f",
+ BM_ELEM_SELECT, threshold);
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
+ BMO_op_exec(em->bm, &bmop);
+
+ if (!EDBM_op_callf(em, op, "weld_verts targetmap=%S", &bmop, "targetmap.out")) {
+ BMO_op_finish(em->bm, &bmop);
+ continue;
+ }
+
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
}
- }
- count = totvert_orig - em->bm->totvert;
- BKE_reportf(op->reports, RPT_INFO, "Removed %d vertices", count);
+ const int count = (totvert_orig - em->bm->totvert);
- /* restore selection from tags */
- BM_mesh_elem_hflag_enable_test(em->bm, htype_select, BM_ELEM_SELECT, true, true, BM_ELEM_TAG);
- EDBM_selectmode_flush(em);
+ /* restore selection from tags */
+ BM_mesh_elem_hflag_enable_test(em->bm, htype_select, BM_ELEM_SELECT, true, true, BM_ELEM_TAG);
+ EDBM_selectmode_flush(em);
- EDBM_update_generic(em, true, true);
+ if (count) {
+ count_multi += count;
+ EDBM_update_generic(em, true, true);
+ }
+ }
+ MEM_freeN(objects);
+
+ BKE_reportf(op->reports, RPT_INFO, "Removed %d vertices", count_multi);
return OPERATOR_FINISHED;
}
@@ -2599,7 +2842,7 @@ static void shape_propagate(BMEditMesh *em, wmOperator *op)
//TAG Mesh Objects that share this data
for (base = scene->base.first; base; base = base->next) {
if (base->object && base->object->data == me) {
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
}
}
#endif
@@ -3184,7 +3427,7 @@ enum {
MESH_SEPARATE_LOOSE = 2,
};
-static Base *mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMesh *bm_old)
+static Base *mesh_separate_tagged(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base_old, BMesh *bm_old)
{
Base *base_new;
Object *obedit = base_old->object;
@@ -3205,11 +3448,11 @@ static Base *mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMe
CustomData_bmesh_init_pool(&bm_new->ldata, bm_mesh_allocsize_default.totloop, BM_LOOP);
CustomData_bmesh_init_pool(&bm_new->pdata, bm_mesh_allocsize_default.totface, BM_FACE);
- base_new = ED_object_add_duplicate(bmain, scene, base_old, USER_DUP_MESH);
+ base_new = ED_object_add_duplicate(bmain, scene, view_layer, base_old, USER_DUP_MESH);
/* DAG_relations_tag_update(bmain); */ /* normally would call directly after but in this case delay recalc */
assign_matarar(base_new->object, give_matarar(obedit), *give_totcolp(obedit)); /* new in 2.5 */
- ED_base_object_select(base_new, BA_SELECT);
+ ED_object_base_select(base_new, BA_SELECT);
BMO_op_callf(bm_old, (BMO_FLAG_DEFAULTS & ~BMO_FLAG_RESPECT_HIDE),
"duplicate geom=%hvef dest=%p", BM_ELEM_TAG, bm_new);
@@ -3231,7 +3474,7 @@ static Base *mesh_separate_tagged(Main *bmain, Scene *scene, Base *base_old, BMe
return base_new;
}
-static bool mesh_separate_selected(Main *bmain, Scene *scene, Base *base_old, BMesh *bm_old)
+static bool mesh_separate_selected(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base_old, BMesh *bm_old)
{
/* we may have tags from previous operators */
BM_mesh_elem_hflag_disable_all(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, false);
@@ -3239,7 +3482,7 @@ static bool mesh_separate_selected(Main *bmain, Scene *scene, Base *base_old, BM
/* sel -> tag */
BM_mesh_elem_hflag_enable_test(bm_old, BM_FACE | BM_EDGE | BM_VERT, BM_ELEM_TAG, true, false, BM_ELEM_SELECT);
- return (mesh_separate_tagged(bmain, scene, base_old, bm_old) != NULL);
+ return (mesh_separate_tagged(bmain, scene, view_layer, base_old, bm_old) != NULL);
}
/* flush a hflag to from verts to edges/faces */
@@ -3338,7 +3581,7 @@ static void mesh_separate_material_assign_mat_nr(Main *bmain, Object *ob, const
}
}
-static bool mesh_separate_material(Main *bmain, Scene *scene, Base *base_old, BMesh *bm_old)
+static bool mesh_separate_material(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base_old, BMesh *bm_old)
{
BMFace *f_cmp, *f;
BMIter iter;
@@ -3379,7 +3622,7 @@ static bool mesh_separate_material(Main *bmain, Scene *scene, Base *base_old, BM
}
/* Move selection into a separate object */
- base_new = mesh_separate_tagged(bmain, scene, base_old, bm_old);
+ base_new = mesh_separate_tagged(bmain, scene, view_layer, base_old, bm_old);
if (base_new) {
mesh_separate_material_assign_mat_nr(bmain, base_new->object, mat_nr);
}
@@ -3390,7 +3633,7 @@ static bool mesh_separate_material(Main *bmain, Scene *scene, Base *base_old, BM
return result;
}
-static bool mesh_separate_loose(Main *bmain, Scene *scene, Base *base_old, BMesh *bm_old)
+static bool mesh_separate_loose(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base_old, BMesh *bm_old)
{
int i;
BMEdge *e;
@@ -3443,7 +3686,7 @@ static bool mesh_separate_loose(Main *bmain, Scene *scene, Base *base_old, BMesh
bm_mesh_hflag_flush_vert(bm_old, BM_ELEM_TAG);
/* Move selection into a separate object */
- result |= (mesh_separate_tagged(bmain, scene, base_old, bm_old) != NULL);
+ result |= (mesh_separate_tagged(bmain, scene, view_layer, base_old, bm_old) != NULL);
}
return result;
@@ -3453,6 +3696,7 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
const int type = RNA_enum_get(op->ptr, "type");
int retval = 0;
@@ -3473,13 +3717,13 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
/* editmode separate */
switch (type) {
case MESH_SEPARATE_SELECTED:
- retval = mesh_separate_selected(bmain, scene, base, em->bm);
+ retval = mesh_separate_selected(bmain, scene, view_layer, base, em->bm);
break;
case MESH_SEPARATE_MATERIAL:
- retval = mesh_separate_material(bmain, scene, base, em->bm);
+ retval = mesh_separate_material(bmain, scene, view_layer, base, em->bm);
break;
case MESH_SEPARATE_LOOSE:
- retval = mesh_separate_loose(bmain, scene, base, em->bm);
+ retval = mesh_separate_loose(bmain, scene, view_layer, base, em->bm);
break;
default:
BLI_assert(0);
@@ -3514,10 +3758,10 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
switch (type) {
case MESH_SEPARATE_MATERIAL:
- retval_iter = mesh_separate_material(bmain, scene, base_iter, bm_old);
+ retval_iter = mesh_separate_material(bmain, scene, view_layer, base_iter, bm_old);
break;
case MESH_SEPARATE_LOOSE:
- retval_iter = mesh_separate_loose(bmain, scene, base_iter, bm_old);
+ retval_iter = mesh_separate_loose(bmain, scene, view_layer, base_iter, bm_old);
break;
default:
BLI_assert(0);
@@ -3531,7 +3775,7 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
.calc_object_remap = true,
}));
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&me->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
}
@@ -3546,7 +3790,7 @@ static int edbm_separate_exec(bContext *C, wmOperator *op)
if (retval) {
/* delay depsgraph recalc until all objects are duplicated */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, NULL);
return OPERATOR_FINISHED;
@@ -3852,6 +4096,12 @@ static int edbm_fill_grid_exec(bContext *C, wmOperator *op)
BMO_op_exec(em->bm, &bmop);
+ /* NOTE: EDBM_op_finish() will change bmesh pointer inside of edit mesh,
+ * so need to tell evaluated objects to sync new bmesh pointer to their
+ * edit mesh structures.
+ */
+ DEG_id_tag_update(&obedit->id, 0);
+
/* cancel if nothing was done */
if ((totedge_orig == em->bm->totedge) &&
(totface_orig == em->bm->totface))
@@ -3903,20 +4153,32 @@ void MESH_OT_fill_grid(wmOperatorType *ot)
static int edbm_fill_holes_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
const int sides = RNA_int_get(op->ptr, "sides");
- if (!EDBM_op_call_and_selectf(
- em, op,
- "faces.out", true,
- "holes_fill edges=%he sides=%i",
- BM_ELEM_SELECT, sides))
- {
- return OPERATOR_CANCELLED;
- }
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- EDBM_update_generic(em, true, true);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+
+ if (em->bm->totedgesel == 0) {
+ continue;
+ }
+
+ if (!EDBM_op_call_and_selectf(
+ em, op,
+ "faces.out", true,
+ "holes_fill edges=%he sides=%i",
+ BM_ELEM_SELECT, sides))
+ {
+ continue;
+ }
+
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
@@ -4016,30 +4278,40 @@ void MESH_OT_beautify_fill(wmOperatorType *ot)
static int edbm_poke_face_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMOperator bmop;
-
const float offset = RNA_float_get(op->ptr, "offset");
const bool use_relative_offset = RNA_boolean_get(op->ptr, "use_relative_offset");
const int center_mode = RNA_enum_get(op->ptr, "center_mode");
- EDBM_op_init(em, &bmop, op, "poke faces=%hf offset=%f use_relative_offset=%b center_mode=%i",
- BM_ELEM_SELECT, offset, use_relative_offset, center_mode);
- BMO_op_exec(em->bm, &bmop);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
- BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true);
- BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
+ BMOperator bmop;
+ EDBM_op_init(em, &bmop, op, "poke faces=%hf offset=%f use_relative_offset=%b center_mode=%i",
+ BM_ELEM_SELECT, offset, use_relative_offset, center_mode);
+ BMO_op_exec(em->bm, &bmop);
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
- }
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
- EDBM_mesh_normals_update(em);
+ BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "verts.out", BM_VERT, BM_ELEM_SELECT, true);
+ BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
- EDBM_update_generic(em, true, true);
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
+
+ EDBM_mesh_normals_update(em);
+
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
@@ -4080,32 +4352,48 @@ void MESH_OT_poke(wmOperatorType *ot)
static int edbm_quads_convert_to_tris_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMOperator bmop;
const int quad_method = RNA_enum_get(op->ptr, "quad_method");
const int ngon_method = RNA_enum_get(op->ptr, "ngon_method");
- BMOIter oiter;
- BMFace *f;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- EDBM_op_init(em, &bmop, op, "triangulate faces=%hf quad_method=%i ngon_method=%i", BM_ELEM_SELECT, quad_method, ngon_method);
- BMO_op_exec(em->bm, &bmop);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- /* select the output */
- BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
- /* remove the doubles */
- BMO_ITER (f, &oiter, bmop.slots_out, "face_map_double.out", BM_FACE) {
- BM_face_kill(em->bm, f);
- }
+ BMOperator bmop;
+ BMOIter oiter;
+ BMFace *f;
- EDBM_selectmode_flush(em);
+ EDBM_op_init(
+ em, &bmop, op,
+ "triangulate faces=%hf quad_method=%i ngon_method=%i",
+ BM_ELEM_SELECT, quad_method, ngon_method);
+ BMO_op_exec(em->bm, &bmop);
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
+ /* select the output */
+ BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "faces.out", BM_FACE, BM_ELEM_SELECT, true);
+
+ /* remove the doubles */
+ BMO_ITER (f, &oiter, bmop.slots_out, "face_map_double.out", BM_FACE) {
+ BM_face_kill(em->bm, f);
+ }
+
+ EDBM_selectmode_flush(em);
+
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
+
+ EDBM_update_generic(em, true, true);
}
- EDBM_update_generic(em, true, true);
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -4139,52 +4427,68 @@ void MESH_OT_quads_convert_to_tris(wmOperatorType *ot)
static int edbm_tris_convert_to_quads_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- bool do_seam, do_sharp, do_uvs, do_vcols, do_materials;
- float angle_face_threshold, angle_shape_threshold;
- PropertyRNA *prop;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- /* When joining exactly 2 faces, no limit.
- * this is useful for one off joins while editing. */
- prop = RNA_struct_find_property(op->ptr, "face_threshold");
- if ((em->bm->totfacesel == 2) &&
- (RNA_property_is_set(op->ptr, prop) == false))
- {
- angle_face_threshold = DEG2RADF(180.0f);
- }
- else {
- angle_face_threshold = RNA_property_float_get(op->ptr, prop);
- }
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ bool is_face_pair;
- prop = RNA_struct_find_property(op->ptr, "shape_threshold");
- if ((em->bm->totfacesel == 2) &&
- (RNA_property_is_set(op->ptr, prop) == false))
{
- angle_shape_threshold = DEG2RADF(180.0f);
- }
- else {
- angle_shape_threshold = RNA_property_float_get(op->ptr, prop);
+ int totelem_sel[3];
+ EDBM_mesh_stats_multi(objects, objects_len, NULL, totelem_sel);
+ is_face_pair = (totelem_sel[2] == 2);
}
- do_seam = RNA_boolean_get(op->ptr, "seam");
- do_sharp = RNA_boolean_get(op->ptr, "sharp");
- do_uvs = RNA_boolean_get(op->ptr, "uvs");
- do_vcols = RNA_boolean_get(op->ptr, "vcols");
- do_materials = RNA_boolean_get(op->ptr, "materials");
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
- if (!EDBM_op_call_and_selectf(
- em, op,
- "faces.out", true,
- "join_triangles faces=%hf angle_face_threshold=%f angle_shape_threshold=%f "
- "cmp_seam=%b cmp_sharp=%b cmp_uvs=%b cmp_vcols=%b cmp_materials=%b",
- BM_ELEM_SELECT, angle_face_threshold, angle_shape_threshold,
- do_seam, do_sharp, do_uvs, do_vcols, do_materials))
- {
- return OPERATOR_CANCELLED;
- }
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ bool do_seam, do_sharp, do_uvs, do_vcols, do_materials;
+ float angle_face_threshold, angle_shape_threshold;
+ PropertyRNA *prop;
+
+ /* When joining exactly 2 faces, no limit.
+ * this is useful for one off joins while editing. */
+ prop = RNA_struct_find_property(op->ptr, "face_threshold");
+ if (is_face_pair &&
+ (RNA_property_is_set(op->ptr, prop) == false))
+ {
+ angle_face_threshold = DEG2RADF(180.0f);
+ }
+ else {
+ angle_face_threshold = RNA_property_float_get(op->ptr, prop);
+ }
- EDBM_update_generic(em, true, true);
+ prop = RNA_struct_find_property(op->ptr, "shape_threshold");
+ if (is_face_pair &&
+ (RNA_property_is_set(op->ptr, prop) == false))
+ {
+ angle_shape_threshold = DEG2RADF(180.0f);
+ }
+ else {
+ angle_shape_threshold = RNA_property_float_get(op->ptr, prop);
+ }
+
+ do_seam = RNA_boolean_get(op->ptr, "seam");
+ do_sharp = RNA_boolean_get(op->ptr, "sharp");
+ do_uvs = RNA_boolean_get(op->ptr, "uvs");
+ do_vcols = RNA_boolean_get(op->ptr, "vcols");
+ do_materials = RNA_boolean_get(op->ptr, "materials");
+
+ if (!EDBM_op_call_and_selectf(
+ em, op,
+ "faces.out", true,
+ "join_triangles faces=%hf angle_face_threshold=%f angle_shape_threshold=%f "
+ "cmp_seam=%b cmp_sharp=%b cmp_uvs=%b cmp_vcols=%b cmp_materials=%b",
+ BM_ELEM_SELECT, angle_face_threshold, angle_shape_threshold,
+ do_seam, do_sharp, do_uvs, do_vcols, do_materials))
+ {
+ continue;
+ }
+
+ EDBM_update_generic(em, true, true);
+ }
return OPERATOR_FINISHED;
}
@@ -4240,10 +4544,6 @@ void MESH_OT_tris_convert_to_quads(wmOperatorType *ot)
static int edbm_decimate_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMesh *bm = em->bm;
-
const float ratio = RNA_float_get(op->ptr, "ratio");
bool use_vertex_group = RNA_boolean_get(op->ptr, "use_vertex_group");
const float vertex_group_factor = RNA_float_get(op->ptr, "vertex_group_factor");
@@ -4257,95 +4557,108 @@ static int edbm_decimate_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
- float *vweights = MEM_mallocN(sizeof(*vweights) * bm->totvert, __func__);
- {
- const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT);
- const int defbase_act = obedit->actdef - 1;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- if (use_vertex_group && (cd_dvert_offset == -1)) {
- BKE_report(op->reports, RPT_WARNING, "No active vertex group");
- use_vertex_group = false;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ if (bm->totedgesel == 0) {
+ continue;
}
- BMIter iter;
- BMVert *v;
- int i;
- BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) {
- float weight = 0.0f;
- if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
- if (use_vertex_group) {
- const MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(v, cd_dvert_offset);
- weight = defvert_find_weight(dv, defbase_act);
- if (invert_vertex_group) {
- weight = 1.0f - weight;
+ float *vweights = MEM_mallocN(sizeof(*vweights) * bm->totvert, __func__);
+ {
+ const int cd_dvert_offset = CustomData_get_offset(&bm->vdata, CD_MDEFORMVERT);
+ const int defbase_act = obedit->actdef - 1;
+
+ if (use_vertex_group && (cd_dvert_offset == -1)) {
+ BKE_report(op->reports, RPT_WARNING, "No active vertex group");
+ use_vertex_group = false;
+ }
+
+ BMIter iter;
+ BMVert *v;
+ int i;
+ BM_ITER_MESH_INDEX (v, &iter, bm, BM_VERTS_OF_MESH, i) {
+ float weight = 0.0f;
+ if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
+ if (use_vertex_group) {
+ const MDeformVert *dv = BM_ELEM_CD_GET_VOID_P(v, cd_dvert_offset);
+ weight = defvert_find_weight(dv, defbase_act);
+ if (invert_vertex_group) {
+ weight = 1.0f - weight;
+ }
+ }
+ else {
+ weight = 1.0f;
}
}
- else {
- weight = 1.0f;
- }
- }
- vweights[i] = weight;
- BM_elem_index_set(v, i); /* set_inline */
+ vweights[i] = weight;
+ BM_elem_index_set(v, i); /* set_inline */
+ }
+ bm->elem_index_dirty &= ~BM_VERT;
}
- bm->elem_index_dirty &= ~BM_VERT;
- }
- float ratio_adjust;
+ float ratio_adjust;
- if ((bm->totface == bm->totfacesel) || (ratio == 0.0f)) {
- ratio_adjust = ratio;
- }
- else {
- /**
- * Calculate a new ratio based on faces that could be remoevd during decimation.
- * needed so 0..1 has a meaningful range when operating on the selection.
- *
- * This doesn't have to be totally accurate,
- * but needs to be greater than the number of selected faces
- */
-
- int totface_basis = 0;
- int totface_adjacent = 0;
- BMIter iter;
- BMFace *f;
- BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
- /* count faces during decimation, ngons are triangulated */
- const int f_len = f->len > 4 ? (f->len - 2) : 1;
- totface_basis += f_len;
-
- BMLoop *l_iter, *l_first;
- l_iter = l_first = BM_FACE_FIRST_LOOP(f);
- do {
- if (vweights[BM_elem_index_get(l_iter->v)] != 0.0f) {
- totface_adjacent += f_len;
- break;
- }
- } while ((l_iter = l_iter->next) != l_first);
+ if ((bm->totface == bm->totfacesel) || (ratio == 0.0f)) {
+ ratio_adjust = ratio;
}
+ else {
+ /**
+ * Calculate a new ratio based on faces that could be remoevd during decimation.
+ * needed so 0..1 has a meaningful range when operating on the selection.
+ *
+ * This doesn't have to be totally accurate,
+ * but needs to be greater than the number of selected faces
+ */
+
+ int totface_basis = 0;
+ int totface_adjacent = 0;
+ BMIter iter;
+ BMFace *f;
+ BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+ /* count faces during decimation, ngons are triangulated */
+ const int f_len = f->len > 4 ? (f->len - 2) : 1;
+ totface_basis += f_len;
+
+ BMLoop *l_iter, *l_first;
+ l_iter = l_first = BM_FACE_FIRST_LOOP(f);
+ do {
+ if (vweights[BM_elem_index_get(l_iter->v)] != 0.0f) {
+ totface_adjacent += f_len;
+ break;
+ }
+ } while ((l_iter = l_iter->next) != l_first);
+ }
- ratio_adjust = ratio;
- ratio_adjust = 1.0f - ratio_adjust;
- ratio_adjust *= (float)totface_adjacent / (float)totface_basis;
- ratio_adjust = 1.0f - ratio_adjust;
- }
+ ratio_adjust = ratio;
+ ratio_adjust = 1.0f - ratio_adjust;
+ ratio_adjust *= (float)totface_adjacent / (float)totface_basis;
+ ratio_adjust = 1.0f - ratio_adjust;
+ }
- BM_mesh_decimate_collapse(
- em->bm, ratio_adjust, vweights, vertex_group_factor, false,
- symmetry_axis, symmetry_eps);
+ BM_mesh_decimate_collapse(
+ em->bm, ratio_adjust, vweights, vertex_group_factor, false,
+ symmetry_axis, symmetry_eps);
- MEM_freeN(vweights);
+ MEM_freeN(vweights);
- {
- short selectmode = em->selectmode;
- if ((selectmode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) == 0) {
- /* ensure we flush edges -> faces */
- selectmode |= SCE_SELECT_EDGE;
+ {
+ short selectmode = em->selectmode;
+ if ((selectmode & (SCE_SELECT_VERTEX | SCE_SELECT_EDGE)) == 0) {
+ /* ensure we flush edges -> faces */
+ selectmode |= SCE_SELECT_EDGE;
+ }
+ EDBM_selectmode_flush_ex(em, selectmode);
}
- EDBM_selectmode_flush_ex(em, selectmode);
+ EDBM_update_generic(em, true, true);
}
-
- EDBM_update_generic(em, true, true);
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -4628,52 +4941,65 @@ void MESH_OT_dissolve_mode(wmOperatorType *ot)
static int edbm_dissolve_limited_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMesh *bm = em->bm;
const float angle_limit = RNA_float_get(op->ptr, "angle_limit");
const bool use_dissolve_boundaries = RNA_boolean_get(op->ptr, "use_dissolve_boundaries");
const int delimit = RNA_enum_get(op->ptr, "delimit");
-
char dissolve_flag;
- if (em->selectmode == SCE_SELECT_FACE) {
- /* flush selection to tags and untag edges/verts with partially selected faces */
- BMIter iter;
- BMIter liter;
-
- BMElem *ele;
- BMFace *f;
- BMLoop *l;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
- BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
- BM_elem_flag_set(ele, BM_ELEM_TAG, BM_elem_flag_test(ele, BM_ELEM_SELECT));
- }
- BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
- BM_elem_flag_set(ele, BM_ELEM_TAG, BM_elem_flag_test(ele, BM_ELEM_SELECT));
+ if ((bm->totvertsel == 0) &&
+ (bm->totedgesel == 0) &&
+ (bm->totfacesel == 0))
+ {
+ continue;
}
- BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
- if (!BM_elem_flag_test(f, BM_ELEM_SELECT)) {
- BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
- BM_elem_flag_disable(l->v, BM_ELEM_TAG);
- BM_elem_flag_disable(l->e, BM_ELEM_TAG);
+ if (em->selectmode == SCE_SELECT_FACE) {
+ /* flush selection to tags and untag edges/verts with partially selected faces */
+ BMIter iter;
+ BMIter liter;
+
+ BMElem *ele;
+ BMFace *f;
+ BMLoop *l;
+
+ BM_ITER_MESH (ele, &iter, bm, BM_VERTS_OF_MESH) {
+ BM_elem_flag_set(ele, BM_ELEM_TAG, BM_elem_flag_test(ele, BM_ELEM_SELECT));
+ }
+ BM_ITER_MESH (ele, &iter, bm, BM_EDGES_OF_MESH) {
+ BM_elem_flag_set(ele, BM_ELEM_TAG, BM_elem_flag_test(ele, BM_ELEM_SELECT));
+ }
+
+ BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(f, BM_ELEM_SELECT)) {
+ BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
+ BM_elem_flag_disable(l->v, BM_ELEM_TAG);
+ BM_elem_flag_disable(l->e, BM_ELEM_TAG);
+ }
}
}
- }
- dissolve_flag = BM_ELEM_TAG;
- }
- else {
- dissolve_flag = BM_ELEM_SELECT;
- }
+ dissolve_flag = BM_ELEM_TAG;
+ }
+ else {
+ dissolve_flag = BM_ELEM_SELECT;
+ }
- EDBM_op_call_and_selectf(
- em, op, "region.out", true,
- "dissolve_limit edges=%he verts=%hv angle_limit=%f use_dissolve_boundaries=%b delimit=%i",
- dissolve_flag, dissolve_flag, angle_limit, use_dissolve_boundaries, delimit);
+ EDBM_op_call_and_selectf(
+ em, op, "region.out", true,
+ "dissolve_limit edges=%he verts=%hv angle_limit=%f use_dissolve_boundaries=%b delimit=%i",
+ dissolve_flag, dissolve_flag, angle_limit, use_dissolve_boundaries, delimit);
- EDBM_update_generic(em, true, true);
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -4711,26 +5037,48 @@ void MESH_OT_dissolve_limited(wmOperatorType *ot)
static int edbm_dissolve_degenerate_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ int totelem_old[3] = {0, 0, 0};
+ int totelem_new[3] = {0, 0, 0};
+
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ totelem_old[0] += bm->totvert;
+ totelem_old[1] += bm->totedge;
+ totelem_old[2] += bm->totface;
+ } /* objects */
+
const float thresh = RNA_float_get(op->ptr, "threshold");
- BMesh *bm = em->bm;
- const int totelem[3] = {bm->totvert, bm->totedge, bm->totface};
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
- if (!EDBM_op_callf(
- em, op,
- "dissolve_degenerate edges=%he dist=%f",
- BM_ELEM_SELECT, thresh))
- {
- return OPERATOR_CANCELLED;
- }
+ if (!EDBM_op_callf(
+ em, op,
+ "dissolve_degenerate edges=%he dist=%f",
+ BM_ELEM_SELECT, thresh))
+ {
+ return OPERATOR_CANCELLED;
+ }
- /* tricky to maintain correct selection here, so just flush up from verts */
- EDBM_select_flush(em);
+ /* tricky to maintain correct selection here, so just flush up from verts */
+ EDBM_select_flush(em);
- EDBM_update_generic(em, true, true);
+ EDBM_update_generic(em, true, true);
+
+ totelem_new[0] += bm->totvert;
+ totelem_new[1] += bm->totedge;
+ totelem_new[2] += bm->totface;
+ }
- edbm_report_delete_info(op->reports, bm, totelem);
+ edbm_report_delete_info(op->reports, totelem_old, totelem_new);
return OPERATOR_FINISHED;
}
@@ -4762,42 +5110,52 @@ void MESH_OT_dissolve_degenerate(wmOperatorType *ot)
/* internally uses dissolve */
static int edbm_delete_edgeloop_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
-
const bool use_face_split = RNA_boolean_get(op->ptr, "use_face_split");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- /* deal with selection */
- {
- BMEdge *e;
- BMIter iter;
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, false);
+ if (em->bm->totedgesel == 0) {
+ continue;
+ }
- BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (BM_elem_flag_test(e, BM_ELEM_SELECT) && e->l) {
- BMLoop *l_iter = e->l;
- do {
- BM_elem_flag_enable(l_iter->f, BM_ELEM_TAG);
- } while ((l_iter = l_iter->radial_next) != e->l);
+ /* deal with selection */
+ {
+ BMEdge *e;
+ BMIter iter;
+
+ BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, false);
+
+ BM_ITER_MESH (e, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (BM_elem_flag_test(e, BM_ELEM_SELECT) && e->l) {
+ BMLoop *l_iter = e->l;
+ do {
+ BM_elem_flag_enable(l_iter->f, BM_ELEM_TAG);
+ } while ((l_iter = l_iter->radial_next) != e->l);
+ }
}
}
- }
- if (!EDBM_op_callf(
- em, op,
- "dissolve_edges edges=%he use_verts=%b use_face_split=%b",
- BM_ELEM_SELECT, true, use_face_split))
- {
- return OPERATOR_CANCELLED;
- }
+ if (!EDBM_op_callf(
+ em, op,
+ "dissolve_edges edges=%he use_verts=%b use_face_split=%b",
+ BM_ELEM_SELECT, true, use_face_split))
+ {
+ continue;
+ }
- BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, true, false, BM_ELEM_TAG);
+ BM_mesh_elem_hflag_enable_test(em->bm, BM_FACE, BM_ELEM_SELECT, true, false, BM_ELEM_TAG);
- EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX);
+ EDBM_selectmode_flush_ex(em, SCE_SELECT_VERTEX);
- EDBM_update_generic(em, true, true);
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -4827,22 +5185,33 @@ void MESH_OT_delete_edgeloop(wmOperatorType *ot)
static int edbm_split_exec(bContext *C, wmOperator *op)
{
- Object *ob = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(ob);
- BMOperator bmop;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- EDBM_op_init(em, &bmop, op, "split geom=%hvef use_only_faces=%b", BM_ELEM_SELECT, false);
- BMO_op_exec(em->bm, &bmop);
- BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false);
- BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
- }
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
- /* Geometry has changed, need to recalc normals and looptris */
- EDBM_mesh_normals_update(em);
+ BMOperator bmop;
+ EDBM_op_init(em, &bmop, op, "split geom=%hvef use_only_faces=%b", BM_ELEM_SELECT, false);
+ BMO_op_exec(em->bm, &bmop);
+ BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT | BM_EDGE | BM_FACE, BM_ELEM_SELECT, false);
+ BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
- EDBM_update_generic(em, true, true);
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
+
+ /* Geometry has changed, need to recalc normals and looptris */
+ EDBM_mesh_normals_update(em);
+
+ EDBM_update_generic(em, true, true);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -5320,7 +5689,7 @@ static void sort_bmelem_flag(
}
BM_mesh_remap(em->bm, map[0], map[1], map[2]);
-/* DAG_id_tag_update(ob->data, 0);*/
+/* DEG_id_tag_update(ob->data, 0);*/
for (j = 3; j--; ) {
if (map[j])
@@ -5404,7 +5773,7 @@ static void edbm_sort_elements_ui(bContext *C, wmOperator *op)
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
/* Main auto-draw call. */
- uiDefAutoButsRNA(layout, &ptr, edbm_sort_elements_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, edbm_sort_elements_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
}
void MESH_OT_sort_elements(wmOperatorType *ot)
@@ -5459,84 +5828,6 @@ void MESH_OT_sort_elements(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Noise (Deform Vertices) Operator
- * \{ */
-
-static int edbm_noise_exec(bContext *C, wmOperator *op)
-{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- Material *ma;
- Tex *tex;
- BMVert *eve;
- BMIter iter;
- const float fac = RNA_float_get(op->ptr, "factor");
-
- if (em == NULL) {
- return OPERATOR_FINISHED;
- }
-
- if ((ma = give_current_material(obedit, obedit->actcol)) == NULL ||
- (tex = give_current_material_texture(ma)) == NULL)
- {
- BKE_report(op->reports, RPT_WARNING, "Mesh has no material or texture assigned");
- return OPERATOR_FINISHED;
- }
-
- if (tex->type == TEX_STUCCI) {
- float b2, vec[3];
- float ofs = tex->turbul / 200.0f;
- BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
- b2 = BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2]);
- if (tex->stype) ofs *= (b2 * b2);
- vec[0] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0] + ofs, eve->co[1], eve->co[2]));
- vec[1] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1] + ofs, eve->co[2]));
- vec[2] = fac * (b2 - BLI_hnoise(tex->noisesize, eve->co[0], eve->co[1], eve->co[2] + ofs));
-
- add_v3_v3(eve->co, vec);
- }
- }
- }
- else {
- BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
- float tin = 0.0f, dum;
- if (ma->mtex[ma->texact] != NULL) {
- externtex(ma->mtex[ma->texact], eve->co, &tin, &dum, &dum, &dum, &dum, 0, NULL, false, false);
- }
- eve->co[2] += fac * tin;
- }
- }
- }
-
- EDBM_mesh_normals_update(em);
-
- EDBM_update_generic(em, true, false);
-
- return OPERATOR_FINISHED;
-}
-
-void MESH_OT_noise(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Noise";
- ot->description = "Use vertex coordinate as texture coordinate";
- ot->idname = "MESH_OT_noise";
-
- /* api callbacks */
- ot->exec = edbm_noise_exec;
- ot->poll = ED_operator_editmesh;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- RNA_def_float(ot->srna, "factor", 0.1f, -1e4f, 1e4f, "Factor", "", 0.0f, 1.0f);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Bridge Operator
* \{ */
@@ -5975,30 +6266,42 @@ void MESH_OT_convex_hull(wmOperatorType *ot)
static int mesh_symmetrize_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMOperator bmop;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- const float thresh = RNA_float_get(op->ptr, "threshold");
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- EDBM_op_init(
- em, &bmop, op,
- "symmetrize input=%hvef direction=%i dist=%f",
- BM_ELEM_SELECT, RNA_enum_get(op->ptr, "direction"), thresh);
- BMO_op_exec(em->bm, &bmop);
+ if (em->bm->totvertsel == 0 ) {
+ continue;
+ }
+ BMOperator bmop;
- EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+ const float thresh = RNA_float_get(op->ptr, "threshold");
- BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
+ EDBM_op_init(
+ em, &bmop, op,
+ "symmetrize input=%hvef direction=%i dist=%f",
+ BM_ELEM_SELECT, RNA_enum_get(op->ptr, "direction"), thresh);
+ BMO_op_exec(em->bm, &bmop);
- if (!EDBM_op_finish(em, &bmop, op, true)) {
- return OPERATOR_CANCELLED;
- }
- else {
- EDBM_update_generic(em, true, true);
- EDBM_selectmode_flush(em);
- return OPERATOR_FINISHED;
+ EDBM_flag_disable_all(em, BM_ELEM_SELECT);
+
+ BMO_slot_buffer_hflag_enable(em->bm, bmop.slots_out, "geom.out", BM_ALL_NOLOOP, BM_ELEM_SELECT, true);
+
+ if (!EDBM_op_finish(em, &bmop, op, true)) {
+ continue;
+ }
+ else {
+ EDBM_update_generic(em, true, true);
+ EDBM_selectmode_flush(em);
+ }
}
+ MEM_freeN(objects);
+
+ return OPERATOR_FINISHED;
}
void MESH_OT_symmetrize(struct wmOperatorType *ot)
@@ -6165,45 +6468,59 @@ void MESH_OT_symmetry_snap(struct wmOperatorType *ot)
static int edbm_mark_freestyle_edge_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Mesh *me = (Mesh *)obedit->data;
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMEdge *eed;
BMIter iter;
FreestyleEdge *fed;
const bool clear = RNA_boolean_get(op->ptr, "clear");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- if (em == NULL)
- return OPERATOR_FINISHED;
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- /* auto-enable Freestyle edge mark drawing */
- if (clear == 0) {
- me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
- }
+ if (em == NULL) {
+ continue;
+ }
- if (!CustomData_has_layer(&em->bm->edata, CD_FREESTYLE_EDGE)) {
- BM_data_layer_add(em->bm, &em->bm->edata, CD_FREESTYLE_EDGE);
- }
+ BMesh *bm = em->bm;
+ Mesh *me = ((Mesh *)obedit->data);
- if (clear) {
- BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- fed = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
- fed->flag &= ~FREESTYLE_EDGE_MARK;
+ if (bm->totedgesel == 0) {
+ continue;
+ }
+
+ /* auto-enable Freestyle edge mark drawing */
+ if (clear == 0) {
+ me->drawflag |= ME_DRAW_FREESTYLE_EDGE;
+ }
+
+ if (!CustomData_has_layer(&em->bm->edata, CD_FREESTYLE_EDGE)) {
+ BM_data_layer_add(em->bm, &em->bm->edata, CD_FREESTYLE_EDGE);
+ }
+
+ if (clear) {
+ BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ fed = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
+ fed->flag &= ~FREESTYLE_EDGE_MARK;
+ }
}
}
- }
- else {
- BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- fed = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
- fed->flag |= FREESTYLE_EDGE_MARK;
+ else {
+ BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT) && !BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ fed = CustomData_bmesh_get(&em->bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
+ fed->flag |= FREESTYLE_EDGE_MARK;
+ }
}
}
- }
- DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ DEG_id_tag_update(obedit->data, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
@@ -6236,44 +6553,57 @@ void MESH_OT_mark_freestyle_edge(wmOperatorType *ot)
static int edbm_mark_freestyle_face_exec(bContext *C, wmOperator *op)
{
- Object *obedit = CTX_data_edit_object(C);
- Mesh *me = (Mesh *)obedit->data;
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMIter iter;
FreestyleFace *ffa;
const bool clear = RNA_boolean_get(op->ptr, "clear");
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- if (em == NULL) return OPERATOR_FINISHED;
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ Mesh *me = (Mesh *)obedit->data;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- /* auto-enable Freestyle face mark drawing */
- if (!clear) {
- me->drawflag |= ME_DRAW_FREESTYLE_FACE;
- }
+ if (em == NULL) {
+ continue;
+ }
- if (!CustomData_has_layer(&em->bm->pdata, CD_FREESTYLE_FACE)) {
- BM_data_layer_add(em->bm, &em->bm->pdata, CD_FREESTYLE_FACE);
- }
+ if (em->bm->totfacesel == 0) {
+ continue;
+ }
- if (clear) {
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- ffa = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
- ffa->flag &= ~FREESTYLE_FACE_MARK;
+ /* auto-enable Freestyle face mark drawing */
+ if (!clear) {
+ me->drawflag |= ME_DRAW_FREESTYLE_FACE;
+ }
+
+ if (!CustomData_has_layer(&em->bm->pdata, CD_FREESTYLE_FACE)) {
+ BM_data_layer_add(em->bm, &em->bm->pdata, CD_FREESTYLE_FACE);
+ }
+
+ if (clear) {
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ ffa = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
+ ffa->flag &= ~FREESTYLE_FACE_MARK;
+ }
}
}
- }
- else {
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- ffa = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
- ffa->flag |= FREESTYLE_FACE_MARK;
+ else {
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ ffa = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
+ ffa->flag |= FREESTYLE_FACE_MARK;
+ }
}
}
- }
- DAG_id_tag_update(obedit->data, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ DEG_id_tag_update(obedit->data, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ }
+ MEM_freeN(objects);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/mesh/editmesh_undo.c b/source/blender/editors/mesh/editmesh_undo.c
index 50aecd0a821..4d4b7a098b0 100644
--- a/source/blender/editors/mesh/editmesh_undo.c
+++ b/source/blender/editors/mesh/editmesh_undo.c
@@ -24,9 +24,12 @@
#include "MEM_guardedalloc.h"
+#include "CLG_log.h"
+
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_key_types.h"
+#include "DNA_layer_types.h"
#include "BLI_listbase.h"
#include "BLI_array_utils.h"
@@ -35,14 +38,17 @@
#include "BKE_DerivedMesh.h"
#include "BKE_context.h"
#include "BKE_key.h"
+#include "BKE_layer.h"
#include "BKE_mesh.h"
#include "BKE_editmesh.h"
-#include "BKE_depsgraph.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_object.h"
#include "ED_mesh.h"
#include "ED_util.h"
+#include "ED_undo.h"
#include "WM_types.h"
#include "WM_api.h"
@@ -68,6 +74,9 @@
# include "BLI_task.h"
#endif
+/** We only need this locally. */
+static CLG_LogRef LOG = {"ed.undo.mesh"};
+
/* -------------------------------------------------------------------- */
/** \name Undo Conversion
* \{ */
@@ -667,80 +676,23 @@ static Object *editmesh_object_from_context(bContext *C)
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
+ *
+ * \note This is similar for all edit-mode types.
* \{ */
+typedef struct MeshUndoStep_Elem {
+ struct MeshUndoStep_Elem *next, *prev;
+ UndoRefID_Object obedit_ref;
+ UndoMesh data;
+} MeshUndoStep_Elem;
+
typedef struct MeshUndoStep {
UndoStep step;
- /* Use for all ID lookups (can be NULL). */
struct UndoIDPtrMap *id_map;
-
- /* note: will split out into list for multi-object-editmode. */
- UndoRefID_Object obedit_ref;
- /* Needed for MTexPoly's image use. */
- UndoRefID_Object *image_array_ref;
- UndoMesh data;
+ MeshUndoStep_Elem *elems;
+ uint elems_len;
} MeshUndoStep;
-static void mesh_undosys_step_encode_store_ids(MeshUndoStep *us)
-{
- Mesh *me = us->obedit_ref.ptr->data;
- BMesh *bm = me->edit_btmesh->bm;
- const int mtex_len = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
- if (mtex_len != 0) {
- ID **id_prev_array = BLI_array_alloca(id_prev_array, mtex_len);
- memset(id_prev_array, 0x0, sizeof(*id_prev_array) * mtex_len);
-
- BMIter iter;
- BMFace *efa;
-
- if (us->id_map == NULL) {
- us->id_map = BKE_undosys_ID_map_create();
- }
-
- uint cd_poly_tex_offset_first = CustomData_get_n_offset(&bm->pdata, CD_MTEXPOLY, 0);
- uint cd_poly_tex_offset_end = cd_poly_tex_offset_first + (sizeof(MTexPoly) * mtex_len);
- BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
- for (uint cd_poly_tex_offset = cd_poly_tex_offset_first, i = 0;
- cd_poly_tex_offset < cd_poly_tex_offset_end;
- cd_poly_tex_offset += sizeof(MTexPoly), i++)
- {
- const MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (tf->tpage != NULL) {
- BKE_undosys_ID_map_add_with_prev(us->id_map, (ID *)tf->tpage, &id_prev_array[i]);
- }
- }
- }
- }
-}
-
-static void mesh_undosys_step_decode_restore_ids(MeshUndoStep *us)
-{
- Mesh *me = us->obedit_ref.ptr->data;
- BMesh *bm = me->edit_btmesh->bm;
- const int mtex_len = CustomData_number_of_layers(&bm->pdata, CD_MTEXPOLY);
- if (mtex_len != 0 && us->id_map) {
- BMIter iter;
- BMFace *efa;
-
- ID *(*id_prev_array)[2] = BLI_array_alloca(id_prev_array, mtex_len);
- memset(id_prev_array, 0x0, sizeof(*id_prev_array) * mtex_len);
-
- uint cd_poly_tex_offset_first = CustomData_get_n_offset(&bm->pdata, CD_MTEXPOLY, 0);
- uint cd_poly_tex_offset_end = cd_poly_tex_offset_first + (sizeof(MTexPoly) * mtex_len);
- BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
- for (uint cd_poly_tex_offset = cd_poly_tex_offset_first, i = 0;
- cd_poly_tex_offset < cd_poly_tex_offset_end;
- cd_poly_tex_offset += sizeof(MTexPoly), i++)
- {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (tf->tpage != NULL) {
- tf->tpage = (Image *)BKE_undosys_ID_map_lookup_with_prev(us->id_map, (ID *)tf->tpage, id_prev_array[i]);
- }
- }
- }
- }
-}
-
static bool mesh_undosys_poll(bContext *C)
{
return editmesh_object_from_context(C) != NULL;
@@ -749,11 +701,24 @@ static bool mesh_undosys_poll(bContext *C)
static bool mesh_undosys_step_encode(struct bContext *C, UndoStep *us_p)
{
MeshUndoStep *us = (MeshUndoStep *)us_p;
- us->obedit_ref.ptr = editmesh_object_from_context(C);
- Mesh *me = us->obedit_ref.ptr->data;
- undomesh_from_editmesh(&us->data, me->edit_btmesh, me->key);
- mesh_undosys_step_encode_store_ids(us);
- us->step.data_size = us->data.undo_size;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__);
+ us->elems_len = objects_len;
+
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ MeshUndoStep_Elem *elem = &us->elems[i];
+
+ elem->obedit_ref.ptr = ob;
+ Mesh *me = elem->obedit_ref.ptr->data;
+ undomesh_from_editmesh(&elem->data, me->edit_btmesh, me->key);
+ us->step.data_size += elem->data.undo_size;
+ }
+ MEM_freeN(objects);
return true;
}
@@ -764,19 +729,37 @@ static void mesh_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNU
BLI_assert(mesh_undosys_poll(C));
MeshUndoStep *us = (MeshUndoStep *)us_p;
- Object *obedit = us->obedit_ref.ptr;
- Mesh *me = obedit->data;
- BMEditMesh *em = me->edit_btmesh;
- undomesh_to_editmesh(&us->data, em, obedit->data);
- mesh_undosys_step_decode_restore_ids(us);
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ MeshUndoStep_Elem *elem = &us->elems[i];
+ Object *obedit = elem->obedit_ref.ptr;
+ Mesh *me = obedit->data;
+ if (me->edit_btmesh == NULL) {
+ /* Should never fail, may not crash but can give odd behavior. */
+ CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid",
+ us_p->name, obedit->id.name);
+ continue;
+ }
+ BMEditMesh *em = me->edit_btmesh;
+ undomesh_to_editmesh(&elem->data, em, obedit->data);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ }
+
+ /* The first element is always active */
+ ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
+
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
static void mesh_undosys_step_free(UndoStep *us_p)
{
MeshUndoStep *us = (MeshUndoStep *)us_p;
- undomesh_free_data(&us->data);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ MeshUndoStep_Elem *elem = &us->elems[i];
+ undomesh_free_data(&elem->data);
+ }
+ MEM_freeN(us->elems);
if (us->id_map != NULL) {
BKE_undosys_ID_map_destroy(us->id_map);
@@ -787,7 +770,12 @@ static void mesh_undosys_foreach_ID_ref(
UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
{
MeshUndoStep *us = (MeshUndoStep *)us_p;
- foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref));
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ MeshUndoStep_Elem *elem = &us->elems[i];
+ foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref));
+ }
+
if (us->id_map != NULL) {
BKE_undosys_ID_map_foreach_ID_ref(us->id_map, foreach_ID_ref_fn, user_data);
}
diff --git a/source/blender/editors/mesh/editmesh_utils.c b/source/blender/editors/mesh/editmesh_utils.c
index 41e8a963383..e8f3e592715 100644
--- a/source/blender/editors/mesh/editmesh_utils.c
+++ b/source/blender/editors/mesh/editmesh_utils.c
@@ -43,13 +43,14 @@
#include "BKE_DerivedMesh.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_report.h"
#include "BKE_editmesh.h"
#include "BKE_editmesh_bvh.h"
+#include "DEG_depsgraph.h"
+
#include "BKE_object.h" /* XXX. only for EDBM_mesh_load(). */
#include "WM_api.h"
@@ -323,7 +324,7 @@ void EDBM_mesh_make(Object *ob, const int select_mode, const bool add_key_index)
/**
* \warning This can invalidate the #DerivedMesh cache of other objects (for linked duplicates).
- * Most callers should run #DAG_id_tag_update on \a ob->data, see: T46738, T46913
+ * Most callers should run #DEG_id_tag_update on \a ob->data, see: T46738, T46913
*/
void EDBM_mesh_load(Object *ob)
{
@@ -511,7 +512,6 @@ UvVertMap *BM_uv_vert_map_create(
/* vars from original func */
UvVertMap *vmap;
UvMapVert *buf;
- /* MTexPoly *tf; */ /* UNUSED */
MLoopUV *luv;
unsigned int a;
int totverts, i, totuv, totfaces;
@@ -553,7 +553,7 @@ UvVertMap *BM_uv_vert_map_create(
BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, a) {
if ((use_select == false) || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
- float (*tf_uv)[2];
+ float (*tf_uv)[2] = NULL;
if (use_winding) {
tf_uv = (float (*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, efa->len);
@@ -593,7 +593,6 @@ UvVertMap *BM_uv_vert_map_create(
newvlist = v;
efa = BM_face_at_index(bm, v->f);
- /* tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
l = BM_iter_at_index(bm, BM_LOOPS_OF_FACE, efa, v->tfindex);
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
@@ -605,8 +604,6 @@ UvVertMap *BM_uv_vert_map_create(
while (iterv) {
next = iterv->next;
efa = BM_face_at_index(bm, iterv->f);
- /* tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY); */ /* UNUSED */
-
l = BM_iter_at_index(bm, BM_LOOPS_OF_FACE, efa, iterv->tfindex);
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
uv2 = luv->uv;
@@ -660,7 +657,7 @@ UvElementMap *BM_uv_element_map_create(
/* vars from original func */
UvElementMap *element_map;
UvElement *buf;
- bool *winding;
+ bool *winding = NULL;
BLI_buffer_declare_static(vec2f, tf_uv_buf, BLI_BUFFER_NOP, BM_DEFAULT_NGON_STACK_SIZE);
MLoopUV *luv;
@@ -701,7 +698,7 @@ UvElementMap *BM_uv_element_map_create(
}
if (!selected || BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
- float (*tf_uv)[2];
+ float (*tf_uv)[2] = NULL;
if (use_winding) {
tf_uv = (float (*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, efa->len);
@@ -925,7 +922,7 @@ UvElement *BM_uv_element_get(UvElementMap *map, BMFace *efa, BMLoop *l)
/* last_sel, use em->act_face otherwise get the last selected face in the editselections
* at the moment, last_sel is mainly useful for making sure the space image dosnt flicker */
-BMFace *EDBM_uv_active_face_get(BMEditMesh *em, const bool sloppy, const bool selected, MTexPoly **r_tf)
+BMFace *EDBM_uv_active_face_get(BMEditMesh *em, const bool sloppy, const bool selected)
{
BMFace *efa = NULL;
@@ -936,11 +933,9 @@ BMFace *EDBM_uv_active_face_get(BMEditMesh *em, const bool sloppy, const bool se
efa = BM_mesh_active_face_get(em->bm, sloppy, selected);
if (efa) {
- if (r_tf) *r_tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
return efa;
}
- if (r_tf) *r_tf = NULL;
return NULL;
}
@@ -949,7 +944,6 @@ bool EDBM_uv_check(BMEditMesh *em)
{
/* some of these checks could be a touch overkill */
return em && em->bm->totface &&
- CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY) &&
CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV);
}
@@ -1008,7 +1002,7 @@ void EDBM_verts_mirror_cache_begin_ex(
BMesh *bm = em->bm;
BMIter iter;
BMVert *v;
- int cd_vmirr_offset;
+ int cd_vmirr_offset = 0;
int i;
const float maxdist_sq = SQUARE(maxdist);
@@ -1036,7 +1030,7 @@ void EDBM_verts_mirror_cache_begin_ex(
BM_mesh_elem_index_ensure(bm, BM_VERT);
if (use_topology) {
- ED_mesh_mirrtopo_init(me, NULL, -1, &mesh_topo_store, true);
+ ED_mesh_mirrtopo_init(me, NULL, &mesh_topo_store, true);
}
else {
tree = BLI_kdtree_new(bm->totvert);
@@ -1334,7 +1328,7 @@ void EDBM_update_generic(BMEditMesh *em, const bool do_tessface, const bool is_d
{
Object *ob = em->ob;
/* order of calling isn't important */
- DAG_id_tag_update(ob->data, OB_RECALC_DATA);
+ DEG_id_tag_update(ob->data, OB_RECALC_DATA);
WM_main_add_notifier(NC_GEOM | ND_DATA, ob->data);
if (do_tessface) {
@@ -1486,7 +1480,9 @@ static void scale_point(float c1[3], const float p[3], const float s)
add_v3_v3(c1, p);
}
-bool BMBVH_EdgeVisible(struct BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v3d, Object *obedit)
+bool BMBVH_EdgeVisible(struct BMBVHTree *tree, BMEdge *e,
+ struct Depsgraph *depsgraph,
+ ARegion *ar, View3D *v3d, Object *obedit)
{
BMFace *f;
float co1[3], co2[3], co3[3], dir1[3], dir2[3], dir3[3];
@@ -1498,7 +1494,7 @@ bool BMBVH_EdgeVisible(struct BMBVHTree *tree, BMEdge *e, ARegion *ar, View3D *v
ar->winy / 2.0f,
};
- ED_view3d_win_to_segment(ar, v3d, mval_f, origin, end, false);
+ ED_view3d_win_to_segment(depsgraph, ar, v3d, mval_f, origin, end, false);
invert_m4_m4(invmat, obedit->obmat);
mul_m4_v3(invmat, origin);
diff --git a/source/blender/editors/mesh/mesh_data.c b/source/blender/editors/mesh/mesh_data.c
index 84d2ac3cef1..676af4fea5b 100644
--- a/source/blender/editors/mesh/mesh_data.c
+++ b/source/blender/editors/mesh/mesh_data.c
@@ -42,7 +42,6 @@
#include "BLI_math.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
@@ -50,6 +49,8 @@
#include "BKE_report.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_define.h"
#include "WM_api.h"
@@ -245,14 +246,14 @@ void ED_mesh_uv_loop_reset_ex(struct Mesh *me, const int layernum)
}
}
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
}
void ED_mesh_uv_loop_reset(struct bContext *C, struct Mesh *me)
{
/* could be ldata or pdata */
- CustomData *pdata = GET_CD_DATA(me, pdata);
- const int layernum = CustomData_get_active_layer(pdata, CD_MTEXPOLY);
+ CustomData *ldata = GET_CD_DATA(me, ldata);
+ const int layernum = CustomData_get_active_layer(ldata, CD_MLOOPUV);
ED_mesh_uv_loop_reset_ex(me, layernum);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
@@ -269,21 +270,10 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
if (me->edit_btmesh) {
em = me->edit_btmesh;
- layernum_dst = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
+ layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV);
if (layernum_dst >= MAX_MTFACE)
return -1;
- /* CD_MTEXPOLY */
- BM_data_layer_add_named(em->bm, &em->bm->pdata, CD_MTEXPOLY, name);
- /* copy data from active UV */
- if (layernum_dst) {
- const int layernum_src = CustomData_get_active_layer(&em->bm->pdata, CD_MTEXPOLY);
- BM_data_layer_copy(em->bm, &em->bm->pdata, CD_MTEXPOLY, layernum_src, layernum_dst);
- }
- if (active_set || layernum_dst == 0) {
- CustomData_set_layer_active(&em->bm->pdata, CD_MTEXPOLY, layernum_dst);
- }
-
/* CD_MLOOPUV */
BM_data_layer_add_named(em->bm, &em->bm->ldata, CD_MLOOPUV, name);
/* copy data from active UV */
@@ -298,26 +288,22 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
}
}
else {
- layernum_dst = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+ layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
if (layernum_dst >= MAX_MTFACE)
return -1;
- if (me->mtpoly) {
- CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DUPLICATE, me->mtpoly, me->totpoly, name);
+ if (me->mloopuv) {
CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DUPLICATE, me->mloopuv, me->totloop, name);
CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DUPLICATE, me->mtface, me->totface, name);
is_init = true;
}
else {
- CustomData_add_layer_named(&me->pdata, CD_MTEXPOLY, CD_DEFAULT, NULL, me->totpoly, name);
CustomData_add_layer_named(&me->ldata, CD_MLOOPUV, CD_DEFAULT, NULL, me->totloop, name);
CustomData_add_layer_named(&me->fdata, CD_MTFACE, CD_DEFAULT, NULL, me->totface, name);
}
if (active_set || layernum_dst == 0) {
- CustomData_set_layer_active(&me->pdata, CD_MTEXPOLY, layernum_dst);
CustomData_set_layer_active(&me->ldata, CD_MLOOPUV, layernum_dst);
-
CustomData_set_layer_active(&me->fdata, CD_MTFACE, layernum_dst);
}
@@ -329,7 +315,7 @@ int ED_mesh_uv_texture_add(Mesh *me, const char *name, const bool active_set)
ED_mesh_uv_loop_reset_ex(me, layernum_dst);
}
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, me);
return layernum_dst;
@@ -343,12 +329,12 @@ void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name)
if (me->edit_btmesh) {
em = me->edit_btmesh;
- layernum_dst = CustomData_number_of_layers(&em->bm->pdata, CD_MTEXPOLY);
+ layernum_dst = CustomData_number_of_layers(&em->bm->ldata, CD_MLOOPUV);
if (layernum_dst == 0)
ED_mesh_uv_texture_add(me, name, true);
}
else {
- layernum_dst = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+ layernum_dst = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
if (layernum_dst == 0)
ED_mesh_uv_texture_add(me, name, true);
}
@@ -357,23 +343,19 @@ void ED_mesh_uv_texture_ensure(struct Mesh *me, const char *name)
bool ED_mesh_uv_texture_remove_index(Mesh *me, const int n)
{
- CustomData *pdata = GET_CD_DATA(me, pdata), *ldata = GET_CD_DATA(me, ldata);
- CustomDataLayer *cdlp, *cdlu;
+ CustomData *ldata = GET_CD_DATA(me, ldata);
+ CustomDataLayer *cdlu;
int index;
- index = CustomData_get_layer_index_n(pdata, CD_MTEXPOLY, n);
- cdlp = (index == -1) ? NULL : &pdata->layers[index];
-
index = CustomData_get_layer_index_n(ldata, CD_MLOOPUV, n);
cdlu = (index == -1) ? NULL : &ldata->layers[index];
- if (!cdlp || !cdlu)
+ if (!cdlu)
return false;
- delete_customdata_layer(me, cdlp);
delete_customdata_layer(me, cdlu);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, me);
return true;
@@ -381,14 +363,8 @@ bool ED_mesh_uv_texture_remove_index(Mesh *me, const int n)
bool ED_mesh_uv_texture_remove_active(Mesh *me)
{
/* texpoly/uv are assumed to be in sync */
- CustomData *pdata = GET_CD_DATA(me, pdata);
- const int n = CustomData_get_active_layer(pdata, CD_MTEXPOLY);
-
- /* double check active layers align! */
-#ifdef DEBUG
CustomData *ldata = GET_CD_DATA(me, ldata);
- BLI_assert(CustomData_get_active_layer(ldata, CD_MLOOPUV) == n);
-#endif
+ const int n = CustomData_get_active_layer(ldata, CD_MLOOPUV);
if (n != -1) {
return ED_mesh_uv_texture_remove_index(me, n);
@@ -400,8 +376,8 @@ bool ED_mesh_uv_texture_remove_active(Mesh *me)
bool ED_mesh_uv_texture_remove_named(Mesh *me, const char *name)
{
/* texpoly/uv are assumed to be in sync */
- CustomData *pdata = GET_CD_DATA(me, pdata);
- const int n = CustomData_get_named_layer(pdata, CD_MTEXPOLY, name);
+ CustomData *ldata = GET_CD_DATA(me, ldata);
+ const int n = CustomData_get_named_layer(ldata, CD_MLOOPUV, name);
if (n != -1) {
return ED_mesh_uv_texture_remove_index(me, n);
}
@@ -458,7 +434,7 @@ int ED_mesh_color_add(Mesh *me, const char *name, const bool active_set)
BKE_mesh_update_customdata_pointers(me, true);
}
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, me);
return layernum;
@@ -473,7 +449,7 @@ bool ED_mesh_color_ensure(struct Mesh *me, const char *name)
BKE_mesh_update_customdata_pointers(me, true);
}
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
return (me->mloopcol != NULL);
}
@@ -491,7 +467,7 @@ bool ED_mesh_color_remove_index(Mesh *me, const int n)
return false;
delete_customdata_layer(me, cdl);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, me);
return true;
@@ -562,7 +538,6 @@ void MESH_OT_uv_texture_add(wmOperatorType *ot)
static int drop_named_image_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
View3D *v3d = CTX_wm_view3d(C);
Base *base;
@@ -602,8 +577,6 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, const wmEvent *e
if (me->edit_btmesh == NULL)
return OPERATOR_CANCELLED;
- ED_uvedit_assign_image(bmain, scene, obedit, ima, NULL);
-
if (exitmode) {
EDBM_mesh_load(obedit);
EDBM_mesh_free(me->edit_btmesh);
@@ -612,7 +585,7 @@ static int drop_named_image_invoke(bContext *C, wmOperator *op, const wmEvent *e
/* load_editMesh free's pointers used by CustomData layers which might be used by DerivedMesh too,
* so signal to re-create DerivedMesh here (sergey) */
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
}
/* dummie drop support; ensure view shows a result :) */
@@ -751,7 +724,7 @@ static int mesh_customdata_clear_exec__internal(bContext *C,
CustomData_free_layers(data, type, tot);
}
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return OPERATOR_FINISHED;
@@ -847,7 +820,7 @@ static int mesh_customdata_skin_add_exec(bContext *C, wmOperator *UNUSED(op))
BKE_mesh_ensure_skin_customdata(me);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return OPERATOR_FINISHED;
@@ -938,7 +911,7 @@ static int mesh_customdata_custom_splitnormals_add_exec(bContext *C, wmOperator
CustomData_add_layer(data, CD_CUSTOMLOOPNORMAL, CD_DEFAULT, NULL, me->totloop);
}
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return OPERATOR_FINISHED;
@@ -1015,7 +988,7 @@ void ED_mesh_update(Mesh *mesh, bContext *C, int calc_edges, int calc_tessface)
BKE_mesh_calc_normals(mesh);
- DAG_id_tag_update(&mesh->id, 0);
+ DEG_id_tag_update(&mesh->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mesh);
}
@@ -1335,7 +1308,6 @@ void ED_mesh_calc_tessface(Mesh *mesh, bool free_mpoly)
mesh->mloopcol = NULL;
mesh->mloopuv = NULL;
mesh->mpoly = NULL;
- mesh->mtpoly = NULL;
}
}
diff --git a/source/blender/editors/mesh/mesh_intern.h b/source/blender/editors/mesh/mesh_intern.h
index 71e283ea043..aefc8d72b72 100644
--- a/source/blender/editors/mesh/mesh_intern.h
+++ b/source/blender/editors/mesh/mesh_intern.h
@@ -113,6 +113,12 @@ void MESH_OT_screw(struct wmOperatorType *ot);
/* *** editmesh_extrude_spin.c *** */
void MESH_OT_spin(struct wmOperatorType *ot);
+/* *** editmesh_polybuild.c *** */
+void MESH_OT_polybuild_face_at_cursor(struct wmOperatorType *ot);
+void MESH_OT_polybuild_split_at_cursor(struct wmOperatorType *ot);
+void MESH_OT_polybuild_dissolve_at_cursor(struct wmOperatorType *ot);
+void MESH_OT_polybuild_hover(struct wmOperatorType *ot);
+
/* *** editmesh_inset.c *** */
void MESH_OT_inset(struct wmOperatorType *ot);
@@ -208,7 +214,6 @@ void MESH_OT_hide(struct wmOperatorType *ot);
void MESH_OT_reveal(struct wmOperatorType *ot);
void MESH_OT_mark_seam(struct wmOperatorType *ot);
void MESH_OT_mark_sharp(struct wmOperatorType *ot);
-void MESH_OT_noise(struct wmOperatorType *ot);
void MESH_OT_flip_normals(struct wmOperatorType *ot);
void MESH_OT_solidify(struct wmOperatorType *ot);
void MESH_OT_knife_cut(struct wmOperatorType *ot);
@@ -252,12 +257,4 @@ void MESH_OT_customdata_custom_splitnormals_clear(struct wmOperatorType *ot);
void MESH_OT_drop_named_image(struct wmOperatorType *ot);
-/* *** mesh_navmesh.c *** */
-void MESH_OT_navmesh_make(struct wmOperatorType *ot);
-void MESH_OT_navmesh_face_copy(struct wmOperatorType *ot);
-void MESH_OT_navmesh_face_add(struct wmOperatorType *ot);
-void MESH_OT_navmesh_reset(struct wmOperatorType *ot);
-void MESH_OT_navmesh_clear(struct wmOperatorType *ot);
-
-
#endif /* __MESH_INTERN_H__ */
diff --git a/source/blender/editors/mesh/mesh_mirror.c b/source/blender/editors/mesh/mesh_mirror.c
index 96b9f054252..22bfd8eedea 100644
--- a/source/blender/editors/mesh/mesh_mirror.c
+++ b/source/blender/editors/mesh/mesh_mirror.c
@@ -141,8 +141,9 @@ static int mirrtopo_vert_sort(const void *v1, const void *v2)
return 0;
}
-bool ED_mesh_mirrtopo_recalc_check(Mesh *me, DerivedMesh *dm, const int ob_mode, MirrTopoStore_t *mesh_topo_store)
+bool ED_mesh_mirrtopo_recalc_check(Mesh *me, DerivedMesh *dm, MirrTopoStore_t *mesh_topo_store)
{
+ const bool is_editmode = (me->edit_btmesh != NULL);
int totvert;
int totedge;
@@ -160,7 +161,7 @@ bool ED_mesh_mirrtopo_recalc_check(Mesh *me, DerivedMesh *dm, const int ob_mode,
}
if ((mesh_topo_store->index_lookup == NULL) ||
- (mesh_topo_store->prev_ob_mode != ob_mode) ||
+ (mesh_topo_store->prev_is_editmode != is_editmode) ||
(totvert != mesh_topo_store->prev_vert_tot) ||
(totedge != mesh_topo_store->prev_edge_tot))
{
@@ -172,9 +173,11 @@ bool ED_mesh_mirrtopo_recalc_check(Mesh *me, DerivedMesh *dm, const int ob_mode,
}
-void ED_mesh_mirrtopo_init(Mesh *me, DerivedMesh *dm, const int ob_mode, MirrTopoStore_t *mesh_topo_store,
- const bool skip_em_vert_array_init)
+void ED_mesh_mirrtopo_init(
+ Mesh *me, DerivedMesh *dm, MirrTopoStore_t *mesh_topo_store,
+ const bool skip_em_vert_array_init)
{
+ const bool is_editmode = (me->edit_btmesh != NULL);
MEdge *medge = NULL, *med;
BMEditMesh *em = dm ? NULL : me->edit_btmesh;
@@ -197,7 +200,7 @@ void ED_mesh_mirrtopo_init(Mesh *me, DerivedMesh *dm, const int ob_mode, MirrTop
/* reallocate if needed */
ED_mesh_mirrtopo_free(mesh_topo_store);
- mesh_topo_store->prev_ob_mode = ob_mode;
+ mesh_topo_store->prev_is_editmode = is_editmode;
if (em) {
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
diff --git a/source/blender/editors/mesh/mesh_navmesh.c b/source/blender/editors/mesh/mesh_navmesh.c
deleted file mode 100644
index 0f1884f4017..00000000000
--- a/source/blender/editors/mesh/mesh_navmesh.c
+++ /dev/null
@@ -1,732 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2011 by Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Benoit Bolsee,
- * Nick Samarin
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/mesh/mesh_navmesh.c
- * \ingroup edmesh
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_scene_types.h"
-#include "DNA_object_types.h"
-#include "DNA_mesh_types.h"
-
-#include "BLI_listbase.h"
-#include "BLI_math_vector.h"
-#include "BLI_linklist.h"
-
-#include "BKE_library.h"
-#include "BKE_depsgraph.h"
-#include "BKE_context.h"
-#include "BKE_mesh.h"
-#include "BKE_scene.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_report.h"
-#include "BKE_editmesh.h"
-
-#include "ED_object.h"
-#include "ED_mesh.h"
-#include "ED_screen.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "recast-capi.h"
-
-#include "mesh_intern.h" /* own include */
-
-
-static void createVertsTrisData(bContext *C, LinkNode *obs,
- int *nverts_r, float **verts_r, int *ntris_r, int **tris_r, unsigned int *r_lay)
-{
- MVert *mvert;
- int nfaces = 0, *tri, i, curnverts, basenverts, curnfaces;
- MFace *mface;
- float co[3], wco[3];
- Object *ob;
- LinkNode *oblink, *dmlink;
- DerivedMesh *dm;
- Scene *scene = CTX_data_scene(C);
- LinkNodePair dms_pair = {NULL, NULL};
-
- int nverts, ntris, *tris;
- float *verts;
-
- nverts = 0;
- ntris = 0;
-
- /* calculate number of verts and tris */
- for (oblink = obs; oblink; oblink = oblink->next) {
- ob = (Object *) oblink->link;
- dm = mesh_create_derived_no_virtual(scene, ob, NULL, CD_MASK_MESH);
- DM_ensure_tessface(dm);
- BLI_linklist_append(&dms_pair, dm);
-
- nverts += dm->getNumVerts(dm);
- nfaces = dm->getNumTessFaces(dm);
- ntris += nfaces;
-
- /* resolve quad faces */
- mface = dm->getTessFaceArray(dm);
- for (i = 0; i < nfaces; i++) {
- MFace *mf = &mface[i];
- if (mf->v4)
- ntris += 1;
- }
-
- *r_lay |= ob->lay;
- }
- LinkNode *dms = dms_pair.list;
-
- /* create data */
- verts = MEM_mallocN(sizeof(float) * 3 * nverts, "createVertsTrisData verts");
- tris = MEM_mallocN(sizeof(int) * 3 * ntris, "createVertsTrisData faces");
-
- basenverts = 0;
- tri = tris;
- for (oblink = obs, dmlink = dms; oblink && dmlink;
- oblink = oblink->next, dmlink = dmlink->next)
- {
- ob = (Object *) oblink->link;
- dm = (DerivedMesh *) dmlink->link;
-
- curnverts = dm->getNumVerts(dm);
- mvert = dm->getVertArray(dm);
-
- /* copy verts */
- for (i = 0; i < curnverts; i++) {
- MVert *v = &mvert[i];
-
- copy_v3_v3(co, v->co);
- mul_v3_m4v3(wco, ob->obmat, co);
-
- verts[3 * (basenverts + i) + 0] = wco[0];
- verts[3 * (basenverts + i) + 1] = wco[2];
- verts[3 * (basenverts + i) + 2] = wco[1];
- }
-
- /* create tris */
- curnfaces = dm->getNumTessFaces(dm);
- mface = dm->getTessFaceArray(dm);
-
- for (i = 0; i < curnfaces; i++) {
- MFace *mf = &mface[i];
-
- tri[0] = basenverts + mf->v1;
- tri[1] = basenverts + mf->v3;
- tri[2] = basenverts + mf->v2;
- tri += 3;
-
- if (mf->v4) {
- tri[0] = basenverts + mf->v1;
- tri[1] = basenverts + mf->v4;
- tri[2] = basenverts + mf->v3;
- tri += 3;
- }
- }
-
- basenverts += curnverts;
- }
-
- /* release derived mesh */
- for (dmlink = dms; dmlink; dmlink = dmlink->next) {
- dm = (DerivedMesh *) dmlink->link;
- dm->release(dm);
- }
-
- BLI_linklist_free(dms, NULL);
-
- *nverts_r = nverts;
- *verts_r = verts;
- *ntris_r = ntris;
- *tris_r = tris;
-}
-
-static bool buildNavMesh(const RecastData *recastParams, int nverts, float *verts, int ntris, int *tris,
- struct recast_polyMesh **pmesh, struct recast_polyMeshDetail **dmesh,
- ReportList *reports)
-{
- float bmin[3], bmax[3];
- struct recast_heightfield *solid;
- unsigned char *triflags;
- struct recast_compactHeightfield *chf;
- struct recast_contourSet *cset;
- int width, height, walkableHeight, walkableClimb, walkableRadius;
- int minRegionArea, mergeRegionArea, maxEdgeLen;
- float detailSampleDist, detailSampleMaxError;
-
- recast_calcBounds(verts, nverts, bmin, bmax);
-
- /* ** Step 1. Initialize build config ** */
- walkableHeight = (int)ceilf(recastParams->agentheight / recastParams->cellheight);
- walkableClimb = (int)floorf(recastParams->agentmaxclimb / recastParams->cellheight);
- walkableRadius = (int)ceilf(recastParams->agentradius / recastParams->cellsize);
- minRegionArea = (int)(recastParams->regionminsize * recastParams->regionminsize);
- mergeRegionArea = (int)(recastParams->regionmergesize * recastParams->regionmergesize);
- maxEdgeLen = (int)(recastParams->edgemaxlen / recastParams->cellsize);
- detailSampleDist = recastParams->detailsampledist < 0.9f ? 0 :
- recastParams->cellsize * recastParams->detailsampledist;
- detailSampleMaxError = recastParams->cellheight * recastParams->detailsamplemaxerror;
-
- /* Set the area where the navigation will be build. */
- recast_calcGridSize(bmin, bmax, recastParams->cellsize, &width, &height);
-
- /* zero dimensions cause zero alloc later on [#33758] */
- if (width <= 0 || height <= 0) {
- BKE_report(reports, RPT_ERROR, "Object has a width or height of zero");
- return false;
- }
-
- /* ** Step 2: Rasterize input polygon soup ** */
- /* Allocate voxel heightfield where we rasterize our input data to */
- solid = recast_newHeightfield();
-
- if (!recast_createHeightfield(solid, width, height, bmin, bmax, recastParams->cellsize, recastParams->cellheight)) {
- recast_destroyHeightfield(solid);
- BKE_report(reports, RPT_ERROR, "Failed to create height field");
- return false;
- }
-
- /* Allocate array that can hold triangle flags */
- triflags = MEM_callocN(sizeof(unsigned char) * ntris, "buildNavMesh triflags");
-
- /* Find triangles which are walkable based on their slope and rasterize them */
- recast_markWalkableTriangles(RAD2DEGF(recastParams->agentmaxslope), verts, nverts, tris, ntris, triflags);
- recast_rasterizeTriangles(verts, nverts, tris, triflags, ntris, solid, 1);
- MEM_freeN(triflags);
-
- /* ** Step 3: Filter walkables surfaces ** */
- recast_filterLowHangingWalkableObstacles(walkableClimb, solid);
- recast_filterLedgeSpans(walkableHeight, walkableClimb, solid);
- recast_filterWalkableLowHeightSpans(walkableHeight, solid);
-
- /* ** Step 4: Partition walkable surface to simple regions ** */
-
- chf = recast_newCompactHeightfield();
- if (!recast_buildCompactHeightfield(walkableHeight, walkableClimb, solid, chf)) {
- recast_destroyHeightfield(solid);
- recast_destroyCompactHeightfield(chf);
-
- BKE_report(reports, RPT_ERROR, "Failed to create compact height field");
- return false;
- }
-
- recast_destroyHeightfield(solid);
- solid = NULL;
-
- if (!recast_erodeWalkableArea(walkableRadius, chf)) {
- recast_destroyCompactHeightfield(chf);
-
- BKE_report(reports, RPT_ERROR, "Failed to erode walkable area");
- return false;
- }
-
- if (recastParams->partitioning == RC_PARTITION_WATERSHED) {
- /* Prepare for region partitioning, by calculating distance field along the walkable surface */
- if (!recast_buildDistanceField(chf)) {
- recast_destroyCompactHeightfield(chf);
-
- BKE_report(reports, RPT_ERROR, "Failed to build distance field");
- return false;
- }
-
- /* Partition the walkable surface into simple regions without holes */
- if (!recast_buildRegions(chf, 0, minRegionArea, mergeRegionArea)) {
- recast_destroyCompactHeightfield(chf);
-
- BKE_report(reports, RPT_ERROR, "Failed to build watershed regions");
- return false;
- }
- }
- else if (recastParams->partitioning == RC_PARTITION_MONOTONE) {
- /* Partition the walkable surface into simple regions without holes */
- /* Monotone partitioning does not need distancefield. */
- if (!recast_buildRegionsMonotone(chf, 0, minRegionArea, mergeRegionArea)) {
- recast_destroyCompactHeightfield(chf);
-
- BKE_report(reports, RPT_ERROR, "Failed to build monotone regions");
- return false;
- }
- }
- else { /* RC_PARTITION_LAYERS */
- /* Partition the walkable surface into simple regions without holes */
- if (!recast_buildLayerRegions(chf, 0, minRegionArea)) {
- recast_destroyCompactHeightfield(chf);
-
- BKE_report(reports, RPT_ERROR, "Failed to build layer regions");
- return false;
- }
- }
-
- /* ** Step 5: Trace and simplify region contours ** */
- /* Create contours */
- cset = recast_newContourSet();
-
- if (!recast_buildContours(chf, recastParams->edgemaxerror, maxEdgeLen, cset, RECAST_CONTOUR_TESS_WALL_EDGES)) {
- recast_destroyCompactHeightfield(chf);
- recast_destroyContourSet(cset);
-
- BKE_report(reports, RPT_ERROR, "Failed to build contours");
- return false;
- }
-
- /* ** Step 6: Build polygons mesh from contours ** */
- *pmesh = recast_newPolyMesh();
- if (!recast_buildPolyMesh(cset, recastParams->vertsperpoly, *pmesh)) {
- recast_destroyCompactHeightfield(chf);
- recast_destroyContourSet(cset);
- recast_destroyPolyMesh(*pmesh);
-
- BKE_report(reports, RPT_ERROR, "Failed to build poly mesh");
- return false;
- }
-
-
- /* ** Step 7: Create detail mesh which allows to access approximate height on each polygon ** */
-
- *dmesh = recast_newPolyMeshDetail();
- if (!recast_buildPolyMeshDetail(*pmesh, chf, detailSampleDist, detailSampleMaxError, *dmesh)) {
- recast_destroyCompactHeightfield(chf);
- recast_destroyContourSet(cset);
- recast_destroyPolyMesh(*pmesh);
- recast_destroyPolyMeshDetail(*dmesh);
-
- BKE_report(reports, RPT_ERROR, "Failed to build poly mesh detail");
- return false;
- }
-
- recast_destroyCompactHeightfield(chf);
- recast_destroyContourSet(cset);
-
- return true;
-}
-
-static Object *createRepresentation(bContext *C, struct recast_polyMesh *pmesh, struct recast_polyMeshDetail *dmesh,
- Base *base, unsigned int lay)
-{
- float co[3], rot[3];
- BMEditMesh *em;
- int i, j, k;
- unsigned short *v;
- int face[3];
- Scene *scene = CTX_data_scene(C);
- Object *obedit;
- int createob = base == NULL;
- int nverts, nmeshes, nvp;
- unsigned short *verts, *polys;
- unsigned int *meshes;
- float bmin[3], cs, ch, *dverts;
- unsigned char *tris;
-
- zero_v3(co);
- zero_v3(rot);
-
- if (createob) {
- /* create new object */
- obedit = ED_object_add_type(C, OB_MESH, "Navmesh", co, rot, false, lay);
- }
- else {
- obedit = base->object;
- BKE_scene_base_deselect_all(scene);
- BKE_scene_base_select(scene, base);
- copy_v3_v3(obedit->loc, co);
- copy_v3_v3(obedit->rot, rot);
- }
-
- ED_object_editmode_enter(C, EM_DO_UNDO | EM_IGNORE_LAYER);
- em = BKE_editmesh_from_object(obedit);
-
- if (!createob) {
- /* clear */
- EDBM_mesh_clear(em);
- }
-
- /* create verts for polygon mesh */
- verts = recast_polyMeshGetVerts(pmesh, &nverts);
- recast_polyMeshGetBoundbox(pmesh, bmin, NULL);
- recast_polyMeshGetCell(pmesh, &cs, &ch);
-
- for (i = 0; i < nverts; i++) {
- v = &verts[3 * i];
- co[0] = bmin[0] + v[0] * cs;
- co[1] = bmin[1] + v[1] * ch;
- co[2] = bmin[2] + v[2] * cs;
- SWAP(float, co[1], co[2]);
- BM_vert_create(em->bm, co, NULL, BM_CREATE_NOP);
- }
-
- /* create custom data layer to save polygon idx */
- CustomData_add_layer_named(&em->bm->pdata, CD_RECAST, CD_CALLOC, NULL, 0, "createRepresentation recastData");
- CustomData_bmesh_init_pool(&em->bm->pdata, 0, BM_FACE);
-
- /* create verts and faces for detailed mesh */
- meshes = recast_polyMeshDetailGetMeshes(dmesh, &nmeshes);
- polys = recast_polyMeshGetPolys(pmesh, NULL, &nvp);
- dverts = recast_polyMeshDetailGetVerts(dmesh, NULL);
- tris = recast_polyMeshDetailGetTris(dmesh, NULL);
-
- for (i = 0; i < nmeshes; i++) {
- int uniquevbase = em->bm->totvert;
- unsigned int vbase = meshes[4 * i + 0];
- unsigned short ndv = meshes[4 * i + 1];
- unsigned short tribase = meshes[4 * i + 2];
- unsigned short trinum = meshes[4 * i + 3];
- const unsigned short *p = &polys[i * nvp * 2];
- int nv = 0;
-
- for (j = 0; j < nvp; ++j) {
- if (p[j] == 0xffff) break;
- nv++;
- }
-
- /* create unique verts */
- for (j = nv; j < ndv; j++) {
- copy_v3_v3(co, &dverts[3 * (vbase + j)]);
- SWAP(float, co[1], co[2]);
- BM_vert_create(em->bm, co, NULL, BM_CREATE_NOP);
- }
-
- /* need to rebuild entirely because array size changes */
- BM_mesh_elem_table_init(em->bm, BM_VERT);
-
- /* create faces */
- for (j = 0; j < trinum; j++) {
- unsigned char *tri = &tris[4 * (tribase + j)];
- BMFace *newFace;
- int *polygonIdx;
-
- for (k = 0; k < 3; k++) {
- if (tri[k] < nv)
- face[k] = p[tri[k]]; /* shared vertex */
- else
- face[k] = uniquevbase + tri[k] - nv; /* unique vertex */
- }
- newFace = BM_face_create_quad_tri(em->bm,
- BM_vert_at_index(em->bm, face[0]),
- BM_vert_at_index(em->bm, face[2]),
- BM_vert_at_index(em->bm, face[1]), NULL,
- NULL, BM_CREATE_NOP);
-
- /* set navigation polygon idx to the custom layer */
- polygonIdx = (int *)CustomData_bmesh_get(&em->bm->pdata, newFace->head.data, CD_RECAST);
- *polygonIdx = i + 1; /* add 1 to avoid zero idx */
- }
- }
-
- recast_destroyPolyMesh(pmesh);
- recast_destroyPolyMeshDetail(dmesh);
-
- DAG_id_tag_update((ID *)obedit->data, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
-
-
- ED_object_editmode_exit(C, EM_FREEDATA);
- WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, obedit);
-
- if (createob) {
- obedit->gameflag &= ~OB_COLLISION;
- obedit->gameflag |= OB_NAVMESH;
- obedit->body_type = OB_BODY_TYPE_NAVMESH;
- }
-
- BKE_mesh_ensure_navmesh(obedit->data);
-
- return obedit;
-}
-
-static int navmesh_create_exec(bContext *C, wmOperator *op)
-{
- Scene *scene = CTX_data_scene(C);
- LinkNode *obs = NULL;
- Base *navmeshBase = NULL;
-
- CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
- {
- if (base->object->type == OB_MESH) {
- if (base->object->body_type == OB_BODY_TYPE_NAVMESH) {
- if (!navmeshBase || base == scene->basact) {
- navmeshBase = base;
- }
- }
- else {
- BLI_linklist_prepend(&obs, base->object);
- }
- }
- }
- CTX_DATA_END;
-
- if (obs) {
- struct recast_polyMesh *pmesh = NULL;
- struct recast_polyMeshDetail *dmesh = NULL;
- bool ok;
- unsigned int lay = 0;
-
- int nverts = 0, ntris = 0;
- int *tris = NULL;
- float *verts = NULL;
-
- createVertsTrisData(C, obs, &nverts, &verts, &ntris, &tris, &lay);
- BLI_linklist_free(obs, NULL);
- if ((ok = buildNavMesh(&scene->gm.recastData, nverts, verts, ntris, tris, &pmesh, &dmesh, op->reports))) {
- createRepresentation(C, pmesh, dmesh, navmeshBase, lay);
- }
-
- MEM_freeN(verts);
- MEM_freeN(tris);
-
- return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
- }
- else {
- BKE_report(op->reports, RPT_ERROR, "No mesh objects found");
-
- return OPERATOR_CANCELLED;
- }
-}
-
-void MESH_OT_navmesh_make(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Create Navigation Mesh";
- ot->description = "Create navigation mesh for selected objects";
- ot->idname = "MESH_OT_navmesh_make";
-
- /* api callbacks */
- ot->exec = navmesh_create_exec;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-static int navmesh_face_copy_exec(bContext *C, wmOperator *op)
-{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
-
- /* do work here */
- BMFace *efa_act = BM_mesh_active_face_get(em->bm, false, false);
-
- if (efa_act) {
- if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) {
- BMFace *efa;
- BMIter iter;
- int targetPolyIdx = *(int *)CustomData_bmesh_get(&em->bm->pdata, efa_act->head.data, CD_RECAST);
- targetPolyIdx = targetPolyIdx >= 0 ? targetPolyIdx : -targetPolyIdx;
-
- if (targetPolyIdx > 0) {
- /* set target poly idx to other selected faces */
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && efa != efa_act) {
- int *recastDataBlock = (int *)CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_RECAST);
- *recastDataBlock = targetPolyIdx;
- }
- }
- }
- else {
- BKE_report(op->reports, RPT_ERROR, "Active face has no index set");
- }
- }
- }
-
- DAG_id_tag_update((ID *)obedit->data, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
-
- return OPERATOR_FINISHED;
-}
-
-void MESH_OT_navmesh_face_copy(struct wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "NavMesh Copy Face Index";
- ot->description = "Copy the index from the active face";
- ot->idname = "MESH_OT_navmesh_face_copy";
-
- /* api callbacks */
- ot->poll = ED_operator_editmesh;
- ot->exec = navmesh_face_copy_exec;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-static int compare(const void *a, const void *b)
-{
- return (*(int *)a - *(int *)b);
-}
-
-static int findFreeNavPolyIndex(BMEditMesh *em)
-{
- /* construct vector of indices */
- int numfaces = em->bm->totface;
- int *indices = MEM_callocN(sizeof(int) * numfaces, "findFreeNavPolyIndex(indices)");
- BMFace *ef;
- BMIter iter;
- int i, idx = em->bm->totface - 1, freeIdx = 1;
-
- /*XXX this originally went last to first, but that isn't possible anymore*/
- BM_ITER_MESH (ef, &iter, em->bm, BM_FACES_OF_MESH) {
- int polyIdx = *(int *)CustomData_bmesh_get(&em->bm->pdata, ef->head.data, CD_RECAST);
- indices[idx] = polyIdx;
- idx--;
- }
-
- qsort(indices, numfaces, sizeof(int), compare);
-
- /* search first free index */
- freeIdx = 1;
- for (i = 0; i < numfaces; i++) {
- if (indices[i] == freeIdx)
- freeIdx++;
- else if (indices[i] > freeIdx)
- break;
- }
-
- MEM_freeN(indices);
-
- return freeIdx;
-}
-
-static int navmesh_face_add_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMFace *ef;
- BMIter iter;
-
- if (CustomData_has_layer(&em->bm->pdata, CD_RECAST)) {
- int targetPolyIdx = findFreeNavPolyIndex(em);
-
- if (targetPolyIdx > 0) {
- /* set target poly idx to selected faces */
- /*XXX this originally went last to first, but that isn't possible anymore*/
-
- BM_ITER_MESH (ef, &iter, em->bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(ef, BM_ELEM_SELECT)) {
- int *recastDataBlock = (int *)CustomData_bmesh_get(&em->bm->pdata, ef->head.data, CD_RECAST);
- *recastDataBlock = targetPolyIdx;
- }
- }
- }
- }
-
- DAG_id_tag_update((ID *)obedit->data, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
-
- return OPERATOR_FINISHED;
-}
-
-void MESH_OT_navmesh_face_add(struct wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "NavMesh New Face Index";
- ot->description = "Add a new index and assign it to selected faces";
- ot->idname = "MESH_OT_navmesh_face_add";
-
- /* api callbacks */
- ot->poll = ED_operator_editmesh;
- ot->exec = navmesh_face_add_exec;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-static int navmesh_obmode_data_poll(bContext *C)
-{
- Object *ob = ED_object_active_context(C);
- if (ob && (ob->mode == OB_MODE_OBJECT) && (ob->type == OB_MESH)) {
- Mesh *me = ob->data;
- return CustomData_has_layer(&me->pdata, CD_RECAST);
- }
- return false;
-}
-
-static int navmesh_obmode_poll(bContext *C)
-{
- Object *ob = ED_object_active_context(C);
- if (ob && (ob->mode == OB_MODE_OBJECT) && (ob->type == OB_MESH)) {
- return true;
- }
- return false;
-}
-
-static int navmesh_reset_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *ob = ED_object_active_context(C);
- Mesh *me = ob->data;
-
- CustomData_free_layers(&me->pdata, CD_RECAST, me->totpoly);
-
- BKE_mesh_ensure_navmesh(me);
-
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, &me->id);
-
- return OPERATOR_FINISHED;
-}
-
-void MESH_OT_navmesh_reset(struct wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "NavMesh Reset Index Values";
- ot->description = "Assign a new index to every face";
- ot->idname = "MESH_OT_navmesh_reset";
-
- /* api callbacks */
- ot->poll = navmesh_obmode_poll;
- ot->exec = navmesh_reset_exec;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-static int navmesh_clear_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *ob = ED_object_active_context(C);
- Mesh *me = ob->data;
-
- CustomData_free_layers(&me->pdata, CD_RECAST, me->totpoly);
-
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, &me->id);
-
- return OPERATOR_FINISHED;
-}
-
-void MESH_OT_navmesh_clear(struct wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "NavMesh Clear Data";
- ot->description = "Remove navmesh data from this mesh";
- ot->idname = "MESH_OT_navmesh_clear";
-
- /* api callbacks */
- ot->poll = navmesh_obmode_data_poll;
- ot->exec = navmesh_clear_exec;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
diff --git a/source/blender/editors/mesh/mesh_ops.c b/source/blender/editors/mesh/mesh_ops.c
index 697a92f36d1..6f663ddbf14 100644
--- a/source/blender/editors/mesh/mesh_ops.c
+++ b/source/blender/editors/mesh/mesh_ops.c
@@ -141,13 +141,18 @@ void ED_operatortypes_mesh(void)
#endif
WM_operatortype_append(MESH_OT_vertices_smooth);
WM_operatortype_append(MESH_OT_vertices_smooth_laplacian);
- WM_operatortype_append(MESH_OT_noise);
WM_operatortype_append(MESH_OT_flip_normals);
WM_operatortype_append(MESH_OT_rip);
WM_operatortype_append(MESH_OT_rip_edge);
WM_operatortype_append(MESH_OT_blend_from_shape);
WM_operatortype_append(MESH_OT_shape_propagate_to_all);
-
+
+ /* editmesh_polybuild */
+ WM_operatortype_append(MESH_OT_polybuild_face_at_cursor);
+ WM_operatortype_append(MESH_OT_polybuild_split_at_cursor);
+ WM_operatortype_append(MESH_OT_polybuild_dissolve_at_cursor);
+ WM_operatortype_append(MESH_OT_polybuild_hover);
+
WM_operatortype_append(MESH_OT_uv_texture_add);
WM_operatortype_append(MESH_OT_uv_texture_remove);
WM_operatortype_append(MESH_OT_vertex_color_add);
@@ -191,14 +196,6 @@ void ED_operatortypes_mesh(void)
WM_operatortype_append(MESH_OT_bisect);
WM_operatortype_append(MESH_OT_symmetrize);
WM_operatortype_append(MESH_OT_symmetry_snap);
-
-#ifdef WITH_GAMEENGINE
- WM_operatortype_append(MESH_OT_navmesh_make);
- WM_operatortype_append(MESH_OT_navmesh_face_copy);
- WM_operatortype_append(MESH_OT_navmesh_face_add);
- WM_operatortype_append(MESH_OT_navmesh_reset);
- WM_operatortype_append(MESH_OT_navmesh_clear);
-#endif
}
#if 0 /* UNUSED, remove? */
@@ -298,6 +295,23 @@ void ED_operatormacros_mesh(void)
otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
RNA_enum_set(otmacro->ptr, "proportional", 0);
RNA_boolean_set(otmacro->ptr, "mirror", false);
+
+
+ ot = WM_operatortype_append_macro(
+ "MESH_OT_polybuild_face_at_cursor_move", "Face At Cursor Move", "",
+ OPTYPE_UNDO | OPTYPE_REGISTER);
+ WM_operatortype_macro_define(ot, "MESH_OT_polybuild_face_at_cursor");
+ otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
+ RNA_enum_set(otmacro->ptr, "proportional", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", false);
+
+ ot = WM_operatortype_append_macro(
+ "MESH_OT_polybuild_split_at_cursor_move", "Split At Cursor Move", "",
+ OPTYPE_UNDO | OPTYPE_REGISTER);
+ WM_operatortype_macro_define(ot, "MESH_OT_polybuild_split_at_cursor");
+ otmacro = WM_operatortype_macro_define(ot, "TRANSFORM_OT_translate");
+ RNA_enum_set(otmacro->ptr, "proportional", 0);
+ RNA_boolean_set(otmacro->ptr, "mirror", false);
}
/* note mesh keymap also for other space? */
diff --git a/source/blender/editors/mesh/meshtools.c b/source/blender/editors/mesh/meshtools.c
index d3d29b61182..83458127820 100644
--- a/source/blender/editors/mesh/meshtools.c
+++ b/source/blender/editors/mesh/meshtools.c
@@ -42,12 +42,12 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_deform.h"
#include "BKE_DerivedMesh.h"
#include "BKE_key.h"
@@ -60,6 +60,10 @@
#include "BKE_report.h"
#include "BKE_editmesh.h"
#include "BKE_multires.h"
+#include "BKE_layer.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "ED_mesh.h"
#include "ED_object.h"
@@ -76,7 +80,7 @@
* return 0 if no join is made (error) and 1 if the join is done */
static void join_mesh_single(
- Main *bmain, Scene *scene,
+ Depsgraph *depsgraph, Main *bmain, Scene *scene,
Object *ob_dst, Object *ob_src, float imat[4][4],
MVert **mvert_pp, MEdge **medge_pp, MLoop **mloop_pp, MPoly **mpoly_pp,
CustomData *vdata, CustomData *edata, CustomData *ldata, CustomData *pdata,
@@ -204,7 +208,7 @@ static void join_mesh_single(
if (ob_src != ob_dst) {
MultiresModifierData *mmd;
- multiresModifier_prepare_join(scene, ob_src, ob_dst);
+ multiresModifier_prepare_join(depsgraph, scene, ob_src, ob_dst);
if ((mmd = get_multires_modifier(scene, ob_src, true))) {
ED_object_iter_other(bmain, ob_src, true,
@@ -278,7 +282,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
bDeformGroup *dg, *odg;
CustomData vdata, edata, fdata, ldata, pdata;
- if (scene->obedit) {
+ if (ob->mode & OB_MODE_EDIT) {
BKE_report(op->reports, RPT_WARNING, "Cannot join while in edit mode");
return OPERATOR_CANCELLED;
}
@@ -288,7 +292,9 @@ int join_mesh_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_WARNING, "Active object is not a mesh");
return OPERATOR_CANCELLED;
}
-
+
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
/* count & check */
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
@@ -483,7 +489,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
* active mesh will remain first ones in new result of the merge, in same order for CD layers, etc. See also T50084.
*/
join_mesh_single(
- bmain, scene,
+ depsgraph, bmain, scene,
ob, ob, imat,
&mvert, &medge, &mloop, &mpoly,
&vdata, &edata, &ldata, &pdata,
@@ -500,7 +506,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* only join if this is a mesh */
if (base->object->type == OB_MESH) {
join_mesh_single(
- bmain, scene,
+ depsgraph, bmain, scene,
ob, base->object, imat,
&mvert, &medge, &mloop, &mpoly,
&vdata, &edata, &ldata, &pdata,
@@ -511,7 +517,7 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* free base, now that data is merged */
if (base->object != ob) {
- ED_base_object_free_and_unlink(bmain, scene, base);
+ ED_object_base_free_and_unlink(bmain, scene, base->object);
}
}
}
@@ -582,9 +588,9 @@ int join_mesh_exec(bContext *C, wmOperator *op)
/* Due to dependnecy cycle some other object might access old derived data. */
BKE_object_free_derived_caches(ob);
- DAG_relations_tag_update(bmain); /* removed objects, need to rebuild dag */
+ DEG_relations_tag_update(bmain); /* removed objects, need to rebuild dag */
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
@@ -600,6 +606,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Mesh *me = (Mesh *)ob->data;
Mesh *selme = NULL;
DerivedMesh *dm = NULL;
@@ -648,7 +655,7 @@ int join_mesh_shapes_exec(bContext *C, wmOperator *op)
selme = (Mesh *)base->object->data;
if (selme->totvert == me->totvert) {
- dm = mesh_get_derived_deform(scene, base->object, CD_MASK_BAREMESH);
+ dm = mesh_get_derived_deform(depsgraph, scene, base->object, CD_MASK_BAREMESH);
if (!dm) continue;
@@ -679,15 +686,16 @@ static MirrTopoStore_t mesh_topo_store = {NULL, -1. - 1, -1};
/* mode is 's' start, or 'e' end, or 'u' use */
/* if end, ob can be NULL */
/* note, is supposed return -1 on error, which callers are currently checking for, but is not used so far */
-int ED_mesh_mirror_topo_table(Object *ob, DerivedMesh *dm, char mode)
+int ED_mesh_mirror_topo_table(
+ Object *ob, DerivedMesh *dm, char mode)
{
if (mode == 'u') { /* use table */
- if (ED_mesh_mirrtopo_recalc_check(ob->data, dm, ob->mode, &mesh_topo_store)) {
+ if (ED_mesh_mirrtopo_recalc_check(ob->data, dm, &mesh_topo_store)) {
ED_mesh_mirror_topo_table(ob, dm, 's');
}
}
else if (mode == 's') { /* start table */
- ED_mesh_mirrtopo_init(ob->data, dm, ob->mode, &mesh_topo_store, false);
+ ED_mesh_mirrtopo_init(ob->data, dm, &mesh_topo_store, false);
}
else if (mode == 'e') { /* end table */
ED_mesh_mirrtopo_free(&mesh_topo_store);
@@ -1056,6 +1064,7 @@ static void ed_mesh_pick_face_vert__mpoly_find(
*/
bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned int *index, int size)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
unsigned int poly_index;
Mesh *me = ob->data;
@@ -1066,7 +1075,7 @@ bool ED_mesh_pick_face_vert(bContext *C, Object *ob, const int mval[2], unsigned
struct ARegion *ar = CTX_wm_region(C);
/* derived mesh to find deformed locations */
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
+ DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
int v_idx_best = ORIGINDEX_NONE;
@@ -1193,7 +1202,7 @@ bool ED_mesh_pick_vert(bContext *C, Object *ob, const int mval[2], unsigned int
}
else {
/* derived mesh to find deformed locations */
- DerivedMesh *dm = mesh_get_derived_final(vc.scene, ob, CD_MASK_BAREMESH);
+ DerivedMesh *dm = mesh_get_derived_final(vc.depsgraph, vc.scene, ob, CD_MASK_BAREMESH);
ARegion *ar = vc.ar;
RegionView3D *rv3d = ar->regiondata;
@@ -1279,3 +1288,47 @@ MDeformVert *ED_mesh_active_dvert_get_only(Object *ob)
return NULL;
}
}
+
+void EDBM_mesh_stats_multi(
+ struct Object **objects, const uint objects_len,
+ int totelem[3], int totelem_sel[3])
+{
+ if (totelem) {
+ totelem[0] = 0;
+ totelem[1] = 0;
+ totelem[2] = 0;
+ }
+ if (totelem_sel) {
+ totelem_sel[0] = 0;
+ totelem_sel[1] = 0;
+ totelem_sel[2] = 0;
+ }
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ if (totelem) {
+ totelem[0] += bm->totvert;
+ totelem[1] += bm->totedge;
+ totelem[2] += bm->totface;
+ }
+ if (totelem_sel) {
+ totelem_sel[0] += bm->totvertsel;
+ totelem_sel[1] += bm->totedgesel;
+ totelem_sel[2] += bm->totfacesel;
+ }
+ }
+}
+
+
+void EDBM_mesh_elem_index_ensure_multi(Object **objects, const uint objects_len, const char htype)
+{
+ int elem_offset[4] = {0, 0, 0, 0};
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+ BM_mesh_elem_index_ensure_ex(bm, htype, elem_offset);
+ }
+}
diff --git a/source/blender/editors/metaball/CMakeLists.txt b/source/blender/editors/metaball/CMakeLists.txt
index 7815240b7a4..b0ae3122727 100644
--- a/source/blender/editors/metaball/CMakeLists.txt
+++ b/source/blender/editors/metaball/CMakeLists.txt
@@ -22,10 +22,12 @@ set(INC
../include
../../blenkernel
../../blenlib
+ ../../depsgraph
../../makesdna
../../makesrna
../../render/extern/include
../../windowmanager
+ ../../../../intern/clog
../../../../intern/guardedalloc
)
diff --git a/source/blender/editors/metaball/editmball_undo.c b/source/blender/editors/metaball/editmball_undo.c
index dc64f61a916..7045025e227 100644
--- a/source/blender/editors/metaball/editmball_undo.c
+++ b/source/blender/editors/metaball/editmball_undo.c
@@ -27,6 +27,8 @@
#include "MEM_guardedalloc.h"
+#include "CLG_log.h"
+
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
#include "BLI_array_utils.h"
@@ -36,16 +38,22 @@
#include "DNA_object_types.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_object.h"
#include "ED_mball.h"
+#include "ED_undo.h"
#include "ED_util.h"
#include "WM_types.h"
#include "WM_api.h"
+/** We only need this locally. */
+static CLG_LogRef LOG = {"ed.undo.mball"};
+
/* -------------------------------------------------------------------- */
/** \name Undo Conversion
* \{ */
@@ -129,13 +137,19 @@ static Object *editmball_object_from_context(bContext *C)
/* -------------------------------------------------------------------- */
/** \name Implements ED Undo System
+ *
+ * \note This is similar for all edit-mode types.
* \{ */
-typedef struct MBallUndoStep {
- UndoStep step;
- /* note: will split out into list for multi-object-editmode. */
+typedef struct MBallUndoStep_Elem {
UndoRefID_Object obedit_ref;
UndoMBall data;
+} MBallUndoStep_Elem;
+
+typedef struct MBallUndoStep {
+ UndoStep step;
+ MBallUndoStep_Elem *elems;
+ uint elems_len;
} MBallUndoStep;
static bool mball_undosys_poll(bContext *C)
@@ -146,36 +160,74 @@ static bool mball_undosys_poll(bContext *C)
static bool mball_undosys_step_encode(struct bContext *C, UndoStep *us_p)
{
MBallUndoStep *us = (MBallUndoStep *)us_p;
- us->obedit_ref.ptr = editmball_object_from_context(C);
- MetaBall *mb = us->obedit_ref.ptr->data;
- editmball_from_undomball(&us->data, mb);
- us->step.data_size = us->data.undo_size;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ us->elems = MEM_callocN(sizeof(*us->elems) * objects_len, __func__);
+ us->elems_len = objects_len;
+
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ MBallUndoStep_Elem *elem = &us->elems[i];
+
+ elem->obedit_ref.ptr = ob;
+ MetaBall *mb = ob->data;
+ editmball_from_undomball(&elem->data, mb);
+ us->step.data_size += elem->data.undo_size;
+ }
+ MEM_freeN(objects);
return true;
}
static void mball_undosys_step_decode(struct bContext *C, UndoStep *us_p, int UNUSED(dir))
{
+ /* TODO(campbell): undo_system: use low-level API to set mode. */
ED_object_mode_set(C, OB_MODE_EDIT);
+ BLI_assert(mball_undosys_poll(C));
MBallUndoStep *us = (MBallUndoStep *)us_p;
- Object *obedit = us->obedit_ref.ptr;
- MetaBall *mb = obedit->data;
- undomball_to_editmball(&us->data, mb);
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ MBallUndoStep_Elem *elem = &us->elems[i];
+ Object *obedit = elem->obedit_ref.ptr;
+ MetaBall *mb = obedit->data;
+ if (mb->editelems == NULL) {
+ /* Should never fail, may not crash but can give odd behavior. */
+ CLOG_ERROR(&LOG, "name='%s', failed to enter edit-mode for object '%s', undo state invalid", us_p->name, obedit->id.name);
+ continue;
+ }
+ undomball_to_editmball(&elem->data, mb);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ }
+
+ /* The first element is always active */
+ ED_undo_object_set_active_or_warn(CTX_data_view_layer(C), us->elems[0].obedit_ref.ptr, us_p->name, &LOG);
+
WM_event_add_notifier(C, NC_GEOM | ND_DATA, NULL);
}
static void mball_undosys_step_free(UndoStep *us_p)
{
MBallUndoStep *us = (MBallUndoStep *)us_p;
- undomball_free_data(&us->data);
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ MBallUndoStep_Elem *elem = &us->elems[i];
+ undomball_free_data(&elem->data);
+ }
+ MEM_freeN(us->elems);
}
static void mball_undosys_foreach_ID_ref(
UndoStep *us_p, UndoTypeForEachIDRefFn foreach_ID_ref_fn, void *user_data)
{
MBallUndoStep *us = (MBallUndoStep *)us_p;
- foreach_ID_ref_fn(user_data, ((UndoRefID *)&us->obedit_ref));
+
+ for (uint i = 0; i < us->elems_len; i++) {
+ MBallUndoStep_Elem *elem = &us->elems[i];
+ foreach_ID_ref_fn(user_data, ((UndoRefID *)&elem->obedit_ref));
+ }
}
/* Export for ED_undo_sys. */
diff --git a/source/blender/editors/metaball/mball_edit.c b/source/blender/editors/metaball/mball_edit.c
index 27140bcdf3b..0aea5cb5480 100644
--- a/source/blender/editors/metaball/mball_edit.c
+++ b/source/blender/editors/metaball/mball_edit.c
@@ -47,10 +47,11 @@
#include "RNA_define.h"
#include "RNA_access.h"
-#include "BKE_depsgraph.h"
#include "BKE_context.h"
#include "BKE_mball.h"
+#include "DEG_depsgraph.h"
+
#include "ED_mball.h"
#include "ED_screen.h"
#include "ED_view3d.h"
@@ -431,7 +432,7 @@ static int duplicate_metaelems_exec(bContext *C, wmOperator *UNUSED(op))
ml = ml->prev;
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mb);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
return OPERATOR_FINISHED;
@@ -473,7 +474,7 @@ static int delete_metaelems_exec(bContext *C, wmOperator *UNUSED(op))
ml = next;
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mb);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
return OPERATOR_FINISHED;
@@ -513,7 +514,7 @@ static int hide_metaelems_exec(bContext *C, wmOperator *op)
ml = ml->next;
}
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mb);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
return OPERATOR_FINISHED;
@@ -556,7 +557,7 @@ static int reveal_metaelems_exec(bContext *C, wmOperator *op)
}
if (changed) {
WM_event_add_notifier(C, NC_GEOM | ND_DATA, mb);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
}
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/object/CMakeLists.txt b/source/blender/editors/object/CMakeLists.txt
index 24740a3372b..e25b04668bc 100644
--- a/source/blender/editors/object/CMakeLists.txt
+++ b/source/blender/editors/object/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../blenlib
../../blentranslation
../../bmesh
+ ../../depsgraph
../../gpu
../../ikplugin
../../imbuf
@@ -46,9 +47,9 @@ set(SRC
object_bake_api.c
object_constraint.c
object_edit.c
+ object_facemap_ops.c
object_group.c
object_hook.c
- object_lod.c
object_modes.c
object_modifier.c
object_ops.c
@@ -70,10 +71,6 @@ if(WITH_PYTHON)
add_definitions(-DWITH_PYTHON)
endif()
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
if(WITH_INTERNATIONAL)
add_definitions(-DWITH_INTERNATIONAL)
endif()
diff --git a/source/blender/editors/object/object_add.c b/source/blender/editors/object/object_add.c
index eeeb3c058d0..c2934b916d0 100644
--- a/source/blender/editors/object/object_add.c
+++ b/source/blender/editors/object/object_add.c
@@ -45,9 +45,9 @@
#include "DNA_object_fluidsim_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_scene_types.h"
#include "DNA_vfont_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_gpencil_types.h"
#include "BLI_utildefines.h"
@@ -63,10 +63,10 @@
#include "BKE_animsys.h"
#include "BKE_armature.h"
#include "BKE_camera.h"
+#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_displist.h"
#include "BKE_effect.h"
@@ -74,6 +74,7 @@
#include "BKE_group.h"
#include "BKE_lamp.h"
#include "BKE_lattice.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
@@ -86,11 +87,13 @@
#include "BKE_object.h"
#include "BKE_particle.h"
#include "BKE_report.h"
-#include "BKE_sca.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_speaker.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -112,8 +115,6 @@
#include "UI_resources.h"
-#include "GPU_material.h"
-
#include "object_intern.h"
/* this is an exact copy of the define in rna_lamp.c
@@ -146,6 +147,16 @@ static const EnumPropertyItem field_type_items[] = {
{0, NULL, 0, NULL, NULL}
};
+static EnumPropertyItem lightprobe_type_items[] = {
+ {LIGHTPROBE_TYPE_CUBE, "SPHERE", ICON_MESH_UVSPHERE, "Reflection Cubemap",
+ "Reflection probe with spherical or cubic attenuation"},
+ {LIGHTPROBE_TYPE_PLANAR, "PLANAR", ICON_MESH_PLANE, "Reflection Plane",
+ "Planar reflection probe"},
+ {LIGHTPROBE_TYPE_GRID, "GRID", ICON_MESH_GRID, "Irradiance Volume",
+ "Irradiance probe to capture diffuse indirect lighting"},
+ {0, NULL, 0, NULL, NULL}
+};
+
/************************** Exported *****************************/
void ED_object_location_from_view(bContext *C, float loc[3])
@@ -207,6 +218,7 @@ void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3],
{
Object *ob = base->object;
Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
if (!scene) return;
@@ -216,7 +228,7 @@ void ED_object_base_init_transform(bContext *C, Base *base, const float loc[3],
if (rot)
copy_v3_v3(ob->rot, rot);
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(depsgraph, scene, ob);
}
/* Uses context to figure out transform for primitive.
@@ -404,10 +416,11 @@ Object *ED_object_add_type(
bContext *C,
int type, const char *name,
const float loc[3], const float rot[3],
- bool enter_editmode, unsigned int layer)
+ bool enter_editmode, unsigned int UNUSED(layer))
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob;
/* for as long scene has editmode... */
@@ -415,24 +428,20 @@ Object *ED_object_add_type(
ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO); /* freedata, and undo */
/* deselects all, sets scene->basact */
- ob = BKE_object_add(bmain, scene, type, name);
- BASACT->lay = ob->lay = layer;
+ ob = BKE_object_add(bmain, scene, view_layer, type, name);
/* editor level activate, notifiers */
- ED_base_object_activate(C, BASACT);
+ ED_object_base_activate(C, view_layer->basact);
/* more editor stuff */
- ED_object_base_init_transform(C, BASACT, loc, rot);
-
- /* Ignore collisions by default for non-mesh objects */
- if (type != OB_MESH) {
- ob->body_type = OB_BODY_TYPE_NO_COLLISION;
- ob->gameflag &= ~(OB_SENSOR | OB_RIGID_BODY | OB_SOFT_BODY | OB_COLLISION | OB_CHARACTER | OB_OCCLUDER | OB_DYNAMIC | OB_NAVMESH); /* copied from rna_object.c */
- }
+ ED_object_base_init_transform(C, view_layer->basact, loc, rot);
- DAG_id_type_tag(bmain, ID_OB);
- DAG_relations_tag_update(bmain);
- if (ob->data) {
- ED_render_id_flush_update(bmain, ob->data);
+ /* TODO(sergey): This is weird to manually tag objects for update, better to
+ * use DEG_id_tag_update here perhaps.
+ */
+ DEG_id_type_tag(bmain, ID_OB);
+ DEG_relations_tag_update(bmain);
+ if (ob->data != NULL) {
+ DEG_id_tag_update_ex(bmain, (ID *)ob->data, DEG_TAG_EDITORS_UPDATE);
}
if (enter_editmode)
@@ -440,6 +449,9 @@ Object *ED_object_add_type(
WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+
return ob;
}
@@ -491,6 +503,79 @@ void OBJECT_OT_add(wmOperatorType *ot)
ED_object_add_generic_props(ot, true);
}
+/********************** Add Probe Operator **********************/
+
+/* for object add operator */
+static int lightprobe_add_exec(bContext *C, wmOperator *op)
+{
+ Object *ob;
+ LightProbe *probe;
+ int type;
+ bool enter_editmode;
+ unsigned int layer;
+ float loc[3], rot[3];
+ float radius;
+
+ WM_operator_view3d_unit_defaults(C, op);
+ if (!ED_object_add_generic_get_opts(C, op, 'Z', loc, rot, &enter_editmode, &layer, NULL))
+ return OPERATOR_CANCELLED;
+
+ type = RNA_enum_get(op->ptr, "type");
+ radius = RNA_float_get(op->ptr, "radius");
+
+ const char *name = CTX_DATA_(BLT_I18NCONTEXT_ID_OBJECT, "Light Probe");
+ ob = ED_object_add_type(C, OB_LIGHTPROBE, name, loc, rot, false, layer);
+ BKE_object_obdata_size_init(ob, radius);
+
+ probe = (LightProbe *)ob->data;
+ probe->type = type;
+
+ switch (type) {
+ case LIGHTPROBE_TYPE_GRID:
+ probe->distinf = 0.3f;
+ probe->falloff = 1.0f;
+ probe->clipsta = 0.01f;
+ break;
+ case LIGHTPROBE_TYPE_PLANAR:
+ probe->distinf = 0.1f;
+ probe->falloff = 0.5f;
+ probe->clipsta = 0.001f;
+ ob->empty_drawsize = 0.5f;
+ break;
+ case LIGHTPROBE_TYPE_CUBE:
+ probe->attenuation_type = LIGHTPROBE_SHAPE_ELIPSOID;
+ break;
+ default:
+ BLI_assert(!"Lightprobe type not configured.");
+ break;
+ }
+
+ DEG_relations_tag_update(CTX_data_main(C));
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_lightprobe_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add Light Probe";
+ ot->description = "Add a light probe object";
+ ot->idname = "OBJECT_OT_lightprobe_add";
+
+ /* api callbacks */
+ ot->exec = lightprobe_add_exec;
+ ot->poll = ED_operator_objectmode;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna, "type", lightprobe_type_items, 0, "Type", "");
+
+ ED_object_add_unit_props(ot);
+ ED_object_add_generic_props(ot, true);
+}
+
/********************* Add Effector Operator ********************/
/* for object add operator */
@@ -534,7 +619,7 @@ static int effector_add_exec(bContext *C, wmOperator *op)
ob->pd = object_add_collision_fields(type);
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
return OPERATOR_FINISHED;
}
@@ -639,7 +724,7 @@ static int object_metaball_add_exec(bContext *C, wmOperator *op)
newob = true;
}
else {
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
}
ED_object_new_primitive_matrix(C, obedit, loc, rot, mat);
@@ -743,7 +828,7 @@ static int object_armature_add_exec(bContext *C, wmOperator *op)
newob = true;
}
else {
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
}
if (obedit == NULL) {
@@ -931,7 +1016,7 @@ static int object_lamp_add_exec(bContext *C, wmOperator *op)
la = (Lamp *)ob->data;
la->type = type;
- if (BKE_scene_use_new_shading_nodes(scene)) {
+ if (BKE_scene_uses_cycles(scene)) {
ED_node_shader_default(C, &la->id);
la->use_nodes = true;
}
@@ -1001,7 +1086,8 @@ static int group_instance_add_exec(bContext *C, wmOperator *op)
id_us_plus(&group->id);
/* works without this except if you try render right after, see: 22027 */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&group->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
@@ -1095,35 +1181,22 @@ void OBJECT_OT_speaker_add(wmOperatorType *ot)
/**************************** Delete Object *************************/
-static void object_delete_check_glsl_update(Object *ob)
-{
- /* some objects could affect on GLSL shading, make sure GLSL settings
- * are being tagged to be updated when object is removing from scene
- */
- if (ob->type == OB_LAMP) {
- if (ob->gpulamp.first)
- GPU_lamp_free(ob);
- }
-}
-
/* remove base from a specific scene */
/* note: now unlinks constraints as well */
-void ED_base_object_free_and_unlink(Main *bmain, Scene *scene, Base *base)
+void ED_object_base_free_and_unlink(Main *bmain, Scene *scene, Object *ob)
{
- if (BKE_library_ID_is_indirectly_used(bmain, base->object) &&
- ID_REAL_USERS(base->object) <= 1 && ID_EXTRA_USERS(base->object) == 0)
+ if (BKE_library_ID_is_indirectly_used(bmain, ob) &&
+ ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0)
{
/* We cannot delete indirectly used object... */
printf("WARNING, undeletable object '%s', should have been catched before reaching this function!",
- base->object->id.name + 2);
+ ob->id.name + 2);
return;
}
- BKE_scene_base_unlink(scene, base);
- object_delete_check_glsl_update(base->object);
- BKE_libblock_free_us(bmain, base->object);
- MEM_freeN(base);
- DAG_id_type_tag(bmain, ID_OB);
+ DEG_id_tag_update_ex(bmain, &ob->id, DEG_TAG_BASE_FLAGS_UPDATE);
+
+ BKE_collections_object_remove(bmain, &scene->id, ob, true);
}
static int object_delete_exec(bContext *C, wmOperator *op)
@@ -1138,18 +1211,18 @@ static int object_delete_exec(bContext *C, wmOperator *op)
if (CTX_data_edit_object(C))
return OPERATOR_CANCELLED;
- CTX_DATA_BEGIN (C, Base *, base, selected_bases)
+ CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
{
- const bool is_indirectly_used = BKE_library_ID_is_indirectly_used(bmain, base->object);
- if (base->object->id.tag & LIB_TAG_INDIRECT) {
+ const bool is_indirectly_used = BKE_library_ID_is_indirectly_used(bmain, ob);
+ if (ob->id.tag & LIB_TAG_INDIRECT) {
/* Can this case ever happen? */
- BKE_reportf(op->reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", base->object->id.name + 2);
+ BKE_reportf(op->reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", ob->id.name + 2);
continue;
}
- else if (is_indirectly_used && ID_REAL_USERS(base->object) <= 1 && ID_EXTRA_USERS(base->object) == 0) {
+ else if (is_indirectly_used && ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0) {
BKE_reportf(op->reports, RPT_WARNING,
"Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user",
- base->object->id.name + 2, scene->id.name + 2);
+ ob->id.name + 2, scene->id.name + 2);
continue;
}
@@ -1157,9 +1230,9 @@ static int object_delete_exec(bContext *C, wmOperator *op)
* custom scene/object/base handling, and use generic lib remap/query for that.
* But this is for later (aka 2.8, once layers & co are settled and working).
*/
- if (use_global && base->object->id.lib == NULL) {
+ if (use_global && ob->id.lib == NULL) {
/* We want to nuke the object, let's nuke it the easy way (not for linked data though)... */
- BKE_libblock_delete(bmain, &base->object->id);
+ BKE_libblock_delete(bmain, &ob->id);
changed = true;
continue;
}
@@ -1170,38 +1243,28 @@ static int object_delete_exec(bContext *C, wmOperator *op)
for (bGPdata *gpd = bmain->gpencil.first; gpd; gpd = gpd->id.next) {
for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
if (gpl->parent != NULL) {
- Object *ob = gpl->parent;
- Object *curob = base->object;
- if (ob == curob) {
+ if (gpl->parent == ob) {
gpl->parent = NULL;
}
}
}
}
- /* deselect object -- it could be used in other scenes */
- base->object->flag &= ~SELECT;
-
/* remove from current scene only */
- ED_base_object_free_and_unlink(bmain, scene, base);
+ ED_object_base_free_and_unlink(bmain, scene, ob);
changed = true;
if (use_global) {
Scene *scene_iter;
- Base *base_other;
-
for (scene_iter = bmain->scene.first; scene_iter; scene_iter = scene_iter->id.next) {
if (scene_iter != scene && !ID_IS_LINKED(scene_iter)) {
- base_other = BKE_scene_base_find(scene_iter, base->object);
- if (base_other) {
- if (is_indirectly_used && ID_REAL_USERS(base->object) <= 1 && ID_EXTRA_USERS(base->object) == 0) {
- BKE_reportf(op->reports, RPT_WARNING,
- "Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user",
- base->object->id.name + 2, scene_iter->id.name + 2);
- break;
- }
- ED_base_object_free_and_unlink(bmain, scene_iter, base_other);
+ if (is_indirectly_used && ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0) {
+ BKE_reportf(op->reports, RPT_WARNING,
+ "Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user",
+ ob->id.name + 2, scene_iter->id.name + 2);
+ break;
}
+ ED_object_base_free_and_unlink(bmain, scene_iter, ob);
}
}
}
@@ -1215,12 +1278,12 @@ static int object_delete_exec(bContext *C, wmOperator *op)
/* delete has to handle all open scenes */
BKE_main_id_tag_listbase(&bmain->scene, LIB_TAG_DOIT, true);
for (win = wm->windows.first; win; win = win->next) {
- scene = win->screen->scene;
-
+ scene = WM_window_get_active_scene(win);
+
if (scene->id.tag & LIB_TAG_DOIT) {
scene->id.tag &= ~LIB_TAG_DOIT;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
@@ -1261,8 +1324,6 @@ static void copy_object_set_idnew(bContext *C)
}
CTX_DATA_END;
- set_sca_new_poins();
-
BKE_main_id_clear_newpoins(bmain);
}
@@ -1342,6 +1403,8 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
const bool use_hierarchy)
{
Main *bmain = CTX_data_main(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
ListBase *lb_duplis;
DupliObject *dob;
GHash *dupli_gh, *parent_gh = NULL;
@@ -1350,7 +1413,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
return;
}
- lb_duplis = object_duplilist(bmain->eval_ctx, scene, base->object);
+ lb_duplis = object_duplilist(depsgraph, scene, base->object);
dupli_gh = BLI_ghash_ptr_new(__func__);
if (use_hierarchy) {
@@ -1374,12 +1437,11 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
ob_dst->totcol = 0;
}
- base_dst = MEM_dupallocN(base);
- base_dst->flag &= ~(OB_FROMDUPLI | OB_FROMGROUP);
- ob_dst->flag = base_dst->flag;
- base_dst->lay = base->lay;
- BLI_addhead(&scene->base, base_dst); /* addhead: othwise eternal loop */
- base_dst->object = ob_dst;
+ BKE_collection_object_add_from(scene, base->object, ob_dst);
+ base_dst = BKE_view_layer_base_find(view_layer, ob_dst);
+ BLI_assert(base_dst != NULL);
+
+ BKE_scene_object_base_flag_sync_from_base(base_dst);
/* make sure apply works */
BKE_animdata_free(&ob_dst->id, true);
@@ -1394,7 +1456,6 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
BKE_constraints_free(&ob_dst->constraints);
ob_dst->curve_cache = NULL;
ob_dst->transflag &= ~OB_DUPLI;
- ob_dst->lay = base->lay;
copy_m4_m4(ob_dst->obmat, dob->mat);
BKE_object_apply_mat4(ob_dst, ob_dst->obmat, false, false);
@@ -1416,9 +1477,8 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
/* Remap new object to itself, and clear again newid pointer of orig object. */
BKE_libblock_relink_to_newid(&ob_dst->id);
- set_sca_new_poins_ob(ob_dst);
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
if (use_hierarchy) {
/* original parents */
@@ -1472,7 +1532,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
BKE_object_apply_mat4(ob_dst, dob->mat, false, true);
/* to set ob_dst->orig and in case theres any other discrepicies */
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_OB);
}
}
@@ -1481,7 +1541,7 @@ static void make_object_duplilist_real(bContext *C, Scene *scene, Base *base,
if (ob->proxy_group == base->object) {
ob->proxy = NULL;
ob->proxy_from = NULL;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
}
}
@@ -1517,7 +1577,7 @@ static int object_duplicates_make_real_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_SCENE, scene);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
@@ -1551,46 +1611,43 @@ static const EnumPropertyItem convert_target_items[] = {
{0, NULL, 0, NULL, NULL}
};
-static void convert_ensure_curve_cache(Main *bmain, Scene *scene, Object *ob)
+static void convert_ensure_curve_cache(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
if (ob->curve_cache == NULL) {
/* Force creation. This is normally not needed but on operator
* redo we might end up with an object which isn't evaluated yet.
*/
if (ELEM(ob->type, OB_SURF, OB_CURVE, OB_FONT)) {
- BKE_displist_make_curveTypes(scene, ob, false);
+ BKE_displist_make_curveTypes(depsgraph, scene, ob, false);
}
else if (ob->type == OB_MBALL) {
- BKE_displist_make_mball(bmain->eval_ctx, scene, ob);
+ BKE_displist_make_mball(depsgraph, scene, ob);
}
}
}
-static void curvetomesh(Main *bmain, Scene *scene, Object *ob)
+static void curvetomesh(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
- convert_ensure_curve_cache(bmain, scene, ob);
+ convert_ensure_curve_cache(depsgraph, scene, ob);
BKE_mesh_from_nurbs(ob); /* also does users */
if (ob->type == OB_MESH) {
BKE_object_free_modifiers(ob, 0);
-
- /* Game engine defaults for mesh objects */
- ob->body_type = OB_BODY_TYPE_STATIC;
- ob->gameflag = OB_PROP | OB_COLLISION;
}
}
static int convert_poll(bContext *C)
{
- Object *obact = CTX_data_active_object(C);
Scene *scene = CTX_data_scene(C);
+ Base *base_act = CTX_data_active_base(C);
+ Object *obact = base_act ? base_act->object : NULL;
- return (!ID_IS_LINKED(scene) && obact && scene->obedit != obact &&
- (obact->flag & SELECT) && !ID_IS_LINKED(obact));
+ return (!ID_IS_LINKED(scene) && obact && (BKE_object_is_in_editmode(obact) == false) &&
+ (base_act->flag & BASE_SELECTED) && !ID_IS_LINKED(obact));
}
/* Helper for convert_exec */
-static Base *duplibase_for_convert(Main *bmain, Scene *scene, Base *base, Object *ob)
+static Base *duplibase_for_convert(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, Object *ob)
{
Object *obn;
Base *basen;
@@ -1600,26 +1657,23 @@ static Base *duplibase_for_convert(Main *bmain, Scene *scene, Base *base, Object
}
obn = BKE_object_copy(bmain, ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
-
- basen = MEM_mallocN(sizeof(Base), "duplibase");
- *basen = *base;
- BLI_addhead(&scene->base, basen); /* addhead: otherwise eternal loop */
- basen->object = obn;
- basen->flag |= SELECT;
- obn->flag |= SELECT;
- base->flag &= ~SELECT;
- ob->flag &= ~SELECT;
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ BKE_collection_object_add_from(scene, ob, obn);
+ basen = BKE_view_layer_base_find(view_layer, obn);
+ ED_object_base_select(basen, BA_SELECT);
+ ED_object_base_select(basen, BA_DESELECT);
return basen;
}
static int convert_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Base *basen = NULL, *basact = NULL;
- Object *ob, *ob1, *newob, *obact = CTX_data_active_object(C);
+ Object *ob1, *newob, *obact = CTX_data_active_object(C);
DerivedMesh *dm;
Curve *cu;
Nurb *nu;
@@ -1632,10 +1686,8 @@ static int convert_exec(bContext *C, wmOperator *op)
/* don't forget multiple users! */
{
- Base *base;
-
- for (base = scene->base.first; base; base = base->next) {
- ob = base->object;
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
+ {
ob->flag &= ~OB_DONE;
/* flag data thats not been edited (only needed for !keep_original) */
@@ -1654,6 +1706,7 @@ static int convert_exec(bContext *C, wmOperator *op)
}
}
}
+ FOREACH_SCENE_OBJECT_END;
}
ListBase selected_editable_bases = CTX_data_collection_get(C, "selected_editable_bases");
@@ -1664,7 +1717,7 @@ static int convert_exec(bContext *C, wmOperator *op)
{
for (CollectionPointerLink *link = selected_editable_bases.first; link; link = link->next) {
Base *base = link->ptr.data;
- ob = base->object;
+ Object *ob = base->object;
/* The way object type conversion works currently (enforcing conversion of *all* objetcs using converted
* obdata, even some un-selected/hidden/inother scene ones, sounds totally bad to me.
@@ -1677,18 +1730,18 @@ static int convert_exec(bContext *C, wmOperator *op)
"Converting some linked object/object data, enforcing 'Keep Original' option to True");
}
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
}
uint64_t customdata_mask_prev = scene->customdata_mask;
scene->customdata_mask |= CD_MASK_MESH;
- BKE_scene_update_tagged(bmain->eval_ctx, bmain, scene);
+ BKE_scene_graph_update_tagged(depsgraph, bmain);
scene->customdata_mask = customdata_mask_prev;
}
for (CollectionPointerLink *link = selected_editable_bases.first; link; link = link->next) {
Base *base = link->ptr.data;
- ob = base->object;
+ Object *ob = base->object;
if (ob->flag & OB_DONE || !IS_TAGGED(ob->data)) {
if (ob->type != target) {
@@ -1709,7 +1762,7 @@ static int convert_exec(bContext *C, wmOperator *op)
ob->flag |= OB_DONE;
if (keep_original) {
- basen = duplibase_for_convert(bmain, scene, base, NULL);
+ basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
newob = basen->object;
/* decrement original mesh's usage count */
@@ -1723,7 +1776,7 @@ static int convert_exec(bContext *C, wmOperator *op)
newob = ob;
}
- BKE_mesh_to_curve(scene, newob);
+ BKE_mesh_to_curve(depsgraph, scene, newob);
if (newob->type == OB_CURVE) {
BKE_object_free_modifiers(newob, 0); /* after derivedmesh calls! */
@@ -1734,7 +1787,7 @@ static int convert_exec(bContext *C, wmOperator *op)
ob->flag |= OB_DONE;
if (keep_original) {
- basen = duplibase_for_convert(bmain, scene, base, NULL);
+ basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
newob = basen->object;
/* decrement original mesh's usage count */
@@ -1746,14 +1799,14 @@ static int convert_exec(bContext *C, wmOperator *op)
}
else {
newob = ob;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
}
/* make new mesh data from the original copy */
/* note: get the mesh from the original, not from the copy in some
* cases this doesnt give correct results (when MDEF is used for eg)
*/
- dm = mesh_get_derived_final(scene, newob, CD_MASK_MESH);
+ dm = mesh_get_derived_final(depsgraph, scene, newob, CD_MASK_MESH);
DM_to_mesh(dm, newob->data, newob, CD_MASK_MESH, true);
@@ -1765,7 +1818,7 @@ static int convert_exec(bContext *C, wmOperator *op)
ob->flag |= OB_DONE;
if (keep_original) {
- basen = duplibase_for_convert(bmain, scene, base, NULL);
+ basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
newob = basen->object;
/* decrement original curve's usage count */
@@ -1812,7 +1865,7 @@ static int convert_exec(bContext *C, wmOperator *op)
for (ob1 = bmain->object.first; ob1; ob1 = ob1->id.next) {
if (ob1->data == ob->data) {
ob1->type = OB_CURVE;
- DAG_id_tag_update(&ob1->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob1->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
}
}
}
@@ -1825,7 +1878,7 @@ static int convert_exec(bContext *C, wmOperator *op)
BKE_curve_curve_dimension_update(cu);
if (target == OB_MESH) {
- curvetomesh(bmain, scene, newob);
+ curvetomesh(depsgraph, scene, newob);
/* meshes doesn't use displist */
BKE_object_free_curve_cache(newob);
@@ -1836,7 +1889,7 @@ static int convert_exec(bContext *C, wmOperator *op)
if (target == OB_MESH) {
if (keep_original) {
- basen = duplibase_for_convert(bmain, scene, base, NULL);
+ basen = duplibase_for_convert(bmain, scene, view_layer, base, NULL);
newob = basen->object;
/* decrement original curve's usage count */
@@ -1849,7 +1902,7 @@ static int convert_exec(bContext *C, wmOperator *op)
newob = ob;
}
- curvetomesh(bmain, scene, newob);
+ curvetomesh(depsgraph, scene, newob);
/* meshes doesn't use displist */
BKE_object_free_curve_cache(newob);
@@ -1858,8 +1911,8 @@ static int convert_exec(bContext *C, wmOperator *op)
else if (ob->type == OB_MBALL && target == OB_MESH) {
Object *baseob;
- base->flag &= ~SELECT;
- ob->flag &= ~SELECT;
+ base->flag &= ~BASE_SELECTED;
+ ob->base_flag &= ~BASE_SELECTED;
baseob = BKE_mball_basis_find(scene, ob);
@@ -1871,7 +1924,7 @@ static int convert_exec(bContext *C, wmOperator *op)
if (!(baseob->flag & OB_DONE)) {
baseob->flag |= OB_DONE;
- basen = duplibase_for_convert(bmain, scene, base, baseob);
+ basen = duplibase_for_convert(bmain, scene, view_layer, base, baseob);
newob = basen->object;
mb = newob->data;
@@ -1887,7 +1940,7 @@ static int convert_exec(bContext *C, wmOperator *op)
for (a = 0; a < newob->totcol; a++) id_us_plus((ID *)me->mat[a]);
}
- convert_ensure_curve_cache(bmain, scene, baseob);
+ convert_ensure_curve_cache(depsgraph, scene, baseob);
BKE_mesh_from_metaball(&baseob->curve_cache->disp, newob->data);
if (obact->type == OB_MBALL) {
@@ -1914,7 +1967,7 @@ static int convert_exec(bContext *C, wmOperator *op)
}
if (!keep_original && (ob->flag & OB_DONE)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
((ID *)ob->data)->tag &= ~LIB_TAG_DOIT; /* flag not to convert this datablock again */
}
}
@@ -1922,27 +1975,24 @@ static int convert_exec(bContext *C, wmOperator *op)
if (!keep_original) {
if (mballConverted) {
- Base *base, *base_next;
-
- for (base = scene->base.first; base; base = base_next) {
- base_next = base->next;
-
- ob = base->object;
- if (ob->type == OB_MBALL) {
- if (ob->flag & OB_DONE) {
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob_mball)
+ {
+ if (ob_mball->type == OB_MBALL) {
+ if (ob_mball->flag & OB_DONE) {
Object *ob_basis = NULL;
- if (BKE_mball_is_basis(ob) ||
- ((ob_basis = BKE_mball_basis_find(scene, ob)) && (ob_basis->flag & OB_DONE)))
+ if (BKE_mball_is_basis(ob_mball) ||
+ ((ob_basis = BKE_mball_basis_find(scene, ob_mball)) && (ob_basis->flag & OB_DONE)))
{
- ED_base_object_free_and_unlink(bmain, scene, base);
+ ED_object_base_free_and_unlink(bmain, scene, ob_mball);
}
}
}
}
+ FOREACH_SCENE_OBJECT_END;
}
/* delete object should renew depsgraph */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
// XXX ED_object_editmode_enter(C, 0);
@@ -1950,15 +2000,15 @@ static int convert_exec(bContext *C, wmOperator *op)
if (basact) {
/* active base was changed */
- ED_base_object_activate(C, basact);
- BASACT = basact;
+ ED_object_base_activate(C, basact);
+ BASACT(view_layer) = basact;
}
- else if (BASACT->object->flag & OB_DONE) {
- WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, BASACT->object);
- WM_event_add_notifier(C, NC_OBJECT | ND_DATA, BASACT->object);
+ else if (BASACT(view_layer)->object->flag & OB_DONE) {
+ WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, BASACT(view_layer)->object);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DATA, BASACT(view_layer)->object);
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, scene);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
@@ -1997,39 +2047,43 @@ void OBJECT_OT_convert(wmOperatorType *ot)
/* used below, assumes id.new is correct */
/* leaves selection of base/object unaltered */
/* Does set ID->newid pointers. */
-static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base, int dupflag)
+static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, ViewLayer *view_layer, Object *ob, int dupflag)
{
#define ID_NEW_REMAP_US(a) if ( (a)->id.newid) { (a) = (void *)(a)->id.newid; (a)->id.us++; }
#define ID_NEW_REMAP_US2(a) if (((ID *)a)->newid) { (a) = ((ID *)a)->newid; ((ID *)a)->us++; }
- Base *basen = NULL;
+ Base *base, *basen = NULL;
Material ***matarar;
- Object *ob, *obn;
+ Object *obn;
ID *id;
int a, didit;
- ob = base->object;
if (ob->mode & OB_MODE_POSE) {
; /* nothing? */
}
else {
obn = ID_NEW_SET(ob, BKE_object_copy(bmain, ob));
- DAG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&obn->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
- basen = MEM_mallocN(sizeof(Base), "duplibase");
- *basen = *base;
- BLI_addhead(&scene->base, basen); /* addhead: prevent eternal loop */
- basen->object = obn;
+ base = BKE_view_layer_base_find(view_layer, ob);
+ if ((base != NULL) && (base->flag & BASE_VISIBLED)) {
+ BKE_collection_object_add_from(scene, ob, obn);
+ }
+ else {
+ LayerCollection *layer_collection = BKE_layer_collection_get_active_ensure(scene, view_layer);
+ BKE_collection_object_add(&scene->id, layer_collection->scene_collection, obn);
+ }
+ basen = BKE_view_layer_base_find(view_layer, obn);
/* 1) duplis should end up in same group as the original
* 2) Rigid Body sim participants MUST always be part of a group...
*/
// XXX: is 2) really a good measure here?
- if ((basen->flag & OB_FROMGROUP) || ob->rigidbody_object || ob->rigidbody_constraint) {
+ if ((ob->flag & OB_FROMGROUP) != 0 || ob->rigidbody_object || ob->rigidbody_constraint) {
Group *group;
for (group = bmain->group.first; group; group = group->id.next) {
if (BKE_group_object_exists(group, ob))
- BKE_group_object_add(group, obn, scene, basen);
+ BKE_group_object_add(group, obn);
}
}
@@ -2138,7 +2192,7 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
}
break;
case OB_ARMATURE:
- DAG_id_tag_update(&obn->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obn->id, OB_RECALC_DATA);
if (obn->pose)
BKE_pose_tag_recalc(bmain, obn->pose);
if (dupflag & USER_DUP_ARM) {
@@ -2193,25 +2247,10 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
}
if (dupflag & USER_DUP_ACT) {
- bActuator *act;
-
BKE_animdata_copy_id_action((ID *)obn->data, true);
if (key) {
BKE_animdata_copy_id_action((ID *)key, true);
}
-
- /* Update the duplicated action in the action actuators */
- /* XXX TODO this code is all wrong! actact->act is user-refcounted (see readfile.c),
- * and what about other ID pointers of other BGE logic bricks,
- * and since this is object-level, why is it only ran if obdata was duplicated??? -mont29 */
- for (act = obn->actuators.first; act; act = act->next) {
- if (act->type == ACT_ACTION) {
- bActionActuator *actact = (bActionActuator *) act->data;
- if (ob->adt && actact->act == ob->adt->action) {
- actact->act = obn->adt->action;
- }
- }
- }
}
if (dupflag & USER_DUP_MAT) {
@@ -2242,14 +2281,12 @@ static Base *object_add_duplicate_internal(Main *bmain, Scene *scene, Base *base
* note: don't call this within a loop since clear_* funcs loop over the entire database.
* note: caller must do DAG_relations_tag_update(bmain);
* this is not done automatic since we may duplicate many objects in a batch */
-Base *ED_object_add_duplicate(Main *bmain, Scene *scene, Base *base, int dupflag)
+Base *ED_object_add_duplicate(Main *bmain, Scene *scene, ViewLayer *view_layer, Base *base, int dupflag)
{
Base *basen;
Object *ob;
- clear_sca_new_poins(); /* BGE logic */
-
- basen = object_add_duplicate_internal(bmain, scene, base, dupflag);
+ basen = object_add_duplicate_internal(bmain, scene, view_layer, base->object, dupflag);
if (basen == NULL) {
return NULL;
}
@@ -2258,12 +2295,11 @@ Base *ED_object_add_duplicate(Main *bmain, Scene *scene, Base *base, int dupflag
/* link own references to the newly duplicated data [#26816] */
BKE_libblock_relink_to_newid(&ob->id);
- set_sca_new_poins_ob(ob);
/* DAG_relations_tag_update(bmain); */ /* caller must do */
- if (ob->data) {
- ED_render_id_flush_update(bmain, ob->data);
+ if (ob->data != NULL) {
+ DEG_id_tag_update_ex(bmain, (ID *)ob->data, DEG_TAG_EDITORS_UPDATE);
}
BKE_main_id_clear_newpoins(bmain);
@@ -2276,29 +2312,29 @@ static int duplicate_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
const bool linked = RNA_boolean_get(op->ptr, "linked");
int dupflag = (linked) ? 0 : U.dupflag;
- clear_sca_new_poins(); /* BGE logic */
-
CTX_DATA_BEGIN (C, Base *, base, selected_bases)
{
- Base *basen = object_add_duplicate_internal(bmain, scene, base, dupflag);
+ Base *basen = object_add_duplicate_internal(bmain, scene, view_layer, base->object, dupflag);
/* note that this is safe to do with this context iterator,
* the list is made in advance */
- ED_base_object_select(base, BA_DESELECT);
+ ED_object_base_select(base, BA_DESELECT);
+ ED_object_base_select(basen, BA_SELECT);
if (basen == NULL) {
continue;
}
/* new object becomes active */
- if (BASACT == base)
- ED_base_object_activate(C, basen);
+ if (BASACT(view_layer) == base)
+ ED_object_base_activate(C, basen);
if (basen->object->data) {
- DAG_id_tag_update(basen->object->data, 0);
+ DEG_id_tag_update(basen->object->data, 0);
}
}
CTX_DATA_END;
@@ -2307,7 +2343,9 @@ static int duplicate_exec(bContext *C, wmOperator *op)
BKE_main_id_clear_newpoins(bmain);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&CTX_data_scene(C)->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
@@ -2343,9 +2381,9 @@ static int add_named_exec(bContext *C, wmOperator *op)
wmWindow *win = CTX_wm_window(C);
const wmEvent *event = win ? win->eventstate : NULL;
Main *bmain = CTX_data_main(C);
- View3D *v3d = CTX_wm_view3d(C); /* may be NULL */
Scene *scene = CTX_data_scene(C);
- Base *basen, *base;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Base *basen;
Object *ob;
const bool linked = RNA_boolean_get(op->ptr, "linked");
int dupflag = (linked) ? 0 : U.dupflag;
@@ -2360,22 +2398,15 @@ static int add_named_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- base = MEM_callocN(sizeof(Base), "duplibase");
- base->object = ob;
- base->flag = ob->flag;
-
/* prepare dupli */
- clear_sca_new_poins(); /* BGE logic */
-
- basen = object_add_duplicate_internal(bmain, scene, base, dupflag);
+ basen = object_add_duplicate_internal(bmain, scene, view_layer, ob, dupflag);
if (basen == NULL) {
- MEM_freeN(base);
BKE_report(op->reports, RPT_ERROR, "Object could not be duplicated");
return OPERATOR_CANCELLED;
}
- basen->lay = basen->object->lay = BKE_screen_view3d_layer_active(v3d, scene);
+ BKE_scene_object_base_flag_sync_from_object(basen);
basen->object->restrictflag &= ~OB_RESTRICT_VIEW;
if (event) {
@@ -2386,16 +2417,15 @@ static int add_named_exec(bContext *C, wmOperator *op)
ED_view3d_cursor3d_position(C, basen->object->loc, mval);
}
- ED_base_object_select(basen, BA_SELECT);
- ED_base_object_activate(C, basen);
+ ED_object_base_select(basen, BA_SELECT);
+ ED_object_base_activate(C, basen);
copy_object_set_idnew(C);
BKE_main_id_clear_newpoins(bmain);
- DAG_relations_tag_update(bmain);
-
- MEM_freeN(base);
+ /* TODO(sergey): Only update relations for the current scene. */
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
@@ -2437,10 +2467,9 @@ static int join_poll(bContext *C)
static int join_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- if (scene->obedit) {
+ if (ob->mode & OB_MODE_EDIT) {
BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
return OPERATOR_CANCELLED;
}
@@ -2491,10 +2520,9 @@ static int join_shapes_poll(bContext *C)
static int join_shapes_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- if (scene->obedit) {
+ if (ob->mode & OB_MODE_EDIT) {
BKE_report(op->reports, RPT_ERROR, "This data does not support joining in edit mode");
return OPERATOR_CANCELLED;
}
diff --git a/source/blender/editors/object/object_bake.c b/source/blender/editors/object/object_bake.c
index 9837fec2b1e..a8da5c038b4 100644
--- a/source/blender/editors/object/object_bake.c
+++ b/source/blender/editors/object/object_bake.c
@@ -52,15 +52,17 @@
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_main.h"
+#include "BKE_material.h"
#include "BKE_multires.h"
#include "BKE_report.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_modifier.h"
#include "BKE_DerivedMesh.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+
#include "RE_pipeline.h"
#include "RE_shader_ext.h"
#include "RE_multires_bake.h"
@@ -77,15 +79,37 @@
#include "ED_object.h"
#include "ED_screen.h"
+#include "ED_uvedit.h"
#include "object_intern.h"
+static Image *bake_object_image_get(Object *ob, int mat_nr)
+{
+ Image *image = NULL;
+ ED_object_get_active_image(ob, mat_nr + 1, &image, NULL, NULL, NULL);
+ return image;
+}
+
+static Image **bake_object_image_get_array(Object *ob)
+{
+ Image **image_array = MEM_mallocN(sizeof(Material *) * ob->totcol, __func__);
+ for (int i = 0; i < ob->totcol; i++) {
+ image_array[i] = bake_object_image_get(ob, i);
+ }
+ return image_array;
+}
+
/* ****************** multires BAKING ********************** */
/* holder of per-object data needed for bake job
* needed to make job totally thread-safe */
typedef struct MultiresBakerJobData {
struct MultiresBakerJobData *next, *prev;
+ /* material aligned image array (for per-face bake image) */
+ struct {
+ Image **array;
+ int len;
+ } ob_image;
DerivedMesh *lores_dm, *hires_dm;
bool simple;
int lvl, tot_lvl;
@@ -101,8 +125,6 @@ typedef struct {
bool use_lores_mesh; /* Use low-resolution mesh when baking displacement maps */
int number_of_rays; /* Number of rays to be cast when doing AO baking */
float bias; /* Bias between object and start ray point when doing AO baking */
- int raytrace_structure; /* Optimization structure to be used for AO baking */
- int octree_resolution; /* Reslution of octotree when using octotree optimization structure */
int threads; /* Number of threads to be used for baking */
float user_scale; /* User scale used to scale displacement when baking derivative map. */
} MultiresBakeJob;
@@ -152,7 +174,7 @@ static bool multiresbake_check(bContext *C, wmOperator *op)
break;
}
- if (!me->mtpoly) {
+ if (!me->mloopuv) {
BKE_report(op->reports, RPT_ERROR, "Mesh should be unwrapped before multires data baking");
ok = false;
@@ -160,7 +182,7 @@ static bool multiresbake_check(bContext *C, wmOperator *op)
else {
a = me->totpoly;
while (ok && a--) {
- Image *ima = me->mtpoly[a].tpage;
+ Image *ima = bake_object_image_get(ob, me->mpoly[a].mat_nr);
if (!ima) {
BKE_report(op->reports, RPT_ERROR, "You should have active texture to use multires baker");
@@ -283,20 +305,27 @@ static void clear_single_image(Image *image, ClearFlag flag)
}
}
-static void clear_images_poly(MTexPoly *mtpoly, int totpoly, ClearFlag flag)
+static void clear_images_poly(Image **ob_image_array, int ob_image_array_len, ClearFlag flag)
{
- int a;
-
- for (a = 0; a < totpoly; a++) {
- mtpoly[a].tpage->id.tag &= ~LIB_TAG_DOIT;
+ for (int i = 0; i < ob_image_array_len; i++) {
+ Image *image = ob_image_array[i];
+ if (image) {
+ image->id.tag &= ~LIB_TAG_DOIT;
+ }
}
- for (a = 0; a < totpoly; a++) {
- clear_single_image(mtpoly[a].tpage, flag);
+ for (int i = 0; i < ob_image_array_len; i++) {
+ Image *image = ob_image_array[i];
+ if (image) {
+ clear_single_image(image, flag);
+ }
}
- for (a = 0; a < totpoly; a++) {
- mtpoly[a].tpage->id.tag &= ~LIB_TAG_DOIT;
+ for (int i = 0; i < ob_image_array_len; i++) {
+ Image *image = ob_image_array[i];
+ if (image) {
+ image->id.tag &= ~LIB_TAG_DOIT;
+ }
}
}
@@ -312,20 +341,23 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
if (scene->r.bake_flag & R_BAKE_CLEAR) { /* clear images */
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
- Mesh *me;
ClearFlag clear_flag = 0;
ob = base->object;
- me = (Mesh *)ob->data;
+ // me = (Mesh *)ob->data;
if (scene->r.bake_mode == RE_BAKE_NORMALS) {
clear_flag = CLEAR_TANGENT_NORMAL;
}
- else if (ELEM(scene->r.bake_mode, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) {
+ else if (scene->r.bake_mode == RE_BAKE_DISPLACEMENT) {
clear_flag = CLEAR_DISPLACEMENT;
}
- clear_images_poly(me->mtpoly, me->totpoly, clear_flag);
+ {
+ Image **ob_image_array = bake_object_image_get_array(ob);
+ clear_images_poly(ob_image_array, ob->totcol, clear_flag);
+ MEM_freeN(ob_image_array);
+ }
}
CTX_DATA_END;
}
@@ -344,18 +376,21 @@ static int multiresbake_image_exec_locked(bContext *C, wmOperator *op)
bkr.use_lores_mesh = scene->r.bake_flag & R_BAKE_LORES_MESH;
bkr.bias = scene->r.bake_biasdist;
bkr.number_of_rays = scene->r.bake_samples;
- bkr.raytrace_structure = scene->r.raytrace_structure;
- bkr.octree_resolution = scene->r.ocres;
bkr.threads = BKE_scene_num_threads(scene);
bkr.user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f;
//bkr.reports= op->reports;
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
+ bkr.ob_image.array = bake_object_image_get_array(ob);
+ bkr.ob_image.len = ob->totcol;
+
bkr.hires_dm = multiresbake_create_hiresdm(scene, ob, &bkr.tot_lvl, &bkr.simple);
bkr.lores_dm = multiresbake_create_loresdm(scene, ob, &bkr.lvl);
RE_multires_bake_images(&bkr);
+ MEM_freeN(bkr.ob_image.array);
+
BLI_freelistN(&bkr.image);
bkr.lores_dm->release(bkr.lores_dm);
@@ -384,8 +419,6 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
bkj->bake_clear = scene->r.bake_flag & R_BAKE_CLEAR;
bkj->bias = scene->r.bake_biasdist;
bkj->number_of_rays = scene->r.bake_samples;
- bkj->raytrace_structure = scene->r.raytrace_structure;
- bkj->octree_resolution = scene->r.ocres;
bkj->threads = BKE_scene_num_threads(scene);
bkj->user_scale = (scene->r.bake_flag & R_BAKE_USERSCALE) ? scene->r.bake_user_scale : -1.0f;
//bkj->reports = op->reports;
@@ -401,6 +434,9 @@ static void init_multiresbake_job(bContext *C, MultiresBakeJob *bkj)
data = MEM_callocN(sizeof(MultiresBakerJobData), "multiresBaker derivedMesh_data");
+ data->ob_image.array = bake_object_image_get_array(ob);
+ data->ob_image.len = ob->totcol;
+
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
data->hires_dm = multiresbake_create_hiresdm(scene, ob, &data->tot_lvl, &data->simple);
data->lores_dm = multiresbake_create_loresdm(scene, ob, &lvl);
@@ -421,18 +457,16 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa
if (bkj->bake_clear) { /* clear images */
for (data = bkj->data.first; data; data = data->next) {
- DerivedMesh *dm = data->lores_dm;
- MTexPoly *mtexpoly = CustomData_get_layer(&dm->polyData, CD_MTEXPOLY);
ClearFlag clear_flag = 0;
if (bkj->mode == RE_BAKE_NORMALS) {
clear_flag = CLEAR_TANGENT_NORMAL;
}
- else if (ELEM(bkj->mode, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) {
+ else if (bkj->mode == RE_BAKE_DISPLACEMENT) {
clear_flag = CLEAR_DISPLACEMENT;
}
- clear_images_poly(mtexpoly, dm->getNumPolys(dm), clear_flag);
+ clear_images_poly(data->ob_image.array, data->ob_image.len, clear_flag);
}
}
@@ -445,6 +479,8 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa
bkr.use_lores_mesh = bkj->use_lores_mesh;
bkr.user_scale = bkj->user_scale;
//bkr.reports = bkj->reports;
+ bkr.ob_image.array = data->ob_image.array;
+ bkr.ob_image.len = data->ob_image.len;
/* create low-resolution DM (to bake to) and hi-resolution DM (to bake from) */
bkr.lores_dm = data->lores_dm;
@@ -463,8 +499,6 @@ static void multiresbake_startjob(void *bkv, short *stop, short *do_update, floa
bkr.bias = bkj->bias;
bkr.number_of_rays = bkj->number_of_rays;
- bkr.raytrace_structure = bkj->raytrace_structure;
- bkr.octree_resolution = bkj->octree_resolution;
bkr.threads = bkj->threads;
RE_multires_bake_images(&bkr);
@@ -493,6 +527,8 @@ static void multiresbake_freejob(void *bkv)
GPU_free_image(ima);
}
+ MEM_freeN(data->ob_image.array);
+
BLI_freelistN(&data->images);
MEM_freeN(data);
@@ -539,200 +575,6 @@ static int multiresbake_image_exec(bContext *C, wmOperator *op)
/* ****************** render BAKING ********************** */
-/* threaded break test */
-static int thread_break(void *UNUSED(arg))
-{
- return G.is_break;
-}
-
-typedef struct BakeRender {
- Render *re;
- Main *main;
- Scene *scene;
- struct Object *actob;
- int result, ready;
-
- ReportList *reports;
-
- short *stop;
- short *do_update;
- float *progress;
-
- ListBase threads;
-
- /* backup */
- short prev_wo_amb_occ;
- short prev_r_raytrace;
-
- /* for redrawing */
- ScrArea *sa;
-} BakeRender;
-
-/* use by exec and invoke */
-static int test_bake_internal(bContext *C, ReportList *reports)
-{
- Scene *scene = CTX_data_scene(C);
-
- if ((scene->r.bake_flag & R_BAKE_TO_ACTIVE) && CTX_data_active_object(C) == NULL) {
- BKE_report(reports, RPT_ERROR, "No active object");
- }
- else if (scene->r.bake_mode == RE_BAKE_AO && scene->world == NULL) {
- BKE_report(reports, RPT_ERROR, "No world set up");
- }
- else {
- return 1;
- }
-
- return 0;
-}
-
-static void init_bake_internal(BakeRender *bkr, bContext *C)
-{
- Scene *scene = CTX_data_scene(C);
- bScreen *sc = CTX_wm_screen(C);
-
- /* get editmode results */
- ED_object_editmode_load(CTX_data_edit_object(C));
-
- bkr->sa = sc ? BKE_screen_find_big_area(sc, SPACE_IMAGE, 10) : NULL; /* can be NULL */
- bkr->main = CTX_data_main(C);
- bkr->scene = scene;
- bkr->actob = (scene->r.bake_flag & R_BAKE_TO_ACTIVE) ? OBACT : NULL;
- bkr->re = RE_NewRender("_Bake View_");
-
- if (scene->r.bake_mode == RE_BAKE_AO) {
- /* If raytracing or AO is disabled, switch it on temporarily for baking. */
- bkr->prev_wo_amb_occ = (scene->world->mode & WO_AMB_OCC) != 0;
- scene->world->mode |= WO_AMB_OCC;
- }
- if (scene->r.bake_mode == RE_BAKE_AO || bkr->actob) {
- bkr->prev_r_raytrace = (scene->r.mode & R_RAYTRACE) != 0;
- scene->r.mode |= R_RAYTRACE;
- }
-}
-
-static void finish_bake_internal(BakeRender *bkr)
-{
- Image *ima;
-
- RE_Database_Free(bkr->re);
-
- /* restore raytrace and AO */
- if (bkr->scene->r.bake_mode == RE_BAKE_AO)
- if (bkr->prev_wo_amb_occ == 0)
- bkr->scene->world->mode &= ~WO_AMB_OCC;
-
- if (bkr->scene->r.bake_mode == RE_BAKE_AO || bkr->actob)
- if (bkr->prev_r_raytrace == 0)
- bkr->scene->r.mode &= ~R_RAYTRACE;
-
- /* force OpenGL reload and mipmap recalc */
- if ((bkr->scene->r.bake_flag & R_BAKE_VCOL) == 0) {
- for (ima = G.main->image.first; ima; ima = ima->id.next) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
-
- /* some of the images could have been changed during bake,
- * so recreate mipmaps regardless bake result status
- */
- if (ima->ok == IMA_OK_LOADED) {
- if (ibuf) {
- if (ibuf->userflags & IB_BITMAPDIRTY) {
- GPU_free_image(ima);
- imb_freemipmapImBuf(ibuf);
- }
-
- /* invalidate display buffers for changed images */
- if (ibuf->userflags & IB_BITMAPDIRTY)
- ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
- }
- }
-
- /* freed when baking is done, but if its canceled we need to free here */
- if (ibuf) {
- if (ibuf->userdata) {
- BakeImBufuserData *userdata = (BakeImBufuserData *) ibuf->userdata;
- if (userdata->mask_buffer)
- MEM_freeN(userdata->mask_buffer);
- if (userdata->displacement_buffer)
- MEM_freeN(userdata->displacement_buffer);
- MEM_freeN(userdata);
- ibuf->userdata = NULL;
- }
- }
-
- BKE_image_release_ibuf(ima, ibuf, NULL);
- DAG_id_tag_update(&ima->id, 0);
- }
- }
-
- if (bkr->scene->r.bake_flag & R_BAKE_VCOL) {
- /* update all tagged meshes */
- Mesh *me;
- BLI_assert(BLI_thread_is_main());
- for (me = G.main->mesh.first; me; me = me->id.next) {
- if (me->id.tag & LIB_TAG_DOIT) {
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
- BKE_mesh_tessface_clear(me);
- }
- }
- }
-
-}
-
-static void *do_bake_render(void *bake_v)
-{
- BakeRender *bkr = bake_v;
-
- bkr->result = RE_bake_shade_all_selected(bkr->re, bkr->scene->r.bake_mode, bkr->actob, NULL, bkr->progress);
- bkr->ready = 1;
-
- return NULL;
-}
-
-static void bake_startjob(void *bkv, short *stop, short *do_update, float *progress)
-{
- BakeRender *bkr = bkv;
- Scene *scene = bkr->scene;
- Main *bmain = bkr->main;
-
- bkr->stop = stop;
- bkr->do_update = do_update;
- bkr->progress = progress;
-
- RE_test_break_cb(bkr->re, NULL, thread_break);
- G.is_break = false; /* BKE_blender_test_break uses this global */
-
- RE_Database_Baking(bkr->re, bmain, scene, scene->lay, scene->r.bake_mode, bkr->actob);
-
- /* baking itself is threaded, cannot use test_break in threads. we also update optional imagewindow */
- bkr->result = RE_bake_shade_all_selected(bkr->re, scene->r.bake_mode, bkr->actob, bkr->do_update, bkr->progress);
-}
-
-static void bake_update(void *bkv)
-{
- BakeRender *bkr = bkv;
-
- if (bkr->sa && bkr->sa->spacetype == SPACE_IMAGE) { /* in case the user changed while baking */
- SpaceImage *sima = bkr->sa->spacedata.first;
- if (sima)
- sima->image = RE_bake_shade_get_image();
- }
-}
-
-static void bake_freejob(void *bkv)
-{
- BakeRender *bkr = bkv;
- finish_bake_internal(bkr);
-
- if (bkr->result == BAKE_RESULT_NO_OBJECTS)
- BKE_report(bkr->reports, RPT_ERROR, "No objects or images found to bake to");
- else if (bkr->result == BAKE_RESULT_FEEDBACK_LOOP)
- BKE_report(bkr->reports, RPT_WARNING, "Circular reference in texture stack");
-
- MEM_freeN(bkr);
- G.is_rendering = false;
-}
-
/* catch esc */
static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
{
@@ -750,7 +592,7 @@ static int objects_bake_render_modal(bContext *C, wmOperator *UNUSED(op), const
static bool is_multires_bake(Scene *scene)
{
- if (ELEM(scene->r.bake_mode, RE_BAKE_NORMALS, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_AO))
+ if (ELEM(scene->r.bake_mode, RE_BAKE_NORMALS, RE_BAKE_DISPLACEMENT, RE_BAKE_AO))
return scene->r.bake_flag & R_BAKE_MULTIRES;
return 0;
@@ -761,44 +603,7 @@ static int objects_bake_render_invoke(bContext *C, wmOperator *op, const wmEvent
Scene *scene = CTX_data_scene(C);
int result = OPERATOR_CANCELLED;
- if (is_multires_bake(scene)) {
- result = multiresbake_image_exec(C, op);
- }
- else {
- /* only one render job at a time */
- if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_OBJECT_BAKE_TEXTURE))
- return OPERATOR_CANCELLED;
-
- if (test_bake_internal(C, op->reports) == 0) {
- return OPERATOR_CANCELLED;
- }
- else {
- BakeRender *bkr = MEM_callocN(sizeof(BakeRender), "render bake");
- wmJob *wm_job;
-
- init_bake_internal(bkr, C);
- bkr->reports = op->reports;
-
- /* setup job */
- wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), scene, "Texture Bake",
- WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS, WM_JOB_TYPE_OBJECT_BAKE_TEXTURE);
- WM_jobs_customdata_set(wm_job, bkr, bake_freejob);
- WM_jobs_timer(wm_job, 0.5, NC_IMAGE, 0); /* TODO - only draw bake image, can we enforce this */
- WM_jobs_callbacks(wm_job, bake_startjob, NULL, bake_update, NULL);
-
- G.is_break = false;
- G.is_rendering = true;
-
- WM_jobs_start(CTX_wm_manager(C), wm_job);
-
- WM_cursor_wait(0);
-
- /* add modal handler for ESC */
- WM_event_add_modal_handler(C, op);
- }
-
- result = OPERATOR_RUNNING_MODAL;
- }
+ result = multiresbake_image_exec(C, op);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
@@ -808,55 +613,15 @@ static int objects_bake_render_invoke(bContext *C, wmOperator *op, const wmEvent
static int bake_image_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
int result = OPERATOR_CANCELLED;
- if (is_multires_bake(scene)) {
- result = multiresbake_image_exec_locked(C, op);
+ if (!is_multires_bake(scene)) {
+ BLI_assert(0);
+ return result;
}
- else {
- if (test_bake_internal(C, op->reports) == 0) {
- return OPERATOR_CANCELLED;
- }
- else {
- ListBase threads;
- BakeRender bkr = {NULL};
-
- init_bake_internal(&bkr, C);
- bkr.reports = op->reports;
-
- RE_test_break_cb(bkr.re, NULL, thread_break);
- G.is_break = false; /* BKE_blender_test_break uses this global */
-
- RE_Database_Baking(bkr.re, bmain, scene, scene->lay, scene->r.bake_mode, (scene->r.bake_flag & R_BAKE_TO_ACTIVE) ? OBACT : NULL);
-
- /* baking itself is threaded, cannot use test_break in threads */
- BLI_threadpool_init(&threads, do_bake_render, 1);
- bkr.ready = 0;
- BLI_threadpool_insert(&threads, &bkr);
- while (bkr.ready == 0) {
- PIL_sleep_ms(50);
- if (bkr.ready)
- break;
-
- /* used to redraw in 2.4x but this is just for exec in 2.5 */
- if (!G.background)
- BKE_blender_test_break();
- }
- BLI_threadpool_end(&threads);
-
- if (bkr.result == BAKE_RESULT_NO_OBJECTS)
- BKE_report(op->reports, RPT_ERROR, "No valid images found to bake to");
- else if (bkr.result == BAKE_RESULT_FEEDBACK_LOOP)
- BKE_report(op->reports, RPT_ERROR, "Circular reference in texture stack");
-
- finish_bake_internal(&bkr);
-
- result = OPERATOR_FINISHED;
- }
- }
+ result = multiresbake_image_exec_locked(C, op);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
diff --git a/source/blender/editors/object/object_bake_api.c b/source/blender/editors/object/object_bake_api.c
index c78b9b37da1..b49a58b3766 100644
--- a/source/blender/editors/object/object_bake_api.c
+++ b/source/blender/editors/object/object_bake_api.c
@@ -56,8 +56,11 @@
#include "BKE_report.h"
#include "BKE_modifier.h"
#include "BKE_mesh.h"
+#include "BKE_scene.h"
#include "BKE_screen.h"
-#include "BKE_depsgraph.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "RE_engine.h"
#include "RE_pipeline.h"
@@ -84,6 +87,7 @@ typedef struct BakeAPIRender {
Object *ob;
Main *main;
Scene *scene;
+ ViewLayer *view_layer;
ReportList *reports;
ListBase selected_objects;
@@ -272,7 +276,7 @@ static void refresh_images(BakeImages *bake_images)
Image *ima = bake_images->data[i].image;
if (ima->ok == IMA_OK_LOADED) {
GPU_free_image(ima);
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
}
}
}
@@ -619,11 +623,11 @@ static size_t initialize_internal_images(BakeImages *bake_images, ReportList *re
}
/* create new mesh with edit mode changes and modifiers applied */
-static Mesh *bake_mesh_new_from_object(Main *bmain, Scene *scene, Object *ob)
+static Mesh *bake_mesh_new_from_object(Depsgraph *depsgraph, Main *bmain, Scene *scene, Object *ob)
{
ED_object_editmode_load(ob);
- Mesh *me = BKE_mesh_new_from_object(bmain, scene, ob, 1, 2, 0, 0);
+ Mesh *me = BKE_mesh_new_from_object(depsgraph, bmain, scene, ob, 1, 0, 0);
if (me->flag & ME_AUTOSMOOTH) {
BKE_mesh_split_faces(me, true);
}
@@ -632,7 +636,8 @@ static Mesh *bake_mesh_new_from_object(Main *bmain, Scene *scene, Object *ob)
}
static int bake(
- Render *re, Main *bmain, Scene *scene, Object *ob_low, ListBase *selected_objects, ReportList *reports,
+ Render *re, Main *bmain, Scene *scene, ViewLayer *view_layer, Object *ob_low, ListBase *selected_objects,
+ ReportList *reports,
const eScenePassType pass_type, const int pass_filter, const int margin,
const eBakeSaveMode save_mode, const bool is_clear, const bool is_split_materials,
const bool is_automatic_name, const bool is_selected_to_active, const bool is_cage,
@@ -640,6 +645,8 @@ static int bake(
const char *custom_cage, const char *filepath, const int width, const int height,
const char *identifier, ScrArea *sa, const char *uv_layer)
{
+ Depsgraph *depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER);
+
int op_result = OPERATOR_CANCELLED;
bool ok = false;
@@ -781,8 +788,12 @@ static int bake(
}
}
+ /* Make sure depsgraph is up to date. */
+ DEG_graph_build_from_view_layer(depsgraph, bmain, scene, view_layer);
+ BKE_scene_graph_update_tagged(depsgraph, bmain);
+
/* get the mesh as it arrives in the renderer */
- me_low = bake_mesh_new_from_object(bmain, scene, ob_low);
+ me_low = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low);
/* populate the pixel array with the face data */
if ((is_selected_to_active && (ob_cage == NULL) && is_cage) == false)
@@ -797,7 +808,7 @@ static int bake(
/* prepare cage mesh */
if (ob_cage) {
- me_cage = bake_mesh_new_from_object(bmain, scene, ob_cage);
+ me_cage = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_cage);
if ((me_low->totpoly != me_cage->totpoly) || (me_low->totloop != me_cage->totloop)) {
BKE_report(reports, RPT_ERROR,
"Invalid cage object, the cage mesh must have the same number "
@@ -829,7 +840,7 @@ static int bake(
ob_low->modifiers = modifiers_tmp;
/* get the cage mesh as it arrives in the renderer */
- me_cage = bake_mesh_new_from_object(bmain, scene, ob_low);
+ me_cage = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low);
RE_bake_pixels_populate(me_cage, pixel_array_low, num_pixels, &bake_images, uv_layer);
}
@@ -855,7 +866,7 @@ static int bake(
tmd->quad_method = MOD_TRIANGULATE_QUAD_FIXED;
tmd->ngon_method = MOD_TRIANGULATE_NGON_EARCLIP;
- highpoly[i].me = bake_mesh_new_from_object(bmain, scene, highpoly[i].ob);
+ highpoly[i].me = bake_mesh_new_from_object(depsgraph, bmain, scene, highpoly[i].ob);
highpoly[i].ob->restrictflag &= ~OB_RESTRICT_RENDER;
/* lowpoly to highpoly transformation matrix */
@@ -882,7 +893,7 @@ static int bake(
/* the baking itself */
for (i = 0; i < tot_highpoly; i++) {
- ok = RE_bake_engine(re, highpoly[i].ob, i, pixel_array_high,
+ ok = RE_bake_engine(re, view_layer, highpoly[i].ob, i, pixel_array_high,
num_pixels, depth, pass_type, pass_filter, result);
if (!ok) {
BKE_reportf(reports, RPT_ERROR, "Error baking from object \"%s\"", highpoly[i].ob->id.name + 2);
@@ -909,7 +920,7 @@ cage_cleanup:
ob_low->restrictflag &= ~OB_RESTRICT_RENDER;
if (RE_bake_has_engine(re)) {
- ok = RE_bake_engine(re, ob_low, 0, pixel_array_low, num_pixels, depth, pass_type, pass_filter, result);
+ ok = RE_bake_engine(re, view_layer, ob_low, 0, pixel_array_low, num_pixels, depth, pass_type, pass_filter, result);
}
else {
BKE_report(reports, RPT_ERROR, "Current render engine does not support baking");
@@ -958,7 +969,7 @@ cage_cleanup:
md->mode &= ~eModifierMode_Render;
}
- me_nores = bake_mesh_new_from_object(bmain, scene, ob_low);
+ me_nores = bake_mesh_new_from_object(depsgraph, bmain, scene, ob_low);
RE_bake_pixels_populate(me_nores, pixel_array_low, num_pixels, &bake_images, uv_layer);
RE_bake_normal_world_to_tangent(pixel_array_low, num_pixels, depth, result, me_nores, normal_swizzle, ob_low->obmat);
@@ -1119,6 +1130,7 @@ static void bake_init_api_data(wmOperator *op, bContext *C, BakeAPIRender *bkr)
bkr->ob = CTX_data_active_object(C);
bkr->main = CTX_data_main(C);
+ bkr->view_layer = CTX_data_view_layer(C);
bkr->scene = CTX_data_scene(C);
bkr->sa = sc ? BKE_screen_find_big_area(sc, SPACE_IMAGE, 10) : NULL;
@@ -1202,7 +1214,7 @@ static int bake_exec(bContext *C, wmOperator *op)
if (bkr.is_selected_to_active) {
result = bake(
- bkr.render, bkr.main, bkr.scene, bkr.ob, &bkr.selected_objects, bkr.reports,
+ bkr.render, bkr.main, bkr.scene, bkr.view_layer, bkr.ob, &bkr.selected_objects, bkr.reports,
bkr.pass_type, bkr.pass_filter, bkr.margin, bkr.save_mode,
bkr.is_clear, bkr.is_split_materials, bkr.is_automatic_name, true, bkr.is_cage,
bkr.cage_extrusion, bkr.normal_space, bkr.normal_swizzle,
@@ -1215,7 +1227,7 @@ static int bake_exec(bContext *C, wmOperator *op)
for (link = bkr.selected_objects.first; link; link = link->next) {
Object *ob_iter = link->ptr.data;
result = bake(
- bkr.render, bkr.main, bkr.scene, ob_iter, NULL, bkr.reports,
+ bkr.render, bkr.main, bkr.scene, bkr.view_layer, ob_iter, NULL, bkr.reports,
bkr.pass_type, bkr.pass_filter, bkr.margin, bkr.save_mode,
is_clear, bkr.is_split_materials, bkr.is_automatic_name, false, bkr.is_cage,
bkr.cage_extrusion, bkr.normal_space, bkr.normal_swizzle,
@@ -1260,7 +1272,7 @@ static void bake_startjob(void *bkv, short *UNUSED(stop), short *do_update, floa
if (bkr->is_selected_to_active) {
bkr->result = bake(
- bkr->render, bkr->main, bkr->scene, bkr->ob, &bkr->selected_objects, bkr->reports,
+ bkr->render, bkr->main, bkr->scene, bkr->view_layer, bkr->ob, &bkr->selected_objects, bkr->reports,
bkr->pass_type, bkr->pass_filter, bkr->margin, bkr->save_mode,
bkr->is_clear, bkr->is_split_materials, bkr->is_automatic_name, true, bkr->is_cage,
bkr->cage_extrusion, bkr->normal_space, bkr->normal_swizzle,
@@ -1273,7 +1285,7 @@ static void bake_startjob(void *bkv, short *UNUSED(stop), short *do_update, floa
for (link = bkr->selected_objects.first; link; link = link->next) {
Object *ob_iter = link->ptr.data;
bkr->result = bake(
- bkr->render, bkr->main, bkr->scene, ob_iter, NULL, bkr->reports,
+ bkr->render, bkr->main, bkr->scene, bkr->view_layer, ob_iter, NULL, bkr->reports,
bkr->pass_type, bkr->pass_filter, bkr->margin, bkr->save_mode,
is_clear, bkr->is_split_materials, bkr->is_automatic_name, false, bkr->is_cage,
bkr->cage_extrusion, bkr->normal_space, bkr->normal_swizzle,
diff --git a/source/blender/editors/object/object_constraint.c b/source/blender/editors/object/object_constraint.c
index 94caaedec19..6a0dedd1d43 100644
--- a/source/blender/editors/object/object_constraint.c
+++ b/source/blender/editors/object/object_constraint.c
@@ -53,7 +53,6 @@
#include "BKE_armature.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_main.h"
@@ -62,6 +61,9 @@
#include "BKE_tracking.h"
#include "BIK_api.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#ifdef WITH_PYTHON
#include "BPY_extern.h"
#endif
@@ -596,6 +598,11 @@ static int edit_constraint_poll_generic(bContext *C, StructRNA *rna_type)
return 0;
}
+ if (ID_IS_STATIC_OVERRIDE(ob)) {
+ CTX_wm_operator_poll_msg_set(C, "Cannot edit constraints comming from static override");
+ return (((bConstraint *)ptr.data)->flag & CONSTRAINT_STATICOVERRIDE_LOCAL) != 0;
+ }
+
return 1;
}
@@ -773,8 +780,10 @@ void CONSTRAINT_OT_limitdistance_reset(wmOperatorType *ot)
/* ------------- Child-Of Constraint ------------------ */
-static void child_get_inverse_matrix(Scene *scene, Object *ob, bConstraint *con, float invmat[4][4], const int owner)
+static void child_get_inverse_matrix(const bContext *C, Scene *scene, Object *ob, bConstraint *con, float invmat[4][4], const int owner)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
/* nullify inverse matrix first */
unit_m4(invmat);
@@ -800,7 +809,7 @@ static void child_get_inverse_matrix(Scene *scene, Object *ob, bConstraint *con,
* to use as baseline ("pmat") to derive delta from. This extra calc saves users
* from having pressing "Clear Inverse" first
*/
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
copy_m4_m4(pmat, pchan->pose_mat);
/* 2. knock out constraints starting from this one */
@@ -817,7 +826,7 @@ static void child_get_inverse_matrix(Scene *scene, Object *ob, bConstraint *con,
}
/* 3. solve pose without disabled constraints */
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
/* 4. determine effect of constraint by removing the newly calculated
* pchan->pose_mat from the original pchan->pose_mat, thus determining
@@ -840,7 +849,7 @@ static void child_get_inverse_matrix(Scene *scene, Object *ob, bConstraint *con,
}
/* 6. recalculate pose with new inv-mat applied */
- BKE_pose_where_is(scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob);
}
}
if (owner == EDIT_CONSTRAINT_OWNER_OBJECT) {
@@ -851,7 +860,7 @@ static void child_get_inverse_matrix(Scene *scene, Object *ob, bConstraint *con,
BLI_assert(BLI_findindex(&ob->constraints, con) != -1);
/* use BKE_object_workob_calc_parent to find inverse - just like for normal parenting */
- BKE_object_workob_calc_parent(scene, ob, &workob);
+ BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
invert_m4_m4(invmat, workob.obmat);
}
}
@@ -873,7 +882,7 @@ static int childof_set_inverse_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- child_get_inverse_matrix(scene, ob, con, data->invmat, owner);
+ child_get_inverse_matrix(C, scene, ob, con, data->invmat, owner);
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
@@ -1095,7 +1104,7 @@ static int objectsolver_set_inverse_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- child_get_inverse_matrix(scene, ob, con, data->invmat, owner);
+ child_get_inverse_matrix(C, scene, ob, con, data->invmat, owner);
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, ob);
@@ -1196,9 +1205,9 @@ void ED_object_constraint_update(Object *ob)
object_test_constraints(ob);
if (ob->type == OB_ARMATURE)
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
else
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
static void object_pose_tag_update(Main *bmain, Object *ob)
@@ -1221,7 +1230,7 @@ void ED_object_constraint_dependency_update(Main *bmain, Object *ob)
if (ob->pose) {
object_pose_tag_update(bmain, ob);
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
void ED_object_constraint_tag_update(Object *ob, bConstraint *con)
@@ -1233,9 +1242,9 @@ void ED_object_constraint_tag_update(Object *ob, bConstraint *con)
object_test_constraint(ob, con);
if (ob->type == OB_ARMATURE)
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
else
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
void ED_object_constraint_dependency_tag_update(Main *bmain, Object *ob, bConstraint *con)
@@ -1245,7 +1254,7 @@ void ED_object_constraint_dependency_tag_update(Main *bmain, Object *ob, bConstr
if (ob->pose) {
object_pose_tag_update(bmain, ob);
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
static int constraint_poll(bContext *C)
@@ -1269,7 +1278,7 @@ static int constraint_delete_exec(bContext *C, wmOperator *UNUSED(op))
ED_object_constraint_update(ob); /* needed to set the flags on posebones correctly */
/* relatiols */
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
/* notifiers */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
@@ -1411,12 +1420,12 @@ static int pose_constraints_clear_exec(bContext *C, wmOperator *UNUSED(op))
CTX_DATA_END;
/* force depsgraph to get recalculated since relationships removed */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
/* note, calling BIK_clear_data() isn't needed here */
/* do updates */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
return OPERATOR_FINISHED;
@@ -1443,12 +1452,12 @@ static int object_constraints_clear_exec(bContext *C, wmOperator *UNUSED(op))
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
{
BKE_constraints_free(&ob->constraints);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
CTX_DATA_END;
/* force depsgraph to get recalculated since relationships removed */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
/* do updates */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, NULL);
@@ -1496,13 +1505,13 @@ static int pose_constraint_copy_exec(bContext *C, wmOperator *op)
chan->constflag |= pchan->constflag;
BKE_pose_tag_recalc(bmain, ob->pose);
- DAG_id_tag_update((ID *)ob, OB_RECALC_DATA);
+ DEG_id_tag_update((ID *)ob, OB_RECALC_DATA);
}
}
BLI_freelistN(&lb);
/* force depsgraph to get recalculated since new relationships added */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT, NULL);
@@ -1535,13 +1544,13 @@ static int object_constraint_copy_exec(bContext *C, wmOperator *UNUSED(op))
/* if we're not handling the object we're copying from, copy all constraints over */
if (obact != ob) {
BKE_constraints_copy(&ob->constraints, &obact->constraints, true);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
CTX_DATA_END;
/* force depsgraph to get recalculated since new relationships added */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_ADDED, NULL);
@@ -1611,11 +1620,6 @@ static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob
only_ob = true;
add = false;
break;
-
- /* object only - add here is ok? */
- case CONSTRAINT_TYPE_RIGIDBODYJOINT:
- only_ob = true;
- break;
}
/* if the active Object is Armature, and we can search for bones, do so... */
@@ -1647,7 +1651,7 @@ static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob
/* for armatures in pose mode, look inside the armature for the active bone
* so that we set up cross-armature constraints with less effort
*/
- if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) &&
+ if ((ob->type == OB_ARMATURE) && (ob->mode & OB_MODE_POSE) &&
(!only_curve && !only_mesh))
{
/* just use the active bone, and assume that it is visible + usable */
@@ -1682,14 +1686,15 @@ static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob
if ((found == false) && (add)) {
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
- Base *base = BASACT, *newbase = NULL;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Base *base = BASACT(view_layer), *newbase = NULL;
Object *obt;
/* add new target object */
- obt = BKE_object_add(bmain, scene, OB_EMPTY, NULL);
+ obt = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, NULL);
/* set layers OK */
- newbase = BASACT;
+ newbase = BASACT(view_layer);
newbase->lay = base->lay;
obt->lay = newbase->lay;
@@ -1708,8 +1713,8 @@ static bool get_new_constraint_target(bContext *C, int con_type, Object **tar_ob
}
/* restore, BKE_object_add sets active */
- BASACT = base;
- base->flag |= SELECT;
+ BASACT(view_layer) = base;
+ base->flag |= BASE_SELECTED;
/* make our new target the new object */
*tar_ob = obt;
@@ -1743,10 +1748,6 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase
if (type == CONSTRAINT_TYPE_NULL) {
return OPERATOR_CANCELLED;
}
- if ((type == CONSTRAINT_TYPE_RIGIDBODYJOINT) && (list != &ob->constraints)) {
- BKE_report(op->reports, RPT_ERROR, "Rigid Body Joint constraint can only be added to objects");
- return OPERATOR_CANCELLED;
- }
if ((type == CONSTRAINT_TYPE_KINEMATIC) && ((!pchan) || (list != &pchan->constraints))) {
BKE_report(op->reports, RPT_ERROR, "IK constraint can only be added to bones");
return OPERATOR_CANCELLED;
@@ -1817,7 +1818,7 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase
/* force depsgraph to get recalculated since new relationships added */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
if ((ob->type == OB_ARMATURE) && (pchan)) {
BKE_pose_tag_recalc(bmain, ob->pose); /* sort pose channels */
@@ -1827,10 +1828,10 @@ static int constraint_add_exec(bContext *C, wmOperator *op, Object *ob, ListBase
* XXX Temp hack until new depsgraph hopefully solves this. */
ob->adt->recalc |= ADT_RECALC_ANIM;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
}
else
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
/* notifiers for updates */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_ADDED, ob);
@@ -2070,7 +2071,7 @@ static int pose_ik_clear_exec(bContext *C, wmOperator *UNUSED(op))
CTX_DATA_END;
/* refresh depsgraph */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* note, notifier might evolve */
WM_event_add_notifier(C, NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, ob);
diff --git a/source/blender/editors/object/object_data_transfer.c b/source/blender/editors/object/object_data_transfer.c
index 7845cfe1022..d4e8955b38e 100644
--- a/source/blender/editors/object/object_data_transfer.c
+++ b/source/blender/editors/object/object_data_transfer.c
@@ -40,13 +40,14 @@
#include "BKE_context.h"
#include "BKE_data_transfer.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_mesh_remap.h"
#include "BKE_object.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -95,13 +96,14 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(
{
EnumPropertyItem *item = NULL, tmp_item = {0};
int totitem = 0;
-
const int data_type = RNA_enum_get(ptr, "data_type");
if (!C) { /* needed for docs and i18n tools */
return rna_enum_dt_layers_select_src_items;
}
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ACTIVE_SRC);
RNA_enum_items_add_value(&item, &totitem, rna_enum_dt_layers_select_src_items, DT_LAYERS_ALL_SRC);
@@ -135,19 +137,19 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(
if (ob_src) {
DerivedMesh *dm_src;
- CustomData *pdata;
+ CustomData *ldata;
int num_data, i;
/* XXX Is this OK? */
- dm_src = mesh_get_derived_final(scene, ob_src, CD_MASK_BAREMESH | CD_MTEXPOLY);
- pdata = dm_src->getPolyDataLayout(dm_src);
- num_data = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
+ dm_src = mesh_get_derived_final(depsgraph, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPUV);
+ ldata = dm_src->getLoopDataLayout(dm_src);
+ num_data = CustomData_number_of_layers(ldata, CD_MLOOPUV);
RNA_enum_item_add_separator(&item, &totitem);
for (i = 0; i < num_data; i++) {
tmp_item.value = i;
- tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(pdata, CD_MTEXPOLY, i);
+ tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(ldata, CD_MLOOPUV, i);
RNA_enum_item_add(&item, &totitem, &tmp_item);
}
}
@@ -162,7 +164,7 @@ static const EnumPropertyItem *dt_layers_select_src_itemf(
int num_data, i;
/* XXX Is this OK? */
- dm_src = mesh_get_derived_final(scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPCOL);
+ dm_src = mesh_get_derived_final(depsgraph, scene, ob_src, CD_MASK_BAREMESH | CD_MLOOPCOL);
ldata = dm_src->getLoopDataLayout(dm_src);
num_data = CustomData_number_of_layers(ldata, CD_MLOOPCOL);
@@ -344,6 +346,7 @@ static int data_transfer_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Object *ob_src = ED_object_active_context(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
ListBase ctx_objects;
CollectionPointerLink *ctx_ob_dst;
@@ -412,7 +415,7 @@ static int data_transfer_exec(bContext *C, wmOperator *op)
}
if (BKE_object_data_transfer_mesh(
- scene, ob_src, ob_dst, data_type, use_create,
+ depsgraph, scene, ob_src, ob_dst, data_type, use_create,
map_vert_mode, map_edge_mode, map_loop_mode, map_poly_mode,
space_transform, use_auto_transform,
max_distance, ray_radius, islands_precision,
@@ -423,7 +426,7 @@ static int data_transfer_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
if (reverse_transfer) {
SWAP(Object *, ob_src, ob_dst);
@@ -525,7 +528,7 @@ static void data_transfer_ui(bContext *C, wmOperator *op)
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
/* Main auto-draw call */
- uiDefAutoButsRNA(layout, &ptr, data_transfer_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, data_transfer_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
}
/* transfers weight from active to selected */
@@ -622,6 +625,7 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Object *ob_act = ED_object_active_context(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
DataTransferModifierData *dtmd;
dtmd = (DataTransferModifierData *)edit_modifier_property_get(op, ob_act, eModifierType_DataTransfer);
@@ -638,10 +642,10 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- BKE_object_data_transfer_layout(scene, ob_src, ob_dst, dtmd->data_types, use_delete,
+ BKE_object_data_transfer_layout(depsgraph, scene, ob_src, ob_dst, dtmd->data_types, use_delete,
dtmd->layers_select_src, dtmd->layers_select_dst);
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
}
else {
Object *ob_src = ob_act;
@@ -668,11 +672,11 @@ static int datalayout_transfer_exec(bContext *C, wmOperator *op)
for (ctx_ob_dst = ctx_objects.first; ctx_ob_dst; ctx_ob_dst = ctx_ob_dst->next) {
Object *ob_dst = ctx_ob_dst->ptr.data;
if (data_transfer_exec_is_object_valid(op, ob_src, ob_dst, false)) {
- BKE_object_data_transfer_layout(scene, ob_src, ob_dst, data_type, use_delete,
+ BKE_object_data_transfer_layout(depsgraph, scene, ob_src, ob_dst, data_type, use_delete,
layers_select_src, layers_select_dst);
}
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
}
BLI_freelistN(&ctx_objects);
diff --git a/source/blender/editors/object/object_edit.c b/source/blender/editors/object/object_edit.c
index 844ed168157..d051e42cb32 100644
--- a/source/blender/editors/object/object_edit.c
+++ b/source/blender/editors/object/object_edit.c
@@ -51,7 +51,6 @@
#include "DNA_group_types.h"
#include "DNA_material_types.h"
#include "DNA_meta_types.h"
-#include "DNA_property_types.h"
#include "DNA_scene_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force_types.h"
@@ -59,15 +58,16 @@
#include "DNA_vfont_types.h"
#include "DNA_mesh_types.h"
#include "DNA_lattice_types.h"
+#include "DNA_workspace_types.h"
#include "IMB_imbuf_types.h"
#include "BKE_anim.h"
+#include "BKE_collection.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_effect.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_lattice.h"
@@ -77,15 +77,18 @@
#include "BKE_mball.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
+#include "BKE_paint.h"
#include "BKE_pointcache.h"
-#include "BKE_property.h"
-#include "BKE_sca.h"
#include "BKE_softbody.h"
#include "BKE_modifier.h"
#include "BKE_editlattice.h"
#include "BKE_editmesh.h"
#include "BKE_report.h"
-#include "BKE_undo_system.h"
+#include "BKE_workspace.h"
+#include "BKE_layer.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "ED_armature.h"
#include "ED_curve.h"
@@ -104,11 +107,16 @@
/* for menu/popup icons etc etc*/
#include "UI_interface.h"
+#include "UI_resources.h"
#include "WM_api.h"
#include "WM_types.h"
#include "object_intern.h" // own include
+/* prototypes */
+typedef struct MoveToCollectionData MoveToCollectionData;
+static void move_to_collection_menus_items(struct uiLayout *layout, struct MoveToCollectionData *menu);
+
/* ************* XXX **************** */
static void error(const char *UNUSED(arg)) {}
static void waitcursor(int UNUSED(val)) {}
@@ -135,192 +143,6 @@ Object *ED_object_active_context(bContext *C)
}
-/* ********* clear/set restrict view *********/
-static int object_hide_view_clear_exec(bContext *C, wmOperator *op)
-{
- Main *bmain = CTX_data_main(C);
- ScrArea *sa = CTX_wm_area(C);
- View3D *v3d = sa->spacedata.first;
- Scene *scene = CTX_data_scene(C);
- Base *base;
- bool changed = false;
- const bool select = RNA_boolean_get(op->ptr, "select");
-
- /* XXX need a context loop to handle such cases */
- for (base = FIRSTBASE; base; base = base->next) {
- if ((base->lay & v3d->lay) && base->object->restrictflag & OB_RESTRICT_VIEW) {
- if (!(base->object->restrictflag & OB_RESTRICT_SELECT)) {
- SET_FLAG_FROM_TEST(base->flag, select, SELECT);
- }
- base->object->flag = base->flag;
- base->object->restrictflag &= ~OB_RESTRICT_VIEW;
- changed = true;
- }
- }
- if (changed) {
- DAG_id_type_tag(bmain, ID_OB);
- DAG_relations_tag_update(bmain);
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
- }
-
- return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_hide_view_clear(wmOperatorType *ot)
-{
-
- /* identifiers */
- ot->name = "Clear Restrict View";
- ot->description = "Reveal the object by setting the hide flag";
- ot->idname = "OBJECT_OT_hide_view_clear";
-
- /* api callbacks */
- ot->exec = object_hide_view_clear_exec;
- ot->poll = ED_operator_view3d_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- RNA_def_boolean(ot->srna, "select", true, "Select", "");
-}
-
-static int object_hide_view_set_exec(bContext *C, wmOperator *op)
-{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- bool changed = false;
- const bool unselected = RNA_boolean_get(op->ptr, "unselected");
-
- CTX_DATA_BEGIN(C, Base *, base, visible_bases)
- {
- if (!unselected) {
- if (base->flag & SELECT) {
- base->flag &= ~SELECT;
- base->object->flag = base->flag;
- base->object->restrictflag |= OB_RESTRICT_VIEW;
- changed = true;
- if (base == BASACT) {
- ED_base_object_activate(C, NULL);
- }
- }
- }
- else {
- if (!(base->flag & SELECT)) {
- base->object->restrictflag |= OB_RESTRICT_VIEW;
- changed = true;
- if (base == BASACT) {
- ED_base_object_activate(C, NULL);
- }
- }
- }
- }
- CTX_DATA_END;
-
- if (changed) {
- DAG_id_type_tag(bmain, ID_OB);
- DAG_relations_tag_update(bmain);
-
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-
- }
-
- return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_hide_view_set(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Set Restrict View";
- ot->description = "Hide the object by setting the hide flag";
- ot->idname = "OBJECT_OT_hide_view_set";
-
- /* api callbacks */
- ot->exec = object_hide_view_set_exec;
- ot->poll = ED_operator_view3d_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
-
-}
-
-/* 99% same as above except no need for scene refreshing (TODO, update render preview) */
-static int object_hide_render_clear_exec(bContext *C, wmOperator *UNUSED(op))
-{
- bool changed = false;
-
- /* XXX need a context loop to handle such cases */
- CTX_DATA_BEGIN(C, Object *, ob, selected_editable_objects)
- {
- if (ob->restrictflag & OB_RESTRICT_RENDER) {
- ob->restrictflag &= ~OB_RESTRICT_RENDER;
- changed = true;
- }
- }
- CTX_DATA_END;
-
- if (changed)
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_hide_render_clear(wmOperatorType *ot)
-{
-
- /* identifiers */
- ot->name = "Clear Restrict Render";
- ot->description = "Reveal the render object by setting the hide render flag";
- ot->idname = "OBJECT_OT_hide_render_clear";
-
- /* api callbacks */
- ot->exec = object_hide_render_clear_exec;
- ot->poll = ED_operator_view3d_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-static int object_hide_render_set_exec(bContext *C, wmOperator *op)
-{
- const bool unselected = RNA_boolean_get(op->ptr, "unselected");
-
- CTX_DATA_BEGIN(C, Base *, base, visible_bases)
- {
- if (!unselected) {
- if (base->flag & SELECT) {
- base->object->restrictflag |= OB_RESTRICT_RENDER;
- }
- }
- else {
- if (!(base->flag & SELECT)) {
- base->object->restrictflag |= OB_RESTRICT_RENDER;
- }
- }
- }
- CTX_DATA_END;
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_OUTLINER, NULL);
- return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_hide_render_set(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Set Restrict Render";
- ot->description = "Hide the render object by setting the hide render flag";
- ot->idname = "OBJECT_OT_hide_render_set";
-
- /* api callbacks */
- ot->exec = object_hide_render_set_exec;
- ot->poll = ED_operator_view3d_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- RNA_def_boolean(ot->srna, "unselected", 0, "Unselected", "Hide unselected rather than selected objects");
-}
-
/* ******************* toggle editmode operator ***************** */
static bool mesh_needs_keyindex(const Mesh *me)
@@ -391,7 +213,7 @@ static bool ED_object_editmode_load_ex(Main *bmain, Object *obedit, const bool f
* to inform dependency graph about this. But is it really the
* best place to do this?
*/
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
const Curve *cu = obedit->data;
@@ -459,8 +281,8 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f
if (ED_object_editmode_load_ex(G.main, obedit, freedata) == false) {
/* in rare cases (background mode) its possible active object
* is flagged for editmode, without 'obedit' being set [#35489] */
- if (UNLIKELY(scene->basact && (scene->basact->object->mode & OB_MODE_EDIT))) {
- scene->basact->object->mode &= ~OB_MODE_EDIT;
+ if (UNLIKELY(obedit && obedit->mode & OB_MODE_EDIT)) {
+ obedit->mode &= ~OB_MODE_EDIT;
}
if (flag & EM_WAITCURSOR) waitcursor(0);
return;
@@ -471,9 +293,6 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f
ListBase pidlist;
PTCacheID *pid;
- /* for example; displist make is different in editmode */
- scene->obedit = NULL; // XXX for context
-
/* flag object caches as outdated */
BKE_ptcache_ids_from_object(&pidlist, obedit, scene, 0);
for (pid = pidlist.first; pid; pid = pid->next) {
@@ -485,7 +304,7 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f
BKE_ptcache_object_reset(scene, obedit, PTCACHE_RESET_OUTDATED);
/* also flush ob recalc, doesn't take much overhead, but used for particles */
- DAG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_OB | OB_RECALC_DATA);
if (flag & EM_DO_UNDO)
ED_undo_push(C, "Editmode");
@@ -497,6 +316,7 @@ void ED_object_editmode_exit_ex(bContext *C, Scene *scene, Object *obedit, int f
WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
}
+
obedit->mode &= ~OB_MODE_EDIT;
}
@@ -510,34 +330,12 @@ void ED_object_editmode_exit(bContext *C, int flag)
ED_object_editmode_exit_ex(C, scene, obedit, flag);
}
-void ED_object_editmode_enter(bContext *C, int flag)
+void ED_object_editmode_enter_ex(Scene *scene, Object *ob, int flag)
{
- Scene *scene = CTX_data_scene(C);
- Base *base = NULL;
- Object *ob;
- ScrArea *sa = CTX_wm_area(C);
- View3D *v3d = NULL;
bool ok = false;
- if (ID_IS_LINKED(scene)) return;
-
- if (sa && sa->spacetype == SPACE_VIEW3D)
- v3d = sa->spacedata.first;
-
- if ((flag & EM_IGNORE_LAYER) == 0) {
- base = CTX_data_active_base(C); /* active layer checked here for view3d */
-
- if (base == NULL) return;
- else if (v3d && (base->lay & v3d->lay) == 0) return;
- else if (!v3d && (base->lay & scene->lay) == 0) return;
- }
- else {
- base = scene->basact;
- }
-
- if (ELEM(NULL, base, base->object, base->object->data)) return;
-
- ob = base->object;
+ if (ELEM(NULL, ob, ob->data)) return;
+ if (ID_IS_LINKED(ob)) return;
/* this checks actual object->data, for cases when other scenes have it in editmode context */
if (BKE_object_is_in_editmode(ob))
@@ -552,18 +350,11 @@ void ED_object_editmode_enter(bContext *C, int flag)
ob->restore_mode = ob->mode;
- /* note, when switching scenes the object can have editmode data but
- * not be scene->obedit: bug 22954, this avoids calling self eternally */
- if ((ob->restore_mode & OB_MODE_EDIT) == 0)
- ED_object_mode_toggle(C, ob->mode);
-
ob->mode = OB_MODE_EDIT;
if (ob->type == OB_MESH) {
BMEditMesh *em;
ok = 1;
- scene->obedit = ob; /* context sees this */
-
const bool use_key_index = mesh_needs_keyindex(ob->data);
EDBM_mesh_make(ob, scene->toolsettings->selectmode, use_key_index);
@@ -575,7 +366,7 @@ void ED_object_editmode_enter(bContext *C, int flag)
BKE_editmesh_tessface_calc(em);
}
- WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MESH, scene);
+ WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_MESH, NULL);
}
else if (ob->type == OB_ARMATURE) {
bArmature *arm = ob->data;
@@ -593,53 +384,68 @@ void ED_object_editmode_enter(bContext *C, int flag)
return;
}
ok = 1;
- scene->obedit = ob;
ED_armature_to_edit(arm);
/* to ensure all goes in restposition and without striding */
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME); /* XXX: should this be OB_RECALC_DATA? */
- WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene);
+ WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_ARMATURE, scene);
}
else if (ob->type == OB_FONT) {
- scene->obedit = ob; /* XXX for context */
ok = 1;
ED_curve_editfont_make(ob);
- WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene);
+ WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_TEXT, scene);
}
else if (ob->type == OB_MBALL) {
- scene->obedit = ob; /* XXX for context */
ok = 1;
ED_mball_editmball_make(ob);
- WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene);
+ WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_MBALL, scene);
}
else if (ob->type == OB_LATTICE) {
- scene->obedit = ob; /* XXX for context */
ok = 1;
BKE_editlattice_make(ob);
- WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_LATTICE, scene);
+ WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_LATTICE, scene);
}
else if (ob->type == OB_SURF || ob->type == OB_CURVE) {
ok = 1;
- scene->obedit = ob; /* XXX for context */
ED_curve_editnurb_make(ob);
- WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene);
+ WM_main_add_notifier(NC_SCENE | ND_MODE | NS_EDITMODE_CURVE, scene);
}
if (ok) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
else {
- scene->obedit = NULL; /* XXX for context */
- ob->mode &= ~OB_MODE_EDIT;
- WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
+ if ((flag & EM_NO_CONTEXT) == 0) {
+ ob->mode &= ~OB_MODE_EDIT;
+ }
+ WM_main_add_notifier(NC_SCENE | ND_MODE | NS_MODE_OBJECT, scene);
}
- if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
if (flag & EM_WAITCURSOR) waitcursor(0);
+ BLI_assert((flag & EM_DO_UNDO) == 0);
+}
+
+void ED_object_editmode_enter(bContext *C, int flag)
+{
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob;
+
+ if ((flag & EM_IGNORE_LAYER) == 0) {
+ ob = CTX_data_active_object(C); /* active layer checked here for view3d */
+ }
+ else {
+ ob = view_layer->basact->object;
+ }
+ if (ob == NULL) return;
+ if (ID_IS_LINKED(ob)) return;
+
+ ED_object_editmode_enter_ex(scene, ob, flag & ~EM_DO_UNDO);
+ if (flag & EM_DO_UNDO) ED_undo_push(C, "Enter Editmode");
}
static int editmode_toggle_exec(bContext *C, wmOperator *op)
@@ -647,18 +453,39 @@ static int editmode_toggle_exec(bContext *C, wmOperator *op)
const int mode_flag = OB_MODE_EDIT;
const bool is_mode_set = (CTX_data_edit_object(C) != NULL);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *obact = OBACT(view_layer);
if (!is_mode_set) {
- Object *ob = CTX_data_active_object(C);
- if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
+ if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) {
return OPERATOR_CANCELLED;
}
}
- if (!is_mode_set)
+ if (!is_mode_set) {
ED_object_editmode_enter(C, EM_WAITCURSOR);
- else
+ if (obact->mode & mode_flag) {
+ FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
+ {
+ if ((ob != obact) && (ob->type == obact->type)) {
+ ED_object_editmode_enter_ex(scene, ob, EM_WAITCURSOR | EM_NO_CONTEXT);
+ }
+ }
+ FOREACH_SELECTED_OBJECT_END;
+ }
+ }
+ else {
ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR); /* had EM_DO_UNDO but op flag calls undo too [#24685] */
+ if ((obact->mode & mode_flag) == 0) {
+ FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
+ {
+ if ((ob != obact) && (ob->type == obact->type)) {
+ ED_object_editmode_exit_ex(NULL, scene, ob, EM_FREEDATA | EM_WAITCURSOR);
+ }
+ }
+ FOREACH_SELECTED_OBJECT_END;
+ }
+ }
ED_space_image_uv_sculpt_update(CTX_wm_manager(C), scene);
@@ -674,8 +501,9 @@ static int editmode_toggle_poll(bContext *C)
return 0;
/* if hidden but in edit mode, we still display */
- if ((ob->restrictflag & OB_RESTRICT_VIEW) && !(ob->mode & OB_MODE_EDIT))
+ if ((ob->restrictflag & OB_RESTRICT_VIEW) && !(ob->mode & OB_MODE_EDIT)) {
return 0;
+ }
return OB_TYPE_SUPPORT_EDITMODE(ob->type);
}
@@ -701,29 +529,57 @@ void OBJECT_OT_editmode_toggle(wmOperatorType *ot)
static int posemode_exec(bContext *C, wmOperator *op)
{
Base *base = CTX_data_active_base(C);
- Object *ob = base->object;
+ Object *obact = base->object;
const int mode_flag = OB_MODE_POSE;
- bool is_mode_set = (ob->mode & mode_flag) != 0;
+ bool is_mode_set = (obact->mode & mode_flag) != 0;
if (!is_mode_set) {
- if (!ED_object_mode_compat_set(C, ob, mode_flag, op->reports)) {
+ if (!ED_object_mode_compat_set(C, obact, mode_flag, op->reports)) {
return OPERATOR_CANCELLED;
}
}
- if (ob->type == OB_ARMATURE) {
- if (ob == CTX_data_edit_object(C)) {
+ if (obact->type == OB_ARMATURE) {
+ if (obact == CTX_data_edit_object(C)) {
ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO);
is_mode_set = false;
}
if (is_mode_set) {
- ED_object_posemode_exit(C, ob);
+ bool ok = ED_object_posemode_exit(C, obact);
+ if (ok) {
+ struct Main *bmain = CTX_data_main(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
+ {
+ if ((ob != obact) &&
+ (ob->type == OB_ARMATURE) &&
+ (ob->mode & mode_flag))
+ {
+ ED_object_posemode_exit_ex(bmain, ob);
+ }
+ }
+ FOREACH_SELECTED_OBJECT_END;
+ }
}
else {
- ED_object_posemode_enter(C, ob);
+ bool ok = ED_object_posemode_enter(C, obact);
+ if (ok) {
+ struct Main *bmain = CTX_data_main(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
+ {
+ if ((ob != obact) &&
+ (ob->type == OB_ARMATURE) &&
+ (ob->mode == OB_MODE_OBJECT) &&
+ (!ID_IS_LINKED(ob)))
+ {
+ ED_object_posemode_enter_ex(bmain, ob);
+ }
+ }
+ FOREACH_SELECTED_OBJECT_END;
+ }
}
-
return OPERATOR_FINISHED;
}
@@ -745,102 +601,6 @@ void OBJECT_OT_posemode_toggle(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
}
-static void copymenu_properties(Scene *scene, View3D *v3d, Object *ob)
-{
-//XXX no longer used - to be removed - replaced by game_properties_copy_exec
- bProperty *prop;
- Base *base;
- int nr, tot = 0;
- char *str;
-
- prop = ob->prop.first;
- while (prop) {
- tot++;
- prop = prop->next;
- }
-
- str = MEM_callocN(50 + 33 * tot, "copymenu prop");
-
- if (tot)
- strcpy(str, "Copy Property %t|Replace All|Merge All|%l");
- else
- strcpy(str, "Copy Property %t|Clear All (no properties on active)");
-
- tot = 0;
- prop = ob->prop.first;
- while (prop) {
- tot++;
- strcat(str, "|");
- strcat(str, prop->name);
- prop = prop->next;
- }
-
- nr = pupmenu(str);
-
- if (nr == 1 || nr == 2) {
- for (base = FIRSTBASE; base; base = base->next) {
- if ((base != BASACT) && (TESTBASELIB(v3d, base))) {
- if (nr == 1) { /* replace */
- BKE_bproperty_copy_list(&base->object->prop, &ob->prop);
- }
- else {
- for (prop = ob->prop.first; prop; prop = prop->next) {
- BKE_bproperty_object_set(base->object, prop);
- }
- }
- }
- }
- }
- else if (nr > 0) {
- prop = BLI_findlink(&ob->prop, nr - 4); /* account for first 3 menu items & menu index starting at 1*/
-
- if (prop) {
- for (base = FIRSTBASE; base; base = base->next) {
- if ((base != BASACT) && (TESTBASELIB(v3d, base))) {
- BKE_bproperty_object_set(base->object, prop);
- }
- }
- }
- }
- MEM_freeN(str);
-
-}
-
-static void copymenu_logicbricks(Scene *scene, View3D *v3d, Object *ob)
-{
-//XXX no longer used - to be removed - replaced by logicbricks_copy_exec
- Base *base;
-
- for (base = FIRSTBASE; base; base = base->next) {
- if (base->object != ob) {
- if (TESTBASELIB(v3d, base)) {
-
- /* first: free all logic */
- free_sensors(&base->object->sensors);
- unlink_controllers(&base->object->controllers);
- free_controllers(&base->object->controllers);
- unlink_actuators(&base->object->actuators);
- free_actuators(&base->object->actuators);
-
- /* now copy it, this also works without logicbricks! */
- clear_sca_new_poins_ob(ob);
- copy_sensors(&base->object->sensors, &ob->sensors, 0);
- copy_controllers(&base->object->controllers, &ob->controllers, 0);
- copy_actuators(&base->object->actuators, &ob->actuators, 0);
- set_sca_new_poins_ob(base->object);
-
- /* some menu settings */
- base->object->scavisflag = ob->scavisflag;
- base->object->scaflag = ob->scaflag;
-
- /* set the initial state */
- base->object->state = ob->state;
- base->object->init_state = ob->init_state;
- }
- }
- }
-}
-
/* both pointers should exist */
static void copy_texture_space(Object *to, Object *ob)
{
@@ -892,7 +652,7 @@ static void copy_texture_space(Object *to, Object *ob)
}
/* UNUSED, keep in case we want to copy functionality for use elsewhere */
-static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
+static void copy_attr(Main *bmain, Scene *scene, ViewLayer *view_layer, short event)
{
Object *ob;
Base *base;
@@ -902,30 +662,23 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
if (ID_IS_LINKED(scene)) return;
- if (!(ob = OBACT)) return;
+ if (!(ob = OBACT(view_layer))) return;
- if (scene->obedit) { // XXX get from context
+ if (BKE_object_is_in_editmode(ob)) {
/* obedit_copymenu(); */
return;
}
- if (event == 9) {
- copymenu_properties(scene, v3d, ob);
- return;
- }
- else if (event == 10) {
- copymenu_logicbricks(scene, v3d, ob);
- return;
- }
- else if (event == 24) {
+
+ if (event == 24) {
/* moved to BKE_object_link_modifiers */
/* copymenu_modifiers(bmain, scene, v3d, ob); */
return;
}
- for (base = FIRSTBASE; base; base = base->next) {
- if (base != BASACT) {
- if (TESTBASELIB(v3d, base)) {
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ if (base != BASACT(view_layer)) {
+ if (TESTBASELIB(base)) {
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
if (event == 1) { /* loc */
copy_v3_v3(base->object->loc, ob->loc);
@@ -964,30 +717,6 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
if (ob->dup_group)
id_us_plus(&ob->dup_group->id);
}
- else if (event == 7) { /* mass */
- base->object->mass = ob->mass;
- }
- else if (event == 8) { /* damping */
- base->object->damping = ob->damping;
- base->object->rdamping = ob->rdamping;
- }
- else if (event == 11) { /* all physical attributes */
- base->object->gameflag = ob->gameflag;
- base->object->inertia = ob->inertia;
- base->object->formfactor = ob->formfactor;
- base->object->damping = ob->damping;
- base->object->rdamping = ob->rdamping;
- base->object->min_vel = ob->min_vel;
- base->object->max_vel = ob->max_vel;
- base->object->min_angvel = ob->min_angvel;
- base->object->max_angvel = ob->max_angvel;
- if (ob->gameflag & OB_BOUNDS) {
- base->object->collision_boundtype = ob->collision_boundtype;
- }
- base->object->margin = ob->margin;
- base->object->bsoft = copy_bulletsoftbody(ob->bsoft, 0);
-
- }
else if (event == 17) { /* tex space */
copy_texture_space(base->object, ob);
}
@@ -1028,7 +757,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
BLI_strncpy(cu1->family, cu->family, sizeof(cu1->family));
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
}
}
else if (event == 19) { /* bevel settings */
@@ -1044,7 +773,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
cu1->ext1 = cu->ext1;
cu1->ext2 = cu->ext2;
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
}
}
else if (event == 25) { /* curve resolution */
@@ -1063,7 +792,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
nu = nu->next;
}
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
}
}
else if (event == 21) {
@@ -1079,7 +808,7 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
}
modifier_copyData(md, tmd);
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_DATA);
}
}
}
@@ -1140,18 +869,18 @@ static void copy_attr(Main *bmain, Scene *scene, View3D *v3d, short event)
}
if (do_depgraph_update)
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
-static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, View3D *v3d)
+static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, ViewLayer *view_layer, Object *obedit)
{
Object *ob;
short event;
char str[512];
- if (!(ob = OBACT)) return;
+ if (!(ob = OBACT(view_layer))) return;
- if (scene->obedit) { /* XXX get from context */
+ if (obedit) {
/* if (ob->type == OB_MESH) */
/* XXX mesh_copy_menu(); */
return;
@@ -1197,7 +926,7 @@ static void UNUSED_FUNCTION(copy_attr_menu) (Main *bmain, Scene *scene, View3D *
event = pupmenu(str);
if (event <= 0) return;
- copy_attr(bmain, scene, v3d, event);
+ copy_attr(bmain, scene, view_layer, event);
}
/* ******************* force field toggle operator ***************** */
@@ -1232,7 +961,7 @@ static int forcefield_toggle_exec(bContext *C, wmOperator *UNUSED(op))
ob->pd->forcefield = PFIELD_FORCE;
else
ob->pd->forcefield = 0;
-
+
ED_object_check_force_modifiers(CTX_data_main(C), CTX_data_scene(C), ob);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
@@ -1266,6 +995,8 @@ void OBJECT_OT_forcefield_toggle(wmOperatorType *ot)
*/
void ED_objects_recalculate_paths(bContext *C, Scene *scene)
{
+ struct Main *bmain = CTX_data_main(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
ListBase targets = {NULL, NULL};
/* loop over objects in scene */
@@ -1278,7 +1009,7 @@ void ED_objects_recalculate_paths(bContext *C, Scene *scene)
CTX_DATA_END;
/* recalculate paths, then free */
- animviz_calc_motionpaths(scene, &targets);
+ animviz_calc_motionpaths(depsgraph, bmain, scene, &targets);
BLI_freelistN(&targets);
}
@@ -1499,7 +1230,8 @@ static int shade_smooth_exec(bContext *C, wmOperator *op)
if (ob->type == OB_MESH) {
BKE_mesh_smooth_flag_set(ob, !clear);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
done = true;
@@ -1512,7 +1244,7 @@ static int shade_smooth_exec(bContext *C, wmOperator *op)
else nu->flag &= ~ME_SMOOTH;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
done = true;
@@ -1563,68 +1295,6 @@ void OBJECT_OT_shade_smooth(wmOperatorType *ot)
/* ********************** */
-static void UNUSED_FUNCTION(image_aspect) (Scene *scene, View3D *v3d)
-{
- /* all selected objects with an image map: scale in image aspect */
- Base *base;
- Object *ob;
- Material *ma;
- Tex *tex;
- float x, y, space;
- int a, b, done;
-
- if (scene->obedit) return; // XXX get from context
- if (ID_IS_LINKED(scene)) return;
-
- for (base = FIRSTBASE; base; base = base->next) {
- if (TESTBASELIB(v3d, base)) {
- ob = base->object;
- done = false;
-
- for (a = 1; a <= ob->totcol; a++) {
- ma = give_current_material(ob, a);
- if (ma) {
- for (b = 0; b < MAX_MTEX; b++) {
- if (ma->mtex[b] && ma->mtex[b]->tex) {
- tex = ma->mtex[b]->tex;
- if (tex->type == TEX_IMAGE && tex->ima) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, NULL, NULL);
-
- /* texturespace */
- space = 1.0;
- if (ob->type == OB_MESH) {
- float size[3];
- BKE_mesh_texspace_get(ob->data, NULL, NULL, size);
- space = size[0] / size[1];
- }
- else if (ELEM(ob->type, OB_CURVE, OB_FONT, OB_SURF)) {
- float size[3];
- BKE_curve_texspace_get(ob->data, NULL, NULL, size);
- space = size[0] / size[1];
- }
-
- x = ibuf->x / space;
- y = ibuf->y;
-
- if (x > y) ob->size[0] = ob->size[1] * x / y;
- else ob->size[1] = ob->size[0] * y / x;
-
- done = true;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
-
- BKE_image_release_ibuf(tex->ima, ibuf, NULL);
- }
- }
- if (done) break;
- }
- }
- if (done) break;
- }
- }
- }
-
-}
-
static const EnumPropertyItem *object_mode_set_itemsf(
bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
{
@@ -1770,453 +1440,339 @@ void OBJECT_OT_mode_set(wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-/************************ Game Properties ***********************/
-
-static int game_property_new_exec(bContext *C, wmOperator *op)
+bool ED_object_editmode_calc_active_center(Object *obedit, const bool select_only, float r_center[3])
{
- Object *ob = CTX_data_active_object(C);
- bProperty *prop;
- char name[MAX_NAME];
- int type = RNA_enum_get(op->ptr, "type");
-
- prop = BKE_bproperty_new(type);
- BLI_addtail(&ob->prop, prop);
-
- RNA_string_get(op->ptr, "name", name);
- if (name[0] != '\0') {
- BLI_strncpy(prop->name, name, sizeof(prop->name));
- }
+ switch (obedit->type) {
+ case OB_MESH:
+ {
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMEditSelection ese;
- BLI_uniquename(&ob->prop, prop, DATA_("Property"), '.', offsetof(bProperty, name), sizeof(prop->name));
+ if (BM_select_history_active_get(em->bm, &ese)) {
+ BM_editselection_center(&ese, r_center);
+ return true;
+ }
+ break;
+ }
+ case OB_ARMATURE:
+ {
+ bArmature *arm = obedit->data;
+ EditBone *ebo = arm->act_edbone;
- WM_event_add_notifier(C, NC_LOGIC, NULL);
- return OPERATOR_FINISHED;
-}
+ if (ebo && (!select_only || (ebo->flag & (BONE_SELECTED | BONE_ROOTSEL)))) {
+ copy_v3_v3(r_center, ebo->head);
+ return true;
+ }
+ break;
+ }
+ case OB_CURVE:
+ case OB_SURF:
+ {
+ Curve *cu = obedit->data;
-void OBJECT_OT_game_property_new(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "New Game Property";
- ot->description = "Create a new property available to the game engine";
- ot->idname = "OBJECT_OT_game_property_new";
+ if (ED_curve_active_center(cu, r_center)) {
+ return true;
+ }
+ break;
+ }
+ case OB_MBALL:
+ {
+ MetaBall *mb = obedit->data;
+ MetaElem *ml_act = mb->lastelem;
- /* api callbacks */
- ot->exec = game_property_new_exec;
- ot->poll = ED_operator_object_active_editable;
+ if (ml_act && (!select_only || (ml_act->flag & SELECT))) {
+ copy_v3_v3(r_center, &ml_act->x);
+ return true;
+ }
+ break;
+ }
+ case OB_LATTICE:
+ {
+ BPoint *actbp = BKE_lattice_active_point_get(obedit->data);
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ if (actbp) {
+ copy_v3_v3(r_center, actbp->vec);
+ return true;
+ }
+ break;
+ }
+ }
- RNA_def_enum(ot->srna, "type", rna_enum_gameproperty_type_items, GPROP_FLOAT, "Type", "Type of game property to add");
- RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the game property to add");
+ return false;
}
-static int game_property_remove_exec(bContext *C, wmOperator *op)
+#define COLLECTION_INVALID_INDEX -1
+
+static int move_to_collection_exec(bContext *C, wmOperator *op)
{
- Object *ob = CTX_data_active_object(C);
- bProperty *prop;
- int index = RNA_int_get(op->ptr, "index");
+ Scene *scene = CTX_data_scene(C);
+ PropertyRNA *prop = RNA_struct_find_property(op->ptr, "collection_index");
+ const bool is_add = RNA_boolean_get(op->ptr, "is_add");
+ const bool is_new = RNA_boolean_get(op->ptr, "is_new");
+ SceneCollection *scene_collection;
- if (!ob)
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ BKE_report(op->reports, RPT_ERROR, "No collection selected");
return OPERATOR_CANCELLED;
+ }
- prop = BLI_findlink(&ob->prop, index);
+ int collection_index = RNA_property_int_get(op->ptr, prop);
+ scene_collection = BKE_collection_from_index(CTX_data_scene(C), collection_index);
+ if (scene_collection == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Unexpected error, collection not found");
+ return OPERATOR_CANCELLED;
+ }
- if (prop) {
- BLI_remlink(&ob->prop, prop);
- BKE_bproperty_free(prop);
+ Object *single_object = NULL;
+ CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
+ {
+ if (single_object != NULL) {
+ single_object = NULL;
+ break;
+ }
+ else {
+ single_object = ob;
+ }
+ }
+ CTX_DATA_END;
- WM_event_add_notifier(C, NC_LOGIC, NULL);
- return OPERATOR_FINISHED;
+ if (is_new) {
+ char new_collection_name[MAX_NAME];
+ RNA_string_get(op->ptr, "new_collection_name", new_collection_name);
+ scene_collection = BKE_collection_add(&scene->id, scene_collection, COLLECTION_TYPE_NONE, new_collection_name);
}
- else {
+
+ if ((single_object != NULL) &&
+ is_add &&
+ BLI_findptr(&scene_collection->objects, single_object, offsetof(LinkData, data)))
+ {
+ BKE_reportf(op->reports, RPT_ERROR, "%s already in %s", single_object->id.name + 2, scene_collection->name);
return OPERATOR_CANCELLED;
}
-}
-void OBJECT_OT_game_property_remove(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Remove Game Property";
- ot->description = "Remove game property";
- ot->idname = "OBJECT_OT_game_property_remove";
+ CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
+ {
+ if (!is_add) {
+ BKE_collection_object_move(&scene->id, scene_collection, NULL, ob);
+ }
+ else {
+ BKE_collection_object_add(&scene->id, scene_collection, ob);
+ }
+ }
+ CTX_DATA_END;
- /* api callbacks */
- ot->exec = game_property_remove_exec;
- ot->poll = ED_operator_object_active_editable;
+ BKE_reportf(op->reports,
+ RPT_INFO,
+ "%s %s to %s",
+ (single_object != NULL) ? single_object->id.name + 2 : "Objects",
+ is_add ? "added" : "moved",
+ scene_collection->name);
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ DEG_relations_tag_update(CTX_data_main(C));
+ DEG_id_tag_update(&scene->id, 0);
+
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
- RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to remove ", 0, INT_MAX);
+ return OPERATOR_FINISHED;
}
-#define GAME_PROPERTY_MOVE_UP 1
-#define GAME_PROPERTY_MOVE_DOWN -1
+typedef struct MoveToCollectionData {
+ struct MoveToCollectionData *next, *prev;
+ int index;
+ struct SceneCollection *collection;
+ struct ListBase submenus;
+ PointerRNA ptr;
+ struct wmOperatorType *ot;
+} MoveToCollectionData;
-static int game_property_move(bContext *C, wmOperator *op)
+static int move_to_collection_menus_create(wmOperator *op, MoveToCollectionData *menu)
{
- Object *ob = CTX_data_active_object(C);
- bProperty *prop;
- bProperty *otherprop = NULL;
- const int index = RNA_int_get(op->ptr, "index");
- const int dir = RNA_enum_get(op->ptr, "direction");
-
- if (ob == NULL)
- return OPERATOR_CANCELLED;
-
- prop = BLI_findlink(&ob->prop, index);
- /* invalid index */
- if (prop == NULL)
- return OPERATOR_CANCELLED;
-
- if (dir == GAME_PROPERTY_MOVE_UP) {
- otherprop = prop->prev;
- }
- else if (dir == GAME_PROPERTY_MOVE_DOWN) {
- otherprop = prop->next;
- }
- else {
- BLI_assert(0);
+ int index = menu->index;
+ for (SceneCollection *scene_collection = menu->collection->scene_collections.first;
+ scene_collection != NULL;
+ scene_collection = scene_collection->next)
+ {
+ MoveToCollectionData *submenu = MEM_callocN(sizeof(MoveToCollectionData),
+ "MoveToCollectionData submenu - expected memleak");
+ BLI_addtail(&menu->submenus, submenu);
+ submenu->collection = scene_collection;
+ submenu->index = ++index;
+ index = move_to_collection_menus_create(op, submenu);
+ submenu->ot = op->type;
}
+ return index;
+}
- if (prop && otherprop) {
- BLI_listbase_swaplinks(&ob->prop, prop, otherprop);
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
- return OPERATOR_FINISHED;
- }
- else {
- return OPERATOR_CANCELLED;
+static void move_to_collection_menus_free_recursive(MoveToCollectionData *menu)
+{
+ for (MoveToCollectionData *submenu = menu->submenus.first;
+ submenu != NULL;
+ submenu = submenu->next)
+ {
+ move_to_collection_menus_free_recursive(submenu);
}
+ BLI_freelistN(&menu->submenus);
}
-void OBJECT_OT_game_property_move(wmOperatorType *ot)
+static void move_to_collection_menus_free(MoveToCollectionData **menu)
{
- static const EnumPropertyItem direction_property_move[] = {
- {GAME_PROPERTY_MOVE_UP, "UP", 0, "Up", ""},
- {GAME_PROPERTY_MOVE_DOWN, "DOWN", 0, "Down", ""},
- {0, NULL, 0, NULL, NULL}
- };
- PropertyRNA *prop;
-
- /* identifiers */
- ot->name = "Move Game Property";
- ot->description = "Move game property";
- ot->idname = "OBJECT_OT_game_property_move";
-
- /* api callbacks */
- ot->exec = game_property_move;
- ot->poll = ED_operator_object_active_editable;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ if (*menu == NULL) {
+ return;
+ }
- /* properties */
- prop = RNA_def_int(ot->srna, "index", 0, 0, INT_MAX, "Index", "Property index to move", 0, INT_MAX);
- RNA_def_property_flag(prop, PROP_HIDDEN);
- RNA_def_enum(ot->srna, "direction", direction_property_move, 0, "Direction",
- "Direction for moving the property");
+ move_to_collection_menus_free_recursive(*menu);
+ MEM_freeN(*menu);
+ *menu = NULL;
}
-#undef GAME_PROPERTY_MOVE_UP
-#undef GAME_PROPERTY_MOVE_DOWN
-
-#define COPY_PROPERTIES_REPLACE 1
-#define COPY_PROPERTIES_MERGE 2
-#define COPY_PROPERTIES_COPY 3
-
-static const EnumPropertyItem game_properties_copy_operations[] = {
- {COPY_PROPERTIES_REPLACE, "REPLACE", 0, "Replace Properties", ""},
- {COPY_PROPERTIES_MERGE, "MERGE", 0, "Merge Properties", ""},
- {COPY_PROPERTIES_COPY, "COPY", 0, "Copy a Property", ""},
- {0, NULL, 0, NULL, NULL}
-};
+static void move_to_collection_menu_create(bContext *UNUSED(C), uiLayout *layout, void *menu_v)
+{
+ MoveToCollectionData *menu = menu_v;
-static const EnumPropertyItem *gameprops_itemf(bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
-{
- Object *ob = ED_object_active_context(C);
- EnumPropertyItem tmp = {0, "", 0, "", ""};
- EnumPropertyItem *item = NULL;
- bProperty *prop;
- int a, totitem = 0;
-
- if (!ob)
- return DummyRNA_NULL_items;
+ uiItemIntO(layout,
+ menu->collection->name,
+ ICON_NONE,
+ "OBJECT_OT_move_to_collection",
+ "collection_index",
+ menu->index);
+ uiItemS(layout);
- for (a = 1, prop = ob->prop.first; prop; prop = prop->next, a++) {
- tmp.value = a;
- tmp.identifier = prop->name;
- tmp.name = prop->name;
- RNA_enum_item_add(&item, &totitem, &tmp);
+ for (MoveToCollectionData *submenu = menu->submenus.first;
+ submenu != NULL;
+ submenu = submenu->next)
+ {
+ move_to_collection_menus_items(layout, submenu);
}
- RNA_enum_item_end(&item, &totitem);
- *r_free = true;
+ uiItemS(layout);
- return item;
+ WM_operator_properties_create_ptr(&menu->ptr, menu->ot);
+ RNA_int_set(&menu->ptr, "collection_index", menu->index);
+ RNA_boolean_set(&menu->ptr, "is_new", true);
+
+ uiItemFullO_ptr(layout,
+ menu->ot,
+ "New Collection",
+ ICON_ZOOMIN,
+ menu->ptr.data,
+ /* We use invoke here so we can read ctrl from event. */
+ WM_OP_INVOKE_DEFAULT,
+ 0,
+ NULL);
}
-static int game_property_copy_exec(bContext *C, wmOperator *op)
+static void move_to_collection_menus_items(uiLayout *layout, MoveToCollectionData *menu)
{
- Object *ob = ED_object_active_context(C);
- bProperty *prop;
- int type = RNA_enum_get(op->ptr, "operation");
- int propid = RNA_enum_get(op->ptr, "property");
-
- if (propid > 0) { /* copy */
- prop = BLI_findlink(&ob->prop, propid - 1);
-
- if (prop) {
- CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
- {
- if (ob != ob_iter)
- BKE_bproperty_object_set(ob_iter, prop);
- } CTX_DATA_END;
- }
+ if (BLI_listbase_is_empty(&menu->submenus)) {
+ uiItemIntO(layout,
+ menu->collection->name,
+ ICON_NONE,
+ "OBJECT_OT_move_to_collection",
+ "collection_index",
+ menu->index);
}
-
else {
- CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
- {
- if (ob != ob_iter) {
- if (type == COPY_PROPERTIES_REPLACE) {
- BKE_bproperty_copy_list(&ob_iter->prop, &ob->prop);
- }
- else {
- /* merge - the default when calling with no argument */
- for (prop = ob->prop.first; prop; prop = prop->next) {
- BKE_bproperty_object_set(ob_iter, prop);
- }
- }
- }
- }
- CTX_DATA_END;
+ uiItemMenuF(layout,
+ menu->collection->name,
+ ICON_NONE,
+ move_to_collection_menu_create,
+ menu);
}
-
- return OPERATOR_FINISHED;
}
-void OBJECT_OT_game_property_copy(wmOperatorType *ot)
-{
- PropertyRNA *prop;
- /* identifiers */
- ot->name = "Copy Game Property";
- ot->idname = "OBJECT_OT_game_property_copy";
- ot->description = "Copy/merge/replace a game property from active object to all selected objects";
+/* This is allocated statically because we need this available for the menus creation callback. */
+static MoveToCollectionData *master_collection_menu = NULL;
- /* api callbacks */
- ot->exec = game_property_copy_exec;
- ot->poll = ED_operator_object_active_editable;
+static int move_to_collection_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ /* Reset the menus data for the current master collection, and free previously allocated data. */
+ move_to_collection_menus_free(&master_collection_menu);
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ PropertyRNA *prop;
+ prop = RNA_struct_find_property(op->ptr, "collection_index");
+ if (RNA_property_is_set(op->ptr, prop)) {
+ int collection_index = RNA_property_int_get(op->ptr, prop);
+ RNA_boolean_set(op->ptr, "is_add", event->ctrl);
+
+ if (RNA_boolean_get(op->ptr, "is_new")) {
+ prop = RNA_struct_find_property(op->ptr, "new_collection_name");
+ if (!RNA_property_is_set(op->ptr, prop)) {
+ char name[MAX_NAME];
+ SceneCollection *scene_collection;
+
+ scene_collection = BKE_collection_from_index(CTX_data_scene(C), collection_index);
+ BKE_collection_new_name_get(&CTX_data_scene(C)->id, scene_collection, name);
+
+ RNA_property_string_set(op->ptr, prop, name);
+ return WM_operator_props_dialog_popup(C, op, 10 * UI_UNIT_X, 5 * UI_UNIT_Y);
+ }
+ }
+ return move_to_collection_exec(C, op);
+ }
- RNA_def_enum(ot->srna, "operation", game_properties_copy_operations, 3, "Operation", "");
- prop = RNA_def_enum(ot->srna, "property", DummyRNA_NULL_items, 0, "Property", "Properties to copy");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_ENUM_NO_TRANSLATE);
- RNA_def_enum_funcs(prop, gameprops_itemf);
- ot->prop = prop;
-}
+ SceneCollection *master_collection = BKE_collection_master(&CTX_data_scene(C)->id);
-static int game_property_clear_exec(bContext *C, wmOperator *UNUSED(op))
-{
- CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
- {
- BKE_bproperty_free_list(&ob_iter->prop);
+ /* We need the data to be allocated so it's available during menu drawing.
+ * Technically we could use wmOperator->customdata. However there is no free callback
+ * called to an operator that exit with OPERATOR_INTERFACE to launch a menu.
+ *
+ * So we are left with a memory that will necessarily leak. It's a small leak though.*/
+ if (master_collection_menu == NULL) {
+ master_collection_menu = MEM_callocN(sizeof(MoveToCollectionData),
+ "MoveToCollectionData menu - expected eventual memleak");
}
- CTX_DATA_END;
- WM_event_add_notifier(C, NC_LOGIC, NULL);
- return OPERATOR_FINISHED;
-}
-void OBJECT_OT_game_property_clear(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Clear Game Properties";
- ot->idname = "OBJECT_OT_game_property_clear";
- ot->description = "Remove all game properties from all selected objects";
+ master_collection_menu->collection = master_collection;
+ master_collection_menu->ot = op->type;
+ move_to_collection_menus_create(op, master_collection_menu);
- /* api callbacks */
- ot->exec = game_property_clear_exec;
- ot->poll = ED_operator_object_active_editable;
+ uiPopupMenu *pup;
+ uiLayout *layout;
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
+ /* Build the menus. */
+ pup = UI_popup_menu_begin(C, IFACE_("Move to Collection"), ICON_NONE);
+ layout = UI_popup_menu_layout(pup);
-/************************ Copy Logic Bricks ***********************/
+ /* We use invoke here so we can read ctrl from event. */
+ uiLayoutSetOperatorContext(layout, WM_OP_INVOKE_DEFAULT);
-static int logicbricks_copy_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *ob = ED_object_active_context(C);
+ move_to_collection_menu_create(C, layout, master_collection_menu);
- CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
- {
- if (ob != ob_iter) {
- /* first: free all logic */
- free_sensors(&ob_iter->sensors);
- unlink_controllers(&ob_iter->controllers);
- free_controllers(&ob_iter->controllers);
- unlink_actuators(&ob_iter->actuators);
- free_actuators(&ob_iter->actuators);
-
- /* now copy it, this also works without logicbricks! */
- clear_sca_new_poins_ob(ob);
- copy_sensors(&ob_iter->sensors, &ob->sensors, 0);
- copy_controllers(&ob_iter->controllers, &ob->controllers, 0);
- copy_actuators(&ob_iter->actuators, &ob->actuators, 0);
- set_sca_new_poins_ob(ob_iter);
-
- /* some menu settings */
- ob_iter->scavisflag = ob->scavisflag;
- ob_iter->scaflag = ob->scaflag;
-
- /* set the initial state */
- ob_iter->state = ob->state;
- ob_iter->init_state = ob->init_state;
+ UI_popup_menu_end(C, pup);
- if (ob_iter->totcol == ob->totcol) {
- ob_iter->actcol = ob->actcol;
- WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
- }
- }
- }
- CTX_DATA_END;
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
+ return OPERATOR_INTERFACE;
}
-void OBJECT_OT_logic_bricks_copy(wmOperatorType *ot)
+void OBJECT_OT_move_to_collection(wmOperatorType *ot)
{
+ PropertyRNA *prop;
+
/* identifiers */
- ot->name = "Copy Logic Bricks to Selected";
- ot->description = "Copy logic bricks to other selected objects";
- ot->idname = "OBJECT_OT_logic_bricks_copy";
+ ot->name = "Move to Collection";
+ ot->description = "Move to a collection only (Ctrl to add)";
+ ot->idname = "OBJECT_OT_move_to_collection";
/* api callbacks */
- ot->exec = logicbricks_copy_exec;
+ ot->exec = move_to_collection_exec;
+ ot->invoke = move_to_collection_invoke;
ot->poll = ED_operator_object_active_editable;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-static int game_physics_copy_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *ob = ED_object_active_context(C);
-
- CTX_DATA_BEGIN(C, Object *, ob_iter, selected_editable_objects)
- {
- if (ob != ob_iter) {
- ob_iter->gameflag = ob->gameflag;
- ob_iter->gameflag2 = ob->gameflag2;
- ob_iter->inertia = ob->inertia;
- ob_iter->formfactor = ob->formfactor;
- ob_iter->damping = ob->damping;
- ob_iter->rdamping = ob->rdamping;
- ob_iter->min_vel = ob->min_vel;
- ob_iter->max_vel = ob->max_vel;
- ob_iter->min_angvel = ob->min_angvel;
- ob_iter->max_angvel = ob->max_angvel;
- ob_iter->obstacleRad = ob->obstacleRad;
- ob_iter->mass = ob->mass;
- copy_v3_v3(ob_iter->anisotropicFriction, ob->anisotropicFriction);
- ob_iter->collision_boundtype = ob->collision_boundtype;
- ob_iter->margin = ob->margin;
- ob_iter->bsoft = copy_bulletsoftbody(ob->bsoft, 0);
- if (ob->restrictflag & OB_RESTRICT_RENDER)
- ob_iter->restrictflag |= OB_RESTRICT_RENDER;
- else
- ob_iter->restrictflag &= ~OB_RESTRICT_RENDER;
-
- ob_iter->col_group = ob->col_group;
- ob_iter->col_mask = ob->col_mask;
- }
- }
- CTX_DATA_END;
-
- return OPERATOR_FINISHED;
-}
-void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Copy Game Physics Properties to Selected";
- ot->description = "Copy game physics properties to other selected objects";
- ot->idname = "OBJECT_OT_game_physics_copy";
-
- /* api callbacks */
- ot->exec = game_physics_copy_exec;
- ot->poll = ED_operator_object_active_editable;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+ prop = RNA_def_int(ot->srna, "collection_index", COLLECTION_INVALID_INDEX, COLLECTION_INVALID_INDEX, INT_MAX,
+ "Collection Index", "Index of the collection to move to", 0, INT_MAX);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
+ prop = RNA_def_boolean(ot->srna, "is_add", false, "Add", "Keep object in original collections as well");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
+ prop = RNA_def_boolean(ot->srna, "is_new", false, "New", "Move objects to a new collection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
+ prop = RNA_def_string(ot->srna, "new_collection_name", NULL, MAX_NAME, "Name",
+ "Name of the newly added collection");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
}
-/* generic utility function */
-
-bool ED_object_editmode_calc_active_center(Object *obedit, const bool select_only, float r_center[3])
-{
- switch (obedit->type) {
- case OB_MESH:
- {
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMEditSelection ese;
-
- if (BM_select_history_active_get(em->bm, &ese)) {
- BM_editselection_center(&ese, r_center);
- return true;
- }
- break;
- }
- case OB_ARMATURE:
- {
- bArmature *arm = obedit->data;
- EditBone *ebo = arm->act_edbone;
-
- if (ebo && (!select_only || (ebo->flag & (BONE_SELECTED | BONE_ROOTSEL)))) {
- copy_v3_v3(r_center, ebo->head);
- return true;
- }
-
- break;
- }
- case OB_CURVE:
- case OB_SURF:
- {
- Curve *cu = obedit->data;
-
- if (ED_curve_active_center(cu, r_center)) {
- return true;
- }
- break;
- }
- case OB_MBALL:
- {
- MetaBall *mb = obedit->data;
- MetaElem *ml_act = mb->lastelem;
-
- if (ml_act && (!select_only || (ml_act->flag & SELECT))) {
- copy_v3_v3(r_center, &ml_act->x);
- return true;
- }
- break;
- }
- case OB_LATTICE:
- {
- BPoint *actbp = BKE_lattice_active_point_get(obedit->data);
-
- if (actbp) {
- copy_v3_v3(r_center, actbp->vec);
- return true;
- }
- break;
- }
- }
-
- return false;
-}
+#undef COLLECTION_INVALID_INDEX
diff --git a/source/blender/editors/object/object_facemap_ops.c b/source/blender/editors/object/object_facemap_ops.c
new file mode 100644
index 00000000000..c5882560083
--- /dev/null
+++ b/source/blender/editors/object/object_facemap_ops.c
@@ -0,0 +1,498 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+#include "BLI_listbase.h"
+
+#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_workspace_types.h"
+
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_editmesh.h"
+#include "BKE_object.h"
+#include "BKE_object_facemap.h"
+#include "BKE_object_deform.h"
+
+#include "DEG_depsgraph.h"
+
+#include "RNA_define.h"
+#include "RNA_access.h"
+
+#include "WM_types.h"
+#include "WM_api.h"
+
+#include "ED_mesh.h"
+#include "ED_object.h"
+
+#include "object_intern.h"
+
+/* called while not in editmode */
+void ED_object_facemap_face_add(Object *ob, bFaceMap *fmap, int facenum)
+{
+ int fmap_nr;
+ if (GS(((ID *)ob->data)->name) != ID_ME)
+ return;
+
+ /* get the face map number, exit if it can't be found */
+ fmap_nr = BLI_findindex(&ob->fmaps, fmap);
+
+ if (fmap_nr != -1) {
+ int *facemap;
+ Mesh *me = ob->data;
+
+ /* if there's is no facemap layer then create one */
+ if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == NULL)
+ facemap = CustomData_add_layer(&me->pdata, CD_FACEMAP, CD_DEFAULT, NULL, me->totpoly);
+
+ facemap[facenum] = fmap_nr;
+ }
+}
+
+/* called while not in editmode */
+void ED_object_facemap_face_remove(Object *ob, bFaceMap *fmap, int facenum)
+{
+ int fmap_nr;
+ if (GS(((ID *)ob->data)->name) != ID_ME)
+ return;
+
+ /* get the face map number, exit if it can't be found */
+ fmap_nr = BLI_findindex(&ob->fmaps, fmap);
+
+ if (fmap_nr != -1) {
+ int *facemap;
+ Mesh *me = ob->data;
+
+ /* if there's is no facemap layer then create one */
+ if ((facemap = CustomData_get_layer(&me->pdata, CD_FACEMAP)) == NULL)
+ return;
+
+ facemap[facenum] = -1;
+ }
+}
+
+static void object_fmap_swap_edit_mode(Object *ob, int num1, int num2)
+{
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+
+ if (me->edit_btmesh) {
+ BMEditMesh *em = me->edit_btmesh;
+ const int cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP);
+
+ if (cd_fmap_offset != -1) {
+ BMFace *efa;
+ BMIter iter;
+ int *map;
+
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ map = BM_ELEM_CD_GET_VOID_P(efa, cd_fmap_offset);
+
+ if (map) {
+ if (num1 != -1) {
+ if (*map == num1)
+ *map = num2;
+ else if (*map == num2)
+ *map = num1;
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+static void object_fmap_swap_object_mode(Object *ob, int num1, int num2)
+{
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+
+ if (CustomData_has_layer(&me->pdata, CD_FACEMAP)) {
+ int *map = CustomData_get_layer(&me->pdata, CD_FACEMAP);
+ int i;
+
+ if (map) {
+ for (i = 0; i < me->totpoly; i++) {
+ if (num1 != -1) {
+ if (map[i] == num1)
+ map[i] = num2;
+ else if (map[i] == num2)
+ map[i] = num1;
+ }
+ }
+ }
+ }
+ }
+}
+
+static void object_facemap_swap(Object *ob, int num1, int num2)
+{
+ if (BKE_object_is_in_editmode(ob))
+ object_fmap_swap_edit_mode(ob, num1, num2);
+ else
+ object_fmap_swap_object_mode(ob, num1, num2);
+}
+
+static int face_map_supported_poll(bContext *C)
+{
+ Object *ob = ED_object_context(C);
+ ID *data = (ob) ? ob->data : NULL;
+ return (ob && !ob->id.lib && ob->type == OB_MESH && data && !data->lib);
+}
+
+static int face_map_supported_edit_mode_poll(bContext *C)
+{
+ Object *ob = ED_object_context(C);
+ ID *data = (ob) ? ob->data : NULL;
+ if (ob && !ob->id.lib && ob->type == OB_MESH && data && !data->lib) {
+ if (ob->mode == OB_MODE_EDIT) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static int face_map_add_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = ED_object_context(C);
+
+ BKE_object_facemap_add(ob);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_face_map_add(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add Face Map";
+ ot->idname = "OBJECT_OT_face_map_add";
+ ot->description = "Add a new face map to the active object";
+
+ /* api callbacks */
+ ot->poll = face_map_supported_poll;
+ ot->exec = face_map_add_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int face_map_remove_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = ED_object_context(C);
+ bFaceMap *fmap = BLI_findlink(&ob->fmaps, ob->actfmap - 1);
+
+ if (fmap) {
+ BKE_object_facemap_remove(ob, fmap);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+ }
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_face_map_remove(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Remove Face Map";
+ ot->idname = "OBJECT_OT_face_map_remove";
+ ot->description = "Remove a face map from the active object";
+
+ /* api callbacks */
+ ot->poll = face_map_supported_poll;
+ ot->exec = face_map_remove_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int face_map_assign_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = ED_object_context(C);
+ bFaceMap *fmap = BLI_findlink(&ob->fmaps, ob->actfmap - 1);
+
+ if (fmap) {
+ Mesh *me = ob->data;
+ BMEditMesh *em = me->edit_btmesh;
+ BMFace *efa;
+ BMIter iter;
+ int *map;
+ int cd_fmap_offset;
+
+ if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP))
+ BM_data_layer_add(em->bm, &em->bm->pdata, CD_FACEMAP);
+
+ cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP);
+
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ map = BM_ELEM_CD_GET_VOID_P(efa, cd_fmap_offset);
+
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
+ *map = ob->actfmap - 1;
+ }
+ }
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+ }
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_face_map_assign(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Assign Face Map";
+ ot->idname = "OBJECT_OT_face_map_assign";
+ ot->description = "Assign faces to a face map";
+
+ /* api callbacks */
+ ot->poll = face_map_supported_edit_mode_poll;
+ ot->exec = face_map_assign_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int face_map_remove_from_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = ED_object_context(C);
+ bFaceMap *fmap = BLI_findlink(&ob->fmaps, ob->actfmap - 1);
+
+ if (fmap) {
+ Mesh *me = ob->data;
+ BMEditMesh *em = me->edit_btmesh;
+ BMFace *efa;
+ BMIter iter;
+ int *map;
+ int cd_fmap_offset;
+ int mapindex = ob->actfmap - 1;
+
+ if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP))
+ return OPERATOR_CANCELLED;
+
+ cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP);
+
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ map = BM_ELEM_CD_GET_VOID_P(efa, cd_fmap_offset);
+
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && *map == mapindex) {
+ *map = -1;
+ }
+ }
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+ }
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_face_map_remove_from(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Remove From Face Map";
+ ot->idname = "OBJECT_OT_face_map_remove_from";
+ ot->description = "Remove faces from a face map";
+
+ /* api callbacks */
+ ot->poll = face_map_supported_edit_mode_poll;
+ ot->exec = face_map_remove_from_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static void fmap_select(Object *ob, bool select)
+{
+ Mesh *me = ob->data;
+ BMEditMesh *em = me->edit_btmesh;
+ BMFace *efa;
+ BMIter iter;
+ int *map;
+ int cd_fmap_offset;
+ int mapindex = ob->actfmap - 1;
+
+ if (!CustomData_has_layer(&em->bm->pdata, CD_FACEMAP))
+ BM_data_layer_add(em->bm, &em->bm->pdata, CD_FACEMAP);
+
+ cd_fmap_offset = CustomData_get_offset(&em->bm->pdata, CD_FACEMAP);
+
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ map = BM_ELEM_CD_GET_VOID_P(efa, cd_fmap_offset);
+
+ if (*map == mapindex) {
+ BM_face_select_set(em->bm, efa, select);
+ }
+ }
+}
+
+static int face_map_select_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = ED_object_context(C);
+ bFaceMap *fmap = BLI_findlink(&ob->fmaps, ob->actfmap - 1);
+
+ if (fmap) {
+ fmap_select(ob, true);
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+ }
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_face_map_select(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select Face Map Faces";
+ ot->idname = "OBJECT_OT_face_map_select";
+ ot->description = "Select faces belonging to a face map";
+
+ /* api callbacks */
+ ot->poll = face_map_supported_edit_mode_poll;
+ ot->exec = face_map_select_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int face_map_deselect_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Object *ob = ED_object_context(C);
+ bFaceMap *fmap = BLI_findlink(&ob->fmaps, ob->actfmap - 1);
+
+ if (fmap) {
+ fmap_select(ob, false);
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
+ }
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_face_map_deselect(struct wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Deselect Face Map Faces";
+ ot->idname = "OBJECT_OT_face_map_deselect";
+ ot->description = "Deselect faces belonging to a face map";
+
+ /* api callbacks */
+ ot->poll = face_map_supported_edit_mode_poll;
+ ot->exec = face_map_deselect_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+
+static int face_map_move_exec(bContext *C, wmOperator *op)
+{
+ Object *ob = ED_object_context(C);
+ bFaceMap *fmap;
+ int dir = RNA_enum_get(op->ptr, "direction");
+ int pos1, pos2 = -1, count;
+
+ fmap = BLI_findlink(&ob->fmaps, ob->actfmap - 1);
+ if (!fmap) {
+ return OPERATOR_CANCELLED;
+ }
+
+ count = BLI_listbase_count(&ob->fmaps);
+ pos1 = BLI_findindex(&ob->fmaps, fmap);
+
+ if (dir == 1) { /*up*/
+ void *prev = fmap->prev;
+
+ if (prev) {
+ pos2 = pos1 - 1;
+ }
+ else {
+ pos2 = count - 1;
+ }
+
+ BLI_remlink(&ob->fmaps, fmap);
+ BLI_insertlinkbefore(&ob->fmaps, prev, fmap);
+ }
+ else { /*down*/
+ void *next = fmap->next;
+
+ if (next) {
+ pos2 = pos1 + 1;
+ }
+ else {
+ pos2 = 0;
+ }
+
+ BLI_remlink(&ob->fmaps, fmap);
+ BLI_insertlinkafter(&ob->fmaps, next, fmap);
+ }
+
+ /* iterate through mesh and substitute the indices as necessary */
+ object_facemap_swap(ob, pos2, pos1);
+
+ ob->actfmap = pos2 + 1;
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob);
+
+ return OPERATOR_FINISHED;
+}
+
+
+void OBJECT_OT_face_map_move(wmOperatorType *ot)
+{
+ static EnumPropertyItem fmap_slot_move[] = {
+ {1, "UP", 0, "Up", ""},
+ {-1, "DOWN", 0, "Down", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ /* identifiers */
+ ot->name = "Move Face Map";
+ ot->idname = "OBJECT_OT_face_map_move";
+ ot->description = "Move the active face map up/down in the list";
+
+ /* api callbacks */
+ ot->poll = face_map_supported_poll;
+ ot->exec = face_map_move_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_enum(ot->srna, "direction", fmap_slot_move, 0, "Direction", "Direction to move, UP or DOWN");
+}
diff --git a/source/blender/editors/object/object_group.c b/source/blender/editors/object/object_group.c
index 46c2c4e4b7d..cb0fbdda970 100644
--- a/source/blender/editors/object/object_group.c
+++ b/source/blender/editors/object/object_group.c
@@ -40,7 +40,6 @@
#include "DNA_scene_types.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_group.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
@@ -48,6 +47,8 @@
#include "BKE_report.h"
#include "BKE_object.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_screen.h"
#include "ED_object.h"
@@ -128,7 +129,6 @@ static int objects_add_active_exec(bContext *C, wmOperator *op)
{
Object *ob = ED_object_context(C);
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
int single_group_index = RNA_enum_get(op->ptr, "group");
Group *single_group = group_object_active_find_index(ob, single_group_index);
Group *group;
@@ -151,7 +151,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op)
continue;
if (!BKE_group_object_cyclic_check(bmain, base->object, group)) {
- BKE_group_object_add(group, base->object, scene, base);
+ BKE_group_object_add(group, base->object);
updated = true;
}
else {
@@ -167,7 +167,7 @@ static int objects_add_active_exec(bContext *C, wmOperator *op)
if (!updated)
return OPERATOR_CANCELLED;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
return OPERATOR_FINISHED;
@@ -200,8 +200,8 @@ void GROUP_OT_objects_add_active(wmOperatorType *ot)
static int objects_remove_active_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
int single_group_index = RNA_enum_get(op->ptr, "group");
Group *single_group = group_object_active_find_index(ob, single_group_index);
Group *group;
@@ -221,7 +221,7 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op)
/* Remove groups from selected objects */
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
- BKE_group_object_unlink(group, base->object, scene, base);
+ BKE_group_object_unlink(group, base->object);
ok = 1;
}
CTX_DATA_END;
@@ -231,7 +231,7 @@ static int objects_remove_active_exec(bContext *C, wmOperator *op)
if (!ok)
BKE_report(op->reports, RPT_ERROR, "Active object contains no groups");
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
return OPERATOR_FINISHED;
@@ -264,15 +264,14 @@ void GROUP_OT_objects_remove_active(wmOperatorType *ot)
static int group_objects_remove_all_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
- BKE_object_groups_clear(scene, base, base->object);
+ BKE_object_groups_clear(base->object);
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
return OPERATOR_FINISHED;
@@ -297,7 +296,6 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op)
{
Object *ob = ED_object_context(C);
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
int single_group_index = RNA_enum_get(op->ptr, "group");
Group *single_group = group_object_active_find_index(ob, single_group_index);
Group *group;
@@ -315,7 +313,7 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op)
/* now remove all selected objects from the group */
CTX_DATA_BEGIN (C, Base *, base, selected_editable_bases)
{
- BKE_group_object_unlink(group, base->object, scene, base);
+ BKE_group_object_unlink(group, base->object);
updated = true;
}
CTX_DATA_END;
@@ -324,7 +322,7 @@ static int group_objects_remove_exec(bContext *C, wmOperator *op)
if (!updated)
return OPERATOR_CANCELLED;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
return OPERATOR_FINISHED;
@@ -357,7 +355,6 @@ void GROUP_OT_objects_remove(wmOperatorType *ot)
static int group_create_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
Group *group = NULL;
char name[MAX_ID_NAME - 2]; /* id name */
@@ -367,11 +364,11 @@ static int group_create_exec(bContext *C, wmOperator *op)
CTX_DATA_BEGIN (C, Base *, base, selected_bases)
{
- BKE_group_object_add(group, base->object, scene, base);
+ BKE_group_object_add(group, base->object);
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_GROUP | NA_EDITED, NULL);
return OPERATOR_FINISHED;
@@ -398,7 +395,6 @@ void GROUP_OT_create(wmOperatorType *ot)
static int group_add_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
Object *ob = ED_object_context(C);
Main *bmain = CTX_data_main(C);
Group *group;
@@ -407,7 +403,7 @@ static int group_add_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED;
group = BKE_group_add(bmain, "Group");
- BKE_group_object_add(group, ob, scene, NULL);
+ BKE_group_object_add(group, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -432,7 +428,6 @@ void OBJECT_OT_group_add(wmOperatorType *ot)
static int group_link_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
Object *ob = ED_object_context(C);
Group *group = BLI_findlink(&bmain->group, RNA_enum_get(op->ptr, "group"));
@@ -457,7 +452,7 @@ static int group_link_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- BKE_group_object_add(group, ob, scene, NULL);
+ BKE_group_object_add(group, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -490,14 +485,13 @@ void OBJECT_OT_group_link(wmOperatorType *ot)
static int group_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
Object *ob = ED_object_context(C);
Group *group = CTX_data_pointer_get_type(C, "group", &RNA_Group).data;
if (!ob || !group)
return OPERATOR_CANCELLED;
- BKE_group_object_unlink(group, ob, scene, NULL); /* base will be used if found */
+ BKE_group_object_unlink(group, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -559,8 +553,10 @@ static int select_grouped_exec(bContext *C, wmOperator *UNUSED(op)) /* Select o
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if (!(base->flag & SELECT) && BKE_group_object_exists(group, base->object)) {
- ED_base_object_select(base, BA_SELECT);
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+ if (BKE_group_object_exists(group, base->object)) {
+ ED_object_base_select(base, BA_SELECT);
+ }
}
}
CTX_DATA_END;
diff --git a/source/blender/editors/object/object_hook.c b/source/blender/editors/object/object_hook.c
index e9203fa1972..b5a71bb7a35 100644
--- a/source/blender/editors/object/object_hook.c
+++ b/source/blender/editors/object/object_hook.c
@@ -48,7 +48,7 @@
#include "BKE_action.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
@@ -57,6 +57,9 @@
#include "BKE_deform.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RNA_define.h"
#include "RNA_access.h"
#include "RNA_enum_types.h"
@@ -318,7 +321,7 @@ static bool object_hook_index_array(Scene *scene, Object *obedit,
EDBM_mesh_load(obedit);
EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
em = me->edit_btmesh;
@@ -445,26 +448,26 @@ static int hook_op_edit_poll(bContext *C)
return 0;
}
-static Object *add_hook_object_new(Main *bmain, Scene *scene, Object *obedit)
+static Object *add_hook_object_new(Main *bmain, Scene *scene, ViewLayer *view_layer, Object *obedit)
{
Base *base, *basedit;
Object *ob;
- ob = BKE_object_add(bmain, scene, OB_EMPTY, NULL);
+ ob = BKE_object_add(bmain, scene, view_layer, OB_EMPTY, NULL);
- basedit = BKE_scene_base_find(scene, obedit);
- base = scene->basact;
+ basedit = BKE_view_layer_base_find(view_layer, obedit);
+ base = view_layer->basact;
base->lay = ob->lay = obedit->lay;
- BLI_assert(scene->basact->object == ob);
+ BLI_assert(view_layer->basact->object == ob);
/* icky, BKE_object_add sets new base as active.
* so set it back to the original edit object */
- scene->basact = basedit;
+ view_layer->basact = basedit;
return ob;
}
-static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob, int mode, ReportList *reports)
+static int add_hook_object(const bContext *C, Main *bmain, Scene *scene, ViewLayer *view_layer, Object *obedit, Object *ob, int mode, ReportList *reports)
{
ModifierData *md = NULL;
HookModifierData *hmd = NULL;
@@ -482,7 +485,7 @@ static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob
if (mode == OBJECT_ADDHOOK_NEWOB && !ob) {
- ob = add_hook_object_new(bmain, scene, obedit);
+ ob = add_hook_object_new(bmain, scene, view_layer, obedit);
/* transform cent to global coords for loc */
mul_v3_m4v3(ob->loc, obedit->obmat, cent);
@@ -541,13 +544,13 @@ static int add_hook_object(Main *bmain, Scene *scene, Object *obedit, Object *ob
/* matrix calculus */
/* vert x (obmat x hook->imat) x hook->obmat x ob->imat */
/* (parentinv ) */
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(CTX_data_depsgraph(C), scene, ob);
invert_m4_m4(ob->imat, ob->obmat);
/* apparently this call goes from right to left... */
mul_m4_series(hmd->parentinv, pose_mat, ob->imat, obedit->obmat);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
return true;
}
@@ -556,6 +559,7 @@ static int object_add_hook_selob_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
Object *obsel = NULL;
const bool use_bone = RNA_boolean_get(op->ptr, "use_bone");
@@ -580,7 +584,7 @@ static int object_add_hook_selob_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- if (add_hook_object(bmain, scene, obedit, obsel, mode, op->reports)) {
+ if (add_hook_object(C, bmain, scene, view_layer, obedit, obsel, mode, op->reports)) {
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit);
return OPERATOR_FINISHED;
}
@@ -611,9 +615,10 @@ static int object_add_hook_newob_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
- if (add_hook_object(bmain, scene, obedit, NULL, OBJECT_ADDHOOK_NEWOB, op->reports)) {
+ if (add_hook_object(C, bmain, scene, view_layer, obedit, NULL, OBJECT_ADDHOOK_NEWOB, op->reports)) {
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obedit);
return OPERATOR_FINISHED;
@@ -655,7 +660,7 @@ static int object_hook_remove_exec(bContext *C, wmOperator *op)
BLI_remlink(&ob->modifiers, (ModifierData *)hmd);
modifier_free((ModifierData *)hmd);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -729,7 +734,7 @@ static int object_hook_reset_exec(bContext *C, wmOperator *op)
BKE_object_modifier_hook_reset(ob, hmd);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -779,7 +784,7 @@ static int object_hook_recenter_exec(bContext *C, wmOperator *op)
sub_v3_v3v3(hmd->cent, scene->cursor, ob->obmat[3]);
mul_m3_v3(imat, hmd->cent);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -837,7 +842,7 @@ static int object_hook_assign_exec(bContext *C, wmOperator *op)
hmd->indexar = indexar;
hmd->totindex = tot;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/object/object_intern.h b/source/blender/editors/object/object_intern.h
index d9524f40a3c..dbb81be124a 100644
--- a/source/blender/editors/object/object_intern.h
+++ b/source/blender/editors/object/object_intern.h
@@ -55,6 +55,7 @@ void OBJECT_OT_scale_clear(struct wmOperatorType *ot);
void OBJECT_OT_origin_clear(struct wmOperatorType *ot);
void OBJECT_OT_visual_transform_apply(struct wmOperatorType *ot);
void OBJECT_OT_transform_apply(struct wmOperatorType *ot);
+void OBJECT_OT_transform_axis_target(struct wmOperatorType *ot);
void OBJECT_OT_origin_set(struct wmOperatorType *ot);
/* object_relations.c */
@@ -67,10 +68,10 @@ void OBJECT_OT_track_clear(struct wmOperatorType *ot);
void OBJECT_OT_slow_parent_set(struct wmOperatorType *ot);
void OBJECT_OT_slow_parent_clear(struct wmOperatorType *ot);
void OBJECT_OT_make_local(struct wmOperatorType *ot);
+void OBJECT_OT_make_override_static(struct wmOperatorType *ot);
void OBJECT_OT_make_single_user(struct wmOperatorType *ot);
void OBJECT_OT_make_links_scene(struct wmOperatorType *ot);
void OBJECT_OT_make_links_data(struct wmOperatorType *ot);
-void OBJECT_OT_move_to_layer(struct wmOperatorType *ot);
void OBJECT_OT_drop_named_material(struct wmOperatorType *ot);
void OBJECT_OT_unlink_data(struct wmOperatorType *ot);
@@ -78,10 +79,6 @@ void OBJECT_OT_unlink_data(struct wmOperatorType *ot);
void OBJECT_OT_mode_set(struct wmOperatorType *ot);
void OBJECT_OT_editmode_toggle(struct wmOperatorType *ot);
void OBJECT_OT_posemode_toggle(struct wmOperatorType *ot);
-void OBJECT_OT_hide_view_set(struct wmOperatorType *ot);
-void OBJECT_OT_hide_view_clear(struct wmOperatorType *ot);
-void OBJECT_OT_hide_render_set(struct wmOperatorType *ot);
-void OBJECT_OT_hide_render_clear(struct wmOperatorType *ot);
void OBJECT_OT_proxy_make(struct wmOperatorType *ot);
void OBJECT_OT_shade_smooth(struct wmOperatorType *ot);
void OBJECT_OT_shade_flat(struct wmOperatorType *ot);
@@ -90,13 +87,7 @@ void OBJECT_OT_paths_update(struct wmOperatorType *ot);
void OBJECT_OT_paths_clear(struct wmOperatorType *ot);
void OBJECT_OT_forcefield_toggle(struct wmOperatorType *ot);
-void OBJECT_OT_game_property_new(struct wmOperatorType *ot);
-void OBJECT_OT_game_property_remove(struct wmOperatorType *ot);
-void OBJECT_OT_game_property_copy(struct wmOperatorType *ot);
-void OBJECT_OT_game_property_clear(struct wmOperatorType *ot);
-void OBJECT_OT_game_property_move(struct wmOperatorType *ot);
-void OBJECT_OT_logic_bricks_copy(struct wmOperatorType *ot);
-void OBJECT_OT_game_physics_copy(struct wmOperatorType *ot);
+void OBJECT_OT_move_to_collection(struct wmOperatorType *ot);
/* object_select.c */
void OBJECT_OT_select_all(struct wmOperatorType *ot);
@@ -109,6 +100,7 @@ void OBJECT_OT_select_mirror(struct wmOperatorType *ot);
void OBJECT_OT_select_more(struct wmOperatorType *ot);
void OBJECT_OT_select_less(struct wmOperatorType *ot);
void OBJECT_OT_select_same_group(struct wmOperatorType *ot);
+void OBJECT_OT_select_same_collection(struct wmOperatorType *ot);
/* object_add.c */
void OBJECT_OT_add(struct wmOperatorType *ot);
@@ -117,6 +109,7 @@ void OBJECT_OT_metaball_add(struct wmOperatorType *ot);
void OBJECT_OT_text_add(struct wmOperatorType *ot);
void OBJECT_OT_armature_add(struct wmOperatorType *ot);
void OBJECT_OT_empty_add(struct wmOperatorType *ot);
+void OBJECT_OT_lightprobe_add(struct wmOperatorType *ot);
void OBJECT_OT_drop_named_image(struct wmOperatorType *ot);
void OBJECT_OT_lamp_add(struct wmOperatorType *ot);
void OBJECT_OT_effector_add(struct wmOperatorType *ot);
@@ -237,6 +230,15 @@ void OBJECT_OT_vertex_weight_set_active(struct wmOperatorType *ot);
void OBJECT_OT_vertex_weight_normalize_active_vertex(struct wmOperatorType *ot);
void OBJECT_OT_vertex_weight_copy(struct wmOperatorType *ot);
+/* object_facemap_ops.c */
+void OBJECT_OT_face_map_add(struct wmOperatorType *ot);
+void OBJECT_OT_face_map_remove(struct wmOperatorType *ot);
+void OBJECT_OT_face_map_assign(struct wmOperatorType *ot);
+void OBJECT_OT_face_map_remove_from(struct wmOperatorType *ot);
+void OBJECT_OT_face_map_select(struct wmOperatorType *ot);
+void OBJECT_OT_face_map_deselect(struct wmOperatorType *ot);
+void OBJECT_OT_face_map_move(struct wmOperatorType *ot);
+
/* object_warp.c */
void TRANSFORM_OT_vertex_warp(struct wmOperatorType *ot);
@@ -259,10 +261,6 @@ void OBJECT_OT_grouped_select(struct wmOperatorType *ot);
void OBJECT_OT_bake_image(wmOperatorType *ot);
void OBJECT_OT_bake(wmOperatorType *ot);
-/* object_lod.c */
-void OBJECT_OT_lod_add(struct wmOperatorType *ot);
-void OBJECT_OT_lod_remove(struct wmOperatorType *ot);
-
/* object_random.c */
void TRANSFORM_OT_vertex_random(struct wmOperatorType *ot);
diff --git a/source/blender/editors/object/object_lod.c b/source/blender/editors/object/object_lod.c
deleted file mode 100644
index ced306178b8..00000000000
--- a/source/blender/editors/object/object_lod.c
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/object/object_lod.c
- * \ingroup edobj
- */
-
-#include "DNA_object_types.h"
-
-#include "BKE_context.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "RNA_access.h"
-#include "RNA_define.h"
-
-#include "ED_screen.h"
-#include "ED_object.h"
-
-#ifdef WITH_GAMEENGINE
-# include "BKE_object.h"
-
-# include "RNA_enum_types.h"
-#endif
-
-#include "object_intern.h"
-
-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;
-}
-
-void OBJECT_OT_lod_add(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Add Level of Detail";
- ot->description = "Add a level of detail to this object";
- ot->idname = "OBJECT_OT_lod_add";
-
- /* api callbacks */
- ot->exec = object_lod_add_exec;
- ot->poll = ED_operator_object_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-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;
-}
-
-void OBJECT_OT_lod_remove(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Remove Level of Detail";
- ot->description = "Remove a level of detail from this object";
- ot->idname = "OBJECT_OT_lod_remove";
-
- /* api callbacks */
- ot->exec = object_lod_remove_exec;
- ot->poll = ED_operator_object_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- ot->prop = RNA_def_int(ot->srna, "index", 1, 1, INT_MAX, "Index", "", 1, INT_MAX);
-}
diff --git a/source/blender/editors/object/object_modes.c b/source/blender/editors/object/object_modes.c
index d70a69e30f8..3fb0e75a01e 100644
--- a/source/blender/editors/object/object_modes.c
+++ b/source/blender/editors/object/object_modes.c
@@ -29,16 +29,30 @@
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
+#include "BKE_object.h"
+#include "BKE_paint.h"
#include "BKE_report.h"
#include "WM_api.h"
#include "WM_types.h"
-#include "ED_object.h"
+#include "RNA_access.h"
+
+#include "DEG_depsgraph.h"
+
+#include "ED_screen.h"
+
+#include "ED_object.h" /* own include */
+
+/* -------------------------------------------------------------------- */
+/** \name High Level Mode Operations
+ *
+ * \{ */
static const char *object_mode_op_string(eObjectMode mode)
{
@@ -102,7 +116,6 @@ bool ED_object_mode_compat_test(const Object *ob, eObjectMode mode)
return false;
}
-
/**
* Sets the mode to a compatible state (use before entering the mode).
*
@@ -113,6 +126,7 @@ bool ED_object_mode_compat_set(bContext *C, Object *ob, eObjectMode mode, Report
bool ok;
if (!ELEM(ob->mode, mode, OB_MODE_OBJECT)) {
const char *opstring = object_mode_op_string(ob->mode);
+
WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
ok = ELEM(ob->mode, mode, OB_MODE_OBJECT);
if (!ok) {
@@ -131,48 +145,116 @@ void ED_object_mode_toggle(bContext *C, eObjectMode mode)
{
if (mode != OB_MODE_OBJECT) {
const char *opstring = object_mode_op_string(mode);
+
if (opstring) {
WM_operator_name_call(C, opstring, WM_OP_EXEC_REGION_WIN, NULL);
}
}
}
+
/* Wrapper for operator */
void ED_object_mode_set(bContext *C, eObjectMode mode)
{
-#if 0
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wm->op_undo_depth++;
+ /* needed so we don't do undo pushes. */
+ ED_object_mode_generic_enter(C, mode);
+ wm->op_undo_depth--;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Generic Mode Enter/Exit
+ *
+ * Supports exiting a mode without it being in the current context.
+ * This could be done for entering modes too if it's needed.
+ *
+ * \{ */
+
+bool ED_object_mode_generic_enter(
+ struct bContext *C, eObjectMode object_mode)
+{
+ Object *ob = CTX_data_active_object(C);
+ if (ob == NULL) {
+ return (object_mode == OB_MODE_OBJECT);
+ }
+ if (ob->mode == object_mode) {
+ return true;
+ }
wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_mode_set", false);
PointerRNA ptr;
-
WM_operator_properties_create_ptr(&ptr, ot);
- RNA_enum_set(&ptr, "mode", mode);
- RNA_boolean_set(&ptr, "toggle", false);
- WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &ptr);
+ RNA_enum_set(&ptr, "mode", object_mode);
+ WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &ptr);
WM_operator_properties_free(&ptr);
-#else
- Object *ob = CTX_data_active_object(C);
- if (ob == NULL) {
- return;
+ return (ob->mode == object_mode);
+}
+
+/**
+ * Use for changing works-paces or changing active object.
+ * Caller can check #OB_MODE_ALL_MODE_DATA to test if this needs to be run.
+ */
+static bool ed_object_mode_generic_exit_ex(
+ struct Depsgraph *depsgraph,
+ struct Scene *scene, struct Object *ob,
+ bool only_test)
+{
+ if (ob->mode & OB_MODE_EDIT) {
+ if (BKE_object_is_in_editmode(ob)) {
+ if (only_test) {
+ return true;
+ }
+ ED_object_editmode_exit_ex(NULL, scene, ob, EM_FREEDATA);
+ }
}
- if (ob->mode == mode) {
- /* pass */
+ else if (ob->mode & OB_MODE_VERTEX_PAINT) {
+ if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_VERTEX_PAINT)) {
+ if (only_test) {
+ return true;
+ }
+ ED_object_vpaintmode_exit_ex(ob);
+ }
}
- else if (mode != OB_MODE_OBJECT) {
- if (ob && (ob->mode & mode) == 0) {
- /* needed so we don't do undo pushes. */
- wmWindowManager *wm = CTX_wm_manager(C);
- wm->op_undo_depth++;
- ED_object_mode_toggle(C, mode);
- wm->op_undo_depth--;
+ else if (ob->mode & OB_MODE_WEIGHT_PAINT) {
+ if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_WEIGHT_PAINT)) {
+ if (only_test) {
+ return true;
+ }
+ ED_object_wpaintmode_exit_ex(ob);
+ }
+ }
+ else if (ob->mode & OB_MODE_SCULPT) {
+ if (ob->sculpt && (ob->sculpt->mode_type == OB_MODE_SCULPT)) {
+ if (only_test) {
+ return true;
+ }
+ ED_object_sculptmode_exit_ex(depsgraph, scene, ob);
}
}
else {
- /* needed so we don't do undo pushes. */
- wmWindowManager *wm = CTX_wm_manager(C);
- wm->op_undo_depth++;
- ED_object_mode_toggle(C, ob->mode);
- wm->op_undo_depth--;
-
+ if (only_test) {
+ return false;
+ }
+ BLI_assert((ob->mode & OB_MODE_ALL_MODE_DATA) == 0);
}
-#endif
+
+ return false;
+}
+
+void ED_object_mode_generic_exit(
+ struct Depsgraph *depsgraph,
+ struct Scene *scene, struct Object *ob)
+{
+ ed_object_mode_generic_exit_ex(depsgraph, scene, ob, false);
}
+
+bool ED_object_mode_generic_has_data(
+ struct Depsgraph *depsgraph,
+ struct Object *ob)
+{
+ return ed_object_mode_generic_exit_ex(depsgraph, NULL, ob, true);
+}
+
+/** \} */
diff --git a/source/blender/editors/object/object_modifier.c b/source/blender/editors/object/object_modifier.c
index bf99d1c52ac..dd04a730542 100644
--- a/source/blender/editors/object/object_modifier.c
+++ b/source/blender/editors/object/object_modifier.c
@@ -54,7 +54,6 @@
#include "BKE_animsys.h"
#include "BKE_curve.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_displist.h"
#include "BKE_DerivedMesh.h"
#include "BKE_effect.h"
@@ -75,6 +74,10 @@
#include "BKE_softbody.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -171,8 +174,8 @@ ModifierData *ED_object_modifier_add(ReportList *reports, Main *bmain, Scene *sc
}
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- DAG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
return new_md;
}
@@ -253,7 +256,7 @@ bool ED_object_multires_update_totlevels_cb(Object *ob, void *totlevel_v)
for (md = ob->modifiers.first; md; md = md->next) {
if (md->type == eModifierType_Multires) {
multires_set_tot_level(ob, (MultiresModifierData *)md, totlevel);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
return false;
@@ -320,7 +323,7 @@ static bool object_modifier_remove(Main *bmain, Object *ob, ModifierData *md,
ob->mode &= ~OB_MODE_PARTICLE_EDIT;
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
BLI_remlink(&ob->modifiers, md);
modifier_free(md);
@@ -341,8 +344,8 @@ bool ED_object_modifier_remove(ReportList *reports, Main *bmain, Object *ob, Mod
return 0;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- DAG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
return 1;
}
@@ -365,8 +368,8 @@ void ED_object_modifier_clear(Main *bmain, Object *ob)
md = next_md;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- DAG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
}
int ED_object_modifier_move_up(ReportList *reports, Object *ob, ModifierData *md)
@@ -411,7 +414,7 @@ int ED_object_modifier_move_down(ReportList *reports, Object *ob, ModifierData *
return 1;
}
-int ED_object_modifier_convert(ReportList *UNUSED(reports), Main *bmain, Scene *scene, Object *ob, ModifierData *md)
+int ED_object_modifier_convert(ReportList *UNUSED(reports), Main *bmain, Scene *scene, ViewLayer *view_layer, Object *ob, ModifierData *md)
{
Object *obn;
ParticleSystem *psys;
@@ -463,7 +466,7 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), Main *bmain, Scene *
if (totvert == 0) return 0;
/* add new mesh */
- obn = BKE_object_add(bmain, scene, OB_MESH, NULL);
+ obn = BKE_object_add(bmain, scene, view_layer, OB_MESH, NULL);
me = obn->data;
me->totvert = totvert;
@@ -515,12 +518,12 @@ int ED_object_modifier_convert(ReportList *UNUSED(reports), Main *bmain, Scene *
}
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
return 1;
}
-static int modifier_apply_shape(ReportList *reports, Scene *scene, Object *ob, ModifierData *md)
+static int modifier_apply_shape(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
@@ -553,7 +556,7 @@ static int modifier_apply_shape(ReportList *reports, Scene *scene, Object *ob, M
return 0;
}
- dm = mesh_create_derived_for_modifier(scene, ob, md, 0);
+ dm = mesh_create_derived_for_modifier(depsgraph, scene, ob, md, 0);
if (!dm) {
BKE_report(reports, RPT_ERROR, "Modifier is disabled or returned error, skipping apply");
return 0;
@@ -580,7 +583,7 @@ static int modifier_apply_shape(ReportList *reports, Scene *scene, Object *ob, M
return 1;
}
-static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob, ModifierData *md)
+static int modifier_apply_obdata(ReportList *reports, Depsgraph *depsgraph, Scene *scene, Object *ob, ModifierData *md)
{
const ModifierTypeInfo *mti = modifierType_getInfo(md->type);
@@ -606,13 +609,13 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob,
multires_force_update(ob);
if (mmd && mmd->totlvl && mti->type == eModifierTypeType_OnlyDeform) {
- if (!multiresModifier_reshapeFromDeformMod(scene, mmd, ob, md)) {
+ if (!multiresModifier_reshapeFromDeformMod(depsgraph, scene, mmd, ob, md)) {
BKE_report(reports, RPT_ERROR, "Multires modifier returned error, skipping apply");
return 0;
}
}
else {
- dm = mesh_create_derived_for_modifier(scene, ob, md, 1);
+ dm = mesh_create_derived_for_modifier(depsgraph, scene, ob, md, 1);
if (!dm) {
BKE_report(reports, RPT_ERROR, "Modifier returned error, skipping apply");
return 0;
@@ -628,6 +631,7 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob,
Curve *cu;
int numVerts;
float (*vertexCos)[3];
+ ModifierEvalContext mectx = {depsgraph, ob, 0};
if (ELEM(mti->type, eModifierTypeType_Constructive, eModifierTypeType_Nonconstructive)) {
BKE_report(reports, RPT_ERROR, "Cannot apply constructive modifiers on curve");
@@ -638,12 +642,12 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob,
BKE_report(reports, RPT_INFO, "Applied modifier only changed CV points, not tessellated/bevel vertices");
vertexCos = BKE_curve_nurbs_vertexCos_get(&cu->nurb, &numVerts);
- mti->deformVerts(md, ob, NULL, vertexCos, numVerts, 0);
+ modifier_deformVerts_DM_deprecated(md, &mectx, NULL, vertexCos, numVerts);
BK_curve_nurbs_vertexCos_apply(&cu->nurb, vertexCos);
MEM_freeN(vertexCos);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
else {
BKE_report(reports, RPT_ERROR, "Cannot apply modifier for this object type");
@@ -660,18 +664,20 @@ static int modifier_apply_obdata(ReportList *reports, Scene *scene, Object *ob,
if (psys->part->type != PART_HAIR)
continue;
- psys_apply_hair_lattice(scene, ob, psys);
+ psys_apply_hair_lattice(depsgraph, scene, ob, psys);
}
}
return 1;
}
-int ED_object_modifier_apply(ReportList *reports, Scene *scene, Object *ob, ModifierData *md, int mode)
+int ED_object_modifier_apply(
+ ReportList *reports, Depsgraph *depsgraph,
+ Scene *scene, Object *ob, ModifierData *md, int mode)
{
int prev_mode;
- if (scene->obedit) {
+ if (BKE_object_is_in_editmode(ob)) {
BKE_report(reports, RPT_ERROR, "Modifiers cannot be applied in edit mode");
return 0;
}
@@ -695,13 +701,13 @@ int ED_object_modifier_apply(ReportList *reports, Scene *scene, Object *ob, Modi
md->mode |= eModifierMode_Realtime;
if (mode == MODIFIER_APPLY_SHAPE) {
- if (!modifier_apply_shape(reports, scene, ob, md)) {
+ if (!modifier_apply_shape(reports, depsgraph, scene, ob, md)) {
md->mode = prev_mode;
return 0;
}
}
else {
- if (!modifier_apply_obdata(reports, scene, ob, md)) {
+ if (!modifier_apply_obdata(reports, depsgraph, scene, ob, md)) {
md->mode = prev_mode;
return 0;
}
@@ -819,9 +825,19 @@ int edit_modifier_poll_generic(bContext *C, StructRNA *rna_type, int obtype_flag
PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", rna_type);
Object *ob = (ptr.id.data) ? ptr.id.data : ED_object_active_context(C);
+ if (!ptr.data) {
+ CTX_wm_operator_poll_msg_set(C, "Context missing 'modifier'");
+ return 0;
+ }
+
if (!ob || ID_IS_LINKED(ob)) return 0;
if (obtype_flag && ((1 << ob->type) & obtype_flag) == 0) return 0;
if (ptr.id.data && ID_IS_LINKED(ptr.id.data)) return 0;
+
+ if (ID_IS_STATIC_OVERRIDE(ob)) {
+ CTX_wm_operator_poll_msg_set(C, "Cannot edit modifiers comming from static override");
+ return (((ModifierData *)ptr.data)->flag & eModifierFlag_StaticOverride_Local) != 0;
+ }
return 1;
}
@@ -874,7 +890,7 @@ ModifierData *edit_modifier_property_get(wmOperator *op, Object *ob, int type)
static int modifier_remove_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = ED_object_active_context(C);
ModifierData *md = edit_modifier_property_get(op, ob, 0);
int mode_orig = ob->mode;
@@ -885,11 +901,13 @@ static int modifier_remove_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
/* if cloth/softbody was removed, particle mode could be cleared */
- if (mode_orig & OB_MODE_PARTICLE_EDIT)
- if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0)
- if (scene->basact && scene->basact->object == ob)
+ if (mode_orig & OB_MODE_PARTICLE_EDIT) {
+ if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) {
+ if (ob == OBACT(view_layer)) {
WM_event_add_notifier(C, NC_SCENE | ND_MODE | NS_MODE_OBJECT, NULL);
-
+ }
+ }
+ }
return OPERATOR_FINISHED;
}
@@ -926,7 +944,7 @@ static int modifier_move_up_exec(bContext *C, wmOperator *op)
if (!md || !ED_object_modifier_move_up(op->reports, ob, md))
return OPERATOR_CANCELLED;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -965,7 +983,7 @@ static int modifier_move_down_exec(bContext *C, wmOperator *op)
if (!md || !ED_object_modifier_move_down(op->reports, ob, md))
return OPERATOR_CANCELLED;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -998,16 +1016,17 @@ void OBJECT_OT_modifier_move_down(wmOperatorType *ot)
static int modifier_apply_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = ED_object_active_context(C);
ModifierData *md = edit_modifier_property_get(op, ob, 0);
int apply_as = RNA_enum_get(op->ptr, "apply_as");
- if (!md || !ED_object_modifier_apply(op->reports, scene, ob, md, apply_as)) {
+ if (!md || !ED_object_modifier_apply(op->reports, depsgraph, scene, ob, md, apply_as)) {
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1050,13 +1069,14 @@ static int modifier_convert_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob = ED_object_active_context(C);
ModifierData *md = edit_modifier_property_get(op, ob, 0);
- if (!md || !ED_object_modifier_convert(op->reports, bmain, scene, ob, md))
+ if (!md || !ED_object_modifier_convert(op->reports, bmain, scene, view_layer, ob, md))
return OPERATOR_CANCELLED;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1095,7 +1115,7 @@ static int modifier_copy_exec(bContext *C, wmOperator *op)
if (!md || !ED_object_modifier_copy(op->reports, ob, md))
return OPERATOR_CANCELLED;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1189,7 +1209,7 @@ static int multires_subdivide_exec(bContext *C, wmOperator *op)
ED_object_multires_update_totlevels_cb,
&mmd->totlvl);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
if (ob->mode & OB_MODE_SCULPT) {
@@ -1227,6 +1247,7 @@ void OBJECT_OT_multires_subdivide(wmOperatorType *ot)
static int multires_reshape_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Object *ob = ED_object_active_context(C), *secondob = NULL;
Scene *scene = CTX_data_scene(C);
MultiresModifierData *mmd = (MultiresModifierData *)edit_modifier_property_get(op, ob, eModifierType_Multires);
@@ -1253,12 +1274,12 @@ static int multires_reshape_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- if (!multiresModifier_reshape(scene, mmd, ob, secondob)) {
+ if (!multiresModifier_reshape(depsgraph, scene, mmd, ob, secondob)) {
BKE_report(op->reports, RPT_ERROR, "Objects do not have the same number of vertices");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1406,7 +1427,7 @@ static int multires_base_apply_exec(bContext *C, wmOperator *op)
multiresModifier_base_apply(mmd, ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1512,7 +1533,7 @@ static int skin_root_mark_exec(bContext *C, wmOperator *UNUSED(op))
BLI_gset_free(visited, NULL);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1567,7 +1588,7 @@ static int skin_loose_mark_clear_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1617,7 +1638,7 @@ static int skin_radii_equalize_exec(bContext *C, wmOperator *UNUSED(op))
}
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1686,7 +1707,7 @@ static void skin_armature_bone_create(Object *skin_ob,
}
}
-static Object *modifier_skin_armature_create(Main *bmain, Scene *scene, Object *skin_ob)
+static Object *modifier_skin_armature_create(Depsgraph *depsgraph, Main *bmain, Scene *scene, Object *skin_ob)
{
BLI_bitmap *edges_visited;
DerivedMesh *deform_dm;
@@ -1699,7 +1720,7 @@ static Object *modifier_skin_armature_create(Main *bmain, Scene *scene, Object *
int *emap_mem;
int v;
- deform_dm = mesh_get_derived_deform(scene, skin_ob, CD_MASK_BAREMESH);
+ deform_dm = mesh_get_derived_deform(depsgraph, scene, skin_ob, CD_MASK_BAREMESH);
mvert = deform_dm->getVertArray(deform_dm);
/* add vertex weights to original mesh */
@@ -1709,7 +1730,8 @@ static Object *modifier_skin_armature_create(Main *bmain, Scene *scene, Object *
NULL,
me->totvert);
- arm_ob = BKE_object_add(bmain, scene, OB_ARMATURE, NULL);
+ ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
+ arm_ob = BKE_object_add(bmain, scene, view_layer, OB_ARMATURE, NULL);
BKE_object_transform_copy(arm_ob, skin_ob);
arm = arm_ob->data;
arm->layer = 1;
@@ -1767,6 +1789,7 @@ static Object *modifier_skin_armature_create(Main *bmain, Scene *scene, Object *
static int skin_armature_create_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C), *arm_ob;
Mesh *me = ob->data;
@@ -1779,7 +1802,7 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op)
}
/* create new armature */
- arm_ob = modifier_skin_armature_create(bmain, scene, ob);
+ arm_ob = modifier_skin_armature_create(depsgraph, bmain, scene, ob);
/* add a modifier to connect the new armature to the mesh */
arm_md = (ArmatureModifierData *)modifier_new(eModifierType_Armature);
@@ -1789,8 +1812,8 @@ static int skin_armature_create_exec(bContext *C, wmOperator *op)
arm_md->object = arm_ob;
arm_md->deformflag = ARM_DEF_VGROUP | ARM_DEF_QUATERNION;
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
@@ -1857,7 +1880,7 @@ static int correctivesmooth_bind_exec(bContext *C, wmOperator *op)
csmd->bind_coords_num = (unsigned int)-1;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -1899,6 +1922,7 @@ static int meshdeform_bind_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
Object *ob = ED_object_active_context(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
MeshDeformModifierData *mmd = (MeshDeformModifierData *)edit_modifier_property_get(op, ob, eModifierType_MeshDeform);
if (!mmd)
@@ -1926,7 +1950,7 @@ static int meshdeform_bind_exec(bContext *C, wmOperator *op)
mmd->totcagevert = 0;
mmd->totinfluence = 0;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
}
else {
@@ -1938,17 +1962,17 @@ static int meshdeform_bind_exec(bContext *C, wmOperator *op)
mmd->modifier.mode |= eModifierMode_Realtime;
if (ob->type == OB_MESH) {
- dm = mesh_create_derived_view(scene, ob, 0);
+ dm = mesh_create_derived_view(depsgraph, scene, ob, 0);
dm->release(dm);
}
else if (ob->type == OB_LATTICE) {
- BKE_lattice_modifiers_calc(scene, ob);
+ BKE_lattice_modifiers_calc(depsgraph, scene, ob);
}
else if (ob->type == OB_MBALL) {
- BKE_displist_make_mball(CTX_data_main(C)->eval_ctx, scene, ob);
+ BKE_displist_make_mball(depsgraph, scene, ob);
}
else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
- BKE_displist_make_curveTypes(scene, ob, 0);
+ BKE_displist_make_curveTypes(depsgraph, scene, ob, 0);
}
mmd->bindfunc = NULL;
@@ -2000,7 +2024,7 @@ static int explode_refresh_exec(bContext *C, wmOperator *op)
emd->flag |= eExplodeFlag_CalcFaces;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
@@ -2145,7 +2169,7 @@ static int ocean_bake_exec(bContext *C, wmOperator *op)
if (free) {
omd->refresh |= MOD_OCEAN_REFRESH_CLEAR_CACHE;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
}
@@ -2173,7 +2197,7 @@ static int ocean_bake_exec(bContext *C, wmOperator *op)
* this part of the process before a threaded job is created */
//scene->r.cfra = f;
- //ED_update_for_newframe(CTX_data_main(C), scene, 1);
+ //ED_update_for_newframe(CTX_data_main(C), scene);
/* ok, this doesn't work with drivers, but is way faster.
* let's use this for now and hope nobody wants to drive the time value... */
@@ -2195,7 +2219,7 @@ static int ocean_bake_exec(bContext *C, wmOperator *op)
scene->r.cfra = cfra;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
#endif
@@ -2268,7 +2292,7 @@ static int laplaciandeform_bind_exec(bContext *C, wmOperator *op)
else {
lmd->flag |= MOD_LAPLACIANDEFORM_BIND;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
}
@@ -2320,7 +2344,7 @@ static int surfacedeform_bind_exec(bContext *C, wmOperator *op)
smd->flags |= MOD_SDEF_BIND;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/object/object_ops.c b/source/blender/editors/object/object_ops.c
index c090b8684d0..c4c86b3932d 100644
--- a/source/blender/editors/object/object_ops.c
+++ b/source/blender/editors/object/object_ops.c
@@ -47,6 +47,8 @@
#include "ED_screen.h"
#include "ED_object.h"
+#include "DEG_depsgraph.h"
+
#include "object_intern.h"
@@ -61,16 +63,13 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_origin_clear);
WM_operatortype_append(OBJECT_OT_visual_transform_apply);
WM_operatortype_append(OBJECT_OT_transform_apply);
+ WM_operatortype_append(OBJECT_OT_transform_axis_target);
WM_operatortype_append(OBJECT_OT_origin_set);
WM_operatortype_append(OBJECT_OT_mode_set);
WM_operatortype_append(OBJECT_OT_editmode_toggle);
WM_operatortype_append(OBJECT_OT_posemode_toggle);
WM_operatortype_append(OBJECT_OT_proxy_make);
- WM_operatortype_append(OBJECT_OT_hide_view_clear);
- WM_operatortype_append(OBJECT_OT_hide_view_set);
- WM_operatortype_append(OBJECT_OT_hide_render_clear);
- WM_operatortype_append(OBJECT_OT_hide_render_set);
WM_operatortype_append(OBJECT_OT_shade_smooth);
WM_operatortype_append(OBJECT_OT_shade_flat);
WM_operatortype_append(OBJECT_OT_paths_calculate);
@@ -87,16 +86,16 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_slow_parent_set);
WM_operatortype_append(OBJECT_OT_slow_parent_clear);
WM_operatortype_append(OBJECT_OT_make_local);
+ WM_operatortype_append(OBJECT_OT_make_override_static);
WM_operatortype_append(OBJECT_OT_make_single_user);
WM_operatortype_append(OBJECT_OT_make_links_scene);
WM_operatortype_append(OBJECT_OT_make_links_data);
- WM_operatortype_append(OBJECT_OT_move_to_layer);
WM_operatortype_append(OBJECT_OT_select_random);
WM_operatortype_append(OBJECT_OT_select_all);
WM_operatortype_append(OBJECT_OT_select_same_group);
+ WM_operatortype_append(OBJECT_OT_select_same_collection);
WM_operatortype_append(OBJECT_OT_select_by_type);
- WM_operatortype_append(OBJECT_OT_select_by_layer);
WM_operatortype_append(OBJECT_OT_select_linked);
WM_operatortype_append(OBJECT_OT_select_grouped);
WM_operatortype_append(OBJECT_OT_select_mirror);
@@ -113,6 +112,7 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_text_add);
WM_operatortype_append(OBJECT_OT_armature_add);
WM_operatortype_append(OBJECT_OT_empty_add);
+ WM_operatortype_append(OBJECT_OT_lightprobe_add);
WM_operatortype_append(OBJECT_OT_drop_named_image);
WM_operatortype_append(OBJECT_OT_lamp_add);
WM_operatortype_append(OBJECT_OT_camera_add);
@@ -202,15 +202,17 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_vertex_weight_normalize_active_vertex);
WM_operatortype_append(OBJECT_OT_vertex_weight_copy);
+ WM_operatortype_append(OBJECT_OT_face_map_add);
+ WM_operatortype_append(OBJECT_OT_face_map_remove);
+ WM_operatortype_append(OBJECT_OT_face_map_assign);
+ WM_operatortype_append(OBJECT_OT_face_map_remove_from);
+ WM_operatortype_append(OBJECT_OT_face_map_select);
+ WM_operatortype_append(OBJECT_OT_face_map_deselect);
+ WM_operatortype_append(OBJECT_OT_face_map_move);
+
WM_operatortype_append(TRANSFORM_OT_vertex_warp);
- WM_operatortype_append(OBJECT_OT_game_property_new);
- WM_operatortype_append(OBJECT_OT_game_property_remove);
- WM_operatortype_append(OBJECT_OT_game_property_copy);
- WM_operatortype_append(OBJECT_OT_game_property_clear);
- WM_operatortype_append(OBJECT_OT_game_property_move);
- WM_operatortype_append(OBJECT_OT_logic_bricks_copy);
- WM_operatortype_append(OBJECT_OT_game_physics_copy);
+ WM_operatortype_append(OBJECT_OT_move_to_collection);
WM_operatortype_append(OBJECT_OT_shape_key_add);
WM_operatortype_append(OBJECT_OT_shape_key_remove);
@@ -239,9 +241,6 @@ void ED_operatortypes_object(void)
WM_operatortype_append(OBJECT_OT_unlink_data);
WM_operatortype_append(OBJECT_OT_laplaciandeform_bind);
- WM_operatortype_append(OBJECT_OT_lod_add);
- WM_operatortype_append(OBJECT_OT_lod_remove);
-
WM_operatortype_append(TRANSFORM_OT_vertex_random);
WM_operatortype_append(OBJECT_OT_data_transfer);
@@ -317,9 +316,6 @@ void ED_keymap_object(wmKeyConfig *keyconf)
ED_keymap_proportional_cycle(keyconf, keymap);
ED_keymap_proportional_obmode(keyconf, keymap);
- /* game-engine only, leave free for users to define */
- WM_keymap_add_item(keymap, "VIEW3D_OT_game_start", PKEY, KM_PRESS, 0, 0);
-
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_all", AKEY, KM_PRESS, 0, 0);
RNA_enum_set(kmi->ptr, "action", SEL_TOGGLE);
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_select_all", IKEY, KM_PRESS, KM_CTRL, 0);
@@ -367,25 +363,6 @@ void ED_keymap_object(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "OBJECT_OT_origin_clear", OKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_clear", HKEY, KM_PRESS, KM_ALT, 0);
- kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, 0, 0);
- RNA_boolean_set(kmi->ptr, "unselected", false);
-
- kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_view_set", HKEY, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "unselected", true);
-
- /* same as above but for rendering */
- WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_clear", HKEY, KM_PRESS, KM_ALT | KM_CTRL, 0);
- WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_CTRL, 0);
-
- /* conflicts, removing */
-#if 0
- kmi = WM_keymap_add_item(keymap, "OBJECT_OT_hide_render_set", HKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0)
- RNA_boolean_set(kmi->ptr, "unselected", true);
-#endif
-
- WM_keymap_add_item(keymap, "OBJECT_OT_move_to_layer", MKEY, KM_PRESS, 0, 0);
-
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_delete", XKEY, KM_PRESS, 0, 0);
RNA_boolean_set(kmi->ptr, "use_global", false);
@@ -434,6 +411,8 @@ void ED_keymap_object(wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "OBJECT_OT_subdivision_set", ZEROKEY + i, KM_PRESS, KM_CTRL, 0);
RNA_int_set(kmi->ptr, "level", i);
}
+
+ WM_keymap_add_item(keymap, "OBJECT_OT_move_to_collection", MKEY, KM_PRESS, 0, 0);
}
void ED_keymap_proportional_cycle(struct wmKeyConfig *UNUSED(keyconf), struct wmKeyMap *keymap)
diff --git a/source/blender/editors/object/object_relations.c b/source/blender/editors/object/object_relations.c
index 4618d05133e..ee1ef490274 100644
--- a/source/blender/editors/object/object_relations.c
+++ b/source/blender/editors/object/object_relations.c
@@ -63,10 +63,10 @@
#include "BKE_animsys.h"
#include "BKE_armature.h"
#include "BKE_camera.h"
+#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_constraint.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_displist.h"
#include "BKE_global.h"
@@ -75,9 +75,12 @@
#include "BKE_idprop.h"
#include "BKE_lamp.h"
#include "BKE_lattice.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
+#include "BKE_library_override.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
+#include "BKE_lightprobe.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_mball.h"
@@ -86,12 +89,14 @@
#include "BKE_node.h"
#include "BKE_object.h"
#include "BKE_report.h"
-#include "BKE_sca.h"
#include "BKE_scene.h"
#include "BKE_speaker.h"
#include "BKE_texture.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -123,6 +128,8 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
BMVert *eve;
BMIter iter;
@@ -142,7 +149,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
EDBM_mesh_load(obedit);
EDBM_mesh_make(obedit, scene->toolsettings->selectmode, true);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
em = me->edit_btmesh;
@@ -151,7 +158,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
/* derivedMesh might be needed for solving parenting,
* so re-create it here */
- makeDerivedMesh(scene, obedit, em, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX, false);
+ makeDerivedMesh(depsgraph, scene, obedit, em, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX, false);
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
@@ -230,7 +237,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
{
if (ob != obedit) {
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
par = obedit->parent;
if (BKE_object_parent_loop_check(par, ob)) {
@@ -239,7 +246,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
else {
Object workob;
- ob->parent = BASACT->object;
+ ob->parent = BASACT(view_layer)->object;
if (v3) {
ob->partype = PARVERT3;
ob->par1 = v1 - 1;
@@ -247,7 +254,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
ob->par3 = v3 - 1;
/* inverse parent matrix */
- BKE_object_workob_calc_parent(scene, ob, &workob);
+ BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
}
else {
@@ -255,7 +262,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
ob->par1 = v1 - 1;
/* inverse parent matrix */
- BKE_object_workob_calc_parent(scene, ob, &workob);
+ BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
}
}
@@ -263,7 +270,7 @@ static int vertex_parent_set_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT, NULL);
@@ -332,44 +339,41 @@ static int make_proxy_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Object *ob, *gob = ED_object_active_context(C);
- GroupObject *go;
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
if (gob->dup_group != NULL) {
- go = BLI_findlink(&gob->dup_group->gobject, RNA_enum_get(op->ptr, "object"));
- ob = go->ob;
+ Base *base = BLI_findlink(&gob->dup_group->view_layer->object_bases, RNA_enum_get(op->ptr, "object"));
+ ob = base->object;
}
else {
ob = gob;
- gob = NULL;
}
if (ob) {
Object *newob;
- Base *newbase, *oldbase = BASACT;
char name[MAX_ID_NAME + 4];
BLI_snprintf(name, sizeof(name), "%s_proxy", ((ID *)(gob ? gob : ob))->name + 2);
/* Add new object for the proxy */
- newob = BKE_object_add(bmain, scene, OB_EMPTY, name);
+ newob = BKE_object_add_from(bmain, scene, view_layer, OB_EMPTY, name, gob ? gob : ob);
/* set layers OK */
- newbase = BASACT; /* BKE_object_add sets active... */
- newbase->lay = oldbase->lay;
- newob->lay = newbase->lay;
-
- /* remove base, leave user count of object, it gets linked in BKE_object_make_proxy */
- if (gob == NULL) {
- BKE_scene_base_unlink(scene, oldbase);
- MEM_freeN(oldbase);
- }
-
BKE_object_make_proxy(newob, ob, gob);
+ /* Set back pointer immediately so dependency graph knows that this is
+ * is a proxy and will act accordingly. Otherwise correctness of graph
+ * will depend on order of bases.
+ *
+ * TODO(sergey): We really need to get rid of this bi-directional links
+ * in proxies with something like static overrides.
+ */
+ newob->proxy->proxy_from = newob;
+
/* depsgraph flushes are needed for the new data */
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&newob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&newob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, newob);
}
else {
@@ -388,17 +392,18 @@ static const EnumPropertyItem *proxy_group_object_itemf(bContext *C, PointerRNA
int totitem = 0;
int i = 0;
Object *ob = ED_object_active_context(C);
- GroupObject *go;
if (!ob || !ob->dup_group)
return DummyRNA_DEFAULT_items;
/* find the object to affect */
- for (go = ob->dup_group->gobject.first; go; go = go->next) {
- item_tmp.identifier = item_tmp.name = go->ob->id.name + 2;
+ FOREACH_GROUP_OBJECT_BEGIN(ob->dup_group, object)
+ {
+ item_tmp.identifier = item_tmp.name = object->id.name + 2;
item_tmp.value = i++;
RNA_enum_item_add(&item, &totitem, &item_tmp);
}
+ FOREACH_GROUP_OBJECT_END;
RNA_enum_item_end(&item, &totitem);
*r_free = true;
@@ -524,7 +529,7 @@ void ED_object_parent_clear(Object *ob, const int type)
/* Always clear parentinv matrix for sake of consistency, see T41950. */
unit_m4(ob->parentinv);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
}
/* note, poll should check for editable scene */
@@ -539,7 +544,7 @@ static int parent_clear_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
return OPERATOR_FINISHED;
@@ -607,13 +612,15 @@ EnumPropertyItem prop_make_parent_types[] = {
{0, NULL, 0, NULL, NULL}
};
-bool ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object *ob, Object *par,
+bool ED_object_parent_set(ReportList *reports, const bContext *C, Scene *scene, Object *ob, Object *par,
int partype, const bool xmirror, const bool keep_transform, const int vert_par[3])
{
+ Main *bmain = CTX_data_main(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
bPoseChannel *pchan = NULL;
const bool pararm = ELEM(partype, PAR_ARMATURE, PAR_ARMATURE_NAME, PAR_ARMATURE_ENVELOPE, PAR_ARMATURE_AUTO);
- DAG_id_tag_update(&par->id, OB_RECALC_OB);
+ DEG_id_tag_update(&par->id, OB_RECALC_OB);
/* preconditions */
if (partype == PAR_FOLLOW || partype == PAR_PATH_CONST) {
@@ -624,7 +631,7 @@ bool ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object
if ((cu->flag & CU_PATH) == 0) {
cu->flag |= CU_PATH | CU_FOLLOW;
- BKE_displist_make_curveTypes(scene, par, 0); /* force creation of path data */
+ BKE_displist_make_curveTypes(depsgraph, scene, par, 0); /* force creation of path data */
}
else {
cu->flag |= CU_FOLLOW;
@@ -710,7 +717,7 @@ bool ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object
((CurveModifierData *)md)->object = par;
}
if (par->curve_cache && par->curve_cache->path == NULL) {
- DAG_id_tag_update(&par->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&par->id, OB_RECALC_DATA);
}
}
break;
@@ -766,34 +773,36 @@ bool ED_object_parent_set(ReportList *reports, Main *bmain, Scene *scene, Object
data = con->data;
data->tar = par;
- BKE_constraint_target_matrix_get(scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra);
+ BKE_constraint_target_matrix_get(depsgraph, scene, con, 0, CONSTRAINT_OBTYPE_OBJECT, NULL, cmat, scene->r.cfra);
sub_v3_v3v3(vec, ob->obmat[3], cmat[3]);
copy_v3_v3(ob->loc, vec);
}
else if (pararm && (ob->type == OB_MESH) && (par->type == OB_ARMATURE)) {
- if (partype == PAR_ARMATURE_NAME)
- ED_object_vgroup_calc_from_armature(reports, scene, ob, par, ARM_GROUPS_NAME, false);
- else if (partype == PAR_ARMATURE_ENVELOPE)
- ED_object_vgroup_calc_from_armature(reports, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror);
+ if (partype == PAR_ARMATURE_NAME) {
+ ED_object_vgroup_calc_from_armature(reports, depsgraph, scene, ob, par, ARM_GROUPS_NAME, false);
+ }
+ else if (partype == PAR_ARMATURE_ENVELOPE) {
+ ED_object_vgroup_calc_from_armature(reports, depsgraph, scene, ob, par, ARM_GROUPS_ENVELOPE, xmirror);
+ }
else if (partype == PAR_ARMATURE_AUTO) {
WM_cursor_wait(1);
- ED_object_vgroup_calc_from_armature(reports, scene, ob, par, ARM_GROUPS_AUTO, xmirror);
+ ED_object_vgroup_calc_from_armature(reports, depsgraph, scene, ob, par, ARM_GROUPS_AUTO, xmirror);
WM_cursor_wait(0);
}
/* get corrected inverse */
ob->partype = PAROBJECT;
- BKE_object_workob_calc_parent(scene, ob, &workob);
+ BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
}
else {
/* calculate inverse parent matrix */
- BKE_object_workob_calc_parent(scene, ob, &workob);
+ BKE_object_workob_calc_parent(depsgraph, scene, ob, &workob);
invert_m4_m4(ob->parentinv, workob.obmat);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
}
}
@@ -864,7 +873,7 @@ static int parent_set_exec(bContext *C, wmOperator *op)
parent_set_vert_find(tree, ob, vert_par, is_tri);
}
- if (!ED_object_parent_set(op->reports, bmain, scene, ob, par, partype, xmirror, keep_transform, vert_par_p)) {
+ if (!ED_object_parent_set(op->reports, C, scene, ob, par, partype, xmirror, keep_transform, vert_par_p)) {
ok = false;
break;
}
@@ -879,7 +888,7 @@ static int parent_set_exec(bContext *C, wmOperator *op)
if (!ok)
return OPERATOR_CANCELLED;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
@@ -963,7 +972,7 @@ static void parent_set_ui(bContext *C, wmOperator *op)
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
/* Main auto-draw call. */
- uiDefAutoButsRNA(layout, &ptr, parent_set_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, parent_set_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
}
void OBJECT_OT_parent_set(wmOperatorType *ot)
@@ -996,7 +1005,7 @@ static int parent_noinv_set_exec(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
Object *par = ED_object_active_context(C);
- DAG_id_tag_update(&par->id, OB_RECALC_OB);
+ DEG_id_tag_update(&par->id, OB_RECALC_OB);
/* context iterator */
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
@@ -1011,7 +1020,7 @@ static int parent_noinv_set_exec(bContext *C, wmOperator *op)
memset(ob->loc, 0, 3 * sizeof(float));
/* set recalc flags */
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
/* set parenting type for object - object only... */
ob->parent = par;
@@ -1021,7 +1030,7 @@ static int parent_noinv_set_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
@@ -1047,6 +1056,7 @@ void OBJECT_OT_parent_no_inverse_set(wmOperatorType *ot)
static int object_slow_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
@@ -1054,9 +1064,9 @@ static int object_slow_parent_clear_exec(bContext *C, wmOperator *UNUSED(op))
if (ob->parent) {
if (ob->partype & PARSLOW) {
ob->partype -= PARSLOW;
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(depsgraph, scene, ob);
ob->partype |= PARSLOW;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
}
}
@@ -1094,7 +1104,7 @@ static int object_slow_parent_set_exec(bContext *C, wmOperator *UNUSED(op))
if (ob->parent)
ob->partype |= PARSLOW;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
CTX_DATA_END;
@@ -1148,7 +1158,7 @@ static int object_track_clear_exec(bContext *C, wmOperator *op)
/* remove track-object for old track */
ob->track = NULL;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
/* also remove all tracking constraints */
for (con = ob->constraints.last; con; con = pcon) {
@@ -1162,7 +1172,7 @@ static int object_track_clear_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
@@ -1222,7 +1232,7 @@ static int track_set_exec(bContext *C, wmOperator *op)
data = con->data;
data->tar = obact;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
/* Lamp, Camera and Speaker track differently by default */
if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
@@ -1245,7 +1255,7 @@ static int track_set_exec(bContext *C, wmOperator *op)
data = con->data;
data->tar = obact;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
/* Lamp, Camera and Speaker track differently by default */
if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
@@ -1269,7 +1279,7 @@ static int track_set_exec(bContext *C, wmOperator *op)
data = con->data;
data->tar = obact;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
/* Lamp, Camera and Speaker track differently by default */
if (ELEM(ob->type, OB_LAMP, OB_CAMERA, OB_SPEAKER)) {
@@ -1283,7 +1293,7 @@ static int track_set_exec(bContext *C, wmOperator *op)
}
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
return OPERATOR_FINISHED;
@@ -1309,119 +1319,6 @@ void OBJECT_OT_track_set(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "type", prop_make_track_types, 0, "Type", "");
}
-/************************** Move to Layer Operator *****************************/
-
-static unsigned int move_to_layer_init(bContext *C, wmOperator *op)
-{
- int values[20], a;
- unsigned int lay = 0;
-
- if (!RNA_struct_property_is_set(op->ptr, "layers")) {
- /* note: layers are set in bases, library objects work for this */
- CTX_DATA_BEGIN (C, Base *, base, selected_bases)
- {
- lay |= base->lay;
- }
- CTX_DATA_END;
-
- for (a = 0; a < 20; a++)
- values[a] = (lay & (1 << a)) != 0;
-
- RNA_boolean_set_array(op->ptr, "layers", values);
- }
- else {
- RNA_boolean_get_array(op->ptr, "layers", values);
-
- for (a = 0; a < 20; a++)
- if (values[a])
- lay |= (1 << a);
- }
-
- return lay;
-}
-
-static int move_to_layer_invoke(bContext *C, wmOperator *op, const wmEvent *event)
-{
- View3D *v3d = CTX_wm_view3d(C);
- if (v3d && v3d->localvd) {
- return WM_operator_confirm_message(C, op, "Move out of Local View");
- }
- else {
- move_to_layer_init(C, op);
- return WM_operator_props_popup(C, op, event);
- }
-}
-
-static int move_to_layer_exec(bContext *C, wmOperator *op)
-{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
- unsigned int lay, local;
- /* bool is_lamp = false; */ /* UNUSED */
-
- lay = move_to_layer_init(C, op);
- lay &= 0xFFFFFF;
-
- if (lay == 0) return OPERATOR_CANCELLED;
-
- if (v3d && v3d->localvd) {
- /* now we can move out of localview. */
- /* note: layers are set in bases, library objects work for this */
- CTX_DATA_BEGIN (C, Base *, base, selected_bases)
- {
- lay = base->lay & ~v3d->lay;
- base->lay = lay;
- base->object->lay = lay;
- base->object->flag &= ~SELECT;
- base->flag &= ~SELECT;
- /* if (base->object->type == OB_LAMP) is_lamp = true; */
- }
- CTX_DATA_END;
- }
- else {
- /* normal non localview operation */
- /* note: layers are set in bases, library objects work for this */
- CTX_DATA_BEGIN (C, Base *, base, selected_bases)
- {
- /* upper byte is used for local view */
- local = base->lay & 0xFF000000;
- base->lay = lay + local;
- base->object->lay = base->lay;
- /* if (base->object->type == OB_LAMP) is_lamp = true; */
- }
- CTX_DATA_END;
- }
-
- /* warning, active object may be hidden now */
-
- WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, scene);
- WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
-
- DAG_relations_tag_update(bmain);
-
- return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_move_to_layer(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Move to Layer";
- ot->description = "Move the object to different layers";
- ot->idname = "OBJECT_OT_move_to_layer";
-
- /* api callbacks */
- ot->invoke = move_to_layer_invoke;
- ot->exec = move_to_layer_exec;
- ot->poll = ED_operator_objectmode;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_boolean_layer_member(ot->srna, "layers", 20, NULL, "Layer", "");
-}
-
/************************** Link to Scene Operator *****************************/
#if 0
@@ -1444,20 +1341,6 @@ static void link_to_scene(Main *UNUSED(bmain), unsigned short UNUSED(nr))
}
#endif
-Base *ED_object_scene_link(Scene *scene, Object *ob)
-{
- Base *base;
-
- if (BKE_scene_base_find(scene, ob)) {
- return NULL;
- }
-
- base = BKE_scene_base_add(scene, ob);
- id_us_plus(&ob->id);
-
- return base;
-}
-
static int make_links_scene_exec(bContext *C, wmOperator *op)
{
Scene *scene_to = BLI_findlink(&CTX_data_main(C)->scene, RNA_enum_get(op->ptr, "scene"));
@@ -1477,9 +1360,10 @@ static int make_links_scene_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
+ SceneCollection *sc_to = BKE_collection_master(&scene_to->id);
CTX_DATA_BEGIN (C, Base *, base, selected_bases)
{
- ED_object_scene_link(scene_to, base->object);
+ BKE_collection_object_add(&scene_to->id, sc_to, base->object);
}
CTX_DATA_END;
@@ -1535,7 +1419,6 @@ static bool allow_make_links_data(const int type, Object *ob_src, Object *ob_dst
static int make_links_data_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
const int type = RNA_enum_get(op->ptr, "type");
Object *ob_src;
ID *obdata_id;
@@ -1572,7 +1455,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
/* if amount of material indices changed: */
test_object_materials(ob_dst, ob_dst->data);
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
break;
case MAKE_LINKS_MATERIALS:
/* new approach, using functions from kernel */
@@ -1580,30 +1463,30 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
Material *ma = give_current_material(ob_src, a + 1);
assign_material(ob_dst, ma, a + 1, BKE_MAT_ASSIGN_USERPREF); /* also works with ma==NULL */
}
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_DATA);
break;
case MAKE_LINKS_ANIMDATA:
- BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, false);
+ BKE_animdata_copy_id(bmain, (ID *)ob_dst, (ID *)ob_src, false, true);
if (ob_dst->data && ob_src->data) {
if (ID_IS_LINKED(obdata_id)) {
is_lib = true;
break;
}
- BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, false);
+ BKE_animdata_copy_id(bmain, (ID *)ob_dst->data, (ID *)ob_src->data, false, true);
}
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
break;
case MAKE_LINKS_GROUP:
{
LinkNode *group_node;
/* first clear groups */
- BKE_object_groups_clear(scene, base_dst, ob_dst);
+ BKE_object_groups_clear(ob_dst);
/* now add in the groups from the link nodes */
for (group_node = ob_groups; group_node; group_node = group_node->next) {
if (ob_dst->dup_group != group_node->link) {
- BKE_group_object_add(group_node->link, ob_dst, scene, base_dst);
+ BKE_group_object_add(group_node->link, ob_dst);
}
else {
is_cycle = true;
@@ -1620,7 +1503,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
break;
case MAKE_LINKS_MODIFIERS:
BKE_object_link_modifiers(ob_dst, ob_src);
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
break;
case MAKE_LINKS_FONTS:
{
@@ -1649,7 +1532,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
cu_dst->vfontbi = cu_src->vfontbi;
id_us_plus((ID *)cu_dst->vfontbi);
- DAG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob_dst->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
break;
}
}
@@ -1672,7 +1555,7 @@ static int make_links_data_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_WARNING, "Skipped editing library object data");
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
WM_event_add_notifier(C, NC_ANIMATION | ND_NLA_ACTCHANGE, CTX_wm_view3d(C));
WM_event_add_notifier(C, NC_OBJECT, NULL);
@@ -1736,69 +1619,100 @@ void OBJECT_OT_make_links_data(wmOperatorType *ot)
/**************************** Make Single User ********************************/
-/* Warning, sets ID->newid pointers of objects and groups, but does not clear them. */
-static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_groups)
+static Object *single_object_users_object(Main *bmain, Scene *scene, Object *ob, const bool copy_groups)
{
- Base *base;
- Object *ob, *obn;
- Group *group, *groupn;
- GroupObject *go;
+ /* base gets copy of object */
+ Object *obn = ID_NEW_SET(ob, BKE_object_copy(bmain, ob));
- clear_sca_new_poins(); /* BGE logic */
+ if (copy_groups) {
+ if (ob->flag & OB_FROMGROUP) {
+ obn->flag |= OB_FROMGROUP;
+ }
+ }
+ else {
+ /* copy already clears */
+ }
+ /* remap gpencil parenting */
- /* duplicate (must set newid) */
- for (base = FIRSTBASE; base; base = base->next) {
- ob = base->object;
+ if (scene->gpd) {
+ bGPdata *gpd = scene->gpd;
+ for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+ if (gpl->parent == ob) {
+ gpl->parent = obn;
+ }
+ }
+ }
+
+ id_us_min(&ob->id);
+ return obn;
+}
+
+static void libblock_relink_scene_collection(SceneCollection *sc)
+{
+ for (LinkData *link = sc->objects.first; link; link = link->next) {
+ BKE_libblock_relink_to_newid(link->data);
+ }
+
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ libblock_relink_scene_collection(nsc);
+ }
+}
- if ((base->flag & flag) == flag) {
+static void single_object_users_scene_collection(Main *bmain, Scene *scene, SceneCollection *sc, const int flag, const bool copy_groups)
+{
+ for (LinkData *link = sc->objects.first; link; link = link->next) {
+ Object *ob = link->data;
+ /* an object may be in more than one collection */
+ if ((ob->id.newid == NULL) && ((ob->flag & flag) == flag)) {
if (!ID_IS_LINKED(ob) && ob->id.us > 1) {
- /* base gets copy of object */
- base->object = obn = ID_NEW_SET(ob, BKE_object_copy(bmain, ob));
+ link->data = single_object_users_object(bmain, scene, link->data, copy_groups);
+ }
+ }
+ }
- if (copy_groups) {
- if (ob->flag & OB_FROMGROUP) {
- obn->flag |= OB_FROMGROUP;
- }
- }
- else {
- /* copy already clears */
- }
- /* remap gpencil parenting */
+ for (SceneCollection *nsc = sc->scene_collections.first; nsc; nsc = nsc->next) {
+ single_object_users_scene_collection(bmain, scene, nsc, flag, copy_groups);
+ }
+}
- if (scene->gpd) {
- bGPdata *gpd = scene->gpd;
- for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- if (gpl->parent == ob) {
- gpl->parent = obn;
- }
- }
- }
+/* Warning, sets ID->newid pointers of objects and groups, but does not clear them. */
+static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const int flag, const bool copy_groups)
+{
+ Group *group, *groupn;
- base->flag = obn->flag;
+ /* duplicate all the objects of the scene */
+ SceneCollection *msc = BKE_collection_master(&scene->id);
+ single_object_users_scene_collection(bmain, scene, msc, flag, copy_groups);
- id_us_min(&ob->id);
- }
+ /* loop over ViewLayers and assign the pointers accordingly */
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ ID_NEW_REMAP(base->object);
}
}
/* duplicate groups that consist entirely of duplicated objects */
for (group = bmain->group.first; group; group = group->id.next) {
- if (copy_groups && group->gobject.first) {
+ if (copy_groups && group->view_layer->object_bases.first) {
bool all_duplicated = true;
- for (go = group->gobject.first; go; go = go->next) {
- if (!(go->ob && (go->ob->id.newid))) {
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ if (object->id.newid == NULL) {
all_duplicated = false;
break;
}
}
+ FOREACH_GROUP_OBJECT_END;
if (all_duplicated) {
groupn = ID_NEW_SET(group, BKE_group_copy(bmain, group));
- for (go = groupn->gobject.first; go; go = go->next) {
- go->ob = (Object *)go->ob->id.newid;
+ FOREACH_GROUP_BASE_BEGIN(groupn, base)
+ {
+ base->object = (Object *)base->object->id.newid;
}
+ FOREACH_GROUP_BASE_END
}
}
}
@@ -1810,27 +1724,23 @@ static void single_object_users(Main *bmain, Scene *scene, View3D *v3d, const in
if (v3d) ID_NEW_REMAP(v3d->camera);
/* object and group pointers */
- for (base = FIRSTBASE; base; base = base->next) {
- BKE_libblock_relink_to_newid(&base->object->id);
- }
-
- set_sca_new_poins();
+ libblock_relink_scene_collection(msc);
}
/* not an especially efficient function, only added so the single user
* button can be functional.*/
void ED_object_single_user(Main *bmain, Scene *scene, Object *ob)
{
- Base *base;
- const bool copy_groups = false;
-
- for (base = FIRSTBASE; base; base = base->next) {
- if (base->object == ob) base->flag |= OB_DONE;
- else base->flag &= ~OB_DONE;
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob_iter)
+ {
+ ob_iter->flag &= ~OB_DONE;
}
+ FOREACH_SCENE_OBJECT_END;
- single_object_users(bmain, scene, NULL, OB_DONE, copy_groups);
+ /* tag only the one object */
+ ob->flag |= OB_DONE;
+ single_object_users(bmain, scene, NULL, OB_DONE, false);
BKE_main_id_clear_newpoins(bmain);
}
@@ -1855,34 +1765,26 @@ static void new_id_matar(Main *bmain, Material **matar, const int totcol)
}
}
-static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
+static void single_obdata_users(Main *bmain, Scene *scene, ViewLayer *view_layer, const int flag)
{
- Object *ob;
Lamp *la;
Curve *cu;
/* Camera *cam; */
- Base *base;
Mesh *me;
Lattice *lat;
ID *id;
- int a;
- for (base = FIRSTBASE; base; base = base->next) {
- ob = base->object;
- if (!ID_IS_LINKED(ob) && (base->flag & flag) == flag) {
+ FOREACH_OBJECT_FLAG_BEGIN(scene, view_layer, flag, ob)
+ {
+ if (!ID_IS_LINKED(ob)) {
id = ob->data;
if (id && id->us > 1 && !ID_IS_LINKED(id)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
switch (ob->type) {
case OB_LAMP:
ob->data = la = ID_NEW_SET(ob->data, BKE_lamp_copy(bmain, ob->data));
- for (a = 0; a < MAX_MTEX; a++) {
- if (la->mtex[a]) {
- ID_NEW_REMAP(la->mtex[a]->object);
- }
- }
break;
case OB_CAMERA:
ob->data = ID_NEW_SET(ob->data, BKE_camera_copy(bmain, ob->data));
@@ -1911,16 +1813,22 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
BKE_animdata_copy_id_action((ID *)lat->key, false);
break;
case OB_ARMATURE:
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
ob->data = ID_NEW_SET(ob->data, BKE_armature_copy(bmain, ob->data));
BKE_pose_rebuild(ob, ob->data);
break;
case OB_SPEAKER:
ob->data = ID_NEW_SET(ob->data, BKE_speaker_copy(bmain, ob->data));
break;
+ case OB_LIGHTPROBE:
+ ob->data = ID_NEW_SET(ob->data, BKE_lightprobe_copy(bmain, ob->data));
+ break;
default:
- if (G.debug & G_DEBUG)
- printf("ERROR %s: can't copy %s\n", __func__, id->name);
+ printf("ERROR %s: can't copy %s\n", __func__, id->name);
+ BLI_assert(!"This should never happen.");
+
+ /* We need to end the FOREACH_OBJECT_FLAG_BEGIN iterator to prevent memory leak. */
+ BKE_scene_objects_iterator_end(&iter_macro);
return;
}
@@ -1935,6 +1843,7 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
}
}
}
+ FOREACH_OBJECT_FLAG_END;
me = bmain->mesh.first;
while (me) {
@@ -1943,31 +1852,26 @@ static void single_obdata_users(Main *bmain, Scene *scene, const int flag)
}
}
-static void single_object_action_users(Scene *scene, const int flag)
+static void single_object_action_users(Scene *scene, ViewLayer *view_layer, const int flag)
{
- Object *ob;
- Base *base;
-
- for (base = FIRSTBASE; base; base = base->next) {
- ob = base->object;
- if (!ID_IS_LINKED(ob) && (flag == 0 || (base->flag & SELECT)) ) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ FOREACH_OBJECT_FLAG_BEGIN(scene, view_layer, flag, ob)
+ {
+ if (!ID_IS_LINKED(ob)) {
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
BKE_animdata_copy_id_action(&ob->id, false);
}
}
+ FOREACH_OBJECT_FLAG_END;
}
-static void single_mat_users(Main *bmain, Scene *scene, const int flag, const bool do_textures)
+static void single_mat_users(Main *bmain, Scene *scene, ViewLayer *view_layer, const int flag)
{
- Object *ob;
- Base *base;
Material *ma, *man;
- Tex *tex;
- int a, b;
+ int a;
- for (base = FIRSTBASE; base; base = base->next) {
- ob = base->object;
- if (!ID_IS_LINKED(ob) && (flag == 0 || (base->flag & SELECT)) ) {
+ FOREACH_OBJECT_FLAG_BEGIN(scene, view_layer, flag, ob)
+ {
+ if (!ID_IS_LINKED(ob)) {
for (a = 1; a <= ob->totcol; a++) {
ma = give_current_material(ob, a);
if (ma) {
@@ -1979,84 +1883,12 @@ static void single_mat_users(Main *bmain, Scene *scene, const int flag, const bo
man->id.us = 0;
assign_material(ob, man, a, BKE_MAT_ASSIGN_USERPREF);
-
- if (do_textures) {
- for (b = 0; b < MAX_MTEX; b++) {
- if (ma->mtex[b] && (tex = ma->mtex[b]->tex)) {
- if (tex->id.us > 1) {
- id_us_min(&tex->id);
- tex = BKE_texture_copy(bmain, tex);
- BKE_animdata_copy_id_action(&tex->id, false);
- man->mtex[b]->tex = tex;
- }
- }
- }
- }
}
}
}
}
}
-}
-
-static void do_single_tex_user(Main *bmain, Tex **from)
-{
- Tex *tex, *texn;
-
- tex = *from;
- if (tex == NULL) return;
-
- if (tex->id.newid) {
- *from = (Tex *)tex->id.newid;
- id_us_plus(tex->id.newid);
- id_us_min(&tex->id);
- }
- else if (tex->id.us > 1) {
- texn = ID_NEW_SET(tex, BKE_texture_copy(bmain, tex));
- BKE_animdata_copy_id_action(&texn->id, false);
- tex->id.newid = (ID *)texn;
- id_us_min(&tex->id);
- *from = texn;
- }
-}
-
-static void single_tex_users_expand(Main *bmain)
-{
- /* only when 'parent' blocks are LIB_TAG_NEW */
- Material *ma;
- Lamp *la;
- World *wo;
- int b;
-
- for (ma = bmain->mat.first; ma; ma = ma->id.next) {
- if (ma->id.tag & LIB_TAG_NEW) {
- for (b = 0; b < MAX_MTEX; b++) {
- if (ma->mtex[b] && ma->mtex[b]->tex) {
- do_single_tex_user(bmain, &(ma->mtex[b]->tex));
- }
- }
- }
- }
-
- for (la = bmain->lamp.first; la; la = la->id.next) {
- if (la->id.tag & LIB_TAG_NEW) {
- for (b = 0; b < MAX_MTEX; b++) {
- if (la->mtex[b] && la->mtex[b]->tex) {
- do_single_tex_user(bmain, &(la->mtex[b]->tex));
- }
- }
- }
- }
-
- for (wo = bmain->world.first; wo; wo = wo->id.next) {
- if (wo->id.tag & LIB_TAG_NEW) {
- for (b = 0; b < MAX_MTEX; b++) {
- if (wo->mtex[b] && wo->mtex[b]->tex) {
- do_single_tex_user(bmain, &(wo->mtex[b]->tex));
- }
- }
- }
- }
+ FOREACH_OBJECT_FLAG_END;
}
static void single_mat_users_expand(Main *bmain)
@@ -2066,8 +1898,6 @@ static void single_mat_users_expand(Main *bmain)
Mesh *me;
Curve *cu;
MetaBall *mb;
- Material *ma;
- int a;
for (ob = bmain->object.first; ob; ob = ob->id.next)
if (ob->id.tag & LIB_TAG_NEW)
@@ -2084,13 +1914,6 @@ static void single_mat_users_expand(Main *bmain)
for (mb = bmain->mball.first; mb; mb = mb->id.next)
if (mb->id.tag & LIB_TAG_NEW)
new_id_matar(bmain, mb->mat, mb->totcol);
-
- /* material imats */
- for (ma = bmain->mat.first; ma; ma = ma->id.next)
- if (ma->id.tag & LIB_TAG_NEW)
- for (a = 0; a < MAX_MTEX; a++)
- if (ma->mtex[a])
- ID_NEW_REMAP(ma->mtex[a]->object);
}
/* used for copying scenes */
@@ -2099,10 +1922,9 @@ void ED_object_single_users(Main *bmain, Scene *scene, const bool full, const bo
single_object_users(bmain, scene, NULL, 0, copy_groups);
if (full) {
- single_obdata_users(bmain, scene, 0);
- single_object_action_users(scene, 0);
+ single_obdata_users(bmain, scene, NULL, 0);
+ single_object_action_users(scene, NULL, 0);
single_mat_users_expand(bmain);
- single_tex_users_expand(bmain);
}
/* Relink nodetrees' pointers that have been duplicated. */
@@ -2121,12 +1943,13 @@ void ED_object_single_users(Main *bmain, Scene *scene, const bool full, const bo
{
IDP_RelinkProperty(scene->id.properties);
- for (Base *base = scene->base.first; base; base = base->next) {
- Object *ob = base->object;
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
+ {
if (!ID_IS_LINKED(ob)) {
IDP_RelinkProperty(ob->id.properties);
}
}
+ FOREACH_SCENE_OBJECT_END;
if (scene->nodetree) {
IDP_RelinkProperty(scene->nodetree->id.properties);
@@ -2148,7 +1971,7 @@ void ED_object_single_users(Main *bmain, Scene *scene, const bool full, const bo
}
}
BKE_main_id_clear_newpoins(bmain);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
/******************************* Make Local ***********************************/
@@ -2215,7 +2038,7 @@ static void tag_localizable_objects(bContext *C, const int mode)
* Instance indirectly referenced zero user objects,
* otherwise they're lost on reload, see T40595.
*/
-static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene)
+static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene, ViewLayer *view_layer, SceneCollection *sc)
{
Object *ob;
bool changed = false;
@@ -2226,10 +2049,11 @@ static bool make_local_all__instance_indirect_unused(Main *bmain, Scene *scene)
id_us_plus(&ob->id);
- base = BKE_scene_base_add(scene, ob);
- base->flag |= SELECT;
- base->object->flag = base->flag;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ BKE_collection_object_add(&scene->id, sc, ob);
+ base = BKE_view_layer_base_find(view_layer, ob);
+ base->flag |= BASE_SELECTED;
+ BKE_scene_object_base_flag_sync_from_base(base);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
changed = true;
}
@@ -2287,12 +2111,6 @@ static void make_local_material_tag(Material *ma)
make_local_animdata_tag(BKE_animdata_from_id(&ma->id));
/* About nodetrees: root one is made local together with material, others we keep linked for now... */
-
- for (int a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a] && ma->mtex[a]->tex) {
- ma->mtex[a]->tex->id.tag &= ~LIB_TAG_PRE_EXISTING;
- }
- }
}
}
@@ -2302,18 +2120,20 @@ static int make_local_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
ParticleSystem *psys;
Material *ma, ***matarar;
- Lamp *la;
const int mode = RNA_enum_get(op->ptr, "type");
int a;
/* Note: we (ab)use LIB_TAG_PRE_EXISTING to cherry pick which ID to make local... */
if (mode == MAKE_LOCAL_ALL) {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ SceneCollection *scene_collection = CTX_data_scene_collection(C);
+
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
- /* de-select so the user can differentiate newly instanced from existing objects */
- BKE_scene_base_deselect_all(scene);
+ /* De-select so the user can differentiate newly instanced from existing objects. */
+ BKE_view_layer_base_deselect_all(view_layer);
- if (make_local_all__instance_indirect_unused(bmain, scene)) {
+ if (make_local_all__instance_indirect_unused(bmain, scene, view_layer, scene_collection)) {
BKE_report(op->reports, RPT_INFO, "Orphan library objects added to the current scene to avoid loss");
}
}
@@ -2350,16 +2170,6 @@ static int make_local_exec(bContext *C, wmOperator *op)
}
}
}
-
- if (ob->type == OB_LAMP) {
- BLI_assert(ob->data != NULL);
- la = ob->data;
- for (a = 0; a < MAX_MTEX; a++) {
- if (la->mtex[a] && la->mtex[a]->tex) {
- la->id.tag &= ~LIB_TAG_PRE_EXISTING;
- }
- }
- }
}
if (ELEM(mode, MAKE_LOCAL_SELECT_OBDATA, MAKE_LOCAL_SELECT_OBDATA_MATERIAL) && ob->data != NULL) {
@@ -2404,6 +2214,205 @@ void OBJECT_OT_make_local(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
}
+
+static void make_override_static_tag_object(Object *obact, Object *ob)
+{
+ if (ob == obact) {
+ return;
+ }
+
+ if (!ID_IS_LINKED(ob)) {
+ return;
+ }
+
+ /* Note: all this is very case-by-case bad handling, ultimately we'll want a real full 'automatic', generic
+ * handling of all this, will probably require adding some override-aware stuff to library_query code... */
+
+ if (obact->type == OB_ARMATURE && ob->modifiers.first != NULL) {
+ for (ModifierData *md = ob->modifiers.first; md != NULL; md = md->next) {
+ if (md->type == eModifierType_Armature) {
+ ArmatureModifierData *amd = (ArmatureModifierData *)md;
+ if (amd->object == obact) {
+ ob->id.tag |= LIB_TAG_DOIT;
+ break;
+ }
+ }
+ }
+ }
+ else if (ob->parent == obact) {
+ ob->id.tag |= LIB_TAG_DOIT;
+ }
+
+ if (ob->id.tag & LIB_TAG_DOIT) {
+ printf("Indirectly overriding %s for %s\n", ob->id.name, obact->id.name);
+ }
+}
+
+/* Set the object to override. */
+static int make_override_static_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ Scene *scene = CTX_data_scene(C);
+ Object *obact = ED_object_active_context(C);
+
+ /* Sanity checks. */
+ if (!scene || ID_IS_LINKED(scene) || !obact) {
+ return OPERATOR_CANCELLED;
+ }
+
+ /* Get object to work on - use a menu if we need to... */
+ if (!ID_IS_LINKED(obact) && obact->dup_group != NULL && ID_IS_LINKED(obact->dup_group)) {
+ /* Gives menu with list of objects in group. */
+ WM_enum_search_invoke(C, op, event);
+ return OPERATOR_CANCELLED;
+ }
+ else if (ID_IS_LINKED(obact)) {
+ uiPopupMenu *pup = UI_popup_menu_begin(C, IFACE_("OK?"), ICON_QUESTION);
+ uiLayout *layout = UI_popup_menu_layout(pup);
+
+ /* Create operator menu item with relevant properties filled in. */
+ PointerRNA opptr_dummy;
+ uiItemFullO_ptr(layout, op->type, op->type->name, ICON_NONE, NULL,
+ WM_OP_EXEC_REGION_WIN, 0, &opptr_dummy);
+
+ /* Present the menu and be done... */
+ UI_popup_menu_end(C, pup);
+
+ /* This invoke just calls another instance of this operator... */
+ return OPERATOR_INTERFACE;
+ }
+ else {
+ /* Error.. cannot continue. */
+ BKE_report(op->reports, RPT_ERROR, "Can only make static override for a referenced object or group");
+ return OPERATOR_CANCELLED;
+ }
+
+}
+
+static int make_override_static_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ Object *obact = CTX_data_active_object(C);
+
+ bool success = false;
+
+ if (!ID_IS_LINKED(obact) && obact->dup_group != NULL && ID_IS_LINKED(obact->dup_group)) {
+ Base *base = BLI_findlink(&obact->dup_group->view_layer->object_bases, RNA_enum_get(op->ptr, "object"));
+ Object *obgroup = obact;
+ obact = base->object;
+ Group *group = obgroup->dup_group;
+
+ /* First, we make a static override of the linked group itself. */
+ group->id.tag |= LIB_TAG_DOIT;
+
+ /* Then, we make static override of the whole set of objects in the group. */
+ FOREACH_GROUP_OBJECT_BEGIN(group, ob)
+ {
+ ob->id.tag |= LIB_TAG_DOIT;
+ }
+ FOREACH_GROUP_OBJECT_END;
+
+ success = BKE_override_static_create_from_tag(bmain);
+
+ /* Intantiate our newly overridden objects in scene, if not yet done. */
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Group *new_group = (Group *)group->id.newid;
+ FOREACH_GROUP_OBJECT_BEGIN(new_group, new_ob)
+ {
+ if (new_ob != NULL && (base = BKE_view_layer_base_find(view_layer, new_ob)) == NULL) {
+ BKE_collection_object_add_from(scene, obgroup, new_ob);
+ DEG_id_tag_update_ex(bmain, &new_ob->id, OB_RECALC_OB | DEG_TAG_BASE_FLAGS_UPDATE);
+ /* parent to 'group' empty */
+ if (new_ob->parent == NULL) {
+ new_ob->parent = obgroup;
+ }
+ if (new_ob == (Object *)obact->id.newid) {
+ base = BKE_view_layer_base_find(view_layer, new_ob);
+ BKE_view_layer_base_select(view_layer, base);
+ }
+ else {
+ /* Disable auto-override tags for non-active objects, will help with performaces... */
+ new_ob->id.override_static->flag &= ~STATICOVERRIDE_AUTO;
+ }
+ /* We still want to store all objects' current override status (i.e. change of parent). */
+ BKE_override_static_operations_create(&new_ob->id, true);
+ }
+ }
+ FOREACH_GROUP_OBJECT_END;
+
+ /* obgroup is no more dupligroup-ing, it merely parents whole group of overriding instantiated objects. */
+ obgroup->dup_group = NULL;
+
+ /* Also, we'd likely want to lock by default things like transformations of implicitly overriden objects? */
+
+ DEG_id_tag_update(&scene->id, 0);
+
+ /* Cleanup. */
+ BKE_main_id_clear_newpoins(bmain);
+ BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, false);
+ }
+ /* Else, poll func ensures us that ID_IS_LINKED(obact) is true. */
+ else if (obact->type == OB_ARMATURE) {
+ BKE_main_id_tag_all(bmain, LIB_TAG_DOIT, false);
+
+ obact->id.tag |= LIB_TAG_DOIT;
+
+ for (Object *ob = bmain->object.first; ob != NULL; ob = ob->id.next) {
+ make_override_static_tag_object(obact, ob);
+ }
+
+ success = BKE_override_static_create_from_tag(bmain);
+
+ /* Also, we'd likely want to lock by default things like transformations of implicitly overriden objects? */
+
+ /* Cleanup. */
+ BKE_main_id_clear_newpoins(bmain);
+ BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, false);
+ }
+ /* TODO: probably more cases where we want to do automated smart things in the future! */
+ else {
+ success = (BKE_override_static_create_from_id(bmain, &obact->id) != NULL);
+ }
+
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+
+ return success ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+}
+
+static int make_override_static_poll(bContext *C)
+{
+ Object *obact = CTX_data_active_object(C);
+
+ /* Object must be directly linked to be overridable. */
+ return (ED_operator_objectmode(C) && obact != NULL &&
+ ((ID_IS_LINKED(obact) && obact->id.tag & LIB_TAG_EXTERN) ||
+ (!ID_IS_LINKED(obact) && obact->dup_group != NULL && ID_IS_LINKED(obact->dup_group))));
+}
+
+void OBJECT_OT_make_override_static(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Make Static Override";
+ ot->description = "Make local override of this library linked data-block";
+ ot->idname = "OBJECT_OT_make_override_static";
+
+ /* api callbacks */
+ ot->invoke = make_override_static_invoke;
+ ot->exec = make_override_static_exec;
+ ot->poll = make_override_static_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ PropertyRNA *prop;
+ prop = RNA_def_enum(ot->srna, "object", DummyRNA_DEFAULT_items, 0, "Override Object",
+ "Name of lib-linked/group object to make an override from");
+ RNA_def_enum_funcs(prop, proxy_group_object_itemf);
+ RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE);
+ ot->prop = prop;
+}
+
enum {
MAKE_SINGLE_USER_ALL = 1,
MAKE_SINGLE_USER_SELECTED = 2,
@@ -2413,32 +2422,35 @@ static int make_single_user_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C); /* ok if this is NULL */
const int flag = (RNA_enum_get(op->ptr, "type") == MAKE_SINGLE_USER_SELECTED) ? SELECT : 0;
const bool copy_groups = false;
bool update_deps = false;
if (RNA_boolean_get(op->ptr, "object")) {
- single_object_users(bmain, scene, v3d, flag, copy_groups);
+ if (flag == SELECT) {
+ BKE_view_layer_selected_objects_tag(view_layer, OB_DONE);
+ single_object_users(bmain, scene, v3d, OB_DONE, copy_groups);
+ }
+ else {
+ single_object_users(bmain, scene, v3d, 0, copy_groups);
+ }
/* needed since object relationships may have changed */
update_deps = true;
}
if (RNA_boolean_get(op->ptr, "obdata")) {
- single_obdata_users(bmain, scene, flag);
+ single_obdata_users(bmain, scene, view_layer, flag);
}
if (RNA_boolean_get(op->ptr, "material")) {
- single_mat_users(bmain, scene, flag, RNA_boolean_get(op->ptr, "texture"));
+ single_mat_users(bmain, scene, view_layer, flag);
}
-#if 0 /* can't do this separate from materials */
- if (RNA_boolean_get(op->ptr, "texture"))
- single_mat_users(scene, flag, true);
-#endif
if (RNA_boolean_get(op->ptr, "animation")) {
- single_object_action_users(scene, flag);
+ single_object_action_users(scene, view_layer, flag);
}
BKE_main_id_clear_newpoins(bmain);
@@ -2446,7 +2458,7 @@ static int make_single_user_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_WINDOW, NULL);
if (update_deps) {
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
return OPERATOR_FINISHED;
@@ -2478,8 +2490,6 @@ void OBJECT_OT_make_single_user(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "object", 0, "Object", "Make single user objects");
RNA_def_boolean(ot->srna, "obdata", 0, "Object Data", "Make single user object data");
RNA_def_boolean(ot->srna, "material", 0, "Materials", "Make materials local to each data-block");
- RNA_def_boolean(ot->srna, "texture", 0, "Textures",
- "Make textures local to each material (needs 'Materials' to be set too)");
RNA_def_boolean(ot->srna, "animation", 0, "Object Animation", "Make animation data local to each object");
}
@@ -2496,7 +2506,7 @@ static int drop_named_material_invoke(bContext *C, wmOperator *op, const wmEvent
assign_material(base->object, ma, 1, BKE_MAT_ASSIGN_USERPREF);
- DAG_id_tag_update(&base->object->id, OB_RECALC_OB);
+ DEG_id_tag_update(&base->object->id, OB_RECALC_OB);
WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, base->object);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
diff --git a/source/blender/editors/object/object_select.c b/source/blender/editors/object/object_select.c
index 8d5c2387fe9..d0d0418c861 100644
--- a/source/blender/editors/object/object_select.c
+++ b/source/blender/editors/object/object_select.c
@@ -37,10 +37,10 @@
#include "DNA_group_types.h"
#include "DNA_material_types.h"
#include "DNA_modifier_types.h"
-#include "DNA_property_types.h"
#include "DNA_scene_types.h"
#include "DNA_armature_types.h"
#include "DNA_lamp_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_math.h"
#include "BLI_listbase.h"
@@ -52,15 +52,20 @@
#include "BKE_context.h"
#include "BKE_group.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_material.h"
+#include "BKE_object.h"
#include "BKE_particle.h"
-#include "BKE_property.h"
+#include "BKE_paint.h"
#include "BKE_report.h"
#include "BKE_scene.h"
+#include "BKE_workspace.h"
#include "BKE_library.h"
#include "BKE_deform.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -86,37 +91,44 @@
/* Note: send a NC_SCENE|ND_OB_SELECT notifier yourself! (or
* or a NC_SCENE|ND_OB_VISIBLE in case of visibility toggling */
-void ED_base_object_select(Base *base, short mode)
+void ED_object_base_select(Base *base, eObjectSelect_Mode mode)
{
+ if (mode == BA_INVERT) {
+ mode = (base->flag & BASE_SELECTED) != 0 ? BA_DESELECT : BA_SELECT;
+ }
+
if (base) {
- if (mode == BA_SELECT) {
- if (!(base->object->restrictflag & OB_RESTRICT_SELECT))
- base->flag |= SELECT;
- }
- else if (mode == BA_DESELECT) {
- base->flag &= ~SELECT;
+ switch (mode) {
+ case BA_SELECT:
+ if ((base->flag & BASE_SELECTABLED) != 0) {
+ base->flag |= BASE_SELECTED;
+ }
+ break;
+ case BA_DESELECT:
+ base->flag &= ~BASE_SELECTED;
+ break;
+ case BA_INVERT:
+ /* Never happens. */
+ break;
}
- base->object->flag = base->flag;
+ BKE_scene_object_base_flag_sync_from_base(base);
}
}
-/* also to set active NULL */
-void ED_base_object_activate(bContext *C, Base *base)
+/**
+ * Change active base, it includes the notifier
+ */
+void ED_object_base_activate(bContext *C, Base *base)
{
- Scene *scene = CTX_data_scene(C);
-
- /* sets scene->basact */
- BASACT = base;
-
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ view_layer->basact = base;
+
if (base) {
-
- /* XXX old signals, remember to handle notifiers now! */
- // select_actionchannel_by_name(base->object->action, "Object", 1);
-
- WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, view_layer);
}
- else
+ else {
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, NULL);
+ }
}
/********************** Selection Operators **********************/
@@ -147,7 +159,7 @@ static int object_select_by_type_exec(bContext *C, wmOperator *op)
if (extend == 0) {
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- ED_base_object_select(base, BA_DESELECT);
+ ED_object_base_select(base, BA_DESELECT);
}
CTX_DATA_END;
}
@@ -155,7 +167,7 @@ static int object_select_by_type_exec(bContext *C, wmOperator *op)
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
if (base->object->type == obtype) {
- ED_base_object_select(base, BA_SELECT);
+ ED_object_base_select(base, BA_SELECT);
}
}
CTX_DATA_END;
@@ -191,7 +203,6 @@ enum {
OBJECT_SELECT_LINKED_IPO = 1,
OBJECT_SELECT_LINKED_OBDATA,
OBJECT_SELECT_LINKED_MATERIAL,
- OBJECT_SELECT_LINKED_TEXTURE,
OBJECT_SELECT_LINKED_DUPGROUP,
OBJECT_SELECT_LINKED_PARTICLE,
OBJECT_SELECT_LINKED_LIBRARY,
@@ -202,7 +213,6 @@ static const EnumPropertyItem prop_select_linked_types[] = {
//{OBJECT_SELECT_LINKED_IPO, "IPO", 0, "Object IPO", ""}, // XXX deprecated animation system stuff...
{OBJECT_SELECT_LINKED_OBDATA, "OBDATA", 0, "Object Data", ""},
{OBJECT_SELECT_LINKED_MATERIAL, "MATERIAL", 0, "Material", ""},
- {OBJECT_SELECT_LINKED_TEXTURE, "TEXTURE", 0, "Texture", ""},
{OBJECT_SELECT_LINKED_DUPGROUP, "DUPGROUP", 0, "Dupligroup", ""},
{OBJECT_SELECT_LINKED_PARTICLE, "PARTICLE", 0, "Particle System", ""},
{OBJECT_SELECT_LINKED_LIBRARY, "LIBRARY", 0, "Library", ""},
@@ -210,38 +220,15 @@ static const EnumPropertyItem prop_select_linked_types[] = {
{0, NULL, 0, NULL, NULL}
};
-// XXX old animation system
-#if 0
-static int object_select_all_by_ipo(bContext *C, Ipo *ipo)
-{
- bool changed = false;
-
- CTX_DATA_BEGIN (C, Base *, base, visible_bases)
- {
- if (base->object->ipo == ipo) {
- base->flag |= SELECT;
- base->object->flag = base->flag;
-
- changed = true;
- }
- }
- CTX_DATA_END;
-
- return changed;
-}
-#endif
-
static bool object_select_all_by_obdata(bContext *C, void *obdata)
{
bool changed = false;
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if ((base->flag & SELECT) == 0) {
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
if (base->object->data == obdata) {
- base->flag |= SELECT;
- base->object->flag = base->flag;
-
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -251,40 +238,25 @@ static bool object_select_all_by_obdata(bContext *C, void *obdata)
return changed;
}
-static bool object_select_all_by_material_texture(bContext *C, int use_texture, Material *mat, Tex *tex)
+static bool object_select_all_by_material(bContext *C, Material *mat)
{
bool changed = false;
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if ((base->flag & SELECT) == 0) {
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
Object *ob = base->object;
Material *mat1;
- int a, b;
+ int a;
for (a = 1; a <= ob->totcol; a++) {
mat1 = give_current_material(ob, a);
- if (!use_texture) {
- if (mat1 == mat) {
- base->flag |= SELECT;
- changed = true;
- }
- }
- else if (mat1 && use_texture) {
- for (b = 0; b < MAX_MTEX; b++) {
- if (mat1->mtex[b]) {
- if (tex == mat1->mtex[b]->tex) {
- base->flag |= SELECT;
- changed = true;
- break;
- }
- }
- }
+ if (mat1 == mat) {
+ ED_object_base_select(base, BA_SELECT);
+ changed = true;
}
}
-
- base->object->flag = base->flag;
}
}
CTX_DATA_END;
@@ -299,12 +271,10 @@ static bool object_select_all_by_dup_group(bContext *C, Object *ob)
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if ((base->flag & SELECT) == 0) {
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
Group *dup_group_other = (base->object->transflag & OB_DUPLIGROUP) ? base->object->dup_group : NULL;
if (dup_group == dup_group_other) {
- base->flag |= SELECT;
- base->object->flag = base->flag;
-
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -321,23 +291,21 @@ static bool object_select_all_by_particle(bContext *C, Object *ob)
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if ((base->flag & SELECT) == 0) {
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
/* loop through other particles*/
ParticleSystem *psys;
for (psys = base->object->particlesystem.first; psys; psys = psys->next) {
if (psys->part == psys_act->part) {
- base->flag |= SELECT;
+ ED_object_base_select(base, BA_SELECT);
changed = true;
break;
}
- if (base->flag & SELECT) {
+ if (base->flag & BASE_SELECTED) {
break;
}
}
-
- base->object->flag = base->flag;
}
}
CTX_DATA_END;
@@ -351,11 +319,9 @@ static bool object_select_all_by_library(bContext *C, Library *lib)
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if ((base->flag & SELECT) == 0) {
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
if (lib == base->object->id.lib) {
- base->flag |= SELECT;
- base->object->flag = base->flag;
-
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -371,11 +337,9 @@ static bool object_select_all_by_library_obdata(bContext *C, Library *lib)
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if ((base->flag & SELECT) == 0) {
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
if (base->object->data && lib == ((ID *)base->object->data)->lib) {
- base->flag |= SELECT;
- base->object->flag = base->flag;
-
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -394,7 +358,7 @@ void ED_object_select_linked_by_id(bContext *C, ID *id)
changed = object_select_all_by_obdata(C, id);
}
else if (idtype == ID_MA) {
- changed = object_select_all_by_material_texture(C, false, (Material *)id, NULL);
+ changed = object_select_all_by_material(C, (Material *)id);
}
else if (idtype == ID_LI) {
changed = object_select_all_by_library(C, (Library *) id);
@@ -408,6 +372,7 @@ void ED_object_select_linked_by_id(bContext *C, ID *id)
static int object_select_linked_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob;
int nr = RNA_enum_get(op->ptr, "type");
bool changed = false, extend;
@@ -417,12 +382,12 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
if (extend == 0) {
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- ED_base_object_select(base, BA_DESELECT);
+ ED_object_base_select(base, BA_DESELECT);
}
CTX_DATA_END;
}
- ob = OBACT;
+ ob = OBACT(view_layer);
if (ob == NULL) {
BKE_report(op->reports, RPT_ERROR, "No active object");
return OPERATOR_CANCELLED;
@@ -440,21 +405,13 @@ static int object_select_linked_exec(bContext *C, wmOperator *op)
changed = object_select_all_by_obdata(C, ob->data);
}
- else if (nr == OBJECT_SELECT_LINKED_MATERIAL || nr == OBJECT_SELECT_LINKED_TEXTURE) {
+ else if (nr == OBJECT_SELECT_LINKED_MATERIAL) {
Material *mat = NULL;
- Tex *tex = NULL;
- bool use_texture = false;
mat = give_current_material(ob, ob->actcol);
if (mat == NULL) return OPERATOR_CANCELLED;
- if (nr == OBJECT_SELECT_LINKED_TEXTURE) {
- use_texture = true;
-
- if (mat->mtex[(int)mat->texact]) tex = mat->mtex[(int)mat->texact]->tex;
- if (tex == NULL) return OPERATOR_CANCELLED;
- }
- changed = object_select_all_by_material_texture(C, use_texture, mat, tex);
+ changed = object_select_all_by_material(C, mat);
}
else if (nr == OBJECT_SELECT_LINKED_DUPGROUP) {
if (ob->dup_group == NULL)
@@ -517,14 +474,13 @@ enum {
OBJECT_GRPSEL_PARENT = 2,
OBJECT_GRPSEL_SIBLINGS = 3,
OBJECT_GRPSEL_TYPE = 4,
- OBJECT_GRPSEL_LAYER = 5,
+ OBJECT_GRPSEL_COLLECTION = 5,
OBJECT_GRPSEL_GROUP = 6,
OBJECT_GRPSEL_HOOK = 7,
OBJECT_GRPSEL_PASS = 8,
OBJECT_GRPSEL_COLOR = 9,
- OBJECT_GRPSEL_PROPERTIES = 10,
- OBJECT_GRPSEL_KEYINGSET = 11,
- OBJECT_GRPSEL_LAMP_TYPE = 12,
+ OBJECT_GRPSEL_KEYINGSET = 10,
+ OBJECT_GRPSEL_LAMP_TYPE = 11,
};
static const EnumPropertyItem prop_select_grouped_types[] = {
@@ -533,12 +489,11 @@ static const EnumPropertyItem prop_select_grouped_types[] = {
{OBJECT_GRPSEL_PARENT, "PARENT", 0, "Parent", ""},
{OBJECT_GRPSEL_SIBLINGS, "SIBLINGS", 0, "Siblings", "Shared Parent"},
{OBJECT_GRPSEL_TYPE, "TYPE", 0, "Type", "Shared object type"},
- {OBJECT_GRPSEL_LAYER, "LAYER", 0, "Layer", "Shared layers"},
+ {OBJECT_GRPSEL_COLLECTION, "COLLECTION", 0, "Collection", "Shared collection"},
{OBJECT_GRPSEL_GROUP, "GROUP", 0, "Group", "Shared group"},
{OBJECT_GRPSEL_HOOK, "HOOK", 0, "Hook", ""},
{OBJECT_GRPSEL_PASS, "PASS", 0, "Pass", "Render pass Index"},
{OBJECT_GRPSEL_COLOR, "COLOR", 0, "Color", "Object Color"},
- {OBJECT_GRPSEL_PROPERTIES, "PROPERTIES", 0, "Properties", "Game Properties"},
{OBJECT_GRPSEL_KEYINGSET, "KEYINGSET", 0, "Keying Set", "Objects included in active Keying Set"},
{OBJECT_GRPSEL_LAMP_TYPE, "LAMP_TYPE", 0, "Lamp Type", "Matching lamp types"},
{0, NULL, 0, NULL, NULL}
@@ -551,13 +506,14 @@ static bool select_grouped_children(bContext *C, Object *ob, const bool recursiv
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
if (ob == base->object->parent) {
- if (!(base->flag & SELECT)) {
- ED_base_object_select(base, BA_SELECT);
+ if ((base->flag & BASE_SELECTED) == 0) {
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
- if (recursive)
+ if (recursive) {
changed |= select_grouped_children(C, base->object, 1);
+ }
}
}
CTX_DATA_END;
@@ -566,20 +522,20 @@ static bool select_grouped_children(bContext *C, Object *ob, const bool recursiv
static bool select_grouped_parent(bContext *C) /* Makes parent active and de-selected OBACT */
{
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
-
- bool changed = false;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Base *baspar, *basact = CTX_data_active_base(C);
+ bool changed = false;
- if (!basact || !(basact->object->parent)) return 0; /* we know OBACT is valid */
+ if (!basact || !(basact->object->parent)) {
+ return 0; /* we know OBACT is valid */
+ }
- baspar = BKE_scene_base_find(scene, basact->object->parent);
+ baspar = BKE_view_layer_base_find(view_layer, basact->object->parent);
/* can be NULL if parent in other scene */
- if (baspar && BASE_SELECTABLE(v3d, baspar)) {
- ED_base_object_select(baspar, BA_SELECT);
- ED_base_object_activate(C, baspar);
+ if (baspar && BASE_SELECTABLE(baspar)) {
+ ED_object_base_select(baspar, BA_SELECT);
+ ED_object_base_activate(C, baspar);
changed = true;
}
return changed;
@@ -608,9 +564,11 @@ static bool select_grouped_group(bContext *C, Object *ob) /* Select objects in
group = ob_groups[0];
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if (!(base->flag & SELECT) && BKE_group_object_exists(group, base->object)) {
- ED_base_object_select(base, BA_SELECT);
- changed = true;
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+ if (BKE_group_object_exists(group, base->object)) {
+ ED_object_base_select(base, BA_SELECT);
+ changed = true;
+ }
}
}
CTX_DATA_END;
@@ -632,8 +590,7 @@ static bool select_grouped_group(bContext *C, Object *ob) /* Select objects in
static bool select_grouped_object_hooks(bContext *C, Object *ob)
{
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
bool changed = false;
Base *base;
@@ -643,10 +600,10 @@ static bool select_grouped_object_hooks(bContext *C, Object *ob)
for (md = ob->modifiers.first; md; md = md->next) {
if (md->type == eModifierType_Hook) {
hmd = (HookModifierData *) md;
- if (hmd->object && !(hmd->object->flag & SELECT)) {
- base = BKE_scene_base_find(scene, hmd->object);
- if (base && (BASE_SELECTABLE(v3d, base))) {
- ED_base_object_select(base, BA_SELECT);
+ if (hmd->object) {
+ base = BKE_view_layer_base_find(view_layer, hmd->object);
+ if (base && ((base->flag & BASE_SELECTED) == 0) && (BASE_SELECTABLE(base))) {
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -663,8 +620,8 @@ static bool select_grouped_siblings(bContext *C, Object *ob)
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
- if ((base->object->parent == ob->parent) && !(base->flag & SELECT)) {
- ED_base_object_select(base, BA_SELECT);
+ if ((base->object->parent == ob->parent) && ((base->flag & BASE_SELECTED) == 0)) {
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -681,8 +638,8 @@ static bool select_grouped_lamptype(bContext *C, Object *ob)
{
if (base->object->type == OB_LAMP) {
Lamp *la_test = base->object->data;
- if ((la->type == la_test->type) && !(base->flag & SELECT)) {
- ED_base_object_select(base, BA_SELECT);
+ if ((la->type == la_test->type) && ((base->flag & BASE_SELECTED) == 0)) {
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -696,8 +653,8 @@ static bool select_grouped_type(bContext *C, Object *ob)
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
- if ((base->object->type == ob->type) && !(base->flag & SELECT)) {
- ED_base_object_select(base, BA_SELECT);
+ if ((base->object->type == ob->type) && ((base->flag & BASE_SELECTED) == 0)) {
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -705,44 +662,68 @@ static bool select_grouped_type(bContext *C, Object *ob)
return changed;
}
-static bool select_grouped_layer(bContext *C, Object *ob)
+#define COLLECTION_MENU_MAX 24
+static bool select_grouped_collection(bContext *C, Object *ob) /* Select objects in the same collection as the active */
{
+ typedef struct EnumeratedCollection {
+ struct SceneCollection *collection;
+ int index;
+ } EnumeratedCollection;
+
bool changed = false;
+ SceneCollection *collection;
+ EnumeratedCollection ob_collections[COLLECTION_MENU_MAX];
+ int collection_count = 0, i;
+ uiPopupMenu *pup;
+ uiLayout *layout;
- CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
+ i = 0;
+ FOREACH_SCENE_COLLECTION_BEGIN(CTX_data_scene(C), scene_collection)
{
- if ((base->lay & ob->lay) && !(base->flag & SELECT)) {
- ED_base_object_select(base, BA_SELECT);
- changed = true;
+ if (BKE_collection_object_exists(scene_collection, ob)) {
+ ob_collections[collection_count].index = i;
+ ob_collections[collection_count].collection = scene_collection;
+ if (++collection_count >= COLLECTION_MENU_MAX) {
+ break;
+ }
}
+ i++;
}
- CTX_DATA_END;
- return changed;
-}
+ FOREACH_SCENE_COLLECTION_END;
-static bool select_grouped_index_object(bContext *C, Object *ob)
-{
- bool changed = false;
+ if (!collection_count) {
+ return 0;
+ }
+ else if (collection_count == 1) {
+ collection = ob_collections[0].collection;
+ return BKE_collection_objects_select(CTX_data_view_layer(C), collection);
+ }
- CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
- {
- if ((base->object->index == ob->index) && !(base->flag & SELECT)) {
- ED_base_object_select(base, BA_SELECT);
- changed = true;
- }
+ /* build the menu. */
+ pup = UI_popup_menu_begin(C, IFACE_("Select Collection"), ICON_NONE);
+ layout = UI_popup_menu_layout(pup);
+
+ for (i = 0; i < collection_count; i++) {
+ uiItemIntO(layout,
+ ob_collections[i].collection->name,
+ ICON_NONE,
+ "OBJECT_OT_select_same_collection",
+ "collection_index",
+ ob_collections[i].index);
}
- CTX_DATA_END;
- return changed;
+
+ UI_popup_menu_end(C, pup);
+ return changed; /* The operator already handle this! */
}
-static bool select_grouped_color(bContext *C, Object *ob)
+static bool select_grouped_index_object(bContext *C, Object *ob)
{
bool changed = false;
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
- if (!(base->flag & SELECT) && (compare_v3v3(base->object->col, ob->col, 0.005f))) {
- ED_base_object_select(base, BA_SELECT);
+ if ((base->object->index == ob->index) && ((base->flag & BASE_SELECTED) == 0)) {
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -750,26 +731,14 @@ static bool select_grouped_color(bContext *C, Object *ob)
return changed;
}
-static bool objects_share_gameprop(Object *a, Object *b)
-{
- bProperty *prop;
-
- for (prop = a->prop.first; prop; prop = prop->next) {
- if (BKE_bproperty_object_get(b, prop->name)) {
- return 1;
- }
- }
- return 0;
-}
-
-static bool select_grouped_gameprops(bContext *C, Object *ob)
+static bool select_grouped_color(bContext *C, Object *ob)
{
bool changed = false;
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
- if (!(base->flag & SELECT) && (objects_share_gameprop(base->object, ob))) {
- ED_base_object_select(base, BA_SELECT);
+ if (((base->flag & BASE_SELECTED) == 0) && (compare_v3v3(base->object->col, ob->col, 0.005f))) {
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -807,7 +776,7 @@ static bool select_grouped_keyingset(bContext *C, Object *UNUSED(ob), ReportList
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
/* only check for this object if it isn't selected already, to limit time wasted */
- if ((base->flag & SELECT) == 0) {
+ if ((base->flag & BASE_SELECTED) == 0) {
KS_Path *ksp;
/* this is the slow way... we could end up with > 500 items here,
@@ -816,7 +785,7 @@ static bool select_grouped_keyingset(bContext *C, Object *UNUSED(ob), ReportList
for (ksp = ks->paths.first; ksp; ksp = ksp->next) {
/* if id matches, select then stop looping (match found) */
if (ksp->id == (ID *)base->object) {
- ED_base_object_select(base, BA_SELECT);
+ ED_object_base_select(base, BA_SELECT);
changed = true;
break;
}
@@ -831,6 +800,7 @@ static bool select_grouped_keyingset(bContext *C, Object *UNUSED(ob), ReportList
static int object_select_grouped_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob;
const int type = RNA_enum_get(op->ptr, "type");
bool changed = false, extend;
@@ -840,13 +810,13 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
if (extend == 0) {
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- ED_base_object_select(base, BA_DESELECT);
+ ED_object_base_select(base, BA_DESELECT);
changed = true;
}
CTX_DATA_END;
}
- ob = OBACT;
+ ob = OBACT(view_layer);
if (ob == NULL) {
BKE_report(op->reports, RPT_ERROR, "No active object");
return OPERATOR_CANCELLED;
@@ -868,8 +838,8 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
case OBJECT_GRPSEL_TYPE:
changed |= select_grouped_type(C, ob);
break;
- case OBJECT_GRPSEL_LAYER:
- changed |= select_grouped_layer(C, ob);
+ case OBJECT_GRPSEL_COLLECTION:
+ changed |= select_grouped_collection(C, ob);
break;
case OBJECT_GRPSEL_GROUP:
changed |= select_grouped_group(C, ob);
@@ -883,9 +853,6 @@ static int object_select_grouped_exec(bContext *C, wmOperator *op)
case OBJECT_GRPSEL_COLOR:
changed |= select_grouped_color(C, ob);
break;
- case OBJECT_GRPSEL_PROPERTIES:
- changed |= select_grouped_gameprops(C, ob);
- break;
case OBJECT_GRPSEL_KEYINGSET:
changed |= select_grouped_keyingset(C, ob, op->reports);
break;
@@ -928,85 +895,6 @@ void OBJECT_OT_select_grouped(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "type", prop_select_grouped_types, 0, "Type", "");
}
-/************************* Select by Layer **********************/
-enum {
- OB_SEL_LAYERMATCH_EXACT = 1,
- OB_SEL_LAYERMATCH_SHARED = 2,
-};
-
-static int object_select_by_layer_exec(bContext *C, wmOperator *op)
-{
- unsigned int layernum;
- bool extend;
- int match;
-
- extend = RNA_boolean_get(op->ptr, "extend");
- layernum = RNA_int_get(op->ptr, "layers");
- match = RNA_enum_get(op->ptr, "match");
-
- if (extend == false) {
- CTX_DATA_BEGIN (C, Base *, base, visible_bases)
- {
- ED_base_object_select(base, BA_DESELECT);
- }
- CTX_DATA_END;
- }
-
- CTX_DATA_BEGIN (C, Base *, base, visible_bases)
- {
- bool ok = false;
-
- switch (match) {
- case OB_SEL_LAYERMATCH_EXACT:
- /* Mask out bits used for local view, only work on real layer ones, see T45783. */
- ok = ((base->lay & ((1 << 20) - 1)) == (1 << (layernum - 1)));
- break;
- case OB_SEL_LAYERMATCH_SHARED:
- ok = (base->lay & (1 << (layernum - 1))) != 0;
- break;
- default:
- break;
- }
-
- if (ok) {
- ED_base_object_select(base, BA_SELECT);
- }
- }
- CTX_DATA_END;
-
- /* undo? */
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
-
- return OPERATOR_FINISHED;
-}
-
-void OBJECT_OT_select_by_layer(wmOperatorType *ot)
-{
- static const EnumPropertyItem match_items[] = {
- {OB_SEL_LAYERMATCH_EXACT, "EXACT", 0, "Exact Match", ""},
- {OB_SEL_LAYERMATCH_SHARED, "SHARED", 0, "Shared Layers", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- /* identifiers */
- ot->name = "Select by Layer";
- ot->description = "Select all visible objects on a layer";
- ot->idname = "OBJECT_OT_select_by_layer";
-
- /* api callbacks */
- /*ot->invoke = XXX - need a int grid popup*/
- ot->exec = object_select_by_layer_exec;
- ot->poll = objects_selectable_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_enum(ot->srna, "match", match_items, OB_SEL_LAYERMATCH_EXACT, "Match", "");
- RNA_def_boolean(ot->srna, "extend", false, "Extend", "Extend selection instead of deselecting everything first");
- RNA_def_int(ot->srna, "layers", 1, 1, 20, "Layer", "", 1, 20);
-}
-
/**************************** (De)select All ****************************/
static int object_select_all_exec(bContext *C, wmOperator *op)
@@ -1020,7 +908,7 @@ static int object_select_all_exec(bContext *C, wmOperator *op)
action = SEL_SELECT;
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if (base->flag & SELECT) {
+ if ((base->flag & BASE_SELECTED) != 0) {
action = SEL_DESELECT;
break;
}
@@ -1032,17 +920,17 @@ static int object_select_all_exec(bContext *C, wmOperator *op)
{
switch (action) {
case SEL_SELECT:
- ED_base_object_select(base, BA_SELECT);
+ ED_object_base_select(base, BA_SELECT);
break;
case SEL_DESELECT:
- ED_base_object_select(base, BA_DESELECT);
+ ED_object_base_select(base, BA_DESELECT);
break;
case SEL_INVERT:
- if (base->flag & SELECT) {
- ED_base_object_select(base, BA_DESELECT);
+ if ((base->flag & BASE_SELECTED) != 0) {
+ ED_object_base_select(base, BA_DESELECT);
}
else {
- ED_base_object_select(base, BA_SELECT);
+ ED_object_base_select(base, BA_SELECT);
}
break;
}
@@ -1092,8 +980,11 @@ static int object_select_same_group_exec(bContext *C, wmOperator *op)
CTX_DATA_BEGIN (C, Base *, base, visible_bases)
{
- if (!(base->flag & SELECT) && BKE_group_object_exists(group, base->object))
- ED_base_object_select(base, BA_SELECT);
+ if (((base->flag & BASE_SELECTED) == 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+ if (BKE_group_object_exists(group, base->object)) {
+ ED_object_base_select(base, BA_SELECT);
+ }
+ }
}
CTX_DATA_END;
@@ -1120,10 +1011,54 @@ void OBJECT_OT_select_same_group(wmOperatorType *ot)
RNA_def_string(ot->srna, "group", NULL, MAX_ID_NAME, "Group", "Name of the group to select");
}
+/**************************** Select In The Same Collection ****************************/
+
+static int object_select_same_collection_exec(bContext *C, wmOperator *op)
+{
+ SceneCollection *collection;
+
+ /* passthrough if no objects are visible */
+ if (CTX_DATA_COUNT(C, visible_bases) == 0) return OPERATOR_PASS_THROUGH;
+
+ int collection_index = RNA_int_get(op->ptr, "collection_index");
+ collection = BKE_collection_from_index(CTX_data_scene(C), collection_index);
+
+ if (!collection) {
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ if (BKE_collection_objects_select(CTX_data_view_layer(C), collection)) {
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+ }
+
+ return OPERATOR_FINISHED;
+}
+
+void OBJECT_OT_select_same_collection(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Select Same Collection";
+ ot->description = "Select object in the same collection";
+ ot->idname = "OBJECT_OT_select_same_collection";
+
+ /* api callbacks */
+ ot->exec = object_select_same_collection_exec;
+ ot->poll = objects_selectable_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ prop = RNA_def_int(ot->srna, "collection_index", -1, -1, INT_MAX,
+ "Collection Index", "Index of the collection to select", 0, INT_MAX);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+}
/**************************** Select Mirror ****************************/
static int object_select_mirror_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
bool extend;
extend = RNA_boolean_get(op->ptr, "extend");
@@ -1137,15 +1072,15 @@ static int object_select_mirror_exec(bContext *C, wmOperator *op)
if (!STREQ(name_flip, primbase->object->id.name + 2)) {
Object *ob = (Object *)BKE_libblock_find_name(ID_OB, name_flip);
if (ob) {
- Base *secbase = BKE_scene_base_find(scene, ob);
+ Base *secbase = BKE_view_layer_base_find(view_layer, ob);
if (secbase) {
- ED_base_object_select(secbase, BA_SELECT);
+ ED_object_base_select(secbase, BA_SELECT);
}
}
}
- if (extend == false) ED_base_object_select(primbase, BA_DESELECT);
+ if (extend == false) ED_object_base_select(primbase, BA_DESELECT);
}
CTX_DATA_END;
@@ -1180,9 +1115,9 @@ void OBJECT_OT_select_mirror(wmOperatorType *ot)
static bool object_select_more_less(bContext *C, const bool select)
{
- Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- for (Base *base = scene->base.first; base; base = base->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
Object *ob = base->object;
ob->flag &= ~OB_DONE;
ob->id.tag &= ~LIB_TAG_DOIT;
@@ -1217,13 +1152,13 @@ static bool object_select_more_less(bContext *C, const bool select)
bool changed = false;
const short select_mode = select ? BA_SELECT : BA_DESELECT;
- const short select_flag = select ? SELECT : 0;
+ const short select_flag = select ? BASE_SELECTED : 0;
for (ctx_base = ctx_base_list.first; ctx_base; ctx_base = ctx_base->next) {
Base *base = ctx_base->ptr.data;
Object *ob = base->object;
- if ((ob->id.tag & LIB_TAG_DOIT) && ((ob->flag & SELECT) != select_flag)) {
- ED_base_object_select(base, select_mode);
+ if ((ob->id.tag & LIB_TAG_DOIT) && ((base->flag & BASE_SELECTED) != select_flag)) {
+ ED_object_base_select(base, select_mode);
changed = true;
}
}
@@ -1305,7 +1240,7 @@ static int object_select_random_exec(bContext *C, wmOperator *op)
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
if (BLI_rng_get_float(rng) < randfac) {
- ED_base_object_select(base, select);
+ ED_object_base_select(base, select);
}
}
CTX_DATA_END;
diff --git a/source/blender/editors/object/object_shapekey.c b/source/blender/editors/object/object_shapekey.c
index 27da607c696..1f80cb5f0bc 100644
--- a/source/blender/editors/object/object_shapekey.c
+++ b/source/blender/editors/object/object_shapekey.c
@@ -51,7 +51,6 @@
#include "DNA_object_types.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_key.h"
#include "BKE_library.h"
#include "BKE_main.h"
@@ -59,6 +58,9 @@
#include "BKE_lattice.h"
#include "BKE_curve.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "BLI_sys_types.h" // for intptr_t support
#include "ED_object.h"
@@ -213,7 +215,7 @@ static bool object_shape_key_mirror(bContext *C, Object *ob,
*r_totmirr = totmirr;
*r_totfail = totfail;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return 1;
@@ -264,8 +266,8 @@ static int shape_key_add_exec(bContext *C, wmOperator *op)
ED_object_shape_key_add(C, ob, from_mix);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(CTX_data_main(C));
return OPERATOR_FINISHED;
}
@@ -302,8 +304,8 @@ static int shape_key_remove_exec(bContext *C, wmOperator *op)
}
if (changed) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
@@ -343,7 +345,7 @@ static int shape_key_clear_exec(bContext *C, wmOperator *UNUSED(op))
for (kb = key->block.first; kb; kb = kb->next)
kb->curval = 0.0f;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
@@ -378,7 +380,7 @@ static int shape_key_retime_exec(bContext *C, wmOperator *UNUSED(op))
for (kb = key->block.first; kb; kb = kb->next)
kb->pos = (cfra += 0.1f);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
@@ -469,7 +471,7 @@ static int shape_key_move_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/object/object_transform.c b/source/blender/editors/object/object_transform.c
index e29d49d00cb..f3045d44826 100644
--- a/source/blender/editors/object/object_transform.c
+++ b/source/blender/editors/object/object_transform.c
@@ -40,14 +40,15 @@
#include "DNA_scene_types.h"
#include "DNA_group_types.h"
#include "DNA_lattice_types.h"
+#include "DNA_lamp_types.h"
#include "BLI_math.h"
#include "BLI_listbase.h"
#include "BLI_utildefines.h"
+#include "BLI_array.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_idcode.h"
#include "BKE_mball.h"
@@ -60,6 +61,8 @@
#include "BKE_lattice.h"
#include "BKE_tracking.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_define.h"
#include "RNA_access.h"
@@ -72,6 +75,8 @@
#include "ED_screen.h"
#include "ED_view3d.h"
+#include "MEM_guardedalloc.h"
+
#include "object_intern.h"
/*************************** Clear Transformation ****************************/
@@ -266,7 +271,7 @@ static int object_clear_transform_generic_exec(bContext *C, wmOperator *op,
ED_autokeyframe_object(C, scene, ob, ks);
/* tag for updates */
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
}
CTX_DATA_END;
@@ -372,7 +377,7 @@ static int object_origin_clear_exec(bContext *C, wmOperator *UNUSED(op))
mul_m3_v3(mat, v3);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
CTX_DATA_END;
@@ -400,16 +405,17 @@ void OBJECT_OT_origin_clear(wmOperatorType *ot)
/* use this when the loc/size/rot of the parent has changed but the children
* should stay in the same place, e.g. for apply-size-rot or object center */
-static void ignore_parent_tx(Main *bmain, Scene *scene, Object *ob)
+static void ignore_parent_tx(const bContext *C, Main *bmain, Scene *scene, Object *ob)
{
Object workob;
Object *ob_child;
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
/* a change was made, adjust the children to compensate */
for (ob_child = bmain->object.first; ob_child; ob_child = ob_child->id.next) {
if (ob_child->parent == ob) {
BKE_object_apply_mat4(ob_child, ob_child->obmat, true, false);
- BKE_object_workob_calc_parent(scene, ob_child, &workob);
+ BKE_object_workob_calc_parent(depsgraph, scene, ob_child, &workob);
invert_m4_m4(ob_child->parentinv, workob.obmat);
}
}
@@ -422,9 +428,10 @@ static int apply_objects_internal(
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
float rsmat[3][3], obmat[3][3], iobmat[3][3], mat[4][4], scale;
bool changed = true;
-
+
/* first check if we can execute */
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
{
@@ -538,7 +545,7 @@ static int apply_objects_internal(
Mesh *me = ob->data;
if (apply_scale)
- multiresModifier_scale_disp(scene, ob);
+ multiresModifier_scale_disp(depsgraph, scene, ob);
/* adjust data */
BKE_mesh_transform(me, mat, true);
@@ -644,14 +651,14 @@ static int apply_objects_internal(
unit_axis_angle(ob->rotAxis, &ob->rotAngle);
}
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(depsgraph, scene, ob);
if (ob->type == OB_ARMATURE) {
- BKE_pose_where_is(scene, ob); /* needed for bone parents */
+ BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */
}
- ignore_parent_tx(bmain, scene, ob);
+ ignore_parent_tx(C, bmain, scene, ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA);
changed = true;
}
@@ -669,16 +676,17 @@ static int apply_objects_internal(
static int visual_transform_apply_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
bool changed = false;
-
+
CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
{
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(depsgraph, scene, ob);
BKE_object_apply_mat4(ob, ob->obmat, true, true);
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(depsgraph, scene, ob);
/* update for any children that may get moved */
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
changed = true;
}
@@ -759,6 +767,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
Object *obact = CTX_data_active_object(C);
Object *obedit = CTX_data_edit_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Object *tob;
float cursor[3], cent[3], cent_neg[3], centn[3];
int centermode = RNA_enum_get(op->ptr, "type");
@@ -822,7 +831,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
EDBM_mesh_normals_update(em);
tot_change++;
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
}
}
@@ -883,7 +892,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
float min[3], max[3];
/* only bounds support */
INIT_MINMAX(min, max);
- BKE_object_minmax_dupli(scene, ob, min, max, true);
+ BKE_object_minmax_dupli(depsgraph, scene, ob, min, max, true);
mid_v3_v3v3(cent, min, max);
invert_m4_m4(ob->imat, ob->obmat);
mul_m4_v3(ob->imat, cent);
@@ -947,7 +956,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
if (obedit) {
if (centermode == GEOMETRY_TO_ORIGIN) {
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
}
break;
}
@@ -994,16 +1003,16 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
/* Function to recenter armatures in editarmature.c
* Bone + object locations are handled there.
*/
- ED_armature_origin_set(scene, ob, cursor, centermode, around);
+ ED_armature_origin_set(ob, cursor, centermode, around);
tot_change++;
arm->id.tag |= LIB_TAG_DOIT;
/* do_inverse_offset = true; */ /* docenter_armature() handles this */
- BKE_object_where_is_calc(scene, ob);
- BKE_pose_where_is(scene, ob); /* needed for bone parents */
+ BKE_object_where_is_calc(depsgraph, scene, ob);
+ BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */
- ignore_parent_tx(bmain, scene, ob);
+ ignore_parent_tx(C, bmain, scene, ob);
if (obedit)
break;
@@ -1025,7 +1034,7 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
if (obedit) {
if (centermode == GEOMETRY_TO_ORIGIN) {
- DAG_id_tag_update(&obedit->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obedit->id, OB_RECALC_DATA);
}
break;
}
@@ -1059,12 +1068,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
add_v3_v3(ob->loc, centn);
- BKE_object_where_is_calc(scene, ob);
+ BKE_object_where_is_calc(depsgraph, scene, ob);
if (ob->type == OB_ARMATURE) {
- BKE_pose_where_is(scene, ob); /* needed for bone parents */
+ BKE_pose_where_is(depsgraph, scene, ob); /* needed for bone parents */
}
- ignore_parent_tx(bmain, scene, ob);
+ ignore_parent_tx(C, bmain, scene, ob);
/* other users? */
//CTX_DATA_BEGIN (C, Object *, ob_other, selected_editable_objects)
@@ -1083,16 +1092,16 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
(ob->transflag | ob_other->transflag) & OB_DUPLIGROUP)))
{
ob_other->flag |= OB_DONE;
- DAG_id_tag_update(&ob_other->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_other->id, OB_RECALC_OB | OB_RECALC_DATA);
mul_v3_mat3_m4v3(centn, ob_other->obmat, cent); /* omit translation part */
add_v3_v3(ob_other->loc, centn);
- BKE_object_where_is_calc(scene, ob_other);
+ BKE_object_where_is_calc(depsgraph, scene, ob_other);
if (ob_other->type == OB_ARMATURE) {
- BKE_pose_where_is(scene, ob_other); /* needed for bone parents */
+ BKE_pose_where_is(depsgraph, scene, ob_other); /* needed for bone parents */
}
- ignore_parent_tx(bmain, scene, ob_other);
+ ignore_parent_tx(C, bmain, scene, ob_other);
}
}
//CTX_DATA_END;
@@ -1101,9 +1110,12 @@ static int object_origin_set_exec(bContext *C, wmOperator *op)
}
BLI_freelistN(&ctx_data_list);
- for (tob = bmain->object.first; tob; tob = tob->id.next)
- if (tob->data && (((ID *)tob->data)->tag & LIB_TAG_DOIT))
- DAG_id_tag_update(&tob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ for (tob = bmain->object.first; tob; tob = tob->id.next) {
+ if (tob->data && (((ID *)tob->data)->tag & LIB_TAG_DOIT)) {
+ BKE_mesh_batch_cache_dirty(tob->data, BKE_MESH_BATCH_DIRTY_ALL);
+ DEG_id_tag_update(&tob->id, OB_RECALC_OB | OB_RECALC_DATA);
+ }
+ }
if (tot_change) {
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
@@ -1160,3 +1172,385 @@ void OBJECT_OT_origin_set(wmOperatorType *ot)
ot->prop = RNA_def_enum(ot->srna, "type", prop_set_center_types, 0, "Type", "");
RNA_def_enum(ot->srna, "center", prop_set_bounds_types, V3D_AROUND_CENTER_MEAN, "Center", "");
}
+
+/* -------------------------------------------------------------------- */
+
+/** \name Transform Axis Target
+ *
+ * Note this is an experemental operator to point lamps/cameras at objects.
+ * We may re-work how this behaves based on user feedback.
+ * - campbell.
+ * \{ */
+
+/* When using multiple objects, apply their relative rotational offset to the active object. */
+#define USE_RELATIVE_ROTATION
+
+struct XFormAxisItem {
+ Object *ob;
+ float rot_mat[3][3];
+ void *obtfm;
+ float xform_dist;
+
+#ifdef USE_RELATIVE_ROTATION
+ /* use when translating multiple */
+ float xform_rot_offset[3][3];
+#endif
+};
+
+struct XFormAxisData {
+ ViewContext vc;
+ struct {
+ float depth;
+ float normal[3];
+ bool is_depth_valid;
+ bool is_normal_valid;
+ } prev;
+
+ struct XFormAxisItem *object_data;
+ uint object_data_len;
+ bool is_translate;
+
+ int init_event;
+};
+
+static bool object_is_target_compat(const Object *ob)
+{
+ if (ob->type == OB_LAMP) {
+ const Lamp *la = ob->data;
+ if (ELEM(la->type, LA_SUN, LA_SPOT, LA_HEMI, LA_AREA)) {
+ return true;
+ }
+ }
+ /* We might want to enable this later, for now just lamps */
+#if 0
+ else if (ob->type == OB_CAMERA) {
+ return true;
+ }
+#endif
+ return false;
+}
+
+static void object_transform_axis_target_free_data(wmOperator *op)
+{
+ struct XFormAxisData *xfd = op->customdata;
+ struct XFormAxisItem *item = xfd->object_data;
+ for (int i = 0; i < xfd->object_data_len; i++, item++) {
+ MEM_freeN(item->obtfm);
+ }
+ MEM_freeN(xfd->object_data);
+ MEM_freeN(xfd);
+ op->customdata = NULL;
+}
+
+/* We may want to expose as alternative to: BKE_object_apply_rotation */
+static void object_apply_rotation(Object *ob, const float rmat[3][3])
+{
+ float size[3];
+ float loc[3];
+ float rmat4[4][4];
+ copy_m4_m3(rmat4, rmat);
+
+ copy_v3_v3(size, ob->size);
+ copy_v3_v3(loc, ob->loc);
+ BKE_object_apply_mat4(ob, rmat4, true, true);
+ copy_v3_v3(ob->size, size);
+ copy_v3_v3(ob->loc, loc);
+}
+/* We may want to extract this to: BKE_object_apply_location */
+static void object_apply_location(Object *ob, const float loc[3])
+{
+ /* quick but weak */
+ Object ob_prev = *ob;
+ float mat[4][4];
+ copy_m4_m4(mat, ob->obmat);
+ copy_v3_v3(mat[3], loc);
+ BKE_object_apply_mat4(ob, mat, true, true);
+ copy_v3_v3(mat[3], ob->loc);
+ *ob = ob_prev;
+ copy_v3_v3(ob->loc, mat[3]);
+}
+
+static void object_orient_to_location(
+ Object *ob, float rot_orig[3][3], const float axis[3], const float location[3])
+{
+ float delta[3];
+ sub_v3_v3v3(delta, ob->obmat[3], location);
+ if (normalize_v3(delta) != 0.0f) {
+ if (len_squared_v3v3(delta, axis) > FLT_EPSILON) {
+ float delta_rot[3][3];
+ float final_rot[3][3];
+ rotation_between_vecs_to_mat3(delta_rot, axis, delta);
+
+ mul_m3_m3m3(final_rot, delta_rot, rot_orig);
+
+ object_apply_rotation(ob, final_rot);
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
+ }
+ }
+}
+
+static void object_transform_axis_target_cancel(bContext *C, wmOperator *op)
+{
+ struct XFormAxisData *xfd = op->customdata;
+ struct XFormAxisItem *item = xfd->object_data;
+ for (int i = 0; i < xfd->object_data_len; i++, item++) {
+ BKE_object_tfm_restore(item->ob, item->obtfm);
+ DEG_id_tag_update(&item->ob->id, OB_RECALC_OB);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, item->ob);
+ }
+
+ object_transform_axis_target_free_data(op);
+}
+
+static int object_transform_axis_target_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ ViewContext vc;
+ ED_view3d_viewcontext_init(C, &vc);
+
+ if (!object_is_target_compat(vc.obact)) {
+ /* Falls back to texture space transform. */
+ return OPERATOR_PASS_THROUGH;
+ }
+
+ ED_view3d_autodist_init(vc.depsgraph, vc.ar, vc.v3d, 0);
+
+ if (vc.rv3d->depths != NULL) {
+ vc.rv3d->depths->damaged = true;
+ }
+ ED_view3d_depth_update(vc.ar);
+
+ if (vc.rv3d->depths == NULL) {
+ BKE_report(op->reports, RPT_WARNING, "Unable to access depth buffer, using view plane");
+ return OPERATOR_CANCELLED;
+ }
+
+ ED_region_tag_redraw(vc.ar);
+
+ struct XFormAxisData *xfd;
+ xfd = op->customdata = MEM_callocN(sizeof(struct XFormAxisData), __func__);
+
+ /* Don't change this at runtime. */
+ xfd->vc = vc;
+ xfd->vc.mval[0] = event->mval[0];
+ xfd->vc.mval[1] = event->mval[1];
+
+ xfd->prev.depth = 1.0f;
+ xfd->prev.is_depth_valid = false;
+ xfd->prev.is_normal_valid = false;
+ xfd->is_translate = false;
+
+ xfd->init_event = WM_userdef_event_type_from_keymap_type(event->type);
+
+ {
+ struct XFormAxisItem *object_data = NULL;
+ BLI_array_declare(object_data);
+
+ struct XFormAxisItem *item = BLI_array_append_ret(object_data);
+ item->ob = xfd->vc.obact;
+
+ CTX_DATA_BEGIN (C, Object *, ob, selected_editable_objects)
+ {
+ if ((ob != xfd->vc.obact) && object_is_target_compat(ob)) {
+ item = BLI_array_append_ret(object_data);
+ item->ob = ob;
+ }
+ }
+ CTX_DATA_END;
+
+ xfd->object_data = object_data;
+ xfd->object_data_len = BLI_array_len(object_data);
+
+ if (xfd->object_data_len != BLI_array_len(object_data)) {
+ xfd->object_data = MEM_reallocN(xfd->object_data, xfd->object_data_len * sizeof(*xfd->object_data));
+ }
+ }
+
+ {
+ struct XFormAxisItem *item = xfd->object_data;
+ for (int i = 0; i < xfd->object_data_len; i++, item++) {
+ item->obtfm = BKE_object_tfm_backup(item->ob);
+ BKE_object_rot_to_mat3(item->ob, item->rot_mat, true);
+ }
+ }
+
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static int object_transform_axis_target_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ struct XFormAxisData *xfd = op->customdata;
+ ARegion *ar = xfd->vc.ar;
+
+ view3d_operator_needs_opengl(C);
+
+ const bool is_translate = (event->ctrl != 0);
+ const bool is_translate_init = is_translate && (xfd->is_translate != is_translate);
+
+ if (event->type == MOUSEMOVE || is_translate_init) {
+ const ViewDepths *depths = xfd->vc.rv3d->depths;
+ if (depths &&
+ ((unsigned int)event->mval[0] < depths->w) &&
+ ((unsigned int)event->mval[1] < depths->h))
+ {
+ double depth = (double)ED_view3d_depth_read_cached(&xfd->vc, event->mval);
+ float location_world[3];
+ if (depth == 1.0f) {
+ if (xfd->prev.is_depth_valid) {
+ depth = (double)xfd->prev.depth;
+ }
+ }
+ if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
+ xfd->prev.depth = depth;
+ xfd->prev.is_depth_valid = true;
+ if (ED_view3d_depth_unproject(ar, event->mval, depth, location_world)) {
+ if (is_translate) {
+
+ float normal[3];
+ bool normal_found = false;
+ if (ED_view3d_depth_read_cached_normal(&xfd->vc, event->mval, normal)) {
+ normal_found = true;
+
+ /* cheap attempt to smooth normals out a bit! */
+ const uint ofs = 2;
+ for (uint x = -ofs; x <= ofs; x += ofs / 2) {
+ for (uint y = -ofs; y <= ofs; y += ofs / 2) {
+ if (x != 0 && y != 0) {
+ int mval_ofs[2] = {event->mval[0] + x, event->mval[1] + y};
+ float n[3];
+ if (ED_view3d_depth_read_cached_normal(
+ &xfd->vc, mval_ofs, n))
+ {
+ add_v3_v3(normal, n);
+ }
+ }
+ }
+ }
+ normalize_v3(normal);
+ }
+ else if (xfd->prev.is_normal_valid) {
+ copy_v3_v3(normal, xfd->prev.normal);
+ normal_found = true;
+ }
+
+ if (normal_found) {
+#ifdef USE_RELATIVE_ROTATION
+ if (is_translate_init && xfd->object_data_len > 1) {
+ float xform_rot_offset_inv_first[3][3];
+ struct XFormAxisItem *item = xfd->object_data;
+ for (int i = 0; i < xfd->object_data_len; i++, item++) {
+ copy_m3_m4(item->xform_rot_offset, item->ob->obmat);
+ normalize_m3(item->xform_rot_offset);
+
+ if (i == 0) {
+ invert_m3_m3(xform_rot_offset_inv_first, xfd->object_data[0].xform_rot_offset);
+ }
+ else {
+ mul_m3_m3m3(item->xform_rot_offset,
+ item->xform_rot_offset,
+ xform_rot_offset_inv_first);
+ }
+ }
+ }
+
+#endif
+
+ struct XFormAxisItem *item = xfd->object_data;
+ for (int i = 0; i < xfd->object_data_len; i++, item++) {
+ if (is_translate_init) {
+ float ob_axis[3];
+ item->xform_dist = len_v3v3(item->ob->obmat[3], location_world);
+ normalize_v3_v3(ob_axis, item->ob->obmat[2]);
+ /* Scale to avoid adding distance when moving between surfaces. */
+ float scale = fabsf(dot_v3v3(ob_axis, normal));
+ item->xform_dist *= scale;
+ }
+
+ float target_normal[3];
+ copy_v3_v3(target_normal, normal);
+
+#ifdef USE_RELATIVE_ROTATION
+ if (i != 0) {
+ mul_m3_v3(item->xform_rot_offset, target_normal);
+ }
+#endif
+ {
+ float loc[3];
+
+ copy_v3_v3(loc, location_world);
+ madd_v3_v3fl(loc, target_normal, item->xform_dist);
+ object_apply_location(item->ob, loc);
+ copy_v3_v3(item->ob->obmat[3], loc); /* so orient behaves as expected */
+ }
+
+ object_orient_to_location(item->ob, item->rot_mat, item->rot_mat[2], location_world);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, item->ob);
+ }
+ copy_v3_v3(xfd->prev.normal, normal);
+ xfd->prev.is_normal_valid = true;
+ }
+ }
+ else {
+ struct XFormAxisItem *item = xfd->object_data;
+ for (int i = 0; i < xfd->object_data_len; i++, item++) {
+ object_orient_to_location(item->ob, item->rot_mat, item->rot_mat[2], location_world);
+ WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, item->ob);
+ }
+ xfd->prev.is_normal_valid = false;
+ }
+ }
+ }
+ }
+ xfd->is_translate = is_translate;
+
+ ED_region_tag_redraw(xfd->vc.ar);
+ }
+
+ bool is_finished = false;
+
+ if (ISMOUSE(xfd->init_event)) {
+ if ((event->type == xfd->init_event) && (event->val == KM_RELEASE)) {
+ is_finished = true;
+ }
+ }
+ else {
+ if (ELEM(event->type, LEFTMOUSE, RETKEY, PADENTER)) {
+ is_finished = true;
+ }
+ }
+
+ if (is_finished) {
+ object_transform_axis_target_free_data(op);
+ return OPERATOR_FINISHED;
+ }
+ else if (ELEM(event->type, ESCKEY, RIGHTMOUSE)) {
+ object_transform_axis_target_cancel(C, op);
+ return OPERATOR_CANCELLED;
+ }
+
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void OBJECT_OT_transform_axis_target(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Interactive Lamp Track to Cursor";
+ ot->description = "Interactively point cameras and lamps to a location (Ctrl translates)";
+ ot->idname = "OBJECT_OT_transform_axis_target";
+
+ /* api callbacks */
+ ot->invoke = object_transform_axis_target_invoke;
+ ot->cancel = object_transform_axis_target_cancel;
+ ot->modal = object_transform_axis_target_modal;
+ ot->poll = ED_operator_region_view3d_active;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_BLOCKING;
+}
+
+#undef USE_RELATIVE_ROTATION
+
+/** \} */
diff --git a/source/blender/editors/object/object_vgroup.c b/source/blender/editors/object/object_vgroup.c
index c6c20182ac3..ff40aa07cd2 100644
--- a/source/blender/editors/object/object_vgroup.c
+++ b/source/blender/editors/object/object_vgroup.c
@@ -43,6 +43,7 @@
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_alloca.h"
#include "BLI_array.h"
@@ -56,9 +57,9 @@
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh_mapping.h"
#include "BKE_editmesh.h"
+#include "BKE_layer.h"
#include "BKE_modifier.h"
#include "BKE_report.h"
#include "BKE_DerivedMesh.h"
@@ -66,6 +67,8 @@
#include "BKE_object.h"
#include "BKE_lattice.h"
+#include "DEG_depsgraph.h"
+
#include "DNA_armature_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -1270,9 +1273,9 @@ static void dm_deform_clear(DerivedMesh *dm, Object *ob)
}
/* recalculate the deformation */
-static DerivedMesh *dm_deform_recalc(Scene *scene, Object *ob)
+static DerivedMesh *dm_deform_recalc(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
- return mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
+ return mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH);
}
/* by changing nonzero weights, try to move a vertex in me->mverts with index 'index' to
@@ -1285,7 +1288,7 @@ static DerivedMesh *dm_deform_recalc(Scene *scene, Object *ob)
* coord is a point on the plane
*/
static void moveCloserToDistanceFromPlane(
- Scene *scene, Object *ob, Mesh *me, int index, float norm[3],
+ Depsgraph *depsgraph, Scene *scene, Object *ob, Mesh *me, int index, float norm[3],
float coord[3], float d, float distToBe, float strength, float cp)
{
DerivedMesh *dm;
@@ -1312,7 +1315,7 @@ static void moveCloserToDistanceFromPlane(
float originalDistToBe = distToBe;
do {
wasChange = false;
- dm = dm_deform_recalc(scene, ob);
+ dm = dm_deform_recalc(depsgraph, scene, ob);
dm->getVert(dm, index, &m);
copy_v3_v3(oldPos, m.co);
distToStart = dot_v3v3(norm, oldPos) + d;
@@ -1350,7 +1353,7 @@ static void moveCloserToDistanceFromPlane(
if (dw->weight > 1) {
dw->weight = 1;
}
- dm = dm_deform_recalc(scene, ob);
+ dm = dm_deform_recalc(depsgraph, scene, ob);
dm->getVert(dm, index, &m);
getVerticalAndHorizontalChange(norm, d, coord, oldPos, distToStart, m.co, changes, dists, i);
dw->weight = oldw;
@@ -1460,8 +1463,9 @@ static void moveCloserToDistanceFromPlane(
/* this is used to try to smooth a surface by only adjusting the nonzero weights of a vertex
* but it could be used to raise or lower an existing 'bump.' */
-static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength, float cp)
+static void vgroup_fix(const bContext *C, Scene *scene, Object *ob, float distToBe, float strength, float cp)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
int i;
Mesh *me = ob->data;
@@ -1477,7 +1481,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength,
MVert *p = MEM_callocN(sizeof(MVert) * (count), "deformedPoints");
int k;
- DerivedMesh *dm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
+ DerivedMesh *dm = mesh_get_derived_deform(depsgraph, scene, ob, CD_MASK_BAREMESH);
k = count;
while (k--) {
dm->getVert(dm, verts[k], &m);
@@ -1495,7 +1499,7 @@ static void vgroup_fix(Scene *scene, Object *ob, float distToBe, float strength,
if (mag) { /* zeros fix */
d = -dot_v3v3(norm, coord);
/* dist = (dot_v3v3(norm, m.co) + d); */ /* UNUSED */
- moveCloserToDistanceFromPlane(scene, ob, me, i, norm, coord, d, distToBe, strength, cp);
+ moveCloserToDistanceFromPlane(depsgraph, scene, ob, me, i, norm, coord, d, distToBe, strength, cp);
}
}
@@ -2635,7 +2639,7 @@ static int vertex_group_add_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = ED_object_context(C);
BKE_object_defgroup_add(ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -2668,7 +2672,7 @@ static int vertex_group_remove_exec(bContext *C, wmOperator *op)
else
vgroup_delete_active(ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -2703,7 +2707,7 @@ static int vertex_group_assign_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = ED_object_context(C);
vgroup_assign_verts(ob, ts->vgroup_weight);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
return OPERATOR_FINISHED;
@@ -2776,7 +2780,7 @@ static int vertex_group_remove_from_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
return OPERATOR_FINISHED;
@@ -2865,7 +2869,7 @@ static int vertex_group_copy_exec(bContext *C, wmOperator *UNUSED(op))
Object *ob = ED_object_context(C);
vgroup_duplicate(ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob->data);
@@ -2901,7 +2905,7 @@ static int vertex_group_levels_exec(bContext *C, wmOperator *op)
vgroup_levels_subset(ob, vgroup_validmap, vgroup_tot, subset_count, offset, gain);
MEM_freeN((void *)vgroup_validmap);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -2935,7 +2939,7 @@ static int vertex_group_normalize_exec(bContext *C, wmOperator *UNUSED(op))
changed = vgroup_normalize(ob);
if (changed) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -2974,7 +2978,7 @@ static int vertex_group_normalize_all_exec(bContext *C, wmOperator *op)
MEM_freeN((void *)vgroup_validmap);
if (changed) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3027,9 +3031,9 @@ static int vertex_group_fix_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR_INVALID_CONTEXT, "This operator does not support an active mirror modifier");
return OPERATOR_CANCELLED;
}
- vgroup_fix(scene, ob, distToBe, strength, cp);
+ vgroup_fix(C, scene, ob, distToBe, strength, cp);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3101,7 +3105,7 @@ static int vertex_group_invert_exec(bContext *C, wmOperator *op)
vgroup_invert_subset(ob, vgroup_validmap, vgroup_tot, subset_count, auto_assign, auto_remove);
MEM_freeN((void *)vgroup_validmap);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3143,7 +3147,7 @@ static int vertex_group_smooth_exec(bContext *C, wmOperator *op)
vgroup_smooth_subset(ob, vgroup_validmap, vgroup_tot, subset_count, fac, repeat, fac_expand);
MEM_freeN((void *)vgroup_validmap);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3185,7 +3189,7 @@ static int vertex_group_clean_exec(bContext *C, wmOperator *op)
vgroup_clean_subset(ob, vgroup_validmap, vgroup_tot, subset_count, limit, keep_single);
MEM_freeN((void *)vgroup_validmap);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3226,7 +3230,7 @@ static int vertex_group_quantize_exec(bContext *C, wmOperator *op)
vgroup_quantize_subset(ob, vgroup_validmap, vgroup_tot, subset_count, steps);
MEM_freeN((void *)vgroup_validmap);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3267,7 +3271,7 @@ static int vertex_group_limit_total_exec(bContext *C, wmOperator *op)
BKE_reportf(op->reports, remove_tot ? RPT_INFO : RPT_WARNING, "%d vertex weights limited", remove_tot);
if (remove_tot) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3313,7 +3317,7 @@ static int vertex_group_mirror_exec(bContext *C, wmOperator *op)
ED_mesh_report_mirror(op, totmirr, totfail);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
@@ -3346,25 +3350,26 @@ void OBJECT_OT_vertex_group_mirror(wmOperatorType *ot)
static int vertex_group_copy_to_linked_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
- Object *ob = ED_object_context(C);
- Base *base;
+ Object *ob_active = ED_object_context(C);
int retval = OPERATOR_CANCELLED;
- for (base = scene->base.first; base; base = base->next) {
- if (base->object->type == ob->type) {
- if (base->object != ob && base->object->data == ob->data) {
- BLI_freelistN(&base->object->defbase);
- BLI_duplicatelist(&base->object->defbase, &ob->defbase);
- base->object->actdef = ob->actdef;
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob_iter)
+ {
+ if (ob_iter->type == ob_active->type) {
+ if (ob_iter != ob_active && ob_iter->data == ob_active->data) {
+ BLI_freelistN(&ob_iter->defbase);
+ BLI_duplicatelist(&ob_iter->defbase, &ob_active->defbase);
+ ob_iter->actdef = ob_active->actdef;
- DAG_id_tag_update(&base->object->id, OB_RECALC_DATA);
- WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, base->object);
- WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, base->object->data);
+ DEG_id_tag_update(&ob_iter->id, OB_RECALC_DATA);
+ WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
+ WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob_iter->data);
retval = OPERATOR_FINISHED;
}
}
}
+ FOREACH_SCENE_OBJECT_END;
return retval;
}
@@ -3394,7 +3399,7 @@ static int vertex_group_copy_to_selected_exec(bContext *C, wmOperator *op)
{
if (obact != ob) {
if (ED_vgroup_array_copy(ob, obact)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob);
changed_tot++;
}
@@ -3437,7 +3442,7 @@ static int set_active_group_exec(bContext *C, wmOperator *op)
BLI_assert(nr + 1 >= 0);
ob->actdef = nr + 1;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob);
return OPERATOR_FINISHED;
@@ -3651,7 +3656,7 @@ static int vertex_group_sort_exec(bContext *C, wmOperator *op)
ret = vgroup_do_remap(ob, name_array, op);
if (ret != OPERATOR_CANCELLED) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob);
}
@@ -3701,7 +3706,7 @@ static int vgroup_move_exec(bContext *C, wmOperator *op)
ret = vgroup_do_remap(ob, name_array, op);
if (ret != OPERATOR_CANCELLED) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_VERTEX_GROUP, ob);
}
}
@@ -3830,7 +3835,7 @@ static int vertex_weight_paste_exec(bContext *C, wmOperator *op)
vgroup_copy_active_to_sel_single(ob, def_nr);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
@@ -3867,7 +3872,7 @@ static int vertex_weight_delete_exec(bContext *C, wmOperator *op)
vgroup_remove_weight(ob, def_nr);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
@@ -3900,7 +3905,7 @@ static int vertex_weight_set_active_exec(bContext *C, wmOperator *op)
if (wg_index != -1) {
ob->actdef = wg_index + 1;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
}
@@ -3937,7 +3942,7 @@ static int vertex_weight_normalize_active_vertex_exec(bContext *C, wmOperator *U
changed = vgroup_normalize_active_vertex(ob, subset_type);
if (changed) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
@@ -3970,7 +3975,7 @@ static int vertex_weight_copy_exec(bContext *C, wmOperator *UNUSED(op))
vgroup_copy_active_to_sel(ob, subset_type);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/physics/CMakeLists.txt b/source/blender/editors/physics/CMakeLists.txt
index a04ebb24d2c..3705ff9d41a 100644
--- a/source/blender/editors/physics/CMakeLists.txt
+++ b/source/blender/editors/physics/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../gpu
../../makesdna
../../makesrna
diff --git a/source/blender/editors/physics/dynamicpaint_ops.c b/source/blender/editors/physics/dynamicpaint_ops.c
index 86db76bfcd6..6dee6825b31 100644
--- a/source/blender/editors/physics/dynamicpaint_ops.c
+++ b/source/blender/editors/physics/dynamicpaint_ops.c
@@ -42,7 +42,6 @@
#include "BKE_context.h"
#include "BKE_deform.h"
#include "BKE_object_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_dynamicpaint.h"
#include "BKE_global.h"
#include "BKE_main.h"
@@ -50,6 +49,9 @@
#include "BKE_report.h"
#include "BKE_screen.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_mesh.h"
#include "ED_screen.h"
#include "ED_object.h"
@@ -135,7 +137,7 @@ static int surface_slot_remove_exec(bContext *C, wmOperator *UNUSED(op))
}
dynamicPaint_resetPreview(canvas);
- DAG_id_tag_update(&obj_ctx->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obj_ctx->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, obj_ctx);
return OPERATOR_FINISHED;
@@ -181,8 +183,8 @@ static int type_toggle_exec(bContext *C, wmOperator *op)
}
/* update dependency */
- DAG_id_tag_update(&cObject->id, OB_RECALC_DATA);
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_id_tag_update(&cObject->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, cObject);
return OPERATOR_FINISHED;
@@ -286,6 +288,7 @@ typedef struct DynamicPaintBakeJob {
struct Main *bmain;
Scene *scene;
+ Depsgraph *depsgraph;
Object *ob;
DynamicPaintSurface *surface;
@@ -357,7 +360,7 @@ static void dynamicPaint_bakeImageSequence(DynamicPaintBakeJob *job)
frame = surface->start_frame;
orig_frame = scene->r.cfra;
scene->r.cfra = (int)frame;
- ED_update_for_newframe(job->bmain, scene, 1);
+ ED_update_for_newframe(job->bmain, job->depsgraph);
/* Init surface */
if (!dynamicPaint_createUVSurface(scene, surface, job->progress, job->do_update)) {
@@ -383,8 +386,8 @@ static void dynamicPaint_bakeImageSequence(DynamicPaintBakeJob *job)
/* calculate a frame */
scene->r.cfra = (int)frame;
- ED_update_for_newframe(job->bmain, scene, 1);
- if (!dynamicPaint_calculateFrame(surface, scene, cObject, frame)) {
+ ED_update_for_newframe(job->bmain, job->depsgraph);
+ if (!dynamicPaint_calculateFrame(surface, job->depsgraph, scene, cObject, frame)) {
job->success = 0;
return;
}
@@ -479,6 +482,7 @@ static int dynamicpaint_bake_exec(struct bContext *C, struct wmOperator *op)
DynamicPaintBakeJob *job = MEM_mallocN(sizeof(DynamicPaintBakeJob), "DynamicPaintBakeJob");
job->bmain = CTX_data_main(C);
job->scene = scene;
+ job->depsgraph = CTX_data_depsgraph(C);
job->ob = ob;
job->canvas = canvas;
job->surface = surface;
diff --git a/source/blender/editors/physics/particle_boids.c b/source/blender/editors/physics/particle_boids.c
index 14b12497c4a..681ac75e847 100644
--- a/source/blender/editors/physics/particle_boids.c
+++ b/source/blender/editors/physics/particle_boids.c
@@ -39,10 +39,12 @@
#include "BKE_boids.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_particle.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RNA_access.h"
#include "RNA_enum_types.h"
#include "RNA_define.h"
@@ -75,7 +77,7 @@ static int rule_add_exec(bContext *C, wmOperator *op)
BLI_addtail(&state->rules, rule);
- DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
+ DEG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
return OPERATOR_FINISHED;
}
@@ -121,8 +123,8 @@ static int rule_del_exec(bContext *C, wmOperator *UNUSED(op))
if (rule)
rule->flag |= BOIDRULE_CURRENT;
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
return OPERATOR_FINISHED;
}
@@ -158,7 +160,7 @@ static int rule_move_up_exec(bContext *C, wmOperator *UNUSED(op))
BLI_remlink(&state->rules, rule);
BLI_insertlinkbefore(&state->rules, rule->prev, rule);
- DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
+ DEG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
break;
}
}
@@ -194,7 +196,7 @@ static int rule_move_down_exec(bContext *C, wmOperator *UNUSED(op))
BLI_remlink(&state->rules, rule);
BLI_insertlinkafter(&state->rules, rule->next, rule);
- DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
+ DEG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
break;
}
}
@@ -277,8 +279,8 @@ static int state_del_exec(bContext *C, wmOperator *UNUSED(op))
state->flag |= BOIDSTATE_CURRENT;
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
return OPERATOR_FINISHED;
}
@@ -349,7 +351,7 @@ static int state_move_down_exec(bContext *C, wmOperator *UNUSED(op))
if (state->flag & BOIDSTATE_CURRENT && state->next) {
BLI_remlink(&boids->states, state);
BLI_insertlinkafter(&boids->states, state->next, state);
- DAG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
+ DEG_id_tag_update(&part->id, OB_RECALC_DATA|PSYS_RECALC_RESET);
break;
}
}
diff --git a/source/blender/editors/physics/particle_edit.c b/source/blender/editors/physics/particle_edit.c
index 2f18a0cd4c0..5c476df3dd3 100644
--- a/source/blender/editors/physics/particle_edit.c
+++ b/source/blender/editors/physics/particle_edit.c
@@ -46,12 +46,12 @@
#include "BLI_math.h"
#include "BLI_lasso_2d.h"
#include "BLI_listbase.h"
+#include "BLI_string.h"
#include "BLI_kdtree.h"
#include "BLI_rand.h"
#include "BLI_utildefines.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
#include "BKE_object.h"
@@ -62,15 +62,20 @@
#include "BKE_bvhutils.h"
#include "BKE_pointcache.h"
+#include "DEG_depsgraph.h"
+
#include "BIF_gl.h"
-#include "BIF_glutil.h"
#include "ED_object.h"
#include "ED_physics.h"
#include "ED_mesh.h"
#include "ED_particle.h"
+#include "ED_screen.h"
#include "ED_view3d.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+
#include "UI_resources.h"
#include "WM_api.h"
@@ -90,9 +95,9 @@ int PE_poll(bContext *C)
Scene *scene= CTX_data_scene(C);
Object *ob= CTX_data_active_object(C);
- if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT))
+ if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) {
return 0;
-
+ }
return (PE_get_current(scene, ob) != NULL);
}
@@ -102,9 +107,9 @@ int PE_hair_poll(bContext *C)
Object *ob= CTX_data_active_object(C);
PTCacheEdit *edit;
- if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT))
+ if (!scene || !ob || !(ob->mode & OB_MODE_PARTICLE_EDIT)) {
return 0;
-
+ }
edit= PE_get_current(scene, ob);
return (edit && edit->psys);
@@ -188,7 +193,8 @@ static float pe_brush_size_get(const Scene *UNUSED(scene), ParticleBrushData *br
*
* note: this function runs on poll, therefor it can runs many times a second
* keep it fast! */
-static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create)
+static PTCacheEdit *pe_get_current(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, int create)
{
ParticleEditSettings *pset= PE_settings(scene);
PTCacheEdit *edit = NULL;
@@ -227,18 +233,18 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create)
if (psys->part && psys->part->type == PART_HAIR) {
if (psys->flag & PSYS_HAIR_DYNAMICS && psys->pointcache->flag & PTCACHE_BAKED) {
if (create && !psys->pointcache->edit)
- PE_create_particle_edit(scene, ob, pid->cache, NULL);
+ PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL);
edit = pid->cache->edit;
}
else {
if (create && !psys->edit && psys->flag & PSYS_HAIR_DONE)
- PE_create_particle_edit(scene, ob, NULL, psys);
+ PE_create_particle_edit(depsgraph, scene, ob, NULL, psys);
edit = psys->edit;
}
}
else {
if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit)
- PE_create_particle_edit(scene, ob, pid->cache, psys);
+ PE_create_particle_edit(depsgraph, scene, ob, pid->cache, psys);
edit = pid->cache->edit;
}
@@ -249,7 +255,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create)
if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) {
pset->flag |= PE_FADE_TIME;
// NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB;
- PE_create_particle_edit(scene, ob, pid->cache, NULL);
+ PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL);
}
edit = pid->cache->edit;
break;
@@ -258,7 +264,7 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create)
if (create && pid->cache->flag & PTCACHE_BAKED && !pid->cache->edit) {
pset->flag |= PE_FADE_TIME;
// NICE TO HAVE but doesn't work: pset->brushtype = PE_BRUSH_COMB;
- PE_create_particle_edit(scene, ob, pid->cache, NULL);
+ PE_create_particle_edit(depsgraph, scene, ob, pid->cache, NULL);
}
edit = pid->cache->edit;
break;
@@ -275,18 +281,19 @@ static PTCacheEdit *pe_get_current(Scene *scene, Object *ob, int create)
PTCacheEdit *PE_get_current(Scene *scene, Object *ob)
{
- return pe_get_current(scene, ob, 0);
+ return pe_get_current(NULL, scene, ob, 0);
}
-PTCacheEdit *PE_create_current(Scene *scene, Object *ob)
+PTCacheEdit *PE_create_current(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
- return pe_get_current(scene, ob, 1);
+ return pe_get_current(depsgraph, scene, ob, 1);
}
-void PE_current_changed(Scene *scene, Object *ob)
+void PE_current_changed(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
- if (ob->mode == OB_MODE_PARTICLE_EDIT)
- PE_create_current(scene, ob);
+ if (ob->mode == OB_MODE_PARTICLE_EDIT) {
+ PE_create_current(depsgraph, scene, ob);
+ }
}
void PE_hide_keys_time(Scene *scene, PTCacheEdit *edit, float cfra)
@@ -328,13 +335,15 @@ static int pe_x_mirror(Object *ob)
typedef struct PEData {
ViewContext vc;
- bglMats mats;
+ const bContext *context;
Scene *scene;
+ ViewLayer *view_layer;
Object *ob;
DerivedMesh *dm;
PTCacheEdit *edit;
BVHTreeFromMesh shape_bvh;
+ Depsgraph *depsgraph;
const int *mval;
rcti *rect;
@@ -364,9 +373,11 @@ static void PE_set_data(bContext *C, PEData *data)
{
memset(data, 0, sizeof(*data));
- data->scene= CTX_data_scene(C);
- data->ob= CTX_data_active_object(C);
- data->edit= PE_get_current(data->scene, data->ob);
+ data->scene = CTX_data_scene(C);
+ data->view_layer = CTX_data_view_layer(C);
+ data->ob = CTX_data_active_object(C);
+ data->depsgraph = CTX_data_depsgraph(C);
+ data->edit = PE_get_current(data->scene, data->ob);
}
static void PE_set_view3d_data(bContext *C, PEData *data)
@@ -374,8 +385,6 @@ static void PE_set_view3d_data(bContext *C, PEData *data)
PE_set_data(C, data);
ED_view3d_viewcontext_init(C, &data->vc);
- /* note, the object argument means the modelview matrix does not account for the objects matrix, use viewmat rather than (obmat * viewmat) */
- view3d_get_transformation(data->vc.ar, data->vc.rv3d, NULL, &data->mats);
if (V3D_IS_ZBUF(data->vc.v3d)) {
if (data->vc.v3d->flag & V3D_INVALID_BACKBUF) {
@@ -415,7 +424,6 @@ static bool key_test_depth(PEData *data, const float co[3], const int screen_co[
{
View3D *v3d= data->vc.v3d;
ViewDepths *vd = data->vc.rv3d->depths;
- double ux, uy, uz;
float depth;
/* nothing to do */
@@ -431,9 +439,6 @@ static bool key_test_depth(PEData *data, const float co[3], const int screen_co[
}
#endif
- gluProject(co[0], co[1], co[2], data->mats.modelview, data->mats.projection,
- (GLint *)data->mats.viewport, &ux, &uy, &uz);
-
/* check if screen_co is within bounds because brush_cut uses out of screen coords */
if (screen_co[0] >= 0 && screen_co[0] < vd->w && screen_co[1] >= 0 && screen_co[1] < vd->h) {
BLI_assert(vd && vd->depths);
@@ -443,7 +448,10 @@ static bool key_test_depth(PEData *data, const float co[3], const int screen_co[
else
return 0;
- if ((float)uz - 0.00001f > depth)
+ float win[3];
+ ED_view3d_project(data->vc.ar, co, win);
+
+ if (win[2] - 0.00001f > depth)
return 0;
else
return 1;
@@ -1128,9 +1136,9 @@ void recalc_emitter_field(Object *ob, ParticleSystem *psys)
BLI_kdtree_balance(edit->emitter_field);
}
-static void PE_update_selection(Scene *scene, Object *ob, int useflag)
+static void PE_update_selection(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag)
{
- PTCacheEdit *edit= PE_get_current(scene, ob);
+ PTCacheEdit *edit = PE_get_current(scene, ob);
HairKey *hkey;
POINT_P; KEY_K;
@@ -1149,7 +1157,7 @@ static void PE_update_selection(Scene *scene, Object *ob, int useflag)
}
}
- psys_cache_edit_paths(scene, ob, edit, CFRA, G.is_rendering);
+ psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering);
/* disable update flag */
@@ -1235,7 +1243,7 @@ static void update_velocities(PTCacheEdit *edit)
}
}
-void PE_update_object(Scene *scene, Object *ob, int useflag)
+void PE_update_object(Depsgraph *depsgraph, Scene *scene, Object *ob, int useflag)
{
/* use this to do partial particle updates, not usable when adding or
* removing, then a full redo is necessary and calling this may crash */
@@ -1265,7 +1273,7 @@ void PE_update_object(Scene *scene, Object *ob, int useflag)
PE_hide_keys_time(scene, edit, CFRA);
/* regenerate path caches */
- psys_cache_edit_paths(scene, ob, edit, CFRA, G.is_rendering);
+ psys_cache_edit_paths(depsgraph, scene, ob, edit, CFRA, G.is_rendering);
/* disable update flag */
LOOP_POINTS {
@@ -1274,6 +1282,8 @@ void PE_update_object(Scene *scene, Object *ob, int useflag)
if (edit->psys)
edit->psys->flag &= ~PSYS_HAIR_UPDATED;
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
/************************************************/
@@ -1375,6 +1385,7 @@ static void select_action_apply(PTCacheEditPoint *point, PTCacheEditKey *key, in
static int pe_select_all_exec(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Object *ob= CTX_data_active_object(C);
PTCacheEdit *edit= PE_get_current(scene, ob);
POINT_P; KEY_K;
@@ -1399,7 +1410,7 @@ static int pe_select_all_exec(bContext *C, wmOperator *op)
}
}
- PE_update_selection(scene, ob, 1);
+ PE_update_selection(depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob);
return OPERATOR_FINISHED;
@@ -1431,7 +1442,7 @@ int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselec
Object *ob= CTX_data_active_object(C);
PTCacheEdit *edit= PE_get_current(scene, ob);
POINT_P; KEY_K;
-
+
if (!PE_start_edit(edit))
return OPERATOR_CANCELLED;
@@ -1456,7 +1467,7 @@ int PE_mouse_particles(bContext *C, const int mval[2], bool extend, bool deselec
else
for_mouse_hit_keys(&data, toggle_key_select, 1);
- PE_update_selection(scene, ob, 1);
+ PE_update_selection(data.depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob);
return OPERATOR_FINISHED;
@@ -1497,7 +1508,7 @@ static int select_roots_exec(bContext *C, wmOperator *op)
data.select_action = action;
foreach_point(&data, select_root);
- PE_update_selection(data.scene, data.ob, 1);
+ PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob);
return OPERATOR_FINISHED;
@@ -1562,7 +1573,7 @@ static int select_tips_exec(bContext *C, wmOperator *op)
data.select_action = action;
foreach_point(&data, select_tip);
- PE_update_selection(data.scene, data.ob, 1);
+ PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob);
return OPERATOR_FINISHED;
@@ -1646,7 +1657,7 @@ static int select_random_exec(bContext *C, wmOperator *op)
BLI_rng_free(rng);
- PE_update_selection(data.scene, data.ob, 1);
+ PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob);
return OPERATOR_FINISHED;
@@ -1690,7 +1701,7 @@ static int select_linked_exec(bContext *C, wmOperator *op)
data.select= !RNA_boolean_get(op->ptr, "deselect");
for_mouse_hit_keys(&data, select_keys, 1); /* nearest only */
- PE_update_selection(data.scene, data.ob, 1);
+ PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob);
return OPERATOR_FINISHED;
@@ -1754,7 +1765,7 @@ int PE_border_select(bContext *C, rcti *rect, bool select, bool extend)
for_mouse_hit_keys(&data, select_key, 0);
- PE_update_selection(scene, ob, 1);
+ PE_update_selection(data.depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob);
return OPERATOR_FINISHED;
@@ -1779,7 +1790,7 @@ int PE_circle_select(bContext *C, int selecting, const int mval[2], float rad)
for_mouse_hit_keys(&data, select_key, 0);
- PE_update_selection(scene, ob, 1);
+ PE_update_selection(data.depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob);
return OPERATOR_FINISHED;
@@ -1867,7 +1878,7 @@ int PE_lasso_select(bContext *C, const int mcords[][2], const short moves, bool
}
}
- PE_update_selection(scene, ob, 1);
+ PE_update_selection(data.depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob);
return OPERATOR_FINISHED;
@@ -1879,9 +1890,12 @@ static int hide_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_active_object(C);
Scene *scene= CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
PTCacheEdit *edit= PE_get_current(scene, ob);
POINT_P; KEY_K;
-
+
+
if (RNA_enum_get(op->ptr, "unselected")) {
LOOP_UNSELECTED_POINTS {
point->flag |= PEP_HIDE;
@@ -1901,7 +1915,7 @@ static int hide_exec(bContext *C, wmOperator *op)
}
}
- PE_update_selection(scene, ob, 1);
+ PE_update_selection(depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob);
return OPERATOR_FINISHED;
@@ -1931,7 +1945,8 @@ static int reveal_exec(bContext *C, wmOperator *op)
{
Object *ob= CTX_data_active_object(C);
Scene *scene= CTX_data_scene(C);
- PTCacheEdit *edit = PE_get_current(scene, ob);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ PTCacheEdit *edit= PE_get_current(scene, ob);
const bool select = RNA_boolean_get(op->ptr, "select");
POINT_P; KEY_K;
@@ -1946,7 +1961,7 @@ static int reveal_exec(bContext *C, wmOperator *op)
}
}
- PE_update_selection(scene, ob, 1);
+ PE_update_selection(depsgraph, scene, ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, ob);
return OPERATOR_FINISHED;
@@ -2008,7 +2023,7 @@ static int select_less_exec(bContext *C, wmOperator *UNUSED(op))
PE_set_data(C, &data);
foreach_point(&data, select_less_keys);
- PE_update_selection(data.scene, data.ob, 1);
+ PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob);
return OPERATOR_FINISHED;
@@ -2070,7 +2085,7 @@ static int select_more_exec(bContext *C, wmOperator *UNUSED(op))
PE_set_data(C, &data);
foreach_point(&data, select_more_keys);
- PE_update_selection(data.scene, data.ob, 1);
+ PE_update_selection(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_SELECTED, data.ob);
return OPERATOR_FINISHED;
@@ -2106,9 +2121,10 @@ static void rekey_particle(PEData *data, int pa_index)
float dval, sta, end;
int k;
- sim.scene= data->scene;
- sim.ob= data->ob;
- sim.psys= edit->psys;
+ sim.depsgraph = data->depsgraph;
+ sim.scene = data->scene;
+ sim.ob = data->ob;
+ sim.psys = edit->psys;
pa->flag |= PARS_REKEY;
@@ -2167,7 +2183,7 @@ static int rekey_exec(bContext *C, wmOperator *op)
foreach_selected_point(&data, rekey_particle);
recalc_lengths(data.edit);
- PE_update_object(data.scene, data.ob, 1);
+ PE_update_object(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob);
return OPERATOR_FINISHED;
@@ -2192,11 +2208,11 @@ void PARTICLE_OT_rekey(wmOperatorType *ot)
RNA_def_int(ot->srna, "keys_number", 2, 2, INT_MAX, "Number of Keys", "", 2, 100);
}
-static void rekey_particle_to_time(Scene *scene, Object *ob, int pa_index, float path_time)
+static void rekey_particle_to_time(const bContext *C, Scene *scene, Object *ob, int pa_index, float path_time)
{
PTCacheEdit *edit= PE_get_current(scene, ob);
ParticleSystem *psys;
- ParticleSimulationData sim= {0};
+ ParticleSimulationData sim = {0};
ParticleData *pa;
ParticleKey state;
HairKey *new_keys, *key;
@@ -2207,9 +2223,10 @@ static void rekey_particle_to_time(Scene *scene, Object *ob, int pa_index, float
psys = edit->psys;
- sim.scene= scene;
- sim.ob= ob;
- sim.psys= psys;
+ sim.depsgraph = CTX_data_depsgraph(C);
+ sim.scene = scene;
+ sim.ob = ob;
+ sim.psys = psys;
pa= psys->particles + pa_index;
@@ -2424,9 +2441,10 @@ static void subdivide_particle(PEData *data, int pa_index)
short totnewkey=0;
float endtime;
- sim.scene= data->scene;
- sim.ob= data->ob;
- sim.psys= edit->psys;
+ sim.depsgraph = data->depsgraph;
+ sim.scene = data->scene;
+ sim.ob = data->ob;
+ sim.psys = edit->psys;
for (k=0, ekey=point->keys; k<pa->totkey-1; k++, ekey++) {
if (ekey->flag&PEK_SELECT && (ekey+1)->flag&PEK_SELECT)
@@ -2498,7 +2516,7 @@ static int subdivide_exec(bContext *C, wmOperator *UNUSED(op))
foreach_point(&data, subdivide_particle);
recalc_lengths(data.edit);
- PE_update_object(data.scene, data.ob, 1);
+ PE_update_object(data.depsgraph, data.scene, data.ob, 1);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob);
return OPERATOR_FINISHED;
@@ -2587,7 +2605,7 @@ static int remove_doubles_exec(bContext *C, wmOperator *op)
BKE_reportf(op->reports, RPT_INFO, "Removed %d double particles", totremoved);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
return OPERATOR_FINISHED;
@@ -2639,7 +2657,7 @@ static int weight_set_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
return OPERATOR_FINISHED;
@@ -2671,24 +2689,27 @@ static void brush_drawcursor(bContext *C, int x, int y, void *UNUSED(customdata)
ParticleEditSettings *pset= PE_settings(scene);
ParticleBrushData *brush;
- if (pset->brushtype < 0)
+ if (pset->brushtype < 0) {
return;
+ }
- brush= &pset->brush[pset->brushtype];
+ brush = &pset->brush[pset->brushtype];
if (brush) {
- glPushMatrix();
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glTranslatef((float)x, (float)y, 0.0f);
+ immUniformColor4ub(255, 255, 255, 128);
- glColor4ub(255, 255, 255, 128);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
- glutil_draw_lined_arc(0.0, M_PI*2.0, pe_brush_size_get(scene, brush), 40);
+
+ imm_draw_circle_wire_2d(pos, (float)x, (float)y, pe_brush_size_get(scene, brush), 40);
+
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
-
- glPopMatrix();
+
+ immUnbindProgram();
}
}
@@ -2745,7 +2766,7 @@ static int delete_exec(bContext *C, wmOperator *op)
recalc_lengths(data.edit);
}
- DAG_id_tag_update(&data.ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&data.ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, data.ob);
return OPERATOR_FINISHED;
@@ -2772,11 +2793,12 @@ void PARTICLE_OT_delete(wmOperatorType *ot)
/*************************** mirror operator **************************/
-static void PE_mirror_x(Scene *scene, Object *ob, int tagged)
+static void PE_mirror_x(
+ Scene *scene, Object *ob, int tagged)
{
Mesh *me= (Mesh *)(ob->data);
ParticleSystemModifierData *psmd;
- PTCacheEdit *edit= PE_get_current(scene, ob);
+ PTCacheEdit *edit = PE_get_current(scene, ob);
ParticleSystem *psys = edit->psys;
ParticleData *pa, *newpa, *new_pars;
PTCacheEditPoint *newpoint, *new_points;
@@ -2930,7 +2952,7 @@ static int mirror_exec(bContext *C, wmOperator *UNUSED(op))
update_world_cos(ob, edit);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
return OPERATOR_FINISHED;
}
@@ -3063,7 +3085,7 @@ static void brush_cut(PEData *data, int pa_index)
edit->points[pa_index].flag |= PEP_TAG;
}
else {
- rekey_particle_to_time(data->scene, ob, pa_index, cut_time);
+ rekey_particle_to_time(data->context, data->scene, ob, pa_index, cut_time);
edit->points[pa_index].flag |= PEP_EDIT_RECALC;
}
}
@@ -3311,13 +3333,14 @@ static void intersect_dm_quad_weights(const float v1[3], const float v2[3], cons
}
/* check intersection with a derivedmesh */
-static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm,
+static int particle_intersect_dm(const bContext *C, Scene *scene, Object *ob, DerivedMesh *dm,
float *vert_cos,
const float co1[3], const float co2[3],
float *min_d, int *min_face, float *min_w,
float *face_minmax, float *pa_minmax,
float radius, float *ipoint)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
MFace *mface= NULL;
MVert *mvert= NULL;
int i, totface, intersect=0;
@@ -3327,9 +3350,9 @@ static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm,
if (dm == NULL) {
psys_disable_all(ob);
- dm=mesh_get_derived_final(scene, ob, 0);
+ dm = mesh_get_derived_final(depsgraph, scene, ob, 0);
if (dm == NULL)
- dm=mesh_get_derived_deform(scene, ob, 0);
+ dm = mesh_get_derived_deform(depsgraph, scene, ob, 0);
psys_enable_all(ob);
@@ -3442,8 +3465,9 @@ static int particle_intersect_dm(Scene *scene, Object *ob, DerivedMesh *dm,
return intersect;
}
-static int brush_add(PEData *data, short number)
+static int brush_add(const bContext *C, PEData *data, short number)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene= data->scene;
Object *ob= data->ob;
DerivedMesh *dm;
@@ -3471,6 +3495,7 @@ static int brush_add(PEData *data, short number)
rng = BLI_rng_new_srandom(psys->seed+data->mval[0]+data->mval[1]);
+ sim.depsgraph = depsgraph;
sim.scene= scene;
sim.ob= ob;
sim.psys= psys;
@@ -3504,14 +3529,14 @@ static int brush_add(PEData *data, short number)
mco[0] = data->mval[0] + dmx;
mco[1] = data->mval[1] + dmy;
- ED_view3d_win_to_segment(data->vc.ar, data->vc.v3d, mco, co1, co2, true);
+ ED_view3d_win_to_segment(depsgraph, data->vc.ar, data->vc.v3d, mco, co1, co2, true);
mul_m4_v3(imat, co1);
mul_m4_v3(imat, co2);
min_d=2.0;
/* warning, returns the derived mesh face */
- if (particle_intersect_dm(scene, ob, dm, 0, co1, co2, &min_d, &add_pars[n].num_dmcache, add_pars[n].fuv, 0, 0, 0, 0)) {
+ if (particle_intersect_dm(C, scene, ob, dm, 0, co1, co2, &min_d, &add_pars[n].num_dmcache, add_pars[n].fuv, 0, 0, 0, 0)) {
if (psys->part->use_modifier_stack && !psmd->dm_final->deformedOnly) {
add_pars[n].num = add_pars[n].num_dmcache;
add_pars[n].num_dmcache = DMCACHE_ISCHILD;
@@ -3562,7 +3587,7 @@ static int brush_add(PEData *data, short number)
tree=BLI_kdtree_new(psys->totpart);
for (i=0, pa=psys->particles; i<totpart; i++, pa++) {
- psys_particle_on_dm(psmd->dm_final, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, cur_co, 0, 0, 0, 0, 0);
+ psys_particle_on_dm(psmd->dm_final, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, cur_co, 0, 0, 0, 0);
BLI_kdtree_insert(tree, i, cur_co);
}
@@ -3606,7 +3631,7 @@ static int brush_add(PEData *data, short number)
int w, maxw;
float maxd, totw=0.0, weight[3];
- psys_particle_on_dm(psmd->dm_final, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co1, 0, 0, 0, 0, 0);
+ psys_particle_on_dm(psmd->dm_final, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co1, 0, 0, 0, 0);
maxw = BLI_kdtree_find_nearest_n(tree, co1, ptn, 3);
maxd= ptn[maxw-1].dist;
@@ -3692,6 +3717,7 @@ static int brush_add(PEData *data, short number)
typedef struct BrushEdit {
Scene *scene;
+ ViewLayer *view_layer;
Object *ob;
PTCacheEdit *edit;
@@ -3706,6 +3732,7 @@ typedef struct BrushEdit {
static int brush_edit_init(bContext *C, wmOperator *op)
{
Scene *scene= CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *ob= CTX_data_active_object(C);
ParticleEditSettings *pset= PE_settings(scene);
PTCacheEdit *edit= PE_get_current(scene, ob);
@@ -3718,7 +3745,7 @@ static int brush_edit_init(bContext *C, wmOperator *op)
/* set the 'distance factor' for grabbing (used in comb etc) */
INIT_MINMAX(min, max);
- PE_minmax(scene, min, max);
+ PE_minmax(scene, view_layer, min, max);
mid_v3_v3v3(min, min, max);
bedit= MEM_callocN(sizeof(BrushEdit), "BrushEdit");
@@ -3726,6 +3753,7 @@ static int brush_edit_init(bContext *C, wmOperator *op)
op->customdata= bedit;
bedit->scene= scene;
+ bedit->view_layer = view_layer;
bedit->ob= ob;
bedit->edit= edit;
@@ -3756,6 +3784,8 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
if (!PE_start_edit(edit))
return;
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
RNA_float_get_array(itemptr, "mouse", mousef);
mouse[0] = mousef[0];
mouse[1] = mousef[1];
@@ -3781,6 +3811,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
(sqrtf(dx * dx + dy * dy) > pset->brush[PE_BRUSH_ADD].step) : (dx != 0 || dy != 0)) || bedit->first)
{
PEData data= bedit->data;
+ data.context = C; // TODO(mai): why isnt this set in bedit->data?
view3d_operator_needs_opengl(C);
selected= (short)count_selected_keys(scene, edit);
@@ -3881,7 +3912,7 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
if (edit->psys && edit->psys->part->from==PART_FROM_FACE) {
data.mval= mval;
- added= brush_add(&data, brush->count);
+ added= brush_add(C, &data, brush->count);
if (pset->flag & PE_KEEP_LENGTHS)
recalc_lengths(edit);
@@ -3935,17 +3966,18 @@ static void brush_edit_apply(bContext *C, wmOperator *op, PointerRNA *itemptr)
update_world_cos(ob, edit);
psys_free_path_cache(NULL, edit);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
+ else {
+ PE_update_object(depsgraph, scene, ob, 1);
}
- else
- PE_update_object(scene, ob, 1);
}
if (edit->psys) {
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
}
else {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
}
@@ -4153,7 +4185,7 @@ static void shape_cut(PEData *data, int pa_index)
edit->points[pa_index].flag |= PEP_TAG;
}
else {
- rekey_particle_to_time(data->scene, ob, pa_index, cut_time);
+ rekey_particle_to_time(data->context, data->scene, ob, pa_index, cut_time);
edit->points[pa_index].flag |= PEP_EDIT_RECALC;
}
}
@@ -4197,16 +4229,17 @@ static int shape_cut_exec(bContext *C, wmOperator *UNUSED(op))
if (removed) {
update_world_cos(ob, edit);
psys_free_path_cache(NULL, edit);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
+ else {
+ PE_update_object(data.depsgraph, scene, ob, 1);
}
- else
- PE_update_object(scene, ob, 1);
if (edit->psys) {
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
}
else {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
}
@@ -4235,9 +4268,9 @@ void PARTICLE_OT_shape_cut(wmOperatorType *ot)
/************************ utilities ******************************/
-int PE_minmax(Scene *scene, float min[3], float max[3])
+int PE_minmax(Scene *scene, ViewLayer *view_layer, float min[3], float max[3])
{
- Object *ob= OBACT;
+ Object *ob= OBACT(view_layer);
PTCacheEdit *edit= PE_get_current(scene, ob);
ParticleSystem *psys;
ParticleSystemModifierData *psmd = NULL;
@@ -4275,7 +4308,8 @@ int PE_minmax(Scene *scene, float min[3], float max[3])
/************************ particle edit toggle operator ************************/
/* initialize needed data for bake edit */
-void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys)
+void PE_create_particle_edit(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, PointCache *cache, ParticleSystem *psys)
{
PTCacheEdit *edit;
ParticleSystemModifierData *psmd = (psys) ? psys_get_modifier(ob, psys) : NULL;
@@ -4376,7 +4410,8 @@ void PE_create_particle_edit(Scene *scene, Object *ob, PointCache *cache, Partic
recalc_lengths(edit);
if (psys && !cache)
recalc_emitter_field(ob, psys);
- PE_update_object(scene, ob, 1);
+
+ PE_update_object(depsgraph, scene, ob, 1);
}
}
@@ -4398,6 +4433,7 @@ static int particle_edit_toggle_poll(bContext *C)
static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
const int mode_flag = OB_MODE_PARTICLE_EDIT;
@@ -4411,8 +4447,9 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
if (!is_mode_set) {
PTCacheEdit *edit;
+
ob->mode |= mode_flag;
- edit= PE_create_current(scene, ob);
+ edit= PE_create_current(depsgraph, scene, ob);
/* mesh may have changed since last entering editmode.
* note, this may have run before if the edit data was just created, so could avoid this and speed up a little */
@@ -4428,7 +4465,9 @@ static int particle_edit_toggle_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ // ED_workspace_object_mode_sync_from_object(wm, workspace, ob);
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
return OPERATOR_FINISHED;
}
@@ -4469,7 +4508,7 @@ static int clear_edited_exec(bContext *C, wmOperator *UNUSED(op))
psys_reset(psys, PSYS_RESET_DEPSGRAPH);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
else { /* some operation might have protected hair from editing so let's clear the flag */
@@ -4477,7 +4516,7 @@ static int clear_edited_exec(bContext *C, wmOperator *UNUSED(op))
psys->flag &= ~PSYS_GLOBAL_HAIR;
psys->flag &= ~PSYS_EDITED;
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
return OPERATOR_FINISHED;
@@ -4580,19 +4619,23 @@ static int unify_length_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob = CTX_data_active_object(C);
Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
PTCacheEdit *edit = PE_get_current(scene, ob);
float average_length = calculate_average_length(edit);
+
if (average_length == 0.0f) {
return OPERATOR_CANCELLED;
}
scale_points_to_length(edit, average_length);
- PE_update_object(scene, ob, 1);
+
+ PE_update_object(depsgraph, scene, ob, 1);
if (edit->psys) {
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE|NA_EDITED, ob);
}
else {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_MODIFIER, ob);
}
diff --git a/source/blender/editors/physics/particle_edit_undo.c b/source/blender/editors/physics/particle_edit_undo.c
index ef0a2711fdd..5199b1c54fa 100644
--- a/source/blender/editors/physics/particle_edit_undo.c
+++ b/source/blender/editors/physics/particle_edit_undo.c
@@ -44,12 +44,13 @@
#include "BLI_string.h"
#include "BLI_utildefines.h"
-#include "BKE_depsgraph.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
#include "BKE_context.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_object.h"
#include "ED_particle.h"
#include "ED_physics.h"
@@ -229,16 +230,19 @@ typedef struct ParticleUndoStep {
static bool particle_undosys_poll(struct bContext *C)
{
Scene *scene = CTX_data_scene(C);
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
PTCacheEdit *edit = PE_get_current(scene, ob);
+
return (edit != NULL);
}
static bool particle_undosys_step_encode(struct bContext *C, UndoStep *us_p)
{
ParticleUndoStep *us = (ParticleUndoStep *)us_p;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
us->scene_ref.ptr = CTX_data_scene(C);
- us->object_ref.ptr = us->scene_ref.ptr->basact->object;
+ us->object_ref.ptr = OBACT(view_layer);
PTCacheEdit *edit = PE_get_current(us->scene_ref.ptr, us->object_ref.ptr);
undoptcache_from_editcache(&us->data, edit);
return true;
@@ -256,7 +260,7 @@ static void particle_undosys_step_decode(struct bContext *C, UndoStep *us_p, int
PTCacheEdit *edit = PE_get_current(scene, ob);
if (edit) {
undoptcache_to_editcache(&us->data, edit);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
else {
BLI_assert(0);
diff --git a/source/blender/editors/physics/particle_object.c b/source/blender/editors/physics/particle_object.c
index 1e204e97499..ecebcb1ff6c 100644
--- a/source/blender/editors/physics/particle_object.c
+++ b/source/blender/editors/physics/particle_object.c
@@ -43,7 +43,6 @@
#include "BLI_string.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_global.h"
@@ -55,6 +54,9 @@
#include "BKE_pointcache.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -110,6 +112,7 @@ static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
Object *ob = ED_object_context(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
int mode_orig;
if (!scene || !ob)
@@ -123,7 +126,7 @@ static int particle_system_remove_exec(bContext *C, wmOperator *UNUSED(op))
*/
if (mode_orig & OB_MODE_PARTICLE_EDIT) {
if ((ob->mode & OB_MODE_PARTICLE_EDIT) == 0) {
- if (scene->basact && scene->basact->object == ob) {
+ if (view_layer->basact && view_layer->basact->object == ob) {
WM_event_add_notifier(C, NC_SCENE|ND_MODE|NS_MODE_OBJECT, NULL);
}
}
@@ -185,8 +188,8 @@ static int new_particle_settings_exec(bContext *C, wmOperator *UNUSED(op))
psys_check_boid_data(psys);
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
@@ -233,8 +236,8 @@ static int new_particle_target_exec(bContext *C, wmOperator *UNUSED(op))
BLI_addtail(&psys->targets, pt);
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
@@ -281,8 +284,8 @@ static int remove_particle_target_exec(bContext *C, wmOperator *UNUSED(op))
if (pt)
pt->flag |= PTARGET_CURRENT;
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
@@ -321,7 +324,7 @@ static int target_move_up_exec(bContext *C, wmOperator *UNUSED(op))
BLI_remlink(&psys->targets, pt);
BLI_insertlinkbefore(&psys->targets, pt->prev, pt);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
break;
}
@@ -359,7 +362,7 @@ static int target_move_down_exec(bContext *C, wmOperator *UNUSED(op))
BLI_remlink(&psys->targets, pt);
BLI_insertlinkafter(&psys->targets, pt->next, pt);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
break;
}
@@ -542,7 +545,9 @@ void PARTICLE_OT_dupliob_move_down(wmOperatorType *ot)
/************************ connect/disconnect hair operators *********************/
-static void disconnect_hair(Scene *scene, Object *ob, ParticleSystem *psys)
+static void disconnect_hair(
+ Depsgraph *depsgraph, Scene *scene,
+ Object *ob, ParticleSystem *psys)
{
ParticleSystemModifierData *psmd = psys_get_modifier(ob, psys);
ParticleEditSettings *pset= PE_settings(scene);
@@ -588,11 +593,12 @@ static void disconnect_hair(Scene *scene, Object *ob, ParticleSystem *psys)
if (ELEM(pset->brushtype, PE_BRUSH_ADD, PE_BRUSH_PUFF))
pset->brushtype = PE_BRUSH_NONE;
- PE_update_object(scene, ob, 0);
+ PE_update_object(depsgraph, scene, ob, 0);
}
static int disconnect_hair_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene= CTX_data_scene(C);
Object *ob= ED_object_context(C);
ParticleSystem *psys= NULL;
@@ -603,15 +609,15 @@ static int disconnect_hair_exec(bContext *C, wmOperator *op)
if (all) {
for (psys=ob->particlesystem.first; psys; psys=psys->next) {
- disconnect_hair(scene, ob, psys);
+ disconnect_hair(depsgraph, scene, ob, psys);
}
}
else {
psys = psys_get_current(ob);
- disconnect_hair(scene, ob, psys);
+ disconnect_hair(depsgraph, scene, ob, psys);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
return OPERATOR_FINISHED;
@@ -634,9 +640,10 @@ void PARTICLE_OT_disconnect_hair(wmOperatorType *ot)
/* from/to_world_space : whether from/to particles are in world or hair space
* from/to_mat : additional transform for from/to particles (e.g. for using object space copying)
*/
-static bool remap_hair_emitter(Scene *scene, Object *ob, ParticleSystem *psys,
- Object *target_ob, ParticleSystem *target_psys, PTCacheEdit *target_edit,
- float from_mat[4][4], float to_mat[4][4], bool from_global, bool to_global)
+static bool remap_hair_emitter(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, ParticleSystem *psys,
+ Object *target_ob, ParticleSystem *target_psys, PTCacheEdit *target_edit,
+ float from_mat[4][4], float to_mat[4][4], bool from_global, bool to_global)
{
ParticleSystemModifierData *target_psmd = psys_get_modifier(target_ob, target_psys);
ParticleData *pa, *tpa;
@@ -820,19 +827,23 @@ static bool remap_hair_emitter(Scene *scene, Object *ob, ParticleSystem *psys,
psys_free_path_cache(target_psys, target_edit);
- PE_update_object(scene, target_ob, 0);
+ PE_update_object(depsgraph, scene, target_ob, 0);
return true;
}
-static bool connect_hair(Scene *scene, Object *ob, ParticleSystem *psys)
+static bool connect_hair(
+ Depsgraph *depsgraph, Scene *scene,
+ Object *ob, ParticleSystem *psys)
{
bool ok;
if (!psys)
return false;
- ok = remap_hair_emitter(scene, ob, psys, ob, psys, psys->edit, ob->obmat, ob->obmat, psys->flag & PSYS_GLOBAL_HAIR, false);
+ ok = remap_hair_emitter(
+ depsgraph, scene, ob, psys, ob, psys, psys->edit,
+ ob->obmat, ob->obmat, psys->flag & PSYS_GLOBAL_HAIR, false);
psys->flag &= ~PSYS_GLOBAL_HAIR;
return ok;
@@ -840,6 +851,7 @@ static bool connect_hair(Scene *scene, Object *ob, ParticleSystem *psys)
static int connect_hair_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene= CTX_data_scene(C);
Object *ob= ED_object_context(C);
ParticleSystem *psys= NULL;
@@ -851,12 +863,12 @@ static int connect_hair_exec(bContext *C, wmOperator *op)
if (all) {
for (psys=ob->particlesystem.first; psys; psys=psys->next) {
- any_connected |= connect_hair(scene, ob, psys);
+ any_connected |= connect_hair(depsgraph, scene, ob, psys);
}
}
else {
psys = psys_get_current(ob);
- any_connected |= connect_hair(scene, ob, psys);
+ any_connected |= connect_hair(depsgraph, scene, ob, psys);
}
if (!any_connected) {
@@ -865,7 +877,7 @@ static int connect_hair_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT|ND_PARTICLE, ob);
return OPERATOR_FINISHED;
@@ -892,7 +904,9 @@ typedef enum eCopyParticlesSpace {
PAR_COPY_SPACE_WORLD = 1,
} eCopyParticlesSpace;
-static void copy_particle_edit(Scene *scene, Object *ob, ParticleSystem *psys, ParticleSystem *psys_from)
+static void copy_particle_edit(
+ Depsgraph *depsgraph, Scene *scene,
+ Object *ob, ParticleSystem *psys, ParticleSystem *psys_from)
{
PTCacheEdit *edit_from = psys_from->edit, *edit;
ParticleData *pa;
@@ -939,7 +953,7 @@ static void copy_particle_edit(Scene *scene, Object *ob, ParticleSystem *psys, P
recalc_lengths(edit);
recalc_emitter_field(ob, psys);
- PE_update_object(scene, ob, true);
+ PE_update_object(depsgraph, scene, ob, true);
}
static void remove_particle_systems_from_object(Object *ob_to)
@@ -967,7 +981,7 @@ static void remove_particle_systems_from_object(Object *ob_to)
}
/* single_psys_from is optional, if NULL all psys of ob_from are copied */
-static bool copy_particle_systems_to_object(Main *bmain,
+static bool copy_particle_systems_to_object(const bContext *C,
Scene *scene,
Object *ob_from,
ParticleSystem *single_psys_from,
@@ -975,13 +989,15 @@ static bool copy_particle_systems_to_object(Main *bmain,
int space,
bool duplicate_settings)
{
+ Main *bmain = CTX_data_main(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
ModifierData *md;
ParticleSystem *psys_start = NULL, *psys, *psys_from;
ParticleSystem **tmp_psys;
DerivedMesh *final_dm;
CustomDataMask cdmask;
int i, totpsys;
-
+
if (ob_to->type != OB_MESH)
return false;
if (!ob_to->data || ID_IS_LINKED(ob_to->data))
@@ -1020,7 +1036,7 @@ static bool copy_particle_systems_to_object(Main *bmain,
psys_start = totpsys > 0 ? tmp_psys[0] : NULL;
/* get the DM (psys and their modifiers have not been appended yet) */
- final_dm = mesh_get_derived_final(scene, ob_to, cdmask);
+ final_dm = mesh_get_derived_final(depsgraph, scene, ob_to, cdmask);
/* now append psys to the object and make modifiers */
for (i = 0, psys_from = PSYS_FROM_FIRST;
@@ -1048,8 +1064,9 @@ static bool copy_particle_systems_to_object(Main *bmain,
CDDM_calc_normals(psmd->dm_final);
DM_ensure_tessface(psmd->dm_final);
- if (psys_from->edit)
- copy_particle_edit(scene, ob_to, psys, psys_from);
+ if (psys_from->edit) {
+ copy_particle_edit(depsgraph, scene, ob_to, psys, psys_from);
+ }
if (duplicate_settings) {
id_us_min(&psys->part->id);
@@ -1083,7 +1100,9 @@ static bool copy_particle_systems_to_object(Main *bmain,
break;
}
if (ob_from != ob_to) {
- remap_hair_emitter(scene, ob_from, psys_from, ob_to, psys, psys->edit, from_mat, to_mat, psys_from->flag & PSYS_GLOBAL_HAIR, psys->flag & PSYS_GLOBAL_HAIR);
+ remap_hair_emitter(
+ depsgraph, scene, ob_from, psys_from, ob_to, psys, psys->edit,
+ from_mat, to_mat, psys_from->flag & PSYS_GLOBAL_HAIR, psys->flag & PSYS_GLOBAL_HAIR);
}
/* tag for recalc */
@@ -1093,7 +1112,7 @@ static bool copy_particle_systems_to_object(Main *bmain,
#undef PSYS_FROM_FIRST
#undef PSYS_FROM_NEXT
- DAG_id_tag_update(&ob_to->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_to->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, ob_to);
return true;
}
@@ -1116,7 +1135,6 @@ static int copy_particle_systems_exec(bContext *C, wmOperator *op)
const int space = RNA_enum_get(op->ptr, "space");
const bool remove_target_particles = RNA_boolean_get(op->ptr, "remove_target_particles");
const bool use_active = RNA_boolean_get(op->ptr, "use_active");
- Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
Object *ob_from = ED_object_active_context(C);
ParticleSystem *psys_from = use_active ? CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data : NULL;
@@ -1132,7 +1150,7 @@ static int copy_particle_systems_exec(bContext *C, wmOperator *op)
remove_particle_systems_from_object(ob_to);
changed = true;
}
- if (copy_particle_systems_to_object(bmain, scene, ob_from, psys_from, ob_to, space, false))
+ if (copy_particle_systems_to_object(C, scene, ob_from, psys_from, ob_to, space, false))
changed = true;
else
fail++;
@@ -1193,7 +1211,7 @@ static int duplicate_particle_systems_exec(bContext *C, wmOperator *op)
Scene *scene = CTX_data_scene(C);
Object *ob = ED_object_active_context(C);
ParticleSystem *psys = CTX_data_pointer_get_type(C, "particle_system", &RNA_ParticleSystem).data;
- copy_particle_systems_to_object(CTX_data_main(C), scene, ob, psys, ob,
+ copy_particle_systems_to_object(C, scene, ob, psys, ob,
PAR_COPY_SPACE_OBJECT, duplicate_settings);
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/physics/physics_fluid.c b/source/blender/editors/physics/physics_fluid.c
index ce1e9d5cf6a..541242fdc09 100644
--- a/source/blender/editors/physics/physics_fluid.c
+++ b/source/blender/editors/physics/physics_fluid.c
@@ -53,6 +53,8 @@
#include "BKE_report.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+
#include "LBM_fluidsim.h"
#include "ED_screen.h"
@@ -244,7 +246,7 @@ static void set_channel(float *channel, float time, float *value, int i, int siz
}
}
-static void set_vertex_channel(float *channel, float time, struct Scene *scene, struct FluidObject *fobj, int i)
+static void set_vertex_channel(Depsgraph *depsgraph, float *channel, float time, struct Scene *scene, struct FluidObject *fobj, int i)
{
Object *ob = fobj->object;
FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
@@ -257,7 +259,7 @@ static void set_vertex_channel(float *channel, float time, struct Scene *scene,
if (channel == NULL)
return;
- initElbeemMesh(scene, ob, &numVerts, &verts, &numTris, &tris, 1, modifierIndex);
+ initElbeemMesh(depsgraph, scene, ob, &numVerts, &verts, &numTris, &tris, 1, modifierIndex);
/* don't allow mesh to change number of verts in anim sequence */
if (numVerts != fobj->numVerts) {
@@ -329,11 +331,13 @@ static void free_all_fluidobject_channels(ListBase *fobjects)
static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), FluidsimSettings *domainSettings, FluidAnimChannels *channels, ListBase *fobjects)
{
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Base *base;
int i;
int length = channels->length;
float eval_time;
-
+
/* init time values (assuming that time moves at a constant speed; may be overridden later) */
init_time(domainSettings, channels);
@@ -343,7 +347,7 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid
channels->DomainTime = MEM_callocN(length * (CHANNEL_FLOAT+1) * sizeof(float), "channel DomainTime");
/* allocate fluid objects */
- for (base=scene->base.first; base; base= base->next) {
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
Object *ob = base->object;
FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
@@ -373,7 +377,7 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid
float *verts=NULL;
int *tris=NULL, modifierIndex = BLI_findindex(&ob->modifiers, (ModifierData *)fluidmd);
- initElbeemMesh(scene, ob, &fobj->numVerts, &verts, &fobj->numTris, &tris, 0, modifierIndex);
+ initElbeemMesh(depsgraph, scene, ob, &fobj->numVerts, &verts, &fobj->numTris, &tris, 0, modifierIndex);
fobj->VertexCache = MEM_callocN(length *((fobj->numVerts*CHANNEL_VEC)+1) * sizeof(float), "fluidobject VertexCache");
MEM_freeN(verts);
@@ -402,7 +406,7 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid
/* Modifying the global scene isn't nice, but we can do it in
* this part of the process before a threaded job is created */
scene->r.cfra = (int)eval_time;
- ED_update_for_newframe(CTX_data_main(C), scene, 1);
+ ED_update_for_newframe(CTX_data_main(C), depsgraph);
/* now scene data should be current according to animation system, so we fill the channels */
@@ -461,14 +465,15 @@ static void fluid_init_all_channels(bContext *C, Object *UNUSED(fsDomain), Fluid
}
if (fluid_is_animated_mesh(fluidmd->fss)) {
- set_vertex_channel(fobj->VertexCache, timeAtFrame, scene, fobj, i);
+ set_vertex_channel(depsgraph, fobj->VertexCache, timeAtFrame, scene, fobj, i);
}
}
}
}
-static void export_fluid_objects(ListBase *fobjects, Scene *scene, int length)
+static void export_fluid_objects(const bContext *C, ListBase *fobjects, Scene *scene, int length)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
FluidObject *fobj;
for (fobj=fobjects->first; fobj; fobj=fobj->next) {
@@ -491,7 +496,7 @@ static void export_fluid_objects(ListBase *fobjects, Scene *scene, int length)
fsmesh.type = fluidmd->fss->type;
fsmesh.name = ob->id.name;
- initElbeemMesh(scene, ob, &numVerts, &verts, &numTris, &tris, 0, modifierIndex);
+ initElbeemMesh(depsgraph, scene, ob, &numVerts, &verts, &numTris, &tris, 0, modifierIndex);
fsmesh.numVertices = numVerts;
fsmesh.numTriangles = numTris;
@@ -570,14 +575,14 @@ static void export_fluid_objects(ListBase *fobjects, Scene *scene, int length)
}
}
-static int fluid_validate_scene(ReportList *reports, Scene *scene, Object *fsDomain)
+static int fluid_validate_scene(ReportList *reports, ViewLayer *view_layer, Object *fsDomain)
{
Base *base;
Object *newdomain = NULL;
int channelObjCount = 0;
int fluidInputCount = 0;
- for (base=scene->base.first; base; base= base->next) {
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
Object *ob = base->object;
FluidsimModifierData *fluidmdtmp = (FluidsimModifierData *)modifiers_findByType(ob, eModifierType_Fluidsim);
@@ -835,7 +840,9 @@ static void fluidsim_delete_until_lastframe(FluidsimSettings *fss, const char *r
static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, short do_job)
{
- Scene *scene= CTX_data_scene(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
int i;
FluidsimSettings *domainSettings;
@@ -882,7 +889,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor
}
/* check scene for sane object/modifier settings */
- if (!fluid_validate_scene(reports, scene, fsDomain)) {
+ if (!fluid_validate_scene(reports, view_layer, fsDomain)) {
fluidbake_free_data(channels, fobjects, fsset, fb);
return 0;
}
@@ -947,7 +954,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor
/* reset to original current frame */
scene->r.cfra = origFrame;
- ED_update_for_newframe(CTX_data_main(C), scene, 1);
+ ED_update_for_newframe(CTX_data_main(C), depsgraph);
/* ******** init domain object's matrix ******** */
copy_m4_m4(domainMat, fsDomain->obmat);
@@ -1034,7 +1041,7 @@ static int fluidsimBake(bContext *C, ReportList *reports, Object *fsDomain, shor
elbeemAddDomain(fsset);
/* ******** export all fluid objects to elbeem ******** */
- export_fluid_objects(fobjects, scene, channels->length);
+ export_fluid_objects(C, fobjects, scene, channels->length);
/* custom data for fluid bake job */
fb->settings = fsset;
diff --git a/source/blender/editors/physics/physics_intern.h b/source/blender/editors/physics/physics_intern.h
index f3f3697caaa..72da417da63 100644
--- a/source/blender/editors/physics/physics_intern.h
+++ b/source/blender/editors/physics/physics_intern.h
@@ -33,11 +33,13 @@
#ifndef __PHYSICS_INTERN_H__
#define __PHYSICS_INTERN_H__
+struct Depsgraph;
struct Object;
struct PTCacheEdit;
struct ParticleSystem;
struct PointCache;
struct Scene;
+struct ViewLayer;
struct wmOperatorType;
/* particle_edit.c */
@@ -68,7 +70,9 @@ void PARTICLE_OT_edited_clear(struct wmOperatorType *ot);
void PARTICLE_OT_unify_length(struct wmOperatorType *ot);
-void PE_create_particle_edit(struct Scene *scene, struct Object *ob, struct PointCache *cache, struct ParticleSystem *psys);
+void PE_create_particle_edit(
+ struct Depsgraph *depsgraph, struct Scene *scene,
+ struct Object *ob, struct PointCache *cache, struct ParticleSystem *psys);
void recalc_lengths(struct PTCacheEdit *edit);
void recalc_emitter_field(struct Object *ob, struct ParticleSystem *psys);
void update_world_cos(struct Object *ob, struct PTCacheEdit *edit);
diff --git a/source/blender/editors/physics/physics_ops.c b/source/blender/editors/physics/physics_ops.c
index b1d708ebc07..758ef43590e 100644
--- a/source/blender/editors/physics/physics_ops.c
+++ b/source/blender/editors/physics/physics_ops.c
@@ -137,23 +137,6 @@ static void keymap_particle(wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "PARTICLE_OT_hide", HKEY, KM_PRESS, KM_SHIFT, 0);
RNA_boolean_set(kmi->ptr, "unselected", true);
- /* Shift+LMB behavior first, so it has priority over KM_ANY item below. */
- kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", true);
- RNA_boolean_set(kmi->ptr, "use_planar_constraint", true);
- RNA_boolean_set(kmi->ptr, "use_accurate", false);
-
- kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", true);
- RNA_boolean_set(kmi->ptr, "use_planar_constraint", false);
- RNA_boolean_set(kmi->ptr, "use_accurate", true);
-
- /* Using KM_ANY here to allow holding modifiers before starting to transform. */
- kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", true);
- RNA_boolean_set(kmi->ptr, "use_planar_constraint", false);
- RNA_boolean_set(kmi->ptr, "use_accurate", false);
-
WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "PARTICLE_OT_brush_edit", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
diff --git a/source/blender/editors/physics/physics_pointcache.c b/source/blender/editors/physics/physics_pointcache.c
index f36ebb3715e..fdafd6c28ed 100644
--- a/source/blender/editors/physics/physics_pointcache.c
+++ b/source/blender/editors/physics/physics_pointcache.c
@@ -42,6 +42,7 @@
#include "BKE_context.h"
#include "BKE_screen.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_particle.h"
#include "BKE_pointcache.h"
@@ -165,6 +166,8 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all)
baker->main = CTX_data_main(C);
baker->scene = CTX_data_scene(C);
+ baker->view_layer = CTX_data_view_layer(C);
+ baker->depsgraph = CTX_data_depsgraph(C);
baker->bake = RNA_boolean_get(op->ptr, "bake");
baker->render = 0;
baker->anim_init = 0;
@@ -174,18 +177,7 @@ static PTCacheBaker *ptcache_baker_create(bContext *C, wmOperator *op, bool all)
PointerRNA ptr = CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
Object *ob = ptr.id.data;
PointCache *cache = ptr.data;
-
- ListBase pidlist;
- BKE_ptcache_ids_from_object(&pidlist, ob, baker->scene, MAX_DUPLI_RECUR);
-
- for (PTCacheID *pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache) {
- baker->pid = *pid;
- break;
- }
- }
-
- BLI_freelistN(&pidlist);
+ baker->pid = BKE_ptcache_id_find(ob, baker->scene, cache);
}
return baker;
@@ -253,22 +245,23 @@ static void ptcache_bake_cancel(bContext *C, wmOperator *op)
static int ptcache_free_bake_all_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene= CTX_data_scene(C);
- Base *base;
+ Scene *scene = CTX_data_scene(C);
PTCacheID *pid;
ListBase pidlist;
- for (base=scene->base.first; base; base= base->next) {
- BKE_ptcache_ids_from_object(&pidlist, base->object, scene, MAX_DUPLI_RECUR);
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
+ {
+ BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
- for (pid=pidlist.first; pid; pid=pid->next) {
+ for (pid = pidlist.first; pid; pid = pid->next) {
ptcache_free_bake(pid->cache);
}
BLI_freelistN(&pidlist);
- WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, base->object);
+ WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob);
}
+ FOREACH_SCENE_OBJECT_END;
WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
@@ -387,22 +380,14 @@ static int ptcache_add_new_exec(bContext *C, wmOperator *UNUSED(op))
PointerRNA ptr= CTX_data_pointer_get_type(C, "point_cache", &RNA_PointCache);
Object *ob= ptr.id.data;
PointCache *cache= ptr.data;
- PTCacheID *pid;
- ListBase pidlist;
+ PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache);
- BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
-
- for (pid=pidlist.first; pid; pid=pid->next) {
- if (pid->cache == cache) {
- PointCache *cache_new = BKE_ptcache_add(pid->ptcaches);
- cache_new->step = pid->default_step;
- *(pid->cache_ptr) = cache_new;
- break;
- }
+ if (pid.cache) {
+ PointCache *cache_new = BKE_ptcache_add(pid.ptcaches);
+ cache_new->step = pid.default_step;
+ *(pid.cache_ptr) = cache_new;
}
- BLI_freelistN(&pidlist);
-
WM_event_add_notifier(C, NC_SCENE|ND_FRAME, scene);
WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob);
@@ -414,26 +399,15 @@ static int ptcache_remove_exec(bContext *C, wmOperator *UNUSED(op))
Scene *scene= CTX_data_scene(C);
Object *ob= ptr.id.data;
PointCache *cache= ptr.data;
- PTCacheID *pid;
- ListBase pidlist;
+ PTCacheID pid = BKE_ptcache_id_find(ob, scene, cache);
- BKE_ptcache_ids_from_object(&pidlist, ob, scene, MAX_DUPLI_RECUR);
-
- for (pid=pidlist.first; pid; pid=pid->next) {
- if (pid->cache == cache) {
- if (pid->ptcaches->first == pid->ptcaches->last)
- continue; /* don't delete last cache */
-
- BLI_remlink(pid->ptcaches, pid->cache);
- BKE_ptcache_free(pid->cache);
- *(pid->cache_ptr) = pid->ptcaches->first;
-
- break;
- }
+ /* don't delete last cache */
+ if (pid.cache && pid.ptcaches->first != pid.ptcaches->last) {
+ BLI_remlink(pid.ptcaches, pid.cache);
+ BKE_ptcache_free(pid.cache);
+ *(pid.cache_ptr) = pid.ptcaches->first;
}
- BLI_freelistN(&pidlist);
-
WM_event_add_notifier(C, NC_OBJECT|ND_POINTCACHE, ob);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/physics/rigidbody_constraint.c b/source/blender/editors/physics/rigidbody_constraint.c
index 412f9acf718..3bcc047bf5b 100644
--- a/source/blender/editors/physics/rigidbody_constraint.c
+++ b/source/blender/editors/physics/rigidbody_constraint.c
@@ -38,12 +38,14 @@
#include "DNA_scene_types.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_group.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_rigidbody.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -88,10 +90,10 @@ bool ED_rigidbody_constraint_add(Main *bmain, Scene *scene, Object *ob, int type
ob->rigidbody_constraint->flag |= RBC_FLAG_NEEDS_VALIDATE;
/* add constraint to rigid body constraint group */
- BKE_group_object_add(rbw->constraints, ob, scene, NULL);
+ BKE_group_object_add(rbw->constraints, ob);
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
return true;
}
@@ -101,10 +103,10 @@ void ED_rigidbody_constraint_remove(Main *bmain, Scene *scene, Object *ob)
BKE_rigidbody_remove_constraint(scene, ob);
if (rbw)
- BKE_group_object_unlink(rbw->constraints, ob, scene, NULL);
+ BKE_group_object_unlink(rbw->constraints, ob);
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
/* ********************************************** */
@@ -116,8 +118,9 @@ static int rigidbody_con_add_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
RigidBodyWorld *rbw = BKE_rigidbody_get_world(scene);
- Object *ob = (scene) ? OBACT : NULL;
+ Object *ob = OBACT(view_layer);
int type = RNA_enum_get(op->ptr, "type");
bool changed;
@@ -165,11 +168,8 @@ static int rigidbody_con_remove_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
- Object *ob = (scene) ? OBACT : NULL;
-
- /* sanity checks */
- if (scene == NULL)
- return OPERATOR_CANCELLED;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
/* apply to active object */
if (ELEM(NULL, ob, ob->rigidbody_constraint)) {
diff --git a/source/blender/editors/physics/rigidbody_object.c b/source/blender/editors/physics/rigidbody_object.c
index b7083c29721..3553ffa5033 100644
--- a/source/blender/editors/physics/rigidbody_object.c
+++ b/source/blender/editors/physics/rigidbody_object.c
@@ -43,12 +43,14 @@
#include "BLT_translation.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_group.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_rigidbody.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -118,10 +120,10 @@ bool ED_rigidbody_object_add(Main *bmain, Scene *scene, Object *ob, int type, Re
ob->rigidbody_object->flag |= RBO_FLAG_NEEDS_VALIDATE;
/* add object to rigid body group */
- BKE_group_object_add(rbw->group, ob, scene, NULL);
+ BKE_group_object_add(rbw->group, ob);
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
return true;
}
@@ -132,10 +134,10 @@ void ED_rigidbody_object_remove(Main *bmain, Scene *scene, Object *ob)
BKE_rigidbody_remove_object(scene, ob);
if (rbw)
- BKE_group_object_unlink(rbw->group, ob, scene, NULL);
+ BKE_group_object_unlink(rbw->group, ob);
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
/* ********************************************** */
@@ -344,7 +346,7 @@ static int rigidbody_objects_shape_change_exec(bContext *C, wmOperator *op)
RNA_pointer_create(&ob->id, &RNA_RigidBodyObject, ob->rigidbody_object, &ptr);
RNA_enum_set(&ptr, "collision_shape", shape);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
changed = true;
}
@@ -526,7 +528,7 @@ static int rigidbody_objects_calc_mass_exec(bContext *C, wmOperator *op)
RNA_pointer_create(&ob->id, &RNA_RigidBodyObject, ob->rigidbody_object, &ptr);
RNA_float_set(&ptr, "mass", mass);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
changed = true;
}
diff --git a/source/blender/editors/render/CMakeLists.txt b/source/blender/editors/render/CMakeLists.txt
index ec8bf3e955d..ed2e9747d1c 100644
--- a/source/blender/editors/render/CMakeLists.txt
+++ b/source/blender/editors/render/CMakeLists.txt
@@ -24,6 +24,8 @@ set(INC
../../blenlib
../../blenloader
../../blentranslation
+ ../../depsgraph
+ ../../draw
../../gpu
../../imbuf
../../bmesh
diff --git a/source/blender/editors/render/render_intern.h b/source/blender/editors/render/render_intern.h
index fb07b03c286..a1f646aefc1 100644
--- a/source/blender/editors/render/render_intern.h
+++ b/source/blender/editors/render/render_intern.h
@@ -53,8 +53,8 @@ void WORLD_OT_new(struct wmOperatorType *ot);
void MATERIAL_OT_copy(struct wmOperatorType *ot);
void MATERIAL_OT_paste(struct wmOperatorType *ot);
-void SCENE_OT_render_layer_add(struct wmOperatorType *ot);
-void SCENE_OT_render_layer_remove(struct wmOperatorType *ot);
+void SCENE_OT_view_layer_add(struct wmOperatorType *ot);
+void SCENE_OT_view_layer_remove(struct wmOperatorType *ot);
void SCENE_OT_render_view_add(struct wmOperatorType *ot);
void SCENE_OT_render_view_remove(struct wmOperatorType *ot);
@@ -83,15 +83,10 @@ void SCENE_OT_freestyle_stroke_material_create(struct wmOperatorType *ot);
void TEXTURE_OT_slot_copy(struct wmOperatorType *ot);
void TEXTURE_OT_slot_paste(struct wmOperatorType *ot);
void TEXTURE_OT_slot_move(struct wmOperatorType *ot);
-void TEXTURE_OT_envmap_save(struct wmOperatorType *ot);
-void TEXTURE_OT_envmap_clear(struct wmOperatorType *ot);
-void TEXTURE_OT_envmap_clear_all(struct wmOperatorType *ot);
/* render_internal.c */
void RENDER_OT_render(struct wmOperatorType *ot);
void RENDER_OT_shutter_curve_preset(struct wmOperatorType *ot);
-void render_view3d_update(struct RenderEngine *engine, const struct bContext *C);
-void render_view3d_draw(struct RenderEngine *engine, const struct bContext *C);
/* render_view.c */
struct ScrArea *render_view_open(struct bContext *C, int mx, int my, struct ReportList *reports);
diff --git a/source/blender/editors/render/render_internal.c b/source/blender/editors/render/render_internal.c
index 509fdcf080a..4e44c9b1185 100644
--- a/source/blender/editors/render/render_internal.c
+++ b/source/blender/editors/render/render_internal.c
@@ -54,9 +54,9 @@
#include "BKE_camera.h"
#include "BKE_context.h"
#include "BKE_colortools.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_node.h"
@@ -66,6 +66,9 @@
#include "BKE_screen.h"
#include "BKE_scene.h"
#include "BKE_undo_system.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -83,6 +86,7 @@
#include "IMB_colormanagement.h"
#include "IMB_imbuf_types.h"
+#include "GPU_shader.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
@@ -100,9 +104,13 @@ static int render_break(void *rjv);
typedef struct RenderJob {
Main *main;
Scene *scene;
+ ViewLayer *single_layer;
Scene *current_scene;
+ /* TODO(sergey): Should not be needed once engine will have own
+ * depsgraph and copy-on-write will be implemented.
+ */
+ Depsgraph *depsgraph;
Render *re;
- SceneRenderLayer *srl;
struct Object *camera_override;
int lay_override;
bool v3d_override;
@@ -255,7 +263,7 @@ static void image_buffer_rect_update(RenderJob *rj, RenderResult *rr, ImBuf *ibu
/* set callbacks, exported to sequence render too.
* Only call in foreground (UI) renders. */
-static void screen_render_scene_layer_set(wmOperator *op, Main *mainp, Scene **scene, SceneRenderLayer **srl)
+static void screen_render_single_layer_set(wmOperator *op, Main *mainp, WorkSpace *workspace, Scene **scene, ViewLayer **single_layer)
{
/* single layer re-render */
if (RNA_struct_property_is_set(op->ptr, "scene")) {
@@ -275,14 +283,17 @@ static void screen_render_scene_layer_set(wmOperator *op, Main *mainp, Scene **s
}
if (RNA_struct_property_is_set(op->ptr, "layer")) {
- SceneRenderLayer *rl;
+ ViewLayer *rl;
char rl_name[RE_MAXNAME];
RNA_string_get(op->ptr, "layer", rl_name);
- rl = (SceneRenderLayer *)BLI_findstring(&(*scene)->r.layers, rl_name, offsetof(SceneRenderLayer, name));
+ rl = (ViewLayer *)BLI_findstring(&(*scene)->view_layers, rl_name, offsetof(ViewLayer, name));
if (rl)
- *srl = rl;
+ *single_layer = rl;
+ }
+ else if (((*scene)->r.scemode & R_SINGLE_LAYER) && workspace) {
+ *single_layer = BKE_view_layer_from_workspace_get(*scene, workspace);
}
}
@@ -290,18 +301,25 @@ static void screen_render_scene_layer_set(wmOperator *op, Main *mainp, Scene **s
static int screen_render_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = NULL;
+ RenderEngineType *re_type = RE_engines_find(scene->r.engine);
+ ViewLayer *single_layer = NULL;
Render *re;
Image *ima;
View3D *v3d = CTX_wm_view3d(C);
Main *mainp = CTX_data_main(C);
+ WorkSpace *workspace = CTX_wm_workspace(C);
unsigned int lay_override;
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL;
+ /* Cannot do render if there is not this function. */
+ if (re_type->render_to_image == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
/* custom scene and single layer re-render */
- screen_render_scene_layer_set(op, mainp, &scene, &srl);
+ screen_render_single_layer_set(op, mainp, workspace, &scene, &single_layer);
if (!is_animation && is_write_still && BKE_imtype_is_movie(scene->r.im_format.imtype)) {
BKE_report(op->reports, RPT_ERROR, "Cannot write a single file with an animation format selected");
@@ -330,13 +348,13 @@ static int screen_render_exec(bContext *C, wmOperator *op)
if (is_animation)
RE_BlenderAnim(re, mainp, scene, camera_override, lay_override, scene->r.sfra, scene->r.efra, scene->r.frame_step);
else
- RE_BlenderFrame(re, mainp, scene, srl, camera_override, lay_override, scene->r.cfra, is_write_still);
+ RE_BlenderFrame(re, mainp, scene, single_layer, camera_override, lay_override, scene->r.cfra, is_write_still);
BLI_threaded_malloc_end();
RE_SetReports(re, NULL);
// no redraw needed, we leave state as we entered it
- ED_update_for_newframe(mainp, scene, 1);
+ ED_update_for_newframe(mainp, CTX_data_depsgraph(C));
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, scene);
@@ -492,8 +510,9 @@ static void render_image_update_pass_and_layer(RenderJob *rj, RenderResult *rr,
for (wm = rj->main->wm.first; wm && matched_sa == NULL; wm = wm->id.next) { /* only 1 wm */
wmWindow *win;
for (win = wm->windows.first; win && matched_sa == NULL; win = win->next) {
- ScrArea *sa;
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+ const bScreen *screen = WM_window_get_active_screen(win);
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->spacetype == SPACE_IMAGE) {
SpaceImage *sima = sa->spacedata.first;
// sa->spacedata might be empty when toggling fullscreen mode.
@@ -604,7 +623,7 @@ static void render_startjob(void *rjv, short *stop, short *do_update, float *pro
if (rj->anim)
RE_BlenderAnim(rj->re, rj->main, rj->scene, rj->camera_override, rj->lay_override, rj->scene->r.sfra, rj->scene->r.efra, rj->scene->r.frame_step);
else
- RE_BlenderFrame(rj->re, rj->main, rj->scene, rj->srl, rj->camera_override, rj->lay_override, rj->scene->r.cfra, rj->write_still);
+ RE_BlenderFrame(rj->re, rj->main, rj->scene, rj->single_layer, rj->camera_override, rj->lay_override, rj->scene->r.cfra, rj->write_still);
RE_SetReports(rj->re, NULL);
}
@@ -617,8 +636,9 @@ static void render_image_restore_layer(RenderJob *rj)
for (wm = rj->main->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
wmWindow *win;
for (win = wm->windows.first; win; win = win->next) {
- ScrArea *sa;
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+ const bScreen *screen = WM_window_get_active_screen(win);
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
if (sa == rj->sa) {
if (sa->spacetype == SPACE_IMAGE) {
SpaceImage *sima = sa->spacedata.first;
@@ -660,7 +680,7 @@ static void render_endjob(void *rjv)
if (rj->anim && !(rj->scene->r.scemode & R_NO_FRAME_UPDATE)) {
/* possible this fails of loading new file while rendering */
if (G.main->wm.first) {
- ED_update_for_newframe(G.main, rj->scene, 1);
+ ED_update_for_newframe(G.main, rj->depsgraph);
}
}
@@ -670,7 +690,7 @@ static void render_endjob(void *rjv)
/* potentially set by caller */
rj->scene->r.scemode &= ~R_NO_FRAME_UPDATE;
- if (rj->srl) {
+ if (rj->single_layer) {
nodeUpdateID(rj->scene->nodetree, &rj->scene->id);
WM_main_add_notifier(NC_NODE | NA_EDITED, rj->scene);
}
@@ -700,7 +720,7 @@ static void render_endjob(void *rjv)
* engine API, so lets use simple and robust way for now
* - sergey -
*/
- if (rj->scene->r.layers.first != rj->scene->r.layers.last ||
+ if (rj->scene->view_layers.first != rj->scene->view_layers.last ||
rj->image_outdated)
{
void *lock;
@@ -733,7 +753,7 @@ static void render_endjob(void *rjv)
scene->lay_updated = 0;
}
- DAG_on_visible_update(G.main, false);
+ DEG_on_visible_update(G.main, false);
}
}
@@ -797,33 +817,46 @@ static void screen_render_cancel(bContext *C, wmOperator *op)
WM_jobs_kill_type(wm, scene, WM_JOB_TYPE_RENDER);
}
-static void clean_viewport_memory(Main *bmain, Scene *scene, int renderlay)
+static void clean_viewport_memory_base(Base *base)
{
- Object *object;
- Scene *sce_iter;
- Base *base;
+ if ((base->flag & BASE_VISIBLED) == 0) {
+ return;
+ }
+
+ Object *object = base->object;
- for (object = bmain->object.first; object; object = object->id.next) {
- object->id.tag |= LIB_TAG_DOIT;
+ if (object->id.tag & LIB_TAG_DOIT) {
+ return;
}
- for (SETLOOPER(scene, sce_iter, base)) {
- if ((base->lay & renderlay) == 0) {
- continue;
- }
- if (RE_allow_render_generic_object(base->object)) {
- base->object->id.tag &= ~LIB_TAG_DOIT;
- }
+ object->id.tag &= ~LIB_TAG_DOIT;
+ if (RE_allow_render_generic_object(object)) {
+ BKE_object_free_derived_caches(object);
}
+}
+
+static void clean_viewport_memory(Main *bmain, Scene *scene)
+{
+ Scene *sce_iter;
+ Base *base;
+
+ /* Tag all the available objects. */
+ BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, true);
- for (SETLOOPER(scene, sce_iter, base)) {
- object = base->object;
- if ((object->id.tag & LIB_TAG_DOIT) == 0) {
- continue;
+ /* Go over all the visible objects. */
+ for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+ ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
+
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ clean_viewport_memory_base(base);
+ }
}
- object->id.tag &= ~LIB_TAG_DOIT;
+ }
- BKE_object_free_derived_caches(object);
+ for (SETLOOPER_SET_ONLY(scene, sce_iter, base)) {
+ clean_viewport_memory_base(base);
}
}
@@ -831,9 +864,10 @@ static void clean_viewport_memory(Main *bmain, Scene *scene, int renderlay)
static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
/* new render clears all callbacks */
- Main *mainp;
+ Main *bmain = CTX_data_main(C);
+ ViewLayer *single_layer = NULL;
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = NULL;
+ RenderEngineType *re_type = RE_engines_find(scene->r.engine);
Render *re;
wmJob *wm_job;
RenderJob *rj;
@@ -843,18 +877,24 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
const bool is_write_still = RNA_boolean_get(op->ptr, "write_still");
const bool use_viewport = RNA_boolean_get(op->ptr, "use_viewport");
View3D *v3d = use_viewport ? CTX_wm_view3d(C) : NULL;
+ WorkSpace *workspace = CTX_wm_workspace(C);
struct Object *camera_override = v3d ? V3D_CAMERA_LOCAL(v3d) : NULL;
const char *name;
ScrArea *sa;
-
+
+ /* Cannot do render if there is not this function. */
+ if (re_type->render_to_image == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ /* custom scene and single layer re-render */
+ screen_render_single_layer_set(op, bmain, workspace, &scene, &single_layer);
+
/* only one render job at a time */
if (WM_jobs_test(CTX_wm_manager(C), scene, WM_JOB_TYPE_RENDER))
return OPERATOR_CANCELLED;
- if (RE_force_single_renderlayer(scene))
- WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- if (!RE_is_rendering_allowed(scene, camera_override, op->reports)) {
+ if (!RE_is_rendering_allowed(scene, single_layer, camera_override, op->reports)) {
return OPERATOR_CANCELLED;
}
@@ -866,15 +906,6 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
/* stop all running jobs, except screen one. currently previews frustrate Render */
WM_jobs_kill_all_except(CTX_wm_manager(C), CTX_wm_screen(C));
- /* get main */
- if (G.debug_value == 101) {
- /* thread-safety experiment, copy main from the undo buffer */
- struct MemFile *memfile = ED_undosys_stack_memfile_get_active(CTX_wm_manager(C)->undo_stack);
- mainp = BLO_memfile_main_get(memfile, CTX_data_main(C), &scene);
- }
- else
- mainp = CTX_data_main(C);
-
/* cancel animation playback */
if (ED_screen_animation_playing(CTX_wm_manager(C)))
ED_screen_animation_play(C, 0, 0);
@@ -900,18 +931,17 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
jobflag = WM_JOB_EXCL_RENDER | WM_JOB_PRIORITY | WM_JOB_PROGRESS;
- /* custom scene and single layer re-render */
- screen_render_scene_layer_set(op, mainp, &scene, &srl);
-
if (RNA_struct_property_is_set(op->ptr, "layer"))
jobflag |= WM_JOB_SUSPEND;
/* job custom data */
rj = MEM_callocN(sizeof(RenderJob), "render job");
- rj->main = mainp;
+ rj->main = bmain;
rj->scene = scene;
rj->current_scene = rj->scene;
- rj->srl = srl;
+ rj->single_layer = single_layer;
+ /* TODO(sergey): Render engine should be using own depsgraph. */
+ rj->depsgraph = CTX_data_depsgraph(C);
rj->camera_override = camera_override;
rj->lay_override = 0;
rj->anim = is_animation;
@@ -946,8 +976,6 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
/* Lock the user interface depending on render settings. */
if (scene->r.use_lock_interface) {
- int renderlay = rj->lay_override ? rj->lay_override : scene->lay;
-
WM_set_locked_interface(CTX_wm_manager(C), true);
/* Set flag interface need to be unlocked.
@@ -961,7 +989,7 @@ static int screen_render_invoke(bContext *C, wmOperator *op, const wmEvent *even
rj->interface_locked = true;
/* Clean memory used by viewport? */
- clean_viewport_memory(rj->main, scene, renderlay);
+ clean_viewport_memory(rj->main, scene);
}
/* setup job */
@@ -1043,614 +1071,6 @@ void RENDER_OT_render(wmOperatorType *ot)
}
-/* ************** preview for 3d viewport ***************** */
-
-#define PR_UPDATE_VIEW 1
-#define PR_UPDATE_RENDERSIZE 2
-#define PR_UPDATE_MATERIAL 4
-#define PR_UPDATE_DATABASE 8
-
-typedef struct RenderPreview {
- /* from wmJob */
- void *owner;
- short *stop, *do_update;
- wmJob *job;
-
- Scene *scene;
- ScrArea *sa;
- ARegion *ar;
- View3D *v3d;
- RegionView3D *rv3d;
- Main *bmain;
- RenderEngine *engine;
-
- float viewmat[4][4];
-
- int start_resolution_divider;
- int resolution_divider;
- bool has_freestyle;
-} RenderPreview;
-
-static int render_view3d_disprect(Scene *scene, ARegion *ar, View3D *v3d, RegionView3D *rv3d, rcti *disprect)
-{
- /* copied code from view3d_draw.c */
- rctf viewborder;
- int draw_border;
-
- if (rv3d->persp == RV3D_CAMOB)
- draw_border = (scene->r.mode & R_BORDER) != 0;
- else
- draw_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0;
-
- if (draw_border) {
- if (rv3d->persp == RV3D_CAMOB) {
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, false);
-
- disprect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder);
- disprect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder);
- disprect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder);
- disprect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder);
- }
- else {
- disprect->xmin = v3d->render_border.xmin * ar->winx;
- disprect->xmax = v3d->render_border.xmax * ar->winx;
- disprect->ymin = v3d->render_border.ymin * ar->winy;
- disprect->ymax = v3d->render_border.ymax * ar->winy;
- }
-
- return 1;
- }
-
- BLI_rcti_init(disprect, 0, 0, 0, 0);
- return 0;
-}
-
-/* returns true if OK */
-static bool render_view3d_get_rects(ARegion *ar, View3D *v3d, RegionView3D *rv3d, rctf *viewplane, RenderEngine *engine,
- float *r_clipsta, float *r_clipend, float *r_pixsize, bool *r_ortho)
-{
-
- if (ar->winx < 4 || ar->winy < 4) return false;
-
- *r_ortho = ED_view3d_viewplane_get(v3d, rv3d, ar->winx, ar->winy, viewplane, r_clipsta, r_clipend, r_pixsize);
-
- engine->resolution_x = ar->winx;
- engine->resolution_y = ar->winy;
-
- return true;
-}
-
-static bool render_view3d_is_valid(RenderPreview *rp)
-{
- return (rp->rv3d->render_engine != NULL);
-}
-
-/* called by renderer, checks job value */
-static int render_view3d_break(void *rpv)
-{
- RenderPreview *rp = rpv;
-
- if (G.is_break)
- return 1;
-
- /* during render, rv3d->engine can get freed */
- if (render_view3d_is_valid(rp) == false) {
- *rp->stop = 1;
- }
-
- return *(rp->stop);
-}
-
-static void render_view3d_display_update(void *rpv, RenderResult *UNUSED(rr), volatile struct rcti *UNUSED(rect))
-{
- RenderPreview *rp = rpv;
-
- *(rp->do_update) = true;
-}
-
-static void render_view3d_renderinfo_cb(void *rjp, RenderStats *rs)
-{
- RenderPreview *rp = rjp;
-
- /* during render, rv3d->engine can get freed */
- if (rp->rv3d->render_engine == NULL) {
- *rp->stop = 1;
- }
- else {
- make_renderinfo_string(rs, rp->scene, false, NULL, rp->engine->text);
-
- /* make jobs timer to send notifier */
- *(rp->do_update) = true;
- }
-}
-
-BLI_INLINE void rcti_scale_coords(rcti *scaled_rect, const rcti *rect,
- const float scale)
-{
- scaled_rect->xmin = rect->xmin * scale;
- scaled_rect->ymin = rect->ymin * scale;
- scaled_rect->xmax = rect->xmax * scale;
- scaled_rect->ymax = rect->ymax * scale;
-}
-
-static void render_update_resolution(Render *re, const RenderPreview *rp,
- bool use_border, const rcti *clip_rect)
-{
- int winx = rp->ar->winx / rp->resolution_divider;
- int winy = rp->ar->winy / rp->resolution_divider;
- if (use_border) {
- rcti scaled_cliprct;
- rcti_scale_coords(&scaled_cliprct, clip_rect,
- 1.0f / rp->resolution_divider);
- RE_ChangeResolution(re, winx, winy, &scaled_cliprct);
- }
- else {
- RE_ChangeResolution(re, winx, winy, NULL);
- }
-
- if (rp->has_freestyle) {
- if (rp->resolution_divider == BKE_render_preview_pixel_size(&rp->scene->r)) {
- RE_ChangeModeFlag(re, R_EDGE_FRS, false);
- }
- else {
- RE_ChangeModeFlag(re, R_EDGE_FRS, true);
- }
- }
-}
-
-static void render_view3d_startjob(void *customdata, short *stop, short *do_update, float *UNUSED(progress))
-{
- RenderPreview *rp = customdata;
- Render *re;
- RenderStats *rstats;
- rctf viewplane;
- rcti cliprct;
- float clipsta, clipend, pixsize;
- bool orth, restore = 0;
- char name[32];
- int update_flag;
- bool use_border;
- int ob_inst_update_flag = 0;
-
- update_flag = rp->engine->job_update_flag;
- rp->engine->job_update_flag = 0;
-
- //printf("ma %d res %d view %d db %d\n", update_flag & PR_UPDATE_MATERIAL, update_flag & PR_UPDATE_RENDERSIZE, update_flag & PR_UPDATE_VIEW, update_flag & PR_UPDATE_DATABASE);
-
- G.is_break = false;
-
- if (false == render_view3d_get_rects(rp->ar, rp->v3d, rp->rv3d, &viewplane, rp->engine, &clipsta, &clipend, &pixsize, &orth))
- return;
-
- rp->stop = stop;
- rp->do_update = do_update;
-
- // printf("Enter previewrender\n");
-
- /* ok, are we rendering all over? */
- sprintf(name, "View3dPreview %p", (void *)rp->ar);
- re = rp->engine->re = RE_GetRender(name);
-
- /* set this always, rp is different for each job */
- RE_test_break_cb(re, rp, render_view3d_break);
- RE_display_update_cb(re, rp, render_view3d_display_update);
- RE_stats_draw_cb(re, rp, render_view3d_renderinfo_cb);
-
- rstats = RE_GetStats(re);
-
- if (update_flag & PR_UPDATE_VIEW) {
- Object *object;
- rp->resolution_divider = rp->start_resolution_divider;
-
- /* Same as database_init_objects(), loop over all objects.
- * We might consider de-duplicating the code between this two cases.
- */
- for (object = rp->bmain->object.first; object; object = object->id.next) {
- float mat[4][4];
- mul_m4_m4m4(mat, rp->viewmat, object->obmat);
- invert_m4_m4(object->imat_ren, mat);
- }
- }
-
- use_border = render_view3d_disprect(rp->scene, rp->ar, rp->v3d,
- rp->rv3d, &cliprct);
-
- if ((update_flag & (PR_UPDATE_RENDERSIZE | PR_UPDATE_DATABASE | PR_UPDATE_VIEW)) || rstats->convertdone == 0) {
- RenderData rdata;
-
- /* no osa, blur, seq, layers, savebuffer etc for preview render */
- rdata = rp->scene->r;
- rdata.mode &= ~(R_OSA | R_MBLUR | R_BORDER | R_PANORAMA);
- rdata.scemode &= ~(R_DOSEQ | R_DOCOMP | R_FREE_IMAGE | R_EXR_TILE_FILE | R_FULL_SAMPLE);
- rdata.scemode |= R_VIEWPORT_PREVIEW;
-
- /* we do use layers, but only active */
- rdata.scemode |= R_SINGLE_LAYER;
-
- /* initalize always */
- if (use_border) {
- rdata.mode |= R_BORDER;
- RE_InitState(re, NULL, &rdata, NULL, rp->ar->winx, rp->ar->winy, &cliprct);
- }
- else
- RE_InitState(re, NULL, &rdata, NULL, rp->ar->winx, rp->ar->winy, NULL);
- }
-
- if (orth)
- RE_SetOrtho(re, &viewplane, clipsta, clipend);
- else
- RE_SetWindow(re, &viewplane, clipsta, clipend);
-
- RE_SetPixelSize(re, pixsize);
-
- if ((update_flag & PR_UPDATE_DATABASE) || rstats->convertdone == 0) {
- unsigned int lay = rp->scene->lay;
-
- /* allow localview render for objects with lights in normal layers */
- if (rp->v3d->lay & 0xFF000000)
- lay |= rp->v3d->lay;
- else lay = rp->v3d->lay;
-
- RE_SetView(re, rp->viewmat);
-
- /* copying blender data while main thread is locked, to avoid crashes */
- WM_job_main_thread_lock_acquire(rp->job);
- RE_Database_Free(re);
- RE_Database_FromScene(re, rp->bmain, rp->scene, lay, 0); // 0= dont use camera view
- WM_job_main_thread_lock_release(rp->job);
-
- /* do preprocessing like building raytree, shadows, volumes, SSS */
- RE_Database_Preprocess(re);
-
- /* conversion not completed, need to do it again */
- if (!rstats->convertdone) {
- if (render_view3d_is_valid(rp)) {
- rp->engine->job_update_flag |= PR_UPDATE_DATABASE;
- }
- }
-
- // printf("dbase update\n");
- }
- else {
- // printf("dbase rotate\n");
- RE_DataBase_IncrementalView(re, rp->viewmat, 0);
- restore = 1;
- }
-
- RE_DataBase_ApplyWindow(re);
-
- /* OK, can we enter render code? */
- if (rstats->convertdone) {
- bool first_time = true;
-
- if (update_flag & PR_UPDATE_VIEW) {
- ob_inst_update_flag |= RE_OBJECT_INSTANCES_UPDATE_VIEW;
- }
-
- RE_updateRenderInstances(re, ob_inst_update_flag);
-
- for (;;) {
- int pixel_size = BKE_render_preview_pixel_size(&rp->scene->r);
- if (first_time == false) {
- if (restore)
- RE_DataBase_IncrementalView(re, rp->viewmat, 1);
-
- rp->resolution_divider = MAX2(rp->resolution_divider / 2, pixel_size);
- *do_update = 1;
-
- render_update_resolution(re, rp, use_border, &cliprct);
-
- RE_DataBase_IncrementalView(re, rp->viewmat, 0);
- RE_DataBase_ApplyWindow(re);
- restore = 1;
- }
- else {
- render_update_resolution(re, rp, use_border, &cliprct);
- }
-
- RE_TileProcessor(re);
-
- first_time = false;
-
- if (*stop || rp->resolution_divider == pixel_size) {
- break;
- }
- }
-
- /* always rotate back */
- if (restore)
- RE_DataBase_IncrementalView(re, rp->viewmat, 1);
- }
-}
-
-static void render_view3d_free(void *customdata)
-{
- RenderPreview *rp = customdata;
-
- MEM_freeN(rp);
-}
-
-static bool render_view3d_flag_changed(RenderEngine *engine, const bContext *C)
-{
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
- View3D *v3d = CTX_wm_view3d(C);
- ARegion *ar = CTX_wm_region(C);
- Scene *scene = CTX_data_scene(C);
- Render *re;
- rctf viewplane;
- rcti disprect;
- float clipsta, clipend;
- bool orth;
- int job_update_flag = 0;
- char name[32];
-
- /* ensure render engine exists */
- re = engine->re;
-
- if (!re) {
- sprintf(name, "View3dPreview %p", (void *)ar);
- re = engine->re = RE_GetRender(name);
- if (!re)
- re = engine->re = RE_NewRender(name);
-
- engine->update_flag |= RE_ENGINE_UPDATE_DATABASE;
- }
-
- /* check update_flag */
- if (engine->update_flag & RE_ENGINE_UPDATE_MA)
- job_update_flag |= PR_UPDATE_MATERIAL;
-
- if (engine->update_flag & RE_ENGINE_UPDATE_OTHER)
- job_update_flag |= PR_UPDATE_MATERIAL;
-
- if (engine->update_flag & RE_ENGINE_UPDATE_DATABASE) {
- job_update_flag |= PR_UPDATE_DATABASE;
-
- /* load editmesh */
- if (scene->obedit)
- ED_object_editmode_load(scene->obedit);
- }
-
- engine->update_flag = 0;
-
- /* check if viewport changed */
- if (engine->last_winx != ar->winx || engine->last_winy != ar->winy) {
- engine->last_winx = ar->winx;
- engine->last_winy = ar->winy;
- job_update_flag |= PR_UPDATE_RENDERSIZE;
- }
-
- if (compare_m4m4(engine->last_viewmat, rv3d->viewmat, 0.00001f) == 0) {
- copy_m4_m4(engine->last_viewmat, rv3d->viewmat);
- job_update_flag |= PR_UPDATE_VIEW;
- }
-
- render_view3d_get_rects(ar, v3d, rv3d, &viewplane, engine, &clipsta, &clipend, NULL, &orth);
-
- if (BLI_rctf_compare(&viewplane, &engine->last_viewplane, 0.00001f) == 0) {
- engine->last_viewplane = viewplane;
- job_update_flag |= PR_UPDATE_VIEW;
- }
-
- render_view3d_disprect(scene, ar, v3d, rv3d, &disprect);
- if (BLI_rcti_compare(&disprect, &engine->last_disprect) == 0) {
- engine->last_disprect = disprect;
- job_update_flag |= PR_UPDATE_RENDERSIZE;
- }
-
- /* any changes? go ahead and rerender */
- if (job_update_flag) {
- engine->job_update_flag |= job_update_flag;
- return true;
- }
-
- return false;
-}
-
-static void render_view3d_do(RenderEngine *engine, const bContext *C)
-{
- wmJob *wm_job;
- RenderPreview *rp;
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
- int width = ar->winx, height = ar->winy;
- int divider = BKE_render_preview_pixel_size(&scene->r);
- int resolution_threshold = scene->r.preview_start_resolution *
- scene->r.preview_start_resolution;
-
- if (CTX_wm_window(C) == NULL)
- return;
- if (!render_view3d_flag_changed(engine, C))
- return;
-
- wm_job = WM_jobs_get(CTX_wm_manager(C), CTX_wm_window(C), CTX_wm_region(C), "Render Preview",
- WM_JOB_EXCL_RENDER, WM_JOB_TYPE_RENDER_PREVIEW);
- rp = MEM_callocN(sizeof(RenderPreview), "render preview");
- rp->job = wm_job;
-
- while (width * height > resolution_threshold) {
- width = max_ii(1, width / 2);
- height = max_ii(1, height / 2);
- divider *= 2;
- }
-
- /* customdata for preview thread */
- rp->scene = scene;
- rp->engine = engine;
- rp->sa = CTX_wm_area(C);
- rp->ar = CTX_wm_region(C);
- rp->v3d = rp->sa->spacedata.first;
- rp->rv3d = CTX_wm_region_view3d(C);
- rp->bmain = CTX_data_main(C);
- rp->resolution_divider = divider;
- rp->start_resolution_divider = divider;
- rp->has_freestyle = (scene->r.mode & R_EDGE_FRS) != 0;
- copy_m4_m4(rp->viewmat, rp->rv3d->viewmat);
-
- /* clear info text */
- engine->text[0] = '\0';
-
- /* setup job */
- WM_jobs_customdata_set(wm_job, rp, render_view3d_free);
- WM_jobs_timer(wm_job, 0.1, NC_SPACE | ND_SPACE_VIEW3D, NC_SPACE | ND_SPACE_VIEW3D);
- WM_jobs_callbacks(wm_job, render_view3d_startjob, NULL, NULL, NULL);
-
- WM_jobs_start(CTX_wm_manager(C), wm_job);
-
- engine->flag &= ~RE_ENGINE_DO_UPDATE;
-}
-
-/* callback for render engine, on changes */
-void render_view3d_update(RenderEngine *engine, const bContext *C)
-{
- /* this shouldn't be needed and causes too many database rebuilds, but we
- * aren't actually tracking updates for all relevant datablocks so this is
- * a catch-all for updates */
- engine->update_flag |= RE_ENGINE_UPDATE_DATABASE;
-
- render_view3d_do(engine, C);
-}
-
-void render_view3d_draw(RenderEngine *engine, const bContext *C)
-{
- Render *re = engine->re;
- RenderResult rres;
- char name[32];
-
- render_view3d_do(engine, C);
-
- if (re == NULL) {
- sprintf(name, "View3dPreview %p", (void *)CTX_wm_region(C));
- re = RE_GetRender(name);
-
- if (re == NULL) return;
- }
-
- /* Viewport render preview doesn't support multiview, view hardcoded to 0 */
- RE_AcquireResultImage(re, &rres, 0);
-
- if (rres.rectf) {
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
- View3D *v3d = CTX_wm_view3d(C);
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
- bool force_fallback = false;
- bool need_fallback = true;
- float dither = scene->r.dither_intensity;
- float scale_x, scale_y;
- rcti clip_rect;
- int xof, yof;
-
- if (render_view3d_disprect(scene, ar, v3d, rv3d, &clip_rect)) {
- scale_x = (float) BLI_rcti_size_x(&clip_rect) / rres.rectx;
- scale_y = (float) BLI_rcti_size_y(&clip_rect) / rres.recty;
- xof = clip_rect.xmin;
- yof = clip_rect.ymin;
- }
- else {
- scale_x = (float) ar->winx / rres.rectx;
- scale_y = (float) ar->winy / rres.recty;
- xof = rres.xof;
- yof = rres.yof;
- }
-
- /* If user decided not to use GLSL, fallback to glaDrawPixelsAuto */
- force_fallback |= (U.image_draw_method != IMAGE_DRAW_METHOD_GLSL);
-
- /* Try using GLSL display transform. */
- if (force_fallback == false) {
- if (IMB_colormanagement_setup_glsl_draw(&scene->view_settings, &scene->display_settings, dither, true)) {
- glEnable(GL_BLEND);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glPixelZoom(scale_x, scale_y);
- glaDrawPixelsTex(xof, yof, rres.rectx, rres.recty,
- GL_RGBA, GL_FLOAT, GL_NEAREST, rres.rectf);
- glPixelZoom(1.0f, 1.0f);
- glDisable(GL_BLEND);
-
- IMB_colormanagement_finish_glsl_draw();
- need_fallback = false;
- }
- }
-
- /* If GLSL failed, use old-school CPU-based transform. */
- if (need_fallback) {
- unsigned char *display_buffer = MEM_mallocN(4 * rres.rectx * rres.recty * sizeof(char),
- "render_view3d_draw");
-
- IMB_colormanagement_buffer_make_display_space(rres.rectf, display_buffer, rres.rectx, rres.recty,
- 4, dither, &scene->view_settings, &scene->display_settings);
-
- glEnable(GL_BLEND);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glPixelZoom(scale_x, scale_y);
- glaDrawPixelsAuto(xof, yof, rres.rectx, rres.recty,
- GL_RGBA, GL_UNSIGNED_BYTE,
- GL_NEAREST, display_buffer);
- glPixelZoom(1.0f, 1.0f);
- glDisable(GL_BLEND);
-
- MEM_freeN(display_buffer);
- }
- }
-
- RE_ReleaseResultImage(re);
-}
-
-void ED_viewport_render_kill_jobs(wmWindowManager *wm,
- Main *bmain,
- bool free_database)
-{
- bScreen *sc;
- ScrArea *sa;
- ARegion *ar;
-
- if (!wm)
- return;
-
- /* kill all actively running jobs */
- WM_jobs_kill(wm, NULL, render_view3d_startjob);
-
- /* loop over 3D view render engines */
- for (sc = bmain->screen.first; sc; sc = sc->id.next) {
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- if (sa->spacetype != SPACE_VIEW3D)
- continue;
-
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- RegionView3D *rv3d;
-
- if (ar->regiontype != RGN_TYPE_WINDOW)
- continue;
-
- rv3d = ar->regiondata;
-
- if (rv3d->render_engine) {
- /* free render database now before we change data, because
- * RE_Database_Free will also loop over blender data */
- if (free_database) {
- char name[32];
- Render *re;
-
- sprintf(name, "View3dPreview %p", (void *)ar);
- re = RE_GetRender(name);
-
- if (re)
- RE_Database_Free(re);
-
- /* tag render engine to update entire database */
- rv3d->render_engine->update_flag |= RE_ENGINE_UPDATE_DATABASE;
- }
- else {
- /* quick shader update */
- rv3d->render_engine->update_flag |= RE_ENGINE_UPDATE_MA;
- }
- }
- }
- }
- }
-}
-
Scene *ED_render_job_get_scene(const bContext *C)
{
wmWindowManager *wm = CTX_wm_manager(C);
@@ -1672,6 +1092,7 @@ Scene *ED_render_job_get_current_scene(const bContext *C)
return NULL;
}
+
/* Motion blur curve preset */
static int render_shutter_curve_preset_exec(bContext *C, wmOperator *op)
diff --git a/source/blender/editors/render/render_opengl.c b/source/blender/editors/render/render_opengl.c
index 1133b5f79d1..bf6aa9c9675 100644
--- a/source/blender/editors/render/render_opengl.c
+++ b/source/blender/editors/render/render_opengl.c
@@ -55,6 +55,10 @@
#include "BKE_sequencer.h"
#include "BKE_writeavi.h"
+#include "DEG_depsgraph.h"
+
+#include "DRW_engine.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -70,9 +74,9 @@
#include "RNA_access.h"
#include "RNA_define.h"
-#include "GPU_glew.h"
-#include "GPU_compositing.h"
#include "GPU_framebuffer.h"
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
#include "render_intern.h"
@@ -91,6 +95,9 @@ typedef struct OGLRender {
Main *bmain;
Render *re;
Scene *scene;
+ WorkSpace *workspace;
+ ViewLayer *view_layer;
+ Depsgraph *depsgraph;
View3D *v3d;
RegionView3D *rv3d;
@@ -114,7 +121,6 @@ typedef struct OGLRender {
GPUOffScreen *ofs;
int ofs_samples;
bool ofs_full_samples;
- GPUFX *fx;
int sizex, sizey;
int write_still;
@@ -148,17 +154,6 @@ typedef struct OGLRender {
#endif
} OGLRender;
-/* added because v3d is not always valid */
-static unsigned int screen_opengl_layers(OGLRender *oglrender)
-{
- if (oglrender->v3d) {
- return oglrender->scene->lay | oglrender->v3d->lay;
- }
- else {
- return oglrender->scene->lay;
- }
-}
-
static bool screen_opengl_is_multiview(OGLRender *oglrender)
{
View3D *v3d = oglrender->v3d;
@@ -271,8 +266,9 @@ static void screen_opengl_views_setup(OGLRender *oglrender)
RE_ReleaseResult(oglrender->re);
}
-static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
+static void screen_opengl_render_doit(const bContext *C, OGLRender *oglrender, RenderResult *rr)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = oglrender->scene;
ARegion *ar = oglrender->ar;
View3D *v3d = oglrender->v3d;
@@ -281,9 +277,8 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
int sizex = oglrender->sizex;
int sizey = oglrender->sizey;
const short view_context = (v3d != NULL);
- bool draw_bgpic = true;
bool draw_sky = (scene->r.alphamode == R_ADDSKY);
- unsigned char *rect = NULL;
+ float *rectf = NULL;
const char *viewname = RE_GetActiveRenderView(oglrender->re);
ImBuf *ibuf_result = NULL;
@@ -324,13 +319,14 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
unsigned char *gp_rect;
unsigned char *render_rect = (unsigned char *)RE_RenderViewGetById(rr, oglrender->view_id)->rect32;
+ DRW_opengl_context_enable();
GPU_offscreen_bind(oglrender->ofs, true);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
wmOrtho2(0, sizex, 0, sizey);
- glTranslatef(sizex / 2, sizey / 2, 0.0f);
+ gpuTranslate2f(sizex / 2, sizey / 2);
G.f |= G_RENDER_OGL;
ED_gpencil_draw_ex(scene, gpd, sizex, sizey, scene->r.cfra, SPACE_SEQ);
@@ -343,6 +339,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
blend_color_mix_byte(&render_rect[i], &render_rect[i], &gp_rect[i]);
}
GPU_offscreen_unbind(oglrender->ofs, true);
+ DRW_opengl_context_disable();
MEM_freeN(gp_rect);
}
@@ -357,12 +354,11 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
draw_flags |= (oglrender->ofs_full_samples) ? V3D_OFSDRAW_USE_FULL_SAMPLE : 0;
if (view_context) {
- draw_flags |= (draw_bgpic) ? V3D_OFSDRAW_USE_BACKGROUND : 0;
-
ibuf_view = ED_view3d_draw_offscreen_imbuf(
- scene, v3d, ar, sizex, sizey,
- IB_rect, draw_flags, alpha_mode, oglrender->ofs_samples, viewname,
- oglrender->fx, oglrender->ofs, err_out);
+ depsgraph, scene, v3d->drawtype,
+ v3d, ar, sizex, sizey,
+ IB_rectfloat, draw_flags, alpha_mode, oglrender->ofs_samples, viewname,
+ oglrender->ofs, err_out);
/* for stamp only */
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
@@ -370,18 +366,19 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
}
}
else {
- draw_flags |= (V3D_OFSDRAW_USE_GPENCIL | V3D_OFSDRAW_USE_BACKGROUND);
+ draw_flags |= V3D_OFSDRAW_USE_GPENCIL;
ibuf_view = ED_view3d_draw_offscreen_imbuf_simple(
- scene, scene->camera, oglrender->sizex, oglrender->sizey,
- IB_rect, draw_flags, OB_SOLID,
+ depsgraph, scene, OB_SOLID,
+ scene->camera, oglrender->sizex, oglrender->sizey,
+ IB_rectfloat, draw_flags,
alpha_mode, oglrender->ofs_samples, viewname,
- oglrender->fx, oglrender->ofs, err_out);
+ oglrender->ofs, err_out);
camera = scene->camera;
}
if (ibuf_view) {
ibuf_result = ibuf_view;
- rect = (unsigned char *)ibuf_view->rect;
+ rectf = (float *)ibuf_view->rect_float;
}
else {
fprintf(stderr, "%s: failed to get buffer, %s\n", __func__, err_out);
@@ -390,7 +387,7 @@ static void screen_opengl_render_doit(OGLRender *oglrender, RenderResult *rr)
if (ibuf_result != NULL) {
if ((scene->r.stamp & R_STAMP_ALL) && (scene->r.stamp & R_STAMP_DRAW)) {
- BKE_image_stamp_buf(scene, camera, NULL, rect, NULL, rr->rectx, rr->recty, 4);
+ BKE_image_stamp_buf(scene, camera, NULL, NULL, rectf, rr->rectx, rr->recty, 4);
}
RE_render_result_rect_from_ibuf(rr, &scene->r, ibuf_result, oglrender->view_id);
IMB_freeImBuf(ibuf_result);
@@ -435,7 +432,7 @@ static void addAlphaOverFloat(float dest[4], const float source[4])
}
/* add renderlayer and renderpass for each grease pencil layer for using in composition */
-static void add_gpencil_renderpass(OGLRender *oglrender, RenderResult *rr, RenderView *rv)
+static void add_gpencil_renderpass(const bContext *C, OGLRender *oglrender, RenderResult *rr, RenderView *rv)
{
bGPdata *gpd = oglrender->scene->gpd;
Scene *scene = oglrender->scene;
@@ -479,7 +476,7 @@ static void add_gpencil_renderpass(OGLRender *oglrender, RenderResult *rr, Rende
}
/* render this gp layer */
- screen_opengl_render_doit(oglrender, rr);
+ screen_opengl_render_doit(C, oglrender, rr);
/* add RendePass composite */
RenderPass *rp = RE_create_gp_pass(rr, gpl->info, rv->name);
@@ -519,7 +516,7 @@ static void add_gpencil_renderpass(OGLRender *oglrender, RenderResult *rr, Rende
scene->r.alphamode = oldalphamode;
}
-static void screen_opengl_render_apply(OGLRender *oglrender)
+static void screen_opengl_render_apply(const bContext *C, OGLRender *oglrender)
{
RenderResult *rr;
RenderView *rv;
@@ -535,14 +532,13 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
int chanshown = sseq ? sseq->chanshown : 0;
BKE_sequencer_new_render_data(
- oglrender->bmain->eval_ctx, oglrender->bmain, scene,
- oglrender->sizex, oglrender->sizey, 100.0f,
+ oglrender->bmain, scene,
+ oglrender->sizex, oglrender->sizey, 100.0f, false,
&context);
for (view_id = 0; view_id < oglrender->views_len; view_id++) {
context.view_id = view_id;
context.gpu_offscreen = oglrender->ofs;
- context.gpu_fx = oglrender->fx;
context.gpu_full_samples = oglrender->ofs_full_samples;
oglrender->seq_data.ibufs_arr[view_id] = BKE_sequencer_give_ibuf(&context, CFRA, chanshown);
@@ -557,10 +553,10 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
/* add grease pencil passes. For sequencer, the render does not include renderpasses
* TODO: The sequencer render of grease pencil should be rethought */
if (!oglrender->is_sequencer) {
- add_gpencil_renderpass(oglrender, rr, rv);
+ add_gpencil_renderpass(C, oglrender, rr, rv);
}
/* render composite */
- screen_opengl_render_doit(oglrender, rr);
+ screen_opengl_render_doit(C, oglrender, rr);
}
RE_ReleaseResult(oglrender->re);
@@ -576,11 +572,30 @@ static void screen_opengl_render_apply(OGLRender *oglrender)
}
}
+static bool screen_opengl_fullsample_enabled(Scene *scene)
+{
+ if (scene->r.scemode & R_FULL_SAMPLE) {
+ return true;
+ }
+ else {
+ /* XXX TODO:
+ * Technically if the hardware supports MSAA we could keep using Blender 2.7x approach.
+ * However anti-aliasing without full_sample is not playing well even in 2.7x.
+ *
+ * For example, if you enable depth of field, there is aliasing, even if the viewport is fine.
+ * For 2.8x this is more complicated because so many things rely on shader.
+ * So until we fix the gpu_framebuffer anti-aliasing suupport we need to force full sample.
+ */
+ return true;
+ }
+}
+
static bool screen_opengl_render_init(bContext *C, wmOperator *op)
{
/* new render clears all callbacks */
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
+ WorkSpace *workspace = CTX_wm_workspace(C);
Scene *scene = CTX_data_scene(C);
ScrArea *prevsa = CTX_wm_area(C);
@@ -589,7 +604,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
OGLRender *oglrender;
int sizex, sizey;
const int samples = (scene->r.mode & R_OSA) ? scene->r.osa : 0;
- const bool full_samples = (samples != 0) && (scene->r.scemode & R_FULL_SAMPLE);
+ const bool full_samples = (samples != 0) && screen_opengl_fullsample_enabled(scene);
bool is_view_context = RNA_boolean_get(op->ptr, "view_context");
const bool is_animation = RNA_boolean_get(op->ptr, "animation");
const bool is_sequencer = RNA_boolean_get(op->ptr, "sequencer");
@@ -634,7 +649,9 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
sizey = (scene->r.size * scene->r.ysch) / 100;
/* corrects render size with actual size, not every card supports non-power-of-two dimensions */
- ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, err_out);
+ DRW_opengl_context_enable(); /* Offscreen creation needs to be done in DRW context. */
+ ofs = GPU_offscreen_create(sizex, sizey, full_samples ? 0 : samples, true, true, err_out);
+ DRW_opengl_context_disable();
if (!ofs) {
BKE_reportf(op->reports, RPT_ERROR, "Failed to create OpenGL off-screen buffer, %s", err_out);
@@ -652,6 +669,9 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
oglrender->sizey = sizey;
oglrender->bmain = CTX_data_main(C);
oglrender->scene = scene;
+ oglrender->workspace = workspace;
+ oglrender->view_layer = CTX_data_view_layer(C);
+ oglrender->depsgraph = CTX_data_depsgraph(C);
oglrender->cfrao = scene->r.cfra;
oglrender->write_still = is_write_still && !is_animation;
@@ -679,19 +699,6 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
/* apply immediately in case we're rendering from a script,
* running notifiers again will overwrite */
oglrender->scene->customdata_mask |= oglrender->scene->customdata_mask_modal;
-
- if (oglrender->v3d->fx_settings.fx_flag & (GPU_FX_FLAG_DOF | GPU_FX_FLAG_SSAO)) {
- oglrender->fx = GPU_fx_compositor_create();
- }
- }
- else if (is_sequencer) {
- /* NOTE: We allow animation of DoF setting for flexibility in edits, so
- * we can't check in advance whether we need FX compositor or not.
- * We just always allocated it and make sure it doesn't add extra
- * overhead rather than memory allocation here if it's not really
- * needed.
- */
- oglrender->fx = GPU_fx_compositor_create();
}
/* create render */
@@ -706,7 +713,7 @@ static bool screen_opengl_render_init(bContext *C, wmOperator *op)
oglrender->iuser.ok = 1;
/* create render result */
- RE_InitState(oglrender->re, NULL, &scene->r, NULL, sizex, sizey, NULL);
+ RE_InitState(oglrender->re, NULL, &scene->r, &scene->view_layers, NULL, sizex, sizey, NULL);
/* create render views */
screen_opengl_views_setup(oglrender);
@@ -803,8 +810,9 @@ static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
}
if (oglrender->timer) { /* exec will not have a timer */
+ Depsgraph *depsgraph = oglrender->depsgraph;
scene->r.cfra = oglrender->cfrao;
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, screen_opengl_layers(oglrender));
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
WM_event_remove_timer(oglrender->wm, oglrender->win, oglrender->timer);
}
@@ -813,10 +821,9 @@ static void screen_opengl_render_end(bContext *C, OGLRender *oglrender)
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, oglrender->scene);
- if (oglrender->fx)
- GPU_fx_compositor_destroy(oglrender->fx);
-
+ DRW_opengl_context_enable();
GPU_offscreen_free(oglrender->ofs);
+ DRW_opengl_context_disable();
if (oglrender->is_sequencer) {
MEM_freeN(oglrender->seq_data.ibufs_arr);
@@ -1004,6 +1011,7 @@ static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op)
Main *bmain = CTX_data_main(C);
OGLRender *oglrender = op->customdata;
Scene *scene = oglrender->scene;
+ Depsgraph *depsgraph = oglrender->depsgraph;
char name[FILE_MAX];
bool ok = false;
const bool view_context = (oglrender->v3d != NULL);
@@ -1014,12 +1022,7 @@ static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op)
if (CFRA < oglrender->nfra)
CFRA++;
while (CFRA < oglrender->nfra) {
- unsigned int lay = screen_opengl_layers(oglrender);
-
- if (lay & 0xFF000000)
- lay &= 0xFF000000;
-
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
CFRA++;
}
@@ -1041,11 +1044,11 @@ static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op)
WM_cursor_time(oglrender->win, scene->r.cfra);
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, screen_opengl_layers(oglrender));
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
if (view_context) {
if (oglrender->rv3d->persp == RV3D_CAMOB && oglrender->v3d->camera && oglrender->v3d->scenelock) {
- /* since BKE_scene_update_for_newframe() is used rather
+ /* since BKE_scene_graph_update_for_newframe() is used rather
* then ED_update_for_newframe() the camera needs to be set */
if (BKE_scene_camera_switch_update(scene)) {
oglrender->v3d->camera = scene->camera;
@@ -1057,7 +1060,7 @@ static bool screen_opengl_render_anim_step(bContext *C, wmOperator *op)
}
/* render into offscreen buffer */
- screen_opengl_render_apply(oglrender);
+ screen_opengl_render_apply(C, oglrender);
/* save to disk */
rr = RE_AcquireResultRead(oglrender->re);
@@ -1107,7 +1110,7 @@ static int screen_opengl_render_modal(bContext *C, wmOperator *op, const wmEvent
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, oglrender->scene);
if (anim == 0) {
- screen_opengl_render_apply(op->customdata);
+ screen_opengl_render_apply(C, op->customdata);
screen_opengl_render_end(C, op->customdata);
return OPERATOR_FINISHED;
}
@@ -1158,7 +1161,7 @@ static int screen_opengl_render_exec(bContext *C, wmOperator *op)
if (!is_animation) { /* same as invoke */
/* render image */
- screen_opengl_render_apply(op->customdata);
+ screen_opengl_render_apply(C, op->customdata);
screen_opengl_render_end(C, op->customdata);
return OPERATOR_FINISHED;
@@ -1175,7 +1178,7 @@ static int screen_opengl_render_exec(bContext *C, wmOperator *op)
}
/* no redraw needed, we leave state as we entered it */
-// ED_update_for_newframe(C, 1);
+// ED_update_for_newframe(C);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_RESULT, CTX_data_scene(C));
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/render/render_ops.c b/source/blender/editors/render/render_ops.c
index c09e8576dc2..13fe40e768a 100644
--- a/source/blender/editors/render/render_ops.c
+++ b/source/blender/editors/render/render_ops.c
@@ -56,8 +56,8 @@ void ED_operatortypes_render(void)
WM_operatortype_append(MATERIAL_OT_copy);
WM_operatortype_append(MATERIAL_OT_paste);
- WM_operatortype_append(SCENE_OT_render_layer_add);
- WM_operatortype_append(SCENE_OT_render_layer_remove);
+ WM_operatortype_append(SCENE_OT_view_layer_add);
+ WM_operatortype_append(SCENE_OT_view_layer_remove);
WM_operatortype_append(SCENE_OT_render_view_add);
WM_operatortype_append(SCENE_OT_render_view_remove);
@@ -85,9 +85,6 @@ void ED_operatortypes_render(void)
WM_operatortype_append(TEXTURE_OT_slot_copy);
WM_operatortype_append(TEXTURE_OT_slot_paste);
WM_operatortype_append(TEXTURE_OT_slot_move);
- WM_operatortype_append(TEXTURE_OT_envmap_save);
- WM_operatortype_append(TEXTURE_OT_envmap_clear);
- WM_operatortype_append(TEXTURE_OT_envmap_clear_all);
/* render_internal.c */
WM_operatortype_append(RENDER_OT_view_show);
diff --git a/source/blender/editors/render/render_preview.c b/source/blender/editors/render/render_preview.c
index e52dd7c65c8..d0390985181 100644
--- a/source/blender/editors/render/render_preview.c
+++ b/source/blender/editors/render/render_preview.c
@@ -69,6 +69,7 @@
#include "BKE_image.h"
#include "BKE_icons.h"
#include "BKE_lamp.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
#include "BKE_main.h"
@@ -78,6 +79,10 @@
#include "BKE_texture.h"
#include "BKE_world.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+#include "DEG_depsgraph_build.h"
+
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "IMB_thumbs.h"
@@ -85,6 +90,7 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_shader.h"
#include "RE_pipeline.h"
#include "RE_engine.h"
@@ -94,6 +100,7 @@
#include "ED_datafiles.h"
#include "ED_render.h"
+#include "ED_screen.h"
#ifndef NDEBUG
/* Used for database init assert(). */
@@ -149,6 +156,7 @@ typedef struct ShaderPreview {
short *stop, *do_update;
Scene *scene;
+ Depsgraph *depsgraph;
ID *id;
ID *parent;
MTex *slot;
@@ -178,6 +186,7 @@ typedef struct IconPreviewSize {
typedef struct IconPreview {
Main *bmain;
Scene *scene;
+ Depsgraph *depsgraph;
void *owner;
ID *id;
ListBase sizes;
@@ -236,53 +245,83 @@ void ED_preview_free_dbase(void)
BKE_main_free(G_pr_main_cycles);
}
-static int preview_mat_has_sss(Material *mat, bNodeTree *ntree)
+static Scene *preview_get_scene(Main *pr_main)
+{
+ if (pr_main == NULL) return NULL;
+
+ return pr_main->scene.first;
+}
+
+static const char *preview_layer_name(const char pr_type)
{
- if (mat) {
- if (mat->sss_flag & MA_DIFF_SSS)
- return 1;
- if (mat->nodetree)
- if (preview_mat_has_sss(NULL, mat->nodetree))
- return 1;
+ switch (pr_type) {
+ case MA_FLAT:
+ return "Flat";
+ case MA_SPHERE:
+ return "Sphere";
+ case MA_CUBE:
+ return "Cube";
+ case MA_MONKEY:
+ return "Monkey";
+ case MA_SPHERE_A:
+ return "World Sphere";
+ case MA_TEXTURE:
+ return "Texture";
+ case MA_LAMP:
+ return "Lamp";
+ case MA_SKY:
+ return "Sky";
+ case MA_HAIR:
+ return "Hair";
+ case MA_ATMOS:
+ return "Atmosphere";
+ default:
+ BLI_assert(!"Unknown preview type");
+ return "";
}
- else if (ntree) {
- bNode *node;
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->type == NODE_GROUP && node->id) {
- if (preview_mat_has_sss(NULL, (bNodeTree *)node->id))
- return 1;
- }
- else if (node->id && ELEM(node->type, SH_NODE_MATERIAL, SH_NODE_MATERIAL_EXT)) {
- mat = (Material *)node->id;
- if (mat->sss_flag & MA_DIFF_SSS)
- return 1;
- }
+}
+
+static void set_preview_layer(ViewLayer *view_layer, char pr_type)
+{
+ LayerCollection *lc;
+ const char *collection_name = preview_layer_name(pr_type);
+
+ for (lc = view_layer->layer_collections.first; lc; lc = lc->next) {
+ if (STREQ(lc->scene_collection->name, collection_name)) {
+ lc->flag = COLLECTION_VIEWPORT | COLLECTION_RENDER;
+ }
+ else {
+ lc->flag = COLLECTION_DISABLED;
}
}
- return 0;
}
-static Scene *preview_get_scene(Main *pr_main)
+static World *preview_get_localized_world(ShaderPreview *sp, World *world)
{
- if (pr_main == NULL) return NULL;
-
- return pr_main->scene.first;
+ if (world == NULL) {
+ return NULL;
+ }
+ if (sp->worldcopy != NULL) {
+ return sp->worldcopy;
+ }
+ sp->worldcopy = BKE_world_localize(world);
+ BLI_addtail(&sp->pr_main->world, sp->worldcopy);
+ return sp->worldcopy;
}
-
/* call this with a pointer to initialize preview scene */
/* call this with NULL to restore assigned ID pointers in preview scene */
static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_type, ShaderPreview *sp)
{
Scene *sce;
- Base *base;
Main *pr_main = sp->pr_main;
memcpy(pr_main->name, bmain->name, sizeof(pr_main->name));
sce = preview_get_scene(pr_main);
if (sce) {
-
+ ViewLayer *view_layer = sce->view_layers.first;
+
/* this flag tells render to not execute depsgraph or ipos etc */
sce->r.scemode |= R_BUTS_PREVIEW;
/* set world always back, is used now */
@@ -320,7 +359,7 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
* seems commonly used render engines does not support
* such kind of rendering.
*/
- BLI_strncpy(sce->r.engine, RE_engine_id_BLENDER_RENDER, sizeof(sce->r.engine));
+ BLI_strncpy(sce->r.engine, RE_engine_id_BLENDER_EEVEE, sizeof(sce->r.engine));
}
else {
BLI_strncpy(sce->r.engine, scene->r.engine, sizeof(sce->r.engine));
@@ -335,77 +374,26 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
sp->matcopy = mat;
BLI_addtail(&pr_main->mat, mat);
- if (!BKE_scene_use_new_shading_nodes(scene)) {
- init_render_material(mat, 0, NULL); /* call that retrieves mode_l */
- end_render_material(mat);
-
- /* un-useful option */
- if (sp->pr_method == PR_ICON_RENDER)
- mat->shade_flag &= ~MA_OBCOLOR;
-
- /* turn on raytracing if needed */
- if (mat->mode_l & MA_RAYMIRROR)
- sce->r.mode |= R_RAYTRACE;
- if (mat->material_type == MA_TYPE_VOLUME)
- sce->r.mode |= R_RAYTRACE;
- if ((mat->mode_l & MA_RAYTRANSP) && (mat->mode_l & MA_TRANSP))
- sce->r.mode |= R_RAYTRACE;
- if (preview_mat_has_sss(mat, NULL))
- sce->r.mode |= R_SSS;
-
- /* turn off fake shadows if needed */
- /* this only works in a specific case where the preview.blend contains
- * an object starting with 'c' which has a material linked to it (not the obdata)
- * and that material has a fake shadow texture in the active texture slot */
- for (base = sce->base.first; base; base = base->next) {
- if (base->object->id.name[2] == 'c') {
- Material *shadmat = give_current_material(base->object, base->object->actcol);
- if (shadmat) {
- if (mat->mode2 & MA_CASTSHADOW) shadmat->septex = 0;
- else shadmat->septex |= 1;
- }
- }
- }
-
- /* turn off bounce lights for volume,
- * doesn't make much visual difference and slows it down too */
- for (base = sce->base.first; base; base = base->next) {
- if (base->object->type == OB_LAMP) {
- /* if doesn't match 'Lamp.002' --> main key light */
- if (!STREQ(base->object->id.name + 2, "Lamp.002")) {
- if (mat->material_type == MA_TYPE_VOLUME)
- base->object->restrictflag |= OB_RESTRICT_RENDER;
- else
- base->object->restrictflag &= ~OB_RESTRICT_RENDER;
- }
- }
- }
+ /* use current scene world to light sphere */
+ if (mat->pr_type == MA_SPHERE_A && sp->pr_method == PR_BUTS_RENDER) {
+ /* Use current scene world to light sphere. */
+ sce->world = preview_get_localized_world(sp, scene->world);
}
- else {
- if (mat->pr_type == MA_SPHERE_A && sp->pr_method == PR_BUTS_RENDER) {
- /* Use current scene world to light sphere. */
- sce->world = scene->world;
- }
- else if (sce->world) {
- /* Use a default world color. Using the current
- * scene world can be slow if it has big textures. */
- sce->world->use_nodes = false;
- sce->world->horr = 0.5f;
- sce->world->horg = 0.5f;
- sce->world->horb = 0.5f;
- }
+ else if (sce->world) {
+ /* Use a default world color. Using the current
+ * scene world can be slow if it has big textures. */
+ sce->world->use_nodes = false;
+ sce->world->horr = 0.5f;
+ sce->world->horg = 0.5f;
+ sce->world->horb = 0.5f;
}
if (sp->pr_method == PR_ICON_RENDER) {
- if (mat->material_type == MA_TYPE_HALO) {
- sce->lay = 1 << MA_FLAT;
- }
- else {
- sce->lay = 1 << MA_SPHERE_A;
- }
+ set_preview_layer(view_layer, MA_SPHERE_A);
}
else {
- sce->lay = 1 << mat->pr_type;
+ set_preview_layer(view_layer, mat->pr_type);
+
if (mat->nodetree && sp->pr_method == PR_NODE_RENDER) {
/* two previews, they get copied by wmJob */
BKE_node_preview_init_tree(mat->nodetree, sp->sizex, sp->sizey, true);
@@ -414,11 +402,11 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
}
}
else {
- sce->r.mode &= ~(R_OSA | R_RAYTRACE | R_SSS);
+ sce->r.mode &= ~(R_OSA);
}
- for (base = sce->base.first; base; base = base->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
if (base->object->id.name[2] == 'p') {
/* copy over object color, in case material uses it */
copy_v4_v4(base->object->col, sp->col);
@@ -432,7 +420,7 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
(*matar)[actcol] = mat;
}
else if (base->object->type == OB_LAMP) {
- base->object->restrictflag &= ~OB_RESTRICT_RENDER;
+ base->flag |= BASE_VISIBLED;
}
}
}
@@ -445,31 +433,8 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
sp->texcopy = tex;
BLI_addtail(&pr_main->tex, tex);
}
- sce->lay = 1 << MA_TEXTURE;
+ set_preview_layer(view_layer, MA_TEXTURE);
- for (base = sce->base.first; base; base = base->next) {
- if (base->object->id.name[2] == 't') {
- Material *mat = give_current_material(base->object, base->object->actcol);
- if (mat && mat->mtex[0]) {
- mat->mtex[0]->tex = tex;
-
- if (tex && sp->slot)
- mat->mtex[0]->which_output = sp->slot->which_output;
-
- mat->mtex[0]->mapto &= ~MAP_ALPHA;
- mat->alpha = 1.0f;
-
- /* show alpha in this case */
- if (tex == NULL || (tex->flag & TEX_PRV_ALPHA)) {
- if (!(tex && tex->type == TEX_IMAGE && (tex->imaflag & (TEX_USEALPHA | TEX_CALCALPHA)) == 0)) {
- mat->mtex[0]->mapto |= MAP_ALPHA;
- mat->alpha = 0.0f;
- }
- }
- }
- }
- }
-
if (tex && tex->nodetree && sp->pr_method == PR_NODE_RENDER) {
/* two previews, they get copied by wmJob */
BKE_node_preview_init_tree(origtex->nodetree, sp->sizex, sp->sizey, true);
@@ -486,30 +451,17 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
BLI_addtail(&pr_main->lamp, la);
}
- sce->lay = 1 << MA_LAMP;
+ set_preview_layer(view_layer, MA_LAMP);
- if (!BKE_scene_use_new_shading_nodes(scene)) {
- if (la && la->type == LA_SUN && (la->sun_effect_type & LA_SUN_EFFECT_SKY)) {
- sce->lay = 1 << MA_ATMOS;
- sce->world = scene->world;
- sce->camera = (Object *)BLI_findstring(&pr_main->object, "CameraAtmo", offsetof(ID, name) + 2);
- }
- else {
- sce->world = NULL;
- sce->camera = (Object *)BLI_findstring(&pr_main->object, "Camera", offsetof(ID, name) + 2);
- }
- }
- else {
- if (sce->world) {
- /* Only use lighting from the lamp. */
- sce->world->use_nodes = false;
- sce->world->horr = 0.0f;
- sce->world->horg = 0.0f;
- sce->world->horb = 0.0f;
- }
+ if (sce->world) {
+ /* Only use lighting from the lamp. */
+ sce->world->use_nodes = false;
+ sce->world->horr = 0.0f;
+ sce->world->horg = 0.0f;
+ sce->world->horb = 0.0f;
}
- for (base = sce->base.first; base; base = base->next) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
if (base->object->id.name[2] == 'p') {
if (base->object->type == OB_LAMP)
base->object->data = la;
@@ -531,7 +483,7 @@ static Scene *preview_prepare_scene(Main *bmain, Scene *scene, ID *id, int id_ty
BLI_addtail(&pr_main->world, wrld);
}
- sce->lay = 1 << MA_SKY;
+ set_preview_layer(view_layer, MA_SKY);
sce->world = wrld;
if (wrld && wrld->nodetree && sp->pr_method == PR_NODE_RENDER) {
@@ -607,7 +559,9 @@ static bool ed_preview_draw_rect(ScrArea *sa, int split, int first, rcti *rect,
if (re)
RE_AcquiredResultGet32(re, &rres, (unsigned int *)rect_byte, 0);
- glaDrawPixelsSafe(fx, fy, rres.rectx, rres.recty, rres.rectx, GL_RGBA, GL_UNSIGNED_BYTE, rect_byte);
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex(&state, fx, fy, rres.rectx, rres.recty, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, rect_byte,
+ 1.0f, 1.0f, NULL);
MEM_freeN(rect_byte);
@@ -728,6 +682,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
char name[32];
int sizex;
Main *pr_main = sp->pr_main;
+ ID *id_eval = DEG_get_evaluated_id(sp->depsgraph, id);
/* in case of split preview, use border render */
if (split) {
@@ -747,7 +702,7 @@ static void shader_preview_render(ShaderPreview *sp, ID *id, int split, int firs
}
/* get the stuff from the builtin preview dbase */
- sce = preview_prepare_scene(sp->bmain, sp->scene, id, idtype, sp);
+ sce = preview_prepare_scene(sp->bmain, sp->scene, id_eval, idtype, sp);
if (sce == NULL) return;
if (!split || first) sprintf(name, "Preview %p", sp->owner);
@@ -1036,6 +991,12 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat
*do_update = true;
}
+ else if (idtype == ID_SCR) {
+ bScreen *screen = (bScreen *)id;
+
+ ED_screen_preview_render(screen, sp->sizex, sp->sizey, sp->pr_rect);
+ *do_update = true;
+ }
else {
/* re-use shader job */
shader_preview_startjob(customdata, stop, do_update);
@@ -1045,12 +1006,6 @@ static void icon_preview_startjob(void *customdata, short *stop, short *do_updat
if (idtype == ID_WO) {
set_alpha((char *)sp->pr_rect, sp->sizex, sp->sizey, 255);
}
- else if (idtype == ID_MA) {
- Material *ma = (Material *)id;
-
- if (ma->material_type == MA_TYPE_HALO)
- set_alpha((char *)sp->pr_rect, sp->sizex, sp->sizey, 255);
- }
}
}
}
@@ -1095,7 +1050,6 @@ static void icon_preview_startjob_all_sizes(void *customdata, short *stop, short
{
IconPreview *ip = (IconPreview *)customdata;
IconPreviewSize *cur_size;
- const bool use_new_shading = BKE_scene_use_new_shading_nodes(ip->scene);
for (cur_size = ip->sizes.first; cur_size; cur_size = cur_size->next) {
PreviewImage *prv = ip->owner;
@@ -1110,6 +1064,7 @@ static void icon_preview_startjob_all_sizes(void *customdata, short *stop, short
/* construct shader preview from image size and previewcustomdata */
sp->scene = ip->scene;
+ sp->depsgraph = ip->depsgraph;
sp->owner = ip->owner;
sp->sizex = cur_size->sizex;
sp->sizey = cur_size->sizey;
@@ -1120,19 +1075,14 @@ static void icon_preview_startjob_all_sizes(void *customdata, short *stop, short
if (is_render) {
BLI_assert(ip->id);
- if (use_new_shading) {
- /* texture icon rendering is hardcoded to use BI,
- * so don't even think of using cycle's bmain for
- * texture icons
- */
- if (GS(ip->id->name) != ID_TE)
- sp->pr_main = G_pr_main_cycles;
- else
- sp->pr_main = G_pr_main;
- }
- else {
+ /* texture icon rendering is hardcoded to use the BI scene,
+ * so don't even think of using cycle's bmain for
+ * texture icons
+ */
+ if (GS(ip->id->name) != ID_TE)
+ sp->pr_main = G_pr_main_cycles;
+ else
sp->pr_main = G_pr_main;
- }
}
common_preview_startjob(sp, stop, do_update, progress);
@@ -1227,6 +1177,7 @@ void ED_preview_icon_job(const bContext *C, void *owner, ID *id, unsigned int *r
/* customdata for preview thread */
ip->bmain = CTX_data_main(C);
ip->scene = CTX_data_scene(C);
+ ip->depsgraph = CTX_data_depsgraph(C);
ip->owner = owner;
ip->id = id;
@@ -1255,10 +1206,11 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
ShaderPreview *sp;
Scene *scene = CTX_data_scene(C);
short id_type = GS(id->name);
- bool use_new_shading = BKE_scene_use_new_shading_nodes(scene);
+
+ /* Use workspace render only for buttons Window, since the other previews are related to the datablock. */
/* Only texture node preview is supported with Cycles. */
- if (use_new_shading && method == PR_NODE_RENDER && id_type != ID_TE) {
+ if (method == PR_NODE_RENDER && id_type != ID_TE) {
return;
}
@@ -1270,6 +1222,7 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
/* customdata for preview thread */
sp->scene = scene;
+ sp->depsgraph = CTX_data_depsgraph(C);
sp->owner = owner;
sp->sizex = sizex;
sp->sizey = sizey;
@@ -1279,9 +1232,9 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
sp->slot = slot;
sp->bmain = CTX_data_main(C);
- /* hardcoded preview .blend for cycles/internal, this should be solved
+ /* hardcoded preview .blend for Eevee + Cycles, this should be solved
* once with custom preview .blend path for external engines */
- if ((method != PR_NODE_RENDER) && id_type != ID_TE && use_new_shading) {
+ if ((method != PR_NODE_RENDER) && id_type != ID_TE) {
sp->pr_main = G_pr_main_cycles;
}
else {
@@ -1299,11 +1252,9 @@ void ED_preview_shader_job(const bContext *C, void *owner, ID *id, ID *parent, M
WM_jobs_start(CTX_wm_manager(C), wm_job);
}
-void ED_preview_kill_jobs(wmWindowManager *wm, Main *bmain)
+void ED_preview_kill_jobs(wmWindowManager *wm, Main *UNUSED(bmain))
{
if (wm)
WM_jobs_kill(wm, NULL, common_preview_startjob);
-
- ED_viewport_render_kill_jobs(wm, bmain, false);
}
diff --git a/source/blender/editors/render/render_shading.c b/source/blender/editors/render/render_shading.c
index 49d74c25633..e792de01e2c 100644
--- a/source/blender/editors/render/render_shading.c
+++ b/source/blender/editors/render/render_shading.c
@@ -50,10 +50,10 @@
#include "BKE_animsys.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_font.h"
#include "BKE_global.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_linestyle.h"
#include "BKE_main.h"
@@ -62,10 +62,12 @@
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_texture.h"
+#include "BKE_workspace.h"
#include "BKE_world.h"
#include "BKE_editmesh.h"
-
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#ifdef WITH_FREESTYLE
# include "BKE_freestyle.h"
@@ -83,6 +85,7 @@
#include "ED_mesh.h"
#include "ED_node.h"
#include "ED_render.h"
+#include "ED_scene.h"
#include "ED_screen.h"
#include "RNA_define.h"
@@ -153,7 +156,7 @@ static int material_slot_remove_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_OB_SHADING, ob);
WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_PREVIEW, ob);
@@ -219,7 +222,7 @@ static int material_slot_assign_exec(bContext *C, wmOperator *UNUSED(op))
}
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
return OPERATOR_FINISHED;
@@ -359,7 +362,7 @@ static int material_slot_copy_exec(bContext *C, wmOperator *UNUSED(op))
if (ob_iter->totcol == ob->totcol) {
ob_iter->actcol = ob->actcol;
- DAG_id_tag_update(&ob_iter->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob_iter->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob_iter);
}
}
@@ -424,7 +427,7 @@ static int material_slot_move_exec(bContext *C, wmOperator *op)
MEM_freeN(slot_remap);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob);
@@ -458,7 +461,6 @@ void OBJECT_OT_material_slot_move(wmOperatorType *ot)
static int new_material_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
Material *ma = CTX_data_pointer_get_type(C, "material", &RNA_Material).data;
Main *bmain = CTX_data_main(C);
PointerRNA ptr, idptr;
@@ -470,11 +472,8 @@ static int new_material_exec(bContext *C, wmOperator *UNUSED(op))
}
else {
ma = BKE_material_add(bmain, DATA_("Material"));
-
- if (BKE_scene_use_new_shading_nodes(scene)) {
- ED_node_shader_default(C, &ma->id);
- ma->use_nodes = true;
- }
+ ED_node_shader_default(C, &ma->id);
+ ma->use_nodes = true;
}
/* hook into UI */
@@ -534,14 +533,6 @@ static int new_texture_exec(bContext *C, wmOperator *UNUSED(op))
* pointer use also increases user, so this compensates it */
id_us_min(&tex->id);
- if (ptr.id.data && GS(((ID *)ptr.id.data)->name) == ID_MA &&
- RNA_property_pointer_get(&ptr, prop).id.data == NULL)
- {
- /* In case we are assigning new texture to a material, and active slot was empty, reset 'use' flag. */
- Material *ma = (Material *)ptr.id.data;
- ma->septex &= ~(1 << ma->texact);
- }
-
RNA_id_pointer_create(&tex->id, &idptr);
RNA_property_pointer_set(&ptr, prop, idptr);
RNA_property_update(C, &ptr, prop);
@@ -570,7 +561,6 @@ void TEXTURE_OT_new(wmOperatorType *ot)
static int new_world_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
World *wo = CTX_data_pointer_get_type(C, "world", &RNA_World).data;
Main *bmain = CTX_data_main(C);
PointerRNA ptr, idptr;
@@ -582,11 +572,8 @@ static int new_world_exec(bContext *C, wmOperator *UNUSED(op))
}
else {
wo = BKE_world_add(bmain, DATA_("World"));
-
- if (BKE_scene_use_new_shading_nodes(scene)) {
- ED_node_shader_default(C, &wo->id);
- wo->use_nodes = true;
- }
+ ED_node_shader_default(C, &wo->id);
+ wo->use_nodes = true;
}
/* hook into UI */
@@ -623,56 +610,61 @@ void WORLD_OT_new(wmOperatorType *ot)
/********************** render layer operators *********************/
-static int render_layer_add_exec(bContext *C, wmOperator *UNUSED(op))
+static int view_layer_add_exec(bContext *C, wmOperator *UNUSED(op))
{
+ WorkSpace *workspace = CTX_wm_workspace(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = BKE_view_layer_add(scene, NULL);
- BKE_scene_add_render_layer(scene, NULL);
- scene->r.actlay = BLI_listbase_count(&scene->r.layers) - 1;
+ if (workspace) {
+ BKE_workspace_view_layer_set(workspace, view_layer, scene);
+ }
- DAG_id_tag_update(&scene->id, 0);
- WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
+ DEG_id_tag_update(&scene->id, 0);
+ DEG_relations_tag_update(CTX_data_main(C));
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
return OPERATOR_FINISHED;
}
-void SCENE_OT_render_layer_add(wmOperatorType *ot)
+void SCENE_OT_view_layer_add(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "Add Render Layer";
- ot->idname = "SCENE_OT_render_layer_add";
- ot->description = "Add a render layer";
+ ot->name = "Add View Layer";
+ ot->idname = "SCENE_OT_view_layer_add";
+ ot->description = "Add a view layer";
/* api callbacks */
- ot->exec = render_layer_add_exec;
+ ot->exec = view_layer_add_exec;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
}
-static int render_layer_remove_exec(bContext *C, wmOperator *UNUSED(op))
+static int view_layer_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
+ Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *rl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- if (!BKE_scene_remove_render_layer(CTX_data_main(C), scene, rl))
+ if (!ED_scene_view_layer_delete(bmain, scene, view_layer, NULL)) {
return OPERATOR_CANCELLED;
+ }
- DAG_id_tag_update(&scene->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
-
+
return OPERATOR_FINISHED;
}
-void SCENE_OT_render_layer_remove(wmOperatorType *ot)
+void SCENE_OT_view_layer_remove(wmOperatorType *ot)
{
/* identifiers */
- ot->name = "Remove Render Layer";
- ot->idname = "SCENE_OT_render_layer_remove";
- ot->description = "Remove the selected render layer";
+ ot->name = "Remove View Layer";
+ ot->idname = "SCENE_OT_view_layer_remove";
+ ot->description = "Remove the selected view layer";
/* api callbacks */
- ot->exec = render_layer_remove_exec;
+ ot->exec = view_layer_remove_exec;
/* flags */
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
@@ -769,9 +761,9 @@ static int freestyle_active_module_poll(bContext *C)
static int freestyle_module_add_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- BKE_freestyle_module_add(&srl->freestyleConfig);
+ BKE_freestyle_module_add(&view_layer->freestyle_config);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
@@ -795,13 +787,13 @@ void SCENE_OT_freestyle_module_add(wmOperatorType *ot)
static int freestyle_module_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
FreestyleModuleConfig *module = ptr.data;
- BKE_freestyle_module_delete(&srl->freestyleConfig, module);
+ BKE_freestyle_module_delete(&view_layer->freestyle_config, module);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
return OPERATOR_FINISHED;
@@ -825,13 +817,13 @@ void SCENE_OT_freestyle_module_remove(wmOperatorType *ot)
static int freestyle_module_move_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
PointerRNA ptr = CTX_data_pointer_get_type(C, "freestyle_module", &RNA_FreestyleModuleSettings);
FreestyleModuleConfig *module = ptr.data;
int dir = RNA_enum_get(op->ptr, "direction");
- if (BKE_freestyle_module_move(&srl->freestyleConfig, module, dir)) {
- DAG_id_tag_update(&scene->id, 0);
+ if (BKE_freestyle_module_move(&view_layer->freestyle_config, module, dir)) {
+ DEG_id_tag_update(&scene->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
}
@@ -867,11 +859,11 @@ static int freestyle_lineset_add_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- BKE_freestyle_lineset_add(bmain, &srl->freestyleConfig, NULL);
+ BKE_freestyle_lineset_add(bmain, &view_layer->freestyle_config, NULL);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
return OPERATOR_FINISHED;
@@ -893,22 +885,20 @@ void SCENE_OT_freestyle_lineset_add(wmOperatorType *ot)
static int freestyle_active_lineset_poll(bContext *C)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- if (!srl) {
+ if (!view_layer) {
return false;
}
- return BKE_freestyle_lineset_get_active(&srl->freestyleConfig) != NULL;
+ return BKE_freestyle_lineset_get_active(&view_layer->freestyle_config) != NULL;
}
static int freestyle_lineset_copy_exec(bContext *C, wmOperator *UNUSED(op))
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- FRS_copy_active_lineset(&srl->freestyleConfig);
+ FRS_copy_active_lineset(&view_layer->freestyle_config);
return OPERATOR_FINISHED;
}
@@ -931,11 +921,11 @@ void SCENE_OT_freestyle_lineset_copy(wmOperatorType *ot)
static int freestyle_lineset_paste_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- FRS_paste_active_lineset(&srl->freestyleConfig);
+ FRS_paste_active_lineset(&view_layer->freestyle_config);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
return OPERATOR_FINISHED;
@@ -959,11 +949,11 @@ void SCENE_OT_freestyle_lineset_paste(wmOperatorType *ot)
static int freestyle_lineset_remove_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
- FRS_delete_active_lineset(&srl->freestyleConfig);
+ FRS_delete_active_lineset(&view_layer->freestyle_config);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
return OPERATOR_FINISHED;
@@ -987,11 +977,11 @@ void SCENE_OT_freestyle_lineset_remove(wmOperatorType *ot)
static int freestyle_lineset_move_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
int dir = RNA_enum_get(op->ptr, "direction");
- if (FRS_move_active_lineset(&srl->freestyleConfig, dir)) {
- DAG_id_tag_update(&scene->id, 0);
+ if (FRS_move_active_lineset(&view_layer->freestyle_config, dir)) {
+ DEG_id_tag_update(&scene->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, scene);
}
@@ -1026,9 +1016,8 @@ void SCENE_OT_freestyle_lineset_move(wmOperatorType *ot)
static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
if (!lineset) {
BKE_report(op->reports, RPT_ERROR, "No active lineset to add a new line style to");
@@ -1041,7 +1030,7 @@ static int freestyle_linestyle_new_exec(bContext *C, wmOperator *op)
else {
lineset->linestyle = BKE_linestyle_new(bmain, "LineStyle");
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
return OPERATOR_FINISHED;
@@ -1064,9 +1053,8 @@ void SCENE_OT_freestyle_linestyle_new(wmOperatorType *ot)
static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
int type = RNA_enum_get(op->ptr, "type");
if (!freestyle_linestyle_check_report(lineset, op->reports)) {
@@ -1077,7 +1065,7 @@ static int freestyle_color_modifier_add_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "Unknown line color modifier type");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
return OPERATOR_FINISHED;
@@ -1104,9 +1092,8 @@ void SCENE_OT_freestyle_color_modifier_add(wmOperatorType *ot)
static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
int type = RNA_enum_get(op->ptr, "type");
if (!freestyle_linestyle_check_report(lineset, op->reports)) {
@@ -1117,7 +1104,7 @@ static int freestyle_alpha_modifier_add_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "Unknown alpha transparency modifier type");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
return OPERATOR_FINISHED;
@@ -1144,9 +1131,8 @@ void SCENE_OT_freestyle_alpha_modifier_add(wmOperatorType *ot)
static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
int type = RNA_enum_get(op->ptr, "type");
if (!freestyle_linestyle_check_report(lineset, op->reports)) {
@@ -1157,7 +1143,7 @@ static int freestyle_thickness_modifier_add_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "Unknown line thickness modifier type");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
return OPERATOR_FINISHED;
@@ -1184,9 +1170,8 @@ void SCENE_OT_freestyle_thickness_modifier_add(wmOperatorType *ot)
static int freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
int type = RNA_enum_get(op->ptr, "type");
if (!freestyle_linestyle_check_report(lineset, op->reports)) {
@@ -1197,7 +1182,7 @@ static int freestyle_geometry_modifier_add_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "Unknown stroke geometry modifier type");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
return OPERATOR_FINISHED;
@@ -1237,9 +1222,8 @@ static int freestyle_get_modifier_type(PointerRNA *ptr)
static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
LineStyleModifier *modifier = ptr.data;
@@ -1264,7 +1248,7 @@ static int freestyle_modifier_remove_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
return OPERATOR_FINISHED;
@@ -1287,9 +1271,8 @@ void SCENE_OT_freestyle_modifier_remove(wmOperatorType *ot)
static int freestyle_modifier_copy_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
LineStyleModifier *modifier = ptr.data;
@@ -1314,7 +1297,7 @@ static int freestyle_modifier_copy_exec(bContext *C, wmOperator *op)
BKE_report(op->reports, RPT_ERROR, "The object the data pointer refers to is not a valid modifier");
return OPERATOR_CANCELLED;
}
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
return OPERATOR_FINISHED;
@@ -1337,9 +1320,8 @@ void SCENE_OT_freestyle_modifier_copy(wmOperatorType *ot)
static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&srl->freestyleConfig);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(&view_layer->freestyle_config);
PointerRNA ptr = CTX_data_pointer_get_type(C, "modifier", &RNA_LineStyleModifier);
LineStyleModifier *modifier = ptr.data;
int dir = RNA_enum_get(op->ptr, "direction");
@@ -1368,7 +1350,7 @@ static int freestyle_modifier_move_exec(bContext *C, wmOperator *op)
}
if (changed) {
- DAG_id_tag_update(&lineset->linestyle->id, 0);
+ DEG_id_tag_update(&lineset->linestyle->id, 0);
WM_event_add_notifier(C, NC_LINESTYLE, lineset->linestyle);
}
@@ -1403,8 +1385,8 @@ void SCENE_OT_freestyle_modifier_move(wmOperatorType *ot)
static int freestyle_stroke_material_create_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer);
if (!linestyle) {
BKE_report(op->reports, RPT_ERROR, "No active line style in the current scene");
@@ -1453,15 +1435,6 @@ static int texture_slot_move_exec(bContext *C, wmOperator *op)
BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act - 1, -1, 0);
BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act, act - 1, 0);
BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, -1, act, 0);
-
- if (GS(id->name) == ID_MA) {
- Material *ma = (Material *)id;
- int mtexuse = ma->septex & (1 << act);
- ma->septex &= ~(1 << act);
- ma->septex |= (ma->septex & (1 << (act - 1))) << 1;
- ma->septex &= ~(1 << (act - 1));
- ma->septex |= mtexuse >> 1;
- }
set_active_mtex(id, act - 1);
}
@@ -1475,21 +1448,12 @@ static int texture_slot_move_exec(bContext *C, wmOperator *op)
BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act + 1, -1, 0);
BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, act, act + 1, 0);
BKE_animdata_fix_paths_rename(id, adt, NULL, "texture_slots", NULL, NULL, -1, act, 0);
-
- if (GS(id->name) == ID_MA) {
- Material *ma = (Material *)id;
- int mtexuse = ma->septex & (1 << act);
- ma->septex &= ~(1 << act);
- ma->septex |= (ma->septex & (1 << (act + 1))) >> 1;
- ma->septex &= ~(1 << (act + 1));
- ma->septex |= mtexuse << 1;
- }
set_active_mtex(id, act + 1);
}
}
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_event_add_notifier(C, NC_TEXTURE, CTX_data_scene(C));
}
@@ -1520,180 +1484,6 @@ void TEXTURE_OT_slot_move(wmOperatorType *ot)
-/********************** environment map operators *********************/
-
-static int save_envmap(wmOperator *op, Scene *scene, EnvMap *env, char *path, const char imtype)
-{
- PropertyRNA *prop;
- float layout[12];
-
- if ((prop = RNA_struct_find_property(op->ptr, "layout"))) {
- RNA_property_float_get_array(op->ptr, prop, layout);
- }
- else {
- memcpy(layout, default_envmap_layout, sizeof(layout));
- }
-
- if (RE_WriteEnvmapResult(op->reports, scene, env, path, imtype, layout)) {
- return OPERATOR_FINISHED;
- }
- else {
- return OPERATOR_CANCELLED;
- }
-
-}
-
-static int envmap_save_exec(bContext *C, wmOperator *op)
-{
- Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
- Scene *scene = CTX_data_scene(C);
- //int imtype = RNA_enum_get(op->ptr, "file_type");
- char imtype = scene->r.im_format.imtype;
- char path[FILE_MAX];
-
- RNA_string_get(op->ptr, "filepath", path);
-
- if (scene->r.scemode & R_EXTENSION) {
- BKE_image_path_ensure_ext_from_imformat(path, &scene->r.im_format);
- }
-
- WM_cursor_wait(1);
-
- save_envmap(op, scene, tex->env, path, imtype);
-
- WM_cursor_wait(0);
-
- WM_event_add_notifier(C, NC_TEXTURE, tex);
-
- return OPERATOR_FINISHED;
-}
-
-static int envmap_save_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- //Scene *scene= CTX_data_scene(C);
-
- if (RNA_struct_property_is_set(op->ptr, "filepath"))
- return envmap_save_exec(C, op);
-
- //RNA_enum_set(op->ptr, "file_type", scene->r.im_format.imtype);
- RNA_string_set(op->ptr, "filepath", G.main->name);
- WM_event_add_fileselect(C, op);
-
- return OPERATOR_RUNNING_MODAL;
-}
-
-static int envmap_save_poll(bContext *C)
-{
- Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
-
- if (!tex)
- return 0;
- if (!tex->env || !tex->env->ok)
- return 0;
- if (tex->env->cube[1] == NULL)
- return 0;
-
- return 1;
-}
-
-void TEXTURE_OT_envmap_save(wmOperatorType *ot)
-{
- PropertyRNA *prop;
- /* identifiers */
- ot->name = "Save Environment Map";
- ot->idname = "TEXTURE_OT_envmap_save";
- ot->description = "Save the current generated Environment map to an image file";
-
- /* api callbacks */
- ot->exec = envmap_save_exec;
- ot->invoke = envmap_save_invoke;
- ot->poll = envmap_save_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_INTERNAL; /* no undo since this doesnt modify the env-map */
-
- /* properties */
- prop = RNA_def_float_array(ot->srna, "layout", 12, default_envmap_layout, 0.0f, 0.0f,
- "File layout",
- "Flat array describing the X,Y position of each cube face in the output image, "
- "where 1 is the size of a face - order is [+Z -Z +Y -X -Y +X] "
- "(use -1 to skip a face)", 0.0f, 0.0f);
- RNA_def_property_flag(prop, PROP_HIDDEN);
-
- WM_operator_properties_filesel(
- ot, FILE_TYPE_FOLDER | FILE_TYPE_IMAGE | FILE_TYPE_MOVIE, FILE_SPECIAL, FILE_SAVE,
- WM_FILESEL_FILEPATH, FILE_DEFAULTDISPLAY, FILE_SORT_ALPHA);
-}
-
-static int envmap_clear_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
-
- BKE_texture_envmap_free_data(tex->env);
-
- WM_event_add_notifier(C, NC_TEXTURE | NA_EDITED, tex);
-
- return OPERATOR_FINISHED;
-}
-
-static int envmap_clear_poll(bContext *C)
-{
- Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
-
- if (!tex)
- return 0;
- if (!tex->env || !tex->env->ok)
- return 0;
- if (tex->env->cube[1] == NULL)
- return 0;
-
- return 1;
-}
-
-void TEXTURE_OT_envmap_clear(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Clear Environment Map";
- ot->idname = "TEXTURE_OT_envmap_clear";
- ot->description = "Discard the environment map and free it from memory";
-
- /* api callbacks */
- ot->exec = envmap_clear_exec;
- ot->poll = envmap_clear_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
-}
-
-static int envmap_clear_all_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Main *bmain = CTX_data_main(C);
- Tex *tex;
-
- for (tex = bmain->tex.first; tex; tex = tex->id.next)
- if (tex->env)
- BKE_texture_envmap_free_data(tex->env);
-
- WM_event_add_notifier(C, NC_TEXTURE | NA_EDITED, tex);
-
- return OPERATOR_FINISHED;
-}
-
-void TEXTURE_OT_envmap_clear_all(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Clear All Environment Maps";
- ot->idname = "TEXTURE_OT_envmap_clear_all";
- ot->description = "Discard all environment maps in the .blend file and free them from memory";
-
- /* api callbacks */
- ot->exec = envmap_clear_all_exec;
- ot->poll = envmap_clear_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
/********************** material operators *********************/
/* material copy/paste */
@@ -1765,17 +1555,6 @@ static void copy_mtex_copybuf(ID *id)
MTex **mtex = NULL;
switch (GS(id->name)) {
- case ID_MA:
- mtex = &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
- break;
- case ID_LA:
- mtex = &(((Lamp *)id)->mtex[(int)((Lamp *)id)->texact]);
- // la->mtex[(int)la->texact] // TODO
- break;
- case ID_WO:
- mtex = &(((World *)id)->mtex[(int)((World *)id)->texact]);
- // mtex= wrld->mtex[(int)wrld->texact]; // TODO
- break;
case ID_PA:
mtex = &(((ParticleSettings *)id)->mtex[(int)((ParticleSettings *)id)->texact]);
break;
@@ -1803,17 +1582,6 @@ static void paste_mtex_copybuf(ID *id)
return;
switch (GS(id->name)) {
- case ID_MA:
- mtex = &(((Material *)id)->mtex[(int)((Material *)id)->texact]);
- break;
- case ID_LA:
- mtex = &(((Lamp *)id)->mtex[(int)((Lamp *)id)->texact]);
- // la->mtex[(int)la->texact] // TODO
- break;
- case ID_WO:
- mtex = &(((World *)id)->mtex[(int)((World *)id)->texact]);
- // mtex= wrld->mtex[(int)wrld->texact]; // TODO
- break;
case ID_PA:
mtex = &(((ParticleSettings *)id)->mtex[(int)((ParticleSettings *)id)->texact]);
break;
diff --git a/source/blender/editors/render/render_update.c b/source/blender/editors/render/render_update.c
index 4e02ff77a31..7da571f1941 100644
--- a/source/blender/editors/render/render_update.c
+++ b/source/blender/editors/render/render_update.c
@@ -38,9 +38,12 @@
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_world_types.h"
#include "DNA_windowmanager_types.h"
+#include "DRW_engine.h"
+
#include "BLI_listbase.h"
#include "BLI_threads.h"
#include "BLI_utildefines.h"
@@ -48,14 +51,15 @@
#include "BKE_context.h"
#include "BKE_DerivedMesh.h"
#include "BKE_icons.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_node.h"
#include "BKE_paint.h"
#include "BKE_scene.h"
+#include "BKE_workspace.h"
#include "GPU_material.h"
-#include "GPU_buffers.h"
#include "RE_engine.h"
#include "RE_pipeline.h"
@@ -64,16 +68,23 @@
#include "ED_render.h"
#include "ED_view3d.h"
+#include "DEG_depsgraph.h"
+
+#include "WM_api.h"
+
#include "render_intern.h" // own include
extern Material defmaterial;
/***************************** Render Engines ********************************/
-void ED_render_scene_update(Main *bmain, Scene *scene, int updated)
+void ED_render_scene_update(const DEGEditorUpdateContext *update_ctx, int updated)
{
/* viewport rendering update on data changes, happens after depsgraph
* updates if there was any change. context is set to the 3d view */
+ Main *bmain = update_ctx->bmain;
+ Scene *scene = update_ctx->scene;
+ ViewLayer *view_layer = update_ctx->view_layer;
bContext *C;
wmWindowManager *wm;
wmWindow *win;
@@ -102,26 +113,23 @@ void ED_render_scene_update(Main *bmain, Scene *scene, int updated)
wm = bmain->wm.first;
for (win = wm->windows.first; win; win = win->next) {
- bScreen *sc = win->screen;
+ bScreen *sc = WM_window_get_active_screen(win);
ScrArea *sa;
ARegion *ar;
CTX_wm_window_set(C, win);
-
+
for (sa = sc->areabase.first; sa; sa = sa->next) {
- if (sa->spacetype != SPACE_VIEW3D)
+ if (sa->spacetype != SPACE_VIEW3D) {
continue;
-
+ }
+ View3D *v3d = sa->spacedata.first;
for (ar = sa->regionbase.first; ar; ar = ar->next) {
- RegionView3D *rv3d;
- RenderEngine *engine;
-
- if (ar->regiontype != RGN_TYPE_WINDOW)
+ if (ar->regiontype != RGN_TYPE_WINDOW) {
continue;
-
- rv3d = ar->regiondata;
- engine = rv3d->render_engine;
-
+ }
+ RegionView3D *rv3d = ar->regiondata;
+ RenderEngine *engine = rv3d->render_engine;
/* call update if the scene changed, or if the render engine
* tagged itself for update (e.g. because it was busy at the
* time of the last update) */
@@ -133,6 +141,23 @@ void ED_render_scene_update(Main *bmain, Scene *scene, int updated)
engine->flag &= ~RE_ENGINE_DO_UPDATE;
engine->type->view_update(engine, C);
+
+ }
+ else {
+ RenderEngineType *engine_type =
+ ED_view3d_engine_type(scene, v3d->drawtype);
+ if (updated) {
+ DRW_notify_view_update(
+ (&(DRWUpdateContext){
+ .bmain = bmain,
+ .depsgraph = update_ctx->depsgraph,
+ .scene = scene,
+ .view_layer = view_layer,
+ .ar = ar,
+ .v3d = (View3D *)sa->spacedata.first,
+ .engine_type = engine_type
+ }));
+ }
}
}
}
@@ -143,23 +168,6 @@ void ED_render_scene_update(Main *bmain, Scene *scene, int updated)
recursive_check = false;
}
-void ED_render_scene_update_pre(Main *bmain, Scene *scene, bool time)
-{
- /* Blender internal might access to the data which is gonna to be freed
- * by the scene update functions. This applies for example to simulation
- * data like smoke and fire.
- */
- if (time && !BKE_scene_use_new_shading_nodes(scene)) {
- bScreen *sc;
- ScrArea *sa;
- for (sc = bmain->screen.first; sc; sc = sc->id.next) {
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- ED_render_engine_area_exit(bmain, sa);
- }
- }
- }
-}
-
void ED_render_engine_area_exit(Main *bmain, ScrArea *sa)
{
/* clear all render engines in this area */
@@ -179,18 +187,23 @@ void ED_render_engine_area_exit(Main *bmain, ScrArea *sa)
void ED_render_engine_changed(Main *bmain)
{
/* on changing the render engine type, clear all running render engines */
- bScreen *sc;
- ScrArea *sa;
- Scene *scene;
-
- for (sc = bmain->screen.first; sc; sc = sc->id.next)
- for (sa = sc->areabase.first; sa; sa = sa->next)
+ for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
+ for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
ED_render_engine_area_exit(bmain, sa);
-
+ }
+ }
RE_FreePersistentData();
-
- for (scene = bmain->scene.first; scene; scene = scene->id.next) {
- ED_render_id_flush_update(bmain, &scene->id);
+ /* Inform all render engines and draw managers. */
+ DEGEditorUpdateContext update_ctx = {NULL};
+ update_ctx.bmain = bmain;
+ for (Scene *scene = bmain->scene.first; scene; scene = scene->id.next) {
+ update_ctx.scene = scene;
+ LISTBASE_FOREACH(ViewLayer *, view_layer, &scene->view_layers) {
+ /* TDODO(sergey): Iterate over depsgraphs instead? */
+ update_ctx.depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+ update_ctx.view_layer = view_layer;
+ ED_render_id_flush_update(&update_ctx, &scene->id);
+ }
if (scene->nodetree) {
ntreeCompositUpdateRLayers(scene->nodetree);
}
@@ -198,7 +211,7 @@ void ED_render_engine_changed(Main *bmain)
}
/***************************** Updates ***********************************
- * ED_render_id_flush_update gets called from DAG_id_tag_update, to do *
+ * ED_render_id_flush_update gets called from DEG_id_tag_update, to do *
* editor level updates when the ID changes. when these ID blocks are in *
* the dependency graph, we can get rid of the manual dependency checks */
@@ -228,207 +241,42 @@ static void render_engine_flag_changed(Main *bmain, int update_flag)
}
}
-static int mtex_use_tex(MTex **mtex, int tot, Tex *tex)
+static void material_changed(Main *UNUSED(bmain), Material *ma)
{
- int a;
-
- if (!mtex)
- return 0;
-
- for (a = 0; a < tot; a++)
- if (mtex[a] && mtex[a]->tex == tex)
- return 1;
-
- return 0;
-}
-
-static int nodes_use_tex(bNodeTree *ntree, Tex *tex)
-{
- bNode *node;
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->id) {
- if (node->id == (ID *)tex) {
- return 1;
- }
- else if (GS(node->id->name) == ID_MA) {
- if (mtex_use_tex(((Material *)node->id)->mtex, MAX_MTEX, tex))
- return 1;
- }
- else if (node->type == NODE_GROUP) {
- if (nodes_use_tex((bNodeTree *)node->id, tex))
- return 1;
- }
- }
- }
-
- return 0;
-}
-
-static int nodes_use_material(bNodeTree *ntree, Material *ma)
-{
- bNode *node;
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->id) {
- if (node->id == (ID *)ma) {
- return 1;
- }
- else if (node->type == NODE_GROUP) {
- if (nodes_use_material((bNodeTree *)node->id, ma))
- return 1;
- }
- }
- }
-
- return 0;
-}
-
-static void material_changed(Main *bmain, Material *ma)
-{
- Material *parent;
- Object *ob;
- Scene *scene;
- int texture_draw = false;
-
/* icons */
BKE_icon_changed(BKE_icon_id_ensure(&ma->id));
/* glsl */
- if (ma->gpumaterial.first)
- GPU_material_free(&ma->gpumaterial);
-
- /* find node materials using this */
- for (parent = bmain->mat.first; parent; parent = parent->id.next) {
- if (parent->use_nodes && parent->nodetree && nodes_use_material(parent->nodetree, ma)) {
- /* pass */
- }
- else {
- continue;
- }
-
- BKE_icon_changed(BKE_icon_id_ensure(&parent->id));
-
- if (parent->gpumaterial.first)
- GPU_material_free(&parent->gpumaterial);
- }
-
- /* find if we have a scene with textured display */
- for (scene = bmain->scene.first; scene; scene = scene->id.next) {
- if (scene->customdata_mask & CD_MASK_MTFACE) {
- texture_draw = true;
- break;
- }
- }
-
- /* find textured objects */
- if (texture_draw) {
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- DerivedMesh *dm = ob->derivedFinal;
- Material ***material = give_matarar(ob);
- short a, *totmaterial = give_totcolp(ob);
-
- if (dm && totmaterial && material) {
- for (a = 0; a < *totmaterial; a++) {
- if ((*material)[a] == ma) {
- GPU_drawobject_free(dm);
- break;
- }
- }
- }
+ if (ma->id.recalc & ID_RECALC) {
+ if (!BLI_listbase_is_empty(&ma->gpumaterial)) {
+ GPU_material_free(&ma->gpumaterial);
}
}
-
}
-static void lamp_changed(Main *bmain, Lamp *la)
+static void lamp_changed(Main *UNUSED(bmain), Lamp *la)
{
- Object *ob;
- Material *ma;
-
/* icons */
BKE_icon_changed(BKE_icon_id_ensure(&la->id));
- /* glsl */
- for (ob = bmain->object.first; ob; ob = ob->id.next)
- if (ob->data == la && ob->gpulamp.first)
- GPU_lamp_free(ob);
-
- for (ma = bmain->mat.first; ma; ma = ma->id.next)
- if (ma->gpumaterial.first)
- GPU_material_free(&ma->gpumaterial);
-
if (defmaterial.gpumaterial.first)
GPU_material_free(&defmaterial.gpumaterial);
}
-static int material_uses_texture(Material *ma, Tex *tex)
-{
- if (mtex_use_tex(ma->mtex, MAX_MTEX, tex))
- return true;
- else if (ma->use_nodes && ma->nodetree && nodes_use_tex(ma->nodetree, tex))
- return true;
-
- return false;
-}
-
static void texture_changed(Main *bmain, Tex *tex)
{
- Material *ma;
- Lamp *la;
- World *wo;
Scene *scene;
- Object *ob;
+ ViewLayer *view_layer;
bNode *node;
- bool texture_draw = false;
/* icons */
BKE_icon_changed(BKE_icon_id_ensure(&tex->id));
/* paint overlays */
- for (scene = bmain->scene.first; scene; scene = scene->id.next)
- BKE_paint_invalidate_overlay_tex(scene, tex);
-
- /* find materials */
- for (ma = bmain->mat.first; ma; ma = ma->id.next) {
- if (!material_uses_texture(ma, tex))
- continue;
-
- BKE_icon_changed(BKE_icon_id_ensure(&ma->id));
-
- if (ma->gpumaterial.first)
- GPU_material_free(&ma->gpumaterial);
- }
-
- /* find lamps */
- for (la = bmain->lamp.first; la; la = la->id.next) {
- if (mtex_use_tex(la->mtex, MAX_MTEX, tex)) {
- lamp_changed(bmain, la);
- }
- else if (la->nodetree && nodes_use_tex(la->nodetree, tex)) {
- lamp_changed(bmain, la);
- }
- else {
- continue;
- }
- }
-
- /* find worlds */
- for (wo = bmain->world.first; wo; wo = wo->id.next) {
- if (mtex_use_tex(wo->mtex, MAX_MTEX, tex)) {
- /* pass */
- }
- else if (wo->nodetree && nodes_use_tex(wo->nodetree, tex)) {
- /* pass */
- }
- else {
- continue;
+ for (scene = bmain->scene.first; scene; scene = scene->id.next) {
+ for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ BKE_paint_invalidate_overlay_tex(scene, view_layer, tex);
}
-
- BKE_icon_changed(BKE_icon_id_ensure(&wo->id));
-
- if (wo->gpumaterial.first)
- GPU_material_free(&wo->gpumaterial);
}
/* find compositing nodes */
@@ -439,52 +287,26 @@ static void texture_changed(Main *bmain, Tex *tex)
ED_node_tag_update_id(&scene->id);
}
}
-
- if (scene->customdata_mask & CD_MASK_MTFACE)
- texture_draw = true;
- }
-
- /* find textured objects */
- if (texture_draw) {
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- DerivedMesh *dm = ob->derivedFinal;
- Material ***material = give_matarar(ob);
- short a, *totmaterial = give_totcolp(ob);
-
- if (dm && totmaterial && material) {
- for (a = 0; a < *totmaterial; a++) {
- if (ob->matbits && ob->matbits[a])
- ma = ob->mat[a];
- else
- ma = (*material)[a];
-
- if (ma && material_uses_texture(ma, tex)) {
- GPU_drawobject_free(dm);
- break;
- }
- }
- }
- }
}
}
-static void world_changed(Main *bmain, World *wo)
+static void world_changed(Main *UNUSED(bmain), World *wo)
{
- Material *ma;
-
/* icons */
BKE_icon_changed(BKE_icon_id_ensure(&wo->id));
-
- /* glsl */
- for (ma = bmain->mat.first; ma; ma = ma->id.next)
- if (ma->gpumaterial.first)
- GPU_material_free(&ma->gpumaterial);
- if (defmaterial.gpumaterial.first)
- GPU_material_free(&defmaterial.gpumaterial);
-
- if (wo->gpumaterial.first)
- GPU_material_free(&wo->gpumaterial);
+ /* XXX temporary flag waiting for depsgraph proper tagging */
+ wo->update_flag = 1;
+
+ /* glsl */
+ if (wo->id.recalc & ID_RECALC) {
+ if (!BLI_listbase_is_empty(&defmaterial.gpumaterial)) {
+ GPU_material_free(&defmaterial.gpumaterial);
+ }
+ if (!BLI_listbase_is_empty(&wo->gpumaterial)) {
+ GPU_material_free(&wo->gpumaterial);
+ }
+ }
}
static void image_changed(Main *bmain, Image *ima)
@@ -503,41 +325,26 @@ static void image_changed(Main *bmain, Image *ima)
static void scene_changed(Main *bmain, Scene *scene)
{
Object *ob;
- Material *ma;
- World *wo;
/* glsl */
for (ob = bmain->object.first; ob; ob = ob->id.next) {
- if (ob->gpulamp.first)
- GPU_lamp_free(ob);
-
if (ob->mode & OB_MODE_TEXTURE_PAINT) {
BKE_texpaint_slots_refresh_object(scene, ob);
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
- GPU_drawobject_free(ob->derivedFinal);
}
}
-
- for (ma = bmain->mat.first; ma; ma = ma->id.next)
- if (ma->gpumaterial.first)
- GPU_material_free(&ma->gpumaterial);
-
- for (wo = bmain->world.first; wo; wo = wo->id.next)
- if (wo->gpumaterial.first)
- GPU_material_free(&wo->gpumaterial);
-
- if (defmaterial.gpumaterial.first)
- GPU_material_free(&defmaterial.gpumaterial);
}
-void ED_render_id_flush_update(Main *bmain, ID *id)
+void ED_render_id_flush_update(const DEGEditorUpdateContext *update_ctx, ID *id)
{
/* this can be called from render or baking thread when a python script makes
* changes, in that case we don't want to do any editor updates, and making
* GPU changes is not possible because OpenGL only works in the main thread */
- if (!BLI_thread_is_main())
+ if (!BLI_thread_is_main()) {
return;
-
+ }
+ Main *bmain = update_ctx->bmain;
+ /* Internal ID update handlers. */
switch (GS(id->name)) {
case ID_MA:
material_changed(bmain, (Material *)id);
@@ -563,15 +370,5 @@ void ED_render_id_flush_update(Main *bmain, ID *id)
render_engine_flag_changed(bmain, RE_ENGINE_UPDATE_OTHER);
break;
}
-
}
-
-void ED_render_internal_init(void)
-{
- RenderEngineType *ret = RE_engines_find(RE_engine_id_BLENDER_RENDER);
-
- ret->view_update = render_view3d_update;
- ret->view_draw = render_view3d_draw;
-
-}
diff --git a/source/blender/editors/render/render_view.c b/source/blender/editors/render/render_view.c
index c4a9af79ec2..e4bae9d78ea 100644
--- a/source/blender/editors/render/render_view.c
+++ b/source/blender/editors/render/render_view.c
@@ -90,8 +90,10 @@ static ScrArea *find_area_showing_r_result(bContext *C, Scene *scene, wmWindow *
/* find an imagewindow showing render result */
for (*win = wm->windows.first; *win; *win = (*win)->next) {
- if ((*win)->screen->scene == scene) {
- for (sa = (*win)->screen->areabase.first; sa; sa = sa->next) {
+ if (WM_window_get_active_scene(*win) == scene) {
+ const bScreen *screen = WM_window_get_active_screen(*win);
+
+ for (sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->spacetype == SPACE_IMAGE) {
sima = sa->spacedata.first;
if (sima->image && sima->image->type == IMA_TYPE_R_RESULT)
@@ -246,7 +248,7 @@ static int render_view_cancel_exec(bContext *C, wmOperator *UNUSED(op))
}
/* test if we have a temp screen in front */
- if (win->screen->temp) {
+ if (WM_window_is_temp_screen(win)) {
wm_window_lower(win);
return OPERATOR_FINISHED;
}
@@ -292,7 +294,7 @@ static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *e
wmWindow *wincur = CTX_wm_window(C);
/* test if we have currently a temp screen active */
- if (wincur->screen->temp) {
+ if (WM_window_is_temp_screen(wincur)) {
wm_window_lower(wincur);
}
else {
@@ -301,8 +303,9 @@ static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *e
/* is there another window on current scene showing result? */
for (win = CTX_wm_manager(C)->windows.first; win; win = win->next) {
- bScreen *sc = win->screen;
- if ((sc->temp && ((ScrArea *)sc->areabase.first)->spacetype == SPACE_IMAGE) ||
+ const bScreen *sc = WM_window_get_active_screen(win);
+
+ if ((WM_window_is_temp_screen(win) && ((ScrArea *)sc->areabase.first)->spacetype == SPACE_IMAGE) ||
(win == winshow && winshow != wincur))
{
wm_window_raise(win);
diff --git a/source/blender/editors/scene/CMakeLists.txt b/source/blender/editors/scene/CMakeLists.txt
new file mode 100644
index 00000000000..9fbebbc58cc
--- /dev/null
+++ b/source/blender/editors/scene/CMakeLists.txt
@@ -0,0 +1,44 @@
+# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Contributor(s): Jacques Beaurain.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ ../include
+ ../../blenkernel
+ ../../blenlib
+ ../../blentranslation
+ ../../depsgraph
+ ../../makesdna
+ ../../makesrna
+ ../../windowmanager
+)
+
+set(INC_SYS
+
+)
+
+set(SRC
+ scene_edit.c
+)
+
+if(WITH_INTERNATIONAL)
+ add_definitions(-DWITH_INTERNATIONAL)
+endif()
+
+blender_add_lib(bf_editor_scene "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/scene/scene_edit.c b/source/blender/editors/scene/scene_edit.c
new file mode 100644
index 00000000000..b6608ce600f
--- /dev/null
+++ b/source/blender/editors/scene/scene_edit.c
@@ -0,0 +1,288 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/scene/scene_edit.c
+ * \ingroup edscene
+ */
+
+#include <stdio.h>
+
+#include "BLI_compiler_attrs.h"
+#include "BLI_listbase.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_layer.h"
+#include "BKE_library_remap.h"
+#include "BKE_main.h"
+#include "BKE_node.h"
+#include "BKE_report.h"
+#include "BKE_scene.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
+#include "BLT_translation.h"
+
+#include "DNA_object_types.h"
+#include "DNA_workspace_types.h"
+
+#include "ED_object.h"
+#include "ED_render.h"
+#include "ED_scene.h"
+#include "ED_screen.h"
+#include "ED_util.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+
+Scene *ED_scene_add(Main *bmain, bContext *C, wmWindow *win, eSceneCopyMethod method)
+{
+ Scene *scene_new;
+
+ if (method == SCE_COPY_NEW) {
+ scene_new = BKE_scene_add(bmain, DATA_("Scene"));
+ }
+ else { /* different kinds of copying */
+ Scene *scene_old = WM_window_get_active_scene(win);
+
+ scene_new = BKE_scene_copy(bmain, scene_old, method);
+
+ /* these can't be handled in blenkernel currently, so do them here */
+ if (method == SCE_COPY_LINK_DATA) {
+ ED_object_single_users(bmain, scene_new, false, true);
+ }
+ else if (method == SCE_COPY_FULL) {
+ ED_editors_flush_edits(C, false);
+ ED_object_single_users(bmain, scene_new, true, true);
+ }
+ }
+
+ WM_window_change_active_scene(bmain, C, win, scene_new);
+
+ WM_event_add_notifier(C, NC_SCENE | ND_SCENEBROWSE, scene_new);
+
+ return scene_new;
+}
+
+/**
+ * \note Only call outside of area/region loops
+ * \return true if successful
+ */
+bool ED_scene_delete(bContext *C, Main *bmain, wmWindow *win, Scene *scene)
+{
+ Scene *scene_new;
+
+ if (scene->id.prev)
+ scene_new = scene->id.prev;
+ else if (scene->id.next)
+ scene_new = scene->id.next;
+ else
+ return false;
+
+ WM_window_change_active_scene(bmain, C, win, scene_new);
+
+ BKE_libblock_remap(bmain, scene, scene_new, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
+
+ id_us_clear_real(&scene->id);
+ if (scene->id.us == 0) {
+ BKE_libblock_free(bmain, scene);
+ }
+
+ return true;
+}
+
+static ViewLayer *scene_change_get_new_view_layer(const WorkSpace *workspace, const Scene *scene_new)
+{
+ ViewLayer *layer_new = BKE_workspace_view_layer_get(workspace, scene_new);
+ return layer_new ? layer_new : BKE_view_layer_default_view(scene_new);
+}
+
+void ED_scene_change_update(
+ Main *bmain, bContext *C,
+ wmWindow *win, const bScreen *screen, Scene *UNUSED(scene_old), Scene *scene_new)
+{
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ ViewLayer *layer_new = scene_change_get_new_view_layer(workspace, scene_new);
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene_new, layer_new, true);
+ Object *obact_new = OBACT(layer_new);
+ UNUSED_VARS(obact_new);
+
+#if 0
+ /* mode syncing */
+ eObjectMode object_mode_old = workspace->object_mode;
+ ViewLayer *layer_old = BKE_view_layer_from_workspace_get(scene_old, workspace);
+ Object *obact_old = OBACT(layer_old);
+ UNUSED_VARS(obact_old, object_mode_old);
+#endif
+
+ win->scene = scene_new;
+ CTX_data_scene_set(C, scene_new);
+ BKE_workspace_view_layer_set(workspace, layer_new, scene_new);
+ BKE_scene_set_background(bmain, scene_new);
+ DEG_graph_relations_update(depsgraph, bmain, scene_new, layer_new);
+ DEG_on_visible_update(bmain, false);
+
+ ED_screen_update_after_scene_change(screen, scene_new, layer_new);
+ ED_render_engine_changed(bmain);
+ ED_update_for_newframe(bmain, depsgraph);
+
+ /* complete redraw */
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+}
+
+static bool view_layer_remove_poll(
+ const Scene *scene, const ViewLayer *layer)
+{
+ const int act = BLI_findindex(&scene->view_layers, layer);
+
+ if (act == -1) {
+ return false;
+ }
+ else if ((scene->view_layers.first == scene->view_layers.last) &&
+ (scene->view_layers.first == layer))
+ {
+ /* ensure 1 layer is kept */
+ return false;
+ }
+
+ return true;
+}
+
+static void view_layer_remove_unset_nodetrees(const Main *bmain, Scene *scene, ViewLayer *layer)
+{
+ int act_layer_index = BLI_findindex(&scene->view_layers, layer);
+
+ for (Scene *sce = bmain->scene.first; sce; sce = sce->id.next) {
+ if (sce->nodetree) {
+ BKE_nodetree_remove_layer_n(sce->nodetree, scene, act_layer_index);
+ }
+ }
+}
+
+bool ED_scene_view_layer_delete(
+ Main *bmain, Scene *scene, ViewLayer *layer,
+ ReportList *reports)
+{
+ if (view_layer_remove_poll(scene, layer) == false) {
+ if (reports) {
+ BKE_reportf(reports, RPT_ERROR, "View layer '%s' could not be removed from scene '%s'",
+ layer->name, scene->id.name + 2);
+ }
+
+ return false;
+ }
+
+ /* We need to unset nodetrees before removing the layer, otherwise its index will be -1. */
+ view_layer_remove_unset_nodetrees(bmain, scene, layer);
+
+ BLI_remlink(&scene->view_layers, layer);
+ BLI_assert(BLI_listbase_is_empty(&scene->view_layers) == false);
+
+ ED_workspace_view_layer_unset(bmain, scene, layer, scene->view_layers.first);
+ BKE_workspace_view_layer_remove_references(bmain, layer);
+
+ BKE_view_layer_free(layer);
+
+ DEG_id_tag_update(&scene->id, 0);
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER | NA_REMOVED, scene);
+
+ return true;
+}
+
+static int scene_new_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindow *win = CTX_wm_window(C);
+ int type = RNA_enum_get(op->ptr, "type");
+
+ ED_scene_add(bmain, C, win, type);
+
+ return OPERATOR_FINISHED;
+}
+
+static void SCENE_OT_new(wmOperatorType *ot)
+{
+ static EnumPropertyItem type_items[] = {
+ {SCE_COPY_NEW, "NEW", 0, "New", "Add new scene"},
+ {SCE_COPY_EMPTY, "EMPTY", 0, "Copy Settings", "Make a copy without any objects"},
+ {SCE_COPY_LINK_OB, "LINK_OBJECTS", 0, "Link Objects", "Link to the objects from the current scene"},
+ {SCE_COPY_LINK_DATA, "LINK_OBJECT_DATA", 0, "Link Object Data", "Copy objects linked to data from the current scene"},
+ {SCE_COPY_FULL, "FULL_COPY", 0, "Full Copy", "Make a full copy of the current scene"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ /* identifiers */
+ ot->name = "New Scene";
+ ot->description = "Add new scene by type";
+ ot->idname = "SCENE_OT_new";
+
+ /* api callbacks */
+ ot->exec = scene_new_exec;
+ ot->invoke = WM_menu_invoke;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
+}
+
+static int scene_delete_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Scene *scene = CTX_data_scene(C);
+
+ if (ED_scene_delete(C, CTX_data_main(C), CTX_wm_window(C), scene) == false) {
+ return OPERATOR_CANCELLED;
+ }
+
+ if (G.debug & G_DEBUG)
+ printf("scene delete %p\n", scene);
+
+ WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene);
+
+ return OPERATOR_FINISHED;
+}
+
+static void SCENE_OT_delete(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Delete Scene";
+ ot->description = "Delete active scene";
+ ot->idname = "SCENE_OT_delete";
+
+ /* api callbacks */
+ ot->exec = scene_delete_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+void ED_operatortypes_scene(void)
+{
+ WM_operatortype_append(SCENE_OT_new);
+ WM_operatortype_append(SCENE_OT_delete);
+}
diff --git a/source/blender/editors/screen/CMakeLists.txt b/source/blender/editors/screen/CMakeLists.txt
index 43e044b613a..29b9971eabb 100644
--- a/source/blender/editors/screen/CMakeLists.txt
+++ b/source/blender/editors/screen/CMakeLists.txt
@@ -23,8 +23,10 @@ set(INC
../../blenfont
../../blenkernel
../../blenlib
+ ../../blenloader
../../blentranslation
../../bmesh
+ ../../depsgraph
../../gpu
../../imbuf
../../makesdna
@@ -46,6 +48,8 @@ set(SRC
screen_edit.c
screen_ops.c
screendump.c
+ workspace_edit.c
+ workspace_layout_edit.c
screen_intern.h
)
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index a53a16906d3..d0d19398f5b 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -41,24 +41,27 @@
#include "BLI_utildefines.h"
#include "BLI_linklist_stack.h"
-
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_screen.h"
+#include "BKE_workspace.h"
#include "RNA_access.h"
#include "RNA_types.h"
#include "WM_api.h"
#include "WM_types.h"
-#include "wm_subwindow.h"
+#include "WM_message.h"
#include "ED_screen.h"
#include "ED_screen_types.h"
#include "ED_space_api.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+#include "GPU_draw.h"
+
#include "BLF_api.h"
#include "IMB_imbuf.h"
@@ -72,51 +75,79 @@
#include "screen_intern.h"
-extern void ui_draw_anti_tria(float x1, float y1, float x2, float y2, float x3, float y3); /* xxx temp */
+enum RegionEmbossSide {
+ REGION_EMBOSS_LEFT = (1 << 0),
+ REGION_EMBOSS_TOP = (1 << 1),
+ REGION_EMBOSS_BOTTOM = (1 << 2),
+ REGION_EMBOSS_RIGHT = (1 << 3),
+ REGION_EMBOSS_ALL = REGION_EMBOSS_LEFT | REGION_EMBOSS_TOP | REGION_EMBOSS_RIGHT | REGION_EMBOSS_BOTTOM,
+};
/* general area and region code */
-static void region_draw_emboss(const ARegion *ar, const rcti *scirct)
+static void region_draw_emboss(const ARegion *ar, const rcti *scirct, int sides)
{
rcti rect;
-
+
/* translate scissor rect to region space */
rect.xmin = scirct->xmin - ar->winrct.xmin;
rect.ymin = scirct->ymin - ar->winrct.ymin;
rect.xmax = scirct->xmax - ar->winrct.xmin;
rect.ymax = scirct->ymax - ar->winrct.ymin;
-
+
/* set transp line */
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- /* right */
- glColor4ub(0, 0, 0, 30);
- sdrawline(rect.xmax, rect.ymin, rect.xmax, rect.ymax);
-
- /* bottom */
- glColor4ub(0, 0, 0, 30);
- sdrawline(rect.xmin, rect.ymin, rect.xmax, rect.ymin);
-
- /* top */
- glColor4ub(255, 255, 255, 30);
- sdrawline(rect.xmin, rect.ymax, rect.xmax, rect.ymax);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ float color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
+ UI_GetThemeColor3fv(TH_EDITOR_OUTLINE, color);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv(color);
+
+ immBeginAtMost(GWN_PRIM_LINES, 8);
+
+ /* right */
+ if (sides & REGION_EMBOSS_RIGHT) {
+ immVertex2f(pos, rect.xmax, rect.ymax);
+ immVertex2f(pos, rect.xmax, rect.ymin);
+ }
+
+ /* bottom */
+ if (sides & REGION_EMBOSS_BOTTOM) {
+ immVertex2f(pos, rect.xmax, rect.ymin);
+ immVertex2f(pos, rect.xmin, rect.ymin);
+ }
+
+ /* left */
+ if (sides & REGION_EMBOSS_LEFT) {
+ immVertex2f(pos, rect.xmin, rect.ymin);
+ immVertex2f(pos, rect.xmin, rect.ymax);
+ }
+
+ /* top */
+ if (sides & REGION_EMBOSS_TOP) {
+ immVertex2f(pos, rect.xmin, rect.ymax);
+ immVertex2f(pos, rect.xmax, rect.ymax);
+ }
+
+ immEnd();
+ immUnbindProgram();
- /* left */
- glColor4ub(255, 255, 255, 30);
- sdrawline(rect.xmin, rect.ymin, rect.xmin, rect.ymax);
-
glDisable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
void ED_region_pixelspace(ARegion *ar)
{
wmOrtho2_region_pixelspace(ar);
- glLoadIdentity();
+ gpuLoadIdentity();
}
/* only exported for WM */
-void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note)
+void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note, const Scene *scene)
{
/* generic notes first */
switch (note->category) {
@@ -130,15 +161,15 @@ void ED_region_do_listen(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *note
}
if (ar->type && ar->type->listener)
- ar->type->listener(sc, sa, ar, note);
+ ar->type->listener(sc, sa, ar, note, scene);
}
/* only exported for WM */
-void ED_area_do_listen(bScreen *sc, ScrArea *sa, wmNotifier *note)
+void ED_area_do_listen(bScreen *sc, ScrArea *sa, wmNotifier *note, Scene *scene, WorkSpace *workspace)
{
/* no generic notes? */
if (sa->type && sa->type->listener) {
- sa->type->listener(sc, sa, note);
+ sa->type->listener(sc, sa, note, scene, workspace);
}
}
@@ -172,6 +203,24 @@ void ED_area_azones_update(ScrArea *sa, const int mouse_xy[2])
break;
}
}
+ else if (az->type == AZONE_REGION_SCROLL) {
+ /* only if mouse is not hovering the azone */
+ if (BLI_rcti_isect_pt_v(&az->rect, mouse_xy) == false) {
+ View2D *v2d = &az->ar->v2d;
+
+ if (az->direction == AZ_SCROLL_VERT) {
+ az->alpha = v2d->alpha_vert = 0;
+ changed = true;
+ }
+ else if (az->direction == AZ_SCROLL_HOR) {
+ az->alpha = v2d->alpha_hor = 0;
+ changed = true;
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+ }
}
if (changed) {
@@ -207,92 +256,55 @@ static void area_draw_azone_fullscreen(short x1, short y1, short x2, short y2, f
if (G.debug_value == 1) {
rcti click_rect;
float icon_size = UI_DPI_ICON_SIZE + 7 * UI_DPI_FAC;
- char alpha_debug = 255 * alpha;
BLI_rcti_init(&click_rect, x, x + icon_size, y, y + icon_size);
- glColor4ub(255, 0, 0, alpha_debug);
- fdrawbox(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
- glColor4ub(0, 255, 255, alpha_debug);
- fdrawline(click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
- fdrawline(click_rect.xmin, click_rect.ymax, click_rect.xmax, click_rect.ymin);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4f(1.0f, 0.0f, 0.0f, alpha);
+ imm_draw_box_wire_2d(pos, click_rect.xmin, click_rect.ymin, click_rect.xmax, click_rect.ymax);
+
+ immUniformColor4f(0.0f, 1.0f, 1.0f, alpha);
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, click_rect.xmin, click_rect.ymin);
+ immVertex2f(pos, click_rect.xmax, click_rect.ymax);
+ immVertex2f(pos, click_rect.xmin, click_rect.ymax);
+ immVertex2f(pos, click_rect.xmax, click_rect.ymin);
+ immEnd();
+
+ immUnbindProgram();
}
}
/**
* \brief Corner widgets use for dragging and splitting the view.
*/
-static void area_draw_azone(short x1, short y1, short x2, short y2)
+static void area_draw_azone(short UNUSED(x1), short UNUSED(y1), short UNUSED(x2), short UNUSED(y2))
{
- int dx = x2 - x1;
- int dy = y2 - y1;
-
- dx = copysign(ceilf(0.3f * abs(dx)), dx);
- dy = copysign(ceilf(0.3f * abs(dy)), dy);
-
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
-
- glColor4ub(255, 255, 255, 180);
- fdrawline(x1, y2, x2, y1);
- glColor4ub(255, 255, 255, 130);
- fdrawline(x1, y2 - dy, x2 - dx, y1);
- glColor4ub(255, 255, 255, 80);
- fdrawline(x1, y2 - 2 * dy, x2 - 2 * dx, y1);
-
- glColor4ub(0, 0, 0, 210);
- fdrawline(x1, y2 + 1, x2 + 1, y1);
- glColor4ub(0, 0, 0, 180);
- fdrawline(x1, y2 - dy + 1, x2 - dx + 1, y1);
- glColor4ub(0, 0, 0, 150);
- fdrawline(x1, y2 - 2 * dy + 1, x2 - 2 * dx + 1, y1);
-
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
+ /* No drawing needed since all corners are action zone, and visually distinguishable. */
}
-static void region_draw_azone_icon(AZone *az)
+static void draw_azone_plus(float x1, float y1, float x2, float y2)
{
- GLUquadricObj *qobj = NULL;
- short midx = az->x1 + (az->x2 - az->x1) / 2;
- short midy = az->y1 + (az->y2 - az->y1) / 2;
-
- qobj = gluNewQuadric();
-
- glPushMatrix();
- glTranslatef(midx, midy, 0.0);
-
- /* outlined circle */
- glEnable(GL_LINE_SMOOTH);
+ float width = 0.1f * U.widget_unit;
+ float pad = 0.2f * U.widget_unit;
- glColor4f(1.f, 1.f, 1.f, 0.8f);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- gluQuadricDrawStyle(qobj, GLU_FILL);
- gluDisk(qobj, 0.0, 4.25f, 16, 1);
+ glEnable(GL_BLEND);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4f(0.8f, 0.8f, 0.8f, 0.4f);
- glColor4f(0.2f, 0.2f, 0.2f, 0.9f);
-
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
- gluDisk(qobj, 0.0, 4.25f, 16, 1);
-
- glDisable(GL_LINE_SMOOTH);
-
- glPopMatrix();
- gluDeleteQuadric(qobj);
-
- /* + */
- sdrawline(midx, midy - 2, midx, midy + 3);
- sdrawline(midx - 2, midy, midx + 3, midy);
-}
+ immRectf(pos, (x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
+ immRectf(pos, x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
+ immRectf(pos, (x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
-static void draw_azone_plus(float x1, float y1, float x2, float y2)
-{
- float width = 0.1f * U.widget_unit;
- float pad = 0.2f * U.widget_unit;
-
- glRectf((x1 + x2 - width) * 0.5f, y1 + pad, (x1 + x2 + width) * 0.5f, y2 - pad);
- glRectf(x1 + pad, (y1 + y2 - width) * 0.5f, (x1 + x2 - width) * 0.5f, (y1 + y2 + width) * 0.5f);
- glRectf((x1 + x2 + width) * 0.5f, (y1 + y2 - width) * 0.5f, x2 - pad, (y1 + y2 + width) * 0.5f);
+ immUnbindProgram();
+ glDisable(GL_BLEND);
}
static void region_draw_azone_tab_plus(AZone *az)
@@ -315,87 +327,10 @@ static void region_draw_azone_tab_plus(AZone *az)
break;
}
- glColor4f(0.05f, 0.05f, 0.05f, 0.4f);
- UI_draw_roundbox((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
+ float color[4] = {0.05f, 0.05f, 0.05f, 0.4f};
+ UI_draw_roundbox_aa(true, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, color);
- glEnable(GL_BLEND);
-
- glColor4f(0.8f, 0.8f, 0.8f, 0.4f);
draw_azone_plus((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2);
-
- glDisable(GL_BLEND);
-}
-
-static void region_draw_azone_tab(AZone *az)
-{
- float col[3];
-
- glEnable(GL_BLEND);
- UI_GetThemeColor3fv(TH_HEADER, col);
- glColor4f(col[0], col[1], col[2], 0.5f);
-
- /* add code to draw region hidden as 'too small' */
- switch (az->edge) {
- case AE_TOP_TO_BOTTOMRIGHT:
- UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT | UI_RB_ALPHA);
-
- UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
- glColor4ub(0, 0, 0, 255);
- UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
- break;
- case AE_BOTTOM_TO_TOPLEFT:
- UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_RIGHT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
-
- UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
- glColor4ub(0, 0, 0, 255);
- UI_draw_roundbox_unfilled((float)az->x1, 0.3f + (float)az->y1, (float)az->x2, 0.3f + (float)az->y2, 4.0f);
- break;
- case AE_LEFT_TO_TOPRIGHT:
- UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_BOTTOM_LEFT | UI_RB_ALPHA);
-
- UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
- glColor4ub(0, 0, 0, 255);
- UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
- break;
- case AE_RIGHT_TO_TOPLEFT:
- UI_draw_roundbox_corner_set(UI_CNR_TOP_RIGHT | UI_CNR_BOTTOM_RIGHT | UI_RB_ALPHA);
-
- UI_draw_roundbox_shade_x(GL_POLYGON, (float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f, -0.3f, 0.05f);
- glColor4ub(0, 0, 0, 255);
- UI_draw_roundbox_unfilled((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y2, 4.0f);
- break;
- }
-
- glDisable(GL_BLEND);
-}
-
-static void region_draw_azone_tria(AZone *az)
-{
- glEnable(GL_BLEND);
- //UI_GetThemeColor3fv(TH_HEADER, col);
- glColor4f(0.0f, 0.0f, 0.0f, 0.35f);
-
- /* add code to draw region hidden as 'too small' */
- switch (az->edge) {
- case AE_TOP_TO_BOTTOMRIGHT:
- ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x2, (float)az->y1, (float)(az->x1 + az->x2) / 2, (float)az->y2);
- break;
-
- case AE_BOTTOM_TO_TOPLEFT:
- ui_draw_anti_tria((float)az->x1, (float)az->y2, (float)az->x2, (float)az->y2, (float)(az->x1 + az->x2) / 2, (float)az->y1);
- break;
-
- case AE_LEFT_TO_TOPRIGHT:
- ui_draw_anti_tria((float)az->x2, (float)az->y1, (float)az->x2, (float)az->y2, (float)az->x1, (float)(az->y1 + az->y2) / 2);
- break;
-
- case AE_RIGHT_TO_TOPLEFT:
- ui_draw_anti_tria((float)az->x1, (float)az->y1, (float)az->x1, (float)az->y2, (float)az->x2, (float)(az->y1 + az->y2) / 2);
- break;
-
- }
-
- glDisable(GL_BLEND);
}
static void area_azone_tag_update(ScrArea *sa)
@@ -412,10 +347,10 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar)
glLineWidth(1.0f);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- glPushMatrix();
- glTranslatef(-ar->winrct.xmin, -ar->winrct.ymin, 0.0f);
+ gpuPushMatrix();
+ gpuTranslate2f(-ar->winrct.xmin, -ar->winrct.ymin);
for (az = sa->actionzones.first; az; az = az->next) {
/* test if action zone is over this region */
@@ -427,18 +362,10 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar)
area_draw_azone(az->x1, az->y1, az->x2, az->y2);
}
else if (az->type == AZONE_REGION) {
-
if (az->ar) {
/* only display tab or icons when the region is hidden */
if (az->ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
- if (G.debug_value == 3)
- region_draw_azone_icon(az);
- else if (G.debug_value == 2)
- region_draw_azone_tria(az);
- else if (G.debug_value == 1)
- region_draw_azone_tab(az);
- else
- region_draw_azone_tab_plus(az);
+ region_draw_azone_tab_plus(az);
}
}
}
@@ -449,31 +376,68 @@ static void region_draw_azones(ScrArea *sa, ARegion *ar)
area_azone_tag_update(sa);
}
}
+ else if (az->type == AZONE_REGION_SCROLL) {
+ if (az->alpha != 0.0f) {
+ area_azone_tag_update(sa);
+ }
+ /* Don't draw this azone. */
+ }
}
}
- glPopMatrix();
+ gpuPopMatrix();
glDisable(GL_BLEND);
}
+/* Follow wmMsgNotifyFn spec */
+void ED_region_do_msg_notify_tag_redraw(
+ bContext *UNUSED(C), wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val)
+{
+ ARegion *ar = msg_val->owner;
+ ED_region_tag_redraw(ar);
+
+ /* This avoids _many_ situations where header/properties control display settings.
+ * the common case is space properties in the header */
+ if (ELEM(ar->regiontype, RGN_TYPE_HEADER, RGN_TYPE_UI)) {
+ while (ar && ar->prev) {
+ ar = ar->prev;
+ }
+ for (; ar; ar = ar->next) {
+ if (ELEM(ar->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_CHANNELS)) {
+ ED_region_tag_redraw(ar);
+ }
+ }
+ }
+}
+/* Follow wmMsgNotifyFn spec */
+void ED_area_do_msg_notify_tag_refresh(
+ bContext *UNUSED(C), wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val)
+{
+ ScrArea *sa = msg_val->user_data;
+ ED_area_tag_refresh(sa);
+}
+
/* only exported for WM */
-/* makes region ready for drawing, sets pixelspace */
-void ED_region_set(const bContext *C, ARegion *ar)
+void ED_region_do_layout(bContext *C, ARegion *ar)
{
- wmWindow *win = CTX_wm_window(C);
+ /* This is optional, only needed for dynamically sized regions. */
ScrArea *sa = CTX_wm_area(C);
-
- ar->drawrct = ar->winrct;
-
- /* note; this sets state, so we can use wmOrtho and friends */
- wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, true);
-
- UI_SetTheme(sa ? sa->spacetype : 0, ar->type ? ar->type->regionid : 0);
-
- ED_region_pixelspace(ar);
-}
+ ARegionType *at = ar->type;
+
+ if (!at->layout) {
+ return;
+ }
+
+ if (at->do_lock) {
+ return;
+ }
+
+ ar->do_draw |= RGN_DRAWING;
+ UI_SetTheme(sa ? sa->spacetype : 0, at->regionid);
+ at->layout(C, ar);
+}
/* only exported for WM */
void ED_region_do_draw(bContext *C, ARegion *ar)
@@ -481,27 +445,15 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
wmWindow *win = CTX_wm_window(C);
ScrArea *sa = CTX_wm_area(C);
ARegionType *at = ar->type;
- bool scissor_pad;
/* see BKE_spacedata_draw_locks() */
if (at->do_lock)
return;
- /* if no partial draw rect set, full rect */
- if (ar->drawrct.xmin == ar->drawrct.xmax) {
- ar->drawrct = ar->winrct;
- scissor_pad = true;
- }
- else {
- /* extra clip for safety */
- BLI_rcti_isect(&ar->winrct, &ar->drawrct, &ar->drawrct);
- scissor_pad = false;
- }
-
ar->do_draw |= RGN_DRAWING;
- /* note; this sets state, so we can use wmOrtho and friends */
- wmSubWindowScissorSet(win, ar->swinid, &ar->drawrct, scissor_pad);
+ /* Set viewport, scissor, ortho and ar->drawrct. */
+ wmPartialViewport(&ar->drawrct, &ar->winrct, &ar->drawrct);
wmOrtho2_region_pixelspace(ar);
@@ -512,7 +464,7 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
UI_ThemeClearColor(TH_HEADER);
glClear(GL_COLOR_BUFFER_BIT);
- UI_ThemeColor(TH_TEXT);
+ UI_FontThemeColor(BLF_default(), TH_TEXT);
BLF_draw_default(UI_UNIT_X, 0.4f * UI_UNIT_Y, 0.0f, ar->headerstr, BLF_DRAW_STR_DUMMY_MAX);
}
else if (at->draw) {
@@ -529,9 +481,13 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
/* for debugging unneeded area redraws and partial redraw */
#if 0
glEnable(GL_BLEND);
- glColor4f(drand48(), drand48(), drand48(), 0.1f);
- glRectf(ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4f(drand48(), drand48(), drand48(), 0.1f);
+ immRectf(pos, ar->drawrct.xmin - ar->winrct.xmin, ar->drawrct.ymin - ar->winrct.ymin,
ar->drawrct.xmax - ar->winrct.xmin, ar->drawrct.ymax - ar->winrct.ymin);
+ immUnbindProgram();
glDisable(GL_BLEND);
#endif
@@ -540,11 +496,46 @@ void ED_region_do_draw(bContext *C, ARegion *ar)
UI_blocklist_free_inactive(C, &ar->uiblocks);
if (sa) {
- /* disable emboss when the area is full,
- * unless we need to see division between regions (quad-split for eg) */
- if (((win->screen->state == SCREENFULL) && (ar->alignment == RGN_ALIGN_NONE)) == 0) {
- region_draw_emboss(ar, &ar->winrct);
+ const bScreen *screen = WM_window_get_active_screen(win);
+
+ /* Only draw region emboss for top-bar and quad-view. */
+ if ((screen->state != SCREENFULL) && ED_area_is_global(sa)) {
+ region_draw_emboss(ar, &ar->winrct, (REGION_EMBOSS_LEFT | REGION_EMBOSS_RIGHT));
+ }
+ else if ((ar->regiontype == RGN_TYPE_WINDOW) && (ar->alignment == RGN_ALIGN_QSPLIT)) {
+ region_draw_emboss(ar, &ar->winrct, REGION_EMBOSS_ALL);
+ }
+ }
+
+ /* We may want to detach message-subscriptions from drawing. */
+ {
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ wmWindowManager *wm = CTX_wm_manager(C);
+ bScreen *screen = WM_window_get_active_screen(win);
+ Scene *scene = CTX_data_scene(C);
+ struct wmMsgBus *mbus = wm->message_bus;
+ WM_msgbus_clear_by_owner(mbus, ar);
+
+ /* Cheat, always subscribe to this space type properties.
+ *
+ * This covers most cases and avoids copy-paste similar code for each space type.
+ */
+ if (ELEM(ar->regiontype, RGN_TYPE_WINDOW, RGN_TYPE_CHANNELS, RGN_TYPE_UI, RGN_TYPE_TOOLS)) {
+ SpaceLink *sl = sa->spacedata.first;
+
+ PointerRNA ptr;
+ RNA_pointer_create(&screen->id, &RNA_Space, sl, &ptr);
+
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+ /* All properties for this space type. */
+ WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_region_tag_redraw, __func__);
}
+
+ ED_region_message_subscribe(C, workspace, scene, screen, sa, ar, mbus);
}
}
@@ -656,7 +647,7 @@ void ED_area_headerprint(ScrArea *sa, const char *str)
/* ************************************************************ */
-static void area_azone_initialize(wmWindow *win, bScreen *screen, ScrArea *sa)
+static void area_azone_initialize(wmWindow *win, const bScreen *screen, ScrArea *sa)
{
AZone *az;
@@ -671,39 +662,62 @@ static void area_azone_initialize(wmWindow *win, bScreen *screen, ScrArea *sa)
return;
}
- /* can't click on bottom corners on OS X, already used for resizing */
+ if (ED_area_is_global(sa)) {
+ return;
+ }
+
+ float coords[4][4] = {
+ /* Bottom-left. */
+ {sa->totrct.xmin,
+ sa->totrct.ymin,
+ sa->totrct.xmin + (AZONESPOT - 1),
+ sa->totrct.ymin + (AZONESPOT - 1)},
+ /* Bottom-right. */
+ {sa->totrct.xmax,
+ sa->totrct.ymin,
+ sa->totrct.xmax - (AZONESPOT - 1),
+ sa->totrct.ymin + (AZONESPOT - 1)},
+ /* Top-left. */
+ {sa->totrct.xmin,
+ sa->totrct.ymax,
+ sa->totrct.xmin + (AZONESPOT - 1),
+ sa->totrct.ymax - (AZONESPOT - 1)},
+ /* Top-right. */
+ {sa->totrct.xmax,
+ sa->totrct.ymax,
+ sa->totrct.xmax - (AZONESPOT - 1),
+ sa->totrct.ymax - (AZONESPOT - 1)}};
+
+ for (int i = 0; i < 4; i++) {
+ /* can't click on bottom corners on OS X, already used for resizing */
#ifdef __APPLE__
- if (!(sa->totrct.xmin == 0 && sa->totrct.ymin == 0) || WM_window_is_fullscreen(win))
+ if (!WM_window_is_fullscreen(win) &&
+ ((coords[i][0] == 0 && coords[i][1] == 0) ||
+ (coords[i][0] == WM_window_pixels_x(win) && coords[i][1] == 0)))
+ {
+ continue;
+ }
#else
- (void)win;
+ (void)win;
#endif
- {
+
/* set area action zones */
az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
BLI_addtail(&(sa->actionzones), az);
az->type = AZONE_AREA;
- az->x1 = sa->totrct.xmin;
- az->y1 = sa->totrct.ymin;
- az->x2 = sa->totrct.xmin + (AZONESPOT - 1);
- az->y2 = sa->totrct.ymin + (AZONESPOT - 1);
+ az->x1 = coords[i][0];
+ az->y1 = coords[i][1];
+ az->x2 = coords[i][2];
+ az->y2 = coords[i][3];
BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
-
- az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&(sa->actionzones), az);
- az->type = AZONE_AREA;
- az->x1 = sa->totrct.xmax;
- az->y1 = sa->totrct.ymax;
- az->x2 = sa->totrct.xmax - (AZONESPOT - 1);
- az->y2 = sa->totrct.ymax - (AZONESPOT - 1);
- BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
static void fullscreen_azone_initialize(ScrArea *sa, ARegion *ar)
{
AZone *az;
- if (ar->regiontype != RGN_TYPE_WINDOW)
+ if (ED_area_is_global(sa) || (ar->regiontype != RGN_TYPE_WINDOW))
return;
az = (AZone *)MEM_callocN(sizeof(AZone), "fullscreen action zone");
@@ -753,65 +767,6 @@ static void region_azone_edge(AZone *az, ARegion *ar)
BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
-static void region_azone_icon(ScrArea *sa, AZone *az, ARegion *ar)
-{
- AZone *azt;
- int tot = 0;
-
- /* count how many actionzones with along same edge are available.
- * This allows for adding more action zones in the future without
- * having to worry about correct offset */
- for (azt = sa->actionzones.first; azt; azt = azt->next) {
- if (azt->edge == az->edge) tot++;
- }
-
- switch (az->edge) {
- case AE_TOP_TO_BOTTOMRIGHT:
- az->x1 = ar->winrct.xmax - tot * 2 * AZONEPAD_ICON;
- az->y1 = ar->winrct.ymax + AZONEPAD_ICON;
- az->x2 = ar->winrct.xmax - tot * AZONEPAD_ICON;
- az->y2 = ar->winrct.ymax + 2 * AZONEPAD_ICON;
- break;
- case AE_BOTTOM_TO_TOPLEFT:
- az->x1 = ar->winrct.xmin + AZONEPAD_ICON;
- az->y1 = ar->winrct.ymin - 2 * AZONEPAD_ICON;
- az->x2 = ar->winrct.xmin + 2 * AZONEPAD_ICON;
- az->y2 = ar->winrct.ymin - AZONEPAD_ICON;
- break;
- case AE_LEFT_TO_TOPRIGHT:
- az->x1 = ar->winrct.xmin - 2 * AZONEPAD_ICON;
- az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
- az->x2 = ar->winrct.xmin - AZONEPAD_ICON;
- az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
- break;
- case AE_RIGHT_TO_TOPLEFT:
- az->x1 = ar->winrct.xmax + AZONEPAD_ICON;
- az->y1 = ar->winrct.ymax - tot * 2 * AZONEPAD_ICON;
- az->x2 = ar->winrct.xmax + 2 * AZONEPAD_ICON;
- az->y2 = ar->winrct.ymax - tot * AZONEPAD_ICON;
- break;
- }
-
- BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
-
- /* if more azones on 1 spot, set offset */
- for (azt = sa->actionzones.first; azt; azt = azt->next) {
- if (az != azt) {
- if (ABS(az->x1 - azt->x1) < 2 && ABS(az->y1 - azt->y1) < 2) {
- if (az->edge == AE_TOP_TO_BOTTOMRIGHT || az->edge == AE_BOTTOM_TO_TOPLEFT) {
- az->x1 += AZONESPOT;
- az->x2 += AZONESPOT;
- }
- else {
- az->y1 -= AZONESPOT;
- az->y2 -= AZONESPOT;
- }
- BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
- }
- }
- }
-}
-
#define AZONEPAD_TAB_PLUSW (0.7f * U.widget_unit)
#define AZONEPAD_TAB_PLUSH (0.7f * U.widget_unit)
@@ -856,143 +811,99 @@ static void region_azone_tab_plus(ScrArea *sa, AZone *az, ARegion *ar)
BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
}
+static void region_azone_edge_initialize(ScrArea *sa, ARegion *ar, AZEdge edge, const bool is_fullscreen)
+{
+ AZone *az = NULL;
+ const bool is_hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
-#define AZONEPAD_TABW (0.9f * U.widget_unit)
-#define AZONEPAD_TABH (0.35f * U.widget_unit)
+ if (is_hidden && is_fullscreen) {
+ return;
+ }
-/* region already made zero sized, in shape of edge */
-static void region_azone_tab(ScrArea *sa, AZone *az, ARegion *ar)
-{
- AZone *azt;
- int tot = 0, add;
-
- for (azt = sa->actionzones.first; azt; azt = azt->next) {
- if (azt->edge == az->edge) tot++;
+ az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
+ BLI_addtail(&(sa->actionzones), az);
+ az->type = AZONE_REGION;
+ az->ar = ar;
+ az->edge = edge;
+
+ if (is_hidden) {
+ region_azone_tab_plus(sa, az, ar);
}
-
- switch (az->edge) {
- case AE_TOP_TO_BOTTOMRIGHT:
- add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
- az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TABW;
- az->y1 = ar->winrct.ymax - add;
- az->x2 = ar->winrct.xmax - AZONEPAD_TABW;
- az->y2 = ar->winrct.ymax - add + AZONEPAD_TABH;
- break;
- case AE_BOTTOM_TO_TOPLEFT:
- az->x1 = ar->winrct.xmin + AZONEPAD_TABW;
- az->y1 = ar->winrct.ymin - AZONEPAD_TABH;
- az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TABW;
- az->y2 = ar->winrct.ymin;
- break;
- case AE_LEFT_TO_TOPRIGHT:
- az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TABH;
- az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
- az->x2 = ar->winrct.xmin + 1;
- az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
- break;
- case AE_RIGHT_TO_TOPLEFT:
- az->x1 = ar->winrct.xmax - 1;
- az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TABW;
- az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TABH;
- az->y2 = ar->winrct.ymax - AZONEPAD_TABW;
- break;
+ else {
+ region_azone_edge(az, ar);
}
- /* rect needed for mouse pointer test */
- BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
-}
+}
-#define AZONEPAD_TRIAW (0.8f * U.widget_unit)
-#define AZONEPAD_TRIAH (0.45f * U.widget_unit)
+static void region_azone_scrollbar_initialize(ScrArea *sa, ARegion *ar, AZScrollDirection direction)
+{
+ rcti scroller_vert = (direction == AZ_SCROLL_VERT) ? ar->v2d.vert : ar->v2d.hor;
+ AZone *az = MEM_callocN(sizeof(*az), __func__);
+ BLI_addtail(&sa->actionzones, az);
+ az->type = AZONE_REGION_SCROLL;
+ az->ar = ar;
+ az->direction = direction;
-/* region already made zero sized, in shape of edge */
-static void region_azone_tria(ScrArea *sa, AZone *az, ARegion *ar)
-{
- AZone *azt;
- int tot = 0, add;
-
- for (azt = sa->actionzones.first; azt; azt = azt->next) {
- if (azt->edge == az->edge) tot++;
+ if (direction == AZ_SCROLL_VERT) {
+ az->ar->v2d.alpha_vert = 0;
}
-
- switch (az->edge) {
- case AE_TOP_TO_BOTTOMRIGHT:
- add = (ar->winrct.ymax == sa->totrct.ymin) ? 1 : 0;
- az->x1 = ar->winrct.xmax - 2 * AZONEPAD_TRIAW;
- az->y1 = ar->winrct.ymax - add;
- az->x2 = ar->winrct.xmax - AZONEPAD_TRIAW;
- az->y2 = ar->winrct.ymax - add + AZONEPAD_TRIAH;
- break;
- case AE_BOTTOM_TO_TOPLEFT:
- az->x1 = ar->winrct.xmin + AZONEPAD_TRIAW;
- az->y1 = ar->winrct.ymin - AZONEPAD_TRIAH;
- az->x2 = ar->winrct.xmin + 2 * AZONEPAD_TRIAW;
- az->y2 = ar->winrct.ymin;
- break;
- case AE_LEFT_TO_TOPRIGHT:
- az->x1 = ar->winrct.xmin + 1 - AZONEPAD_TRIAH;
- az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
- az->x2 = ar->winrct.xmin + 1;
- az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
- break;
- case AE_RIGHT_TO_TOPLEFT:
- az->x1 = ar->winrct.xmax - 1;
- az->y1 = ar->winrct.ymax - 2 * AZONEPAD_TRIAW;
- az->x2 = ar->winrct.xmax - 1 + AZONEPAD_TRIAH;
- az->y2 = ar->winrct.ymax - AZONEPAD_TRIAW;
- break;
+ else if (direction == AZ_SCROLL_HOR) {
+ az->ar->v2d.alpha_hor = 0;
}
- /* rect needed for mouse pointer test */
- BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
-}
+ BLI_rcti_translate(&scroller_vert, ar->winrct.xmin, ar->winrct.ymin);
+ az->x1 = scroller_vert.xmin - AZONEFADEIN;
+ az->y1 = scroller_vert.ymin - AZONEFADEIN;
+ az->x2 = scroller_vert.xmax + AZONEFADEIN;
+ az->y2 = scroller_vert.ymax + AZONEFADEIN;
-static void region_azone_initialize(ScrArea *sa, ARegion *ar, AZEdge edge, const bool is_fullscreen)
+ BLI_rcti_init(&az->rect, az->x1, az->x2, az->y1, az->y2);
+}
+
+static void region_azones_scrollbars_initialize(ScrArea *sa, ARegion *ar)
{
- AZone *az = NULL;
- const bool is_hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) == 0;
-
- if (is_hidden || !is_fullscreen) {
- az = (AZone *)MEM_callocN(sizeof(AZone), "actionzone");
- BLI_addtail(&(sa->actionzones), az);
- az->type = AZONE_REGION;
- az->ar = ar;
- az->edge = edge;
+ const View2D *v2d = &ar->v2d;
+
+ if ((v2d->scroll & V2D_SCROLL_VERTICAL) && ((v2d->scroll & V2D_SCROLL_SCALE_VERTICAL) == 0)) {
+ region_azone_scrollbar_initialize(sa, ar, AZ_SCROLL_VERT);
}
-
- if (!is_hidden) {
- if (!is_fullscreen) {
- if (G.debug_value == 3)
- region_azone_icon(sa, az, ar);
- else if (G.debug_value == 2)
- region_azone_tria(sa, az, ar);
- else if (G.debug_value == 1)
- region_azone_tab(sa, az, ar);
- else
- region_azone_tab_plus(sa, az, ar);
- }
+ if ((v2d->scroll & V2D_SCROLL_HORIZONTAL) && ((v2d->scroll & V2D_SCROLL_SCALE_HORIZONTAL) == 0)) {
+ region_azone_scrollbar_initialize(sa, ar, AZ_SCROLL_HOR);
}
- else {
- region_azone_edge(az, ar);
- }
-
}
/* *************************************************************** */
-static void region_azone_add(ScrArea *sa, ARegion *ar, const int alignment, const bool is_fullscreen)
+static void region_azones_add(const bScreen *screen, ScrArea *sa, ARegion *ar, const int alignment)
{
+ const bool is_fullscreen = screen->state == SCREENFULL;
+
/* edge code (t b l r) is along which area edge azone will be drawn */
-
- if (alignment == RGN_ALIGN_TOP)
- region_azone_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT, is_fullscreen);
+
+ if (ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
+ /* The logic for this is: when the header takes up the full area,
+ * disallow hiding it to view the main window.
+ *
+ * Without this, you can drag down the file selectors header and hide it
+ * by accident very easily (highly annoying!), the value 6 is arbitrary
+ * but accounts for small common rounding problems when scaling the UI,
+ * must be minimum '4' */
+ }
+ else if (alignment == RGN_ALIGN_TOP)
+ region_azone_edge_initialize(sa, ar, AE_BOTTOM_TO_TOPLEFT, is_fullscreen);
else if (alignment == RGN_ALIGN_BOTTOM)
- region_azone_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen);
+ region_azone_edge_initialize(sa, ar, AE_TOP_TO_BOTTOMRIGHT, is_fullscreen);
else if (alignment == RGN_ALIGN_RIGHT)
- region_azone_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT, is_fullscreen);
+ region_azone_edge_initialize(sa, ar, AE_LEFT_TO_TOPRIGHT, is_fullscreen);
else if (alignment == RGN_ALIGN_LEFT)
- region_azone_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT, is_fullscreen);
+ region_azone_edge_initialize(sa, ar, AE_RIGHT_TO_TOPLEFT, is_fullscreen);
+
+ if (is_fullscreen) {
+ fullscreen_azone_initialize(sa, ar);
+ }
+
+ region_azones_scrollbars_initialize(sa, ar);
}
/* dir is direction to check, not the splitting edge direction! */
@@ -1018,6 +929,10 @@ static void region_overlap_fix(ScrArea *sa, ARegion *ar)
/* find overlapping previous region on same place */
for (ar1 = ar->prev; ar1; ar1 = ar1->prev) {
+ if (ar1->flag & (RGN_FLAG_HIDDEN)) {
+ continue;
+ }
+
if (ar1->overlap && ((ar1->alignment & RGN_SPLIT_PREV) == 0)) {
align1 = ar1->alignment;
if (BLI_rcti_isect(&ar1->winrct, &ar->winrct, NULL)) {
@@ -1057,6 +972,10 @@ static void region_overlap_fix(ScrArea *sa, ARegion *ar)
/* At this point, 'ar' is in its final position and still open.
* Make a final check it does not overlap any previous 'other side' region. */
for (ar1 = ar->prev; ar1; ar1 = ar1->prev) {
+ if (ar1->flag & (RGN_FLAG_HIDDEN)) {
+ continue;
+ }
+
if (ar1->overlap && (ar1->alignment & RGN_SPLIT_PREV) == 0) {
if ((ar1->alignment != align) && BLI_rcti_isect(&ar1->winrct, &ar->winrct, NULL)) {
/* Left overlapping right or vice-versa, forbid this! */
@@ -1068,16 +987,19 @@ static void region_overlap_fix(ScrArea *sa, ARegion *ar)
}
/* overlapping regions only in the following restricted cases */
-static bool region_is_overlap(wmWindow *win, ScrArea *sa, ARegion *ar)
+static bool region_is_overlap(ScrArea *sa, ARegion *ar)
{
if (U.uiflag2 & USER_REGION_OVERLAP) {
- if (WM_is_draw_triple(win)) {
- if (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_SEQ)) {
- if (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS))
+ if (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_SEQ, SPACE_IMAGE)) {
+ if (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS))
+ return 1;
+
+ if (ELEM(sa->spacetype, SPACE_VIEW3D, SPACE_IMAGE)) {
+ if (ar->regiontype == RGN_TYPE_HEADER)
return 1;
}
- else if (sa->spacetype == SPACE_IMAGE) {
- if (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI, RGN_TYPE_TOOL_PROPS, RGN_TYPE_PREVIEW))
+ else if(sa->spacetype == SPACE_SEQ) {
+ if (ar->regiontype == RGN_TYPE_PREVIEW)
return 1;
}
}
@@ -1086,7 +1008,7 @@ static bool region_is_overlap(wmWindow *win, ScrArea *sa, ARegion *ar)
return 0;
}
-static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti *remainder, int quad)
+static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti *remainder, rcti *overlap_remainder, int quad)
{
rcti *remainder_prev = remainder;
int prefsizex, prefsizey;
@@ -1106,20 +1028,23 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
alignment = ar->alignment & ~RGN_SPLIT_PREV;
/* set here, assuming userpref switching forces to call this again */
- ar->overlap = region_is_overlap(win, sa, ar);
+ ar->overlap = region_is_overlap(sa, ar);
/* clear state flags first */
ar->flag &= ~RGN_FLAG_TOO_SMALL;
/* user errors */
if (ar->next == NULL && alignment != RGN_ALIGN_QSPLIT)
alignment = RGN_ALIGN_NONE;
-
- /* prefsize, for header we stick to exception (prevent dpi rounding error) */
- prefsizex = UI_DPI_FAC * (ar->sizex > 1 ? ar->sizex + 0.5f : ar->type->prefsizex);
-
+
+ /* prefsize, taking into account DPI */
+ prefsizex = UI_DPI_FAC * ((ar->sizex > 1) ? ar->sizex + 0.5f : ar->type->prefsizex);
+
if (ar->regiontype == RGN_TYPE_HEADER) {
prefsizey = ED_area_headersize();
}
+ else if (ED_area_is_global(sa)) {
+ prefsizey = ED_region_global_size_y();
+ }
else if (ar->regiontype == RGN_TYPE_UI && sa->spacetype == SPACE_FILE) {
prefsizey = UI_UNIT_Y * 2 + (UI_UNIT_Y / 2);
}
@@ -1144,50 +1069,50 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
BLI_rcti_init(remainder, 0, 0, 0, 0);
}
else if (alignment == RGN_ALIGN_TOP || alignment == RGN_ALIGN_BOTTOM) {
+ rcti *winrct = (ar->overlap) ? overlap_remainder : remainder;
- if (rct_fits(remainder, 'v', prefsizey) < 0) {
+ if (rct_fits(winrct, 'v', prefsizey) < 0) {
ar->flag |= RGN_FLAG_TOO_SMALL;
}
else {
- int fac = rct_fits(remainder, 'v', prefsizey);
+ int fac = rct_fits(winrct, 'v', prefsizey);
if (fac < 0)
prefsizey += fac;
- ar->winrct = *remainder;
+ ar->winrct = *winrct;
if (alignment == RGN_ALIGN_TOP) {
ar->winrct.ymin = ar->winrct.ymax - prefsizey + 1;
- remainder->ymax = ar->winrct.ymin - 1;
+ winrct->ymax = ar->winrct.ymin - 1;
}
else {
ar->winrct.ymax = ar->winrct.ymin + prefsizey - 1;
- remainder->ymin = ar->winrct.ymax + 1;
+ winrct->ymin = ar->winrct.ymax + 1;
}
}
}
else if (ELEM(alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
+ rcti *winrct = (ar->overlap) ? overlap_remainder : remainder;
- if (rct_fits(remainder, 'h', prefsizex) < 0) {
+ if (rct_fits(winrct, 'h', prefsizex) < 0) {
ar->flag |= RGN_FLAG_TOO_SMALL;
}
else {
- int fac = rct_fits(remainder, 'h', prefsizex);
+ int fac = rct_fits(winrct, 'h', prefsizex);
if (fac < 0)
prefsizex += fac;
- ar->winrct = *remainder;
+ ar->winrct = *winrct;
if (alignment == RGN_ALIGN_RIGHT) {
ar->winrct.xmin = ar->winrct.xmax - prefsizex + 1;
- if (ar->overlap == 0)
- remainder->xmax = ar->winrct.xmin - 1;
+ winrct->xmax = ar->winrct.xmin - 1;
}
else {
ar->winrct.xmax = ar->winrct.xmin + prefsizex - 1;
- if (ar->overlap == 0)
- remainder->xmin = ar->winrct.xmax + 1;
+ winrct->xmin = ar->winrct.xmax + 1;
}
}
}
@@ -1271,12 +1196,13 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
if (ar->winy > 1) ar->sizey = (ar->winy + 0.5f) / UI_DPI_FAC;
/* exception for multiple overlapping regions on same spot */
- if (ar->overlap)
+ if (ar->overlap) {
region_overlap_fix(sa, ar);
+ }
/* set winrect for azones */
if (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) {
- ar->winrct = *remainder;
+ ar->winrct = (ar->overlap) ? *overlap_remainder : *remainder;
switch (alignment) {
case RGN_ALIGN_TOP:
@@ -1304,44 +1230,48 @@ static void region_rect_recursive(wmWindow *win, ScrArea *sa, ARegion *ar, rcti
ar->prev->winy = BLI_rcti_size_y(&ar->prev->winrct) + 1;
}
}
-
- /* in end, add azones, where appropriate */
- if (ar->regiontype == RGN_TYPE_HEADER && ar->winy + 6 > sa->winy) {
- /* The logic for this is: when the header takes up the full area,
- * disallow hiding it to view the main window.
- *
- * Without this, you can drag down the file selectors header and hide it
- * by accident very easily (highly annoying!), the value 6 is arbitrary
- * but accounts for small common rounding problems when scaling the UI,
- * must be minimum '4' */
- }
- else {
- if (ELEM(win->screen->state, SCREENNORMAL, SCREENMAXIMIZED)) {
- region_azone_add(sa, ar, alignment, false);
- }
- else {
- region_azone_add(sa, ar, alignment, true);
- fullscreen_azone_initialize(sa, ar);
- }
+
+ /* After non-overlapping region, all following overlapping regions
+ * fit within the remaining space again. */
+ if (!ar->overlap) {
+ *overlap_remainder = *remainder;
}
- region_rect_recursive(win, sa, ar->next, remainder, quad);
+ region_rect_recursive(win, sa, ar->next, remainder, overlap_remainder, quad);
}
-static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
+static void area_calc_totrct(ScrArea *sa, int window_size_x, int window_size_y)
{
- short rt = (short) U.pixelsize;
+ short px = (short)U.pixelsize;
+
+ sa->totrct.xmin = sa->v1->vec.x;
+ sa->totrct.xmax = sa->v4->vec.x;
+ sa->totrct.ymin = sa->v1->vec.y;
+ sa->totrct.ymax = sa->v2->vec.y;
+
+ /* scale down totrct by 1 pixel on all sides not matching window borders */
+ if (sa->totrct.xmin > 0) {
+ sa->totrct.xmin += px;
+ }
+ if (sa->totrct.xmax < (window_size_x - 1)) {
+ sa->totrct.xmax -= px;
+ }
+ if (sa->totrct.ymin > 0) {
+ sa->totrct.ymin += px;
+ }
+ if (sa->totrct.ymax < (window_size_y - 1)) {
+ sa->totrct.ymax -= px;
+ }
+ /* Although the following asserts are correct they lead to a very unstable Blender.
+ * And the asserts would fail even in 2.7x (they were added in 2.8x as part of the top-bar commit).
+ * For more details see T54864. */
+#if 0
+ BLI_assert(sa->totrct.xmin >= 0);
+ BLI_assert(sa->totrct.xmax >= 0);
+ BLI_assert(sa->totrct.ymin >= 0);
+ BLI_assert(sa->totrct.ymax >= 0);
+#endif
- if (sa->v1->vec.x > 0) sa->totrct.xmin = sa->v1->vec.x + rt;
- else sa->totrct.xmin = sa->v1->vec.x;
- if (sa->v4->vec.x < sizex - 1) sa->totrct.xmax = sa->v4->vec.x - rt;
- else sa->totrct.xmax = sa->v4->vec.x;
-
- if (sa->v1->vec.y > 0) sa->totrct.ymin = sa->v1->vec.y + rt;
- else sa->totrct.ymin = sa->v1->vec.y;
- if (sa->v2->vec.y < sizey - 1) sa->totrct.ymax = sa->v2->vec.y - rt;
- else sa->totrct.ymax = sa->v2->vec.y;
-
/* for speedup */
sa->winx = BLI_rcti_size_x(&sa->totrct) + 1;
sa->winy = BLI_rcti_size_y(&sa->totrct) + 1;
@@ -1349,24 +1279,14 @@ static void area_calc_totrct(ScrArea *sa, int sizex, int sizey)
/* used for area initialize below */
-static void region_subwindow(wmWindow *win, ARegion *ar, bool activate)
+static void region_subwindow(ARegion *ar)
{
bool hidden = (ar->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL)) != 0;
if ((ar->alignment & RGN_SPLIT_PREV) && ar->prev)
hidden = hidden || (ar->prev->flag & (RGN_FLAG_HIDDEN | RGN_FLAG_TOO_SMALL));
- if (hidden) {
- if (ar->swinid)
- wm_subwindow_close(win, ar->swinid);
- ar->swinid = 0;
- }
- else if (ar->swinid == 0) {
- ar->swinid = wm_subwindow_open(win, &ar->winrct, activate);
- }
- else {
- wm_subwindow_position(win, ar->swinid, &ar->winrct, activate);
- }
+ ar->visible = !hidden;
}
static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *handlers, int flag)
@@ -1390,19 +1310,15 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
/* time-markers */
wmKeyMap *keymap = WM_keymap_find(wm->defaultconf, "Markers", 0, 0);
- /* time space only has this keymap, the others get a boundbox restricted map */
- if (sa->spacetype != SPACE_TIME) {
- ARegion *ar;
- /* same local check for all areas */
- static rcti rect = {0, 10000, 0, -1};
- rect.ymax = UI_MARKER_MARGIN_Y;
- ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
- if (ar) {
- WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
- }
+ /* use a boundbox restricted map */
+ ARegion *ar;
+ /* same local check for all areas */
+ static rcti rect = {0, 10000, 0, -1};
+ rect.ymax = UI_MARKER_MARGIN_Y;
+ ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
+ if (ar) {
+ WM_event_add_keymap_handler_bb(handlers, keymap, &rect, &ar->winrct);
}
- else
- WM_event_add_keymap_handler(handlers, keymap);
}
if (flag & ED_KEYMAP_ANIMATION) {
/* frame changing and timeline operators (for time spaces) */
@@ -1436,55 +1352,96 @@ static void ed_default_handlers(wmWindowManager *wm, ScrArea *sa, ListBase *hand
}
}
+void ED_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area)
+{
+ if (!(area->flag & AREA_FLAG_REGION_SIZE_UPDATE)) {
+ return;
+ }
+
+ const int size_x = WM_window_pixels_x(win);
+ const int size_y = WM_window_pixels_y(win);
+ rcti rect, overlap_rect;
+
+ area_calc_totrct(area, size_x, size_y);
+
+ /* region rect sizes */
+ rect = area->totrct;
+ overlap_rect = rect;
+ region_rect_recursive(win, area, area->regionbase.first, &rect, &overlap_rect, 0);
+
+ for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
+ region_subwindow(ar);
+
+ /* region size may have changed, init does necessary adjustments */
+ if (ar->type->init) {
+ ar->type->init(wm, ar);
+ }
+ }
+
+ area->flag &= ~AREA_FLAG_REGION_SIZE_UPDATE;
+}
/* called in screen_refresh, or screens_init, also area size changes */
void ED_area_initialize(wmWindowManager *wm, wmWindow *win, ScrArea *sa)
{
+ const bScreen *screen = WM_window_get_active_screen(win);
+ const int window_size_x = WM_window_pixels_x(win);
+ const int window_size_y = WM_window_pixels_y(win);
ARegion *ar;
- rcti rect;
-
+ rcti rect, overlap_rect;
+
+ if (ED_area_is_global(sa) && (sa->global->flag & GLOBAL_AREA_IS_HIDDEN)) {
+ return;
+ }
+
/* set typedefinitions */
sa->type = BKE_spacetype_from_id(sa->spacetype);
if (sa->type == NULL) {
- sa->butspacetype = sa->spacetype = SPACE_VIEW3D;
+ sa->spacetype = SPACE_VIEW3D;
sa->type = BKE_spacetype_from_id(sa->spacetype);
}
-
+
for (ar = sa->regionbase.first; ar; ar = ar->next)
ar->type = BKE_regiontype_from_id(sa->type, ar->regiontype);
-
+
/* area sizes */
- area_calc_totrct(sa, WM_window_pixels_x(win), WM_window_pixels_y(win));
-
- /* clear all azones, add the area triange widgets */
- area_azone_initialize(win, win->screen, sa);
+ area_calc_totrct(sa, window_size_x, window_size_y);
/* region rect sizes */
rect = sa->totrct;
- region_rect_recursive(win, sa, sa->regionbase.first, &rect, 0);
+ overlap_rect = rect;
+ region_rect_recursive(win, sa, sa->regionbase.first, &rect, &overlap_rect, 0);
+ sa->flag &= ~AREA_FLAG_REGION_SIZE_UPDATE;
/* default area handlers */
ed_default_handlers(wm, sa, &sa->handlers, sa->type->keymapflag);
/* checks spacedata, adds own handlers */
if (sa->type->init)
sa->type->init(wm, sa);
-
+
+ /* clear all azones, add the area triange widgets */
+ area_azone_initialize(win, screen, sa);
+
/* region windows, default and own handlers */
for (ar = sa->regionbase.first; ar; ar = ar->next) {
- region_subwindow(win, ar, false);
+ region_subwindow(ar);
- if (ar->swinid) {
+ if (ar->visible) {
/* default region handlers */
ed_default_handlers(wm, sa, &ar->handlers, ar->type->keymapflag);
/* own handlers */
- if (ar->type->init)
+ if (ar->type->init) {
ar->type->init(wm, ar);
+ }
}
else {
/* prevent uiblocks to run */
UI_blocklist_free(NULL, &ar->uiblocks);
}
+
+ /* Some AZones use View2D data which is only updated in region init, so call that first! */
+ region_azones_add(screen, sa, ar, ar->alignment & ~RGN_SPLIT_PREV);
}
}
@@ -1500,22 +1457,16 @@ static void region_update_rect(ARegion *ar)
/**
* Call to move a popup window (keep OpenGL context free!)
*/
-void ED_region_update_rect(bContext *C, ARegion *ar)
+void ED_region_update_rect(bContext *UNUSED(C), ARegion *ar)
{
- wmWindow *win = CTX_wm_window(C);
-
- wm_subwindow_rect_set(win, ar->swinid, &ar->winrct);
-
region_update_rect(ar);
}
/* externally called for floating regions like menus */
-void ED_region_init(bContext *C, ARegion *ar)
+void ED_region_init(bContext *UNUSED(C), ARegion *ar)
{
-// ARegionType *at = ar->type;
-
/* refresh can be called before window opened */
- region_subwindow(CTX_wm_window(C), ar, false);
+ region_subwindow(ar);
region_update_rect(ar);
}
@@ -1530,6 +1481,18 @@ void ED_region_cursor_set(wmWindow *win, ScrArea *sa, ARegion *ar)
}
}
+/* for use after changing visiblity of regions */
+void ED_region_visibility_change_update(bContext *C, ARegion *ar)
+{
+ ScrArea *sa = CTX_wm_area(C);
+
+ if (ar->flag & RGN_FLAG_HIDDEN)
+ WM_event_remove_handlers(C, &ar->handlers);
+
+ ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
+ ED_area_tag_redraw(sa);
+}
+
/* for quick toggle, can skip fades */
void region_toggle_hidden(bContext *C, ARegion *ar, const bool do_fade)
{
@@ -1542,11 +1505,7 @@ void region_toggle_hidden(bContext *C, ARegion *ar, const bool do_fade)
region_blend_start(C, sa, ar);
}
else {
- if (ar->flag & RGN_FLAG_HIDDEN)
- WM_event_remove_handlers(C, &ar->handlers);
-
- ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
- ED_area_tag_redraw(sa);
+ ED_region_visibility_change_update(C, ar);
}
}
@@ -1566,10 +1525,8 @@ void ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free)
const char spacetype = sa_dst->spacetype;
const short flag_copy = HEADER_NO_PULLDOWN;
- sa_dst->headertype = sa_src->headertype;
sa_dst->spacetype = sa_src->spacetype;
sa_dst->type = sa_src->type;
- sa_dst->butspacetype = sa_src->butspacetype;
sa_dst->flag = (sa_dst->flag & ~flag_copy) | (sa_src->flag & flag_copy);
@@ -1597,10 +1554,8 @@ void ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free)
void ED_area_data_swap(ScrArea *sa_dst, ScrArea *sa_src)
{
- SWAP(short, sa_dst->headertype, sa_src->headertype);
SWAP(char, sa_dst->spacetype, sa_src->spacetype);
SWAP(SpaceType *, sa_dst->type, sa_src->type);
- SWAP(char, sa_dst->butspacetype, sa_src->butspacetype);
SWAP(ListBase, sa_dst->spacedata, sa_src->spacedata);
@@ -1639,12 +1594,15 @@ void ED_area_swapspace(bContext *C, ScrArea *sa1, ScrArea *sa2)
*/
void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exit)
{
+ wmWindow *win = CTX_wm_window(C);
+
if (sa->spacetype != type) {
SpaceType *st;
SpaceLink *slold;
SpaceLink *sl;
/* store sa->type->exit callback */
void *sa_exit = sa->type ? sa->type->exit : NULL;
+ int header_alignment = ED_area_header_alignment(sa);
/* in some cases (opening temp space) we don't want to
* call area exit callback, so we temporarily unset it */
@@ -1663,9 +1621,12 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
slold = sa->spacedata.first;
sa->spacetype = type;
- sa->butspacetype = type;
sa->type = st;
-
+
+ /* If st->new may be called, don't use context until then. The
+ * sa->type->context() callback has changed but data may be invalid
+ * (e.g. with properties editor) until space-data is properly created */
+
/* check previously stored space */
for (sl = sa->spacedata.first; sl; sl = sl->next)
if (sl->spacetype == type)
@@ -1680,7 +1641,7 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
}
sl = NULL;
}
-
+
if (sl) {
/* swap regions */
slold->regionbase = sa->regionbase;
@@ -1690,11 +1651,22 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
/* put in front of list */
BLI_remlink(&sa->spacedata, sl);
BLI_addhead(&sa->spacedata, sl);
+
+
+ /* Sync header alignment. */
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->regiontype == RGN_TYPE_HEADER) {
+ ar->alignment = header_alignment;
+ break;
+ }
+ }
}
else {
/* new space */
if (st) {
- sl = st->new(C);
+ /* Don't get scene from context here which may depend on space-data. */
+ Scene *scene = WM_window_get_active_scene(win);
+ sl = st->new(sa, scene);
BLI_addhead(&sa->spacedata, sl);
/* swap regions */
@@ -1705,7 +1677,7 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
}
}
- ED_area_initialize(CTX_wm_manager(C), CTX_wm_window(C), sa);
+ ED_area_initialize(CTX_wm_manager(C), win, sa);
/* tell WM to refresh, cursor types etc */
WM_event_add_mousemove(C);
@@ -1762,8 +1734,45 @@ int ED_area_header_switchbutton(const bContext *C, uiBlock *block, int yco)
/************************ standard UI regions ************************/
+static ThemeColorID region_background_color_id(const bContext *C, const ARegion *region)
+{
+ ScrArea *area = CTX_wm_area(C);
+
+ switch (region->regiontype) {
+ case RGN_TYPE_HEADER:
+ if (ED_screen_area_active(C) || ED_area_is_global(area)) {
+ return TH_HEADER;
+ }
+ else {
+ return TH_HEADERDESEL;
+ }
+ case RGN_TYPE_PREVIEW:
+ return TH_PREVIEW_BACK;
+ default:
+ return TH_BACK;
+ }
+}
+
+static void region_clear_color(const bContext *C, const ARegion *ar, ThemeColorID colorid)
+{
+ if (ar->overlap) {
+ /* view should be in pixelspace */
+ UI_view2d_view_restore(C);
+
+ float back[4];
+ UI_GetThemeColor4fv(colorid, back);
+ glClearColor(back[3] * back[0], back[3] * back[1], back[3] * back[2], back[3]);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+ else {
+ UI_ThemeClearColor(colorid);
+ glClear(GL_COLOR_BUFFER_BIT);
+ }
+}
+
void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int contextnr, const bool vertical)
{
+ const WorkSpace *workspace = CTX_wm_workspace(C);
ScrArea *sa = CTX_wm_area(C);
uiStyle *style = UI_style_get_dpi();
uiBlock *block;
@@ -1773,7 +1782,6 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c
View2DScrollers *scrollers;
int x, y, xco, yco, w, em, triangle;
bool is_context_new = 0;
- int redo;
int scroll;
bool use_category_tabs = (ELEM(ar->regiontype, RGN_TYPE_TOOLS, RGN_TYPE_UI)); /* XXX, should use some better check? */
@@ -1814,6 +1822,11 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c
continue;
}
+ /* If we're tagged, only use compatible. */
+ if (pt->owner_id[0] && BKE_workspace_owner_id_check(workspace, pt->owner_id) == false) {
+ continue;
+ }
+
/* draw panel */
if (pt->draw && (!pt->poll || pt->poll(C, pt))) {
BLI_SMALLSTACK_PUSH(pt_stack, pt);
@@ -1846,155 +1859,134 @@ void ED_region_panels(const bContext *C, ARegion *ar, const char *context, int c
}
- /* sortof hack - but we cannot predict the height of panels, until it's being generated */
- /* the layout engine works with fixed width (from v2d->cur), which is being set at end of the loop */
- /* in case scroller settings (hide flags) differ from previous, the whole loop gets done again */
- for (redo = 2; redo > 0; redo--) {
-
- if (vertical) {
- w = BLI_rctf_size_x(&v2d->cur);
- em = (ar->type->prefsizex) ? 10 : 20; /* works out to 10*UI_UNIT_X or 20*UI_UNIT_X */
- }
- else {
- w = UI_PANEL_WIDTH;
- em = (ar->type->prefsizex) ? 10 : 20;
- }
+ if (vertical) {
+ w = BLI_rctf_size_x(&v2d->cur);
+ em = (ar->type->prefsizex) ? 10 : 20; /* works out to 10*UI_UNIT_X or 20*UI_UNIT_X */
+ }
+ else {
+ w = UI_PANEL_WIDTH;
+ em = (ar->type->prefsizex) ? 10 : 20;
+ }
- w -= margin_x;
-
- /* create panels */
- UI_panels_begin(C, ar);
+ w -= margin_x;
- /* set view2d view matrix - UI_block_begin() stores it */
- UI_view2d_view_ortho(v2d);
+ /* create panels */
+ UI_panels_begin(C, ar);
- BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt)
- {
- bool open;
+ /* set view2d view matrix - UI_block_begin() stores it */
+ UI_view2d_view_ortho(v2d);
- panel = UI_panel_find_by_type(ar, pt);
+ BLI_SMALLSTACK_ITER_BEGIN(pt_stack, pt)
+ {
+ bool open;
- if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) {
- if ((panel == NULL) || ((panel->flag & PNL_PIN) == 0)) {
- continue;
- }
+ panel = UI_panel_find_by_type(ar, pt);
+
+ if (use_category_tabs && pt->category[0] && !STREQ(category, pt->category)) {
+ if ((panel == NULL) || ((panel->flag & PNL_PIN) == 0)) {
+ continue;
}
+ }
- /* draw panel */
- block = UI_block_begin(C, ar, pt->idname, UI_EMBOSS);
- panel = UI_panel_begin(sa, ar, block, pt, panel, &open);
+ /* draw panel */
+ block = UI_block_begin(C, ar, pt->idname, UI_EMBOSS);
+ panel = UI_panel_begin(sa, ar, block, pt, panel, &open);
- /* bad fixed values */
- triangle = (int)(UI_UNIT_Y * 1.1f);
+ /* bad fixed values */
+ triangle = (int)(UI_UNIT_Y * 1.1f);
- if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
- /* for enabled buttons */
- panel->layout = UI_block_layout(
- block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
- triangle, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, 0, style);
+ if (pt->draw_header && !(pt->flag & PNL_NO_HEADER) && (open || vertical)) {
+ /* for enabled buttons */
+ panel->layout = UI_block_layout(
+ block, UI_LAYOUT_HORIZONTAL, UI_LAYOUT_HEADER,
+ triangle, (UI_UNIT_Y * 1.1f) + style->panelspace, UI_UNIT_Y, 1, 0, style);
- pt->draw_header(C, panel);
+ pt->draw_header(C, panel);
- UI_block_layout_resolve(block, &xco, &yco);
- panel->labelofs = xco - triangle;
- panel->layout = NULL;
- }
- else {
- panel->labelofs = 0;
- }
+ UI_block_layout_resolve(block, &xco, &yco);
+ panel->labelofs = xco - triangle;
+ panel->layout = NULL;
+ }
+ else {
+ panel->labelofs = 0;
+ }
+
+ if (open) {
+ short panelContext;
+
+ /* panel context can either be toolbar region or normal panels region */
+ if (ar->regiontype == RGN_TYPE_TOOLS)
+ panelContext = UI_LAYOUT_TOOLBAR;
+ else
+ panelContext = UI_LAYOUT_PANEL;
- if (open) {
- short panelContext;
+ panel->layout = UI_block_layout(
+ block, UI_LAYOUT_VERTICAL, panelContext,
+ style->panelspace, 0, w - 2 * style->panelspace, em, 0, style);
- /* panel context can either be toolbar region or normal panels region */
- if (ar->regiontype == RGN_TYPE_TOOLS)
- panelContext = UI_LAYOUT_TOOLBAR;
- else
- panelContext = UI_LAYOUT_PANEL;
+ pt->draw(C, panel);
- panel->layout = UI_block_layout(
- block, UI_LAYOUT_VERTICAL, panelContext,
- style->panelspace, 0, w - 2 * style->panelspace, em, 0, style);
+ UI_block_layout_resolve(block, &xco, &yco);
+ panel->layout = NULL;
- pt->draw(C, panel);
+ yco -= 2 * style->panelspace;
+ UI_panel_end(block, w, -yco);
+ }
+ else {
+ yco = 0;
+ UI_panel_end(block, w, 0);
+ }
- UI_block_layout_resolve(block, &xco, &yco);
- panel->layout = NULL;
+ UI_block_end(C, block);
+ }
+ BLI_SMALLSTACK_ITER_END;
- yco -= 2 * style->panelspace;
- UI_panel_end(block, w, -yco);
+ /* align panels and return size */
+ UI_panels_end(C, ar, &x, &y);
+
+ /* before setting the view */
+ if (vertical) {
+ /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */
+ if (v2d->cur.ymax < -FLT_EPSILON) {
+ /* Clamp to lower view boundary */
+ if (v2d->tot.ymin < -v2d->winy) {
+ y = min_ii(y, 0);
}
else {
- yco = 0;
- UI_panel_end(block, w, 0);
+ y = min_ii(y, v2d->cur.ymin);
}
-
- UI_block_end(C, block);
}
- BLI_SMALLSTACK_ITER_END;
- /* align panels and return size */
- UI_panels_end(C, ar, &x, &y);
-
- /* before setting the view */
- if (vertical) {
- /* we always keep the scroll offset - so the total view gets increased with the scrolled away part */
- if (v2d->cur.ymax < -FLT_EPSILON) {
- /* Clamp to lower view boundary */
- if (v2d->tot.ymin < -v2d->winy) {
- y = min_ii(y, 0);
- }
- else {
- y = min_ii(y, v2d->cur.ymin);
- }
+ y = -y;
+ }
+ else {
+ /* don't jump back when panels close or hide */
+ if (!is_context_new) {
+ if (v2d->tot.xmax > v2d->winx) {
+ x = max_ii(x, 0);
}
-
- y = -y;
- }
- else {
- /* don't jump back when panels close or hide */
- if (!is_context_new) {
- if (v2d->tot.xmax > v2d->winx) {
- x = max_ii(x, 0);
- }
- else {
- x = max_ii(x, v2d->cur.xmax);
- }
+ else {
+ x = max_ii(x, v2d->cur.xmax);
}
-
- y = -y;
}
-
- /* this also changes the 'cur' */
- UI_view2d_totRect_set(v2d, x, y);
-
- if (scroll != v2d->scroll) {
- /* Note: this code scales fine, but because of rounding differences, positions of elements
- * flip +1 or -1 pixel compared to redoing the entire layout again.
- * Leaving in commented code for future tests */
+
+ y = -y;
+ }
+
+ /* this also changes the 'cur' */
+ UI_view2d_totRect_set(v2d, x, y);
+
+ if (scroll != v2d->scroll) {
+ /* Note: this code scales fine, but because of rounding differences, positions of elements
+ * flip +1 or -1 pixel compared to redoing the entire layout again.
+ * Leaving in commented code for future tests */
#if 0
- UI_panels_scale(ar, BLI_rctf_size_x(&v2d->cur));
- break;
+ UI_panels_scale(ar, BLI_rctf_size_x(&v2d->cur));
+ break;
#endif
- }
- else {
- break;
- }
}
- /* clear */
- if (ar->overlap) {
- /* view should be in pixelspace */
- UI_view2d_view_restore(C);
- glEnable(GL_BLEND);
- UI_ThemeColor4((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
- glRecti(0, 0, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct) + 1);
- glDisable(GL_BLEND);
- }
- else {
- UI_ThemeClearColor((ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
- glClear(GL_COLOR_BUFFER_BIT);
- }
+ region_clear_color(C, ar, (ar->type->regionid == RGN_TYPE_PREVIEW) ? TH_PREVIEW_BACK : TH_BACK);
/* reset line width for drawing tabs */
glLineWidth(1.0f);
@@ -2028,7 +2020,7 @@ void ED_region_panels_init(wmWindowManager *wm, ARegion *ar)
WM_event_add_keymap_handler(&ar->handlers, keymap);
}
-void ED_region_header(const bContext *C, ARegion *ar)
+void ED_region_header_layout(const bContext *C, ARegion *ar)
{
uiStyle *style = UI_style_get_dpi();
uiBlock *block;
@@ -2037,16 +2029,20 @@ void ED_region_header(const bContext *C, ARegion *ar)
Header header = {NULL};
int maxco, xco, yco;
int headery = ED_area_headersize();
+ const int start_ofs = 0.4f * UI_UNIT_X;
+ bool region_layout_based = ar->flag & RGN_FLAG_DYNAMIC_SIZE;
- /* clear */
- UI_ThemeClearColor((ED_screen_area_active(C)) ? TH_HEADER : TH_HEADERDESEL);
- glClear(GL_COLOR_BUFFER_BIT);
-
/* set view2d view matrix for scrolling (without scrollers) */
UI_view2d_view_ortho(&ar->v2d);
- xco = maxco = 0.4f * UI_UNIT_X;
- yco = headery - floor(0.2f * UI_UNIT_Y);
+ xco = maxco = start_ofs;
+ yco = headery + (ar->winy - headery) / 2 - floor(0.2f * UI_UNIT_Y);
+
+ /* XXX workaround for 1 px alignment issue. Not sure what causes it... Would prefer a proper fix - Julian */
+ if (CTX_wm_area(C)->spacetype == SPACE_TOPBAR) {
+ xco += 1;
+ yco += 1;
+ }
/* draw all headers types */
for (ht = ar->type->headertypes.first; ht; ht = ht->next) {
@@ -2069,18 +2065,51 @@ void ED_region_header(const bContext *C, ARegion *ar)
/* for view2d */
if (xco > maxco)
maxco = xco;
-
+
+ int new_sizex = (maxco + start_ofs) / UI_DPI_FAC;
+
+ if (region_layout_based && (ar->sizex != new_sizex)) {
+ /* region size is layout based and needs to be updated */
+ ScrArea *sa = CTX_wm_area(C);
+
+ ar->sizex = new_sizex;
+ sa->flag |= AREA_FLAG_REGION_SIZE_UPDATE;
+ }
+
UI_block_end(C, block);
- UI_block_draw(C, block);
}
/* always as last */
- UI_view2d_totRect_set(&ar->v2d, maxco + UI_UNIT_X + 80, headery);
+ UI_view2d_totRect_set(&ar->v2d, maxco + (region_layout_based ? 0 : UI_UNIT_X + 80), headery);
- /* restore view matrix? */
+ /* restore view matrix */
+ UI_view2d_view_restore(C);
+}
+
+void ED_region_header_draw(const bContext *C, ARegion *ar)
+{
+ UI_view2d_view_ortho(&ar->v2d);
+
+ /* clear */
+ region_clear_color(C, ar, region_background_color_id(C, ar));
+
+ /* View2D matrix might have changed due to dynamic sized regions. */
+ UI_blocklist_update_window_matrix(C, &ar->uiblocks);
+
+ /* draw blocks */
+ UI_blocklist_draw(C, &ar->uiblocks);
+
+ /* restore view matrix */
UI_view2d_view_restore(C);
}
+void ED_region_header(const bContext *C, ARegion *ar)
+{
+ /* TODO: remove? */
+ ED_region_header_layout(C, ar);
+ ED_region_header_draw(C, ar);
+}
+
void ED_region_header_init(ARegion *ar)
{
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_HEADER, ar->winx, ar->winy);
@@ -2092,42 +2121,133 @@ int ED_area_headersize(void)
return (int)(HEADERY * UI_DPI_FAC);
}
-void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], const bool full_redraw)
+
+int ED_area_header_alignment(const ScrArea *area)
+{
+ for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
+ if (ar->regiontype == RGN_TYPE_HEADER) {
+ return ar->alignment;
+ }
+ }
+
+ return RGN_ALIGN_TOP;
+}
+
+/**
+ * \return the final height of a global \a area, accounting for DPI.
+ */
+int ED_area_global_size_y(const ScrArea *area)
+{
+ BLI_assert(ED_area_is_global(area));
+ return round_fl_to_int(area->global->cur_fixed_height * UI_DPI_FAC);
+}
+
+bool ED_area_is_global(const ScrArea *area)
+{
+ return area->global != NULL;
+}
+
+ScrArea *ED_screen_areas_iter_first(const wmWindow *win, const bScreen *screen)
+{
+ ScrArea *global_area = win->global_areas.areabase.first;
+
+ if (!global_area) {
+ return screen->areabase.first;
+ }
+ else if ((global_area->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) {
+ return global_area;
+ }
+ /* Find next visible area. */
+ return ED_screen_areas_iter_next(screen, global_area);
+}
+ScrArea *ED_screen_areas_iter_next(const bScreen *screen, const ScrArea *area)
+{
+ if (area->global) {
+ for (ScrArea *area_iter = area->next; area_iter; area_iter = area_iter->next) {
+ if ((area_iter->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) {
+ return area_iter;
+ }
+ }
+ /* No visible next global area found, start iterating over layout areas. */
+ return screen->areabase.first;
+ }
+
+ return area->next;
+}
+
+/**
+ * For now we just assume all global areas are made up out of horizontal bars
+ * with the same size. A fixed size could be stored in ARegion instead if needed.
+ *
+ * \return the DPI aware height of a single bar/region in global areas.
+ */
+int ED_region_global_size_y(void)
+{
+ return ED_area_headersize(); /* same size as header */
+}
+
+void ED_region_info_draw_multiline(ARegion *ar, const char *text_array[], float fill_color[4], const bool full_redraw)
{
const int header_height = UI_UNIT_Y;
uiStyle *style = UI_style_get_dpi();
int fontid = style->widget.uifont_id;
GLint scissor[4];
rcti rect;
+ int num_lines = 0;
/* background box */
ED_region_visible_rect(ar, &rect);
- rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height;
- /* box fill entire width or just around text */
- if (!full_redraw)
- rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
+ /* Box fill entire width or just around text. */
+ if (!full_redraw) {
+ const char **text = &text_array[0];
+ while (*text) {
+ rect.xmax = min_ii(rect.xmax, rect.xmin + BLF_width(fontid, *text, BLF_DRAW_STR_DUMMY_MAX) + 1.2f * U.widget_unit);
+ text++;
+ num_lines++;
+ }
+ }
+ /* Just count the line number. */
+ else {
+ const char **text = &text_array[0];
+ while (*text) {
+ text++;
+ num_lines++;
+ }
+ }
+ rect.ymin = BLI_rcti_size_y(&ar->winrct) - header_height * num_lines;
rect.ymax = BLI_rcti_size_y(&ar->winrct);
/* setup scissor */
glGetIntegerv(GL_SCISSOR_BOX, scissor);
- glScissor(ar->winrct.xmin + rect.xmin, ar->winrct.ymin + rect.ymin,
+ glScissor(rect.xmin, rect.ymin,
BLI_rcti_size_x(&rect) + 1, BLI_rcti_size_y(&rect) + 1);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4fv(fill_color);
- glRecti(rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv(fill_color);
+ immRecti(pos, rect.xmin, rect.ymin, rect.xmax + 1, rect.ymax + 1);
+ immUnbindProgram();
glDisable(GL_BLEND);
/* text */
- UI_ThemeColor(TH_TEXT_HI);
+ UI_FontThemeColor(fontid, TH_TEXT_HI);
BLF_clipping(fontid, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
BLF_enable(fontid, BLF_CLIPPING);
- BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit, 0.0f);
-
- BLF_draw(fontid, text, BLF_DRAW_STR_DUMMY_MAX);
+ int offset = num_lines - 1;
+ {
+ const char **text = &text_array[0];
+ while (*text) {
+ BLF_position(fontid, rect.xmin + 0.6f * U.widget_unit, rect.ymin + 0.3f * U.widget_unit + offset * header_height, 0.0f);
+ BLF_draw(fontid, *text, BLF_DRAW_STR_DUMMY_MAX);
+ text++;
+ offset--;
+ }
+ }
BLF_disable(fontid, BLF_CLIPPING);
@@ -2135,6 +2255,11 @@ void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], con
glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
}
+void ED_region_info_draw(ARegion *ar, const char *text, float fill_color[4], const bool full_redraw)
+{
+ ED_region_info_draw_multiline(ar, (const char *[2]){text, NULL}, fill_color, full_redraw);
+}
+
#define MAX_METADATA_STR 1024
static const char *meta_data_list[] =
@@ -2303,11 +2428,11 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
return;
/* find window pixel coordinates of origin */
- glPushMatrix();
+ gpuPushMatrix();
/* offset and zoom using ogl */
- glTranslatef(x, y, 0.0f);
- glScalef(zoomx, zoomy, 1.0f);
+ gpuTranslate2f(x, y);
+ gpuScale2f(zoomx, zoomy);
BLF_size(blf_mono_font, style->widgetlabel.points * 1.5f * U.pixelsize, U.dpi);
@@ -2317,17 +2442,20 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
box_y = metadata_box_height_get(ibuf, blf_mono_font, true);
if (box_y) {
- UI_ThemeColor(TH_METADATA_BG);
-
/* set up rect */
BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymax, frame->ymax + box_y);
/* draw top box */
- glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_METADATA_BG);
+ immRectf(pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+ immUnbindProgram();
BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
BLF_enable(blf_mono_font, BLF_CLIPPING);
- UI_ThemeColor(TH_METADATA_TEXT);
+ UI_FontThemeColor(blf_mono_font, TH_METADATA_TEXT);
metadata_draw_imbuf(ibuf, &rect, blf_mono_font, true);
BLF_disable(blf_mono_font, BLF_CLIPPING);
@@ -2339,23 +2467,26 @@ void ED_region_image_metadata_draw(int x, int y, ImBuf *ibuf, const rctf *frame,
box_y = metadata_box_height_get(ibuf, blf_mono_font, false);
if (box_y) {
- UI_ThemeColor(TH_METADATA_BG);
-
/* set up box rect */
BLI_rctf_init(&rect, frame->xmin, frame->xmax, frame->ymin - box_y, frame->ymin);
/* draw top box */
- glRectf(rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_METADATA_BG);
+ immRectf(pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
+ immUnbindProgram();
BLF_clipping(blf_mono_font, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
BLF_enable(blf_mono_font, BLF_CLIPPING);
- UI_ThemeColor(TH_METADATA_TEXT);
+ UI_FontThemeColor(blf_mono_font, TH_METADATA_TEXT);
metadata_draw_imbuf(ibuf, &rect, blf_mono_font, false);
BLF_disable(blf_mono_font, BLF_CLIPPING);
}
- glPopMatrix();
+ gpuPopMatrix();
}
void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
@@ -2365,11 +2496,16 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
int x1, y1, x2, y2;
/* the image is located inside (0, 0), (1, 1) as set by view2d */
- UI_ThemeColorShade(TH_BACK, 20);
-
UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x1, &y1);
UI_view2d_view_to_region(&ar->v2d, 1.0f, 1.0f, &x2, &y2);
- glRectf(x1, y1, x2, y2);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShade(TH_BACK, 20);
+ immRectf(pos, x1, y1, x2, y2);
+ immUnbindProgram();
/* gridsize adapted to zoom level */
gridsize = 0.5f * (zoomx + zoomy);
@@ -2389,33 +2525,58 @@ void ED_region_grid_draw(ARegion *ar, float zoomx, float zoomy)
}
}
- /* the fine resolution level */
blendfac = 0.25f * gridsize - floorf(0.25f * gridsize);
CLAMP(blendfac, 0.0f, 1.0f);
- UI_ThemeColorShade(TH_BACK, (int)(20.0f * (1.0f - blendfac)));
- fac = 0.0f;
- glBegin(GL_LINES);
- while (fac < 1.0f) {
- glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
- glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
- glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
- glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
- fac += gridstep;
- }
+ int count_fine = 1.0f / gridstep;
+ int count_large = 1.0f / (4.0f * gridstep);
- /* the large resolution level */
- UI_ThemeColor(TH_BACK);
+ if (count_fine > 0) {
+ GWN_vertformat_clear(format);
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GWN_PRIM_LINES, 4 * count_fine + 4 * count_large);
+
+ float theme_color[3];
+ UI_GetThemeColorShade3fv(TH_BACK, (int)(20.0f * (1.0f - blendfac)), theme_color);
+ fac = 0.0f;
+
+ /* the fine resolution level */
+ for (int i = 0; i < count_fine; i++) {
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
+ fac += gridstep;
+ }
- fac = 0.0f;
- while (fac < 1.0f) {
- glVertex2f(x1, y1 * (1.0f - fac) + y2 * fac);
- glVertex2f(x2, y1 * (1.0f - fac) + y2 * fac);
- glVertex2f(x1 * (1.0f - fac) + x2 * fac, y1);
- glVertex2f(x1 * (1.0f - fac) + x2 * fac, y2);
- fac += 4.0f * gridstep;
+ if (count_large > 0) {
+ UI_GetThemeColor3fv(TH_BACK, theme_color);
+ fac = 0.0f;
+
+ /* the large resolution level */
+ for (int i = 0; i < count_large; i++) {
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1, y1 * (1.0f - fac) + y2 * fac);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x2, y1 * (1.0f - fac) + y2 * fac);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y1);
+ immAttrib3fv(color, theme_color);
+ immVertex2f(pos, x1 * (1.0f - fac) + x2 * fac, y2);
+ fac += 4.0f * gridstep;
+ }
+ }
+
+ immEnd();
+ immUnbindProgram();
}
- glEnd();
}
/* If the area has overlapping regions, it returns visible rect for Region *ar */
@@ -2452,8 +2613,11 @@ void ED_region_visible_rect(ARegion *ar, rcti *rect)
void ED_region_cache_draw_background(const ARegion *ar)
{
- glColor4ub(128, 128, 255, 64);
- glRecti(0, 0, ar->winx, 8 * UI_DPI_FAC);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ub(128, 128, 255, 64);
+ immRecti(pos, 0, 0, ar->winx, 8 * UI_DPI_FAC);
+ immUnbindProgram();
}
void ED_region_cache_draw_curfra_label(const int framenr, const float x, const float y)
@@ -2469,9 +2633,13 @@ void ED_region_cache_draw_curfra_label(const int framenr, const float x, const f
BLF_width_and_height(fontid, numstr, sizeof(numstr), &font_dims[0], &font_dims[1]);
- glRecti(x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_CFRAME);
+ immRecti(pos, x, y, x + font_dims[0] + 6.0f, y + font_dims[1] + 4.0f);
+ immUnbindProgram();
- UI_ThemeColor(TH_TEXT);
+ UI_FontThemeColor(fontid, TH_TEXT);
BLF_position(fontid, x + 2.0f, y + 2.0f, 0.0f);
BLF_draw(fontid, numstr, sizeof(numstr));
}
@@ -2479,17 +2647,73 @@ void ED_region_cache_draw_curfra_label(const int framenr, const float x, const f
void ED_region_cache_draw_cached_segments(const ARegion *ar, const int num_segments, const int *points, const int sfra, const int efra)
{
if (num_segments) {
- int a;
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ub(128, 128, 255, 128);
- glColor4ub(128, 128, 255, 128);
+ for (int a = 0; a < num_segments; a++) {
+ float x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
+ float x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
- for (a = 0; a < num_segments; a++) {
- float x1, x2;
+ immRecti(pos, x1, 0, x2, 8 * UI_DPI_FAC);
+ /* TODO(merwin): use primitive restart to draw multiple rects more efficiently */
+ }
- x1 = (float)(points[a * 2] - sfra) / (efra - sfra + 1) * ar->winx;
- x2 = (float)(points[a * 2 + 1] - sfra + 1) / (efra - sfra + 1) * ar->winx;
+ immUnbindProgram();
+ }
+}
- glRecti(x1, 0, x2, 8 * UI_DPI_FAC);
+/**
+ * Generate subscriptions for this region.
+ */
+void ED_region_message_subscribe(
+ bContext *C,
+ struct WorkSpace *workspace, struct Scene *scene,
+ struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ if (ar->manipulator_map != NULL) {
+ WM_manipulatormap_message_subscribe(C, ar->manipulator_map, ar, mbus);
+ }
+
+ if (BLI_listbase_is_empty(&ar->uiblocks)) {
+ UI_region_message_subscribe(ar, mbus);
+ }
+
+ if (ar->type->message_subscribe != NULL) {
+ ar->type->message_subscribe(C, workspace, scene, screen, sa, ar, mbus);
+ }
+}
+
+int ED_region_snap_size_test(const ARegion *ar)
+{
+ /* Use a larger value because toggling scrollbars can jump in size. */
+ const int snap_match_threshold = 16;
+ if (ar->type->snap_size != NULL) {
+ return ((((ar->sizex - ar->type->snap_size(ar, ar->sizex, 0)) <= snap_match_threshold) << 0) |
+ (((ar->sizey - ar->type->snap_size(ar, ar->sizey, 1)) <= snap_match_threshold) << 1));
+ }
+ return 0;
+}
+
+bool ED_region_snap_size_apply(ARegion *ar, int snap_flag)
+{
+ bool changed = false;
+ if (ar->type->snap_size != NULL) {
+ if (snap_flag & (1 << 0)) {
+ short snap_size = ar->type->snap_size(ar, ar->sizex, 0);
+ if (snap_size != ar->sizex) {
+ ar->sizex = snap_size;
+ changed = true;
+ }
+ }
+ if (snap_flag & (1 << 1)) {
+ short snap_size = ar->type->snap_size(ar, ar->sizey, 1);
+ if (snap_size != ar->sizey) {
+ ar->sizey = snap_size;
+ changed = true;
+ }
}
}
+ return changed;
}
diff --git a/source/blender/editors/screen/glutil.c b/source/blender/editors/screen/glutil.c
index 216cbe9d7f4..39178af9e4e 100644
--- a/source/blender/editors/screen/glutil.c
+++ b/source/blender/editors/screen/glutil.c
@@ -49,133 +49,11 @@
#include "IMB_imbuf_types.h"
#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "UI_interface.h"
-#ifndef GL_CLAMP_TO_EDGE
-#define GL_CLAMP_TO_EDGE 0x812F
-#endif
-
-/* UNUSED */
-#if 0
-void fdrawbezier(float vec[4][3])
-{
- float dist;
- float curve_res = 24, spline_step = 0.0f;
-
- dist = 0.5f * fabsf(vec[0][0] - vec[3][0]);
-
- /* check direction later, for top sockets */
- vec[1][0] = vec[0][0] + dist;
- vec[1][1] = vec[0][1];
-
- vec[2][0] = vec[3][0] - dist;
- vec[2][1] = vec[3][1];
- /* we can reuse the dist variable here to increment the GL curve eval amount */
- dist = 1.0f / curve_res;
-
- cpack(0x0);
- glMap1f(GL_MAP1_VERTEX_3, 0.0, 1.0, 3, 4, vec[0]);
- glBegin(GL_LINE_STRIP);
- while (spline_step < 1.000001f) {
-#if 0
- if (do_shaded)
- UI_ThemeColorBlend(th_col1, th_col2, spline_step);
-#endif
- glEvalCoord1f(spline_step);
- spline_step += dist;
- }
- glEnd();
-}
-#endif
-
-void fdrawline(float x1, float y1, float x2, float y2)
-{
- glBegin(GL_LINES);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
- glEnd();
-}
-
-void fdrawbox(float x1, float y1, float x2, float y2)
-{
- glBegin(GL_LINE_LOOP);
-
- glVertex2f(x1, y1);
- glVertex2f(x1, y2);
- glVertex2f(x2, y2);
- glVertex2f(x2, y1);
-
- glEnd();
-}
-
-void fdrawcheckerboard(float x1, float y1, float x2, float y2)
-{
- unsigned char col1[4] = {40, 40, 40}, col2[4] = {50, 50, 50};
-
- glColor3ubv(col1);
- glRectf(x1, y1, x2, y2);
- glColor3ubv(col2);
-
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_CHECKER_8PX);
- glRectf(x1, y1, x2, y2);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-}
-
-void sdrawline(int x1, int y1, int x2, int y2)
-{
- glBegin(GL_LINES);
- glVertex2i(x1, y1);
- glVertex2i(x2, y2);
- glEnd();
-}
-
-/* UNUSED */
-#if 0
-/*
- * x1,y2
- * | \
- * | \
- * | \
- * x1,y1-- x2,y1
- */
-
-static void sdrawtripoints(int x1, int y1, int x2, int y2)
-{
- glVertex2i(x1, y1);
- glVertex2i(x1, y2);
- glVertex2i(x2, y1);
-}
-
-void sdrawtri(int x1, int y1, int x2, int y2)
-{
- glBegin(GL_LINE_STRIP);
- sdrawtripoints(x1, y1, x2, y2);
- glEnd();
-}
-
-void sdrawtrifill(int x1, int y1, int x2, int y2)
-{
- glBegin(GL_TRIANGLES);
- sdrawtripoints(x1, y1, x2, y2);
- glEnd();
-}
-#endif
-
-void sdrawbox(int x1, int y1, int x2, int y2)
-{
- glBegin(GL_LINE_LOOP);
-
- glVertex2i(x1, y1);
- glVertex2i(x1, y2);
- glVertex2i(x2, y2);
- glVertex2i(x2, y1);
-
- glEnd();
-}
-
-
/* ******************************************** */
void setlinestyle(int nr)
@@ -204,122 +82,6 @@ void set_inverted_drawing(int enable)
GL_TOGGLE(GL_DITHER, !enable);
}
-/* UNUSED */
-#if 0
-void sdrawXORline(int x0, int y0, int x1, int y1)
-{
- if (x0 == x1 && y0 == y1) return;
-
- set_inverted_drawing(1);
-
- glBegin(GL_LINES);
- glVertex2i(x0, y0);
- glVertex2i(x1, y1);
- glEnd();
-
- set_inverted_drawing(0);
-}
-
-void sdrawXORline4(int nr, int x0, int y0, int x1, int y1)
-{
- static int old[4][2][2];
- static char flags[4] = {0, 0, 0, 0};
-
- /* with builtin memory, max 4 lines */
-
- set_inverted_drawing(1);
-
- glBegin(GL_LINES);
- if (nr == -1) { /* flush */
- for (nr = 0; nr < 4; nr++) {
- if (flags[nr]) {
- glVertex2iv(old[nr][0]);
- glVertex2iv(old[nr][1]);
- flags[nr] = 0;
- }
- }
- }
- else {
- if (nr >= 0 && nr < 4) {
- if (flags[nr]) {
- glVertex2iv(old[nr][0]);
- glVertex2iv(old[nr][1]);
- }
-
- old[nr][0][0] = x0;
- old[nr][0][1] = y0;
- old[nr][1][0] = x1;
- old[nr][1][1] = y1;
-
- flags[nr] = 1;
- }
-
- glVertex2i(x0, y0);
- glVertex2i(x1, y1);
- }
- glEnd();
-
- set_inverted_drawing(0);
-}
-
-void fdrawXORellipse(float xofs, float yofs, float hw, float hh)
-{
- if (hw == 0) return;
-
- set_inverted_drawing(1);
-
- glPushMatrix();
- glTranslatef(xofs, yofs, 0.0f);
- glScalef(1.0f, hh / hw, 1.0f);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, hw, 20);
- glPopMatrix();
-
- set_inverted_drawing(0);
-}
-
-#endif
-
-void fdrawXORcirc(float xofs, float yofs, float rad)
-{
- set_inverted_drawing(1);
-
- glPushMatrix();
- glTranslatef(xofs, yofs, 0.0);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, rad, 20);
- glPopMatrix();
-
- set_inverted_drawing(0);
-}
-
-void glutil_draw_filled_arc(float start, float angle, float radius, int nsegments)
-{
- int i;
-
- glBegin(GL_TRIANGLE_FAN);
- glVertex2f(0.0, 0.0);
- for (i = 0; i < nsegments; i++) {
- float t = (float) i / (nsegments - 1);
- float cur = start + t * angle;
-
- glVertex2f(cosf(cur) * radius, sinf(cur) * radius);
- }
- glEnd();
-}
-
-void glutil_draw_lined_arc(float start, float angle, float radius, int nsegments)
-{
- int i;
-
- glBegin(GL_LINE_STRIP);
- for (i = 0; i < nsegments; i++) {
- float t = (float) i / (nsegments - 1);
- float cur = start + t * angle;
-
- glVertex2f(cosf(cur) * radius, sinf(cur) * radius);
- }
- glEnd();
-}
-
float glaGetOneFloat(int param)
{
GLfloat v;
@@ -375,25 +137,68 @@ static int get_cached_work_texture(int *r_w, int *r_h)
return texid;
}
-void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
+static void immDrawPixelsTexSetupAttributes(IMMDrawPixelsTexState *state)
+{
+ Gwn_VertFormat *vert_format = immVertexFormat();
+ state->pos = GWN_vertformat_attr_add(vert_format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ state->texco = GWN_vertformat_attr_add(vert_format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+}
+
+/* To be used before calling immDrawPixelsTex
+ * Default shader is GPU_SHADER_2D_IMAGE_COLOR
+ * You can still set uniforms with :
+ * GPU_shader_uniform_int(shader, GPU_shader_get_uniform(shader, "name"), 0);
+ * */
+IMMDrawPixelsTexState immDrawPixelsTexSetup(int builtin)
+{
+ IMMDrawPixelsTexState state;
+ immDrawPixelsTexSetupAttributes(&state);
+
+ state.shader = GPU_shader_get_builtin_shader(builtin);
+
+ /* Shader will be unbind by immUnbindProgram in immDrawPixelsTexScaled_clipping */
+ immBindBuiltinProgram(builtin);
+ immUniform1i("image", 0);
+ state.do_shader_unbind = true;
+
+ return state;
+}
+
+/* Use the currently bound shader.
+ *
+ * Use immDrawPixelsTexSetup to bind the shader you
+ * want before calling immDrawPixelsTex.
+ *
+ * If using a special shader double check it uses the same
+ * attributes "pos" "texCoord" and uniform "image".
+ *
+ * If color is NULL then use white by default
+ *
+ * Be also aware that this function unbinds the shader when
+ * it's finished.
+ * */
+void immDrawPixelsTexScaled_clipping(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h,
int format, int type, int zoomfilter, void *rect,
float scaleX, float scaleY,
float clip_min_x, float clip_min_y,
- float clip_max_x, float clip_max_y)
+ float clip_max_x, float clip_max_y,
+ float xzoom, float yzoom, float color[4])
{
unsigned char *uc_rect = (unsigned char *) rect;
const float *f_rect = (float *)rect;
- float xzoom = glaGetOneFloat(GL_ZOOM_X), yzoom = glaGetOneFloat(GL_ZOOM_Y);
int subpart_x, subpart_y, tex_w, tex_h;
int seamless, offset_x, offset_y, nsubparts_x, nsubparts_y;
int texid = get_cached_work_texture(&tex_w, &tex_h);
int components;
const bool use_clipping = ((clip_min_x < clip_max_x) && (clip_min_y < clip_max_y));
+ float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+
+ GLint unpack_row_length;
+ glGetIntegerv(GL_UNPACK_ROW_LENGTH, &unpack_row_length);
- /* Specify the color outside this function, and tex will modulate it.
- * This is useful for changing alpha without using glPixelTransferf()
- */
glPixelStorei(GL_UNPACK_ROW_LENGTH, img_w);
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texid);
/* don't want nasty border artifacts */
@@ -401,18 +206,12 @@ void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, zoomfilter);
-#if defined(__APPLE__) && 0
- /* [merwin] disable this workaround and see if anyone is affected. If not scrap it! Also at end of this function */
- /* workaround for os x 10.5/10.6 driver bug: http://lists.apple.com/archives/Mac-opengl/2008/Jul/msg00117.html */
- glPixelZoom(1.0f, 1.0f);
-#endif
-
/* setup seamless 2=on, 0=off */
seamless = ((tex_w < img_w || tex_h < img_h) && tex_w > 2 && tex_h > 2) ? 2 : 0;
-
+
offset_x = tex_w - seamless;
offset_y = tex_h - seamless;
-
+
nsubparts_x = (img_w + (offset_x - 1)) / (offset_x);
nsubparts_y = (img_h + (offset_y - 1)) / (offset_y);
@@ -420,7 +219,7 @@ void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
components = 4;
else if (format == GL_RGB)
components = 3;
- else if (ELEM(format, GL_LUMINANCE, GL_ALPHA))
+ else if (format == GL_RED)
components = 1;
else {
BLI_assert(!"Incompatible format passed to glaDrawPixelsTexScaled");
@@ -429,20 +228,23 @@ void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
if (type == GL_FLOAT) {
/* need to set internal format to higher range float */
-
- /* NOTE: this could fail on some drivers, like mesa,
- * but currently this code is only used by color
- * management stuff which already checks on whether
- * it's possible to use GL_RGBA16F_ARB
- */
-
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, tex_w, tex_h, 0, format, GL_FLOAT, NULL);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, tex_w, tex_h, 0, format, GL_FLOAT, NULL);
}
else {
/* switch to 8bit RGBA for byte buffer */
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, tex_w, tex_h, 0, format, GL_UNSIGNED_BYTE, NULL);
}
+ unsigned int pos = state->pos, texco = state->texco;
+
+ /* optional */
+ /* NOTE: Shader could be null for GLSL OCIO drawing, it is fine, since
+ * it does not need color.
+ */
+ if (state->shader != NULL && GPU_shader_get_uniform(state->shader, "color") != -1) {
+ immUniformColor4fv((color) ? color : white);
+ }
+
for (subpart_y = 0; subpart_y < nsubparts_y; subpart_y++) {
for (subpart_x = 0; subpart_x < nsubparts_x; subpart_x++) {
int remainder_x = img_w - subpart_x * offset_x;
@@ -474,7 +276,7 @@ void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
if (type == GL_FLOAT) {
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, format, GL_FLOAT, &f_rect[((size_t)subpart_y) * offset_y * img_w * components + subpart_x * offset_x * components]);
-
+
/* add an extra border of pixels so linear looks ok at edges of full image */
if (subpart_w < tex_w)
glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, 0, 1, subpart_h, format, GL_FLOAT, &f_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]);
@@ -485,7 +287,7 @@ void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
}
else {
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, subpart_w, subpart_h, format, GL_UNSIGNED_BYTE, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + subpart_x * offset_x * components]);
-
+
if (subpart_w < tex_w)
glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, 0, 1, subpart_h, format, GL_UNSIGNED_BYTE, &uc_rect[((size_t)subpart_y) * offset_y * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]);
if (subpart_h < tex_h)
@@ -494,325 +296,55 @@ void glaDrawPixelsTexScaled_clipping(float x, float y, int img_w, int img_h,
glTexSubImage2D(GL_TEXTURE_2D, 0, subpart_w, subpart_h, 1, 1, format, GL_UNSIGNED_BYTE, &uc_rect[(((size_t)subpart_y) * offset_y + subpart_h - 1) * img_w * components + (subpart_x * offset_x + subpart_w - 1) * components]);
}
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
- glBegin(GL_QUADS);
- glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(0 + offset_bot) / tex_h);
- glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)offset_bot * yzoom);
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+ immAttrib2f(texco, (float)(0 + offset_left) / tex_w, (float)(0 + offset_bot) / tex_h);
+ immVertex2f(pos, rast_x + (float)offset_left * xzoom, rast_y + (float)offset_bot * yzoom);
- glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(0 + offset_bot) / tex_h);
- glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)offset_bot * yzoom);
+ immAttrib2f(texco, (float)(subpart_w - offset_right) / tex_w, (float)(0 + offset_bot) / tex_h);
+ immVertex2f(pos, rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)offset_bot * yzoom);
- glTexCoord2f((float)(subpart_w - offset_right) / tex_w, (float)(subpart_h - offset_top) / tex_h);
- glVertex2f(rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);
+ immAttrib2f(texco, (float)(subpart_w - offset_right) / tex_w, (float)(subpart_h - offset_top) / tex_h);
+ immVertex2f(pos, rast_x + (float)(subpart_w - offset_right) * xzoom * scaleX, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);
- glTexCoord2f((float)(0 + offset_left) / tex_w, (float)(subpart_h - offset_top) / tex_h);
- glVertex2f(rast_x + (float)offset_left * xzoom, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);
- glEnd();
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ immAttrib2f(texco, (float)(0 + offset_left) / tex_w, (float)(subpart_h - offset_top) / tex_h);
+ immVertex2f(pos, rast_x + (float)offset_left * xzoom, rast_y + (float)(subpart_h - offset_top) * yzoom * scaleY);
+ immEnd();
}
}
+ if (state->do_shader_unbind) {
+ immUnbindProgram();
+ }
+
glBindTexture(GL_TEXTURE_2D, 0);
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-
-#if defined(__APPLE__) && 0
- /* workaround for os x 10.5/10.6 driver bug (above) */
- glPixelZoom(xzoom, yzoom);
-#endif
+ glPixelStorei(GL_UNPACK_ROW_LENGTH, unpack_row_length);
}
-void glaDrawPixelsTexScaled(float x, float y, int img_w, int img_h,
+void immDrawPixelsTexScaled(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h,
int format, int type, int zoomfilter, void *rect,
- float scaleX, float scaleY)
+ float scaleX, float scaleY, float xzoom, float yzoom, float color[4])
{
- glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect,
- scaleX, scaleY, 0.0f, 0.0f, 0.0f, 0.0f);
+ immDrawPixelsTexScaled_clipping(state, x, y, img_w, img_h, format, type, zoomfilter, rect,
+ scaleX, scaleY, 0.0f, 0.0f, 0.0f, 0.0f, xzoom, yzoom, color);
}
-void glaDrawPixelsTex(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect)
+void immDrawPixelsTex(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect,
+ float xzoom, float yzoom, float color[4])
{
- glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
- 0.0f, 0.0f, 0.0f, 0.0f);
+ immDrawPixelsTexScaled_clipping(state, x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
+ 0.0f, 0.0f, 0.0f, 0.0f, xzoom, yzoom, color);
}
-void glaDrawPixelsTex_clipping(float x, float y, int img_w, int img_h,
+void immDrawPixelsTex_clipping(IMMDrawPixelsTexState *state,
+ float x, float y, int img_w, int img_h,
int format, int type, int zoomfilter, void *rect,
- float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y)
-{
- glaDrawPixelsTexScaled_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
- clip_min_x, clip_min_y, clip_max_x, clip_max_y);
-}
-
-void glaDrawPixelsSafe(float x, float y, int img_w, int img_h, int row_w, int format, int type, void *rect)
-{
- float xzoom = glaGetOneFloat(GL_ZOOM_X);
- float yzoom = glaGetOneFloat(GL_ZOOM_Y);
-
- /* The pixel space coordinate of the intersection of
- * the [zoomed] image with the origin.
- */
- float ix = -x / xzoom;
- float iy = -y / yzoom;
-
- /* The maximum pixel amounts the image can be cropped
- * at the lower left without exceeding the origin.
- */
- int off_x = floor(max_ff(ix, 0.0f));
- int off_y = floor(max_ff(iy, 0.0f));
-
- /* The zoomed space coordinate of the raster position
- * (starting at the lower left most unclipped pixel).
- */
- float rast_x = x + off_x * xzoom;
- float rast_y = y + off_y * yzoom;
-
- GLfloat viewport[4];
- int draw_w, draw_h;
-
- /* Determine the smallest number of pixels we need to draw
- * before the image would go off the upper right corner.
- *
- * It may seem this is just an optimization but some graphics
- * cards (ATI) freak out if there is a large zoom factor and
- * a large number of pixels off the screen (probably at some
- * level the number of image pixels to draw is getting multiplied
- * by the zoom and then clamped). Making sure we draw the
- * fewest pixels possible keeps everyone mostly happy (still
- * fails if we zoom in on one really huge pixel so that it
- * covers the entire screen).
- */
- glGetFloatv(GL_VIEWPORT, viewport);
- draw_w = min_ii(img_w - off_x, ceil((viewport[2] - rast_x) / xzoom));
- draw_h = min_ii(img_h - off_y, ceil((viewport[3] - rast_y) / yzoom));
-
- if (draw_w > 0 && draw_h > 0) {
-
- int bound_options;
- GPU_BASIC_SHADER_DISABLE_AND_STORE(bound_options);
-
- /* Don't use safe RasterPos (slower) if we can avoid it. */
- if (rast_x >= 0 && rast_y >= 0) {
- glRasterPos2f(rast_x, rast_y);
- }
- else {
- glaRasterPosSafe2f(rast_x, rast_y, 0, 0);
- }
-
- glPixelStorei(GL_UNPACK_ROW_LENGTH, row_w);
- if (format == GL_LUMINANCE || format == GL_RED) {
- if (type == GL_FLOAT) {
- const float *f_rect = (float *)rect;
- glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x));
- }
- else if (type == GL_INT || type == GL_UNSIGNED_INT) {
- const int *i_rect = (int *)rect;
- glDrawPixels(draw_w, draw_h, format, type, i_rect + (off_y * row_w + off_x));
- }
- }
- else { /* RGBA */
- if (type == GL_FLOAT) {
- const float *f_rect = (float *)rect;
- glDrawPixels(draw_w, draw_h, format, type, f_rect + (off_y * row_w + off_x) * 4);
- }
- else if (type == GL_UNSIGNED_BYTE) {
- unsigned char *uc_rect = (unsigned char *) rect;
- glDrawPixels(draw_w, draw_h, format, type, uc_rect + (off_y * row_w + off_x) * 4);
- }
- }
-
- glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
-
- GPU_BASIC_SHADER_ENABLE_AND_RESTORE(bound_options);
- }
-}
-
-/* uses either DrawPixelsSafe or DrawPixelsTex, based on user defined maximum */
-void glaDrawPixelsAuto_clipping(float x, float y, int img_w, int img_h,
- int format, int type, int zoomfilter, void *rect,
- float clip_min_x, float clip_min_y,
- float clip_max_x, float clip_max_y)
-{
- if (U.image_draw_method != IMAGE_DRAW_METHOD_DRAWPIXELS) {
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glaDrawPixelsTex_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect,
- clip_min_x, clip_min_y, clip_max_x, clip_max_y);
- }
- else {
- glaDrawPixelsSafe(x, y, img_w, img_h, img_w, format, type, rect);
- }
-}
-
-void glaDrawPixelsAuto(float x, float y, int img_w, int img_h, int format, int type, int zoomfilter, void *rect)
-{
- glaDrawPixelsAuto_clipping(x, y, img_w, img_h, format, type, zoomfilter, rect,
- 0.0f, 0.0f, 0.0f, 0.0f);
-}
-
-/* 2D Drawing Assistance */
-
-void glaDefine2DArea(rcti *screen_rect)
-{
- const int sc_w = BLI_rcti_size_x(screen_rect) + 1;
- const int sc_h = BLI_rcti_size_y(screen_rect) + 1;
-
- glViewport(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h);
- glScissor(screen_rect->xmin, screen_rect->ymin, sc_w, sc_h);
-
- /* The GLA_PIXEL_OFS magic number is to shift the matrix so that
- * both raster and vertex integer coordinates fall at pixel
- * centers properly. For a longer discussion see the OpenGL
- * Programming Guide, Appendix H, Correctness Tips.
- */
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0, sc_w, 0.0, sc_h, -1, 1);
- glTranslatef(GLA_PIXEL_OFS, GLA_PIXEL_OFS, 0.0);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-}
-
-#if 0 /* UNUSED */
-
-struct gla2DDrawInfo {
- int orig_vp[4], orig_sc[4];
- float orig_projmat[16], orig_viewmat[16];
-
- rcti screen_rect;
- rctf world_rect;
-
- float wo_to_sc[2];
-};
-
-void gla2DGetMap(gla2DDrawInfo *di, rctf *rect)
-{
- *rect = di->world_rect;
-}
-
-void gla2DSetMap(gla2DDrawInfo *di, rctf *rect)
-{
- int sc_w, sc_h;
- float wo_w, wo_h;
-
- di->world_rect = *rect;
-
- sc_w = BLI_rcti_size_x(&di->screen_rect);
- sc_h = BLI_rcti_size_y(&di->screen_rect);
- wo_w = BLI_rcti_size_x(&di->world_rect);
- wo_h = BLI_rcti_size_y(&di->world_rect);
-
- di->wo_to_sc[0] = sc_w / wo_w;
- di->wo_to_sc[1] = sc_h / wo_h;
-}
-
-/** Save the current OpenGL state and initialize OpenGL for 2D
- * rendering. glaEnd2DDraw should be called on the returned structure
- * to free it and to return OpenGL to its previous state. The
- * scissor rectangle is set to match the viewport.
- *
- * See glaDefine2DArea for an explanation of why this function uses integers.
- *
- * \param screen_rect The screen rectangle to be used for 2D drawing.
- * \param world_rect The world rectangle that the 2D area represented
- * by \a screen_rect is supposed to represent. If NULL it is assumed the
- * world has a 1 to 1 mapping to the screen.
- */
-gla2DDrawInfo *glaBegin2DDraw(rcti *screen_rect, rctf *world_rect)
-{
- gla2DDrawInfo *di = MEM_mallocN(sizeof(*di), "gla2DDrawInfo");
- int sc_w, sc_h;
- float wo_w, wo_h;
-
- glGetIntegerv(GL_VIEWPORT, (GLint *)di->orig_vp);
- glGetIntegerv(GL_SCISSOR_BOX, (GLint *)di->orig_sc);
- glGetFloatv(GL_PROJECTION_MATRIX, (GLfloat *)di->orig_projmat);
- glGetFloatv(GL_MODELVIEW_MATRIX, (GLfloat *)di->orig_viewmat);
-
- di->screen_rect = *screen_rect;
- if (world_rect) {
- di->world_rect = *world_rect;
- }
- else {
- di->world_rect.xmin = di->screen_rect.xmin;
- di->world_rect.ymin = di->screen_rect.ymin;
- di->world_rect.xmax = di->screen_rect.xmax;
- di->world_rect.ymax = di->screen_rect.ymax;
- }
-
- sc_w = BLI_rcti_size_x(&di->screen_rect);
- sc_h = BLI_rcti_size_y(&di->screen_rect);
- wo_w = BLI_rcti_size_x(&di->world_rect);
- wo_h = BLI_rcti_size_y(&di->world_rect);
-
- di->wo_to_sc[0] = sc_w / wo_w;
- di->wo_to_sc[1] = sc_h / wo_h;
-
- glaDefine2DArea(&di->screen_rect);
-
- return di;
-}
-
-/**
- * Translate the (\a wo_x, \a wo_y) point from world coordinates into screen space.
- */
-void gla2DDrawTranslatePt(gla2DDrawInfo *di, float wo_x, float wo_y, int *r_sc_x, int *r_sc_y)
-{
- *r_sc_x = (wo_x - di->world_rect.xmin) * di->wo_to_sc[0];
- *r_sc_y = (wo_y - di->world_rect.ymin) * di->wo_to_sc[1];
-}
-
-/**
- * Translate the \a world point from world coordinates into screen space.
- */
-void gla2DDrawTranslatePtv(gla2DDrawInfo *di, float world[2], int r_screen[2])
+ float clip_min_x, float clip_min_y, float clip_max_x, float clip_max_y,
+ float xzoom, float yzoom, float color[4])
{
- screen_r[0] = (world[0] - di->world_rect.xmin) * di->wo_to_sc[0];
- screen_r[1] = (world[1] - di->world_rect.ymin) * di->wo_to_sc[1];
-}
-
-/**
- * Restores the previous OpenGL state and frees the auxiliary gla data.
- */
-void glaEnd2DDraw(gla2DDrawInfo *di)
-{
- glViewport(di->orig_vp[0], di->orig_vp[1], di->orig_vp[2], di->orig_vp[3]);
- glScissor(di->orig_vp[0], di->orig_vp[1], di->orig_vp[2], di->orig_vp[3]);
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixf(di->orig_projmat);
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(di->orig_viewmat);
-
- MEM_freeN(di);
-}
-#endif
-
-
-/* Uses current OpenGL state to get view matrices for gluProject/gluUnProject */
-void bgl_get_mats(bglMats *mats)
-{
- const double badvalue = 1.0e-6;
-
- glGetDoublev(GL_MODELVIEW_MATRIX, mats->modelview);
- glGetDoublev(GL_PROJECTION_MATRIX, mats->projection);
- glGetIntegerv(GL_VIEWPORT, (GLint *)mats->viewport);
-
- /* Very strange code here - it seems that certain bad values in the
- * modelview matrix can cause gluUnProject to give bad results. */
- if (mats->modelview[0] < badvalue &&
- mats->modelview[0] > -badvalue)
- {
- mats->modelview[0] = 0;
- }
- if (mats->modelview[5] < badvalue &&
- mats->modelview[5] > -badvalue)
- {
- mats->modelview[5] = 0;
- }
-
- /* Set up viewport so that gluUnProject will give correct values */
- mats->viewport[0] = 0;
- mats->viewport[1] = 0;
+ immDrawPixelsTexScaled_clipping(state, x, y, img_w, img_h, format, type, zoomfilter, rect, 1.0f, 1.0f,
+ clip_min_x, clip_min_y, clip_max_x, clip_max_y, xzoom, yzoom, color);
}
/* *************** glPolygonOffset hack ************* */
@@ -831,8 +363,7 @@ void bglPolygonOffset(float viewdist, float dist)
// glPolygonOffset(-1.0, -1.0);
/* hack below is to mimic polygon offset */
- glMatrixMode(GL_PROJECTION);
- glGetFloatv(GL_PROJECTION_MATRIX, (float *)winmat);
+ gpuGetProjectionMatrix(winmat);
/* dist is from camera to center point */
@@ -863,17 +394,13 @@ void bglPolygonOffset(float viewdist, float dist)
winmat[14] -= offs;
offset += offs;
-
- glLoadMatrixf(winmat);
- glMatrixMode(GL_MODELVIEW);
}
else {
- glMatrixMode(GL_PROJECTION);
winmat[14] += offset;
offset = 0.0;
- glLoadMatrixf(winmat);
- glMatrixMode(GL_MODELVIEW);
}
+
+ gpuLoadProjectionMatrix(winmat);
}
/* **** Color management helper functions for GLSL display/transform ***** */
@@ -883,7 +410,8 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
ColorManagedViewSettings *view_settings,
ColorManagedDisplaySettings *display_settings,
float clip_min_x, float clip_min_y,
- float clip_max_x, float clip_max_y)
+ float clip_max_x, float clip_max_y,
+ float zoom_x, float zoom_y)
{
bool force_fallback = false;
bool need_fallback = true;
@@ -902,6 +430,11 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
if (force_fallback == false) {
int ok;
+ IMMDrawPixelsTexState state = {0};
+ /* We want GLSL state to be fully handled by OCIO. */
+ state.do_shader_unbind = false;
+ immDrawPixelsTexSetupAttributes(&state);
+
if (ibuf->rect_float) {
if (ibuf->float_colorspace) {
ok = IMB_colormanagement_setup_glsl_draw_from_space(view_settings, display_settings,
@@ -920,8 +453,6 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
}
if (ok) {
- glColor4f(1.0, 1.0, 1.0, 1.0);
-
if (ibuf->rect_float) {
int format = 0;
@@ -933,16 +464,20 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
BLI_assert(!"Incompatible number of channels for GLSL display");
if (format != 0) {
- glaDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, format, GL_FLOAT,
+ immDrawPixelsTex_clipping(&state,
+ x, y, ibuf->x, ibuf->y, format, GL_FLOAT,
zoomfilter, ibuf->rect_float,
- clip_min_x, clip_min_y, clip_max_x, clip_max_y);
+ clip_min_x, clip_min_y, clip_max_x, clip_max_y,
+ zoom_x, zoom_y, NULL);
}
}
else if (ibuf->rect) {
/* ibuf->rect is always RGBA */
- glaDrawPixelsTex_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
+ immDrawPixelsTex_clipping(&state,
+ x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
zoomfilter, ibuf->rect,
- clip_min_x, clip_min_y, clip_max_x, clip_max_y);
+ clip_min_x, clip_min_y, clip_max_x, clip_max_y,
+ zoom_x, zoom_y, NULL);
}
IMB_colormanagement_finish_glsl_draw();
@@ -959,9 +494,12 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
if (display_buffer) {
- glaDrawPixelsAuto_clipping(x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
- zoomfilter, display_buffer,
- clip_min_x, clip_min_y, clip_max_x, clip_max_y);
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex_clipping(&state,
+ x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE,
+ zoomfilter, display_buffer,
+ clip_min_x, clip_min_y, clip_max_x, clip_max_y,
+ zoom_x, zoom_y, NULL);
}
IMB_display_buffer_release(cache_handle);
@@ -970,10 +508,11 @@ void glaDrawImBuf_glsl_clipping(ImBuf *ibuf, float x, float y, int zoomfilter,
void glaDrawImBuf_glsl(ImBuf *ibuf, float x, float y, int zoomfilter,
ColorManagedViewSettings *view_settings,
- ColorManagedDisplaySettings *display_settings)
+ ColorManagedDisplaySettings *display_settings,
+ float zoom_x, float zoom_y)
{
glaDrawImBuf_glsl_clipping(ibuf, x, y, zoomfilter, view_settings, display_settings,
- 0.0f, 0.0f, 0.0f, 0.0f);
+ 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y);
}
void glaDrawImBuf_glsl_ctx_clipping(const bContext *C,
@@ -981,7 +520,8 @@ void glaDrawImBuf_glsl_ctx_clipping(const bContext *C,
float x, float y,
int zoomfilter,
float clip_min_x, float clip_min_y,
- float clip_max_x, float clip_max_y)
+ float clip_max_x, float clip_max_y,
+ float zoom_x, float zoom_y)
{
ColorManagedViewSettings *view_settings;
ColorManagedDisplaySettings *display_settings;
@@ -989,22 +529,19 @@ void glaDrawImBuf_glsl_ctx_clipping(const bContext *C,
IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
glaDrawImBuf_glsl_clipping(ibuf, x, y, zoomfilter, view_settings, display_settings,
- clip_min_x, clip_min_y, clip_max_x, clip_max_y);
-}
-
-void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int zoomfilter)
-{
- glaDrawImBuf_glsl_ctx_clipping(C, ibuf, x, y, zoomfilter, 0.0f, 0.0f, 0.0f, 0.0f);
+ clip_min_x, clip_min_y, clip_max_x, clip_max_y,
+ zoom_x, zoom_y);
}
-void cpack(unsigned int x)
+void glaDrawImBuf_glsl_ctx(const bContext *C, ImBuf *ibuf, float x, float y, int zoomfilter,
+ float zoom_x, float zoom_y)
{
- glColor3ub(( (x) & 0xFF),
- (((x) >> 8) & 0xFF),
- (((x) >> 16) & 0xFF));
+ glaDrawImBuf_glsl_ctx_clipping(C, ibuf, x, y, zoomfilter, 0.0f, 0.0f, 0.0f, 0.0f, zoom_x, zoom_y);
}
-void glaDrawBorderCorners(const rcti *border, float zoomx, float zoomy)
+/* don't move to GPU_immediate_util.h because this uses user-prefs
+ * and isn't very low level */
+void immDrawBorderCorners(unsigned int pos, const rcti *border, float zoomx, float zoomy)
{
float delta_x = 4.0f * UI_DPI_FAC / zoomx;
float delta_y = 4.0f * UI_DPI_FAC / zoomy;
@@ -1013,30 +550,30 @@ void glaDrawBorderCorners(const rcti *border, float zoomx, float zoomy)
delta_y = min_ff(delta_y, border->ymax - border->ymin);
/* left bottom corner */
- glBegin(GL_LINE_STRIP);
- glVertex2f(border->xmin, border->ymin + delta_y);
- glVertex2f(border->xmin, border->ymin);
- glVertex2f(border->xmin + delta_x, border->ymin);
- glEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, border->xmin, border->ymin + delta_y);
+ immVertex2f(pos, border->xmin, border->ymin);
+ immVertex2f(pos, border->xmin + delta_x, border->ymin);
+ immEnd();
/* left top corner */
- glBegin(GL_LINE_STRIP);
- glVertex2f(border->xmin, border->ymax - delta_y);
- glVertex2f(border->xmin, border->ymax);
- glVertex2f(border->xmin + delta_x, border->ymax);
- glEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, border->xmin, border->ymax - delta_y);
+ immVertex2f(pos, border->xmin, border->ymax);
+ immVertex2f(pos, border->xmin + delta_x, border->ymax);
+ immEnd();
/* right bottom corner */
- glBegin(GL_LINE_STRIP);
- glVertex2f(border->xmax - delta_x, border->ymin);
- glVertex2f(border->xmax, border->ymin);
- glVertex2f(border->xmax, border->ymin + delta_y);
- glEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, border->xmax - delta_x, border->ymin);
+ immVertex2f(pos, border->xmax, border->ymin);
+ immVertex2f(pos, border->xmax, border->ymin + delta_y);
+ immEnd();
/* right top corner */
- glBegin(GL_LINE_STRIP);
- glVertex2f(border->xmax - delta_x, border->ymax);
- glVertex2f(border->xmax, border->ymax);
- glVertex2f(border->xmax, border->ymax - delta_y);
- glEnd();
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2f(pos, border->xmax - delta_x, border->ymax);
+ immVertex2f(pos, border->xmax, border->ymax);
+ immVertex2f(pos, border->xmax, border->ymax - delta_y);
+ immEnd();
}
diff --git a/source/blender/editors/screen/screen_context.c b/source/blender/editors/screen/screen_context.c
index e714e095ef9..85087d58276 100644
--- a/source/blender/editors/screen/screen_context.c
+++ b/source/blender/editors/screen/screen_context.c
@@ -30,6 +30,8 @@
#include <stdlib.h>
#include <string.h>
+#include "MEM_guardedalloc.h"
+
#include "DNA_object_types.h"
#include "DNA_armature_types.h"
#include "DNA_gpencil_types.h"
@@ -38,17 +40,21 @@
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_utildefines.h"
-
#include "BKE_context.h"
#include "BKE_object.h"
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_gpencil.h"
+#include "BKE_layer.h"
#include "BKE_screen.h"
#include "BKE_sequencer.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
#include "RNA_access.h"
@@ -61,20 +67,8 @@
#include "screen_intern.h"
-static unsigned int context_layers(bScreen *sc, Scene *scene, ScrArea *sa_ctx)
-{
- /* needed for 'USE_ALLSELECT' define, otherwise we end up editing off-screen layers. */
- if (sc && sa_ctx && (sa_ctx->spacetype == SPACE_BUTS)) {
- const unsigned int lay = BKE_screen_view3d_layer_all(sc);
- if (lay) {
- return lay;
- }
- }
- return scene->lay;
-}
-
const char *screen_context_dir[] = {
- "scene", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
+ "scene", "view_layer", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
"selected_objects", "selected_bases",
"editable_objects", "editable_bases",
"selected_editable_objects", "selected_editable_bases",
@@ -93,20 +87,14 @@ const char *screen_context_dir[] = {
int ed_screen_context(const bContext *C, const char *member, bContextDataResult *result)
{
+ wmWindow *win = CTX_wm_window(C);
bScreen *sc = CTX_wm_screen(C);
ScrArea *sa = CTX_wm_area(C);
- Scene *scene = sc->scene;
- Base *base;
-
-#if 0 /* Using the context breaks adding objects in the UI. Need to find out why - campbell */
- Object *obact = CTX_data_active_object(C);
- Object *obedit = CTX_data_edit_object(C);
- base = CTX_data_active_base(C);
-#else
- Object *obedit = scene->obedit;
- Object *obact = OBACT;
- base = BASACT;
-#endif
+ Scene *scene = WM_window_get_active_scene(win);
+ WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+ ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
+ Object *obact = (view_layer && view_layer->basact) ? view_layer->basact->object : NULL;
+ Object *obedit = view_layer ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL;
if (CTX_data_dir(member)) {
CTX_data_dir_set(result, screen_context_dir);
@@ -116,84 +104,100 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
CTX_data_id_pointer_set(result, &scene->id);
return 1;
}
- else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) {
- const unsigned int lay = context_layers(sc, scene, sa);
- const bool visible_objects = CTX_data_equals(member, "visible_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) && (base->lay & lay)) {
- if (visible_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
+ else if (CTX_data_equals(member, "visible_objects")) {
+ FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, ob)
+ {
+ CTX_data_id_list_add(result, &ob->id);
+ }
+ FOREACH_VISIBLE_BASE_END;
+ CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
+ return 1;
+ }
+ else if (CTX_data_equals(member, "selectable_objects")) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (((base->flag & BASE_VISIBLED) != 0) && ((base->flag & BASE_SELECTABLED) != 0)) {
+ CTX_data_id_list_add(result, &base->object->id);
}
}
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
}
- else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) {
- const unsigned int lay = context_layers(sc, scene, sa);
- const bool selectable_objects = CTX_data_equals(member, "selectable_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if (base->lay & lay) {
- if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) {
- if (selectable_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
- }
+ else if (CTX_data_equals(member, "selected_objects")) {
+ FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
+ {
+ CTX_data_id_list_add(result, &ob->id);
+ }
+ FOREACH_SELECTED_OBJECT_END;
+ CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
+ return 1;
+ }
+ else if (CTX_data_equals(member, "selected_editable_objects")) {
+ FOREACH_SELECTED_OBJECT_BEGIN(view_layer, ob)
+ {
+ if (0 == BKE_object_is_libdata(ob)) {
+ CTX_data_id_list_add(result, &ob->id);
}
}
+ FOREACH_SELECTED_OBJECT_END;
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
}
- else if (CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
- const unsigned int lay = context_layers(sc, scene, sa);
- const bool selected_objects = CTX_data_equals(member, "selected_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if ((base->flag & SELECT) && (base->lay & lay)) {
- if (selected_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
+ else if (CTX_data_equals(member, "editable_objects")) {
+ /* Visible + Editable, but not necessarily selected */
+ FOREACH_VISIBLE_OBJECT_BEGIN(view_layer, ob)
+ {
+ if (0 == BKE_object_is_libdata(ob)) {
+ CTX_data_id_list_add(result, &ob->id);
}
}
+ FOREACH_VISIBLE_OBJECT_END;
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
}
- else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
- const unsigned int lay = context_layers(sc, scene, sa);
- const bool selected_editable_objects = CTX_data_equals(member, "selected_editable_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if ((base->flag & SELECT) && (base->lay & lay)) {
- if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
- if (0 == BKE_object_is_libdata(base->object)) {
- if (selected_editable_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
- }
+ else if ( CTX_data_equals(member, "visible_bases")) {
+ FOREACH_VISIBLE_BASE_BEGIN(view_layer, base)
+ {
+ CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
+ }
+ FOREACH_VISIBLE_BASE_END;
+ CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
+ return 1;
+ }
+ else if (CTX_data_equals(member, "selectable_bases")) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if ((base->flag & BASE_SELECTABLED) != 0) {
+ CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
+ }
+ }
+ CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
+ return 1;
+ }
+ else if (CTX_data_equals(member, "selected_bases")) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if ((base->flag & BASE_SELECTED) != 0) {
+ CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
+ }
+ }
+ CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
+ return 1;
+ }
+ else if (CTX_data_equals(member, "selected_editable_bases")) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if ((base->flag & BASE_SELECTED) != 0) {
+ if (0 == BKE_object_is_libdata(base->object)) {
+ CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
}
}
}
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
}
- else if (CTX_data_equals(member, "editable_objects") || CTX_data_equals(member, "editable_bases")) {
- const unsigned int lay = context_layers(sc, scene, sa);
- const bool editable_objects = CTX_data_equals(member, "editable_objects");
-
+ else if (CTX_data_equals(member, "editable_bases")) {
/* Visible + Editable, but not necessarily selected */
- for (base = scene->base.first; base; base = base->next) {
- if (((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) && (base->lay & lay)) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if ((base->flag & BASE_VISIBLED) != 0) {
if (0 == BKE_object_is_libdata(base->object)) {
- if (editable_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
+ CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
}
}
}
@@ -206,38 +210,47 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
const bool editable_bones = CTX_data_equals(member, "editable_bones");
if (arm && arm->edbo) {
- /* Attention: X-Axis Mirroring is also handled here... */
- for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
- /* first and foremost, bone must be visible and selected */
- if (EBONE_VISIBLE(arm, ebone)) {
- /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
- * so that most users of this data don't need to explicitly check for it themselves.
- *
- * We need to make sure that these mirrored copies are not selected, otherwise some
- * bones will be operated on twice.
- */
- if (arm->flag & ARM_MIRROR_EDIT)
- flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
-
- /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
- if (editable_bones) {
- /* only selected + editable */
- if (EBONE_EDITABLE(ebone)) {
+ uint objects_len;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ arm = ob->data;
+
+ /* Attention: X-Axis Mirroring is also handled here... */
+ for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+ /* first and foremost, bone must be visible and selected */
+ if (EBONE_VISIBLE(arm, ebone)) {
+ /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
+ * so that most users of this data don't need to explicitly check for it themselves.
+ *
+ * We need to make sure that these mirrored copies are not selected, otherwise some
+ * bones will be operated on twice.
+ */
+ if (arm->flag & ARM_MIRROR_EDIT)
+ flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
+
+ /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
+ if (editable_bones) {
+ /* only selected + editable */
+ if (EBONE_EDITABLE(ebone)) {
+ CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
+
+ if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
+ CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
+ }
+ }
+ else {
+ /* only include bones if visible */
CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
-
- if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
+
+ if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0)
CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
}
}
- else {
- /* only include bones if visible */
- CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
-
- if ((flipbone) && EBONE_VISIBLE(arm, flipbone) == 0)
- CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
- }
}
}
+ MEM_freeN(objects);
+
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
}
@@ -248,53 +261,65 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
const bool selected_editable_bones = CTX_data_equals(member, "selected_editable_bones");
if (arm && arm->edbo) {
- /* Attention: X-Axis Mirroring is also handled here... */
- for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
- /* first and foremost, bone must be visible and selected */
- if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) {
- /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
- * so that most users of this data don't need to explicitly check for it themselves.
- *
- * We need to make sure that these mirrored copies are not selected, otherwise some
- * bones will be operated on twice.
- */
- if (arm->flag & ARM_MIRROR_EDIT)
- flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
-
- /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
- if (selected_editable_bones) {
- /* only selected + editable */
- if (EBONE_EDITABLE(ebone)) {
+ uint objects_len;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+ for (uint i = 0; i < objects_len; i++) {
+ Object *ob = objects[i];
+ arm = ob->data;
+
+ /* Attention: X-Axis Mirroring is also handled here... */
+ for (ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+ /* first and foremost, bone must be visible and selected */
+ if (EBONE_VISIBLE(arm, ebone) && (ebone->flag & BONE_SELECTED)) {
+ /* Get 'x-axis mirror equivalent' bone if the X-Axis Mirroring option is enabled
+ * so that most users of this data don't need to explicitly check for it themselves.
+ *
+ * We need to make sure that these mirrored copies are not selected, otherwise some
+ * bones will be operated on twice.
+ */
+ if (arm->flag & ARM_MIRROR_EDIT)
+ flipbone = ED_armature_ebone_get_mirrored(arm->edbo, ebone);
+
+ /* if we're filtering for editable too, use the check for that instead, as it has selection check too */
+ if (selected_editable_bones) {
+ /* only selected + editable */
+ if (EBONE_EDITABLE(ebone)) {
+ CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
+
+ if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
+ CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
+ }
+ }
+ else {
+ /* only include bones if selected */
CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
-
+
if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
}
}
- else {
- /* only include bones if selected */
- CTX_data_list_add(result, &arm->id, &RNA_EditBone, ebone);
-
- if ((flipbone) && !(flipbone->flag & BONE_SELECTED))
- CTX_data_list_add(result, &arm->id, &RNA_EditBone, flipbone);
- }
}
}
+ MEM_freeN(objects);
+
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
}
}
else if (CTX_data_equals(member, "visible_pose_bones")) {
Object *obpose = BKE_object_pose_armature_get(obact);
- bArmature *arm = (obpose) ? obpose->data : NULL;
- bPoseChannel *pchan;
-
- if (obpose && obpose->pose && arm) {
- for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) {
- /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
- if (PBONE_VISIBLE(arm, pchan->bone)) {
+ if (obpose && obpose->pose && obpose->data) {
+ if (obpose != obact) {
+ FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (obpose, pchan) {
CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
- }
+ } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
+ }
+ else if (obact->mode & OB_MODE_POSE) {
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob_iter) {
+ FOREACH_PCHAN_VISIBLE_IN_OBJECT_BEGIN (ob_iter, pchan) {
+ CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
+ } FOREACH_PCHAN_VISIBLE_IN_OBJECT_END;
+ } FOREACH_OBJECT_IN_MODE_END;
}
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
@@ -302,16 +327,18 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
}
else if (CTX_data_equals(member, "selected_pose_bones")) {
Object *obpose = BKE_object_pose_armature_get(obact);
- bArmature *arm = (obpose) ? obpose->data : NULL;
- bPoseChannel *pchan;
-
- if (obpose && obpose->pose && arm) {
- for (pchan = obpose->pose->chanbase.first; pchan; pchan = pchan->next) {
- /* ensure that PoseChannel is on visible layer and is not hidden in PoseMode */
- if (PBONE_VISIBLE(arm, pchan->bone)) {
- if (pchan->bone->flag & BONE_SELECTED)
- CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
- }
+ if (obpose && obpose->pose && obpose->data) {
+ if (obpose != obact) {
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (obpose, pchan) {
+ CTX_data_list_add(result, &obpose->id, &RNA_PoseBone, pchan);
+ } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
+ }
+ else if (obact->mode & OB_MODE_POSE) {
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer, OB_MODE_POSE, ob_iter) {
+ FOREACH_PCHAN_SELECTED_IN_OBJECT_BEGIN (ob_iter, pchan) {
+ CTX_data_list_add(result, &ob_iter->id, &RNA_PoseBone, pchan);
+ } FOREACH_PCHAN_SELECTED_IN_OBJECT_END;
+ } FOREACH_OBJECT_IN_MODE_END;
}
CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
return 1;
@@ -345,8 +372,8 @@ int ed_screen_context(const bContext *C, const char *member, bContextDataResult
}
}
else if (CTX_data_equals(member, "active_base")) {
- if (base)
- CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, base);
+ if (view_layer->basact)
+ CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact);
return 1;
}
diff --git a/source/blender/editors/screen/screen_draw.c b/source/blender/editors/screen/screen_draw.c
index e67ae4e321c..fec39ade110 100644
--- a/source/blender/editors/screen/screen_draw.c
+++ b/source/blender/editors/screen/screen_draw.c
@@ -22,18 +22,26 @@
* \ingroup edscr
*/
-#include "BIF_gl.h"
+#include "ED_screen.h"
+
+#include "GPU_framebuffer.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
+#include "BLI_math.h"
#include "WM_api.h"
+#include "WM_types.h"
-#include "ED_screen.h"
+#include "UI_interface.h"
+#include "UI_resources.h"
#include "screen_intern.h"
/**
* Draw horizontal shape visualizing future joining (left as well right direction of future joining).
*/
-static void draw_horizontal_join_shape(ScrArea *sa, char dir)
+static void draw_horizontal_join_shape(ScrArea *sa, char dir, unsigned int pos)
{
vec2f points[10];
short i;
@@ -90,24 +98,31 @@ static void draw_horizontal_join_shape(ScrArea *sa, char dir)
}
}
- glBegin(GL_POLYGON);
- for (i = 0; i < 5; i++)
- glVertex2f(points[i].x, points[i].y);
- glEnd();
- glBegin(GL_POLYGON);
- for (i = 4; i < 8; i++)
- glVertex2f(points[i].x, points[i].y);
- glVertex2f(points[0].x, points[0].y);
- glEnd();
-
- glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
- glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
+ immBegin(GWN_PRIM_TRI_FAN, 5);
+
+ for (i = 0; i < 5; i++) {
+ immVertex2f(pos, points[i].x, points[i].y);
+ }
+
+ immEnd();
+
+ immBegin(GWN_PRIM_TRI_FAN, 5);
+
+ for (i = 4; i < 8; i++) {
+ immVertex2f(pos, points[i].x, points[i].y);
+ }
+
+ immVertex2f(pos, points[0].x, points[0].y);
+ immEnd();
+
+ immRectf(pos, points[2].x, points[2].y, points[8].x, points[8].y);
+ immRectf(pos, points[6].x, points[6].y, points[9].x, points[9].y);
}
/**
* Draw vertical shape visualizing future joining (up/down direction).
*/
-static void draw_vertical_join_shape(ScrArea *sa, char dir)
+static void draw_vertical_join_shape(ScrArea *sa, char dir, unsigned int pos)
{
vec2f points[10];
short i;
@@ -144,7 +159,7 @@ static void draw_vertical_join_shape(ScrArea *sa, char dir)
points[6].x = sa->v4->vec.x;
points[6].y = sa->v4->vec.y + h;
-
+
points[7].x = sa->v3->vec.x;
points[7].y = sa->v3->vec.y;
@@ -164,93 +179,252 @@ static void draw_vertical_join_shape(ScrArea *sa, char dir)
}
}
- glBegin(GL_POLYGON);
- for (i = 0; i < 5; i++)
- glVertex2f(points[i].x, points[i].y);
- glEnd();
- glBegin(GL_POLYGON);
- for (i = 4; i < 8; i++)
- glVertex2f(points[i].x, points[i].y);
- glVertex2f(points[0].x, points[0].y);
- glEnd();
-
- glRectf(points[2].x, points[2].y, points[8].x, points[8].y);
- glRectf(points[6].x, points[6].y, points[9].x, points[9].y);
+ immBegin(GWN_PRIM_TRI_FAN, 5);
+
+ for (i = 0; i < 5; i++) {
+ immVertex2f(pos, points[i].x, points[i].y);
+ }
+
+ immEnd();
+
+ immBegin(GWN_PRIM_TRI_FAN, 5);
+
+ for (i = 4; i < 8; i++) {
+ immVertex2f(pos, points[i].x, points[i].y);
+ }
+
+ immVertex2f(pos, points[0].x, points[0].y);
+ immEnd();
+
+ immRectf(pos, points[2].x, points[2].y, points[8].x, points[8].y);
+ immRectf(pos, points[6].x, points[6].y, points[9].x, points[9].y);
}
/**
* Draw join shape due to direction of joining.
*/
-static void draw_join_shape(ScrArea *sa, char dir)
+static void draw_join_shape(ScrArea *sa, char dir, unsigned int pos)
{
if (dir == 'u' || dir == 'd') {
- draw_vertical_join_shape(sa, dir);
+ draw_vertical_join_shape(sa, dir, pos);
+ }
+ else {
+ draw_horizontal_join_shape(sa, dir, pos);
+ }
+}
+
+#define CORNER_RESOLUTION 10
+static void drawscredge_corner_geometry(
+ int sizex, int sizey,
+ int corner_x, int corner_y,
+ int center_x, int center_y,
+ double angle_offset,
+ const float *color)
+{
+ const int radius = ABS(corner_x - center_x);
+ const int line_thickness = U.pixelsize;
+
+ if (corner_x < center_x) {
+ if (corner_x > 0.0f) {
+ /* Left (internal) edge. */
+ corner_x += line_thickness;
+ center_x += line_thickness;
+ }
+ }
+ else {
+ /* Right (internal) edge. */
+ if (corner_x < sizex - 1) {
+ corner_x += 1 - line_thickness;
+ center_x += 1 - line_thickness;
+ }
+ else {
+ /* Corner case, extreme right edge. */
+ corner_x += 1;
+ center_x += 1;
+ }
+ }
+
+ if (corner_y < center_y) {
+ if (corner_y > 0.0f) {
+ /* Bottom (internal) edge. */
+ corner_y += line_thickness;
+ center_y += line_thickness;
+ }
}
else {
- draw_horizontal_join_shape(sa, dir);
+ /* Top (internal) edge. */
+ if (corner_y < sizey) {
+ corner_y += 1 - line_thickness;
+ center_y += 1 - line_thickness;
+ }
}
+
+ float tri_array[CORNER_RESOLUTION + 1][2];
+
+ tri_array[0][0] = corner_x;
+ tri_array[0][1] = corner_y;
+
+ for (int i = 0; i < CORNER_RESOLUTION; i++) {
+ double angle = angle_offset + (M_PI_2 * ((float)i / (CORNER_RESOLUTION - 1)));
+ float x = center_x + (radius * cos(angle));
+ float y = center_y + (radius * sin(angle));
+ tri_array[i + 1][0] = x;
+ tri_array[i + 1][1] = y;
+ }
+
+ UI_draw_anti_fan(tri_array, CORNER_RESOLUTION + 1, color);
+}
+
+#undef CORNER_RESOLUTION
+
+static void drawscredge_corner(ScrArea *sa, int sizex, int sizey)
+{
+ int size = 10 * U.pixelsize;
+ float color[4] = {0};
+ UI_GetThemeColor4fv(TH_EDITOR_OUTLINE, color);
+
+ /* Bottom-Left. */
+ drawscredge_corner_geometry(sizex, sizey,
+ sa->v1->vec.x,
+ sa->v1->vec.y,
+ sa->v1->vec.x + size,
+ sa->v1->vec.y + size,
+ M_PI_2 * 2.0f,
+ color);
+
+ /* Top-Left. */
+ drawscredge_corner_geometry(sizex, sizey,
+ sa->v2->vec.x,
+ sa->v2->vec.y,
+ sa->v2->vec.x + size,
+ sa->v2->vec.y - size,
+ M_PI_2,
+ color);
+
+ /* Top-Right. */
+ drawscredge_corner_geometry(sizex, sizey,
+ sa->v3->vec.x,
+ sa->v3->vec.y,
+ sa->v3->vec.x - size,
+ sa->v3->vec.y - size,
+ 0.0f,
+ color);
+
+ /* Bottom-Right. */
+ drawscredge_corner_geometry(sizex, sizey,
+ sa->v4->vec.x,
+ sa->v4->vec.y,
+ sa->v4->vec.x - size,
+ sa->v4->vec.y + size,
+ M_PI_2 * 3.0f,
+ color);
+
+ /* Wrap up the corners with a nice embossing. */
+ rcti rect = sa->totrct;
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4fv(color);
+ immBeginAtMost(GWN_PRIM_LINES, 8);
+
+ /* Right. */
+ immVertex2f(pos, rect.xmax, rect.ymax);
+ immVertex2f(pos, rect.xmax, rect.ymin);
+
+ /* Bottom. */
+ immVertex2f(pos, rect.xmax, rect.ymin);
+ immVertex2f(pos, rect.xmin, rect.ymin);
+
+ /* Left. */
+ immVertex2f(pos, rect.xmin, rect.ymin);
+ immVertex2f(pos, rect.xmin, rect.ymax);
+
+ /* Top. */
+ immVertex2f(pos, rect.xmin, rect.ymax);
+ immVertex2f(pos, rect.xmax, rect.ymax);
+
+ immEnd();
+ immUnbindProgram();
}
/**
* Draw screen area darker with arrow (visualization of future joining).
*/
-static void scrarea_draw_shape_dark(ScrArea *sa, char dir)
+static void scrarea_draw_shape_dark(ScrArea *sa, char dir, unsigned int pos)
{
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4ub(0, 0, 0, 50);
- draw_join_shape(sa, dir);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ immUniformColor4ub(0, 0, 0, 50);
+
+ draw_join_shape(sa, dir, pos);
}
/**
* Draw screen area ligher with arrow shape ("eraser" of previous dark shape).
*/
-static void scrarea_draw_shape_light(ScrArea *sa, char UNUSED(dir))
+static void scrarea_draw_shape_light(ScrArea *sa, char UNUSED(dir), unsigned int pos)
{
glBlendFunc(GL_DST_COLOR, GL_SRC_ALPHA);
/* value 181 was hardly computed: 181~105 */
- glColor4ub(255, 255, 255, 50);
+ immUniformColor4ub(255, 255, 255, 50);
/* draw_join_shape(sa, dir); */
- glRecti(sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y);
+
+ immRectf(pos, sa->v1->vec.x, sa->v1->vec.y, sa->v3->vec.x, sa->v3->vec.y);
}
-static void drawscredge_area_draw(int sizex, int sizey, short x1, short y1, short x2, short y2)
+static void drawscredge_area_draw(int sizex, int sizey, short x1, short y1, short x2, short y2, unsigned int pos)
{
+ int count = 0;
+
+ if (x2 < sizex - 1) count += 2;
+ if (x1 > 0) count += 2;
+ if (y2 < sizey - 1) count += 2;
+ if (y1 > 0) count += 2;
+
+ if (count == 0) {
+ return;
+ }
+
+ immBegin(GWN_PRIM_LINES, count);
+
/* right border area */
if (x2 < sizex - 1) {
- glVertex2s(x2, y1);
- glVertex2s(x2, y2);
+ immVertex2f(pos, x2, y1);
+ immVertex2f(pos, x2, y2);
}
/* left border area */
if (x1 > 0) { /* otherwise it draws the emboss of window over */
- glVertex2s(x1, y1);
- glVertex2s(x1, y2);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x1, y2);
}
/* top border area */
if (y2 < sizey - 1) {
- glVertex2s(x1, y2);
- glVertex2s(x2, y2);
+ immVertex2f(pos, x1, y2);
+ immVertex2f(pos, x2, y2);
}
/* bottom border area */
if (y1 > 0) {
- glVertex2s(x1, y1);
- glVertex2s(x2, y1);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x2, y1);
}
+
+ immEnd();
}
/**
* \brief Screen edges drawing.
*/
-static void drawscredge_area(ScrArea *sa, int sizex, int sizey)
+static void drawscredge_area(ScrArea *sa, int sizex, int sizey, unsigned int pos)
{
short x1 = sa->v1->vec.x;
short y1 = sa->v1->vec.y;
short x2 = sa->v3->vec.x;
short y2 = sa->v3->vec.y;
- drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2);
+ drawscredge_area_draw(sizex, sizey, x1, y1, x2, y2, pos);
}
/**
@@ -258,33 +432,40 @@ static void drawscredge_area(ScrArea *sa, int sizex, int sizey)
*/
void ED_screen_draw_edges(wmWindow *win)
{
+ bScreen *screen = WM_window_get_active_screen(win);
const int winsize_x = WM_window_pixels_x(win);
const int winsize_y = WM_window_pixels_y(win);
ScrArea *sa;
- wmSubWindowSet(win, win->screen->mainwin);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* Note: first loop only draws if U.pixelsize > 1, skip otherwise */
if (U.pixelsize > 1.0f) {
/* FIXME: doesn't our glLineWidth already scale by U.pixelsize? */
glLineWidth((2.0f * U.pixelsize) - 1);
- glColor3ub(0x50, 0x50, 0x50);
- glBegin(GL_LINES);
- for (sa = win->screen->areabase.first; sa; sa = sa->next)
- drawscredge_area(sa, winsize_x, winsize_y);
- glEnd();
+ immUniformThemeColor(TH_EDITOR_OUTLINE);
+
+ for (sa = screen->areabase.first; sa; sa = sa->next) {
+ drawscredge_area(sa, winsize_x, winsize_y, pos);
+ }
}
glLineWidth(1);
- glColor3ub(0, 0, 0);
- glBegin(GL_LINES);
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
- drawscredge_area(sa, winsize_x, winsize_y);
+ immUniformThemeColor(TH_EDITOR_OUTLINE);
+
+ for (sa = screen->areabase.first; sa; sa = sa->next) {
+ drawscredge_area(sa, winsize_x, winsize_y, pos);
}
- glEnd();
- win->screen->do_draw = false;
+ immUnbindProgram();
+
+ for (sa = screen->areabase.first; sa; sa = sa->next) {
+ drawscredge_corner(sa, winsize_x, winsize_y);
+ }
+
+ screen->do_draw = false;
}
/**
@@ -295,6 +476,9 @@ void ED_screen_draw_edges(wmWindow *win)
*/
void ED_screen_draw_join_shape(ScrArea *sa1, ScrArea *sa2)
{
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
glLineWidth(1);
/* blended join arrow */
@@ -319,37 +503,155 @@ void ED_screen_draw_join_shape(ScrArea *sa1, ScrArea *sa2)
dira = 'd';
break;
}
+
glEnable(GL_BLEND);
- scrarea_draw_shape_dark(sa2, dir);
- scrarea_draw_shape_light(sa1, dira);
+
+ scrarea_draw_shape_dark(sa2, dir, pos);
+ scrarea_draw_shape_light(sa1, dira, pos);
+
glDisable(GL_BLEND);
}
+
+ immUnbindProgram();
}
void ED_screen_draw_split_preview(ScrArea *sa, const int dir, const float fac)
{
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* splitpoint */
glEnable(GL_BLEND);
- glBegin(GL_LINES);
- glColor4ub(255, 255, 255, 100);
+ immUniformColor4ub(255, 255, 255, 100);
+
+ immBegin(GWN_PRIM_LINES, 2);
if (dir == 'h') {
const float y = (1 - fac) * sa->totrct.ymin + fac * sa->totrct.ymax;
- glVertex2s(sa->totrct.xmin, y);
- glVertex2s(sa->totrct.xmax, y);
- glColor4ub(0, 0, 0, 100);
- glVertex2s(sa->totrct.xmin, y + 1);
- glVertex2s(sa->totrct.xmax, y + 1);
+
+ immVertex2f(pos, sa->totrct.xmin, y);
+ immVertex2f(pos, sa->totrct.xmax, y);
+
+ immEnd();
+
+ immUniformColor4ub(0, 0, 0, 100);
+
+ immBegin(GWN_PRIM_LINES, 2);
+
+ immVertex2f(pos, sa->totrct.xmin, y + 1);
+ immVertex2f(pos, sa->totrct.xmax, y + 1);
+
+ immEnd();
}
else {
+ BLI_assert(dir == 'v');
const float x = (1 - fac) * sa->totrct.xmin + fac * sa->totrct.xmax;
- glVertex2s(x, sa->totrct.ymin);
- glVertex2s(x, sa->totrct.ymax);
- glColor4ub(0, 0, 0, 100);
- glVertex2s(x + 1, sa->totrct.ymin);
- glVertex2s(x + 1, sa->totrct.ymax);
+
+ immVertex2f(pos, x, sa->totrct.ymin);
+ immVertex2f(pos, x, sa->totrct.ymax);
+
+ immEnd();
+
+ immUniformColor4ub(0, 0, 0, 100);
+
+ immBegin(GWN_PRIM_LINES, 2);
+
+ immVertex2f(pos, x + 1, sa->totrct.ymin);
+ immVertex2f(pos, x + 1, sa->totrct.ymax);
+
+ immEnd();
}
- glEnd();
+
glDisable(GL_BLEND);
+
+ immUnbindProgram();
+}
+
+
+/* -------------------------------------------------------------------- */
+/* Screen Thumbnail Preview */
+
+/**
+ * Calculates a scale factor to squash the preview for \a screen into a rectangle of given size and aspect.
+ */
+static void screen_preview_scale_get(
+ const bScreen *screen, float size_x, float size_y,
+ const float asp[2],
+ float r_scale[2])
+{
+ float max_x = 0, max_y = 0;
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ max_x = MAX2(max_x, sa->totrct.xmax);
+ max_y = MAX2(max_y, sa->totrct.ymax);
+ }
+ r_scale[0] = (size_x * asp[0]) / max_x;
+ r_scale[1] = (size_y * asp[1]) / max_y;
}
+static void screen_preview_draw_areas(const bScreen *screen, const float scale[2], const float col[4],
+ const float ofs_between_areas)
+{
+ const float ofs_h = ofs_between_areas * 0.5f;
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv(col);
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ rctf rect = {
+ .xmin = sa->totrct.xmin * scale[0] + ofs_h,
+ .xmax = sa->totrct.xmax * scale[0] - ofs_h,
+ .ymin = sa->totrct.ymin * scale[1] + ofs_h,
+ .ymax = sa->totrct.ymax * scale[1] - ofs_h
+ };
+
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+ immVertex2f(pos, rect.xmin, rect.ymin);
+ immVertex2f(pos, rect.xmax, rect.ymin);
+ immVertex2f(pos, rect.xmax, rect.ymax);
+ immVertex2f(pos, rect.xmin, rect.ymax);
+ immEnd();
+ }
+
+ immUnbindProgram();
+}
+
+static void screen_preview_draw(const bScreen *screen, int size_x, int size_y)
+{
+ const float asp[2] = {1.0f, 0.8f}; /* square previews look a bit ugly */
+ /* could use theme color (tui.wcol_menu_item.text), but then we'd need to regenerate all previews when changing */
+ const float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ float scale[2];
+
+ wmOrtho2(0.0f, size_x, 0.0f, size_y);
+ /* center */
+ gpuPushMatrix();
+ gpuLoadIdentity();
+ gpuTranslate2f(size_x * (1.0f - asp[0]) * 0.5f, size_y * (1.0f - asp[1]) * 0.5f);
+
+ screen_preview_scale_get(screen, size_x, size_y, asp, scale);
+ screen_preview_draw_areas(screen, scale, col, 1.5f);
+
+ gpuPopMatrix();
+}
+
+/**
+ * Render the preview for a screen layout in \a screen.
+ */
+void ED_screen_preview_render(const bScreen *screen, int size_x, int size_y, unsigned int *r_rect)
+{
+ char err_out[256] = "unknown";
+ GPUOffScreen *offscreen = GPU_offscreen_create(size_x, size_y, 0, true, false, err_out);
+
+ GPU_offscreen_bind(offscreen, true);
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ screen_preview_draw(screen, size_x, size_y);
+
+ GPU_offscreen_read_pixels(offscreen, GL_UNSIGNED_BYTE, r_rect);
+ GPU_offscreen_unbind(offscreen, true);
+
+ GPU_offscreen_free(offscreen);
+}
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index 2cd8ee9223f..d024262121c 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -33,7 +33,9 @@
#include "MEM_guardedalloc.h"
+#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_userdef_types.h"
#include "BLI_math.h"
@@ -41,18 +43,17 @@
#include "BLI_utildefines.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_icons.h"
#include "BKE_image.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_screen.h"
#include "BKE_scene.h"
-
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "BKE_workspace.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -66,198 +67,43 @@
#include "UI_interface.h"
-/* XXX actually should be not here... solve later */
-#include "wm_subwindow.h"
+#include "WM_message.h"
+
+#include "DEG_depsgraph_query.h"
#include "screen_intern.h" /* own module include */
/* ******************* screen vert, edge, area managing *********************** */
-static ScrVert *screen_addvert(bScreen *sc, short x, short y)
+static ScrVert *screen_addvert_ex(ScrAreaMap *area_map, short x, short y)
{
ScrVert *sv = MEM_callocN(sizeof(ScrVert), "addscrvert");
sv->vec.x = x;
sv->vec.y = y;
- BLI_addtail(&sc->vertbase, sv);
+ BLI_addtail(&area_map->vertbase, sv);
return sv;
}
-
-static void sortscrvert(ScrVert **v1, ScrVert **v2)
+static ScrVert *screen_addvert(bScreen *sc, short x, short y)
{
- ScrVert *tmp;
-
- if (*v1 > *v2) {
- tmp = *v1;
- *v1 = *v2;
- *v2 = tmp;
- }
+ return screen_addvert_ex(AREAMAP_FROM_SCREEN(sc), x, y);
}
-static ScrEdge *screen_addedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
+static ScrEdge *screen_addedge_ex(ScrAreaMap *area_map, ScrVert *v1, ScrVert *v2)
{
ScrEdge *se = MEM_callocN(sizeof(ScrEdge), "addscredge");
-
- sortscrvert(&v1, &v2);
+
+ BKE_screen_sort_scrvert(&v1, &v2);
se->v1 = v1;
se->v2 = v2;
-
- BLI_addtail(&sc->edgebase, se);
- return se;
-}
-
-
-ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
-{
- ScrEdge *se;
-
- sortscrvert(&v1, &v2);
- for (se = sc->edgebase.first; se; se = se->next)
- if (se->v1 == v1 && se->v2 == v2)
- return se;
-
- return NULL;
-}
-
-void removedouble_scrverts(bScreen *sc)
-{
- ScrVert *v1, *verg;
- ScrEdge *se;
- ScrArea *sa;
-
- verg = sc->vertbase.first;
- while (verg) {
- if (verg->newv == NULL) { /* !!! */
- v1 = verg->next;
- while (v1) {
- if (v1->newv == NULL) { /* !?! */
- if (v1->vec.x == verg->vec.x && v1->vec.y == verg->vec.y) {
- /* printf("doublevert\n"); */
- v1->newv = verg;
- }
- }
- v1 = v1->next;
- }
- }
- verg = verg->next;
- }
-
- /* replace pointers in edges and faces */
- se = sc->edgebase.first;
- while (se) {
- if (se->v1->newv) se->v1 = se->v1->newv;
- if (se->v2->newv) se->v2 = se->v2->newv;
- /* edges changed: so.... */
- sortscrvert(&(se->v1), &(se->v2));
- se = se->next;
- }
- sa = sc->areabase.first;
- while (sa) {
- if (sa->v1->newv) sa->v1 = sa->v1->newv;
- if (sa->v2->newv) sa->v2 = sa->v2->newv;
- if (sa->v3->newv) sa->v3 = sa->v3->newv;
- if (sa->v4->newv) sa->v4 = sa->v4->newv;
- sa = sa->next;
- }
-
- /* remove */
- verg = sc->vertbase.first;
- while (verg) {
- v1 = verg->next;
- if (verg->newv) {
- BLI_remlink(&sc->vertbase, verg);
- MEM_freeN(verg);
- }
- verg = v1;
- }
-
-}
-
-void removenotused_scrverts(bScreen *sc)
-{
- ScrVert *sv, *svn;
- ScrEdge *se;
-
- /* we assume edges are ok */
-
- se = sc->edgebase.first;
- while (se) {
- se->v1->flag = 1;
- se->v2->flag = 1;
- se = se->next;
- }
-
- sv = sc->vertbase.first;
- while (sv) {
- svn = sv->next;
- if (sv->flag == 0) {
- BLI_remlink(&sc->vertbase, sv);
- MEM_freeN(sv);
- }
- else {
- sv->flag = 0;
- }
- sv = svn;
- }
-}
-void removedouble_scredges(bScreen *sc)
-{
- ScrEdge *verg, *se, *sn;
-
- /* compare */
- verg = sc->edgebase.first;
- while (verg) {
- se = verg->next;
- while (se) {
- sn = se->next;
- if (verg->v1 == se->v1 && verg->v2 == se->v2) {
- BLI_remlink(&sc->edgebase, se);
- MEM_freeN(se);
- }
- se = sn;
- }
- verg = verg->next;
- }
+ BLI_addtail(&area_map->edgebase, se);
+ return se;
}
-
-void removenotused_scredges(bScreen *sc)
+static ScrEdge *screen_addedge(bScreen *sc, ScrVert *v1, ScrVert *v2)
{
- ScrEdge *se, *sen;
- ScrArea *sa;
- int a = 0;
-
- /* sets flags when edge is used in area */
- sa = sc->areabase.first;
- while (sa) {
- se = screen_findedge(sc, sa->v1, sa->v2);
- if (se == NULL) printf("error: area %d edge 1 doesn't exist\n", a);
- else se->flag = 1;
- se = screen_findedge(sc, sa->v2, sa->v3);
- if (se == NULL) printf("error: area %d edge 2 doesn't exist\n", a);
- else se->flag = 1;
- se = screen_findedge(sc, sa->v3, sa->v4);
- if (se == NULL) printf("error: area %d edge 3 doesn't exist\n", a);
- else se->flag = 1;
- se = screen_findedge(sc, sa->v4, sa->v1);
- if (se == NULL) printf("error: area %d edge 4 doesn't exist\n", a);
- else se->flag = 1;
- sa = sa->next;
- a++;
- }
- se = sc->edgebase.first;
- while (se) {
- sen = se->next;
- if (se->flag == 0) {
- BLI_remlink(&sc->edgebase, se);
- MEM_freeN(se);
- }
- else {
- se->flag = 0;
- }
- se = sen;
- }
+ return screen_addedge_ex(AREAMAP_FROM_SCREEN(sc), v1, v2);
}
bool scredge_is_horizontal(ScrEdge *se)
@@ -266,16 +112,16 @@ bool scredge_is_horizontal(ScrEdge *se)
}
/* need win size to make sure not to include edges along screen edge */
-ScrEdge *screen_find_active_scredge(bScreen *sc,
- const int winsize_x, const int winsize_y,
- const int mx, const int my)
+ScrEdge *screen_area_map_find_active_scredge(
+ const ScrAreaMap *area_map,
+ const int winsize_x, const int winsize_y,
+ const int mx, const int my)
{
- ScrEdge *se;
int safety = U.widget_unit / 10;
-
- if (safety < 2) safety = 2;
-
- for (se = sc->edgebase.first; se; se = se->next) {
+
+ CLAMP_MIN(safety, 2);
+
+ for (ScrEdge *se = area_map->edgebase.first; se; se = se->next) {
if (scredge_is_horizontal(se)) {
if (se->v1->vec.y > 0 && se->v1->vec.y < winsize_y - 1) {
short min, max;
@@ -297,27 +143,55 @@ ScrEdge *screen_find_active_scredge(bScreen *sc,
}
}
}
-
+
return NULL;
}
+/* need win size to make sure not to include edges along screen edge */
+ScrEdge *screen_find_active_scredge(
+ const wmWindow *win, const bScreen *screen,
+ const int mx, const int my)
+{
+ /* Use layout size (screen excluding global areas) for screen-layout area edges */
+ const int screen_x = WM_window_screen_pixels_x(win), screen_y = WM_window_screen_pixels_y(win);
+ ScrEdge *se = screen_area_map_find_active_scredge(AREAMAP_FROM_SCREEN(screen), screen_x, screen_y, mx, my);
+
+ if (!se) {
+ /* Use entire window size (screen including global areas) for global area edges */
+ const int win_x = WM_window_pixels_x(win), win_y = WM_window_pixels_y(win);
+ se = screen_area_map_find_active_scredge(&win->global_areas, win_x, win_y, mx, my);
+ }
+ return se;
+}
+
/* adds no space data */
-static ScrArea *screen_addarea(bScreen *sc, ScrVert *v1, ScrVert *v2, ScrVert *v3, ScrVert *v4, short headertype, short spacetype)
+static ScrArea *screen_addarea_ex(
+ ScrAreaMap *area_map,
+ ScrVert *bottom_left, ScrVert *top_left, ScrVert *top_right, ScrVert *bottom_right,
+ short spacetype)
{
ScrArea *sa = MEM_callocN(sizeof(ScrArea), "addscrarea");
- sa->v1 = v1;
- sa->v2 = v2;
- sa->v3 = v3;
- sa->v4 = v4;
- sa->headertype = headertype;
- sa->spacetype = sa->butspacetype = spacetype;
-
- BLI_addtail(&sc->areabase, sa);
-
+
+ sa->v1 = bottom_left;
+ sa->v2 = top_left;
+ sa->v3 = top_right;
+ sa->v4 = bottom_right;
+ sa->spacetype = spacetype;
+
+ BLI_addtail(&area_map->areabase, sa);
+
return sa;
}
+static ScrArea *screen_addarea(
+ bScreen *sc,
+ ScrVert *left_bottom, ScrVert *left_top, ScrVert *right_top, ScrVert *right_bottom,
+ short spacetype)
+{
+ return screen_addarea_ex(AREAMAP_FROM_SCREEN(sc), left_bottom, left_top, right_top, right_bottom,
+ spacetype);
+}
static void screen_delarea(bContext *C, bScreen *sc, ScrArea *sa)
{
@@ -398,7 +272,7 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
if (fac > 0.5f) {
/* new areas: top */
- newa = screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->headertype, sa->spacetype);
+ newa = screen_addarea(sc, sv1, sa->v2, sa->v3, sv2, sa->spacetype);
/* area below */
sa->v2 = sv1;
@@ -406,7 +280,7 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
}
else {
/* new areas: bottom */
- newa = screen_addarea(sc, sa->v1, sv1, sv2, sa->v4, sa->headertype, sa->spacetype);
+ newa = screen_addarea(sc, sa->v1, sv1, sv2, sa->v4, sa->spacetype);
/* area above */
sa->v1 = sv1;
@@ -430,7 +304,7 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
if (fac > 0.5f) {
/* new areas: right */
- newa = screen_addarea(sc, sv1, sv2, sa->v3, sa->v4, sa->headertype, sa->spacetype);
+ newa = screen_addarea(sc, sv1, sv2, sa->v3, sa->v4, sa->spacetype);
/* area left */
sa->v3 = sv2;
@@ -438,7 +312,7 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
}
else {
/* new areas: left */
- newa = screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->headertype, sa->spacetype);
+ newa = screen_addarea(sc, sa->v1, sa->v2, sv2, sv1, sa->spacetype);
/* area right */
sa->v1 = sv1;
@@ -450,28 +324,24 @@ ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge)
/* remove double vertices en edges */
if (merge)
- removedouble_scrverts(sc);
- removedouble_scredges(sc);
- removenotused_scredges(sc);
+ BKE_screen_remove_double_scrverts(sc);
+ BKE_screen_remove_double_scredges(sc);
+ BKE_screen_remove_unused_scredges(sc);
return newa;
}
-/* empty screen, with 1 dummy area without spacedata */
-/* uses window size */
-bScreen *ED_screen_add(wmWindow *win, Scene *scene, const char *name)
+/**
+ * Empty screen, with 1 dummy area without spacedata. Uses window size.
+ */
+bScreen *screen_add(const char *name, const int winsize_x, const int winsize_y)
{
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
-
bScreen *sc;
ScrVert *sv1, *sv2, *sv3, *sv4;
sc = BKE_libblock_alloc(G.main, ID_SCR, name, 0);
- sc->scene = scene;
sc->do_refresh = true;
sc->redraws_flag = TIME_ALL_3D_WIN | TIME_ALL_ANIM_WIN;
- sc->winid = win->winid;
sv1 = screen_addvert(sc, 0, 0);
sv2 = screen_addvert(sc, 0, winsize_y - 1);
@@ -484,12 +354,12 @@ bScreen *ED_screen_add(wmWindow *win, Scene *scene, const char *name)
screen_addedge(sc, sv4, sv1);
/* dummy type, no spacedata */
- screen_addarea(sc, sv1, sv2, sv3, sv4, HEADERDOWN, SPACE_EMPTY);
+ screen_addarea(sc, sv1, sv2, sv3, sv4, SPACE_EMPTY);
return sc;
}
-static void screen_copy(bScreen *to, bScreen *from)
+void screen_data_copy(bScreen *to, bScreen *from)
{
ScrVert *s1, *s2;
ScrEdge *se;
@@ -511,7 +381,7 @@ static void screen_copy(bScreen *to, bScreen *from)
for (se = to->edgebase.first; se; se = se->next) {
se->v1 = se->v1->newv;
se->v2 = se->v2->newv;
- sortscrvert(&(se->v1), &(se->v2));
+ BKE_screen_sort_scrvert(&(se->v1), &(se->v2));
}
saf = from->areabase.first;
@@ -532,7 +402,16 @@ static void screen_copy(bScreen *to, bScreen *from)
/* put at zero (needed?) */
for (s1 = from->vertbase.first; s1; s1 = s1->next)
s1->newv = NULL;
+}
+/**
+ * Prepare a newly created screen for initializing it as active screen.
+ */
+void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new)
+{
+ screen_new->winid = win->winid;
+ screen_new->do_refresh = true;
+ screen_new->do_draw = true;
}
@@ -611,15 +490,17 @@ int screen_area_join(bContext *C, bScreen *scr, ScrArea *sa1, ScrArea *sa2)
}
screen_delarea(C, scr, sa2);
- removedouble_scrverts(scr);
+ BKE_screen_remove_double_scrverts(scr);
+ /* Update preview thumbnail */
+ BKE_icon_changed(scr->id.icon_id);
return 1;
}
-void select_connected_scredge(bScreen *sc, ScrEdge *edge)
+void select_connected_scredge(const wmWindow *win, ScrEdge *edge)
{
+ bScreen *sc = WM_window_get_active_screen(win);
ScrEdge *se;
- ScrVert *sv;
int oneselected;
char dir;
@@ -629,12 +510,10 @@ void select_connected_scredge(bScreen *sc, ScrEdge *edge)
if (edge->v1->vec.x == edge->v2->vec.x) dir = 'v';
else dir = 'h';
- sv = sc->vertbase.first;
- while (sv) {
+ ED_screen_verts_iter(win, sc, sv) {
sv->flag = 0;
- sv = sv->next;
}
-
+
edge->v1->flag = 1;
edge->v2->flag = 1;
@@ -662,8 +541,13 @@ void select_connected_scredge(bScreen *sc, ScrEdge *edge)
}
}
-/* test if screen vertices should be scaled */
-static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
+/**
+ * Test if screen vertices should be scaled and do if needed.
+ */
+static void screen_vertices_scale(
+ const wmWindow *win, bScreen *sc,
+ int window_size_x, int window_size_y,
+ int screen_size_x, int screen_size_y)
{
/* clamp Y size of header sized areas when expanding windows
* avoids annoying empty space around file menu */
@@ -672,7 +556,7 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
const int headery_init = ED_area_headersize();
ScrVert *sv = NULL;
ScrArea *sa;
- int winsize_x_prev, winsize_y_prev;
+ int screen_size_x_prev, screen_size_y_prev;
float facx, facy, tempf, min[2], max[2];
/* calculate size */
@@ -690,8 +574,8 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
sv->vec.y -= min[1];
}
- winsize_x_prev = (max[0] - min[0]) + 1;
- winsize_y_prev = (max[1] - min[1]) + 1;
+ screen_size_x_prev = (max[0] - min[0]) + 1;
+ screen_size_y_prev = (max[1] - min[1]) + 1;
#ifdef USE_HEADER_SIZE_CLAMP
@@ -699,14 +583,14 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
#define TEMP_TOP 2
/* if the window's Y axis grows, clamp header sized areas */
- if (winsize_y_prev < winsize_y) { /* growing? */
+ if (screen_size_y_prev < screen_size_y) { /* growing? */
const int headery_margin_max = headery_init + 4;
for (sa = sc->areabase.first; sa; sa = sa->next) {
ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
sa->temp = 0;
if (ar && !(ar->flag & RGN_FLAG_HIDDEN)) {
- if (sa->v2->vec.y == winsize_y_prev - 1) {
+ if (sa->v2->vec.y == screen_size_y_prev) {
if ((sa->v2->vec.y - sa->v1->vec.y) < headery_margin_max) {
sa->temp = TEMP_TOP;
}
@@ -722,9 +606,9 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
#endif
- if (winsize_x_prev != winsize_x || winsize_y_prev != winsize_y) {
- facx = ((float)winsize_x - 1) / ((float)winsize_x_prev - 1);
- facy = ((float)winsize_y - 1) / ((float)winsize_y_prev - 1);
+ if (screen_size_x_prev != screen_size_x || screen_size_y_prev != screen_size_y) {
+ facx = ((float)screen_size_x - 1) / ((float)screen_size_x_prev - 1);
+ facy = ((float)screen_size_y) / ((float)screen_size_y_prev);
/* make sure it fits! */
for (sv = sc->vertbase.first; sv; sv = sv->next) {
@@ -735,20 +619,20 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
//sv->vec.x += AREAGRID - 1;
//sv->vec.x -= (sv->vec.x % AREAGRID);
- CLAMP(sv->vec.x, 0, winsize_x - 1);
+ CLAMP(sv->vec.x, 0, screen_size_x - 1);
tempf = ((float)sv->vec.y) * facy;
sv->vec.y = (short)(tempf + 0.5f);
//sv->vec.y += AREAGRID - 1;
//sv->vec.y -= (sv->vec.y % AREAGRID);
- CLAMP(sv->vec.y, 0, winsize_y - 1);
+ CLAMP(sv->vec.y, 0, screen_size_y);
}
}
#ifdef USE_HEADER_SIZE_CLAMP
- if (winsize_y_prev < winsize_y) { /* growing? */
+ if (screen_size_y_prev < screen_size_y) { /* growing? */
for (sa = sc->areabase.first; sa; sa = sa->next) {
ScrEdge *se = NULL;
@@ -762,9 +646,9 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
if (sa->temp == TEMP_TOP) {
/* lower edge */
const int yval = sa->v2->vec.y - headery_init;
- se = screen_findedge(sc, sa->v4, sa->v1);
+ se = BKE_screen_find_edge(sc, sa->v4, sa->v1);
if (se != NULL) {
- select_connected_scredge(sc, se);
+ select_connected_scredge(win, se);
}
for (sv = sc->vertbase.first; sv; sv = sv->next) {
if (sv != sa->v2 && sv != sa->v3) {
@@ -777,9 +661,9 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
else {
/* upper edge */
const int yval = sa->v1->vec.y + headery_init;
- se = screen_findedge(sc, sa->v2, sa->v3);
+ se = BKE_screen_find_edge(sc, sa->v2, sa->v3);
if (se != NULL) {
- select_connected_scredge(sc, se);
+ select_connected_scredge(win, se);
}
for (sv = sc->vertbase.first; sv; sv = sv->next) {
if (sv != sa->v1 && sv != sa->v4) {
@@ -808,16 +692,16 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
/* adjust headery if verts are along the edge of window */
if (sa->v1->vec.y > 0)
headery += U.pixelsize;
- if (sa->v2->vec.y < winsize_y - 1)
+ if (sa->v2->vec.y < screen_size_y)
headery += U.pixelsize;
if (sa->v2->vec.y - sa->v1->vec.y + 1 < headery) {
/* lower edge */
- ScrEdge *se = screen_findedge(sc, sa->v4, sa->v1);
+ ScrEdge *se = BKE_screen_find_edge(sc, sa->v4, sa->v1);
if (se && sa->v1 != sa->v2) {
int yval;
- select_connected_scredge(sc, se);
+ select_connected_scredge(win, se);
/* all selected vertices get the right offset */
yval = sa->v2->vec.y - headery + 1;
@@ -832,32 +716,39 @@ static void screen_test_scale(bScreen *sc, int winsize_x, int winsize_y)
}
}
}
-
+
+ /* Global areas have a fixed size that only changes with the DPI. Here we ensure that exactly this size is set.
+ * TODO Assumes global area to be top-aligned. Should be made more generic */
+ for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) {
+ if (area->global->flag & GLOBAL_AREA_IS_HIDDEN) {
+ continue;
+ }
+ /* width */
+ area->v1->vec.x = area->v2->vec.x = 0;
+ area->v3->vec.x = area->v4->vec.x = window_size_x - 1;
+ /* height */
+ area->v2->vec.y = area->v3->vec.y = window_size_y - 1;
+ area->v1->vec.y = area->v4->vec.y = area->v2->vec.y - ED_area_global_size_y(area);
+ }
}
+
/* ****************** EXPORTED API TO OTHER MODULES *************************** */
-bScreen *ED_screen_duplicate(wmWindow *win, bScreen *sc)
+/* screen sets cursor based on active region */
+static void region_cursor_set(wmWindow *win, bool swin_changed)
{
- bScreen *newsc;
-
- if (sc->state != SCREENNORMAL) return NULL; /* XXX handle this case! */
-
- /* make new empty screen: */
- newsc = ED_screen_add(win, sc->scene, sc->id.name + 2);
- /* copy all data */
- screen_copy(newsc, sc);
+ bScreen *screen = WM_window_get_active_screen(win);
- return newsc;
-}
-
-/* screen sets cursor based on swinid */
-static void region_cursor_set(wmWindow *win, int swinid, int swin_changed)
-{
- for (ScrArea *sa = win->screen->areabase.first; sa; sa = sa->next) {
+ ED_screen_areas_iter(win, screen, sa) {
for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid == swinid) {
+ if (ar == screen->active_region) {
if (swin_changed || (ar->type && ar->type->event_cursor)) {
+ if (ar->manipulator_map != NULL) {
+ if (WM_manipulatormap_cursor_set(ar->manipulator_map, win)) {
+ return;
+ }
+ }
ED_region_cursor_set(win, sa, ar);
}
return;
@@ -869,23 +760,24 @@ static void region_cursor_set(wmWindow *win, int swinid, int swin_changed)
void ED_screen_do_listen(bContext *C, wmNotifier *note)
{
wmWindow *win = CTX_wm_window(C);
-
+ bScreen *screen = CTX_wm_screen(C);
+
/* generic notes */
switch (note->category) {
case NC_WM:
if (note->data == ND_FILEREAD)
- win->screen->do_draw = true;
+ screen->do_draw = true;
break;
case NC_WINDOW:
- win->screen->do_draw = true;
+ screen->do_draw = true;
break;
case NC_SCREEN:
if (note->action == NA_EDITED)
- win->screen->do_draw = win->screen->do_refresh = true;
+ screen->do_draw = screen->do_refresh = true;
break;
case NC_SCENE:
if (note->data == ND_MODE)
- region_cursor_set(win, note->swinid, true);
+ region_cursor_set(win, true);
break;
}
}
@@ -905,49 +797,41 @@ static void screen_refresh_headersizes(void)
/* make this screen usable */
/* for file read and first use, for scaling window, area moves */
void ED_screen_refresh(wmWindowManager *wm, wmWindow *win)
-{
+{
+ bScreen *screen = WM_window_get_active_screen(win);
+
/* exception for bg mode, we only need the screen context */
if (!G.background) {
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
- ScrArea *sa;
- rcti winrct;
-
- winrct.xmin = 0;
- winrct.xmax = winsize_x - 1;
- winrct.ymin = 0;
- winrct.ymax = winsize_y - 1;
-
+ const int window_size_x = WM_window_pixels_x(win);
+ const int window_size_y = WM_window_pixels_y(win);
+ const int screen_size_x = WM_window_screen_pixels_x(win);
+ const int screen_size_y = WM_window_screen_pixels_y(win);
+
/* header size depends on DPI, let's verify */
WM_window_set_dpi(win);
screen_refresh_headersizes();
-
- screen_test_scale(win->screen, winsize_x, winsize_y);
-
- if (win->screen->mainwin == 0) {
- win->screen->mainwin = wm_subwindow_open(win, &winrct, false);
- }
- else {
- wm_subwindow_position(win, win->screen->mainwin, &winrct, false);
- }
-
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+
+ screen_vertices_scale(win, screen, window_size_x, window_size_y, screen_size_x, screen_size_y);
+
+ ED_screen_areas_iter(win, screen, area) {
/* set spacetype and region callbacks, calls init() */
/* sets subwindows for regions, adds handlers */
- ED_area_initialize(wm, win, sa);
+ ED_area_initialize(wm, win, area);
}
/* wake up animtimer */
- if (win->screen->animtimer)
- WM_event_timer_sleep(wm, win, win->screen->animtimer, false);
+ if (screen->animtimer)
+ WM_event_timer_sleep(wm, win, screen->animtimer, false);
}
if (G.debug & G_DEBUG_EVENTS) {
printf("%s: set screen\n", __func__);
}
- win->screen->do_refresh = false;
+ screen->do_refresh = false;
+ /* prevent multiwin errors */
+ screen->winid = win->winid;
- win->screen->context = ed_screen_context;
+ screen->context = ed_screen_context;
}
/* file read, set all screens, ... */
@@ -956,10 +840,20 @@ void ED_screens_initialize(wmWindowManager *wm)
wmWindow *win;
for (win = wm->windows.first; win; win = win->next) {
-
- if (win->screen == NULL)
- win->screen = G.main->screen.first;
-
+ if (WM_window_get_active_workspace(win) == NULL) {
+ WM_window_set_active_workspace(win, G.main->workspaces.first);
+ }
+
+ if (BLI_listbase_is_empty(&win->global_areas.areabase)) {
+ ED_screen_global_areas_create(win);
+ }
+ ED_screen_refresh(wm, win);
+ }
+}
+
+void ED_screen_ensure_updated(wmWindowManager *wm, wmWindow *win, bScreen *screen)
+{
+ if (screen->do_refresh) {
ED_screen_refresh(wm, win);
}
}
@@ -970,17 +864,17 @@ void ED_screens_initialize(wmWindowManager *wm)
void ED_region_exit(bContext *C, ARegion *ar)
{
wmWindowManager *wm = CTX_wm_manager(C);
+ wmWindow *win = CTX_wm_window(C);
ARegion *prevar = CTX_wm_region(C);
if (ar->type && ar->type->exit)
ar->type->exit(wm, ar);
CTX_wm_region_set(C, ar);
+
WM_event_remove_handlers(C, &ar->handlers);
- if (ar->swinid) {
- wm_subwindow_close(CTX_wm_window(C), ar->swinid);
- ar->swinid = 0;
- }
+ WM_event_modal_handler_region_replace(win, ar, NULL);
+ WM_draw_region_free(ar);
if (ar->headerstr) {
MEM_freeN(ar->headerstr);
@@ -988,16 +882,19 @@ void ED_region_exit(bContext *C, ARegion *ar)
}
if (ar->regiontimer) {
- WM_event_remove_timer(CTX_wm_manager(C), CTX_wm_window(C), ar->regiontimer);
+ WM_event_remove_timer(wm, win, ar->regiontimer);
ar->regiontimer = NULL;
}
+ WM_msgbus_clear_by_owner(wm->message_bus, ar);
+
CTX_wm_region_set(C, prevar);
}
void ED_area_exit(bContext *C, ScrArea *sa)
{
wmWindowManager *wm = CTX_wm_manager(C);
+ wmWindow *win = CTX_wm_window(C);
ScrArea *prevsa = CTX_wm_area(C);
ARegion *ar;
@@ -1005,10 +902,13 @@ void ED_area_exit(bContext *C, ScrArea *sa)
sa->type->exit(wm, sa);
CTX_wm_area_set(C, sa);
+
for (ar = sa->regionbase.first; ar; ar = ar->next)
ED_region_exit(C, ar);
WM_event_remove_handlers(C, &sa->handlers);
+ WM_event_modal_handler_area_replace(win, sa, NULL);
+
CTX_wm_area_set(C, prevsa);
}
@@ -1026,21 +926,22 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
screen->animtimer = NULL;
screen->scrubbing = false;
- if (screen->mainwin)
- wm_subwindow_close(window, screen->mainwin);
- screen->mainwin = 0;
- screen->subwinactive = 0;
+ screen->active_region = NULL;
- for (ar = screen->regionbase.first; ar; ar = ar->next)
+ for (ar = screen->regionbase.first; ar; ar = ar->next) {
ED_region_exit(C, ar);
-
- for (sa = screen->areabase.first; sa; sa = sa->next)
+ }
+ for (sa = screen->areabase.first; sa; sa = sa->next) {
+ ED_area_exit(C, sa);
+ }
+ for (sa = window->global_areas.areabase.first; sa; sa = sa->next) {
ED_area_exit(C, sa);
+ }
/* mark it available for use for other windows */
screen->winid = 0;
- if (prevwin->screen->temp == 0) {
+ if (!WM_window_is_temp_screen(prevwin)) {
/* use previous window if possible */
CTX_wm_window_set(C, prevwin);
}
@@ -1054,16 +955,14 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
/* *********************************** */
/* case when on area-edge or in azones, or outside window */
-static void screen_cursor_set(wmWindow *win, const wmEvent *event)
+static void screen_cursor_set(wmWindow *win, const int xy[2])
{
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
-
+ const bScreen *screen = WM_window_get_active_screen(win);
AZone *az = NULL;
ScrArea *sa;
- for (sa = win->screen->areabase.first; sa; sa = sa->next)
- if ((az = is_in_area_actionzone(sa, &event->x)))
+ for (sa = screen->areabase.first; sa; sa = sa->next)
+ if ((az = is_in_area_actionzone(sa, xy)))
break;
if (sa) {
@@ -1077,8 +976,8 @@ static void screen_cursor_set(wmWindow *win, const wmEvent *event)
}
}
else {
- ScrEdge *actedge = screen_find_active_scredge(win->screen, winsize_x, winsize_y, event->x, event->y);
-
+ ScrEdge *actedge = screen_find_active_scredge(win, screen, xy[0], xy[1]);
+
if (actedge) {
if (scredge_is_horizontal(actedge))
WM_cursor_set(win, CURSOR_Y_MOVE);
@@ -1093,68 +992,76 @@ static void screen_cursor_set(wmWindow *win, const wmEvent *event)
/* called in wm_event_system.c. sets state vars in screen, cursors */
/* event type is mouse move */
-void ED_screen_set_subwinactive(bContext *C, const wmEvent *event)
+void ED_screen_set_active_region(bContext *C, const int xy[2])
{
wmWindow *win = CTX_wm_window(C);
-
- if (win->screen) {
- bScreen *scr = win->screen;
- ScrArea *sa;
+ bScreen *scr = WM_window_get_active_screen(win);
+
+ if (scr) {
+ ScrArea *sa = NULL;
ARegion *ar;
- int oldswin = scr->subwinactive;
+ ARegion *old_ar = scr->active_region;
- for (sa = scr->areabase.first; sa; sa = sa->next) {
- if (event->x > sa->totrct.xmin && event->x < sa->totrct.xmax)
- if (event->y > sa->totrct.ymin && event->y < sa->totrct.ymax)
- if (NULL == is_in_area_actionzone(sa, &event->x))
+ ED_screen_areas_iter(win, scr, area_iter) {
+ if (xy[0] > area_iter->totrct.xmin && xy[0] < area_iter->totrct.xmax) {
+ if (xy[1] > area_iter->totrct.ymin && xy[1] < area_iter->totrct.ymax) {
+ if (is_in_area_actionzone(area_iter, xy) == NULL) {
+ sa = area_iter;
break;
+ }
+ }
+ }
}
if (sa) {
/* make overlap active when mouse over */
for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (BLI_rcti_isect_pt_v(&ar->winrct, &event->x)) {
- scr->subwinactive = ar->swinid;
+ if (BLI_rcti_isect_pt_v(&ar->winrct, xy)) {
+ scr->active_region = ar;
break;
}
}
}
else
- scr->subwinactive = scr->mainwin;
+ scr->active_region = NULL;
/* check for redraw headers */
- if (oldswin != scr->subwinactive) {
+ if (old_ar != scr->active_region) {
- for (sa = scr->areabase.first; sa; sa = sa->next) {
+ ED_screen_areas_iter(win, scr, area_iter) {
bool do_draw = false;
- for (ar = sa->regionbase.first; ar; ar = ar->next)
- if (ar->swinid == oldswin || ar->swinid == scr->subwinactive)
+ for (ar = area_iter->regionbase.first; ar; ar = ar->next) {
+ if (ar == old_ar || ar == scr->active_region) {
do_draw = true;
+ }
+ }
if (do_draw) {
- for (ar = sa->regionbase.first; ar; ar = ar->next)
- if (ar->regiontype == RGN_TYPE_HEADER)
+ for (ar = area_iter->regionbase.first; ar; ar = ar->next) {
+ if (ar->regiontype == RGN_TYPE_HEADER) {
ED_region_tag_redraw(ar);
+ }
+ }
}
}
}
/* cursors, for time being set always on edges, otherwise aregion doesnt switch */
- if (scr->subwinactive == scr->mainwin) {
- screen_cursor_set(win, event);
+ if (scr->active_region == NULL) {
+ screen_cursor_set(win, xy);
}
else {
/* notifier invokes freeing the buttons... causing a bit too much redraws */
- if (oldswin != scr->subwinactive) {
- region_cursor_set(win, scr->subwinactive, true);
+ if (old_ar != scr->active_region) {
+ region_cursor_set(win, true);
/* this used to be a notifier, but needs to be done immediate
* because it can undo setting the right button as active due
* to delayed notifier handling */
- UI_screen_free_active_but(C, win->screen);
+ UI_screen_free_active_but(C, scr);
}
else
- region_cursor_set(win, scr->subwinactive, false);
+ region_cursor_set(win, false);
}
}
}
@@ -1173,183 +1080,182 @@ int ED_screen_area_active(const bContext *C)
return 1;
for (ar = sa->regionbase.first; ar; ar = ar->next)
- if (ar->swinid == sc->subwinactive)
+ if (ar == sc->active_region)
return 1;
}
return 0;
}
/**
- * operator call, WM + Window + screen already existed before
- *
- * \warning Do NOT call in area/region queues!
- * \returns success.
+ * Add an area and geometry (screen-edges and -vertices) for it to \a area_map,
+ * with coordinates/dimensions matching \a rect.
*/
-bool ED_screen_set(bContext *C, bScreen *sc)
+static ScrArea *screen_area_create_with_geometry(
+ ScrAreaMap *area_map, const rcti *rect,
+ short spacetype)
{
- Main *bmain = CTX_data_main(C);
- wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *win = CTX_wm_window(C);
- bScreen *oldscreen = CTX_wm_screen(C);
-
- /* validate screen, it's called with notifier reference */
- if (BLI_findindex(&bmain->screen, sc) == -1) {
- return true;
+ ScrVert *bottom_left = screen_addvert_ex(area_map, rect->xmin, rect->ymin);
+ ScrVert *top_left = screen_addvert_ex(area_map, rect->xmin, rect->ymax);
+ ScrVert *top_right = screen_addvert_ex(area_map, rect->xmax, rect->ymax);
+ ScrVert *bottom_right = screen_addvert_ex(area_map, rect->xmax, rect->ymin);
+
+ screen_addedge_ex(area_map, bottom_left, top_left);
+ screen_addedge_ex(area_map, top_left, top_right);
+ screen_addedge_ex(area_map, top_right, bottom_right);
+ screen_addedge_ex(area_map, bottom_right, bottom_left);
+
+ return screen_addarea_ex(area_map, bottom_left, top_left, top_right, bottom_right, spacetype);
+}
+
+void ED_screen_global_topbar_area_create(wmWindow *win, const bScreen *screen)
+{
+ if (screen->temp == 0) {
+ const short size_y = 2.25 * HEADERY;
+ SpaceType *st;
+ SpaceLink *sl;
+ ScrArea *sa;
+ rcti rect;
+
+ BLI_rcti_init(&rect, 0, WM_window_pixels_x(win) - 1, 0, WM_window_pixels_y(win) - 1);
+ rect.ymin = rect.ymax - size_y;
+
+ sa = screen_area_create_with_geometry(&win->global_areas, &rect, SPACE_TOPBAR);
+ st = BKE_spacetype_from_id(SPACE_TOPBAR);
+ sl = st->new(sa, WM_window_get_active_scene(win));
+ sa->regionbase = sl->regionbase;
+
+ /* Data specific to global areas. */
+ sa->global = MEM_callocN(sizeof(*sa->global), __func__);
+ sa->global->cur_fixed_height = size_y;
+ sa->global->size_max = size_y;
+ sa->global->size_min = HEADERY;
+
+ BLI_addhead(&sa->spacedata, sl);
+ BLI_listbase_clear(&sl->regionbase);
}
+ /* Do not create more area types here! Function is called on file load (wm_window_ghostwindows_ensure). TODO */
+}
- if (ELEM(sc->state, SCREENMAXIMIZED, SCREENFULL)) {
- /* find associated full */
- bScreen *sc1;
- for (sc1 = bmain->screen.first; sc1; sc1 = sc1->id.next) {
- ScrArea *sa = sc1->areabase.first;
- if (sa->full == sc) {
- sc = sc1;
- break;
- }
+void ED_screen_global_areas_create(wmWindow *win)
+{
+ const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
+ ED_screen_global_topbar_area_create(win, screen);
+}
+
+
+/* -------------------------------------------------------------------- */
+/* Screen changing */
+
+static bScreen *screen_fullscreen_find_associated_normal_screen(const Main *bmain, bScreen *screen)
+{
+ for (bScreen *screen_iter = bmain->screen.first; screen_iter; screen_iter = screen_iter->id.next) {
+ ScrArea *sa = screen_iter->areabase.first;
+ if (sa->full == screen) {
+ return screen_iter;
}
}
+ return screen;
+}
+
+/**
+ * \return the screen to activate.
+ * \warning The returned screen may not always equal \a screen_new!
+ */
+bScreen *screen_change_prepare(bScreen *screen_old, bScreen *screen_new, Main *bmain, bContext *C, wmWindow *win)
+{
+ /* validate screen, it's called with notifier reference */
+ if (BLI_findindex(&bmain->screen, screen_new) == -1) {
+ return NULL;
+ }
+
+ if (ELEM(screen_new->state, SCREENMAXIMIZED, SCREENFULL)) {
+ screen_new = screen_fullscreen_find_associated_normal_screen(bmain, screen_new);
+ }
+
/* check for valid winid */
- if (sc->winid != 0 && sc->winid != win->winid) {
- return false;
+ if (!(screen_new->winid == 0 || screen_new->winid == win->winid)) {
+ return NULL;
}
-
- if (oldscreen != sc) {
- wmTimer *wt = oldscreen->animtimer;
- ScrArea *sa;
- Scene *oldscene = oldscreen->scene;
+
+ if (screen_old != screen_new) {
+ wmTimer *wt = screen_old->animtimer;
/* remove handlers referencing areas in old screen */
- for (sa = oldscreen->areabase.first; sa; sa = sa->next) {
+ for (ScrArea *sa = screen_old->areabase.first; sa; sa = sa->next) {
WM_event_remove_area_handler(&win->modalhandlers, sa);
}
/* we put timer to sleep, so screen_exit has to think there's no timer */
- oldscreen->animtimer = NULL;
+ screen_old->animtimer = NULL;
if (wt) {
- WM_event_timer_sleep(wm, win, wt, true);
+ WM_event_timer_sleep(CTX_wm_manager(C), win, wt, true);
}
-
- ED_screen_exit(C, win, oldscreen);
+ ED_screen_exit(C, win, screen_old);
/* Same scene, "transfer" playback to new screen. */
if (wt) {
- if (oldscene == sc->scene) {
- sc->animtimer = wt;
- }
- /* Else, stop playback. */
- else {
- oldscreen->animtimer = wt;
- ED_screen_animation_play(C, 0, 0);
- }
- }
-
- win->screen = sc;
- CTX_wm_window_set(C, win); // stores C->wm.screen... hrmf
-
- /* prevent multiwin errors */
- sc->winid = win->winid;
-
- ED_screen_refresh(CTX_wm_manager(C), CTX_wm_window(C));
- WM_event_add_notifier(C, NC_WINDOW, NULL);
- WM_event_add_notifier(C, NC_SCREEN | ND_SCREENSET, sc);
-
- /* makes button hilites work */
- WM_event_add_mousemove(C);
-
- /* Needed to make sure all the derivedMeshes are
- * up-to-date before viewport starts acquiring this.
- *
- * This is needed in cases when, for example, boolean
- * modifier uses operant from invisible layer.
- * Without this trick boolean wouldn't apply correct.
- *
- * Quite the same happens when setting screen's scene,
- * so perhaps this is in fact correct thing to do.
- */
- if (oldscene != sc->scene) {
- BKE_scene_set_background(bmain, sc->scene);
+ screen_new->animtimer = wt;
}
- /* Always do visible update since it's possible new screen will
- * have different layers visible in 3D view-ports.
- * This is possible because of view3d.lock_camera_and_layers option.
- */
- DAG_on_visible_update(bmain, false);
+ return screen_new;
}
- return true;
+ return NULL;
}
-static bool ed_screen_used(wmWindowManager *wm, bScreen *sc)
+void screen_change_update(bContext *C, wmWindow *win, bScreen *sc)
{
- wmWindow *win;
+ Scene *scene = WM_window_get_active_scene(win);
+ WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+ WorkSpaceLayout *layout = BKE_workspace_layout_find(workspace, sc);
- for (win = wm->windows.first; win; win = win->next) {
- if (win->screen == sc) {
- return true;
- }
+ CTX_wm_window_set(C, win); /* stores C->wm.screen... hrmf */
- if (ELEM(win->screen->state, SCREENMAXIMIZED, SCREENFULL)) {
- ScrArea *sa = win->screen->areabase.first;
- if (sa->full == sc) {
- return true;
- }
- }
- }
+ ED_screen_refresh(CTX_wm_manager(C), win);
- return false;
+ BKE_screen_view3d_scene_sync(sc, scene); /* sync new screen with scene data */
+ WM_event_add_notifier(C, NC_WINDOW, NULL);
+ WM_event_add_notifier(C, NC_SCREEN | ND_LAYOUTSET, layout);
+
+ /* makes button hilites work */
+ WM_event_add_mousemove(C);
}
-/* only call outside of area/region loops */
-bool ED_screen_delete(bContext *C, bScreen *sc)
+
+/**
+ * \brief Change the active screen.
+ *
+ * Operator call, WM + Window + screen already existed before
+ *
+ * \warning Do NOT call in area/region queues!
+ * \returns if screen changing was successful.
+ */
+bool ED_screen_change(bContext *C, bScreen *sc)
{
Main *bmain = CTX_data_main(C);
- wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = CTX_wm_window(C);
- bScreen *newsc;
-
- /* don't allow deleting temp fullscreens for now */
- if (ELEM(sc->state, SCREENMAXIMIZED, SCREENFULL)) {
- return false;
- }
+ bScreen *screen_old = CTX_wm_screen(C);
+ bScreen *screen_new = screen_change_prepare(screen_old, sc, bmain, C, win);
- /* screen can only be in use by one window at a time, so as
- * long as we are able to find a screen that is unused, we
- * can safely assume ours is not in use anywhere an delete it */
+ if (screen_new) {
+ WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+ WM_window_set_active_screen(win, workspace, sc);
+ screen_change_update(C, win, screen_new);
- for (newsc = sc->id.prev; newsc; newsc = newsc->id.prev)
- if (!ed_screen_used(wm, newsc) && !newsc->temp)
- break;
-
- if (!newsc) {
- for (newsc = sc->id.next; newsc; newsc = newsc->id.next)
- if (!ed_screen_used(wm, newsc) && !newsc->temp)
- break;
- }
-
- if (!newsc) {
- return false;
- }
-
- ED_screen_set(C, newsc);
-
- if (win->screen != sc) {
- BKE_libblock_free(bmain, sc);
return true;
}
- else {
- return false;
- }
+
+ return false;
}
-static void ed_screen_set_3dview_camera(Scene *scene, bScreen *sc, ScrArea *sa, View3D *v3d)
+static void screen_set_3dview_camera(Scene *scene, ViewLayer *view_layer, ScrArea *sa, View3D *v3d)
{
/* fix any cameras that are used in the 3d view but not in the scene */
BKE_screen_view3d_sync(v3d, scene);
- if (!v3d->camera || !BKE_scene_base_find(scene, v3d->camera)) {
- v3d->camera = BKE_scene_camera_find(sc->scene);
+ if (!v3d->camera || !BKE_view_layer_base_find(view_layer, v3d->camera)) {
+ v3d->camera = BKE_view_layer_camera_find(view_layer);
// XXX if (sc == curscreen) handle_view3d_lock();
if (!v3d->camera) {
ARegion *ar;
@@ -1373,99 +1279,21 @@ static void ed_screen_set_3dview_camera(Scene *scene, bScreen *sc, ScrArea *sa,
}
}
-/* only call outside of area/region loops */
-void ED_screen_set_scene(bContext *C, bScreen *screen, Scene *scene)
+void ED_screen_update_after_scene_change(const bScreen *screen, Scene *scene_new, ViewLayer *view_layer)
{
- Main *bmain = CTX_data_main(C);
- bScreen *sc;
-
- if (screen == NULL)
- return;
-
- if (ed_screen_used(CTX_wm_manager(C), screen))
- ED_object_editmode_exit(C, EM_FREEDATA | EM_DO_UNDO);
-
- for (sc = bmain->screen.first; sc; sc = sc->id.next) {
- if ((U.flag & USER_SCENEGLOBAL) || sc == screen) {
-
- if (scene != sc->scene) {
- /* all areas endlocalview */
- // XXX ScrArea *sa = sc->areabase.first;
- // while (sa) {
- // endlocalview(sa);
- // sa = sa->next;
- // }
- sc->scene = scene;
- }
-
- }
- }
-
- // copy_view3d_lock(0); /* space.c */
-
- /* are there cameras in the views that are not in the scene? */
- for (sc = bmain->screen.first; sc; sc = sc->id.next) {
- if ((U.flag & USER_SCENEGLOBAL) || sc == screen) {
- ScrArea *sa = sc->areabase.first;
- while (sa) {
- SpaceLink *sl = sa->spacedata.first;
- while (sl) {
- if (sl->spacetype == SPACE_VIEW3D) {
- View3D *v3d = (View3D *) sl;
- ed_screen_set_3dview_camera(scene, sc, sa, v3d);
-
- }
- sl = sl->next;
- }
- sa = sa->next;
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+ if (sl->spacetype == SPACE_VIEW3D) {
+ View3D *v3d = (View3D *)sl;
+ screen_set_3dview_camera(scene_new, view_layer, sa, v3d);
}
}
}
-
- CTX_data_scene_set(C, scene);
- BKE_scene_set_background(bmain, scene);
- DAG_on_visible_update(bmain, false);
-
- ED_render_engine_changed(bmain);
- ED_update_for_newframe(bmain, scene, 1);
-
- /* complete redraw */
- WM_event_add_notifier(C, NC_WINDOW, NULL);
-
-}
-
-/**
- * \note Only call outside of area/region loops
- * \return true if successful
- */
-bool ED_screen_delete_scene(bContext *C, Scene *scene)
-{
- Main *bmain = CTX_data_main(C);
- Scene *newscene;
-
- if (scene->id.prev)
- newscene = scene->id.prev;
- else if (scene->id.next)
- newscene = scene->id.next;
- else
- return false;
-
- ED_screen_set_scene(C, CTX_wm_screen(C), newscene);
-
- BKE_libblock_remap(bmain, scene, newscene, ID_REMAP_SKIP_INDIRECT_USAGE | ID_REMAP_SKIP_NEVER_NULL_USAGE);
-
- id_us_clear_real(&scene->id);
- if (scene->id.us == 0) {
- BKE_libblock_free(bmain, scene);
- }
-
- return true;
}
ScrArea *ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
{
wmWindow *win = CTX_wm_window(C);
- bScreen *screen = CTX_wm_screen(C);
ScrArea *newsa = NULL;
if (!sa || sa->full == NULL) {
@@ -1473,18 +1301,7 @@ ScrArea *ED_screen_full_newspace(bContext *C, ScrArea *sa, int type)
}
if (!newsa) {
- if (sa->full && (screen->state == SCREENMAXIMIZED)) {
- /* if this has been called from the temporary info header generated in
- * temp fullscreen layouts, find the correct fullscreen area to change
- * to create a new space inside */
- for (newsa = screen->areabase.first; newsa; newsa = newsa->next) {
- if (!(sa->flag & AREA_TEMP_INFO))
- break;
- }
- }
- else {
- newsa = sa;
- }
+ newsa = sa;
}
BLI_assert(newsa);
@@ -1566,6 +1383,7 @@ void ED_screen_full_restore(bContext *C, ScrArea *sa)
ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const short state)
{
wmWindowManager *wm = CTX_wm_manager(C);
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
bScreen *sc, *oldscreen;
ARegion *ar;
@@ -1587,9 +1405,10 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
}
if (sa && sa->full) {
+ WorkSpaceLayout *layout_old = WM_window_get_active_layout(win);
/* restoring back to SCREENNORMAL */
sc = sa->full; /* the old screen to restore */
- oldscreen = win->screen; /* the one disappearing */
+ oldscreen = WM_window_get_active_screen(win); /* the one disappearing */
sc->state = SCREENNORMAL;
@@ -1603,10 +1422,8 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
/* clear full screen state */
old->full = NULL;
- old->flag &= ~AREA_TEMP_INFO;
}
- sa->flag &= ~AREA_TEMP_INFO;
sa->full = NULL;
if (fullsa == NULL) {
@@ -1616,6 +1433,10 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
}
if (state == SCREENFULL) {
+ /* unhide global areas */
+ for (ScrArea *glob_area = win->global_areas.areabase.first; glob_area; glob_area = glob_area->next) {
+ glob_area->global->flag &= ~GLOBAL_AREA_IS_HIDDEN;
+ }
/* restore the old side panels/header visibility */
for (ar = sa->regionbase.first; ar; ar = ar->next) {
ar->flag = ar->flagfullscreen;
@@ -1628,9 +1449,9 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
sc->animtimer = oldscreen->animtimer;
oldscreen->animtimer = NULL;
- ED_screen_set(C, sc);
+ ED_screen_change(C, sc);
- BKE_libblock_free(CTX_data_main(C), oldscreen);
+ BKE_workspace_layout_remove(CTX_data_main(C), workspace, layout_old);
/* After we've restored back to SCREENNORMAL, we have to wait with
* screen handling as it uses the area coords which aren't updated yet.
@@ -1640,14 +1461,20 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
}
else {
/* change from SCREENNORMAL to new state */
+ WorkSpaceLayout *layout_new;
ScrArea *newa;
char newname[MAX_ID_NAME - 2];
- oldscreen = win->screen;
+ BLI_assert(ELEM(state, SCREENMAXIMIZED, SCREENFULL));
+
+ oldscreen = WM_window_get_active_screen(win);
oldscreen->state = state;
BLI_snprintf(newname, sizeof(newname), "%s-%s", oldscreen->id.name + 2, "nonnormal");
- sc = ED_screen_add(win, oldscreen->scene, newname);
+
+ layout_new = ED_workspace_layout_add(workspace, win, newname);
+
+ sc = BKE_workspace_layout_screen_get(layout_new);
sc->state = state;
sc->redraws_flag = oldscreen->redraws_flag;
sc->temp = oldscreen->temp;
@@ -1658,51 +1485,35 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
/* use random area when we have no active one, e.g. when the
* mouse is outside of the window and we open a file browser */
- if (!sa)
+ if (!sa) {
sa = oldscreen->areabase.first;
-
- if (state == SCREENMAXIMIZED) {
- /* returns the top small area */
- newa = area_split(sc, (ScrArea *)sc->areabase.first, 'h', 0.99f, 1);
- ED_area_newspace(C, newa, SPACE_INFO, false);
-
- /* copy area */
- newa = newa->prev;
- ED_area_data_swap(newa, sa);
- sa->flag |= AREA_TEMP_INFO;
-
- sa->full = oldscreen;
- newa->full = oldscreen;
- newa->next->full = oldscreen; // XXX
}
- else if (state == SCREENFULL) {
- newa = (ScrArea *)sc->areabase.first;
- /* copy area */
- ED_area_data_swap(newa, sa);
- newa->flag = sa->flag; /* mostly for AREA_FLAG_WASFULLSCREEN */
+ newa = (ScrArea *)sc->areabase.first;
+ /* copy area */
+ ED_area_data_swap(newa, sa);
+ newa->flag = sa->flag; /* mostly for AREA_FLAG_WASFULLSCREEN */
+
+ if (state == SCREENFULL) {
+ /* temporarily hide global areas */
+ for (ScrArea *glob_area = win->global_areas.areabase.first; glob_area; glob_area = glob_area->next) {
+ glob_area->global->flag |= GLOBAL_AREA_IS_HIDDEN;
+ }
/* temporarily hide the side panels/header */
for (ar = newa->regionbase.first; ar; ar = ar->next) {
ar->flagfullscreen = ar->flag;
- if (ELEM(ar->regiontype,
- RGN_TYPE_UI,
- RGN_TYPE_HEADER,
- RGN_TYPE_TOOLS))
- {
+ if (ELEM(ar->regiontype, RGN_TYPE_UI, RGN_TYPE_HEADER, RGN_TYPE_TOOLS)) {
ar->flag |= RGN_FLAG_HIDDEN;
}
}
-
- sa->full = oldscreen;
- newa->full = oldscreen;
- }
- else {
- BLI_assert(false);
}
- ED_screen_set(C, sc);
+ sa->full = oldscreen;
+ newa->full = oldscreen;
+
+ ED_screen_change(C, sc);
}
/* XXX bad code: setscreen() ends with first area active. fullscreen render assumes this too */
@@ -1789,7 +1600,7 @@ void ED_screen_animation_timer(bContext *C, int redraws, int refresh, int sync,
if (sa)
spacetype = sa->spacetype;
- sad->from_anim_edit = (ELEM(spacetype, SPACE_IPO, SPACE_ACTION, SPACE_NLA, SPACE_TIME));
+ sad->from_anim_edit = (ELEM(spacetype, SPACE_IPO, SPACE_ACTION, SPACE_NLA));
screen->animtimer->customdata = sad;
@@ -1837,13 +1648,10 @@ void ED_screen_animation_timer_update(bScreen *screen, int redraws, int refresh)
}
}
-/* results in fully updated anim system
- * screen can be NULL */
-void ED_update_for_newframe(Main *bmain, Scene *scene, int UNUSED(mute))
+/* results in fully updated anim system */
+void ED_update_for_newframe(Main *bmain, Depsgraph *depsgraph)
{
- wmWindowManager *wm = bmain->wm.first;
- wmWindow *window;
- int layers = 0;
+ Scene *scene = DEG_get_input_scene(depsgraph);
#ifdef DURIAN_CAMERA_SWITCH
void *camera = BKE_scene_camera_switch_find(scene);
@@ -1852,19 +1660,15 @@ void ED_update_for_newframe(Main *bmain, Scene *scene, int UNUSED(mute))
scene->camera = camera;
/* are there cameras in the views that are not in the scene? */
for (sc = bmain->screen.first; sc; sc = sc->id.next) {
- BKE_screen_view3d_scene_sync(sc);
+ BKE_screen_view3d_scene_sync(sc, scene);
}
}
#endif
ED_clip_update_frame(bmain, scene->r.cfra);
- /* get layers from all windows */
- for (window = wm->windows.first; window; window = window->next)
- layers |= BKE_screen_visible_layers(window->screen, scene);
-
/* this function applies the changes too */
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, layers);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
/* composite */
if (scene->use_nodes && scene->nodetree)
@@ -1885,11 +1689,10 @@ void ED_update_for_newframe(Main *bmain, Scene *scene, int UNUSED(mute))
/*
* return true if any active area requires to see in 3D
*/
-bool ED_screen_stereo3d_required(bScreen *screen)
+bool ED_screen_stereo3d_required(const bScreen *screen, const Scene *scene)
{
ScrArea *sa;
- Scene *sce = screen->scene;
- const bool is_multiview = (sce->r.scemode & R_MULTIVIEW) != 0;
+ const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0;
for (sa = screen->areabase.first; sa; sa = sa->next) {
switch (sa->spacetype) {
@@ -1964,3 +1767,40 @@ bool ED_screen_stereo3d_required(bScreen *screen)
return false;
}
+
+/**
+ * Find the scene displayed in \a screen.
+ * \note Assumes \a screen to be visible/active!
+ */
+
+Scene *ED_screen_scene_find_with_window(const bScreen *screen, const wmWindowManager *wm, struct wmWindow **r_window)
+{
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ if (WM_window_get_active_screen(win) == screen) {
+ if (r_window) {
+ *r_window = win;
+ }
+ return WM_window_get_active_scene(win);
+ }
+ }
+
+ BLI_assert(0);
+ return NULL;
+}
+
+
+Scene *ED_screen_scene_find(const bScreen *screen, const wmWindowManager *wm)
+{
+ return ED_screen_scene_find_with_window(screen, wm, NULL);
+}
+
+
+wmWindow *ED_screen_window_find(const bScreen *screen, const wmWindowManager *wm)
+{
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ if (WM_window_get_active_screen(win) == screen) {
+ return win;
+ }
+ }
+ return NULL;
+}
diff --git a/source/blender/editors/screen/screen_intern.h b/source/blender/editors/screen/screen_intern.h
index db5259f5865..045e5ee6b48 100644
--- a/source/blender/editors/screen/screen_intern.h
+++ b/source/blender/editors/screen/screen_intern.h
@@ -33,6 +33,7 @@
struct bContext;
struct bContextDataResult;
+struct Main;
/* internal exports only */
@@ -43,23 +44,28 @@ struct bContextDataResult;
/* area.c */
void ED_area_data_copy(ScrArea *sa_dst, ScrArea *sa_src, const bool do_free);
void ED_area_data_swap(ScrArea *sa1, ScrArea *sa2);
-void region_toggle_hidden(struct bContext *C, ARegion *ar, const bool do_fade);
+void screen_area_update_region_sizes(wmWindowManager *wm, wmWindow *win, ScrArea *area);
+void region_toggle_hidden(struct bContext *C, ARegion *ar, const bool do_fade);
/* screen_edit.c */
-ScrEdge *screen_findedge(bScreen *sc, ScrVert *v1, ScrVert *v2);
+bScreen *screen_add(const char *name, const int winsize_x, const int winsize_y);
+void screen_data_copy(bScreen *to, bScreen *from);
+void screen_new_activate_prepare(const wmWindow *win, bScreen *screen_new);
+void screen_change_update(struct bContext *C, wmWindow *win, bScreen *sc);
+bScreen *screen_change_prepare(bScreen *screen_old, bScreen *screen_new, struct Main *bmain, struct bContext *C, wmWindow *win);
ScrArea *area_split(bScreen *sc, ScrArea *sa, char dir, float fac, int merge);
int screen_area_join(struct bContext *C, bScreen *scr, ScrArea *sa1, ScrArea *sa2);
int area_getorientation(ScrArea *sa, ScrArea *sb);
-void select_connected_scredge(bScreen *sc, ScrEdge *edge);
+void select_connected_scredge(const wmWindow *win, ScrEdge *edge);
-void removenotused_scrverts(bScreen *sc);
-void removedouble_scrverts(bScreen *sc);
-void removedouble_scredges(bScreen *sc);
-void removenotused_scredges(bScreen *sc);
bool scredge_is_horizontal(ScrEdge *se);
-ScrEdge *screen_find_active_scredge(bScreen *sc,
- const int winsize_x, const int winsize_y,
- const int mx, const int my);
+ScrEdge *screen_area_map_find_active_scredge(
+ const struct ScrAreaMap *area_map,
+ const int winsize_x, const int winsize_y,
+ const int mx, const int my);
+ScrEdge *screen_find_active_scredge(
+ const wmWindow *win, const bScreen *screen,
+ const int mx, const int my);
struct AZone *is_in_area_actionzone(ScrArea *sa, const int xy[2]);
@@ -76,5 +82,8 @@ void SCREEN_OT_screencast(struct wmOperatorType *ot);
/* screen_ops.c */
void region_blend_start(struct bContext *C, struct ScrArea *sa, struct ARegion *ar);
+/* workspace_layout_edit.c */
+bool workspace_layout_set_poll(const struct WorkSpaceLayout *layout);
+
#endif /* __SCREEN_INTERN_H__ */
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index cbdf05a1c82..df0466075ef 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -48,11 +48,13 @@
#include "DNA_meta_types.h"
#include "DNA_mask_types.h"
#include "DNA_node_types.h"
+#include "DNA_workspace_types.h"
#include "DNA_userdef_types.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
#include "BKE_global.h"
+#include "BKE_icons.h"
#include "BKE_main.h"
#include "BKE_object.h"
#include "BKE_report.h"
@@ -61,10 +63,13 @@
#include "BKE_editmesh.h"
#include "BKE_sound.h"
#include "BKE_mask.h"
+#include "BKE_workspace.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "DEG_depsgraph.h"
+
#include "ED_armature.h"
#include "ED_clip.h"
#include "ED_image.h"
@@ -134,7 +139,7 @@ int ED_operator_screen_mainwinactive(bContext *C)
if (CTX_wm_window(C) == NULL) return 0;
screen = CTX_wm_screen(C);
if (screen == NULL) return 0;
- if (screen->subwinactive != screen->mainwin) return 0;
+ if (screen->active_region != NULL) return 0;
return 1;
}
@@ -192,7 +197,7 @@ int ED_operator_animview_active(bContext *C)
{
if (ED_operator_areaactive(C)) {
SpaceLink *sl = (SpaceLink *)CTX_wm_space_data(C);
- if (sl && (ELEM(sl->spacetype, SPACE_SEQ, SPACE_ACTION, SPACE_NLA, SPACE_IPO, SPACE_TIME)))
+ if (sl && (ELEM(sl->spacetype, SPACE_SEQ, SPACE_ACTION, SPACE_NLA, SPACE_IPO)))
return true;
}
@@ -200,11 +205,6 @@ int ED_operator_animview_active(bContext *C)
return 0;
}
-int ED_operator_timeline_active(bContext *C)
-{
- return ed_spacetype_test(C, SPACE_TIME);
-}
-
int ED_operator_outliner_active(bContext *C)
{
return ed_spacetype_test(C, SPACE_OUTLINER);
@@ -283,11 +283,6 @@ int ED_operator_nla_active(bContext *C)
return ed_spacetype_test(C, SPACE_NLA);
}
-int ED_operator_logic_active(bContext *C)
-{
- return ed_spacetype_test(C, SPACE_LOGIC);
-}
-
int ED_operator_info_active(bContext *C)
{
return ed_spacetype_test(C, SPACE_INFO);
@@ -544,8 +539,8 @@ int ED_operator_mask(bContext *C)
case SPACE_IMAGE:
{
SpaceImage *sima = sa->spacedata.first;
- Scene *scene = CTX_data_scene(C);
- return ED_space_image_check_show_maskedit(scene, sima);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ return ED_space_image_check_show_maskedit(sima, view_layer);
}
}
}
@@ -553,6 +548,12 @@ int ED_operator_mask(bContext *C)
return false;
}
+int ED_operator_camera(bContext *C)
+{
+ struct Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
+ return (cam != NULL);
+}
+
/** \} */
/* -------------------------------------------------------------------- */
@@ -709,6 +710,59 @@ AZone *is_in_area_actionzone(ScrArea *sa, const int xy[2])
ED_area_tag_redraw(sa);
break;
}
+ else if (az->type == AZONE_REGION_SCROLL) {
+ ARegion *ar = az->ar;
+ View2D *v2d = &ar->v2d;
+ const short isect_value = UI_view2d_mouse_in_scrollers(ar, v2d, xy[0], xy[1]);
+ bool redraw = false;
+
+ if (isect_value == 'h') {
+ if (az->direction == AZ_SCROLL_HOR) {
+ az->alpha = 1.0f;
+ v2d->alpha_hor = 255;
+ v2d->size_hor = V2D_SCROLL_HEIGHT;
+ redraw = true;
+ }
+ }
+ else if (isect_value == 'v') {
+ if (az->direction == AZ_SCROLL_VERT) {
+ az->alpha = 1.0f;
+ v2d->alpha_vert = 255;
+ v2d->size_vert = V2D_SCROLL_WIDTH;
+ redraw = true;
+ }
+ }
+ else {
+ const int local_xy[2] = {xy[0] - ar->winrct.xmin, xy[1] - ar->winrct.ymin};
+ float dist_fac = 0.0f, alpha = 0.0f;
+
+ if (az->direction == AZ_SCROLL_HOR) {
+ dist_fac = BLI_rcti_length_y(&v2d->hor, local_xy[1]) / AZONEFADEIN;
+ CLAMP(dist_fac, 0.0f, 1.0f);
+ alpha = 1.0f - dist_fac;
+
+ v2d->alpha_hor = alpha * 255;
+ v2d->size_hor = round_fl_to_int(V2D_SCROLL_HEIGHT -
+ ((V2D_SCROLL_HEIGHT - V2D_SCROLL_HEIGHT_MIN) * dist_fac));
+ }
+ else if (az->direction == AZ_SCROLL_VERT) {
+ dist_fac = BLI_rcti_length_x(&v2d->vert, local_xy[0]) / AZONEFADEIN;
+ CLAMP(dist_fac, 0.0f, 1.0f);
+ alpha = 1.0f - dist_fac;
+
+ v2d->alpha_vert = alpha * 255;
+ v2d->size_vert = round_fl_to_int(V2D_SCROLL_WIDTH -
+ ((V2D_SCROLL_WIDTH - V2D_SCROLL_WIDTH_MIN) * dist_fac));
+ }
+ az->alpha = alpha;
+ redraw = true;
+ }
+
+ if (redraw) {
+ ED_area_tag_redraw(sa);
+ }
+ /* Don't return! */
+ }
}
}
@@ -771,6 +825,9 @@ static int actionzone_invoke(bContext *C, wmOperator *op, const wmEvent *event)
actionzone_exit(op);
return OPERATOR_FINISHED;
}
+ else if (ELEM(sad->az->type, AZONE_REGION_SCROLL)) {
+ return OPERATOR_PASS_THROUGH;
+ }
else {
/* add modal handler */
WM_event_add_modal_handler(C, op);
@@ -785,8 +842,8 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event)
wmWindow *win = CTX_wm_window(C);
bScreen *sc = CTX_wm_screen(C);
sActionzoneData *sad = op->customdata;
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
+ const int screen_size_x = WM_window_screen_pixels_x(win);
+ const int screen_size_y = WM_window_screen_pixels_y(win);
switch (event->type) {
case MOUSEMOVE:
@@ -810,7 +867,8 @@ static int actionzone_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* once we drag outside the actionzone, register a gesture
* check we're not on an edge so join finds the other area */
is_gesture = ((is_in_area_actionzone(sad->sa1, &event->x) != sad->az) &&
- (screen_find_active_scredge(sc, winsize_x, winsize_y, event->x, event->y) == NULL));
+ (screen_area_map_find_active_scredge(
+ AREAMAP_FROM_SCREEN(sc), screen_size_x, screen_size_y, event->x, event->y) == NULL));
}
else {
const int delta_min = 1;
@@ -999,13 +1057,17 @@ static void SCREEN_OT_area_swap(wmOperatorType *ot)
/* operator callback */
static int area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
- wmWindow *newwin, *win;
- bScreen *newsc, *sc;
+ wmWindow *newwin, *win = CTX_wm_window(C);
+ Scene *scene;
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ WorkSpaceLayout *layout_old = WM_window_get_active_layout(win);
+ WorkSpaceLayout *layout_new;
+ bScreen *newsc;
ScrArea *sa;
rcti rect;
win = CTX_wm_window(C);
- sc = CTX_wm_screen(C);
+ scene = CTX_data_scene(C);
sa = CTX_wm_area(C);
/* XXX hrmf! */
@@ -1031,11 +1093,15 @@ static int area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
*newwin->stereo3d_format = *win->stereo3d_format;
-
+
+ newwin->scene = scene;
+
+ WM_window_set_active_workspace(newwin, workspace);
/* allocs new screen and adds to newly created window, using window size */
- newsc = ED_screen_add(newwin, CTX_data_scene(C), sc->id.name + 2);
- newwin->screen = newsc;
-
+ layout_new = ED_workspace_layout_add(workspace, newwin, BKE_workspace_layout_name_get(layout_old));
+ newsc = BKE_workspace_layout_screen_get(layout_new);
+ WM_window_set_active_layout(newwin, workspace, layout_new);
+
/* copy area to new screen */
ED_area_data_copy((ScrArea *)newsc->areabase.first, sa, true);
@@ -1102,25 +1168,73 @@ static void SCREEN_OT_area_dupli(wmOperatorType *ot)
*/
typedef struct sAreaMoveData {
- int bigger, smaller, origval;
+ int bigger, smaller, origval, step;
char dir;
- bool do_snap;
+ enum AreaMoveSnapType {
+ /* Snapping disabled */
+ SNAP_NONE = 0,
+ /* Snap to mid-point and adjacent edges. */
+ SNAP_MIDPOINT_AND_ADJACENT,
+ /* Snap to either bigger or smaller, nothing in-between (used for
+ * global areas). This has priority over other snap types, if it is
+ * used, toggling SNAP_MIDPOINT_AND_ADJACENT doesn't work. */
+ SNAP_BIGGER_SMALLER_ONLY,
+ } snap_type;
} sAreaMoveData;
/* helper call to move area-edge, sets limits
* need window size in order to get correct limits */
-static void area_move_set_limits(bScreen *sc, int dir,
- const int winsize_x, const int winsize_y,
- int *bigger, int *smaller)
+static void area_move_set_limits(
+ wmWindow *win, bScreen *sc, int dir,
+ const int winsize_x, const int winsize_y,
+ int *bigger, int *smaller,
+ bool *use_bigger_smaller_snap)
{
- ScrArea *sa;
int areaminy = ED_area_headersize();
int areamin;
-
+
/* we check all areas and test for free space with MINSIZE */
*bigger = *smaller = 100000;
-
- for (sa = sc->areabase.first; sa; sa = sa->next) {
+
+ if (use_bigger_smaller_snap != NULL) {
+ *use_bigger_smaller_snap = false;
+ for (ScrArea *area = win->global_areas.areabase.first; area; area = area->next) {
+ const int size_min = round_fl_to_int(area->global->size_min * UI_DPI_FAC);
+ const int size_max = round_fl_to_int(area->global->size_max * UI_DPI_FAC);
+
+ /* logic here is only tested for lower edge :) */
+ /* left edge */
+ if ((area->v1->editflag && area->v2->editflag)) {
+ *smaller = area->v4->vec.x - size_max;
+ *bigger = area->v4->vec.x - size_min;
+ *use_bigger_smaller_snap = true;
+ return;
+ }
+ /* top edge */
+ else if ((area->v2->editflag && area->v3->editflag)) {
+ *smaller = area->v1->vec.y + size_min;
+ *bigger = area->v1->vec.y + size_max;
+ *use_bigger_smaller_snap = true;
+ return;
+ }
+ /* right edge */
+ else if ((area->v3->editflag && area->v4->editflag)) {
+ *smaller = area->v1->vec.x + size_min;
+ *bigger = area->v1->vec.x + size_max;
+ *use_bigger_smaller_snap = true;
+ return;
+ }
+ /* lower edge */
+ else if ((area->v4->editflag && area->v1->editflag)) {
+ *smaller = area->v2->vec.y - size_max;
+ *bigger = area->v2->vec.y - size_min;
+ *use_bigger_smaller_snap = true;
+ return;
+ }
+ }
+ }
+
+ for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
if (dir == 'h') {
int y1;
areamin = areaminy;
@@ -1166,9 +1280,8 @@ static int area_move_init(bContext *C, wmOperator *op)
wmWindow *win = CTX_wm_window(C);
ScrEdge *actedge;
sAreaMoveData *md;
- ScrVert *v1;
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
+ const int screen_size_x = WM_window_screen_pixels_x(win);
+ const int screen_size_y = WM_window_screen_pixels_y(win);
int x, y;
/* required properties */
@@ -1176,7 +1289,7 @@ static int area_move_init(bContext *C, wmOperator *op)
y = RNA_int_get(op->ptr, "y");
/* setup */
- actedge = screen_find_active_scredge(sc, winsize_x, winsize_y, x, y);
+ actedge = screen_find_active_scredge(win, sc, x, y);
if (actedge == NULL) return 0;
md = MEM_callocN(sizeof(sAreaMoveData), "sAreaMoveData");
@@ -1186,23 +1299,33 @@ static int area_move_init(bContext *C, wmOperator *op)
if (md->dir == 'h') md->origval = actedge->v1->vec.y;
else md->origval = actedge->v1->vec.x;
- select_connected_scredge(sc, actedge);
- /* now all vertices with 'flag==1' are the ones that can be moved. Move this to editflag */
- for (v1 = sc->vertbase.first; v1; v1 = v1->next)
+ select_connected_scredge(win, actedge);
+ /* now all vertices with 'flag == 1' are the ones that can be moved. Move this to editflag */
+ ED_screen_verts_iter(win, sc, v1) {
v1->editflag = v1->flag;
-
- area_move_set_limits(sc, md->dir, winsize_x, winsize_y, &md->bigger, &md->smaller);
-
+ }
+
+ bool use_bigger_smaller_snap = false;
+ area_move_set_limits(win, sc, md->dir, screen_size_x, screen_size_y,
+ &md->bigger, &md->smaller,
+ &use_bigger_smaller_snap);
+
+ md->snap_type = use_bigger_smaller_snap ? SNAP_BIGGER_SMALLER_ONLY : SNAP_NONE;
+
return 1;
}
static int area_snap_calc_location(
- const bScreen *sc, const int delta,
- const int origval, const int dir,
+ const bScreen *sc, const enum AreaMoveSnapType snap_type,
+ const int delta, const int origval, const int dir,
const int bigger, const int smaller)
{
- int final_loc = -1;
+ BLI_assert(snap_type != SNAP_NONE);
+ if (snap_type == SNAP_BIGGER_SMALLER_ONLY) {
+ return ((origval + delta) >= bigger) ? bigger : smaller;
+ }
+ int final_loc = -1;
const int m_loc = origval + delta;
const int axis = (dir == 'v') ? 0 : 1;
int snap_dist;
@@ -1246,29 +1369,29 @@ static void area_move_apply_do(
const bContext *C, int delta,
const int origval, const int dir,
const int bigger, const int smaller,
- const bool do_snap)
+ const enum AreaMoveSnapType snap_type)
{
+ wmWindow *win = CTX_wm_window(C);
bScreen *sc = CTX_wm_screen(C);
- ScrVert *v1;
bool doredraw = false;
CLAMP(delta, -smaller, bigger);
short final_loc = -1;
- if (do_snap) {
- final_loc = area_snap_calc_location(sc, delta, origval, dir, bigger, smaller);
- }
- else {
+ if (snap_type == SNAP_NONE) {
final_loc = origval + delta;
if (delta != bigger && delta != -smaller) {
final_loc -= (final_loc % AREAGRID);
}
}
+ else {
+ final_loc = area_snap_calc_location(sc, snap_type, delta, origval, dir, bigger, smaller);
+ }
BLI_assert(final_loc != -1);
short axis = (dir == 'v') ? 0 : 1;
- for (v1 = sc->vertbase.first; v1; v1 = v1->next) {
+ ED_screen_verts_iter(win, sc, v1) {
if (v1->editflag) {
short oldval = (&v1->vec.x)[axis];
(&v1->vec.x)[axis] = final_loc;
@@ -1283,12 +1406,26 @@ static void area_move_apply_do(
/* only redraw if we actually moved a screen vert, for AREAGRID */
if (doredraw) {
- for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
+ bool redraw_all = false;
+ ED_screen_areas_iter(win, sc, sa) {
if (sa->v1->editflag || sa->v2->editflag || sa->v3->editflag || sa->v4->editflag) {
+ if (ED_area_is_global(sa)) {
+ sa->global->cur_fixed_height = round_fl_to_int((sa->v2->vec.y - sa->v1->vec.y) / UI_DPI_FAC);
+ sc->do_refresh = true;
+ redraw_all = true;
+ }
+ ED_area_tag_redraw(sa);
+ }
+ }
+ if (redraw_all) {
+ ED_screen_areas_iter(win, sc, sa) {
ED_area_tag_redraw(sa);
}
}
+
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL); /* redraw everything */
+ /* Update preview thumbnail */
+ BKE_icon_changed(sc->id.icon_id);
}
}
@@ -1297,7 +1434,7 @@ static void area_move_apply(bContext *C, wmOperator *op)
sAreaMoveData *md = op->customdata;
int delta = RNA_int_get(op->ptr, "delta");
- area_move_apply_do(C, delta, md->origval, md->dir, md->bigger, md->smaller, md->do_snap);
+ area_move_apply_do(C, delta, md->origval, md->dir, md->bigger, md->smaller, md->snap_type);
}
static void area_move_exit(bContext *C, wmOperator *op)
@@ -1307,8 +1444,8 @@ static void area_move_exit(bContext *C, wmOperator *op)
op->customdata = NULL;
/* this makes sure aligned edges will result in aligned grabbing */
- removedouble_scrverts(CTX_wm_screen(C));
- removedouble_scredges(CTX_wm_screen(C));
+ BKE_screen_remove_double_scrverts(CTX_wm_screen(C));
+ BKE_screen_remove_double_scredges(CTX_wm_screen(C));
}
static int area_move_exec(bContext *C, wmOperator *op)
@@ -1376,10 +1513,14 @@ static int area_move_modal(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_CANCELLED;
case KM_MODAL_SNAP_ON:
- md->do_snap = true;
+ if (md->snap_type == SNAP_NONE) {
+ md->snap_type = SNAP_MIDPOINT_AND_ADJACENT;
+ }
break;
case KM_MODAL_SNAP_OFF:
- md->do_snap = false;
+ if (md->snap_type == SNAP_MIDPOINT_AND_ADJACENT) {
+ md->snap_type = SNAP_NONE;
+ }
break;
}
break;
@@ -1536,16 +1677,16 @@ static ScrEdge *area_findsharededge(bScreen *screen, ScrArea *sa, ScrArea *sb)
ScrVert *sbv4 = sb->v4;
if (sav1 == sbv4 && sav2 == sbv3) { /* sa to right of sb = W */
- return screen_findedge(screen, sav1, sav2);
+ return BKE_screen_find_edge(screen, sav1, sav2);
}
else if (sav2 == sbv1 && sav3 == sbv4) { /* sa to bottom of sb = N */
- return screen_findedge(screen, sav2, sav3);
+ return BKE_screen_find_edge(screen, sav2, sav3);
}
else if (sav3 == sbv2 && sav4 == sbv1) { /* sa to left of sb = E */
- return screen_findedge(screen, sav3, sav4);
+ return BKE_screen_find_edge(screen, sav3, sav4);
}
else if (sav1 == sbv2 && sav4 == sbv3) { /* sa on top of sb = S*/
- return screen_findedge(screen, sav1, sav4);
+ return BKE_screen_find_edge(screen, sav1, sav4);
}
return NULL;
@@ -1584,7 +1725,9 @@ static int area_split_apply(bContext *C, wmOperator *op)
ED_area_tag_redraw(sd->narea);
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
-
+ /* Update preview thumbnail */
+ BKE_icon_changed(sc->id.icon_id);
+
return 1;
}
@@ -1609,8 +1752,8 @@ static void area_split_exit(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
/* this makes sure aligned edges will result in aligned grabbing */
- removedouble_scrverts(CTX_wm_screen(C));
- removedouble_scredges(CTX_wm_screen(C));
+ BKE_screen_remove_double_scrverts(CTX_wm_screen(C));
+ BKE_screen_remove_double_scredges(CTX_wm_screen(C));
}
static void area_split_preview_update_cursor(bContext *C, wmOperator *op)
@@ -1626,8 +1769,8 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmWindow *win = CTX_wm_window(C);
bScreen *sc = CTX_wm_screen(C);
sAreaSplitData *sd;
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
+ const int screen_size_x = WM_window_screen_pixels_x(win);
+ const int screen_size_y = WM_window_screen_pixels_y(win);
int dir;
/* no full window splitting allowed */
@@ -1680,7 +1823,7 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
else
y = event->x;
- actedge = screen_find_active_scredge(sc, winsize_x, winsize_y, x, y);
+ actedge = screen_area_map_find_active_scredge(AREAMAP_FROM_SCREEN(sc), screen_size_x, screen_size_y, x, y);
if (actedge == NULL)
return OPERATOR_CANCELLED;
@@ -1700,7 +1843,7 @@ static int area_split_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* do the split */
if (area_split_apply(C, op)) {
- area_move_set_limits(sc, dir, winsize_x, winsize_y, &sd->bigger, &sd->smaller);
+ area_move_set_limits(win, sc, dir, screen_size_x, screen_size_y, &sd->bigger, &sd->smaller, NULL);
/* add temp handler for edge move or cancel */
WM_event_add_modal_handler(C, op);
@@ -1818,10 +1961,11 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
if (sd->previewmode == 0) {
if (sd->do_snap) {
const int snap_loc = area_snap_calc_location(
- CTX_wm_screen(C), sd->delta, sd->origval, dir, sd->bigger, sd->smaller);
+ CTX_wm_screen(C), SNAP_MIDPOINT_AND_ADJACENT, sd->delta, sd->origval, dir,
+ sd->bigger, sd->smaller);
sd->delta = snap_loc - sd->origval;
}
- area_move_apply_do(C, sd->delta, sd->origval, dir, sd->bigger, sd->smaller, false);
+ area_move_apply_do(C, sd->delta, sd->origval, dir, sd->bigger, sd->smaller, SNAP_NONE);
}
else {
if (sd->sarea) {
@@ -1845,7 +1989,8 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 1;
const int snap_loc = area_snap_calc_location(
- CTX_wm_screen(C), sd->delta, sd->origval, dir, sd->origmin + sd->origsize, -sd->origmin);
+ CTX_wm_screen(C), SNAP_MIDPOINT_AND_ADJACENT, sd->delta, sd->origval, dir,
+ sd->origmin + sd->origsize, -sd->origmin);
sa->v1->editflag = sa->v2->editflag = sa->v3->editflag = sa->v4->editflag = 0;
sd->delta = snap_loc - sd->origval;
@@ -1854,7 +1999,7 @@ static int area_split_modal(bContext *C, wmOperator *op, const wmEvent *event)
ED_area_tag_redraw(sd->sarea);
}
- CTX_wm_window(C)->screen->do_draw = true;
+ CTX_wm_screen(C)->do_draw = true;
}
float fac = (float)(sd->delta + sd->origval - sd->origmin) / sd->origsize;
@@ -2023,7 +2168,8 @@ static int region_scale_get_maxsize(RegionMoveData *rmd)
if (rmd->ar->regiontype == RGN_TYPE_TOOL_PROPS) {
/* this calculation seems overly verbose
* can someone explain why this method is necessary? - campbell */
- maxsize = rmd->maxsize - ((rmd->sa->headertype == HEADERTOP) ? UI_UNIT_Y * 2 : UI_UNIT_Y) - (UI_UNIT_Y / 4);
+ const bool top_header = ED_area_header_alignment(rmd->sa) == RGN_ALIGN_TOP;
+ maxsize = rmd->maxsize - ((top_header) ? UI_UNIT_Y * 2 : UI_UNIT_Y) - (UI_UNIT_Y / 4);
}
return maxsize;
@@ -2067,7 +2213,9 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
/* execute the events */
switch (event->type) {
case MOUSEMOVE:
-
+ {
+ const float aspect = BLI_rctf_size_x(&rmd->ar->v2d.cur) / (BLI_rcti_size_x(&rmd->ar->v2d.mask) + 1);
+ const int snap_size_threshold = (U.widget_unit * 3) / aspect;
if (rmd->edge == AE_LEFT_TO_TOPRIGHT || rmd->edge == AE_RIGHT_TO_TOPLEFT) {
delta = event->x - rmd->origx;
if (rmd->edge == AE_LEFT_TO_TOPRIGHT) delta = -delta;
@@ -2076,8 +2224,15 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
delta /= UI_DPI_FAC;
rmd->ar->sizex = rmd->origval + delta;
+
+ if (rmd->ar->type->snap_size) {
+ short sizex_test = rmd->ar->type->snap_size(rmd->ar, rmd->ar->sizex, 0);
+ if (ABS(rmd->ar->sizex - sizex_test) < snap_size_threshold) {
+ rmd->ar->sizex = sizex_test;
+ }
+ }
CLAMP(rmd->ar->sizex, 0, rmd->maxsize);
-
+
if (rmd->ar->sizex < UI_UNIT_X) {
rmd->ar->sizex = rmd->origval;
if (!(rmd->ar->flag & RGN_FLAG_HIDDEN))
@@ -2095,6 +2250,13 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
delta /= UI_DPI_FAC;
rmd->ar->sizey = rmd->origval + delta;
+
+ if (rmd->ar->type->snap_size) {
+ short sizey_test = rmd->ar->type->snap_size(rmd->ar, rmd->ar->sizey, 1);
+ if (ABS(rmd->ar->sizey - sizey_test) < snap_size_threshold) {
+ rmd->ar->sizey = sizey_test;
+ }
+ }
CLAMP(rmd->ar->sizey, 0, rmd->maxsize);
/* note, 'UI_UNIT_Y/4' means you need to drag the header almost
@@ -2114,7 +2276,7 @@ static int region_scale_modal(bContext *C, wmOperator *op, const wmEvent *event)
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
break;
-
+ }
case LEFTMOUSE:
if (event->val == KM_RELEASE) {
@@ -2177,16 +2339,15 @@ static void areas_do_frame_follow(bContext *C, bool middle)
bScreen *scr = CTX_wm_screen(C);
Scene *scene = CTX_data_scene(C);
wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *window;
- for (window = wm->windows.first; window; window = window->next) {
- ScrArea *sa;
- for (sa = window->screen->areabase.first; sa; sa = sa->next) {
- ARegion *ar;
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
+ for (wmWindow *window = wm->windows.first; window; window = window->next) {
+ const bScreen *screen = WM_window_get_active_screen(window);
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
/* do follow here if editor type supports it */
if ((scr->redraws_flag & TIME_FOLLOW)) {
if ((ar->regiontype == RGN_TYPE_WINDOW &&
- ELEM(sa->spacetype, SPACE_SEQ, SPACE_TIME, SPACE_IPO, SPACE_ACTION, SPACE_NLA)) ||
+ ELEM(sa->spacetype, SPACE_SEQ, SPACE_IPO, SPACE_ACTION, SPACE_NLA)) ||
(sa->spacetype == SPACE_CLIP && ar->regiontype == RGN_TYPE_PREVIEW))
{
float w = BLI_rctf_size_x(&ar->v2d.cur);
@@ -2497,64 +2658,16 @@ static void SCREEN_OT_marker_jump(wmOperatorType *ot)
/** \name Set Screen Operator
* \{ */
-static bool screen_set_is_ok(bScreen *screen, bScreen *screen_prev)
-{
- return ((screen->winid == 0) &&
- /* in typical usage these should have a nonzero winid
- * (all temp screens should be used, or closed & freed). */
- (screen->temp == false) &&
- (screen->state == SCREENNORMAL) &&
- (screen != screen_prev) &&
- (screen->id.name[2] != '.' || !(U.uiflag & USER_HIDE_DOT)));
-}
-
/* function to be called outside UI context, or for redo */
static int screen_set_exec(bContext *C, wmOperator *op)
{
- Main *bmain = CTX_data_main(C);
- bScreen *screen = CTX_wm_screen(C);
- bScreen *screen_prev = screen;
-
- ScrArea *sa = CTX_wm_area(C);
- int tot = BLI_listbase_count(&bmain->screen);
+ WorkSpace *workspace = CTX_wm_workspace(C);
int delta = RNA_int_get(op->ptr, "delta");
-
- /* temp screens are for userpref or render display */
- if (screen->temp || (sa && sa->full && sa->full->temp)) {
- return OPERATOR_CANCELLED;
- }
-
- if (delta == 1) {
- while (tot--) {
- screen = screen->id.next;
- if (screen == NULL) screen = bmain->screen.first;
- if (screen_set_is_ok(screen, screen_prev)) {
- break;
- }
- }
- }
- else if (delta == -1) {
- while (tot--) {
- screen = screen->id.prev;
- if (screen == NULL) screen = bmain->screen.last;
- if (screen_set_is_ok(screen, screen_prev)) {
- break;
- }
- }
- }
- else {
- screen = NULL;
- }
-
- if (screen && screen_prev != screen) {
- /* return to previous state before switching screens */
- if (sa && sa->full) {
- ED_screen_full_restore(C, sa); /* may free 'screen_prev' */
- }
-
- ED_screen_set(C, screen);
+
+ if (ED_workspace_layout_cycle(workspace, delta, C)) {
return OPERATOR_FINISHED;
}
+
return OPERATOR_CANCELLED;
}
@@ -2610,6 +2723,14 @@ static int screen_maximize_area_exec(bContext *C, wmOperator *op)
return OPERATOR_FINISHED;
}
+static int screen_maximize_area_poll(bContext *C)
+{
+ const bScreen *screen = CTX_wm_screen(C);
+ const ScrArea *area = CTX_wm_area(C);
+ return ED_operator_areaactive(C) &&
+ ((screen->state != SCREENNORMAL) || (area->spacetype != SPACE_TOPBAR));
+}
+
static void SCREEN_OT_screen_full_area(wmOperatorType *ot)
{
PropertyRNA *prop;
@@ -2619,7 +2740,7 @@ static void SCREEN_OT_screen_full_area(wmOperatorType *ot)
ot->idname = "SCREEN_OT_screen_full_area";
ot->exec = screen_maximize_area_exec;
- ot->poll = ED_operator_areaactive;
+ ot->poll = screen_maximize_area_poll;
ot->flag = 0;
prop = RNA_def_boolean(ot->srna, "use_hide_panels", false, "Hide Panels", "Hide all the panels");
@@ -2752,9 +2873,9 @@ static void area_join_exit(bContext *C, wmOperator *op)
}
/* this makes sure aligned edges will result in aligned grabbing */
- removedouble_scredges(CTX_wm_screen(C));
- removenotused_scredges(CTX_wm_screen(C));
- removenotused_scrverts(CTX_wm_screen(C));
+ BKE_screen_remove_double_scredges(CTX_wm_screen(C));
+ BKE_screen_remove_unused_scredges(CTX_wm_screen(C));
+ BKE_screen_remove_unused_scrverts(CTX_wm_screen(C));
}
static int area_join_exec(bContext *C, wmOperator *op)
@@ -2929,10 +3050,11 @@ static int screen_area_options_invoke(bContext *C, wmOperator *op, const wmEvent
uiLayout *layout;
PointerRNA ptr;
ScrEdge *actedge;
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
+ const int screen_size_x = WM_window_screen_pixels_x(win);
+ const int screen_size_y = WM_window_screen_pixels_y(win);
- actedge = screen_find_active_scredge(sc, winsize_x, winsize_y, event->x, event->y);
+ actedge = screen_area_map_find_active_scredge(
+ AREAMAP_FROM_SCREEN(sc), screen_size_x, screen_size_y, event->x, event->y);
if (actedge == NULL) return OPERATOR_CANCELLED;
@@ -3336,6 +3458,18 @@ static int region_flip_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
}
+static int region_flip_poll(bContext *C)
+{
+ ScrArea *area = CTX_wm_area(C);
+
+ /* don't flip anything around in topbar */
+ if (area->spacetype == SPACE_TOPBAR) {
+ CTX_wm_operator_poll_msg_set(C, "Flipping regions in the Top-bar is not allowed");
+ return 0;
+ }
+
+ return ED_operator_areaactive(C);
+}
static void SCREEN_OT_region_flip(wmOperatorType *ot)
{
@@ -3346,7 +3480,7 @@ static void SCREEN_OT_region_flip(wmOperatorType *ot)
/* api callbacks */
ot->exec = region_flip_exec;
- ot->poll = ED_operator_areaactive;
+ ot->poll = region_flip_poll;
ot->flag = 0;
}
@@ -3398,7 +3532,7 @@ static int header_toggle_menus_exec(bContext *C, wmOperator *UNUSED(op))
sa->flag = sa->flag ^ HEADER_NO_PULLDOWN;
ED_area_tag_redraw(sa);
- WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
+ WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
return OPERATOR_FINISHED;
}
@@ -3439,12 +3573,11 @@ void ED_screens_header_tools_menu_create(bContext *C, uiLayout *layout, void *UN
uiItemS(layout);
- /* file browser should be fullscreen all the time, but other regions can be maximized/restored... */
- if (sa->spacetype != SPACE_FILE) {
- if (sa->full)
- uiItemO(layout, IFACE_("Tile Area"), ICON_NONE, "SCREEN_OT_screen_full_area");
- else
- uiItemO(layout, IFACE_("Maximize Area"), ICON_NONE, "SCREEN_OT_screen_full_area");
+ /* file browser should be fullscreen all the time, topbar should
+ * never be. But other regions can be maximized/restored... */
+ if (!ELEM(sa->spacetype, SPACE_FILE, SPACE_TOPBAR)) {
+ const char *but_str = sa->full ? IFACE_("Tile Area") : IFACE_("Maximize Area");
+ uiItemO(layout, but_str, ICON_NONE, "SCREEN_OT_screen_full_area");
}
}
@@ -3504,13 +3637,14 @@ static int match_region_with_redraws(int spacetype, int regiontype, int redraws,
return 1;
break;
case SPACE_IPO:
- case SPACE_ACTION:
case SPACE_NLA:
if ((redraws & TIME_ALL_ANIM_WIN) || from_anim_edit)
return 1;
break;
- case SPACE_TIME:
- /* if only 1 window or 3d windows, we do timeline too */
+ case SPACE_ACTION:
+ /* if only 1 window or 3d windows, we do timeline too
+ * NOTE: Now we do do action editor in all these cases, since timeline is here
+ */
if ((redraws & (TIME_ALL_ANIM_WIN | TIME_REGION | TIME_ALL_3D_WIN)) || from_anim_edit)
return 1;
break;
@@ -3561,7 +3695,7 @@ static int match_region_with_redraws(int spacetype, int regiontype, int redraws,
return 1;
}
else if (regiontype == RGN_TYPE_HEADER) {
- if (spacetype == SPACE_TIME)
+ if (spacetype == SPACE_ACTION)
return 1;
}
else if (regiontype == RGN_TYPE_PREVIEW) {
@@ -3591,6 +3725,7 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv
if (screen->animtimer && screen->animtimer == event->customdata) {
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
wmTimer *wt = screen->animtimer;
ScreenAnimData *sad = wt->customdata;
wmWindowManager *wm = CTX_wm_manager(C);
@@ -3701,10 +3836,12 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv
}
/* since we follow drawflags, we can't send notifier but tag regions ourselves */
- ED_update_for_newframe(bmain, scene, 1);
+ ED_update_for_newframe(bmain, depsgraph);
for (window = wm->windows.first; window; window = window->next) {
- for (sa = window->screen->areabase.first; sa; sa = sa->next) {
+ const bScreen *win_screen = WM_window_get_active_screen(window);
+
+ for (sa = win_screen->areabase.first; sa; sa = sa->next) {
ARegion *ar;
for (ar = sa->regionbase.first; ar; ar = ar->next) {
bool redraw = false;
@@ -3720,7 +3857,7 @@ static int screen_animation_step(bContext *C, wmOperator *UNUSED(op), const wmEv
/* do follow here if editor type supports it */
if ((sad->redraws & TIME_FOLLOW)) {
if ((ar->regiontype == RGN_TYPE_WINDOW &&
- ELEM(sa->spacetype, SPACE_SEQ, SPACE_TIME, SPACE_IPO, SPACE_ACTION, SPACE_NLA)) ||
+ ELEM(sa->spacetype, SPACE_SEQ, SPACE_IPO, SPACE_ACTION, SPACE_NLA)) ||
(sa->spacetype == SPACE_CLIP && ar->regiontype == RGN_TYPE_PREVIEW))
{
float w = BLI_rctf_size_x(&ar->v2d.cur);
@@ -3784,11 +3921,11 @@ static void SCREEN_OT_animation_step(wmOperatorType *ot)
/* find window that owns the animation timer */
bScreen *ED_screen_animation_playing(const wmWindowManager *wm)
{
- wmWindow *win;
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ bScreen *screen = WM_window_get_active_screen(win);
- for (win = wm->windows.first; win; win = win->next) {
- if (win->screen->animtimer || win->screen->scrubbing) {
- return win->screen;
+ if (screen->animtimer || screen->scrubbing) {
+ return screen;
}
}
@@ -3797,11 +3934,11 @@ bScreen *ED_screen_animation_playing(const wmWindowManager *wm)
bScreen *ED_screen_animation_no_scrub(const wmWindowManager *wm)
{
- wmWindow *win;
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ bScreen *screen = WM_window_get_active_screen(win);
- for (win = wm->windows.first; win; win = win->next) {
- if (win->screen->animtimer) {
- return win->screen;
+ if (screen->animtimer) {
+ return screen;
}
}
@@ -3823,7 +3960,7 @@ int ED_screen_animation_play(bContext *C, int sync, int mode)
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
}
else {
- int refresh = SPACE_TIME; /* these settings are currently only available from a menu in the TimeLine */
+ int refresh = SPACE_ACTION; /* these settings are currently only available from a menu in the TimeLine */
if (mode == 1) /* XXX only play audio forwards!? */
BKE_sound_play_scene(scene);
@@ -4059,11 +4196,13 @@ static void SCREEN_OT_userpref_show(struct wmOperatorType *ot)
static int screen_new_exec(bContext *C, wmOperator *UNUSED(op))
{
wmWindow *win = CTX_wm_window(C);
- bScreen *sc = CTX_wm_screen(C);
-
- sc = ED_screen_duplicate(win, sc);
- WM_event_add_notifier(C, NC_SCREEN | ND_SCREENBROWSE, sc);
-
+ WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+ WorkSpaceLayout *layout_old = BKE_workspace_active_layout_get(win->workspace_hook);
+ WorkSpaceLayout *layout_new;
+
+ layout_new = ED_workspace_layout_duplicate(workspace, layout_old, win);
+ WM_event_add_notifier(C, NC_SCREEN | ND_LAYOUTBROWSE, layout_new);
+
return OPERATOR_FINISHED;
}
@@ -4088,9 +4227,11 @@ static void SCREEN_OT_new(wmOperatorType *ot)
static int screen_delete_exec(bContext *C, wmOperator *UNUSED(op))
{
bScreen *sc = CTX_wm_screen(C);
-
- WM_event_add_notifier(C, NC_SCREEN | ND_SCREENDELETE, sc);
-
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ WorkSpaceLayout *layout = BKE_workspace_layout_find(workspace, sc);
+
+ WM_event_add_notifier(C, NC_SCREEN | ND_LAYOUTDELETE, layout);
+
return OPERATOR_FINISHED;
}
@@ -4108,103 +4249,6 @@ static void SCREEN_OT_delete(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name New Scene Operator
- * \{ */
-
-static int scene_new_exec(bContext *C, wmOperator *op)
-{
- Scene *newscene, *scene = CTX_data_scene(C);
- Main *bmain = CTX_data_main(C);
- int type = RNA_enum_get(op->ptr, "type");
-
- if (type == SCE_COPY_NEW) {
- newscene = BKE_scene_add(bmain, DATA_("Scene"));
- }
- else { /* different kinds of copying */
- newscene = BKE_scene_copy(bmain, scene, type);
-
- /* these can't be handled in blenkernel currently, so do them here */
- if (type == SCE_COPY_LINK_DATA) {
- ED_object_single_users(bmain, newscene, false, true);
- }
- else if (type == SCE_COPY_FULL) {
- ED_editors_flush_edits(C, false);
- ED_object_single_users(bmain, newscene, true, true);
- }
- }
-
- ED_screen_set_scene(C, CTX_wm_screen(C), newscene);
-
- WM_event_add_notifier(C, NC_SCENE | ND_SCENEBROWSE, newscene);
-
- return OPERATOR_FINISHED;
-}
-
-static void SCENE_OT_new(wmOperatorType *ot)
-{
- static const EnumPropertyItem type_items[] = {
- {SCE_COPY_NEW, "NEW", 0, "New", "Add new scene"},
- {SCE_COPY_EMPTY, "EMPTY", 0, "Copy Settings", "Make a copy without any objects"},
- {SCE_COPY_LINK_OB, "LINK_OBJECTS", 0, "Link Objects", "Link to the objects from the current scene"},
- {SCE_COPY_LINK_DATA, "LINK_OBJECT_DATA", 0, "Link Object Data", "Copy objects linked to data from the current scene"},
- {SCE_COPY_FULL, "FULL_COPY", 0, "Full Copy", "Make a full copy of the current scene"},
- {0, NULL, 0, NULL, NULL}};
-
- /* identifiers */
- ot->name = "New Scene";
- ot->description = "Add new scene by type";
- ot->idname = "SCENE_OT_new";
-
- /* api callbacks */
- ot->exec = scene_new_exec;
- ot->invoke = WM_menu_invoke;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- ot->prop = RNA_def_enum(ot->srna, "type", type_items, 0, "Type", "");
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Delete Screen Operator
- * \{ */
-
-static int scene_delete_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Scene *scene = CTX_data_scene(C);
-
- if (ED_screen_delete_scene(C, scene) == false) {
- return OPERATOR_CANCELLED;
- }
-
- if (G.debug & G_DEBUG)
- printf("scene delete %p\n", scene);
-
- WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene);
-
- return OPERATOR_FINISHED;
-}
-
-static void SCENE_OT_delete(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Delete Scene";
- ot->description = "Delete active scene";
- ot->idname = "SCENE_OT_delete";
-
- /* api callbacks */
- ot->exec = scene_delete_exec;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Region Alpha Blending Operator
* \{ */
@@ -4221,7 +4265,7 @@ typedef struct RegionAlphaInfo {
#define TIMEOUT 0.2f
#define TIMESTEP 0.04f
-float ED_region_blend_factor(ARegion *ar)
+float ED_region_blend_alpha(ARegion *ar)
{
/* check parent too */
if (ar->regiontimer == NULL && (ar->alignment & RGN_SPLIT_PREV) && ar->prev) {
@@ -4482,13 +4526,11 @@ void ED_operatortypes_screen(void)
WM_operatortype_append(SCREEN_OT_animation_step);
WM_operatortype_append(SCREEN_OT_animation_play);
WM_operatortype_append(SCREEN_OT_animation_cancel);
-
+
/* new/delete */
WM_operatortype_append(SCREEN_OT_new);
WM_operatortype_append(SCREEN_OT_delete);
- WM_operatortype_append(SCENE_OT_new);
- WM_operatortype_append(SCENE_OT_delete);
-
+
/* tools shared by more space types */
WM_operatortype_append(ED_OT_undo);
WM_operatortype_append(ED_OT_undo_push);
diff --git a/source/blender/editors/screen/screendump.c b/source/blender/editors/screen/screendump.c
index 2dd7400bc37..2c1cbc3d21d 100644
--- a/source/blender/editors/screen/screendump.c
+++ b/source/blender/editors/screen/screendump.c
@@ -54,7 +54,9 @@
#include "BKE_writeavi.h"
#include "BIF_gl.h"
-#include "BIF_glutil.h"
+
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -273,7 +275,7 @@ static void screenshot_draw(bContext *UNUSED(C), wmOperator *op)
/* main draw call */
RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
- uiDefAutoButsRNA(layout, &ptr, screenshot_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, screenshot_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
}
static int screenshot_poll(bContext *C)
@@ -451,25 +453,24 @@ static void screenshot_startjob(void *sjv, short *stop, short *do_update, float
/* Helper callback for drawing the cursor itself */
static void screencast_draw_cursor(bContext *UNUSED(C), int x, int y, void *UNUSED(p_ptr))
{
-
- glPushMatrix();
-
- glTranslatef((float)x, (float)y, 0.0f);
-
-
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
-
- glColor4ub(0, 0, 0, 32);
- glutil_draw_filled_arc(0.0, M_PI * 2.0, 20, 40);
-
- glColor4ub(255, 255, 255, 128);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, 20, 40);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4ub(0, 0, 0, 32);
+ imm_draw_circle_fill_2d(pos, (float)x, (float)y, 20, 40);
+
+ immUniformColor4ub(255, 255, 255, 128);
+ imm_draw_circle_wire_2d(pos, (float)x, (float)y, 20, 40);
+
+ immUnbindProgram();
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
-
- glPopMatrix();
}
/* Turn brush cursor in 3D view on/off */
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
new file mode 100644
index 00000000000..c8aa4560dc4
--- /dev/null
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -0,0 +1,500 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/screen/workspace_edit.c
+ * \ingroup edscr
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_fileops.h"
+#include "BLI_listbase.h"
+#include "BLI_path_util.h"
+#include "BLI_string.h"
+
+#include "BKE_appdir.h"
+#include "BKE_blendfile.h"
+#include "BKE_context.h"
+#include "BKE_idcode.h"
+#include "BKE_main.h"
+#include "BKE_layer.h"
+#include "BKE_library.h"
+#include "BKE_report.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_workspace.h"
+
+#include "BLO_readfile.h"
+
+#include "DNA_object_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
+
+#include "ED_object.h"
+#include "ED_screen.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "DEG_depsgraph.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "screen_intern.h"
+
+
+/** \name Workspace API
+ *
+ * \brief API for managing workspaces and their data.
+ * \{ */
+
+WorkSpace *ED_workspace_add(
+ Main *bmain, const char *name, Scene *scene,
+ ViewLayer *act_view_layer)
+{
+ WorkSpace *workspace = BKE_workspace_add(bmain, name);
+
+ BKE_workspace_view_layer_set(workspace, act_view_layer, scene);
+
+ return workspace;
+}
+
+/**
+ * Changes the object mode (if needed) to the one set in \a workspace_new.
+ * Object mode is still stored on object level. In future it should all be workspace level instead.
+ */
+static void workspace_change_update_mode(
+ const WorkSpace *workspace_old, const WorkSpace *workspace_new,
+ bContext *C, Object *ob_act, ReportList *reports)
+{
+ UNUSED_VARS(workspace_old, workspace_new, C, ob_act, reports);
+#if 0
+ eObjectMode mode_old = workspace_old->object_mode;
+ eObjectMode mode_new = workspace_new->object_mode;
+
+ if (mode_old != mode_new) {
+ ED_object_mode_compat_set(C, ob_act, mode_new, reports);
+ ED_object_mode_toggle(C, mode_new);
+ }
+#endif
+}
+
+static void workspace_change_update_view_layer(
+ WorkSpace *workspace_new, const WorkSpace *workspace_old,
+ Scene *scene)
+{
+ if (!BKE_workspace_view_layer_get(workspace_new, scene)) {
+ BKE_workspace_view_layer_set(workspace_new, BKE_workspace_view_layer_get(workspace_old, scene), scene);
+ }
+}
+
+static void workspace_change_update(
+ WorkSpace *workspace_new, const WorkSpace *workspace_old,
+ bContext *C, wmWindowManager *wm)
+{
+ /* needs to be done before changing mode! (to ensure right context) */
+ workspace_change_update_view_layer(workspace_new, workspace_old, CTX_data_scene(C));
+ workspace_change_update_mode(workspace_old, workspace_new, C, CTX_data_active_object(C), &wm->reports);
+}
+
+static bool workspace_change_find_new_layout_cb(const WorkSpaceLayout *layout, void *UNUSED(arg))
+{
+ /* return false to stop the iterator if we've found a layout that can be activated */
+ return workspace_layout_set_poll(layout) ? false : true;
+}
+
+static WorkSpaceLayout *workspace_change_get_new_layout(
+ WorkSpace *workspace_new, wmWindow *win)
+{
+ /* ED_workspace_duplicate may have stored a layout to activate once the workspace gets activated. */
+ WorkSpaceLayout *layout_new;
+ bScreen *screen_new;
+
+ if (win->workspace_hook->temp_workspace_store) {
+ layout_new = win->workspace_hook->temp_layout_store;
+ }
+ else {
+ layout_new = BKE_workspace_hook_layout_for_workspace_get(win->workspace_hook, workspace_new);
+ if (!layout_new) {
+ layout_new = BKE_workspace_layouts_get(workspace_new)->first;
+ }
+ }
+ screen_new = BKE_workspace_layout_screen_get(layout_new);
+
+ if (screen_new->winid) {
+ /* screen is already used, try to find a free one */
+ WorkSpaceLayout *layout_temp = BKE_workspace_layout_iter_circular(
+ workspace_new, layout_new, workspace_change_find_new_layout_cb,
+ NULL, false);
+ if (!layout_temp) {
+ /* fallback solution: duplicate layout */
+ layout_temp = ED_workspace_layout_duplicate(workspace_new, layout_new, win);
+ }
+ layout_new = layout_temp;
+ }
+
+ return layout_new;
+}
+
+/**
+ * \brief Change the active workspace.
+ *
+ * Operator call, WM + Window + screen already existed before
+ * Pretty similar to #ED_screen_change since changing workspace also changes screen.
+ *
+ * \warning Do NOT call in area/region queues!
+ * \returns if workspace changing was successful.
+ */
+bool ED_workspace_change(
+ WorkSpace *workspace_new, bContext *C, wmWindowManager *wm, wmWindow *win)
+{
+ Main *bmain = CTX_data_main(C);
+ WorkSpace *workspace_old = WM_window_get_active_workspace(win);
+ WorkSpaceLayout *layout_new = workspace_change_get_new_layout(workspace_new, win);
+ bScreen *screen_new = BKE_workspace_layout_screen_get(layout_new);
+ bScreen *screen_old = BKE_workspace_active_screen_get(win->workspace_hook);
+
+ win->workspace_hook->temp_layout_store = NULL;
+ if (workspace_old == workspace_new) {
+ /* Could also return true, everything that needs to be done was done (nothing :P), but nothing changed */
+ return false;
+ }
+
+ screen_new = screen_change_prepare(screen_old, screen_new, bmain, C, win);
+ BLI_assert(BKE_workspace_layout_screen_get(layout_new) == screen_new);
+
+ if (screen_new) {
+ WM_window_set_active_layout(win, workspace_new, layout_new);
+ WM_window_set_active_workspace(win, workspace_new);
+
+ /* update screen *after* changing workspace - which also causes the
+ * actual screen change and updates context (including CTX_wm_workspace) */
+ screen_change_update(C, win, screen_new);
+ workspace_change_update(workspace_new, workspace_old, C, wm);
+
+ BLI_assert(BKE_workspace_view_layer_get(workspace_new, CTX_data_scene(C)) != NULL);
+ BLI_assert(CTX_wm_workspace(C) == workspace_new);
+
+ WM_toolsystem_unlink(C, workspace_old);
+ WM_toolsystem_link(C, workspace_new);
+
+ return true;
+ }
+
+ return false;
+}
+
+/**
+ * Duplicate a workspace including its layouts. Does not activate the workspace, but
+ * it stores the screen-layout to be activated (BKE_workspace_temp_layout_store)
+ */
+WorkSpace *ED_workspace_duplicate(
+ WorkSpace *workspace_old, Main *bmain, wmWindow *win)
+{
+ WorkSpaceLayout *layout_active_old = BKE_workspace_active_layout_get(win->workspace_hook);
+ ListBase *layouts_old = BKE_workspace_layouts_get(workspace_old);
+ Scene *scene = WM_window_get_active_scene(win);
+ WorkSpace *workspace_new = ED_workspace_add(
+ bmain, workspace_old->id.name + 2, scene,
+ BKE_workspace_view_layer_get(workspace_old, scene));
+
+ workspace_new->tool = workspace_old->tool;
+
+ for (WorkSpaceLayout *layout_old = layouts_old->first; layout_old; layout_old = layout_old->next) {
+ WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(workspace_new, layout_old, win);
+
+ if (layout_active_old == layout_old) {
+ win->workspace_hook->temp_layout_store = layout_new;
+ }
+ }
+ return workspace_new;
+}
+
+/**
+ * \return if succeeded.
+ */
+bool ED_workspace_delete(
+ WorkSpace *workspace, Main *bmain, bContext *C, wmWindowManager *wm)
+{
+ ID *workspace_id = (ID *)workspace;
+
+ if (BLI_listbase_is_single(&bmain->workspaces)) {
+ return false;
+ }
+
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ WorkSpace *prev = workspace_id->prev;
+ WorkSpace *next = workspace_id->next;
+
+ ED_workspace_change((prev != NULL) ? prev : next, C, wm, win);
+ }
+ BKE_libblock_free(bmain, workspace_id);
+
+ return true;
+}
+
+/**
+ * Some editor data may need to be synced with scene data (3D View camera and layers).
+ * This function ensures data is synced for editors in active layout of \a workspace.
+ */
+void ED_workspace_scene_data_sync(
+ WorkSpaceInstanceHook *hook, Scene *scene)
+{
+ bScreen *screen = BKE_workspace_active_screen_get(hook);
+ BKE_screen_view3d_scene_sync(screen, scene);
+}
+
+void ED_workspace_view_layer_unset(
+ const Main *bmain, Scene *scene,
+ const ViewLayer *layer_unset, ViewLayer *layer_new)
+{
+ for (WorkSpace *workspace = bmain->workspaces.first; workspace; workspace = workspace->id.next) {
+ if (BKE_workspace_view_layer_get(workspace, scene) == layer_unset) {
+ BKE_workspace_view_layer_set(workspace, layer_new, scene);
+ }
+ }
+}
+
+/** \} Workspace API */
+
+
+/** \name Workspace Operators
+ *
+ * \{ */
+
+static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindow *win = CTX_wm_window(C);
+ WorkSpace *workspace = ED_workspace_duplicate(WM_window_get_active_workspace(win), bmain, win);
+
+ WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_SET, workspace);
+
+ return OPERATOR_FINISHED;
+}
+
+static void WORKSPACE_OT_workspace_duplicate(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "New Workspace";
+ ot->description = "Add a new workspace";
+ ot->idname = "WORKSPACE_OT_workspace_duplicate";
+
+ /* api callbacks */
+ ot->exec = workspace_new_exec;
+ ot->poll = WM_operator_winactive;
+}
+
+static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ wmWindow *win = CTX_wm_window(C);
+
+ WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_DELETE, WM_window_get_active_workspace(win));
+
+ return OPERATOR_FINISHED;
+}
+
+static void WORKSPACE_OT_workspace_delete(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Delete Workspace";
+ ot->description = "Delete the active workspace";
+ ot->idname = "WORKSPACE_OT_workspace_delete";
+
+ /* api callbacks */
+ ot->exec = workspace_delete_exec;
+}
+
+static int workspace_append(bContext *C, const char *directory, const char *idname)
+{
+ wmOperatorType *ot = WM_operatortype_find("WM_OT_append", false);
+ PointerRNA opptr;
+ int retval;
+
+ WM_operator_properties_create_ptr(&opptr, ot);
+ RNA_string_set(&opptr, "directory", directory);
+ RNA_string_set(&opptr, "filename", idname);
+ RNA_boolean_set(&opptr, "autoselect", false);
+
+ retval = WM_operator_name_call_ptr(C, ot, WM_OP_EXEC_DEFAULT, &opptr);
+
+ WM_operator_properties_free(&opptr);
+
+ return retval;
+}
+
+static int workspace_append_activate_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ char idname[MAX_ID_NAME - 2], directory[FILE_MAX];
+
+ if (!RNA_struct_property_is_set(op->ptr, "idname") ||
+ !RNA_struct_property_is_set(op->ptr, "directory"))
+ {
+ return OPERATOR_CANCELLED;
+ }
+ RNA_string_get(op->ptr, "idname", idname);
+ RNA_string_get(op->ptr, "directory", directory);
+
+ if (workspace_append(C, directory, idname) != OPERATOR_CANCELLED) {
+ WorkSpace *appended_workspace = BLI_findstring(&bmain->workspaces, idname, offsetof(ID, name) + 2);
+
+ BLI_assert(appended_workspace != NULL);
+ /* Changing workspace changes context. Do delayed! */
+ WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_SET, appended_workspace);
+
+ return OPERATOR_FINISHED;
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+static void WORKSPACE_OT_append_activate(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Append and Activate Workspace";
+ ot->description = "Append a workspace and make it the active one in the current window";
+ ot->idname = "WORKSPACE_OT_append_activate";
+
+ /* api callbacks */
+ ot->exec = workspace_append_activate_exec;
+
+ RNA_def_string(ot->srna, "idname", NULL, MAX_ID_NAME - 2, "Identifier",
+ "Name of the workspace to append and activate");
+ RNA_def_string(ot->srna, "directory", NULL, FILE_MAX, "Directory",
+ "Path to the library");
+}
+
+static void workspace_config_file_path_from_folder_id(
+ const Main *bmain, int folder_id, char *r_path)
+{
+ const char *app_template = U.app_template[0] ? U.app_template : NULL;
+ const char * const cfgdir = BKE_appdir_folder_id(folder_id, app_template);
+
+ if (cfgdir) {
+ BLI_make_file_string(bmain->name, r_path, cfgdir, BLENDER_WORKSPACES_FILE);
+ }
+ else {
+ r_path[0] = '\0';
+ }
+}
+
+ATTR_NONNULL(1)
+static WorkspaceConfigFileData *workspace_config_file_read(
+ const Main *bmain, ReportList *reports)
+{
+ char workspace_config_path[FILE_MAX];
+ bool has_path = false;
+
+ workspace_config_file_path_from_folder_id(bmain, BLENDER_USER_CONFIG, workspace_config_path);
+ if (BLI_exists(workspace_config_path)) {
+ has_path = true;
+ }
+ else {
+ workspace_config_file_path_from_folder_id(bmain, BLENDER_DATAFILES, workspace_config_path);
+ if (BLI_exists(workspace_config_path)) {
+ has_path = true;
+ }
+ }
+
+ return has_path ? BKE_blendfile_workspace_config_read(workspace_config_path, reports) : NULL;
+}
+
+static void workspace_append_button(
+ uiLayout *layout, wmOperatorType *ot_append, const WorkSpace *workspace, const Main *from_main)
+{
+ const ID *id = (ID *)workspace;
+ PointerRNA opptr;
+ char lib_path[FILE_MAX_LIBEXTRA];
+
+ BLI_path_join(
+ lib_path, sizeof(lib_path), from_main->name, BKE_idcode_to_name(GS(id->name)), NULL);
+
+ BLI_assert(STREQ(ot_append->idname, "WORKSPACE_OT_append_activate"));
+ uiItemFullO_ptr(
+ layout, ot_append, workspace->id.name + 2, ICON_NONE, NULL,
+ WM_OP_EXEC_DEFAULT, 0, &opptr);
+ RNA_string_set(&opptr, "idname", id->name + 2);
+ RNA_string_set(&opptr, "directory", lib_path);
+}
+
+ATTR_NONNULL(1, 2)
+static void workspace_config_file_append_buttons(
+ uiLayout *layout, const Main *bmain, ReportList *reports)
+{
+ WorkspaceConfigFileData *workspace_config = workspace_config_file_read(bmain, reports);
+
+ if (workspace_config) {
+ wmOperatorType *ot_append = WM_operatortype_find("WORKSPACE_OT_append_activate", true);
+
+ for (WorkSpace *workspace = workspace_config->workspaces.first; workspace; workspace = workspace->id.next) {
+ workspace_append_button(layout, ot_append, workspace, workspace_config->main);
+ }
+
+ BKE_blendfile_workspace_config_data_free(workspace_config);
+ }
+}
+
+static int workspace_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ const Main *bmain = CTX_data_main(C);
+
+ uiPopupMenu *pup = UI_popup_menu_begin(C, op->type->name, ICON_NONE);
+ uiLayout *layout = UI_popup_menu_layout(pup);
+
+ uiItemO(layout, "Duplicate Current", ICON_NONE, "WORKSPACE_OT_workspace_duplicate");
+ uiItemS(layout);
+ workspace_config_file_append_buttons(layout, bmain, op->reports);
+
+ UI_popup_menu_end(C, pup);
+
+ return OPERATOR_INTERFACE;
+}
+
+static void WORKSPACE_OT_workspace_add_menu(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add Workspace";
+ ot->description = "Add a new workspace by duplicating the current one or appending one "
+ "from the user configuration";
+ ot->idname = "WORKSPACE_OT_workspace_add_menu";
+
+ /* api callbacks */
+ ot->invoke = workspace_add_invoke;
+}
+
+void ED_operatortypes_workspace(void)
+{
+ WM_operatortype_append(WORKSPACE_OT_workspace_duplicate);
+ WM_operatortype_append(WORKSPACE_OT_workspace_delete);
+ WM_operatortype_append(WORKSPACE_OT_workspace_add_menu);
+ WM_operatortype_append(WORKSPACE_OT_append_activate);
+}
+
+/** \} Workspace Operators */
diff --git a/source/blender/editors/screen/workspace_layout_edit.c b/source/blender/editors/screen/workspace_layout_edit.c
new file mode 100644
index 00000000000..a6f991d4bbe
--- /dev/null
+++ b/source/blender/editors/screen/workspace_layout_edit.c
@@ -0,0 +1,197 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/screen/workspace_layout_edit.c
+ * \ingroup edscr
+ */
+
+#include <stdlib.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+
+#include "DNA_screen_types.h"
+#include "DNA_workspace_types.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_screen.h"
+#include "BKE_workspace.h"
+
+#include "WM_api.h"
+
+#include "ED_screen.h"
+
+#include "screen_intern.h"
+
+/**
+ * Empty screen, with 1 dummy area without spacedata. Uses window size.
+ */
+WorkSpaceLayout *ED_workspace_layout_add(
+ WorkSpace *workspace,
+ wmWindow *win,
+ const char *name)
+{
+ const int screen_size_x = WM_window_screen_pixels_x(win);
+ const int screen_size_y = WM_window_screen_pixels_y(win);
+
+ bScreen *screen = screen_add(name, screen_size_x, screen_size_y);
+ WorkSpaceLayout *layout = BKE_workspace_layout_add(workspace, screen, name);
+
+ return layout;
+}
+
+WorkSpaceLayout *ED_workspace_layout_duplicate(
+ WorkSpace *workspace, const WorkSpaceLayout *layout_old,
+ wmWindow *win)
+{
+ bScreen *screen_old = BKE_workspace_layout_screen_get(layout_old);
+ const char *name = BKE_workspace_layout_name_get(layout_old);
+ bScreen *screen_new;
+ WorkSpaceLayout *layout_new;
+
+ if (BKE_screen_is_fullscreen_area(screen_old)) {
+ return NULL; /* XXX handle this case! */
+ }
+
+ layout_new = ED_workspace_layout_add(workspace, win, name);
+ screen_new = BKE_workspace_layout_screen_get(layout_new);
+ screen_data_copy(screen_new, screen_old);
+
+ return layout_new;
+}
+
+static bool workspace_layout_delete_doit(
+ WorkSpace *workspace, WorkSpaceLayout *layout_old, WorkSpaceLayout *layout_new,
+ bContext *C)
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindow *win = CTX_wm_window(C);
+ bScreen *screen_new = BKE_workspace_layout_screen_get(layout_new);
+
+ ED_screen_change(C, screen_new);
+
+ if (BKE_workspace_active_layout_get(win->workspace_hook) != layout_old) {
+ BKE_workspace_layout_remove(bmain, workspace, layout_old);
+ return true;
+ }
+
+ return false;
+}
+
+bool workspace_layout_set_poll(const WorkSpaceLayout *layout)
+{
+ const bScreen *screen = BKE_workspace_layout_screen_get(layout);
+
+ return ((BKE_screen_is_used(screen) == false) &&
+ /* in typical usage temp screens should have a nonzero winid
+ * (all temp screens should be used, or closed & freed). */
+ (screen->temp == false) &&
+ (BKE_screen_is_fullscreen_area(screen) == false) &&
+ (screen->id.name[2] != '.' || !(U.uiflag & USER_HIDE_DOT)));
+}
+
+static WorkSpaceLayout *workspace_layout_delete_find_new(const WorkSpaceLayout *layout_old)
+{
+ for (WorkSpaceLayout *layout_new = layout_old->prev; layout_new; layout_new = layout_new->next) {
+ if (workspace_layout_set_poll(layout_new)) {
+ return layout_new;
+ }
+ }
+
+ for (WorkSpaceLayout *layout_new = layout_old->next; layout_new; layout_new = layout_new->next) {
+ if (workspace_layout_set_poll(layout_new)) {
+ return layout_new;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * \warning Only call outside of area/region loops!
+ * \return true if succeeded.
+ */
+bool ED_workspace_layout_delete(
+ WorkSpace *workspace, WorkSpaceLayout *layout_old,
+ bContext *C)
+{
+ const bScreen *screen_old = BKE_workspace_layout_screen_get(layout_old);
+ WorkSpaceLayout *layout_new;
+
+ BLI_assert(BLI_findindex(BKE_workspace_layouts_get(workspace), layout_old) != -1);
+
+ /* don't allow deleting temp fullscreens for now */
+ if (BKE_screen_is_fullscreen_area(screen_old)) {
+ return false;
+ }
+
+ /* A layout/screen can only be in use by one window at a time, so as
+ * long as we are able to find a layout/screen that is unused, we
+ * can safely assume ours is not in use anywhere an delete it. */
+
+ layout_new = workspace_layout_delete_find_new(layout_old);
+
+ if (layout_new) {
+ return workspace_layout_delete_doit(workspace, layout_old, layout_new, C);
+ }
+
+ return false;
+}
+
+static bool workspace_layout_cycle_iter_cb(const WorkSpaceLayout *layout, void *UNUSED(arg))
+{
+ /* return false to stop iterator when we have found a layout to activate */
+ return !workspace_layout_set_poll(layout);
+}
+
+bool ED_workspace_layout_cycle(
+ WorkSpace *workspace, const short direction, bContext *C)
+{
+ wmWindow *win = CTX_wm_window(C);
+ WorkSpaceLayout *old_layout = BKE_workspace_active_layout_get(win->workspace_hook);
+ WorkSpaceLayout *new_layout;
+ const bScreen *old_screen = BKE_workspace_layout_screen_get(old_layout);
+ ScrArea *sa = CTX_wm_area(C);
+
+ if (old_screen->temp || (sa && sa->full && sa->full->temp)) {
+ return false;
+ }
+
+ BLI_assert(ELEM(direction, 1, -1));
+ new_layout = BKE_workspace_layout_iter_circular(workspace, old_layout, workspace_layout_cycle_iter_cb,
+ NULL, (direction == -1) ? true : false);
+
+ if (new_layout && (old_layout != new_layout)) {
+ bScreen *new_screen = BKE_workspace_layout_screen_get(new_layout);
+
+ if (sa && sa->full) {
+ /* return to previous state before switching screens */
+ ED_screen_full_restore(C, sa); /* may free screen of old_layout */
+ }
+
+ ED_screen_change(C, new_screen);
+
+ return true;
+ }
+
+ return false;
+}
diff --git a/source/blender/editors/sculpt_paint/CMakeLists.txt b/source/blender/editors/sculpt_paint/CMakeLists.txt
index 9527dc4fe83..80c58e5b91d 100644
--- a/source/blender/editors/sculpt_paint/CMakeLists.txt
+++ b/source/blender/editors/sculpt_paint/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
../../blenlib
../../blentranslation
../../bmesh
+ ../../depsgraph
../../gpu
../../imbuf
../../makesdna
diff --git a/source/blender/editors/sculpt_paint/paint_cursor.c b/source/blender/editors/sculpt_paint/paint_cursor.c
index e6219b4fae1..8d941078c5f 100644
--- a/source/blender/editors/sculpt_paint/paint_cursor.c
+++ b/source/blender/editors/sculpt_paint/paint_cursor.c
@@ -54,14 +54,14 @@
#include "WM_api.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
#include "IMB_imbuf_types.h"
#include "ED_view3d.h"
-#include "GPU_basic_shader.h"
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
#include "UI_resources.h"
@@ -338,11 +338,12 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
size = target->old_size;
}
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, target->overlay_texture);
if (refresh) {
- GLenum format = col ? GL_RGBA : GL_ALPHA;
- GLenum internalformat = col ? GL_RGBA8 : GL_ALPHA8;
+ GLenum format = col ? GL_RGBA : GL_RED;
+ GLenum internalformat = col ? GL_RGBA8 : GL_R8;
if (!init || (target->old_col != col)) {
glTexImage2D(GL_TEXTURE_2D, 0, internalformat, size, size, 0, format, GL_UNSIGNED_BYTE, buffer);
@@ -357,8 +358,6 @@ static int load_tex(Brush *br, ViewContext *vc, float zoom, bool col, bool prima
target->old_col = col;
}
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -466,22 +465,21 @@ static int load_tex_cursor(Brush *br, ViewContext *vc, float zoom)
size = cursor_snap.size;
}
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, cursor_snap.overlay_texture);
if (refresh) {
if (!init) {
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, size, size, 0, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, size, size, 0, GL_RED, GL_UNSIGNED_BYTE, buffer);
}
else {
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_ALPHA, GL_UNSIGNED_BYTE, buffer);
+ glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, size, size, GL_RED, GL_UNSIGNED_BYTE, buffer);
}
if (buffer)
MEM_freeN(buffer);
}
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
-
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
@@ -615,26 +613,27 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush,
glDepthMask(GL_FALSE);
glDepthFunc(GL_ALWAYS);
- glMatrixMode(GL_TEXTURE);
- glPushMatrix();
- glLoadIdentity();
-
if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
+ gpuPushMatrix();
+
/* brush rotation */
- glTranslatef(0.5, 0.5, 0);
- glRotatef((double)RAD2DEGF((primary) ? ups->brush_rotation : ups->brush_rotation_sec),
- 0.0, 0.0, 1.0);
- glTranslatef(-0.5f, -0.5f, 0);
+ gpuTranslate2f(x, y);
+ gpuRotate2D(-RAD2DEGF(primary ? ups->brush_rotation : ups->brush_rotation_sec));
+ gpuTranslate2f(-x, -y);
/* scale based on tablet pressure */
if (primary && ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) {
- glTranslatef(0.5f, 0.5f, 0);
- glScalef(1.0f / ups->size_pressure_value, 1.0f / ups->size_pressure_value, 1);
- glTranslatef(-0.5f, -0.5f, 0);
+ const float scale = ups->size_pressure_value;
+ gpuTranslate2f(x, y);
+ gpuScale2f(scale, scale);
+ gpuTranslate2f(-x, -y);
}
if (ups->draw_anchored) {
- const float *aim = ups->anchored_initial_mouse;
+ float aim[2] = {
+ ups->anchored_initial_mouse[0] + vc->ar->winrct.xmin,
+ ups->anchored_initial_mouse[1] + vc->ar->winrct.ymin,
+ };
quad.xmin = aim[0] - ups->anchored_size;
quad.ymin = aim[1] - ups->anchored_size;
quad.xmax = aim[0] + ups->anchored_size;
@@ -668,41 +667,46 @@ static void paint_draw_tex_overlay(UnifiedPaintSettings *ups, Brush *brush,
quad.xmax = brush->mask_stencil_dimension[0];
quad.ymax = brush->mask_stencil_dimension[1];
}
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
+ gpuPushMatrix();
if (primary)
- glTranslate2fv(brush->stencil_pos);
+ gpuTranslate2fv(brush->stencil_pos);
else
- glTranslate2fv(brush->mask_stencil_pos);
- glRotatef(RAD2DEGF(mtex->rot), 0, 0, 1);
- glMatrixMode(GL_TEXTURE);
+ gpuTranslate2fv(brush->mask_stencil_pos);
+ gpuRotate2D(RAD2DEGF(mtex->rot));
}
/* set quad color. Colored overlay does not get blending */
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int texCoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
if (col) {
- glColor4f(1.0, 1.0, 1.0, overlay_alpha / 100.0f);
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, overlay_alpha * 0.01f);
}
else {
- glColor4f(UNPACK3(U.sculpt_paint_overlay_col), overlay_alpha / 100.0f);
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_ALPHA_COLOR);
+ immUniformColor3fvAlpha(U.sculpt_paint_overlay_col, overlay_alpha * 0.01f);
}
/* draw textured quad */
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(quad.xmin, quad.ymin);
- glTexCoord2f(1, 0);
- glVertex2f(quad.xmax, quad.ymin);
- glTexCoord2f(1, 1);
- glVertex2f(quad.xmax, quad.ymax);
- glTexCoord2f(0, 1);
- glVertex2f(quad.xmin, quad.ymax);
- glEnd();
-
- glPopMatrix();
-
- if (mtex->brush_map_mode == MTEX_MAP_MODE_STENCIL) {
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
+ immUniform1i("image", GL_TEXTURE0);
+
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+ immAttrib2f(texCoord, 0.0f, 0.0f);
+ immVertex2f(pos, quad.xmin, quad.ymin);
+ immAttrib2f(texCoord, 1.0f, 0.0f);
+ immVertex2f(pos, quad.xmax, quad.ymin);
+ immAttrib2f(texCoord, 1.0f, 1.0f);
+ immVertex2f(pos, quad.xmax, quad.ymax);
+ immAttrib2f(texCoord, 0.0f, 1.0f);
+ immVertex2f(pos, quad.xmin, quad.ymax);
+ immEnd();
+
+ immUnbindProgram();
+
+ if (ELEM(mtex->brush_map_mode, MTEX_MAP_MODE_STENCIL, MTEX_MAP_MODE_VIEW)) {
+ gpuPopMatrix();
}
}
}
@@ -729,7 +733,10 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush,
glDepthFunc(GL_ALWAYS);
if (ups->draw_anchored) {
- const float *aim = ups->anchored_initial_mouse;
+ float aim[2] = {
+ ups->anchored_initial_mouse[0] + vc->ar->winrct.xmin,
+ ups->anchored_initial_mouse[1] + vc->ar->winrct.ymin,
+ };
copy_v2_v2(center, aim);
quad.xmin = aim[0] - ups->anchored_size;
quad.ymin = aim[1] - ups->anchored_size;
@@ -750,32 +757,41 @@ static void paint_draw_cursor_overlay(UnifiedPaintSettings *ups, Brush *brush,
/* scale based on tablet pressure */
if (ups->stroke_active && BKE_brush_use_size_pressure(vc->scene, brush)) {
do_pop = true;
- glPushMatrix();
- glLoadIdentity();
- glTranslate2fv(center);
- glScalef(ups->size_pressure_value, ups->size_pressure_value, 1);
- glTranslatef(-center[0], -center[1], 0);
+ gpuPushMatrix();
+ gpuLoadIdentity();
+ gpuTranslate2fv(center);
+ gpuScaleUniform(ups->size_pressure_value);
+ gpuTranslate2f(-center[0], -center[1]);
}
- glColor4f(U.sculpt_paint_overlay_col[0],
- U.sculpt_paint_overlay_col[1],
- U.sculpt_paint_overlay_col[2],
- brush->cursor_overlay_alpha / 100.0f);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int texCoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+
+ immUniformColor3fvAlpha(U.sculpt_paint_overlay_col, brush->cursor_overlay_alpha * 0.01f);
+
+ /* draw textured quad */
/* draw textured quad */
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(quad.xmin, quad.ymin);
- glTexCoord2f(1, 0);
- glVertex2f(quad.xmax, quad.ymin);
- glTexCoord2f(1, 1);
- glVertex2f(quad.xmax, quad.ymax);
- glTexCoord2f(0, 1);
- glVertex2f(quad.xmin, quad.ymax);
- glEnd();
+ immUniform1i("image", 0);
+
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+ immAttrib2f(texCoord, 0.0f, 0.0f);
+ immVertex2f(pos, quad.xmin, quad.ymin);
+ immAttrib2f(texCoord, 1.0f, 0.0f);
+ immVertex2f(pos, quad.xmax, quad.ymin);
+ immAttrib2f(texCoord, 1.0f, 1.0f);
+ immVertex2f(pos, quad.xmax, quad.ymax);
+ immAttrib2f(texCoord, 0.0f, 1.0f);
+ immVertex2f(pos, quad.xmin, quad.ymax);
+ immEnd();
+
+ immUnbindProgram();
if (do_pop)
- glPopMatrix();
+ gpuPopMatrix();
}
}
@@ -785,19 +801,7 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
/* color means that primary brush texture is colured and secondary is used for alpha/mask control */
bool col = ELEM(mode, ePaintTextureProjective, ePaintTexture2D, ePaintVertex) ? true : false;
eOverlayControlFlags flags = BKE_paint_get_overlay_flags();
- /* save lots of GL state
- * TODO: check on whether all of these are needed? */
- glPushAttrib(GL_COLOR_BUFFER_BIT |
- GL_CURRENT_BIT |
- GL_DEPTH_BUFFER_BIT |
- GL_ENABLE_BIT |
- GL_LINE_BIT |
- GL_POLYGON_BIT |
- GL_STENCIL_BUFFER_BIT |
- GL_TRANSFORM_BIT |
- GL_VIEWPORT_BIT |
- GL_TEXTURE_BIT);
-
+ gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_BLEND_BIT);
/* coloured overlay should be drawn separately */
if (col) {
@@ -815,86 +819,98 @@ static void paint_draw_alpha_overlay(UnifiedPaintSettings *ups, Brush *brush,
paint_draw_cursor_overlay(ups, brush, vc, x, y, zoom);
}
- glPopAttrib();
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ gpuPopAttrib();
}
-BLI_INLINE void draw_tri_point(float *co, float width, bool selected)
+BLI_INLINE void draw_tri_point(
+ unsigned int pos, float sel_col[4], float pivot_col[4],
+ float *co, float width, bool selected)
{
+ immUniformColor4fv(selected ? sel_col : pivot_col);
+
+ glLineWidth(3.0f);
+
float w = width / 2.0f;
- if (selected)
- UI_ThemeColor4(TH_VERTEX_SELECT);
- else
- UI_ThemeColor4(TH_PAINT_CURVE_PIVOT);
-
- glLineWidth(3.0);
-
- glBegin(GL_LINE_LOOP);
- glVertex2f(co[0], co[1] + w);
- glVertex2f(co[0] - w, co[1] - w);
- glVertex2f(co[0] + w, co[1] - w);
- glEnd();
-
- glColor4f(1.0, 1.0, 1.0, 0.5);
- glLineWidth(1.0);
-
- glBegin(GL_LINE_LOOP);
- glVertex2f(co[0], co[1] + w);
- glVertex2f(co[0] - w, co[1] - w);
- glVertex2f(co[0] + w, co[1] - w);
- glEnd();
+ float tri[3][2] = {
+ {co[0], co[1] + w},
+ {co[0] - w, co[1] - w},
+ {co[0] + w, co[1] - w},
+ };
+
+ immBegin(GWN_PRIM_LINE_LOOP, 3);
+ immVertex2fv(pos, tri[0]);
+ immVertex2fv(pos, tri[1]);
+ immVertex2fv(pos, tri[2]);
+ immEnd();
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
+ glLineWidth(1.0f);
+
+ immBegin(GWN_PRIM_LINE_LOOP, 3);
+ immVertex2fv(pos, tri[0]);
+ immVertex2fv(pos, tri[1]);
+ immVertex2fv(pos, tri[2]);
+ immEnd();
}
-BLI_INLINE void draw_rect_point(float *co, float width, bool selected)
+BLI_INLINE void draw_rect_point(
+ unsigned int pos, float sel_col[4], float handle_col[4],
+ float *co, float width, bool selected)
{
+ immUniformColor4fv(selected ? sel_col : handle_col);
+
+ glLineWidth(3.0f);
+
float w = width / 2.0f;
- if (selected)
- UI_ThemeColor4(TH_VERTEX_SELECT);
- else
- UI_ThemeColor4(TH_PAINT_CURVE_HANDLE);
- glLineWidth(3.0);
-
- glBegin(GL_LINE_LOOP);
- glVertex2f(co[0] + w, co[1] + w);
- glVertex2f(co[0] - w, co[1] + w);
- glVertex2f(co[0] - w, co[1] - w);
- glVertex2f(co[0] + w, co[1] - w);
- glEnd();
-
- glColor4f(1.0, 1.0, 1.0, 0.5);
- glLineWidth(1.0);
-
- glBegin(GL_LINE_LOOP);
- glVertex2f(co[0] + w, co[1] + w);
- glVertex2f(co[0] - w, co[1] + w);
- glVertex2f(co[0] - w, co[1] - w);
- glVertex2f(co[0] + w, co[1] - w);
- glEnd();
+ float minx = co[0] - w;
+ float miny = co[1] - w;
+ float maxx = co[0] + w;
+ float maxy = co[1] + w;
+
+ imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy);
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
+ glLineWidth(1.0f);
+
+ imm_draw_box_wire_2d(pos, minx, miny, maxx, maxy);
}
-BLI_INLINE void draw_bezier_handle_lines(BezTriple *bez)
+BLI_INLINE void draw_bezier_handle_lines(unsigned int pos, float sel_col[4], BezTriple *bez)
{
- short line1[] = {0, 1};
- short line2[] = {1, 2};
-
- glVertexPointer(2, GL_FLOAT, 3 * sizeof(float), bez->vec);
- glColor4f(0.0, 0.0, 0.0, 0.5);
- glLineWidth(3.0);
- glDrawArrays(GL_LINE_STRIP, 0, 3);
-
- glLineWidth(1.0);
- if (bez->f1 || bez->f2)
- UI_ThemeColor4(TH_VERTEX_SELECT);
- else
- glColor4f(1.0, 1.0, 1.0, 0.5);
- glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, line1);
- if (bez->f3 || bez->f2)
- UI_ThemeColor4(TH_VERTEX_SELECT);
- else
- glColor4f(1.0, 1.0, 1.0, 0.5);
- glDrawElements(GL_LINES, 2, GL_UNSIGNED_SHORT, line2);
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f);
+ glLineWidth(3.0f);
+
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ immVertex2fv(pos, bez->vec[0]);
+ immVertex2fv(pos, bez->vec[1]);
+ immVertex2fv(pos, bez->vec[2]);
+ immEnd();
+
+ glLineWidth(1.0f);
+
+ if (bez->f1 || bez->f2) {
+ immUniformColor4fv(sel_col);
+ }
+ else {
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
+ }
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(pos, bez->vec[0]);
+ immVertex2fv(pos, bez->vec[1]);
+ immEnd();
+
+ if (bez->f3 || bez->f2) {
+ immUniformColor4fv(sel_col);
+ }
+ else {
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
+ }
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(pos, bez->vec[1]);
+ immVertex2fv(pos, bez->vec[2]);
+ immEnd();
}
static void paint_draw_curve_cursor(Brush *brush)
@@ -906,18 +922,26 @@ static void paint_draw_curve_cursor(Brush *brush)
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
- glEnableClientState(GL_VERTEX_ARRAY);
/* draw the bezier handles and the curve segment between the current and next point */
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ float selec_col[4], handle_col[4], pivot_col[4];
+ UI_GetThemeColor4fv(TH_VERTEX_SELECT, selec_col);
+ UI_GetThemeColor4fv(TH_PAINT_CURVE_HANDLE, handle_col);
+ UI_GetThemeColor4fv(TH_PAINT_CURVE_PIVOT, pivot_col);
+
for (i = 0; i < pc->tot_points - 1; i++, cp++) {
int j;
PaintCurvePoint *cp_next = cp + 1;
float data[(PAINT_CURVE_NUM_SEGMENTS + 1) * 2];
/* use color coding to distinguish handles vs curve segments */
- draw_bezier_handle_lines(&cp->bez);
- draw_tri_point(&cp->bez.vec[1][0], 10.0, cp->bez.f2);
- draw_rect_point(&cp->bez.vec[0][0], 8.0, cp->bez.f1 || cp->bez.f2);
- draw_rect_point(&cp->bez.vec[2][0], 8.0, cp->bez.f3 || cp->bez.f2);
+ draw_bezier_handle_lines(pos, selec_col, &cp->bez);
+ draw_tri_point(pos, selec_col, pivot_col, &cp->bez.vec[1][0], 10.0f, cp->bez.f2);
+ draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[0][0], 8.0f, cp->bez.f1 || cp->bez.f2);
+ draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[2][0], 8.0f, cp->bez.f3 || cp->bez.f2);
for (j = 0; j < 2; j++)
BKE_curve_forward_diff_bezier(
@@ -927,25 +951,35 @@ static void paint_draw_curve_cursor(Brush *brush)
cp_next->bez.vec[1][j],
data + j, PAINT_CURVE_NUM_SEGMENTS, sizeof(float[2]));
- glVertexPointer(2, GL_FLOAT, 0, data);
- glLineWidth(3.0);
- glColor4f(0.0, 0.0, 0.0, 0.5);
- glDrawArrays(GL_LINE_STRIP, 0, PAINT_CURVE_NUM_SEGMENTS + 1);
+ float (*v)[2] = (float(*)[2])data;
+
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.5f);
+ glLineWidth(3.0f);
+ immBegin(GWN_PRIM_LINE_STRIP, PAINT_CURVE_NUM_SEGMENTS + 1);
+ for (j = 0; j <= PAINT_CURVE_NUM_SEGMENTS; j++) {
+ immVertex2fv(pos, v[j]);
+ }
+ immEnd();
- glLineWidth(1.0);
- glColor4f(0.9, 0.9, 1.0, 0.5);
- glDrawArrays(GL_LINE_STRIP, 0, PAINT_CURVE_NUM_SEGMENTS + 1);
+ immUniformColor4f(0.9f, 0.9f, 1.0f, 0.5f);
+ glLineWidth(1.0f);
+ immBegin(GWN_PRIM_LINE_STRIP, PAINT_CURVE_NUM_SEGMENTS + 1);
+ for (j = 0; j <= PAINT_CURVE_NUM_SEGMENTS; j++) {
+ immVertex2fv(pos, v[j]);
+ }
+ immEnd();
}
/* draw last line segment */
- draw_bezier_handle_lines(&cp->bez);
- draw_tri_point(&cp->bez.vec[1][0], 10.0, cp->bez.f2);
- draw_rect_point(&cp->bez.vec[0][0], 8.0, cp->bez.f1 || cp->bez.f2);
- draw_rect_point(&cp->bez.vec[2][0], 8.0, cp->bez.f3 || cp->bez.f2);
+ draw_bezier_handle_lines(pos, selec_col, &cp->bez);
+ draw_tri_point(pos, selec_col, pivot_col, &cp->bez.vec[1][0], 10.0f, cp->bez.f2);
+ draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[0][0], 8.0f, cp->bez.f1 || cp->bez.f2);
+ draw_rect_point(pos, selec_col, handle_col, &cp->bez.vec[2][0], 8.0f, cp->bez.f3 || cp->bez.f2);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
- glDisableClientState(GL_VERTEX_ARRAY);
+
+ immUnbindProgram();
}
}
@@ -995,15 +1029,11 @@ static bool ommit_cursor_drawing(Paint *paint, ePaintMode mode, Brush *brush)
static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
{
Scene *scene = CTX_data_scene(C);
+ ARegion *ar = CTX_wm_region(C);
UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
Paint *paint = BKE_paint_get_active_from_context(C);
Brush *brush = BKE_paint_brush(paint);
ePaintMode mode = BKE_paintmode_get_active_from_context(C);
- ViewContext vc;
- float final_radius;
- float translation[2];
- float outline_alpha, *outline_col;
- float zoomx, zoomy;
/* check that brush drawing is enabled */
if (ommit_cursor_drawing(paint, mode, brush))
@@ -1011,6 +1041,7 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
/* can't use stroke vc here because this will be called during
* mouse over too, not just during a stroke */
+ ViewContext vc;
ED_view3d_viewcontext_init(C, &vc);
if (vc.rv3d && (vc.rv3d->rflag & RV3D_NAVIGATING)) {
@@ -1023,15 +1054,15 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
return;
}
+ float zoomx, zoomy;
get_imapaint_zoom(C, &zoomx, &zoomy);
zoomx = max_ff(zoomx, zoomy);
/* set various defaults */
- translation[0] = x;
- translation[1] = y;
- outline_alpha = 0.5;
- outline_col = brush->add_col;
- final_radius = (BKE_brush_size_get(scene, brush) * zoomx);
+ const float *outline_col = brush->add_col;
+ const float outline_alpha = 0.5f;
+ float translation[2] = { x, y };
+ float final_radius = (BKE_brush_size_get(scene, brush) * zoomx);
/* don't calculate rake angles while a stroke is active because the rake variables are global and
* we may get interference with the stroke itself. For line strokes, such interference is visible */
@@ -1047,10 +1078,9 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
if ((mode == ePaintSculpt) && vc.obact->sculpt) {
float location[3];
int pixel_radius;
- bool hit;
/* test if brush is over the mesh */
- hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location, ups);
+ bool hit = sculpt_get_brush_geometry(C, &vc, x, y, &pixel_radius, location, ups);
if (BKE_brush_use_locked_size(scene, brush))
BKE_brush_size_set(scene, brush, pixel_radius);
@@ -1071,30 +1101,32 @@ static void paint_draw_cursor(bContext *C, int x, int y, void *UNUSED(unused))
if (ups->draw_anchored) {
final_radius = ups->anchored_size;
- translation[0] = ups->anchored_initial_mouse[0];
- translation[1] = ups->anchored_initial_mouse[1];
+ copy_v2_fl2(translation,
+ ups->anchored_initial_mouse[0] + ar->winrct.xmin,
+ ups->anchored_initial_mouse[1] + ar->winrct.ymin);
}
/* make lines pretty */
glLineWidth(1.0f);
- glEnable(GL_BLEND);
+ glEnable(GL_BLEND); /* TODO: also set blend mode? */
glEnable(GL_LINE_SMOOTH);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* set brush color */
- glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha);
+ immUniformColor3fvAlpha(outline_col, outline_alpha);
/* draw brush outline */
- glTranslate2fv(translation);
-
- /* draw an inner brush */
if (ups->stroke_active && BKE_brush_use_size_pressure(scene, brush)) {
/* inner at full alpha */
- glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius * ups->size_pressure_value, 40);
+ imm_draw_circle_wire_2d(pos, translation[0], translation[1], final_radius * ups->size_pressure_value, 40);
/* outer at half alpha */
- glColor4f(outline_col[0], outline_col[1], outline_col[2], outline_alpha * 0.5f);
+ immUniformColor3fvAlpha(outline_col, outline_alpha * 0.5f);
}
- glutil_draw_lined_arc(0.0, M_PI * 2.0, final_radius, 40);
- glTranslatef(-translation[0], -translation[1], 0);
+ imm_draw_circle_wire_2d(pos, translation[0], translation[1], final_radius, 40);
+
+ immUnbindProgram();
/* restore GL state */
glDisable(GL_BLEND);
diff --git a/source/blender/editors/sculpt_paint/paint_curve.c b/source/blender/editors/sculpt_paint/paint_curve.c
index 120514762f4..049d8ff8c0b 100644
--- a/source/blender/editors/sculpt_paint/paint_curve.c
+++ b/source/blender/editors/sculpt_paint/paint_curve.c
@@ -39,6 +39,8 @@
#include "BKE_main.h"
#include "BKE_paint.h"
+#include "DEG_depsgraph.h"
+
#include "ED_view3d.h"
#include "ED_paint.h"
diff --git a/source/blender/editors/sculpt_paint/paint_hide.c b/source/blender/editors/sculpt_paint/paint_hide.c
index e2b318710a8..4dd770d79b9 100644
--- a/source/blender/editors/sculpt_paint/paint_hide.c
+++ b/source/blender/editors/sculpt_paint/paint_hide.c
@@ -52,7 +52,7 @@
#include "BKE_paint.h"
#include "BKE_subsurf.h"
-#include "BIF_glutil.h"
+#include "DEG_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -323,12 +323,10 @@ static void clip_planes_from_rect(bContext *C,
{
ViewContext vc;
BoundBox bb;
- bglMats mats = {{0}};
view3d_operator_needs_opengl(C);
ED_view3d_viewcontext_init(C, &vc);
- view3d_get_transformation(vc.ar, vc.rv3d, vc.obact, &mats);
- ED_view3d_clipping_calc(&bb, clip_planes, &mats, rect);
+ ED_view3d_clipping_calc(&bb, clip_planes, vc.ar, vc.obact, rect);
negate_m4(clip_planes);
}
@@ -364,6 +362,7 @@ static int hide_show_exec(bContext *C, wmOperator *op)
{
ARegion *ar = CTX_wm_region(C);
Object *ob = CTX_data_active_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Mesh *me = ob->data;
PartialVisAction action;
PartialVisArea area;
@@ -382,7 +381,7 @@ static int hide_show_exec(bContext *C, wmOperator *op)
clip_planes_from_rect(C, clip_planes, &rect);
- dm = mesh_get_derived_final(CTX_data_scene(C), ob, CD_MASK_BAREMESH);
+ dm = mesh_get_derived_final(depsgraph, CTX_data_scene(C), ob, CD_MASK_BAREMESH);
pbvh = dm->getPBVH(ob, dm);
ob->sculpt->pbvh = pbvh;
diff --git a/source/blender/editors/sculpt_paint/paint_image.c b/source/blender/editors/sculpt_paint/paint_image.c
index cb6dba4772f..3207b4f6a0a 100644
--- a/source/blender/editors/sculpt_paint/paint_image.c
+++ b/source/blender/editors/sculpt_paint/paint_image.c
@@ -51,7 +51,6 @@
#include "BKE_colorband.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_brush.h"
#include "BKE_main.h"
@@ -61,6 +60,8 @@
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "UI_interface.h"
#include "UI_view2d.h"
@@ -77,10 +78,9 @@
#include "RNA_define.h"
#include "GPU_draw.h"
-#include "GPU_buffers.h"
+#include "GPU_immediate.h"
#include "BIF_gl.h"
-#include "BIF_glutil.h"
#include "IMB_colormanagement.h"
@@ -264,7 +264,7 @@ static Brush *image_paint_brush(bContext *C)
return BKE_paint_brush(&settings->imapaint.paint);
}
-static int image_paint_poll(bContext *C)
+static int image_paint_poll_ex(bContext *C, bool check_tool)
{
Object *obact;
@@ -273,7 +273,9 @@ static int image_paint_poll(bContext *C)
obact = CTX_data_active_object(C);
if ((obact && obact->mode & OB_MODE_TEXTURE_PAINT) && CTX_wm_region_view3d(C)) {
- return 1;
+ if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) {
+ return 1;
+ }
}
else {
SpaceImage *sima = CTX_wm_space_image(C);
@@ -290,6 +292,16 @@ static int image_paint_poll(bContext *C)
return 0;
}
+static int image_paint_poll(bContext *C)
+{
+ return image_paint_poll_ex(C, true);
+}
+
+static int image_paint_poll_ignore_tool(bContext *C)
+{
+ return image_paint_poll_ex(C, false);
+}
+
static int image_paint_2d_clone_poll(bContext *C)
{
Brush *brush = image_paint_brush(C);
@@ -401,12 +413,28 @@ static void gradient_draw_line(bContext *UNUSED(C), int x, int y, void *customda
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
glLineWidth(4.0);
- glColor4ub(0, 0, 0, 255);
- sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]);
+ immUniformColor4ub(0, 0, 0, 255);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2i(pos, x, y);
+ immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]);
+ immEnd();
+
glLineWidth(2.0);
- glColor4ub(255, 255, 255, 255);
- sdrawline(x, y, pop->startmouse[0], pop->startmouse[1]);
+ immUniformColor4ub(255, 255, 255, 255);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2i(pos, x, y);
+ immVertex2i(pos, pop->startmouse[0], pop->startmouse[1]);
+ immEnd();
+
+ immUnbindProgram();
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
@@ -428,7 +456,8 @@ static PaintOperation *texture_paint_init(bContext *C, wmOperator *op, const flo
/* initialize from context */
if (CTX_wm_region_view3d(C)) {
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
bool uvs, mat, tex, stencil;
if (!BKE_paint_proj_mesh_data_check(scene, ob, &uvs, &mat, &tex, &stencil)) {
BKE_paint_data_warning(op->reports, uvs, mat, tex, stencil);
@@ -711,16 +740,20 @@ static void toggle_paint_cursor(bContext *C, int enable)
void ED_space_image_paint_update(wmWindowManager *wm, Scene *scene)
{
ToolSettings *settings = scene->toolsettings;
- wmWindow *win;
- ScrArea *sa;
ImagePaintSettings *imapaint = &settings->imapaint;
bool enabled = false;
- for (win = wm->windows.first; win; win = win->next)
- for (sa = win->screen->areabase.first; sa; sa = sa->next)
- if (sa->spacetype == SPACE_IMAGE)
- if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT)
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ bScreen *screen = WM_window_get_active_screen(win);
+
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ if (sa->spacetype == SPACE_IMAGE) {
+ if (((SpaceImage *)sa->spacedata.first)->mode == SI_MODE_PAINT) {
enabled = true;
+ }
+ }
+ }
+ }
if (enabled) {
BKE_paint_init(scene, ePaintTexture2D, PAINT_CURSOR_TEXTURE_PAINT);
@@ -978,7 +1011,7 @@ static int sample_color_modal(bContext *C, wmOperator *op, const wmEvent *event)
static int sample_color_poll(bContext *C)
{
- return (image_paint_poll(C) || vertex_paint_poll(C));
+ return (image_paint_poll_ignore_tool(C) || image_paint_poll_ignore_tool(C));
}
void PAINT_OT_sample_color(wmOperatorType *ot)
@@ -1076,8 +1109,10 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
if (sl->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)sl;
- if (!sima->pin)
- ED_space_image_set(sima, scene, scene->obedit, ima);
+ if (!sima->pin) {
+ Object *obedit = CTX_data_edit_object(C);
+ ED_space_image_set(sima, scene, obedit, ima);
+ }
}
}
}
@@ -1095,7 +1130,8 @@ static int texture_paint_toggle_exec(bContext *C, wmOperator *op)
toggle_paint_cursor(C, 1);
}
- GPU_drawobject_free(ob->derivedFinal);
+ // ED_workspace_object_mode_sync_from_object(wm, workspace, ob);
+
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
return OPERATOR_FINISHED;
@@ -1121,8 +1157,8 @@ static int brush_colors_flip_exec(bContext *C, wmOperator *UNUSED(op))
{
UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings;
- Brush *br;
Object *ob = CTX_data_active_object(C);
+ Brush *br;
if (!(ob && (ob->mode & OB_MODE_VERTEX_PAINT))) {
br = image_paint_brush(C);
}
@@ -1191,7 +1227,7 @@ void ED_imapaint_bucket_fill(struct bContext *C, float color[3], wmOperator *op)
BKE_undosys_step_push(wm->undo_stack, C, op->type->name);
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
}
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 37096f9e660..c2ce9d83782 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -46,12 +46,13 @@
#include "BKE_colorband.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_brush.h"
#include "BKE_image.h"
#include "BKE_paint.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "ED_paint.h"
#include "ED_screen.h"
@@ -1367,7 +1368,7 @@ void paint_2d_redraw(const bContext *C, void *ps, bool final)
/* compositor listener deals with updating */
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, s->image);
- DAG_id_tag_update(&s->image->id, 0);
+ DEG_id_tag_update(&s->image->id, 0);
}
else {
if (!s->sima || !s->sima->lock)
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index 7784926128f..8c148dcb313 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -65,7 +65,6 @@
#include "BKE_colorband.h"
#include "BKE_context.h"
#include "BKE_colortools.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_idprop.h"
#include "BKE_brush.h"
@@ -81,6 +80,8 @@
#include "BKE_scene.h"
#include "BKE_texture.h"
+#include "DEG_depsgraph.h"
+
#include "UI_interface.h"
#include "ED_mesh.h"
@@ -226,6 +227,7 @@ typedef struct ProjPaintState {
View3D *v3d;
RegionView3D *rv3d;
ARegion *ar;
+ Depsgraph *depsgraph;
Scene *scene;
int source; /* PROJ_SRC_**** */
@@ -281,7 +283,6 @@ typedef struct ProjPaintState {
bool do_backfacecull; /* ignore faces with normals pointing away, skips a lot of raycasts if your normals are correctly flipped */
bool do_mask_normal; /* mask out pixels based on their normals */
bool do_mask_cavity; /* mask out pixels based on cavity */
- bool do_new_shading_nodes; /* cache BKE_scene_use_new_shading_nodes value */
float normal_angle; /* what angle to mask at */
float normal_angle__cos; /* cos(normal_angle), faster to compare */
float normal_angle_inner;
@@ -2490,8 +2491,7 @@ static bool IsectPoly2Df_twoside(const float pt[2], float uv[][2], const int tot
static void project_paint_face_init(
const ProjPaintState *ps,
const int thread_index, const int bucket_index, const int tri_index, const int image_index,
- const rctf *clip_rect, const rctf *bucket_bounds, ImBuf *ibuf, ImBuf **tmpibuf,
- const bool clamp_u, const bool clamp_v)
+ const rctf *clip_rect, const rctf *bucket_bounds, ImBuf *ibuf, ImBuf **tmpibuf)
{
/* Projection vars, to get the 3D locations into screen space */
MemArena *arena = ps->arena_mt[thread_index];
@@ -2598,17 +2598,6 @@ static void project_paint_face_init(
#endif
if (pixel_bounds_array(uv_clip, &bounds_px, ibuf->x, ibuf->y, uv_clip_tot)) {
-
- if (clamp_u) {
- CLAMP(bounds_px.xmin, 0, ibuf->x);
- CLAMP(bounds_px.xmax, 0, ibuf->x);
- }
-
- if (clamp_v) {
- CLAMP(bounds_px.ymin, 0, ibuf->y);
- CLAMP(bounds_px.ymax, 0, ibuf->y);
- }
-
#if 0
project_paint_undo_tiles_init(&bounds_px, ps->projImages + image_index, tmpibuf,
tile_width, threaded, ps->do_masking);
@@ -2925,19 +2914,16 @@ static void project_bucket_init(
int tri_index, image_index = 0;
ImBuf *ibuf = NULL;
Image *tpage_last = NULL, *tpage;
- Image *ima = NULL;
ImBuf *tmpibuf = NULL;
if (ps->image_tot == 1) {
/* Simple loop, no context switching */
ibuf = ps->projImages[0].ibuf;
- ima = ps->projImages[0].ima;
for (node = ps->bucketFaces[bucket_index]; node; node = node->next) {
project_paint_face_init(
ps, thread_index, bucket_index, GET_INT_FROM_POINTER(node->link), 0,
- clip_rect, bucket_bounds, ibuf, &tmpibuf,
- (ima->tpageflag & IMA_CLAMP_U) != 0, (ima->tpageflag & IMA_CLAMP_V) != 0);
+ clip_rect, bucket_bounds, ibuf, &tmpibuf);
}
}
else {
@@ -2954,7 +2940,6 @@ static void project_bucket_init(
for (image_index = 0; image_index < ps->image_tot; image_index++) {
if (ps->projImages[image_index].ima == tpage_last) {
ibuf = ps->projImages[image_index].ibuf;
- ima = ps->projImages[image_index].ima;
break;
}
}
@@ -2963,8 +2948,7 @@ static void project_bucket_init(
project_paint_face_init(
ps, thread_index, bucket_index, tri_index, image_index,
- clip_rect, bucket_bounds, ibuf, &tmpibuf,
- (ima->tpageflag & IMA_CLAMP_U) != 0, (ima->tpageflag & IMA_CLAMP_V) != 0);
+ clip_rect, bucket_bounds, ibuf, &tmpibuf);
}
}
@@ -3133,7 +3117,7 @@ static void proj_paint_state_viewport_init(
ED_view3d_ob_project_mat_get_from_obmat(ps->rv3d, ps->obmat, ps->projectMat);
- ps->is_ortho = ED_view3d_clip_range_get(ps->v3d, ps->rv3d, &ps->clipsta, &ps->clipend, true);
+ ps->is_ortho = ED_view3d_clip_range_get(ps->depsgraph, ps->v3d, ps->rv3d, &ps->clipsta, &ps->clipend, true);
}
else {
/* re-projection */
@@ -3422,12 +3406,14 @@ static void project_paint_bleed_add_face_user(
#endif
/* Return true if DM can be painted on, false otherwise */
-static bool proj_paint_state_dm_init(ProjPaintState *ps)
+static bool proj_paint_state_dm_init(const bContext *C, ProjPaintState *ps)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
/* Workaround for subsurf selection, try the display mesh first */
if (ps->source == PROJ_SRC_IMAGE_CAM) {
/* using render mesh, assume only camera was rendered from */
- ps->dm = mesh_create_derived_render(ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE);
+ ps->dm = mesh_create_derived_render(depsgraph, ps->scene, ps->ob, ps->scene->customdata_mask | CD_MASK_MTFACE);
ps->dm_release = true;
}
else if (ps->ob->derivedFinal &&
@@ -3439,7 +3425,7 @@ static bool proj_paint_state_dm_init(ProjPaintState *ps)
}
else {
ps->dm = mesh_get_derived_final(
- ps->scene, ps->ob,
+ depsgraph, ps->scene, ps->ob,
ps->scene->customdata_mask | CD_MASK_MTFACE | (ps->do_face_sel ? CD_ORIGINDEX : 0));
ps->dm_release = true;
}
@@ -3489,7 +3475,7 @@ static void proj_paint_layer_clone_init(
/* use clone mtface? */
if (ps->do_layer_clone) {
- const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->pdata, CD_MTEXPOLY);
+ const int layer_num = CustomData_get_clone_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV);
ps->dm_mloopuv_clone = MEM_mallocN(ps->dm_totpoly * sizeof(MLoopUV *), "proj_paint_mtfaces");
@@ -3819,7 +3805,7 @@ static void project_paint_prepare_all_faces(
/* run once per stroke before projection painting */
static void project_paint_begin(
- ProjPaintState *ps,
+ const bContext *C, ProjPaintState *ps,
const bool is_multi_view, const char symmetry_flag)
{
ProjPaintLayerClone layer_clone;
@@ -3842,7 +3828,7 @@ static void project_paint_begin(
/* paint onto the derived mesh */
if (ps->is_shared_user == false) {
- if (!proj_paint_state_dm_init(ps)) {
+ if (!proj_paint_state_dm_init(C, ps)) {
return;
}
}
@@ -3852,7 +3838,7 @@ static void project_paint_begin(
if (ps->do_layer_stencil || ps->do_stencil_brush) {
//int layer_num = CustomData_get_stencil_layer(&ps->dm->loopData, CD_MLOOPUV);
- int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->pdata, CD_MTEXPOLY);
+ int layer_num = CustomData_get_stencil_layer(&((Mesh *)ps->ob->data)->ldata, CD_MLOOPUV);
if (layer_num != -1)
ps->dm_mloopuv_stencil = CustomData_get_layer_n(&ps->dm->loopData, CD_MLOOPUV, layer_num);
@@ -3940,7 +3926,7 @@ static void project_paint_end(ProjPaintState *ps)
ProjPaintImage *projIma;
for (a = 0, projIma = ps->projImages; a < ps->image_tot; a++, projIma++) {
BKE_image_release_ibuf(projIma->ima, projIma->ibuf, NULL);
- DAG_id_tag_update(&projIma->ima->id, 0);
+ DEG_id_tag_update(&projIma->ima->id, 0);
}
}
@@ -5026,6 +5012,7 @@ void paint_proj_stroke(
/* clone gets special treatment here to avoid going through image initialization */
if (ps_handle->is_clone_cursor_pick) {
Scene *scene = ps_handle->scene;
+ struct Depsgraph *graph = CTX_data_depsgraph(C);
View3D *v3d = CTX_wm_view3d(C);
ARegion *ar = CTX_wm_region(C);
float *cursor = ED_view3d_cursor3d_get(scene, v3d);
@@ -5033,8 +5020,9 @@ void paint_proj_stroke(
view3d_operator_needs_opengl(C);
- if (!ED_view3d_autodist(scene, ar, v3d, mval_i, cursor, false, NULL))
+ if (!ED_view3d_autodist(graph, ar, v3d, mval_i, cursor, false, NULL)) {
return;
+ }
ED_region_tag_redraw(ar);
@@ -5090,6 +5078,7 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
ps->rv3d = CTX_wm_region_view3d(C);
ps->ar = CTX_wm_region(C);
+ ps->depsgraph = CTX_data_depsgraph(C);
ps->scene = scene;
ps->ob = ob; /* allow override of active object */
@@ -5112,7 +5101,6 @@ static void project_state_init(bContext *C, Object *ob, ProjPaintState *ps, int
else {
ps->do_backfacecull = ps->do_occlude = ps->do_mask_normal = 0;
}
- ps->do_new_shading_nodes = BKE_scene_use_new_shading_nodes(scene); /* only cache the value */
if (ps->tool == PAINT_TOOL_CLONE)
ps->do_layer_clone = (settings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) ? 1 : 0;
@@ -5212,7 +5200,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m
project_state_init(C, ob, ps, mode);
- if (ps->ob == NULL || !(ps->ob->lay & ps->v3d->lay)) {
+ if (ps->ob == NULL) {
ps_handle->ps_views_tot = i + 1;
goto fail;
}
@@ -5236,7 +5224,7 @@ void *paint_proj_new_stroke(bContext *C, Object *ob, const float mouse[2], int m
PROJ_PAINT_STATE_SHARED_MEMCPY(ps, ps_handle->ps_views[0]);
}
- project_paint_begin(ps, is_multi_view, symmetry_flag_views[i]);
+ project_paint_begin(C, ps, is_multi_view, symmetry_flag_views[i]);
paint_proj_begin_clone(ps, mouse);
@@ -5314,11 +5302,12 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
{
Image *image = BLI_findlink(&CTX_data_main(C)->image, RNA_enum_get(op->ptr, "image"));
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
ProjPaintState ps = {NULL};
int orig_brush_size;
IDProperty *idgroup;
IDProperty *view_data = NULL;
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
bool uvs, mat, tex;
if (ob == NULL || ob->type != OB_MESH) {
@@ -5388,7 +5377,7 @@ static int texture_paint_camera_project_exec(bContext *C, wmOperator *op)
ED_image_undo_push_begin(op->type->name);
/* allocate and initialize spatial data structures */
- project_paint_begin(&ps, false, 0);
+ project_paint_begin(C, &ps, false, 0);
if (ps.dm == NULL) {
BKE_brush_size_set(scene, ps.brush, orig_brush_size);
@@ -5445,8 +5434,11 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
ImBuf *ibuf;
char filename[FILE_MAX];
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
ToolSettings *settings = scene->toolsettings;
+ View3D *v3d = CTX_wm_view3d(C);
+ RegionView3D *rv3d = CTX_wm_region_view3d(C);
int w = settings->imapaint.screen_grab_size[0];
int h = settings->imapaint.screen_grab_size[1];
int maxsize;
@@ -5460,9 +5452,10 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
if (h > maxsize) h = maxsize;
ibuf = ED_view3d_draw_offscreen_imbuf(
- scene, CTX_wm_view3d(C), CTX_wm_region(C),
+ depsgraph, scene, v3d->drawtype,
+ v3d, CTX_wm_region(C),
w, h, IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL,
- NULL, NULL, err_out);
+ NULL, err_out);
if (!ibuf) {
/* Mostly happens when OpenGL offscreen buffer was failed to create, */
/* but could be other reasons. Should be handled in the future. nazgul */
@@ -5478,9 +5471,6 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
if (image) {
/* now for the trickiness. store the view projection here!
* re-projection will reuse this */
- View3D *v3d = CTX_wm_view3d(C);
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
-
IDPropertyTemplate val;
IDProperty *idgroup = IDP_GetProperties(&image->id, 1);
IDProperty *view_data;
@@ -5494,7 +5484,7 @@ static int texture_paint_image_from_view_exec(bContext *C, wmOperator *op)
array = (float *)IDP_Array(view_data);
memcpy(array, rv3d->winmat, sizeof(rv3d->winmat)); array += sizeof(rv3d->winmat) / sizeof(float);
memcpy(array, rv3d->viewmat, sizeof(rv3d->viewmat)); array += sizeof(rv3d->viewmat) / sizeof(float);
- is_ortho = ED_view3d_clip_range_get(v3d, rv3d, &array[0], &array[1], true);
+ is_ortho = ED_view3d_clip_range_get(CTX_data_depsgraph(C), v3d, rv3d, &array[0], &array[1], true);
/* using float for a bool is dodgy but since its an extra member in the array...
* easier then adding a single bool prop */
array[2] = is_ortho ? 1.0f : 0.0f;
@@ -5594,7 +5584,7 @@ bool BKE_paint_proj_mesh_data_check(Scene *scene, Object *ob, bool *uvs, bool *m
}
me = BKE_mesh_from_object(ob);
- layernum = CustomData_number_of_layers(&me->pdata, CD_MTEXPOLY);
+ layernum = CustomData_number_of_layers(&me->ldata, CD_MLOOPUV);
if (layernum == 0) {
hasuvs = false;
@@ -5633,20 +5623,11 @@ bool BKE_paint_proj_mesh_data_check(Scene *scene, Object *ob, bool *uvs, bool *m
/* Add layer operator */
static const EnumPropertyItem layer_type_items[] = {
- {MAP_COL, "DIFFUSE_COLOR", 0, "Diffuse Color", ""},
- {MAP_REF, "DIFFUSE_INTENSITY", 0, "Diffuse Intensity", ""},
- {MAP_ALPHA, "ALPHA", 0, "Alpha", ""},
- {MAP_TRANSLU, "TRANSLUCENCY", 0, "Translucency", ""},
- {MAP_COLSPEC, "SPECULAR_COLOR", 0, "Specular Color", ""},
- {MAP_SPEC, "SPECULAR_INTENSITY", 0, "Specular Intensity", ""},
- {MAP_HAR, "SPECULAR_HARDNESS", 0, "Specular Hardness", ""},
- {MAP_AMB, "AMBIENT", 0, "Ambient", ""},
- {MAP_EMIT, "EMIT", 0, "Emit", ""},
- {MAP_COLMIR, "MIRROR_COLOR", 0, "Mirror Color", ""},
- {MAP_RAYMIRR, "RAYMIRROR", 0, "Ray Mirror", ""},
- {MAP_NORM, "NORMAL", 0, "Normal", ""},
- {MAP_WARP, "WARP", 0, "Warp", ""},
- {MAP_DISPLACE, "DISPLACE", 0, "Displace", ""},
+ {0, "BASE_COLOR", 0, "Base Color", ""},
+ {1, "EMISSION", 0, "Emission", ""},
+ {2, "NORMAL", 0, "Normal", ""},
+ {3, "BUMP", 0, "Bump", ""},
+ {4, "DISPLACEMENT", 0, "Displacement", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -5681,7 +5662,6 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
Object *ob = CTX_data_active_object(C);
Scene *scene = CTX_data_scene(C);
Material *ma;
- bool is_bi = BKE_scene_uses_blender_internal(scene) || BKE_scene_uses_blender_game(scene);
Image *ima = NULL;
if (!ob)
@@ -5690,60 +5670,34 @@ static bool proj_paint_add_slot(bContext *C, wmOperator *op)
ma = give_current_material(ob, ob->actcol);
if (ma) {
+ /* TODO: use type to link to proper socket. */
Main *bmain = CTX_data_main(C);
- if (!is_bi && BKE_scene_use_new_shading_nodes(scene)) {
- bNode *imanode;
- bNodeTree *ntree = ma->nodetree;
-
- if (!ntree) {
- ED_node_shader_default(C, &ma->id);
- ntree = ma->nodetree;
- }
-
- ma->use_nodes = true;
-
- /* try to add an image node */
- imanode = nodeAddStaticNode(C, ntree, SH_NODE_TEX_IMAGE);
-
- ima = proj_paint_image_create(op, bmain);
- imanode->id = &ima->id;
-
- nodeSetActive(ntree, imanode);
-
- ntreeUpdateTree(CTX_data_main(C), ntree);
- }
- else {
- MTex *mtex = BKE_texture_mtex_add_id(&ma->id, -1);
-
- /* successful creation of mtex layer, now create set */
- if (mtex) {
- int type = MAP_COL;
- char imagename_buff[MAX_ID_NAME - 2];
- const char *imagename = DATA_("Diffuse Color");
-
- if (op) {
- type = RNA_enum_get(op->ptr, "type");
- RNA_string_get(op->ptr, "name", imagename_buff);
- imagename = imagename_buff;
- }
-
- mtex->tex = BKE_texture_add(bmain, imagename);
- mtex->mapto = type;
-
- if (mtex->tex) {
- ima = mtex->tex->ima = proj_paint_image_create(op, bmain);
- }
+ bNode *imanode;
+ bNodeTree *ntree = ma->nodetree;
- WM_event_add_notifier(C, NC_TEXTURE | NA_ADDED, mtex->tex);
- }
+ if (!ntree) {
+ ED_node_shader_default(C, &ma->id);
+ ntree = ma->nodetree;
}
+ ma->use_nodes = true;
+
+ /* try to add an image node */
+ imanode = nodeAddStaticNode(C, ntree, SH_NODE_TEX_IMAGE);
+
+ ima = proj_paint_image_create(op, bmain);
+ imanode->id = &ima->id;
+
+ nodeSetActive(ntree, imanode);
+
+ ntreeUpdateTree(CTX_data_main(C), ntree);
+
if (ima) {
BKE_texpaint_slot_refresh_cache(scene, ma);
BKE_image_signal(ima, NULL, IMA_SIGNAL_USER_NEW_IMAGE);
WM_event_add_notifier(C, NC_IMAGE | NA_ADDED, ima);
- DAG_id_tag_update(&ma->id, 0);
+ DEG_id_tag_update(&ma->id, 0);
ED_area_tag_redraw(CTX_wm_area(C));
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
@@ -5829,59 +5783,6 @@ void PAINT_OT_add_texture_paint_slot(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "float", 0, "32 bit Float", "Create image with 32 bit floating point bit depth");
}
-static int texture_paint_delete_texture_paint_slot_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Object *ob = CTX_data_active_object(C);
- Scene *scene = CTX_data_scene(C);
- Material *ma;
- bool is_bi = BKE_scene_uses_blender_internal(scene) || BKE_scene_uses_blender_game(scene);
- TexPaintSlot *slot;
-
- /* not supported for node-based engines */
- if (!ob || !is_bi)
- return OPERATOR_CANCELLED;
-
- ma = give_current_material(ob, ob->actcol);
-
- if (!ma->texpaintslot || ma->use_nodes)
- return OPERATOR_CANCELLED;
-
- slot = ma->texpaintslot + ma->paint_active_slot;
-
- if (ma->mtex[slot->index]->tex) {
- id_us_min(&ma->mtex[slot->index]->tex->id);
-
- if (ma->mtex[slot->index]->tex->ima) {
- id_us_min(&ma->mtex[slot->index]->tex->ima->id);
- }
- }
- MEM_freeN(ma->mtex[slot->index]);
- ma->mtex[slot->index] = NULL;
-
- BKE_texpaint_slot_refresh_cache(scene, ma);
- DAG_id_tag_update(&ma->id, 0);
- WM_event_add_notifier(C, NC_MATERIAL, ma);
- /* we need a notifier for data change since we change the displayed modifier uvs */
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
- return OPERATOR_FINISHED;
-}
-
-
-void PAINT_OT_delete_texture_paint_slot(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Delete Texture Paint Slot";
- ot->description = "Delete selected texture paint slot";
- ot->idname = "PAINT_OT_delete_texture_paint_slot";
-
- /* api callbacks */
- ot->exec = texture_paint_delete_texture_paint_slot_exec;
- ot->poll = ED_operator_region_view3d_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op))
{
/* no checks here, poll function does them for us */
@@ -5917,7 +5818,7 @@ static int add_simple_uvs_exec(bContext *C, wmOperator *UNUSED(op))
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
- DAG_id_tag_update(ob->data, 0);
+ DEG_id_tag_update(ob->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, scene);
return OPERATOR_FINISHED;
@@ -5927,9 +5828,9 @@ static int add_simple_uvs_poll(bContext *C)
{
Object *ob = CTX_data_active_object(C);
- if (!ob || ob->type != OB_MESH || ob->mode != OB_MODE_TEXTURE_PAINT)
+ if (!ob || ob->type != OB_MESH || ob->mode != OB_MODE_TEXTURE_PAINT) {
return false;
-
+ }
return true;
}
diff --git a/source/blender/editors/sculpt_paint/paint_image_undo.c b/source/blender/editors/sculpt_paint/paint_image_undo.c
index ef28dafa8c9..ade775d14e6 100644
--- a/source/blender/editors/sculpt_paint/paint_image_undo.c
+++ b/source/blender/editors/sculpt_paint/paint_image_undo.c
@@ -33,16 +33,18 @@
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
+#include "DNA_workspace_types.h"
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BKE_main.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "ED_paint.h"
#include "ED_undo.h"
@@ -328,7 +330,7 @@ static void image_undo_restore_list(ListBase *lb, struct UndoIDPtrMap *id_map)
}
ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
BKE_image_release_ibuf(ima, ibuf, NULL);
}
diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h
index 63a12b3c145..a6d8a90e95a 100644
--- a/source/blender/editors/sculpt_paint/paint_intern.h
+++ b/source/blender/editors/sculpt_paint/paint_intern.h
@@ -94,8 +94,10 @@ void paint_cursor_delete_textures(void);
/* paint_vertex.c */
int weight_paint_poll(struct bContext *C);
+int weight_paint_poll_ignore_tool(bContext *C);
int weight_paint_mode_poll(struct bContext *C);
int vertex_paint_poll(struct bContext *C);
+int vertex_paint_poll_ignore_tool(struct bContext *C);
int vertex_paint_mode_poll(struct bContext *C);
typedef void (*VPaintTransform_Callback)(const float col[3], const void *user_data, float r_col[3]);
@@ -157,10 +159,10 @@ void PAINT_OT_weight_sample_group(struct wmOperatorType *ot);
/* paint_vertex_proj.c */
struct VertProjHandle;
struct VertProjHandle *ED_vpaint_proj_handle_create(
- struct Scene *scene, struct Object *ob,
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
struct DMCoNo **r_vcosnos);
void ED_vpaint_proj_handle_update(
- struct VertProjHandle *vp_handle,
+ struct Depsgraph *depsgraph, struct VertProjHandle *vp_handle,
/* runtime vars */
struct ARegion *ar, const float mval_fl[2]);
void ED_vpaint_proj_handle_free(
@@ -216,7 +218,6 @@ void PAINT_OT_texture_paint_toggle(struct wmOperatorType *ot);
void PAINT_OT_project_image(struct wmOperatorType *ot);
void PAINT_OT_image_from_view(struct wmOperatorType *ot);
void PAINT_OT_add_texture_paint_slot(struct wmOperatorType *ot);
-void PAINT_OT_delete_texture_paint_slot(struct wmOperatorType *ot);
void PAINT_OT_image_paint(struct wmOperatorType *ot);
void PAINT_OT_add_simple_uvs(struct wmOperatorType *ot);
@@ -259,7 +260,6 @@ bool paint_convert_bb_to_rect(struct rcti *rect,
* 2D screens-space bounding box into four 3D planes) */
void paint_calc_redraw_planes(float planes[4][4],
const struct ARegion *ar,
- struct RegionView3D *rv3d,
struct Object *ob,
const struct rcti *screen_rect);
diff --git a/source/blender/editors/sculpt_paint/paint_mask.c b/source/blender/editors/sculpt_paint/paint_mask.c
index 76b629395e2..f22e6f514e6 100644
--- a/source/blender/editors/sculpt_paint/paint_mask.c
+++ b/source/blender/editors/sculpt_paint/paint_mask.c
@@ -35,8 +35,6 @@
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
-#include "BIF_glutil.h"
-
#include "BLI_bitmap_draw_2d.h"
#include "BLI_math_matrix.h"
#include "BLI_math_geom.h"
@@ -52,6 +50,8 @@
#include "BKE_paint.h"
#include "BKE_subsurf.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -134,6 +134,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
ARegion *ar = CTX_wm_region(C);
struct Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
PaintMaskFloodMode mode;
float value;
PBVH *pbvh;
@@ -145,7 +146,7 @@ static int mask_flood_fill_exec(bContext *C, wmOperator *op)
mode = RNA_enum_get(op->ptr, "mode");
value = RNA_float_get(op->ptr, "value");
- BKE_sculpt_update_mesh_elements(scene, sd, ob, false, true);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, true);
pbvh = ob->sculpt->pbvh;
multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS);
@@ -258,9 +259,9 @@ static void mask_box_select_task_cb(
int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *rect, bool select, bool UNUSED(extend))
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Sculpt *sd = vc->scene->toolsettings->sculpt;
BoundBox bb;
- bglMats mats = {{0}};
float clip_planes[4][4];
float clip_planes_final[4][4];
ARegion *ar = vc->ar;
@@ -278,11 +279,10 @@ int ED_sculpt_mask_box_select(struct bContext *C, ViewContext *vc, const rcti *r
value = select ? 1.0 : 0.0;
/* transform the clip planes in object space */
- view3d_get_transformation(vc->ar, vc->rv3d, vc->obact, &mats);
- ED_view3d_clipping_calc(&bb, clip_planes, &mats, rect);
+ ED_view3d_clipping_calc(&bb, clip_planes, vc->ar, vc->obact, rect);
negate_m4(clip_planes);
- BKE_sculpt_update_mesh_elements(scene, sd, ob, false, true);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, true);
pbvh = ob->sculpt->pbvh;
multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS);
@@ -424,9 +424,9 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
const int (*mcords)[2] = WM_gesture_lasso_path_to_array(C, op, &mcords_tot);
if (mcords) {
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
float clip_planes[4][4], clip_planes_final[4][4];
BoundBox bb;
- bglMats mats = {{0}};
Object *ob;
ViewContext vc;
LassoMaskData data;
@@ -444,7 +444,6 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
* calculations done. Bounding box PBVH collision is not computed against enclosing rectangle
* of lasso */
ED_view3d_viewcontext_init(C, &vc);
- view3d_get_transformation(vc.ar, vc.rv3d, vc.obact, &mats);
/* lasso data calculations */
data.vc = &vc;
@@ -460,10 +459,10 @@ static int paint_mask_gesture_lasso_exec(bContext *C, wmOperator *op)
mcords, mcords_tot,
mask_lasso_px_cb, &data);
- ED_view3d_clipping_calc(&bb, clip_planes, &mats, &data.rect);
+ ED_view3d_clipping_calc(&bb, clip_planes, vc.ar, vc.obact, &data.rect);
negate_m4(clip_planes);
- BKE_sculpt_update_mesh_elements(scene, sd, ob, false, true);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, true);
pbvh = ob->sculpt->pbvh;
multires = (BKE_pbvh_type(pbvh) == PBVH_GRIDS);
diff --git a/source/blender/editors/sculpt_paint/paint_ops.c b/source/blender/editors/sculpt_paint/paint_ops.c
index 572d969dcca..3afff02ec52 100644
--- a/source/blender/editors/sculpt_paint/paint_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_ops.c
@@ -1035,7 +1035,6 @@ void ED_operatortypes_paint(void)
WM_operatortype_append(PAINT_OT_image_from_view);
WM_operatortype_append(PAINT_OT_brush_colors_flip);
WM_operatortype_append(PAINT_OT_add_texture_paint_slot);
- WM_operatortype_append(PAINT_OT_delete_texture_paint_slot);
WM_operatortype_append(PAINT_OT_add_simple_uvs);
/* weight */
diff --git a/source/blender/editors/sculpt_paint/paint_stroke.c b/source/blender/editors/sculpt_paint/paint_stroke.c
index e6a9fd9adf8..861015375cb 100644
--- a/source/blender/editors/sculpt_paint/paint_stroke.c
+++ b/source/blender/editors/sculpt_paint/paint_stroke.c
@@ -51,6 +51,7 @@
#include "BKE_curve.h"
#include "BKE_colortools.h"
#include "BKE_image.h"
+#include "BKE_mesh.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -58,7 +59,7 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
-#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
#include "ED_screen.h"
#include "ED_view3d.h"
@@ -147,9 +148,18 @@ static void paint_draw_smooth_cursor(bContext *C, int x, int y, void *customdata
if (stroke && brush) {
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
- glColor4ubv(paint->paint_cursor_col);
- sdrawline(x, y, (int)stroke->last_mouse_position[0],
- (int)stroke->last_mouse_position[1]);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4ubv(paint->paint_cursor_col);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, x, y);
+ immVertex2f(pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
+ immEnd();
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
}
@@ -161,36 +171,35 @@ static void paint_draw_line_cursor(bContext *C, int x, int y, void *customdata)
PaintStroke *stroke = customdata;
glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(3, 0xAAAA);
- GPU_basic_shader_line_width(3.0);
+ uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- glColor4ub(0, 0, 0, paint->paint_cursor_col[3]);
- if (stroke->constrain_line) {
- sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1],
- stroke->constrained_pos[0], stroke->constrained_pos[1]);
- }
- else {
- sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1],
- x, y);
- }
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ const float alpha = (float)paint->paint_cursor_col[3] / 255.0f;
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.0f, 0.0f, 0.0f, alpha}, {1.0f, 1.0f, 1.0f, alpha}}, 2);
+ immUniform1f("dash_width", 6.0f);
+
+ immBegin(GWN_PRIM_LINES, 2);
- glColor4ub(255, 255, 255, paint->paint_cursor_col[3]);
- GPU_basic_shader_line_width(1.0);
if (stroke->constrain_line) {
- sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1],
- stroke->constrained_pos[0], stroke->constrained_pos[1]);
+ immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
+ immVertex2f(shdr_pos, stroke->constrained_pos[0], stroke->constrained_pos[1]);
}
else {
- sdrawline((int)stroke->last_mouse_position[0], (int)stroke->last_mouse_position[1],
- x, y);
+ immVertex2f(shdr_pos, stroke->last_mouse_position[0], stroke->last_mouse_position[1]);
+ immVertex2f(shdr_pos, x, y);
}
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
+ immEnd();
+
+ immUnbindProgram();
- glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
}
diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c
index 70fd57830c0..f8888ad9809 100644
--- a/source/blender/editors/sculpt_paint/paint_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_utils.c
@@ -56,11 +56,13 @@
#include "BKE_paint.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf_types.h"
@@ -130,17 +132,12 @@ bool paint_convert_bb_to_rect(rcti *rect,
* 2D screens-space bounding box into four 3D planes) */
void paint_calc_redraw_planes(float planes[4][4],
const ARegion *ar,
- RegionView3D *rv3d,
Object *ob,
const rcti *screen_rect)
{
BoundBox bb;
- bglMats mats;
rcti rect;
- memset(&bb, 0, sizeof(BoundBox));
- view3d_get_transformation(ar, rv3d, ob, &mats);
-
/* use some extra space just in case */
rect = *screen_rect;
rect.xmin -= 2;
@@ -148,7 +145,7 @@ void paint_calc_redraw_planes(float planes[4][4],
rect.ymin -= 2;
rect.ymax += 2;
- ED_view3d_clipping_calc(&bb, planes, &mats, &rect);
+ ED_view3d_clipping_calc(&bb, planes, ar, ob, &rect);
negate_m4(planes);
}
@@ -277,9 +274,9 @@ static void imapaint_tri_weights(float matrix[4][4], GLint view[4],
}
/* compute uv coordinates of mouse in face */
-static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2])
+static void imapaint_pick_uv(Depsgraph *depsgraph, Scene *scene, Object *ob, unsigned int faceindex, const int xy[2], float uv[2])
{
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+ DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
const int tottri = dm->getNumLoopTri(dm);
int i, findex;
float p[2], w[3], absw, minabsw;
@@ -293,8 +290,8 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
/* get the needed opengl matrices */
glGetIntegerv(GL_VIEWPORT, view);
- glGetFloatv(GL_MODELVIEW_MATRIX, (float *)matrix);
- glGetFloatv(GL_PROJECTION_MATRIX, (float *)proj);
+ gpuGetModelViewMatrix(matrix);
+ gpuGetProjectionMatrix(proj);
view[0] = view[1] = 0;
mul_m4_m4m4(matrix, matrix, ob->obmat);
mul_m4_m4m4(matrix, proj, matrix);
@@ -355,7 +352,9 @@ static void imapaint_pick_uv(Scene *scene, Object *ob, unsigned int faceindex, c
}
/* returns 0 if not found, otherwise 1 */
-static int imapaint_pick_face(ViewContext *vc, const int mval[2], unsigned int *r_index, unsigned int totpoly)
+static int imapaint_pick_face(
+ ViewContext *vc, const int mval[2],
+ unsigned int *r_index, unsigned int totpoly)
{
if (totpoly == 0)
return 0;
@@ -427,6 +426,7 @@ void flip_qt_qt(float out[4], const float in[4], const char symm)
void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_proj, bool use_palette)
{
Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Paint *paint = BKE_paint_get_active_from_context(C);
Palette *palette = BKE_paint_palette(paint);
PaletteColor *color = NULL;
@@ -450,14 +450,15 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr
if (CTX_wm_view3d(C) && texpaint_proj) {
/* first try getting a colour directly from the mesh faces if possible */
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
bool sample_success = false;
ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
bool use_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL);
if (ob) {
Mesh *me = (Mesh *)ob->data;
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
+ DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
ViewContext vc;
const int mval[2] = {x, y};
@@ -482,7 +483,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr
if (ibuf && ibuf->rect) {
float uv[2];
float u, v;
- imapaint_pick_uv(scene, ob, faceindex, mval, uv);
+ imapaint_pick_uv(depsgraph, scene, ob, faceindex, mval, uv);
sample_success = true;
u = fmodf(uv[0], 1.0f);
@@ -496,10 +497,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr
if (ibuf->rect_float) {
float rgba_f[4];
- if (U.gameflags & USER_DISABLE_MIPMAP)
- nearest_interpolation_color_wrap(ibuf, NULL, rgba_f, u, v);
- else
- bilinear_interpolation_color_wrap(ibuf, NULL, rgba_f, u, v);
+ bilinear_interpolation_color_wrap(ibuf, NULL, rgba_f, u, v);
straight_to_premul_v4(rgba_f);
if (use_palette) {
linearrgb_to_srgb_v3_v3(color->rgb, rgba_f);
@@ -511,10 +509,7 @@ void paint_sample_color(bContext *C, ARegion *ar, int x, int y, bool texpaint_pr
}
else {
unsigned char rgba[4];
- if (U.gameflags & USER_DISABLE_MIPMAP)
- nearest_interpolation_color_wrap(ibuf, rgba, NULL, u, v);
- else
- bilinear_interpolation_color_wrap(ibuf, rgba, NULL, u, v);
+ bilinear_interpolation_color_wrap(ibuf, rgba, NULL, u, v);
if (use_palette) {
rgb_uchar_to_float(color->rgb, rgba);
}
@@ -564,8 +559,9 @@ static int brush_curve_preset_exec(bContext *C, wmOperator *op)
if (br) {
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
BKE_brush_curve_preset(br, RNA_enum_get(op->ptr, "shape"));
- BKE_paint_invalidate_cursor_overlay(scene, br->curve);
+ BKE_paint_invalidate_cursor_overlay(scene, view_layer, br->curve);
}
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c
index 4b2eb0fdd30..d5991ac67d4 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex.c
@@ -54,8 +54,9 @@
#include "BKE_brush.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_deform.h"
+#include "BKE_global.h"
+#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_object_deform.h"
@@ -63,6 +64,8 @@
#include "BKE_report.h"
#include "BKE_subsurf.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -203,7 +206,7 @@ int vertex_paint_mode_poll(bContext *C)
return ob && ob->mode == OB_MODE_VERTEX_PAINT && ((Mesh *)ob->data)->totpoly;
}
-int vertex_paint_poll(bContext *C)
+static int vertex_paint_poll_ex(bContext *C, bool check_tool)
{
if (vertex_paint_mode_poll(C) &&
BKE_paint_brush(&CTX_data_tool_settings(C)->vpaint->paint))
@@ -211,13 +214,26 @@ int vertex_paint_poll(bContext *C)
ScrArea *sa = CTX_wm_area(C);
if (sa && sa->spacetype == SPACE_VIEW3D) {
ARegion *ar = CTX_wm_region(C);
- if (ar->regiontype == RGN_TYPE_WINDOW)
- return 1;
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) {
+ return 1;
+ }
+ }
}
}
return 0;
}
+int vertex_paint_poll(bContext *C)
+{
+ return vertex_paint_poll_ex(C, true);
+}
+
+int vertex_paint_poll_ignore_tool(bContext *C)
+{
+ return vertex_paint_poll_ex(C, true);
+}
+
int weight_paint_mode_poll(bContext *C)
{
Object *ob = CTX_data_active_object(C);
@@ -225,7 +241,7 @@ int weight_paint_mode_poll(bContext *C)
return ob && ob->mode == OB_MODE_WEIGHT_PAINT && ((Mesh *)ob->data)->totpoly;
}
-int weight_paint_poll(bContext *C)
+static int weight_paint_poll_ex(bContext *C, bool check_tool)
{
Object *ob = CTX_data_active_object(C);
ScrArea *sa;
@@ -238,12 +254,24 @@ int weight_paint_poll(bContext *C)
{
ARegion *ar = CTX_wm_region(C);
if (ar->regiontype == RGN_TYPE_WINDOW) {
- return 1;
+ if (!check_tool || WM_toolsystem_active_tool_is_brush(C)) {
+ return 1;
+ }
}
}
return 0;
}
+int weight_paint_poll(bContext *C)
+{
+ return weight_paint_poll_ex(C, true);
+}
+
+int weight_paint_poll_ignore_tool(bContext *C)
+{
+ return weight_paint_poll_ex(C, false);
+}
+
static VPaint *new_vpaint(void)
{
VPaint *vp = MEM_callocN(sizeof(VPaint), "VPaint");
@@ -937,14 +965,14 @@ static void do_weight_paint_vertex(
/* Toggle operator for turning vertex paint mode on or off (copied from sculpt.c) */
-static void vertex_paint_init_session(Scene *scene, Object *ob)
+static void vertex_paint_init_session(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
/* Create persistent sculpt mode data */
BKE_sculpt_toolsettings_data_ensure(scene);
if (ob->sculpt == NULL) {
ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
- BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, 0, false);
}
}
@@ -1031,8 +1059,7 @@ static void vertex_paint_init_session_data(const ToolSettings *ts, Object *ob)
* \{ */
static void ed_vwpaintmode_enter_generic(
- wmWindowManager *wm,
- Scene *scene,
+ Depsgraph *depsgraph, wmWindowManager *wm, Scene *scene,
Object *ob, const eObjectMode mode_flag)
{
ob->mode |= mode_flag;
@@ -1078,37 +1105,39 @@ static void ed_vwpaintmode_enter_generic(
BKE_sculptsession_free(ob);
}
- vertex_paint_init_session(scene, ob);
+ vertex_paint_init_session(depsgraph, scene, ob);
}
void ED_object_vpaintmode_enter_ex(
- wmWindowManager *wm,
+ Depsgraph *depsgraph, wmWindowManager *wm,
Scene *scene, Object *ob)
{
ed_vwpaintmode_enter_generic(
- wm, scene, ob, OB_MODE_VERTEX_PAINT);
+ depsgraph, wm, scene, ob, OB_MODE_VERTEX_PAINT);
}
void ED_object_vpaintmode_enter(struct bContext *C)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
wmWindowManager *wm = CTX_wm_manager(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- ED_object_vpaintmode_enter_ex(wm, scene, ob);
+ ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob);
}
void ED_object_wpaintmode_enter_ex(
- wmWindowManager *wm,
+ Depsgraph *depsgraph, wmWindowManager *wm,
Scene *scene, Object *ob)
{
ed_vwpaintmode_enter_generic(
- wm, scene, ob, OB_MODE_WEIGHT_PAINT);
+ depsgraph, wm, scene, ob, OB_MODE_WEIGHT_PAINT);
}
void ED_object_wpaintmode_enter(struct bContext *C)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
wmWindowManager *wm = CTX_wm_manager(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- ED_object_wpaintmode_enter_ex(wm, scene, ob);
+ ED_object_wpaintmode_enter_ex(depsgraph, wm, scene, ob);
}
/** \} */
@@ -1205,8 +1234,9 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
ED_object_wpaintmode_exit_ex(ob);
}
else {
+ Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
wmWindowManager *wm = CTX_wm_manager(C);
- ED_object_wpaintmode_enter_ex(wm, scene, ob);
+ ED_object_wpaintmode_enter_ex(depsgraph, wm, scene, ob);
}
/* Weightpaint works by overriding colors in mesh,
@@ -1214,7 +1244,7 @@ static int wpaint_mode_toggle_exec(bContext *C, wmOperator *op)
* exit (exit needs doing regardless because we
* should redeform).
*/
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
@@ -1397,6 +1427,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
bool *defbase_sel;
SculptSession *ss = ob->sculpt;
VPaint *vp = CTX_data_tool_settings(C)->wpaint;
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
if (ED_wpaint_ensure_data(C, op->reports, WPAINT_ENSURE_MIRROR, &vgroup_index) == false) {
return false;
@@ -1500,7 +1531,7 @@ static bool wpaint_stroke_test_start(bContext *C, wmOperator *op, const float mo
}
/* If not previously created, create vertex/weight paint mode session data */
- vertex_paint_init_session(scene, ob);
+ vertex_paint_init_session(depsgraph, scene, ob);
vwpaint_update_cache_invariants(C, vp, ss, op, mouse);
vertex_paint_init_session_data(ts, ob);
@@ -1941,7 +1972,8 @@ static void wpaint_paint_leaves(
/* threaded loop over nodes */
SculptThreadedTaskData data = {
- .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vp = vp, .wpd = wpd, .wpi = wpi, .me = me, .C = C,
+ .C = C, .sd = sd, .ob = ob, .brush = brush, .nodes = nodes,
+ .vp = vp, .wpd = wpd, .wpi = wpi, .me = me,
};
/* Use this so average can modify its weight without touching the brush. */
@@ -2169,7 +2201,9 @@ static void wpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
/* also needed for "View Selected" on last stroke */
paint_last_stroke_update(scene, vc->ar, mval);
- DAG_id_tag_update(ob->data, 0);
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
+
+ DEG_id_tag_update(ob->data, 0);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
swap_m4m4(wpd->vc.rv3d->persmat, mat);
@@ -2233,7 +2267,7 @@ static void wpaint_stroke_done(const bContext *C, struct PaintStroke *stroke)
}
}
- DAG_id_tag_update(ob->data, 0);
+ DEG_id_tag_update(ob->data, 0);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
@@ -2333,12 +2367,15 @@ static int vpaint_mode_toggle_exec(bContext *C, wmOperator *op)
ED_object_vpaintmode_exit_ex(ob);
}
else {
+ Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
wmWindowManager *wm = CTX_wm_manager(C);
- ED_object_vpaintmode_enter_ex(wm, scene, ob);
+ ED_object_vpaintmode_enter_ex(depsgraph, wm, scene, ob);
}
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
+
/* update modifier stack for mapping requirements */
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
@@ -2424,6 +2461,7 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f
Object *ob = CTX_data_active_object(C);
Mesh *me;
SculptSession *ss = ob->sculpt;
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
/* context checks could be a poll() */
me = BKE_mesh_from_object(ob);
@@ -2471,12 +2509,12 @@ static bool vpaint_stroke_test_start(bContext *C, struct wmOperator *op, const f
/* Create projection handle */
if (vpd->is_texbrush) {
ob->sculpt->building_vp_handle = true;
- vpd->vp_handle = ED_vpaint_proj_handle_create(scene, ob, &vpd->vertexcosnos);
+ vpd->vp_handle = ED_vpaint_proj_handle_create(depsgraph, scene, ob, &vpd->vertexcosnos);
ob->sculpt->building_vp_handle = false;
}
/* If not previously created, create vertex/weight paint mode session data */
- vertex_paint_init_session(scene, ob);
+ vertex_paint_init_session(depsgraph, scene, ob);
vwpaint_update_cache_invariants(C, vp, ss, op, mouse);
vertex_paint_init_session_data(ts, ob);
@@ -2932,8 +2970,8 @@ static void vpaint_paint_leaves(
const Brush *brush = ob->sculpt->cache->brush;
SculptThreadedTaskData data = {
- .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vp = vp, .vpd = vpd,
- .lcol = (uint *)me->mloopcol, .me = me, .C = C,
+ .C = C, .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vp = vp, .vpd = vpd,
+ .lcol = (uint *)me->mloopcol, .me = me,
};
ParallelRangeSettings settings;
BLI_parallel_range_settings_defaults(&settings);
@@ -3070,6 +3108,8 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
swap_m4m4(vc->rv3d->persmat, mat);
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_ALL);
+
if (vp->paint.brush->vertexpaint_tool == PAINT_BLEND_SMEAR) {
memcpy(vpd->smear.color_prev, vpd->smear.color_curr, sizeof(uint) * ((Mesh *)ob->data)->totloop);
}
@@ -3083,11 +3123,7 @@ static void vpaint_stroke_update_step(bContext *C, struct PaintStroke *stroke, P
if (vpd->use_fast_update == false) {
/* recalculate modifier stack to get new colors, slow,
* avoid this if we can! */
- DAG_id_tag_update(ob->data, 0);
- }
- else {
- /* If using new VBO drawing, mark mcol as dirty to force colors gpu buffer refresh! */
- ob->derivedFinal->dirty |= DM_DIRTY_MCOL_UPDATE_DRAW;
+ DEG_id_tag_update(ob->data, 0);
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
index b69ca32e5af..d7668a48139 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex_color_ops.c
@@ -33,10 +33,11 @@
#include "BLI_math_color.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
#include "BKE_deform.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -97,7 +98,7 @@ static bool vertex_color_set(Object *ob, uint paintcol)
/* remove stale me->mcol, will be added later */
BKE_mesh_tessface_clear(me);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
return true;
}
@@ -168,7 +169,7 @@ static bool vertex_paint_from_weight(Object *ob)
} while (j < mp->totloop);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
return true;
}
@@ -304,7 +305,7 @@ static bool vertex_color_smooth(Object *ob)
MEM_freeN(mlooptag);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
return true;
}
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c
index a0bd5ea2a2d..481d5e7d5ea 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex_color_utils.c
@@ -38,9 +38,10 @@
#include "IMB_colormanagement.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
+#include "DEG_depsgraph.h"
+
#include "ED_mesh.h"
#include "paint_intern.h" /* own include */
@@ -87,7 +88,7 @@ bool ED_vpaint_color_transform(
/* remove stale me->mcol, will be added later */
BKE_mesh_tessface_clear(me);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
return true;
}
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_proj.c b/source/blender/editors/sculpt_paint/paint_vertex_proj.c
index 411a0ca9ec3..c5c9aa48760 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex_proj.c
@@ -42,6 +42,8 @@
#include "BKE_DerivedMesh.h"
#include "BKE_context.h"
+#include "DEG_depsgraph.h"
+
#include "ED_screen.h"
#include "ED_view3d.h"
@@ -100,13 +102,13 @@ static void vpaint_proj_dm_map_cosnos_init__map_cb(
}
static void vpaint_proj_dm_map_cosnos_init(
- Scene *scene, Object *ob,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob,
struct VertProjHandle *vp_handle)
{
Mesh *me = ob->data;
DerivedMesh *dm;
- dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
+ dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
if (dm->foreachMappedVert) {
memset(vp_handle->vcosnos, 0, sizeof(DMCoNo) * me->totvert);
@@ -174,7 +176,7 @@ static void vpaint_proj_dm_map_cosnos_update__map_cb(
}
static void vpaint_proj_dm_map_cosnos_update(
- struct VertProjHandle *vp_handle,
+ struct Depsgraph *depsgraph, struct VertProjHandle *vp_handle,
ARegion *ar, const float mval_fl[2])
{
struct VertProjUpdate vp_update = {vp_handle, ar, mval_fl};
@@ -187,7 +189,7 @@ static void vpaint_proj_dm_map_cosnos_update(
/* quick sanity check - we shouldn't have to run this if there are no modifiers */
BLI_assert(BLI_listbase_is_empty(&ob->modifiers) == false);
- dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
+ dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH | CD_MASK_ORIGINDEX);
/* highly unlikely this will become unavailable once painting starts (perhaps with animated modifiers) */
if (LIKELY(dm->foreachMappedVert)) {
@@ -204,7 +206,7 @@ static void vpaint_proj_dm_map_cosnos_update(
/* Public Functions */
struct VertProjHandle *ED_vpaint_proj_handle_create(
- Scene *scene, Object *ob,
+ struct Depsgraph *depsgraph, Scene *scene, Object *ob,
DMCoNo **r_vcosnos)
{
struct VertProjHandle *vp_handle = MEM_mallocN(sizeof(struct VertProjHandle), __func__);
@@ -215,7 +217,7 @@ struct VertProjHandle *ED_vpaint_proj_handle_create(
vp_handle->use_update = false;
/* sets 'use_update' if needed */
- vpaint_proj_dm_map_cosnos_init(scene, ob, vp_handle);
+ vpaint_proj_dm_map_cosnos_init(depsgraph, scene, ob, vp_handle);
if (vp_handle->use_update) {
vp_handle->dists_sq = MEM_mallocN(sizeof(float) * me->totvert, __func__);
@@ -235,11 +237,11 @@ struct VertProjHandle *ED_vpaint_proj_handle_create(
}
void ED_vpaint_proj_handle_update(
- struct VertProjHandle *vp_handle,
+ struct Depsgraph *depsgraph, struct VertProjHandle *vp_handle,
ARegion *ar, const float mval_fl[2])
{
if (vp_handle->use_update) {
- vpaint_proj_dm_map_cosnos_update(vp_handle, ar, mval_fl);
+ vpaint_proj_dm_map_cosnos_update(depsgraph, vp_handle, ar, mval_fl);
}
}
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
index 957cb6a7389..e560a4cddff 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_ops.c
@@ -49,7 +49,6 @@
#include "BKE_DerivedMesh.h"
#include "BKE_brush.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_deform.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
@@ -59,6 +58,8 @@
#include "BKE_report.h"
#include "BKE_colortools.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -124,15 +125,16 @@ static int weight_from_bones_poll(bContext *C)
static int weight_from_bones_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
Object *armob = modifiers_isDeformedByArmature(ob);
Mesh *me = ob->data;
int type = RNA_enum_get(op->ptr, "type");
- ED_object_vgroup_calc_from_armature(op->reports, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X));
+ ED_object_vgroup_calc_from_armature(op->reports, depsgraph, scene, ob, armob, type, (me->editflag & ME_EDIT_MIRROR_X));
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return OPERATOR_FINISHED;
@@ -366,7 +368,7 @@ static int weight_sample_group_exec(bContext *C, wmOperator *op)
BLI_assert(type + 1 >= 0);
vc.obact->actdef = type + 1;
- DAG_id_tag_update(&vc.obact->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&vc.obact->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, vc.obact);
return OPERATOR_FINISHED;
}
@@ -482,7 +484,7 @@ static bool weight_paint_set(Object *ob, float paintweight)
wpaint_prev_destroy(&wpp);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
return true;
}
@@ -694,7 +696,7 @@ static int paint_weight_gradient_modal(bContext *C, wmOperator *op, const wmEven
}
MEM_freeN(vert_cache);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
}
else if (ret & OPERATOR_FINISHED) {
@@ -720,7 +722,10 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op)
float sco_start[2] = {x_start, y_start};
float sco_end[2] = {x_end, y_end};
const bool is_interactive = (gesture != NULL);
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
+
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
+ DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, scene->customdata_mask);
DMGradient_userData data = {NULL};
@@ -792,7 +797,7 @@ static int paint_weight_gradient_exec(bContext *C, wmOperator *op)
dm->foreachMappedVert(dm, gradientVertUpdate__mapFunc, &data, DM_FOREACH_NOP);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
if (is_interactive == false) {
@@ -844,7 +849,7 @@ void PAINT_OT_weight_gradient(wmOperatorType *ot)
ot->invoke = paint_weight_gradient_invoke;
ot->modal = paint_weight_gradient_modal;
ot->exec = paint_weight_gradient_exec;
- ot->poll = weight_paint_poll;
+ ot->poll = weight_paint_poll_ignore_tool;
ot->cancel = WM_gesture_straightline_cancel;
/* flags */
diff --git a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c
index 4d70d82d5c6..51cd759b260 100644
--- a/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c
+++ b/source/blender/editors/sculpt_paint/paint_vertex_weight_utils.c
@@ -43,6 +43,7 @@
#include "BKE_modifier.h"
#include "BKE_object_deform.h"
#include "BKE_report.h"
+#include "BKE_object.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -58,7 +59,6 @@ bool ED_wpaint_ensure_data(
bContext *C, struct ReportList *reports,
enum eWPaintFlag flag, struct WPaintVGroupIndex *vgroup_index)
{
- Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
Mesh *me = BKE_mesh_from_object(ob);
@@ -67,7 +67,7 @@ bool ED_wpaint_ensure_data(
vgroup_index->mirror = -1;
}
- if (scene->obedit) {
+ if (BKE_object_is_in_editmode(ob)) {
return false;
}
@@ -308,4 +308,4 @@ float ED_wpaint_blend_tool(
}
}
-/** \} */ \ No newline at end of file
+/** \} */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c
index f9bfe4be866..5f5fa044f1e 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -56,7 +56,6 @@
#include "BKE_brush.h"
#include "BKE_ccg.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_key.h"
@@ -73,6 +72,8 @@
#include "BKE_subsurf.h"
#include "BKE_colortools.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -86,9 +87,6 @@
#include "RNA_access.h"
#include "RNA_define.h"
-#include "GPU_buffers.h"
-#include "GPU_extensions.h"
-
#include "UI_interface.h"
#include "UI_resources.h"
@@ -500,8 +498,7 @@ bool sculpt_get_redraw_rect(ARegion *ar, RegionView3D *rv3d,
return 1;
}
-void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar,
- RegionView3D *rv3d, Object *ob)
+void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar, Object *ob)
{
PBVH *pbvh = ob->sculpt->pbvh;
/* copy here, original will be used below */
@@ -509,7 +506,7 @@ void ED_sculpt_redraw_planes_get(float planes[4][4], ARegion *ar,
sculpt_extend_redraw_rect_previous(ob, &rect);
- paint_calc_redraw_planes(planes, ar, rv3d, ob, &rect);
+ paint_calc_redraw_planes(planes, ar, ob, &rect);
/* we will draw this rect, so now we can set it as the previous partial rect.
* Note that we don't update with the union of previous/current (rect), only with
@@ -2101,6 +2098,10 @@ static void do_draw_brush(Sculpt *sd, Object *ob, PBVHNode **nodes, int totnode)
mul_v3_v3(offset, ss->cache->scale);
mul_v3_fl(offset, bstrength);
+ /* XXX - this shouldn't be necessary, but sculpting crashes in blender2.8 otherwise
+ * initialize before threads so they can do curve mapping */
+ curvemapping_initialize(brush->curve);
+
/* threaded loop over nodes */
SculptThreadedTaskData data = {
.sd = sd, .ob = ob, .brush = brush, .nodes = nodes,
@@ -4599,10 +4600,11 @@ static void sculpt_stroke_modifiers_check(const bContext *C, Object *ob, const B
SculptSession *ss = ob->sculpt;
if (ss->kb || ss->modifiers_active) {
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Sculpt *sd = scene->toolsettings->sculpt;
bool need_pmap = sculpt_any_smooth_mode(brush, ss->cache, 0);
- BKE_sculpt_update_mesh_elements(scene, sd, ob, need_pmap, false);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, need_pmap, false);
}
}
@@ -4687,7 +4689,7 @@ static float sculpt_raycast_init(
RegionView3D *rv3d = vc->ar->regiondata;
/* TODO: what if the segment is totally clipped? (return == 0) */
- ED_view3d_win_to_segment(vc->ar, vc->v3d, mouse, ray_start, ray_end, true);
+ ED_view3d_win_to_segment(vc->depsgraph, vc->ar, vc->v3d, mouse, ray_start, ray_end, true);
invert_m4_m4(obimat, ob->obmat);
mul_m4_v3(obimat, ray_start);
@@ -4805,6 +4807,7 @@ static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession
static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
@@ -4822,7 +4825,7 @@ static bool sculpt_brush_stroke_init(bContext *C, wmOperator *op)
sculpt_brush_init_tex(scene, sd, ss);
is_smooth = sculpt_any_smooth_mode(brush, NULL, mode);
- BKE_sculpt_update_mesh_elements(scene, sd, ob, is_smooth, need_mask);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, is_smooth, need_mask);
return 1;
}
@@ -4862,11 +4865,9 @@ static void sculpt_flush_update(bContext *C)
if (mmd)
multires_mark_as_modified(ob, MULTIRES_COORDS_MODIFIED);
- if (ob->derivedFinal) /* VBO no longer valid */
- GPU_drawobject_free(ob->derivedFinal);
if (ss->kb || ss->modifiers_active) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
ED_region_tag_redraw(ar);
}
else {
@@ -4896,6 +4897,9 @@ static void sculpt_flush_update(bContext *C)
ED_region_tag_redraw_partial(ar, &r);
}
}
+
+ /* 2.8x - avoid full mesh update! */
+ BKE_mesh_batch_cache_dirty(ob->data, BKE_MESH_BATCH_DIRTY_SCULPT_COORDS);
}
/* Returns whether the mouse/stylus is over the mesh (1)
@@ -4979,7 +4983,7 @@ static void sculpt_stroke_update_step(bContext *C, struct PaintStroke *UNUSED(st
* Could be optimized later, but currently don't think it's so
* much common scenario.
*
- * Same applies to the DAG_id_tag_update() invoked from
+ * Same applies to the DEG_id_tag_update() invoked from
* sculpt_flush_update().
*/
if (ss->modifiers_active) {
@@ -5053,7 +5057,7 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str
/* try to avoid calling this, only for e.g. linked duplicates now */
if (((Mesh *)ob->data)->id.us > 1)
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
}
@@ -5246,16 +5250,18 @@ void sculpt_dyntopo_node_layers_add(SculptSession *ss)
void sculpt_update_after_dynamic_topology_toggle(
+ Depsgraph *depsgraph,
Scene *scene, Object *ob)
{
Sculpt *sd = scene->toolsettings->sculpt;
/* Create the PBVH */
- BKE_sculpt_update_mesh_elements(scene, sd, ob, false, false);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, false, false);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
}
void sculpt_dynamic_topology_enable_ex(
+ Depsgraph *depsgraph,
Scene *scene, Object *ob)
{
SculptSession *ss = ob->sculpt;
@@ -5293,7 +5299,7 @@ void sculpt_dynamic_topology_enable_ex(
ss->bm_log = BM_log_create(ss->bm);
/* Refresh */
- sculpt_update_after_dynamic_topology_toggle(scene, ob);
+ sculpt_update_after_dynamic_topology_toggle(depsgraph, scene, ob);
}
/* Free the sculpt BMesh and BMLog
@@ -5301,6 +5307,7 @@ void sculpt_dynamic_topology_enable_ex(
* If 'unode' is given, the BMesh's data is copied out to the unode
* before the BMesh is deleted so that it can be restored from */
void sculpt_dynamic_topology_disable_ex(
+ Depsgraph *depsgraph,
Scene *scene, Object *ob, SculptUndoNode *unode)
{
SculptSession *ss = ob->sculpt;
@@ -5351,35 +5358,37 @@ void sculpt_dynamic_topology_disable_ex(
}
/* Refresh */
- sculpt_update_after_dynamic_topology_toggle(scene, ob);
+ sculpt_update_after_dynamic_topology_toggle(depsgraph, scene, ob);
}
void sculpt_dynamic_topology_disable(bContext *C, SculptUndoNode *unode)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- sculpt_dynamic_topology_disable_ex(scene, ob, unode);
+ sculpt_dynamic_topology_disable_ex(depsgraph, scene, ob, unode);
}
static void sculpt_dynamic_topology_disable_with_undo(
- Scene *scene, Object *ob)
+ Depsgraph *depsgraph, Scene *scene, Object *ob)
{
SculptSession *ss = ob->sculpt;
if (ss->bm) {
sculpt_undo_push_begin("Dynamic topology disable");
sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_END);
- sculpt_dynamic_topology_disable_ex(scene, ob, NULL);
+ sculpt_dynamic_topology_disable_ex(depsgraph, scene, ob, NULL);
sculpt_undo_push_end();
}
}
static void sculpt_dynamic_topology_enable_with_undo(
+ Depsgraph *depsgraph,
Scene *scene, Object *ob)
{
SculptSession *ss = ob->sculpt;
if (ss->bm == NULL) {
sculpt_undo_push_begin("Dynamic topology enable");
- sculpt_dynamic_topology_enable_ex(scene, ob);
+ sculpt_dynamic_topology_enable_ex(depsgraph, scene, ob);
sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN);
sculpt_undo_push_end();
}
@@ -5387,6 +5396,7 @@ static void sculpt_dynamic_topology_enable_with_undo(
static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(op))
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
SculptSession *ss = ob->sculpt;
@@ -5394,10 +5404,10 @@ static int sculpt_dynamic_topology_toggle_exec(bContext *C, wmOperator *UNUSED(o
WM_cursor_wait(1);
if (ss->bm) {
- sculpt_dynamic_topology_disable_with_undo(scene, ob);
+ sculpt_dynamic_topology_disable_with_undo(depsgraph, scene, ob);
}
else {
- sculpt_dynamic_topology_enable_with_undo(scene, ob);
+ sculpt_dynamic_topology_enable_with_undo(depsgraph, scene, ob);
}
WM_cursor_wait(0);
@@ -5608,13 +5618,14 @@ static void SCULPT_OT_symmetrize(wmOperatorType *ot)
/**** Toggle operator for turning sculpt mode on or off ****/
-static void sculpt_init_session(Scene *scene, Object *ob)
+static void sculpt_init_session(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
/* Create persistent sculpt mode data */
BKE_sculpt_toolsettings_data_ensure(scene);
ob->sculpt = MEM_callocN(sizeof(SculptSession), "sculpt session");
- BKE_sculpt_update_mesh_elements(scene, scene->toolsettings->sculpt, ob, 0, false);
+ ob->sculpt->mode_type = OB_MODE_SCULPT;
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, scene->toolsettings->sculpt, ob, 0, false);
}
static int ed_object_sculptmode_flush_recalc_flag(Scene *scene, Object *ob, MultiresModifierData *mmd)
@@ -5628,6 +5639,7 @@ static int ed_object_sculptmode_flush_recalc_flag(Scene *scene, Object *ob, Mult
}
void ED_object_sculptmode_enter_ex(
+ Depsgraph *depsgraph,
Scene *scene, Object *ob,
ReportList *reports)
{
@@ -5637,21 +5649,19 @@ void ED_object_sculptmode_enter_ex(
/* Enter sculptmode */
ob->mode |= mode_flag;
-
MultiresModifierData *mmd = BKE_sculpt_multires_active(scene, ob);
const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd);
- if (flush_recalc) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- }
+ if (flush_recalc)
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* Create sculpt mode session data */
if (ob->sculpt) {
BKE_sculptsession_free(ob);
}
- sculpt_init_session(scene, ob);
+ sculpt_init_session(depsgraph, scene, ob);
/* Mask layer is required */
if (mmd) {
@@ -5709,7 +5719,7 @@ void ED_object_sculptmode_enter_ex(
if (message_unsupported == NULL) {
/* undo push is needed to prevent memory leak */
sculpt_undo_push_begin("Dynamic topology enable");
- sculpt_dynamic_topology_enable_ex(scene, ob);
+ sculpt_dynamic_topology_enable_ex(depsgraph, scene, ob);
sculpt_undo_push_node(ob, NULL, SCULPT_UNDO_DYNTOPO_BEGIN);
}
else {
@@ -5720,20 +5730,19 @@ void ED_object_sculptmode_enter_ex(
}
}
- /* VBO no longer valid */
- if (ob->derivedFinal) {
- GPU_drawobject_free(ob->derivedFinal);
- }
+ // ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, ob);
}
void ED_object_sculptmode_enter(struct bContext *C, ReportList *reports)
{
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- ED_object_sculptmode_enter_ex(scene, ob, reports);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ED_object_sculptmode_enter_ex(depsgraph, scene, ob, reports);
}
void ED_object_sculptmode_exit_ex(
+ Depsgraph *depsgraph,
Scene *scene, Object *ob)
{
const int mode_flag = OB_MODE_SCULPT;
@@ -5743,7 +5752,7 @@ void ED_object_sculptmode_exit_ex(
if (mmd) {
multires_force_update(ob);
}
-
+
/* Not needed for now. */
#if 0
const int flush_recalc = ed_object_sculptmode_flush_recalc_flag(scene, ob, mmd);
@@ -5753,14 +5762,14 @@ void ED_object_sculptmode_exit_ex(
* a consistent state.
*/
if (true || /* flush_recalc || */ (ob->sculpt && ob->sculpt->bm)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
if (me->flag & ME_SCULPT_DYNAMIC_TOPOLOGY) {
/* Dynamic topology must be disabled before exiting sculpt
* mode to ensure the undo stack stays in a consistent
* state */
- sculpt_dynamic_topology_disable_with_undo(scene, ob);
+ sculpt_dynamic_topology_disable_with_undo(depsgraph, scene, ob);
/* store so we know to re-enable when entering sculpt mode */
me->flag |= ME_SCULPT_DYNAMIC_TOPOLOGY;
@@ -5769,25 +5778,24 @@ void ED_object_sculptmode_exit_ex(
/* Leave sculptmode */
ob->mode &= ~mode_flag;
+ // ED_workspace_object_mode_sync_from_object(G.main->wm.first, workspace, ob);
+
BKE_sculptsession_free(ob);
paint_cursor_delete_textures();
-
- /* VBO no longer valid */
- if (ob->derivedFinal) {
- GPU_drawobject_free(ob->derivedFinal);
- }
}
void ED_object_sculptmode_exit(bContext *C)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
- ED_object_sculptmode_exit_ex(scene, ob);
+ ED_object_sculptmode_exit_ex(depsgraph, scene, ob);
}
static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph_on_load(C);
Scene *scene = CTX_data_scene(C);
Object *ob = CTX_data_active_object(C);
const int mode_flag = OB_MODE_SCULPT;
@@ -5800,10 +5808,10 @@ static int sculpt_mode_toggle_exec(bContext *C, wmOperator *op)
}
if (is_mode_set) {
- ED_object_sculptmode_exit_ex(scene, ob);
+ ED_object_sculptmode_exit_ex(depsgraph, scene, ob);
}
else {
- ED_object_sculptmode_enter_ex(scene, ob, op->reports);
+ ED_object_sculptmode_enter_ex(depsgraph, scene, ob, op->reports);
}
WM_event_add_notifier(C, NC_SCENE | ND_MODE, scene);
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index e46760258e1..bca33ad8014 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -61,12 +61,15 @@ bool sculpt_stroke_get_location(struct bContext *C, float out[3], const float mo
void sculpt_pbvh_clear(Object *ob);
void sculpt_dyntopo_node_layers_add(struct SculptSession *ss);
void sculpt_update_after_dynamic_topology_toggle(
+ struct Depsgraph *depsgraph,
struct Scene *scene, struct Object *ob);
void sculpt_dynamic_topology_enable_ex(
+ struct Depsgraph *depsgraph,
struct Scene *scene, struct Object *ob);
void sculpt_dynamic_topology_enable(bContext *C);
void sculpt_dynamic_topology_disable_ex(
+ struct Depsgraph *depsgraph,
struct Scene *scene, struct Object *ob,
struct SculptUndoNode *unode);
void sculpt_dynamic_topology_disable(bContext *C, struct SculptUndoNode *unode);
diff --git a/source/blender/editors/sculpt_paint/sculpt_undo.c b/source/blender/editors/sculpt_paint/sculpt_undo.c
index e90d2b58c0c..b819fe8e97d 100644
--- a/source/blender/editors/sculpt_paint/sculpt_undo.c
+++ b/source/blender/editors/sculpt_paint/sculpt_undo.c
@@ -50,10 +50,10 @@
#include "DNA_mesh_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
+#include "DNA_workspace_types.h"
#include "BKE_ccg.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_multires.h"
#include "BKE_paint.h"
#include "BKE_key.h"
@@ -61,11 +61,11 @@
#include "BKE_subsurf.h"
#include "BKE_undo_system.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
-#include "GPU_buffers.h"
-
#include "ED_paint.h"
#include "ED_object.h"
#include "ED_sculpt.h"
@@ -140,6 +140,7 @@ static bool sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoN
Scene *scene = CTX_data_scene(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Object *ob = CTX_data_active_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
SculptSession *ss = ob->sculpt;
MVert *mvert;
int *index;
@@ -156,7 +157,7 @@ static bool sculpt_undo_restore_coords(bContext *C, DerivedMesh *dm, SculptUndoN
if (kb) {
ob->shapenr = BLI_findindex(&key->block, kb) + 1;
- BKE_sculpt_update_mesh_elements(scene, sd, ob, 0, false);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, 0, false);
WM_event_add_notifier(C, NC_OBJECT | ND_DATA, ob);
}
else {
@@ -378,8 +379,8 @@ static void sculpt_undo_bmesh_restore_generic(bContext *C,
}
/* Create empty sculpt BMesh and enable logging */
-static void sculpt_undo_bmesh_enable(Object *ob,
- SculptUndoNode *unode)
+static void sculpt_undo_bmesh_enable(
+ Object *ob, SculptUndoNode *unode)
{
SculptSession *ss = ob->sculpt;
Mesh *me = ob->data;
@@ -472,6 +473,7 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb)
Scene *scene = CTX_data_scene(C);
Sculpt *sd = CTX_data_tool_settings(C)->sculpt;
Object *ob = CTX_data_active_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
DerivedMesh *dm;
SculptSession *ss = ob->sculpt;
SculptUndoNode *unode;
@@ -490,10 +492,10 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb)
}
}
- BKE_sculpt_update_mesh_elements(scene, sd, ob, 0, need_mask);
+ BKE_sculpt_update_mesh_elements(depsgraph, scene, sd, ob, 0, need_mask);
/* call _after_ sculpt_update_mesh_elements() which may update 'ob->derivedFinal' */
- dm = mesh_get_derived_final(scene, ob, 0);
+ dm = mesh_get_derived_final(depsgraph, scene, ob, 0);
if (lb->first && sculpt_undo_bmesh_restore(C, lb->first, ob, ss))
return;
@@ -576,14 +578,11 @@ static void sculpt_undo_restore_list(bContext *C, ListBase *lb)
}
if (tag_update) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
else {
sculpt_update_object_bounding_box(ob);
}
-
- /* for non-PBVH drawing, need to recreate VBOs */
- GPU_drawobject_free(ob->derivedFinal);
}
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_uv.c b/source/blender/editors/sculpt_paint/sculpt_uv.c
index e39750227c0..6928610f280 100644
--- a/source/blender/editors/sculpt_paint/sculpt_uv.c
+++ b/source/blender/editors/sculpt_paint/sculpt_uv.c
@@ -46,15 +46,19 @@
#include "BKE_paint.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh_mapping.h"
#include "BKE_customdata.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+
#include "ED_screen.h"
#include "ED_image.h"
#include "ED_mesh.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -64,9 +68,6 @@
#include "paint_intern.h"
#include "uvedit_intern.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
#include "UI_view2d.h"
#define MARK_BOUNDARY 1
@@ -212,18 +213,17 @@ static void brush_drawcursor_uvsculpt(bContext *C, int x, int y, void *UNUSED(cu
alpha *= (size - PX_SIZE_FADE_MIN) / (PX_SIZE_FADE_MAX - PX_SIZE_FADE_MIN);
}
- glPushMatrix();
-
- glTranslatef((float)x, (float)y, 0.0f);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fvAlpha(brush->add_col, alpha);
- glColor4f(brush->add_col[0], brush->add_col[1], brush->add_col[2], alpha);
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
- glutil_draw_lined_arc(0, (float)(M_PI * 2.0), size, 40);
+ imm_draw_circle_wire_2d(pos, (float)x, (float)y, size, 40);
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
- glPopMatrix();
+ immUnbindProgram();
}
#undef PX_SIZE_FADE_MAX
#undef PX_SIZE_FADE_MIN
@@ -652,7 +652,7 @@ static UvSculptData *uv_sculpt_stroke_init(bContext *C, wmOperator *op, const wm
UvElement *element;
UvNearestHit hit = UV_NEAREST_HIT_INIT;
Image *ima = CTX_data_edit_image(C);
- uv_find_nearest_vert(scene, ima, em, co, 0.0f, &hit);
+ uv_find_nearest_vert(scene, ima, obedit, co, 0.0f, &hit);
element = BM_uv_element_get(data->elementMap, hit.efa, hit.l);
island_index = element->island;
@@ -899,7 +899,7 @@ static int uv_sculpt_stroke_modal(bContext *C, wmOperator *op, const wmEvent *ev
ED_region_tag_redraw(CTX_wm_region(C));
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
return OPERATOR_RUNNING_MODAL;
}
diff --git a/source/blender/editors/sound/CMakeLists.txt b/source/blender/editors/sound/CMakeLists.txt
index 535cd579030..9efdf11e8d7 100644
--- a/source/blender/editors/sound/CMakeLists.txt
+++ b/source/blender/editors/sound/CMakeLists.txt
@@ -39,7 +39,7 @@ set(SRC
)
if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
+ add_definitions(-DWITH_AUDASPACE)
list(APPEND INC_SYS
${AUDASPACE_C_INCLUDE_DIRS}
diff --git a/source/blender/editors/sound/sound_ops.c b/source/blender/editors/sound/sound_ops.c
index 0c349e6433e..eaf101b1083 100644
--- a/source/blender/editors/sound/sound_ops.c
+++ b/source/blender/editors/sound/sound_ops.c
@@ -67,7 +67,7 @@
#include "WM_types.h"
#ifdef WITH_AUDASPACE
-# include AUD_SPECIAL_H
+# include <AUD_Special.h>
#endif
#include "ED_sound.h"
@@ -311,6 +311,7 @@ static int sound_bake_animation_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
int oldfra = scene->r.cfra;
int cfra;
@@ -318,11 +319,11 @@ static int sound_bake_animation_exec(bContext *C, wmOperator *UNUSED(op))
for (cfra = (scene->r.sfra > 0) ? (scene->r.sfra - 1) : 0; cfra <= scene->r.efra + 1; cfra++) {
scene->r.cfra = cfra;
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
}
scene->r.cfra = oldfra;
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
return OPERATOR_FINISHED;
}
@@ -634,7 +635,7 @@ static void sound_mixdown_draw(bContext *C, wmOperator *op)
RNA_pointer_create(&wm->id, op->type->srna, op->properties, &ptr);
/* main draw call */
- uiDefAutoButsRNA(layout, &ptr, sound_mixdown_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, sound_mixdown_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
}
#endif // WITH_AUDASPACE
diff --git a/source/blender/editors/space_action/action_buttons.c b/source/blender/editors/space_action/action_buttons.c
index ba6cef38acd..3ba59b3be75 100644
--- a/source/blender/editors/space_action/action_buttons.c
+++ b/source/blender/editors/space_action/action_buttons.c
@@ -48,7 +48,6 @@
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_screen.h"
#include "BKE_unit.h"
diff --git a/source/blender/editors/space_action/action_draw.c b/source/blender/editors/space_action/action_draw.c
index 0764f586de9..3e9b742480a 100644
--- a/source/blender/editors/space_action/action_draw.c
+++ b/source/blender/editors/space_action/action_draw.c
@@ -43,16 +43,23 @@
/* Types --------------------------------------------------------------- */
#include "DNA_anim_types.h"
+#include "DNA_cachefile_types.h"
+#include "DNA_object_types.h"
#include "DNA_screen_types.h"
+#include "DNA_scene_types.h"
#include "BKE_action.h"
#include "BKE_context.h"
+#include "BKE_pointcache.h"
/* Everything from source (BIF, BDR, BSE) ------------------------------ */
#include "BIF_gl.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -156,15 +163,12 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
{
ListBase anim_data = {NULL, NULL};
bAnimListElem *ale;
- int filter;
View2D *v2d = &ar->v2d;
bDopeSheet *ads = &saction->ads;
AnimData *adt = NULL;
float act_start, act_end, y;
- size_t items;
- int height;
unsigned char col1[3], col2[3];
unsigned char col1a[3], col2a[3];
@@ -194,10 +198,10 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
}
/* build list of channels to draw */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
- items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+ int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
+ size_t items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
- height = ((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac)));
+ int height = ((items * ACHANNEL_STEP(ac)) + (ACHANNEL_HEIGHT(ac)));
/* don't use totrect set, as the width stays the same
* (NOTE: this is ok here, the configuration is pretty straightforward)
*/
@@ -205,6 +209,12 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
/* first backdrop strips */
y = (float)(-ACHANNEL_HEIGHT(ac));
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
glEnable(GL_BLEND);
for (ale = anim_data.first; ale; ale = ale->next) {
@@ -223,28 +233,26 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
/* determine if channel is selected */
if (acf->has_setting(ac, ale, ACHANNEL_SETTING_SELECT))
sel = ANIM_channel_setting_get(ac, ale, ACHANNEL_SETTING_SELECT);
-
+
if (ELEM(ac->datatype, ANIMCONT_ACTION, ANIMCONT_DOPESHEET, ANIMCONT_SHAPEKEY)) {
switch (ale->type) {
case ANIMTYPE_SUMMARY:
{
/* reddish color from NLA */
- UI_ThemeColor4(TH_ANIM_ACTIVE);
+ immUniformThemeColor(TH_ANIM_ACTIVE);
break;
}
case ANIMTYPE_SCENE:
case ANIMTYPE_OBJECT:
{
- if (sel) glColor4ub(col1b[0], col1b[1], col1b[2], 0x45);
- else glColor4ub(col1b[0], col1b[1], col1b[2], 0x22);
+ immUniformColor3ubvAlpha(col1b, sel ? 0x45 : 0x22);
break;
}
case ANIMTYPE_FILLACTD:
case ANIMTYPE_DSSKEY:
case ANIMTYPE_DSWOR:
{
- if (sel) glColor4ub(col2b[0], col2b[1], col2b[2], 0x45);
- else glColor4ub(col2b[0], col2b[1], col2b[2], 0x22);
+ immUniformColor3ubvAlpha(col2b, sel ? 0x45 : 0x22);
break;
}
case ANIMTYPE_GROUP:
@@ -252,17 +260,14 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
bActionGroup *agrp = ale->data;
if (show_group_colors && agrp->customCol) {
if (sel) {
- unsigned char *cp = (unsigned char *)agrp->cs.select;
- glColor4ub(cp[0], cp[1], cp[2], 0x45);
+ immUniformColor3ubvAlpha((unsigned char *)agrp->cs.select, 0x45);
}
else {
- unsigned char *cp = (unsigned char *)agrp->cs.solid;
- glColor4ub(cp[0], cp[1], cp[2], 0x1D);
+ immUniformColor3ubvAlpha((unsigned char *)agrp->cs.solid, 0x1D);
}
}
else {
- if (sel) glColor4ub(col1a[0], col1a[1], col1a[2], 0x22);
- else glColor4ub(col2a[0], col2a[1], col2a[2], 0x22);
+ immUniformColor3ubvAlpha(sel ? col1a : col2a, 0x22);
}
break;
}
@@ -270,53 +275,43 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
{
FCurve *fcu = ale->data;
if (show_group_colors && fcu->grp && fcu->grp->customCol) {
- unsigned char *cp = (unsigned char *)fcu->grp->cs.active;
-
- if (sel) glColor4ub(cp[0], cp[1], cp[2], 0x65);
- else glColor4ub(cp[0], cp[1], cp[2], 0x0B);
+ immUniformColor3ubvAlpha((unsigned char *)fcu->grp->cs.active, sel ? 0x65 : 0x0B);
}
else {
- if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
- else glColor4ub(col2[0], col2[1], col2[2], 0x22);
+ immUniformColor3ubvAlpha(sel ? col1 : col2, 0x22);
}
break;
}
default:
{
- if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
- else glColor4ub(col2[0], col2[1], col2[2], 0x22);
- break;
+ immUniformColor3ubvAlpha(sel ? col1 : col2, 0x22);
}
}
/* draw region twice: firstly backdrop, then the current range */
- glRectf(v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
+ immRectf(pos, v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
if (ac->datatype == ANIMCONT_ACTION)
- glRectf(act_start, (float)y - ACHANNEL_HEIGHT_HALF(ac), act_end, (float)y + ACHANNEL_HEIGHT_HALF(ac));
+ immRectf(pos, act_start, (float)y - ACHANNEL_HEIGHT_HALF(ac), act_end, (float)y + ACHANNEL_HEIGHT_HALF(ac));
}
else if (ac->datatype == ANIMCONT_GPENCIL) {
/* frames less than one get less saturated background */
- if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
- else glColor4ub(col2[0], col2[1], col2[2], 0x22);
- glRectf(0.0f, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmin, (float)y + ACHANNEL_HEIGHT_HALF(ac));
+ immUniformColor3ubvAlpha(sel ? col1 : col2, 0x22);
+ immRectf(pos, 0.0f, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmin, (float)y + ACHANNEL_HEIGHT_HALF(ac));
/* frames one and higher get a saturated background */
- if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x44);
- else glColor4ub(col2[0], col2[1], col2[2], 0x44);
- glRectf(v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
+ immUniformColor3ubvAlpha(sel ? col1 : col2, 0x44);
+ immRectf(pos, v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
}
else if (ac->datatype == ANIMCONT_MASK) {
/* TODO --- this is a copy of gpencil */
/* frames less than one get less saturated background */
- if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x22);
- else glColor4ub(col2[0], col2[1], col2[2], 0x22);
- glRectf(0.0f, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmin, (float)y + ACHANNEL_HEIGHT_HALF(ac));
+ immUniformColor3ubvAlpha(sel ? col1 : col2, 0x22);
+ immRectf(pos, 0.0f, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmin, (float)y + ACHANNEL_HEIGHT_HALF(ac));
/* frames one and higher get a saturated background */
- if (sel) glColor4ub(col1[0], col1[1], col1[2], 0x44);
- else glColor4ub(col2[0], col2[1], col2[2], 0x44);
- glRectf(v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
+ immUniformColor3ubvAlpha(sel ? col1 : col2, 0x44);
+ immRectf(pos, v2d->cur.xmin, (float)y - ACHANNEL_HEIGHT_HALF(ac), v2d->cur.xmax + EXTRA_SCROLL_PAD, (float)y + ACHANNEL_HEIGHT_HALF(ac));
}
}
}
@@ -325,18 +320,29 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
y -= ACHANNEL_STEP(ac);
}
glDisable(GL_BLEND);
-
- /* Draw keyframes
+
+ /* black line marking 'current frame' for Time-Slide transform mode */
+ if (saction->flag & SACTION_MOVING) {
+ immUniformColor3f(0.0f, 0.0f, 0.0f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, saction->timeslide, v2d->cur.ymin - EXTRA_SCROLL_PAD);
+ immVertex2f(pos, saction->timeslide, v2d->cur.ymax);
+ immEnd();
+ }
+ immUnbindProgram();
+
+ /* Draw keyframes
* 1) Only channels that are visible in the Action Editor get drawn/evaluated.
* This is to try to optimize this for heavier data sets
* 2) Keyframes which are out of view horizontally are disregarded
*/
y = (float)(-ACHANNEL_HEIGHT(ac));
-
+
for (ale = anim_data.first; ale; ale = ale->next) {
const float yminc = (float)(y - ACHANNEL_HEIGHT_HALF(ac));
const float ymaxc = (float)(y + ACHANNEL_HEIGHT_HALF(ac));
-
+
/* check if visible */
if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax) )
@@ -344,7 +350,7 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
/* check if anything to show for this channel */
if (ale->datatype != ALE_NONE) {
adt = ANIM_nla_mapping_get(ac, ale);
-
+
/* draw 'keyframes' for each specific datatype */
switch (ale->datatype) {
case ALE_ALL:
@@ -374,20 +380,145 @@ void draw_channel_strips(bAnimContext *ac, SpaceAction *saction, ARegion *ar)
}
}
}
-
+
y -= ACHANNEL_STEP(ac);
}
-
- /* free tempolary channels used for drawing */
+
+ /* free temporary channels used for drawing */
ANIM_animdata_freelist(&anim_data);
+}
- /* black line marking 'current frame' for Time-Slide transform mode */
- if (saction->flag & SACTION_MOVING) {
- glColor3f(0.0f, 0.0f, 0.0f);
+/* ************************************************************************* */
+/* Timeline - Caches */
+
+void timeline_draw_cache(SpaceAction *saction, Object *ob, Scene *scene)
+{
+ PTCacheID *pid;
+ ListBase pidlist;
+ const float cache_draw_height = (4.0f * UI_DPI_FAC * U.pixelsize);
+ float yoffs = 0.f;
+
+ if (!(saction->cache_display & TIME_CACHE_DISPLAY) || (!ob))
+ return;
+
+ BKE_ptcache_ids_from_object(&pidlist, ob, scene, 0);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* iterate over pointcaches on the active object, and draw each one's range */
+ for (pid = pidlist.first; pid; pid = pid->next) {
+ float col[4];
+
+ switch (pid->type) {
+ case PTCACHE_TYPE_SOFTBODY:
+ if (!(saction->cache_display & TIME_CACHE_SOFTBODY)) continue;
+ break;
+ case PTCACHE_TYPE_PARTICLES:
+ if (!(saction->cache_display & TIME_CACHE_PARTICLES)) continue;
+ break;
+ case PTCACHE_TYPE_CLOTH:
+ if (!(saction->cache_display & TIME_CACHE_CLOTH)) continue;
+ break;
+ case PTCACHE_TYPE_SMOKE_DOMAIN:
+ case PTCACHE_TYPE_SMOKE_HIGHRES:
+ if (!(saction->cache_display & TIME_CACHE_SMOKE)) continue;
+ break;
+ case PTCACHE_TYPE_DYNAMICPAINT:
+ if (!(saction->cache_display & TIME_CACHE_DYNAMICPAINT)) continue;
+ break;
+ case PTCACHE_TYPE_RIGIDBODY:
+ if (!(saction->cache_display & TIME_CACHE_RIGIDBODY)) continue;
+ break;
+ }
+
+ if (pid->cache->cached_frames == NULL)
+ continue;
+
+ gpuPushMatrix();
+ gpuTranslate2f(0.0, (float)V2D_SCROLL_HEIGHT + yoffs);
+ gpuScale2f(1.0, cache_draw_height);
- glBegin(GL_LINES);
- glVertex2f(saction->timeslide, v2d->cur.ymin - EXTRA_SCROLL_PAD);
- glVertex2f(saction->timeslide, v2d->cur.ymax);
- glEnd();
+ switch (pid->type) {
+ case PTCACHE_TYPE_SOFTBODY:
+ col[0] = 1.0; col[1] = 0.4; col[2] = 0.02;
+ col[3] = 0.1;
+ break;
+ case PTCACHE_TYPE_PARTICLES:
+ col[0] = 1.0; col[1] = 0.1; col[2] = 0.02;
+ col[3] = 0.1;
+ break;
+ case PTCACHE_TYPE_CLOTH:
+ col[0] = 0.1; col[1] = 0.1; col[2] = 0.75;
+ col[3] = 0.1;
+ break;
+ case PTCACHE_TYPE_SMOKE_DOMAIN:
+ case PTCACHE_TYPE_SMOKE_HIGHRES:
+ col[0] = 0.2; col[1] = 0.2; col[2] = 0.2;
+ col[3] = 0.1;
+ break;
+ case PTCACHE_TYPE_DYNAMICPAINT:
+ col[0] = 1.0; col[1] = 0.1; col[2] = 0.75;
+ col[3] = 0.1;
+ break;
+ case PTCACHE_TYPE_RIGIDBODY:
+ col[0] = 1.0; col[1] = 0.6; col[2] = 0.0;
+ col[3] = 0.1;
+ break;
+ default:
+ col[0] = 1.0; col[1] = 0.0; col[2] = 1.0;
+ col[3] = 0.1;
+ BLI_assert(0);
+ break;
+ }
+
+ const int sta = pid->cache->startframe, end = pid->cache->endframe;
+ const int len = (end - sta + 1) * 6;
+
+ glEnable(GL_BLEND);
+
+ immUniformColor4fv(col);
+ immRectf(pos, (float)sta, 0.0, (float)end, 1.0);
+
+ col[3] = 0.4f;
+ if (pid->cache->flag & PTCACHE_BAKED) {
+ col[0] -= 0.4f; col[1] -= 0.4f; col[2] -= 0.4f;
+ }
+ else if (pid->cache->flag & PTCACHE_OUTDATED) {
+ col[0] += 0.4f; col[1] += 0.4f; col[2] += 0.4f;
+ }
+
+ immUniformColor4fv(col);
+
+ if (len > 0) {
+ immBeginAtMost(GWN_PRIM_TRIS, len);
+
+ /* draw a quad for each cached frame */
+ for (int i = sta; i <= end; i++) {
+ if (pid->cache->cached_frames[i - sta]) {
+ immVertex2f(pos, (float)i - 0.5f, 0.0f);
+ immVertex2f(pos, (float)i - 0.5f, 1.0f);
+ immVertex2f(pos, (float)i + 0.5f, 1.0f);
+
+ immVertex2f(pos, (float)i - 0.5f, 0.0f);
+ immVertex2f(pos, (float)i + 0.5f, 1.0f);
+ immVertex2f(pos, (float)i + 0.5f, 0.0f);
+ }
+ }
+
+ immEnd();
+ }
+
+ glDisable(GL_BLEND);
+
+ gpuPopMatrix();
+
+ yoffs += cache_draw_height;
}
+
+ immUnbindProgram();
+
+ BLI_freelistN(&pidlist);
}
+
+/* ************************************************************************* */
diff --git a/source/blender/editors/space_action/action_intern.h b/source/blender/editors/space_action/action_intern.h
index 408eb38d386..6ec6f0561c2 100644
--- a/source/blender/editors/space_action/action_intern.h
+++ b/source/blender/editors/space_action/action_intern.h
@@ -33,10 +33,13 @@
struct bContext;
struct bAnimContext;
+struct Scene;
+struct Object;
struct SpaceAction;
struct ScrArea;
struct ARegion;
struct ARegionType;
+struct View2D;
struct wmOperatorType;
/* internal exports only */
@@ -54,6 +57,8 @@ void ACTION_OT_properties(struct wmOperatorType *ot);
void draw_channel_names(struct bContext *C, struct bAnimContext *ac, struct ARegion *ar);
void draw_channel_strips(struct bAnimContext *ac, struct SpaceAction *saction, struct ARegion *ar);
+void timeline_draw_cache(struct SpaceAction *saction, struct Object *ob, struct Scene *scene);
+
/* ***************************************** */
/* action_select.c */
diff --git a/source/blender/editors/space_action/space_action.c b/source/blender/editors/space_action/space_action.c
index 5cde224b7dc..5353c250d1e 100644
--- a/source/blender/editors/space_action/space_action.c
+++ b/source/blender/editors/space_action/space_action.c
@@ -34,6 +34,7 @@
#include "DNA_action_types.h"
#include "DNA_group_types.h"
+#include "DNA_object_types.h"
#include "DNA_scene_types.h"
#include "MEM_guardedalloc.h"
@@ -45,10 +46,13 @@
#include "BKE_context.h"
#include "BKE_screen.h"
-#include "BIF_gl.h"
+#include "RNA_access.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
+
+#include "BIF_gl.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -88,10 +92,8 @@ ARegion *action_has_buttons_region(ScrArea *sa)
/* ******************** default callbacks for action space ***************** */
-static SpaceLink *action_new(const bContext *C)
+static SpaceLink *action_new(const ScrArea *sa, const Scene *scene)
{
- Scene *scene = CTX_data_scene(C);
- ScrArea *sa = CTX_wm_area(C);
SpaceAction *saction;
ARegion *ar;
@@ -103,6 +105,12 @@ static SpaceLink *action_new(const bContext *C)
saction->ads.filterflag |= ADS_FILTER_SUMMARY;
+ /* enable all cache display */
+ saction->cache_display |= TIME_CACHE_DISPLAY;
+ saction->cache_display |= (TIME_CACHE_SOFTBODY | TIME_CACHE_PARTICLES);
+ saction->cache_display |= (TIME_CACHE_CLOTH | TIME_CACHE_SMOKE | TIME_CACHE_DYNAMICPAINT);
+ saction->cache_display |= TIME_CACHE_RIGIDBODY;
+
/* header */
ar = MEM_callocN(sizeof(ARegion), "header for action");
@@ -170,6 +178,7 @@ static void action_free(SpaceLink *UNUSED(sl))
static void action_init(struct wmWindowManager *UNUSED(wm), ScrArea *sa)
{
SpaceAction *saction = sa->spacedata.first;
+
saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
}
@@ -202,11 +211,15 @@ static void action_main_region_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
SpaceAction *saction = CTX_wm_space_action(C);
+ Scene *scene = CTX_data_scene(C);
+ Object *obact = CTX_data_active_object(C);
bAnimContext ac;
View2D *v2d = &ar->v2d;
View2DGrid *grid;
View2DScrollers *scrollers;
- short unit = 0, flag = 0;
+ short marker_flag = 0;
+ short cfra_flag = 0;
+ short unit = 0;
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
@@ -221,22 +234,29 @@ static void action_main_region_draw(const bContext *C, ARegion *ar)
UI_view2d_grid_free(grid);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
-
+
+ /* start and end frame */
+ ANIM_draw_framerange(scene, v2d);
+
/* data */
if (ANIM_animdata_get_context(C, &ac)) {
draw_channel_strips(&ac, saction, ar);
}
/* current frame */
- if (saction->flag & SACTION_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
- if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
- ANIM_draw_cfra(C, v2d, flag);
+ if (saction->flag & SACTION_DRAWTIME) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
+ ANIM_draw_cfra(C, v2d, cfra_flag);
/* markers */
UI_view2d_view_orthoSpecial(ar, v2d, 1);
- flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN;
- ED_markers_draw(C, flag);
+ marker_flag = ((ac.markers && (ac.markers != &ac.scene->markers)) ? DRAW_MARKERS_LOCAL : 0) | DRAW_MARKERS_MARGIN;
+ ED_markers_draw(C, marker_flag);
+
+ /* caches */
+ if (saction->mode == SACTCONT_TIMELINE) {
+ timeline_draw_cache(saction, obact, scene);
+ }
/* preview range */
UI_view2d_view_ortho(v2d);
@@ -253,6 +273,12 @@ static void action_main_region_draw(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
+
+ /* draw current frame number-indicator on top of scrollers */
+ if ((saction->flag & SACTION_NODRAWCFRANUM) == 0) {
+ UI_view2d_view_orthoSpecial(ar, v2d, 1);
+ ANIM_draw_cfra_number(C, v2d, cfra_flag);
+ }
}
/* add handlers, stuff you only do once or on area/region changes */
@@ -308,7 +334,9 @@ static void action_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void action_channel_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void action_channel_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -351,7 +379,9 @@ static void action_channel_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(
}
}
-static void action_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void action_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -363,6 +393,7 @@ static void action_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa)
case ND_RENDER_OPTIONS:
case ND_OB_ACTIVE:
case ND_FRAME:
+ case ND_FRAME_RANGE:
case ND_MARKERS:
ED_region_tag_redraw(ar);
break;
@@ -391,7 +422,11 @@ static void action_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa)
if (wmn->action == NA_RENAME)
ED_region_tag_redraw(ar);
break;
-
+ case NC_SCREEN:
+ if (ELEM(wmn->data, ND_LAYER)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
default:
if (wmn->data == ND_KEYS)
ED_region_tag_redraw(ar);
@@ -399,8 +434,50 @@ static void action_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa)
}
}
+static void saction_main_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *scene,
+ struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ PointerRNA ptr;
+ RNA_pointer_create(&screen->id, &RNA_SpaceDopeSheetEditor, sa->spacedata.first, &ptr);
+
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ /* Timeline depends on scene properties. */
+ {
+ bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
+ extern PropertyRNA rna_Scene_frame_start;
+ extern PropertyRNA rna_Scene_frame_end;
+ extern PropertyRNA rna_Scene_frame_preview_start;
+ extern PropertyRNA rna_Scene_frame_preview_end;
+ extern PropertyRNA rna_Scene_use_preview_range;
+ extern PropertyRNA rna_Scene_frame_current;
+ const PropertyRNA *props[] = {
+ use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
+ use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
+ &rna_Scene_use_preview_range,
+ &rna_Scene_frame_current,
+ };
+
+ PointerRNA idptr;
+ RNA_id_pointer_create(&scene->id, &idptr);
+
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ WM_msg_subscribe_rna(mbus, &idptr, props[i], &msg_sub_value_region_tag_redraw, __func__);
+ }
+ }
+}
+
/* editor level listener */
-static void action_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void action_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
@@ -440,16 +517,43 @@ static void action_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
}
break;
case NC_SCENE:
- switch (wmn->data) {
- case ND_OB_ACTIVE: /* selection changed, so force refresh to flush (needs flag set to do syncing) */
- case ND_OB_SELECT:
- saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
- ED_area_tag_refresh(sa);
- break;
-
- default: /* just redrawing the view will do */
- ED_area_tag_redraw(sa);
- break;
+ if (saction->mode == SACTCONT_TIMELINE) {
+ switch (wmn->data) {
+ case ND_RENDER_RESULT:
+ ED_area_tag_redraw(sa);
+ break;
+ case ND_OB_ACTIVE:
+ case ND_FRAME:
+ ED_area_tag_refresh(sa);
+ break;
+ case ND_FRAME_RANGE:
+ {
+ ARegion *ar;
+ Scene *scene = wmn->reference;
+
+ for (ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ ar->v2d.tot.xmin = (float)(SFRA - 4);
+ ar->v2d.tot.xmax = (float)(EFRA + 4);
+ break;
+ }
+ }
+ break;
+ }
+ }
+ }
+ else {
+ switch (wmn->data) {
+ case ND_OB_ACTIVE: /* selection changed, so force refresh to flush (needs flag set to do syncing) */
+ case ND_OB_SELECT:
+ saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
+ ED_area_tag_refresh(sa);
+ break;
+
+ default: /* just redrawing the view will do */
+ ED_area_tag_redraw(sa);
+ break;
+ }
}
break;
case NC_OBJECT:
@@ -462,6 +566,15 @@ static void action_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
case ND_TRANSFORM:
/* moving object shouldn't need to redraw action */
break;
+ case ND_POINTCACHE:
+ case ND_MODIFIER:
+ case ND_PARTICLE:
+ /* only needed in timeline mode */
+ if (saction->mode == SACTCONT_TIMELINE) {
+ ED_area_tag_refresh(sa);
+ ED_area_tag_redraw(sa);
+ }
+ break;
default: /* just redrawing the view will do */
ED_area_tag_redraw(sa);
break;
@@ -492,6 +605,9 @@ static void action_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
case ND_SPACE_DOPESHEET:
ED_area_tag_redraw(sa);
break;
+ case ND_SPACE_TIME:
+ ED_area_tag_redraw(sa);
+ break;
case ND_SPACE_CHANGED:
saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
ED_area_tag_refresh(sa);
@@ -504,20 +620,49 @@ static void action_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
ED_area_tag_refresh(sa);
}
break;
+ case NC_WM:
+ switch (wmn->data) {
+ case ND_FILEREAD:
+ ED_area_tag_refresh(sa);
+ break;
+ }
+ break;
}
}
-static void action_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void action_header_region_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
- // SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
+ SpaceAction *saction = (SpaceAction *)sa->spacedata.first;
/* context changes */
switch (wmn->category) {
- case NC_SCENE:
- switch (wmn->data) {
- case ND_OB_ACTIVE:
+ case NC_SCREEN:
+ if (saction->mode == SACTCONT_TIMELINE) {
+ if (wmn->data == ND_ANIMPLAY)
ED_region_tag_redraw(ar);
- break;
+ }
+ break;
+ case NC_SCENE:
+ if (saction->mode == SACTCONT_TIMELINE) {
+ switch (wmn->data) {
+ case ND_RENDER_RESULT:
+ case ND_OB_SELECT:
+ case ND_FRAME:
+ case ND_FRAME_RANGE:
+ case ND_KEYINGSET:
+ case ND_RENDER_OPTIONS:
+ ED_region_tag_redraw(ar);
+ break;
+ }
+ }
+ else {
+ switch (wmn->data) {
+ case ND_OB_ACTIVE:
+ ED_region_tag_redraw(ar);
+ break;
+ }
}
break;
case NC_ID:
@@ -559,7 +704,9 @@ static void action_buttons_area_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void action_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void action_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -662,6 +809,7 @@ void ED_spacetype_action(void)
art->init = action_main_region_init;
art->draw = action_main_region_draw;
art->listener = action_main_region_listener;
+ art->message_subscribe = saction_main_region_message_subscribe;
art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
BLI_addhead(&st->regiontypes, art);
diff --git a/source/blender/editors/space_api/spacetypes.c b/source/blender/editors/space_api/spacetypes.c
index 9247cdb1ae7..12f16f1fe42 100644
--- a/source/blender/editors/space_api/spacetypes.c
+++ b/source/blender/editors/space_api/spacetypes.c
@@ -55,6 +55,7 @@
#include "ED_paint.h"
#include "ED_physics.h"
#include "ED_render.h"
+#include "ED_scene.h"
#include "ED_screen.h"
#include "ED_sculpt.h"
#include "ED_space_api.h"
@@ -66,6 +67,7 @@
#include "ED_clip.h"
#include "ED_mask.h"
#include "ED_sequencer.h"
+#include "ED_manipulator_library.h"
#include "io_ops.h"
@@ -80,7 +82,6 @@ void ED_spacetypes_init(void)
/* create space types */
ED_spacetype_outliner();
- ED_spacetype_time();
ED_spacetype_view3d();
ED_spacetype_ipo();
ED_spacetype_image();
@@ -93,13 +94,15 @@ void ED_spacetypes_init(void)
ED_spacetype_script();
ED_spacetype_text();
ED_spacetype_sequencer();
- ED_spacetype_logic();
ED_spacetype_console();
ED_spacetype_userpref();
ED_spacetype_clip();
+ ED_spacetype_topbar();
// ...
/* register operator types for screen and all spaces */
+ ED_operatortypes_workspace();
+ ED_operatortypes_scene();
ED_operatortypes_screen();
ED_operatortypes_anim();
ED_operatortypes_animchannels();
@@ -117,22 +120,33 @@ void ED_spacetypes_init(void)
ED_operatortypes_metaball();
ED_operatortypes_sound();
ED_operatortypes_render();
- ED_operatortypes_logic();
ED_operatortypes_mask();
ED_operatortypes_io();
ED_operatortypes_view2d();
ED_operatortypes_ui();
-
- /* register operators */
+
+ /* manipulator types */
+ ED_manipulatortypes_button_2d();
+ ED_manipulatortypes_dial_3d();
+ ED_manipulatortypes_grab_3d();
+ ED_manipulatortypes_arrow_2d();
+ ED_manipulatortypes_arrow_3d();
+ ED_manipulatortypes_primitive_3d();
+ ED_manipulatortypes_cage_2d();
+ ED_manipulatortypes_cage_3d();
+
+ /* register types for operators and manipulators */
spacetypes = BKE_spacetypes_list();
for (type = spacetypes->first; type; type = type->next) {
- if (type->operatortypes)
+ /* init manipulator types first, operator-types need them */
+ if (type->manipulators) {
+ type->manipulators();
+ }
+ if (type->operatortypes) {
type->operatortypes();
+ }
}
-
- /* register internal render callbacks */
- ED_render_internal_init();
}
void ED_spacemacros_init(void)
@@ -254,7 +268,6 @@ void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
for (rdc = ar->type->drawcalls.first; rdc; rdc = rdc->next) {
if (rdc->type == type) {
- UI_reinit_gl_state();
rdc->draw(C, ar, rdc->customdata);
}
}
@@ -267,7 +280,7 @@ void ED_region_draw_cb_draw(const bContext *C, ARegion *ar, int type)
void ED_spacetype_xxx(void);
/* allocate and init some vars */
-static SpaceLink *xxx_new(const bContext *UNUSED(C))
+static SpaceLink *xxx_new(const ScrArea *UNUSED(sa), const Scene *UNUSED(scene))
{
return NULL;
}
diff --git a/source/blender/editors/space_buttons/buttons_context.c b/source/blender/editors/space_buttons/buttons_context.c
index da3364d872d..6793f0a0195 100644
--- a/source/blender/editors/space_buttons/buttons_context.c
+++ b/source/blender/editors/space_buttons/buttons_context.c
@@ -39,6 +39,7 @@
#include "BLT_translation.h"
#include "DNA_armature_types.h"
+#include "DNA_group_types.h"
#include "DNA_lamp_types.h"
#include "DNA_material_types.h"
#include "DNA_node_types.h"
@@ -49,6 +50,7 @@
#include "BKE_context.h"
#include "BKE_action.h"
+#include "BKE_layer.h"
#include "BKE_material.h"
#include "BKE_modifier.h"
#include "BKE_paint.h"
@@ -56,6 +58,7 @@
#include "BKE_screen.h"
#include "BKE_texture.h"
#include "BKE_linestyle.h"
+#include "BKE_workspace.h"
#include "RNA_access.h"
@@ -111,6 +114,20 @@ static int buttons_context_path_scene(ButsContextPath *path)
return RNA_struct_is_a(ptr->type, &RNA_Scene);
}
+static int buttons_context_path_view_layer(ButsContextPath *path, WorkSpace *workspace)
+{
+ if (buttons_context_path_scene(path)) {
+ Scene *scene = path->ptr[path->len - 1].data;
+ ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
+
+ RNA_pointer_create(&scene->id, &RNA_ViewLayer, view_layer, &path->ptr[path->len]);
+ path->len++;
+ return 1;
+ }
+
+ return 0;
+}
+
/* note: this function can return 1 without adding a world to the path
* so the buttons stay visible, but be sure to check the ID type if a ID_WO */
static int buttons_context_path_world(ButsContextPath *path)
@@ -142,9 +159,8 @@ static int buttons_context_path_world(ButsContextPath *path)
return 0;
}
-static int buttons_context_path_linestyle(ButsContextPath *path)
+static int buttons_context_path_linestyle(ButsContextPath *path, WorkSpace *workspace)
{
- Scene *scene;
FreestyleLineStyle *linestyle;
PointerRNA *ptr = &path->ptr[path->len - 1];
@@ -152,10 +168,10 @@ static int buttons_context_path_linestyle(ButsContextPath *path)
if (RNA_struct_is_a(ptr->type, &RNA_FreestyleLineStyle)) {
return 1;
}
- /* if we have a scene, use the lineset's linestyle */
- else if (buttons_context_path_scene(path)) {
- scene = path->ptr[path->len - 1].data;
- linestyle = BKE_linestyle_active_from_scene(scene);
+ /* if we have a view layer, use the lineset's linestyle */
+ else if (buttons_context_path_view_layer(path, workspace)) {
+ ViewLayer *view_layer = path->ptr[path->len - 1].data;
+ linestyle = BKE_linestyle_active_from_view_layer(view_layer);
if (linestyle) {
RNA_id_pointer_create(&linestyle->id, &path->ptr[path->len]);
path->len++;
@@ -167,27 +183,65 @@ static int buttons_context_path_linestyle(ButsContextPath *path)
return 0;
}
+static int buttons_context_path_workspace(ButsContextPath *path)
+{
+ PointerRNA *ptr = &path->ptr[path->len - 1];
+
+ /* This one just verifies. */
+ return RNA_struct_is_a(ptr->type, &RNA_WorkSpace);
+}
+
+static int buttons_context_path_collection(ButsContextPath *path, eSpaceButtons_Collection_Context collection_context)
+{
+ PointerRNA *ptr = &path->ptr[path->len - 1];
+
+ /* if we already have a (pinned) Collection, we're done */
+ if (RNA_struct_is_a(ptr->type, &RNA_LayerCollection)) {
+ return 1;
+ }
+ else if (RNA_struct_is_a(ptr->type, &RNA_ViewLayer)) {
+ ViewLayer *view_layer = ptr->data;
+
+ if (collection_context == SB_COLLECTION_CTX_GROUP) {
+ Object *ob = OBACT(view_layer);
+ if (ob && ob->dup_group) {
+ view_layer = ob->dup_group->view_layer;
+
+ /* Replace the view layer by the group in the context path. */
+ RNA_pointer_create(NULL, &RNA_Group, ob->dup_group, &path->ptr[path->len - 1]);
+ }
+ }
+
+ LayerCollection *layer_collection = BKE_layer_collection_get_active(view_layer);
+
+ if (layer_collection) {
+ RNA_pointer_create(NULL, &RNA_LayerCollection, layer_collection, &path->ptr[path->len]);
+ path->len++;
+ return 1;
+ }
+ }
+
+ /* no path to a collection possible */
+ return 0;
+}
+
static int buttons_context_path_object(ButsContextPath *path)
{
- Scene *scene;
- Object *ob;
PointerRNA *ptr = &path->ptr[path->len - 1];
/* if we already have a (pinned) object, we're done */
if (RNA_struct_is_a(ptr->type, &RNA_Object)) {
return 1;
}
- /* if we have a scene, use the scene's active object */
- else if (buttons_context_path_scene(path)) {
- scene = path->ptr[path->len - 1].data;
- ob = (scene->basact) ? scene->basact->object : NULL;
- if (ob) {
- RNA_id_pointer_create(&ob->id, &path->ptr[path->len]);
- path->len++;
+ ViewLayer *view_layer = ptr->data;
+ Object *ob = (view_layer->basact) ? view_layer->basact->object : NULL;
- return 1;
- }
+ if (ob) {
+ RNA_id_pointer_create(&ob->id, &path->ptr[path->len]);
+ path->len++;
+
+ return 1;
}
/* no path to a object possible */
@@ -208,6 +262,7 @@ static int buttons_context_path_data(ButsContextPath *path, int type)
else if (RNA_struct_is_a(ptr->type, &RNA_Camera) && (type == -1 || type == OB_CAMERA)) return 1;
else if (RNA_struct_is_a(ptr->type, &RNA_Lamp) && (type == -1 || type == OB_LAMP)) return 1;
else if (RNA_struct_is_a(ptr->type, &RNA_Speaker) && (type == -1 || type == OB_SPEAKER)) return 1;
+ else if (RNA_struct_is_a(ptr->type, &RNA_LightProbe) && (type == -1 || type == OB_LIGHTPROBE)) return 1;
/* try to get an object in the path, no pinning supported here */
else if (buttons_context_path_object(path)) {
ob = path->ptr[path->len - 1].data;
@@ -238,7 +293,7 @@ static int buttons_context_path_modifier(ButsContextPath *path)
return 0;
}
-static int buttons_context_path_material(ButsContextPath *path, bool for_texture, bool new_shading)
+static int buttons_context_path_material(ButsContextPath *path)
{
Object *ob;
PointerRNA *ptr = &path->ptr[path->len - 1];
@@ -256,18 +311,6 @@ static int buttons_context_path_material(ButsContextPath *path, bool for_texture
ma = give_current_material(ob, ob->actcol);
RNA_id_pointer_create(&ma->id, &path->ptr[path->len]);
path->len++;
-
- if (for_texture && give_current_material_texture_node(ma))
- return 1;
-
- if (!new_shading) {
- /* Only try to get mat from node in case of old shading system (see T40331). */
- ma = give_node_material(ma);
- if (ma) {
- RNA_id_pointer_create(&ma->id, &path->ptr[path->len]);
- path->len++;
- }
- }
return 1;
}
}
@@ -367,7 +410,7 @@ static int buttons_context_path_particle(ButsContextPath *path)
return 0;
}
-static int buttons_context_path_brush(ButsContextPath *path)
+static int buttons_context_path_brush(const bContext *C, ButsContextPath *path)
{
Scene *scene;
Brush *br = NULL;
@@ -381,8 +424,10 @@ static int buttons_context_path_brush(ButsContextPath *path)
else if (buttons_context_path_scene(path)) {
scene = path->ptr[path->len - 1].data;
- if (scene)
- br = BKE_paint_brush(BKE_paint_get_active(scene));
+ if (scene) {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ br = BKE_paint_brush(BKE_paint_get_active(scene, view_layer));
+ }
if (br) {
RNA_id_pointer_create((ID *)br, &path->ptr[path->len]);
@@ -396,141 +441,46 @@ static int buttons_context_path_brush(ButsContextPath *path)
return 0;
}
-static int buttons_context_path_texture(ButsContextPath *path, ButsContextTexture *ct)
+static int buttons_context_path_texture(const bContext *C, ButsContextPath *path, ButsContextTexture *ct)
{
- if (ct) {
- /* new shading system */
- PointerRNA *ptr = &path->ptr[path->len - 1];
- ID *id;
-
- /* if we already have a (pinned) texture, we're done */
- if (RNA_struct_is_a(ptr->type, &RNA_Texture))
- return 1;
-
- if (!ct->user)
- return 0;
-
- id = ct->user->id;
-
- if (id) {
- if (GS(id->name) == ID_BR)
- buttons_context_path_brush(path);
- else if (GS(id->name) == ID_MA)
- buttons_context_path_material(path, false, true);
- else if (GS(id->name) == ID_WO)
- buttons_context_path_world(path);
- else if (GS(id->name) == ID_LA)
- buttons_context_path_data(path, OB_LAMP);
- else if (GS(id->name) == ID_PA)
- buttons_context_path_particle(path);
- else if (GS(id->name) == ID_OB)
- buttons_context_path_object(path);
- else if (GS(id->name) == ID_LS)
- buttons_context_path_linestyle(path);
- }
+ PointerRNA *ptr = &path->ptr[path->len - 1];
+ ID *id;
- if (ct->texture) {
- RNA_id_pointer_create(&ct->texture->id, &path->ptr[path->len]);
- path->len++;
- }
+ if (!ct)
+ return 0;
+ /* if we already have a (pinned) texture, we're done */
+ if (RNA_struct_is_a(ptr->type, &RNA_Texture))
return 1;
- }
- else {
- /* old shading system */
- Material *ma;
- Lamp *la;
- World *wo;
- ParticleSystem *psys;
- FreestyleLineStyle *ls;
- Tex *tex;
- PointerRNA *ptr = &path->ptr[path->len - 1];
-
- /* if we already have a (pinned) texture, we're done */
- if (RNA_struct_is_a(ptr->type, &RNA_Texture)) {
- return 1;
- }
- /* try world */
- else if ((path->tex_ctx == SB_TEXC_WORLD) && buttons_context_path_world(path)) {
- wo = path->ptr[path->len - 1].data;
-
- if (wo && GS(wo->id.name) == ID_WO) {
- tex = give_current_world_texture(wo);
-
- RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
- path->len++;
- return 1;
- }
- }
- /* try particles */
- else if ((path->tex_ctx == SB_TEXC_PARTICLES) && buttons_context_path_particle(path)) {
- if (path->ptr[path->len - 1].type == &RNA_ParticleSettings) {
- ParticleSettings *part = path->ptr[path->len - 1].data;
- tex = give_current_particle_texture(part);
- RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
- path->len++;
- return 1;
- }
- else {
- psys = path->ptr[path->len - 1].data;
-
- if (psys && psys->part && GS(psys->part->id.name) == ID_PA) {
- tex = give_current_particle_texture(psys->part);
-
- RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
- path->len++;
- return 1;
- }
- }
- }
- /* try material */
- else if ((path->tex_ctx == SB_TEXC_MATERIAL) && buttons_context_path_material(path, true, false)) {
- ma = path->ptr[path->len - 1].data;
-
- if (ma) {
- tex = give_current_material_texture(ma);
-
- RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
- path->len++;
- return 1;
- }
- }
- /* try lamp */
- else if ((path->tex_ctx == SB_TEXC_LAMP) && buttons_context_path_data(path, OB_LAMP)) {
- la = path->ptr[path->len - 1].data;
-
- if (la) {
- tex = give_current_lamp_texture(la);
-
- RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
- path->len++;
- return 1;
- }
- }
- /* try linestyle */
- else if ((path->tex_ctx == SB_TEXC_LINESTYLE) && buttons_context_path_linestyle(path)) {
- ls = path->ptr[path->len - 1].data;
+ if (!ct->user)
+ return 0;
+
+ id = ct->user->id;
- if (ls) {
- tex = give_current_linestyle_texture(ls);
+ if (id) {
+ if (GS(id->name) == ID_BR)
+ buttons_context_path_brush(C, path);
+ else if (GS(id->name) == ID_PA)
+ buttons_context_path_particle(path);
+ else if (GS(id->name) == ID_OB)
+ buttons_context_path_object(path);
+ else if (GS(id->name) == ID_LS)
+ buttons_context_path_linestyle(path, CTX_wm_workspace(C));
+ }
- RNA_id_pointer_create(&tex->id, &path->ptr[path->len]);
- path->len++;
- return 1;
- }
- }
+ if (ct->texture) {
+ RNA_id_pointer_create(&ct->texture->id, &path->ptr[path->len]);
+ path->len++;
}
- /* no path to a texture possible */
- return 0;
+ return 1;
}
#ifdef WITH_FREESTYLE
-static bool buttons_context_linestyle_pinnable(const bContext *C)
+static bool buttons_context_linestyle_pinnable(const bContext *C, ViewLayer *view_layer)
{
Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *actsrl;
FreestyleConfig *config;
SpaceButs *sbuts;
@@ -539,8 +489,7 @@ static bool buttons_context_linestyle_pinnable(const bContext *C)
return false;
}
/* if Freestyle is not in the Parameter Editor mode */
- actsrl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- config = &actsrl->freestyleConfig;
+ config = &view_layer->freestyle_config;
if (config->mode != FREESTYLE_CONTROL_EDITOR_MODE) {
return false;
}
@@ -556,26 +505,37 @@ static bool buttons_context_linestyle_pinnable(const bContext *C)
static int buttons_context_path(const bContext *C, ButsContextPath *path, int mainb, int flag)
{
SpaceButs *sbuts = CTX_wm_space_buts(C);
+ Scene *scene = CTX_data_scene(C);
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
ID *id;
int found;
memset(path, 0, sizeof(*path));
path->flag = flag;
- path->tex_ctx = sbuts->texture_context;
- /* if some ID datablock is pinned, set the root pointer */
+ /* If some ID datablock is pinned, set the root pointer. */
if (sbuts->pinid) {
id = sbuts->pinid;
RNA_id_pointer_create(id, &path->ptr[0]);
path->len++;
}
+ /* No pinned root, use scene as initial root. */
+ else {
+ if (mainb == BCONTEXT_WORKSPACE) {
+ RNA_id_pointer_create(&workspace->id, &path->ptr[0]);
+ path->len++;
+ }
+ else {
+ RNA_id_pointer_create(&scene->id, &path->ptr[0]);
+ path->len++;
- /* no pinned root, use scene as root */
- if (path->len == 0) {
- id = (ID *)CTX_data_scene(C);
- RNA_id_pointer_create(id, &path->ptr[0]);
- path->len++;
+ if (!ELEM(mainb, BCONTEXT_SCENE, BCONTEXT_RENDER, BCONTEXT_VIEW_LAYER, BCONTEXT_WORLD)) {
+ RNA_pointer_create(NULL, &RNA_ViewLayer, view_layer, &path->ptr[path->len]);
+ path->len++;
+ }
+ }
}
/* now for each buttons context type, we try to construct a path,
@@ -585,20 +545,26 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
case BCONTEXT_RENDER:
found = buttons_context_path_scene(path);
break;
- case BCONTEXT_RENDER_LAYER:
+ case BCONTEXT_VIEW_LAYER:
#ifdef WITH_FREESTYLE
- if (buttons_context_linestyle_pinnable(C)) {
- found = buttons_context_path_linestyle(path);
+ if (buttons_context_linestyle_pinnable(C, view_layer)) {
+ found = buttons_context_path_linestyle(path, workspace);
if (found) {
break;
}
}
#endif
- found = buttons_context_path_scene(path);
+ found = buttons_context_path_view_layer(path, workspace);
break;
case BCONTEXT_WORLD:
found = buttons_context_path_world(path);
break;
+ case BCONTEXT_WORKSPACE:
+ found = buttons_context_path_workspace(path);
+ break;
+ case BCONTEXT_COLLECTION:
+ found = buttons_context_path_collection(path, sbuts->collection_context);
+ break;
case BCONTEXT_OBJECT:
case BCONTEXT_PHYSICS:
case BCONTEXT_CONSTRAINT:
@@ -614,10 +580,10 @@ static int buttons_context_path(const bContext *C, ButsContextPath *path, int ma
found = buttons_context_path_particle(path);
break;
case BCONTEXT_MATERIAL:
- found = buttons_context_path_material(path, false, (sbuts->texuser != NULL));
+ found = buttons_context_path_material(path);
break;
case BCONTEXT_TEXTURE:
- found = buttons_context_path_texture(path, sbuts->texuser);
+ found = buttons_context_path_texture(C, path, sbuts->texuser);
break;
case BCONTEXT_BONE:
found = buttons_context_path_bone(path);
@@ -672,7 +638,7 @@ void buttons_context_compute(const bContext *C, SpaceButs *sbuts)
path = sbuts->path;
- /* We need to set Scene path now! Else, buttons_texture_context_compute() might not get a valid scene. */
+ /* Set scene path. */
buttons_context_path(C, path, BCONTEXT_SCENE, pflag);
buttons_texture_context_compute(C, sbuts);
@@ -740,11 +706,11 @@ void buttons_context_compute(const bContext *C, SpaceButs *sbuts)
const char *buttons_context_dir[] = {
"texture_slot", "scene", "world", "object", "mesh", "armature", "lattice", "curve",
- "meta_ball", "lamp", "speaker", "camera", "material", "material_slot",
+ "meta_ball", "lamp", "speaker", "lightprobe", "camera", "material", "material_slot",
"texture", "texture_user", "texture_user_property", "bone", "edit_bone",
"pose_bone", "particle_system", "particle_system_editable", "particle_settings",
"cloth", "soft_body", "fluid", "smoke", "collision", "brush", "dynamic_paint",
- "line_style", NULL
+ "line_style", "collection", NULL
};
int buttons_context(const bContext *C, const char *member, bContextDataResult *result)
@@ -809,6 +775,10 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
set_pointer_type(path, result, &RNA_Speaker);
return 1;
}
+ else if (CTX_data_equals(member, "lightprobe")) {
+ set_pointer_type(path, result, &RNA_LightProbe);
+ return 1;
+ }
else if (CTX_data_equals(member, "material")) {
set_pointer_type(path, result, &RNA_Material);
return 1;
@@ -817,13 +787,8 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
ButsContextTexture *ct = sbuts->texuser;
if (ct) {
- /* new shading system */
CTX_data_pointer_set(result, &ct->texture->id, &RNA_Texture, ct->texture);
}
- else {
- /* old shading system */
- set_pointer_type(path, result, &RNA_Texture);
- }
return 1;
}
@@ -847,7 +812,7 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
ButsContextTexture *ct = sbuts->texuser;
if (!ct)
- return -1; /* old shading system (found but not available) */
+ return -1;
if (ct->user && ct->user->ptr.data) {
ButsTextureUser *user = ct->user;
@@ -860,7 +825,7 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
ButsContextTexture *ct = sbuts->texuser;
if (!ct)
- return -1; /* old shading system (found but not available) */
+ return -1;
if (ct->user && ct->user->ptr.data) {
ButsTextureUser *user = ct->user;
@@ -880,21 +845,6 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
return 1;
}
- else {
- /* old shading system */
- PointerRNA *ptr;
-
- if ((ptr = get_pointer_type(path, &RNA_Material))) {
- Material *ma = ptr->data;
-
- if (ma) {
- bNode *node = give_current_material_texture_node(ma);
- CTX_data_pointer_set(result, &ma->nodetree->id, &RNA_Node, node);
- }
- }
-
- return 1;
- }
}
else if (CTX_data_equals(member, "texture_slot")) {
ButsContextTexture *ct = sbuts->texuser;
@@ -910,38 +860,6 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
else if (ct) {
return 0; /* new shading system */
}
- else if ((ptr = get_pointer_type(path, &RNA_Material))) {
- Material *ma = ptr->data;
-
- /* if we have a node material, get slot from material in material node */
- if (ma && ma->use_nodes && ma->nodetree) {
- /* if there's an active texture node in the node tree,
- * then that texture is in context directly, without a texture slot */
- if (give_current_material_texture_node(ma))
- return 0;
-
- ma = give_node_material(ma);
- if (ma)
- CTX_data_pointer_set(result, &ma->id, &RNA_MaterialTextureSlot, ma->mtex[(int)ma->texact]);
- else
- return 0;
- }
- else if (ma) {
- CTX_data_pointer_set(result, &ma->id, &RNA_MaterialTextureSlot, ma->mtex[(int)ma->texact]);
- }
- }
- else if ((ptr = get_pointer_type(path, &RNA_Lamp))) {
- Lamp *la = ptr->data;
-
- if (la)
- CTX_data_pointer_set(result, &la->id, &RNA_LampTextureSlot, la->mtex[(int)la->texact]);
- }
- else if ((ptr = get_pointer_type(path, &RNA_World))) {
- World *wo = ptr->data;
-
- if (wo)
- CTX_data_pointer_set(result, &wo->id, &RNA_WorldTextureSlot, wo->mtex[(int)wo->texact]);
- }
else if ((ptr = get_pointer_type(path, &RNA_FreestyleLineStyle))) {
FreestyleLineStyle *ls = ptr->data;
@@ -1064,6 +982,10 @@ int buttons_context(const bContext *C, const char *member, bContextDataResult *r
set_pointer_type(path, result, &RNA_FreestyleLineStyle);
return 1;
}
+ else if (CTX_data_equals(member, "collection")) {
+ set_pointer_type(path, result, &RNA_LayerCollection);
+ return 1;
+ }
else {
return 0; /* not found */
}
@@ -1121,10 +1043,15 @@ void buttons_context_draw(const bContext *C, uiLayout *layout)
name = RNA_struct_name_get_alloc(ptr, namebuf, sizeof(namebuf), NULL);
if (name) {
- if (!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_RENDER_LAYER) && ptr->type == &RNA_Scene)
+ if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_VIEW_LAYER) && ptr->type == &RNA_Scene)) {
uiItemLDrag(row, ptr, "", icon); /* save some space */
- else
+ }
+ else if ((!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_VIEW_LAYER) && ptr->type == &RNA_ViewLayer)) {
+ uiItemLDrag(row, ptr, "", icon); /* save some space */
+ }
+ else {
uiItemLDrag(row, ptr, name, icon);
+ }
if (name != namebuf)
MEM_freeN(name);
diff --git a/source/blender/editors/space_buttons/buttons_intern.h b/source/blender/editors/space_buttons/buttons_intern.h
index 7fc35a6b1e7..84c935dd737 100644
--- a/source/blender/editors/space_buttons/buttons_intern.h
+++ b/source/blender/editors/space_buttons/buttons_intern.h
@@ -64,7 +64,7 @@ typedef struct ButsContextPath {
PointerRNA ptr[8];
int len;
int flag;
- int tex_ctx;
+ int collection_ctx;
} ButsContextPath;
typedef struct ButsTextureUser {
diff --git a/source/blender/editors/space_buttons/buttons_texture.c b/source/blender/editors/space_buttons/buttons_texture.c
index 49bd0794a51..078ab540ace 100644
--- a/source/blender/editors/space_buttons/buttons_texture.c
+++ b/source/blender/editors/space_buttons/buttons_texture.c
@@ -41,8 +41,6 @@
#include "DNA_brush_types.h"
#include "DNA_ID.h"
-#include "DNA_lamp_types.h"
-#include "DNA_material_types.h"
#include "DNA_node_types.h"
#include "DNA_object_types.h"
#include "DNA_object_force_types.h"
@@ -50,17 +48,17 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
-#include "DNA_world_types.h"
#include "DNA_linestyle_types.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_linestyle.h"
-#include "BKE_material.h"
#include "BKE_modifier.h"
#include "BKE_node.h"
#include "BKE_paint.h"
#include "BKE_particle.h"
#include "BKE_scene.h"
+#include "BKE_workspace.h"
#ifdef WITH_FREESTYLE
# include "BKE_freestyle.h"
#endif
@@ -78,172 +76,6 @@
#include "buttons_intern.h" // own include
-/****************** "Old Shading" Texture Context ****************/
-
-bool ED_texture_context_check_world(const bContext *C)
-{
- Scene *scene = CTX_data_scene(C);
- return (scene && scene->world);
-}
-
-bool ED_texture_context_check_material(const bContext *C)
-{
- Object *ob = CTX_data_active_object(C);
- return (ob && (ob->totcol != 0));
-}
-
-bool ED_texture_context_check_lamp(const bContext *C)
-{
- Object *ob = CTX_data_active_object(C);
- return (ob && (ob->type == OB_LAMP));
-}
-
-bool ED_texture_context_check_particles(const bContext *C)
-{
- Object *ob = CTX_data_active_object(C);
- return (ob && ob->particlesystem.first);
-}
-
-bool ED_texture_context_check_linestyle(const bContext *C)
-{
-#ifdef WITH_FREESTYLE
- Scene *scene = CTX_data_scene(C);
- SceneRenderLayer *actsrl;
- FreestyleConfig *config;
- FreestyleLineSet *lineset;
- FreestyleLineStyle *linestyle;
-
- if (scene && (scene->r.mode & R_EDGE_FRS)) {
- actsrl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- config = &actsrl->freestyleConfig;
- if (config->mode == FREESTYLE_CONTROL_EDITOR_MODE) {
- lineset = BKE_freestyle_lineset_get_active(config);
- if (lineset) {
- linestyle = lineset->linestyle;
- return linestyle && (linestyle->flag & LS_TEXTURE);
- }
- }
- }
-#else
- (void)C;
-#endif
- return false;
-}
-
-static void texture_context_check_modifier_foreach(void *userData, Object *UNUSED(ob), ModifierData *UNUSED(md),
- const char *UNUSED(propname))
-{
- *((bool *)userData) = true;
-}
-
-bool ED_texture_context_check_others(const bContext *C)
-{
- /* We cannot rely on sbuts->texuser here, as it is NULL when in "old" tex handling, non-OTHERS tex context. */
- Object *ob = CTX_data_active_object(C);
-
- /* object */
- if (ob) {
- /* Tex force field. */
- if (ob->pd && ob->pd->forcefield == PFIELD_TEXTURE) {
- return true;
- }
-
- /* modifiers */
- {
- bool check = false;
- modifiers_foreachTexLink(ob, texture_context_check_modifier_foreach, &check);
- if (check) {
- return true;
- }
- }
- }
-
- /* brush */
- if (BKE_paint_brush(BKE_paint_get_active_from_context(C))) {
- return true;
- }
-
- return false;
-}
-
-static void set_texture_context(const bContext *C, SpaceButs *sbuts)
-{
- Scene *scene = CTX_data_scene(C);
-
- if (BKE_scene_use_new_shading_nodes(scene)) {
- return; /* No texture context in new shading mode */
- }
-
- {
- bool valid_world = ED_texture_context_check_world(C);
- bool valid_material = ED_texture_context_check_material(C);
- bool valid_lamp = ED_texture_context_check_lamp(C);
- bool valid_particles = ED_texture_context_check_particles(C);
- bool valid_linestyle = ED_texture_context_check_linestyle(C);
- bool valid_others = ED_texture_context_check_others(C);
-
- /* this is similar to direct user action, no need to keep "better" ctxt in _prev */
- if ((sbuts->mainb == BCONTEXT_WORLD) && valid_world) {
- sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_WORLD;
- }
- else if ((sbuts->mainb == BCONTEXT_MATERIAL) && valid_material) {
- sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_MATERIAL;
- }
- else if ((sbuts->mainb == BCONTEXT_DATA) && valid_lamp) {
- sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LAMP;
- }
- else if ((sbuts->mainb == BCONTEXT_PARTICLE) && valid_particles) {
- sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_PARTICLES;
- }
- else if ((sbuts->mainb == BCONTEXT_RENDER_LAYER) && valid_linestyle) {
- sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_LINESTYLE;
- }
- else if ((ELEM(sbuts->mainb, BCONTEXT_MODIFIER, BCONTEXT_PHYSICS)) && valid_others) {
- sbuts->texture_context = sbuts->texture_context_prev = SB_TEXC_OTHER;
- }
- /* Else, try to revive a previous "better" ctxt... */
- else if ((sbuts->texture_context_prev != sbuts->texture_context) &&
- (((sbuts->texture_context_prev == SB_TEXC_WORLD) && valid_world) ||
- ((sbuts->texture_context_prev == SB_TEXC_MATERIAL) && valid_material) ||
- ((sbuts->texture_context_prev == SB_TEXC_LAMP) && valid_lamp) ||
- ((sbuts->texture_context_prev == SB_TEXC_PARTICLES) && valid_particles) ||
- ((sbuts->texture_context_prev == SB_TEXC_LINESTYLE) && valid_linestyle) ||
- ((sbuts->texture_context_prev == SB_TEXC_OTHER) && valid_others)))
- {
- sbuts->texture_context = sbuts->texture_context_prev;
- }
- /* Else, just be sure that current context is valid! */
- else if (((sbuts->texture_context == SB_TEXC_WORLD) && !valid_world) ||
- ((sbuts->texture_context == SB_TEXC_MATERIAL) && !valid_material) ||
- ((sbuts->texture_context == SB_TEXC_LAMP) && !valid_lamp) ||
- ((sbuts->texture_context == SB_TEXC_PARTICLES) && !valid_particles) ||
- ((sbuts->texture_context == SB_TEXC_LINESTYLE) && !valid_linestyle) ||
- ((sbuts->texture_context == SB_TEXC_OTHER) && !valid_others))
- {
- /* this is default fallback, do keep "better" ctxt in _prev */
- sbuts->texture_context_prev = sbuts->texture_context;
- if (valid_material) {
- sbuts->texture_context = SB_TEXC_MATERIAL;
- }
- else if (valid_lamp) {
- sbuts->texture_context = SB_TEXC_LAMP;
- }
- else if (valid_particles) {
- sbuts->texture_context = SB_TEXC_PARTICLES;
- }
- else if (valid_linestyle) {
- sbuts->texture_context = SB_TEXC_LINESTYLE;
- }
- else if (valid_world) {
- sbuts->texture_context = SB_TEXC_WORLD;
- }
- else if (valid_others) {
- sbuts->texture_context = SB_TEXC_OTHER;
- }
- }
- }
-}
-
/************************* Texture User **************************/
static void buttons_texture_user_property_add(ListBase *users, ID *id,
@@ -321,9 +153,6 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
{
Scene *scene = NULL;
Object *ob = NULL;
- Material *ma = NULL;
- Lamp *la = NULL;
- World *wrld = NULL;
FreestyleLineStyle *linestyle = NULL;
Brush *brush = NULL;
ID *pinid = sbuts->pinid;
@@ -335,42 +164,29 @@ static void buttons_texture_users_from_context(ListBase *users, const bContext *
scene = (Scene *)pinid;
else if (GS(pinid->name) == ID_OB)
ob = (Object *)pinid;
- else if (GS(pinid->name) == ID_LA)
- la = (Lamp *)pinid;
- else if (GS(pinid->name) == ID_WO)
- wrld = (World *)pinid;
- else if (GS(pinid->name) == ID_MA)
- ma = (Material *)pinid;
else if (GS(pinid->name) == ID_BR)
brush = (Brush *)pinid;
else if (GS(pinid->name) == ID_LS)
linestyle = (FreestyleLineStyle *)pinid;
}
- if (!scene)
+ if (!scene) {
scene = CTX_data_scene(C);
+ }
+
+ const ID_Type id_type = pinid != NULL ? GS(pinid->name) : -1;
+ if (!pinid || id_type == ID_SCE) {
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
- if (!pinid || GS(pinid->name) == ID_SCE) {
- ob = (scene->basact) ? scene->basact->object : NULL;
- wrld = scene->world;
brush = BKE_paint_brush(BKE_paint_get_active_from_context(C));
- linestyle = BKE_linestyle_active_from_scene(scene);
+ linestyle = BKE_linestyle_active_from_view_layer(view_layer);
+ ob = OBACT(view_layer);
}
- if (ob && ob->type == OB_LAMP && !la)
- la = ob->data;
- if (ob && !ma)
- ma = give_current_material(ob, ob->actcol);
-
/* fill users */
BLI_listbase_clear(users);
- if (ma && !limited_mode)
- buttons_texture_users_find_nodetree(users, &ma->id, ma->nodetree, N_("Material"));
- if (la && !limited_mode)
- buttons_texture_users_find_nodetree(users, &la->id, la->nodetree, N_("Lamp"));
- if (wrld && !limited_mode)
- buttons_texture_users_find_nodetree(users, &wrld->id, wrld->nodetree, N_("World"));
if (linestyle && !limited_mode)
buttons_texture_users_find_nodetree(users, &linestyle->id, linestyle->nodetree, N_("Line Style"));
@@ -439,21 +255,8 @@ void buttons_texture_context_compute(const bContext *C, SpaceButs *sbuts)
/* gather available texture users in context. runs on every draw of
* properties editor, before the buttons are created. */
ButsContextTexture *ct = sbuts->texuser;
- Scene *scene = CTX_data_scene(C);
ID *pinid = sbuts->pinid;
- set_texture_context(C, sbuts);
-
- if (!((sbuts->texture_context == SB_TEXC_OTHER) || BKE_scene_use_new_shading_nodes(scene))) {
- if (ct) {
- BLI_freelistN(&ct->users);
- MEM_freeN(ct);
- sbuts->texuser = NULL;
- }
-
- return;
- }
-
if (!ct) {
ct = MEM_callocN(sizeof(ButsContextTexture), "ButsContextTexture");
sbuts->texuser = ct;
@@ -687,4 +490,3 @@ void uiTemplateTextureShow(uiLayout *layout, bContext *C, PointerRNA *ptr, Prope
UI_but_func_set(but, template_texture_show, user->ptr.data, user->prop);
}
}
-
diff --git a/source/blender/editors/space_buttons/space_buttons.c b/source/blender/editors/space_buttons/space_buttons.c
index e4c23ad74f8..d3fab82f7ff 100644
--- a/source/blender/editors/space_buttons/space_buttons.c
+++ b/source/blender/editors/space_buttons/space_buttons.c
@@ -44,6 +44,7 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "RNA_access.h"
@@ -51,7 +52,7 @@
/* ******************** default callbacks for buttons space ***************** */
-static SpaceLink *buttons_new(const bContext *UNUSED(C))
+static SpaceLink *buttons_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceButs *sbuts;
@@ -147,10 +148,14 @@ static void buttons_main_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, "scene", sbuts->mainb, vertical);
else if (sbuts->mainb == BCONTEXT_RENDER)
ED_region_panels(C, ar, "render", sbuts->mainb, vertical);
- else if (sbuts->mainb == BCONTEXT_RENDER_LAYER)
- ED_region_panels(C, ar, "render_layer", sbuts->mainb, vertical);
+ else if (sbuts->mainb == BCONTEXT_VIEW_LAYER)
+ ED_region_panels(C, ar, "view_layer", sbuts->mainb, vertical);
else if (sbuts->mainb == BCONTEXT_WORLD)
ED_region_panels(C, ar, "world", sbuts->mainb, vertical);
+ else if (sbuts->mainb == BCONTEXT_WORKSPACE)
+ ED_region_panels(C, ar, "workspace", sbuts->mainb, vertical);
+ else if (sbuts->mainb == BCONTEXT_COLLECTION)
+ ED_region_panels(C, ar, "collection", sbuts->mainb, vertical);
else if (sbuts->mainb == BCONTEXT_OBJECT)
ED_region_panels(C, ar, "object", sbuts->mainb, vertical);
else if (sbuts->mainb == BCONTEXT_DATA)
@@ -176,6 +181,20 @@ static void buttons_main_region_draw(const bContext *C, ARegion *ar)
sbuts->mainbo = sbuts->mainb;
}
+static void buttons_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn,
+ const Scene *UNUSED(scene))
+{
+ /* context changes */
+ switch (wmn->category) {
+ case NC_SCREEN:
+ if (ELEM(wmn->data, ND_LAYER)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
+ }
+}
+
static void buttons_operatortypes(void)
{
WM_operatortype_append(BUTTONS_OT_toolbox);
@@ -206,6 +225,28 @@ static void buttons_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
+static void buttons_header_region_message_subscribe(
+ const bContext *UNUSED(C),
+ WorkSpace *UNUSED(workspace), Scene *UNUSED(scene),
+ bScreen *UNUSED(screen), ScrArea *sa, ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ SpaceButs *sbuts = sa->spacedata.first;
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ /* Don't check for SpaceButs.mainb here, we may toggle between view-layers
+ * where one has no active object, so that available contexts changes. */
+ WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
+
+ if (!ELEM(sbuts->mainb, BCONTEXT_RENDER, BCONTEXT_SCENE, BCONTEXT_WORLD)) {
+ WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
+ }
+}
+
/* draw a certain button set only if properties area is currently
* showing that button set, to reduce unnecessary drawing. */
static void buttons_area_redraw(ScrArea *sa, short buttons)
@@ -218,7 +259,9 @@ static void buttons_area_redraw(ScrArea *sa, short buttons)
}
/* reused! */
-static void buttons_area_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void buttons_area_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
SpaceButs *sbuts = sa->spacedata.first;
@@ -228,7 +271,7 @@ static void buttons_area_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *
switch (wmn->data) {
case ND_RENDER_OPTIONS:
buttons_area_redraw(sa, BCONTEXT_RENDER);
- buttons_area_redraw(sa, BCONTEXT_RENDER_LAYER);
+ buttons_area_redraw(sa, BCONTEXT_VIEW_LAYER);
break;
case ND_WORLD:
buttons_area_redraw(sa, BCONTEXT_WORLD);
@@ -468,6 +511,7 @@ void ED_spacetype_buttons(void)
art->regionid = RGN_TYPE_WINDOW;
art->init = buttons_main_region_init;
art->draw = buttons_main_region_draw;
+ art->listener = buttons_main_region_listener;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
BLI_addhead(&st->regiontypes, art);
@@ -481,6 +525,7 @@ void ED_spacetype_buttons(void)
art->init = buttons_header_region_init;
art->draw = buttons_header_region_draw;
+ art->message_subscribe = buttons_header_region_message_subscribe;
BLI_addhead(&st->regiontypes, art);
BKE_spacetype_register(st);
diff --git a/source/blender/editors/space_clip/CMakeLists.txt b/source/blender/editors/space_clip/CMakeLists.txt
index 32d48c9c564..8fa4a0de53f 100644
--- a/source/blender/editors/space_clip/CMakeLists.txt
+++ b/source/blender/editors/space_clip/CMakeLists.txt
@@ -27,6 +27,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../imbuf
../../gpu
../../makesdna
diff --git a/source/blender/editors/space_clip/clip_buttons.c b/source/blender/editors/space_clip/clip_buttons.c
index ec8e4a881e1..469d94fed3a 100644
--- a/source/blender/editors/space_clip/clip_buttons.c
+++ b/source/blender/editors/space_clip/clip_buttons.c
@@ -47,11 +47,12 @@
#include "BLT_translation.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_screen.h"
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
+#include "DEG_depsgraph.h"
+
#include "ED_gpencil.h"
#include "UI_interface.h"
@@ -236,7 +237,7 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event)
marker->pos[1] = cb->marker_pos[1] / height;
/* to update position of "parented" objects */
- DAG_id_tag_update(&cb->clip->id, 0);
+ DEG_id_tag_update(&cb->clip->id, 0);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
ok = true;
@@ -321,7 +322,7 @@ static void marker_block_handler(bContext *C, void *arg_cb, int event)
sub_v2_v2(cb->track->markers[i].pos, delta);
/* to update position of "parented" objects */
- DAG_id_tag_update(&cb->clip->id, 0);
+ DEG_id_tag_update(&cb->clip->id, 0);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
ok = true;
diff --git a/source/blender/editors/space_clip/clip_dopesheet_draw.c b/source/blender/editors/space_clip/clip_dopesheet_draw.c
index 4bf4c1e7baa..631d891ce02 100644
--- a/source/blender/editors/space_clip/clip_dopesheet_draw.c
+++ b/source/blender/editors/space_clip/clip_dopesheet_draw.c
@@ -42,8 +42,6 @@
#include "ED_screen.h"
#include "ED_clip.h"
-#include "BIF_gl.h"
-
#include "WM_types.h"
#include "UI_interface.h"
@@ -54,6 +52,9 @@
#include "RNA_access.h"
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+
#include "clip_intern.h" /* own include */
static void track_channel_color(MovieTrackingTrack *track, float default_color[3], float color[3])
@@ -72,78 +73,25 @@ static void track_channel_color(MovieTrackingTrack *track, float default_color[3
}
}
-static void draw_keyframe_shape(float x, float y, float xscale, float yscale, bool sel, float alpha)
+static void draw_keyframe_shape(float x, float y, bool sel, float alpha,
+ unsigned int pos_id, unsigned int color_id)
{
- /* coordinates for diamond shape */
- static const float _unit_diamond_shape[4][2] = {
- {0.0f, 1.0f}, /* top vert */
- {1.0f, 0.0f}, /* mid-right */
- {0.0f, -1.0f}, /* bottom vert */
- {-1.0f, 0.0f} /* mid-left */
- };
- static GLuint displist1 = 0;
- static GLuint displist2 = 0;
- int hsize = STRIP_HEIGHT_HALF;
-
- /* initialize 2 display lists for diamond shape - one empty, one filled */
- if (displist1 == 0) {
- displist1 = glGenLists(1);
- glNewList(displist1, GL_COMPILE);
-
- glBegin(GL_LINE_LOOP);
- glVertex2fv(_unit_diamond_shape[0]);
- glVertex2fv(_unit_diamond_shape[1]);
- glVertex2fv(_unit_diamond_shape[2]);
- glVertex2fv(_unit_diamond_shape[3]);
- glEnd();
- glEndList();
+ float color[4] = { 0.91f, 0.91f, 0.91f, alpha };
+ if (sel) {
+ UI_GetThemeColorShadeAlpha4fv(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha), color);
}
- if (displist2 == 0) {
- displist2 = glGenLists(1);
- glNewList(displist2, GL_COMPILE);
-
- glBegin(GL_QUADS);
- glVertex2fv(_unit_diamond_shape[0]);
- glVertex2fv(_unit_diamond_shape[1]);
- glVertex2fv(_unit_diamond_shape[2]);
- glVertex2fv(_unit_diamond_shape[3]);
- glEnd();
- glEndList();
- }
-
- glPushMatrix();
-
- /* adjust view transform before starting */
- glTranslatef(x, y, 0.0f);
- glScalef(1.0f / xscale * hsize, 1.0f / yscale * hsize, 1.0f);
-
- /* anti-aliased lines for more consistent appearance */
- glEnable(GL_LINE_SMOOTH);
-
- if (sel)
- UI_ThemeColorShadeAlpha(TH_STRIP_SELECT, 50, -255 * (1.0f - alpha));
- else
- glColor4f(0.91f, 0.91f, 0.91f, alpha);
-
- glCallList(displist2);
- /* exterior - black frame */
- glColor4f(0.0f, 0.0f, 0.0f, alpha);
- glCallList(displist1);
-
- glDisable(GL_LINE_SMOOTH);
-
- /* restore view transform */
- glPopMatrix();
+ immAttrib4fv(color_id, color);
+ immVertex2f(pos_id, x, y);
}
-static void clip_draw_dopesheet_background(ARegion *ar, MovieClip *clip)
+static void clip_draw_dopesheet_background(ARegion *ar, MovieClip *clip, unsigned int pos_id)
{
View2D *v2d = &ar->v2d;
MovieTracking *tracking = &clip->tracking;
MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
MovieTrackingDopesheetCoverageSegment *coverage_segment;
-
+
for (coverage_segment = dopesheet->coverage_segments.first;
coverage_segment;
coverage_segment = coverage_segment->next)
@@ -153,12 +101,13 @@ static void clip_draw_dopesheet_background(ARegion *ar, MovieClip *clip)
int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, coverage_segment->end_frame);
if (coverage_segment->coverage == TRACKING_COVERAGE_BAD) {
- glColor4f(1.0f, 0.0f, 0.0f, 0.07f);
+ immUniformColor4f(1.0f, 0.0f, 0.0f, 0.07f);
+ }
+ else {
+ immUniformColor4f(1.0f, 1.0f, 0.0f, 0.07f);
}
- else
- glColor4f(1.0f, 1.0f, 0.0f, 0.07f);
- glRectf(start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
+ immRectf(pos_id, start_frame, v2d->cur.ymin, end_frame, v2d->cur.ymax);
}
}
}
@@ -175,18 +124,21 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene)
MovieTracking *tracking = &clip->tracking;
MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
MovieTrackingDopesheetChannel *channel;
- float y, xscale, yscale;
float strip[4], selected_strip[4];
float height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);
+ unsigned int keyframe_ct = 0;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* don't use totrect set, as the width stays the same
* (NOTE: this is ok here, the configuration is pretty straightforward)
*/
v2d->tot.ymin = (float)(-height);
- y = (float) CHANNEL_FIRST;
-
- UI_view2d_scale_get(v2d, &xscale, &yscale);
+ float y = (float) CHANNEL_FIRST;
/* setup colors for regular and selected strips */
UI_GetThemeColor3fv(TH_STRIP, strip);
@@ -197,7 +149,7 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene)
glEnable(GL_BLEND);
- clip_draw_dopesheet_background(ar, clip);
+ clip_draw_dopesheet_background(ar, clip, pos_id);
for (channel = dopesheet->channels.first; channel; channel = channel->next) {
float yminc = (float) (y - CHANNEL_HEIGHT_HALF);
@@ -208,7 +160,6 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene)
IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
{
MovieTrackingTrack *track = channel->track;
- float alpha;
int i;
bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
@@ -218,32 +169,26 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene)
float default_color[4] = {0.8f, 0.93f, 0.8f, 0.3f};
track_channel_color(track, default_color, color);
- glColor4fv(color);
+ immUniformColor4fv(color);
- glRectf(v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF,
- v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF);
+ immRectf(pos_id, v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF,
+ v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF);
}
- alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
-
/* tracked segments */
for (i = 0; i < channel->tot_segment; i++) {
int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i]);
int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i + 1]);
- if (sel)
- glColor4fv(selected_strip);
- else
- glColor4fv(strip);
+ immUniformColor4fv(sel ? selected_strip : strip);
if (start_frame != end_frame) {
- glRectf(start_frame, (float) y - STRIP_HEIGHT_HALF,
- end_frame, (float) y + STRIP_HEIGHT_HALF);
- draw_keyframe_shape(start_frame, y, xscale, yscale, sel, alpha);
- draw_keyframe_shape(end_frame, y, xscale, yscale, sel, alpha);
+ immRectf(pos_id, start_frame, (float) y - STRIP_HEIGHT_HALF,
+ end_frame, (float) y + STRIP_HEIGHT_HALF);
+ keyframe_ct += 2;
}
else {
- draw_keyframe_shape(start_frame, y, xscale, yscale, sel, alpha);
+ keyframe_ct++;
}
}
@@ -253,9 +198,7 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene)
MovieTrackingMarker *marker = &track->markers[i];
if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
- int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
-
- draw_keyframe_shape(framenr, y, xscale, yscale, sel, alpha);
+ keyframe_ct++;
}
i++;
@@ -266,6 +209,76 @@ void clip_draw_dopesheet_main(SpaceClip *sc, ARegion *ar, Scene *scene)
y -= CHANNEL_STEP;
}
+ immUnbindProgram();
+
+ if (keyframe_ct > 0) {
+ /* draw keyframe markers */
+ format = immVertexFormat();
+ pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int size_id = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color_id = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ unsigned int outline_color_id = GWN_vertformat_attr_add(format, "outlineColor", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+
+ immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
+ GPU_enable_program_point_size();
+ immBegin(GWN_PRIM_POINTS, keyframe_ct);
+
+ /* all same size with black outline */
+ immAttrib1f(size_id, 2.0f * STRIP_HEIGHT_HALF);
+ immAttrib4ub(outline_color_id, 0, 0, 0, 255);
+
+ y = (float) CHANNEL_FIRST; /* start again at the top */
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ float yminc = (float) (y - CHANNEL_HEIGHT_HALF);
+ float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF);
+
+ /* check if visible */
+ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
+ {
+ MovieTrackingTrack *track = channel->track;
+ int i;
+ bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
+ float alpha = (track->flag & TRACK_LOCKED) ? 0.5f : 1.0f;
+
+ /* tracked segments */
+ for (i = 0; i < channel->tot_segment; i++) {
+ int start_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i]);
+ int end_frame = BKE_movieclip_remap_clip_to_scene_frame(clip, channel->segments[2 * i + 1]);
+
+ if (start_frame != end_frame) {
+ draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
+ draw_keyframe_shape(end_frame, y, sel, alpha, pos_id, color_id);
+ }
+ else {
+ draw_keyframe_shape(start_frame, y, sel, alpha, pos_id, color_id);
+ }
+ }
+
+ /* keyframes */
+ i = 0;
+ while (i < track->markersnr) {
+ MovieTrackingMarker *marker = &track->markers[i];
+
+ if ((marker->flag & (MARKER_DISABLED | MARKER_TRACKED)) == 0) {
+ int framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, marker->framenr);
+
+ draw_keyframe_shape(framenr, y, sel, alpha, pos_id, color_id);
+ }
+
+ i++;
+ }
+ }
+
+ /* adjust y-position for next one */
+ y -= CHANNEL_STEP;
+ }
+
+ immEnd();
+ GPU_disable_program_point_size();
+ immUnbindProgram();
+ }
+
glDisable(GL_BLEND);
}
@@ -279,22 +292,15 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar)
SpaceClip *sc = CTX_wm_space_clip(C);
View2D *v2d = &ar->v2d;
MovieClip *clip = ED_space_clip_get_clip(sc);
- MovieTracking *tracking;
- MovieTrackingDopesheet *dopesheet;
- MovieTrackingDopesheetChannel *channel;
uiStyle *style = UI_style_get();
- uiBlock *block;
int fontid = style->widget.uifont_id;
- int height;
- float y;
- PropertyRNA *chan_prop_lock;
-
+
if (!clip)
return;
- tracking = &clip->tracking;
- dopesheet = &tracking->dopesheet;
- height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);
+ MovieTracking *tracking = &clip->tracking;
+ MovieTrackingDopesheet *dopesheet = &tracking->dopesheet;
+ int height = (dopesheet->tot_channel * CHANNEL_STEP) + (CHANNEL_HEIGHT);
if (height > BLI_rcti_size_y(&v2d->mask)) {
/* don't use totrect set, as the width stays the same
@@ -309,6 +315,37 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar)
/* loop through channels, and set up drawing depending on their type
* first pass: just the standard GL-drawing for backdrop + text
*/
+ float y = (float) CHANNEL_FIRST;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ MovieTrackingDopesheetChannel *channel;
+ for (channel = dopesheet->channels.first; channel; channel = channel->next) {
+ float yminc = (float) (y - CHANNEL_HEIGHT_HALF);
+ float ymaxc = (float) (y + CHANNEL_HEIGHT_HALF);
+
+ /* check if visible */
+ if (IN_RANGE(yminc, v2d->cur.ymin, v2d->cur.ymax) ||
+ IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
+ {
+ MovieTrackingTrack *track = channel->track;
+ float color[3];
+ track_channel_color(track, NULL, color);
+ immUniformColor3fv(color);
+
+ immRectf(pos, v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF,
+ v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF);
+ }
+
+ /* adjust y-position for next one */
+ y -= CHANNEL_STEP;
+ }
+ immUnbindProgram();
+
+ /* second pass: text */
y = (float) CHANNEL_FIRST;
BLF_size(fontid, 11.0f * U.pixelsize, U.dpi);
@@ -322,21 +359,11 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar)
IN_RANGE(ymaxc, v2d->cur.ymin, v2d->cur.ymax))
{
MovieTrackingTrack *track = channel->track;
- float font_height, color[3];
bool sel = (track->flag & TRACK_DOPE_SEL) != 0;
- track_channel_color(track, NULL, color);
- glColor3fv(color);
-
- glRectf(v2d->cur.xmin, (float) y - CHANNEL_HEIGHT_HALF,
- v2d->cur.xmax + EXTRA_SCROLL_PAD, (float) y + CHANNEL_HEIGHT_HALF);
-
- if (sel)
- UI_ThemeColor(TH_TEXT_HI);
- else
- UI_ThemeColor(TH_TEXT);
+ UI_FontThemeColor(fontid, sel ? TH_TEXT_HI : TH_TEXT);
- font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
+ float font_height = BLF_height(fontid, channel->name, sizeof(channel->name));
BLF_position(fontid, v2d->cur.xmin + CHANNEL_PAD,
y - font_height / 2.0f, 0.0f);
BLF_draw(fontid, channel->name, strlen(channel->name));
@@ -346,12 +373,12 @@ void clip_draw_dopesheet_channels(const bContext *C, ARegion *ar)
y -= CHANNEL_STEP;
}
- /* second pass: widgets */
- block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
+ /* third pass: widgets */
+ uiBlock *block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
y = (float) CHANNEL_FIRST;
/* get RNA properties (once) */
- chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
+ PropertyRNA *chan_prop_lock = RNA_struct_type_find_property(&RNA_MovieTrackingTrack, "lock");
BLI_assert(chan_prop_lock);
glEnable(GL_BLEND);
diff --git a/source/blender/editors/space_clip/clip_draw.c b/source/blender/editors/space_clip/clip_draw.c
index a71b2baa96f..5962bfe33f3 100644
--- a/source/blender/editors/space_clip/clip_draw.c
+++ b/source/blender/editors/space_clip/clip_draw.c
@@ -55,10 +55,11 @@
#include "ED_mask.h"
#include "ED_gpencil.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
-#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
#include "WM_types.h"
@@ -66,26 +67,25 @@
#include "UI_resources.h"
#include "UI_view2d.h"
-
#include "BLF_api.h"
#include "clip_intern.h" // own include
/*********************** main area drawing *************************/
-static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width)
+static void draw_keyframe(int frame, int cfra, int sfra, float framelen, int width, unsigned int pos)
{
int height = (frame == cfra) ? 22 : 10;
int x = (frame - sfra) * framelen;
if (width == 1) {
- glBegin(GL_LINES);
- glVertex2i(x, 0);
- glVertex2i(x, height * UI_DPI_FAC);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2i(pos, x, 0);
+ immVertex2i(pos, x, height * UI_DPI_FAC);
+ immEnd();
}
else {
- glRecti(x, 0, x + width, height * UI_DPI_FAC);
+ immRecti(pos, x, 0, x + width, height * UI_DPI_FAC);
}
}
@@ -157,7 +157,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* cache background */
ED_region_cache_draw_background(ar);
@@ -166,6 +166,9 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
BKE_movieclip_get_cache_segments(clip, &sc->user, &totseg, &points);
ED_region_cache_draw_cached_segments(ar, totseg, points, sfra, efra);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* track */
if (act_track || act_plane_track) {
for (i = sfra - clip->start_frame + 1, a = 0; i <= efra - clip->start_frame + 1; i++) {
@@ -189,14 +192,17 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
if (generic_track_is_marker_enabled(act_track, act_plane_track, a)) {
framenr = generic_track_get_marker_framenr(act_track, act_plane_track, a);
- if (framenr != i)
- glColor4ub(128, 128, 0, 96);
- else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a))
- glColor4ub(255, 255, 0, 196);
- else
- glColor4ub(255, 255, 0, 96);
+ if (framenr != i) {
+ immUniformColor4ub(128, 128, 0, 96);
+ }
+ else if (generic_track_is_marker_keyframed(act_track, act_plane_track, a)) {
+ immUniformColor4ub(255, 255, 0, 196);
+ }
+ else {
+ immUniformColor4ub(255, 255, 0, 96);
+ }
- glRecti((i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 4 * UI_DPI_FAC);
+ immRecti(pos, (i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 4 * UI_DPI_FAC);
}
}
}
@@ -206,7 +212,7 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
int n = reconstruction->camnr;
MovieReconstructedCamera *cameras = reconstruction->cameras;
- glColor4ub(255, 0, 0, 96);
+ immUniformColor4ub(255, 0, 0, 96);
for (i = sfra, a = 0; i <= efra; i++) {
bool ok = false;
@@ -223,8 +229,9 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
a++;
}
- if (!ok)
- glRecti((i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 8 * UI_DPI_FAC);
+ if (!ok) {
+ immRecti(pos, (i - sfra + clip->start_frame - 1) * framelen, 0, (i - sfra + clip->start_frame) * framelen, 8 * UI_DPI_FAC);
+ }
}
}
@@ -233,15 +240,22 @@ static void draw_movieclip_cache(SpaceClip *sc, ARegion *ar, MovieClip *clip, Sc
/* current frame */
x = (sc->user.framenr - sfra) / (efra - sfra + 1) * ar->winx;
- UI_ThemeColor(TH_CFRAME);
- glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
+ immUniformThemeColor(TH_CFRAME);
+ immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
+
+ immUnbindProgram();
ED_region_cache_draw_curfra_label(sc->user.framenr, x, 8.0f * UI_DPI_FAC);
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* solver keyframes */
- glColor4ub(175, 255, 0, 255);
- draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2);
- draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2);
+ immUniformColor4ub(175, 255, 0, 255);
+ draw_keyframe(act_object->keyframe1 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
+ draw_keyframe(act_object->keyframe2 + clip->start_frame - 1, CFRA, sfra, framelen, 2, pos);
+
+ immUnbindProgram();
/* movie clip animation */
if ((sc->mode == SC_MODE_MASKEDIT) && sc->mask_info.mask) {
@@ -275,11 +289,16 @@ static void draw_movieclip_muted(ARegion *ar, int width, int height, float zoomx
{
int x, y;
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* find window pixel coordinates of origin */
UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
- glColor3f(0.0f, 0.0f, 0.0f);
- glRectf(x, y, x + zoomx * width, y + zoomy * height);
+ immUniformColor3f(0.0f, 0.0f, 0.0f);
+ immRectf(pos, x, y, x + zoomx * width, y + zoomy * height);
+
+ immUnbindProgram();
}
static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar, ImBuf *ibuf,
@@ -295,9 +314,9 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar,
/* checkerboard for case alpha */
if (ibuf->planes == 32) {
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- fdrawcheckerboard(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y);
+ imm_draw_box_checker_2d(x, y, x + zoomx * ibuf->x, y + zoomy * ibuf->y);
}
/* non-scaled proxy shouldn't use filtering */
@@ -307,13 +326,7 @@ static void draw_movieclip_buffer(const bContext *C, SpaceClip *sc, ARegion *ar,
filter = GL_NEAREST;
}
- /* set zoom */
- glPixelZoom(zoomx * width / ibuf->x, zoomy * height / ibuf->y);
-
- glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter);
- /* reset zoom */
- glPixelZoom(1.0f, 1.0f);
-
+ glaDrawImBuf_glsl_ctx(C, ibuf, x, y, filter, zoomx * width / ibuf->x, zoomy * height / ibuf->y);
if (sc->flag & SC_SHOW_METADATA) {
rctf frame;
@@ -335,31 +348,37 @@ static void draw_stabilization_border(SpaceClip *sc, ARegion *ar, int width, int
/* draw boundary border for frame if stabilization is enabled */
if (sc->flag & SC_SHOW_STABLE && clip->tracking.stabilization.flag & TRACKING_2D_STABILIZATION) {
- glColor3f(0.0f, 0.0f, 0.0f);
-
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(3, 0xAAAA);
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ /* Exclusive OR allows to get orig value when second operand is 0,
+ * and negative of orig value when second operand is 1. */
glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(GL_NOR);
+ glLogicOp(GL_XOR);
+
+ gpuPushMatrix();
+ gpuTranslate2f(x, y);
+
+ gpuScale2f(zoomx, zoomy);
+ gpuMultMatrix(sc->stabmat);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
- glPushMatrix();
- glTranslatef(x, y, 0.0f);
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
- glScalef(zoomx, zoomy, 1.0f);
- glMultMatrixf(sc->stabmat);
+ imm_draw_box_wire_2d(shdr_pos, 0.0f, 0.0f, width, height);
- glBegin(GL_LINE_LOOP);
- glVertex2f(0.0f, 0.0f);
- glVertex2f(width, 0.0f);
- glVertex2f(width, height);
- glVertex2f(0.0f, height);
- glEnd();
+ immUnbindProgram();
- glPopMatrix();
+ gpuPopMatrix();
glDisable(GL_COLOR_LOGIC_OP);
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
}
}
@@ -432,53 +451,97 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin
i++;
}
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
if (!tiny) {
- UI_ThemeColor(TH_MARKER_OUTLINE);
+ immUniformThemeColor(TH_MARKER_OUTLINE);
if (TRACK_VIEW_SELECTED(sc, track)) {
- glPointSize(5.0f);
- glBegin(GL_POINTS);
- for (i = a; i < b; i++) {
- if (i != curindex)
- glVertex2f(path[i][0], path[i][1]);
+ if ((b - a - 1) >= 1) {
+ glPointSize(5.0f);
+
+ immBegin(GWN_PRIM_POINTS, b - a - 1);
+
+ for (i = a; i < b; i++) {
+ if (i != curindex) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
+ }
+
+ immEnd();
}
- glEnd();
}
- glLineWidth(3.0f);
- glBegin(GL_LINE_STRIP);
- for (i = a; i < b; i++)
- glVertex2f(path[i][0], path[i][1]);
- glEnd();
- }
+ if ((b - a) >= 2) {
+ glLineWidth(3.0f);
+
+ immBegin(GWN_PRIM_LINE_STRIP, b - a);
+
+ for (i = a; i < b; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
- UI_ThemeColor(TH_PATH_BEFORE);
+ immEnd();
+ }
+ }
if (TRACK_VIEW_SELECTED(sc, track)) {
glPointSize(3.0f);
- glBegin(GL_POINTS);
- for (i = a; i < b; i++) {
- if (i == count + 1)
- UI_ThemeColor(TH_PATH_AFTER);
- if (i != curindex)
- glVertex2f(path[i][0], path[i][1]);
+ if ((curindex - a) >= 1) {
+ immUniformThemeColor(TH_PATH_BEFORE);
+
+ immBegin(GWN_PRIM_POINTS, curindex - a);
+
+ for (i = a; i < curindex; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
+
+ immEnd();
}
- glEnd();
- }
- UI_ThemeColor(TH_PATH_BEFORE);
+ if ((b - curindex - 1) >= 1) {
+ immUniformThemeColor(TH_PATH_AFTER);
+
+ immBegin(GWN_PRIM_POINTS, b - curindex - 1);
+
+ for (i = curindex + 1; i < b; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
+
+ immEnd();
+ }
+ }
glLineWidth(1);
- glBegin(GL_LINE_STRIP);
- for (i = a; i < b; i++) {
- if (i == count + 1)
- UI_ThemeColor(TH_PATH_AFTER);
+ if ((curindex - a + 1) >= 2) {
+ immUniformThemeColor(TH_PATH_BEFORE);
+
+ immBegin(GWN_PRIM_LINE_STRIP, curindex - a + 1);
+
+ for (i = a; i <= curindex; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
+
+ immEnd();
+ }
+
+ if ((b - curindex) >= 2) {
+ immUniformThemeColor(TH_PATH_AFTER);
+
+ immBegin(GWN_PRIM_LINE_STRIP, b - curindex);
+
+ for (i = curindex; i < b; i++) {
+ immVertex2f(pos, path[i][0], path[i][1]);
+ }
- glVertex2f(path[i][0], path[i][1]);
+ immEnd();
}
- glEnd();
+
+ immUnbindProgram();
if (path != path_static) {
MEM_freeN(path);
@@ -487,19 +550,19 @@ static void draw_track_path(SpaceClip *sc, MovieClip *UNUSED(clip), MovieTrackin
}
static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- const float marker_pos[2], int width, int height)
+ const float marker_pos[2], int width, int height, unsigned int position)
{
int tiny = sc->flag & SC_SHOW_TINY_MARKER;
bool show_search = false;
float px[2];
- UI_ThemeColor(TH_MARKER_OUTLINE);
-
px[0] = 1.0f / width / sc->zoom;
px[1] = 1.0f / height / sc->zoom;
glLineWidth(tiny ? 1.0f : 3.0f);
+ immUniformThemeColor(TH_MARKER_OUTLINE);
+
if ((marker->flag & MARKER_DISABLED) == 0) {
float pos[2];
float p[2];
@@ -514,51 +577,54 @@ static void draw_marker_outline(SpaceClip *sc, MovieTrackingTrack *track, MovieT
marker->pattern_corners[2], marker->pattern_corners[3]))
{
glPointSize(tiny ? 3.0f : 4.0f);
- glBegin(GL_POINTS);
- glVertex2f(pos[0], pos[1]);
- glEnd();
+
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2f(position, pos[0], pos[1]);
+ immEnd();
}
else {
- glBegin(GL_LINES);
- glVertex2f(pos[0] + px[0] * 2, pos[1]);
- glVertex2f(pos[0] + px[0] * 8, pos[1]);
+ immBegin(GWN_PRIM_LINES, 8);
+
+ immVertex2f(position, pos[0] + px[0] * 2, pos[1]);
+ immVertex2f(position, pos[0] + px[0] * 8, pos[1]);
+
+ immVertex2f(position, pos[0] - px[0] * 2, pos[1]);
+ immVertex2f(position, pos[0] - px[0] * 8, pos[1]);
- glVertex2f(pos[0] - px[0] * 2, pos[1]);
- glVertex2f(pos[0] - px[0] * 8, pos[1]);
+ immVertex2f(position, pos[0], pos[1] - px[1] * 2);
+ immVertex2f(position, pos[0], pos[1] - px[1] * 8);
- glVertex2f(pos[0], pos[1] - px[1] * 2);
- glVertex2f(pos[0], pos[1] - px[1] * 8);
+ immVertex2f(position, pos[0], pos[1] + px[1] * 2);
+ immVertex2f(position, pos[0], pos[1] + px[1] * 8);
- glVertex2f(pos[0], pos[1] + px[1] * 2);
- glVertex2f(pos[0], pos[1] + px[1] * 8);
- glEnd();
+ immEnd();
}
}
/* pattern and search outline */
- glPushMatrix();
- glTranslate2fv(marker_pos);
+ gpuPushMatrix();
+ gpuTranslate2fv(marker_pos);
if (sc->flag & SC_SHOW_MARKER_PATTERN) {
- glBegin(GL_LINE_LOOP);
- glVertex2fv(marker->pattern_corners[0]);
- glVertex2fv(marker->pattern_corners[1]);
- glVertex2fv(marker->pattern_corners[2]);
- glVertex2fv(marker->pattern_corners[3]);
- glEnd();
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2fv(position, marker->pattern_corners[0]);
+ immVertex2fv(position, marker->pattern_corners[1]);
+ immVertex2fv(position, marker->pattern_corners[2]);
+ immVertex2fv(position, marker->pattern_corners[3]);
+ immEnd();
}
show_search = (TRACK_VIEW_SELECTED(sc, track) &&
((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0;
+
if (sc->flag & SC_SHOW_MARKER_SEARCH && show_search) {
- glBegin(GL_LINE_LOOP);
- glVertex2f(marker->search_min[0], marker->search_min[1]);
- glVertex2f(marker->search_max[0], marker->search_min[1]);
- glVertex2f(marker->search_max[0], marker->search_max[1]);
- glVertex2f(marker->search_min[0], marker->search_max[1]);
- glEnd();
- }
- glPopMatrix();
+ imm_draw_box_wire_2d(position, marker->search_min[0],
+ marker->search_min[1],
+ marker->search_max[0],
+ marker->search_max[1]);
+ }
+
+ gpuPopMatrix();
}
static void track_colors(MovieTrackingTrack *track, int act, float col[3], float scol[3])
@@ -582,11 +648,12 @@ static void track_colors(MovieTrackingTrack *track, int act, float col[3], float
}
static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- const float marker_pos[2], int width, int height, int act, int sel)
+ const float marker_pos[2], int width, int height, int act, int sel, const uint shdr_pos)
{
int tiny = sc->flag & SC_SHOW_TINY_MARKER;
bool show_search = false;
- float col[3], scol[3], px[2];
+ float col[3], scol[3];
+ float px[2];
track_colors(track, act, col, scol);
@@ -595,23 +662,34 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
glLineWidth(1.0f);
+ /* Since we are switching solid and dashed lines in rather complex logic here, just always go with dashed shader. */
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* "simple" mode */
+
/* marker position and offset position */
if ((track->flag & SELECT) == sel && (marker->flag & MARKER_DISABLED) == 0) {
float pos[2], p[2];
if (track->flag & TRACK_LOCKED) {
- if (act)
- UI_ThemeColor(TH_ACT_MARKER);
- else if (track->flag & SELECT)
- UI_ThemeColorShade(TH_LOCK_MARKER, 64);
- else
- UI_ThemeColor(TH_LOCK_MARKER);
+ if (act) {
+ immUniformThemeColor(TH_ACT_MARKER);
+ }
+ else if (track->flag & SELECT) {
+ immUniformThemeColorShade(TH_LOCK_MARKER, 64);
+ }
+ else {
+ immUniformThemeColor(TH_LOCK_MARKER);
+ }
}
else {
- if (track->flag & SELECT)
- glColor3fv(scol);
- else
- glColor3fv(col);
+ immUniformColor3fv((track->flag & SELECT) ? scol : col);
}
add_v2_v2v2(pos, marker->pos, track->offset);
@@ -623,123 +701,114 @@ static void draw_marker_areas(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
marker->pattern_corners[2], marker->pattern_corners[3]))
{
glPointSize(tiny ? 1.0f : 2.0f);
- glBegin(GL_POINTS);
- glVertex2f(pos[0], pos[1]);
- glEnd();
+
+ immUniform1f("dash_factor", 2.0f); /* Solid "line" */
+
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2f(shdr_pos, pos[0], pos[1]);
+ immEnd();
}
else {
- glBegin(GL_LINES);
- glVertex2f(pos[0] + px[0] * 3, pos[1]);
- glVertex2f(pos[0] + px[0] * 7, pos[1]);
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+
+ immBegin(GWN_PRIM_LINES, 8);
+
+ immVertex2f(shdr_pos, pos[0] + px[0] * 3, pos[1]);
+ immVertex2f(shdr_pos, pos[0] + px[0] * 7, pos[1]);
+
+ immVertex2f(shdr_pos, pos[0] - px[0] * 3, pos[1]);
+ immVertex2f(shdr_pos, pos[0] - px[0] * 7, pos[1]);
- glVertex2f(pos[0] - px[0] * 3, pos[1]);
- glVertex2f(pos[0] - px[0] * 7, pos[1]);
+ immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 3);
+ immVertex2f(shdr_pos, pos[0], pos[1] - px[1] * 7);
- glVertex2f(pos[0], pos[1] - px[1] * 3);
- glVertex2f(pos[0], pos[1] - px[1] * 7);
+ immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 3);
+ immVertex2f(shdr_pos, pos[0], pos[1] + px[1] * 7);
- glVertex2f(pos[0], pos[1] + px[1] * 3);
- glVertex2f(pos[0], pos[1] + px[1] * 7);
- glEnd();
+ immEnd();
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.0f);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
- glColor3f(0.0f, 0.0f, 0.0f);
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(3, 0xAAAA);
glEnable(GL_COLOR_LOGIC_OP);
- glLogicOp(GL_NOR);
+ glLogicOp(GL_XOR);
- glBegin(GL_LINES);
- glVertex2fv(pos);
- glVertex2fv(marker_pos);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(shdr_pos, pos);
+ immVertex2fv(shdr_pos, marker_pos);
+ immEnd();
glDisable(GL_COLOR_LOGIC_OP);
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
}
}
/* pattern */
- glPushMatrix();
- glTranslate2fv(marker_pos);
-
- if (tiny) {
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(3, 0xAAAA);
- }
- else {
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE);
- }
+ gpuPushMatrix();
+ gpuTranslate2fv(marker_pos);
- if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
- if (track->flag & TRACK_LOCKED) {
- if (act)
- UI_ThemeColor(TH_ACT_MARKER);
- else if (track->pat_flag & SELECT)
- UI_ThemeColorShade(TH_LOCK_MARKER, 64);
- else UI_ThemeColor(TH_LOCK_MARKER);
+ if (track->flag & TRACK_LOCKED) {
+ if (act) {
+ immUniformThemeColor(TH_ACT_MARKER);
}
- else if (marker->flag & MARKER_DISABLED) {
- if (act)
- UI_ThemeColor(TH_ACT_MARKER);
- else if (track->pat_flag & SELECT)
- UI_ThemeColorShade(TH_DIS_MARKER, 128);
- else UI_ThemeColor(TH_DIS_MARKER);
+ else if (track->pat_flag & SELECT) {
+ immUniformThemeColorShade(TH_LOCK_MARKER, 64);
}
else {
- if (track->pat_flag & SELECT)
- glColor3fv(scol);
- else glColor3fv(col);
+ immUniformThemeColor(TH_LOCK_MARKER);
}
-
- glBegin(GL_LINE_LOOP);
- glVertex2fv(marker->pattern_corners[0]);
- glVertex2fv(marker->pattern_corners[1]);
- glVertex2fv(marker->pattern_corners[2]);
- glVertex2fv(marker->pattern_corners[3]);
- glEnd();
}
-
- /* search */
- show_search = (TRACK_VIEW_SELECTED(sc, track) &&
- ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0;
- if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) {
- if (track->flag & TRACK_LOCKED) {
- if (act)
- UI_ThemeColor(TH_ACT_MARKER);
- else if (track->search_flag & SELECT)
- UI_ThemeColorShade(TH_LOCK_MARKER, 64);
- else UI_ThemeColor(TH_LOCK_MARKER);
+ else if (marker->flag & MARKER_DISABLED) {
+ if (act) {
+ immUniformThemeColor(TH_ACT_MARKER);
}
- else if (marker->flag & MARKER_DISABLED) {
- if (act)
- UI_ThemeColor(TH_ACT_MARKER);
- else if (track->search_flag & SELECT)
- UI_ThemeColorShade(TH_DIS_MARKER, 128);
- else UI_ThemeColor(TH_DIS_MARKER);
+ else if (track->pat_flag & SELECT) {
+ immUniformThemeColorShade(TH_DIS_MARKER, 128);
}
else {
- if (track->search_flag & SELECT)
- glColor3fv(scol);
- else
- glColor3fv(col);
+ immUniformThemeColor(TH_DIS_MARKER);
}
-
- glBegin(GL_LINE_LOOP);
- glVertex2f(marker->search_min[0], marker->search_min[1]);
- glVertex2f(marker->search_max[0], marker->search_min[1]);
- glVertex2f(marker->search_max[0], marker->search_max[1]);
- glVertex2f(marker->search_min[0], marker->search_max[1]);
- glEnd();
+ }
+ else {
+ immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
}
if (tiny) {
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
}
else {
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE);
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+ }
+
+ if ((track->pat_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_PATTERN)) {
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2fv(shdr_pos, marker->pattern_corners[0]);
+ immVertex2fv(shdr_pos, marker->pattern_corners[1]);
+ immVertex2fv(shdr_pos, marker->pattern_corners[2]);
+ immVertex2fv(shdr_pos, marker->pattern_corners[3]);
+ immEnd();
+ }
+
+ /* search */
+ show_search = (TRACK_VIEW_SELECTED(sc, track) &&
+ ((marker->flag & MARKER_DISABLED) == 0 || (sc->flag & SC_SHOW_MARKER_PATTERN) == 0)) != 0;
+
+ if ((track->search_flag & SELECT) == sel && (sc->flag & SC_SHOW_MARKER_SEARCH) && show_search) {
+ imm_draw_box_wire_2d(shdr_pos, marker->search_min[0], marker->search_min[1],
+ marker->search_max[0], marker->search_max[1]);
}
- glPopMatrix();
+ gpuPopMatrix();
+
+ /* Restore default shader */
+ immUnbindProgram();
+
+ const uint pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ BLI_assert(pos == shdr_pos);
+ UNUSED_VARS_NDEBUG(pos);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
}
static float get_shortest_pattern_side(MovieTrackingMarker *marker)
@@ -760,7 +829,7 @@ static float get_shortest_pattern_side(MovieTrackingMarker *marker)
return sqrtf(len_sq);
}
-static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, float px[2])
+static void draw_marker_slide_square(float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos)
{
float tdx, tdy;
@@ -772,15 +841,10 @@ static void draw_marker_slide_square(float x, float y, float dx, float dy, int o
tdy += px[1];
}
- glBegin(GL_QUADS);
- glVertex3f(x - tdx, y + tdy, 0.0f);
- glVertex3f(x + tdx, y + tdy, 0.0f);
- glVertex3f(x + tdx, y - tdy, 0.0f);
- glVertex3f(x - tdx, y - tdy, 0.0f);
- glEnd();
+ immRectf(pos, x - tdx, y - tdy, x + tdx, y + tdy);
}
-static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int outline, float px[2])
+static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int outline, float px[2], unsigned int pos)
{
float tdx, tdy;
@@ -792,15 +856,16 @@ static void draw_marker_slide_triangle(float x, float y, float dx, float dy, int
tdy += px[1];
}
- glBegin(GL_TRIANGLES);
- glVertex3f(x, y, 0.0f);
- glVertex3f(x - tdx, y, 0.0f);
- glVertex3f(x, y + tdy, 0.0f);
- glEnd();
+ immBegin(GWN_PRIM_TRIS, 3);
+ immVertex2f(pos, x, y);
+ immVertex2f(pos, x - tdx, y);
+ immVertex2f(pos, x, y + tdy);
+ immEnd();
}
static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
- const float marker_pos[2], int outline, int sel, int act, int width, int height)
+ const float marker_pos[2], int outline, int sel, int act,
+ int width, int height, unsigned int pos)
{
float dx, dy, patdx, patdy, searchdx, searchdy;
int tiny = sc->flag & SC_SHOW_TINY_MARKER;
@@ -815,11 +880,11 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
track_colors(track, act, col, scol);
if (outline) {
- UI_ThemeColor(TH_MARKER_OUTLINE);
+ immUniformThemeColor(TH_MARKER_OUTLINE);
}
- glPushMatrix();
- glTranslate2fv(marker_pos);
+ gpuPushMatrix();
+ gpuTranslate2fv(marker_pos);
dx = 6.0f / width / sc->zoom;
dy = 6.0f / height / sc->zoom;
@@ -836,17 +901,14 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
if ((sc->flag & SC_SHOW_MARKER_SEARCH) && ((track->search_flag & SELECT) == sel || outline)) {
if (!outline) {
- if (track->search_flag & SELECT)
- glColor3fv(scol);
- else
- glColor3fv(col);
+ immUniformColor3fv((track->search_flag & SELECT) ? scol : col);
}
/* search offset square */
- draw_marker_slide_square(marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px);
+ draw_marker_slide_square(marker->search_min[0], marker->search_max[1], searchdx, searchdy, outline, px, pos);
/* search re-sizing triangle */
- draw_marker_slide_triangle(marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px);
+ draw_marker_slide_triangle(marker->search_max[0], marker->search_min[1], searchdx, searchdy, outline, px, pos);
}
if ((sc->flag & SC_SHOW_MARKER_PATTERN) && ((track->pat_flag & SELECT) == sel || outline)) {
@@ -856,16 +918,13 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
float tilt_ctrl[2];
if (!outline) {
- if (track->pat_flag & SELECT)
- glColor3fv(scol);
- else
- glColor3fv(col);
+ immUniformColor3fv((track->pat_flag & SELECT) ? scol : col);
}
/* pattern's corners sliding squares */
for (i = 0; i < 4; i++) {
draw_marker_slide_square(marker->pattern_corners[i][0], marker->pattern_corners[i][1],
- patdx / 1.5f, patdy / 1.5f, outline, px);
+ patdx / 1.5f, patdy / 1.5f, outline, px, pos);
}
/* ** sliders to control overall pattern ** */
@@ -875,18 +934,16 @@ static void draw_marker_slide_zones(SpaceClip *sc, MovieTrackingTrack *track, Mo
glLineWidth(outline ? 3.0f : 1.0f);
- glBegin(GL_LINES);
- glVertex2f(0.0f, 0.0f);
- glVertex2fv(tilt_ctrl);
- glEnd();
-
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, 0.0f, 0.0f);
+ immVertex2fv(pos, tilt_ctrl);
+ immEnd();
/* slider to control pattern tilt */
- draw_marker_slide_square(tilt_ctrl[0], tilt_ctrl[1], patdx, patdy, outline, px);
+ draw_marker_slide_square(tilt_ctrl[0], tilt_ctrl[1], patdx, patdy, outline, px, pos);
}
- glPopMatrix();
+ gpuPopMatrix();
}
static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTrackingMarker *marker,
@@ -904,16 +961,17 @@ static void draw_marker_texts(SpaceClip *sc, MovieTrackingTrack *track, MovieTra
fontsize = BLF_height_max(fontid);
if (marker->flag & MARKER_DISABLED) {
- if (act)
- UI_ThemeColor(TH_ACT_MARKER);
- else
- UI_ThemeColorShade(TH_DIS_MARKER, 128);
+ if (act) {
+ UI_FontThemeColor(fontid, TH_ACT_MARKER);
+ }
+ else {
+ unsigned char color[4];
+ UI_GetThemeColorShade4ubv(TH_DIS_MARKER, 128, color);
+ BLF_color4ubv(fontid, color);
+ }
}
else {
- if (act)
- UI_ThemeColor(TH_ACT_MARKER);
- else
- UI_ThemeColor(TH_SEL_MARKER);
+ UI_FontThemeColor(fontid, act ? TH_ACT_MARKER : TH_SEL_MARKER);
}
if ((sc->flag & SC_SHOW_MARKER_SEARCH) &&
@@ -974,10 +1032,7 @@ static void plane_track_colors(bool is_active, float color[3], float selected_co
{
UI_GetThemeColor3fv(TH_MARKER, color);
- if (is_active)
- UI_GetThemeColor3fv(TH_ACT_MARKER, selected_color);
- else
- UI_GetThemeColor3fv(TH_SEL_MARKER, selected_color);
+ UI_GetThemeColor3fv(is_active ? TH_ACT_MARKER : TH_SEL_MARKER, selected_color);
}
static void getArrowEndPoint(const int width, const int height, const float zoom,
@@ -1071,14 +1126,12 @@ static void draw_plane_marker_image(Scene *scene,
if (plane_track->image_opacity != 1.0f || ibuf->planes == 32) {
transparent = true;
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
- glColor4f(1.0, 1.0, 1.0, plane_track->image_opacity);
-
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
glGenTextures(1, (GLuint *)&texid);
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
@@ -1087,20 +1140,38 @@ static void draw_plane_marker_image(Scene *scene,
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, GL_RGBA,
GL_UNSIGNED_BYTE, display_buffer);
- glPushMatrix();
- glMultMatrixf(gl_matrix);
+ gpuPushMatrix();
+ gpuMultMatrix(gl_matrix);
+
+ Gwn_VertFormat *imm_format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(imm_format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int texCoord = GWN_vertformat_attr_add(imm_format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, plane_track->image_opacity);
+ immUniform1i("image", 0);
+
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+
+ immAttrib2f(texCoord, 0.0f, 0.0f);
+ immVertex2f(pos, 0.0f, 0.0f);
+
+ immAttrib2f(texCoord, 1.0f, 0.0f);
+ immVertex2f(pos, 1.0f, 0.0f);
+
+ immAttrib2f(texCoord, 1.0f, 1.0f);
+ immVertex2f(pos, 1.0f, 1.0f);
+
+ immAttrib2f(texCoord, 0.0f, 1.0f);
+ immVertex2f(pos, 0.0f, 1.0f);
+
+ immEnd();
- glBegin(GL_QUADS);
- glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f);
- glTexCoord2f(1.0f, 0.0f); glVertex2f(1.0f, 0.0f);
- glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f);
- glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f);
- glEnd();
+ immUnbindProgram();
- glPopMatrix();
+ gpuPopMatrix();
glBindTexture(GL_TEXTURE_2D, 0);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
if (transparent) {
glDisable(GL_BLEND);
@@ -1123,20 +1194,7 @@ static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlane
BKE_image_has_ibuf(plane_track->image, NULL);
const bool draw_plane_quad = !has_image || plane_track->image_opacity == 0.0f;
float px[2];
-
- if (draw_outline) {
- UI_ThemeColor(TH_MARKER_OUTLINE);
- }
- else {
- float color[3], selected_color[3];
- plane_track_colors(is_active_track, color, selected_color);
- if (is_selected_track) {
- glColor3fv(selected_color);
- }
- else {
- glColor3fv(color);
- }
- }
+ float color[3], selected_color[3];
px[0] = 1.0f / width / sc->zoom;
px[1] = 1.0f / height / sc->zoom;
@@ -1146,66 +1204,92 @@ static void draw_plane_marker_ex(SpaceClip *sc, Scene *scene, MovieTrackingPlane
draw_plane_marker_image(scene, plane_track, plane_marker);
}
- if (draw_plane_quad) {
+ if (draw_plane_quad || is_selected_track) {
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- const bool stipple = !draw_outline && tiny;
- const bool thick = draw_outline && !tiny;
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- if (stipple) {
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(3, 0xAAAA);
- }
- else {
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE);
- }
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
- GPU_basic_shader_line_width(thick ? 3.0f : 1.0f);
+ immUniform1i("num_colors", 0); /* "simple" mode */
- /* Draw rectangle itself. */
- glBegin(GL_LINE_LOOP);
- glVertex2fv(plane_marker->corners[0]);
- glVertex2fv(plane_marker->corners[1]);
- glVertex2fv(plane_marker->corners[2]);
- glVertex2fv(plane_marker->corners[3]);
- glEnd();
+ if (draw_plane_quad) {
+ const bool stipple = !draw_outline && tiny;
+ const bool thick = draw_outline && !tiny;
- /* Draw axis. */
- if (!draw_outline) {
- float end_point[2];
- glPushAttrib(GL_COLOR_BUFFER_BIT | GL_CURRENT_BIT);
+ glLineWidth(thick ? 3.0f : 1.0f);
- glBegin(GL_LINES);
+ if (stipple) {
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+ }
+ else {
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+ }
- getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[1], end_point);
- glColor3f(1.0, 0.0, 0.0f);
- glVertex2fv(plane_marker->corners[0]);
- glVertex2fv(end_point);
+ if (draw_outline) {
+ immUniformThemeColor(TH_MARKER_OUTLINE);
+ }
+ else {
+ plane_track_colors(is_active_track, color, selected_color);
+ immUniformColor3fv(is_selected_track ? selected_color : color);
+ }
- getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[3], end_point);
- glColor3f(0.0, 1.0, 0.0f);
- glVertex2fv(plane_marker->corners[0]);
- glVertex2fv(end_point);
+ /* Draw rectangle itself. */
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2fv(shdr_pos, plane_marker->corners[0]);
+ immVertex2fv(shdr_pos, plane_marker->corners[1]);
+ immVertex2fv(shdr_pos, plane_marker->corners[2]);
+ immVertex2fv(shdr_pos, plane_marker->corners[3]);
+ immEnd();
- glEnd();
+ /* Draw axis. */
+ if (!draw_outline) {
+ float end_point[2];
- glPopAttrib();
- }
+ immUniformColor3f(1.0f, 0.0f, 0.0f);
- if (stipple) {
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- }
- else {
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE);
+ immBegin(GWN_PRIM_LINES, 2);
+
+ getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[1], end_point);
+ immVertex2fv(shdr_pos, plane_marker->corners[0]);
+ immVertex2fv(shdr_pos, end_point);
+
+ immEnd();
+
+ immUniformColor3f(0.0f, 1.0f, 0.0f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+
+ getArrowEndPoint(width, height, sc->zoom, plane_marker->corners[0], plane_marker->corners[3], end_point);
+ immVertex2fv(shdr_pos, plane_marker->corners[0]);
+ immVertex2fv(shdr_pos, end_point);
+
+ immEnd();
+ }
}
- }
- /* Draw sliders. */
- if (is_selected_track) {
- int i;
- for (i = 0; i < 4; i++) {
- draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1],
- 3.0f * px[0], 3.0f * px[1], draw_outline, px);
+ /* Draw sliders. */
+ if (is_selected_track) {
+ immUniform1f("dash_factor", 2.0f); /* Solid line */
+
+ if (draw_outline) {
+ immUniformThemeColor(TH_MARKER_OUTLINE);
+ }
+ else {
+ immUniformColor3fv(selected_color);
+ }
+
+ int i;
+ for (i = 0; i < 4; i++) {
+ draw_marker_slide_square(plane_marker->corners[i][0], plane_marker->corners[i][1],
+ 3.0f * px[0], 3.0f * px[1], draw_outline, px, shdr_pos);
+ }
}
+
+ immUnbindProgram();
}
}
@@ -1257,13 +1341,13 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
- glPushMatrix();
- glTranslatef(x, y, 0);
+ gpuPushMatrix();
+ gpuTranslate2f(x, y);
- glPushMatrix();
- glScalef(zoomx, zoomy, 0);
- glMultMatrixf(sc->stabmat);
- glScalef(width, height, 0);
+ gpuPushMatrix();
+ gpuScale2f(zoomx, zoomy);
+ gpuMultMatrix(sc->stabmat);
+ gpuScale2f(width, height);
act_track = BKE_tracking_track_get_active(tracking);
@@ -1329,6 +1413,10 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
}
}
+ unsigned int position = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* markers outline and non-selected areas */
track = tracksbase->first;
fp = marker_pos;
@@ -1339,10 +1427,10 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
if (MARKER_VISIBLE(sc, track, marker)) {
copy_v2_v2(cur_pos, fp ? fp : marker->pos);
- draw_marker_outline(sc, track, marker, cur_pos, width, height);
- draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0);
- draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height);
- draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height);
+ draw_marker_outline(sc, track, marker, cur_pos, width, height, position);
+ draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 0, position);
+ draw_marker_slide_zones(sc, track, marker, cur_pos, 1, 0, 0, width, height, position);
+ draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 0, 0, width, height, position);
if (fp)
fp += 2;
@@ -1365,8 +1453,8 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
if (!act) {
copy_v2_v2(cur_pos, fp ? fp : marker->pos);
- draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1);
- draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height);
+ draw_marker_areas(sc, track, marker, cur_pos, width, height, 0, 1, position);
+ draw_marker_slide_zones(sc, track, marker, cur_pos, 0, 1, 0, width, height, position);
}
if (fp)
@@ -1385,8 +1473,8 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
if (MARKER_VISIBLE(sc, act_track, marker)) {
copy_v2_v2(cur_pos, active_pos ? active_pos : marker->pos);
- draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1);
- draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height);
+ draw_marker_areas(sc, act_track, marker, cur_pos, width, height, 1, 1, position);
+ draw_marker_slide_zones(sc, act_track, marker, cur_pos, 0, 1, 1, width, height, position);
}
}
}
@@ -1395,7 +1483,6 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
MovieTrackingObject *object = BKE_tracking_object_get_active(tracking);
float pos[4], vec[4], mat[4][4], aspy;
- glEnable(GL_POINT_SMOOTH);
glPointSize(3.0f);
aspy = 1.0f / clip->tracking.camera.pixel_aspect;
@@ -1424,28 +1511,34 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
sub_v2_v2(vec, npos);
- if (len_squared_v2(vec) < (3.0f * 3.0f))
- glColor3f(0.0f, 1.0f, 0.0f);
- else
- glColor3f(1.0f, 0.0f, 0.0f);
+ if (len_squared_v2(vec) < (3.0f * 3.0f)) {
+ immUniformColor3f(0.0f, 1.0f, 0.0f);
+ }
+ else {
+ immUniformColor3f(1.0f, 0.0f, 0.0f);
+ }
- glBegin(GL_POINTS);
- if (undistort)
- glVertex3f(pos[0] / width, pos[1] / (height * aspy), 0);
- else
- glVertex3f(npos[0] / width, npos[1] / (height * aspy), 0);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+
+ if (undistort) {
+ immVertex2f(position, pos[0] / width, pos[1] / (height * aspy));
+ }
+ else {
+ immVertex2f(position, npos[0] / width, npos[1] / (height * aspy));
+ }
+
+ immEnd();
}
}
}
track = track->next;
}
-
- glDisable(GL_POINT_SMOOTH);
}
- glPopMatrix();
+ immUnbindProgram();
+
+ gpuPopMatrix();
if (sc->flag & SC_SHOW_NAMES) {
/* scaling should be cleared before drawing texts, otherwise font would also be scaled */
@@ -1471,7 +1564,7 @@ static void draw_tracking_tracks(SpaceClip *sc, Scene *scene, ARegion *ar, Movie
}
}
- glPopMatrix();
+ gpuPopMatrix();
if (marker_pos)
MEM_freeN(marker_pos);
@@ -1498,11 +1591,15 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
UI_view2d_view_to_region_fl(&ar->v2d, 0.0f, 0.0f, &x, &y);
- glPushMatrix();
- glTranslatef(x, y, 0);
- glScalef(zoomx, zoomy, 0);
- glMultMatrixf(sc->stabmat);
- glScalef(width, height, 0);
+ gpuPushMatrix();
+ gpuTranslate2f(x, y);
+ gpuScale2f(zoomx, zoomy);
+ gpuMultMatrix(sc->stabmat);
+ gpuScale2f(width, height);
+
+ unsigned int position = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* grid */
if (sc->flag & SC_SHOW_GRID) {
@@ -1574,22 +1671,26 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
pos[1] += dy;
}
- glColor3f(1.0f, 0.0f, 0.0f);
+ immUniformColor3f(1.0f, 0.0f, 0.0f);
for (i = 0; i <= n; i++) {
- glBegin(GL_LINE_STRIP);
+ immBegin(GWN_PRIM_LINE_STRIP, n + 1);
+
for (j = 0; j <= n; j++) {
- glVertex2fv(grid[i][j]);
+ immVertex2fv(position, grid[i][j]);
}
- glEnd();
+
+ immEnd();
}
for (j = 0; j <= n; j++) {
- glBegin(GL_LINE_STRIP);
+ immBegin(GWN_PRIM_LINE_STRIP, n + 1);
+
for (i = 0; i <= n; i++) {
- glVertex2fv(grid[i][j]);
+ immVertex2fv(position, grid[i][j]);
}
- glEnd();
+
+ immEnd();
}
}
@@ -1608,7 +1709,8 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
continue;
}
- glColor4fv(layer->color);
+ immUniformColor4fv(layer->color);
+
glLineWidth(layer->thickness);
glPointSize((float)(layer->thickness + 2));
@@ -1618,7 +1720,6 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
while (stroke) {
if (stroke->flag & GP_STROKE_2DSPACE) {
if (stroke->totpoints > 1) {
- glBegin(GL_LINE_STRIP);
for (i = 0; i < stroke->totpoints - 1; i++) {
float npos[2], dpos[2], len;
int steps;
@@ -1641,19 +1742,22 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
sub_v2_v2v2(dpos, npos, pos);
mul_v2_fl(dpos, 1.0f / steps);
+ immBegin(GWN_PRIM_LINE_STRIP, steps + 1);
+
for (j = 0; j <= steps; j++) {
BKE_tracking_distort_v2(tracking, pos, tpos);
- glVertex2f(tpos[0] / width, tpos[1] / (height * aspy));
+ immVertex2f(position, tpos[0] / width, tpos[1] / (height * aspy));
add_v2_v2(pos, dpos);
}
+
+ immEnd();
}
- glEnd();
}
else if (stroke->totpoints == 1) {
- glBegin(GL_POINTS);
- glVertex2f(stroke->points[0].x + offsx, stroke->points[0].y + offsy);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2f(position, stroke->points[0].x + offsx, stroke->points[0].y + offsy);
+ immEnd();
}
}
@@ -1667,7 +1771,9 @@ static void draw_distortion(SpaceClip *sc, ARegion *ar, MovieClip *clip,
}
}
- glPopMatrix();
+ immUnbindProgram();
+
+ gpuPopMatrix();
}
void clip_draw_main(const bContext *C, SpaceClip *sc, ARegion *ar)
@@ -1764,8 +1870,8 @@ void clip_draw_grease_pencil(bContext *C, int onlyv2d)
* associated with the clip is already drawn in draw_distortion
*/
if ((sc->flag & SC_MANUAL_CALIBRATION) == 0 || is_track_source) {
- glPushMatrix();
- glMultMatrixf(sc->unistabmat);
+ gpuPushMatrix();
+ gpuMultMatrix(sc->unistabmat);
if (is_track_source) {
MovieTrackingTrack *track = BKE_tracking_track_get_active(&sc->clip->tracking);
@@ -1774,13 +1880,13 @@ void clip_draw_grease_pencil(bContext *C, int onlyv2d)
int framenr = ED_space_clip_get_clip_frame_number(sc);
MovieTrackingMarker *marker = BKE_tracking_marker_get(track, framenr);
- glTranslate2fv(marker->pos);
+ gpuTranslate2fv(marker->pos);
}
}
ED_gpencil_draw_2dimage(C);
- glPopMatrix();
+ gpuPopMatrix();
}
}
else {
diff --git a/source/blender/editors/space_clip/clip_editor.c b/source/blender/editors/space_clip/clip_editor.c
index 59dd755173f..942bc2661c3 100644
--- a/source/blender/editors/space_clip/clip_editor.c
+++ b/source/blender/editors/space_clip/clip_editor.c
@@ -305,15 +305,12 @@ bool ED_space_clip_color_sample(SpaceClip *sc, ARegion *ar, int mval[2], float r
void ED_clip_update_frame(const Main *mainp, int cfra)
{
- wmWindowManager *wm;
- wmWindow *win;
-
/* image window, compo node users */
- for (wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
- for (win = wm->windows.first; win; win = win->next) {
- ScrArea *sa;
+ for (wmWindowManager *wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ bScreen *screen = WM_window_get_active_screen(win);
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->spacetype == SPACE_CLIP) {
SpaceClip *sc = sa->spacedata.first;
diff --git a/source/blender/editors/space_clip/clip_graph_draw.c b/source/blender/editors/space_clip/clip_graph_draw.c
index 424d25defdd..1bd1ad69d64 100644
--- a/source/blender/editors/space_clip/clip_graph_draw.c
+++ b/source/blender/editors/space_clip/clip_graph_draw.c
@@ -42,7 +42,9 @@
#include "ED_screen.h"
#include "ED_clip.h"
-#include "BIF_gl.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
#include "WM_types.h"
@@ -53,52 +55,30 @@
#include "clip_intern.h" // own include
-static void draw_curve_knot(float x, float y, float xscale, float yscale, float hsize)
-{
- static GLuint displist = 0;
-
- /* initialize round circle shape */
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
- gluDisk(qobj, 0, 0.7, 8, 1);
- gluDeleteQuadric(qobj);
-
- glEndList();
- }
-
- glPushMatrix();
-
- glTranslatef(x, y, 0.0f);
- glScalef(1.0f / xscale * hsize, 1.0f / yscale * hsize, 1.0f);
- glCallList(displist);
-
- glPopMatrix();
-}
+typedef struct TrackMotionCurveUserData {
+ MovieTrackingTrack *act_track;
+ bool sel;
+ float xscale, yscale, hsize;
+ unsigned int pos;
+} TrackMotionCurveUserData;
-static void tracking_segment_point_cb(void *UNUSED(userdata), MovieTrackingTrack *UNUSED(track),
+static void tracking_segment_point_cb(void *userdata, MovieTrackingTrack *UNUSED(track),
MovieTrackingMarker *UNUSED(marker), int UNUSED(coord),
int scene_framenr, float val)
{
- glVertex2f(scene_framenr, val);
+ TrackMotionCurveUserData *data = (TrackMotionCurveUserData *) userdata;
+
+ immVertex2f(data->pos, scene_framenr, val);
}
-static void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track, int coord)
+static void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track, int coord, bool is_point)
{
- const float colors[2][3] = {
- {1.0f, 0.0f, 0.0f},
- {0.0f, 1.0f, 0.0f},
- };
- float col[4];
+ TrackMotionCurveUserData *data = (TrackMotionCurveUserData *) userdata;
+ float col[4] = {0.0f, 0.0f, 0.0f, 0.0f};
- copy_v3_v3(col, colors[coord]);
+ col[coord] = 1.0f;
- if (track == userdata) {
+ if (track == data->act_track) {
col[3] = 1.0f;
glLineWidth(2.0f);
}
@@ -107,22 +87,22 @@ static void tracking_segment_start_cb(void *userdata, MovieTrackingTrack *track,
glLineWidth(1.0f);
}
- glColor4fv(col);
+ immUniformColor4fv(col);
- glBegin(GL_LINE_STRIP);
+ if (is_point) {
+ immBeginAtMost(GWN_PRIM_POINTS, 1);
+ }
+ else {
+ /* Graph can be composed of smaller segments, if any marker is disabled */
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, track->markersnr);
+ }
}
static void tracking_segment_end_cb(void *UNUSED(userdata), int UNUSED(coord))
{
- glEnd();
+ immEnd();
}
-typedef struct TrackMotionCurveUserData {
- MovieTrackingTrack *act_track;
- bool sel;
- float xscale, yscale, hsize;
-} TrackMotionCurveUserData;
-
static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
MovieTrackingMarker *marker, int coord, int scene_framenr, float val)
{
@@ -136,16 +116,19 @@ static void tracking_segment_knot_cb(void *userdata, MovieTrackingTrack *track,
sel = (marker->flag & sel_flag) ? 1 : 0;
if (sel == data->sel) {
- if (sel)
- UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
- else
- UI_ThemeColor(TH_HANDLE_VERTEX);
+ immUniformThemeColor(sel ? TH_HANDLE_VERTEX_SELECT : TH_HANDLE_VERTEX);
+
+ gpuPushMatrix();
+ gpuTranslate2f(scene_framenr, val);
+ gpuScale2f(1.0f / data->xscale * data->hsize, 1.0f / data->yscale * data->hsize);
- draw_curve_knot(scene_framenr, val, data->xscale, data->yscale, data->hsize);
+ imm_draw_circle_wire_2d(data->pos, 0, 0, 0.7, 8);
+
+ gpuPopMatrix();
}
}
-static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc)
+static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc, unsigned int pos)
{
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
@@ -162,18 +145,18 @@ static void draw_tracks_motion_curves(View2D *v2d, SpaceClip *sc)
userdata.hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE);
userdata.sel = false;
userdata.act_track = act_track;
+ userdata.pos = pos;
UI_view2d_scale_get(v2d, &userdata.xscale, &userdata.yscale);
clip_graph_tracking_values_iterate(sc,
(sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
(sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
&userdata, tracking_segment_knot_cb, NULL, NULL);
-
/* draw graph lines */
glEnable(GL_BLEND);
clip_graph_tracking_values_iterate(sc,
(sc->flag & SC_SHOW_GRAPH_SEL_ONLY) != 0,
(sc->flag & SC_SHOW_GRAPH_HIDDEN) != 0,
- act_track, tracking_segment_point_cb, tracking_segment_start_cb,
+ &userdata, tracking_segment_point_cb, tracking_segment_start_cb,
tracking_segment_end_cb);
glDisable(GL_BLEND);
@@ -195,6 +178,7 @@ typedef struct TrackErrorCurveUserData {
float projection_matrix[4][4];
int width, height;
float aspy;
+ unsigned int pos;
} TrackErrorCurveUserData;
static void tracking_error_segment_point_cb(void *userdata,
@@ -230,11 +214,11 @@ static void tracking_error_segment_point_cb(void *userdata,
sub_v2_v2v2(delta, reprojected_position, marker_position);
reprojection_error = len_v2(delta) * weight;
- glVertex2f(scene_framenr, reprojection_error);
+ immVertex2f(data->pos, scene_framenr, reprojection_error);
}
}
-static void tracking_error_segment_start_cb(void *userdata, MovieTrackingTrack *track, int coord)
+static void tracking_error_segment_start_cb(void *userdata, MovieTrackingTrack *track, int coord, bool is_point)
{
if (coord == 1) {
TrackErrorCurveUserData *data = (TrackErrorCurveUserData *) userdata;
@@ -249,20 +233,26 @@ static void tracking_error_segment_start_cb(void *userdata, MovieTrackingTrack *
glLineWidth(1.0f);
}
- glColor4fv(col);
+ immUniformColor4fv(col);
- glBegin(GL_LINE_STRIP);
+ if (is_point) { /* This probably never happens here, but just in case... */
+ immBeginAtMost(GWN_PRIM_POINTS, 1);
+ }
+ else {
+ /* Graph can be composed of smaller segments, if any marker is disabled */
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, track->markersnr);
+ }
}
}
static void tracking_error_segment_end_cb(void *UNUSED(userdata), int coord)
{
if (coord == 1) {
- glEnd();
+ immEnd();
}
}
-static void draw_tracks_error_curves(SpaceClip *sc)
+static void draw_tracks_error_curves(SpaceClip *sc, unsigned int pos)
{
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
@@ -273,6 +263,7 @@ static void draw_tracks_error_curves(SpaceClip *sc)
data.tracking_object = BKE_tracking_object_get_active(tracking);
data.active_track = BKE_tracking_track_get_active(tracking);
data.matrix_initialized = false;
+ data.pos = pos;
BKE_movieclip_get_size(clip, &sc->user, &data.width, &data.height);
data.aspy = 1.0f / tracking->camera.pixel_aspect;
@@ -289,37 +280,38 @@ static void draw_tracks_error_curves(SpaceClip *sc)
tracking_error_segment_end_cb);
}
-static void draw_frame_curves(SpaceClip *sc)
+static void draw_frame_curves(SpaceClip *sc, unsigned int pos)
{
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
MovieTrackingReconstruction *reconstruction = BKE_tracking_get_active_reconstruction(tracking);
int i, lines = 0, prevfra = 0;
- glColor3f(0.0f, 0.0f, 1.0f);
+ immUniformColor3f(0.0f, 0.0f, 1.0f);
for (i = 0; i < reconstruction->camnr; i++) {
MovieReconstructedCamera *camera = &reconstruction->cameras[i];
int framenr;
if (lines && camera->framenr != prevfra + 1) {
- glEnd();
+ immEnd();
lines = 0;
}
if (!lines) {
- glBegin(GL_LINE_STRIP);
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, reconstruction->camnr);
lines = 1;
}
framenr = BKE_movieclip_remap_clip_to_scene_frame(clip, camera->framenr);
- glVertex2f(framenr, camera->error);
+ immVertex2f(pos, framenr, camera->error);
prevfra = camera->framenr;
}
- if (lines)
- glEnd();
+ if (lines) {
+ immEnd();
+ }
}
void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene)
@@ -335,14 +327,24 @@ void clip_draw_graph(SpaceClip *sc, ARegion *ar, Scene *scene)
UI_view2d_grid_free(grid);
if (clip) {
- if (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION)
- draw_tracks_motion_curves(v2d, sc);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ glPointSize(3.0f);
- if (sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR)
- draw_tracks_error_curves(sc);
+ if (sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) {
+ draw_tracks_motion_curves(v2d, sc, pos);
+ }
+
+ if (sc->flag & SC_SHOW_GRAPH_TRACKS_ERROR) {
+ draw_tracks_error_curves(sc, pos);
+ }
+
+ if (sc->flag & SC_SHOW_GRAPH_FRAMES) {
+ draw_frame_curves(sc, pos);
+ }
- if (sc->flag & SC_SHOW_GRAPH_FRAMES)
- draw_frame_curves(sc);
+ immUnbindProgram();
}
/* frame range */
diff --git a/source/blender/editors/space_clip/clip_graph_ops.c b/source/blender/editors/space_clip/clip_graph_ops.c
index 9ad4fd4642a..e5a3cb6b57b 100644
--- a/source/blender/editors/space_clip/clip_graph_ops.c
+++ b/source/blender/editors/space_clip/clip_graph_ops.c
@@ -37,7 +37,8 @@
#include "BKE_context.h"
#include "BKE_tracking.h"
-#include "BKE_depsgraph.h"
+
+#include "DEG_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -691,7 +692,7 @@ static int graph_disable_markers_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
diff --git a/source/blender/editors/space_clip/clip_intern.h b/source/blender/editors/space_clip/clip_intern.h
index ae15834a1d9..b0d00744558 100644
--- a/source/blender/editors/space_clip/clip_intern.h
+++ b/source/blender/editors/space_clip/clip_intern.h
@@ -125,12 +125,12 @@ void ED_clip_tool_props_register(struct ARegionType *art);
/* clip_utils.c */
void clip_graph_tracking_values_iterate_track(struct SpaceClip *sc, struct MovieTrackingTrack *track, void *userdata,
void (*func)(void *userdata, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, int coord, int scene_framenr, float val),
- void (*segment_start)(void *userdata, struct MovieTrackingTrack *track, int coord),
+ void (*segment_start)(void *userdata, struct MovieTrackingTrack *track, int coord, bool is_point),
void (*segment_end)(void *userdata, int coord));
void clip_graph_tracking_values_iterate(struct SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata,
void (*func)(void *userdata, struct MovieTrackingTrack *track, struct MovieTrackingMarker *marker, int coord, int scene_framenr, float val),
- void (*segment_start)(void *userdata, struct MovieTrackingTrack *track, int coord),
+ void (*segment_start)(void *userdata, struct MovieTrackingTrack *track, int coord, bool is_point),
void (*segment_end)(void *userdata, int coord));
void clip_graph_tracking_iterate(struct SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata,
diff --git a/source/blender/editors/space_clip/clip_ops.c b/source/blender/editors/space_clip/clip_ops.c
index 7d8dd629562..4afec844f6d 100644
--- a/source/blender/editors/space_clip/clip_ops.c
+++ b/source/blender/editors/space_clip/clip_ops.c
@@ -56,7 +56,6 @@
#include "BKE_context.h"
#include "BKE_global.h"
-#include "BKE_depsgraph.h"
#include "BKE_report.h"
#include "BKE_library.h"
#include "BKE_main.h"
@@ -83,6 +82,8 @@
#include "PIL_time.h"
+#include "DEG_depsgraph_build.h"
+
#include "clip_intern.h" // own include
/******************** view navigation utilities *********************/
@@ -248,7 +249,7 @@ static int open_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_MOVIECLIP | NA_ADDED, clip);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
MEM_freeN(op->customdata);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_clip/clip_toolbar.c b/source/blender/editors/space_clip/clip_toolbar.c
index d2a7244eded..61bd8df3dbf 100644
--- a/source/blender/editors/space_clip/clip_toolbar.c
+++ b/source/blender/editors/space_clip/clip_toolbar.c
@@ -32,6 +32,7 @@
#include <string.h>
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "MEM_guardedalloc.h"
@@ -118,19 +119,17 @@ void CLIP_OT_properties(wmOperatorType *ot)
static ARegion *clip_has_tools_region(ScrArea *sa)
{
- ARegion *ar, *artool = NULL, *arprops = NULL, *arhead;
+ ARegion *ar, *artool = NULL, *arhead;
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->regiontype == RGN_TYPE_TOOLS)
artool = ar;
-
- if (ar->regiontype == RGN_TYPE_TOOL_PROPS)
- arprops = ar;
}
/* tool region hide/unhide also hides props */
- if (arprops && artool)
+ if (artool) {
return artool;
+ }
if (artool == NULL) {
/* add subdiv level; after header */
@@ -149,15 +148,6 @@ static ARegion *clip_has_tools_region(ScrArea *sa)
artool->flag = RGN_FLAG_HIDDEN;
}
- if (arprops == NULL) {
- /* add extra subdivided region for tool properties */
- arprops = MEM_callocN(sizeof(ARegion), "tool props for clip");
-
- BLI_insertlinkafter(&sa->regionbase, artool, arprops);
- arprops->regiontype = RGN_TYPE_TOOL_PROPS;
- arprops->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
- }
-
return artool;
}
@@ -188,78 +178,3 @@ void CLIP_OT_tools(wmOperatorType *ot)
ot->exec = tools_exec;
ot->poll = tools_poll;
}
-
-/************************** redo panel ******************************/
-
-static void clip_panel_operator_redo_buts(const bContext *C, Panel *pa, wmOperator *op)
-{
- uiTemplateOperatorPropertyButs(C, pa->layout, op, NULL, 'V', 0);
-}
-
-static void clip_panel_operator_redo_header(const bContext *C, Panel *pa)
-{
- wmOperator *op = WM_operator_last_redo(C);
-
- if (op)
- BLI_strncpy(pa->drawname, RNA_struct_ui_name(op->type->srna), sizeof(pa->drawname));
- else
- BLI_strncpy(pa->drawname, IFACE_("Operator"), sizeof(pa->drawname));
-}
-
-static void clip_panel_operator_redo_operator(const bContext *C, Panel *pa, wmOperator *op)
-{
- if (op->type->flag & OPTYPE_MACRO) {
- for (op = op->macro.first; op; op = op->next) {
- uiItemL(pa->layout, RNA_struct_ui_name(op->type->srna), ICON_NONE);
- clip_panel_operator_redo_operator(C, pa, op);
- }
- }
- else {
- clip_panel_operator_redo_buts(C, pa, op);
- }
-}
-
-/* TODO de-duplicate redo panel functions - campbell */
-static void clip_panel_operator_redo(const bContext *C, Panel *pa)
-{
- wmOperator *op = WM_operator_last_redo(C);
- ARegion *ar;
- ARegion *ar1;
-
- if (op == NULL)
- return;
-
- /* keep in sync with logic in ED_undo_operator_repeat() */
- ar = CTX_wm_region(C);
- ar1 = BKE_area_find_region_type(CTX_wm_area(C), RGN_TYPE_WINDOW);
- if (ar1)
- CTX_wm_region_set((bContext *)C, ar1);
-
- if (WM_operator_poll((bContext *)C, op->type)) {
- uiBlock *block = uiLayoutGetBlock(pa->layout);
-
- if (!WM_operator_check_ui_enabled(C, op->type->name))
- uiLayoutSetEnabled(pa->layout, false);
-
- /* note, blockfunc is a default but->func, use Handle func to allow button callbacks too */
- UI_block_func_handle_set(block, ED_undo_operator_repeat_cb_evt, op);
-
- clip_panel_operator_redo_operator(C, pa, op);
- }
-
- /* set region back */
- CTX_wm_region_set((bContext *)C, ar);
-}
-
-void ED_clip_tool_props_register(ARegionType *art)
-{
- PanelType *pt;
-
- pt = MEM_callocN(sizeof(PanelType), "spacetype clip panel last operator");
- strcpy(pt->idname, "CLIP_PT_last_operator");
- strcpy(pt->label, N_("Operator"));
- strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
- pt->draw_header = clip_panel_operator_redo_header;
- pt->draw = clip_panel_operator_redo;
- BLI_addtail(&art->paneltypes, pt);
-}
diff --git a/source/blender/editors/space_clip/clip_utils.c b/source/blender/editors/space_clip/clip_utils.c
index e7853cb2a0c..9f79e8ffd6b 100644
--- a/source/blender/editors/space_clip/clip_utils.c
+++ b/source/blender/editors/space_clip/clip_utils.c
@@ -41,10 +41,11 @@
#include "BKE_context.h"
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
-#include "BKE_depsgraph.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "DEG_depsgraph.h"
+
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -52,7 +53,6 @@
#include "ED_screen.h"
#include "ED_clip.h"
-
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -63,7 +63,7 @@ void clip_graph_tracking_values_iterate_track(
SpaceClip *sc, MovieTrackingTrack *track, void *userdata,
void (*func)(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker, int coord,
int scene_framenr, float val),
- void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord),
+ void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point),
void (*segment_end)(void *userdata, int coord))
{
MovieClip *clip = ED_space_clip_get_clip(sc);
@@ -92,8 +92,14 @@ void clip_graph_tracking_values_iterate_track(
}
if (!open) {
- if (segment_start)
- segment_start(userdata, track, coord);
+ if (segment_start) {
+ if ((i + 1) == track->markersnr) {
+ segment_start(userdata, track, coord, true);
+ }
+ else {
+ segment_start(userdata, track, coord, (track->markers[i + 1].flag & MARKER_DISABLED));
+ }
+ }
open = true;
prevval = marker->pos[coord];
@@ -124,7 +130,7 @@ void clip_graph_tracking_values_iterate(
SpaceClip *sc, bool selected_only, bool include_hidden, void *userdata,
void (*func)(void *userdata, MovieTrackingTrack *track, MovieTrackingMarker *marker,
int coord, int scene_framenr, float val),
- void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord),
+ void (*segment_start)(void *userdata, MovieTrackingTrack *track, int coord, bool is_point),
void (*segment_end)(void *userdata, int coord))
{
MovieClip *clip = ED_space_clip_get_clip(sc);
@@ -204,11 +210,11 @@ void clip_delete_track(bContext *C, MovieClip *clip, MovieTrackingTrack *track)
if (used_for_stabilization) {
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
+ /* Inform dependency graph. */
+ DEG_id_tag_update(&clip->id, 0);
if (has_bundle) {
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
}
- /* Inform dependency graph. */
- DAG_id_tag_update(&clip->id, 0);
}
void clip_delete_marker(bContext *C, MovieClip *clip, MovieTrackingTrack *track,
@@ -243,7 +249,7 @@ void clip_delete_plane_track(bContext *C,
/* TODO(sergey): Any notifiers to be sent here? */
(void) C;
/* Inform dependency graph. */
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
}
void clip_view_center_to_point(SpaceClip *sc, float x, float y)
@@ -260,31 +266,35 @@ void clip_view_center_to_point(SpaceClip *sc, float x, float y)
void clip_draw_cfra(SpaceClip *sc, ARegion *ar, Scene *scene)
{
+ /* Draw a light green line to indicate current frame */
View2D *v2d = &ar->v2d;
- float xscale, yscale;
+ float x = (float)(sc->user.framenr * scene->r.framelen);
- /* Draw a light green line to indicate current frame */
- UI_ThemeColor(TH_CFRAME);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- float x = (float)(sc->user.framenr * scene->r.framelen);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_CFRAME);
+ glLineWidth(2.0f);
- glLineWidth(2.0);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, x, v2d->cur.ymin);
+ immVertex2f(pos, x, v2d->cur.ymax);
+ immEnd();
- glBegin(GL_LINES);
- glVertex2f(x, v2d->cur.ymin);
- glVertex2f(x, v2d->cur.ymax);
- glEnd();
+ immUnbindProgram();
UI_view2d_view_orthoSpecial(ar, v2d, 1);
/* because the frame number text is subject to the same scaling as the contents of the view */
- UI_view2d_scale_get(v2d, &xscale, &yscale);
- glScalef(1.0f / xscale, 1.0f, 1.0f);
+ float xscale;
+ UI_view2d_scale_get(v2d, &xscale, NULL);
+ gpuPushMatrix();
+ gpuScale2f(1.0f / xscale, 1.0f);
ED_region_cache_draw_curfra_label(sc->user.framenr, (float)sc->user.framenr * xscale, 18);
/* restore view transform */
- glScalef(xscale, 1.0, 1.0);
+ gpuPopMatrix();
}
void clip_draw_sfra_efra(View2D *v2d, Scene *scene)
@@ -292,17 +302,29 @@ void clip_draw_sfra_efra(View2D *v2d, Scene *scene)
UI_view2d_view_ortho(v2d);
/* currently clip editor supposes that editing clip length is equal to scene frame range */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
- glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)SFRA, v2d->cur.ymax);
- glRectf((float)EFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, (float)SFRA, v2d->cur.ymax);
+ immRectf(pos, (float)EFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+
glDisable(GL_BLEND);
- UI_ThemeColorShade(TH_BACK, -60);
+ immUniformThemeColorShade(TH_BACK, -60);
/* thin lines where the actual frames are */
- fdrawline((float)SFRA, v2d->cur.ymin, (float)SFRA, v2d->cur.ymax);
- fdrawline((float)EFRA, v2d->cur.ymin, (float)EFRA, v2d->cur.ymax);
+ glLineWidth(1.0f);
+
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, (float)SFRA, v2d->cur.ymin);
+ immVertex2f(pos, (float)SFRA, v2d->cur.ymax);
+ immVertex2f(pos, (float)EFRA, v2d->cur.ymin);
+ immVertex2f(pos, (float)EFRA, v2d->cur.ymax);
+ immEnd();
+
+ immUnbindProgram();
}
diff --git a/source/blender/editors/space_clip/space_clip.c b/source/blender/editors/space_clip/space_clip.c
index 58930fa2cf2..e416acf0e58 100644
--- a/source/blender/editors/space_clip/space_clip.c
+++ b/source/blender/editors/space_clip/space_clip.c
@@ -60,7 +60,8 @@
#include "IMB_imbuf.h"
-#include "BIF_gl.h"
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -74,12 +75,8 @@
#include "clip_intern.h" /* own include */
-static void init_preview_region(const bContext *C, ARegion *ar)
+static void init_preview_region(const Scene *scene, const ScrArea *sa, const SpaceClip *sc, ARegion *ar)
{
- Scene *scene = CTX_data_scene(C);
- ScrArea *sa = CTX_wm_area(C);
- SpaceClip *sc = CTX_wm_space_clip(C);
-
ar->regiontype = RGN_TYPE_PREVIEW;
ar->alignment = RGN_ALIGN_TOP;
ar->flag |= RGN_FLAG_HIDDEN;
@@ -137,15 +134,17 @@ static void init_preview_region(const bContext *C, ARegion *ar)
static void reinit_preview_region(const bContext *C, ARegion *ar)
{
+ Scene *scene = CTX_data_scene(C);
+ ScrArea *sa = CTX_wm_area(C);
SpaceClip *sc = CTX_wm_space_clip(C);
if (sc->view == SC_VIEW_DOPESHEET) {
if ((ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL) == 0)
- init_preview_region(C, ar);
+ init_preview_region(scene, sa, sc, ar);
}
else {
if (ar->v2d.flag & V2D_VIEWSYNC_AREA_VERTICAL)
- init_preview_region(C, ar);
+ init_preview_region(scene, sa, sc, ar);
}
}
@@ -167,7 +166,7 @@ static ARegion *ED_clip_has_preview_region(const bContext *C, ScrArea *sa)
arnew = MEM_callocN(sizeof(ARegion), "clip preview region");
BLI_insertlinkbefore(&sa->regionbase, ar, arnew);
- init_preview_region(C, arnew);
+ init_preview_region(CTX_data_scene(C), sa, CTX_wm_space_clip(C), arnew);
return arnew;
}
@@ -227,7 +226,7 @@ static void clip_scopes_check_gpencil_change(ScrArea *sa)
/* ******************** default callbacks for clip space ***************** */
-static SpaceLink *clip_new(const bContext *C)
+static SpaceLink *clip_new(const ScrArea *sa, const Scene *scene)
{
ARegion *ar;
SpaceClip *sc;
@@ -255,13 +254,6 @@ static SpaceLink *clip_new(const bContext *C)
ar->regiontype = RGN_TYPE_TOOLS;
ar->alignment = RGN_ALIGN_LEFT;
- /* tool properties */
- ar = MEM_callocN(sizeof(ARegion), "tool properties for clip");
-
- BLI_addtail(&sc->regionbase, ar);
- ar->regiontype = RGN_TYPE_TOOL_PROPS;
- ar->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
-
/* properties view */
ar = MEM_callocN(sizeof(ARegion), "properties for clip");
@@ -283,7 +275,7 @@ static SpaceLink *clip_new(const bContext *C)
ar = MEM_callocN(sizeof(ARegion), "preview for clip");
BLI_addtail(&sc->regionbase, ar);
- init_preview_region(C, ar);
+ init_preview_region(scene, sa, sc, ar);
/* main region */
ar = MEM_callocN(sizeof(ARegion), "main region for clip");
@@ -329,7 +321,8 @@ static SpaceLink *clip_duplicate(SpaceLink *sl)
return (SpaceLink *)scn;
}
-static void clip_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void clip_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
/* context changes */
switch (wmn->category) {
@@ -887,12 +880,11 @@ static void clip_refresh(const bContext *C, ScrArea *sa)
SpaceClip *sc = (SpaceClip *)sa->spacedata.first;
ARegion *ar_main = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
ARegion *ar_tools = BKE_area_find_region_type(sa, RGN_TYPE_TOOLS);
- ARegion *ar_tool_props = BKE_area_find_region_type(sa, RGN_TYPE_TOOL_PROPS);
ARegion *ar_preview = ED_clip_has_preview_region(C, sa);
ARegion *ar_properties = ED_clip_has_properties_region(sa);
ARegion *ar_channels = ED_clip_has_channels_region(sa);
bool main_visible = false, preview_visible = false, tools_visible = false;
- bool tool_props_visible = false, properties_visible = false, channels_visible = false;
+ bool properties_visible = false, channels_visible = false;
bool view_changed = false;
switch (sc->view) {
@@ -900,7 +892,6 @@ static void clip_refresh(const bContext *C, ScrArea *sa)
main_visible = true;
preview_visible = false;
tools_visible = true;
- tool_props_visible = true;
properties_visible = true;
channels_visible = false;
break;
@@ -908,7 +899,6 @@ static void clip_refresh(const bContext *C, ScrArea *sa)
main_visible = false;
preview_visible = true;
tools_visible = false;
- tool_props_visible = false;
properties_visible = false;
channels_visible = false;
@@ -918,7 +908,6 @@ static void clip_refresh(const bContext *C, ScrArea *sa)
main_visible = false;
preview_visible = true;
tools_visible = false;
- tool_props_visible = false;
properties_visible = false;
channels_visible = true;
@@ -999,30 +988,6 @@ static void clip_refresh(const bContext *C, ScrArea *sa)
}
}
- if (tool_props_visible) {
- if (ar_tool_props && (ar_tool_props->flag & RGN_FLAG_HIDDEN)) {
- ar_tool_props->flag &= ~RGN_FLAG_HIDDEN;
- ar_tool_props->v2d.flag &= ~V2D_IS_INITIALISED;
- view_changed = true;
- }
- if (ar_tool_props && (ar_tool_props->alignment != (RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV))) {
- ar_tool_props->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
- view_changed = true;
- }
- }
- else {
- if (ar_tool_props && !(ar_tool_props->flag & RGN_FLAG_HIDDEN)) {
- ar_tool_props->flag |= RGN_FLAG_HIDDEN;
- ar_tool_props->v2d.flag &= ~V2D_IS_INITIALISED;
- WM_event_remove_handlers((bContext *)C, &ar_tool_props->handlers);
- view_changed = true;
- }
- if (ar_tool_props && ar_tool_props->alignment != RGN_ALIGN_NONE) {
- ar_tool_props->alignment = RGN_ALIGN_NONE;
- view_changed = true;
- }
- }
-
if (preview_visible) {
if (ar_preview && (ar_preview->flag & RGN_FLAG_HIDDEN)) {
ar_preview->flag &= ~RGN_FLAG_HIDDEN;
@@ -1214,13 +1179,13 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar)
show_cursor |= sc->around == V3D_AROUND_CURSOR;
if (show_cursor) {
- glPushMatrix();
- glTranslatef(x, y, 0);
- glScalef(zoomx, zoomy, 0);
- glMultMatrixf(sc->stabmat);
- glScalef(width, height, 0);
+ gpuPushMatrix();
+ gpuTranslate2f(x, y);
+ gpuScale2f(zoomx, zoomy);
+ gpuMultMatrix(sc->stabmat);
+ gpuScale2f(width, height);
ED_image_draw_cursor(ar, sc->cursor);
- glPopMatrix();
+ gpuPopMatrix();
}
clip_draw_cache_and_notes(C, sc, ar);
@@ -1239,7 +1204,9 @@ static void clip_main_region_draw(const bContext *C, ARegion *ar)
}
}
-static void clip_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void clip_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -1350,7 +1317,9 @@ static void clip_preview_region_draw(const bContext *C, ARegion *ar)
dopesheet_region_draw(C, ar);
}
-static void clip_preview_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
+static void clip_preview_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
{
}
@@ -1391,7 +1360,9 @@ static void clip_channels_region_draw(const bContext *C, ARegion *ar)
UI_view2d_view_restore(C);
}
-static void clip_channels_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
+static void clip_channels_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
{
}
@@ -1408,7 +1379,9 @@ static void clip_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void clip_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void clip_header_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -1448,7 +1421,9 @@ static void clip_tools_region_draw(const bContext *C, ARegion *ar)
/****************** tool properties region ******************/
-static void clip_props_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void clip_props_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -1493,7 +1468,9 @@ static void clip_properties_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void clip_properties_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void clip_properties_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -1593,19 +1570,6 @@ void ED_spacetype_clip(void)
BLI_addhead(&st->regiontypes, art);
- /* tool properties */
- art = MEM_callocN(sizeof(ARegionType), "spacetype clip tool properties region");
- art->regionid = RGN_TYPE_TOOL_PROPS;
- art->prefsizex = 0;
- art->prefsizey = 120;
- art->keymapflag = ED_KEYMAP_FRAMES | ED_KEYMAP_UI;
- art->listener = clip_props_region_listener;
- art->init = clip_tools_region_init;
- art->draw = clip_tools_region_draw;
- ED_clip_tool_props_register(art);
-
- BLI_addhead(&st->regiontypes, art);
-
/* regions: header */
art = MEM_callocN(sizeof(ARegionType), "spacetype clip region");
art->regionid = RGN_TYPE_HEADER;
diff --git a/source/blender/editors/space_clip/tracking_ops.c b/source/blender/editors/space_clip/tracking_ops.c
index 50f21c8891c..bfce5a862d0 100644
--- a/source/blender/editors/space_clip/tracking_ops.c
+++ b/source/blender/editors/space_clip/tracking_ops.c
@@ -42,10 +42,11 @@
#include "BKE_context.h"
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
-#include "BKE_depsgraph.h"
#include "BKE_report.h"
#include "BKE_sound.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -675,7 +676,7 @@ MovieTrackingTrack *tracking_marker_check_slide(bContext *C,
* the mouse.
*/
if (sc->flag & SC_SHOW_MARKER_PATTERN) {
- int current_corner;
+ int current_corner = -1;
distance_squared =
mouse_to_closest_pattern_corner_distance_squared(
marker,
@@ -898,7 +899,7 @@ static int slide_marker_modal(bContext *C, wmOperator *op, const wmEvent *event)
}
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
- DAG_id_tag_update(&sc->clip->id, 0);
+ DEG_id_tag_update(&sc->clip->id, 0);
}
else if (data->area == TRACK_AREA_PAT) {
if (data->action == SLIDE_ACTION_SIZE) {
@@ -1193,7 +1194,7 @@ static int disable_markers_exec(bContext *C, wmOperator *op)
}
}
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
diff --git a/source/blender/editors/space_clip/tracking_ops_orient.c b/source/blender/editors/space_clip/tracking_ops_orient.c
index 8c5be7c9d04..2c6ef20f1c4 100644
--- a/source/blender/editors/space_clip/tracking_ops_orient.c
+++ b/source/blender/editors/space_clip/tracking_ops_orient.c
@@ -42,10 +42,12 @@
#include "BKE_context.h"
#include "BKE_constraint.h"
#include "BKE_tracking.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_object.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -68,17 +70,16 @@ static Object *get_camera_with_movieclip(Scene *scene, MovieClip *clip)
return camera;
}
- for (Base *base = scene->base.first;
- base != NULL;
- base = base->next)
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
{
- if (base->object->type == OB_CAMERA) {
- if (BKE_object_movieclip_get(scene, base->object, false) == clip) {
- camera = base->object;
+ if (ob->type == OB_CAMERA) {
+ if (BKE_object_movieclip_get(scene, ob, false) == clip) {
+ camera = ob;
break;
}
}
}
+ FOREACH_SCENE_OBJECT_END;
return camera;
}
@@ -86,6 +87,7 @@ static Object *get_camera_with_movieclip(Scene *scene, MovieClip *clip)
static Object *get_orientation_object(bContext *C)
{
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
SpaceClip *sc = CTX_wm_space_clip(C);
MovieClip *clip = ED_space_clip_get_clip(sc);
MovieTracking *tracking = &clip->tracking;
@@ -96,7 +98,7 @@ static Object *get_orientation_object(bContext *C)
object = get_camera_with_movieclip(scene, clip);
}
else {
- object = OBACT;
+ object = OBACT(view_layer);
}
if (object != NULL && object->parent != NULL) {
@@ -110,7 +112,7 @@ static int set_orientation_poll(bContext *C)
{
SpaceClip *sc = CTX_wm_space_clip(C);
if (sc != NULL) {
- Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
MovieClip *clip = ED_space_clip_get_clip(sc);
if (clip != NULL) {
MovieTracking *tracking = &clip->tracking;
@@ -119,7 +121,7 @@ static int set_orientation_poll(bContext *C)
return true;
}
else {
- return OBACT != NULL;
+ return OBACT(view_layer) != NULL;
}
}
}
@@ -246,8 +248,8 @@ static int set_origin_exec(bContext *C, wmOperator *op)
copy_v3_v3(object->loc, vec);
}
- DAG_id_tag_update(&clip->id, 0);
- DAG_id_tag_update(&object->id, OB_RECALC_OB);
+ DEG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&object->id, OB_RECALC_OB);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
@@ -403,6 +405,7 @@ static int set_plane_exec(bContext *C, wmOperator *op)
ListBase *tracksbase;
Object *object;
Object *camera = get_camera_with_movieclip(scene, clip);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
int tot = 0;
float vec[3][3], mat[4][4], obmat[4][4], newmat[4][4], orig[3] = {0.0f, 0.0f, 0.0f};
int plane = RNA_enum_get(op->ptr, "plane");
@@ -489,11 +492,11 @@ static int set_plane_exec(bContext *C, wmOperator *op)
BKE_object_apply_mat4(object, mat, 0, 0);
}
- BKE_object_where_is_calc(scene, object);
+ BKE_object_where_is_calc(depsgraph, scene, object);
set_axis(scene, object, clip, tracking_object, axis_track, 'X');
- DAG_id_tag_update(&clip->id, 0);
- DAG_id_tag_update(&object->id, OB_RECALC_OB);
+ DEG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&object->id, OB_RECALC_OB);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
@@ -566,8 +569,8 @@ static int set_axis_exec(bContext *C, wmOperator *op)
set_axis(scene, object, clip, tracking_object, track, axis == 0 ? 'X' : 'Y');
- DAG_id_tag_update(&clip->id, 0);
- DAG_id_tag_update(&object->id, OB_RECALC_OB);
+ DEG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&object->id, OB_RECALC_OB);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
@@ -693,10 +696,10 @@ static int do_set_scale(bContext *C,
tracking_object->scale = scale;
}
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
if (object)
- DAG_id_tag_update(&object->id, OB_RECALC_OB);
+ DEG_id_tag_update(&object->id, OB_RECALC_OB);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
diff --git a/source/blender/editors/space_clip/tracking_ops_plane.c b/source/blender/editors/space_clip/tracking_ops_plane.c
index aa8518befaa..6c85bdfc4ec 100644
--- a/source/blender/editors/space_clip/tracking_ops_plane.c
+++ b/source/blender/editors/space_clip/tracking_ops_plane.c
@@ -39,9 +39,10 @@
#include "BKE_context.h"
#include "BKE_tracking.h"
-#include "BKE_depsgraph.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -372,7 +373,7 @@ static int slide_plane_marker_modal(bContext *C,
data->previous_mval[1] = event->mval[1];
copy_v2_v2(data->previous_corner, data->corner);
- DAG_id_tag_update(&sc->clip->id, 0);
+ DEG_id_tag_update(&sc->clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, NULL);
@@ -390,7 +391,7 @@ static int slide_plane_marker_modal(bContext *C,
clip_tracking_show_cursor(C);
- DAG_id_tag_update(&sc->clip->id, 0);
+ DEG_id_tag_update(&sc->clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EDITED, clip);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_clip/tracking_ops_solve.c b/source/blender/editors/space_clip/tracking_ops_solve.c
index 5c74c1947e3..89dfadc8974 100644
--- a/source/blender/editors/space_clip/tracking_ops_solve.c
+++ b/source/blender/editors/space_clip/tracking_ops_solve.c
@@ -43,10 +43,11 @@
#include "BKE_movieclip.h"
#include "BKE_tracking.h"
#include "BKE_global.h"
-#include "BKE_depsgraph.h"
#include "BKE_report.h"
#include "BKE_library.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -180,7 +181,7 @@ static void solve_camera_freejob(void *scv)
MEM_freeN(tracking->stats);
tracking->stats = NULL;
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_main_add_notifier(NC_MOVIECLIP | NA_EVALUATED, clip);
WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, NULL);
@@ -327,7 +328,7 @@ static int clear_solution_exec(bContext *C, wmOperator *UNUSED(op))
reconstruction->camnr = 0;
reconstruction->flag &= ~TRACKING_RECONSTRUCTED;
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | NA_EVALUATED, clip);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, NULL);
diff --git a/source/blender/editors/space_clip/tracking_ops_stabilize.c b/source/blender/editors/space_clip/tracking_ops_stabilize.c
index 35b1aead343..4eb6a4fbb24 100644
--- a/source/blender/editors/space_clip/tracking_ops_stabilize.c
+++ b/source/blender/editors/space_clip/tracking_ops_stabilize.c
@@ -38,7 +38,8 @@
#include "BKE_context.h"
#include "BKE_tracking.h"
-#include "BKE_depsgraph.h"
+
+#include "DEG_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -84,7 +85,7 @@ static int stabilize_2d_add_exec(bContext *C, wmOperator *UNUSED(op))
}
if (update) {
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
@@ -138,7 +139,7 @@ static int stabilize_2d_remove_exec(bContext *C, wmOperator *UNUSED(op))
}
if (update) {
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
@@ -227,7 +228,7 @@ static int stabilize_2d_rotation_add_exec(bContext *C, wmOperator *UNUSED(op))
}
if (update) {
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
@@ -281,7 +282,7 @@ static int stabilize_2d_rotation_remove_exec(bContext *C, wmOperator *UNUSED(op)
}
if (update) {
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
WM_event_add_notifier(C, NC_MOVIECLIP | ND_DISPLAY, clip);
}
diff --git a/source/blender/editors/space_clip/tracking_ops_track.c b/source/blender/editors/space_clip/tracking_ops_track.c
index 0dd0ee8c7d4..cd8e92c9b9c 100644
--- a/source/blender/editors/space_clip/tracking_ops_track.c
+++ b/source/blender/editors/space_clip/tracking_ops_track.c
@@ -297,7 +297,8 @@ static void track_markers_endjob(void *tmv)
tmj->scene->r.cfra = BKE_movieclip_remap_clip_to_scene_frame(tmj->clip,
tmj->lastfra);
if (wm != NULL) {
- ED_update_for_newframe(tmj->main, tmj->scene, 0);
+ // XXX: ...
+ // ED_update_for_newframe(tmj->main, tmj->scene);
}
BKE_autotrack_context_sync(tmj->context);
diff --git a/source/blender/editors/space_console/console_draw.c b/source/blender/editors/space_console/console_draw.c
index 6396b390ca0..c8a06545e0f 100644
--- a/source/blender/editors/space_console/console_draw.c
+++ b/source/blender/editors/space_console/console_draw.c
@@ -40,6 +40,7 @@
#include "MEM_guardedalloc.h"
#include "BIF_gl.h"
+#include "GPU_immediate.h"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -157,6 +158,8 @@ static int console_textview_line_color(struct TextViewContext *tvc, unsigned cha
int offl = 0, offc = 0;
int xy[2] = {CONSOLE_DRAW_MARGIN, CONSOLE_DRAW_MARGIN};
int pen[2];
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
xy[1] += tvc->lheight / 6;
console_cursor_wrap_offset(sc->prompt, tvc->console_width, &offl, &offc, NULL);
@@ -168,14 +171,17 @@ static int console_textview_line_color(struct TextViewContext *tvc, unsigned cha
pen[1] += tvc->lheight * offl;
/* cursor */
- UI_GetThemeColor3ubv(TH_CONSOLE_CURSOR, fg);
- glColor3ubv(fg);
-
- glRecti((xy[0] + pen[0]) - 1,
- (xy[1] + pen[1]),
- (xy[0] + pen[0]) + 1,
- (xy[1] + pen[1] + tvc->lheight)
- );
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_CONSOLE_CURSOR);
+
+ immRectf(pos,
+ (xy[0] + pen[0]) - 1,
+ (xy[1] + pen[1]),
+ (xy[0] + pen[0]) + 1,
+ (xy[1] + pen[1] + tvc->lheight)
+ );
+
+ immUnbindProgram();
}
console_line_color(fg, cl_iter->type);
diff --git a/source/blender/editors/space_console/space_console.c b/source/blender/editors/space_console/space_console.c
index 97a85bce006..c49df387707 100644
--- a/source/blender/editors/space_console/space_console.c
+++ b/source/blender/editors/space_console/space_console.c
@@ -52,7 +52,7 @@
/* ******************** default callbacks for console space ***************** */
-static SpaceLink *console_new(const bContext *UNUSED(C))
+static SpaceLink *console_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceConsole *sconsole;
@@ -368,7 +368,9 @@ static void console_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void console_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar, wmNotifier *wmn)
+static void console_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
// SpaceInfo *sinfo = sa->spacedata.first;
diff --git a/source/blender/editors/space_file/file_draw.c b/source/blender/editors/space_file/file_draw.c
index 396f3cf32f4..043f32c56e7 100644
--- a/source/blender/editors/space_file/file_draw.c
+++ b/source/blender/editors/space_file/file_draw.c
@@ -42,7 +42,6 @@
# include "BLI_winstuff.h"
#endif
-#include "BIF_gl.h"
#include "BIF_glutil.h"
#include "BKE_context.h"
@@ -53,6 +52,8 @@
#include "BLT_translation.h"
+#include "BLF_api.h"
+
#include "IMB_imbuf_types.h"
#include "DNA_userdef_types.h"
@@ -71,6 +72,9 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+
#include "filelist.h"
#include "file_intern.h" // own include
@@ -258,9 +262,10 @@ void file_draw_buttons(const bContext *C, ARegion *ar)
static void draw_tile(int sx, int sy, int width, int height, int colorid, int shade)
{
- UI_ThemeColorShade(colorid, shade);
+ float color[4];
+ UI_GetThemeColorShade4fv(colorid, shade, color);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox((float)sx, (float)(sy - height), (float)(sx + width), (float)sy, 5.0f);
+ UI_draw_roundbox_aa(true, (float)sx, (float)(sy - height), (float)(sx + width), (float)sy, 5.0f, color);
}
@@ -285,7 +290,8 @@ static void file_draw_icon(uiBlock *block, const char *path, int sx, int sy, int
}
-static void file_draw_string(int sx, int sy, const char *string, float width, int height, short align)
+static void file_draw_string(int sx, int sy, const char *string, float width, int height, short align,
+ const unsigned char col[4])
{
uiStyle *style;
uiFontStyle fs;
@@ -310,7 +316,7 @@ static void file_draw_string(int sx, int sy, const char *string, float width, in
rect.ymin = sy - height;
rect.ymax = sy;
- UI_fontstyle_draw(&fs, &rect, fname);
+ UI_fontstyle_draw(&fs, &rect, fname, col);
}
void file_calc_previews(const bContext *C, ARegion *ar)
@@ -335,6 +341,7 @@ static void file_draw_preview(
float scale;
int ex, ey;
bool use_dropshadow = !is_icon && (typeflags & FILE_TYPE_IMAGE);
+ float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
BLI_assert(imb != NULL);
@@ -370,7 +377,7 @@ static void file_draw_preview(
xco = sx + (int)dx;
yco = sy - layout->prv_h + (int)dy;
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* shadow */
if (use_dropshadow) {
@@ -381,12 +388,12 @@ static void file_draw_preview(
/* the image */
if (!is_icon && typeflags & FILE_TYPE_FTFONT) {
- UI_ThemeColor(TH_TEXT);
- }
- else {
- glColor4f(1.0, 1.0, 1.0, 1.0);
+ UI_GetThemeColor4fv(TH_TEXT, col);
}
- glaDrawPixelsTexScaled((float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect, scale, scale);
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTexScaled(&state, (float)xco, (float)yco, imb->x, imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, imb->rect,
+ scale, scale, 1.0f, 1.0f, col);
if (icon) {
UI_icon_draw_aspect((float)xco, (float)yco, icon, icon_aspect, 1.0f);
@@ -394,8 +401,13 @@ static void file_draw_preview(
/* border */
if (use_dropshadow) {
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
- fdrawbox((float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4f(0.0f, 0.0f, 0.0f, 0.4f);
+ imm_draw_box_wire_2d(pos, (float)xco, (float)yco, (float)(xco + ex), (float)(yco + ey));
+ immUnbindProgram();
}
but = uiDefBut(block, UI_BTYPE_LABEL, 0, "", xco, yco, ex, ey, NULL, 0.0, 0.0, 0, 0, NULL);
@@ -451,49 +463,70 @@ static void draw_background(FileLayout *layout, View2D *v2d)
int i;
int sy;
- UI_ThemeColorShade(TH_BACK, -7);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShade(TH_BACK, -7);
/* alternating flat shade background */
for (i = 0; (i <= layout->rows); i += 2) {
sy = (int)v2d->cur.ymax - i * (layout->tile_h + 2 * layout->tile_border_y) - layout->tile_border_y;
- glRectf(v2d->cur.xmin, (float)sy, v2d->cur.xmax, (float)(sy + layout->tile_h + 2 * layout->tile_border_y));
-
+ immRectf(pos, v2d->cur.xmin, (float)sy, v2d->cur.xmax, (float)(sy + layout->tile_h + 2 * layout->tile_border_y));
}
+
+ immUnbindProgram();
}
static void draw_dividers(FileLayout *layout, View2D *v2d)
{
+ /* vertical column dividers */
+
const int step = (layout->tile_w + 2 * layout->tile_border_x);
- int v1[2], v2[2];
- int sx;
- unsigned char col_hi[3], col_lo[3];
- UI_GetThemeColorShade3ubv(TH_BACK, 30, col_hi);
- UI_GetThemeColorShade3ubv(TH_BACK, -30, col_lo);
+ unsigned int vertex_ct = 0;
+ int sx = (int)v2d->tot.xmin;
+ while (sx < v2d->cur.xmax) {
+ sx += step;
+ vertex_ct += 4; /* vertex_count = 2 points per line * 2 lines per divider */
+ }
+
+ if (vertex_ct > 0) {
+ int v1[2], v2[2];
+ unsigned char col_hi[3], col_lo[3];
- v1[1] = v2d->cur.ymax - layout->tile_border_y;
- v2[1] = v2d->cur.ymin;
+ UI_GetThemeColorShade3ubv(TH_BACK, 30, col_hi);
+ UI_GetThemeColorShade3ubv(TH_BACK, -30, col_lo);
- glBegin(GL_LINES);
+ v1[1] = v2d->cur.ymax - layout->tile_border_y;
+ v2[1] = v2d->cur.ymin;
- /* vertical column dividers */
- sx = (int)v2d->tot.xmin;
- while (sx < v2d->cur.xmax) {
- sx += step;
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
- glColor3ubv(col_lo);
- v1[0] = v2[0] = sx;
- glVertex2iv(v1);
- glVertex2iv(v2);
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GWN_PRIM_LINES, vertex_ct);
- glColor3ubv(col_hi);
- v1[0] = v2[0] = sx + 1;
- glVertex2iv(v1);
- glVertex2iv(v2);
- }
+ sx = (int)v2d->tot.xmin;
+ while (sx < v2d->cur.xmax) {
+ sx += step;
+
+ v1[0] = v2[0] = sx;
+ immSkipAttrib(color);
+ immVertex2iv(pos, v1);
+ immAttrib3ubv(color, col_lo);
+ immVertex2iv(pos, v2);
- glEnd();
+ v1[0] = v2[0] = sx + 1;
+ immSkipAttrib(color);
+ immVertex2iv(pos, v1);
+ immAttrib3ubv(color, col_hi);
+ immVertex2iv(pos, v2);
+ }
+
+ immEnd();
+ immUnbindProgram();
+ }
}
void file_draw_list(const bContext *C, ARegion *ar)
@@ -517,6 +550,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
short align;
bool do_drag;
int column_space = 0.6f * UI_UNIT_X;
+ unsigned char text_col[4];
const bool small_size = SMALL_SIZE_CHECK(params->thumbnail_size);
const bool update_stat_strings = small_size != SMALL_SIZE_CHECK(layout->curr_size);
const float thumb_icon_aspect = sqrtf(64.0f / (float)(params->thumbnail_size));
@@ -575,6 +609,8 @@ void file_draw_list(const bContext *C, ARegion *ar)
}
}
+ BLF_batch_draw_begin();
+
for (i = offset; (i < numfiles) && (i < offset + numfiles_layout); i++) {
unsigned int file_selflag;
char path[FILE_MAX_LIBEXTRA];
@@ -587,9 +623,6 @@ void file_draw_list(const bContext *C, ARegion *ar)
BLI_join_dirfile(path, sizeof(path), root, file->relpath);
- UI_ThemeColor4(TH_TEXT);
-
-
if (!(file_selflag & FILE_SEL_EDITING)) {
if ((params->highlight_file == i) || (file_selflag & FILE_SEL_HIGHLIGHTED) ||
(file_selflag & FILE_SEL_SELECTED))
@@ -625,7 +658,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
sx += ICON_DEFAULT_WIDTH_SCALE + 0.2f * UI_UNIT_X;
}
- UI_ThemeColor4(TH_TEXT);
+ UI_GetThemeColor4ubv(TH_TEXT, text_col);
if (file_selflag & FILE_SEL_EDITING) {
uiBut *but;
@@ -656,7 +689,7 @@ void file_draw_list(const bContext *C, ARegion *ar)
if (!(file_selflag& FILE_SEL_EDITING)) {
int tpos = (FILE_IMGDISPLAY == params->display) ? sy - layout->tile_h + layout->textheight : sy;
- file_draw_string(sx + 1, tpos, file->name, (float)textwidth, textheight, align);
+ file_draw_string(sx + 1, tpos, file->name, (float)textwidth, textheight, align, text_col);
}
sx += (int)layout->column_widths[COLUMN_NAME] + column_space;
@@ -668,7 +701,8 @@ void file_draw_list(const bContext *C, ARegion *ar)
BLI_filelist_entry_size_to_string(NULL, file->entry->size, small_size, file->entry->size_str);
}
file_draw_string(
- sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
+ sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h,
+ align, text_col);
}
sx += (int)layout->column_widths[COLUMN_SIZE] + column_space;
}
@@ -679,10 +713,12 @@ void file_draw_list(const bContext *C, ARegion *ar)
NULL, file->entry->time, small_size, file->entry->time_str, file->entry->date_str);
}
file_draw_string(
- sx, sy, file->entry->date_str, layout->column_widths[COLUMN_DATE], layout->tile_h, align);
+ sx, sy, file->entry->date_str, layout->column_widths[COLUMN_DATE], layout->tile_h,
+ align, text_col);
sx += (int)layout->column_widths[COLUMN_DATE] + column_space;
file_draw_string(
- sx, sy, file->entry->time_str, layout->column_widths[COLUMN_TIME], layout->tile_h, align);
+ sx, sy, file->entry->time_str, layout->column_widths[COLUMN_TIME], layout->tile_h,
+ align, text_col);
sx += (int)layout->column_widths[COLUMN_TIME] + column_space;
}
else {
@@ -697,12 +733,15 @@ void file_draw_list(const bContext *C, ARegion *ar)
BLI_filelist_entry_size_to_string(NULL, file->entry->size, small_size, file->entry->size_str);
}
file_draw_string(
- sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h, align);
+ sx, sy, file->entry->size_str, layout->column_widths[COLUMN_SIZE], layout->tile_h,
+ align, text_col);
}
sx += (int)layout->column_widths[COLUMN_SIZE] + column_space;
}
}
+ BLF_batch_draw_end();
+
UI_block_end(C, block);
UI_block_draw(C, block);
diff --git a/source/blender/editors/space_file/file_panels.c b/source/blender/editors/space_file/file_panels.c
index 1839e861518..363e9666399 100644
--- a/source/blender/editors/space_file/file_panels.c
+++ b/source/blender/editors/space_file/file_panels.c
@@ -88,7 +88,8 @@ static void file_panel_operator(const bContext *C, Panel *pa)
UI_block_func_set(uiLayoutGetBlock(pa->layout), file_draw_check_cb, NULL, NULL);
- uiTemplateOperatorPropertyButs(C, pa->layout, op, file_panel_check_prop, '\0', UI_TEMPLATE_OP_PROPS_SHOW_EMPTY);
+ uiTemplateOperatorPropertyButs(C, pa->layout, op, file_panel_check_prop, UI_BUT_LABEL_ALIGN_NONE,
+ UI_TEMPLATE_OP_PROPS_SHOW_EMPTY);
UI_block_func_set(uiLayoutGetBlock(pa->layout), NULL, NULL, NULL);
}
diff --git a/source/blender/editors/space_file/file_utils.c b/source/blender/editors/space_file/file_utils.c
index c1caf5ae8ac..fc870399696 100644
--- a/source/blender/editors/space_file/file_utils.c
+++ b/source/blender/editors/space_file/file_utils.c
@@ -26,6 +26,7 @@
#include "BLI_rect.h"
#include "BLI_fileops.h"
+#include "BLI_listbase.h"
#include "BLO_readfile.h"
diff --git a/source/blender/editors/space_file/filesel.c b/source/blender/editors/space_file/filesel.c
index 7abe5ff5070..3dfeb5eb5b3 100644
--- a/source/blender/editors/space_file/filesel.c
+++ b/source/blender/editors/space_file/filesel.c
@@ -215,7 +215,8 @@ short ED_fileselect_set_params(SpaceFile *sfile)
FILTER_ID_GR | FILTER_ID_IM | FILTER_ID_LA | FILTER_ID_LS | FILTER_ID_LT | FILTER_ID_MA |
FILTER_ID_MB | FILTER_ID_MC | FILTER_ID_ME | FILTER_ID_MSK | FILTER_ID_NT | FILTER_ID_OB |
FILTER_ID_PA | FILTER_ID_PAL | FILTER_ID_PC | FILTER_ID_SCE | FILTER_ID_SPK | FILTER_ID_SO |
- FILTER_ID_TE | FILTER_ID_TXT | FILTER_ID_VF | FILTER_ID_WO | FILTER_ID_CF;
+ FILTER_ID_TE | FILTER_ID_TXT | FILTER_ID_VF | FILTER_ID_WO | FILTER_ID_CF | FILTER_ID_WS |
+ FILTER_ID_LP;
if (U.uiflag & USER_HIDE_DOT) {
params->flag |= FILE_HIDE_DOT;
@@ -228,7 +229,7 @@ short ED_fileselect_set_params(SpaceFile *sfile)
if (params->type == FILE_LOADLIB) {
params->flag |= RNA_boolean_get(op->ptr, "link") ? FILE_LINK : 0;
params->flag |= RNA_boolean_get(op->ptr, "autoselect") ? FILE_AUTOSELECT : 0;
- params->flag |= RNA_boolean_get(op->ptr, "active_layer") ? FILE_ACTIVELAY : 0;
+ params->flag |= RNA_boolean_get(op->ptr, "active_collection") ? FILE_ACTIVE_COLLECTION : 0;
}
if ((prop = RNA_struct_find_property(op->ptr, "display_type"))) {
diff --git a/source/blender/editors/space_file/space_file.c b/source/blender/editors/space_file/space_file.c
index 1623712786c..40707d5add7 100644
--- a/source/blender/editors/space_file/space_file.c
+++ b/source/blender/editors/space_file/space_file.c
@@ -49,6 +49,7 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "ED_space_api.h"
#include "ED_screen.h"
@@ -67,7 +68,7 @@
/* ******************** default callbacks for file space ***************** */
-static SpaceLink *file_new(const bContext *UNUSED(C))
+static SpaceLink *file_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceFile *sfile;
@@ -291,11 +292,13 @@ static void file_refresh(const bContext *C, ScrArea *sa)
file_tools_region(sa);
ED_area_initialize(wm, CTX_wm_window(C), sa);
- ED_area_tag_redraw(sa);
}
+
+ ED_area_tag_redraw(sa);
}
-static void file_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void file_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
SpaceFile *sfile = (SpaceFile *)sa->spacedata.first;
@@ -305,16 +308,13 @@ static void file_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
switch (wmn->data) {
case ND_SPACE_FILE_LIST:
ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
break;
case ND_SPACE_FILE_PARAMS:
ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
break;
case ND_SPACE_FILE_PREVIEW:
if (sfile->files && filelist_cache_previews_update(sfile->files)) {
ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
}
break;
}
@@ -337,7 +337,9 @@ static void file_main_region_init(wmWindowManager *wm, ARegion *ar)
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
}
-static void file_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void file_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -354,6 +356,42 @@ static void file_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa),
}
}
+static void file_main_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *UNUSED(scene),
+ struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ SpaceFile *sfile = sa->spacedata.first;
+ FileSelectParams *params = ED_fileselect_get_params(sfile);
+ /* This is a bit odd that a region owns the subscriber for an area,
+ * keep for now since all subscribers for WM are regions.
+ * May be worth re-visiting later. */
+ wmMsgSubscribeValue msg_sub_value_area_tag_refresh = {
+ .owner = ar,
+ .user_data = sa,
+ .notify = ED_area_do_msg_notify_tag_refresh,
+ };
+
+ /* SpaceFile itself. */
+ {
+ PointerRNA ptr;
+ RNA_pointer_create(&screen->id, &RNA_SpaceFileBrowser, sfile, &ptr);
+
+ /* All properties for this space type. */
+ WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_area_tag_refresh, __func__);
+ }
+
+ /* FileSelectParams */
+ {
+ PointerRNA ptr;
+ RNA_pointer_create(&screen->id, &RNA_FileSelectParams, params, &ptr);
+
+ /* All properties for this space type. */
+ WM_msg_subscribe_rna(mbus, &ptr, NULL, &msg_sub_value_area_tag_refresh, __func__);
+ }
+}
+
static void file_main_region_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
@@ -601,7 +639,9 @@ static void file_tools_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void file_tools_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
+static void file_tools_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
{
#if 0
/* context changes */
@@ -663,7 +703,9 @@ static void file_ui_region_draw(const bContext *C, ARegion *ar)
UI_view2d_view_restore(C);
}
-static void file_ui_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void file_ui_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -727,6 +769,7 @@ void ED_spacetype_file(void)
art->init = file_main_region_init;
art->draw = file_main_region_draw;
art->listener = file_main_region_listener;
+ art->message_subscribe = file_main_region_message_subscribe;
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D;
BLI_addhead(&st->regiontypes, art);
diff --git a/source/blender/editors/space_graph/CMakeLists.txt b/source/blender/editors/space_graph/CMakeLists.txt
index 40a196fa95b..2840324e65e 100644
--- a/source/blender/editors/space_graph/CMakeLists.txt
+++ b/source/blender/editors/space_graph/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../gpu
../../makesdna
../../makesrna
@@ -48,7 +49,7 @@ set(SRC
)
if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
+ add_definitions(-DWITH_AUDASPACE)
list(APPEND INC_SYS
${AUDASPACE_C_INCLUDE_DIRS}
diff --git a/source/blender/editors/space_graph/graph_buttons.c b/source/blender/editors/space_graph/graph_buttons.c
index 1ada5538fe3..c79652795ac 100644
--- a/source/blender/editors/space_graph/graph_buttons.c
+++ b/source/blender/editors/space_graph/graph_buttons.c
@@ -48,13 +48,13 @@
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_main.h"
#include "BKE_global.h"
#include "BKE_screen.h"
#include "BKE_unit.h"
+#include "DEG_depsgraph_build.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -481,7 +481,7 @@ static void do_graph_region_driver_buttons(bContext *C, void *UNUSED(arg), int e
case B_IPO_DEPCHANGE:
{
/* rebuild depsgraph for the new deps */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
break;
}
}
diff --git a/source/blender/editors/space_graph/graph_draw.c b/source/blender/editors/space_graph/graph_draw.c
index 96a078b2817..26a3f110d36 100644
--- a/source/blender/editors/space_graph/graph_draw.c
+++ b/source/blender/editors/space_graph/graph_draw.c
@@ -46,10 +46,12 @@
#include "BKE_curve.h"
#include "BKE_fcurve.h"
-
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
#include "ED_anim_api.h"
#include "graph_intern.h"
@@ -82,38 +84,59 @@ static void draw_fcurve_modifier_controls_envelope(FModifier *fcm, View2D *v2d)
FCM_EnvelopeData *fed;
const float fac = 0.05f * BLI_rctf_size_x(&v2d->cur);
int i;
-
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ glLineWidth(1.0f);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* Simple dashes. */
+ immUniformColor3f(0.0f, 0.0f, 0.0f);
+ immUniform1f("dash_width", 10.0f);
+ immUniform1f("dash_factor", 0.5f);
+
/* draw two black lines showing the standard reference levels */
- glColor3f(0.0f, 0.0f, 0.0f);
- glLineWidth(1);
- setlinestyle(5);
-
- glBegin(GL_LINES);
- glVertex2f(v2d->cur.xmin, env->midval + env->min);
- glVertex2f(v2d->cur.xmax, env->midval + env->min);
-
- glVertex2f(v2d->cur.xmin, env->midval + env->max);
- glVertex2f(v2d->cur.xmax, env->midval + env->max);
- glEnd();
- setlinestyle(0);
-
- /* set size of vertices (non-adjustable for now) */
- glPointSize(2.0f);
-
- /* for now, point color is fixed, and is white */
- glColor3f(1.0f, 1.0f, 1.0f);
-
- glBegin(GL_POINTS);
- for (i = 0, fed = env->data; i < env->totvert; i++, fed++) {
- /* only draw if visible
- * - min/max here are fixed, not relative
- */
- if (IN_RANGE(fed->time, (v2d->cur.xmin - fac), (v2d->cur.xmax + fac))) {
- glVertex2f(fed->time, fed->min);
- glVertex2f(fed->time, fed->max);
+
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(shdr_pos, v2d->cur.xmin, env->midval + env->min);
+ immVertex2f(shdr_pos, v2d->cur.xmax, env->midval + env->min);
+
+ immVertex2f(shdr_pos, v2d->cur.xmin, env->midval + env->max);
+ immVertex2f(shdr_pos, v2d->cur.xmax, env->midval + env->max);
+ immEnd();
+
+ immUnbindProgram();
+
+ if (env->totvert > 0) {
+ /* set size of vertices (non-adjustable for now) */
+ glPointSize(2.0f);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* for now, point color is fixed, and is white */
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
+
+ immBeginAtMost(GWN_PRIM_POINTS, env->totvert * 2);
+
+ for (i = 0, fed = env->data; i < env->totvert; i++, fed++) {
+ /* only draw if visible
+ * - min/max here are fixed, not relative
+ */
+ if (IN_RANGE(fed->time, (v2d->cur.xmin - fac), (v2d->cur.xmax + fac))) {
+ immVertex2f(shdr_pos, fed->time, fed->min);
+ immVertex2f(shdr_pos, fed->time, fed->max);
+ }
}
+
+ immEnd();
+
+ immUnbindProgram();
}
- glEnd();
}
/* *************************** */
@@ -121,16 +144,37 @@ static void draw_fcurve_modifier_controls_envelope(FModifier *fcm, View2D *v2d)
/* Points ---------------- */
-/* helper func - draw keyframe vertices only for an F-Curve */
-static void draw_fcurve_vertices_keyframes(FCurve *fcu, SpaceIpo *UNUSED(sipo), View2D *v2d, short edit, short sel)
+/* helper func - set color to draw F-Curve data with */
+static void set_fcurve_vertex_color(FCurve *fcu, bool sel)
+{
+ /* Fade the 'intensity' of the vertices based on the selection of the curves too */
+ int alphaOffset = (int)((fcurve_display_alpha(fcu) - 1.0f) * 255);
+
+ float color[4];
+
+ /* Set color of curve vertex based on state of curve (i.e. 'Edit' Mode) */
+ if ((fcu->flag & FCURVE_PROTECTED) == 0) {
+ /* Curve's points ARE BEING edited */
+ UI_GetThemeColorShadeAlpha4fv(sel ? TH_VERTEX_SELECT : TH_VERTEX, 0, alphaOffset, color);
+ }
+ else {
+ /* Curve's points CANNOT BE edited */
+ UI_GetThemeColorShadeAlpha4fv(sel ? TH_TEXT_HI : TH_TEXT, 0, alphaOffset, color);
+ }
+
+ immUniformColor4fv(color);
+}
+
+static void draw_fcurve_selected_keyframe_vertices(FCurve *fcu, View2D *v2d, bool edit, bool sel, unsigned pos)
{
- BezTriple *bezt = fcu->bezt;
const float fac = 0.05f * BLI_rctf_size_x(&v2d->cur);
- int i;
-
- glBegin(GL_POINTS);
-
- for (i = 0; i < fcu->totvert; i++, bezt++) {
+
+ set_fcurve_vertex_color(fcu, sel);
+
+ immBeginAtMost(GWN_PRIM_POINTS, fcu->totvert);
+
+ BezTriple *bezt = fcu->bezt;
+ for (int i = 0; i < fcu->totvert; i++, bezt++) {
/* as an optimization step, only draw those in view
* - we apply a correction factor to ensure that points don't pop in/out due to slight twitches of view size
*/
@@ -141,80 +185,50 @@ static void draw_fcurve_vertices_keyframes(FCurve *fcu, SpaceIpo *UNUSED(sipo),
* -
*/
if ((bezt->f2 & SELECT) == sel)
- glVertex3fv(bezt->vec[1]);
+ immVertex2fv(pos, bezt->vec[1]);
}
else {
/* no check for selection here, as curve is not editable... */
/* XXX perhaps we don't want to even draw points? maybe add an option for that later */
- glVertex3fv(bezt->vec[1]);
+ immVertex2fv(pos, bezt->vec[1]);
}
}
}
-
- glEnd();
-}
+ immEnd();
+}
-/* helper func - draw handle vertex for an F-Curve as a round unfilled circle
- * NOTE: the caller MUST HAVE GL_LINE_SMOOTH & GL_BLEND ENABLED, otherwise, the controls don't
- * have a consistent appearance (due to off-pixel alignments)...
- */
-static void draw_fcurve_handle_control(float x, float y, float xscale, float yscale, float hsize)
+/* helper func - draw keyframe vertices only for an F-Curve */
+static void draw_fcurve_keyframe_vertices(FCurve *fcu, View2D *v2d, bool edit, unsigned pos)
{
- static GLuint displist = 0;
-
- /* initialize round circle shape */
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
- gluDisk(qobj, 0, 0.7, 8, 1);
- gluDeleteQuadric(qobj);
-
- glEndList();
- }
-
- /* adjust view transform before starting */
- glTranslatef(x, y, 0.0f);
- glScalef(1.0f / xscale * hsize, 1.0f / yscale * hsize, 1.0f);
-
- /* draw! */
- glCallList(displist);
-
- /* restore view transform */
- glScalef(xscale / hsize, yscale / hsize, 1.0);
- glTranslatef(-x, -y, 0.0f);
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA);
+
+ immUniform1f("size", UI_GetThemeValuef(TH_VERTEX_SIZE) * U.pixelsize);
+
+ draw_fcurve_selected_keyframe_vertices(fcu, v2d, edit, false, pos);
+ draw_fcurve_selected_keyframe_vertices(fcu, v2d, edit, true, pos);
+
+ immUnbindProgram();
}
+
/* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
-static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2d, short sel, short sel_handle_only, float units_scale)
+static void draw_fcurve_selected_handle_vertices(FCurve *fcu, View2D *v2d, bool sel, bool sel_handle_only, unsigned pos)
{
- BezTriple *bezt = fcu->bezt;
- BezTriple *prevbezt = NULL;
- float hsize, xscale, yscale;
- int i;
-
- /* get view settings */
- hsize = UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE) * U.pixelsize;
- UI_view2d_scale_get(v2d, &xscale, &yscale);
+ (void) v2d; /* TODO: use this to draw only points in view */
- /* Compensate OGL scale sued for unit mapping, so circle will be circle, not ellipse */
- yscale *= units_scale;
-
/* set handle color */
- if (sel) UI_ThemeColor(TH_HANDLE_VERTEX_SELECT);
- else UI_ThemeColor(TH_HANDLE_VERTEX);
-
- /* anti-aliased lines for more consistent appearance */
- if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
-
- for (i = 0; i < fcu->totvert; i++, prevbezt = bezt, bezt++) {
- /* Draw the editmode handles for a bezier curve (others don't have handles)
+ float hcolor[3];
+ UI_GetThemeColor3fv(sel ? TH_HANDLE_VERTEX_SELECT : TH_HANDLE_VERTEX, hcolor);
+ immUniform4f("outlineColor", hcolor[0], hcolor[1], hcolor[2], 1.0f);
+ immUniformColor3fvAlpha(hcolor, 0.01f); /* almost invisible - only keep for smoothness */
+
+ immBeginAtMost(GWN_PRIM_POINTS, fcu->totvert * 2);
+
+ BezTriple *bezt = fcu->bezt;
+ BezTriple *prevbezt = NULL;
+ for (int i = 0; i < fcu->totvert; i++, prevbezt = bezt, bezt++) {
+ /* Draw the editmode handles for a bezier curve (others don't have handles)
* if their selection status matches the selection status we're drawing for
* - first handle only if previous beztriple was bezier-mode
* - second handle only if current beztriple is bezier-mode
@@ -225,68 +239,61 @@ static void draw_fcurve_vertices_handles(FCurve *fcu, SpaceIpo *sipo, View2D *v2
if (!sel_handle_only || BEZT_ISSEL_ANY(bezt)) {
if ((!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) {
if ((bezt->f1 & SELECT) == sel) /* && v2d->cur.xmin < bezt->vec[0][0] < v2d->cur.xmax)*/
- draw_fcurve_handle_control(bezt->vec[0][0], bezt->vec[0][1], xscale, yscale, hsize);
+ immVertex2fv(pos, bezt->vec[0]);
}
-
+
if (bezt->ipo == BEZT_IPO_BEZ) {
if ((bezt->f3 & SELECT) == sel) /* && v2d->cur.xmin < bezt->vec[2][0] < v2d->cur.xmax)*/
- draw_fcurve_handle_control(bezt->vec[2][0], bezt->vec[2][1], xscale, yscale, hsize);
+ immVertex2fv(pos, bezt->vec[2]);
}
}
}
-
- if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
+
+ immEnd();
}
-/* helper func - set color to draw F-Curve data with */
-static void set_fcurve_vertex_color(FCurve *fcu, short sel)
+/* helper func - draw handle vertices only for an F-Curve (if it is not protected) */
+static void draw_fcurve_handle_vertices(FCurve *fcu, View2D *v2d, bool sel_handle_only, unsigned pos)
{
- /* Fade the 'intensity' of the vertices based on the selection of the curves too */
- int alphaOffset = (int)((fcurve_display_alpha(fcu) - 1.0f) * 255);
-
- /* Set color of curve vertex based on state of curve (i.e. 'Edit' Mode) */
- if ((fcu->flag & FCURVE_PROTECTED) == 0) {
- /* Curve's points ARE BEING edited */
- if (sel) UI_ThemeColorShadeAlpha(TH_VERTEX_SELECT, 0, alphaOffset);
- else UI_ThemeColorShadeAlpha(TH_VERTEX, 0, alphaOffset);
- }
- else {
- /* Curve's points CANNOT BE edited */
- if (sel) UI_ThemeColorShadeAlpha(TH_TEXT_HI, 0, alphaOffset);
- else UI_ThemeColorShadeAlpha(TH_TEXT, 0, alphaOffset);
- }
+ /* smooth outlines for more consistent appearance */
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA);
+
+ /* set handle size */
+ immUniform1f("size", (1.4f * UI_GetThemeValuef(TH_HANDLE_VERTEX_SIZE)) * U.pixelsize);
+ immUniform1f("outlineWidth", 1.5f * U.pixelsize);
+
+ draw_fcurve_selected_handle_vertices(fcu, v2d, false, sel_handle_only, pos);
+ draw_fcurve_selected_handle_vertices(fcu, v2d, true, sel_handle_only, pos);
+
+ immUnbindProgram();
}
-static void draw_fcurve_vertices(SpaceIpo *sipo, ARegion *ar, FCurve *fcu, short do_handles, short sel_handle_only, float units_scale)
+static void draw_fcurve_vertices(ARegion *ar, FCurve *fcu, bool do_handles, bool sel_handle_only)
{
View2D *v2d = &ar->v2d;
-
+
/* only draw points if curve is visible
- * - draw unselected points before selected points as separate passes to minimize color-changing overhead
- * (XXX dunno if this is faster than drawing all in one pass though)
- * and also to make sure in the case of overlapping points that the selected is always visible
+ * - draw unselected points before selected points as separate passes
+ * to make sure in the case of overlapping points that the selected is always visible
* - draw handles before keyframes, so that keyframes will overlap handles (keyframes are more important for users)
*/
-
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ glEnable(GL_BLEND);
+ GPU_enable_program_point_size();
+
/* draw the two handles first (if they're shown, the curve doesn't have just a single keyframe, and the curve is being edited) */
if (do_handles) {
- set_fcurve_vertex_color(fcu, 0);
- draw_fcurve_vertices_handles(fcu, sipo, v2d, 0, sel_handle_only, units_scale);
-
- set_fcurve_vertex_color(fcu, 1);
- draw_fcurve_vertices_handles(fcu, sipo, v2d, 1, sel_handle_only, units_scale);
+ draw_fcurve_handle_vertices(fcu, v2d, sel_handle_only, pos);
}
-
+
/* draw keyframes over the handles */
- set_fcurve_vertex_color(fcu, 0);
- draw_fcurve_vertices_keyframes(fcu, sipo, v2d, !(fcu->flag & FCURVE_PROTECTED), 0);
-
- set_fcurve_vertex_color(fcu, 1);
- draw_fcurve_vertices_keyframes(fcu, sipo, v2d, !(fcu->flag & FCURVE_PROTECTED), 1);
+ draw_fcurve_keyframe_vertices(fcu, v2d, !(fcu->flag & FCURVE_PROTECTED), pos);
+
+ GPU_disable_program_point_size();
+ glDisable(GL_BLEND);
}
/* Handles ---------------- */
@@ -303,10 +310,10 @@ static bool draw_fcurve_handles_check(SpaceIpo *sipo, FCurve *fcu)
(fcu->totvert <= 1) /* do not show handles if there is only 1 keyframe, otherwise they all clump together in an ugly ball */
)
{
- return 0;
+ return false;
}
else {
- return 1;
+ return true;
}
}
@@ -315,13 +322,14 @@ static bool draw_fcurve_handles_check(SpaceIpo *sipo, FCurve *fcu)
static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu)
{
int sel, b;
-
- /* a single call to GL_LINES here around these calls should be sufficient to still
- * get separate line segments, but which aren't wrapped with GL_LINE_STRIP every time we
- * want a single line
- */
- glBegin(GL_LINES);
-
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ immBeginAtMost(GWN_PRIM_LINES, 4 * 2 * fcu->totvert);
+
/* slightly hacky, but we want to draw unselected points before selected ones
* so that selected points are clearly visible
*/
@@ -330,7 +338,7 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu)
int basecol = (sel) ? TH_HANDLE_SEL_FREE : TH_HANDLE_FREE;
const float *fp;
unsigned char col[4];
-
+
for (b = 0; b < fcu->totvert; b++, prevbezt = bezt, bezt++) {
/* if only selected keyframes can get their handles shown,
* check that keyframe is selected
@@ -348,18 +356,20 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu)
if ((!prevbezt && (bezt->ipo == BEZT_IPO_BEZ)) || (prevbezt && (prevbezt->ipo == BEZT_IPO_BEZ))) {
UI_GetThemeColor3ubv(basecol + bezt->h1, col);
col[3] = fcurve_display_alpha(fcu) * 255;
- glColor4ubv((GLubyte *)col);
-
- glVertex2fv(fp); glVertex2fv(fp + 3);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp + 3);
}
/* only draw second handle if this segment is bezier */
if (bezt->ipo == BEZT_IPO_BEZ) {
UI_GetThemeColor3ubv(basecol + bezt->h2, col);
col[3] = fcurve_display_alpha(fcu) * 255;
- glColor4ubv((GLubyte *)col);
-
- glVertex2fv(fp + 3); glVertex2fv(fp + 6);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp + 3);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp + 6);
}
}
else {
@@ -370,9 +380,10 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu)
fp = bezt->vec[0];
UI_GetThemeColor3ubv(basecol + bezt->h1, col);
col[3] = fcurve_display_alpha(fcu) * 255;
- glColor4ubv((GLubyte *)col);
-
- glVertex2fv(fp); glVertex2fv(fp + 3);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp + 3);
}
/* only draw second handle if this segment is bezier, and selection is ok */
@@ -382,15 +393,17 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu)
fp = bezt->vec[1];
UI_GetThemeColor3ubv(basecol + bezt->h2, col);
col[3] = fcurve_display_alpha(fcu) * 255;
- glColor4ubv((GLubyte *)col);
-
- glVertex2fv(fp); glVertex2fv(fp + 3);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp);
+ immAttrib4ubv(color, col);
+ immVertex2fv(pos, fp + 3);
}
}
}
}
-
- glEnd(); /* GL_LINES */
+
+ immEnd();
+ immUnbindProgram();
}
/* Samples ---------------- */
@@ -399,36 +412,24 @@ static void draw_fcurve_handles(SpaceIpo *sipo, FCurve *fcu)
* NOTE: the caller MUST HAVE GL_LINE_SMOOTH & GL_BLEND ENABLED, otherwise, the controls don't
* have a consistent appearance (due to off-pixel alignments)...
*/
-static void draw_fcurve_sample_control(float x, float y, float xscale, float yscale, float hsize)
+static void draw_fcurve_sample_control(float x, float y, float xscale, float yscale, float hsize, unsigned int pos)
{
- static GLuint displist = 0;
-
- /* initialize X shape */
- if (displist == 0) {
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- glBegin(GL_LINES);
- glVertex2f(-0.7f, -0.7f);
- glVertex2f(+0.7f, +0.7f);
-
- glVertex2f(-0.7f, +0.7f);
- glVertex2f(+0.7f, -0.7f);
- glEnd(); /* GL_LINES */
-
- glEndList();
- }
-
/* adjust view transform before starting */
- glTranslatef(x, y, 0.0f);
- glScalef(1.0f / xscale * hsize, 1.0f / yscale * hsize, 1.0f);
-
- /* draw! */
- glCallList(displist);
-
+ gpuPushMatrix();
+ gpuTranslate2f(x, y);
+ gpuScale2f(1.0f / xscale * hsize, 1.0f / yscale * hsize);
+
+ /* draw X shape */
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, -0.7f, -0.7f);
+ immVertex2f(pos, +0.7f, +0.7f);
+
+ immVertex2f(pos, -0.7f, +0.7f);
+ immVertex2f(pos, +0.7f, -0.7f);
+ immEnd();
+
/* restore view transform */
- glScalef(xscale / hsize, yscale / hsize, 1.0);
- glTranslatef(-x, -y, 0.0f);
+ gpuPopMatrix();
}
/* helper func - draw keyframe vertices only for an F-Curve */
@@ -441,10 +442,6 @@ static void draw_fcurve_samples(SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
hsize = UI_GetThemeValuef(TH_VERTEX_SIZE);
UI_view2d_scale_get(&ar->v2d, &xscale, &yscale);
- /* set vertex color */
- if (fcu->flag & (FCURVE_ACTIVE | FCURVE_SELECTED)) UI_ThemeColor(TH_TEXT_HI);
- else UI_ThemeColor(TH_TEXT);
-
/* get verts */
first = fcu->fpt;
last = (first) ? (first + (fcu->totvert - 1)) : (NULL);
@@ -454,10 +451,17 @@ static void draw_fcurve_samples(SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
/* anti-aliased lines for more consistent appearance */
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
-
- draw_fcurve_sample_control(first->vec[0], first->vec[1], xscale, yscale, hsize);
- draw_fcurve_sample_control(last->vec[0], last->vec[1], xscale, yscale, hsize);
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColor((fcu->flag & FCURVE_SELECTED) ? TH_TEXT_HI : TH_TEXT);
+
+ draw_fcurve_sample_control(first->vec[0], first->vec[1], xscale, yscale, hsize, pos);
+ draw_fcurve_sample_control(last->vec[0], last->vec[1], xscale, yscale, hsize, pos);
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glDisable(GL_LINE_SMOOTH);
}
@@ -466,7 +470,7 @@ static void draw_fcurve_samples(SpaceIpo *sipo, ARegion *ar, FCurve *fcu)
/* Curve ---------------- */
/* helper func - just draw the F-Curve by sampling the visible region (for drawing curves with modifiers) */
-static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid)
+static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, View2DGrid *grid, unsigned int pos)
{
SpaceIpo *sipo = (SpaceIpo *)ac->sl;
ChannelDriver *driver;
@@ -536,37 +540,50 @@ static void draw_fcurve_curve(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d
* - apply the unit correction factor to the calculated values so that
* the displayed values appear correctly in the viewport
*/
- glBegin(GL_LINE_STRIP);
-
+
n = (etime - stime) / samplefreq + 0.5f;
- for (i = 0; i <= n; i++) {
- float ctime = stime + i * samplefreq;
- glVertex2f(ctime, (evaluate_fcurve(fcu, ctime) + offset) * unitFac);
+
+ if (n > 0) {
+ immBegin(GWN_PRIM_LINE_STRIP, (n + 1));
+
+ for (i = 0; i <= n; i++) {
+ float ctime = stime + i * samplefreq;
+ immVertex2f(pos, ctime, (evaluate_fcurve(fcu, ctime) + offset) * unitFac);
+ }
+
+ immEnd();
}
-
- glEnd();
-
+
/* restore driver */
fcu->driver = driver;
}
/* helper func - draw a samples-based F-Curve */
-static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d)
+static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, const uint shdr_pos)
{
FPoint *prevfpt = fcu->fpt;
FPoint *fpt = prevfpt + 1;
float fac, v[2];
- int b = fcu->totvert - 1;
+ int b = fcu->totvert;
float unit_scale, offset;
short mapping_flag = ANIM_get_normalization_flags(ac);
+ int count = fcu->totvert;
+
+ if (prevfpt->vec[0] > v2d->cur.xmin) {
+ count++;
+ }
+
+ if ((prevfpt + b - 1)->vec[0] < v2d->cur.xmax) {
+ count++;
+ }
/* apply unit mapping */
- glPushMatrix();
+ gpuPushMatrix();
unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
- glScalef(1.0f, unit_scale, 1.0f);
- glTranslatef(0.0f, offset, 0.0f);
+ gpuScale2f(1.0f, unit_scale);
+ gpuTranslate2f(0.0f, offset);
- glBegin(GL_LINE_STRIP);
+ immBegin(GWN_PRIM_LINE_STRIP, count);
/* extrapolate to left? - left-side of view comes before first keyframe? */
if (prevfpt->vec[0] > v2d->cur.xmin) {
@@ -584,26 +601,19 @@ static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, Vie
v[1] = prevfpt->vec[1] - fac * (prevfpt->vec[1] - fpt->vec[1]);
}
- glVertex2fv(v);
+ immVertex2fv(shdr_pos, v);
}
- /* if only one sample, add it now */
- if (fcu->totvert == 1)
- glVertex2fv(prevfpt->vec);
-
/* loop over samples, drawing segments */
/* draw curve between first and last keyframe (if there are enough to do so) */
while (b--) {
/* Linear interpolation: just add one point (which should add a new line segment) */
- glVertex2fv(prevfpt->vec);
+ immVertex2fv(shdr_pos, prevfpt->vec);
/* get next pointers */
- prevfpt = fpt;
- fpt++;
-
- /* last point? */
- if (b == 0)
- glVertex2fv(prevfpt->vec);
+ if (b > 0) {
+ prevfpt++;
+ }
}
/* extrapolate to right? (see code for left-extrapolation above too) */
@@ -623,11 +633,12 @@ static void draw_fcurve_curve_samples(bAnimContext *ac, ID *id, FCurve *fcu, Vie
v[1] = prevfpt->vec[1] - fac * (prevfpt->vec[1] - fpt->vec[1]);
}
- glVertex2fv(v);
+ immVertex2fv(shdr_pos, v);
}
- glEnd();
- glPopMatrix();
+ immEnd();
+
+ gpuPopMatrix();
}
/* helper func - check if the F-Curve only contains easily drawable segments
@@ -648,7 +659,7 @@ static bool fcurve_can_use_simple_bezt_drawing(FCurve *fcu)
}
/* helper func - draw one repeat of an F-Curve (using Bezier curve approximations) */
-static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d)
+static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2D *v2d, unsigned int pos)
{
BezTriple *prevbezt = fcu->bezt;
BezTriple *bezt = prevbezt + 1;
@@ -661,12 +672,15 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
short mapping_flag = ANIM_get_normalization_flags(ac);
/* apply unit mapping */
- glPushMatrix();
+ gpuPushMatrix();
unit_scale = ANIM_unit_mapping_get_factor(ac->scene, id, fcu, mapping_flag, &offset);
- glScalef(1.0f, unit_scale, 1.0f);
- glTranslatef(0.0f, offset, 0.0f);
+ gpuScale2f(1.0f, unit_scale);
+ gpuTranslate2f(0.0f, offset);
- glBegin(GL_LINE_STRIP);
+ /* For now, this assumes the worst case scenario, where all the keyframes have
+ * bezier interpolation, and are drawn at full res.
+ * This is tricky to optimize, but maybe can be improved at some point... */
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, (b * 32 + 3));
/* extrapolate to left? */
if (prevbezt->vec[1][0] > v2d->cur.xmin) {
@@ -691,14 +705,14 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[0][1] - prevbezt->vec[1][1]);
}
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
}
/* if only one keyframe, add it now */
if (fcu->totvert == 1) {
v1[0] = prevbezt->vec[1][0];
v1[1] = prevbezt->vec[1][1];
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
}
/* draw curve between first and last keyframe (if there are enough to do so) */
@@ -708,17 +722,17 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
/* Constant-Interpolation: draw segment between previous keyframe and next, but holding same value */
v1[0] = prevbezt->vec[1][0];
v1[1] = prevbezt->vec[1][1];
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
v1[0] = bezt->vec[1][0];
v1[1] = prevbezt->vec[1][1];
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
}
else if (prevbezt->ipo == BEZT_IPO_LIN) {
/* Linear interpolation: just add one point (which should add a new line segment) */
v1[0] = prevbezt->vec[1][0];
v1[1] = prevbezt->vec[1][1];
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
}
else if (prevbezt->ipo == BEZT_IPO_BEZ) {
/* Bezier-Interpolation: draw curve as series of segments between keyframes
@@ -738,7 +752,7 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
/* only draw one */
v1[0] = prevbezt->vec[1][0];
v1[1] = prevbezt->vec[1][1];
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
}
else {
/* clamp resolution to max of 32 */
@@ -760,8 +774,9 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
BKE_curve_forward_diff_bezier(v1[0], v2[0], v3[0], v4[0], data, resol, sizeof(float) * 3);
BKE_curve_forward_diff_bezier(v1[1], v2[1], v3[1], v4[1], data + 1, resol, sizeof(float) * 3);
- for (fp = data; resol; resol--, fp += 3)
- glVertex2fv(fp);
+ for (fp = data; resol; resol--, fp += 3) {
+ immVertex2fv(pos, fp);
+ }
}
}
@@ -773,7 +788,7 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
if (b == 0) {
v1[0] = prevbezt->vec[1][0];
v1[1] = prevbezt->vec[1][1];
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
}
}
@@ -800,11 +815,12 @@ static void draw_fcurve_curve_bezts(bAnimContext *ac, ID *id, FCurve *fcu, View2
v1[1] = prevbezt->vec[1][1] - fac * (prevbezt->vec[2][1] - prevbezt->vec[1][1]);
}
- glVertex2fv(v1);
+ immVertex2fv(pos, v1);
}
- glEnd();
- glPopMatrix();
+ immEnd();
+
+ gpuPopMatrix();
}
/* Debugging -------------------------------- */
@@ -825,7 +841,16 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
/* for now, only show when debugging driver... */
//if ((driver->flag & DRIVER_FLAG_SHOWDEBUG) == 0)
// return;
-
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* Simple dashes. */
+
/* No curve to modify/visualize the result?
* => We still want to show the 1-1 default...
*/
@@ -833,26 +858,24 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
float t;
/* draw with thin dotted lines in style of what curve would have been */
- glColor3fv(fcu->color);
+ immUniformColor3fv(fcu->color);
- setlinestyle(20);
+ immUniform1f("dash_width", 40.0f);
+ immUniform1f("dash_factor", 0.5f);
glLineWidth(2.0f);
/* draw 1-1 line, stretching just past the screen limits
* NOTE: we need to scale the y-values to be valid for the units
*/
- glBegin(GL_LINES);
- {
- t = v2d->cur.xmin;
- glVertex2f(t, (t + offset) * unitfac);
-
- t = v2d->cur.xmax;
- glVertex2f(t, (t + offset) * unitfac);
- }
- glEnd();
-
- /* cleanup line drawing */
- setlinestyle(0);
+ immBegin(GWN_PRIM_LINES, 2);
+
+ t = v2d->cur.xmin;
+ immVertex2f(shdr_pos, t, (t + offset) * unitfac);
+
+ t = v2d->cur.xmax;
+ immVertex2f(shdr_pos, t, (t + offset) * unitfac);
+
+ immEnd();
}
/* draw driver only if actually functional */
@@ -866,53 +889,59 @@ static void graph_draw_driver_debug(bAnimContext *ac, ID *id, FCurve *fcu)
float co[2];
/* draw dotted lines leading towards this point from both axes ....... */
- glColor3f(0.9f, 0.9f, 0.9f);
- setlinestyle(5);
-
- glBegin(GL_LINES);
- {
- /* x-axis lookup */
- co[0] = x;
-
- if (y >= v2d->cur.ymin) {
- co[1] = v2d->cur.ymin - 1.0f;
- glVertex2fv(co);
-
- co[1] = y;
- glVertex2fv(co);
- }
-
- /* y-axis lookup */
+ immUniformColor3f(0.9f, 0.9f, 0.9f);
+ immUniform1f("dash_width", 10.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ immBegin(GWN_PRIM_LINES, (y >= v2d->cur.ymin) ? 4 : 2);
+
+ /* x-axis lookup */
+ co[0] = x;
+
+ if (y >= v2d->cur.ymin) {
+ co[1] = v2d->cur.ymin - 1.0f;
+ immVertex2fv(shdr_pos, co);
+
co[1] = y;
-
- co[0] = v2d->cur.xmin - 1.0f;
- glVertex2fv(co);
-
- co[0] = x;
- glVertex2fv(co);
+ immVertex2fv(shdr_pos, co);
}
- glEnd();
-
- setlinestyle(0);
+
+ /* y-axis lookup */
+ co[1] = y;
+
+ co[0] = v2d->cur.xmin - 1.0f;
+ immVertex2fv(shdr_pos, co);
+
+ co[0] = x;
+ immVertex2fv(shdr_pos, co);
+
+ immEnd();
+ immUnbindProgram();
+
+ /* GWN_PRIM_POINTS do not survive dashed line geometry shader... */
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* x marks the spot .................................................... */
/* -> outer frame */
- glColor3f(0.9f, 0.9f, 0.9f);
+ immUniformColor3f(0.9f, 0.9f, 0.9f);
glPointSize(7.0);
- glBegin(GL_POINTS);
- glVertex2f(x, y);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2f(shdr_pos, x, y);
+ immEnd();
/* inner frame */
- glColor3f(0.9f, 0.0f, 0.0f);
+ immUniformColor3f(0.9f, 0.0f, 0.0f);
glPointSize(3.0);
- glBegin(GL_POINTS);
- glVertex2f(x, y);
- glEnd();
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex2f(shdr_pos, x, y);
+ immEnd();
}
}
+
+ immUnbindProgram();
}
/* Public Curve-Drawing API ---------------- */
@@ -925,29 +954,43 @@ void graph_draw_ghost_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar)
FCurve *fcu;
/* draw with thick dotted lines */
- setlinestyle(10);
glLineWidth(3.0f);
/* anti-aliased lines for less jagged appearance */
- if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glEnable(GL_LINE_SMOOTH);
+ if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
+ glEnable(GL_LINE_SMOOTH);
+ }
glEnable(GL_BLEND);
-
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* Simple dashes. */
+ immUniform1f("dash_width", 20.0f);
+ immUniform1f("dash_factor", 0.5f);
+
/* the ghost curves are simply sampled F-Curves stored in sipo->ghostCurves */
for (fcu = sipo->ghostCurves.first; fcu; fcu = fcu->next) {
/* set whatever color the curve has set
* - this is set by the function which creates these
* - draw with a fixed opacity of 2
*/
- glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], 0.5f);
+ immUniformColor3fvAlpha(fcu->color, 0.5f);
/* simply draw the stored samples */
- draw_fcurve_curve_samples(ac, NULL, fcu, &ar->v2d);
+ draw_fcurve_curve_samples(ac, NULL, fcu, &ar->v2d, shdr_pos);
+ }
+
+ immUnbindProgram();
+
+ if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
+ glDisable(GL_LINE_SMOOTH);
}
-
- /* restore settings */
- setlinestyle(0);
-
- if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
@@ -975,9 +1018,10 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid
AnimData *adt = ANIM_nla_mapping_get(ac, ale);
/* map keyframes for drawing if scaled F-Curve */
- if (adt)
- ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0);
-
+ if (adt) {
+ ANIM_nla_mapping_apply_fcurve(adt, ale->key_data, 0, 0);
+ }
+
/* draw curve:
* - curve line may be result of one or more destructive modifiers or just the raw data,
* so we need to check which method should be used
@@ -986,60 +1030,82 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid
*/
/* 1) draw curve line */
+ if (((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) ||
+ (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)))
{
/* set color/drawing style for curve itself */
+ /* draw active F-Curve thicker than the rest to make it stand out */
+ if (fcu->flag & FCURVE_ACTIVE) {
+ glLineWidth(2.5);
+ }
+ else {
+ glLineWidth(1.0);
+ }
+
+ /* anti-aliased lines for less jagged appearance */
+ if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
+ glEnable(GL_LINE_SMOOTH);
+ }
+ glEnable(GL_BLEND);
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* Simple dashes. */
+
if (BKE_fcurve_is_protected(fcu)) {
/* protected curves (non editable) are drawn with dotted lines */
- setlinestyle(2);
+ immUniform1f("dash_width", 4.0f);
+ immUniform1f("dash_factor", 0.5f);
+ }
+ else {
+ immUniform1f("dash_factor", 2.0f); /* solid line */
}
+
if (((fcu->grp) && (fcu->grp->flag & AGRP_MUTED)) || (fcu->flag & FCURVE_MUTED)) {
/* muted curves are drawn in a grayish hue */
/* XXX should we have some variations? */
- UI_ThemeColorShade(TH_HEADER, 50);
+ immUniformThemeColorShade(TH_HEADER, 50);
}
else {
- /* set whatever color the curve has set
+ /* set whatever color the curve has set
* - unselected curves draw less opaque to help distinguish the selected ones
*/
- glColor4f(fcu->color[0], fcu->color[1], fcu->color[2], fcurve_display_alpha(fcu));
- }
-
- /* draw active F-Curve thicker than the rest to make it stand out */
- if (fcu->flag & FCURVE_ACTIVE) {
- glLineWidth(2.0);
- }
- else {
- glLineWidth(1.0);
+ immUniformColor3fvAlpha(fcu->color, fcurve_display_alpha(fcu));
}
-
- /* anti-aliased lines for less jagged appearance */
- if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glEnable(GL_LINE_SMOOTH);
- glEnable(GL_BLEND);
-
+
/* draw F-Curve */
if ((fcu->modifiers.first) || (fcu->flag & FCURVE_INT_VALUES)) {
/* draw a curve affected by modifiers or only allowed to have integer values
* by sampling it at various small-intervals over the visible region
*/
- draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid);
+ draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid, shdr_pos);
}
else if (((fcu->bezt) || (fcu->fpt)) && (fcu->totvert)) {
/* just draw curve based on defined data (i.e. no modifiers) */
if (fcu->bezt) {
- if (fcurve_can_use_simple_bezt_drawing(fcu))
- draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d);
- else
- draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid);
+ if (fcurve_can_use_simple_bezt_drawing(fcu)) {
+ draw_fcurve_curve_bezts(ac, ale->id, fcu, &ar->v2d, shdr_pos);
+ }
+ else {
+ draw_fcurve_curve(ac, ale->id, fcu, &ar->v2d, grid, shdr_pos);
+ }
}
else if (fcu->fpt) {
- draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d);
+ draw_fcurve_curve_samples(ac, ale->id, fcu, &ar->v2d, shdr_pos);
}
}
-
- /* restore settings */
- setlinestyle(0);
-
- if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) glDisable(GL_LINE_SMOOTH);
+
+ immUnbindProgram();
+
+ if ((sipo->flag & SIPO_BEAUTYDRAW_OFF) == 0) {
+ glDisable(GL_LINE_SMOOTH);
+ }
glDisable(GL_BLEND);
}
@@ -1047,7 +1113,7 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid
* - if the option to only show controls if the F-Curve is selected is enabled, we must obey this
*/
if (!(sipo->flag & SIPO_SELCUVERTSONLY) || (fcu->flag & FCURVE_SELECTED)) {
- if (fcurve_are_keyframes_usable(fcu) == 0) {
+ if (!fcurve_are_keyframes_usable(fcu) && !(fcu->fpt && fcu->totvert)) {
/* only draw controls if this is the active modifier */
if ((fcu->flag & FCURVE_ACTIVE) && (fcm)) {
switch (fcm->type) {
@@ -1063,9 +1129,9 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid
float unit_scale = ANIM_unit_mapping_get_factor(ac->scene, ale->id, fcu, mapping_flag, &offset);
/* apply unit-scaling to all values via OpenGL */
- glPushMatrix();
- glScalef(1.0f, unit_scale, 1.0f);
- glTranslatef(0.0f, offset, 0.0f);
+ gpuPushMatrix();
+ gpuScale2f(1.0f, unit_scale);
+ gpuTranslate2f(0.0f, offset);
/* set this once and for all - all handles and handle-verts should use the same thickness */
glLineWidth(1.0);
@@ -1080,14 +1146,14 @@ void graph_draw_curves(bAnimContext *ac, SpaceIpo *sipo, ARegion *ar, View2DGrid
glDisable(GL_BLEND);
}
- draw_fcurve_vertices(sipo, ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY), unit_scale);
+ draw_fcurve_vertices(ar, fcu, do_handles, (sipo->flag & SIPO_SELVHANDLESONLY));
}
else {
/* samples: only draw two indicators at either end as indicators */
draw_fcurve_samples(sipo, ar, fcu);
}
- glPopMatrix();
+ gpuPopMatrix();
}
}
@@ -1163,7 +1229,7 @@ void graph_draw_channel_names(bContext *C, bAnimContext *ac, ARegion *ar)
y = (float)ACHANNEL_FIRST(ac);
/* set blending again, as may not be set in previous step */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
for (ale = anim_data.first, i = 0; ale; ale = ale->next, i++) {
diff --git a/source/blender/editors/space_graph/graph_edit.c b/source/blender/editors/space_graph/graph_edit.c
index 12d24502ad6..29e3f99e1d4 100644
--- a/source/blender/editors/space_graph/graph_edit.c
+++ b/source/blender/editors/space_graph/graph_edit.c
@@ -36,7 +36,7 @@
#include <float.h>
#ifdef WITH_AUDASPACE
-# include AUD_SPECIAL_H
+# include <AUD_Special.h>
#endif
#include "MEM_guardedalloc.h"
@@ -54,13 +54,14 @@
#include "BLT_translation.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_nla.h"
#include "BKE_context.h"
#include "BKE_report.h"
+#include "DEG_depsgraph_build.h"
+
#include "UI_view2d.h"
#include "ED_anim_api.h"
@@ -2714,7 +2715,7 @@ static int graph_driver_vars_paste_exec(bContext *C, wmOperator *op)
/* successful or not? */
if (ok) {
/* rebuild depsgraph, now that there are extra deps here */
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
/* set notifier that keyframes have changed */
WM_event_add_notifier(C, NC_SCENE | ND_FRAME, CTX_data_scene(C));
@@ -2788,7 +2789,7 @@ static int graph_driver_delete_invalid_exec(bContext *C, wmOperator *op)
if (deleted > 0) {
/* notify the world of any changes */
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_REMOVED, NULL);
WM_reportf(RPT_INFO, "Deleted %u drivers", deleted);
}
diff --git a/source/blender/editors/space_graph/space_graph.c b/source/blender/editors/space_graph/space_graph.c
index 362bd284105..f59d70d97c7 100644
--- a/source/blender/editors/space_graph/space_graph.c
+++ b/source/blender/editors/space_graph/space_graph.c
@@ -53,10 +53,13 @@
#include "ED_anim_api.h"
#include "ED_markers.h"
-#include "BIF_gl.h"
+#include "GPU_immediate.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
+
+#include "RNA_access.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -92,9 +95,8 @@ ARegion *graph_has_buttons_region(ScrArea *sa)
/* ******************** default callbacks for ipo space ***************** */
-static SpaceLink *graph_new(const bContext *C)
+static SpaceLink *graph_new(const ScrArea *UNUSED(sa), const Scene *scene)
{
- Scene *scene = CTX_data_scene(C);
ARegion *ar;
SpaceIpo *sipo;
@@ -226,12 +228,13 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
SpaceIpo *sipo = CTX_wm_space_graph(C);
+ Scene *scene = CTX_data_scene(C);
bAnimContext ac;
View2D *v2d = &ar->v2d;
View2DGrid *grid;
View2DScrollers *scrollers;
float col[3];
- short unitx = 0, unity = V2D_UNIT_VALUES, flag = 0;
+ short unitx = 0, unity = V2D_UNIT_VALUES, cfra_flag = 0;
/* clear and setup matrix */
UI_GetThemeColor3fv(TH_BACK, col);
@@ -246,7 +249,12 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
UI_view2d_grid_draw(v2d, grid, V2D_GRIDLINES_ALL);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
-
+
+ /* start and end frame (in F-Curve mode only) */
+ if (sipo->mode != SIPO_MODE_DRIVERS) {
+ ANIM_draw_framerange(scene, v2d);
+ }
+
/* draw data */
if (ANIM_animdata_get_context(C, &ac)) {
/* draw ghost curves */
@@ -265,47 +273,54 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
/* only free grid after drawing data, as we need to use it to determine sampling rate */
UI_view2d_grid_free(grid);
-
- /* horizontal component of value-cursor (value line before the current frame line) */
- if ((sipo->flag & SIPO_NODRAWCURSOR) == 0) {
- float y = sipo->cursorVal;
-
- /* Draw a green line to indicate the cursor value */
- UI_ThemeColorShadeAlpha(TH_CFRAME, -10, -50);
- glEnable(GL_BLEND);
- glLineWidth(2.0);
+ if (((sipo->flag & SIPO_NODRAWCURSOR) == 0) || (sipo->mode == SIPO_MODE_DRIVERS)) {
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- glBegin(GL_LINES);
- glVertex2f(v2d->cur.xmin, y);
- glVertex2f(v2d->cur.xmax, y);
- glEnd();
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glDisable(GL_BLEND);
- }
-
- /* current frame or vertical component of vertical component of the cursor */
- if (sipo->mode == SIPO_MODE_DRIVERS) {
- /* cursor x-value */
- float x = sipo->cursorTime;
-
- /* to help differentiate this from the current frame, draw slightly darker like the horizontal one */
- UI_ThemeColorShadeAlpha(TH_CFRAME, -40, -50);
- glEnable(GL_BLEND);
- glLineWidth(2.0);
-
- glBegin(GL_LINES);
- glVertex2f(x, v2d->cur.ymin);
- glVertex2f(x, v2d->cur.ymax);
- glEnd();
+ /* horizontal component of value-cursor (value line before the current frame line) */
+ if ((sipo->flag & SIPO_NODRAWCURSOR) == 0) {
+ float y = sipo->cursorVal;
+
+ /* Draw a green line to indicate the cursor value */
+ immUniformThemeColorShadeAlpha(TH_CFRAME, -10, -50);
+ glEnable(GL_BLEND);
+ glLineWidth(2.0);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, v2d->cur.xmin, y);
+ immVertex2f(pos, v2d->cur.xmax, y);
+ immEnd();
+
+ glDisable(GL_BLEND);
+ }
- glDisable(GL_BLEND);
+ /* current frame or vertical component of vertical component of the cursor */
+ if (sipo->mode == SIPO_MODE_DRIVERS) {
+ /* cursor x-value */
+ float x = sipo->cursorTime;
+
+ /* to help differentiate this from the current frame, draw slightly darker like the horizontal one */
+ immUniformThemeColorShadeAlpha(TH_CFRAME, -40, -50);
+ glEnable(GL_BLEND);
+ glLineWidth(2.0);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, x, v2d->cur.ymin);
+ immVertex2f(pos, x, v2d->cur.ymax);
+ immEnd();
+
+ glDisable(GL_BLEND);
+ }
+
+ immUnbindProgram();
}
- else {
+
+ if (sipo->mode != SIPO_MODE_DRIVERS) {
/* current frame */
- if (sipo->flag & SIPO_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
- if ((sipo->flag & SIPO_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
- ANIM_draw_cfra(C, v2d, flag);
+ if (sipo->flag & SIPO_DRAWTIME) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
+ ANIM_draw_cfra(C, v2d, cfra_flag);
}
/* markers */
@@ -328,6 +343,12 @@ static void graph_main_region_draw(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unitx, V2D_GRID_NOCLAMP, unity, V2D_GRID_NOCLAMP);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
+
+ /* draw current frame number-indicator on top of scrollers */
+ if ((sipo->mode != SIPO_MODE_DRIVERS) && ((sipo->flag & SIPO_NODRAWCFRANUM) == 0)) {
+ UI_view2d_view_orthoSpecial(ar, v2d, 1);
+ ANIM_draw_cfra_number(C, v2d, cfra_flag);
+ }
}
static void graph_channel_region_init(wmWindowManager *wm, ARegion *ar)
@@ -404,7 +425,9 @@ static void graph_buttons_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void graph_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void graph_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -416,6 +439,7 @@ static void graph_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), AReg
case ND_RENDER_OPTIONS:
case ND_OB_ACTIVE:
case ND_FRAME:
+ case ND_FRAME_RANGE:
case ND_MARKERS:
ED_region_tag_redraw(ar);
break;
@@ -450,6 +474,11 @@ static void graph_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), AReg
if (wmn->action == NA_RENAME)
ED_region_tag_redraw(ar);
break;
+ case NC_SCREEN:
+ if (ELEM(wmn->data, ND_LAYER)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
default:
if (wmn->data == ND_KEYS)
ED_region_tag_redraw(ar);
@@ -458,8 +487,49 @@ static void graph_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), AReg
}
}
+static void graph_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *scene,
+ struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ PointerRNA ptr;
+ RNA_pointer_create(&screen->id, &RNA_SpaceGraphEditor, sa->spacedata.first, &ptr);
+
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ /* Timeline depends on scene properties. */
+ {
+ bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
+ extern PropertyRNA rna_Scene_frame_start;
+ extern PropertyRNA rna_Scene_frame_end;
+ extern PropertyRNA rna_Scene_frame_preview_start;
+ extern PropertyRNA rna_Scene_frame_preview_end;
+ extern PropertyRNA rna_Scene_use_preview_range;
+ extern PropertyRNA rna_Scene_frame_current;
+ const PropertyRNA *props[] = {
+ use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
+ use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
+ &rna_Scene_use_preview_range,
+ &rna_Scene_frame_current,
+ };
+
+ PointerRNA idptr;
+ RNA_id_pointer_create(&scene->id, &idptr);
+
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ WM_msg_subscribe_rna(mbus, &idptr, props[i], &msg_sub_value_region_tag_redraw, __func__);
+ }
+ }
+}
+
/* editor level listener */
-static void graph_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void graph_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
SpaceIpo *sipo = (SpaceIpo *)sa->spacedata.first;
@@ -718,6 +788,7 @@ void ED_spacetype_ipo(void)
art->init = graph_main_region_init;
art->draw = graph_main_region_draw;
art->listener = graph_region_listener;
+ art->message_subscribe = graph_region_message_subscribe;
art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
BLI_addhead(&st->regiontypes, art);
diff --git a/source/blender/editors/space_image/CMakeLists.txt b/source/blender/editors/space_image/CMakeLists.txt
index c60d194b620..0bc09981ba5 100644
--- a/source/blender/editors/space_image/CMakeLists.txt
+++ b/source/blender/editors/space_image/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
../../blenlib
../../blentranslation
../../bmesh
+ ../../depsgraph
../../imbuf
../../gpu
../../makesdna
diff --git a/source/blender/editors/space_image/image_draw.c b/source/blender/editors/space_image/image_draw.c
index 594938b82aa..fc4d8c39e26 100644
--- a/source/blender/editors/space_image/image_draw.c
+++ b/source/blender/editors/space_image/image_draw.c
@@ -60,9 +60,12 @@
#include "BKE_image.h"
#include "BKE_paint.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+
#include "BLF_api.h"
#include "ED_gpencil.h"
@@ -87,7 +90,6 @@ static void draw_render_info(const bContext *C,
float zoomx,
float zoomy)
{
- RenderResult *rr;
Render *re = RE_GetSceneRender(scene);
RenderData *rd = RE_engine_get_render_data(re);
Scene *stats_scene = ED_render_job_get_scene(C);
@@ -95,7 +97,7 @@ static void draw_render_info(const bContext *C,
stats_scene = CTX_data_scene(C);
}
- rr = BKE_image_acquire_renderresult(stats_scene, ima);
+ RenderResult *rr = BKE_image_acquire_renderresult(stats_scene, ima);
if (rr && rr->text) {
float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
@@ -107,39 +109,41 @@ static void draw_render_info(const bContext *C,
if (re) {
int total_tiles;
bool need_free_tiles;
- rcti *tiles;
-
- tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles);
+ rcti *tiles = RE_engine_get_current_tiles(re, &total_tiles, &need_free_tiles);
if (total_tiles) {
- int i, x, y;
- rcti *tile;
-
/* find window pixel coordinates of origin */
+ int x, y;
UI_view2d_view_to_region(&ar->v2d, 0.0f, 0.0f, &x, &y);
- glPushMatrix();
- glTranslatef(x, y, 0.0f);
- glScalef(zoomx, zoomy, 1.0f);
+ gpuPushMatrix();
+ gpuTranslate2f(x, y);
+ gpuScale2f(zoomx, zoomy);
if (rd->mode & R_BORDER) {
- glTranslatef((int)(-rd->border.xmin * rd->xsch * rd->size / 100.0f),
- (int)(-rd->border.ymin * rd->ysch * rd->size / 100.0f),
- 0.0f);
+ /* TODO: round or floor instead of casting to int */
+ gpuTranslate2f((int)(-rd->border.xmin * rd->xsch * rd->size * 0.01f),
+ (int)(-rd->border.ymin * rd->ysch * rd->size * 0.01f));
}
- UI_ThemeColor(TH_FACE_SELECT);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_FACE_SELECT);
glLineWidth(1.0f);
- for (i = 0, tile = tiles; i < total_tiles; i++, tile++) {
- glaDrawBorderCorners(tile, zoomx, zoomy);
+
+ rcti *tile = tiles;
+ for (int i = 0; i < total_tiles; i++, tile++) {
+ immDrawBorderCorners(pos, tile, zoomx, zoomy);
}
+ immUnbindProgram();
+
if (need_free_tiles) {
MEM_freeN(tiles);
}
- glPopMatrix();
+ gpuPopMatrix();
}
}
}
@@ -166,31 +170,37 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
float hue = 0, sat = 0, val = 0, lum = 0, u = 0, v = 0;
float col[4], finalcol[4];
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* noisy, high contrast make impossible to read if lower alpha is used. */
- glColor4ub(0, 0, 0, 190);
- glRecti(0.0, 0.0, BLI_rcti_size_x(&ar->winrct) + 1, UI_UNIT_Y);
+ immUniformColor4ub(0, 0, 0, 190);
+ immRecti(pos, 0, 0, BLI_rcti_size_x(&ar->winrct) + 1, UI_UNIT_Y);
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
BLF_size(blf_mono_font, 11 * U.pixelsize, U.dpi);
- glColor3ub(255, 255, 255);
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
BLI_snprintf(str, sizeof(str), "X:%-4d Y:%-4d |", x, y);
BLF_position(blf_mono_font, dx, dy, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str, sizeof(str));
if (zp) {
- glColor3ub(255, 255, 255);
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
BLI_snprintf(str, sizeof(str), " Z:%-.4f |", 0.5f + 0.5f * (((float)*zp) / (float)0x7fffffff));
BLF_position(blf_mono_font, dx, dy, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str, sizeof(str));
}
if (zpf) {
- glColor3ub(255, 255, 255);
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
BLI_snprintf(str, sizeof(str), " Z:%-.3f |", *zpf);
BLF_position(blf_mono_font, dx, dy, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
@@ -204,14 +214,14 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
else if (cp != NULL) {
BLI_snprintf(str, sizeof(str), " Val:%-.3f |", cp[0] / 255.0f);
}
- glColor3ub(255, 255, 255);
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
BLF_position(blf_mono_font, dx, dy, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str, sizeof(str));
}
if (channels >= 3) {
- glColor3ubv(red);
+ BLF_color3ubv(blf_mono_font, red);
if (fp)
BLI_snprintf(str, sizeof(str), " R:%-.5f", fp[0]);
else if (cp)
@@ -222,7 +232,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str, sizeof(str));
- glColor3ubv(green);
+ BLF_color3ubv(blf_mono_font, green);
if (fp)
BLI_snprintf(str, sizeof(str), " G:%-.5f", fp[1]);
else if (cp)
@@ -233,7 +243,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
dx += BLF_width(blf_mono_font, str, sizeof(str));
- glColor3ubv(blue);
+ BLF_color3ubv(blf_mono_font, blue);
if (fp)
BLI_snprintf(str, sizeof(str), " B:%-.5f", fp[2]);
else if (cp)
@@ -245,7 +255,7 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
dx += BLF_width(blf_mono_font, str, sizeof(str));
if (channels == 4) {
- glColor3ub(255, 255, 255);
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
if (fp)
BLI_snprintf(str, sizeof(str), " A:%-.4f", fp[3]);
else if (cp)
@@ -267,9 +277,9 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
rgba[3] = linearcol[3];
if (use_default_view)
- IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, NULL, &scene->display_settings);
+ IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, NULL, &scene->display_settings);
else
- IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, &scene->view_settings, &scene->display_settings);
+ IMB_colormanagement_pixel_to_display_space_v4(rgba, rgba, &scene->view_settings, &scene->display_settings);
BLI_snprintf(str, sizeof(str), " | CM R:%-.4f G:%-.4f B:%-.4f", rgba[0], rgba[1], rgba[2]);
BLF_position(blf_mono_font, dx, dy, 0);
@@ -305,9 +315,9 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
if (color_manage) {
if (use_default_view)
- IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, NULL, &scene->display_settings);
+ IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, NULL, &scene->display_settings);
else
- IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, &scene->view_settings, &scene->display_settings);
+ IMB_colormanagement_pixel_to_display_space_v4(finalcol, col, &scene->view_settings, &scene->display_settings);
}
else {
copy_v4_v4(finalcol, col);
@@ -318,13 +328,18 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
BLI_rcti_init(&color_rect, dx, dx + (1.5f * UI_UNIT_X), 0.15f * UI_UNIT_Y, 0.85f * UI_UNIT_Y);
+ /* BLF uses immediate mode too, so we must reset our vertex format */
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
if (channels == 4) {
rcti color_rect_half;
int color_quater_x, color_quater_y;
color_rect_half = color_rect;
color_rect_half.xmax = BLI_rcti_cent_x(&color_rect);
- glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ /* what color ??? */
+ immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
color_rect_half = color_rect;
color_rect_half.xmin = BLI_rcti_cent_x(&color_rect);
@@ -332,31 +347,34 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
color_quater_x = BLI_rcti_cent_x(&color_rect_half);
color_quater_y = BLI_rcti_cent_y(&color_rect_half);
- glColor4ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, 255);
- glRecti(color_rect_half.xmin, color_rect_half.ymin, color_rect_half.xmax, color_rect_half.ymax);
+ immUniformColor3ub(UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK, UI_ALPHA_CHECKER_DARK);
+ immRecti(pos, color_rect_half.xmin, color_rect_half.ymin, color_rect_half.xmax, color_rect_half.ymax);
- glColor4ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, 255);
- glRecti(color_quater_x, color_quater_y, color_rect_half.xmax, color_rect_half.ymax);
- glRecti(color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y);
+ immUniformColor3ub(UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT, UI_ALPHA_CHECKER_LIGHT);
+ immRecti(pos, color_quater_x, color_quater_y, color_rect_half.xmax, color_rect_half.ymax);
+ immRecti(pos, color_rect_half.xmin, color_rect_half.ymin, color_quater_x, color_quater_y);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4f(UNPACK3(finalcol), fp ? fp[3] : (cp[3] / 255.0f));
- glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ immUniformColor3fvAlpha(finalcol, fp ? fp[3] : (cp[3] / 255.0f));
+ immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
glDisable(GL_BLEND);
}
else {
- glColor3fv(finalcol);
- glRecti(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ immUniformColor3fv(finalcol);
+ immRecti(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
}
+ immUnbindProgram();
/* draw outline */
- glColor3ub(128, 128, 128);
- sdrawbox(color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3ub(128, 128, 128);
+ imm_draw_box_wire_2d(pos, color_rect.xmin, color_rect.ymin, color_rect.xmax, color_rect.ymax);
+ immUnbindProgram();
dx += 1.75f * UI_UNIT_X;
- glColor3ub(255, 255, 255);
+ BLF_color3ub(blf_mono_font, 255, 255, 255);
if (channels == 1) {
if (fp) {
rgb_to_hsv(fp[0], fp[0], fp[0], &hue, &sat, &val);
@@ -375,7 +393,6 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
BLI_snprintf(str, sizeof(str), " L:%-.4f", lum);
BLF_position(blf_mono_font, dx, dy, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
}
else if (channels >= 3) {
rgb_to_hsv(finalcol[0], finalcol[1], finalcol[2], &hue, &sat, &val);
@@ -399,70 +416,37 @@ void ED_image_draw_info(Scene *scene, ARegion *ar, bool color_manage, bool use_d
BLI_snprintf(str, sizeof(str), " L:%-.4f", lum);
BLF_position(blf_mono_font, dx, dy, 0);
BLF_draw_ascii(blf_mono_font, str, sizeof(str));
- dx += BLF_width(blf_mono_font, str, sizeof(str));
}
-
- (void)dx;
}
/* image drawing */
-
-static void sima_draw_alpha_pixels(float x1, float y1, int rectx, int recty, unsigned int *recti)
+static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int *rect,
+ float zoomx, float zoomy)
{
-
- /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
- if (ENDIAN_ORDER == B_ENDIAN)
- glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
+ float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
- glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_UNSIGNED_INT, recti);
- glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
-}
+ /* Slowwww */
+ int *recti = MEM_mallocN(rectx * recty * sizeof(int), "temp");
+ for (int a = rectx * recty - 1; a >= 0; a--) {
+ /* zbuffer values are signed, so we need to shift color range */
+ recti[a] = rect[a] * 0.5f + 0.5f;
+ }
-static void sima_draw_alpha_pixelsf(float x1, float y1, int rectx, int recty, float *rectf)
-{
- float *trectf = MEM_mallocN(rectx * recty * 4, "temp");
- int a, b;
-
- for (a = rectx * recty - 1, b = 4 * a + 3; a >= 0; a--, b -= 4)
- trectf[a] = rectf[b];
-
- glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_FLOAT, trectf);
- MEM_freeN(trectf);
- /* ogl trick below is slower... (on ATI 9600) */
-// glColorMask(1, 0, 0, 0);
-// glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_RGBA, GL_FLOAT, rectf + 3);
-// glColorMask(0, 1, 0, 0);
-// glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_RGBA, GL_FLOAT, rectf + 2);
-// glColorMask(0, 0, 1, 0);
-// glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_RGBA, GL_FLOAT, rectf + 1);
-// glColorMask(1, 1, 1, 1);
-}
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
-static void sima_draw_zbuf_pixels(float x1, float y1, int rectx, int recty, int *recti)
-{
- /* zbuffer values are signed, so we need to shift color range */
- glPixelTransferf(GL_RED_SCALE, 0.5f);
- glPixelTransferf(GL_GREEN_SCALE, 0.5f);
- glPixelTransferf(GL_BLUE_SCALE, 0.5f);
- glPixelTransferf(GL_RED_BIAS, 0.5f);
- glPixelTransferf(GL_GREEN_BIAS, 0.5f);
- glPixelTransferf(GL_BLUE_BIAS, 0.5f);
-
- glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_INT, recti);
-
- glPixelTransferf(GL_RED_SCALE, 1.0f);
- glPixelTransferf(GL_GREEN_SCALE, 1.0f);
- glPixelTransferf(GL_BLUE_SCALE, 1.0f);
- glPixelTransferf(GL_RED_BIAS, 0.0f);
- glPixelTransferf(GL_GREEN_BIAS, 0.0f);
- glPixelTransferf(GL_BLUE_BIAS, 0.0f);
+ immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_INT, GL_NEAREST, recti, zoomx, zoomy, NULL);
+
+ MEM_freeN(recti);
}
-static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rectx, int recty, float *rect_float)
+static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rectx, int recty,
+ float *rect_float, float zoomx, float zoomy)
{
float bias, scale, *rectf, clipend;
int a;
-
+ float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
+
if (scene->camera && scene->camera->type == OB_CAMERA) {
bias = ((Camera *)scene->camera->data)->clipsta;
clipend = ((Camera *)scene->camera->data)->clipend;
@@ -473,8 +457,8 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec
scale = 0.01f;
clipend = 100.0f;
}
-
- rectf = MEM_mallocN(rectx * recty * 4, "temp");
+
+ rectf = MEM_mallocN(rectx * recty * sizeof(float), "temp");
for (a = rectx * recty - 1; a >= 0; a--) {
if (rect_float[a] > clipend)
rectf[a] = 0.0f;
@@ -485,196 +469,83 @@ static void sima_draw_zbuffloat_pixels(Scene *scene, float x1, float y1, int rec
rectf[a] *= rectf[a];
}
}
- glaDrawPixelsSafe(x1, y1, rectx, recty, rectx, GL_LUMINANCE, GL_FLOAT, rectf);
-
- MEM_freeN(rectf);
-}
-static int draw_image_channel_offset(SpaceImage *sima)
-{
-#ifdef __BIG_ENDIAN__
- if (sima->flag & SI_SHOW_R) return 0;
- else if (sima->flag & SI_SHOW_G) return 1;
- else return 2;
-#else
- if (sima->flag & SI_SHOW_R) return 1;
- else if (sima->flag & SI_SHOW_G) return 2;
- else return 3;
-#endif
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
+
+ immDrawPixelsTex(&state, x1, y1, rectx, recty, GL_RED, GL_FLOAT, GL_NEAREST, rectf, zoomx, zoomy, NULL);
+
+ MEM_freeN(rectf);
}
static void draw_image_buffer(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
{
int x, y;
- /* set zoom */
- glPixelZoom(zoomx, zoomy);
-
- glaDefine2DArea(&ar->winrct);
-
/* find window pixel coordinates of origin */
UI_view2d_view_to_region(&ar->v2d, fx, fy, &x, &y);
/* this part is generic image display */
- if (sima->flag & SI_SHOW_ALPHA) {
- if (ibuf->rect)
- sima_draw_alpha_pixels(x, y, ibuf->x, ibuf->y, ibuf->rect);
- else if (ibuf->rect_float && ibuf->channels == 4)
- sima_draw_alpha_pixelsf(x, y, ibuf->x, ibuf->y, ibuf->rect_float);
- }
- else if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
+ if (sima->flag & SI_SHOW_ZBUF && (ibuf->zbuf || ibuf->zbuf_float || (ibuf->channels == 1))) {
if (ibuf->zbuf)
- sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf);
+ sima_draw_zbuf_pixels(x, y, ibuf->x, ibuf->y, ibuf->zbuf, zoomx, zoomy);
else if (ibuf->zbuf_float)
- sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float);
+ sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->zbuf_float, zoomx, zoomy);
else if (ibuf->channels == 1)
- sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float);
+ sima_draw_zbuffloat_pixels(scene, x, y, ibuf->x, ibuf->y, ibuf->rect_float, zoomx, zoomy);
}
else {
+ int clip_max_x, clip_max_y;
+ UI_view2d_view_to_region(&ar->v2d,
+ ar->v2d.cur.xmax, ar->v2d.cur.ymax,
+ &clip_max_x, &clip_max_y);
+
if (sima->flag & SI_USE_ALPHA) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ imm_draw_box_checker_2d(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy);
- fdrawcheckerboard(x, y, x + ibuf->x * zoomx, y + ibuf->y * zoomy);
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
- if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B)) == 0) {
- int clip_max_x, clip_max_y;
- UI_view2d_view_to_region(&ar->v2d,
- ar->v2d.cur.xmax, ar->v2d.cur.ymax,
- &clip_max_x, &clip_max_y);
+ /* If RGBA display with color management */
+ if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B | SI_SHOW_ALPHA)) == 0) {
+
glaDrawImBuf_glsl_ctx_clipping(C, ibuf, x, y, GL_NEAREST,
- 0, 0, clip_max_x, clip_max_y);
+ 0, 0, clip_max_x, clip_max_y, zoomx, zoomy);
}
else {
+ float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f};
unsigned char *display_buffer;
void *cache_handle;
-
- /* TODO(sergey): Ideally GLSL shading should be capable of either
- * disabling some channels or displaying buffer with custom offset.
- */
- display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
-
- if (display_buffer != NULL) {
- int channel_offset = draw_image_channel_offset(sima);
- glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT,
- display_buffer - (4 - channel_offset));
- }
- if (cache_handle != NULL) {
- IMB_display_buffer_release(cache_handle);
+ ColorManagedViewSettings *view_settings;
+ ColorManagedDisplaySettings *display_settings;
+
+ if (sima->flag & SI_SHOW_R)
+ shuffle[0] = 1.0f;
+ else if (sima->flag & SI_SHOW_G)
+ shuffle[1] = 1.0f;
+ else if (sima->flag & SI_SHOW_B)
+ shuffle[2] = 1.0f;
+ else if (sima->flag & SI_SHOW_ALPHA)
+ shuffle[3] = 1.0f;
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle);
+
+ IMB_colormanagement_display_settings_from_ctx(C, &view_settings, &display_settings);
+ display_buffer = IMB_display_buffer_acquire(ibuf, view_settings, display_settings, &cache_handle);
+
+ if (display_buffer) {
+ immDrawPixelsTex_clipping(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer,
+ 0, 0, clip_max_x, clip_max_y, zoomx, zoomy, NULL);
}
+
+ IMB_display_buffer_release(cache_handle);
}
if (sima->flag & SI_USE_ALPHA)
glDisable(GL_BLEND);
}
-
- /* reset zoom */
- glPixelZoom(1.0f, 1.0f);
-}
-
-static unsigned int *get_part_from_buffer(unsigned int *buffer, int width, short startx, short starty, short endx, short endy)
-{
- unsigned int *rt, *rp, *rectmain;
- short y, heigth, len;
-
- /* the right offset in rectot */
-
- rt = buffer + (starty * width + startx);
-
- len = (endx - startx);
- heigth = (endy - starty);
-
- rp = rectmain = MEM_mallocN(heigth * len * sizeof(int), "rect");
-
- for (y = 0; y < heigth; y++) {
- memcpy(rp, rt, len * 4);
- rt += width;
- rp += len;
- }
- return rectmain;
-}
-
-static void draw_image_buffer_tiled(SpaceImage *sima, ARegion *ar, Scene *scene, Image *ima, ImBuf *ibuf, float fx, float fy, float zoomx, float zoomy)
-{
- unsigned char *display_buffer;
- unsigned int *rect;
- int dx, dy, sx, sy, x, y;
- void *cache_handle;
- int channel_offset = -1;
-
- /* verify valid values, just leave this a while */
- if (ima->xrep < 1) return;
- if (ima->yrep < 1) return;
-
- if (ima->flag & IMA_VIEW_AS_RENDER)
- display_buffer = IMB_display_buffer_acquire(ibuf, &scene->view_settings, &scene->display_settings, &cache_handle);
- else
- display_buffer = IMB_display_buffer_acquire(ibuf, NULL, &scene->display_settings, &cache_handle);
-
- if (!display_buffer)
- return;
-
- glPixelZoom(zoomx, zoomy);
-
- if (sima->curtile >= ima->xrep * ima->yrep)
- sima->curtile = ima->xrep * ima->yrep - 1;
-
- /* retrieve part of image buffer */
- dx = max_ii(ibuf->x / ima->xrep, 1);
- dy = max_ii(ibuf->y / ima->yrep, 1);
- sx = (sima->curtile % ima->xrep) * dx;
- sy = (sima->curtile / ima->xrep) * dy;
- rect = get_part_from_buffer((unsigned int *)display_buffer, ibuf->x, sx, sy, sx + dx, sy + dy);
-
- /* draw repeated */
- if ((sima->flag & (SI_SHOW_R | SI_SHOW_G | SI_SHOW_B)) != 0) {
- channel_offset = draw_image_channel_offset(sima);
- }
- for (sy = 0; sy + dy <= ibuf->y; sy += dy) {
- for (sx = 0; sx + dx <= ibuf->x; sx += dx) {
- UI_view2d_view_to_region(&ar->v2d, fx + (float)sx / (float)ibuf->x, fy + (float)sy / (float)ibuf->y, &x, &y);
- if (channel_offset == -1) {
- glaDrawPixelsSafe(x, y, dx, dy, dx, GL_RGBA, GL_UNSIGNED_BYTE, rect);
- }
- else {
- glaDrawPixelsSafe(x, y, dx, dy, dx, GL_LUMINANCE, GL_UNSIGNED_INT,
- (unsigned char *)rect - (4 - channel_offset));
- }
- }
- }
-
- glPixelZoom(1.0f, 1.0f);
-
- IMB_display_buffer_release(cache_handle);
-
- MEM_freeN(rect);
-}
-
-static void draw_image_buffer_repeated(const bContext *C, SpaceImage *sima, ARegion *ar, Scene *scene, Image *ima, ImBuf *ibuf, float zoomx, float zoomy)
-{
- const double time_current = PIL_check_seconds_timer();
-
- const int xmax = ceil(ar->v2d.cur.xmax);
- const int ymax = ceil(ar->v2d.cur.ymax);
- const int xmin = floor(ar->v2d.cur.xmin);
- const int ymin = floor(ar->v2d.cur.ymin);
-
- int x;
-
- for (x = xmin; x < xmax; x++) {
- int y;
- for (y = ymin; y < ymax; y++) {
- if (ima && (ima->tpageflag & IMA_TILES))
- draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, x, y, zoomx, zoomy);
- else
- draw_image_buffer(C, sima, ar, scene, ibuf, x, y, zoomx, zoomy);
-
- /* only draw until running out of time */
- if ((PIL_check_seconds_timer() - time_current) > 0.25)
- return;
- }
- }
}
/* draw uv edit */
@@ -701,134 +572,62 @@ void draw_image_sample_line(SpaceImage *sima)
if (sima->sample_line_hist.flag & HISTO_FLAG_SAMPLELINE) {
Histogram *hist = &sima->sample_line_hist;
- glBegin(GL_LINES);
- glColor3ub(0, 0, 0);
- glVertex2fv(hist->co[0]);
- glVertex2fv(hist->co[1]);
- glEnd();
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int shdr_dashed_pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- setlinestyle(1);
- glBegin(GL_LINES);
- glColor3ub(255, 255, 255);
- glVertex2fv(hist->co[0]);
- glVertex2fv(hist->co[1]);
- glEnd();
- setlinestyle(0);
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- }
-}
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
-/* XXX becomes WM paint cursor */
-#if 0
-static void draw_image_view_tool(Scene *scene)
-{
- ToolSettings *settings = scene->toolsettings;
- Brush *brush = settings->imapaint.brush;
- int mval[2];
- float radius;
- int draw = 0;
-
- if (brush) {
- if (settings->imapaint.flag & IMAGEPAINT_DRAWING) {
- if (settings->imapaint.flag & IMAGEPAINT_DRAW_TOOL_DRAWING)
- draw = 1;
- }
- else if (settings->imapaint.flag & IMAGEPAINT_DRAW_TOOL)
- draw = 1;
-
- if (draw) {
- getmouseco_areawin(mval);
+ immUniform1i("num_colors", 2); /* Advanced dashes. */
+ immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 2.0f);
- radius = BKE_brush_size_get(brush) * G.sima->zoom;
- fdrawXORcirc(mval[0], mval[1], radius);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(shdr_dashed_pos, hist->co[0]);
+ immVertex2fv(shdr_dashed_pos, hist->co[1]);
+ immEnd();
- if (brush->innerradius != 1.0) {
- radius *= brush->innerradius;
- fdrawXORcirc(mval[0], mval[1], radius);
- }
- }
+ immUnbindProgram();
}
}
-#endif
-
-static unsigned char *get_alpha_clone_image(const bContext *C, Scene *scene, int *width, int *height)
-{
- Brush *brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint);
- ImBuf *ibuf;
- unsigned int size, alpha;
- unsigned char *display_buffer;
- unsigned char *rect, *cp;
- void *cache_handle;
-
- if (!brush || !brush->clone.image)
- return NULL;
-
- ibuf = BKE_image_acquire_ibuf(brush->clone.image, NULL, NULL);
-
- if (!ibuf)
- return NULL;
-
- display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
-
- if (!display_buffer) {
- BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
- IMB_display_buffer_release(cache_handle);
-
- return NULL;
- }
-
- rect = MEM_dupallocN(display_buffer);
-
- IMB_display_buffer_release(cache_handle);
-
- if (!rect) {
- BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
- return NULL;
- }
-
- *width = ibuf->x;
- *height = ibuf->y;
-
- size = (*width) * (*height);
- alpha = (unsigned char)255 * brush->clone.alpha;
- cp = rect;
-
- while (size-- > 0) {
- cp[3] = alpha;
- cp += 4;
- }
-
- BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
-
- return rect;
-}
static void draw_image_paint_helpers(const bContext *C, ARegion *ar, Scene *scene, float zoomx, float zoomy)
{
Brush *brush;
- int x, y, w, h;
- unsigned char *clonerect;
+ int x, y;
+ ImBuf *ibuf;
brush = BKE_paint_brush(&scene->toolsettings->imapaint.paint);
- if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE)) {
- /* this is not very efficient, but glDrawPixels doesn't allow
- * drawing with alpha */
- clonerect = get_alpha_clone_image(C, scene, &w, &h);
+ if (brush && (brush->imagepaint_tool == PAINT_TOOL_CLONE) && brush->clone.image) {
+ ibuf = BKE_image_acquire_ibuf(brush->clone.image, NULL, NULL);
- if (clonerect) {
+ if (ibuf) {
+ void *cache_handle = NULL;
+ float col[4] = {1.0f, 1.0f, 1.0f, brush->clone.alpha};
UI_view2d_view_to_region(&ar->v2d, brush->clone.offset[0], brush->clone.offset[1], &x, &y);
- glPixelZoom(zoomx, zoomy);
+ unsigned char *display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
+
+ if (!display_buffer) {
+ BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
+ IMB_display_buffer_release(cache_handle);
+ return;
+ }
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glaDrawPixelsSafe(x, y, w, h, w, GL_RGBA, GL_UNSIGNED_BYTE, clonerect);
- glDisable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, display_buffer, zoomx, zoomy, col);
- glPixelZoom(1.0, 1.0);
+ glDisable(GL_BLEND);
- MEM_freeN(clonerect);
+ BKE_image_release_ibuf(brush->clone.image, ibuf, NULL);
+ IMB_display_buffer_release(cache_handle);
}
}
}
@@ -899,14 +698,8 @@ void draw_image_main(const bContext *C, ARegion *ar)
ED_region_grid_draw(ar, zoomx, zoomy);
}
else {
+ draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
- if (sima->flag & SI_DRAW_TILE)
- draw_image_buffer_repeated(C, sima, ar, scene, ima, ibuf, zoomx, zoomy);
- else if (ima && (ima->tpageflag & IMA_TILES))
- draw_image_buffer_tiled(sima, ar, scene, ima, ibuf, 0.0f, 0.0, zoomx, zoomy);
- else
- draw_image_buffer(C, sima, ar, scene, ibuf, 0.0f, 0.0f, zoomx, zoomy);
-
if (sima->flag & SI_DRAW_METADATA) {
int x, y;
rctf frame;
@@ -924,23 +717,6 @@ void draw_image_main(const bContext *C, ARegion *ar)
if (show_paint)
draw_image_paint_helpers(C, ar, scene, zoomx, zoomy);
- /* XXX integrate this code */
-#if 0
- if (ibuf) {
- float xoffs = 0.0f, yoffs = 0.0f;
-
- if (image_preview_active(sa, &xim, &yim)) {
- xoffs = scene->r.disprect.xmin;
- yoffs = scene->r.disprect.ymin;
- glColor3ub(0, 0, 0);
- calc_image_view(sima, 'f');
- myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
- glRectf(0.0f, 0.0f, 1.0f, 1.0f);
- glLoadIdentity();
- }
- }
-#endif
-
if (show_viewer) {
BLI_thread_unlock(LOCK_DRAW_IMAGE);
}
@@ -983,7 +759,7 @@ void draw_image_cache(const bContext *C, ARegion *ar)
}
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* Draw cache background. */
ED_region_cache_draw_background(ar);
@@ -1002,8 +778,12 @@ void draw_image_cache(const bContext *C, ARegion *ar)
/* Draw current frame. */
x = (cfra - sfra) / (efra - sfra + 1) * ar->winx;
- UI_ThemeColor(TH_CFRAME);
- glRecti(x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_CFRAME);
+ immRecti(pos, x, 0, x + ceilf(framelen), 8 * UI_DPI_FAC);
+ immUnbindProgram();
+
ED_region_cache_draw_curfra_label(cfra, x, 8.0f * UI_DPI_FAC);
if (mask != NULL) {
diff --git a/source/blender/editors/space_image/image_edit.c b/source/blender/editors/space_image/image_edit.c
index 9d7944a25d3..c598e486a7e 100644
--- a/source/blender/editors/space_image/image_edit.c
+++ b/source/blender/editors/space_image/image_edit.c
@@ -44,6 +44,8 @@
#include "IMB_imbuf_types.h"
+#include "DEG_depsgraph.h"
+
#include "ED_image.h" /* own include */
#include "ED_mesh.h"
#include "ED_screen.h"
@@ -61,11 +63,8 @@ Image *ED_space_image(SpaceImage *sima)
}
/* called to assign images to UV faces */
-void ED_space_image_set(SpaceImage *sima, Scene *scene, Object *obedit, Image *ima)
+void ED_space_image_set(SpaceImage *sima, Scene *UNUSED(scene), Object *obedit, Image *ima)
{
- /* context may be NULL, so use global */
- ED_uvedit_assign_image(G.main, scene, obedit, ima, sima->image);
-
/* change the space ima after because uvedit_face_visible_test uses the space ima
* to check if the face is displayed in UV-localview */
sima->image = ima;
@@ -374,10 +373,10 @@ bool ED_space_image_show_uvedit(SpaceImage *sima, Object *obedit)
}
/* matches clip function */
-bool ED_space_image_check_show_maskedit(Scene *scene, SpaceImage *sima)
+bool ED_space_image_check_show_maskedit(SpaceImage *sima, ViewLayer *view_layer)
{
/* check editmode - this is reserved for UV editing */
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
if (ob && ob->mode & OB_MODE_EDIT && ED_space_image_show_uvedit(sima, ob)) {
return false;
}
@@ -390,8 +389,8 @@ int ED_space_image_maskedit_poll(bContext *C)
SpaceImage *sima = CTX_wm_space_image(C);
if (sima) {
- Scene *scene = CTX_data_scene(C);
- return ED_space_image_check_show_maskedit(scene, sima);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ return ED_space_image_check_show_maskedit(sima, view_layer);
}
return false;
diff --git a/source/blender/editors/space_image/image_intern.h b/source/blender/editors/space_image/image_intern.h
index 52d04ad4956..47d6257366c 100644
--- a/source/blender/editors/space_image/image_intern.h
+++ b/source/blender/editors/space_image/image_intern.h
@@ -90,7 +90,7 @@ void IMAGE_OT_curves_point_set(struct wmOperatorType *ot);
void IMAGE_OT_change_frame(struct wmOperatorType *ot);
-void IMAGE_OT_read_renderlayers(struct wmOperatorType *ot);
+void IMAGE_OT_read_viewlayers(struct wmOperatorType *ot);
void IMAGE_OT_render_border(struct wmOperatorType *ot);
void IMAGE_OT_clear_render_border(struct wmOperatorType *ot);
diff --git a/source/blender/editors/space_image/image_ops.c b/source/blender/editors/space_image/image_ops.c
index e14e7820403..a2afb5cb5c5 100644
--- a/source/blender/editors/space_image/image_ops.c
+++ b/source/blender/editors/space_image/image_ops.c
@@ -48,6 +48,7 @@
#include "BLT_translation.h"
+#include "DNA_camera_types.h"
#include "DNA_object_types.h"
#include "DNA_node_types.h"
#include "DNA_packedFile_types.h"
@@ -56,7 +57,6 @@
#include "BKE_colortools.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_icons.h"
#include "BKE_image.h"
@@ -70,8 +70,9 @@
#include "BKE_sound.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+
#include "GPU_draw.h"
-#include "GPU_buffers.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
@@ -277,8 +278,9 @@ static int space_image_main_area_not_uv_brush_poll(bContext *C)
Scene *scene = CTX_data_scene(C);
ToolSettings *toolsettings = scene->toolsettings;
- if (sima && !toolsettings->uvsculpt && !scene->obedit)
+ if (sima && !toolsettings->uvsculpt && (CTX_data_edit_object(C) == NULL)) {
return 1;
+ }
return 0;
}
@@ -792,6 +794,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
SpaceImage *sima;
ARegion *ar;
Scene *scene;
+ ViewLayer *view_layer;
Object *obedit;
Image *ima;
@@ -799,6 +802,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
sima = CTX_wm_space_image(C);
ar = CTX_wm_region(C);
scene = CTX_data_scene(C);
+ view_layer = CTX_data_view_layer(C);
obedit = CTX_data_edit_object(C);
ima = ED_space_image(sima);
@@ -810,7 +814,7 @@ static int image_view_selected_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_CANCELLED;
}
}
- else if (ED_space_image_check_show_maskedit(scene, sima)) {
+ else if (ED_space_image_check_show_maskedit(sima, view_layer)) {
if (!ED_mask_selected_minmax(C, min, max)) {
return OPERATOR_CANCELLED;
}
@@ -1307,21 +1311,23 @@ static int image_open_exec(bContext *C, wmOperator *op)
ED_space_image_set(sima, scene, obedit, ima);
iuser = &sima->iuser;
}
- else if (sa && sa->spacetype == SPACE_VIEW3D) {
- View3D *v3d = sa->spacedata.first;
-
- for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- if (bgpic->ima == ima) {
- iuser = &bgpic->iuser;
- break;
- }
- }
- }
else {
Tex *tex = CTX_data_pointer_get_type(C, "texture", &RNA_Texture).data;
if (tex && tex->type == TEX_IMAGE) {
iuser = &tex->iuser;
}
+
+ if (iuser == NULL) {
+ Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
+ if (cam) {
+ for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+ if (bgpic->ima == ima) {
+ iuser = &bgpic->iuser;
+ break;
+ }
+ }
+ }
+ }
}
/* initialize because of new image */
@@ -1425,7 +1431,7 @@ static void image_open_draw(bContext *UNUSED(C), wmOperator *op)
/* main draw call */
RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
- uiDefAutoButsRNA(layout, &ptr, image_open_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, image_open_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
/* image template */
RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr);
@@ -2141,7 +2147,7 @@ static void image_save_as_draw(bContext *UNUSED(C), wmOperator *op)
/* main draw call */
RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
- uiDefAutoButsRNA(layout, &ptr, image_save_as_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, image_save_as_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
/* multiview template */
if (is_multiview)
@@ -2341,7 +2347,7 @@ static int image_reload_exec(bContext *C, wmOperator *UNUSED(op))
// XXX other users?
BKE_image_signal(ima, (sima) ? &sima->iuser : NULL, IMA_SIGNAL_RELOAD);
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
WM_event_add_notifier(C, NC_IMAGE | NA_EDITED, ima);
@@ -2438,7 +2444,6 @@ static int image_new_exec(bContext *C, wmOperator *op)
bScreen *sc;
Object *ob = CTX_data_active_object(C);
- GPU_drawobject_free(ob->derivedFinal);
if (scene->toolsettings->imapaint.canvas)
id_us_min(&scene->toolsettings->imapaint.canvas->id);
scene->toolsettings->imapaint.canvas = ima;
@@ -2452,7 +2457,7 @@ static int image_new_exec(bContext *C, wmOperator *op)
SpaceImage *sima_other = (SpaceImage *)sl;
if (!sima_other->pin) {
- ED_space_image_set(sima_other, scene, scene->obedit, ima);
+ ED_space_image_set(sima_other, scene, obedit, ima);
}
}
}
@@ -3594,7 +3599,7 @@ void IMAGE_OT_change_frame(wmOperatorType *ot)
/* Reload cached render results... */
/* goes over all scenes, reads render layers */
-static int image_read_renderlayers_exec(bContext *C, wmOperator *UNUSED(op))
+static int image_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op))
{
Scene *scene = CTX_data_scene(C);
SpaceImage *sima = CTX_wm_space_image(C);
@@ -3611,14 +3616,14 @@ static int image_read_renderlayers_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
}
-void IMAGE_OT_read_renderlayers(wmOperatorType *ot)
+void IMAGE_OT_read_viewlayers(wmOperatorType *ot)
{
- ot->name = "Read Render Layers";
- ot->idname = "IMAGE_OT_read_renderlayers";
- ot->description = "Read all the current scene's render layers from cache, as needed";
+ ot->name = "Read View Layers";
+ ot->idname = "IMAGE_OT_read_viewlayers";
+ ot->description = "Read all the current scene's view layers from cache, as needed";
ot->poll = space_image_main_region_poll;
- ot->exec = image_read_renderlayers_exec;
+ ot->exec = image_read_viewlayers_exec;
/* flags */
ot->flag = 0;
diff --git a/source/blender/editors/space_image/space_image.c b/source/blender/editors/space_image/space_image.c
index bac3b9f8df7..bfbf51487ad 100644
--- a/source/blender/editors/space_image/space_image.c
+++ b/source/blender/editors/space_image/space_image.c
@@ -44,10 +44,15 @@
#include "BKE_colortools.h"
#include "BKE_context.h"
+#include "BKE_editmesh.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
+#include "BKE_material.h"
+
+#include "DEG_depsgraph.h"
#include "IMB_imbuf_types.h"
@@ -59,6 +64,7 @@
#include "ED_space_api.h"
#include "ED_screen.h"
#include "ED_uvedit.h"
+#include "ED_transform.h"
#include "BIF_gl.h"
@@ -156,7 +162,7 @@ ARegion *image_has_tools_region(ScrArea *sa)
/* ******************** default callbacks for image space ***************** */
-static SpaceLink *image_new(const bContext *UNUSED(C))
+static SpaceLink *image_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceImage *simage;
@@ -275,7 +281,7 @@ static void image_operatortypes(void)
WM_operatortype_append(IMAGE_OT_change_frame);
- WM_operatortype_append(IMAGE_OT_read_renderlayers);
+ WM_operatortype_append(IMAGE_OT_read_viewlayers);
WM_operatortype_append(IMAGE_OT_render_border);
WM_operatortype_append(IMAGE_OT_clear_render_border);
}
@@ -289,7 +295,7 @@ static void image_keymap(struct wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "IMAGE_OT_new", NKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_open", OKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_reload", RKEY, KM_PRESS, KM_ALT, 0);
- WM_keymap_add_item(keymap, "IMAGE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0);
+ WM_keymap_add_item(keymap, "IMAGE_OT_read_viewlayers", RKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_save", SKEY, KM_PRESS, KM_ALT, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_save_as", F3KEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "IMAGE_OT_properties", NKEY, KM_PRESS, 0, 0);
@@ -404,7 +410,6 @@ static void image_refresh(const bContext *C, ScrArea *sa)
{
Scene *scene = CTX_data_scene(C);
SpaceImage *sima = sa->spacedata.first;
- Object *obedit = CTX_data_edit_object(C);
Image *ima;
ima = ED_space_image(sima);
@@ -420,38 +425,11 @@ static void image_refresh(const bContext *C, ScrArea *sa)
}
}
}
- else if (ima && (ima->source == IMA_SRC_VIEWER || sima->pin)) {
- /* pass */
- }
- else if (obedit && obedit->type == OB_MESH) {
- Mesh *me = (Mesh *)obedit->data;
- struct BMEditMesh *em = me->edit_btmesh;
- bool sloppy = true; /* partially selected face is ok */
- bool selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION); /* only selected active face? */
-
- if (BKE_scene_use_new_shading_nodes(scene)) {
- /* new shading system does not alter image */
- }
- else {
- /* old shading system, we set texface */
- if (em && EDBM_uv_check(em)) {
- MTexPoly *tf;
- if (EDBM_uv_active_face_get(em, sloppy, selected, &tf)) {
- /* don't need to check for pin here, see above */
- sima->image = tf->tpage;
-
- if ((sima->flag & SI_EDITTILE) == 0) {
- sima->curtile = tf->tile;
- }
- }
- }
- }
- }
}
-static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn)
+static void image_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *scene,
+ WorkSpace *workspace)
{
- Scene *scene = sc->scene;
SpaceImage *sima = (SpaceImage *)sa->spacedata.first;
/* context changes */
@@ -544,7 +522,8 @@ static void image_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn)
case ND_TRANSFORM:
case ND_MODIFIER:
{
- Object *ob = OBACT;
+ ViewLayer *view_layer = BKE_view_layer_from_workspace_get(scene, workspace);
+ Object *ob = OBACT(view_layer);
if (ob && (ob == wmn->reference) && (ob->mode & OB_MODE_EDIT)) {
if (sima->lock && (sima->flag & SI_DRAWSHADOW)) {
ED_area_tag_refresh(sa);
@@ -596,6 +575,27 @@ static int image_context(const bContext *C, const char *member, bContextDataResu
return 0;
}
+static void IMAGE_WGT_manipulator2d(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "UV Transform Manipulator";
+ wgt->idname = "IMAGE_WGT_manipulator2d";
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT;
+
+ wgt->poll = ED_widgetgroup_manipulator2d_poll;
+ wgt->setup = ED_widgetgroup_manipulator2d_setup;
+ wgt->refresh = ED_widgetgroup_manipulator2d_refresh;
+ wgt->draw_prepare = ED_widgetgroup_manipulator2d_draw_prepare;
+}
+
+static void image_widgets(void)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(
+ &(const struct wmManipulatorMapType_Params){SPACE_IMAGE, RGN_TYPE_WINDOW});
+
+ WM_manipulatorgrouptype_append_and_link(mmap_type, IMAGE_WGT_manipulator2d);
+}
+
/************************** main region ***************************/
/* sets up the fields of the View2D from zoom and offset */
@@ -659,6 +659,16 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
// image space manages own v2d
// UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_STANDARD, ar->winx, ar->winy);
+ /* manipulators */
+ if (ar->manipulator_map == NULL) {
+ const struct wmManipulatorMapType_Params wmap_params = {
+ .spaceid = SPACE_IMAGE,
+ .regionid = RGN_TYPE_WINDOW,
+ };
+ ar->manipulator_map = WM_manipulatormap_new_from_type(&wmap_params);
+ }
+ WM_manipulatormap_add_handlers(ar, ar->manipulator_map);
+
/* mask polls mode */
keymap = WM_keymap_find(wm->defaultconf, "Mask Editing", 0, 0);
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
@@ -684,7 +694,6 @@ static void image_main_region_init(wmWindowManager *wm, ARegion *ar)
WM_event_add_keymap_handler(&ar->handlers, keymap);
keymap = WM_keymap_find(wm->defaultconf, "Image", SPACE_IMAGE, 0);
WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
-
}
static void image_main_region_draw(const bContext *C, ARegion *ar)
@@ -693,9 +702,11 @@ static void image_main_region_draw(const bContext *C, ARegion *ar)
SpaceImage *sima = CTX_wm_space_image(C);
Object *obact = CTX_data_active_object(C);
Object *obedit = CTX_data_edit_object(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Mask *mask = NULL;
bool curve = false;
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
View2D *v2d = &ar->v2d;
//View2DScrollers *scrollers;
float col[3];
@@ -721,7 +732,7 @@ static void image_main_region_draw(const bContext *C, ARegion *ar)
ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
- ED_uvedit_draw_main(sima, ar, scene, obedit, obact);
+ ED_uvedit_draw_main(sima, ar, scene, view_layer, obedit, obact, depsgraph);
/* check for mask (delay draw) */
if (ED_space_image_show_uvedit(sima, obedit)) {
@@ -790,6 +801,8 @@ static void image_main_region_draw(const bContext *C, ARegion *ar)
UI_view2d_view_restore(C);
}
+ WM_manipulatormap_draw(ar->manipulator_map, C, WM_MANIPULATORMAP_DRAWSTEP_2D);
+
draw_image_cache(C, ar);
/* scrollers? */
@@ -800,10 +813,16 @@ static void image_main_region_draw(const bContext *C, ARegion *ar)
#endif
}
-static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar, wmNotifier *wmn)
+static void image_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
+ case NC_GEOM:
+ if (ELEM(wmn->data, ND_DATA, ND_SELECT))
+ WM_manipulatormap_tag_refresh(ar->manipulator_map);
+ break;
case NC_GPENCIL:
if (ELEM(wmn->action, NA_EDITED, NA_SELECTED))
ED_region_tag_redraw(ar);
@@ -813,6 +832,7 @@ static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion
case NC_IMAGE:
if (wmn->action == NA_PAINTING)
ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(ar->manipulator_map);
break;
case NC_MATERIAL:
if (wmn->data == ND_SHADING_LINKS) {
@@ -822,6 +842,11 @@ static void image_main_region_listener(bScreen *UNUSED(sc), ScrArea *sa, ARegion
ED_region_tag_redraw(ar);
}
break;
+ case NC_SCREEN:
+ if (ELEM(wmn->data, ND_LAYER)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
}
}
@@ -844,7 +869,9 @@ static void image_buttons_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void image_buttons_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void image_buttons_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -917,7 +944,9 @@ static void image_tools_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void image_tools_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void image_tools_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -968,7 +997,9 @@ static void image_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void image_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void image_header_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -1037,6 +1068,7 @@ void ED_spacetype_image(void)
st->refresh = image_refresh;
st->listener = image_listener;
st->context = image_context;
+ st->manipulators = image_widgets;
st->id_remap = image_id_remap;
/* regions: main window */
diff --git a/source/blender/editors/space_info/info_report.c b/source/blender/editors/space_info/info_report.c
index 31df9b199ea..a6b3dad239c 100644
--- a/source/blender/editors/space_info/info_report.c
+++ b/source/blender/editors/space_info/info_report.c
@@ -133,9 +133,6 @@ static int select_report_pick_invoke(bContext *C, wmOperator *op, const wmEvent
ReportList *reports = CTX_wm_reports(C);
Report *report;
- /* uses opengl */
- wmSubWindowSet(CTX_wm_window(C), ar->swinid);
-
report = info_text_pick(sinfo, ar, reports, event->mval[1]);
RNA_int_set(op->ptr, "report_index", BLI_findindex(&reports->list, report));
diff --git a/source/blender/editors/space_info/info_stats.c b/source/blender/editors/space_info/info_stats.c
index 8dc6c4229b2..c7d4fa1465b 100644
--- a/source/blender/editors/space_info/info_stats.c
+++ b/source/blender/editors/space_info/info_stats.c
@@ -49,9 +49,11 @@
#include "BKE_displist.h"
#include "BKE_DerivedMesh.h"
#include "BKE_key.h"
+#include "BKE_layer.h"
#include "BKE_paint.h"
#include "BKE_particle.h"
#include "BKE_editmesh.h"
+#include "BKE_object.h"
#include "ED_info.h"
#include "ED_armature.h"
@@ -269,9 +271,42 @@ static void stats_object_sculpt_dynamic_topology(Object *ob, SceneStats *stats)
stats->tottri = ob->sculpt->bm->totface;
}
+static void stats_dupli_object_group_count(SceneCollection *scene_collection, int *count)
+{
+ for (LinkData *link = scene_collection->objects.first; link; link = link->next) {
+ (*count)++;
+ }
+
+ SceneCollection *scene_collection_nested;
+ for (scene_collection_nested = scene_collection->scene_collections.first;
+ scene_collection_nested;
+ scene_collection_nested = scene_collection_nested->next)
+ {
+ stats_dupli_object_group_count(scene_collection_nested, count);
+ }
+}
+
+static void stats_dupli_object_group_doit(SceneCollection *scene_collection, SceneStats *stats, ParticleSystem *psys,
+ const int totgroup, int *cur)
+{
+ for (LinkData *link = scene_collection->objects.first; link; link = link->next) {
+ int tot = count_particles_mod(psys, totgroup, *cur);
+ stats_object(link->data, 0, tot, stats);
+ (*cur)++;
+ }
+
+ SceneCollection *scene_collection_nested;
+ for (scene_collection_nested = scene_collection->scene_collections.first;
+ scene_collection_nested;
+ scene_collection_nested = scene_collection_nested->next)
+ {
+ stats_dupli_object_group_doit(scene_collection_nested, stats, psys, totgroup, cur);
+ }
+}
+
static void stats_dupli_object(Base *base, Object *ob, SceneStats *stats)
{
- if (base->flag & SELECT) stats->totobjsel++;
+ if (base->flag & BASE_SELECTED) stats->totobjsel++;
if (ob->transflag & OB_DUPLIPARTS) {
/* Dupli Particles */
@@ -286,21 +321,15 @@ static void stats_dupli_object(Base *base, Object *ob, SceneStats *stats)
stats_object(part->dup_ob, 0, tot, stats);
}
else if (part->draw_as == PART_DRAW_GR && part->dup_group) {
- GroupObject *go;
- int tot, totgroup = 0, cur = 0;
-
- for (go = part->dup_group->gobject.first; go; go = go->next)
- totgroup++;
-
- for (go = part->dup_group->gobject.first; go; go = go->next) {
- tot = count_particles_mod(psys, totgroup, cur);
- stats_object(go->ob, 0, tot, stats);
- cur++;
- }
+ int totgroup = 0, cur = 0;
+
+ SceneCollection *scene_collection = part->dup_group->collection;
+ stats_dupli_object_group_count(scene_collection, &totgroup);
+ stats_dupli_object_group_doit(scene_collection, stats, psys, totgroup, &cur);
}
}
- stats_object(ob, base->flag & SELECT, 1, stats);
+ stats_object(ob, base->flag & BASE_SELECTED, 1, stats);
stats->totobj++;
}
else if (ob->parent && (ob->parent->transflag & (OB_DUPLIVERTS | OB_DUPLIFACES))) {
@@ -316,71 +345,77 @@ static void stats_dupli_object(Base *base, Object *ob, SceneStats *stats)
}
stats->totobj += tot;
- stats_object(ob, base->flag & SELECT, tot, stats);
+ stats_object(ob, base->flag & BASE_SELECTED, tot, stats);
}
else if (ob->transflag & OB_DUPLIFRAMES) {
/* Dupli Frames */
int tot = count_duplilist(ob);
stats->totobj += tot;
- stats_object(ob, base->flag & SELECT, tot, stats);
+ stats_object(ob, base->flag & BASE_SELECTED, tot, stats);
}
else if ((ob->transflag & OB_DUPLIGROUP) && ob->dup_group) {
/* Dupli Group */
int tot = count_duplilist(ob);
stats->totobj += tot;
- stats_object(ob, base->flag & SELECT, tot, stats);
+ stats_object(ob, base->flag & BASE_SELECTED, tot, stats);
}
else {
/* No Dupli */
- stats_object(ob, base->flag & SELECT, 1, stats);
+ stats_object(ob, base->flag & BASE_SELECTED, 1, stats);
stats->totobj++;
}
}
-static bool stats_is_object_dynamic_topology_sculpt(Object *ob)
+static bool stats_is_object_dynamic_topology_sculpt(Object *ob, const eObjectMode object_mode)
{
- return (ob && (ob->mode & OB_MODE_SCULPT) &&
+ return (ob &&
+ (object_mode & OB_MODE_SCULPT) &&
ob->sculpt && ob->sculpt->bm);
}
/* Statistics displayed in info header. Called regularly on scene changes. */
-static void stats_update(Scene *scene)
+static void stats_update(ViewLayer *view_layer)
{
SceneStats stats = {0};
- Object *ob = (scene->basact) ? scene->basact->object : NULL;
+ Object *ob = OBACT(view_layer);
+ Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
Base *base;
-
- if (scene->obedit) {
+
+ if (obedit) {
/* Edit Mode */
- stats_object_edit(scene->obedit, &stats);
+ stats_object_edit(ob, &stats);
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
/* Pose Mode */
stats_object_pose(ob, &stats);
}
- else if (stats_is_object_dynamic_topology_sculpt(ob)) {
+ else if (ob && stats_is_object_dynamic_topology_sculpt(ob, ob->mode)) {
/* Dynamic-topology sculpt mode */
stats_object_sculpt_dynamic_topology(ob, &stats);
}
else {
/* Objects */
- for (base = scene->base.first; base; base = base->next)
- if (scene->lay & base->lay)
+ for (base = view_layer->object_bases.first; base; base = base->next)
+ if (base->flag & BASE_VISIBLED) {
stats_dupli_object(base, base->object, &stats);
+ }
}
- if (!scene->stats)
- scene->stats = MEM_callocN(sizeof(SceneStats), "SceneStats");
+ if (!view_layer->stats) {
+ view_layer->stats = MEM_callocN(sizeof(SceneStats), "SceneStats");
+ }
- *(scene->stats) = stats;
+ *(view_layer->stats) = stats;
}
-static void stats_string(Scene *scene)
+static void stats_string(ViewLayer *view_layer)
{
#define MAX_INFO_MEM_LEN 64
- SceneStats *stats = scene->stats;
+ SceneStats *stats = view_layer->stats;
SceneStatsFmt stats_fmt;
- Object *ob = (scene->basact) ? scene->basact->object : NULL;
+ Object *ob = OBACT(view_layer);
+ Object *obedit = OBEDIT_FROM_OBACT(ob);
+ eObjectMode object_mode = ob ? ob->mode : OB_MODE_OBJECT;
uintptr_t mem_in_use, mmap_in_use;
char memstr[MAX_INFO_MEM_LEN];
char gpumemstr[MAX_INFO_MEM_LEN] = "";
@@ -441,17 +476,17 @@ static void stats_string(Scene *scene)
ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, "%s | ", versionstr);
- if (scene->obedit) {
- if (BKE_keyblock_from_object(scene->obedit))
+ if (obedit) {
+ if (BKE_keyblock_from_object(obedit))
ofs += BLI_strncpy_rlen(s + ofs, IFACE_("(Key) "), MAX_INFO_LEN - ofs);
- if (scene->obedit->type == OB_MESH) {
+ if (obedit->type == OB_MESH) {
ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs,
IFACE_("Verts:%s/%s | Edges:%s/%s | Faces:%s/%s | Tris:%s"),
stats_fmt.totvertsel, stats_fmt.totvert, stats_fmt.totedgesel, stats_fmt.totedge,
stats_fmt.totfacesel, stats_fmt.totface, stats_fmt.tottri);
}
- else if (scene->obedit->type == OB_ARMATURE) {
+ else if (obedit->type == OB_ARMATURE) {
ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%s/%s | Bones:%s/%s"), stats_fmt.totvertsel,
stats_fmt.totvert, stats_fmt.totbonesel, stats_fmt.totbone);
}
@@ -463,11 +498,11 @@ static void stats_string(Scene *scene)
ofs += BLI_strncpy_rlen(s + ofs, memstr, MAX_INFO_LEN - ofs);
ofs += BLI_strncpy_rlen(s + ofs, gpumemstr, MAX_INFO_LEN - ofs);
}
- else if (ob && (ob->mode & OB_MODE_POSE)) {
+ else if (ob && (object_mode & OB_MODE_POSE)) {
ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Bones:%s/%s %s%s"),
stats_fmt.totbonesel, stats_fmt.totbone, memstr, gpumemstr);
}
- else if (stats_is_object_dynamic_topology_sculpt(ob)) {
+ else if (stats_is_object_dynamic_topology_sculpt(ob, object_mode)) {
ofs += BLI_snprintf(s + ofs, MAX_INFO_LEN - ofs, IFACE_("Verts:%s | Tris:%s%s"), stats_fmt.totvert,
stats_fmt.tottri, gpumemstr);
}
@@ -487,19 +522,19 @@ static void stats_string(Scene *scene)
#undef MAX_INFO_LEN
-void ED_info_stats_clear(Scene *scene)
+void ED_info_stats_clear(ViewLayer *view_layer)
{
- if (scene->stats) {
- MEM_freeN(scene->stats);
- scene->stats = NULL;
+ if (view_layer->stats) {
+ MEM_freeN(view_layer->stats);
+ view_layer->stats = NULL;
}
}
-const char *ED_info_stats_string(Scene *scene)
+const char *ED_info_stats_string(Scene *UNUSED(scene), ViewLayer *view_layer)
{
- if (!scene->stats)
- stats_update(scene);
- stats_string(scene);
-
- return scene->stats->infostr;
+ if (!view_layer->stats) {
+ stats_update(view_layer);
+ }
+ stats_string(view_layer);
+ return view_layer->stats->infostr;
}
diff --git a/source/blender/editors/space_info/space_info.c b/source/blender/editors/space_info/space_info.c
index 21777fd8afa..96a0a1ed3ec 100644
--- a/source/blender/editors/space_info/space_info.c
+++ b/source/blender/editors/space_info/space_info.c
@@ -50,6 +50,9 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
+
+#include "RNA_access.h"
#include "UI_resources.h"
#include "UI_interface.h"
@@ -60,7 +63,7 @@
/* ******************** default callbacks for info space ***************** */
-static SpaceLink *info_new(const bContext *UNUSED(C))
+static SpaceLink *info_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceInfo *sinfo;
@@ -236,7 +239,9 @@ static void info_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void info_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void info_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
// SpaceInfo *sinfo = sa->spacedata.first;
@@ -251,13 +256,16 @@ static void info_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa),
}
}
-static void info_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void info_header_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
case NC_SCREEN:
- if (ELEM(wmn->data, ND_SCREENCAST, ND_ANIMPLAY))
+ if (ELEM(wmn->data, ND_LAYER, ND_SCREENCAST, ND_ANIMPLAY)) {
ED_region_tag_redraw(ar);
+ }
break;
case NC_WM:
if (wmn->data == ND_JOB)
@@ -279,6 +287,22 @@ static void info_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegi
}
+static void info_header_region_message_subscribe(
+ const bContext *UNUSED(C),
+ WorkSpace *UNUSED(workspace), Scene *UNUSED(scene),
+ bScreen *UNUSED(screen), ScrArea *UNUSED(sa), ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
+ WM_msg_subscribe_rna_anon_prop(mbus, ViewLayer, name, &msg_sub_value_region_tag_redraw);
+}
+
static void recent_files_menu_draw(const bContext *UNUSED(C), Menu *menu)
{
struct RecentFile *recent;
@@ -342,6 +366,7 @@ void ED_spacetype_info(void)
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
art->listener = info_header_listener;
+ art->message_subscribe = info_header_region_message_subscribe;
art->init = info_header_region_init;
art->draw = info_header_region_draw;
diff --git a/source/blender/editors/space_info/textview.c b/source/blender/editors/space_info/textview.c
index c801a736e31..3f35cadd820 100644
--- a/source/blender/editors/space_info/textview.c
+++ b/source/blender/editors/space_info/textview.c
@@ -39,6 +39,8 @@
#include "BLI_utildefines.h"
#include "BLI_string_utf8.h"
+#include "GPU_immediate.h"
+
#include "BIF_gl.h"
#include "BKE_text.h"
@@ -80,10 +82,16 @@ static void console_draw_sel(const char *str, const int sel[2], const int xy[2],
const int end = txt_utf8_offset_to_column(str, min_ii(sel[1], str_len_draw));
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glColor4ubv(bg_sel);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4ubv(bg_sel);
+ immRecti(pos, xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2);
- glRecti(xy[0] + (cwidth * sta), xy[1] - 2 + lheight, xy[0] + (cwidth * end), xy[1] - 2);
+ immUnbindProgram();
glDisable(GL_BLEND);
}
@@ -182,21 +190,25 @@ static int console_draw_string(ConsoleDrawContext *cdc, const char *str, int str
cdc->sel[1] = str_len - sel_orig[0];
if (bg) {
- glColor3ubv(bg);
- glRecti(0, cdc->xy[1], cdc->winx, (cdc->xy[1] + (cdc->lheight * tot_lines)));
- }
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glColor3ubv(fg);
+ immUniformColor3ubv(bg);
+ immRecti(pos, 0, cdc->xy[1], cdc->winx, (cdc->xy[1] + (cdc->lheight * tot_lines)));
+
+ immUnbindProgram();
+ }
/* last part needs no clipping */
BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0);
+ BLF_color3ubv(cdc->font_id, fg);
BLF_draw_mono(cdc->font_id, s, len, cdc->cwidth);
if (cdc->sel[0] != cdc->sel[1]) {
console_step_sel(cdc, -initial_offset);
- // glColor4ub(255, 0, 0, 96); // debug
+ /* BLF_color3ub(cdc->font_id, 255, 0, 0); // debug */
console_draw_sel(s, cdc->sel, cdc->xy, len, cdc->cwidth, cdc->lheight, bg_sel);
- glColor3ubv(fg);
}
cdc->xy[1] += cdc->lheight;
@@ -210,9 +222,8 @@ static int console_draw_string(ConsoleDrawContext *cdc, const char *str, int str
if (cdc->sel[0] != cdc->sel[1]) {
console_step_sel(cdc, len);
- // glColor4ub(0, 255, 0, 96); // debug
+ /* BLF_color3ub(cdc->font_id, 0, 255, 0); // debug */
console_draw_sel(s, cdc->sel, cdc->xy, len, cdc->cwidth, cdc->lheight, bg_sel);
- glColor3ubv(fg);
}
cdc->xy[1] += cdc->lheight;
@@ -230,12 +241,17 @@ static int console_draw_string(ConsoleDrawContext *cdc, const char *str, int str
else { /* simple, no wrap */
if (bg) {
- glColor3ubv(bg);
- glRecti(0, cdc->xy[1], cdc->winx, cdc->xy[1] + cdc->lheight);
- }
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glColor3ubv(fg);
+ immUniformColor3ubv(bg);
+ immRecti(pos, 0, cdc->xy[1], cdc->winx, cdc->xy[1] + cdc->lheight);
+
+ immUnbindProgram();
+ }
+ BLF_color3ubv(cdc->font_id, fg);
BLF_position(cdc->font_id, cdc->xy[0], cdc->lofs + cdc->xy[1], 0);
BLF_draw_mono(cdc->font_id, str, str_len, cdc->cwidth);
@@ -245,7 +261,7 @@ static int console_draw_string(ConsoleDrawContext *cdc, const char *str, int str
isel[0] = str_len - cdc->sel[1];
isel[1] = str_len - cdc->sel[0];
- // glColor4ub(255, 255, 0, 96); // debug
+ /* BLF_color3ub(cdc->font_id, 255, 255, 0); // debug */
console_draw_sel(str, isel, cdc->xy, str_len, cdc->cwidth, cdc->lheight, bg_sel);
console_step_sel(cdc, -(str_len + 1));
}
diff --git a/source/blender/editors/space_logic/CMakeLists.txt b/source/blender/editors/space_logic/CMakeLists.txt
deleted file mode 100644
index 349c003cf56..00000000000
--- a/source/blender/editors/space_logic/CMakeLists.txt
+++ /dev/null
@@ -1,58 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- ../include
- ../interface
- ../../blenkernel
- ../../blenlib
- ../../blentranslation
- ../../gpu
- ../../makesdna
- ../../makesrna
- ../../windowmanager
- ../../../../intern/guardedalloc
- ../../../../intern/glew-mx
-)
-
-set(INC_SYS
- ${GLEW_INCLUDE_PATH}
-)
-
-set(SRC
- logic_buttons.c
- logic_ops.c
- logic_window.c
- space_logic.c
-
- logic_intern.h
-)
-
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
-add_definitions(${GL_DEFINITIONS})
-
-if(WITH_INTERNATIONAL)
- add_definitions(-DWITH_INTERNATIONAL)
-endif()
-
-blender_add_lib(bf_editor_space_logic "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/space_logic/logic_buttons.c b/source/blender/editors/space_logic/logic_buttons.c
deleted file mode 100644
index 54e6e217b77..00000000000
--- a/source/blender/editors/space_logic/logic_buttons.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 by Blender Foundation
- * All rights reserved.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_logic/logic_buttons.c
- * \ingroup splogic
- */
-
-
-#include <string.h>
-#include <stdio.h>
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_context.h"
-
-#include "ED_screen.h"
-
-#include "RNA_access.h"
-#include "RNA_define.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "UI_interface.h"
-#include "UI_view2d.h"
-
-#include "interface_intern.h"
-#include "logic_intern.h"
-
-static int logic_properties_toggle_exec(bContext *C, wmOperator *UNUSED(op))
-{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = logic_has_buttons_region(sa);
-
- if (ar)
- ED_region_toggle_hidden(C, ar);
-
- return OPERATOR_FINISHED;
-}
-
-void LOGIC_OT_properties(wmOperatorType *ot)
-{
- ot->name = "Properties";
- ot->description = "Toggle the properties region visibility";
- ot->idname = "LOGIC_OT_properties";
-
- ot->exec = logic_properties_toggle_exec;
- ot->poll = ED_operator_logic_active;
-
- /* flags */
- ot->flag = 0;
-}
-
-/* Remove Logic Bricks Connections */
-/* ********************** Cut Link operator ***************** */
-
-#define LINK_RESOL 12
-static int cut_links_intersect(uiLinkLine *line, float mcoords[][2], int tot)
-{
- float coord_array[LINK_RESOL+1][2];
- int i, b;
- rcti rectlink;
-
- rectlink.xmin = (int)BLI_rctf_cent_x(&line->from->rect);
- rectlink.ymin = (int)BLI_rctf_cent_y(&line->from->rect);
- rectlink.xmax = (int)BLI_rctf_cent_x(&line->to->rect);
- rectlink.ymax = (int)BLI_rctf_cent_y(&line->to->rect);
-
- if (ui_link_bezier_points(&rectlink, coord_array, LINK_RESOL)) {
- for (i=0; i<tot-1; i++)
- for (b=0; b<LINK_RESOL-1; b++)
- if (isect_seg_seg_v2(mcoords[i], mcoords[i + 1], coord_array[b], coord_array[b + 1]) > 0)
- return 1;
- }
- return 0;
-}
-
-static int cut_links_exec(bContext *C, wmOperator *op)
-{
- ARegion *ar = CTX_wm_region(C);
- float mcoords[256][2];
- int i = 0;
-
- RNA_BEGIN (op->ptr, itemptr, "path")
- {
- float loc[2];
-
- RNA_float_get_array(&itemptr, "loc", loc);
- UI_view2d_region_to_view(&ar->v2d,
- (int)loc[0], (int)loc[1],
- &mcoords[i][0], &mcoords[i][1]);
- i++;
- if (i >= 256) break;
- }
- RNA_END;
-
- if (i>1) {
- uiBlock *block;
- uiLinkLine *line, *nline;
- uiBut *but;
- for (block = ar->uiblocks.first; block; block = block->next) {
- but = block->buttons.first;
- while (but) {
- if (but->type==UI_BTYPE_LINK && but->link) {
- for (line = but->link->lines.first; line; line = nline) {
- nline = line->next;
-
- if (cut_links_intersect(line, mcoords, i)) {
- ui_linkline_remove(line, but);
- }
- }
- }
- but = but->next;
- }
- }
- return OPERATOR_FINISHED;
- }
- return OPERATOR_CANCELLED|OPERATOR_PASS_THROUGH;
-}
-
-void LOGIC_OT_links_cut(wmOperatorType *ot)
-{
- ot->name = "Cut Links";
- ot->idname = "LOGIC_OT_links_cut";
- ot->description = "Remove logic brick connections";
-
- ot->invoke = WM_gesture_lines_invoke;
- ot->modal = WM_gesture_lines_modal;
- ot->exec = cut_links_exec;
- ot->cancel = WM_gesture_lines_cancel;
-
- ot->poll = ED_operator_logic_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER|OPTYPE_UNDO;
-
- /* properties */
- PropertyRNA *prop;
- prop = RNA_def_collection_runtime(ot->srna, "path", &RNA_OperatorMousePath, "Path", "");
- RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
- /* internal */
- RNA_def_int(ot->srna, "cursor", BC_KNIFECURSOR, 0, INT_MAX, "Cursor", "", 0, INT_MAX);
-}
-
diff --git a/source/blender/editors/space_logic/logic_intern.h b/source/blender/editors/space_logic/logic_intern.h
deleted file mode 100644
index 13146621d1b..00000000000
--- a/source/blender/editors/space_logic/logic_intern.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_logic/logic_intern.h
- * \ingroup splogic
- */
-
-
-#ifndef __LOGIC_INTERN_H__
-#define __LOGIC_INTERN_H__
-
-/* internal exports only */
-struct bContext;
-struct ARegion;
-struct ScrArea;
-struct wmOperatorType;
-
-/* space_logic.c */
-struct ARegion *logic_has_buttons_region(struct ScrArea *sa);
-
-/* logic_ops.c */
-
-/* logic_buttons.c */
-void LOGIC_OT_properties(struct wmOperatorType *ot);
-void LOGIC_OT_links_cut(struct wmOperatorType *ot);
-
-/* logic_window.c */
-void logic_buttons(struct bContext *C, struct ARegion *ar);
-void make_unique_prop_names(struct bContext *C, char *str);
-
-#endif /* __LOGIC_INTERN_H__ */
-
diff --git a/source/blender/editors/space_logic/logic_ops.c b/source/blender/editors/space_logic/logic_ops.c
deleted file mode 100644
index 7b9a8634490..00000000000
--- a/source/blender/editors/space_logic/logic_ops.c
+++ /dev/null
@@ -1,753 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_logic/logic_ops.c
- * \ingroup splogic
- */
-
-#include <stddef.h>
-
-#include "DNA_object_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_scene_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_string_utils.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "BKE_context.h"
-#include "BKE_main.h"
-#include "BKE_sca.h"
-
-#include "ED_logic.h"
-#include "ED_object.h"
-#include "ED_screen.h"
-
-#include "RNA_access.h"
-#include "RNA_define.h"
-#include "RNA_enum_types.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "UI_view2d.h"
-
-#include "logic_intern.h"
-
-/* ************* Generic Operator Helpers ************* */
-static int edit_sensor_poll(bContext *C)
-{
- PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);
-
- if (ptr.data && ID_IS_LINKED(ptr.id.data)) return 0;
- return 1;
-}
-
-static int edit_controller_poll(bContext *C)
-{
- PointerRNA ptr = CTX_data_pointer_get_type(C, "controller", &RNA_Controller);
-
- if (ptr.data && ID_IS_LINKED(ptr.id.data)) return 0;
- return 1;
-}
-
-static int edit_actuator_poll(bContext *C)
-{
- PointerRNA ptr = CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator);
-
- if (ptr.data && ID_IS_LINKED(ptr.id.data)) return 0;
- return 1;
-}
-
-static void edit_sensor_properties(wmOperatorType *ot)
-{
- RNA_def_string(ot->srna, "sensor", NULL, MAX_NAME, "Sensor", "Name of the sensor to edit");
- RNA_def_string(ot->srna, "object", NULL, MAX_NAME, "Object", "Name of the object the sensor belongs to");
-}
-
-static int edit_sensor_invoke_properties(bContext *C, wmOperator *op)
-{
- PointerRNA ptr = CTX_data_pointer_get_type(C, "sensor", &RNA_Sensor);
-
- if (RNA_struct_property_is_set(op->ptr, "sensor") && RNA_struct_property_is_set(op->ptr, "object") )
- return 1;
-
- if (ptr.data) {
- bSensor *sens = ptr.data;
- Object *ob = ptr.id.data;
-
- RNA_string_set(op->ptr, "sensor", sens->name);
- RNA_string_set(op->ptr, "object", ob->id.name + 2);
- return 1;
- }
-
- return 0;
-}
-
-static Object *edit_object_property_get(bContext *C, wmOperator *op)
-{
- char ob_name[MAX_NAME];
- Object *ob;
-
- RNA_string_get(op->ptr, "object", ob_name);
-
- /* if ob_name is valid try to find the object with this name
- * otherwise gets the active object */
- if (*ob_name)
- ob = BLI_findstring(&(CTX_data_main(C)->object), ob_name, offsetof(ID, name) + 2);
- else
- ob = ED_object_active_context(C);
-
- return ob;
-}
-
-static bSensor *edit_sensor_property_get(bContext *C, wmOperator *op, Object **ob)
-{
- char sensor_name[MAX_NAME];
- bSensor *sens;
-
- RNA_string_get(op->ptr, "sensor", sensor_name);
-
- *ob = edit_object_property_get(C, op);
- if (!*ob) return NULL;
-
- sens = BLI_findstring(&((*ob)->sensors), sensor_name, offsetof(bSensor, name));
- return sens;
-}
-
-static void edit_controller_properties(wmOperatorType *ot)
-{
- RNA_def_string(ot->srna, "controller", NULL, MAX_NAME, "Controller", "Name of the controller to edit");
- RNA_def_string(ot->srna, "object", NULL, MAX_NAME, "Object", "Name of the object the controller belongs to");
-}
-
-static int edit_controller_invoke_properties(bContext *C, wmOperator *op)
-{
- PointerRNA ptr = CTX_data_pointer_get_type(C, "controller", &RNA_Controller);
-
- if (RNA_struct_property_is_set(op->ptr, "controller") && RNA_struct_property_is_set(op->ptr, "object") )
- return 1;
-
- if (ptr.data) {
- bController *cont = ptr.data;
- Object *ob = ptr.id.data;
-
- RNA_string_set(op->ptr, "controller", cont->name);
- RNA_string_set(op->ptr, "object", ob->id.name + 2);
- return 1;
- }
-
- return 0;
-}
-
-static bController *edit_controller_property_get(bContext *C, wmOperator *op, Object **ob)
-{
- char controller_name[MAX_NAME];
- bController *cont;
-
- RNA_string_get(op->ptr, "controller", controller_name);
-
- *ob = edit_object_property_get(C, op);
- if (!*ob) return NULL;
-
- cont = BLI_findstring(&((*ob)->controllers), controller_name, offsetof(bController, name));
- return cont;
-}
-
-static void edit_actuator_properties(wmOperatorType *ot)
-{
- RNA_def_string(ot->srna, "actuator", NULL, MAX_NAME, "Actuator", "Name of the actuator to edit");
- RNA_def_string(ot->srna, "object", NULL, MAX_NAME, "Object", "Name of the object the actuator belongs to");
-}
-
-static int edit_actuator_invoke_properties(bContext *C, wmOperator *op)
-{
- PointerRNA ptr = CTX_data_pointer_get_type(C, "actuator", &RNA_Actuator);
-
- if (RNA_struct_property_is_set(op->ptr, "actuator") && RNA_struct_property_is_set(op->ptr, "object") )
- return 1;
-
- if (ptr.data) {
- bActuator *act = ptr.data;
- Object *ob = ptr.id.data;
-
- RNA_string_set(op->ptr, "actuator", act->name);
- RNA_string_set(op->ptr, "object", ob->id.name + 2);
- return 1;
- }
-
- return 0;
-}
-
-static bActuator *edit_actuator_property_get(bContext *C, wmOperator *op, Object **ob)
-{
- char actuator_name[MAX_NAME];
- bActuator *act;
-
- RNA_string_get(op->ptr, "actuator", actuator_name);
-
- *ob = edit_object_property_get(C, op);
- if (!*ob) return NULL;
-
- act = BLI_findstring(&((*ob)->actuators), actuator_name, offsetof(bActuator, name));
- return act;
-}
-
-static int logicbricks_move_property_get(wmOperator *op)
-{
- int type = RNA_enum_get(op->ptr, "direction");
-
- if (type == 1)
- return true;
- else
- return false;
-}
-
-/* ************* Add/Remove Sensor Operator ************* */
-
-static int sensor_remove_exec(bContext *C, wmOperator *op)
-{
- Object *ob = NULL;
- bSensor *sens = edit_sensor_property_get(C, op, &ob);
-
- if (!sens)
- return OPERATOR_CANCELLED;
-
- BLI_remlink(&(ob->sensors), sens);
- free_sensor(sens);
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static int sensor_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- if (edit_sensor_invoke_properties(C, op))
- return sensor_remove_exec(C, op);
- else
- return OPERATOR_CANCELLED;
-}
-
-static void LOGIC_OT_sensor_remove(wmOperatorType *ot)
-{
- ot->name = "Remove Sensor";
- ot->description = "Remove a sensor from the active object";
- ot->idname = "LOGIC_OT_sensor_remove";
-
- ot->invoke = sensor_remove_invoke;
- ot->exec = sensor_remove_exec;
- ot->poll = edit_sensor_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
- edit_sensor_properties(ot);
-}
-
-static int sensor_add_exec(bContext *C, wmOperator *op)
-{
- Object *ob;
- bSensor *sens;
- PointerRNA sens_ptr;
- PropertyRNA *prop;
- const char *sens_name;
- char name[MAX_NAME];
- int type = RNA_enum_get(op->ptr, "type");
-
- ob = edit_object_property_get(C, op);
- if (!ob)
- return OPERATOR_CANCELLED;
-
- sens = new_sensor(type);
- BLI_addtail(&(ob->sensors), sens);
-
- /* set the sensor name based on rna type enum */
- RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &sens_ptr);
- prop = RNA_struct_find_property(&sens_ptr, "type");
-
- RNA_string_get(op->ptr, "name", name);
- if (*name) {
- BLI_strncpy(sens->name, name, sizeof(sens->name));
- }
- else {
- RNA_property_enum_name(C, &sens_ptr, prop, RNA_property_enum_get(&sens_ptr, prop), &sens_name);
- BLI_strncpy(sens->name, sens_name, sizeof(sens->name));
- }
-
- BLI_uniquename(&ob->sensors, sens, DATA_("Sensor"), '.', offsetof(bSensor, name), sizeof(sens->name));
- ob->scaflag |= OB_SHOWSENS;
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static void LOGIC_OT_sensor_add(wmOperatorType *ot)
-{
- PropertyRNA *prop;
-
- /* identifiers */
- ot->name = "Add Sensor";
- ot->description = "Add a sensor to the active object";
- ot->idname = "LOGIC_OT_sensor_add";
-
- /* api callbacks */
- ot->invoke = WM_menu_invoke;
- ot->exec = sensor_add_exec;
- ot->poll = ED_operator_object_active_editable;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
-
- /* properties */
- ot->prop = prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, SENS_ALWAYS, "Type", "Type of sensor to add");
- RNA_def_enum_funcs(prop, rna_Sensor_type_itemf);
- prop = RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the Sensor to add");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_string(ot->srna, "object", NULL, MAX_NAME, "Object", "Name of the Object to add the Sensor to");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-}
-
-/* ************* Add/Remove Controller Operator ************* */
-
-static int controller_remove_exec(bContext *C, wmOperator *op)
-{
- Object *ob = NULL;
- bController *cont = edit_controller_property_get(C, op, &ob);
-
- if (!cont)
- return OPERATOR_CANCELLED;
-
- BLI_remlink(&(ob->controllers), cont);
- unlink_controller(cont);
- free_controller(cont);
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static int controller_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- if (edit_controller_invoke_properties(C, op))
- return controller_remove_exec(C, op);
- else
- return OPERATOR_CANCELLED;
-}
-
-static void LOGIC_OT_controller_remove(wmOperatorType *ot)
-{
- ot->name = "Remove Controller";
- ot->description = "Remove a controller from the active object";
- ot->idname = "LOGIC_OT_controller_remove";
-
- ot->invoke = controller_remove_invoke;
- ot->exec = controller_remove_exec;
- ot->poll = edit_controller_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
- edit_controller_properties(ot);
-}
-
-static int controller_add_exec(bContext *C, wmOperator *op)
-{
- Object *ob;
- bController *cont;
- PointerRNA cont_ptr;
- PropertyRNA *prop;
- const char *cont_name;
- int bit;
- char name[MAX_NAME];
- int type = RNA_enum_get(op->ptr, "type");
-
- ob = edit_object_property_get(C, op);
- if (!ob)
- return OPERATOR_CANCELLED;
-
- cont = new_controller(type);
- BLI_addtail(&(ob->controllers), cont);
-
- /* set the controller name based on rna type enum */
- RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &cont_ptr);
- prop = RNA_struct_find_property(&cont_ptr, "type");
-
- RNA_string_get(op->ptr, "name", name);
- if (*name) {
- BLI_strncpy(cont->name, name, sizeof(cont->name));
- }
- else {
- RNA_property_enum_name(C, &cont_ptr, prop, RNA_property_enum_get(&cont_ptr, prop), &cont_name);
- BLI_strncpy(cont->name, cont_name, sizeof(cont->name));
- }
-
- BLI_uniquename(&ob->controllers, cont, DATA_("Controller"), '.', offsetof(bController, name), sizeof(cont->name));
-
- /* set the controller state mask from the current object state.
- * A controller is always in a single state, so select the lowest bit set
- * from the object state */
- for (bit = 0; bit < OB_MAX_STATES; bit++) {
- if (ob->state & (1 << bit))
- break;
- }
- cont->state_mask = (1 << bit);
- if (cont->state_mask == 0) {
- /* shouldn't happen, object state is never 0 */
- cont->state_mask = 1;
- }
-
- ob->scaflag |= OB_SHOWCONT;
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static void LOGIC_OT_controller_add(wmOperatorType *ot)
-{
- PropertyRNA *prop;
-
- /* identifiers */
- ot->name = "Add Controller";
- ot->description = "Add a controller to the active object";
- ot->idname = "LOGIC_OT_controller_add";
-
- /* api callbacks */
- ot->invoke = WM_menu_invoke;
- ot->exec = controller_add_exec;
- ot->poll = ED_operator_object_active_editable;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
-
- /* properties */
- ot->prop = RNA_def_enum(ot->srna, "type", rna_enum_controller_type_items, CONT_LOGIC_AND, "Type", "Type of controller to add");
- prop = RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the Controller to add");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_string(ot->srna, "object", NULL, MAX_NAME, "Object", "Name of the Object to add the Controller to");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-}
-
-/* ************* Add/Remove Actuator Operator ************* */
-
-static int actuator_remove_exec(bContext *C, wmOperator *op)
-{
- Object *ob = NULL;
- bActuator *act = edit_actuator_property_get(C, op, &ob);
-
- if (!act)
- return OPERATOR_CANCELLED;
-
- BLI_remlink(&(ob->actuators), act);
- unlink_actuator(act);
- free_actuator(act);
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static int actuator_remove_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- if (edit_actuator_invoke_properties(C, op))
- return actuator_remove_exec(C, op);
- else
- return OPERATOR_CANCELLED;
-}
-
-static void LOGIC_OT_actuator_remove(wmOperatorType *ot)
-{
- ot->name = "Remove Actuator";
- ot->description = "Remove an actuator from the active object";
- ot->idname = "LOGIC_OT_actuator_remove";
-
- ot->invoke = actuator_remove_invoke;
- ot->exec = actuator_remove_exec;
- ot->poll = edit_actuator_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
- edit_actuator_properties(ot);
-}
-
-static int actuator_add_exec(bContext *C, wmOperator *op)
-{
- Object *ob;
- bActuator *act;
- PointerRNA act_ptr;
- PropertyRNA *prop;
- const char *act_name;
- char name[MAX_NAME];
- int type = RNA_enum_get(op->ptr, "type");
-
- ob = edit_object_property_get(C, op);
- if (!ob)
- return OPERATOR_CANCELLED;
-
- act = new_actuator(type);
- BLI_addtail(&(ob->actuators), act);
-
- /* set the actuator name based on rna type enum */
- RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &act_ptr);
- prop = RNA_struct_find_property(&act_ptr, "type");
-
- RNA_string_get(op->ptr, "name", name);
- if (*name) {
- BLI_strncpy(act->name, name, sizeof(act->name));
- }
- else {
- RNA_property_enum_name(C, &act_ptr, prop, RNA_property_enum_get(&act_ptr, prop), &act_name);
- BLI_strncpy(act->name, act_name, sizeof(act->name));
- }
-
- BLI_uniquename(&ob->actuators, act, DATA_("Actuator"), '.', offsetof(bActuator, name), sizeof(act->name));
- ob->scaflag |= OB_SHOWACT;
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static void LOGIC_OT_actuator_add(wmOperatorType *ot)
-{
- PropertyRNA *prop;
-
- /* identifiers */
- ot->name = "Add Actuator";
- ot->description = "Add an actuator to the active object";
- ot->idname = "LOGIC_OT_actuator_add";
-
- /* api callbacks */
- ot->invoke = WM_menu_invoke;
- ot->exec = actuator_add_exec;
- ot->poll = ED_operator_object_active_editable;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
-
- /* properties */
- ot->prop = prop = RNA_def_enum(ot->srna, "type", DummyRNA_NULL_items, CONT_LOGIC_AND, "Type", "Type of actuator to add");
- RNA_def_enum_funcs(prop, rna_Actuator_type_itemf);
- prop = RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the Actuator to add");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_string(ot->srna, "object", NULL, MAX_NAME, "Object", "Name of the Object to add the Actuator to");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-}
-
-/* ************* Move Logic Bricks Operator ************* */
-static const EnumPropertyItem logicbricks_move_direction[] = {
- {1, "UP", 0, "Move Up", ""},
- {2, "DOWN", 0, "Move Down", ""},
- {0, NULL, 0, NULL, NULL}
-};
-
-
-static int sensor_move_exec(bContext *C, wmOperator *op)
-{
- Object *ob = NULL;
- bSensor *sens = edit_sensor_property_get(C, op, &ob);
- int move_up = logicbricks_move_property_get(op);
-
- if (!sens)
- return OPERATOR_CANCELLED;
-
- sca_move_sensor(sens, ob, move_up);
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static int sensor_move_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- if (edit_sensor_invoke_properties(C, op)) {
- return sensor_move_exec(C, op);
- }
- else
- return OPERATOR_CANCELLED;
-}
-
-static void LOGIC_OT_sensor_move(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Move Sensor";
- ot->description = "Move Sensor";
- ot->idname = "LOGIC_OT_sensor_move";
-
- /* api callbacks */
- ot->invoke = sensor_move_invoke;
- ot->exec = sensor_move_exec;
- ot->poll = edit_sensor_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
-
- /* properties */
- edit_sensor_properties(ot);
- RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
-}
-
-static int controller_move_exec(bContext *C, wmOperator *op)
-{
- Object *ob = NULL;
- bController *cont = edit_controller_property_get(C, op, &ob);
- int move_up = logicbricks_move_property_get(op);
-
- if (!cont)
- return OPERATOR_CANCELLED;
-
- sca_move_controller(cont, ob, move_up);
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static int controller_move_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- if (edit_controller_invoke_properties(C, op)) {
- return controller_move_exec(C, op);
- }
- else
- return OPERATOR_CANCELLED;
-}
-
-static void LOGIC_OT_controller_move(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Move Controller";
- ot->description = "Move Controller";
- ot->idname = "LOGIC_OT_controller_move";
-
- /* api callbacks */
- ot->invoke = controller_move_invoke;
- ot->exec = controller_move_exec;
- ot->poll = edit_controller_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
-
- /* properties */
- edit_controller_properties(ot);
- RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
-}
-
-static int actuator_move_exec(bContext *C, wmOperator *op)
-{
- Object *ob = NULL;
- bActuator *act = edit_actuator_property_get(C, op, &ob);
- int move_up = logicbricks_move_property_get(op);
-
- if (!act)
- return OPERATOR_CANCELLED;
-
- sca_move_actuator(act, ob, move_up);
-
- WM_event_add_notifier(C, NC_LOGIC, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-static int actuator_move_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- if (edit_actuator_invoke_properties(C, op)) {
- return actuator_move_exec(C, op);
- }
- else
- return OPERATOR_CANCELLED;
-}
-
-static void LOGIC_OT_actuator_move(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Move Actuator";
- ot->description = "Move Actuator";
- ot->idname = "LOGIC_OT_actuator_move";
-
- /* api callbacks */
- ot->invoke = actuator_move_invoke;
- ot->exec = actuator_move_exec;
- ot->poll = edit_actuator_poll;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO | OPTYPE_INTERNAL;
-
- /* properties */
- edit_actuator_properties(ot);
- RNA_def_enum(ot->srna, "direction", logicbricks_move_direction, 1, "Direction", "Move Up or Down");
-}
-
-/* ************************ view ********************* */
-
-static int logic_view_all_exec(bContext *C, wmOperator *op)
-{
- ARegion *ar = CTX_wm_region(C);
- rctf cur_new = ar->v2d.tot;
- float aspect = BLI_rctf_size_y(&ar->v2d.cur) / BLI_rctf_size_x(&ar->v2d.cur);
- const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
-
- /* force the view2d code to zoom to width, not height */
- cur_new.ymin = cur_new.ymax - BLI_rctf_size_x(&cur_new) * aspect;
-
- UI_view2d_smooth_view(C, ar, &cur_new, smooth_viewtx);
-
- return OPERATOR_FINISHED;
-}
-
-static void LOGIC_OT_view_all(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "View All";
- ot->idname = "LOGIC_OT_view_all";
- ot->description = "Resize view so you can see all logic bricks";
-
- /* api callbacks */
- ot->exec = logic_view_all_exec;
- ot->poll = ED_operator_logic_active;
-
- /* flags */
- ot->flag = 0;
-}
-
-/* ************************* */
-
-void ED_operatortypes_logic(void)
-{
- WM_operatortype_append(LOGIC_OT_sensor_remove);
- WM_operatortype_append(LOGIC_OT_sensor_add);
- WM_operatortype_append(LOGIC_OT_sensor_move);
- WM_operatortype_append(LOGIC_OT_controller_remove);
- WM_operatortype_append(LOGIC_OT_controller_add);
- WM_operatortype_append(LOGIC_OT_controller_move);
- WM_operatortype_append(LOGIC_OT_actuator_remove);
- WM_operatortype_append(LOGIC_OT_actuator_add);
- WM_operatortype_append(LOGIC_OT_actuator_move);
- WM_operatortype_append(LOGIC_OT_view_all);
-}
diff --git a/source/blender/editors/space_logic/logic_window.c b/source/blender/editors/space_logic/logic_window.c
deleted file mode 100644
index 4dd3f369204..00000000000
--- a/source/blender/editors/space_logic/logic_window.c
+++ /dev/null
@@ -1,2601 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_logic/logic_window.c
- * \ingroup splogic
- */
-
-
-#include <string.h>
-#include <stdio.h>
-#include <stddef.h>
-#include <float.h>
-
-#include "DNA_actuator_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_property_types.h"
-#include "DNA_space_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_object_types.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_string_utils.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_action.h"
-#include "BKE_context.h"
-#include "BKE_library.h"
-#include "BKE_main.h"
-#include "BKE_sca.h"
-
-#include "ED_undo.h"
-
-#include "BLT_translation.h"
-
-#include "UI_interface.h"
-#include "UI_view2d.h"
-
-#include "RNA_access.h"
-
-/* XXX BAD BAD */
-#include "../interface/interface_intern.h"
-
-#include "logic_intern.h"
-
-#define B_REDR 1
-
-#define B_ADD_SENS 2703
-#define B_CHANGE_SENS 2704
-#define B_DEL_SENS 2705
-
-#define B_ADD_CONT 2706
-#define B_CHANGE_CONT 2707
-#define B_DEL_CONT 2708
-
-#define B_ADD_ACT 2709
-#define B_CHANGE_ACT 2710
-#define B_DEL_ACT 2711
-
-#define B_SOUNDACT_BROWSE 2712
-
-#define B_SETPROP 2714
-#define B_SETACTOR 2715
-#define B_SETMAINACTOR 2716
-#define B_SETDYNA 2717
-#define B_SET_STATE_BIT 2718
-#define B_INIT_STATE_BIT 2719
-
-/* proto */
-static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag);
-
-static void do_logic_buts(bContext *C, void *UNUSED(arg), int event)
-{
- Main *bmain= CTX_data_main(C);
- bSensor *sens;
- bController *cont;
- bActuator *act;
- Object *ob;
- int didit, bit;
-
- ob= CTX_data_active_object(C);
- if (ob==NULL) return;
-
- switch (event) {
-
- case B_SETPROP:
- /* check for inconsistent types */
- ob->gameflag &= ~(OB_SECTOR|OB_MAINACTOR|OB_DYNAMIC|OB_ACTOR);
- break;
-
- case B_SETACTOR:
- case B_SETDYNA:
- case B_SETMAINACTOR:
- ob->gameflag &= ~(OB_SECTOR|OB_PROP);
- break;
-
- case B_ADD_SENS:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- if (ob->scaflag & OB_ADDSENS) {
- ob->scaflag &= ~OB_ADDSENS;
- sens= new_sensor(SENS_ALWAYS);
- BLI_addtail(&(ob->sensors), sens);
- BLI_uniquename(&ob->sensors, sens, DATA_("Sensor"), '.', offsetof(bSensor, name), sizeof(sens->name));
- ob->scaflag |= OB_SHOWSENS;
- }
- }
-
- ED_undo_push(C, "Add sensor");
- break;
-
- case B_CHANGE_SENS:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- sens= ob->sensors.first;
- while (sens) {
- if (sens->type != sens->otype) {
- init_sensor(sens);
- sens->otype= sens->type;
- break;
- }
- sens= sens->next;
- }
- }
- break;
-
- case B_DEL_SENS:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- sens= ob->sensors.first;
- while (sens) {
- if (sens->flag & SENS_DEL) {
- BLI_remlink(&(ob->sensors), sens);
- free_sensor(sens);
- break;
- }
- sens= sens->next;
- }
- }
- ED_undo_push(C, "Delete sensor");
- break;
-
- case B_ADD_CONT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- if (ob->scaflag & OB_ADDCONT) {
- ob->scaflag &= ~OB_ADDCONT;
- cont= new_controller(CONT_LOGIC_AND);
- BLI_uniquename(&ob->controllers, cont, DATA_("Controller"), '.', offsetof(bController, name), sizeof(cont->name));
- ob->scaflag |= OB_SHOWCONT;
- BLI_addtail(&(ob->controllers), cont);
- /* set the controller state mask from the current object state.
- * A controller is always in a single state, so select the lowest bit set
- * from the object state */
- for (bit=0; bit<32; bit++) {
- if (ob->state & (1<<bit))
- break;
- }
- cont->state_mask = (1<<bit);
- if (cont->state_mask == 0) {
- /* shouldn't happen, object state is never 0 */
- cont->state_mask = 1;
- }
- }
- }
- ED_undo_push(C, "Add controller");
- break;
-
- case B_SET_STATE_BIT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- if (ob->scaflag & OB_ALLSTATE) {
- ob->scaflag &= ~OB_ALLSTATE;
- ob->state = 0x3FFFFFFF;
- }
- }
- break;
-
- case B_INIT_STATE_BIT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- if (ob->scaflag & OB_INITSTBIT) {
- ob->scaflag &= ~OB_INITSTBIT;
- ob->state = ob->init_state;
- if (!ob->state)
- ob->state = 1;
- }
- }
- break;
-
- case B_CHANGE_CONT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- cont= ob->controllers.first;
- while (cont) {
- if (cont->type != cont->otype) {
- init_controller(cont);
- cont->otype= cont->type;
- break;
- }
- cont= cont->next;
- }
- }
- break;
-
-
- case B_DEL_CONT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- cont= ob->controllers.first;
- while (cont) {
- if (cont->flag & CONT_DEL) {
- BLI_remlink(&(ob->controllers), cont);
- unlink_controller(cont);
- free_controller(cont);
- break;
- }
- cont= cont->next;
- }
- }
- ED_undo_push(C, "Delete controller");
- break;
-
- case B_ADD_ACT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- if (ob->scaflag & OB_ADDACT) {
- ob->scaflag &= ~OB_ADDACT;
- act= new_actuator(ACT_OBJECT);
- BLI_uniquename(&ob->actuators, act, DATA_("Actuator"), '.', offsetof(bActuator, name), sizeof(act->name));
- BLI_addtail(&(ob->actuators), act);
- ob->scaflag |= OB_SHOWACT;
- }
- }
- ED_undo_push(C, "Add actuator");
- break;
-
- case B_CHANGE_ACT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- act= ob->actuators.first;
- while (act) {
- if (act->type != act->otype) {
- init_actuator(act);
- act->otype= act->type;
- break;
- }
- act= act->next;
- }
- }
- break;
-
- case B_DEL_ACT:
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- act= ob->actuators.first;
- while (act) {
- if (act->flag & ACT_DEL) {
- BLI_remlink(&(ob->actuators), act);
- unlink_actuator(act);
- free_actuator(act);
- break;
- }
- act= act->next;
- }
- }
- ED_undo_push(C, "Delete actuator");
- break;
-
- case B_SOUNDACT_BROWSE:
- /* since we don't know which... */
- didit= 0;
- for (ob=bmain->object.first; ob; ob=ob->id.next) {
- act= ob->actuators.first;
- while (act) {
- if (act->type==ACT_SOUND) {
- bSoundActuator *sa= act->data;
- if (sa->sndnr) {
- ID *sound= bmain->sound.first;
- int nr= 1;
-
- if (sa->sndnr == -2) {
-// XXX activate_databrowse((ID *)bmain->sound.first, ID_SO, 0, B_SOUNDACT_BROWSE,
-// &sa->sndnr, do_logic_buts);
- break;
- }
-
- while (sound) {
- if (nr==sa->sndnr)
- break;
- nr++;
- sound= sound->next;
- }
-
- if (sa->sound)
- id_us_min(((ID *)sa->sound));
-
- sa->sound= (struct bSound *)sound;
-
- if (sound) {
- id_us_plus(sound);
- }
-
- sa->sndnr= 0;
- didit= 1;
- }
- }
- act= act->next;
- }
- if (didit)
- break;
- }
-
- break;
- }
-}
-
-
-static const char *sensor_name(int type)
-{
- switch (type) {
- case SENS_ALWAYS:
- return N_("Always");
- case SENS_NEAR:
- return N_("Near");
- case SENS_KEYBOARD:
- return N_("Keyboard");
- case SENS_PROPERTY:
- return N_("Property");
- case SENS_ARMATURE:
- return N_("Armature");
- case SENS_ACTUATOR:
- return N_("Actuator");
- case SENS_DELAY:
- return N_("Delay");
- case SENS_MOUSE:
- return N_("Mouse");
- case SENS_COLLISION:
- return N_("Collision");
- case SENS_RADAR:
- return N_("Radar");
- case SENS_RANDOM:
- return N_("Random");
- case SENS_RAY:
- return N_("Ray");
- case SENS_MESSAGE:
- return N_("Message");
- case SENS_JOYSTICK:
- return N_("Joystick");
- }
- return N_("Unknown");
-}
-
-static const char *controller_name(int type)
-{
- switch (type) {
- case CONT_LOGIC_AND:
- return N_("And");
- case CONT_LOGIC_OR:
- return N_("Or");
- case CONT_LOGIC_NAND:
- return N_("Nand");
- case CONT_LOGIC_NOR:
- return N_("Nor");
- case CONT_LOGIC_XOR:
- return N_("Xor");
- case CONT_LOGIC_XNOR:
- return N_("Xnor");
- case CONT_EXPRESSION:
- return N_("Expression");
- case CONT_PYTHON:
- return N_("Python");
- }
- return N_("Unknown");
-}
-
-static const char *actuator_name(int type)
-{
- switch (type) {
- case ACT_SHAPEACTION:
- return N_("Shape Action");
- case ACT_ACTION:
- return N_("Action");
- case ACT_OBJECT:
- return N_("Motion");
- case ACT_LAMP:
- return N_("Lamp");
- case ACT_CAMERA:
- return N_("Camera");
- case ACT_MATERIAL:
- return N_("Material");
- case ACT_SOUND:
- return N_("Sound");
- case ACT_PROPERTY:
- return N_("Property");
- case ACT_EDIT_OBJECT:
- return N_("Edit Object");
- case ACT_CONSTRAINT:
- return N_("Constraint");
- case ACT_SCENE:
- return N_("Scene");
- case ACT_GROUP:
- return N_("Group");
- case ACT_RANDOM:
- return N_("Random");
- case ACT_MESSAGE:
- return N_("Message");
- case ACT_GAME:
- return N_("Game");
- case ACT_VISIBILITY:
- return N_("Visibility");
- case ACT_2DFILTER:
- return N_("Filter 2D");
- case ACT_PARENT:
- return N_("Parent");
- case ACT_STATE:
- return N_("State");
- case ACT_ARMATURE:
- return N_("Armature");
- case ACT_STEERING:
- return N_("Steering");
- case ACT_MOUSE:
- return N_("Mouse");
- }
- return N_("Unknown");
-}
-
-static void set_sca_ob(Object *ob)
-{
- bController *cont;
- bActuator *act;
-
- cont= ob->controllers.first;
- while (cont) {
- cont->mynew= (bController *)ob;
- cont= cont->next;
- }
- act= ob->actuators.first;
- while (act) {
- act->mynew= (bActuator *)ob;
- act= act->next;
- }
-}
-
-static ID **get_selected_and_linked_obs(bContext *C, short *count, short scavisflag)
-{
- Base *base;
- Main *bmain= CTX_data_main(C);
- Scene *scene= CTX_data_scene(C);
- Object *ob, *obt, *obact= CTX_data_active_object(C);
- ID **idar;
- bSensor *sens;
- bController *cont;
- unsigned int lay;
- int a, nr, do_it;
-
- /* we need a sorted object list */
- /* set scavisflags flags in Objects to indicate these should be evaluated */
- /* also hide ob pointers in ->new entries of controllerss/actuators */
-
- *count= 0;
-
- if (scene==NULL) return NULL;
-
- ob= bmain->object.first;
- while (ob) {
- ob->scavisflag= 0;
- set_sca_ob(ob);
- ob= ob->id.next;
- }
-
- /* XXX here it checked 3d lay */
- lay= scene->lay;
-
- base= FIRSTBASE;
- while (base) {
- if (base->lay & lay) {
- if (base->flag & SELECT) {
- if (scavisflag & BUTS_SENS_SEL) base->object->scavisflag |= OB_VIS_SENS;
- if (scavisflag & BUTS_CONT_SEL) base->object->scavisflag |= OB_VIS_CONT;
- if (scavisflag & BUTS_ACT_SEL) base->object->scavisflag |= OB_VIS_ACT;
- }
- }
- base= base->next;
- }
-
- if (obact) {
- if (scavisflag & BUTS_SENS_ACT) obact->scavisflag |= OB_VIS_SENS;
- if (scavisflag & BUTS_CONT_ACT) obact->scavisflag |= OB_VIS_CONT;
- if (scavisflag & BUTS_ACT_ACT) obact->scavisflag |= OB_VIS_ACT;
- }
-
- /* BUTS_XXX_STATE are similar to BUTS_XXX_LINK for selecting the object */
- if (scavisflag & (BUTS_SENS_LINK|BUTS_CONT_LINK|BUTS_ACT_LINK|BUTS_SENS_STATE|BUTS_ACT_STATE)) {
- do_it = true;
- while (do_it) {
- do_it = false;
-
- ob= bmain->object.first;
- while (ob) {
-
- /* 1st case: select sensor when controller selected */
- if ((scavisflag & (BUTS_SENS_LINK|BUTS_SENS_STATE)) && (ob->scavisflag & OB_VIS_SENS)==0) {
- sens= ob->sensors.first;
- while (sens) {
- for (a=0; a<sens->totlinks; a++) {
- if (sens->links[a]) {
- obt= (Object *)sens->links[a]->mynew;
- if (obt && (obt->scavisflag & OB_VIS_CONT)) {
- do_it = true;
- ob->scavisflag |= OB_VIS_SENS;
- break;
- }
- }
- }
- if (do_it) break;
- sens= sens->next;
- }
- }
-
- /* 2nd case: select cont when act selected */
- if ((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_CONT)==0) {
- cont= ob->controllers.first;
- while (cont) {
- for (a=0; a<cont->totlinks; a++) {
- if (cont->links[a]) {
- obt= (Object *)cont->links[a]->mynew;
- if (obt && (obt->scavisflag & OB_VIS_ACT)) {
- do_it = true;
- ob->scavisflag |= OB_VIS_CONT;
- break;
- }
- }
- }
- if (do_it) break;
- cont= cont->next;
- }
- }
-
- /* 3rd case: select controller when sensor selected */
- if ((scavisflag & BUTS_CONT_LINK) && (ob->scavisflag & OB_VIS_SENS)) {
- sens= ob->sensors.first;
- while (sens) {
- for (a=0; a<sens->totlinks; a++) {
- if (sens->links[a]) {
- obt= (Object *)sens->links[a]->mynew;
- if (obt && (obt->scavisflag & OB_VIS_CONT)==0) {
- do_it = true;
- obt->scavisflag |= OB_VIS_CONT;
- }
- }
- }
- sens= sens->next;
- }
- }
-
- /* 4th case: select actuator when controller selected */
- if ((scavisflag & (BUTS_ACT_LINK|BUTS_ACT_STATE)) && (ob->scavisflag & OB_VIS_CONT)) {
- cont= ob->controllers.first;
- while (cont) {
- for (a=0; a<cont->totlinks; a++) {
- if (cont->links[a]) {
- obt= (Object *)cont->links[a]->mynew;
- if (obt && (obt->scavisflag & OB_VIS_ACT)==0) {
- do_it = true;
- obt->scavisflag |= OB_VIS_ACT;
- }
- }
- }
- cont= cont->next;
- }
-
- }
- ob= ob->id.next;
- }
- }
- }
-
- /* now we count */
- ob= bmain->object.first;
- while (ob) {
- if ( ob->scavisflag ) (*count)++;
- ob= ob->id.next;
- }
-
- if (*count == 0) return NULL;
- if (*count > 24) *count = 24; /* temporal */
-
- idar= MEM_callocN((*count)*sizeof(void *), "idar");
-
- ob= bmain->object.first;
- nr= 0;
-
- /* make the active object always the first one of the list */
- if (obact) {
- idar[0] = (ID *)obact;
- nr++;
- }
-
- while (ob) {
- if ((ob->scavisflag) && (ob != obact)) {
- idar[nr] = (ID *)ob;
- nr++;
- }
- if (nr >= 24) break;
- ob= ob->id.next;
- }
-
- /* just to be sure... these were set in set_sca_done_ob() */
- clear_sca_new_poins();
-
- return idar;
-}
-
-static void get_armature_bone_constraint(Object *ob, const char *posechannel, const char *constraint_name, bConstraint **constraint)
-{
- /* check that bone exist in the active object */
- if (ob->type == OB_ARMATURE && ob->pose) {
- bPoseChannel *pchan= BKE_pose_channel_find_name(ob->pose, posechannel);
- if (pchan) {
- bConstraint *con= BLI_findstring(&pchan->constraints, constraint_name, offsetof(bConstraint, name));
- if (con) {
- *constraint= con;
- }
- }
- }
- /* didn't find any */
-}
-
-static void do_sensor_menu(bContext *C, void *UNUSED(arg), int event)
-{
- SpaceLogic *slogic= CTX_wm_space_logic(C);
- ID **idar;
- Object *ob;
- bSensor *sens;
- short count, a;
-
- idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
-
- for (a=0; a<count; a++) {
- ob= (Object *)idar[a];
- if (event==0 || event==2) ob->scaflag |= OB_SHOWSENS;
- else if (event==1) ob->scaflag &= ~OB_SHOWSENS;
- }
-
- for (a=0; a<count; a++) {
- ob= (Object *)idar[a];
- sens= ob->sensors.first;
- while (sens) {
- if (event==2) sens->flag |= SENS_SHOW;
- else if (event==3) sens->flag &= ~SENS_SHOW;
- sens= sens->next;
- }
- }
-
- if (idar) MEM_freeN(idar);
-}
-
-static uiBlock *sensor_menu(bContext *C, ARegion *ar, void *UNUSED(arg))
-{
- uiBlock *block;
- int yco=0;
-
- block= UI_block_begin(C, ar, __func__, UI_EMBOSS_PULLDOWN);
- UI_block_func_butmenu_set(block, do_sensor_menu, NULL);
-
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Show Objects"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Hide Objects"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
- uiDefBut(block, UI_BTYPE_SEPR_LINE, 0, "", 0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Show Sensors"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Hide Sensors"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
-
- UI_block_direction_set(block, UI_DIR_UP);
- UI_block_end(C, block);
-
- return block;
-}
-
-static void do_controller_menu(bContext *C, void *UNUSED(arg), int event)
-{
- SpaceLogic *slogic= CTX_wm_space_logic(C);
- ID **idar;
- Object *ob;
- bController *cont;
- short count, a;
-
- idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
-
- for (a=0; a<count; a++) {
- ob= (Object *)idar[a];
- if (event==0 || event==2) ob->scaflag |= OB_SHOWCONT;
- else if (event==1) ob->scaflag &= ~OB_SHOWCONT;
- }
-
- for (a=0; a<count; a++) {
- ob= (Object *)idar[a];
- cont= ob->controllers.first;
- while (cont) {
- if (event==2) cont->flag |= CONT_SHOW;
- else if (event==3) cont->flag &= ~CONT_SHOW;
- cont= cont->next;
- }
- }
-
- if (idar) MEM_freeN(idar);
-}
-
-static uiBlock *controller_menu(bContext *C, ARegion *ar, void *UNUSED(arg))
-{
- uiBlock *block;
- int yco=0;
-
- block= UI_block_begin(C, ar, __func__, UI_EMBOSS_PULLDOWN);
- UI_block_func_butmenu_set(block, do_controller_menu, NULL);
-
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Show Objects"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Hide Objects"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
- uiDefBut(block, UI_BTYPE_SEPR_LINE, 0, "", 0, (short)(yco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Show Controllers"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 2, 2, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Hide Controllers"), 0, (short)(yco-=20), 160, 19, NULL, 0.0, 0.0, 3, 3, "");
-
- UI_block_direction_set(block, UI_DIR_UP);
- UI_block_end(C, block);
-
- return block;
-}
-
-static void do_actuator_menu(bContext *C, void *UNUSED(arg), int event)
-{
- SpaceLogic *slogic= CTX_wm_space_logic(C);
- ID **idar;
- Object *ob;
- bActuator *act;
- short count, a;
-
- idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
-
- for (a=0; a<count; a++) {
- ob= (Object *)idar[a];
- if (event==0 || event==2) ob->scaflag |= OB_SHOWACT;
- else if (event==1) ob->scaflag &= ~OB_SHOWACT;
- }
-
- for (a=0; a<count; a++) {
- ob= (Object *)idar[a];
- act= ob->actuators.first;
- while (act) {
- if (event==2) act->flag |= ACT_SHOW;
- else if (event==3) act->flag &= ~ACT_SHOW;
- act= act->next;
- }
- }
-
- if (idar) MEM_freeN(idar);
-}
-
-static uiBlock *actuator_menu(bContext *C, ARegion *ar, void *UNUSED(arg))
-{
- uiBlock *block;
- int xco=0;
-
- block= UI_block_begin(C, ar, __func__, UI_EMBOSS_PULLDOWN);
- UI_block_func_butmenu_set(block, do_actuator_menu, NULL);
-
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Show Objects"), 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 0, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Hide Objects"), 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 1, "");
- uiDefBut(block, UI_BTYPE_SEPR_LINE, 0, "", 0, (short)(xco-=6), 160, 6, NULL, 0.0, 0.0, 0, 0, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Show Actuators"), 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 2, "");
- uiDefBut(block, UI_BTYPE_BUT_MENU, 1, IFACE_("Hide Actuators"), 0, (short)(xco-=20), 160, 19, NULL, 0.0, 0.0, 1, 3, "");
-
- UI_block_direction_set(block, UI_DIR_UP);
- UI_block_end(C, block);
-
- return block;
-}
-
-static void check_controller_state_mask(bContext *UNUSED(C), void *arg1_but, void *arg2_mask)
-{
- unsigned int *cont_mask = arg2_mask;
- uiBut *but = arg1_but;
-
- /* a controller is always in a single state */
- *cont_mask = (1<<but->retval);
- but->retval = B_REDR;
-}
-
-static uiBlock *controller_state_mask_menu(bContext *C, ARegion *ar, void *arg_cont)
-{
- uiBlock *block;
- uiBut *but;
- bController *cont = arg_cont;
-
- short yco = 12, xco = 0, stbit, offset;
-
- block= UI_block_begin(C, ar, __func__, UI_EMBOSS);
-
- /* use this for a fake extra empy space around the buttons */
- uiDefBut(block, UI_BTYPE_LABEL, 0, "", -5, -5, 200, 34, NULL, 0, 0, 0, 0, "");
-
- for (offset=0; offset<15; offset += 5) {
- UI_block_align_begin(block);
- for (stbit=0; stbit<5; stbit++) {
- but = uiDefButBitI(block, UI_BTYPE_TOGGLE, (1<<(stbit+offset)), (stbit+offset), "", (short)(xco+12*stbit+13*offset), yco, 12, 12, (int *)&(cont->state_mask), 0, 0, 0, 0, "");
- UI_but_func_set(but, check_controller_state_mask, but, &(cont->state_mask));
- }
- for (stbit=0; stbit<5; stbit++) {
- but = uiDefButBitI(block, UI_BTYPE_TOGGLE, (1<<(stbit+offset+15)), (stbit+offset+15), "", (short)(xco+12*stbit+13*offset), yco-12, 12, 12, (int *)&(cont->state_mask), 0, 0, 0, 0, "");
- UI_but_func_set(but, check_controller_state_mask, but, &(cont->state_mask));
- }
- }
- UI_block_align_end(block);
-
- UI_block_direction_set(block, UI_DIR_UP);
- UI_block_end(C, block);
-
- return block;
-}
-
-static bool is_sensor_linked(uiBlock *block, bSensor *sens)
-{
- bController *cont;
- int i;
-
- for (i=0; i<sens->totlinks; i++) {
- cont = sens->links[i];
- if (UI_block_links_find_inlink(block, cont) != NULL)
- return 1;
- }
- return 0;
-}
-
-/* Sensors code */
-
-static void draw_sensor_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *logic_ptr)
-{
- uiLayout *box, *row, *sub;
- bSensor *sens= (bSensor *)ptr->data;
-
- box = uiLayoutBox(layout);
- row = uiLayoutRow(box, false);
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemR(sub, ptr, "show_expanded", UI_ITEM_R_NO_BG, "", ICON_NONE);
- if (RNA_boolean_get(ptr, "show_expanded")) {
- uiItemR(sub, ptr, "type", 0, "", ICON_NONE);
- uiItemR(sub, ptr, "name", 0, "", ICON_NONE);
- }
- else {
- uiItemL(sub, IFACE_(sensor_name(sens->type)), ICON_NONE);
- uiItemL(sub, sens->name, ICON_NONE);
- }
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, (((RNA_boolean_get(logic_ptr, "show_sensors_active_states") &&
- RNA_boolean_get(ptr, "show_expanded")) || RNA_boolean_get(ptr, "pin")) &&
- RNA_boolean_get(ptr, "active")));
- uiItemR(sub, ptr, "pin", UI_ITEM_R_NO_BG, "", ICON_NONE);
-
- if (RNA_boolean_get(ptr, "show_expanded")==0) {
- sub = uiLayoutRow(row, true);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemEnumO(sub, "LOGIC_OT_sensor_move", "", ICON_TRIA_UP, "direction", 1); // up
- uiItemEnumO(sub, "LOGIC_OT_sensor_move", "", ICON_TRIA_DOWN, "direction", 2); // down
- }
-
- sub = uiLayoutRow(row, false);
- uiItemR(sub, ptr, "active", 0, "", ICON_NONE);
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemO(sub, "", ICON_X, "LOGIC_OT_sensor_remove");
-}
-
-static void draw_sensor_internal_header(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *box, *split, *sub, *row;
-
- box = uiLayoutBox(layout);
- uiLayoutSetActive(box, RNA_boolean_get(ptr, "active"));
- split = uiLayoutSplit(box, 0.45f, false);
-
- row = uiLayoutRow(split, true);
- uiItemR(row, ptr, "use_pulse_true_level", 0, "", ICON_DOTSUP);
- uiItemR(row, ptr, "use_pulse_false_level", 0, "", ICON_DOTSDOWN);
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, (RNA_boolean_get(ptr, "use_pulse_true_level") ||
- RNA_boolean_get(ptr, "use_pulse_false_level")));
- uiItemR(sub, ptr, "tick_skip", 0, IFACE_("Skip"), ICON_NONE);
-
- row = uiLayoutRow(split, true);
- uiItemR(row, ptr, "use_level", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_tap", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- uiItemR(split, ptr, "invert", UI_ITEM_R_TOGGLE, IFACE_("Invert"), ICON_NONE);
-}
-/* sensors in alphabetical order */
-
-static void draw_sensor_actuator(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- PointerRNA settings_ptr;
-
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
- uiItemPointerR(layout, ptr, "actuator", &settings_ptr, "actuators", NULL, ICON_LOGIC);
-}
-
-static void draw_sensor_armature(uiLayout *layout, PointerRNA *ptr)
-{
- bSensor *sens = (bSensor *)ptr->data;
- bArmatureSensor *as = (bArmatureSensor *) sens->data;
- Object *ob = (Object *)ptr->id.data;
- uiLayout *row;
-
- if (ob->type != OB_ARMATURE) {
- uiItemL(layout, IFACE_("Sensor only available for armatures"), ICON_NONE);
- return;
- }
-
- if (ob->pose) {
- PointerRNA pose_ptr, pchan_ptr;
- PropertyRNA *bones_prop;
-
- RNA_pointer_create((ID *)ob, &RNA_Pose, ob->pose, &pose_ptr);
- bones_prop = RNA_struct_find_property(&pose_ptr, "bones");
-
- uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
-
- if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, as->posechannel, &pchan_ptr))
- uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
- }
- row = uiLayoutRow(layout, true);
- uiItemR(row, ptr, "test_type", 0, NULL, ICON_NONE);
- if (RNA_enum_get(ptr, "test_type") != SENS_ARM_STATE_CHANGED)
- uiItemR(row, ptr, "value", 0, NULL, ICON_NONE);
-}
-
-static void draw_sensor_collision(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- uiLayout *row, *split;
- PointerRNA main_ptr;
-
- RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
-
- split = uiLayoutSplit(layout, 0.3f, false);
- row = uiLayoutRow(split, true);
- uiItemR(row, ptr, "use_pulse", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_material", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- switch (RNA_boolean_get(ptr, "use_material")) {
- case SENS_COLLISION_PROPERTY:
- uiItemR(split, ptr, "property", 0, NULL, ICON_NONE);
- break;
- case SENS_COLLISION_MATERIAL:
- uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
- break;
- }
-}
-
-static void draw_sensor_delay(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row;
-
- row = uiLayoutRow(layout, false);
-
- uiItemR(row, ptr, "delay", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "duration", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_repeat", 0, NULL, ICON_NONE);
-}
-
-static void draw_sensor_joystick(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *col, *row;
-
- uiItemR(layout, ptr, "joystick_index", 0, NULL, ICON_NONE);
- uiItemR(layout, ptr, "event_type", 0, NULL, ICON_NONE);
-
- switch (RNA_enum_get(ptr, "event_type")) {
- case SENS_JOY_BUTTON:
- uiItemR(layout, ptr, "use_all_events", 0, NULL, ICON_NONE);
-
- col = uiLayoutColumn(layout, false);
- uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_events") == false);
- uiItemR(col, ptr, "button_number", 0, NULL, ICON_NONE);
- break;
- case SENS_JOY_AXIS:
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "axis_number", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "axis_threshold", 0, NULL, ICON_NONE);
-
- uiItemR(layout, ptr, "use_all_events", 0, NULL, ICON_NONE);
- col = uiLayoutColumn(layout, false);
- uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_events") == false);
- uiItemR(col, ptr, "axis_direction", 0, NULL, ICON_NONE);
- break;
- case SENS_JOY_HAT:
- uiItemR(layout, ptr, "hat_number", 0, NULL, ICON_NONE);
- uiItemR(layout, ptr, "use_all_events", 0, NULL, ICON_NONE);
-
- col = uiLayoutColumn(layout, false);
- uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_events") == false);
- uiItemR(col, ptr, "hat_direction", 0, NULL, ICON_NONE);
- break;
- case SENS_JOY_AXIS_SINGLE:
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "single_axis_number", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "axis_threshold", 0, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_sensor_keyboard(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- PointerRNA settings_ptr;
- uiLayout *row, *col;
-
- row = uiLayoutRow(layout, false);
- uiItemL(row, CTX_IFACE_(BLT_I18NCONTEXT_ID_WINDOWMANAGER, "Key:"), ICON_NONE);
- col = uiLayoutColumn(row, false);
- uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_keys") == false);
- uiItemR(col, ptr, "key", UI_ITEM_R_EVENT, "", ICON_NONE);
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "use_all_keys", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- col = uiLayoutColumn(layout, false);
- uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_all_keys") == false);
- row = uiLayoutRow(col, false);
- uiItemL(row, IFACE_("First Modifier:"), ICON_NONE);
- uiItemR(row, ptr, "modifier_key_1", UI_ITEM_R_EVENT, "", ICON_NONE);
-
- row = uiLayoutRow(col, false);
- uiItemL(row, IFACE_("Second Modifier:"), ICON_NONE);
- uiItemR(row, ptr, "modifier_key_2", UI_ITEM_R_EVENT, "", ICON_NONE);
-
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
- uiItemPointerR(layout, ptr, "log", &settings_ptr, "properties", NULL, ICON_NONE);
- uiItemPointerR(layout, ptr, "target", &settings_ptr, "properties", NULL, ICON_NONE);
-}
-
-static void draw_sensor_message(uiLayout *layout, PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "subject", 0, NULL, ICON_NONE);
-}
-
-static void draw_sensor_mouse(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- uiLayout *split, *split2;
- PointerRNA main_ptr;
-
- split = uiLayoutSplit(layout, 0.8f, false);
- uiItemR(split, ptr, "mouse_event", 0, NULL, ICON_NONE);
-
- if (RNA_enum_get(ptr, "mouse_event") == BL_SENS_MOUSE_MOUSEOVER_ANY) {
- uiItemR(split, ptr, "use_pulse", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.3f, false);
- uiItemR(split, ptr, "use_material", 0, "", ICON_NONE);
-
- split2 = uiLayoutSplit(split, 0.7f, false);
- if (RNA_enum_get(ptr, "use_material") == SENS_RAY_PROPERTY) {
- uiItemR(split2, ptr, "property", 0, "", ICON_NONE);
- }
- else {
- RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
- uiItemPointerR(split2, ptr, "material", &main_ptr, "materials", "", ICON_MATERIAL_DATA);
- }
- uiItemR(split2, ptr, "use_x_ray", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- }
-}
-
-static void draw_sensor_near(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row;
-
- uiItemR(layout, ptr, "property", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, true);
- uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "reset_distance", 0, NULL, ICON_NONE);
-}
-
-static void draw_sensor_property(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- PointerRNA settings_ptr;
-
- uiLayout *row;
- uiItemR(layout, ptr, "evaluation_type", 0, NULL, ICON_NONE);
-
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
- uiItemPointerR(layout, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
-
- switch (RNA_enum_get(ptr, "evaluation_type")) {
- case SENS_PROP_INTERVAL:
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "value_min", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "value_max", 0, NULL, ICON_NONE);
- break;
- case SENS_PROP_EQUAL:
- case SENS_PROP_NEQUAL:
- case SENS_PROP_LESSTHAN:
- case SENS_PROP_GREATERTHAN:
- uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);
- break;
- case SENS_PROP_CHANGED:
- break;
- }
-}
-
-static void draw_sensor_radar(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row;
-
- uiItemR(layout, ptr, "property", 0, NULL, ICON_NONE);
- uiItemR(layout, ptr, "axis", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "angle", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE);
-}
-
-static void draw_sensor_random(uiLayout *layout, PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "seed", 0, NULL, ICON_NONE);
-}
-
-static void draw_sensor_ray(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- uiLayout *split, *row;
- PointerRNA main_ptr;
-
- RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
- split = uiLayoutSplit(layout, 0.3f, false);
- uiItemR(split, ptr, "ray_type", 0, "", ICON_NONE);
- switch (RNA_enum_get(ptr, "ray_type")) {
- case SENS_RAY_PROPERTY:
- uiItemR(split, ptr, "property", 0, "", ICON_NONE);
- break;
- case SENS_RAY_MATERIAL:
- uiItemPointerR(split, ptr, "material", &main_ptr, "materials", "", ICON_MATERIAL_DATA);
- break;
- }
-
- split = uiLayoutSplit(layout, 0.3, false);
- uiItemR(split, ptr, "axis", 0, "", ICON_NONE);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "range", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_x_ray", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-}
-
-static void draw_brick_sensor(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- uiLayout *box;
-
- if (!RNA_boolean_get(ptr, "show_expanded"))
- return;
-
- draw_sensor_internal_header(layout, ptr);
-
- box = uiLayoutBox(layout);
- uiLayoutSetActive(box, RNA_boolean_get(ptr, "active"));
-
- switch (RNA_enum_get(ptr, "type")) {
-
- case SENS_ACTUATOR:
- draw_sensor_actuator(box, ptr);
- break;
- case SENS_ALWAYS:
- break;
- case SENS_ARMATURE:
- draw_sensor_armature(box, ptr);
- break;
- case SENS_COLLISION:
- draw_sensor_collision(box, ptr, C);
- break;
- case SENS_DELAY:
- draw_sensor_delay(box, ptr);
- break;
- case SENS_JOYSTICK:
- draw_sensor_joystick(box, ptr);
- break;
- case SENS_KEYBOARD:
- draw_sensor_keyboard(box, ptr);
- break;
- case SENS_MESSAGE:
- draw_sensor_message(box, ptr);
- break;
- case SENS_MOUSE:
- draw_sensor_mouse(box, ptr, C);
- break;
- case SENS_NEAR:
- draw_sensor_near(box, ptr);
- break;
- case SENS_PROPERTY:
- draw_sensor_property(box, ptr);
- break;
- case SENS_RADAR:
- draw_sensor_radar(box, ptr);
- break;
- case SENS_RANDOM:
- draw_sensor_random(box, ptr);
- break;
- case SENS_RAY:
- draw_sensor_ray(box, ptr, C);
- break;
- }
-}
-
-/* Controller code */
-static void draw_controller_header(uiLayout *layout, PointerRNA *ptr, int xco, int width, int yco)
-{
- uiLayout *box, *row, *sub;
- bController *cont= (bController *)ptr->data;
-
- char state[3];
- BLI_snprintf(state, sizeof(state), "%d", RNA_int_get(ptr, "states"));
-
- box = uiLayoutBox(layout);
- row = uiLayoutRow(box, false);
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemR(sub, ptr, "show_expanded", UI_ITEM_R_NO_BG, "", ICON_NONE);
- if (RNA_boolean_get(ptr, "show_expanded")) {
- uiItemR(sub, ptr, "type", 0, "", ICON_NONE);
- uiItemR(sub, ptr, "name", 0, "", ICON_NONE);
- /* XXX provisory for Blender 2.50Beta */
- uiDefBlockBut(uiLayoutGetBlock(layout), controller_state_mask_menu, cont, state, (short)(xco+width-44), yco, 22+22, UI_UNIT_Y, IFACE_("Set controller state index (from 1 to 30)"));
- }
- else {
- uiItemL(sub, IFACE_(controller_name(cont->type)), ICON_NONE);
- uiItemL(sub, cont->name, ICON_NONE);
- uiItemL(sub, state, ICON_NONE);
- }
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemR(sub, ptr, "use_priority", 0, "", ICON_NONE);
-
- if (RNA_boolean_get(ptr, "show_expanded")==0) {
- sub = uiLayoutRow(row, true);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemEnumO(sub, "LOGIC_OT_controller_move", "", ICON_TRIA_UP, "direction", 1); // up
- uiItemEnumO(sub, "LOGIC_OT_controller_move", "", ICON_TRIA_DOWN, "direction", 2); // down
- }
-
- sub = uiLayoutRow(row, false);
- uiItemR(sub, ptr, "active", 0, "", ICON_NONE);
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemO(sub, "", ICON_X, "LOGIC_OT_controller_remove");
-}
-
-static void draw_controller_expression(uiLayout *layout, PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "expression", 0, "", ICON_NONE);
-}
-
-static void draw_controller_python(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *split, *sub;
-
- split = uiLayoutSplit(layout, 0.3, true);
- uiItemR(split, ptr, "mode", 0, "", ICON_NONE);
- if (RNA_enum_get(ptr, "mode") == CONT_PY_SCRIPT) {
- uiItemR(split, ptr, "text", 0, "", ICON_NONE);
- }
- else {
- sub = uiLayoutSplit(split, 0.8f, false);
- uiItemR(sub, ptr, "module", 0, "", ICON_NONE);
- uiItemR(sub, ptr, "use_debug", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- }
-}
-
-static void draw_controller_state(uiLayout *UNUSED(layout), PointerRNA *UNUSED(ptr))
-{
-
-}
-
-static void draw_brick_controller(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *box;
-
- if (!RNA_boolean_get(ptr, "show_expanded"))
- return;
-
- box = uiLayoutBox(layout);
- uiLayoutSetActive(box, RNA_boolean_get(ptr, "active"));
-
- draw_controller_state(box, ptr);
-
- switch (RNA_enum_get(ptr, "type")) {
- case CONT_LOGIC_AND:
- break;
- case CONT_LOGIC_OR:
- break;
- case CONT_EXPRESSION:
- draw_controller_expression(box, ptr);
- break;
- case CONT_PYTHON:
- draw_controller_python(box, ptr);
- break;
- case CONT_LOGIC_NAND:
- break;
- case CONT_LOGIC_NOR:
- break;
- case CONT_LOGIC_XOR:
- break;
- case CONT_LOGIC_XNOR:
- break;
- }
-}
-
-/* Actuator code */
-static void draw_actuator_header(uiLayout *layout, PointerRNA *ptr, PointerRNA *logic_ptr)
-{
- uiLayout *box, *row, *sub;
- bActuator *act= (bActuator *)ptr->data;
-
- box = uiLayoutBox(layout);
- row = uiLayoutRow(box, false);
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemR(sub, ptr, "show_expanded", UI_ITEM_R_NO_BG, "", ICON_NONE);
- if (RNA_boolean_get(ptr, "show_expanded")) {
- uiItemR(sub, ptr, "type", 0, "", ICON_NONE);
- uiItemR(sub, ptr, "name", 0, "", ICON_NONE);
- }
- else {
- uiItemL(sub, IFACE_(actuator_name(act->type)), ICON_NONE);
- uiItemL(sub, act->name, ICON_NONE);
- }
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, (((RNA_boolean_get(logic_ptr, "show_actuators_active_states") &&
- RNA_boolean_get(ptr, "show_expanded")) || RNA_boolean_get(ptr, "pin")) &&
- RNA_boolean_get(ptr, "active")));
- uiItemR(sub, ptr, "pin", UI_ITEM_R_NO_BG, "", ICON_NONE);
-
- if (RNA_boolean_get(ptr, "show_expanded")==0) {
- sub = uiLayoutRow(row, true);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemEnumO(sub, "LOGIC_OT_actuator_move", "", ICON_TRIA_UP, "direction", 1); // up
- uiItemEnumO(sub, "LOGIC_OT_actuator_move", "", ICON_TRIA_DOWN, "direction", 2); // down
- }
-
- sub = uiLayoutRow(row, false);
- uiItemR(sub, ptr, "active", 0, "", ICON_NONE);
-
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "active"));
- uiItemO(sub, "", ICON_X, "LOGIC_OT_actuator_remove");
-}
-
-static void draw_actuator_action(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- PointerRNA settings_ptr;
- uiLayout *row, *sub;
-
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "play_mode", 0, "", ICON_NONE);
-
- sub = uiLayoutRow(row, true);
- uiItemR(sub, ptr, "use_force", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(sub, ptr, "use_additive", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutColumn(sub, false);
- uiLayoutSetActive(row, (RNA_boolean_get(ptr, "use_additive") || RNA_boolean_get(ptr, "use_force")));
- uiItemR(row, ptr, "use_local", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "action", 0, "", ICON_NONE);
- uiItemR(row, ptr, "use_continue_last_frame", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- if ((RNA_enum_get(ptr, "play_mode") == ACT_ACTION_FROM_PROP))
- uiItemPointerR(row, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
-
- else {
- uiItemR(row, ptr, "frame_start", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "frame_end", 0, NULL, ICON_NONE);
- }
-
- uiItemR(row, ptr, "apply_to_children", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "frame_blend_in", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "priority", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "layer", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "layer_weight", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "blend_mode", 0, "", ICON_NONE);
-
- uiItemPointerR(layout, ptr, "frame_property", &settings_ptr, "properties", NULL, ICON_NONE);
-
-#ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
- uiItemR(layout, "stride_length", 0, NULL, ICON_NONE);
-#endif
-}
-
-static void draw_actuator_armature(uiLayout *layout, PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bArmatureActuator *aa = (bArmatureActuator *) act->data;
- Object *ob = (Object *)ptr->id.data;
- bConstraint *constraint = NULL;
- PointerRNA pose_ptr, pchan_ptr;
- PropertyRNA *bones_prop = NULL;
-
- if (ob->type != OB_ARMATURE) {
- uiItemL(layout, IFACE_("Actuator only available for armatures"), ICON_NONE);
- return;
- }
-
- if (ob->pose) {
- RNA_pointer_create((ID *)ob, &RNA_Pose, ob->pose, &pose_ptr);
- bones_prop = RNA_struct_find_property(&pose_ptr, "bones");
- }
-
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
-
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_ARM_RUN:
- break;
- case ACT_ARM_ENABLE:
- case ACT_ARM_DISABLE:
- if (ob->pose) {
- uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
-
- if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
- uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
- }
- break;
- case ACT_ARM_SETTARGET:
- if (ob->pose) {
- uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
-
- if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
- uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
- }
-
- uiItemR(layout, ptr, "target", 0, NULL, ICON_NONE);
-
- /* show second target only if the constraint supports it */
- get_armature_bone_constraint(ob, aa->posechannel, aa->constraint, &constraint);
- if (constraint && constraint->type == CONSTRAINT_TYPE_KINEMATIC) {
- uiItemR(layout, ptr, "secondary_target", 0, NULL, ICON_NONE);
- }
- break;
- case ACT_ARM_SETWEIGHT:
- if (ob->pose) {
- uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
-
- if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
- uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
- }
-
- uiItemR(layout, ptr, "weight", 0, NULL, ICON_NONE);
- break;
- case ACT_ARM_SETINFLUENCE:
- if (ob->pose) {
- uiItemPointerR(layout, ptr, "bone", &pose_ptr, "bones", NULL, ICON_BONE_DATA);
-
- if (RNA_property_collection_lookup_string(&pose_ptr, bones_prop, aa->posechannel, &pchan_ptr))
- uiItemPointerR(layout, ptr, "constraint", &pchan_ptr, "constraints", NULL, ICON_CONSTRAINT_BONE);
- }
-
- uiItemR(layout, ptr, "influence", 0, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_actuator_camera(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row;
- uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "height", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "axis", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, true);
- uiItemR(row, ptr, "min", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "max", 0, NULL, ICON_NONE);
-
- uiItemR(layout, ptr, "damping", 0, NULL, ICON_NONE);
-}
-
-static void draw_actuator_constraint(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- uiLayout *row, *col, *sub, *split;
- PointerRNA main_ptr;
-
- RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
-
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_CONST_TYPE_LOC:
- uiItemR(layout, ptr, "limit", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, true);
- uiItemR(row, ptr, "limit_min", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "limit_max", 0, NULL, ICON_NONE);
-
- uiItemR(layout, ptr, "damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
- break;
-
- case ACT_CONST_TYPE_DIST:
- split = uiLayoutSplit(layout, 0.8, false);
- uiItemR(split, ptr, "direction", 0, NULL, ICON_NONE);
- row = uiLayoutRow(split, true);
- uiItemR(row, ptr, "use_local", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_normal", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- col = uiLayoutColumn(row, true);
- uiItemL(col, IFACE_("Range:"), ICON_NONE);
- uiItemR(col, ptr, "range", 0, "", ICON_NONE);
-
- col = uiLayoutColumn(row, true);
- uiItemR(col, ptr, "use_force_distance", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- sub = uiLayoutColumn(col, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_force_distance") == true);
- uiItemR(sub, ptr, "distance", 0, "", ICON_NONE);
-
- uiItemR(layout, ptr, "damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.15f, false);
- uiItemR(split, ptr, "use_material_detect", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- if (RNA_boolean_get(ptr, "use_material_detect"))
- uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
- else
- uiItemR(split, ptr, "property", 0, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.15, false);
- uiItemR(split, ptr, "use_persistent", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutRow(split, true);
- uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "damping_rotation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
- break;
-
- case ACT_CONST_TYPE_ORI:
- uiItemR(layout, ptr, "direction_axis_pos", 0, NULL, ICON_NONE);
-
- row=uiLayoutRow(layout, true);
- uiItemR(row, ptr, "damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
- uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
-
- row=uiLayoutRow(layout, false);
- uiItemR(row, ptr, "rotation_max", 0, NULL, ICON_NONE);
-
- row=uiLayoutRow(layout, true);
- uiItemR(row, ptr, "angle_min", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "angle_max", 0, NULL, ICON_NONE);
- break;
-
- case ACT_CONST_TYPE_FH:
- split = uiLayoutSplit(layout, 0.75, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "fh_damping", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
-
- uiItemR(row, ptr, "fh_height", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_fh_paralel_axis", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "direction_axis", 0, NULL, ICON_NONE);
- split = uiLayoutSplit(row, 0.9f, false);
- uiItemR(split, ptr, "fh_force", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_fh_normal", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.15, false);
- uiItemR(split, ptr, "use_material_detect", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- if (RNA_boolean_get(ptr, "use_material_detect"))
- uiItemPointerR(split, ptr, "material", &main_ptr, "materials", NULL, ICON_MATERIAL_DATA);
- else
- uiItemR(split, ptr, "property", 0, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.15, false);
- uiItemR(split, ptr, "use_persistent", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "damping_rotation", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_actuator_edit_object(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- uiLayout *row, *split, *sub;
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
-
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_EDOB_ADD_OBJECT:
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "object", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "time", 0, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "linear_velocity", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "angular_velocity", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_angular_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- break;
- case ACT_EDOB_END_OBJECT:
- break;
- case ACT_EDOB_REPLACE_MESH:
- if (ob->type != OB_MESH) {
- uiItemL(layout, IFACE_("Mode only available for mesh objects"), ICON_NONE);
- break;
- }
- split = uiLayoutSplit(layout, 0.6, false);
- uiItemR(split, ptr, "mesh", 0, NULL, ICON_NONE);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "use_replace_display_mesh", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_replace_physics_mesh", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- break;
- case ACT_EDOB_TRACK_TO:
- split = uiLayoutSplit(layout, 0.5, false);
- uiItemR(split, ptr, "track_object", 0, NULL, ICON_NONE);
- sub = uiLayoutSplit(split, 0.7f, false);
- uiItemR(sub, ptr, "time", 0, NULL, ICON_NONE);
- uiItemR(sub, ptr, "use_3d_tracking", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "up_axis", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "track_axis", 0, NULL, ICON_NONE);
- break;
- case ACT_EDOB_DYNAMICS:
- if (ob->type != OB_MESH) {
- uiItemL(layout, IFACE_("Mode only available for mesh objects"), ICON_NONE);
- break;
- }
- uiItemR(layout, ptr, "dynamic_operation", 0, NULL, ICON_NONE);
- if (RNA_enum_get(ptr, "dynamic_operation") == ACT_EDOB_SET_MASS)
- uiItemR(layout, ptr, "mass", 0, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_actuator_filter_2d(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row, *split;
-
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_2DFILTER_CUSTOMFILTER:
- uiItemR(layout, ptr, "filter_pass", 0, NULL, ICON_NONE);
- uiItemR(layout, ptr, "glsl_shader", 0, NULL, ICON_NONE);
- break;
- case ACT_2DFILTER_MOTIONBLUR:
- split=uiLayoutSplit(layout, 0.75f, true);
- row = uiLayoutRow(split, false);
- uiLayoutSetActive(row, RNA_boolean_get(ptr, "use_motion_blur") == true);
- uiItemR(row, ptr, "motion_blur_factor", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_motion_blur", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- break;
- default: // all other 2D Filters
- uiItemR(layout, ptr, "filter_pass", 0, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_actuator_game(uiLayout *layout, PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
- if (ELEM(RNA_enum_get(ptr, "mode"), ACT_GAME_LOAD, ACT_GAME_SCREENSHOT))
- uiItemR(layout, ptr, "filename", 0, NULL, ICON_NONE);
-}
-
-static void draw_actuator_message(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- Object *ob;
- PointerRNA main_ptr, settings_ptr;
- uiLayout *row;
-
- RNA_main_pointer_create(CTX_data_main(C), &main_ptr);
-
- ob = (Object *)ptr->id.data;
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-
- uiItemPointerR(layout, ptr, "to_property", &main_ptr, "objects", NULL, ICON_OBJECT_DATA);
- uiItemR(layout, ptr, "subject", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, true);
- uiItemR(row, ptr, "body_type", 0, NULL, ICON_NONE);
-
- if (RNA_enum_get(ptr, "body_type") == ACT_MESG_MESG)
- uiItemR(row, ptr, "body_message", 0, "", ICON_NONE);
- else // mode == ACT_MESG_PROP
- uiItemPointerR(row, ptr, "body_property", &settings_ptr, "properties", "", ICON_NONE);
-}
-
-static void draw_actuator_motion(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob;
- PointerRNA settings_ptr;
- uiLayout *split, *row, *col, *sub;
- int physics_type;
-
- ob = (Object *)ptr->id.data;
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
- physics_type = RNA_enum_get(&settings_ptr, "physics_type");
-
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
-
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_OBJECT_NORMAL:
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "offset_location", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_location", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "offset_rotation", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_rotation", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- if (ELEM(physics_type, OB_BODY_TYPE_DYNAMIC, OB_BODY_TYPE_RIGID, OB_BODY_TYPE_SOFT)) {
- uiItemL(layout, IFACE_("Dynamic Object Settings:"), ICON_NONE);
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "force", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_force", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "torque", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_torque", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "linear_velocity", 0, NULL, ICON_NONE);
- row = uiLayoutRow(split, true);
- uiItemR(row, ptr, "use_local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_add_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "angular_velocity", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_angular_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- uiItemR(layout, ptr, "damping", 0, NULL, ICON_NONE);
- }
- break;
- case ACT_OBJECT_SERVO:
- uiItemR(layout, ptr, "reference_object", 0, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "linear_velocity", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_linear_velocity", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "use_servo_limit_x", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- sub = uiLayoutColumn(col, true);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_servo_limit_x") == true);
- uiItemR(sub, ptr, "force_max_x", 0, NULL, ICON_NONE);
- uiItemR(sub, ptr, "force_min_x", 0, NULL, ICON_NONE);
-
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "use_servo_limit_y", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- sub = uiLayoutColumn(col, true);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_servo_limit_y") == true);
- uiItemR(sub, ptr, "force_max_y", 0, NULL, ICON_NONE);
- uiItemR(sub, ptr, "force_min_y", 0, NULL, ICON_NONE);
-
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "use_servo_limit_z", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- sub = uiLayoutColumn(col, true);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_servo_limit_z") == true);
- uiItemR(sub, ptr, "force_max_z", 0, NULL, ICON_NONE);
- uiItemR(sub, ptr, "force_min_z", 0, NULL, ICON_NONE);
-
- //XXXACTUATOR missing labels from original 2.49 ui (e.g. Servo, Min, Max, Fast)
- //Layout designers willing to help on that, please compare with 2.49 ui
- // (since the old code is going to be deleted ... soon)
-
- col = uiLayoutColumn(layout, true);
- uiItemR(col, ptr, "proportional_coefficient", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
- uiItemR(col, ptr, "integral_coefficient", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
- uiItemR(col, ptr, "derivate_coefficient", UI_ITEM_R_SLIDER, NULL, ICON_NONE);
- break;
- case ACT_OBJECT_CHARACTER:
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "offset_location", 0, NULL, ICON_NONE);
- row = uiLayoutRow(split, true);
- uiItemR(row, ptr, "use_local_location", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_add_character_location", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- uiItemR(row, ptr, "offset_rotation", 0, NULL, ICON_NONE);
- uiItemR(split, ptr, "use_local_rotation", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
-
- split = uiLayoutSplit(layout, 0.9, false);
- row = uiLayoutRow(split, false);
- split = uiLayoutSplit(row, 0.7, false);
- uiItemL(split, "", ICON_NONE); /*Just use this for some spacing */
- uiItemR(split, ptr, "use_character_jump", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_actuator_parent(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row, *sub;
-
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
-
- if (RNA_enum_get(ptr, "mode") == ACT_PARENT_SET) {
- uiItemR(layout, ptr, "object", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "use_compound", 0, NULL, ICON_NONE);
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, RNA_boolean_get(ptr, "use_compound") == true);
- uiItemR(sub, ptr, "use_ghost", 0, NULL, ICON_NONE);
- }
-}
-
-static void draw_actuator_property(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- bActuator *act = (bActuator *)ptr->data;
- bPropertyActuator *pa = (bPropertyActuator *) act->data;
- Object *ob_from= pa->ob;
- PointerRNA settings_ptr, obj_settings_ptr;
-
- uiLayout *row, *sub;
-
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
- uiItemPointerR(layout, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
-
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_PROP_TOGGLE:
- case ACT_PROP_LEVEL:
- break;
- case ACT_PROP_ADD:
- uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);
- break;
- case ACT_PROP_ASSIGN:
- uiItemR(layout, ptr, "value", 0, NULL, ICON_NONE);
- break;
- case ACT_PROP_COPY:
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "object", 0, NULL, ICON_NONE);
- if (ob_from) {
- RNA_pointer_create((ID *)ob_from, &RNA_GameObjectSettings, ob_from, &obj_settings_ptr);
- uiItemPointerR(row, ptr, "object_property", &obj_settings_ptr, "properties", NULL, ICON_NONE);
- }
- else {
- sub = uiLayoutRow(row, false);
- uiLayoutSetActive(sub, false);
- uiItemR(sub, ptr, "object_property", 0, NULL, ICON_NONE);
- }
- break;
- }
-}
-
-static void draw_actuator_random(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob;
- PointerRNA settings_ptr;
- uiLayout *row;
-
- ob = (Object *)ptr->id.data;
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-
- row = uiLayoutRow(layout, false);
-
- uiItemR(row, ptr, "seed", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "distribution", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemPointerR(row, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
-
- switch (RNA_enum_get(ptr, "distribution")) {
- case ACT_RANDOM_BOOL_CONST:
- uiItemR(row, ptr, "use_always_true", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_BOOL_UNIFORM:
- uiItemL(row, IFACE_("Choose between true and false, 50% chance each"), ICON_NONE);
- break;
-
- case ACT_RANDOM_BOOL_BERNOUILLI:
- uiItemR(row, ptr, "chance", 0, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_INT_CONST:
- uiItemR(row, ptr, "int_value", 0, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_INT_UNIFORM:
- uiItemR(row, ptr, "int_min", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "int_max", 0, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_INT_POISSON:
- uiItemR(row, ptr, "int_mean", 0, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_FLOAT_CONST:
- uiItemR(row, ptr, "float_value", 0, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_FLOAT_UNIFORM:
- uiItemR(row, ptr, "float_min", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "float_max", 0, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_FLOAT_NORMAL:
- uiItemR(row, ptr, "float_mean", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "standard_derivation", 0, NULL, ICON_NONE);
- break;
-
- case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
- uiItemR(row, ptr, "half_life_time", 0, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_actuator_scene(uiLayout *layout, PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
-
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_SCENE_CAMERA:
- uiItemR(layout, ptr, "camera", 0, NULL, ICON_NONE);
- break;
- case ACT_SCENE_RESTART:
- break;
- default: // ACT_SCENE_SET|ACT_SCENE_ADD_FRONT|ACT_SCENE_ADD_BACK|ACT_SCENE_REMOVE|ACT_SCENE_SUSPEND|ACT_SCENE_RESUME
- uiItemR(layout, ptr, "scene", 0, NULL, ICON_NONE);
- break;
- }
-}
-
-static void draw_actuator_shape_action(uiLayout *layout, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- PointerRNA settings_ptr;
- uiLayout *row;
-
- if (ob->type != OB_MESH) {
- uiItemL(layout, IFACE_("Actuator only available for mesh objects"), ICON_NONE);
- return;
- }
-
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "mode", 0, "", ICON_NONE);
- uiItemR(row, ptr, "action", 0, "", ICON_NONE);
- uiItemR(row, ptr, "use_continue_last_frame", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- if ((RNA_enum_get(ptr, "mode") == ACT_ACTION_FROM_PROP))
- uiItemPointerR(row, ptr, "property", &settings_ptr, "properties", NULL, ICON_NONE);
-
- else {
- uiItemR(row, ptr, "frame_start", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "frame_end", 0, NULL, ICON_NONE);
- }
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "frame_blend_in", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "priority", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemPointerR(row, ptr, "frame_property", &settings_ptr, "properties", NULL, ICON_NONE);
-
-#ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
- uiItemR(row, "stride_length", 0, NULL, ICON_NONE);
-#endif
-}
-
-static void draw_actuator_sound(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- uiLayout *row, *col;
-
- uiTemplateID(layout, C, ptr, "sound", NULL, "SOUND_OT_open", NULL, UI_TEMPLATE_ID_FILTER_ALL);
- if (!RNA_pointer_get(ptr, "sound").data) {
- uiItemL(layout, IFACE_("Select a sound from the list or load a new one"), ICON_NONE);
- return;
- }
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "volume", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "pitch", 0, NULL, ICON_NONE);
-
- uiItemR(layout, ptr, "use_sound_3d", 0, NULL, ICON_NONE);
-
- col = uiLayoutColumn(layout, false);
- uiLayoutSetActive(col, RNA_boolean_get(ptr, "use_sound_3d") == true);
-
- row = uiLayoutRow(col, false);
- uiItemR(row, ptr, "gain_3d_min", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "gain_3d_max", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(col, false);
- uiItemR(row, ptr, "distance_3d_reference", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "distance_3d_max", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(col, false);
- uiItemR(row, ptr, "rolloff_factor_3d", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "cone_outer_gain_3d", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(col, false);
- uiItemR(row, ptr, "cone_outer_angle_3d", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "cone_inner_angle_3d", 0, NULL, ICON_NONE);
-}
-
-static void draw_actuator_state(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *split;
- Object *ob = (Object *)ptr->id.data;
- PointerRNA settings_ptr;
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-
- split = uiLayoutSplit(layout, 0.35, false);
- uiItemR(split, ptr, "operation", 0, NULL, ICON_NONE);
-
- uiTemplateLayers(split, ptr, "states", &settings_ptr, "used_states", 0);
-}
-
-static void draw_actuator_visibility(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row;
- row = uiLayoutRow(layout, false);
-
- uiItemR(row, ptr, "use_visible", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "use_occlusion", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "apply_to_children", 0, NULL, ICON_NONE);
-}
-
-static void draw_actuator_steering(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row;
- uiLayout *col;
-
- uiItemR(layout, ptr, "mode", 0, NULL, ICON_NONE);
- uiItemR(layout, ptr, "target", 0, NULL, ICON_NONE);
- uiItemR(layout, ptr, "navmesh", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "distance", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "velocity", 0, NULL, ICON_NONE);
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "acceleration", 0, NULL, ICON_NONE);
- uiItemR(row, ptr, "turn_speed", 0, NULL, ICON_NONE);
-
- row = uiLayoutRow(layout, false);
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "facing", 0, NULL, ICON_NONE);
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "facing_axis", 0, NULL, ICON_NONE);
- if (!RNA_boolean_get(ptr, "facing")) {
- uiLayoutSetActive(col, false);
- }
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "normal_up", 0, NULL, ICON_NONE);
- if (!RNA_pointer_get(ptr, "navmesh").data) {
- uiLayoutSetActive(col, false);
- }
-
- row = uiLayoutRow(layout, false);
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "self_terminated", 0, NULL, ICON_NONE);
- if (RNA_enum_get(ptr, "mode")==ACT_STEERING_PATHFOLLOWING) {
- col = uiLayoutColumn(row, false);
- uiItemR(col, ptr, "update_period", 0, NULL, ICON_NONE);
- }
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "lock_z_velocity", 1, NULL, ICON_NONE);
- row = uiLayoutRow(layout, false);
- uiItemR(row, ptr, "show_visualization", 0, NULL, ICON_NONE);
- if (RNA_enum_get(ptr, "mode") != ACT_STEERING_PATHFOLLOWING) {
- uiLayoutSetActive(row, false);
- }
-}
-
-static void draw_actuator_mouse(uiLayout *layout, PointerRNA *ptr)
-{
- uiLayout *row, *col, *subcol, *split, *subsplit;
-
- uiItemR(layout, ptr, "mode", 0, NULL, 0);
-
- switch (RNA_enum_get(ptr, "mode")) {
- case ACT_MOUSE_VISIBILITY:
- row = uiLayoutRow(layout, 0);
- uiItemR(row, ptr, "visible", UI_ITEM_R_TOGGLE, NULL, 0);
- break;
-
- case ACT_MOUSE_LOOK:
- /* X axis */
- row = uiLayoutRow(layout, 0);
- col = uiLayoutColumn(row, 1);
-
- uiItemR(col, ptr, "use_axis_x", UI_ITEM_R_TOGGLE, NULL, 0);
-
- subcol = uiLayoutColumn(col, 1);
- uiLayoutSetActive(subcol, RNA_boolean_get(ptr, "use_axis_x")==1);
- uiItemR(subcol, ptr, "sensitivity_x", 0, NULL, 0);
- uiItemR(subcol, ptr, "threshold_x", 0, NULL, 0);
-
- uiItemR(subcol, ptr, "min_x", 0, NULL, 0);
- uiItemR(subcol, ptr, "max_x", 0, NULL, 0);
-
- uiItemR(subcol, ptr, "object_axis_x", 0, NULL, 0);
-
- /* Y Axis */
- col = uiLayoutColumn(row, 1);
-
- uiItemR(col, ptr, "use_axis_y", UI_ITEM_R_TOGGLE, NULL, 0);
-
- subcol = uiLayoutColumn(col, 1);
- uiLayoutSetActive(subcol, RNA_boolean_get(ptr, "use_axis_y")==1);
- uiItemR(subcol, ptr, "sensitivity_y", 0, NULL, 0);
- uiItemR(subcol, ptr, "threshold_y", 0, NULL, 0);
-
- uiItemR(subcol, ptr, "min_y", 0, NULL, 0);
- uiItemR(subcol, ptr, "max_y", 0, NULL, 0);
-
- uiItemR(subcol, ptr, "object_axis_y", 0, NULL, 0);
-
- /* Lower options */
- row = uiLayoutRow(layout, 0);
- split = uiLayoutSplit(row, 0.5, 0);
-
- subsplit = uiLayoutSplit(split, 0.5, 1);
- uiLayoutSetActive(subsplit, RNA_boolean_get(ptr, "use_axis_x")==1);
- uiItemR(subsplit, ptr, "local_x", UI_ITEM_R_TOGGLE, NULL, 0);
- uiItemR(subsplit, ptr, "reset_x", UI_ITEM_R_TOGGLE, NULL, 0);
-
- subsplit = uiLayoutSplit(split, 0.5, 1);
- uiLayoutSetActive(subsplit, RNA_boolean_get(ptr, "use_axis_y")==1);
- uiItemR(subsplit, ptr, "local_y", UI_ITEM_R_TOGGLE, NULL, 0);
- uiItemR(subsplit, ptr, "reset_y", UI_ITEM_R_TOGGLE, NULL, 0);
-
- break;
- }
-}
-
-static void draw_brick_actuator(uiLayout *layout, PointerRNA *ptr, bContext *C)
-{
- uiLayout *box;
-
- if (!RNA_boolean_get(ptr, "show_expanded"))
- return;
-
- box = uiLayoutBox(layout);
- uiLayoutSetActive(box, RNA_boolean_get(ptr, "active"));
-
- switch (RNA_enum_get(ptr, "type")) {
- case ACT_ACTION:
- draw_actuator_action(box, ptr);
- break;
- case ACT_ARMATURE:
- draw_actuator_armature(box, ptr);
- break;
- case ACT_CAMERA:
- draw_actuator_camera(box, ptr);
- break;
- case ACT_CONSTRAINT:
- draw_actuator_constraint(box, ptr, C);
- break;
- case ACT_EDIT_OBJECT:
- draw_actuator_edit_object(box, ptr);
- break;
- case ACT_2DFILTER:
- draw_actuator_filter_2d(box, ptr);
- break;
- case ACT_GAME:
- draw_actuator_game(box, ptr);
- break;
- case ACT_MESSAGE:
- draw_actuator_message(box, ptr, C);
- break;
- case ACT_OBJECT:
- draw_actuator_motion(box, ptr);
- break;
- case ACT_PARENT:
- draw_actuator_parent(box, ptr);
- break;
- case ACT_PROPERTY:
- draw_actuator_property(box, ptr);
- break;
- case ACT_RANDOM:
- draw_actuator_random(box, ptr);
- break;
- case ACT_SCENE:
- draw_actuator_scene(box, ptr);
- break;
- case ACT_SHAPEACTION:
- draw_actuator_shape_action(box, ptr);
- break;
- case ACT_SOUND:
- draw_actuator_sound(box, ptr, C);
- break;
- case ACT_STATE:
- draw_actuator_state(box, ptr);
- break;
- case ACT_VISIBILITY:
- draw_actuator_visibility(box, ptr);
- break;
- case ACT_STEERING:
- draw_actuator_steering(box, ptr);
- break;
- case ACT_MOUSE:
- draw_actuator_mouse(box, ptr);
- break;
- }
-}
-
-void logic_buttons(bContext *C, ARegion *ar)
-{
- SpaceLogic *slogic= CTX_wm_space_logic(C);
- Object *ob= CTX_data_active_object(C);
- ID **idar;
- PointerRNA logic_ptr, settings_ptr, object_ptr;
- uiLayout *layout, *row, *box;
- uiBlock *block;
- uiBut *but;
- char uiblockstr[32];
- short a, count;
- int xco, yco, width, height;
-
- if (ob==NULL) return;
-
- RNA_pointer_create(NULL, &RNA_SpaceLogicEditor, slogic, &logic_ptr);
- idar= get_selected_and_linked_obs(C, &count, slogic->scaflag);
-
- BLI_snprintf(uiblockstr, sizeof(uiblockstr), "buttonswin %p", (void *)ar);
- block= UI_block_begin(C, ar, uiblockstr, UI_EMBOSS);
- UI_block_func_handle_set(block, do_logic_buts, NULL);
- UI_block_bounds_set_normal(block, U.widget_unit/2);
-
- /* loop over all objects and set visible/linked flags for the logic bricks */
- for (a=0; a<count; a++) {
- bActuator *act;
- bSensor *sens;
- bController *cont;
- int iact;
- short flag;
-
- ob= (Object *)idar[a];
-
- /* clean ACT_LINKED and ACT_VISIBLE of all potentially visible actuators so that we can determine which is actually linked/visible */
- act = ob->actuators.first;
- while (act) {
- act->flag &= ~(ACT_LINKED|ACT_VISIBLE);
- act = act->next;
- }
- /* same for sensors */
- sens= ob->sensors.first;
- while (sens) {
- sens->flag &= ~(SENS_VISIBLE);
- sens = sens->next;
- }
-
- /* mark the linked and visible actuators */
- cont= ob->controllers.first;
- while (cont) {
- flag = ACT_LINKED;
-
- /* this controller is visible, mark all its actuator */
- if ((ob->scaflag & OB_ALLSTATE) || (ob->state & cont->state_mask))
- flag |= ACT_VISIBLE;
-
- for (iact=0; iact<cont->totlinks; iact++) {
- act = cont->links[iact];
- if (act)
- act->flag |= flag;
- }
- cont = cont->next;
- }
- }
-
- /* ****************** Controllers ****************** */
-
- xco= 21 * U.widget_unit; yco= - U.widget_unit / 2; width= 15 * U.widget_unit;
- layout= UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, 0, UI_style_get());
- row = uiLayoutRow(layout, true);
-
- uiDefBlockBut(block, controller_menu, NULL, IFACE_("Controllers"), xco - U.widget_unit / 2, yco, width, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
-
- uiItemR(row, &logic_ptr, "show_controllers_selected_objects", 0, IFACE_("Sel"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_controllers_active_object", 0, IFACE_("Act"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_controllers_linked_controller", 0, IFACE_("Link"), ICON_NONE);
-
- for (a=0; a<count; a++) {
- bController *cont;
- PointerRNA ptr;
- uiLayout *split, *subsplit, *col;
-
-
- ob= (Object *)idar[a];
-
- /* only draw the controller common header if "use_visible" */
- if ( (ob->scavisflag & OB_VIS_CONT) == 0) {
- continue;
- }
-
- /* Drawing the Controller Header common to all Selected Objects */
-
- RNA_pointer_create((ID *)ob, &RNA_GameObjectSettings, ob, &settings_ptr);
-
- split = uiLayoutSplit(layout, 0.05f, false);
- uiItemR(split, &settings_ptr, "show_state_panel", UI_ITEM_R_NO_BG, "", ICON_DISCLOSURE_TRI_RIGHT);
-
- row = uiLayoutRow(split, true);
- uiDefButBitS(block, UI_BTYPE_TOGGLE, OB_SHOWCONT, B_REDR, ob->id.name + 2, (short)(xco - U.widget_unit / 2), yco, (short)(width - 1.5f * U.widget_unit), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, TIP_("Object name, click to show/hide controllers"));
-
- RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
- uiLayoutSetContextPointer(row, "object", &object_ptr);
- uiItemMenuEnumO(row, C, "LOGIC_OT_controller_add", "type", IFACE_("Add Controller"), ICON_NONE);
-
- if (RNA_boolean_get(&settings_ptr, "show_state_panel")) {
-
- box = uiLayoutBox(layout);
- split = uiLayoutSplit(box, 0.2f, false);
-
- col = uiLayoutColumn(split, false);
- uiItemL(col, IFACE_("Visible"), ICON_NONE);
- uiItemL(col, IFACE_("Initial"), ICON_NONE);
-
- subsplit = uiLayoutSplit(split, 0.85f, false);
- col = uiLayoutColumn(subsplit, false);
- row = uiLayoutRow(col, false);
- uiLayoutSetActive(row, RNA_boolean_get(&settings_ptr, "use_all_states") == false);
- uiTemplateGameStates(row, &settings_ptr, "states_visible", &settings_ptr, "used_states", 0);
- row = uiLayoutRow(col, false);
- uiTemplateGameStates(row, &settings_ptr, "states_initial", &settings_ptr, "used_states", 0);
-
- col = uiLayoutColumn(subsplit, false);
- uiItemR(col, &settings_ptr, "use_all_states", UI_ITEM_R_TOGGLE, NULL, ICON_NONE);
- uiItemR(col, &settings_ptr, "show_debug_state", 0, "", ICON_NONE);
- }
-
- /* End of Drawing the Controller Header common to all Selected Objects */
-
- if ((ob->scaflag & OB_SHOWCONT) == 0) continue;
-
-
- uiItemS(layout);
-
- for (cont= ob->controllers.first; cont; cont=cont->next) {
- RNA_pointer_create((ID *)ob, &RNA_Controller, cont, &ptr);
-
- if (!(ob->scaflag & OB_ALLSTATE) && !(ob->state & cont->state_mask))
- continue;
-
- /* use two nested splits to align inlinks/links properly */
- split = uiLayoutSplit(layout, 0.05f, false);
-
- /* put inlink button to the left */
- col = uiLayoutColumn(split, false);
- uiLayoutSetActive(col, RNA_boolean_get(&ptr, "active"));
- uiLayoutSetAlignment(col, UI_LAYOUT_ALIGN_LEFT);
- but = uiDefIconBut(block, UI_BTYPE_INLINK, 0, ICON_INLINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, cont, LINK_CONTROLLER, 0, 0, 0, "");
- if (!RNA_boolean_get(&ptr, "active")) {
- UI_but_flag_enable(but, UI_BUT_SCA_LINK_GREY);
- }
-
- //col = uiLayoutColumn(split, true);
- /* nested split for middle and right columns */
- subsplit = uiLayoutSplit(split, 0.95f, false);
-
- col = uiLayoutColumn(subsplit, true);
- uiLayoutSetContextPointer(col, "controller", &ptr);
-
- /* should make UI template for controller header.. function will do for now */
-// draw_controller_header(col, &ptr);
- draw_controller_header(col, &ptr, xco, width, yco); //provisory for 2.50 beta
-
- /* draw the brick contents */
- draw_brick_controller(col, &ptr);
-
- /* put link button to the right */
- col = uiLayoutColumn(subsplit, false);
- uiLayoutSetActive(col, RNA_boolean_get(&ptr, "active"));
- uiLayoutSetAlignment(col, UI_LAYOUT_ALIGN_LEFT);
- but = uiDefIconBut(block, UI_BTYPE_LINK, 0, ICON_LINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
- if (!RNA_boolean_get(&ptr, "active")) {
- UI_but_flag_enable(but, UI_BUT_SCA_LINK_GREY);
- }
-
- UI_but_link_set(but, NULL, (void ***)&(cont->links), &cont->totlinks, LINK_CONTROLLER, LINK_ACTUATOR);
-
- }
- }
- UI_block_layout_resolve(block, NULL, &yco); /* stores final height in yco */
- height = yco;
-
- /* ****************** Sensors ****************** */
-
- xco= U.widget_unit / 2; yco= -U.widget_unit / 2; width= 17 * U.widget_unit;
- layout= UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, 0, UI_style_get());
- row = uiLayoutRow(layout, true);
-
- uiDefBlockBut(block, sensor_menu, NULL, IFACE_("Sensors"), xco - U.widget_unit / 2, yco, 15 * U.widget_unit, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
-
- uiItemR(row, &logic_ptr, "show_sensors_selected_objects", 0, IFACE_("Sel"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_sensors_active_object", 0, IFACE_("Act"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_sensors_linked_controller", 0, IFACE_("Link"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_sensors_active_states", 0, IFACE_("State"), ICON_NONE);
-
- for (a=0; a<count; a++) {
- bSensor *sens;
- PointerRNA ptr;
-
- ob= (Object *)idar[a];
-
- /* only draw the sensor common header if "use_visible" */
- if ((ob->scavisflag & OB_VIS_SENS) == 0) continue;
-
- row = uiLayoutRow(layout, true);
- uiDefButBitS(block, UI_BTYPE_TOGGLE, OB_SHOWSENS, B_REDR, ob->id.name + 2, (short)(xco - U.widget_unit / 2), yco, (short)(width - 1.5f * U.widget_unit), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, TIP_("Object name, click to show/hide sensors"));
-
- RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
- uiLayoutSetContextPointer(row, "object", &object_ptr);
- uiItemMenuEnumO(row, C, "LOGIC_OT_sensor_add", "type", IFACE_("Add Sensor"), ICON_NONE);
-
- if ((ob->scaflag & OB_SHOWSENS) == 0) continue;
-
- uiItemS(layout);
-
- for (sens= ob->sensors.first; sens; sens=sens->next) {
- RNA_pointer_create((ID *)ob, &RNA_Sensor, sens, &ptr);
-
- if ((ob->scaflag & OB_ALLSTATE) ||
- !(slogic->scaflag & BUTS_SENS_STATE) ||
- (sens->totlinks == 0) || /* always display sensor without links so that is can be edited */
- (sens->flag & SENS_PIN && slogic->scaflag & BUTS_SENS_STATE) || /* states can hide some sensors, pinned sensors ignore the visible state */
- (is_sensor_linked(block, sens))
- )
- { // gotta check if the current state is visible or not
- uiLayout *split, *col;
-
- /* make as visible, for move operator */
- sens->flag |= SENS_VISIBLE;
-
- split = uiLayoutSplit(layout, 0.95f, false);
- col = uiLayoutColumn(split, true);
- uiLayoutSetContextPointer(col, "sensor", &ptr);
-
- /* should make UI template for sensor header.. function will do for now */
- draw_sensor_header(col, &ptr, &logic_ptr);
-
- /* draw the brick contents */
- draw_brick_sensor(col, &ptr, C);
-
- /* put link button to the right */
- col = uiLayoutColumn(split, false);
- uiLayoutSetActive(col, RNA_boolean_get(&ptr, "active"));
- but = uiDefIconBut(block, UI_BTYPE_LINK, 0, ICON_LINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, NULL, 0, 0, 0, 0, "");
- if (!RNA_boolean_get(&ptr, "active")) {
- UI_but_flag_enable(but, UI_BUT_SCA_LINK_GREY);
- }
-
- /* use old-school uiButtons for links for now */
- UI_but_link_set(but, NULL, (void ***)&sens->links, &sens->totlinks, LINK_SENSOR, LINK_CONTROLLER);
- }
- }
- }
- UI_block_layout_resolve(block, NULL, &yco); /* stores final height in yco */
- height = MIN2(height, yco);
-
- /* ****************** Actuators ****************** */
-
- xco= 40 * U.widget_unit; yco= -U.widget_unit / 2; width= 17 * U.widget_unit;
- layout= UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, xco, yco, width, 20, 0, UI_style_get());
- row = uiLayoutRow(layout, true);
-
- uiDefBlockBut(block, actuator_menu, NULL, IFACE_("Actuators"), xco - U.widget_unit / 2, yco, 15 * U.widget_unit, UI_UNIT_Y, ""); /* replace this with uiLayout stuff later */
-
- uiItemR(row, &logic_ptr, "show_actuators_selected_objects", 0, IFACE_("Sel"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_actuators_active_object", 0, IFACE_("Act"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_actuators_linked_controller", 0, IFACE_("Link"), ICON_NONE);
- uiItemR(row, &logic_ptr, "show_actuators_active_states", 0, IFACE_("State"), ICON_NONE);
-
- for (a=0; a<count; a++) {
- bActuator *act;
- PointerRNA ptr;
-
- ob= (Object *)idar[a];
-
- /* only draw the actuator common header if "use_visible" */
- if ((ob->scavisflag & OB_VIS_ACT) == 0) {
- continue;
- }
-
- row = uiLayoutRow(layout, true);
- uiDefButBitS(block, UI_BTYPE_TOGGLE, OB_SHOWACT, B_REDR, ob->id.name + 2, (short)(xco - U.widget_unit / 2), yco, (short)(width - 1.5f * U.widget_unit), UI_UNIT_Y, &ob->scaflag, 0, 31, 0, 0, TIP_("Object name, click to show/hide actuators"));
-
- RNA_pointer_create((ID *)ob, &RNA_Object, ob, &object_ptr);
- uiLayoutSetContextPointer(row, "object", &object_ptr);
- uiItemMenuEnumO(row, C, "LOGIC_OT_actuator_add", "type", IFACE_("Add Actuator"), ICON_NONE);
-
- if ((ob->scaflag & OB_SHOWACT) == 0) continue;
-
- uiItemS(layout);
-
- for (act= ob->actuators.first; act; act=act->next) {
-
- RNA_pointer_create((ID *)ob, &RNA_Actuator, act, &ptr);
-
- if ((ob->scaflag & OB_ALLSTATE) ||
- !(slogic->scaflag & BUTS_ACT_STATE) ||
- !(act->flag & ACT_LINKED) || /* always display actuators without links so that is can be edited */
- (act->flag & ACT_VISIBLE) || /* this actuator has visible connection, display it */
- (act->flag & ACT_PIN && slogic->scaflag & BUTS_ACT_STATE) /* states can hide some sensors, pinned sensors ignore the visible state */
- )
- { // gotta check if the current state is visible or not
- uiLayout *split, *col;
-
- /* make as visible, for move operator */
- act->flag |= ACT_VISIBLE;
-
- split = uiLayoutSplit(layout, 0.05f, false);
-
- /* put inlink button to the left */
- col = uiLayoutColumn(split, false);
- uiLayoutSetActive(col, RNA_boolean_get(&ptr, "active"));
- but = uiDefIconBut(block, UI_BTYPE_INLINK, 0, ICON_INLINK, 0, 0, UI_UNIT_X, UI_UNIT_Y, act, LINK_ACTUATOR, 0, 0, 0, "");
- if (!RNA_boolean_get(&ptr, "active")) {
- UI_but_flag_enable(but, UI_BUT_SCA_LINK_GREY);
- }
-
- col = uiLayoutColumn(split, true);
- uiLayoutSetContextPointer(col, "actuator", &ptr);
-
- /* should make UI template for actuator header.. function will do for now */
- draw_actuator_header(col, &ptr, &logic_ptr);
-
- /* draw the brick contents */
- draw_brick_actuator(col, &ptr, C);
-
- }
- }
- }
- UI_block_layout_resolve(block, NULL, &yco); /* stores final height in yco */
- height = MIN2(height, yco);
-
- UI_view2d_totRect_set(&ar->v2d, 57.5f * U.widget_unit, height - U.widget_unit);
-
- /* set the view */
- UI_view2d_view_ortho(&ar->v2d);
-
- UI_block_links_compose(block);
-
- UI_block_end(C, block);
- UI_block_draw(C, block);
-
- /* restore view matrix */
- UI_view2d_view_restore(C);
-
- if (idar) MEM_freeN(idar);
-}
-
diff --git a/source/blender/editors/space_logic/space_logic.c b/source/blender/editors/space_logic/space_logic.c
deleted file mode 100644
index 12ca141128b..00000000000
--- a/source/blender/editors/space_logic/space_logic.c
+++ /dev/null
@@ -1,375 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_logic/space_logic.c
- * \ingroup splogic
- */
-
-
-#include <string.h>
-#include <stdio.h>
-
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-
-#include "DNA_gpencil_types.h"
-
-#include "BKE_context.h"
-#include "BKE_library.h"
-#include "BKE_screen.h"
-
-#include "ED_space_api.h"
-#include "ED_screen.h"
-
-#include "BIF_gl.h"
-
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "UI_resources.h"
-#include "UI_view2d.h"
-
-#include "logic_intern.h"
-
-/* ******************** manage regions ********************* */
-
-ARegion *logic_has_buttons_region(ScrArea *sa)
-{
- ARegion *ar, *arnew;
-
- ar = BKE_area_find_region_type(sa, RGN_TYPE_UI);
- if (ar) return ar;
-
- /* add subdiv level; after header */
- ar = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
-
- /* is error! */
- if (ar == NULL) return NULL;
-
- arnew= MEM_callocN(sizeof(ARegion), "buttons for image");
-
- BLI_insertlinkafter(&sa->regionbase, ar, arnew);
- arnew->regiontype = RGN_TYPE_UI;
- arnew->alignment = RGN_ALIGN_RIGHT;
-
- arnew->flag = RGN_FLAG_HIDDEN;
-
- return arnew;
-}
-
-/* ******************** default callbacks for image space ***************** */
-
-static SpaceLink *logic_new(const bContext *C)
-{
- ScrArea *sa= CTX_wm_area(C);
- ARegion *ar;
- SpaceLogic *slogic;
-
- slogic= MEM_callocN(sizeof(SpaceLogic), "initlogic");
- slogic->spacetype= SPACE_LOGIC;
-
- /* default options */
- slogic->scaflag = ((BUTS_SENS_SEL|BUTS_SENS_ACT|BUTS_SENS_LINK) |
- (BUTS_CONT_SEL|BUTS_CONT_ACT|BUTS_CONT_LINK) |
- (BUTS_ACT_SEL|BUTS_ACT_ACT|BUTS_ACT_LINK) |
- (BUTS_SENS_STATE|BUTS_ACT_STATE));
-
-
- /* header */
- ar= MEM_callocN(sizeof(ARegion), "header for logic");
-
- BLI_addtail(&slogic->regionbase, ar);
- ar->regiontype= RGN_TYPE_HEADER;
- ar->alignment= RGN_ALIGN_BOTTOM;
-
- /* buttons/list view */
- ar= MEM_callocN(sizeof(ARegion), "buttons for logic");
-
- BLI_addtail(&slogic->regionbase, ar);
- ar->regiontype= RGN_TYPE_UI;
- ar->alignment= RGN_ALIGN_RIGHT;
-
- /* main region */
- ar= MEM_callocN(sizeof(ARegion), "main region for logic");
-
- BLI_addtail(&slogic->regionbase, ar);
- ar->regiontype= RGN_TYPE_WINDOW;
-
- ar->v2d.tot.xmin = 0.0f;
- ar->v2d.tot.ymax = 0.0f;
- ar->v2d.tot.xmax = 1150.0f;
- ar->v2d.tot.ymin = ( 1150.0f/(float)sa->winx ) * (float)-sa->winy;
-
- ar->v2d.cur = ar->v2d.tot;
-
- ar->v2d.min[0] = 1.0f;
- ar->v2d.min[1] = 1.0f;
-
- ar->v2d.max[0] = 32000.0f;
- ar->v2d.max[1] = 32000.0f;
-
- ar->v2d.minzoom = 0.5f;
- ar->v2d.maxzoom = 1.5f;
-
- ar->v2d.scroll = (V2D_SCROLL_RIGHT | V2D_SCROLL_BOTTOM);
- ar->v2d.keepzoom = V2D_KEEPZOOM | V2D_LIMITZOOM | V2D_KEEPASPECT;
- ar->v2d.keeptot = V2D_KEEPTOT_BOUNDS;
- ar->v2d.align = V2D_ALIGN_NO_POS_Y | V2D_ALIGN_NO_NEG_X;
- ar->v2d.keepofs = V2D_KEEPOFS_Y;
-
- return (SpaceLink *)slogic;
-}
-
-/* not spacelink itself */
-static void logic_free(SpaceLink *UNUSED(sl))
-{
-// Spacelogic *slogic= (SpaceLogic *) sl;
-
-// if (slogic->gpd)
-// XXX BKE_gpencil_free(slogic->gpd);
-
-}
-
-
-/* spacetype; init callback */
-static void logic_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
-{
-
-}
-
-static SpaceLink *logic_duplicate(SpaceLink *sl)
-{
- SpaceLogic *slogicn= MEM_dupallocN(sl);
-
- return (SpaceLink *)slogicn;
-}
-
-static void logic_operatortypes(void)
-{
- WM_operatortype_append(LOGIC_OT_properties);
- WM_operatortype_append(LOGIC_OT_links_cut);
-}
-
-static void logic_keymap(struct wmKeyConfig *keyconf)
-{
- wmKeyMap *keymap = WM_keymap_find(keyconf, "Logic Editor", SPACE_LOGIC, 0);
-
- WM_keymap_add_item(keymap, "LOGIC_OT_properties", NKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "LOGIC_OT_links_cut", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_menu(keymap, "LOGIC_MT_logicbricks_add", AKEY, KM_PRESS, KM_SHIFT, 0);
-
- WM_keymap_add_item(keymap, "LOGIC_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
-#ifdef WITH_INPUT_NDOF
- WM_keymap_add_item(keymap, "LOGIC_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
-#endif
-}
-
-static void logic_refresh(const bContext *UNUSED(C), ScrArea *UNUSED(sa))
-{
-// SpaceLogic *slogic= CTX_wm_space_logic(C);
-// Object *obedit= CTX_data_edit_object(C);
-
-}
-
-static void logic_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
-{
- /* context changes */
- switch (wmn->category) {
- case NC_LOGIC:
- ED_region_tag_redraw(ar);
- break;
- case NC_SCENE:
- switch (wmn->data) {
- case ND_FRAME:
- ED_region_tag_redraw(ar);
- break;
-
- case ND_OB_ACTIVE:
- ED_region_tag_redraw(ar);
- break;
- }
- break;
- case NC_OBJECT:
- break;
- case NC_ID:
- if (wmn->action == NA_RENAME)
- ED_region_tag_redraw(ar);
- break;
- }
-}
-
-static int logic_context(const bContext *UNUSED(C), const char *UNUSED(member), bContextDataResult *UNUSED(result))
-{
-// SpaceLogic *slogic= CTX_wm_space_logic(C);
- return 0;
-}
-
-/************************** main region ***************************/
-
-
-/* add handlers, stuff you only do once or on area/region changes */
-static void logic_main_region_init(wmWindowManager *wm, ARegion *ar)
-{
- wmKeyMap *keymap;
-
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
-
- /* own keymaps */
- keymap = WM_keymap_find(wm->defaultconf, "Logic Editor", SPACE_LOGIC, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
-}
-
-static void logic_main_region_draw(const bContext *C, ARegion *ar)
-{
- /* draw entirely, view changes should be handled here */
-// SpaceLogic *slogic= CTX_wm_space_logic(C);
- View2D *v2d= &ar->v2d;
- View2DScrollers *scrollers;
-
- /* clear and setup matrix */
- UI_ThemeClearColor(TH_BACK);
- glClear(GL_COLOR_BUFFER_BIT);
-
- UI_view2d_view_ortho(v2d);
-
- logic_buttons((bContext *)C, ar);
-
- /* reset view matrix */
- UI_view2d_view_restore(C);
-
- /* scrollers */
- scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
- UI_view2d_scrollers_draw(C, v2d, scrollers);
- UI_view2d_scrollers_free(scrollers);
-
-}
-
-
-/* *********************** buttons region ************************ */
-
-/* add handlers, stuff you only do once or on area/region changes */
-static void logic_buttons_region_init(wmWindowManager *wm, ARegion *ar)
-{
- wmKeyMap *keymap;
-
- ED_region_panels_init(wm, ar);
-
- keymap = WM_keymap_find(wm->defaultconf, "Logic Editor", SPACE_LOGIC, 0);
- WM_event_add_keymap_handler(&ar->handlers, keymap);
-}
-
-static void logic_buttons_region_draw(const bContext *C, ARegion *ar)
-{
- ED_region_panels(C, ar, NULL, -1, true);
-}
-
-/************************* header region **************************/
-
-/* add handlers, stuff you only do once or on area/region changes */
-static void logic_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
-{
- ED_region_header_init(ar);
-}
-
-static void logic_header_region_draw(const bContext *C, ARegion *ar)
-{
- ED_region_header(C, ar);
-}
-
-/**************************** spacetype *****************************/
-
-static void logic_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
-{
- SpaceLogic *slog = (SpaceLogic *)slink;
-
- if (!ELEM(GS(old_id->name), ID_GD)) {
- return;
- }
-
- if ((ID *)slog->gpd == old_id) {
- slog->gpd = (bGPdata *)new_id;
- id_us_min(old_id);
- id_us_plus(new_id);
- }
-}
-
-/* only called once, from space/spacetypes.c */
-void ED_spacetype_logic(void)
-{
- SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype logic");
- ARegionType *art;
-
- st->spaceid = SPACE_LOGIC;
- strncpy(st->name, "Logic", BKE_ST_MAXNAME);
-
- st->new = logic_new;
- st->free = logic_free;
- st->init = logic_init;
- st->duplicate = logic_duplicate;
- st->operatortypes = logic_operatortypes;
- st->keymap = logic_keymap;
- st->refresh = logic_refresh;
- st->context = logic_context;
- st->id_remap = logic_id_remap;
-
- /* regions: main window */
- art = MEM_callocN(sizeof(ARegionType), "spacetype logic region");
- art->regionid = RGN_TYPE_WINDOW;
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES | ED_KEYMAP_VIEW2D;
- art->init = logic_main_region_init;
- art->draw = logic_main_region_draw;
- art->listener = logic_listener;
-
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: listview/buttons */
- art = MEM_callocN(sizeof(ARegionType), "spacetype logic region");
- art->regionid = RGN_TYPE_UI;
- art->prefsizex= 220; // XXX
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
- art->listener = logic_listener;
- art->init = logic_buttons_region_init;
- art->draw = logic_buttons_region_draw;
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: header */
- art= MEM_callocN(sizeof(ARegionType), "spacetype logic region");
- art->regionid = RGN_TYPE_HEADER;
- art->prefsizey = HEADERY;
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
- art->init = logic_header_region_init;
- art->draw = logic_header_region_draw;
-
- BLI_addhead(&st->regiontypes, art);
-
- BKE_spacetype_register(st);
-}
-
-
diff --git a/source/blender/editors/space_nla/nla_channels.c b/source/blender/editors/space_nla/nla_channels.c
index 27f275c15dd..1cc3d5142f5 100644
--- a/source/blender/editors/space_nla/nla_channels.c
+++ b/source/blender/editors/space_nla/nla_channels.c
@@ -45,6 +45,7 @@
#include "BKE_nla.h"
#include "BKE_context.h"
#include "BKE_global.h"
+#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_report.h"
@@ -123,40 +124,37 @@ static int mouse_nla_channels(bContext *C, bAnimContext *ac, float x, int channe
}
case ANIMTYPE_OBJECT:
{
- bDopeSheet *ads = (bDopeSheet *)ac->data;
- Scene *sce = (Scene *)ads->source;
+ ViewLayer *view_layer = ac->view_layer;
Base *base = (Base *)ale->data;
Object *ob = base->object;
AnimData *adt = ob->adt;
- if (nlaedit_is_tweakmode_on(ac) == 0 && (ob->restrictflag & OB_RESTRICT_SELECT) == 0) {
+ if (nlaedit_is_tweakmode_on(ac) == 0 && (base->flag & BASE_SELECTABLED)) {
/* set selection status */
if (selectmode == SELECT_INVERT) {
/* swap select */
- base->flag ^= SELECT;
- ob->flag = base->flag;
+ ED_object_base_select(base, BA_INVERT);
+ BKE_scene_object_base_flag_sync_from_base(base);
if (adt) adt->flag ^= ADT_UI_SELECTED;
}
else {
- Base *b;
-
/* deselect all */
/* TODO: should this deselect all other types of channels too? */
- for (b = sce->base.first; b; b = b->next) {
- b->flag &= ~SELECT;
- b->object->flag = b->flag;
+ for (Base *b = view_layer->object_bases.first; b; b = b->next) {
+ ED_object_base_select(b, BA_DESELECT);
+ BKE_scene_object_base_flag_sync_from_base(b);
if (b->object->adt) b->object->adt->flag &= ~(ADT_UI_SELECTED | ADT_UI_ACTIVE);
}
/* select object now */
- base->flag |= SELECT;
- ob->flag |= SELECT;
+ ED_object_base_select(base, BA_SELECT);
+ BKE_scene_object_base_flag_sync_from_base(base);
if (adt) adt->flag |= ADT_UI_SELECTED;
}
/* change active object - regardless of whether it is now selected [T37883] */
- ED_base_object_activate(C, base); /* adds notifier */
+ ED_object_base_activate(C, base); /* adds notifier */
if ((adt) && (adt->flag & ADT_UI_SELECTED))
adt->flag |= ADT_UI_ACTIVE;
diff --git a/source/blender/editors/space_nla/nla_draw.c b/source/blender/editors/space_nla/nla_draw.c
index d33b84f76c0..a7773aaaed5 100644
--- a/source/blender/editors/space_nla/nla_draw.c
+++ b/source/blender/editors/space_nla/nla_draw.c
@@ -53,9 +53,12 @@
#include "ED_anim_api.h"
#include "ED_keyframes_draw.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_draw.h"
+
#include "WM_types.h"
#include "UI_interface.h"
@@ -97,50 +100,68 @@ void nla_action_get_color(AnimData *adt, bAction *act, float color[4])
}
/* draw the keyframes in the specified Action */
-static void nla_action_draw_keyframes(AnimData *adt, bAction *act, View2D *v2d, float y, float ymin, float ymax)
+static void nla_action_draw_keyframes(AnimData *adt, bAction *act, float y, float ymin, float ymax)
{
- DLRBT_Tree keys;
- ActKeyColumn *ak;
- float xscale, f1, f2;
- float color[4];
-
/* get a list of the keyframes with NLA-scaling applied */
+ DLRBT_Tree keys;
BLI_dlrbTree_init(&keys);
action_to_keylist(adt, act, &keys, NULL);
BLI_dlrbTree_linkedlist_sync(&keys);
-
+
if (ELEM(NULL, act, keys.first))
return;
-
+
/* draw a darkened region behind the strips
* - get and reset the background color, this time without the alpha to stand out better
* (amplified alpha is used instead)
*/
+ float color[4];
nla_action_get_color(adt, act, color);
color[3] *= 2.5f;
-
- glColor4fv(color);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4fv(color);
+
/* - draw a rect from the first to the last frame (no extra overlaps for now)
* that is slightly stumpier than the track background (hardcoded 2-units here)
*/
- f1 = ((ActKeyColumn *)keys.first)->cfra;
- f2 = ((ActKeyColumn *)keys.last)->cfra;
-
- glRectf(f1, ymin + 2, f2, ymax - 2);
-
-
- /* get View2D scaling factor */
- UI_view2d_scale_get(v2d, &xscale, NULL);
-
- /* for now, color is hardcoded to be black */
- glColor3f(0.0f, 0.0f, 0.0f);
-
- /* just draw each keyframe as a simple dot (regardless of the selection status)
- * - size is 3.0f which is smaller than the editable keyframes, so that there is a distinction
- */
- for (ak = keys.first; ak; ak = ak->next)
- draw_keyframe_shape(ak->cfra, y, xscale, 3.0f, 0, ak->key_type, KEYFRAME_SHAPE_FRAME, 1.0f);
-
+ float f1 = ((ActKeyColumn *)keys.first)->cfra;
+ float f2 = ((ActKeyColumn *)keys.last)->cfra;
+
+ immRectf(pos_id, f1, ymin + 2, f2, ymax - 2);
+ immUnbindProgram();
+
+ /* count keys before drawing */
+ /* Note: It's safe to cast DLRBT_Tree, as it's designed to degrade down to a ListBase */
+ unsigned int key_ct = BLI_listbase_count((ListBase *)&keys);
+
+ if (key_ct > 0) {
+ format = immVertexFormat();
+ pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int size_id = GWN_vertformat_attr_add(format, "size", GWN_COMP_F32, 1, GWN_FETCH_FLOAT);
+ unsigned int color_id = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ unsigned int outline_color_id = GWN_vertformat_attr_add(format, "outlineColor", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ immBindBuiltinProgram(GPU_SHADER_KEYFRAME_DIAMOND);
+ GPU_enable_program_point_size();
+ immBegin(GWN_PRIM_POINTS, key_ct);
+
+ /* - disregard the selection status of keyframes so they draw a certain way
+ * - size is 6.0f which is smaller than the editable keyframes, so that there is a distinction
+ */
+ for (ActKeyColumn *ak = keys.first; ak; ak = ak->next) {
+ draw_keyframe_shape(ak->cfra, y, 6.0f, false, ak->key_type, KEYFRAME_SHAPE_FRAME, 1.0f,
+ pos_id, size_id, color_id, outline_color_id);
+ }
+
+ immEnd();
+ GPU_disable_program_point_size();
+ immUnbindProgram();
+ }
+
/* free icons */
BLI_dlrbTree_free(&keys);
}
@@ -148,57 +169,70 @@ static void nla_action_draw_keyframes(AnimData *adt, bAction *act, View2D *v2d,
/* Strip Markers ------------------------ */
/* Markers inside an action strip */
-static void nla_actionclip_draw_markers(NlaStrip *strip, float yminc, float ymaxc)
+static void nla_actionclip_draw_markers(NlaStrip *strip, float yminc, float ymaxc, int shade, const bool dashed)
{
- bAction *act = strip->act;
- TimeMarker *marker;
-
- if (ELEM(NULL, strip->act, strip->act->markers.first))
+ const bAction *act = strip->act;
+
+ if (ELEM(NULL, act, act->markers.first))
return;
-
- for (marker = act->markers.first; marker; marker = marker->next) {
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ if (dashed) {
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+ }
+ else {
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ }
+ immUniformThemeColorShade(TH_STRIP_SELECT, shade);
+
+ immBeginAtMost(GWN_PRIM_LINES, BLI_listbase_count(&act->markers) * 2);
+ for (TimeMarker *marker = act->markers.first; marker; marker = marker->next) {
if ((marker->frame > strip->actstart) && (marker->frame < strip->actend)) {
float frame = nlastrip_get_frame(strip, marker->frame, NLATIME_CONVERT_MAP);
-
+
/* just a simple line for now */
- // XXX: draw a triangle instead...
- fdrawline(frame, yminc + 1, frame, ymaxc - 1);
+ /* XXX: draw a triangle instead... */
+ immVertex2f(shdr_pos, frame, yminc + 1);
+ immVertex2f(shdr_pos, frame, ymaxc - 1);
}
}
+ immEnd();
+
+ immUnbindProgram();
}
/* Markers inside a NLA-Strip */
static void nla_strip_draw_markers(NlaStrip *strip, float yminc, float ymaxc)
{
- glLineWidth(2.0);
+ glLineWidth(2.0f);
if (strip->type == NLASTRIP_TYPE_CLIP) {
/* try not to be too conspicuous, while being visible enough when transforming */
- if (strip->flag & NLASTRIP_FLAG_SELECT)
- UI_ThemeColorShade(TH_STRIP_SELECT, -60);
- else
- UI_ThemeColorShade(TH_STRIP_SELECT, -40);
-
- setlinestyle(3);
-
+ int shade = (strip->flag & NLASTRIP_FLAG_SELECT) ? -60 : -40;
+
/* just draw the markers in this clip */
- nla_actionclip_draw_markers(strip, yminc, ymaxc);
-
- setlinestyle(0);
+ nla_actionclip_draw_markers(strip, yminc, ymaxc, shade, true);
}
else if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
/* just a solid color, so that it is very easy to spot */
- UI_ThemeColorShade(TH_STRIP_SELECT, 20);
-
+ int shade = 20;
/* draw the markers in the first level of strips only (if they are actions) */
for (NlaStrip *nls = strip->strips.first; nls; nls = nls->next) {
if (nls->type == NLASTRIP_TYPE_CLIP) {
- nla_actionclip_draw_markers(nls, yminc, ymaxc);
+ nla_actionclip_draw_markers(nls, yminc, ymaxc, shade, false);
}
}
}
- glLineWidth(1.0);
+ glLineWidth(1.0f);
}
/* Strips (Proper) ---------------------- */
@@ -266,15 +300,12 @@ static void nla_strip_get_color_inside(AnimData *adt, NlaStrip *strip, float col
}
/* helper call for drawing influence/time control curves for a given NLA-strip */
-static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc)
+static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc, unsigned int pos)
{
const float yheight = ymaxc - yminc;
- /* drawing color is simply a light-gray */
- // TODO: is this color suitable?
- // XXX nasty hacked color for now... which looks quite bad too...
- glColor3f(0.7f, 0.7f, 0.7f);
-
+ immUniformColor3f(0.7f, 0.7f, 0.7f);
+
/* draw with AA'd line */
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
@@ -286,68 +317,102 @@ static void nla_draw_strip_curves(NlaStrip *strip, float yminc, float ymaxc)
/* plot the curve (over the strip's main region) */
if (fcu) {
- glBegin(GL_LINE_STRIP);
-
+ immBegin(GWN_PRIM_LINE_STRIP, abs((int)(strip->end - strip->start) + 1));
+
/* sample at 1 frame intervals, and draw
* - min y-val is yminc, max is y-maxc, so clamp in those regions
*/
for (cfra = strip->start; cfra <= strip->end; cfra += 1.0f) {
- float y = evaluate_fcurve(fcu, cfra);
+ float y = evaluate_fcurve(fcu, cfra); /* assume this to be in 0-1 range */
CLAMP(y, 0.0f, 1.0f);
- glVertex2f(cfra, ((y * yheight) + yminc));
+ immVertex2f(pos, cfra, ((y * yheight) + yminc));
}
-
- glEnd(); // GL_LINE_STRIP
+
+ immEnd();
}
}
else {
/* use blend in/out values only if both aren't zero */
if ((IS_EQF(strip->blendin, 0.0f) && IS_EQF(strip->blendout, 0.0f)) == 0) {
- glBegin(GL_LINE_STRIP);
+ immBeginAtMost(GWN_PRIM_LINE_STRIP, 4);
+
/* start of strip - if no blendin, start straight at 1, otherwise from 0 to 1 over blendin frames */
if (IS_EQF(strip->blendin, 0.0f) == 0) {
- glVertex2f(strip->start, yminc);
- glVertex2f(strip->start + strip->blendin, ymaxc);
+ immVertex2f(pos, strip->start, yminc);
+ immVertex2f(pos, strip->start + strip->blendin, ymaxc);
}
else
- glVertex2f(strip->start, ymaxc);
+ immVertex2f(pos, strip->start, ymaxc);
/* end of strip */
if (IS_EQF(strip->blendout, 0.0f) == 0) {
- glVertex2f(strip->end - strip->blendout, ymaxc);
- glVertex2f(strip->end, yminc);
+ immVertex2f(pos, strip->end - strip->blendout, ymaxc);
+ immVertex2f(pos, strip->end, yminc);
}
else
- glVertex2f(strip->end, ymaxc);
- glEnd(); // GL_LINE_STRIP
+ immVertex2f(pos, strip->end, ymaxc);
+
+ immEnd();
}
}
-
- /* time -------------------------- */
- // XXX do we want to draw this curve? in a different color too?
-
+
/* turn off AA'd lines */
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
+/* helper call to setup dashed-lines for strip outlines */
+static uint nla_draw_use_dashed_outlines(float color[4], bool muted)
+{
+ /* Note that we use dashed shader here, and make it draw solid lines if not muted... */
+ uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* Simple dashes. */
+ immUniformColor3fv(color);
+
+ /* line style: dotted for muted */
+ if (muted) {
+ /* dotted - and slightly thicker for readability of the dashes */
+ immUniform1f("dash_width", 5.0f);
+ immUniform1f("dash_factor", 0.4f);
+ glLineWidth(1.5f);
+ }
+ else {
+ /* solid line */
+ immUniform1f("dash_factor", 2.0f);
+ glLineWidth(1.0f);
+ }
+
+ return shdr_pos;
+}
+
/* main call for drawing a single NLA-strip */
static void nla_draw_strip(SpaceNla *snla, AnimData *adt, NlaTrack *nlt, NlaStrip *strip, View2D *v2d, float yminc, float ymaxc)
{
const bool non_solo = ((adt && (adt->flag & ADT_NLA_SOLO_TRACK)) && (nlt->flag & NLATRACK_SOLO) == 0);
- float color[3];
+ const bool muted = ((nlt->flag & NLATRACK_MUTED) || (strip->flag & NLASTRIP_FLAG_MUTED));
+ float color[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ uint shdr_pos;
/* get color of strip */
nla_strip_get_color_inside(adt, strip, color);
+ shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* draw extrapolation info first (as backdrop)
* - but this should only be drawn if track has some contribution
*/
if ((strip->extendmode != NLASTRIP_EXTEND_NOTHING) && (non_solo == 0)) {
/* enable transparency... */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
-
+
switch (strip->extendmode) {
/* since this does both sides, only do the 'before' side, and leave the rest to the next case */
case NLASTRIP_EXTEND_HOLD:
@@ -356,15 +421,10 @@ static void nla_draw_strip(SpaceNla *snla, AnimData *adt, NlaTrack *nlt, NlaStri
*/
if (strip->prev == NULL) {
/* set the drawing color to the color of the strip, but with very faint alpha */
- glColor4f(color[0], color[1], color[2], 0.15f);
-
+ immUniformColor3fvAlpha(color, 0.15f);
+
/* draw the rect to the edge of the screen */
- glBegin(GL_QUADS);
- glVertex2f(v2d->cur.xmin, yminc);
- glVertex2f(v2d->cur.xmin, ymaxc);
- glVertex2f(strip->start, ymaxc);
- glVertex2f(strip->start, yminc);
- glEnd();
+ immRectf(shdr_pos, v2d->cur.xmin, yminc, strip->start, ymaxc);
}
ATTR_FALLTHROUGH;
@@ -373,118 +433,132 @@ static void nla_draw_strip(SpaceNla *snla, AnimData *adt, NlaTrack *nlt, NlaStri
/* only need to try and draw if the next strip doesn't occur immediately after */
if ((strip->next == NULL) || (IS_EQF(strip->next->start, strip->end) == 0)) {
/* set the drawing color to the color of the strip, but this time less faint */
- glColor4f(color[0], color[1], color[2], 0.3f);
+ immUniformColor3fvAlpha(color, 0.3f);
/* draw the rect to the next strip or the edge of the screen */
- glBegin(GL_QUADS);
- glVertex2f(strip->end, yminc);
- glVertex2f(strip->end, ymaxc);
-
- if (strip->next) {
- glVertex2f(strip->next->start, ymaxc);
- glVertex2f(strip->next->start, yminc);
- }
- else {
- glVertex2f(v2d->cur.xmax, ymaxc);
- glVertex2f(v2d->cur.xmax, yminc);
- }
- glEnd();
+ float x2 = strip->next ? strip->next->start : v2d->cur.xmax;
+ immRectf(shdr_pos, strip->end, yminc, x2, ymaxc);
}
break;
}
-
+
glDisable(GL_BLEND);
}
-
-
+
+
/* draw 'inside' of strip itself */
if (non_solo == 0) {
+ immUnbindProgram();
+
/* strip is in normal track */
- glColor3fv(color);
UI_draw_roundbox_corner_set(UI_CNR_ALL); /* all corners rounded */
-
- UI_draw_roundbox_shade_x(GL_POLYGON, strip->start, yminc, strip->end, ymaxc, 0.0, 0.5, 0.1);
+ UI_draw_roundbox_shade_x(true, strip->start, yminc, strip->end, ymaxc, 0.0, 0.5, 0.1, color);
+
+ /* restore current vertex format & program (roundbox trashes it) */
+ shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
}
else {
/* strip is in disabled track - make less visible */
- glColor4f(color[0], color[1], color[2], 0.1f);
+ immUniformColor3fvAlpha(color, 0.1f);
glEnable(GL_BLEND);
- glRectf(strip->start, yminc, strip->end, ymaxc);
+ immRectf(shdr_pos, strip->start, yminc, strip->end, ymaxc);
glDisable(GL_BLEND);
}
-
-
+
+
/* draw strip's control 'curves'
* - only if user hasn't hidden them...
*/
if ((snla->flag & SNLA_NOSTRIPCURVES) == 0)
- nla_draw_strip_curves(strip, yminc, ymaxc);
-
-
+ nla_draw_strip_curves(strip, yminc, ymaxc, shdr_pos);
+
+ immUnbindProgram();
+
/* draw markings indicating locations of local markers (useful for lining up different actions) */
if ((snla->flag & SNLA_NOLOCALMARKERS) == 0)
nla_strip_draw_markers(strip, yminc, ymaxc);
-
- /* draw strip outline
+
+ /* draw strip outline
* - color used here is to indicate active vs non-active
*/
if (strip->flag & NLASTRIP_FLAG_ACTIVE) {
/* strip should appear 'sunken', so draw a light border around it */
- glColor3f(0.9f, 1.0f, 0.9f); // FIXME: hardcoded temp-hack colors
+ color[0] = 0.9f; /* FIXME: hardcoded temp-hack colors */
+ color[1] = 1.0f;
+ color[2] = 0.9f;
}
else {
/* strip should appear to stand out, so draw a dark border around it */
- glColor3f(0.0f, 0.0f, 0.0f);
+ color[0] = color[1] = color[2] = 0.0f; /* FIXME: or 1.0f ?? */
}
-
- /* - line style: dotted for muted */
- if ((nlt->flag & NLATRACK_MUTED) || (strip->flag & NLASTRIP_FLAG_MUTED))
- setlinestyle(4);
+
+ /* draw outline
+ * - dashed-line shader is loaded after this block
+ */
+ if (muted) {
+ /* muted - draw dotted, squarish outline (for simplicity) */
+ shdr_pos = nla_draw_use_dashed_outlines(color, muted);
+ imm_draw_box_wire_2d(shdr_pos, strip->start, yminc, strip->end, ymaxc);
+ }
+ else {
+ /* non-muted - draw solid, rounded outline */
+ UI_draw_roundbox_shade_x(false, strip->start, yminc, strip->end, ymaxc, 0.0, 0.0, 0.1, color);
- /* draw outline */
- UI_draw_roundbox_shade_x(GL_LINE_LOOP, strip->start, yminc, strip->end, ymaxc, 0.0, 0.0, 0.1);
-
+ /* restore current vertex format & program (roundbox trashes it) */
+ shdr_pos = nla_draw_use_dashed_outlines(color, muted);
+ }
+
/* if action-clip strip, draw lines delimiting repeats too (in the same color as outline) */
if ((strip->type == NLASTRIP_TYPE_CLIP) && IS_EQF(strip->repeat, 1.0f) == 0) {
float repeatLen = (strip->actend - strip->actstart) * strip->scale;
- int i;
-
+
/* only draw lines for whole-numbered repeats, starting from the first full-repeat
* up to the last full repeat (but not if it lies on the end of the strip)
*/
- for (i = 1; i < strip->repeat; i++) {
+ immBeginAtMost(GWN_PRIM_LINES, 2 * (strip->repeat - 1));
+ for (int i = 1; i < strip->repeat; i++) {
float repeatPos = strip->start + (repeatLen * i);
-
+
/* don't draw if line would end up on or after the end of the strip */
- if (repeatPos < strip->end)
- fdrawline(repeatPos, yminc + 4, repeatPos, ymaxc - 4);
+ if (repeatPos < strip->end) {
+ immVertex2f(shdr_pos, repeatPos, yminc + 4);
+ immVertex2f(shdr_pos, repeatPos, ymaxc - 4);
+ }
}
+ immEnd();
}
/* or if meta-strip, draw lines delimiting extents of sub-strips (in same color as outline, if more than 1 exists) */
else if ((strip->type == NLASTRIP_TYPE_META) && (strip->strips.first != strip->strips.last)) {
- NlaStrip *cs;
- float y = (ymaxc - yminc) / 2.0f + yminc;
-
+ const float y = (ymaxc - yminc) * 0.5f + yminc;
+
+ immBeginAtMost(GWN_PRIM_LINES, 4 * BLI_listbase_count(&strip->strips)); /* up to 2 lines per strip */
+
/* only draw first-level of child-strips, but don't draw any lines on the endpoints */
- for (cs = strip->strips.first; cs; cs = cs->next) {
+ for (NlaStrip *cs = strip->strips.first; cs; cs = cs->next) {
/* draw start-line if not same as end of previous (and only if not the first strip)
* - on upper half of strip
*/
- if ((cs->prev) && IS_EQF(cs->prev->end, cs->start) == 0)
- fdrawline(cs->start, y, cs->start, ymaxc);
-
+ if ((cs->prev) && IS_EQF(cs->prev->end, cs->start) == 0) {
+ immVertex2f(shdr_pos, cs->start, y);
+ immVertex2f(shdr_pos, cs->start, ymaxc);
+ }
+
/* draw end-line if not the last strip
* - on lower half of strip
*/
- if (cs->next)
- fdrawline(cs->end, yminc, cs->end, y);
+ if (cs->next) {
+ immVertex2f(shdr_pos, cs->end, yminc);
+ immVertex2f(shdr_pos, cs->end, y);
+ }
}
+
+ immEnd();
}
-
- /* reset linestyle */
- setlinestyle(0);
-}
+
+ immUnbindProgram();
+}
/* add the relevant text to the cache of text-strings to draw in pixelspace */
static void nla_draw_strip_text(
@@ -495,7 +569,6 @@ static void nla_draw_strip_text(
char str[256];
size_t str_len;
char col[4];
- rctf rect;
/* just print the name and the range */
if (strip->flag & NLASTRIP_FLAG_TEMP_META) {
@@ -522,12 +595,14 @@ static void nla_draw_strip_text(
/* set bounding-box for text
* - padding of 2 'units' on either side
*/
- // TODO: make this centered?
- rect.xmin = xminc;
- rect.ymin = yminc;
- rect.xmax = xmaxc;
- rect.ymax = ymaxc;
-
+ /* TODO: make this centered? */
+ rctf rect = {
+ .xmin = xminc,
+ .ymin = yminc,
+ .xmax = xmaxc,
+ .ymax = ymaxc
+ };
+
/* add this string to the cache of texts to draw */
UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
}
@@ -541,8 +616,7 @@ static void nla_draw_strip_frames_text(NlaTrack *UNUSED(nlt), NlaStrip *strip, V
const char col[4] = {220, 220, 220, 255}; /* light gray */
char numstr[32];
size_t numstr_len;
-
-
+
/* Always draw times above the strip, whereas sequencer drew below + above.
* However, we should be fine having everything on top, since these tend to be
* quite spaced out.
@@ -552,7 +626,7 @@ static void nla_draw_strip_frames_text(NlaTrack *UNUSED(nlt), NlaStrip *strip, V
/* start frame */
numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%.1f", strip->start);
UI_view2d_text_cache_add(v2d, strip->start - 1.0f, ymaxc + ytol, numstr, numstr_len, col);
-
+
/* end frame */
numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%.1f", strip->end);
UI_view2d_text_cache_add(v2d, strip->end, ymaxc + ytol, numstr, numstr_len, col);
@@ -562,20 +636,14 @@ static void nla_draw_strip_frames_text(NlaTrack *UNUSED(nlt), NlaStrip *strip, V
void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *ar)
{
- ListBase anim_data = {NULL, NULL};
- bAnimListElem *ale;
- int filter;
-
View2D *v2d = &ar->v2d;
- float y = 0.0f;
- size_t items;
- int height;
const float pixelx = BLI_rctf_size_x(&v2d->cur) / BLI_rcti_size_x(&v2d->mask);
const float text_margin_x = (8 * UI_DPI_FAC) * pixelx;
/* build list of channels to draw */
- filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
- items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
+ ListBase anim_data = {NULL, NULL};
+ int filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
+ size_t items = ANIM_animdata_filter(ac, &anim_data, filter, ac->data, ac->datatype);
/* Update max-extent of channels here (taking into account scrollers):
* - this is done to allow the channel list to be scrollable, but must be done here
@@ -583,16 +651,17 @@ void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *ar)
* - offset of NLACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for
* start of list offset, and the second is as a correction for the scrollers.
*/
- height = ((items * NLACHANNEL_STEP(snla)) + (NLACHANNEL_HEIGHT(snla) * 2));
+ int height = ((items * NLACHANNEL_STEP(snla)) + (NLACHANNEL_HEIGHT(snla) * 2));
+
/* don't use totrect set, as the width stays the same
* (NOTE: this is ok here, the configuration is pretty straightforward)
*/
v2d->tot.ymin = (float)(-height);
/* loop through channels, and set up drawing depending on their type */
- y = (float)(-NLACHANNEL_HEIGHT(snla));
+ float y = (float)(-NLACHANNEL_HEIGHT(snla));
- for (ale = anim_data.first; ale; ale = ale->next) {
+ for (bAnimListElem *ale = anim_data.first; ale; ale = ale->next) {
const float yminc = (float)(y - NLACHANNEL_HEIGHT_HALF(snla));
const float ymaxc = (float)(y + NLACHANNEL_HEIGHT_HALF(snla));
@@ -635,45 +704,60 @@ void draw_nla_main_data(bAnimContext *ac, SpaceNla *snla, ARegion *ar)
case ANIMTYPE_NLAACTION:
{
AnimData *adt = ale->adt;
- float color[4];
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* just draw a semi-shaded rect spanning the width of the viewable area if there's data,
* and a second darker rect within which we draw keyframe indicator dots if there's data
*/
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
-
+
/* get colors for drawing */
+ float color[4];
nla_action_get_color(adt, ale->data, color);
- glColor4fv(color);
-
+ immUniformColor4fv(color);
+
/* draw slightly shifted up for greater separation from standard channels,
* but also slightly shorter for some more contrast when viewing the strips
*/
- glRectf(v2d->cur.xmin, yminc + NLACHANNEL_SKIP, v2d->cur.xmax, ymaxc - NLACHANNEL_SKIP);
-
- /* draw keyframes in the action */
- nla_action_draw_keyframes(adt, ale->data, v2d, y, yminc + NLACHANNEL_SKIP, ymaxc - NLACHANNEL_SKIP);
+ immRectf(pos, v2d->cur.xmin, yminc + NLACHANNEL_SKIP, v2d->cur.xmax, ymaxc - NLACHANNEL_SKIP);
/* draw 'embossed' lines above and below the strip for effect */
/* white base-lines */
glLineWidth(2.0f);
- glColor4f(1.0f, 1.0f, 1.0f, 0.3);
- fdrawline(v2d->cur.xmin, yminc + NLACHANNEL_SKIP, v2d->cur.xmax, yminc + NLACHANNEL_SKIP);
- fdrawline(v2d->cur.xmin, ymaxc - NLACHANNEL_SKIP, v2d->cur.xmax, ymaxc - NLACHANNEL_SKIP);
-
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.3f);
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, v2d->cur.xmin, yminc + NLACHANNEL_SKIP);
+ immVertex2f(pos, v2d->cur.xmax, yminc + NLACHANNEL_SKIP);
+ immVertex2f(pos, v2d->cur.xmin, ymaxc - NLACHANNEL_SKIP);
+ immVertex2f(pos, v2d->cur.xmax, ymaxc - NLACHANNEL_SKIP);
+ immEnd();
+
/* black top-lines */
glLineWidth(1.0f);
- glColor3f(0.0f, 0.0f, 0.0f);
- fdrawline(v2d->cur.xmin, yminc + NLACHANNEL_SKIP, v2d->cur.xmax, yminc + NLACHANNEL_SKIP);
- fdrawline(v2d->cur.xmin, ymaxc - NLACHANNEL_SKIP, v2d->cur.xmax, ymaxc - NLACHANNEL_SKIP);
-
+ immUniformColor3f(0.0f, 0.0f, 0.0f);
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, v2d->cur.xmin, yminc + NLACHANNEL_SKIP);
+ immVertex2f(pos, v2d->cur.xmax, yminc + NLACHANNEL_SKIP);
+ immVertex2f(pos, v2d->cur.xmin, ymaxc - NLACHANNEL_SKIP);
+ immVertex2f(pos, v2d->cur.xmax, ymaxc - NLACHANNEL_SKIP);
+ immEnd();
+
+ /* TODO: these lines but better --^ */
+
+ immUnbindProgram();
+
+ /* draw keyframes in the action */
+ nla_action_draw_keyframes(adt, ale->data, y, yminc + NLACHANNEL_SKIP, ymaxc - NLACHANNEL_SKIP);
+
glDisable(GL_BLEND);
break;
}
}
}
-
+
/* adjust y-position for next one */
y -= NLACHANNEL_STEP(snla);
}
@@ -695,7 +779,6 @@ void draw_nla_channel_list(const bContext *C, bAnimContext *ac, ARegion *ar)
View2D *v2d = &ar->v2d;
float y = 0.0f;
size_t items;
- int height;
/* build list of channels to draw */
filter = (ANIMFILTER_DATA_VISIBLE | ANIMFILTER_LIST_VISIBLE | ANIMFILTER_LIST_CHANNELS);
@@ -707,7 +790,7 @@ void draw_nla_channel_list(const bContext *C, bAnimContext *ac, ARegion *ar)
* - offset of NLACHANNEL_HEIGHT*2 is added to the height of the channels, as first is for
* start of list offset, and the second is as a correction for the scrollers.
*/
- height = ((items * NLACHANNEL_STEP(snla)) + (NLACHANNEL_HEIGHT(snla) * 2));
+ int height = ((items * NLACHANNEL_STEP(snla)) + (NLACHANNEL_HEIGHT(snla) * 2));
/* don't use totrect set, as the width stays the same
* (NOTE: this is ok here, the configuration is pretty straightforward)
*/
@@ -745,7 +828,7 @@ void draw_nla_channel_list(const bContext *C, bAnimContext *ac, ARegion *ar)
y = (float)(-NLACHANNEL_HEIGHT(snla));
/* set blending again, as may not be set in previous step */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
/* loop through channels, and set up drawing depending on their type */
diff --git a/source/blender/editors/space_nla/space_nla.c b/source/blender/editors/space_nla/space_nla.c
index f1e8b655673..331fae606af 100644
--- a/source/blender/editors/space_nla/space_nla.c
+++ b/source/blender/editors/space_nla/space_nla.c
@@ -55,6 +55,9 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
+
+#include "RNA_access.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -91,10 +94,8 @@ ARegion *nla_has_buttons_region(ScrArea *sa)
/* ******************** default callbacks for nla space ***************** */
-static SpaceLink *nla_new(const bContext *C)
+static SpaceLink *nla_new(const ScrArea *sa, const Scene *scene)
{
- Scene *scene = CTX_data_scene(C);
- ScrArea *sa = CTX_wm_area(C);
ARegion *ar;
SpaceNla *snla;
@@ -268,11 +269,12 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar)
{
/* draw entirely, view changes should be handled here */
SpaceNla *snla = CTX_wm_space_nla(C);
+ Scene *scene = CTX_data_scene(C);
bAnimContext ac;
View2D *v2d = &ar->v2d;
View2DGrid *grid;
View2DScrollers *scrollers;
- short unit = 0, flag = 0;
+ short unit = 0, cfra_flag = 0;
/* clear and setup matrix */
UI_ThemeClearColor(TH_BACK);
@@ -287,7 +289,10 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar)
UI_view2d_grid_free(grid);
ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
-
+
+ /* start and end frame */
+ ANIM_draw_framerange(scene, v2d);
+
/* data */
if (ANIM_animdata_get_context(C, &ac)) {
/* strips and backdrops */
@@ -300,9 +305,8 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar)
UI_view2d_view_ortho(v2d);
/* current frame */
- if (snla->flag & SNLA_DRAWTIME) flag |= DRAWCFRA_UNIT_SECONDS;
- if ((snla->flag & SNLA_NODRAWCFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
- ANIM_draw_cfra(C, v2d, flag);
+ if (snla->flag & SNLA_DRAWTIME) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
+ ANIM_draw_cfra(C, v2d, cfra_flag);
/* markers */
UI_view2d_view_orthoSpecial(ar, v2d, 1);
@@ -323,6 +327,12 @@ static void nla_main_region_draw(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
+
+ /* draw current frame number-indicator on top of scrollers */
+ if ((snla->flag & SNLA_NODRAWCFRANUM) == 0) {
+ UI_view2d_view_orthoSpecial(ar, v2d, 1);
+ ANIM_draw_cfra_number(C, v2d, cfra_flag);
+ }
}
@@ -353,7 +363,9 @@ static void nla_buttons_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void nla_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void nla_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -386,7 +398,9 @@ static void nla_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegio
}
-static void nla_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void nla_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -398,6 +412,7 @@ static void nla_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), A
case ND_RENDER_OPTIONS:
case ND_OB_ACTIVE:
case ND_FRAME:
+ case ND_FRAME_RANGE:
case ND_MARKERS:
ED_region_tag_redraw(ar);
break;
@@ -424,6 +439,11 @@ static void nla_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), A
if (wmn->action == NA_RENAME)
ED_region_tag_redraw(ar);
break;
+ case NC_SCREEN:
+ if (ELEM(wmn->data, ND_LAYER)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
default:
if (wmn->data == ND_KEYS)
ED_region_tag_redraw(ar);
@@ -431,7 +451,49 @@ static void nla_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), A
}
}
-static void nla_channel_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void nla_main_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *scene,
+ struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ PointerRNA ptr;
+ RNA_pointer_create(&screen->id, &RNA_SpaceNLA, sa->spacedata.first, &ptr);
+
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ /* Timeline depends on scene properties. */
+ {
+ bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
+ extern PropertyRNA rna_Scene_frame_start;
+ extern PropertyRNA rna_Scene_frame_end;
+ extern PropertyRNA rna_Scene_frame_preview_start;
+ extern PropertyRNA rna_Scene_frame_preview_end;
+ extern PropertyRNA rna_Scene_use_preview_range;
+ extern PropertyRNA rna_Scene_frame_current;
+ const PropertyRNA *props[] = {
+ use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
+ use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
+ &rna_Scene_use_preview_range,
+ &rna_Scene_frame_current,
+ };
+
+ PointerRNA idptr;
+ RNA_id_pointer_create(&scene->id, &idptr);
+
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ WM_msg_subscribe_rna(mbus, &idptr, props[i], &msg_sub_value_region_tag_redraw, __func__);
+ }
+ }
+}
+
+static void nla_channel_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -466,7 +528,8 @@ static void nla_channel_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa)
}
/* editor level listener */
-static void nla_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void nla_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
/* context changes */
switch (wmn->category) {
@@ -540,6 +603,7 @@ void ED_spacetype_nla(void)
art->init = nla_main_region_init;
art->draw = nla_main_region_draw;
art->listener = nla_main_region_listener;
+ art->message_subscribe = nla_main_region_message_subscribe;
art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
BLI_addhead(&st->regiontypes, art);
diff --git a/source/blender/editors/space_node/CMakeLists.txt b/source/blender/editors/space_node/CMakeLists.txt
index cde818333e4..77b1351435b 100644
--- a/source/blender/editors/space_node/CMakeLists.txt
+++ b/source/blender/editors/space_node/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../imbuf
../../gpu
../../makesdna
@@ -47,6 +48,7 @@ set(SRC
node_draw.c
node_edit.c
node_group.c
+ node_manipulators.c
node_ops.c
node_relationships.c
node_select.c
diff --git a/source/blender/editors/space_node/drawnode.c b/source/blender/editors/space_node/drawnode.c
index 5665a5cff2d..ca6ae5955a9 100644
--- a/source/blender/editors/space_node/drawnode.c
+++ b/source/blender/editors/space_node/drawnode.c
@@ -50,9 +50,13 @@
#include "BLF_api.h"
#include "BLT_translation.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_draw.h"
+#include "GPU_batch.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -62,6 +66,7 @@
#include "WM_types.h"
#include "UI_resources.h"
+#include "UI_view2d.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf_types.h"
@@ -80,49 +85,6 @@ static void node_socket_button_label(bContext *UNUSED(C), uiLayout *layout, Poin
uiItemL(layout, text, 0);
}
-
-/* ****************** BASE DRAW FUNCTIONS FOR NEW OPERATOR NODES ***************** */
-
-#if 0 /* UNUSED */
-static void node_draw_socket_new(bNodeSocket *sock, float size)
-{
- float x = sock->locx, y = sock->locy;
-
- /* 16 values of sin function */
- static float si[16] = {
- 0.00000000f, 0.39435585f, 0.72479278f, 0.93775213f,
- 0.99871650f, 0.89780453f, 0.65137248f, 0.29936312f,
- -0.10116832f, -0.48530196f, -0.79077573f, -0.96807711f,
- -0.98846832f, -0.84864425f, -0.57126821f, -0.20129852f
- };
- /* 16 values of cos function */
- static float co[16] = {
- 1.00000000f, 0.91895781f, 0.68896691f, 0.34730525f,
- -0.05064916f, -0.44039415f, -0.75875812f, -0.95413925f,
- -0.99486932f, -0.87434661f, -0.61210598f, -0.25065253f,
- 0.15142777f, 0.52896401f, 0.82076344f, 0.97952994f,
- };
- int a;
-
- glColor3ub(180, 180, 180);
-
- glBegin(GL_POLYGON);
- for (a = 0; a < 16; a++)
- glVertex2f(x + size * si[a], y + size * co[a]);
- glEnd();
-
- glColor4ub(0, 0, 0, 150);
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
- glBegin(GL_LINE_LOOP);
- for (a = 0; a < 16; a++)
- glVertex2f(x + size * si[a], y + size * co[a]);
- glEnd();
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
-}
-#endif
-
/* ****************** BUTTON CALLBACKS FOR ALL TREES ***************** */
static void node_buts_value(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
@@ -392,6 +354,7 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
const int font_size = data->label_size / aspect;
const float margin = (float)(NODE_DY / 4);
int label_height;
+ unsigned char color[3];
nodeLabel(ntree, node, label, sizeof(label));
@@ -400,7 +363,8 @@ static void node_draw_frame_label(bNodeTree *ntree, bNode *node, const float asp
BLF_size(fontid, MIN2(24, font_size), U.dpi); /* clamp otherwise it can suck up a LOT of memory */
/* title color */
- UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.4f, 10);
+ UI_GetThemeColorBlendShade3ubv(TH_TEXT, color_id, 0.4f, 10, color);
+ BLF_color3ubv(fontid, color);
width = BLF_width(fontid, label, sizeof(label));
ascender = BLF_ascender(fontid);
@@ -465,7 +429,7 @@ static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode,
{
rctf *rct = &node->totr;
int color_id = node_get_colorid(node);
- unsigned char color[4];
+ float color[4];
float alpha;
/* skip if out of view */
@@ -475,40 +439,32 @@ static void node_draw_frame(const bContext *C, ARegion *ar, SpaceNode *snode,
return;
}
- UI_GetThemeColor4ubv(TH_NODE_FRAME, color);
- alpha = (float)(color[3]) / 255.0f;
+ UI_GetThemeColor4fv(TH_NODE_FRAME, color);
+ alpha = color[3];
/* shadow */
node_draw_shadow(snode, node, BASIS_RAD, alpha);
/* body */
- if (node->flag & NODE_CUSTOM_COLOR)
- glColor4f(node->color[0], node->color[1], node->color[2], alpha);
+ if (node->flag & NODE_CUSTOM_COLOR) {
+ rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], alpha);
+ }
else
- UI_ThemeColor4(TH_NODE_FRAME);
- glEnable(GL_BLEND);
+ UI_GetThemeColor4fv(TH_NODE_FRAME, color);
+
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
- glDisable(GL_BLEND);
+ UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color);
/* outline active and selected emphasis */
if (node->flag & SELECT) {
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
-
if (node->flag & NODE_ACTIVE)
- UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -40);
+ UI_GetThemeColorShadeAlpha4fv(TH_ACTIVE, 0, -40, color);
else
- UI_ThemeColorShadeAlpha(TH_SELECT, 0, -40);
- UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP,
- rct->xmin, rct->ymin,
- rct->xmax, rct->ymax, BASIS_RAD);
-
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
+ UI_GetThemeColorShadeAlpha4fv(TH_SELECT, 0, -40, color);
+
+ UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color);
}
-
+
/* label */
node_draw_frame_label(ntree, node, snode->aspect);
@@ -580,15 +536,9 @@ static void node_draw_reroute_prepare(const bContext *UNUSED(C), bNodeTree *UNUS
static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED(snode),
bNodeTree *ntree, bNode *node, bNodeInstanceKey UNUSED(key))
{
- bNodeSocket *sock;
char showname[128]; /* 128 used below */
rctf *rct = &node->totr;
-#if 0 /* UNUSED */
- float size = NODE_REROUTE_SIZE;
-#endif
- float socket_size = NODE_SOCKSIZE;
-
/* skip if out of view */
if (node->totr.xmax < ar->v2d.cur.xmin || node->totr.xmin > ar->v2d.cur.xmax ||
node->totr.ymax < ar->v2d.cur.ymin || node->totr.ymin > ar->v2d.cur.ymax)
@@ -602,23 +552,26 @@ static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED(
* selection state is indicated by socket outline below!
*/
#if 0
+ float size = NODE_REROUTE_SIZE;
+
/* body */
+ float debug_color[4];
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_ThemeColor4(TH_NODE);
- glEnable(GL_BLEND);
- UI_draw_roundbox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, size);
- glDisable(GL_BLEND);
+ UI_GetThemeColor4fv(TH_NODE, debug_color);
+ UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color);
/* outline active and selected emphasis */
if (node->flag & SELECT) {
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
/* using different shades of TH_TEXT_HI for the empasis, like triangle */
- if (node->flag & NODE_ACTIVE)
- UI_ThemeColorShadeAlpha(TH_TEXT_HI, 0, -40);
- else
- UI_ThemeColorShadeAlpha(TH_TEXT_HI, -20, -120);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size);
+ if (node->flag & NODE_ACTIVE) {
+ UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, 0, -40, debug_color);
+ }
+ else {
+ UI_GetThemeColorShadeAlpha4fv(TH_TEXT_HI, -20, -120, debug_color);
+ }
+ UI_draw_roundbox_4fv(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, size, debug_color);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
@@ -637,9 +590,7 @@ static void node_draw_reroute(const bContext *C, ARegion *ar, SpaceNode *UNUSED(
/* only draw input socket. as they all are placed on the same position.
* highlight also if node itself is selected, since we don't display the node body separately!
*/
- for (sock = node->inputs.first; sock; sock = sock->next) {
- node_socket_draw(C, ntree, node, sock, socket_size, (sock->flag & SELECT) || (node->flag & SELECT));
- }
+ node_draw_sockets(&ar->v2d, C, ntree, node, false, node->flag & SELECT);
UI_block_end(C, node->block);
UI_block_draw(C, node->block);
@@ -728,21 +679,6 @@ static void node_buts_image_user(uiLayout *layout, bContext *C, PointerRNA *ptr,
}
}
-static void node_shader_buts_material(uiLayout *layout, bContext *C, PointerRNA *ptr)
-{
- bNode *node = ptr->data;
- uiLayout *col;
-
- uiTemplateID(layout, C, ptr, "material", "MATERIAL_OT_new", NULL, NULL, UI_TEMPLATE_ID_FILTER_ALL);
-
- if (!node->id) return;
-
- col = uiLayoutColumn(layout, false);
- uiItemR(col, ptr, "use_diffuse", 0, NULL, ICON_NONE);
- uiItemR(col, ptr, "use_specular", 0, NULL, ICON_NONE);
- uiItemR(col, ptr, "invert_normal", 0, NULL, ICON_NONE);
-}
-
static void node_shader_buts_mapping(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiLayout *row, *col, *sub;
@@ -790,30 +726,6 @@ static void node_shader_buts_vect_transform(uiLayout *layout, bContext *UNUSED(C
uiItemR(layout, ptr, "convert_to", 0, "", ICON_NONE);
}
-static void node_shader_buts_geometry(uiLayout *layout, bContext *C, PointerRNA *ptr)
-{
- PointerRNA obptr = CTX_data_pointer_get(C, "active_object");
- uiLayout *col;
-
- col = uiLayoutColumn(layout, false);
-
- if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
- PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
-
- uiItemPointerR(col, ptr, "uv_layer", &dataptr, "uv_textures", "", ICON_NONE);
- uiItemPointerR(col, ptr, "color_layer", &dataptr, "vertex_colors", "", ICON_NONE);
- }
- else {
- uiItemR(col, ptr, "uv_layer", 0, IFACE_("UV"), ICON_NONE);
- uiItemR(col, ptr, "color_layer", 0, IFACE_("VCol"), ICON_NONE);
- }
-}
-
-static void node_shader_buts_lamp(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
- uiItemR(layout, ptr, "lamp_object", 0, IFACE_("Lamp Object"), ICON_NONE);
-}
-
static void node_shader_buts_attribute(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
{
uiItemR(layout, ptr, "attribute_name", 0, IFACE_("Name"), ICON_NONE);
@@ -1022,7 +934,7 @@ static void node_shader_buts_uvmap(uiLayout *layout, bContext *C, PointerRNA *pt
if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
- uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_textures", "", ICON_NONE);
+ uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE);
}
}
}
@@ -1041,7 +953,7 @@ static void node_shader_buts_normal_map(uiLayout *layout, bContext *C, PointerRN
if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
- uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_textures", "", ICON_NONE);
+ uiItemPointerR(layout, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE);
}
else
uiItemR(layout, ptr, "uv_map", 0, "", 0);
@@ -1068,7 +980,7 @@ static void node_shader_buts_tangent(uiLayout *layout, bContext *C, PointerRNA *
if (obptr.data && RNA_enum_get(&obptr, "type") == OB_MESH) {
PointerRNA dataptr = RNA_pointer_get(&obptr, "data");
- uiItemPointerR(row, ptr, "uv_map", &dataptr, "uv_textures", "", ICON_NONE);
+ uiItemPointerR(row, ptr, "uv_map", &dataptr, "uv_layers", "", ICON_NONE);
}
else
uiItemR(row, ptr, "uv_map", 0, "", 0);
@@ -1157,13 +1069,6 @@ static void node_shader_buts_bevel(uiLayout *layout, bContext *UNUSED(C), Pointe
static void node_shader_set_butfunc(bNodeType *ntype)
{
switch (ntype->type) {
- case SH_NODE_MATERIAL:
- case SH_NODE_MATERIAL_EXT:
- ntype->draw_buttons = node_shader_buts_material;
- break;
- case SH_NODE_TEXTURE:
- ntype->draw_buttons = node_buts_texture;
- break;
case SH_NODE_NORMAL:
ntype->draw_buttons = node_buts_normal;
break;
@@ -1197,12 +1102,6 @@ static void node_shader_set_butfunc(bNodeType *ntype)
case SH_NODE_VECT_TRANSFORM:
ntype->draw_buttons = node_shader_buts_vect_transform;
break;
- case SH_NODE_GEOMETRY:
- ntype->draw_buttons = node_shader_buts_geometry;
- break;
- case SH_NODE_LAMP:
- ntype->draw_buttons = node_shader_buts_lamp;
- break;
case SH_NODE_ATTRIBUTE:
ntype->draw_buttons = node_shader_buts_attribute;
break;
@@ -1345,7 +1244,7 @@ static void node_composit_buts_image_ex(uiLayout *layout, bContext *C, PointerRN
uiTemplateImage(layout, C, ptr, "image", &iuserptr, 0, 1);
}
-static void node_composit_buts_renderlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
+static void node_composit_buts_viewlayers(uiLayout *layout, bContext *C, PointerRNA *ptr)
{
bNode *node = ptr->data;
uiLayout *col, *row;
@@ -2243,14 +2142,21 @@ static void node_composit_backdrop_viewer(SpaceNode *snode, ImBuf *backdrop, bNo
const float cy = y + snode->zoom * backdropHeight * node->custom4;
const float cross_size = 12 * U.pixelsize;
- glColor3f(1.0, 1.0, 1.0);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
- glBegin(GL_LINES);
- glVertex2f(cx - cross_size, cy - cross_size);
- glVertex2f(cx + cross_size, cy + cross_size);
- glVertex2f(cx + cross_size, cy - cross_size);
- glVertex2f(cx - cross_size, cy + cross_size);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, cx - cross_size, cy - cross_size);
+ immVertex2f(pos, cx + cross_size, cy + cross_size);
+ immVertex2f(pos, cx + cross_size, cy - cross_size);
+ immVertex2f(pos, cx - cross_size, cy + cross_size);
+ immEnd();
+
+ immUnbindProgram();
}
}
@@ -2269,9 +2175,6 @@ static void node_composit_backdrop_boxmask(SpaceNode *snode, ImBuf *backdrop, bN
float cx, cy, x1, x2, x3, x4;
float y1, y2, y3, y4;
-
- glColor3f(1.0, 1.0, 1.0);
-
cx = x + snode->zoom * backdropWidth * boxmask->x;
cy = y + snode->zoom * backdropHeight * boxmask->y;
@@ -2284,12 +2187,21 @@ static void node_composit_backdrop_boxmask(SpaceNode *snode, ImBuf *backdrop, bN
y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
- glBegin(GL_LINE_LOOP);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
- glVertex2f(x3, y3);
- glVertex2f(x4, y4);
- glEnd();
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
+
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x2, y2);
+ immVertex2f(pos, x3, y3);
+ immVertex2f(pos, x4, y4);
+ immEnd();
+
+ immUnbindProgram();
}
static void node_composit_backdrop_ellipsemask(SpaceNode *snode, ImBuf *backdrop, bNode *node, int x, int y)
@@ -2307,9 +2219,6 @@ static void node_composit_backdrop_ellipsemask(SpaceNode *snode, ImBuf *backdrop
float cx, cy, x1, x2, x3, x4;
float y1, y2, y3, y4;
-
- glColor3f(1.0, 1.0, 1.0);
-
cx = x + snode->zoom * backdropWidth * ellipsemask->x;
cy = y + snode->zoom * backdropHeight * ellipsemask->y;
@@ -2322,13 +2231,21 @@ static void node_composit_backdrop_ellipsemask(SpaceNode *snode, ImBuf *backdrop
y3 = cy - (-sine * -halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
y4 = cy - (-sine * halveBoxWidth + cosine * -halveBoxHeight) * snode->zoom;
- glBegin(GL_LINE_LOOP);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
- glVertex2f(x3, y3);
- glVertex2f(x4, y4);
- glEnd();
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
+
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x2, y2);
+ immVertex2f(pos, x3, y3);
+ immVertex2f(pos, x4, y4);
+ immEnd();
+
+ immUnbindProgram();
}
static void node_composit_buts_ellipsemask(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
@@ -2528,7 +2445,7 @@ static void node_composit_set_butfunc(bNodeType *ntype)
ntype->draw_buttons_ex = node_composit_buts_image_ex;
break;
case CMP_NODE_R_LAYERS:
- ntype->draw_buttons = node_composit_buts_renderlayers;
+ ntype->draw_buttons = node_composit_buts_viewlayers;
break;
case CMP_NODE_NORMAL:
ntype->draw_buttons = node_buts_normal;
@@ -3217,6 +3134,7 @@ void ED_init_node_socket_type_virtual(bNodeSocketType *stype)
void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeInstanceKey parent_key)
{
bNodeInstanceKey active_viewer_key = (snode->nodetree ? snode->nodetree->active_viewer_key : NODE_INSTANCE_KEY_NONE);
+ float shuffle[4] = {0.0f, 0.0f, 0.0f, 0.0f};
Image *ima;
void *lock;
ImBuf *ibuf;
@@ -3231,15 +3149,11 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
if (ibuf) {
float x, y;
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-
+
+ gpuPushProjectionMatrix();
+ gpuPushMatrix();
+
/* somehow the offset has to be calculated inverse */
-
- glaDefine2DArea(&ar->winrct);
wmOrtho2_region_pixelspace(ar);
x = (ar->winx - snode->zoom * ibuf->x) / 2 + snode->xof;
@@ -3249,60 +3163,37 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
unsigned char *display_buffer = NULL;
void *cache_handle = NULL;
- if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B)) {
- int ofs;
+ if (snode->flag & (SNODE_SHOW_R | SNODE_SHOW_G | SNODE_SHOW_B | SNODE_SHOW_ALPHA)) {
display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
-
-#ifdef __BIG_ENDIAN__
- if (snode->flag & SNODE_SHOW_R) ofs = 0;
- else if (snode->flag & SNODE_SHOW_G) ofs = 1;
- else ofs = 2;
-#else
- if (snode->flag & SNODE_SHOW_R) ofs = 1;
- else if (snode->flag & SNODE_SHOW_G) ofs = 2;
- else ofs = 3;
-#endif
-
- glPixelZoom(snode->zoom, snode->zoom);
- /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
-
- glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT,
- display_buffer - (4 - ofs));
-
- glPixelZoom(1.0f, 1.0f);
- }
- else if (snode->flag & SNODE_SHOW_ALPHA) {
- display_buffer = IMB_display_buffer_acquire_ctx(C, ibuf, &cache_handle);
-
- glPixelZoom(snode->zoom, snode->zoom);
- /* swap bytes, so alpha is most significant one, then just draw it as luminance int */
-#ifdef __BIG_ENDIAN__
- glPixelStorei(GL_UNPACK_SWAP_BYTES, 1);
-#endif
- glaDrawPixelsSafe(x, y, ibuf->x, ibuf->y, ibuf->x, GL_LUMINANCE, GL_UNSIGNED_INT, display_buffer);
-
-#ifdef __BIG_ENDIAN__
- glPixelStorei(GL_UNPACK_SWAP_BYTES, 0);
-#endif
- glPixelZoom(1.0f, 1.0f);
+
+ if (snode->flag & SNODE_SHOW_R)
+ shuffle[0] = 1.0f;
+ else if (snode->flag & SNODE_SHOW_G)
+ shuffle[1] = 1.0f;
+ else if (snode->flag & SNODE_SHOW_B)
+ shuffle[2] = 1.0f;
+ else
+ shuffle[3] = 1.0f;
+
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, shuffle);
+
+ immDrawPixelsTex(&state, x, y, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
+ display_buffer, snode->zoom, snode->zoom, NULL);
+
+ GPU_shader_unbind();
}
else if (snode->flag & SNODE_USE_ALPHA) {
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPixelZoom(snode->zoom, snode->zoom);
-
- glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST);
-
- glPixelZoom(1.0f, 1.0f);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom);
+
glDisable(GL_BLEND);
}
else {
- glPixelZoom(snode->zoom, snode->zoom);
-
- glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST);
-
- glPixelZoom(1.0f, 1.0f);
+ glaDrawImBuf_glsl_ctx(C, ibuf, x, y, GL_NEAREST, snode->zoom, snode->zoom);
}
if (cache_handle)
@@ -3327,30 +3218,33 @@ void draw_nodespace_back_pix(const bContext *C, ARegion *ar, SpaceNode *snode, b
viewer_border->ymin < viewer_border->ymax)
{
rcti pixel_border;
- UI_ThemeColor(TH_ACTIVE);
BLI_rcti_init(&pixel_border,
x + snode->zoom * viewer_border->xmin * ibuf->x,
x + snode->zoom * viewer_border->xmax * ibuf->x,
y + snode->zoom * viewer_border->ymin * ibuf->y,
y + snode->zoom * viewer_border->ymax * ibuf->y);
- glaDrawBorderCorners(&pixel_border, 1.0f, 1.0f);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_ACTIVE);
+
+ immDrawBorderCorners(pos, &pixel_border, 1.0f, 1.0f);
+
+ immUnbindProgram();
}
}
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
+
+ gpuPopProjectionMatrix();
+ gpuPopMatrix();
}
BKE_image_release_ibuf(ima, ibuf, lock);
}
-
-/* if v2d not NULL, it clips and returns 0 if not visible */
-bool node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
+/* return quadratic beziers points for a given nodelink and clip if v2d is not NULL. */
+static bool node_link_bezier_handles(View2D *v2d, SpaceNode *snode, bNodeLink *link, float vec[4][2])
{
- float dist, vec[4][2];
+ float dist;
float deltax, deltay;
float cursor[2] = {0.0f, 0.0f};
int toreroute, fromreroute;
@@ -3418,13 +3312,23 @@ bool node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, flo
vec[2][0] = vec[3][0] - dist;
vec[2][1] = vec[3][1];
}
+
if (v2d && min_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) > v2d->cur.xmax) {
- /* clipped */
+ return 0; /* clipped */
}
else if (v2d && max_ffff(vec[0][0], vec[1][0], vec[2][0], vec[3][0]) < v2d->cur.xmin) {
- /* clipped */
+ return 0; /* clipped */
}
- else {
+
+ return 1;
+}
+
+/* if v2d not NULL, it clips and returns 0 if not visible */
+bool node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, float coord_array[][2], int resol)
+{
+ float vec[4][2];
+
+ if (node_link_bezier_handles(v2d, snode, link, vec)) {
/* always do all three, to prevent data hanging around */
BKE_curve_forward_diff_bezier(vec[0][0], vec[1][0], vec[2][0], vec[3][0],
coord_array[0] + 0, resol, sizeof(float) * 2);
@@ -3436,186 +3340,242 @@ bool node_link_bezier_points(View2D *v2d, SpaceNode *snode, bNodeLink *link, flo
return 0;
}
+#define NODELINK_GROUP_SIZE 256
#define LINK_RESOL 24
-#define LINK_ARROW 12 /* position of arrow on the link, LINK_RESOL/2 */
-#define ARROW_SIZE (7 * UI_DPI_FAC)
-void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link,
- int th_col1, bool do_shaded, int th_col2, bool do_triple, int th_col3)
-{
- float coord_array[LINK_RESOL + 1][2];
-
- if (node_link_bezier_points(v2d, snode, link, coord_array, LINK_RESOL)) {
- float dist, spline_step = 0.0f;
- int i;
- int drawarrow;
- /* store current linewidth */
- float linew;
- float arrow[2], arrow1[2], arrow2[2];
- glGetFloatv(GL_LINE_WIDTH, &linew);
-
- /* we can reuse the dist variable here to increment the GL curve eval amount*/
- dist = 1.0f / (float)LINK_RESOL;
-
- glEnable(GL_LINE_SMOOTH);
-
- drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) &&
- (link->fromnode && (link->fromnode->type == NODE_REROUTE)));
-
- if (drawarrow) {
- /* draw arrow in line segment LINK_ARROW */
- float d_xy[2], len;
-
- sub_v2_v2v2(d_xy, coord_array[LINK_ARROW], coord_array[LINK_ARROW - 1]);
- len = len_v2(d_xy);
- mul_v2_fl(d_xy, ARROW_SIZE / len);
- arrow1[0] = coord_array[LINK_ARROW][0] - d_xy[0] + d_xy[1];
- arrow1[1] = coord_array[LINK_ARROW][1] - d_xy[1] - d_xy[0];
- arrow2[0] = coord_array[LINK_ARROW][0] - d_xy[0] - d_xy[1];
- arrow2[1] = coord_array[LINK_ARROW][1] - d_xy[1] + d_xy[0];
- arrow[0] = coord_array[LINK_ARROW][0];
- arrow[1] = coord_array[LINK_ARROW][1];
+#define LINK_WIDTH (2.5f * UI_DPI_FAC)
+#define ARROW_SIZE (7 * UI_DPI_FAC)
+
+static float arrow_verts[3][2] = {{-1.0f, 1.0f}, {0.0f, 0.0f}, {-1.0f, -1.0f}};
+static float arrow_expand_axis[3][2] = {{0.7071f, 0.7071f}, {M_SQRT2, 0.0f}, {0.7071f, -0.7071f}};
+
+struct {
+ Gwn_Batch *batch; /* for batching line together */
+ Gwn_Batch *batch_single; /* for single line */
+ Gwn_VertBuf *inst_vbo;
+ unsigned int p0_id, p1_id, p2_id, p3_id;
+ unsigned int colid_id;
+ Gwn_VertBufRaw p0_step, p1_step, p2_step, p3_step;
+ Gwn_VertBufRaw colid_step;
+ unsigned int count;
+ bool enabled;
+} g_batch_link = {0};
+
+static void nodelink_batch_reset(void)
+{
+ GWN_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p0_id, &g_batch_link.p0_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p1_id, &g_batch_link.p1_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p2_id, &g_batch_link.p2_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.p3_id, &g_batch_link.p3_step);
+ GWN_vertbuf_attr_get_raw_data(g_batch_link.inst_vbo, g_batch_link.colid_id, &g_batch_link.colid_step);
+ g_batch_link.count = 0;
+}
+
+static void set_nodelink_vertex(
+ Gwn_VertBuf *vbo,
+ unsigned int uv_id, unsigned int pos_id, unsigned int exp_id, unsigned int v,
+ const unsigned char uv[2], const float pos[2], const float exp[2])
+{
+ GWN_vertbuf_attr_set(vbo, uv_id, v, uv);
+ GWN_vertbuf_attr_set(vbo, pos_id, v, pos);
+ GWN_vertbuf_attr_set(vbo, exp_id, v, exp);
+}
+
+static void nodelink_batch_init(void)
+{
+ Gwn_VertFormat format = {0};
+ unsigned int uv_id = GWN_vertformat_attr_add(&format, "uv", GWN_COMP_U8, 2, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ unsigned int pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int expand_id = GWN_vertformat_attr_add(&format, "expand", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format_ex(&format, GWN_USAGE_STATIC);
+ int vcount = LINK_RESOL * 2; /* curve */
+ vcount += 2; /* restart strip */
+ vcount += 3 * 2; /* arrow */
+ vcount *= 2; /* shadow */
+ vcount += 2; /* restart strip */
+ GWN_vertbuf_data_alloc(vbo, vcount);
+ int v = 0;
+
+ for (int k = 0; k < 2; ++k) {
+ unsigned char uv[2] = {0, 0};
+ float pos[2] = {0.0f, 0.0f};
+ float exp[2] = {0.0f, 1.0f};
+
+ /* restart */
+ if (k == 1)
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
+
+ /* curve strip */
+ for (int i = 0; i < LINK_RESOL; ++i) {
+ uv[0] = 255 * (i / (float)(LINK_RESOL - 1));
+ uv[1] = 0;
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
+ uv[1] = 255;
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
}
- if (do_triple) {
- UI_ThemeColorShadeAlpha(th_col3, -80, -120);
- glLineWidth(4.0f);
-
- glBegin(GL_LINE_STRIP);
- for (i = 0; i <= LINK_RESOL; i++) {
- glVertex2fv(coord_array[i]);
- }
- glEnd();
- if (drawarrow) {
- glBegin(GL_LINE_STRIP);
- glVertex2fv(arrow1);
- glVertex2fv(arrow);
- glVertex2fv(arrow2);
- glEnd();
- }
+ /* restart */
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
+
+ uv[0] = 127;
+ uv[1] = 0;
+ copy_v2_v2(pos, arrow_verts[0]);
+ copy_v2_v2(exp, arrow_expand_axis[0]);
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
+ /* arrow */
+ for (int i = 0; i < 3; ++i) {
+ uv[1] = 0;
+ copy_v2_v2(pos, arrow_verts[i]);
+ copy_v2_v2(exp, arrow_expand_axis[i]);
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
+
+ uv[1] = 255;
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
}
-
- /* XXX using GL_LINES for shaded node lines is a workaround
- * for Intel hardware, this breaks with GL_LINE_STRIP and
- * changing color in begin/end blocks.
- */
- glLineWidth(1.5f);
- if (do_shaded) {
- glBegin(GL_LINES);
- for (i = 0; i < LINK_RESOL; i++) {
- UI_ThemeColorBlend(th_col1, th_col2, spline_step);
- glVertex2fv(coord_array[i]);
-
- UI_ThemeColorBlend(th_col1, th_col2, spline_step + dist);
- glVertex2fv(coord_array[i + 1]);
-
- spline_step += dist;
- }
- glEnd();
- }
- else {
- UI_ThemeColor(th_col1);
- glBegin(GL_LINE_STRIP);
- for (i = 0; i <= LINK_RESOL; i++) {
- glVertex2fv(coord_array[i]);
- }
- glEnd();
- }
-
- if (drawarrow) {
- glBegin(GL_LINE_STRIP);
- glVertex2fv(arrow1);
- glVertex2fv(arrow);
- glVertex2fv(arrow2);
- glEnd();
- }
-
- glDisable(GL_LINE_SMOOTH);
+
+ /* restart */
+ if (k == 0)
+ set_nodelink_vertex(vbo, uv_id, pos_id, expand_id, v++, uv, pos, exp);
}
+
+ g_batch_link.batch = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ gpu_batch_presets_register(g_batch_link.batch);
+
+ g_batch_link.batch_single = GWN_batch_create_ex(GWN_PRIM_TRI_STRIP, vbo, NULL, 0);
+ gpu_batch_presets_register(g_batch_link.batch_single);
+
+ /* Instances data */
+ Gwn_VertFormat format_inst = {0};
+ g_batch_link.p0_id = GWN_vertformat_attr_add(&format_inst, "P0", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ g_batch_link.p1_id = GWN_vertformat_attr_add(&format_inst, "P1", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ g_batch_link.p2_id = GWN_vertformat_attr_add(&format_inst, "P2", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ g_batch_link.p3_id = GWN_vertformat_attr_add(&format_inst, "P3", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ g_batch_link.colid_id = GWN_vertformat_attr_add(&format_inst, "colid_doarrow", GWN_COMP_U8, 4, GWN_FETCH_INT);
+ g_batch_link.inst_vbo = GWN_vertbuf_create_with_format_ex(&format_inst, GWN_USAGE_STREAM);
+ GWN_vertbuf_data_alloc(g_batch_link.inst_vbo, NODELINK_GROUP_SIZE); /* Alloc max count but only draw the range we need. */
+
+ GWN_batch_instbuf_set(g_batch_link.batch, g_batch_link.inst_vbo, true);
+
+ nodelink_batch_reset();
}
-#if 0 /* not used in 2.5x yet */
-static void node_link_straight_points(View2D *UNUSED(v2d), SpaceNode *snode, bNodeLink *link, float coord_array[][2])
+static char nodelink_get_color_id(int th_col)
{
- if (link->fromsock) {
- coord_array[0][0] = link->fromsock->locx;
- coord_array[0][1] = link->fromsock->locy;
- }
- else {
- if (snode == NULL) return;
- coord_array[0][0] = snode->mx;
- coord_array[0][1] = snode->my;
- }
- if (link->tosock) {
- coord_array[1][0] = link->tosock->locx;
- coord_array[1][1] = link->tosock->locy;
- }
- else {
- if (snode == NULL) return;
- coord_array[1][0] = snode->mx;
- coord_array[1][1] = snode->my;
+ switch (th_col) {
+ case TH_WIRE: return 1;
+ case TH_WIRE_INNER: return 2;
+ case TH_ACTIVE: return 3;
+ case TH_EDGE_SELECT: return 4;
+ case TH_REDALERT: return 5;
}
+ return 0;
}
-void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link,
- int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3)
+static void nodelink_batch_draw(SpaceNode *snode)
{
- float coord_array[2][2];
- int i;
-
- node_link_straight_points(v2d, snode, link, coord_array);
-
- glEnable(GL_LINE_SMOOTH);
-
- if (do_triple) {
- UI_ThemeColorShadeAlpha(th_col3, -80, -120);
- glLineWidth(4.0f);
-
- glBegin(GL_LINES);
- glVertex2fv(coord_array[0]);
- glVertex2fv(coord_array[1]);
- glEnd();
+ if (g_batch_link.count == 0)
+ return;
+
+ glEnable(GL_BLEND);
+
+ float colors[6][4] = {{0.0f}};
+ UI_GetThemeColor4fv(TH_WIRE_INNER, colors[nodelink_get_color_id(TH_WIRE_INNER)]);
+ UI_GetThemeColor4fv(TH_WIRE, colors[nodelink_get_color_id(TH_WIRE)]);
+ UI_GetThemeColor4fv(TH_ACTIVE, colors[nodelink_get_color_id(TH_ACTIVE)]);
+ UI_GetThemeColor4fv(TH_EDGE_SELECT, colors[nodelink_get_color_id(TH_EDGE_SELECT)]);
+ UI_GetThemeColor4fv(TH_REDALERT, colors[nodelink_get_color_id(TH_REDALERT)]);
+
+ GWN_vertbuf_vertex_count_set(g_batch_link.inst_vbo, g_batch_link.count);
+ GWN_vertbuf_use(g_batch_link.inst_vbo); /* force update. */
+
+ GWN_batch_program_set_builtin(g_batch_link.batch, GPU_SHADER_2D_NODELINK_INST);
+ GWN_batch_uniform_4fv_array(g_batch_link.batch, "colors", 6, (float *)colors);
+ GWN_batch_uniform_1f(g_batch_link.batch, "expandSize", snode->aspect * LINK_WIDTH);
+ GWN_batch_uniform_1f(g_batch_link.batch, "arrowSize", ARROW_SIZE);
+ GWN_batch_draw(g_batch_link.batch);
+
+ nodelink_batch_reset();
+
+ glDisable(GL_BLEND);
+}
+
+void nodelink_batch_start(SpaceNode *UNUSED(snode))
+{
+ g_batch_link.enabled = true;
+}
+
+void nodelink_batch_end(SpaceNode *snode)
+{
+ nodelink_batch_draw(snode);
+ g_batch_link.enabled = false;
+}
+
+static void nodelink_batch_add_link(
+ SpaceNode *snode,
+ const float p0[2], const float p1[2], const float p2[2], const float p3[2],
+ int th_col1, int th_col2, int th_col3, bool drawarrow)
+{
+ /* Only allow these colors. If more is needed, you need to modify the shader accordingly. */
+ BLI_assert(ELEM(th_col1, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT));
+ BLI_assert(ELEM(th_col2, TH_WIRE_INNER, TH_WIRE, TH_ACTIVE, TH_EDGE_SELECT, TH_REDALERT));
+ BLI_assert(ELEM(th_col3, TH_WIRE, -1));
+
+ g_batch_link.count++;
+ copy_v2_v2(GWN_vertbuf_raw_step(&g_batch_link.p0_step), p0);
+ copy_v2_v2(GWN_vertbuf_raw_step(&g_batch_link.p1_step), p1);
+ copy_v2_v2(GWN_vertbuf_raw_step(&g_batch_link.p2_step), p2);
+ copy_v2_v2(GWN_vertbuf_raw_step(&g_batch_link.p3_step), p3);
+ char *colid = GWN_vertbuf_raw_step(&g_batch_link.colid_step);
+ colid[0] = nodelink_get_color_id(th_col1);
+ colid[1] = nodelink_get_color_id(th_col2);
+ colid[2] = nodelink_get_color_id(th_col3);
+ colid[3] = drawarrow;
+
+ if (g_batch_link.count == NODELINK_GROUP_SIZE) {
+ nodelink_batch_draw(snode);
}
-
- UI_ThemeColor(th_col1);
- glLineWidth(1.5f);
-
- /* XXX using GL_LINES for shaded node lines is a workaround
- * for Intel hardware, this breaks with GL_LINE_STRIP and
- * changing color in begin/end blocks.
- */
- if (do_shaded) {
- glBegin(GL_LINES);
- for (i = 0; i < LINK_RESOL - 1; ++i) {
- float t = (float)i / (float)(LINK_RESOL - 1);
- UI_ThemeColorBlend(th_col1, th_col2, t);
- glVertex2f((1.0f - t) * coord_array[0][0] + t * coord_array[1][0],
- (1.0f - t) * coord_array[0][1] + t * coord_array[1][1]);
-
- t = (float)(i + 1) / (float)(LINK_RESOL - 1);
- UI_ThemeColorBlend(th_col1, th_col2, t);
- glVertex2f((1.0f - t) * coord_array[0][0] + t * coord_array[1][0],
- (1.0f - t) * coord_array[0][1] + t * coord_array[1][1]);
+}
+
+/* don't do shadows if th_col3 is -1. */
+void node_draw_link_bezier(View2D *v2d, SpaceNode *snode, bNodeLink *link,
+ int th_col1, int th_col2, int th_col3)
+{
+ float vec[4][2];
+
+ if (node_link_bezier_handles(v2d, snode, link, vec)) {
+ int drawarrow = ((link->tonode && (link->tonode->type == NODE_REROUTE)) &&
+ (link->fromnode && (link->fromnode->type == NODE_REROUTE)));
+
+ if (g_batch_link.batch == NULL) {
+ nodelink_batch_init();
}
- glEnd();
- }
- else {
- glBegin(GL_LINE_STRIP);
- for (i = 0; i < LINK_RESOL; ++i) {
- float t = (float)i / (float)(LINK_RESOL - 1);
- glVertex2f((1.0f - t) * coord_array[0][0] + t * coord_array[1][0],
- (1.0f - t) * coord_array[0][1] + t * coord_array[1][1]);
+
+ if (g_batch_link.enabled) {
+ /* Add link to batch. */
+ nodelink_batch_add_link(snode, vec[0], vec[1], vec[2], vec[3], th_col1, th_col2, th_col3, drawarrow);
+ }
+ else {
+ /* Draw single link. */
+ float colors[3][4] = {{0.0f}};
+ if (th_col3 != -1) {
+ UI_GetThemeColor4fv(th_col3, colors[0]);
+ }
+ UI_GetThemeColor4fv(th_col1, colors[1]);
+ UI_GetThemeColor4fv(th_col2, colors[2]);
+
+ Gwn_Batch *batch = g_batch_link.batch_single;
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_NODELINK);
+ GWN_batch_uniform_2fv_array(batch, "bezierPts", 4, (float *)vec);
+ GWN_batch_uniform_4fv_array(batch, "colors", 3, (float *)colors);
+ GWN_batch_uniform_1f(batch, "expandSize", snode->aspect * LINK_WIDTH);
+ GWN_batch_uniform_1f(batch, "arrowSize", ARROW_SIZE);
+ GWN_batch_uniform_1i(batch, "doArrow", drawarrow);
+ GWN_batch_draw(batch);
}
- glEnd();
}
-
- glDisable(GL_LINE_SMOOTH);
}
-#endif
/* note; this is used for fake links in groups too */
void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
{
- bool do_shaded = false;
- bool do_triple = false;
int th_col1 = TH_WIRE_INNER, th_col2 = TH_WIRE_INNER, th_col3 = TH_WIRE;
if (link->fromsock == NULL && link->tosock == NULL)
@@ -3623,8 +3583,7 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
/* new connection */
if (!link->fromsock || !link->tosock) {
- th_col1 = TH_ACTIVE;
- do_triple = true;
+ th_col1 = th_col2 = TH_ACTIVE;
}
else {
/* going to give issues once... */
@@ -3645,39 +3604,38 @@ void node_draw_link(View2D *v2d, SpaceNode *snode, bNodeLink *link)
if (link->tonode && link->tonode->flag & SELECT)
th_col2 = TH_EDGE_SELECT;
}
- do_shaded = true;
- do_triple = true;
}
else {
- th_col1 = TH_REDALERT;
+ th_col1 = th_col2 = TH_REDALERT;
+ // th_col3 = -1; /* no shadow */
}
}
- node_draw_link_bezier(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);
+ node_draw_link_bezier(v2d, snode, link, th_col1, th_col2, th_col3);
// node_draw_link_straight(v2d, snode, link, th_col1, do_shaded, th_col2, do_triple, th_col3);
}
-void ED_node_draw_snap(View2D *v2d, const float cent[2], float size, NodeBorder border)
+void ED_node_draw_snap(View2D *v2d, const float cent[2], float size, NodeBorder border, unsigned pos)
{
- glBegin(GL_LINES);
+ immBegin(GWN_PRIM_LINES, 4);
if (border & (NODE_LEFT | NODE_RIGHT)) {
- glVertex2f(cent[0], v2d->cur.ymin);
- glVertex2f(cent[0], v2d->cur.ymax);
+ immVertex2f(pos, cent[0], v2d->cur.ymin);
+ immVertex2f(pos, cent[0], v2d->cur.ymax);
}
else {
- glVertex2f(cent[0], cent[1] - size);
- glVertex2f(cent[0], cent[1] + size);
+ immVertex2f(pos, cent[0], cent[1] - size);
+ immVertex2f(pos, cent[0], cent[1] + size);
}
if (border & (NODE_TOP | NODE_BOTTOM)) {
- glVertex2f(v2d->cur.xmin, cent[1]);
- glVertex2f(v2d->cur.xmax, cent[1]);
+ immVertex2f(pos, v2d->cur.xmin, cent[1]);
+ immVertex2f(pos, v2d->cur.xmax, cent[1]);
}
else {
- glVertex2f(cent[0] - size, cent[1]);
- glVertex2f(cent[0] + size, cent[1]);
+ immVertex2f(pos, cent[0] - size, cent[1]);
+ immVertex2f(pos, cent[0] + size, cent[1]);
}
- glEnd();
+ immEnd();
}
diff --git a/source/blender/editors/space_node/node_add.c b/source/blender/editors/space_node/node_add.c
index ec35727d176..c200c5a7612 100644
--- a/source/blender/editors/space_node/node_add.c
+++ b/source/blender/editors/space_node/node_add.c
@@ -316,10 +316,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
switch (snode->nodetree->type) {
case NTREE_SHADER:
- if (BKE_scene_use_new_shading_nodes(CTX_data_scene(C)))
- type = SH_NODE_TEX_IMAGE;
- else
- type = SH_NODE_TEXTURE;
+ type = SH_NODE_TEX_IMAGE;
break;
case NTREE_TEXTURE:
type = TEX_NODE_IMAGE;
@@ -340,14 +337,7 @@ static int node_add_file_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- if (type == SH_NODE_TEXTURE) {
- Tex *tex = BKE_texture_add(CTX_data_main(C), DATA_(ima->id.name));
- tex->ima = ima;
- node->id = (ID *)tex;
- WM_event_add_notifier(C, NC_TEXTURE | NA_ADDED, node->id);
- }
- else
- node->id = (ID *)ima;
+ node->id = (ID *)ima;
/* When adding new image file via drag-drop we need to load imbuf in order
* to get proper image source.
diff --git a/source/blender/editors/space_node/node_draw.c b/source/blender/editors/space_node/node_draw.c
index e56a3a549fc..ae810b0fde0 100644
--- a/source/blender/editors/space_node/node_draw.c
+++ b/source/blender/editors/space_node/node_draw.c
@@ -44,16 +44,21 @@
#include "BLT_translation.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_node.h"
+#include "DEG_depsgraph.h"
+
#include "BLF_api.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_draw.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -128,10 +133,10 @@ void ED_node_tag_update_id(ID *id)
* all the users of this tree will have update
* flushed from the tree,
*/
- DAG_id_tag_update(&ntree->id, 0);
+ DEG_id_tag_update(&ntree->id, 0);
if (ntree->type == NTREE_SHADER) {
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
if (GS(id->name) == ID_MA)
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, id);
@@ -144,12 +149,12 @@ void ED_node_tag_update_id(ID *id)
WM_main_add_notifier(NC_SCENE | ND_NODES, id);
}
else if (ntree->type == NTREE_TEXTURE) {
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_TEXTURE | ND_NODES, id);
}
else if (id == &ntree->id) {
/* node groups */
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
}
}
@@ -616,112 +621,23 @@ static void node_draw_mute_line(View2D *v2d, SpaceNode *snode, bNode *node)
bNodeLink *link;
glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
for (link = node->internal_links.first; link; link = link->next)
- node_draw_link_bezier(v2d, snode, link, TH_REDALERT, 0, TH_WIRE, 0, TH_WIRE);
-
- glDisable(GL_BLEND);
- glDisable(GL_LINE_SMOOTH);
-}
-
-static void node_socket_shape_draw(
- float x, float y, float size, const float col[4], bool highlight,
- const float coords[][2], int coords_len)
-{
- int a;
-
- glColor4fv(col);
-
- glEnable(GL_BLEND);
- glBegin(GL_POLYGON);
- for (a = 0; a < coords_len; a++) {
- glVertex2f(x + size * coords[a][0], y + size * coords[a][1]);
- }
- glEnd();
- glDisable(GL_BLEND);
+ node_draw_link_bezier(v2d, snode, link, TH_REDALERT, TH_REDALERT, -1);
- if (highlight) {
- UI_ThemeColor(TH_TEXT_HI);
- glLineWidth(1.5f);
- }
- else {
- glColor4ub(0, 0, 0, 150);
- }
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
- glBegin(GL_LINE_LOOP);
- for (a = 0; a < coords_len; a++) {
- glVertex2f(x + size * coords[a][0], y + size * coords[a][1]);
- }
- glEnd();
- glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
-
-void node_socket_draw(const bContext *C, bNodeTree *ntree, bNode *node, bNodeSocket *sock, float size, bool highlight)
+static void node_socket_circle_draw(const bContext *C, bNodeTree *ntree, PointerRNA node_ptr, bNodeSocket *sock, unsigned pos, unsigned col)
{
- PointerRNA ptr, node_ptr;
+ PointerRNA ptr;
float color[4];
RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &ptr);
- RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr);
sock->typeinfo->draw_color((bContext *)C, &ptr, &node_ptr, color);
-
- /* 16 values of {sin, cos} function */
- const float shape_circle[16][2] = {
- {0.00000000f, 1.00000000f},
- {0.39435585f, 0.91895781f},
- {0.72479278f, 0.68896691f},
- {0.93775213f, 0.34730525f},
- {0.99871650f, -0.05064916f},
- {0.89780453f, -0.44039415f},
- {0.65137248f, -0.75875812f},
- {0.29936312f, -0.95413925f},
- {-0.10116832f, -0.99486932f},
- {-0.48530196f, -0.87434661f},
- {-0.79077573f, -0.61210598f},
- {-0.96807711f, -0.25065253f},
- {-0.98846832f, 0.15142777f},
- {-0.84864425f, 0.52896401f},
- {-0.57126821f, 0.82076344f},
- {-0.20129852f, 0.97952994f }
- };
-
- const float shape_diamond[4][2] = {
- {0.0f, 1.2f},
- {1.2f, 0.0f},
- {0.0f, -1.2f},
- {-1.2f, 0.0f},
- };
-
- const float shape_square[4][2] = {
- {-0.9f, 0.9f},
- {0.9f, 0.9f},
- {0.9f, -0.9f},
- {-0.9f, -0.9f},
- };
-
- const float (*shape)[2];
- int shape_len;
- switch (sock->draw_shape) {
- default:
- case SOCK_DRAW_SHAPE_CIRCLE:
- shape = shape_circle;
- shape_len = ARRAY_SIZE(shape_circle);
- break;
- case SOCK_DRAW_SHAPE_DIAMOND:
- shape = shape_diamond;
- shape_len = ARRAY_SIZE(shape_diamond);
- break;
- case SOCK_DRAW_SHAPE_SQUARE:
- shape = shape_square;
- shape_len = ARRAY_SIZE(shape_square);
- break;
- }
-
- node_socket_shape_draw(sock->locx, sock->locy, size, color, highlight, shape, shape_len);
+
+ immAttrib4fv(col, color);
+ immVertex2f(pos, sock->locx, sock->locy);
}
/* ************** Socket callbacks *********** */
@@ -730,10 +646,15 @@ static void node_draw_preview_background(float tile, rctf *rect)
{
float x, y;
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* draw checkerboard backdrop to show alpha */
- glColor3ub(120, 120, 120);
- glRectf(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
- glColor3ub(160, 160, 160);
+ immUniformColor3ub(120, 120, 120);
+ immRectf(pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+ immUniformColor3ub(160, 160, 160);
for (y = rect->ymin; y < rect->ymax; y += tile * 2) {
for (x = rect->xmin; x < rect->xmax; x += tile * 2) {
@@ -744,7 +665,7 @@ static void node_draw_preview_background(float tile, rctf *rect)
if (y + tile > rect->ymax)
tiley = rect->ymax - y;
- glRectf(x, y, x + tilex, y + tiley);
+ immRectf(pos, x, y, x + tilex, y + tiley);
}
}
for (y = rect->ymin + tile; y < rect->ymax; y += tile * 2) {
@@ -756,9 +677,10 @@ static void node_draw_preview_background(float tile, rctf *rect)
if (y + tile > rect->ymax)
tiley = rect->ymax - y;
- glRectf(x, y, x + tilex, y + tiley);
+ immRectf(pos, x, y, x + tilex, y + tiley);
}
}
+ immUnbindProgram();
}
/* not a callback */
@@ -789,17 +711,19 @@ static void node_draw_preview(bNodePreview *preview, rctf *prv)
node_draw_preview_background(BLI_rctf_size_x(prv) / 10.0f, &draw_rect);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* premul graphics */
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); /* premul graphics */
- glColor4f(1.0, 1.0, 1.0, 1.0);
- glPixelZoom(scale, scale);
- glaDrawPixelsTex(draw_rect.xmin, draw_rect.ymin, preview->xsize, preview->ysize, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, preview->rect);
- glPixelZoom(1.0f, 1.0f);
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex(&state, draw_rect.xmin, draw_rect.ymin, preview->xsize, preview->ysize, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, preview->rect,
+ scale, scale, NULL);
glDisable(GL_BLEND);
- UI_ThemeColorShadeAlpha(TH_BACK, -15, +100);
- fdrawbox(draw_rect.xmin, draw_rect.ymin, draw_rect.xmax, draw_rect.ymax);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShadeAlpha(TH_BACK, -15, +100);
+ imm_draw_box_wire_2d(pos, draw_rect.xmin, draw_rect.ymin, draw_rect.xmax, draw_rect.ymax);
+ immUnbindProgram();
}
/* common handle function for operator buttons that need to select the node first */
@@ -824,32 +748,139 @@ void node_draw_shadow(SpaceNode *snode, bNode *node, float radius, float alpha)
else {
const float margin = 3.0f;
- glColor4f(0.0f, 0.0f, 0.0f, 0.33f);
- glEnable(GL_BLEND);
- UI_draw_roundbox(rct->xmin - margin, rct->ymin - margin,
- rct->xmax + margin, rct->ymax + margin, radius + margin);
- glDisable(GL_BLEND);
+ float color[4] = {0.0f, 0.0f, 0.0f, 0.33f};
+ UI_draw_roundbox_aa(true, rct->xmin - margin, rct->ymin - margin,
+ rct->xmax + margin, rct->ymax + margin, radius + margin, color);
+ }
+}
+
+void node_draw_sockets(View2D *v2d, const bContext *C, bNodeTree *ntree, bNode *node, bool draw_outputs, bool select_all)
+{
+ const unsigned int total_input_ct = BLI_listbase_count(&node->inputs);
+ const unsigned int total_output_ct = BLI_listbase_count(&node->outputs);
+
+ if (total_input_ct + total_output_ct == 0) {
+ return;
+ }
+
+ PointerRNA node_ptr;
+ RNA_pointer_create((ID *)ntree, &RNA_Node, node, &node_ptr);
+
+ float scale;
+ UI_view2d_scale_get(v2d, &scale, NULL);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+
+ glEnable(GL_BLEND);
+ GPU_enable_program_point_size();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_POINT_UNIFORM_SIZE_VARYING_COLOR_OUTLINE_AA);
+
+ /* set handle size */
+ immUniform1f("size", 2.0f * NODE_SOCKSIZE * scale); /* 2 * size to have diameter */
+
+ if (!select_all) {
+ /* outline for unselected sockets */
+ immUniform1f("outlineWidth", 1.0f);
+ immUniform4f("outlineColor", 0.0f, 0.0f, 0.0f, 0.6f);
+
+ immBeginAtMost(GWN_PRIM_POINTS, total_input_ct + total_output_ct);
+ }
+
+ /* socket inputs */
+ short selected_input_ct = 0;
+ bNodeSocket *sock;
+ for (sock = node->inputs.first; sock; sock = sock->next) {
+ if (nodeSocketIsHidden(sock))
+ continue;
+ if (select_all || (sock->flag & SELECT)) {
+ ++selected_input_ct;
+ continue;
+ }
+
+ node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col);
+ }
+
+ /* socket outputs */
+ short selected_output_ct = 0;
+ if (draw_outputs) {
+ for (sock = node->outputs.first; sock; sock = sock->next) {
+ if (nodeSocketIsHidden(sock))
+ continue;
+ if (select_all || (sock->flag & SELECT)) {
+ ++selected_output_ct;
+ continue;
+ }
+
+ node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col);
+ }
+ }
+
+ if (!select_all) {
+ immEnd();
+ }
+
+ /* go back and draw selected sockets */
+ if (selected_input_ct + selected_output_ct > 0) {
+ /* outline for selected sockets */
+ float c[3];
+ UI_GetThemeColor3fv(TH_TEXT_HI, c);
+ immUniform4f("outlineColor", c[0], c[1], c[2], 1.0f);
+ immUniform1f("outlineWidth", 1.5f);
+
+ immBegin(GWN_PRIM_POINTS, selected_input_ct + selected_output_ct);
+
+ if (selected_input_ct) {
+ /* socket inputs */
+ for (sock = node->inputs.first; sock; sock = sock->next) {
+ if (nodeSocketIsHidden(sock))
+ continue;
+ if (select_all || (sock->flag & SELECT)) {
+ node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col);
+ if (--selected_input_ct == 0)
+ break; /* stop as soon as last one is drawn */
+ }
+ }
+ }
+
+ if (selected_output_ct) {
+ /* socket outputs */
+ for (sock = node->outputs.first; sock; sock = sock->next) {
+ if (nodeSocketIsHidden(sock))
+ continue;
+ if (select_all || (sock->flag & SELECT)) {
+ node_socket_circle_draw(C, ntree, node_ptr, sock, pos, col);
+ if (--selected_output_ct == 0)
+ break; /* stop as soon as last one is drawn */
+ }
+ }
+ }
+
+ immEnd();
}
+
+ immUnbindProgram();
+
+ GPU_disable_program_point_size();
+ glDisable(GL_BLEND);
}
static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey key)
{
bNodeInstanceHash *previews = CTX_data_pointer_get(C, "node_previews").data;
- bNodeSocket *sock;
rctf *rct = &node->totr;
float iconofs;
/* float socket_size = NODE_SOCKSIZE*U.dpi/72; */ /* UNUSED */
float iconbutw = 0.8f * UI_UNIT_X;
int color_id = node_get_colorid(node);
+ float color[4];
char showname[128]; /* 128 used below */
View2D *v2d = &ar->v2d;
- /* XXX hack: copy values from linked ID data where displayed as sockets */
- if (node->block)
- nodeSynchronizeID(node, false);
-
/* skip if out of view */
- if (BLI_rctf_isect(&node->totr, &ar->v2d.cur, NULL) == false) {
+ if (BLI_rctf_isect(&node->totr, &v2d->cur, NULL) == false) {
UI_block_end(C, node->block);
node->block = NULL;
return;
@@ -858,23 +889,24 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
/* shadow */
node_draw_shadow(snode, node, BASIS_RAD, 1.0f);
- /* header uses color from backdrop, but we make it opaqie */
- if (color_id == TH_NODE) {
- float col[3];
- UI_GetThemeColorShade3fv(color_id, -20, col);
- glColor4f(col[0], col[1], col[2], 1.0f);
+ if (node->flag & NODE_MUTED) {
+ UI_GetThemeColorBlendShade4fv(color_id, TH_REDALERT, 0.5f, 0, color);
+ }
+ else {
+ /* header uses color from backdrop, but we make it opaque */
+ if (color_id == TH_NODE) {
+ UI_GetThemeColorShade3fv(color_id, -20, color);
+ color[3] = 1.0f;
+ }
+ else {
+ UI_GetThemeColor4fv(color_id, color);
+ }
}
- else
- UI_ThemeColor(color_id);
-
- if (node->flag & NODE_MUTED)
- UI_ThemeColorBlend(color_id, TH_REDALERT, 0.5f);
-
glLineWidth(1.0f);
UI_draw_roundbox_corner_set(UI_CNR_TOP_LEFT | UI_CNR_TOP_RIGHT);
- UI_draw_roundbox(rct->xmin, rct->ymax - NODE_DY, rct->xmax, rct->ymax, BASIS_RAD);
+ UI_draw_roundbox_aa(true, rct->xmin, rct->ymax - NODE_DY, rct->xmax, rct->ymax, BASIS_RAD, color);
/* show/hide icons */
iconofs = rct->xmax - 0.35f * U.widget_unit;
@@ -907,10 +939,12 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
}
/* title */
- if (node->flag & SELECT)
- UI_ThemeColor(TH_SELECT);
- else
- UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.4f, 10);
+ if (node->flag & SELECT) {
+ UI_GetThemeColor4fv(TH_SELECT, color);
+ }
+ else {
+ UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color);
+ }
/* open/close entirely? */
{
@@ -925,17 +959,9 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
UI_block_emboss_set(node->block, UI_EMBOSS);
/* custom draw function for this button */
- UI_draw_icon_tri(rct->xmin + 0.5f * U.widget_unit, rct->ymax - NODE_DY / 2.0f, 'v');
+ UI_draw_icon_tri(rct->xmin + 0.5f * U.widget_unit, rct->ymax - NODE_DY / 2.0f, 'v', color);
}
- /* this isn't doing anything for the label, so commenting out */
-#if 0
- if (node->flag & SELECT)
- UI_ThemeColor(TH_TEXT_HI);
- else
- UI_ThemeColor(TH_TEXT);
-#endif
-
nodeLabel(ntree, node, showname, sizeof(showname));
//if (node->flag & NODE_MUTED)
@@ -948,55 +974,30 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
/* body */
if (!nodeIsRegistered(node))
- UI_ThemeColor4(TH_REDALERT); /* use warning color to indicate undefined types */
- else if (node->flag & NODE_CUSTOM_COLOR)
- glColor3fv(node->color);
+ UI_GetThemeColor4fv(TH_REDALERT, color); /* use warning color to indicate undefined types */
+ else if (node->flag & NODE_CUSTOM_COLOR) {
+ rgba_float_args_set(color, node->color[0], node->color[1], node->color[2], 1.0f);
+ }
else
- UI_ThemeColor4(TH_NODE);
- glEnable(GL_BLEND);
+ UI_GetThemeColor4fv(TH_NODE, color);
+
UI_draw_roundbox_corner_set(UI_CNR_BOTTOM_LEFT | UI_CNR_BOTTOM_RIGHT);
- UI_draw_roundbox(rct->xmin, rct->ymin, rct->xmax, rct->ymax - NODE_DY, BASIS_RAD);
- glDisable(GL_BLEND);
+ UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax - NODE_DY, BASIS_RAD, color);
/* outline active and selected emphasis */
if (node->flag & SELECT) {
-
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
-
- if (node->flag & NODE_ACTIVE)
- UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -40);
- else
- UI_ThemeColorShadeAlpha(TH_SELECT, 0, -40);
-
+ UI_GetThemeColorShadeAlpha4fv((node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, 0, -40, color);
+
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD);
-
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
+ UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, BASIS_RAD, color);
}
/* disable lines */
if (node->flag & NODE_MUTED)
node_draw_mute_line(v2d, snode, node);
-
- /* socket inputs, buttons */
- for (sock = node->inputs.first; sock; sock = sock->next) {
- if (nodeSocketIsHidden(sock))
- continue;
-
- node_socket_draw(C, ntree, node, sock, NODE_SOCKSIZE, sock->flag & SELECT);
- }
-
- /* socket outputs */
- for (sock = node->outputs.first; sock; sock = sock->next) {
- if (nodeSocketIsHidden(sock))
- continue;
-
- node_socket_draw(C, ntree, node, sock, NODE_SOCKSIZE, sock->flag & SELECT);
- }
-
+ node_draw_sockets(v2d, C, ntree, node, true, false);
+
/* preview */
if (node->flag & NODE_PREVIEW && previews) {
bNodePreview *preview = BKE_node_instance_hash_lookup(previews, key);
@@ -1016,37 +1017,33 @@ static void node_draw_basis(const bContext *C, ARegion *ar, SpaceNode *snode, bN
static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeTree *ntree, bNode *node, bNodeInstanceKey UNUSED(key))
{
- bNodeSocket *sock;
rctf *rct = &node->totr;
float dx, centy = BLI_rctf_cent_y(rct);
float hiddenrad = BLI_rctf_size_y(rct) / 2.0f;
- float socket_size = NODE_SOCKSIZE;
int color_id = node_get_colorid(node);
+ float color[4];
char showname[128]; /* 128 is used below */
+ View2D *v2d = &ar->v2d;
+ float scale;
+
+ UI_view2d_scale_get(v2d, &scale, NULL);
/* shadow */
node_draw_shadow(snode, node, hiddenrad, 1.0f);
/* body */
- UI_ThemeColor(color_id);
if (node->flag & NODE_MUTED)
- UI_ThemeColorBlend(color_id, TH_REDALERT, 0.5f);
-
- UI_draw_roundbox(rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad);
+ UI_GetThemeColorBlendShade4fv(color_id, TH_REDALERT, 0.5f, 0, color);
+ else
+ UI_GetThemeColor4fv(color_id, color);
+
+ UI_draw_roundbox_aa(true, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad, color);
/* outline active and selected emphasis */
if (node->flag & SELECT) {
- glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
-
- if (node->flag & NODE_ACTIVE)
- UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -40);
- else
- UI_ThemeColorShadeAlpha(TH_SELECT, 0, -40);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad);
-
- glDisable(GL_LINE_SMOOTH);
- glDisable(GL_BLEND);
+ UI_GetThemeColorShadeAlpha4fv((node->flag & NODE_ACTIVE) ? TH_ACTIVE : TH_SELECT, 0, -40, color);
+
+ UI_draw_roundbox_aa(false, rct->xmin, rct->ymin, rct->xmax, rct->ymax, hiddenrad, color);
}
/* custom color inline */
@@ -1054,18 +1051,19 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
- glColor3fv(node->color);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, rct->xmin + 1, rct->ymin + 1, rct->xmax -1, rct->ymax - 1, hiddenrad);
+ UI_draw_roundbox_3fvAlpha(false, rct->xmin + 1, rct->ymin + 1, rct->xmax -1, rct->ymax - 1, hiddenrad, node->color, 1.0f);
glDisable(GL_LINE_SMOOTH);
glDisable(GL_BLEND);
}
/* title */
- if (node->flag & SELECT)
- UI_ThemeColor(TH_SELECT);
- else
- UI_ThemeColorBlendShade(TH_TEXT, color_id, 0.4f, 10);
+ if (node->flag & SELECT) {
+ UI_GetThemeColor4fv(TH_SELECT, color);
+ }
+ else {
+ UI_GetThemeColorBlendShade4fv(TH_SELECT, color_id, 0.4f, 10, color);
+ }
/* open entirely icon */
{
@@ -1080,18 +1078,13 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
UI_block_emboss_set(node->block, UI_EMBOSS);
/* custom draw function for this button */
- UI_draw_icon_tri(rct->xmin + 10.0f, centy, 'h');
+ UI_draw_icon_tri(rct->xmin + 10.0f, centy, 'h', color);
}
/* disable lines */
if (node->flag & NODE_MUTED)
node_draw_mute_line(&ar->v2d, snode, node);
-
- if (node->flag & SELECT)
- UI_ThemeColor(TH_SELECT);
- else
- UI_ThemeColor(TH_TEXT);
-
+
if (node->miniwidth > 0.0f) {
nodeLabel(ntree, node, showname, sizeof(showname));
@@ -1105,29 +1098,35 @@ static void node_draw_hidden(const bContext *C, ARegion *ar, SpaceNode *snode, b
}
/* scale widget thing */
- UI_ThemeColorShade(color_id, -10);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColorShade(color_id, -10);
dx = 10.0f;
- fdrawline(rct->xmax - dx, centy - 4.0f, rct->xmax - dx, centy + 4.0f);
- fdrawline(rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f);
-
- UI_ThemeColorShade(color_id, +30);
+
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, rct->xmax - dx, centy - 4.0f);
+ immVertex2f(pos, rct->xmax - dx, centy + 4.0f);
+
+ immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f);
+ immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f);
+ immEnd();
+
+ immUniformThemeColorShade(color_id, 30);
dx -= snode->aspect;
- fdrawline(rct->xmax - dx, centy - 4.0f, rct->xmax - dx, centy + 4.0f);
- fdrawline(rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f);
- /* sockets */
- for (sock = node->inputs.first; sock; sock = sock->next) {
- if (!nodeSocketIsHidden(sock)) {
- node_socket_draw(C, ntree, node, sock, socket_size, sock->flag & SELECT);
- }
- }
-
- for (sock = node->outputs.first; sock; sock = sock->next) {
- if (!nodeSocketIsHidden(sock)) {
- node_socket_draw(C, ntree, node, sock, socket_size, sock->flag & SELECT);
- }
- }
-
+ immBegin(GWN_PRIM_LINES, 4);
+ immVertex2f(pos, rct->xmax - dx, centy - 4.0f);
+ immVertex2f(pos, rct->xmax - dx, centy + 4.0f);
+
+ immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy - 4.0f);
+ immVertex2f(pos, rct->xmax - dx - 3.0f * snode->aspect, centy + 4.0f);
+ immEnd();
+
+ immUnbindProgram();
+
+ node_draw_sockets(v2d, C, ntree, node, true, false);
+
UI_block_end(C, node->block);
UI_block_draw(C, node->block);
node->block = NULL;
@@ -1241,12 +1240,12 @@ void node_draw_nodetree(const bContext *C, ARegion *ar, SpaceNode *snode, bNodeT
/* node lines */
glEnable(GL_BLEND);
- glEnable(GL_LINE_SMOOTH);
+ nodelink_batch_start(snode);
for (link = ntree->links.first; link; link = link->next) {
if (!nodeLinkIsHidden(link))
node_draw_link(&ar->v2d, snode, link);
}
- glDisable(GL_LINE_SMOOTH);
+ nodelink_batch_end(snode);
glDisable(GL_BLEND);
/* draw foreground nodes, last nodes in front */
@@ -1268,7 +1267,7 @@ static void draw_tree_path(SpaceNode *snode)
ED_node_tree_path_get_fixedbuf(snode, info, sizeof(info));
- UI_ThemeColor(TH_TEXT_HI);
+ UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
BLF_draw_default(1.5f * UI_UNIT_X, 1.5f * UI_UNIT_Y, 0.0f, info, sizeof(info));
}
@@ -1301,12 +1300,14 @@ static void draw_group_overlay(const bContext *C, ARegion *ar)
View2D *v2d = &ar->v2d;
rctf rect = v2d->cur;
uiBlock *block;
-
+ float color[4];
+
/* shade node groups to separate them visually */
- UI_ThemeColorShadeAlpha(TH_NODE_GROUP, 0, -70);
glEnable(GL_BLEND);
+
+ UI_GetThemeColorShadeAlpha4fv(TH_NODE_GROUP, 0, -70, color);
UI_draw_roundbox_corner_set(UI_CNR_NONE);
- UI_draw_roundbox_gl_mode(GL_POLYGON, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 0);
+ UI_draw_roundbox_4fv(true, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 0, color);
glDisable(GL_BLEND);
/* set the block bounds to clip mouse events from underlying nodes */
@@ -1337,8 +1338,7 @@ void drawnodespace(const bContext *C, ARegion *ar)
ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
/* only set once */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_MAP1_VERTEX_3);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
/* nodes */
snode_set_context(C);
@@ -1398,7 +1398,22 @@ void drawnodespace(const bContext *C, ARegion *ar)
/* backdrop */
draw_nodespace_back_pix(C, ar, snode, path->parent_key);
-
+
+ {
+ float original_proj[4][4];
+ gpuGetProjectionMatrix(original_proj);
+
+ gpuPushMatrix();
+ gpuLoadIdentity();
+
+ wmOrtho2_pixelspace(ar->winx, ar->winy);
+
+ WM_manipulatormap_draw(ar->manipulator_map, C, WM_MANIPULATORMAP_DRAWSTEP_2D);
+
+ gpuPopMatrix();
+ gpuLoadProjectionMatrix(original_proj);
+ }
+
draw_nodetree(C, ar, ntree, path->parent_key);
}
diff --git a/source/blender/editors/space_node/node_edit.c b/source/blender/editors/space_node/node_edit.c
index e38b48d4bb8..d91c330c853 100644
--- a/source/blender/editors/space_node/node_edit.c
+++ b/source/blender/editors/space_node/node_edit.c
@@ -41,7 +41,6 @@
#include "BLI_blenlib.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_library.h"
@@ -50,6 +49,8 @@
#include "BKE_report.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+
#include "RE_engine.h"
#include "RE_pipeline.h"
@@ -123,7 +124,7 @@ static int compo_get_recalc_flags(const bContext *C)
int recalc_flags = 0;
for (win = wm->windows.first; win; win = win->next) {
- bScreen *sc = win->screen;
+ const bScreen *sc = WM_window_get_active_screen(win);
ScrArea *sa;
for (sa = sc->areabase.first; sa; sa = sa->next) {
@@ -328,11 +329,11 @@ void snode_dag_update(bContext *C, SpaceNode *snode)
if (snode->edittree != snode->nodetree) {
FOREACH_NODETREE(bmain, tntree, id) {
if (ntreeHasTree(tntree, snode->edittree))
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
} FOREACH_NODETREE_END
}
- DAG_id_tag_update(snode->id, 0);
+ DEG_id_tag_update(snode->id, 0);
}
void snode_notify(bContext *C, SpaceNode *snode)
@@ -382,7 +383,6 @@ bool ED_node_is_texture(struct SpaceNode *snode)
/* called from shading buttons or header */
void ED_node_shader_default(const bContext *C, ID *id)
{
- Scene *scene = CTX_data_scene(C);
bNode *in, *out;
bNodeSocket *fromsock, *tosock, *sock;
bNodeTree *ntree;
@@ -397,14 +397,8 @@ void ED_node_shader_default(const bContext *C, ID *id)
Material *ma = (Material *)id;
ma->nodetree = ntree;
- if (BKE_scene_use_new_shading_nodes(scene)) {
- output_type = SH_NODE_OUTPUT_MATERIAL;
- shader_type = SH_NODE_BSDF_DIFFUSE;
- }
- else {
- output_type = SH_NODE_OUTPUT;
- shader_type = SH_NODE_MATERIAL;
- }
+ output_type = SH_NODE_OUTPUT_MATERIAL;
+ shader_type = SH_NODE_BSDF_PRINCIPLED;
copy_v3_v3(color, &ma->r);
strength = 0.0f;
@@ -455,18 +449,16 @@ void ED_node_shader_default(const bContext *C, ID *id)
nodeAddLink(ntree, in, fromsock, out, tosock);
/* default values */
- if (BKE_scene_use_new_shading_nodes(scene)) {
- PointerRNA sockptr;
- sock = in->inputs.first;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr);
-
- RNA_float_set_array(&sockptr, "default_value", color);
+ PointerRNA sockptr;
+ sock = in->inputs.first;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr);
+
+ RNA_float_set_array(&sockptr, "default_value", color);
- if (strength != 0.0f) {
- sock = in->inputs.last;
- RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr);
- RNA_float_set(&sockptr, "default_value", strength);
- }
+ if (strength != 0.0f) {
+ sock = in->inputs.last;
+ RNA_pointer_create((ID *)ntree, &RNA_NodeSocket, sock, &sockptr);
+ RNA_float_set(&sockptr, "default_value", strength);
}
ntreeUpdateTree(CTX_data_main(C), ntree);
@@ -545,12 +537,6 @@ void snode_set_context(const bContext *C)
bNodeTree *ntree = snode->nodetree;
ID *id = snode->id, *from = snode->from;
- /* we use this to signal warnings, when node shaders are drawn in wrong render engine */
- if (BKE_scene_use_new_shading_nodes(CTX_data_scene(C)))
- snode->flag |= SNODE_NEW_SHADERS;
- else
- snode->flag &= ~SNODE_NEW_SHADERS;
-
/* check the tree type */
if (!treetype ||
(treetype->poll && !treetype->poll(C, treetype)))
@@ -638,7 +624,7 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
if (node->id && ELEM(GS(node->id->name), ID_MA, ID_LA, ID_WO))
nodeClearActiveID(ntree, ID_TE);
- if (ELEM(node->type, SH_NODE_OUTPUT, SH_NODE_OUTPUT_MATERIAL,
+ if (ELEM(node->type, SH_NODE_OUTPUT_MATERIAL,
SH_NODE_OUTPUT_WORLD, SH_NODE_OUTPUT_LAMP, SH_NODE_OUTPUT_LINESTYLE))
{
bNode *tnode;
@@ -689,22 +675,6 @@ void ED_node_set_active(Main *bmain, bNodeTree *ntree, bNode *node)
/* addnode() doesnt link this yet... */
node->id = (ID *)BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
}
- else if (node->type == CMP_NODE_R_LAYERS) {
- Scene *scene;
-
- for (scene = bmain->scene.first; scene; scene = scene->id.next) {
- if (scene->nodetree && scene->use_nodes && ntreeHasTree(scene->nodetree, ntree)) {
- if (node->id == NULL || node->id == (ID *)scene) {
- int num_layers = BLI_listbase_count(&scene->r.layers);
- scene->r.actlay = node->custom1;
- /* Clamp the value, because it might have come from a different
- * scene which could have more render layers than new one.
- */
- scene->r.actlay = min_ff(scene->r.actlay, num_layers - 1);
- }
- }
- }
- }
else if (node->type == CMP_NODE_COMPOSITE) {
if (was_output == 0) {
bNode *tnode;
@@ -1271,7 +1241,7 @@ bool ED_node_select_check(ListBase *lb)
/* goes over all scenes, reads render layers */
-static int node_read_renderlayers_exec(bContext *C, wmOperator *UNUSED(op))
+static int node_read_viewlayers_exec(bContext *C, wmOperator *UNUSED(op))
{
Main *bmain = CTX_data_main(C);
SpaceNode *snode = CTX_wm_space_node(C);
@@ -1301,48 +1271,14 @@ static int node_read_renderlayers_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
}
-void NODE_OT_read_renderlayers(wmOperatorType *ot)
+void NODE_OT_read_viewlayers(wmOperatorType *ot)
{
- ot->name = "Read Render Layers";
- ot->idname = "NODE_OT_read_renderlayers";
+ ot->name = "Read View Layers";
+ ot->idname = "NODE_OT_read_viewlayers";
ot->description = "Read all render layers of all used scenes";
- ot->exec = node_read_renderlayers_exec;
-
- ot->poll = composite_node_active;
-
- /* flags */
- ot->flag = 0;
-}
-
-static int node_read_fullsamplelayers_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Main *bmain = CTX_data_main(C);
- SpaceNode *snode = CTX_wm_space_node(C);
- Scene *curscene = CTX_data_scene(C);
- Render *re = RE_NewSceneRender(curscene);
-
- WM_cursor_wait(1);
- RE_MergeFullSample(re, bmain, curscene, snode->nodetree);
- WM_cursor_wait(0);
-
- /* note we are careful to send the right notifier, as otherwise the
- * compositor would reexecute and overwrite the full sample result */
- WM_event_add_notifier(C, NC_SCENE | ND_COMPO_RESULT, NULL);
-
- return OPERATOR_FINISHED;
-}
-
-
-void NODE_OT_read_fullsamplelayers(wmOperatorType *ot)
-{
-
- ot->name = "Read Full Sample Layers";
- ot->idname = "NODE_OT_read_fullsamplelayers";
- ot->description = "Read all render layers of current scene, in full sample";
-
- ot->exec = node_read_fullsamplelayers_exec;
+ ot->exec = node_read_viewlayers_exec;
ot->poll = composite_node_active;
@@ -1361,13 +1297,13 @@ int node_render_changed_exec(bContext *C, wmOperator *UNUSED(op))
}
}
if (node) {
- SceneRenderLayer *srl = BLI_findlink(&sce->r.layers, node->custom1);
+ ViewLayer *view_layer = BLI_findlink(&sce->view_layers, node->custom1);
- if (srl) {
+ if (view_layer) {
PointerRNA op_ptr;
WM_operator_properties_create(&op_ptr, "RENDER_OT_render");
- RNA_string_set(&op_ptr, "layer", srl->name);
+ RNA_string_set(&op_ptr, "layer", view_layer->name);
RNA_string_set(&op_ptr, "scene", sce->id.name + 2);
/* to keep keypositions */
diff --git a/source/blender/editors/space_node/node_intern.h b/source/blender/editors/space_node/node_intern.h
index 352f9e51012..1235133f8ac 100644
--- a/source/blender/editors/space_node/node_intern.h
+++ b/source/blender/editors/space_node/node_intern.h
@@ -67,13 +67,11 @@ void snode_group_offset(struct SpaceNode *snode, float *x, float *y); /* transfo
/* node_draw.c */
int node_get_colorid(struct bNode *node);
-void node_socket_draw(
- const struct bContext *C, struct bNodeTree *ntree, struct bNode *node,
- struct bNodeSocket *sock, float size, bool highlight);
int node_get_resize_cursor(int directions);
void node_draw_shadow(struct SpaceNode *snode, struct bNode *node, float radius, float alpha);
void node_draw_default(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode,
struct bNodeTree *ntree, struct bNode *node, bNodeInstanceKey key);
+void node_draw_sockets(struct View2D *v2d, const struct bContext *C, struct bNodeTree *ntree, struct bNode *node, bool draw_outputs, bool select_all);
void node_update_default(const struct bContext *C, struct bNodeTree *ntree, struct bNode *node);
int node_select_area_default(struct bNode *node, int x, int y);
int node_tweak_area_default(struct bNode *node, int x, int y);
@@ -132,8 +130,11 @@ void NODE_OT_backimage_fit(struct wmOperatorType *ot);
void NODE_OT_backimage_sample(struct wmOperatorType *ot);
/* drawnode.c */
+void nodelink_batch_start(struct SpaceNode *snode);
+void nodelink_batch_end(struct SpaceNode *snode);
+
void node_draw_link(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link);
-void node_draw_link_bezier(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link, int th_col1, bool do_shaded, int th_col2, bool do_triple, int th_col3);
+void node_draw_link_bezier(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link, int th_col1, int th_col2, int th_col3);
bool node_link_bezier_points(struct View2D *v2d, struct SpaceNode *snode, struct bNodeLink *link, float coord_array[][2], int resol);
// void node_draw_link_straight(View2D *v2d, SpaceNode *snode, bNodeLink *link, int th_col1, int do_shaded, int th_col2, int do_triple, int th_col3 );
void draw_nodespace_back_pix(const struct bContext *C, struct ARegion *ar, struct SpaceNode *snode, bNodeInstanceKey parent_key);
@@ -199,7 +200,7 @@ void NODE_OT_options_toggle(struct wmOperatorType *ot);
void NODE_OT_node_copy_color(struct wmOperatorType *ot);
void NODE_OT_read_fullsamplelayers(struct wmOperatorType *ot);
-void NODE_OT_read_renderlayers(struct wmOperatorType *ot);
+void NODE_OT_read_viewlayers(struct wmOperatorType *ot);
void NODE_OT_render_changed(struct wmOperatorType *ot);
void NODE_OT_output_file_add_socket(struct wmOperatorType *ot);
@@ -221,6 +222,13 @@ void NODE_OT_shader_script_update(struct wmOperatorType *ot);
void NODE_OT_viewer_border(struct wmOperatorType *ot);
void NODE_OT_clear_viewer_border(struct wmOperatorType *ot);
+/* node_widgets.c */
+void NODE_WGT_backdrop_transform(struct wmManipulatorGroupType *wgt);
+void NODE_WGT_backdrop_crop(struct wmManipulatorGroupType *wgt);
+void NODE_WGT_backdrop_sun_beams(struct wmManipulatorGroupType *wgt);
+void NODE_WGT_backdrop_corner_pin(struct wmManipulatorGroupType *wgt);
+
+
extern const char *node_context_dir[];
// XXXXXX
diff --git a/source/blender/editors/space_node/node_manipulators.c b/source/blender/editors/space_node/node_manipulators.c
new file mode 100644
index 00000000000..73b0f44b043
--- /dev/null
+++ b/source/blender/editors/space_node/node_manipulators.c
@@ -0,0 +1,616 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_node/node_manipulators.c
+ * \ingroup spnode
+ */
+
+#include <math.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_math_matrix.h"
+#include "BLI_math_vector.h"
+#include "BLI_rect.h"
+
+#include "BKE_context.h"
+#include "BKE_image.h"
+
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "IMB_imbuf_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "node_intern.h"
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Local Utilities
+ * \{ */
+
+static void node_manipulator_calc_matrix_space(
+ const SpaceNode *snode, const ARegion *ar, float matrix_space[4][4])
+{
+ unit_m4(matrix_space);
+ mul_v3_fl(matrix_space[0], snode->zoom);
+ mul_v3_fl(matrix_space[1], snode->zoom);
+ matrix_space[3][0] = (ar->winx / 2) + snode->xof;
+ matrix_space[3][1] = (ar->winy / 2) + snode->yof;
+}
+
+static void node_manipulator_calc_matrix_space_with_image_dims(
+ const SpaceNode *snode, const ARegion *ar, const float image_dims[2], float matrix_space[4][4])
+{
+ unit_m4(matrix_space);
+ mul_v3_fl(matrix_space[0], snode->zoom * image_dims[0]);
+ mul_v3_fl(matrix_space[1], snode->zoom * image_dims[1]);
+ matrix_space[3][0] = ((ar->winx / 2) + snode->xof) - ((image_dims[0] / 2.0f) * snode->zoom);
+ matrix_space[3][1] = ((ar->winy / 2) + snode->yof) - ((image_dims[1] / 2.0f) * snode->zoom);
+}
+
+/** \} */
+
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Backdrop Manipulator
+ * \{ */
+
+static void manipulator_node_backdrop_prop_matrix_get(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ const SpaceNode *snode = mpr_prop->custom_func.user_data;
+ matrix[0][0] = snode->zoom;
+ matrix[1][1] = snode->zoom;
+ matrix[3][0] = snode->xof;
+ matrix[3][1] = snode->yof;
+}
+
+static void manipulator_node_backdrop_prop_matrix_set(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ const float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ SpaceNode *snode = mpr_prop->custom_func.user_data;
+ snode->zoom = matrix[0][0];
+ snode->zoom = matrix[1][1];
+ snode->xof = matrix[3][0];
+ snode->yof = matrix[3][1];
+}
+
+static bool WIDGETGROUP_node_transform_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ SpaceNode *snode = CTX_wm_space_node(C);
+
+ if ((snode->flag & SNODE_BACKDRAW) == 0) {
+ return false;
+ }
+
+ if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) {
+ bNode *node = nodeGetActive(snode->edittree);
+
+ if (node && ELEM(node->type, CMP_NODE_VIEWER, CMP_NODE_SPLITVIEWER)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static void WIDGETGROUP_node_transform_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__);
+
+ wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_cage_2d", mgroup, NULL);
+
+ RNA_enum_set(wwrapper->manipulator->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE | ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM);
+
+ mgroup->customdata = wwrapper;
+}
+
+static void WIDGETGROUP_node_transform_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmManipulator *cage = ((wmManipulatorWrapper *)mgroup->customdata)->manipulator;
+ const ARegion *ar = CTX_wm_region(C);
+ /* center is always at the origin */
+ const float origin[3] = {ar->winx / 2, ar->winy / 2};
+
+ void *lock;
+ Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+ if (ibuf) {
+ const float dims[2] = {
+ (ibuf->x > 0) ? ibuf->x : 64.0f,
+ (ibuf->y > 0) ? ibuf->y : 64.0f,
+ };
+
+ RNA_float_set_array(cage->ptr, "dimensions", dims);
+ WM_manipulator_set_matrix_location(cage, origin);
+ WM_manipulator_set_flag(cage, WM_MANIPULATOR_HIDDEN, false);
+
+ /* need to set property here for undo. TODO would prefer to do this in _init */
+ SpaceNode *snode = CTX_wm_space_node(C);
+#if 0
+ PointerRNA nodeptr;
+ RNA_pointer_create(snode->id, &RNA_SpaceNodeEditor, snode, &nodeptr);
+ WM_manipulator_target_property_def_rna(cage, "offset", &nodeptr, "backdrop_offset", -1);
+ WM_manipulator_target_property_def_rna(cage, "scale", &nodeptr, "backdrop_zoom", -1);
+#endif
+
+ WM_manipulator_target_property_def_func(
+ cage, "matrix",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_node_backdrop_prop_matrix_get,
+ .value_set_fn = manipulator_node_backdrop_prop_matrix_set,
+ .range_get_fn = NULL,
+ .user_data = snode,
+ });
+ }
+ else {
+ WM_manipulator_set_flag(cage, WM_MANIPULATOR_HIDDEN, true);
+ }
+
+ BKE_image_release_ibuf(ima, ibuf, lock);
+}
+
+void NODE_WGT_backdrop_transform(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Backdrop Transform Widget";
+ wgt->idname = "NODE_WGT_backdrop_transform";
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT;
+
+ wgt->poll = WIDGETGROUP_node_transform_poll;
+ wgt->setup = WIDGETGROUP_node_transform_setup;
+ wgt->refresh = WIDGETGROUP_node_transform_refresh;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Crop Manipulator
+ * \{ */
+
+struct NodeCropWidgetGroup {
+ wmManipulator *border;
+
+ struct {
+ float dims[2];
+ } state;
+
+ struct {
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ bContext *context;
+ } update_data;
+};
+
+static void manipulator_node_crop_update(struct NodeCropWidgetGroup *crop_group)
+{
+ RNA_property_update(crop_group->update_data.context, &crop_group->update_data.ptr, crop_group->update_data.prop);
+}
+
+static void two_xy_to_rect(const NodeTwoXYs *nxy, rctf *rect, const float dims[2], bool is_relative)
+{
+ if (is_relative) {
+ rect->xmin = nxy->fac_x1;
+ rect->xmax = nxy->fac_x2;
+ rect->ymin = nxy->fac_y1;
+ rect->ymax = nxy->fac_y2;
+ }
+ else {
+ rect->xmin = nxy->x1 / dims[0];
+ rect->xmax = nxy->x2 / dims[0];
+ rect->ymin = nxy->y1 / dims[1];
+ rect->ymax = nxy->y2 / dims[1];
+ }
+}
+
+static void two_xy_from_rect(NodeTwoXYs *nxy, const rctf *rect, const float dims[2], bool is_relative)
+{
+ if (is_relative) {
+ nxy->fac_x1 = rect->xmin;
+ nxy->fac_x2 = rect->xmax;
+ nxy->fac_y1 = rect->ymin;
+ nxy->fac_y2 = rect->ymax;
+ }
+ else {
+ nxy->x1 = rect->xmin * dims[0];
+ nxy->x2 = rect->xmax * dims[0];
+ nxy->y1 = rect->ymin * dims[1];
+ nxy->y2 = rect->ymax * dims[1];
+ }
+}
+
+/* scale callbacks */
+static void manipulator_node_crop_prop_matrix_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ struct NodeCropWidgetGroup *crop_group = mpr->parent_mgroup->customdata;
+ const float *dims = crop_group->state.dims;
+ const bNode *node = mpr_prop->custom_func.user_data;
+ const NodeTwoXYs *nxy = node->storage;
+ bool is_relative = (bool)node->custom2;
+ rctf rct;
+ two_xy_to_rect(nxy, &rct, dims, is_relative);
+ matrix[0][0] = BLI_rctf_size_x(&rct);
+ matrix[1][1] = BLI_rctf_size_y(&rct);
+ matrix[3][0] = (BLI_rctf_cent_x(&rct) - 0.5f) * dims[0];
+ matrix[3][1] = (BLI_rctf_cent_y(&rct) - 0.5f) * dims[1];
+}
+
+static void manipulator_node_crop_prop_matrix_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ const float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ struct NodeCropWidgetGroup *crop_group = mpr->parent_mgroup->customdata;
+ const float *dims = crop_group->state.dims;
+ bNode *node = mpr_prop->custom_func.user_data;
+ NodeTwoXYs *nxy = node->storage;
+ bool is_relative = (bool)node->custom2;
+ rctf rct;
+ two_xy_to_rect(nxy, &rct, dims, is_relative);
+ BLI_rctf_resize(&rct, matrix[0][0], matrix[1][1]);
+ BLI_rctf_recenter(&rct, (matrix[3][0] / dims[0]) + 0.5f, (matrix[3][1] / dims[1]) + 0.5f);
+ BLI_rctf_isect(&(rctf){.xmin = 0, .ymin = 0, .xmax = 1, .ymax = 1}, &rct, &rct);
+ two_xy_from_rect(nxy, &rct, dims, is_relative);
+ manipulator_node_crop_update(crop_group);
+}
+
+static bool WIDGETGROUP_node_crop_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ SpaceNode *snode = CTX_wm_space_node(C);
+
+ if ((snode->flag & SNODE_BACKDRAW) == 0) {
+ return false;
+ }
+
+ if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) {
+ bNode *node = nodeGetActive(snode->edittree);
+
+ if (node && ELEM(node->type, CMP_NODE_CROP)) {
+ /* ignore 'use_crop_size', we can't usefully edit the crop in this case. */
+ if ((node->custom1 & (0 << 1)) == 0) {
+ return true;
+ }
+ }
+ }
+
+ return false;
+}
+
+static void WIDGETGROUP_node_crop_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ struct NodeCropWidgetGroup *crop_group = MEM_mallocN(sizeof(struct NodeCropWidgetGroup), __func__);
+
+ crop_group->border = WM_manipulator_new("MANIPULATOR_WT_cage_2d", mgroup, NULL);
+
+ RNA_enum_set(crop_group->border->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE | ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE);
+
+ mgroup->customdata = crop_group;
+}
+
+static void WIDGETGROUP_node_crop_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ARegion *ar = CTX_wm_region(C);
+ wmManipulator *mpr = mgroup->manipulators.first;
+
+ SpaceNode *snode = CTX_wm_space_node(C);
+
+ node_manipulator_calc_matrix_space(snode, ar, mpr->matrix_space);
+}
+
+static void WIDGETGROUP_node_crop_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct NodeCropWidgetGroup *crop_group = mgroup->customdata;
+ wmManipulator *mpr = crop_group->border;
+
+ void *lock;
+ Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+ if (ibuf) {
+ crop_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f;
+ crop_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f;
+
+ RNA_float_set_array(mpr->ptr, "dimensions", crop_group->state.dims);
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+
+ SpaceNode *snode = CTX_wm_space_node(C);
+ bNode *node = nodeGetActive(snode->edittree);
+
+ crop_group->update_data.context = (bContext *)C;
+ RNA_pointer_create((ID *)snode->edittree, &RNA_CompositorNodeCrop, node, &crop_group->update_data.ptr);
+ crop_group->update_data.prop = RNA_struct_find_property(&crop_group->update_data.ptr, "relative");
+
+ WM_manipulator_target_property_def_func(
+ mpr, "matrix",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_node_crop_prop_matrix_get,
+ .value_set_fn = manipulator_node_crop_prop_matrix_set,
+ .range_get_fn = NULL,
+ .user_data = node,
+ });
+ }
+ else {
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
+ }
+
+ BKE_image_release_ibuf(ima, ibuf, lock);
+}
+
+void NODE_WGT_backdrop_crop(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Backdrop Crop Widget";
+ wgt->idname = "NODE_WGT_backdrop_crop";
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT;
+
+ wgt->poll = WIDGETGROUP_node_crop_poll;
+ wgt->setup = WIDGETGROUP_node_crop_setup;
+ wgt->draw_prepare = WIDGETGROUP_node_crop_draw_prepare;
+ wgt->refresh = WIDGETGROUP_node_crop_refresh;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Sun Beams
+ * \{ */
+
+struct NodeSunBeamsWidgetGroup {
+ wmManipulator *manipulator;
+
+ struct {
+ float dims[2];
+ } state;
+};
+
+static bool WIDGETGROUP_node_sbeam_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ SpaceNode *snode = CTX_wm_space_node(C);
+
+ if ((snode->flag & SNODE_BACKDRAW) == 0) {
+ return false;
+ }
+
+ if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) {
+ bNode *node = nodeGetActive(snode->edittree);
+
+ if (node && ELEM(node->type, CMP_NODE_SUNBEAMS)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static void WIDGETGROUP_node_sbeam_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ struct NodeSunBeamsWidgetGroup *sbeam_group = MEM_mallocN(sizeof(struct NodeSunBeamsWidgetGroup), __func__);
+
+ sbeam_group->manipulator = WM_manipulator_new("MANIPULATOR_WT_grab_3d", mgroup, NULL);
+ wmManipulator *mpr = sbeam_group->manipulator;
+
+ RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_GRAB_STYLE_CROSS_2D);
+
+ mpr->scale_basis = 0.05f;
+
+ mgroup->customdata = sbeam_group;
+}
+
+static void WIDGETGROUP_node_sbeam_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct NodeSunBeamsWidgetGroup *sbeam_group = mgroup->customdata;
+ ARegion *ar = CTX_wm_region(C);
+ wmManipulator *mpr = mgroup->manipulators.first;
+
+ SpaceNode *snode = CTX_wm_space_node(C);
+
+ node_manipulator_calc_matrix_space_with_image_dims(snode, ar, sbeam_group->state.dims, mpr->matrix_space);
+}
+
+static void WIDGETGROUP_node_sbeam_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct NodeSunBeamsWidgetGroup *sbeam_group = mgroup->customdata;
+ wmManipulator *mpr = sbeam_group->manipulator;
+
+ void *lock;
+ Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+ if (ibuf) {
+ sbeam_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f;
+ sbeam_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f;
+
+ SpaceNode *snode = CTX_wm_space_node(C);
+ bNode *node = nodeGetActive(snode->edittree);
+
+ /* need to set property here for undo. TODO would prefer to do this in _init */
+ PointerRNA nodeptr;
+ RNA_pointer_create((ID *)snode->edittree, &RNA_CompositorNodeSunBeams, node, &nodeptr);
+ WM_manipulator_target_property_def_rna(mpr, "offset", &nodeptr, "source", -1);
+
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_MODAL, true);
+ }
+ else {
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
+ }
+
+ BKE_image_release_ibuf(ima, ibuf, lock);
+}
+
+void NODE_WGT_backdrop_sun_beams(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Sun Beams Widget";
+ wgt->idname = "NODE_WGT_sbeam";
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT;
+
+ wgt->poll = WIDGETGROUP_node_sbeam_poll;
+ wgt->setup = WIDGETGROUP_node_sbeam_setup;
+ wgt->draw_prepare = WIDGETGROUP_node_sbeam_draw_prepare;
+ wgt->refresh = WIDGETGROUP_node_sbeam_refresh;
+}
+
+/** \} */
+
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Corner Pin
+ * \{ */
+
+struct NodeCornerPinWidgetGroup {
+ wmManipulator *manipulators[4];
+
+ struct {
+ float dims[2];
+ } state;
+};
+
+static bool WIDGETGROUP_node_corner_pin_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ SpaceNode *snode = CTX_wm_space_node(C);
+
+ if ((snode->flag & SNODE_BACKDRAW) == 0) {
+ return false;
+ }
+
+ if (snode && snode->edittree && snode->edittree->type == NTREE_COMPOSIT) {
+ bNode *node = nodeGetActive(snode->edittree);
+
+ if (node && ELEM(node->type, CMP_NODE_CORNERPIN)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static void WIDGETGROUP_node_corner_pin_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ struct NodeCornerPinWidgetGroup *cpin_group = MEM_mallocN(sizeof(struct NodeCornerPinWidgetGroup), __func__);
+ const wmManipulatorType *wt_grab_3d = WM_manipulatortype_find("MANIPULATOR_WT_grab_3d", false);
+
+ for (int i = 0; i < 4; i++) {
+ cpin_group->manipulators[i] = WM_manipulator_new_ptr(wt_grab_3d, mgroup, NULL);
+ wmManipulator *mpr = cpin_group->manipulators[i];
+
+ RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_GRAB_STYLE_CROSS_2D);
+
+ mpr->scale_basis = 0.01f;
+ }
+
+ mgroup->customdata = cpin_group;
+}
+
+static void WIDGETGROUP_node_corner_pin_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct NodeCornerPinWidgetGroup *cpin_group = mgroup->customdata;
+ ARegion *ar = CTX_wm_region(C);
+
+ SpaceNode *snode = CTX_wm_space_node(C);
+
+ float matrix_space[4][4];
+ node_manipulator_calc_matrix_space_with_image_dims(snode, ar, cpin_group->state.dims, matrix_space);
+
+ for (int i = 0; i < 4; i++) {
+ wmManipulator *mpr = cpin_group->manipulators[i];
+ copy_m4_m4(mpr->matrix_space, matrix_space);
+ }
+}
+
+static void WIDGETGROUP_node_corner_pin_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct NodeCornerPinWidgetGroup *cpin_group = mgroup->customdata;
+
+ void *lock;
+ Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+ ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, &lock);
+
+ if (ibuf) {
+ cpin_group->state.dims[0] = (ibuf->x > 0) ? ibuf->x : 64.0f;
+ cpin_group->state.dims[1] = (ibuf->y > 0) ? ibuf->y : 64.0f;
+
+ SpaceNode *snode = CTX_wm_space_node(C);
+ bNode *node = nodeGetActive(snode->edittree);
+
+ /* need to set property here for undo. TODO would prefer to do this in _init */
+ int i = 0;
+ for (bNodeSocket *sock = node->inputs.first; sock && i < 4; sock = sock->next) {
+ if (sock->type == SOCK_VECTOR) {
+ wmManipulator *mpr = cpin_group->manipulators[i++];
+
+ PointerRNA sockptr;
+ RNA_pointer_create((ID *)snode->edittree, &RNA_NodeSocket, sock, &sockptr);
+ WM_manipulator_target_property_def_rna(mpr, "offset", &sockptr, "default_value", -1);
+
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_MODAL, true);
+ }
+ }
+ }
+ else {
+ for (int i = 0; i < 4; i++) {
+ wmManipulator *mpr = cpin_group->manipulators[i];
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
+ }
+ }
+
+ BKE_image_release_ibuf(ima, ibuf, lock);
+}
+
+void NODE_WGT_backdrop_corner_pin(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Corner Pin Widget";
+ wgt->idname = "NODE_WGT_backdrop_corner_pin";
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_PERSISTENT;
+
+ wgt->poll = WIDGETGROUP_node_corner_pin_poll;
+ wgt->setup = WIDGETGROUP_node_corner_pin_setup;
+ wgt->draw_prepare = WIDGETGROUP_node_corner_pin_draw_prepare;
+ wgt->refresh = WIDGETGROUP_node_corner_pin_refresh;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_node/node_ops.c b/source/blender/editors/space_node/node_ops.c
index 5118d52efc4..c9c29212f02 100644
--- a/source/blender/editors/space_node/node_ops.c
+++ b/source/blender/editors/space_node/node_ops.c
@@ -94,8 +94,7 @@ void node_operatortypes(void)
WM_operatortype_append(NODE_OT_insert_offset);
- WM_operatortype_append(NODE_OT_read_renderlayers);
- WM_operatortype_append(NODE_OT_read_fullsamplelayers);
+ WM_operatortype_append(NODE_OT_read_viewlayers);
WM_operatortype_append(NODE_OT_render_changed);
WM_operatortype_append(NODE_OT_backimage_move);
@@ -335,8 +334,7 @@ void node_keymap(struct wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "NODE_OT_group_edit", TABKEY, KM_PRESS, KM_CTRL, 0);
RNA_boolean_set(kmi->ptr, "exit", true);
- WM_keymap_add_item(keymap, "NODE_OT_read_renderlayers", RKEY, KM_PRESS, KM_CTRL, 0);
- WM_keymap_add_item(keymap, "NODE_OT_read_fullsamplelayers", RKEY, KM_PRESS, KM_SHIFT, 0);
+ WM_keymap_add_item(keymap, "NODE_OT_read_viewlayers", RKEY, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "NODE_OT_render_changed", ZKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "NODE_OT_clipboard_copy", CKEY, KM_PRESS, KM_CTRL, 0);
diff --git a/source/blender/editors/space_node/node_templates.c b/source/blender/editors/space_node/node_templates.c
index fcfde6f87bf..5f48b7d7a0f 100644
--- a/source/blender/editors/space_node/node_templates.c
+++ b/source/blender/editors/space_node/node_templates.c
@@ -448,10 +448,7 @@ static void ui_node_menu_column(NodeLinkArg *arg, int nclass, const char *cname)
int compatibility = 0;
if (ntree->type == NTREE_SHADER) {
- if (BKE_scene_use_new_shading_nodes(arg->scene))
- compatibility = NODE_NEW_SHADING;
- else
- compatibility = NODE_OLD_SHADING;
+ compatibility = NODE_NEW_SHADING;
}
/* generate array of node types sorted by UI name */
diff --git a/source/blender/editors/space_node/space_node.c b/source/blender/editors/space_node/space_node.c
index 2267316d257..a5f96ee04d6 100644
--- a/source/blender/editors/space_node/space_node.c
+++ b/source/blender/editors/space_node/space_node.c
@@ -49,14 +49,15 @@
#include "ED_node.h"
#include "ED_render.h"
#include "ED_screen.h"
-#include "WM_api.h"
-#include "WM_types.h"
#include "UI_resources.h"
#include "UI_view2d.h"
#include "RNA_access.h"
+#include "WM_api.h"
+#include "WM_types.h"
+
#include "node_intern.h" /* own include */
@@ -290,7 +291,7 @@ ARegion *node_has_tools_region(ScrArea *sa)
/* ******************** default callbacks for node space ***************** */
-static SpaceLink *node_new(const bContext *UNUSED(C))
+static SpaceLink *node_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceNode *snode;
@@ -381,12 +382,13 @@ static void node_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
}
-static void node_area_listener(bScreen *sc, ScrArea *sa, wmNotifier *wmn)
+static void node_area_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
/* note, ED_area_tag_refresh will re-execute compositor */
SpaceNode *snode = sa->spacedata.first;
/* shaderfrom is only used for new shading nodes, otherwise all shaders are from objects */
- short shader_type = BKE_scene_use_new_shading_nodes(sc->scene) ? snode->shaderfrom : SNODE_SHADER_OBJECT;
+ short shader_type = snode->shaderfrom;
/* preview renders */
switch (wmn->category) {
@@ -643,6 +645,14 @@ static void node_main_region_init(wmWindowManager *wm, ARegion *ar)
UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
+ /* manipulators stay in the background for now - quick patchjob to make sure nodes themselves work */
+ if (ar->manipulator_map == NULL) {
+ ar->manipulator_map = WM_manipulatormap_new_from_type(
+ &(const struct wmManipulatorMapType_Params){SPACE_NODE, RGN_TYPE_WINDOW});
+ }
+
+ WM_manipulatormap_add_handlers(ar, ar->manipulator_map);
+
/* own keymaps */
keymap = WM_keymap_find(wm->defaultconf, "Node Generic", SPACE_NODE, 0);
WM_event_add_keymap_handler(&ar->handlers, keymap);
@@ -737,18 +747,32 @@ static void node_header_region_draw(const bContext *C, ARegion *ar)
}
/* used for header + main region */
-static void node_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void node_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
+ wmManipulatorMap *mmap = ar->manipulator_map;
+
/* context changes */
switch (wmn->category) {
case NC_SPACE:
- if (wmn->data == ND_SPACE_NODE)
- ED_region_tag_redraw(ar);
+ switch (wmn->data) {
+ case ND_SPACE_NODE:
+ ED_region_tag_redraw(ar);
+ break;
+ case ND_SPACE_NODE_VIEW:
+ WM_manipulatormap_tag_refresh(mmap);
+ break;
+ }
break;
case NC_SCREEN:
+ if (wmn->data == ND_LAYOUTSET || wmn->action == NA_EDITED) {
+ WM_manipulatormap_tag_refresh(mmap);
+ }
switch (wmn->data) {
case ND_SCREENCAST:
case ND_ANIMPLAY:
+ case ND_LAYER:
ED_region_tag_redraw(ar);
break;
}
@@ -758,10 +782,20 @@ static void node_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegi
ED_region_tag_redraw(ar);
break;
case NC_SCENE:
+ ED_region_tag_redraw(ar);
+ if (wmn->data == ND_RENDER_RESULT) {
+ WM_manipulatormap_tag_refresh(mmap);
+ }
+ break;
+ case NC_NODE:
+ ED_region_tag_redraw(ar);
+ if (ELEM(wmn->action, NA_EDITED, NA_SELECTED)) {
+ WM_manipulatormap_tag_refresh(mmap);
+ }
+ break;
case NC_MATERIAL:
case NC_TEXTURE:
case NC_WORLD:
- case NC_NODE:
case NC_LINESTYLE:
ED_region_tag_redraw(ar);
break;
@@ -826,6 +860,17 @@ static int node_context(const bContext *C, const char *member, bContextDataResul
return 0;
}
+static void node_widgets(void)
+{
+ /* create the widgetmap for the area here */
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(
+ &(const struct wmManipulatorMapType_Params){SPACE_NODE, RGN_TYPE_WINDOW});
+ WM_manipulatorgrouptype_append_and_link(mmap_type, NODE_WGT_backdrop_transform);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, NODE_WGT_backdrop_crop);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, NODE_WGT_backdrop_sun_beams);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, NODE_WGT_backdrop_corner_pin);
+}
+
static void node_id_remap(ScrArea *UNUSED(sa), SpaceLink *slink, ID *old_id, ID *new_id)
{
SpaceNode *snode = (SpaceNode *)slink;
@@ -916,6 +961,7 @@ void ED_spacetype_node(void)
st->refresh = node_area_refresh;
st->context = node_context;
st->dropboxes = node_dropboxes;
+ st->manipulators = node_widgets;
st->id_remap = node_id_remap;
/* regions: main window */
diff --git a/source/blender/editors/space_outliner/CMakeLists.txt b/source/blender/editors/space_outliner/CMakeLists.txt
index 289d6e715e1..96d27c6fd89 100644
--- a/source/blender/editors/space_outliner/CMakeLists.txt
+++ b/source/blender/editors/space_outliner/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
../../blenkernel
../../blenlib
../../blentranslation
+ ../../depsgraph
../../imbuf
../../gpu
../../makesdna
@@ -37,12 +38,14 @@ set(INC_SYS
)
set(SRC
+ outliner_collections.c
outliner_draw.c
outliner_edit.c
outliner_ops.c
outliner_select.c
outliner_tools.c
outliner_tree.c
+ outliner_utils.c
space_outliner.c
outliner_intern.h
diff --git a/source/blender/editors/space_outliner/outliner_collections.c b/source/blender/editors/space_outliner/outliner_collections.c
new file mode 100644
index 00000000000..fd2b463f91b
--- /dev/null
+++ b/source/blender/editors/space_outliner/outliner_collections.c
@@ -0,0 +1,1043 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation, Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_outliner/outliner_collections.c
+ * \ingroup spoutliner
+ */
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+
+#include "BKE_context.h"
+#include "BKE_collection.h"
+#include "BKE_layer.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
+#include "DNA_group_types.h"
+#include "DNA_object_types.h"
+
+#include "ED_screen.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "UI_resources.h"
+
+#include "outliner_intern.h" /* own include */
+
+/* Prototypes. */
+static int collection_delete_exec(struct bContext *C, struct wmOperator *op);
+
+/* -------------------------------------------------------------------- */
+
+static LayerCollection *outliner_collection_active(bContext *C)
+{
+ return CTX_data_layer_collection(C);
+}
+
+SceneCollection *outliner_scene_collection_from_tree_element(TreeElement *te)
+{
+ TreeStoreElem *tselem = TREESTORE(te);
+
+ if (tselem->type == TSE_SCENE_COLLECTION) {
+ return te->directdata;
+ }
+ else if (tselem->type == TSE_LAYER_COLLECTION) {
+ LayerCollection *lc = te->directdata;
+ return lc->scene_collection;
+ }
+
+ return NULL;
+}
+
+/* -------------------------------------------------------------------- */
+/* Poll functions. */
+
+static int collections_editor_poll(bContext *C)
+{
+ SpaceOops *so = CTX_wm_space_outliner(C);
+ return (so != NULL) && (so->outlinevis == SO_COLLECTIONS);
+}
+
+
+static int outliner_objects_collection_poll(bContext *C)
+{
+ SpaceOops *so = CTX_wm_space_outliner(C);
+ if (so == NULL) {
+ return 0;
+ }
+
+ /* Groups don't support filtering. */
+ if ((so->outlinevis != SO_GROUPS) &&
+ ((so->filter & (SO_FILTER_ENABLE | SO_FILTER_NO_COLLECTION)) ==
+ (SO_FILTER_ENABLE | SO_FILTER_NO_COLLECTION)))
+ {
+ return 0;
+ }
+
+ return ELEM(so->outlinevis, SO_COLLECTIONS, SO_GROUPS);
+}
+
+/* -------------------------------------------------------------------- */
+/* collection manager operators */
+
+/**
+ * Recursively get the collection for a given index
+ */
+static SceneCollection *scene_collection_from_index(ListBase *lb, const int number, int *i)
+{
+ for (SceneCollection *sc = lb->first; sc; sc = sc->next) {
+ if (*i == number) {
+ return sc;
+ }
+
+ (*i)++;
+
+ SceneCollection *sc_nested = scene_collection_from_index(&sc->scene_collections, number, i);
+ if (sc_nested) {
+ return sc_nested;
+ }
+ }
+ return NULL;
+}
+
+typedef struct TreeElementFindData {
+ SceneCollection *collection;
+ TreeElement *r_result_te;
+} TreeElementFindData;
+
+static TreeTraversalAction tree_element_find_by_scene_collection_cb(TreeElement *te, void *customdata)
+{
+ TreeElementFindData *data = customdata;
+ const SceneCollection *current_element_sc = outliner_scene_collection_from_tree_element(te);
+
+ if (current_element_sc == data->collection) {
+ data->r_result_te = te;
+ return TRAVERSE_BREAK;
+ }
+
+ return TRAVERSE_CONTINUE;
+}
+
+static TreeElement *outliner_tree_element_from_layer_collection_index(
+ SpaceOops *soops, ViewLayer *view_layer,
+ const int index)
+{
+ LayerCollection *lc = BKE_layer_collection_from_index(view_layer, index);
+
+ if (lc == NULL) {
+ return NULL;
+ }
+
+ /* Find the tree element containing the LayerCollection's scene_collection. */
+ TreeElementFindData data = {
+ .collection = lc->scene_collection,
+ .r_result_te = NULL,
+ };
+ outliner_tree_traverse(soops, &soops->tree, 0, 0, tree_element_find_by_scene_collection_cb, &data);
+
+ return data.r_result_te;
+}
+
+static int collection_link_exec(bContext *C, wmOperator *op)
+{
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ SceneCollection *sc_master = BKE_collection_master(&scene->id);
+ SceneCollection *sc;
+
+ int scene_collection_index = RNA_enum_get(op->ptr, "scene_collection");
+ if (scene_collection_index == 0) {
+ sc = sc_master;
+ }
+ else {
+ int index = 1;
+ sc = scene_collection_from_index(&sc_master->scene_collections, scene_collection_index, &index);
+ BLI_assert(sc);
+ }
+
+ BKE_collection_link(view_layer, sc);
+
+ DEG_relations_tag_update(CTX_data_main(C));
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ return OPERATOR_FINISHED;
+}
+
+static int collection_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ Scene *scene = CTX_data_scene(C);
+ SceneCollection *master_collection = BKE_collection_master(&scene->id);
+ if (master_collection->scene_collections.first == NULL) {
+ RNA_enum_set(op->ptr, "scene_collection", 0);
+ return collection_link_exec(C, op);
+ }
+ else {
+ return WM_enum_search_invoke(C, op, event);
+ }
+}
+
+static void collection_scene_collection_itemf_recursive(
+ EnumPropertyItem *tmp, EnumPropertyItem **item, int *totitem, int *value, SceneCollection *sc)
+{
+ tmp->value = *value;
+ tmp->icon = ICON_COLLAPSEMENU;
+ tmp->identifier = sc->name;
+ tmp->name = sc->name;
+ RNA_enum_item_add(item, totitem, tmp);
+
+ (*value)++;
+
+ for (SceneCollection *ncs = sc->scene_collections.first; ncs; ncs = ncs->next) {
+ collection_scene_collection_itemf_recursive(tmp, item, totitem, value, ncs);
+ }
+}
+
+static const EnumPropertyItem *collection_scene_collection_itemf(
+ bContext *C, PointerRNA *UNUSED(ptr), PropertyRNA *UNUSED(prop), bool *r_free)
+{
+ EnumPropertyItem tmp = {0, "", 0, "", ""};
+ EnumPropertyItem *item = NULL;
+ int value = 0, totitem = 0;
+
+ Scene *scene = CTX_data_scene(C);
+ SceneCollection *sc = BKE_collection_master(&scene->id);
+
+ collection_scene_collection_itemf_recursive(&tmp, &item, &totitem, &value, sc);
+ RNA_enum_item_end(&item, &totitem);
+ *r_free = true;
+
+ return item;
+}
+
+void OUTLINER_OT_collection_link(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Link Collection";
+ ot->idname = "OUTLINER_OT_collection_link";
+ ot->description = "Link a new collection to the active layer";
+
+ /* api callbacks */
+ ot->exec = collection_link_exec;
+ ot->invoke = collection_link_invoke;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ prop = RNA_def_enum(ot->srna, "scene_collection", DummyRNA_NULL_items, 0, "Scene Collection", "");
+ RNA_def_enum_funcs(prop, collection_scene_collection_itemf);
+ RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE);
+ ot->prop = prop;
+}
+
+/**
+ * Returns true if selected element is a collection directly
+ * linked to the active ViewLayer (not a nested collection)
+ */
+static int collection_unlink_poll(bContext *C)
+{
+ if (collections_editor_poll(C) == 0) {
+ return 0;
+ }
+
+ LayerCollection *lc = outliner_collection_active(C);
+
+ if (lc == NULL) {
+ return 0;
+ }
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ return BLI_findindex(&view_layer->layer_collections, lc) != -1 ? 1 : 0;
+}
+
+static int collection_unlink_exec(bContext *C, wmOperator *op)
+{
+ LayerCollection *lc = outliner_collection_active(C);
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+
+ if (lc == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Active element is not a collection");
+ return OPERATOR_CANCELLED;
+ }
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ BKE_collection_unlink(view_layer, lc);
+
+ if (soops) {
+ outliner_cleanup_tree(soops);
+ }
+
+ DEG_relations_tag_update(CTX_data_main(C));
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&CTX_data_scene(C)->id, 0);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_unlink(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Unlink Collection";
+ ot->idname = "OUTLINER_OT_collection_unlink";
+ ot->description = "Unlink collection from the active layer";
+
+ /* api callbacks */
+ ot->exec = collection_unlink_exec;
+ ot->poll = collection_unlink_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/**********************************************************************************/
+/* Add new collection. */
+
+static int collection_new_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ SceneCollection *scene_collection_parent = BKE_collection_master(&scene->id);
+ SceneCollection *scene_collection = BKE_collection_add(&scene->id, scene_collection_parent, COLLECTION_TYPE_NONE, NULL);
+ BKE_collection_link(view_layer, scene_collection);
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_new(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "New Collection";
+ ot->idname = "OUTLINER_OT_collection_new";
+ ot->description = "Add a new collection to the scene";
+
+ /* api callbacks */
+ ot->exec = collection_new_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/**********************************************************************************/
+/* Add new nested collection. */
+
+struct CollectionNewData
+{
+ bool error;
+ SceneCollection *scene_collection;
+};
+
+static TreeTraversalAction collection_find_selected_to_add(TreeElement *te, void *customdata)
+{
+ struct CollectionNewData *data = customdata;
+ SceneCollection *scene_collection = outliner_scene_collection_from_tree_element(te);
+
+ if (!scene_collection) {
+ return TRAVERSE_SKIP_CHILDS;
+ }
+
+ if (data->scene_collection != NULL) {
+ data->error = true;
+ return TRAVERSE_BREAK;
+ }
+
+ data->scene_collection = scene_collection;
+ return TRAVERSE_CONTINUE;
+}
+
+static int collection_nested_new_exec(bContext *C, wmOperator *op)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+
+ struct CollectionNewData data = {
+ .error = false,
+ .scene_collection = NULL,
+ };
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_selected_to_add, &data);
+
+ if (data.error) {
+ BKE_report(op->reports, RPT_ERROR, "More than one collection is selected");
+ return OPERATOR_CANCELLED;
+ }
+
+ BKE_collection_add(
+ &scene->id,
+ data.scene_collection,
+ COLLECTION_TYPE_NONE,
+ NULL);
+
+ outliner_cleanup_tree(soops);
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_nested_new(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "New Nested Collection";
+ ot->idname = "OUTLINER_OT_collection_nested_new";
+ ot->description = "Add a new collection inside selected collection";
+
+ /* api callbacks */
+ ot->exec = collection_nested_new_exec;
+ ot->poll = collections_editor_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/**********************************************************************************/
+/* Delete selected collection. */
+
+void OUTLINER_OT_collection_delete_selected(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Delete Selected Collections";
+ ot->idname = "OUTLINER_OT_collection_delete_selected";
+ ot->description = "Delete all the selected collections";
+
+ /* api callbacks */
+ ot->exec = collection_delete_exec;
+ ot->poll = collections_editor_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/**********************************************************************************/
+/* Add new selected objects. */
+
+struct SceneCollectionSelectedData {
+ ListBase scene_collections_array;
+};
+
+static TreeTraversalAction collection_find_selected_scene_collections(TreeElement *te, void *customdata)
+{
+ struct SceneCollectionSelectedData *data = customdata;
+ SceneCollection *scene_collection = outliner_scene_collection_from_tree_element(te);
+
+ if (!scene_collection) {
+ return TRAVERSE_SKIP_CHILDS;
+ }
+
+ BLI_addtail(&data->scene_collections_array, BLI_genericNodeN(scene_collection));
+ return TRAVERSE_CONTINUE;
+}
+
+static int collection_objects_add_exec(bContext *C, wmOperator *op)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+
+ struct SceneCollectionSelectedData data = {
+ .scene_collections_array = {NULL, NULL},
+ };
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_selected_scene_collections, &data);
+
+ if (BLI_listbase_is_empty(&data.scene_collections_array)) {
+ BKE_report(op->reports, RPT_ERROR, "No collection is selected");
+ return OPERATOR_CANCELLED;
+ }
+
+ CTX_DATA_BEGIN (C, struct Object *, ob, selected_objects)
+ {
+ LISTBASE_FOREACH (LinkData *, link, &data.scene_collections_array) {
+ SceneCollection *scene_collection = link->data;
+ BKE_collection_object_add(
+ &scene->id,
+ scene_collection,
+ ob);
+ }
+ }
+ CTX_DATA_END;
+ BLI_freelistN(&data.scene_collections_array);
+
+ outliner_cleanup_tree(soops);
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_objects_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add Objects";
+ ot->idname = "OUTLINER_OT_collection_objects_add";
+ ot->description = "Add selected objects to collection";
+
+ /* api callbacks */
+ ot->exec = collection_objects_add_exec;
+ ot->poll = collections_editor_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+/**********************************************************************************/
+/* Remove selected objects. */
+
+
+static int collection_objects_remove_exec(bContext *C, wmOperator *op)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+
+ struct SceneCollectionSelectedData data = {
+ .scene_collections_array = {NULL, NULL},
+ };
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_selected_scene_collections, &data);
+
+ if (BLI_listbase_is_empty(&data.scene_collections_array)) {
+ BKE_report(op->reports, RPT_ERROR, "No collection is selected");
+ return OPERATOR_CANCELLED;
+ }
+
+ CTX_DATA_BEGIN (C, struct Object *, ob, selected_objects)
+ {
+ LISTBASE_FOREACH (LinkData *, link, &data.scene_collections_array) {
+ SceneCollection *scene_collection = link->data;
+ BKE_collection_object_remove(
+ bmain,
+ &scene->id,
+ scene_collection,
+ ob,
+ true);
+ }
+ }
+ CTX_DATA_END;
+ BLI_freelistN(&data.scene_collections_array);
+
+ outliner_cleanup_tree(soops);
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_objects_remove(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Remove Objects";
+ ot->idname = "OUTLINER_OT_collection_objects_remove";
+ ot->description = "Remove selected objects from collection";
+
+ /* api callbacks */
+ ot->exec = collection_objects_remove_exec;
+ ot->poll = collections_editor_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static TreeElement *outliner_collection_parent_element_get(TreeElement *te)
+{
+ TreeElement *te_parent = te;
+ while ((te_parent = te_parent->parent)) {
+ if (outliner_scene_collection_from_tree_element(te->parent)) {
+ return te_parent;
+ }
+ }
+ return NULL;
+}
+
+static int object_collection_remove_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ Main *bmain = CTX_data_main(C);
+
+ struct ObjectsSelectedData data = {
+ .objects_selected_array = {NULL, NULL},
+ };
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, outliner_find_selected_objects, &data);
+
+ LISTBASE_FOREACH (LinkData *, link, &data.objects_selected_array) {
+ TreeElement *te = (TreeElement *)link->data;
+ Object *ob = (Object *)TREESTORE(te)->id;
+ SceneCollection *scene_collection = NULL;
+
+ TreeElement *te_parent = outliner_collection_parent_element_get(te);
+ if (te_parent != NULL) {
+ scene_collection = outliner_scene_collection_from_tree_element(te_parent);
+ ID *owner_id = TREESTORE(te_parent)->id;
+ BKE_collection_object_remove(bmain, owner_id, scene_collection, ob, true);
+ DEG_id_tag_update(owner_id, DEG_TAG_BASE_FLAGS_UPDATE);
+ }
+ }
+
+ BLI_freelistN(&data.objects_selected_array);
+
+ outliner_cleanup_tree(soops);
+ DEG_relations_tag_update(bmain);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, NULL);
+ WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_object_remove_from_collection(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Remove Object from Collection";
+ ot->idname = "OUTLINER_OT_object_remove_from_collection";
+ ot->description = "Remove selected objects from their respective collection";
+
+ /* api callbacks */
+ ot->exec = object_collection_remove_exec;
+ ot->poll = outliner_objects_collection_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int object_add_to_new_collection_exec(bContext *C, wmOperator *op)
+{
+ int operator_result = OPERATOR_CANCELLED;
+
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ Main *bmain = CTX_data_main(C);
+
+ SceneCollection *scene_collection_parent, *scene_collection_new;
+ TreeElement *te_active, *te_parent;
+
+ struct ObjectsSelectedData data = {{NULL}}, active = {{NULL}};
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_HIGHLIGHTED, outliner_find_selected_objects, &active);
+ if (BLI_listbase_is_empty(&active.objects_selected_array)) {
+ BKE_report(op->reports, RPT_ERROR, "No object is selected");
+ goto cleanup;
+ }
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, outliner_find_selected_objects, &data);
+ if (BLI_listbase_is_empty(&data.objects_selected_array)) {
+ BKE_report(op->reports, RPT_ERROR, "No objects are selected");
+ goto cleanup;
+ }
+
+ /* Heuristic to get the "active" / "last object" */
+ te_active = ((LinkData *)active.objects_selected_array.first)->data;
+ te_parent = outliner_collection_parent_element_get(te_active);
+
+ if (te_parent == NULL) {
+ BKE_reportf(op->reports, RPT_ERROR, "Couldn't find collection of \"%s\" object", te_active->name);
+ goto cleanup;
+ }
+
+ ID *owner_id = TREESTORE(te_parent)->id;
+ scene_collection_parent = outliner_scene_collection_from_tree_element(te_parent);
+ scene_collection_new = BKE_collection_add(owner_id, scene_collection_parent, scene_collection_parent->type, NULL);
+
+ LISTBASE_FOREACH (LinkData *, link, &data.objects_selected_array) {
+ TreeElement *te = (TreeElement *)link->data;
+ Object *ob = (Object *)TREESTORE(te)->id;
+ BKE_collection_object_add(owner_id, scene_collection_new, ob);
+ }
+
+ outliner_cleanup_tree(soops);
+ DEG_relations_tag_update(bmain);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ operator_result = OPERATOR_FINISHED;
+cleanup:
+ BLI_freelistN(&active.objects_selected_array);
+ BLI_freelistN(&data.objects_selected_array);
+ return operator_result;
+}
+
+void OUTLINER_OT_object_add_to_new_collection(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Add Objects to New Collection";
+ ot->idname = "OUTLINER_OT_object_add_to_new_collection";
+ ot->description = "Add objects to a new collection";
+
+ /* api callbacks */
+ ot->exec = object_add_to_new_collection_exec;
+ ot->poll = outliner_objects_collection_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+struct CollectionDeleteData {
+ Scene *scene;
+ SpaceOops *soops;
+ GSet *collections_to_delete;
+};
+
+static TreeTraversalAction collection_find_data_to_delete(TreeElement *te, void *customdata)
+{
+ struct CollectionDeleteData *data = customdata;
+ SceneCollection *scene_collection = outliner_scene_collection_from_tree_element(te);
+
+ if (!scene_collection) {
+ return TRAVERSE_SKIP_CHILDS;
+ }
+
+ if (scene_collection == BKE_collection_master(&data->scene->id)) {
+ /* skip - showing warning/error message might be missleading
+ * when deleting multiple collections, so just do nothing */
+ }
+ else {
+ BLI_gset_add(data->collections_to_delete, scene_collection);
+ return TRAVERSE_SKIP_CHILDS; /* Childs will be gone anyway, no need to recurse deeper. */
+ }
+
+ return TRAVERSE_CONTINUE;
+}
+
+static TreeTraversalAction collection_delete_elements_from_collection(TreeElement *te, void *customdata)
+{
+ struct CollectionDeleteData *data = customdata;
+ SceneCollection *scene_collection = outliner_scene_collection_from_tree_element(te);
+
+ if (!scene_collection) {
+ return TRAVERSE_SKIP_CHILDS;
+ }
+
+ const bool will_be_deleted = BLI_gset_haskey(data->collections_to_delete, scene_collection);
+ if (will_be_deleted) {
+ outliner_free_tree_element(te, te->parent ? &te->parent->subtree : &data->soops->tree);
+ /* Childs are freed now, so don't recurse into them. */
+ return TRAVERSE_SKIP_CHILDS;
+ }
+
+ return TRAVERSE_CONTINUE;
+}
+
+static int collection_delete_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ Scene *scene = CTX_data_scene(C);
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ struct CollectionDeleteData data = {.scene = scene, .soops = soops};
+
+ data.collections_to_delete = BLI_gset_ptr_new(__func__);
+
+ /* We first walk over and find the SceneCollections we actually want to delete (ignoring duplicates). */
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, collection_find_data_to_delete, &data);
+
+ /* Now, delete all tree elements representing a collection that will be deleted. We'll look for a
+ * new element to select in a few lines, so we can't wait until the tree is recreated on redraw. */
+ outliner_tree_traverse(soops, &soops->tree, 0, 0, collection_delete_elements_from_collection, &data);
+
+ /* Effectively delete the collections. */
+ GSetIterator collections_to_delete_iter;
+ GSET_ITER(collections_to_delete_iter, data.collections_to_delete) {
+ SceneCollection *sc = BLI_gsetIterator_getKey(&collections_to_delete_iter);
+ BKE_collection_remove(&data.scene->id, sc);
+ }
+
+ BLI_gset_free(data.collections_to_delete, NULL);
+
+ TreeElement *select_te = outliner_tree_element_from_layer_collection_index(soops, CTX_data_view_layer(C), 0);
+ if (select_te) {
+ outliner_item_select(soops, select_te, false, false);
+ }
+
+ DEG_relations_tag_update(CTX_data_main(C));
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+
+ soops->storeflag |= SO_TREESTORE_REDRAW;
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collections_delete(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Delete";
+ ot->idname = "OUTLINER_OT_collections_delete";
+ ot->description = "Delete selected overrides or collections";
+
+ /* api callbacks */
+ ot->exec = collection_delete_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+static int collection_select_exec(bContext *C, wmOperator *op)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ const int collection_index = RNA_int_get(op->ptr, "collection_index");
+ view_layer->active_collection = collection_index;
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_select(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select";
+ ot->idname = "OUTLINER_OT_collection_select";
+ ot->description = "Change active collection or override";
+
+ /* api callbacks */
+ ot->exec = collection_select_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ RNA_def_int(ot->srna, "collection_index", 0, 0, INT_MAX, "Index",
+ "Index of collection to select", 0, INT_MAX);
+}
+
+#define ACTION_DISABLE 0
+#define ACTION_ENABLE 1
+#define ACTION_TOGGLE 2
+
+static int collection_toggle_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ int action = RNA_enum_get(op->ptr, "action");
+ LayerCollection *layer_collection = CTX_data_layer_collection(C);
+
+ if (layer_collection->flag & COLLECTION_DISABLED) {
+ if (ELEM(action, ACTION_TOGGLE, ACTION_ENABLE)) {
+ layer_collection->flag &= ~COLLECTION_DISABLED;
+ }
+ else { /* ACTION_DISABLE */
+ BKE_reportf(op->reports, RPT_ERROR, "Layer collection %s already disabled",
+ layer_collection->scene_collection->name);
+ return OPERATOR_CANCELLED;
+ }
+ }
+ else {
+ if (ELEM(action, ACTION_TOGGLE, ACTION_DISABLE)) {
+ layer_collection->flag |= COLLECTION_DISABLED;
+ }
+ else { /* ACTION_ENABLE */
+ BKE_reportf(op->reports, RPT_ERROR, "Layer collection %s already enabled",
+ layer_collection->scene_collection->name);
+ return OPERATOR_CANCELLED;
+ }
+ }
+
+ DEG_relations_tag_update(bmain);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, scene);
+
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_toggle(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ static EnumPropertyItem actions_items[] = {
+ {ACTION_DISABLE, "DISABLE", 0, "Disable", "Disable selected markers"},
+ {ACTION_ENABLE, "ENABLE", 0, "Enable", "Enable selected markers"},
+ {ACTION_TOGGLE, "TOGGLE", 0, "Toggle", "Toggle disabled flag for selected markers"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ /* identifiers */
+ ot->name = "Toggle Collection";
+ ot->idname = "OUTLINER_OT_collection_toggle";
+ ot->description = "Deselect collection objects";
+
+ /* api callbacks */
+ ot->exec = collection_toggle_exec;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+
+ /* properties */
+ prop = RNA_def_int(ot->srna, "collection_index", -1, -1, INT_MAX, "Collection Index", "Index of collection to toggle", 0, INT_MAX);
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+ prop = RNA_def_enum(ot->srna, "action", actions_items, ACTION_TOGGLE, "Action", "Selection action to execute");
+ RNA_def_property_flag(prop, PROP_SKIP_SAVE);
+}
+
+#undef ACTION_TOGGLE
+#undef ACTION_ENABLE
+#undef ACTION_DISABLE
+
+struct CollectionObjectsSelectData {
+ bool error;
+ LayerCollection *layer_collection;
+};
+
+static TreeTraversalAction outliner_find_first_selected_layer_collection(TreeElement *te, void *customdata)
+{
+ struct CollectionObjectsSelectData *data = customdata;
+ TreeStoreElem *tselem = TREESTORE(te);
+
+ switch (tselem->type) {
+ case TSE_LAYER_COLLECTION:
+ data->layer_collection = te->directdata;
+ return TRAVERSE_BREAK;
+ case TSE_LAYER_COLLECTION_BASE:
+ return TRAVERSE_CONTINUE;
+ default:
+ return TRAVERSE_SKIP_CHILDS;
+ }
+}
+
+static LayerCollection *outliner_active_layer_collection(bContext *C)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+
+ struct CollectionObjectsSelectData data = {
+ .layer_collection = NULL,
+ };
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, outliner_find_first_selected_layer_collection, &data);
+ return data.layer_collection;
+}
+
+static int collection_objects_select_exec(bContext *C, wmOperator *UNUSED(op))
+{
+ LayerCollection *layer_collection = outliner_active_layer_collection(C);
+
+ if (layer_collection == NULL) {
+ return OPERATOR_CANCELLED;
+ }
+
+ BKE_layer_collection_objects_select(layer_collection);
+ WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_objects_select(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Select Objects";
+ ot->idname = "OUTLINER_OT_collection_objects_select";
+ ot->description = "Select all the collection objects";
+
+ /* api callbacks */
+ ot->exec = collection_objects_select_exec;
+ ot->poll = collections_editor_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
+
+struct CollectionDuplicateData {
+ TreeElement *te;
+};
+
+static TreeTraversalAction outliner_find_first_selected_collection(TreeElement *te, void *customdata)
+{
+ struct CollectionDuplicateData *data = customdata;
+ TreeStoreElem *tselem = TREESTORE(te);
+
+ switch (tselem->type) {
+ case TSE_LAYER_COLLECTION:
+ case TSE_SCENE_COLLECTION:
+ data->te = te;
+ return TRAVERSE_BREAK;
+ case TSE_LAYER_COLLECTION_BASE:
+ default:
+ return TRAVERSE_CONTINUE;
+ }
+}
+
+static TreeElement *outliner_active_collection(bContext *C)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+
+ struct CollectionDuplicateData data = {
+ .te = NULL,
+ };
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, outliner_find_first_selected_collection, &data);
+ return data.te;
+}
+
+static int collection_duplicate_exec(bContext *C, wmOperator *op)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ TreeElement *te = outliner_active_collection(C);
+
+ BLI_assert(te != NULL);
+ if (BKE_collection_master(TREESTORE(te)->id) == outliner_scene_collection_from_tree_element(te)) {
+ BKE_report(op->reports, RPT_ERROR, "You can't duplicate the master collection");
+ return OPERATOR_CANCELLED;
+ }
+
+ switch (soops->outlinevis) {
+ case SO_SCENES:
+ BKE_collection_duplicate(TREESTORE(te)->id, (SceneCollection *)te->directdata);
+ break;
+ case SO_COLLECTIONS:
+ case SO_GROUPS:
+ BKE_layer_collection_duplicate(TREESTORE(te)->id, (LayerCollection *)te->directdata);
+ break;
+ }
+
+ DEG_relations_tag_update(CTX_data_main(C));
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, CTX_data_scene(C));
+
+ return OPERATOR_FINISHED;
+}
+
+void OUTLINER_OT_collection_duplicate(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Duplicate Collection";
+ ot->idname = "OUTLINER_OT_collection_duplicate";
+ ot->description = "Duplicate collection";
+
+ /* api callbacks */
+ ot->exec = collection_duplicate_exec;
+ ot->poll = collections_editor_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
+}
diff --git a/source/blender/editors/space_outliner/outliner_draw.c b/source/blender/editors/space_outliner/outliner_draw.c
index d8d6b09ac6b..25e40ccf6e5 100644
--- a/source/blender/editors/space_outliner/outliner_draw.c
+++ b/source/blender/editors/space_outliner/outliner_draw.c
@@ -48,9 +48,9 @@
#include "BKE_context.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
@@ -58,6 +58,9 @@
#include "BKE_scene.h"
#include "BKE_object.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_armature.h"
#include "ED_keyframing.h"
#include "ED_object.h"
@@ -66,8 +69,7 @@
#include "WM_api.h"
#include "WM_types.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_immediate.h"
#include "UI_interface.h"
#include "UI_interface_icons.h"
@@ -172,116 +174,6 @@ static void restrictbutton_recursive_bone(Bone *bone_parent, int flag, bool set_
}
-static void restrictbutton_recursive_child(bContext *C, Scene *scene, Object *ob_parent, char flag,
- bool state, bool deselect, const char *rnapropname)
-{
- Main *bmain = CTX_data_main(C);
- Object *ob;
-
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- if (BKE_object_is_child_recursive(ob_parent, ob)) {
- /* only do if child object is selectable */
- if ((flag == OB_RESTRICT_SELECT) || (ob->restrictflag & OB_RESTRICT_SELECT) == 0) {
- if (state) {
- ob->restrictflag |= flag;
- if (deselect) {
- ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
- }
- }
- else {
- ob->restrictflag &= ~flag;
- }
- }
-
- if (rnapropname) {
- PointerRNA ptr;
- PropertyRNA *prop;
- ID *id;
- bAction *action;
- FCurve *fcu;
- bool driven, special;
-
- RNA_id_pointer_create(&ob->id, &ptr);
- prop = RNA_struct_find_property(&ptr, rnapropname);
- fcu = rna_get_fcurve_context_ui(C, &ptr, prop, 0, NULL, &action, &driven, &special);
-
- if (fcu && !driven) {
- id = ptr.id.data;
- if (autokeyframe_cfra_can_key(scene, id)) {
- ReportList *reports = CTX_wm_reports(C);
- ToolSettings *ts = scene->toolsettings;
- eInsertKeyFlags key_flag = ANIM_get_keyframing_flags(scene, 1);
-
- fcu->flag &= ~FCURVE_SELECTED;
- insert_keyframe(reports, id, action, ((fcu->grp) ? (fcu->grp->name) : (NULL)),
- fcu->rna_path, fcu->array_index, CFRA, ts->keyframe_type, key_flag);
- /* Assuming this is not necessary here, since 'ancestor' object button will do it anyway. */
- /* WM_event_add_notifier(C, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, NULL); */
- }
- }
- }
- }
- }
-}
-
-static void restrictbutton_view_cb(bContext *C, void *poin, void *poin2)
-{
- Scene *scene = (Scene *)poin;
- Object *ob = (Object *)poin2;
-
- if (!common_restrict_check(C, ob)) return;
-
- /* deselect objects that are invisible */
- if (ob->restrictflag & OB_RESTRICT_VIEW) {
- /* Ouch! There is no backwards pointer from Object to Base,
- * so have to do loop to find it. */
- ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
- }
-
- if (CTX_wm_window(C)->eventstate->ctrl) {
- restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_VIEW,
- (ob->restrictflag & OB_RESTRICT_VIEW) != 0, true, "hide");
- }
-
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-
-}
-
-static void restrictbutton_sel_cb(bContext *C, void *poin, void *poin2)
-{
- Scene *scene = (Scene *)poin;
- Object *ob = (Object *)poin2;
-
- if (!common_restrict_check(C, ob)) return;
-
- /* if select restriction has just been turned on */
- if (ob->restrictflag & OB_RESTRICT_SELECT) {
- /* Ouch! There is no backwards pointer from Object to Base,
- * so have to do loop to find it. */
- ED_base_object_select(BKE_scene_base_find(scene, ob), BA_DESELECT);
- }
-
- if (CTX_wm_window(C)->eventstate->ctrl) {
- restrictbutton_recursive_child(C, scene, ob, OB_RESTRICT_SELECT,
- (ob->restrictflag & OB_RESTRICT_SELECT) != 0, true, NULL);
- }
-
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
-
-}
-
-static void restrictbutton_rend_cb(bContext *C, void *poin, void *poin2)
-{
- Object *ob = (Object *)poin2;
-
- if (CTX_wm_window(C)->eventstate->ctrl) {
- restrictbutton_recursive_child(C, (Scene *)poin, ob, OB_RESTRICT_RENDER,
- (ob->restrictflag & OB_RESTRICT_RENDER) != 0, false, "hide_render");
- }
-
- WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, poin);
-}
-
static void restrictbutton_r_lay_cb(bContext *C, void *poin, void *UNUSED(poin2))
{
WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, poin);
@@ -291,7 +183,7 @@ static void restrictbutton_modifier_cb(bContext *C, void *UNUSED(poin), void *po
{
Object *ob = (Object *)poin2;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
}
@@ -355,96 +247,17 @@ static void restrictbutton_gp_layer_flag_cb(bContext *C, void *UNUSED(poin), voi
WM_event_add_notifier(C, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
}
-static int group_restrict_flag(Group *gr, int flag)
+static void restrictbutton_collection_flag_cb(bContext *C, void *poin, void *UNUSED(poin2))
{
- GroupObject *gob;
-
-#ifdef USE_GROUP_SELECT
- for (gob = gr->gobject.first; gob; gob = gob->next) {
- if ((gob->ob->restrictflag & flag) == 0)
- return 0;
- }
- return 1;
-#else
- /* weak but fast */
- if ((gob = gr->gobject.first))
- if ((gob->ob->restrictflag & flag) == 0)
- return 0;
- return 1;
-#endif
-}
-
-static int group_select_flag(Group *gr)
-{
- GroupObject *gob;
-
-#ifdef USE_GROUP_SELECT
- for (gob = gr->gobject.first; gob; gob = gob->next)
- if ((gob->ob->flag & SELECT))
- return 1;
-
- return 0;
-#else
- /* weak but fast */
- if ((gob = gr->gobject.first))
- if (gob->ob->flag & SELECT)
- return 1;
- return 0;
-#endif
-}
-
-void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag)
-{
- Scene *scene = (Scene *)poin;
- GroupObject *gob;
- Group *gr = (Group *)poin2;
-
- if (group_restrict_flag(gr, flag)) {
- for (gob = gr->gobject.first; gob; gob = gob->next) {
- if (ID_IS_LINKED(gob->ob))
- continue;
-
- gob->ob->restrictflag &= ~flag;
-
- if (flag == OB_RESTRICT_VIEW)
- if (gob->ob->flag & SELECT)
- ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
- }
- }
- else {
- for (gob = gr->gobject.first; gob; gob = gob->next) {
- if (ID_IS_LINKED(gob->ob))
- continue;
+ ID *id = (ID *)poin;
- /* not in editmode */
- if (scene->obedit != gob->ob) {
- gob->ob->restrictflag |= flag;
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
- if (ELEM(flag, OB_RESTRICT_SELECT, OB_RESTRICT_VIEW)) {
- if ((gob->ob->flag & SELECT)) {
- ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_DESELECT);
- }
- }
- }
- }
+ if (GS(id->name) == ID_SCE) {
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, id);
}
-}
-
-static void restrictbutton_gr_restrict_view(bContext *C, void *poin, void *poin2)
-{
- restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_VIEW);
- WM_event_add_notifier(C, NC_GROUP, NULL);
- DAG_id_type_tag(CTX_data_main(C), ID_OB);
-}
-static void restrictbutton_gr_restrict_select(bContext *C, void *poin, void *poin2)
-{
- restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_SELECT);
- WM_event_add_notifier(C, NC_GROUP, NULL);
-}
-static void restrictbutton_gr_restrict_render(bContext *C, void *poin, void *poin2)
-{
- restrictbutton_gr_restrict_flag(poin, poin2, OB_RESTRICT_RENDER);
- WM_event_add_notifier(C, NC_GROUP, NULL);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER_CONTENT, NULL);
}
static void restrictbutton_id_user_toggle(bContext *UNUSED(C), void *poin, void *UNUSED(poin2))
@@ -466,6 +279,7 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
{
SpaceOops *soops = CTX_wm_space_outliner(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
BLI_mempool *ts = soops->treestore;
TreeStoreElem *tselem = tsep;
@@ -527,7 +341,7 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
BLI_strncpy(newname, ebone->name, sizeof(ebone->name));
BLI_strncpy(ebone->name, oldname, sizeof(ebone->name));
ED_armature_bone_rename(obedit->data, oldname, newname);
- WM_event_add_notifier(C, NC_OBJECT | ND_POSE, OBACT);
+ WM_event_add_notifier(C, NC_OBJECT | ND_POSE, OBACT(view_layer));
}
break;
}
@@ -539,8 +353,8 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
char newname[sizeof(bone->name)];
/* always make current object active */
- tree_element_active(C, scene, soops, te, OL_SETSEL_NORMAL, true);
- ob = OBACT;
+ tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NORMAL, true);
+ ob = OBACT(view_layer);
/* restore bone name */
BLI_strncpy(newname, bone->name, sizeof(bone->name));
@@ -556,8 +370,8 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
char newname[sizeof(pchan->name)];
/* always make current pose-bone active */
- tree_element_active(C, scene, soops, te, OL_SETSEL_NORMAL, true);
- ob = OBACT;
+ tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NORMAL, true);
+ ob = OBACT(view_layer);
BLI_assert(ob->type == OB_ARMATURE);
@@ -591,6 +405,14 @@ static void namebutton_cb(bContext *C, void *tsep, char *oldname)
}
case TSE_R_LAYER:
break;
+ case TSE_SCENE_COLLECTION:
+ case TSE_LAYER_COLLECTION:
+ {
+ SceneCollection *sc = outliner_scene_collection_from_tree_element(te);
+ BKE_collection_rename(tselem->id, sc, te->name);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ break;
+ }
}
}
tselem->flag &= ~TSE_TEXTBUT;
@@ -603,8 +425,8 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
TreeElement *te;
TreeStoreElem *tselem;
Object *ob = NULL;
- Group *gr = NULL;
+#if 0
PropertyRNA *object_prop_hide, *object_prop_hide_select, *object_prop_hide_render;
/* get RNA properties (once) */
@@ -612,112 +434,24 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
object_prop_hide_select = RNA_struct_type_find_property(&RNA_Object, "hide_select");
object_prop_hide_render = RNA_struct_type_find_property(&RNA_Object, "hide_render");
BLI_assert(object_prop_hide && object_prop_hide_select && object_prop_hide_render);
+#endif
for (te = lb->first; te; te = te->next) {
tselem = TREESTORE(te);
if (te->ys + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && te->ys <= ar->v2d.cur.ymax) {
- /* objects have toggle-able restriction flags */
- if (tselem->type == 0 && te->idcode == ID_OB) {
- PointerRNA ptr;
-
- ob = (Object *)tselem->id;
- RNA_pointer_create((ID *)ob, &RNA_Object, ob, &ptr);
-
- UI_block_emboss_set(block, UI_EMBOSS_NONE);
- bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_VIEW_OFF,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
- &ptr, object_prop_hide, -1, 0, 0, -1, -1,
- TIP_("Restrict viewport visibility (Ctrl - Recursive)"));
- UI_but_func_set(bt, restrictbutton_view_cb, scene, ob);
- UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
- bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_SELECT_OFF,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
- &ptr, object_prop_hide_select, -1, 0, 0, -1, -1,
- TIP_("Restrict viewport selection (Ctrl - Recursive)"));
- UI_but_func_set(bt, restrictbutton_sel_cb, scene, ob);
- UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
- bt = uiDefIconButR_prop(block, UI_BTYPE_ICON_TOGGLE, 0, ICON_RESTRICT_RENDER_OFF,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
- &ptr, object_prop_hide_render, -1, 0, 0, -1, -1,
- TIP_("Restrict rendering (Ctrl - Recursive)"));
- UI_but_func_set(bt, restrictbutton_rend_cb, scene, ob);
- UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
- UI_block_emboss_set(block, UI_EMBOSS);
-
- }
- if (tselem->type == 0 && te->idcode == ID_GR) {
- int restrict_bool;
- int but_flag = UI_BUT_DRAG_LOCK;
- gr = (Group *)tselem->id;
-
- if (ID_IS_LINKED(gr))
- but_flag |= UI_BUT_DISABLED;
-
- UI_block_emboss_set(block, UI_EMBOSS_NONE);
-
- restrict_bool = group_restrict_flag(gr, OB_RESTRICT_VIEW);
- bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, restrict_bool ? ICON_RESTRICT_VIEW_ON : ICON_RESTRICT_VIEW_OFF,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X, UI_UNIT_Y,
- NULL, 0, 0, 0, 0, TIP_("Restrict/Allow visibility in the 3D View"));
- UI_but_func_set(bt, restrictbutton_gr_restrict_view, scene, gr);
- UI_but_flag_enable(bt, but_flag);
-
- restrict_bool = group_restrict_flag(gr, OB_RESTRICT_SELECT);
- bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, restrict_bool ? ICON_RESTRICT_SELECT_ON : ICON_RESTRICT_SELECT_OFF,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X, UI_UNIT_Y,
- NULL, 0, 0, 0, 0, TIP_("Restrict/Allow selection in the 3D View"));
- UI_but_func_set(bt, restrictbutton_gr_restrict_select, scene, gr);
- UI_but_flag_enable(bt, but_flag);
+ if (tselem->type == TSE_R_LAYER && (soops->outlinevis == SO_SCENES)) {
+ /* View layer render toggle. */
+ ViewLayer *view_layer = te->directdata;
- restrict_bool = group_restrict_flag(gr, OB_RESTRICT_RENDER);
- bt = uiDefIconBut(block, UI_BTYPE_ICON_TOGGLE, 0, restrict_bool ? ICON_RESTRICT_RENDER_ON : ICON_RESTRICT_RENDER_OFF,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X, UI_UNIT_Y,
- NULL, 0, 0, 0, 0, TIP_("Restrict/Allow renderability"));
- UI_but_func_set(bt, restrictbutton_gr_restrict_render, scene, gr);
- UI_but_flag_enable(bt, but_flag);
-
- UI_block_emboss_set(block, UI_EMBOSS);
- }
- /* scene render layers and passes have toggle-able flags too! */
- else if (tselem->type == TSE_R_LAYER) {
UI_block_emboss_set(block, UI_EMBOSS_NONE);
- bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE_N, SCE_LAY_DISABLE, 0, ICON_CHECKBOX_HLT - 1,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
- UI_UNIT_Y, te->directdata, 0, 0, 0, 0, TIP_("Render this RenderLayer"));
- UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
- UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
-
- UI_block_emboss_set(block, UI_EMBOSS);
- }
- else if (tselem->type == TSE_R_PASS) {
- int *layflag = te->directdata;
- int passflag = 1 << tselem->nr;
-
- UI_block_emboss_set(block, UI_EMBOSS_NONE);
-
-
- bt = uiDefIconButBitI(block, UI_BTYPE_ICON_TOGGLE, passflag, 0, ICON_CHECKBOX_HLT - 1,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
- UI_UNIT_Y, layflag, 0, 0, 0, 0, TIP_("Render this Pass"));
+ bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE_N, VIEW_LAYER_RENDER, 0, ICON_RESTRICT_RENDER_OFF,
+ (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
+ UI_UNIT_Y, &view_layer->flag, 0, 0, 0, 0, TIP_("Use view layer for rendering"));
UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
- layflag++; /* is lay_xor */
- if (ELEM(passflag, SCE_PASS_SPEC, SCE_PASS_SHADOW, SCE_PASS_AO, SCE_PASS_REFLECT, SCE_PASS_REFRACT,
- SCE_PASS_INDIRECT, SCE_PASS_EMIT, SCE_PASS_ENVIRONMENT))
- {
- bt = uiDefIconButBitI(block, UI_BTYPE_TOGGLE, passflag, 0, (*layflag & passflag) ? ICON_DOT : ICON_BLANK1,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
- UI_UNIT_Y, layflag, 0, 0, 0, 0, TIP_("Exclude this Pass from Combined"));
- UI_but_func_set(bt, restrictbutton_r_lay_cb, tselem->id, NULL);
- UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
- }
-
UI_block_emboss_set(block, UI_EMBOSS);
}
else if (tselem->type == TSE_MODIFIER) {
@@ -805,6 +539,49 @@ static void outliner_draw_restrictbuts(uiBlock *block, Scene *scene, ARegion *ar
UI_block_emboss_set(block, UI_EMBOSS);
}
+ else if (tselem->type == TSE_LAYER_COLLECTION) {
+ LayerCollection *collection = te->directdata;
+
+ const bool is_enabled = (collection->flag & COLLECTION_DISABLED) == 0;
+
+ UI_block_emboss_set(block, UI_EMBOSS_NONE);
+
+ if (collection->scene_collection->type == COLLECTION_TYPE_NONE) {
+ bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE_N, COLLECTION_SELECTABLE, 0, ICON_RESTRICT_SELECT_OFF,
+ (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
+ UI_UNIT_Y, &collection->flag, 0, 0, 0, 0,
+ TIP_("Restrict/Allow 3D View selection of objects in the collection"));
+ UI_but_func_set(bt, restrictbutton_collection_flag_cb, scene, collection);
+ UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+ }
+ else if ((soops->outlinevis == SO_GROUPS) &&
+ (collection->scene_collection->type == COLLECTION_TYPE_GROUP_INTERNAL))
+ {
+ bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE_N, COLLECTION_VIEWPORT, 0, ICON_RESTRICT_VIEW_OFF,
+ (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), te->ys, UI_UNIT_X,
+ UI_UNIT_Y, &collection->flag, 0, 0, 0, 0,
+ TIP_("Restrict/Allow 3D View selection of objects in the collection"));
+ UI_but_func_set(bt, restrictbutton_collection_flag_cb, tselem->id, collection);
+ UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+
+ bt = uiDefIconButBitS(block, UI_BTYPE_ICON_TOGGLE_N, COLLECTION_RENDER, 0, ICON_RESTRICT_RENDER_OFF,
+ (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), te->ys, UI_UNIT_X,
+ UI_UNIT_Y, &collection->flag, 0, 0, 0, 0,
+ TIP_("Restrict/Allow 3D View selection of objects in the collection"));
+ UI_but_func_set(bt, restrictbutton_collection_flag_cb, tselem->id, collection);
+ UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+ }
+
+ bt = uiDefIconButBitS(block, UI_BTYPE_BUT_TOGGLE, COLLECTION_DISABLED, 0,
+ is_enabled ? ICON_CHECKBOX_HLT : ICON_CHECKBOX_DEHLT,
+ (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), te->ys, UI_UNIT_X,
+ UI_UNIT_Y, &collection->flag, 0, 0, 0, 0,
+ TIP_("Enable/Disable collection"));
+ UI_but_func_set(bt, restrictbutton_collection_flag_cb, tselem->id, collection);
+ UI_but_flag_enable(bt, UI_BUT_DRAG_LOCK);
+
+ UI_block_emboss_set(block, UI_EMBOSS);
+ }
}
if (TSELEM_OPEN(tselem, soops)) outliner_draw_restrictbuts(block, scene, ar, soops, &te->subtree);
@@ -878,18 +655,23 @@ static void outliner_draw_rnacols(ARegion *ar, int sizex)
float miny = v2d->cur.ymin;
if (miny < v2d->tot.ymin) miny = v2d->tot.ymin;
- UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
+ glLineWidth(1.0f);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
- /* draw column separator lines */
- fdrawline((float)sizex,
- v2d->cur.ymax,
- (float)sizex,
- miny);
+ immBegin(GWN_PRIM_LINES, 4);
- fdrawline((float)sizex + OL_RNA_COL_SIZEX,
- v2d->cur.ymax,
- (float)sizex + OL_RNA_COL_SIZEX,
- miny);
+ immVertex2f(pos, sizex, v2d->cur.ymax);
+ immVertex2f(pos, sizex, miny);
+
+ immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, v2d->cur.ymax);
+ immVertex2f(pos, sizex + OL_RNA_COL_SIZEX, miny);
+
+ immEnd();
+
+ immUnbindProgram();
}
static void outliner_draw_rnabuts(uiBlock *block, ARegion *ar, SpaceOops *soops, int sizex, ListBase *lb)
@@ -987,7 +769,7 @@ static void tselem_draw_icon_uibut(struct DrawIconArg *arg, int icon)
/* restrict column clip... it has been coded by simply overdrawing, doesnt work for buttons */
if (arg->x >= arg->xmax) {
glEnable(GL_BLEND);
- UI_icon_draw_aspect(arg->x, arg->y, icon, 1.0f / UI_DPI_FAC, arg->alpha);
+ UI_icon_draw_alpha(arg->x, arg->y, icon, arg->alpha);
glDisable(GL_BLEND);
}
else {
@@ -1047,7 +829,7 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
arg.xb = x; /* for ui buttons */
arg.yb = y;
arg.alpha = alpha;
-
+
/* placement of icons, copied from interface_widgets.c */
aspect = (0.8f * UI_UNIT_Y) / ICON_DEFAULT_HEIGHT;
x += 2.0f * aspect;
@@ -1055,184 +837,260 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
arg.x = x;
arg.y = y;
+#define ICON_DRAW(_icon) UI_icon_draw_alpha(x, y, _icon, alpha)
+
if (tselem->type) {
switch (tselem->type) {
case TSE_ANIM_DATA:
- UI_icon_draw(x, y, ICON_ANIM_DATA); break; // xxx
+ ICON_DRAW(ICON_ANIM_DATA); /* XXX */
+ break;
case TSE_NLA:
- UI_icon_draw(x, y, ICON_NLA); break;
+ ICON_DRAW(ICON_NLA);
+ break;
case TSE_NLA_TRACK:
- UI_icon_draw(x, y, ICON_NLA); break; // XXX
+ ICON_DRAW(ICON_NLA); /* XXX */
+ break;
case TSE_NLA_ACTION:
- UI_icon_draw(x, y, ICON_ACTION); break;
+ ICON_DRAW(ICON_ACTION);
+ break;
case TSE_DRIVER_BASE:
- UI_icon_draw(x, y, ICON_DRIVER); break;
+ ICON_DRAW(ICON_DRIVER);
+ break;
case TSE_DEFGROUP_BASE:
- UI_icon_draw(x, y, ICON_GROUP_VERTEX); break;
+ ICON_DRAW(ICON_GROUP_VERTEX);
+ break;
case TSE_BONE:
case TSE_EBONE:
- UI_icon_draw(x, y, ICON_BONE_DATA); break;
+ ICON_DRAW(ICON_BONE_DATA);
+ break;
case TSE_CONSTRAINT_BASE:
- UI_icon_draw(x, y, ICON_CONSTRAINT); break;
+ ICON_DRAW(ICON_CONSTRAINT);
+ break;
case TSE_MODIFIER_BASE:
- UI_icon_draw(x, y, ICON_MODIFIER); break;
+ ICON_DRAW(ICON_MODIFIER);
+ break;
case TSE_LINKED_OB:
- UI_icon_draw(x, y, ICON_OBJECT_DATA); break;
+ ICON_DRAW(ICON_OBJECT_DATA);
+ break;
case TSE_LINKED_PSYS:
- UI_icon_draw(x, y, ICON_PARTICLES); break;
+ ICON_DRAW(ICON_PARTICLES);
+ break;
case TSE_MODIFIER:
{
Object *ob = (Object *)tselem->id;
ModifierData *md = BLI_findlink(&ob->modifiers, tselem->nr);
switch ((ModifierType)md->type) {
- case eModifierType_Subsurf:
- UI_icon_draw(x, y, ICON_MOD_SUBSURF); break;
- case eModifierType_Armature:
- UI_icon_draw(x, y, ICON_MOD_ARMATURE); break;
- case eModifierType_Lattice:
- UI_icon_draw(x, y, ICON_MOD_LATTICE); break;
- case eModifierType_Curve:
- UI_icon_draw(x, y, ICON_MOD_CURVE); break;
- case eModifierType_Build:
- UI_icon_draw(x, y, ICON_MOD_BUILD); break;
- case eModifierType_Mirror:
- UI_icon_draw(x, y, ICON_MOD_MIRROR); break;
- case eModifierType_Decimate:
- UI_icon_draw(x, y, ICON_MOD_DECIM); break;
- case eModifierType_Wave:
- UI_icon_draw(x, y, ICON_MOD_WAVE); break;
- case eModifierType_Hook:
- UI_icon_draw(x, y, ICON_HOOK); break;
- case eModifierType_Softbody:
- UI_icon_draw(x, y, ICON_MOD_SOFT); break;
- case eModifierType_Boolean:
- UI_icon_draw(x, y, ICON_MOD_BOOLEAN); break;
- case eModifierType_ParticleSystem:
- UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
+ case eModifierType_Subsurf:
+ ICON_DRAW(ICON_MOD_SUBSURF);
+ break;
+ case eModifierType_Armature:
+ ICON_DRAW(ICON_MOD_ARMATURE);
+ break;
+ case eModifierType_Lattice:
+ ICON_DRAW(ICON_MOD_LATTICE);
+ break;
+ case eModifierType_Curve:
+ ICON_DRAW(ICON_MOD_CURVE);
+ break;
+ case eModifierType_Build:
+ ICON_DRAW(ICON_MOD_BUILD);
+ break;
+ case eModifierType_Mirror:
+ ICON_DRAW(ICON_MOD_MIRROR);
+ break;
+ case eModifierType_Decimate:
+ ICON_DRAW(ICON_MOD_DECIM);
+ break;
+ case eModifierType_Wave:
+ ICON_DRAW(ICON_MOD_WAVE);
+ break;
+ case eModifierType_Hook:
+ ICON_DRAW(ICON_HOOK);
+ break;
+ case eModifierType_Softbody:
+ ICON_DRAW(ICON_MOD_SOFT);
+ break;
+ case eModifierType_Boolean:
+ ICON_DRAW(ICON_MOD_BOOLEAN);
+ break;
+ case eModifierType_ParticleSystem:
+ ICON_DRAW(ICON_MOD_PARTICLES);
+ break;
case eModifierType_ParticleInstance:
- UI_icon_draw(x, y, ICON_MOD_PARTICLES); break;
+ ICON_DRAW(ICON_MOD_PARTICLES);
+ break;
case eModifierType_EdgeSplit:
- UI_icon_draw(x, y, ICON_MOD_EDGESPLIT); break;
+ ICON_DRAW(ICON_MOD_EDGESPLIT);
+ break;
case eModifierType_Array:
- UI_icon_draw(x, y, ICON_MOD_ARRAY); break;
+ ICON_DRAW(ICON_MOD_ARRAY);
+ break;
case eModifierType_UVProject:
case eModifierType_UVWarp: /* TODO, get own icon */
- UI_icon_draw(x, y, ICON_MOD_UVPROJECT); break;
+ ICON_DRAW(ICON_MOD_UVPROJECT);
+ break;
case eModifierType_Displace:
- UI_icon_draw(x, y, ICON_MOD_DISPLACE); break;
+ ICON_DRAW(ICON_MOD_DISPLACE);
+ break;
case eModifierType_Shrinkwrap:
- UI_icon_draw(x, y, ICON_MOD_SHRINKWRAP); break;
+ ICON_DRAW(ICON_MOD_SHRINKWRAP);
+ break;
case eModifierType_Cast:
- UI_icon_draw(x, y, ICON_MOD_CAST); break;
+ ICON_DRAW(ICON_MOD_CAST);
+ break;
case eModifierType_MeshDeform:
case eModifierType_SurfaceDeform:
- UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break;
+ ICON_DRAW(ICON_MOD_MESHDEFORM);
+ break;
case eModifierType_Bevel:
- UI_icon_draw(x, y, ICON_MOD_BEVEL); break;
+ ICON_DRAW(ICON_MOD_BEVEL);
+ break;
case eModifierType_Smooth:
case eModifierType_LaplacianSmooth:
case eModifierType_CorrectiveSmooth:
- UI_icon_draw(x, y, ICON_MOD_SMOOTH); break;
+ ICON_DRAW(ICON_MOD_SMOOTH);
+ break;
case eModifierType_SimpleDeform:
- UI_icon_draw(x, y, ICON_MOD_SIMPLEDEFORM); break;
+ ICON_DRAW(ICON_MOD_SIMPLEDEFORM);
+ break;
case eModifierType_Mask:
- UI_icon_draw(x, y, ICON_MOD_MASK); break;
+ ICON_DRAW(ICON_MOD_MASK);
+ break;
case eModifierType_Cloth:
- UI_icon_draw(x, y, ICON_MOD_CLOTH); break;
+ ICON_DRAW(ICON_MOD_CLOTH);
+ break;
case eModifierType_Explode:
- UI_icon_draw(x, y, ICON_MOD_EXPLODE); break;
+ ICON_DRAW(ICON_MOD_EXPLODE);
+ break;
case eModifierType_Collision:
case eModifierType_Surface:
- UI_icon_draw(x, y, ICON_MOD_PHYSICS); break;
+ ICON_DRAW(ICON_MOD_PHYSICS);
+ break;
case eModifierType_Fluidsim:
- UI_icon_draw(x, y, ICON_MOD_FLUIDSIM); break;
+ ICON_DRAW(ICON_MOD_FLUIDSIM);
+ break;
case eModifierType_Multires:
- UI_icon_draw(x, y, ICON_MOD_MULTIRES); break;
+ ICON_DRAW(ICON_MOD_MULTIRES);
+ break;
case eModifierType_Smoke:
- UI_icon_draw(x, y, ICON_MOD_SMOKE); break;
+ ICON_DRAW(ICON_MOD_SMOKE);
+ break;
case eModifierType_Solidify:
- UI_icon_draw(x, y, ICON_MOD_SOLIDIFY); break;
+ ICON_DRAW(ICON_MOD_SOLIDIFY);
+ break;
case eModifierType_Screw:
- UI_icon_draw(x, y, ICON_MOD_SCREW); break;
+ ICON_DRAW(ICON_MOD_SCREW);
+ break;
case eModifierType_Remesh:
- UI_icon_draw(x, y, ICON_MOD_REMESH); break;
+ ICON_DRAW(ICON_MOD_REMESH);
+ break;
case eModifierType_WeightVGEdit:
case eModifierType_WeightVGMix:
case eModifierType_WeightVGProximity:
- UI_icon_draw(x, y, ICON_MOD_VERTEX_WEIGHT); break;
+ ICON_DRAW(ICON_MOD_VERTEX_WEIGHT);
+ break;
case eModifierType_DynamicPaint:
- UI_icon_draw(x, y, ICON_MOD_DYNAMICPAINT); break;
+ ICON_DRAW(ICON_MOD_DYNAMICPAINT);
+ break;
case eModifierType_Ocean:
- UI_icon_draw(x, y, ICON_MOD_OCEAN); break;
+ ICON_DRAW(ICON_MOD_OCEAN);
+ break;
case eModifierType_Warp:
- UI_icon_draw(x, y, ICON_MOD_WARP); break;
+ ICON_DRAW(ICON_MOD_WARP);
+ break;
case eModifierType_Skin:
- UI_icon_draw(x, y, ICON_MOD_SKIN); break;
+ ICON_DRAW(ICON_MOD_SKIN);
+ break;
case eModifierType_Triangulate:
- UI_icon_draw(x, y, ICON_MOD_TRIANGULATE); break;
+ ICON_DRAW(ICON_MOD_TRIANGULATE);
+ break;
case eModifierType_MeshCache:
- UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break; /* XXX, needs own icon */
+ ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
+ break;
case eModifierType_MeshSequenceCache:
- UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break; /* XXX, needs own icon */
+ ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
+ break;
case eModifierType_Wireframe:
- UI_icon_draw(x, y, ICON_MOD_WIREFRAME); break;
+ ICON_DRAW(ICON_MOD_WIREFRAME);
+ break;
case eModifierType_LaplacianDeform:
- UI_icon_draw(x, y, ICON_MOD_MESHDEFORM); break; /* XXX, needs own icon */
+ ICON_DRAW(ICON_MOD_MESHDEFORM); /* XXX, needs own icon */
+ break;
case eModifierType_DataTransfer:
- UI_icon_draw(x, y, ICON_MOD_DATA_TRANSFER); break;
+ ICON_DRAW(ICON_MOD_DATA_TRANSFER);
+ break;
case eModifierType_NormalEdit:
- UI_icon_draw(x, y, ICON_MOD_NORMALEDIT); break;
+ ICON_DRAW(ICON_MOD_NORMALEDIT);
+ break;
/* Default */
case eModifierType_None:
case eModifierType_ShapeKey:
case NUM_MODIFIER_TYPES:
- UI_icon_draw(x, y, ICON_DOT); break;
+ ICON_DRAW(ICON_DOT);
+ break;
}
break;
}
case TSE_POSE_BASE:
- UI_icon_draw(x, y, ICON_ARMATURE_DATA); break;
+ ICON_DRAW(ICON_ARMATURE_DATA);
+ break;
case TSE_POSE_CHANNEL:
- UI_icon_draw(x, y, ICON_BONE_DATA); break;
+ ICON_DRAW(ICON_BONE_DATA);
+ break;
case TSE_PROXY:
- UI_icon_draw(x, y, ICON_GHOST); break;
+ ICON_DRAW(ICON_GHOST);
+ break;
case TSE_R_LAYER_BASE:
- UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
+ ICON_DRAW(ICON_RENDERLAYERS);
+ break;
+ case TSE_SCENE_OBJECTS_BASE:
+ ICON_DRAW(ICON_OUTLINER_OB_GROUP_INSTANCE);
+ break;
case TSE_R_LAYER:
- UI_icon_draw(x, y, ICON_RENDERLAYERS); break;
+ ICON_DRAW(ICON_RENDER_RESULT);
+ break;
case TSE_LINKED_LAMP:
- UI_icon_draw(x, y, ICON_LAMP_DATA); break;
+ ICON_DRAW(ICON_LAMP_DATA);
+ break;
case TSE_LINKED_MAT:
- UI_icon_draw(x, y, ICON_MATERIAL_DATA); break;
+ ICON_DRAW(ICON_MATERIAL_DATA);
+ break;
case TSE_POSEGRP_BASE:
- UI_icon_draw(x, y, ICON_GROUP_BONE); break;
+ ICON_DRAW(ICON_GROUP_BONE);
+ break;
case TSE_SEQUENCE:
if (te->idcode == SEQ_TYPE_MOVIE)
- UI_icon_draw(x, y, ICON_SEQUENCE);
+ ICON_DRAW(ICON_SEQUENCE);
else if (te->idcode == SEQ_TYPE_META)
- UI_icon_draw(x, y, ICON_DOT);
+ ICON_DRAW(ICON_DOT);
else if (te->idcode == SEQ_TYPE_SCENE)
- UI_icon_draw(x, y, ICON_SCENE);
+ ICON_DRAW(ICON_SCENE);
else if (te->idcode == SEQ_TYPE_SOUND_RAM)
- UI_icon_draw(x, y, ICON_SOUND);
+ ICON_DRAW(ICON_SOUND);
else if (te->idcode == SEQ_TYPE_IMAGE)
- UI_icon_draw(x, y, ICON_IMAGE_COL);
+ ICON_DRAW(ICON_IMAGE_COL);
else
- UI_icon_draw(x, y, ICON_PARTICLES);
+ ICON_DRAW(ICON_PARTICLES);
break;
case TSE_SEQ_STRIP:
- UI_icon_draw(x, y, ICON_LIBRARY_DATA_DIRECT);
+ ICON_DRAW(ICON_LIBRARY_DATA_DIRECT);
break;
case TSE_SEQUENCE_DUP:
- UI_icon_draw(x, y, ICON_OBJECT_DATA);
+ ICON_DRAW(ICON_OBJECT_DATA);
break;
case TSE_RNA_STRUCT:
if (RNA_struct_is_ID(te->rnaptr.type)) {
arg.id = (ID *)te->rnaptr.data;
tselem_draw_icon_uibut(&arg, RNA_struct_ui_icon(te->rnaptr.type));
}
- else
- UI_icon_draw(x, y, RNA_struct_ui_icon(te->rnaptr.type));
+ else {
+ int icon = RNA_struct_ui_icon(te->rnaptr.type);
+ ICON_DRAW(icon);
+ }
+ break;
+ case TSE_LAYER_COLLECTION:
+ case TSE_SCENE_COLLECTION:
+ ICON_DRAW(ICON_COLLAPSEMENU);
break;
/* Removed the icons from outliner. Need a better structure with Layers, Palettes and Colors */
#if 0
@@ -1241,7 +1099,8 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
break;
#endif
default:
- UI_icon_draw(x, y, ICON_DOT); break;
+ ICON_DRAW(ICON_DOT);
+ break;
}
}
else if (tselem->id) {
@@ -1351,17 +1210,19 @@ static void tselem_draw_icon(uiBlock *block, int xmax, float x, float y, TreeSto
}
}
}
+
+#undef ICON_DRAW
}
-static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, SpaceOops *soops, ListBase *lb, int level,
- int xmax, int *offsx, int ys)
+static void outliner_draw_iconrow(
+ bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer, Object *obedit, SpaceOops *soops,
+ ListBase *lb, int level, int xmax, int *offsx, int ys, float alpha_fac)
{
TreeElement *te;
TreeStoreElem *tselem;
eOLDrawState active;
for (te = lb->first; te; te = te->next) {
-
/* exit drawing early */
if ((*offsx) - UI_UNIT_X > xmax)
break;
@@ -1374,34 +1235,38 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa
/* active blocks get white circle */
if (tselem->type == 0) {
if (te->idcode == ID_OB) {
- active = (OBACT == (Object *)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
+ active = (OBACT(view_layer) == (Object *)tselem->id) ? OL_DRAWSEL_NORMAL : OL_DRAWSEL_NONE;
}
- else if (scene->obedit && scene->obedit->data == tselem->id) {
+ else if (obedit && obedit->data == tselem->id) {
active = OL_DRAWSEL_NORMAL;
}
else {
- active = tree_element_active(C, scene, soops, te, OL_SETSEL_NONE, false);
+ active = tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false);
}
}
else {
- active = tree_element_type_active(NULL, scene, soops, te, tselem, OL_SETSEL_NONE, false);
+ active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
}
if (active != OL_DRAWSEL_NONE) {
float ufac = UI_UNIT_X / 20.0f;
+ float color[4] = {1.0f, 1.0f, 1.0f, 0.4f};
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- glColor4ub(255, 255, 255, 100);
- UI_draw_roundbox(
+ color[3] *= alpha_fac;
+
+ UI_draw_roundbox_aa(
+ true,
(float) *offsx + 1.0f * ufac,
(float)ys + 1.0f * ufac,
(float)*offsx + UI_UNIT_X - 1.0f * ufac,
(float)ys + UI_UNIT_Y - ufac,
- (float)UI_UNIT_Y / 2.0f - ufac);
+ (float)UI_UNIT_Y / 2.0f - ufac,
+ color);
glEnable(GL_BLEND); /* roundbox disables */
}
- tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f);
+ tselem_draw_icon(block, xmax, (float)*offsx, (float)ys, tselem, te, 0.5f * alpha_fac);
te->xs = *offsx;
te->ys = ys;
te->xend = (short)*offsx + UI_UNIT_X;
@@ -1412,7 +1277,9 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa
/* this tree element always has same amount of branches, so don't draw */
if (tselem->type != TSE_R_LAYER)
- outliner_draw_iconrow(C, block, scene, soops, &te->subtree, level + 1, xmax, offsx, ys);
+ outliner_draw_iconrow(
+ C, block, scene, view_layer, obedit, soops,
+ &te->subtree, level + 1, xmax, offsx, ys, alpha_fac);
}
}
@@ -1421,11 +1288,14 @@ static void outliner_draw_iconrow(bContext *C, uiBlock *block, Scene *scene, Spa
static void outliner_set_coord_tree_element(TreeElement *te, int startx, int starty)
{
TreeElement *ten;
-
- /* store coord and continue, we need coordinates for elements outside view too */
- te->xs = startx;
- te->ys = starty;
-
+
+ /* closed items may be displayed in row of parent, don't change their coordinate! */
+ if ((te->flag & TE_ICONROW) == 0) {
+ /* store coord and continue, we need coordinates for elements outside view too */
+ te->xs = startx;
+ te->ys = starty;
+ }
+
for (ten = te->subtree.first; ten; ten = ten->next) {
outliner_set_coord_tree_element(ten, startx + UI_UNIT_X, starty);
}
@@ -1433,24 +1303,28 @@ static void outliner_set_coord_tree_element(TreeElement *te, int startx, int sta
static void outliner_draw_tree_element(
- bContext *C, uiBlock *block, const uiFontStyle *fstyle, Scene *scene, ARegion *ar, SpaceOops *soops,
- TreeElement *te, int startx, int *starty, TreeElement **te_edit)
+ bContext *C, uiBlock *block, const uiFontStyle *fstyle, Scene *scene, ViewLayer *view_layer, Object *obedit,
+ ARegion *ar, SpaceOops *soops, TreeElement *te, bool draw_grayed_out,
+ int startx, int *starty, TreeElement **te_edit, TreeElement **te_floating)
{
- TreeElement *ten;
TreeStoreElem *tselem;
float ufac = UI_UNIT_X / 20.0f;
int offsx = 0;
eOLDrawState active = OL_DRAWSEL_NONE;
-
+ float color[4];
tselem = TREESTORE(te);
if (*starty + 2 * UI_UNIT_Y >= ar->v2d.cur.ymin && *starty <= ar->v2d.cur.ymax) {
+ const float alpha_fac = draw_grayed_out ? 0.5f : 1.0f;
+ const float alpha = 0.5f * alpha_fac;
int xmax = ar->v2d.cur.xmax;
- unsigned char alpha = 128;
-
+
if ((tselem->flag & TSE_TEXTBUT) && (*te_edit == NULL)) {
*te_edit = te;
}
+ if ((te->drag_data != NULL) && (*te_floating == NULL)) {
+ *te_floating = te;
+ }
/* icons can be ui buts, we don't want it to overlap with restrict */
if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
@@ -1458,151 +1332,137 @@ static void outliner_draw_tree_element(
glEnable(GL_BLEND);
- /* start by highlighting search matches
- * we don't expand items when searching in the datablocks but we
- * still want to highlight any filter matches.
- */
- if ((SEARCHING_OUTLINER(soops) || (soops->outlinevis == SO_DATABLOCKS && soops->search_string[0] != 0)) &&
- (tselem->flag & TSE_SEARCHMATCH))
- {
- char col[4];
- UI_GetThemeColorType4ubv(TH_MATCH, SPACE_OUTLINER, col);
- col[3] = alpha;
- glColor4ubv((GLubyte *)col);
- glRecti(startx, *starty + 1, ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
- }
-
/* colors for active/selected data */
if (tselem->type == 0) {
-
if (te->idcode == ID_SCE) {
if (tselem->id == (ID *)scene) {
- glColor4ub(255, 255, 255, alpha);
- active = OL_DRAWSEL_ACTIVE;
- }
- }
- else if (te->idcode == ID_GR) {
- Group *gr = (Group *)tselem->id;
- if (group_select_flag(gr)) {
- char col[4];
- UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
- col[3] = alpha;
- glColor4ubv((GLubyte *)col);
-
+ rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
active = OL_DRAWSEL_ACTIVE;
}
}
else if (te->idcode == ID_OB) {
Object *ob = (Object *)tselem->id;
-
- if (ob == OBACT || (ob->flag & SELECT)) {
+ Base *base = (Base *)te->directdata;
+ const bool is_selected = (base != NULL) && ((base->flag & BASE_SELECTED) != 0);
+
+ if (ob == OBACT(view_layer) || is_selected) {
char col[4] = {0, 0, 0, 0};
/* outliner active ob: always white text, circle color now similar to view3d */
active = OL_DRAWSEL_ACTIVE;
- if (ob == OBACT) {
- if (ob->flag & SELECT) {
+ if (ob == OBACT(view_layer)) {
+ if (is_selected) {
UI_GetThemeColorType4ubv(TH_ACTIVE, SPACE_VIEW3D, col);
col[3] = alpha;
}
active = OL_DRAWSEL_NORMAL;
}
- else if (ob->flag & SELECT) {
+ else if (is_selected) {
UI_GetThemeColorType4ubv(TH_SELECT, SPACE_VIEW3D, col);
col[3] = alpha;
}
-
- glColor4ubv((GLubyte *)col);
+ rgba_float_args_set(color, (float)col[0] / 255, (float)col[1] / 255, (float)col[2] / 255, alpha);
}
}
- else if (scene->obedit && scene->obedit->data == tselem->id) {
- glColor4ub(255, 255, 255, alpha);
+ else if (obedit && obedit->data == tselem->id) {
+ rgba_float_args_set(color, 1.0f, 1.0f, 1.0f, alpha);
active = OL_DRAWSEL_ACTIVE;
}
else {
- if (tree_element_active(C, scene, soops, te, OL_SETSEL_NONE, false)) {
- glColor4ub(220, 220, 255, alpha);
+ if (tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NONE, false)) {
+ rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
active = OL_DRAWSEL_ACTIVE;
}
}
}
else {
- if (tree_element_type_active(NULL, scene, soops, te, tselem, OL_SETSEL_NONE, false) != OL_DRAWSEL_NONE) {
- active = OL_DRAWSEL_ACTIVE;
- }
- glColor4ub(220, 220, 255, alpha);
+ active = tree_element_type_active(C, scene, view_layer, soops, te, tselem, OL_SETSEL_NONE, false);
+ rgba_float_args_set(color, 0.85f, 0.85f, 1.0f, alpha);
}
/* active circle */
if (active != OL_DRAWSEL_NONE) {
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox(
+ UI_draw_roundbox_aa(
+ true,
(float)startx + UI_UNIT_X + 1.0f * ufac,
(float)*starty + 1.0f * ufac,
(float)startx + 2.0f * UI_UNIT_X - 1.0f * ufac,
(float)*starty + UI_UNIT_Y - 1.0f * ufac,
- UI_UNIT_Y / 2.0f - 1.0f * ufac);
+ UI_UNIT_Y / 2.0f - 1.0f * ufac, color);
glEnable(GL_BLEND); /* roundbox disables it */
te->flag |= TE_ACTIVE; // for lookup in display hierarchies
}
- /* open/close icon, only when sublevels, except for scene */
- if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
- int icon_x;
- icon_x = startx;
-
+ if ((soops->outlinevis == SO_COLLECTIONS) && (tselem->type == TSE_R_LAYER)) {
+ /* View layer in collections can't expand/collapse. */
+ }
+ else if (te->subtree.first || (tselem->type == 0 && te->idcode == ID_SCE) || (te->flag & TE_LAZY_CLOSED)) {
+ /* open/close icon, only when sublevels, except for scene */
+ int icon_x = startx;
+
// icons a bit higher
if (TSELEM_OPEN(tselem, soops))
- UI_icon_draw((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_DOWN);
+ UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_DOWN,
+ alpha_fac);
else
- UI_icon_draw((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_RIGHT);
+ UI_icon_draw_alpha((float)icon_x + 2 * ufac, (float)*starty + 1 * ufac, ICON_DISCLOSURE_TRI_RIGHT,
+ alpha_fac);
}
offsx += UI_UNIT_X;
/* datatype icon */
if (!(ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM))) {
-
- tselem_draw_icon(block, xmax, (float)startx + offsx, (float)*starty, tselem, te, 1.0f);
-
+ tselem_draw_icon(block, xmax, (float)startx + offsx, (float)*starty, tselem, te, alpha_fac);
offsx += UI_UNIT_X + 2 * ufac;
}
else
offsx += 2 * ufac;
if (tselem->type == 0 && ID_IS_LINKED(tselem->id)) {
- glPixelTransferf(GL_ALPHA_SCALE, 0.5f);
if (tselem->id->tag & LIB_TAG_MISSING) {
- UI_icon_draw((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_BROKEN);
+ UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_BROKEN,
+ alpha_fac);
}
else if (tselem->id->tag & LIB_TAG_INDIRECT) {
- UI_icon_draw((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_INDIRECT);
+ UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_INDIRECT,
+ alpha_fac);
}
else {
- UI_icon_draw((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_DIRECT);
+ UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_DIRECT,
+ alpha_fac);
}
- glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
+ offsx += UI_UNIT_X + 2 * ufac;
+ }
+ else if (tselem->type == 0 && ID_IS_STATIC_OVERRIDE(tselem->id)) {
+ UI_icon_draw_alpha((float)startx + offsx + 2 * ufac, (float)*starty + 2 * ufac, ICON_LIBRARY_DATA_OVERRIDE,
+ alpha_fac);
offsx += UI_UNIT_X + 2 * ufac;
}
glDisable(GL_BLEND);
/* name */
if ((tselem->flag & TSE_TEXTBUT) == 0) {
+ unsigned char text_col[4];
+
if (active == OL_DRAWSEL_NORMAL) {
- UI_ThemeColor(TH_TEXT_HI);
+ UI_GetThemeColor4ubv(TH_TEXT_HI, text_col);
}
else if (ELEM(tselem->type, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM)) {
- UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.75f);
+ UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.75f, text_col);
+ text_col[3] = 255;
}
else {
- UI_ThemeColor(TH_TEXT);
+ UI_GetThemeColor4ubv(TH_TEXT, text_col);
}
+ text_col[3] *= alpha_fac;
- UI_fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name);
+ UI_fontstyle_draw_simple(fstyle, startx + offsx, *starty + 5 * ufac, te->name, text_col);
}
offsx += (int)(UI_UNIT_X + UI_fontstyle_string_width(fstyle, te->name));
@@ -1613,24 +1473,34 @@ static void outliner_draw_tree_element(
if (tselem->type == 0 && te->idcode == ID_SCE) {
/* pass */
}
+ /* this tree element always has same amount of branches, so don't draw */
else if (tselem->type != TSE_R_LAYER) {
- /* this tree element always has same amount of branches, so don't draw */
-
int tempx = startx + offsx;
-
- /* divider */
- UI_ThemeColorShade(TH_BACK, -40);
- glRecti(tempx - 10.0f * ufac,
- *starty + 4.0f * ufac,
- tempx - 8.0f * ufac,
- *starty + UI_UNIT_Y - 4.0f * ufac);
-
+
glEnable(GL_BLEND);
- glPixelTransferf(GL_ALPHA_SCALE, 0.5);
-
- outliner_draw_iconrow(C, block, scene, soops, &te->subtree, 0, xmax, &tempx, *starty);
-
- glPixelTransferf(GL_ALPHA_SCALE, 1.0);
+
+ /* divider */
+ {
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ unsigned char col[4];
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ UI_GetThemeColorShade4ubv(TH_BACK, -40, col);
+ col[3] *= alpha_fac;
+
+ immUniformColor4ubv(col);
+ immRecti(pos, tempx - 10.0f * ufac,
+ *starty + 4.0f * ufac,
+ tempx - 8.0f * ufac,
+ *starty + UI_UNIT_Y - 4.0f * ufac);
+ immUnbindProgram();
+ }
+
+ outliner_draw_iconrow(
+ C, block, scene, view_layer, obedit, soops, &te->subtree, 0, xmax, &tempx,
+ *starty, alpha_fac);
+
glDisable(GL_BLEND);
}
}
@@ -1640,16 +1510,22 @@ static void outliner_draw_tree_element(
te->xs = startx;
te->ys = *starty;
te->xend = startx + offsx;
-
+
if (TSELEM_OPEN(tselem, soops)) {
*starty -= UI_UNIT_Y;
- for (ten = te->subtree.first; ten; ten = ten->next) {
- outliner_draw_tree_element(C, block, fstyle, scene, ar, soops, ten, startx + UI_UNIT_X, starty, te_edit);
+ for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
+ /* check if element needs to be drawn grayed out, but also gray out
+ * childs of a grayed out parent (pass on draw_grayed_out to childs) */
+ bool draw_childs_grayed_out = draw_grayed_out || (ten->drag_data != NULL);
+ outliner_draw_tree_element(
+ C, block, fstyle, scene, view_layer, obedit,
+ ar, soops, ten, draw_childs_grayed_out,
+ startx + UI_UNIT_X, starty, te_edit, te_floating);
}
}
else {
- for (ten = te->subtree.first; ten; ten = ten->next) {
+ for (TreeElement *ten = te->subtree.first; ten; ten = ten->next) {
outliner_set_coord_tree_element(ten, startx, *starty);
}
@@ -1657,115 +1533,286 @@ static void outliner_draw_tree_element(
}
}
-static void outliner_draw_hierarchy(SpaceOops *soops, ListBase *lb, int startx, int *starty)
+static void outliner_draw_tree_element_floating(
+ const ARegion *ar, const TreeElement *te_floating)
{
- TreeElement *te;
+ const TreeElement *te_insert = te_floating->drag_data->insert_handle;
+ const int line_width = 2;
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ int coord_y = te_insert->ys;
+ int coord_x = te_insert->xs;
+ float col[4];
+
+ if (te_insert == te_floating) {
+ /* don't draw anything */
+ return;
+ }
+
+ UI_GetThemeColorShade4fv(TH_BACK, -40, col);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ glEnable(GL_BLEND);
+
+ if (ELEM(te_floating->drag_data->insert_type, TE_INSERT_BEFORE, TE_INSERT_AFTER)) {
+ if (te_floating->drag_data->insert_type == TE_INSERT_BEFORE) {
+ coord_y += UI_UNIT_Y;
+ }
+ immUniformColor4fv(col);
+ glLineWidth(line_width);
+
+ immBegin(GWN_PRIM_LINE_STRIP, 2);
+ immVertex2f(pos, coord_x, coord_y);
+ immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
+ immEnd();
+ }
+ else {
+ BLI_assert(te_floating->drag_data->insert_type == TE_INSERT_INTO);
+ immUniformColor3fvAlpha(col, col[3] * 0.5f);
+
+ immBegin(GWN_PRIM_TRI_STRIP, 4);
+ immVertex2f(pos, coord_x, coord_y + UI_UNIT_Y);
+ immVertex2f(pos, coord_x, coord_y);
+ immVertex2f(pos, ar->v2d.cur.xmax, coord_y + UI_UNIT_Y);
+ immVertex2f(pos, ar->v2d.cur.xmax, coord_y);
+ immEnd();
+ }
+
+ glDisable(GL_BLEND);
+ immUnbindProgram();
+}
+
+static void outliner_draw_hierarchy_lines_recursive(unsigned pos, SpaceOops *soops, ListBase *lb, int startx,
+ const unsigned char col[4], bool draw_grayed_out,
+ int *starty)
+{
+ TreeElement *te, *te_vertical_line_last = NULL;
TreeStoreElem *tselem;
int y1, y2;
-
- if (BLI_listbase_is_empty(lb)) return;
-
- y1 = y2 = *starty; /* for vertical lines between objects */
+
+ if (BLI_listbase_is_empty(lb)) {
+ return;
+ }
+
+ const unsigned char grayed_alpha = col[3] / 2;
+
+ /* For vertical lines between objects. */
+ y1 = y2 = *starty;
for (te = lb->first; te; te = te->next) {
- y2 = *starty;
+ bool draw_childs_grayed_out = draw_grayed_out || (te->drag_data != NULL);
tselem = TREESTORE(te);
-
- /* horizontal line? */
- if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE))
- glRecti(startx, *starty, startx + UI_UNIT_X, *starty - 1);
-
+
+ if (draw_childs_grayed_out) {
+ immUniformColor3ubvAlpha(col, grayed_alpha);
+ }
+ else {
+ immUniformColor4ubv(col);
+ }
+
+ /* Horizontal Line? */
+ if (tselem->type == 0 && (te->idcode == ID_OB || te->idcode == ID_SCE)) {
+ immRecti(pos, startx, *starty, startx + UI_UNIT_X, *starty - 1);
+
+ /* Vertical Line? */
+ if (te->idcode == ID_OB) {
+ te_vertical_line_last = te;
+ y2 = *starty;
+ }
+ }
+
*starty -= UI_UNIT_Y;
if (TSELEM_OPEN(tselem, soops))
- outliner_draw_hierarchy(soops, &te->subtree, startx + UI_UNIT_X, starty);
+ outliner_draw_hierarchy_lines_recursive(pos, soops, &te->subtree, startx + UI_UNIT_X,
+ col, draw_childs_grayed_out, starty);
}
-
- /* vertical line */
- te = lb->last;
- if (te->parent || lb->first != lb->last) {
- tselem = TREESTORE(te);
- if (tselem->type == 0 && te->idcode == ID_OB) {
-
- glRecti(startx, y1 + UI_UNIT_Y, startx + 1, y2);
- }
+
+ if (draw_grayed_out) {
+ immUniformColor3ubvAlpha(col, grayed_alpha);
+ }
+ else {
+ immUniformColor4ubv(col);
+ }
+
+ /* Vertical line. */
+ te = te_vertical_line_last;
+ if ((te != NULL) && (te->parent || lb->first != lb->last)) {
+ immRecti(pos, startx, y1 + UI_UNIT_Y, startx + 1, y2);
}
}
+static void outliner_draw_hierarchy_lines(SpaceOops *soops, ListBase *lb, int startx, int *starty)
+{
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ unsigned char col[4];
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ UI_GetThemeColorBlend3ubv(TH_BACK, TH_TEXT, 0.4f, col);
+ col[3] = 255;
+
+ glEnable(GL_BLEND);
+ outliner_draw_hierarchy_lines_recursive(pos, soops, lb, startx, col, false, starty);
+ glDisable(GL_BLEND);
+
+ immUnbindProgram();
+}
+
static void outliner_draw_struct_marks(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty)
{
TreeElement *te;
TreeStoreElem *tselem;
-
+
for (te = lb->first; te; te = te->next) {
tselem = TREESTORE(te);
/* selection status */
if (TSELEM_OPEN(tselem, soops))
- if (tselem->type == TSE_RNA_STRUCT)
- glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
+ if (tselem->type == TSE_RNA_STRUCT) {
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immThemeColorShadeAlpha(TH_BACK, -15, -200);
+ immRecti(pos, 0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
+ immUnbindProgram();
+ }
*starty -= UI_UNIT_Y;
if (TSELEM_OPEN(tselem, soops)) {
outliner_draw_struct_marks(ar, soops, &te->subtree, starty);
- if (tselem->type == TSE_RNA_STRUCT)
- fdrawline(0, (float)*starty + UI_UNIT_Y, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
+ if (tselem->type == TSE_RNA_STRUCT) {
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immThemeColorShadeAlpha(TH_BACK, -15, -200);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, 0, (float)*starty + UI_UNIT_Y);
+ immVertex2f(pos, ar->v2d.cur.xmax, (float)*starty + UI_UNIT_Y);
+ immEnd();
+
+ immUnbindProgram();
+ }
}
}
}
-static void outliner_draw_selection(ARegion *ar, SpaceOops *soops, ListBase *lb, int *starty)
+static void outliner_draw_highlights_recursive(
+ unsigned pos, const ARegion *ar, const SpaceOops *soops, const ListBase *lb,
+ const float col_selection[4], const float col_highlight[4], const float col_searchmatch[4],
+ int start_x, int *io_start_y)
{
- TreeElement *te;
- TreeStoreElem *tselem;
-
- for (te = lb->first; te; te = te->next) {
- tselem = TREESTORE(te);
-
+ const bool is_searching = SEARCHING_OUTLINER(soops) ||
+ (soops->outlinevis == SO_DATABLOCKS &&
+ (soops->filter & SO_FILTER_SEARCH) &&
+ soops->search_string[0] != 0);
+
+ for (TreeElement *te = lb->first; te; te = te->next) {
+ const TreeStoreElem *tselem = TREESTORE(te);
+ const int start_y = *io_start_y;
+
/* selection status */
if (tselem->flag & TSE_SELECTED) {
- glRecti(0, *starty + 1, (int)ar->v2d.cur.xmax, *starty + UI_UNIT_Y - 1);
+ immUniformColor4fv(col_selection);
+ immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
+ }
+
+ /* search match highlights
+ * we don't expand items when searching in the datablocks but we
+ * still want to highlight any filter matches. */
+ if (is_searching && (tselem->flag & TSE_SEARCHMATCH)) {
+ immUniformColor4fv(col_searchmatch);
+ immRecti(pos, start_x, start_y + 1, ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
+ }
+
+ /* mouse hover highlights */
+ if ((tselem->flag & TSE_HIGHLIGHTED) || (te->drag_data != NULL)) {
+ immUniformColor4fv(col_highlight);
+ immRecti(pos, 0, start_y + 1, (int)ar->v2d.cur.xmax, start_y + UI_UNIT_Y - 1);
+ }
+
+ *io_start_y -= UI_UNIT_Y;
+ if (TSELEM_OPEN(tselem, soops)) {
+ outliner_draw_highlights_recursive(
+ pos, ar, soops, &te->subtree, col_selection, col_highlight, col_searchmatch,
+ start_x + UI_UNIT_X, io_start_y);
}
- *starty -= UI_UNIT_Y;
- if (TSELEM_OPEN(tselem, soops)) outliner_draw_selection(ar, soops, &te->subtree, starty);
}
}
+static void outliner_draw_highlights(ARegion *ar, SpaceOops *soops, int startx, int *starty)
+{
+ const float col_highlight[4] = {1.0f, 1.0f, 1.0f, 0.13f};
+ float col_selection[4], col_searchmatch[4];
+
+ UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col_selection);
+ col_selection[3] = 1.0f; /* no alpha */
+ UI_GetThemeColor4fv(TH_MATCH, col_searchmatch);
+ col_searchmatch[3] = 0.5f;
+
+ glEnable(GL_BLEND);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ outliner_draw_highlights_recursive(pos, ar, soops, &soops->tree, col_selection, col_highlight, col_searchmatch,
+ startx, starty);
+ immUnbindProgram();
+ glDisable(GL_BLEND);
+}
-static void outliner_draw_tree(bContext *C, uiBlock *block, Scene *scene, ARegion *ar,
- SpaceOops *soops, TreeElement **te_edit)
+static void outliner_draw_tree(
+ bContext *C, uiBlock *block, Scene *scene, ViewLayer *view_layer, Object *obedit,
+ ARegion *ar, SpaceOops *soops, const bool has_restrict_icons,
+ TreeElement **te_edit)
{
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
- TreeElement *te;
+ TreeElement *te_floating = NULL;
int starty, startx;
- float col[3];
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); // only once
-
- if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA); // only once
+
+ if (soops->outlinevis == SO_DATABLOCKS) {
/* struct marks */
- UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
- //UI_ThemeColorShade(TH_BACK, -20);
starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
outliner_draw_struct_marks(ar, soops, &soops->tree, &starty);
}
-
- /* always draw selection fill before hierarchy */
- UI_GetThemeColor3fv(TH_SELECT_HIGHLIGHT, col);
- glColor3fv(col);
+
+ /* draw highlights before hierarchy */
starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
- outliner_draw_selection(ar, soops, &soops->tree, &starty);
-
+ startx = 0;
+ outliner_draw_highlights(ar, soops, startx, &starty);
+
+ /* set scissor so tree elements or lines can't overlap restriction icons */
+ GLfloat scissor[4] = {0};
+ if (has_restrict_icons) {
+ int mask_x = BLI_rcti_size_x(&ar->v2d.mask) - (int)OL_TOGW + 1;
+ CLAMP_MIN(mask_x, 0);
+
+ glGetFloatv(GL_SCISSOR_BOX, scissor);
+ glScissor(0, 0, mask_x, ar->winy);
+ }
+
// gray hierarchy lines
- UI_ThemeColorBlend(TH_BACK, TH_TEXT, 0.4f);
+
starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y / 2 - OL_Y_OFFSET;
startx = UI_UNIT_X / 2 - 1.0f;
- outliner_draw_hierarchy(soops, &soops->tree, startx, &starty);
-
+ outliner_draw_hierarchy_lines(soops, &soops->tree, startx, &starty);
+
// items themselves
starty = (int)ar->v2d.tot.ymax - UI_UNIT_Y - OL_Y_OFFSET;
startx = 0;
- for (te = soops->tree.first; te; te = te->next) {
- outliner_draw_tree_element(C, block, fstyle, scene, ar, soops, te, startx, &starty, te_edit);
+ for (TreeElement *te = soops->tree.first; te; te = te->next) {
+ outliner_draw_tree_element(
+ C, block, fstyle, scene, view_layer, obedit,
+ ar, soops, te, te->drag_data != NULL,
+ startx, &starty, te_edit, &te_floating);
+ }
+ if (te_floating && te_floating->drag_data->insert_handle) {
+ outliner_draw_tree_element_floating(ar, te_floating);
+ }
+
+ if (has_restrict_icons) {
+ /* reset scissor */
+ glScissor(UNPACK4(scissor));
}
}
@@ -1774,53 +1821,57 @@ static void outliner_back(ARegion *ar)
{
int ystart;
- UI_ThemeColorShade(TH_BACK, 6);
ystart = (int)ar->v2d.tot.ymax;
ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
-
- while (ystart + 2 * UI_UNIT_Y > ar->v2d.cur.ymin) {
- glRecti(0, ystart, (int)ar->v2d.cur.xmax, ystart + UI_UNIT_Y);
- ystart -= 2 * UI_UNIT_Y;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShade(TH_BACK, 6);
+
+ const float x1 = 0.0f, x2 = ar->v2d.cur.xmax;
+ float y1 = ystart, y2;
+ int tot = (int)floor(ystart - ar->v2d.cur.ymin + 2 * UI_UNIT_Y) / (2 * UI_UNIT_Y);
+
+ if (tot > 0) {
+ immBegin(GWN_PRIM_TRIS, 6 * tot);
+ while (tot--) {
+ y1 -= 2 * UI_UNIT_Y;
+ y2 = y1 + UI_UNIT_Y;
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x2, y1);
+ immVertex2f(pos, x2, y2);
+
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x2, y2);
+ immVertex2f(pos, x1, y2);
+ }
+ immEnd();
}
+ immUnbindProgram();
}
static void outliner_draw_restrictcols(ARegion *ar)
{
- int ystart;
-
- /* background underneath */
- UI_ThemeColor(TH_BACK);
- glRecti((int)(ar->v2d.cur.xmax - OL_TOGW),
- (int)(ar->v2d.cur.ymin - 1), (int)ar->v2d.cur.xmax, (int)ar->v2d.cur.ymax);
-
- UI_ThemeColorShade(TH_BACK, 6);
- ystart = (int)ar->v2d.tot.ymax;
- ystart = UI_UNIT_Y * (ystart / (UI_UNIT_Y)) - OL_Y_OFFSET;
-
- while (ystart + 2 * UI_UNIT_Y > ar->v2d.cur.ymin) {
- glRecti((int)ar->v2d.cur.xmax - OL_TOGW, ystart, (int)ar->v2d.cur.xmax, ystart + UI_UNIT_Y);
- ystart -= 2 * UI_UNIT_Y;
- }
-
- UI_ThemeColorShadeAlpha(TH_BACK, -15, -200);
-
- /* view */
- sdrawline((int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX),
- (int)ar->v2d.cur.ymax,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX),
- (int)ar->v2d.cur.ymin);
-
- /* render */
- sdrawline((int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX),
- (int)ar->v2d.cur.ymax,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX),
- (int)ar->v2d.cur.ymin);
-
- /* render */
- sdrawline((int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX),
- (int)ar->v2d.cur.ymax,
- (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX),
- (int)ar->v2d.cur.ymin);
+ glLineWidth(1.0f);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColorShadeAlpha(TH_BACK, -15, -200);
+ immBegin(GWN_PRIM_LINES, 6);
+
+ immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymax);
+ immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX), (int)ar->v2d.cur.ymin);
+
+ immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymax);
+ immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_SELECTX), (int)ar->v2d.cur.ymin);
+
+ immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymax);
+ immVertex2i(pos, (int)(ar->v2d.cur.xmax - OL_TOG_RESTRICT_RENDERX), (int)ar->v2d.cur.ymin);
+
+ immEnd();
+ immUnbindProgram();
}
/* ****************************************************** */
@@ -1830,19 +1881,22 @@ void draw_outliner(const bContext *C)
{
Main *mainvar = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
ARegion *ar = CTX_wm_region(C);
View2D *v2d = &ar->v2d;
SpaceOops *soops = CTX_wm_space_outliner(C);
uiBlock *block;
int sizey = 0, sizex = 0, sizex_rna = 0;
TreeElement *te_edit = NULL;
+ bool has_restrict_icons;
- outliner_build_tree(mainvar, scene, soops); // always
+ outliner_build_tree(mainvar, scene, view_layer, soops, ar); // always
/* get extents of data */
outliner_height(soops, &soops->tree, &sizey);
- if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+ if (soops->outlinevis == SO_DATABLOCKS) {
/* RNA has two columns:
* - column 1 is (max_width + OL_RNA_COL_SPACEX) or
* (OL_RNA_COL_X), whichever is wider...
@@ -1857,6 +1911,7 @@ void draw_outliner(const bContext *C)
/* get width of data (for setting 'tot' rect, this is column 1 + column 2 + a bit extra) */
sizex = sizex_rna + OL_RNA_COL_SIZEX + 50;
+ has_restrict_icons = false;
}
else {
/* width must take into account restriction columns (if visible) so that entries will still be visible */
@@ -1866,9 +1921,11 @@ void draw_outliner(const bContext *C)
/* constant offset for restriction columns */
// XXX this isn't that great yet...
- if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0)
+ if ((soops->flag & SO_HIDE_RESTRICTCOLS) == 0) {
sizex += OL_TOGW * 3;
-
+ }
+
+ has_restrict_icons = !(soops->flag & SO_HIDE_RESTRICTCOLS);
}
/* adds vertical offset */
@@ -1885,19 +1942,21 @@ void draw_outliner(const bContext *C)
/* draw outliner stuff (background, hierarchy lines and names) */
outliner_back(ar);
block = UI_block_begin(C, ar, __func__, UI_EMBOSS);
- outliner_draw_tree((bContext *)C, block, scene, ar, soops, &te_edit);
-
- if (ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF)) {
+ outliner_draw_tree(
+ (bContext *)C, block, scene, view_layer, obedit,
+ ar, soops, has_restrict_icons, &te_edit);
+
+ if (soops->outlinevis == SO_DATABLOCKS) {
/* draw rna buttons */
outliner_draw_rnacols(ar, sizex_rna);
outliner_draw_rnabuts(block, ar, soops, sizex_rna, &soops->tree);
}
- else if ((soops->outlinevis == SO_ID_ORPHANS) && !(soops->flag & SO_HIDE_RESTRICTCOLS)) {
+ else if ((soops->outlinevis == SO_ID_ORPHANS) && has_restrict_icons) {
/* draw user toggle columns */
outliner_draw_restrictcols(ar);
outliner_draw_userbuts(block, ar, soops, &soops->tree);
}
- else if (!(soops->flag & SO_HIDE_RESTRICTCOLS)) {
+ else if (has_restrict_icons) {
/* draw restriction columns */
outliner_draw_restrictcols(ar);
outliner_draw_restrictbuts(block, scene, ar, soops, &soops->tree);
diff --git a/source/blender/editors/space_outliner/outliner_edit.c b/source/blender/editors/space_outliner/outliner_edit.c
index 71edd855cf0..2447a7e4a60 100644
--- a/source/blender/editors/space_outliner/outliner_edit.c
+++ b/source/blender/editors/space_outliner/outliner_edit.c
@@ -51,8 +51,8 @@
#include "BKE_animsys.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_idcode.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
@@ -63,6 +63,8 @@
#include "BKE_material.h"
#include "BKE_group.h"
+#include "DEG_depsgraph_build.h"
+
#include "../blenloader/BLO_readfile.h"
#include "ED_object.h"
@@ -147,8 +149,46 @@ TreeElement *outliner_dropzone_find(const SpaceOops *soops, const float fmval[2]
return NULL;
}
+
/* ************************************************************** */
-/* Click Activated */
+
+/* Highlight --------------------------------------------------- */
+
+static int outliner_highlight_update(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+{
+ ARegion *ar = CTX_wm_region(C);
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ const float my = UI_view2d_region_to_view_y(&ar->v2d, event->mval[1]);
+
+ TreeElement *hovered_te = outliner_find_item_at_y(soops, &soops->tree, my);
+ bool changed = false;
+
+ if (!hovered_te || !(hovered_te->store_elem->flag & TSE_HIGHLIGHTED)) {
+ changed = outliner_set_flag(&soops->tree, TSE_HIGHLIGHTED, false);
+ if (hovered_te) {
+ hovered_te->store_elem->flag |= TSE_HIGHLIGHTED;
+ changed = true;
+ }
+ }
+
+ if (changed) {
+ soops->storeflag |= SO_TREESTORE_REDRAW; /* only needs to redraw, no rebuild */
+ ED_region_tag_redraw(ar);
+ }
+
+ return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH);
+}
+
+void OUTLINER_OT_highlight_update(wmOperatorType *ot)
+{
+ ot->name = "Update Highlight";
+ ot->idname = "OUTLINER_OT_highlight_update";
+ ot->description = "Update the item highlight based on the current mouse position";
+
+ ot->invoke = outliner_highlight_update;
+
+ ot->poll = ED_operator_outliner_active;
+}
/* Toggle Open/Closed ------------------------------------------- */
@@ -215,20 +255,35 @@ void OUTLINER_OT_item_openclose(wmOperatorType *ot)
/* Rename --------------------------------------------------- */
-static void do_item_rename(ARegion *ar, TreeElement *te, TreeStoreElem *tselem, ReportList *reports)
+static void do_item_rename(const Scene *scene, ARegion *ar, TreeElement *te, TreeStoreElem *tselem,
+ ReportList *reports)
{
+ bool add_textbut = false;
+
/* can't rename rna datablocks entries or listbases */
- if (ELEM(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE)) {
+ if (ELEM(tselem->type, TSE_RNA_STRUCT, TSE_RNA_PROPERTY, TSE_RNA_ARRAY_ELEM, TSE_ID_BASE, TSE_SCENE_OBJECTS_BASE)) {
/* do nothing */;
}
else if (ELEM(tselem->type, TSE_ANIM_DATA, TSE_NLA, TSE_DEFGROUP_BASE, TSE_CONSTRAINT_BASE, TSE_MODIFIER_BASE,
- TSE_DRIVER_BASE, TSE_POSE_BASE, TSE_POSEGRP_BASE, TSE_R_LAYER_BASE, TSE_R_PASS))
+ TSE_DRIVER_BASE, TSE_POSE_BASE, TSE_POSEGRP_BASE, TSE_R_LAYER_BASE))
{
BKE_report(reports, RPT_WARNING, "Cannot edit builtin name");
}
else if (ELEM(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP)) {
BKE_report(reports, RPT_WARNING, "Cannot edit sequence name");
}
+ else if (ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION)) {
+ SceneCollection *master = BKE_collection_master(&scene->id);
+
+ if ((tselem->type == TSE_SCENE_COLLECTION && te->directdata == master) ||
+ (((LayerCollection *)te->directdata)->scene_collection == master))
+ {
+ BKE_report(reports, RPT_WARNING, "Cannot edit name of master collection");
+ }
+ else {
+ add_textbut = true;
+ }
+ }
else if (ID_IS_LINKED(tselem->id)) {
BKE_report(reports, RPT_WARNING, "Cannot edit external libdata");
}
@@ -236,34 +291,39 @@ static void do_item_rename(ARegion *ar, TreeElement *te, TreeStoreElem *tselem,
BKE_report(reports, RPT_WARNING, "Cannot edit the path of an indirectly linked library");
}
else {
+ add_textbut = true;
+ }
+
+ if (add_textbut) {
tselem->flag |= TSE_TEXTBUT;
ED_region_tag_redraw(ar);
}
}
void item_rename_cb(
- bContext *C, ReportList *reports, Scene *UNUSED(scene), TreeElement *te,
+ bContext *C, ReportList *reports, Scene *scene, TreeElement *te,
TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
{
ARegion *ar = CTX_wm_region(C);
- do_item_rename(ar, te, tselem, reports);
+ do_item_rename(scene, ar, te, tselem, reports);
}
-static int do_outliner_item_rename(ReportList *reports, ARegion *ar, TreeElement *te, const float mval[2])
+static int do_outliner_item_rename(const Scene *scene, ReportList *reports, ARegion *ar, TreeElement *te,
+ const float mval[2])
{
if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
TreeStoreElem *tselem = TREESTORE(te);
/* click on name */
if (mval[0] > te->xs + UI_UNIT_X * 2 && mval[0] < te->xend) {
- do_item_rename(ar, te, tselem, reports);
+ do_item_rename(scene, ar, te, tselem, reports);
return 1;
}
return 0;
}
for (te = te->subtree.first; te; te = te->next) {
- if (do_outliner_item_rename(reports, ar, te, mval)) return 1;
+ if (do_outliner_item_rename(scene, reports, ar, te, mval)) return 1;
}
return 0;
}
@@ -279,7 +339,7 @@ static int outliner_item_rename(bContext *C, wmOperator *op, const wmEvent *even
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
for (te = soops->tree.first; te; te = te->next) {
- if (do_outliner_item_rename(op->reports, ar, te, fmval)) {
+ if (do_outliner_item_rename(CTX_data_scene(C), op->reports, ar, te, fmval)) {
changed = true;
break;
}
@@ -402,7 +462,6 @@ void OUTLINER_OT_id_delete(wmOperatorType *ot)
static int outliner_id_remap_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
SpaceOops *soops = CTX_wm_space_outliner(C);
const short id_type = (short)RNA_enum_get(op->ptr, "id_type");
@@ -432,7 +491,7 @@ static int outliner_id_remap_exec(bContext *C, wmOperator *op)
BKE_main_lib_objects_recalc_all(bmain);
/* recreate dependency graph to include new objects */
- DAG_scene_relations_rebuild(bmain, scene);
+ DEG_relations_tag_update(bmain);
/* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */
GPU_materials_free();
@@ -743,17 +802,34 @@ int outliner_has_one_flag(ListBase *lb, short flag, const int curlevel)
return 0;
}
-void outliner_set_flag(ListBase *lb, short flag, short set)
+/**
+ * Set or unset \a flag for all outliner elements in \a lb and sub-trees.
+ * \return if any flag was modified.
+ */
+bool outliner_set_flag(ListBase *lb, short flag, short set)
{
TreeElement *te;
TreeStoreElem *tselem;
-
+ bool changed = false;
+ bool has_flag;
+
for (te = lb->first; te; te = te->next) {
tselem = TREESTORE(te);
- if (set == 0) tselem->flag &= ~flag;
- else tselem->flag |= flag;
- outliner_set_flag(&te->subtree, flag, set);
+ has_flag = (tselem->flag & flag);
+ if (set == 0) {
+ if (has_flag) {
+ tselem->flag &= ~flag;
+ changed = true;
+ }
+ }
+ else if (!has_flag) {
+ tselem->flag |= flag;
+ changed = true;
+ }
+ changed |= outliner_set_flag(&te->subtree, flag, set);
}
+
+ return changed;
}
/* Restriction Columns ------------------------------- */
@@ -781,181 +857,6 @@ int common_restrict_check(bContext *C, Object *ob)
}
/* =============================================== */
-/* Restriction toggles */
-
-/* Toggle Visibility ---------------------------------------- */
-
-void object_toggle_visibility_cb(
- bContext *C, ReportList *reports, Scene *scene, TreeElement *te,
- TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
-{
- Base *base = (Base *)te->directdata;
- Object *ob = (Object *)tselem->id;
-
- if (ID_IS_LINKED(tselem->id)) {
- BKE_report(reports, RPT_WARNING, "Cannot edit external libdata");
- return;
- }
-
- /* add check for edit mode */
- if (!common_restrict_check(C, ob)) return;
-
- if (base || (base = BKE_scene_base_find(scene, ob))) {
- if ((base->object->restrictflag ^= OB_RESTRICT_VIEW)) {
- ED_base_object_select(base, BA_DESELECT);
- }
- }
-}
-
-void group_toggle_visibility_cb(
- bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te),
- TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
-{
- Group *group = (Group *)tselem->id;
- restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_VIEW);
-}
-
-static int outliner_toggle_visibility_exec(bContext *C, wmOperator *op)
-{
- Main *bmain = CTX_data_main(C);
- SpaceOops *soops = CTX_wm_space_outliner(C);
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
-
- outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_visibility_cb);
-
- DAG_id_type_tag(bmain, ID_OB);
- WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene);
- ED_region_tag_redraw(ar);
-
- return OPERATOR_FINISHED;
-}
-
-void OUTLINER_OT_visibility_toggle(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Toggle Visibility";
- ot->idname = "OUTLINER_OT_visibility_toggle";
- ot->description = "Toggle the visibility of selected items";
-
- /* callbacks */
- ot->exec = outliner_toggle_visibility_exec;
- ot->poll = ED_operator_outliner_active_no_editobject;
-
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/* Toggle Selectability ---------------------------------------- */
-
-void object_toggle_selectability_cb(
- bContext *UNUSED(C), ReportList *reports, Scene *scene, TreeElement *te,
- TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
-{
- Base *base = (Base *)te->directdata;
-
- if (ID_IS_LINKED(tselem->id)) {
- BKE_report(reports, RPT_WARNING, "Cannot edit external libdata");
- return;
- }
-
- if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
- if (base) {
- base->object->restrictflag ^= OB_RESTRICT_SELECT;
- }
-}
-
-void group_toggle_selectability_cb(
- bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te),
- TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
-{
- Group *group = (Group *)tselem->id;
- restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_SELECT);
-}
-
-static int outliner_toggle_selectability_exec(bContext *C, wmOperator *op)
-{
- SpaceOops *soops = CTX_wm_space_outliner(C);
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
-
- outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_selectability_cb);
-
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
- ED_region_tag_redraw(ar);
-
- return OPERATOR_FINISHED;
-}
-
-void OUTLINER_OT_selectability_toggle(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Toggle Selectability";
- ot->idname = "OUTLINER_OT_selectability_toggle";
- ot->description = "Toggle the selectability";
-
- /* callbacks */
- ot->exec = outliner_toggle_selectability_exec;
- ot->poll = ED_operator_outliner_active_no_editobject;
-
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/* Toggle Renderability ---------------------------------------- */
-
-void object_toggle_renderability_cb(
- bContext *UNUSED(C), ReportList *reports, Scene *scene, TreeElement *te,
- TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
-{
- Base *base = (Base *)te->directdata;
-
- if (ID_IS_LINKED(tselem->id)) {
- BKE_report(reports, RPT_WARNING, "Cannot edit external libdata");
- return;
- }
-
- if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
- if (base) {
- base->object->restrictflag ^= OB_RESTRICT_RENDER;
- }
-}
-
-void group_toggle_renderability_cb(
- bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te),
- TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
-{
- Group *group = (Group *)tselem->id;
- restrictbutton_gr_restrict_flag(scene, group, OB_RESTRICT_RENDER);
-}
-
-static int outliner_toggle_renderability_exec(bContext *C, wmOperator *op)
-{
- Main *bmain = CTX_data_main(C);
- SpaceOops *soops = CTX_wm_space_outliner(C);
- Scene *scene = CTX_data_scene(C);
-
- outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_renderability_cb);
-
- DAG_id_type_tag(bmain, ID_OB);
- WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene);
-
- return OPERATOR_FINISHED;
-}
-
-void OUTLINER_OT_renderability_toggle(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Toggle Renderability";
- ot->idname = "OUTLINER_OT_renderability_toggle";
- ot->description = "Toggle the renderability of selected items";
-
- /* callbacks */
- ot->exec = outliner_toggle_renderability_exec;
- ot->poll = ED_operator_outliner_active;
-
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/* =============================================== */
/* Outliner setting toggles */
/* Toggle Expanded (Outliner) ---------------------------------------- */
@@ -1047,7 +948,7 @@ static void outliner_set_coordinates_element_recursive(SpaceOops *soops, TreeEle
}
/* to retrieve coordinates with redrawing the entire tree */
-static void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
+void outliner_set_coordinates(ARegion *ar, SpaceOops *soops)
{
TreeElement *te;
int starty = (int)(ar->v2d.tot.ymax) - UI_UNIT_Y;
@@ -1076,14 +977,14 @@ static int outliner_open_back(TreeElement *te)
static int outliner_show_active_exec(bContext *C, wmOperator *UNUSED(op))
{
SpaceOops *so = CTX_wm_space_outliner(C);
- Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
ARegion *ar = CTX_wm_region(C);
View2D *v2d = &ar->v2d;
TreeElement *te;
int xdelta, ytop;
- Object *obact = OBACT;
+ Object *obact = OBACT(view_layer);
if (!obact)
return OPERATOR_CANCELLED;
@@ -2001,9 +1902,9 @@ static int parent_drop_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
- ED_object_parent_set(op->reports, bmain, scene, ob, par, partype, false, false, NULL);
+ ED_object_parent_set(op->reports, C, scene, ob, par, partype, false, false, NULL);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
@@ -2019,6 +1920,7 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Main *bmain = CTX_data_main(C);
Scene *scene = NULL;
TreeElement *te = NULL;
+ TreeStoreElem *tselem;
char childname[MAX_ID_NAME];
char parname[MAX_ID_NAME];
int partype = 0;
@@ -2028,8 +1930,21 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
/* Find object hovered over */
te = outliner_dropzone_find(soops, fmval, true);
+ tselem = te ? TREESTORE(te) : NULL;
- if (te) {
+ if (tselem && ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION)) {
+ SceneCollection *sc = outliner_scene_collection_from_tree_element(te);
+
+ scene = BKE_scene_find_from_collection(bmain, sc);
+ BLI_assert(scene);
+ RNA_string_get(op->ptr, "child", childname);
+ ob = (Object *)BKE_libblock_find_name(ID_OB, childname);
+ BKE_collection_object_add(&scene->id, sc, ob);
+
+ DEG_relations_tag_update(bmain);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ }
+ else if (te) {
RNA_string_set(op->ptr, "parent", te->name);
/* Identify parent and child */
RNA_string_get(op->ptr, "child", childname);
@@ -2061,8 +1976,8 @@ static int parent_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
}
if ((par->type != OB_ARMATURE) && (par->type != OB_CURVE) && (par->type != OB_LATTICE)) {
- if (ED_object_parent_set(op->reports, bmain, scene, ob, par, partype, false, false, NULL)) {
- DAG_relations_tag_update(bmain);
+ if (ED_object_parent_set(op->reports, C, scene, ob, par, partype, false, false, NULL)) {
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
}
@@ -2169,7 +2084,14 @@ static int outliner_parenting_poll(bContext *C)
SpaceOops *soops = CTX_wm_space_outliner(C);
if (soops) {
- return ELEM(soops->outlinevis, SO_ALL_SCENES, SO_CUR_SCENE, SO_VISIBLE, SO_GROUPS);
+ if (soops->outlinevis == SO_SCENES) {
+ return true;
+ }
+
+ if (soops->outlinevis == SO_COLLECTIONS) {
+ return ((soops->filter & SO_FILTER_ENABLE) &&
+ (soops->filter & SO_FILTER_NO_COLLECTION));
+ }
}
return false;
@@ -2190,7 +2112,7 @@ static int parent_clear_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
ED_object_parent_clear(ob, RNA_enum_get(op->ptr, "type"));
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, NULL);
WM_event_add_notifier(C, NC_OBJECT | ND_PARENT, NULL);
return OPERATOR_FINISHED;
@@ -2233,8 +2155,6 @@ static int scene_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
te = outliner_dropzone_find(soops, fmval, false);
if (te) {
- Base *base;
-
RNA_string_set(op->ptr, "scene", te->name);
scene = (Scene *)BKE_libblock_find_name(ID_SCE, te->name);
@@ -2245,19 +2165,29 @@ static int scene_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_CANCELLED;
}
- base = ED_object_scene_link(scene, ob);
-
- if (base == NULL) {
+ if (BKE_scene_has_object(scene, ob)) {
return OPERATOR_CANCELLED;
}
- if (scene == CTX_data_scene(C)) {
- /* when linking to an inactive scene don't touch the layer */
- ob->lay = base->lay;
- ED_base_object_select(base, BA_SELECT);
+ SceneCollection *sc;
+ if (scene != CTX_data_scene(C)) {
+ /* when linking to an inactive scene link to the master collection */
+ sc = BKE_collection_master(&scene->id);
+ }
+ else {
+ sc = CTX_data_scene_collection(C);
+ }
+
+ BKE_collection_object_add(&scene->id, sc, ob);
+
+ for (ViewLayer *view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+ if (base) {
+ ED_object_base_select(base, BA_SELECT);
+ }
}
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, scene);
@@ -2349,7 +2279,6 @@ static int group_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
Main *bmain = CTX_data_main(C);
Group *group = NULL;
Object *ob = NULL;
- Scene *scene = CTX_data_scene(C);
SpaceOops *soops = CTX_wm_space_outliner(C);
ARegion *ar = CTX_wm_region(C);
TreeElement *te = NULL;
@@ -2379,7 +2308,7 @@ static int group_link_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_CANCELLED;
}
- BKE_group_object_add(group, ob, scene, NULL);
+ BKE_group_object_add(group, ob);
WM_event_add_notifier(C, NC_OBJECT | ND_DRAW, ob);
return OPERATOR_FINISHED;
diff --git a/source/blender/editors/space_outliner/outliner_intern.h b/source/blender/editors/space_outliner/outliner_intern.h
index ca7dbe4f73c..a0de3a06556 100644
--- a/source/blender/editors/space_outliner/outliner_intern.h
+++ b/source/blender/editors/space_outliner/outliner_intern.h
@@ -36,14 +36,55 @@
/* internal exports only */
+struct ARegion;
+struct ListBase;
struct wmOperatorType;
+struct TreeElement;
struct TreeStoreElem;
+struct Main;
struct bContext;
struct Scene;
+struct ViewLayer;
struct ID;
struct Object;
struct bPoseChannel;
struct EditBone;
+struct wmEvent;
+struct wmKeyConfig;
+
+typedef enum TreeElementInsertType {
+ TE_INSERT_BEFORE,
+ TE_INSERT_AFTER,
+ TE_INSERT_INTO,
+} TreeElementInsertType;
+
+typedef enum TreeTraversalAction {
+ /* Continue traversal regularly, don't skip children. */
+ TRAVERSE_CONTINUE = 0,
+ /* Stop traversal */
+ TRAVERSE_BREAK,
+ /* Continue traversal, but skip childs of traversed element */
+ TRAVERSE_SKIP_CHILDS,
+} TreeTraversalAction;
+
+/**
+ * Callback type for reinserting elements at a different position, used to allow user customizable element order.
+ */
+typedef void (*TreeElementReinsertFunc)(struct Main *bmain,
+ struct SpaceOops *soops,
+ struct TreeElement *insert_element,
+ struct TreeElement *insert_handle,
+ TreeElementInsertType action,
+ const struct wmEvent *event);
+/**
+ * Executed on (almost) each mouse move while dragging. It's supposed to give info
+ * if reinserting insert_element before/after/into insert_handle would be allowed.
+ * It's allowed to change the reinsert info here for non const pointers.
+ */
+typedef bool (*TreeElementReinsertPollFunc)(const struct TreeElement *insert_element,
+ struct TreeElement **io_insert_handle, TreeElementInsertType *io_action);
+typedef TreeTraversalAction (*TreeTraversalFunc)(struct TreeElement *te, void *customdata);
+
typedef struct TreeElement {
struct TreeElement *next, *prev, *parent;
@@ -57,18 +98,33 @@ typedef struct TreeElement {
const char *name;
void *directdata; // Armature Bones, Base, Sequence, Strip...
PointerRNA rnaptr; // RNA Pointer
-} TreeElement;
+
+ /* callbacks - TODO should be moved into a type (like TreeElementType) */
+ TreeElementReinsertFunc reinsert;
+ TreeElementReinsertPollFunc reinsert_poll;
+
+ struct {
+ TreeElementInsertType insert_type;
+ /* the element before/after/into which we may insert the dragged one (NULL to insert at top) */
+ struct TreeElement *insert_handle;
+ void *tooltip_draw_handle;
+ } *drag_data;
+} TreeElement;
#define TREESTORE_ID_TYPE(_id) \
(ELEM(GS((_id)->name), ID_SCE, ID_LI, ID_OB, ID_ME, ID_CU, ID_MB, ID_NT, ID_MA, ID_TE, ID_IM, ID_LT, ID_LA, ID_CA) || \
- ELEM(GS((_id)->name), ID_KE, ID_WO, ID_SPK, ID_GR, ID_AR, ID_AC, ID_BR, ID_PA, ID_GD, ID_LS) || \
- ELEM(GS((_id)->name), ID_SCR, ID_WM, ID_TXT, ID_VF, ID_SO, ID_CF, ID_PAL)) /* Only in 'blendfile' mode ... :/ */
+ ELEM(GS((_id)->name), ID_KE, ID_WO, ID_SPK, ID_GR, ID_AR, ID_AC, ID_BR, ID_PA, ID_GD, ID_LS, ID_LP) || \
+ ELEM(GS((_id)->name), ID_SCR, ID_WM, ID_TXT, ID_VF, ID_SO, ID_CF, ID_PAL, ID_WS)) /* Only in 'blendfile' mode ... :/ */
/* TreeElement->flag */
-#define TE_ACTIVE 1
-#define TE_ICONROW 2
-#define TE_LAZY_CLOSED 4
-#define TE_FREE_NAME 8
+enum {
+ TE_ACTIVE = (1 << 0),
+ /* Closed items display their children as icon within the row. TE_ICONROW is for
+ * these child-items that are visible but only within the row of the closed parent. */
+ TE_ICONROW = (1 << 1),
+ TE_LAZY_CLOSED = (1 << 2),
+ TE_FREE_NAME = (1 << 3),
+};
/* button events */
#define OL_NAMEBUTTON 1
@@ -103,6 +159,9 @@ typedef enum {
#define OL_RNA_COL_SIZEX (UI_UNIT_X * 7.5f)
#define OL_RNA_COL_SPACEX (UI_UNIT_X * 2.5f)
+/* The outliner display modes that support the filter system.
+ * Note: keep it synced with space_outliner.py */
+#define SUPPORT_FILTER_OUTLINER(soops_) ((soops_)->outlinevis == SO_COLLECTIONS)
/* Outliner Searching --
*
@@ -120,24 +179,28 @@ typedef enum {
* - not searching into RNA items helps but isn't the complete solution
*/
-#define SEARCHING_OUTLINER(sov) (sov->search_flags & SO_SEARCH_RECURSIVE)
+#define SEARCHING_OUTLINER(sov) ((sov->search_flags & SO_SEARCH_RECURSIVE) && (sov->filter & SO_FILTER_SEARCH))
/* is the currrent element open? if so we also show children */
#define TSELEM_OPEN(telm, sv) ( (telm->flag & TSE_CLOSED) == 0 || (SEARCHING_OUTLINER(sv) && (telm->flag & TSE_CHILDSEARCH)) )
/* outliner_tree.c ----------------------------------------------- */
-void outliner_free_tree(ListBase *lb);
+void outliner_free_tree(ListBase *tree);
void outliner_cleanup_tree(struct SpaceOops *soops);
+void outliner_free_tree_element(TreeElement *element, ListBase *parent_subtree);
+void outliner_remove_treestore_element(struct SpaceOops *soops, TreeStoreElem *tselem);
-TreeElement *outliner_find_tse(struct SpaceOops *soops, const TreeStoreElem *tse);
-TreeElement *outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem);
-TreeElement *outliner_find_id(struct SpaceOops *soops, ListBase *lb, const struct ID *id);
-TreeElement *outliner_find_posechannel(ListBase *lb, const struct bPoseChannel *pchan);
-TreeElement *outliner_find_editbone(ListBase *lb, const struct EditBone *ebone);
-struct ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode);
+void outliner_build_tree(
+ struct Main *mainvar,
+ struct Scene *scene, struct ViewLayer *view_layer,
+ struct SpaceOops *soops, struct ARegion *ar);
+
+typedef struct ObjectsSelectedData {
+ struct ListBase objects_selected_array;
+} ObjectsSelectedData;
-void outliner_build_tree(struct Main *mainvar, struct Scene *scene, struct SpaceOops *soops);
+TreeTraversalAction outliner_find_selected_objects(struct TreeElement *te, void *customdata);
/* outliner_draw.c ---------------------------------------------- */
@@ -146,9 +209,9 @@ void restrictbutton_gr_restrict_flag(void *poin, void *poin2, int flag);
/* outliner_select.c -------------------------------------------- */
eOLDrawState tree_element_type_active(
- struct bContext *C, struct Scene *scene, struct SpaceOops *soops,
+ struct bContext *C, struct Scene *scene, struct ViewLayer *view_layer, struct SpaceOops *soops,
TreeElement *te, TreeStoreElem *tselem, const eOLSetState set, bool recursive);
-eOLDrawState tree_element_active(struct bContext *C, struct Scene *scene, SpaceOops *soops,
+eOLDrawState tree_element_active(struct bContext *C, struct Scene *scene, struct ViewLayer *view_layer, SpaceOops *soops,
TreeElement *te, const eOLSetState set, const bool handle_all_types);
void outliner_item_do_activate_from_tree_element(
@@ -158,22 +221,26 @@ int outliner_item_do_activate_from_cursor(
struct bContext *C, const int mval[2],
bool extend, bool recursive);
+void outliner_item_select(
+ struct SpaceOops *soops, const struct TreeElement *te,
+ const bool extend, const bool toggle);
+
/* outliner_edit.c ---------------------------------------------- */
typedef void (*outliner_operation_cb)(
struct bContext *C, struct ReportList *, struct Scene *scene,
struct TreeElement *, struct TreeStoreElem *, TreeStoreElem *, void *);
void outliner_do_object_operation_ex(
- struct bContext *C, ReportList *reports, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb,
- outliner_operation_cb operation_cb, bool recurse_selected);
+ struct bContext *C, struct ReportList *reports, struct Scene *scene, struct SpaceOops *soops,
+ struct ListBase *lb, outliner_operation_cb operation_cb, bool recurse_selected);
void outliner_do_object_operation(
- struct bContext *C, ReportList *reports, struct Scene *scene, struct SpaceOops *soops, struct ListBase *lb,
- outliner_operation_cb operation_cb);
+ struct bContext *C, struct ReportList *reports, struct Scene *scene, struct SpaceOops *soops,
+ struct ListBase *lb, outliner_operation_cb operation_cb);
int common_restrict_check(struct bContext *C, struct Object *ob);
int outliner_has_one_flag(ListBase *lb, short flag, const int curlevel);
-void outliner_set_flag(ListBase *lb, short flag, short set);
+bool outliner_set_flag(ListBase *lb, short flag, short set);
void object_toggle_visibility_cb(
struct bContext *C, struct ReportList *reports, struct Scene *scene,
@@ -214,8 +281,13 @@ void id_remap_cb(
struct TreeStoreElem *tsep, struct TreeStoreElem *tselem, void *user_data);
TreeElement *outliner_dropzone_find(const struct SpaceOops *soops, const float fmval[2], const bool children);
+
+void outliner_set_coordinates(struct ARegion *ar, struct SpaceOops *soops);
+
/* ...................................................... */
+void OUTLINER_OT_highlight_update(struct wmOperatorType *ot);
+
void OUTLINER_OT_item_activate(struct wmOperatorType *ot);
void OUTLINER_OT_item_openclose(struct wmOperatorType *ot);
void OUTLINER_OT_item_rename(struct wmOperatorType *ot);
@@ -235,10 +307,6 @@ void OUTLINER_OT_expanded_toggle(struct wmOperatorType *ot);
void OUTLINER_OT_scroll_page(struct wmOperatorType *ot);
-void OUTLINER_OT_renderability_toggle(struct wmOperatorType *ot);
-void OUTLINER_OT_selectability_toggle(struct wmOperatorType *ot);
-void OUTLINER_OT_visibility_toggle(struct wmOperatorType *ot);
-
void OUTLINER_OT_keyingset_add_selected(struct wmOperatorType *ot);
void OUTLINER_OT_keyingset_remove_selected(struct wmOperatorType *ot);
@@ -267,10 +335,45 @@ void OUTLINER_OT_animdata_operation(struct wmOperatorType *ot);
void OUTLINER_OT_action_set(struct wmOperatorType *ot);
void OUTLINER_OT_constraint_operation(struct wmOperatorType *ot);
void OUTLINER_OT_modifier_operation(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_operation(struct wmOperatorType *ot);
/* ---------------------------------------------------------------- */
/* outliner_ops.c */
void outliner_operatortypes(void);
void outliner_keymap(struct wmKeyConfig *keyconf);
+/* outliner_collections.c */
+
+struct SceneCollection *outliner_scene_collection_from_tree_element(TreeElement *te);
+
+void OUTLINER_OT_collections_delete(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_select(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_toggle(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_link(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_unlink(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_new(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_duplicate(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_objects_remove(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_objects_select(struct wmOperatorType *ot);
+void OUTLINER_OT_object_add_to_new_collection(struct wmOperatorType *ot);
+void OUTLINER_OT_object_remove_from_collection(struct wmOperatorType *ot);
+
+void OUTLINER_OT_collection_objects_add(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_nested_new(struct wmOperatorType *ot);
+void OUTLINER_OT_collection_delete_selected(struct wmOperatorType *ot);
+
+/* outliner_utils.c ---------------------------------------------- */
+
+TreeElement *outliner_find_item_at_y(const SpaceOops *soops, const ListBase *tree, float view_co_y);
+TreeElement *outliner_find_item_at_x_in_row(const SpaceOops *soops, const TreeElement *parent_te, float view_co_x);
+TreeElement *outliner_find_tse(struct SpaceOops *soops, const TreeStoreElem *tse);
+TreeElement *outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem);
+TreeElement *outliner_find_id(struct SpaceOops *soops, ListBase *lb, const struct ID *id);
+TreeElement *outliner_find_posechannel(ListBase *lb, const struct bPoseChannel *pchan);
+TreeElement *outliner_find_editbone(ListBase *lb, const struct EditBone *ebone);
+struct ID *outliner_search_back(SpaceOops *soops, TreeElement *te, short idcode);
+bool outliner_tree_traverse(const SpaceOops *soops, ListBase *tree, int filter_te_flag, int filter_tselem_flag,
+ TreeTraversalFunc func, void *customdata);
+
+
#endif /* __OUTLINER_INTERN_H__ */
diff --git a/source/blender/editors/space_outliner/outliner_ops.c b/source/blender/editors/space_outliner/outliner_ops.c
index 776717c8443..2c4670d9ea3 100644
--- a/source/blender/editors/space_outliner/outliner_ops.c
+++ b/source/blender/editors/space_outliner/outliner_ops.c
@@ -28,25 +28,408 @@
* \ingroup spoutliner
*/
-#include "DNA_space_types.h"
+#include "MEM_guardedalloc.h"
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+#include "BLT_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_main.h"
+
+#include "GPU_immediate.h"
#include "RNA_access.h"
+#include "UI_interface.h"
+#include "UI_view2d.h"
+
#include "WM_api.h"
#include "WM_types.h"
+#include "ED_screen.h"
+
#include "outliner_intern.h"
+typedef struct OutlinerDragDropTooltip {
+ TreeElement *te;
+ void *handle;
+} OutlinerDragDropTooltip;
+
+enum {
+ OUTLINER_ITEM_DRAG_CANCEL,
+ OUTLINER_ITEM_DRAG_CONFIRM,
+};
+
+static int outliner_item_drag_drop_poll(bContext *C)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ return ED_operator_outliner_active(C) &&
+ /* Only collection display modes supported for now. Others need more design work */
+ ELEM(soops->outlinevis, SO_COLLECTIONS, SO_GROUPS);
+}
+
+static TreeElement *outliner_item_drag_element_find(SpaceOops *soops, ARegion *ar, const wmEvent *event)
+{
+ /* note: using EVT_TWEAK_ events to trigger dragging is fine,
+ * it sends coordinates from where dragging was started */
+ const float my = UI_view2d_region_to_view_y(&ar->v2d, event->mval[1]);
+ return outliner_find_item_at_y(soops, &soops->tree, my);
+}
+
+static void outliner_item_drag_end(wmWindow *win, OutlinerDragDropTooltip *data)
+{
+ MEM_SAFE_FREE(data->te->drag_data);
+
+ if (data->handle) {
+ WM_draw_cb_exit(win, data->handle);
+ }
+
+ MEM_SAFE_FREE(data);
+}
+
+static void outliner_item_drag_get_insert_data(
+ const SpaceOops *soops, ARegion *ar, const wmEvent *event, TreeElement *te_dragged,
+ TreeElement **r_te_insert_handle, TreeElementInsertType *r_insert_type)
+{
+ TreeElement *te_hovered;
+ float view_mval[2];
+
+ UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &view_mval[0], &view_mval[1]);
+ te_hovered = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]);
+
+ if (te_hovered) {
+ /* mouse hovers an element (ignoring x-axis), now find out how to insert the dragged item exactly */
+
+ if (te_hovered == te_dragged) {
+ *r_te_insert_handle = te_dragged;
+ }
+ else if (te_hovered != te_dragged) {
+ const float margin = UI_UNIT_Y * (1.0f / 4);
+
+ *r_te_insert_handle = te_hovered;
+ if (view_mval[1] < (te_hovered->ys + margin)) {
+ if (TSELEM_OPEN(TREESTORE(te_hovered), soops)) {
+ /* inserting after a open item means we insert into it, but as first child */
+ if (BLI_listbase_is_empty(&te_hovered->subtree)) {
+ *r_insert_type = TE_INSERT_INTO;
+ }
+ else {
+ *r_insert_type = TE_INSERT_BEFORE;
+ *r_te_insert_handle = te_hovered->subtree.first;
+ }
+ }
+ else {
+ *r_insert_type = TE_INSERT_AFTER;
+ }
+ }
+ else if (view_mval[1] > (te_hovered->ys + (3 * margin))) {
+ *r_insert_type = TE_INSERT_BEFORE;
+ }
+ else {
+ *r_insert_type = TE_INSERT_INTO;
+ }
+ }
+ }
+ else {
+ /* mouse doesn't hover any item (ignoring x-axis), so it's either above list bounds or below. */
+
+ TreeElement *first = soops->tree.first;
+ TreeElement *last = soops->tree.last;
+
+ if (view_mval[1] < last->ys) {
+ *r_te_insert_handle = last;
+ *r_insert_type = TE_INSERT_AFTER;
+ }
+ else if (view_mval[1] > (first->ys + UI_UNIT_Y)) {
+ *r_te_insert_handle = first;
+ *r_insert_type = TE_INSERT_BEFORE;
+ }
+ else {
+ BLI_assert(0);
+ }
+ }
+}
+
+static void outliner_item_drag_handle(
+ SpaceOops *soops, ARegion *ar, const wmEvent *event, TreeElement *te_dragged)
+{
+ TreeElement *te_insert_handle;
+ TreeElementInsertType insert_type;
+
+ outliner_item_drag_get_insert_data(soops, ar, event, te_dragged, &te_insert_handle, &insert_type);
+
+ if (!te_dragged->reinsert_poll &&
+ /* there is no reinsert_poll, so we do some generic checks (same types and reinsert callback is available) */
+ (TREESTORE(te_dragged)->type == TREESTORE(te_insert_handle)->type) &&
+ te_dragged->reinsert)
+ {
+ /* pass */
+ }
+ else if (te_dragged == te_insert_handle) {
+ /* nothing will happen anyway, no need to do poll check */
+ }
+ else if (!te_dragged->reinsert_poll ||
+ !te_dragged->reinsert_poll(te_dragged, &te_insert_handle, &insert_type))
+ {
+ te_insert_handle = NULL;
+ }
+ te_dragged->drag_data->insert_type = insert_type;
+ te_dragged->drag_data->insert_handle = te_insert_handle;
+}
+
+/**
+ * Returns true if it is a collection and empty.
+ */
+static bool is_empty_collection(TreeElement *te)
+{
+ if (!ELEM(TREESTORE(te)->type, TSE_SCENE_COLLECTION, TSE_LAYER_COLLECTION)) {
+ return false;
+ }
+
+ SceneCollection *scene_collection;
+ if (TREESTORE(te)->type == TSE_SCENE_COLLECTION) {
+ scene_collection = (SceneCollection *)te->directdata;
+ }
+ else {
+ BLI_assert(TREESTORE(te)->type == TSE_LAYER_COLLECTION);
+ scene_collection = ((LayerCollection *)te->directdata)->scene_collection;
+ }
+
+ return BLI_listbase_is_empty(&scene_collection->objects) &&
+ BLI_listbase_is_empty(&scene_collection->scene_collections);
+}
+
+static bool outliner_item_drag_drop_apply(
+ Main *bmain,
+ SpaceOops *soops,
+ OutlinerDragDropTooltip *data,
+ const wmEvent *event)
+{
+ TreeElement *dragged_te = data->te;
+ TreeElement *insert_handle = dragged_te->drag_data->insert_handle;
+ TreeElementInsertType insert_type = dragged_te->drag_data->insert_type;
+
+ if ((insert_handle == dragged_te) || !insert_handle) {
+ /* No need to do anything */
+ }
+ else if (dragged_te->reinsert) {
+ BLI_assert(!dragged_te->reinsert_poll || dragged_te->reinsert_poll(dragged_te, &insert_handle,
+ &insert_type));
+ /* call of assert above should not have changed insert_handle and insert_type at this point */
+ BLI_assert(dragged_te->drag_data->insert_handle == insert_handle &&
+ dragged_te->drag_data->insert_type == insert_type);
+
+ /* If the collection was just created and you moved objects/collections inside it,
+ * it is strange to have it closed and we not see the newly dragged elements. */
+ const bool should_open_collection = (insert_type == TE_INSERT_INTO) && is_empty_collection(insert_handle);
+
+ dragged_te->reinsert(bmain, soops, dragged_te, insert_handle, insert_type, event);
+
+ if (should_open_collection && !is_empty_collection(insert_handle)) {
+ TREESTORE(insert_handle)->flag &= ~TSE_CLOSED;
+ }
+ return true;
+ }
+
+ return false;
+}
+
+static int outliner_item_drag_drop_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ Main *bmain = CTX_data_main(C);
+ ARegion *ar = CTX_wm_region(C);
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ OutlinerDragDropTooltip *data = op->customdata;
+ TreeElement *te_dragged = data->te;
+ int retval = OPERATOR_RUNNING_MODAL;
+ bool redraw = false;
+ bool skip_rebuild = true;
+
+ switch (event->type) {
+ case EVT_MODAL_MAP:
+ if (event->val == OUTLINER_ITEM_DRAG_CONFIRM) {
+ if (outliner_item_drag_drop_apply(bmain, soops, data, event)) {
+ skip_rebuild = false;
+ }
+ retval = OPERATOR_FINISHED;
+ }
+ else if (event->val == OUTLINER_ITEM_DRAG_CANCEL) {
+ retval = OPERATOR_CANCELLED;
+ }
+ else {
+ BLI_assert(0);
+ }
+ WM_event_add_mousemove(C); /* update highlight */
+ outliner_item_drag_end(CTX_wm_window(C), data);
+ redraw = true;
+ break;
+ case MOUSEMOVE:
+ outliner_item_drag_handle(soops, ar, event, te_dragged);
+ redraw = true;
+ break;
+ }
+
+ if (skip_rebuild) {
+ soops->storeflag |= SO_TREESTORE_REDRAW; /* only needs to redraw, no rebuild */
+ }
+ if (redraw) {
+ ED_region_tag_redraw(ar);
+ }
+
+ return retval;
+}
+
+/**
+ * Check if the given TreeElement is a collection
+ *
+ * This test is mainly used to see if next/prev TreeElement is a collection.
+ * It will fail when there is no next/prev TreeElement, or when the
+ * element is an Override or something else in the future.
+ */
+static bool tree_element_is_collection_get(const TreeElement *te)
+{
+ if (te == NULL) {
+ return false;
+ }
+
+ TreeStoreElem *tselem = TREESTORE(te);
+ return ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION);
+}
+
+static const char *outliner_drag_drop_tooltip_get(
+ const TreeElement *te_float)
+{
+ const char *name = NULL;
+
+ const TreeElement *te_insert = te_float->drag_data->insert_handle;
+ if (tree_element_is_collection_get(te_float)) {
+ if (te_insert == NULL) {
+ name = TIP_("Move collection");
+ }
+ else {
+ switch (te_float->drag_data->insert_type) {
+ case TE_INSERT_BEFORE:
+ if (tree_element_is_collection_get(te_insert->prev)) {
+ name = TIP_("Move between collections");
+ }
+ else {
+ name = TIP_("Move before collection");
+ }
+ break;
+ case TE_INSERT_AFTER:
+ if (tree_element_is_collection_get(te_insert->next)) {
+ name = TIP_("Move between collections");
+ }
+ else {
+ name = TIP_("Move after collection");
+ }
+ break;
+ case TE_INSERT_INTO:
+ name = TIP_("Move inside collection");
+ break;
+ }
+ }
+ }
+ else if ((TREESTORE(te_float)->type == 0) && (te_float->idcode == ID_OB)) {
+ name = TIP_("Move to collection (Ctrl to add)");
+ }
+
+ return name;
+}
+
+static void outliner_drag_drop_tooltip_cb(const wmWindow *win, void *vdata)
+{
+ OutlinerDragDropTooltip *data = vdata;
+ const char *tooltip;
+
+ int cursorx, cursory;
+ int x, y;
+
+ tooltip = outliner_drag_drop_tooltip_get(data->te);
+ if (tooltip == NULL) {
+ return;
+ }
+
+ cursorx = win->eventstate->x;
+ cursory = win->eventstate->y;
+
+ x = cursorx + U.widget_unit;
+ y = cursory - U.widget_unit;
+
+ /* Drawing. */
+ const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
+
+ const float col_fg[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ const float col_bg[4] = {0.0f, 0.0f, 0.0f, 0.2f};
+
+ glEnable(GL_BLEND);
+ UI_fontstyle_draw_simple_backdrop(fstyle, x, y, tooltip, col_fg, col_bg);
+ glDisable(GL_BLEND);
+}
+
+static int outliner_item_drag_drop_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ ARegion *ar = CTX_wm_region(C);
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ TreeElement *te_dragged = outliner_item_drag_element_find(soops, ar, event);
+
+ if (!te_dragged) {
+ return (OPERATOR_FINISHED | OPERATOR_PASS_THROUGH);
+ }
+
+ OutlinerDragDropTooltip *data = MEM_mallocN(sizeof(OutlinerDragDropTooltip), __func__);
+ data->te = te_dragged;
+
+ op->customdata = data;
+ te_dragged->drag_data = MEM_callocN(sizeof(*te_dragged->drag_data), __func__);
+ /* by default we don't change the item position */
+ te_dragged->drag_data->insert_handle = te_dragged;
+ /* unset highlighted tree element, dragged one will be highlighted instead */
+ outliner_set_flag(&soops->tree, TSE_HIGHLIGHTED, false);
+
+ soops->storeflag |= SO_TREESTORE_REDRAW; /* only needs to redraw, no rebuild */
+ ED_region_tag_redraw(ar);
+
+ WM_event_add_modal_handler(C, op);
+
+ data->handle = WM_draw_cb_activate(CTX_wm_window(C), outliner_drag_drop_tooltip_cb, data);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+/**
+ * Notes about Outliner Item Drag 'n Drop:
+ * Right now only collections display mode is supported. But ideally all/most modes would support this. There are
+ * just some open design questions that have to be answered: do we want to allow mixing order of different data types
+ * (like render-layers and objects)? Would that be a purely visual change or would that have any other effect? ...
+ */
+static void OUTLINER_OT_item_drag_drop(wmOperatorType *ot)
+{
+ ot->name = "Drag and Drop Item";
+ ot->idname = "OUTLINER_OT_item_drag_drop";
+ ot->description = "Change the hierarchical position of an item by repositioning it using drag and drop";
+
+ ot->invoke = outliner_item_drag_drop_invoke;
+ ot->modal = outliner_item_drag_drop_modal;
+
+ ot->poll = outliner_item_drag_drop_poll;
+
+ ot->flag = OPTYPE_UNDO;
+}
+
/* ************************** registration **********************************/
void outliner_operatortypes(void)
{
+ WM_operatortype_append(OUTLINER_OT_highlight_update);
WM_operatortype_append(OUTLINER_OT_item_activate);
WM_operatortype_append(OUTLINER_OT_select_border);
WM_operatortype_append(OUTLINER_OT_item_openclose);
WM_operatortype_append(OUTLINER_OT_item_rename);
+ WM_operatortype_append(OUTLINER_OT_item_drag_drop);
WM_operatortype_append(OUTLINER_OT_operation);
WM_operatortype_append(OUTLINER_OT_scene_operation);
WM_operatortype_append(OUTLINER_OT_object_operation);
@@ -61,6 +444,7 @@ void outliner_operatortypes(void)
WM_operatortype_append(OUTLINER_OT_action_set);
WM_operatortype_append(OUTLINER_OT_constraint_operation);
WM_operatortype_append(OUTLINER_OT_modifier_operation);
+ WM_operatortype_append(OUTLINER_OT_collection_operation);
WM_operatortype_append(OUTLINER_OT_show_one_level);
WM_operatortype_append(OUTLINER_OT_show_active);
@@ -70,10 +454,6 @@ void outliner_operatortypes(void)
WM_operatortype_append(OUTLINER_OT_selected_toggle);
WM_operatortype_append(OUTLINER_OT_expanded_toggle);
- WM_operatortype_append(OUTLINER_OT_renderability_toggle);
- WM_operatortype_append(OUTLINER_OT_selectability_toggle);
- WM_operatortype_append(OUTLINER_OT_visibility_toggle);
-
WM_operatortype_append(OUTLINER_OT_keyingset_add_selected);
WM_operatortype_append(OUTLINER_OT_keyingset_remove_selected);
@@ -87,13 +467,62 @@ void outliner_operatortypes(void)
WM_operatortype_append(OUTLINER_OT_scene_drop);
WM_operatortype_append(OUTLINER_OT_material_drop);
WM_operatortype_append(OUTLINER_OT_group_link);
+
+ /* collections */
+ WM_operatortype_append(OUTLINER_OT_collections_delete);
+ WM_operatortype_append(OUTLINER_OT_collection_select);
+ WM_operatortype_append(OUTLINER_OT_collection_toggle);
+ WM_operatortype_append(OUTLINER_OT_collection_link);
+ WM_operatortype_append(OUTLINER_OT_collection_unlink);
+ WM_operatortype_append(OUTLINER_OT_collection_new);
+ WM_operatortype_append(OUTLINER_OT_collection_duplicate);
+
+ WM_operatortype_append(OUTLINER_OT_collection_nested_new);
+ WM_operatortype_append(OUTLINER_OT_collection_delete_selected);
+ WM_operatortype_append(OUTLINER_OT_collection_objects_add);
+ WM_operatortype_append(OUTLINER_OT_collection_objects_remove);
+ WM_operatortype_append(OUTLINER_OT_collection_objects_select);
+ WM_operatortype_append(OUTLINER_OT_object_add_to_new_collection);
+ WM_operatortype_append(OUTLINER_OT_object_remove_from_collection);
+}
+
+static wmKeyMap *outliner_item_drag_drop_modal_keymap(wmKeyConfig *keyconf)
+{
+ static EnumPropertyItem modal_items[] = {
+ {OUTLINER_ITEM_DRAG_CANCEL, "CANCEL", 0, "Cancel", ""},
+ {OUTLINER_ITEM_DRAG_CONFIRM, "CONFIRM", 0, "Confirm/Drop", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ const char *map_name = "Outliner Item Drap 'n Drop Modal Map";
+
+ wmKeyMap *keymap = WM_modalkeymap_get(keyconf, map_name);
+
+ /* this function is called for each spacetype, only needs to add map once */
+ if (keymap && keymap->modal_items)
+ return NULL;
+
+ keymap = WM_modalkeymap_add(keyconf, map_name, modal_items);
+
+ /* items for modal map */
+ WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, OUTLINER_ITEM_DRAG_CANCEL);
+ WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, OUTLINER_ITEM_DRAG_CANCEL);
+
+ WM_modalkeymap_add_item(keymap, LEFTMOUSE, KM_RELEASE, KM_ANY, 0, OUTLINER_ITEM_DRAG_CONFIRM);
+ WM_modalkeymap_add_item(keymap, RETKEY, KM_RELEASE, KM_ANY, 0, OUTLINER_ITEM_DRAG_CONFIRM);
+ WM_modalkeymap_add_item(keymap, PADENTER, KM_RELEASE, KM_ANY, 0, OUTLINER_ITEM_DRAG_CONFIRM);
+
+ WM_modalkeymap_assign(keymap, "OUTLINER_OT_item_drag_drop");
+
+ return keymap;
}
void outliner_keymap(wmKeyConfig *keyconf)
{
wmKeyMap *keymap = WM_keymap_find(keyconf, "Outliner", SPACE_OUTLINER, 0);
wmKeyMapItem *kmi;
-
+
+ WM_keymap_add_item(keymap, "OUTLINER_OT_highlight_update", MOUSEMOVE, KM_ANY, KM_ANY, 0);
+
WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_DBL_CLICK, 0, 0);
kmi = WM_keymap_add_item(keymap, "OUTLINER_OT_item_activate", LEFTMOUSE, KM_CLICK, 0, 0);
@@ -123,6 +552,8 @@ void outliner_keymap(wmKeyConfig *keyconf)
WM_keymap_add_item(keymap, "OUTLINER_OT_item_rename", LEFTMOUSE, KM_PRESS, KM_CTRL, 0);
WM_keymap_add_item(keymap, "OUTLINER_OT_operation", RIGHTMOUSE, KM_PRESS, 0, 0);
+ WM_keymap_add_item(keymap, "OUTLINER_OT_item_drag_drop", EVT_TWEAK_L, KM_ANY, 0, 0);
+
WM_keymap_add_item(keymap, "OUTLINER_OT_show_hierarchy", HOMEKEY, KM_PRESS, 0, 0);
WM_keymap_add_item(keymap, "OUTLINER_OT_show_active", PERIODKEY, KM_PRESS, 0, 0);
@@ -140,11 +571,6 @@ void outliner_keymap(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "OUTLINER_OT_selected_toggle", AKEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "OUTLINER_OT_expanded_toggle", AKEY, KM_PRESS, KM_SHIFT, 0);
- WM_keymap_verify_item(keymap, "OUTLINER_OT_renderability_toggle", RKEY, KM_PRESS, 0, 0);
- WM_keymap_verify_item(keymap, "OUTLINER_OT_selectability_toggle", SKEY, KM_PRESS, 0, 0);
- WM_keymap_verify_item(keymap, "OUTLINER_OT_visibility_toggle", VKEY, KM_PRESS, 0, 0);
-
-
/* keying sets - only for databrowse */
WM_keymap_verify_item(keymap, "OUTLINER_OT_keyingset_add_selected", KKEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "OUTLINER_OT_keyingset_remove_selected", KKEY, KM_PRESS, KM_ALT, 0);
@@ -154,5 +580,10 @@ void outliner_keymap(wmKeyConfig *keyconf)
WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_add_selected", DKEY, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "OUTLINER_OT_drivers_delete_selected", DKEY, KM_PRESS, KM_ALT, 0);
+
+ WM_keymap_verify_item(keymap, "OUTLINER_OT_collection_nested_new", CKEY, KM_PRESS, 0, 0);
+ WM_keymap_verify_item(keymap, "OUTLINER_OT_collection_delete_selected", XKEY, KM_PRESS, 0, 0);
+
+ outliner_item_drag_drop_modal_keymap(keyconf);
}
diff --git a/source/blender/editors/space_outliner/outliner_select.c b/source/blender/editors/space_outliner/outliner_select.c
index 0b8724b4e28..a3dbab1b3fd 100644
--- a/source/blender/editors/space_outliner/outliner_select.c
+++ b/source/blender/editors/space_outliner/outliner_select.c
@@ -43,12 +43,16 @@
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
+#include "BKE_armature.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_group.h"
+#include "BKE_layer.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "BKE_sequencer.h"
-#include "BKE_armature.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
#include "ED_armature.h"
#include "ED_object.h"
@@ -68,61 +72,12 @@
#include "outliner_intern.h"
-/* ****************************************************** */
-/* Outliner Selection (gray-blue highlight for rows) */
-
-static int outliner_select(SpaceOops *soops, ListBase *lb, int *index, short *selecting)
-{
- TreeElement *te;
- TreeStoreElem *tselem;
- bool changed = false;
-
- for (te = lb->first; te && *index >= 0; te = te->next, (*index)--) {
- tselem = TREESTORE(te);
-
- /* if we've encountered the right item, set its 'Outliner' selection status */
- if (*index == 0) {
- /* this should be the last one, so no need to do anything with index */
- if ((te->flag & TE_ICONROW) == 0) {
- /* -1 value means toggle testing for now... */
- if (*selecting == -1) {
- if (tselem->flag & TSE_SELECTED)
- *selecting = 0;
- else
- *selecting = 1;
- }
-
- /* set selection */
- if (*selecting)
- tselem->flag |= TSE_SELECTED;
- else
- tselem->flag &= ~TSE_SELECTED;
-
- changed |= true;
- }
- }
- else if (TSELEM_OPEN(tselem, soops)) {
- /* Only try selecting sub-elements if we haven't hit the right element yet
- *
- * Hack warning:
- * Index must be reduced before supplying it to the sub-tree to try to do
- * selection, however, we need to increment it again for the next loop to
- * function correctly
- */
- (*index)--;
- changed |= outliner_select(soops, &te->subtree, index, selecting);
- (*index)++;
- }
- }
-
- return changed;
-}
/* ****************************************************** */
/* Outliner Element Selection/Activation on Click */
-static eOLDrawState tree_element_active_renderlayer(
- bContext *C, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
+static eOLDrawState active_viewlayer(
+ bContext *C, Scene *UNUSED(scene), ViewLayer *UNUSED(sl), TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
{
Scene *sce;
@@ -131,12 +86,15 @@ static eOLDrawState tree_element_active_renderlayer(
return OL_DRAWSEL_NONE;
sce = (Scene *)tselem->id;
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ ViewLayer *view_layer = te->directdata;
+
if (set != OL_SETSEL_NONE) {
- sce->r.actlay = tselem->nr;
- WM_event_add_notifier(C, NC_SCENE | ND_RENDER_OPTIONS, sce);
+ BKE_workspace_view_layer_set(workspace, view_layer, sce);
+ WM_event_add_notifier(C, NC_SCREEN | ND_LAYER, NULL);
}
else {
- return sce->r.actlay == tselem->nr;
+ return BKE_workspace_view_layer_get(workspace, sce) == view_layer;
}
return OL_DRAWSEL_NONE;
}
@@ -146,14 +104,14 @@ static eOLDrawState tree_element_active_renderlayer(
* CTRL+LMB: Select/Deselect object and all children.
* CTRL+SHIFT+LMB: Add/Remove object and all children.
*/
-static void do_outliner_object_select_recursive(Scene *scene, Object *ob_parent, bool select)
+static void do_outliner_object_select_recursive(ViewLayer *view_layer, Object *ob_parent, bool select)
{
Base *base;
- for (base = FIRSTBASE; base; base = base->next) {
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
Object *ob = base->object;
- if ((((ob->restrictflag & OB_RESTRICT_VIEW) == 0) && BKE_object_is_child_recursive(ob_parent, ob))) {
- ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT);
+ if ((((base->flag & BASE_VISIBLED) == 0) && BKE_object_is_child_recursive(ob_parent, ob))) {
+ ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT);
}
}
}
@@ -184,7 +142,7 @@ static void do_outliner_ebone_select_recursive(bArmature *arm, EditBone *ebone_p
}
static eOLDrawState tree_element_set_active_object(
- bContext *C, Scene *scene, SpaceOops *soops,
+ bContext *C, Scene *scene, ViewLayer *view_layer, SpaceOops *soops,
TreeElement *te, const eOLSetState set, bool recursive)
{
TreeStoreElem *tselem = TREESTORE(te);
@@ -198,7 +156,7 @@ static eOLDrawState tree_element_set_active_object(
}
else {
ob = (Object *)outliner_search_back(soops, te, ID_OB);
- if (ob == OBACT) {
+ if (ob == OBACT(view_layer)) {
return OL_DRAWSEL_NONE;
}
}
@@ -208,46 +166,46 @@ static eOLDrawState tree_element_set_active_object(
sce = (Scene *)outliner_search_back(soops, te, ID_SCE);
if (sce && scene != sce) {
- ED_screen_set_scene(C, CTX_wm_screen(C), sce);
+ WM_window_change_active_scene(CTX_data_main(C), C, CTX_wm_window(C), sce);
scene = sce;
}
/* find associated base in current scene */
- base = BKE_scene_base_find(scene, ob);
+ base = BKE_view_layer_base_find(view_layer, ob);
if (base) {
if (set == OL_SETSEL_EXTEND) {
/* swap select */
- if (base->flag & SELECT)
- ED_base_object_select(base, BA_DESELECT);
+ if (base->flag & BASE_SELECTED)
+ ED_object_base_select(base, BA_DESELECT);
else
- ED_base_object_select(base, BA_SELECT);
+ ED_object_base_select(base, BA_SELECT);
}
else {
/* deleselect all */
- BKE_scene_base_deselect_all(scene);
- ED_base_object_select(base, BA_SELECT);
+ BKE_view_layer_base_deselect_all(view_layer);
+ ED_object_base_select(base, BA_SELECT);
}
if (recursive) {
/* Recursive select/deselect for Object hierarchies */
- do_outliner_object_select_recursive(scene, ob, (ob->flag & SELECT) != 0);
+ do_outliner_object_select_recursive(view_layer, ob, (base->flag & BASE_SELECTED) != 0);
}
- if (C) {
- ED_base_object_activate(C, base); /* adds notifier */
+ if (set != OL_SETSEL_NONE) {
+ ED_object_base_activate(C, base); /* adds notifier */
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
}
}
- if (ob != scene->obedit)
+ if (ob != OBEDIT_FROM_VIEW_LAYER(view_layer))
ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
return OL_DRAWSEL_NORMAL;
}
static eOLDrawState tree_element_active_material(
- bContext *C, Scene *scene, SpaceOops *soops,
+ bContext *C, Scene *UNUSED(scene), ViewLayer *view_layer, SpaceOops *soops,
TreeElement *te, const eOLSetState set)
{
TreeElement *tes;
@@ -256,7 +214,7 @@ static eOLDrawState tree_element_active_material(
/* we search for the object parent */
ob = (Object *)outliner_search_back(soops, te, ID_OB);
// note: ob->matbits can be NULL when a local object points to a library mesh.
- if (ob == NULL || ob != OBACT || ob->matbits == NULL) {
+ if (ob == NULL || ob != OBACT(view_layer) || ob->matbits == NULL) {
return OL_DRAWSEL_NONE; /* just paranoia */
}
@@ -293,108 +251,21 @@ static eOLDrawState tree_element_active_material(
/* Tagging object for update seems a bit stupid here, but looks like we have to do it
* for render views to update. See T42973.
* Note that RNA material update does it too, see e.g. rna_MaterialSlot_update(). */
- DAG_id_tag_update((ID *)ob, OB_RECALC_OB);
+ DEG_id_tag_update((ID *)ob, OB_RECALC_OB);
WM_event_add_notifier(C, NC_MATERIAL | ND_SHADING_LINKS, NULL);
}
return OL_DRAWSEL_NONE;
}
-static eOLDrawState tree_element_active_texture(
- bContext *C, Scene *scene, SpaceOops *UNUSED(soops),
- TreeElement *te, const eOLSetState set)
-{
- TreeElement *tep;
- TreeStoreElem /* *tselem,*/ *tselemp;
- Object *ob = OBACT;
- SpaceButs *sbuts = NULL;
-
- if (ob == NULL) {
- /* no active object */
- return OL_DRAWSEL_NONE;
- }
-
- /*tselem = TREESTORE(te);*/ /*UNUSED*/
-
- /* find buttons region (note, this is undefined really still, needs recode in blender) */
- /* XXX removed finding sbuts */
-
- /* where is texture linked to? */
- tep = te->parent;
- tselemp = TREESTORE(tep);
-
- if (tep->idcode == ID_WO) {
- World *wrld = (World *)tselemp->id;
-
- if (set != OL_SETSEL_NONE) {
- if (sbuts) {
- // XXX sbuts->tabo = TAB_SHADING_TEX; // hack from header_buttonswin.c
- // XXX sbuts->texfrom = 1;
- }
-// XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
- wrld->texact = te->index;
- }
- else if (tselemp->id == (ID *)(scene->world)) {
- if (wrld->texact == te->index) {
- return OL_DRAWSEL_NORMAL;
- }
- }
- }
- else if (tep->idcode == ID_LA) {
- Lamp *la = (Lamp *)tselemp->id;
- if (set != OL_SETSEL_NONE) {
- if (sbuts) {
- // XXX sbuts->tabo = TAB_SHADING_TEX; // hack from header_buttonswin.c
- // XXX sbuts->texfrom = 2;
- }
-// XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
- la->texact = te->index;
- }
- else {
- if (tselemp->id == ob->data) {
- if (la->texact == te->index) {
- return OL_DRAWSEL_NORMAL;
- }
- }
- }
- }
- else if (tep->idcode == ID_MA) {
- Material *ma = (Material *)tselemp->id;
- if (set != OL_SETSEL_NONE) {
- if (sbuts) {
- //sbuts->tabo = TAB_SHADING_TEX; // hack from header_buttonswin.c
- // XXX sbuts->texfrom = 0;
- }
-// XXX extern_set_butspace(F6KEY, 0); // force shading buttons texture
- ma->texact = (char)te->index;
-
- /* also set active material */
- ob->actcol = tep->index + 1;
- }
- else if (tep->flag & TE_ACTIVE) { // this is active material
- if (ma->texact == te->index) {
- return OL_DRAWSEL_NORMAL;
- }
- }
- }
-
- if (set != OL_SETSEL_NONE) {
- WM_event_add_notifier(C, NC_TEXTURE, NULL);
- }
-
- /* no active object */
- return OL_DRAWSEL_NONE;
-}
-
-
static eOLDrawState tree_element_active_lamp(
- bContext *UNUSED(C), Scene *scene, SpaceOops *soops,
+ bContext *UNUSED(C), Scene *UNUSED(scene), ViewLayer *view_layer, SpaceOops *soops,
TreeElement *te, const eOLSetState set)
{
Object *ob;
/* we search for the object parent */
ob = (Object *)outliner_search_back(soops, te, ID_OB);
- if (ob == NULL || ob != OBACT) {
+ if (ob == NULL || ob != OBACT(view_layer)) {
/* just paranoia */
return OL_DRAWSEL_NONE;
}
@@ -410,7 +281,7 @@ static eOLDrawState tree_element_active_lamp(
}
static eOLDrawState tree_element_active_camera(
- bContext *UNUSED(C), Scene *scene, SpaceOops *soops,
+ bContext *UNUSED(C), Scene *scene, ViewLayer *UNUSED(sl), SpaceOops *soops,
TreeElement *te, const eOLSetState set)
{
Object *ob = (Object *)outliner_search_back(soops, te, ID_OB);
@@ -423,7 +294,7 @@ static eOLDrawState tree_element_active_camera(
}
static eOLDrawState tree_element_active_world(
- bContext *C, Scene *scene, SpaceOops *UNUSED(soops),
+ bContext *C, Scene *scene, ViewLayer *UNUSED(sl), SpaceOops *UNUSED(soops),
TreeElement *te, const eOLSetState set)
{
TreeElement *tep;
@@ -440,7 +311,7 @@ static eOLDrawState tree_element_active_world(
if (set != OL_SETSEL_NONE) {
/* make new scene active */
if (sce && scene != sce) {
- ED_screen_set_scene(C, CTX_wm_screen(C), sce);
+ WM_window_change_active_scene(CTX_data_main(C), C, CTX_wm_window(C), sce);
}
}
@@ -456,7 +327,7 @@ static eOLDrawState tree_element_active_world(
}
static eOLDrawState tree_element_active_defgroup(
- bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
+ bContext *C, ViewLayer *view_layer, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
{
Object *ob;
@@ -466,21 +337,20 @@ static eOLDrawState tree_element_active_defgroup(
BLI_assert(te->index + 1 >= 0);
ob->actdef = te->index + 1;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, ob);
}
else {
- if (ob == OBACT) {
+ if (ob == OBACT(view_layer))
if (ob->actdef == te->index + 1) {
return OL_DRAWSEL_NORMAL;
}
- }
}
return OL_DRAWSEL_NONE;
}
static eOLDrawState tree_element_active_posegroup(
- bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
+ bContext *C, Scene *UNUSED(scene), ViewLayer *view_layer, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
{
Object *ob = (Object *)tselem->id;
@@ -491,7 +361,7 @@ static eOLDrawState tree_element_active_posegroup(
}
}
else {
- if (ob == OBACT && ob->pose) {
+ if (ob == OBACT(view_layer) && ob->pose) {
if (ob->pose->active_group == te->index + 1) {
return OL_DRAWSEL_NORMAL;
}
@@ -501,7 +371,7 @@ static eOLDrawState tree_element_active_posegroup(
}
static eOLDrawState tree_element_active_posechannel(
- bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set, bool recursive)
+ bContext *C, Scene *UNUSED(scene), ViewLayer *view_layer, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set, bool recursive)
{
Object *ob = (Object *)tselem->id;
bArmature *arm = ob->data;
@@ -535,7 +405,7 @@ static eOLDrawState tree_element_active_posechannel(
}
}
else {
- if (ob == OBACT && ob->pose) {
+ if (ob == OBACT(view_layer) && ob->pose) {
if (pchan->bone->flag & BONE_SELECTED) {
return OL_DRAWSEL_NORMAL;
}
@@ -545,14 +415,14 @@ static eOLDrawState tree_element_active_posechannel(
}
static eOLDrawState tree_element_active_bone(
- bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set, bool recursive)
+ bContext *C, ViewLayer *view_layer, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set, bool recursive)
{
bArmature *arm = (bArmature *)tselem->id;
Bone *bone = te->directdata;
if (set != OL_SETSEL_NONE) {
if (!(bone->flag & BONE_HIDDEN_P)) {
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
if (ob) {
if (set != OL_SETSEL_EXTEND) {
/* single select forces all other bones to get unselected */
@@ -581,7 +451,7 @@ static eOLDrawState tree_element_active_bone(
}
}
else {
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
if (ob && ob->data == arm) {
if (bone->flag & BONE_SELECTED) {
@@ -594,7 +464,7 @@ static eOLDrawState tree_element_active_bone(
/* ebones only draw in editmode armature */
-static void tree_element_active_ebone__sel(bContext *C, Scene *scene, bArmature *arm, EditBone *ebone, short sel)
+static void tree_element_active_ebone__sel(bContext *C, Object *obedit, bArmature *arm, EditBone *ebone, short sel)
{
if (sel) {
ebone->flag |= BONE_SELECTED | BONE_ROOTSEL | BONE_TIPSEL;
@@ -608,34 +478,34 @@ static void tree_element_active_ebone__sel(bContext *C, Scene *scene, bArmature
if (ebone->parent && (ebone->flag & BONE_CONNECTED)) ebone->parent->flag &= ~BONE_TIPSEL;
}
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_ACTIVE, scene->obedit);
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_ACTIVE, obedit);
}
static eOLDrawState tree_element_active_ebone(
- bContext *C, Scene *scene, TreeElement *te, TreeStoreElem *UNUSED(tselem), const eOLSetState set, bool recursive)
+ bContext *C, TreeElement *te, TreeStoreElem *UNUSED(tselem), const eOLSetState set, bool recursive)
{
- BLI_assert(scene->obedit != NULL);
-
- bArmature *arm = scene->obedit->data;
+ Object *obedit = CTX_data_edit_object(C);
+ BLI_assert(obedit != NULL);
+ bArmature *arm = obedit->data;
EditBone *ebone = te->directdata;
eOLDrawState status = OL_DRAWSEL_NONE;
if (set != OL_SETSEL_NONE) {
if (set == OL_SETSEL_NORMAL) {
if (!(ebone->flag & BONE_HIDDEN_A)) {
- ED_armature_edit_deselect_all(scene->obedit);
- tree_element_active_ebone__sel(C, scene, arm, ebone, true);
+ ED_armature_edit_deselect_all(obedit);
+ tree_element_active_ebone__sel(C, obedit, arm, ebone, true);
status = OL_DRAWSEL_NORMAL;
}
}
else if (set == OL_SETSEL_EXTEND) {
if (!(ebone->flag & BONE_HIDDEN_A)) {
if (!(ebone->flag & BONE_SELECTED)) {
- tree_element_active_ebone__sel(C, scene, arm, ebone, true);
+ tree_element_active_ebone__sel(C, obedit, arm, ebone, true);
status = OL_DRAWSEL_NORMAL;
}
else {
/* entirely selected, so de-select */
- tree_element_active_ebone__sel(C, scene, arm, ebone, false);
+ tree_element_active_ebone__sel(C, obedit, arm, ebone, false);
status = OL_DRAWSEL_NONE;
}
}
@@ -654,7 +524,7 @@ static eOLDrawState tree_element_active_ebone(
}
static eOLDrawState tree_element_active_modifier(
- bContext *C, TreeElement *UNUSED(te), TreeStoreElem *tselem, const eOLSetState set)
+ bContext *C, Scene *UNUSED(scene), ViewLayer *UNUSED(sl), TreeElement *UNUSED(te), TreeStoreElem *tselem, const eOLSetState set)
{
if (set != OL_SETSEL_NONE) {
Object *ob = (Object *)tselem->id;
@@ -682,7 +552,7 @@ static eOLDrawState tree_element_active_psys(
}
static int tree_element_active_constraint(
- bContext *C, TreeElement *UNUSED(te), TreeStoreElem *tselem, const eOLSetState set)
+ bContext *C, Scene *UNUSED(scene), ViewLayer *UNUSED(sl), TreeElement *UNUSED(te), TreeStoreElem *tselem, const eOLSetState set)
{
if (set != OL_SETSEL_NONE) {
Object *ob = (Object *)tselem->id;
@@ -695,7 +565,7 @@ static int tree_element_active_constraint(
}
static eOLDrawState tree_element_active_text(
- bContext *UNUSED(C), Scene *UNUSED(scene), SpaceOops *UNUSED(soops),
+ bContext *UNUSED(C), Scene *UNUSED(scene), ViewLayer *UNUSED(sl), SpaceOops *UNUSED(soops),
TreeElement *UNUSED(te), int UNUSED(set))
{
// XXX removed
@@ -703,10 +573,10 @@ static eOLDrawState tree_element_active_text(
}
static eOLDrawState tree_element_active_pose(
- bContext *C, Scene *scene, TreeElement *UNUSED(te), TreeStoreElem *tselem, const eOLSetState set)
+ bContext *C, ViewLayer *view_layer, TreeElement *UNUSED(te), TreeStoreElem *tselem, const eOLSetState set)
{
Object *ob = (Object *)tselem->id;
- Base *base = BKE_scene_base_find(scene, ob);
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
if (base == NULL) {
/* Armature not instantiated in current scene (e.g. inside an appended group...). */
@@ -714,7 +584,7 @@ static eOLDrawState tree_element_active_pose(
}
if (set != OL_SETSEL_NONE) {
- if (scene->obedit) {
+ if (OBEDIT_FROM_VIEW_LAYER(view_layer)) {
ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
}
@@ -795,7 +665,7 @@ static eOLDrawState tree_element_active_sequence_dup(
}
static eOLDrawState tree_element_active_keymap_item(
- bContext *UNUSED(C), TreeElement *te, TreeStoreElem *UNUSED(tselem), const eOLSetState set)
+ bContext *UNUSED(C), Scene *UNUSED(scene), ViewLayer *UNUSED(sl), TreeElement *te, TreeStoreElem *UNUSED(tselem), const eOLSetState set)
{
wmKeyMapItem *kmi = te->directdata;
@@ -811,84 +681,130 @@ static eOLDrawState tree_element_active_keymap_item(
return OL_DRAWSEL_NONE;
}
+static eOLDrawState tree_element_active_collection(
+ bContext *C, TreeElement *te, TreeStoreElem *tselem, const eOLSetState set)
+{
+ if (set == OL_SETSEL_NONE) {
+ LayerCollection *active = CTX_data_layer_collection(C);
+
+ /* sometimes the renderlayer has no LayerCollection at all */
+ if (active == NULL) {
+ return OL_DRAWSEL_NONE;
+ }
+
+ if ((tselem->type == TSE_SCENE_COLLECTION && active->scene_collection == te->directdata) ||
+ (tselem->type == TSE_LAYER_COLLECTION && active == te->directdata))
+ {
+ return OL_DRAWSEL_NORMAL;
+ }
+ }
+ /* don't allow selecting a scene collection, it can have multiple layer collection
+ * instances (which one would the user want to be selected then?) */
+ else if (tselem->type == TSE_LAYER_COLLECTION) {
+ LayerCollection *layer_collection = te->directdata;
+
+ switch (layer_collection->scene_collection->type) {
+ case COLLECTION_TYPE_NONE:
+ case COLLECTION_TYPE_GROUP_INTERNAL:
+ {
+ ViewLayer *view_layer = BKE_view_layer_find_from_collection(tselem->id, layer_collection);
+ const int collection_index = BKE_layer_collection_findindex(view_layer, layer_collection);
+
+ if (collection_index > -1) {
+ view_layer->active_collection = collection_index;
+ }
+ break;
+ }
+ default:
+ BLI_assert(!"Collection type not fully implemented");
+ }
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+ }
+
+ return OL_DRAWSEL_NONE;
+}
+
/* ---------------------------------------------- */
/* generic call for ID data check or make/check active in UI */
-eOLDrawState tree_element_active(bContext *C, Scene *scene, SpaceOops *soops, TreeElement *te,
+eOLDrawState tree_element_active(bContext *C, Scene *scene, ViewLayer *view_layer, SpaceOops *soops, TreeElement *te,
const eOLSetState set, const bool handle_all_types)
{
switch (te->idcode) {
/* Note: ID_OB only if handle_all_type is true, else objects are handled specially to allow multiple
- * selection. See do_outliner_item_activate_from_cursor. */
+ * selection. See do_outliner_item_activate. */
case ID_OB:
if (handle_all_types) {
- return tree_element_set_active_object(C, scene, soops, te, set, false);
+ return tree_element_set_active_object(C, scene, view_layer, soops, te, set, false);
}
break;
case ID_MA:
- return tree_element_active_material(C, scene, soops, te, set);
+ return tree_element_active_material(C, scene, view_layer, soops, te, set);
case ID_WO:
- return tree_element_active_world(C, scene, soops, te, set);
+ return tree_element_active_world(C, scene, view_layer, soops, te, set);
case ID_LA:
- return tree_element_active_lamp(C, scene, soops, te, set);
- case ID_TE:
- return tree_element_active_texture(C, scene, soops, te, set);
+ return tree_element_active_lamp(C, scene, view_layer, soops, te, set);
case ID_TXT:
- return tree_element_active_text(C, scene, soops, te, set);
+ return tree_element_active_text(C, scene, view_layer, soops, te, set);
case ID_CA:
- return tree_element_active_camera(C, scene, soops, te, set);
+ return tree_element_active_camera(C, scene, view_layer, soops, te, set);
}
return OL_DRAWSEL_NONE;
}
/**
* Generic call for non-id data to make/check active in UI
- *
- * \note Context can be NULL when ``(set == OL_SETSEL_NONE)``
*/
eOLDrawState tree_element_type_active(
- bContext *C, Scene *scene, SpaceOops *soops,
+ bContext *C, Scene *scene, ViewLayer *view_layer, SpaceOops *soops,
TreeElement *te, TreeStoreElem *tselem, const eOLSetState set, bool recursive)
{
switch (tselem->type) {
case TSE_DEFGROUP:
- return tree_element_active_defgroup(C, scene, te, tselem, set);
+ return tree_element_active_defgroup(C, view_layer, te, tselem, set);
case TSE_BONE:
- return tree_element_active_bone(C, scene, te, tselem, set, recursive);
+ return tree_element_active_bone(C, view_layer, te, tselem, set, recursive);
case TSE_EBONE:
- return tree_element_active_ebone(C, scene, te, tselem, set, recursive);
+ return tree_element_active_ebone(C, te, tselem, set, recursive);
case TSE_MODIFIER:
- return tree_element_active_modifier(C, te, tselem, set);
+ return tree_element_active_modifier(C, scene, view_layer, te, tselem, set);
case TSE_LINKED_OB:
if (set != OL_SETSEL_NONE) {
- tree_element_set_active_object(C, scene, soops, te, set, false);
+ tree_element_set_active_object(C, scene, view_layer, soops, te, set, false);
}
- else if (tselem->id == (ID *)OBACT) {
+ else if (tselem->id == (ID *)OBACT(view_layer)) {
return OL_DRAWSEL_NORMAL;
}
break;
case TSE_LINKED_PSYS:
return tree_element_active_psys(C, scene, te, tselem, set);
case TSE_POSE_BASE:
- return tree_element_active_pose(C, scene, te, tselem, set);
+ return tree_element_active_pose(C, view_layer, te, tselem, set);
case TSE_POSE_CHANNEL:
- return tree_element_active_posechannel(C, scene, te, tselem, set, recursive);
+ return tree_element_active_posechannel(C, scene, view_layer, te, tselem, set, recursive);
case TSE_CONSTRAINT:
- return tree_element_active_constraint(C, te, tselem, set);
+ return tree_element_active_constraint(C, scene, view_layer, te, tselem, set);
case TSE_R_LAYER:
- return tree_element_active_renderlayer(C, te, tselem, set);
+ if (soops->outlinevis == SO_SCENES) {
+ return active_viewlayer(C, scene, view_layer, te, tselem, set);
+ }
+ else {
+ return OL_DRAWSEL_NONE;
+ }
case TSE_POSEGRP:
- return tree_element_active_posegroup(C, scene, te, tselem, set);
+ return tree_element_active_posegroup(C, scene, view_layer, te, tselem, set);
case TSE_SEQUENCE:
return tree_element_active_sequence(C, scene, te, tselem, set);
case TSE_SEQUENCE_DUP:
return tree_element_active_sequence_dup(scene, te, tselem, set);
case TSE_KEYMAP_ITEM:
- return tree_element_active_keymap_item(C, te, tselem, set);
+ return tree_element_active_keymap_item(C, scene, view_layer, te, tselem, set);
case TSE_GP_LAYER:
- //return tree_element_active_gplayer(C, scene, te, tselem, set);
+ //return tree_element_active_gplayer(C, scene, s, te, tselem, set);
break;
-
+ case TSE_SCENE_COLLECTION:
+ case TSE_LAYER_COLLECTION:
+ return tree_element_active_collection(C, te, tselem, set);
}
return OL_DRAWSEL_NONE;
}
@@ -902,16 +818,16 @@ eOLDrawState tree_element_type_active(
* Needed to run from operators accessed from a menu.
*/
static void do_outliner_item_activate_tree_element(
- bContext *C, Scene *scene, SpaceOops *soops,
+ bContext *C, Scene *scene, ViewLayer *view_layer, SpaceOops *soops,
TreeElement *te, TreeStoreElem *tselem,
- bool extend, bool recursive)
+ const bool extend, const bool recursive)
{
/* always makes active object, except for some specific types.
* Note about TSE_EBONE: In case of a same ID_AR datablock shared among several objects, we do not want
* to switch out of edit mode (see T48328 for details). */
- if (!ELEM(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP, TSE_EBONE)) {
+ if (!ELEM(tselem->type, TSE_SEQUENCE, TSE_SEQ_STRIP, TSE_SEQUENCE_DUP, TSE_EBONE, TSE_LAYER_COLLECTION)) {
tree_element_set_active_object(
- C, scene, soops, te,
+ C, scene, view_layer, soops, te,
(extend && tselem->type == 0) ? OL_SETSEL_EXTEND : OL_SETSEL_NORMAL,
recursive && tselem->type == 0);
}
@@ -920,100 +836,101 @@ static void do_outliner_item_activate_tree_element(
/* editmode? */
if (te->idcode == ID_SCE) {
if (scene != (Scene *)tselem->id) {
- ED_screen_set_scene(C, CTX_wm_screen(C), (Scene *)tselem->id);
+ WM_window_change_active_scene(CTX_data_main(C), C, CTX_wm_window(C), (Scene *)tselem->id);
}
}
else if (te->idcode == ID_GR) {
Group *gr = (Group *)tselem->id;
- GroupObject *gob;
if (extend) {
int sel = BA_SELECT;
- for (gob = gr->gobject.first; gob; gob = gob->next) {
- if (gob->ob->flag & SELECT) {
+ FOREACH_GROUP_BASE_BEGIN(gr, base)
+ {
+ if (base->flag & BASE_SELECTED) {
sel = BA_DESELECT;
break;
}
}
+ FOREACH_GROUP_BASE_END
- for (gob = gr->gobject.first; gob; gob = gob->next) {
- ED_base_object_select(BKE_scene_base_find(scene, gob->ob), sel);
+ FOREACH_GROUP_OBJECT_BEGIN(gr, object)
+ {
+ ED_object_base_select(BKE_view_layer_base_find(view_layer, object), sel);
}
+ FOREACH_GROUP_OBJECT_END;
}
else {
- BKE_scene_base_deselect_all(scene);
-
- for (gob = gr->gobject.first; gob; gob = gob->next) {
- if ((gob->ob->flag & SELECT) == 0)
- ED_base_object_select(BKE_scene_base_find(scene, gob->ob), BA_SELECT);
+ BKE_view_layer_base_deselect_all(view_layer);
+
+ FOREACH_GROUP_OBJECT_BEGIN(gr, object)
+ {
+ Base *base = BKE_view_layer_base_find(view_layer, object);
+ /* Object may not be in this scene */
+ if (base != NULL) {
+ if ((base->flag & BASE_SELECTED) == 0) {
+ ED_object_base_select(base, BA_SELECT);
+ }
+ }
}
+ FOREACH_GROUP_OBJECT_END;
}
-
+
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
}
else if (ELEM(te->idcode, ID_ME, ID_CU, ID_MB, ID_LT, ID_AR)) {
WM_operator_name_call(C, "OBJECT_OT_editmode_toggle", WM_OP_INVOKE_REGION_WIN, NULL);
}
else { // rest of types
- tree_element_active(C, scene, soops, te, OL_SETSEL_NORMAL, false);
+ tree_element_active(C, scene, view_layer, soops, te, OL_SETSEL_NORMAL, false);
}
}
else {
- tree_element_type_active(
- C, scene, soops, te, tselem,
- extend ? OL_SETSEL_EXTEND : OL_SETSEL_NORMAL,
- recursive);
+ tree_element_type_active(C, scene, view_layer, soops, te, tselem,
+ extend ? OL_SETSEL_EXTEND : OL_SETSEL_NORMAL,
+ recursive);
}
}
/**
- * Activates tree items, also handles clicking on arrows.
+ * \param extend: Don't deselect other items, only modify \a te.
+ * \param toggle: Select \a te when not selected, deselect when selected.
*/
-static bool do_outliner_item_activate_from_cursor(
- bContext *C, Scene *scene, ARegion *ar, SpaceOops *soops,
- TreeElement *te, bool extend, bool recursive, const float mval[2])
+void outliner_item_select(SpaceOops *soops, const TreeElement *te, const bool extend, const bool toggle)
{
- if (mval[1] > te->ys && mval[1] < te->ys + UI_UNIT_Y) {
- TreeStoreElem *tselem = TREESTORE(te);
- bool openclose = false;
-
- /* open close icon */
- if ((te->flag & TE_ICONROW) == 0) { // hidden icon, no open/close
- if (mval[0] > te->xs && mval[0] < te->xs + UI_UNIT_X)
- openclose = true;
- }
-
- if (openclose) {
- /* all below close/open? */
- if (extend) {
- tselem->flag &= ~TSE_CLOSED;
- outliner_set_flag(&te->subtree, TSE_CLOSED, !outliner_has_one_flag(&te->subtree, TSE_CLOSED, 1));
- }
- else {
- if (tselem->flag & TSE_CLOSED) tselem->flag &= ~TSE_CLOSED;
- else tselem->flag |= TSE_CLOSED;
-
- }
-
- return true;
- }
- /* name and first icon */
- else if (mval[0] > te->xs + UI_UNIT_X && mval[0] < te->xend) {
- do_outliner_item_activate_tree_element(
- C, scene, soops,
- te, tselem,
- extend, recursive);
- return true;
- }
+ TreeStoreElem *tselem = TREESTORE(te);
+ const short new_flag = toggle ? (tselem->flag ^ TSE_SELECTED) : (tselem->flag | TSE_SELECTED);
+
+ if (extend == false) {
+ outliner_set_flag(&soops->tree, TSE_SELECTED, false);
}
-
- for (te = te->subtree.first; te; te = te->next) {
- if (do_outliner_item_activate_from_cursor(C, scene, ar, soops, te, extend, recursive, mval)) {
- return true;
- }
+ tselem->flag = new_flag;
+}
+
+static void outliner_item_toggle_closed(TreeElement *te, const bool toggle_children)
+{
+ TreeStoreElem *tselem = TREESTORE(te);
+ if (toggle_children) {
+ tselem->flag &= ~TSE_CLOSED;
+
+ const bool all_opened = !outliner_has_one_flag(&te->subtree, TSE_CLOSED, 1);
+ outliner_set_flag(&te->subtree, TSE_CLOSED, all_opened);
+ }
+ else {
+ tselem->flag ^= TSE_CLOSED;
}
- return false;
+}
+
+static bool outliner_item_is_co_within_close_toggle(TreeElement *te, float view_co_x)
+{
+ return ((te->flag & TE_ICONROW) == 0) && (view_co_x > te->xs) && (view_co_x < te->xs + UI_UNIT_X);
+}
+
+static bool outliner_is_co_within_restrict_columns(const SpaceOops *soops, const ARegion *ar, float view_co_x)
+{
+ return ((soops->outlinevis != SO_DATABLOCKS) &&
+ !(soops->flag & SO_HIDE_RESTRICTCOLS) &&
+ (view_co_x > ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX));
}
/**
@@ -1027,10 +944,11 @@ void outliner_item_do_activate_from_tree_element(
bool extend, bool recursive)
{
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
SpaceOops *soops = CTX_wm_space_outliner(C);
do_outliner_item_activate_tree_element(
- C, scene, soops,
+ C, scene, view_layer, soops,
te, tselem,
extend, recursive);
}
@@ -1044,56 +962,52 @@ int outliner_item_do_activate_from_cursor(
bContext *C, const int mval[2],
bool extend, bool recursive)
{
- Scene *scene = CTX_data_scene(C);
ARegion *ar = CTX_wm_region(C);
SpaceOops *soops = CTX_wm_space_outliner(C);
TreeElement *te;
- float fmval[2];
+ float view_mval[2];
+ bool changed = false, rebuild_tree = false;
- UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &fmval[0], &fmval[1]);
+ UI_view2d_region_to_view(&ar->v2d, mval[0], mval[1], &view_mval[0], &view_mval[1]);
- if (!ELEM(soops->outlinevis, SO_DATABLOCKS, SO_USERDEF) &&
- !(soops->flag & SO_HIDE_RESTRICTCOLS) &&
- (fmval[0] > ar->v2d.cur.xmax - OL_TOG_RESTRICT_VIEWX))
- {
+ if (outliner_is_co_within_restrict_columns(soops, ar, view_mval[0])) {
return OPERATOR_CANCELLED;
}
- for (te = soops->tree.first; te; te = te->next) {
- if (do_outliner_item_activate_from_cursor(C, scene, ar, soops, te, extend, recursive, fmval)) {
- break;
- }
+ if (!(te = outliner_find_item_at_y(soops, &soops->tree, view_mval[1]))) {
+ /* skip */
}
-
- if (te) {
- ED_undo_push(C, "Outliner click event");
+ else if (outliner_item_is_co_within_close_toggle(te, view_mval[0])) {
+ outliner_item_toggle_closed(te, extend);
+ changed = true;
+ rebuild_tree = true;
}
else {
- short selecting = -1;
- int row;
-
- /* get row number - 100 here is just a dummy value since we don't need the column */
- UI_view2d_listview_view_to_cell(&ar->v2d, 1000, UI_UNIT_Y, 0.0f, OL_Y_OFFSET,
- fmval[0], fmval[1], NULL, &row);
-
- /* select relevant row */
- if (outliner_select(soops, &soops->tree, &row, &selecting)) {
-
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ /* the row may also contain children, if one is hovered we want this instead of current te */
+ TreeElement *activate_te = outliner_find_item_at_x_in_row(soops, te, view_mval[0]);
+ TreeStoreElem *activate_tselem = TREESTORE(activate_te);
+
+ outliner_item_select(soops, activate_te, extend, extend);
+ do_outliner_item_activate_tree_element(C, scene, view_layer, soops, activate_te, activate_tselem, extend, recursive);
+ changed = true;
+ }
+
+ if (changed) {
+ if (!rebuild_tree) {
+ /* only needs to redraw, no rebuild */
soops->storeflag |= SO_TREESTORE_REDRAW;
-
- /* no need for undo push here, only changing outliner data which is
- * scene level - campbell */
- /* ED_undo_push(C, "Outliner selection event"); */
}
+ ED_undo_push(C, "Outliner selection change");
+ ED_region_tag_redraw(ar);
}
-
- ED_region_tag_redraw(ar);
return OPERATOR_FINISHED;
}
/* event can enterkey, then it opens/closes */
-static int outliner_item_activate(bContext *C, wmOperator *op, const wmEvent *event)
+static int outliner_item_activate_invoke(bContext *C, wmOperator *op, const wmEvent *event)
{
bool extend = RNA_boolean_get(op->ptr, "extend");
bool recursive = RNA_boolean_get(op->ptr, "recursive");
@@ -1106,7 +1020,7 @@ void OUTLINER_OT_item_activate(wmOperatorType *ot)
ot->idname = "OUTLINER_OT_item_activate";
ot->description = "Handle mouse clicks to activate/select items";
- ot->invoke = outliner_item_activate;
+ ot->invoke = outliner_item_activate_invoke;
ot->poll = ED_operator_outliner_active;
diff --git a/source/blender/editors/space_outliner/outliner_tools.c b/source/blender/editors/space_outliner/outliner_tools.c
index e8275d597a6..f51acff3ba2 100644
--- a/source/blender/editors/space_outliner/outliner_tools.c
+++ b/source/blender/editors/space_outliner/outliner_tools.c
@@ -53,10 +53,11 @@
#include "BKE_animsys.h"
#include "BKE_context.h"
#include "BKE_constraint.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_group.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
+#include "BKE_library_override.h"
#include "BKE_library_query.h"
#include "BKE_library_remap.h"
#include "BKE_main.h"
@@ -64,8 +65,12 @@
#include "BKE_scene.h"
#include "BKE_sequencer.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_armature.h"
#include "ED_object.h"
+#include "ED_scene.h"
#include "ED_screen.h"
#include "ED_sequencer.h"
#include "ED_undo.h"
@@ -191,19 +196,7 @@ static void unlink_texture_cb(
MTex **mtex = NULL;
int a;
- if (GS(tsep->id->name) == ID_MA) {
- Material *ma = (Material *)tsep->id;
- mtex = ma->mtex;
- }
- else if (GS(tsep->id->name) == ID_LA) {
- Lamp *la = (Lamp *)tsep->id;
- mtex = la->mtex;
- }
- else if (GS(tsep->id->name) == ID_WO) {
- World *wrld = (World *)tsep->id;
- mtex = wrld->mtex;
- }
- else if (GS(tsep->id->name) == ID_LS) {
+ if (GS(tsep->id->name) == ID_LS) {
FreestyleLineStyle *ls = (FreestyleLineStyle *)tsep->id;
mtex = ls->mtex;
}
@@ -308,7 +301,7 @@ static bool scene_cb(bContext *C, eOutliner_PropSceneOps event, TreeElement *UNU
Scene *scene = (Scene *)tselem->id;
if (event == OL_SCENE_OP_DELETE) {
- if (ED_screen_delete_scene(C, scene)) {
+ if (ED_scene_delete(C, CTX_data_main(C), CTX_wm_window(C), scene)) {
WM_event_add_notifier(C, NC_SCENE | NA_REMOVED, scene);
}
else {
@@ -359,15 +352,15 @@ void OUTLINER_OT_scene_operation(wmOperatorType *ot)
/* ******************************************** */
static void object_select_cb(
- bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *te,
+ bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te),
TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
{
- Base *base = (Base *)te->directdata;
-
- if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
- if (base && ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0)) {
- base->flag |= SELECT;
- base->object->flag |= SELECT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = (Object *)tselem->id;
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (base && ((base->flag & BASE_VISIBLED) != 0)) {
+ base->flag |= BASE_SELECTED;
}
}
@@ -381,15 +374,15 @@ static void object_select_hierarchy_cb(
}
static void object_deselect_cb(
- bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *te,
+ bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te),
TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
{
- Base *base = (Base *)te->directdata;
-
- if (base == NULL) base = BKE_scene_base_find(scene, (Object *)tselem->id);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = (Object *)tselem->id;
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+
if (base) {
- base->flag &= ~SELECT;
- base->object->flag &= ~SELECT;
+ base->flag &= ~BASE_SELECTED;
}
}
@@ -397,30 +390,27 @@ static void object_delete_cb(
bContext *C, ReportList *reports, Scene *scene, TreeElement *te,
TreeStoreElem *tsep, TreeStoreElem *tselem, void *user_data)
{
- Base *base = (Base *)te->directdata;
-
- if (base == NULL)
- base = BKE_scene_base_find(scene, (Object *)tselem->id);
- if (base) {
+ Object *ob = (Object *)tselem->id;
+ if (ob) {
Main *bmain = CTX_data_main(C);
- if (base->object->id.tag & LIB_TAG_INDIRECT) {
- BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", base->object->id.name + 2);
+ if (ob->id.tag & LIB_TAG_INDIRECT) {
+ BKE_reportf(reports, RPT_WARNING, "Cannot delete indirectly linked object '%s'", ob->id.name + 2);
return;
}
- else if (BKE_library_ID_is_indirectly_used(bmain, base->object) &&
- ID_REAL_USERS(base->object) <= 1 && ID_EXTRA_USERS(base->object) == 0)
+ else if (BKE_library_ID_is_indirectly_used(bmain, ob) &&
+ ID_REAL_USERS(ob) <= 1 && ID_EXTRA_USERS(ob) == 0)
{
BKE_reportf(reports, RPT_WARNING,
"Cannot delete object '%s' from scene '%s', indirectly used objects need at least one user",
- base->object->id.name + 2, scene->id.name + 2);
+ ob->id.name + 2, scene->id.name + 2);
return;
}
// check also library later
- if (scene->obedit == base->object)
+ if (ob == CTX_data_edit_object(C)) {
ED_object_editmode_exit(C, EM_FREEDATA | EM_WAITCURSOR | EM_DO_UNDO);
-
- ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
+ }
+ ED_object_base_free_and_unlink(CTX_data_main(C), scene, ob);
/* leave for ED_outliner_id_unref to handle */
#if 0
te->directdata = NULL;
@@ -453,6 +443,19 @@ static void id_local_cb(
}
}
+static void id_static_override_cb(
+ bContext *C, ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te),
+ TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
+{
+ if (ID_IS_LINKED(tselem->id) && (tselem->id->tag & LIB_TAG_EXTERN)) {
+ Main *bmain = CTX_data_main(C);
+ ID *override_id = BKE_override_static_create_from_id(bmain, tselem->id);
+ if (override_id != NULL) {
+ BKE_main_id_clear_newpoins(bmain);
+ }
+ }
+}
+
static void id_fake_user_set_cb(
bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *UNUSED(scene), TreeElement *UNUSED(te),
TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
@@ -518,23 +521,27 @@ static void singleuser_world_cb(
}
static void group_linkobs2scene_cb(
- bContext *UNUSED(C), ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te),
+ bContext *C, ReportList *UNUSED(reports), Scene *scene, TreeElement *UNUSED(te),
TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ SceneCollection *sc = CTX_data_scene_collection(C);
Group *group = (Group *)tselem->id;
- GroupObject *gob;
Base *base;
- for (gob = group->gobject.first; gob; gob = gob->next) {
- base = BKE_scene_base_find(scene, gob->ob);
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ base = BKE_view_layer_base_find(view_layer, object);
if (!base) {
/* link to scene */
- base = BKE_scene_base_add(scene, gob->ob);
- id_us_plus(&gob->ob->id);
+ BKE_collection_object_add(&scene->id, sc, object);
+ base = BKE_view_layer_base_find(view_layer, object);
+ id_us_plus(&object->id);
}
- base->object->flag |= SELECT;
- base->flag |= SELECT;
+
+ base->flag |= BASE_SELECTED;
}
+ FOREACH_GROUP_OBJECT_END;
}
static void group_instance_cb(
@@ -566,7 +573,7 @@ void outliner_do_object_operation_ex(
// when objects selected in other scenes... dunno if that should be allowed
Scene *scene_owner = (Scene *)outliner_search_back(soops, te, ID_SCE);
if (scene_owner && scene_act != scene_owner) {
- ED_screen_set_scene(C, CTX_wm_screen(C), scene_owner);
+ WM_window_change_active_scene(CTX_data_main(C), C, CTX_wm_window(C), scene_owner);
}
/* important to use 'scene_owner' not scene_act else deleting objects can crash.
* only use 'scene_act' when 'scene_owner' is NULL, which can happen when the
@@ -653,6 +660,17 @@ typedef enum eOutliner_PropModifierOps {
OL_MODIFIER_OP_DELETE
} eOutliner_PropModifierOps;
+typedef enum eOutliner_PropCollectionOps {
+ OL_COLLECTION_OP_OBJECTS_ADD = 1,
+ OL_COLLECTION_OP_OBJECTS_REMOVE,
+ OL_COLLECTION_OP_OBJECTS_SELECT,
+ OL_COLLECTION_OP_COLLECTION_NEW,
+ OL_COLLECTION_OP_COLLECTION_COPY,
+ OL_COLLECTION_OP_COLLECTION_DEL,
+ OL_COLLECTION_OP_COLLECTION_UNLINK,
+ OL_COLLECTION_OP_GROUP_CREATE,
+} eOutliner_PropCollectionOps;
+
static void pchan_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *UNUSED(arg))
{
bPoseChannel *pchan = (bPoseChannel *)te->directdata;
@@ -788,12 +806,12 @@ static void modifier_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem
if (event == OL_MODIFIER_OP_TOGVIS) {
md->mode ^= eModifierMode_Realtime;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
}
else if (event == OL_MODIFIER_OP_TOGREN) {
md->mode ^= eModifierMode_Render;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_OBJECT | ND_MODIFIER, ob);
}
else if (event == OL_MODIFIER_OP_DELETE) {
@@ -803,6 +821,90 @@ static void modifier_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem
}
}
+static void collection_cb(int event, TreeElement *te, TreeStoreElem *UNUSED(tselem), void *Carg)
+{
+ bContext *C = (bContext *)Carg;
+ Scene *scene = CTX_data_scene(C);
+ LayerCollection *lc = te->directdata;
+ ID *id = te->store_elem->id;
+ SceneCollection *sc = lc->scene_collection;
+
+ if (event == OL_COLLECTION_OP_OBJECTS_ADD) {
+ CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
+ {
+ BKE_collection_object_add(id, sc, ob);
+ }
+ CTX_DATA_END;
+
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ }
+ else if (event == OL_COLLECTION_OP_OBJECTS_REMOVE) {
+ Main *bmain = CTX_data_main(C);
+
+ CTX_DATA_BEGIN (C, Object *, ob, selected_objects)
+ {
+ BKE_collection_object_remove(bmain, id, sc, ob, true);
+ }
+ CTX_DATA_END;
+
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ te->store_elem->flag &= ~TSE_SELECTED;
+ }
+ else if (event == OL_COLLECTION_OP_OBJECTS_SELECT) {
+ BKE_layer_collection_objects_select(lc);
+ WM_main_add_notifier(NC_SCENE | ND_OB_SELECT, scene);
+ }
+ else if (event == OL_COLLECTION_OP_COLLECTION_NEW) {
+ if (GS(id->name) == ID_GR) {
+ BKE_collection_add(id, sc, COLLECTION_TYPE_GROUP_INTERNAL, NULL);
+ }
+ else {
+ BLI_assert(GS(id->name) == ID_SCE);
+ BKE_collection_add(id, sc, COLLECTION_TYPE_NONE, NULL);
+ }
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ }
+ else if (event == OL_COLLECTION_OP_COLLECTION_COPY) {
+ BKE_layer_collection_duplicate(id, lc);
+ DEG_relations_tag_update(CTX_data_main(C));
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ }
+ else if (event == OL_COLLECTION_OP_COLLECTION_UNLINK) {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+
+ if (BLI_findindex(&view_layer->layer_collections, lc) == -1) {
+ /* we can't unlink if the layer collection wasn't directly linked */
+ TODO_LAYER_OPERATORS; /* this shouldn't be in the menu in those cases */
+ }
+ else {
+ BKE_collection_unlink(view_layer, lc);
+ DEG_relations_tag_update(CTX_data_main(C));
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ }
+ }
+ else if (event == OL_COLLECTION_OP_COLLECTION_DEL) {
+ if (BKE_collection_remove(id, sc)) {
+ DEG_relations_tag_update(CTX_data_main(C));
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ }
+ else {
+ /* we can't remove the master collection */
+ TODO_LAYER_OPERATORS; /* this shouldn't be in the menu in those cases */
+ }
+ }
+ else if (event == OL_COLLECTION_OP_GROUP_CREATE) {
+ Main *bmain = CTX_data_main(C);
+ BKE_collection_group_create(bmain, scene, lc);
+ DEG_relations_tag_update(bmain);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ }
+ else {
+ BLI_assert(!"Collection operation not fully implemented!");
+ }
+}
+
static void outliner_do_data_operation(SpaceOops *soops, int type, int event, ListBase *lb,
void (*operation_cb)(int, TreeElement *, TreeStoreElem *, void *),
void *arg)
@@ -827,12 +929,13 @@ static Base *outline_delete_hierarchy(bContext *C, ReportList *reports, Scene *s
{
Base *child_base, *base_next;
Object *parent;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
if (!base) {
return NULL;
}
- for (child_base = scene->base.first; child_base; child_base = base_next) {
+ for (child_base = view_layer->object_bases.first; child_base; child_base = base_next) {
base_next = child_base->next;
for (parent = child_base->object->parent; parent && (parent != base->object); parent = parent->parent);
if (parent) {
@@ -855,7 +958,7 @@ static Base *outline_delete_hierarchy(bContext *C, ReportList *reports, Scene *s
base->object->id.name + 2, scene->id.name + 2);
return base_next;
}
- ED_base_object_free_and_unlink(CTX_data_main(C), scene, base);
+ ED_object_base_free_and_unlink(CTX_data_main(C), scene, base->object);
return base_next;
}
@@ -863,11 +966,12 @@ static void object_delete_hierarchy_cb(
bContext *C, ReportList *reports, Scene *scene,
TreeElement *te, TreeStoreElem *UNUSED(tsep), TreeStoreElem *tselem, void *UNUSED(user_data))
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Base *base = (Base *)te->directdata;
- Object *obedit = scene->obedit;
+ Object *obedit = CTX_data_edit_object(C);
if (!base) {
- base = BKE_scene_base_find(scene, (Object *)tselem->id);
+ base = BKE_view_layer_base_find(view_layer, (Object *)tselem->id);
}
if (base) {
/* Check also library later. */
@@ -911,9 +1015,6 @@ static const EnumPropertyItem prop_object_op_types[] = {
{OL_OP_DELETE_HIERARCHY, "DELETE_HIERARCHY", 0, "Delete Hierarchy", ""},
{OL_OP_REMAP, "REMAP", 0, "Remap Users",
"Make all users of selected data-blocks to use instead a new chosen one"},
- {OL_OP_TOGVIS, "TOGVIS", 0, "Toggle Visible", ""},
- {OL_OP_TOGSEL, "TOGSEL", 0, "Toggle Selectable", ""},
- {OL_OP_TOGREN, "TOGREN", 0, "Toggle Renderable", ""},
{OL_OP_RENAME, "RENAME", 0, "Rename", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -922,6 +1023,7 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ wmWindow *win = CTX_wm_window(C);
SpaceOops *soops = CTX_wm_space_outliner(C);
int event;
const char *str = NULL;
@@ -936,7 +1038,7 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
Scene *sce = scene; // to be able to delete, scenes are set...
outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_select_cb);
if (scene != sce) {
- ED_screen_set_scene(C, CTX_wm_screen(C), sce);
+ WM_window_change_active_scene(bmain, C, win, sce);
}
str = "Select Objects";
@@ -946,8 +1048,8 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
Scene *sce = scene; // to be able to delete, scenes are set...
outliner_do_object_operation_ex(C, op->reports, scene, soops, &soops->tree, object_select_hierarchy_cb, false);
if (scene != sce) {
- ED_screen_set_scene(C, CTX_wm_screen(C), sce);
- }
+ WM_window_change_active_scene(bmain, C, win, sce);
+ }
str = "Select Object Hierarchy";
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
}
@@ -966,7 +1068,7 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
* cleanup tree here to prevent such cases. */
outliner_cleanup_tree(soops);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
str = "Delete Objects";
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
}
@@ -976,7 +1078,7 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
/* XXX: See OL_OP_DELETE comment above. */
outliner_cleanup_tree(soops);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
str = "Delete Object Hierarchy";
WM_event_add_notifier(C, NC_SCENE | ND_OB_ACTIVE, scene);
}
@@ -988,21 +1090,6 @@ static int outliner_object_operation_exec(bContext *C, wmOperator *op)
outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, id_local_cb);
str = "Localized Objects";
}
- else if (event == OL_OP_TOGVIS) {
- outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_visibility_cb);
- str = "Toggle Visibility";
- WM_event_add_notifier(C, NC_SCENE | ND_OB_VISIBLE, scene);
- }
- else if (event == OL_OP_TOGSEL) {
- outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_selectability_cb);
- str = "Toggle Selectability";
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
- }
- else if (event == OL_OP_TOGREN) {
- outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, object_toggle_renderability_cb);
- str = "Toggle Renderability";
- WM_event_add_notifier(C, NC_SCENE | ND_OB_RENDER, scene);
- }
else if (event == OL_OP_RENAME) {
outliner_do_object_operation(C, op->reports, scene, soops, &soops->tree, item_rename_cb);
str = "Rename Object";
@@ -1040,6 +1127,7 @@ void OUTLINER_OT_object_operation(wmOperatorType *ot)
typedef enum eOutliner_PropGroupOps {
OL_GROUPOP_UNLINK = 1,
OL_GROUPOP_LOCAL,
+ OL_GROUPOP_STATIC_OVERRIDE,
OL_GROUPOP_LINK,
OL_GROUPOP_DELETE,
OL_GROUPOP_REMAP,
@@ -1053,6 +1141,8 @@ typedef enum eOutliner_PropGroupOps {
static const EnumPropertyItem prop_group_op_types[] = {
{OL_GROUPOP_UNLINK, "UNLINK", 0, "Unlink Group", ""},
{OL_GROUPOP_LOCAL, "LOCAL", 0, "Make Local Group", ""},
+ {OL_GROUPOP_STATIC_OVERRIDE, "STATIC_OVERRIDE",
+ 0, "Add Static Override", "Add a local static override of that group"},
{OL_GROUPOP_LINK, "LINK", 0, "Link Group Objects to Scene", ""},
{OL_GROUPOP_DELETE, "DELETE", 0, "Delete Group", ""},
{OL_GROUPOP_REMAP, "REMAP", 0, "Remap Users",
@@ -1084,13 +1174,16 @@ static int outliner_group_operation_exec(bContext *C, wmOperator *op)
case OL_GROUPOP_LOCAL:
outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_local_cb, NULL);
break;
+ case OL_GROUPOP_STATIC_OVERRIDE:
+ outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_static_override_cb, NULL);
+ break;
case OL_GROUPOP_LINK:
outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_linkobs2scene_cb, NULL);
break;
case OL_GROUPOP_INSTANCE:
outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_instance_cb, NULL);
/* works without this except if you try render right after, see: 22027 */
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
break;
case OL_GROUPOP_DELETE:
outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_delete_cb, NULL);
@@ -1098,15 +1191,6 @@ static int outliner_group_operation_exec(bContext *C, wmOperator *op)
case OL_GROUPOP_REMAP:
outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_remap_cb, NULL);
break;
- case OL_GROUPOP_TOGVIS:
- outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_toggle_visibility_cb, NULL);
- break;
- case OL_GROUPOP_TOGSEL:
- outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_toggle_selectability_cb, NULL);
- break;
- case OL_GROUPOP_TOGREN:
- outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, group_toggle_renderability_cb, NULL);
- break;
case OL_GROUPOP_RENAME:
outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, item_rename_cb, NULL);
break;
@@ -1145,6 +1229,7 @@ typedef enum eOutlinerIdOpTypes {
OUTLINER_IDOP_UNLINK,
OUTLINER_IDOP_LOCAL,
+ OUTLINER_IDOP_STATIC_OVERRIDE,
OUTLINER_IDOP_SINGLE,
OUTLINER_IDOP_DELETE,
OUTLINER_IDOP_REMAP,
@@ -1160,6 +1245,8 @@ typedef enum eOutlinerIdOpTypes {
static const EnumPropertyItem prop_id_op_types[] = {
{OUTLINER_IDOP_UNLINK, "UNLINK", 0, "Unlink", ""},
{OUTLINER_IDOP_LOCAL, "LOCAL", 0, "Make Local", ""},
+ {OUTLINER_IDOP_STATIC_OVERRIDE, "STATIC_OVERRIDE",
+ 0, "Add Static Override", "Add a local static override of this data-block"},
{OUTLINER_IDOP_SINGLE, "SINGLE", 0, "Make Single User", ""},
{OUTLINER_IDOP_DELETE, "DELETE", 0, "Delete", "WARNING: no undo"},
{OUTLINER_IDOP_REMAP, "REMAP", 0, "Remap Users",
@@ -1229,6 +1316,13 @@ static int outliner_id_operation_exec(bContext *C, wmOperator *op)
ED_undo_push(C, "Localized Data");
break;
}
+ case OUTLINER_IDOP_STATIC_OVERRIDE:
+ {
+ /* make local */
+ outliner_do_libdata_operation(C, op->reports, scene, soops, &soops->tree, id_static_override_cb, NULL);
+ ED_undo_push(C, "Overrided Data");
+ break;
+ }
case OUTLINER_IDOP_SINGLE:
{
/* make single user */
@@ -1628,7 +1722,7 @@ static int outliner_animdata_operation_exec(bContext *C, wmOperator *op)
/* update dependencies */
if (updateDeps) {
/* rebuild depsgraph for the new deps */
- DAG_relations_tag_update(CTX_data_main(C));
+ DEG_relations_tag_update(CTX_data_main(C));
}
return OPERATOR_FINISHED;
@@ -1746,6 +1840,84 @@ void OUTLINER_OT_modifier_operation(wmOperatorType *ot)
/* ******************** */
+static EnumPropertyItem prop_collection_op_types[] = {
+ {OL_COLLECTION_OP_OBJECTS_ADD, "OBJECTS_ADD", ICON_ZOOMIN, "Add Selected", "Add selected objects to collection"},
+ {OL_COLLECTION_OP_OBJECTS_REMOVE, "OBJECTS_REMOVE", ICON_X, "Remove Selected", "Remove selected objects from collection"},
+ {OL_COLLECTION_OP_OBJECTS_SELECT, "OBJECTS_SELECT", ICON_RESTRICT_SELECT_OFF, "Select Objects", "Select collection objects"},
+ {OL_COLLECTION_OP_COLLECTION_NEW, "COLLECTION_NEW", ICON_NEW, "New Collection", "Add a new nested collection"},
+ {OL_COLLECTION_OP_COLLECTION_COPY, "COLLECTION_DUPLI", ICON_NONE, "Duplicate Collection", "Duplicate the collection"},
+ {OL_COLLECTION_OP_COLLECTION_UNLINK, "COLLECTION_UNLINK", ICON_UNLINKED, "Unlink", "Unlink collection"},
+ {OL_COLLECTION_OP_COLLECTION_DEL, "COLLECTION_DEL", ICON_X, "Delete Collection", "Delete the collection"},
+ {OL_COLLECTION_OP_GROUP_CREATE, "GROUP_CREATE", ICON_GROUP, "Create Group", "Turn the collection into a group collection"},
+ {0, NULL, 0, NULL, NULL}
+};
+
+static int outliner_collection_operation_exec(bContext *C, wmOperator *op)
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ int scenelevel = 0, objectlevel = 0, idlevel = 0, datalevel = 0;
+ eOutliner_PropCollectionOps event;
+
+ event = RNA_enum_get(op->ptr, "type");
+ set_operation_types(soops, &soops->tree, &scenelevel, &objectlevel, &idlevel, &datalevel);
+
+ outliner_do_data_operation(soops, datalevel, event, &soops->tree, collection_cb, C);
+
+ outliner_cleanup_tree(soops);
+
+ ED_undo_push(C, "Collection operation");
+
+ return OPERATOR_FINISHED;
+}
+
+static int outliner_collection_operation_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ SpaceOops *soops = CTX_wm_space_outliner(C);
+ wmOperatorType *ot = op->type;
+ EnumPropertyItem *prop = &prop_collection_op_types[0];
+
+ uiPopupMenu *pup = UI_popup_menu_begin(C, "Collection", ICON_NONE);
+ uiLayout *layout = UI_popup_menu_layout(pup);
+
+ for (int i = 0; i < (ARRAY_SIZE(prop_collection_op_types) - 1); i++, prop++) {
+ if (soops->outlinevis != SO_GROUPS ||
+ !ELEM(prop->value,
+ OL_COLLECTION_OP_OBJECTS_SELECT,
+ OL_COLLECTION_OP_COLLECTION_UNLINK,
+ OL_COLLECTION_OP_GROUP_CREATE))
+ {
+ uiItemEnumO_ptr(layout, ot, NULL, prop->icon, "type", prop->value);
+ }
+ }
+
+ UI_popup_menu_end(C, pup);
+
+ return OPERATOR_INTERFACE;
+}
+
+void OUTLINER_OT_collection_operation(wmOperatorType *ot)
+{
+ PropertyRNA *prop;
+
+ /* identifiers */
+ ot->name = "Outliner Collection Operation";
+ ot->idname = "OUTLINER_OT_collection_operation";
+ ot->description = "";
+
+ /* callbacks */
+ ot->invoke = outliner_collection_operation_invoke;
+ ot->exec = outliner_collection_operation_exec;
+ ot->poll = ED_operator_outliner_active;
+
+ ot->flag = 0;
+
+ prop = RNA_def_enum(ot->srna, "type", prop_collection_op_types, OL_COLLECTION_OP_OBJECTS_ADD, "Collection Operation", "");
+ RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE);
+ ot->prop = prop;
+}
+
+/* ******************** */
+
// XXX: select linked is for RNA structs only
static const EnumPropertyItem prop_data_op_types[] = {
{OL_DOP_SELECT, "SELECT", 0, "Select", ""},
@@ -1878,7 +2050,7 @@ static int do_outliner_operation_event(bContext *C, ARegion *ar, SpaceOops *soop
}
}
else if (objectlevel) {
- WM_operator_name_call(C, "OUTLINER_OT_object_operation", WM_OP_INVOKE_REGION_WIN, NULL);
+ WM_menu_name_call(C, "OUTLINER_MT_context_object", WM_OP_INVOKE_REGION_WIN);
}
else if (idlevel) {
if (idlevel == -1 || datalevel) {
@@ -1908,7 +2080,7 @@ static int do_outliner_operation_event(bContext *C, ARegion *ar, SpaceOops *soop
else if (datalevel == TSE_DRIVER_BASE) {
/* do nothing... no special ops needed yet */
}
- else if (ELEM(datalevel, TSE_R_LAYER_BASE, TSE_R_LAYER, TSE_R_PASS)) {
+ else if (ELEM(datalevel, TSE_R_LAYER_BASE, TSE_R_LAYER)) {
/*WM_operator_name_call(C, "OUTLINER_OT_renderdata_operation", WM_OP_INVOKE_REGION_WIN, NULL)*/
}
else if (datalevel == TSE_ID_BASE) {
@@ -1920,6 +2092,12 @@ static int do_outliner_operation_event(bContext *C, ARegion *ar, SpaceOops *soop
else if (datalevel == TSE_MODIFIER) {
WM_operator_name_call(C, "OUTLINER_OT_modifier_operation", WM_OP_INVOKE_REGION_WIN, NULL);
}
+ else if (datalevel == TSE_LAYER_COLLECTION) {
+ WM_operator_name_call(C, "OUTLINER_OT_collection_operation", WM_OP_INVOKE_REGION_WIN, NULL);
+ }
+ else if (datalevel == TSE_SCENE_COLLECTION) {
+ WM_menu_name_call(C, "OUTLINER_MT_context_scene_collection", WM_OP_INVOKE_REGION_WIN);
+ }
else {
WM_operator_name_call(C, "OUTLINER_OT_data_operation", WM_OP_INVOKE_REGION_WIN, NULL);
}
diff --git a/source/blender/editors/space_outliner/outliner_tree.c b/source/blender/editors/space_outliner/outliner_tree.c
index 051605b1079..2a5151a16ad 100644
--- a/source/blender/editors/space_outliner/outliner_tree.c
+++ b/source/blender/editors/space_outliner/outliner_tree.c
@@ -46,6 +46,7 @@
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meta_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_particle_types.h"
#include "DNA_scene_types.h"
#include "DNA_world_types.h"
@@ -63,12 +64,16 @@
#include "BKE_fcurve.h"
#include "BKE_main.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_modifier.h"
#include "BKE_sequencer.h"
#include "BKE_idcode.h"
#include "BKE_outliner_treehash.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_armature.h"
#include "ED_screen.h"
@@ -77,12 +82,25 @@
#include "RNA_access.h"
+#include "UI_interface.h"
+
#include "outliner_intern.h"
#ifdef WIN32
# include "BLI_math_base.h" /* M_PI */
#endif
+/* prototypes */
+static void outliner_add_layer_collections_recursive(
+ SpaceOops *soops, ListBase *tree, ID *id, ListBase *layer_collections, TreeElement *parent_ten,
+ const bool show_objects);
+static TreeElement *outliner_add_scene_collection_recursive(
+ SpaceOops *soops, ListBase *tree, Scene *scene, SceneCollection *scene_collection, TreeElement *parent_ten);
+static void outliner_add_view_layer(
+ SpaceOops *soops, ListBase *tree, TreeElement *parent,
+ Scene *scene, ViewLayer *layer, const bool show_objects);
+static void outliner_make_object_parent_hierarchy(ListBase *lb);
+
/* ********************************************************* */
/* Persistent Data */
@@ -180,16 +198,11 @@ static void check_persistent(SpaceOops *soops, TreeElement *te, ID *id, short ty
/* ********************************************************* */
/* Tree Management */
-void outliner_free_tree(ListBase *lb)
+void outliner_free_tree(ListBase *tree)
{
- while (lb->first) {
- TreeElement *te = lb->first;
-
- outliner_free_tree(&te->subtree);
- BLI_remlink(lb, te);
-
- if (te->flag & TE_FREE_NAME) MEM_freeN((void *)te->name);
- MEM_freeN(te);
+ for (TreeElement *element = tree->first, *element_next; element; element = element_next) {
+ element_next = element->next;
+ outliner_free_tree_element(element, tree);
}
}
@@ -199,103 +212,23 @@ void outliner_cleanup_tree(SpaceOops *soops)
outliner_storage_cleanup(soops);
}
-/* Find specific item from the treestore */
-TreeElement *outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem)
-{
- TreeElement *te, *tes;
- for (te = lb->first; te; te = te->next) {
- if (te->store_elem == store_elem) return te;
- tes = outliner_find_tree_element(&te->subtree, store_elem);
- if (tes) return tes;
- }
- return NULL;
-}
-
-/* tse is not in the treestore, we use its contents to find a match */
-TreeElement *outliner_find_tse(SpaceOops *soops, const TreeStoreElem *tse)
-{
- TreeStoreElem *tselem;
-
- if (tse->id == NULL) return NULL;
-
- /* check if 'tse' is in treestore */
- tselem = BKE_outliner_treehash_lookup_any(soops->treehash, tse->type, tse->nr, tse->id);
- if (tselem)
- return outliner_find_tree_element(&soops->tree, tselem);
-
- return NULL;
-}
-
-/* Find treestore that refers to given ID */
-TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, const ID *id)
-{
- for (TreeElement *te = lb->first; te; te = te->next) {
- TreeStoreElem *tselem = TREESTORE(te);
- if (tselem->type == 0) {
- if (tselem->id == id) {
- return te;
- }
- /* only deeper on scene or object */
- if (ELEM(te->idcode, ID_OB, ID_SCE) ||
- ((soops->outlinevis == SO_GROUPS) && (te->idcode == ID_GR)))
- {
- TreeElement *tes = outliner_find_id(soops, &te->subtree, id);
- if (tes) {
- return tes;
- }
- }
- }
- }
- return NULL;
-}
-
-TreeElement *outliner_find_posechannel(ListBase *lb, const bPoseChannel *pchan)
-{
- for (TreeElement *te = lb->first; te; te = te->next) {
- if (te->directdata == pchan) {
- return te;
- }
-
- TreeStoreElem *tselem = TREESTORE(te);
- if (ELEM(tselem->type, TSE_POSE_BASE, TSE_POSE_CHANNEL)) {
- TreeElement *tes = outliner_find_posechannel(&te->subtree, pchan);
- if (tes) {
- return tes;
- }
- }
- }
- return NULL;
-}
-
-TreeElement *outliner_find_editbone(ListBase *lb, const EditBone *ebone)
+/**
+ * Free \a element and its sub-tree and remove its link in \a parent_subtree.
+ *
+ * \note Does not remove the TreeStoreElem of \a element!
+ * \param parent_subtree Subtree of the parent element, so the list containing \a element.
+ */
+void outliner_free_tree_element(TreeElement *element, ListBase *parent_subtree)
{
- for (TreeElement *te = lb->first; te; te = te->next) {
- if (te->directdata == ebone) {
- return te;
- }
+ BLI_assert(BLI_findindex(parent_subtree, element) > -1);
+ BLI_remlink(parent_subtree, element);
- TreeStoreElem *tselem = TREESTORE(te);
- if (ELEM(tselem->type, 0, TSE_EBONE)) {
- TreeElement *tes = outliner_find_editbone(&te->subtree, ebone);
- if (tes) {
- return tes;
- }
- }
- }
- return NULL;
-}
+ outliner_free_tree(&element->subtree);
-ID *outliner_search_back(SpaceOops *UNUSED(soops), TreeElement *te, short idcode)
-{
- TreeStoreElem *tselem;
- te = te->parent;
-
- while (te) {
- tselem = TREESTORE(te);
- if (tselem->type == 0 && te->idcode == idcode) return tselem->id;
- te = te->parent;
+ if (element->flag & TE_FREE_NAME) {
+ MEM_freeN((void *)element->name);
}
- return NULL;
+ MEM_freeN(element);
}
@@ -322,98 +255,6 @@ static void outliner_add_bone(SpaceOops *soops, ListBase *lb, ID *id, Bone *curB
}
}
-/* -------------------------------------------------------- */
-
-#define LOG2I(x) (int)(log(x) / M_LN2)
-
-static void outliner_add_passes(SpaceOops *soops, TreeElement *tenla, ID *id, SceneRenderLayer *srl)
-{
- TreeStoreElem *tselem = NULL;
- TreeElement *te = NULL;
-
- /* log stuff is to convert bitflags (powers of 2) to small integers,
- * in order to not overflow short tselem->nr */
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_COMBINED));
- te->name = IFACE_("Combined");
- te->directdata = &srl->passflag;
-
- /* save cpu cycles, but we add the first to invoke an open/close triangle */
- tselem = TREESTORE(tenla);
- if (tselem->flag & TSE_CLOSED)
- return;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_Z));
- te->name = IFACE_("Z");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_VECTOR));
- te->name = IFACE_("Vector");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_NORMAL));
- te->name = IFACE_("Normal");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_UV));
- te->name = IFACE_("UV");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_MIST));
- te->name = IFACE_("Mist");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_INDEXOB));
- te->name = IFACE_("Index Object");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_INDEXMA));
- te->name = IFACE_("Index Material");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_RGBA));
- te->name = IFACE_("Color");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_DIFFUSE));
- te->name = IFACE_("Diffuse");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_SPEC));
- te->name = IFACE_("Specular");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_SHADOW));
- te->name = IFACE_("Shadow");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_AO));
- te->name = IFACE_("AO");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_REFLECT));
- te->name = IFACE_("Reflection");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_REFRACT));
- te->name = IFACE_("Refraction");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_INDIRECT));
- te->name = IFACE_("Indirect");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_ENVIRONMENT));
- te->name = IFACE_("Environment");
- te->directdata = &srl->passflag;
-
- te = outliner_add_element(soops, &tenla->subtree, id, tenla, TSE_R_PASS, LOG2I(SCE_PASS_EMIT));
- te->name = IFACE_("Emit");
- te->directdata = &srl->passflag;
-}
-
-#undef LOG2I
-
static bool outliner_animdata_test(AnimData *adt)
{
if (adt)
@@ -424,19 +265,19 @@ static bool outliner_animdata_test(AnimData *adt)
#ifdef WITH_FREESTYLE
static void outliner_add_line_styles(SpaceOops *soops, ListBase *lb, Scene *sce, TreeElement *te)
{
- SceneRenderLayer *srl;
+ ViewLayer *view_layer;
FreestyleLineSet *lineset;
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
- for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
+ for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
FreestyleLineStyle *linestyle = lineset->linestyle;
if (linestyle) {
linestyle->id.tag |= LIB_TAG_DOIT;
}
}
}
- for (srl = sce->r.layers.first; srl; srl = srl->next) {
- for (lineset = srl->freestyleConfig.linesets.first; lineset; lineset = lineset->next) {
+ for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ for (lineset = view_layer->freestyle_config.linesets.first; lineset; lineset = lineset->next) {
FreestyleLineStyle *linestyle = lineset->linestyle;
if (linestyle) {
if (!(linestyle->id.tag & LIB_TAG_DOIT))
@@ -451,44 +292,143 @@ static void outliner_add_line_styles(SpaceOops *soops, ListBase *lb, Scene *sce,
static void outliner_add_scene_contents(SpaceOops *soops, ListBase *lb, Scene *sce, TreeElement *te)
{
- SceneRenderLayer *srl;
+ /* View layers */
TreeElement *tenla = outliner_add_element(soops, lb, sce, te, TSE_R_LAYER_BASE, 0);
- int a;
-
- tenla->name = IFACE_("RenderLayers");
- for (a = 0, srl = sce->r.layers.first; srl; srl = srl->next, a++) {
- TreeElement *tenlay = outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, a);
- tenlay->name = srl->name;
- tenlay->directdata = &srl->layflag;
-
- if (srl->light_override)
- outliner_add_element(soops, &tenlay->subtree, srl->light_override, tenlay, TSE_LINKED_LAMP, 0);
- if (srl->mat_override)
- outliner_add_element(soops, &tenlay->subtree, srl->mat_override, tenlay, TSE_LINKED_MAT, 0);
-
- outliner_add_passes(soops, tenlay, &sce->id, srl);
+ tenla->name = IFACE_("View Layers");
+
+ ViewLayer *view_layer;
+ for (view_layer = sce->view_layers.first; view_layer; view_layer = view_layer->next) {
+ TreeElement *tenlay = outliner_add_element(soops, &tenla->subtree, sce, te, TSE_R_LAYER, 0);
+ tenlay->name = view_layer->name;
+ tenlay->directdata = view_layer;
}
+
+ /* Collections */
+ outliner_add_scene_collection_recursive(soops, lb, sce, sce->collection, NULL);
+
+ /* Objects */
+ tenla = outliner_add_element(soops, lb, sce, te, TSE_SCENE_OBJECTS_BASE, 0);
+ tenla->name = IFACE_("Objects");
+ FOREACH_SCENE_OBJECT_BEGIN(sce, ob)
+ {
+ outliner_add_element(soops, &tenla->subtree, ob, NULL, 0, 0);
+ }
+ FOREACH_SCENE_OBJECT_END;
+ outliner_make_object_parent_hierarchy(&tenla->subtree);
- // TODO: move this to the front?
+ /* Animation Data */
if (outliner_animdata_test(sce->adt))
outliner_add_element(soops, lb, sce, te, TSE_ANIM_DATA, 0);
+ /* Grease Pencil */
outliner_add_element(soops, lb, sce->gpd, te, 0, 0);
-
- outliner_add_element(soops, lb, sce->world, te, 0, 0);
+}
-#ifdef WITH_FREESTYLE
- if (STREQ(sce->r.engine, RE_engine_id_BLENDER_RENDER) && (sce->r.mode & R_EDGE_FRS))
- outliner_add_line_styles(soops, lb, sce, te);
-#endif
+TreeTraversalAction outliner_find_selected_objects(TreeElement *te, void *customdata)
+{
+ struct ObjectsSelectedData *data = customdata;
+ TreeStoreElem *tselem = TREESTORE(te);
+
+ if (ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION)) {
+ return TRAVERSE_CONTINUE;
+ }
+
+ if (tselem->type || (tselem->id == NULL) || (GS(tselem->id->name) != ID_OB)) {
+ return TRAVERSE_SKIP_CHILDS;
+ }
+
+ BLI_addtail(&data->objects_selected_array, BLI_genericNodeN(te));
+
+ return TRAVERSE_CONTINUE;
+}
+
+/**
+ * Move objects from a collection to another.
+ * We ignore the original object being inserted, we used it for polling only.
+ * Instead we move all the selected objects around.
+ */
+static void outliner_object_reorder(
+ Main *bmain, SpaceOops *soops,
+ TreeElement *insert_element,
+ TreeElement *insert_handle, TreeElementInsertType action,
+ const wmEvent *event)
+{
+ SceneCollection *sc = outliner_scene_collection_from_tree_element(insert_handle);
+ SceneCollection *sc_ob_parent = NULL;
+ ID *id = insert_handle->store_elem->id;
+
+ BLI_assert(action == TE_INSERT_INTO);
+ UNUSED_VARS_NDEBUG(action);
+
+ struct ObjectsSelectedData data = {
+ .objects_selected_array = {NULL, NULL},
+ };
+
+ const bool is_append = event->ctrl;
+
+ /* Make sure we include the originally inserted element as well. */
+ TREESTORE(insert_element)->flag |= TSE_SELECTED;
+
+ outliner_tree_traverse(soops, &soops->tree, 0, TSE_SELECTED, outliner_find_selected_objects, &data);
+ LISTBASE_FOREACH (LinkData *, link, &data.objects_selected_array) {
+ TreeElement *ten_selected = (TreeElement *)link->data;
+ Object *ob = (Object *)TREESTORE(ten_selected)->id;
+
+ if (is_append) {
+ BKE_collection_object_add(id, sc, ob);
+ continue;
+ }
+
+ /* Find parent scene-collection of object. */
+ if (ten_selected->parent) {
+ for (TreeElement *te_ob_parent = ten_selected->parent; te_ob_parent; te_ob_parent = te_ob_parent->parent) {
+ if (ELEM(TREESTORE(te_ob_parent)->type, TSE_SCENE_COLLECTION, TSE_LAYER_COLLECTION)) {
+ sc_ob_parent = outliner_scene_collection_from_tree_element(te_ob_parent);
+ break;
+ }
+ }
+ }
+ else {
+ sc_ob_parent = BKE_collection_master(id);
+ }
+
+ BKE_collection_object_move(id, sc, sc_ob_parent, ob);
+ }
+
+ BLI_freelistN(&data.objects_selected_array);
+
+ DEG_relations_tag_update(bmain);
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+}
+
+static bool outliner_object_reorder_poll(
+ const TreeElement *insert_element,
+ TreeElement **io_insert_handle, TreeElementInsertType *io_action)
+{
+ TreeStoreElem *tselem_handle = TREESTORE(*io_insert_handle);
+ if (ELEM(tselem_handle->type, TSE_SCENE_COLLECTION, TSE_LAYER_COLLECTION) &&
+ (insert_element->parent != *io_insert_handle))
+ {
+ *io_action = TE_INSERT_INTO;
+ return true;
+ }
+
+ return false;
}
// can be inlined if necessary
static void outliner_add_object_contents(SpaceOops *soops, TreeElement *te, TreeStoreElem *tselem, Object *ob)
{
+ te->reinsert = outliner_object_reorder;
+ te->reinsert_poll = outliner_object_reorder_poll;
+
if (outliner_animdata_test(ob->adt))
outliner_add_element(soops, &te->subtree, ob, te, TSE_ANIM_DATA, 0);
-
+
outliner_add_element(soops, &te->subtree, ob->poselib, te, 0, 0); // XXX FIXME.. add a special type for this
if (ob->proxy && !ID_IS_LINKED(ob))
@@ -719,14 +659,9 @@ static void outliner_add_id_contents(SpaceOops *soops, TreeElement *te, TreeStor
case ID_MA:
{
Material *ma = (Material *)id;
- int a;
if (outliner_animdata_test(ma->adt))
outliner_add_element(soops, &te->subtree, ma, te, TSE_ANIM_DATA, 0);
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) outliner_add_element(soops, &te->subtree, ma->mtex[a]->tex, te, 0, a);
- }
break;
}
case ID_TE:
@@ -760,14 +695,9 @@ static void outliner_add_id_contents(SpaceOops *soops, TreeElement *te, TreeStor
case ID_LA:
{
Lamp *la = (Lamp *)id;
- int a;
if (outliner_animdata_test(la->adt))
outliner_add_element(soops, &te->subtree, la, te, TSE_ANIM_DATA, 0);
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (la->mtex[a]) outliner_add_element(soops, &te->subtree, la->mtex[a]->tex, te, 0, a);
- }
break;
}
case ID_SPK:
@@ -778,17 +708,20 @@ static void outliner_add_id_contents(SpaceOops *soops, TreeElement *te, TreeStor
outliner_add_element(soops, &te->subtree, spk, te, TSE_ANIM_DATA, 0);
break;
}
+ case ID_LP:
+ {
+ LightProbe *prb = (LightProbe *)id;
+
+ if (outliner_animdata_test(prb->adt))
+ outliner_add_element(soops, &te->subtree, prb, te, TSE_ANIM_DATA, 0);
+ break;
+ }
case ID_WO:
{
World *wrld = (World *)id;
- int a;
if (outliner_animdata_test(wrld->adt))
outliner_add_element(soops, &te->subtree, wrld, te, TSE_ANIM_DATA, 0);
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (wrld->mtex[a]) outliner_add_element(soops, &te->subtree, wrld->mtex[a]->tex, te, 0, a);
- }
break;
}
case ID_KE:
@@ -905,7 +838,7 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
id = TREESTORE(parent)->id;
}
- /* One exception */
+ /* exceptions */
if (type == TSE_ID_BASE) {
/* pass */
}
@@ -943,6 +876,9 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
else if (type == TSE_GP_LAYER) {
/* pass */
}
+ else if (ELEM(type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION)) {
+ /* pass */
+ }
else if (type == TSE_ID_BASE) {
/* pass */
}
@@ -1241,9 +1177,23 @@ static TreeElement *outliner_add_element(SpaceOops *soops, ListBase *lb, void *i
te->flag |= TE_LAZY_CLOSED;
}
+ if ((type != TSE_LAYER_COLLECTION) && (te->idcode == ID_GR)) {
+ Group *group = (Group *)id;
+ outliner_add_layer_collections_recursive(soops, &te->subtree, id, &group->view_layer->layer_collections, NULL, true);
+ }
+
return te;
}
+/**
+ * \note Really only removes \a tselem, not it's TreeElement instance or any children.
+ */
+void outliner_remove_treestore_element(SpaceOops *soops, TreeStoreElem *tselem)
+{
+ BKE_outliner_treehash_remove_element(soops->treehash, tselem);
+ BLI_mempool_free(soops->treestore, tselem);
+}
+
/* ======================================================= */
/* Sequencer mode tree building */
@@ -1381,13 +1331,182 @@ static void outliner_add_orphaned_datablocks(Main *mainvar, SpaceOops *soops)
}
}
+static void outliner_layer_collections_reorder(
+ Main *bmain,
+ SpaceOops *UNUSED(soops),
+ TreeElement *insert_element, TreeElement *insert_handle, TreeElementInsertType action,
+ const wmEvent *UNUSED(event))
+{
+ LayerCollection *lc_insert = insert_element->directdata;
+ LayerCollection *lc_handle = insert_handle->directdata;
+ ID *id = insert_element->store_elem->id;
+
+ if (action == TE_INSERT_BEFORE) {
+ BKE_layer_collection_move_above(id, lc_handle, lc_insert);
+ }
+ else if (action == TE_INSERT_AFTER) {
+ BKE_layer_collection_move_below(id, lc_handle, lc_insert);
+ }
+ else if (action == TE_INSERT_INTO) {
+ BKE_layer_collection_move_into(id, lc_handle, lc_insert);
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ DEG_relations_tag_update(bmain);
+}
+static bool outliner_layer_collections_reorder_poll(
+ const TreeElement *insert_element,
+ TreeElement **io_insert_handle, TreeElementInsertType *UNUSED(io_action))
+{
+ const TreeStoreElem *tselem_handle = TREESTORE(*io_insert_handle);
+
+ if (tselem_handle->id != insert_element->store_elem->id) {
+ return false;
+ }
+
+ return ELEM(tselem_handle->type, TSE_LAYER_COLLECTION);
+}
+
+static void outliner_add_layer_collections_recursive(
+ SpaceOops *soops, ListBase *tree, ID *id, ListBase *layer_collections, TreeElement *parent_ten,
+ const bool show_objects)
+{
+ for (LayerCollection *collection = layer_collections->first; collection; collection = collection->next) {
+ TreeElement *ten = outliner_add_element(soops, tree, id, parent_ten, TSE_LAYER_COLLECTION, 0);
+
+ ten->name = collection->scene_collection->name;
+ ten->directdata = collection;
+ ten->reinsert = outliner_layer_collections_reorder;
+ ten->reinsert_poll = outliner_layer_collections_reorder_poll;
+
+ outliner_add_layer_collections_recursive(soops, &ten->subtree, id, &collection->layer_collections, ten, show_objects);
+ if (show_objects) {
+ for (LinkData *link = collection->object_bases.first; link; link = link->next) {
+ Base *base = (Base *)link->data;
+ TreeElement *te_object = outliner_add_element(soops, &ten->subtree, base->object, ten, 0, 0);
+ te_object->directdata = base;
+ }
+ }
+ }
+}
+
+static void outliner_add_view_layer(SpaceOops *soops, ListBase *tree, TreeElement *parent,
+ Scene *scene, ViewLayer *layer, const bool show_objects)
+{
+ outliner_add_layer_collections_recursive(soops, tree, &scene->id, &layer->layer_collections, parent, show_objects);
+}
+
+static void outliner_scene_collections_reorder(
+ Main *bmain,
+ SpaceOops *UNUSED(soops),
+ TreeElement *insert_element, TreeElement *insert_handle, TreeElementInsertType action,
+ const wmEvent *UNUSED(event))
+{
+ SceneCollection *sc_insert = insert_element->directdata;
+ SceneCollection *sc_handle = insert_handle->directdata;
+ ID *id = insert_handle->store_elem->id;
+ BLI_assert(id == insert_element->store_elem->id);
+
+ BLI_assert((action == TE_INSERT_INTO) || (sc_handle != BKE_collection_master(id)));
+ if (action == TE_INSERT_BEFORE) {
+ BKE_collection_move_above(id, sc_handle, sc_insert);
+ }
+ else if (action == TE_INSERT_AFTER) {
+ BKE_collection_move_below(id, sc_handle, sc_insert);
+ }
+ else if (action == TE_INSERT_INTO) {
+ BKE_collection_move_into(id, sc_handle, sc_insert);
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ DEG_relations_tag_update(bmain);
+}
+static bool outliner_scene_collections_reorder_poll(
+ const TreeElement *insert_element,
+ TreeElement **io_insert_handle, TreeElementInsertType *io_action)
+{
+ const TreeStoreElem *tselem_handle = TREESTORE(*io_insert_handle);
+ ID *id = tselem_handle->id;
+
+ if (id != insert_element->store_elem->id) {
+ return false;
+ }
+
+ if (!ELEM(tselem_handle->type, TSE_SCENE_COLLECTION)) {
+ return false;
+ }
+
+ SceneCollection *sc_master = BKE_collection_master(id);
+ SceneCollection *sc_handle = (*io_insert_handle)->directdata;
+
+ if (sc_handle == sc_master) {
+ /* exception: Can't insert before/after master selection, has to be one of its childs */
+ TreeElement *te_master = *io_insert_handle;
+ if (*io_action == TE_INSERT_BEFORE) {
+ /* can't go higher than master collection, insert into it */
+ *io_action = TE_INSERT_INTO;
+ }
+ else if (*io_action == TE_INSERT_AFTER) {
+ *io_insert_handle = te_master->subtree.last;
+ }
+ }
+ return true;
+}
+
+BLI_INLINE void outliner_add_scene_collection_init(TreeElement *te, Scene *scene, SceneCollection *collection)
+{
+ if (collection == scene->collection) {
+ // Don't display name of master collection
+ te->name = IFACE_("Collections");
+ }
+ else {
+ te->name = collection->name;
+ }
+
+ te->directdata = collection;
+ te->reinsert = outliner_scene_collections_reorder;
+ te->reinsert_poll = outliner_scene_collections_reorder_poll;
+}
+
+BLI_INLINE void outliner_add_scene_collection_objects(
+ SpaceOops *soops, ListBase *tree, SceneCollection *collection, TreeElement *parent)
+{
+ for (LinkData *link = collection->objects.first; link; link = link->next) {
+ outliner_add_element(soops, tree, link->data, parent, 0, 0);
+ }
+}
+
+static TreeElement *outliner_add_scene_collection_recursive(
+ SpaceOops *soops, ListBase *tree, Scene *scene, SceneCollection *scene_collection, TreeElement *parent_ten)
+{
+ TreeElement *ten = outliner_add_element(soops, tree, &scene->id, parent_ten, TSE_SCENE_COLLECTION, 0);
+ outliner_add_scene_collection_init(ten, scene, scene_collection);
+
+ if (soops->outlinevis != SO_SCENES) {
+ outliner_add_scene_collection_objects(soops, &ten->subtree, scene_collection, ten);
+ }
+
+ for (SceneCollection *scene_collection_nested = scene_collection->scene_collections.first;
+ scene_collection_nested != NULL;
+ scene_collection_nested = scene_collection_nested->next)
+ {
+ outliner_add_scene_collection_recursive(soops, &ten->subtree, scene, scene_collection_nested, ten);
+ }
+
+ return ten;
+}
+
/* ======================================================= */
/* Generic Tree Building helpers - order these are called is top to bottom */
/* Hierarchy --------------------------------------------- */
/* make sure elements are correctly nested */
-static void outliner_make_hierarchy(ListBase *lb)
+static void outliner_make_object_parent_hierarchy(ListBase *lb)
{
TreeElement *te, *ten, *tep;
TreeStoreElem *tselem;
@@ -1494,18 +1613,15 @@ static void outliner_sort(ListBase *lb)
{
TreeElement *te;
TreeStoreElem *tselem;
- int totelem = 0;
te = lb->last;
if (te == NULL) return;
tselem = TREESTORE(te);
-
+
/* sorting rules; only object lists, ID lists, or deformgroups */
- if ( ELEM(tselem->type, TSE_DEFGROUP, TSE_ID_BASE) || (tselem->type == 0 && te->idcode == ID_OB)) {
-
- /* count first */
- for (te = lb->first; te; te = te->next) totelem++;
-
+ if (ELEM(tselem->type, TSE_DEFGROUP, TSE_ID_BASE) || (tselem->type == 0 && te->idcode == ID_OB)) {
+ int totelem = BLI_listbase_count(lb);
+
if (totelem > 1) {
tTreeSort *tear = MEM_mallocN(totelem * sizeof(tTreeSort), "tree sort array");
tTreeSort *tp = tear;
@@ -1555,6 +1671,305 @@ static void outliner_sort(ListBase *lb)
/* Filtering ----------------------------------------------- */
+typedef struct OutlinerTreeElementFocus {
+ TreeStoreElem *tselem;
+ int ys;
+} OutlinerTreeElementFocus;
+
+/**
+ * Bring the outliner scrolling back to where it was in relation to the original focus element
+ * Caller is expected to handle redrawing of ARegion.
+ */
+static void outliner_restore_scrolling_position(SpaceOops *soops, ARegion *ar, OutlinerTreeElementFocus *focus)
+{
+ View2D *v2d = &ar->v2d;
+ int ytop;
+
+ if (focus->tselem != NULL) {
+ outliner_set_coordinates(ar, soops);
+
+ TreeElement *te_new = outliner_find_tree_element(&soops->tree, focus->tselem);
+
+ if (te_new != NULL) {
+ int ys_new, ys_old;
+
+ ys_new = te_new->ys;
+ ys_old = focus->ys;
+
+ ytop = v2d->cur.ymax + (ys_new - ys_old) -1;
+ if (ytop > 0) ytop = 0;
+
+ v2d->cur.ymax = (float)ytop;
+ v2d->cur.ymin = (float)(ytop - BLI_rcti_size_y(&v2d->mask));
+ }
+ else {
+ return;
+ }
+
+ soops->storeflag |= SO_TREESTORE_REDRAW;
+ }
+}
+
+static bool test_collection_callback(TreeElement *te)
+{
+ TreeStoreElem *tselem = TREESTORE(te);
+ return ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION);
+}
+
+static bool test_object_callback(TreeElement *te)
+{
+ TreeStoreElem *tselem = TREESTORE(te);
+ return ((tselem->type == 0) && (te->idcode == ID_OB));
+}
+
+/**
+ * See if TreeElement or any of its children pass the callback_test.
+ */
+static TreeElement *outliner_find_first_desired_element_at_y_recursive(
+ const SpaceOops *soops,
+ TreeElement *te,
+ const float limit,
+ bool (*callback_test)(TreeElement *))
+{
+ if (callback_test(te)) {
+ return te;
+ }
+
+ if (TSELEM_OPEN(te->store_elem, soops)) {
+ TreeElement *te_iter, *te_sub;
+ for (te_iter = te->subtree.first; te_iter; te_iter = te_iter->next) {
+ te_sub = outliner_find_first_desired_element_at_y_recursive(soops, te_iter, limit, callback_test);
+ if (te_sub != NULL) {
+ return te_sub;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Find the first element that passes a test starting from a reference vertical coordinate
+ *
+ * If the element that is in the position is not what we are looking for, keep looking for its
+ * children, siblings, and eventually, aunts, cousins, disntant families, ...
+ *
+ * Basically we keep going up and down the outliner tree from that point forward, until we find
+ * what we are looking for. If we are past the visible range and we can't find a valid element
+ * we return NULL.
+ */
+static TreeElement *outliner_find_first_desired_element_at_y(
+ const SpaceOops *soops,
+ const float view_co,
+ const float view_co_limit)
+{
+ TreeElement *te, *te_sub;
+ te = outliner_find_item_at_y(soops, &soops->tree, view_co);
+
+ bool (*callback_test)(TreeElement *);
+ if (soops->filter & SO_FILTER_NO_COLLECTION) {
+ callback_test = test_object_callback;
+ }
+ else {
+ callback_test = test_collection_callback;
+ }
+
+ while (te != NULL) {
+ te_sub = outliner_find_first_desired_element_at_y_recursive(soops, te, view_co_limit, callback_test);
+ if (te_sub != NULL) {
+ /* Skip the element if it was not visible to start with. */
+ if (te->ys + UI_UNIT_Y > view_co_limit) {
+ return te_sub;
+ }
+ else {
+ return NULL;
+ }
+ }
+
+ if (te->next) {
+ te = te->next;
+ continue;
+ }
+
+ if (te->parent == NULL) {
+ break;
+ }
+
+ while (te->parent) {
+ if (te->parent->next) {
+ te = te->parent->next;
+ break;
+ }
+ te = te->parent;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Store information of current outliner scrolling status to be restored later
+ *
+ * Finds the top-most collection visible in the outliner and populates the OutlinerTreeElementFocus
+ * struct to retrieve this element later to make sure it is in the same original position as before filtering
+ */
+static void outliner_store_scrolling_position(SpaceOops *soops, ARegion *ar, OutlinerTreeElementFocus *focus)
+{
+ TreeElement *te;
+ float limit = ar->v2d.cur.ymin;
+
+ outliner_set_coordinates(ar, soops);
+
+ te = outliner_find_first_desired_element_at_y(soops, ar->v2d.cur.ymax, limit);
+
+ if (te != NULL) {
+ focus->tselem = TREESTORE(te);
+ focus->ys = te->ys;
+ }
+ else {
+ focus->tselem = NULL;
+ }
+}
+
+static int outliner_exclude_filter_get(SpaceOops *soops)
+{
+ int exclude_filter = soops->filter & ~(SO_FILTER_OB_STATE_VISIBLE |
+ SO_FILTER_OB_STATE_SELECTED |
+ SO_FILTER_OB_STATE_ACTIVE);
+
+ if (soops->filter & SO_FILTER_SEARCH) {
+ if (soops->search_string[0] == 0) {
+ exclude_filter &= ~SO_FILTER_SEARCH;
+ }
+ }
+
+ /* Let's have this for the collection options at first. */
+ if (!SUPPORT_FILTER_OUTLINER(soops)) {
+ return (exclude_filter & SO_FILTER_SEARCH);
+ }
+
+ if ((exclude_filter & SO_FILTER_NO_OB_ALL) == 0) {
+ exclude_filter &= ~SO_FILTER_OB_TYPE;
+ }
+
+ if (exclude_filter & SO_FILTER_OB_STATE) {
+ switch (soops->filter_state) {
+ case SO_FILTER_OB_VISIBLE:
+ exclude_filter |= SO_FILTER_OB_STATE_VISIBLE;
+ break;
+ case SO_FILTER_OB_SELECTED:
+ exclude_filter |= SO_FILTER_OB_STATE_SELECTED;
+ break;
+ case SO_FILTER_OB_ACTIVE:
+ exclude_filter |= SO_FILTER_OB_STATE_ACTIVE;
+ break;
+ }
+ }
+
+ if ((exclude_filter & SO_FILTER_ANY) == 0) {
+ exclude_filter &= ~(SO_FILTER_OB_STATE);
+ }
+
+ return exclude_filter;
+}
+
+static bool outliner_element_visible_get(ViewLayer *view_layer, TreeElement *te, const int exclude_filter)
+{
+ if ((exclude_filter & SO_FILTER_ENABLE) == 0) {
+ return true;
+ }
+
+ TreeStoreElem *tselem = TREESTORE(te);
+ if ((tselem->type == 0) && (te->idcode == ID_OB)) {
+ if ((exclude_filter & SO_FILTER_NO_OBJECT)) {
+ return false;
+ }
+
+ Object *ob = (Object *)tselem->id;
+ Base *base = (Base *)te->directdata;
+ BLI_assert((base == NULL) || (base->object == ob));
+
+ if (exclude_filter & SO_FILTER_OB_TYPE) {
+ switch (ob->type) {
+ case OB_MESH:
+ if (exclude_filter & SO_FILTER_NO_OB_MESH) {
+ return false;
+ }
+ break;
+ case OB_ARMATURE:
+ if (exclude_filter & SO_FILTER_NO_OB_ARMATURE) {
+ return false;
+ }
+ break;
+ case OB_EMPTY:
+ if (exclude_filter & SO_FILTER_NO_OB_EMPTY) {
+ return false;
+ }
+ break;
+ case OB_LAMP:
+ if (exclude_filter & SO_FILTER_NO_OB_LAMP) {
+ return false;
+ }
+ break;
+ case OB_CAMERA:
+ if (exclude_filter & SO_FILTER_NO_OB_CAMERA) {
+ return false;
+ }
+ break;
+ default:
+ if (exclude_filter & SO_FILTER_NO_OB_OTHERS) {
+ return false;
+ }
+ break;
+ }
+ }
+
+ if (exclude_filter & SO_FILTER_OB_STATE) {
+ if (base == NULL) {
+ base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (base == NULL) {
+ return false;
+ }
+ }
+
+ if (exclude_filter & SO_FILTER_OB_STATE_VISIBLE) {
+ if ((base->flag & BASE_VISIBLED) == 0) {
+ return false;
+ }
+ }
+ else if (exclude_filter & SO_FILTER_OB_STATE_SELECTED) {
+ if ((base->flag & BASE_SELECTED) == 0) {
+ return false;
+ }
+ }
+ else {
+ BLI_assert(exclude_filter & SO_FILTER_OB_STATE_ACTIVE);
+ if (base != BASACT(view_layer)) {
+ return false;
+ }
+ }
+ }
+
+ if ((te->parent != NULL) &&
+ (TREESTORE(te->parent)->type == 0) && (te->parent->idcode == ID_OB))
+ {
+ if (exclude_filter & SO_FILTER_NO_CHILDREN) {
+ return false;
+ }
+ }
+ }
+ else if (te->parent != NULL &&
+ TREESTORE(te->parent)->type == 0 && te->parent->idcode == ID_OB)
+ {
+ if (exclude_filter & SO_FILTER_NO_OB_CONTENT) {
+ return false;
+ }
+ }
+
+ return true;
+}
+
static bool outliner_filter_has_name(TreeElement *te, const char *name, int flags)
{
int fn_flag = 0;
@@ -1565,31 +1980,25 @@ static bool outliner_filter_has_name(TreeElement *te, const char *name, int flag
return fnmatch(name, te->name, fn_flag) == 0;
}
-static int outliner_filter_tree(SpaceOops *soops, ListBase *lb)
+static int outliner_filter_subtree(
+ SpaceOops *soops, ViewLayer *view_layer, ListBase *lb, const char *search_string, const int exclude_filter)
{
- TreeElement *te, *ten;
+ TreeElement *te, *te_next;
TreeStoreElem *tselem;
- char search_buff[sizeof(((struct SpaceOops *)NULL)->search_string) + 2];
- char *search_string;
- /* although we don't have any search string, we return true
- * since the entire tree is ok then...
- */
- if (soops->search_string[0] == 0)
- return 1;
+ for (te = lb->first; te; te = te_next) {
+ te_next = te->next;
- if (soops->search_flags & SO_FIND_COMPLETE) {
- search_string = soops->search_string;
- }
- else {
- /* Implicitly add heading/trailing wildcards if needed. */
- BLI_strncpy_ensure_pad(search_buff, soops->search_string, '*', sizeof(search_buff));
- search_string = search_buff;
- }
+ if ((outliner_element_visible_get(view_layer, te, exclude_filter) == false)) {
+ outliner_free_tree_element(te, lb);
+ continue;
+ }
+ else if ((exclude_filter & SO_FILTER_SEARCH) == 0) {
+ /* Filter subtree too. */
+ outliner_filter_subtree(soops, view_layer, &te->subtree, search_string, exclude_filter);
+ continue;
+ }
- for (te = lb->first; te; te = ten) {
- ten = te->next;
-
if (!outliner_filter_has_name(te, search_string, soops->search_flags)) {
/* item isn't something we're looking for, but...
* - if the subtree is expanded, check if there are any matches that can be easily found
@@ -1598,41 +2007,61 @@ static int outliner_filter_tree(SpaceOops *soops, ListBase *lb)
* so these can be safely ignored (i.e. the subtree can get freed)
*/
tselem = TREESTORE(te);
-
+
/* flag as not a found item */
tselem->flag &= ~TSE_SEARCHMATCH;
- if ((!TSELEM_OPEN(tselem, soops)) || outliner_filter_tree(soops, &te->subtree) == 0) {
- outliner_free_tree(&te->subtree);
- BLI_remlink(lb, te);
-
- if (te->flag & TE_FREE_NAME) MEM_freeN((void *)te->name);
- MEM_freeN(te);
+ if ((!TSELEM_OPEN(tselem, soops)) ||
+ outliner_filter_subtree(soops, view_layer, &te->subtree, search_string, exclude_filter) == 0)
+ {
+ outliner_free_tree_element(te, lb);
}
}
else {
tselem = TREESTORE(te);
-
+
/* flag as a found item - we can then highlight it */
tselem->flag |= TSE_SEARCHMATCH;
-
+
/* filter subtree too */
- outliner_filter_tree(soops, &te->subtree);
+ outliner_filter_subtree(soops, view_layer, &te->subtree, search_string, exclude_filter);
}
}
-
+
/* if there are still items in the list, that means that there were still some matches */
return (BLI_listbase_is_empty(lb) == false);
}
+static void outliner_filter_tree(SpaceOops *soops, ViewLayer *view_layer)
+{
+ char search_buff[sizeof(((struct SpaceOops *)NULL)->search_string) + 2];
+ char *search_string;
+
+ const int exclude_filter = outliner_exclude_filter_get(soops);
+
+ if (exclude_filter == 0) {
+ return;
+ }
+
+ if (soops->search_flags & SO_FIND_COMPLETE) {
+ search_string = soops->search_string;
+ }
+ else {
+ /* Implicitly add heading/trailing wildcards if needed. */
+ BLI_strncpy_ensure_pad(search_buff, soops->search_string, '*', sizeof(search_buff));
+ search_string = search_buff;
+ }
+
+ outliner_filter_subtree(soops, view_layer, &soops->tree, search_string, exclude_filter);
+}
+
/* ======================================================= */
/* Main Tree Building API */
/* Main entry point for building the tree data-structure that the outliner represents */
// TODO: split each mode into its own function?
-void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
+void outliner_build_tree(Main *mainvar, Scene *scene, ViewLayer *view_layer, SpaceOops *soops, ARegion *ar)
{
- Base *base;
TreeElement *te = NULL, *ten;
TreeStoreElem *tselem;
int show_opened = !soops->treestore || !BLI_mempool_len(soops->treestore); /* on first view, we open scenes */
@@ -1653,6 +2082,9 @@ void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
if (soops->tree.first && (soops->storeflag & SO_TREESTORE_REDRAW))
return;
+ OutlinerTreeElementFocus focus;
+ outliner_store_scrolling_position(soops, ar, &focus);
+
outliner_free_tree(&soops->tree);
outliner_storage_cleanup(soops);
@@ -1706,81 +2138,25 @@ void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
lib->id.newid = NULL;
}
- else if (soops->outlinevis == SO_ALL_SCENES) {
+ else if (soops->outlinevis == SO_SCENES) {
Scene *sce;
for (sce = mainvar->scene.first; sce; sce = sce->id.next) {
te = outliner_add_element(soops, &soops->tree, sce, NULL, 0, 0);
tselem = TREESTORE(te);
- if (sce == scene && show_opened)
+
+ if (sce == scene && show_opened) {
tselem->flag &= ~TSE_CLOSED;
-
- for (base = sce->base.first; base; base = base->next) {
- ten = outliner_add_element(soops, &te->subtree, base->object, te, 0, 0);
- ten->directdata = base;
}
- outliner_make_hierarchy(&te->subtree);
- /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
- for (base = sce->base.first; base; base = base->next) base->object->id.newid = NULL;
- }
- }
- else if (soops->outlinevis == SO_CUR_SCENE) {
-
- outliner_add_scene_contents(soops, &soops->tree, scene, NULL);
-
- for (base = scene->base.first; base; base = base->next) {
- ten = outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
- ten->directdata = base;
- }
- outliner_make_hierarchy(&soops->tree);
- }
- else if (soops->outlinevis == SO_VISIBLE) {
- for (base = scene->base.first; base; base = base->next) {
- if (base->lay & scene->lay)
- outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
+
+ outliner_make_object_parent_hierarchy(&te->subtree);
}
- outliner_make_hierarchy(&soops->tree);
}
else if (soops->outlinevis == SO_GROUPS) {
Group *group;
- GroupObject *go;
-
for (group = mainvar->group.first; group; group = group->id.next) {
- if (group->gobject.first) {
- te = outliner_add_element(soops, &soops->tree, group, NULL, 0, 0);
-
- for (go = group->gobject.first; go; go = go->next) {
- ten = outliner_add_element(soops, &te->subtree, go->ob, te, 0, 0);
- ten->directdata = NULL; /* eh, why? */
- }
- outliner_make_hierarchy(&te->subtree);
- /* clear id.newid, to prevent objects be inserted in wrong scenes (parent in other scene) */
- for (go = group->gobject.first; go; go = go->next) go->ob->id.newid = NULL;
- }
- }
- }
- else if (soops->outlinevis == SO_SAME_TYPE) {
- Object *ob = OBACT;
- if (ob) {
- for (base = scene->base.first; base; base = base->next) {
- if (base->object->type == ob->type) {
- ten = outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
- ten->directdata = base;
- }
- }
- outliner_make_hierarchy(&soops->tree);
+ te = outliner_add_element(soops, &soops->tree, group, NULL, 0, 0);
}
}
- else if (soops->outlinevis == SO_SELECTED) {
- for (base = scene->base.first; base; base = base->next) {
- if (base->lay & scene->lay) {
- if (base->flag & SELECT) {
- ten = outliner_add_element(soops, &soops->tree, base->object, NULL, 0, 0);
- ten->directdata = base;
- }
- }
- }
- outliner_make_hierarchy(&soops->tree);
- }
else if (soops->outlinevis == SO_SEQUENCE) {
Sequence *seq;
Editing *ed = BKE_sequencer_editing_get(scene, false);
@@ -1817,30 +2193,39 @@ void outliner_build_tree(Main *mainvar, Scene *scene, SpaceOops *soops)
tselem->flag &= ~TSE_CLOSED;
}
}
- else if (soops->outlinevis == SO_USERDEF) {
- PointerRNA userdefptr;
-
- RNA_pointer_create(NULL, &RNA_UserPreferences, &U, &userdefptr);
-
- ten = outliner_add_element(soops, &soops->tree, (void *)&userdefptr, NULL, TSE_RNA_STRUCT, -1);
-
- if (show_opened) {
- tselem = TREESTORE(ten);
- tselem->flag &= ~TSE_CLOSED;
- }
- }
else if (soops->outlinevis == SO_ID_ORPHANS) {
outliner_add_orphaned_datablocks(mainvar, soops);
}
+ else if (soops->outlinevis == SO_COLLECTIONS) {
+ TreeElement *tenlay = outliner_add_element(soops, &soops->tree, scene, te, TSE_R_LAYER, 0);
+ tenlay->name = view_layer->name;
+ tenlay->directdata = view_layer;
+ TREESTORE(tenlay)->flag &= ~TSE_CLOSED;
+
+ if ((soops->filter & SO_FILTER_ENABLE) && (soops->filter & SO_FILTER_NO_COLLECTION)) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ TreeElement *te_object = outliner_add_element(soops, &tenlay->subtree, base->object, NULL, 0, 0);
+ te_object->directdata = base;
+ }
+ outliner_make_object_parent_hierarchy(&tenlay->subtree);
+ }
+ else {
+ outliner_add_view_layer(soops, &tenlay->subtree, NULL, scene, view_layer, true);
+ }
+ }
else {
- ten = outliner_add_element(soops, &soops->tree, OBACT, NULL, 0, 0);
- if (ten) ten->directdata = BASACT;
+ if (BASACT(view_layer)) {
+ ten = outliner_add_element(soops, &soops->tree, OBACT(view_layer), NULL, 0, 0);
+ ten->directdata = BASACT(view_layer);
+ }
}
if ((soops->flag & SO_SKIP_SORT_ALPHA) == 0) {
outliner_sort(&soops->tree);
}
- outliner_filter_tree(soops, &soops->tree);
+
+ outliner_filter_tree(soops, view_layer);
+ outliner_restore_scrolling_position(soops, ar, &focus);
BKE_main_id_clear_newpoins(mainvar);
}
diff --git a/source/blender/editors/space_outliner/outliner_utils.c b/source/blender/editors/space_outliner/outliner_utils.c
new file mode 100644
index 00000000000..d3f7fd7055e
--- /dev/null
+++ b/source/blender/editors/space_outliner/outliner_utils.c
@@ -0,0 +1,233 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_outliner/outliner_utils.c
+ * \ingroup spoutliner
+ */
+
+#include "BLI_utildefines.h"
+
+#include "DNA_action_types.h"
+#include "DNA_space_types.h"
+
+#include "BKE_outliner_treehash.h"
+
+#include "ED_armature.h"
+
+#include "UI_interface.h"
+
+#include "outliner_intern.h"
+
+/**
+ * Try to find an item under y-coordinate \a view_co_y (view-space).
+ * \note Recursive
+ */
+TreeElement *outliner_find_item_at_y(const SpaceOops *soops, const ListBase *tree, float view_co_y)
+{
+ for (TreeElement *te_iter = tree->first; te_iter; te_iter = te_iter->next) {
+ if (view_co_y < (te_iter->ys + UI_UNIT_Y)) {
+ if (view_co_y >= te_iter->ys) {
+ /* co_y is inside this element */
+ return te_iter;
+ }
+ else if (TSELEM_OPEN(te_iter->store_elem, soops)) {
+ /* co_y is lower than current element, possibly inside children */
+ TreeElement *te_sub = outliner_find_item_at_y(soops, &te_iter->subtree, view_co_y);
+ if (te_sub) {
+ return te_sub;
+ }
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Collapsed items can show their children as click-able icons. This function tries to find
+ * such an icon that represents the child item at x-coordinate \a view_co_x (view-space).
+ *
+ * \return a hovered child item or \a parent_te (if no hovered child found).
+ */
+TreeElement *outliner_find_item_at_x_in_row(const SpaceOops *soops, const TreeElement *parent_te, float view_co_x)
+{
+ if (!TSELEM_OPEN(TREESTORE(parent_te), soops)) { /* if parent_te is opened, it doesn't show childs in row */
+ /* no recursion, items can only display their direct children in the row */
+ for (TreeElement *child_te = parent_te->subtree.first;
+ child_te && view_co_x >= child_te->xs; /* don't look further if co_x is smaller than child position*/
+ child_te = child_te->next)
+ {
+ if ((child_te->flag & TE_ICONROW) && (view_co_x > child_te->xs) && (view_co_x < child_te->xend)) {
+ return child_te;
+ }
+ }
+ }
+
+ /* return parent if no child is hovered */
+ return (TreeElement *)parent_te;
+}
+
+/* Find specific item from the treestore */
+TreeElement *outliner_find_tree_element(ListBase *lb, const TreeStoreElem *store_elem)
+{
+ TreeElement *te, *tes;
+ for (te = lb->first; te; te = te->next) {
+ if (te->store_elem == store_elem) return te;
+ tes = outliner_find_tree_element(&te->subtree, store_elem);
+ if (tes) return tes;
+ }
+ return NULL;
+}
+
+/* tse is not in the treestore, we use its contents to find a match */
+TreeElement *outliner_find_tse(SpaceOops *soops, const TreeStoreElem *tse)
+{
+ TreeStoreElem *tselem;
+
+ if (tse->id == NULL) return NULL;
+
+ /* check if 'tse' is in treestore */
+ tselem = BKE_outliner_treehash_lookup_any(soops->treehash, tse->type, tse->nr, tse->id);
+ if (tselem)
+ return outliner_find_tree_element(&soops->tree, tselem);
+
+ return NULL;
+}
+
+/* Find treestore that refers to given ID */
+TreeElement *outliner_find_id(SpaceOops *soops, ListBase *lb, const ID *id)
+{
+ for (TreeElement *te = lb->first; te; te = te->next) {
+ TreeStoreElem *tselem = TREESTORE(te);
+ if (tselem->type == 0) {
+ if (tselem->id == id) {
+ return te;
+ }
+ /* only deeper on scene or object */
+ if (ELEM(te->idcode, ID_OB, ID_SCE) ||
+ ((soops->outlinevis == SO_GROUPS) && (te->idcode == ID_GR)))
+ {
+ TreeElement *tes = outliner_find_id(soops, &te->subtree, id);
+ if (tes) {
+ return tes;
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+TreeElement *outliner_find_posechannel(ListBase *lb, const bPoseChannel *pchan)
+{
+ for (TreeElement *te = lb->first; te; te = te->next) {
+ if (te->directdata == pchan) {
+ return te;
+ }
+
+ TreeStoreElem *tselem = TREESTORE(te);
+ if (ELEM(tselem->type, TSE_POSE_BASE, TSE_POSE_CHANNEL)) {
+ TreeElement *tes = outliner_find_posechannel(&te->subtree, pchan);
+ if (tes) {
+ return tes;
+ }
+ }
+ }
+ return NULL;
+}
+
+TreeElement *outliner_find_editbone(ListBase *lb, const EditBone *ebone)
+{
+ for (TreeElement *te = lb->first; te; te = te->next) {
+ if (te->directdata == ebone) {
+ return te;
+ }
+
+ TreeStoreElem *tselem = TREESTORE(te);
+ if (ELEM(tselem->type, 0, TSE_EBONE)) {
+ TreeElement *tes = outliner_find_editbone(&te->subtree, ebone);
+ if (tes) {
+ return tes;
+ }
+ }
+ }
+ return NULL;
+}
+
+ID *outliner_search_back(SpaceOops *UNUSED(soops), TreeElement *te, short idcode)
+{
+ TreeStoreElem *tselem;
+ te = te->parent;
+
+ while (te) {
+ tselem = TREESTORE(te);
+ if (tselem->type == 0 && te->idcode == idcode) return tselem->id;
+ te = te->parent;
+ }
+ return NULL;
+}
+
+/**
+ * Iterate over all tree elements (pre-order traversal), executing \a func callback for
+ * each tree element matching the optional filters.
+ *
+ * \param filter_te_flag: If not 0, only TreeElements with this flag will be visited.
+ * \param filter_tselem_flag: Same as \a filter_te_flag, but for the TreeStoreElem.
+ * \param func: Custom callback to execute for each visited item.
+ */
+bool outliner_tree_traverse(const SpaceOops *soops, ListBase *tree, int filter_te_flag, int filter_tselem_flag,
+ TreeTraversalFunc func, void *customdata)
+{
+ for (TreeElement *te = tree->first, *te_next; te; te = te_next) {
+ TreeTraversalAction func_retval = TRAVERSE_CONTINUE;
+ /* in case te is freed in callback */
+ TreeStoreElem *tselem = TREESTORE(te);
+ ListBase subtree = te->subtree;
+ te_next = te->next;
+
+ if (filter_te_flag && (te->flag & filter_te_flag) == 0) {
+ /* skip */
+ }
+ else if (filter_tselem_flag && (tselem->flag & filter_tselem_flag) == 0) {
+ /* skip */
+ }
+ else {
+ func_retval = func(te, customdata);
+ }
+ /* Don't access te or tselem from now on! Might've been freed... */
+
+ if (func_retval == TRAVERSE_BREAK) {
+ return false;
+ }
+
+ if (func_retval == TRAVERSE_SKIP_CHILDS) {
+ /* skip */
+ }
+ else if (!outliner_tree_traverse(soops, &subtree, filter_te_flag, filter_tselem_flag, func, customdata)) {
+ return false;
+ }
+ }
+
+ return true;
+}
diff --git a/source/blender/editors/space_outliner/space_outliner.c b/source/blender/editors/space_outliner/space_outliner.c
index 759ef4e78e4..557a0723cb4 100644
--- a/source/blender/editors/space_outliner/space_outliner.c
+++ b/source/blender/editors/space_outliner/space_outliner.c
@@ -39,6 +39,7 @@
#include "BLI_mempool.h"
#include "BKE_context.h"
+#include "BKE_layer.h"
#include "BKE_screen.h"
#include "BKE_scene.h"
#include "BKE_outliner_treehash.h"
@@ -47,6 +48,7 @@
#include "ED_screen.h"
#include "WM_api.h"
+#include "WM_message.h"
#include "WM_types.h"
#include "BIF_gl.h"
@@ -102,10 +104,14 @@ static int outliner_parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *e
if (GS(id->name) == ID_OB) {
/* Ensure item under cursor is valid drop target */
TreeElement *te = outliner_dropzone_find(soops, fmval, true);
+ TreeStoreElem *tselem = te ? TREESTORE(te) : NULL;
- if (te && te->idcode == ID_OB && TREESTORE(te)->type == 0) {
+ if (!te) {
+ /* pass */
+ }
+ else if (te->idcode == ID_OB && tselem->type == 0) {
Scene *scene;
- ID *te_id = TREESTORE(te)->id;
+ ID *te_id = tselem->id;
/* check if dropping self or parent */
if (te_id == id || (Object *)te_id == ((Object *)id)->parent)
@@ -118,9 +124,23 @@ static int outliner_parent_drop_poll(bContext *C, wmDrag *drag, const wmEvent *e
* element for object it means that all displayed objects belong to
* active scene and parenting them is allowed (sergey)
*/
- if (!scene || BKE_scene_base_find(scene, (Object *)id)) {
+ if (!scene) {
return 1;
}
+ else {
+ for (ViewLayer *view_layer = scene->view_layers.first;
+ view_layer;
+ view_layer = view_layer->next)
+ {
+ if (BKE_view_layer_base_find(view_layer, (Object *)id)) {
+ return 1;
+ }
+ }
+ }
+ }
+ else if (ELEM(tselem->type, TSE_LAYER_COLLECTION, TSE_SCENE_COLLECTION)) {
+ /* support adding object from different scene to collection */
+ return 1;
}
}
}
@@ -143,7 +163,7 @@ static int outliner_parent_clear_poll(bContext *C, wmDrag *drag, const wmEvent *
UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fmval[0], &fmval[1]);
- if (!ELEM(soops->outlinevis, SO_ALL_SCENES, SO_CUR_SCENE, SO_VISIBLE, SO_GROUPS)) {
+ if (!ELEM(soops->outlinevis, SO_SCENES, SO_GROUPS, SO_COLLECTIONS)) {
return false;
}
@@ -156,7 +176,7 @@ static int outliner_parent_clear_poll(bContext *C, wmDrag *drag, const wmEvent *
switch (te->idcode) {
case ID_SCE:
- return (ELEM(tselem->type, TSE_R_LAYER_BASE, TSE_R_LAYER, TSE_R_PASS));
+ return (ELEM(tselem->type, TSE_R_LAYER_BASE, TSE_R_LAYER));
case ID_OB:
return (ELEM(tselem->type, TSE_MODIFIER_BASE, TSE_CONSTRAINT_BASE));
/* Other codes to ignore? */
@@ -292,7 +312,9 @@ static void outliner_main_region_free(ARegion *UNUSED(ar))
}
-static void outliner_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void outliner_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -308,7 +330,9 @@ static void outliner_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(s
case ND_RENDER_OPTIONS:
case ND_SEQUENCER:
case ND_LAYER:
+ case ND_LAYER_CONTENT:
case ND_WORLD:
+ case ND_SCENEBROWSE:
ED_region_tag_redraw(ar);
break;
}
@@ -392,10 +416,33 @@ static void outliner_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(s
if (ELEM(wmn->action, NA_EDITED, NA_SELECTED))
ED_region_tag_redraw(ar);
break;
+ case NC_SCREEN:
+ if (ELEM(wmn->data, ND_LAYER)) {
+ ED_region_tag_redraw(ar);
+ }
+ break;
}
}
+static void outliner_main_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *UNUSED(scene),
+ struct bScreen *UNUSED(screen), struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ SpaceOops *soops = sa->spacedata.first;
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ if (soops->outlinevis == SO_COLLECTIONS) {
+ WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_region_tag_redraw);
+ }
+}
+
/* ************************ header outliner area region *********************** */
@@ -414,7 +461,9 @@ static void outliner_header_region_free(ARegion *UNUSED(ar))
{
}
-static void outliner_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void outliner_header_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -431,7 +480,7 @@ static void outliner_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED
/* ******************** default callbacks for outliner space ***************** */
-static SpaceLink *outliner_new(const bContext *UNUSED(C))
+static SpaceLink *outliner_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceOops *soutliner;
@@ -547,6 +596,7 @@ void ED_spacetype_outliner(void)
art->draw = outliner_main_region_draw;
art->free = outliner_main_region_free;
art->listener = outliner_main_region_listener;
+ art->message_subscribe = outliner_main_region_message_subscribe;
BLI_addhead(&st->regiontypes, art);
/* regions: header */
diff --git a/source/blender/editors/space_script/space_script.c b/source/blender/editors/space_script/space_script.c
index 4228635ccd6..767db745c33 100644
--- a/source/blender/editors/space_script/space_script.c
+++ b/source/blender/editors/space_script/space_script.c
@@ -62,7 +62,7 @@
/* ******************** default callbacks for script space ***************** */
-static SpaceLink *script_new(const bContext *UNUSED(C))
+static SpaceLink *script_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceScript *sscript;
@@ -176,7 +176,9 @@ static void script_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void script_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
+static void script_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
{
/* context changes */
// XXX - Todo, need the ScriptSpace accessible to get the python script to run.
diff --git a/source/blender/editors/space_sequencer/CMakeLists.txt b/source/blender/editors/space_sequencer/CMakeLists.txt
index 6dce962ee02..6b8108a1265 100644
--- a/source/blender/editors/space_sequencer/CMakeLists.txt
+++ b/source/blender/editors/space_sequencer/CMakeLists.txt
@@ -54,7 +54,7 @@ set(SRC
)
if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
+ add_definitions(-DWITH_AUDASPACE)
list(APPEND INC_SYS
${AUDASPACE_C_INCLUDE_DIRS}
diff --git a/source/blender/editors/space_sequencer/sequencer_add.c b/source/blender/editors/space_sequencer/sequencer_add.c
index 258cbdfaffd..caa3ba593fb 100644
--- a/source/blender/editors/space_sequencer/sequencer_add.c
+++ b/source/blender/editors/space_sequencer/sequencer_add.c
@@ -69,7 +69,7 @@
#include "BKE_sound.h"
#ifdef WITH_AUDASPACE
-# include AUD_SEQUENCE_H
+# include <AUD_Sequence.h>
#endif
/* own include */
@@ -690,7 +690,7 @@ static void sequencer_add_draw(bContext *UNUSED(C), wmOperator *op)
/* main draw call */
RNA_pointer_create(NULL, op->type->srna, op->properties, &ptr);
- uiDefAutoButsRNA(layout, &ptr, sequencer_add_draw_check_prop, '\0');
+ uiDefAutoButsRNA(layout, &ptr, sequencer_add_draw_check_prop, UI_BUT_LABEL_ALIGN_NONE, false);
/* image template */
RNA_pointer_create(NULL, &RNA_ImageFormatSettings, imf, &imf_ptr);
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c
index c3a27dad538..06ea3fceb2f 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -56,11 +56,11 @@
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
-#include "GPU_basic_shader.h"
-#include "GPU_compositing.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
#include "ED_anim_api.h"
#include "ED_gpencil.h"
@@ -194,25 +194,35 @@ void color3ubv_from_seq(Scene *curscene, Sequence *seq, unsigned char col[3])
}
}
-static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequence *seq, float x1, float y1, float x2, float y2, float stepsize)
+static void drawseqwave(View2D *v2d, const bContext *C, SpaceSeq *sseq, Scene *scene, Sequence *seq,
+ float x1, float y1, float x2, float y2, float stepsize, unsigned int pos)
{
/*
* x1 is the starting x value to draw the wave,
* x2 the end x value, same for y1 and y2
* stepsize is width of a pixel.
*/
+
+ /* offset x1 and x2 values, to match view min/max, if strip is out of bounds */
+ int x1_offset = max_ff(v2d->cur.xmin, x1);
+ int x2_offset = min_ff(v2d->cur.xmax + 1.0f, x2);
+
if (seq->sound && ((sseq->flag & SEQ_ALL_WAVEFORMS) || (seq->flag & SEQ_AUDIO_DRAW_WAVEFORM))) {
- int i, j, pos;
- int length = floor((x2 - x1) / stepsize) + 1;
- float ymid = (y1 + y2) / 2;
- float yscale = (y2 - y1) / 2;
+ int i, j, p;
+ int length = floor((x2_offset - x1_offset) / stepsize) + 1;
+ float ymid = (y1 + y2) / 2.0f;
+ float yscale = (y2 - y1) / 2.0f;
float samplestep;
float startsample, endsample;
float value1, value2;
bSound *sound = seq->sound;
SoundWaveform *waveform;
-
+
+ if (length < 2) {
+ return;
+ }
+
if (!sound->spinlock) {
sound->spinlock = MEM_mallocN(sizeof(SpinLock), "sound_spinlock");
BLI_spin_init(sound->spinlock);
@@ -245,21 +255,27 @@ static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequenc
endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp) / FPS * SOUND_WAVE_SAMPLES_PER_SECOND);
samplestep = (endsample - startsample) * stepsize / (x2 - x1);
- if (length > floor((waveform->length - startsample) / samplestep))
- length = floor((waveform->length - startsample) / samplestep);
+ length = min_ii(floor((waveform->length - startsample) / samplestep), length);
+
+ if (length < 2) {
+ return;
+ }
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
- glColor4f(1.0f, 1.0f, 1.0f, 0.5);
glEnable(GL_BLEND);
- glBegin(GL_TRIANGLE_STRIP);
+
+ immBegin(GWN_PRIM_TRI_STRIP, length * 2);
+
for (i = 0; i < length; i++) {
- float sampleoffset = startsample + i * samplestep;
- pos = sampleoffset;
+ float sampleoffset = startsample + ((x1_offset - x1) / stepsize + i) * samplestep;
+ p = sampleoffset;
- value1 = waveform->data[pos * 3];
- value2 = waveform->data[pos * 3 + 1];
+ value1 = waveform->data[p * 3];
+ value2 = waveform->data[p * 3 + 1];
if (samplestep > 1.0f) {
- for (j = pos + 1; (j < waveform->length) && (j < pos + samplestep); j++) {
+ for (j = p + 1; (j < waveform->length) && (j < p + samplestep); j++) {
if (value1 > waveform->data[j * 3])
value1 = waveform->data[j * 3];
@@ -269,34 +285,20 @@ static void drawseqwave(const bContext *C, SpaceSeq *sseq, Scene *scene, Sequenc
}
else {
/* use simple linear interpolation */
- float f = sampleoffset - pos;
- value1 = (1.0f - f) * value1 + f * waveform->data[pos * 3 + 3];
- value2 = (1.0f - f) * value2 + f * waveform->data[pos * 3 + 4];
+ float f = sampleoffset - p;
+ value1 = (1.0f - f) * value1 + f * waveform->data[p * 3 + 3];
+ value2 = (1.0f - f) * value2 + f * waveform->data[p * 3 + 4];
}
- glVertex2f(x1 + i * stepsize, ymid + value1 * yscale);
- glVertex2f(x1 + i * stepsize, ymid + value2 * yscale);
+ immVertex2f(pos, x1_offset + i * stepsize, ymid + value1 * yscale);
+ immVertex2f(pos, x1_offset + i * stepsize, ymid + value2 * yscale);
}
- glEnd();
- glDisable(GL_BLEND);
- }
-}
-static void drawmeta_stipple(int value)
-{
- if (value) {
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
-
- glEnable(GL_LINE_STIPPLE);
- glLineStipple(1, 0x8888);
- }
- else {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- glDisable(GL_LINE_STIPPLE);
+ immEnd();
+
+ glDisable(GL_BLEND);
}
}
-
static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1, float x2, float y2)
{
/* note: this used to use SEQ_BEGIN/SEQ_END, but it messes up the
@@ -327,10 +329,7 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
}
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- if (seqm->flag & SEQ_MUTE)
- drawmeta_stipple(1);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
for (seq = seqbase->first; seq; seq = seq->next) {
chan_min = min_ii(chan_min, seq->machine);
@@ -342,6 +341,10 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
col[3] = 196; /* alpha, used for all meta children */
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
for (seq = seqbase->first; seq; seq = seq->next) {
const int startdisp = seq->startdisp + offset;
const int enddisp = seq->enddisp + offset;
@@ -352,12 +355,16 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
float x2_chan = enddisp;
float y1_chan, y2_chan;
- if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
- drawmeta_stipple(1);
-
color3ubv_from_seq(scene, seq, col);
- glColor4ubv(col);
+ if ((seqm->flag & SEQ_MUTE) || (seq->flag & SEQ_MUTE)) {
+ col[3] = 64;
+ }
+ else {
+ col[3] = 196;
+ }
+
+ immUniformColor4ubv(col);
/* clamp within parent sequence strip bounds */
if (x1_chan < x1) x1_chan = x1;
@@ -366,20 +373,12 @@ static void drawmeta_contents(Scene *scene, Sequence *seqm, float x1, float y1,
y1_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSBOTTOM);
y2_chan = y1 + y_chan + (draw_height * SEQ_STRIP_OFSTOP);
- glRectf(x1_chan, y1_chan, x2_chan, y2_chan);
-
- UI_GetColorPtrShade3ubv(col, col, -30);
- glColor4ubv(col);
- fdrawbox(x1_chan, y1_chan, x2_chan, y2_chan);
-
- if ((seqm->flag & SEQ_MUTE) == 0 && (seq->flag & SEQ_MUTE))
- drawmeta_stipple(0);
+ immRectf(pos, x1_chan, y1_chan, x2_chan, y2_chan);
}
}
- if (seqm->flag & SEQ_MUTE)
- drawmeta_stipple(0);
-
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
@@ -395,7 +394,7 @@ static float draw_seq_handle_size_get_clamped(Sequence *seq, const float pixelx)
}
/* draw a handle, for each end of a sequence strip */
-static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction)
+static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_clamped, const short direction, unsigned int pos)
{
float v1[2], v2[2], v3[2], rx1 = 0, rx2 = 0; //for triangles and rect
float x1, x2, y1, y2;
@@ -435,23 +434,33 @@ static void draw_seq_handle(View2D *v2d, Sequence *seq, const float handsize_cla
{
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- if (seq->flag & whichsel) glColor4ub(0, 0, 0, 80);
- else if (seq->flag & SELECT) glColor4ub(255, 255, 255, 30);
- else glColor4ub(0, 0, 0, 22);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- glRectf(rx1, y1, rx2, y2);
-
- if (seq->flag & whichsel) glColor4ub(255, 255, 255, 200);
- else glColor4ub(0, 0, 0, 50);
+ if (seq->flag & whichsel) {
+ immUniformColor4ub(0, 0, 0, 80);
+ }
+ else if (seq->flag & SELECT) {
+ immUniformColor4ub(255, 255, 255, 30);
+ }
+ else {
+ immUniformColor4ub(0, 0, 0, 22);
+ }
- glEnable(GL_POLYGON_SMOOTH);
- glBegin(GL_TRIANGLES);
- glVertex2fv(v1); glVertex2fv(v2); glVertex2fv(v3);
- glEnd();
+ immRectf(pos, rx1, y1, rx2, y2);
- glDisable(GL_POLYGON_SMOOTH);
+ if (seq->flag & whichsel) {
+ immUniformColor4ub(255, 255, 255, 200);
+ }
+ else {
+ immUniformColor4ub(0, 0, 0, 50);
+ }
+
+ immBegin(GWN_PRIM_TRIS, 3);
+ immVertex2fv(pos, v1);
+ immVertex2fv(pos, v2);
+ immVertex2fv(pos, v3);
+ immEnd();
+
glDisable(GL_BLEND);
}
@@ -590,67 +599,10 @@ static void draw_seq_text(View2D *v2d, SpaceSeq *sseq, Sequence *seq, float x1,
UI_view2d_text_cache_add_rectf(v2d, &rect, str, str_len, col);
}
-/* draws a shaded strip, made from gradient + flat color + gradient */
-void draw_shadedstrip(Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2)
+static void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq, unsigned int pos)
{
- float ymid1, ymid2;
-
- if (seq->flag & SEQ_MUTE) {
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_HALFTONE);
- }
-
- ymid1 = (y2 - y1) * 0.25f + y1;
- ymid2 = (y2 - y1) * 0.65f + y1;
-
- glBegin(GL_QUADS);
-
- if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
- else if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -50);
- /* else UI_GetColorPtrShade3ubv(col, col, 0); */ /* DO NOTHING */
-
- glColor3ubv(col);
-
- glVertex2f(x1, y1);
- glVertex2f(x2, y1);
-
- if (seq->flag & SEQ_INVALID_EFFECT) { col[0] = 255; col[1] = 0; col[2] = 255; }
- else if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 5);
- else UI_GetColorPtrShade3ubv(col, col, -5);
-
- glColor3ubv((GLubyte *)col);
-
- glVertex2f(x2, ymid1);
- glVertex2f(x1, ymid1);
-
- glEnd();
-
- glRectf(x1, ymid1, x2, ymid2);
-
- glBegin(GL_QUADS);
-
- glVertex2f(x1, ymid2);
- glVertex2f(x2, ymid2);
-
- if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, -15);
- else UI_GetColorPtrShade3ubv(col, col, 25);
-
- glColor3ubv((GLubyte *)col);
-
- glVertex2f(x2, y2);
- glVertex2f(x1, y2);
-
- glEnd();
-
- if (seq->flag & SEQ_MUTE) {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
-}
-
-void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq)
-{
- float x1, x2, y1, y2, pixely, a;
- unsigned char col[3], blendcol[3];
+ float x1, x2, y1, y2, pixely;
+ unsigned char col[4], blendcol[3];
View2D *v2d = &ar->v2d;
x1 = seq->startdisp;
@@ -664,90 +616,82 @@ void draw_sequence_extensions(Scene *scene, ARegion *ar, Sequence *seq)
if (pixely <= 0) return; /* can happen when the view is split/resized */
blendcol[0] = blendcol[1] = blendcol[2] = 120;
-
- if (seq->startofs) {
+
+ if (seq->startofs || seq->endofs) {
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
color3ubv_from_seq(scene, seq, col);
-
+
if (seq->flag & SELECT) {
- UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
- glColor4ub(col[0], col[1], col[2], 170);
+ UI_GetColorPtrShade3ubv(col, col, -50);
+ }
+
+ if (seq->flag & SEQ_MUTE) {
+ col[3] = 64;
}
else {
- UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
- glColor4ub(col[0], col[1], col[2], 110);
+ if (seq->flag & SELECT) {
+ col[3] = 170;
+ }
+ else {
+ col[3] = 80;
+ }
}
-
- glRectf((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);
-
- if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
- else glColor4ub(col[0], col[1], col[2], 160);
-
- fdrawbox((float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1); //outline
-
- glDisable(GL_BLEND);
+ }
+
+ if (seq->startofs) {
+ immUniformColor4ubv(col);
+ immRectf(pos, (float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1);
+
+ immUniformColor3ubvAlpha(col, col[3] + 50);
+
+ imm_draw_box_wire_2d(pos, (float)(seq->start), y1 - SEQ_STRIP_OFSBOTTOM, x1, y1); /* outline */
}
if (seq->endofs) {
+ immUniformColor4ubv(col);
+ immRectf(pos, x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM);
+
+ immUniformColor3ubvAlpha(col, col[3] + 50);
+
+ imm_draw_box_wire_2d(pos, x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM); /* outline */
+ }
+
+ if (seq->startofs || seq->endofs) {
+ glDisable(GL_BLEND);
+ }
+
+ if (seq->startstill || seq->endstill) {
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
color3ubv_from_seq(scene, seq, col);
-
- if (seq->flag & SELECT) {
- UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.3, -40);
- glColor4ub(col[0], col[1], col[2], 170);
+ UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.5f, 60);
+
+ if (seq->flag & SEQ_MUTE) {
+ col[3] = 96;
}
else {
- UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.6, 0);
- glColor4ub(col[0], col[1], col[2], 110);
+ if (seq->flag & SELECT) {
+ col[3] = 255;
+ }
+ else {
+ col[3] = 170;
+ }
}
-
- glRectf(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM);
-
- if (seq->flag & SELECT) glColor4ub(col[0], col[1], col[2], 255);
- else glColor4ub(col[0], col[1], col[2], 160);
-
- fdrawbox(x2, y2, (float)(seq->start + seq->len), y2 + SEQ_STRIP_OFSBOTTOM); //outline
-
- glDisable(GL_BLEND);
+
+ immUniformColor4ubv(col);
}
+
if (seq->startstill) {
- color3ubv_from_seq(scene, seq, col);
- UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
- glColor3ubv((GLubyte *)col);
-
- draw_shadedstrip(seq, col, x1, y1, (float)(seq->start), y2);
-
- /* feint pinstripes, helps see exactly which is extended and which isn't,
- * especially when the extension is very small */
- if (seq->flag & SELECT) UI_GetColorPtrBlendShade3ubv(col, col, col, 0.0, 24);
- else UI_GetColorPtrShade3ubv(col, col, -16);
-
- glColor3ubv((GLubyte *)col);
-
- for (a = y1; a < y2; a += pixely * 2.0f) {
- fdrawline(x1, a, (float)(seq->start), a);
- }
+ immRectf(pos, x1, y1, (float)(seq->start), y2);
}
if (seq->endstill) {
- color3ubv_from_seq(scene, seq, col);
- UI_GetColorPtrBlendShade3ubv(col, blendcol, col, 0.75, 40);
- glColor3ubv((GLubyte *)col);
-
- draw_shadedstrip(seq, col, (float)(seq->start + seq->len), y1, x2, y2);
-
- /* feint pinstripes, helps see exactly which is extended and which isn't,
- * especially when the extension is very small */
- if (seq->flag & SELECT) UI_GetColorPtrShade3ubv(col, col, 24);
- else UI_GetColorPtrShade3ubv(col, col, -16);
-
- glColor3ubv((GLubyte *)col);
-
- for (a = y1; a < y2; a += pixely * 2.0f) {
- fdrawline((float)(seq->start + seq->len), a, x2, a);
- }
+ immRectf(pos, (float)(seq->start + seq->len), y1, x2, y2);
+ }
+
+ if (seq->startstill || seq->endstill) {
+ glDisable(GL_BLEND);
}
}
@@ -761,7 +705,7 @@ static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, AReg
{
View2D *v2d = &ar->v2d;
float x1, x2, y1, y2;
- unsigned char col[3], background_col[3], is_single_image;
+ unsigned char col[4], background_col[4], is_single_image;
const float handsize_clamped = draw_seq_handle_size_get_clamped(seq, pixelx);
/* we need to know if this is a single image/color or not for drawing */
@@ -773,72 +717,105 @@ static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, AReg
x2 = (seq->endstill) ? (seq->start + seq->len) : seq->enddisp;
y2 = seq->machine + SEQ_STRIP_OFSTOP;
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* get the correct color per strip type*/
//color3ubv_from_seq(scene, seq, col);
color3ubv_from_seq(scene, seq, background_col);
-
+
+ if (seq->flag & SEQ_MUTE) {
+ background_col[3] = 128;
+
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ }
+ else {
+ background_col[3] = 255;
+ }
+
+ if (seq->flag & SELECT) {
+ UI_GetColorPtrShade3ubv(background_col, background_col, -50);
+ }
+
+ immUniformColor4ubv(background_col);
+
/* draw the main strip body */
if (is_single_image) { /* single image */
- draw_shadedstrip(seq, background_col,
- BKE_sequence_tx_get_final_left(seq, false), y1,
- BKE_sequence_tx_get_final_right(seq, false), y2);
+ immRectf(pos, BKE_sequence_tx_get_final_left(seq, false), y1,
+ BKE_sequence_tx_get_final_right(seq, false), y2);
}
else { /* normal operation */
- draw_shadedstrip(seq, background_col, x1, y1, x2, y2);
+ immRectf(pos, x1, y1, x2, y2);
+ }
+
+ if (seq->flag & SEQ_MUTE) {
+ glDisable(GL_BLEND);
}
if (!is_single_image) {
if ((sseq->draw_flag & SEQ_DRAW_OFFSET_EXT) || (seq == special_seq_update)) {
- draw_sequence_extensions(scene, ar, seq);
+ draw_sequence_extensions(scene, ar, seq, pos);
}
}
- draw_seq_handle(v2d, seq, handsize_clamped, SEQ_LEFTHANDLE);
- draw_seq_handle(v2d, seq, handsize_clamped, SEQ_RIGHTHANDLE);
-
- /* draw the strip outline */
+ draw_seq_handle(v2d, seq, handsize_clamped, SEQ_LEFTHANDLE, pos);
+ draw_seq_handle(v2d, seq, handsize_clamped, SEQ_RIGHTHANDLE, pos);
+
x1 = seq->startdisp;
x2 = seq->enddisp;
/* draw sound wave */
if (seq->type == SEQ_TYPE_SOUND_RAM) {
if (!(sseq->flag & SEQ_NO_WAVEFORMS)) {
- drawseqwave(C, sseq, scene, seq, x1, y1, x2, y2, BLI_rctf_size_x(&ar->v2d.cur) / ar->winx);
+ drawseqwave(v2d, C, sseq, scene, seq, x1, y1, x2, y2, BLI_rctf_size_x(&ar->v2d.cur) / ar->winx, pos);
}
}
+ immUnbindProgram();
+
/* draw lock */
if (seq->flag & SEQ_LOCK) {
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
glEnable(GL_BLEND);
- /* light stripes */
- glColor4ub(255, 255, 255, 32);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
- glRectf(x1, y1, x2, y2);
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_DIAG_STRIPES);
+
+ immUniform4f("color1", 1.0f, 1.0f, 1.0f, 0.125f);
+ immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.125f);
+ immUniform1i("size1", 8);
+ immUniform1i("size2", 8);
- /* dark stripes */
- glColor4ub(0, 0, 0, 32);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP);
- glRectf(x1, y1, x2, y2);
+ immRectf(pos, x1, y1, x2, y2);
+
+ immUnbindProgram();
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
glDisable(GL_BLEND);
}
if (!BKE_sequence_is_valid_check(seq)) {
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
+ glEnable(GL_BLEND);
- /* panic! */
- glColor4ub(255, 0, 0, 255);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_DIAG_STRIPES);
- glRectf(x1, y1, x2, y2);
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_DIAG_STRIPES);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ immUniform4f("color1", 1.0f, 0.0f, 0.0f, 1.0f);
+ immUniform4f("color2", 0.0f, 0.0f, 0.0f, 0.0f);
+ immUniform1i("size1", 8);
+ immUniform1i("size2", 8);
+
+ immRectf(pos, x1, y1, x2, y2);
+
+ immUnbindProgram();
+
+ glDisable(GL_BLEND);
}
color3ubv_from_seq(scene, seq, col);
+
+ /* draw the strip outline */
+ color3ubv_from_seq(scene, seq, col);
if ((G.moving & G_TRANSFORM_SEQ) && (seq->flag & SELECT)) {
if (seq->flag & SEQ_OVERLAP) {
col[0] = 255; col[1] = col[2] = 40;
@@ -855,19 +832,27 @@ static void draw_seq_strip(const bContext *C, SpaceSeq *sseq, Scene *scene, AReg
drawmeta_contents(scene, seq, x1, y1, x2, y2);
}
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ /* TODO: add back stippled line for muted strips? */
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
if (seq->flag & SEQ_MUTE) {
- glEnable(GL_LINE_STIPPLE);
- glLineStipple(1, 0x8888);
+ col[3] = 96;
+
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ immUniformColor4ubv(col);
}
-
- glColor3ubv((GLubyte *)col);
-
- UI_draw_roundbox_shade_x(GL_LINE_LOOP, x1, y1, x2, y2, 0.0, 0.1, 0.0);
-
- if (seq->flag & SEQ_MUTE) {
- glDisable(GL_LINE_STIPPLE);
+ else {
+ immUniformColor3ubv(col);
}
-
+
+ imm_draw_box_wire_2d(pos, x1, y1, x2, y2); /* outline */
+
+ immUnbindProgram();
+
/* calculate if seq is long enough to print a name */
x1 = seq->startdisp + handsize_clamped;
x2 = seq->enddisp - handsize_clamped;
@@ -934,16 +919,10 @@ ImBuf *sequencer_ibuf_get(struct Main *bmain, Scene *scene, SpaceSeq *sseq, int
recty = (render_size * (float)scene->r.ysch) / 100.0f + 0.5f;
BKE_sequencer_new_render_data(
- bmain->eval_ctx, bmain, scene,
- rectx, recty, proxy_size,
+ bmain, scene,
+ rectx, recty, proxy_size, false,
&context);
context.view_id = BKE_scene_multiview_view_id_get(&scene->r, viewname);
- if (scene->r.seq_flag & R_SEQ_CAMERA_DOF) {
- if (sseq->compositor == NULL) {
- sseq->compositor = GPU_fx_compositor_create();
- }
- context.gpu_fx = sseq->compositor;
- }
/* sequencer could start rendering, in this case we need to be sure it wouldn't be canceled
* by Esc pressed somewhere in the past
@@ -1057,33 +1036,39 @@ static void sequencer_draw_borders(const SpaceSeq *sseq, const View2D *v2d, cons
glLineWidth(1.0f);
/* border */
- setlinestyle(3);
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- UI_ThemeColorBlendShade(TH_WIRE, TH_BACK, 1.0, 0);
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
- glBegin(GL_LINE_LOOP);
- glVertex2f(x1 - 0.5f, y1 - 0.5f);
- glVertex2f(x1 - 0.5f, y2 + 0.5f);
- glVertex2f(x2 + 0.5f, y2 + 0.5f);
- glVertex2f(x2 + 0.5f, y1 - 0.5f);
- glEnd();
+ immUniformThemeColor(TH_BACK);
+ immUniform1i("num_colors", 0); /* Simple dashes. */
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ imm_draw_box_wire_2d(shdr_pos, x1 - 0.5f, y1 - 0.5f, x2 + 0.5f, y2 + 0.5f);
/* safety border */
if (sseq->flag & SEQ_SHOW_SAFE_MARGINS) {
+ immUniformThemeColorBlend(TH_VIEW_OVERLAY, TH_BACK, 0.25f);
+
UI_draw_safe_areas(
- x1, x2, y1, y2,
+ shdr_pos, x1, x2, y1, y2,
scene->safe_areas.title,
scene->safe_areas.action);
if (sseq->flag & SEQ_SHOW_SAFE_CENTER) {
UI_draw_safe_areas(
- x1, x2, y1, y2,
+ shdr_pos, x1, x2, y1, y2,
scene->safe_areas.title_center,
scene->safe_areas.action_center);
}
}
- setlinestyle(0);
+ immUnbindProgram();
}
/* draws checkerboard background for transparent content */
@@ -1098,11 +1083,7 @@ static void sequencer_draw_background(
/* only draw alpha for main buffer */
if (sseq->mainb == SEQ_DRAW_IMG_IMBUF) {
if ((sseq->flag & SEQ_USE_ALPHA) && !draw_overlay) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- fdrawcheckerboard(v2d->tot.xmin, v2d->tot.ymin, v2d->tot.xmax, v2d->tot.ymax);
- glColor4f(1.0, 1.0, 1.0, 1.0);
+ imm_draw_box_checker_2d(v2d->tot.xmin, v2d->tot.ymin, v2d->tot.xmax, v2d->tot.ymax);
}
}
}
@@ -1144,9 +1125,6 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
glClear(GL_COLOR_BUFFER_BIT);
}
- /* without this colors can flicker from previous opengl state */
- glColor4ub(255, 255, 255, 255);
-
/* only initialize the preview if a render is in progress */
if (G.is_rendering)
return;
@@ -1161,15 +1139,16 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
if ((ibuf == NULL) ||
(ibuf->rect == NULL && ibuf->rect_float == NULL))
{
- /* gpencil can also be drawn without a valid imbuf */
- if ((draw_gpencil && is_imbuf) && !draw_overlay) {
- sequencer_display_size(scene, sseq, viewrect);
+ sequencer_display_size(scene, sseq, viewrect);
- sequencer_draw_background(sseq, v2d, viewrect, false);
- sequencer_draw_borders(sseq, v2d, scene);
+ sequencer_draw_background(sseq, v2d, viewrect, false);
+ sequencer_draw_borders(sseq, v2d, scene);
+ /* gpencil can also be drawn without a valid imbuf */
+ if ((draw_gpencil && is_imbuf) && !draw_overlay) {
sequencer_draw_gpencil(C);
}
+
return;
}
@@ -1238,6 +1217,18 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
sequencer_draw_background(sseq, v2d, viewrect, draw_overlay);
}
+ if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA) {
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ }
+
+ /* Format needs to be created prior to any immBindProgram call.
+ * Do it here because OCIO binds it's own shader.
+ */
+ Gwn_VertFormat *imm_format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(imm_format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int texCoord = GWN_vertformat_attr_add(imm_format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
if (scope) {
IMB_freeImBuf(ibuf);
ibuf = scope;
@@ -1310,30 +1301,32 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
}
}
- glColor4f(1.0, 1.0, 1.0, 1.0);
+ if (draw_backdrop) {
+ /* XXX: need to load identity projection too? */
+ gpuPushMatrix();
+ gpuLoadIdentity();
+ }
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
glGenTextures(1, (GLuint *)&texid);
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, texid);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
if (type == GL_FLOAT)
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, ibuf->x, ibuf->y, 0, format, type, display_buffer);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, ibuf->x, ibuf->y, 0, format, type, display_buffer);
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, ibuf->x, ibuf->y, 0, format, type, display_buffer);
- if (draw_backdrop) {
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
+ if (!glsl_used) {
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_COLOR);
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
+ immUniform1i("image", 0);
}
- glBegin(GL_QUADS);
+
+ immBegin(GWN_PRIM_TRI_FAN, 4);
if (draw_overlay) {
if (sseq->overlay_type == SEQ_DRAW_OVERLAY_RECT) {
@@ -1343,16 +1336,30 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
tot_clip.xmax = v2d->tot.xmin + (fabsf(BLI_rctf_size_x(&v2d->tot)) * scene->ed->over_border.xmax);
tot_clip.ymax = v2d->tot.ymin + (fabsf(BLI_rctf_size_y(&v2d->tot)) * scene->ed->over_border.ymax);
- glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmin, tot_clip.ymin);
- glTexCoord2f(scene->ed->over_border.xmin, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmin, tot_clip.ymax);
- glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymax); glVertex2f(tot_clip.xmax, tot_clip.ymax);
- glTexCoord2f(scene->ed->over_border.xmax, scene->ed->over_border.ymin); glVertex2f(tot_clip.xmax, tot_clip.ymin);
+ immAttrib2f(texCoord, scene->ed->over_border.xmin, scene->ed->over_border.ymin);
+ immVertex2f(pos, tot_clip.xmin, tot_clip.ymin);
+
+ immAttrib2f(texCoord, scene->ed->over_border.xmin, scene->ed->over_border.ymax);
+ immVertex2f(pos, tot_clip.xmin, tot_clip.ymax);
+
+ immAttrib2f(texCoord, scene->ed->over_border.xmax, scene->ed->over_border.ymax);
+ immVertex2f(pos, tot_clip.xmax, tot_clip.ymax);
+
+ immAttrib2f(texCoord, scene->ed->over_border.xmax, scene->ed->over_border.ymin);
+ immVertex2f(pos, tot_clip.xmax, tot_clip.ymin);
}
else if (sseq->overlay_type == SEQ_DRAW_OVERLAY_REFERENCE) {
- glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
- glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
- glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
- glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
+ immAttrib2f(texCoord, 0.0f, 0.0f);
+ immVertex2f(pos, v2d->tot.xmin, v2d->tot.ymin);
+
+ immAttrib2f(texCoord, 0.0f, 1.0f);
+ immVertex2f(pos, v2d->tot.xmin, v2d->tot.ymax);
+
+ immAttrib2f(texCoord, 1.0f, 1.0f);
+ immVertex2f(pos, v2d->tot.xmax, v2d->tot.ymax);
+
+ immAttrib2f(texCoord, 1.0f, 0.0f);
+ immVertex2f(pos, v2d->tot.xmax, v2d->tot.ymin);
}
}
else if (draw_backdrop) {
@@ -1371,25 +1378,46 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
imagey = aspect / image_aspect;
}
- glTexCoord2f(0.0f, 0.0f); glVertex2f(-imagex, -imagey);
- glTexCoord2f(0.0f, 1.0f); glVertex2f(-imagex, imagey);
- glTexCoord2f(1.0f, 1.0f); glVertex2f(imagex, imagey);
- glTexCoord2f(1.0f, 0.0f); glVertex2f(imagex, -imagey);
+ immAttrib2f(texCoord, 0.0f, 0.0f);
+ immVertex2f(pos, -imagex, -imagey);
+
+ immAttrib2f(texCoord, 0.0f, 1.0f);
+ immVertex2f(pos, -imagex, imagey);
+
+ immAttrib2f(texCoord, 1.0f, 1.0f);
+ immVertex2f(pos, imagex, imagey);
+
+ immAttrib2f(texCoord, 1.0f, 0.0f);
+ immVertex2f(pos, imagex, -imagey);
}
else {
draw_metadata = ((sseq->flag & SEQ_SHOW_METADATA) != 0);
- glTexCoord2f(0.0f, 0.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymin);
- glTexCoord2f(0.0f, 1.0f); glVertex2f(v2d->tot.xmin, v2d->tot.ymax);
- glTexCoord2f(1.0f, 1.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymax);
- glTexCoord2f(1.0f, 0.0f); glVertex2f(v2d->tot.xmax, v2d->tot.ymin);
+ immAttrib2f(texCoord, 0.0f, 0.0f);
+ immVertex2f(pos, v2d->tot.xmin, v2d->tot.ymin);
+
+ immAttrib2f(texCoord, 0.0f, 1.0f);
+ immVertex2f(pos, v2d->tot.xmin, v2d->tot.ymax);
+
+ immAttrib2f(texCoord, 1.0f, 1.0f);
+ immVertex2f(pos, v2d->tot.xmax, v2d->tot.ymax);
+
+ immAttrib2f(texCoord, 1.0f, 0.0f);
+ immVertex2f(pos, v2d->tot.xmax, v2d->tot.ymin);
}
- glEnd();
+
+ immEnd();
glBindTexture(GL_TEXTURE_2D, 0);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA)
+
+ if (!glsl_used) {
+ immUnbindProgram();
+ }
+
+ if (sseq->mainb == SEQ_DRAW_IMG_IMBUF && sseq->flag & SEQ_USE_ALPHA) {
glDisable(GL_BLEND);
+ }
+
glDeleteTextures(1, &texid);
if (glsl_used)
@@ -1406,10 +1434,7 @@ void draw_image_seq(const bContext *C, Scene *scene, ARegion *ar, SpaceSeq *sseq
}
if (draw_backdrop) {
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
+ gpuPopMatrix();
return;
}
@@ -1483,42 +1508,42 @@ void drawprefetchseqspace(Scene *scene, ARegion *UNUSED(ar), SpaceSeq *sseq)
static void draw_seq_backdrop(View2D *v2d)
{
int i;
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* darker gray overlay over the view backdrop */
- UI_ThemeColorShade(TH_BACK, -20);
- glRectf(v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0);
+ immUniformThemeColorShade(TH_BACK, -20);
+ immRectf(pos, v2d->cur.xmin, -1.0, v2d->cur.xmax, 1.0);
/* Alternating horizontal stripes */
i = max_ii(1, ((int)v2d->cur.ymin) - 1);
- glBegin(GL_QUADS);
while (i < v2d->cur.ymax) {
- if (((int)i) & 1)
- UI_ThemeColorShade(TH_BACK, -15);
- else
- UI_ThemeColorShade(TH_BACK, -25);
-
- glVertex2f(v2d->cur.xmax, i);
- glVertex2f(v2d->cur.xmin, i);
- glVertex2f(v2d->cur.xmin, i + 1);
- glVertex2f(v2d->cur.xmax, i + 1);
+ if (i & 1) {
+ immUniformThemeColorShade(TH_BACK, -15);
+ }
+ else {
+ immUniformThemeColorShade(TH_BACK, -25);
+ }
+
+ immRectf(pos, v2d->cur.xmin, i, v2d->cur.xmax, i + 1);
- i += 1.0;
+ i++;
}
- glEnd();
-
+
/* Darker lines separating the horizontal bands */
i = max_ii(1, ((int)v2d->cur.ymin) - 1);
- UI_ThemeColor(TH_GRID);
-
- glBegin(GL_LINES);
- while (i < v2d->cur.ymax) {
- glVertex2f(v2d->cur.xmax, i);
- glVertex2f(v2d->cur.xmin, i);
-
- i += 1.0;
+ int line_ct = (int)v2d->cur.ymax - i + 1;
+ immUniformThemeColor(TH_GRID);
+ immBegin(GWN_PRIM_LINES, line_ct * 2);
+ while (line_ct--) {
+ immVertex2f(pos, v2d->cur.xmax, i);
+ immVertex2f(pos, v2d->cur.xmin, i);
}
- glEnd();
+ immEnd();
+
+ immUnbindProgram();
}
/* draw the contents of the sequencer strips view */
@@ -1534,7 +1559,7 @@ static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
/* loop through twice, first unselected, then selected */
for (j = 0; j < 2; j++) {
Sequence *seq;
- int outline_tint = (j) ? -60 : -150; /* highlighting around strip edges indicating selection */
+ int outline_tint = (j) ? 40 : -40; /* highlighting around strip edges indicating selection */
/* loop through strips, checking for those that are visible */
for (seq = ed->seqbasep->first; seq; seq = seq->next) {
@@ -1562,8 +1587,15 @@ static void draw_seq_strips(const bContext *C, Editing *ed, ARegion *ar)
if (special_seq_update) {
const Sequence *seq = special_seq_update;
glEnable(GL_BLEND);
- glColor4ub(255, 255, 255, 48);
- glRectf(seq->startdisp, seq->machine + SEQ_STRIP_OFSBOTTOM, seq->enddisp, seq->machine + SEQ_STRIP_OFSTOP);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4ub(255, 255, 255, 48);
+ immRectf(pos, seq->startdisp, seq->machine + SEQ_STRIP_OFSBOTTOM, seq->enddisp, seq->machine + SEQ_STRIP_OFSTOP);
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
}
@@ -1575,36 +1607,56 @@ static void seq_draw_sfra_efra(Scene *scene, View2D *v2d)
const int frame_end = PEFRA + 1;
glEnable(GL_BLEND);
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* draw darkened area outside of active timeline
* frame range used is preview range or scene range */
- UI_ThemeColorShadeAlpha(TH_BACK, -25, -100);
+ immUniformThemeColorShadeAlpha(TH_BACK, -25, -100);
if (frame_sta < frame_end) {
- glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)frame_sta, v2d->cur.ymax);
- glRectf((float)frame_end, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, (float)frame_sta, v2d->cur.ymax);
+ immRectf(pos, (float)frame_end, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
}
else {
- glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
+ immRectf(pos, v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
}
- UI_ThemeColorShade(TH_BACK, -60);
+ immUniformThemeColorShade(TH_BACK, -60);
+
/* thin lines where the actual frames are */
- fdrawline(frame_sta, v2d->cur.ymin, frame_sta, v2d->cur.ymax);
- fdrawline(frame_end, v2d->cur.ymin, frame_end, v2d->cur.ymax);
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, frame_sta, v2d->cur.ymin);
+ immVertex2f(pos, frame_sta, v2d->cur.ymax);
+
+ immVertex2f(pos, frame_end, v2d->cur.ymin);
+ immVertex2f(pos, frame_end, v2d->cur.ymax);
+
+ immEnd();
if (ed && !BLI_listbase_is_empty(&ed->metastack)) {
MetaStack *ms = ed->metastack.last;
- glColor4ub(255, 255, 255, 8);
- glRectf(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
+ immUniformColor4ub(255, 255, 255, 8);
+ immRectf(pos, ms->disp_range[0], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
+
+ immUniformThemeColorShade(TH_BACK, -40);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(pos, ms->disp_range[0], v2d->cur.ymin);
+ immVertex2f(pos, ms->disp_range[0], v2d->cur.ymax);
- UI_ThemeColorShade(TH_BACK, -40);
+ immVertex2f(pos, ms->disp_range[1], v2d->cur.ymin);
+ immVertex2f(pos, ms->disp_range[1], v2d->cur.ymax);
- fdrawline(ms->disp_range[0], v2d->cur.ymin, ms->disp_range[0], v2d->cur.ymax);
- fdrawline(ms->disp_range[1], v2d->cur.ymin, ms->disp_range[1], v2d->cur.ymax);
+ immEnd();
}
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
@@ -1616,7 +1668,7 @@ void draw_timeline_seq(const bContext *C, ARegion *ar)
SpaceSeq *sseq = CTX_wm_space_seq(C);
View2D *v2d = &ar->v2d;
View2DScrollers *scrollers;
- short unit = 0, flag = 0;
+ short unit = 0, cfra_flag = 0;
float col[3];
/* clear and setup matrix */
@@ -1663,9 +1715,8 @@ void draw_timeline_seq(const bContext *C, ARegion *ar)
/* current frame */
UI_view2d_view_ortho(v2d);
- if ((sseq->flag & SEQ_DRAWFRAMES) == 0) flag |= DRAWCFRA_UNIT_SECONDS;
- if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) flag |= DRAWCFRA_SHOW_NUMBOX;
- ANIM_draw_cfra(C, v2d, flag);
+ if ((sseq->flag & SEQ_DRAWFRAMES) == 0) cfra_flag |= DRAWCFRA_UNIT_SECONDS;
+ ANIM_draw_cfra(C, v2d, cfra_flag);
/* markers */
UI_view2d_view_orthoSpecial(ar, v2d, 1);
@@ -1678,16 +1729,20 @@ void draw_timeline_seq(const bContext *C, ARegion *ar)
/* overlap playhead */
if (scene->ed && scene->ed->over_flag & SEQ_EDIT_OVERLAY_SHOW) {
int cfra_over = (scene->ed->over_flag & SEQ_EDIT_OVERLAY_ABS) ? scene->ed->over_cfra : scene->r.cfra + scene->ed->over_ofs;
- glColor3f(0.2, 0.2, 0.2);
- // glRectf(cfra_over, v2d->cur.ymin, scene->ed->over_ofs + scene->r.cfra + 1, v2d->cur.ymax);
- glBegin(GL_LINES);
- glVertex2f(cfra_over, v2d->cur.ymin);
- glVertex2f(cfra_over, v2d->cur.ymax);
- glEnd();
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor3f(0.2f, 0.2f, 0.2f);
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, cfra_over, v2d->cur.ymin);
+ immVertex2f(pos, cfra_over, v2d->cur.ymax);
+ immEnd();
+
+ immUnbindProgram();
}
-
+
/* callback */
ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
@@ -1699,6 +1754,12 @@ void draw_timeline_seq(const bContext *C, ARegion *ar)
scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP);
UI_view2d_scrollers_draw(C, v2d, scrollers);
UI_view2d_scrollers_free(scrollers);
+
+ /* draw current frame number-indicator on top of scrollers */
+ if ((sseq->flag & SEQ_NO_DRAW_CFRANUM) == 0) {
+ UI_view2d_view_orthoSpecial(ar, v2d, 1);
+ ANIM_draw_cfra_number(C, v2d, cfra_flag);
+ }
}
diff --git a/source/blender/editors/space_sequencer/sequencer_edit.c b/source/blender/editors/space_sequencer/sequencer_edit.c
index 0895d28fba7..e200dffa308 100644
--- a/source/blender/editors/space_sequencer/sequencer_edit.c
+++ b/source/blender/editors/space_sequencer/sequencer_edit.c
@@ -71,7 +71,6 @@
#include "UI_view2d.h"
#include "UI_interface.h"
-
/* own include */
#include "sequencer_intern.h"
@@ -1288,7 +1287,6 @@ typedef struct SlipData {
int num_seq;
bool slow;
int slow_offset; /* offset at the point where offset was turned on */
- void *draw_handle;
NumInput num_input;
} SlipData;
@@ -1323,21 +1321,6 @@ static void transseq_restore(TransSeq *ts, Sequence *seq)
seq->len = ts->len;
}
-static void draw_slip_extensions(const bContext *C, ARegion *ar, void *data)
-{
- Scene *scene = CTX_data_scene(C);
- SlipData *td = data;
- int i;
-
- for (i = 0; i < td->num_seq; i++) {
- Sequence *seq = td->seq_array[i];
-
- if ((seq->type != SEQ_TYPE_META) && td->trim[i]) {
- draw_sequence_extensions(scene, ar, seq);
- }
- }
-}
-
static int slip_add_sequences_rec(ListBase *seqbasep, Sequence **seq_array, bool *trim, int offset, bool do_trim)
{
Sequence *seq;
@@ -1386,7 +1369,6 @@ static int sequencer_slip_invoke(bContext *C, wmOperator *op, const wmEvent *eve
SlipData *data;
Scene *scene = CTX_data_scene(C);
Editing *ed = BKE_sequencer_editing_get(scene, false);
- ARegion *ar = CTX_wm_region(C);
float mouseloc[2];
int num_seq, i;
View2D *v2d = UI_view2d_fromcontext(C);
@@ -1416,8 +1398,6 @@ static int sequencer_slip_invoke(bContext *C, wmOperator *op, const wmEvent *eve
transseq_backup(data->ts + i, data->seq_array[i]);
}
- data->draw_handle = ED_region_draw_cb_activate(ar->type, draw_slip_extensions, data, REGION_DRAW_POST_VIEW);
-
UI_view2d_region_to_view(v2d, event->mval[0], event->mval[1], &mouseloc[0], &mouseloc[1]);
copy_v2_v2_int(data->init_mouse, event->mval);
@@ -1559,7 +1539,6 @@ static int sequencer_slip_modal(bContext *C, wmOperator *op, const wmEvent *even
Scene *scene = CTX_data_scene(C);
SlipData *data = (SlipData *)op->customdata;
ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
const bool has_numInput = hasNumInput(&data->num_input);
bool handled = true;
@@ -1617,7 +1596,6 @@ static int sequencer_slip_modal(bContext *C, wmOperator *op, const wmEvent *even
case RETKEY:
case SPACEKEY:
{
- ED_region_draw_cb_exit(ar->type, data->draw_handle);
MEM_freeN(data->seq_array);
MEM_freeN(data->trim);
MEM_freeN(data->ts);
@@ -1646,8 +1624,6 @@ static int sequencer_slip_modal(bContext *C, wmOperator *op, const wmEvent *even
BKE_sequence_calc(scene, seq);
}
- ED_region_draw_cb_exit(ar->type, data->draw_handle);
-
MEM_freeN(data->seq_array);
MEM_freeN(data->ts);
MEM_freeN(data->trim);
diff --git a/source/blender/editors/space_sequencer/sequencer_intern.h b/source/blender/editors/space_sequencer/sequencer_intern.h
index 730cc117287..de7c46cc02c 100644
--- a/source/blender/editors/space_sequencer/sequencer_intern.h
+++ b/source/blender/editors/space_sequencer/sequencer_intern.h
@@ -36,6 +36,7 @@
/* internal exports only */
+struct Depsgraph;
struct Sequence;
struct bContext;
struct rctf;
@@ -56,8 +57,6 @@ struct ARegion *sequencer_has_buttons_region(struct ScrArea *sa);
void draw_timeline_seq(const struct bContext *C, struct ARegion *ar);
void draw_image_seq(const struct bContext *C, struct Scene *scene, struct ARegion *ar, struct SpaceSeq *sseq, int cfra, int offset, bool draw_overlay, bool draw_backdrop);
void color3ubv_from_seq(struct Scene *curscene, struct Sequence *seq, unsigned char col[3]);
-void draw_shadedstrip(struct Sequence *seq, unsigned char col[3], float x1, float y1, float x2, float y2);
-void draw_sequence_extensions(struct Scene *scene, struct ARegion *ar, struct Sequence *seq);
void sequencer_special_update_set(Sequence *seq);
diff --git a/source/blender/editors/space_sequencer/space_sequencer.c b/source/blender/editors/space_sequencer/space_sequencer.c
index 6b50d3fecdf..4e78e056093 100644
--- a/source/blender/editors/space_sequencer/space_sequencer.c
+++ b/source/blender/editors/space_sequencer/space_sequencer.c
@@ -53,6 +53,9 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
+
+#include "RNA_access.h"
#include "UI_interface.h"
#include "UI_resources.h"
@@ -60,8 +63,6 @@
#include "IMB_imbuf.h"
-#include "GPU_compositing.h"
-
#include "sequencer_intern.h" // own include
/**************************** common state *****************************/
@@ -112,9 +113,8 @@ static ARegion *sequencer_find_region(ScrArea *sa, short type)
/* ******************** default callbacks for sequencer space ***************** */
-static SpaceLink *sequencer_new(const bContext *C)
+static SpaceLink *sequencer_new(const ScrArea *UNUSED(sa), const Scene *scene)
{
- Scene *scene = CTX_data_scene(C);
ARegion *ar;
SpaceSeq *sseq;
@@ -220,11 +220,6 @@ static void sequencer_free(SpaceLink *sl)
if (scopes->histogram_ibuf)
IMB_freeImBuf(scopes->histogram_ibuf);
-
- if (sseq->compositor != NULL) {
- GPU_fx_compositor_destroy(sseq->compositor);
- sseq->compositor = NULL;
- }
}
@@ -344,7 +339,9 @@ static SpaceLink *sequencer_duplicate(SpaceLink *sl)
return (SpaceLink *)sseqn;
}
-static void sequencer_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void sequencer_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
/* context changes */
switch (wmn->category) {
@@ -498,7 +495,9 @@ static void sequencer_main_region_draw(const bContext *C, ARegion *ar)
draw_timeline_seq(C, ar);
}
-static void sequencer_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void sequencer_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -536,6 +535,46 @@ static void sequencer_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(
}
}
+static void sequencer_main_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *scene,
+ struct bScreen *screen, struct ScrArea *sa, struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ PointerRNA ptr;
+ RNA_pointer_create(&screen->id, &RNA_SpaceSequenceEditor, sa->spacedata.first, &ptr);
+
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ /* Timeline depends on scene properties. */
+ {
+ bool use_preview = (scene->r.flag & SCER_PRV_RANGE);
+ extern PropertyRNA rna_Scene_frame_start;
+ extern PropertyRNA rna_Scene_frame_end;
+ extern PropertyRNA rna_Scene_frame_preview_start;
+ extern PropertyRNA rna_Scene_frame_preview_end;
+ extern PropertyRNA rna_Scene_use_preview_range;
+ extern PropertyRNA rna_Scene_frame_current;
+ const PropertyRNA *props[] = {
+ use_preview ? &rna_Scene_frame_preview_start : &rna_Scene_frame_start,
+ use_preview ? &rna_Scene_frame_preview_end : &rna_Scene_frame_end,
+ &rna_Scene_use_preview_range,
+ &rna_Scene_frame_current,
+ };
+
+ PointerRNA idptr;
+ RNA_id_pointer_create(&scene->id, &idptr);
+
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ WM_msg_subscribe_rna(mbus, &idptr, props[i], &msg_sub_value_region_tag_redraw, __func__);
+ }
+ }
+}
+
/* *********************** header region ************************ */
/* add handlers, stuff you only do once or on area/region changes */
static void sequencer_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
@@ -604,7 +643,9 @@ static void sequencer_preview_region_draw(const bContext *C, ARegion *ar)
}
}
-static void sequencer_preview_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void sequencer_preview_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -670,7 +711,9 @@ static void sequencer_buttons_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void sequencer_buttons_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void sequencer_buttons_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -742,6 +785,7 @@ void ED_spacetype_sequencer(void)
art->init = sequencer_main_region_init;
art->draw = sequencer_main_region_draw;
art->listener = sequencer_main_region_listener;
+ art->message_subscribe = sequencer_main_region_message_subscribe;
art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_FRAMES | ED_KEYMAP_ANIMATION;
BLI_addhead(&st->regiontypes, art);
diff --git a/source/blender/editors/space_text/space_text.c b/source/blender/editors/space_text/space_text.c
index fcb46ced750..c0324908b60 100644
--- a/source/blender/editors/space_text/space_text.c
+++ b/source/blender/editors/space_text/space_text.c
@@ -62,7 +62,7 @@
/* ******************** default callbacks for text space ***************** */
-static SpaceLink *text_new(const bContext *UNUSED(C))
+static SpaceLink *text_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceText *stext;
@@ -125,7 +125,8 @@ static SpaceLink *text_duplicate(SpaceLink *sl)
return (SpaceLink *)stextn;
}
-static void text_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
+static void text_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
SpaceText *st = sa->spacedata.first;
diff --git a/source/blender/editors/space_text/text_draw.c b/source/blender/editors/space_text/text_draw.c
index 4eb66811c7d..3949aa928c9 100644
--- a/source/blender/editors/space_text/text_draw.c
+++ b/source/blender/editors/space_text/text_draw.c
@@ -49,6 +49,8 @@
#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -123,38 +125,38 @@ static void txt_format_text(SpaceText *st)
#endif
/* Sets the current drawing color based on the format character specified */
-static void format_draw_color(char formatchar)
+static void format_draw_color(const TextDrawContext *tdc, char formatchar)
{
switch (formatchar) {
case FMT_TYPE_WHITESPACE:
break;
case FMT_TYPE_SYMBOL:
- UI_ThemeColor(TH_SYNTAX_S);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_S);
break;
case FMT_TYPE_COMMENT:
- UI_ThemeColor(TH_SYNTAX_C);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_C);
break;
case FMT_TYPE_NUMERAL:
- UI_ThemeColor(TH_SYNTAX_N);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_N);
break;
case FMT_TYPE_STRING:
- UI_ThemeColor(TH_SYNTAX_L);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_L);
break;
case FMT_TYPE_DIRECTIVE:
- UI_ThemeColor(TH_SYNTAX_D);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_D);
break;
case FMT_TYPE_SPECIAL:
- UI_ThemeColor(TH_SYNTAX_V);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_V);
break;
case FMT_TYPE_RESERVED:
- UI_ThemeColor(TH_SYNTAX_R);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_R);
break;
case FMT_TYPE_KEYWORD:
- UI_ThemeColor(TH_SYNTAX_B);
+ UI_FontThemeColor(tdc->font_id, TH_SYNTAX_B);
break;
case FMT_TYPE_DEFAULT:
default:
- UI_ThemeColor(TH_TEXT);
+ UI_FontThemeColor(tdc->font_id, TH_TEXT);
break;
}
}
@@ -429,7 +431,7 @@ static int text_draw_wrapped(
/* Draw the visible portion of text on the overshot line */
for (a = fstart, ma = mstart; ma < mend; a++, ma += BLI_str_utf8_size_safe(str + ma)) {
if (use_syntax) {
- if (fmt_prev != format[a]) format_draw_color(fmt_prev = format[a]);
+ if (fmt_prev != format[a]) format_draw_color(tdc, fmt_prev = format[a]);
}
x += text_font_draw_character_utf8(tdc, x, y, str + ma);
fpos++;
@@ -452,7 +454,7 @@ static int text_draw_wrapped(
/* Draw the remaining text */
for (a = fstart, ma = mstart; str[ma] && y > clip_min_y; a++, ma += BLI_str_utf8_size_safe(str + ma)) {
if (use_syntax) {
- if (fmt_prev != format[a]) format_draw_color(fmt_prev = format[a]);
+ if (fmt_prev != format[a]) format_draw_color(tdc, fmt_prev = format[a]);
}
x += text_font_draw_character_utf8(tdc, x, y, str + ma);
@@ -505,7 +507,7 @@ static void text_draw(
char fmt_prev = 0xff;
for (a = 0; a < amount; a++) {
- if (format[a] != fmt_prev) format_draw_color(fmt_prev = format[a]);
+ if (format[a] != fmt_prev) format_draw_color(tdc, fmt_prev = format[a]);
x += text_font_draw_character_utf8(tdc, x, y, in + str_shift);
str_shift += BLI_str_utf8_size_safe(in + str_shift);
}
@@ -906,22 +908,23 @@ static void draw_textscroll(const SpaceText *st, rcti *scroll, rcti *back)
{
bTheme *btheme = UI_GetTheme();
uiWidgetColors wcol = btheme->tui.wcol_scroll;
- unsigned char col[4];
+ float col[4];
float rad;
-
- UI_ThemeColor(TH_BACK);
- glRecti(back->xmin, back->ymin, back->xmax, back->ymax);
+
+ /* background so highlights don't go behind the scrollbar */
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_BACK);
+ immRecti(pos, back->xmin, back->ymin, back->xmax, back->ymax);
+ immUnbindProgram();
UI_draw_widget_scroll(&wcol, scroll, &st->txtbar, (st->flags & ST_SCROLL_SELECT) ? UI_SCROLL_PRESSED : 0);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
rad = 0.4f * min_ii(BLI_rcti_size_x(&st->txtscroll), BLI_rcti_size_y(&st->txtscroll));
- UI_GetThemeColor3ubv(TH_HILITE, col);
- col[3] = 48;
- glColor4ubv(col);
- glEnable(GL_BLEND);
- UI_draw_roundbox(st->txtscroll.xmin + 1, st->txtscroll.ymin, st->txtscroll.xmax - 1, st->txtscroll.ymax, rad);
- glDisable(GL_BLEND);
+ UI_GetThemeColor3fv(TH_HILITE, col);
+ col[3] = 0.18f;
+ UI_draw_roundbox_aa(true, st->txtscroll.xmin + 1, st->txtscroll.ymin, st->txtscroll.xmax - 1, st->txtscroll.ymax, rad, col);
}
/*********************** draw documentation *******************************/
@@ -963,26 +966,32 @@ static void draw_documentation(const SpaceText *st, ARegion *ar)
boxh = (DOC_HEIGHT + 1) * (st->lheight_dpi + TXT_LINE_SPACING);
/* Draw panel */
- UI_ThemeColor(TH_BACK);
- glRecti(x, y, x + boxw, y - boxh);
- UI_ThemeColor(TH_SHADE1);
- glBegin(GL_LINE_LOOP);
- glVertex2i(x, y);
- glVertex2i(x + boxw, y);
- glVertex2i(x + boxw, y - boxh);
- glVertex2i(x, y - boxh);
- glEnd();
- glBegin(GL_LINE_LOOP);
- glVertex2i(x + boxw - 10, y - 7);
- glVertex2i(x + boxw - 4, y - 7);
- glVertex2i(x + boxw - 7, y - 2);
- glEnd();
- glBegin(GL_LINE_LOOP);
- glVertex2i(x + boxw - 10, y - boxh + 7);
- glVertex2i(x + boxw - 4, y - boxh + 7);
- glVertex2i(x + boxw - 7, y - boxh + 2);
- glEnd();
- UI_ThemeColor(TH_TEXT);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColor(TH_BACK);
+ immRecti(pos, x, y, x + boxw, y - boxh);
+ immUniformThemeColor(TH_SHADE1);
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2i(pos, x, y);
+ immVertex2i(pos, x + boxw, y);
+ immVertex2i(pos, x + boxw, y - boxh);
+ immVertex2i(pos, x, y - boxh);
+ immEnd();
+ immBegin(GWN_PRIM_LINE_LOOP, 3);
+ immVertex2i(pos, x + boxw - 10, y - 7);
+ immVertex2i(pos, x + boxw - 4, y - 7);
+ immVertex2i(pos, x + boxw - 7, y - 2);
+ immEnd();
+ immBegin(GWN_PRIM_LINE_LOOP, 3);
+ immVertex2i(pos, x + boxw - 10, y - boxh + 7);
+ immVertex2i(pos, x + boxw - 4, y - boxh + 7);
+ immVertex2i(pos, x + boxw - 7, y - boxh + 2);
+ immEnd();
+
+ immUnbindProgram();
+
+ UI_FontThemeColor(tdc.font_id, TH_TEXT);
i = 0; br = DOC_WIDTH; lines = 0; // XXX -doc_scroll;
for (p = docs; *p; p++) {
@@ -1009,11 +1018,6 @@ static void draw_documentation(const SpaceText *st, ARegion *ar)
}
if (lines >= DOC_HEIGHT) break;
}
-
- if (0 /* XXX doc_scroll*/ /* > 0 && lines < DOC_HEIGHT */) {
- // XXX doc_scroll--;
- draw_documentation(st, ar);
- }
}
#endif
@@ -1061,10 +1065,15 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
/* not needed but stands out nicer */
UI_draw_box_shadow(220, x, y - boxh, x + boxw, y);
- UI_ThemeColor(TH_SHADE1);
- glRecti(x - 1, y + 1, x + boxw + 1, y - boxh - 1);
- UI_ThemeColorShade(TH_BACK, 16);
- glRecti(x, y, x + boxw, y - boxh);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColor(TH_SHADE1);
+ immRecti(pos, x - 1, y + 1, x + boxw + 1, y - boxh - 1);
+ immUniformThemeColorShade(TH_BACK, 16);
+ immRecti(pos, x, y, x + boxw, y - boxh);
+
+ immUnbindProgram();
/* Set the top 'item' of the visible list */
for (i = 0, item = first; i < *top && item->next; i++, item = item->next) ;
@@ -1079,11 +1088,16 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
w = st->cwidth * text_get_char_pos(st, str, len);
if (item == sel) {
- UI_ThemeColor(TH_SHADE2);
- glRecti(x + margin_x, y - 3, x + margin_x + w, y + lheight - 3);
+ unsigned int posi = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColor(TH_SHADE2);
+ immRecti(posi, x + margin_x, y - 3, x + margin_x + w, y + lheight - 3);
+
+ immUnbindProgram();
}
- format_draw_color(item->type);
+ format_draw_color(tdc, item->type);
text_draw(st, tdc, str, 0, 0, x + margin_x, y - 1, NULL);
if (item == last) break;
@@ -1092,42 +1106,57 @@ static void draw_suggestion_list(const SpaceText *st, const TextDrawContext *tdc
/*********************** draw cursor ************************/
-static void draw_cursor(SpaceText *st, ARegion *ar)
+static void draw_text_decoration(SpaceText *st, ARegion *ar)
{
Text *text = st->text;
int vcurl, vcurc, vsell, vselc, hidden = 0;
int x, y, w, i;
+ int offl, offc;
const int lheight = st->lheight_dpi + TXT_LINE_SPACING;
+ /* Convert to view space character coordinates to determine if cursor is hidden */
+ wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
+ vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
+ vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
+
+ if (vselc < 0) {
+ vselc = 0;
+ hidden = 1;
+ }
+
+ if (text->curl == text->sell && text->curc == text->selc && !st->line_hlight && hidden) {
+ /* Nothing to draw here */
+ return;
+ }
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* Draw the selection */
if (text->curl != text->sell || text->curc != text->selc) {
- int offl, offc;
/* Convert all to view space character coordinates */
wrap_offset(st, ar, text->curl, text->curc, &offl, &offc);
vcurl = txt_get_span(text->lines.first, text->curl) - st->top + offl;
vcurc = text_get_char_pos(st, text->curl->line, text->curc) - st->left + offc;
- wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
- vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
- vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
if (vcurc < 0) {
vcurc = 0;
}
- if (vselc < 0) {
- vselc = 0;
- hidden = 1;
- }
-
- UI_ThemeColor(TH_SHADE2);
+
+ immUniformThemeColor(TH_SHADE2);
+
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y = ar->winy;
if (vcurl == vsell) {
y -= vcurl * lheight;
- if (vcurc < vselc)
- glRecti(x + vcurc * st->cwidth - 1, y, x + vselc * st->cwidth, y - lheight);
- else
- glRecti(x + vselc * st->cwidth - 1, y, x + vcurc * st->cwidth, y - lheight);
+
+ if (vcurc < vselc) {
+ immRecti(pos, x + vcurc * st->cwidth - 1, y, x + vselc * st->cwidth, y - lheight);
+ }
+ else {
+ immRecti(pos, x + vselc * st->cwidth - 1, y, x + vcurc * st->cwidth, y - lheight);
+ }
}
else {
int froml, fromc, tol, toc;
@@ -1143,35 +1172,24 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
y -= froml * lheight;
- glRecti(x + fromc * st->cwidth - 1, y, ar->winx, y - lheight);
+ immRecti(pos, x + fromc * st->cwidth - 1, y, ar->winx, y - lheight);
y -= lheight;
+
for (i = froml + 1; i < tol; i++) {
- glRecti(x - 4, y, ar->winx, y - lheight);
+ immRecti(pos, x - 4, y, ar->winx, y - lheight);
y -= lheight;
}
- glRecti(x - 4, y, x + toc * st->cwidth, y - lheight);
+ immRecti(pos, x - 4, y, x + toc * st->cwidth, y - lheight);
y -= lheight;
}
}
- else {
- int offl, offc;
- wrap_offset(st, ar, text->sell, text->selc, &offl, &offc);
- vsell = txt_get_span(text->lines.first, text->sell) - st->top + offl;
- vselc = text_get_char_pos(st, text->sell->line, text->selc) - st->left + offc;
-
- if (vselc < 0) {
- vselc = 0;
- hidden = 1;
- }
- }
if (st->line_hlight) {
int x1, x2, y1, y2;
if (st->wordwrap) {
int visible_lines = text_get_visible_lines(st, ar, text->sell->line);
- int offl, offc;
wrap_offset_in_line(st, ar, text->sell, text->selc, &offl, &offc);
@@ -1187,36 +1205,38 @@ static void draw_cursor(SpaceText *st, ARegion *ar)
x1 = 0; // st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
x2 = x1 + ar->winx;
- glColor4ub(255, 255, 255, 32);
-
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ immUniformColor4ub(255, 255, 255, 32);
+
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
- glRecti(x1 - 4, y1, x2, y2);
+ immRecti(pos, x1 - 4, y1, x2, y2);
glDisable(GL_BLEND);
}
}
-
+
if (!hidden) {
/* Draw the cursor itself (we draw the sel. cursor as this is the leading edge) */
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
x += vselc * st->cwidth;
y = ar->winy - vsell * lheight;
-
+
+ immUniformThemeColor(TH_HILITE);
+
if (st->overwrite) {
char ch = text->sell->line[text->selc];
-
+
y += TXT_LINE_SPACING;
w = st->cwidth;
if (ch == '\t') w *= st->tabnumber - (vselc + st->left) % st->tabnumber;
-
- UI_ThemeColor(TH_HILITE);
- glRecti(x, y - lheight - 1, x + w, y - lheight + 1);
+
+ immRecti(pos, x, y - lheight - 1, x + w, y - lheight + 1);
}
else {
- UI_ThemeColor(TH_HILITE);
- glRecti(x - 1, y, x + 1, y - lheight);
+ immRecti(pos, x - 1, y, x + 1, y - lheight);
}
}
+
+ immUnbindProgram();
}
/******************* draw matching brackets *********************/
@@ -1317,7 +1337,7 @@ static void draw_brackets(const SpaceText *st, const TextDrawContext *tdc, ARegi
if (!endl || endc == -1)
return;
- UI_ThemeColor(TH_HILITE);
+ UI_FontThemeColor(tdc->font_id, TH_HILITE);
x = st->showlinenrs ? TXT_OFFSET + TEXTXLOC : TXT_OFFSET;
y = ar->winy - st->lheight_dpi;
@@ -1422,8 +1442,11 @@ void draw_text_main(SpaceText *st, ARegion *ar)
if (st->showlinenrs) {
x = TXT_OFFSET + TEXTXLOC;
- UI_ThemeColor(TH_GRID);
- glRecti((TXT_OFFSET - 12), 0, (TXT_OFFSET - 5) + TEXTXLOC, ar->winy - 2);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_GRID);
+ immRecti(pos, (TXT_OFFSET - 12), 0, (TXT_OFFSET - 5) + TEXTXLOC, ar->winy - 2);
+ immUnbindProgram();
}
else {
st->linenrs_tot = 0; /* not used */
@@ -1432,11 +1455,11 @@ void draw_text_main(SpaceText *st, ARegion *ar)
y = ar->winy - st->lheight_dpi;
winx = ar->winx - TXT_SCROLL_WIDTH;
- /* draw cursor */
- draw_cursor(st, ar);
+ /* draw cursor, margin, selection and highlight */
+ draw_text_decoration(st, ar);
/* draw the text */
- UI_ThemeColor(TH_TEXT);
+ UI_FontThemeColor(tdc.font_id, TH_TEXT);
for (i = 0; y > clip_min_y && i < st->viewlines && tmp; i++, tmp = tmp->next) {
if (st->showsyntax && !tmp->format)
@@ -1444,16 +1467,20 @@ void draw_text_main(SpaceText *st, ARegion *ar)
if (st->showlinenrs && !wrap_skip) {
/* draw line number */
- if (tmp == text->curl)
- UI_ThemeColor(TH_HILITE);
- else
- UI_ThemeColor(TH_TEXT);
+ if (tmp == text->curl) {
+ UI_FontThemeColor(tdc.font_id, TH_HILITE);
+ }
+ else {
+ UI_FontThemeColor(tdc.font_id, TH_TEXT);
+ }
BLI_snprintf(linenr, sizeof(linenr), "%*d", st->linenrs_tot, i + linecount + 1);
/* itoa(i + linecount + 1, linenr, 10); */ /* not ansi-c :/ */
text_font_draw(&tdc, TXT_OFFSET - 7, y, linenr);
- UI_ThemeColor(TH_TEXT);
+ if (tmp == text->curl) {
+ UI_FontThemeColor(tdc.font_id, TH_TEXT);
+ }
}
if (st->wordwrap) {
@@ -1474,15 +1501,24 @@ void draw_text_main(SpaceText *st, ARegion *ar)
margin_column_x = x + st->cwidth * (st->margin_column - st->left);
if (margin_column_x >= x) {
- /* same color as line number background */
- UI_ThemeColor(TH_GRID);
-
- setlinestyle(1);
- glBegin(GL_LINES);
- glVertex2i(margin_column_x, 0);
- glVertex2i(margin_column_x, ar->winy - 2);
- glEnd();
- setlinestyle(0);
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformThemeColor(TH_GRID); /* same color as line number background */
+ immUniform1f("dash_width", 2.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2i(shdr_pos, margin_column_x, 0);
+ immVertex2i(shdr_pos, margin_column_x, ar->winy - 2);
+ immEnd();
+ immUnbindProgram();
}
}
diff --git a/source/blender/editors/space_text/text_ops.c b/source/blender/editors/space_text/text_ops.c
index 68338bf2337..2ce699aa6e2 100644
--- a/source/blender/editors/space_text/text_ops.c
+++ b/source/blender/editors/space_text/text_ops.c
@@ -694,7 +694,7 @@ static int text_refresh_pyconstraints_exec(bContext *UNUSED(C), wmOperator *UNUS
}
if (update) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
#endif
diff --git a/source/blender/editors/space_time/CMakeLists.txt b/source/blender/editors/space_time/CMakeLists.txt
deleted file mode 100644
index 90af405eaa8..00000000000
--- a/source/blender/editors/space_time/CMakeLists.txt
+++ /dev/null
@@ -1,46 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- ../include
- ../../blenkernel
- ../../blenlib
- ../../gpu
- ../../makesdna
- ../../makesrna
- ../../windowmanager
- ../../../../intern/guardedalloc
- ../../../../intern/glew-mx
-)
-
-set(INC_SYS
- ${GLEW_INCLUDE_PATH}
-)
-
-set(SRC
- space_time.c
- time_ops.c
-
- time_intern.h
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-blender_add_lib(bf_editor_space_time "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/space_time/space_time.c b/source/blender/editors/space_time/space_time.c
deleted file mode 100644
index f29d2b30ffe..00000000000
--- a/source/blender/editors/space_time/space_time.c
+++ /dev/null
@@ -1,833 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_time/space_time.c
- * \ingroup sptime
- */
-
-
-#include <string.h>
-#include <stdio.h>
-
-#include "DNA_cachefile_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_gpencil_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_dlrbTree.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_constraint.h"
-#include "BKE_context.h"
-#include "BKE_main.h"
-#include "BKE_modifier.h"
-#include "BKE_screen.h"
-#include "BKE_pointcache.h"
-
-#include "ED_anim_api.h"
-#include "ED_keyframes_draw.h"
-#include "ED_screen.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
-#include "UI_resources.h"
-#include "UI_view2d.h"
-#include "UI_interface.h"
-
-#include "ED_space_api.h"
-#include "ED_markers.h"
-
-#include "time_intern.h"
-
-/* ************************ main time area region *********************** */
-
-static void time_draw_sfra_efra(Scene *scene, View2D *v2d)
-{
- /* draw darkened area outside of active timeline
- * frame range used is preview range or scene range
- */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
-
- if (PSFRA < PEFRA) {
- glRectf(v2d->cur.xmin, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
- glRectf((float)PEFRA, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
- }
- else {
- glRectf(v2d->cur.xmin, v2d->cur.ymin, v2d->cur.xmax, v2d->cur.ymax);
- }
- glDisable(GL_BLEND);
-
- UI_ThemeColorShade(TH_BACK, -60);
- /* thin lines where the actual frames are */
- fdrawline((float)PSFRA, v2d->cur.ymin, (float)PSFRA, v2d->cur.ymax);
- fdrawline((float)PEFRA, v2d->cur.ymin, (float)PEFRA, v2d->cur.ymax);
-}
-
-static void time_draw_cache(SpaceTime *stime, Object *ob, Scene *scene)
-{
- PTCacheID *pid;
- ListBase pidlist;
- SpaceTimeCache *stc = stime->caches.first;
- const float cache_draw_height = (4.0f * UI_DPI_FAC * U.pixelsize);
- float yoffs = 0.f;
-
- if (!(stime->cache_display & TIME_CACHE_DISPLAY) || (!ob))
- return;
-
- BKE_ptcache_ids_from_object(&pidlist, ob, scene, 0);
-
- /* iterate over pointcaches on the active object,
- * add spacetimecache and vertex array for each */
- for (pid = pidlist.first; pid; pid = pid->next) {
- float col[4], *fp;
- int i, sta = pid->cache->startframe, end = pid->cache->endframe;
- int len = (end - sta + 1) * 4;
-
- switch (pid->type) {
- case PTCACHE_TYPE_SOFTBODY:
- if (!(stime->cache_display & TIME_CACHE_SOFTBODY)) continue;
- break;
- case PTCACHE_TYPE_PARTICLES:
- if (!(stime->cache_display & TIME_CACHE_PARTICLES)) continue;
- break;
- case PTCACHE_TYPE_CLOTH:
- if (!(stime->cache_display & TIME_CACHE_CLOTH)) continue;
- break;
- case PTCACHE_TYPE_SMOKE_DOMAIN:
- case PTCACHE_TYPE_SMOKE_HIGHRES:
- if (!(stime->cache_display & TIME_CACHE_SMOKE)) continue;
- break;
- case PTCACHE_TYPE_DYNAMICPAINT:
- if (!(stime->cache_display & TIME_CACHE_DYNAMICPAINT)) continue;
- break;
- case PTCACHE_TYPE_RIGIDBODY:
- if (!(stime->cache_display & TIME_CACHE_RIGIDBODY)) continue;
- break;
- }
-
- if (pid->cache->cached_frames == NULL)
- continue;
-
- /* make sure we have stc with correct array length */
- if (stc == NULL || MEM_allocN_len(stc->array) != len * 2 * sizeof(float)) {
- if (stc) {
- MEM_freeN(stc->array);
- }
- else {
- stc = MEM_callocN(sizeof(SpaceTimeCache), "spacetimecache");
- BLI_addtail(&stime->caches, stc);
- }
-
- stc->array = MEM_callocN(len * 2 * sizeof(float), "SpaceTimeCache array");
- }
-
- /* fill the vertex array with a quad for each cached frame */
- for (i = sta, fp = stc->array; i <= end; i++) {
- if (pid->cache->cached_frames[i - sta]) {
- fp[0] = (float)i - 0.5f;
- fp[1] = 0.0;
- fp += 2;
-
- fp[0] = (float)i - 0.5f;
- fp[1] = 1.0;
- fp += 2;
-
- fp[0] = (float)i + 0.5f;
- fp[1] = 1.0;
- fp += 2;
-
- fp[0] = (float)i + 0.5f;
- fp[1] = 0.0;
- fp += 2;
- }
- }
-
- glPushMatrix();
- glTranslatef(0.0, (float)V2D_SCROLL_HEIGHT + yoffs, 0.0);
- glScalef(1.0, cache_draw_height, 0.0);
-
- switch (pid->type) {
- case PTCACHE_TYPE_SOFTBODY:
- col[0] = 1.0; col[1] = 0.4; col[2] = 0.02;
- col[3] = 0.1;
- break;
- case PTCACHE_TYPE_PARTICLES:
- col[0] = 1.0; col[1] = 0.1; col[2] = 0.02;
- col[3] = 0.1;
- break;
- case PTCACHE_TYPE_CLOTH:
- col[0] = 0.1; col[1] = 0.1; col[2] = 0.75;
- col[3] = 0.1;
- break;
- case PTCACHE_TYPE_SMOKE_DOMAIN:
- case PTCACHE_TYPE_SMOKE_HIGHRES:
- col[0] = 0.2; col[1] = 0.2; col[2] = 0.2;
- col[3] = 0.1;
- break;
- case PTCACHE_TYPE_DYNAMICPAINT:
- col[0] = 1.0; col[1] = 0.1; col[2] = 0.75;
- col[3] = 0.1;
- break;
- case PTCACHE_TYPE_RIGIDBODY:
- col[0] = 1.0; col[1] = 0.6; col[2] = 0.0;
- col[3] = 0.1;
- break;
- default:
- col[0] = 1.0; col[1] = 0.0; col[2] = 1.0;
- col[3] = 0.1;
- BLI_assert(0);
- break;
- }
- glColor4fv(col);
-
- glEnable(GL_BLEND);
-
- glRectf((float)sta, 0.0, (float)end, 1.0);
-
- col[3] = 0.4f;
- if (pid->cache->flag & PTCACHE_BAKED) {
- col[0] -= 0.4f; col[1] -= 0.4f; col[2] -= 0.4f;
- }
- else if (pid->cache->flag & PTCACHE_OUTDATED) {
- col[0] += 0.4f; col[1] += 0.4f; col[2] += 0.4f;
- }
- glColor4fv(col);
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, stc->array);
- glDrawArrays(GL_QUADS, 0, (fp - stc->array) / 2);
- glDisableClientState(GL_VERTEX_ARRAY);
-
- glDisable(GL_BLEND);
-
- glPopMatrix();
-
- yoffs += cache_draw_height;
-
- stc = stc->next;
- }
-
- BLI_freelistN(&pidlist);
-
- /* free excessive caches */
- while (stc) {
- SpaceTimeCache *tmp = stc->next;
- BLI_remlink(&stime->caches, stc);
- MEM_freeN(stc->array);
- MEM_freeN(stc);
- stc = tmp;
- }
-}
-
-static void time_cache_free(SpaceTime *stime)
-{
- SpaceTimeCache *stc;
-
- for (stc = stime->caches.first; stc; stc = stc->next) {
- if (stc->array) {
- MEM_freeN(stc->array);
- stc->array = NULL;
- }
- }
-
- BLI_freelistN(&stime->caches);
-}
-
-static void time_cache_refresh(SpaceTime *stime)
-{
- /* Free previous caches to indicate full refresh */
- time_cache_free(stime);
-}
-
-/* helper function - find actkeycolumn that occurs on cframe, or the nearest one if not found */
-static ActKeyColumn *time_cfra_find_ak(ActKeyColumn *ak, float cframe)
-{
- ActKeyColumn *akn = NULL;
-
- /* sanity checks */
- if (ak == NULL)
- return NULL;
-
- /* check if this is a match, or whether it is in some subtree */
- if (cframe < ak->cfra)
- akn = time_cfra_find_ak(ak->left, cframe);
- else if (cframe > ak->cfra)
- akn = time_cfra_find_ak(ak->right, cframe);
-
- /* if no match found (or found match), just use the current one */
- if (akn == NULL)
- return ak;
- else
- return akn;
-}
-
-/* helper for time_draw_keyframes() */
-static void time_draw_idblock_keyframes(View2D *v2d, ID *id, short onlysel)
-{
- bDopeSheet ads = {NULL};
- DLRBT_Tree keys;
- ActKeyColumn *ak;
-
- float fac1 = (GS(id->name) == ID_GD) ? 0.8f : 0.6f; /* draw GPencil keys taller, to help distinguish them */
- float fac2 = 1.0f - fac1;
-
- float ymin = v2d->tot.ymin;
- float ymax = v2d->tot.ymax * fac1 + ymin * fac2;
-
- /* init binarytree-list for getting keyframes */
- BLI_dlrbTree_init(&keys);
-
- /* init dopesheet settings */
- if (onlysel)
- ads.filterflag |= ADS_FILTER_ONLYSEL;
-
- /* populate tree with keyframe nodes */
- switch (GS(id->name)) {
- case ID_SCE:
- scene_to_keylist(&ads, (Scene *)id, &keys, NULL);
- break;
- case ID_OB:
- ob_to_keylist(&ads, (Object *)id, &keys, NULL);
- break;
- case ID_GD:
- gpencil_to_keylist(&ads, (bGPdata *)id, &keys);
- break;
- case ID_CF:
- cachefile_to_keylist(&ads, (CacheFile *)id, &keys, NULL);
- break;
- default:
- break;
- }
-
- /* build linked-list for searching */
- BLI_dlrbTree_linkedlist_sync(&keys);
-
- /* start drawing keyframes
- * - we use the binary-search capabilities of the tree to only start from
- * the first visible keyframe (last one can then be easily checked)
- * - draw within a single GL block to be faster
- */
- glBegin(GL_LINES);
- for (ak = time_cfra_find_ak(keys.root, v2d->cur.xmin);
- (ak) && (ak->cfra <= v2d->cur.xmax);
- ak = ak->next)
- {
- glVertex2f(ak->cfra, ymin);
- glVertex2f(ak->cfra, ymax);
- }
- glEnd(); // GL_LINES
-
- /* free temp stuff */
- BLI_dlrbTree_free(&keys);
-}
-
-static void time_draw_caches_keyframes(Main *bmain, Scene *scene, View2D *v2d, bool onlysel)
-{
- CacheFile *cache_file;
-
- for (cache_file = bmain->cachefiles.first;
- cache_file;
- cache_file = cache_file->id.next)
- {
- cache_file->draw_flag &= ~CACHEFILE_KEYFRAME_DRAWN;
- }
-
- for (Base *base = scene->base.first; base; base = base->next) {
- Object *ob = base->object;
-
- ModifierData *md = modifiers_findByType(ob, eModifierType_MeshSequenceCache);
-
- if (md) {
- MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *)md;
-
- cache_file = mcmd->cache_file;
-
- if (!cache_file || (cache_file->draw_flag & CACHEFILE_KEYFRAME_DRAWN) != 0) {
- continue;
- }
-
- cache_file->draw_flag |= CACHEFILE_KEYFRAME_DRAWN;
-
- time_draw_idblock_keyframes(v2d, (ID *)cache_file, onlysel);
- }
-
- for (bConstraint *con = ob->constraints.first; con; con = con->next) {
- if (con->type != CONSTRAINT_TYPE_TRANSFORM_CACHE) {
- continue;
- }
-
- bTransformCacheConstraint *data = con->data;
-
- cache_file = data->cache_file;
-
- if (!cache_file || (cache_file->draw_flag & CACHEFILE_KEYFRAME_DRAWN) != 0) {
- continue;
- }
-
- cache_file->draw_flag |= CACHEFILE_KEYFRAME_DRAWN;
-
- time_draw_idblock_keyframes(v2d, (ID *)cache_file, onlysel);
- }
- }
-}
-
-/* draw keyframe lines for timeline */
-static void time_draw_keyframes(const bContext *C, ARegion *ar)
-{
- Scene *scene = CTX_data_scene(C);
- Object *ob = CTX_data_active_object(C);
- View2D *v2d = &ar->v2d;
- bool onlysel = ((scene->flag & SCE_KEYS_NO_SELONLY) == 0);
-
- /* set this for all keyframe lines once and for all */
- glLineWidth(1.0);
-
- /* draw cache files keyframes (if available) */
- UI_ThemeColor(TH_TIME_KEYFRAME);
- time_draw_caches_keyframes(CTX_data_main(C), scene, v2d, onlysel);
-
- /* draw grease pencil keyframes (if available) */
- UI_ThemeColor(TH_TIME_GP_KEYFRAME);
- if (scene->gpd) {
- time_draw_idblock_keyframes(v2d, (ID *)scene->gpd, onlysel);
- }
- if (ob && ob->gpd) {
- time_draw_idblock_keyframes(v2d, (ID *)ob->gpd, onlysel);
- }
-
- /* draw scene keyframes first
- * - don't try to do this when only drawing active/selected data keyframes,
- * since this can become quite slow
- */
- if (onlysel == 0) {
- /* set draw color */
- UI_ThemeColorShade(TH_TIME_KEYFRAME, -50);
- time_draw_idblock_keyframes(v2d, (ID *)scene, onlysel);
- }
-
- /* draw keyframes from selected objects
- * - only do the active object if in posemode (i.e. showing only keyframes for the bones)
- * OR the onlysel flag was set, which means that only active object's keyframes should
- * be considered
- */
- UI_ThemeColor(TH_TIME_KEYFRAME);
-
- if (ob && ((ob->mode == OB_MODE_POSE) || onlysel)) {
- /* draw keyframes for active object only */
- time_draw_idblock_keyframes(v2d, (ID *)ob, onlysel);
- }
- else {
- bool active_done = false;
-
- /* draw keyframes from all selected objects */
- CTX_DATA_BEGIN (C, Object *, obsel, selected_objects)
- {
- /* last arg is 0, since onlysel doesn't apply here... */
- time_draw_idblock_keyframes(v2d, (ID *)obsel, 0);
-
- /* if this object is the active one, set flag so that we don't draw again */
- if (obsel == ob)
- active_done = true;
- }
- CTX_DATA_END;
-
- /* if active object hasn't been done yet, draw it... */
- if (ob && (active_done == 0))
- time_draw_idblock_keyframes(v2d, (ID *)ob, 0);
- }
-}
-
-/* ---------------- */
-
-static void time_refresh(const bContext *UNUSED(C), ScrArea *sa)
-{
- /* find the main timeline region and refresh cache display*/
- ARegion *ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
- if (ar) {
- SpaceTime *stime = (SpaceTime *)sa->spacedata.first;
- time_cache_refresh(stime);
- }
-}
-
-/* editor level listener */
-static void time_listener(bScreen *UNUSED(sc), ScrArea *sa, wmNotifier *wmn)
-{
-
- /* mainly for updating cache display */
- switch (wmn->category) {
- case NC_OBJECT:
- {
- switch (wmn->data) {
- case ND_BONE_SELECT:
- case ND_BONE_ACTIVE:
- case ND_POINTCACHE:
- case ND_MODIFIER:
- case ND_PARTICLE:
- case ND_KEYS:
- ED_area_tag_refresh(sa);
- ED_area_tag_redraw(sa);
- break;
- }
- break;
- }
- case NC_SCENE:
- {
- switch (wmn->data) {
- case ND_RENDER_RESULT:
- ED_area_tag_redraw(sa);
- break;
- case ND_OB_ACTIVE:
- case ND_FRAME:
- ED_area_tag_refresh(sa);
- break;
- case ND_FRAME_RANGE:
- {
- ARegion *ar;
- Scene *scene = wmn->reference;
-
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- ar->v2d.tot.xmin = (float)(SFRA - 4);
- ar->v2d.tot.xmax = (float)(EFRA + 4);
- break;
- }
- }
- break;
- }
- }
- break;
- }
- case NC_SPACE:
- {
- switch (wmn->data) {
- case ND_SPACE_CHANGED:
- ED_area_tag_refresh(sa);
- break;
- }
- break;
- }
- case NC_WM:
- {
- switch (wmn->data) {
- case ND_FILEREAD:
- ED_area_tag_refresh(sa);
- break;
- }
- break;
- }
- }
-}
-
-/* ---------------- */
-
-/* add handlers, stuff you only do once or on area/region changes */
-static void time_main_region_init(wmWindowManager *wm, ARegion *ar)
-{
- wmKeyMap *keymap;
-
- UI_view2d_region_reinit(&ar->v2d, V2D_COMMONVIEW_CUSTOM, ar->winx, ar->winy);
-
- /* own keymap */
- keymap = WM_keymap_find(wm->defaultconf, "Timeline", SPACE_TIME, 0);
- WM_event_add_keymap_handler_bb(&ar->handlers, keymap, &ar->v2d.mask, &ar->winrct);
-}
-
-static void time_main_region_draw(const bContext *C, ARegion *ar)
-{
- /* draw entirely, view changes should be handled here */
- Scene *scene = CTX_data_scene(C);
- SpaceTime *stime = CTX_wm_space_time(C);
- Object *obact = CTX_data_active_object(C);
- View2D *v2d = &ar->v2d;
- View2DGrid *grid;
- View2DScrollers *scrollers;
- int unit, flag = 0;
-
- /* clear and setup matrix */
- UI_ThemeClearColor(TH_BACK);
- glClear(GL_COLOR_BUFFER_BIT);
-
- UI_view2d_view_ortho(v2d);
-
- /* grid */
- unit = (stime->flag & TIME_DRAWFRAMES) ? V2D_UNIT_FRAMES : V2D_UNIT_SECONDS;
- grid = UI_view2d_grid_calc(scene, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY, ar->winx, ar->winy);
- UI_view2d_grid_draw(v2d, grid, (V2D_VERTICAL_LINES | V2D_VERTICAL_AXIS));
- UI_view2d_grid_free(grid);
-
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
-
- /* start and end frame */
- time_draw_sfra_efra(scene, v2d);
-
- /* current frame */
- flag = DRAWCFRA_WIDE; /* this is only really needed on frames where there's a keyframe, but this will do... */
- if ((stime->flag & TIME_DRAWFRAMES) == 0) flag |= DRAWCFRA_UNIT_SECONDS;
- if (stime->flag & TIME_CFRA_NUM) flag |= DRAWCFRA_SHOW_NUMBOX;
- ANIM_draw_cfra(C, v2d, flag);
-
- UI_view2d_view_ortho(v2d);
-
- /* keyframes */
- time_draw_keyframes(C, ar);
-
- /* markers */
- UI_view2d_view_orthoSpecial(ar, v2d, 1);
- ED_markers_draw(C, 0);
-
- /* caches */
- time_draw_cache(stime, obact, scene);
-
- /* callback */
- UI_view2d_view_ortho(v2d);
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
-
- /* reset view matrix */
- UI_view2d_view_restore(C);
-
- /* scrollers */
- scrollers = UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_ARG_DUMMY, V2D_ARG_DUMMY);
- UI_view2d_scrollers_draw(C, v2d, scrollers);
- UI_view2d_scrollers_free(scrollers);
-}
-
-static void time_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
-{
- /* context changes */
- switch (wmn->category) {
- case NC_SPACE:
- if (wmn->data == ND_SPACE_TIME)
- ED_region_tag_redraw(ar);
- break;
-
- case NC_ANIMATION:
- ED_region_tag_redraw(ar);
- break;
-
- case NC_SCENE:
- switch (wmn->data) {
- case ND_OB_SELECT:
- case ND_OB_ACTIVE:
- case ND_FRAME:
- case ND_FRAME_RANGE:
- case ND_KEYINGSET:
- case ND_RENDER_OPTIONS:
- ED_region_tag_redraw(ar);
- break;
- }
- break;
- case NC_GPENCIL:
- if (wmn->data == ND_DATA)
- ED_region_tag_redraw(ar);
- break;
- }
-}
-
-/* ************************ header time area region *********************** */
-
-/* add handlers, stuff you only do once or on area/region changes */
-static void time_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
-{
- ED_region_header_init(ar);
-}
-
-static void time_header_region_draw(const bContext *C, ARegion *ar)
-{
- ED_region_header(C, ar);
-}
-
-static void time_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
-{
- /* context changes */
- switch (wmn->category) {
- case NC_SCREEN:
- {
- if (wmn->data == ND_ANIMPLAY)
- ED_region_tag_redraw(ar);
- break;
- }
- case NC_SCENE:
- {
- switch (wmn->data) {
- case ND_RENDER_RESULT:
- case ND_OB_SELECT:
- case ND_FRAME:
- case ND_FRAME_RANGE:
- case ND_KEYINGSET:
- case ND_RENDER_OPTIONS:
- ED_region_tag_redraw(ar);
- break;
- }
- break;
- }
- case NC_SPACE:
- {
- if (wmn->data == ND_SPACE_TIME)
- ED_region_tag_redraw(ar);
- break;
- }
- }
-}
-
-/* ******************** default callbacks for time space ***************** */
-
-static SpaceLink *time_new(const bContext *C)
-{
- Scene *scene = CTX_data_scene(C);
- ARegion *ar;
- SpaceTime *stime;
-
- stime = MEM_callocN(sizeof(SpaceTime), "inittime");
-
- stime->spacetype = SPACE_TIME;
- stime->flag |= TIME_DRAWFRAMES;
-
- /* header */
- ar = MEM_callocN(sizeof(ARegion), "header for time");
-
- BLI_addtail(&stime->regionbase, ar);
- ar->regiontype = RGN_TYPE_HEADER;
- ar->alignment = RGN_ALIGN_BOTTOM;
-
- /* main region */
- ar = MEM_callocN(sizeof(ARegion), "main region for time");
-
- BLI_addtail(&stime->regionbase, ar);
- ar->regiontype = RGN_TYPE_WINDOW;
-
- ar->v2d.tot.xmin = (float)(SFRA - 4);
- ar->v2d.tot.ymin = 0.0f;
- ar->v2d.tot.xmax = (float)(EFRA + 4);
- ar->v2d.tot.ymax = 50.0f;
-
- ar->v2d.cur = ar->v2d.tot;
-
- ar->v2d.min[0] = 1.0f;
- ar->v2d.min[1] = 50.0f;
-
- ar->v2d.max[0] = MAXFRAMEF;
- ar->v2d.max[1] = 50.0;
-
- ar->v2d.minzoom = 0.1f;
- ar->v2d.maxzoom = 10.0;
-
- ar->v2d.scroll |= (V2D_SCROLL_BOTTOM | V2D_SCROLL_SCALE_HORIZONTAL);
- ar->v2d.align |= V2D_ALIGN_NO_NEG_Y;
- ar->v2d.keepofs |= V2D_LOCKOFS_Y;
- ar->v2d.keepzoom |= V2D_LOCKZOOM_Y;
-
-
- return (SpaceLink *)stime;
-}
-
-/* not spacelink itself */
-static void time_free(SpaceLink *sl)
-{
- SpaceTime *stime = (SpaceTime *)sl;
-
- time_cache_free(stime);
-}
-/* spacetype; init callback in ED_area_initialize() */
-/* init is called to (re)initialize an existing editor (file read, screen changes) */
-/* validate spacedata, add own area level handlers */
-static void time_init(wmWindowManager *UNUSED(wm), ScrArea *sa)
-{
- SpaceTime *stime = (SpaceTime *)sa->spacedata.first;
-
- time_cache_free(stime);
-
- /* enable all cache display */
- stime->cache_display |= TIME_CACHE_DISPLAY;
- stime->cache_display |= (TIME_CACHE_SOFTBODY | TIME_CACHE_PARTICLES);
- stime->cache_display |= (TIME_CACHE_CLOTH | TIME_CACHE_SMOKE | TIME_CACHE_DYNAMICPAINT);
- stime->cache_display |= TIME_CACHE_RIGIDBODY;
-}
-
-static SpaceLink *time_duplicate(SpaceLink *sl)
-{
- SpaceTime *stime = (SpaceTime *)sl;
- SpaceTime *stimen = MEM_dupallocN(stime);
-
- BLI_listbase_clear(&stimen->caches);
-
- return (SpaceLink *)stimen;
-}
-
-/* only called once, from space_api/spacetypes.c */
-/* it defines all callbacks to maintain spaces */
-void ED_spacetype_time(void)
-{
- SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype time");
- ARegionType *art;
-
- st->spaceid = SPACE_TIME;
- strncpy(st->name, "Timeline", BKE_ST_MAXNAME);
-
- st->new = time_new;
- st->free = time_free;
- st->init = time_init;
- st->duplicate = time_duplicate;
- st->operatortypes = time_operatortypes;
- st->keymap = NULL;
- st->listener = time_listener;
- st->refresh = time_refresh;
-
- /* regions: main window */
- art = MEM_callocN(sizeof(ARegionType), "spacetype time region");
- art->regionid = RGN_TYPE_WINDOW;
- art->keymapflag = ED_KEYMAP_VIEW2D | ED_KEYMAP_MARKERS | ED_KEYMAP_ANIMATION | ED_KEYMAP_FRAMES;
-
- art->init = time_main_region_init;
- art->draw = time_main_region_draw;
- art->listener = time_main_region_listener;
- art->keymap = time_keymap;
- art->lock = 1; /* Due to pointcache, see T4960. */
- BLI_addhead(&st->regiontypes, art);
-
- /* regions: header */
- art = MEM_callocN(sizeof(ARegionType), "spacetype time region");
- art->regionid = RGN_TYPE_HEADER;
- art->prefsizey = HEADERY;
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_FRAMES | ED_KEYMAP_HEADER;
-
- art->init = time_header_region_init;
- art->draw = time_header_region_draw;
- art->listener = time_header_region_listener;
- BLI_addhead(&st->regiontypes, art);
-
- BKE_spacetype_register(st);
-}
diff --git a/source/blender/editors/space_time/time_intern.h b/source/blender/editors/space_time/time_intern.h
deleted file mode 100644
index ced36b2ac2d..00000000000
--- a/source/blender/editors/space_time/time_intern.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_time/time_intern.h
- * \ingroup sptime
- */
-
-
-#ifndef __TIME_INTERN_H__
-#define __TIME_INTERN_H__
-
-/* internal exports only */
-
-
-/* time_ops.c */
-void time_operatortypes(void);
-void time_keymap(struct wmKeyConfig *keyconf);
-
-#endif /* __TIME_INTERN_H__ */
-
diff --git a/source/blender/editors/space_time/time_ops.c b/source/blender/editors/space_time/time_ops.c
deleted file mode 100644
index 872793128f0..00000000000
--- a/source/blender/editors/space_time/time_ops.c
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_time/time_ops.c
- * \ingroup sptime
- */
-
-
-#include <stdlib.h>
-#include <math.h>
-
-#include "DNA_scene_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_context.h"
-
-#include "ED_anim_api.h"
-#include "ED_screen.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "time_intern.h"
-
-/* ****************** Start/End Frame Operators *******************************/
-static int time_set_sfra_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Scene *scene = CTX_data_scene(C);
- int frame;
-
- if (scene == NULL)
- return OPERATOR_CANCELLED;
-
- frame = CFRA;
-
- /* if Preview Range is defined, set the 'start' frame for that */
- if (PRVRANGEON)
- scene->r.psfra = frame;
- else
- scene->r.sfra = frame;
-
- if (PEFRA < frame) {
- if (PRVRANGEON)
- scene->r.pefra = frame;
- else
- scene->r.efra = frame;
- }
-
- WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
-
- return OPERATOR_FINISHED;
-}
-
-static void TIME_OT_start_frame_set(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Set Start Frame";
- ot->idname = "TIME_OT_start_frame_set";
- ot->description = "Set the start frame";
-
- /* api callbacks */
- ot->exec = time_set_sfra_exec;
- ot->poll = ED_operator_timeline_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-
-static int time_set_efra_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Scene *scene = CTX_data_scene(C);
- int frame;
-
- if (scene == NULL)
- return OPERATOR_CANCELLED;
-
- frame = CFRA;
-
- /* if Preview Range is defined, set the 'end' frame for that */
- if (PRVRANGEON)
- scene->r.pefra = frame;
- else
- scene->r.efra = frame;
-
- if (PSFRA > frame) {
- if (PRVRANGEON)
- scene->r.psfra = frame;
- else
- scene->r.sfra = frame;
- }
-
- WM_event_add_notifier(C, NC_SCENE | ND_FRAME, scene);
-
- return OPERATOR_FINISHED;
-}
-
-static void TIME_OT_end_frame_set(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Set End Frame";
- ot->idname = "TIME_OT_end_frame_set";
- ot->description = "Set the end frame";
-
- /* api callbacks */
- ot->exec = time_set_efra_exec;
- ot->poll = ED_operator_timeline_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/* ************************ View All Operator *******************************/
-
-static int time_view_all_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Scene *scene = CTX_data_scene(C);
- ARegion *ar = CTX_wm_region(C);
-
- if (ELEM(NULL, scene, ar))
- return OPERATOR_CANCELLED;
-
- View2D *v2d = &ar->v2d;
-
- /* set extents of view to start/end frames (Preview Range too) */
- v2d->cur.xmin = (float)PSFRA;
- v2d->cur.xmax = (float)PEFRA;
-
- /* we need an extra "buffer" factor on either side so that the endpoints are visible */
- const float extra = 0.01f * BLI_rctf_size_x(&v2d->cur);
- v2d->cur.xmin -= extra;
- v2d->cur.xmax += extra;
-
- /* this only affects this TimeLine instance, so just force redraw of this region */
- ED_region_tag_redraw(ar);
-
- return OPERATOR_FINISHED;
-}
-
-static void TIME_OT_view_all(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "View All";
- ot->idname = "TIME_OT_view_all";
- ot->description = "Show the entire playable frame range";
-
- /* api callbacks */
- ot->exec = time_view_all_exec;
- ot->poll = ED_operator_timeline_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/* ************************ View Frame Operator *******************************/
-
-static int time_view_frame_exec(bContext *C, wmOperator *op)
-{
- const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
- ANIM_center_frame(C, smooth_viewtx);
-
- return OPERATOR_FINISHED;
-}
-
-static void TIME_OT_view_frame(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "View Frame";
- ot->idname = "TIME_OT_view_frame";
- ot->description = "Reset viewable area to show range around current frame";
-
- /* api callbacks */
- ot->exec = time_view_frame_exec;
- ot->poll = ED_operator_timeline_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-}
-
-/* ************************** registration **********************************/
-
-void time_operatortypes(void)
-{
- WM_operatortype_append(TIME_OT_start_frame_set);
- WM_operatortype_append(TIME_OT_end_frame_set);
- WM_operatortype_append(TIME_OT_view_all);
- WM_operatortype_append(TIME_OT_view_frame);
-}
-
-void time_keymap(wmKeyConfig *keyconf)
-{
- wmKeyMap *keymap = WM_keymap_find(keyconf, "Timeline", SPACE_TIME, 0);
-
- WM_keymap_add_item(keymap, "TIME_OT_start_frame_set", SKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "TIME_OT_end_frame_set", EKEY, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "TIME_OT_view_all", HOMEKEY, KM_PRESS, 0, 0);
-#ifdef WITH_INPUT_NDOF
- WM_keymap_add_item(keymap, "TIME_OT_view_all", NDOF_BUTTON_FIT, KM_PRESS, 0, 0);
-#endif
- WM_keymap_add_item(keymap, "TIME_OT_view_frame", PAD0, KM_PRESS, 0, 0);
-}
-
diff --git a/source/blender/editors/space_topbar/CMakeLists.txt b/source/blender/editors/space_topbar/CMakeLists.txt
new file mode 100644
index 00000000000..9559c28de0a
--- /dev/null
+++ b/source/blender/editors/space_topbar/CMakeLists.txt
@@ -0,0 +1,45 @@
+# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Contributor(s): Jacques Beaurain.
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ ../include
+ ../../blenkernel
+ ../../blenlib
+ ../../blenloader
+ ../../blentranslation
+ ../../gpu
+ ../../makesdna
+ ../../makesrna
+ ../../windowmanager
+ ../../../../intern/guardedalloc
+ ../../../../intern/glew-mx
+)
+
+set(INC_SYS
+ ${GLEW_INCLUDE_PATH}
+)
+
+set(SRC
+ space_topbar.c
+)
+
+add_definitions(${GL_DEFINITIONS})
+
+blender_add_lib(bf_editor_space_topbar "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/space_topbar/space_topbar.c b/source/blender/editors/space_topbar/space_topbar.c
new file mode 100644
index 00000000000..8cf27d86cfe
--- /dev/null
+++ b/source/blender/editors/space_topbar/space_topbar.c
@@ -0,0 +1,339 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_topbar/space_topbar.c
+ * \ingroup sptopbar
+ */
+
+
+#include <string.h>
+#include <stdio.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_utildefines.h"
+
+#include "BLO_readfile.h"
+#include "BLT_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+#include "BKE_screen.h"
+
+#include "ED_screen.h"
+#include "ED_space_api.h"
+#include "ED_undo.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+#include "UI_view2d.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "WM_message.h"
+
+
+void topbar_panels_register(ARegionType *art);
+
+/* ******************** default callbacks for topbar space ***************** */
+
+static SpaceLink *topbar_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
+{
+ ARegion *ar;
+ SpaceTopBar *stopbar;
+
+ stopbar = MEM_callocN(sizeof(*stopbar), "init topbar");
+ stopbar->spacetype = SPACE_TOPBAR;
+
+ /* header */
+ ar = MEM_callocN(sizeof(ARegion), "left aligned header for topbar");
+ BLI_addtail(&stopbar->regionbase, ar);
+ ar->regiontype = RGN_TYPE_HEADER;
+ ar->alignment = RGN_ALIGN_TOP;
+ ar = MEM_callocN(sizeof(ARegion), "right aligned header for topbar");
+ BLI_addtail(&stopbar->regionbase, ar);
+ ar->regiontype = RGN_TYPE_HEADER;
+ ar->alignment = RGN_ALIGN_RIGHT | RGN_SPLIT_PREV;
+
+ /* main regions */
+ ar = MEM_callocN(sizeof(ARegion), "left aligned main region for topbar");
+ BLI_addtail(&stopbar->regionbase, ar);
+ ar->regiontype = RGN_TYPE_WINDOW;
+ ar->alignment = RGN_ALIGN_LEFT;
+ ar = MEM_callocN(sizeof(ARegion), "right aligned main region for topbar");
+ BLI_addtail(&stopbar->regionbase, ar);
+ ar->regiontype = RGN_TYPE_WINDOW;
+ ar->alignment = RGN_ALIGN_RIGHT;
+ ar = MEM_callocN(sizeof(ARegion), "center main region for topbar");
+ BLI_addtail(&stopbar->regionbase, ar);
+ ar->regiontype = RGN_TYPE_WINDOW;
+
+ return (SpaceLink *)stopbar;
+}
+
+/* not spacelink itself */
+static void topbar_free(SpaceLink *UNUSED(sl))
+{
+
+}
+
+
+/* spacetype; init callback */
+static void topbar_init(struct wmWindowManager *UNUSED(wm), ScrArea *UNUSED(sa))
+{
+
+}
+
+static SpaceLink *topbar_duplicate(SpaceLink *sl)
+{
+ SpaceTopBar *stopbarn = MEM_dupallocN(sl);
+
+ /* clear or remove stuff from old */
+
+ return (SpaceLink *)stopbarn;
+}
+
+
+
+/* add handlers, stuff you only do once or on area/region changes */
+static void topbar_main_region_init(wmWindowManager *wm, ARegion *region)
+{
+ wmKeyMap *keymap;
+
+ /* force delayed UI_view2d_region_reinit call */
+ if (ELEM(region->alignment, RGN_ALIGN_LEFT, RGN_ALIGN_RIGHT)) {
+ region->flag |= RGN_FLAG_DYNAMIC_SIZE;
+ }
+ UI_view2d_region_reinit(&region->v2d, V2D_COMMONVIEW_HEADER, region->winx, region->winy);
+
+ keymap = WM_keymap_find(wm->defaultconf, "View2D Buttons List", 0, 0);
+ WM_event_add_keymap_handler(&region->handlers, keymap);
+}
+
+static void topbar_operatortypes(void)
+{
+
+}
+
+static void topbar_keymap(struct wmKeyConfig *UNUSED(keyconf))
+{
+
+}
+
+/* add handlers, stuff you only do once or on area/region changes */
+static void topbar_header_region_init(wmWindowManager *UNUSED(wm), ARegion *ar)
+{
+ if ((ar->alignment & ~RGN_SPLIT_PREV) == RGN_ALIGN_RIGHT) {
+ ar->flag |= RGN_FLAG_DYNAMIC_SIZE;
+ }
+ ED_region_header_init(ar);
+}
+
+static void topbar_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
+{
+ /* context changes */
+ switch (wmn->category) {
+ case NC_WM:
+ if (wmn->data == ND_HISTORY)
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_SCENE:
+ if (wmn->data == ND_MODE)
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_SPACE:
+ if (wmn->data == ND_SPACE_VIEW3D)
+ ED_region_tag_redraw(ar);
+ break;
+ }
+}
+
+static void topbar_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
+{
+ /* context changes */
+ switch (wmn->category) {
+ case NC_SCREEN:
+ if (wmn->data == ND_LAYER)
+ ED_region_tag_redraw(ar);
+ break;
+ case NC_SCENE:
+ if (wmn->data == ND_SCENEBROWSE)
+ ED_region_tag_redraw(ar);
+ break;
+ }
+}
+
+static void topbar_header_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *workspace, struct Scene *UNUSED(scene),
+ struct bScreen *UNUSED(screen), struct ScrArea *UNUSED(sa), struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+ WM_msg_subscribe_rna_prop(
+ mbus, &workspace->id, workspace,
+ WorkSpace, tool_keymap, &msg_sub_value_region_tag_redraw);
+}
+
+static void recent_files_menu_draw(const bContext *UNUSED(C), Menu *menu)
+{
+ struct RecentFile *recent;
+ uiLayout *layout = menu->layout;
+ uiLayoutSetOperatorContext(layout, WM_OP_EXEC_REGION_WIN);
+ if (!BLI_listbase_is_empty(&G.recent_files)) {
+ for (recent = G.recent_files.first; (recent); recent = recent->next) {
+ const char *file = BLI_path_basename(recent->filepath);
+ const int icon = BLO_has_bfile_extension(file) ? ICON_FILE_BLEND : ICON_FILE_BACKUP;
+ uiItemStringO(layout, file, icon, "WM_OT_open_mainfile", "filepath", recent->filepath);
+ }
+ }
+ else {
+ uiItemL(layout, IFACE_("No Recent Files"), ICON_NONE);
+ }
+}
+
+static void recent_files_menu_register(void)
+{
+ MenuType *mt;
+
+ mt = MEM_callocN(sizeof(MenuType), "spacetype info menu recent files");
+ strcpy(mt->idname, "TOPBAR_MT_file_open_recent");
+ strcpy(mt->label, N_("Open Recent..."));
+ strcpy(mt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+ mt->draw = recent_files_menu_draw;
+ WM_menutype_add(mt);
+}
+
+
+/* only called once, from space/spacetypes.c */
+void ED_spacetype_topbar(void)
+{
+ SpaceType *st = MEM_callocN(sizeof(SpaceType), "spacetype topbar");
+ ARegionType *art;
+
+ st->spaceid = SPACE_TOPBAR;
+ strncpy(st->name, "Top Bar", BKE_ST_MAXNAME);
+
+ st->new = topbar_new;
+ st->free = topbar_free;
+ st->init = topbar_init;
+ st->duplicate = topbar_duplicate;
+ st->operatortypes = topbar_operatortypes;
+ st->keymap = topbar_keymap;
+
+ /* regions: main window */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype topbar main region");
+ art->regionid = RGN_TYPE_WINDOW;
+ art->init = topbar_main_region_init;
+ art->layout = ED_region_header_layout;
+ art->draw = ED_region_header_draw;
+ art->listener = topbar_main_region_listener;
+ art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
+ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
+
+ BLI_addhead(&st->regiontypes, art);
+
+ /* regions: header */
+ art = MEM_callocN(sizeof(ARegionType), "spacetype topbar header region");
+ art->regionid = RGN_TYPE_HEADER;
+ art->prefsizey = HEADERY;
+ art->prefsizex = UI_UNIT_X * 5; /* Mainly to avoid glitches */
+ art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_VIEW2D | ED_KEYMAP_HEADER;
+ art->listener = topbar_header_listener;
+ art->message_subscribe = topbar_header_region_message_subscribe;
+ art->init = topbar_header_region_init;
+ art->layout = ED_region_header_layout;
+ art->draw = ED_region_header_draw;
+
+ /* For popovers. */
+ topbar_panels_register(art);
+
+ BLI_addhead(&st->regiontypes, art);
+
+ recent_files_menu_register();
+
+ BKE_spacetype_register(st);
+}
+
+
+/* -------------------------------------------------------------------- */
+/** \name Redo Panel
+ * \{ */
+
+static int topbar_panel_operator_redo_poll(const bContext *C, PanelType *UNUSED(pt))
+{
+ wmOperator *op = WM_operator_last_redo(C);
+ if (op == NULL) {
+ return false;
+ }
+
+ bool success = false;
+ if (!WM_operator_check_ui_empty(op->type)) {
+ const OperatorRepeatContextHandle *context_info;
+ context_info = ED_operator_repeat_prepare_context((bContext *)C, op);
+ success = WM_operator_poll((bContext *)C, op->type);
+ ED_operator_repeat_reset_context((bContext *)C, context_info);
+ }
+ return success;
+}
+
+static void topbar_panel_operator_redo(const bContext *C, Panel *pa)
+{
+ wmOperator *op = WM_operator_last_redo(C);
+ if (op == NULL) {
+ return;
+ }
+ if (!WM_operator_check_ui_enabled(C, op->type->name)) {
+ uiLayoutSetEnabled(pa->layout, false);
+ }
+ uiLayout *col = uiLayoutColumn(pa->layout, false);
+ uiTemplateOperatorRedoProperties(col, C);
+}
+
+void topbar_panels_register(ARegionType *art)
+{
+ PanelType *pt;
+
+ pt = MEM_callocN(sizeof(PanelType), __func__);
+ strcpy(pt->idname, "TOPBAR_PT_redo");
+ strcpy(pt->label, N_("Redo"));
+ strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
+ pt->draw = topbar_panel_operator_redo;
+ pt->poll = topbar_panel_operator_redo_poll;
+ pt->space_type = SPACE_TOPBAR;
+ pt->region_type = RGN_TYPE_HEADER;
+ BLI_addtail(&art->paneltypes, pt);
+}
+
+/** \} */
diff --git a/source/blender/editors/space_userpref/space_userpref.c b/source/blender/editors/space_userpref/space_userpref.c
index aeba4a86f3e..8e569c3b16e 100644
--- a/source/blender/editors/space_userpref/space_userpref.c
+++ b/source/blender/editors/space_userpref/space_userpref.c
@@ -51,7 +51,7 @@
/* ******************** default callbacks for userpref space ***************** */
-static SpaceLink *userpref_new(const bContext *UNUSED(C))
+static SpaceLink *userpref_new(const ScrArea *UNUSED(area), const Scene *UNUSED(scene))
{
ARegion *ar;
SpaceUserPref *spref;
@@ -136,12 +136,16 @@ static void userpref_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void userpref_main_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
+static void userpref_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
{
/* context changes */
}
-static void userpref_header_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar), wmNotifier *UNUSED(wmn))
+static void userpref_header_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *UNUSED(ar),
+ wmNotifier *UNUSED(wmn), const Scene *UNUSED(scene))
{
/* context changes */
#if 0
diff --git a/source/blender/editors/space_view3d/CMakeLists.txt b/source/blender/editors/space_view3d/CMakeLists.txt
index e25a9c04f15..f8e38587117 100644
--- a/source/blender/editors/space_view3d/CMakeLists.txt
+++ b/source/blender/editors/space_view3d/CMakeLists.txt
@@ -25,6 +25,7 @@ set(INC
../../blenlib
../../blentranslation
../../bmesh
+ ../../draw
../../gpu
../../imbuf
../../makesdna
@@ -42,21 +43,26 @@ set(INC_SYS
)
set(SRC
- drawanimviz.c
- drawarmature.c
- drawmesh.c
drawobject.c
- drawsimdebug.c
drawvolume.c
space_view3d.c
view3d_buttons.c
view3d_camera_control.c
view3d_draw.c
+ view3d_draw_legacy.c
view3d_edit.c
view3d_fly.c
view3d_walk.c
view3d_header.c
view3d_iterators.c
+ view3d_manipulator_armature.c
+ view3d_manipulator_camera.c
+ view3d_manipulator_empty.c
+ view3d_manipulator_forcefield.c
+ view3d_manipulator_lamp.c
+ view3d_manipulator_navigate.c
+ view3d_manipulator_navigate_type.c
+ view3d_manipulator_ruler.c
view3d_ops.c
view3d_project.c
view3d_ruler.c
@@ -74,13 +80,6 @@ if(WITH_PYTHON)
add_definitions(-DWITH_PYTHON)
endif()
-if(WITH_GAMEENGINE)
- list(APPEND INC
- ../../../gameengine/BlenderRoutines
- )
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
add_definitions(${GL_DEFINITIONS})
if(WITH_INTERNATIONAL)
@@ -95,8 +94,4 @@ if(WITH_MOD_SMOKE)
add_definitions(-DWITH_SMOKE)
endif()
-if(WITH_LEGACY_DEPSGRAPH)
- add_definitions(-DWITH_LEGACY_DEPSGRAPH)
-endif()
-
blender_add_lib(bf_editor_space_view3d "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/space_view3d/drawanimviz.c b/source/blender/editors/space_view3d/drawanimviz.c
deleted file mode 100644
index a99ac0d46a5..00000000000
--- a/source/blender/editors/space_view3d/drawanimviz.c
+++ /dev/null
@@ -1,402 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 by the Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Joshua Leung
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_view3d/drawanimviz.c
- * \ingroup spview3d
- */
-
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "BLI_sys_types.h"
-
-#include "DNA_anim_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_math.h"
-#include "BLI_dlrbTree.h"
-
-#include "BKE_animsys.h"
-#include "BKE_action.h"
-
-#include "BIF_gl.h"
-
-#include "ED_keyframes_draw.h"
-
-
-#include "UI_resources.h"
-
-#include "view3d_intern.h"
-
-/* ************************************ Motion Paths ************************************* */
-
-/* TODO:
- * - options to draw paths with lines
- * - include support for editing the path verts */
-
-/* Set up drawing environment for drawing motion paths */
-void draw_motion_paths_init(View3D *v3d, ARegion *ar)
-{
- RegionView3D *rv3d = ar->regiondata;
-
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- glPushMatrix();
- glLoadMatrixf(rv3d->viewmat);
-}
-
-/* set color
- * - more intense for active/selected bones, less intense for unselected bones
- * - black for before current frame, green for current frame, blue for after current frame
- * - intensity decreases as distance from current frame increases
- *
- * If the user select custom color, the color is replaced for the color selected in UI panel
- * - 75% Darker color is used for previous frames
- * - 50% Darker color for current frame
- * - User selected color for next frames
- */
-static void set_motion_path_color(Scene *scene, bMotionPath *mpath, int i, short sel, int sfra, int efra,
- float prev_color[3], float frame_color[3], float next_color[3])
-{
- int frame = sfra + i;
- int blend_base = (abs(frame - CFRA) == 1) ? TH_CFRAME : TH_BACK; /* "bleed" cframe color to ease color blending */
-
-#define SET_INTENSITY(A, B, C, min, max) (((1.0f - ((C - B) / (C - A))) * (max - min)) + min)
- float intensity; /* how faint */
-
- if (frame < CFRA) {
- if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
- /* Custom color: previous frames color is darker than current frame */
- glColor3fv(prev_color);
- }
- else {
- /* black - before cfra */
- if (sel) {
- /* intensity = 0.5f; */
- intensity = SET_INTENSITY(sfra, i, CFRA, 0.25f, 0.75f);
- }
- else {
- /* intensity = 0.8f; */
- intensity = SET_INTENSITY(sfra, i, CFRA, 0.68f, 0.92f);
- }
- UI_ThemeColorBlend(TH_WIRE, blend_base, intensity);
- }
- }
- else if (frame > CFRA) {
- if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
- /* Custom color: next frames color is equal to user selected color */
- glColor3fv(next_color);
- }
- else {
- /* blue - after cfra */
- if (sel) {
- /* intensity = 0.5f; */
- intensity = SET_INTENSITY(CFRA, i, efra, 0.25f, 0.75f);
- }
- else {
- /* intensity = 0.8f; */
- intensity = SET_INTENSITY(CFRA, i, efra, 0.68f, 0.92f);
- }
- UI_ThemeColorBlend(TH_BONE_POSE, blend_base, intensity);
- }
- }
- else {
- if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
- /* Custom color: current frame color is slightly darker than user selected color */
- glColor3fv(frame_color);
- }
- else {
- /* green - on cfra */
- if (sel) {
- intensity = 0.5f;
- }
- else {
- intensity = 0.99f;
- }
- UI_ThemeColorBlendShade(TH_CFRAME, TH_BACK, intensity, 10);
- }
- }
-#undef SET_INTENSITY
-}
-
-/* Draw the given motion path for an Object or a Bone
- * - assumes that the viewport has already been initialized properly
- * i.e. draw_motion_paths_init() has been called
- */
-void draw_motion_path_instance(Scene *scene,
- Object *ob, bPoseChannel *pchan, bAnimVizSettings *avs, bMotionPath *mpath)
-{
- //RegionView3D *rv3d = ar->regiondata;
- bMotionPathVert *mpv, *mpv_start;
- int i, stepsize = avs->path_step;
- int sfra, efra, sind, len;
- float prev_color[3];
- float frame_color[3];
- float next_color[3];
-
- /* Custom color - Previous frames: color is darker than current frame */
- prev_color[0] = mpath->color[0] * 0.25f;
- prev_color[1] = mpath->color[1] * 0.25f;
- prev_color[2] = mpath->color[2] * 0.25f;
-
- /* Custom color - Current frame: color is slightly darker than user selected color */
- frame_color[0] = mpath->color[0] * 0.50f;
- frame_color[1] = mpath->color[1] * 0.50f;
- frame_color[2] = mpath->color[2] * 0.50f;
-
- /* Custom color - Next frames: color is equal to user selection */
- next_color[0] = mpath->color[0];
- next_color[1] = mpath->color[1];
- next_color[2] = mpath->color[2];
-
- /* Save old line width */
- GLfloat old_width;
- glGetFloatv(GL_LINE_WIDTH, &old_width);
-
- /* get frame ranges */
- if (avs->path_type == MOTIONPATH_TYPE_ACFRA) {
- /* With "Around Current", we only choose frames from around
- * the current frame to draw.
- */
- sfra = CFRA - avs->path_bc;
- efra = CFRA + avs->path_ac;
- }
- else {
- /* Use the current display range */
- sfra = avs->path_sf;
- efra = avs->path_ef;
- }
-
- /* no matter what, we can only show what is in the cache and no more
- * - abort if whole range is past ends of path
- * - otherwise clamp endpoints to extents of path
- */
- if (sfra < mpath->start_frame) {
- /* start clamp */
- sfra = mpath->start_frame;
- }
- if (efra > mpath->end_frame) {
- /* end clamp */
- efra = mpath->end_frame;
- }
-
- if ((sfra > mpath->end_frame) || (efra < mpath->start_frame)) {
- /* whole path is out of bounds */
- return;
- }
-
- len = efra - sfra;
-
- if ((len <= 0) || (mpath->points == NULL)) {
- return;
- }
-
- /* get pointers to parts of path */
- sind = sfra - mpath->start_frame;
- mpv_start = (mpath->points + sind);
-
- /* draw curve-line of path */
- /* Draw lines only if line drawing option is enabled */
- if (mpath->flag & MOTIONPATH_FLAG_LINES) {
- /* set line thickness */
- glLineWidth(mpath->line_thickness);
-
- glBegin(GL_LINE_STRIP);
- for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
- short sel = (pchan) ? (pchan->bone->flag & BONE_SELECTED) : (ob->flag & SELECT);
- /* Set color */
- set_motion_path_color(scene, mpath, i, sel, sfra, efra, prev_color, frame_color, next_color);
- /* draw a vertex with this color */
- glVertex3fv(mpv->co);
- }
-
- glEnd();
- /* back to old line thickness */
- glLineWidth(old_width);
- }
-
- /* Point must be bigger than line thickness */
- glPointSize(mpath->line_thickness + 1.0);
-
- /* draw little black point at each frame
- * NOTE: this is not really visible/noticeable
- */
- glBegin(GL_POINTS);
- for (i = 0, mpv = mpv_start; i < len; i++, mpv++)
- glVertex3fv(mpv->co);
- glEnd();
-
- /* Draw little white dots at each framestep value or replace with custom color */
- if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
- glColor4fv(mpath->color);
- }
- else {
- UI_ThemeColor(TH_TEXT_HI);
- }
- glBegin(GL_POINTS);
- for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize)
- glVertex3fv(mpv->co);
- glEnd();
-
- /* Draw big green dot where the current frame is
- * NOTE: this is only done when keyframes are shown, since this adds similar types of clutter
- */
- if ((avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) &&
- (sfra < CFRA) && (CFRA <= efra))
- {
- UI_ThemeColor(TH_CFRAME);
-
- glPointSize(mpath->line_thickness + 5.0);
- glBegin(GL_POINTS);
- mpv = mpv_start + (CFRA - sfra);
- glVertex3fv(mpv->co);
- glEnd();
-
- UI_ThemeColor(TH_TEXT_HI);
- }
-
- /* XXX, this isn't up to date but probably should be kept so. */
- invert_m4_m4(ob->imat, ob->obmat);
-
- /* Draw frame numbers at each framestep value */
- if (avs->path_viewflag & MOTIONPATH_VIEW_FNUMS) {
- unsigned char col[4];
- UI_GetThemeColor3ubv(TH_TEXT_HI, col);
- col[3] = 255;
-
- for (i = 0, mpv = mpv_start; i < len; i += stepsize, mpv += stepsize) {
- int frame = sfra + i;
- char numstr[32];
- size_t numstr_len;
- float co[3];
-
- /* only draw framenum if several consecutive highlighted points don't occur on same point */
- if (i == 0) {
- numstr_len = sprintf(numstr, " %d", frame);
- mul_v3_m4v3(co, ob->imat, mpv->co);
- view3d_cached_text_draw_add(co, numstr, numstr_len,
- 0, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, col);
- }
- else if ((i >= stepsize) && (i < len - stepsize)) {
- bMotionPathVert *mpvP = (mpv - stepsize);
- bMotionPathVert *mpvN = (mpv + stepsize);
-
- if ((equals_v3v3(mpv->co, mpvP->co) == 0) || (equals_v3v3(mpv->co, mpvN->co) == 0)) {
- numstr_len = sprintf(numstr, " %d", frame);
- mul_v3_m4v3(co, ob->imat, mpv->co);
- view3d_cached_text_draw_add(co, numstr, numstr_len,
- 0, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, col);
- }
- }
- }
- }
-
- /* Keyframes - dots and numbers */
- if (avs->path_viewflag & MOTIONPATH_VIEW_KFRAS) {
- unsigned char col[4];
-
- AnimData *adt = BKE_animdata_from_id(&ob->id);
- DLRBT_Tree keys;
-
- /* build list of all keyframes in active action for object or pchan */
- BLI_dlrbTree_init(&keys);
-
- if (adt) {
- /* it is assumed that keyframes for bones are all grouped in a single group
- * unless an option is set to always use the whole action
- */
- if ((pchan) && (avs->path_viewflag & MOTIONPATH_VIEW_KFACT) == 0) {
- bActionGroup *agrp = BKE_action_group_find_name(adt->action, pchan->name);
-
- if (agrp) {
- agroup_to_keylist(adt, agrp, &keys, NULL);
- BLI_dlrbTree_linkedlist_sync(&keys);
- }
- }
- else {
- action_to_keylist(adt, adt->action, &keys, NULL);
- BLI_dlrbTree_linkedlist_sync(&keys);
- }
- }
-
- /* Draw slightly-larger yellow dots at each keyframe */
- UI_GetThemeColor3ubv(TH_VERTEX_SELECT, col);
- col[3] = 255;
-
- /* if custom, point must be bigger than line */
- if (mpath->flag & MOTIONPATH_FLAG_CUSTOM) {
- glPointSize(mpath->line_thickness + 3.0);
- }
- else {
- glPointSize(4.0f);
- }
- glColor3ubv(col);
-
- glBegin(GL_POINTS);
- for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
- int frame = sfra + i;
- float mframe = (float)(frame);
-
- if (BLI_dlrbTree_search_exact(&keys, compare_ak_cfraPtr, &mframe))
- glVertex3fv(mpv->co);
- }
- glEnd();
-
- /* Draw frame numbers of keyframes */
- if (avs->path_viewflag & MOTIONPATH_VIEW_KFNOS) {
- float co[3];
- for (i = 0, mpv = mpv_start; i < len; i++, mpv++) {
- float mframe = (float)(sfra + i);
-
- if (BLI_dlrbTree_search_exact(&keys, compare_ak_cfraPtr, &mframe)) {
- char numstr[32];
- size_t numstr_len;
-
- numstr_len = sprintf(numstr, " %d", (sfra + i));
- mul_v3_m4v3(co, ob->imat, mpv->co);
- view3d_cached_text_draw_add(co, numstr, numstr_len,
- 0, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, col);
- }
- }
- }
-
- BLI_dlrbTree_free(&keys);
- }
-}
-
-/* Clean up drawing environment after drawing motion paths */
-void draw_motion_paths_cleanup(View3D *v3d)
-{
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- glPopMatrix();
-}
diff --git a/source/blender/editors/space_view3d/drawarmature.c b/source/blender/editors/space_view3d/drawarmature.c
deleted file mode 100644
index 5208013b6fe..00000000000
--- a/source/blender/editors/space_view3d/drawarmature.c
+++ /dev/null
@@ -1,2793 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2005 by the Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_view3d/drawarmature.c
- * \ingroup spview3d
- */
-
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-
-#include "DNA_anim_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_dlrbTree.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_animsys.h"
-#include "BKE_action.h"
-#include "BKE_armature.h"
-#include "BKE_global.h"
-#include "BKE_modifier.h"
-#include "BKE_nla.h"
-#include "BKE_curve.h"
-
-
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
-#include "ED_armature.h"
-#include "ED_keyframes_draw.h"
-
-#include "GPU_basic_shader.h"
-
-#include "UI_resources.h"
-
-#include "view3d_intern.h"
-
-#include "GPU_select.h"
-
-/* *************** Armature Drawing - Coloring API ***************************** */
-
-/* global here is reset before drawing each bone */
-static ThemeWireColor *bcolor = NULL;
-
-/* values of colCode for set_pchan_glcolor */
-enum {
- PCHAN_COLOR_NORMAL = 0, /* normal drawing */
- PCHAN_COLOR_SOLID, /* specific case where "solid" color is needed */
- PCHAN_COLOR_CONSTS, /* "constraint" colors (which may/may-not be suppressed) */
-
- PCHAN_COLOR_SPHEREBONE_BASE, /* for the 'stick' of sphere (envelope) bones */
- PCHAN_COLOR_SPHEREBONE_END, /* for the ends of sphere (envelope) bones */
- PCHAN_COLOR_LINEBONE /* for the middle of line-bones */
-};
-
-/* This function sets the color-set for coloring a certain bone */
-static void set_pchan_colorset(Object *ob, bPoseChannel *pchan)
-{
- bPose *pose = (ob) ? ob->pose : NULL;
- bArmature *arm = (ob) ? ob->data : NULL;
- bActionGroup *grp = NULL;
- short color_index = 0;
-
- /* sanity check */
- if (ELEM(NULL, ob, arm, pose, pchan)) {
- bcolor = NULL;
- return;
- }
-
- /* only try to set custom color if enabled for armature */
- if (arm->flag & ARM_COL_CUSTOM) {
- /* currently, a bone can only use a custom color set if it's group (if it has one),
- * has been set to use one
- */
- if (pchan->agrp_index) {
- grp = (bActionGroup *)BLI_findlink(&pose->agroups, (pchan->agrp_index - 1));
- if (grp)
- color_index = grp->customCol;
- }
- }
-
- /* bcolor is a pointer to the color set to use. If NULL, then the default
- * color set (based on the theme colors for 3d-view) is used.
- */
- if (color_index > 0) {
- bTheme *btheme = UI_GetTheme();
- bcolor = &btheme->tarm[(color_index - 1)];
- }
- else if (color_index == -1) {
- /* use the group's own custom color set (grp is always != NULL here) */
- bcolor = &grp->cs;
- }
- else {
- bcolor = NULL;
- }
-}
-
-/* This function is for brightening/darkening a given color (like UI_ThemeColorShade()) */
-static void cp_shade_color3ub(unsigned char cp[3], const int offset)
-{
- int r, g, b;
-
- r = offset + (int) cp[0];
- CLAMP(r, 0, 255);
- g = offset + (int) cp[1];
- CLAMP(g, 0, 255);
- b = offset + (int) cp[2];
- CLAMP(b, 0, 255);
-
- cp[0] = r;
- cp[1] = g;
- cp[2] = b;
-}
-
-/* This function sets the gl-color for coloring a certain bone (based on bcolor) */
-static bool set_pchan_glColor(short colCode, int boneflag, short constflag)
-{
- switch (colCode) {
- case PCHAN_COLOR_NORMAL:
- {
- if (bcolor) {
- unsigned char cp[3];
-
- if (boneflag & BONE_DRAW_ACTIVE) {
- copy_v3_v3_char((char *)cp, bcolor->active);
- if (!(boneflag & BONE_SELECTED)) {
- cp_shade_color3ub(cp, -80);
- }
- }
- else if (boneflag & BONE_SELECTED) {
- copy_v3_v3_char((char *)cp, bcolor->select);
- }
- else {
- /* a bit darker than solid */
- copy_v3_v3_char((char *)cp, bcolor->solid);
- cp_shade_color3ub(cp, -50);
- }
-
- glColor3ubv(cp);
- }
- else {
- if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) {
- UI_ThemeColor(TH_BONE_POSE_ACTIVE);
- }
- else if (boneflag & BONE_DRAW_ACTIVE) {
- UI_ThemeColorBlend(TH_WIRE, TH_BONE_POSE, 0.15f); /* unselected active */
- }
- else if (boneflag & BONE_SELECTED) {
- UI_ThemeColor(TH_BONE_POSE);
- }
- else {
- UI_ThemeColor(TH_WIRE);
- }
- }
-
- return true;
- }
- case PCHAN_COLOR_SOLID:
- {
- if (bcolor) {
- glColor3ubv((unsigned char *)bcolor->solid);
- }
- else
- UI_ThemeColor(TH_BONE_SOLID);
-
- return true;
- }
- case PCHAN_COLOR_CONSTS:
- {
- if ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS)) {
- if (constflag & PCHAN_HAS_TARGET) glColor4ub(255, 150, 0, 80);
- else if (constflag & PCHAN_HAS_IK) glColor4ub(255, 255, 0, 80);
- else if (constflag & PCHAN_HAS_SPLINEIK) glColor4ub(200, 255, 0, 80);
- else if (constflag & PCHAN_HAS_CONST) glColor4ub(0, 255, 120, 80);
-
- return true;
- }
- return false;
- }
- case PCHAN_COLOR_SPHEREBONE_BASE:
- {
- if (bcolor) {
- unsigned char cp[3];
-
- if (boneflag & BONE_DRAW_ACTIVE) {
- copy_v3_v3_char((char *)cp, bcolor->active);
- }
- else if (boneflag & BONE_SELECTED) {
- copy_v3_v3_char((char *)cp, bcolor->select);
- }
- else {
- copy_v3_v3_char((char *)cp, bcolor->solid);
- }
-
- glColor3ubv(cp);
- }
- else {
- if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 40);
- else if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_BONE_POSE);
- else UI_ThemeColor(TH_BONE_SOLID);
- }
-
- return true;
- }
- case PCHAN_COLOR_SPHEREBONE_END:
- {
- if (bcolor) {
- unsigned char cp[3];
-
- if (boneflag & BONE_DRAW_ACTIVE) {
- copy_v3_v3_char((char *)cp, bcolor->active);
- cp_shade_color3ub(cp, 10);
- }
- else if (boneflag & BONE_SELECTED) {
- copy_v3_v3_char((char *)cp, bcolor->select);
- cp_shade_color3ub(cp, -30);
- }
- else {
- copy_v3_v3_char((char *)cp, bcolor->solid);
- cp_shade_color3ub(cp, -30);
- }
-
- glColor3ubv(cp);
- }
- else {
- if (boneflag & BONE_DRAW_ACTIVE) UI_ThemeColorShade(TH_BONE_POSE, 10);
- else if (boneflag & BONE_SELECTED) UI_ThemeColorShade(TH_BONE_POSE, -30);
- else UI_ThemeColorShade(TH_BONE_SOLID, -30);
- }
- break;
- }
- case PCHAN_COLOR_LINEBONE:
- {
- /* inner part in background color or constraint */
- if ((constflag) && ((bcolor == NULL) || (bcolor->flag & TH_WIRECOLOR_CONSTCOLS))) {
- if (constflag & PCHAN_HAS_TARGET) glColor3ub(255, 150, 0);
- else if (constflag & PCHAN_HAS_IK) glColor3ub(255, 255, 0);
- else if (constflag & PCHAN_HAS_SPLINEIK) glColor3ub(200, 255, 0);
- else if (constflag & PCHAN_HAS_CONST) glColor3ub(0, 255, 120);
- else if (constflag) UI_ThemeColor(TH_BONE_POSE); /* PCHAN_HAS_ACTION */
- }
- else {
- if (bcolor) {
- const char *cp = bcolor->solid;
- glColor4ub(cp[0], cp[1], cp[2], 204);
- }
- else
- UI_ThemeColorShade(TH_BACK, -30);
- }
-
- return true;
- }
- }
-
- return false;
-}
-
-static void set_ebone_glColor(const unsigned int boneflag)
-{
- if ((boneflag & BONE_DRAW_ACTIVE) && (boneflag & BONE_SELECTED)) {
- UI_ThemeColor(TH_EDGE_SELECT);
- }
- else if (boneflag & BONE_DRAW_ACTIVE) {
- UI_ThemeColorBlend(TH_WIRE_EDIT, TH_EDGE_SELECT, 0.15f); /* unselected active */
- }
- else if (boneflag & BONE_SELECTED) {
- UI_ThemeColorShade(TH_EDGE_SELECT, -20);
- }
- else {
- UI_ThemeColor(TH_WIRE_EDIT);
- }
-}
-
-/* *************** Armature drawing, helper calls for parts ******************* */
-
-/* half the cube, in Y */
-static const float cube[8][3] = {
- {-1.0, 0.0, -1.0},
- {-1.0, 0.0, 1.0},
- {-1.0, 1.0, 1.0},
- {-1.0, 1.0, -1.0},
- { 1.0, 0.0, -1.0},
- { 1.0, 0.0, 1.0},
- { 1.0, 1.0, 1.0},
- { 1.0, 1.0, -1.0},
-};
-
-static void drawsolidcube_size(float xsize, float ysize, float zsize)
-{
- static GLuint displist = 0;
- float n[3] = {0.0f};
-
- glScalef(xsize, ysize, zsize);
-
- if (displist == 0) {
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- glBegin(GL_QUADS);
- n[0] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
- n[0] = 0;
- n[1] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
- n[1] = 0;
- n[0] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
- n[0] = 0;
- n[1] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
- n[1] = 0;
- n[2] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
- n[2] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
- glEnd();
-
- glEndList();
- }
-
- glCallList(displist);
-}
-
-static void drawcube_size(float xsize, float ysize, float zsize)
-{
- static GLuint displist = 0;
-
- if (displist == 0) {
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- glBegin(GL_LINE_STRIP);
- glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
- glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[6]);
- glVertex3fv(cube[7]); glVertex3fv(cube[4]);
- glEnd();
-
- glBegin(GL_LINES);
- glVertex3fv(cube[1]); glVertex3fv(cube[5]);
- glVertex3fv(cube[2]); glVertex3fv(cube[6]);
- glVertex3fv(cube[3]); glVertex3fv(cube[7]);
- glEnd();
-
- glEndList();
- }
-
- glScalef(xsize, ysize, zsize);
- glCallList(displist);
-
-}
-
-
-static void draw_bonevert(void)
-{
- static GLuint displist = 0;
-
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- glPushMatrix();
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
- gluDisk(qobj, 0.0, 0.05, 16, 1);
-
- glRotatef(90, 0, 1, 0);
- gluDisk(qobj, 0.0, 0.05, 16, 1);
-
- glRotatef(90, 1, 0, 0);
- gluDisk(qobj, 0.0, 0.05, 16, 1);
-
- gluDeleteQuadric(qobj);
-
- glPopMatrix();
- glEndList();
- }
-
- glCallList(displist);
-}
-
-static void draw_bonevert_solid(void)
-{
- static GLuint displist = 0;
-
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_FILL);
- /* Draw tips of a bone */
- gluSphere(qobj, 0.05, 8, 5);
- gluDeleteQuadric(qobj);
-
- glEndList();
- }
-
- glCallList(displist);
-}
-
-static const float bone_octahedral_verts[6][3] = {
- { 0.0f, 0.0f, 0.0f},
- { 0.1f, 0.1f, 0.1f},
- { 0.1f, 0.1f, -0.1f},
- {-0.1f, 0.1f, -0.1f},
- {-0.1f, 0.1f, 0.1f},
- { 0.0f, 1.0f, 0.0f}
-};
-
-static const unsigned int bone_octahedral_wire_sides[8] = {0, 1, 5, 3, 0, 4, 5, 2};
-static const unsigned int bone_octahedral_wire_square[8] = {1, 2, 3, 4, 1};
-
-static const unsigned int bone_octahedral_solid_tris[8][3] = {
- {2, 1, 0}, /* bottom */
- {3, 2, 0},
- {4, 3, 0},
- {1, 4, 0},
-
- {5, 1, 2}, /* top */
- {5, 2, 3},
- {5, 3, 4},
- {5, 4, 1}
-};
-
-/* aligned with bone_octahedral_solid_tris */
-static const float bone_octahedral_solid_normals[8][3] = {
- { M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
- {-0.00000000f, -M_SQRT1_2, -M_SQRT1_2},
- {-M_SQRT1_2, -M_SQRT1_2, 0.00000000f},
- { 0.00000000f, -M_SQRT1_2, M_SQRT1_2},
- { 0.99388373f, 0.11043154f, -0.00000000f},
- { 0.00000000f, 0.11043154f, -0.99388373f},
- {-0.99388373f, 0.11043154f, 0.00000000f},
- { 0.00000000f, 0.11043154f, 0.99388373f}
-};
-
-static void draw_bone_octahedral(void)
-{
- static GLuint displist = 0;
-
- if (displist == 0) {
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- /* Section 1, sides */
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts);
- glDrawElements(GL_LINE_LOOP,
- sizeof(bone_octahedral_wire_sides) / sizeof(*bone_octahedral_wire_sides),
- GL_UNSIGNED_INT,
- bone_octahedral_wire_sides);
-
- /* Section 1, square */
- glDrawElements(GL_LINE_LOOP,
- sizeof(bone_octahedral_wire_square) / sizeof(*bone_octahedral_wire_square),
- GL_UNSIGNED_INT,
- bone_octahedral_wire_square);
- glDisableClientState(GL_VERTEX_ARRAY);
-
- glEndList();
- }
-
- glCallList(displist);
-}
-
-static void draw_bone_solid_octahedral(void)
-{
- static GLuint displist = 0;
-
- if (displist == 0) {
- int i;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
-#if 1
- glBegin(GL_TRIANGLES);
- for (i = 0; i < 8; i++) {
- glNormal3fv(bone_octahedral_solid_normals[i]);
- glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][0]]);
- glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][1]]);
- glVertex3fv(bone_octahedral_verts[bone_octahedral_solid_tris[i][2]]);
- }
-
- glEnd();
-
-#else /* not working because each vert needs a different normal */
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_VERTEX_ARRAY);
- glNormalPointer(GL_FLOAT, 0, bone_octahedral_solid_normals);
- glVertexPointer(3, GL_FLOAT, 0, bone_octahedral_verts);
- glDrawElements(GL_TRIANGLES, sizeof(bone_octahedral_solid_tris) / sizeof(unsigned int),
- GL_UNSIGNED_INT, bone_octahedral_solid_tris);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
-#endif
-
- glEndList();
- }
-
- glCallList(displist);
-}
-
-/* *************** Armature drawing, bones ******************* */
-
-
-static void draw_bone_points(const short dt, int armflag, unsigned int boneflag, int id)
-{
- /* Draw root point if we are not connected */
- if ((boneflag & BONE_CONNECTED) == 0) {
- if (id != -1)
- GPU_select_load_id(id | BONESEL_ROOT);
-
- if (dt <= OB_WIRE) {
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColor(TH_VERTEX);
- }
- }
- else {
- if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, 0);
- else
- UI_ThemeColor(TH_BONE_SOLID);
- }
-
- if (dt > OB_WIRE)
- draw_bonevert_solid();
- else
- draw_bonevert();
- }
-
- /* Draw tip point */
- if (id != -1)
- GPU_select_load_id(id | BONESEL_TIP);
-
- if (dt <= OB_WIRE) {
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColor(TH_VERTEX);
- }
- }
- else {
- if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, 0);
- else
- UI_ThemeColor(TH_BONE_SOLID);
- }
-
- glTranslatef(0.0f, 1.0f, 0.0f);
- if (dt > OB_WIRE)
- draw_bonevert_solid();
- else
- draw_bonevert();
- glTranslatef(0.0f, -1.0f, 0.0f);
-
-}
-
-/* 16 values of sin function (still same result!) */
-static const float si[16] = {
- 0.00000000f,
- 0.20129852f, 0.39435585f,
- 0.57126821f, 0.72479278f,
- 0.84864425f, 0.93775213f,
- 0.98846832f, 0.99871650f,
- 0.96807711f, 0.89780453f,
- 0.79077573f, 0.65137248f,
- 0.48530196f, 0.29936312f,
- 0.10116832f
-};
-/* 16 values of cos function (still same result!) */
-static const float co[16] = {
- 1.00000000f,
- 0.97952994f, 0.91895781f,
- 0.82076344f, 0.68896691f,
- 0.52896401f, 0.34730525f,
- 0.15142777f, -0.05064916f,
- -0.25065253f, -0.44039415f,
- -0.61210598f, -0.75875812f,
- -0.87434661f, -0.95413925f,
- -0.99486932f
-};
-
-
-
-/* smat, imat = mat & imat to draw screenaligned */
-static void draw_sphere_bone_dist(float smat[4][4], float imat[4][4], bPoseChannel *pchan, EditBone *ebone)
-{
- float head, tail, dist /*, length*/;
- float *headvec, *tailvec, dirvec[3];
-
- /* figure out the sizes of spheres */
- if (ebone) {
- /* this routine doesn't call get_matrix_editbone() that calculates it */
- ebone->length = len_v3v3(ebone->head, ebone->tail);
-
- /*length = ebone->length;*/ /*UNUSED*/
- tail = ebone->rad_tail;
- dist = ebone->dist;
- if (ebone->parent && (ebone->flag & BONE_CONNECTED))
- head = ebone->parent->rad_tail;
- else
- head = ebone->rad_head;
- headvec = ebone->head;
- tailvec = ebone->tail;
- }
- else {
- /*length = pchan->bone->length;*/ /*UNUSED*/
- tail = pchan->bone->rad_tail;
- dist = pchan->bone->dist;
- if (pchan->parent && (pchan->bone->flag & BONE_CONNECTED))
- head = pchan->parent->bone->rad_tail;
- else
- head = pchan->bone->rad_head;
- headvec = pchan->pose_head;
- tailvec = pchan->pose_tail;
- }
-
- /* ***** draw it ***** */
-
- /* move vector to viewspace */
- sub_v3_v3v3(dirvec, tailvec, headvec);
- mul_mat3_m4_v3(smat, dirvec);
- /* clear zcomp */
- dirvec[2] = 0.0f;
-
- if (head != tail) {
- /* correction when viewing along the bones axis
- * it pops in and out but better then artifacts, [#23841] */
- float view_dist = len_v2(dirvec);
-
- if (head - view_dist > tail) {
- tailvec = headvec;
- tail = head;
- zero_v3(dirvec);
- dirvec[0] = 0.00001; /* XXX. weak but ok */
- }
- else if (tail - view_dist > head) {
- headvec = tailvec;
- head = tail;
- zero_v3(dirvec);
- dirvec[0] = 0.00001; /* XXX. weak but ok */
- }
- }
-
- /* move vector back */
- mul_mat3_m4_v3(imat, dirvec);
-
- if (0.0f != normalize_v3(dirvec)) {
- float norvec[3], vec1[3], vec2[3], vec[3];
- int a;
-
- //mul_v3_fl(dirvec, head);
- cross_v3_v3v3(norvec, dirvec, imat[2]);
-
- glBegin(GL_QUAD_STRIP);
-
- for (a = 0; a < 16; a++) {
- vec[0] = -si[a] * dirvec[0] + co[a] * norvec[0];
- vec[1] = -si[a] * dirvec[1] + co[a] * norvec[1];
- vec[2] = -si[a] * dirvec[2] + co[a] * norvec[2];
-
- madd_v3_v3v3fl(vec1, headvec, vec, head);
- madd_v3_v3v3fl(vec2, headvec, vec, head + dist);
-
- glColor4ub(255, 255, 255, 50);
- glVertex3fv(vec1);
- //glColor4ub(255, 255, 255, 0);
- glVertex3fv(vec2);
- }
-
- for (a = 15; a >= 0; a--) {
- vec[0] = si[a] * dirvec[0] + co[a] * norvec[0];
- vec[1] = si[a] * dirvec[1] + co[a] * norvec[1];
- vec[2] = si[a] * dirvec[2] + co[a] * norvec[2];
-
- madd_v3_v3v3fl(vec1, tailvec, vec, tail);
- madd_v3_v3v3fl(vec2, tailvec, vec, tail + dist);
-
- //glColor4ub(255, 255, 255, 50);
- glVertex3fv(vec1);
- //glColor4ub(255, 255, 255, 0);
- glVertex3fv(vec2);
- }
- /* make it cyclic... */
-
- vec[0] = -si[0] * dirvec[0] + co[0] * norvec[0];
- vec[1] = -si[0] * dirvec[1] + co[0] * norvec[1];
- vec[2] = -si[0] * dirvec[2] + co[0] * norvec[2];
-
- madd_v3_v3v3fl(vec1, headvec, vec, head);
- madd_v3_v3v3fl(vec2, headvec, vec, head + dist);
-
- //glColor4ub(255, 255, 255, 50);
- glVertex3fv(vec1);
- //glColor4ub(255, 255, 255, 0);
- glVertex3fv(vec2);
-
- glEnd();
- }
-}
-
-
-/* smat, imat = mat & imat to draw screenaligned */
-static void draw_sphere_bone_wire(float smat[4][4], float imat[4][4],
- int armflag, int boneflag, short constflag, unsigned int id,
- bPoseChannel *pchan, EditBone *ebone)
-{
- float head, tail /*, length*/;
- float *headvec, *tailvec, dirvec[3];
-
- /* figure out the sizes of spheres */
- if (ebone) {
- /* this routine doesn't call get_matrix_editbone() that calculates it */
- ebone->length = len_v3v3(ebone->head, ebone->tail);
-
- /*length = ebone->length;*/ /*UNUSED*/
- tail = ebone->rad_tail;
- if (ebone->parent && (boneflag & BONE_CONNECTED))
- head = ebone->parent->rad_tail;
- else
- head = ebone->rad_head;
- headvec = ebone->head;
- tailvec = ebone->tail;
- }
- else {
- /*length = pchan->bone->length;*/ /*UNUSED*/
- tail = pchan->bone->rad_tail;
- if ((pchan->parent) && (boneflag & BONE_CONNECTED))
- head = pchan->parent->bone->rad_tail;
- else
- head = pchan->bone->rad_head;
- headvec = pchan->pose_head;
- tailvec = pchan->pose_tail;
- }
-
- /* sphere root color */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColor(TH_VERTEX);
- }
- else if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
-
- /* Draw root point if we are not connected */
- if ((boneflag & BONE_CONNECTED) == 0) {
- if (id != -1)
- GPU_select_load_id(id | BONESEL_ROOT);
-
- drawcircball(GL_LINE_LOOP, headvec, head, imat);
- }
-
- /* Draw tip point */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColor(TH_VERTEX);
- }
-
- if (id != -1)
- GPU_select_load_id(id | BONESEL_TIP);
-
- drawcircball(GL_LINE_LOOP, tailvec, tail, imat);
-
- /* base */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
- else UI_ThemeColor(TH_WIRE_EDIT);
- }
-
- sub_v3_v3v3(dirvec, tailvec, headvec);
-
- /* move vector to viewspace */
- mul_mat3_m4_v3(smat, dirvec);
- /* clear zcomp */
- dirvec[2] = 0.0f;
- /* move vector back */
- mul_mat3_m4_v3(imat, dirvec);
-
- if (0.0f != normalize_v3(dirvec)) {
- float norvech[3], norvect[3], vec[3];
-
- copy_v3_v3(vec, dirvec);
-
- mul_v3_fl(dirvec, head);
- cross_v3_v3v3(norvech, dirvec, imat[2]);
-
- mul_v3_fl(vec, tail);
- cross_v3_v3v3(norvect, vec, imat[2]);
-
- if (id != -1)
- GPU_select_load_id(id | BONESEL_BONE);
-
- glBegin(GL_LINES);
-
- add_v3_v3v3(vec, headvec, norvech);
- glVertex3fv(vec);
-
- add_v3_v3v3(vec, tailvec, norvect);
- glVertex3fv(vec);
-
- sub_v3_v3v3(vec, headvec, norvech);
- glVertex3fv(vec);
-
- sub_v3_v3v3(vec, tailvec, norvect);
- glVertex3fv(vec);
-
- glEnd();
- }
-}
-
-/* does wire only for outline selecting */
-static void draw_sphere_bone(const short dt, int armflag, int boneflag, short constflag, unsigned int id,
- bPoseChannel *pchan, EditBone *ebone)
-{
- GLUquadricObj *qobj;
- float head, tail, length;
- float fac1, fac2;
-
- glPushMatrix();
- qobj = gluNewQuadric();
-
- /* figure out the sizes of spheres */
- if (ebone) {
- length = ebone->length;
- tail = ebone->rad_tail;
- if (ebone->parent && (boneflag & BONE_CONNECTED))
- head = ebone->parent->rad_tail;
- else
- head = ebone->rad_head;
- }
- else {
- length = pchan->bone->length;
- tail = pchan->bone->rad_tail;
- if (pchan->parent && (boneflag & BONE_CONNECTED))
- head = pchan->parent->bone->rad_tail;
- else
- head = pchan->bone->rad_head;
- }
-
- /* move to z-axis space */
- glRotatef(-90.0f, 1.0f, 0.0f, 0.0f);
-
- if (dt == OB_SOLID) {
- /* set up solid drawing */
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
-
- gluQuadricDrawStyle(qobj, GLU_FILL);
- }
- else {
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
- }
-
- /* sphere root color */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColorShade(TH_BONE_SOLID, -30);
- }
- else if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_END, boneflag, constflag);
- else if (dt == OB_SOLID)
- UI_ThemeColorShade(TH_BONE_SOLID, -30);
-
- /* Draw root point if we are not connected */
- if ((boneflag & BONE_CONNECTED) == 0) {
- if (id != -1)
- GPU_select_load_id(id | BONESEL_ROOT);
- gluSphere(qobj, head, 16, 10);
- }
-
- /* Draw tip point */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColorShade(TH_BONE_SOLID, -30);
- }
-
- if (id != -1)
- GPU_select_load_id(id | BONESEL_TIP);
-
- glTranslatef(0.0f, 0.0f, length);
- gluSphere(qobj, tail, 16, 10);
- glTranslatef(0.0f, 0.0f, -length);
-
- /* base */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_SELECT);
- else UI_ThemeColor(TH_BONE_SOLID);
- }
- else if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_SPHEREBONE_BASE, boneflag, constflag);
- else if (dt == OB_SOLID)
- UI_ThemeColor(TH_BONE_SOLID);
-
- fac1 = (length - head) / length;
- fac2 = (length - tail) / length;
-
- if (length > (head + tail)) {
- if (id != -1)
- GPU_select_load_id(id | BONESEL_BONE);
-
- glEnable(GL_POLYGON_OFFSET_FILL);
- glPolygonOffset(-1.0f, -1.0f);
-
- glTranslatef(0.0f, 0.0f, head);
- gluCylinder(qobj, fac1 * head + (1.0f - fac1) * tail, fac2 * tail + (1.0f - fac2) * head, length - head - tail, 16, 1);
- glTranslatef(0.0f, 0.0f, -head);
-
- glDisable(GL_POLYGON_OFFSET_FILL);
-
- /* draw sphere on extrema */
- glTranslatef(0.0f, 0.0f, length - tail);
- gluSphere(qobj, fac2 * tail + (1.0f - fac2) * head, 16, 10);
- glTranslatef(0.0f, 0.0f, -length + tail);
-
- glTranslatef(0.0f, 0.0f, head);
- gluSphere(qobj, fac1 * head + (1.0f - fac1) * tail, 16, 10);
- }
- else {
- /* 1 sphere in center */
- glTranslatef(0.0f, 0.0f, (head + length - tail) / 2.0f);
- gluSphere(qobj, fac1 * head + (1.0f - fac1) * tail, 16, 10);
- }
-
- /* restore */
- if (dt == OB_SOLID) {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
-
- glPopMatrix();
- gluDeleteQuadric(qobj);
-}
-
-static GLubyte bm_dot6[] = {0x0, 0x18, 0x3C, 0x7E, 0x7E, 0x3C, 0x18, 0x0};
-static GLubyte bm_dot8[] = {0x3C, 0x7E, 0xFF, 0xFF, 0xFF, 0xFF, 0x7E, 0x3C};
-
-static GLubyte bm_dot5[] = {0x0, 0x0, 0x10, 0x38, 0x7c, 0x38, 0x10, 0x0};
-static GLubyte bm_dot7[] = {0x0, 0x38, 0x7C, 0xFE, 0xFE, 0xFE, 0x7C, 0x38};
-
-
-static void draw_line_bone(int armflag, int boneflag, short constflag, unsigned int id,
- bPoseChannel *pchan, EditBone *ebone)
-{
- /* call this once, avoid constant changing */
- BLI_assert(glaGetOneInt(GL_UNPACK_ALIGNMENT) == 1);
-
- float length;
-
- if (pchan)
- length = pchan->bone->length;
- else
- length = ebone->length;
-
- glPushMatrix();
- glScalef(length, length, length);
-
- /* this chunk not in object mode */
- if (armflag & (ARM_EDITMODE | ARM_POSEMODE)) {
- glLineWidth(4.0f);
- if (G.f & G_PICKSEL) {
- /* no bitmap in selection mode, crashes 3d cards...
- * instead draw a solid point the same size */
- glPointSize(8.0f);
- }
-
- if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
- else if (armflag & ARM_EDITMODE) {
- UI_ThemeColor(TH_WIRE_EDIT);
- }
-
- /* Draw root point if we are not connected */
- if ((boneflag & BONE_CONNECTED) == 0) {
- if (G.f & G_PICKSEL) {
- GPU_select_load_id(id | BONESEL_ROOT);
- glBegin(GL_POINTS);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glEnd();
- }
- else {
- glRasterPos3f(0.0f, 0.0f, 0.0f);
- glBitmap(8, 8, 4, 4, 0, 0, bm_dot8);
- }
- }
-
- if (id != -1)
- GPU_select_load_id((GLuint) id | BONESEL_BONE);
-
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glEnd();
-
- /* tip */
- if (G.f & G_PICKSEL) {
- /* no bitmap in selection mode, crashes 3d cards... */
- GPU_select_load_id(id | BONESEL_TIP);
- glBegin(GL_POINTS);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glEnd();
- }
- else {
- glRasterPos3f(0.0f, 1.0f, 0.0f);
- glBitmap(8, 8, 4, 4, 0, 0, bm_dot7);
- }
-
- /* further we send no names */
- if (id != -1)
- GPU_select_load_id(id & 0xFFFF); /* object tag, for bordersel optim */
-
- if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_LINEBONE, boneflag, constflag);
- }
-
- glLineWidth(2.0);
-
- /*Draw root point if we are not connected */
- if ((boneflag & BONE_CONNECTED) == 0) {
- if ((G.f & G_PICKSEL) == 0) {
- /* no bitmap in selection mode, crashes 3d cards... */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_ROOTSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColor(TH_VERTEX);
- }
- glRasterPos3f(0.0f, 0.0f, 0.0f);
- glBitmap(8, 8, 4, 4, 0, 0, bm_dot6);
- }
- }
-
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_SELECTED) UI_ThemeColor(TH_EDGE_SELECT);
- else UI_ThemeColorShade(TH_BACK, -30);
- }
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glEnd();
-
- /* tip */
- if ((G.f & G_PICKSEL) == 0) {
- /* no bitmap in selection mode, crashes 3d cards... */
- if (armflag & ARM_EDITMODE) {
- if (boneflag & BONE_TIPSEL) UI_ThemeColor(TH_VERTEX_SELECT);
- else UI_ThemeColor(TH_VERTEX);
- }
- glRasterPos3f(0.0f, 1.0f, 0.0f);
- glBitmap(8, 8, 4, 4, 0, 0, bm_dot5);
- }
-
- glPopMatrix();
-}
-
-/* A partial copy of b_bone_spline_setup(), with just the parts for previewing editmode curve settings
- *
- * This assumes that prev/next bones don't have any impact (since they should all still be in the "straight"
- * position here anyway), and that we can simply apply the bbone settings to get the desired effect...
- */
-static void ebone_spline_preview(EditBone *ebone, Mat4 result_array[MAX_BBONE_SUBDIV])
-{
- float h1[3], h2[3], length, hlength1, hlength2, roll1 = 0.0f, roll2 = 0.0f;
- float mat3[3][3];
- float data[MAX_BBONE_SUBDIV + 1][4], *fp;
- int a;
-
- length = ebone->length;
-
- hlength1 = ebone->ease1 * length * 0.390464f; /* 0.5f * sqrt(2) * kappa, the handle length for near-perfect circles */
- hlength2 = ebone->ease2 * length * 0.390464f;
-
- /* find the handle points, since this is inside bone space, the
- * first point = (0, 0, 0)
- * last point = (0, length, 0)
- *
- * we also just apply all the "extra effects", since they're the whole reason we're doing this...
- */
- h1[0] = ebone->curveInX;
- h1[1] = hlength1;
- h1[2] = ebone->curveInY;
- roll1 = ebone->roll1;
-
- h2[0] = ebone->curveOutX;
- h2[1] = -hlength2;
- h2[2] = ebone->curveOutY;
- roll2 = ebone->roll2;
-
- /* make curve */
- if (ebone->segments > MAX_BBONE_SUBDIV)
- ebone->segments = MAX_BBONE_SUBDIV;
-
- BKE_curve_forward_diff_bezier(0.0f, h1[0], h2[0], 0.0f, data[0], MAX_BBONE_SUBDIV, 4 * sizeof(float));
- BKE_curve_forward_diff_bezier(0.0f, h1[1], length + h2[1], length, data[0] + 1, MAX_BBONE_SUBDIV, 4 * sizeof(float));
- BKE_curve_forward_diff_bezier(0.0f, h1[2], h2[2], 0.0f, data[0] + 2, MAX_BBONE_SUBDIV, 4 * sizeof(float));
- BKE_curve_forward_diff_bezier(roll1, roll1 + 0.390464f * (roll2 - roll1), roll2 - 0.390464f * (roll2 - roll1), roll2, data[0] + 3, MAX_BBONE_SUBDIV, 4 * sizeof(float));
-
- equalize_bbone_bezier(data[0], ebone->segments); /* note: does stride 4! */
-
- /* make transformation matrices for the segments for drawing */
- for (a = 0, fp = data[0]; a < ebone->segments; a++, fp += 4) {
- sub_v3_v3v3(h1, fp + 4, fp);
- vec_roll_to_mat3(h1, fp[3], mat3); /* fp[3] is roll */
-
- copy_m4_m3(result_array[a].mat, mat3);
- copy_v3_v3(result_array[a].mat[3], fp);
-
- /* "extra" scale facs... */
- {
- const int num_segments = ebone->segments;
-
- const float scaleFactorIn = 1.0f + (ebone->scaleIn - 1.0f) * ((float)(num_segments - a) / (float)num_segments);
- const float scaleFactorOut = 1.0f + (ebone->scaleOut - 1.0f) * ((float)(a + 1) / (float)num_segments);
-
- const float scalefac = scaleFactorIn * scaleFactorOut;
- float bscalemat[4][4], bscale[3];
-
- bscale[0] = scalefac;
- bscale[1] = 1.0f;
- bscale[2] = scalefac;
-
- size_to_mat4(bscalemat, bscale);
-
- /* Note: don't multiply by inverse scale mat here, as it causes problems with scaling shearing and breaking segment chains */
- mul_m4_series(result_array[a].mat, result_array[a].mat, bscalemat);
- }
- }
-}
-
-static void draw_b_bone_boxes(const short dt, bPoseChannel *pchan, EditBone *ebone, float xwidth, float length, float zwidth)
-{
- int segments = 0;
-
- if (pchan)
- segments = pchan->bone->segments;
- else if (ebone)
- segments = ebone->segments;
-
- if (segments > 1) {
- float dlen = length / (float)segments;
- Mat4 bbone[MAX_BBONE_SUBDIV];
- int a;
-
- if (pchan) {
- b_bone_spline_setup(pchan, 0, bbone);
- }
- else if (ebone) {
- ebone_spline_preview(ebone, bbone);
- }
-
- for (a = 0; a < segments; a++) {
- glPushMatrix();
- glMultMatrixf(bbone[a].mat);
- if (dt == OB_SOLID) drawsolidcube_size(xwidth, dlen, zwidth);
- else drawcube_size(xwidth, dlen, zwidth);
- glPopMatrix();
- }
- }
- else {
- glPushMatrix();
- if (dt == OB_SOLID) drawsolidcube_size(xwidth, length, zwidth);
- else drawcube_size(xwidth, length, zwidth);
- glPopMatrix();
- }
-}
-
-static void draw_b_bone(const short dt, int armflag, int boneflag, short constflag, unsigned int id,
- bPoseChannel *pchan, EditBone *ebone)
-{
- float xwidth, length, zwidth;
-
- if (pchan) {
- xwidth = pchan->bone->xwidth;
- length = pchan->bone->length;
- zwidth = pchan->bone->zwidth;
- }
- else {
- xwidth = ebone->xwidth;
- length = ebone->length;
- zwidth = ebone->zwidth;
- }
-
- /* draw points only if... */
- if (armflag & ARM_EDITMODE) {
- /* move to unitspace */
- glPushMatrix();
- glScalef(length, length, length);
- draw_bone_points(dt, armflag, boneflag, id);
- glPopMatrix();
- length *= 0.95f; /* make vertices visible */
- }
-
- /* colors for modes */
- if (armflag & ARM_POSEMODE) {
- if (dt <= OB_WIRE)
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
- else
- set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
- }
- else if (armflag & ARM_EDITMODE) {
- if (dt == OB_WIRE) {
- set_ebone_glColor(boneflag);
- }
- else
- UI_ThemeColor(TH_BONE_SOLID);
- }
-
- if (id != -1) {
- GPU_select_load_id((GLuint) id | BONESEL_BONE);
- }
-
- /* set up solid drawing */
- if (dt > OB_WIRE) {
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
-
- if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
- else
- UI_ThemeColor(TH_BONE_SOLID);
-
- draw_b_bone_boxes(OB_SOLID, pchan, ebone, xwidth, length, zwidth);
-
- /* disable solid drawing */
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
- else {
- /* wire */
- if (armflag & ARM_POSEMODE) {
- if (constflag && ((G.f & G_PICKSEL) == 0)) {
- /* set constraint colors */
- if (set_pchan_glColor(PCHAN_COLOR_CONSTS, boneflag, constflag)) {
- glEnable(GL_BLEND);
-
- draw_b_bone_boxes(OB_SOLID, pchan, ebone, xwidth, length, zwidth);
-
- glDisable(GL_BLEND);
- }
-
- /* restore colors */
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
- }
- }
-
- draw_b_bone_boxes(OB_WIRE, pchan, ebone, xwidth, length, zwidth);
- }
-}
-
-static void draw_wire_bone_segments(bPoseChannel *pchan, Mat4 *bbones, float length, int segments)
-{
- if ((segments > 1) && (pchan)) {
- float dlen = length / (float)segments;
- Mat4 *bbone = bbones;
- int a;
-
- for (a = 0; a < segments; a++, bbone++) {
- glPushMatrix();
- glMultMatrixf(bbone->mat);
-
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, dlen, 0.0f);
- glEnd(); /* GL_LINES */
-
- glPopMatrix();
- }
- }
- else {
- glPushMatrix();
-
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3f(0.0f, length, 0.0f);
- glEnd();
-
- glPopMatrix();
- }
-}
-
-static void draw_wire_bone(const short dt, int armflag, int boneflag, short constflag, unsigned int id,
- bPoseChannel *pchan, EditBone *ebone)
-{
- Mat4 bbones_array[MAX_BBONE_SUBDIV];
- Mat4 *bbones = NULL;
- int segments = 0;
- float length;
-
- if (pchan) {
- segments = pchan->bone->segments;
- length = pchan->bone->length;
-
- if (segments > 1) {
- b_bone_spline_setup(pchan, 0, bbones_array);
- bbones = bbones_array;
- }
- }
- else
- length = ebone->length;
-
- /* draw points only if... */
- if (armflag & ARM_EDITMODE) {
- /* move to unitspace */
- glPushMatrix();
- glScalef(length, length, length);
- draw_bone_points(dt, armflag, boneflag, id);
- glPopMatrix();
- length *= 0.95f; /* make vertices visible */
- }
-
- /* this chunk not in object mode */
- if (armflag & (ARM_EDITMODE | ARM_POSEMODE)) {
- if (id != -1)
- GPU_select_load_id((GLuint) id | BONESEL_BONE);
-
- draw_wire_bone_segments(pchan, bbones, length, segments);
-
- /* further we send no names */
- if (id != -1)
- GPU_select_load_id(id & 0xFFFF); /* object tag, for bordersel optim */
- }
-
- /* colors for modes */
- if (armflag & ARM_POSEMODE) {
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
- }
- else if (armflag & ARM_EDITMODE) {
- set_ebone_glColor(boneflag);
- }
-
- /* draw normal */
- draw_wire_bone_segments(pchan, bbones, length, segments);
-}
-
-static void draw_bone(const short dt, int armflag, int boneflag, short constflag, unsigned int id, float length)
-{
-
- /* Draw a 3d octahedral bone, we use normalized space based on length,
- * for display-lists */
-
- glScalef(length, length, length);
-
- /* set up solid drawing */
- if (dt > OB_WIRE) {
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
- UI_ThemeColor(TH_BONE_SOLID);
- }
-
- /* colors for posemode */
- if (armflag & ARM_POSEMODE) {
- if (dt <= OB_WIRE)
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
- else
- set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
- }
-
-
- draw_bone_points(dt, armflag, boneflag, id);
-
- /* now draw the bone itself */
- if (id != -1) {
- GPU_select_load_id((GLuint) id | BONESEL_BONE);
- }
-
- /* wire? */
- if (dt <= OB_WIRE) {
- /* colors */
- if (armflag & ARM_EDITMODE) {
- set_ebone_glColor(boneflag);
- }
- else if (armflag & ARM_POSEMODE) {
- if (constflag && ((G.f & G_PICKSEL) == 0)) {
- /* draw constraint colors */
- if (set_pchan_glColor(PCHAN_COLOR_CONSTS, boneflag, constflag)) {
- glEnable(GL_BLEND);
-
- draw_bone_solid_octahedral();
-
- glDisable(GL_BLEND);
- }
-
- /* restore colors */
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, constflag);
- }
- }
- draw_bone_octahedral();
- }
- else {
- /* solid */
- if (armflag & ARM_POSEMODE)
- set_pchan_glColor(PCHAN_COLOR_SOLID, boneflag, constflag);
- else
- UI_ThemeColor(TH_BONE_SOLID);
- draw_bone_solid_octahedral();
- }
-
- /* disable solid drawing */
- if (dt > OB_WIRE) {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
-}
-
-static void draw_custom_bone(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob,
- const short dt, int armflag, int boneflag, unsigned int id, float length)
-{
- if (ob == NULL) return;
-
- glScalef(length, length, length);
-
- /* colors for posemode */
- if (armflag & ARM_POSEMODE) {
- set_pchan_glColor(PCHAN_COLOR_NORMAL, boneflag, 0);
- }
-
- if (id != -1) {
- GPU_select_load_id((GLuint) id | BONESEL_BONE);
- }
-
- draw_object_instance(scene, v3d, rv3d, ob, dt, armflag & ARM_POSEMODE);
-}
-
-
-static void pchan_draw_IK_root_lines(bPoseChannel *pchan, short only_temp)
-{
- bConstraint *con;
- bPoseChannel *parchan;
-
- for (con = pchan->constraints.first; con; con = con->next) {
- if (con->enforce == 0.0f)
- continue;
-
- switch (con->type) {
- case CONSTRAINT_TYPE_KINEMATIC:
- {
- bKinematicConstraint *data = (bKinematicConstraint *)con->data;
- int segcount = 0;
-
- /* if only_temp, only draw if it is a temporary ik-chain */
- if ((only_temp) && !(data->flag & CONSTRAINT_IK_TEMP))
- continue;
-
- setlinestyle(3);
- glBegin(GL_LINES);
-
- /* exclude tip from chain? */
- if ((data->flag & CONSTRAINT_IK_TIP) == 0)
- parchan = pchan->parent;
- else
- parchan = pchan;
-
- glVertex3fv(parchan->pose_tail);
-
- /* Find the chain's root */
- while (parchan->parent) {
- segcount++;
- if (segcount == data->rootbone || segcount > 255) {
- break; /* 255 is weak */
- }
- parchan = parchan->parent;
- }
- if (parchan)
- glVertex3fv(parchan->pose_head);
-
- glEnd();
- setlinestyle(0);
- break;
- }
- case CONSTRAINT_TYPE_SPLINEIK:
- {
- bSplineIKConstraint *data = (bSplineIKConstraint *)con->data;
- int segcount = 0;
-
- setlinestyle(3);
- glBegin(GL_LINES);
-
- parchan = pchan;
- glVertex3fv(parchan->pose_tail);
-
- /* Find the chain's root */
- while (parchan->parent) {
- segcount++;
- /* FIXME: revise the breaking conditions */
- if (segcount == data->chainlen || segcount > 255) break; /* 255 is weak */
- parchan = parchan->parent;
- }
- /* Only draw line in case our chain is more than one bone long! */
- if (parchan != pchan) /* XXX revise the breaking conditions to only stop at the tail? */
- glVertex3fv(parchan->pose_head);
-
- glEnd();
- setlinestyle(0);
- break;
- }
- }
- }
-}
-
-static void bgl_sphere_project(float ax, float az)
-{
- float dir[3], sine, q3;
-
- sine = 1.0f - ax * ax - az * az;
- q3 = (sine < 0.0f) ? 0.0f : (2.0f * sqrtf(sine));
-
- dir[0] = -az * q3;
- dir[1] = 1.0f - 2.0f * sine;
- dir[2] = ax * q3;
-
- glVertex3fv(dir);
-}
-
-static void draw_dof_ellipse(float ax, float az)
-{
- const float staticSine[16] = {
- 0.0f, 0.104528463268f, 0.207911690818f, 0.309016994375f,
- 0.406736643076f, 0.5f, 0.587785252292f, 0.669130606359f,
- 0.743144825477f, 0.809016994375f, 0.866025403784f,
- 0.913545457643f, 0.951056516295f, 0.978147600734f,
- 0.994521895368f, 1.0f
- };
-
- int i, j, n = 16;
- float x, z, px, pz;
-
- glEnable(GL_BLEND);
- glDepthMask(0);
-
- glColor4ub(70, 70, 70, 50);
-
- glBegin(GL_QUADS);
- pz = 0.0f;
- for (i = 1; i < n; i++) {
- z = staticSine[i];
-
- px = 0.0f;
- for (j = 1; j <= (n - i); j++) {
- x = staticSine[j];
-
- if (j == n - i) {
- glEnd();
- glBegin(GL_TRIANGLES);
- bgl_sphere_project(ax * px, az * z);
- bgl_sphere_project(ax * px, az * pz);
- bgl_sphere_project(ax * x, az * pz);
- glEnd();
- glBegin(GL_QUADS);
- }
- else {
- bgl_sphere_project(ax * x, az * z);
- bgl_sphere_project(ax * x, az * pz);
- bgl_sphere_project(ax * px, az * pz);
- bgl_sphere_project(ax * px, az * z);
- }
-
- px = x;
- }
- pz = z;
- }
- glEnd();
-
- glDisable(GL_BLEND);
- glDepthMask(1);
-
- glColor3ub(0, 0, 0);
-
- glBegin(GL_LINE_STRIP);
- for (i = 0; i < n; i++)
- bgl_sphere_project(staticSine[n - i - 1] * ax, staticSine[i] * az);
- glEnd();
-}
-
-static void draw_pose_dofs(Object *ob)
-{
- bArmature *arm = ob->data;
- bPoseChannel *pchan;
- Bone *bone;
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- bone = pchan->bone;
-
- if ((bone != NULL) && !(bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
- if (bone->flag & BONE_SELECTED) {
- if (bone->layer & arm->layer) {
- if (pchan->ikflag & (BONE_IK_XLIMIT | BONE_IK_ZLIMIT)) {
- if (BKE_pose_channel_in_IK_chain(ob, pchan)) {
- float corner[4][3], posetrans[3], mat[4][4];
- float phi = 0.0f, theta = 0.0f, scale;
- int a, i;
-
- /* in parent-bone pose, but own restspace */
- glPushMatrix();
-
- copy_v3_v3(posetrans, pchan->pose_mat[3]);
- glTranslate3fv(posetrans);
-
- if (pchan->parent) {
- copy_m4_m4(mat, pchan->parent->pose_mat);
- mat[3][0] = mat[3][1] = mat[3][2] = 0.0f;
- glMultMatrixf(mat);
- }
-
- copy_m4_m3(mat, pchan->bone->bone_mat);
- glMultMatrixf(mat);
-
- scale = bone->length * pchan->size[1];
- glScalef(scale, scale, scale);
-
- if (pchan->ikflag & BONE_IK_XLIMIT) {
- if (pchan->ikflag & BONE_IK_ZLIMIT) {
- float amin[3], amax[3];
-
- for (i = 0; i < 3; i++) {
- /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
- amin[i] = sinf(pchan->limitmin[i] * 0.5f);
- amax[i] = sinf(pchan->limitmax[i] * 0.5f);
- }
-
- glScalef(1.0f, -1.0f, 1.0f);
- if ((amin[0] != 0.0f) && (amin[2] != 0.0f))
- draw_dof_ellipse(amin[0], amin[2]);
- if ((amin[0] != 0.0f) && (amax[2] != 0.0f))
- draw_dof_ellipse(amin[0], amax[2]);
- if ((amax[0] != 0.0f) && (amin[2] != 0.0f))
- draw_dof_ellipse(amax[0], amin[2]);
- if ((amax[0] != 0.0f) && (amax[2] != 0.0f))
- draw_dof_ellipse(amax[0], amax[2]);
- glScalef(1.0f, -1.0f, 1.0f);
- }
- }
-
- /* arcs */
- if (pchan->ikflag & BONE_IK_ZLIMIT) {
- /* OpenGL requires rotations in degrees; so we're taking the average angle here */
- theta = RAD2DEGF(0.5f * (pchan->limitmin[2] + pchan->limitmax[2]));
- glRotatef(theta, 0.0f, 0.0f, 1.0f);
-
- glColor3ub(50, 50, 255); /* blue, Z axis limit */
- glBegin(GL_LINE_STRIP);
- for (a = -16; a <= 16; a++) {
- /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
- float fac = ((float)a) / 16.0f * 0.5f;
-
- phi = fac * (pchan->limitmax[2] - pchan->limitmin[2]);
-
- i = (a == -16) ? 0 : 1;
- corner[i][0] = sinf(phi);
- corner[i][1] = cosf(phi);
- corner[i][2] = 0.0f;
- glVertex3fv(corner[i]);
- }
- glEnd();
-
- glRotatef(-theta, 0.0f, 0.0f, 1.0f);
- }
-
- if (pchan->ikflag & BONE_IK_XLIMIT) {
- /* OpenGL requires rotations in degrees; so we're taking the average angle here */
- theta = RAD2DEGF(0.5f * (pchan->limitmin[0] + pchan->limitmax[0]));
- glRotatef(theta, 1.0f, 0.0f, 0.0f);
-
- glColor3ub(255, 50, 50); /* Red, X axis limit */
- glBegin(GL_LINE_STRIP);
- for (a = -16; a <= 16; a++) {
- /* *0.5f here comes from M_PI/360.0f when rotations were still in degrees */
- float fac = ((float)a) / 16.0f * 0.5f;
- phi = (float)M_PI_2 + fac * (pchan->limitmax[0] - pchan->limitmin[0]);
-
- i = (a == -16) ? 2 : 3;
- corner[i][0] = 0.0f;
- corner[i][1] = sinf(phi);
- corner[i][2] = cosf(phi);
- glVertex3fv(corner[i]);
- }
- glEnd();
-
- glRotatef(-theta, 1.0f, 0.0f, 0.0f);
- }
-
- /* out of cone, out of bone */
- glPopMatrix();
- }
- }
- }
- }
- }
- }
-}
-
-static void bone_matrix_translate_y(float mat[4][4], float y)
-{
- float trans[3];
-
- copy_v3_v3(trans, mat[1]);
- mul_v3_fl(trans, y);
- add_v3_v3(mat[3], trans);
-}
-
-/* assumes object is Armature with pose */
-static void draw_pose_bones(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
- const short dt, const unsigned char ob_wire_col[4],
- const bool do_const_color, const bool is_outline)
-{
- RegionView3D *rv3d = ar->regiondata;
- Object *ob = base->object;
- bArmature *arm = ob->data;
- bPoseChannel *pchan;
- Bone *bone;
- float smat[4][4], imat[4][4], bmat[4][4];
- int index = -1;
- const enum {
- DASH_RELATIONSHIP_LINES = 1,
- DASH_HELP_LINES = 2,
- } do_dashed = (
- (is_outline ? 0 : DASH_RELATIONSHIP_LINES) |
- ((v3d->flag & V3D_HIDE_HELPLINES) ? 0 : DASH_HELP_LINES));
- bool draw_wire = false;
- int flag;
- bool is_cull_enabled;
-
- /* being set below */
- arm->layer_used = 0;
-
- /* precalc inverse matrix for drawing screen aligned */
- if (arm->drawtype == ARM_ENVELOPE) {
- /* precalc inverse matrix for drawing screen aligned */
- copy_m4_m4(smat, rv3d->viewmatob);
- mul_mat3_m4_fl(smat, 1.0f / len_v3(ob->obmat[0]));
- invert_m4_m4(imat, smat);
-
- /* and draw blended distances */
- if (arm->flag & ARM_POSEMODE) {
- glEnable(GL_BLEND);
-
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- bone = pchan->bone;
- if (bone) {
- /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194]
- * NOTE: this is the only case with (NO_DEFORM == 0) flag, as this is for envelope influence drawing
- */
- if (((bone->flag & (BONE_HIDDEN_P | BONE_NO_DEFORM | BONE_HIDDEN_PG)) == 0) &&
- ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0))
- {
- if (bone->flag & (BONE_SELECTED)) {
- if (bone->layer & arm->layer)
- draw_sphere_bone_dist(smat, imat, pchan, NULL);
- }
- }
- }
- }
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- glDisable(GL_BLEND);
- }
- }
-
- /* little speedup, also make sure transparent only draws once */
- glCullFace(GL_BACK);
- if (v3d->flag2 & V3D_BACKFACE_CULLING) {
- glEnable(GL_CULL_FACE);
- is_cull_enabled = true;
- }
- else {
- is_cull_enabled = false;
- }
-
- /* if solid we draw that first, with selection codes, but without names, axes etc */
- if (dt > OB_WIRE) {
- if (arm->flag & ARM_POSEMODE)
- index = base->selcol;
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- bone = pchan->bone;
- arm->layer_used |= bone->layer;
-
- /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
- if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) &&
- ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0))
- {
- if (bone->layer & arm->layer) {
- const bool use_custom = (pchan->custom) && !(arm->flag & ARM_NO_CUSTOM);
- glPushMatrix();
-
- if (use_custom && pchan->custom_tx) {
- glMultMatrixf(pchan->custom_tx->pose_mat);
- }
- else {
- glMultMatrixf(pchan->pose_mat);
- }
-
- /* catch exception for bone with hidden parent */
- flag = bone->flag;
- if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG))) {
- flag &= ~BONE_CONNECTED;
- }
-
- /* set temporary flag for drawing bone as active, but only if selected */
- if (bone == arm->act_bone)
- flag |= BONE_DRAW_ACTIVE;
-
- if (do_const_color) {
- /* keep color */
- }
- else {
- /* set color-set to use */
- set_pchan_colorset(ob, pchan);
- }
-
- /* may be 2x width from custom bone's outline option */
- glLineWidth(1.0f);
-
- if (use_custom) {
- /* if drawwire, don't try to draw in solid */
- if (pchan->bone->flag & BONE_DRAWWIRE) {
- draw_wire = true;
- }
- else {
- if (is_cull_enabled && (v3d->flag2 & V3D_BACKFACE_CULLING) == 0) {
- is_cull_enabled = false;
- glDisable(GL_CULL_FACE);
- }
-
- draw_custom_bone(scene, v3d, rv3d, pchan->custom,
- OB_SOLID, arm->flag, flag, index, PCHAN_CUSTOM_DRAW_SIZE(pchan));
- }
- }
- else {
- if (is_cull_enabled == false) {
- is_cull_enabled = true;
- glEnable(GL_CULL_FACE);
- }
-
- if (arm->drawtype == ARM_LINE) {
- /* nothing in solid */
- }
- else if (arm->drawtype == ARM_WIRE) {
- /* nothing in solid */
- }
- else if (arm->drawtype == ARM_ENVELOPE) {
- draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
- }
- else if (arm->drawtype == ARM_B_BONE) {
- draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, pchan, NULL);
- }
- else {
- draw_bone(OB_SOLID, arm->flag, flag, 0, index, bone->length);
- }
- }
-
- glPopMatrix();
- }
- }
-
- if (index != -1)
- index += 0x10000; /* pose bones count in higher 2 bytes only */
- }
-
- /* very very confusing... but in object mode, solid draw, we cannot do GPU_select_load_id yet,
- * stick bones and/or wire custom-shapes are drawn in next loop
- */
- if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE) == 0 && (draw_wire == false) && index != -1) {
- /* object tag, for bordersel optim */
- GPU_select_load_id(index & 0xFFFF);
- index = -1;
- }
- }
-
- /* custom bone may draw outline double-width */
- if (arm->flag & ARM_POSEMODE) {
- glLineWidth(1.0f);
- }
-
- /* draw custom bone shapes as wireframes */
- if (!(arm->flag & ARM_NO_CUSTOM) &&
- (draw_wire || (dt <= OB_WIRE)) )
- {
- if (arm->flag & ARM_POSEMODE)
- index = base->selcol;
-
- /* only draw custom bone shapes that need to be drawn as wires */
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- bone = pchan->bone;
-
- /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
- if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) &&
- ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0) )
- {
- if (bone->layer & arm->layer) {
- if (pchan->custom) {
- if ((dt < OB_SOLID) || (bone->flag & BONE_DRAWWIRE)) {
- glPushMatrix();
-
- if (pchan->custom_tx) {
- glMultMatrixf(pchan->custom_tx->pose_mat);
- }
- else {
- glMultMatrixf(pchan->pose_mat);
- }
-
- /* prepare colors */
- if (do_const_color) {
- /* 13 October 2009, Disabled this to make ghosting show the right colors (Aligorith) */
- }
- else if (arm->flag & ARM_POSEMODE)
- set_pchan_colorset(ob, pchan);
- else {
- glColor3ubv(ob_wire_col);
- }
-
- /* catch exception for bone with hidden parent */
- flag = bone->flag;
- if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)))
- flag &= ~BONE_CONNECTED;
-
- /* set temporary flag for drawing bone as active, but only if selected */
- if (bone == arm->act_bone)
- flag |= BONE_DRAW_ACTIVE;
-
- draw_custom_bone(scene, v3d, rv3d, pchan->custom,
- OB_WIRE, arm->flag, flag, index, PCHAN_CUSTOM_DRAW_SIZE(pchan));
-
- glPopMatrix();
- }
- }
- }
- }
-
- if (index != -1)
- index += 0x10000; /* pose bones count in higher 2 bytes only */
- }
- /* stick or wire bones have not been drawn yet so don't clear object selection in this case */
- if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE) == 0 && draw_wire && index != -1) {
- /* object tag, for bordersel optim */
- GPU_select_load_id(index & 0xFFFF);
- index = -1;
- }
- }
-
- /* wire draw over solid only in posemode */
- if ((dt <= OB_WIRE) || (arm->flag & ARM_POSEMODE) || ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
- /* draw line check first. we do selection indices */
- if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
- if (arm->flag & ARM_POSEMODE)
- index = base->selcol;
- }
- /* if solid && posemode, we draw again with polygonoffset */
- else if ((dt > OB_WIRE) && (arm->flag & ARM_POSEMODE)) {
- ED_view3d_polygon_offset(rv3d, 1.0);
- }
- else {
- /* and we use selection indices if not done yet */
- if (arm->flag & ARM_POSEMODE)
- index = base->selcol;
- }
-
- if (is_cull_enabled == false) {
- is_cull_enabled = true;
- glEnable(GL_CULL_FACE);
- }
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- bone = pchan->bone;
- arm->layer_used |= bone->layer;
-
- /* 1) bone must be visible, 2) for OpenGL select-drawing cannot have unselectable [#27194] */
- if (((bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) &&
- ((G.f & G_PICKSEL) == 0 || (bone->flag & BONE_UNSELECTABLE) == 0))
- {
- if (bone->layer & arm->layer) {
- const short constflag = pchan->constflag;
- if ((do_dashed & DASH_RELATIONSHIP_LINES) && (pchan->parent)) {
- /* Draw a line from our root to the parent's tip
- * - only if V3D_HIDE_HELPLINES is enabled...
- */
- if ((do_dashed & DASH_HELP_LINES) && ((bone->flag & BONE_CONNECTED) == 0)) {
- if (arm->flag & ARM_POSEMODE) {
- GPU_select_load_id(index & 0xFFFF); /* object tag, for bordersel optim */
- UI_ThemeColor(TH_WIRE);
- }
- setlinestyle(3);
- glBegin(GL_LINES);
- glVertex3fv(pchan->pose_head);
- glVertex3fv(pchan->parent->pose_tail);
- glEnd();
- setlinestyle(0);
- }
-
- /* Draw a line to IK root bone
- * - only if temporary chain (i.e. "autoik")
- */
- if (arm->flag & ARM_POSEMODE) {
- if (constflag & PCHAN_HAS_IK) {
- if (bone->flag & BONE_SELECTED) {
- if (constflag & PCHAN_HAS_TARGET) glColor3ub(200, 120, 0);
- else glColor3ub(200, 200, 50); /* add theme! */
-
- GPU_select_load_id(index & 0xFFFF);
- pchan_draw_IK_root_lines(pchan, !(do_dashed & DASH_HELP_LINES));
- }
- }
- else if (constflag & PCHAN_HAS_SPLINEIK) {
- if (bone->flag & BONE_SELECTED) {
- glColor3ub(150, 200, 50); /* add theme! */
-
- GPU_select_load_id(index & 0xFFFF);
- pchan_draw_IK_root_lines(pchan, !(do_dashed & DASH_HELP_LINES));
- }
- }
- }
- }
-
- glPushMatrix();
- if (arm->drawtype != ARM_ENVELOPE)
- glMultMatrixf(pchan->pose_mat);
-
- /* catch exception for bone with hidden parent */
- flag = bone->flag;
- if ((bone->parent) && (bone->parent->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)))
- flag &= ~BONE_CONNECTED;
-
- /* set temporary flag for drawing bone as active, but only if selected */
- if (bone == arm->act_bone)
- flag |= BONE_DRAW_ACTIVE;
-
- /* extra draw service for pose mode */
-
- /* set color-set to use */
- if (do_const_color) {
- /* keep color */
- }
- else {
- set_pchan_colorset(ob, pchan);
- }
-
- if ((pchan->custom) && !(arm->flag & ARM_NO_CUSTOM)) {
- /* custom bone shapes should not be drawn here! */
- }
- else if (arm->drawtype == ARM_ENVELOPE) {
- if (dt < OB_SOLID)
- draw_sphere_bone_wire(smat, imat, arm->flag, flag, constflag, index, pchan, NULL);
- }
- else if (arm->drawtype == ARM_LINE)
- draw_line_bone(arm->flag, flag, constflag, index, pchan, NULL);
- else if (arm->drawtype == ARM_WIRE)
- draw_wire_bone(dt, arm->flag, flag, constflag, index, pchan, NULL);
- else if (arm->drawtype == ARM_B_BONE)
- draw_b_bone(OB_WIRE, arm->flag, flag, constflag, index, pchan, NULL);
- else
- draw_bone(OB_WIRE, arm->flag, flag, constflag, index, bone->length);
-
- glPopMatrix();
- }
- }
-
- /* pose bones count in higher 2 bytes only */
- if (index != -1)
- index += 0x10000;
- }
- /* restore things */
- if (!ELEM(arm->drawtype, ARM_WIRE, ARM_LINE) && (dt > OB_WIRE) && (arm->flag & ARM_POSEMODE))
- ED_view3d_polygon_offset(rv3d, 0.0);
- }
-
- /* restore */
- if (is_cull_enabled) {
- glDisable(GL_CULL_FACE);
- }
-
- /* draw DoFs */
- if (arm->flag & ARM_POSEMODE) {
- if (((base->flag & OB_FROMDUPLI) == 0) && ((v3d->flag & V3D_HIDE_HELPLINES) == 0)) {
- draw_pose_dofs(ob);
- }
- }
-
- /* finally names and axes */
- if ((arm->flag & (ARM_DRAWNAMES | ARM_DRAWAXES)) &&
- (is_outline == 0) &&
- ((base->flag & OB_FROMDUPLI) == 0))
- {
- /* patch for several 3d cards (IBM mostly) that crash on GL_SELECT with text drawing */
- if ((G.f & G_PICKSEL) == 0) {
- float vec[3];
-
- unsigned char col[4];
- if (do_const_color) {
- /* so we can draw bone names in current const color */
- float tcol[4];
- glGetFloatv(GL_CURRENT_COLOR, tcol);
- rgb_float_to_uchar(col, tcol);
- col[3] = 255;
- }
- else {
- col[0] = ob_wire_col[0];
- col[1] = ob_wire_col[1];
- col[2] = ob_wire_col[2];
- col[3] = 255;
- }
-
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- if ((pchan->bone->flag & (BONE_HIDDEN_P | BONE_HIDDEN_PG)) == 0) {
- if (pchan->bone->layer & arm->layer) {
- if (arm->flag & (ARM_EDITMODE | ARM_POSEMODE)) {
- bone = pchan->bone;
- UI_GetThemeColor3ubv((bone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, col);
- }
- else if (dt > OB_WIRE) {
- UI_GetThemeColor3ubv(TH_TEXT, col);
- }
-
- /* Draw names of bone */
- if (arm->flag & ARM_DRAWNAMES) {
- mid_v3_v3v3(vec, pchan->pose_head, pchan->pose_tail);
- view3d_cached_text_draw_add(vec, pchan->name, strlen(pchan->name), 10, 0, col);
- }
-
- /* Draw additional axes on the bone tail */
- if ((arm->flag & ARM_DRAWAXES) && (arm->flag & ARM_POSEMODE)) {
- glPushMatrix();
- copy_m4_m4(bmat, pchan->pose_mat);
- bone_matrix_translate_y(bmat, pchan->bone->length);
- glMultMatrixf(bmat);
-
- glColor3ubv(col);
-
- float viewmat_pchan[4][4];
- mul_m4_m4m4(viewmat_pchan, rv3d->viewmatob, bmat);
- drawaxes(viewmat_pchan, pchan->bone->length * 0.25f, OB_ARROWS);
-
- glPopMatrix();
- }
- }
- }
- }
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- }
- }
-
- if (index != -1) {
- GPU_select_load_id(-1);
- }
-}
-
-/* in editmode, we don't store the bone matrix... */
-static void get_matrix_editbone(EditBone *ebone, float bmat[4][4])
-{
- ebone->length = len_v3v3(ebone->tail, ebone->head);
- ED_armature_ebone_to_mat4(ebone, bmat);
-}
-
-static void draw_ebones(View3D *v3d, ARegion *ar, Object *ob, const short dt)
-{
- RegionView3D *rv3d = ar->regiondata;
- EditBone *eBone;
- bArmature *arm = ob->data;
- float smat[4][4], imat[4][4], bmat[4][4];
- unsigned int index;
- int flag;
-
- /* being set in code below */
- arm->layer_used = 0;
-
- ED_view3d_check_mats_rv3d(rv3d);
-
- /* envelope (deform distance) */
- if (arm->drawtype == ARM_ENVELOPE) {
- /* precalc inverse matrix for drawing screen aligned */
- copy_m4_m4(smat, rv3d->viewmatob);
- mul_mat3_m4_fl(smat, 1.0f / len_v3(ob->obmat[0]));
- invert_m4_m4(imat, smat);
-
- /* and draw blended distances */
- glEnable(GL_BLEND);
-
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
- if (eBone->layer & arm->layer) {
- if ((eBone->flag & (BONE_HIDDEN_A | BONE_NO_DEFORM)) == 0) {
- if (eBone->flag & (BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL))
- draw_sphere_bone_dist(smat, imat, NULL, eBone);
- }
- }
- }
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- glDisable(GL_BLEND);
- }
-
- /* if solid we draw it first */
- if ((dt > OB_WIRE) && (arm->drawtype != ARM_LINE)) {
- for (eBone = arm->edbo->first, index = 0; eBone; eBone = eBone->next, index++) {
- if (eBone->layer & arm->layer) {
- if ((eBone->flag & BONE_HIDDEN_A) == 0) {
- glPushMatrix();
- get_matrix_editbone(eBone, bmat);
- glMultMatrixf(bmat);
-
- /* catch exception for bone with hidden parent */
- flag = eBone->flag;
- if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) {
- flag &= ~BONE_CONNECTED;
- }
-
- /* set temporary flag for drawing bone as active, but only if selected */
- if (eBone == arm->act_edbone)
- flag |= BONE_DRAW_ACTIVE;
-
- if (arm->drawtype == ARM_ENVELOPE)
- draw_sphere_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
- else if (arm->drawtype == ARM_B_BONE)
- draw_b_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
- else if (arm->drawtype == ARM_WIRE)
- draw_wire_bone(OB_SOLID, arm->flag, flag, 0, index, NULL, eBone);
- else {
- draw_bone(OB_SOLID, arm->flag, flag, 0, index, eBone->length);
- }
-
- glPopMatrix();
- }
- }
- }
- }
-
- /* if wire over solid, set offset */
- index = -1;
- GPU_select_load_id(-1);
- if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
- if (G.f & G_PICKSEL)
- index = 0;
- }
- else if (dt > OB_WIRE)
- ED_view3d_polygon_offset(rv3d, 1.0);
- else if (arm->flag & ARM_EDITMODE)
- index = 0; /* do selection codes */
-
- for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
- arm->layer_used |= eBone->layer;
- if (eBone->layer & arm->layer) {
- if ((eBone->flag & BONE_HIDDEN_A) == 0) {
-
- /* catch exception for bone with hidden parent */
- flag = eBone->flag;
- if ((eBone->parent) && !EBONE_VISIBLE(arm, eBone->parent)) {
- flag &= ~BONE_CONNECTED;
- }
-
- /* set temporary flag for drawing bone as active, but only if selected */
- if (eBone == arm->act_edbone)
- flag |= BONE_DRAW_ACTIVE;
-
- if (arm->drawtype == ARM_ENVELOPE) {
- if (dt < OB_SOLID)
- draw_sphere_bone_wire(smat, imat, arm->flag, flag, 0, index, NULL, eBone);
- }
- else {
- glPushMatrix();
- get_matrix_editbone(eBone, bmat);
- glMultMatrixf(bmat);
-
- if (arm->drawtype == ARM_LINE)
- draw_line_bone(arm->flag, flag, 0, index, NULL, eBone);
- else if (arm->drawtype == ARM_WIRE)
- draw_wire_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
- else if (arm->drawtype == ARM_B_BONE)
- draw_b_bone(OB_WIRE, arm->flag, flag, 0, index, NULL, eBone);
- else
- draw_bone(OB_WIRE, arm->flag, flag, 0, index, eBone->length);
-
- glPopMatrix();
- }
-
- /* offset to parent */
- if (eBone->parent) {
- UI_ThemeColor(TH_WIRE_EDIT);
- GPU_select_load_id(-1); /* -1 here is OK! */
- setlinestyle(3);
-
- glBegin(GL_LINES);
- glVertex3fv(eBone->parent->tail);
- glVertex3fv(eBone->head);
- glEnd();
-
- setlinestyle(0);
- }
- }
- }
- if (index != -1) index++;
- }
-
- /* restore */
- if (index != -1) {
- GPU_select_load_id(-1);
- }
-
- if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
- /* pass */
- }
- else if (dt > OB_WIRE) {
- ED_view3d_polygon_offset(rv3d, 0.0);
- }
-
- /* finally names and axes */
- if (arm->flag & (ARM_DRAWNAMES | ARM_DRAWAXES)) {
- /* patch for several 3d cards (IBM mostly) that crash on GL_SELECT with text drawing */
- if ((G.f & G_PICKSEL) == 0) {
- float vec[3];
- unsigned char col[4];
- col[3] = 255;
-
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- for (eBone = arm->edbo->first; eBone; eBone = eBone->next) {
- if (eBone->layer & arm->layer) {
- if ((eBone->flag & BONE_HIDDEN_A) == 0) {
-
- UI_GetThemeColor3ubv((eBone->flag & BONE_SELECTED) ? TH_TEXT_HI : TH_TEXT, col);
-
- /* Draw name */
- if (arm->flag & ARM_DRAWNAMES) {
- mid_v3_v3v3(vec, eBone->head, eBone->tail);
- view3d_cached_text_draw_add(vec, eBone->name, strlen(eBone->name), 10, 0, col);
- }
- /* Draw additional axes */
- if (arm->flag & ARM_DRAWAXES) {
- glPushMatrix();
- get_matrix_editbone(eBone, bmat);
- bone_matrix_translate_y(bmat, eBone->length);
- glMultMatrixf(bmat);
-
- glColor3ubv(col);
-
- float viewmat_ebone[4][4];
- mul_m4_m4m4(viewmat_ebone, rv3d->viewmatob, bmat);
- drawaxes(viewmat_ebone, eBone->length * 0.25f, OB_ARROWS);
-
- glPopMatrix();
- }
-
- }
- }
- }
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- }
- }
-}
-
-/* ****************************** Armature Visualization ******************************** */
-
-/* ---------- Paths --------- */
-
-/* draw bone paths
- * - in view space
- */
-static void draw_pose_paths(Scene *scene, View3D *v3d, ARegion *ar, Object *ob)
-{
- bAnimVizSettings *avs = &ob->pose->avs;
- bArmature *arm = ob->data;
- bPoseChannel *pchan;
-
- /* setup drawing environment for paths */
- draw_motion_paths_init(v3d, ar);
-
- /* draw paths where they exist and they releated bone is visible */
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- if ((pchan->bone->layer & arm->layer) && (pchan->mpath))
- draw_motion_path_instance(scene, ob, pchan, avs, pchan->mpath);
- }
-
- /* cleanup after drawing */
- draw_motion_paths_cleanup(v3d);
-}
-
-
-/* ---------- Ghosts --------- */
-
-/* helper function for ghost drawing - sets/removes flags for temporarily
- * hiding unselected bones while drawing ghosts
- */
-static void ghost_poses_tag_unselected(Object *ob, short unset)
-{
- bArmature *arm = ob->data;
- bPose *pose = ob->pose;
- bPoseChannel *pchan;
-
- /* don't do anything if no hiding any bones */
- if ((arm->flag & ARM_GHOST_ONLYSEL) == 0)
- return;
-
- /* loop over all pchans, adding/removing tags as appropriate */
- for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
- if ((pchan->bone) && (arm->layer & pchan->bone->layer)) {
- if (unset) {
- /* remove tags from all pchans if cleaning up */
- pchan->bone->flag &= ~BONE_HIDDEN_PG;
- }
- else {
- /* set tags on unselected pchans only */
- if ((pchan->bone->flag & BONE_SELECTED) == 0)
- pchan->bone->flag |= BONE_HIDDEN_PG;
- }
- }
- }
-}
-
-/* draw ghosts that occur within a frame range
- * note: object should be in posemode
- */
-static void draw_ghost_poses_range(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
-{
- Object *ob = base->object;
- AnimData *adt = BKE_animdata_from_id(&ob->id);
- bArmature *arm = ob->data;
- bPose *posen, *poseo;
- float start, end, stepsize, range, colfac;
- int cfrao, flago;
-
- start = (float)arm->ghostsf;
- end = (float)arm->ghostef;
- if (end <= start)
- return;
-
- /* prevent infinite loops if this is set to 0 - T49527 */
- if (arm->ghostsize < 1)
- arm->ghostsize = 1;
-
- stepsize = (float)(arm->ghostsize);
- range = (float)(end - start);
-
- /* store values */
- ob->mode &= ~OB_MODE_POSE;
- cfrao = CFRA;
- flago = arm->flag;
- arm->flag &= ~(ARM_DRAWNAMES | ARM_DRAWAXES);
-
- /* copy the pose */
- poseo = ob->pose;
- BKE_pose_copy_data(&posen, ob->pose, 1);
- ob->pose = posen;
- BKE_pose_rebuild(ob, ob->data); /* child pointers for IK */
- ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
-
- glEnable(GL_BLEND);
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- /* draw from first frame of range to last */
- for (CFRA = (int)start; CFRA <= end; CFRA += (int)stepsize) {
- colfac = (end - (float)CFRA) / range;
- UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
-
- BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
- BKE_pose_where_is(scene, ob);
- draw_pose_bones(scene, v3d, ar, base, OB_WIRE, NULL, true, false);
- }
- glDisable(GL_BLEND);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
-
- /* before disposing of temp pose, use it to restore object to a sane state */
- BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL);
-
- /* clean up temporary pose */
- ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
- BKE_pose_free(posen);
-
- /* restore */
- CFRA = cfrao;
- ob->pose = poseo;
- arm->flag = flago;
- ob->mode |= OB_MODE_POSE;
-}
-
-/* draw ghosts on keyframes in action within range
- * - object should be in posemode
- */
-static void draw_ghost_poses_keys(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
-{
- Object *ob = base->object;
- AnimData *adt = BKE_animdata_from_id(&ob->id);
- bAction *act = (adt) ? adt->action : NULL;
- bArmature *arm = ob->data;
- bPose *posen, *poseo;
- DLRBT_Tree keys;
- ActKeyColumn *ak, *akn;
- float start, end, range, colfac, i;
- int cfrao, flago;
-
- start = (float)arm->ghostsf;
- end = (float)arm->ghostef;
- if (end <= start)
- return;
-
- /* get keyframes - then clip to only within range */
- BLI_dlrbTree_init(&keys);
- action_to_keylist(adt, act, &keys, NULL);
- BLI_dlrbTree_linkedlist_sync(&keys);
-
- range = 0;
- for (ak = keys.first; ak; ak = akn) {
- akn = ak->next;
-
- if ((ak->cfra < start) || (ak->cfra > end))
- BLI_freelinkN((ListBase *)&keys, ak);
- else
- range++;
- }
- if (range == 0) return;
-
- /* store values */
- ob->mode &= ~OB_MODE_POSE;
- cfrao = CFRA;
- flago = arm->flag;
- arm->flag &= ~(ARM_DRAWNAMES | ARM_DRAWAXES);
-
- /* copy the pose */
- poseo = ob->pose;
- BKE_pose_copy_data(&posen, ob->pose, 1);
- ob->pose = posen;
- BKE_pose_rebuild(ob, ob->data); /* child pointers for IK */
- ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
-
- glEnable(GL_BLEND);
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- /* draw from first frame of range to last */
- for (ak = keys.first, i = 0; ak; ak = ak->next, i++) {
- colfac = i / range;
- UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
-
- CFRA = (int)ak->cfra;
-
- BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
- BKE_pose_where_is(scene, ob);
- draw_pose_bones(scene, v3d, ar, base, OB_WIRE, NULL, true, false);
- }
- glDisable(GL_BLEND);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
-
- /* before disposing of temp pose, use it to restore object to a sane state */
- BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL);
-
- /* clean up temporary pose */
- ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
- BLI_dlrbTree_free(&keys);
- BKE_pose_free(posen);
-
- /* restore */
- CFRA = cfrao;
- ob->pose = poseo;
- arm->flag = flago;
- ob->mode |= OB_MODE_POSE;
-}
-
-/* draw ghosts around current frame
- * - object is supposed to be armature in posemode
- */
-static void draw_ghost_poses(Scene *scene, View3D *v3d, ARegion *ar, Base *base)
-{
- Object *ob = base->object;
- AnimData *adt = BKE_animdata_from_id(&ob->id);
- bArmature *arm = ob->data;
- bPose *posen, *poseo;
- float cur, start, end, stepsize, range, colfac, actframe, ctime;
- int cfrao, flago;
-
- /* pre conditions, get an action with sufficient frames */
- if (ELEM(NULL, adt, adt->action))
- return;
-
- calc_action_range(adt->action, &start, &end, 0);
- if (start == end)
- return;
-
- /* prevent infinite loops if this is set to 0 - T49527 */
- if (arm->ghostsize < 1)
- arm->ghostsize = 1;
-
- stepsize = (float)(arm->ghostsize);
- range = (float)(arm->ghostep) * stepsize + 0.5f; /* plus half to make the for loop end correct */
-
- /* store values */
- ob->mode &= ~OB_MODE_POSE;
- cfrao = CFRA;
- actframe = BKE_nla_tweakedit_remap(adt, (float)CFRA, 0);
- flago = arm->flag;
- arm->flag &= ~(ARM_DRAWNAMES | ARM_DRAWAXES);
-
- /* copy the pose */
- poseo = ob->pose;
- BKE_pose_copy_data(&posen, ob->pose, 1);
- ob->pose = posen;
- BKE_pose_rebuild(ob, ob->data); /* child pointers for IK */
- ghost_poses_tag_unselected(ob, 0); /* hide unselected bones if need be */
-
- glEnable(GL_BLEND);
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- /* draw from darkest blend to lowest */
- for (cur = stepsize; cur < range; cur += stepsize) {
- ctime = cur - (float)fmod(cfrao, stepsize); /* ensures consistent stepping */
- colfac = ctime / range;
- UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
-
- /* only within action range */
- if (actframe + ctime >= start && actframe + ctime <= end) {
- CFRA = (int)BKE_nla_tweakedit_remap(adt, actframe + ctime, NLATIME_CONVERT_MAP);
-
- if (CFRA != cfrao) {
- BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
- BKE_pose_where_is(scene, ob);
- draw_pose_bones(scene, v3d, ar, base, OB_WIRE, NULL, true, false);
- }
- }
-
- ctime = cur + (float)fmod((float)cfrao, stepsize) - stepsize + 1.0f; /* ensures consistent stepping */
- colfac = ctime / range;
- UI_ThemeColorShadeAlpha(TH_WIRE, 0, -128 - (int)(120.0f * sqrtf(colfac)));
-
- /* only within action range */
- if ((actframe - ctime >= start) && (actframe - ctime <= end)) {
- CFRA = (int)BKE_nla_tweakedit_remap(adt, actframe - ctime, NLATIME_CONVERT_MAP);
-
- if (CFRA != cfrao) {
- BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)CFRA, ADT_RECALC_ALL);
- BKE_pose_where_is(scene, ob);
- draw_pose_bones(scene, v3d, ar, base, OB_WIRE, NULL, true, false);
- }
- }
- }
- glDisable(GL_BLEND);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
-
- /* before disposing of temp pose, use it to restore object to a sane state */
- BKE_animsys_evaluate_animdata(scene, &ob->id, adt, (float)cfrao, ADT_RECALC_ALL);
-
- /* clean up temporary pose */
- ghost_poses_tag_unselected(ob, 1); /* unhide unselected bones if need be */
- BKE_pose_free(posen);
-
- /* restore */
- CFRA = cfrao;
- ob->pose = poseo;
- arm->flag = flago;
- ob->mode |= OB_MODE_POSE;
-}
-
-/* ********************************** Armature Drawing - Main ************************* */
-
-/* called from drawobject.c, return true if nothing was drawn
- * (ob_wire_col == NULL) when drawing ghost */
-bool draw_armature(Scene *scene, View3D *v3d, ARegion *ar, Base *base,
- const short dt, const short dflag, const unsigned char ob_wire_col[4],
- const bool is_outline)
-{
- Object *ob = base->object;
- bArmature *arm = ob->data;
- bool retval = false;
-
- if (v3d->flag2 & V3D_RENDER_OVERRIDE)
- return true;
-
- /* needed for 'draw_line_bone' which draws pixel. */
- if (arm->drawtype == ARM_LINE) {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- }
-
- if (dt > OB_WIRE) {
- /* we use color for solid lighting */
- if (ELEM(arm->drawtype, ARM_LINE, ARM_WIRE)) {
- const float diffuse[3] = {0.64f, 0.64f, 0.64f};
- const float specular[3] = {0.5f, 0.5f, 0.5f};
- GPU_basic_shader_colors(diffuse, specular, 35, 1.0f);
- }
- else {
- const float diffuse[3] = {1.0f, 1.0f, 1.0f};
- const float specular[3] = {1.0f, 1.0f, 1.0f};
- GPU_basic_shader_colors(diffuse, specular, 35, 1.0f);
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW); /* only for lighting... */
- }
- }
-
- /* arm->flag is being used to detect mode... */
- /* editmode? */
- if (arm->edbo) {
- arm->flag |= ARM_EDITMODE;
- draw_ebones(v3d, ar, ob, dt);
- arm->flag &= ~ARM_EDITMODE;
- }
- else {
- /* Draw Pose */
- if (ob->pose && ob->pose->chanbase.first) {
- /* We can't safely draw non-updated pose, might contain NULL bone pointers... */
- if (ob->pose->flag & POSE_RECALC) {
- BKE_pose_rebuild(ob, arm);
- }
-
- /* drawing posemode selection indices or colors only in these cases */
- if (!(base->flag & OB_FROMDUPLI)) {
- if (G.f & G_PICKSEL) {
-#if 0
- /* nifty but actually confusing to allow bone selection out of posemode */
- if (OBACT && (OBACT->mode & OB_MODE_WEIGHT_PAINT)) {
- if (ob == modifiers_isDeformedByArmature(OBACT))
- arm->flag |= ARM_POSEMODE;
- }
- else
-#endif
- if (ob->mode & OB_MODE_POSE) {
- arm->flag |= ARM_POSEMODE;
- }
- }
- else if (ob->mode & OB_MODE_POSE) {
- if (arm->ghosttype == ARM_GHOST_RANGE) {
- draw_ghost_poses_range(scene, v3d, ar, base);
- }
- else if (arm->ghosttype == ARM_GHOST_KEYS) {
- draw_ghost_poses_keys(scene, v3d, ar, base);
- }
- else if (arm->ghosttype == ARM_GHOST_CUR) {
- if (arm->ghostep)
- draw_ghost_poses(scene, v3d, ar, base);
- }
- if ((dflag & DRAW_SCENESET) == 0) {
- if (ob == OBACT)
- arm->flag |= ARM_POSEMODE;
- else if (OBACT && (OBACT->mode & OB_MODE_WEIGHT_PAINT)) {
- if (ob == modifiers_isDeformedByArmature(OBACT))
- arm->flag |= ARM_POSEMODE;
- }
- draw_pose_paths(scene, v3d, ar, ob);
- }
- }
- }
- draw_pose_bones(scene, v3d, ar, base, dt, ob_wire_col, (dflag & DRAW_CONSTCOLOR), is_outline);
- arm->flag &= ~ARM_POSEMODE;
-
- if (ob->mode & OB_MODE_POSE)
- UI_ThemeColor(TH_WIRE); /* restore, for extra draw stuff */
- }
- else {
- retval = true;
- }
- }
- /* restore */
- glFrontFace(GL_CCW);
-
- if (arm->drawtype == ARM_LINE) {
- glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
- }
-
- return retval;
-}
diff --git a/source/blender/editors/space_view3d/drawmesh.c b/source/blender/editors/space_view3d/drawmesh.c
deleted file mode 100644
index b6bcc592cc8..00000000000
--- a/source/blender/editors/space_view3d/drawmesh.c
+++ /dev/null
@@ -1,1406 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): Blender Foundation, full update, glsl support
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_view3d/drawmesh.c
- * \ingroup spview3d
- */
-
-#include <string.h>
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_bitmap.h"
-#include "BLI_math.h"
-
-#include "DNA_material_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_node_types.h"
-#include "DNA_object_types.h"
-#include "DNA_property_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_view3d_types.h"
-
-#include "BKE_DerivedMesh.h"
-#include "BKE_global.h"
-#include "BKE_image.h"
-#include "BKE_material.h"
-#include "BKE_paint.h"
-#include "BKE_property.h"
-#include "BKE_editmesh.h"
-#include "BKE_scene.h"
-
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
-
-#include "UI_resources.h"
-
-#include "GPU_draw.h"
-#include "GPU_material.h"
-#include "GPU_basic_shader.h"
-#include "GPU_shader.h"
-
-#include "RE_engine.h"
-
-#include "ED_uvedit.h"
-
-#include "view3d_intern.h" /* own include */
-
-/* user data structures for derived mesh callbacks */
-typedef struct drawMeshFaceSelect_userData {
- Mesh *me;
- BLI_bitmap *edge_flags; /* pairs of edge options (visible, select) */
-} drawMeshFaceSelect_userData;
-
-typedef struct drawEMTFMapped_userData {
- BMEditMesh *em;
- bool has_mcol;
- int cd_poly_tex_offset;
- const MPoly *mpoly;
- const MTexPoly *mtexpoly;
-} drawEMTFMapped_userData;
-
-typedef struct drawTFace_userData {
- const Mesh *me;
- const MPoly *mpoly;
- const MTexPoly *mtexpoly;
-} drawTFace_userData;
-
-/**************************** Face Select Mode *******************************/
-
-/* mainly to be less confusing */
-BLI_INLINE int edge_vis_index(const int index) { return index * 2; }
-BLI_INLINE int edge_sel_index(const int index) { return index * 2 + 1; }
-
-static BLI_bitmap *get_tface_mesh_marked_edge_info(Mesh *me, bool draw_select_edges)
-{
- BLI_bitmap *bitmap_edge_flags = BLI_BITMAP_NEW(me->totedge * 2, __func__);
- MPoly *mp;
- MLoop *ml;
- int i, j;
- bool select_set;
-
- for (i = 0; i < me->totpoly; i++) {
- mp = &me->mpoly[i];
-
- if (!(mp->flag & ME_HIDE)) {
- select_set = (mp->flag & ME_FACE_SEL) != 0;
-
- ml = me->mloop + mp->loopstart;
- for (j = 0; j < mp->totloop; j++, ml++) {
- if ((draw_select_edges == false) &&
- (select_set && BLI_BITMAP_TEST(bitmap_edge_flags, edge_sel_index(ml->e))))
- {
- BLI_BITMAP_DISABLE(bitmap_edge_flags, edge_vis_index(ml->e));
- }
- else {
- BLI_BITMAP_ENABLE(bitmap_edge_flags, edge_vis_index(ml->e));
- if (select_set) {
- BLI_BITMAP_ENABLE(bitmap_edge_flags, edge_sel_index(ml->e));
- }
- }
- }
- }
- }
-
- return bitmap_edge_flags;
-}
-
-
-static DMDrawOption draw_mesh_face_select__setHiddenOpts(void *userData, int index)
-{
- drawMeshFaceSelect_userData *data = userData;
- Mesh *me = data->me;
-
- if (me->drawflag & ME_DRAWEDGES) {
- if ((BLI_BITMAP_TEST(data->edge_flags, edge_vis_index(index))))
- return DM_DRAW_OPTION_NORMAL;
- else
- return DM_DRAW_OPTION_SKIP;
- }
- else if (BLI_BITMAP_TEST(data->edge_flags, edge_sel_index(index)) &&
- BLI_BITMAP_TEST(data->edge_flags, edge_vis_index(index)))
- {
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
- }
-}
-
-static DMDrawOption draw_mesh_face_select__setSelectOpts(void *userData, int index)
-{
- drawMeshFaceSelect_userData *data = userData;
- return (BLI_BITMAP_TEST(data->edge_flags, edge_sel_index(index)) &&
- BLI_BITMAP_TEST(data->edge_flags, edge_vis_index(index))) ? DM_DRAW_OPTION_NORMAL : DM_DRAW_OPTION_SKIP;
-}
-
-/* draws unselected */
-static DMDrawOption draw_mesh_face_select__drawFaceOptsInv(void *userData, int index)
-{
- Mesh *me = (Mesh *)userData;
-
- MPoly *mpoly = &me->mpoly[index];
- if (!(mpoly->flag & ME_HIDE) && !(mpoly->flag & ME_FACE_SEL))
- return DM_DRAW_OPTION_NORMAL;
- else
- return DM_DRAW_OPTION_SKIP;
-}
-
-void draw_mesh_face_select(RegionView3D *rv3d, Mesh *me, DerivedMesh *dm, bool draw_select_edges)
-{
- drawMeshFaceSelect_userData data;
-
- data.me = me;
- data.edge_flags = get_tface_mesh_marked_edge_info(me, draw_select_edges);
-
- glEnable(GL_DEPTH_TEST);
- ED_view3d_polygon_offset(rv3d, 1.0);
-
- /* Draw (Hidden) Edges */
- setlinestyle(1);
- UI_ThemeColor(TH_EDGE_FACESEL);
- dm->drawMappedEdges(dm, draw_mesh_face_select__setHiddenOpts, &data);
- setlinestyle(0);
-
- /* Draw Selected Faces */
- if (me->drawflag & ME_DRAWFACES) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- /* dull unselected faces so as not to get in the way of seeing color */
- glColor4ub(96, 96, 96, 64);
- dm->drawMappedFaces(dm, draw_mesh_face_select__drawFaceOptsInv, NULL, NULL, (void *)me, DM_DRAW_SKIP_HIDDEN);
- glDisable(GL_BLEND);
- }
-
- ED_view3d_polygon_offset(rv3d, 1.0);
-
- /* Draw Stippled Outline for selected faces */
- glColor3ub(255, 255, 255);
- setlinestyle(1);
- dm->drawMappedEdges(dm, draw_mesh_face_select__setSelectOpts, &data);
- setlinestyle(0);
-
- ED_view3d_polygon_offset(rv3d, 0.0); /* resets correctly now, even after calling accumulated offsets */
-
- MEM_freeN(data.edge_flags);
-}
-
-/***************************** Texture Drawing ******************************/
-
-static Material *give_current_material_or_def(Object *ob, int matnr)
-{
- extern Material defmaterial; /* render module abuse... */
- Material *ma = give_current_material(ob, matnr);
-
- return ma ? ma : &defmaterial;
-}
-
-/* Icky globals, fix with userdata parameter */
-
-static struct TextureDrawState {
- Object *ob;
- Image *stencil; /* texture painting stencil */
- Image *canvas; /* texture painting canvas, for image mode */
- bool use_game_mat;
- int is_lit, is_tex;
- int color_profile;
- bool use_backface_culling;
- bool two_sided_lighting;
- unsigned char obcol[4];
- bool is_texpaint;
- bool texpaint_material; /* use material slots for texture painting */
-} Gtexdraw = {NULL, NULL, NULL, false, 0, 0, 0, false, false, {0, 0, 0, 0}, false, false};
-
-static bool set_draw_settings_cached(
- int clearcache, MTexPoly *texface, Material *ma,
- const struct TextureDrawState *gtexdraw)
-{
- static Material *c_ma;
- static int c_textured;
- static MTexPoly c_texface;
- static int c_backculled;
- static bool c_badtex;
- static int c_lit;
- static int c_has_texface;
-
- int backculled = 1;
- int alphablend = GPU_BLEND_SOLID;
- int textured = 0;
- int lit = 0;
- int has_texface = texface != NULL;
- bool need_set_tpage = false;
- bool texpaint = ((gtexdraw->ob->mode & OB_MODE_TEXTURE_PAINT) != 0);
-
- Image *ima = NULL;
-
- if (ma != NULL) {
- if (ma->mode & MA_TRANSP) {
- alphablend = GPU_BLEND_ALPHA;
- }
- }
-
- if (clearcache) {
- c_textured = c_lit = c_backculled = -1;
- memset(&c_texface, 0, sizeof(c_texface));
- c_badtex = false;
- c_has_texface = -1;
- c_ma = NULL;
- }
- else {
- textured = gtexdraw->is_tex;
- }
-
- /* convert number of lights into boolean */
- if (gtexdraw->is_lit) {
- lit = 1;
- }
-
- backculled = gtexdraw->use_backface_culling;
- if (ma) {
- if (ma->mode & MA_SHLESS) lit = 0;
- if (gtexdraw->use_game_mat) {
- backculled = backculled || (ma->game.flag & GEMAT_BACKCULL);
- alphablend = ma->game.alpha_blend;
- }
- }
-
- if (texface && !texpaint) {
- textured = textured && (texface->tpage);
-
- /* no material, render alpha if texture has depth=32 */
- if (!ma && BKE_image_has_alpha(texface->tpage))
- alphablend = GPU_BLEND_ALPHA;
- }
- else if (texpaint) {
- if (gtexdraw->texpaint_material)
- ima = ma && ma->texpaintslot ? ma->texpaintslot[ma->paint_active_slot].ima : NULL;
- else
- ima = gtexdraw->canvas;
- }
- else
- textured = 0;
-
- if (backculled != c_backculled) {
- if (backculled) glEnable(GL_CULL_FACE);
- else glDisable(GL_CULL_FACE);
-
- c_backculled = backculled;
- }
-
- /* need to re-set tpage if textured flag changed or existsment of texface changed.. */
- need_set_tpage = textured != c_textured || has_texface != c_has_texface;
- /* ..or if settings inside texface were changed (if texface was used) */
- need_set_tpage |= (texpaint && c_ma != ma) || (texface && memcmp(&c_texface, texface, sizeof(c_texface)));
-
- if (need_set_tpage) {
- if (textured) {
- if (texpaint) {
- c_badtex = false;
- if (GPU_verify_image(ima, NULL, GL_TEXTURE_2D, 0, 1, 0, false)) {
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_MODULATE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_TEXTURE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_TEXTURE);
-
- glActiveTexture(GL_TEXTURE1);
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS);
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
- glActiveTexture(GL_TEXTURE0);
- }
- else {
- glActiveTexture(GL_TEXTURE1);
- glDisable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glActiveTexture(GL_TEXTURE0);
-
- c_badtex = true;
- GPU_clear_tpage(true);
- glDisable(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- }
- }
- else {
- c_badtex = !GPU_set_tpage(texface, !texpaint, alphablend);
- }
- }
- else {
- GPU_set_tpage(NULL, 0, 0);
- c_badtex = false;
- }
- c_textured = textured;
- c_has_texface = has_texface;
- if (texface)
- memcpy(&c_texface, texface, sizeof(c_texface));
- }
-
- if (c_badtex) lit = 0;
- if (lit != c_lit || ma != c_ma || textured != c_textured) {
- int options = GPU_SHADER_USE_COLOR;
-
- if (c_textured && !c_badtex) {
- options |= GPU_SHADER_TEXTURE_2D;
- }
- if (gtexdraw->two_sided_lighting) {
- options |= GPU_SHADER_TWO_SIDED;
- }
-
- if (lit) {
- options |= GPU_SHADER_LIGHTING;
- if (!ma)
- ma = give_current_material_or_def(NULL, 0); /* default material */
-
- float specular[3];
- mul_v3_v3fl(specular, &ma->specr, ma->spec);
-
- GPU_basic_shader_colors(NULL, specular, ma->har, 1.0f);
- }
-
- GPU_basic_shader_bind(options);
-
- c_lit = lit;
- c_ma = ma;
- }
-
- return c_badtex;
-}
-
-static void draw_textured_begin(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
-{
- unsigned char obcol[4];
- bool is_tex, solidtex;
- Mesh *me = ob->data;
- ImagePaintSettings *imapaint = &scene->toolsettings->imapaint;
-
- /* XXX scene->obedit warning */
-
- /* texture draw is abused for mask selection mode, do this so wire draw
- * with face selection in weight paint is not lit. */
- if ((v3d->drawtype <= OB_WIRE) && (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT))) {
- solidtex = false;
- Gtexdraw.is_lit = 0;
- }
- else if ((ob->mode & OB_MODE_TEXTURE_PAINT) && BKE_scene_use_new_shading_nodes(scene)) {
- solidtex = true;
- if (v3d->flag2 & V3D_SHADELESS_TEX)
- Gtexdraw.is_lit = 0;
- else
- Gtexdraw.is_lit = -1;
- }
- else if ((v3d->drawtype == OB_SOLID) ||
- ((ob->mode & OB_MODE_EDIT) && (v3d->drawtype != OB_TEXTURE)))
- {
- /* draw with default lights in solid draw mode and edit mode */
- solidtex = true;
- Gtexdraw.is_lit = -1;
- }
- else {
- /* draw with lights in the scene otherwise */
- solidtex = false;
- if (v3d->flag2 & V3D_SHADELESS_TEX) {
- Gtexdraw.is_lit = 0;
- }
- else {
- Gtexdraw.is_lit = GPU_scene_object_lights(
- scene, ob, v3d->localvd ? v3d->localvd->lay : v3d->lay,
- rv3d->viewmat, !rv3d->is_persp);
- }
- }
-
- rgba_float_to_uchar(obcol, ob->col);
-
- if (solidtex || v3d->drawtype == OB_TEXTURE) is_tex = true;
- else is_tex = false;
-
- Gtexdraw.ob = ob;
- Gtexdraw.stencil = (imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL) ? imapaint->stencil : NULL;
- Gtexdraw.is_texpaint = (ob->mode == OB_MODE_TEXTURE_PAINT);
- Gtexdraw.texpaint_material = (imapaint->mode == IMAGEPAINT_MODE_MATERIAL);
- Gtexdraw.canvas = (Gtexdraw.texpaint_material) ? NULL : imapaint->canvas;
- Gtexdraw.is_tex = is_tex;
-
- /* naughty multitexturing hacks to quickly support stencil + shading + alpha blending
- * in new texpaint code. The better solution here would be to support GLSL */
- if (Gtexdraw.is_texpaint) {
- glActiveTexture(GL_TEXTURE1);
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_PRIMARY_COLOR);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_PREVIOUS);
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_ALPHA);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_REPLACE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
-
- /* load the stencil texture here */
- if (Gtexdraw.stencil != NULL) {
- glActiveTexture(GL_TEXTURE2);
- if (GPU_verify_image(Gtexdraw.stencil, NULL, GL_TEXTURE_2D, false, false, false, false)) {
- float col[4] = {imapaint->stencil_col[0], imapaint->stencil_col[1], imapaint->stencil_col[2], 1.0f};
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_RGB, GL_INTERPOLATE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_RGB, GL_PREVIOUS);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_RGB, GL_CONSTANT);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC2_RGB, GL_TEXTURE);
- glTexEnvi(GL_TEXTURE_ENV, GL_COMBINE_ALPHA, GL_MODULATE);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC0_ALPHA, GL_PREVIOUS);
- glTexEnvi(GL_TEXTURE_ENV, GL_SRC1_ALPHA, GL_TEXTURE);
- glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, col);
- if ((imapaint->flag & IMAGEPAINT_PROJECT_LAYER_STENCIL_INV) == 0) {
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_ONE_MINUS_SRC_COLOR);
- }
- else {
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
- }
- }
- }
- glActiveTexture(GL_TEXTURE0);
- }
-
- Gtexdraw.color_profile = BKE_scene_check_color_management_enabled(scene);
- Gtexdraw.use_game_mat = (RE_engines_find(scene->r.engine)->flag & RE_GAME) != 0;
- Gtexdraw.use_backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0;
- Gtexdraw.two_sided_lighting = (me->flag & ME_TWOSIDED);
-
- memcpy(Gtexdraw.obcol, obcol, sizeof(obcol));
- set_draw_settings_cached(1, NULL, NULL, &Gtexdraw);
- glCullFace(GL_BACK);
-}
-
-static void draw_textured_end(void)
-{
- if (Gtexdraw.ob->mode & OB_MODE_TEXTURE_PAINT) {
- glActiveTexture(GL_TEXTURE1);
- glDisable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBindTexture(GL_TEXTURE_2D, 0);
-
- if (Gtexdraw.stencil != NULL) {
- glActiveTexture(GL_TEXTURE2);
- glDisable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_OPERAND2_RGB, GL_SRC_COLOR);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- glBindTexture(GL_TEXTURE_2D, 0);
- }
- glActiveTexture(GL_TEXTURE0);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- /* manual reset, since we don't use tpage */
- glBindTexture(GL_TEXTURE_2D, 0);
- /* force switch off textures */
- GPU_clear_tpage(true);
- }
- else {
- /* switch off textures */
- GPU_set_tpage(NULL, 0, 0);
- }
-
- glDisable(GL_CULL_FACE);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
- /* XXX, bad patch - GPU_default_lights() calls
- * glLightfv(GL_POSITION, ...) which
- * is transformed by the current matrix... we
- * need to make sure that matrix is identity.
- *
- * It would be better if drawmesh.c kept track
- * of and restored the light settings it changed.
- * - zr
- */
- glPushMatrix();
- glLoadIdentity();
- GPU_default_lights();
- glPopMatrix();
-}
-
-static DMDrawOption draw_tface__set_draw_legacy(MTexPoly *mtexpoly, const bool has_mcol, int matnr)
-{
- Material *ma = give_current_material(Gtexdraw.ob, matnr + 1);
- bool invalidtexture = false;
-
- if (ma && (ma->game.flag & GEMAT_INVISIBLE))
- return DM_DRAW_OPTION_SKIP;
-
- invalidtexture = set_draw_settings_cached(0, mtexpoly, ma, &Gtexdraw);
-
- if (mtexpoly && invalidtexture) {
- glColor3ub(0xFF, 0x00, 0xFF);
- return DM_DRAW_OPTION_NO_MCOL; /* Don't set color */
- }
- else if (!has_mcol) {
- if (mtexpoly) {
- glColor3f(1.0, 1.0, 1.0);
- }
- else {
- if (ma) {
- if (ma->shade_flag & MA_OBCOLOR) {
- glColor3ubv(Gtexdraw.obcol);
- }
- else {
- float col[3];
- if (Gtexdraw.color_profile) linearrgb_to_srgb_v3_v3(col, &ma->r);
- else copy_v3_v3(col, &ma->r);
-
- glColor3fv(col);
- }
- }
- else {
- glColor3f(1.0, 1.0, 1.0);
- }
- }
- return DM_DRAW_OPTION_NORMAL; /* normal drawing (no mcols anyway, no need to turn off) */
- }
- else {
- return DM_DRAW_OPTION_NORMAL; /* Set color from mcol */
- }
-}
-
-static DMDrawOption draw_tface__set_draw(MTexPoly *mtexpoly, const bool UNUSED(has_mcol), int matnr)
-{
- Material *ma = give_current_material(Gtexdraw.ob, matnr + 1);
-
- if (ma && (ma->game.flag & GEMAT_INVISIBLE)) return DM_DRAW_OPTION_SKIP;
-
- if (mtexpoly || Gtexdraw.is_texpaint)
- set_draw_settings_cached(0, mtexpoly, ma, &Gtexdraw);
-
- /* always use color from mcol, as set in update_tface_color_layer */
- return DM_DRAW_OPTION_NORMAL;
-}
-
-static void update_tface_color_layer(DerivedMesh *dm, bool use_mcol)
-{
- const MPoly *mp = dm->getPolyArray(dm);
- const int mpoly_num = dm->getNumPolys(dm);
- MTexPoly *mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY);
- MLoopCol *finalCol;
- int i, j;
- MLoopCol *mloopcol = NULL;
-
- /* cache material values to avoid a lot of lookups */
- Material *ma = NULL;
- short mat_nr_prev = -1;
- enum {
- COPY_CALC,
- COPY_ORIG,
- COPY_PREV,
- } copy_mode = COPY_CALC;
-
- if (use_mcol) {
- mloopcol = dm->getLoopDataArray(dm, CD_PREVIEW_MLOOPCOL);
- if (!mloopcol)
- mloopcol = dm->getLoopDataArray(dm, CD_MLOOPCOL);
- }
-
- if (CustomData_has_layer(&dm->loopData, CD_TEXTURE_MLOOPCOL)) {
- finalCol = CustomData_get_layer(&dm->loopData, CD_TEXTURE_MLOOPCOL);
- }
- else {
- finalCol = MEM_mallocN(sizeof(MLoopCol) * dm->numLoopData, "add_tface_color_layer");
- CustomData_add_layer(&dm->loopData, CD_TEXTURE_MLOOPCOL, CD_ASSIGN, finalCol, dm->numLoopData);
- }
-
- for (i = mpoly_num; i--; mp++) {
- const short mat_nr = mp->mat_nr;
-
- if (UNLIKELY(mat_nr_prev != mat_nr)) {
- ma = give_current_material(Gtexdraw.ob, mat_nr + 1);
- copy_mode = COPY_CALC;
- mat_nr_prev = mat_nr;
- }
-
- /* avoid lookups */
- if (copy_mode == COPY_ORIG) {
- memcpy(&finalCol[mp->loopstart], &mloopcol[mp->loopstart], sizeof(*finalCol) * mp->totloop);
- }
- else if (copy_mode == COPY_PREV) {
- int loop_index = mp->loopstart;
- const MLoopCol *lcol_prev = &finalCol[(mp - 1)->loopstart];
- for (j = 0; j < mp->totloop; j++, loop_index++) {
- finalCol[loop_index] = *lcol_prev;
- }
- }
-
- /* (copy_mode == COPY_CALC) */
- else if (ma && (ma->game.flag & GEMAT_INVISIBLE)) {
- if (mloopcol) {
- memcpy(&finalCol[mp->loopstart], &mloopcol[mp->loopstart], sizeof(*finalCol) * mp->totloop);
- copy_mode = COPY_ORIG;
- }
- else {
- memset(&finalCol[mp->loopstart], 0xff, sizeof(*finalCol) * mp->totloop);
- copy_mode = COPY_PREV;
- }
- }
- else if (mtexpoly && set_draw_settings_cached(0, mtexpoly, ma, &Gtexdraw)) {
- int loop_index = mp->loopstart;
- for (j = 0; j < mp->totloop; j++, loop_index++) {
- finalCol[loop_index].r = 255;
- finalCol[loop_index].g = 0;
- finalCol[loop_index].b = 255;
- finalCol[loop_index].a = 255;
- }
- copy_mode = COPY_PREV;
- }
- else if (ma && (ma->shade_flag & MA_OBCOLOR)) {
- int loop_index = mp->loopstart;
- for (j = 0; j < mp->totloop; j++, loop_index++) {
- copy_v3_v3_uchar(&finalCol[loop_index].r, Gtexdraw.obcol);
- finalCol[loop_index].a = 255;
- }
- copy_mode = COPY_PREV;
- }
- else {
- if (mloopcol) {
- memcpy(&finalCol[mp->loopstart], &mloopcol[mp->loopstart], sizeof(*finalCol) * mp->totloop);
- copy_mode = COPY_ORIG;
- }
- else if (mtexpoly) {
- memset(&finalCol[mp->loopstart], 0xff, sizeof(*finalCol) * mp->totloop);
- copy_mode = COPY_PREV;
- }
- else {
- float col[3];
-
- if (ma) {
- int loop_index = mp->loopstart;
- MLoopCol lcol;
-
- if (Gtexdraw.color_profile) linearrgb_to_srgb_v3_v3(col, &ma->r);
- else copy_v3_v3(col, &ma->r);
- rgb_float_to_uchar((unsigned char *)&lcol.r, col);
- lcol.a = 255;
-
- for (j = 0; j < mp->totloop; j++, loop_index++) {
- finalCol[loop_index] = lcol;
- }
- }
- else {
- memset(&finalCol[mp->loopstart], 0xff, sizeof(*finalCol) * mp->totloop);
- }
- copy_mode = COPY_PREV;
- }
- }
- }
-
- dm->dirty |= DM_DIRTY_MCOL_UPDATE_DRAW;
-}
-
-static DMDrawOption draw_tface_mapped__set_draw(void *userData, int origindex, int UNUSED(mat_nr))
-{
- const Mesh *me = ((drawTFace_userData *)userData)->me;
-
- /* array checked for NULL before calling */
- MPoly *mpoly = &me->mpoly[origindex];
-
- BLI_assert(origindex >= 0 && origindex < me->totpoly);
-
- if (mpoly->flag & ME_HIDE) {
- return DM_DRAW_OPTION_SKIP;
- }
- else {
- MTexPoly *tpoly = (me->mtpoly) ? &me->mtpoly[origindex] : NULL;
- int matnr = mpoly->mat_nr;
-
- return draw_tface__set_draw(tpoly, (me->mloopcol != NULL), matnr);
- }
-}
-
-static DMDrawOption draw_em_tf_mapped__set_draw(void *userData, int origindex, int mat_nr)
-{
- drawEMTFMapped_userData *data = userData;
- BMEditMesh *em = data->em;
- BMFace *efa;
-
- if (UNLIKELY(origindex >= em->bm->totface))
- return DM_DRAW_OPTION_NORMAL;
-
- efa = BM_face_at_index(em->bm, origindex);
-
- if (BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- return DM_DRAW_OPTION_SKIP;
- }
- else {
- MTexPoly *mtexpoly = (data->cd_poly_tex_offset != -1) ?
- BM_ELEM_CD_GET_VOID_P(efa, data->cd_poly_tex_offset) : NULL;
- int matnr = (mat_nr != -1) ? mat_nr : efa->mat_nr;
-
- return draw_tface__set_draw_legacy(mtexpoly, data->has_mcol, matnr);
- }
-}
-
-/* when face select is on, use face hidden flag */
-static DMDrawOption wpaint__setSolidDrawOptions_facemask(void *userData, int index)
-{
- Mesh *me = (Mesh *)userData;
- MPoly *mp = &me->mpoly[index];
- if (mp->flag & ME_HIDE)
- return DM_DRAW_OPTION_SKIP;
- return DM_DRAW_OPTION_NORMAL;
-}
-
-static void draw_mesh_text(Scene *scene, Object *ob, int glsl)
-{
- Mesh *me = ob->data;
- DerivedMesh *ddm;
- MPoly *mp, *mface = me->mpoly;
- MTexPoly *mtpoly = me->mtpoly;
- MLoopUV *mloopuv = me->mloopuv;
- MLoopUV *luv;
- MLoopCol *mloopcol = me->mloopcol; /* why does mcol exist? */
- MLoopCol *lcol;
-
- bProperty *prop = BKE_bproperty_object_get(ob, "Text");
- GPUVertexAttribs gattribs;
- int a, totpoly = me->totpoly;
-
- /* fake values to pass to GPU_render_text() */
- MCol tmp_mcol[4] = {{0}};
- MCol *tmp_mcol_pt = mloopcol ? tmp_mcol : NULL;
-
- /* don't draw without tfaces */
- if (!mtpoly || !mloopuv)
- return;
-
- /* don't draw when editing */
- if (ob->mode & OB_MODE_EDIT)
- return;
- else if (ob == OBACT)
- if (BKE_paint_select_elem_test(ob))
- return;
-
- ddm = mesh_get_derived_deform(scene, ob, CD_MASK_BAREMESH);
-
- for (a = 0, mp = mface; a < totpoly; a++, mtpoly++, mp++) {
- short matnr = mp->mat_nr;
- const bool mf_smooth = (mp->flag & ME_SMOOTH) != 0;
- Material *mat = (me->mat) ? me->mat[matnr] : NULL;
- int mode = mat ? mat->game.flag : GEMAT_INVISIBLE;
-
-
- if (!(mode & GEMAT_INVISIBLE) && (mode & GEMAT_TEXT) && mp->totloop >= 3) {
- /* get the polygon as a tri/quad */
- int mp_vi[4];
- float v_quad_data[4][3];
- const float *v_quad[4];
- const float *uv_quad[4];
- char string[MAX_PROPSTRING];
- int characters, i, glattrib = -1, badtex = 0;
-
-
- /* TEXFACE */
- if (glsl) {
- GPU_object_material_bind(matnr + 1, &gattribs);
-
- for (i = 0; i < gattribs.totlayer; i++) {
- if (gattribs.layer[i].type == CD_MTFACE) {
- glattrib = gattribs.layer[i].glindex;
- break;
- }
- }
- }
- else {
- badtex = set_draw_settings_cached(0, mtpoly, mat, &Gtexdraw);
- if (badtex) {
- continue;
- }
- }
-
- mp_vi[0] = me->mloop[mp->loopstart + 0].v;
- mp_vi[1] = me->mloop[mp->loopstart + 1].v;
- mp_vi[2] = me->mloop[mp->loopstart + 2].v;
- mp_vi[3] = (mp->totloop >= 4) ? me->mloop[mp->loopstart + 3].v : 0;
-
- /* UV */
- luv = &mloopuv[mp->loopstart];
- uv_quad[0] = luv->uv; luv++;
- uv_quad[1] = luv->uv; luv++;
- uv_quad[2] = luv->uv; luv++;
- if (mp->totloop >= 4) {
- uv_quad[3] = luv->uv;
- }
- else {
- uv_quad[3] = NULL;
- }
-
-
- /* COLOR */
- if (mloopcol) {
- unsigned int totloop_clamp = min_ii(4, mp->totloop);
- unsigned int j;
- lcol = &mloopcol[mp->loopstart];
-
- for (j = 0; j < totloop_clamp; j++, lcol++) {
- MESH_MLOOPCOL_TO_MCOL(lcol, &tmp_mcol[j]);
- }
- }
-
- /* LOCATION */
- ddm->getVertCo(ddm, mp_vi[0], v_quad_data[0]);
- ddm->getVertCo(ddm, mp_vi[1], v_quad_data[1]);
- ddm->getVertCo(ddm, mp_vi[2], v_quad_data[2]);
- if (mp->totloop >= 4) {
- ddm->getVertCo(ddm, mp_vi[3], v_quad_data[3]);
- }
-
- v_quad[0] = v_quad_data[0];
- v_quad[1] = v_quad_data[1];
- v_quad[2] = v_quad_data[2];
- if (mp->totloop >= 4) {
- v_quad[3] = v_quad_data[2];
- }
- else {
- v_quad[3] = NULL;
- }
-
-
- /* The BM_FONT handling is in the gpu module, shared with the
- * game engine, was duplicated previously */
-
- BKE_bproperty_set_valstr(prop, string);
- characters = strlen(string);
-
- if (!BKE_image_has_ibuf(mtpoly->tpage, NULL))
- characters = 0;
-
- if (!mf_smooth) {
- float nor[3];
-
- normal_tri_v3(nor, v_quad[0], v_quad[1], v_quad[2]);
-
- glNormal3fv(nor);
- }
-
- GPU_render_text(
- mtpoly, mode, string, characters,
- (unsigned int *)tmp_mcol_pt,
- v_quad, uv_quad,
- glattrib);
- }
- }
-
- ddm->release(ddm);
-}
-
-static int compareDrawOptions(void *userData, int cur_index, int next_index)
-{
- drawTFace_userData *data = userData;
-
- if (data->mpoly && data->mpoly[cur_index].mat_nr != data->mpoly[next_index].mat_nr)
- return 0;
-
- if (data->mtexpoly && data->mtexpoly[cur_index].tpage != data->mtexpoly[next_index].tpage)
- return 0;
-
- return 1;
-}
-
-
-static int compareDrawOptionsEm(void *userData, int cur_index, int next_index)
-{
- drawEMTFMapped_userData *data = userData;
-
- if (data->mpoly && data->mpoly[cur_index].mat_nr != data->mpoly[next_index].mat_nr)
- return 0;
-
- if (data->mtexpoly && data->mtexpoly[cur_index].tpage != data->mtexpoly[next_index].tpage)
- return 0;
-
- return 1;
-}
-
-static void draw_mesh_textured_old(Scene *scene, View3D *v3d, RegionView3D *rv3d,
- Object *ob, DerivedMesh *dm, const int draw_flags)
-{
- Mesh *me = ob->data;
-
- /* correct for negative scale */
- if (ob->transflag & OB_NEG_SCALE) glFrontFace(GL_CW);
- else glFrontFace(GL_CCW);
-
- /* draw the textured mesh */
- draw_textured_begin(scene, v3d, rv3d, ob);
-
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
-
- if (ob->mode & OB_MODE_EDIT) {
- drawEMTFMapped_userData data;
-
- data.em = me->edit_btmesh;
- data.has_mcol = CustomData_has_layer(&me->edit_btmesh->bm->ldata, CD_MLOOPCOL);
- data.cd_poly_tex_offset = CustomData_get_offset(&me->edit_btmesh->bm->pdata, CD_MTEXPOLY);
-
- data.mpoly = DM_get_poly_data_layer(dm, CD_MPOLY);
- data.mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY);
-
- dm->drawMappedFacesTex(dm, draw_em_tf_mapped__set_draw, compareDrawOptionsEm, &data, 0);
- }
- else {
- DMDrawFlag dm_draw_flag;
- drawTFace_userData userData;
-
- if (ob->mode & OB_MODE_TEXTURE_PAINT) {
- dm_draw_flag = DM_DRAW_USE_TEXPAINT_UV;
- }
- else {
- dm_draw_flag = DM_DRAW_USE_ACTIVE_UV;
- }
-
- if (ob == OBACT) {
- if (ob->mode & OB_MODE_WEIGHT_PAINT) {
- dm_draw_flag |= DM_DRAW_USE_COLORS | DM_DRAW_ALWAYS_SMOOTH | DM_DRAW_SKIP_HIDDEN;
- }
- else if (ob->mode & OB_MODE_SCULPT) {
- dm_draw_flag |= DM_DRAW_SKIP_HIDDEN | DM_DRAW_USE_COLORS;
- }
- else if ((ob->mode & OB_MODE_TEXTURE_PAINT) == 0) {
- dm_draw_flag |= DM_DRAW_USE_COLORS;
- }
- }
- else {
- if ((ob->mode & OB_MODE_TEXTURE_PAINT) == 0) {
- dm_draw_flag |= DM_DRAW_USE_COLORS;
- }
- }
-
-
- userData.mpoly = DM_get_poly_data_layer(dm, CD_MPOLY);
- userData.mtexpoly = DM_get_poly_data_layer(dm, CD_MTEXPOLY);
-
- if (draw_flags & DRAW_FACE_SELECT) {
- userData.me = me;
-
- dm->drawMappedFacesTex(
- dm, me->mpoly ? draw_tface_mapped__set_draw : NULL, compareDrawOptions,
- &userData, dm_draw_flag);
- }
- else {
- userData.me = NULL;
-
- /* if ((ob->mode & OB_MODE_ALL_PAINT) == 0) */ {
-
- /* Note: this isn't efficient and runs on every redraw,
- * its needed so material colors are used for vertex colors.
- * In the future we will likely remove 'texface' so, just avoid running this where possible,
- * (when vertex paint or weight paint are used).
- *
- * Note 2: We disable optimization for now since it causes T48788
- * and it is now too close to release to do something smarter.
- *
- * TODO(sergey): Find some real solution here.
- */
-
- update_tface_color_layer(dm, !(ob->mode & OB_MODE_TEXTURE_PAINT));
- }
-
- dm->drawFacesTex(
- dm, draw_tface__set_draw, compareDrawOptions,
- &userData, dm_draw_flag);
- }
- }
-
- /* draw game engine text hack */
- if (rv3d->rflag & RV3D_IS_GAME_ENGINE) {
- if (BKE_bproperty_object_get(ob, "Text")) {
- draw_mesh_text(scene, ob, 0);
- }
- }
-
- draw_textured_end();
-
- /* draw edges and selected faces over textured mesh */
- if (!(ob == scene->obedit) && (draw_flags & DRAW_FACE_SELECT)) {
- bool draw_select_edges = (ob->mode & OB_MODE_TEXTURE_PAINT) == 0;
- draw_mesh_face_select(rv3d, me, dm, draw_select_edges);
- }
-
- /* reset from negative scale correction */
- glFrontFace(GL_CCW);
-
- /* in editmode, the blend mode needs to be set in case it was ADD */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-}
-
-/************************** NEW SHADING NODES ********************************/
-
-typedef struct TexMatCallback {
- Scene *scene;
- Object *ob;
- Mesh *me;
- DerivedMesh *dm;
- bool shadeless;
- bool two_sided_lighting;
-} TexMatCallback;
-
-static void tex_mat_set_material_cb(void *UNUSED(userData), int mat_nr, void *attribs)
-{
- /* all we have to do here is simply enable the GLSL material, but note
- * that the GLSL code will give different result depending on the drawtype,
- * in texture draw mode it will output the active texture node, in material
- * draw mode it will show the full material. */
- GPU_object_material_bind(mat_nr, attribs);
-}
-
-static void tex_mat_set_texture_cb(void *userData, int mat_nr, void *attribs)
-{
- /* texture draw mode without GLSL */
- TexMatCallback *data = (TexMatCallback *)userData;
- GPUVertexAttribs *gattribs = attribs;
- Image *ima;
- ImageUser *iuser;
- bNode *node;
-
- /* draw image texture if we find one */
- if (ED_object_get_active_image(data->ob, mat_nr, &ima, &iuser, &node, NULL)) {
- /* get openl texture */
- int mipmap = 1;
- int bindcode = (ima) ? GPU_verify_image(ima, iuser, GL_TEXTURE_2D, 0, 0, mipmap, false) : 0;
-
- if (bindcode) {
- NodeTexBase *texbase = node->storage;
-
- /* disable existing material */
- GPU_object_material_unbind();
-
- /* bind texture */
- glBindTexture(GL_TEXTURE_2D, ima->bindcode[TEXTARGET_TEXTURE_2D]);
-
- glMatrixMode(GL_TEXTURE);
- glLoadMatrixf(texbase->tex_mapping.mat);
- glMatrixMode(GL_MODELVIEW);
-
- /* use active UV texture layer */
- memset(gattribs, 0, sizeof(*gattribs));
-
- gattribs->layer[0].type = CD_MTFACE;
- gattribs->layer[0].name[0] = '\0';
- gattribs->layer[0].gltexco = 1;
- gattribs->layer[0].glinfoindoex = -1;
- gattribs->totlayer = 1;
-
- /* bind material */
- float diffuse[3] = {1.0f, 1.0f, 1.0f};
-
- int options = GPU_SHADER_TEXTURE_2D;
- if (!data->shadeless)
- options |= GPU_SHADER_LIGHTING;
- if (data->two_sided_lighting)
- options |= GPU_SHADER_TWO_SIDED;
-
- GPU_basic_shader_colors(diffuse, NULL, 0, 1.0f);
- GPU_basic_shader_bind(options);
-
- return;
- }
- }
-
- /* disable texture material */
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
- if (data->shadeless) {
- glColor3f(1.0f, 1.0f, 1.0f);
- memset(gattribs, 0, sizeof(*gattribs));
- }
- else {
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
-
- /* enable solid material */
- GPU_object_material_bind(mat_nr, attribs);
- }
-}
-
-static bool tex_mat_set_face_mesh_cb(void *userData, int index)
-{
- /* faceselect mode face hiding */
- TexMatCallback *data = (TexMatCallback *)userData;
- Mesh *me = (Mesh *)data->me;
- MPoly *mp = &me->mpoly[index];
-
- return !(mp->flag & ME_HIDE);
-}
-
-static bool tex_mat_set_face_editmesh_cb(void *userData, int index)
-{
- /* editmode face hiding */
- TexMatCallback *data = (TexMatCallback *)userData;
- Mesh *me = (Mesh *)data->me;
- BMEditMesh *em = me->edit_btmesh;
- BMFace *efa;
-
- if (UNLIKELY(index >= em->bm->totface))
- return DM_DRAW_OPTION_NORMAL;
-
- efa = BM_face_at_index(em->bm, index);
-
- return !BM_elem_flag_test(efa, BM_ELEM_HIDDEN);
-}
-
-void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d,
- Object *ob, DerivedMesh *dm, const int draw_flags)
-{
- /* if not cycles, or preview-modifiers, or drawing matcaps */
- if ((draw_flags & DRAW_MODIFIERS_PREVIEW) ||
- (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) ||
- (BKE_scene_use_new_shading_nodes(scene) == false) ||
- ((ob->mode & OB_MODE_TEXTURE_PAINT) && ELEM(v3d->drawtype, OB_TEXTURE, OB_SOLID)))
- {
- draw_mesh_textured_old(scene, v3d, rv3d, ob, dm, draw_flags);
- return;
- }
- else if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
- draw_mesh_paint(v3d, rv3d, ob, dm, draw_flags);
- return;
- }
-
- /* set opengl state for negative scale & color */
- if (ob->transflag & OB_NEG_SCALE) glFrontFace(GL_CW);
- else glFrontFace(GL_CCW);
-
- Mesh *me = ob->data;
-
- bool shadeless = ((v3d->flag2 & V3D_SHADELESS_TEX) &&
- ((v3d->drawtype == OB_TEXTURE) || (ob->mode & OB_MODE_TEXTURE_PAINT)));
- bool two_sided_lighting = (me->flag & ME_TWOSIDED) != 0;
-
- TexMatCallback data = {scene, ob, me, dm, shadeless, two_sided_lighting};
- bool (*set_face_cb)(void *, int);
- bool picking = (G.f & G_PICKSEL) != 0;
-
- /* face hiding callback depending on mode */
- if (ob == scene->obedit)
- set_face_cb = tex_mat_set_face_editmesh_cb;
- else if (draw_flags & DRAW_FACE_SELECT)
- set_face_cb = tex_mat_set_face_mesh_cb;
- else
- set_face_cb = NULL;
-
- /* test if we can use glsl */
- const int drawtype = view3d_effective_drawtype(v3d);
- bool glsl = (drawtype == OB_MATERIAL) && !picking;
-
- GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
-
- if (glsl || picking) {
- /* draw glsl or solid */
- dm->drawMappedFacesMat(dm,
- tex_mat_set_material_cb,
- set_face_cb, &data);
- }
- else {
- /* draw textured */
- dm->drawMappedFacesMat(dm,
- tex_mat_set_texture_cb,
- set_face_cb, &data);
- }
-
- GPU_end_object_materials();
-
- /* reset opengl state */
- GPU_end_object_materials();
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
- glBindTexture(GL_TEXTURE_2D, 0);
-
- glFrontFace(GL_CCW);
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
-
- /* faceselect mode drawing over textured mesh */
- if (!(ob == scene->obedit) && (draw_flags & DRAW_FACE_SELECT)) {
- bool draw_select_edges = (ob->mode & OB_MODE_TEXTURE_PAINT) == 0;
- draw_mesh_face_select(rv3d, ob->data, dm, draw_select_edges);
- }
-}
-
-/* Vertex Paint and Weight Paint */
-static void draw_mesh_paint_light_begin(void)
-{
- /* get material diffuse color from vertex colors but set default spec */
- const float specular[3] = {0.47f, 0.47f, 0.47f};
- GPU_basic_shader_colors(NULL, specular, 35, 1.0f);
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
-}
-
-static void draw_mesh_paint_light_end(void)
-{
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-}
-
-void draw_mesh_paint_weight_faces(DerivedMesh *dm, const bool use_light,
- void *facemask_cb, void *user_data)
-{
- DMSetMaterial setMaterial = GPU_object_materials_check() ? GPU_object_material_bind : NULL;
- int flags = DM_DRAW_USE_COLORS;
-
- if (use_light) {
- draw_mesh_paint_light_begin();
- flags |= DM_DRAW_NEED_NORMALS;
- }
-
- dm->drawMappedFaces(dm, (DMSetDrawOptions)facemask_cb, setMaterial, NULL, user_data, flags);
-
- if (use_light) {
- draw_mesh_paint_light_end();
- }
-}
-
-void draw_mesh_paint_vcolor_faces(DerivedMesh *dm, const bool use_light,
- void *facemask_cb, void *user_data,
- const Mesh *me)
-{
- DMSetMaterial setMaterial = GPU_object_materials_check() ? GPU_object_material_bind : NULL;
- int flags = 0;
-
- if (use_light) {
- draw_mesh_paint_light_begin();
- flags |= DM_DRAW_NEED_NORMALS;
- }
-
- /* Don't show alpha in wire mode. */
- const bool show_alpha = use_light;
- if (show_alpha) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
-
- if (me->mloopcol) {
- dm->drawMappedFaces(dm, facemask_cb, setMaterial, NULL, user_data,
- DM_DRAW_USE_COLORS | flags);
- }
- else {
- glColor3f(1.0f, 1.0f, 1.0f);
- dm->drawMappedFaces(dm, facemask_cb, setMaterial, NULL, user_data, flags);
- }
-
- if (show_alpha) {
- glDisable(GL_BLEND);
- }
-
- if (use_light) {
- draw_mesh_paint_light_end();
- }
-}
-
-void draw_mesh_paint_weight_edges(RegionView3D *rv3d, DerivedMesh *dm,
- const bool use_depth, const bool use_alpha,
- void *edgemask_cb, void *user_data)
-{
- /* weight paint in solid mode, special case. focus on making the weights clear
- * rather than the shading, this is also forced in wire view */
-
- if (use_depth) {
- ED_view3d_polygon_offset(rv3d, 1.0);
- glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */
- }
- else {
- glDisable(GL_DEPTH_TEST);
- }
-
- if (use_alpha) {
- glEnable(GL_BLEND);
- }
-
- glColor4ub(255, 255, 255, 96);
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(1, 0xAAAA);
-
- dm->drawMappedEdges(dm, (DMSetDrawOptions)edgemask_cb, user_data);
-
- if (use_depth) {
- ED_view3d_polygon_offset(rv3d, 0.0);
- glDepthMask(1);
- }
- else {
- glEnable(GL_DEPTH_TEST);
- }
-
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
-
- if (use_alpha) {
- glDisable(GL_BLEND);
- }
-}
-
-void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d,
- Object *ob, DerivedMesh *dm, const int draw_flags)
-{
- DMSetDrawOptions facemask = NULL;
- Mesh *me = ob->data;
- const bool use_light = (v3d->drawtype >= OB_SOLID);
-
- /* hide faces in face select mode */
- if (me->editflag & (ME_EDIT_PAINT_VERT_SEL | ME_EDIT_PAINT_FACE_SEL))
- facemask = wpaint__setSolidDrawOptions_facemask;
-
- if (ob->mode & OB_MODE_WEIGHT_PAINT) {
- draw_mesh_paint_weight_faces(dm, use_light, facemask, me);
- }
- else if (ob->mode & OB_MODE_VERTEX_PAINT) {
- draw_mesh_paint_vcolor_faces(dm, use_light, facemask, me, me);
- }
-
- /* draw face selection on top */
- if (draw_flags & DRAW_FACE_SELECT) {
- bool draw_select_edges = (ob->mode & OB_MODE_TEXTURE_PAINT) == 0;
- draw_mesh_face_select(rv3d, me, dm, draw_select_edges);
- }
- else if ((use_light == false) || (ob->dtx & OB_DRAWWIRE)) {
- const bool use_depth = (v3d->flag & V3D_ZBUF_SELECT) || !(ob->mode & OB_MODE_WEIGHT_PAINT);
- const bool use_alpha = (ob->mode & OB_MODE_VERTEX_PAINT) == 0;
-
- if (use_alpha == false) {
- set_inverted_drawing(1);
- }
-
- draw_mesh_paint_weight_edges(rv3d, dm, use_depth, use_alpha, NULL, NULL);
-
- if (use_alpha == false) {
- set_inverted_drawing(0);
- }
- }
-}
-
diff --git a/source/blender/editors/space_view3d/drawobject.c b/source/blender/editors/space_view3d/drawobject.c
index c3823627009..8e04a2e17b8 100644
--- a/source/blender/editors/space_view3d/drawobject.c
+++ b/source/blender/editors/space_view3d/drawobject.c
@@ -54,6 +54,7 @@
#include "BKE_camera.h"
#include "BKE_colortools.h"
#include "BKE_constraint.h" /* for the get_constraint_target function */
+#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_DerivedMesh.h"
#include "BKE_deform.h"
@@ -62,6 +63,7 @@
#include "BKE_global.h"
#include "BKE_image.h"
#include "BKE_key.h"
+#include "BKE_layer.h"
#include "BKE_lattice.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
@@ -80,6 +82,9 @@
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
@@ -90,6 +95,10 @@
#include "GPU_select.h"
#include "GPU_basic_shader.h"
#include "GPU_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_batch.h"
+#include "GPU_matrix.h"
#include "ED_mesh.h"
#include "ED_particle.h"
@@ -105,127 +114,7 @@
#include "view3d_intern.h" /* bad level include */
-/* Workaround for sequencer scene render mode.
- *
- * Strips doesn't use DAG to update objects or so, which
- * might lead to situations when object is drawing without
- * curve cache ready.
- *
- * Ideally we don't want to evaluate objects from drawing,
- * but it'll require some major sequencer re-design. So
- * for now just fallback to legacy behavior with calling
- * display ist creating from draw().
- */
-#define SEQUENCER_DAG_WORKAROUND
-
-typedef enum eWireDrawMode {
- OBDRAW_WIRE_OFF = 0,
- OBDRAW_WIRE_ON = 1,
- OBDRAW_WIRE_ON_DEPTH = 2
-} eWireDrawMode;
-
-typedef struct drawDMVerts_userData {
- BMesh *bm;
-
- BMVert *eve_act;
- char sel;
-
- /* cached theme values */
- unsigned char th_editmesh_active[4];
- unsigned char th_vertex_select[4];
- unsigned char th_vertex[4];
- unsigned char th_skin_root[4];
-
- /* for skin node drawing */
- int cd_vskin_offset;
- float imat[4][4];
-} drawDMVerts_userData;
-
-typedef struct drawDMEdgesSel_userData {
- BMesh *bm;
-
- unsigned char *baseCol, *selCol, *actCol;
- BMEdge *eed_act;
-} drawDMEdgesSel_userData;
-
-typedef struct drawDMEdgesSelInterp_userData {
- BMesh *bm;
-
- unsigned char *baseCol, *selCol;
- unsigned char *lastCol;
-} drawDMEdgesSelInterp_userData;
-
-typedef struct drawDMEdgesWeightInterp_userData {
- BMesh *bm;
-
- int cd_dvert_offset;
- int defgroup_tot;
- int vgroup_index;
- char weight_user;
- float alert_color[3];
-
-} drawDMEdgesWeightInterp_userData;
-
-typedef struct drawDMFacesSel_userData {
-#ifdef WITH_FREESTYLE
- unsigned char *cols[4];
-#else
- unsigned char *cols[3];
-#endif
-
- DerivedMesh *dm;
- BMesh *bm;
-
- BMFace *efa_act;
- const int *orig_index_mp_to_orig;
-} drawDMFacesSel_userData;
-
-typedef struct drawDMNormal_userData {
- BMesh *bm;
- int uniform_scale;
- float normalsize;
- float tmat[3][3];
- float imat[3][3];
-} drawDMNormal_userData;
-
-typedef struct drawMVertOffset_userData {
- MVert *mvert;
- int offset;
-} drawMVertOffset_userData;
-
-typedef struct drawDMLayer_userData {
- BMesh *bm;
- int cd_layer_offset;
-} drawDMLayer_userData;
-
-typedef struct drawBMOffset_userData {
- BMesh *bm;
- int offset;
-} drawBMOffset_userData;
-
-typedef struct drawBMSelect_userData {
- BMesh *bm;
- bool select;
-} drawBMSelect_userData;
-
-static void draw_bounding_volume(Object *ob, char type);
-
-static void drawcube_size(float size);
-static void drawcircle_size(float size);
-static void draw_empty_sphere(float size);
-static void draw_empty_cone(float size);
-static void draw_box(const float vec[8][3], bool solid);
-
-static void ob_wire_color_blend_theme_id(const unsigned char ob_wire_col[4], const int theme_id, float fac)
-{
- float col_wire[3], col_bg[3], col[3];
-
- rgb_uchar_to_float(col_wire, ob_wire_col);
-
- UI_GetThemeColor3fv(theme_id, col_bg);
- interp_v3_v3v3(col, col_bg, col_wire, fac);
- glColor3fv(col);
-}
+#include "../../draw/intern/draw_cache_impl.h" /* bad level include (temporary) */
int view3d_effective_drawtype(const struct View3D *v3d)
{
@@ -235,42 +124,6 @@ int view3d_effective_drawtype(const struct View3D *v3d)
return v3d->drawtype;
}
-/* this condition has been made more complex since editmode can draw textures */
-bool check_object_draw_texture(Scene *scene, View3D *v3d, const char drawtype)
-{
- const int v3d_drawtype = view3d_effective_drawtype(v3d);
- /* texture and material draw modes */
- if (ELEM(v3d_drawtype, OB_TEXTURE, OB_MATERIAL) && drawtype > OB_SOLID) {
- return true;
- }
-
- /* textured solid */
- if ((v3d_drawtype == OB_SOLID) &&
- (v3d->flag2 & V3D_SOLID_TEX) &&
- (BKE_scene_use_new_shading_nodes(scene) == false))
- {
- return true;
- }
-
- if (v3d->flag2 & V3D_SHOW_SOLID_MATCAP) {
- return true;
- }
-
- return false;
-}
-
-static bool check_object_draw_editweight(Mesh *me, DerivedMesh *finalDM)
-{
- if (me->drawflag & ME_DRAWEIGHT) {
- /* editmesh handles its own weight drawing */
- if (finalDM->type != DM_TYPE_EDITBMESH) {
- return true;
- }
- }
-
- return false;
-}
-
static bool check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
{
if ((sce->toolsettings->selectmode & SCE_SELECT_FACE) == 0)
@@ -292,49 +145,6 @@ static bool check_ob_drawface_dot(Scene *sce, View3D *vd, char dt)
return true;
}
-/* ************************ */
-
-/* check for glsl drawing */
-
-bool draw_glsl_material(Scene *scene, Object *ob, View3D *v3d, const char dt)
-{
- if (G.f & G_PICKSEL)
- return false;
- if (!check_object_draw_texture(scene, v3d, dt))
- return false;
- if (ob == OBACT && (ob && ob->mode & OB_MODE_WEIGHT_PAINT))
- return false;
-
- if (v3d->flag2 & V3D_SHOW_SOLID_MATCAP)
- return true;
-
- if (v3d->drawtype == OB_TEXTURE)
- return (scene->gm.matmode == GAME_MAT_GLSL && !BKE_scene_use_new_shading_nodes(scene));
- else if (v3d->drawtype == OB_MATERIAL && dt > OB_SOLID)
- return true;
- else
- return false;
-}
-
-static bool check_alpha_pass(Base *base)
-{
- if (base->flag & OB_FROMDUPLI)
- return false;
-
- if (G.f & G_PICKSEL)
- return false;
-
- if (base->object->mode & OB_MODE_ALL_PAINT)
- return false;
-
- return (base->object->dtx & OB_DRAWTRANSP);
-}
-
-/***/
-static const unsigned int colortab[] = {
- 0x0, 0x403000, 0xFFFF88
-};
-
/* ----------------- OpenGL Circle Drawing - Tables for Optimized Drawing Speed ------------------ */
/* 32 values of sin function (still same result!) */
#define CIRCLE_RESOL 32
@@ -410,328 +220,6 @@ static const float cosval[CIRCLE_RESOL] = {
1.00000000
};
-/**
- * \param viewmat_local_unit is typically the 'rv3d->viewmatob'
- * copied into a 3x3 matrix and normalized.
- */
-static void draw_xyz_wire(const float viewmat_local_unit[3][3], const float c[3], float size, int axis)
-{
- int line_type;
- float buffer[4][3];
- int n = 0;
-
- float v1[3] = {0.0f, 0.0f, 0.0f}, v2[3] = {0.0f, 0.0f, 0.0f};
- float dim = size * 0.1f;
- float dx[3], dy[3];
-
- dx[0] = dim; dx[1] = 0.0f; dx[2] = 0.0f;
- dy[0] = 0.0f; dy[1] = dim; dy[2] = 0.0f;
-
- switch (axis) {
- case 0: /* x axis */
- line_type = GL_LINES;
-
- /* bottom left to top right */
- negate_v3_v3(v1, dx);
- sub_v3_v3(v1, dy);
- copy_v3_v3(v2, dx);
- add_v3_v3(v2, dy);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- /* top left to bottom right */
- mul_v3_fl(dy, 2.0f);
- add_v3_v3(v1, dy);
- sub_v3_v3(v2, dy);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- break;
- case 1: /* y axis */
- line_type = GL_LINES;
-
- /* bottom left to top right */
- mul_v3_fl(dx, 0.75f);
- negate_v3_v3(v1, dx);
- sub_v3_v3(v1, dy);
- copy_v3_v3(v2, dx);
- add_v3_v3(v2, dy);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- /* top left to center */
- mul_v3_fl(dy, 2.0f);
- add_v3_v3(v1, dy);
- zero_v3(v2);
-
- copy_v3_v3(buffer[n++], v1);
- copy_v3_v3(buffer[n++], v2);
-
- break;
- case 2: /* z axis */
- line_type = GL_LINE_STRIP;
-
- /* start at top left */
- negate_v3_v3(v1, dx);
- add_v3_v3(v1, dy);
-
- copy_v3_v3(buffer[n++], v1);
-
- mul_v3_fl(dx, 2.0f);
- add_v3_v3(v1, dx);
-
- copy_v3_v3(buffer[n++], v1);
-
- mul_v3_fl(dy, 2.0f);
- sub_v3_v3(v1, dx);
- sub_v3_v3(v1, dy);
-
- copy_v3_v3(buffer[n++], v1);
-
- add_v3_v3(v1, dx);
-
- copy_v3_v3(buffer[n++], v1);
-
- break;
- default:
- BLI_assert(0);
- return;
- }
-
- for (int i = 0; i < n; i++) {
- mul_transposed_m3_v3((float (*)[3])viewmat_local_unit, buffer[i]);
- add_v3_v3(buffer[i], c);
- }
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, buffer);
- glDrawArrays(line_type, 0, n);
- glDisableClientState(GL_VERTEX_ARRAY);
-}
-
-void drawaxes(const float viewmat_local[4][4], float size, char drawtype)
-{
- int axis;
- float v1[3] = {0.0, 0.0, 0.0};
- float v2[3] = {0.0, 0.0, 0.0};
- float v3[3] = {0.0, 0.0, 0.0};
-
- glLineWidth(1);
-
- switch (drawtype) {
-
- case OB_PLAINAXES:
- for (axis = 0; axis < 3; axis++) {
- glBegin(GL_LINES);
-
- v1[axis] = size;
- v2[axis] = -size;
- glVertex3fv(v1);
- glVertex3fv(v2);
-
- /* reset v1 & v2 to zero */
- v1[axis] = v2[axis] = 0.0f;
-
- glEnd();
- }
- break;
- case OB_SINGLE_ARROW:
-
- glBegin(GL_LINES);
- /* in positive z direction only */
- v1[2] = size;
- glVertex3fv(v1);
- glVertex3fv(v2);
- glEnd();
-
- /* square pyramid */
- glBegin(GL_TRIANGLES);
-
- v2[0] = size * 0.035f; v2[1] = size * 0.035f;
- v3[0] = size * -0.035f; v3[1] = size * 0.035f;
- v2[2] = v3[2] = size * 0.75f;
-
- for (axis = 0; axis < 4; axis++) {
- if (axis % 2 == 1) {
- v2[0] = -v2[0];
- v3[1] = -v3[1];
- }
- else {
- v2[1] = -v2[1];
- v3[0] = -v3[0];
- }
-
- glVertex3fv(v1);
- glVertex3fv(v2);
- glVertex3fv(v3);
-
- }
- glEnd();
-
- break;
- case OB_CUBE:
- drawcube_size(size);
- break;
-
- case OB_CIRCLE:
- drawcircle_size(size);
- break;
-
- case OB_EMPTY_SPHERE:
- draw_empty_sphere(size);
- break;
-
- case OB_EMPTY_CONE:
- draw_empty_cone(size);
- break;
-
- case OB_ARROWS:
- default:
- {
- float viewmat_local_unit[3][3];
-
- copy_m3_m4(viewmat_local_unit, (float (*)[4])viewmat_local);
- normalize_m3(viewmat_local_unit);
-
- for (axis = 0; axis < 3; axis++) {
- const int arrow_axis = (axis == 0) ? 1 : 0;
-
- glBegin(GL_LINES);
-
- v2[axis] = size;
- glVertex3fv(v1);
- glVertex3fv(v2);
-
- v1[axis] = size * 0.85f;
- v1[arrow_axis] = -size * 0.08f;
- glVertex3fv(v1);
- glVertex3fv(v2);
-
- v1[arrow_axis] = size * 0.08f;
- glVertex3fv(v1);
- glVertex3fv(v2);
-
- glEnd();
-
- v2[axis] += size * 0.125f;
-
- draw_xyz_wire(viewmat_local_unit, v2, size, axis);
-
-
- /* reset v1 & v2 to zero */
- v1[arrow_axis] = v1[axis] = v2[axis] = 0.0f;
- }
- break;
- }
- }
-}
-
-
-/* Function to draw an Image on an empty Object */
-static void draw_empty_image(Object *ob, const short dflag, const unsigned char ob_wire_col[4], eStereoViews sview)
-{
- Image *ima = ob->data;
- ImBuf *ibuf;
- ImageUser iuser = *ob->iuser;
-
- /* Support multi-view */
- if (ima && (sview == STEREO_RIGHT_ID)) {
- iuser.multiview_eye = sview;
- iuser.flag |= IMA_SHOW_STEREO;
- BKE_image_multiview_index(ima, &iuser);
- }
-
- ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
-
- if (ibuf && (ibuf->rect == NULL) && (ibuf->rect_float != NULL)) {
- IMB_rect_from_float(ibuf);
- }
-
- int ima_x, ima_y;
-
- /* Get the buffer dimensions so we can fallback to fake ones */
- if (ibuf && ibuf->rect) {
- ima_x = ibuf->x;
- ima_y = ibuf->y;
- }
- else {
- ima_x = 1;
- ima_y = 1;
- }
-
- float sca_x = 1.0f;
- float sca_y = 1.0f;
-
- /* Get the image aspect even if the buffer is invalid */
- if (ima) {
- if (ima->aspx > ima->aspy) {
- sca_y = ima->aspy / ima->aspx;
- }
- else if (ima->aspx < ima->aspy) {
- sca_x = ima->aspx / ima->aspy;
- }
- }
-
- /* Calculate the scale center based on object's origin */
- float ofs_x = ob->ima_ofs[0] * ima_x;
- float ofs_y = ob->ima_ofs[1] * ima_y;
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-
- /* Calculate Image scale */
- float scale = ob->empty_drawsize / max_ff((float)ima_x * sca_x, (float)ima_y * sca_y);
-
- /* Set the object scale */
- glScalef(scale * sca_x, scale * sca_y, 1.0f);
-
- if (ibuf && ibuf->rect) {
- const bool use_clip = (U.glalphaclip != 1.0f);
- int zoomfilter = (U.gameflags & USER_DISABLE_MIPMAP) ? GL_NEAREST : GL_LINEAR;
- /* Setup GL params */
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- if (use_clip) {
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, U.glalphaclip);
- }
-
- /* Use the object color and alpha */
- glColor4fv(ob->col);
-
- /* Draw the Image on the screen */
- glaDrawPixelsTex(ofs_x, ofs_y, ima_x, ima_y, GL_RGBA, GL_UNSIGNED_BYTE, zoomfilter, ibuf->rect);
-
- glDisable(GL_BLEND);
-
- if (use_clip) {
- glDisable(GL_ALPHA_TEST);
- glAlphaFunc(GL_ALWAYS, 0.0f);
- }
- }
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(ob_wire_col);
- }
-
- /* Calculate the outline vertex positions */
- glBegin(GL_LINE_LOOP);
- glVertex2f(ofs_x, ofs_y);
- glVertex2f(ofs_x + ima_x, ofs_y);
- glVertex2f(ofs_x + ima_x, ofs_y + ima_y);
- glVertex2f(ofs_x, ofs_y + ima_y);
- glEnd();
-
- /* Reset GL settings */
- glPopMatrix();
-
- BKE_image_release_ibuf(ima, ibuf, NULL);
-}
-
static void circball_array_fill(float verts[CIRCLE_RESOL][3], const float cent[3], float rad, const float tmat[4][4])
{
float vx[3], vy[3];
@@ -747,838 +235,17 @@ static void circball_array_fill(float verts[CIRCLE_RESOL][3], const float cent[3
}
}
-void drawcircball(int mode, const float cent[3], float rad, const float tmat[4][4])
+void imm_drawcircball(const float cent[3], float rad, const float tmat[4][4], unsigned pos)
{
float verts[CIRCLE_RESOL][3];
circball_array_fill(verts, cent, rad, tmat);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, verts);
- glDrawArrays(mode, 0, CIRCLE_RESOL);
- glDisableClientState(GL_VERTEX_ARRAY);
-}
-
-/* circle for object centers, special_color is for library or ob users */
-static void drawcentercircle(View3D *v3d, RegionView3D *rv3d, const float co[3], int selstate, bool special_color)
-{
- const float size = ED_view3d_pixel_size(rv3d, co) * (float)U.obcenter_dia * 0.5f;
- float verts[CIRCLE_RESOL][3];
-
- /* using glDepthFunc guarantees that it does write z values,
- * but not checks for it, so centers remain visible independent of draw order */
- if (v3d->zbuf) glDepthFunc(GL_ALWAYS);
- /* write to near buffer always */
- glDepthRange(0.0, 0.0);
- glEnable(GL_BLEND);
-
- if (special_color) {
- if (selstate == ACTIVE || selstate == SELECT) glColor4ub(0x88, 0xFF, 0xFF, 155);
- else glColor4ub(0x55, 0xCC, 0xCC, 155);
- }
- else {
- if (selstate == ACTIVE) UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -80);
- else if (selstate == SELECT) UI_ThemeColorShadeAlpha(TH_SELECT, 0, -80);
- else if (selstate == DESELECT) UI_ThemeColorShadeAlpha(TH_TRANSFORM, 0, -80);
- }
-
- circball_array_fill(verts, co, size, rv3d->viewinv);
-
- /* enable vertex array */
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, verts);
-
- /* 1. draw filled, blended polygon */
- glDrawArrays(GL_POLYGON, 0, CIRCLE_RESOL);
-
- /* 2. draw outline */
- glLineWidth(1);
- UI_ThemeColorShadeAlpha(TH_WIRE, 0, -30);
- glDrawArrays(GL_LINE_LOOP, 0, CIRCLE_RESOL);
-
- /* finish up */
- glDisableClientState(GL_VERTEX_ARRAY);
-
- glDepthRange(0.0, 1.0);
- glDisable(GL_BLEND);
-
- if (v3d->zbuf) glDepthFunc(GL_LEQUAL);
-}
-
-/* *********** text drawing for object/particles/armature ************* */
-
-typedef struct ViewCachedString {
- struct ViewCachedString *next;
- float vec[3];
- union {
- unsigned char ub[4];
- int pack;
- } col;
- short sco[2];
- short xoffs;
- short flag;
- int str_len;
-
- /* str is allocated past the end */
- char str[0];
-} ViewCachedString;
-
-/* one arena for all 3 string lists */
-static MemArena *g_v3d_strings_arena = NULL;
-static ViewCachedString *g_v3d_strings[3] = {NULL, NULL, NULL};
-static int g_v3d_string_level = -1;
-
-void view3d_cached_text_draw_begin(void)
-{
- g_v3d_string_level++;
-
- BLI_assert(g_v3d_string_level >= 0);
-
- if (g_v3d_string_level == 0) {
- BLI_assert(g_v3d_strings_arena == NULL);
- }
-}
-
-void view3d_cached_text_draw_add(const float co[3],
- const char *str, const size_t str_len,
- short xoffs, short flag,
- const unsigned char col[4])
-{
- int alloc_len = str_len + 1;
- ViewCachedString *vos;
-
- BLI_assert(str_len == strlen(str));
-
- if (g_v3d_strings_arena == NULL) {
- g_v3d_strings_arena = BLI_memarena_new(MEM_SIZE_OPTIMAL(1 << 14), __func__);
- }
-
- vos = BLI_memarena_alloc(g_v3d_strings_arena, sizeof(ViewCachedString) + alloc_len);
-
- BLI_LINKS_PREPEND(g_v3d_strings[g_v3d_string_level], vos);
-
- copy_v3_v3(vos->vec, co);
- copy_v4_v4_uchar(vos->col.ub, col);
- vos->xoffs = xoffs;
- vos->flag = flag;
- vos->str_len = str_len;
-
- /* allocate past the end */
- memcpy(vos->str, str, alloc_len);
-}
-
-void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write)
-{
- RegionView3D *rv3d = ar->regiondata;
- ViewCachedString *vos;
- int tot = 0;
-
- BLI_assert(g_v3d_string_level >= 0 && g_v3d_string_level <= 2);
-
- /* project first and test */
- for (vos = g_v3d_strings[g_v3d_string_level]; vos; vos = vos->next) {
- if (ED_view3d_project_short_ex(ar,
- (vos->flag & V3D_CACHE_TEXT_GLOBALSPACE) ? rv3d->persmat : rv3d->persmatob,
- (vos->flag & V3D_CACHE_TEXT_LOCALCLIP) != 0,
- vos->vec, vos->sco,
- V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
- {
- tot++;
- }
- else {
- vos->sco[0] = IS_CLIPPED;
- }
- }
-
- if (tot) {
- int col_pack_prev = 0;
-
-#if 0
- bglMats mats; /* ZBuffer depth vars */
- double ux, uy, uz;
- float depth;
-
- if (v3d->zbuf)
- bgl_get_mats(&mats);
-#endif
- if (rv3d->rflag & RV3D_CLIPPING) {
- ED_view3d_clipping_disable();
- }
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- wmOrtho2_region_pixelspace(ar);
- glLoadIdentity();
-
- if (depth_write) {
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
- }
- else {
- glDepthMask(0);
- }
-
- for (vos = g_v3d_strings[g_v3d_string_level]; vos; vos = vos->next) {
- if (vos->sco[0] != IS_CLIPPED) {
- if (col_pack_prev != vos->col.pack) {
- glColor3ubv(vos->col.ub);
- col_pack_prev = vos->col.pack;
- }
-
- ((vos->flag & V3D_CACHE_TEXT_ASCII) ? BLF_draw_default_ascii : BLF_draw_default)(
- (float)(vos->sco[0] + vos->xoffs),
- (float)(vos->sco[1]),
- (depth_write) ? 0.0f : 2.0f,
- vos->str,
- vos->str_len);
- }
- }
-
- if (depth_write) {
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- }
- else {
- glDepthMask(1);
- }
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-
- if (rv3d->rflag & RV3D_CLIPPING) {
- ED_view3d_clipping_enable();
- }
- }
-
- g_v3d_strings[g_v3d_string_level] = NULL;
-
- if (g_v3d_string_level == 0) {
- if (g_v3d_strings_arena) {
- BLI_memarena_free(g_v3d_strings_arena);
- g_v3d_strings_arena = NULL;
- }
- }
-
- g_v3d_string_level--;
-}
-
-/* ******************** primitive drawing ******************* */
-
-/* draws a cube given the scaling of the cube, assuming that
- * all required matrices have been set (used for drawing empties)
- */
-static void drawcube_size(float size)
-{
- const GLfloat pos[8][3] = {
- {-size, -size, -size},
- {-size, -size, size},
- {-size, size, -size},
- {-size, size, size},
- { size, -size, -size},
- { size, -size, size},
- { size, size, -size},
- { size, size, size}
- };
-
- const GLubyte indices[24] = {0, 1, 1, 3, 3, 2, 2, 0, 0, 4, 4, 5, 5, 7, 7, 6, 6, 4, 1, 5, 3, 7, 2, 6};
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, pos);
- glDrawRangeElements(GL_LINES, 0, 7, 24, GL_UNSIGNED_BYTE, indices);
- glDisableClientState(GL_VERTEX_ARRAY);
-}
-
-static void drawshadbuflimits(Lamp *la, float mat[4][4])
-{
- float sta[3], end[3], lavec[3];
-
- negate_v3_v3(lavec, mat[2]);
- normalize_v3(lavec);
-
- madd_v3_v3v3fl(sta, mat[3], lavec, la->clipsta);
- madd_v3_v3v3fl(end, mat[3], lavec, la->clipend);
-
- glBegin(GL_LINES);
- glVertex3fv(sta);
- glVertex3fv(end);
- glEnd();
-
- glPointSize(3.0);
- glBegin(GL_POINTS);
- glVertex3fv(sta);
- glVertex3fv(end);
- glEnd();
-}
-
-static void spotvolume(float lvec[3], float vvec[3], const float inp)
-{
- /* camera is at 0,0,0 */
- float temp[3], plane[3], mat1[3][3], mat2[3][3], mat3[3][3], mat4[3][3], q[4], co, si, angle;
-
- normalize_v3(lvec);
- normalize_v3(vvec); /* is this the correct vector ? */
-
- cross_v3_v3v3(temp, vvec, lvec); /* equation for a plane through vvec and lvec */
- cross_v3_v3v3(plane, lvec, temp); /* a plane perpendicular to this, parallel with lvec */
-
- /* vectors are exactly aligned, use the X axis, this is arbitrary */
- if (normalize_v3(plane) == 0.0f)
- plane[1] = 1.0f;
-
- /* now we've got two equations: one of a cone and one of a plane, but we have
- * three unknowns. We remove one unknown by rotating the plane to z=0 (the plane normal) */
-
- /* rotate around cross product vector of (0,0,1) and plane normal, dot product degrees */
- /* according definition, we derive cross product is (plane[1],-plane[0],0), en cos = plane[2]);*/
-
- /* translating this comment to english didnt really help me understanding the math! :-) (ton) */
-
- q[1] = plane[1];
- q[2] = -plane[0];
- q[3] = 0;
- normalize_v3(&q[1]);
-
- angle = saacos(plane[2]) / 2.0f;
- co = cosf(angle);
- si = sqrtf(1 - co * co);
-
- q[0] = co;
- q[1] *= si;
- q[2] *= si;
- q[3] = 0;
-
- quat_to_mat3(mat1, q);
-
- /* rotate lamp vector now over acos(inp) degrees */
- copy_v3_v3(vvec, lvec);
-
- unit_m3(mat2);
- co = inp;
- si = sqrtf(1.0f - inp * inp);
-
- mat2[0][0] = co;
- mat2[1][0] = -si;
- mat2[0][1] = si;
- mat2[1][1] = co;
- mul_m3_m3m3(mat3, mat2, mat1);
-
- mat2[1][0] = si;
- mat2[0][1] = -si;
- mul_m3_m3m3(mat4, mat2, mat1);
- transpose_m3(mat1);
-
- mul_m3_m3m3(mat2, mat1, mat3);
- mul_m3_v3(mat2, lvec);
- mul_m3_m3m3(mat2, mat1, mat4);
- mul_m3_v3(mat2, vvec);
-}
-
-static void draw_spot_cone(Lamp *la, float x, float z)
-{
- z = fabsf(z);
-
- glBegin(GL_TRIANGLE_FAN);
- glVertex3f(0.0f, 0.0f, -x);
-
- if (la->mode & LA_SQUARE) {
- glVertex3f(z, z, 0);
- glVertex3f(-z, z, 0);
- glVertex3f(-z, -z, 0);
- glVertex3f(z, -z, 0);
- glVertex3f(z, z, 0);
- }
- else {
- for (int a = 0; a < 33; a++) {
- float angle = a * M_PI * 2 / (33 - 1);
- glVertex3f(z * cosf(angle), z * sinf(angle), 0);
- }
- }
-
- glEnd();
-}
-
-static void draw_transp_spot_volume(Lamp *la, float x, float z)
-{
- glEnable(GL_CULL_FACE);
- glEnable(GL_BLEND);
- glDepthMask(0);
-
- /* draw backside darkening */
- glCullFace(GL_FRONT);
-
- glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
-
- draw_spot_cone(la, x, z);
-
- /* draw front side lighting */
- glCullFace(GL_BACK);
-
- glBlendFunc(GL_ONE, GL_ONE);
- glColor4f(0.2f, 0.2f, 0.2f, 1.0f);
-
- draw_spot_cone(la, x, z);
-
- /* restore state */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_BLEND);
- glDepthMask(1);
- glDisable(GL_CULL_FACE);
- glCullFace(GL_BACK);
-}
-
-#ifdef WITH_GAMEENGINE
-static void draw_transp_sun_volume(Lamp *la)
-{
- float box[8][3];
-
- /* construct box */
- box[0][0] = box[1][0] = box[2][0] = box[3][0] = -la->shadow_frustum_size;
- box[4][0] = box[5][0] = box[6][0] = box[7][0] = +la->shadow_frustum_size;
- box[0][1] = box[1][1] = box[4][1] = box[5][1] = -la->shadow_frustum_size;
- box[2][1] = box[3][1] = box[6][1] = box[7][1] = +la->shadow_frustum_size;
- box[0][2] = box[3][2] = box[4][2] = box[7][2] = -la->clipend;
- box[1][2] = box[2][2] = box[5][2] = box[6][2] = -la->clipsta;
-
- /* draw edges */
- draw_box(box, false);
-
- /* draw faces */
- glEnable(GL_CULL_FACE);
- glEnable(GL_BLEND);
- glDepthMask(0);
-
- /* draw backside darkening */
- glCullFace(GL_FRONT);
-
- glBlendFunc(GL_ZERO, GL_SRC_ALPHA);
- glColor4f(0.0f, 0.0f, 0.0f, 0.4f);
-
- draw_box(box, true);
-
- /* draw front side lighting */
- glCullFace(GL_BACK);
-
- glBlendFunc(GL_ONE, GL_ONE);
- glColor4f(0.2f, 0.2f, 0.2f, 1.0f);
-
- draw_box(box, true);
-
- /* restore state */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_BLEND);
- glDepthMask(1);
- glDisable(GL_CULL_FACE);
- glCullFace(GL_BACK);
-}
-#endif
-
-static void drawlamp(View3D *v3d, RegionView3D *rv3d, Base *base,
- const char dt, const short dflag, const unsigned char ob_wire_col[4], const bool is_obact)
-{
- Object *ob = base->object;
- const float pixsize = ED_view3d_pixel_size(rv3d, ob->obmat[3]);
- Lamp *la = ob->data;
- float vec[3], lvec[3], vvec[3], circrad;
- float lampsize;
- float imat[4][4];
-
- unsigned char curcol[4];
- unsigned char col[4];
- /* cone can't be drawn for duplicated lamps, because duplilist would be freed */
- /* the moment of view3d_draw_transp() call */
- const bool is_view = (rv3d->persp == RV3D_CAMOB && v3d->camera == base->object);
- const bool drawcone = ((dt > OB_WIRE) &&
- !(G.f & G_PICKSEL) &&
- (la->type == LA_SPOT) &&
- (la->mode & LA_SHOW_CONE) &&
- !(base->flag & OB_FROMDUPLI) &&
- !is_view);
-
-#ifdef WITH_GAMEENGINE
- const bool drawshadowbox = (
- (rv3d->rflag & RV3D_IS_GAME_ENGINE) &&
- (dt > OB_WIRE) &&
- !(G.f & G_PICKSEL) &&
- (la->type == LA_SUN) &&
- ((la->mode & LA_SHAD_BUF) ||
- (la->mode & LA_SHAD_RAY)) &&
- (la->mode & LA_SHOW_SHADOW_BOX) &&
- !(base->flag & OB_FROMDUPLI) &&
- !is_view);
-#else
- const bool drawshadowbox = false;
-#endif
-
- if ((drawcone || drawshadowbox) && !v3d->transp) {
- /* in this case we need to draw delayed */
- ED_view3d_after_add(v3d->xray ? &v3d->afterdraw_xraytransp : &v3d->afterdraw_transp, base, dflag);
- return;
- }
-
- /* we first draw only the screen aligned & fixed scale stuff */
- glPushMatrix();
- glLoadMatrixf(rv3d->viewmat);
-
- /* lets calculate the scale: */
- lampsize = pixsize * ((float)U.obcenter_dia * 0.5f);
-
- /* and view aligned matrix: */
- copy_m4_m4(imat, rv3d->viewinv);
- normalize_v3(imat[0]);
- normalize_v3(imat[1]);
-
- /* lamp center */
- copy_v3_v3(vec, ob->obmat[3]);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- /* for AA effects */
- curcol[0] = ob_wire_col[0];
- curcol[1] = ob_wire_col[1];
- curcol[2] = ob_wire_col[2];
- curcol[3] = 154;
- glColor4ubv(curcol);
- }
-
- glLineWidth(1);
-
- if (lampsize > 0.0f) {
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (ob->id.us > 1) {
- if (is_obact || (ob->flag & SELECT)) {
- glColor4ub(0x88, 0xFF, 0xFF, 155);
- }
- else {
- glColor4ub(0x77, 0xCC, 0xCC, 155);
- }
- }
- }
-
- /* Inner Circle */
- glEnable(GL_BLEND);
- drawcircball(GL_LINE_LOOP, vec, lampsize, imat);
- glDisable(GL_BLEND);
- drawcircball(GL_POLYGON, vec, lampsize, imat);
-
- /* restore */
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (ob->id.us > 1)
- glColor4ubv(curcol);
- }
-
- /* Outer circle */
- circrad = 3.0f * lampsize;
- setlinestyle(3);
-
- drawcircball(GL_LINE_LOOP, vec, circrad, imat);
-
- /* draw dashed outer circle if shadow is on. remember some lamps can't have certain shadows! */
- if (la->type != LA_HEMI) {
- if ((la->mode & LA_SHAD_RAY) || ((la->mode & LA_SHAD_BUF) && (la->type == LA_SPOT))) {
- drawcircball(GL_LINE_LOOP, vec, circrad + 3.0f * pixsize, imat);
- }
- }
- }
- else {
- setlinestyle(3);
- circrad = 0.0f;
- }
-
- /* draw the pretty sun rays */
- if (la->type == LA_SUN) {
- float v1[3], v2[3], mat[3][3];
- short axis;
-
- /* setup a 45 degree rotation matrix */
- axis_angle_normalized_to_mat3_ex(mat, imat[2], M_SQRT1_2, M_SQRT1_2);
-
- /* vectors */
- mul_v3_v3fl(v1, imat[0], circrad * 1.2f);
- mul_v3_v3fl(v2, imat[0], circrad * 2.5f);
-
- /* center */
- glTranslate3fv(vec);
-
- setlinestyle(3);
-
- glBegin(GL_LINES);
- for (axis = 0; axis < 8; axis++) {
- glVertex3fv(v1);
- glVertex3fv(v2);
- mul_m3_v3(mat, v1);
- mul_m3_v3(mat, v2);
- }
- glEnd();
-
- glTranslatef(-vec[0], -vec[1], -vec[2]);
-
- }
-
- if (la->type == LA_LOCAL) {
- if (la->mode & LA_SPHERE) {
- drawcircball(GL_LINE_LOOP, vec, la->dist, imat);
- }
- }
-
- glPopMatrix(); /* back in object space */
- zero_v3(vec);
-
- if (is_view) {
- /* skip drawing extra info */
- }
- else if (la->type == LA_SPOT) {
- float x, y, z, z_abs;
- copy_v3_fl3(lvec, 0.0f, 0.0f, 1.0f);
- copy_v3_fl3(vvec, rv3d->persmat[0][2], rv3d->persmat[1][2], rv3d->persmat[2][2]);
- mul_transposed_mat3_m4_v3(ob->obmat, vvec);
-
- x = -la->dist;
- y = cosf(la->spotsize * 0.5f);
- z = x * sqrtf(1.0f - y * y);
-
- spotvolume(lvec, vvec, y);
- mul_v3_fl(lvec, x);
- mul_v3_fl(vvec, x);
-
- x *= y;
-
- z_abs = fabsf(z);
-
- if (la->mode & LA_SQUARE) {
- /* draw pyramid */
- const float vertices[5][3] = {
- /* 5 of vertex coords of pyramid */
- {0.0f, 0.0f, 0.0f},
- {z_abs, z_abs, x},
- {-z_abs, -z_abs, x},
- {z_abs, -z_abs, x},
- {-z_abs, z_abs, x},
- };
- const unsigned char indices[] = {
- 0, 1, 3,
- 0, 3, 2,
- 0, 2, 4,
- 0, 1, 4,
- };
-
- /* Draw call:
- * activate and specify pointer to vertex array */
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vertices);
- /* draw the pyramid */
- glDrawElements(GL_LINE_STRIP, 12, GL_UNSIGNED_BYTE, indices);
-
- /* deactivate vertex arrays after drawing */
- glDisableClientState(GL_VERTEX_ARRAY);
-
- glTranslatef(0.0f, 0.0f, x);
-
- /* draw the square representing spotbl */
- if (la->type == LA_SPOT) {
- float blend = z_abs * (1.0f - pow2f(la->spotblend));
-
- /* hide line if it is zero size or overlaps with outer border,
- * previously it adjusted to always to show it but that seems
- * confusing because it doesn't show the actual blend size */
- if (blend != 0.0f && blend != z_abs) {
- fdrawbox(blend, -blend, -blend, blend);
- }
- }
- }
- else {
-
- /* draw the angled sides of the cone */
- glBegin(GL_LINE_STRIP);
- glVertex3fv(vvec);
- glVertex3fv(vec);
- glVertex3fv(lvec);
- glEnd();
-
- /* draw the circle at the end of the cone */
- glTranslatef(0.0f, 0.0f, x);
- circ(0.0f, 0.0f, z_abs);
-
- /* draw the circle representing spotbl */
- if (la->type == LA_SPOT) {
- float blend = z_abs * (1.0f - pow2f(la->spotblend));
-
- /* hide line if it is zero size or overlaps with outer border,
- * previously it adjusted to always to show it but that seems
- * confusing because it doesn't show the actual blend size */
- if (blend != 0.0f && blend != z_abs) {
- circ(0.0f, 0.0f, blend);
- }
- }
- }
-
- if (drawcone)
- draw_transp_spot_volume(la, x, z);
-
- /* draw clip start, useful for wide cones where its not obvious where the start is */
- glTranslatef(0.0, 0.0, -x); /* reverse translation above */
- glBegin(GL_LINES);
- if (la->type == LA_SPOT && (la->mode & LA_SHAD_BUF)) {
- float lvec_clip[3];
- float vvec_clip[3];
- float clipsta_fac = la->clipsta / -x;
-
- interp_v3_v3v3(lvec_clip, vec, lvec, clipsta_fac);
- interp_v3_v3v3(vvec_clip, vec, vvec, clipsta_fac);
-
- glVertex3fv(lvec_clip);
- glVertex3fv(vvec_clip);
- }
- /* Else, draw spot direction (using distance as end limit, same as for Area lamp). */
- else {
- glVertex3f(0.0, 0.0, -circrad);
- glVertex3f(0.0, 0.0, -la->dist);
- }
- glEnd();
- }
- else if (ELEM(la->type, LA_HEMI, LA_SUN)) {
-
- /* draw the line from the circle along the dist */
- glBegin(GL_LINES);
- vec[2] = -circrad;
- glVertex3fv(vec);
- vec[2] = -la->dist;
- glVertex3fv(vec);
- glEnd();
-
- if (la->type == LA_HEMI) {
- /* draw the hemisphere curves */
- short axis, steps, dir;
- float outdist, zdist, mul;
- zero_v3(vec);
- outdist = 0.14; mul = 1.4; dir = 1;
-
- setlinestyle(4);
- /* loop over the 4 compass points, and draw each arc as a LINE_STRIP */
- for (axis = 0; axis < 4; axis++) {
- float v[3] = {0.0, 0.0, 0.0};
- zdist = 0.02;
-
- glBegin(GL_LINE_STRIP);
-
- for (steps = 0; steps < 6; steps++) {
- if (axis == 0 || axis == 1) { /* x axis up, x axis down */
- /* make the arcs start at the edge of the energy circle */
- if (steps == 0) v[0] = dir * circrad;
- else v[0] = v[0] + dir * (steps * outdist);
- }
- else if (axis == 2 || axis == 3) { /* y axis up, y axis down */
- /* make the arcs start at the edge of the energy circle */
- v[1] = (steps == 0) ? (dir * circrad) : (v[1] + dir * (steps * outdist));
- }
-
- v[2] = v[2] - steps * zdist;
-
- glVertex3fv(v);
-
- zdist = zdist * mul;
- }
-
- glEnd();
- /* flip the direction */
- dir = -dir;
- }
- }
-
-#ifdef WITH_GAMEENGINE
- if (drawshadowbox) {
- draw_transp_sun_volume(la);
- }
-#endif
-
- }
- else if (la->type == LA_AREA) {
- setlinestyle(3);
- if (la->area_shape == LA_AREA_SQUARE)
- fdrawbox(-la->area_size * 0.5f, -la->area_size * 0.5f, la->area_size * 0.5f, la->area_size * 0.5f);
- else if (la->area_shape == LA_AREA_RECT)
- fdrawbox(-la->area_size * 0.5f, -la->area_sizey * 0.5f, la->area_size * 0.5f, la->area_sizey * 0.5f);
-
- glBegin(GL_LINES);
- glVertex3f(0.0, 0.0, -circrad);
- glVertex3f(0.0, 0.0, -la->dist);
- glEnd();
- }
-
- /* and back to viewspace */
- glPushMatrix();
- glLoadMatrixf(rv3d->viewmat);
- copy_v3_v3(vec, ob->obmat[3]);
-
- setlinestyle(0);
-
- if ((la->type == LA_SPOT) && (la->mode & LA_SHAD_BUF) && (is_view == false)) {
- drawshadbuflimits(la, ob->obmat);
- }
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- UI_GetThemeColor4ubv(TH_LAMP, col);
- glColor4ubv(col);
+ immBegin(GWN_PRIM_LINE_LOOP, CIRCLE_RESOL);
+ for (int i = 0; i < CIRCLE_RESOL; ++i) {
+ immVertex3fv(pos, verts[i]);
}
-
- glEnable(GL_BLEND);
-
- if (vec[2] > 0) vec[2] -= circrad;
- else vec[2] += circrad;
-
- glBegin(GL_LINES);
- glVertex3fv(vec);
- vec[2] = 0;
- glVertex3fv(vec);
- glEnd();
-
- glPointSize(2.0);
- glBegin(GL_POINTS);
- glVertex3fv(vec);
- glEnd();
-
- glDisable(GL_BLEND);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- /* restore for drawing extra stuff */
- glColor3ubv(ob_wire_col);
- }
- /* and finally back to org object space! */
- glPopMatrix();
-}
-
-static void draw_limit_line(float sta, float end, const short dflag, const unsigned char col[3])
-{
- glBegin(GL_LINES);
- glVertex3f(0.0, 0.0, -sta);
- glVertex3f(0.0, 0.0, -end);
- glEnd();
-
- if (!(dflag & DRAW_PICKING)) {
- glPointSize(3.0);
- glBegin(GL_POINTS);
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(col);
- }
- glVertex3f(0.0, 0.0, -sta);
- glVertex3f(0.0, 0.0, -end);
- glEnd();
- }
-}
-
-
-/* yafray: draw camera focus point (cross, similar to aqsis code in tuhopuu) */
-/* qdn: now also enabled for Blender to set focus point for defocus composite node */
-static void draw_focus_cross(float dist, float size)
-{
- glBegin(GL_LINES);
- glVertex3f(-size, 0.0f, -dist);
- glVertex3f(size, 0.0f, -dist);
- glVertex3f(0.0f, -size, -dist);
- glVertex3f(0.0f, size, -dist);
- glEnd();
+ immEnd();
}
#ifdef VIEW3D_CAMERA_BORDER_HACK
@@ -1586,6779 +253,290 @@ unsigned char view3d_camera_border_hack_col[3];
bool view3d_camera_border_hack_test = false;
#endif
-/* ****************** draw clip data *************** */
-
-static void draw_bundle_sphere(void)
-{
- static GLuint displist = 0;
-
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_FILL);
- gluSphere(qobj, 0.05, 8, 8);
- gluDeleteQuadric(qobj);
-
- glEndList();
- }
-
- glCallList(displist);
-}
-
-static void draw_viewport_object_reconstruction(
- Scene *scene, Base *base, const View3D *v3d, const RegionView3D *rv3d,
- MovieClip *clip, MovieTrackingObject *tracking_object,
- const short dflag, const unsigned char ob_wire_col[4],
- int *global_track_index, bool draw_selected)
-{
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingTrack *track;
- float mat[4][4], imat[4][4];
- unsigned char col_unsel[4], col_sel[4];
- int tracknr = *global_track_index;
- ListBase *tracksbase = BKE_tracking_object_get_tracks(tracking, tracking_object);
- float camera_size[3];
-
- UI_GetThemeColor4ubv(TH_TEXT, col_unsel);
- UI_GetThemeColor4ubv(TH_SELECT, col_sel);
-
- BKE_tracking_get_camera_object_matrix(scene, base->object, mat);
-
- /* we're compensating camera size for bundles size,
- * to make it so bundles are always displayed with the same size */
- copy_v3_v3(camera_size, base->object->size);
- if ((tracking_object->flag & TRACKING_OBJECT_CAMERA) == 0)
- mul_v3_fl(camera_size, tracking_object->scale);
-
- glPushMatrix();
-
- if (tracking_object->flag & TRACKING_OBJECT_CAMERA) {
- /* current ogl matrix is translated in camera space, bundles should
- * be rendered in world space, so camera matrix should be "removed"
- * from current ogl matrix */
- invert_m4_m4(imat, base->object->obmat);
-
- glMultMatrixf(imat);
- glMultMatrixf(mat);
- }
- else {
- float obmat[4][4];
- int framenr = BKE_movieclip_remap_scene_to_clip_frame(clip, scene->r.cfra);
-
- BKE_tracking_camera_get_reconstructed_interpolate(tracking, tracking_object, framenr, obmat);
-
- invert_m4_m4(imat, obmat);
- glMultMatrixf(imat);
- }
-
- for (track = tracksbase->first; track; track = track->next) {
- bool selected = TRACK_SELECTED(track);
-
- if (draw_selected && !selected)
- continue;
-
- if ((track->flag & TRACK_HAS_BUNDLE) == 0)
- continue;
-
- if (dflag & DRAW_PICKING)
- GPU_select_load_id(base->selcol + (tracknr << 16));
-
- glPushMatrix();
- glTranslate3fv(track->bundle_pos);
- glScalef(v3d->bundle_size / 0.05f / camera_size[0],
- v3d->bundle_size / 0.05f / camera_size[1],
- v3d->bundle_size / 0.05f / camera_size[2]);
-
- const int v3d_drawtype = view3d_effective_drawtype(v3d);
- if (v3d_drawtype == OB_WIRE) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (selected && (track->flag & TRACK_CUSTOMCOLOR) == 0) {
- glColor3ubv(ob_wire_col);
- }
- else {
- glColor3fv(track->color);
- }
- }
-
- drawaxes(rv3d->viewmatob, 0.05f, v3d->bundle_drawtype);
- }
- else if (v3d_drawtype > OB_WIRE) {
- if (v3d->bundle_drawtype == OB_EMPTY_SPHERE) {
- /* selection outline */
- if (selected) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(ob_wire_col);
- }
-
- glLineWidth(2.0f);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
- draw_bundle_sphere();
-
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
- else UI_ThemeColor(TH_BUNDLE_SOLID);
- }
-
- draw_bundle_sphere();
- }
- else {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (selected) {
- glColor3ubv(ob_wire_col);
- }
- else {
- if (track->flag & TRACK_CUSTOMCOLOR) glColor3fv(track->color);
- else UI_ThemeColor(TH_WIRE);
- }
- }
-
- drawaxes(rv3d->viewmatob, 0.05f, v3d->bundle_drawtype);
- }
- }
-
- glPopMatrix();
-
- if ((dflag & DRAW_PICKING) == 0 && (v3d->flag2 & V3D_SHOW_BUNDLENAME)) {
- float pos[3];
-
- mul_v3_m4v3(pos, mat, track->bundle_pos);
- view3d_cached_text_draw_add(pos,
- track->name, strlen(track->name),
- 10, V3D_CACHE_TEXT_GLOBALSPACE,
- selected ? col_sel : col_unsel);
- }
-
- tracknr++;
- }
-
- if ((dflag & DRAW_PICKING) == 0) {
- if ((v3d->flag2 & V3D_SHOW_CAMERAPATH) && (tracking_object->flag & TRACKING_OBJECT_CAMERA)) {
- MovieTrackingReconstruction *reconstruction;
- reconstruction = BKE_tracking_object_get_reconstruction(tracking, tracking_object);
-
- if (reconstruction->camnr) {
- MovieReconstructedCamera *camera = reconstruction->cameras;
-
- UI_ThemeColor(TH_CAMERA_PATH);
- glLineWidth(2.0f);
-
- glBegin(GL_LINE_STRIP);
- for (int a = 0; a < reconstruction->camnr; a++, camera++) {
- glVertex3fv(camera->mat[3]);
- }
- glEnd();
- }
- }
- }
-
- glPopMatrix();
-
- *global_track_index = tracknr;
-}
-
-static void draw_viewport_reconstruction(
- Scene *scene, Base *base, const View3D *v3d, const RegionView3D *rv3d, MovieClip *clip,
- const short dflag, const unsigned char ob_wire_col[4],
- const bool draw_selected)
-{
- MovieTracking *tracking = &clip->tracking;
- MovieTrackingObject *tracking_object;
- int global_track_index = 1;
-
- if ((v3d->flag2 & V3D_SHOW_RECONSTRUCTION) == 0)
- return;
-
- if (v3d->flag2 & V3D_RENDER_OVERRIDE)
- return;
-
- GPU_basic_shader_colors(NULL, NULL, 0, 1.0f);
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
-
- tracking_object = tracking->objects.first;
- while (tracking_object) {
- draw_viewport_object_reconstruction(
- scene, base, v3d, rv3d, clip, tracking_object,
- dflag, ob_wire_col, &global_track_index, draw_selected);
-
- tracking_object = tracking_object->next;
- }
-
- /* restore */
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(ob_wire_col);
- }
-
- if (dflag & DRAW_PICKING)
- GPU_select_load_id(base->selcol);
-}
-
-static void drawcamera_volume(float near_plane[4][3], float far_plane[4][3], const GLenum mode)
-{
- glBegin(mode);
- glVertex3fv(near_plane[0]);
- glVertex3fv(far_plane[0]);
- glVertex3fv(far_plane[1]);
- glVertex3fv(near_plane[1]);
- glEnd();
-
- glBegin(mode);
- glVertex3fv(near_plane[1]);
- glVertex3fv(far_plane[1]);
- glVertex3fv(far_plane[2]);
- glVertex3fv(near_plane[2]);
- glEnd();
-
- glBegin(mode);
- glVertex3fv(near_plane[2]);
- glVertex3fv(far_plane[2]);
- glVertex3fv(far_plane[3]);
- glVertex3fv(near_plane[3]);
- glEnd();
-
- glBegin(mode);
- glVertex3fv(far_plane[3]);
- glVertex3fv(near_plane[3]);
- glVertex3fv(near_plane[0]);
- glVertex3fv(far_plane[0]);
- glEnd();
-}
-
-/* camera frame */
-static void drawcamera_frame(float vec[4][3], const GLenum mode)
-{
- glBegin(mode);
- glVertex3fv(vec[0]);
- glVertex3fv(vec[1]);
- glVertex3fv(vec[2]);
- glVertex3fv(vec[3]);
- glEnd();
-}
-
-/* center point to camera frame */
-static void drawcamera_framelines(float vec[4][3], float origin[3])
-{
- glBegin(GL_LINE_STRIP);
- glVertex3fv(vec[1]);
- glVertex3fv(origin);
- glVertex3fv(vec[0]);
- glVertex3fv(vec[3]);
- glVertex3fv(origin);
- glVertex3fv(vec[2]);
- glEnd();
-}
-
-static bool drawcamera_is_stereo3d(Scene *scene, View3D *v3d, Object *ob)
-{
- return (ob == v3d->camera) &&
- (scene->r.scemode & R_MULTIVIEW) != 0 &&
- (v3d->stereo3d_flag);
-}
-
-static void drawcamera_stereo3d(
- Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, const Camera *cam,
- float vec[4][3], float drawsize, const float scale[3])
-{
- float obmat[4][4];
- float vec_lr[2][4][3];
- const float fac = (cam->stereo.pivot == CAM_S3D_PIVOT_CENTER) ? 2.0f : 1.0f;
- float origin[2][3] = {{0}};
- float tvec[3];
- const Camera *cam_lr[2];
- const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
-
- const bool is_stereo3d_cameras = (v3d->stereo3d_flag & V3D_S3D_DISPCAMERAS) && (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D);
- const bool is_stereo3d_plane = (v3d->stereo3d_flag & V3D_S3D_DISPPLANE) && (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D);
- const bool is_stereo3d_volume = (v3d->stereo3d_flag & V3D_S3D_DISPVOLUME);
-
- zero_v3(tvec);
-
- glPushMatrix();
-
- for (int i = 0; i < 2; i++) {
- ob = BKE_camera_multiview_render(scene, ob, names[i]);
- cam_lr[i] = ob->data;
-
- glLoadMatrixf(rv3d->viewmat);
- BKE_camera_multiview_model_matrix(&scene->r, ob, names[i], obmat);
- glMultMatrixf(obmat);
-
- copy_m3_m3(vec_lr[i], vec);
- copy_v3_v3(vec_lr[i][3], vec[3]);
-
- if (cam->stereo.convergence_mode == CAM_S3D_OFFAXIS) {
- const float shift_x =
- ((BKE_camera_multiview_shift_x(&scene->r, ob, names[i]) - cam->shiftx) *
- (drawsize * scale[0] * fac));
-
- for (int j = 0; j < 4; j++) {
- vec_lr[i][j][0] += shift_x;
- }
- }
-
- if (is_stereo3d_cameras) {
- /* camera frame */
- drawcamera_frame(vec_lr[i], GL_LINE_LOOP);
-
- /* center point to camera frame */
- drawcamera_framelines(vec_lr[i], tvec);
- }
-
- /* connecting line */
- mul_m4_v3(obmat, origin[i]);
-
- /* convergence plane */
- if (is_stereo3d_plane || is_stereo3d_volume) {
- for (int j = 0; j < 4; j++) {
- mul_m4_v3(obmat, vec_lr[i][j]);
- }
- }
- }
-
-
- /* the remaining drawing takes place in the view space */
- glLoadMatrixf(rv3d->viewmat);
-
- if (is_stereo3d_cameras) {
- /* draw connecting lines */
- GPU_basic_shader_bind_enable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- GPU_basic_shader_line_stipple(2, 0xAAAA);
-
- glBegin(GL_LINES);
- glVertex3fv(origin[0]);
- glVertex3fv(origin[1]);
- glEnd();
-
- GPU_basic_shader_bind_disable(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- }
-
- /* draw convergence plane */
- if (is_stereo3d_plane) {
- float axis_center[3], screen_center[3];
- float world_plane[4][3];
- float local_plane[4][3];
- float offset;
-
- mid_v3_v3v3(axis_center, origin[0], origin[1]);
-
- for (int i = 0; i < 4; i++) {
- mid_v3_v3v3(world_plane[i], vec_lr[0][i], vec_lr[1][i]);
- sub_v3_v3v3(local_plane[i], world_plane[i], axis_center);
- }
-
- mid_v3_v3v3(screen_center, world_plane[0], world_plane[2]);
- offset = cam->stereo.convergence_distance / len_v3v3(screen_center, axis_center);
-
- for (int i = 0; i < 4; i++) {
- mul_v3_fl(local_plane[i], offset);
- add_v3_v3(local_plane[i], axis_center);
- }
-
- glColor3f(0.0f, 0.0f, 0.0f);
-
- /* camera frame */
- drawcamera_frame(local_plane, GL_LINE_LOOP);
-
- if (v3d->stereo3d_convergence_alpha > 0.0f) {
- glEnable(GL_BLEND);
- glDepthMask(0); /* disable write in zbuffer, needed for nice transp */
-
- glColor4f(0.0f, 0.0f, 0.0f, v3d->stereo3d_convergence_alpha);
-
- drawcamera_frame(local_plane, GL_QUADS);
-
- glDisable(GL_BLEND);
- glDepthMask(1); /* restore write in zbuffer */
- }
- }
-
- /* draw convergence plane */
- if (is_stereo3d_volume) {
- float screen_center[3];
- float near_plane[4][3], far_plane[4][3];
-
- for (int i = 0; i < 2; i++) {
- mid_v3_v3v3(screen_center, vec_lr[i][0], vec_lr[i][2]);
-
- float offset = len_v3v3(screen_center, origin[i]);
-
- for (int j = 0; j < 4; j++) {
- sub_v3_v3v3(near_plane[j], vec_lr[i][j], origin[i]);
- mul_v3_fl(near_plane[j], cam_lr[i]->clipsta / offset);
- add_v3_v3(near_plane[j], origin[i]);
-
- sub_v3_v3v3(far_plane[j], vec_lr[i][j], origin[i]);
- mul_v3_fl(far_plane[j], cam_lr[i]->clipend / offset);
- add_v3_v3(far_plane[j], origin[i]);
- }
-
- /* camera frame */
- glColor3f(0.0f, 0.0f, 0.0f);
-
- drawcamera_frame(near_plane, GL_LINE_LOOP);
- drawcamera_frame(far_plane, GL_LINE_LOOP);
- drawcamera_volume(near_plane, far_plane, GL_LINE_LOOP);
-
- if (v3d->stereo3d_volume_alpha > 0.0f) {
- glEnable(GL_BLEND);
- glDepthMask(0); /* disable write in zbuffer, needed for nice transp */
-
- if (i == 0)
- glColor4f(0.0f, 1.0f, 1.0f, v3d->stereo3d_volume_alpha);
- else
- glColor4f(1.0f, 0.0f, 0.0f, v3d->stereo3d_volume_alpha);
-
- drawcamera_frame(near_plane, GL_QUADS);
- drawcamera_frame(far_plane, GL_QUADS);
- drawcamera_volume(near_plane, far_plane, GL_QUADS);
-
- glDisable(GL_BLEND);
- glDepthMask(1); /* restore write in zbuffer */
- }
- }
- }
-
- glPopMatrix();
-}
-
-/* flag similar to draw_object() */
-static void drawcamera(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
- const short dflag, const unsigned char ob_wire_col[4])
-{
- /* a standing up pyramid with (0,0,0) as top */
- Camera *cam;
- Object *ob = base->object;
- float tvec[3];
- float vec[4][3], asp[2], shift[2], scale[3];
- MovieClip *clip = BKE_object_movieclip_get(scene, base->object, false);
-
- const bool is_active = (ob == v3d->camera);
- const bool is_view = (rv3d->persp == RV3D_CAMOB && is_active);
- const bool is_multiview = (scene->r.scemode & R_MULTIVIEW) != 0;
- const bool is_stereo3d = drawcamera_is_stereo3d(scene, v3d, ob);
- const bool is_stereo3d_view = (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D);
- const bool is_stereo3d_cameras = (ob == scene->camera) &&
- is_multiview &&
- is_stereo3d_view &&
- (v3d->stereo3d_flag & V3D_S3D_DISPCAMERAS);
- const bool is_selection_camera_stereo = (G.f & G_PICKSEL) &&
- is_view && is_multiview &&
- is_stereo3d_view;
-
- /* draw data for movie clip set as active for scene */
- if (clip) {
- draw_viewport_reconstruction(scene, base, v3d, rv3d, clip, dflag, ob_wire_col, false);
- draw_viewport_reconstruction(scene, base, v3d, rv3d, clip, dflag, ob_wire_col, true);
- }
-
-#ifdef VIEW3D_CAMERA_BORDER_HACK
- if (is_view && !(G.f & G_PICKSEL)) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- view3d_camera_border_hack_col[0] = ob_wire_col[0];
- view3d_camera_border_hack_col[1] = ob_wire_col[1];
- view3d_camera_border_hack_col[2] = ob_wire_col[2];
- }
- else {
- float col[4];
- glGetFloatv(GL_CURRENT_COLOR, col);
- rgb_float_to_uchar(view3d_camera_border_hack_col, col);
- }
- view3d_camera_border_hack_test = true;
- return;
- }
-#endif
-
- cam = ob->data;
-
- /* BKE_camera_multiview_model_matrix already accounts for scale, don't do it here */
- if (is_selection_camera_stereo) {
- scale[0] = 1.0f;
- scale[1] = 1.0f;
- scale[2] = 1.0f;
- }
- else {
- scale[0] = 1.0f / len_v3(ob->obmat[0]);
- scale[1] = 1.0f / len_v3(ob->obmat[1]);
- scale[2] = 1.0f / len_v3(ob->obmat[2]);
- }
-
- float drawsize;
- BKE_camera_view_frame_ex(scene, cam, cam->drawsize, is_view, scale,
- asp, shift, &drawsize, vec);
-
- glDisable(GL_CULL_FACE);
- glLineWidth(1);
-
- /* camera frame */
- if (!is_stereo3d_cameras) {
- /* make sure selection uses the same matrix for camera as the one used while viewing */
- if (is_selection_camera_stereo) {
- float obmat[4][4];
- bool is_left = v3d->multiview_eye == STEREO_LEFT_ID;
-
- glPushMatrix();
- glLoadMatrixf(rv3d->viewmat);
- BKE_camera_multiview_model_matrix(&scene->r, ob, is_left ? STEREO_LEFT_NAME : STEREO_RIGHT_NAME, obmat);
- glMultMatrixf(obmat);
-
- drawcamera_frame(vec, GL_LINE_LOOP);
- glPopMatrix();
- }
- else {
- drawcamera_frame(vec, GL_LINE_LOOP);
- }
- }
-
- if (is_view)
- return;
-
- zero_v3(tvec);
-
- /* center point to camera frame */
- if (!is_stereo3d_cameras)
- drawcamera_framelines(vec, tvec);
-
- /* arrow on top */
- tvec[2] = vec[1][2]; /* copy the depth */
-
- /* draw an outline arrow for inactive cameras and filled
- * for active cameras. We actually draw both outline+filled
- * for active cameras so the wire can be seen side-on */
- for (int i = 0; i < 2; i++) {
- if (i == 0) glBegin(GL_LINE_LOOP);
- else if (i == 1 && is_active) glBegin(GL_TRIANGLES);
- else break;
-
- tvec[0] = shift[0] + ((-0.7f * drawsize) * scale[0]);
- tvec[1] = shift[1] + ((drawsize * (asp[1] + 0.1f)) * scale[1]);
- glVertex3fv(tvec); /* left */
-
- tvec[0] = shift[0] + ((0.7f * drawsize) * scale[0]);
- glVertex3fv(tvec); /* right */
-
- tvec[0] = shift[0];
- tvec[1] = shift[1] + ((1.1f * drawsize * (asp[1] + 0.7f)) * scale[1]);
- glVertex3fv(tvec); /* top */
-
- glEnd();
- }
-
- if ((dflag & DRAW_SCENESET) == 0) {
- if (cam->flag & (CAM_SHOWLIMITS | CAM_SHOWMIST)) {
- float nobmat[4][4];
-
- /* draw in normalized object matrix space */
- copy_m4_m4(nobmat, ob->obmat);
- normalize_m4(nobmat);
-
- glPushMatrix();
- glLoadMatrixf(rv3d->viewmat);
- glMultMatrixf(nobmat);
-
- if (cam->flag & CAM_SHOWLIMITS) {
- const unsigned char col[3] = {128, 128, 60}, col_hi[3] = {255, 255, 120};
-
- draw_limit_line(cam->clipsta, cam->clipend, dflag, (is_active ? col_hi : col));
- /* qdn: was yafray only, now also enabled for Blender to be used with defocus composite node */
- draw_focus_cross(BKE_camera_object_dof_distance(ob), cam->drawsize);
- }
-
- if (cam->flag & CAM_SHOWMIST) {
- World *world = scene->world;
- const unsigned char col[3] = {128, 128, 128}, col_hi[3] = {255, 255, 255};
-
- if (world) {
- draw_limit_line(world->miststa, world->miststa + world->mistdist,
- dflag, (is_active ? col_hi : col));
- }
- }
- glPopMatrix();
- }
- }
-
- /* stereo cameras drawing */
- if (is_stereo3d) {
- drawcamera_stereo3d(scene, v3d, rv3d, ob, cam, vec, drawsize, scale);
- }
-}
-
-/* flag similar to draw_object() */
-static void drawspeaker(Scene *UNUSED(scene), View3D *UNUSED(v3d), RegionView3D *UNUSED(rv3d),
- Object *UNUSED(ob), int UNUSED(flag))
-{
- float vec[3];
-
- glEnable(GL_BLEND);
- glLineWidth(1);
-
- for (int j = 0; j < 3; j++) {
- vec[2] = 0.25f * j - 0.125f;
-
- glBegin(GL_LINE_LOOP);
- for (int i = 0; i < 16; i++) {
- vec[0] = cosf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
- vec[1] = sinf((float)M_PI * i / 8.0f) * (j == 0 ? 0.5f : 0.25f);
- glVertex3fv(vec);
- }
- glEnd();
- }
-
- for (int j = 0; j < 4; j++) {
- vec[0] = (((j + 1) % 2) * (j - 1)) * 0.5f;
- vec[1] = ((j % 2) * (j - 2)) * 0.5f;
- glBegin(GL_LINE_STRIP);
- for (int i = 0; i < 3; i++) {
- if (i == 1) {
- vec[0] *= 0.5f;
- vec[1] *= 0.5f;
- }
-
- vec[2] = 0.25f * i - 0.125f;
- glVertex3fv(vec);
- }
- glEnd();
- }
-
- glDisable(GL_BLEND);
-}
-
-static void lattice_draw_verts(Lattice *lt, DispList *dl, BPoint *actbp, short sel)
-{
- BPoint *bp = lt->def;
- const float *co = dl ? dl->verts : NULL;
-
- const int color = sel ? TH_VERTEX_SELECT : TH_VERTEX;
- UI_ThemeColor(color);
-
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
- glBegin(GL_POINTS);
-
- for (int w = 0; w < lt->pntsw; w++) {
- int wxt = (w == 0 || w == lt->pntsw - 1);
- for (int v = 0; v < lt->pntsv; v++) {
- int vxt = (v == 0 || v == lt->pntsv - 1);
- for (int u = 0; u < lt->pntsu; u++, bp++, co += 3) {
- int uxt = (u == 0 || u == lt->pntsu - 1);
- if (!(lt->flag & LT_OUTSIDE) || uxt || vxt || wxt) {
- if (bp->hide == 0) {
- /* check for active BPoint and ensure selected */
- if ((bp == actbp) && (bp->f1 & SELECT)) {
- UI_ThemeColor(TH_ACTIVE_VERT);
- glVertex3fv(dl ? co : bp->vec);
- UI_ThemeColor(color);
- }
- else if ((bp->f1 & SELECT) == sel) {
- glVertex3fv(dl ? co : bp->vec);
- }
- }
- }
- }
- }
- }
-
- glEnd();
-}
-
-static void drawlattice__point(Lattice *lt, DispList *dl, int u, int v, int w, int actdef_wcol)
-{
- int index = ((w * lt->pntsv + v) * lt->pntsu) + u;
-
- if (actdef_wcol) {
- float col[3];
- MDeformWeight *mdw = defvert_find_index(lt->dvert + index, actdef_wcol - 1);
-
- weight_to_rgb(col, mdw ? mdw->weight : 0.0f);
- glColor3fv(col);
-
- }
-
- if (dl) {
- glVertex3fv(&dl->verts[index * 3]);
- }
- else {
- glVertex3fv(lt->def[index].vec);
- }
-}
-
-#ifdef SEQUENCER_DAG_WORKAROUND
-static void ensure_curve_cache(Scene *scene, Object *object)
-{
- bool need_recalc = object->curve_cache == NULL;
- /* Render thread might have freed the curve cache if the
- * object is not visible. If the object is also used for
- * particles duplication, then render thread might have
- * also created curve_cache with only bevel and path
- * filled in.
- *
- * So check for curve_cache != NULL is not fully correct
- * here, we also need to check whether display list is
- * empty or not.
- *
- * The trick below tries to optimize calls to displist
- * creation for cases curve is empty. Meaning, if the curve
- * is empty (without splines) bevel list would also be empty.
- * And the thing is, render thread always leaves bevel list
- * in a proper state. So if bevel list is here and display
- * list is not we need to make display list.
- */
- if (need_recalc == false) {
- need_recalc = object->curve_cache->disp.first == NULL &&
- object->curve_cache->bev.first != NULL;
- }
- if (need_recalc) {
- switch (object->type) {
- case OB_CURVE:
- case OB_SURF:
- case OB_FONT:
- BKE_displist_make_curveTypes(scene, object, false);
- break;
- case OB_MBALL:
- BKE_displist_make_mball(G.main->eval_ctx, scene, object);
- break;
- case OB_LATTICE:
- BKE_lattice_modifiers_calc(scene, object);
- break;
- }
- }
-}
-#endif
-
-/* lattice color is hardcoded, now also shows weightgroup values in edit mode */
-static void drawlattice(View3D *v3d, Object *ob)
-{
- Lattice *lt = ob->data;
- DispList *dl;
- int u, v, w;
- int actdef_wcol = 0;
- const bool is_edit = (lt->editlatt != NULL);
-
- dl = BKE_displist_find(&ob->curve_cache->disp, DL_VERTS);
-
- if (is_edit) {
- lt = lt->editlatt->latt;
-
- UI_ThemeColor(TH_WIRE_EDIT);
-
- if (ob->defbase.first && lt->dvert) {
- actdef_wcol = ob->actdef;
- }
- }
-
- glLineWidth(1);
- glBegin(GL_LINES);
- for (w = 0; w < lt->pntsw; w++) {
- int wxt = (w == 0 || w == lt->pntsw - 1);
- for (v = 0; v < lt->pntsv; v++) {
- int vxt = (v == 0 || v == lt->pntsv - 1);
- for (u = 0; u < lt->pntsu; u++) {
- int uxt = (u == 0 || u == lt->pntsu - 1);
-
- if (w && ((uxt || vxt) || !(lt->flag & LT_OUTSIDE))) {
- drawlattice__point(lt, dl, u, v, w - 1, actdef_wcol);
- drawlattice__point(lt, dl, u, v, w, actdef_wcol);
- }
- if (v && ((uxt || wxt) || !(lt->flag & LT_OUTSIDE))) {
- drawlattice__point(lt, dl, u, v - 1, w, actdef_wcol);
- drawlattice__point(lt, dl, u, v, w, actdef_wcol);
- }
- if (u && ((vxt || wxt) || !(lt->flag & LT_OUTSIDE))) {
- drawlattice__point(lt, dl, u - 1, v, w, actdef_wcol);
- drawlattice__point(lt, dl, u, v, w, actdef_wcol);
- }
- }
- }
- }
- glEnd();
-
- if (is_edit) {
- BPoint *actbp = BKE_lattice_active_point_get(lt);
-
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
-
- lattice_draw_verts(lt, dl, actbp, 0);
- lattice_draw_verts(lt, dl, actbp, 1);
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- }
-}
-
-/* ***************** ******************** */
-
-/* draw callback */
-
-typedef struct drawDMVertSel_userData {
- MVert *mvert;
- int active;
- unsigned char *col[3]; /* (base, sel, act) */
- char sel_prev;
-} drawDMVertSel_userData;
+/* ***************** BACKBUF SEL (BBS) ********* */
-static void drawSelectedVertices__mapFunc(void *userData, int index, const float co[3],
- const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
+#ifdef USE_MESH_DM_SELECT
+static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, const float co[3],
+ const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
{
- drawDMVertSel_userData *data = userData;
+ drawMVertOffset_userData *data = userData;
MVert *mv = &data->mvert[index];
if (!(mv->flag & ME_HIDE)) {
- const char sel = (index == data->active) ? 2 : (mv->flag & SELECT);
- if (sel != data->sel_prev) {
- glColor3ubv(data->col[sel]);
- data->sel_prev = sel;
- }
-
- glVertex3fv(co);
+ int selcol;
+ GPU_select_index_get(data->offset + index, &selcol);
+ immAttrib1u(data->col, selcol);
+ immVertex3fv(data->pos, co);
}
}
-static void drawSelectedVertices(DerivedMesh *dm, Mesh *me)
-{
- drawDMVertSel_userData data;
-
- /* TODO define selected color */
- unsigned char base_col[3] = {0x0, 0x0, 0x0};
- unsigned char sel_col[3] = {0xd8, 0xb8, 0x0};
- unsigned char act_col[3] = {0xff, 0xff, 0xff};
-
- data.mvert = me->mvert;
- data.active = BKE_mesh_mselect_active_get(me, ME_VSEL);
- data.sel_prev = 0xff;
-
- data.col[0] = base_col;
- data.col[1] = sel_col;
- data.col[2] = act_col;
-
- glBegin(GL_POINTS);
- dm->foreachMappedVert(dm, drawSelectedVertices__mapFunc, &data, DM_FOREACH_NOP);
- glEnd();
-}
-
-/* ************** DRAW MESH ****************** */
-
-/* First section is all the "simple" draw routines,
- * ones that just pass some sort of primitive to GL,
- * with perhaps various options to control lighting,
- * color, etc.
- *
- * These routines should not have user interface related
- * logic!!!
- */
-
-static void calcDrawDMNormalScale(Object *ob, drawDMNormal_userData *data)
-{
- float obmat[3][3];
-
- copy_m3_m4(obmat, ob->obmat);
-
- data->uniform_scale = is_uniform_scaled_m3(obmat);
-
- if (!data->uniform_scale) {
- /* inverted matrix */
- invert_m3_m3(data->imat, obmat);
-
- /* transposed inverted matrix */
- transpose_m3_m3(data->tmat, data->imat);
- }
-}
-
-static void draw_dm_face_normals__mapFunc(void *userData, int index, const float cent[3], const float no[3])
+static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset)
{
- drawDMNormal_userData *data = userData;
- BMFace *efa = BM_face_at_index(data->bm, index);
- float n[3];
+ drawMVertOffset_userData data;
+ Mesh *me = ob->data;
+ MVert *mvert = me->mvert;
+ data.mvert = mvert;
+ data.offset = offset;
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- if (!data->uniform_scale) {
- mul_v3_m3v3(n, data->tmat, no);
- normalize_v3(n);
- mul_m3_v3(data->imat, n);
- }
- else {
- copy_v3_v3(n, no);
- }
+ const int imm_len = dm->getNumVerts(dm);
- glVertex3fv(cent);
- glVertex3f(cent[0] + n[0] * data->normalsize,
- cent[1] + n[1] * data->normalsize,
- cent[2] + n[2] * data->normalsize);
- }
-}
+ if (imm_len == 0) return;
-static void draw_dm_face_normals(BMEditMesh *em, Scene *scene, Object *ob, DerivedMesh *dm)
-{
- drawDMNormal_userData data;
+ Gwn_VertFormat *format = immVertexFormat();
+ data.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ data.col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U32, 1, GWN_FETCH_INT);
- data.bm = em->bm;
- data.normalsize = scene->toolsettings->normalsize;
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR_U32);
- calcDrawDMNormalScale(ob, &data);
+ glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
- glBegin(GL_LINES);
- dm->foreachMappedFaceCenter(dm, draw_dm_face_normals__mapFunc, &data, DM_FOREACH_USE_NORMAL);
- glEnd();
-}
+ immBeginAtMost(GWN_PRIM_POINTS, imm_len);
+ dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, &data, DM_FOREACH_NOP);
+ immEnd();
-static void draw_dm_face_centers__mapFunc(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
-{
- drawBMSelect_userData *data = userData;
- BMFace *efa = BM_face_at_index(data->bm, index);
-
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN) &&
- (BM_elem_flag_test(efa, BM_ELEM_SELECT) == data->select))
- {
- glVertex3fv(cent);
- }
+ immUnbindProgram();
}
-static void draw_dm_face_centers(BMEditMesh *em, DerivedMesh *dm, bool select)
+#else
+static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *UNUSED(dm), int offset)
{
- drawBMSelect_userData data = {em->bm, select};
-
- glBegin(GL_POINTS);
- dm->foreachMappedFaceCenter(dm, draw_dm_face_centers__mapFunc, &data, DM_FOREACH_NOP);
- glEnd();
+ Mesh *me = ob->data;
+ Gwn_Batch *batch = DRW_mesh_batch_cache_get_verts_with_select_id(me, offset);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_FLAT_COLOR_U32);
+ GWN_batch_draw(batch);
}
+#endif
-static void draw_dm_vert_normals__mapFunc(void *userData, int index, const float co[3], const float no_f[3], const short no_s[3])
+#ifdef USE_MESH_DM_SELECT
+static void bbs_mesh_verts__mapFunc(void *userData, int index, const float co[3],
+ const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
{
- drawDMNormal_userData *data = userData;
+ drawBMOffset_userData *data = userData;
BMVert *eve = BM_vert_at_index(data->bm, index);
if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
- float no[3], n[3];
-
- if (no_f) {
- copy_v3_v3(no, no_f);
- }
- else {
- normal_short_to_float_v3(no, no_s);
- }
-
- if (!data->uniform_scale) {
- mul_v3_m3v3(n, data->tmat, no);
- normalize_v3(n);
- mul_m3_v3(data->imat, n);
- }
- else {
- copy_v3_v3(n, no);
- }
-
- glVertex3fv(co);
- glVertex3f(co[0] + n[0] * data->normalsize,
- co[1] + n[1] * data->normalsize,
- co[2] + n[2] * data->normalsize);
+ int selcol;
+ GPU_select_index_get(data->offset + index, &selcol);
+ immAttrib1u(data->col, selcol);
+ immVertex3fv(data->pos, co);
}
}
-
-static void draw_dm_vert_normals(BMEditMesh *em, Scene *scene, Object *ob, DerivedMesh *dm)
-{
- drawDMNormal_userData data;
-
- data.bm = em->bm;
- data.normalsize = scene->toolsettings->normalsize;
-
- calcDrawDMNormalScale(ob, &data);
-
- glBegin(GL_LINES);
- dm->foreachMappedVert(dm, draw_dm_vert_normals__mapFunc, &data, DM_FOREACH_USE_NORMAL);
- glEnd();
-}
-
-/* Draw verts with color set based on selection */
-static void draw_dm_verts__mapFunc(void *userData, int index, const float co[3],
- const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
-{
- drawDMVerts_userData *data = userData;
- BMVert *eve = BM_vert_at_index(data->bm, index);
-
- if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN) && BM_elem_flag_test(eve, BM_ELEM_SELECT) == data->sel) {
- /* skin nodes: draw a red circle around the root node(s) */
- if (data->cd_vskin_offset != -1) {
- const MVertSkin *vs = BM_ELEM_CD_GET_VOID_P(eve, data->cd_vskin_offset);
- if (vs->flag & MVERT_SKIN_ROOT) {
- float radius = (vs->radius[0] + vs->radius[1]) * 0.5f;
- glEnd();
-
- glColor4ubv(data->th_skin_root);
- drawcircball(GL_LINES, co, radius, data->imat);
-
- glColor4ubv(data->sel ? data->th_vertex_select : data->th_vertex);
- glBegin(GL_POINTS);
- }
- }
-
- /* draw active in a different color - no need to stop/start point drawing for this :D */
- if (eve == data->eve_act) {
- glColor4ubv(data->th_editmesh_active);
- glVertex3fv(co);
-
- /* back to regular vertex color */
- glColor4ubv(data->sel ? data->th_vertex_select : data->th_vertex);
- }
- else {
- glVertex3fv(co);
- }
- }
-}
-
-static void draw_dm_verts(BMEditMesh *em, DerivedMesh *dm, const char sel, BMVert *eve_act,
- RegionView3D *rv3d)
+static void bbs_mesh_verts(BMEditMesh *em, DerivedMesh *dm, int offset)
{
- drawDMVerts_userData data;
- data.sel = sel;
- data.eve_act = eve_act;
+ drawBMOffset_userData data;
data.bm = em->bm;
+ data.offset = offset;
+ Gwn_VertFormat *format = immVertexFormat();
+ data.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ data.col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U32, 1, GWN_FETCH_INT);
- /* Cache theme values */
- UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, data.th_editmesh_active);
- UI_GetThemeColor4ubv(TH_VERTEX_SELECT, data.th_vertex_select);
- UI_GetThemeColor4ubv(TH_VERTEX, data.th_vertex);
- UI_GetThemeColor4ubv(TH_SKIN_ROOT, data.th_skin_root);
-
- /* For skin root drawing */
- data.cd_vskin_offset = CustomData_get_offset(&em->bm->vdata, CD_MVERT_SKIN);
- /* view-aligned matrix */
- mul_m4_m4m4(data.imat, rv3d->viewmat, em->ob->obmat);
- invert_m4(data.imat);
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR_U32);
glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
- glBegin(GL_POINTS);
- dm->foreachMappedVert(dm, draw_dm_verts__mapFunc, &data, DM_FOREACH_NOP);
- glEnd();
-}
-/* Draw edges with color set based on selection */
-static DMDrawOption draw_dm_edges_sel__setDrawOptions(void *userData, int index)
-{
- BMEdge *eed;
- drawDMEdgesSel_userData *data = userData;
- unsigned char *col;
-
- eed = BM_edge_at_index(data->bm, index);
-
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- if (eed == data->eed_act) {
- glColor4ubv(data->actCol);
- }
- else {
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) {
- col = data->selCol;
- }
- else {
- col = data->baseCol;
- }
- /* no alpha, this is used so a transparent color can disable drawing unselected edges in editmode */
- if (col[3] == 0)
- return DM_DRAW_OPTION_SKIP;
-
- glColor4ubv(col);
- }
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
- }
-}
-
-static void draw_dm_edges_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
- unsigned char *selCol, unsigned char *actCol, BMEdge *eed_act)
-{
- drawDMEdgesSel_userData data;
-
- data.baseCol = baseCol;
- data.selCol = selCol;
- data.actCol = actCol;
- data.bm = em->bm;
- data.eed_act = eed_act;
- dm->drawMappedEdges(dm, draw_dm_edges_sel__setDrawOptions, &data);
-}
-
-/* Draw edges */
-static DMDrawOption draw_dm_edges__setDrawOptions(void *userData, int index)
-{
- if (BM_elem_flag_test(BM_edge_at_index(userData, index), BM_ELEM_HIDDEN))
- return DM_DRAW_OPTION_SKIP;
- else
- return DM_DRAW_OPTION_NORMAL;
-}
-
-static void draw_dm_edges(BMEditMesh *em, DerivedMesh *dm)
-{
- dm->drawMappedEdges(dm, draw_dm_edges__setDrawOptions, em->bm);
-}
-
-/* Draw edges with color interpolated based on selection */
-static DMDrawOption draw_dm_edges_sel_interp__setDrawOptions(void *userData, int index)
-{
- drawDMEdgesSelInterp_userData *data = userData;
- if (BM_elem_flag_test(BM_edge_at_index(data->bm, index), BM_ELEM_HIDDEN))
- return DM_DRAW_OPTION_SKIP;
- else
- return DM_DRAW_OPTION_NORMAL;
-}
-static void draw_dm_edges_sel_interp__setDrawInterpOptions(void *userData, int index, float t)
-{
- drawDMEdgesSelInterp_userData *data = userData;
- BMEdge *eed = BM_edge_at_index(data->bm, index);
- unsigned char **cols = userData;
- unsigned int col0_id = (BM_elem_flag_test(eed->v1, BM_ELEM_SELECT)) ? 2 : 1;
- unsigned int col1_id = (BM_elem_flag_test(eed->v2, BM_ELEM_SELECT)) ? 2 : 1;
- unsigned char *col0 = cols[col0_id];
- unsigned char *col1 = cols[col1_id];
- unsigned char *col_pt;
-
- if (col0_id == col1_id) {
- col_pt = col0;
- }
- else if (t == 0.0f) {
- col_pt = col0;
- }
- else if (t == 1.0f) {
- col_pt = col1;
- }
- else {
- unsigned char col_blend[4];
- interp_v4_v4v4_uchar(col_blend, col0, col1, t);
- glColor4ubv(col_blend);
- data->lastCol = NULL;
- return;
- }
-
- if (data->lastCol != col_pt) {
- data->lastCol = col_pt;
- glColor4ubv(col_pt);
- }
-}
-
-static void draw_dm_edges_sel_interp(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol, unsigned char *selCol)
-{
- drawDMEdgesSelInterp_userData data;
- data.bm = em->bm;
- data.baseCol = baseCol;
- data.selCol = selCol;
- data.lastCol = NULL;
+ immBeginAtMost(GWN_PRIM_POINTS, em->bm->totvert);
+ dm->foreachMappedVert(dm, bbs_mesh_verts__mapFunc, &data, DM_FOREACH_NOP);
+ immEnd();
- dm->drawMappedEdgesInterp(dm, draw_dm_edges_sel_interp__setDrawOptions, draw_dm_edges_sel_interp__setDrawInterpOptions, &data);
+ immUnbindProgram();
}
-
-static void bm_color_from_weight(float col[3], BMVert *vert, drawDMEdgesWeightInterp_userData *data)
+#else
+static void bbs_mesh_verts(BMEditMesh *em, DerivedMesh *UNUSED(dm), int offset)
{
- MDeformVert *dvert = BM_ELEM_CD_GET_VOID_P(vert, data->cd_dvert_offset);
- float weight = defvert_find_weight(dvert, data->vgroup_index);
-
- if ((weight == 0.0f) &&
- ((data->weight_user == OB_DRAW_GROUPUSER_ACTIVE) ||
- ((data->weight_user == OB_DRAW_GROUPUSER_ALL) && defvert_is_weight_zero(dvert, data->defgroup_tot))))
- {
- copy_v3_v3(col, data->alert_color);
- }
- else {
- weight_to_rgb(col, weight);
- }
-}
+ glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
-static void draw_dm_edges_nop_interp__setDrawInterpOptions(void *UNUSED(userData), int UNUSED(index), float UNUSED(t))
-{
- /* pass */
+ Mesh *me = em->ob->data;
+ Gwn_Batch *batch = DRW_mesh_batch_cache_get_verts_with_select_id(me, offset);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_FLAT_COLOR_U32);
+ GWN_batch_draw(batch);
}
+#endif
-static void draw_dm_edges_weight_interp__setDrawInterpOptions(void *userData, int index, float t)
+#ifdef USE_MESH_DM_SELECT
+static void bbs_mesh_wire__mapFunc(void *userData, int index, const float v0co[3], const float v1co[3])
{
- drawDMEdgesWeightInterp_userData *data = userData;
+ drawBMOffset_userData *data = userData;
BMEdge *eed = BM_edge_at_index(data->bm, index);
- float col[3];
-
- if (t == 0.0f) {
- bm_color_from_weight(col, eed->v1, data);
- }
- else if (t == 1.0f) {
- bm_color_from_weight(col, eed->v2, data);
- }
- else {
- float col_v1[3];
- float col_v2[3];
- bm_color_from_weight(col_v1, eed->v1, data);
- bm_color_from_weight(col_v2, eed->v2, data);
- interp_v3_v3v3(col, col_v1, col_v2, t);
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ int selcol;
+ GPU_select_index_get(data->offset + index, &selcol);
+ immAttrib1u(data->col, selcol);
+ immVertex3fv(data->pos, v0co);
+ immVertex3fv(data->pos, v1co);
}
-
- glColor3fv(col);
}
-static void draw_dm_edges_weight_interp(BMEditMesh *em, DerivedMesh *dm, const char weight_user)
+static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *dm, int offset)
{
- drawDMEdgesWeightInterp_userData data;
- Object *ob = em->ob;
-
+ drawBMOffset_userData data;
data.bm = em->bm;
- data.cd_dvert_offset = CustomData_get_offset(&em->bm->vdata, CD_MDEFORMVERT);
- data.defgroup_tot = BLI_listbase_count(&ob->defbase);
- data.vgroup_index = ob->actdef - 1;
- data.weight_user = weight_user;
- UI_GetThemeColor3fv(TH_VERTEX_UNREFERENCED, data.alert_color);
-
- if ((data.vgroup_index != -1) && (data.cd_dvert_offset != -1)) {
- glEnable(GL_BLEND);
- dm->drawMappedEdgesInterp(
- dm,
- draw_dm_edges_sel_interp__setDrawOptions,
- draw_dm_edges_weight_interp__setDrawInterpOptions,
- &data);
- glDisable(GL_BLEND);
- }
- else {
- float col[3];
-
- if (data.weight_user == OB_DRAW_GROUPUSER_NONE) {
- weight_to_rgb(col, 0.0f);
- }
- else {
- copy_v3_v3(col, data.alert_color);
- }
- glColor3fv(col);
-
- dm->drawMappedEdgesInterp(
- dm,
- draw_dm_edges_sel_interp__setDrawOptions,
- draw_dm_edges_nop_interp__setDrawInterpOptions,
- &data);
- }
-
-}
-
-static bool draw_dm_edges_weight_check(Mesh *me, View3D *v3d)
-{
- if (me->drawflag & ME_DRAWEIGHT) {
- if ((v3d->drawtype == OB_WIRE) ||
- (v3d->flag2 & V3D_SOLID_MATCAP) ||
- ((v3d->flag2 & V3D_OCCLUDE_WIRE) && (v3d->drawtype > OB_WIRE)))
- {
- return true;
- }
- }
-
- return false;
-}
-
-/* Draw only seam edges */
-static DMDrawOption draw_dm_edges_seams__setDrawOptions(void *userData, int index)
-{
- BMEdge *eed = BM_edge_at_index(userData, index);
-
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && BM_elem_flag_test(eed, BM_ELEM_SEAM))
- return DM_DRAW_OPTION_NORMAL;
- else
- return DM_DRAW_OPTION_SKIP;
-}
-
-static void draw_dm_edges_seams(BMEditMesh *em, DerivedMesh *dm)
-{
- dm->drawMappedEdges(dm, draw_dm_edges_seams__setDrawOptions, em->bm);
-}
-
-/* Draw only sharp edges */
-static DMDrawOption draw_dm_edges_sharp__setDrawOptions(void *userData, int index)
-{
- BMEdge *eed = BM_edge_at_index(userData, index);
-
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && !BM_elem_flag_test(eed, BM_ELEM_SMOOTH))
- return DM_DRAW_OPTION_NORMAL;
- else
- return DM_DRAW_OPTION_SKIP;
-}
-
-static void draw_dm_edges_sharp(BMEditMesh *em, DerivedMesh *dm)
-{
- dm->drawMappedEdges(dm, draw_dm_edges_sharp__setDrawOptions, em->bm);
-}
+ data.offset = offset;
-#ifdef WITH_FREESTYLE
+ Gwn_VertFormat *format = immVertexFormat();
-static bool draw_dm_test_freestyle_edge_mark(BMesh *bm, BMEdge *eed)
-{
- FreestyleEdge *fed = CustomData_bmesh_get(&bm->edata, eed->head.data, CD_FREESTYLE_EDGE);
- if (!fed)
- return false;
- return (fed->flag & FREESTYLE_EDGE_MARK) != 0;
-}
+ const int imm_len = dm->getNumEdges(dm) * 2;
-/* Draw only Freestyle feature edges */
-static DMDrawOption draw_dm_edges_freestyle__setDrawOptions(void *userData, int index)
-{
- BMEdge *eed = BM_edge_at_index(userData, index);
+ if (imm_len == 0) return;
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && draw_dm_test_freestyle_edge_mark(userData, eed))
- return DM_DRAW_OPTION_NORMAL;
- else
- return DM_DRAW_OPTION_SKIP;
-}
+ data.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ data.col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U32, 1, GWN_FETCH_INT);
-static void draw_dm_edges_freestyle(BMEditMesh *em, DerivedMesh *dm)
-{
- dm->drawMappedEdges(dm, draw_dm_edges_freestyle__setDrawOptions, em->bm);
-}
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR_U32);
-static bool draw_dm_test_freestyle_face_mark(BMesh *bm, BMFace *efa)
-{
- FreestyleFace *ffa = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_FREESTYLE_FACE);
- if (!ffa)
- return false;
- return (ffa->flag & FREESTYLE_FACE_MARK) != 0;
-}
-
-#endif
-
-/* Draw loop normals. */
-static void draw_dm_loop_normals__mapFunc(void *userData, int vertex_index, int face_index,
- const float co[3], const float no[3])
-{
- if (no) {
- const drawDMNormal_userData *data = userData;
- const BMVert *eve = BM_vert_at_index(data->bm, vertex_index);
- const BMFace *efa = BM_face_at_index(data->bm, face_index);
- float vec[3];
-
- if (!(BM_elem_flag_test(eve, BM_ELEM_HIDDEN) || BM_elem_flag_test(efa, BM_ELEM_HIDDEN))) {
- if (!data->uniform_scale) {
- mul_v3_m3v3(vec, (float(*)[3])data->tmat, no);
- normalize_v3(vec);
- mul_m3_v3((float(*)[3])data->imat, vec);
- }
- else {
- copy_v3_v3(vec, no);
- }
- mul_v3_fl(vec, data->normalsize);
- add_v3_v3(vec, co);
- glVertex3fv(co);
- glVertex3fv(vec);
- }
- }
-}
-
-static void draw_dm_loop_normals(BMEditMesh *em, Scene *scene, Object *ob, DerivedMesh *dm)
-{
- drawDMNormal_userData data;
-
- data.bm = em->bm;
- data.normalsize = scene->toolsettings->normalsize;
+ glLineWidth(1.0f);
- calcDrawDMNormalScale(ob, &data);
+ immBeginAtMost(GWN_PRIM_LINES, imm_len);
+ dm->foreachMappedEdge(dm, bbs_mesh_wire__mapFunc, &data);
+ immEnd();
- glBegin(GL_LINES);
- dm->foreachMappedLoop(dm, draw_dm_loop_normals__mapFunc, &data, DM_FOREACH_USE_NORMAL);
- glEnd();
+ immUnbindProgram();
}
-
-/* Draw faces with color set based on selection
- * return 2 for the active face so it renders with stipple enabled */
-static DMDrawOption draw_dm_faces_sel__setDrawOptions(void *userData, int index)
-{
- drawDMFacesSel_userData *data = userData;
- BMFace *efa = BM_face_at_index(data->bm, index);
- unsigned char *col;
-
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- if (efa == data->efa_act) {
- glColor4ubv(data->cols[2]);
- return DM_DRAW_OPTION_STIPPLE;
- }
- else {
-#ifdef WITH_FREESTYLE
- col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->bm, efa) ? 3 : 0];
#else
- col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
-#endif
- if (col[3] == 0)
- return DM_DRAW_OPTION_SKIP;
- glColor4ubv(col);
- return DM_DRAW_OPTION_NORMAL;
- }
- }
- return DM_DRAW_OPTION_SKIP;
-}
-
-static int draw_dm_faces_sel__compareDrawOptions(void *userData, int index, int next_index)
+static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *UNUSED(dm), int offset)
{
+ glLineWidth(1.0f);
- drawDMFacesSel_userData *data = userData;
- int i;
- BMFace *efa;
- BMFace *next_efa;
-
- unsigned char *col, *next_col;
-
- i = data->orig_index_mp_to_orig ? data->orig_index_mp_to_orig[index] : index;
- efa = (i != ORIGINDEX_NONE) ? BM_face_at_index(data->bm, i) : NULL;
- i = data->orig_index_mp_to_orig ? data->orig_index_mp_to_orig[next_index] : next_index;
- next_efa = (i != ORIGINDEX_NONE) ? BM_face_at_index(data->bm, i) : NULL;
-
- if (ELEM(NULL, efa, next_efa))
- return 0;
-
- if (efa == next_efa)
- return 1;
-
- if (efa == data->efa_act || next_efa == data->efa_act)
- return 0;
-
-#ifdef WITH_FREESTYLE
- col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->bm, efa) ? 3 : 0];
- next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : draw_dm_test_freestyle_face_mark(data->bm, efa) ? 3 : 0];
-#else
- col = data->cols[BM_elem_flag_test(efa, BM_ELEM_SELECT) ? 1 : 0];
- next_col = data->cols[BM_elem_flag_test(next_efa, BM_ELEM_SELECT) ? 1 : 0];
-#endif
-
- if (col[3] == 0 || next_col[3] == 0)
- return 0;
-
- return col == next_col;
+ Mesh *me = em->ob->data;
+ Gwn_Batch *batch = DRW_mesh_batch_cache_get_edges_with_select_id(me, offset);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_FLAT_COLOR_U32);
+ GWN_batch_draw(batch);
}
-
-/* also draws the active face */
-#ifdef WITH_FREESTYLE
-static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
- unsigned char *selCol, unsigned char *actCol, unsigned char *markCol, BMFace *efa_act)
-#else
-static void draw_dm_faces_sel(BMEditMesh *em, DerivedMesh *dm, unsigned char *baseCol,
- unsigned char *selCol, unsigned char *actCol, BMFace *efa_act)
#endif
-{
- drawDMFacesSel_userData data;
- data.dm = dm;
- data.cols[0] = baseCol;
- data.bm = em->bm;
- data.cols[1] = selCol;
- data.cols[2] = actCol;
-#ifdef WITH_FREESTYLE
- data.cols[3] = markCol;
-#endif
- data.efa_act = efa_act;
- /* double lookup */
- data.orig_index_mp_to_orig = DM_get_poly_data_layer(dm, CD_ORIGINDEX);
-
- dm->drawMappedFaces(dm, draw_dm_faces_sel__setDrawOptions, NULL, draw_dm_faces_sel__compareDrawOptions, &data, DM_DRAW_SKIP_HIDDEN);
-}
-static DMDrawOption draw_dm_creases__setDrawOptions(void *userData, int index)
-{
- drawDMLayer_userData *data = userData;
- BMesh *bm = data->bm;
- BMEdge *eed = BM_edge_at_index(bm, index);
-
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- const float crease = BM_ELEM_CD_GET_FLOAT(eed, data->cd_layer_offset);
- if (crease != 0.0f) {
- UI_ThemeColorBlend(TH_WIRE_EDIT, TH_EDGE_CREASE, crease);
- return DM_DRAW_OPTION_NORMAL;
- }
- }
- return DM_DRAW_OPTION_SKIP;
-}
-static void draw_dm_creases(BMEditMesh *em, DerivedMesh *dm)
+#ifdef USE_MESH_DM_SELECT
+static void bbs_mesh_face(BMEditMesh *em, DerivedMesh *dm, const bool use_select)
{
- drawDMLayer_userData data;
+ UNUSED_VARS(dm);
+ drawBMOffset_userData data;
data.bm = em->bm;
- data.cd_layer_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE);
-
- if (data.cd_layer_offset != -1) {
- glLineWidth(3.0);
- dm->drawMappedEdges(dm, draw_dm_creases__setDrawOptions, &data);
- }
-}
-
-static DMDrawOption draw_dm_bweights__setDrawOptions(void *userData, int index)
-{
- drawDMLayer_userData *data = userData;
- BMesh *bm = data->bm;
- BMEdge *eed = BM_edge_at_index(bm, index);
-
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- const float bweight = BM_ELEM_CD_GET_FLOAT(eed, data->cd_layer_offset);
- if (bweight != 0.0f) {
- UI_ThemeColorBlend(TH_WIRE_EDIT, TH_EDGE_BEVEL, bweight);
- return DM_DRAW_OPTION_NORMAL;
- }
- }
- return DM_DRAW_OPTION_SKIP;
-}
-static void draw_dm_bweights__mapFunc(void *userData, int index, const float co[3],
- const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
-{
- drawDMLayer_userData *data = userData;
- BMesh *bm = data->bm;
- BMVert *eve = BM_vert_at_index(bm, index);
-
- if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
- const float bweight = BM_ELEM_CD_GET_FLOAT(eve, data->cd_layer_offset);
- if (bweight != 0.0f) {
- UI_ThemeColorBlend(TH_VERTEX, TH_VERTEX_BEVEL, bweight);
- glVertex3fv(co);
- }
- }
-}
-static void draw_dm_bweights(BMEditMesh *em, Scene *scene, DerivedMesh *dm)
-{
- ToolSettings *ts = scene->toolsettings;
-
- if (ts->selectmode & SCE_SELECT_VERTEX) {
- drawDMLayer_userData data;
-
- data.bm = em->bm;
- data.cd_layer_offset = CustomData_get_offset(&em->bm->vdata, CD_BWEIGHT);
-
- if (data.cd_layer_offset != -1) {
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE) + 2);
- glBegin(GL_POINTS);
- dm->foreachMappedVert(dm, draw_dm_bweights__mapFunc, &data, DM_FOREACH_NOP);
- glEnd();
- }
- }
- else {
- drawDMLayer_userData data;
-
- data.bm = em->bm;
- data.cd_layer_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT);
-
- if (data.cd_layer_offset != -1) {
- glLineWidth(3.0);
- dm->drawMappedEdges(dm, draw_dm_bweights__setDrawOptions, &data);
- }
- }
-}
-
-/* Second section of routines: Combine first sets to form fancy
- * drawing routines (for example rendering twice to get overlays).
- *
- * Also includes routines that are basic drawing but are too
- * specialized to be split out (like drawing creases or measurements).
- */
-
-/* EditMesh drawing routines */
-static void draw_em_fancy_verts(Scene *scene, View3D *v3d, Object *obedit,
- BMEditMesh *em, DerivedMesh *cageDM, BMVert *eve_act,
- RegionView3D *rv3d)
-{
- ToolSettings *ts = scene->toolsettings;
-
- if (v3d->zbuf) glDepthMask(0); /* disable write in zbuffer, zbuf select */
+ const int tri_len = em->tottri;
+ const int imm_len = tri_len * 3;
+ const char hflag_skip = use_select ? BM_ELEM_HIDDEN : (BM_ELEM_HIDDEN | BM_ELEM_SELECT);
- for (int sel = 0; sel < 2; sel++) {
- unsigned char col[4], fcol[4];
+ if (imm_len == 0) return;
- UI_GetThemeColor3ubv(sel ? TH_VERTEX_SELECT : TH_VERTEX, col);
- UI_GetThemeColor3ubv(sel ? TH_FACE_DOT : TH_WIRE_EDIT, fcol);
+ Gwn_VertFormat *format = immVertexFormat();
+ data.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ data.col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U32, 1, GWN_FETCH_INT);
- for (int pass = 0; pass < 2; pass++) {
- float size = UI_GetThemeValuef(TH_VERTEX_SIZE);
- float fsize = UI_GetThemeValuef(TH_FACEDOT_SIZE);
-
- if (pass == 0) {
- if (v3d->zbuf && !(v3d->flag & V3D_ZBUF_SELECT)) {
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_BLEND);
- }
- else {
- continue;
- }
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR_U32);
- size = (size > 2.1f ? size / 2.0f : size);
- fsize = (fsize > 2.1f ? fsize / 2.0f : fsize);
- col[3] = fcol[3] = 100;
- }
- else {
- col[3] = fcol[3] = 255;
- }
+ immBeginAtMost(GWN_PRIM_TRIS, imm_len);
- if (ts->selectmode & SCE_SELECT_VERTEX) {
- glPointSize(size);
- glColor4ubv(col);
- draw_dm_verts(em, cageDM, sel, eve_act, rv3d);
- }
-
- if (check_ob_drawface_dot(scene, v3d, obedit->dt)) {
- glPointSize(fsize);
- glColor4ubv(fcol);
- draw_dm_face_centers(em, cageDM, sel);
- }
-
- if (pass == 0) {
- glDisable(GL_BLEND);
- glEnable(GL_DEPTH_TEST);
- }
- }
+ if (use_select == false) {
+ int selcol;
+ GPU_select_index_get(0, &selcol);
+ immAttrib1u(data.col, selcol);
}
- if (v3d->zbuf) glDepthMask(1);
-}
-
-static void draw_em_fancy_edges(BMEditMesh *em, Scene *scene, View3D *v3d,
- Mesh *me, DerivedMesh *cageDM, short sel_only,
- BMEdge *eed_act)
-{
- ToolSettings *ts = scene->toolsettings;
- unsigned char wireCol[4], selCol[4], actCol[4];
-
- /* since this function does transparent... */
- UI_GetThemeColor4ubv(TH_EDGE_SELECT, selCol);
- UI_GetThemeColor4ubv(TH_WIRE_EDIT, wireCol);
- UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, actCol);
-
- /* when sel only is used, don't render wire, only selected, this is used for
- * textured draw mode when the 'edges' option is disabled */
- if (sel_only)
- wireCol[3] = 0;
-
- for (int pass = 0; pass < 2; pass++) {
- /* show wires in transparent when no zbuf clipping for select */
- if (pass == 0) {
- if (v3d->zbuf && (v3d->flag & V3D_ZBUF_SELECT) == 0) {
- glEnable(GL_BLEND);
- glDisable(GL_DEPTH_TEST);
- selCol[3] = 85;
- if (!sel_only) wireCol[3] = 85;
- }
- else {
- continue;
+ int index = 0;
+ while (index < tri_len) {
+ const BMFace *f = em->looptris[index][0]->f;
+ const int ntris = f->len - 2;
+ if (!BM_elem_flag_test(f, hflag_skip)) {
+ if (use_select) {
+ int selcol;
+ GPU_select_index_get(BM_elem_index_get(f) + 1, &selcol);
+ immAttrib1u(data.col, selcol);
+ }
+ for (int t = 0; t < ntris; t++) {
+ immVertex3fv(data.pos, em->looptris[index][0]->v->co);
+ immVertex3fv(data.pos, em->looptris[index][1]->v->co);
+ immVertex3fv(data.pos, em->looptris[index][2]->v->co);
+ index++;
}
}
else {
- selCol[3] = 255;
- if (!sel_only) wireCol[3] = 255;
- }
-
- if ((me->drawflag & ME_DRAWEDGES) || (ts->selectmode & SCE_SELECT_EDGE)) {
- if (cageDM->drawMappedEdgesInterp &&
- ((ts->selectmode & SCE_SELECT_VERTEX) || (me->drawflag & ME_DRAWEIGHT)))
- {
- if (draw_dm_edges_weight_check(me, v3d)) {
- // Interpolate vertex weights
- draw_dm_edges_weight_interp(em, cageDM, ts->weightuser);
- }
- else if (ts->selectmode == SCE_SELECT_FACE) {
- draw_dm_edges_sel(em, cageDM, wireCol, selCol, actCol, eed_act);
- }
- else {
- // Interpolate vertex selection
- draw_dm_edges_sel_interp(em, cageDM, wireCol, selCol);
- }
- }
- else {
- draw_dm_edges_sel(em, cageDM, wireCol, selCol, actCol, eed_act);
- }
- }
- else {
- if (!sel_only) {
- glColor4ubv(wireCol);
- draw_dm_edges(em, cageDM);
- }
- }
-
- if (pass == 0) {
- glDisable(GL_BLEND);
- glEnable(GL_DEPTH_TEST);
- }
- }
-}
-
-static void draw_em_measure_stats(ARegion *ar, View3D *v3d, Object *ob, BMEditMesh *em, UnitSettings *unit)
-{
- /* Do not use ascii when using non-default unit system, some unit chars are utf8 (micro, square, etc.).
- * See bug #36090.
- */
- const short txt_flag = V3D_CACHE_TEXT_LOCALCLIP | (unit->system ? 0 : V3D_CACHE_TEXT_ASCII);
- Mesh *me = ob->data;
- float v1[3], v2[3], v3[3], vmid[3], fvec[3];
- char numstr[32]; /* Stores the measurement display text here */
- size_t numstr_len;
- const char *conv_float; /* Use a float conversion matching the grid size */
- unsigned char col[4] = {0, 0, 0, 255}; /* color of the text to draw */
- float area; /* area of the face */
- float grid = unit->system ? unit->scale_length : v3d->grid;
- const bool do_split = (unit->flag & USER_UNIT_OPT_SPLIT) != 0;
- const bool do_global = (v3d->flag & V3D_GLOBAL_STATS) != 0;
- const bool do_moving = (G.moving & G_TRANSFORM_EDIT) != 0;
- /* when 2 edge-info options are enabled, space apart */
- const bool do_edge_textpair = (me->drawflag & ME_DRAWEXTRA_EDGELEN) && (me->drawflag & ME_DRAWEXTRA_EDGEANG);
- const float edge_texpair_sep = 0.4f;
- float clip_planes[4][4];
- /* allow for displaying shape keys and deform mods */
- DerivedMesh *dm = EDBM_mesh_deform_dm_get(em);
- BMIter iter;
-
- /* make the precision of the display value proportionate to the gridsize */
-
- if (grid <= 0.01f) conv_float = "%.6g";
- else if (grid <= 0.1f) conv_float = "%.5g";
- else if (grid <= 1.0f) conv_float = "%.4g";
- else if (grid <= 10.0f) conv_float = "%.3g";
- else conv_float = "%.2g";
-
- if (me->drawflag & (ME_DRAWEXTRA_EDGELEN | ME_DRAWEXTRA_EDGEANG)) {
- BoundBox bb;
- bglMats mats = {{0}};
- const rcti rect = {0, ar->winx, 0, ar->winy};
-
- view3d_get_transformation(ar, ar->regiondata, em->ob, &mats);
- ED_view3d_clipping_calc(&bb, clip_planes, &mats, &rect);
- }
-
- if (me->drawflag & ME_DRAWEXTRA_EDGELEN) {
- BMEdge *eed;
-
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGELEN, col);
-
- if (dm) {
- BM_mesh_elem_index_ensure(em->bm, BM_VERT);
- }
-
- BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
- /* draw selected edges, or edges next to selected verts while dragging */
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT) ||
- (do_moving && (BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
- BM_elem_flag_test(eed->v2, BM_ELEM_SELECT))))
- {
- float v1_clip[3], v2_clip[3];
-
- if (dm) {
- dm->getVertCo(dm, BM_elem_index_get(eed->v1), v1);
- dm->getVertCo(dm, BM_elem_index_get(eed->v2), v2);
- }
- else {
- copy_v3_v3(v1, eed->v1->co);
- copy_v3_v3(v2, eed->v2->co);
- }
-
- if (clip_segment_v3_plane_n(v1, v2, clip_planes, 4, v1_clip, v2_clip)) {
-
- if (do_edge_textpair) {
- interp_v3_v3v3(vmid, v1, v2, edge_texpair_sep);
- }
- else {
- mid_v3_v3v3(vmid, v1_clip, v2_clip);
- }
-
- if (do_global) {
- mul_mat3_m4_v3(ob->obmat, v1);
- mul_mat3_m4_v3(ob->obmat, v2);
- }
-
- if (unit->system) {
- numstr_len = bUnit_AsString(numstr, sizeof(numstr), len_v3v3(v1, v2) * unit->scale_length, 3,
- unit->system, B_UNIT_LENGTH, do_split, false);
- }
- else {
- numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, len_v3v3(v1, v2));
- }
-
- view3d_cached_text_draw_add(vmid, numstr, numstr_len, 0, txt_flag, col);
- }
- }
- }
- }
-
- if (me->drawflag & ME_DRAWEXTRA_EDGEANG) {
- const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
- BMEdge *eed;
-
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGEANG, col);
-
- if (dm) {
- BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
- }
-
- BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
- BMLoop *l_a, *l_b;
- if (BM_edge_loop_pair(eed, &l_a, &l_b)) {
- /* draw selected edges, or edges next to selected verts while dragging */
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT) ||
- (do_moving && (BM_elem_flag_test(eed->v1, BM_ELEM_SELECT) ||
- BM_elem_flag_test(eed->v2, BM_ELEM_SELECT) ||
- /* special case, this is useful to show when verts connected to
- * this edge via a face are being transformed */
- BM_elem_flag_test(l_a->next->next->v, BM_ELEM_SELECT) ||
- BM_elem_flag_test(l_a->prev->v, BM_ELEM_SELECT) ||
- BM_elem_flag_test(l_b->next->next->v, BM_ELEM_SELECT) ||
- BM_elem_flag_test(l_b->prev->v, BM_ELEM_SELECT)
- )))
- {
- float v1_clip[3], v2_clip[3];
-
- if (dm) {
- dm->getVertCo(dm, BM_elem_index_get(eed->v1), v1);
- dm->getVertCo(dm, BM_elem_index_get(eed->v2), v2);
- }
- else {
- copy_v3_v3(v1, eed->v1->co);
- copy_v3_v3(v2, eed->v2->co);
- }
-
- if (clip_segment_v3_plane_n(v1, v2, clip_planes, 4, v1_clip, v2_clip)) {
- float no_a[3], no_b[3];
- float angle;
-
- if (do_edge_textpair) {
- interp_v3_v3v3(vmid, v2_clip, v1_clip, edge_texpair_sep);
- }
- else {
- mid_v3_v3v3(vmid, v1_clip, v2_clip);
- }
-
- if (dm) {
- dm->getPolyNo(dm, BM_elem_index_get(l_a->f), no_a);
- dm->getPolyNo(dm, BM_elem_index_get(l_b->f), no_b);
- }
- else {
- copy_v3_v3(no_a, l_a->f->no);
- copy_v3_v3(no_b, l_b->f->no);
- }
-
- if (do_global) {
- mul_mat3_m4_v3(ob->imat, no_a);
- mul_mat3_m4_v3(ob->imat, no_b);
- normalize_v3(no_a);
- normalize_v3(no_b);
- }
-
- angle = angle_normalized_v3v3(no_a, no_b);
-
- numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%.3f", is_rad ? angle : RAD2DEGF(angle));
-
- view3d_cached_text_draw_add(vmid, numstr, numstr_len, 0, txt_flag, col);
- }
- }
- }
+ index += ntris;
}
}
+ immEnd();
- if (me->drawflag & ME_DRAWEXTRA_FACEAREA) {
- /* would be nice to use BM_face_calc_area, but that is for 2d faces
- * so instead add up tessellation triangle areas */
- BMFace *f = NULL;
-
-#define DRAW_EM_MEASURE_STATS_FACEAREA() \
- if (BM_elem_flag_test(f, BM_ELEM_SELECT)) { \
- mul_v3_fl(vmid, 1.0f / (float)n); \
- if (unit->system) { \
- numstr_len = bUnit_AsString( \
- numstr, sizeof(numstr), \
- (double)(area * unit->scale_length * unit->scale_length), \
- 3, unit->system, B_UNIT_AREA, do_split, false); \
- } \
- else { \
- numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), conv_float, area); \
- } \
- view3d_cached_text_draw_add(vmid, numstr, numstr_len, 0, txt_flag, col); \
- } (void)0
-
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
-
- if (dm) {
- BM_mesh_elem_index_ensure(em->bm, BM_VERT);
- }
-
- area = 0.0;
- zero_v3(vmid);
- int n = 0;
- for (int i = 0; i < em->tottri; i++) {
- BMLoop **l = em->looptris[i];
- if (f && l[0]->f != f) {
- DRAW_EM_MEASURE_STATS_FACEAREA();
- zero_v3(vmid);
- area = 0.0;
- n = 0;
- }
-
- f = l[0]->f;
-
- if (dm) {
- dm->getVertCo(dm, BM_elem_index_get(l[0]->v), v1);
- dm->getVertCo(dm, BM_elem_index_get(l[1]->v), v2);
- dm->getVertCo(dm, BM_elem_index_get(l[2]->v), v3);
- }
- else {
- copy_v3_v3(v1, l[0]->v->co);
- copy_v3_v3(v2, l[1]->v->co);
- copy_v3_v3(v3, l[2]->v->co);
- }
-
- add_v3_v3(vmid, v1);
- add_v3_v3(vmid, v2);
- add_v3_v3(vmid, v3);
- n += 3;
- if (do_global) {
- mul_mat3_m4_v3(ob->obmat, v1);
- mul_mat3_m4_v3(ob->obmat, v2);
- mul_mat3_m4_v3(ob->obmat, v3);
- }
- area += area_tri_v3(v1, v2, v3);
- }
-
- if (f) {
- DRAW_EM_MEASURE_STATS_FACEAREA();
- }
-#undef DRAW_EM_MEASURE_STATS_FACEAREA
- }
-
- if (me->drawflag & ME_DRAWEXTRA_FACEANG) {
- BMFace *efa;
- const bool is_rad = (unit->system_rotation == USER_UNIT_ROT_RADIANS);
-
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
-
- if (dm) {
- BM_mesh_elem_index_ensure(em->bm, BM_VERT);
- }
-
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- const bool is_face_sel = BM_elem_flag_test_bool(efa, BM_ELEM_SELECT);
-
- if (is_face_sel || do_moving) {
- BMIter liter;
- BMLoop *loop;
- bool is_first = true;
-
- BM_ITER_ELEM (loop, &liter, efa, BM_LOOPS_OF_FACE) {
- if (is_face_sel ||
- (do_moving &&
- (BM_elem_flag_test(loop->v, BM_ELEM_SELECT) ||
- BM_elem_flag_test(loop->prev->v, BM_ELEM_SELECT) ||
- BM_elem_flag_test(loop->next->v, BM_ELEM_SELECT))))
- {
- float v2_local[3];
-
- /* lazy init center calc */
- if (is_first) {
- if (dm) {
- BMLoop *l_iter, *l_first;
- float tvec[3];
- zero_v3(vmid);
- l_iter = l_first = BM_FACE_FIRST_LOOP(efa);
- do {
- dm->getVertCo(dm, BM_elem_index_get(l_iter->v), tvec);
- add_v3_v3(vmid, tvec);
- } while ((l_iter = l_iter->next) != l_first);
- mul_v3_fl(vmid, 1.0f / (float)efa->len);
- }
- else {
- BM_face_calc_center_bounds(efa, vmid);
- }
- is_first = false;
- }
-
- if (dm) {
- dm->getVertCo(dm, BM_elem_index_get(loop->prev->v), v1);
- dm->getVertCo(dm, BM_elem_index_get(loop->v), v2);
- dm->getVertCo(dm, BM_elem_index_get(loop->next->v), v3);
- }
- else {
- copy_v3_v3(v1, loop->prev->v->co);
- copy_v3_v3(v2, loop->v->co);
- copy_v3_v3(v3, loop->next->v->co);
- }
-
- copy_v3_v3(v2_local, v2);
-
- if (do_global) {
- mul_mat3_m4_v3(ob->obmat, v1);
- mul_mat3_m4_v3(ob->obmat, v2);
- mul_mat3_m4_v3(ob->obmat, v3);
- }
-
- float angle = angle_v3v3v3(v1, v2, v3);
-
- numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%.3f", is_rad ? angle : RAD2DEGF(angle));
- interp_v3_v3v3(fvec, vmid, v2_local, 0.8f);
- view3d_cached_text_draw_add(fvec, numstr, numstr_len, 0, txt_flag, col);
- }
- }
- }
- }
- }
+ immUnbindProgram();
}
-
-static void draw_em_indices(BMEditMesh *em)
-{
- const short txt_flag = V3D_CACHE_TEXT_ASCII | V3D_CACHE_TEXT_LOCALCLIP;
- BMEdge *e;
- BMFace *f;
- BMVert *v;
- char numstr[32];
- size_t numstr_len;
- float pos[3];
- unsigned char col[4];
-
- BMIter iter;
- BMesh *bm = em->bm;
-
- /* For now, reuse appropriate theme colors from stats text colors */
- int i = 0;
- if (em->selectmode & SCE_SELECT_VERTEX) {
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEANG, col);
- BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(v, BM_ELEM_SELECT)) {
- numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", i);
- view3d_cached_text_draw_add(v->co, numstr, numstr_len, 0, txt_flag, col);
- }
- i++;
- }
- }
-
- if (em->selectmode & SCE_SELECT_EDGE) {
- i = 0;
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_EDGELEN, col);
- BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
- if (BM_elem_flag_test(e, BM_ELEM_SELECT)) {
- numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", i);
- mid_v3_v3v3(pos, e->v1->co, e->v2->co);
- view3d_cached_text_draw_add(pos, numstr, numstr_len, 0, txt_flag, col);
- }
- i++;
- }
- }
-
- if (em->selectmode & SCE_SELECT_FACE) {
- i = 0;
- UI_GetThemeColor3ubv(TH_DRAWEXTRA_FACEAREA, col);
- BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
- if (BM_elem_flag_test(f, BM_ELEM_SELECT)) {
- BM_face_calc_center_mean(f, pos);
- numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%d", i);
- view3d_cached_text_draw_add(pos, numstr, numstr_len, 0, txt_flag, col);
- }
- i++;
- }
- }
-}
-
-static DMDrawOption draw_em_fancy__setFaceOpts(void *userData, int index)
-{
- BMEditMesh *em = userData;
-
- if (UNLIKELY(index >= em->bm->totface))
- return DM_DRAW_OPTION_NORMAL;
-
- BMFace *efa = BM_face_at_index(em->bm, index);
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
- }
-}
-
-static DMDrawOption draw_em_fancy__setGLSLFaceOpts(void *userData, int index)
-{
- BMEditMesh *em = userData;
-
- if (UNLIKELY(index >= em->bm->totface))
- return DM_DRAW_OPTION_NORMAL;
-
- BMFace *efa = BM_face_at_index(em->bm, index);
-
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
- }
-}
-
-static void draw_em_fancy(Scene *scene, ARegion *ar, View3D *v3d,
- Object *ob, BMEditMesh *em, DerivedMesh *cageDM, DerivedMesh *finalDM, const char dt)
-
-{
- RegionView3D *rv3d = ar->regiondata;
- Mesh *me = ob->data;
- const bool use_occlude_wire = (dt > OB_WIRE) && (v3d->flag2 & V3D_OCCLUDE_WIRE);
- bool use_depth_offset = false;
-
- glLineWidth(1);
-
- BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE);
-
- if (check_object_draw_editweight(me, finalDM)) {
- if (dt > OB_WIRE) {
- draw_mesh_paint_weight_faces(finalDM, true, draw_em_fancy__setFaceOpts, me->edit_btmesh);
-
- ED_view3d_polygon_offset(rv3d, 1.0);
- glDepthMask(0);
- use_depth_offset = true;
- }
- else {
- glEnable(GL_DEPTH_TEST);
- draw_mesh_paint_weight_faces(finalDM, false, draw_em_fancy__setFaceOpts, me->edit_btmesh);
- draw_mesh_paint_weight_edges(rv3d, finalDM, true, true, draw_dm_edges__setDrawOptions, me->edit_btmesh->bm);
- glDisable(GL_DEPTH_TEST);
- }
- }
- else if (dt > OB_WIRE) {
- if (use_occlude_wire) {
- /* use the cageDM since it always overlaps the editmesh faces */
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
- cageDM->drawMappedFaces(cageDM, draw_em_fancy__setFaceOpts,
- GPU_object_material_bind, NULL, me->edit_btmesh, DM_DRAW_SKIP_HIDDEN | DM_DRAW_NEED_NORMALS);
- GPU_object_material_unbind();
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- }
- else if (check_object_draw_texture(scene, v3d, dt)) {
- if (draw_glsl_material(scene, ob, v3d, dt)) {
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
-
- finalDM->drawMappedFacesGLSL(finalDM, GPU_object_material_bind,
- draw_em_fancy__setGLSLFaceOpts, em);
- GPU_object_material_unbind();
-
- glFrontFace(GL_CCW);
- }
- else {
- draw_mesh_textured(scene, v3d, rv3d, ob, finalDM, 0);
- }
- }
- else {
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
- finalDM->drawMappedFaces(finalDM, draw_em_fancy__setFaceOpts, GPU_object_material_bind, NULL, me->edit_btmesh, DM_DRAW_SKIP_HIDDEN | DM_DRAW_NEED_NORMALS);
-
- glFrontFace(GL_CCW);
-
- GPU_object_material_unbind();
- }
-
- /* Setup for drawing wire over, disable zbuffer
- * write to show selected edge wires better */
- UI_ThemeColor(TH_WIRE_EDIT);
-
- ED_view3d_polygon_offset(rv3d, 1.0);
- glDepthMask(0);
- use_depth_offset = true;
- }
- else {
- if (cageDM != finalDM) {
- UI_ThemeColorBlend(TH_WIRE_EDIT, TH_BACK, 0.7);
- finalDM->drawEdges(finalDM, 1, 0);
- }
- }
-
- if ((dt > OB_WIRE) && (v3d->flag2 & V3D_RENDER_SHADOW)) {
- /* pass */
- }
- else {
- /* annoying but active faces is stored differently */
- BMFace *efa_act = BM_mesh_active_face_get(em->bm, false, true);
- BMEdge *eed_act = NULL;
- BMVert *eve_act = NULL;
-
- if (em->bm->selected.last) {
- BMEditSelection *ese = em->bm->selected.last;
- /* face is handled above */
-#if 0
- if (ese->type == BM_FACE) {
- efa_act = (BMFace *)ese->data;
- }
- else
-#endif
- if (ese->htype == BM_EDGE) {
- eed_act = (BMEdge *)ese->ele;
- }
- else if (ese->htype == BM_VERT) {
- eve_act = (BMVert *)ese->ele;
- }
- }
-
- if ((me->drawflag & ME_DRAWFACES) && (use_occlude_wire == false)) { /* transp faces */
- unsigned char col1[4], col2[4], col3[4];
-#ifdef WITH_FREESTYLE
- unsigned char col4[4];
-#endif
-
- UI_GetThemeColor4ubv(TH_FACE, col1);
- UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
- UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
-#ifdef WITH_FREESTYLE
- UI_GetThemeColor4ubv(TH_FREESTYLE_FACE_MARK, col4);
-#endif
-
- glEnable(GL_BLEND);
- glDepthMask(0); /* disable write in zbuffer, needed for nice transp */
-
- /* don't draw unselected faces, only selected, this is MUCH nicer when texturing */
- if (check_object_draw_texture(scene, v3d, dt))
- col1[3] = 0;
-
-#ifdef WITH_FREESTYLE
- if (!(me->drawflag & ME_DRAW_FREESTYLE_FACE) || !CustomData_has_layer(&em->bm->pdata, CD_FREESTYLE_FACE))
- col4[3] = 0;
-
- draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
-#else
- draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
-#endif
-
- glDisable(GL_BLEND);
- glDepthMask(1); /* restore write in zbuffer */
- }
- else if (efa_act) {
- /* even if draw faces is off it would be nice to draw the stipple face
- * Make all other faces zero alpha except for the active */
- unsigned char col1[4], col2[4], col3[4];
-#ifdef WITH_FREESTYLE
- unsigned char col4[4];
- col4[3] = 0; /* don't draw */
-#endif
- col1[3] = col2[3] = 0; /* don't draw */
-
- UI_GetThemeColor4ubv(TH_EDITMESH_ACTIVE, col3);
-
- glEnable(GL_BLEND);
- glDepthMask(0); /* disable write in zbuffer, needed for nice transp */
-
-#ifdef WITH_FREESTYLE
- draw_dm_faces_sel(em, cageDM, col1, col2, col3, col4, efa_act);
#else
- draw_dm_faces_sel(em, cageDM, col1, col2, col3, efa_act);
-#endif
-
- glDisable(GL_BLEND);
- glDepthMask(1); /* restore write in zbuffer */
- }
-
- /* here starts all fancy draw-extra over */
- if ((me->drawflag & ME_DRAWEDGES) == 0 && check_object_draw_texture(scene, v3d, dt)) {
- /* we are drawing textures and 'ME_DRAWEDGES' is disabled, don't draw any edges */
-
- /* only draw selected edges otherwise there is no way of telling if a face is selected */
- draw_em_fancy_edges(em, scene, v3d, me, cageDM, 1, eed_act);
-
- }
- else {
- if (me->drawflag & ME_DRAWSEAMS) {
- UI_ThemeColor(TH_EDGE_SEAM);
- glLineWidth(2);
-
- draw_dm_edges_seams(em, cageDM);
-
- glColor3ub(0, 0, 0);
- }
-
- if (me->drawflag & ME_DRAWSHARP) {
- UI_ThemeColor(TH_EDGE_SHARP);
- glLineWidth(2);
-
- draw_dm_edges_sharp(em, cageDM);
-
- glColor3ub(0, 0, 0);
- }
-
-#ifdef WITH_FREESTYLE
- if (me->drawflag & ME_DRAW_FREESTYLE_EDGE && CustomData_has_layer(&em->bm->edata, CD_FREESTYLE_EDGE)) {
- UI_ThemeColor(TH_FREESTYLE_EDGE_MARK);
- glLineWidth(2);
-
- draw_dm_edges_freestyle(em, cageDM);
-
- glColor3ub(0, 0, 0);
- }
-#endif
-
- if (me->drawflag & ME_DRAWCREASES) {
- draw_dm_creases(em, cageDM);
- }
- if (me->drawflag & ME_DRAWBWEIGHTS) {
- draw_dm_bweights(em, scene, cageDM);
- }
-
- glLineWidth(1);
- draw_em_fancy_edges(em, scene, v3d, me, cageDM, 0, eed_act);
- }
-
- {
- draw_em_fancy_verts(scene, v3d, ob, em, cageDM, eve_act, rv3d);
-
- if (me->drawflag & ME_DRAWNORMALS) {
- UI_ThemeColor(TH_NORMAL);
- draw_dm_face_normals(em, scene, ob, cageDM);
- }
- if (me->drawflag & ME_DRAW_VNORMALS) {
- UI_ThemeColor(TH_VNORMAL);
- draw_dm_vert_normals(em, scene, ob, cageDM);
- }
- if (me->drawflag & ME_DRAW_LNORMALS) {
- UI_ThemeColor(TH_LNORMAL);
- draw_dm_loop_normals(em, scene, ob, cageDM);
- }
-
- if ((me->drawflag & (ME_DRAWEXTRA_EDGELEN |
- ME_DRAWEXTRA_FACEAREA |
- ME_DRAWEXTRA_FACEANG |
- ME_DRAWEXTRA_EDGEANG)) &&
- !(v3d->flag2 & V3D_RENDER_OVERRIDE))
- {
- draw_em_measure_stats(ar, v3d, ob, em, &scene->unit);
- }
-
- if ((G.debug & G_DEBUG) && (me->drawflag & ME_DRAWEXTRA_INDICES) &&
- !(v3d->flag2 & V3D_RENDER_OVERRIDE))
- {
- draw_em_indices(em);
- }
- }
- }
-
- if (use_depth_offset) {
- glDepthMask(1);
- ED_view3d_polygon_offset(rv3d, 0.0);
- GPU_object_material_unbind();
- }
-#if 0 /* currently not needed */
- else if (use_occlude_wire) {
- ED_view3d_polygon_offset(rv3d, 0.0);
- }
-#endif
-}
-
-/* Mesh drawing routines */
-
-static void draw_mesh_object_outline(View3D *v3d, Object *ob, DerivedMesh *dm)
+static void bbs_mesh_face(BMEditMesh *em, DerivedMesh *UNUSED(dm), const bool use_select)
{
- if ((v3d->transp == false) && /* not when we draw the transparent pass */
- (ob->mode & OB_MODE_ALL_PAINT) == false) /* not when painting (its distracting) - campbell */
- {
- glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f);
- glDepthMask(0);
-
- /* if transparent, we cannot draw the edges for solid select... edges
- * have no material info. GPU_object_material_visible will skip the
- * transparent faces */
- if (ob->dtx & OB_DRAWTRANSP) {
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_visible);
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- }
- else {
- dm->drawEdges(dm, 0, 1);
- }
+ Mesh *me = em->ob->data;
+ Gwn_Batch *batch;
- glDepthMask(1);
- }
-}
-
-static bool object_is_halo(Scene *scene, Object *ob)
-{
- const Material *ma = give_current_material(ob, 1);
- return (ma && (ma->material_type == MA_TYPE_HALO) && !BKE_scene_use_new_shading_nodes(scene));
-}
-
-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)
-{
-#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;
- eWireDrawMode draw_wire = OBDRAW_WIRE_OFF;
- bool /* no_verts,*/ no_edges, no_faces;
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
- const bool is_obact = (ob == OBACT);
- int draw_flags = (is_obact && BKE_paint_select_face_test(ob)) ? DRAW_FACE_SELECT : 0;
-
- if (!dm)
- return;
-
- DM_update_materials(dm, ob);
-
- /* Check to draw dynamic paint colors (or weights from WeightVG modifiers).
- * Note: Last "preview-active" modifier in stack will win! */
- if (DM_get_loop_data_layer(dm, CD_PREVIEW_MLOOPCOL) && modifiers_isPreview(ob))
- draw_flags |= DRAW_MODIFIERS_PREVIEW;
-
- /* Unwanted combination */
- if (draw_flags & DRAW_FACE_SELECT) {
- draw_wire = OBDRAW_WIRE_OFF;
- }
- else if (ob->dtx & OB_DRAWWIRE) {
- draw_wire = OBDRAW_WIRE_ON_DEPTH; /* draw wire after solid using zoffset and depth buffer adjusment */
- }
-
- /* check polys instead of tessfaces because of dyntopo where tessfaces don't exist */
- if (dm->type == DM_TYPE_CCGDM) {
- no_edges = !subsurf_has_edges(dm);
- no_faces = !subsurf_has_faces(dm);
+ if (use_select) {
+ batch = DRW_mesh_batch_cache_get_triangles_with_select_id(me, true, 1);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_FLAT_COLOR_U32);
+ GWN_batch_draw(batch);
}
else {
- no_edges = (dm->getNumEdges(dm) == 0);
- no_faces = (dm->getNumPolys(dm) == 0);
- }
-
- /* vertexpaint, faceselect wants this, but it doesnt work for shaded? */
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
-
- if (dt == OB_BOUNDBOX) {
- if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_WIRE) == 0)
- draw_bounding_volume(ob, ob->boundtype);
+ int selcol;
+ GPU_select_index_get(0, &selcol);
+ batch = DRW_mesh_batch_cache_get_triangles_with_select_mask(me, true);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR_U32);
+ GWN_batch_uniform_1ui(batch, "color", selcol);
+ GWN_batch_draw(batch);
}
- else if ((no_faces && no_edges) ||
- ((!is_obact || (ob->mode == OB_MODE_OBJECT)) && object_is_halo(scene, ob)))
- {
- glPointSize(1.5);
- dm->drawVerts(dm);
- }
- else if ((dt == OB_WIRE) || no_faces) {
- draw_wire = OBDRAW_WIRE_ON; /* draw wire only, no depth buffer stuff */
- }
- else if (((is_obact && ob->mode & OB_MODE_TEXTURE_PAINT)) ||
- check_object_draw_texture(scene, v3d, dt))
- {
- bool draw_loose = true;
-
- if ((v3d->flag & V3D_SELECT_OUTLINE) &&
- ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
- (base->flag & SELECT) &&
- !(G.f & G_PICKSEL || (draw_flags & DRAW_FACE_SELECT)) &&
- (draw_wire == OBDRAW_WIRE_OFF))
- {
- draw_mesh_object_outline(v3d, ob, dm);
- }
-
- if (draw_glsl_material(scene, ob, v3d, dt) && !(draw_flags & DRAW_MODIFIERS_PREVIEW)) {
- Paint *p;
-
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
-
- if ((v3d->flag2 & V3D_SHOW_SOLID_MATCAP) && ob->sculpt && (p = BKE_paint_get_active(scene))) {
- GPUVertexAttribs gattribs;
- float planes[4][4];
- float (*fpl)[4] = NULL;
- const bool fast = (p->flags & PAINT_FAST_NAVIGATE) && (rv3d->rflag & RV3D_NAVIGATING);
-
- if (ob->sculpt->partial_redraw) {
- if (ar->do_draw & RGN_DRAW_PARTIAL) {
- ED_sculpt_redraw_planes_get(planes, ar, rv3d, ob);
- fpl = planes;
- ob->sculpt->partial_redraw = 0;
- }
- }
-
- GPU_object_material_bind(1, &gattribs);
- dm->drawFacesSolid(dm, fpl, fast, NULL);
- draw_loose = false;
- }
- else
- dm->drawFacesGLSL(dm, GPU_object_material_bind);
-
-#if 0 /* XXX */
- if (BKE_bproperty_object_get(ob, "Text"))
- draw_mesh_text(ob, 1);
-#endif
- GPU_object_material_unbind();
-
- glFrontFace(GL_CCW);
-
- if (draw_flags & DRAW_FACE_SELECT)
- draw_mesh_face_select(rv3d, me, dm, false);
- }
- else {
- draw_mesh_textured(scene, v3d, rv3d, ob, dm, draw_flags);
- }
-
- if (draw_loose && !(draw_flags & DRAW_FACE_SELECT)) {
- if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(ob_wire_col);
- }
- glLineWidth(1.0f);
- dm->drawLooseEdges(dm);
- }
- }
- }
- else if (dt == OB_SOLID) {
- if (draw_flags & DRAW_MODIFIERS_PREVIEW) {
- /* for object selection draws no shade */
- if (dflag & (DRAW_PICKING | DRAW_CONSTCOLOR)) {
- dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind);
- GPU_object_material_unbind();
- }
- else {
- const float specular[3] = {0.47f, 0.47f, 0.47f};
-
- /* draw outline */
- if ((v3d->flag & V3D_SELECT_OUTLINE) &&
- ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
- (base->flag & SELECT) &&
- (draw_wire == OBDRAW_WIRE_OFF) &&
- (ob->sculpt == NULL))
- {
- draw_mesh_object_outline(v3d, ob, dm);
- }
-
- /* materials arent compatible with vertex colors */
- GPU_end_object_materials();
-
- /* set default specular */
- GPU_basic_shader_colors(NULL, specular, 35, 1.0f);
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
-
- dm->drawMappedFaces(dm, NULL, NULL, NULL, NULL, DM_DRAW_USE_COLORS | DM_DRAW_NEED_NORMALS);
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
- }
- else {
- Paint *p;
-
- if ((v3d->flag & V3D_SELECT_OUTLINE) &&
- ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) &&
- (base->flag & SELECT) &&
- (draw_wire == OBDRAW_WIRE_OFF) &&
- (ob->sculpt == NULL))
- {
- draw_mesh_object_outline(v3d, ob, dm);
- }
-
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
-
- if (ob->sculpt && (p = BKE_paint_get_active(scene))) {
- float planes[4][4];
- float (*fpl)[4] = NULL;
- const bool fast = (p->flags & PAINT_FAST_NAVIGATE) && (rv3d->rflag & RV3D_NAVIGATING);
-
- if (ob->sculpt->partial_redraw) {
- if (ar->do_draw & RGN_DRAW_PARTIAL) {
- ED_sculpt_redraw_planes_get(planes, ar, rv3d, ob);
- fpl = planes;
- ob->sculpt->partial_redraw = 0;
- }
- }
-
- dm->drawFacesSolid(dm, fpl, fast, GPU_object_material_bind);
- }
- else
- dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind);
-
- glFrontFace(GL_CCW);
-
- GPU_object_material_unbind();
-
- if (!ob->sculpt && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(ob_wire_col);
- }
- glLineWidth(1.0f);
- dm->drawLooseEdges(dm);
- }
- }
- }
- else if (dt == OB_PAINT) {
- draw_mesh_paint(v3d, rv3d, ob, dm, draw_flags);
-
- /* since we already draw wire as wp guide, don't draw over the top */
- draw_wire = OBDRAW_WIRE_OFF;
- }
-
- if ((draw_wire != OBDRAW_WIRE_OFF) && /* draw extra wire */
- /* when overriding with render only, don't bother */
- (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID) == 0))
- {
- /* When using wireframe object draw in particle edit mode
- * the mesh gets in the way of seeing the particles, fade the wire color
- * with the background. */
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (is_obact && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
- ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.15f);
- }
- else {
- glColor3ubv(ob_wire_col);
- }
- }
-
- /* If drawing wire and drawtype is not OB_WIRE then we are
- * overlaying the wires.
- *
- * UPDATE bug #10290 - With this wire-only objects can draw
- * behind other objects depending on their order in the scene. 2x if 0's below. undo'ing zr's commit: r4059
- *
- * if draw wire is 1 then just drawing wire, no need for depth buffer stuff,
- * otherwise this wire is to overlay solid mode faces so do some depth buffer tricks.
- */
- if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
- ED_view3d_polygon_offset(rv3d, 1.0);
- glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */
- }
-
- glLineWidth(1.0f);
- dm->drawEdges(dm, ((dt == OB_WIRE) || no_faces), (ob->dtx & OB_DRAW_ALL_EDGES) != 0);
-
- if (dt != OB_WIRE && (draw_wire == OBDRAW_WIRE_ON_DEPTH)) {
- glDepthMask(1);
- ED_view3d_polygon_offset(rv3d, 0.0);
- }
- }
-
- if (is_obact && BKE_paint_select_vert_test(ob)) {
- const bool use_depth = (v3d->flag & V3D_ZBUF_SELECT) != 0;
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
-
- if (!use_depth) glDisable(GL_DEPTH_TEST);
- else ED_view3d_polygon_offset(rv3d, 1.0);
- drawSelectedVertices(dm, ob->data);
- if (!use_depth) glEnable(GL_DEPTH_TEST);
- else ED_view3d_polygon_offset(rv3d, 0.0);
- }
- dm->release(dm);
}
-
-/* returns true if nothing was drawn, for detecting to draw an object center */
-static bool draw_mesh_object(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 = base->object;
- Object *obedit = scene->obedit;
- Mesh *me = ob->data;
- BMEditMesh *em = me->edit_btmesh;
- bool do_alpha_after = false, drawlinked = false, retval = false;
-
- /* If we are drawing shadows and any of the materials don't cast a shadow,
- * then don't draw the object */
- if (v3d->flag2 & V3D_RENDER_SHADOW) {
- for (int i = 1; i <= ob->totcol; ++i) {
- Material *ma = give_current_material(ob, i);
- if (ma && !(ma->mode2 & MA_CASTSHADOW)) {
- return true;
- }
- }
- }
-
- if (obedit && ob != obedit && ob->data == obedit->data) {
- if (BKE_key_from_object(ob) || BKE_key_from_object(obedit)) {}
- else if (ob->modifiers.first || obedit->modifiers.first) {}
- else drawlinked = true;
- }
-
- /* backface culling */
- if (v3d->flag2 & V3D_BACKFACE_CULLING) {
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- }
-
- if (ob == obedit || drawlinked) {
- DerivedMesh *finalDM, *cageDM;
-
- if (obedit != ob) {
- finalDM = cageDM = editbmesh_get_derived_base(
- ob, em, scene->customdata_mask);
- }
- else {
- cageDM = editbmesh_get_derived_cage_and_final(
- scene, ob, em, scene->customdata_mask,
- &finalDM);
- }
-
- const bool use_material = ((me->drawflag & ME_DRAWEIGHT) == 0);
-
- DM_update_materials(finalDM, ob);
- if (cageDM != finalDM) {
- DM_update_materials(cageDM, ob);
- }
-
- if (use_material) {
- if (dt > OB_WIRE) {
- const bool glsl = draw_glsl_material(scene, ob, v3d, dt);
-
- GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
- }
- }
-
- draw_em_fancy(scene, ar, v3d, ob, em, cageDM, finalDM, dt);
-
- if (use_material) {
- GPU_end_object_materials();
- }
-
- if (obedit != ob)
- finalDM->release(finalDM);
- }
- else {
- /* ob->bb was set by derived mesh system, do NULL check just to be sure */
- if (me->totpoly <= 4 || (!ob->bb || ED_view3d_boundbox_clip(rv3d, ob->bb))) {
- if (dt > OB_WIRE) {
- const bool glsl = draw_glsl_material(scene, ob, v3d, dt);
-
- if (dt == OB_SOLID || glsl) {
- const bool check_alpha = check_alpha_pass(base);
- GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl,
- (check_alpha) ? &do_alpha_after : NULL);
- }
- }
-
- draw_mesh_fancy(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
-
- GPU_end_object_materials();
-
- if (me->totvert == 0) retval = true;
- }
- }
-
- if ((dflag & DRAW_PICKING) == 0 && (base->flag & OB_FROMDUPLI) == 0 && (v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
- /* GPU_begin_object_materials checked if this is needed */
- if (do_alpha_after) {
- if (ob->dtx & OB_DRAWXRAY) {
- ED_view3d_after_add(&v3d->afterdraw_xraytransp, base, dflag);
- }
- else {
- ED_view3d_after_add(&v3d->afterdraw_transp, base, dflag);
- }
- }
- else if (ob->dtx & OB_DRAWXRAY && ob->dtx & OB_DRAWTRANSP) {
- /* special case xray+transp when alpha is 1.0, without this the object vanishes */
- if (v3d->xray == 0 && v3d->transp == 0) {
- ED_view3d_after_add(&v3d->afterdraw_xray, base, dflag);
- }
- }
- }
-
- if (v3d->flag2 & V3D_BACKFACE_CULLING)
- glDisable(GL_CULL_FACE);
-
- return retval;
-}
-
-/* ************** DRAW DISPLIST ****************** */
-
-
-/**
- * \param dl_type_mask Only draw types matching this mask.
- * \return true when nothing was drawn
- */
-static bool drawDispListwire_ex(ListBase *dlbase, unsigned int dl_type_mask)
-{
- if (dlbase == NULL) return true;
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
-
- for (DispList *dl = dlbase->first; dl; dl = dl->next) {
- if (dl->parts == 0 || dl->nr == 0) {
- continue;
- }
-
- if ((dl_type_mask & (1 << dl->type)) == 0) {
- continue;
- }
-
- const float *data = dl->verts;
- int parts;
-
- switch (dl->type) {
- case DL_SEGM:
-
- glVertexPointer(3, GL_FLOAT, 0, data);
-
- for (parts = 0; parts < dl->parts; parts++)
- glDrawArrays(GL_LINE_STRIP, parts * dl->nr, dl->nr);
-
- break;
- case DL_POLY:
-
- glVertexPointer(3, GL_FLOAT, 0, data);
-
- for (parts = 0; parts < dl->parts; parts++)
- glDrawArrays(GL_LINE_LOOP, parts * dl->nr, dl->nr);
-
- break;
- case DL_SURF:
-
- glVertexPointer(3, GL_FLOAT, 0, data);
-
- for (parts = 0; parts < dl->parts; parts++) {
- if (dl->flag & DL_CYCL_U)
- glDrawArrays(GL_LINE_LOOP, parts * dl->nr, dl->nr);
- else
- glDrawArrays(GL_LINE_STRIP, parts * dl->nr, dl->nr);
- }
-
- for (int nr = 0; nr < dl->nr; nr++) {
- int ofs = 3 * dl->nr;
-
- data = (dl->verts) + 3 * nr;
- parts = dl->parts;
-
- if (dl->flag & DL_CYCL_V) glBegin(GL_LINE_LOOP);
- else glBegin(GL_LINE_STRIP);
-
- while (parts--) {
- glVertex3fv(data);
- data += ofs;
- }
- glEnd();
-
-#if 0
- /* (ton) this code crashes for me when resolv is 86 or higher... no clue */
- glVertexPointer(3, GL_FLOAT, sizeof(float) * 3 * dl->nr, data + 3 * nr);
- if (dl->flag & DL_CYCL_V)
- glDrawArrays(GL_LINE_LOOP, 0, dl->parts);
- else
- glDrawArrays(GL_LINE_STRIP, 0, dl->parts);
#endif
- }
- break;
-
- case DL_INDEX3:
- glVertexPointer(3, GL_FLOAT, 0, dl->verts);
- glDrawElements(GL_TRIANGLES, 3 * dl->parts, GL_UNSIGNED_INT, dl->index);
- break;
-
- case DL_INDEX4:
- glVertexPointer(3, GL_FLOAT, 0, dl->verts);
- glDrawElements(GL_QUADS, 4 * dl->parts, GL_UNSIGNED_INT, dl->index);
- break;
- }
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- return false;
-}
-
-static bool drawDispListwire(ListBase *dlbase, const short ob_type)
-{
- unsigned int dl_mask = 0xffffffff;
-
- /* skip fill-faces for curves & fonts */
- if (ELEM(ob_type, OB_FONT, OB_CURVE)) {
- dl_mask &= ~((1 << DL_INDEX3) | (1 << DL_INDEX4));
- }
-
- return drawDispListwire_ex(dlbase, dl_mask);
-}
-
-static bool index3_nors_incr = true;
-
-static void drawDispListsolid(ListBase *lb, Object *ob, const short dflag,
- const unsigned char ob_wire_col[4], const bool use_glsl)
-{
- GPUVertexAttribs gattribs;
-
- if (lb == NULL) return;
-
- glEnableClientState(GL_VERTEX_ARRAY);
-
- /* track current material, -1 for none (needed for lines) */
- short col = -1;
-
- DispList *dl = lb->first;
- while (dl) {
- const float *data = dl->verts;
- const float *ndata = dl->nors;
-
- switch (dl->type) {
- case DL_SEGM:
- if (ob->type == OB_SURF) {
- if (col != -1) {
- GPU_object_material_unbind();
- col = -1;
- }
-
- if ((dflag & DRAW_CONSTCOLOR) == 0)
- glColor3ubv(ob_wire_col);
-
- // glVertexPointer(3, GL_FLOAT, 0, dl->verts);
- // glDrawArrays(GL_LINE_STRIP, 0, dl->nr);
- glBegin(GL_LINE_STRIP);
- for (int nr = dl->nr; nr; nr--, data += 3)
- glVertex3fv(data);
- glEnd();
- }
- break;
- case DL_POLY:
- if (ob->type == OB_SURF) {
- if (col != -1) {
- GPU_object_material_unbind();
- col = -1;
- }
-
- /* for some reason glDrawArrays crashes here in half of the platforms (not osx) */
- //glVertexPointer(3, GL_FLOAT, 0, dl->verts);
- //glDrawArrays(GL_LINE_LOOP, 0, dl->nr);
-
- glBegin(GL_LINE_LOOP);
- for (int nr = dl->nr; nr; nr--, data += 3)
- glVertex3fv(data);
- glEnd();
- }
- break;
- case DL_SURF:
-
- if (dl->index) {
- if (col != dl->col) {
- GPU_object_material_bind(dl->col + 1, use_glsl ? &gattribs : NULL);
- col = dl->col;
- }
- /* FLAT/SMOOTH shading for surfaces */
- glShadeModel((dl->rt & CU_SMOOTH) ? GL_SMOOTH : GL_FLAT);
-
- glEnableClientState(GL_NORMAL_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, dl->verts);
- glNormalPointer(GL_FLOAT, 0, dl->nors);
- glDrawElements(GL_QUADS, 4 * dl->totindex, GL_UNSIGNED_INT, dl->index);
- glDisableClientState(GL_NORMAL_ARRAY);
- glShadeModel(GL_SMOOTH);
- }
- break;
-
- case DL_INDEX3:
- if (col != dl->col) {
- GPU_object_material_bind(dl->col + 1, use_glsl ? &gattribs : NULL);
- col = dl->col;
- }
-
- glVertexPointer(3, GL_FLOAT, 0, dl->verts);
-
- /* for polys only one normal needed */
- if (index3_nors_incr) {
- glEnableClientState(GL_NORMAL_ARRAY);
- glNormalPointer(GL_FLOAT, 0, dl->nors);
- }
- else
- glNormal3fv(ndata);
-
- glDrawElements(GL_TRIANGLES, 3 * dl->parts, GL_UNSIGNED_INT, dl->index);
-
- if (index3_nors_incr)
- glDisableClientState(GL_NORMAL_ARRAY);
-
- break;
-
- case DL_INDEX4:
- if (col != dl->col) {
- GPU_object_material_bind(dl->col + 1, use_glsl ? &gattribs : NULL);
- col = dl->col;
- }
-
- glEnableClientState(GL_NORMAL_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, dl->verts);
- glNormalPointer(GL_FLOAT, 0, dl->nors);
- glDrawElements(GL_QUADS, 4 * dl->parts, GL_UNSIGNED_INT, dl->index);
- glDisableClientState(GL_NORMAL_ARRAY);
-
- break;
- }
- dl = dl->next;
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glFrontFace(GL_CCW);
-
- if (col != -1) {
- GPU_object_material_unbind();
- }
-}
-
-static void drawCurveDMWired(Object *ob)
-{
- DerivedMesh *dm = ob->derivedFinal;
- dm->drawEdges(dm, 1, 0);
-}
-
-/* return true when nothing was drawn */
-static bool drawCurveDerivedMesh(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, const char dt)
-{
- Object *ob = base->object;
- DerivedMesh *dm = ob->derivedFinal;
-
- if (!dm) {
- return true;
- }
-
- DM_update_materials(dm, ob);
-
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
-
- if (dt > OB_WIRE && dm->getNumPolys(dm)) {
- bool glsl = draw_glsl_material(scene, ob, v3d, dt);
- GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
-
- if (!glsl)
- dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind);
- else
- dm->drawFacesGLSL(dm, GPU_object_material_bind);
-
- GPU_end_object_materials();
- }
- else {
- if (((v3d->flag2 & V3D_RENDER_OVERRIDE) && v3d->drawtype >= OB_SOLID) == 0)
- drawCurveDMWired(ob);
- }
-
- return false;
-}
-
-/**
- * Only called by #drawDispList
- * \return true when nothing was drawn
- */
-static bool drawDispList_nobackface(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
- const char dt, const short dflag, const unsigned char ob_wire_col[4])
-{
- Object *ob = base->object;
- ListBase *lb = NULL;
- DispList *dl;
- Curve *cu;
- const bool render_only = (v3d->flag2 & V3D_RENDER_OVERRIDE) != 0;
- const bool solid = (dt > OB_WIRE);
-
- switch (ob->type) {
- case OB_FONT:
- case OB_CURVE:
- cu = ob->data;
-
- lb = &ob->curve_cache->disp;
-
- if (solid) {
- const bool has_faces = BKE_displist_has_faces(lb);
- dl = lb->first;
- if (dl == NULL) {
- return true;
- }
- if (dl->nors == NULL) BKE_displist_normals_add(lb);
- index3_nors_incr = false;
-
- if (!render_only) {
- /* when we have faces, only draw loose-wire */
- if (has_faces) {
- drawDispListwire_ex(lb, (1 << DL_SEGM));
- }
- else {
- drawDispListwire(lb, ob->type);
- }
- }
-
- if (has_faces == false) {
- /* pass */
- }
- else {
- if (draw_glsl_material(scene, ob, v3d, dt)) {
- GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
- drawDispListsolid(lb, ob, dflag, ob_wire_col, true);
- GPU_end_object_materials();
- }
- else {
- GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
- drawDispListsolid(lb, ob, dflag, ob_wire_col, false);
- GPU_end_object_materials();
- }
- if (cu->editnurb && cu->bevobj == NULL && cu->taperobj == NULL && cu->ext1 == 0.0f && cu->ext2 == 0.0f) {
- cpack(0);
- drawDispListwire(lb, ob->type);
- }
- }
- index3_nors_incr = true;
- }
- else {
- if (!render_only || BKE_displist_has_faces(lb)) {
- return drawDispListwire(lb, ob->type);
- }
- }
- break;
- case OB_SURF:
-
- lb = &ob->curve_cache->disp;
-
- if (solid) {
- dl = lb->first;
- if (dl == NULL) {
- return true;
- }
-
- if (dl->nors == NULL) BKE_displist_normals_add(lb);
-
- if (draw_glsl_material(scene, ob, v3d, dt)) {
- GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
- drawDispListsolid(lb, ob, dflag, ob_wire_col, true);
- GPU_end_object_materials();
- }
- else {
- GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
- drawDispListsolid(lb, ob, dflag, ob_wire_col, false);
- GPU_end_object_materials();
- }
- }
- else {
- return drawDispListwire(lb, ob->type);
- }
- break;
- case OB_MBALL:
-
- if (BKE_mball_is_basis(ob)) {
- lb = &ob->curve_cache->disp;
- if (BLI_listbase_is_empty(lb)) {
- return true;
- }
-
- if (solid) {
-
- if (draw_glsl_material(scene, ob, v3d, dt)) {
- GPU_begin_object_materials(v3d, rv3d, scene, ob, 1, NULL);
- drawDispListsolid(lb, ob, dflag, ob_wire_col, true);
- GPU_end_object_materials();
- }
- else {
- GPU_begin_object_materials(v3d, rv3d, scene, ob, 0, NULL);
- drawDispListsolid(lb, ob, dflag, ob_wire_col, false);
- GPU_end_object_materials();
- }
- }
- else {
- return drawDispListwire(lb, ob->type);
- }
- }
- break;
- }
-
- return false;
-}
-static bool drawDispList(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
- const char dt, const short dflag, const unsigned char ob_wire_col[4])
+#ifdef USE_MESH_DM_SELECT
+static void bbs_mesh_solid__drawCenter(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
{
- bool retval;
-
- /* backface culling */
- if (v3d->flag2 & V3D_BACKFACE_CULLING) {
- /* not all displists use same in/out normal direction convention */
- glEnable(GL_CULL_FACE);
- glCullFace(GL_BACK);
- }
-
-#ifdef SEQUENCER_DAG_WORKAROUND
- ensure_curve_cache(scene, base->object);
-#endif
-
- if (drawCurveDerivedMesh(scene, v3d, rv3d, base, dt) == false) {
- retval = false;
- }
- else {
- Object *ob = base->object;
- GLenum mode;
-
- if (ob->type == OB_MBALL) {
- mode = (ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW;
- }
- else {
- mode = (ob->transflag & OB_NEG_SCALE) ? GL_CCW : GL_CW;
- }
-
- glFrontFace(mode);
-
- retval = drawDispList_nobackface(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
-
- if (mode != GL_CCW) {
- glFrontFace(GL_CCW);
- }
- }
+ drawBMOffset_userData *data = (drawBMOffset_userData *)userData;
+ BMFace *efa = BM_face_at_index(userData, index);
- if (v3d->flag2 & V3D_BACKFACE_CULLING) {
- glDisable(GL_CULL_FACE);
+ if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
+ int selcol;
+ GPU_select_index_get(index + 1, &selcol);
+ immAttrib1u(data->col, selcol);
+ immVertex3fv(data->pos, cent);
}
-
- return retval;
}
-/* *********** drawing for particles ************* */
-static void draw_particle_arrays(int draw_as, int totpoint, int ob_dt, int select)
-{
- /* draw created data arrays */
- switch (draw_as) {
- case PART_DRAW_AXIS:
- case PART_DRAW_CROSS:
- glDrawArrays(GL_LINES, 0, 6 * totpoint);
- break;
- case PART_DRAW_LINE:
- glDrawArrays(GL_LINES, 0, 2 * totpoint);
- break;
- case PART_DRAW_BB:
- if (ob_dt <= OB_WIRE || select)
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- glDrawArrays(GL_QUADS, 0, 4 * totpoint);
- break;
- default:
- glDrawArrays(GL_POINTS, 0, totpoint);
- break;
- }
-}
-static void draw_particle(ParticleKey *state, int draw_as, short draw, float pixsize,
- float imat[4][4], const float draw_line[2], ParticleBillboardData *bb, ParticleDrawData *pdd)
+static void bbs_mesh_face_dot(BMEditMesh *em, DerivedMesh *dm)
{
- float vec[3], vec2[3];
- float *vd = NULL;
- float *cd = NULL;
- float ma_col[3] = {0.0f, 0.0f, 0.0f};
-
- /* null only for PART_DRAW_CIRC */
- if (pdd) {
- vd = pdd->vd;
- cd = pdd->cd;
-
- if (pdd->ma_col) {
- copy_v3_v3(ma_col, pdd->ma_col);
- }
- }
-
- switch (draw_as) {
- case PART_DRAW_DOT:
- {
- if (vd) {
- copy_v3_v3(vd, state->co); pdd->vd += 3;
- }
- if (cd) {
- copy_v3_v3(cd, pdd->ma_col);
- pdd->cd += 3;
- }
- break;
- }
- case PART_DRAW_CROSS:
- case PART_DRAW_AXIS:
- {
- vec[0] = 2.0f * pixsize;
- vec[1] = vec[2] = 0.0;
- mul_qt_v3(state->rot, vec);
- if (draw_as == PART_DRAW_AXIS) {
- if (cd) {
- cd[1] = cd[2] = cd[4] = cd[5] = 0.0;
- cd[0] = cd[3] = 1.0;
- cd[6] = cd[8] = cd[9] = cd[11] = 0.0;
- cd[7] = cd[10] = 1.0;
- cd[13] = cd[12] = cd[15] = cd[16] = 0.0;
- cd[14] = cd[17] = 1.0;
- pdd->cd += 18;
- }
-
- copy_v3_v3(vec2, state->co);
- }
- else {
- if (cd) {
- cd[0] = cd[3] = cd[6] = cd[9] = cd[12] = cd[15] = ma_col[0];
- cd[1] = cd[4] = cd[7] = cd[10] = cd[13] = cd[16] = ma_col[1];
- cd[2] = cd[5] = cd[8] = cd[11] = cd[14] = cd[17] = ma_col[2];
- pdd->cd += 18;
- }
- sub_v3_v3v3(vec2, state->co, vec);
- }
-
- add_v3_v3(vec, state->co);
- copy_v3_v3(pdd->vd, vec); pdd->vd += 3;
- copy_v3_v3(pdd->vd, vec2); pdd->vd += 3;
-
- vec[1] = 2.0f * pixsize;
- vec[0] = vec[2] = 0.0;
- mul_qt_v3(state->rot, vec);
- if (draw_as == PART_DRAW_AXIS) {
- copy_v3_v3(vec2, state->co);
- }
- else {
- sub_v3_v3v3(vec2, state->co, vec);
- }
-
- add_v3_v3(vec, state->co);
- copy_v3_v3(pdd->vd, vec); pdd->vd += 3;
- copy_v3_v3(pdd->vd, vec2); pdd->vd += 3;
-
- vec[2] = 2.0f * pixsize;
- vec[0] = vec[1] = 0.0f;
- mul_qt_v3(state->rot, vec);
- if (draw_as == PART_DRAW_AXIS) {
- copy_v3_v3(vec2, state->co);
- }
- else {
- sub_v3_v3v3(vec2, state->co, vec);
- }
-
- add_v3_v3(vec, state->co);
-
- copy_v3_v3(pdd->vd, vec); pdd->vd += 3;
- copy_v3_v3(pdd->vd, vec2); pdd->vd += 3;
- break;
- }
- case PART_DRAW_LINE:
- {
- copy_v3_v3(vec, state->vel);
- normalize_v3(vec);
- if (draw & PART_DRAW_VEL_LENGTH)
- mul_v3_fl(vec, len_v3(state->vel));
- madd_v3_v3v3fl(pdd->vd, state->co, vec, -draw_line[0]); pdd->vd += 3;
- madd_v3_v3v3fl(pdd->vd, state->co, vec, draw_line[1]); pdd->vd += 3;
- if (cd) {
- cd[0] = cd[3] = ma_col[0];
- cd[1] = cd[4] = ma_col[1];
- cd[2] = cd[5] = ma_col[2];
- pdd->cd += 6;
- }
- break;
- }
- case PART_DRAW_CIRC:
- {
- drawcircball(GL_LINE_LOOP, state->co, pixsize, imat);
- break;
- }
- case PART_DRAW_BB:
- {
- float xvec[3], yvec[3], zvec[3], bb_center[3];
- if (cd) {
- cd[0] = cd[3] = cd[6] = cd[9] = ma_col[0];
- cd[1] = cd[4] = cd[7] = cd[10] = ma_col[1];
- cd[2] = cd[5] = cd[8] = cd[11] = ma_col[2];
- pdd->cd += 12;
- }
-
- copy_v3_v3(bb->vec, state->co);
- copy_v3_v3(bb->vel, state->vel);
-
- psys_make_billboard(bb, xvec, yvec, zvec, bb_center);
-
- add_v3_v3v3(pdd->vd, bb_center, xvec);
- add_v3_v3(pdd->vd, yvec); pdd->vd += 3;
-
- sub_v3_v3v3(pdd->vd, bb_center, xvec);
- add_v3_v3(pdd->vd, yvec); pdd->vd += 3;
-
- sub_v3_v3v3(pdd->vd, bb_center, xvec);
- sub_v3_v3v3(pdd->vd, pdd->vd, yvec); pdd->vd += 3;
+ drawBMOffset_userData data; /* don't use offset */
+ data.bm = em->bm;
+ Gwn_VertFormat *format = immVertexFormat();
+ data.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ data.col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U32, 1, GWN_FETCH_INT);
- add_v3_v3v3(pdd->vd, bb_center, xvec);
- sub_v3_v3v3(pdd->vd, pdd->vd, yvec); pdd->vd += 3;
+ immBindBuiltinProgram(GPU_SHADER_3D_FLAT_COLOR_U32);
- copy_v3_v3(pdd->nd, zvec); pdd->nd += 3;
- copy_v3_v3(pdd->nd, zvec); pdd->nd += 3;
- copy_v3_v3(pdd->nd, zvec); pdd->nd += 3;
- copy_v3_v3(pdd->nd, zvec); pdd->nd += 3;
- break;
- }
- }
-}
-static void draw_particle_data(ParticleSystem *psys, RegionView3D *rv3d,
- ParticleKey *state, int draw_as,
- float imat[4][4], ParticleBillboardData *bb, ParticleDrawData *pdd,
- const float ct, const float pa_size, const float r_tilt, const float pixsize_scale)
-{
- ParticleSettings *part = psys->part;
- float pixsize;
-
- if (psys->parent)
- mul_m4_v3(psys->parent->obmat, state->co);
-
- /* create actual particle data */
- if (draw_as == PART_DRAW_BB) {
- bb->offset[0] = part->bb_offset[0];
- bb->offset[1] = part->bb_offset[1];
- bb->size[0] = part->bb_size[0] * pa_size;
- if (part->bb_align == PART_BB_VEL) {
- float pa_vel = len_v3(state->vel);
- float head = part->bb_vel_head * pa_vel;
- float tail = part->bb_vel_tail * pa_vel;
- bb->size[1] = part->bb_size[1] * pa_size + head + tail;
- /* use offset to adjust the particle center. this is relative to size, so need to divide! */
- if (bb->size[1] > 0.0f)
- bb->offset[1] += (head - tail) / bb->size[1];
- }
- else {
- bb->size[1] = part->bb_size[1] * pa_size;
- }
- bb->tilt = part->bb_tilt * (1.0f - part->bb_rand_tilt * r_tilt);
- bb->time = ct;
- }
+ glPointSize(UI_GetThemeValuef(TH_FACEDOT_SIZE));
- pixsize = ED_view3d_pixel_size(rv3d, state->co) * pixsize_scale;
+ immBeginAtMost(GWN_PRIM_POINTS, em->bm->totface);
+ dm->foreachMappedFaceCenter(dm, bbs_mesh_solid__drawCenter, &data, DM_FOREACH_NOP);
+ immEnd();
- draw_particle(state, draw_as, part->draw, pixsize, imat, part->draw_line, bb, pdd);
+ immUnbindProgram();
}
-/* unified drawing of all new particle systems draw types except dupli ob & group
- * mostly tries to use vertex arrays for speed
- *
- * 1. check that everything is ok & updated
- * 2. start initializing things
- * 3. initialize according to draw type
- * 4. allocate drawing data arrays
- * 5. start filling the arrays
- * 6. draw the arrays
- * 7. clean up
- */
-static void draw_new_particle_system(Scene *scene, View3D *v3d, RegionView3D *rv3d,
- Base *base, ParticleSystem *psys,
- const char ob_dt, const short dflag)
-{
- Object *ob = base->object;
- ParticleEditSettings *pset = PE_settings(scene);
- ParticleSettings *part = psys->part;
- ParticleData *pars = psys->particles;
- ParticleData *pa;
- ParticleKey state, *states = NULL;
- ParticleBillboardData bb;
- ParticleSimulationData sim = {NULL};
- ParticleDrawData *pdd = psys->pdd;
- Material *ma;
- float vel[3], imat[4][4];
- float timestep, pixsize_scale = 1.0f, pa_size, r_tilt, r_length;
- float pa_time, pa_birthtime, pa_dietime, pa_health, intensity;
- float cfra;
- float ma_col[3] = {0.0f, 0.0f, 0.0f};
- int a, totpart, totpoint = 0, totve = 0, drawn, draw_as, totchild = 0;
- bool select = (ob->flag & SELECT) != 0, create_cdata = false, need_v = false;
- GLint polygonmode[2];
- char numstr[32];
- unsigned char tcol[4] = {0, 0, 0, 255};
-
-/* 1. */
- if (part == NULL || !psys_check_enabled(ob, psys, G.is_rendering))
- return;
-
- if (pars == NULL) return;
-
- /* don't draw normal paths in edit mode */
- if (psys_in_edit_mode(scene, psys) && (pset->flag & PE_DRAW_PART) == 0)
- return;
-
- if (part->draw_as == PART_DRAW_REND)
- draw_as = part->ren_as;
- else
- draw_as = part->draw_as;
-
- if (draw_as == PART_DRAW_NOT)
- return;
-
- /* prepare curvemapping tables */
- if ((psys->part->child_flag & PART_CHILD_USE_CLUMP_CURVE) && psys->part->clumpcurve)
- curvemapping_changed_all(psys->part->clumpcurve);
- if ((psys->part->child_flag & PART_CHILD_USE_ROUGH_CURVE) && psys->part->roughcurve)
- curvemapping_changed_all(psys->part->roughcurve);
- if ((psys->part->child_flag & PART_CHILD_USE_TWIST_CURVE) && psys->part->twistcurve)
- curvemapping_changed_all(psys->part->twistcurve);
-
-/* 2. */
- sim.scene = scene;
- sim.ob = ob;
- sim.psys = psys;
- sim.psmd = psys_get_modifier(ob, psys);
-
- if (part->phystype == PART_PHYS_KEYED) {
- if (psys->flag & PSYS_KEYED) {
- psys_count_keyed_targets(&sim);
- if (psys->totkeyed == 0)
- return;
- }
- }
-
- if (select) {
- select = false;
- if (psys_get_current(ob) == psys)
- select = true;
- }
-
- psys->flag |= PSYS_DRAWING;
-
- if (part->type == PART_HAIR && !psys->childcache)
- totchild = 0;
- else
- totchild = psys->totchild * part->disp / 100;
-
- ma = give_current_material(ob, part->omat);
-
- if (v3d->zbuf) glDepthMask(1);
-
- if ((ma) && (part->draw_col == PART_DRAW_COL_MAT)) {
- rgb_float_to_uchar(tcol, &(ma->r));
- copy_v3_v3(ma_col, &ma->r);
- }
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(tcol);
- }
-
- timestep = psys_get_timestep(&sim);
-
- if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) {
- float mat[4][4];
- mul_m4_m4m4(mat, ob->obmat, psys->imat);
- glMultMatrixf(mat);
- }
-
- /* needed for text display */
- invert_m4_m4(ob->imat, ob->obmat);
-
- totpart = psys->totpart;
-
- cfra = BKE_scene_frame_get(scene);
-
- if (draw_as == PART_DRAW_PATH && psys->pathcache == NULL && psys->childcache == NULL)
- draw_as = PART_DRAW_DOT;
-
-/* 3. */
- glLineWidth(1.0f);
-
- switch (draw_as) {
- case PART_DRAW_DOT:
- if (part->draw_size)
- glPointSize(part->draw_size);
- else
- glPointSize(2.0); /* default dot size */
- break;
- case PART_DRAW_CIRC:
- /* calculate view aligned matrix: */
- copy_m4_m4(imat, rv3d->viewinv);
- normalize_v3(imat[0]);
- normalize_v3(imat[1]);
- ATTR_FALLTHROUGH;
- case PART_DRAW_CROSS:
- case PART_DRAW_AXIS:
- /* lets calculate the scale: */
-
- if (part->draw_size == 0.0)
- pixsize_scale = 2.0f;
- else
- pixsize_scale = part->draw_size;
-
- if (draw_as == PART_DRAW_AXIS)
- create_cdata = 1;
- break;
- case PART_DRAW_OB:
- if (part->dup_ob == NULL)
- draw_as = PART_DRAW_DOT;
- else
- draw_as = 0;
- break;
- case PART_DRAW_GR:
- if (part->dup_group == NULL)
- draw_as = PART_DRAW_DOT;
- else
- draw_as = 0;
- break;
- case PART_DRAW_BB:
- if (v3d->camera == NULL && part->bb_ob == NULL) {
- printf("Billboards need an active camera or a target object!\n");
-
- draw_as = part->draw_as = PART_DRAW_DOT;
-
- if (part->draw_size)
- glPointSize(part->draw_size);
- else
- glPointSize(2.0); /* default dot size */
- }
- else if (part->bb_ob)
- bb.ob = part->bb_ob;
- else
- bb.ob = v3d->camera;
-
- bb.align = part->bb_align;
- bb.anim = part->bb_anim;
- bb.lock = part->draw & PART_DRAW_BB_LOCK;
- break;
- case PART_DRAW_PATH:
- break;
- case PART_DRAW_LINE:
- need_v = 1;
- break;
- }
- if (part->draw & PART_DRAW_SIZE && part->draw_as != PART_DRAW_CIRC) {
- copy_m4_m4(imat, rv3d->viewinv);
- normalize_v3(imat[0]);
- normalize_v3(imat[1]);
- }
-
- if (ELEM(draw_as, PART_DRAW_DOT, PART_DRAW_CROSS, PART_DRAW_LINE) &&
- (part->draw_col > PART_DRAW_COL_MAT))
- {
- create_cdata = 1;
- }
-
- if (!create_cdata && pdd && pdd->cdata) {
- MEM_freeN(pdd->cdata);
- pdd->cdata = pdd->cd = NULL;
- }
-
-/* 4. */
- if (draw_as && ELEM(draw_as, PART_DRAW_PATH, PART_DRAW_CIRC) == 0) {
- int partsize = 3 * sizeof(float);
- int create_ndata = 0;
-
- if (!pdd)
- pdd = psys->pdd = MEM_callocN(sizeof(ParticleDrawData), "ParticleDrawData");
-
- if (part->draw_as == PART_DRAW_REND && part->trail_count > 1) {
- partsize *= part->trail_count;
- psys_make_temp_pointcache(ob, psys);
- }
-
- switch (draw_as) {
- case PART_DRAW_AXIS:
- case PART_DRAW_CROSS:
- partsize *= 6;
- if (draw_as != PART_DRAW_CROSS)
- create_cdata = 1;
- break;
- case PART_DRAW_LINE:
- partsize *= 2;
- break;
- case PART_DRAW_BB:
- partsize *= 4;
- create_ndata = 1;
- break;
- }
-
- if (pdd->totpart != totpart + totchild || pdd->partsize != partsize)
- psys_free_pdd(psys);
-
- if (!pdd->vdata)
- pdd->vdata = MEM_calloc_arrayN(totpart + totchild, partsize, "particle_vdata");
- if (create_cdata && !pdd->cdata)
- pdd->cdata = MEM_calloc_arrayN(totpart + totchild, partsize, "particle_cdata");
- if (create_ndata && !pdd->ndata)
- pdd->ndata = MEM_calloc_arrayN(totpart + totchild, partsize, "particle_ndata");
-
- if (part->draw & PART_DRAW_VEL && draw_as != PART_DRAW_LINE) {
- if (!pdd->vedata)
- pdd->vedata = MEM_calloc_arrayN(totpart + totchild, 2 * 3 * sizeof(float), "particle_vedata");
-
- need_v = 1;
- }
- else if (pdd->vedata) {
- /* velocity data not needed, so free it */
- MEM_freeN(pdd->vedata);
- pdd->vedata = NULL;
- }
-
- pdd->vd = pdd->vdata;
- pdd->ved = pdd->vedata;
- pdd->cd = pdd->cdata;
- pdd->nd = pdd->ndata;
- pdd->totpart = totpart + totchild;
- pdd->partsize = partsize;
- }
- else if (psys->pdd) {
- psys_free_pdd(psys);
- MEM_freeN(psys->pdd);
- pdd = psys->pdd = NULL;
- }
-
- if (pdd) {
- pdd->ma_col = ma_col;
- }
-
- psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
-
- /* circles don't use drawdata, so have to add a special case here */
- if ((pdd || draw_as == PART_DRAW_CIRC) && draw_as != PART_DRAW_PATH) {
- /* 5. */
- if (pdd && (pdd->flag & PARTICLE_DRAW_DATA_UPDATED) &&
- (pdd->vedata || part->draw & (PART_DRAW_SIZE | PART_DRAW_NUM | PART_DRAW_HEALTH)) == 0)
- {
- totpoint = pdd->totpoint; /* draw data is up to date */
- }
- else {
- for (a = 0, pa = pars; a < totpart + totchild; a++, pa++) {
- /* setup per particle individual stuff */
- if (a < totpart) {
- if (totchild && (part->draw & PART_DRAW_PARENT) == 0) continue;
- if (pa->flag & PARS_NO_DISP || pa->flag & PARS_UNEXIST) continue;
-
- pa_time = (cfra - pa->time) / pa->lifetime;
- pa_birthtime = pa->time;
- pa_dietime = pa->dietime;
- pa_size = pa->size;
- if (part->phystype == PART_PHYS_BOIDS)
- pa_health = pa->boid->data.health;
- else
- pa_health = -1.0;
-
- r_tilt = 2.0f * (psys_frand(psys, a + 21) - 0.5f);
- r_length = psys_frand(psys, a + 22);
-
- if (part->draw_col > PART_DRAW_COL_MAT) {
- switch (part->draw_col) {
- case PART_DRAW_COL_VEL:
- intensity = len_v3(pa->state.vel) / part->color_vec_max;
- break;
- case PART_DRAW_COL_ACC:
- intensity = len_v3v3(pa->state.vel, pa->prev_state.vel) / ((pa->state.time - pa->prev_state.time) * part->color_vec_max);
- break;
- default:
- intensity = 1.0f; /* should never happen */
- BLI_assert(0);
- break;
- }
- CLAMP(intensity, 0.0f, 1.0f);
- weight_to_rgb(ma_col, intensity);
- }
- }
- else {
- ChildParticle *cpa = &psys->child[a - totpart];
-
- pa_time = psys_get_child_time(psys, cpa, cfra, &pa_birthtime, &pa_dietime);
- pa_size = psys_get_child_size(psys, cpa, cfra, NULL);
-
- pa_health = -1.0;
-
- r_tilt = 2.0f * (psys_frand(psys, a + 21) - 0.5f);
- r_length = psys_frand(psys, a + 22);
- }
-
- drawn = 0;
- if (part->draw_as == PART_DRAW_REND && part->trail_count > 1) {
- float length = part->path_end * (1.0f - part->randlength * r_length);
- int trail_count = part->trail_count * (1.0f - part->randlength * r_length);
- float ct = ((part->draw & PART_ABS_PATH_TIME) ? cfra : pa_time) - length;
- float dt = length / (trail_count ? (float)trail_count : 1.0f);
- int i = 0;
-
- ct += dt;
- for (i = 0; i < trail_count; i++, ct += dt) {
-
- if (part->draw & PART_ABS_PATH_TIME) {
- if (ct < pa_birthtime || ct > pa_dietime)
- continue;
- }
- else if (ct < 0.0f || ct > 1.0f)
- continue;
-
- state.time = (part->draw & PART_ABS_PATH_TIME) ? -ct : -(pa_birthtime + ct * (pa_dietime - pa_birthtime));
- psys_get_particle_on_path(&sim, a, &state, need_v);
-
- draw_particle_data(psys, rv3d,
- &state, draw_as, imat, &bb, psys->pdd,
- ct, pa_size, r_tilt, pixsize_scale);
-
- totpoint++;
- drawn = 1;
- }
- }
- else {
- state.time = cfra;
- if (psys_get_particle_state(&sim, a, &state, 0)) {
-
- draw_particle_data(psys, rv3d,
- &state, draw_as, imat, &bb, psys->pdd,
- pa_time, pa_size, r_tilt, pixsize_scale);
-
- totpoint++;
- drawn = 1;
- }
- }
-
- if (drawn) {
- /* additional things to draw for each particle
- * (velocity, size and number) */
- if ((part->draw & PART_DRAW_VEL) && pdd && pdd->vedata) {
- copy_v3_v3(pdd->ved, state.co);
- pdd->ved += 3;
- mul_v3_v3fl(vel, state.vel, timestep);
- add_v3_v3v3(pdd->ved, state.co, vel);
- pdd->ved += 3;
-
- totve++;
- }
-
- if (part->draw & PART_DRAW_SIZE) {
- setlinestyle(3);
- drawcircball(GL_LINE_LOOP, state.co, pa_size, imat);
- setlinestyle(0);
- }
-
-
- if ((part->draw & PART_DRAW_NUM || part->draw & PART_DRAW_HEALTH) &&
- (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0)
- {
- size_t numstr_len;
- float vec_txt[3];
- char *val_pos = numstr;
- numstr[0] = '\0';
-
- if (part->draw & PART_DRAW_NUM) {
- if (a < totpart && (part->draw & PART_DRAW_HEALTH) && (part->phystype == PART_PHYS_BOIDS)) {
- numstr_len = BLI_snprintf_rlen(val_pos, sizeof(numstr), "%d:%.2f", a, pa_health);
- }
- else {
- numstr_len = BLI_snprintf_rlen(val_pos, sizeof(numstr), "%d", a);
- }
- }
- else {
- if (a < totpart && (part->draw & PART_DRAW_HEALTH) && (part->phystype == PART_PHYS_BOIDS)) {
- numstr_len = BLI_snprintf_rlen(val_pos, sizeof(numstr), "%.2f", pa_health);
- }
- }
-
- if (numstr[0]) {
- /* in path drawing state.co is the end point
- * use worldspace because object matrix is already applied */
- mul_v3_m4v3(vec_txt, ob->imat, state.co);
- view3d_cached_text_draw_add(vec_txt, numstr, numstr_len,
- 10, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, tcol);
- }
- }
- }
- }
- }
- }
-/* 6. */
-
- glGetIntegerv(GL_POLYGON_MODE, polygonmode);
- glEnableClientState(GL_VERTEX_ARRAY);
-
- if (draw_as == PART_DRAW_PATH) {
- ParticleCacheKey **cache, *path;
- float *cdata2 = NULL;
-
- /* setup gl flags */
- if (1) { //ob_dt > OB_WIRE) {
- glEnableClientState(GL_NORMAL_ARRAY);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (part->draw_col == PART_DRAW_COL_MAT)
- glEnableClientState(GL_COLOR_ARRAY);
- }
-
- // XXX test
- GPU_basic_shader_colors(NULL, NULL, 0.0f, 1.0f);
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
- }
-
- if (totchild && (part->draw & PART_DRAW_PARENT) == 0)
- totpart = 0;
- else if (psys->pathcache == NULL)
- totpart = 0;
-
- /* draw actual/parent particles */
- cache = psys->pathcache;
- for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
- path = cache[a];
- if (path->segments > 0) {
- glVertexPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->co);
-
- if (1) { //ob_dt > OB_WIRE) {
- glNormalPointer(GL_FLOAT, sizeof(ParticleCacheKey), path->vel);
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (part->draw_col == PART_DRAW_COL_MAT) {
- glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
- }
- }
- }
-
- glDrawArrays(GL_LINE_STRIP, 0, path->segments + 1);
- }
- }
-
- if (part->type == PART_HAIR) {
- if (part->draw & PART_DRAW_GUIDE_HAIRS) {
- DerivedMesh *hair_dm = psys->hair_out_dm;
-
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
-
- for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
- if (pa->totkey > 1) {
- HairKey *hkey = pa->hair;
-
- glVertexPointer(3, GL_FLOAT, sizeof(HairKey), hkey->world_co);
-
-#if 0 /* XXX use proper theme color here */
- UI_ThemeColor(TH_NORMAL);
#else
- glColor3f(0.58f, 0.67f, 1.0f);
-#endif
-
- glDrawArrays(GL_LINE_STRIP, 0, pa->totkey);
- }
- }
-
- if (hair_dm) {
- MVert *mvert = hair_dm->getVertArray(hair_dm);
- int i;
-
- glColor3f(0.9f, 0.4f, 0.4f);
-
- glBegin(GL_LINES);
- for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
- for (i = 1; i < pa->totkey; ++i) {
- float v1[3], v2[3];
-
- copy_v3_v3(v1, mvert[pa->hair_index + i - 1].co);
- copy_v3_v3(v2, mvert[pa->hair_index + i].co);
-
- mul_m4_v3(ob->obmat, v1);
- mul_m4_v3(ob->obmat, v2);
-
- glVertex3fv(v1);
- glVertex3fv(v2);
- }
- }
- glEnd();
- }
-
- glEnableClientState(GL_NORMAL_ARRAY);
- if ((dflag & DRAW_CONSTCOLOR) == 0)
- if (part->draw_col == PART_DRAW_COL_MAT)
- glEnableClientState(GL_COLOR_ARRAY);
- }
-
- if (part->draw & PART_DRAW_HAIR_GRID) {
- ClothModifierData *clmd = psys->clmd;
- if (clmd) {
- float *gmin = clmd->hair_grid_min;
- float *gmax = clmd->hair_grid_max;
- int *res = clmd->hair_grid_res;
- int i;
-
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
-
- if (select)
- UI_ThemeColor(TH_ACTIVE);
- else
- UI_ThemeColor(TH_WIRE);
- glBegin(GL_LINES);
- glVertex3f(gmin[0], gmin[1], gmin[2]); glVertex3f(gmax[0], gmin[1], gmin[2]);
- glVertex3f(gmax[0], gmin[1], gmin[2]); glVertex3f(gmax[0], gmax[1], gmin[2]);
- glVertex3f(gmax[0], gmax[1], gmin[2]); glVertex3f(gmin[0], gmax[1], gmin[2]);
- glVertex3f(gmin[0], gmax[1], gmin[2]); glVertex3f(gmin[0], gmin[1], gmin[2]);
-
- glVertex3f(gmin[0], gmin[1], gmax[2]); glVertex3f(gmax[0], gmin[1], gmax[2]);
- glVertex3f(gmax[0], gmin[1], gmax[2]); glVertex3f(gmax[0], gmax[1], gmax[2]);
- glVertex3f(gmax[0], gmax[1], gmax[2]); glVertex3f(gmin[0], gmax[1], gmax[2]);
- glVertex3f(gmin[0], gmax[1], gmax[2]); glVertex3f(gmin[0], gmin[1], gmax[2]);
-
- glVertex3f(gmin[0], gmin[1], gmin[2]); glVertex3f(gmin[0], gmin[1], gmax[2]);
- glVertex3f(gmax[0], gmin[1], gmin[2]); glVertex3f(gmax[0], gmin[1], gmax[2]);
- glVertex3f(gmin[0], gmax[1], gmin[2]); glVertex3f(gmin[0], gmax[1], gmax[2]);
- glVertex3f(gmax[0], gmax[1], gmin[2]); glVertex3f(gmax[0], gmax[1], gmax[2]);
- glEnd();
-
- if (select)
- UI_ThemeColorShadeAlpha(TH_ACTIVE, 0, -100);
- else
- UI_ThemeColorShadeAlpha(TH_WIRE, 0, -100);
- glEnable(GL_BLEND);
- glBegin(GL_LINES);
- for (i = 1; i < res[0] - 1; ++i) {
- float f = interpf(gmax[0], gmin[0], (float)i / (float)(res[0] - 1));
- glVertex3f(f, gmin[1], gmin[2]); glVertex3f(f, gmax[1], gmin[2]);
- glVertex3f(f, gmax[1], gmin[2]); glVertex3f(f, gmax[1], gmax[2]);
- glVertex3f(f, gmax[1], gmax[2]); glVertex3f(f, gmin[1], gmax[2]);
- glVertex3f(f, gmin[1], gmax[2]); glVertex3f(f, gmin[1], gmin[2]);
- }
- for (i = 1; i < res[1] - 1; ++i) {
- float f = interpf(gmax[1], gmin[1], (float)i / (float)(res[1] - 1));
- glVertex3f(gmin[0], f, gmin[2]); glVertex3f(gmax[0], f, gmin[2]);
- glVertex3f(gmax[0], f, gmin[2]); glVertex3f(gmax[0], f, gmax[2]);
- glVertex3f(gmax[0], f, gmax[2]); glVertex3f(gmin[0], f, gmax[2]);
- glVertex3f(gmin[0], f, gmax[2]); glVertex3f(gmin[0], f, gmin[2]);
- }
- for (i = 1; i < res[2] - 1; ++i) {
- float f = interpf(gmax[2], gmin[2], (float)i / (float)(res[2] - 1));
- glVertex3f(gmin[0], gmin[1], f); glVertex3f(gmax[0], gmin[1], f);
- glVertex3f(gmax[0], gmin[1], f); glVertex3f(gmax[0], gmax[1], f);
- glVertex3f(gmax[0], gmax[1], f); glVertex3f(gmin[0], gmax[1], f);
- glVertex3f(gmin[0], gmax[1], f); glVertex3f(gmin[0], gmin[1], f);
- }
- glEnd();
- glDisable(GL_BLEND);
-
- glEnableClientState(GL_NORMAL_ARRAY);
- if ((dflag & DRAW_CONSTCOLOR) == 0)
- if (part->draw_col == PART_DRAW_COL_MAT)
- glEnableClientState(GL_COLOR_ARRAY);
- }
- }
- }
-
- /* draw child particles */
- cache = psys->childcache;
- for (a = 0; a < totchild; a++) {
- path = cache[a];
- glVertexPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->co);
-
- if (1) { //ob_dt > OB_WIRE) {
- glNormalPointer(GL_FLOAT, sizeof(ParticleCacheKey), path->vel);
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (part->draw_col == PART_DRAW_COL_MAT) {
- glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
- }
- }
- }
-
- glDrawArrays(GL_LINE_STRIP, 0, path->segments + 1);
- }
-
- /* restore & clean up */
- if (1) { //ob_dt > OB_WIRE) {
- if (part->draw_col == PART_DRAW_COL_MAT)
- glDisableClientState(GL_COLOR_ARRAY);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
-
- if (cdata2) {
- MEM_freeN(cdata2);
- cdata2 = NULL;
- }
-
- if ((part->draw & PART_DRAW_NUM) && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
- cache = psys->pathcache;
-
- for (a = 0, pa = psys->particles; a < totpart; a++, pa++) {
- float vec_txt[3];
- size_t numstr_len = BLI_snprintf_rlen(numstr, sizeof(numstr), "%i", a);
- /* use worldspace because object matrix is already applied */
- mul_v3_m4v3(vec_txt, ob->imat, cache[a]->co);
- view3d_cached_text_draw_add(vec_txt, numstr, numstr_len,
- 10, V3D_CACHE_TEXT_WORLDSPACE | V3D_CACHE_TEXT_ASCII, tcol);
- }
- }
- }
- else if (pdd && ELEM(draw_as, 0, PART_DRAW_CIRC) == 0) {
- glDisableClientState(GL_COLOR_ARRAY);
-
- /* enable point data array */
- if (pdd->vdata) {
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, pdd->vdata);
- }
- else
- glDisableClientState(GL_VERTEX_ARRAY);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (select) {
- UI_ThemeColor(TH_ACTIVE);
-
- if (part->draw_size)
- glPointSize(part->draw_size + 2);
- else
- glPointSize(4.0);
-
- glLineWidth(3.0);
-
- draw_particle_arrays(draw_as, totpoint, ob_dt, 1);
- }
-
- /* restore from select */
- glColor3fv(ma_col);
- }
-
- glPointSize(part->draw_size ? part->draw_size : 2.0);
- glLineWidth(1.0);
-
- /* enable other data arrays */
-
- /* billboards are drawn this way */
- if (pdd->ndata && ob_dt > OB_WIRE) {
- glEnableClientState(GL_NORMAL_ARRAY);
- glNormalPointer(GL_FLOAT, 0, pdd->ndata);
- GPU_basic_shader_colors(NULL, NULL, 0.0f, 1.0f);
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_USE_COLOR);
- }
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if (pdd->cdata) {
- glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer(3, GL_FLOAT, 0, pdd->cdata);
- }
- }
-
- draw_particle_arrays(draw_as, totpoint, ob_dt, 0);
-
- pdd->flag |= PARTICLE_DRAW_DATA_UPDATED;
- pdd->totpoint = totpoint;
- }
-
- if (pdd && pdd->vedata) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glDisableClientState(GL_COLOR_ARRAY);
- cpack(0xC0C0C0);
- }
-
- glVertexPointer(3, GL_FLOAT, 0, pdd->vedata);
-
- glDrawArrays(GL_LINES, 0, 2 * totve);
- }
-
- glPolygonMode(GL_FRONT, polygonmode[0]);
- glPolygonMode(GL_BACK, polygonmode[1]);
-
-/* 7. */
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
-
- if (states)
- MEM_freeN(states);
-
- psys->flag &= ~PSYS_DRAWING;
-
- /* draw data can't be saved for billboards as they must update to target changes */
- if (draw_as == PART_DRAW_BB) {
- psys_free_pdd(psys);
- pdd->flag &= ~PARTICLE_DRAW_DATA_UPDATED;
- }
-
- if (psys->lattice_deform_data) {
- end_latt_deform(psys->lattice_deform_data);
- psys->lattice_deform_data = NULL;
- }
-
- if (pdd) {
- /* drop references to stack memory */
- pdd->ma_col = NULL;
- }
-
- if ((base->flag & OB_FROMDUPLI) && (ob->flag & OB_FROMGROUP)) {
- glLoadMatrixf(rv3d->viewmat);
- }
-}
-
-static void draw_update_ptcache_edit(Scene *scene, Object *ob, PTCacheEdit *edit)
-{
- if (edit->psys && edit->psys->flag & PSYS_HAIR_UPDATED)
- PE_update_object(scene, ob, 0);
-
- /* create path and child path cache if it doesn't exist already */
- if (edit->pathcache == NULL)
- psys_cache_edit_paths(scene, ob, edit, CFRA, G.is_rendering);
-}
-
-static void draw_ptcache_edit(Scene *scene, View3D *v3d, PTCacheEdit *edit)
-{
- ParticleCacheKey **cache, *path, *pkey;
- PTCacheEditPoint *point;
- PTCacheEditKey *key;
- ParticleEditSettings *pset = PE_settings(scene);
- int i, k, totpoint = edit->totpoint, timed = (pset->flag & PE_FADE_TIME) ? pset->fade_frames : 0;
- int totkeys = 1;
- float sel_col[3];
- float nosel_col[3];
- float *pathcol = NULL, *pcol;
-
- if (edit->pathcache == NULL)
- return;
-
- PE_hide_keys_time(scene, edit, CFRA);
-
- /* opengl setup */
- if ((v3d->flag & V3D_ZBUF_SELECT) == 0)
- glDisable(GL_DEPTH_TEST);
-
- /* get selection theme colors */
- UI_GetThemeColor3fv(TH_VERTEX_SELECT, sel_col);
- UI_GetThemeColor3fv(TH_VERTEX, nosel_col);
-
- /* draw paths */
- totkeys = (*edit->pathcache)->segments + 1;
-
- glEnable(GL_BLEND);
- pathcol = MEM_calloc_arrayN(totkeys, 4 * sizeof(float), "particle path color data");
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- if (pset->brushtype == PE_BRUSH_WEIGHT)
- glLineWidth(2.0f);
-
- cache = edit->pathcache;
- for (i = 0, point = edit->points; i < totpoint; i++, point++) {
- path = cache[i];
- glVertexPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->co);
-
- if (point->flag & PEP_HIDE) {
- for (k = 0, pcol = pathcol; k < totkeys; k++, pcol += 4) {
- copy_v3_v3(pcol, path->col);
- pcol[3] = 0.25f;
- }
-
- glColorPointer(4, GL_FLOAT, 4 * sizeof(float), pathcol);
- }
- else if (timed) {
- for (k = 0, pcol = pathcol, pkey = path; k < totkeys; k++, pkey++, pcol += 4) {
- copy_v3_v3(pcol, pkey->col);
- pcol[3] = 1.0f - fabsf((float)(CFRA) -pkey->time) / (float)pset->fade_frames;
- }
-
- glColorPointer(4, GL_FLOAT, 4 * sizeof(float), pathcol);
- }
- else
- glColorPointer(3, GL_FLOAT, sizeof(ParticleCacheKey), path->col);
-
- glDrawArrays(GL_LINE_STRIP, 0, path->segments + 1);
- }
-
- if (pathcol) { MEM_freeN(pathcol); pathcol = pcol = NULL; }
-
-
- /* draw edit vertices */
- if (pset->selectmode != SCE_SELECT_PATH) {
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
-
- if (pset->selectmode == SCE_SELECT_POINT) {
- float *pd = NULL, *pdata = NULL;
- float *cd = NULL, *cdata = NULL;
- int totkeys_visible = 0;
-
- for (i = 0, point = edit->points; i < totpoint; i++, point++)
- if (!(point->flag & PEP_HIDE))
- totkeys_visible += point->totkey;
-
- if (totkeys_visible) {
- if (edit->points && !(edit->points->keys->flag & PEK_USE_WCO))
- pd = pdata = MEM_calloc_arrayN(totkeys_visible, 3 * sizeof(float), "particle edit point data");
- cd = cdata = MEM_calloc_arrayN(totkeys_visible, (timed ? 4 : 3) * sizeof(float), "particle edit color data");
- }
-
- for (i = 0, point = edit->points; i < totpoint; i++, point++) {
- if (point->flag & PEP_HIDE)
- continue;
-
- for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
- if (pd) {
- copy_v3_v3(pd, key->co);
- pd += 3;
- }
-
- if (key->flag & PEK_SELECT) {
- copy_v3_v3(cd, sel_col);
- }
- else {
- copy_v3_v3(cd, nosel_col);
- }
-
- if (timed)
- *(cd + 3) = 1.0f - fabsf((float)CFRA - *key->time) / (float)pset->fade_frames;
-
- cd += (timed ? 4 : 3);
- }
- }
- cd = cdata;
- pd = pdata;
- for (i = 0, point = edit->points; i < totpoint; i++, point++) {
- if (point->flag & PEP_HIDE || point->totkey == 0)
- continue;
-
- if (point->keys->flag & PEK_USE_WCO)
- glVertexPointer(3, GL_FLOAT, sizeof(PTCacheEditKey), point->keys->world_co);
- else
- glVertexPointer(3, GL_FLOAT, 3 * sizeof(float), pd);
-
- glColorPointer((timed ? 4 : 3), GL_FLOAT, (timed ? 4 : 3) * sizeof(float), cd);
-
- glDrawArrays(GL_POINTS, 0, point->totkey);
-
- pd += pd ? 3 * point->totkey : 0;
- cd += (timed ? 4 : 3) * point->totkey;
- }
- if (pdata) { MEM_freeN(pdata); pd = pdata = NULL; }
- if (cdata) { MEM_freeN(cdata); cd = cdata = NULL; }
- }
- else if (pset->selectmode == SCE_SELECT_END) {
- glBegin(GL_POINTS);
- for (i = 0, point = edit->points; i < totpoint; i++, point++) {
- if ((point->flag & PEP_HIDE) == 0 && point->totkey) {
- key = point->keys + point->totkey - 1;
- glColor3fv((key->flag & PEK_SELECT) ? sel_col : nosel_col);
- /* has to be like this.. otherwise selection won't work, have try glArrayElement later..*/
- glVertex3fv((key->flag & PEK_USE_WCO) ? key->world_co : key->co);
- }
- }
- glEnd();
- }
- }
-
- glDisable(GL_BLEND);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_VERTEX_ARRAY);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
-}
-
-static void ob_draw_RE_motion(float com[3], float rotscale[3][3], float itw, float ith, float drw_size)
-{
- float tr[3][3];
- float root[3], tip[3];
- /* take a copy for not spoiling original */
- copy_m3_m3(tr, rotscale);
- float tw = itw * drw_size;
- float th = ith * drw_size;
-
- glBegin(GL_LINES);
-
- glColor4ub(0x7F, 0x00, 0x00, 155);
- root[1] = root[2] = 0.0f;
- root[0] = -drw_size;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- tip[1] = tip[2] = 0.0f;
- tip[0] = drw_size;
- mul_m3_v3(tr, tip);
- add_v3_v3(tip, com);
- glVertex3fv(tip);
-
- root[1] = 0.0f; root[2] = tw;
- root[0] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[1] = 0.0f; root[2] = -tw;
- root[0] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[1] = tw; root[2] = 0.0f;
- root[0] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[1] = -tw; root[2] = 0.0f;
- root[0] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- glColor4ub(0x00, 0x7F, 0x00, 155);
-
- root[0] = root[2] = 0.0f;
- root[1] = -drw_size;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- tip[0] = tip[2] = 0.0f;
- tip[1] = drw_size;
- mul_m3_v3(tr, tip);
- add_v3_v3(tip, com);
- glVertex3fv(tip);
-
- root[0] = 0.0f; root[2] = tw;
- root[1] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[0] = 0.0f; root[2] = -tw;
- root[1] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[0] = tw; root[2] = 0.0f;
- root[1] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[0] = -tw; root[2] = 0.0f;
- root[1] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- glColor4ub(0x00, 0x00, 0x7F, 155);
- root[0] = root[1] = 0.0f;
- root[2] = -drw_size;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- tip[0] = tip[1] = 0.0f;
- tip[2] = drw_size;
- mul_m3_v3(tr, tip);
- add_v3_v3(tip, com);
- glVertex3fv(tip);
-
- root[0] = 0.0f; root[1] = tw;
- root[2] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[0] = 0.0f; root[1] = -tw;
- root[2] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[0] = tw; root[1] = 0.0f;
- root[2] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- root[0] = -tw; root[1] = 0.0f;
- root[2] = th;
- mul_m3_v3(tr, root);
- add_v3_v3(root, com);
- glVertex3fv(root);
- glVertex3fv(tip);
-
- glEnd();
-}
-
-/* place to add drawers */
-
-static void drawhandlesN(Nurb *nu, const char sel, const bool hide_handles)
-{
- if (nu->hide || hide_handles) return;
-
- if (nu->type == CU_BEZIER) {
-
- const float *fp;
-
-#define TH_HANDLE_COL_TOT ((TH_HANDLE_SEL_FREE - TH_HANDLE_FREE) + 1)
- /* use MIN2 when indexing to ensure newer files don't read outside the array */
- unsigned char handle_cols[TH_HANDLE_COL_TOT][3];
- const int basecol = sel ? TH_HANDLE_SEL_FREE : TH_HANDLE_FREE;
-
- for (int a = 0; a < TH_HANDLE_COL_TOT; a++) {
- UI_GetThemeColor3ubv(basecol + a, handle_cols[a]);
- }
-
- glLineWidth(1.0f);
-
- glBegin(GL_LINES);
-
- BezTriple *bezt = nu->bezt;
- int a = nu->pntsu;
- while (a--) {
- if (bezt->hide == 0) {
- if ((bezt->f2 & SELECT) == sel) {
- fp = bezt->vec[0];
-
- glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
- glVertex3fv(fp);
- glVertex3fv(fp + 3);
-
- glColor3ubv(handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]);
- glVertex3fv(fp + 3);
- glVertex3fv(fp + 6);
- }
- else if ((bezt->f1 & SELECT) == sel) {
- fp = bezt->vec[0];
-
- glColor3ubv(handle_cols[MIN2(bezt->h1, TH_HANDLE_COL_TOT - 1)]);
- glVertex3fv(fp);
- glVertex3fv(fp + 3);
- }
- else if ((bezt->f3 & SELECT) == sel) {
- fp = bezt->vec[1];
-
- glColor3ubv(handle_cols[MIN2(bezt->h2, TH_HANDLE_COL_TOT - 1)]);
- glVertex3fv(fp);
- glVertex3fv(fp + 3);
- }
- }
- bezt++;
- }
-
- glEnd();
-
-#undef TH_HANDLE_COL_TOT
-
- }
-}
-
-static void drawhandlesN_active(Nurb *nu)
-{
- if (nu->hide) return;
-
- UI_ThemeColor(TH_ACTIVE_SPLINE);
- glLineWidth(2);
-
- glBegin(GL_LINES);
-
- if (nu->type == CU_BEZIER) {
- BezTriple *bezt = nu->bezt;
- int a = nu->pntsu;
- while (a--) {
- if (bezt->hide == 0) {
- const float *fp = bezt->vec[0];
-
- glVertex3fv(fp);
- glVertex3fv(fp + 3);
-
- glVertex3fv(fp + 3);
- glVertex3fv(fp + 6);
- }
- bezt++;
- }
- }
- glEnd();
-
- glColor3ub(0, 0, 0);
-}
-
-static void drawvertsN(Nurb *nu, const char sel, const bool hide_handles, const void *vert)
-{
- if (nu->hide) return;
-
- const int color = sel ? TH_VERTEX_SELECT : TH_VERTEX;
-
- UI_ThemeColor(color);
-
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
-
- glBegin(GL_POINTS);
-
- if (nu->type == CU_BEZIER) {
-
- BezTriple *bezt = nu->bezt;
- int a = nu->pntsu;
- while (a--) {
- if (bezt->hide == 0) {
- if (sel == 1 && bezt == vert) {
- UI_ThemeColor(TH_ACTIVE_VERT);
-
- if (bezt->f2 & SELECT) glVertex3fv(bezt->vec[1]);
- if (!hide_handles) {
- if (bezt->f1 & SELECT) glVertex3fv(bezt->vec[0]);
- if (bezt->f3 & SELECT) glVertex3fv(bezt->vec[2]);
- }
-
- UI_ThemeColor(color);
- }
- else if (hide_handles) {
- if ((bezt->f2 & SELECT) == sel) glVertex3fv(bezt->vec[1]);
- }
- else {
- if ((bezt->f1 & SELECT) == sel) glVertex3fv(bezt->vec[0]);
- if ((bezt->f2 & SELECT) == sel) glVertex3fv(bezt->vec[1]);
- if ((bezt->f3 & SELECT) == sel) glVertex3fv(bezt->vec[2]);
- }
- }
- bezt++;
- }
- }
- else {
- BPoint *bp = nu->bp;
- int a = nu->pntsu * nu->pntsv;
- while (a--) {
- if (bp->hide == 0) {
- if (bp == vert) {
- UI_ThemeColor(TH_ACTIVE_VERT);
- glVertex3fv(bp->vec);
- UI_ThemeColor(color);
- }
- else {
- if ((bp->f1 & SELECT) == sel) glVertex3fv(bp->vec);
- }
- }
- bp++;
- }
- }
-
- glEnd();
-}
-
-static void editnurb_draw_active_poly(Nurb *nu)
-{
- UI_ThemeColor(TH_ACTIVE_SPLINE);
- glLineWidth(2);
-
- BPoint *bp = nu->bp;
- for (int b = 0; b < nu->pntsv; b++) {
- if (nu->flagu & 1) glBegin(GL_LINE_LOOP);
- else glBegin(GL_LINE_STRIP);
-
- for (int a = 0; a < nu->pntsu; a++, bp++) {
- glVertex3fv(bp->vec);
- }
-
- glEnd();
- }
-
- glColor3ub(0, 0, 0);
-}
-
-static void editnurb_draw_active_nurbs(Nurb *nu)
-{
- UI_ThemeColor(TH_ACTIVE_SPLINE);
- glLineWidth(2);
-
- glBegin(GL_LINES);
- BPoint *bp = nu->bp;
- for (int b = 0; b < nu->pntsv; b++) {
- BPoint *bp1 = bp;
- bp++;
-
- for (int a = nu->pntsu - 1; a > 0; a--, bp++) {
- if (bp->hide == 0 && bp1->hide == 0) {
- glVertex3fv(bp->vec);
- glVertex3fv(bp1->vec);
- }
- bp1 = bp;
- }
- }
-
- if (nu->pntsv > 1) { /* surface */
-
- int ofs = nu->pntsu;
- for (int b = 0; b < nu->pntsu; b++) {
- BPoint *bp1 = nu->bp + b;
- bp = bp1 + ofs;
- for (int a = nu->pntsv - 1; a > 0; a--, bp += ofs) {
- if (bp->hide == 0 && bp1->hide == 0) {
- glVertex3fv(bp->vec);
- glVertex3fv(bp1->vec);
- }
- bp1 = bp;
- }
- }
- }
-
- glEnd();
-
- glColor3ub(0, 0, 0);
-}
-
-static void draw_editnurb_splines(Object *ob, Nurb *nurb, const bool sel)
-{
- BPoint *bp, *bp1;
- int a, b;
- Curve *cu = ob->data;
-
- int index = 0;
- Nurb *nu = nurb;
- while (nu) {
- if (nu->hide == 0) {
- switch (nu->type) {
- case CU_POLY:
- if (!sel && index == cu->actnu) {
- /* we should draw active spline highlight below everything */
- editnurb_draw_active_poly(nu);
- }
-
- glLineWidth(1);
-
- UI_ThemeColor(TH_NURB_ULINE);
- bp = nu->bp;
- for (b = 0; b < nu->pntsv; b++) {
- if (nu->flagu & 1) glBegin(GL_LINE_LOOP);
- else glBegin(GL_LINE_STRIP);
-
- for (a = 0; a < nu->pntsu; a++, bp++) {
- glVertex3fv(bp->vec);
- }
-
- glEnd();
- }
- break;
- case CU_NURBS:
- if (!sel && index == cu->actnu) {
- /* we should draw active spline highlight below everything */
- editnurb_draw_active_nurbs(nu);
- }
-
- glLineWidth(1);
-
- glBegin(GL_LINES);
-
- bp = nu->bp;
- for (b = 0; b < nu->pntsv; b++) {
- bp1 = bp;
- bp++;
- for (a = nu->pntsu - 1; a > 0; a--, bp++) {
- if (bp->hide == 0 && bp1->hide == 0) {
- if (sel) {
- if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) {
- UI_ThemeColor(TH_NURB_SEL_ULINE);
-
- glVertex3fv(bp->vec);
- glVertex3fv(bp1->vec);
- }
- }
- else {
- if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) {
- /* pass */
- }
- else {
- UI_ThemeColor(TH_NURB_ULINE);
-
- glVertex3fv(bp->vec);
- glVertex3fv(bp1->vec);
- }
- }
- }
- bp1 = bp;
- }
- }
-
- if (nu->pntsv > 1) { /* surface */
- int ofs = nu->pntsu;
- for (b = 0; b < nu->pntsu; b++) {
- bp1 = nu->bp + b;
- bp = bp1 + ofs;
- for (a = nu->pntsv - 1; a > 0; a--, bp += ofs) {
- if (bp->hide == 0 && bp1->hide == 0) {
- if (sel) {
- if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) {
- UI_ThemeColor(TH_NURB_SEL_VLINE);
-
- glVertex3fv(bp->vec);
- glVertex3fv(bp1->vec);
- }
- }
- else {
- if ((bp->f1 & SELECT) && (bp1->f1 & SELECT)) {
- /* pass */
- }
- else {
- UI_ThemeColor(TH_NURB_VLINE);
-
- glVertex3fv(bp->vec);
- glVertex3fv(bp1->vec);
- }
- }
- }
- bp1 = bp;
- }
- }
- }
-
- glEnd();
- break;
- }
- }
-
- index++;
- nu = nu->next;
- }
-}
-
-static void draw_editnurb(
- Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base, Nurb *nurb,
- const char dt, const short dflag, const unsigned char ob_wire_col[4])
-{
- ToolSettings *ts = scene->toolsettings;
- Object *ob = base->object;
- Curve *cu = ob->data;
- Nurb *nu;
- const void *vert = BKE_curve_vert_active_get(cu);
- const bool hide_handles = (cu->drawflag & CU_HIDE_HANDLES) != 0;
- unsigned char wire_col[3];
-
- /* DispList */
- UI_GetThemeColor3ubv(TH_WIRE_EDIT, wire_col);
- glColor3ubv(wire_col);
-
- drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
-
- /* for shadows only show solid faces */
- if (v3d->flag2 & V3D_RENDER_SHADOW)
- return;
-
- if (v3d->zbuf) glDepthFunc(GL_ALWAYS);
-
- /* first non-selected and active handles */
- int index = 0;
- for (nu = nurb; nu; nu = nu->next) {
- if (nu->type == CU_BEZIER) {
- if (index == cu->actnu && !hide_handles)
- drawhandlesN_active(nu);
- drawhandlesN(nu, 0, hide_handles);
- }
- index++;
- }
- draw_editnurb_splines(ob, nurb, false);
- draw_editnurb_splines(ob, nurb, true);
- /* selected handles */
- for (nu = nurb; nu; nu = nu->next) {
- if (nu->type == CU_BEZIER && (cu->drawflag & CU_HIDE_HANDLES) == 0)
- drawhandlesN(nu, 1, hide_handles);
- drawvertsN(nu, 0, hide_handles, NULL);
- }
-
- if (v3d->zbuf) glDepthFunc(GL_LEQUAL);
-
- glColor3ubv(wire_col);
-
- /* direction vectors for 3d curve paths
- * when at its lowest, don't render normals */
- if ((cu->flag & CU_3D) && (ts->normalsize > 0.0015f) && (cu->drawflag & CU_HIDE_NORMALS) == 0) {
- BevList *bl;
- glLineWidth(1.0f);
- for (bl = ob->curve_cache->bev.first, nu = nurb; nu && bl; bl = bl->next, nu = nu->next) {
- BevPoint *bevp = bl->bevpoints;
- int nr = bl->nr;
- int skip = nu->resolu / 16;
-
- while (nr-- > 0) { /* accounts for empty bevel lists */
- const float fac = bevp->radius * ts->normalsize;
- float vec_a[3]; /* Offset perpendicular to the curve */
- float vec_b[3]; /* Delta along the curve */
-
- vec_a[0] = fac;
- vec_a[1] = 0.0f;
- vec_a[2] = 0.0f;
-
- mul_qt_v3(bevp->quat, vec_a);
- madd_v3_v3fl(vec_a, bevp->dir, -fac);
-
- reflect_v3_v3v3(vec_b, vec_a, bevp->dir);
- negate_v3(vec_b);
-
- add_v3_v3(vec_a, bevp->vec);
- add_v3_v3(vec_b, bevp->vec);
-
- glBegin(GL_LINE_STRIP);
- glVertex3fv(vec_a);
- glVertex3fv(bevp->vec);
- glVertex3fv(vec_b);
- glEnd();
-
- bevp += skip + 1;
- nr -= skip;
- }
- }
- }
-
- if (v3d->zbuf) glDepthFunc(GL_ALWAYS);
-
- for (nu = nurb; nu; nu = nu->next) {
- drawvertsN(nu, 1, hide_handles, vert);
- }
-
- if (v3d->zbuf) glDepthFunc(GL_LEQUAL);
-}
-
-static void draw_editfont_textcurs(RegionView3D *rv3d, float textcurs[4][2])
-{
- cpack(0);
- ED_view3d_polygon_offset(rv3d, -1.0);
- set_inverted_drawing(1);
- glBegin(GL_QUADS);
- glVertex2fv(textcurs[0]);
- glVertex2fv(textcurs[1]);
- glVertex2fv(textcurs[2]);
- glVertex2fv(textcurs[3]);
- glEnd();
- set_inverted_drawing(0);
- ED_view3d_polygon_offset(rv3d, 0.0);
-}
-
-static void draw_editfont(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
- const char dt, const short dflag, const unsigned char ob_wire_col[4])
-{
- Object *ob = base->object;
- Curve *cu = ob->data;
- EditFont *ef = cu->editfont;
- float vec1[3], vec2[3];
-
- draw_editfont_textcurs(rv3d, ef->textcurs);
-
- if (cu->flag & CU_FAST) {
- cpack(0xFFFFFF);
- set_inverted_drawing(1);
- drawDispList(scene, v3d, rv3d, base, OB_WIRE, dflag, ob_wire_col);
- set_inverted_drawing(0);
- }
- else {
- drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
- }
-
- if (cu->linewidth != 0.0f) {
- UI_ThemeColor(TH_WIRE_EDIT);
- copy_v3_v3(vec1, ob->orig);
- copy_v3_v3(vec2, ob->orig);
- vec1[0] += cu->linewidth;
- vec2[0] += cu->linewidth;
- vec1[1] += cu->linedist * cu->fsize;
- vec2[1] -= cu->lines * cu->linedist * cu->fsize;
- setlinestyle(3);
- glBegin(GL_LINES);
- glVertex2fv(vec1);
- glVertex2fv(vec2);
- glEnd();
- setlinestyle(0);
- }
-
- setlinestyle(3);
- for (int i = 0; i < cu->totbox; i++) {
- if (cu->tb[i].w != 0.0f) {
- UI_ThemeColor(i == (cu->actbox - 1) ? TH_ACTIVE : TH_WIRE);
- vec1[0] = cu->xof + cu->tb[i].x;
- vec1[1] = cu->yof + cu->tb[i].y + cu->fsize;
- vec1[2] = 0.001;
- glBegin(GL_LINE_STRIP);
- glVertex3fv(vec1);
- vec1[0] += cu->tb[i].w;
- glVertex3fv(vec1);
- vec1[1] -= cu->tb[i].h;
- glVertex3fv(vec1);
- vec1[0] -= cu->tb[i].w;
- glVertex3fv(vec1);
- vec1[1] += cu->tb[i].h;
- glVertex3fv(vec1);
- glEnd();
- }
- }
- setlinestyle(0);
-
-
- if (ef->selboxes && ef->selboxes_len) {
- float selboxw;
-
- cpack(0xffffff);
- set_inverted_drawing(1);
- for (int i = 0; i < ef->selboxes_len; i++) {
- EditFontSelBox *sb = &ef->selboxes[i];
- float tvec[3];
-
- if (i + 1 != ef->selboxes_len) {
- if (ef->selboxes[i + 1].y == sb->y)
- selboxw = ef->selboxes[i + 1].x - sb->x;
- else
- selboxw = sb->w;
- }
- else {
- selboxw = sb->w;
- }
-
- /* fill in xy below */
- tvec[2] = 0.001;
-
- glBegin(GL_QUADS);
-
- if (sb->rot == 0.0f) {
- copy_v2_fl2(tvec, sb->x, sb->y);
- glVertex3fv(tvec);
-
- copy_v2_fl2(tvec, sb->x + selboxw, sb->y);
- glVertex3fv(tvec);
-
- copy_v2_fl2(tvec, sb->x + selboxw, sb->y + sb->h);
- glVertex3fv(tvec);
-
- copy_v2_fl2(tvec, sb->x, sb->y + sb->h);
- glVertex3fv(tvec);
- }
- else {
- float mat[2][2];
-
- angle_to_mat2(mat, sb->rot);
-
- copy_v2_fl2(tvec, sb->x, sb->y);
- glVertex3fv(tvec);
-
- copy_v2_fl2(tvec, selboxw, 0.0f);
- mul_m2v2(mat, tvec);
- add_v2_v2(tvec, &sb->x);
- glVertex3fv(tvec);
-
- copy_v2_fl2(tvec, selboxw, sb->h);
- mul_m2v2(mat, tvec);
- add_v2_v2(tvec, &sb->x);
- glVertex3fv(tvec);
-
- copy_v2_fl2(tvec, 0.0f, sb->h);
- mul_m2v2(mat, tvec);
- add_v2_v2(tvec, &sb->x);
- glVertex3fv(tvec);
- }
-
- glEnd();
- }
- set_inverted_drawing(0);
- }
-}
-
-/* draw a sphere for use as an empty drawtype */
-static void draw_empty_sphere(float size)
-{
- static GLuint displist = 0;
-
- if (displist == 0) {
- GLUquadricObj *qobj;
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
-
- glPushMatrix();
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
- gluDisk(qobj, 0.0, 1, 16, 1);
-
- glRotatef(90, 0, 1, 0);
- gluDisk(qobj, 0.0, 1, 16, 1);
-
- glRotatef(90, 1, 0, 0);
- gluDisk(qobj, 0.0, 1, 16, 1);
-
- gluDeleteQuadric(qobj);
-
- glPopMatrix();
- glEndList();
- }
-
- glScalef(size, size, size);
- glCallList(displist);
- glScalef(1.0f / size, 1.0f / size, 1.0f / size);
-}
-
-/* draw a cone for use as an empty drawtype */
-static void draw_empty_cone(float size)
-{
- const float radius = size;
-
- GLUquadricObj *qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
-
- glPushMatrix();
-
- glScalef(radius, size * 2.0f, radius);
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- gluCylinder(qobj, 1.0, 0.0, 1.0, 8, 1);
-
- glPopMatrix();
-
- gluDeleteQuadric(qobj);
-}
-
-static void drawspiral(const float cent[3], float rad, float tmat[4][4], int start)
-{
- float vec[3], vx[3], vy[3];
- const float tot_inv = 1.0f / (float)CIRCLE_RESOL;
- int a;
- bool inverse = false;
- float x, y, fac;
-
- if (start < 0) {
- inverse = true;
- start = -start;
- }
-
- mul_v3_v3fl(vx, tmat[0], rad);
- mul_v3_v3fl(vy, tmat[1], rad);
-
- glBegin(GL_LINE_STRIP);
-
- if (inverse == 0) {
- copy_v3_v3(vec, cent);
- glVertex3fv(vec);
-
- for (a = 0; a < CIRCLE_RESOL; a++) {
- if (a + start >= CIRCLE_RESOL)
- start = -a + 1;
-
- fac = (float)a * tot_inv;
- x = sinval[a + start] * fac;
- y = cosval[a + start] * fac;
-
- vec[0] = cent[0] + (x * vx[0] + y * vy[0]);
- vec[1] = cent[1] + (x * vx[1] + y * vy[1]);
- vec[2] = cent[2] + (x * vx[2] + y * vy[2]);
-
- glVertex3fv(vec);
- }
- }
- else {
- fac = (float)(CIRCLE_RESOL - 1) * tot_inv;
- x = sinval[start] * fac;
- y = cosval[start] * fac;
-
- vec[0] = cent[0] + (x * vx[0] + y * vy[0]);
- vec[1] = cent[1] + (x * vx[1] + y * vy[1]);
- vec[2] = cent[2] + (x * vx[2] + y * vy[2]);
-
- glVertex3fv(vec);
-
- for (a = 0; a < CIRCLE_RESOL; a++) {
- if (a + start >= CIRCLE_RESOL)
- start = -a + 1;
-
- fac = (float)(-a + (CIRCLE_RESOL - 1)) * tot_inv;
- x = sinval[a + start] * fac;
- y = cosval[a + start] * fac;
-
- vec[0] = cent[0] + (x * vx[0] + y * vy[0]);
- vec[1] = cent[1] + (x * vx[1] + y * vy[1]);
- vec[2] = cent[2] + (x * vx[2] + y * vy[2]);
- glVertex3fv(vec);
- }
- }
-
- glEnd();
-}
-
-/* draws a circle on x-z plane given the scaling of the circle, assuming that
- * all required matrices have been set (used for drawing empties) */
-static void drawcircle_size(float size)
-{
- glBegin(GL_LINE_LOOP);
-
- /* coordinates are: cos(degrees * 11.25) = x, sin(degrees * 11.25) = y, 0.0f = z */
- for (short degrees = 0; degrees < CIRCLE_RESOL; degrees++) {
- float x = cosval[degrees];
- float y = sinval[degrees];
-
- glVertex3f(x * size, 0.0f, y * size);
- }
-
- glEnd();
-
-}
-
-/* needs fixing if non-identity matrix used */
-static void drawtube(const float vec[3], float radius, float height, float tmat[4][4])
-{
- float cur[3];
- drawcircball(GL_LINE_LOOP, vec, radius, tmat);
-
- copy_v3_v3(cur, vec);
- cur[2] += height;
-
- drawcircball(GL_LINE_LOOP, cur, radius, tmat);
-
- glBegin(GL_LINES);
- glVertex3f(vec[0] + radius, vec[1], vec[2]);
- glVertex3f(cur[0] + radius, cur[1], cur[2]);
- glVertex3f(vec[0] - radius, vec[1], vec[2]);
- glVertex3f(cur[0] - radius, cur[1], cur[2]);
- glVertex3f(vec[0], vec[1] + radius, vec[2]);
- glVertex3f(cur[0], cur[1] + radius, cur[2]);
- glVertex3f(vec[0], vec[1] - radius, vec[2]);
- glVertex3f(cur[0], cur[1] - radius, cur[2]);
- glEnd();
-}
-
-/* needs fixing if non-identity matrix used */
-static void drawcone(const float vec[3], float radius, float height, float tmat[4][4])
-{
- float cur[3];
-
- copy_v3_v3(cur, vec);
- cur[2] += height;
-
- drawcircball(GL_LINE_LOOP, cur, radius, tmat);
-
- glBegin(GL_LINES);
- glVertex3f(vec[0], vec[1], vec[2]);
- glVertex3f(cur[0] + radius, cur[1], cur[2]);
- glVertex3f(vec[0], vec[1], vec[2]);
- glVertex3f(cur[0] - radius, cur[1], cur[2]);
- glVertex3f(vec[0], vec[1], vec[2]);
- glVertex3f(cur[0], cur[1] + radius, cur[2]);
- glVertex3f(vec[0], vec[1], vec[2]);
- glVertex3f(cur[0], cur[1] - radius, cur[2]);
- glEnd();
-}
-
-/* return true if nothing was drawn */
-static bool drawmball(Scene *scene, View3D *v3d, RegionView3D *rv3d, Base *base,
- const char dt, const short dflag, const unsigned char ob_wire_col[4])
-{
- Object *ob = base->object;
- MetaElem *ml;
- float imat[4][4];
- int code = 1;
-
- MetaBall *mb = ob->data;
-
- if (mb->editelems) {
- if ((G.f & G_PICKSEL) == 0) {
- unsigned char wire_col[4];
- UI_GetThemeColor4ubv(TH_WIRE_EDIT, wire_col);
- glColor3ubv(wire_col);
-
- drawDispList(scene, v3d, rv3d, base, dt, dflag, wire_col);
- }
- ml = mb->editelems->first;
- }
- else {
- if ((base->flag & OB_FROMDUPLI) == 0) {
- drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
- }
- ml = mb->elems.first;
- }
-
- if (ml == NULL) {
- return true;
- }
-
- if (v3d->flag2 & V3D_RENDER_OVERRIDE) {
- return false;
- }
-
- invert_m4_m4(imat, rv3d->viewmatob);
- normalize_v3(imat[0]);
- normalize_v3(imat[1]);
-
- if (mb->editelems == NULL) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(ob_wire_col);
- }
- }
-
- glLineWidth(1.0f);
-
- while (ml) {
- /* draw radius */
- if (mb->editelems) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if ((ml->flag & SELECT) && (ml->flag & MB_SCALE_RAD)) cpack(0xA0A0F0);
- else cpack(0x3030A0);
- }
-
- if (G.f & G_PICKSEL) {
- ml->selcol1 = code;
- GPU_select_load_id(code++);
- }
- }
- drawcircball(GL_LINE_LOOP, &(ml->x), ml->rad, imat);
-
- /* draw stiffness */
- if (mb->editelems) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- if ((ml->flag & SELECT) && !(ml->flag & MB_SCALE_RAD)) cpack(0xA0F0A0);
- else cpack(0x30A030);
- }
-
- if (G.f & G_PICKSEL) {
- ml->selcol2 = code;
- GPU_select_load_id(code++);
- }
- drawcircball(GL_LINE_LOOP, &(ml->x), ml->rad * atanf(ml->s) / (float)M_PI_2, imat);
- }
-
- ml = ml->next;
- }
- return false;
-}
-
-static void draw_forcefield(Object *ob, RegionView3D *rv3d,
- const short dflag, const unsigned char ob_wire_col[4])
-{
- PartDeflect *pd = ob->pd;
- float imat[4][4], tmat[4][4];
- float vec[3] = {0.0, 0.0, 0.0};
- /* scale size of circle etc with the empty drawsize */
- const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
-
- /* calculus here, is reused in PFIELD_FORCE */
- invert_m4_m4(imat, rv3d->viewmatob);
-#if 0
- normalize_v3(imat[0]); /* we don't do this because field doesnt scale either... apart from wind! */
- normalize_v3(imat[1]);
-#endif
-
- if (pd->forcefield == PFIELD_WIND) {
- float force_val = pd->f_strength;
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
- }
-
- unit_m4(tmat);
- force_val *= 0.1f;
- drawcircball(GL_LINE_LOOP, vec, size, tmat);
- vec[2] = 0.5f * force_val;
- drawcircball(GL_LINE_LOOP, vec, size, tmat);
- vec[2] = 1.0f * force_val;
- drawcircball(GL_LINE_LOOP, vec, size, tmat);
- vec[2] = 1.5f * force_val;
- drawcircball(GL_LINE_LOOP, vec, size, tmat);
- vec[2] = 0.0f; /* reset vec for max dist circle */
-
- }
- else if (pd->forcefield == PFIELD_FORCE) {
- float ffall_val = pd->f_power;
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
- drawcircball(GL_LINE_LOOP, vec, size, imat);
- if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.9f - 0.4f / powf(1.5f, ffall_val));
- drawcircball(GL_LINE_LOOP, vec, size * 1.5f, imat);
- if ((dflag & DRAW_CONSTCOLOR) == 0) ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.9f - 0.4f / powf(2.0f, ffall_val));
- drawcircball(GL_LINE_LOOP, vec, size * 2.0f, imat);
- }
- else if (pd->forcefield == PFIELD_VORTEX) {
- float force_val = pd->f_strength;
-
- unit_m4(tmat);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.7f);
- }
-
- if (force_val < 0) {
- drawspiral(vec, size, tmat, 1);
- drawspiral(vec, size, tmat, 16);
- }
- else {
- drawspiral(vec, size, tmat, -1);
- drawspiral(vec, size, tmat, -16);
- }
- }
- else if (pd->forcefield == PFIELD_GUIDE && ob->type == OB_CURVE) {
- Curve *cu = ob->data;
- if ((cu->flag & CU_PATH) && ob->curve_cache->path && ob->curve_cache->path->data) {
- float guidevec1[4], guidevec2[3];
- float mindist = pd->f_strength;
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
- }
-
- /* path end */
- setlinestyle(3);
- where_on_path(ob, 1.0f, guidevec1, guidevec2, NULL, NULL, NULL);
- drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
-
- /* path beginning */
- setlinestyle(0);
- where_on_path(ob, 0.0f, guidevec1, guidevec2, NULL, NULL, NULL);
- drawcircball(GL_LINE_LOOP, guidevec1, mindist, imat);
-
- copy_v3_v3(vec, guidevec1); /* max center */
- }
- }
-
- setlinestyle(3);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- ob_wire_color_blend_theme_id(ob_wire_col, TH_BACK, 0.5f);
- }
-
- if (pd->falloff == PFIELD_FALL_SPHERE) {
- /* as last, guide curve alters it */
- if (pd->flag & PFIELD_USEMAX)
- drawcircball(GL_LINE_LOOP, vec, pd->maxdist, imat);
-
- if (pd->flag & PFIELD_USEMIN)
- drawcircball(GL_LINE_LOOP, vec, pd->mindist, imat);
- }
- else if (pd->falloff == PFIELD_FALL_TUBE) {
- float radius, distance;
-
- unit_m4(tmat);
-
- vec[0] = vec[1] = 0.0f;
- radius = (pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f;
- distance = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
- vec[2] = distance;
- distance = (pd->flag & PFIELD_POSZ) ? -distance : -2.0f * distance;
-
- if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR))
- drawtube(vec, radius, distance, tmat);
-
- radius = (pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f;
- distance = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
- vec[2] = distance;
- distance = (pd->flag & PFIELD_POSZ) ? -distance : -2.0f * distance;
-
- if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR))
- drawtube(vec, radius, distance, tmat);
- }
- else if (pd->falloff == PFIELD_FALL_CONE) {
- float radius, distance;
-
- unit_m4(tmat);
-
- radius = DEG2RADF((pd->flag & PFIELD_USEMAXR) ? pd->maxrad : 1.0f);
- distance = (pd->flag & PFIELD_USEMAX) ? pd->maxdist : 0.0f;
-
- if (pd->flag & (PFIELD_USEMAX | PFIELD_USEMAXR)) {
- drawcone(vec, distance * sinf(radius), distance * cosf(radius), tmat);
- if ((pd->flag & PFIELD_POSZ) == 0)
- drawcone(vec, distance * sinf(radius), -distance * cosf(radius), tmat);
- }
-
- radius = DEG2RADF((pd->flag & PFIELD_USEMINR) ? pd->minrad : 1.0f);
- distance = (pd->flag & PFIELD_USEMIN) ? pd->mindist : 0.0f;
-
- if (pd->flag & (PFIELD_USEMIN | PFIELD_USEMINR)) {
- drawcone(vec, distance * sinf(radius), distance * cosf(radius), tmat);
- if ((pd->flag & PFIELD_POSZ) == 0)
- drawcone(vec, distance * sinf(radius), -distance * cosf(radius), tmat);
- }
- }
- setlinestyle(0);
-}
-
-static void draw_box(const float vec[8][3], bool solid)
-{
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vec);
-
- if (solid) {
- const GLubyte indices[24] = {0, 1, 2, 3, 7, 6, 5, 4, 4, 5, 1, 0, 3, 2, 6, 7, 3, 7, 4, 0, 1, 5, 6, 2};
- glDrawRangeElements(GL_QUADS, 0, 7, 24, GL_UNSIGNED_BYTE, indices);
- }
- else {
- const GLubyte indices[24] = {0, 1, 1, 2, 2, 3, 3, 0, 0, 4, 4, 5, 5, 6, 6, 7, 7, 4, 1, 5, 2, 6, 3, 7};
- glDrawRangeElements(GL_LINES, 0, 7, 24, GL_UNSIGNED_BYTE, indices);
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
-}
-
-static void draw_bb_quadric(BoundBox *bb, char type, bool around_origin)
+static void bbs_mesh_face_dot(BMEditMesh *em, DerivedMesh *UNUSED(dm))
{
- float size[3], cent[3];
- GLUquadricObj *qobj = gluNewQuadric();
-
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
-
- BKE_boundbox_calc_size_aabb(bb, size);
-
- if (around_origin) {
- zero_v3(cent);
- }
- else {
- BKE_boundbox_calc_center_aabb(bb, cent);
- }
-
- glPushMatrix();
- if (type == OB_BOUND_SPHERE) {
- float scale = MAX3(size[0], size[1], size[2]);
- glTranslate3fv(cent);
- glScalef(scale, scale, scale);
- gluSphere(qobj, 1.0, 8, 5);
- }
- else if (type == OB_BOUND_CYLINDER) {
- float radius = size[0] > size[1] ? size[0] : size[1];
- glTranslatef(cent[0], cent[1], cent[2] - size[2]);
- glScalef(radius, radius, 2.0f * size[2]);
- gluCylinder(qobj, 1.0, 1.0, 1.0, 8, 1);
- }
- else if (type == OB_BOUND_CONE) {
- float radius = size[0] > size[1] ? size[0] : size[1];
- glTranslatef(cent[0], cent[1], cent[2] - size[2]);
- glScalef(radius, radius, 2.0f * size[2]);
- gluCylinder(qobj, 1.0, 0.0, 1.0, 8, 1);
- }
- else if (type == OB_BOUND_CAPSULE) {
- float radius = size[0] > size[1] ? size[0] : size[1];
- float length = size[2] > radius ? 2.0f * (size[2] - radius) : 0.0f;
- glTranslatef(cent[0], cent[1], cent[2] - length * 0.5f);
- gluCylinder(qobj, radius, radius, length, 8, 1);
- gluSphere(qobj, radius, 8, 4);
- glTranslatef(0.0, 0.0, length);
- gluSphere(qobj, radius, 8, 4);
- }
- glPopMatrix();
-
- gluDeleteQuadric(qobj);
+ Mesh *me = em->ob->data;
+ Gwn_Batch *batch = DRW_mesh_batch_cache_get_facedots_with_select_id(me, 1);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_FLAT_COLOR_U32);
+ GWN_batch_draw(batch);
}
-
-static void draw_bounding_volume(Object *ob, char type)
-{
- BoundBox bb_local;
- BoundBox *bb = NULL;
-
- if (ob->type == OB_MESH) {
- bb = BKE_mesh_boundbox_get(ob);
- }
- else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
- bb = BKE_curve_boundbox_get(ob);
- }
- else if (ob->type == OB_MBALL) {
- if (BKE_mball_is_basis(ob)) {
- bb = ob->bb;
- }
- }
- else if (ob->type == OB_ARMATURE) {
- bb = BKE_armature_boundbox_get(ob);
- }
- else if (ob->type == OB_LATTICE) {
- bb = BKE_lattice_boundbox_get(ob);
- }
- else {
- const float min[3] = {-1.0f, -1.0f, -1.0f}, max[3] = {1.0f, 1.0f, 1.0f};
- bb = &bb_local;
- BKE_boundbox_init_from_minmax(bb, min, max);
- }
-
- if (bb == NULL)
- return;
-
- if (ob->gameflag & OB_BOUNDS) { /* bounds need to be drawn around origin for game engine */
-
- if (type == OB_BOUND_BOX) {
- float vec[8][3], size[3];
-
- BKE_boundbox_calc_size_aabb(bb, size);
-
- vec[0][0] = vec[1][0] = vec[2][0] = vec[3][0] = -size[0];
- vec[4][0] = vec[5][0] = vec[6][0] = vec[7][0] = +size[0];
- vec[0][1] = vec[1][1] = vec[4][1] = vec[5][1] = -size[1];
- vec[2][1] = vec[3][1] = vec[6][1] = vec[7][1] = +size[1];
- vec[0][2] = vec[3][2] = vec[4][2] = vec[7][2] = -size[2];
- vec[1][2] = vec[2][2] = vec[5][2] = vec[6][2] = +size[2];
-
- draw_box(vec, false);
- }
- else {
- draw_bb_quadric(bb, type, true);
- }
- }
- else {
- if (type == OB_BOUND_BOX)
- draw_box(bb->vec, false);
- else
- draw_bb_quadric(bb, type, false);
- }
-}
-
-static void drawtexspace(Object *ob)
-{
- float vec[8][3], loc[3], size[3];
-
- if (ob->type == OB_MESH) {
- BKE_mesh_texspace_get(ob->data, loc, NULL, size);
- }
- else if (ELEM(ob->type, OB_CURVE, OB_SURF, OB_FONT)) {
- BKE_curve_texspace_get(ob->data, loc, NULL, size);
- }
- else if (ob->type == OB_MBALL) {
- MetaBall *mb = ob->data;
- copy_v3_v3(size, mb->size);
- copy_v3_v3(loc, mb->loc);
- }
- else {
- return;
- }
-
- vec[0][0] = vec[1][0] = vec[2][0] = vec[3][0] = loc[0] - size[0];
- vec[4][0] = vec[5][0] = vec[6][0] = vec[7][0] = loc[0] + size[0];
-
- vec[0][1] = vec[1][1] = vec[4][1] = vec[5][1] = loc[1] - size[1];
- vec[2][1] = vec[3][1] = vec[6][1] = vec[7][1] = loc[1] + size[1];
-
- vec[0][2] = vec[3][2] = vec[4][2] = vec[7][2] = loc[2] - size[2];
- vec[1][2] = vec[2][2] = vec[5][2] = vec[6][2] = loc[2] + size[2];
-
- setlinestyle(2);
-
- draw_box(vec, false);
-
- setlinestyle(0);
-}
-
-/* draws wire outline */
-static void draw_object_selected_outline(
- Scene *scene, View3D *v3d, ARegion *ar, Base *base,
- const unsigned char ob_wire_col[4])
-{
- RegionView3D *rv3d = ar->regiondata;
- Object *ob = base->object;
-
- glDepthMask(0);
-
- if (ELEM(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
- bool has_faces = false;
-
-#ifdef SEQUENCER_DAG_WORKAROUND
- ensure_curve_cache(scene, ob);
#endif
- DerivedMesh *dm = ob->derivedFinal;
- if (dm) {
- DM_update_materials(dm, ob);
- }
-
- if (dm) {
- has_faces = (dm->getNumPolys(dm) != 0);
- }
- else {
- has_faces = BKE_displist_has_faces(&ob->curve_cache->disp);
- }
-
- if (has_faces && ED_view3d_boundbox_clip(rv3d, ob->bb)) {
- glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f);
- if (dm) {
- draw_mesh_object_outline(v3d, ob, dm);
- }
- else {
- /* only draw 'solid' parts of the display list as wire. */
- drawDispListwire_ex(&ob->curve_cache->disp, (DL_INDEX3 | DL_INDEX4 | DL_SURF));
- }
- }
- }
- else if (ob->type == OB_MBALL) {
- if (BKE_mball_is_basis(ob)) {
- if ((base->flag & OB_FROMDUPLI) == 0) {
- glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f);
- drawDispListwire(&ob->curve_cache->disp, ob->type);
- }
- }
- }
- else if (ob->type == OB_ARMATURE) {
- if (!(ob->mode & OB_MODE_POSE && base == scene->basact)) {
- glLineWidth(UI_GetThemeValuef(TH_OUTLINE_WIDTH) * 2.0f);
- draw_armature(scene, v3d, ar, base, OB_WIRE, 0, ob_wire_col, true);
- }
- }
-
- glDepthMask(1);
-}
-
-static void draw_wire_extra(Scene *scene, RegionView3D *rv3d, Object *ob, const unsigned char ob_wire_col[4])
-{
- if (ELEM(ob->type, OB_FONT, OB_CURVE, OB_SURF, OB_MBALL)) {
-
- if (scene->obedit == ob) {
- UI_ThemeColor(TH_WIRE_EDIT);
- }
- else {
- glColor3ubv(ob_wire_col);
- }
-
- ED_view3d_polygon_offset(rv3d, 1.0);
- glDepthMask(0); /* disable write in zbuffer, selected edge wires show better */
- glLineWidth(1);
-
- if (ELEM(ob->type, OB_FONT, OB_CURVE, OB_SURF)) {
- if (ED_view3d_boundbox_clip(rv3d, ob->bb)) {
-
- if (ob->derivedFinal) {
- drawCurveDMWired(ob);
- }
- else {
- drawDispListwire(&ob->curve_cache->disp, ob->type);
- }
- }
- }
- else if (ob->type == OB_MBALL) {
- if (BKE_mball_is_basis(ob)) {
- drawDispListwire(&ob->curve_cache->disp, ob->type);
- }
- }
-
- glDepthMask(1);
- ED_view3d_polygon_offset(rv3d, 0.0);
- }
-}
-
-/* should be called in view space */
-static void draw_hooks(Object *ob)
-{
- for (ModifierData *md = ob->modifiers.first; md; md = md->next) {
- if (md->type == eModifierType_Hook) {
- HookModifierData *hmd = (HookModifierData *) md;
- float vec[3];
-
- mul_v3_m4v3(vec, ob->obmat, hmd->cent);
-
- if (hmd->object) {
- setlinestyle(3);
- glBegin(GL_LINES);
- glVertex3fv(hmd->object->obmat[3]);
- glVertex3fv(vec);
- glEnd();
- setlinestyle(0);
- }
-
- glPointSize(3.0);
- glBegin(GL_POINTS);
- glVertex3fv(vec);
- glEnd();
- }
- }
-}
-
-static void draw_rigid_body_pivot(bRigidBodyJointConstraint *data,
- const short dflag, const unsigned char ob_wire_col[4])
-{
- const char *axis_str[3] = {"px", "py", "pz"};
- float mat[4][4];
-
- eul_to_mat4(mat, &data->axX);
- glLineWidth(4.0f);
- setlinestyle(2);
- for (int axis = 0; axis < 3; axis++) {
- float dir[3] = {0, 0, 0};
- float v[3];
-
- copy_v3_v3(v, &data->pivX);
-
- dir[axis] = 1.0f;
- glBegin(GL_LINES);
- mul_m4_v3(mat, dir);
- add_v3_v3(v, dir);
- glVertex3fv(&data->pivX);
- glVertex3fv(v);
- glEnd();
-
- /* when const color is set wirecolor is NULL - we could get the current color but
- * with selection and group instancing its not needed to draw the text */
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- view3d_cached_text_draw_add(v, axis_str[axis], 2, 0, V3D_CACHE_TEXT_ASCII, ob_wire_col);
- }
- }
-
- setlinestyle(0);
-}
-
-static void draw_object_wire_color(Scene *scene, Base *base, unsigned char r_ob_wire_col[4])
-{
- Object *ob = base->object;
- int colindex = 0;
- const bool is_edit = (ob->mode & OB_MODE_EDIT) != 0;
- /* confusing logic here, there are 2 methods of setting the color
- * 'colortab[colindex]' and 'theme_id', colindex overrides theme_id.
- *
- * note: no theme yet for 'colindex' */
- int theme_id = is_edit ? TH_WIRE_EDIT : TH_WIRE;
- int theme_shade = 0;
-
- if ((scene->obedit == NULL) &&
- (G.moving & G_TRANSFORM_OBJ) &&
- (base->flag & (SELECT + BA_WAS_SEL)))
- {
- theme_id = TH_TRANSFORM;
- }
- else {
- /* Sets the 'colindex' */
- if (ID_IS_LINKED(ob)) {
- colindex = (base->flag & (SELECT + BA_WAS_SEL)) ? 2 : 1;
- }
- /* Sets the 'theme_id' or fallback to wire */
- else {
- if (ob->flag & OB_FROMGROUP) {
- if (base->flag & (SELECT + BA_WAS_SEL)) {
- /* uses darker active color for non-active + selected */
- theme_id = TH_GROUP_ACTIVE;
-
- if (scene->basact != base) {
- theme_shade = -32;
- }
- }
- else {
- theme_id = TH_GROUP;
- }
- }
- else {
- if (base->flag & (SELECT + BA_WAS_SEL)) {
- theme_id = scene->basact == base ? TH_ACTIVE : TH_SELECT;
- }
- else {
- if (ob->type == OB_LAMP) theme_id = TH_LAMP;
- else if (ob->type == OB_SPEAKER) theme_id = TH_SPEAKER;
- else if (ob->type == OB_CAMERA) theme_id = TH_CAMERA;
- else if (ob->type == OB_EMPTY) theme_id = TH_EMPTY;
- /* fallback to TH_WIRE */
- }
- }
- }
- }
-
- /* finally set the color */
- if (colindex == 0) {
- if (theme_shade == 0) UI_GetThemeColor3ubv(theme_id, r_ob_wire_col);
- else UI_GetThemeColorShade3ubv(theme_id, theme_shade, r_ob_wire_col);
- }
- else {
- cpack_cpy_3ub(r_ob_wire_col, colortab[colindex]);
- }
-
- /* no reason to use this but some functions take col[4] */
- r_ob_wire_col[3] = 255;
-}
-
-static void draw_object_matcap_check(View3D *v3d, Object *ob)
-{
- /* fixed rule, active object draws as matcap */
- BLI_assert((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) == 0);
- (void)ob;
-
- if (v3d->defmaterial == NULL) {
- extern Material defmaterial;
-
- v3d->defmaterial = MEM_mallocN(sizeof(Material), "matcap material");
- *(v3d->defmaterial) = defmaterial;
- BLI_listbase_clear(&v3d->defmaterial->gpumaterial);
- v3d->defmaterial->preview = NULL;
- }
- /* first time users */
- if (v3d->matcap_icon < ICON_MATCAP_01 ||
- v3d->matcap_icon > ICON_MATCAP_24)
- {
- v3d->matcap_icon = ICON_MATCAP_01;
- }
-
- if (v3d->defmaterial->preview == NULL)
- v3d->defmaterial->preview = UI_icon_to_preview(v3d->matcap_icon);
-
- /* signal to all material checks, gets cleared below */
- v3d->flag2 |= V3D_SHOW_SOLID_MATCAP;
-}
-
-static void draw_rigidbody_shape(Object *ob)
-{
- BoundBox *bb = NULL;
- float size[3], vec[8][3];
-
- if (ob->type == OB_MESH) {
- bb = BKE_mesh_boundbox_get(ob);
- }
-
- if (bb == NULL)
- return;
-
- switch (ob->rigidbody_object->shape) {
- case RB_SHAPE_BOX:
- BKE_boundbox_calc_size_aabb(bb, size);
-
- vec[0][0] = vec[1][0] = vec[2][0] = vec[3][0] = -size[0];
- vec[4][0] = vec[5][0] = vec[6][0] = vec[7][0] = +size[0];
- vec[0][1] = vec[1][1] = vec[4][1] = vec[5][1] = -size[1];
- vec[2][1] = vec[3][1] = vec[6][1] = vec[7][1] = +size[1];
- vec[0][2] = vec[3][2] = vec[4][2] = vec[7][2] = -size[2];
- vec[1][2] = vec[2][2] = vec[5][2] = vec[6][2] = +size[2];
-
- draw_box(vec, false);
- break;
- case RB_SHAPE_SPHERE:
- draw_bb_quadric(bb, OB_BOUND_SPHERE, true);
- break;
- case RB_SHAPE_CONE:
- draw_bb_quadric(bb, OB_BOUND_CONE, true);
- break;
- case RB_SHAPE_CYLINDER:
- draw_bb_quadric(bb, OB_BOUND_CYLINDER, true);
- break;
- case RB_SHAPE_CAPSULE:
- draw_bb_quadric(bb, OB_BOUND_CAPSULE, true);
- break;
- }
-}
-
-/**
- * main object drawing function, draws in selection
- * \param dflag (draw flag) can be DRAW_PICKING and/or DRAW_CONSTCOLOR, DRAW_SCENESET
- */
-void draw_object(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short dflag)
-{
- ModifierData *md = NULL;
- Object *ob = base->object;
- Curve *cu;
- RegionView3D *rv3d = ar->regiondata;
- unsigned int col = 0;
- unsigned char _ob_wire_col[4]; /* dont initialize this */
- const unsigned char *ob_wire_col = NULL; /* dont initialize this, use NULL crashes as a way to find invalid use */
- bool zbufoff = false, is_paint = false, empty_object = false;
- const bool is_obact = (ob == OBACT);
- const bool render_override = (v3d->flag2 & V3D_RENDER_OVERRIDE) != 0;
- const bool is_picking = (G.f & G_PICKSEL) != 0;
- const bool has_particles = (ob->particlesystem.first != NULL);
- bool skip_object = false; /* Draw particles but not their emitter object. */
- SmokeModifierData *smd = NULL;
-
- if (ob != scene->obedit) {
- if (ob->restrictflag & OB_RESTRICT_VIEW)
- return;
-
- if (render_override) {
- if (ob->restrictflag & OB_RESTRICT_RENDER)
- return;
-
- if (!has_particles && (ob->transflag & (OB_DUPLI & ~OB_DUPLIFRAMES)))
- return;
- }
- }
-
- if (has_particles) {
- /* XXX particles are not safe for simultaneous threaded render */
- if (G.is_rendering) {
- return;
- }
-
- if (ob->mode == OB_MODE_OBJECT) {
- ParticleSystem *psys;
-
- skip_object = render_override;
- for (psys = ob->particlesystem.first; psys; psys = psys->next) {
- /* Once we have found a psys which renders its emitter object, we are done. */
- if (psys->part->draw & PART_DRAW_EMITTER) {
- skip_object = false;
- break;
- }
- }
- }
- }
-
- if (((base->flag & OB_FROMDUPLI) == 0) &&
- (md = modifiers_findByType(ob, eModifierType_Smoke)) &&
- (modifier_isEnabled(scene, md, eModifierMode_Realtime)))
- {
- smd = (SmokeModifierData *)md;
-
- if (smd->domain) {
- if (!v3d->transp && (dflag & DRAW_PICKING) == 0) {
- if (!v3d->xray && !(ob->dtx & OB_DRAWXRAY)) {
- /* object has already been drawn so skip drawing it */
- ED_view3d_after_add(&v3d->afterdraw_transp, base, dflag);
- return;
- }
- else if (v3d->xray) {
- /* object has already been drawn so skip drawing it */
- ED_view3d_after_add(&v3d->afterdraw_xraytransp, base, dflag);
- return;
- }
- }
- }
- }
-
-
- /* xray delay? */
- if ((dflag & DRAW_PICKING) == 0 && (base->flag & OB_FROMDUPLI) == 0 && (v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
- /* don't do xray in particle mode, need the z-buffer */
- if (!(ob->mode & OB_MODE_PARTICLE_EDIT)) {
- /* xray and transp are set when it is drawing the 2nd/3rd pass */
- if (!v3d->xray && !v3d->transp && (ob->dtx & OB_DRAWXRAY) && !(ob->dtx & OB_DRAWTRANSP)) {
- ED_view3d_after_add(&v3d->afterdraw_xray, base, dflag);
- return;
- }
-
- /* allow transp option for empty images */
- if (ob->type == OB_EMPTY && ob->empty_drawtype == OB_EMPTY_IMAGE) {
- if (!v3d->xray && !v3d->transp && !(ob->dtx & OB_DRAWXRAY) && (ob->dtx & OB_DRAWTRANSP)) {
- ED_view3d_after_add(&v3d->afterdraw_transp, base, dflag);
- return;
- }
- }
- }
- }
-
-
- /* -------------------------------------------------------------------- */
- /* no return after this point, otherwise leaks */
-
- /* only once set now, will be removed too, should become a global standard */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- /* reset here to avoid having to call all over */
- glLineWidth(1.0f);
-
- view3d_cached_text_draw_begin();
-
- /* draw motion paths (in view space) */
- if (ob->mpath && !render_override) {
- bAnimVizSettings *avs = &ob->avs;
-
- /* setup drawing environment for paths */
- draw_motion_paths_init(v3d, ar);
-
- /* draw motion path for object */
- draw_motion_path_instance(scene, ob, NULL, avs, ob->mpath);
-
- /* cleanup after drawing */
- draw_motion_paths_cleanup(v3d);
- }
-
- /* multiply view with object matrix.
- * local viewmat and persmat, to calculate projections */
- ED_view3d_init_mats_rv3d_gl(ob, rv3d);
-
- /* which wire color */
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
-
- ED_view3d_project_base(ar, base);
-
- draw_object_wire_color(scene, base, _ob_wire_col);
- ob_wire_col = _ob_wire_col;
-
- glColor3ubv(ob_wire_col);
- }
-
- /* maximum drawtype */
- char dt = v3d->drawtype;
- if (dt == OB_RENDER) dt = v3d->prev_drawtype;
- dt = MIN2(dt, ob->dt);
- if (v3d->zbuf == 0 && dt > OB_WIRE) dt = OB_WIRE;
- short dtx = 0;
-
-
- /* faceselect exception: also draw solid when (dt == wire), except in editmode */
- if (is_obact) {
- if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) {
- if (ob->type == OB_MESH) {
- if (dt < OB_SOLID) {
- zbufoff = true;
- dt = OB_SOLID;
- }
-
- if (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)) {
- dt = OB_PAINT;
- }
-
- is_paint = true;
- glEnable(GL_DEPTH_TEST);
- }
- }
- }
-
- /* matcap check - only when not painting color */
- if ((v3d->flag2 & V3D_SOLID_MATCAP) &&
- (dt == OB_SOLID) &&
- (is_paint == false && is_picking == false) &&
- ((v3d->flag2 & V3D_RENDER_SHADOW) == 0))
- {
- draw_object_matcap_check(v3d, ob);
- }
-
- /* draw-extra supported for boundbox drawmode too */
- if (dt >= OB_BOUNDBOX) {
- dtx = ob->dtx;
- if (ob->mode & OB_MODE_EDIT) {
- /* the only 2 extra drawtypes alowed in editmode */
- dtx = dtx & (OB_DRAWWIRE | OB_TEXSPACE);
- }
- }
-
- if (!skip_object) {
- /* draw outline for selected objects, mesh does itself */
- if ((v3d->flag & V3D_SELECT_OUTLINE) && !render_override && ob->type != OB_MESH) {
- if (dt > OB_WIRE && (ob->mode & OB_MODE_EDIT) == 0 && (dflag & DRAW_SCENESET) == 0) {
- if (!(ob->dtx & OB_DRAWWIRE) && (ob->flag & SELECT) && !(dflag & (DRAW_PICKING | DRAW_CONSTCOLOR))) {
- draw_object_selected_outline(scene, v3d, ar, base, ob_wire_col);
- }
- }
- }
-
- switch (ob->type) {
- case OB_MESH:
- empty_object = draw_mesh_object(scene, ar, v3d, rv3d, base, dt, ob_wire_col, dflag);
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- /* mesh draws wire itself */
- dtx &= ~OB_DRAWWIRE;
- }
-
- break;
- case OB_FONT:
- cu = ob->data;
- if (cu->editfont) {
- draw_editfont(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
- }
- else if (dt == OB_BOUNDBOX) {
- if ((render_override && v3d->drawtype >= OB_WIRE) == 0) {
-#ifdef SEQUENCER_DAG_WORKAROUND
- ensure_curve_cache(scene, base->object);
-#endif
- draw_bounding_volume(ob, ob->boundtype);
- }
- }
- else if (ED_view3d_boundbox_clip(rv3d, ob->bb)) {
- empty_object = drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
- }
-
- break;
- case OB_CURVE:
- case OB_SURF:
- cu = ob->data;
-
- if (cu->editnurb) {
- ListBase *nurbs = BKE_curve_editNurbs_get(cu);
- draw_editnurb(scene, v3d, rv3d, base, nurbs->first, dt, dflag, ob_wire_col);
- }
- else if (dt == OB_BOUNDBOX) {
- if ((render_override && (v3d->drawtype >= OB_WIRE)) == 0) {
-#ifdef SEQUENCER_DAG_WORKAROUND
- ensure_curve_cache(scene, base->object);
-#endif
- draw_bounding_volume(ob, ob->boundtype);
- }
- }
- else if (ED_view3d_boundbox_clip(rv3d, ob->bb)) {
- empty_object = drawDispList(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
- }
- break;
- case OB_MBALL:
- {
- MetaBall *mb = ob->data;
-
- if (mb->editelems)
- drawmball(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
- else if (dt == OB_BOUNDBOX) {
- if ((render_override && (v3d->drawtype >= OB_WIRE)) == 0) {
-#ifdef SEQUENCER_DAG_WORKAROUND
- ensure_curve_cache(scene, base->object);
-#endif
- draw_bounding_volume(ob, ob->boundtype);
- }
- }
- else
- empty_object = drawmball(scene, v3d, rv3d, base, dt, dflag, ob_wire_col);
- break;
- }
- case OB_EMPTY:
- if (!render_override) {
- if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
- draw_empty_image(ob, dflag, ob_wire_col, v3d->multiview_eye);
- }
- else {
- drawaxes(rv3d->viewmatob, ob->empty_drawsize, ob->empty_drawtype);
- }
- }
- break;
- case OB_LAMP:
- if (!render_override) {
- drawlamp(v3d, rv3d, base, dt, dflag, ob_wire_col, is_obact);
- }
- break;
- case OB_CAMERA:
- if (!render_override ||
- (rv3d->persp == RV3D_CAMOB && v3d->camera == ob)) /* special exception for active camera */
- {
- drawcamera(scene, v3d, rv3d, base, dflag, ob_wire_col);
- }
- break;
- case OB_SPEAKER:
- if (!render_override)
- drawspeaker(scene, v3d, rv3d, ob, dflag);
- break;
- case OB_LATTICE:
- if (!render_override) {
- /* Do not allow boundbox in edit nor pose mode! */
- if ((dt == OB_BOUNDBOX) && (ob->mode & OB_MODE_EDIT))
- dt = OB_WIRE;
- if (dt == OB_BOUNDBOX) {
- draw_bounding_volume(ob, ob->boundtype);
- }
- else {
-#ifdef SEQUENCER_DAG_WORKAROUND
- ensure_curve_cache(scene, ob);
-#endif
- drawlattice(v3d, ob);
- }
- }
- break;
- case OB_ARMATURE:
- if (!render_override) {
- /* Do not allow boundbox in edit nor pose mode! */
- if ((dt == OB_BOUNDBOX) && (ob->mode & (OB_MODE_EDIT | OB_MODE_POSE)))
- dt = OB_WIRE;
- if (dt == OB_BOUNDBOX) {
- draw_bounding_volume(ob, ob->boundtype);
- }
- else {
- glLineWidth(1.0f);
- empty_object = draw_armature(scene, v3d, ar, base, dt, dflag, ob_wire_col, false);
- }
- }
- break;
- default:
- if (!render_override) {
- drawaxes(rv3d->viewmatob, 1.0, OB_ARROWS);
- }
- break;
- }
-
- if (!render_override) {
- if (ob->soft /*&& dflag & OB_SBMOTION*/) {
- float mrt[3][3], msc[3][3], mtr[3][3];
- SoftBody *sb = NULL;
- float tipw = 0.5f, tiph = 0.5f, drawsize = 4.0f;
- if ((sb = ob->soft)) {
- if (sb->solverflags & SBSO_ESTIMATEIPO) {
-
- glLoadMatrixf(rv3d->viewmat);
- copy_m3_m3(msc, sb->lscale);
- copy_m3_m3(mrt, sb->lrot);
- mul_m3_m3m3(mtr, mrt, msc);
- ob_draw_RE_motion(sb->lcom, mtr, tipw, tiph, drawsize);
- glMultMatrixf(ob->obmat);
- }
- }
- }
-
- if (ob->pd && ob->pd->forcefield) {
- draw_forcefield(ob, rv3d, dflag, ob_wire_col);
- }
- }
- }
-
- /* code for new particle system */
- if ((ob->particlesystem.first) &&
- (ob != scene->obedit))
- {
- ParticleSystem *psys;
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- /* for visibility, also while wpaint */
- if (col || (ob->flag & SELECT)) {
- cpack(0xFFFFFF);
- }
- }
- //glDepthMask(GL_FALSE);
-
- glLoadMatrixf(rv3d->viewmat);
-
- view3d_cached_text_draw_begin();
-
- for (psys = ob->particlesystem.first; psys; psys = psys->next) {
- /* run this so that possible child particles get cached */
- if (ob->mode & OB_MODE_PARTICLE_EDIT && is_obact) {
- PTCacheEdit *edit = PE_create_current(scene, ob);
- if (edit && edit->psys == psys)
- draw_update_ptcache_edit(scene, ob, edit);
- }
-
- draw_new_particle_system(scene, v3d, rv3d, base, psys, dt, dflag);
- }
- invert_m4_m4(ob->imat, ob->obmat);
- view3d_cached_text_draw_end(v3d, ar, 0);
-
- glMultMatrixf(ob->obmat);
-
- //glDepthMask(GL_TRUE);
- if (col) cpack(col);
- }
-
- /* draw edit particles last so that they can draw over child particles */
- if ((dflag & DRAW_PICKING) == 0 &&
- (!scene->obedit))
- {
-
- if (ob->mode & OB_MODE_PARTICLE_EDIT && is_obact) {
- PTCacheEdit *edit = PE_create_current(scene, ob);
- if (edit) {
- glLoadMatrixf(rv3d->viewmat);
- draw_update_ptcache_edit(scene, ob, edit);
- draw_ptcache_edit(scene, v3d, edit);
- glMultMatrixf(ob->obmat);
- }
- }
- }
-
- /* draw code for smoke, only draw domains */
- if (smd && smd->domain) {
- SmokeDomainSettings *sds = smd->domain;
- float viewnormal[3];
-
- glLoadMatrixf(rv3d->viewmat);
- glMultMatrixf(ob->obmat);
-
- if (!render_override) {
- BoundBox bb;
- float p0[3], p1[3];
-
- /* draw max domain bounds */
- if ((sds->flags & MOD_SMOKE_ADAPTIVE_DOMAIN)) {
- VECSUBFAC(p0, sds->p0, sds->cell_size, sds->adapt_res);
- VECADDFAC(p1, sds->p1, sds->cell_size, sds->adapt_res);
- BKE_boundbox_init_from_minmax(&bb, p0, p1);
- draw_box(bb.vec, false);
- }
-
- /* draw a single voxel to hint the user about the resolution of the fluid */
- copy_v3_v3(p0, sds->p0);
-
- if (sds->flags & MOD_SMOKE_HIGHRES) {
- madd_v3_v3v3fl(p1, p0, sds->cell_size, 1.0f / (sds->amplify + 1));
- }
- else {
- add_v3_v3v3(p1, p0, sds->cell_size);
- }
-
- BKE_boundbox_init_from_minmax(&bb, p0, p1);
- draw_box(bb.vec, false);
- }
-
- /* don't show smoke before simulation starts, this could be made an option in the future */
- if (sds->fluid && CFRA >= sds->point_cache[0]->startframe) {
- float p0[3], p1[3];
-
- /* get view vector */
- invert_m4_m4(ob->imat, ob->obmat);
- mul_v3_mat3_m4v3(viewnormal, ob->imat, rv3d->viewinv[2]);
- normalize_v3(viewnormal);
-
- /* set dynamic boundaries to draw the volume
- * also scale cube to global space to equalize volume slicing on all axes
- * (it's scaled back before drawing) */
- p0[0] = (sds->p0[0] + sds->cell_size[0] * sds->res_min[0] + sds->obj_shift_f[0]) * fabsf(ob->size[0]);
- p0[1] = (sds->p0[1] + sds->cell_size[1] * sds->res_min[1] + sds->obj_shift_f[1]) * fabsf(ob->size[1]);
- p0[2] = (sds->p0[2] + sds->cell_size[2] * sds->res_min[2] + sds->obj_shift_f[2]) * fabsf(ob->size[2]);
- p1[0] = (sds->p0[0] + sds->cell_size[0] * sds->res_max[0] + sds->obj_shift_f[0]) * fabsf(ob->size[0]);
- p1[1] = (sds->p0[1] + sds->cell_size[1] * sds->res_max[1] + sds->obj_shift_f[1]) * fabsf(ob->size[1]);
- p1[2] = (sds->p0[2] + sds->cell_size[2] * sds->res_max[2] + sds->obj_shift_f[2]) * fabsf(ob->size[2]);
-
- if (!sds->wt || !(sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
- sds->tex = NULL;
- GPU_create_smoke(smd, 0);
- draw_smoke_volume(sds, ob, p0, p1, viewnormal);
- GPU_free_smoke(smd);
- }
- else if (sds->wt && (sds->viewsettings & MOD_SMOKE_VIEW_SHOWBIG)) {
- sds->tex = NULL;
- GPU_create_smoke(smd, 1);
- draw_smoke_volume(sds, ob, p0, p1, viewnormal);
- GPU_free_smoke(smd);
- }
-
- /* smoke debug render */
- if (!render_override && sds->draw_velocity) {
- draw_smoke_velocity(sds, viewnormal);
- }
- }
- }
-
- if (!render_override) {
- bConstraint *con;
-
- for (con = ob->constraints.first; con; con = con->next) {
- if (con->type == CONSTRAINT_TYPE_RIGIDBODYJOINT) {
- bRigidBodyJointConstraint *data = (bRigidBodyJointConstraint *)con->data;
- if (data->flag & CONSTRAINT_DRAW_PIVOT)
- draw_rigid_body_pivot(data, dflag, ob_wire_col);
- }
- }
-
- if ((ob->gameflag & OB_BOUNDS) && (ob->mode == OB_MODE_OBJECT)) {
- if (ob->boundtype != ob->collision_boundtype || (dtx & OB_DRAWBOUNDOX) == 0) {
- setlinestyle(2);
- draw_bounding_volume(ob, ob->collision_boundtype);
- setlinestyle(0);
- }
- }
- if (ob->rigidbody_object) {
- draw_rigidbody_shape(ob);
- }
-
- /* draw extra: after normal draw because of makeDispList */
- if (dtx && (G.f & G_RENDER_OGL) == 0) {
-
- if (dtx & OB_AXIS) {
- drawaxes(rv3d->viewmatob, 1.0f, OB_ARROWS);
- }
- if (dtx & OB_DRAWBOUNDOX) {
- draw_bounding_volume(ob, ob->boundtype);
- }
- if (dtx & OB_TEXSPACE) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- /* prevent random colors being used */
- glColor3ubv(ob_wire_col);
- }
- drawtexspace(ob);
- }
- if (dtx & OB_DRAWNAME) {
- /* patch for several 3d cards (IBM mostly) that crash on GL_SELECT with text drawing */
- /* but, we also don't draw names for sets or duplicators */
- if (dflag == 0) {
- const float zero[3] = {0, 0, 0};
- view3d_cached_text_draw_add(zero, ob->id.name + 2, strlen(ob->id.name + 2), 10, 0, ob_wire_col);
- }
- }
- if ((dtx & OB_DRAWWIRE) && dt >= OB_SOLID) {
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- draw_wire_extra(scene, rv3d, ob, ob_wire_col);
- }
- }
- }
- }
-
- if ((dt <= OB_SOLID) && !render_override) {
- if (((ob->gameflag & OB_DYNAMIC) &&
- ((ob->gameflag & OB_BOUNDS) == 0)) ||
-
- ((ob->gameflag & OB_BOUNDS) &&
- (ob->collision_boundtype == OB_BOUND_SPHERE)))
- {
- float imat[4][4], vec[3] = {0.0f, 0.0f, 0.0f};
-
- invert_m4_m4(imat, rv3d->viewmatob);
-
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- /* prevent random colors being used */
- glColor3ubv(ob_wire_col);
- }
-
- setlinestyle(2);
- drawcircball(GL_LINE_LOOP, vec, ob->inertia, imat);
- setlinestyle(0);
- }
- }
-
- /* return warning, this is cached text draw */
- invert_m4_m4(ob->imat, ob->obmat);
- view3d_cached_text_draw_end(v3d, ar, 1);
- /* return warning, clear temp flag */
- v3d->flag2 &= ~V3D_SHOW_SOLID_MATCAP;
-
- glLoadMatrixf(rv3d->viewmat);
-
- if (zbufoff) {
- glDisable(GL_DEPTH_TEST);
- }
-
- if ((base->flag & OB_FROMDUPLI) || render_override) {
- ED_view3d_clear_mats_rv3d(rv3d);
- return;
- }
-
- /* object centers, need to be drawn in viewmat space for speed, but OK for picking select */
- if (!is_obact || !(ob->mode & OB_MODE_ALL_PAINT)) {
- int do_draw_center = -1; /* defines below are zero or positive... */
-
- if (render_override) {
- /* don't draw */
- }
- else if (is_obact)
- do_draw_center = ACTIVE;
- else if (base->flag & SELECT)
- do_draw_center = SELECT;
- else if (empty_object || (v3d->flag & V3D_DRAW_CENTERS))
- do_draw_center = DESELECT;
-
- if (do_draw_center != -1) {
- if (dflag & DRAW_PICKING) {
- /* draw a single point for opengl selection */
- if ((base->sx != IS_CLIPPED) &&
- (U.obcenter_dia != 0.0))
- {
- glPointSize(U.obcenter_dia);
- glBegin(GL_POINTS);
- glVertex3fv(ob->obmat[3]);
- glEnd();
- }
- }
- else if ((dflag & DRAW_CONSTCOLOR) == 0) {
- /* we don't draw centers for duplicators and sets */
- if ((base->sx != IS_CLIPPED) &&
- (U.obcenter_dia != 0.0) &&
- !(G.f & G_RENDER_OGL))
- {
- /* check > 0 otherwise grease pencil can draw into the circle select which is annoying. */
- drawcentercircle(v3d, rv3d, ob->obmat[3], do_draw_center, ID_IS_LINKED(ob) || ob->id.us > 1);
- }
- }
- }
- }
-
- /* not for sets, duplicators or picking */
- if (dflag == 0 && (v3d->flag & V3D_HIDE_HELPLINES) == 0 && !render_override) {
- ListBase *list;
- RigidBodyCon *rbc = ob->rigidbody_constraint;
-
- /* draw hook center and offset line */
- if (ob != scene->obedit)
- draw_hooks(ob);
-
- /* help lines and so */
- if (ob != scene->obedit && ob->parent && (ob->parent->lay & v3d->lay)) {
- setlinestyle(3);
- glBegin(GL_LINES);
- glVertex3fv(ob->obmat[3]);
- glVertex3fv(ob->orig);
- glEnd();
- setlinestyle(0);
- }
-
- /* Drawing the constraint lines */
- if (ob->constraints.first) {
- bConstraint *curcon;
- bConstraintOb *cob;
- unsigned char col1[4], col2[4];
-
- list = &ob->constraints;
-
- UI_GetThemeColor3ubv(TH_GRID, col1);
- UI_make_axis_color(col1, col2, 'Z');
- glColor3ubv(col2);
-
- cob = BKE_constraints_make_evalob(scene, ob, NULL, CONSTRAINT_OBTYPE_OBJECT);
-
- for (curcon = list->first; curcon; curcon = curcon->next) {
- if (ELEM(curcon->type, CONSTRAINT_TYPE_FOLLOWTRACK, CONSTRAINT_TYPE_OBJECTSOLVER)) {
- /* special case for object solver and follow track constraints because they don't fill
- * constraint targets properly (design limitation -- scene is needed for their target
- * but it can't be accessed from get_targets callback) */
-
- Object *camob = NULL;
-
- if (curcon->type == CONSTRAINT_TYPE_FOLLOWTRACK) {
- bFollowTrackConstraint *data = (bFollowTrackConstraint *)curcon->data;
-
- camob = data->camera ? data->camera : scene->camera;
- }
- else if (curcon->type == CONSTRAINT_TYPE_OBJECTSOLVER) {
- bObjectSolverConstraint *data = (bObjectSolverConstraint *)curcon->data;
-
- camob = data->camera ? data->camera : scene->camera;
- }
-
- if (camob) {
- setlinestyle(3);
- glBegin(GL_LINES);
- glVertex3fv(camob->obmat[3]);
- glVertex3fv(ob->obmat[3]);
- glEnd();
- setlinestyle(0);
- }
- }
- else {
- const bConstraintTypeInfo *cti = BKE_constraint_typeinfo_get(curcon);
-
- if ((cti && cti->get_constraint_targets) && (curcon->flag & CONSTRAINT_EXPAND)) {
- ListBase targets = {NULL, NULL};
- bConstraintTarget *ct;
-
- cti->get_constraint_targets(curcon, &targets);
-
- for (ct = targets.first; ct; ct = ct->next) {
- /* calculate target's matrix */
- if (cti->get_target_matrix)
- cti->get_target_matrix(curcon, cob, ct, BKE_scene_frame_get(scene));
- else
- unit_m4(ct->matrix);
-
- setlinestyle(3);
- glBegin(GL_LINES);
- glVertex3fv(ct->matrix[3]);
- glVertex3fv(ob->obmat[3]);
- glEnd();
- setlinestyle(0);
- }
-
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(curcon, &targets, 1);
- }
- }
- }
-
- BKE_constraints_clear_evalob(cob);
- }
- /* draw rigid body constraint lines */
- if (rbc) {
- UI_ThemeColor(TH_WIRE);
- setlinestyle(3);
- glBegin(GL_LINES);
- if (rbc->ob1) {
- glVertex3fv(ob->obmat[3]);
- glVertex3fv(rbc->ob1->obmat[3]);
- }
- if (rbc->ob2) {
- glVertex3fv(ob->obmat[3]);
- glVertex3fv(rbc->ob2->obmat[3]);
- }
- glEnd();
- setlinestyle(0);
- }
- }
-
- ED_view3d_clear_mats_rv3d(rv3d);
-}
-
-
-/**
- * Drawing for selection picking,
- * caller must have called 'GPU_select_load_id(base->selcode)' first.
- */
-void draw_object_select(Scene *scene, ARegion *ar, View3D *v3d, Base *base, const short dflag)
-{
- BLI_assert(dflag & DRAW_PICKING && dflag & DRAW_CONSTCOLOR);
- draw_object(scene, ar, v3d, base, dflag);
-
- /* we draw duplicators for selection too */
- if ((base->object->transflag & OB_DUPLI)) {
- ListBase *lb;
- DupliObject *dob;
- Base tbase;
-
- tbase.flag = OB_FROMDUPLI;
- lb = object_duplilist(G.main->eval_ctx, scene, base->object);
-
- for (dob = lb->first; dob; dob = dob->next) {
- float omat[4][4];
- char dt;
- short dtx;
-
- tbase.object = dob->ob;
- copy_m4_m4(omat, dob->ob->obmat);
- copy_m4_m4(dob->ob->obmat, dob->mat);
-
- /* extra service: draw the duplicator in drawtype of parent */
- /* MIN2 for the drawtype to allow bounding box objects in groups for lods */
- dt = tbase.object->dt; tbase.object->dt = MIN2(tbase.object->dt, base->object->dt);
- dtx = tbase.object->dtx; tbase.object->dtx = base->object->dtx;
-
- draw_object(scene, ar, v3d, &tbase, dflag);
-
- tbase.object->dt = dt;
- tbase.object->dtx = dtx;
-
- copy_m4_m4(dob->ob->obmat, omat);
- }
- free_object_duplilist(lb);
- }
-}
-
-/* ***************** BACKBUF SEL (BBS) ********* */
-
-static void bbs_obmode_mesh_verts__mapFunc(void *userData, int index, const float co[3],
- const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
-{
- drawMVertOffset_userData *data = userData;
- MVert *mv = &data->mvert[index];
-
- if (!(mv->flag & ME_HIDE)) {
- GPU_select_index_set(data->offset + index);
- glVertex3fv(co);
- }
-}
-
-static void bbs_obmode_mesh_verts(Object *ob, DerivedMesh *dm, int offset)
-{
- drawMVertOffset_userData data;
- Mesh *me = ob->data;
- MVert *mvert = me->mvert;
- data.mvert = mvert;
- data.offset = offset;
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
- glBegin(GL_POINTS);
- dm->foreachMappedVert(dm, bbs_obmode_mesh_verts__mapFunc, &data, DM_FOREACH_NOP);
- glEnd();
-}
-
-static void bbs_mesh_verts__mapFunc(void *userData, int index, const float co[3],
- const float UNUSED(no_f[3]), const short UNUSED(no_s[3]))
-{
- drawBMOffset_userData *data = userData;
- BMVert *eve = BM_vert_at_index(data->bm, index);
-
- if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
- GPU_select_index_set(data->offset + index);
- glVertex3fv(co);
- }
-}
-static void bbs_mesh_verts(BMEditMesh *em, DerivedMesh *dm, int offset)
-{
- drawBMOffset_userData data = {em->bm, offset};
- glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE));
- glBegin(GL_POINTS);
- dm->foreachMappedVert(dm, bbs_mesh_verts__mapFunc, &data, DM_FOREACH_NOP);
- glEnd();
-}
-
-static DMDrawOption bbs_mesh_wire__setDrawOptions(void *userData, int index)
-{
- drawBMOffset_userData *data = userData;
- BMEdge *eed = BM_edge_at_index(data->bm, index);
-
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- GPU_select_index_set(data->offset + index);
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
- }
-}
-static void bbs_mesh_wire(BMEditMesh *em, DerivedMesh *dm, int offset)
-{
- drawBMOffset_userData data = {em->bm, offset};
- glLineWidth(1);
- dm->drawMappedEdges(dm, bbs_mesh_wire__setDrawOptions, &data);
-}
-
-/**
- * dont set #GPU_framebuffer_index_set. just use to mask other
- */
-static DMDrawOption bbs_mesh_mask__setSolidDrawOptions(void *userData, int index)
-{
- BMFace *efa = BM_face_at_index(userData, index);
-
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
- }
-}
-
-static DMDrawOption bbs_mesh_solid__setSolidDrawOptions(void *userData, int index)
-{
- BMFace *efa = BM_face_at_index(userData, index);
-
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- GPU_select_index_set(index + 1);
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
- }
-}
-
-static void bbs_mesh_solid__drawCenter(void *userData, int index, const float cent[3], const float UNUSED(no[3]))
-{
- BMFace *efa = BM_face_at_index(userData, index);
-
- if (!BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- GPU_select_index_set(index + 1);
-
- glVertex3fv(cent);
- }
-}
-
/* two options, facecolors or black */
static void bbs_mesh_solid_EM(BMEditMesh *em, Scene *scene, View3D *v3d,
Object *ob, DerivedMesh *dm, bool use_faceselect)
{
- cpack(0);
-
if (use_faceselect) {
- dm->drawMappedFaces(dm, bbs_mesh_solid__setSolidDrawOptions, NULL, NULL, em->bm, DM_DRAW_SKIP_HIDDEN | DM_DRAW_SELECT_USE_EDITMODE);
+ bbs_mesh_face(em, dm, true);
if (check_ob_drawface_dot(scene, v3d, ob->dt)) {
- glPointSize(UI_GetThemeValuef(TH_FACEDOT_SIZE));
-
- glBegin(GL_POINTS);
- dm->foreachMappedFaceCenter(dm, bbs_mesh_solid__drawCenter, em->bm, DM_FOREACH_NOP);
- glEnd();
+ bbs_mesh_face_dot(em, dm);
}
-
}
else {
- dm->drawMappedFaces(dm, bbs_mesh_mask__setSolidDrawOptions, NULL, NULL, em->bm, DM_DRAW_SKIP_SELECT | DM_DRAW_SKIP_HIDDEN | DM_DRAW_SELECT_USE_EDITMODE);
- }
-}
-
-static DMDrawOption bbs_mesh_solid__setDrawOpts(void *UNUSED(userData), int index)
-{
- GPU_select_index_set(index + 1);
- return DM_DRAW_OPTION_NORMAL;
-}
-
-static DMDrawOption bbs_mesh_solid_hide__setDrawOpts(void *userData, int index)
-{
- Mesh *me = userData;
-
- if (!(me->mpoly[index].flag & ME_HIDE)) {
- GPU_select_index_set(index + 1);
- return DM_DRAW_OPTION_NORMAL;
- }
- else {
- return DM_DRAW_OPTION_SKIP;
+ bbs_mesh_face(em, dm, false);
}
}
+#ifdef USE_MESH_DM_SELECT
/* must have called GPU_framebuffer_index_set beforehand */
static DMDrawOption bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index)
{
@@ -8372,11 +550,10 @@ static DMDrawOption bbs_mesh_solid_hide2__setDrawOpts(void *userData, int index)
}
}
-static void bbs_mesh_solid_verts(Scene *scene, Object *ob)
+static void bbs_mesh_solid_verts(Depsgraph *depsgraph, Scene *scene, Object *ob)
{
Mesh *me = ob->data;
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
- glColor3ub(0, 0, 0);
+ DerivedMesh *dm = mesh_get_derived_final(depsgraph, scene, ob, scene->customdata_mask);
DM_update_materials(dm, ob);
@@ -8392,29 +569,52 @@ static void bbs_mesh_solid_verts(Scene *scene, Object *ob)
bm_vertoffs = me->totvert + 1;
dm->release(dm);
}
-
-static void bbs_mesh_solid_faces(Scene *scene, Object *ob)
+#else
+static void bbs_mesh_solid_verts(Depsgraph *UNUSED(depsgraph), Scene *UNUSED(scene), Object *ob)
{
- DerivedMesh *dm = mesh_get_derived_final(scene, ob, scene->customdata_mask);
Mesh *me = ob->data;
-
- glColor3ub(0, 0, 0);
- DM_update_materials(dm, ob);
+ /* Only draw faces to mask out verts, we don't want their selection ID's. */
+ const int G_f_orig = G.f;
+ G.f &= ~G_BACKBUFSEL;
- if ((me->editflag & ME_EDIT_PAINT_FACE_SEL))
- dm->drawMappedFaces(dm, bbs_mesh_solid_hide__setDrawOpts, NULL, NULL, me, DM_DRAW_SKIP_HIDDEN);
- else
- dm->drawMappedFaces(dm, bbs_mesh_solid__setDrawOpts, NULL, NULL, me, 0);
+ {
+ int selcol;
+ Gwn_Batch *batch;
+ GPU_select_index_get(0, &selcol);
+ batch = DRW_mesh_batch_cache_get_triangles_with_select_mask(me, true);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_UNIFORM_COLOR_U32);
+ GWN_batch_uniform_1ui(batch, "color", selcol);
+ GWN_batch_draw(batch);
+ }
- dm->release(dm);
+ G.f |= (G_f_orig & G_BACKBUFSEL);
+
+ bbs_obmode_mesh_verts(ob, NULL, 1);
+ bm_vertoffs = me->totvert + 1;
+}
+#endif
+
+static void bbs_mesh_solid_faces(Scene *UNUSED(scene), Object *ob)
+{
+ Mesh *me = ob->data;
+ Gwn_Batch *batch;
+ if ((me->editflag & ME_EDIT_PAINT_FACE_SEL)) {
+ batch = DRW_mesh_batch_cache_get_triangles_with_select_id(me, true, 1);
+ }
+ else {
+ batch = DRW_mesh_batch_cache_get_triangles_with_select_id(me, false, 1);
+ }
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_3D_FLAT_COLOR_U32);
+ GWN_batch_draw(batch);
}
-void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
+void draw_object_backbufsel(
+ Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob)
{
ToolSettings *ts = scene->toolsettings;
- glMultMatrixf(ob->obmat);
+ gpuMultMatrix(ob->obmat);
glClearDepth(1.0); glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
@@ -8425,7 +625,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
Mesh *me = ob->data;
BMEditMesh *em = me->edit_btmesh;
- DerivedMesh *dm = editbmesh_get_derived_cage(scene, ob, em, CD_MASK_BAREMESH);
+ DerivedMesh *dm = editbmesh_get_derived_cage(depsgraph, scene, ob, em, CD_MASK_BAREMESH);
BM_mesh_elem_table_ensure(em->bm, BM_VERT | BM_EDGE | BM_FACE);
@@ -8469,7 +669,7 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
/* currently vertex select supports weight paint and vertex paint*/
((ob->mode & OB_MODE_WEIGHT_PAINT) || (ob->mode & OB_MODE_VERTEX_PAINT)))
{
- bbs_mesh_solid_verts(scene, ob);
+ bbs_mesh_solid_verts(depsgraph, scene, ob);
}
else {
bbs_mesh_solid_faces(scene, ob);
@@ -8481,77 +681,134 @@ void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, Objec
break;
}
- glLoadMatrixf(rv3d->viewmat);
+ gpuLoadMatrix(rv3d->viewmat);
}
-/* ************* draw object instances for bones, for example ****************** */
-/* assumes all matrices/etc set OK */
-
-/* helper function for drawing object instances - meshes */
-static void draw_object_mesh_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d,
- Object *ob, const short dt, int outline)
+void ED_draw_object_facemap(
+ Depsgraph *depsgraph, Scene *scene, Object *ob, const float col[4], const int facemap)
{
- Mesh *me = ob->data;
- DerivedMesh *dm = NULL, *edm = NULL;
-
- if (ob->mode & OB_MODE_EDIT) {
- edm = editbmesh_get_derived_base(ob, me->edit_btmesh, CD_MASK_BAREMESH);
- DM_update_materials(edm, ob);
- }
- else {
- dm = mesh_get_derived_final(scene, ob, CD_MASK_BAREMESH);
- DM_update_materials(dm, ob);
+ DerivedMesh *dm = NULL;
+
+ /* happens on undo */
+ if (ob->type != OB_MESH || !ob->data)
+ return;
+
+ /* Temporary, happens on undo, would resolve but will eventually move away from DM. */
+ if (ob->derivedFinal == NULL) {
+ return;
}
- if (dt <= OB_WIRE) {
- if (dm)
- dm->drawEdges(dm, 1, 0);
- else if (edm)
- edm->drawEdges(edm, 1, 0);
+ dm = mesh_get_derived_final(depsgraph, scene, ob, CD_MASK_BAREMESH);
+ if (!dm || !CustomData_has_layer(&dm->polyData, CD_FACEMAP))
+ return;
+
+
+ glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
+
+#if 0
+ DM_update_materials(dm, ob);
+
+ /* add polygon offset so we draw above the original surface */
+ glPolygonOffset(1.0, 1.0);
+
+ GPU_facemap_setup(dm);
+
+ glColor4fv(col);
+
+ gpuPushAttrib(GL_ENABLE_BIT);
+ glEnable(GL_BLEND);
+ glDisable(GL_LIGHTING);
+
+ /* always draw using backface culling */
+ glEnable(GL_CULL_FACE);
+ glCullFace(GL_BACK);
+
+ if (dm->drawObject->facemapindices) {
+ glDrawElements(GL_TRIANGLES, dm->drawObject->facemap_count[facemap] * 3, GL_UNSIGNED_INT,
+ (int *)NULL + dm->drawObject->facemap_start[facemap] * 3);
}
- else {
- if (outline)
- draw_mesh_object_outline(v3d, ob, dm ? dm : edm);
+ gpuPopAttrib();
- if (dm) {
- bool glsl = draw_glsl_material(scene, ob, v3d, dt);
- GPU_begin_object_materials(v3d, rv3d, scene, ob, glsl, NULL);
- }
-
- glFrontFace((ob->transflag & OB_NEG_SCALE) ? GL_CW : GL_CCW);
-
- if (dm) {
- dm->drawFacesSolid(dm, NULL, 0, GPU_object_material_bind);
- GPU_end_object_materials();
+ GPU_buffers_unbind();
+
+ glPolygonOffset(0.0, 0.0);
+
+#else
+
+ /* Just to create the data to pass to immediate mode, grr! */
+ Mesh *me = ob->data;
+ const int *facemap_data = CustomData_get_layer(&me->pdata, CD_FACEMAP);
+ if (facemap_data) {
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor4fv(col);
+
+ /* XXX, alpha isn't working yet, not sure why. */
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ MVert *mvert;
+
+ MPoly *mpoly;
+ int mpoly_len;
+
+ MLoop *mloop;
+ int mloop_len;
+
+ if (dm && CustomData_has_layer(&dm->polyData, CD_FACEMAP)) {
+ mvert = dm->getVertArray(dm);
+ mpoly = dm->getPolyArray(dm);
+ mloop = dm->getLoopArray(dm);
+
+ mpoly_len = dm->getNumPolys(dm);
+ mloop_len = dm->getNumLoops(dm);
+
+ facemap_data = CustomData_get_layer(&dm->polyData, CD_FACEMAP);
}
- else if (edm)
- edm->drawMappedFaces(edm, NULL, GPU_object_material_bind, NULL, NULL, DM_DRAW_NEED_NORMALS);
+ else {
+ mvert = me->mvert;
+ mpoly = me->mpoly;
+ mloop = me->mloop;
- GPU_object_material_unbind();
- }
+ mpoly_len = me->totpoly;
+ mloop_len = me->totloop;
- if (edm) edm->release(edm);
- if (dm) dm->release(dm);
-}
+ facemap_data = CustomData_get_layer(&me->pdata, CD_FACEMAP);
+ }
-void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, Object *ob, const char dt, int outline)
-{
- if (ob == NULL)
- return;
+ /* use gawain immediate mode fore now */
+ const int looptris_len = poly_to_tri_count(mpoly_len, mloop_len);
+ immBeginAtMost(GWN_PRIM_TRIS, looptris_len * 3);
- switch (ob->type) {
- case OB_MESH:
- draw_object_mesh_instance(scene, v3d, rv3d, ob, dt, outline);
- break;
- case OB_EMPTY:
- if (ob->empty_drawtype == OB_EMPTY_IMAGE) {
- /* CONSTCOLOR == no wire outline */
- draw_empty_image(ob, DRAW_CONSTCOLOR, NULL, v3d->multiview_eye);
- }
- else {
- drawaxes(rv3d->viewmatob, ob->empty_drawsize, ob->empty_drawtype);
+ MPoly *mp;
+ int i;
+ for (mp = mpoly, i = 0; i < mpoly_len; i++, mp++) {
+ if (facemap_data[i] == facemap) {
+ /* Weak, fan-fill, use until we have derived-mesh replaced. */
+ const MLoop *ml_start = &mloop[mp->loopstart];
+ const MLoop *ml_a = ml_start + 1;
+ const MLoop *ml_b = ml_start + 2;
+ for (int j = 2; j < mp->totloop; j++) {
+ immVertex3fv(pos, mvert[ml_start->v].co);
+ immVertex3fv(pos, mvert[ml_a->v].co);
+ immVertex3fv(pos, mvert[ml_b->v].co);
+
+ ml_a++;
+ ml_b++;
+ }
}
- break;
+ }
+ immEnd();
+
+ immUnbindProgram();
+
+ glDisable(GL_BLEND);
}
+#endif
+
+ dm->release(dm);
}
+
diff --git a/source/blender/editors/space_view3d/drawsimdebug.c b/source/blender/editors/space_view3d/drawsimdebug.c
deleted file mode 100644
index 3f23d4aa09a..00000000000
--- a/source/blender/editors/space_view3d/drawsimdebug.c
+++ /dev/null
@@ -1,180 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2014 by the Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Lukas Toenne
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/space_view3d/drawsimdebug.c
- * \ingroup spview3d
- */
-
-#include "DNA_scene_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-
-#include "BKE_effect.h"
-
-#include "view3d_intern.h"
-
-#include "BIF_gl.h"
-
-
-static void draw_sim_debug_elements(SimDebugData *debug_data, float imat[4][4])
-{
- GHashIterator iter;
-
- /**** dots ****/
-
- glPointSize(3.0f);
- glBegin(GL_POINTS);
- for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
- SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
- if (elem->type != SIM_DEBUG_ELEM_DOT)
- continue;
-
- glColor3f(elem->color[0], elem->color[1], elem->color[2]);
- glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
- }
- glEnd();
-
- /**** circles ****/
-
- {
- float circle[16][2] = {
- {0.000000, 1.000000}, {0.382683, 0.923880}, {0.707107, 0.707107}, {0.923880, 0.382683},
- {1.000000, -0.000000}, {0.923880, -0.382683}, {0.707107, -0.707107}, {0.382683, -0.923880},
- {-0.000000, -1.000000}, {-0.382683, -0.923880}, {-0.707107, -0.707107}, {-0.923879, -0.382684},
- {-1.000000, 0.000000}, {-0.923879, 0.382684}, {-0.707107, 0.707107}, {-0.382683, 0.923880} };
- for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
- SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
- float radius = elem->v2[0];
- float co[3];
- int i;
-
- if (elem->type != SIM_DEBUG_ELEM_CIRCLE)
- continue;
-
- glColor3f(elem->color[0], elem->color[1], elem->color[2]);
- glBegin(GL_LINE_LOOP);
- for (i = 0; i < 16; ++i) {
- co[0] = radius * circle[i][0];
- co[1] = radius * circle[i][1];
- co[2] = 0.0f;
- mul_mat3_m4_v3(imat, co);
- add_v3_v3(co, elem->v1);
-
- glVertex3f(co[0], co[1], co[2]);
- }
- glEnd();
- }
- }
-
- /**** lines ****/
-
- glBegin(GL_LINES);
- for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
- SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
- if (elem->type != SIM_DEBUG_ELEM_LINE)
- continue;
-
- glColor3f(elem->color[0], elem->color[1], elem->color[2]);
- glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
- glVertex3f(elem->v2[0], elem->v2[1], elem->v2[2]);
- }
- glEnd();
-
- /**** vectors ****/
-
- glPointSize(2.0f);
- glBegin(GL_POINTS);
- for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
- SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
- if (elem->type != SIM_DEBUG_ELEM_VECTOR)
- continue;
-
- glColor3f(elem->color[0], elem->color[1], elem->color[2]);
- glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
- }
- glEnd();
-
- glBegin(GL_LINES);
- for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
- SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
- float t[3];
- if (elem->type != SIM_DEBUG_ELEM_VECTOR)
- continue;
-
- glColor3f(elem->color[0], elem->color[1], elem->color[2]);
- glVertex3f(elem->v1[0], elem->v1[1], elem->v1[2]);
- add_v3_v3v3(t, elem->v1, elem->v2);
- glVertex3f(t[0], t[1], t[2]);
- }
- glEnd();
-
- /**** strings ****/
-
- for (BLI_ghashIterator_init(&iter, debug_data->gh); !BLI_ghashIterator_done(&iter); BLI_ghashIterator_step(&iter)) {
- SimDebugElement *elem = BLI_ghashIterator_getValue(&iter);
- if (elem->type != SIM_DEBUG_ELEM_STRING)
- continue;
-
- unsigned char col[4];
- rgb_float_to_uchar(col, elem->color);
- col[3] = 255;
- view3d_cached_text_draw_add(elem->v1, elem->str, strlen(elem->str),
- 0, V3D_CACHE_TEXT_GLOBALSPACE, col);
- }
-}
-
-void draw_sim_debug_data(Scene *UNUSED(scene), View3D *v3d, ARegion *ar)
-{
- RegionView3D *rv3d = ar->regiondata;
- /*Object *ob = base->object;*/
- float imat[4][4];
-
- if (!_sim_debug_data)
- return;
-
- invert_m4_m4(imat, rv3d->viewmatob);
-
-// glDepthMask(GL_FALSE);
-// glEnable(GL_BLEND);
-
- glPushMatrix();
- glLoadMatrixf(rv3d->viewmat);
-
- view3d_cached_text_draw_begin();
- draw_sim_debug_elements(_sim_debug_data, imat);
- view3d_cached_text_draw_end(v3d, ar, false);
-
- glPopMatrix();
-
-// glDepthMask(GL_TRUE);
-// glDisable(GL_BLEND);
-}
diff --git a/source/blender/editors/space_view3d/drawvolume.c b/source/blender/editors/space_view3d/drawvolume.c
index cf118404183..3b648e3b13a 100644
--- a/source/blender/editors/space_view3d/drawvolume.c
+++ b/source/blender/editors/space_view3d/drawvolume.c
@@ -48,7 +48,6 @@
#include "BIF_gl.h"
-#include "GPU_debug.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
@@ -129,7 +128,7 @@ static GPUTexture *create_transfer_function(int type, const ColorBand *coba)
break;
}
- GPUTexture *tex = GPU_texture_create_1D(TFUNC_WIDTH, data, NULL);
+ GPUTexture *tex = GPU_texture_create_1D(TFUNC_WIDTH, GPU_RGBA8, data, NULL);
MEM_freeN(data);
@@ -160,7 +159,7 @@ static GPUTexture *create_field_texture(SmokeDomainSettings *sds)
default: return NULL;
}
- return GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, field);
+ return GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], GPU_R8, field, NULL);
}
typedef struct VolumeSlicer {
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index a36b698a04e..ff5eb46a38e 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -43,31 +43,39 @@
#include "BLI_utildefines.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_curve.h"
#include "BKE_icons.h"
+#include "BKE_lattice.h"
#include "BKE_library.h"
#include "BKE_main.h"
+#include "BKE_mball.h"
+#include "BKE_mesh.h"
#include "BKE_object.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
+#include "BKE_workspace.h"
#include "ED_space_api.h"
#include "ED_screen.h"
+#include "ED_transform.h"
-#include "GPU_compositing.h"
#include "GPU_framebuffer.h"
#include "GPU_material.h"
+#include "GPU_viewport.h"
+#include "GPU_matrix.h"
-#include "BIF_gl.h"
+#include "DRW_engine.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "RE_engine.h"
#include "RE_pipeline.h"
#include "RNA_access.h"
+#include "UI_interface.h"
#include "UI_resources.h"
#ifdef WITH_PYTHON
@@ -106,18 +114,18 @@ ARegion *view3d_has_buttons_region(ScrArea *sa)
ARegion *view3d_has_tools_region(ScrArea *sa)
{
- ARegion *ar, *artool = NULL, *arprops = NULL, *arhead;
-
+ ARegion *ar, *artool = NULL, *arhead;
+
for (ar = sa->regionbase.first; ar; ar = ar->next) {
if (ar->regiontype == RGN_TYPE_TOOLS)
artool = ar;
- if (ar->regiontype == RGN_TYPE_TOOL_PROPS)
- arprops = ar;
}
-
+
/* tool region hide/unhide also hides props */
- if (arprops && artool) return artool;
-
+ if (artool) {
+ return artool;
+ }
+
if (artool == NULL) {
/* add subdiv level; after header */
for (arhead = sa->regionbase.first; arhead; arhead = arhead->next)
@@ -135,15 +143,6 @@ ARegion *view3d_has_tools_region(ScrArea *sa)
artool->flag = RGN_FLAG_HIDDEN;
}
- if (arprops == NULL) {
- /* add extra subdivided region for tool properties */
- arprops = MEM_callocN(sizeof(ARegion), "tool props for view3d");
-
- BLI_insertlinkafter(&sa->regionbase, artool, arprops);
- arprops->regiontype = RGN_TYPE_TOOL_PROPS;
- arprops->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
- }
-
return artool;
}
@@ -250,7 +249,7 @@ void ED_view3d_init_mats_rv3d_gl(struct Object *ob, struct RegionView3D *rv3d)
/* we have to multiply instead of loading viewmatob to make
* it work with duplis using displists, otherwise it will
* override the dupli-matrix */
- glMultMatrixf(ob->obmat);
+ gpuMultMatrix(ob->obmat);
}
#ifdef DEBUG
@@ -283,8 +282,6 @@ void ED_view3d_stop_render_preview(wmWindowManager *wm, ARegion *ar)
BPy_END_ALLOW_THREADS;
#endif
- if (rv3d->render_engine->re)
- RE_Database_Free(rv3d->render_engine->re);
RE_engine_free(rv3d->render_engine);
rv3d->render_engine = NULL;
}
@@ -306,9 +303,8 @@ void ED_view3d_shade_update(Main *bmain, View3D *v3d, ScrArea *sa)
/* ******************** default callbacks for view3d space ***************** */
-static SpaceLink *view3d_new(const bContext *C)
+static SpaceLink *view3d_new(const ScrArea *UNUSED(sa), const Scene *scene)
{
- Scene *scene = CTX_data_scene(C);
ARegion *ar;
View3D *v3d;
RegionView3D *rv3d;
@@ -326,6 +322,9 @@ static SpaceLink *view3d_new(const bContext *C)
v3d->gridlines = 16;
v3d->gridsubdiv = 10;
v3d->drawtype = OB_SOLID;
+ v3d->shading.light = V3D_LIGHTING_STUDIO;
+ v3d->shading.shadow_intensity = 0.5;
+ copy_v3_fl(v3d->shading.single_color, 0.8f);
v3d->gridflag = V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_FLOOR;
@@ -336,10 +335,9 @@ static SpaceLink *view3d_new(const bContext *C)
v3d->near = 0.01f;
v3d->far = 1000.0f;
- v3d->twflag |= U.tw_flag & V3D_USE_MANIPULATOR;
- v3d->twtype = V3D_MANIP_TRANSLATE;
+ v3d->twflag |= U.manipulator_flag & V3D_MANIPULATOR_DRAW;
v3d->around = V3D_AROUND_CENTER_MEAN;
-
+
v3d->bundle_size = 0.2f;
v3d->bundle_drawtype = OB_PLAINAXES;
@@ -363,15 +361,7 @@ static SpaceLink *view3d_new(const bContext *C)
ar->regiontype = RGN_TYPE_TOOLS;
ar->alignment = RGN_ALIGN_LEFT;
ar->flag = RGN_FLAG_HIDDEN;
-
- /* tool properties */
- ar = MEM_callocN(sizeof(ARegion), "tool properties for view3d");
-
- BLI_addtail(&v3d->regionbase, ar);
- ar->regiontype = RGN_TYPE_TOOL_PROPS;
- ar->alignment = RGN_ALIGN_BOTTOM | RGN_SPLIT_PREV;
- ar->flag = RGN_FLAG_HIDDEN;
-
+
/* buttons/list view */
ar = MEM_callocN(sizeof(ARegion), "buttons for view3d");
@@ -400,30 +390,11 @@ static SpaceLink *view3d_new(const bContext *C)
static void view3d_free(SpaceLink *sl)
{
View3D *vd = (View3D *) sl;
- BGpic *bgpic;
-
- for (bgpic = vd->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- if (bgpic->source == V3D_BGPIC_IMAGE) {
- id_us_min((ID *)bgpic->ima);
- }
- else if (bgpic->source == V3D_BGPIC_MOVIE) {
- id_us_min((ID *)bgpic->clip);
- }
- }
- BLI_freelistN(&vd->bgpicbase);
if (vd->localvd) MEM_freeN(vd->localvd);
if (vd->properties_storage) MEM_freeN(vd->properties_storage);
- /* matcap material, its preview rect gets freed via icons */
- if (vd->defmaterial) {
- if (vd->defmaterial->gpumaterial.first)
- GPU_material_free(&vd->defmaterial->gpumaterial);
- BKE_previewimg_free(&vd->defmaterial->preview);
- MEM_freeN(vd->defmaterial);
- }
-
if (vd->fx_settings.ssao)
MEM_freeN(vd->fx_settings.ssao);
if (vd->fx_settings.dof)
@@ -441,7 +412,6 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
{
View3D *v3do = (View3D *)sl;
View3D *v3dn = MEM_dupallocN(sl);
- BGpic *bgpic;
/* clear or remove stuff from old */
@@ -456,18 +426,6 @@ static SpaceLink *view3d_duplicate(SpaceLink *sl)
/* copy or clear inside new stuff */
- v3dn->defmaterial = NULL;
-
- BLI_duplicatelist(&v3dn->bgpicbase, &v3do->bgpicbase);
- for (bgpic = v3dn->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- if (bgpic->source == V3D_BGPIC_IMAGE) {
- id_us_plus((ID *)bgpic->ima);
- }
- else if (bgpic->source == V3D_BGPIC_MOVIE) {
- id_us_plus((ID *)bgpic->clip);
- }
- }
-
v3dn->properties_storage = NULL;
if (v3dn->fx_settings.dof)
v3dn->fx_settings.dof = MEM_dupallocN(v3do->fx_settings.dof);
@@ -483,6 +441,13 @@ static void view3d_main_region_init(wmWindowManager *wm, ARegion *ar)
ListBase *lb;
wmKeyMap *keymap;
+ if (ar->manipulator_map == NULL) {
+ ar->manipulator_map = WM_manipulatormap_new_from_type(
+ &(const struct wmManipulatorMapType_Params) {SPACE_VIEW3D, RGN_TYPE_WINDOW});
+ }
+
+ WM_manipulatormap_add_handlers(ar, ar->manipulator_map);
+
/* object ops. */
/* important to be before Pose keymap since they can both be enabled at once */
@@ -573,11 +538,6 @@ static void view3d_main_region_exit(wmWindowManager *wm, ARegion *ar)
GPU_offscreen_free(rv3d->gpuoffscreen);
rv3d->gpuoffscreen = NULL;
}
-
- if (rv3d->compositor) {
- GPU_fx_compositor_destroy(rv3d->compositor);
- rv3d->compositor = NULL;
- }
}
static int view3d_ob_drop_poll(bContext *UNUSED(C), wmDrag *drag, const wmEvent *UNUSED(event))
@@ -708,6 +668,29 @@ static void view3d_dropboxes(void)
WM_dropbox_add(lb, "OBJECT_OT_group_instance_add", view3d_group_drop_poll, view3d_group_drop_copy);
}
+static void view3d_widgets(void)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(
+ &(const struct wmManipulatorMapType_Params){SPACE_VIEW3D, RGN_TYPE_WINDOW});
+
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_lamp_spot);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_lamp_area);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_lamp_target);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_force_field);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_camera);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_camera_view);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_empty_image);
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_armature_spline);
+
+ WM_manipulatorgrouptype_append(TRANSFORM_WGT_manipulator);
+ WM_manipulatorgrouptype_append(VIEW3D_WGT_xform_cage);
+
+ WM_manipulatorgrouptype_append(VIEW3D_WGT_ruler);
+ WM_manipulatortype_append(VIEW3D_WT_ruler_item);
+
+ WM_manipulatorgrouptype_append_and_link(mmap_type, VIEW3D_WGT_navigate);
+ WM_manipulatortype_append(VIEW3D_WT_navigate_rotate);
+}
/* type callback, not region itself */
@@ -732,9 +715,6 @@ static void view3d_main_region_free(ARegion *ar)
if (rv3d->gpuoffscreen) {
GPU_offscreen_free(rv3d->gpuoffscreen);
}
- if (rv3d->compositor) {
- GPU_fx_compositor_destroy(rv3d->compositor);
- }
MEM_freeN(rv3d);
ar->regiondata = NULL;
@@ -758,33 +738,21 @@ static void *view3d_main_region_duplicate(void *poin)
new->render_engine = NULL;
new->sms = NULL;
new->smooth_timer = NULL;
- new->compositor = NULL;
return new;
}
return NULL;
}
-static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn, Scene *scene)
+static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn, const Scene *UNUSED(scene))
{
wmWindow *win = wmn->wm->winactive;
- ScrArea *sa;
unsigned int lay_used = 0;
- Base *base;
if (!win) return;
- base = scene->base.first;
- while (base) {
- lay_used |= base->lay & ((1 << 20) - 1); /* ignore localview */
-
- if (lay_used == (1 << 20) - 1)
- break;
-
- base = base->next;
- }
-
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+ const bScreen *screen = WM_window_get_active_screen(win);
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->spacetype == SPACE_VIEW3D) {
if (BLI_findindex(&sa->regionbase, ar) != -1) {
View3D *v3d = sa->spacedata.first;
@@ -795,13 +763,21 @@ static void view3d_recalc_used_layers(ARegion *ar, wmNotifier *wmn, Scene *scene
}
}
-static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, wmNotifier *wmn)
+static void view3d_main_region_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, ARegion *ar,
+ wmNotifier *wmn, const Scene *scene)
{
- Scene *scene = sc->scene;
View3D *v3d = sa->spacedata.first;
-
+ RegionView3D *rv3d = ar->regiondata;
+ wmManipulatorMap *mmap = ar->manipulator_map;
+
/* context changes */
switch (wmn->category) {
+ case NC_WM:
+ if (ELEM(wmn->data, ND_UNDO)) {
+ WM_manipulatormap_tag_refresh(mmap);
+ }
+ break;
case NC_ANIMATION:
switch (wmn->data) {
case ND_KEYFRAME_PROP:
@@ -821,21 +797,32 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
break;
case NC_SCENE:
switch (wmn->data) {
+ case ND_SCENEBROWSE:
case ND_LAYER_CONTENT:
if (wmn->reference)
view3d_recalc_used_layers(ar, wmn, wmn->reference);
ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(mmap);
+ break;
+ case ND_LAYER:
+ if (wmn->reference) {
+ BKE_screen_view3d_sync(v3d, wmn->reference);
+ }
+ ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(mmap);
break;
- case ND_FRAME:
- case ND_TRANSFORM:
case ND_OB_ACTIVE:
case ND_OB_SELECT:
+ DEG_id_tag_update((ID *)&scene->id, DEG_TAG_SELECT_UPDATE);
+ ATTR_FALLTHROUGH;
+ case ND_FRAME:
+ case ND_TRANSFORM:
case ND_OB_VISIBLE:
- case ND_LAYER:
case ND_RENDER_OPTIONS:
case ND_MARKERS:
case ND_MODE:
ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(mmap);
break;
case ND_WORLD:
/* handled by space_view3d_listener() for v3d access */
@@ -843,7 +830,6 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
case ND_DRAW_RENDER_VIEWPORT:
{
if (v3d->camera && (scene == wmn->reference)) {
- RegionView3D *rv3d = ar->regiondata;
if (rv3d->persp == RV3D_CAMOB) {
ED_region_tag_redraw(ar);
}
@@ -868,6 +854,7 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
case ND_POINTCACHE:
case ND_LOD:
ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(mmap);
break;
}
switch (wmn->action) {
@@ -878,9 +865,25 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
break;
case NC_GEOM:
switch (wmn->data) {
+ case ND_SELECT:
+ {
+ WM_manipulatormap_tag_refresh(mmap);
+
+ ID *ob_data = wmn->reference;
+ if (ob_data == NULL) {
+ BLI_assert(wmn->window); // Use `WM_event_add_notifier` instead of `WM_main_add_notifier`
+ ViewLayer *view_layer = WM_window_get_active_view_layer(wmn->window);
+ ob_data = OBEDIT_FROM_VIEW_LAYER(view_layer)->data;
+ }
+ if (ob_data) {
+ BLI_assert(OB_DATA_SUPPORT_ID(GS(ob_data->name)));
+ /* TODO(sergey): Notifiers shouldn't really be doing DEG tags. */
+ DEG_id_tag_update(ob_data, DEG_TAG_SELECT_UPDATE);
+ }
+ ATTR_FALLTHROUGH;
+ }
case ND_DATA:
case ND_VERTEX_GROUP:
- case ND_SELECT:
ED_region_tag_redraw(ar);
break;
}
@@ -895,7 +898,6 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
case ND_DRAW_RENDER_VIEWPORT:
{
if (v3d->camera && (v3d->camera->data == wmn->reference)) {
- RegionView3D *rv3d = ar->regiondata;
if (rv3d->persp == RV3D_CAMOB) {
ED_region_tag_redraw(ar);
}
@@ -924,21 +926,13 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
switch (wmn->data) {
case ND_SHADING:
case ND_NODES:
- {
-#ifdef WITH_LEGACY_DEPSGRAPH
- Object *ob = OBACT;
- if ((v3d->drawtype == OB_MATERIAL) ||
- (ob && (ob->mode == OB_MODE_TEXTURE_PAINT)) ||
- (v3d->drawtype == OB_TEXTURE &&
- (scene->gm.matmode == GAME_MAT_GLSL ||
- BKE_scene_use_new_shading_nodes(scene))) ||
- !DEG_depsgraph_use_legacy())
-#endif
- {
- ED_region_tag_redraw(ar);
- }
+ /* TODO(sergey) This is a bit too much updates, but needed to
+ * have proper material drivers update in the viewport.
+ *
+ * How to solve?
+ */
+ ED_region_tag_redraw(ar);
break;
- }
case ND_SHADING_DRAW:
case ND_SHADING_LINKS:
ED_region_tag_redraw(ar);
@@ -950,20 +944,23 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
case ND_WORLD_DRAW:
/* handled by space_view3d_listener() for v3d access */
break;
+ case ND_WORLD:
+ /* Needed for updating world materials */
+ ED_region_tag_redraw(ar);
+ break;
}
break;
case NC_LAMP:
switch (wmn->data) {
case ND_LIGHTING:
- if ((v3d->drawtype == OB_MATERIAL) ||
- (v3d->drawtype == OB_TEXTURE && (scene->gm.matmode == GAME_MAT_GLSL)) ||
- !DEG_depsgraph_use_legacy())
- {
- ED_region_tag_redraw(ar);
- }
+ /* TODO(sergey): This is a bit too much, but needed to
+ * handle updates from new depsgraph.
+ */
+ ED_region_tag_redraw(ar);
break;
case ND_LIGHTING_DRAW:
ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(mmap);
break;
}
break;
@@ -983,10 +980,10 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
case NC_SPACE:
if (wmn->data == ND_SPACE_VIEW3D) {
if (wmn->subtype == NS_VIEW3D_GPU) {
- RegionView3D *rv3d = ar->regiondata;
rv3d->rflag |= RV3D_GPULIGHT_UPDATE;
}
ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(mmap);
}
break;
case NC_ID:
@@ -999,15 +996,13 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
case ND_SKETCH:
ED_region_tag_redraw(ar);
break;
- case ND_SCREENBROWSE:
- case ND_SCREENDELETE:
- case ND_SCREENSET:
- /* screen was changed, need to update used layers due to NC_SCENE|ND_LAYER_CONTENT */
- /* updates used layers only for View3D in active screen */
- if (wmn->reference) {
- bScreen *sc_ref = wmn->reference;
- view3d_recalc_used_layers(ar, wmn, sc_ref->scene);
- }
+ case ND_LAYOUTBROWSE:
+ case ND_LAYOUTDELETE:
+ case ND_LAYOUTSET:
+ WM_manipulatormap_tag_refresh(mmap);
+ ED_region_tag_redraw(ar);
+ break;
+ case ND_LAYER:
ED_region_tag_redraw(ar);
break;
}
@@ -1021,12 +1016,90 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
}
}
+static void view3d_main_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *scene,
+ struct bScreen *UNUSED(screen), struct ScrArea *UNUSED(sa), struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ /* Developer note: there are many properties that impact 3D view drawing,
+ * so instead of subscribing to individual properties, just subscribe to types
+ * accepting some redundant redraws.
+ *
+ * For other space types we might try avoid this, keep the 3D view as an exceptional case! */
+ wmMsgParams_RNA msg_key_params = {{{0}}};
+
+ /* Only subscribe to types. */
+ StructRNA *type_array[] = {
+ &RNA_Window,
+
+ /* These object have properties that impact drawing. */
+ &RNA_AreaLamp,
+ &RNA_Camera,
+ &RNA_Lamp,
+ &RNA_Speaker,
+ &RNA_SunLamp,
+
+ /* General types the 3D view depends on. */
+ &RNA_Object,
+ &RNA_UnitSettings, /* grid-floor */
+
+ &RNA_View3DOverlay,
+ &RNA_View3DShading,
+ &RNA_World,
+ };
+
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ for (int i = 0; i < ARRAY_SIZE(type_array); i++) {
+ msg_key_params.ptr.type = type_array[i];
+ WM_msg_subscribe_rna_params(
+ mbus,
+ &msg_key_params,
+ &msg_sub_value_region_tag_redraw,
+ __func__);
+ }
+
+ /* Subscribe to a handful of other properties. */
+ RegionView3D *rv3d = ar->regiondata;
+
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, engine, &msg_sub_value_region_tag_redraw);
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, resolution_x, &msg_sub_value_region_tag_redraw);
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, resolution_y, &msg_sub_value_region_tag_redraw);
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, pixel_aspect_x, &msg_sub_value_region_tag_redraw);
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, pixel_aspect_y, &msg_sub_value_region_tag_redraw);
+ if (rv3d->persp == RV3D_CAMOB) {
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, use_border, &msg_sub_value_region_tag_redraw);
+ }
+
+ /* Each engine could be responsible for its own engine data types.
+ * For now this is simplest. */
+ if (STREQ(scene->r.engine, RE_engine_id_BLENDER_EEVEE)) {
+ extern StructRNA RNA_ViewLayerEngineSettingsEevee;
+ WM_msg_subscribe_rna_anon_type(mbus, ViewLayerEngineSettingsEevee, &msg_sub_value_region_tag_redraw);
+ }
+ else if (STREQ(scene->r.engine, RE_engine_id_BLENDER_WORKBENCH)) {
+ extern StructRNA RNA_ViewLayerEngineSettingsWorkbench;
+ WM_msg_subscribe_rna_anon_type(mbus, ViewLayerEngineSettingsWorkbench, &msg_sub_value_region_tag_redraw);
+ }
+#ifdef WITH_CLAY_ENGINE
+ else if (STREQ(scene->r.engine, RE_engine_id_BLENDER_CLAY)) {
+ extern StructRNA RNA_ViewLayerEngineSettingsClay;
+ WM_msg_subscribe_rna_anon_type(mbus, ViewLayerEngineSettingsClay, &msg_sub_value_region_tag_redraw);
+ }
+#endif
+}
+
/* concept is to retrieve cursor type context-less */
static void view3d_main_region_cursor(wmWindow *win, ScrArea *UNUSED(sa), ARegion *UNUSED(ar))
{
- Scene *scene = win->screen->scene;
-
- if (scene->obedit) {
+ ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+ Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
+ if (obedit) {
WM_cursor_set(win, CURSOR_EDIT);
}
else {
@@ -1049,7 +1122,9 @@ static void view3d_header_region_draw(const bContext *C, ARegion *ar)
ED_region_header(C, ar);
}
-static void view3d_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void view3d_header_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -1079,6 +1154,36 @@ static void view3d_header_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(s
}
}
+static void view3d_header_region_message_subscribe(
+ const struct bContext *UNUSED(C),
+ struct WorkSpace *UNUSED(workspace), struct Scene *UNUSED(scene),
+ struct bScreen *UNUSED(screen), struct ScrArea *UNUSED(sa), struct ARegion *ar,
+ struct wmMsgBus *mbus)
+{
+ wmMsgParams_RNA msg_key_params = {{{0}}};
+
+ /* Only subscribe to types. */
+ StructRNA *type_array[] = {
+ &RNA_View3DShading,
+ };
+
+ wmMsgSubscribeValue msg_sub_value_region_tag_redraw = {
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ };
+
+ for (int i = 0; i < ARRAY_SIZE(type_array); i++) {
+ msg_key_params.ptr.type = type_array[i];
+ WM_msg_subscribe_rna_params(
+ mbus,
+ &msg_key_params,
+ &msg_sub_value_region_tag_redraw,
+ __func__);
+ }
+}
+
+
/* add handlers, stuff you only do once or on area/region changes */
static void view3d_buttons_region_init(wmWindowManager *wm, ARegion *ar)
{
@@ -1095,7 +1200,9 @@ static void view3d_buttons_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, NULL, -1, true);
}
-static void view3d_buttons_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
+static void view3d_buttons_region_listener(
+ bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar,
+ wmNotifier *wmn, const Scene *UNUSED(scene))
{
/* context changes */
switch (wmn->category) {
@@ -1185,6 +1292,27 @@ static void view3d_buttons_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(
}
}
+static int view3d_tools_region_snap_size(const ARegion *ar, int size, int axis)
+{
+ if (axis == 0) {
+ /* Note, this depends on the icon size: see #ICON_DEFAULT_HEIGHT_TOOLBAR. */
+ const float snap_units[] = {3 + 0.25f, 5 + 0.25};
+ const float aspect = BLI_rctf_size_x(&ar->v2d.cur) / (BLI_rcti_size_x(&ar->v2d.mask) + 1);
+ int best_diff = INT_MAX;
+ int best_size = size;
+ for (uint i = 0; i < ARRAY_SIZE(snap_units); i += 1) {
+ const int test_size = (snap_units[i] * U.widget_unit) / (UI_DPI_FAC * aspect);
+ const int test_diff = ABS(test_size - size);
+ if (test_diff < best_diff) {
+ best_size = test_size;
+ best_diff = test_diff;
+ }
+ }
+ return best_size;
+ }
+ return size;
+}
+
/* add handlers, stuff you only do once or on area/region changes */
static void view3d_tools_region_init(wmWindowManager *wm, ARegion *ar)
{
@@ -1201,27 +1329,10 @@ static void view3d_tools_region_draw(const bContext *C, ARegion *ar)
ED_region_panels(C, ar, CTX_data_mode_string(C), -1, true);
}
-static void view3d_props_region_listener(bScreen *UNUSED(sc), ScrArea *UNUSED(sa), ARegion *ar, wmNotifier *wmn)
-{
- /* context changes */
- switch (wmn->category) {
- case NC_WM:
- if (wmn->data == ND_HISTORY)
- ED_region_tag_redraw(ar);
- break;
- case NC_SCENE:
- if (wmn->data == ND_MODE)
- ED_region_tag_redraw(ar);
- break;
- case NC_SPACE:
- if (wmn->data == ND_SPACE_VIEW3D)
- ED_region_tag_redraw(ar);
- break;
- }
-}
-
/* area (not region) level listener */
-static void space_view3d_listener(bScreen *UNUSED(sc), ScrArea *sa, struct wmNotifier *wmn)
+static void space_view3d_listener(
+ bScreen *UNUSED(sc), ScrArea *sa, struct wmNotifier *wmn, Scene *UNUSED(scene),
+ WorkSpace *UNUSED(workspace))
{
View3D *v3d = sa->spacedata.first;
@@ -1256,8 +1367,6 @@ static void space_view3d_listener(bScreen *UNUSED(sc), ScrArea *sa, struct wmNot
}
const char *view3d_context_dir[] = {
- "selected_objects", "selected_bases", "selected_editable_objects",
- "selected_editable_bases", "visible_objects", "visible_bases", "selectable_objects", "selectable_bases",
"active_base", "active_object", NULL
};
@@ -1268,109 +1377,27 @@ static int view3d_context(const bContext *C, const char *member, bContextDataRes
if (CTX_data_dir(member)) {
CTX_data_dir_set(result, view3d_context_dir);
}
- else if (CTX_data_equals(member, "selected_objects") || CTX_data_equals(member, "selected_bases")) {
- View3D *v3d = CTX_wm_view3d(C);
- Scene *scene = CTX_data_scene(C);
- const unsigned int lay = v3d ? v3d->lay : scene->lay;
- Base *base;
- const bool selected_objects = CTX_data_equals(member, "selected_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if ((base->flag & SELECT) && (base->lay & lay)) {
- if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
- if (selected_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
- }
- }
- }
- CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
- return 1;
- }
- else if (CTX_data_equals(member, "selected_editable_objects") || CTX_data_equals(member, "selected_editable_bases")) {
- View3D *v3d = CTX_wm_view3d(C);
- Scene *scene = CTX_data_scene(C);
- const unsigned int lay = v3d ? v3d->lay : scene->lay;
- Base *base;
- const bool selected_editable_objects = CTX_data_equals(member, "selected_editable_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if ((base->flag & SELECT) && (base->lay & lay)) {
- if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
- if (0 == BKE_object_is_libdata(base->object)) {
- if (selected_editable_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
- }
- }
- }
- }
- CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
- return 1;
- }
- else if (CTX_data_equals(member, "visible_objects") || CTX_data_equals(member, "visible_bases")) {
- View3D *v3d = CTX_wm_view3d(C);
- Scene *scene = CTX_data_scene(C);
- const unsigned int lay = v3d ? v3d->lay : scene->lay;
- Base *base;
- const bool visible_objects = CTX_data_equals(member, "visible_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if (base->lay & lay) {
- if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0) {
- if (visible_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
- }
- }
- }
- CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
- return 1;
- }
- else if (CTX_data_equals(member, "selectable_objects") || CTX_data_equals(member, "selectable_bases")) {
- View3D *v3d = CTX_wm_view3d(C);
- Scene *scene = CTX_data_scene(C);
- const unsigned int lay = v3d ? v3d->lay : scene->lay;
- Base *base;
- const bool selectable_objects = CTX_data_equals(member, "selectable_objects");
-
- for (base = scene->base.first; base; base = base->next) {
- if (base->lay & lay) {
- if ((base->object->restrictflag & OB_RESTRICT_VIEW) == 0 && (base->object->restrictflag & OB_RESTRICT_SELECT) == 0) {
- if (selectable_objects)
- CTX_data_id_list_add(result, &base->object->id);
- else
- CTX_data_list_add(result, &scene->id, &RNA_ObjectBase, base);
- }
- }
- }
- CTX_data_type_set(result, CTX_DATA_TYPE_COLLECTION);
- return 1;
- }
else if (CTX_data_equals(member, "active_base")) {
- View3D *v3d = CTX_wm_view3d(C);
Scene *scene = CTX_data_scene(C);
- const unsigned int lay = v3d ? v3d->lay : scene->lay;
- if (scene->basact && (scene->basact->lay & lay)) {
- Object *ob = scene->basact->object;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ if (view_layer->basact) {
+ Object *ob = view_layer->basact->object;
/* if hidden but in edit mode, we still display, can happen with animation */
- if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT))
- CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, scene->basact);
+ if ((view_layer->basact->flag & BASE_VISIBLED) != 0 || (ob->mode & OB_MODE_EDIT)) {
+ CTX_data_pointer_set(result, &scene->id, &RNA_ObjectBase, view_layer->basact);
+ }
}
return 1;
}
else if (CTX_data_equals(member, "active_object")) {
- View3D *v3d = CTX_wm_view3d(C);
- Scene *scene = CTX_data_scene(C);
- const unsigned int lay = v3d ? v3d->lay : scene->lay;
- if (scene->basact && (scene->basact->lay & lay)) {
- Object *ob = scene->basact->object;
- if ((ob->restrictflag & OB_RESTRICT_VIEW) == 0 || (ob->mode & OB_MODE_EDIT))
- CTX_data_id_pointer_set(result, &scene->basact->object->id);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ if (view_layer->basact) {
+ Object *ob = view_layer->basact->object;
+ /* if hidden but in edit mode, we still display, can happen with animation */
+ if ((view_layer->basact->flag & BASE_VISIBLED) != 0 || (ob->mode & OB_MODE_EDIT) != 0) {
+ CTX_data_id_pointer_set(result, &ob->id);
+ }
}
return 1;
@@ -1411,8 +1438,6 @@ static void view3d_id_remap(ScrArea *sa, SpaceLink *slink, ID *old_id, ID *new_i
/* Values in local-view aren't used, see: T52663 */
if (is_local == false) {
- /* Skip 'v3d->defmaterial', it's not library data. */
-
if ((ID *)v3d->ob_centre == old_id) {
v3d->ob_centre = (Object *)new_id;
/* Otherwise, bonename may remain valid... We could be smart and check this, too? */
@@ -1420,21 +1445,6 @@ static void view3d_id_remap(ScrArea *sa, SpaceLink *slink, ID *old_id, ID *new_i
v3d->ob_centre_bone[0] = '\0';
}
}
-
- if (ELEM(GS(old_id->name), ID_IM, ID_MC)) {
- for (BGpic *bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- if ((ID *)bgpic->ima == old_id) {
- bgpic->ima = (Image *)new_id;
- id_us_min(old_id);
- id_us_plus(new_id);
- }
- if ((ID *)bgpic->clip == old_id) {
- bgpic->clip = (MovieClip *)new_id;
- id_us_min(old_id);
- id_us_plus(new_id);
- }
- }
- }
}
if (is_local) {
@@ -1460,6 +1470,7 @@ void ED_spacetype_view3d(void)
st->operatortypes = view3d_operatortypes;
st->keymap = view3d_keymap;
st->dropboxes = view3d_dropboxes;
+ st->manipulators = view3d_widgets;
st->context = view3d_context;
st->id_remap = view3d_id_remap;
@@ -1473,6 +1484,7 @@ void ED_spacetype_view3d(void)
art->free = view3d_main_region_free;
art->duplicate = view3d_main_region_duplicate;
art->listener = view3d_main_region_listener;
+ art->message_subscribe = view3d_main_region_message_subscribe;
art->cursor = view3d_main_region_cursor;
art->lock = 1; /* can become flag, see BKE_spacedata_draw_locks */
BLI_addhead(&st->regiontypes, art);
@@ -1496,6 +1508,7 @@ void ED_spacetype_view3d(void)
art->prefsizey = 50; /* XXX */
art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
art->listener = view3d_buttons_region_listener;
+ art->snap_size = view3d_tools_region_snap_size;
art->init = view3d_tools_region_init;
art->draw = view3d_tools_region_draw;
BLI_addhead(&st->regiontypes, art);
@@ -1505,20 +1518,6 @@ void ED_spacetype_view3d(void)
view3d_toolshelf_register(art);
#endif
- /* regions: tool properties */
- art = MEM_callocN(sizeof(ARegionType), "spacetype view3d tool properties region");
- art->regionid = RGN_TYPE_TOOL_PROPS;
- art->prefsizex = 0;
- art->prefsizey = 120;
- art->keymapflag = ED_KEYMAP_UI | ED_KEYMAP_FRAMES;
- art->listener = view3d_props_region_listener;
- art->init = view3d_tools_region_init;
- art->draw = view3d_tools_region_draw;
- BLI_addhead(&st->regiontypes, art);
-
- view3d_tool_props_register(art);
-
-
/* regions: header */
art = MEM_callocN(sizeof(ARegionType), "spacetype view3d header region");
art->regionid = RGN_TYPE_HEADER;
@@ -1527,8 +1526,8 @@ void ED_spacetype_view3d(void)
art->listener = view3d_header_region_listener;
art->init = view3d_header_region_init;
art->draw = view3d_header_region_draw;
+ art->message_subscribe = view3d_header_region_message_subscribe;
BLI_addhead(&st->regiontypes, art);
BKE_spacetype_register(st);
}
-
diff --git a/source/blender/editors/space_view3d/view3d_buttons.c b/source/blender/editors/space_view3d/view3d_buttons.c
index 0c67776693d..644a6956e54 100644
--- a/source/blender/editors/space_view3d/view3d_buttons.c
+++ b/source/blender/editors/space_view3d/view3d_buttons.c
@@ -55,13 +55,14 @@
#include "BKE_context.h"
#include "BKE_curve.h"
#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
#include "BKE_screen.h"
#include "BKE_editmesh.h"
#include "BKE_deform.h"
#include "BKE_object.h"
#include "BKE_object_deform.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -776,18 +777,18 @@ static void do_view3d_vgroup_buttons(bContext *C, void *UNUSED(arg), int event)
return;
}
else {
- Scene *scene = CTX_data_scene(C);
- Object *ob = scene->basact->object;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = view_layer->basact->object;
ED_vgroup_vert_active_mirror(ob, event - B_VGRP_PNL_EDIT_SINGLE);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ob->data);
}
}
static int view3d_panel_vgroup_poll(const bContext *C, PanelType *UNUSED(pt))
{
- Scene *scene = CTX_data_scene(C);
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
if (ob && (BKE_object_is_in_editmode_vgroup(ob) ||
BKE_object_is_in_wpaint_select_vert(ob)))
{
@@ -805,7 +806,8 @@ static void view3d_panel_vgroup(const bContext *C, Panel *pa)
{
uiBlock *block = uiLayoutAbsoluteBlock(pa->layout);
Scene *scene = CTX_data_scene(C);
- Object *ob = scene->basact->object;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = view_layer->basact->object;
MDeformVert *dv;
@@ -1095,9 +1097,9 @@ static void v3d_editmetaball_buts(uiLayout *layout, Object *ob)
static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event)
{
- Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C);
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
switch (event) {
@@ -1108,7 +1110,7 @@ static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event
case B_OBJECTPANELMEDIAN:
if (ob) {
v3d_editvertex_buts(NULL, v3d, ob, 1.0);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
break;
}
@@ -1119,16 +1121,17 @@ static void do_view3d_region_buttons(bContext *C, void *UNUSED(index), int event
static int view3d_panel_transform_poll(const bContext *C, PanelType *UNUSED(pt))
{
- Scene *scene = CTX_data_scene(C);
- return (scene->basact != NULL);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ return (view_layer->basact != NULL);
}
static void view3d_panel_transform(const bContext *C, Panel *pa)
{
uiBlock *block;
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
- Object *ob = scene->basact->object;
+ Object *ob = view_layer->basact->object;
uiLayout *col;
block = uiLayoutGetBlock(pa->layout);
diff --git a/source/blender/editors/space_view3d/view3d_camera_control.c b/source/blender/editors/space_view3d/view3d_camera_control.c
index e27b3fe13f9..d0475684262 100644
--- a/source/blender/editors/space_view3d/view3d_camera_control.c
+++ b/source/blender/editors/space_view3d/view3d_camera_control.c
@@ -54,8 +54,9 @@
#include "BLI_utildefines.h"
#include "BKE_object.h"
+#include "BKE_context.h"
-#include "BKE_depsgraph.h" /* for object updating */
+#include "DEG_depsgraph.h"
#include "ED_screen.h"
@@ -137,7 +138,7 @@ Object *ED_view3d_cameracontrol_object_get(View3DCameraControl *vctrl)
* the view for first-person style navigation.
*/
struct View3DCameraControl *ED_view3d_cameracontrol_acquire(
- Scene *scene, View3D *v3d, RegionView3D *rv3d,
+ Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d,
const bool use_parent_root)
{
View3DCameraControl *vctrl;
@@ -177,7 +178,7 @@ struct View3DCameraControl *ED_view3d_cameracontrol_acquire(
/* store the original camera loc and rot */
vctrl->obtfm = BKE_object_tfm_backup(ob_back);
- BKE_object_where_is_calc(scene, v3d->camera);
+ BKE_object_where_is_calc(depsgraph, scene, v3d->camera);
negate_v3_v3(rv3d->ofs, v3d->camera->obmat[3]);
rv3d->dist = 0.0;
@@ -242,7 +243,7 @@ void ED_view3d_cameracontrol_update(
ob_update = v3d->camera->parent;
while (ob_update) {
- DAG_id_tag_update(&ob_update->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob_update->id, OB_RECALC_OB);
ob_update = ob_update->parent;
}
@@ -264,7 +265,7 @@ void ED_view3d_cameracontrol_update(
BKE_object_apply_mat4(v3d->camera, view_mat, true, true);
- DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
+ DEG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
copy_v3_v3(v3d->camera->size, size_back);
@@ -299,7 +300,7 @@ void ED_view3d_cameracontrol_release(
/* store the original camera loc and rot */
BKE_object_tfm_restore(ob_back, vctrl->obtfm);
- DAG_id_tag_update(&ob_back->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob_back->id, OB_RECALC_OB);
}
else {
/* Non Camera we need to reset the view back to the original location bacause the user canceled*/
@@ -311,7 +312,7 @@ void ED_view3d_cameracontrol_release(
rv3d->dist = vctrl->dist_backup;
}
else if (vctrl->persp_backup == RV3D_CAMOB) { /* camera */
- DAG_id_tag_update((ID *)view3d_cameracontrol_object(vctrl), OB_RECALC_OB);
+ DEG_id_tag_update((ID *)view3d_cameracontrol_object(vctrl), OB_RECALC_OB);
/* always, is set to zero otherwise */
copy_v3_v3(rv3d->ofs, vctrl->ofs_backup);
diff --git a/source/blender/editors/space_view3d/view3d_draw.c b/source/blender/editors/space_view3d/view3d_draw.c
index cc046eebc68..99f7abba065 100644
--- a/source/blender/editors/space_view3d/view3d_draw.c
+++ b/source/blender/editors/space_view3d/view3d_draw.c
@@ -28,950 +28,276 @@
* \ingroup spview3d
*/
-#include <string.h>
-#include <stdio.h>
#include <math.h>
-#include "DNA_armature_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_customdata_types.h"
-#include "DNA_object_types.h"
-#include "DNA_group_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_key_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_world_types.h"
-#include "DNA_brush_types.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
-#include "BLI_jitter_2d.h"
-#include "BLI_utildefines.h"
-#include "BLI_endian_switch.h"
+#include "BLI_rect.h"
+#include "BLI_string.h"
#include "BLI_threads.h"
+#include "BLI_jitter_2d.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
-#include "BKE_anim.h"
#include "BKE_camera.h"
#include "BKE_context.h"
-#include "BKE_customdata.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_image.h"
+#include "BKE_global.h"
#include "BKE_key.h"
-#include "BKE_main.h"
+#include "BKE_scene.h"
#include "BKE_object.h"
-#include "BKE_global.h"
#include "BKE_paint.h"
-#include "BKE_scene.h"
-#include "BKE_screen.h"
#include "BKE_unit.h"
-#include "BKE_movieclip.h"
-#include "RE_engine.h"
-
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-#include "IMB_colormanagement.h"
+#include "BLF_api.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "BLT_translation.h"
-#include "WM_api.h"
+#include "DNA_armature_types.h"
+#include "DNA_brush_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_key_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
-#include "BLF_api.h"
-#include "BLT_translation.h"
+#include "DRW_engine.h"
#include "ED_armature.h"
#include "ED_keyframing.h"
#include "ED_gpencil.h"
#include "ED_screen.h"
-#include "ED_space_api.h"
-#include "ED_screen_types.h"
#include "ED_transform.h"
-#include "UI_interface.h"
-#include "UI_interface_icons.h"
-#include "UI_resources.h"
+#include "DEG_depsgraph_query.h"
+#include "GPU_batch.h"
#include "GPU_draw.h"
-#include "GPU_framebuffer.h"
+#include "GPU_matrix.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
#include "GPU_material.h"
-#include "GPU_compositing.h"
-#include "GPU_extensions.h"
-#include "GPU_select.h"
-
-#include "view3d_intern.h" /* own include */
-
-/* prototypes */
-static bool view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d);
-static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect);
-static void view3d_stereo3d_setup_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
- float winmat[4][4], const char *viewname);
-
-/* handy utility for drawing shapes in the viewport for arbitrary code.
- * could add lines and points too */
-// #define DEBUG_DRAW
-#ifdef DEBUG_DRAW
-static void bl_debug_draw(void);
-/* add these locally when using these functions for testing */
-extern void bl_debug_draw_quad_clear(void);
-extern void bl_debug_draw_quad_add(const float v0[3], const float v1[3], const float v2[3], const float v3[3]);
-extern void bl_debug_draw_edge_add(const float v0[3], const float v1[3]);
-extern void bl_debug_color_set(const unsigned int col);
-#endif
-
-void circf(float x, float y, float rad)
-{
- GLUquadricObj *qobj = gluNewQuadric();
-
- gluQuadricDrawStyle(qobj, GLU_FILL);
-
- glPushMatrix();
-
- glTranslatef(x, y, 0.0);
-
- gluDisk(qobj, 0.0, rad, 32, 1);
-
- glPopMatrix();
-
- gluDeleteQuadric(qobj);
-}
-
-void circ(float x, float y, float rad)
-{
- GLUquadricObj *qobj = gluNewQuadric();
-
- gluQuadricDrawStyle(qobj, GLU_SILHOUETTE);
-
- glPushMatrix();
-
- glTranslatef(x, y, 0.0);
-
- gluDisk(qobj, 0.0, rad, 32, 1);
-
- glPopMatrix();
-
- gluDeleteQuadric(qobj);
-}
-
-
-/* ********* custom clipping *********** */
-
-static void view3d_draw_clipping(RegionView3D *rv3d)
-{
- BoundBox *bb = rv3d->clipbb;
-
- if (bb) {
- const unsigned int clipping_index[6][4] = {
- {0, 1, 2, 3},
- {0, 4, 5, 1},
- {4, 7, 6, 5},
- {7, 3, 2, 6},
- {1, 5, 6, 2},
- {7, 4, 0, 3}
- };
-
- /* fill in zero alpha for rendering & re-projection [#31530] */
- unsigned char col[4];
- UI_GetThemeColor4ubv(TH_V3D_CLIPPING_BORDER, col);
- glColor4ubv(col);
-
- glEnable(GL_BLEND);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, bb->vec);
- glDrawElements(GL_QUADS, sizeof(clipping_index) / sizeof(unsigned int), GL_UNSIGNED_INT, clipping_index);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisable(GL_BLEND);
- }
-}
-
-void ED_view3d_clipping_set(RegionView3D *rv3d)
-{
- double plane[4];
- const unsigned int tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
- unsigned int a;
-
- for (a = 0; a < tot; a++) {
- copy_v4db_v4fl(plane, rv3d->clip[a]);
- glClipPlane(GL_CLIP_PLANE0 + a, plane);
- glEnable(GL_CLIP_PLANE0 + a);
- }
-}
-
-/* use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set */
-void ED_view3d_clipping_disable(void)
-{
- unsigned int a;
-
- for (a = 0; a < 6; a++) {
- glDisable(GL_CLIP_PLANE0 + a);
- }
-}
-void ED_view3d_clipping_enable(void)
-{
- unsigned int a;
-
- for (a = 0; a < 6; a++) {
- glEnable(GL_CLIP_PLANE0 + a);
- }
-}
-
-static bool view3d_clipping_test(const float co[3], const float clip[6][4])
-{
- if (plane_point_side_v3(clip[0], co) > 0.0f)
- if (plane_point_side_v3(clip[1], co) > 0.0f)
- if (plane_point_side_v3(clip[2], co) > 0.0f)
- if (plane_point_side_v3(clip[3], co) > 0.0f)
- return false;
-
- return true;
-}
-
-/* for 'local' ED_view3d_clipping_local must run first
- * then all comparisons can be done in localspace */
-bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
-{
- return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
-}
-
-/* ********* end custom clipping *********** */
-
+#include "GPU_viewport.h"
-static void drawgrid_draw(ARegion *ar, double wx, double wy, double x, double y, double dx)
-{
- double verts[2][2];
-
- x += (wx);
- y += (wy);
+#include "MEM_guardedalloc.h"
- /* set fixed 'Y' */
- verts[0][1] = 0.0f;
- verts[1][1] = (double)ar->winy;
+#include "UI_interface.h"
+#include "UI_resources.h"
- /* iter over 'X' */
- verts[0][0] = verts[1][0] = x - dx * floor(x / dx);
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_DOUBLE, 0, verts);
+#include "RE_engine.h"
- while (verts[0][0] < ar->winx) {
- glDrawArrays(GL_LINES, 0, 2);
- verts[0][0] = verts[1][0] = verts[0][0] + dx;
- }
+#include "WM_api.h"
+#include "WM_types.h"
- /* set fixed 'X' */
- verts[0][0] = 0.0f;
- verts[1][0] = (double)ar->winx;
+#include "RNA_access.h"
- /* iter over 'Y' */
- verts[0][1] = verts[1][1] = y - dx * floor(y / dx);
- while (verts[0][1] < ar->winy) {
- glDrawArrays(GL_LINES, 0, 2);
- verts[0][1] = verts[1][1] = verts[0][1] + dx;
- }
+#include "IMB_imbuf.h"
+#include "IMB_imbuf_types.h"
- glDisableClientState(GL_VERTEX_ARRAY);
-}
+#include "view3d_intern.h" /* own include */
-#define GRID_MIN_PX_D 6.0
-#define GRID_MIN_PX_F 6.0f
+/* ******************** general functions ***************** */
-static void drawgrid(UnitSettings *unit, ARegion *ar, View3D *v3d, const char **grid_unit)
+/**
+ * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore
+ */
+void ED_view3d_update_viewmat(
+ Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar,
+ float viewmat[4][4], float winmat[4][4], const rcti *rect)
{
- /* extern short bgpicmode; */
RegionView3D *rv3d = ar->regiondata;
- double wx, wy, x, y, fw, fx, fy, dx;
- double vec4[4];
- unsigned char col[3], col2[3];
-
- fx = rv3d->persmat[3][0];
- fy = rv3d->persmat[3][1];
- fw = rv3d->persmat[3][3];
-
- wx = (ar->winx / 2.0); /* because of rounding errors, grid at wrong location */
- wy = (ar->winy / 2.0);
-
- x = (wx) * fx / fw;
- y = (wy) * fy / fw;
-
- vec4[0] = vec4[1] = v3d->grid;
-
- vec4[2] = 0.0;
- vec4[3] = 1.0;
- mul_m4_v4d(rv3d->persmat, vec4);
- fx = vec4[0];
- fy = vec4[1];
- fw = vec4[3];
-
- dx = fabs(x - (wx) * fx / fw);
- if (dx == 0) dx = fabs(y - (wy) * fy / fw);
-
- glLineWidth(1.0f);
- glDepthMask(GL_FALSE); /* disable write in zbuffer */
-
- /* check zoom out */
- UI_ThemeColor(TH_GRID);
-
- if (unit->system) {
- /* Use GRID_MIN_PX * 2 for units because very very small grid
- * items are less useful when dealing with units */
- const void *usys;
- int len, i;
- double dx_scalar;
- float blend_fac;
-
- bUnit_GetSystem(unit->system, B_UNIT_LENGTH, &usys, &len);
-
- if (usys) {
- i = len;
- while (i--) {
- double scalar = bUnit_GetScaler(usys, i);
-
- dx_scalar = dx * scalar / (double)unit->scale_length;
- if (dx_scalar < (GRID_MIN_PX_D * 2.0))
- continue;
-
- /* Store the smallest drawn grid size units name so users know how big each grid cell is */
- if (*grid_unit == NULL) {
- *grid_unit = bUnit_GetNameDisplay(usys, i);
- rv3d->gridview = (float)((scalar * (double)v3d->grid) / (double)unit->scale_length);
- }
- blend_fac = 1.0f - ((GRID_MIN_PX_F * 2.0f) / (float)dx_scalar);
-
- /* tweak to have the fade a bit nicer */
- blend_fac = (blend_fac * blend_fac) * 2.0f;
- CLAMP(blend_fac, 0.3f, 1.0f);
-
-
- UI_ThemeColorBlend(TH_HIGH_GRAD, TH_GRID, blend_fac);
+ /* setup window matrices */
+ if (winmat)
+ copy_m4_m4(rv3d->winmat, winmat);
+ else
+ view3d_winmatrix_set(depsgraph, ar, v3d, rect);
- drawgrid_draw(ar, wx, wy, x, y, dx_scalar);
- }
- }
+ /* setup view matrix */
+ if (viewmat) {
+ copy_m4_m4(rv3d->viewmat, viewmat);
}
else {
- const double sublines = v3d->gridsubdiv;
- const float sublines_fl = v3d->gridsubdiv;
-
- if (dx < GRID_MIN_PX_D) {
- rv3d->gridview *= sublines_fl;
- dx *= sublines;
-
- if (dx < GRID_MIN_PX_D) {
- rv3d->gridview *= sublines_fl;
- dx *= sublines;
-
- if (dx < GRID_MIN_PX_D) {
- rv3d->gridview *= sublines_fl;
- dx *= sublines;
- if (dx < GRID_MIN_PX_D) {
- /* pass */
- }
- else {
- UI_ThemeColor(TH_GRID);
- drawgrid_draw(ar, wx, wy, x, y, dx);
- }
- }
- else { /* start blending out */
- UI_ThemeColorBlend(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0));
- drawgrid_draw(ar, wx, wy, x, y, dx);
-
- UI_ThemeColor(TH_GRID);
- drawgrid_draw(ar, wx, wy, x, y, sublines * dx);
- }
- }
- else { /* start blending out (GRID_MIN_PX < dx < (GRID_MIN_PX * 10)) */
- UI_ThemeColorBlend(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0));
- drawgrid_draw(ar, wx, wy, x, y, dx);
-
- UI_ThemeColor(TH_GRID);
- drawgrid_draw(ar, wx, wy, x, y, sublines * dx);
- }
- }
- else {
- if (dx > (GRID_MIN_PX_D * 10.0)) { /* start blending in */
- rv3d->gridview /= sublines_fl;
- dx /= sublines;
- if (dx > (GRID_MIN_PX_D * 10.0)) { /* start blending in */
- rv3d->gridview /= sublines_fl;
- dx /= sublines;
- if (dx > (GRID_MIN_PX_D * 10.0)) {
- UI_ThemeColor(TH_GRID);
- drawgrid_draw(ar, wx, wy, x, y, dx);
- }
- else {
- UI_ThemeColorBlend(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0));
- drawgrid_draw(ar, wx, wy, x, y, dx);
- UI_ThemeColor(TH_GRID);
- drawgrid_draw(ar, wx, wy, x, y, dx * sublines);
- }
- }
- else {
- UI_ThemeColorBlend(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0));
- drawgrid_draw(ar, wx, wy, x, y, dx);
- UI_ThemeColor(TH_GRID);
- drawgrid_draw(ar, wx, wy, x, y, dx * sublines);
- }
- }
- else {
- UI_ThemeColorBlend(TH_HIGH_GRAD, TH_GRID, dx / (GRID_MIN_PX_D * 6.0));
- drawgrid_draw(ar, wx, wy, x, y, dx);
- UI_ThemeColor(TH_GRID);
- drawgrid_draw(ar, wx, wy, x, y, dx * sublines);
- }
+ float rect_scale[2];
+ if (rect) {
+ rect_scale[0] = (float)BLI_rcti_size_x(rect) / (float)ar->winx;
+ rect_scale[1] = (float)BLI_rcti_size_y(rect) / (float)ar->winy;
}
+ /* note: calls BKE_object_where_is_calc for camera... */
+ view3d_viewmatrix_set(depsgraph, scene, v3d, rv3d, rect ? rect_scale : NULL);
}
+ /* update utility matrices */
+ mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
+ invert_m4_m4(rv3d->persinv, rv3d->persmat);
+ invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
+ /* calculate GLSL view dependent values */
- x += (wx);
- y += (wy);
- UI_GetThemeColor3ubv(TH_GRID, col);
+ /* store window coordinates scaling/offset */
+ if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
+ rctf cameraborder;
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &cameraborder, false);
+ rv3d->viewcamtexcofac[0] = (float)ar->winx / BLI_rctf_size_x(&cameraborder);
+ rv3d->viewcamtexcofac[1] = (float)ar->winy / BLI_rctf_size_y(&cameraborder);
- setlinestyle(0);
-
- /* center cross */
- /* horizontal line */
- if (ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT))
- UI_make_axis_color(col, col2, 'Y');
- else UI_make_axis_color(col, col2, 'X');
- glColor3ubv(col2);
-
- fdrawline(0.0, y, (float)ar->winx, y);
-
- /* vertical line */
- if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM))
- UI_make_axis_color(col, col2, 'Y');
- else UI_make_axis_color(col, col2, 'Z');
- glColor3ubv(col2);
+ rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / (float)ar->winx;
+ rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / (float)ar->winy;
+ }
+ else {
+ rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f;
+ rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f;
+ }
- fdrawline(x, 0.0, x, (float)ar->winy);
+ /* calculate pixelsize factor once, is used for lamps and obcenters */
+ {
+ /* note: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])'
+ * because of float point precision problems at large values [#23908] */
+ float v1[3], v2[3];
+ float len_px, len_sc;
- glDepthMask(GL_TRUE); /* enable write in zbuffer */
-}
-#undef GRID_MIN_PX
+ v1[0] = rv3d->persmat[0][0];
+ v1[1] = rv3d->persmat[1][0];
+ v1[2] = rv3d->persmat[2][0];
-/** could move this elsewhere, but tied into #ED_view3d_grid_scale */
-float ED_scene_grid_scale(Scene *scene, const char **grid_unit)
-{
- /* apply units */
- if (scene->unit.system) {
- const void *usys;
- int len;
+ v2[0] = rv3d->persmat[0][1];
+ v2[1] = rv3d->persmat[1][1];
+ v2[2] = rv3d->persmat[2][1];
- bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
+ len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
+ len_sc = (float)MAX2(ar->winx, ar->winy);
- if (usys) {
- int i = bUnit_GetBaseUnit(usys);
- if (grid_unit)
- *grid_unit = bUnit_GetNameDisplay(usys, i);
- return (float)bUnit_GetScaler(usys, i) / scene->unit.scale_length;
- }
+ rv3d->pixsize = len_px / len_sc;
}
-
- return 1.0f;
-}
-
-float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit)
-{
- return v3d->grid * ED_scene_grid_scale(scene, grid_unit);
}
-static void drawfloor(Scene *scene, View3D *v3d, const char **grid_unit, bool write_depth)
+static void view3d_main_region_setup_view(
+ Depsgraph *depsgraph, Scene *scene,
+ View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect)
{
- float grid, grid_scale;
- unsigned char col_grid[3];
- const int gridlines = v3d->gridlines / 2;
-
- if (v3d->gridlines < 3) return;
-
- /* use 'grid_scale' instead of 'v3d->grid' from now on */
- grid_scale = ED_view3d_grid_scale(scene, v3d, grid_unit);
- grid = gridlines * grid_scale;
-
- if (!write_depth)
- glDepthMask(GL_FALSE);
-
- UI_GetThemeColor3ubv(TH_GRID, col_grid);
-
- glLineWidth(1);
-
- /* draw the Y axis and/or grid lines */
- if (v3d->gridflag & V3D_SHOW_FLOOR) {
- const int sublines = v3d->gridsubdiv;
- float vert[4][3] = {{0.0f}};
- unsigned char col_bg[3];
- unsigned char col_grid_emphasise[3], col_grid_light[3];
- int a;
- int prev_emphasise = -1;
-
- UI_GetThemeColor3ubv(TH_BACK, col_bg);
-
- /* emphasise division lines lighter instead of darker, if background is darker than grid */
- UI_GetColorPtrShade3ubv(col_grid, col_grid_light, 10);
- UI_GetColorPtrShade3ubv(col_grid, col_grid_emphasise,
- (((col_grid[0] + col_grid[1] + col_grid[2]) + 30) >
- (col_bg[0] + col_bg[1] + col_bg[2])) ? 20 : -10);
-
- /* set fixed axis */
- vert[0][0] = vert[2][1] = grid;
- vert[1][0] = vert[3][1] = -grid;
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, 0, vert);
-
- for (a = -gridlines; a <= gridlines; a++) {
- const float line = a * grid_scale;
- const int is_emphasise = (a % sublines) == 0;
-
- if (is_emphasise != prev_emphasise) {
- glColor3ubv(is_emphasise ? col_grid_emphasise : col_grid_light);
- prev_emphasise = is_emphasise;
- }
-
- /* set variable axis */
- vert[0][1] = vert[1][1] = vert[2][0] = vert[3][0] = line;
+ RegionView3D *rv3d = ar->regiondata;
- glDrawArrays(GL_LINES, 0, 4);
- }
+ ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, viewmat, winmat, rect);
- glDisableClientState(GL_VERTEX_ARRAY);
- }
-
- /* draw the Z axis line */
- /* check for the 'show Z axis' preference */
- if (v3d->gridflag & (V3D_SHOW_X | V3D_SHOW_Y | V3D_SHOW_Z)) {
- glBegin(GL_LINES);
- int axis;
- for (axis = 0; axis < 3; axis++) {
- if (v3d->gridflag & (V3D_SHOW_X << axis)) {
- float vert[3];
- unsigned char tcol[3];
-
- UI_make_axis_color(col_grid, tcol, 'X' + axis);
- glColor3ubv(tcol);
-
- zero_v3(vert);
- vert[axis] = grid;
- glVertex3fv(vert);
- vert[axis] = -grid;
- glVertex3fv(vert);
- }
- }
- glEnd();
- }
-
- glDepthMask(GL_TRUE);
+ /* set for opengl */
+ gpuLoadProjectionMatrix(rv3d->winmat);
+ gpuLoadMatrix(rv3d->viewmat);
}
-
-static void drawcursor(Scene *scene, ARegion *ar, View3D *v3d)
+static bool view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d)
{
- int co[2];
-
- /* we don't want the clipping for cursor */
- if (ED_view3d_project_int_global(ar, ED_view3d_cursor3d_get(scene, v3d), co, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
- const float f5 = 0.25f * U.widget_unit;
- const float f10 = 0.5f * U.widget_unit;
- const float f20 = U.widget_unit;
-
- glLineWidth(1);
- setlinestyle(0);
- cpack(0xFF);
- circ((float)co[0], (float)co[1], f10);
- setlinestyle(4);
- cpack(0xFFFFFF);
- circ((float)co[0], (float)co[1], f10);
- setlinestyle(0);
-
- UI_ThemeColor(TH_VIEW_OVERLAY);
- sdrawline(co[0] - f20, co[1], co[0] - f5, co[1]);
- sdrawline(co[0] + f5, co[1], co[0] + f20, co[1]);
- sdrawline(co[0], co[1] - f20, co[0], co[1] - f5);
- sdrawline(co[0], co[1] + f5, co[0], co[1] + f20);
+ if ((scene->r.scemode & R_MULTIVIEW) == 0) {
+ return false;
}
-}
-
-/* Draw a live substitute of the view icon, which is always shown
- * colors copied from transform_manipulator.c, we should keep these matching. */
-static void draw_view_axis(RegionView3D *rv3d, rcti *rect)
-{
- const float k = U.rvisize * U.pixelsize; /* axis size */
- const float toll = 0.5; /* used to see when view is quasi-orthogonal */
- float startx = k + 1.0f; /* axis center in screen coordinates, x=y */
- float starty = k + 1.0f;
- float ydisp = 0.0; /* vertical displacement to allow obj info text */
- int bright = - 20 * (10 - U.rvibright); /* axis alpha offset (rvibright has range 0-10) */
- float vec[3];
- float dx, dy;
-
- int axis_order[3] = {0, 1, 2};
- int axis_i;
-
- startx += rect->xmin;
- starty += rect->ymin;
-
- axis_sort_v3(rv3d->viewinv[2], axis_order);
-
- /* thickness of lines is proportional to k */
- glLineWidth(2);
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- for (axis_i = 0; axis_i < 3; axis_i++) {
- int i = axis_order[axis_i];
- const char axis_text[2] = {'x' + i, '\0'};
- zero_v3(vec);
- vec[i] = 1.0f;
- mul_qt_v3(rv3d->viewquat, vec);
- dx = vec[0] * k;
- dy = vec[1] * k;
-
- UI_ThemeColorShadeAlpha(TH_AXIS_X + i, 0, bright);
- glBegin(GL_LINES);
- glVertex2f(startx, starty + ydisp);
- glVertex2f(startx + dx, starty + dy + ydisp);
- glEnd();
-
- if (fabsf(dx) > toll || fabsf(dy) > toll) {
- BLF_draw_default_ascii(startx + dx + 2, starty + dy + ydisp + 2, 0.0f, axis_text, 1);
-
- /* BLF_draw_default disables blending */
- glEnable(GL_BLEND);
- }
+ if ((v3d->camera == NULL) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB) {
+ return false;
}
- glDisable(GL_BLEND);
-}
-
-#ifdef WITH_INPUT_NDOF
-/* draw center and axis of rotation for ongoing 3D mouse navigation */
-static void draw_rotation_guide(RegionView3D *rv3d)
-{
- float o[3]; /* center of rotation */
- float end[3]; /* endpoints for drawing */
-
- float color[4] = {0.0f, 0.4235f, 1.0f, 1.0f}; /* bright blue so it matches device LEDs */
-
- negate_v3_v3(o, rv3d->ofs);
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glPointSize(5);
- glEnable(GL_POINT_SMOOTH);
- glDepthMask(0); /* don't overwrite zbuf */
-
- if (rv3d->rot_angle != 0.0f) {
- /* -- draw rotation axis -- */
- float scaled_axis[3];
- const float scale = rv3d->dist;
- mul_v3_v3fl(scaled_axis, rv3d->rot_axis, scale);
-
-
- glBegin(GL_LINE_STRIP);
- color[3] = 0.0f; /* more transparent toward the ends */
- glColor4fv(color);
- add_v3_v3v3(end, o, scaled_axis);
- glVertex3fv(end);
-
-#if 0
- color[3] = 0.2f + fabsf(rv3d->rot_angle); /* modulate opacity with angle */
- /* ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 */
-#endif
-
- color[3] = 0.5f; /* more opaque toward the center */
- glColor4fv(color);
- glVertex3fv(o);
-
- color[3] = 0.0f;
- glColor4fv(color);
- sub_v3_v3v3(end, o, scaled_axis);
- glVertex3fv(end);
- glEnd();
-
- /* -- draw ring around rotation center -- */
- {
-#define ROT_AXIS_DETAIL 13
-
- const float s = 0.05f * scale;
- const float step = 2.0f * (float)(M_PI / ROT_AXIS_DETAIL);
- float angle;
- int i;
-
- float q[4]; /* rotate ring so it's perpendicular to axis */
- const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f;
- if (!upright) {
- const float up[3] = {0.0f, 0.0f, 1.0f};
- float vis_angle, vis_axis[3];
-
- cross_v3_v3v3(vis_axis, up, rv3d->rot_axis);
- vis_angle = acosf(dot_v3v3(up, rv3d->rot_axis));
- axis_angle_to_quat(q, vis_axis, vis_angle);
+ switch (v3d->stereo3d_camera) {
+ case STEREO_MONO_ID:
+ return false;
+ break;
+ case STEREO_3D_ID:
+ /* win will be NULL when calling this from the selection or draw loop. */
+ if ((win == NULL) || (WM_stereo3d_enabled(win, true) == false)) {
+ return false;
}
-
- color[3] = 0.25f; /* somewhat faint */
- glColor4fv(color);
- glBegin(GL_LINE_LOOP);
- for (i = 0, angle = 0.0f; i < ROT_AXIS_DETAIL; ++i, angle += step) {
- float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f};
-
- if (!upright) {
- mul_qt_v3(q, p);
- }
-
- add_v3_v3(p, o);
- glVertex3fv(p);
+ if (((scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) != 0) &&
+ !BKE_scene_multiview_is_stereo3d(&scene->r))
+ {
+ return false;
}
- glEnd();
-
-#undef ROT_AXIS_DETAIL
- }
-
- color[3] = 1.0f; /* solid dot */
- }
- else
- color[3] = 0.5f; /* see-through dot */
-
- /* -- draw rotation center -- */
- glColor4fv(color);
- glBegin(GL_POINTS);
- glVertex3fv(o);
- glEnd();
-
-#if 0
- /* find screen coordinates for rotation center, then draw pretty icon */
- mul_m4_v3(rv3d->persinv, rot_center);
- UI_icon_draw(rot_center[0], rot_center[1], ICON_NDOF_TURN);
- /* ^^ just playing around, does not work */
-#endif
-
- glDisable(GL_BLEND);
- glDisable(GL_POINT_SMOOTH);
- glDepthMask(1);
-}
-#endif /* WITH_INPUT_NDOF */
-
-static void draw_view_icon(RegionView3D *rv3d, rcti *rect)
-{
- BIFIconID icon;
-
- if (ELEM(rv3d->view, RV3D_VIEW_TOP, RV3D_VIEW_BOTTOM))
- icon = ICON_AXIS_TOP;
- else if (ELEM(rv3d->view, RV3D_VIEW_FRONT, RV3D_VIEW_BACK))
- icon = ICON_AXIS_FRONT;
- else if (ELEM(rv3d->view, RV3D_VIEW_RIGHT, RV3D_VIEW_LEFT))
- icon = ICON_AXIS_SIDE;
- else return;
-
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- UI_icon_draw(5.0 + rect->xmin, 5.0 + rect->ymin, icon);
-
- glDisable(GL_BLEND);
-}
-
-static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
-{
- const char *name = NULL;
-
- switch (rv3d->view) {
- case RV3D_VIEW_FRONT:
- if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Front Ortho");
- else name = IFACE_("Front Persp");
- break;
- case RV3D_VIEW_BACK:
- if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Back Ortho");
- else name = IFACE_("Back Persp");
- break;
- case RV3D_VIEW_TOP:
- if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Top Ortho");
- else name = IFACE_("Top Persp");
- break;
- case RV3D_VIEW_BOTTOM:
- if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Bottom Ortho");
- else name = IFACE_("Bottom Persp");
- break;
- case RV3D_VIEW_RIGHT:
- if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Right Ortho");
- else name = IFACE_("Right Persp");
break;
- case RV3D_VIEW_LEFT:
- if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Left Ortho");
- else name = IFACE_("Left Persp");
- break;
-
+ /* We always need the stereo calculation for left and right cameras. */
+ case STEREO_LEFT_ID:
+ case STEREO_RIGHT_ID:
default:
- if (rv3d->persp == RV3D_CAMOB) {
- if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
- Camera *cam;
- cam = v3d->camera->data;
- if (cam->type == CAM_PERSP) {
- name = IFACE_("Camera Persp");
- }
- else if (cam->type == CAM_ORTHO) {
- name = IFACE_("Camera Ortho");
- }
- else {
- BLI_assert(cam->type == CAM_PANO);
- name = IFACE_("Camera Pano");
- }
- }
- else {
- name = IFACE_("Object as Camera");
- }
- }
- else {
- name = (rv3d->persp == RV3D_ORTHO) ? IFACE_("User Ortho") : IFACE_("User Persp");
- }
break;
}
-
- return name;
+ return true;
}
-static void draw_viewport_name(ARegion *ar, View3D *v3d, rcti *rect)
-{
- RegionView3D *rv3d = ar->regiondata;
- const char *name = view3d_get_name(v3d, rv3d);
- /* increase size for unicode languages (Chinese in utf-8...) */
-#ifdef WITH_INTERNATIONAL
- char tmpstr[96];
-#else
- char tmpstr[32];
-#endif
- if (v3d->localvd) {
- BLI_snprintf(tmpstr, sizeof(tmpstr), IFACE_("%s (Local)"), name);
- name = tmpstr;
- }
+/* setup the view and win matrices for the multiview cameras
+ *
+ * unlike view3d_stereo3d_setup_offscreen, when view3d_stereo3d_setup is called
+ * we have no winmatrix (i.e., projection matrix) defined at that time.
+ * Since the camera and the camera shift are needed for the winmat calculation
+ * we do a small hack to replace it temporarily so we don't need to change the
+ * view3d)main_region_setup_view() code to account for that.
+ */
+static void view3d_stereo3d_setup(
+ Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect)
+{
+ bool is_left;
+ const char *names[2] = { STEREO_LEFT_NAME, STEREO_RIGHT_NAME };
+ const char *viewname;
- UI_ThemeColor(TH_TEXT_HI);
-#ifdef WITH_INTERNATIONAL
- BLF_draw_default(U.widget_unit + rect->xmin, rect->ymax - U.widget_unit, 0.0f, name, sizeof(tmpstr));
-#else
- BLF_draw_default_ascii(U.widget_unit + rect->xmin, rect->ymax - U.widget_unit, 0.0f, name, sizeof(tmpstr));
-#endif
-}
+ /* show only left or right camera */
+ if (v3d->stereo3d_camera != STEREO_3D_ID)
+ v3d->multiview_eye = v3d->stereo3d_camera;
-/* draw info beside axes in bottom left-corner:
- * framenum, object name, bone name (if available), marker name (if available)
- */
+ is_left = v3d->multiview_eye == STEREO_LEFT_ID;
+ viewname = names[is_left ? STEREO_LEFT_ID : STEREO_RIGHT_ID];
-static void draw_selected_name(Scene *scene, Object *ob, const rcti *rect)
-{
- const int cfra = CFRA;
- const char *msg_pin = " (Pinned)";
- const char *msg_sep = " : ";
+ /* update the viewport matrices with the new camera */
+ if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
+ Camera *data;
+ float viewmat[4][4];
+ float shiftx;
- char info[300];
- const char *markern;
- char *s = info;
- short offset = 1.5f * UI_UNIT_X + rect->xmin;
+ data = (Camera *)v3d->camera->data;
+ shiftx = data->shiftx;
- s += sprintf(s, "(%d)", cfra);
+ BLI_thread_lock(LOCK_VIEW3D);
+ data->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname);
- /*
- * info can contain:
- * - a frame (7 + 2)
- * - 3 object names (MAX_NAME)
- * - 2 BREAD_CRUMB_SEPARATORs (6)
- * - a SHAPE_KEY_PINNED marker and a trailing '\0' (9+1) - translated, so give some room!
- * - a marker name (MAX_NAME + 3)
- */
+ BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
+ view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, NULL, rect);
- /* get name of marker on current frame (if available) */
- markern = BKE_scene_find_marker_name(scene, cfra);
-
- /* check if there is an object */
- if (ob) {
- *s++ = ' ';
- s += BLI_strcpy_rlen(s, ob->id.name + 2);
+ data->shiftx = shiftx;
+ BLI_thread_unlock(LOCK_VIEW3D);
+ }
+ else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
+ float viewmat[4][4];
+ Object *view_ob = v3d->camera;
+ Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
- /* name(s) to display depends on type of object */
- if (ob->type == OB_ARMATURE) {
- bArmature *arm = ob->data;
-
- /* show name of active bone too (if possible) */
- if (arm->edbo) {
- if (arm->act_edbone) {
- s += BLI_strcpy_rlen(s, msg_sep);
- s += BLI_strcpy_rlen(s, arm->act_edbone->name);
- }
- }
- else if (ob->mode & OB_MODE_POSE) {
- if (arm->act_bone) {
+ BLI_thread_lock(LOCK_VIEW3D);
+ v3d->camera = camera;
- if (arm->act_bone->layer & arm->layer) {
- s += BLI_strcpy_rlen(s, msg_sep);
- s += BLI_strcpy_rlen(s, arm->act_bone->name);
- }
- }
- }
- }
- else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
- Key *key = NULL;
- KeyBlock *kb = NULL;
+ BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
+ view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, NULL, rect);
- /* try to display active bone and active shapekey too (if they exist) */
+ v3d->camera = view_ob;
+ BLI_thread_unlock(LOCK_VIEW3D);
+ }
+}
- if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
- Object *armobj = BKE_object_pose_armature_get(ob);
- if (armobj && armobj->mode & OB_MODE_POSE) {
- bArmature *arm = armobj->data;
- if (arm->act_bone) {
- if (arm->act_bone->layer & arm->layer) {
- s += BLI_strcpy_rlen(s, msg_sep);
- s += BLI_strcpy_rlen(s, arm->act_bone->name);
- }
- }
- }
- }
+/**
+ * Set the correct matrices
+ */
+void ED_view3d_draw_setup_view(
+ wmWindow *win, Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d,
+ float viewmat[4][4], float winmat[4][4], const rcti *rect)
+{
+ RegionView3D *rv3d = ar->regiondata;
- key = BKE_key_from_object(ob);
- if (key) {
- kb = BLI_findlink(&key->block, ob->shapenr - 1);
- if (kb) {
- s += BLI_strcpy_rlen(s, msg_sep);
- s += BLI_strcpy_rlen(s, kb->name);
- if (ob->shapeflag & OB_SHAPE_LOCK) {
- s += BLI_strcpy_rlen(s, IFACE_(msg_pin));
- }
- }
- }
- }
-
- /* color depends on whether there is a keyframe */
- if (id_frame_has_keyframe((ID *)ob, /* BKE_scene_frame_get(scene) */ (float)cfra, ANIMFILTER_KEYS_LOCAL))
- UI_ThemeColor(TH_TIME_KEYFRAME);
- else if (ED_gpencil_has_keyframe_v3d(scene, ob, cfra))
- UI_ThemeColor(TH_TIME_GP_KEYFRAME);
- else
- UI_ThemeColor(TH_TEXT_HI);
+ /* Setup the view matrix. */
+ if (view3d_stereo3d_active(win, scene, v3d, rv3d)) {
+ view3d_stereo3d_setup(depsgraph, scene, v3d, ar, rect);
}
else {
- /* no object */
- if (ED_gpencil_has_keyframe_v3d(scene, NULL, cfra))
- UI_ThemeColor(TH_TIME_GP_KEYFRAME);
- else
- UI_ThemeColor(TH_TEXT_HI);
- }
-
- if (markern) {
- s += sprintf(s, " <%s>", markern);
+ view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, rect);
}
-
- if (U.uiflag & USER_SHOW_ROTVIEWICON)
- offset = U.widget_unit + (U.rvisize * 2) + rect->xmin;
-
- BLF_draw_default(offset, 0.5f * U.widget_unit, 0.0f, info, sizeof(info));
}
+/* ******************** view border ***************** */
+
static void view3d_camera_border(
- const Scene *scene, const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
+ const Scene *scene, struct Depsgraph *depsgraph,
+ const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
rctf *r_viewborder, const bool no_shift, const bool no_zoom)
{
CameraParams params;
@@ -979,7 +305,7 @@ static void view3d_camera_border(
/* get viewport viewplane */
BKE_camera_params_init(&params);
- BKE_camera_params_from_view3d(&params, v3d, rv3d);
+ BKE_camera_params_from_view3d(&params, depsgraph, v3d, rv3d);
if (no_zoom)
params.zoom = 1.0f;
BKE_camera_params_compute_viewplane(&params, ar->winx, ar->winy, 1.0f, 1.0f);
@@ -1006,24 +332,26 @@ static void view3d_camera_border(
}
void ED_view3d_calc_camera_border_size(
- const Scene *scene, const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
+ const Scene *scene, Depsgraph *depsgraph,
+ const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
float r_size[2])
{
rctf viewborder;
- view3d_camera_border(scene, ar, v3d, rv3d, &viewborder, true, true);
+ view3d_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, true, true);
r_size[0] = BLI_rctf_size_x(&viewborder);
r_size[1] = BLI_rctf_size_y(&viewborder);
}
void ED_view3d_calc_camera_border(
- const Scene *scene, const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
+ const Scene *scene, Depsgraph *depsgraph,
+ const ARegion *ar, const View3D *v3d, const RegionView3D *rv3d,
rctf *r_viewborder, const bool no_shift)
{
- view3d_camera_border(scene, ar, v3d, rv3d, r_viewborder, no_shift, false);
+ view3d_camera_border(scene, depsgraph, ar, v3d, rv3d, r_viewborder, no_shift, false);
}
-static void drawviewborder_grid3(float x1, float x2, float y1, float y2, float fac)
+static void drawviewborder_grid3(uint shdr_pos, float x1, float x2, float y1, float y2, float fac)
{
float x3, y3, x4, y4;
@@ -1032,29 +360,33 @@ static void drawviewborder_grid3(float x1, float x2, float y1, float y2, float f
x4 = x1 + (1.0f - fac) * (x2 - x1);
y4 = y1 + (1.0f - fac) * (y2 - y1);
- glBegin(GL_LINES);
- glVertex2f(x1, y3);
- glVertex2f(x2, y3);
+ immBegin(GWN_PRIM_LINES, 8);
+
+ immVertex2f(shdr_pos, x1, y3);
+ immVertex2f(shdr_pos, x2, y3);
- glVertex2f(x1, y4);
- glVertex2f(x2, y4);
+ immVertex2f(shdr_pos, x1, y4);
+ immVertex2f(shdr_pos, x2, y4);
- glVertex2f(x3, y1);
- glVertex2f(x3, y2);
+ immVertex2f(shdr_pos, x3, y1);
+ immVertex2f(shdr_pos, x3, y2);
- glVertex2f(x4, y1);
- glVertex2f(x4, y2);
- glEnd();
+ immVertex2f(shdr_pos, x4, y1);
+ immVertex2f(shdr_pos, x4, y2);
+
+ immEnd();
}
/* harmonious triangle */
-static void drawviewborder_triangle(float x1, float x2, float y1, float y2, const char golden, const char dir)
+static void drawviewborder_triangle(
+ uint shdr_pos, float x1, float x2, float y1, float y2, const char golden, const char dir)
{
float ofs;
float w = x2 - x1;
float h = y2 - y1;
- glBegin(GL_LINES);
+ immBegin(GWN_PRIM_LINES, 6);
+
if (w > h) {
if (golden) {
ofs = w * (1.0f - (1.0f / 1.61803399f));
@@ -1064,14 +396,14 @@ static void drawviewborder_triangle(float x1, float x2, float y1, float y2, cons
}
if (dir == 'B') SWAP(float, y1, y2);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
+ immVertex2f(shdr_pos, x1, y1);
+ immVertex2f(shdr_pos, x2, y2);
- glVertex2f(x2, y1);
- glVertex2f(x1 + (w - ofs), y2);
+ immVertex2f(shdr_pos, x2, y1);
+ immVertex2f(shdr_pos, x1 + (w - ofs), y2);
- glVertex2f(x1, y2);
- glVertex2f(x1 + ofs, y1);
+ immVertex2f(shdr_pos, x1, y2);
+ immVertex2f(shdr_pos, x1 + ofs, y1);
}
else {
if (golden) {
@@ -1082,19 +414,20 @@ static void drawviewborder_triangle(float x1, float x2, float y1, float y2, cons
}
if (dir == 'B') SWAP(float, x1, x2);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
+ immVertex2f(shdr_pos, x1, y1);
+ immVertex2f(shdr_pos, x2, y2);
- glVertex2f(x2, y1);
- glVertex2f(x1, y1 + ofs);
+ immVertex2f(shdr_pos, x2, y1);
+ immVertex2f(shdr_pos, x1, y1 + ofs);
- glVertex2f(x1, y2);
- glVertex2f(x2, y1 + (h - ofs));
+ immVertex2f(shdr_pos, x1, y2);
+ immVertex2f(shdr_pos, x2, y1 + (h - ofs));
}
- glEnd();
+
+ immEnd();
}
-static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
+static void drawviewborder(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d)
{
float x1, x2, y1, y2;
float x1i, x2i, y1i, y2i;
@@ -1108,7 +441,7 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
if (v3d->camera->type == OB_CAMERA)
ca = v3d->camera->data;
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, false);
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, false);
/* the offsets */
x1 = viewborder.xmin;
y1 = viewborder.ymin;
@@ -1128,58 +461,76 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
y1i = (int)(y1 - 1.0001f);
x2i = (int)(x2 + (1.0f - 0.0001f));
y2i = (int)(y2 + (1.0f - 0.0001f));
-
- /* passepartout, specified in camera edit buttons */
- if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001f) {
- const float winx = (ar->winx + 1);
- const float winy = (ar->winy + 1);
- if (ca->passepartalpha == 1.0f) {
- glColor3f(0, 0, 0);
+ uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ /* First, solid lines. */
+ {
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* passepartout, specified in camera edit buttons */
+ if (ca && (ca->flag & CAM_SHOWPASSEPARTOUT) && ca->passepartalpha > 0.000001f) {
+ const float winx = (ar->winx + 1);
+ const float winy = (ar->winy + 1);
+
+ float alpha = 1.0f;
+
+ if (ca->passepartalpha != 1.0f) {
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+ alpha = ca->passepartalpha;
+ }
+
+ immUniformColor4f(0.0f, 0.0f, 0.0f, alpha);
+
+ if (x1i > 0.0f)
+ immRectf(shdr_pos, 0.0f, winy, x1i, 0.0f);
+ if (x2i < winx)
+ immRectf(shdr_pos, x2i, winy, winx, 0.0f);
+ if (y2i < winy)
+ immRectf(shdr_pos, x1i, winy, x2i, y2i);
+ if (y2i > 0.0f)
+ immRectf(shdr_pos, x1i, y1i, x2i, 0.0f);
+
+ glDisable(GL_BLEND);
}
- else {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glColor4f(0, 0, 0, ca->passepartalpha);
+
+ immUniformThemeColor(TH_BACK);
+ imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
+
+#ifdef VIEW3D_CAMERA_BORDER_HACK
+ if (view3d_camera_border_hack_test == true) {
+ immUniformColor3ubv(view3d_camera_border_hack_col);
+ imm_draw_box_wire_2d(shdr_pos, x1i + 1, y1i + 1, x2i - 1, y2i - 1);
+ view3d_camera_border_hack_test = false;
}
+#endif
- if (x1i > 0.0f)
- glRectf(0.0, winy, x1i, 0.0);
- if (x2i < winx)
- glRectf(x2i, winy, winx, 0.0);
- if (y2i < winy)
- glRectf(x1i, winy, x2i, y2i);
- if (y2i > 0.0f)
- glRectf(x1i, y1i, x2i, 0.0);
-
- glDisable(GL_BLEND);
+ immUnbindProgram();
}
- setlinestyle(0);
+ /* And now, the dashed lines! */
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- UI_ThemeColor(TH_BACK);
-
- fdrawbox(x1i, y1i, x2i, y2i);
+ {
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
-#ifdef VIEW3D_CAMERA_BORDER_HACK
- if (view3d_camera_border_hack_test == true) {
- glColor3ubv(view3d_camera_border_hack_col);
- fdrawbox(x1i + 1, y1i + 1, x2i - 1, y2i - 1);
- view3d_camera_border_hack_test = false;
- }
-#endif
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
- setlinestyle(3);
+ /* outer line not to confuse with object selection */
+ if (v3d->flag2 & V3D_LOCK_CAMERA) {
+ immUniformThemeColor(TH_REDALERT);
+ imm_draw_box_wire_2d(shdr_pos, x1i - 1, y1i - 1, x2i + 1, y2i + 1);
+ }
- /* outer line not to confuse with object selecton */
- if (v3d->flag2 & V3D_LOCK_CAMERA) {
- UI_ThemeColor(TH_REDALERT);
- fdrawbox(x1i - 1, y1i - 1, x2i + 1, y2i + 1);
+ immUniformThemeColor(TH_VIEW_OVERLAY);
+ imm_draw_box_wire_2d(shdr_pos, x1i, y1i, x2i, y2i);
}
- UI_ThemeColor(TH_VIEW_OVERLAY);
- fdrawbox(x1i, y1i, x2i, y2i);
-
/* border */
if (scene->r.mode & R_BORDER) {
float x3, y3, x4, y4;
@@ -1189,82 +540,76 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
x4 = floorf(x1 + (scene->r.border.xmax * (x2 - x1))) + (U.pixelsize - 1);
y4 = floorf(y1 + (scene->r.border.ymax * (y2 - y1))) + (U.pixelsize - 1);
- cpack(0x4040FF);
- sdrawbox(x3, y3, x4, y4);
+ immUniformColor3f(1.0f, 0.25f, 0.25f);
+ imm_draw_box_wire_2d(shdr_pos, x3, y3, x4, y4);
}
/* safety border */
if (ca) {
+ immUniformThemeColorBlend(TH_VIEW_OVERLAY, TH_BACK, 0.25f);
+
if (ca->dtx & CAM_DTX_CENTER) {
float x3, y3;
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
-
x3 = x1 + 0.5f * (x2 - x1);
y3 = y1 + 0.5f * (y2 - y1);
- glBegin(GL_LINES);
- glVertex2f(x1, y3);
- glVertex2f(x2, y3);
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(shdr_pos, x1, y3);
+ immVertex2f(shdr_pos, x2, y3);
- glVertex2f(x3, y1);
- glVertex2f(x3, y2);
- glEnd();
+ immVertex2f(shdr_pos, x3, y1);
+ immVertex2f(shdr_pos, x3, y2);
+
+ immEnd();
}
if (ca->dtx & CAM_DTX_CENTER_DIAG) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
+ immBegin(GWN_PRIM_LINES, 4);
+
+ immVertex2f(shdr_pos, x1, y1);
+ immVertex2f(shdr_pos, x2, y2);
- glBegin(GL_LINES);
- glVertex2f(x1, y1);
- glVertex2f(x2, y2);
+ immVertex2f(shdr_pos, x1, y2);
+ immVertex2f(shdr_pos, x2, y1);
- glVertex2f(x1, y2);
- glVertex2f(x2, y1);
- glEnd();
+ immEnd();
}
if (ca->dtx & CAM_DTX_THIRDS) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
- drawviewborder_grid3(x1, x2, y1, y2, 1.0f / 3.0f);
+ drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f / 3.0f);
}
if (ca->dtx & CAM_DTX_GOLDEN) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
- drawviewborder_grid3(x1, x2, y1, y2, 1.0f - (1.0f / 1.61803399f));
+ drawviewborder_grid3(shdr_pos, x1, x2, y1, y2, 1.0f - (1.0f / 1.61803399f));
}
if (ca->dtx & CAM_DTX_GOLDEN_TRI_A) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
- drawviewborder_triangle(x1, x2, y1, y2, 0, 'A');
+ drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'A');
}
if (ca->dtx & CAM_DTX_GOLDEN_TRI_B) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
- drawviewborder_triangle(x1, x2, y1, y2, 0, 'B');
+ drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 0, 'B');
}
if (ca->dtx & CAM_DTX_HARMONY_TRI_A) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
- drawviewborder_triangle(x1, x2, y1, y2, 1, 'A');
+ drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'A');
}
if (ca->dtx & CAM_DTX_HARMONY_TRI_B) {
- UI_ThemeColorBlendShade(TH_VIEW_OVERLAY, TH_BACK, 0.25, 0);
- drawviewborder_triangle(x1, x2, y1, y2, 1, 'B');
+ drawviewborder_triangle(shdr_pos, x1, x2, y1, y2, 1, 'B');
}
if (ca->flag & CAM_SHOW_SAFE_MARGINS) {
UI_draw_safe_areas(
- x1, x2, y1, y2,
- scene->safe_areas.title,
- scene->safe_areas.action);
+ shdr_pos, x1, x2, y1, y2,
+ scene->safe_areas.title, scene->safe_areas.action);
if (ca->flag & CAM_SHOW_SAFE_CENTER) {
UI_draw_safe_areas(
- x1, x2, y1, y2,
- scene->safe_areas.title_center,
- scene->safe_areas.action_center);
+ shdr_pos, x1, x2, y1, y2,
+ scene->safe_areas.title_center, scene->safe_areas.action_center);
}
}
@@ -1300,1891 +645,679 @@ static void drawviewborder(Scene *scene, ARegion *ar, View3D *v3d)
}
/* draw */
- UI_ThemeColorShade(TH_VIEW_OVERLAY, 100);
- UI_draw_roundbox_gl_mode(GL_LINE_LOOP, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f);
+ immUniformThemeColorShade(TH_VIEW_OVERLAY, 100);
+
+ /* TODO Was using UI_draw_roundbox_4fv(false, rect.xmin, rect.ymin, rect.xmax, rect.ymax, 2.0f, color).
+ * We'll probably need a new imm_draw_line_roundbox_dashed dor that - though in practice the
+ * 2.0f round corner effect was nearly not visible anyway... */
+ imm_draw_box_wire_2d(shdr_pos, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
}
}
- setlinestyle(0);
+ immUnbindProgram();
+ /* end dashed lines */
/* camera name - draw in highlighted text color */
if (ca && (ca->flag & CAM_SHOWNAME)) {
- UI_ThemeColor(TH_TEXT_HI);
+ UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
BLF_draw_default(
x1i, y1i - (0.7f * U.widget_unit), 0.0f,
v3d->camera->id.name + 2, sizeof(v3d->camera->id.name) - 2);
}
}
-/* *********************** backdraw for selection *************** */
-
-static void backdrawview3d(Scene *scene, wmWindow *win, ARegion *ar, View3D *v3d, Object *obact, Object *obedit)
+static void drawrenderborder(ARegion *ar, View3D *v3d)
{
- RegionView3D *rv3d = ar->regiondata;
- int multisample_enabled;
+ /* use the same program for everything */
+ uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- BLI_assert(ar->regiontype == RGN_TYPE_WINDOW);
-
- if (obact && (obact->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) ||
- BKE_paint_select_face_test(obact)))
- {
- /* do nothing */
- }
- /* texture paint mode sampling */
- else if (obact && (obact->mode & OB_MODE_TEXTURE_PAINT) &&
- (v3d->drawtype > OB_WIRE))
- {
- /* do nothing */
- }
- else if ((obact && (obact->mode & OB_MODE_PARTICLE_EDIT)) &&
- V3D_IS_ZBUF(v3d))
- {
- /* do nothing */
- }
- else if (obedit &&
- V3D_IS_ZBUF(v3d))
- {
- /* do nothing */
- }
- else {
- v3d->flag &= ~V3D_INVALID_BACKBUF;
- return;
- }
-
- if (!(v3d->flag & V3D_INVALID_BACKBUF))
- return;
-
-#if 0
- if (test) {
- if (qtest()) {
- addafterqueue(ar->win, BACKBUFDRAW, 1);
- return;
- }
- }
-#endif
-
- if (v3d->drawtype > OB_WIRE) v3d->zbuf = true;
-
- /* dithering and AA break color coding, so disable */
- glDisable(GL_DITHER);
-
- multisample_enabled = glIsEnabled(GL_MULTISAMPLE);
- if (multisample_enabled)
- glDisable(GL_MULTISAMPLE);
-
- if (win->multisamples != USER_MULTISAMPLE_NONE) {
- /* for multisample we use an offscreen FBO. multisample drawing can fail
- * with color coded selection drawing, and reading back depths from such
- * a buffer can also cause a few seconds freeze on OS X / NVidia. */
- int w = BLI_rcti_size_x(&ar->winrct);
- int h = BLI_rcti_size_y(&ar->winrct);
- char error[256];
-
- if (rv3d->gpuoffscreen) {
- if (GPU_offscreen_width(rv3d->gpuoffscreen) != w ||
- GPU_offscreen_height(rv3d->gpuoffscreen) != h)
- {
- GPU_offscreen_free(rv3d->gpuoffscreen);
- rv3d->gpuoffscreen = NULL;
- }
- }
-
- if (!rv3d->gpuoffscreen) {
- rv3d->gpuoffscreen = GPU_offscreen_create(w, h, 0, error);
-
- if (!rv3d->gpuoffscreen)
- fprintf(stderr, "Failed to create offscreen selection buffer for multisample: %s\n", error);
- }
- }
-
- if (rv3d->gpuoffscreen)
- GPU_offscreen_bind(rv3d->gpuoffscreen, true);
- else
- glScissor(ar->winrct.xmin, ar->winrct.ymin, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct));
-
- glClearColor(0.0, 0.0, 0.0, 0.0);
- if (v3d->zbuf) {
- glEnable(GL_DEPTH_TEST);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
- else {
- glClear(GL_COLOR_BUFFER_BIT);
- glDisable(GL_DEPTH_TEST);
- }
-
- if (rv3d->rflag & RV3D_CLIPPING)
- ED_view3d_clipping_set(rv3d);
-
- G.f |= G_BACKBUFSEL;
+ glLineWidth(1.0f);
- if (obact && (obact->lay & v3d->lay)) {
- draw_object_backbufsel(scene, v3d, rv3d, obact);
- }
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- if (rv3d->gpuoffscreen)
- GPU_offscreen_unbind(rv3d->gpuoffscreen, true);
- else
- ar->swap = 0; /* mark invalid backbuf for wm draw */
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
- v3d->flag &= ~V3D_INVALID_BACKBUF;
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniform4f("color", 1.0f, 0.25f, 0.25f, 1.0f);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
- G.f &= ~G_BACKBUFSEL;
- v3d->zbuf = false;
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_DITHER);
- if (multisample_enabled)
- glEnable(GL_MULTISAMPLE);
+ imm_draw_box_wire_2d(shdr_pos,
+ v3d->render_border.xmin * ar->winx, v3d->render_border.ymin * ar->winy,
+ v3d->render_border.xmax * ar->winx, v3d->render_border.ymax * ar->winy);
- if (rv3d->rflag & RV3D_CLIPPING)
- ED_view3d_clipping_disable();
+ immUnbindProgram();
}
-void view3d_opengl_read_pixels(ARegion *ar, int x, int y, int w, int h, int format, int type, void *data)
+void ED_view3d_draw_depth(
+ Depsgraph *depsgraph,
+ ARegion *ar, View3D *v3d, bool alphaoverride)
{
+ struct bThemeState theme_state;
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
RegionView3D *rv3d = ar->regiondata;
- if (rv3d->gpuoffscreen) {
- GPU_offscreen_bind(rv3d->gpuoffscreen, true);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
- glReadPixels(x, y, w, h, format, type, data);
- GPU_offscreen_unbind(rv3d->gpuoffscreen, true);
- }
- else {
- glReadPixels(ar->winrct.xmin + x, ar->winrct.ymin + y, w, h, format, type, data);
- }
-}
-
-/* XXX depth reading exception, for code not using gpu offscreen */
-static void view3d_opengl_read_Z_pixels(ARegion *ar, int x, int y, int w, int h, int format, int type, void *data)
-{
+ short zbuf = v3d->zbuf;
+ short flag = v3d->flag;
+ float glalphaclip = U.glalphaclip;
+ int obcenter_dia = U.obcenter_dia;
+ /* temp set drawtype to solid */
+ /* Setting these temporarily is not nice */
+ v3d->flag &= ~V3D_SELECT_OUTLINE;
+ U.glalphaclip = alphaoverride ? 0.5f : glalphaclip; /* not that nice but means we wont zoom into billboards */
+ U.obcenter_dia = 0;
- glReadPixels(ar->winrct.xmin + x, ar->winrct.ymin + y, w, h, format, type, data);
-}
+ /* Tools may request depth outside of regular drawing code. */
+ UI_Theme_Store(&theme_state);
+ UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
-void ED_view3d_backbuf_validate(ViewContext *vc)
-{
- if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
- backdrawview3d(vc->scene, vc->win, vc->ar, vc->v3d, vc->obact, vc->obedit);
- }
-}
+ ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL);
-/**
- * allow for small values [0.5 - 2.5],
- * and large values, FLT_MAX by clamping by the area size
- */
-int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist)
-{
- return (int)min_ff(ceilf(dist), (float)max_ii(ar->winx, ar->winx));
-}
+ glClear(GL_DEPTH_BUFFER_BIT);
-/* samples a single pixel (copied from vpaint) */
-unsigned int ED_view3d_backbuf_sample(ViewContext *vc, int x, int y)
-{
- unsigned int col;
-
- if (x >= vc->ar->winx || y >= vc->ar->winy) {
- return 0;
+ if (rv3d->rflag & RV3D_CLIPPING) {
+ ED_view3d_clipping_set(rv3d);
}
+ /* get surface depth without bias */
+ rv3d->rflag |= RV3D_ZOFFSET_DISABLED;
- ED_view3d_backbuf_validate(vc);
+ v3d->zbuf = true;
+ glEnable(GL_DEPTH_TEST);
- view3d_opengl_read_pixels(vc->ar, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
- glReadBuffer(GL_BACK);
-
- if (ENDIAN_ORDER == B_ENDIAN) {
- BLI_endian_switch_uint32(&col);
- }
-
- return GPU_select_to_index(col);
-}
+ DRW_draw_depth_loop(depsgraph, ar, v3d);
-/* reads full rect, converts indices */
-ImBuf *ED_view3d_backbuf_read(ViewContext *vc, int xmin, int ymin, int xmax, int ymax)
-{
- struct ImBuf *ibuf_clip;
- /* clip */
- const rcti clip = {
- max_ii(xmin, 0), min_ii(xmax, vc->ar->winx - 1),
- max_ii(ymin, 0), min_ii(ymax, vc->ar->winy - 1)};
- const int size_clip[2] = {
- BLI_rcti_size_x(&clip) + 1,
- BLI_rcti_size_y(&clip) + 1};
-
- if (UNLIKELY((clip.xmin > clip.xmax) ||
- (clip.ymin > clip.ymax)))
- {
- return NULL;
+ if (rv3d->rflag & RV3D_CLIPPING) {
+ ED_view3d_clipping_disable();
}
+ rv3d->rflag &= ~RV3D_ZOFFSET_DISABLED;
- ibuf_clip = IMB_allocImBuf(size_clip[0], size_clip[1], 32, IB_rect);
-
- ED_view3d_backbuf_validate(vc);
-
- view3d_opengl_read_pixels(vc->ar, clip.xmin, clip.ymin, size_clip[0], size_clip[1], GL_RGBA, GL_UNSIGNED_BYTE, ibuf_clip->rect);
-
- glReadBuffer(GL_BACK);
+ v3d->zbuf = zbuf;
+ if (!v3d->zbuf) glDisable(GL_DEPTH_TEST);
- if (ENDIAN_ORDER == B_ENDIAN) {
- IMB_convert_rgba_to_abgr(ibuf_clip);
- }
+ U.glalphaclip = glalphaclip;
+ v3d->flag = flag;
+ U.obcenter_dia = obcenter_dia;
- GPU_select_to_index_array(ibuf_clip->rect, size_clip[0] * size_clip[1]);
-
- if ((clip.xmin == xmin) &&
- (clip.xmax == xmax) &&
- (clip.ymin == ymin) &&
- (clip.ymax == ymax))
- {
- return ibuf_clip;
- }
- else {
- /* put clipped result into a non-clipped buffer */
- struct ImBuf *ibuf_full;
- const int size[2] = {
- (xmax - xmin + 1),
- (ymax - ymin + 1)};
-
- ibuf_full = IMB_allocImBuf(size[0], size[1], 32, IB_rect);
-
- IMB_rectcpy(
- ibuf_full, ibuf_clip,
- clip.xmin - xmin, clip.ymin - ymin,
- 0, 0,
- size_clip[0], size_clip[1]);
- IMB_freeImBuf(ibuf_clip);
- return ibuf_full;
- }
+ UI_Theme_Restore(&theme_state);
}
-/**
- * Smart function to sample a rectangle spiral ling outside, nice for backbuf selection
- */
-uint ED_view3d_backbuf_sample_rect(
- ViewContext *vc, const int mval[2], int size,
- unsigned int min, unsigned int max, float *r_dist)
-{
- struct ImBuf *buf;
- const unsigned int *bufmin, *bufmax, *tbuf;
- int minx, miny;
- int a, b, rc, nr, amount, dirvec[4][2];
- unsigned int index = 0;
+/* ******************** other elements ***************** */
- amount = (size - 1) / 2;
+/** could move this elsewhere, but tied into #ED_view3d_grid_scale */
+float ED_scene_grid_scale(Scene *scene, const char **grid_unit)
+{
+ /* apply units */
+ if (scene->unit.system) {
+ const void *usys;
+ int len;
- minx = mval[0] - (amount + 1);
- miny = mval[1] - (amount + 1);
- buf = ED_view3d_backbuf_read(vc, minx, miny, minx + size - 1, miny + size - 1);
- if (!buf) return 0;
+ bUnit_GetSystem(scene->unit.system, B_UNIT_LENGTH, &usys, &len);
- rc = 0;
-
- dirvec[0][0] = 1; dirvec[0][1] = 0;
- dirvec[1][0] = 0; dirvec[1][1] = -size;
- dirvec[2][0] = -1; dirvec[2][1] = 0;
- dirvec[3][0] = 0; dirvec[3][1] = size;
-
- bufmin = buf->rect;
- tbuf = buf->rect;
- bufmax = buf->rect + size * size;
- tbuf += amount * size + amount;
-
- for (nr = 1; nr <= size; nr++) {
-
- for (a = 0; a < 2; a++) {
- for (b = 0; b < nr; b++) {
- if (*tbuf && *tbuf >= min && *tbuf < max) {
- /* we got a hit */
-
- /* get x,y pixel coords from the offset
- * (manhatten distance in keeping with other screen-based selection) */
- *r_dist = (float)(
- abs(((int)(tbuf - buf->rect) % size) - (size / 2)) +
- abs(((int)(tbuf - buf->rect) / size) - (size / 2)));
-
- /* indices start at 1 here */
- index = (*tbuf - min) + 1;
- goto exit;
- }
-
- tbuf += (dirvec[rc][0] + dirvec[rc][1]);
-
- if (tbuf < bufmin || tbuf >= bufmax) {
- goto exit;
- }
- }
- rc++;
- rc &= 3;
+ if (usys) {
+ int i = bUnit_GetBaseUnit(usys);
+ if (grid_unit)
+ *grid_unit = bUnit_GetNameDisplay(usys, i);
+ return (float)bUnit_GetScaler(usys, i) / scene->unit.scale_length;
}
}
-exit:
- IMB_freeImBuf(buf);
- return index;
+ return 1.0f;
}
-
-/* ************************************************************* */
-
-static void view3d_stereo_bgpic_setup(Scene *scene, View3D *v3d, Image *ima, ImageUser *iuser)
+float ED_view3d_grid_scale(Scene *scene, View3D *v3d, const char **grid_unit)
{
- if (BKE_image_is_stereo(ima)) {
- iuser->flag |= IMA_SHOW_STEREO;
-
- if ((scene->r.scemode & R_MULTIVIEW) == 0) {
- iuser->multiview_eye = STEREO_LEFT_ID;
- }
- else if (v3d->stereo3d_camera != STEREO_3D_ID) {
- /* show only left or right camera */
- iuser->multiview_eye = v3d->stereo3d_camera;
- }
-
- BKE_image_multiview_index(ima, iuser);
- }
- else {
- iuser->flag &= ~IMA_SHOW_STEREO;
- }
+ return v3d->grid * ED_scene_grid_scale(scene, grid_unit);
}
-static void view3d_draw_bgpic(Scene *scene, ARegion *ar, View3D *v3d,
- const bool do_foreground, const bool do_camera_frame)
+static void draw_view_axis(RegionView3D *rv3d, const rcti *rect)
{
- RegionView3D *rv3d = ar->regiondata;
- BGpic *bgpic;
- int fg_flag = do_foreground ? V3D_BGPIC_FOREGROUND : 0;
-
- for (bgpic = v3d->bgpicbase.first; bgpic; bgpic = bgpic->next) {
- bgpic->iuser.scene = scene; /* Needed for render results. */
+ const float k = U.rvisize * U.pixelsize; /* axis size */
+ const int bright = - 20 * (10 - U.rvibright); /* axis alpha offset (rvibright has range 0-10) */
- if ((bgpic->flag & V3D_BGPIC_FOREGROUND) != fg_flag)
- continue;
-
- if ((bgpic->view == 0) || /* zero for any */
- (bgpic->view & (1 << rv3d->view)) || /* check agaist flags */
- (rv3d->persp == RV3D_CAMOB && bgpic->view == (1 << RV3D_VIEW_CAMERA)))
- {
- float image_aspect[2];
- float fac, asp, zoomx, zoomy;
- float x1, y1, x2, y2, centx, centy;
-
- ImBuf *ibuf = NULL, *freeibuf, *releaseibuf;
- void *lock;
- rctf clip_rect;
-
- Image *ima = NULL;
- MovieClip *clip = NULL;
-
- /* disable individual images */
- if ((bgpic->flag & V3D_BGPIC_DISABLED))
- continue;
-
- freeibuf = NULL;
- releaseibuf = NULL;
- if (bgpic->source == V3D_BGPIC_IMAGE) {
- ima = bgpic->ima;
- if (ima == NULL)
- continue;
- BKE_image_user_frame_calc(&bgpic->iuser, CFRA, 0);
- if (ima->source == IMA_SRC_SEQUENCE && !(bgpic->iuser.flag & IMA_USER_FRAME_IN_RANGE)) {
- ibuf = NULL; /* frame is out of range, dont show */
- }
- else {
- view3d_stereo_bgpic_setup(scene, v3d, ima, &bgpic->iuser);
- ibuf = BKE_image_acquire_ibuf(ima, &bgpic->iuser, &lock);
- releaseibuf = ibuf;
- }
-
- image_aspect[0] = ima->aspx;
- image_aspect[1] = ima->aspy;
- }
- else if (bgpic->source == V3D_BGPIC_MOVIE) {
- /* TODO: skip drawing when out of frame range (as image sequences do above) */
+ const float startx = rect->xmin + k + 1.0f; /* axis center in screen coordinates, x=y */
+ const float starty = rect->ymin + k + 1.0f;
- if (bgpic->flag & V3D_BGPIC_CAMERACLIP) {
- if (scene->camera)
- clip = BKE_object_movieclip_get(scene, scene->camera, true);
- }
- else {
- clip = bgpic->clip;
- }
+ float axis_pos[3][2];
+ unsigned char axis_col[3][4];
- if (clip == NULL)
- continue;
+ int axis_order[3] = {0, 1, 2};
+ axis_sort_v3(rv3d->viewinv[2], axis_order);
- BKE_movieclip_user_set_frame(&bgpic->cuser, CFRA);
- ibuf = BKE_movieclip_get_ibuf(clip, &bgpic->cuser);
+ for (int axis_i = 0; axis_i < 3; axis_i++) {
+ int i = axis_order[axis_i];
- image_aspect[0] = clip->aspx;
- image_aspect[1] = clip->aspy;
+ /* get position of each axis tip on screen */
+ float vec[3] = { 0.0f };
+ vec[i] = 1.0f;
+ mul_qt_v3(rv3d->viewquat, vec);
+ axis_pos[i][0] = startx + vec[0] * k;
+ axis_pos[i][1] = starty + vec[1] * k;
- /* working with ibuf from image and clip has got different workflow now.
- * ibuf acquired from clip is referenced by cache system and should
- * be dereferenced after usage. */
- freeibuf = ibuf;
- }
- else {
- /* perhaps when loading future files... */
- BLI_assert(0);
- copy_v2_fl(image_aspect, 1.0f);
- }
+ /* get color of each axis */
+ UI_GetThemeColorShade3ubv(TH_AXIS_X + i, bright, axis_col[i]); /* rgb */
+ axis_col[i][3] = 255 * hypotf(vec[0], vec[1]); /* alpha */
+ }
- if (ibuf == NULL)
- continue;
+ /* draw axis lines */
+ glLineWidth(2.0f);
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- if ((ibuf->rect == NULL && ibuf->rect_float == NULL) || ibuf->channels != 4) { /* invalid image format */
- if (freeibuf)
- IMB_freeImBuf(freeibuf);
- if (releaseibuf)
- BKE_image_release_ibuf(ima, releaseibuf, lock);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
- continue;
- }
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+ immBegin(GWN_PRIM_LINES, 6);
- if (ibuf->rect == NULL)
- IMB_rect_from_float(ibuf);
+ for (int axis_i = 0; axis_i < 3; axis_i++) {
+ int i = axis_order[axis_i];
- if (rv3d->persp == RV3D_CAMOB) {
+ immAttrib4ubv(col, axis_col[i]);
+ immVertex2f(pos, startx, starty);
+ immAttrib4ubv(col, axis_col[i]);
+ immVertex2fv(pos, axis_pos[i]);
+ }
- if (do_camera_frame) {
- rctf vb;
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &vb, false);
- x1 = vb.xmin;
- y1 = vb.ymin;
- x2 = vb.xmax;
- y2 = vb.ymax;
- }
- else {
- x1 = ar->winrct.xmin;
- y1 = ar->winrct.ymin;
- x2 = ar->winrct.xmax;
- y2 = ar->winrct.ymax;
- }
+ immEnd();
+ immUnbindProgram();
+ glDisable(GL_LINE_SMOOTH);
- /* apply offset last - camera offset is different to offset in blender units */
- /* so this has some sane way of working - this matches camera's shift _exactly_ */
- {
- const float max_dim = max_ff(x2 - x1, y2 - y1);
- const float xof_scale = bgpic->xof * max_dim;
- const float yof_scale = bgpic->yof * max_dim;
-
- x1 += xof_scale;
- y1 += yof_scale;
- x2 += xof_scale;
- y2 += yof_scale;
- }
+ /* draw axis names */
+ for (int axis_i = 0; axis_i < 3; axis_i++) {
+ int i = axis_order[axis_i];
- centx = (x1 + x2) / 2.0f;
- centy = (y1 + y2) / 2.0f;
+ const char axis_text[2] = {'x' + i, '\0'};
+ BLF_color4ubv(BLF_default(), axis_col[i]);
+ BLF_draw_default_ascii(axis_pos[i][0] + 2, axis_pos[i][1] + 2, 0.0f, axis_text, 1);
+ }
+}
- /* aspect correction */
- if (bgpic->flag & V3D_BGPIC_CAMERA_ASPECT) {
- /* apply aspect from clip */
- const float w_src = ibuf->x * image_aspect[0];
- const float h_src = ibuf->y * image_aspect[1];
+#ifdef WITH_INPUT_NDOF
+/* draw center and axis of rotation for ongoing 3D mouse navigation */
+static void UNUSED_FUNCTION(draw_rotation_guide)(RegionView3D *rv3d)
+{
+ float o[3]; /* center of rotation */
+ float end[3]; /* endpoints for drawing */
- /* destination aspect is already applied from the camera frame */
- const float w_dst = x1 - x2;
- const float h_dst = y1 - y2;
+ GLubyte color[4] = {0, 108, 255, 255}; /* bright blue so it matches device LEDs */
- const float asp_src = w_src / h_src;
- const float asp_dst = w_dst / h_dst;
+ negate_v3_v3(o, rv3d->ofs);
- if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
- if ((asp_src > asp_dst) == ((bgpic->flag & V3D_BGPIC_CAMERA_CROP) != 0)) {
- /* fit X */
- const float div = asp_src / asp_dst;
- x1 = ((x1 - centx) * div) + centx;
- x2 = ((x2 - centx) * div) + centx;
- }
- else {
- /* fit Y */
- const float div = asp_dst / asp_src;
- y1 = ((y1 - centy) * div) + centy;
- y2 = ((y2 - centy) * div) + centy;
- }
- }
- }
- }
- else {
- float tvec[3];
- float sco[2];
- const float mval_f[2] = {1.0f, 0.0f};
- const float co_zero[3] = {0};
- float zfac;
-
- /* calc window coord */
- zfac = ED_view3d_calc_zfac(rv3d, co_zero, NULL);
- ED_view3d_win_to_delta(ar, mval_f, tvec, zfac);
- fac = max_ff(fabsf(tvec[0]), max_ff(fabsf(tvec[1]), fabsf(tvec[2]))); /* largest abs axis */
- fac = 1.0f / fac;
-
- asp = (float)ibuf->y / (float)ibuf->x;
-
- zero_v3(tvec);
- ED_view3d_project_float_v2_m4(ar, tvec, sco, rv3d->persmat);
-
- x1 = sco[0] + fac * (bgpic->xof - bgpic->size);
- y1 = sco[1] + asp * fac * (bgpic->yof - bgpic->size);
- x2 = sco[0] + fac * (bgpic->xof + bgpic->size);
- y2 = sco[1] + asp * fac * (bgpic->yof + bgpic->size);
-
- centx = (x1 + x2) / 2.0f;
- centy = (y1 + y2) / 2.0f;
- }
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glDepthMask(GL_FALSE); /* don't overwrite zbuf */
- /* complete clip? */
- BLI_rctf_init(&clip_rect, x1, x2, y1, y2);
- if (bgpic->rotation) {
- BLI_rctf_rotate_expand(&clip_rect, &clip_rect, bgpic->rotation);
- }
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ unsigned int col = GWN_vertformat_attr_add(format, "color", GWN_COMP_U8, 4, GWN_FETCH_INT_TO_FLOAT_UNIT);
- if (clip_rect.xmax < 0 || clip_rect.ymax < 0 || clip_rect.xmin > ar->winx || clip_rect.ymin > ar->winy) {
- if (freeibuf)
- IMB_freeImBuf(freeibuf);
- if (releaseibuf)
- BKE_image_release_ibuf(ima, releaseibuf, lock);
+ immBindBuiltinProgram(GPU_SHADER_3D_SMOOTH_COLOR);
- continue;
- }
+ if (rv3d->rot_angle != 0.0f) {
+ /* -- draw rotation axis -- */
+ float scaled_axis[3];
+ const float scale = rv3d->dist;
+ mul_v3_v3fl(scaled_axis, rv3d->rot_axis, scale);
- zoomx = (x2 - x1) / ibuf->x;
- zoomy = (y2 - y1) / ibuf->y;
- /* for some reason; zoomlevels down refuses to use GL_ALPHA_SCALE */
- if (zoomx < 1.0f || zoomy < 1.0f) {
- float tzoom = min_ff(zoomx, zoomy);
- int mip = 0;
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+ color[3] = 0; /* more transparent toward the ends */
+ immAttrib4ubv(col, color);
+ add_v3_v3v3(end, o, scaled_axis);
+ immVertex3fv(pos, end);
- if ((ibuf->userflags & IB_MIPMAP_INVALID) != 0) {
- IMB_remakemipmap(ibuf, 0);
- ibuf->userflags &= ~IB_MIPMAP_INVALID;
- }
- else if (ibuf->mipmap[0] == NULL)
- IMB_makemipmap(ibuf, 0);
-
- while (tzoom < 1.0f && mip < 8 && ibuf->mipmap[mip]) {
- tzoom *= 2.0f;
- zoomx *= 2.0f;
- zoomy *= 2.0f;
- mip++;
- }
- if (mip > 0)
- ibuf = ibuf->mipmap[mip - 1];
- }
+#if 0
+ color[3] = 0.2f + fabsf(rv3d->rot_angle); /* modulate opacity with angle */
+ /* ^^ neat idea, but angle is frame-rate dependent, so it's usually close to 0.2 */
+#endif
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
- glDepthMask(0);
+ color[3] = 127; /* more opaque toward the center */
+ immAttrib4ubv(col, color);
+ immVertex3fv(pos, o);
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ color[3] = 0;
+ immAttrib4ubv(col, color);
+ sub_v3_v3v3(end, o, scaled_axis);
+ immVertex3fv(pos, end);
+ immEnd();
+
+ /* -- draw ring around rotation center -- */
+ {
+#define ROT_AXIS_DETAIL 13
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- ED_region_pixelspace(ar);
+ const float s = 0.05f * scale;
+ const float step = 2.0f * (float)(M_PI / ROT_AXIS_DETAIL);
- glTranslatef(centx, centy, 0.0);
- glRotatef(RAD2DEGF(-bgpic->rotation), 0.0f, 0.0f, 1.0f);
+ float q[4]; /* rotate ring so it's perpendicular to axis */
+ const int upright = fabsf(rv3d->rot_axis[2]) >= 0.95f;
+ if (!upright) {
+ const float up[3] = {0.0f, 0.0f, 1.0f};
+ float vis_angle, vis_axis[3];
- if (bgpic->flag & V3D_BGPIC_FLIP_X) {
- zoomx *= -1.0f;
- x1 = x2;
- }
- if (bgpic->flag & V3D_BGPIC_FLIP_Y) {
- zoomy *= -1.0f;
- y1 = y2;
+ cross_v3_v3v3(vis_axis, up, rv3d->rot_axis);
+ vis_angle = acosf(dot_v3v3(up, rv3d->rot_axis));
+ axis_angle_to_quat(q, vis_axis, vis_angle);
}
- glPixelZoom(zoomx, zoomy);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f - bgpic->blend);
- /* could not use glaDrawPixelsAuto because it could fallback to
- * glaDrawPixelsSafe in some cases, which will end up in missing
- * alpha transparency for the background image (sergey)
- */
- glaDrawPixelsTex(x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect);
-
- glPixelZoom(1.0, 1.0);
- glPixelTransferf(GL_ALPHA_SCALE, 1.0f);
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
+ immBegin(GWN_PRIM_LINE_LOOP, ROT_AXIS_DETAIL);
+ color[3] = 63; /* somewhat faint */
+ immAttrib4ubv(col, color);
+ float angle = 0.0f;
+ for (int i = 0; i < ROT_AXIS_DETAIL; ++i, angle += step) {
+ float p[3] = {s * cosf(angle), s * sinf(angle), 0.0f};
- glDisable(GL_BLEND);
+ if (!upright) {
+ mul_qt_v3(q, p);
+ }
- glDepthMask(1);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
+ add_v3_v3(p, o);
+ immVertex3fv(pos, p);
+ }
+ immEnd();
- if (freeibuf)
- IMB_freeImBuf(freeibuf);
- if (releaseibuf)
- BKE_image_release_ibuf(ima, releaseibuf, lock);
+#undef ROT_AXIS_DETAIL
}
+
+ color[3] = 255; /* solid dot */
}
-}
+ else
+ color[3] = 127; /* see-through dot */
-static void view3d_draw_bgpic_test(Scene *scene, ARegion *ar, View3D *v3d,
- const bool do_foreground, const bool do_camera_frame)
-{
- RegionView3D *rv3d = ar->regiondata;
+ immUnbindProgram();
- if ((v3d->flag & V3D_DISPBGPICS) == 0)
- return;
+ /* -- draw rotation center -- */
+ immBindBuiltinProgram(GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR);
+ glPointSize(5.0f);
+ immBegin(GWN_PRIM_POINTS, 1);
+ immAttrib4ubv(col, color);
+ immVertex3fv(pos, o);
+ immEnd();
+ immUnbindProgram();
- /* disabled - mango request, since footage /w only render is quite useful
- * and this option is easy to disable all background images at once */
#if 0
- if (v3d->flag2 & V3D_RENDER_OVERRIDE)
- return;
+ /* find screen coordinates for rotation center, then draw pretty icon */
+ mul_m4_v3(rv3d->persinv, rot_center);
+ UI_icon_draw(rot_center[0], rot_center[1], ICON_NDOF_TURN);
+ /* ^^ just playing around, does not work */
#endif
- if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) {
- if (rv3d->persp == RV3D_CAMOB) {
- view3d_draw_bgpic(scene, ar, v3d, do_foreground, do_camera_frame);
- }
- }
- else {
- view3d_draw_bgpic(scene, ar, v3d, do_foreground, do_camera_frame);
- }
-}
-
-/* ****************** View3d afterdraw *************** */
-
-typedef struct View3DAfter {
- struct View3DAfter *next, *prev;
- struct Base *base;
- short dflag;
-} View3DAfter;
-
-/* temp storage of Objects that need to be drawn as last */
-void ED_view3d_after_add(ListBase *lb, Base *base, const short dflag)
-{
- View3DAfter *v3da = MEM_callocN(sizeof(View3DAfter), "View 3d after");
- BLI_assert((base->flag & OB_FROMDUPLI) == 0);
- BLI_addtail(lb, v3da);
- v3da->base = base;
- v3da->dflag = dflag;
-}
-
-/* disables write in zbuffer and draws it over */
-static void view3d_draw_transp(Scene *scene, ARegion *ar, View3D *v3d)
-{
- View3DAfter *v3da;
-
- glDepthMask(GL_FALSE);
- v3d->transp = true;
-
- while ((v3da = BLI_pophead(&v3d->afterdraw_transp))) {
- draw_object(scene, ar, v3d, v3da->base, v3da->dflag);
- MEM_freeN(v3da);
- }
- v3d->transp = false;
-
+ glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
-
}
+#endif /* WITH_INPUT_NDOF */
-/* clears zbuffer and draws it over */
-static void view3d_draw_xray(Scene *scene, ARegion *ar, View3D *v3d, bool *clear)
-{
- View3DAfter *v3da;
-
- if (*clear && v3d->zbuf) {
- glClear(GL_DEPTH_BUFFER_BIT);
- *clear = false;
- }
-
- v3d->xray = true;
- while ((v3da = BLI_pophead(&v3d->afterdraw_xray))) {
- draw_object(scene, ar, v3d, v3da->base, v3da->dflag);
- MEM_freeN(v3da);
- }
- v3d->xray = false;
-}
-
-
-/* clears zbuffer and draws it over */
-static void view3d_draw_xraytransp(Scene *scene, ARegion *ar, View3D *v3d, const bool clear)
-{
- View3DAfter *v3da;
-
- if (clear && v3d->zbuf)
- glClear(GL_DEPTH_BUFFER_BIT);
-
- v3d->xray = true;
- v3d->transp = true;
-
- glDepthMask(GL_FALSE);
-
- while ((v3da = BLI_pophead(&v3d->afterdraw_xraytransp))) {
- draw_object(scene, ar, v3d, v3da->base, v3da->dflag);
- MEM_freeN(v3da);
- }
-
- v3d->transp = false;
- v3d->xray = false;
-
- glDepthMask(GL_TRUE);
-}
+/* ******************** info ***************** */
-/* clears zbuffer and draws it over,
- * note that in the select version we don't care about transparent flag as with regular drawing */
-static void view3d_draw_xray_select(Scene *scene, ARegion *ar, View3D *v3d, bool *clear)
+/**
+* Render and camera border
+*/
+static void view3d_draw_border(const bContext *C, ARegion *ar)
{
- /* Not ideal, but we need to read from the previous depths before clearing
- * otherwise we could have a function to load the depths after drawing.
- *
- * Clearing the depth buffer isn't all that common between drawing objects so accept this for now.
- */
- if (U.gpu_select_pick_deph) {
- GPU_select_load_id(-1);
- }
+ Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ RegionView3D *rv3d = ar->regiondata;
+ View3D *v3d = CTX_wm_view3d(C);
- View3DAfter *v3da;
- if (*clear && v3d->zbuf) {
- glClear(GL_DEPTH_BUFFER_BIT);
- *clear = false;
+ if (rv3d->persp == RV3D_CAMOB) {
+ drawviewborder(scene, depsgraph, ar, v3d);
}
-
- v3d->xray = true;
- while ((v3da = BLI_pophead(&v3d->afterdraw_xray))) {
- if (GPU_select_load_id(v3da->base->selcol)) {
- draw_object_select(scene, ar, v3d, v3da->base, v3da->dflag);
- }
- MEM_freeN(v3da);
+ else if (v3d->flag2 & V3D_RENDER_BORDER) {
+ drawrenderborder(ar, v3d);
}
- v3d->xray = false;
}
-/* *********************** */
-
-/*
- * In most cases call draw_dupli_objects,
- * draw_dupli_objects_color was added because when drawing set dupli's
- * we need to force the color
- */
-
-#if 0
-int dupli_ob_sort(void *arg1, void *arg2)
-{
- void *p1 = ((DupliObject *)arg1)->ob;
- void *p2 = ((DupliObject *)arg2)->ob;
- int val = 0;
- if (p1 < p2) val = -1;
- else if (p1 > p2) val = 1;
- return val;
-}
-#endif
-
-
-static DupliObject *dupli_step(DupliObject *dob)
+/**
+* Grease Pencil
+*/
+static void view3d_draw_grease_pencil(const bContext *UNUSED(C))
{
- while (dob && dob->no_draw)
- dob = dob->next;
- return dob;
+ /* TODO viewport */
}
-static void draw_dupli_objects_color(
- Scene *scene, ARegion *ar, View3D *v3d, Base *base,
- const short dflag, const int color)
+/**
+* Viewport Name
+*/
+static const char *view3d_get_name(View3D *v3d, RegionView3D *rv3d)
{
- RegionView3D *rv3d = ar->regiondata;
- ListBase *lb;
- LodLevel *savedlod;
- DupliObject *dob_prev = NULL, *dob, *dob_next = NULL;
- Base tbase = {NULL};
- BoundBox bb, *bb_tmp; /* use a copy because draw_object, calls clear_mesh_caches */
- GLuint displist = 0;
- unsigned char color_rgb[3];
- const short dflag_dupli = dflag | DRAW_CONSTCOLOR;
- short transflag;
- bool use_displist = false; /* -1 is initialize */
- char dt;
- short dtx;
- DupliApplyData *apply_data;
-
- if (base->object->restrictflag & OB_RESTRICT_VIEW) return;
- if ((base->object->restrictflag & OB_RESTRICT_RENDER) && (v3d->flag2 & V3D_RENDER_OVERRIDE)) return;
-
- if (dflag & DRAW_CONSTCOLOR) {
- BLI_assert(color == TH_UNDEFINED);
- }
- else {
- UI_GetThemeColorBlend3ubv(color, TH_BACK, 0.5f, color_rgb);
- }
-
- tbase.flag = OB_FROMDUPLI | base->flag;
- lb = object_duplilist(G.main->eval_ctx, scene, base->object);
- // BLI_listbase_sort(lb, dupli_ob_sort); /* might be nice to have if we have a dupli list with mixed objects. */
-
- apply_data = duplilist_apply(base->object, scene, lb);
-
- dob = dupli_step(lb->first);
- if (dob) dob_next = dupli_step(dob->next);
-
- for (; dob; dob_prev = dob, dob = dob_next, dob_next = dob_next ? dupli_step(dob_next->next) : NULL) {
- bool testbb = false;
-
- tbase.object = dob->ob;
-
- /* Make sure lod is updated from dupli's position */
- savedlod = dob->ob->currentlod;
-
-#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 */
- dt = tbase.object->dt;
- tbase.object->dt = MIN2(tbase.object->dt, base->object->dt);
-
- /* inherit draw extra, but not if a boundbox under the assumption that this
- * is intended to speed up drawing, and drawing extra (especially wire) can
- * slow it down too much */
- dtx = tbase.object->dtx;
- if (tbase.object->dt != OB_BOUNDBOX)
- tbase.object->dtx = base->object->dtx;
-
- /* negative scale flag has to propagate */
- transflag = tbase.object->transflag;
+ const char *name = NULL;
- if (is_negative_m4(dob->mat))
- tbase.object->transflag |= OB_NEG_SCALE;
- else
- tbase.object->transflag &= ~OB_NEG_SCALE;
-
- /* should move outside the loop but possible color is set in draw_object still */
- if ((dflag & DRAW_CONSTCOLOR) == 0) {
- glColor3ubv(color_rgb);
- }
-
- /* generate displist, test for new object */
- if (dob_prev && dob_prev->ob != dob->ob) {
- if (use_displist == true)
- glDeleteLists(displist, 1);
-
- use_displist = false;
- }
-
- if ((bb_tmp = BKE_object_boundbox_get(dob->ob))) {
- bb = *bb_tmp; /* must make a copy */
- testbb = true;
- }
+ switch (rv3d->view) {
+ case RV3D_VIEW_FRONT:
+ if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Front Ortho");
+ else name = IFACE_("Front Persp");
+ break;
+ case RV3D_VIEW_BACK:
+ if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Back Ortho");
+ else name = IFACE_("Back Persp");
+ break;
+ case RV3D_VIEW_TOP:
+ if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Top Ortho");
+ else name = IFACE_("Top Persp");
+ break;
+ case RV3D_VIEW_BOTTOM:
+ if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Bottom Ortho");
+ else name = IFACE_("Bottom Persp");
+ break;
+ case RV3D_VIEW_RIGHT:
+ if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Right Ortho");
+ else name = IFACE_("Right Persp");
+ break;
+ case RV3D_VIEW_LEFT:
+ if (rv3d->persp == RV3D_ORTHO) name = IFACE_("Left Ortho");
+ else name = IFACE_("Left Persp");
+ break;
- if (!testbb || ED_view3d_boundbox_clip_ex(rv3d, &bb, dob->mat)) {
- /* generate displist */
- if (use_displist == false) {
-
- /* note, since this was added, its checked (dob->type == OB_DUPLIGROUP)
- * however this is very slow, it was probably needed for the NLA
- * offset feature (used in group-duplicate.blend but no longer works in 2.5)
- * so for now it should be ok to - campbell */
-
- if ( /* if this is the last no need to make a displist */
- (dob_next == NULL || dob_next->ob != dob->ob) ||
- /* lamp drawing messes with matrices, could be handled smarter... but this works */
- (dob->ob->type == OB_LAMP) ||
- (dob->type == OB_DUPLIGROUP && dob->animated) ||
- !bb_tmp ||
- draw_glsl_material(scene, dob->ob, v3d, dt) ||
- check_object_draw_texture(scene, v3d, dt) ||
- (v3d->flag2 & V3D_SOLID_MATCAP) != 0)
- {
- // printf("draw_dupli_objects_color: skipping displist for %s\n", dob->ob->id.name + 2);
- use_displist = false;
+ default:
+ if (rv3d->persp == RV3D_CAMOB) {
+ if ((v3d->camera) && (v3d->camera->type == OB_CAMERA)) {
+ Camera *cam;
+ cam = v3d->camera->data;
+ if (cam->type == CAM_PERSP) {
+ name = IFACE_("Camera Persp");
+ }
+ else if (cam->type == CAM_ORTHO) {
+ name = IFACE_("Camera Ortho");
+ }
+ else {
+ BLI_assert(cam->type == CAM_PANO);
+ name = IFACE_("Camera Pano");
+ }
}
else {
- // printf("draw_dupli_objects_color: using displist for %s\n", dob->ob->id.name + 2);
-
- /* disable boundbox check for list creation */
- BKE_object_boundbox_flag(dob->ob, BOUNDBOX_DISABLED, 1);
- /* need this for next part of code */
- unit_m4(dob->ob->obmat); /* obmat gets restored */
-
- displist = glGenLists(1);
- glNewList(displist, GL_COMPILE);
- draw_object(scene, ar, v3d, &tbase, dflag_dupli);
- glEndList();
-
- use_displist = true;
- BKE_object_boundbox_flag(dob->ob, BOUNDBOX_DISABLED, 0);
- }
+ name = IFACE_("Object as Camera");
+ }
}
-
- if (use_displist) {
- glPushMatrix();
- glMultMatrixf(dob->mat);
- glCallList(displist);
- glPopMatrix();
- }
else {
- copy_m4_m4(dob->ob->obmat, dob->mat);
- GPU_begin_dupli_object(dob);
- draw_object(scene, ar, v3d, &tbase, dflag_dupli);
- GPU_end_dupli_object();
+ name = (rv3d->persp == RV3D_ORTHO) ? IFACE_("User Ortho") : IFACE_("User Persp");
}
- }
-
- tbase.object->dt = dt;
- tbase.object->dtx = dtx;
- tbase.object->transflag = transflag;
- tbase.object->currentlod = savedlod;
}
- if (apply_data) {
- duplilist_restore(lb, apply_data);
- duplilist_free_apply_data(apply_data);
- }
-
- free_object_duplilist(lb);
-
- if (use_displist)
- glDeleteLists(displist, 1);
-}
-
-static void draw_dupli_objects(Scene *scene, ARegion *ar, View3D *v3d, Base *base)
-{
- /* define the color here so draw_dupli_objects_color can be called
- * from the set loop */
-
- int color = (base->flag & SELECT) ? TH_SELECT : TH_WIRE;
- /* debug */
- if (base->object->dup_group && base->object->dup_group->id.us < 1)
- color = TH_REDALERT;
-
- draw_dupli_objects_color(scene, ar, v3d, base, 0, color);
-}
-
-/* XXX warning, not using gpu offscreen here */
-void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect)
-{
- int x, y, w, h;
- rcti r;
- /* clamp rect by region */
-
- r.xmin = 0;
- r.xmax = ar->winx - 1;
- r.ymin = 0;
- r.ymax = ar->winy - 1;
-
- /* Constrain rect to depth bounds */
- BLI_rcti_isect(&r, rect, rect);
-
- /* assign values to compare with the ViewDepths */
- x = rect->xmin;
- y = rect->ymin;
-
- w = BLI_rcti_size_x(rect);
- h = BLI_rcti_size_y(rect);
-
- if (w <= 0 || h <= 0) {
- if (d->depths)
- MEM_freeN(d->depths);
- d->depths = NULL;
-
- d->damaged = false;
- }
- else if (d->w != w ||
- d->h != h ||
- d->x != x ||
- d->y != y ||
- d->depths == NULL
- )
- {
- d->x = x;
- d->y = y;
- d->w = w;
- d->h = h;
-
- if (d->depths)
- MEM_freeN(d->depths);
-
- d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths Subset");
-
- d->damaged = true;
- }
-
- if (d->damaged) {
- /* XXX using special function here, it doesn't use the gpu offscreen system */
- view3d_opengl_read_Z_pixels(ar, d->x, d->y, d->w, d->h, GL_DEPTH_COMPONENT, GL_FLOAT, d->depths);
- glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
- d->damaged = false;
- }
+ return name;
}
-/* note, with nouveau drivers the glReadPixels() is very slow. [#24339] */
-void ED_view3d_depth_update(ARegion *ar)
+static void draw_viewport_name(ARegion *ar, View3D *v3d, const rcti *rect)
{
RegionView3D *rv3d = ar->regiondata;
-
- /* Create storage for, and, if necessary, copy depth buffer */
- if (!rv3d->depths) rv3d->depths = MEM_callocN(sizeof(ViewDepths), "ViewDepths");
- if (rv3d->depths) {
- ViewDepths *d = rv3d->depths;
- if (d->w != ar->winx ||
- d->h != ar->winy ||
- !d->depths)
- {
- d->w = ar->winx;
- d->h = ar->winy;
- if (d->depths)
- MEM_freeN(d->depths);
- d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths");
- d->damaged = true;
- }
-
- if (d->damaged) {
- view3d_opengl_read_pixels(ar, 0, 0, d->w, d->h, GL_DEPTH_COMPONENT, GL_FLOAT, d->depths);
- glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
-
- d->damaged = false;
- }
- }
-}
+ const char *name = view3d_get_name(v3d, rv3d);
+ /* increase size for unicode languages (Chinese in utf-8...) */
+#ifdef WITH_INTERNATIONAL
+ char tmpstr[96];
+#else
+ char tmpstr[32];
+#endif
-/* utility function to find the closest Z value, use for autodepth */
-float view3d_depth_near(ViewDepths *d)
-{
- /* convert to float for comparisons */
- const float near = (float)d->depth_range[0];
- const float far_real = (float)d->depth_range[1];
- float far = far_real;
-
- const float *depths = d->depths;
- float depth = FLT_MAX;
- int i = (int)d->w * (int)d->h; /* cast to avoid short overflow */
-
- /* far is both the starting 'far' value
- * and the closest value found. */
- while (i--) {
- depth = *depths++;
- if ((depth < far) && (depth > near)) {
- far = depth;
- }
+ if (v3d->localvd) {
+ BLI_snprintf(tmpstr, sizeof(tmpstr), IFACE_("%s (Local)"), name);
+ name = tmpstr;
}
- return far == far_real ? FLT_MAX : far;
-}
-
-void ED_view3d_draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d)
-{
- short zbuf = v3d->zbuf;
- RegionView3D *rv3d = ar->regiondata;
-
- /* Setup view matrix. */
- ED_view3d_draw_setup_view(NULL, scene, ar, v3d, rv3d->viewmat, rv3d->winmat, NULL);
-
- glClear(GL_DEPTH_BUFFER_BIT);
-
- v3d->zbuf = true;
- glEnable(GL_DEPTH_TEST);
-
- if (v3d->flag2 & V3D_SHOW_GPENCIL) {
- ED_gpencil_draw_view3d(NULL, scene, v3d, ar, true);
- }
-
- v3d->zbuf = zbuf;
+ UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
+#ifdef WITH_INTERNATIONAL
+ BLF_draw_default(U.widget_unit + rect->xmin, rect->ymax - U.widget_unit, 0.0f, name, sizeof(tmpstr));
+#else
+ BLF_draw_default_ascii(U.widget_unit + rect->xmin, rect->ymax - U.widget_unit, 0.0f, name, sizeof(tmpstr));
+#endif
}
-static void view3d_draw_depth_loop(Scene *scene, ARegion *ar, View3D *v3d)
-{
- Base *base;
-
- /* no need for color when drawing depth buffer */
- const short dflag_depth = DRAW_CONSTCOLOR;
-
- /* draw set first */
- if (scene->set) {
- Scene *sce_iter;
- for (SETLOOPER(scene->set, sce_iter, base)) {
- if (v3d->lay & base->lay) {
- draw_object(scene, ar, v3d, base, 0);
- if (base->object->transflag & OB_DUPLI) {
- draw_dupli_objects_color(scene, ar, v3d, base, dflag_depth, TH_UNDEFINED);
- }
- }
- }
- }
-
- for (base = scene->base.first; base; base = base->next) {
- if (v3d->lay & base->lay) {
- /* dupli drawing */
- if (base->object->transflag & OB_DUPLI) {
- draw_dupli_objects_color(scene, ar, v3d, base, dflag_depth, TH_UNDEFINED);
- }
- draw_object(scene, ar, v3d, base, dflag_depth);
- }
- }
-
- /* this isn't that nice, draw xray objects as if they are normal */
- if (v3d->afterdraw_transp.first ||
- v3d->afterdraw_xray.first ||
- v3d->afterdraw_xraytransp.first)
- {
- View3DAfter *v3da;
- int mask_orig;
-
- v3d->xray = true;
-
- /* transp materials can change the depth mask, see #21388 */
- glGetIntegerv(GL_DEPTH_WRITEMASK, &mask_orig);
-
-
- if (v3d->afterdraw_xray.first || v3d->afterdraw_xraytransp.first) {
- glDepthFunc(GL_ALWAYS); /* always write into the depth bufer, overwriting front z values */
- for (v3da = v3d->afterdraw_xray.first; v3da; v3da = v3da->next) {
- draw_object(scene, ar, v3d, v3da->base, dflag_depth);
- }
- glDepthFunc(GL_LEQUAL); /* Now write the depth buffer normally */
- }
-
- /* draw 3 passes, transp/xray/xraytransp */
- v3d->xray = false;
- v3d->transp = true;
- while ((v3da = BLI_pophead(&v3d->afterdraw_transp))) {
- draw_object(scene, ar, v3d, v3da->base, dflag_depth);
- MEM_freeN(v3da);
- }
-
- v3d->xray = true;
- v3d->transp = false;
- while ((v3da = BLI_pophead(&v3d->afterdraw_xray))) {
- draw_object(scene, ar, v3d, v3da->base, dflag_depth);
- MEM_freeN(v3da);
- }
-
- v3d->xray = true;
- v3d->transp = true;
- while ((v3da = BLI_pophead(&v3d->afterdraw_xraytransp))) {
- draw_object(scene, ar, v3d, v3da->base, dflag_depth);
- MEM_freeN(v3da);
- }
-
-
- v3d->xray = false;
- v3d->transp = false;
-
- glDepthMask(mask_orig);
- }
-}
+/**
+ * draw info beside axes in bottom left-corner:
+ * framenum, object name, bone name (if available), marker name (if available)
+ */
-void ED_view3d_draw_depth(Scene *scene, ARegion *ar, View3D *v3d, bool alphaoverride)
+static void draw_selected_name(Scene *scene, Object *ob, rcti *rect)
{
- struct bThemeState theme_state;
- RegionView3D *rv3d = ar->regiondata;
- short zbuf = v3d->zbuf;
- short flag = v3d->flag;
- float glalphaclip = U.glalphaclip;
- int obcenter_dia = U.obcenter_dia;
- /* temp set drawtype to solid */
-
- /* Setting these temporarily is not nice */
- v3d->flag &= ~V3D_SELECT_OUTLINE;
- U.glalphaclip = alphaoverride ? 0.5f : glalphaclip; /* not that nice but means we wont zoom into billboards */
- U.obcenter_dia = 0;
-
- /* Tools may request depth outside of regular drawing code. */
- UI_Theme_Store(&theme_state);
- UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
-
- /* Setup view matrix. */
- ED_view3d_draw_setup_view(NULL, scene, ar, v3d, rv3d->viewmat, rv3d->winmat, NULL);
-
- glClear(GL_DEPTH_BUFFER_BIT);
-
- if (rv3d->rflag & RV3D_CLIPPING) {
- ED_view3d_clipping_set(rv3d);
- }
- /* get surface depth without bias */
- rv3d->rflag |= RV3D_ZOFFSET_DISABLED;
-
- v3d->zbuf = true;
- glEnable(GL_DEPTH_TEST);
+ const int cfra = CFRA;
+ const char *msg_pin = " (Pinned)";
+ const char *msg_sep = " : ";
- view3d_draw_depth_loop(scene, ar, v3d);
+ const int font_id = BLF_default();
- if (rv3d->rflag & RV3D_CLIPPING) {
- ED_view3d_clipping_disable();
- }
- rv3d->rflag &= ~RV3D_ZOFFSET_DISABLED;
-
- v3d->zbuf = zbuf;
- if (!v3d->zbuf) glDisable(GL_DEPTH_TEST);
+ char info[300];
+ char *s = info;
+ short offset = 1.5f * UI_UNIT_X + rect->xmin;
- U.glalphaclip = glalphaclip;
- v3d->flag = flag;
- U.obcenter_dia = obcenter_dia;
+ s += sprintf(s, "(%d)", cfra);
- UI_Theme_Restore(&theme_state);
-}
+ /*
+ * info can contain:
+ * - a frame (7 + 2)
+ * - 3 object names (MAX_NAME)
+ * - 2 BREAD_CRUMB_SEPARATORs (6)
+ * - a SHAPE_KEY_PINNED marker and a trailing '\0' (9+1) - translated, so give some room!
+ * - a marker name (MAX_NAME + 3)
+ */
-void ED_view3d_draw_select_loop(
- ViewContext *vc, Scene *scene, View3D *v3d, ARegion *ar,
- bool use_obedit_skip, bool use_nearest)
-{
- short code = 1;
- const short dflag = DRAW_PICKING | DRAW_CONSTCOLOR;
+ /* get name of marker on current frame (if available) */
+ const char *markern = BKE_scene_find_marker_name(scene, cfra);
- if (vc->obedit && vc->obedit->type == OB_MBALL) {
- draw_object(scene, ar, v3d, BASACT, dflag);
- }
- else if ((vc->obedit && vc->obedit->type == OB_ARMATURE)) {
- /* if not drawing sketch, draw bones */
- if (!BDR_drawSketchNames(vc)) {
- draw_object(scene, ar, v3d, BASACT, dflag);
- }
- }
- else {
- Base *base;
+ /* check if there is an object */
+ if (ob) {
+ *s++ = ' ';
+ s += BLI_strcpy_rlen(s, ob->id.name + 2);
- for (base = scene->base.first; base; base = base->next) {
- if (base->lay & v3d->lay) {
+ /* name(s) to display depends on type of object */
+ if (ob->type == OB_ARMATURE) {
+ bArmature *arm = ob->data;
- if ((base->object->restrictflag & OB_RESTRICT_SELECT) ||
- (use_obedit_skip && (scene->obedit->data == base->object->data)))
- {
- base->selcol = 0;
+ /* show name of active bone too (if possible) */
+ if (arm->edbo) {
+ if (arm->act_edbone) {
+ s += BLI_strcpy_rlen(s, msg_sep);
+ s += BLI_strcpy_rlen(s, arm->act_edbone->name);
}
- else {
- base->selcol = code;
+ }
+ else if (ob->mode & OB_MODE_POSE) {
+ if (arm->act_bone) {
- if (use_nearest && (base->object->dtx & OB_DRAWXRAY)) {
- ED_view3d_after_add(&v3d->afterdraw_xray, base, dflag);
- }
- else {
- if (GPU_select_load_id(code)) {
- draw_object_select(scene, ar, v3d, base, dflag);
- }
+ if (arm->act_bone->layer & arm->layer) {
+ s += BLI_strcpy_rlen(s, msg_sep);
+ s += BLI_strcpy_rlen(s, arm->act_bone->name);
}
- code++;
}
}
}
+ else if (ELEM(ob->type, OB_MESH, OB_LATTICE, OB_CURVE)) {
+ /* try to display active bone and active shapekey too (if they exist) */
- if (use_nearest) {
- bool xrayclear = true;
- if (v3d->afterdraw_xray.first) {
- view3d_draw_xray_select(scene, ar, v3d, &xrayclear);
+ if (ob->type == OB_MESH && ob->mode & OB_MODE_WEIGHT_PAINT) {
+ Object *armobj = BKE_object_pose_armature_get(ob);
+ if (armobj && armobj->mode & OB_MODE_POSE) {
+ bArmature *arm = armobj->data;
+ if (arm->act_bone) {
+ if (arm->act_bone->layer & arm->layer) {
+ s += BLI_strcpy_rlen(s, msg_sep);
+ s += BLI_strcpy_rlen(s, arm->act_bone->name);
+ }
+ }
+ }
}
- }
- }
-}
-typedef struct View3DShadow {
- struct View3DShadow *next, *prev;
- GPULamp *lamp;
-} View3DShadow;
-
-static void gpu_render_lamp_update(Scene *scene, View3D *v3d,
- Object *ob, Object *par,
- float obmat[4][4], unsigned int lay,
- ListBase *shadows, SceneRenderLayer *srl)
-{
- GPULamp *lamp;
- Lamp *la = (Lamp *)ob->data;
- View3DShadow *shadow;
- unsigned int layers;
-
- lamp = GPU_lamp_from_blender(scene, ob, par);
-
- if (lamp) {
- GPU_lamp_update(lamp, lay, (ob->restrictflag & OB_RESTRICT_RENDER), obmat);
- GPU_lamp_update_colors(lamp, la->r, la->g, la->b, la->energy);
-
- layers = lay & v3d->lay;
- if (srl)
- layers &= srl->lay;
-
- if (layers &&
- GPU_lamp_has_shadow_buffer(lamp) &&
- /* keep last, may do string lookup */
- GPU_lamp_visible(lamp, srl, NULL))
- {
- shadow = MEM_callocN(sizeof(View3DShadow), "View3DShadow");
- shadow->lamp = lamp;
- BLI_addtail(shadows, shadow);
- }
- }
-}
-
-static void gpu_update_lamps_shadows_world(Scene *scene, View3D *v3d)
-{
- ListBase shadows;
- View3DShadow *shadow;
- Scene *sce_iter;
- Base *base;
- Object *ob;
- World *world = scene->world;
- SceneRenderLayer *srl = v3d->scenelock ? BLI_findlink(&scene->r.layers, scene->r.actlay) : NULL;
-
- BLI_listbase_clear(&shadows);
-
- /* update lamp transform and gather shadow lamps */
- for (SETLOOPER(scene, sce_iter, base)) {
- ob = base->object;
-
- if (ob->type == OB_LAMP)
- gpu_render_lamp_update(scene, v3d, ob, NULL, ob->obmat, ob->lay, &shadows, srl);
-
- if (ob->transflag & OB_DUPLI) {
- DupliObject *dob;
- ListBase *lb = object_duplilist(G.main->eval_ctx, scene, ob);
-
- for (dob = lb->first; dob; dob = dob->next)
- if (dob->ob->type == OB_LAMP)
- gpu_render_lamp_update(scene, v3d, dob->ob, ob, dob->mat, ob->lay, &shadows, srl);
-
- free_object_duplilist(lb);
- }
- }
-
- /* render shadows after updating all lamps, nested object_duplilist
- * don't work correct since it's replacing object matrices */
- for (shadow = shadows.first; shadow; shadow = shadow->next) {
- /* this needs to be done better .. */
- float viewmat[4][4], winmat[4][4];
- int drawtype, lay, winsize, flag2 = v3d->flag2;
- ARegion ar = {NULL};
- RegionView3D rv3d = {{{0}}};
-
- drawtype = v3d->drawtype;
- lay = v3d->lay;
-
- v3d->drawtype = OB_SOLID;
- v3d->lay &= GPU_lamp_shadow_layer(shadow->lamp);
- v3d->flag2 &= ~(V3D_SOLID_TEX | V3D_SHOW_SOLID_MATCAP);
- v3d->flag2 |= V3D_RENDER_OVERRIDE | V3D_RENDER_SHADOW;
-
- GPU_lamp_shadow_buffer_bind(shadow->lamp, viewmat, &winsize, winmat);
-
- ar.regiondata = &rv3d;
- ar.regiontype = RGN_TYPE_WINDOW;
- rv3d.persp = RV3D_CAMOB;
- copy_m4_m4(rv3d.winmat, winmat);
- copy_m4_m4(rv3d.viewmat, viewmat);
- invert_m4_m4(rv3d.viewinv, rv3d.viewmat);
- mul_m4_m4m4(rv3d.persmat, rv3d.winmat, rv3d.viewmat);
- invert_m4_m4(rv3d.persinv, rv3d.viewinv);
-
- /* no need to call ED_view3d_draw_offscreen_init since shadow buffers were already updated */
- ED_view3d_draw_offscreen(
- scene, v3d, &ar, winsize, winsize, viewmat, winmat,
- false, false, true,
- NULL, NULL, NULL, NULL);
- GPU_lamp_shadow_buffer_unbind(shadow->lamp);
-
- v3d->drawtype = drawtype;
- v3d->lay = lay;
- v3d->flag2 = flag2;
- }
-
- BLI_freelistN(&shadows);
-
- /* update world values */
- if (world) {
- GPU_mist_update_enable(world->mode & WO_MIST);
- GPU_mist_update_values(world->mistype, world->miststa, world->mistdist, world->misi, &world->horr);
- GPU_horizon_update_color(&world->horr);
- GPU_ambient_update_color(&world->ambr);
- GPU_zenith_update_color(&world->zenr);
- }
-}
-
-/* *********************** customdata **************** */
-
-CustomDataMask ED_view3d_datamask(const Scene *scene, const View3D *v3d)
-{
- CustomDataMask mask = 0;
- const int drawtype = view3d_effective_drawtype(v3d);
-
- if (ELEM(drawtype, OB_TEXTURE, OB_MATERIAL) ||
- ((drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX)))
- {
- mask |= CD_MASK_MTEXPOLY | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL;
-
- if (BKE_scene_use_new_shading_nodes(scene)) {
- if (drawtype == OB_MATERIAL)
- mask |= CD_MASK_ORCO;
- }
- else {
- if ((scene->gm.matmode == GAME_MAT_GLSL && drawtype == OB_TEXTURE) ||
- (drawtype == OB_MATERIAL))
- {
- mask |= CD_MASK_ORCO;
+ Key *key = BKE_key_from_object(ob);
+ if (key) {
+ KeyBlock *kb = BLI_findlink(&key->block, ob->shapenr - 1);
+ if (kb) {
+ s += BLI_strcpy_rlen(s, msg_sep);
+ s += BLI_strcpy_rlen(s, kb->name);
+ if (ob->shapeflag & OB_SHAPE_LOCK) {
+ s += BLI_strcpy_rlen(s, IFACE_(msg_pin));
+ }
+ }
}
}
- }
-
- return mask;
-}
-
-/* goes over all modes and view3d settings */
-CustomDataMask ED_view3d_screen_datamask(const bScreen *screen)
-{
- const Scene *scene = screen->scene;
- CustomDataMask mask = CD_MASK_BAREMESH;
- const ScrArea *sa;
-
- /* check if we need tfaces & mcols due to view mode */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- if (sa->spacetype == SPACE_VIEW3D) {
- mask |= ED_view3d_datamask(scene, sa->spacedata.first);
- }
- }
-
- return mask;
-}
-/**
- * \note keep this synced with #ED_view3d_mats_rv3d_backup/#ED_view3d_mats_rv3d_restore
- */
-void ED_view3d_update_viewmat(
- Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect)
-{
- RegionView3D *rv3d = ar->regiondata;
-
- /* setup window matrices */
- if (winmat)
- copy_m4_m4(rv3d->winmat, winmat);
- else
- view3d_winmatrix_set(ar, v3d, rect);
-
- /* setup view matrix */
- if (viewmat) {
- copy_m4_m4(rv3d->viewmat, viewmat);
+ /* color depends on whether there is a keyframe */
+ if (id_frame_has_keyframe((ID *)ob, /* BKE_scene_frame_get(scene) */ (float)cfra, ANIMFILTER_KEYS_LOCAL))
+ UI_FontThemeColor(font_id, TH_TIME_KEYFRAME);
+ else if (ED_gpencil_has_keyframe_v3d(scene, ob, cfra))
+ UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME);
+ else
+ UI_FontThemeColor(font_id, TH_TEXT_HI);
}
else {
- float rect_scale[2];
- if (rect) {
- rect_scale[0] = (float)BLI_rcti_size_x(rect) / (float)ar->winx;
- rect_scale[1] = (float)BLI_rcti_size_y(rect) / (float)ar->winy;
- }
- view3d_viewmatrix_set(scene, v3d, rv3d, rect ? rect_scale : NULL); /* note: calls BKE_object_where_is_calc for camera... */
+ /* no object */
+ if (ED_gpencil_has_keyframe_v3d(scene, NULL, cfra))
+ UI_FontThemeColor(font_id, TH_TIME_GP_KEYFRAME);
+ else
+ UI_FontThemeColor(font_id, TH_TEXT_HI);
}
- /* update utility matrices */
- mul_m4_m4m4(rv3d->persmat, rv3d->winmat, rv3d->viewmat);
- invert_m4_m4(rv3d->persinv, rv3d->persmat);
- invert_m4_m4(rv3d->viewinv, rv3d->viewmat);
-
- /* calculate GLSL view dependent values */
-
- /* store window coordinates scaling/offset */
- if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
- rctf cameraborder;
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &cameraborder, false);
- rv3d->viewcamtexcofac[0] = (float)ar->winx / BLI_rctf_size_x(&cameraborder);
- rv3d->viewcamtexcofac[1] = (float)ar->winy / BLI_rctf_size_y(&cameraborder);
-
- rv3d->viewcamtexcofac[2] = -rv3d->viewcamtexcofac[0] * cameraborder.xmin / (float)ar->winx;
- rv3d->viewcamtexcofac[3] = -rv3d->viewcamtexcofac[1] * cameraborder.ymin / (float)ar->winy;
- }
- else {
- rv3d->viewcamtexcofac[0] = rv3d->viewcamtexcofac[1] = 1.0f;
- rv3d->viewcamtexcofac[2] = rv3d->viewcamtexcofac[3] = 0.0f;
+ if (markern) {
+ s += sprintf(s, " <%s>", markern);
}
- /**
- * Calculate pixel-size factor once, is used for lamps and object centers.
- * Used by #ED_view3d_pixel_size and typically not accessed directly.
- *
- * \note #BKE_camera_params_compute_viewplane' also calculates a pixel-size value,
- * passed to #RE_SetPixelSize, in ortho mode this is compatible with this value,
- * but in perspective mode its offset by the near-clip.
- *
- * 'RegionView3D.pixsize' is used for viewport drawing, not rendering.
- */
- {
- /* note: '1.0f / len_v3(v1)' replaced 'len_v3(rv3d->viewmat[0])'
- * because of float point precision problems at large values [#23908] */
- float v1[3], v2[3];
- float len_px, len_sc;
-
- v1[0] = rv3d->persmat[0][0];
- v1[1] = rv3d->persmat[1][0];
- v1[2] = rv3d->persmat[2][0];
-
- v2[0] = rv3d->persmat[0][1];
- v2[1] = rv3d->persmat[1][1];
- v2[2] = rv3d->persmat[2][1];
-
- len_px = 2.0f / sqrtf(min_ff(len_squared_v3(v1), len_squared_v3(v2)));
- len_sc = (float)MAX2(ar->winx, ar->winy);
+ if (U.uiflag & USER_SHOW_ROTVIEWICON)
+ offset = U.widget_unit + (U.rvisize * 2) + rect->xmin;
- rv3d->pixsize = len_px / len_sc;
- }
+ BLF_draw_default(offset, 0.5f * U.widget_unit, 0.0f, info, sizeof(info));
}
+/* ******************** view loop ***************** */
+
/**
- * Shared by #ED_view3d_draw_offscreen and #view3d_main_region_draw_objects
- *
- * \note \a C and \a grid_unit will be NULL when \a draw_offscreen is set.
- * \note Drawing lamps and opengl render uses this, so dont do grease pencil or view widgets here.
- */
-static void view3d_draw_objects(
- const bContext *C,
- Scene *scene, View3D *v3d, ARegion *ar,
- const char **grid_unit,
- const bool do_bgpic, const bool draw_offscreen, GPUFX *fx)
+* Information drawn on top of the solid plates and composed data
+*/
+void view3d_draw_region_info(const bContext *C, ARegion *ar, const int offset)
{
RegionView3D *rv3d = ar->regiondata;
- Base *base;
- const bool do_camera_frame = !draw_offscreen;
- const bool draw_grids = !draw_offscreen && (v3d->flag2 & V3D_RENDER_OVERRIDE) == 0;
- const bool draw_floor = (rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO);
- /* only draw grids after in solid modes, else it hovers over mesh wires */
- const bool draw_grids_after = draw_grids && draw_floor && (v3d->drawtype > OB_WIRE) && fx;
- bool do_composite_xray = false;
- bool xrayclear = true;
-
- if (!draw_offscreen) {
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_PRE_VIEW);
- }
+ View3D *v3d = CTX_wm_view3d(C);
+ Scene *scene = CTX_data_scene(C);
+ wmWindowManager *wm = CTX_wm_manager(C);
- if (rv3d->rflag & RV3D_CLIPPING)
- view3d_draw_clipping(rv3d);
+ /* correct projection matrix */
+ ED_region_pixelspace(ar);
- /* set zbuffer after we draw clipping region */
- if (v3d->drawtype > OB_WIRE) {
- v3d->zbuf = true;
- }
- else {
- v3d->zbuf = false;
- }
+ /* local coordinate visible rect inside region, to accomodate overlapping ui */
+ rcti rect;
+ ED_region_visible_rect(ar, &rect);
- /* special case (depth for wire color) */
- if (v3d->drawtype <= OB_WIRE) {
- if (scene->obedit && scene->obedit->type == OB_MESH) {
- Mesh *me = scene->obedit->data;
- if (me->drawflag & ME_DRAWEIGHT) {
- v3d->zbuf = true;
- }
- }
- }
+ /* Leave room for previously drawn info. */
+ rect.ymax -= offset;
- if (v3d->zbuf) {
- glEnable(GL_DEPTH_TEST);
- }
+ view3d_draw_border(C, ar);
+ view3d_draw_grease_pencil(C);
- /* ortho grid goes first, does not write to depth buffer and doesn't need depth test so it will override
- * objects if done last */
- if (draw_grids) {
- /* needs to be done always, gridview is adjusted in drawgrid() now, but only for ortho views. */
- rv3d->gridview = ED_view3d_grid_scale(scene, v3d, grid_unit);
-
- if (!draw_floor) {
- ED_region_pixelspace(ar);
- *grid_unit = NULL; /* drawgrid need this to detect/affect smallest valid unit... */
- drawgrid(&scene->unit, ar, v3d, grid_unit);
- /* XXX make function? replaces persp(1) */
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixf(rv3d->winmat);
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(rv3d->viewmat);
- }
- else if (!draw_grids_after) {
- drawfloor(scene, v3d, grid_unit, true);
- }
- }
+ BLF_batch_draw_begin();
- /* important to do before clipping */
- if (do_bgpic) {
- view3d_draw_bgpic_test(scene, ar, v3d, false, do_camera_frame);
+ if (U.uiflag & USER_SHOW_ROTVIEWICON) {
+ draw_view_axis(rv3d, &rect);
}
- if (rv3d->rflag & RV3D_CLIPPING) {
- ED_view3d_clipping_set(rv3d);
+ if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) {
+ ED_scene_draw_fps(scene, &rect);
}
-
- /* draw set first */
- if (scene->set) {
- const short dflag = DRAW_CONSTCOLOR | DRAW_SCENESET;
- Scene *sce_iter;
- for (SETLOOPER(scene->set, sce_iter, base)) {
- if (v3d->lay & base->lay) {
- UI_ThemeColorBlend(TH_WIRE, TH_BACK, 0.6f);
- draw_object(scene, ar, v3d, base, dflag);
-
- if (base->object->transflag & OB_DUPLI) {
- draw_dupli_objects_color(scene, ar, v3d, base, dflag, TH_UNDEFINED);
- }
- }
- }
-
- /* Transp and X-ray afterdraw stuff for sets is done later */
+ else if (U.uiflag & USER_SHOW_VIEWPORTNAME) {
+ draw_viewport_name(ar, v3d, &rect);
}
-
- if (draw_offscreen) {
- for (base = scene->base.first; base; base = base->next) {
- if (v3d->lay & base->lay) {
- /* dupli drawing */
- if (base->object->transflag & OB_DUPLI)
- draw_dupli_objects(scene, ar, v3d, base);
-
- draw_object(scene, ar, v3d, base, 0);
- }
- }
+ if (U.uiflag & USER_DRAWVIEWINFO) {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+ draw_selected_name(scene, ob, &rect);
}
- else {
- unsigned int lay_used = 0;
-
- /* then draw not selected and the duplis, but skip editmode object */
- for (base = scene->base.first; base; base = base->next) {
- lay_used |= base->lay;
- if (v3d->lay & base->lay) {
+#if 0 /* TODO */
+ if (grid_unit) { /* draw below the viewport name */
+ char numstr[32] = "";
- /* dupli drawing */
- if (base->object->transflag & OB_DUPLI) {
- draw_dupli_objects(scene, ar, v3d, base);
- }
- if ((base->flag & SELECT) == 0) {
- if (base->object != scene->obedit)
- draw_object(scene, ar, v3d, base, 0);
- }
- }
- }
-
- /* mask out localview */
- v3d->lay_used = lay_used & ((1 << 20) - 1);
-
- /* draw selected and editmode */
- for (base = scene->base.first; base; base = base->next) {
- if (v3d->lay & base->lay) {
- if (base->object == scene->obedit || (base->flag & SELECT)) {
- draw_object(scene, ar, v3d, base, 0);
- }
- }
+ UI_FontThemeColor(BLF_default(), TH_TEXT_HI);
+ if (v3d->grid != 1.0f) {
+ BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
}
- }
-
- /* perspective floor goes last to use scene depth and avoid writing to depth buffer */
- if (draw_grids_after) {
- drawfloor(scene, v3d, grid_unit, false);
- }
-
- /* must be before xray draw which clears the depth buffer */
- if (v3d->flag2 & V3D_SHOW_GPENCIL) {
- wmWindowManager *wm = (C != NULL) ? CTX_wm_manager(C) : NULL;
-
- /* must be before xray draw which clears the depth buffer */
- if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
- ED_gpencil_draw_view3d(wm, scene, v3d, ar, true);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- }
-
- /* transp and X-ray afterdraw stuff */
- if (v3d->afterdraw_transp.first) view3d_draw_transp(scene, ar, v3d);
-
- /* always do that here to cleanup depth buffers if none needed */
- if (fx) {
- do_composite_xray = v3d->zbuf && (v3d->afterdraw_xray.first || v3d->afterdraw_xraytransp.first);
- GPU_fx_compositor_setup_XRay_pass(fx, do_composite_xray);
- }
-
- if (v3d->afterdraw_xray.first) view3d_draw_xray(scene, ar, v3d, &xrayclear);
- if (v3d->afterdraw_xraytransp.first) view3d_draw_xraytransp(scene, ar, v3d, xrayclear);
-
- if (fx && do_composite_xray) {
- GPU_fx_compositor_XRay_resolve(fx);
- }
-
- if (!draw_offscreen) {
- ED_region_draw_cb_draw(C, ar, REGION_DRAW_POST_VIEW);
- }
-
- if (rv3d->rflag & RV3D_CLIPPING)
- ED_view3d_clipping_disable();
- /* important to do after clipping */
- if (do_bgpic) {
- view3d_draw_bgpic_test(scene, ar, v3d, true, do_camera_frame);
+ BLF_draw_default_ascii(rect.xmin + U.widget_unit,
+ rect.ymax - (USER_SHOW_VIEWPORTNAME ? 2 * U.widget_unit : U.widget_unit), 0.0f,
+ numstr[0] ? numstr : grid_unit, sizeof(numstr));
}
+#endif
+ BLF_batch_draw_end();
+}
- if (!draw_offscreen) {
- BIF_draw_manipulator(C);
- }
+static void view3d_draw_view(const bContext *C, ARegion *ar)
+{
+ ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, CTX_wm_view3d(C), NULL, NULL, NULL);
- /* cleanup */
- if (v3d->zbuf) {
- v3d->zbuf = false;
- glDisable(GL_DEPTH_TEST);
- }
+ /* Only 100% compliant on new spec goes bellow */
+ DRW_draw_view(C);
+}
- if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
- GPU_free_images_old();
+RenderEngineType *ED_view3d_engine_type(Scene *scene, int drawtype)
+{
+ /*
+ * Tempory viewport draw modes until we have a proper system.
+ * all modes are done in the draw manager, except
+ * cycles material as it is an external render engine.
+ */
+ if (strcmp(scene->r.engine, RE_engine_id_CYCLES) == 0 && drawtype == OB_MATERIAL) {
+ return RE_engines_find(RE_engine_id_BLENDER_EEVEE);
}
+ return RE_engines_find(scene->r.engine);
}
-static void view3d_main_region_setup_view(
- Scene *scene, View3D *v3d, ARegion *ar, float viewmat[4][4], float winmat[4][4], const rcti *rect)
+void view3d_main_region_draw(const bContext *C, ARegion *ar)
{
- RegionView3D *rv3d = ar->regiondata;
+ View3D *v3d = CTX_wm_view3d(C);
- ED_view3d_update_viewmat(scene, v3d, ar, viewmat, winmat, rect);
+ view3d_draw_view(C, ar);
- /* set for opengl */
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixf(rv3d->winmat);
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(rv3d->viewmat);
-}
+ GPU_free_images_old();
+ GPU_pass_cache_garbage_collect();
-/**
- * Store values from #RegionView3D, set when drawing.
- * This is needed when we draw with to a viewport using a different matrix (offscreen drawing for example).
- *
- * Values set by #ED_view3d_update_viewmat should be handled here.
- */
-struct RV3DMatrixStore {
- float winmat[4][4];
- float viewmat[4][4];
- float viewinv[4][4];
- float persmat[4][4];
- float persinv[4][4];
- float viewcamtexcofac[4];
- float pixsize;
-};
-
-struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d)
-{
- struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__);
- copy_m4_m4(rv3dmat->winmat, rv3d->winmat);
- copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat);
- copy_m4_m4(rv3dmat->persmat, rv3d->persmat);
- copy_m4_m4(rv3dmat->persinv, rv3d->persinv);
- copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv);
- copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac);
- rv3dmat->pixsize = rv3d->pixsize;
- return (void *)rv3dmat;
-}
+ /* XXX This is in order to draw UI batches with the DRW
+ * olg context since we now use it for drawing the entire area */
+ gpu_batch_presets_reset();
-void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat)
-{
- copy_m4_m4(rv3d->winmat, rv3dmat->winmat);
- copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat);
- copy_m4_m4(rv3d->persmat, rv3dmat->persmat);
- copy_m4_m4(rv3d->persinv, rv3dmat->persinv);
- copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv);
- copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac);
- rv3d->pixsize = rv3dmat->pixsize;
-}
+ /* No depth test for drawing action zones afterwards. */
+ glDisable(GL_DEPTH_TEST);
-void ED_view3d_draw_offscreen_init(Scene *scene, View3D *v3d)
-{
- /* shadow buffers, before we setup matrices */
- if (draw_glsl_material(scene, NULL, v3d, v3d->drawtype))
- gpu_update_lamps_shadows_world(scene, v3d);
+ v3d->flag |= V3D_INVALID_BACKBUF;
}
-/*
- * Function to clear the view
- */
-static void view3d_main_region_clear(Scene *scene, View3D *v3d, ARegion *ar)
-{
- if (scene->world && (v3d->flag3 & V3D_SHOW_WORLD)) {
- RegionView3D *rv3d = ar->regiondata;
- GPUMaterial *gpumat = GPU_material_world(scene, scene->world);
+/* -------------------------------------------------------------------- */
- /* calculate full shader for background */
- GPU_material_bind(gpumat, 1, 1, 1.0, false, rv3d->viewmat, rv3d->viewinv, rv3d->viewcamtexcofac, (v3d->scenelock != 0));
-
- bool material_not_bound = !GPU_material_bound(gpumat);
-
- if (material_not_bound) {
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
- glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
- }
+/** \name Offscreen Drawing
+ * \{ */
- /* Draw world */
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_ALWAYS);
- glBegin(GL_TRIANGLE_STRIP);
- glVertex3f(-1.0, -1.0, 1.0);
- glVertex3f(1.0, -1.0, 1.0);
- glVertex3f(-1.0, 1.0, 1.0);
- glVertex3f(1.0, 1.0, 1.0);
- glEnd();
-
- if (material_not_bound) {
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- }
+static void view3d_stereo3d_setup_offscreen(
+ Depsgraph *depsgraph, Scene *scene, View3D *v3d, ARegion *ar,
+ float winmat[4][4], const char *viewname)
+{
+ /* update the viewport matrices with the new camera */
+ if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
+ float viewmat[4][4];
+ const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
- GPU_material_unbind(gpumat);
-
- glDepthFunc(GL_LEQUAL);
- glDisable(GL_DEPTH_TEST);
+ BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
+ view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
}
- else {
- if (UI_GetThemeValue(TH_SHOW_BACK_GRAD)) {
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_ALWAYS);
- glBegin(GL_QUADS);
- UI_ThemeColor(TH_LOW_GRAD);
- glVertex3f(-1.0, -1.0, 1.0);
- glVertex3f(1.0, -1.0, 1.0);
- UI_ThemeColor(TH_HIGH_GRAD);
- glVertex3f(1.0, 1.0, 1.0);
- glVertex3f(-1.0, 1.0, 1.0);
- glEnd();
- glDepthFunc(GL_LEQUAL);
- glDisable(GL_DEPTH_TEST);
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
-
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- }
- else {
- UI_ThemeClearColorAlpha(TH_HIGH_GRAD, 1.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
+ else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
+ float viewmat[4][4];
+ Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
+
+ BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
+ view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
}
}
-/* ED_view3d_draw_offscreen_init should be called before this to initialize
- * stuff like shadow buffers
- */
void ED_view3d_draw_offscreen(
- Scene *scene, View3D *v3d, ARegion *ar, int winx, int winy,
+ Depsgraph *depsgraph, Scene *scene,
+ int drawtype,
+ View3D *v3d, ARegion *ar, int winx, int winy,
float viewmat[4][4], float winmat[4][4],
- bool do_bgpic, bool do_sky, bool is_persp, const char *viewname,
- GPUFX *fx, GPUFXSettings *fx_settings,
- GPUOffScreen *ofs)
+ bool do_sky, bool UNUSED(is_persp), const char *viewname,
+ GPUFXSettings *UNUSED(fx_settings),
+ GPUOffScreen *ofs, GPUViewport *viewport)
{
- struct bThemeState theme_state;
- int bwinx, bwiny;
- rcti brect;
- bool do_compositing = false;
RegionView3D *rv3d = ar->regiondata;
-
- glPushMatrix();
+ RenderEngineType *engine_type = ED_view3d_engine_type(scene, drawtype);
/* set temporary new size */
- bwinx = ar->winx;
- bwiny = ar->winy;
- brect = ar->winrct;
+ int bwinx = ar->winx;
+ int bwiny = ar->winy;
+ rcti brect = ar->winrct;
ar->winx = winx;
ar->winy = winy;
@@ -3193,6 +1326,7 @@ void ED_view3d_draw_offscreen(
ar->winrct.xmax = winx;
ar->winrct.ymax = winy;
+ struct bThemeState theme_state;
UI_Theme_Store(&theme_state);
UI_SetTheme(SPACE_VIEW3D, RGN_TYPE_WINDOW);
@@ -3205,66 +1339,28 @@ void ED_view3d_draw_offscreen(
GPU_free_images_anim();
}
- /* setup view matrices before fx or unbinding the offscreen buffers will cause issues */
+ gpuPushProjectionMatrix();
+ gpuLoadIdentity();
+ gpuPushMatrix();
+ gpuLoadIdentity();
+
if ((viewname != NULL && viewname[0] != '\0') && (viewmat == NULL) && rv3d->persp == RV3D_CAMOB && v3d->camera)
- view3d_stereo3d_setup_offscreen(scene, v3d, ar, winmat, viewname);
+ view3d_stereo3d_setup_offscreen(depsgraph, scene, v3d, ar, winmat, viewname);
else
- view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, NULL);
-
- /* framebuffer fx needed, we need to draw offscreen first */
- if (v3d->fx_settings.fx_flag && fx) {
- GPUSSAOSettings *ssao = NULL;
-
- if (v3d->drawtype < OB_SOLID) {
- ssao = v3d->fx_settings.ssao;
- v3d->fx_settings.ssao = NULL;
- }
-
- do_compositing = GPU_fx_compositor_initialize_passes(fx, &ar->winrct, NULL, fx_settings);
-
- if (ssao)
- v3d->fx_settings.ssao = ssao;
- }
-
- /* clear opengl buffers */
- if (do_sky) {
- view3d_main_region_clear(scene, v3d, ar);
- }
- else {
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- }
+ view3d_main_region_setup_view(depsgraph, scene, v3d, ar, viewmat, winmat, NULL);
/* main drawing call */
- view3d_draw_objects(NULL, scene, v3d, ar, NULL, do_bgpic, true, do_compositing ? fx : NULL);
-
- /* post process */
- if (do_compositing) {
- if (!winmat)
- is_persp = rv3d->is_persp;
- GPU_fx_do_composite_pass(fx, winmat, is_persp, scene, ofs);
- }
-
- if ((v3d->flag2 & V3D_RENDER_SHADOW) == 0) {
- /* draw grease-pencil stuff */
- ED_region_pixelspace(ar);
-
-
- if (v3d->flag2 & V3D_SHOW_GPENCIL) {
- /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */
- ED_gpencil_draw_view3d(NULL, scene, v3d, ar, false);
- }
-
- /* freeing the images again here could be done after the operator runs, leaving for now */
- GPU_free_images_anim();
- }
+ DRW_draw_render_loop_offscreen(
+ depsgraph, engine_type, ar, v3d,
+ do_sky, ofs, viewport);
/* restore size */
ar->winx = bwinx;
ar->winy = bwiny;
ar->winrct = brect;
- glPopMatrix();
+ gpuPopProjectionMatrix();
+ gpuPopMatrix();
UI_Theme_Restore(&theme_state);
@@ -3272,39 +1368,22 @@ void ED_view3d_draw_offscreen(
}
/**
- * Set the correct matrices
- */
-void ED_view3d_draw_setup_view(
- wmWindow *win, Scene *scene, ARegion *ar, View3D *v3d, float viewmat[4][4], float winmat[4][4], const rcti *rect)
-{
- RegionView3D *rv3d = ar->regiondata;
-
- /* Setup the view matrix. */
- if (view3d_stereo3d_active(win, scene, v3d, rv3d)) {
- view3d_stereo3d_setup(scene, v3d, ar, rect);
- }
- else {
- view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, rect);
- }
-}
-
-/**
* Utility func for ED_view3d_draw_offscreen
*
* \param ofs: Optional off-screen buffer, can be NULL.
* (avoids re-creating when doing multiple GL renders).
*/
ImBuf *ED_view3d_draw_offscreen_imbuf(
- Scene *scene, View3D *v3d, ARegion *ar, int sizex, int sizey,
+ Depsgraph *depsgraph, Scene *scene,
+ int drawtype,
+ View3D *v3d, ARegion *ar, int sizex, int sizey,
unsigned int flag, unsigned int draw_flags,
int alpha_mode, int samples, const char *viewname,
/* output vars */
- GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
+ GPUOffScreen *ofs, char err_out[256])
{
RegionView3D *rv3d = ar->regiondata;
- ImBuf *ibuf;
const bool draw_sky = (alpha_mode == R_ADDSKY);
- const bool draw_background = (draw_flags & V3D_OFSDRAW_USE_BACKGROUND);
const bool use_full_sample = (draw_flags & V3D_OFSDRAW_USE_FULL_SAMPLE);
/* view state */
@@ -3318,21 +1397,21 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
}
const bool own_ofs = (ofs == NULL);
+ DRW_opengl_context_enable();
if (own_ofs) {
/* bind */
- ofs = GPU_offscreen_create(sizex, sizey, use_full_sample ? 0 : samples, err_out);
+ ofs = GPU_offscreen_create(sizex, sizey, use_full_sample ? 0 : samples, true, false, err_out);
if (ofs == NULL) {
+ DRW_opengl_context_disable();
return NULL;
}
}
- ED_view3d_draw_offscreen_init(scene, v3d);
-
GPU_offscreen_bind(ofs, true);
/* read in pixels & stamp */
- ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
+ ImBuf *ibuf = IMB_allocImBuf(sizex, sizey, 32, flag);
/* render 3d view */
if (rv3d->persp == RV3D_CAMOB && v3d->camera) {
@@ -3357,7 +1436,7 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
rctf viewplane;
float clipsta, clipend;
- is_ortho = ED_view3d_viewplane_get(v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
+ is_ortho = ED_view3d_viewplane_get(depsgraph, v3d, rv3d, sizex, sizey, &viewplane, &clipsta, &clipend, NULL);
if (is_ortho) {
orthographic_m4(winmat, viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, -clipend, clipend);
}
@@ -3369,9 +1448,10 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
if ((samples && use_full_sample) == 0) {
/* Single-pass render, common case */
ED_view3d_draw_offscreen(
- scene, v3d, ar, sizex, sizey, NULL, winmat,
- draw_background, draw_sky, !is_ortho, viewname,
- fx, &fx_settings, ofs);
+ depsgraph, scene, drawtype,
+ v3d, ar, sizex, sizey, NULL, winmat,
+ draw_sky, !is_ortho, viewname,
+ &fx_settings, ofs, NULL);
if (ibuf->rect_float) {
GPU_offscreen_read_pixels(ofs, GL_FLOAT, ibuf->rect_float);
@@ -3385,28 +1465,22 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
* Use because OpenGL may use a lower quality MSAA, and only over-sample edges. */
static float jit_ofs[32][2];
float winmat_jitter[4][4];
- /* use imbuf as temp storage, before writing into it from accumulation buffer */
- unsigned char *rect_temp = ibuf->rect ? (void *)ibuf->rect : (void *)ibuf->rect_float;
- unsigned int *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(int[4]), "accum1");
- unsigned int i;
- int j;
+ float *rect_temp = (ibuf->rect_float) ? ibuf->rect_float : MEM_mallocN(sizex * sizey * sizeof(float[4]), "rect_temp");
+ float *accum_buffer = MEM_mallocN(sizex * sizey * sizeof(float[4]), "accum_buffer");
+ GPUViewport *viewport = GPU_viewport_create_from_offscreen(ofs);
BLI_jitter_init(jit_ofs, samples);
/* first sample buffer, also initializes 'rv3d->persmat' */
ED_view3d_draw_offscreen(
- scene, v3d, ar, sizex, sizey, NULL, winmat,
- draw_background, draw_sky, !is_ortho, viewname,
- fx, &fx_settings, ofs);
- GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp);
-
- i = sizex * sizey * 4;
- while (i--) {
- accum_buffer[i] = rect_temp[i];
- }
+ depsgraph, scene, drawtype,
+ v3d, ar, sizex, sizey, NULL, winmat,
+ draw_sky, !is_ortho, viewname,
+ &fx_settings, ofs, viewport);
+ GPU_offscreen_read_pixels(ofs, GL_FLOAT, accum_buffer);
/* skip the first sample */
- for (j = 1; j < samples; j++) {
+ for (int j = 1; j < samples; j++) {
copy_m4_m4(winmat_jitter, winmat);
window_translate_m4(
winmat_jitter, rv3d->persmat,
@@ -3414,29 +1488,40 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
(jit_ofs[j][1] * 2.0f) / sizey);
ED_view3d_draw_offscreen(
- scene, v3d, ar, sizex, sizey, NULL, winmat_jitter,
- draw_background, draw_sky, !is_ortho, viewname,
- fx, &fx_settings, ofs);
- GPU_offscreen_read_pixels(ofs, GL_UNSIGNED_BYTE, rect_temp);
+ depsgraph, scene, drawtype,
+ v3d, ar, sizex, sizey, NULL, winmat_jitter,
+ draw_sky, !is_ortho, viewname,
+ &fx_settings, ofs, viewport);
+ GPU_offscreen_read_pixels(ofs, GL_FLOAT, rect_temp);
- i = sizex * sizey * 4;
+ unsigned int i = sizex * sizey * 4;
while (i--) {
accum_buffer[i] += rect_temp[i];
}
}
+ {
+ /* don't free data owned by 'ofs' */
+ GPU_viewport_clear_from_offscreen(viewport);
+ GPU_viewport_free(viewport);
+ }
+
+ if (ibuf->rect_float == NULL) {
+ MEM_freeN(rect_temp);
+ }
+
if (ibuf->rect_float) {
float *rect_float = ibuf->rect_float;
- i = sizex * sizey * 4;
+ unsigned int i = sizex * sizey * 4;
while (i--) {
- rect_float[i] = (float)(accum_buffer[i] / samples) * (1.0f / 255.0f);
+ rect_float[i] = accum_buffer[i] / samples;
}
}
else {
unsigned char *rect_ub = (unsigned char *)ibuf->rect;
- i = sizex * sizey * 4;
+ unsigned int i = sizex * sizey * 4;
while (i--) {
- rect_ub[i] = accum_buffer[i] / samples;
+ rect_ub[i] = (unsigned char)(255.0f * accum_buffer[i] / samples);
}
}
@@ -3450,6 +1535,8 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
GPU_offscreen_free(ofs);
}
+ DRW_opengl_context_disable();
+
if (ibuf->rect_float && ibuf->rect)
IMB_rect_from_float(ibuf);
@@ -3465,10 +1552,12 @@ ImBuf *ED_view3d_draw_offscreen_imbuf(
* \note used by the sequencer
*/
ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
- Scene *scene, Object *camera, int width, int height,
- unsigned int flag, unsigned int draw_flags, int drawtype,
+ Depsgraph *depsgraph, Scene *scene,
+ int drawtype,
+ Object *camera, int width, int height,
+ unsigned int flag, unsigned int draw_flags,
int alpha_mode, int samples, const char *viewname,
- GPUFX *fx, GPUOffScreen *ofs, char err_out[256])
+ GPUOffScreen *ofs, char err_out[256])
{
View3D v3d = {NULL};
ARegion ar = {NULL};
@@ -3490,9 +1579,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
if (draw_flags & V3D_OFSDRAW_USE_SOLID_TEX) {
v3d.flag2 |= V3D_SOLID_TEX;
}
- if (draw_flags & V3D_OFSDRAW_USE_BACKGROUND) {
- v3d.flag3 |= V3D_SHOW_WORLD;
- }
+
+ v3d.flag3 |= V3D_SHOW_WORLD;
+
if (draw_flags & V3D_OFSDRAW_USE_CAMERA_DOF) {
if (camera->type == OB_CAMERA) {
v3d.fx_settings.dof = &((Camera *)camera->data)->gpu_dof;
@@ -3526,670 +1615,9 @@ ImBuf *ED_view3d_draw_offscreen_imbuf_simple(
invert_m4_m4(rv3d.persinv, rv3d.viewinv);
return ED_view3d_draw_offscreen_imbuf(
- scene, &v3d, &ar, width, height, flag, draw_flags,
- alpha_mode, samples, viewname, fx, ofs, err_out);
-}
-
-
-/**
- * \note The info that this uses is updated in #ED_refresh_viewport_fps,
- * which currently gets called during #SCREEN_OT_animation_step.
- */
-void ED_scene_draw_fps(Scene *scene, const rcti *rect)
-{
- ScreenFrameRateInfo *fpsi = scene->fps_info;
- float fps;
- char printable[16];
- int i, tot;
-
- if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime)
- return;
-
- printable[0] = '\0';
-
-#if 0
- /* this is too simple, better do an average */
- fps = (float)(1.0 / (fpsi->lredrawtime - fpsi->redrawtime))
-#else
- fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 / (fpsi->lredrawtime - fpsi->redrawtime));
-
- for (i = 0, tot = 0, fps = 0.0f; i < REDRAW_FRAME_AVERAGE; i++) {
- if (fpsi->redrawtimes_fps[i]) {
- fps += fpsi->redrawtimes_fps[i];
- tot++;
- }
- }
- if (tot) {
- fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE;
-
- //fpsi->redrawtime_index++;
- //if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE)
- // fpsi->redrawtime = 0;
-
- fps = fps / tot;
- }
-#endif
-
- /* is this more than half a frame behind? */
- if (fps + 0.5f < (float)(FPS)) {
- UI_ThemeColor(TH_REDALERT);
- BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps);
- }
- else {
- UI_ThemeColor(TH_TEXT_HI);
- BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), (int)(fps + 0.5f));
- }
-
-#ifdef WITH_INTERNATIONAL
- BLF_draw_default(rect->xmin + U.widget_unit, rect->ymax - U.widget_unit, 0.0f, printable, sizeof(printable));
-#else
- BLF_draw_default_ascii(rect->xmin + U.widget_unit, rect->ymax - U.widget_unit, 0.0f, printable, sizeof(printable));
-#endif
-}
-
-static bool view3d_main_region_do_render_draw(const Scene *scene)
-{
- RenderEngineType *type = RE_engines_find(scene->r.engine);
-
- return (type && type->view_update && type->view_draw);
-}
-
-bool ED_view3d_calc_render_border(
- const Scene *scene, const View3D *v3d, const ARegion *ar,
- rcti *rect)
-{
- RegionView3D *rv3d = ar->regiondata;
- rctf viewborder;
- bool use_border;
-
- /* test if there is a 3d view rendering */
- if (v3d->drawtype != OB_RENDER || !view3d_main_region_do_render_draw(scene))
- return false;
-
- /* test if there is a border render */
- if (rv3d->persp == RV3D_CAMOB)
- use_border = (scene->r.mode & R_BORDER) != 0;
- else
- use_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0;
-
- if (!use_border)
- return false;
-
- /* compute border */
- if (rv3d->persp == RV3D_CAMOB) {
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &viewborder, false);
-
- rect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder);
- rect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder);
- rect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder);
- rect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder);
- }
- else {
- rect->xmin = v3d->render_border.xmin * ar->winx;
- rect->xmax = v3d->render_border.xmax * ar->winx;
- rect->ymin = v3d->render_border.ymin * ar->winy;
- rect->ymax = v3d->render_border.ymax * ar->winy;
- }
-
- BLI_rcti_translate(rect, ar->winrct.xmin, ar->winrct.ymin);
- BLI_rcti_isect(&ar->winrct, rect, rect);
-
- return true;
-}
-
-static bool view3d_main_region_draw_engine(const bContext *C, Scene *scene,
- ARegion *ar, View3D *v3d,
- bool clip_border, const rcti *border_rect)
-{
- RegionView3D *rv3d = ar->regiondata;
- RenderEngineType *type;
- GLint scissor[4];
-
- /* create render engine */
- if (!rv3d->render_engine) {
- RenderEngine *engine;
-
- type = RE_engines_find(scene->r.engine);
-
- if (!(type->view_update && type->view_draw))
- return false;
-
- engine = RE_engine_create_ex(type, true);
-
- engine->tile_x = scene->r.tilex;
- engine->tile_y = scene->r.tiley;
-
- type->view_update(engine, C);
-
- rv3d->render_engine = engine;
- }
-
- /* setup view matrices */
- view3d_main_region_setup_view(scene, v3d, ar, NULL, NULL, NULL);
-
- /* background draw */
- ED_region_pixelspace(ar);
-
- if (clip_border) {
- /* for border draw, we only need to clear a subset of the 3d view */
- if (border_rect->xmax > border_rect->xmin && border_rect->ymax > border_rect->ymin) {
- glGetIntegerv(GL_SCISSOR_BOX, scissor);
- glScissor(border_rect->xmin, border_rect->ymin,
- BLI_rcti_size_x(border_rect), BLI_rcti_size_y(border_rect));
- }
- else {
- return false;
- }
- }
-
- glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- if (v3d->flag & V3D_DISPBGPICS)
- view3d_draw_bgpic_test(scene, ar, v3d, false, true);
- else
- fdrawcheckerboard(0, 0, ar->winx, ar->winy);
-
- /* render result draw */
- type = rv3d->render_engine->type;
- type->view_draw(rv3d->render_engine, C);
-
- if (v3d->flag & V3D_DISPBGPICS)
- view3d_draw_bgpic_test(scene, ar, v3d, true, true);
-
- if (clip_border) {
- /* restore scissor as it was before */
- glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
- }
-
- return true;
-}
-
-static void view3d_main_region_draw_engine_info(View3D *v3d, RegionView3D *rv3d, ARegion *ar, bool render_border)
-{
- float fill_color[4] = {0.0f, 0.0f, 0.0f, 0.25f};
-
- if (!rv3d->render_engine || !rv3d->render_engine->text[0])
- return;
-
- if (render_border) {
- /* draw darkened background color. no alpha because border render does
- * partial redraw and will not redraw the region behind this info bar */
- float alpha = 1.0f - fill_color[3];
- Camera *camera = ED_view3d_camera_data_get(v3d, rv3d);
-
- if (camera) {
- if (camera->flag & CAM_SHOWPASSEPARTOUT) {
- alpha *= (1.0f - camera->passepartalpha);
- }
- }
-
- UI_GetThemeColor3fv(TH_HIGH_GRAD, fill_color);
- mul_v3_fl(fill_color, alpha);
- fill_color[3] = 1.0f;
- }
-
- ED_region_info_draw(ar, rv3d->render_engine->text, fill_color, true);
-}
-
-static bool view3d_stereo3d_active(wmWindow *win, Scene *scene, View3D *v3d, RegionView3D *rv3d)
-{
- if ((scene->r.scemode & R_MULTIVIEW) == 0) {
- return false;
- }
-
- if ((v3d->camera == NULL) || (v3d->camera->type != OB_CAMERA) || rv3d->persp != RV3D_CAMOB) {
- return false;
- }
-
- switch (v3d->stereo3d_camera) {
- case STEREO_MONO_ID:
- return false;
- break;
- case STEREO_3D_ID:
- /* win will be NULL when calling this from the selection or draw loop. */
- if ((win == NULL) || (WM_stereo3d_enabled(win, true) == false)) {
- return false;
- }
- if (((scene->r.views_format & SCE_VIEWS_FORMAT_MULTIVIEW) != 0) &&
- !BKE_scene_multiview_is_stereo3d(&scene->r))
- {
- return false;
- }
- break;
- /* We always need the stereo calculation for left and right cameras. */
- case STEREO_LEFT_ID:
- case STEREO_RIGHT_ID:
- default:
- break;
- }
- return true;
-}
-
-/* setup the view and win matrices for the multiview cameras
- *
- * unlike view3d_stereo3d_setup_offscreen, when view3d_stereo3d_setup is called
- * we have no winmatrix (i.e., projection matrix) defined at that time.
- * Since the camera and the camera shift are needed for the winmat calculation
- * we do a small hack to replace it temporarily so we don't need to change the
- * view3d)main_region_setup_view() code to account for that.
- */
-static void view3d_stereo3d_setup(Scene *scene, View3D *v3d, ARegion *ar, const rcti *rect)
-{
- bool is_left;
- const char *names[2] = {STEREO_LEFT_NAME, STEREO_RIGHT_NAME};
- const char *viewname;
-
- /* show only left or right camera */
- if (v3d->stereo3d_camera != STEREO_3D_ID)
- v3d->multiview_eye = v3d->stereo3d_camera;
-
- is_left = v3d->multiview_eye == STEREO_LEFT_ID;
- viewname = names[is_left ? STEREO_LEFT_ID : STEREO_RIGHT_ID];
-
- /* update the viewport matrices with the new camera */
- if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
- Camera *data;
- float viewmat[4][4];
- float shiftx;
-
- data = (Camera *)v3d->camera->data;
- shiftx = data->shiftx;
-
- BLI_thread_lock(LOCK_VIEW3D);
- data->shiftx = BKE_camera_multiview_shift_x(&scene->r, v3d->camera, viewname);
-
- BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
- view3d_main_region_setup_view(scene, v3d, ar, viewmat, NULL, rect);
-
- data->shiftx = shiftx;
- BLI_thread_unlock(LOCK_VIEW3D);
- }
- else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
- float viewmat[4][4];
- Object *view_ob = v3d->camera;
- Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
-
- BLI_thread_lock(LOCK_VIEW3D);
- v3d->camera = camera;
-
- BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
- view3d_main_region_setup_view(scene, v3d, ar, viewmat, NULL, rect);
-
- v3d->camera = view_ob;
- BLI_thread_unlock(LOCK_VIEW3D);
- }
-}
-
-static void view3d_stereo3d_setup_offscreen(Scene *scene, View3D *v3d, ARegion *ar,
- float winmat[4][4], const char *viewname)
-{
- /* update the viewport matrices with the new camera */
- if (scene->r.views_format == SCE_VIEWS_FORMAT_STEREO_3D) {
- float viewmat[4][4];
- const bool is_left = STREQ(viewname, STEREO_LEFT_NAME);
-
- BKE_camera_multiview_view_matrix(&scene->r, v3d->camera, is_left, viewmat);
- view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, NULL);
- }
- else { /* SCE_VIEWS_FORMAT_MULTIVIEW */
- float viewmat[4][4];
- Object *camera = BKE_camera_multiview_render(scene, v3d->camera, viewname);
-
- BKE_camera_multiview_view_matrix(&scene->r, camera, false, viewmat);
- view3d_main_region_setup_view(scene, v3d, ar, viewmat, winmat, NULL);
- }
-}
-
-#ifdef WITH_GAMEENGINE
-static void update_lods(Scene *scene, float camera_pos[3])
-{
- Scene *sce_iter;
- Base *base;
- Object *ob;
-
- for (SETLOOPER(scene, sce_iter, base)) {
- ob = base->object;
- BKE_object_lod_update(ob, camera_pos);
- }
+ depsgraph, scene, drawtype,
+ &v3d, &ar, width, height, flag,
+ draw_flags, alpha_mode, samples, viewname, ofs, err_out);
}
-#endif
-
-static void view3d_main_region_draw_objects(const bContext *C, Scene *scene, View3D *v3d,
- ARegion *ar, const char **grid_unit)
-{
- wmWindow *win = CTX_wm_window(C);
- RegionView3D *rv3d = ar->regiondata;
- unsigned int lay_used = v3d->lay_used;
-
- /* post processing */
- bool do_compositing = false;
-
- /* shadow buffers, before we setup matrices */
- if (draw_glsl_material(scene, NULL, v3d, v3d->drawtype))
- gpu_update_lamps_shadows_world(scene, v3d);
-
- /* reset default OpenGL lights if needed (i.e. after preferences have been altered) */
- if (rv3d->rflag & RV3D_GPULIGHT_UPDATE) {
- rv3d->rflag &= ~RV3D_GPULIGHT_UPDATE;
- GPU_default_lights();
- }
-
- /* Setup the view matrix. */
- ED_view3d_draw_setup_view(CTX_wm_window(C), scene, ar, v3d, NULL, NULL, NULL);
-
- rv3d->rflag &= ~RV3D_IS_GAME_ENGINE;
-#ifdef WITH_GAMEENGINE
- if (STREQ(scene->r.engine, RE_engine_id_BLENDER_GAME)) {
- rv3d->rflag |= RV3D_IS_GAME_ENGINE;
-
- /* Make sure LoDs are up to date */
- update_lods(scene, rv3d->viewinv[3]);
- }
-#endif
-
- /* framebuffer fx needed, we need to draw offscreen first */
- if (v3d->fx_settings.fx_flag && v3d->drawtype >= OB_SOLID) {
- GPUFXSettings fx_settings;
- BKE_screen_gpu_fx_validate(&v3d->fx_settings);
- fx_settings = v3d->fx_settings;
- if (!rv3d->compositor)
- rv3d->compositor = GPU_fx_compositor_create();
-
- if (rv3d->persp == RV3D_CAMOB && v3d->camera)
- BKE_camera_to_gpu_dof(v3d->camera, &fx_settings);
- else {
- fx_settings.dof = NULL;
- }
-
- do_compositing = GPU_fx_compositor_initialize_passes(rv3d->compositor, &ar->winrct, &ar->drawrct, &fx_settings);
- }
-
- /* clear the background */
- view3d_main_region_clear(scene, v3d, ar);
- /* enables anti-aliasing for 3D view drawing */
- if (win->multisamples != USER_MULTISAMPLE_NONE) {
- glEnable(GL_MULTISAMPLE);
- }
-
- /* main drawing call */
- view3d_draw_objects(C, scene, v3d, ar, grid_unit, true, false, do_compositing ? rv3d->compositor : NULL);
-
- /* post process */
- if (do_compositing) {
- GPU_fx_do_composite_pass(rv3d->compositor, rv3d->winmat, rv3d->is_persp, scene, NULL);
- }
-
- /* Disable back anti-aliasing */
- if (win->multisamples != USER_MULTISAMPLE_NONE) {
- glDisable(GL_MULTISAMPLE);
- }
-
- if (v3d->lay_used != lay_used) { /* happens when loading old files or loading with UI load */
- /* find header and force tag redraw */
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar_header = BKE_area_find_region_type(sa, RGN_TYPE_HEADER);
- ED_region_tag_redraw(ar_header); /* can be NULL */
- }
-
- if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
- BDR_drawSketch(C);
- }
-
-#ifdef WITH_INPUT_NDOF
- if ((U.ndof_flag & NDOF_SHOW_GUIDE) && ((rv3d->viewlock & RV3D_LOCKED) == 0) && (rv3d->persp != RV3D_CAMOB))
- /* TODO: draw something else (but not this) during fly mode */
- draw_rotation_guide(rv3d);
-#endif
-}
-
-static bool is_cursor_visible(Scene *scene)
-{
- if (U.app_flag & USER_APP_VIEW3D_HIDE_CURSOR) {
- return false;
- }
-
- Object *ob = OBACT;
-
- /* don't draw cursor in paint modes, but with a few exceptions */
- if (ob && ob->mode & OB_MODE_ALL_PAINT) {
- /* exception: object is in weight paint and has deforming armature in pose mode */
- if (ob->mode & OB_MODE_WEIGHT_PAINT) {
- if (BKE_object_pose_armature_get(ob) != NULL) {
- return true;
- }
- }
- /* exception: object in texture paint mode, clone brush, use_clone_layer disabled */
- else if (ob->mode & OB_MODE_TEXTURE_PAINT) {
- const Paint *p = BKE_paint_get_active(scene);
-
- if (p && p->brush && p->brush->imagepaint_tool == PAINT_TOOL_CLONE) {
- if ((scene->toolsettings->imapaint.flag & IMAGEPAINT_PROJECT_LAYER_CLONE) == 0) {
- return true;
- }
- }
- }
-
- /* no exception met? then don't draw cursor! */
- return false;
- }
-
- return true;
-}
-
-static void view3d_main_region_draw_info(const bContext *C, Scene *scene,
- ARegion *ar, View3D *v3d,
- const char *grid_unit, bool render_border)
-{
- wmWindowManager *wm = CTX_wm_manager(C);
- RegionView3D *rv3d = ar->regiondata;
- rcti rect;
-
- /* local coordinate visible rect inside region, to accomodate overlapping ui */
- ED_region_visible_rect(ar, &rect);
-
- if (rv3d->persp == RV3D_CAMOB) {
- drawviewborder(scene, ar, v3d);
- }
- else if (v3d->flag2 & V3D_RENDER_BORDER) {
- glLineWidth(1.0f);
- setlinestyle(3);
- cpack(0x4040FF);
-
- sdrawbox(v3d->render_border.xmin * ar->winx, v3d->render_border.ymin * ar->winy,
- v3d->render_border.xmax * ar->winx, v3d->render_border.ymax * ar->winy);
-
- setlinestyle(0);
- }
-
- if (v3d->flag2 & V3D_SHOW_GPENCIL) {
- /* draw grease-pencil stuff - needed to get paint-buffer shown too (since it's 2D) */
- ED_gpencil_draw_view3d(wm, scene, v3d, ar, false);
- }
-
- if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
- Object *ob;
-
- /* 3d cursor */
- if (is_cursor_visible(scene)) {
- drawcursor(scene, ar, v3d);
- }
-
- if (U.uiflag & USER_SHOW_ROTVIEWICON)
- draw_view_axis(rv3d, &rect);
- else
- draw_view_icon(rv3d, &rect);
-
- ob = OBACT;
- if (U.uiflag & USER_DRAWVIEWINFO)
- draw_selected_name(scene, ob, &rect);
- }
-
- if (rv3d->render_engine) {
- view3d_main_region_draw_engine_info(v3d, rv3d, ar, render_border);
- return;
- }
-
- if ((v3d->flag2 & V3D_RENDER_OVERRIDE) == 0) {
- if ((U.uiflag & USER_SHOW_FPS) && ED_screen_animation_no_scrub(wm)) {
- ED_scene_draw_fps(scene, &rect);
- }
- else if (U.uiflag & USER_SHOW_VIEWPORTNAME) {
- draw_viewport_name(ar, v3d, &rect);
- }
-
- if (grid_unit) { /* draw below the viewport name */
- char numstr[32] = "";
-
- UI_ThemeColor(TH_TEXT_HI);
- if (v3d->grid != 1.0f) {
- BLI_snprintf(numstr, sizeof(numstr), "%s x %.4g", grid_unit, v3d->grid);
- }
-
- BLF_draw_default_ascii(rect.xmin + U.widget_unit,
- rect.ymax - (USER_SHOW_VIEWPORTNAME ? 2 * U.widget_unit : U.widget_unit), 0.0f,
- numstr[0] ? numstr : grid_unit, sizeof(numstr));
- }
- }
-}
-
-void view3d_main_region_draw(const bContext *C, ARegion *ar)
-{
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = CTX_wm_view3d(C);
- const char *grid_unit = NULL;
- rcti border_rect;
- bool render_border, clip_border;
-
- /* if we only redraw render border area, skip opengl draw and also
- * don't do scissor because it's already set */
- render_border = ED_view3d_calc_render_border(scene, v3d, ar, &border_rect);
- clip_border = (render_border && !BLI_rcti_compare(&ar->drawrct, &border_rect));
-
- /* draw viewport using opengl */
- if (v3d->drawtype != OB_RENDER || !view3d_main_region_do_render_draw(scene) || clip_border) {
- view3d_main_region_draw_objects(C, scene, v3d, ar, &grid_unit);
-
-#ifdef DEBUG_DRAW
- bl_debug_draw();
-#endif
- if (G.debug & G_DEBUG_SIMDATA)
- draw_sim_debug_data(scene, v3d, ar);
-
- ED_region_pixelspace(ar);
- }
-
- /* draw viewport using external renderer */
- if (v3d->drawtype == OB_RENDER)
- view3d_main_region_draw_engine(C, scene, ar, v3d, clip_border, &border_rect);
-
- view3d_main_region_draw_info(C, scene, ar, v3d, grid_unit, render_border);
-
- v3d->flag |= V3D_INVALID_BACKBUF;
-
- BLI_assert(BLI_listbase_is_empty(&v3d->afterdraw_transp));
- BLI_assert(BLI_listbase_is_empty(&v3d->afterdraw_xray));
- BLI_assert(BLI_listbase_is_empty(&v3d->afterdraw_xraytransp));
-}
-
-#ifdef DEBUG_DRAW
-/* debug drawing */
-#define _DEBUG_DRAW_QUAD_TOT 1024
-#define _DEBUG_DRAW_EDGE_TOT 1024
-static float _bl_debug_draw_quads[_DEBUG_DRAW_QUAD_TOT][4][3];
-static int _bl_debug_draw_quads_tot = 0;
-static float _bl_debug_draw_edges[_DEBUG_DRAW_QUAD_TOT][2][3];
-static int _bl_debug_draw_edges_tot = 0;
-static unsigned int _bl_debug_draw_quads_color[_DEBUG_DRAW_QUAD_TOT];
-static unsigned int _bl_debug_draw_edges_color[_DEBUG_DRAW_EDGE_TOT];
-static unsigned int _bl_debug_draw_color;
-
-void bl_debug_draw_quad_clear(void)
-{
- _bl_debug_draw_quads_tot = 0;
- _bl_debug_draw_edges_tot = 0;
- _bl_debug_draw_color = 0x00FF0000;
-}
-void bl_debug_color_set(const unsigned int color)
-{
- _bl_debug_draw_color = color;
-}
-void bl_debug_draw_quad_add(const float v0[3], const float v1[3], const float v2[3], const float v3[3])
-{
- if (_bl_debug_draw_quads_tot >= _DEBUG_DRAW_QUAD_TOT) {
- printf("%s: max quad count hit %d!", __func__, _bl_debug_draw_quads_tot);
- }
- else {
- float *pt = &_bl_debug_draw_quads[_bl_debug_draw_quads_tot][0][0];
- copy_v3_v3(pt, v0); pt += 3;
- copy_v3_v3(pt, v1); pt += 3;
- copy_v3_v3(pt, v2); pt += 3;
- copy_v3_v3(pt, v3); pt += 3;
- _bl_debug_draw_quads_color[_bl_debug_draw_quads_tot] = _bl_debug_draw_color;
- _bl_debug_draw_quads_tot++;
- }
-}
-void bl_debug_draw_edge_add(const float v0[3], const float v1[3])
-{
- if (_bl_debug_draw_quads_tot >= _DEBUG_DRAW_EDGE_TOT) {
- printf("%s: max edge count hit %d!", __func__, _bl_debug_draw_edges_tot);
- }
- else {
- float *pt = &_bl_debug_draw_edges[_bl_debug_draw_edges_tot][0][0];
- copy_v3_v3(pt, v0); pt += 3;
- copy_v3_v3(pt, v1); pt += 3;
- _bl_debug_draw_edges_color[_bl_debug_draw_edges_tot] = _bl_debug_draw_color;
- _bl_debug_draw_edges_tot++;
- }
-}
-static void bl_debug_draw(void)
-{
- unsigned int color;
- if (_bl_debug_draw_quads_tot) {
- int i;
- color = _bl_debug_draw_quads_color[0];
- cpack(color);
- for (i = 0; i < _bl_debug_draw_quads_tot; i ++) {
- if (_bl_debug_draw_quads_color[i] != color) {
- color = _bl_debug_draw_quads_color[i];
- cpack(color);
- }
- glBegin(GL_LINE_LOOP);
- glVertex3fv(_bl_debug_draw_quads[i][0]);
- glVertex3fv(_bl_debug_draw_quads[i][1]);
- glVertex3fv(_bl_debug_draw_quads[i][2]);
- glVertex3fv(_bl_debug_draw_quads[i][3]);
- glEnd();
- }
- }
- if (_bl_debug_draw_edges_tot) {
- int i;
- color = _bl_debug_draw_edges_color[0];
- cpack(color);
- glBegin(GL_LINES);
- for (i = 0; i < _bl_debug_draw_edges_tot; i ++) {
- if (_bl_debug_draw_edges_color[i] != color) {
- color = _bl_debug_draw_edges_color[i];
- cpack(color);
- }
- glVertex3fv(_bl_debug_draw_edges[i][0]);
- glVertex3fv(_bl_debug_draw_edges[i][1]);
- }
- glEnd();
- color = _bl_debug_draw_edges_color[0];
- cpack(color);
- glPointSize(4.0);
- glBegin(GL_POINTS);
- for (i = 0; i < _bl_debug_draw_edges_tot; i ++) {
- if (_bl_debug_draw_edges_color[i] != color) {
- color = _bl_debug_draw_edges_color[i];
- cpack(color);
- }
- glVertex3fv(_bl_debug_draw_edges[i][0]);
- glVertex3fv(_bl_debug_draw_edges[i][1]);
- }
- glEnd();
- }
-}
-#endif
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_draw_legacy.c b/source/blender/editors/space_view3d/view3d_draw_legacy.c
new file mode 100644
index 00000000000..5b0f50b7a68
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_draw_legacy.c
@@ -0,0 +1,1071 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2008 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_draw_legacy.c
+ * \ingroup spview3d
+ */
+
+#include <string.h>
+#include <stdio.h>
+#include <math.h>
+
+#include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
+#include "DNA_customdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_group_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_key_types.h"
+#include "DNA_lamp_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_world_types.h"
+#include "DNA_brush_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_jitter_2d.h"
+#include "BLI_utildefines.h"
+#include "BLI_endian_switch.h"
+#include "BLI_threads.h"
+
+#include "BKE_anim.h"
+#include "BKE_camera.h"
+#include "BKE_context.h"
+#include "BKE_customdata.h"
+#include "BKE_DerivedMesh.h"
+#include "BKE_image.h"
+#include "BKE_key.h"
+#include "BKE_layer.h"
+#include "BKE_main.h"
+#include "BKE_object.h"
+#include "BKE_global.h"
+#include "BKE_paint.h"
+#include "BKE_scene.h"
+#include "BKE_screen.h"
+#include "BKE_unit.h"
+#include "BKE_movieclip.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "IMB_imbuf_types.h"
+#include "IMB_imbuf.h"
+#include "IMB_colormanagement.h"
+
+#include "BIF_glutil.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "BLF_api.h"
+#include "BLT_translation.h"
+
+#include "ED_armature.h"
+#include "ED_keyframing.h"
+#include "ED_gpencil.h"
+#include "ED_screen.h"
+#include "ED_space_api.h"
+#include "ED_screen_types.h"
+#include "ED_transform.h"
+
+#include "UI_interface.h"
+#include "UI_interface_icons.h"
+#include "UI_resources.h"
+
+#include "GPU_draw.h"
+#include "GPU_framebuffer.h"
+#include "GPU_material.h"
+#include "GPU_extensions.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_select.h"
+#include "GPU_matrix.h"
+
+#include "RE_engine.h"
+
+#include "DRW_engine.h"
+
+#include "view3d_intern.h" /* own include */
+
+/* ********* custom clipping *********** */
+
+void ED_view3d_clipping_set(RegionView3D *rv3d)
+{
+ double plane[4];
+ const unsigned int tot = (rv3d->viewlock & RV3D_BOXCLIP) ? 4 : 6;
+
+ for (unsigned a = 0; a < tot; a++) {
+ copy_v4db_v4fl(plane, rv3d->clip[a]);
+ glClipPlane(GL_CLIP_PLANE0 + a, plane);
+ glEnable(GL_CLIP_PLANE0 + a);
+ }
+}
+
+/* use these to temp disable/enable clipping when 'rv3d->rflag & RV3D_CLIPPING' is set */
+void ED_view3d_clipping_disable(void)
+{
+ for (unsigned a = 0; a < 6; a++) {
+ glDisable(GL_CLIP_PLANE0 + a);
+ }
+}
+void ED_view3d_clipping_enable(void)
+{
+ for (unsigned a = 0; a < 6; a++) {
+ glEnable(GL_CLIP_PLANE0 + a);
+ }
+}
+
+static bool view3d_clipping_test(const float co[3], const float clip[6][4])
+{
+ if (plane_point_side_v3(clip[0], co) > 0.0f)
+ if (plane_point_side_v3(clip[1], co) > 0.0f)
+ if (plane_point_side_v3(clip[2], co) > 0.0f)
+ if (plane_point_side_v3(clip[3], co) > 0.0f)
+ return false;
+
+ return true;
+}
+
+/* for 'local' ED_view3d_clipping_local must run first
+ * then all comparisons can be done in localspace */
+bool ED_view3d_clipping_test(const RegionView3D *rv3d, const float co[3], const bool is_local)
+{
+ return view3d_clipping_test(co, is_local ? rv3d->clip_local : rv3d->clip);
+}
+
+/* *********************** backdraw for selection *************** */
+
+static void backdrawview3d(
+ struct Depsgraph *depsgraph, Scene *scene,
+ ARegion *ar, View3D *v3d,
+ Object *obact, Object *obedit)
+{
+ RegionView3D *rv3d = ar->regiondata;
+ Scene *scene_eval = (Scene *)DEG_get_evaluated_id(depsgraph, &scene->id);
+ Object *obact_eval = DEG_get_evaluated_object(depsgraph, obact);
+
+ BLI_assert(ar->regiontype == RGN_TYPE_WINDOW);
+
+ if (obact_eval && (obact_eval->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT) ||
+ BKE_paint_select_face_test(obact_eval)))
+ {
+ /* do nothing */
+ }
+ /* texture paint mode sampling */
+ else if (obact_eval && (obact_eval->mode & OB_MODE_TEXTURE_PAINT) &&
+ (v3d->drawtype > OB_WIRE))
+ {
+ /* do nothing */
+ }
+ else if ((obact_eval && (obact_eval->mode & OB_MODE_PARTICLE_EDIT)) &&
+ V3D_IS_ZBUF(v3d))
+ {
+ /* do nothing */
+ }
+ else if ((obedit && (obedit->mode & OB_MODE_EDIT)) &&
+ V3D_IS_ZBUF(v3d))
+ {
+ /* do nothing */
+ }
+ else {
+ v3d->flag &= ~V3D_INVALID_BACKBUF;
+ return;
+ }
+
+ if (!(v3d->flag & V3D_INVALID_BACKBUF))
+ return;
+
+#if 0
+ if (test) {
+ if (qtest()) {
+ addafterqueue(ar->win, BACKBUFDRAW, 1);
+ return;
+ }
+ }
+#endif
+
+ if (v3d->drawtype > OB_WIRE) v3d->zbuf = true;
+
+ /* dithering and AA break color coding, so disable */
+ glDisable(GL_DITHER);
+
+ if (false) {
+ /* for multisample we use an offscreen FBO. multisample drawing can fail
+ * with color coded selection drawing, and reading back depths from such
+ * a buffer can also cause a few seconds freeze on OS X / NVidia.
+ *
+ * NOTE: code is no longer used now, but offscreen drawing is likely
+ * what we will always want to do for the new viewport. */
+ int w = BLI_rcti_size_x(&ar->winrct);
+ int h = BLI_rcti_size_y(&ar->winrct);
+ char error[256];
+
+ if (rv3d->gpuoffscreen) {
+ if (GPU_offscreen_width(rv3d->gpuoffscreen) != w ||
+ GPU_offscreen_height(rv3d->gpuoffscreen) != h)
+ {
+ GPU_offscreen_free(rv3d->gpuoffscreen);
+ rv3d->gpuoffscreen = NULL;
+ }
+ }
+
+ if (!rv3d->gpuoffscreen) {
+ rv3d->gpuoffscreen = GPU_offscreen_create(w, h, 0, true, false, error);
+
+ if (!rv3d->gpuoffscreen)
+ fprintf(stderr, "Failed to create offscreen selection buffer for multisample: %s\n", error);
+ }
+ }
+
+ if (rv3d->gpuoffscreen)
+ GPU_offscreen_bind(rv3d->gpuoffscreen, true);
+ else
+ glScissor(ar->winrct.xmin, ar->winrct.ymin, BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct));
+
+ glClearColor(0.0, 0.0, 0.0, 0.0);
+ if (v3d->zbuf) {
+ glEnable(GL_DEPTH_TEST);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ }
+ else {
+ glClear(GL_COLOR_BUFFER_BIT);
+ glDisable(GL_DEPTH_TEST);
+ }
+
+ if (rv3d->rflag & RV3D_CLIPPING)
+ ED_view3d_clipping_set(rv3d);
+
+ G.f |= G_BACKBUFSEL;
+
+ if (obact_eval && ((obact_eval->base_flag & BASE_VISIBLED) != 0)) {
+ draw_object_backbufsel(depsgraph, scene_eval, v3d, rv3d, obact_eval);
+ }
+
+ if (rv3d->gpuoffscreen)
+ GPU_offscreen_unbind(rv3d->gpuoffscreen, true);
+
+ v3d->flag &= ~V3D_INVALID_BACKBUF;
+
+ G.f &= ~G_BACKBUFSEL;
+ v3d->zbuf = false;
+ glDisable(GL_DEPTH_TEST);
+ glEnable(GL_DITHER);
+
+ if (rv3d->rflag & RV3D_CLIPPING)
+ ED_view3d_clipping_disable();
+}
+
+void view3d_opengl_read_pixels(ARegion *ar, int x, int y, int w, int h, int format, int type, void *data)
+{
+ RegionView3D *rv3d = ar->regiondata;
+
+ if (rv3d->gpuoffscreen) {
+ GPU_offscreen_bind(rv3d->gpuoffscreen, true);
+ glReadBuffer(GL_COLOR_ATTACHMENT0);
+ glReadPixels(x, y, w, h, format, type, data);
+ GPU_offscreen_unbind(rv3d->gpuoffscreen, true);
+ }
+ else {
+ glReadPixels(ar->winrct.xmin + x, ar->winrct.ymin + y, w, h, format, type, data);
+ }
+}
+
+/* XXX depth reading exception, for code not using gpu offscreen */
+static void view3d_opengl_read_Z_pixels(ARegion *ar, int x, int y, int w, int h, int format, int type, void *data)
+{
+ glReadPixels(ar->winrct.xmin + x, ar->winrct.ymin + y, w, h, format, type, data);
+}
+
+void ED_view3d_backbuf_validate(ViewContext *vc)
+{
+ if (vc->v3d->flag & V3D_INVALID_BACKBUF) {
+ backdrawview3d(vc->depsgraph, vc->scene, vc->ar, vc->v3d, vc->obact, vc->obedit);
+ }
+}
+
+/**
+ * allow for small values [0.5 - 2.5],
+ * and large values, FLT_MAX by clamping by the area size
+ */
+int ED_view3d_backbuf_sample_size_clamp(ARegion *ar, const float dist)
+{
+ return (int)min_ff(ceilf(dist), (float)max_ii(ar->winx, ar->winx));
+}
+
+/* samples a single pixel (copied from vpaint) */
+unsigned int ED_view3d_backbuf_sample(
+ ViewContext *vc, int x, int y)
+{
+ if (x >= vc->ar->winx || y >= vc->ar->winy) {
+ return 0;
+ }
+
+ ED_view3d_backbuf_validate(vc);
+
+ unsigned int col;
+ view3d_opengl_read_pixels(vc->ar, x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, &col);
+ glReadBuffer(GL_BACK);
+
+ if (ENDIAN_ORDER == B_ENDIAN) {
+ BLI_endian_switch_uint32(&col);
+ }
+
+ return GPU_select_to_index(col);
+}
+
+/* reads full rect, converts indices */
+ImBuf *ED_view3d_backbuf_read(
+ ViewContext *vc, int xmin, int ymin, int xmax, int ymax)
+{
+ /* clip */
+ const rcti clip = {
+ max_ii(xmin, 0), min_ii(xmax, vc->ar->winx - 1),
+ max_ii(ymin, 0), min_ii(ymax, vc->ar->winy - 1)};
+ const int size_clip[2] = {
+ BLI_rcti_size_x(&clip) + 1,
+ BLI_rcti_size_y(&clip) + 1};
+
+ if (UNLIKELY((clip.xmin > clip.xmax) ||
+ (clip.ymin > clip.ymax)))
+ {
+ return NULL;
+ }
+
+ ImBuf *ibuf_clip = IMB_allocImBuf(size_clip[0], size_clip[1], 32, IB_rect);
+
+ ED_view3d_backbuf_validate(vc);
+
+ view3d_opengl_read_pixels(vc->ar, clip.xmin, clip.ymin, size_clip[0], size_clip[1], GL_RGBA, GL_UNSIGNED_BYTE, ibuf_clip->rect);
+
+ glReadBuffer(GL_BACK);
+
+ if (ENDIAN_ORDER == B_ENDIAN) {
+ IMB_convert_rgba_to_abgr(ibuf_clip);
+ }
+
+ GPU_select_to_index_array(ibuf_clip->rect, size_clip[0] * size_clip[1]);
+
+ if ((clip.xmin == xmin) &&
+ (clip.xmax == xmax) &&
+ (clip.ymin == ymin) &&
+ (clip.ymax == ymax))
+ {
+ return ibuf_clip;
+ }
+ else {
+ /* put clipped result into a non-clipped buffer */
+ const int size[2] = {
+ (xmax - xmin + 1),
+ (ymax - ymin + 1)};
+
+ ImBuf *ibuf_full = IMB_allocImBuf(size[0], size[1], 32, IB_rect);
+
+ IMB_rectcpy(
+ ibuf_full, ibuf_clip,
+ clip.xmin - xmin, clip.ymin - ymin,
+ 0, 0,
+ size_clip[0], size_clip[1]);
+ IMB_freeImBuf(ibuf_clip);
+ return ibuf_full;
+ }
+}
+
+/* smart function to sample a rect spiralling outside, nice for backbuf selection */
+unsigned int ED_view3d_backbuf_sample_rect(
+ ViewContext *vc, const int mval[2], int size,
+ unsigned int min, unsigned int max, float *r_dist)
+{
+ int dirvec[4][2];
+
+ const int amount = (size - 1) / 2;
+
+ const int minx = mval[0] - (amount + 1);
+ const int miny = mval[1] - (amount + 1);
+ ImBuf *buf = ED_view3d_backbuf_read(vc, minx, miny, minx + size - 1, miny + size - 1);
+ if (!buf) return 0;
+
+ unsigned index = 0;
+ int rc = 0;
+
+ dirvec[0][0] = 1; dirvec[0][1] = 0;
+ dirvec[1][0] = 0; dirvec[1][1] = -size;
+ dirvec[2][0] = -1; dirvec[2][1] = 0;
+ dirvec[3][0] = 0; dirvec[3][1] = size;
+
+ const unsigned *bufmin = buf->rect;
+ const unsigned *tbuf = buf->rect;
+ const unsigned *bufmax = buf->rect + size * size;
+ tbuf += amount * size + amount;
+
+ for (int nr = 1; nr <= size; nr++) {
+ for (int a = 0; a < 2; a++) {
+ for (int b = 0; b < nr; b++) {
+ if (*tbuf && *tbuf >= min && *tbuf < max) {
+ /* we got a hit */
+
+ /* get x,y pixel coords from the offset
+ * (manhatten distance in keeping with other screen-based selection) */
+ *r_dist = (float)(
+ abs(((int)(tbuf - buf->rect) % size) - (size / 2)) +
+ abs(((int)(tbuf - buf->rect) / size) - (size / 2)));
+
+ /* indices start at 1 here */
+ index = (*tbuf - min) + 1;
+ goto exit;
+ }
+
+ tbuf += (dirvec[rc][0] + dirvec[rc][1]);
+
+ if (tbuf < bufmin || tbuf >= bufmax) {
+ goto exit;
+ }
+ }
+ rc++;
+ rc &= 3;
+ }
+ }
+
+exit:
+ IMB_freeImBuf(buf);
+ return index;
+}
+
+
+/* ************************************************************* */
+
+static void view3d_stereo_bgpic_setup(Scene *scene, View3D *v3d, Image *ima, ImageUser *iuser)
+{
+ if (BKE_image_is_stereo(ima)) {
+ iuser->flag |= IMA_SHOW_STEREO;
+
+ if ((scene->r.scemode & R_MULTIVIEW) == 0) {
+ iuser->multiview_eye = STEREO_LEFT_ID;
+ }
+ else if (v3d->stereo3d_camera != STEREO_3D_ID) {
+ /* show only left or right camera */
+ iuser->multiview_eye = v3d->stereo3d_camera;
+ }
+
+ BKE_image_multiview_index(ima, iuser);
+ }
+ else {
+ iuser->flag &= ~IMA_SHOW_STEREO;
+ }
+}
+
+static void view3d_draw_bgpic(Scene *scene, Depsgraph *depsgraph,
+ ARegion *ar, View3D *v3d,
+ const bool do_foreground, const bool do_camera_frame)
+{
+ RegionView3D *rv3d = ar->regiondata;
+ int fg_flag = do_foreground ? CAM_BGIMG_FLAG_FOREGROUND : 0;
+ if (v3d->camera == NULL || v3d->camera->type != OB_CAMERA) {
+ return;
+ }
+ Camera *cam = v3d->camera->data;
+
+ for (CameraBGImage *bgpic = cam->bg_images.first; bgpic; bgpic = bgpic->next) {
+ bgpic->iuser.scene = scene; /* Needed for render results. */
+
+ if ((bgpic->flag & CAM_BGIMG_FLAG_FOREGROUND) != fg_flag)
+ continue;
+
+ {
+ float image_aspect[2];
+ float x1, y1, x2, y2, centx, centy;
+
+ void *lock;
+
+ Image *ima = NULL;
+
+ /* disable individual images */
+ if ((bgpic->flag & CAM_BGIMG_FLAG_DISABLED))
+ continue;
+
+ ImBuf *ibuf = NULL;
+ ImBuf *freeibuf = NULL;
+ ImBuf *releaseibuf = NULL;
+ if (bgpic->source == CAM_BGIMG_SOURCE_IMAGE) {
+ ima = bgpic->ima;
+ if (ima == NULL)
+ continue;
+ BKE_image_user_frame_calc(&bgpic->iuser, CFRA, 0);
+ if (ima->source == IMA_SRC_SEQUENCE && !(bgpic->iuser.flag & IMA_USER_FRAME_IN_RANGE)) {
+ ibuf = NULL; /* frame is out of range, dont show */
+ }
+ else {
+ view3d_stereo_bgpic_setup(scene, v3d, ima, &bgpic->iuser);
+ ibuf = BKE_image_acquire_ibuf(ima, &bgpic->iuser, &lock);
+ releaseibuf = ibuf;
+ }
+
+ image_aspect[0] = ima->aspx;
+ image_aspect[1] = ima->aspy;
+ }
+ else if (bgpic->source == CAM_BGIMG_SOURCE_MOVIE) {
+ /* TODO: skip drawing when out of frame range (as image sequences do above) */
+ MovieClip *clip = NULL;
+
+ if (bgpic->flag & CAM_BGIMG_FLAG_CAMERACLIP) {
+ if (scene->camera)
+ clip = BKE_object_movieclip_get(scene, scene->camera, true);
+ }
+ else {
+ clip = bgpic->clip;
+ }
+
+ if (clip == NULL)
+ continue;
+
+ BKE_movieclip_user_set_frame(&bgpic->cuser, CFRA);
+ ibuf = BKE_movieclip_get_ibuf(clip, &bgpic->cuser);
+
+ image_aspect[0] = clip->aspx;
+ image_aspect[1] = clip->aspy;
+
+ /* working with ibuf from image and clip has got different workflow now.
+ * ibuf acquired from clip is referenced by cache system and should
+ * be dereferenced after usage. */
+ freeibuf = ibuf;
+ }
+ else {
+ /* perhaps when loading future files... */
+ BLI_assert(0);
+ copy_v2_fl(image_aspect, 1.0f);
+ }
+
+ if (ibuf == NULL)
+ continue;
+
+ if ((ibuf->rect == NULL && ibuf->rect_float == NULL) || ibuf->channels != 4) { /* invalid image format */
+ if (freeibuf)
+ IMB_freeImBuf(freeibuf);
+ if (releaseibuf)
+ BKE_image_release_ibuf(ima, releaseibuf, lock);
+
+ continue;
+ }
+
+ if (ibuf->rect == NULL)
+ IMB_rect_from_float(ibuf);
+
+ BLI_assert(rv3d->persp == RV3D_CAMOB);
+ {
+ if (do_camera_frame) {
+ rctf vb;
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &vb, false);
+ x1 = vb.xmin;
+ y1 = vb.ymin;
+ x2 = vb.xmax;
+ y2 = vb.ymax;
+ }
+ else {
+ x1 = ar->winrct.xmin;
+ y1 = ar->winrct.ymin;
+ x2 = ar->winrct.xmax;
+ y2 = ar->winrct.ymax;
+ }
+
+ /* apply offset last - camera offset is different to offset in blender units */
+ /* so this has some sane way of working - this matches camera's shift _exactly_ */
+ {
+ const float max_dim = max_ff(x2 - x1, y2 - y1);
+ const float xof_scale = bgpic->offset[0] * max_dim;
+ const float yof_scale = bgpic->offset[1] * max_dim;
+
+ x1 += xof_scale;
+ y1 += yof_scale;
+ x2 += xof_scale;
+ y2 += yof_scale;
+ }
+
+ centx = (x1 + x2) * 0.5f;
+ centy = (y1 + y2) * 0.5f;
+
+ /* aspect correction */
+ if (bgpic->flag & CAM_BGIMG_FLAG_CAMERA_ASPECT) {
+ /* apply aspect from clip */
+ const float w_src = ibuf->x * image_aspect[0];
+ const float h_src = ibuf->y * image_aspect[1];
+
+ /* destination aspect is already applied from the camera frame */
+ const float w_dst = x1 - x2;
+ const float h_dst = y1 - y2;
+
+ const float asp_src = w_src / h_src;
+ const float asp_dst = w_dst / h_dst;
+
+ if (fabsf(asp_src - asp_dst) >= FLT_EPSILON) {
+ if ((asp_src > asp_dst) == ((bgpic->flag & CAM_BGIMG_FLAG_CAMERA_CROP) != 0)) {
+ /* fit X */
+ const float div = asp_src / asp_dst;
+ x1 = ((x1 - centx) * div) + centx;
+ x2 = ((x2 - centx) * div) + centx;
+ }
+ else {
+ /* fit Y */
+ const float div = asp_dst / asp_src;
+ y1 = ((y1 - centy) * div) + centy;
+ y2 = ((y2 - centy) * div) + centy;
+ }
+ }
+ }
+ }
+
+ /* complete clip? */
+ rctf clip_rect;
+ BLI_rctf_init(&clip_rect, x1, x2, y1, y2);
+ if (bgpic->rotation) {
+ BLI_rctf_rotate_expand(&clip_rect, &clip_rect, bgpic->rotation);
+ }
+
+ if (clip_rect.xmax < 0 || clip_rect.ymax < 0 || clip_rect.xmin > ar->winx || clip_rect.ymin > ar->winy) {
+ if (freeibuf)
+ IMB_freeImBuf(freeibuf);
+ if (releaseibuf)
+ BKE_image_release_ibuf(ima, releaseibuf, lock);
+
+ continue;
+ }
+
+ float zoomx = (x2 - x1) / ibuf->x;
+ float zoomy = (y2 - y1) / ibuf->y;
+
+ /* for some reason; zoomlevels down refuses to use GL_ALPHA_SCALE */
+ if (zoomx < 1.0f || zoomy < 1.0f) {
+ float tzoom = min_ff(zoomx, zoomy);
+ int mip = 0;
+
+ if ((ibuf->userflags & IB_MIPMAP_INVALID) != 0) {
+ IMB_remakemipmap(ibuf, 0);
+ ibuf->userflags &= ~IB_MIPMAP_INVALID;
+ }
+ else if (ibuf->mipmap[0] == NULL)
+ IMB_makemipmap(ibuf, 0);
+
+ while (tzoom < 1.0f && mip < 8 && ibuf->mipmap[mip]) {
+ tzoom *= 2.0f;
+ zoomx *= 2.0f;
+ zoomy *= 2.0f;
+ mip++;
+ }
+ if (mip > 0)
+ ibuf = ibuf->mipmap[mip - 1];
+ }
+
+ if (v3d->zbuf) glDisable(GL_DEPTH_TEST);
+ glDepthMask(GL_FALSE);
+
+ glEnable(GL_BLEND);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ gpuPushProjectionMatrix();
+ gpuPushMatrix();
+ ED_region_pixelspace(ar);
+
+ gpuTranslate2f(centx, centy);
+ gpuScaleUniform(bgpic->scale);
+ gpuRotate2D(RAD2DEGF(-bgpic->rotation));
+
+ if (bgpic->flag & CAM_BGIMG_FLAG_FLIP_X) {
+ zoomx *= -1.0f;
+ x1 = x2;
+ }
+ if (bgpic->flag & CAM_BGIMG_FLAG_FLIP_Y) {
+ zoomy *= -1.0f;
+ y1 = y2;
+ }
+
+ float col[4] = {1.0f, 1.0f, 1.0f, bgpic->alpha};
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTex(&state, x1 - centx, y1 - centy, ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_LINEAR, ibuf->rect,
+ zoomx, zoomy, col);
+
+ gpuPopProjectionMatrix();
+ gpuPopMatrix();
+
+ glDisable(GL_BLEND);
+
+ glDepthMask(GL_TRUE);
+ if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
+
+ if (freeibuf)
+ IMB_freeImBuf(freeibuf);
+ if (releaseibuf)
+ BKE_image_release_ibuf(ima, releaseibuf, lock);
+ }
+ }
+}
+
+void ED_view3d_draw_bgpic_test(
+ Scene *scene, Depsgraph *depsgraph,
+ ARegion *ar, View3D *v3d,
+ const bool do_foreground, const bool do_camera_frame)
+{
+ RegionView3D *rv3d = ar->regiondata;
+
+ if ((rv3d->persp == RV3D_CAMOB) && v3d->camera && (v3d->camera->type == OB_CAMERA)) {
+ Camera *cam = v3d->camera->data;
+ if ((cam->flag & CAM_SHOW_BG_IMAGE) == 0) {
+ return;
+ }
+ }
+ else {
+ return;
+ }
+
+ /* disabled - mango request, since footage /w only render is quite useful
+ * and this option is easy to disable all background images at once */
+#if 0
+ if (v3d->flag2 & V3D_RENDER_OVERRIDE)
+ return;
+#endif
+
+ if ((rv3d->view == RV3D_VIEW_USER) || (rv3d->persp != RV3D_ORTHO)) {
+ if (rv3d->persp == RV3D_CAMOB) {
+ view3d_draw_bgpic(scene, depsgraph, ar, v3d, do_foreground, do_camera_frame);
+ }
+ }
+ else {
+ view3d_draw_bgpic(scene, depsgraph, ar, v3d, do_foreground, do_camera_frame);
+ }
+}
+
+/* *********************** */
+
+/* XXX warning, not using gpu offscreen here */
+void view3d_update_depths_rect(ARegion *ar, ViewDepths *d, rcti *rect)
+{
+ /* clamp rect by region */
+ rcti r = {
+ .xmin = 0,
+ .xmax = ar->winx - 1,
+ .ymin = 0,
+ .ymax = ar->winy - 1
+ };
+
+ /* Constrain rect to depth bounds */
+ BLI_rcti_isect(&r, rect, rect);
+
+ /* assign values to compare with the ViewDepths */
+ int x = rect->xmin;
+ int y = rect->ymin;
+
+ int w = BLI_rcti_size_x(rect);
+ int h = BLI_rcti_size_y(rect);
+
+ if (w <= 0 || h <= 0) {
+ if (d->depths)
+ MEM_freeN(d->depths);
+ d->depths = NULL;
+
+ d->damaged = false;
+ }
+ else if (d->w != w ||
+ d->h != h ||
+ d->x != x ||
+ d->y != y ||
+ d->depths == NULL
+ )
+ {
+ d->x = x;
+ d->y = y;
+ d->w = w;
+ d->h = h;
+
+ if (d->depths)
+ MEM_freeN(d->depths);
+
+ d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths Subset");
+
+ d->damaged = true;
+ }
+
+ if (d->damaged) {
+ /* XXX using special function here, it doesn't use the gpu offscreen system */
+ view3d_opengl_read_Z_pixels(ar, d->x, d->y, d->w, d->h, GL_DEPTH_COMPONENT, GL_FLOAT, d->depths);
+ glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
+ d->damaged = false;
+ }
+}
+
+/* note, with nouveau drivers the glReadPixels() is very slow. [#24339] */
+void ED_view3d_depth_update(ARegion *ar)
+{
+ RegionView3D *rv3d = ar->regiondata;
+
+ /* Create storage for, and, if necessary, copy depth buffer */
+ if (!rv3d->depths) rv3d->depths = MEM_callocN(sizeof(ViewDepths), "ViewDepths");
+ if (rv3d->depths) {
+ ViewDepths *d = rv3d->depths;
+ if (d->w != ar->winx ||
+ d->h != ar->winy ||
+ !d->depths)
+ {
+ d->w = ar->winx;
+ d->h = ar->winy;
+ if (d->depths)
+ MEM_freeN(d->depths);
+ d->depths = MEM_mallocN(sizeof(float) * d->w * d->h, "View depths");
+ d->damaged = true;
+ }
+
+ if (d->damaged) {
+ view3d_opengl_read_pixels(ar, 0, 0, d->w, d->h, GL_DEPTH_COMPONENT, GL_FLOAT, d->depths);
+ glGetDoublev(GL_DEPTH_RANGE, d->depth_range);
+
+ d->damaged = false;
+ }
+ }
+}
+
+/* utility function to find the closest Z value, use for autodepth */
+float view3d_depth_near(ViewDepths *d)
+{
+ /* convert to float for comparisons */
+ const float near = (float)d->depth_range[0];
+ const float far_real = (float)d->depth_range[1];
+ float far = far_real;
+
+ const float *depths = d->depths;
+ float depth = FLT_MAX;
+ int i = (int)d->w * (int)d->h; /* cast to avoid short overflow */
+
+ /* far is both the starting 'far' value
+ * and the closest value found. */
+ while (i--) {
+ depth = *depths++;
+ if ((depth < far) && (depth > near)) {
+ far = depth;
+ }
+ }
+
+ return far == far_real ? FLT_MAX : far;
+}
+
+void ED_view3d_draw_depth_gpencil(
+ Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d)
+{
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(depsgraph);
+ bool zbuf = v3d->zbuf;
+
+ /* Setup view matrix. */
+ ED_view3d_draw_setup_view(NULL, depsgraph, scene, ar, v3d, NULL, NULL, NULL);
+
+ glClear(GL_DEPTH_BUFFER_BIT);
+
+ v3d->zbuf = true;
+ glEnable(GL_DEPTH_TEST);
+
+ if (v3d->flag2 & V3D_SHOW_GPENCIL) {
+ ED_gpencil_draw_view3d(NULL, scene, view_layer, depsgraph, v3d, ar, true);
+ }
+
+ v3d->zbuf = zbuf;
+ if (!zbuf) glDisable(GL_DEPTH_TEST);
+}
+
+/* *********************** customdata **************** */
+
+CustomDataMask ED_view3d_datamask(const Scene *UNUSED(scene), const View3D *v3d)
+{
+ CustomDataMask mask = 0;
+ const int drawtype = view3d_effective_drawtype(v3d);
+
+ if (ELEM(drawtype, OB_TEXTURE, OB_MATERIAL) ||
+ ((drawtype == OB_SOLID) && (v3d->flag2 & V3D_SOLID_TEX)))
+ {
+ mask |= CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL;
+
+ if (drawtype == OB_MATERIAL)
+ mask |= CD_MASK_ORCO;
+ }
+
+ return mask;
+}
+
+/* goes over all modes and view3d settings */
+CustomDataMask ED_view3d_screen_datamask(const Scene *scene, const bScreen *screen)
+{
+ CustomDataMask mask = CD_MASK_BAREMESH;
+
+ /* check if we need tfaces & mcols due to view mode */
+ for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ if (sa->spacetype == SPACE_VIEW3D) {
+ mask |= ED_view3d_datamask(scene, sa->spacedata.first);
+ }
+ }
+
+ return mask;
+}
+
+/**
+ * Store values from #RegionView3D, set when drawing.
+ * This is needed when we draw with to a viewport using a different matrix (offscreen drawing for example).
+ *
+ * Values set by #ED_view3d_update_viewmat should be handled here.
+ */
+struct RV3DMatrixStore {
+ float winmat[4][4];
+ float viewmat[4][4];
+ float viewinv[4][4];
+ float persmat[4][4];
+ float persinv[4][4];
+ float viewcamtexcofac[4];
+ float pixsize;
+};
+
+struct RV3DMatrixStore *ED_view3d_mats_rv3d_backup(struct RegionView3D *rv3d)
+{
+ struct RV3DMatrixStore *rv3dmat = MEM_mallocN(sizeof(*rv3dmat), __func__);
+ copy_m4_m4(rv3dmat->winmat, rv3d->winmat);
+ copy_m4_m4(rv3dmat->viewmat, rv3d->viewmat);
+ copy_m4_m4(rv3dmat->persmat, rv3d->persmat);
+ copy_m4_m4(rv3dmat->persinv, rv3d->persinv);
+ copy_m4_m4(rv3dmat->viewinv, rv3d->viewinv);
+ copy_v4_v4(rv3dmat->viewcamtexcofac, rv3d->viewcamtexcofac);
+ rv3dmat->pixsize = rv3d->pixsize;
+ return (void *)rv3dmat;
+}
+
+void ED_view3d_mats_rv3d_restore(struct RegionView3D *rv3d, struct RV3DMatrixStore *rv3dmat_pt)
+{
+ struct RV3DMatrixStore *rv3dmat = rv3dmat_pt;
+ copy_m4_m4(rv3d->winmat, rv3dmat->winmat);
+ copy_m4_m4(rv3d->viewmat, rv3dmat->viewmat);
+ copy_m4_m4(rv3d->persmat, rv3dmat->persmat);
+ copy_m4_m4(rv3d->persinv, rv3dmat->persinv);
+ copy_m4_m4(rv3d->viewinv, rv3dmat->viewinv);
+ copy_v4_v4(rv3d->viewcamtexcofac, rv3dmat->viewcamtexcofac);
+ rv3d->pixsize = rv3dmat->pixsize;
+}
+
+/**
+ * \note The info that this uses is updated in #ED_refresh_viewport_fps,
+ * which currently gets called during #SCREEN_OT_animation_step.
+ */
+void ED_scene_draw_fps(Scene *scene, const rcti *rect)
+{
+ ScreenFrameRateInfo *fpsi = scene->fps_info;
+ char printable[16];
+
+ if (!fpsi || !fpsi->lredrawtime || !fpsi->redrawtime)
+ return;
+
+ printable[0] = '\0';
+
+#if 0
+ /* this is too simple, better do an average */
+ fps = (float)(1.0 / (fpsi->lredrawtime - fpsi->redrawtime))
+#else
+ fpsi->redrawtimes_fps[fpsi->redrawtime_index] = (float)(1.0 / (fpsi->lredrawtime - fpsi->redrawtime));
+
+ float fps = 0.0f;
+ int tot = 0;
+ for (int i = 0; i < REDRAW_FRAME_AVERAGE; i++) {
+ if (fpsi->redrawtimes_fps[i]) {
+ fps += fpsi->redrawtimes_fps[i];
+ tot++;
+ }
+ }
+ if (tot) {
+ fpsi->redrawtime_index = (fpsi->redrawtime_index + 1) % REDRAW_FRAME_AVERAGE;
+
+ //fpsi->redrawtime_index++;
+ //if (fpsi->redrawtime >= REDRAW_FRAME_AVERAGE)
+ // fpsi->redrawtime = 0;
+
+ fps = fps / tot;
+ }
+#endif
+
+ const int font_id = BLF_default();
+
+ /* is this more than half a frame behind? */
+ if (fps + 0.5f < (float)(FPS)) {
+ UI_FontThemeColor(font_id, TH_REDALERT);
+ BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %.2f"), fps);
+ }
+ else {
+ UI_FontThemeColor(font_id, TH_TEXT_HI);
+ BLI_snprintf(printable, sizeof(printable), IFACE_("fps: %i"), (int)(fps + 0.5f));
+ }
+
+#ifdef WITH_INTERNATIONAL
+ BLF_draw_default(rect->xmin + U.widget_unit, rect->ymax - U.widget_unit, 0.0f, printable, sizeof(printable));
+#else
+ BLF_draw_default_ascii(rect->xmin + U.widget_unit, rect->ymax - U.widget_unit, 0.0f, printable, sizeof(printable));
+#endif
+}
+
+static bool view3d_main_region_do_render_draw(const Scene *scene)
+{
+ RenderEngineType *type = RE_engines_find(scene->r.engine);
+ return (type && type->view_update && type->render_to_view);
+}
+
+bool ED_view3d_calc_render_border(const Scene *scene, Depsgraph *depsgraph, View3D *v3d, ARegion *ar, rcti *rect)
+{
+ RegionView3D *rv3d = ar->regiondata;
+ bool use_border;
+
+ /* test if there is a 3d view rendering */
+ if (v3d->drawtype != OB_RENDER || !view3d_main_region_do_render_draw(scene))
+ return false;
+
+ /* test if there is a border render */
+ if (rv3d->persp == RV3D_CAMOB)
+ use_border = (scene->r.mode & R_BORDER) != 0;
+ else
+ use_border = (v3d->flag2 & V3D_RENDER_BORDER) != 0;
+
+ if (!use_border)
+ return false;
+
+ /* compute border */
+ if (rv3d->persp == RV3D_CAMOB) {
+ rctf viewborder;
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewborder, false);
+
+ rect->xmin = viewborder.xmin + scene->r.border.xmin * BLI_rctf_size_x(&viewborder);
+ rect->ymin = viewborder.ymin + scene->r.border.ymin * BLI_rctf_size_y(&viewborder);
+ rect->xmax = viewborder.xmin + scene->r.border.xmax * BLI_rctf_size_x(&viewborder);
+ rect->ymax = viewborder.ymin + scene->r.border.ymax * BLI_rctf_size_y(&viewborder);
+ }
+ else {
+ rect->xmin = v3d->render_border.xmin * ar->winx;
+ rect->xmax = v3d->render_border.xmax * ar->winx;
+ rect->ymin = v3d->render_border.ymin * ar->winy;
+ rect->ymax = v3d->render_border.ymax * ar->winy;
+ }
+
+ BLI_rcti_translate(rect, ar->winrct.xmin, ar->winrct.ymin);
+ BLI_rcti_isect(&ar->winrct, rect, rect);
+
+ return true;
+}
diff --git a/source/blender/editors/space_view3d/view3d_edit.c b/source/blender/editors/space_view3d/view3d_edit.c
index 199800df539..7e05a80781c 100644
--- a/source/blender/editors/space_view3d/view3d_edit.c
+++ b/source/blender/editors/space_view3d/view3d_edit.c
@@ -36,6 +36,7 @@
#include <float.h>
#include "DNA_armature_types.h"
+#include "DNA_camera_types.h"
#include "DNA_curve_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -48,8 +49,10 @@
#include "BLI_utildefines.h"
#include "BKE_armature.h"
+#include "BKE_camera.h"
#include "BKE_context.h"
#include "BKE_font.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_object.h"
#include "BKE_paint.h"
@@ -58,12 +61,12 @@
#include "BKE_screen.h"
#include "BKE_action.h"
+#include "DEG_depsgraph.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -82,6 +85,8 @@
#include "view3d_intern.h" /* own include */
+#include "DEG_depsgraph_query.h"
+
/* -------------------------------------------------------------------- */
/** \name Generic View Operator Properties
* \{ */
@@ -131,6 +136,7 @@ typedef struct ViewOpsData {
ARegion *ar;
View3D *v3d;
RegionView3D *rv3d;
+ Depsgraph *depsgraph;
/** Needed for continuous zoom. */
wmTimer *timer;
@@ -215,6 +221,7 @@ static void viewops_data_alloc(bContext *C, wmOperator *op)
/* store data */
op->customdata = vod;
+ vod->depsgraph = CTX_data_depsgraph(C);
vod->scene = CTX_data_scene(C);
vod->sa = CTX_wm_area(C);
vod->ar = CTX_wm_region(C);
@@ -243,7 +250,8 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
bool is_set = false;
Scene *scene = CTX_data_scene(C);
- Object *ob_act = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob_act = OBACT(view_layer);
if (ob_act && (ob_act->mode & OB_MODE_ALL_PAINT) &&
/* with weight-paint + pose-mode, fall through to using calculateTransformCenter */
@@ -280,14 +288,13 @@ static bool view3d_orbit_calc_center(bContext *C, float r_dyn_ofs[3])
}
else if (ob_act == NULL || ob_act->mode == OB_MODE_OBJECT) {
/* object mode use boundbox centers */
- View3D *v3d = CTX_wm_view3d(C);
Base *base;
unsigned int tot = 0;
float select_center[3];
zero_v3(select_center);
- for (base = FIRSTBASE; base; base = base->next) {
- if (TESTBASE(v3d, base)) {
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ if (TESTBASE(base)) {
/* use the boundbox if we can */
Object *ob = base->object;
@@ -373,6 +380,7 @@ static void viewops_data_create(
/* we need the depth info before changing any viewport options */
if (viewops_flag & VIEWOPS_FLAG_DEPTH_NAVIGATE) {
+ struct Depsgraph *graph = CTX_data_depsgraph(C);
float fallback_depth_pt[3];
view3d_operator_needs_opengl(C); /* needed for zbuf drawing */
@@ -380,7 +388,7 @@ static void viewops_data_create(
negate_v3_v3(fallback_depth_pt, rv3d->ofs);
vod->use_dyn_ofs = ED_view3d_autodist(
- vod->scene, vod->ar, vod->v3d,
+ graph, vod->ar, vod->v3d,
event->mval, vod->dyn_ofs, true, fallback_depth_pt);
}
else {
@@ -503,8 +511,9 @@ static void viewops_data_create(
static void viewops_data_free(bContext *C, wmOperator *op)
{
ARegion *ar;
+#if 0
Paint *p = BKE_paint_get_active_from_context(C);
-
+#endif
if (op->customdata) {
ViewOpsData *vod = op->customdata;
ar = vod->ar;
@@ -520,7 +529,9 @@ static void viewops_data_free(bContext *C, wmOperator *op)
ar = CTX_wm_region(C);
}
+#if 0
if (p && (p->flags & PAINT_FAST_NAVIGATE))
+#endif
ED_region_tag_redraw(ar);
}
@@ -1789,7 +1800,7 @@ void viewzoom_modal_keymap(wmKeyConfig *keyconf)
* \param zoom_xy: Optionally zoom to window location (coords compatible w/ #wmEvent.x, y). Use when not NULL.
*/
static void view_zoom_to_window_xy_camera(
- Scene *scene, View3D *v3d,
+ Scene *scene, Depsgraph *depsgraph, View3D *v3d,
ARegion *ar, float dfac, const int zoom_xy[2])
{
RegionView3D *rv3d = ar->regiondata;
@@ -1807,13 +1818,13 @@ static void view_zoom_to_window_xy_camera(
float pt_dst[2];
float delta_px[2];
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &camera_frame_old, false);
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &camera_frame_old, false);
BLI_rctf_translate(&camera_frame_old, ar->winrct.xmin, ar->winrct.ymin);
rv3d->camzoom = camzoom_new;
CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &camera_frame_new, false);
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &camera_frame_new, false);
BLI_rctf_translate(&camera_frame_new, ar->winrct.xmin, ar->winrct.ymin);
BLI_rctf_transform_pt_v(&camera_frame_new, &camera_frame_old, pt_dst, pt_src);
@@ -1986,7 +1997,7 @@ static void viewzoom_apply_camera(
/* calculate inverted, then invert again (needed because of camera zoom scaling) */
zfac = 1.0f / zfac;
view_zoom_to_window_xy_camera(
- vod->scene, vod->v3d,
+ vod->scene, vod->depsgraph, vod->v3d,
vod->ar, zfac, zoom_to_pos ? vod->prev.event_xy : NULL);
}
@@ -2106,6 +2117,7 @@ static int viewzoom_modal(bContext *C, wmOperator *op, const wmEvent *event)
static int viewzoom_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
View3D *v3d;
RegionView3D *rv3d;
@@ -2148,7 +2160,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
const float step = 1.2f;
/* this min and max is also in viewmove() */
if (use_cam_zoom) {
- view_zoom_to_window_xy_camera(scene, v3d, ar, step, zoom_xy);
+ view_zoom_to_window_xy_camera(scene, depsgraph, v3d, ar, step, zoom_xy);
}
else {
if (rv3d->dist < dist_range[1]) {
@@ -2159,7 +2171,7 @@ static int viewzoom_exec(bContext *C, wmOperator *op)
else {
const float step = 1.0f / 1.2f;
if (use_cam_zoom) {
- view_zoom_to_window_xy_camera(scene, v3d, ar, step, zoom_xy);
+ view_zoom_to_window_xy_camera(scene, depsgraph, v3d, ar, step, zoom_xy);
}
else {
if (rv3d->dist > dist_range[0]) {
@@ -2692,6 +2704,7 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
ARegion *ar = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Base *base;
float *curs;
const bool use_all_regions = RNA_boolean_get(op->ptr, "use_all_regions");
@@ -2715,8 +2728,8 @@ static int view3d_all_exec(bContext *C, wmOperator *op)
INIT_MINMAX(min, max);
}
- for (base = scene->base.first; base; base = base->next) {
- if (BASE_VISIBLE(v3d, base)) {
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ if (BASE_VISIBLE(base)) {
changed = true;
if (skip_camera && base->object == v3d->camera) {
@@ -2782,9 +2795,13 @@ static int viewselected_exec(bContext *C, wmOperator *op)
ARegion *ar = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
Scene *scene = CTX_data_scene(C);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
bGPdata *gpd = CTX_data_gpencil_data(C);
const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE));
- Object *ob = OBACT;
+ const bool is_face_map = ((is_gp_edit == false) && ar->manipulator_map &&
+ WM_manipulatormap_is_any_selected(ar->manipulator_map));
+ Object *ob_eval = OBACT(view_layer_eval);
Object *obedit = CTX_data_edit_object(C);
float min[3], max[3];
bool ok = false, ok_dist = true;
@@ -2795,28 +2812,27 @@ static int viewselected_exec(bContext *C, wmOperator *op)
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
INIT_MINMAX(min, max);
-
- if (is_gp_edit) {
- ob = NULL;
+ if (is_gp_edit || is_face_map) {
+ ob_eval = NULL;
}
- if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT)) {
+ if (ob_eval && (ob_eval->mode & OB_MODE_WEIGHT_PAINT)) {
/* hard-coded exception, we look for the one selected armature */
/* this is weak code this way, we should make a generic active/selection callback interface once... */
- Base *base;
- for (base = scene->base.first; base; base = base->next) {
- if (TESTBASELIB(v3d, base)) {
- if (base->object->type == OB_ARMATURE)
- if (base->object->mode & OB_MODE_POSE)
+ Base *base_eval;
+ for (base_eval = view_layer_eval->object_bases.first; base_eval; base_eval = base_eval->next) {
+ if (TESTBASELIB(base_eval)) {
+ if (base_eval->object->type == OB_ARMATURE)
+ if (base_eval->object->mode & OB_MODE_POSE)
break;
}
}
- if (base)
- ob = base->object;
+ if (base_eval)
+ ob_eval = base_eval->object;
}
-
if (is_gp_edit) {
+ /* TODO(sergey): Check on this after gpencil merge. */
CTX_DATA_BEGIN(C, bGPDstroke *, gps, editable_gpencil_strokes)
{
/* we're only interested in selected points here... */
@@ -2828,38 +2844,48 @@ static int viewselected_exec(bContext *C, wmOperator *op)
}
CTX_DATA_END;
}
+ else if (is_face_map) {
+ ok = WM_manipulatormap_minmax(ar->manipulator_map, true, true, min, max);
+ }
else if (obedit) {
- ok = ED_view3d_minmax_verts(obedit, min, max); /* only selected */
+ /* only selected */
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer_eval, obedit->mode, ob_eval_iter) {
+ ok |= ED_view3d_minmax_verts(ob_eval_iter, min, max);
+ }
+ FOREACH_OBJECT_IN_MODE_END;
}
- else if (ob && (ob->mode & OB_MODE_POSE)) {
- ok = BKE_pose_minmax(ob, min, max, true, true);
+ else if (ob_eval && (ob_eval->mode & OB_MODE_POSE)) {
+ FOREACH_OBJECT_IN_MODE_BEGIN (view_layer_eval, ob_eval->mode, ob_eval_iter) {
+ ok |= BKE_pose_minmax(ob_eval_iter, min, max, true, true);
+ }
+ FOREACH_OBJECT_IN_MODE_END;
}
- else if (BKE_paint_select_face_test(ob)) {
- ok = paintface_minmax(ob, min, max);
+ else if (BKE_paint_select_face_test(ob_eval)) {
+ ok = paintface_minmax(ob_eval, min, max);
}
- else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
- ok = PE_minmax(scene, min, max);
+ else if (ob_eval && (ob_eval->mode & OB_MODE_PARTICLE_EDIT)) {
+ ok = PE_minmax(scene, view_layer_eval, min, max);
}
- else if (ob &&
- (ob->mode & (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)))
+ else if (ob_eval &&
+ (ob_eval->mode & (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)))
{
- BKE_paint_stroke_get_average(scene, ob, min);
+ BKE_paint_stroke_get_average(scene, ob_eval, min);
copy_v3_v3(max, min);
ok = true;
ok_dist = 0; /* don't zoom */
}
else {
- Base *base;
- for (base = FIRSTBASE; base; base = base->next) {
- if (TESTBASE(v3d, base)) {
+ Base *base_eval;
+ for (base_eval = FIRSTBASE(view_layer_eval); base_eval; base_eval = base_eval->next) {
+ if (TESTBASE(base_eval)) {
- if (skip_camera && base->object == v3d->camera) {
+ if (skip_camera && base_eval->object == v3d->camera) {
continue;
}
/* account for duplis */
- if (BKE_object_minmax_dupli(scene, base->object, min, max, false) == 0)
- BKE_object_minmax(base->object, min, max, false); /* use if duplis not found */
+ if (BKE_object_minmax_dupli(depsgraph, scene, base_eval->object, min, max, false) == 0)
+ BKE_object_minmax(base_eval->object, min, max, false); /* use if duplis not found */
ok = 1;
}
@@ -2948,7 +2974,6 @@ static int view_lock_to_active_exec(bContext *C, wmOperator *UNUSED(op))
Object *obact = CTX_data_active_object(C);
if (v3d) {
-
ED_view3d_lock_clear(v3d);
v3d->ob_centre = obact; /* can be NULL */
@@ -3049,10 +3074,10 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
{
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
- Scene *scene = CTX_data_scene(C);
ARegion *ar = CTX_wm_region(C);
if (rv3d) {
+ struct Depsgraph *graph = CTX_data_depsgraph(C);
float new_ofs[3];
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
@@ -3060,7 +3085,7 @@ static int viewcenter_pick_invoke(bContext *C, wmOperator *op, const wmEvent *ev
view3d_operator_needs_opengl(C);
- if (ED_view3d_autodist(scene, ar, v3d, event->mval, new_ofs, false, NULL)) {
+ if (ED_view3d_autodist(graph, ar, v3d, event->mval, new_ofs, false, NULL)) {
/* pass */
}
else {
@@ -3100,6 +3125,7 @@ void VIEW3D_OT_view_center_pick(wmOperatorType *ot)
static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was view3d_home() in 2.4x */
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
float xfac, yfac;
float size[2];
@@ -3114,7 +3140,7 @@ static int view3d_center_camera_exec(bContext *C, wmOperator *UNUSED(op)) /* was
rv3d->camdx = rv3d->camdy = 0.0f;
- ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size);
+ ED_view3d_calc_camera_border_size(scene, depsgraph, ar, v3d, rv3d, size);
/* 4px is just a little room from the edge of the area */
xfac = (float)ar->winx / (float)(size[0] + 4);
@@ -3183,6 +3209,7 @@ void VIEW3D_OT_view_center_lock(wmOperatorType *ot)
static int render_border_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
View3D *v3d = CTX_wm_view3d(C);
ARegion *ar = CTX_wm_region(C);
RegionView3D *rv3d = ED_view3d_context_rv3d(C);
@@ -3203,7 +3230,7 @@ static int render_border_exec(bContext *C, wmOperator *op)
/* calculate range */
if (rv3d->persp == RV3D_CAMOB) {
- ED_view3d_calc_camera_border(scene, ar, v3d, rv3d, &vb, false);
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &vb, false);
}
else {
vb.xmin = 0;
@@ -3340,7 +3367,6 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
ARegion *ar = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
- Scene *scene = CTX_data_scene(C);
const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
/* Zooms in on a border drawn by the user */
@@ -3353,9 +3379,8 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
float new_ofs[3];
/* ZBuffer depth vars */
- bglMats mats;
float depth_close = FLT_MAX;
- double cent[2], p[3];
+ float cent[2], p[3];
/* note; otherwise opengl won't work */
view3d_operator_needs_opengl(C);
@@ -3369,8 +3394,7 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
ED_view3d_dist_range_get(v3d, dist_range);
/* Get Z Depths, needed for perspective, nice for ortho */
- bgl_get_mats(&mats);
- ED_view3d_draw_depth(scene, ar, v3d, true);
+ ED_view3d_draw_depth(CTX_data_depsgraph(C), ar, v3d, true);
{
/* avoid allocating the whole depth buffer */
@@ -3385,11 +3409,11 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
MEM_SAFE_FREE(depth_temp.depths);
}
- cent[0] = (((double)rect.xmin) + ((double)rect.xmax)) / 2;
- cent[1] = (((double)rect.ymin) + ((double)rect.ymax)) / 2;
+ cent[0] = (((float)rect.xmin) + ((float)rect.xmax)) / 2;
+ cent[1] = (((float)rect.ymin) + ((float)rect.ymax)) / 2;
if (rv3d->is_persp) {
- double p_corner[3];
+ float p_corner[3];
/* no depths to use, we cant do anything! */
if (depth_close == FLT_MAX) {
@@ -3397,23 +3421,14 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
}
/* convert border to 3d coordinates */
- if ((!gluUnProject(cent[0], cent[1], depth_close,
- mats.modelview, mats.projection, (GLint *)mats.viewport,
- &p[0], &p[1], &p[2])) ||
- (!gluUnProject((double)rect.xmin, (double)rect.ymin, depth_close,
- mats.modelview, mats.projection, (GLint *)mats.viewport,
- &p_corner[0], &p_corner[1], &p_corner[2])))
+ if ((!ED_view3d_unproject(ar, cent[0], cent[1], depth_close, p)) ||
+ (!ED_view3d_unproject(ar, rect.xmin, rect.ymin, depth_close, p_corner)))
{
return OPERATOR_CANCELLED;
}
- dvec[0] = p[0] - p_corner[0];
- dvec[1] = p[1] - p_corner[1];
- dvec[2] = p[2] - p_corner[2];
-
- new_ofs[0] = -p[0];
- new_ofs[1] = -p[1];
- new_ofs[2] = -p[2];
+ sub_v3_v3v3(dvec, p, p_corner);
+ negate_v3_v3(new_ofs, p);
new_dist = len_v3(dvec);
@@ -3428,13 +3443,8 @@ static int view3d_zoom_border_exec(bContext *C, wmOperator *op)
new_dist = rv3d->dist;
/* convert the drawn rectangle into 3d space */
- if (depth_close != FLT_MAX && gluUnProject(cent[0], cent[1], depth_close,
- mats.modelview, mats.projection, (GLint *)mats.viewport,
- &p[0], &p[1], &p[2]))
- {
- new_ofs[0] = -p[0];
- new_ofs[1] = -p[1];
- new_ofs[2] = -p[2];
+ if (depth_close != FLT_MAX && ED_view3d_unproject(ar, cent[0], cent[1], depth_close, p)) {
+ negate_v3_v3(new_ofs, p);
}
else {
float mval_f[2];
@@ -3524,13 +3534,13 @@ void VIEW3D_OT_zoom_border(wmOperatorType *ot)
* Sets the view to 1:1 camera/render-pixel.
* \{ */
-static void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d)
+static void view3d_set_1_to_1_viewborder(Scene *scene, Depsgraph *depsgraph, ARegion *ar, View3D *v3d)
{
RegionView3D *rv3d = ar->regiondata;
float size[2];
int im_width = (scene->r.size * scene->r.xsch) / 100;
- ED_view3d_calc_camera_border_size(scene, ar, v3d, rv3d, size);
+ ED_view3d_calc_camera_border_size(scene, depsgraph, ar, v3d, rv3d, size);
rv3d->camzoom = BKE_screen_view3d_zoom_from_fac((float)im_width / size[0]);
CLAMP(rv3d->camzoom, RV3D_CAMZOOM_MIN, RV3D_CAMZOOM_MAX);
@@ -3538,6 +3548,7 @@ static void view3d_set_1_to_1_viewborder(Scene *scene, ARegion *ar, View3D *v3d)
static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op))
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
View3D *v3d;
@@ -3546,7 +3557,7 @@ static int view3d_zoom_1_to_1_camera_exec(bContext *C, wmOperator *UNUSED(op))
/* no NULL check is needed, poll checks */
ED_view3d_context_user_region(C, &v3d, &ar);
- view3d_set_1_to_1_viewborder(scene, ar, v3d);
+ view3d_set_1_to_1_viewborder(scene, depsgraph, ar, v3d);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
@@ -3684,6 +3695,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
ARegion *ar;
RegionView3D *rv3d;
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
static int perspo = RV3D_PERSP;
int viewnum, nextperspo;
bool align_active;
@@ -3718,7 +3730,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
/* lastview - */
if (rv3d->persp != RV3D_CAMOB) {
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
if (!rv3d->smooth_timer) {
/* store settings of current view before allowing overwriting with camera view
@@ -3753,7 +3765,7 @@ static int viewnumpad_exec(bContext *C, wmOperator *op)
v3d->camera = ob;
if (v3d->camera == NULL)
- v3d->camera = BKE_scene_camera_find(scene);
+ v3d->camera = BKE_view_layer_camera_find(view_layer);
/* couldnt find any useful camera, bail out */
if (v3d->camera == NULL)
@@ -4319,11 +4331,11 @@ void VIEW3D_OT_navigate(wmOperatorType *ot)
/** \name Background Image Add Operator
* \{ */
-static BGpic *background_image_add(bContext *C)
+static CameraBGImage *background_image_add(bContext *C)
{
- View3D *v3d = CTX_wm_view3d(C);
+ Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
- return ED_view3d_background_image_new(v3d);
+ return BKE_camera_background_image_new(cam);
}
static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op))
@@ -4335,9 +4347,9 @@ static int background_image_add_exec(bContext *C, wmOperator *UNUSED(op))
static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- View3D *v3d = CTX_wm_view3d(C);
+ Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
Image *ima;
- BGpic *bgpic;
+ CameraBGImage *bgpic;
ima = (Image *)WM_operator_drop_load_path(C, op, ID_IM);
/* may be NULL, continue anyway */
@@ -4345,9 +4357,9 @@ static int background_image_add_invoke(bContext *C, wmOperator *op, const wmEven
bgpic = background_image_add(C);
bgpic->ima = ima;
- v3d->flag |= V3D_DISPBGPICS;
+ cam->flag |= CAM_SHOW_BG_IMAGE;
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
+ WM_event_add_notifier(C, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
return OPERATOR_FINISHED;
}
@@ -4364,7 +4376,7 @@ void VIEW3D_OT_background_image_add(wmOperatorType *ot)
/* api callbacks */
ot->invoke = background_image_add_invoke;
ot->exec = background_image_add_exec;
- ot->poll = ED_operator_view3d_active;
+ ot->poll = ED_operator_camera;
/* flags */
ot->flag = OPTYPE_UNDO;
@@ -4384,21 +4396,21 @@ void VIEW3D_OT_background_image_add(wmOperatorType *ot)
static int background_image_remove_exec(bContext *C, wmOperator *op)
{
- View3D *v3d = CTX_wm_view3d(C);
+ Camera *cam = CTX_data_pointer_get_type(C, "camera", &RNA_Camera).data;
const int index = RNA_int_get(op->ptr, "index");
- BGpic *bgpic_rem = BLI_findlink(&v3d->bgpicbase, index);
+ CameraBGImage *bgpic_rem = BLI_findlink(&cam->bg_images, index);
if (bgpic_rem) {
- if (bgpic_rem->source == V3D_BGPIC_IMAGE) {
+ if (bgpic_rem->source == CAM_BGIMG_SOURCE_IMAGE) {
id_us_min((ID *)bgpic_rem->ima);
}
- else if (bgpic_rem->source == V3D_BGPIC_MOVIE) {
+ else if (bgpic_rem->source == CAM_BGIMG_SOURCE_MOVIE) {
id_us_min((ID *)bgpic_rem->clip);
}
- ED_view3d_background_image_remove(v3d, bgpic_rem);
+ BKE_camera_background_image_remove(cam, bgpic_rem);
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
+ WM_event_add_notifier(C, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
return OPERATOR_FINISHED;
}
else {
@@ -4415,7 +4427,7 @@ void VIEW3D_OT_background_image_remove(wmOperatorType *ot)
/* api callbacks */
ot->exec = background_image_remove_exec;
- ot->poll = ED_operator_view3d_active;
+ ot->poll = ED_operator_camera;
/* flags */
ot->flag = 0;
@@ -4455,9 +4467,8 @@ void ED_view3d_clipping_local(RegionView3D *rv3d, float mat[4][4])
static int view3d_clipping_exec(bContext *C, wmOperator *op)
{
+ ARegion *ar = CTX_wm_region(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
- ViewContext vc;
- bglMats mats;
rcti rect;
WM_operator_properties_border_to_rcti(op, &rect);
@@ -4465,12 +4476,8 @@ static int view3d_clipping_exec(bContext *C, wmOperator *op)
rv3d->rflag |= RV3D_CLIPPING;
rv3d->clipbb = MEM_callocN(sizeof(BoundBox), "clipbb");
- /* note; otherwise opengl won't work */
- view3d_operator_needs_opengl(C);
-
- ED_view3d_viewcontext_init(C, &vc);
- view3d_get_transformation(vc.ar, vc.rv3d, NULL, &mats); /* NULL because we don't want it in object space */
- ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, &mats, &rect);
+ /* NULL object because we don't want it in object space */
+ ED_view3d_clipping_calc(rv3d->clipbb, rv3d->clip, ar, NULL, &rect);
return OPERATOR_FINISHED;
}
@@ -4525,7 +4532,6 @@ void VIEW3D_OT_clip_border(wmOperatorType *ot)
/* note: cannot use event->mval here (called by object_add() */
void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
{
- Scene *scene = CTX_data_scene(C);
ARegion *ar = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = ar->regiondata;
@@ -4547,9 +4553,12 @@ void ED_view3d_cursor3d_position(bContext *C, float fp[3], const int mval[2])
}
if (U.uiflag & USER_DEPTH_CURSOR) { /* maybe this should be accessed some other way */
+ struct Depsgraph *graph = CTX_data_depsgraph(C);
+
view3d_operator_needs_opengl(C);
- if (ED_view3d_autodist(scene, ar, v3d, mval, fp, true, NULL))
+ if (ED_view3d_autodist(graph, ar, v3d, mval, fp, true, NULL)) {
depth_used = true;
+ }
}
if (depth_used == false) {
@@ -4597,6 +4606,14 @@ void ED_view3d_cursor3d_update(bContext *C, const int mval[2])
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
else
WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
+
+ {
+ struct wmMsgBus *mbus = CTX_wm_message_bus(C);
+ WM_msg_publish_rna_prop(
+ mbus, &scene->id, scene, Scene, cursor_location);
+ }
+
+ DEG_id_tag_update(&scene->id, DEG_TAG_COPY_ON_WRITE);
}
static int view3d_cursor3d_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
@@ -4626,96 +4643,6 @@ void VIEW3D_OT_cursor3d(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Transform Manipulator Operator
- * \{ */
-
-static int manipulator_invoke(bContext *C, wmOperator *op, const wmEvent *event)
-{
- View3D *v3d = CTX_wm_view3d(C);
-
- if (!(v3d->twflag & V3D_USE_MANIPULATOR)) return OPERATOR_PASS_THROUGH;
- if (!(v3d->twflag & V3D_DRAW_MANIPULATOR)) return OPERATOR_PASS_THROUGH;
-
- /* note; otherwise opengl won't work */
- view3d_operator_needs_opengl(C);
-
- if (BIF_do_manipulator(C, event, op) == 0)
- return OPERATOR_PASS_THROUGH;
-
- return OPERATOR_FINISHED;
-}
-
-void VIEW3D_OT_manipulator(wmOperatorType *ot)
-{
- PropertyRNA *prop;
-
- /* identifiers */
- ot->name = "3D Manipulator";
- ot->description = "Manipulate selected item by axis";
- ot->idname = "VIEW3D_OT_manipulator";
-
- /* api callbacks */
- ot->invoke = manipulator_invoke;
-
- ot->poll = ED_operator_view3d_active;
-
- /* properties to pass to transform */
- Transform_Properties(ot, P_CONSTRAINT);
-
- prop = RNA_def_boolean(ot->srna, "use_planar_constraint", false, "Planar Constraint", "Limit the transformation to the "
- "two axes that have not been clicked (translate/scale only)");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE | PROP_HIDDEN);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Enable Transform Manipulator Operator
- * \{ */
-
-static int enable_manipulator_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
-{
- View3D *v3d = CTX_wm_view3d(C);
-
- v3d->twtype = 0;
-
- if (RNA_boolean_get(op->ptr, "translate"))
- v3d->twtype |= V3D_MANIP_TRANSLATE;
- if (RNA_boolean_get(op->ptr, "rotate"))
- v3d->twtype |= V3D_MANIP_ROTATE;
- if (RNA_boolean_get(op->ptr, "scale"))
- v3d->twtype |= V3D_MANIP_SCALE;
-
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
-
- return OPERATOR_FINISHED;
-}
-
-void VIEW3D_OT_enable_manipulator(wmOperatorType *ot)
-{
- PropertyRNA *prop;
-
- /* identifiers */
- ot->name = "Enable 3D Manipulator";
- ot->description = "Enable the transform manipulator for use";
- ot->idname = "VIEW3D_OT_enable_manipulator";
-
- /* api callbacks */
- ot->invoke = enable_manipulator_invoke;
- ot->poll = ED_operator_view3d_active;
-
- /* properties */
- prop = RNA_def_boolean(ot->srna, "translate", 0, "Translate", "Enable the translate manipulator");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "rotate", 0, "Rotate", "Enable the rotate manipulator");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "scale", 0, "Scale", "Enable the scale manipulator");
- RNA_def_property_flag(prop, PROP_SKIP_SAVE);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Toggle Render Shading Operator
* \{ */
diff --git a/source/blender/editors/space_view3d/view3d_fly.c b/source/blender/editors/space_view3d/view3d_fly.c
index eda780d01a7..3715f4672d7 100644
--- a/source/blender/editors/space_view3d/view3d_fly.c
+++ b/source/blender/editors/space_view3d/view3d_fly.c
@@ -56,6 +56,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_immediate.h"
+
+#include "DEG_depsgraph.h"
+
#include "view3d_intern.h" /* own include */
/* NOTE: these defines are saved in keymap files, do not change values but just add new ones */
@@ -191,6 +195,7 @@ typedef struct FlyInfo {
RegionView3D *rv3d;
View3D *v3d;
ARegion *ar;
+ struct Depsgraph *depsgraph;
Scene *scene;
wmTimer *timer; /* needed for redraws */
@@ -240,7 +245,7 @@ static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar),
float x1, x2, y1, y2;
if (fly->scene->camera) {
- ED_view3d_calc_camera_border(fly->scene, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
+ ED_view3d_calc_camera_border(fly->scene, fly->depsgraph, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
xoff = viewborder.xmin;
yoff = viewborder.ymin;
}
@@ -257,36 +262,45 @@ static void drawFlyPixel(const struct bContext *UNUSED(C), ARegion *UNUSED(ar),
x2 = xoff + 0.55f * fly->width;
y2 = yoff + 0.55f * fly->height;
- UI_ThemeColor(TH_VIEW_OVERLAY);
- glBegin(GL_LINES);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColor(TH_VIEW_OVERLAY);
+
+ immBegin(GWN_PRIM_LINES, 16);
+
/* bottom left */
- glVertex2f(x1, y1);
- glVertex2f(x1, y1 + 5);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x1, y1 + 5);
- glVertex2f(x1, y1);
- glVertex2f(x1 + 5, y1);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x1 + 5, y1);
/* top right */
- glVertex2f(x2, y2);
- glVertex2f(x2, y2 - 5);
+ immVertex2f(pos, x2, y2);
+ immVertex2f(pos, x2, y2 - 5);
- glVertex2f(x2, y2);
- glVertex2f(x2 - 5, y2);
+ immVertex2f(pos, x2, y2);
+ immVertex2f(pos, x2 - 5, y2);
/* top left */
- glVertex2f(x1, y2);
- glVertex2f(x1, y2 - 5);
+ immVertex2f(pos, x1, y2);
+ immVertex2f(pos, x1, y2 - 5);
- glVertex2f(x1, y2);
- glVertex2f(x1 + 5, y2);
+ immVertex2f(pos, x1, y2);
+ immVertex2f(pos, x1 + 5, y2);
/* bottom right */
- glVertex2f(x2, y1);
- glVertex2f(x2, y1 + 5);
+ immVertex2f(pos, x2, y1);
+ immVertex2f(pos, x2, y1 + 5);
- glVertex2f(x2, y1);
- glVertex2f(x2 - 5, y1);
- glEnd();
+ immVertex2f(pos, x2, y1);
+ immVertex2f(pos, x2 - 5, y1);
+
+ immEnd();
+ immUnbindProgram();
}
static void fly_update_header(bContext *C, wmOperator *op, FlyInfo *fly)
@@ -332,6 +346,7 @@ enum {
static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent *event)
{
wmWindow *win = CTX_wm_window(C);
+
rctf viewborder;
float upvec[3]; /* tmp */
@@ -340,6 +355,7 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent
fly->rv3d = CTX_wm_region_view3d(C);
fly->v3d = CTX_wm_view3d(C);
fly->ar = CTX_wm_region(C);
+ fly->depsgraph = CTX_data_depsgraph(C);
fly->scene = CTX_data_scene(C);
#ifdef NDOF_FLY_DEBUG
@@ -406,12 +422,12 @@ static bool initFlyInfo(bContext *C, FlyInfo *fly, wmOperator *op, const wmEvent
}
fly->v3d_camera_control = ED_view3d_cameracontrol_acquire(
- fly->scene, fly->v3d, fly->rv3d,
+ CTX_data_depsgraph(C), fly->scene, fly->v3d, fly->rv3d,
(U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0);
/* calculate center */
if (fly->scene->camera) {
- ED_view3d_calc_camera_border(fly->scene, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
+ ED_view3d_calc_camera_border(fly->scene, fly->depsgraph, fly->ar, fly->v3d, fly->rv3d, &viewborder, false);
fly->width = BLI_rctf_size_x(&viewborder);
fly->height = BLI_rctf_size_y(&viewborder);
diff --git a/source/blender/editors/space_view3d/view3d_header.c b/source/blender/editors/space_view3d/view3d_header.c
index d80ef486663..52a8562b6ba 100644
--- a/source/blender/editors/space_view3d/view3d_header.c
+++ b/source/blender/editors/space_view3d/view3d_header.c
@@ -41,11 +41,12 @@
#include "BLT_translation.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_screen.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -71,11 +72,10 @@ static void do_view3d_header_buttons(bContext *C, void *arg, int event);
/* XXX quickly ported across */
static void handle_view3d_lock(bContext *C)
{
- Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
ScrArea *sa = CTX_wm_area(C);
View3D *v3d = CTX_wm_view3d(C);
-
+
if (v3d != NULL && sa != NULL) {
if (v3d->localvd == NULL && v3d->scenelock && sa->spacetype == SPACE_VIEW3D) {
/* copy to scene */
@@ -83,10 +83,6 @@ static void handle_view3d_lock(bContext *C)
scene->layact = v3d->layact;
scene->camera = v3d->camera;
- /* not through notifier, listener don't have context
- * and non-open screens or spaces need to be updated too */
- BKE_screen_view3d_main_sync(&bmain->screen, scene);
-
/* notifiers for scene update */
WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
}
@@ -97,16 +93,16 @@ static void handle_view3d_lock(bContext *C)
* layer code is on three levels actually:
* - here for operator
* - uiTemplateLayers in interface/ code for buttons
- * - ED_view3d_scene_layer_set for RNA
+ * - ED_view3d_view_layer_set for RNA
*/
-static void view3d_layers_editmode_ensure(Scene *scene, View3D *v3d)
+static void view3d_layers_editmode_ensure(View3D *v3d, Object *obedit)
{
/* sanity check - when in editmode disallow switching the editmode layer off since its confusing
* an alternative would be to always draw the editmode object. */
- if (scene->obedit && (scene->obedit->lay & v3d->lay) == 0) {
+ if (obedit && (obedit->lay & v3d->lay) == 0) {
int bit;
for (bit = 0; bit < 32; bit++) {
- if (scene->obedit->lay & (1u << bit)) {
+ if (obedit->lay & (1u << bit)) {
v3d->lay |= (1u << bit);
break;
}
@@ -116,9 +112,9 @@ static void view3d_layers_editmode_ensure(Scene *scene, View3D *v3d)
static int view3d_layers_exec(bContext *C, wmOperator *op)
{
- Scene *scene = CTX_data_scene(C);
ScrArea *sa = CTX_wm_area(C);
View3D *v3d = sa->spacedata.first;
+ Object *obedit = CTX_data_edit_object(C);
int nr = RNA_int_get(op->ptr, "nr");
const bool toggle = RNA_boolean_get(op->ptr, "toggle");
@@ -134,7 +130,7 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
/* return to active layer only */
v3d->lay = v3d->lay_prev;
- view3d_layers_editmode_ensure(scene, v3d);
+ view3d_layers_editmode_ensure(v3d, obedit);
}
else {
v3d->lay_prev = v3d->lay;
@@ -155,7 +151,7 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
v3d->lay = (1 << nr);
}
- view3d_layers_editmode_ensure(scene, v3d);
+ view3d_layers_editmode_ensure(v3d, obedit);
/* set active layer, ensure to always have one */
if (v3d->lay & (1 << nr))
@@ -172,7 +168,7 @@ static int view3d_layers_exec(bContext *C, wmOperator *op)
if (v3d->scenelock) handle_view3d_lock(C);
- DAG_on_visible_update(CTX_data_main(C), false);
+ DEG_on_visible_update(CTX_data_main(C), false);
ED_area_tag_redraw(sa);
@@ -278,21 +274,65 @@ void uiTemplateEditModeSelection(uiLayout *layout, struct bContext *C)
}
}
+static void uiTemplatePaintModeSelection(uiLayout *layout, struct bContext *C)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+
+ /* Manipulators aren't used in paint modes */
+ if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
+ /* masks aren't used for sculpt and particle painting */
+ PointerRNA meshptr;
+
+ RNA_pointer_create(ob->data, &RNA_Mesh, ob->data, &meshptr);
+ if (ob->mode & (OB_MODE_TEXTURE_PAINT)) {
+ uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ }
+ else {
+ uiLayout *row = uiLayoutRow(layout, true);
+ uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
+ }
+ }
+}
+
+void uiTemplateHeader3D_mode(uiLayout *layout, struct bContext *C)
+{
+ /* Extracted from: uiTemplateHeader3D */
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+ Object *obedit = CTX_data_edit_object(C);
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+
+ bool is_paint = (
+ ob && !(gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
+ ELEM(ob->mode,
+ OB_MODE_SCULPT, OB_MODE_VERTEX_PAINT, OB_MODE_WEIGHT_PAINT, OB_MODE_TEXTURE_PAINT));
+
+ uiTemplateEditModeSelection(layout, C);
+ if ((obedit == NULL) && is_paint) {
+ uiTemplatePaintModeSelection(layout, C);
+ }
+}
+
void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
{
bScreen *screen = CTX_wm_screen(C);
ScrArea *sa = CTX_wm_area(C);
View3D *v3d = sa->spacedata.first;
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
ToolSettings *ts = CTX_data_tool_settings(C);
PointerRNA v3dptr, toolsptr, sceneptr;
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
Object *obedit = CTX_data_edit_object(C);
bGPdata *gpd = CTX_data_gpencil_data(C);
uiBlock *block;
uiLayout *row;
- bool is_paint = false;
- int modeselect;
+ bool is_paint = (
+ ob && !(gpd && (gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
+ ELEM(ob->mode,
+ OB_MODE_SCULPT, OB_MODE_VERTEX_PAINT, OB_MODE_WEIGHT_PAINT, OB_MODE_TEXTURE_PAINT));
RNA_pointer_create(&screen->id, &RNA_SpaceView3D, v3d, &v3dptr);
RNA_pointer_create(&scene->id, &RNA_ToolSettings, ts, &toolsptr);
@@ -303,39 +343,6 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
/* other buttons: */
UI_block_emboss_set(block, UI_EMBOSS);
-
- /* mode */
- if ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE)) {
- modeselect = OB_MODE_GPENCIL;
- }
- else if (ob) {
- modeselect = ob->mode;
- is_paint = ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_VERTEX_PAINT, OB_MODE_WEIGHT_PAINT, OB_MODE_TEXTURE_PAINT);
- }
- else {
- modeselect = OB_MODE_OBJECT;
- }
-
- row = uiLayoutRow(layout, false);
- {
- const EnumPropertyItem *item = rna_enum_object_mode_items;
- const char *name = "";
- int icon = ICON_OBJECT_DATAMODE;
-
- while (item->identifier) {
- if (item->value == modeselect && item->identifier[0]) {
- name = IFACE_(item->name);
- icon = item->icon;
- break;
- }
- item++;
- }
-
- uiItemMenuEnumO(row, C, "OBJECT_OT_mode_set", "mode", name, icon);
- }
-
- /* Draw type */
- uiItemR(layout, &v3dptr, "viewport_shade", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
row = uiLayoutRow(layout, true);
uiItemR(row, &v3dptr, "pivot_point", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
@@ -344,41 +351,26 @@ void uiTemplateHeader3D(uiLayout *layout, struct bContext *C)
}
if (obedit == NULL && is_paint) {
- /* Manipulators aren't used in paint modes */
- if (!ELEM(ob->mode, OB_MODE_SCULPT, OB_MODE_PARTICLE_EDIT)) {
- /* masks aren't used for sculpt and particle painting */
- PointerRNA meshptr;
-
- RNA_pointer_create(ob->data, &RNA_Mesh, ob->data, &meshptr);
- if (ob->mode & (OB_MODE_TEXTURE_PAINT)) {
- uiItemR(layout, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
- }
- else {
- row = uiLayoutRow(layout, true);
- uiItemR(row, &meshptr, "use_paint_mask", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
- uiItemR(row, &meshptr, "use_paint_mask_vertex", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
- }
- }
+ /* Currently Python calls this directly. */
+#if 0
+ uiTemplatePaintModeSelection(layout, C);
+#endif
+
}
else {
/* Transform widget / manipulators */
row = uiLayoutRow(layout, true);
uiItemR(row, &v3dptr, "show_manipulator", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
- if (v3d->twflag & V3D_USE_MANIPULATOR) {
- uiItemR(row, &v3dptr, "transform_manipulators", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
- }
- uiItemR(row, &v3dptr, "transform_orientation", 0, "", ICON_NONE);
+ uiItemR(row, &sceneptr, "transform_orientation", 0, "", ICON_NONE);
}
if (obedit == NULL && v3d->localvd == NULL) {
- unsigned int ob_lay = ob ? ob->lay : 0;
-
- /* Layers */
- uiTemplateLayers(layout, v3d->scenelock ? &sceneptr : &v3dptr, "layers", &v3dptr, "layers_used", ob_lay);
-
/* Scene lock */
uiItemR(layout, &v3dptr, "lock_camera_and_layers", UI_ITEM_R_ICON_ONLY, "", ICON_NONE);
}
-
+
+ /* Currently Python calls this directly. */
+#if 0
uiTemplateEditModeSelection(layout, C);
+#endif
}
diff --git a/source/blender/editors/space_view3d/view3d_intern.h b/source/blender/editors/space_view3d/view3d_intern.h
index 6237bfe6693..006b0117b99 100644
--- a/source/blender/editors/space_view3d/view3d_intern.h
+++ b/source/blender/editors/space_view3d/view3d_intern.h
@@ -37,7 +37,10 @@
struct ARegion;
struct ARegionType;
+struct Base;
struct BoundBox;
+struct Gwn_Batch;
+struct Depsgraph;
struct DerivedMesh;
struct Object;
struct SmokeDomainSettings;
@@ -46,9 +49,12 @@ struct bContext;
struct bMotionPath;
struct bPoseChannel;
struct Mesh;
+struct ViewLayer;
struct wmOperatorType;
-struct wmWindowManager;
struct wmKeyConfig;
+struct wmManipulatorGroupType;
+struct wmManipulatorType;
+struct wmWindowManager;
/* drawing flags: */
enum {
@@ -57,12 +63,6 @@ enum {
DRAW_SCENESET = (1 << 2)
};
-/* draw_mesh_fancy/draw_mesh_textured draw_flags */
-enum {
- DRAW_MODIFIERS_PREVIEW = (1 << 0),
- DRAW_FACE_SELECT = (1 << 1)
-};
-
/* view3d_header.c */
void VIEW3D_OT_layers(struct wmOperatorType *ot);
@@ -99,8 +99,6 @@ void VIEW3D_OT_view_orbit(struct wmOperatorType *ot);
void VIEW3D_OT_view_roll(struct wmOperatorType *ot);
void VIEW3D_OT_clip_border(struct wmOperatorType *ot);
void VIEW3D_OT_cursor3d(struct wmOperatorType *ot);
-void VIEW3D_OT_manipulator(struct wmOperatorType *ot);
-void VIEW3D_OT_enable_manipulator(struct wmOperatorType *ot);
void VIEW3D_OT_render_border(struct wmOperatorType *ot);
void VIEW3D_OT_clear_render_border(struct wmOperatorType *ot);
void VIEW3D_OT_zoom_border(struct wmOperatorType *ot);
@@ -133,87 +131,31 @@ void VIEW3D_OT_walk(struct wmOperatorType *ot);
/* view3d_ruler.c */
void VIEW3D_OT_ruler(struct wmOperatorType *ot);
-/* drawanim.c */
-void draw_motion_paths_init(View3D *v3d, struct ARegion *ar);
-void draw_motion_path_instance(Scene *scene,
- struct Object *ob, struct bPoseChannel *pchan,
- struct bAnimVizSettings *avs, struct bMotionPath *mpath);
-void draw_motion_paths_cleanup(View3D *v3d);
-
-
-
/* drawobject.c */
-void draw_object(
- Scene *scene, struct ARegion *ar, View3D *v3d,
- Base *base, const short dflag);
-void draw_object_select(
- Scene *scene, ARegion *ar, View3D *v3d,
- Base *base, const short dflag);
-
-bool draw_glsl_material(Scene *scene, struct Object *ob, View3D *v3d, const char dt);
-void draw_object_instance(Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob, const char dt, int outline);
-void draw_object_backbufsel(Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob);
-void drawaxes(const float viewmat_local[4][4], float size, char drawtype);
-
-void view3d_cached_text_draw_begin(void);
-void view3d_cached_text_draw_add(const float co[3],
- const char *str, const size_t str_len,
- short xoffs, short flag, const unsigned char col[4]);
-void view3d_cached_text_draw_end(View3D *v3d, ARegion *ar, bool depth_write);
-
-bool check_object_draw_texture(struct Scene *scene, struct View3D *v3d, const char drawtype);
-
-enum {
- V3D_CACHE_TEXT_ZBUF = (1 << 0),
- V3D_CACHE_TEXT_WORLDSPACE = (1 << 1),
- V3D_CACHE_TEXT_ASCII = (1 << 2),
- V3D_CACHE_TEXT_GLOBALSPACE = (1 << 3),
- V3D_CACHE_TEXT_LOCALCLIP = (1 << 4)
-};
+void draw_object_backbufsel(struct Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d, struct Object *ob);
int view3d_effective_drawtype(const struct View3D *v3d);
-/* drawarmature.c */
-bool draw_armature(
- Scene *scene, View3D *v3d, ARegion *ar, Base *base,
- const short dt, const short dflag, const unsigned char ob_wire_col[4],
- const bool is_outline);
-
-/* drawmesh.c */
-void draw_mesh_textured(Scene *scene, View3D *v3d, RegionView3D *rv3d,
- struct Object *ob, struct DerivedMesh *dm, const int draw_flags);
-void draw_mesh_face_select(
- struct RegionView3D *rv3d, struct Mesh *me, struct DerivedMesh *dm,
- bool draw_select_edges);
-void draw_mesh_paint_weight_faces(struct DerivedMesh *dm, const bool do_light,
- void *facemask_cb, void *user_data);
-void draw_mesh_paint_vcolor_faces(struct DerivedMesh *dm, const bool use_light,
- void *facemask_cb, void *user_data,
- const struct Mesh *me);
-void draw_mesh_paint_weight_edges(RegionView3D *rv3d, struct DerivedMesh *dm,
- const bool use_depth, const bool use_alpha,
- void *edgemask_cb, void *user_data);
-void draw_mesh_paint(View3D *v3d, RegionView3D *rv3d,
- struct Object *ob, struct DerivedMesh *dm, const int draw_flags);
-
-/* drawsimdebug.c */
-void draw_sim_debug_data(Scene *scene, View3D *v3d, ARegion *ar);
-
/* view3d_draw.c */
void view3d_main_region_draw(const struct bContext *C, struct ARegion *ar);
+void view3d_draw_region_info(const struct bContext *C, struct ARegion *ar, const int offset);
void ED_view3d_draw_depth(
- Scene *scene,
+ struct Depsgraph *depsgraph,
struct ARegion *ar, View3D *v3d, bool alphaoverride);
-void ED_view3d_draw_depth_gpencil(Scene *scene, ARegion *ar, View3D *v3d);
+
+/* view3d_draw_legacy.c */
+void ED_view3d_draw_depth_gpencil(struct Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d);
+
void ED_view3d_draw_select_loop(
- ViewContext *vc, Scene *scene, View3D *v3d, ARegion *ar,
+ struct Depsgraph *depsgraph, ViewContext *vc, Scene *scene, struct ViewLayer *view_layer, View3D *v3d, ARegion *ar,
bool use_obedit_skip, bool use_nearest);
-void ED_view3d_after_add(ListBase *lb, Base *base, const short dflag);\
+void ED_view3d_draw_depth_loop(
+ struct Depsgraph *depsgraph, Scene *scene, ARegion *ar, View3D *v3d);
+
+void ED_view3d_after_add(ListBase *lb, Base *base, const short dflag);
-void circf(float x, float y, float rad);
-void circ(float x, float y, float rad);
void view3d_update_depths_rect(struct ARegion *ar, struct ViewDepths *d, struct rcti *rect);
float view3d_depth_near(struct ViewDepths *d);
@@ -228,9 +170,6 @@ void VIEW3D_OT_smoothview(struct wmOperatorType *ot);
void VIEW3D_OT_camera_to_view(struct wmOperatorType *ot);
void VIEW3D_OT_camera_to_view_selected(struct wmOperatorType *ot);
void VIEW3D_OT_object_as_camera(struct wmOperatorType *ot);
-void VIEW3D_OT_localview(struct wmOperatorType *ot);
-void VIEW3D_OT_game_start(struct wmOperatorType *ot);
-
bool ED_view3d_boundbox_clip_ex(const RegionView3D *rv3d, const struct BoundBox *bb, float obmat[4][4]);
bool ED_view3d_boundbox_clip(RegionView3D *rv3d, const struct BoundBox *bb);
@@ -257,9 +196,10 @@ void ED_view3d_smooth_view_force_finish(
struct View3D *v3d, struct ARegion *ar);
void view3d_winmatrix_set(
+ struct Depsgraph *depsgraph,
ARegion *ar, const View3D *v3d, const rcti *rect);
void view3d_viewmatrix_set(
- Scene *scene,
+ struct Depsgraph *depsgraph, Scene *scene,
const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2]);
void fly_modal_keymap(struct wmKeyConfig *keyconf);
@@ -275,7 +215,7 @@ void view3d_buttons_register(struct ARegionType *art);
/* view3d_camera_control.c */
struct View3DCameraControl *ED_view3d_cameracontrol_acquire(
- Scene *scene, View3D *v3d, RegionView3D *rv3d,
+ struct Depsgraph *depsgraph, Scene *scene, View3D *v3d, RegionView3D *rv3d,
const bool use_parent_root);
void ED_view3d_cameracontrol_update(
struct View3DCameraControl *vctrl,
@@ -284,13 +224,12 @@ void ED_view3d_cameracontrol_update(
void ED_view3d_cameracontrol_release(
struct View3DCameraControl *vctrl,
const bool restore);
-Object *ED_view3d_cameracontrol_object_get(
+struct Object *ED_view3d_cameracontrol_object_get(
struct View3DCameraControl *vctrl);
/* view3d_toolbar.c */
void VIEW3D_OT_toolshelf(struct wmOperatorType *ot);
void view3d_toolshelf_register(struct ARegionType *art);
-void view3d_tool_props_register(struct ARegionType *art);
/* view3d_snap.c */
bool ED_view3d_minmax_verts(struct Object *obedit, float min[3], float max[3]);
@@ -309,6 +248,23 @@ ARegion *view3d_has_tools_region(ScrArea *sa);
extern const char *view3d_context_dir[]; /* doc access */
+/* view3d_widgets.c */
+void VIEW3D_WGT_lamp_spot(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_lamp_area(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_lamp_target(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_camera(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_camera_view(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_force_field(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_empty_image(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_armature_spline(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WGT_navigate(struct wmManipulatorGroupType *wgt);
+
+void VIEW3D_WGT_ruler(struct wmManipulatorGroupType *wgt);
+void VIEW3D_WT_ruler_item(struct wmManipulatorType *wt);
+void VIEW3D_OT_ruler_add(struct wmOperatorType *ot);
+
+void VIEW3D_WT_navigate_rotate(struct wmManipulatorType *wt);
+
/* draw_volume.c */
void draw_smoke_volume(struct SmokeDomainSettings *sds, struct Object *ob,
const float min[3], const float max[3],
@@ -328,4 +284,3 @@ extern bool view3d_camera_border_hack_test;
#endif
#endif /* __VIEW3D_INTERN_H__ */
-
diff --git a/source/blender/editors/space_view3d/view3d_iterators.c b/source/blender/editors/space_view3d/view3d_iterators.c
index ef7b01f7a21..35127c7c8c6 100644
--- a/source/blender/editors/space_view3d/view3d_iterators.c
+++ b/source/blender/editors/space_view3d/view3d_iterators.c
@@ -40,6 +40,9 @@
#include "BKE_DerivedMesh.h"
#include "BKE_displist.h"
#include "BKE_editmesh.h"
+#include "BKE_context.h"
+
+#include "DEG_depsgraph.h"
#include "bmesh.h"
@@ -109,7 +112,9 @@ void meshobject_foreachScreenVert(
void *userData, eV3DProjTest clip_flag)
{
foreachScreenObjectVert_userData data;
- DerivedMesh *dm = mesh_get_derived_deform(vc->scene, vc->obact, CD_MASK_BAREMESH);
+ DerivedMesh *dm;
+
+ dm = mesh_get_derived_deform(vc->depsgraph, vc->scene, vc->obact, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -150,7 +155,9 @@ void mesh_foreachScreenVert(
void *userData, eV3DProjTest clip_flag)
{
foreachScreenVert_userData data;
- DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
+ DerivedMesh *dm;
+
+ dm = editbmesh_get_derived_cage(vc->depsgraph, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -204,7 +211,9 @@ void mesh_foreachScreenEdge(
void *userData, eV3DProjTest clip_flag)
{
foreachScreenEdge_userData data;
- DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
+ DerivedMesh *dm;
+
+ dm = editbmesh_get_derived_cage(vc->depsgraph, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
@@ -250,7 +259,9 @@ void mesh_foreachScreenFace(
void *userData, const eV3DProjTest clip_flag)
{
foreachScreenFace_userData data;
- DerivedMesh *dm = editbmesh_get_derived_cage(vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
+ DerivedMesh *dm;
+
+ dm = editbmesh_get_derived_cage(vc->depsgraph, vc->scene, vc->obedit, vc->em, CD_MASK_BAREMESH);
ED_view3d_check_mats_rv3d(vc->rv3d);
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_armature.c b/source/blender/editors/space_view3d/view3d_manipulator_armature.c
new file mode 100644
index 00000000000..5d3d88ff2a2
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_armature.c
@@ -0,0 +1,220 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_manipulator_armature.c
+ * \ingroup spview3d
+ */
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_armature.h"
+#include "BKE_action.h"
+#include "BKE_context.h"
+#include "BKE_object.h"
+
+#include "DNA_object_types.h"
+#include "DNA_armature_types.h"
+
+#include "ED_armature.h"
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "view3d_intern.h" /* own include */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Armature Spline Manipulator
+ *
+ * \{ */
+
+/*
+ * TODO(campbell): Current conversion is a approximation (usable not correct),
+ * we'll need to take the next/previous bones into account to get the tangent directions.
+ * First last matrices from 'b_bone_spline_setup' are close but also not quite accurate
+ * since they're not at either end-points on the curve.
+ *
+ * Likely we'll need a function especially to get the first/last orientations.
+ */
+
+#define BBONE_SCALE_Y 3.0f
+
+struct BoneSplineHandle {
+ wmManipulator *manipulator;
+ bPoseChannel *pchan;
+ /* We could remove, keep since at the moment for checking the conversion. */
+ float co[3];
+ int index;
+};
+
+struct BoneSplineWidgetGroup {
+ struct BoneSplineHandle handles[2];
+};
+
+static void manipulator_bbone_offset_get(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ struct BoneSplineHandle *bh = mpr_prop->custom_func.user_data;
+ bPoseChannel *pchan = bh->pchan;
+
+ float *value = value_p;
+ BLI_assert(mpr_prop->type->array_length == 3);
+
+ if (bh->index == 0) {
+ bh->co[1] = pchan->bone->ease1 / BBONE_SCALE_Y;
+ bh->co[0] = pchan->curveInX;
+ bh->co[2] = pchan->curveInY;
+ }
+ else {
+ bh->co[1] = -pchan->bone->ease2 / BBONE_SCALE_Y;
+ bh->co[0] = pchan->curveOutX;
+ bh->co[2] = pchan->curveOutY;
+ }
+ copy_v3_v3(value, bh->co);
+}
+
+static void manipulator_bbone_offset_set(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ struct BoneSplineHandle *bh = mpr_prop->custom_func.user_data;
+ bPoseChannel *pchan = bh->pchan;
+
+ const float *value = value_p;
+
+ BLI_assert(mpr_prop->type->array_length == 3);
+ copy_v3_v3(bh->co, value);
+
+ if (bh->index == 0) {
+ pchan->bone->ease1 = max_ff(0.0f, bh->co[1] * BBONE_SCALE_Y);
+ pchan->curveInX = bh->co[0];
+ pchan->curveInY = bh->co[2];
+ }
+ else {
+ pchan->bone->ease2 = max_ff(0.0f, -bh->co[1] * BBONE_SCALE_Y);
+ pchan->curveOutX = bh->co[0];
+ pchan->curveOutY = bh->co[2];
+ }
+
+}
+
+static bool WIDGETGROUP_armature_spline_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+ if (ob != NULL) {
+ const bArmature *arm = ob->data;
+ if (arm->drawtype == ARM_B_BONE) {
+ if (arm->act_bone && arm->act_bone->segments > 1) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+
+static void WIDGETGROUP_armature_spline_setup(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+ bPoseChannel *pchan = BKE_pose_channel_active(ob);
+
+ const wmManipulatorType *wt_grab = WM_manipulatortype_find("MANIPULATOR_WT_grab_3d", true);
+
+ struct BoneSplineWidgetGroup *bspline_group = MEM_callocN(sizeof(struct BoneSplineWidgetGroup), __func__);
+ mgroup->customdata = bspline_group;
+
+ /* Handles */
+ for (int i = 0; i < ARRAY_SIZE(bspline_group->handles); i++) {
+ wmManipulator *mpr;
+ mpr = bspline_group->handles[i].manipulator = WM_manipulator_new_ptr(wt_grab, mgroup, NULL);
+ RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_GRAB_STYLE_RING_2D);
+ RNA_enum_set(mpr->ptr, "draw_options",
+ ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL | ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW);
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_VALUE, true);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+
+ mpr->scale_basis = 0.06f;
+
+ if (i == 0) {
+ copy_v3_v3(mpr->matrix_basis[3], pchan->loc);
+ }
+ }
+}
+
+static void WIDGETGROUP_armature_spline_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ Object *ob = BKE_object_pose_armature_get(CTX_data_active_object(C));
+
+ if (!mgroup->customdata)
+ return;
+
+ struct BoneSplineWidgetGroup *bspline_group = mgroup->customdata;
+ bPoseChannel *pchan = BKE_pose_channel_active(ob);
+
+ /* Handles */
+ for (int i = 0; i < ARRAY_SIZE(bspline_group->handles); i++) {
+ wmManipulator *mpr = bspline_group->handles[i].manipulator;
+ bspline_group->handles[i].pchan = pchan;
+ bspline_group->handles[i].index = i;
+
+ float mat[4][4];
+ mul_m4_m4m4(mat, ob->obmat, (i == 0) ? pchan->disp_mat : pchan->disp_tail_mat);
+ copy_m4_m4(mpr->matrix_space, mat);
+
+ /* need to set property here for undo. TODO would prefer to do this in _init */
+ WM_manipulator_target_property_def_func(
+ mpr, "offset",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_bbone_offset_get,
+ .value_set_fn = manipulator_bbone_offset_set,
+ .range_get_fn = NULL,
+ .user_data = &bspline_group->handles[i],
+ });
+ }
+}
+
+void VIEW3D_WGT_armature_spline(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Armature Spline Widgets";
+ wgt->idname = "VIEW3D_WGT_armature_spline";
+
+ wgt->flag = (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_3D);
+
+ wgt->poll = WIDGETGROUP_armature_spline_poll;
+ wgt->setup = WIDGETGROUP_armature_spline_setup;
+ wgt->refresh = WIDGETGROUP_armature_spline_refresh;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_camera.c b/source/blender/editors/space_view3d/view3d_manipulator_camera.c
new file mode 100644
index 00000000000..87e550ba638
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_camera.c
@@ -0,0 +1,464 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_manipulator_camera.c
+ * \ingroup spview3d
+ */
+
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_camera.h"
+#include "BKE_context.h"
+
+#include "DNA_object_types.h"
+#include "DNA_camera_types.h"
+
+#include "ED_armature.h"
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "WM_message.h"
+
+#include "DEG_depsgraph_query.h"
+
+#include "view3d_intern.h" /* own include */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Camera Manipulators
+ * \{ */
+
+struct CameraWidgetGroup {
+ wmManipulator *dop_dist;
+ wmManipulator *focal_len;
+ wmManipulator *ortho_scale;
+};
+
+static bool WIDGETGROUP_camera_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Object *ob = CTX_data_active_object(C);
+ if (ob && ob->type == OB_CAMERA) {
+ Camera *camera = ob->data;
+ /* TODO: support overrides. */
+ if (camera->id.lib == NULL) {
+ return true;
+ }
+ }
+ return false;
+}
+
+static void WIDGETGROUP_camera_setup(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ const Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ Object *ob = CTX_data_active_object(C);
+ const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+ float dir[3];
+
+ const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true);
+
+ struct CameraWidgetGroup *camgroup = MEM_callocN(sizeof(struct CameraWidgetGroup), __func__);
+ mgroup->customdata = camgroup;
+
+ negate_v3_v3(dir, ob_eval->obmat[2]);
+
+ /* dof distance */
+ {
+ wmManipulator *mpr;
+ mpr = camgroup->dop_dist = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_CROSS);
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_HOVER, true);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_A, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+ }
+
+ /* focal length
+ * - logic/calculations are similar to BKE_camera_view_frame_ex, better keep in sync */
+ {
+ wmManipulator *mpr;
+ mpr = camgroup->focal_len = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ mpr->flag |= WM_MANIPULATOR_DRAW_NO_SCALE;
+ RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_CONE);
+ RNA_enum_set(mpr->ptr, "draw_options", ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+
+ mpr = camgroup->ortho_scale = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ mpr->flag |= WM_MANIPULATOR_DRAW_NO_SCALE;
+ RNA_enum_set(mpr->ptr, "draw_style", ED_MANIPULATOR_ARROW_STYLE_CONE);
+ RNA_enum_set(mpr->ptr, "draw_options", ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+ }
+}
+
+static void WIDGETGROUP_camera_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ if (!mgroup->customdata)
+ return;
+
+ const Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ struct CameraWidgetGroup *camgroup = mgroup->customdata;
+ Object *ob = CTX_data_active_object(C);
+ const Object *ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+ Camera *ca = ob->data;
+ PointerRNA camera_ptr;
+ float dir[3];
+
+ const float ob_scale_inv[3] = {
+ 1.0f / len_v3(ob_eval->obmat[0]),
+ 1.0f / len_v3(ob_eval->obmat[1]),
+ 1.0f / len_v3(ob_eval->obmat[2]),
+ };
+ const float ob_scale_uniform_inv = (ob_scale_inv[0] + ob_scale_inv[1] + ob_scale_inv[2]) / 3.0f;
+
+ RNA_pointer_create(&ca->id, &RNA_Camera, ca, &camera_ptr);
+
+ negate_v3_v3(dir, ob_eval->obmat[2]);
+
+ if (ca->flag & CAM_SHOWLIMITS) {
+ WM_manipulator_set_matrix_location(camgroup->dop_dist, ob_eval->obmat[3]);
+ WM_manipulator_set_matrix_rotation_from_yz_axis(camgroup->dop_dist, ob_eval->obmat[1], dir);
+ WM_manipulator_set_scale(camgroup->dop_dist, ca->drawsize);
+ WM_manipulator_set_flag(camgroup->dop_dist, WM_MANIPULATOR_HIDDEN, false);
+
+ /* need to set property here for undo. TODO would prefer to do this in _init */
+ WM_manipulator_target_property_def_rna(camgroup->dop_dist, "offset", &camera_ptr, "dof_distance", -1);
+ }
+ else {
+ WM_manipulator_set_flag(camgroup->dop_dist, WM_MANIPULATOR_HIDDEN, true);
+ }
+
+ /* TODO - make focal length/ortho ob_scale_inv widget optional */
+ const Scene *scene = CTX_data_scene(C);
+ const float aspx = (float)scene->r.xsch * scene->r.xasp;
+ const float aspy = (float)scene->r.ysch * scene->r.yasp;
+ const bool is_ortho = (ca->type == CAM_ORTHO);
+ const int sensor_fit = BKE_camera_sensor_fit(ca->sensor_fit, aspx, aspy);
+ wmManipulator *widget = is_ortho ? camgroup->ortho_scale : camgroup->focal_len;
+ float scale_matrix;
+ if (true) {
+ float offset[3];
+ float aspect[2];
+
+ WM_manipulator_set_flag(widget, WM_MANIPULATOR_HIDDEN, false);
+ WM_manipulator_set_flag(is_ortho ? camgroup->focal_len : camgroup->ortho_scale, WM_MANIPULATOR_HIDDEN, true);
+
+
+ /* account for lens shifting */
+ offset[0] = ((ob->size[0] > 0.0f) ? -2.0f : 2.0f) * ca->shiftx;
+ offset[1] = 2.0f * ca->shifty;
+ offset[2] = 0.0f;
+
+ /* get aspect */
+ aspect[0] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? 1.0f : aspx / aspy;
+ aspect[1] = (sensor_fit == CAMERA_SENSOR_FIT_HOR) ? aspy / aspx : 1.0f;
+
+ unit_m4(widget->matrix_basis);
+ WM_manipulator_set_matrix_location(widget, ob_eval->obmat[3]);
+ WM_manipulator_set_matrix_rotation_from_yz_axis(widget, ob_eval->obmat[1], dir);
+
+ if (is_ortho) {
+ scale_matrix = ca->ortho_scale * 0.5f;
+ }
+ else {
+ scale_matrix = ca->drawsize / ob_scale_uniform_inv;
+ }
+ mul_v3_fl(widget->matrix_basis[0], scale_matrix);
+ mul_v3_fl(widget->matrix_basis[1], scale_matrix);
+
+ RNA_float_set_array(widget->ptr, "aspect", aspect);
+
+ WM_manipulator_set_matrix_offset_location(widget, offset);
+ }
+
+ /* define & update properties */
+ {
+ const char *propname = is_ortho ? "ortho_scale" : "lens";
+ PropertyRNA *prop = RNA_struct_find_property(&camera_ptr, propname);
+ const wmManipulatorPropertyType *mpr_prop_type = WM_manipulatortype_target_property_find(widget->type, "offset");
+
+ WM_manipulator_target_property_clear_rna_ptr(widget, mpr_prop_type);
+
+ float min, max, range;
+ float step, precision;
+
+ /* get property range */
+ RNA_property_float_ui_range(&camera_ptr, prop, &min, &max, &step, &precision);
+ range = max - min;
+
+ ED_manipulator_arrow3d_set_range_fac(
+ widget, is_ortho ?
+ (ca->drawsize * range) :
+ (scale_matrix * range /
+ /* Half sensor, intentionally use sensor from camera and not calculated above. */
+ (0.5f * ((ca->sensor_fit == CAMERA_SENSOR_FIT_HOR) ? ca->sensor_x : ca->sensor_x))));
+
+ WM_manipulator_target_property_def_rna_ptr(widget, mpr_prop_type, &camera_ptr, prop, -1);
+ }
+
+}
+
+static void WIDGETGROUP_camera_message_subscribe(
+ const bContext *C, wmManipulatorGroup *mgroup, struct wmMsgBus *mbus)
+{
+ ARegion *ar = CTX_wm_region(C);
+ Object *ob = CTX_data_active_object(C);
+ Camera *ca = ob->data;
+
+ wmMsgSubscribeValue msg_sub_value_mpr_tag_refresh = {
+ .owner = ar,
+ .user_data = mgroup->parent_mmap,
+ .notify = WM_manipulator_do_msg_notify_tag_refresh,
+ };
+
+ {
+ extern PropertyRNA rna_Camera_dof_distance;
+ extern PropertyRNA rna_Camera_draw_size;
+ extern PropertyRNA rna_Camera_ortho_scale;
+ extern PropertyRNA rna_Camera_sensor_fit;
+ extern PropertyRNA rna_Camera_sensor_width;
+ extern PropertyRNA rna_Camera_shift_x;
+ extern PropertyRNA rna_Camera_shift_y;
+ extern PropertyRNA rna_Camera_type;
+ const PropertyRNA *props[] = {
+ &rna_Camera_dof_distance,
+ &rna_Camera_draw_size,
+ &rna_Camera_ortho_scale,
+ &rna_Camera_sensor_fit,
+ &rna_Camera_sensor_width,
+ &rna_Camera_shift_x,
+ &rna_Camera_shift_y,
+ &rna_Camera_type,
+ };
+
+ PointerRNA idptr;
+ RNA_id_pointer_create(&ca->id, &idptr);
+
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ WM_msg_subscribe_rna(mbus, &idptr, props[i], &msg_sub_value_mpr_tag_refresh, __func__);
+ }
+ }
+
+ /* Subscribe to render settings */
+ {
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, resolution_x, &msg_sub_value_mpr_tag_refresh);
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, resolution_y, &msg_sub_value_mpr_tag_refresh);
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, pixel_aspect_x, &msg_sub_value_mpr_tag_refresh);
+ WM_msg_subscribe_rna_anon_prop(mbus, RenderSettings, pixel_aspect_y, &msg_sub_value_mpr_tag_refresh);
+ }
+}
+
+void VIEW3D_WGT_camera(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Camera Widgets";
+ wgt->idname = "VIEW3D_WGT_camera";
+
+ wgt->flag = (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_3D |
+ WM_MANIPULATORGROUPTYPE_DEPTH_3D);
+
+ wgt->poll = WIDGETGROUP_camera_poll;
+ wgt->setup = WIDGETGROUP_camera_setup;
+ wgt->refresh = WIDGETGROUP_camera_refresh;
+ wgt->message_subscribe = WIDGETGROUP_camera_message_subscribe;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name CameraView Manipulators
+ * \{ */
+
+struct CameraViewWidgetGroup {
+ wmManipulator *border;
+
+ struct {
+ rctf *edit_border;
+ rctf view_border;
+ } state;
+};
+
+/* scale callbacks */
+static void manipulator_render_border_prop_matrix_get(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ struct CameraViewWidgetGroup *viewgroup = mpr_prop->custom_func.user_data;
+ const rctf *border = viewgroup->state.edit_border;
+
+ unit_m4(matrix);
+ matrix[0][0] = BLI_rctf_size_x(border);
+ matrix[1][1] = BLI_rctf_size_y(border);
+ matrix[3][0] = BLI_rctf_cent_x(border);
+ matrix[3][1] = BLI_rctf_cent_y(border);
+}
+
+static void manipulator_render_border_prop_matrix_set(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ const float (*matrix)[4] = value_p;
+ struct CameraViewWidgetGroup *viewgroup = mpr_prop->custom_func.user_data;
+ rctf *border = viewgroup->state.edit_border;
+ BLI_assert(mpr_prop->type->array_length == 16);
+
+ BLI_rctf_resize(border, len_v3(matrix[0]), len_v3(matrix[1]));
+ BLI_rctf_recenter(border, matrix[3][0], matrix[3][1]);
+ BLI_rctf_isect(&(rctf){.xmin = 0, .ymin = 0, .xmax = 1, .ymax = 1}, border, border);
+}
+
+static bool WIDGETGROUP_camera_view_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Scene *scene = CTX_data_scene(C);
+
+ /* This is just so the border isn't always in the way,
+ * stealing mouse clicks from regular usage.
+ * We could change the rules for when to show. */
+ {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ if (scene->camera != OBACT(view_layer)) {
+ return false;
+ }
+ }
+
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+ View3D *v3d = CTX_wm_view3d(C);
+ if (rv3d->persp == RV3D_CAMOB) {
+ if (scene->r.mode & R_BORDER) {
+ /* TODO: support overrides. */
+ if (scene->id.lib == NULL) {
+ return true;
+ }
+ }
+ }
+ else if (v3d->flag2 & V3D_RENDER_BORDER) {
+ return true;
+ }
+ return false;
+}
+
+static void WIDGETGROUP_camera_view_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ struct CameraViewWidgetGroup *viewgroup = MEM_mallocN(sizeof(struct CameraViewWidgetGroup), __func__);
+
+ viewgroup->border = WM_manipulator_new("MANIPULATOR_WT_cage_2d", mgroup, NULL);
+
+ RNA_enum_set(viewgroup->border->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE | ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE);
+ /* Box style is more subtle in this case. */
+ RNA_enum_set(viewgroup->border->ptr, "draw_style", ED_MANIPULATOR_CAGE2D_STYLE_BOX);
+
+
+ mgroup->customdata = viewgroup;
+}
+
+static void WIDGETGROUP_camera_view_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct CameraViewWidgetGroup *viewgroup = mgroup->customdata;
+
+ ARegion *ar = CTX_wm_region(C);
+ struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ RegionView3D *rv3d = ar->regiondata;
+ if (rv3d->persp == RV3D_CAMOB) {
+ Scene *scene = CTX_data_scene(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ ED_view3d_calc_camera_border(scene, depsgraph, ar, v3d, rv3d, &viewgroup->state.view_border, false);
+ }
+ else {
+ viewgroup->state.view_border = (rctf){.xmin = 0, .ymin = 0, .xmax = ar->winx, .ymax = ar->winy};
+ }
+
+ wmManipulator *mpr = viewgroup->border;
+ unit_m4(mpr->matrix_space);
+ mul_v3_fl(mpr->matrix_space[0], BLI_rctf_size_x(&viewgroup->state.view_border));
+ mul_v3_fl(mpr->matrix_space[1], BLI_rctf_size_y(&viewgroup->state.view_border));
+ mpr->matrix_space[3][0] = viewgroup->state.view_border.xmin;
+ mpr->matrix_space[3][1] = viewgroup->state.view_border.ymin;
+}
+
+static void WIDGETGROUP_camera_view_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct CameraViewWidgetGroup *viewgroup = mgroup->customdata;
+
+ View3D *v3d = CTX_wm_view3d(C);
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+ Scene *scene = CTX_data_scene(C);
+
+ {
+ wmManipulator *mpr = viewgroup->border;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+
+ RNA_enum_set(viewgroup->border->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE | ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE);
+
+ if (rv3d->persp == RV3D_CAMOB) {
+ viewgroup->state.edit_border = &scene->r.border;
+ }
+ else {
+ viewgroup->state.edit_border = &v3d->render_border;
+ }
+
+ WM_manipulator_target_property_def_func(
+ mpr, "matrix",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_render_border_prop_matrix_get,
+ .value_set_fn = manipulator_render_border_prop_matrix_set,
+ .range_get_fn = NULL,
+ .user_data = viewgroup,
+ });
+ }
+
+}
+
+void VIEW3D_WGT_camera_view(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Camera View Widgets";
+ wgt->idname = "VIEW3D_WGT_camera_view";
+
+ wgt->flag = (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_SCALE);
+
+ wgt->poll = WIDGETGROUP_camera_view_poll;
+ wgt->setup = WIDGETGROUP_camera_view_setup;
+ wgt->draw_prepare = WIDGETGROUP_camera_view_draw_prepare;
+ wgt->refresh = WIDGETGROUP_camera_view_refresh;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_empty.c b/source/blender/editors/space_view3d/view3d_manipulator_empty.c
new file mode 100644
index 00000000000..1d56c5ee7f4
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_empty.c
@@ -0,0 +1,196 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_manipulator_empty.c
+ * \ingroup spview3d
+ */
+
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
+#include "BKE_image.h"
+
+#include "DNA_object_types.h"
+#include "DNA_lamp_types.h"
+
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "view3d_intern.h" /* own include */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Empty Image Manipulators
+ * \{ */
+
+struct EmptyImageWidgetGroup {
+ wmManipulator *manipulator;
+ struct {
+ Object *ob;
+ float dims[2];
+ } state;
+};
+
+/* translate callbacks */
+static void manipulator_empty_image_prop_matrix_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ struct EmptyImageWidgetGroup *imgroup = mpr_prop->custom_func.user_data;
+ const Object *ob = imgroup->state.ob;
+
+ unit_m4(matrix);
+ matrix[0][0] = ob->empty_drawsize;
+ matrix[1][1] = ob->empty_drawsize;
+
+ float dims[2] = {0.0f, 0.0f};
+ RNA_float_get_array(mpr->ptr, "dimensions", dims);
+ dims[0] *= ob->empty_drawsize;
+ dims[1] *= ob->empty_drawsize;
+
+ matrix[3][0] = (ob->ima_ofs[0] * dims[0]) + (0.5f * dims[0]);
+ matrix[3][1] = (ob->ima_ofs[1] * dims[1]) + (0.5f * dims[1]);
+}
+
+static void manipulator_empty_image_prop_matrix_set(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ const float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ struct EmptyImageWidgetGroup *imgroup = mpr_prop->custom_func.user_data;
+ Object *ob = imgroup->state.ob;
+
+ ob->empty_drawsize = matrix[0][0];
+
+ float dims[2];
+ RNA_float_get_array(mpr->ptr, "dimensions", dims);
+ dims[0] *= ob->empty_drawsize;
+ dims[1] *= ob->empty_drawsize;
+
+ ob->ima_ofs[0] = (matrix[3][0] - (0.5f * dims[0])) / dims[0];
+ ob->ima_ofs[1] = (matrix[3][1] - (0.5f * dims[1])) / dims[1];
+}
+
+static bool WIDGETGROUP_empty_image_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Object *ob = CTX_data_active_object(C);
+
+ if (ob && ob->type == OB_EMPTY) {
+ return (ob->empty_drawtype == OB_EMPTY_IMAGE);
+ }
+ return false;
+}
+
+static void WIDGETGROUP_empty_image_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ struct EmptyImageWidgetGroup *imgroup = MEM_mallocN(sizeof(struct EmptyImageWidgetGroup), __func__);
+ imgroup->manipulator = WM_manipulator_new("MANIPULATOR_WT_cage_2d", mgroup, NULL);
+ wmManipulator *mpr = imgroup->manipulator;
+ RNA_enum_set(mpr->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE);
+
+ mgroup->customdata = imgroup;
+
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_HOVER, true);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+}
+
+static void WIDGETGROUP_empty_image_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct EmptyImageWidgetGroup *imgroup = mgroup->customdata;
+ Object *ob = CTX_data_active_object(C);
+ wmManipulator *mpr = imgroup->manipulator;
+
+ copy_m4_m4(mpr->matrix_basis, ob->obmat);
+
+ RNA_enum_set(mpr->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE |
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE |
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM);
+
+ imgroup->state.ob = ob;
+
+ /* Use dimensions for aspect. */
+ if (ob->data != NULL) {
+ const Image *image = ob->data;
+ ImageUser iuser = *ob->iuser;
+ float size[2];
+ BKE_image_get_size_fl(ob->data, &iuser, size);
+
+ /* Get the image aspect even if the buffer is invalid */
+ if (image->aspx > image->aspy) {
+ size[1] *= image->aspy / image->aspx;
+ }
+ else if (image->aspx < image->aspy) {
+ size[0] *= image->aspx / image->aspy;
+ }
+
+ const float dims_max = max_ff(size[0], size[1]);
+ imgroup->state.dims[0] = size[0] / dims_max;
+ imgroup->state.dims[1] = size[1] / dims_max;
+ }
+ else {
+ copy_v2_fl(imgroup->state.dims, 1.0f);
+ }
+ RNA_float_set_array(mpr->ptr, "dimensions", imgroup->state.dims);
+
+ WM_manipulator_target_property_def_func(
+ mpr, "matrix",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_empty_image_prop_matrix_get,
+ .value_set_fn = manipulator_empty_image_prop_matrix_set,
+ .range_get_fn = NULL,
+ .user_data = imgroup,
+ });
+}
+
+void VIEW3D_WGT_empty_image(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Area Lamp Widgets";
+ wgt->idname = "VIEW3D_WGT_empty_image";
+
+ wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_3D |
+ WM_MANIPULATORGROUPTYPE_DEPTH_3D);
+
+ wgt->poll = WIDGETGROUP_empty_image_poll;
+ wgt->setup = WIDGETGROUP_empty_image_setup;
+ wgt->refresh = WIDGETGROUP_empty_image_refresh;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_forcefield.c b/source/blender/editors/space_view3d/view3d_manipulator_forcefield.c
new file mode 100644
index 00000000000..e76be448be4
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_forcefield.c
@@ -0,0 +1,118 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_manipulator_forcefield.c
+ * \ingroup spview3d
+ */
+
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
+
+#include "DNA_object_types.h"
+#include "DNA_object_force_types.h"
+
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "view3d_intern.h" /* own include */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Force Field Manipulators
+ * \{ */
+
+static bool WIDGETGROUP_forcefield_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Object *ob = CTX_data_active_object(C);
+
+ return (ob && ob->pd && ob->pd->forcefield);
+}
+
+static void WIDGETGROUP_forcefield_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ /* only wind effector for now */
+ wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__);
+ mgroup->customdata = wwrapper;
+
+ wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_arrow_3d", mgroup, NULL);
+ wmManipulator *mpr = wwrapper->manipulator;
+ RNA_enum_set(mpr->ptr, "draw_options", ED_MANIPULATOR_ARROW_STYLE_CONSTRAINED);
+ ED_manipulator_arrow3d_set_ui_range(mpr, -200.0f, 200.0f);
+ ED_manipulator_arrow3d_set_range_fac(mpr, 6.0f);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+}
+
+static void WIDGETGROUP_forcefield_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = mgroup->customdata;
+ wmManipulator *mpr = wwrapper->manipulator;
+ Object *ob = CTX_data_active_object(C);
+ PartDeflect *pd = ob->pd;
+
+ if (pd->forcefield == PFIELD_WIND) {
+ const float size = (ob->type == OB_EMPTY) ? ob->empty_drawsize : 1.0f;
+ const float ofs[3] = {0.0f, -size, 0.0f};
+ PointerRNA field_ptr;
+
+ RNA_pointer_create(&ob->id, &RNA_FieldSettings, pd, &field_ptr);
+ WM_manipulator_set_matrix_location(mpr, ob->obmat[3]);
+ WM_manipulator_set_matrix_rotation_from_z_axis(mpr, ob->obmat[2]);
+ WM_manipulator_set_matrix_offset_location(mpr, ofs);
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+ WM_manipulator_target_property_def_rna(mpr, "offset", &field_ptr, "strength", -1);
+ }
+ else {
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
+ }
+}
+
+void VIEW3D_WGT_force_field(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Force Field Widgets";
+ wgt->idname = "VIEW3D_WGT_force_field";
+
+ wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_3D |
+ WM_MANIPULATORGROUPTYPE_SCALE |
+ WM_MANIPULATORGROUPTYPE_DEPTH_3D);
+
+ wgt->poll = WIDGETGROUP_forcefield_poll;
+ wgt->setup = WIDGETGROUP_forcefield_setup;
+ wgt->refresh = WIDGETGROUP_forcefield_refresh;
+}
+
+/** \} */
+
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_lamp.c b/source/blender/editors/space_view3d/view3d_manipulator_lamp.c
new file mode 100644
index 00000000000..93b6b69a105
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_lamp.c
@@ -0,0 +1,289 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_manipulator_lamp.c
+ * \ingroup spview3d
+ */
+
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
+
+#include "DNA_object_types.h"
+#include "DNA_lamp_types.h"
+
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "view3d_intern.h" /* own include */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Spot Lamp Manipulators
+ * \{ */
+
+static bool WIDGETGROUP_lamp_spot_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Object *ob = CTX_data_active_object(C);
+
+ if (ob && ob->type == OB_LAMP) {
+ Lamp *la = ob->data;
+ return (la->type == LA_SPOT);
+ }
+ return false;
+}
+
+static void WIDGETGROUP_lamp_spot_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__);
+
+ wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_arrow_3d", mgroup, NULL);
+ wmManipulator *mpr = wwrapper->manipulator;
+ RNA_enum_set(mpr->ptr, "draw_options", ED_MANIPULATOR_ARROW_STYLE_INVERTED);
+
+ mgroup->customdata = wwrapper;
+
+ ED_manipulator_arrow3d_set_range_fac(mpr, 4.0f);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_SECONDARY, mpr->color);
+}
+
+static void WIDGETGROUP_lamp_spot_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = mgroup->customdata;
+ wmManipulator *mpr = wwrapper->manipulator;
+ Object *ob = CTX_data_active_object(C);
+ Lamp *la = ob->data;
+ float dir[3];
+
+ negate_v3_v3(dir, ob->obmat[2]);
+
+ WM_manipulator_set_matrix_rotation_from_z_axis(mpr, dir);
+ WM_manipulator_set_matrix_location(mpr, ob->obmat[3]);
+
+ /* need to set property here for undo. TODO would prefer to do this in _init */
+ PointerRNA lamp_ptr;
+ const char *propname = "spot_size";
+ RNA_pointer_create(&la->id, &RNA_Lamp, la, &lamp_ptr);
+ WM_manipulator_target_property_def_rna(mpr, "offset", &lamp_ptr, propname, -1);
+}
+
+void VIEW3D_WGT_lamp_spot(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Spot Lamp Widgets";
+ wgt->idname = "VIEW3D_WGT_lamp_spot";
+
+ wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_3D |
+ WM_MANIPULATORGROUPTYPE_DEPTH_3D);
+
+ wgt->poll = WIDGETGROUP_lamp_spot_poll;
+ wgt->setup = WIDGETGROUP_lamp_spot_setup;
+ wgt->refresh = WIDGETGROUP_lamp_spot_refresh;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Area Lamp Manipulators
+ * \{ */
+
+/* scale callbacks */
+static void manipulator_area_lamp_prop_matrix_get(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ BLI_assert(mpr_prop->type->array_length == 16);
+ float (*matrix)[4] = value_p;
+ const Lamp *la = mpr_prop->custom_func.user_data;
+
+ matrix[0][0] = la->area_size;
+ matrix[1][1] = (la->area_shape == LA_AREA_RECT) ? la->area_sizey : la->area_size;
+}
+
+static void manipulator_area_lamp_prop_matrix_set(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ const float (*matrix)[4] = value_p;
+ BLI_assert(mpr_prop->type->array_length == 16);
+ Lamp *la = mpr_prop->custom_func.user_data;
+
+ if (la->area_shape == LA_AREA_RECT) {
+ la->area_size = len_v3(matrix[0]);
+ la->area_sizey = len_v3(matrix[1]);
+ }
+ else {
+ la->area_size = len_v3(matrix[0]);
+ }
+}
+
+static bool WIDGETGROUP_lamp_area_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Object *ob = CTX_data_active_object(C);
+
+ if (ob && ob->type == OB_LAMP) {
+ Lamp *la = ob->data;
+ return (la->type == LA_AREA);
+ }
+ return false;
+}
+
+static void WIDGETGROUP_lamp_area_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__);
+ wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_cage_2d", mgroup, NULL);
+ wmManipulator *mpr = wwrapper->manipulator;
+ RNA_enum_set(mpr->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE);
+
+ mgroup->customdata = wwrapper;
+
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_HOVER, true);
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+}
+
+static void WIDGETGROUP_lamp_area_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = mgroup->customdata;
+ Object *ob = CTX_data_active_object(C);
+ Lamp *la = ob->data;
+ wmManipulator *mpr = wwrapper->manipulator;
+
+ copy_m4_m4(mpr->matrix_basis, ob->obmat);
+
+ RNA_enum_set(mpr->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE |
+ ((la->area_shape == LA_AREA_SQUARE) ? ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE_UNIFORM : 0));
+
+ /* need to set property here for undo. TODO would prefer to do this in _init */
+ WM_manipulator_target_property_def_func(
+ mpr, "matrix",
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = manipulator_area_lamp_prop_matrix_get,
+ .value_set_fn = manipulator_area_lamp_prop_matrix_set,
+ .range_get_fn = NULL,
+ .user_data = la,
+ });
+}
+
+void VIEW3D_WGT_lamp_area(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Area Lamp Widgets";
+ wgt->idname = "VIEW3D_WGT_lamp_area";
+
+ wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_3D |
+ WM_MANIPULATORGROUPTYPE_DEPTH_3D);
+
+ wgt->poll = WIDGETGROUP_lamp_area_poll;
+ wgt->setup = WIDGETGROUP_lamp_area_setup;
+ wgt->refresh = WIDGETGROUP_lamp_area_refresh;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Lamp Target Manipulator
+ * \{ */
+
+static bool WIDGETGROUP_lamp_target_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ Object *ob = CTX_data_active_object(C);
+
+ if (ob != NULL) {
+ if (ob->type == OB_LAMP) {
+ Lamp *la = ob->data;
+ return (ELEM(la->type, LA_SUN, LA_SPOT, LA_HEMI, LA_AREA));
+ }
+#if 0
+ else if (ob->type == OB_CAMERA) {
+ return true;
+ }
+#endif
+ }
+ return false;
+}
+
+static void WIDGETGROUP_lamp_target_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = MEM_mallocN(sizeof(wmManipulatorWrapper), __func__);
+ wwrapper->manipulator = WM_manipulator_new("MANIPULATOR_WT_grab_3d", mgroup, NULL);
+ wmManipulator *mpr = wwrapper->manipulator;
+
+ mgroup->customdata = wwrapper;
+
+ UI_GetThemeColor3fv(TH_MANIPULATOR_PRIMARY, mpr->color);
+ UI_GetThemeColor3fv(TH_MANIPULATOR_HI, mpr->color_hi);
+
+ mpr->scale_basis = 0.06f;
+
+ wmOperatorType *ot = WM_operatortype_find("OBJECT_OT_transform_axis_target", true);
+
+ RNA_enum_set(mpr->ptr, "draw_options",
+ ED_MANIPULATOR_GRAB_DRAW_FLAG_FILL | ED_MANIPULATOR_GRAB_DRAW_FLAG_ALIGN_VIEW);
+
+ WM_manipulator_operator_set(mpr, 0, ot, NULL);
+}
+
+static void WIDGETGROUP_lamp_target_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmManipulatorWrapper *wwrapper = mgroup->customdata;
+ Object *ob = CTX_data_active_object(C);
+ wmManipulator *mpr = wwrapper->manipulator;
+
+ copy_m4_m4(mpr->matrix_basis, ob->obmat);
+ unit_m4(mpr->matrix_offset);
+ mpr->matrix_offset[3][2] = -2.4f / mpr->scale_basis;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_DRAW_OFFSET_SCALE, true);
+}
+
+void VIEW3D_WGT_lamp_target(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Target Lamp Widgets";
+ wgt->idname = "VIEW3D_WGT_lamp_target";
+
+ wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_3D);
+
+ wgt->poll = WIDGETGROUP_lamp_target_poll;
+ wgt->setup = WIDGETGROUP_lamp_target_setup;
+ wgt->draw_prepare = WIDGETGROUP_lamp_target_draw_prepare;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_navigate.c b/source/blender/editors/space_view3d/view3d_manipulator_navigate.c
new file mode 100644
index 00000000000..2d3f42f9c61
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_navigate.c
@@ -0,0 +1,360 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_manipulator_navigate.c
+ * \ingroup spview3d
+ */
+
+#include "BLI_blenlib.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
+
+#include "DNA_object_types.h"
+
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "view3d_intern.h" /* own include */
+
+/* -------------------------------------------------------------------- */
+/** \name View3D Navigation Manipulator Group
+ * \{ */
+
+/* Offset from screen edge. */
+#define MANIPULATOR_OFFSET_FAC 2.5
+/* Size of main icon. */
+#define MANIPULATOR_SIZE 64
+/* Factor for size of smaller button. */
+#define MANIPULATOR_MINI_FAC 0.5
+/* How much mini buttons offset from the primary. */
+#define MANIPULATOR_MINI_OFFSET_FAC 0.6666f
+
+
+enum {
+ MPR_MOVE = 0,
+ MPR_ROTATE = 1,
+ MPR_ZOOM = 2,
+
+ /* just buttons */
+ /* overlaps MPR_ORTHO (switch between) */
+ MPR_PERSP = 3,
+ MPR_ORTHO = 4,
+ MPR_CAMERA = 5,
+
+ MPR_TOTAL = 6,
+};
+
+/* Vector icons compatible with 'GPU_batch_from_poly_2d_encoded' */
+static const uchar shape_camera[] = {
+ 0xa3, 0x19, 0x78, 0x55, 0x4d, 0x19, 0x4f, 0x0a, 0x7f, 0x00, 0xb0, 0x0a, 0xa9, 0x19,
+ 0xa9, 0x19, 0x25, 0xda, 0x0a, 0xb0, 0x00, 0x7f, 0x0a, 0x4f, 0x25, 0x25, 0x4f, 0x0a,
+ 0x4d, 0x19, 0x47, 0x19, 0x65, 0x55, 0x41, 0x55, 0x41, 0x9e, 0x43, 0xa8, 0x38, 0xb3,
+ 0x34, 0xc3, 0x38, 0xd2, 0x43, 0xdd, 0x53, 0xe1, 0x62, 0xdd, 0x6d, 0xd2, 0x72, 0xc3,
+ 0x78, 0xc3, 0x7c, 0xd2, 0x87, 0xdd, 0x96, 0xe1, 0xa6, 0xdd, 0xb1, 0xd2, 0xb5, 0xc3,
+ 0xb1, 0xb3, 0xa6, 0xa8, 0xa9, 0x9e, 0xa9, 0x8c, 0xbb, 0x8c, 0xbb, 0x86, 0xc7, 0x86,
+ 0xe0, 0x9e, 0xe0, 0x55, 0xc7, 0x6d, 0xbb, 0x6d, 0xbb, 0x67, 0xa9, 0x67, 0xa9, 0x55,
+ 0x8a, 0x55, 0xa9, 0x19, 0xb0, 0x0a, 0xda, 0x25, 0xf5, 0x4f, 0xff, 0x80, 0xf5, 0xb0,
+ 0xda, 0xda, 0xb0, 0xf5, 0x80, 0xff, 0x4f, 0xf5, 0x4f, 0xf5, 0x7c, 0xb3, 0x78, 0xc3,
+ 0x72, 0xc3, 0x6d, 0xb3, 0x62, 0xa8, 0x53, 0xa4, 0x43, 0xa8, 0x41, 0x9e, 0xa9, 0x9e,
+ 0xa6, 0xa8, 0x96, 0xa4, 0x87, 0xa8, 0x87, 0xa8,
+};
+static const uchar shape_ortho[] = {
+ 0x85, 0x15, 0x85, 0x7c, 0xde, 0xb3, 0xde, 0xb8, 0xd9, 0xba, 0x80, 0x85, 0x27, 0xba,
+ 0x22, 0xb8, 0x22, 0xb3, 0x7b, 0x7c, 0x7b, 0x15, 0x80, 0x12, 0x80, 0x12, 0x1d, 0xba,
+ 0x80, 0xf2, 0x80, 0xff, 0x4f, 0xf5, 0x25, 0xda, 0x0a, 0xb0, 0x00, 0x7f, 0x0a, 0x4f,
+ 0x25, 0x25, 0x4f, 0x0a, 0x7f, 0x00, 0x80, 0x0d, 0x1d, 0x45, 0x1d, 0x45, 0xb0, 0x0a,
+ 0xda, 0x25, 0xf5, 0x4f, 0xff, 0x80, 0xf5, 0xb0, 0xda, 0xda, 0xb0, 0xf5, 0x80, 0xff,
+ 0x80, 0xf2, 0xe3, 0xba, 0xe3, 0x45, 0x80, 0x0d, 0x7f, 0x00, 0x7f, 0x00,
+};
+static const uchar shape_pan[] = {
+ 0xbf, 0x4c, 0xbf, 0x66, 0x99, 0x66, 0x99, 0x40, 0xb2, 0x40, 0x7f, 0x0d, 0x7f, 0x00,
+ 0xb0, 0x0a, 0xda, 0x25, 0xf5, 0x4f, 0xff, 0x80, 0xf5, 0xb0, 0xda, 0xda, 0xb0, 0xf5,
+ 0x80, 0xff, 0x80, 0xf2, 0xb3, 0xbf, 0x99, 0xbf, 0x99, 0x99, 0xbf, 0x99, 0xbf, 0xb2,
+ 0xf2, 0x7f, 0xf2, 0x7f, 0x40, 0xb3, 0x40, 0x99, 0x66, 0x99, 0x66, 0xbf, 0x4d, 0xbf,
+ 0x80, 0xf2, 0x80, 0xff, 0x4f, 0xf5, 0x25, 0xda, 0x0a, 0xb0, 0x00, 0x7f, 0x0a, 0x4f,
+ 0x25, 0x25, 0x4f, 0x0a, 0x7f, 0x00, 0x7f, 0x0d, 0x4c, 0x40, 0x66, 0x40, 0x66, 0x66,
+ 0x40, 0x66, 0x40, 0x4d, 0x0d, 0x80, 0x0d, 0x80,
+};
+static const uchar shape_persp[] = {
+ 0xda, 0xda, 0xb0, 0xf5, 0x80, 0xff, 0x4f, 0xf5, 0x25, 0xda, 0x0a, 0xb0, 0x00, 0x7f,
+ 0x0a, 0x4f, 0x25, 0x25, 0x4f, 0x0a, 0x7f, 0x00, 0x80, 0x07, 0x30, 0x50, 0x18, 0xbd,
+ 0x80, 0xdb, 0xe8, 0xbd, 0xf5, 0xb0, 0xf5, 0xb0, 0x83, 0x0f, 0x87, 0x7b, 0xe2, 0xb7,
+ 0xe3, 0xba, 0xe0, 0xbb, 0x80, 0x87, 0x20, 0xbb, 0x1d, 0xba, 0x1d, 0xb7, 0x78, 0x7b,
+ 0x7d, 0x0f, 0x80, 0x0c, 0x80, 0x0c, 0xd0, 0x50, 0x80, 0x07, 0x7f, 0x00, 0xb0, 0x0a,
+ 0xda, 0x25, 0xf5, 0x4f, 0xff, 0x80, 0xf5, 0xb0, 0xe8, 0xbd, 0xe8, 0xbd,
+};
+static const uchar shape_zoom[] = {
+ 0xad, 0x7f, 0xf1, 0x7f, 0xff, 0x80, 0xf5, 0xb0, 0xda, 0xda, 0xb0, 0xf5, 0x80, 0xff,
+ 0x4f, 0xf5, 0x25, 0xda, 0x0a, 0xb0, 0x00, 0x7f, 0x0d, 0x7f, 0x52, 0x7f, 0x69, 0xb7,
+ 0x48, 0xb7, 0x80, 0xd8, 0xb8, 0xb7, 0x96, 0xb7, 0x96, 0xb7, 0x7f, 0x2f, 0x0d, 0x7f,
+ 0x00, 0x7f, 0x0a, 0x4f, 0x25, 0x25, 0x4f, 0x0a, 0x7f, 0x00, 0xb0, 0x0a, 0xda, 0x25,
+ 0xf5, 0x4f, 0xff, 0x80, 0xf1, 0x7f, 0xf1, 0x7f,
+};
+
+
+struct NavigateManipulatorInfo {
+ const char *opname;
+ const char *manipulator;
+ const unsigned char *shape;
+ uint shape_size;
+};
+
+#define SHAPE_VARS(shape_id) shape = shape_id, .shape_size = ARRAY_SIZE(shape_id)
+
+struct NavigateManipulatorInfo g_navigate_params[MPR_TOTAL] = {
+ {
+ .opname = "VIEW3D_OT_move",
+ .manipulator = "MANIPULATOR_WT_button_2d",
+ .SHAPE_VARS(shape_pan),
+ }, {
+ .opname = "VIEW3D_OT_rotate",
+ .manipulator = "VIEW3D_WT_navigate_rotate",
+ .shape = NULL,
+ .shape_size = 0,
+ }, {
+ .opname = "VIEW3D_OT_zoom",
+ .manipulator = "MANIPULATOR_WT_button_2d",
+ .SHAPE_VARS(shape_zoom),
+ }, {
+ .opname = "VIEW3D_OT_view_persportho",
+ .manipulator = "MANIPULATOR_WT_button_2d",
+ .SHAPE_VARS(shape_persp),
+ }, {
+ .opname = "VIEW3D_OT_view_persportho",
+ .manipulator = "MANIPULATOR_WT_button_2d",
+ .SHAPE_VARS(shape_ortho),
+ }, {
+ .opname = "VIEW3D_OT_viewnumpad",
+ .manipulator = "MANIPULATOR_WT_button_2d",
+ .SHAPE_VARS(shape_camera),
+ },
+};
+
+#undef SHAPE_VARS
+
+struct NavigateWidgetGroup {
+ wmManipulator *mpr_array[MPR_TOTAL];
+ /* Store the view state to check for changes. */
+ struct {
+ struct {
+ short winx, winy;
+ } ar;
+ struct {
+ char is_persp;
+ char viewlock;
+ } rv3d;
+ } state;
+ int region_size[2];
+ bool is_persp;
+};
+
+static bool WIDGETGROUP_navigate_poll(const bContext *UNUSED(C), wmManipulatorGroupType *UNUSED(wgt))
+{
+ if (U.manipulator_flag & USER_MANIPULATOR_DRAW_NAVIGATE) {
+ return true;
+ }
+ return false;
+
+}
+
+static void WIDGETGROUP_navigate_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ struct NavigateWidgetGroup *navgroup = MEM_callocN(sizeof(struct NavigateWidgetGroup), __func__);
+
+ navgroup->region_size[0] = -1;
+ navgroup->region_size[1] = -1;
+
+ wmOperatorType *ot_viewnumpad = WM_operatortype_find("VIEW3D_OT_viewnumpad", true);
+
+ for (int i = 0; i < MPR_TOTAL; i++) {
+ const struct NavigateManipulatorInfo *info = &g_navigate_params[i];
+ navgroup->mpr_array[i] = WM_manipulator_new(info->manipulator, mgroup, NULL);
+ wmManipulator *mpr = navgroup->mpr_array[i];
+ mpr->flag |= WM_MANIPULATOR_GRAB_CURSOR | WM_MANIPULATOR_DRAW_MODAL;
+ mpr->color[3] = 0.2f;
+ mpr->color_hi[3] = 0.4f;
+
+ /* may be overwritten later */
+ mpr->scale_basis = (MANIPULATOR_SIZE * MANIPULATOR_MINI_FAC) / 2;
+ if (info->shape != NULL) {
+ PropertyRNA *prop = RNA_struct_find_property(mpr->ptr, "shape");
+ RNA_property_string_set_bytes(
+ mpr->ptr, prop,
+ (const char *)info->shape, info->shape_size);
+ }
+
+ wmOperatorType *ot = WM_operatortype_find(info->opname, true);
+ WM_manipulator_operator_set(mpr, 0, ot, NULL);
+ }
+
+ {
+ wmManipulator *mpr = navgroup->mpr_array[MPR_CAMERA];
+ PointerRNA *ptr = WM_manipulator_operator_set(mpr, 0, ot_viewnumpad, NULL);
+ RNA_enum_set(ptr, "type", RV3D_VIEW_CAMERA);
+ }
+
+ /* Click only buttons (not modal). */
+ {
+ int mpr_ids[] = {MPR_PERSP, MPR_ORTHO, MPR_CAMERA};
+ for (int i = 0; i < ARRAY_SIZE(mpr_ids); i++) {
+ wmManipulator *mpr = navgroup->mpr_array[mpr_ids[i]];
+ RNA_boolean_set(mpr->ptr, "show_drag", false);
+ }
+ }
+
+ /* Modal operators, don't use initial mouse location since we're clicking on a button. */
+ {
+ int mpr_ids[] = {MPR_MOVE, MPR_ROTATE, MPR_ZOOM};
+ for (int i = 0; i < ARRAY_SIZE(mpr_ids); i++) {
+ wmManipulator *mpr = navgroup->mpr_array[mpr_ids[i]];
+ wmManipulatorOpElem *mpop = WM_manipulator_operator_get(mpr, 0);
+ RNA_boolean_set(&mpop->ptr, "use_mouse_init", false);
+ }
+ }
+
+ {
+ wmManipulator *mpr = navgroup->mpr_array[MPR_ROTATE];
+ mpr->scale_basis = MANIPULATOR_SIZE / 2;
+ char mapping[6] = {
+ RV3D_VIEW_LEFT,
+ RV3D_VIEW_RIGHT,
+ RV3D_VIEW_FRONT,
+ RV3D_VIEW_BACK,
+ RV3D_VIEW_BOTTOM,
+ RV3D_VIEW_TOP,
+ };
+
+ for (int part_index = 0; part_index < 6; part_index += 1) {
+ PointerRNA *ptr = WM_manipulator_operator_set(mpr, part_index + 1, ot_viewnumpad, NULL);
+ RNA_enum_set(ptr, "type", mapping[part_index]);
+ }
+
+ /* When dragging an axis, use this instead. */
+ mpr->drag_part = 0;
+ }
+
+ mgroup->customdata = navgroup;
+}
+
+static void WIDGETGROUP_navigate_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct NavigateWidgetGroup *navgroup = mgroup->customdata;
+ ARegion *ar = CTX_wm_region(C);
+ const RegionView3D *rv3d = ar->regiondata;
+
+ for (int i = 0; i < 3; i++) {
+ copy_v3_v3(navgroup->mpr_array[MPR_ROTATE]->matrix_offset[i], rv3d->viewmat[i]);
+ }
+
+ if ((navgroup->state.ar.winx == ar->winx) &&
+ (navgroup->state.ar.winy == ar->winy) &&
+ (navgroup->state.rv3d.is_persp == rv3d->is_persp) &&
+ (navgroup->state.rv3d.viewlock == rv3d->viewlock))
+ {
+ return;
+ }
+
+
+ navgroup->state.ar.winx = ar->winx;
+ navgroup->state.ar.winy = ar->winy;
+ navgroup->state.rv3d.is_persp = rv3d->is_persp;
+ navgroup->state.rv3d.viewlock = rv3d->viewlock;
+
+
+ const float icon_size = MANIPULATOR_SIZE;
+ const float icon_offset = (icon_size / 2.0) * MANIPULATOR_OFFSET_FAC * UI_DPI_FAC;
+ const float icon_offset_mini = icon_size * MANIPULATOR_MINI_OFFSET_FAC * UI_DPI_FAC;
+ const float co[2] = {ar->winx - icon_offset, ar->winy - icon_offset};
+
+ wmManipulator *mpr;
+
+ for (uint i = 0; i < ARRAY_SIZE(navgroup->mpr_array); i++) {
+ mpr = navgroup->mpr_array[i];
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
+ }
+
+ if ((rv3d->viewlock & RV3D_LOCKED) == 0) {
+ mpr = navgroup->mpr_array[MPR_ROTATE];
+ mpr->matrix_basis[3][0] = co[0];
+ mpr->matrix_basis[3][1] = co[1];
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+
+ mpr = navgroup->mpr_array[MPR_MOVE];
+ mpr->matrix_basis[3][0] = co[0] + icon_offset_mini;
+ mpr->matrix_basis[3][1] = co[1] - icon_offset_mini;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+
+ mpr = navgroup->mpr_array[MPR_ZOOM];
+ mpr->matrix_basis[3][0] = co[0] - icon_offset_mini;
+ mpr->matrix_basis[3][1] = co[1] - icon_offset_mini;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+
+ mpr = navgroup->mpr_array[rv3d->is_persp ? MPR_ORTHO : MPR_PERSP];
+ mpr->matrix_basis[3][0] = co[0] + icon_offset_mini;
+ mpr->matrix_basis[3][1] = co[1] + icon_offset_mini;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+
+ mpr = navgroup->mpr_array[MPR_CAMERA];
+ mpr->matrix_basis[3][0] = co[0] - icon_offset_mini;
+ mpr->matrix_basis[3][1] = co[1] + icon_offset_mini;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+ }
+ else {
+ /* RV3D_LOCKED: only show supported buttons. */
+ mpr = navgroup->mpr_array[MPR_MOVE];
+ mpr->matrix_basis[3][0] = co[0] + icon_offset_mini;
+ mpr->matrix_basis[3][1] = co[1] + icon_offset_mini;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+
+ mpr = navgroup->mpr_array[MPR_ZOOM];
+ mpr->matrix_basis[3][0] = co[0];
+ mpr->matrix_basis[3][1] = co[1] + icon_offset_mini;
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+ }
+}
+
+void VIEW3D_WGT_navigate(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "View3D Navigate";
+ wgt->idname = "VIEW3D_WGT_navigate";
+
+ wgt->flag |= (WM_MANIPULATORGROUPTYPE_PERSISTENT |
+ WM_MANIPULATORGROUPTYPE_SCALE |
+ WM_MANIPULATORGROUPTYPE_DRAW_MODAL_ALL);
+
+ wgt->poll = WIDGETGROUP_navigate_poll;
+ wgt->setup = WIDGETGROUP_navigate_setup;
+ wgt->draw_prepare = WIDGETGROUP_navigate_draw_prepare;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c b/source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c
new file mode 100644
index 00000000000..8c9696d908c
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_navigate_type.c
@@ -0,0 +1,309 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file view3d_manipulator_navigate_type.c
+ * \ingroup wm
+ *
+ * \name Custom Orientation/Navigation Manipulator for the 3D View
+ *
+ * \brief Simple manipulator to axis and translate.
+ *
+ * - scale_basis: used for the size.
+ * - matrix_basis: used for the location.
+ * - matrix_offset: used to store the orientation.
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_math.h"
+#include "BLI_sort_utils.h"
+
+#include "BKE_context.h"
+
+#include "BIF_gl.h"
+#include "BIF_glutil.h"
+
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "UI_interface.h"
+#include "UI_resources.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+
+#include "view3d_intern.h"
+
+#define DIAL_RESOLUTION 32
+
+#define HANDLE_SIZE 0.33
+
+static void axis_geom_draw(
+ const wmManipulator *mpr, const float color[4], const bool UNUSED(select))
+{
+ glLineWidth(mpr->line_width);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ const uint pos_id = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
+ /* flip z for reverse */
+ const float cone_coords[5][3] = {
+ {-1, -1, 4},
+ {-1, +1, 4},
+ {+1, +1, 4},
+ {+1, -1, 4},
+ {0, 0, 2},
+ };
+
+ struct {
+ float depth;
+ char index;
+ char axis;
+ char is_pos;
+ } axis_order[6] = {
+ {-mpr->matrix_offset[0][2], 0, 0, false},
+ {+mpr->matrix_offset[0][2], 1, 0, true},
+ {-mpr->matrix_offset[1][2], 2, 1, false},
+ {+mpr->matrix_offset[1][2], 3, 1, true},
+ {-mpr->matrix_offset[2][2], 4, 2, false},
+ {+mpr->matrix_offset[2][2], 5, 2, true},
+ };
+ qsort(&axis_order, ARRAY_SIZE(axis_order), sizeof(axis_order[0]), BLI_sortutil_cmp_float);
+
+ const float scale_axis = 0.25f;
+ static const float axis_highlight[4] = {1, 1, 1, 1};
+ static const float axis_nop[4] = {1, 1, 1, 0};
+ static const float axis_black[4] = {0, 0, 0, 1};
+ static float axis_color[3][4];
+ gpuPushMatrix();
+ gpuMultMatrix(mpr->matrix_offset);
+
+ bool draw_center_done = false;
+
+ for (int axis_index = 0; axis_index < ARRAY_SIZE(axis_order); axis_index++) {
+ const int index = axis_order[axis_index].index;
+ const int axis = axis_order[axis_index].axis;
+ const bool is_pos = axis_order[axis_index].is_pos;
+
+ /* Draw slightly before, so axis aligned arrows draw ontop. */
+ if ((draw_center_done == false) && (axis_order[axis_index].depth > -0.01f)) {
+
+ /* Circle defining active area (revert back to 2D space). */
+ {
+ gpuPopMatrix();
+ immUniformColor4fv(color);
+ imm_draw_circle_fill_3d(pos_id, 0, 0, 1.0f, DIAL_RESOLUTION);
+ gpuPushMatrix();
+ gpuMultMatrix(mpr->matrix_offset);
+ }
+
+ /* Center cube. */
+ {
+ float center[3], size[3];
+
+ zero_v3(center);
+ copy_v3_fl(size, HANDLE_SIZE);
+
+ glEnable(GL_DEPTH_TEST);
+ glDepthMask(GL_TRUE);
+ glDepthFunc(GL_LEQUAL);
+ glBlendFunc(GL_ONE, GL_ZERO);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_BLEND);
+ glLineWidth(1.0f);
+ /* Just draw depth values. */
+ immUniformColor4fv(axis_nop);
+ imm_draw_cube_fill_3d(pos_id, center, size);
+ immUniformColor4fv(axis_black);
+ madd_v3_v3fl(
+ center,
+ (float [3]){
+ mpr->matrix_offset[0][2],
+ mpr->matrix_offset[1][2],
+ mpr->matrix_offset[2][2],
+ },
+ 0.08f);
+ imm_draw_cube_wire_3d(pos_id, center, size);
+ glDisable(GL_BLEND);
+ glDisable(GL_LINE_SMOOTH);
+ glDisable(GL_DEPTH_TEST);
+ }
+
+ draw_center_done = true;
+ }
+ UI_GetThemeColor3fv(TH_AXIS_X + axis, axis_color[axis]);
+ axis_color[axis][3] = 1.0f;
+
+ const int index_z = axis;
+ const int index_y = (axis + 1) % 3;
+ const int index_x = (axis + 2) % 3;
+
+#define ROTATED_VERT(v_orig) \
+ { \
+ float v[3]; \
+ copy_v3_v3(v, v_orig); \
+ if (is_pos == 0) { \
+ v[2] *= -1.0f; \
+ } \
+ immVertex3f(pos_id, v[index_x] * scale_axis, v[index_y] * scale_axis, v[index_z] * scale_axis); \
+ } ((void)0)
+
+ bool ok = true;
+
+ /* skip view align axis */
+ if (len_squared_v2(mpr->matrix_offset[axis]) < 1e-6f && (mpr->matrix_offset[axis][2] > 0.0f) == is_pos) {
+ ok = false;
+ }
+ if (ok) {
+ immUniformColor4fv(index + 1 == mpr->highlight_part ? axis_highlight : axis_color[axis]);
+ immBegin(GWN_PRIM_TRI_FAN, 6);
+ ROTATED_VERT(cone_coords[4]);
+ for (int j = 0; j <= 4; j++) {
+ ROTATED_VERT(cone_coords[j % 4]);
+ }
+ immEnd();
+ }
+
+#undef ROTATED_VERT
+ }
+
+ gpuPopMatrix();
+ immUnbindProgram();
+}
+
+static void axis3d_draw_intern(
+ const bContext *UNUSED(C), wmManipulator *mpr,
+ const bool select, const bool highlight)
+{
+ const float *color = highlight ? mpr->color_hi : mpr->color;
+ float matrix_final[4][4];
+ float matrix_unit[4][4];
+
+ unit_m4(matrix_unit);
+
+ WM_manipulator_calc_matrix_final_params(
+ mpr,
+ &((struct WM_ManipulatorMatrixParams) {
+ .matrix_offset = matrix_unit,
+ }), matrix_final);
+
+ gpuPushMatrix();
+ gpuMultMatrix(matrix_final);
+
+ glEnable(GL_BLEND);
+ axis_geom_draw(mpr, color, select);
+ glDisable(GL_BLEND);
+ gpuPopMatrix();
+}
+
+static void manipulator_axis_draw(const bContext *C, wmManipulator *mpr)
+{
+ const bool is_modal = mpr->state & WM_MANIPULATOR_STATE_MODAL;
+ const bool is_highlight = (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) != 0;
+
+ (void)is_modal;
+
+ glEnable(GL_BLEND);
+ axis3d_draw_intern(C, mpr, false, is_highlight);
+ glDisable(GL_BLEND);
+}
+
+static int manipulator_axis_test_select(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
+{
+ float point_local[2] = {UNPACK2(event->mval)};
+ sub_v2_v2(point_local, mpr->matrix_basis[3]);
+ mul_v2_fl(point_local, 1.0f / (mpr->scale_basis * UI_DPI_FAC));
+
+ const float len_sq = len_squared_v2(point_local);
+ if (len_sq > 1.0) {
+ return -1;
+ }
+
+ int part_best = -1;
+ int part_index = 1;
+ /* Use 'SQUARE(HANDLE_SIZE)' if we want to be able to _not_ focus on one of the axis. */
+ float i_best_len_sq = FLT_MAX;
+ for (int i = 0; i < 3; i++) {
+ for (int is_pos = 0; is_pos < 2; is_pos++) {
+ float co[2] = {
+ mpr->matrix_offset[i][0] * (is_pos ? 1 : -1),
+ mpr->matrix_offset[i][1] * (is_pos ? 1 : -1),
+ };
+
+ bool ok = true;
+
+ /* Check if we're viewing on an axis, there is no point to clicking on the current axis so show the reverse. */
+ if (len_squared_v2(co) < 1e-6f && (mpr->matrix_offset[i][2] > 0.0f) == is_pos) {
+ ok = false;
+ }
+
+ if (ok) {
+ const float len_axis_sq = len_squared_v2v2(co, point_local);
+ if (len_axis_sq < i_best_len_sq) {
+ part_best = part_index;
+ i_best_len_sq = len_axis_sq;
+ }
+ }
+ part_index += 1;
+ }
+ }
+
+ if (part_best != -1) {
+ return part_best;
+ }
+
+ /* The 'mpr->scale_final' is already applied when projecting. */
+ if (len_sq < 1.0f) {
+ return 0;
+ }
+
+ return -1;
+}
+
+static int manipulator_axis_cursor_get(wmManipulator *mpr)
+{
+ if (mpr->highlight_part > 0) {
+ return CURSOR_EDIT;
+ }
+ return BC_NSEW_SCROLLCURSOR;
+}
+
+void VIEW3D_WT_navigate_rotate(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "VIEW3D_WT_navigate_rotate";
+
+ /* api callbacks */
+ wt->draw = manipulator_axis_draw;
+ wt->test_select = manipulator_axis_test_select;
+ wt->cursor_get = manipulator_axis_cursor_get;
+
+ wt->struct_size = sizeof(wmManipulator);
+}
diff --git a/source/blender/editors/space_view3d/view3d_manipulator_ruler.c b/source/blender/editors/space_view3d/view3d_manipulator_ruler.c
new file mode 100644
index 00000000000..eedc346db1d
--- /dev/null
+++ b/source/blender/editors/space_view3d/view3d_manipulator_ruler.c
@@ -0,0 +1,1094 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/space_view3d/view3d_manipulator_ruler.c
+ * \ingroup spview3d
+ */
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_rect.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "BLT_translation.h"
+
+#include "BKE_context.h"
+#include "BKE_object.h"
+#include "BKE_gpencil.h"
+#include "BKE_unit.h"
+
+#include "DNA_object_types.h"
+#include "DNA_gpencil_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BIF_gl.h"
+
+#include "ED_screen.h"
+#include "ED_transform_snap_object_context.h"
+#include "ED_view3d.h"
+
+#include "UI_resources.h"
+#include "UI_interface.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "view3d_intern.h" /* own include */
+
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_select.h"
+
+#include "BLF_api.h"
+
+
+static const char *view3d_wgt_ruler_id = "VIEW3D_WGT_ruler";
+
+
+#define MVAL_MAX_PX_DIST 12.0f
+
+/* -------------------------------------------------------------------- */
+/* Ruler Item (we can have many) */
+enum {
+ RULERITEM_USE_ANGLE = (1 << 0), /* use protractor */
+ RULERITEM_USE_RAYCAST = (1 << 1)
+};
+
+enum {
+ RULERITEM_DIRECTION_IN = 0,
+ RULERITEM_DIRECTION_OUT
+};
+
+/* keep smaller then selection, since we may want click elsewhere without selecting a ruler */
+#define RULER_PICK_DIST 12.0f
+#define RULER_PICK_DIST_SQ (RULER_PICK_DIST * RULER_PICK_DIST)
+
+/* not clicking on a point */
+#define PART_LINE 0xff
+
+/* -------------------------------------------------------------------- */
+/* Ruler Info (wmManipulatorGroup customdata) */
+
+enum {
+ RULER_STATE_NORMAL = 0,
+ RULER_STATE_DRAG
+};
+
+enum {
+ RULER_SNAP_OK = (1 << 0),
+};
+
+typedef struct RulerInfo {
+ // ListBase items;
+ int item_active;
+ int flag;
+ int snap_flag;
+ int state;
+
+ struct SnapObjectContext *snap_context;
+
+ /* wm state */
+ wmWindow *win;
+ ScrArea *sa;
+ ARegion *ar; /* re-assigned every modal update */
+} RulerInfo;
+
+/* -------------------------------------------------------------------- */
+/* Ruler Item (two or three points) */
+
+typedef struct RulerItem {
+ wmManipulator mpr;
+
+ /* worldspace coords, middle being optional */
+ float co[3][3];
+
+ int flag;
+ int raycast_dir; /* RULER_DIRECTION_* */
+} RulerItem;
+
+typedef struct RulerInteraction {
+ /* selected coord */
+ char co_index; /* 0 -> 2 */
+ float drag_start_co[3];
+ uint inside_region : 1;
+} RulerInteraction;
+
+/* -------------------------------------------------------------------- */
+/** \name Internal Ruler Utilities
+ * \{ */
+
+static RulerItem *ruler_item_add(wmManipulatorGroup *mgroup)
+{
+ /* could pass this as an arg */
+ const wmManipulatorType *wt_ruler = WM_manipulatortype_find("VIEW3D_WT_ruler_item", true);
+ RulerItem *ruler_item = (RulerItem *)WM_manipulator_new_ptr(wt_ruler, mgroup, NULL);
+ WM_manipulator_set_flag(&ruler_item->mpr, WM_MANIPULATOR_DRAW_MODAL, true);
+ return ruler_item;
+}
+
+static void ruler_item_remove(bContext *C, wmManipulatorGroup *mgroup, RulerItem *ruler_item)
+{
+ WM_manipulator_unlink(&mgroup->manipulators, mgroup->parent_mmap, &ruler_item->mpr, C);
+}
+
+static void ruler_item_as_string(RulerItem *ruler_item, UnitSettings *unit,
+ char *numstr, size_t numstr_size, int prec)
+{
+ const bool do_split = (unit->flag & USER_UNIT_OPT_SPLIT) != 0;
+
+ if (ruler_item->flag & RULERITEM_USE_ANGLE) {
+ const float ruler_angle = angle_v3v3v3(ruler_item->co[0],
+ ruler_item->co[1],
+ ruler_item->co[2]);
+
+ if (unit->system == USER_UNIT_NONE) {
+ BLI_snprintf(numstr, numstr_size, "%.*f°", prec, RAD2DEGF(ruler_angle));
+ }
+ else {
+ bUnit_AsString(numstr, numstr_size,
+ (double)ruler_angle,
+ prec, unit->system, B_UNIT_ROTATION, do_split, false);
+ }
+ }
+ else {
+ const float ruler_len = len_v3v3(ruler_item->co[0],
+ ruler_item->co[2]);
+
+ if (unit->system == USER_UNIT_NONE) {
+ BLI_snprintf(numstr, numstr_size, "%.*f", prec, ruler_len);
+ }
+ else {
+ bUnit_AsString(numstr, numstr_size,
+ (double)(ruler_len * unit->scale_length),
+ prec, unit->system, B_UNIT_LENGTH, do_split, false);
+ }
+ }
+}
+
+static bool view3d_ruler_pick(
+ wmManipulatorGroup *mgroup, RulerItem *ruler_item, const float mval[2],
+ int *r_co_index)
+{
+ RulerInfo *ruler_info = mgroup->customdata;
+ ARegion *ar = ruler_info->ar;
+ bool found = false;
+
+ float dist_best = RULER_PICK_DIST_SQ;
+ int co_index_best = -1;
+
+ {
+ float co_ss[3][2];
+ float dist;
+ int j;
+
+ /* should these be checked? - ok for now not to */
+ for (j = 0; j < 3; j++) {
+ ED_view3d_project_float_global(ar, ruler_item->co[j], co_ss[j], V3D_PROJ_TEST_NOP);
+ }
+
+ if (ruler_item->flag & RULERITEM_USE_ANGLE) {
+ dist = min_ff(dist_squared_to_line_segment_v2(mval, co_ss[0], co_ss[1]),
+ dist_squared_to_line_segment_v2(mval, co_ss[1], co_ss[2]));
+ if (dist < dist_best) {
+ dist_best = dist;
+ found = true;
+
+ {
+ const float dist_points[3] = {
+ len_squared_v2v2(co_ss[0], mval),
+ len_squared_v2v2(co_ss[1], mval),
+ len_squared_v2v2(co_ss[2], mval),
+ };
+ if (min_fff(UNPACK3(dist_points)) < RULER_PICK_DIST_SQ) {
+ co_index_best = min_axis_v3(dist_points);
+ }
+ else {
+ co_index_best = -1;
+ }
+ }
+ }
+ }
+ else {
+ dist = dist_squared_to_line_segment_v2(mval, co_ss[0], co_ss[2]);
+ if (dist < dist_best) {
+ dist_best = dist;
+ found = true;
+
+ {
+ const float dist_points[2] = {
+ len_squared_v2v2(co_ss[0], mval),
+ len_squared_v2v2(co_ss[2], mval),
+ };
+ if (min_ff(UNPACK2(dist_points)) < RULER_PICK_DIST_SQ) {
+ co_index_best = (dist_points[0] < dist_points[1]) ? 0 : 2;
+ }
+ else {
+ co_index_best = -1;
+ }
+ }
+ }
+ }
+ }
+
+ *r_co_index = co_index_best;
+ return found;
+}
+
+/**
+ * Ensure the 'snap_context' is only cached while dragging,
+ * needed since the user may toggle modes between tool use.
+ */
+static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state)
+{
+ if (state == ruler_info->state) {
+ return;
+ }
+
+ /* always remove */
+ if (ruler_info->snap_context) {
+ ED_transform_snap_object_context_destroy(ruler_info->snap_context);
+ ruler_info->snap_context = NULL;
+ }
+
+ if (state == RULER_STATE_NORMAL) {
+ /* pass */
+ }
+ else if (state == RULER_STATE_DRAG) {
+ ruler_info->snap_context = ED_transform_snap_object_context_create_view3d(
+ CTX_data_main(C), CTX_data_scene(C), CTX_data_depsgraph(C), 0,
+ ruler_info->ar, CTX_wm_view3d(C));
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ ruler_info->state = state;
+}
+
+static void view3d_ruler_item_project(
+ RulerInfo *ruler_info, float r_co[3],
+ const int xy[2])
+{
+ ED_view3d_win_to_3d_int(ruler_info->sa->spacedata.first, ruler_info->ar, r_co, xy, r_co);
+}
+
+/* use for mousemove events */
+static bool view3d_ruler_item_mousemove(
+ RulerInfo *ruler_info, RulerItem *ruler_item, const int mval[2],
+ const bool do_thickness, const bool do_snap)
+{
+ RulerInteraction *inter = ruler_item->mpr.interaction_data;
+ const float eps_bias = 0.0002f;
+ float dist_px = MVAL_MAX_PX_DIST * U.pixelsize; /* snap dist */
+
+ ruler_info->snap_flag &= ~RULER_SNAP_OK;
+
+ if (ruler_item) {
+ float *co = ruler_item->co[inter->co_index];
+ /* restore the initial depth */
+ copy_v3_v3(co, inter->drag_start_co);
+ view3d_ruler_item_project(ruler_info, co, mval);
+ if (do_thickness && inter->co_index != 1) {
+ // Scene *scene = CTX_data_scene(C);
+ // View3D *v3d = ruler_info->sa->spacedata.first;
+ const float mval_fl[2] = {UNPACK2(mval)};
+ float ray_normal[3];
+ float ray_start[3];
+ float *co_other;
+
+ co_other = ruler_item->co[inter->co_index == 0 ? 2 : 0];
+
+ if (ED_transform_snap_object_project_view3d_mixed(
+ ruler_info->snap_context,
+ SCE_SELECT_FACE,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .use_object_edit_cage = true,
+ },
+ mval_fl, &dist_px, true,
+ co, ray_normal))
+ {
+ negate_v3(ray_normal);
+ /* add some bias */
+ madd_v3_v3v3fl(ray_start, co, ray_normal, eps_bias);
+ ED_transform_snap_object_project_ray(
+ ruler_info->snap_context,
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .use_object_edit_cage = true,
+ },
+ ray_start, ray_normal, NULL,
+ co_other, NULL);
+ }
+ }
+ else if (do_snap) {
+ // Scene *scene = CTX_data_scene(C);
+ View3D *v3d = ruler_info->sa->spacedata.first;
+ const float mval_fl[2] = {UNPACK2(mval)};
+ bool use_depth = (v3d->drawtype >= OB_SOLID);
+
+ if (ED_transform_snap_object_project_view3d_mixed(
+ ruler_info->snap_context,
+ (SCE_SELECT_VERTEX | SCE_SELECT_EDGE) | (use_depth ? SCE_SELECT_FACE : 0),
+ &(const struct SnapObjectParams){
+ .snap_select = SNAP_ALL,
+ .use_object_edit_cage = true,
+ },
+ mval_fl, &dist_px, use_depth,
+ co, NULL))
+ {
+ ruler_info->snap_flag |= RULER_SNAP_OK;
+ }
+ }
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Ruler/Grease Pencil Conversion
+ * \{ */
+
+#define RULER_ID "RulerData3D"
+static bool view3d_ruler_to_gpencil(bContext *C, wmManipulatorGroup *mgroup)
+{
+ // RulerInfo *ruler_info = mgroup->customdata;
+ Scene *scene = CTX_data_scene(C);
+ bGPDlayer *gpl;
+ bGPDframe *gpf;
+ bGPDstroke *gps;
+ bGPDpalette *palette;
+ bGPDpalettecolor *palcolor;
+ RulerItem *ruler_item;
+ const char *ruler_name = RULER_ID;
+ bool changed = false;
+
+ if (scene->gpd == NULL) {
+ scene->gpd = BKE_gpencil_data_addnew("GPencil");
+ }
+
+ gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info));
+ if (gpl == NULL) {
+ gpl = BKE_gpencil_layer_addnew(scene->gpd, ruler_name, false);
+ gpl->thickness = 1;
+ gpl->flag |= GP_LAYER_HIDE;
+ }
+
+ /* try to get active palette or create a new one */
+ palette = BKE_gpencil_palette_getactive(scene->gpd);
+ if (palette == NULL) {
+ palette = BKE_gpencil_palette_addnew(scene->gpd, DATA_("GP_Palette"), true);
+ }
+ /* try to get color with the ruler name or create a new one */
+ palcolor = BKE_gpencil_palettecolor_getbyname(palette, (char *)ruler_name);
+ if (palcolor == NULL) {
+ palcolor = BKE_gpencil_palettecolor_addnew(palette, (char *)ruler_name, true);
+ }
+
+ gpf = BKE_gpencil_layer_getframe(gpl, CFRA, true);
+ BKE_gpencil_free_strokes(gpf);
+
+ for (ruler_item = mgroup->manipulators.first; ruler_item; ruler_item = (RulerItem *)ruler_item->mpr.next) {
+ bGPDspoint *pt;
+ int j;
+
+ /* allocate memory for a new stroke */
+ gps = MEM_callocN(sizeof(bGPDstroke), "gp_stroke");
+ if (ruler_item->flag & RULERITEM_USE_ANGLE) {
+ gps->totpoints = 3;
+ pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
+ for (j = 0; j < 3; j++) {
+ copy_v3_v3(&pt->x, ruler_item->co[j]);
+ pt->pressure = 1.0f;
+ pt->strength = 1.0f;
+ pt++;
+ }
+ }
+ else {
+ gps->totpoints = 2;
+ pt = gps->points = MEM_callocN(sizeof(bGPDspoint) * gps->totpoints, "gp_stroke_points");
+ for (j = 0; j < 3; j += 2) {
+ copy_v3_v3(&pt->x, ruler_item->co[j]);
+ pt->pressure = 1.0f;
+ pt->strength = 1.0f;
+ pt++;
+ }
+ }
+ gps->flag = GP_STROKE_3DSPACE;
+ gps->thickness = 3;
+ /* assign color to stroke */
+ BLI_strncpy(gps->colorname, palcolor->info, sizeof(gps->colorname));
+ gps->palcolor = palcolor;
+ BLI_addtail(&gpf->strokes, gps);
+ changed = true;
+ }
+
+ return changed;
+}
+
+static bool view3d_ruler_from_gpencil(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ Scene *scene = CTX_data_scene(C);
+ bool changed = false;
+
+ if (scene->gpd) {
+ bGPDlayer *gpl;
+ const char *ruler_name = RULER_ID;
+ gpl = BLI_findstring(&scene->gpd->layers, ruler_name, offsetof(bGPDlayer, info));
+ if (gpl) {
+ bGPDframe *gpf;
+ gpf = BKE_gpencil_layer_getframe(gpl, CFRA, false);
+ if (gpf) {
+ bGPDstroke *gps;
+ for (gps = gpf->strokes.first; gps; gps = gps->next) {
+ bGPDspoint *pt = gps->points;
+ int j;
+ RulerItem *ruler_item = NULL;
+ if (gps->totpoints == 3) {
+ ruler_item = ruler_item_add(mgroup);
+ for (j = 0; j < 3; j++) {
+ copy_v3_v3(ruler_item->co[j], &pt->x);
+ pt++;
+ }
+ ruler_item->flag |= RULERITEM_USE_ANGLE;
+ changed = true;
+ }
+ else if (gps->totpoints == 2) {
+ ruler_item = ruler_item_add(mgroup);
+ for (j = 0; j < 3; j += 2) {
+ copy_v3_v3(ruler_item->co[j], &pt->x);
+ pt++;
+ }
+ changed = true;
+ }
+ }
+ }
+ }
+ }
+
+ return changed;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Ruler Item Manipulator Type
+ * \{ */
+
+static void manipulator_ruler_draw(const bContext *C, wmManipulator *mpr)
+{
+ Scene *scene = CTX_data_scene(C);
+ UnitSettings *unit = &scene->unit;
+ RulerInfo *ruler_info = mpr->parent_mgroup->customdata;
+ RulerItem *ruler_item = (RulerItem *)mpr;
+ ARegion *ar = ruler_info->ar;
+ RegionView3D *rv3d = ar->regiondata;
+ const float cap_size = 4.0f;
+ const float bg_margin = 4.0f * U.pixelsize;
+ const float bg_radius = 4.0f * U.pixelsize;
+ const float arc_size = 64.0f * U.pixelsize;
+#define ARC_STEPS 24
+ const int arc_steps = ARC_STEPS;
+ const float color_act[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ const float color_base[4] = {0.0f, 0.0f, 0.0f, 1.0f};
+ unsigned char color_text[3];
+ unsigned char color_wire[3];
+ float color_back[4] = {1.0f, 1.0f, 1.0f, 0.5f};
+
+ /* anti-aliased lines for more consistent appearance */
+ glEnable(GL_LINE_SMOOTH);
+
+ BLF_enable(blf_mono_font, BLF_ROTATION);
+ BLF_size(blf_mono_font, 14 * U.pixelsize, U.dpi);
+ BLF_rotation(blf_mono_font, 0.0f);
+
+ UI_GetThemeColor3ubv(TH_TEXT, color_text);
+ UI_GetThemeColor3ubv(TH_WIRE, color_wire);
+
+ const bool is_act = (mpr->flag & WM_MANIPULATOR_DRAW_HOVER);
+ float dir_ruler[2];
+ float co_ss[3][2];
+ int j;
+
+ /* should these be checked? - ok for now not to */
+ for (j = 0; j < 3; j++) {
+ ED_view3d_project_float_global(ar, ruler_item->co[j], co_ss[j], V3D_PROJ_TEST_NOP);
+ }
+
+ glEnable(GL_BLEND);
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ if (ruler_item->flag & RULERITEM_USE_ANGLE) {
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ const float *col = is_act ? color_act : color_base;
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {col[0], col[1], col[2], col[3]}}, 2);
+ immUniform1f("dash_width", 6.0f);
+
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+
+ immVertex2fv(shdr_pos, co_ss[0]);
+ immVertex2fv(shdr_pos, co_ss[1]);
+ immVertex2fv(shdr_pos, co_ss[2]);
+
+ immEnd();
+
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ /* arc */
+ {
+ float dir_tmp[3];
+ float co_tmp[3];
+ float arc_ss_coord[2];
+
+ float dir_a[3];
+ float dir_b[3];
+ float quat[4];
+ float axis[3];
+ float angle;
+ const float px_scale = (ED_view3d_pixel_size(rv3d, ruler_item->co[1]) *
+ min_fff(arc_size,
+ len_v2v2(co_ss[0], co_ss[1]) / 2.0f,
+ len_v2v2(co_ss[2], co_ss[1]) / 2.0f));
+
+ sub_v3_v3v3(dir_a, ruler_item->co[0], ruler_item->co[1]);
+ sub_v3_v3v3(dir_b, ruler_item->co[2], ruler_item->co[1]);
+ normalize_v3(dir_a);
+ normalize_v3(dir_b);
+
+ cross_v3_v3v3(axis, dir_a, dir_b);
+ angle = angle_normalized_v3v3(dir_a, dir_b);
+
+ axis_angle_to_quat(quat, axis, angle / arc_steps);
+
+ copy_v3_v3(dir_tmp, dir_a);
+
+ immUniformColor3ubv(color_wire);
+
+ immBegin(GWN_PRIM_LINE_STRIP, arc_steps + 1);
+
+ for (j = 0; j <= arc_steps; j++) {
+ madd_v3_v3v3fl(co_tmp, ruler_item->co[1], dir_tmp, px_scale);
+ ED_view3d_project_float_global(ar, co_tmp, arc_ss_coord, V3D_PROJ_TEST_NOP);
+ mul_qt_v3(quat, dir_tmp);
+
+ immVertex2fv(shdr_pos, arc_ss_coord);
+ }
+
+ immEnd();
+ }
+
+ /* capping */
+ {
+ float rot_90_vec_a[2];
+ float rot_90_vec_b[2];
+ float cap[2];
+
+ sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[1]);
+ rot_90_vec_a[0] = -dir_ruler[1];
+ rot_90_vec_a[1] = dir_ruler[0];
+ normalize_v2(rot_90_vec_a);
+
+ sub_v2_v2v2(dir_ruler, co_ss[1], co_ss[2]);
+ rot_90_vec_b[0] = -dir_ruler[1];
+ rot_90_vec_b[1] = dir_ruler[0];
+ normalize_v2(rot_90_vec_b);
+
+ glEnable(GL_BLEND);
+
+ immUniformColor3ubv(color_wire);
+
+ immBegin(GWN_PRIM_LINES, 8);
+
+ madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, cap_size);
+ immVertex2fv(shdr_pos, cap);
+ madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, -cap_size);
+ immVertex2fv(shdr_pos, cap);
+
+ madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, cap_size);
+ immVertex2fv(shdr_pos, cap);
+ madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, -cap_size);
+ immVertex2fv(shdr_pos, cap);
+
+ /* angle vertex */
+ immVertex2f(shdr_pos, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size);
+ immVertex2f(shdr_pos, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size);
+ immVertex2f(shdr_pos, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size);
+ immVertex2f(shdr_pos, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size);
+
+ immEnd();
+
+ glDisable(GL_BLEND);
+ }
+
+ immUnbindProgram();
+
+ /* text */
+ {
+ char numstr[256];
+ float numstr_size[2];
+ float posit[2];
+ const int prec = 2; /* XXX, todo, make optional */
+
+ ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
+
+ BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
+
+ posit[0] = co_ss[1][0] + (cap_size * 2.0f);
+ posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
+
+ /* draw text (bg) */
+ UI_draw_roundbox_corner_set(UI_CNR_ALL);
+ UI_draw_roundbox_aa(
+ true,
+ posit[0] - bg_margin, posit[1] - bg_margin,
+ posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
+ bg_radius, color_back);
+ /* draw text */
+ BLF_color3ubv(blf_mono_font, color_text);
+ BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);
+ BLF_rotation(blf_mono_font, 0.0f);
+ BLF_draw(blf_mono_font, numstr, sizeof(numstr));
+ }
+ }
+ else {
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ const float *col = is_act ? color_act : color_base;
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {col[0], col[1], col[2], col[3]}}, 2);
+ immUniform1f("dash_width", 6.0f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+
+ immVertex2fv(shdr_pos, co_ss[0]);
+ immVertex2fv(shdr_pos, co_ss[2]);
+
+ immEnd();
+
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[2]);
+
+ /* capping */
+ {
+ float rot_90_vec[2] = {-dir_ruler[1], dir_ruler[0]};
+ float cap[2];
+
+ normalize_v2(rot_90_vec);
+
+ glEnable(GL_BLEND);
+
+ immUniformColor3ubv(color_wire);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, cap_size);
+ immVertex2fv(shdr_pos, cap);
+ madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, -cap_size);
+ immVertex2fv(shdr_pos, cap);
+
+ madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, cap_size);
+ immVertex2fv(shdr_pos, cap);
+ madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, -cap_size);
+ immVertex2fv(shdr_pos, cap);
+
+ immEnd();
+
+ glDisable(GL_BLEND);
+ }
+
+ immUnbindProgram();
+
+ /* text */
+ {
+ char numstr[256];
+ float numstr_size[2];
+ const int prec = 6; /* XXX, todo, make optional */
+ float posit[2];
+
+ ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
+
+ BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
+
+ mid_v2_v2v2(posit, co_ss[0], co_ss[2]);
+
+ /* center text */
+ posit[0] -= numstr_size[0] / 2.0f;
+ posit[1] -= numstr_size[1] / 2.0f;
+
+ /* draw text (bg) */
+ UI_draw_roundbox_corner_set(UI_CNR_ALL);
+ UI_draw_roundbox_aa(
+ true,
+ posit[0] - bg_margin, posit[1] - bg_margin,
+ posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
+ bg_radius, color_back);
+ /* draw text */
+ BLF_color3ubv(blf_mono_font, color_text);
+ BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);
+ BLF_draw(blf_mono_font, numstr, sizeof(numstr));
+ }
+ }
+
+ glDisable(GL_LINE_SMOOTH);
+
+ BLF_disable(blf_mono_font, BLF_ROTATION);
+
+#undef ARC_STEPS
+
+ /* draw snap */
+ if ((ruler_info->snap_flag & RULER_SNAP_OK) &&
+ (ruler_info->state == RULER_STATE_DRAG) &&
+ (ruler_item->mpr.interaction_data != NULL))
+ {
+ RulerInteraction *inter = ruler_item->mpr.interaction_data;
+ /* size from drawSnapping */
+ const float size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE);
+ float co_ss_snap[3];
+ ED_view3d_project_float_global(ar, ruler_item->co[inter->co_index], co_ss_snap, V3D_PROJ_TEST_NOP);
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv(color_act);
+
+ imm_draw_circle_wire_2d(pos, co_ss_snap[0], co_ss_snap[1], size * U.pixelsize, 32);
+
+ immUnbindProgram();
+ }
+}
+
+static int manipulator_ruler_test_select(
+ bContext *UNUSED(C), wmManipulator *mpr, const wmEvent *event)
+{
+ RulerItem *ruler_item_pick = (RulerItem *)mpr;
+ float mval_fl[2] = {UNPACK2(event->mval)};
+ int co_index;
+
+ /* select and drag */
+ if (view3d_ruler_pick(mpr->parent_mgroup, ruler_item_pick, mval_fl, &co_index)) {
+ if (co_index == -1) {
+ if ((ruler_item_pick->flag & RULERITEM_USE_ANGLE) == 0) {
+ return PART_LINE;
+ }
+ }
+ else {
+ return co_index;
+ }
+ }
+ return -1;
+}
+
+static int manipulator_ruler_modal(
+ bContext *C, wmManipulator *mpr, const wmEvent *event,
+ eWM_ManipulatorTweak UNUSED(tweak_flag))
+{
+ bool do_draw = false;
+ int exit_code = OPERATOR_RUNNING_MODAL;
+ RulerInfo *ruler_info = mpr->parent_mgroup->customdata;
+ RulerItem *ruler_item = (RulerItem *)mpr;
+ RulerInteraction *inter = ruler_item->mpr.interaction_data;
+ ARegion *ar = CTX_wm_region(C);
+
+ ruler_info->ar = ar;
+
+ switch (event->type) {
+ case MOUSEMOVE:
+ {
+ if (ruler_info->state == RULER_STATE_DRAG) {
+ if (view3d_ruler_item_mousemove(
+ ruler_info, ruler_item, event->mval,
+ event->shift != 0, event->ctrl != 0))
+ {
+ do_draw = true;
+ }
+ inter->inside_region = BLI_rcti_isect_pt_v(&ar->winrct, &event->x);
+ }
+ break;
+ }
+ }
+ if (do_draw) {
+ ED_region_tag_redraw(ar);
+ }
+ return exit_code;
+}
+
+static int manipulator_ruler_invoke(
+ bContext *C, wmManipulator *mpr, const wmEvent *event)
+{
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ RulerInfo *ruler_info = mgroup->customdata;
+ RulerItem *ruler_item_pick = (RulerItem *)mpr;
+ RulerInteraction *inter = MEM_callocN(sizeof(RulerInteraction), __func__);
+ mpr->interaction_data = inter;
+
+ ARegion *ar = ruler_info->ar;
+
+ const float mval_fl[2] = {UNPACK2(event->mval)};
+
+ /* select and drag */
+ if (mpr->highlight_part == PART_LINE) {
+ if ((ruler_item_pick->flag & RULERITEM_USE_ANGLE) == 0) {
+ /* Add Center Point */
+ ruler_item_pick->flag |= RULERITEM_USE_ANGLE;
+ inter->co_index = 1;
+ ruler_state_set(C, ruler_info, RULER_STATE_DRAG);
+
+ /* find the factor */
+ {
+ float co_ss[2][2];
+ float fac;
+
+ ED_view3d_project_float_global(ar, ruler_item_pick->co[0], co_ss[0], V3D_PROJ_TEST_NOP);
+ ED_view3d_project_float_global(ar, ruler_item_pick->co[2], co_ss[1], V3D_PROJ_TEST_NOP);
+
+ fac = line_point_factor_v2(mval_fl, co_ss[0], co_ss[1]);
+ CLAMP(fac, 0.0f, 1.0f);
+
+ interp_v3_v3v3(ruler_item_pick->co[1],
+ ruler_item_pick->co[0],
+ ruler_item_pick->co[2], fac);
+ }
+
+ /* update the new location */
+ view3d_ruler_item_mousemove(
+ ruler_info, ruler_item_pick, event->mval,
+ event->shift != 0, event->ctrl != 0);
+ }
+ }
+ else {
+ inter->co_index = mpr->highlight_part;
+ ruler_state_set(C, ruler_info, RULER_STATE_DRAG);
+
+ /* store the initial depth */
+ copy_v3_v3(inter->drag_start_co, ruler_item_pick->co[inter->co_index]);
+ }
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void manipulator_ruler_exit(bContext *C, wmManipulator *mpr, const bool cancel)
+{
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ RulerInfo *ruler_info = mgroup->customdata;
+
+ if (!cancel) {
+ if (ruler_info->state == RULER_STATE_DRAG) {
+ RulerItem *ruler_item = (RulerItem *)mpr;
+ RulerInteraction *inter = mpr->interaction_data;
+ /* rubber-band angle removal */
+ if (!inter->inside_region) {
+ if ((inter->co_index == 1) && (ruler_item->flag & RULERITEM_USE_ANGLE)) {
+ ruler_item->flag &= ~RULERITEM_USE_ANGLE;
+ }
+ else {
+ /* Not ideal, since the ruler isn't a mode and we don't want to override delete key
+ * use dragging out of the view for removal. */
+ ruler_item_remove(C, mgroup, ruler_item);
+ ruler_item = NULL;
+ mpr = NULL;
+ inter = NULL;
+ }
+ }
+ if (ruler_info->snap_flag & RULER_SNAP_OK) {
+ ruler_info->snap_flag &= ~RULER_SNAP_OK;
+ }
+ ruler_state_set(C, ruler_info, RULER_STATE_NORMAL);
+ }
+ /* We could convert only the current manipulator, for now just re-generate. */
+ view3d_ruler_to_gpencil(C, mgroup);
+ }
+
+ if (mpr) {
+ MEM_SAFE_FREE(mpr->interaction_data);
+ }
+
+ ruler_state_set(C, ruler_info, RULER_STATE_NORMAL);
+}
+
+static int manipulator_ruler_cursor_get(wmManipulator *mpr)
+{
+ if (mpr->highlight_part == PART_LINE) {
+ return BC_CROSSCURSOR;
+ }
+ return BC_NSEW_SCROLLCURSOR;
+}
+
+void VIEW3D_WT_ruler_item(wmManipulatorType *wt)
+{
+ /* identifiers */
+ wt->idname = "VIEW3D_WT_ruler_item";
+
+ /* api callbacks */
+ wt->draw = manipulator_ruler_draw;
+ wt->test_select = manipulator_ruler_test_select;
+ wt->modal = manipulator_ruler_modal;
+ wt->invoke = manipulator_ruler_invoke;
+ wt->exit = manipulator_ruler_exit;
+ wt->cursor_get = manipulator_ruler_cursor_get;
+
+ wt->struct_size = sizeof(RulerItem);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Ruler Manipulator Group
+ * \{ */
+
+static bool WIDGETGROUP_ruler_poll(const bContext *C, wmManipulatorGroupType *wgt)
+{
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ if (!STREQ(wgt->idname, workspace->tool.manipulator_group)) {
+ WM_manipulator_group_type_unlink_delayed_ptr(wgt);
+ return false;
+ }
+ return true;
+}
+
+static void WIDGETGROUP_ruler_setup(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ RulerInfo *ruler_info = MEM_callocN(sizeof(RulerInfo), __func__);
+
+ if (view3d_ruler_from_gpencil(C, mgroup)) {
+ /* nop */
+ }
+
+ wmWindow *win = CTX_wm_window(C);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ ruler_info->win = win;
+ ruler_info->sa = sa;
+ ruler_info->ar = ar;
+
+ mgroup->customdata = ruler_info;
+}
+
+void VIEW3D_WGT_ruler(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Ruler Widgets";
+ wgt->idname = view3d_wgt_ruler_id;
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_SCALE | WM_MANIPULATORGROUPTYPE_DRAW_MODAL_ALL;
+
+ wgt->mmap_params.spaceid = SPACE_VIEW3D;
+ wgt->mmap_params.regionid = RGN_TYPE_WINDOW;
+
+ wgt->poll = WIDGETGROUP_ruler_poll;
+ wgt->setup = WIDGETGROUP_ruler_setup;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Add Ruler Operator
+ * \{ */
+
+static int view3d_ruler_poll(bContext *C)
+{
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ if (!STREQ(view3d_wgt_ruler_id, workspace->tool.manipulator_group) ||
+ CTX_wm_region_view3d(C) == NULL)
+ {
+ return false;
+ }
+ return true;
+}
+
+static int view3d_ruler_add_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
+{
+ ARegion *ar = CTX_wm_region(C);
+ View3D *v3d = CTX_wm_view3d(C);
+ RegionView3D *rv3d = ar->regiondata;
+
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ wmManipulatorGroup *mgroup = WM_manipulatormap_group_find(mmap, view3d_wgt_ruler_id);
+ const bool use_depth = (v3d->drawtype >= OB_SOLID);
+
+ /* Create new line */
+ RulerItem *ruler_item;
+ ruler_item = ruler_item_add(mgroup);
+
+ /* This is a little weak, but there is no real good way to tweak directly. */
+ WM_manipulator_highlight_set(mmap, &ruler_item->mpr);
+ if (WM_operator_name_call(
+ C, "MANIPULATORGROUP_OT_manipulator_tweak",
+ WM_OP_INVOKE_REGION_WIN, NULL) == OPERATOR_RUNNING_MODAL)
+ {
+ RulerInfo *ruler_info = mgroup->customdata;
+ RulerInteraction *inter = ruler_item->mpr.interaction_data;
+ if (use_depth) {
+ /* snap the first point added, not essential but handy */
+ inter->co_index = 0;
+ view3d_ruler_item_mousemove(ruler_info, ruler_item, event->mval, false, true);
+ copy_v3_v3(inter->drag_start_co, ruler_item->co[inter->co_index]);
+ }
+ else {
+ negate_v3_v3(inter->drag_start_co, rv3d->ofs);
+ copy_v3_v3(ruler_item->co[0], inter->drag_start_co);
+ view3d_ruler_item_project(ruler_info, ruler_item->co[0], event->mval);
+ }
+
+ copy_v3_v3(ruler_item->co[2], ruler_item->co[0]);
+ ruler_item->mpr.highlight_part = inter->co_index = 2;
+ }
+ return OPERATOR_FINISHED;
+}
+
+void VIEW3D_OT_ruler_add(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Ruler Add";
+ ot->idname = "VIEW3D_OT_ruler_add";
+ ot->description = "";
+
+ ot->invoke = view3d_ruler_add_invoke;
+ ot->poll = view3d_ruler_poll;
+
+ /* flags */
+ ot->flag = OPTYPE_UNDO | OPTYPE_INTERNAL;
+}
+
+/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_ops.c b/source/blender/editors/space_view3d/view3d_ops.c
index d71639c35d2..d986e8ff6ee 100644
--- a/source/blender/editors/space_view3d/view3d_ops.c
+++ b/source/blender/editors/space_view3d/view3d_ops.c
@@ -46,6 +46,7 @@
#include "BKE_appdir.h"
#include "BKE_blender_copybuffer.h"
#include "BKE_context.h"
+#include "BKE_group.h"
#include "BKE_main.h"
#include "BKE_report.h"
@@ -81,14 +82,16 @@ static int view3d_copybuffer_exec(bContext *C, wmOperator *op)
CTX_DATA_END;
for (Group *group = bmain->group.first; group; group = group->id.next) {
- for (GroupObject *go = group->gobject.first; go; go = go->next) {
- if (go->ob && (go->ob->id.tag & LIB_TAG_DOIT)) {
+ FOREACH_GROUP_OBJECT_BEGIN(group, object)
+ {
+ if (object && (object->id.tag & LIB_TAG_DOIT)) {
BKE_copybuffer_tag_ID(&group->id);
/* don't expand out to all other objects */
group->id.tag &= ~LIB_TAG_NEED_EXPAND;
break;
}
}
+ FOREACH_GROUP_OBJECT_END;
}
BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer.blend");
@@ -119,8 +122,8 @@ static int view3d_pastebuffer_exec(bContext *C, wmOperator *op)
if (RNA_boolean_get(op->ptr, "autoselect"))
flag |= FILE_AUTOSELECT;
- if (RNA_boolean_get(op->ptr, "active_layer"))
- flag |= FILE_ACTIVELAY;
+ if (RNA_boolean_get(op->ptr, "active_collection"))
+ flag |= FILE_ACTIVE_COLLECTION;
BLI_make_file_string("/", str, BKE_tempdir_base(), "copybuffer.blend");
if (BKE_copybuffer_paste(C, str, flag, op->reports)) {
@@ -152,7 +155,7 @@ static void VIEW3D_OT_pastebuffer(wmOperatorType *ot)
ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
RNA_def_boolean(ot->srna, "autoselect", true, "Select", "Select pasted objects");
- RNA_def_boolean(ot->srna, "active_layer", true, "Active Layer", "Put pasted objects on the active layer");
+ RNA_def_boolean(ot->srna, "active_collection", true, "Active Collection", "Put pasted objects on the active collection");
}
/* ************************** registration **********************************/
@@ -193,16 +196,12 @@ void view3d_operatortypes(void)
WM_operatortype_append(VIEW3D_OT_render_border);
WM_operatortype_append(VIEW3D_OT_clear_render_border);
WM_operatortype_append(VIEW3D_OT_zoom_border);
- WM_operatortype_append(VIEW3D_OT_manipulator);
- WM_operatortype_append(VIEW3D_OT_enable_manipulator);
WM_operatortype_append(VIEW3D_OT_cursor3d);
WM_operatortype_append(VIEW3D_OT_select_lasso);
WM_operatortype_append(VIEW3D_OT_select_menu);
WM_operatortype_append(VIEW3D_OT_camera_to_view);
WM_operatortype_append(VIEW3D_OT_camera_to_view_selected);
WM_operatortype_append(VIEW3D_OT_object_as_camera);
- WM_operatortype_append(VIEW3D_OT_localview);
- WM_operatortype_append(VIEW3D_OT_game_start);
WM_operatortype_append(VIEW3D_OT_fly);
WM_operatortype_append(VIEW3D_OT_walk);
WM_operatortype_append(VIEW3D_OT_navigate);
@@ -224,6 +223,8 @@ void view3d_operatortypes(void)
WM_operatortype_append(VIEW3D_OT_toggle_render);
+ WM_operatortype_append(VIEW3D_OT_ruler_add);
+
transform_operatortypes();
}
@@ -240,24 +241,7 @@ void view3d_keymap(wmKeyConfig *keyconf)
/* only for region 3D window */
keymap = WM_keymap_find(keyconf, "3D View", SPACE_VIEW3D, 0);
- /* Shift+LMB behavior first, so it has priority over KM_ANY item below. */
- kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", true);
- RNA_boolean_set(kmi->ptr, "use_planar_constraint", true);
- RNA_boolean_set(kmi->ptr, "use_accurate", false);
-
- kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_SHIFT, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", true);
- RNA_boolean_set(kmi->ptr, "use_planar_constraint", false);
- RNA_boolean_set(kmi->ptr, "use_accurate", true);
-
- /* Using KM_ANY here to allow holding modifiers before starting to transform. */
- kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_manipulator", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
- RNA_boolean_set(kmi->ptr, "release_confirm", true);
- RNA_boolean_set(kmi->ptr, "use_planar_constraint", false);
- RNA_boolean_set(kmi->ptr, "use_accurate", false);
-
- WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_PRESS, 0, 0);
+ WM_keymap_verify_item(keymap, "VIEW3D_OT_cursor3d", ACTIONMOUSE, KM_CLICK, 0, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_rotate", MIDDLEMOUSE, KM_PRESS, 0, 0);
WM_keymap_verify_item(keymap, "VIEW3D_OT_move", MIDDLEMOUSE, KM_PRESS, KM_SHIFT, 0);
@@ -372,8 +356,6 @@ void view3d_keymap(wmKeyConfig *keyconf)
kmi = WM_keymap_add_item(keymap, "VIEW3D_OT_viewnumpad", PAD7, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
RNA_enum_set(kmi->ptr, "type", RV3D_VIEW_BOTTOM);
RNA_boolean_set(kmi->ptr, "align_active", true);
-
- WM_keymap_add_item(keymap, "VIEW3D_OT_localview", PADSLASHKEY, KM_PRESS, 0, 0);
#ifdef WITH_INPUT_NDOF
/* note: positioned here so keymaps show keyboard keys if assigned */
@@ -422,12 +404,12 @@ void view3d_keymap(wmKeyConfig *keyconf)
/* drawtype */
kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, 0, 0);
- RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
+ RNA_string_set(kmi->ptr, "data_path", "space_data.shading.type");
RNA_string_set(kmi->ptr, "value_1", "SOLID");
RNA_string_set(kmi->ptr, "value_2", "WIREFRAME");
kmi = WM_keymap_add_item(keymap, "WM_OT_context_toggle_enum", ZKEY, KM_PRESS, KM_ALT, 0);
- RNA_string_set(kmi->ptr, "data_path", "space_data.viewport_shade");
+ RNA_string_set(kmi->ptr, "data_path", "space_data.shading.type");
RNA_string_set(kmi->ptr, "value_1", "SOLID");
RNA_string_set(kmi->ptr, "value_2", "TEXTURED");
diff --git a/source/blender/editors/space_view3d/view3d_project.c b/source/blender/editors/space_view3d/view3d_project.c
index 2e876bc48b3..eb86800f4a9 100644
--- a/source/blender/editors/space_view3d/view3d_project.c
+++ b/source/blender/editors/space_view3d/view3d_project.c
@@ -36,14 +36,13 @@
#include "BLI_sys_types.h" /* int64_t */
-#include "BIF_gl.h" /* bglMats */
-#include "BIF_glutil.h" /* bglMats */
-
#include "BLI_math_vector.h"
#include "BKE_camera.h"
#include "BKE_screen.h"
+#include "GPU_matrix.h"
+
#include "ED_view3d.h" /* own include */
#define BL_NEAR_CLIP 0.001
@@ -310,6 +309,7 @@ float ED_view3d_calc_zfac(const RegionView3D *rv3d, const float co[3], bool *r_f
}
static void view3d_win_to_ray_segment(
+ struct Depsgraph *depsgraph,
const ARegion *ar, const View3D *v3d, const float mval[2],
float r_ray_co[3], float r_ray_dir[3], float r_ray_start[3], float r_ray_end[3])
{
@@ -327,7 +327,7 @@ static void view3d_win_to_ray_segment(
start_offset = -end_offset;
}
else {
- ED_view3d_clip_range_get(v3d, rv3d, &start_offset, &end_offset, false);
+ ED_view3d_clip_range_get(depsgraph, v3d, rv3d, &start_offset, &end_offset, false);
}
if (r_ray_start) {
@@ -366,12 +366,13 @@ bool ED_view3d_clip_segment(const RegionView3D *rv3d, float ray_start[3], float
* \return success, false if the ray is totally clipped.
*/
bool ED_view3d_win_to_ray_ex(
+ struct Depsgraph *depsgraph,
const ARegion *ar, const View3D *v3d, const float mval[2],
float r_ray_co[3], float r_ray_normal[3], float r_ray_start[3], bool do_clip)
{
float ray_end[3];
- view3d_win_to_ray_segment(ar, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end);
+ view3d_win_to_ray_segment(depsgraph, ar, v3d, mval, r_ray_co, r_ray_normal, r_ray_start, ray_end);
/* bounds clipping */
if (do_clip) {
@@ -395,10 +396,11 @@ bool ED_view3d_win_to_ray_ex(
* \return success, false if the ray is totally clipped.
*/
bool ED_view3d_win_to_ray(
+ struct Depsgraph *depsgraph,
const ARegion *ar, const View3D *v3d, const float mval[2],
float r_ray_start[3], float r_ray_normal[3], const bool do_clip)
{
- return ED_view3d_win_to_ray_ex(ar, v3d, mval, NULL, r_ray_normal, r_ray_start, do_clip);
+ return ED_view3d_win_to_ray_ex(depsgraph, ar, v3d, mval, NULL, r_ray_normal, r_ray_start, do_clip);
}
/**
@@ -628,10 +630,11 @@ void ED_view3d_win_to_vector(const ARegion *ar, const float mval[2], float out[3
* \param do_clip Optionally clip the ray by the view clipping planes.
* \return success, false if the segment is totally clipped.
*/
-bool ED_view3d_win_to_segment(const ARegion *ar, View3D *v3d, const float mval[2],
+bool ED_view3d_win_to_segment(struct Depsgraph *depsgraph,
+ const ARegion *ar, View3D *v3d, const float mval[2],
float r_ray_start[3], float r_ray_end[3], const bool do_clip)
{
- view3d_win_to_ray_segment(ar, v3d, mval, NULL, NULL, r_ray_start, r_ray_end);
+ view3d_win_to_ray_segment(depsgraph, ar, v3d, mval, NULL, NULL, r_ray_start, r_ray_end);
/* bounds clipping */
if (do_clip) {
@@ -661,16 +664,22 @@ void ED_view3d_ob_project_mat_get_from_obmat(const RegionView3D *rv3d, float obm
}
/**
- * Uses window coordinates (x,y) and depth component z to find a point in
- * modelspace */
-void ED_view3d_unproject(bglMats *mats, float out[3], const float x, const float y, const float z)
+ * Convert between region relative coordinates (x,y) and depth component z and
+ * a point in world space. */
+void ED_view3d_project(const struct ARegion *ar, const float world[3], float region[3])
{
- double ux, uy, uz;
+ // viewport is set up to make coordinates relative to the region, not window
+ RegionView3D *rv3d = ar->regiondata;
+ int viewport[4] = {0, 0, ar->winx, ar->winy};
- gluUnProject(x, y, z, mats->modelview, mats->projection,
- (GLint *)mats->viewport, &ux, &uy, &uz);
+ gpuProject(world, rv3d->viewmat, rv3d->winmat, viewport, region);
+}
+
+bool ED_view3d_unproject(const struct ARegion *ar, float regionx, float regiony, float regionz, float world[3])
+{
+ RegionView3D *rv3d = ar->regiondata;
+ int viewport[4] = {0, 0, ar->winx, ar->winy};
+ float region[3] = {regionx, regiony, regionz};
- out[0] = ux;
- out[1] = uy;
- out[2] = uz;
+ return gpuUnProject(region, rv3d->viewmat, rv3d->winmat, viewport, world);
}
diff --git a/source/blender/editors/space_view3d/view3d_ruler.c b/source/blender/editors/space_view3d/view3d_ruler.c
index f2c87953302..6706a98ba55 100644
--- a/source/blender/editors/space_view3d/view3d_ruler.c
+++ b/source/blender/editors/space_view3d/view3d_ruler.c
@@ -43,6 +43,9 @@
#include "BIF_gl.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -279,7 +282,7 @@ static void ruler_state_set(bContext *C, RulerInfo *ruler_info, int state)
}
else if (state == RULER_STATE_DRAG) {
ruler_info->snap_context = ED_transform_snap_object_context_create_view3d(
- CTX_data_main(C), CTX_data_scene(C), 0,
+ CTX_data_main(C), CTX_data_scene(C), CTX_data_depsgraph(C), 0,
ruler_info->ar, CTX_wm_view3d(C));
}
else {
@@ -425,12 +428,11 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
#define ARC_STEPS 24
const int arc_steps = ARC_STEPS;
int i;
- //unsigned int color_act = 0x666600;
- unsigned int color_act = 0xffffff;
- unsigned int color_base = 0x0;
- unsigned char color_back[4] = {0xff, 0xff, 0xff, 0x80};
+ const float color_act[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ const float color_base[4] = {0.0f, 0.0f, 0.0f, 1.0f};
unsigned char color_text[3];
unsigned char color_wire[3];
+ float color_back[4] = {1.0f, 1.0f, 1.0f, 0.5f};
/* anti-aliased lines for more consistent appearance */
glEnable(GL_LINE_SMOOTH);
@@ -455,28 +457,37 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
glEnable(GL_BLEND);
- cpack(is_act ? color_act : color_base);
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
if (ruler_item->flag & RULERITEM_USE_ANGLE) {
- glBegin(GL_LINE_STRIP);
- for (j = 0; j < 3; j++) {
- glVertex2fv(co_ss[j]);
- }
- glEnd();
- cpack(0xaaaaaa);
- setlinestyle(3);
- glBegin(GL_LINE_STRIP);
- for (j = 0; j < 3; j++) {
- glVertex2fv(co_ss[j]);
- }
- glEnd();
- setlinestyle(0);
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ const float *col = is_act ? color_act : color_base;
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {col[0], col[1], col[2], col[3]}}, 2);
+ immUniform1f("dash_width", 6.0f);
+
+ immBegin(GWN_PRIM_LINE_STRIP, 3);
+
+ immVertex2fv(shdr_pos, co_ss[0]);
+ immVertex2fv(shdr_pos, co_ss[1]);
+ immVertex2fv(shdr_pos, co_ss[2]);
+
+ immEnd();
+
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
/* arc */
{
float dir_tmp[3];
float co_tmp[3];
- float arc_ss_coords[ARC_STEPS + 1][2];
+ float arc_ss_coord[2];
float dir_a[3];
float dir_b[3];
@@ -500,46 +511,19 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
copy_v3_v3(dir_tmp, dir_a);
- glColor3ubv(color_wire);
+ immUniformColor3ubv(color_wire);
+
+ immBegin(GWN_PRIM_LINE_STRIP, arc_steps + 1);
for (j = 0; j <= arc_steps; j++) {
madd_v3_v3v3fl(co_tmp, ruler_item->co[1], dir_tmp, px_scale);
- ED_view3d_project_float_global(ar, co_tmp, arc_ss_coords[j], V3D_PROJ_TEST_NOP);
+ ED_view3d_project_float_global(ar, co_tmp, arc_ss_coord, V3D_PROJ_TEST_NOP);
mul_qt_v3(quat, dir_tmp);
- }
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(2, GL_FLOAT, 0, arc_ss_coords);
- glDrawArrays(GL_LINE_STRIP, 0, arc_steps + 1);
- glDisableClientState(GL_VERTEX_ARRAY);
- }
- /* text */
- {
- char numstr[256];
- float numstr_size[2];
- float pos[2];
- const int prec = 2; /* XXX, todo, make optional */
-
- ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
-
- BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
-
- pos[0] = co_ss[1][0] + (cap_size * 2.0f);
- pos[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
+ immVertex2fv(shdr_pos, arc_ss_coord);
+ }
- /* draw text (bg) */
- glColor4ubv(color_back);
- UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox(
- pos[0] - bg_margin, pos[1] - bg_margin,
- pos[0] + bg_margin + numstr_size[0], pos[1] + bg_margin + numstr_size[1],
- bg_radius);
- /* draw text */
- glColor3ubv(color_text);
- BLF_position(blf_mono_font, pos[0], pos[1], 0.0f);
- BLF_rotation(blf_mono_font, 0.0f);
- BLF_draw(blf_mono_font, numstr, sizeof(numstr));
+ immEnd();
}
/* capping */
@@ -560,75 +544,84 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
glEnable(GL_BLEND);
- glColor3ubv(color_wire);
+ immUniformColor3ubv(color_wire);
- glBegin(GL_LINES);
+ immBegin(GWN_PRIM_LINES, 8);
madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, cap_size);
- glVertex2fv(cap);
+ immVertex2fv(shdr_pos, cap);
madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec_a, -cap_size);
- glVertex2fv(cap);
+ immVertex2fv(shdr_pos, cap);
madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, cap_size);
- glVertex2fv(cap);
+ immVertex2fv(shdr_pos, cap);
madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec_b, -cap_size);
- glVertex2fv(cap);
+ immVertex2fv(shdr_pos, cap);
/* angle vertex */
- glVertex2f(co_ss[1][0] - cap_size, co_ss[1][1] - cap_size);
- glVertex2f(co_ss[1][0] + cap_size, co_ss[1][1] + cap_size);
- glVertex2f(co_ss[1][0] - cap_size, co_ss[1][1] + cap_size);
- glVertex2f(co_ss[1][0] + cap_size, co_ss[1][1] - cap_size);
- glEnd();
+ immVertex2f(shdr_pos, co_ss[1][0] - cap_size, co_ss[1][1] - cap_size);
+ immVertex2f(shdr_pos, co_ss[1][0] + cap_size, co_ss[1][1] + cap_size);
+ immVertex2f(shdr_pos, co_ss[1][0] - cap_size, co_ss[1][1] + cap_size);
+ immVertex2f(shdr_pos, co_ss[1][0] + cap_size, co_ss[1][1] - cap_size);
+
+ immEnd();
glDisable(GL_BLEND);
}
- }
- else {
- glBegin(GL_LINE_STRIP);
- for (j = 0; j < 3; j += 2) {
- glVertex2fv(co_ss[j]);
- }
- glEnd();
- cpack(0xaaaaaa);
- setlinestyle(3);
- glBegin(GL_LINE_STRIP);
- for (j = 0; j < 3; j += 2) {
- glVertex2fv(co_ss[j]);
- }
- glEnd();
- setlinestyle(0);
- sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[2]);
+ immUnbindProgram();
/* text */
{
char numstr[256];
float numstr_size[2];
- const int prec = 6; /* XXX, todo, make optional */
- float pos[2];
+ float posit[2];
+ const int prec = 2; /* XXX, todo, make optional */
ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
- mid_v2_v2v2(pos, co_ss[0], co_ss[2]);
-
- /* center text */
- pos[0] -= numstr_size[0] / 2.0f;
- pos[1] -= numstr_size[1] / 2.0f;
+ posit[0] = co_ss[1][0] + (cap_size * 2.0f);
+ posit[1] = co_ss[1][1] - (numstr_size[1] / 2.0f);
/* draw text (bg) */
- glColor4ubv(color_back);
UI_draw_roundbox_corner_set(UI_CNR_ALL);
- UI_draw_roundbox(pos[0] - bg_margin, pos[1] - bg_margin,
- pos[0] + bg_margin + numstr_size[0], pos[1] + bg_margin + numstr_size[1],
- bg_radius);
+ UI_draw_roundbox_aa(true,
+ posit[0] - bg_margin, posit[1] - bg_margin,
+ posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
+ bg_radius, color_back);
/* draw text */
- glColor3ubv(color_text);
- BLF_position(blf_mono_font, pos[0], pos[1], 0.0f);
+ BLF_color3ubv(blf_mono_font, color_text);
+ BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);
+ BLF_rotation(blf_mono_font, 0.0f);
BLF_draw(blf_mono_font, numstr, sizeof(numstr));
}
+ }
+ else {
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ const float *col = is_act ? color_act : color_base;
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.67f, 0.67f, 0.67f, 1.0f}, {col[0], col[1], col[2], col[3]}}, 2);
+ immUniform1f("dash_width", 6.0f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+
+ immVertex2fv(shdr_pos, co_ss[0]);
+ immVertex2fv(shdr_pos, co_ss[2]);
+
+ immEnd();
+
+ immUnbindProgram();
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ sub_v2_v2v2(dir_ruler, co_ss[0], co_ss[2]);
/* capping */
{
@@ -638,22 +631,56 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
normalize_v2(rot_90_vec);
glEnable(GL_BLEND);
- glColor3ubv(color_wire);
- glBegin(GL_LINES);
+ immUniformColor3ubv(color_wire);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, cap_size);
- glVertex2fv(cap);
+ immVertex2fv(shdr_pos, cap);
madd_v2_v2v2fl(cap, co_ss[0], rot_90_vec, -cap_size);
- glVertex2fv(cap);
+ immVertex2fv(shdr_pos, cap);
madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, cap_size);
- glVertex2fv(cap);
+ immVertex2fv(shdr_pos, cap);
madd_v2_v2v2fl(cap, co_ss[2], rot_90_vec, -cap_size);
- glVertex2fv(cap);
- glEnd();
+ immVertex2fv(shdr_pos, cap);
+
+ immEnd();
glDisable(GL_BLEND);
}
+
+ immUnbindProgram();
+
+ /* text */
+ {
+ char numstr[256];
+ float numstr_size[2];
+ const int prec = 6; /* XXX, todo, make optional */
+ float posit[2];
+
+ ruler_item_as_string(ruler_item, unit, numstr, sizeof(numstr), prec);
+
+ BLF_width_and_height(blf_mono_font, numstr, sizeof(numstr), &numstr_size[0], &numstr_size[1]);
+
+ mid_v2_v2v2(posit, co_ss[0], co_ss[2]);
+
+ /* center text */
+ posit[0] -= numstr_size[0] / 2.0f;
+ posit[1] -= numstr_size[1] / 2.0f;
+
+ /* draw text (bg) */
+ UI_draw_roundbox_corner_set(UI_CNR_ALL);
+ UI_draw_roundbox_aa(true,
+ posit[0] - bg_margin, posit[1] - bg_margin,
+ posit[0] + bg_margin + numstr_size[0], posit[1] + bg_margin + numstr_size[1],
+ bg_radius, color_back);
+ /* draw text */
+ BLF_color3ubv(blf_mono_font, color_text);
+ BLF_position(blf_mono_font, posit[0], posit[1], 0.0f);
+ BLF_draw(blf_mono_font, numstr, sizeof(numstr));
+ }
}
}
@@ -672,8 +699,14 @@ static void ruler_info_draw_pixel(const struct bContext *C, ARegion *ar, void *a
float co_ss[3];
ED_view3d_project_float_global(ar, ruler_item->co[ruler_item->co_index], co_ss, V3D_PROJ_TEST_NOP);
- cpack(color_act);
- circ(co_ss[0], co_ss[1], size * U.pixelsize);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4fv(color_act);
+
+ imm_draw_circle_wire_2d(pos, co_ss[0], co_ss[1], size * U.pixelsize, 32);
+
+ immUnbindProgram();
}
}
diff --git a/source/blender/editors/space_view3d/view3d_select.c b/source/blender/editors/space_view3d/view3d_select.c
index d184081b03a..555bb0e70de 100644
--- a/source/blender/editors/space_view3d/view3d_select.c
+++ b/source/blender/editors/space_view3d/view3d_select.c
@@ -47,6 +47,7 @@
#include "MEM_guardedalloc.h"
+#include "BLI_array.h"
#include "BLI_math.h"
#include "BLI_lasso_2d.h"
#include "BLI_rect.h"
@@ -55,6 +56,10 @@
#include "BLI_string.h"
#include "BLI_utildefines.h"
+#ifdef __BIG_ENDIAN__
+# include "BLI_endian_switch.h"
+#endif
+
/* vertex box select */
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -63,16 +68,16 @@
#include "BKE_armature.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_mball.h"
#include "BKE_mesh.h"
#include "BKE_object.h"
#include "BKE_paint.h"
#include "BKE_editmesh.h"
+#include "BKE_scene.h"
#include "BKE_tracking.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "DEG_depsgraph.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -94,6 +99,8 @@
#include "UI_interface.h"
#include "GPU_draw.h"
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
#include "view3d_intern.h" /* own include */
@@ -109,7 +116,9 @@ void ED_view3d_viewcontext_init(bContext *C, ViewContext *vc)
{
memset(vc, 0, sizeof(ViewContext));
vc->ar = CTX_wm_region(C);
+ vc->depsgraph = CTX_data_depsgraph(C);
vc->scene = CTX_data_scene(C);
+ vc->view_layer = CTX_data_view_layer(C);
vc->v3d = CTX_wm_view3d(C);
vc->win = CTX_wm_window(C);
vc->rv3d = CTX_wm_region_view3d(C);
@@ -117,32 +126,19 @@ void ED_view3d_viewcontext_init(bContext *C, ViewContext *vc)
vc->obedit = CTX_data_edit_object(C);
}
-/*
- * ob == NULL if you want global matrices
- * */
-void view3d_get_transformation(const ARegion *ar, RegionView3D *rv3d, Object *ob, bglMats *mats)
+void ED_view3d_viewcontext_init_object(ViewContext *vc, Object *obact)
{
- float cpy[4][4];
- int i, j;
+ vc->obact = obact;
+ if (vc->obedit) {
+ BLI_assert(BKE_object_is_in_editmode(obact));
+ vc->obedit = obact;
+ /* previous selections are now invalid. */
+ vc->v3d->flag |= V3D_INVALID_BACKBUF;
- if (ob) {
- mul_m4_m4m4(cpy, rv3d->viewmat, ob->obmat);
- }
- else {
- copy_m4_m4(cpy, rv3d->viewmat);
- }
-
- for (i = 0; i < 4; ++i) {
- for (j = 0; j < 4; ++j) {
- mats->projection[i * 4 + j] = rv3d->winmat[i][j];
- mats->modelview[i * 4 + j] = cpy[i][j];
+ if (vc->em) {
+ vc->em = BKE_editmesh_from_object(vc->obedit);
}
}
-
- mats->viewport[0] = ar->winrct.xmin;
- mats->viewport[1] = ar->winrct.ymin;
- mats->viewport[2] = ar->winx;
- mats->viewport[3] = ar->winy;
}
/* ********************** view3d_select: selection manipulations ********************* */
@@ -397,18 +393,18 @@ static void do_lasso_select_pose(ViewContext *vc, Object *ob, const int mcords[]
bArmature *arm = ob->data;
if (arm->flag & ARM_HAS_VIZ_DEPS) {
/* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
}
-static void object_deselect_all_visible(Scene *scene, View3D *v3d)
+static void object_deselect_all_visible(ViewLayer *view_layer)
{
Base *base;
- for (base = scene->base.first; base; base = base->next) {
- if (BASE_SELECTABLE(v3d, base)) {
- ED_base_object_select(base, BA_DESELECT);
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ if (BASE_SELECTABLE(base)) {
+ ED_object_base_select(base, BA_DESELECT);
}
}
}
@@ -417,21 +413,24 @@ static void do_lasso_select_objects(
ViewContext *vc, const int mcords[][2], const short moves,
const bool extend, const bool select)
{
+ bool is_pose_mode = vc->obact ? (vc->obact->mode & OB_MODE_POSE) : false;
Base *base;
if (extend == false && select)
- object_deselect_all_visible(vc->scene, vc->v3d);
+ object_deselect_all_visible(vc->view_layer);
- for (base = vc->scene->base.first; base; base = base->next) {
- if (BASE_SELECTABLE(vc->v3d, base)) { /* use this to avoid un-needed lasso lookups */
+ for (base = vc->view_layer->object_bases.first; base; base = base->next) {
+ if (BASE_SELECTABLE(base)) { /* use this to avoid un-needed lasso lookups */
if (ED_view3d_project_base(vc->ar, base) == V3D_PROJ_RET_OK) {
if (BLI_lasso_is_point_inside(mcords, moves, base->sx, base->sy, IS_CLIPPED)) {
- ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT);
- base->object->flag = base->flag;
+ ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT);
}
}
- if (vc->obact == base->object && (base->object->mode & OB_MODE_POSE)) {
+ if (is_pose_mode &&
+ ((vc->obact == base->object) || (base->flag & BASE_SELECTED)) &&
+ (base->object->mode & OB_MODE_POSE))
+ {
do_lasso_select_pose(vc, base->object, mcords, moves, select);
}
}
@@ -486,7 +485,9 @@ static void do_lasso_select_mesh__doSelectFace(void *userData, BMFace *efa, cons
}
}
-static void do_lasso_select_mesh(ViewContext *vc, const int mcords[][2], short moves, bool extend, bool select)
+static void do_lasso_select_mesh(
+ ViewContext *vc,
+ const int mcords[][2], short moves, bool extend, bool select)
{
LassoSelectUserData data;
ToolSettings *ts = vc->scene->toolsettings;
@@ -506,7 +507,7 @@ static void do_lasso_select_mesh(ViewContext *vc, const int mcords[][2], short m
/* for non zbuf projections, don't change the GL state */
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
- glLoadMatrixf(vc->rv3d->viewmat);
+ gpuLoadMatrix(vc->rv3d->viewmat);
bbsel = EDBM_backbuf_border_mask_init(vc, mcords, moves, rect.xmin, rect.ymin, rect.xmax, rect.ymax);
if (ts->selectmode & SCE_SELECT_VERTEX) {
@@ -541,8 +542,7 @@ static void do_lasso_select_mesh(ViewContext *vc, const int mcords[][2], short m
EDBM_selectmode_flush(vc->em);
}
-static void do_lasso_select_curve__doSelect(
- void *userData, Nurb *UNUSED(nu), BPoint *bp, BezTriple *bezt, int beztindex, const float screen_co[2])
+static void do_lasso_select_curve__doSelect(void *userData, Nurb *UNUSED(nu), BPoint *bp, BezTriple *bezt, int beztindex, const float screen_co[2])
{
LassoSelectUserData *data = userData;
Object *obedit = data->vc->obedit;
@@ -617,8 +617,7 @@ static void do_lasso_select_lattice(ViewContext *vc, const int mcords[][2], shor
lattice_foreachScreenVert(vc, do_lasso_select_lattice__doSelect, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
}
-static void do_lasso_select_armature__doSelectBone(
- void *userData, struct EditBone *ebone, const float screen_co_a[2], const float screen_co_b[2])
+static void do_lasso_select_armature__doSelectBone(void *userData, struct EditBone *ebone, const float screen_co_a[2], const float screen_co_b[2])
{
LassoSelectUserData *data = userData;
bArmature *arm = data->vc->obedit->data;
@@ -724,8 +723,7 @@ static void do_lasso_select_meta(ViewContext *vc, const int mcords[][2], short m
mball_foreachScreenElem(vc, do_lasso_select_mball__doSelectElem, &data, V3D_PROJ_TEST_CLIP_DEFAULT);
}
-static void do_lasso_select_meshobject__doSelectVert(
- void *userData, MVert *mv, const float screen_co[2], int UNUSED(index))
+static void do_lasso_select_meshobject__doSelectVert(void *userData, MVert *mv, const float screen_co[2], int UNUSED(index))
{
LassoSelectUserData *data = userData;
@@ -838,44 +836,53 @@ static void view3d_lasso_select(
Object *ob = CTX_data_active_object(C);
if (vc->obedit == NULL) { /* Object Mode */
- if (BKE_paint_select_face_test(ob))
+ if (BKE_paint_select_face_test(ob)) {
do_lasso_select_paintface(vc, mcords, moves, extend, select);
- else if (BKE_paint_select_vert_test(ob))
+ }
+ else if (BKE_paint_select_vert_test(ob)) {
do_lasso_select_paintvert(vc, mcords, moves, extend, select);
+ }
else if (ob && (ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT))) {
/* pass */
}
- else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT))
+ else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT)) {
PE_lasso_select(C, mcords, moves, extend, select);
+ }
else {
do_lasso_select_objects(vc, mcords, moves, extend, select);
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc->scene);
}
}
else { /* Edit Mode */
- switch (vc->obedit->type) {
- case OB_MESH:
- do_lasso_select_mesh(vc, mcords, moves, extend, select);
- break;
- case OB_CURVE:
- case OB_SURF:
- do_lasso_select_curve(vc, mcords, moves, extend, select);
- break;
- case OB_LATTICE:
- do_lasso_select_lattice(vc, mcords, moves, extend, select);
- break;
- case OB_ARMATURE:
- do_lasso_select_armature(vc, mcords, moves, extend, select);
- break;
- case OB_MBALL:
- do_lasso_select_meta(vc, mcords, moves, extend, select);
- break;
- default:
- assert(!"lasso select on incorrect object type");
- break;
- }
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc->obedit->data);
+ FOREACH_OBJECT_IN_MODE_BEGIN (vc->view_layer, ob->mode, ob_iter) {
+ ED_view3d_viewcontext_init_object(vc, ob_iter);
+
+ switch (vc->obedit->type) {
+ case OB_MESH:
+ do_lasso_select_mesh(vc, mcords, moves, extend, select);
+ break;
+ case OB_CURVE:
+ case OB_SURF:
+ do_lasso_select_curve(vc, mcords, moves, extend, select);
+ break;
+ case OB_LATTICE:
+ do_lasso_select_lattice(vc, mcords, moves, extend, select);
+ break;
+ case OB_ARMATURE:
+ do_lasso_select_armature(vc, mcords, moves, extend, select);
+ break;
+ case OB_MBALL:
+ do_lasso_select_meta(vc, mcords, moves, extend, select);
+ break;
+ default:
+ assert(!"lasso select on incorrect object type");
+ break;
+ }
+
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc->obedit->data);
+ }
+ FOREACH_OBJECT_IN_MODE_END;
}
}
@@ -973,8 +980,8 @@ static int object_select_menu_exec(bContext *C, wmOperator *op)
if (!toggle) {
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
- if (base->flag & SELECT) {
- ED_base_object_select(base, BA_DESELECT);
+ if ((base->flag & BASE_SELECTED) != 0) {
+ ED_object_base_select(base, BA_DESELECT);
changed = true;
}
}
@@ -985,8 +992,8 @@ static int object_select_menu_exec(bContext *C, wmOperator *op)
{
/* this is a bit dodjy, there should only be ONE object with this name, but library objects can mess this up */
if (STREQ(name, base->object->id.name + 2)) {
- ED_base_object_activate(C, base);
- ED_base_object_select(base, BA_SELECT);
+ ED_object_base_activate(C, base);
+ ED_object_base_select(base, BA_SELECT);
changed = true;
}
}
@@ -1030,14 +1037,12 @@ void VIEW3D_OT_select_menu(wmOperatorType *ot)
RNA_def_boolean(ot->srna, "toggle", 0, "Toggle", "Toggle selection instead of deselecting everything first");
}
-static void deselectall_except(Scene *scene, Base *b) /* deselect all except b */
+static void deselectall_except(ViewLayer *view_layer, Base *b) /* deselect all except b */
{
- Base *base;
-
- for (base = FIRSTBASE; base; base = base->next) {
- if (base->flag & SELECT) {
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (base->flag & BASE_SELECTED) {
if (b != base) {
- ED_base_object_select(base, BA_DESELECT);
+ ED_object_base_select(base, BA_DESELECT);
}
}
}
@@ -1050,7 +1055,8 @@ static Base *object_mouse_select_menu(
short baseCount = 0;
bool ok;
LinkNode *linklist = NULL;
-
+
+ /* handle base->object->select_color */
CTX_DATA_BEGIN (C, Base *, base, selectable_bases)
{
ok = false;
@@ -1059,7 +1065,7 @@ static Base *object_mouse_select_menu(
if (buffer) {
for (int a = 0; a < hits; a++) {
/* index was converted */
- if (base->selcol == (buffer[(4 * a) + 3] & ~0xFFFF0000)) {
+ if (base->object->select_color == (buffer[(4 * a) + 3] & ~0xFFFF0000)) {
ok = true;
break;
}
@@ -1249,8 +1255,7 @@ static Base *mouse_select_eval_buffer(
ViewContext *vc, const uint *buffer, int hits,
Base *startbase, bool has_bones, bool do_nearest)
{
- Scene *scene = vc->scene;
- View3D *v3d = vc->v3d;
+ ViewLayer *view_layer = vc->view_layer;
Base *base, *basact = NULL;
int a;
@@ -1270,7 +1275,9 @@ static Base *mouse_select_eval_buffer(
}
else {
/* only exclude active object when it is selected... */
- if (BASACT && (BASACT->flag & SELECT) && hits > 1) notcol = BASACT->selcol;
+ if (BASACT(view_layer) && (BASACT(view_layer)->flag & BASE_SELECTED) && hits > 1) {
+ notcol = BASACT(view_layer)->object->select_color;
+ }
for (a = 0; a < hits; a++) {
if (min > buffer[4 * a + 1] && notcol != (buffer[4 * a + 3] & 0xFFFF)) {
@@ -1280,10 +1287,10 @@ static Base *mouse_select_eval_buffer(
}
}
- base = FIRSTBASE;
+ base = FIRSTBASE(view_layer);
while (base) {
- if (BASE_SELECTABLE(v3d, base)) {
- if (base->selcol == selcol) break;
+ if (BASE_SELECTABLE(base)) {
+ if (base->object->select_color == selcol) break;
}
base = base->next;
}
@@ -1295,23 +1302,23 @@ static Base *mouse_select_eval_buffer(
while (base) {
/* skip objects with select restriction, to prevent prematurely ending this loop
* with an un-selectable choice */
- if (base->object->restrictflag & OB_RESTRICT_SELECT) {
+ if ((base->flag & BASE_SELECTABLED) == 0) {
base = base->next;
- if (base == NULL) base = FIRSTBASE;
+ if (base == NULL) base = FIRSTBASE(view_layer);
if (base == startbase) break;
}
- if (BASE_SELECTABLE(v3d, base)) {
+ if (BASE_SELECTABLE(base)) {
for (a = 0; a < hits; a++) {
if (has_bones) {
/* skip non-bone objects */
if ((buffer[4 * a + 3] & 0xFFFF0000)) {
- if (base->selcol == (buffer[(4 * a) + 3] & 0xFFFF))
+ if (base->object->select_color == (buffer[(4 * a) + 3] & 0xFFFF))
basact = base;
}
}
else {
- if (base->selcol == (buffer[(4 * a) + 3] & 0xFFFF))
+ if (base->object->select_color == (buffer[(4 * a) + 3] & 0xFFFF))
basact = base;
}
}
@@ -1320,7 +1327,7 @@ static Base *mouse_select_eval_buffer(
if (basact) break;
base = base->next;
- if (base == NULL) base = FIRSTBASE;
+ if (base == NULL) base = FIRSTBASE(view_layer);
if (base == startbase) break;
}
}
@@ -1339,13 +1346,14 @@ Base *ED_view3d_give_base_under_cursor(bContext *C, const int mval[2])
/* setup view context for argument to callbacks */
view3d_operator_needs_opengl(C);
+
ED_view3d_viewcontext_init(C, &vc);
hits = mixed_bones_object_selectbuffer(&vc, buffer, mval, false, false, &do_nearest);
if (hits > 0) {
const bool has_bones = selectbuffer_has_bones(buffer, hits);
- basact = mouse_select_eval_buffer(&vc, buffer, hits, vc.scene->base.first, has_bones, do_nearest);
+ basact = mouse_select_eval_buffer(&vc, buffer, hits, vc.view_layer->object_bases.first, has_bones, do_nearest);
}
return basact;
@@ -1377,8 +1385,8 @@ static bool ed_object_select_pick(
{
ViewContext vc;
ARegion *ar = CTX_wm_region(C);
- View3D *v3d = CTX_wm_view3d(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Base *base, *startbase = NULL, *basact = NULL, *oldbasact = NULL;
bool is_obedit;
float dist = ED_view3d_select_dist_px() * 1.3333f;
@@ -1395,10 +1403,13 @@ static bool ed_object_select_pick(
/* signal for view3d_opengl_select to skip editmode objects */
vc.obedit = NULL;
}
-
+
+ /* In pose mode we don't want to mess with object selection. */
+ const bool is_pose_mode = (vc.obact && vc.obact->mode & OB_MODE_POSE);
+
/* always start list from basact in wire mode */
- startbase = FIRSTBASE;
- if (BASACT && BASACT->next) startbase = BASACT->next;
+ startbase = FIRSTBASE(view_layer);
+ if (BASACT(view_layer) && BASACT(view_layer)->next) startbase = BASACT(view_layer)->next;
/* This block uses the control key to make the object selected by its center point rather than its contents */
/* in editmode do not activate */
@@ -1411,14 +1422,14 @@ static bool ed_object_select_pick(
else {
base = startbase;
while (base) {
- if (BASE_SELECTABLE(v3d, base)) {
+ if (BASE_SELECTABLE(base)) {
float screen_co[2];
if (ED_view3d_project_float_global(
ar, base->object->obmat[3], screen_co,
V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
{
float dist_temp = len_manhattan_v2v2(mval_fl, screen_co);
- if (base == BASACT) dist_temp += 10.0f;
+ if (base == BASACT(view_layer)) dist_temp += 10.0f;
if (dist_temp < dist) {
dist = dist_temp;
basact = base;
@@ -1427,7 +1438,7 @@ static bool ed_object_select_pick(
}
base = base->next;
- if (base == NULL) base = FIRSTBASE;
+ if (base == NULL) base = FIRSTBASE(view_layer);
if (base == startbase) break;
}
}
@@ -1457,7 +1468,7 @@ static bool ed_object_select_pick(
if (has_bones && basact) {
if (basact->object->type == OB_CAMERA) {
- if (BASACT == basact) {
+ if (BASACT(view_layer) == basact) {
int i, hitresult;
bool changed = false;
@@ -1466,7 +1477,7 @@ static bool ed_object_select_pick(
/* if there's bundles in buffer select bundles first,
* so non-camera elements should be ignored in buffer */
- if (basact->selcol != (hitresult & 0xFFFF)) {
+ if (basact->object->select_color != (hitresult & 0xFFFF)) {
continue;
}
@@ -1495,8 +1506,8 @@ static bool ed_object_select_pick(
changed = true;
}
- basact->flag |= SELECT;
- basact->object->flag = basact->flag;
+ basact->flag |= BASE_SELECTED;
+ BKE_scene_object_base_flag_sync_from_base(basact);
retval = true;
@@ -1515,28 +1526,28 @@ static bool ed_object_select_pick(
}
}
else if (ED_armature_pose_select_pick_with_buffer(
- scene, basact, buffer, hits, extend, deselect, toggle, do_nearest))
+ view_layer, basact, buffer, hits, extend, deselect, toggle, do_nearest))
{
/* then bone is found */
/* we make the armature selected:
* not-selected active object in posemode won't work well for tools */
- basact->flag |= SELECT;
- basact->object->flag = basact->flag;
+ basact->flag |= BASE_SELECTED;
+ BKE_scene_object_base_flag_sync_from_base(basact);
retval = true;
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, basact->object);
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_ACTIVE, basact->object);
/* in weightpaint, we use selected bone to select vertexgroup, so no switch to new active object */
- if (BASACT && (BASACT->object->mode & OB_MODE_WEIGHT_PAINT)) {
+ if (BASACT(view_layer) && (BASACT(view_layer)->object->mode & OB_MODE_WEIGHT_PAINT)) {
/* prevent activating */
basact = NULL;
}
}
/* prevent bone selecting to pass on to object selecting */
- if (basact == BASACT)
+ if (basact == BASACT(view_layer))
basact = NULL;
}
}
@@ -1548,37 +1559,40 @@ static bool ed_object_select_pick(
if (vc.obedit) {
/* only do select */
- deselectall_except(scene, basact);
- ED_base_object_select(basact, BA_SELECT);
+ deselectall_except(view_layer, basact);
+ ED_object_base_select(basact, BA_SELECT);
}
/* also prevent making it active on mouse selection */
- else if (BASE_SELECTABLE(v3d, basact)) {
+ else if (BASE_SELECTABLE(basact)) {
- oldbasact = BASACT;
+ oldbasact = BASACT(view_layer);
if (extend) {
- ED_base_object_select(basact, BA_SELECT);
+ ED_object_base_select(basact, BA_SELECT);
}
else if (deselect) {
- ED_base_object_select(basact, BA_DESELECT);
+ ED_object_base_select(basact, BA_DESELECT);
}
else if (toggle) {
- if (basact->flag & SELECT) {
+ if (basact->flag & BASE_SELECTED) {
if (basact == oldbasact) {
- ED_base_object_select(basact, BA_DESELECT);
+ ED_object_base_select(basact, BA_DESELECT);
}
}
else {
- ED_base_object_select(basact, BA_SELECT);
+ ED_object_base_select(basact, BA_SELECT);
}
}
else {
- deselectall_except(scene, basact);
- ED_base_object_select(basact, BA_SELECT);
+ /* When enabled, this puts other objects out of multi pose-mode. */
+ if (is_pose_mode == false) {
+ deselectall_except(view_layer, basact);
+ ED_object_base_select(basact, BA_SELECT);
+ }
}
if ((oldbasact != basact) && (is_obedit == false)) {
- ED_base_object_activate(C, basact); /* adds notifier */
+ ED_object_base_activate(C, basact); /* adds notifier */
}
}
@@ -1635,7 +1649,8 @@ static void do_paintvert_box_select__doSelectVert(void *userData, MVert *mv, con
SET_FLAG_FROM_TEST(mv->flag, data->select, SELECT);
}
}
-static int do_paintvert_box_select(ViewContext *vc, rcti *rect, bool select, bool extend)
+static int do_paintvert_box_select(
+ ViewContext *vc, rcti *rect, bool select, bool extend)
{
const bool use_zbuf = (vc->v3d->flag & V3D_ZBUF_SELECT) != 0;
Mesh *me;
@@ -1824,7 +1839,8 @@ static void do_mesh_box_select__doSelectFace(void *userData, BMFace *efa, const
BM_face_select_set(data->vc->em->bm, efa, data->select);
}
}
-static int do_mesh_box_select(ViewContext *vc, rcti *rect, bool select, bool extend)
+static int do_mesh_box_select(
+ ViewContext *vc, rcti *rect, bool select, bool extend)
{
BoxSelectUserData data;
ToolSettings *ts = vc->scene->toolsettings;
@@ -1838,7 +1854,7 @@ static int do_mesh_box_select(ViewContext *vc, rcti *rect, bool select, bool ext
/* for non zbuf projections, don't change the GL state */
ED_view3d_init_mats_rv3d(vc->obedit, vc->rv3d);
- glLoadMatrixf(vc->rv3d->viewmat);
+ gpuLoadMatrix(vc->rv3d->viewmat);
bbsel = EDBM_backbuf_border_init(vc, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
if (ts->selectmode & SCE_SELECT_VERTEX) {
@@ -1877,7 +1893,9 @@ static int do_mesh_box_select(ViewContext *vc, rcti *rect, bool select, bool ext
return OPERATOR_FINISHED;
}
-static int do_meta_box_select(ViewContext *vc, rcti *rect, bool select, bool extend)
+static int do_meta_box_select(
+ ViewContext *vc,
+ const rcti *rect, bool select, bool extend)
{
MetaBall *mb = (MetaBall *)vc->obedit->data;
MetaElem *ml;
@@ -1911,22 +1929,32 @@ static int do_meta_box_select(ViewContext *vc, rcti *rect, bool select, bool ext
return OPERATOR_FINISHED;
}
-static int do_armature_box_select(ViewContext *vc, rcti *rect, bool select, bool extend)
+static int do_armature_box_select(
+ ViewContext *vc,
+ const rcti *rect, bool select, bool extend)
{
- bArmature *arm = vc->obedit->data;
int a;
unsigned int buffer[MAXPICKBUF];
int hits;
hits = view3d_opengl_select(vc, buffer, MAXPICKBUF, rect, VIEW3D_SELECT_ALL);
-
+
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(vc->view_layer, &objects_len);
+
/* clear flag we use to detect point was affected */
- for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next)
- ebone->flag &= ~BONE_DONE;
-
- if (extend == false && select)
- ED_armature_edit_deselect_all_visible(vc->obedit);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ bArmature *arm = obedit->data;
+ for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+ ebone->flag &= ~BONE_DONE;
+ }
+ }
+
+ if (extend == false && select) {
+ ED_armature_edit_deselect_all_visible_multi(objects, objects_len);
+ }
/* first we only check points inside the border */
for (a = 0; a < hits; a++) {
@@ -1935,7 +1963,9 @@ static int do_armature_box_select(ViewContext *vc, rcti *rect, bool select, bool
if ((index & 0xFFFF0000) == 0) {
continue;
}
- EditBone *ebone = BLI_findlink(arm->edbo, index & ~(BONESEL_ANY));
+
+ EditBone *ebone;
+ ED_armature_object_and_ebone_from_select_buffer(objects, objects_len, index, &ebone);
if ((select == false) || ((ebone->flag & BONE_UNSELECTABLE) == 0)) {
if (index & BONESEL_TIP) {
ebone->flag |= BONE_DONE;
@@ -1953,10 +1983,14 @@ static int do_armature_box_select(ViewContext *vc, rcti *rect, bool select, bool
}
/* now we have to flush tag from parents... */
- for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) {
- if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
- if (ebone->parent->flag & BONE_DONE) {
- ebone->flag |= BONE_DONE;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ bArmature *arm = obedit->data;
+ for (EditBone *ebone = arm->edbo->first; ebone; ebone = ebone->next) {
+ if (ebone->parent && (ebone->flag & BONE_CONNECTED)) {
+ if (ebone->parent->flag & BONE_DONE) {
+ ebone->flag |= BONE_DONE;
+ }
}
}
}
@@ -1966,7 +2000,8 @@ static int do_armature_box_select(ViewContext *vc, rcti *rect, bool select, bool
int index = buffer[(4 * a) + 3];
if (index != -1) {
if (index & BONESEL_BONE) {
- EditBone *ebone = BLI_findlink(arm->edbo, index & ~(BONESEL_ANY));
+ EditBone *ebone;
+ ED_armature_object_and_ebone_from_select_buffer(objects, objects_len, index, &ebone);
if ((select == false) || ((ebone->flag & BONE_UNSELECTABLE) == 0)) {
if (!(ebone->flag & BONE_DONE)) {
if (select) {
@@ -1980,40 +2015,72 @@ static int do_armature_box_select(ViewContext *vc, rcti *rect, bool select, bool
}
}
}
-
- ED_armature_edit_sync_selection(arm->edbo);
-
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ bArmature *arm = obedit->data;
+ ED_armature_edit_sync_selection(arm->edbo);
+ }
+
+ MEM_freeN(objects);
+
return hits > 0 ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
+/**
+ * Compare result of 'GPU_select': 'uint[4]',
+ * needed for when we need to align with object draw-order.
+ */
+static int opengl_bone_select_buffer_cmp(const void *sel_a_p, const void *sel_b_p)
+{
+ /* 4th element is select id */
+ uint sel_a = ((uint *)sel_a_p)[3];
+ uint sel_b = ((uint *)sel_b_p)[3];
+
+#ifdef __BIG_ENDIAN__
+ BLI_endian_switch_uint32(&sel_a);
+ BLI_endian_switch_uint32(&sel_b);
+#endif
+
+ if (sel_a < sel_b) {
+ return -1;
+ }
+ else if (sel_a > sel_b) {
+ return 1;
+ }
+ else {
+ return 0;
+ }
+}
+
static int do_object_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, bool select, bool extend)
{
- Bone *bone;
- Object *ob = vc->obact;
unsigned int *vbuffer = NULL; /* selection buffer */
- unsigned int *col; /* color in buffer */
int bone_only;
- int bone_selected = 0;
int totobj = MAXPICKBUF; /* XXX solve later */
int hits;
- if ((ob) && (ob->mode & OB_MODE_POSE))
+ if (vc->obact && (vc->obact->mode & OB_MODE_POSE))
bone_only = 1;
else
bone_only = 0;
if (extend == false && select) {
if (bone_only) {
- CTX_DATA_BEGIN (C, bPoseChannel *, pchan, visible_pose_bones)
- {
- if ((select == false) || ((pchan->bone->flag & BONE_UNSELECTABLE) == 0)) {
- pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+ FOREACH_OBJECT_IN_MODE_BEGIN (vc->view_layer, OB_MODE_POSE, ob_iter) {
+ bArmature *arm = ob_iter->data;
+ for (bPoseChannel *pchan = ob_iter->pose->chanbase.first; pchan; pchan = pchan->next) {
+ if (PBONE_VISIBLE(arm, pchan->bone)) {
+ if ((select == false) || ((pchan->bone->flag & BONE_UNSELECTABLE) == 0)) {
+ pchan->bone->flag &= ~(BONE_SELECTED | BONE_TIPSEL | BONE_ROOTSEL);
+ }
+ }
}
}
- CTX_DATA_END;
+ FOREACH_OBJECT_IN_MODE_END;
}
else {
- object_deselect_all_visible(vc->scene, vc->v3d);
+ object_deselect_all_visible(vc->view_layer);
}
}
@@ -2027,59 +2094,86 @@ static int do_object_pose_box_select(bContext *C, ViewContext *vc, rcti *rect, b
* is the same as the object, we have a hit and can move to the next color
* and object pair, if not, just move to the next object,
* keeping the same color until we have a hit.
- *
- * The buffer order is defined by OGL standard, hopefully no stupid GFX card
- * does it incorrectly.
*/
if (hits > 0) { /* no need to loop if there's no hit */
- Base *base;
- col = vbuffer + 3;
-
- for (base = vc->scene->base.first; base && hits; base = base->next) {
- if (BASE_SELECTABLE(vc->v3d, base)) {
- while (base->selcol == (*col & 0xFFFF)) { /* we got an object */
- if (*col & 0xFFFF0000) { /* we got a bone */
- bone = ED_armature_bone_find_index(base->object, *col & ~(BONESEL_ANY));
- if (bone) {
- if (select) {
- if ((bone->flag & BONE_UNSELECTABLE) == 0) {
- bone->flag |= BONE_SELECTED;
- bone_selected = 1;
- }
- }
- else {
- bArmature *arm = base->object->data;
- bone->flag &= ~BONE_SELECTED;
- if (arm->act_bone == bone)
- arm->act_bone = NULL;
- }
+
+ /* The draw order doesn't always match the order we populate the engine, see: T51695. */
+ qsort(vbuffer, hits, sizeof(uint[4]), opengl_bone_select_buffer_cmp);
+
+ Base **bases = NULL;
+ BLI_array_declare(bases);
+
+ for (Base *base = vc->view_layer->object_bases.first; base && hits; base = base->next) {
+ if (BASE_SELECTABLE(base)) {
+ if ((base->object->select_color & 0x0000FFFF) != 0) {
+ BLI_array_append(bases, base);
+ }
+ }
+ }
+
+ for (const uint *col = vbuffer + 3, *col_end = col + (hits * 4); col < col_end; col += 4) {
+ Bone *bone;
+ Base *base = ED_armature_base_and_bone_from_select_buffer(bases, BLI_array_len(bases), *col, &bone);
+
+ if (base == NULL) {
+ continue;
+ }
+ /* Loop over contiguous bone hits for 'base'. */
+ bool bone_selected = false;
+ for (; col != col_end; col += 4) {
+ /* should never fail */
+ if (bone != NULL) {
+ if (select) {
+ if ((bone->flag & BONE_UNSELECTABLE) == 0) {
+ bone->flag |= BONE_SELECTED;
+ bone_selected = true;
}
}
- else if (!bone_only) {
- ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT);
+ else {
+ bArmature *arm = base->object->data;
+ bone->flag &= ~BONE_SELECTED;
+ if (arm->act_bone == bone)
+ arm->act_bone = NULL;
+ }
+ }
+ else if (!bone_only) {
+ ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT);
+ }
+
+ /* Select the next bone if we're not switching bases. */
+ if (col + 4 != col_end) {
+ if ((base->object->select_color & 0x0000FFFF) != (col[4] & 0x0000FFFF)) {
+ break;
+ }
+
+ if ((base->object->pose != NULL) && bone_only) {
+ const uint hit_bone = (col[4] & ~BONESEL_ANY) >> 16;
+ bPoseChannel *pchan = BLI_findlink(&base->object->pose->chanbase, hit_bone);;
+ bone = pchan ? pchan->bone : NULL;
+ }
+ else {
+ bone = NULL;
}
-
- col += 4; /* next color */
- hits--;
- if (hits == 0) break;
}
}
-
+
if (bone_selected) {
if (base->object && (base->object->type == OB_ARMATURE)) {
bArmature *arm = base->object->data;
-
+
WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, base->object);
-
- if (arm && (arm->flag & ARM_HAS_VIZ_DEPS)) {
+
+ if (vc->obact && arm && (arm->flag & ARM_HAS_VIZ_DEPS)) {
/* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&vc->obact->id, OB_RECALC_DATA);
}
}
}
}
-
+
+ MEM_freeN(bases);
+
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc->scene);
}
MEM_freeN(vbuffer);
@@ -2106,63 +2200,75 @@ static int view3d_borderselect_exec(bContext *C, wmOperator *op)
WM_operator_properties_border_to_rcti(op, &rect);
if (vc.obedit) {
- switch (vc.obedit->type) {
- case OB_MESH:
- vc.em = BKE_editmesh_from_object(vc.obedit);
- ret = do_mesh_box_select(&vc, &rect, select, extend);
-// if (EM_texFaceCheck())
- if (ret & OPERATOR_FINISHED) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
- }
- break;
- case OB_CURVE:
- case OB_SURF:
- ret = do_nurbs_box_select(&vc, &rect, select, extend);
- if (ret & OPERATOR_FINISHED) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
- }
- break;
- case OB_MBALL:
- ret = do_meta_box_select(&vc, &rect, select, extend);
- if (ret & OPERATOR_FINISHED) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
- }
- break;
- case OB_ARMATURE:
- ret = do_armature_box_select(&vc, &rect, select, extend);
- if (ret & OPERATOR_FINISHED) {
- WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, vc.obedit);
- }
- break;
- case OB_LATTICE:
- ret = do_lattice_box_select(&vc, &rect, select, extend);
- if (ret & OPERATOR_FINISHED) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
- }
- break;
- default:
- assert(!"border select on incorrect object type");
- break;
+
+ FOREACH_OBJECT_IN_MODE_BEGIN (vc.view_layer, vc.obedit->mode, ob_iter) {
+ ED_view3d_viewcontext_init_object(&vc, ob_iter);
+
+ switch (vc.obedit->type) {
+ case OB_MESH:
+ vc.em = BKE_editmesh_from_object(vc.obedit);
+ ret |= do_mesh_box_select(&vc, &rect, select, extend);
+ if (ret & OPERATOR_FINISHED) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
+ }
+ break;
+ case OB_CURVE:
+ case OB_SURF:
+ ret |= do_nurbs_box_select(&vc, &rect, select, extend);
+ if (ret & OPERATOR_FINISHED) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
+ }
+ break;
+ case OB_MBALL:
+ ret |= do_meta_box_select(&vc, &rect, select, extend);
+ if (ret & OPERATOR_FINISHED) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
+ }
+ break;
+ case OB_ARMATURE:
+ ret |= do_armature_box_select(&vc, &rect, select, extend);
+ if (ret & OPERATOR_FINISHED) {
+ WM_event_add_notifier(C, NC_OBJECT | ND_BONE_SELECT, vc.obedit);
+ }
+ break;
+ case OB_LATTICE:
+ ret |= do_lattice_box_select(&vc, &rect, select, extend);
+ if (ret & OPERATOR_FINISHED) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, vc.obedit->data);
+ }
+ break;
+ default:
+ assert(!"border select on incorrect object type");
+ break;
+ }
}
+ FOREACH_OBJECT_IN_MODE_END;
}
else { /* no editmode, unified for bones and objects */
if (vc.obact && vc.obact->mode & OB_MODE_SCULPT) {
- ret = ED_sculpt_mask_box_select(C, &vc, &rect, select, extend);
+ ret |= ED_sculpt_mask_box_select(C, &vc, &rect, select, extend);
}
else if (vc.obact && BKE_paint_select_face_test(vc.obact)) {
- ret = do_paintface_box_select(&vc, &rect, select, extend);
+ ret |= do_paintface_box_select(&vc, &rect, select, extend);
}
else if (vc.obact && BKE_paint_select_vert_test(vc.obact)) {
- ret = do_paintvert_box_select(&vc, &rect, select, extend);
+ ret |= do_paintvert_box_select(&vc, &rect, select, extend);
}
else if (vc.obact && vc.obact->mode & OB_MODE_PARTICLE_EDIT) {
- ret = PE_border_select(C, &rect, select, extend);
+ ret |= PE_border_select(C, &rect, select, extend);
}
else { /* object mode with none active */
- ret = do_object_pose_box_select(C, &vc, &rect, select, extend);
+ ret |= do_object_pose_box_select(C, &vc, &rect, select, extend);
}
}
+ if (ret & OPERATOR_FINISHED) {
+ ret = OPERATOR_FINISHED;
+ }
+ else {
+ ret = OPERATOR_CANCELLED;
+ }
+
return ret;
}
@@ -2459,8 +2565,7 @@ static void paint_facesel_circle_select(ViewContext *vc, const bool select, cons
}
}
-static void paint_vertsel_circle_select_doSelectVert(
- void *userData, MVert *mv, const float screen_co[2], int UNUSED(index))
+static void paint_vertsel_circle_select_doSelectVert(void *userData, MVert *mv, const float screen_co[2], int UNUSED(index))
{
CircleSelectUserData *data = userData;
@@ -2637,7 +2742,7 @@ static void pose_circle_select(ViewContext *vc, const bool select, const int mva
if (arm->flag & ARM_HAS_VIZ_DEPS) {
/* mask modifier ('armature' mode), etc. */
- DAG_id_tag_update(&vc->obact->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&vc->obact->id, OB_RECALC_DATA);
}
}
}
@@ -2748,7 +2853,8 @@ static void mball_circle_select(ViewContext *vc, const bool select, const int mv
/** Callbacks for circle selection in Editmode */
-static void obedit_circle_select(ViewContext *vc, const bool select, const int mval[2], float rad)
+static void obedit_circle_select(
+ ViewContext *vc, const bool select, const int mval[2], float rad)
{
switch (vc->obedit->type) {
case OB_MESH:
@@ -2774,23 +2880,23 @@ static void obedit_circle_select(ViewContext *vc, const bool select, const int m
static bool object_circle_select(ViewContext *vc, const bool select, const int mval[2], float rad)
{
- Scene *scene = vc->scene;
+ ViewLayer *view_layer = vc->view_layer;
const float radius_squared = rad * rad;
const float mval_fl[2] = {mval[0], mval[1]};
bool changed = false;
- const int select_flag = select ? SELECT : 0;
+ const int select_flag = select ? BASE_SELECTED : 0;
Base *base;
- for (base = FIRSTBASE; base; base = base->next) {
- if (BASE_SELECTABLE(vc->v3d, base) && ((base->flag & SELECT) != select_flag)) {
+ for (base = FIRSTBASE(view_layer); base; base = base->next) {
+ if (BASE_SELECTABLE(base) && ((base->flag & BASE_SELECTED) != select_flag)) {
float screen_co[2];
if (ED_view3d_project_float_global(
vc->ar, base->object->obmat[3], screen_co,
V3D_PROJ_TEST_CLIP_BB | V3D_PROJ_TEST_CLIP_WIN | V3D_PROJ_TEST_CLIP_NEAR) == V3D_PROJ_RET_OK)
{
if (len_squared_v2v2(mval_fl, screen_co) <= radius_squared) {
- ED_base_object_select(base, select ? BA_SELECT : BA_DESELECT);
+ ED_object_base_select(base, select ? BA_SELECT : BA_DESELECT);
changed = true;
}
}
@@ -2804,37 +2910,48 @@ static bool object_circle_select(ViewContext *vc, const bool select, const int m
static int view3d_circle_select_exec(bContext *C, wmOperator *op)
{
ViewContext vc;
- ED_view3d_viewcontext_init(C, &vc);
- Object *obact = vc.obact;
- Object *obedit = vc.obedit;
const int radius = RNA_int_get(op->ptr, "radius");
const bool select = !RNA_boolean_get(op->ptr, "deselect");
const int mval[2] = {RNA_int_get(op->ptr, "x"),
RNA_int_get(op->ptr, "y")};
+
+ ED_view3d_viewcontext_init(C, &vc);
+
+ Object *obact = vc.obact;
+ Object *obedit = vc.obedit;
+
if (obedit || BKE_paint_select_elem_test(obact) ||
(obact && (obact->mode & (OB_MODE_PARTICLE_EDIT | OB_MODE_POSE))) )
{
view3d_operator_needs_opengl(C);
- if (CTX_data_edit_object(C)) {
- obedit_circle_select(&vc, select, mval, (float)radius);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data);
- }
- else if (BKE_paint_select_face_test(obact)) {
- paint_facesel_circle_select(&vc, select, mval, (float)radius);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data);
- }
- else if (BKE_paint_select_vert_test(obact)) {
- paint_vertsel_circle_select(&vc, select, mval, (float)radius);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data);
- }
- else if (obact->mode & OB_MODE_POSE) {
- pose_circle_select(&vc, select, mval, (float)radius);
- }
- else {
- return PE_circle_select(C, select, mval, (float)radius);
+ FOREACH_OBJECT_IN_MODE_BEGIN (vc.view_layer, obact->mode, ob_iter) {
+ ED_view3d_viewcontext_init_object(&vc, ob_iter);
+
+ obact = vc.obact;
+ obedit = vc.obedit;
+
+ if (CTX_data_edit_object(C)) {
+ obedit_circle_select(&vc, select, mval, (float)radius);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data);
+ }
+ else if (BKE_paint_select_face_test(obact)) {
+ paint_facesel_circle_select(&vc, select, mval, (float)radius);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data);
+ }
+ else if (BKE_paint_select_vert_test(obact)) {
+ paint_vertsel_circle_select(&vc, select, mval, (float)radius);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obact->data);
+ }
+ else if (obact->mode & OB_MODE_POSE) {
+ pose_circle_select(&vc, select, mval, (float)radius);
+ }
+ else {
+ return PE_circle_select(C, select, mval, (float)radius);
+ }
}
+ FOREACH_OBJECT_IN_MODE_END;
}
else if (obact && obact->mode & OB_MODE_SCULPT) {
return OPERATOR_CANCELLED;
@@ -2844,7 +2961,7 @@ static int view3d_circle_select_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, vc.scene);
}
}
-
+
return OPERATOR_FINISHED;
}
diff --git a/source/blender/editors/space_view3d/view3d_snap.c b/source/blender/editors/space_view3d/view3d_snap.c
index 5dd69cc66eb..970fb5f5b9d 100644
--- a/source/blender/editors/space_view3d/view3d_snap.c
+++ b/source/blender/editors/space_view3d/view3d_snap.c
@@ -40,13 +40,14 @@
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_mball.h"
#include "BKE_object.h"
#include "BKE_report.h"
#include "BKE_tracking.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -68,6 +69,7 @@ static bool snap_calc_active_center(bContext *C, const bool select_only, float r
static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op))
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Object *obedit = CTX_data_edit_object(C);
Scene *scene = CTX_data_scene(C);
RegionView3D *rv3d = CTX_wm_region_data(C);
@@ -153,7 +155,7 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op))
}
ob->pose->flag |= (POSE_LOCKED | POSE_DO_UNLOCK);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
else {
vec[0] = -ob->obmat[3][0] + gridf * floorf(0.5f + ob->obmat[3][0] / gridf);
@@ -162,7 +164,7 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op))
if (ob->parent) {
float originmat[3][3];
- BKE_object_where_is_calc_ex(scene, NULL, ob, originmat);
+ BKE_object_where_is_calc_ex(depsgraph, scene, NULL, ob, originmat);
invert_m3_m3(imat, originmat);
mul_m3_v3(imat, vec);
@@ -177,7 +179,7 @@ static int snap_sel_to_grid_exec(bContext *C, wmOperator *UNUSED(op))
/* auto-keyframing */
ED_autokeyframe_object(C, scene, ob, ks);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
}
CTX_DATA_END;
@@ -207,6 +209,7 @@ void VIEW3D_OT_snap_selected_to_grid(wmOperatorType *ot)
static int snap_selected_to_location(bContext *C, const float snap_target_global[3], const bool use_offset)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
Object *obedit = CTX_data_edit_object(C);
Object *obact = CTX_data_active_object(C);
@@ -329,7 +332,7 @@ static int snap_selected_to_location(bContext *C, const float snap_target_global
obact->pose->flag |= (POSE_LOCKED | POSE_DO_UNLOCK);
- DAG_id_tag_update(&obact->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&obact->id, OB_RECALC_DATA);
}
else {
struct KeyingSet *ks = ANIM_get_keyingset_for_autokeying(scene, ANIM_KS_LOCATION_ID);
@@ -370,7 +373,7 @@ static int snap_selected_to_location(bContext *C, const float snap_target_global
if (ob->parent) {
float originmat[3][3];
- BKE_object_where_is_calc_ex(scene, NULL, ob, originmat);
+ BKE_object_where_is_calc_ex(depsgraph, scene, NULL, ob, originmat);
invert_m3_m3(imat, originmat);
mul_m3_v3(imat, cursor_parent);
@@ -385,7 +388,7 @@ static int snap_selected_to_location(bContext *C, const float snap_target_global
/* auto-keyframing */
ED_autokeyframe_object(C, scene, ob, ks);
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
}
diff --git a/source/blender/editors/space_view3d/view3d_toolbar.c b/source/blender/editors/space_view3d/view3d_toolbar.c
index dfa64bd2015..26dca5bf252 100644
--- a/source/blender/editors/space_view3d/view3d_toolbar.c
+++ b/source/blender/editors/space_view3d/view3d_toolbar.c
@@ -62,70 +62,6 @@
#include "view3d_intern.h" /* own include */
-
-/* ******************* view3d space & buttons ************** */
-
-static void view3d_panel_operator_redo_buts(const bContext *C, Panel *pa, wmOperator *op)
-{
- uiTemplateOperatorPropertyButs(C, pa->layout, op, NULL, 'V', 0);
-}
-
-static void view3d_panel_operator_redo_header(const bContext *C, Panel *pa)
-{
- wmOperator *op = WM_operator_last_redo(C);
-
- if (op)
- BLI_strncpy(pa->drawname, RNA_struct_ui_name(op->type->srna), sizeof(pa->drawname));
- else
- BLI_strncpy(pa->drawname, IFACE_("Operator"), sizeof(pa->drawname));
-}
-
-static void view3d_panel_operator_redo_operator(const bContext *C, Panel *pa, wmOperator *op)
-{
- if (op->type->flag & OPTYPE_MACRO) {
- for (op = op->macro.first; op; op = op->next) {
- uiItemL(pa->layout, RNA_struct_ui_name(op->type->srna), ICON_NONE);
- view3d_panel_operator_redo_operator(C, pa, op);
- }
- }
- else {
- view3d_panel_operator_redo_buts(C, pa, op);
- }
-}
-
-/* TODO de-duplicate redo panel functions - campbell */
-static void view3d_panel_operator_redo(const bContext *C, Panel *pa)
-{
- wmOperator *op = WM_operator_last_redo(C);
- ARegion *ar;
- ARegion *ar1;
-
- if (op == NULL) {
- return;
- }
-
- /* keep in sync with logic in ED_undo_operator_repeat() */
- ar = CTX_wm_region(C);
- ar1 = BKE_area_find_region_active_win(CTX_wm_area(C));
- if (ar1)
- CTX_wm_region_set((bContext *)C, ar1);
-
- if (WM_operator_poll((bContext *)C, op->type)) {
- uiBlock *block = uiLayoutGetBlock(pa->layout);
-
- if (!WM_operator_check_ui_enabled(C, op->type->name))
- uiLayoutSetEnabled(pa->layout, false);
-
- /* note, blockfunc is a default but->func, use Handle func to allow button callbacks too */
- UI_block_func_handle_set(block, ED_undo_operator_repeat_cb_evt, op);
-
- view3d_panel_operator_redo_operator(C, pa, op);
- }
-
- /* set region back */
- CTX_wm_region_set((bContext *)C, ar);
-}
-
/* ******************* */
typedef struct CustomTool {
@@ -239,19 +175,6 @@ void view3d_toolshelf_register(ARegionType *art)
BLI_addtail(&art->paneltypes, pt);
}
-void view3d_tool_props_register(ARegionType *art)
-{
- PanelType *pt;
-
- pt = MEM_callocN(sizeof(PanelType), "spacetype view3d panel last operator");
- strcpy(pt->idname, "VIEW3D_PT_last_operator");
- strcpy(pt->label, N_("Operator"));
- strcpy(pt->translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
- pt->draw_header = view3d_panel_operator_redo_header;
- pt->draw = view3d_panel_operator_redo;
- BLI_addtail(&art->paneltypes, pt);
-}
-
/* ********** operator to open/close toolshelf region */
static int view3d_toolshelf_toggle_exec(bContext *C, wmOperator *UNUSED(op))
diff --git a/source/blender/editors/space_view3d/view3d_utils.c b/source/blender/editors/space_view3d/view3d_utils.c
index e06ae89fa89..09a3202c85e 100644
--- a/source/blender/editors/space_view3d/view3d_utils.c
+++ b/source/blender/editors/space_view3d/view3d_utils.c
@@ -48,11 +48,15 @@
#include "BKE_context.h"
#include "BKE_object.h"
#include "BKE_screen.h"
-#include "BKE_depsgraph.h" /* for ED_view3d_camera_lock_sync */
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_matrix.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -96,6 +100,7 @@ void ED_view3d_dist_range_get(
* \note copies logic of #ED_view3d_viewplane_get(), keep in sync.
*/
bool ED_view3d_clip_range_get(
+ Depsgraph *depsgraph,
const View3D *v3d, const RegionView3D *rv3d,
float *r_clipsta, float *r_clipend,
const bool use_ortho_factor)
@@ -103,7 +108,7 @@ bool ED_view3d_clip_range_get(
CameraParams params;
BKE_camera_params_init(&params);
- BKE_camera_params_from_view3d(&params, v3d, rv3d);
+ BKE_camera_params_from_view3d(&params, depsgraph, v3d, rv3d);
if (use_ortho_factor && params.is_ortho) {
const float fac = 2.0f / (params.clipend - params.clipsta);
@@ -118,13 +123,14 @@ bool ED_view3d_clip_range_get(
}
bool ED_view3d_viewplane_get(
+ Depsgraph *depsgraph,
const View3D *v3d, const RegionView3D *rv3d, int winx, int winy,
rctf *r_viewplane, float *r_clipsta, float *r_clipend, float *r_pixsize)
{
CameraParams params;
BKE_camera_params_init(&params);
- BKE_camera_params_from_view3d(&params, v3d, rv3d);
+ BKE_camera_params_from_view3d(&params, depsgraph, v3d, rv3d);
BKE_camera_params_compute_viewplane(&params, winx, winy, 1.0f, 1.0f);
if (r_viewplane) *r_viewplane = params.viewplane;
@@ -155,7 +161,7 @@ void view3d_operator_needs_opengl(const bContext *C)
view3d_region_operator_needs_opengl(win, ar);
}
-void view3d_region_operator_needs_opengl(wmWindow *win, ARegion *ar)
+void view3d_region_operator_needs_opengl(wmWindow *UNUSED(win), ARegion *ar)
{
/* for debugging purpose, context should always be OK */
if ((ar == NULL) || (ar->regiontype != RGN_TYPE_WINDOW)) {
@@ -164,11 +170,9 @@ void view3d_region_operator_needs_opengl(wmWindow *win, ARegion *ar)
else {
RegionView3D *rv3d = ar->regiondata;
- wmSubWindowSet(win, ar->swinid);
- glMatrixMode(GL_PROJECTION);
- glLoadMatrixf(rv3d->winmat);
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(rv3d->viewmat);
+ wmViewport(&ar->winrct); // TODO: bad
+ gpuLoadProjectionMatrix(rv3d->winmat);
+ gpuLoadMatrix(rv3d->viewmat);
}
}
@@ -230,6 +234,7 @@ bool ED_view3d_context_activate(bContext *C)
/** \name View Clipping Utilities
*
* \{ */
+
void ED_view3d_clipping_calc_from_boundbox(float clip[4][4], const BoundBox *bb, const bool is_flip)
{
int val;
@@ -244,40 +249,35 @@ void ED_view3d_clipping_calc_from_boundbox(float clip[4][4], const BoundBox *bb,
}
}
-void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], bglMats *mats, const rcti *rect)
+void ED_view3d_clipping_calc(BoundBox *bb, float planes[4][4], const ARegion *ar, const Object *ob, const rcti *rect)
{
- float modelview[4][4];
- double xs, ys, p[3];
- int val, flip_sign, a;
-
- /* near zero floating point values can give issues with gluUnProject
- * in side view on some implementations */
- if (fabs(mats->modelview[0]) < 1e-6) mats->modelview[0] = 0.0;
- if (fabs(mats->modelview[5]) < 1e-6) mats->modelview[5] = 0.0;
-
- /* Set up viewport so that gluUnProject will give correct values */
- mats->viewport[0] = 0;
- mats->viewport[1] = 0;
+ /* init in case unproject fails */
+ memset(bb->vec, 0, sizeof(bb->vec));
/* four clipping planes and bounding volume */
/* first do the bounding volume */
- for (val = 0; val < 4; val++) {
- xs = (val == 0 || val == 3) ? rect->xmin : rect->xmax;
- ys = (val == 0 || val == 1) ? rect->ymin : rect->ymax;
+ for (int val = 0; val < 4; val++) {
+ float xs = (val == 0 || val == 3) ? rect->xmin : rect->xmax;
+ float ys = (val == 0 || val == 1) ? rect->ymin : rect->ymax;
- gluUnProject(xs, ys, 0.0, mats->modelview, mats->projection, mats->viewport, &p[0], &p[1], &p[2]);
- copy_v3fl_v3db(bb->vec[val], p);
+ ED_view3d_unproject(ar, xs, ys, 0.0, bb->vec[val]);
+ ED_view3d_unproject(ar, xs, ys, 1.0, bb->vec[4 + val]);
+ }
+
+ /* optionally transform to object space */
+ if (ob) {
+ float imat[4][4];
+ invert_m4_m4(imat, ob->obmat);
- gluUnProject(xs, ys, 1.0, mats->modelview, mats->projection, mats->viewport, &p[0], &p[1], &p[2]);
- copy_v3fl_v3db(bb->vec[4 + val], p);
+ for (int val = 0; val < 8; val++) {
+ mul_m4_v3(imat, bb->vec[val]);
+ }
}
/* verify if we have negative scale. doing the transform before cross
* product flips the sign of the vector compared to doing cross product
* before transform then, so we correct for that. */
- for (a = 0; a < 16; a++)
- ((float *)modelview)[a] = mats->modelview[a];
- flip_sign = is_negative_m4(modelview);
+ int flip_sign = (ob) ? is_negative_m4(ob->obmat) : false;
ED_view3d_clipping_calc_from_boundbox(planes, bb, flip_sign);
}
@@ -500,7 +500,7 @@ bool ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d)
ob_update = v3d->camera;
while (ob_update) {
- DAG_id_tag_update(&ob_update->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob_update->id, OB_RECALC_OB);
WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, ob_update);
ob_update = ob_update->parent;
}
@@ -512,7 +512,7 @@ bool ED_view3d_camera_lock_sync(View3D *v3d, RegionView3D *rv3d)
ED_view3d_to_object(v3d->camera, rv3d->ofs, rv3d->viewquat, rv3d->dist);
BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag | protect_scale_all);
- DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
+ DEG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, v3d->camera);
}
@@ -593,6 +593,7 @@ bool ED_view3d_camera_lock_autokey(
/** \} */
+
/* -------------------------------------------------------------------- */
/** \name Box View Support
*
@@ -877,22 +878,17 @@ static float view_autodist_depth_margin(ARegion *ar, const int mval[2], int marg
* \param fallback_depth_pt: Use this points depth when no depth can be found.
*/
bool ED_view3d_autodist(
- Scene *scene, ARegion *ar, View3D *v3d,
+ struct Depsgraph *graph, ARegion *ar, View3D *v3d,
const int mval[2], float mouse_worldloc[3],
const bool alphaoverride, const float fallback_depth_pt[3])
{
- bglMats mats; /* ZBuffer depth vars */
float depth_close;
- double cent[2], p[3];
int margin_arr[] = {0, 2, 4};
int i;
bool depth_ok = false;
/* Get Z Depths, needed for perspective, nice for ortho */
- ED_view3d_draw_depth(scene, ar, v3d, alphaoverride);
-
- /* call after in case settings have been modified since last drawing, see: T47089 */
- bgl_get_mats(&mats);
+ ED_view3d_draw_depth(graph, ar, v3d, alphaoverride);
/* Attempt with low margin's first */
i = 0;
@@ -902,15 +898,10 @@ bool ED_view3d_autodist(
} while ((depth_ok == false) && (i < ARRAY_SIZE(margin_arr)));
if (depth_ok) {
- cent[0] = (double)mval[0] + 0.5;
- cent[1] = (double)mval[1] + 0.5;
+ float centx = (float)mval[0] + 0.5f;
+ float centy = (float)mval[1] + 0.5f;
- if (gluUnProject(cent[0], cent[1], depth_close,
- mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
- {
- mouse_worldloc[0] = (float)p[0];
- mouse_worldloc[1] = (float)p[1];
- mouse_worldloc[2] = (float)p[2];
+ if (ED_view3d_unproject(ar, centx, centy, depth_close, mouse_worldloc)) {
return true;
}
}
@@ -924,27 +915,29 @@ bool ED_view3d_autodist(
}
}
-void ED_view3d_autodist_init(Scene *scene, ARegion *ar, View3D *v3d, int mode)
+void ED_view3d_autodist_init(
+ struct Depsgraph *graph,
+ ARegion *ar, View3D *v3d, int mode)
{
/* Get Z Depths, needed for perspective, nice for ortho */
switch (mode) {
case 0:
- ED_view3d_draw_depth(scene, ar, v3d, true);
+ ED_view3d_draw_depth(graph, ar, v3d, true);
break;
case 1:
- ED_view3d_draw_depth_gpencil(scene, ar, v3d);
+ {
+ Scene *scene = DEG_get_evaluated_scene(graph);
+ ED_view3d_draw_depth_gpencil(graph, scene, ar, v3d);
break;
+ }
}
}
/* no 4x4 sampling, run #ED_view3d_autodist_init first */
-bool ED_view3d_autodist_simple(
- ARegion *ar, const int mval[2], float mouse_worldloc[3],
- int margin, float *force_depth)
+bool ED_view3d_autodist_simple(ARegion *ar, const int mval[2], float mouse_worldloc[3],
+ int margin, float *force_depth)
{
- bglMats mats; /* ZBuffer depth vars, could cache? */
float depth;
- double cent[2], p[3];
/* Get Z Depths, needed for perspective, nice for ortho */
if (force_depth)
@@ -955,21 +948,9 @@ bool ED_view3d_autodist_simple(
if (depth == FLT_MAX)
return false;
- cent[0] = (double)mval[0] + 0.5;
- cent[1] = (double)mval[1] + 0.5;
-
- bgl_get_mats(&mats);
-
- if (!gluUnProject(cent[0], cent[1], depth,
- mats.modelview, mats.projection, (GLint *)mats.viewport, &p[0], &p[1], &p[2]))
- {
- return false;
- }
-
- mouse_worldloc[0] = (float)p[0];
- mouse_worldloc[1] = (float)p[1];
- mouse_worldloc[2] = (float)p[2];
- return true;
+ float centx = (float)mval[0] + 0.5f;
+ float centy = (float)mval[1] + 0.5f;
+ return ED_view3d_unproject(ar, centx, centy, depth, mouse_worldloc);
}
bool ED_view3d_autodist_depth(ARegion *ar, const int mval[2], int margin, float *depth)
@@ -1376,7 +1357,7 @@ float ED_view3d_depth_read_cached(const ViewContext *vc, const int mval[2])
}
bool ED_view3d_depth_read_cached_normal(
- const ViewContext *vc, const bglMats *mats, const int mval[2],
+ const ViewContext *vc, const int mval[2],
float r_normal[3])
{
/* Note: we could support passing in a radius.
@@ -1395,7 +1376,7 @@ bool ED_view3d_depth_read_cached_normal(
const double depth = (double)ED_view3d_depth_read_cached(vc, mval_ofs);
if ((depth > depths->depth_range[0]) && (depth < depths->depth_range[1])) {
- if (ED_view3d_depth_unproject(ar, mats, mval_ofs, depth, coords[i])) {
+ if (ED_view3d_depth_unproject(ar, mval_ofs, depth, coords[i])) {
depths_valid[i] = true;
}
}
@@ -1437,21 +1418,13 @@ bool ED_view3d_depth_read_cached_normal(
}
bool ED_view3d_depth_unproject(
- const ARegion *ar, const bglMats *mats,
+ const ARegion *ar,
const int mval[2], const double depth,
float r_location_world[3])
{
- double p[3];
- if (gluUnProject(
- (double)ar->winrct.xmin + mval[0] + 0.5,
- (double)ar->winrct.ymin + mval[1] + 0.5,
- depth, mats->modelview, mats->projection, (const GLint *)mats->viewport,
- &p[0], &p[1], &p[2]))
- {
- copy_v3fl_v3db(r_location_world, p);
- return true;
- }
- return false;
+ float centx = (float)mval[0] + 0.5f;
+ float centy = (float)mval[1] + 0.5f;
+ return ED_view3d_unproject(ar, centx, centy, depth, r_location_world);
}
void ED_view3d_depth_tag_update(RegionView3D *rv3d)
@@ -1461,46 +1434,3 @@ void ED_view3d_depth_tag_update(RegionView3D *rv3d)
}
/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Background Image Utilities
- * \{ */
-
-BGpic *ED_view3d_background_image_new(View3D *v3d)
-{
- BGpic *bgpic = MEM_callocN(sizeof(BGpic), "Background Image");
-
- bgpic->rotation = 0.0f;
- bgpic->size = 5.0f;
- bgpic->blend = 0.5f;
- bgpic->iuser.fie_ima = 2;
- bgpic->iuser.ok = 1;
- bgpic->view = 0; /* 0 for all */
- bgpic->flag |= V3D_BGPIC_EXPANDED;
-
- BLI_addtail(&v3d->bgpicbase, bgpic);
-
- return bgpic;
-}
-
-void ED_view3d_background_image_remove(View3D *v3d, BGpic *bgpic)
-{
- BLI_remlink(&v3d->bgpicbase, bgpic);
-
- MEM_freeN(bgpic);
-}
-
-void ED_view3d_background_image_clear(View3D *v3d)
-{
- BGpic *bgpic = v3d->bgpicbase.first;
-
- while (bgpic) {
- BGpic *next_bgpic = bgpic->next;
-
- ED_view3d_background_image_remove(v3d, bgpic);
-
- bgpic = next_bgpic;
- }
-}
-
-/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_view.c b/source/blender/editors/space_view3d/view3d_view.c
index 56f0e39aca0..b6ea68c8fe4 100644
--- a/source/blender/editors/space_view3d/view3d_view.c
+++ b/source/blender/editors/space_view3d/view3d_view.c
@@ -41,32 +41,28 @@
#include "BKE_action.h"
#include "BKE_camera.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_object.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_scene.h"
-#include "BIF_gl.h"
+#include "DEG_depsgraph.h"
#include "UI_resources.h"
+#include "GPU_glew.h"
#include "GPU_select.h"
+#include "GPU_matrix.h"
#include "WM_api.h"
#include "WM_types.h"
#include "ED_screen.h"
-#ifdef WITH_GAMEENGINE
-# include "BLI_listbase.h"
-# include "BLI_callbacks.h"
+#include "DRW_engine.h"
-# include "GPU_draw.h"
-
-# include "BL_System.h"
-#endif
+#include "DEG_depsgraph_query.h"
#include "view3d_intern.h" /* own include */
@@ -405,8 +401,9 @@ void ED_view3d_smooth_view_force_finish(
/* force update of view matrix so tools that run immediately after
* can use them without redrawing first */
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
- ED_view3d_update_viewmat(scene, v3d, ar, NULL, NULL, NULL);
+ ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL);
}
}
@@ -451,7 +448,7 @@ static int view3d_camera_to_view_exec(bContext *C, wmOperator *UNUSED(op))
BKE_object_tfm_protected_restore(v3d->camera, &obtfm, v3d->camera->protectflag);
- DAG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
+ DEG_id_tag_update(&v3d->camera->id, OB_RECALC_OB);
rv3d->persp = RV3D_CAMOB;
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, v3d->camera);
@@ -504,7 +501,9 @@ void VIEW3D_OT_camera_to_view(wmOperatorType *ot)
* meant to take into account vertex/bone selection for eg. */
static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
View3D *v3d = CTX_wm_view3d(C); /* can be NULL */
Object *camera_ob = v3d ? v3d->camera : scene->camera;
@@ -517,7 +516,7 @@ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
}
/* this function does all the important stuff */
- if (BKE_camera_view_frame_fit_to_scene(scene, v3d, camera_ob, r_co, &r_scale)) {
+ if (BKE_camera_view_frame_fit_to_scene(depsgraph, scene, view_layer, camera_ob, r_co, &r_scale)) {
ObjectTfmProtectedChannels obtfm;
float obmat_new[4][4];
@@ -534,7 +533,7 @@ static int view3d_camera_to_view_selected_exec(bContext *C, wmOperator *op)
BKE_object_tfm_protected_restore(camera_ob, &obtfm, OB_LOCK_SCALE | OB_LOCK_ROT4D);
/* notifiers */
- DAG_id_tag_update(&camera_ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&camera_ob->id, OB_RECALC_OB);
WM_event_add_notifier(C, NC_OBJECT | ND_TRANSFORM, camera_ob);
return OPERATOR_FINISHED;
}
@@ -689,14 +688,14 @@ void VIEW3D_OT_object_as_camera(wmOperatorType *ot)
/**
* \param rect optional for picking (can be NULL).
*/
-void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rcti *rect)
+void view3d_winmatrix_set(Depsgraph *depsgraph, ARegion *ar, const View3D *v3d, const rcti *rect)
{
RegionView3D *rv3d = ar->regiondata;
rctf viewplane;
float clipsta, clipend;
bool is_ortho;
- is_ortho = ED_view3d_viewplane_get(v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend, NULL);
+ is_ortho = ED_view3d_viewplane_get(depsgraph, v3d, rv3d, ar->winx, ar->winy, &viewplane, &clipsta, &clipend, NULL);
rv3d->is_persp = !is_ortho;
#if 0
@@ -715,14 +714,14 @@ void view3d_winmatrix_set(ARegion *ar, const View3D *v3d, const rcti *rect)
}
if (is_ortho) {
- wmOrtho(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
+ gpuOrtho(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
}
else {
- wmFrustum(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
+ gpuFrustum(viewplane.xmin, viewplane.xmax, viewplane.ymin, viewplane.ymax, clipsta, clipend);
}
/* update matrix in 3d view region */
- glGetFloatv(GL_PROJECTION_MATRIX, (float *)rv3d->winmat);
+ gpuGetProjectionMatrix(rv3d->winmat);
}
static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
@@ -741,6 +740,7 @@ static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
/**
* Sets #RegionView3D.viewmat
*
+ * \param depsgraph: Depsgraph.
* \param scene: Scene for camera and cursor location.
* \param v3d: View 3D space data.
* \param rv3d: 3D region which stores the final matrices.
@@ -750,13 +750,14 @@ static void obmat_to_viewmat(RegionView3D *rv3d, Object *ob)
* \note don't set windows active in here, is used by renderwin too.
*/
void view3d_viewmatrix_set(
- Scene *scene,
+ Depsgraph *depsgraph, Scene *scene,
const View3D *v3d, RegionView3D *rv3d, const float rect_scale[2])
{
if (rv3d->persp == RV3D_CAMOB) { /* obs/camera */
if (v3d->camera) {
- BKE_object_where_is_calc(scene, v3d->camera);
- obmat_to_viewmat(rv3d, v3d->camera);
+ Object *camera_object = DEG_get_evaluated_object(depsgraph, v3d->camera);
+ BKE_object_where_is_calc(depsgraph, scene, camera_object);
+ obmat_to_viewmat(rv3d, camera_object);
}
else {
quat_to_mat4(rv3d->viewmat, rv3d->viewquat);
@@ -849,6 +850,45 @@ void view3d_opengl_select_cache_end(void)
GPU_select_cache_end();
}
+#ifndef WITH_OPENGL_LEGACY
+struct DrawSelectLoopUserData {
+ uint pass;
+ uint hits;
+ uint *buffer;
+ uint buffer_len;
+ const rcti *rect;
+ char gpu_select_mode;
+};
+
+static bool drw_select_loop_pass(eDRWSelectStage stage, void *user_data)
+{
+ bool continue_pass = false;
+ struct DrawSelectLoopUserData *data = user_data;
+ if (stage == DRW_SELECT_PASS_PRE) {
+ GPU_select_begin(data->buffer, data->buffer_len, data->rect, data->gpu_select_mode, data->hits);
+ /* always run POST after PRE. */
+ continue_pass = true;
+ }
+ else if (stage == DRW_SELECT_PASS_POST) {
+ int hits = GPU_select_end();
+ if (data->pass == 0) {
+ /* quirk of GPU_select_end, only take hits value from first call. */
+ data->hits = hits;
+ }
+ if (data->gpu_select_mode == GPU_SELECT_NEAREST_FIRST_PASS) {
+ data->gpu_select_mode = GPU_SELECT_NEAREST_SECOND_PASS;
+ continue_pass = (hits > 0);
+ }
+ data->pass += 1;
+ }
+ else {
+ BLI_assert(0);
+ }
+ return continue_pass;
+
+}
+#endif /* WITH_OPENGL_LEGACY */
+
/**
* \warning be sure to account for a negative return value
* This is an error, "Too many objects in select buffer"
@@ -861,12 +901,13 @@ int view3d_opengl_select(
eV3DSelectMode select_mode)
{
struct bThemeState theme_state;
+ Depsgraph *graph = vc->depsgraph;
Scene *scene = vc->scene;
View3D *v3d = vc->v3d;
ARegion *ar = vc->ar;
rcti rect;
int hits;
- const bool use_obedit_skip = (scene->obedit != NULL) && (vc->obedit == NULL);
+ const bool use_obedit_skip = (OBEDIT_FROM_VIEW_LAYER(vc->view_layer) != NULL) && (vc->obedit == NULL);
const bool is_pick_select = (U.gpu_select_pick_deph != 0);
const bool do_passes = (
(is_pick_select == false) &&
@@ -918,37 +959,61 @@ int view3d_opengl_select(
goto finally;
}
+#ifndef WITH_OPENGL_LEGACY
+ /* All of the queries need to be perform on the drawing context. */
+ DRW_opengl_context_enable();
+#endif
+
G.f |= G_PICKSEL;
/* Important we use the 'viewmat' and don't re-calculate since
* the object & bone view locking takes 'rect' into account, see: T51629. */
- ED_view3d_draw_setup_view(vc->win, scene, ar, v3d, vc->rv3d->viewmat, NULL, &rect);
+ ED_view3d_draw_setup_view(vc->win, graph, scene, ar, v3d, vc->rv3d->viewmat, NULL, &rect);
if (v3d->drawtype > OB_WIRE) {
v3d->zbuf = true;
glEnable(GL_DEPTH_TEST);
}
-
+
if (vc->rv3d->rflag & RV3D_CLIPPING)
ED_view3d_clipping_set(vc->rv3d);
- GPU_select_begin(buffer, bufsize, &rect, gpu_select_mode, 0);
- ED_view3d_draw_select_loop(vc, scene, v3d, ar, use_obedit_skip, use_nearest);
-
- hits = GPU_select_end();
-
- /* second pass, to get the closest object to camera */
- if (do_passes && (hits > 0)) {
- GPU_select_begin(buffer, bufsize, &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
-
- ED_view3d_draw_select_loop(vc, scene, v3d, ar, use_obedit_skip, use_nearest);
+#ifdef WITH_OPENGL_LEGACY
+ if (IS_VIEWPORT_LEGACY(vc->v3d)) {
+ GPU_select_begin(buffer, bufsize, &rect, gpu_select_mode, 0);
+ ED_view3d_draw_select_loop(vc, scene, sl, v3d, ar, use_obedit_skip, use_nearest);
+ hits = GPU_select_end();
- GPU_select_end();
+ if (do_passes && (hits > 0)) {
+ GPU_select_begin(buffer, bufsize, &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
+ ED_view3d_draw_select_loop(vc, scene, sl, v3d, ar, use_obedit_skip, use_nearest);
+ GPU_select_end();
+ }
}
+ else
+#else
+ {
+ /* We need to call "GPU_select_*" API's inside DRW_draw_select_loop
+ * because the OpenGL context created & destroyed inside this function. */
+ struct DrawSelectLoopUserData drw_select_loop_user_data = {
+ .pass = 0,
+ .hits = 0,
+ .buffer = buffer,
+ .buffer_len = bufsize,
+ .rect = &rect,
+ .gpu_select_mode = gpu_select_mode,
+ };
+ DRW_draw_select_loop(
+ graph, ar, v3d,
+ use_obedit_skip, use_nearest, &rect,
+ drw_select_loop_pass, &drw_select_loop_user_data);
+ hits = drw_select_loop_user_data.hits;
+ }
+#endif /* WITH_OPENGL_LEGACY */
G.f &= ~G_PICKSEL;
- ED_view3d_draw_setup_view(vc->win, scene, ar, v3d, vc->rv3d->viewmat, NULL, NULL);
+ ED_view3d_draw_setup_view(vc->win, graph, scene, ar, v3d, vc->rv3d->viewmat, NULL, NULL);
if (v3d->drawtype > OB_WIRE) {
v3d->zbuf = 0;
@@ -958,7 +1023,12 @@ int view3d_opengl_select(
if (vc->rv3d->rflag & RV3D_CLIPPING)
ED_view3d_clipping_disable();
+#ifndef WITH_OPENGL_LEGACY
+ DRW_opengl_context_disable();
+#endif
+
finally:
+
if (hits < 0) printf("Too many objects in select buffer\n"); /* XXX make error message */
UI_Theme_Restore(&theme_state);
@@ -969,44 +1039,10 @@ finally:
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Local View Operators
+/** \name View Layer Utilities
* \{ */
-static unsigned int free_localbit(Main *bmain)
-{
- unsigned int lay;
- ScrArea *sa;
- bScreen *sc;
-
- lay = 0;
-
- /* sometimes we loose a localview: when an area is closed */
- /* check all areas: which localviews are in use? */
- for (sc = bmain->screen.first; sc; sc = sc->id.next) {
- for (sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl = sa->spacedata.first;
- for (; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_VIEW3D) {
- View3D *v3d = (View3D *) sl;
- lay |= v3d->lay;
- }
- }
- }
- }
-
- if ((lay & 0x01000000) == 0) return 0x01000000;
- if ((lay & 0x02000000) == 0) return 0x02000000;
- if ((lay & 0x04000000) == 0) return 0x04000000;
- if ((lay & 0x08000000) == 0) return 0x08000000;
- if ((lay & 0x10000000) == 0) return 0x10000000;
- if ((lay & 0x20000000) == 0) return 0x20000000;
- if ((lay & 0x40000000) == 0) return 0x40000000;
- if ((lay & 0x80000000) == 0) return 0x80000000;
-
- return 0;
-}
-
-int ED_view3d_scene_layer_set(int lay, const int *values, int *active)
+int ED_view3d_view_layer_set(int lay, const int *values, int *active)
{
int i, tot = 0;
@@ -1044,476 +1080,4 @@ int ED_view3d_scene_layer_set(int lay, const int *values, int *active)
return lay;
}
-static bool view3d_localview_init(
- wmWindowManager *wm, wmWindow *win,
- Main *bmain, Scene *scene, ScrArea *sa, const int smooth_viewtx,
- ReportList *reports)
-{
- View3D *v3d = sa->spacedata.first;
- Base *base;
- float min[3], max[3], box[3], mid[3];
- float size = 0.0f;
- unsigned int locallay;
- bool ok = false;
-
- if (v3d->localvd) {
- return ok;
- }
-
- INIT_MINMAX(min, max);
-
- locallay = free_localbit(bmain);
-
- if (locallay == 0) {
- BKE_report(reports, RPT_ERROR, "No more than 8 local views");
- ok = false;
- }
- else {
- if (scene->obedit) {
- BKE_object_minmax(scene->obedit, min, max, false);
-
- ok = true;
-
- BASACT->lay |= locallay;
- scene->obedit->lay = BASACT->lay;
- }
- else {
- for (base = FIRSTBASE; base; base = base->next) {
- if (TESTBASE(v3d, base)) {
- BKE_object_minmax(base->object, min, max, false);
- base->lay |= locallay;
- base->object->lay = base->lay;
- ok = true;
- }
- }
- }
-
- sub_v3_v3v3(box, max, min);
- size = max_fff(box[0], box[1], box[2]);
- }
-
- if (ok == true) {
- ARegion *ar;
-
- v3d->localvd = MEM_mallocN(sizeof(View3D), "localview");
-
- memcpy(v3d->localvd, v3d, sizeof(View3D));
-
- mid_v3_v3v3(mid, min, max);
-
- copy_v3_v3(v3d->cursor, mid);
-
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- RegionView3D *rv3d = ar->regiondata;
- bool ok_dist = true;
-
- /* new view values */
- Object *camera_old = NULL;
- float dist_new, ofs_new[3];
-
- rv3d->localvd = MEM_mallocN(sizeof(RegionView3D), "localview region");
- memcpy(rv3d->localvd, rv3d, sizeof(RegionView3D));
-
- negate_v3_v3(ofs_new, mid);
-
- if (rv3d->persp == RV3D_CAMOB) {
- rv3d->persp = RV3D_PERSP;
- camera_old = v3d->camera;
- }
-
- if (rv3d->persp == RV3D_ORTHO) {
- if (size < 0.0001f) {
- ok_dist = false;
- }
- }
-
- if (ok_dist) {
- dist_new = ED_view3d_radius_to_dist(v3d, ar, rv3d->persp, true, (size / 2) * VIEW3D_MARGIN);
- if (rv3d->persp == RV3D_PERSP) {
- /* don't zoom closer than the near clipping plane */
- dist_new = max_ff(dist_new, v3d->near * 1.5f);
- }
- }
-
- ED_view3d_smooth_view_ex(
- wm, win, sa, v3d, ar, smooth_viewtx,
- &(const V3D_SmoothParams) {
- .camera_old = camera_old,
- .ofs = ofs_new, .quat = rv3d->viewquat,
- .dist = ok_dist ? &dist_new : NULL, .lens = &v3d->lens});
- }
- }
-
- v3d->lay = locallay;
- }
- else {
- /* clear flags */
- for (base = FIRSTBASE; base; base = base->next) {
- if (base->lay & locallay) {
- base->lay -= locallay;
- if (base->lay == 0) base->lay = v3d->layact;
- if (base->object != scene->obedit) base->flag |= SELECT;
- base->object->lay = base->lay;
- }
- }
- }
-
- DAG_on_visible_update(bmain, false);
-
- return ok;
-}
-
-static void restore_localviewdata(wmWindowManager *wm, wmWindow *win, Main *bmain, ScrArea *sa, const int smooth_viewtx)
-{
- const bool free = true;
- ARegion *ar;
- View3D *v3d = sa->spacedata.first;
- Object *camera_old, *camera_new;
-
- if (v3d->localvd == NULL) return;
-
- camera_old = v3d->camera;
- camera_new = v3d->localvd->camera;
-
- v3d->lay = v3d->localvd->lay;
- v3d->layact = v3d->localvd->layact;
- v3d->drawtype = v3d->localvd->drawtype;
- v3d->camera = v3d->localvd->camera;
-
- if (free) {
- MEM_freeN(v3d->localvd);
- v3d->localvd = NULL;
- }
-
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->regiontype == RGN_TYPE_WINDOW) {
- RegionView3D *rv3d = ar->regiondata;
-
- if (rv3d->localvd) {
- Object *camera_old_rv3d, *camera_new_rv3d;
-
- camera_old_rv3d = (rv3d->persp == RV3D_CAMOB) ? camera_old : NULL;
- camera_new_rv3d = (rv3d->localvd->persp == RV3D_CAMOB) ? camera_new : NULL;
-
- rv3d->view = rv3d->localvd->view;
- rv3d->persp = rv3d->localvd->persp;
- rv3d->camzoom = rv3d->localvd->camzoom;
-
- ED_view3d_smooth_view_ex(
- wm, win, sa,
- v3d, ar, smooth_viewtx,
- &(const V3D_SmoothParams) {
- .camera_old = camera_old_rv3d, .camera = camera_new_rv3d,
- .ofs = rv3d->localvd->ofs, .quat = rv3d->localvd->viewquat,
- .dist = &rv3d->localvd->dist});
-
- if (free) {
- MEM_freeN(rv3d->localvd);
- rv3d->localvd = NULL;
- }
- }
-
- ED_view3d_shade_update(bmain, v3d, sa);
- }
- }
-}
-
-static bool view3d_localview_exit(
- wmWindowManager *wm, wmWindow *win,
- Main *bmain, Scene *scene, ScrArea *sa, const int smooth_viewtx)
-{
- View3D *v3d = sa->spacedata.first;
- struct Base *base;
- unsigned int locallay;
-
- if (v3d->localvd) {
-
- locallay = v3d->lay & 0xFF000000;
-
- restore_localviewdata(wm, win, bmain, sa, smooth_viewtx);
-
- /* for when in other window the layers have changed */
- if (v3d->scenelock) v3d->lay = scene->lay;
-
- for (base = FIRSTBASE; base; base = base->next) {
- if (base->lay & locallay) {
- base->lay -= locallay;
- if (base->lay == 0) base->lay = v3d->layact;
- if (base->object != scene->obedit) {
- base->flag |= SELECT;
- base->object->flag |= SELECT;
- }
- base->object->lay = base->lay;
- }
- }
-
- DAG_on_visible_update(bmain, false);
-
- return true;
- }
- else {
- return false;
- }
-}
-
-static int localview_exec(bContext *C, wmOperator *op)
-{
- const int smooth_viewtx = WM_operator_smooth_viewtx_get(op);
- wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *win = CTX_wm_window(C);
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- ScrArea *sa = CTX_wm_area(C);
- View3D *v3d = CTX_wm_view3d(C);
- bool changed;
-
- if (v3d->localvd) {
- changed = view3d_localview_exit(wm, win, bmain, scene, sa, smooth_viewtx);
- }
- else {
- changed = view3d_localview_init(wm, win, bmain, scene, sa, smooth_viewtx, op->reports);
- }
-
- if (changed) {
- DAG_id_type_tag(bmain, ID_OB);
- ED_area_tag_redraw(sa);
-
- /* unselected objects become selected when exiting */
- if (v3d->localvd == NULL) {
- WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, scene);
- }
-
- return OPERATOR_FINISHED;
- }
- else {
- return OPERATOR_CANCELLED;
- }
-}
-
-void VIEW3D_OT_localview(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Local View";
- ot->description = "Toggle display of selected object(s) separately and centered in view";
- ot->idname = "VIEW3D_OT_localview";
-
- /* api callbacks */
- ot->exec = localview_exec;
- ot->flag = OPTYPE_UNDO; /* localview changes object layer bitflags */
-
- ot->poll = ED_operator_view3d_active;
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
-/** \name Game Engine Operator
- *
- * Start the game engine (handles context switching).
- * \{ */
-
-#ifdef WITH_GAMEENGINE
-
-static ListBase queue_back;
-static void game_engine_save_state(bContext *C, wmWindow *win)
-{
- Object *obact = CTX_data_active_object(C);
-
- glPushAttrib(GL_ALL_ATTRIB_BITS);
-
- if (obact && obact->mode & OB_MODE_TEXTURE_PAINT)
- GPU_paint_set_mipmap(1);
-
- queue_back = win->queue;
-
- BLI_listbase_clear(&win->queue);
-}
-
-static void game_engine_restore_state(bContext *C, wmWindow *win)
-{
- Object *obact = CTX_data_active_object(C);
-
- if (obact && obact->mode & OB_MODE_TEXTURE_PAINT)
- GPU_paint_set_mipmap(0);
-
- /* check because closing win can set to NULL */
- if (win) {
- win->queue = queue_back;
- }
-
- GPU_state_init();
- GPU_set_tpage(NULL, 0, 0);
-
- glPopAttrib();
-}
-
-/* was space_set_commmandline_options in 2.4x */
-static void game_set_commmandline_options(GameData *gm)
-{
- SYS_SystemHandle syshandle;
- int test;
-
- if ((syshandle = SYS_GetSystem())) {
- /* User defined settings */
- test = (U.gameflags & USER_DISABLE_MIPMAP);
- GPU_set_mipmap(!test);
- SYS_WriteCommandLineInt(syshandle, "nomipmap", test);
-
- /* File specific settings: */
- /* Only test the first one. These two are switched
- * simultaneously. */
- test = (gm->flag & GAME_SHOW_FRAMERATE);
- SYS_WriteCommandLineInt(syshandle, "show_framerate", test);
- SYS_WriteCommandLineInt(syshandle, "show_profile", test);
-
- test = (gm->flag & GAME_SHOW_DEBUG_PROPS);
- SYS_WriteCommandLineInt(syshandle, "show_properties", test);
-
- test = (gm->flag & GAME_SHOW_PHYSICS);
- SYS_WriteCommandLineInt(syshandle, "show_physics", test);
-
- test = (gm->flag & GAME_ENABLE_ALL_FRAMES);
- SYS_WriteCommandLineInt(syshandle, "fixedtime", test);
-
- test = (gm->flag & GAME_ENABLE_ANIMATION_RECORD);
- SYS_WriteCommandLineInt(syshandle, "animation_record", test);
-
- test = (gm->flag & GAME_IGNORE_DEPRECATION_WARNINGS);
- SYS_WriteCommandLineInt(syshandle, "ignore_deprecation_warnings", test);
-
- test = (gm->matmode == GAME_MAT_MULTITEX);
- SYS_WriteCommandLineInt(syshandle, "blender_material", test);
- test = (gm->matmode == GAME_MAT_GLSL);
- SYS_WriteCommandLineInt(syshandle, "blender_glsl_material", test);
- test = (gm->flag & GAME_DISPLAY_LISTS);
- SYS_WriteCommandLineInt(syshandle, "displaylists", test);
-
-
- }
-}
-
-#endif /* WITH_GAMEENGINE */
-
-static int game_engine_poll(bContext *C)
-{
- bScreen *screen;
- /* we need a context and area to launch BGE
- * it's a temporary solution to avoid crash at load time
- * if we try to auto run the BGE. Ideally we want the
- * context to be set as soon as we load the file. */
-
- if (CTX_wm_window(C) == NULL) return 0;
- if ((screen = CTX_wm_screen(C)) == NULL) return 0;
-
- if (CTX_data_mode_enum(C) != CTX_MODE_OBJECT)
- return 0;
-
- if (!BKE_scene_uses_blender_game(screen->scene))
- return 0;
-
- return 1;
-}
-
-static int game_engine_exec(bContext *C, wmOperator *op)
-{
-#ifdef WITH_GAMEENGINE
- Scene *startscene = CTX_data_scene(C);
- Main *bmain = CTX_data_main(C);
- ScrArea /* *sa, */ /* UNUSED */ *prevsa = CTX_wm_area(C);
- ARegion *ar, *prevar = CTX_wm_region(C);
- wmWindow *prevwin = CTX_wm_window(C);
- RegionView3D *rv3d;
- rcti cam_frame;
-
- UNUSED_VARS(op);
-
- /* bad context switch .. */
- if (!ED_view3d_context_activate(C))
- return OPERATOR_CANCELLED;
-
- /* redraw to hide any menus/popups, we don't go back to
- * the window manager until after this operator exits */
- WM_redraw_windows(C);
-
- BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_PRE);
-
- rv3d = CTX_wm_region_view3d(C);
- /* sa = CTX_wm_area(C); */ /* UNUSED */
- ar = CTX_wm_region(C);
-
- view3d_operator_needs_opengl(C);
-
- game_set_commmandline_options(&startscene->gm);
-
- if ((rv3d->persp == RV3D_CAMOB) &&
- (startscene->gm.framing.type == SCE_GAMEFRAMING_BARS) &&
- (startscene->gm.stereoflag != STEREO_DOME))
- {
- /* Letterbox */
- rctf cam_framef;
- ED_view3d_calc_camera_border(startscene, ar, CTX_wm_view3d(C), rv3d, &cam_framef, false);
- cam_frame.xmin = cam_framef.xmin + ar->winrct.xmin;
- cam_frame.xmax = cam_framef.xmax + ar->winrct.xmin;
- cam_frame.ymin = cam_framef.ymin + ar->winrct.ymin;
- cam_frame.ymax = cam_framef.ymax + ar->winrct.ymin;
- BLI_rcti_isect(&ar->winrct, &cam_frame, &cam_frame);
- }
- else {
- cam_frame.xmin = ar->winrct.xmin;
- cam_frame.xmax = ar->winrct.xmax;
- cam_frame.ymin = ar->winrct.ymin;
- cam_frame.ymax = ar->winrct.ymax;
- }
-
-
- game_engine_save_state(C, prevwin);
-
- StartKetsjiShell(C, ar, &cam_frame, 1);
-
- /* window wasnt closed while the BGE was running */
- if (BLI_findindex(&CTX_wm_manager(C)->windows, prevwin) == -1) {
- prevwin = NULL;
- CTX_wm_window_set(C, NULL);
- }
-
- ED_area_tag_redraw(CTX_wm_area(C));
-
- if (prevwin) {
- /* restore context, in case it changed in the meantime, for
- * example by working in another window or closing it */
- CTX_wm_region_set(C, prevar);
- CTX_wm_window_set(C, prevwin);
- CTX_wm_area_set(C, prevsa);
- }
-
- game_engine_restore_state(C, prevwin);
-
- //XXX restore_all_scene_cfra(scene_cfra_store);
- BKE_scene_set_background(CTX_data_main(C), startscene);
- //XXX BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);
-
- BLI_callback_exec(bmain, &startscene->id, BLI_CB_EVT_GAME_POST);
-
- return OPERATOR_FINISHED;
-#else
- UNUSED_VARS(C);
- BKE_report(op->reports, RPT_ERROR, "Game engine is disabled in this build");
- return OPERATOR_CANCELLED;
-#endif
-}
-
-void VIEW3D_OT_game_start(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Start Game Engine";
- ot->description = "Start game engine";
- ot->idname = "VIEW3D_OT_game_start";
-
- /* api callbacks */
- ot->exec = game_engine_exec;
-
- ot->poll = game_engine_poll;
-}
-
/** \} */
diff --git a/source/blender/editors/space_view3d/view3d_walk.c b/source/blender/editors/space_view3d/view3d_walk.c
index f780ca35f30..6bbc0b7d985 100644
--- a/source/blender/editors/space_view3d/view3d_walk.c
+++ b/source/blender/editors/space_view3d/view3d_walk.c
@@ -56,6 +56,10 @@
#include "UI_interface.h"
#include "UI_resources.h"
+#include "GPU_immediate.h"
+
+#include "DEG_depsgraph.h"
+
#include "view3d_intern.h" /* own include */
#ifdef WITH_INPUT_NDOF
@@ -245,6 +249,7 @@ typedef struct WalkInfo {
RegionView3D *rv3d;
View3D *v3d;
ARegion *ar;
+ struct Depsgraph *depsgraph;
Scene *scene;
wmTimer *timer; /* needed for redraws */
@@ -328,7 +333,7 @@ static void drawWalkPixel(const struct bContext *UNUSED(C), ARegion *ar, void *a
rctf viewborder;
if (walk->scene->camera) {
- ED_view3d_calc_camera_border(walk->scene, ar, walk->v3d, walk->rv3d, &viewborder, false);
+ ED_view3d_calc_camera_border(walk->scene, walk->depsgraph, ar, walk->v3d, walk->rv3d, &viewborder, false);
xoff = viewborder.xmin + BLI_rctf_size_x(&viewborder) * 0.5f;
yoff = viewborder.ymin + BLI_rctf_size_y(&viewborder) * 0.5f;
}
@@ -337,24 +342,33 @@ static void drawWalkPixel(const struct bContext *UNUSED(C), ARegion *ar, void *a
yoff = walk->ar->winy / 2;
}
- UI_ThemeColor(TH_VIEW_OVERLAY);
- glBegin(GL_LINES);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColor(TH_VIEW_OVERLAY);
+
+ immBegin(GWN_PRIM_LINES, 8);
+
/* North */
- glVertex2i(xoff, yoff + inner_length);
- glVertex2i(xoff, yoff + outter_length);
+ immVertex2i(pos, xoff, yoff + inner_length);
+ immVertex2i(pos, xoff, yoff + outter_length);
/* East */
- glVertex2i(xoff + inner_length, yoff);
- glVertex2i(xoff + outter_length, yoff);
+ immVertex2i(pos, xoff + inner_length, yoff);
+ immVertex2i(pos, xoff + outter_length, yoff);
/* South */
- glVertex2i(xoff, yoff - inner_length);
- glVertex2i(xoff, yoff - outter_length);
+ immVertex2i(pos, xoff, yoff - inner_length);
+ immVertex2i(pos, xoff, yoff - outter_length);
/* West */
- glVertex2i(xoff - inner_length, yoff);
- glVertex2i(xoff - outter_length, yoff);
- glEnd();
+ immVertex2i(pos, xoff - inner_length, yoff);
+ immVertex2i(pos, xoff - outter_length, yoff);
+
+ immEnd();
+ immUnbindProgram();
}
static void walk_update_header(bContext *C, wmOperator *op, WalkInfo *walk)
@@ -498,6 +512,7 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
walk->rv3d = CTX_wm_region_view3d(C);
walk->v3d = CTX_wm_view3d(C);
walk->ar = CTX_wm_region(C);
+ walk->depsgraph = CTX_data_depsgraph(C);
walk->scene = CTX_data_scene(C);
#ifdef NDOF_WALK_DEBUG
@@ -587,11 +602,11 @@ static bool initWalkInfo(bContext *C, WalkInfo *walk, wmOperator *op)
walk->rv3d->rflag |= RV3D_NAVIGATING;
walk->snap_context = ED_transform_snap_object_context_create_view3d(
- CTX_data_main(C), walk->scene, 0,
+ CTX_data_main(C), walk->scene, CTX_data_depsgraph(C), 0,
walk->ar, walk->v3d);
walk->v3d_camera_control = ED_view3d_cameracontrol_acquire(
- walk->scene, walk->v3d, walk->rv3d,
+ walk->depsgraph, walk->scene, walk->v3d, walk->rv3d,
(U.uiflag & USER_CAM_LOCK_NO_PARENT) == 0);
/* center the mouse */
diff --git a/source/blender/editors/transform/CMakeLists.txt b/source/blender/editors/transform/CMakeLists.txt
index b7de49d8158..3e132192875 100644
--- a/source/blender/editors/transform/CMakeLists.txt
+++ b/source/blender/editors/transform/CMakeLists.txt
@@ -29,6 +29,7 @@ set(INC
../../ikplugin
../../makesdna
../../makesrna
+ ../../render/extern/include
../../windowmanager
../../depsgraph
../../../../intern/guardedalloc
@@ -45,7 +46,8 @@ set(SRC
transform_conversions.c
transform_generics.c
transform_input.c
- transform_manipulator.c
+ transform_manipulator_2d.c
+ transform_manipulator_3d.c
transform_ops.c
transform_orientations.c
transform_snap.c
@@ -58,10 +60,6 @@ if(WITH_INTERNATIONAL)
add_definitions(-DWITH_INTERNATIONAL)
endif()
-if(WITH_LEGACY_DEPSGRAPH)
- add_definitions(-DWITH_LEGACY_DEPSGRAPH)
-endif()
-
add_definitions(${GL_DEFINITIONS})
blender_add_lib(bf_editor_transform "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/editors/transform/transform.c b/source/blender/editors/transform/transform.c
index 4a8bd5287df..6b36e738cc0 100644
--- a/source/blender/editors/transform/transform.c
+++ b/source/blender/editors/transform/transform.c
@@ -43,6 +43,7 @@
#include "DNA_mask_types.h"
#include "DNA_movieclip_types.h"
#include "DNA_scene_types.h" /* PET modes */
+#include "DNA_workspace_types.h"
#include "BLI_alloca.h"
#include "BLI_utildefines.h"
@@ -61,12 +62,19 @@
#include "BKE_constraint.h"
#include "BKE_particle.h"
#include "BKE_unit.h"
+#include "BKE_scene.h"
#include "BKE_mask.h"
#include "BKE_report.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+
#include "ED_image.h"
#include "ED_keyframing.h"
#include "ED_screen.h"
@@ -103,7 +111,7 @@ static void drawEdgeSlide(TransInfo *t);
static void drawVertSlide(TransInfo *t);
static void postInputRotation(TransInfo *t, float values[3]);
-static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], const short around);
+static void ElementRotation(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3], const short around);
static void initSnapSpatial(TransInfo *t, float r_snap[3]);
@@ -204,7 +212,8 @@ static bool transdata_check_local_center(TransInfo *t, short around)
{
return ((around == V3D_AROUND_LOCAL_ORIGINS) && (
(t->flag & (T_OBJECT | T_POSE)) ||
- (t->obedit && ELEM(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)) ||
+ /* implicit: (t->flag & T_EDIT) */
+ (ELEM(t->obedit_type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)) ||
(t->spacetype == SPACE_IPO) ||
(t->options & (CTX_MOVIECLIP | CTX_MASK | CTX_PAINT_CURVE)))
);
@@ -213,7 +222,7 @@ static bool transdata_check_local_center(TransInfo *t, short around)
bool transdata_check_local_islands(TransInfo *t, short around)
{
return ((around == V3D_AROUND_LOCAL_ORIGINS) && (
- (t->obedit && ELEM(t->obedit->type, OB_MESH))));
+ (ELEM(t->obedit_type, OB_MESH))));
}
/* ************************** SPACE DEPENDANT CODE **************************** */
@@ -238,6 +247,7 @@ void setTransformViewMatrices(TransInfo *t)
}
calculateCenter2D(t);
+ calculateCenterLocal(t, t->center_global);
}
void setTransformViewAspect(TransInfo *t, float r_aspect[3])
@@ -612,8 +622,12 @@ static void viewRedrawForce(const bContext *C, TransInfo *t)
else {
// XXX how to deal with lock?
SpaceImage *sima = (SpaceImage *)t->sa->spacedata.first;
- if (sima->lock) WM_event_add_notifier(C, NC_GEOM | ND_DATA, t->obedit->data);
- else ED_area_tag_redraw(t->sa);
+ if (sima->lock) {
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, OBEDIT_FROM_VIEW_LAYER(t->view_layer)->data);
+ }
+ else {
+ ED_area_tag_redraw(t->sa);
+ }
}
}
else if (t->spacetype == SPACE_CLIP) {
@@ -1017,7 +1031,7 @@ int transformEvent(TransInfo *t, const wmEvent *event)
handled = true;
}
else {
- if (t->obedit && t->obedit->type == OB_MESH) {
+ if (t->obedit_type == OB_MESH) {
if ((t->mode == TFM_TRANSLATION) && (t->spacetype == SPACE_VIEW3D)) {
restoreTransObjects(t);
resetTransModal(t);
@@ -1027,11 +1041,13 @@ int transformEvent(TransInfo *t, const wmEvent *event)
initEdgeSlide(t);
/* if that fails, do vertex slide */
if (t->state == TRANS_CANCEL) {
+ resetTransModal(t);
t->state = TRANS_STARTING;
initVertSlide(t);
}
/* vert slide can fail on unconnected vertices (rare but possible) */
if (t->state == TRANS_CANCEL) {
+ resetTransModal(t);
t->mode = TFM_TRANSLATION;
t->state = TRANS_STARTING;
restoreTransObjects(t);
@@ -1563,7 +1579,7 @@ bool calculateTransformCenter(bContext *C, int centerMode, float cent3d[3], floa
t->around = centerMode; // override userdefined mode
- if (t->total == 0) {
+ if (t->data_len_all == 0) {
success = false;
}
else {
@@ -1598,8 +1614,16 @@ typedef enum {
LEFT,
RIGHT
} ArrowDirection;
+
+#define POS_INDEX 0
+/* NOTE: this --^ is a bit hackish, but simplifies Gwn_VertFormat usage among functions
+ * private to this file - merwin
+ */
+
static void drawArrow(ArrowDirection d, short offset, short length, short size)
{
+ immBegin(GWN_PRIM_LINES, 6);
+
switch (d) {
case LEFT:
offset = -offset;
@@ -1607,14 +1631,12 @@ static void drawArrow(ArrowDirection d, short offset, short length, short size)
size = -size;
ATTR_FALLTHROUGH;
case RIGHT:
- glBegin(GL_LINES);
- glVertex2s(offset, 0);
- glVertex2s(offset + length, 0);
- glVertex2s(offset + length, 0);
- glVertex2s(offset + length - size, -size);
- glVertex2s(offset + length, 0);
- glVertex2s(offset + length - size, size);
- glEnd();
+ immVertex2f(POS_INDEX, offset, 0);
+ immVertex2f(POS_INDEX, offset + length, 0);
+ immVertex2f(POS_INDEX, offset + length, 0);
+ immVertex2f(POS_INDEX, offset + length - size, -size);
+ immVertex2f(POS_INDEX, offset + length, 0);
+ immVertex2f(POS_INDEX, offset + length - size, size);
break;
case DOWN:
@@ -1623,45 +1645,45 @@ static void drawArrow(ArrowDirection d, short offset, short length, short size)
size = -size;
ATTR_FALLTHROUGH;
case UP:
- glBegin(GL_LINES);
- glVertex2s(0, offset);
- glVertex2s(0, offset + length);
- glVertex2s(0, offset + length);
- glVertex2s(-size, offset + length - size);
- glVertex2s(0, offset + length);
- glVertex2s(size, offset + length - size);
- glEnd();
+ immVertex2f(POS_INDEX, 0, offset);
+ immVertex2f(POS_INDEX, 0, offset + length);
+ immVertex2f(POS_INDEX, 0, offset + length);
+ immVertex2f(POS_INDEX, -size, offset + length - size);
+ immVertex2f(POS_INDEX, 0, offset + length);
+ immVertex2f(POS_INDEX, size, offset + length - size);
break;
}
+
+ immEnd();
}
static void drawArrowHead(ArrowDirection d, short size)
{
+ immBegin(GWN_PRIM_LINES, 4);
+
switch (d) {
case LEFT:
size = -size;
ATTR_FALLTHROUGH;
case RIGHT:
- glBegin(GL_LINES);
- glVertex2s(0, 0);
- glVertex2s(-size, -size);
- glVertex2s(0, 0);
- glVertex2s(-size, size);
- glEnd();
+ immVertex2f(POS_INDEX, 0, 0);
+ immVertex2f(POS_INDEX, -size, -size);
+ immVertex2f(POS_INDEX, 0, 0);
+ immVertex2f(POS_INDEX, -size, size);
break;
case DOWN:
size = -size;
ATTR_FALLTHROUGH;
case UP:
- glBegin(GL_LINES);
- glVertex2s(0, 0);
- glVertex2s(-size, -size);
- glVertex2s(0, 0);
- glVertex2s(size, -size);
- glEnd();
+ immVertex2f(POS_INDEX, 0, 0);
+ immVertex2f(POS_INDEX, -size, -size);
+ immVertex2f(POS_INDEX, 0, 0);
+ immVertex2f(POS_INDEX, size, -size);
break;
}
+
+ immEnd();
}
static void drawArc(float size, float angle_start, float angle_end, int segments)
@@ -1670,14 +1692,14 @@ static void drawArc(float size, float angle_start, float angle_end, int segments
float angle;
int a;
- glBegin(GL_LINE_STRIP);
+ immBegin(GWN_PRIM_LINE_STRIP, segments + 1);
for (angle = angle_start, a = 0; a < segments; angle += delta, a++) {
- glVertex2f(cosf(angle) * size, sinf(angle) * size);
+ immVertex2f(POS_INDEX, cosf(angle) * size, sinf(angle) * size);
}
- glVertex2f(cosf(angle_end) * size, sinf(angle_end) * size);
+ immVertex2f(POS_INDEX, cosf(angle_end) * size, sinf(angle_end) * size);
- glEnd();
+ immEnd();
}
static int helpline_poll(bContext *C)
@@ -1693,88 +1715,122 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
{
TransInfo *t = (TransInfo *)customdata;
- if (t->helpline != HLP_NONE && !(t->flag & T_USES_MANIPULATOR)) {
+ if (t->helpline != HLP_NONE) {
float cent[2];
- int mval[2];
-
- mval[0] = x;
- mval[1] = y;
+ float mval[3] = {
+ x,
+ y,
+ 0.0f,
+ };
+ float tmval[2] = {
+ (float)t->mval[0],
+ (float)t->mval[1],
+ };
projectFloatViewEx(t, t->center_global, cent, V3D_PROJ_TEST_CLIP_ZERO);
- glPushMatrix();
+ /* Offset the values for the area region. */
+ const float offset[2] = {
+ t->ar->winrct.xmin,
+ t->ar->winrct.ymin,
+ };
+
+ for (int i = 0; i < 2; i++) {
+ cent[i] += offset[i];
+ tmval[i] += offset[i];
+ }
+
+ gpuPushMatrix();
+
+ /* Dashed lines first. */
+ if (ELEM(t->helpline, HLP_SPRING, HLP_ANGLE)) {
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ UNUSED_VARS_NDEBUG(shdr_pos); /* silence warning */
+ BLI_assert(shdr_pos == POS_INDEX);
+
+ glLineWidth(1.0f);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformThemeColor(TH_VIEW_OVERLAY);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(POS_INDEX, cent);
+ immVertex2f(POS_INDEX, tmval[0], tmval[1]);
+ immEnd();
+
+ immUnbindProgram();
+ }
+
+ /* And now, solid lines. */
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ UNUSED_VARS_NDEBUG(pos); /* silence warning */
+ BLI_assert(pos == POS_INDEX);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
switch (t->helpline) {
case HLP_SPRING:
- UI_ThemeColor(TH_VIEW_OVERLAY);
-
- setlinestyle(3);
- glLineWidth(1);
- glBegin(GL_LINES);
- glVertex2iv(t->mval);
- glVertex2fv(cent);
- glEnd();
+ immUniformThemeColor(TH_VIEW_OVERLAY);
- glTranslate2iv(mval);
- glRotatef(-RAD2DEGF(atan2f(cent[0] - t->mval[0], cent[1] - t->mval[1])), 0, 0, 1);
+ gpuTranslate3fv(mval);
+ gpuRotateAxis(-RAD2DEGF(atan2f(cent[0] - tmval[0], cent[1] - tmval[1])), 'Z');
- setlinestyle(0);
- glLineWidth(3.0);
+ glLineWidth(3.0f);
drawArrow(UP, 5, 10, 5);
drawArrow(DOWN, 5, 10, 5);
break;
case HLP_HARROW:
- UI_ThemeColor(TH_VIEW_OVERLAY);
-
- glTranslate2iv(mval);
+ immUniformThemeColor(TH_VIEW_OVERLAY);
+ gpuTranslate3fv(mval);
- glLineWidth(3.0);
+ glLineWidth(3.0f);
drawArrow(RIGHT, 5, 10, 5);
drawArrow(LEFT, 5, 10, 5);
break;
case HLP_VARROW:
- UI_ThemeColor(TH_VIEW_OVERLAY);
+ immUniformThemeColor(TH_VIEW_OVERLAY);
- glTranslate2iv(mval);
+ gpuTranslate3fv(mval);
- glLineWidth(3.0);
+ glLineWidth(3.0f);
drawArrow(UP, 5, 10, 5);
drawArrow(DOWN, 5, 10, 5);
break;
case HLP_ANGLE:
{
- float dx = t->mval[0] - cent[0], dy = t->mval[1] - cent[1];
+ float dx = tmval[0] - cent[0], dy = tmval[1] - cent[1];
float angle = atan2f(dy, dx);
float dist = hypotf(dx, dy);
float delta_angle = min_ff(15.0f / dist, (float)M_PI / 4.0f);
float spacing_angle = min_ff(5.0f / dist, (float)M_PI / 12.0f);
- UI_ThemeColor(TH_VIEW_OVERLAY);
- setlinestyle(3);
- glLineWidth(1);
- glBegin(GL_LINES);
- glVertex2iv(t->mval);
- glVertex2fv(cent);
- glEnd();
+ immUniformThemeColor(TH_VIEW_OVERLAY);
- glTranslatef(cent[0] - t->mval[0] + mval[0], cent[1] - t->mval[1] + mval[1], 0);
+ gpuTranslate3f(cent[0] - tmval[0] + mval[0], cent[1] - tmval[1] + mval[1], 0);
- setlinestyle(0);
- glLineWidth(3.0);
+ glLineWidth(3.0f);
drawArc(dist, angle - delta_angle, angle - spacing_angle, 10);
drawArc(dist, angle + spacing_angle, angle + delta_angle, 10);
- glPushMatrix();
+ gpuPushMatrix();
- glTranslatef(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
- glRotatef(RAD2DEGF(angle - delta_angle), 0, 0, 1);
+ gpuTranslate3f(cosf(angle - delta_angle) * dist, sinf(angle - delta_angle) * dist, 0);
+ gpuRotateAxis(RAD2DEGF(angle - delta_angle), 'Z');
drawArrowHead(DOWN, 5);
- glPopMatrix();
+ gpuPopMatrix();
- glTranslatef(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
- glRotatef(RAD2DEGF(angle + delta_angle), 0, 0, 1);
+ gpuTranslate3f(cosf(angle + delta_angle) * dist, sinf(angle + delta_angle) * dist, 0);
+ gpuRotateAxis(RAD2DEGF(angle + delta_angle), 'Z');
drawArrowHead(UP, 5);
break;
@@ -1784,18 +1840,18 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
unsigned char col[3], col2[3];
UI_GetThemeColor3ubv(TH_GRID, col);
- glTranslate2iv(mval);
+ gpuTranslate3fv(mval);
- glLineWidth(3.0);
+ glLineWidth(3.0f);
UI_make_axis_color(col, col2, 'X');
- glColor3ubv((GLubyte *)col2);
+ immUniformColor3ubv((GLubyte *)col2);
drawArrow(RIGHT, 5, 10, 5);
drawArrow(LEFT, 5, 10, 5);
UI_make_axis_color(col, col2, 'Y');
- glColor3ubv((GLubyte *)col2);
+ immUniformColor3ubv((GLubyte *)col2);
drawArrow(UP, 5, 10, 5);
drawArrow(DOWN, 5, 10, 5);
@@ -1803,7 +1859,8 @@ static void drawHelpline(bContext *UNUSED(C), int x, int y, void *customdata)
}
}
- glPopMatrix();
+ immUnbindProgram();
+ gpuPopMatrix();
}
}
@@ -1811,7 +1868,7 @@ static void drawTransformView(const struct bContext *C, ARegion *UNUSED(ar), voi
{
TransInfo *t = arg;
- glLineWidth(1.0);
+ glLineWidth(1.0f);
drawConstraint(t);
drawPropCircle(C, t);
@@ -1831,8 +1888,9 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
int xco, yco;
ED_region_visible_rect(ar, &rect);
-
- BLF_width_and_height_default(printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
+
+ const int font_id = BLF_default();
+ BLF_width_and_height(font_id, printable, BLF_DRAW_STR_DUMMY_MAX, &printable_size[0], &printable_size[1]);
xco = (rect.xmax - U.widget_unit) - (int)printable_size[0];
yco = (rect.ymax - U.widget_unit);
@@ -1840,7 +1898,9 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
/* warning text (to clarify meaning of overlays)
* - original color was red to match the icon, but that clashes badly with a less nasty border
*/
- UI_ThemeColorShade(TH_TEXT_HI, -50);
+ unsigned char color[3];
+ UI_GetThemeColorShade3ubv(TH_TEXT_HI, -50, color);
+ BLF_color3ubv(font_id, color);
#ifdef WITH_INTERNATIONAL
BLF_draw_default(xco, yco, 0.0f, printable, BLF_DRAW_STR_DUMMY_MAX);
#else
@@ -1848,7 +1908,7 @@ static void drawAutoKeyWarning(TransInfo *UNUSED(t), ARegion *ar)
#endif
/* autokey recording icon... */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
xco -= U.widget_unit;
@@ -1863,7 +1923,8 @@ static void drawTransformPixel(const struct bContext *UNUSED(C), ARegion *ar, vo
{
TransInfo *t = arg;
Scene *scene = t->scene;
- Object *ob = OBACT;
+ ViewLayer *view_layer = t->view_layer;
+ Object *ob = OBACT(view_layer);
/* draw autokeyframing hint in the corner
* - only draw if enabled (advanced users may be distracted/annoyed),
@@ -1938,7 +1999,7 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
ts->proportional_fcurve = proportional;
else if (t->spacetype == SPACE_ACTION)
ts->proportional_action = proportional;
- else if (t->obedit)
+ else if (t->obedit_type != -1)
ts->proportional = proportional;
else if (t->options & CTX_MASK)
ts->proportional_mask = (proportional != PROP_EDIT_OFF);
@@ -1970,9 +2031,10 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
if ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
!RNA_property_is_set(op->ptr, prop))
{
- View3D *v3d = t->view;
-
- v3d->twmode = t->current_orientation;
+ t->scene->orientation_type = t->current_orientation;
+ BLI_assert(((t->scene->orientation_index_custom == -1) && (t->custom_orientation == NULL)) ||
+ (BKE_scene_transform_orientation_get_index(
+ t->scene, t->custom_orientation) == t->scene->orientation_index_custom));
}
}
}
@@ -1992,15 +2054,19 @@ void saveTransform(bContext *C, TransInfo *t, wmOperator *op)
}
if ((prop = RNA_struct_find_property(op->ptr, "constraint_axis"))) {
- /* constraint orientation can be global, event if user selects something else
- * so use the orientation in the constraint if set
- * */
- if (t->con.mode & CON_APPLY) {
- RNA_enum_set(op->ptr, "constraint_orientation", t->con.orientation);
- }
- else {
- RNA_enum_set(op->ptr, "constraint_orientation", t->current_orientation);
+ /* constraint orientation can be global, even if user selects something else
+ * so use the orientation in the constraint if set */
+ short orientation = (t->con.mode & CON_APPLY) ? t->con.orientation : t->current_orientation;
+
+ if (orientation == V3D_MANIP_CUSTOM) {
+ const int orientation_index_custom = BKE_scene_transform_orientation_get_index(
+ t->scene, t->custom_orientation);
+
+ /* Maybe we need a t->con.custom_orientation? Seems like it would always match t->custom_orientation. */
+ orientation = V3D_MANIP_CUSTOM + orientation_index_custom;
+ BLI_assert(orientation >= V3D_MANIP_CUSTOM);
}
+ RNA_enum_set(op->ptr, "constraint_orientation", orientation);
if (t->con.mode & CON_APPLY) {
if (t->con.mode & CON_AXIS0) {
@@ -2119,7 +2185,7 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
createTransData(C, t); // make TransData structs from selection
- if (t->total == 0) {
+ if (t->data_len_all == 0) {
postTrans(C, t);
return 0;
}
@@ -2164,6 +2230,33 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
calculatePropRatio(t);
calculateCenter(t);
+ /* Overwrite initial values if operator supplied a non-null vector.
+ *
+ * Run before init functions so 'values_modal_offset' can be applied on mouse input.
+ */
+ BLI_assert(is_zero_v4(t->values_modal_offset));
+ if ((prop = RNA_struct_find_property(op->ptr, "value")) && RNA_property_is_set(op->ptr, prop)) {
+ float values[4] = {0}; /* in case value isn't length 4, avoid uninitialized memory */
+
+ if (RNA_property_array_check(prop)) {
+ RNA_float_get_array(op->ptr, "value", values);
+ }
+ else {
+ values[0] = RNA_float_get(op->ptr, "value");
+ }
+
+ copy_v4_v4(t->values, values);
+
+ if (t->flag & T_MODAL) {
+ copy_v4_v4(t->values_modal_offset, values);
+ t->redraw = TREDRAW_HARD;
+ }
+ else {
+ copy_v4_v4(t->auto_values, values);
+ t->flag |= T_AUTOVALUES;
+ }
+ }
+
if (event) {
/* Initialize accurate transform to settings requested by keymap. */
bool use_accurate = false;
@@ -2223,7 +2316,9 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
break;
case TFM_BONESIZE:
{ /* used for both B-Bone width (bonesize) as for deform-dist (envelope) */
- bArmature *arm = t->poseobj->data;
+ /* Note: we have to pick one, use the active object. */
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_OK(t);
+ bArmature *arm = tc->poseobj->data;
if (arm->drawtype == ARM_ENVELOPE) {
initBoneEnvelope(t);
t->mode = TFM_BONE_ENVELOPE_DIST;
@@ -2340,25 +2435,6 @@ bool initTransform(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
- /* overwrite initial values if operator supplied a non-null vector
- *
- * keep last so we can apply the constraints space.
- */
- if ((prop = RNA_struct_find_property(op->ptr, "value")) && RNA_property_is_set(op->ptr, prop)) {
- float values[4] = {0}; /* in case value isn't length 4, avoid uninitialized memory */
-
- if (RNA_property_array_check(prop)) {
- RNA_float_get_array(op->ptr, "value", values);
- }
- else {
- values[0] = RNA_float_get(op->ptr, "value");
- }
-
- copy_v4_v4(t->values, values);
- copy_v4_v4(t->auto_values, values);
- t->flag |= T_AUTOVALUES;
- }
-
t->context = NULL;
return 1;
@@ -2621,7 +2697,7 @@ static void constraintTransLim(TransInfo *t, TransData *td)
}
/* get constraint targets if needed */
- BKE_constraint_targets_for_solving_get(con, &cob, &targets, ctime);
+ BKE_constraint_targets_for_solving_get(t->depsgraph, con, &cob, &targets, ctime);
/* do constraint */
cti->evaluate_constraint(con, &cob, &targets);
@@ -2828,6 +2904,7 @@ static void constraintSizeLim(TransInfo *t, TransData *td)
* \{ */
struct BendCustomData {
+ /* All values are in global space. */
float warp_sta[3];
float warp_end[3];
@@ -2868,9 +2945,9 @@ static void initBend(TransInfo *t)
//copy_v3_v3(t->center, ED_view3d_cursor3d_get(t->scene, t->view));
if ((t->flag & T_OVERRIDE_CENTER) == 0) {
- calculateCenterCursor(t, t->center);
+ calculateCenterCursor(t, t->center_global);
}
- calculateCenterGlobal(t, t->center, t->center_global);
+ calculateCenterLocal(t, t->center_global);
t->val = 0.0f;
@@ -2881,10 +2958,6 @@ static void initBend(TransInfo *t)
ED_view3d_win_to_3d(t->sa->spacedata.first, t->ar, curs, mval_fl, data->warp_end);
copy_v3_v3(data->warp_nor, t->viewinv[2]);
- if (t->flag & T_EDIT) {
- sub_v3_v3(data->warp_sta, t->obedit->obmat[3]);
- sub_v3_v3(data->warp_end, t->obedit->obmat[3]);
- }
normalize_v3(data->warp_nor);
/* tangent */
@@ -2911,10 +2984,9 @@ static eRedrawFlag handleEventBend(TransInfo *UNUSED(t), const wmEvent *event)
static void Bend(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float vec[3];
- float pivot[3];
- float warp_end_radius[3];
+ float pivot_global[3];
+ float warp_end_radius_global[3];
int i;
char str[UI_MAX_DRAW_STR];
const struct BendCustomData *data = t->custom.mode.data;
@@ -2969,66 +3041,89 @@ static void Bend(TransInfo *t, const int UNUSED(mval[2]))
values.scale *= data->warp_init_dist;
/* calc 'data->warp_end' from 'data->warp_end_init' */
- copy_v3_v3(warp_end_radius, data->warp_end);
- dist_ensure_v3_v3fl(warp_end_radius, data->warp_sta, values.scale);
+ copy_v3_v3(warp_end_radius_global, data->warp_end);
+ dist_ensure_v3_v3fl(warp_end_radius_global, data->warp_sta, values.scale);
/* done */
/* calculate pivot */
- copy_v3_v3(pivot, data->warp_sta);
+ copy_v3_v3(pivot_global, data->warp_sta);
if (values.angle > 0.0f) {
- madd_v3_v3fl(pivot, data->warp_tan, -values.scale * shell_angle_to_dist((float)M_PI_2 - values.angle));
+ madd_v3_v3fl(pivot_global, data->warp_tan, -values.scale * shell_angle_to_dist((float)M_PI_2 - values.angle));
}
else {
- madd_v3_v3fl(pivot, data->warp_tan, +values.scale * shell_angle_to_dist((float)M_PI_2 + values.angle));
+ madd_v3_v3fl(pivot_global, data->warp_tan, +values.scale * shell_angle_to_dist((float)M_PI_2 + values.angle));
}
- for (i = 0; i < t->total; i++, td++) {
- float mat[3][3];
- float delta[3];
- float fac, fac_scaled;
+ /* TODO(campbell): xform, compensate object center. */
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
+ float warp_sta_local[3];
+ float warp_end_local[3];
+ float warp_end_radius_local[3];
+ float pivot_local[3];
- if (UNLIKELY(values.angle == 0.0f)) {
- copy_v3_v3(td->loc, td->iloc);
- continue;
+ if (tc->use_local_mat) {
+ sub_v3_v3v3(warp_sta_local, data->warp_sta, tc->mat[3]);
+ sub_v3_v3v3(warp_end_local, data->warp_end, tc->mat[3]);
+ sub_v3_v3v3(warp_end_radius_local, warp_end_radius_global, tc->mat[3]);
+ sub_v3_v3v3(pivot_local, pivot_global, tc->mat[3]);
+ }
+ else {
+ copy_v3_v3(warp_sta_local, data->warp_sta);
+ copy_v3_v3(warp_end_local, data->warp_end);
+ copy_v3_v3(warp_end_radius_local, warp_end_radius_global);
+ copy_v3_v3(pivot_local, pivot_global);
}
- copy_v3_v3(vec, td->iloc);
- mul_m3_v3(td->mtx, vec);
+ for (i = 0; i < tc->data_len; i++, td++) {
+ float mat[3][3];
+ float delta[3];
+ float fac, fac_scaled;
- fac = line_point_factor_v3(vec, data->warp_sta, warp_end_radius);
- if (is_clamp) {
- CLAMP(fac, 0.0f, 1.0f);
- }
+ if (td->flag & TD_NOACTION)
+ break;
- fac_scaled = fac * td->factor;
- axis_angle_normalized_to_mat3(mat, data->warp_nor, values.angle * fac_scaled);
- interp_v3_v3v3(delta, data->warp_sta, warp_end_radius, fac_scaled);
- sub_v3_v3(delta, data->warp_sta);
+ if (td->flag & TD_SKIP)
+ continue;
- /* delta is subtracted, rotation adds back this offset */
- sub_v3_v3(vec, delta);
+ if (UNLIKELY(values.angle == 0.0f)) {
+ copy_v3_v3(td->loc, td->iloc);
+ continue;
+ }
- sub_v3_v3(vec, pivot);
- mul_m3_v3(mat, vec);
- add_v3_v3(vec, pivot);
+ copy_v3_v3(vec, td->iloc);
+ mul_m3_v3(td->mtx, vec);
- mul_m3_v3(td->smtx, vec);
+ fac = line_point_factor_v3(vec, warp_sta_local, warp_end_radius_local);
+ if (is_clamp) {
+ CLAMP(fac, 0.0f, 1.0f);
+ }
- /* rotation */
- if ((t->flag & T_POINTS) == 0) {
- ElementRotation(t, td, mat, V3D_AROUND_LOCAL_ORIGINS);
- }
+ fac_scaled = fac * td->factor;
+ axis_angle_normalized_to_mat3(mat, data->warp_nor, values.angle * fac_scaled);
+ interp_v3_v3v3(delta, warp_sta_local, warp_end_radius_local, fac_scaled);
+ sub_v3_v3(delta, warp_sta_local);
+
+ /* delta is subtracted, rotation adds back this offset */
+ sub_v3_v3(vec, delta);
- /* location */
- copy_v3_v3(td->loc, vec);
+ sub_v3_v3(vec, pivot_local);
+ mul_m3_v3(mat, vec);
+ add_v3_v3(vec, pivot_local);
+
+ mul_m3_v3(td->smtx, vec);
+
+ /* rotation */
+ if ((t->flag & T_POINTS) == 0) {
+ ElementRotation(t, tc, td, mat, V3D_AROUND_LOCAL_ORIGINS);
+ }
+
+ /* location */
+ copy_v3_v3(td->loc, vec);
+ }
}
-
+
recalcData(t);
ED_area_headerprint(t->sa, str);
@@ -3099,7 +3194,6 @@ static eRedrawFlag handleEventShear(TransInfo *t, const wmEvent *event)
static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float vec[3];
float smat[3][3], tmat[3][3], totmat[3][3], persmat[3][3], persinv[3][3];
float value;
@@ -3142,45 +3236,48 @@ static void applyShear(TransInfo *t, const int UNUSED(mval[2]))
mul_m3_m3m3(tmat, smat, persmat);
mul_m3_m3m3(totmat, persinv, tmat);
- for (i = 0; i < t->total; i++, td++) {
- const float *center, *co;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ const float *center, *co;
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- if (t->obedit) {
- float mat3[3][3];
- mul_m3_m3m3(mat3, totmat, td->mtx);
- mul_m3_m3m3(tmat, td->smtx, mat3);
- }
- else {
- copy_m3_m3(tmat, totmat);
- }
+ if (td->flag & TD_NOACTION)
+ break;
- if (is_local_center) {
- center = td->center;
- co = td->loc;
- }
- else {
- center = t->center;
- co = td->center;
- }
+ if (td->flag & TD_SKIP)
+ continue;
- sub_v3_v3v3(vec, co, center);
-
- mul_m3_v3(tmat, vec);
-
- add_v3_v3(vec, center);
- sub_v3_v3(vec, co);
-
- mul_v3_fl(vec, td->factor);
-
- add_v3_v3v3(td->loc, td->iloc, vec);
+ if (t->flag & T_EDIT) {
+ float mat3[3][3];
+ mul_m3_m3m3(mat3, totmat, td->mtx);
+ mul_m3_m3m3(tmat, td->smtx, mat3);
+ }
+ else {
+ copy_m3_m3(tmat, totmat);
+ }
+
+ if (is_local_center) {
+ center = td->center;
+ co = td->loc;
+ }
+ else {
+ center = tc->center_local;
+ co = td->center;
+ }
+
+ sub_v3_v3v3(vec, co, center);
+
+ mul_m3_v3(tmat, vec);
+
+ add_v3_v3(vec, center);
+ sub_v3_v3(vec, co);
+
+ mul_v3_fl(vec, td->factor);
+
+ add_v3_v3v3(td->loc, td->iloc, vec);
+ }
}
-
+
recalcData(t);
ED_area_headerprint(t->sa, str);
@@ -3206,7 +3303,7 @@ static void initResize(TransInfo *t)
t->num.val_flag[1] |= NUM_NULL_ONE;
t->num.val_flag[2] |= NUM_NULL_ONE;
t->num.flag |= NUM_AFFECT_ALL;
- if (!t->obedit) {
+ if ((t->flag & T_EDIT) == 0) {
t->flag |= T_NO_ZERO;
#ifdef USE_NUM_NO_ZERO
t->num.val_flag[0] |= NUM_NO_ZERO;
@@ -3290,7 +3387,7 @@ static void TransMat3ToSize(float mat[3][3], float smat[3][3], float size[3])
if (dot_v3v3(rmat[2], smat[2]) < 0.0f) size[2] = -size[2];
}
-static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
+static void ElementResize(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3])
{
float tmat[3][3], smat[3][3], center[3];
float vec[3];
@@ -3304,7 +3401,7 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
}
if (t->con.applySize) {
- t->con.applySize(t, td, tmat);
+ t->con.applySize(t, tc, td, tmat);
}
/* local constraint shouldn't alter center */
@@ -3316,11 +3413,11 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
copy_v3_v3(center, td->center);
}
else {
- copy_v3_v3(center, t->center);
+ copy_v3_v3(center, tc->center_local);
}
}
else {
- copy_v3_v3(center, t->center);
+ copy_v3_v3(center, tc->center_local);
}
if (td->ext) {
@@ -3391,9 +3488,8 @@ static void ElementResize(TransInfo *t, TransData *td, float mat[3][3])
constraintTransLim(t, td);
}
-static void applyResize(TransInfo *t, const int mval[2])
+static void applyResize(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td;
float mat[3][3];
int i;
char str[UI_MAX_DRAW_STR];
@@ -3402,15 +3498,7 @@ static void applyResize(TransInfo *t, const int mval[2])
copy_v3_v3(t->values, t->auto_values);
}
else {
- float ratio;
-
- /* for manipulator, center handle, the scaling can't be done relative to center */
- if ((t->flag & T_USES_MANIPULATOR) && t->con.mode == 0) {
- ratio = 1.0f - ((t->mouse.imval[0] - mval[0]) + (t->mouse.imval[1] - mval[1])) / 100.0f;
- }
- else {
- ratio = t->values[0];
- }
+ float ratio = t->values[0];
copy_v3_fl(t->values, ratio);
@@ -3426,39 +3514,46 @@ static void applyResize(TransInfo *t, const int mval[2])
size_to_mat3(mat, t->values);
if (t->con.applySize) {
- t->con.applySize(t, NULL, mat);
+ t->con.applySize(t, NULL, NULL, mat);
}
copy_m3_m3(t->mat, mat); // used in manipulator
headerResize(t, t->values, str);
-
- for (i = 0, td = t->data; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- ElementResize(t, td, mat);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ ElementResize(t, tc, td, mat);
+ }
}
-
+
/* evil hack - redo resize if cliping needed */
if (t->flag & T_CLIP_UV && clipUVTransform(t, t->values, 1)) {
size_to_mat3(mat, t->values);
-
+
if (t->con.applySize)
- t->con.applySize(t, NULL, mat);
-
- for (i = 0, td = t->data; i < t->total; i++, td++)
- ElementResize(t, td, mat);
+ t->con.applySize(t, NULL, NULL, mat);
- /* In proportional edit it can happen that */
- /* vertices in the radius of the brush end */
- /* outside the clipping area */
- /* XXX HACK - dg */
- if (t->flag & T_PROP_EDIT_ALL) {
- clipUVData(t);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++)
+ ElementResize(t, tc, td, mat);
+
+ /* In proportional edit it can happen that */
+ /* vertices in the radius of the brush end */
+ /* outside the clipping area */
+ /* XXX HACK - dg */
+ if (t->flag & T_PROP_EDIT_ALL) {
+ clipUVData(t);
+ }
}
}
@@ -3487,7 +3582,7 @@ static void initSkinResize(TransInfo *t)
t->num.val_flag[1] |= NUM_NULL_ONE;
t->num.val_flag[2] |= NUM_NULL_ONE;
t->num.flag |= NUM_AFFECT_ALL;
- if (!t->obedit) {
+ if ((t->flag & T_EDIT) == 0) {
t->flag |= T_NO_ZERO;
#ifdef USE_NUM_NO_ZERO
t->num.val_flag[0] |= NUM_NO_ZERO;
@@ -3511,7 +3606,6 @@ static void initSkinResize(TransInfo *t)
static void applySkinResize(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td;
float size[3], mat[3][3];
int i;
char str[UI_MAX_DRAW_STR];
@@ -3535,34 +3629,37 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2]))
size_to_mat3(mat, size);
headerResize(t, size, str);
-
- for (i = 0, td = t->data; i < t->total; i++, td++) {
- float tmat[3][3], smat[3][3];
- float fsize[3];
-
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
- if (t->flag & T_EDIT) {
- mul_m3_m3m3(smat, mat, td->mtx);
- mul_m3_m3m3(tmat, td->smtx, smat);
- }
- else {
- copy_m3_m3(tmat, mat);
- }
-
- if (t->con.applySize) {
- t->con.applySize(t, NULL, tmat);
- }
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ float tmat[3][3], smat[3][3];
+ float fsize[3];
- mat3_to_size(fsize, tmat);
- td->val[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
- td->val[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ if (t->flag & T_EDIT) {
+ mul_m3_m3m3(smat, mat, td->mtx);
+ mul_m3_m3m3(tmat, td->smtx, smat);
+ }
+ else {
+ copy_m3_m3(tmat, mat);
+ }
+
+ if (t->con.applySize) {
+ t->con.applySize(t, NULL, NULL, tmat);
+ }
+
+ mat3_to_size(fsize, tmat);
+ td->val[0] = td->ext->isize[0] * (1 + (fsize[0] - 1) * td->factor);
+ td->val[1] = td->ext->isize[1] * (1 + (fsize[1] - 1) * td->factor);
+ }
}
-
+
recalcData(t);
ED_area_headerprint(t->sa, str);
@@ -3578,7 +3675,6 @@ static void applySkinResize(TransInfo *t, const int UNUSED(mval[2]))
static void initToSphere(TransInfo *t)
{
- TransData *td = t->data;
int i;
t->mode = TFM_TOSPHERE;
@@ -3598,13 +3694,16 @@ static void initToSphere(TransInfo *t)
t->num.val_flag[0] |= NUM_NULL_ONE | NUM_NO_NEGATIVE;
t->flag |= T_NO_CONSTRAINT;
-
+
// Calculate average radius
- for (i = 0; i < t->total; i++, td++) {
- t->val += len_v3v3(t->center, td->iloc);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ t->val += len_v3v3(tc->center_local, td->iloc);
+ }
}
-
- t->val /= (float)t->total;
+
+ t->val /= (float)t->data_len_all;
}
static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
@@ -3613,8 +3712,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
float ratio, radius;
int i;
char str[UI_MAX_DRAW_STR];
- TransData *td = t->data;
-
+
ratio = t->values[0];
snapGridIncrement(t, &ratio);
@@ -3637,28 +3735,29 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
/* default header print */
BLI_snprintf(str, sizeof(str), IFACE_("To Sphere: %.4f %s"), ratio, t->proptext);
}
-
-
- for (i = 0; i < t->total; i++, td++) {
- float tratio;
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- sub_v3_v3v3(vec, td->iloc, t->center);
-
- radius = normalize_v3(vec);
-
- tratio = ratio * td->factor;
-
- mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
-
- add_v3_v3v3(td->loc, t->center, vec);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ float tratio;
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ sub_v3_v3v3(vec, td->iloc, tc->center_local);
+
+ radius = normalize_v3(vec);
+
+ tratio = ratio * td->factor;
+
+ mul_v3_fl(vec, radius * (1.0f - tratio) + t->val * tratio);
+
+ add_v3_v3v3(td->loc, tc->center_local, vec);
+ }
}
-
-
+
recalcData(t);
ED_area_headerprint(t->sa, str);
@@ -3675,7 +3774,7 @@ static void applyToSphere(TransInfo *t, const int UNUSED(mval[2]))
static void postInputRotation(TransInfo *t, float values[3])
{
if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
- t->con.applyRot(t, NULL, t->axis, values);
+ t->con.applyRot(t, NULL, NULL, t->axis, values);
}
}
@@ -3720,7 +3819,7 @@ static void initRotation(TransInfo *t)
*
* Protected axis and other transform settings are taken into account.
*/
-static void ElementRotation_ex(TransInfo *t, TransData *td, float mat[3][3], const float *center)
+static void ElementRotation_ex(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3], const float *center)
{
float vec[3], totmat[3][3], smat[3][3];
float eul[3], fmat[3][3], quat[4];
@@ -3764,18 +3863,14 @@ static void ElementRotation_ex(TransInfo *t, TransData *td, float mat[3][3], con
* has been computed, it has to be converted back into the bone's space.
*/
else if (t->flag & T_POSE) {
- float pmtx[3][3], imtx[3][3];
-
// Extract and invert armature object matrix
- copy_m3_m4(pmtx, t->poseobj->obmat);
- invert_m3_m3(imtx, pmtx);
-
+
if ((td->flag & TD_NO_LOC) == 0) {
sub_v3_v3v3(vec, td->center, center);
- mul_m3_v3(pmtx, vec); // To Global space
+ mul_m3_v3(tc->mat3, vec); // To Global space
mul_m3_v3(mat, vec); // Applying rotation
- mul_m3_v3(imtx, vec); // To Local space
+ mul_m3_v3(tc->imat3, vec); // To Local space
add_v3_v3(vec, center);
/* vec now is the location where the object has to be */
@@ -3787,11 +3882,11 @@ static void ElementRotation_ex(TransInfo *t, TransData *td, float mat[3][3], con
/* do nothing */
}
else if (td->flag & TD_PBONE_LOCAL_MTX_C) {
- mul_m3_v3(pmtx, vec); // To Global space
+ mul_m3_v3(tc->mat3, vec); // To Global space
mul_m3_v3(td->ext->l_smtx, vec); // To Pose space (Local Location)
}
else {
- mul_m3_v3(pmtx, vec); // To Global space
+ mul_m3_v3(tc->mat3, vec); // To Global space
mul_m3_v3(td->smtx, vec); // To Pose space
}
@@ -3933,7 +4028,7 @@ static void ElementRotation_ex(TransInfo *t, TransData *td, float mat[3][3], con
}
}
-static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], const short around)
+static void ElementRotation(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3], const short around)
{
const float *center;
@@ -3942,37 +4037,39 @@ static void ElementRotation(TransInfo *t, TransData *td, float mat[3][3], const
center = td->center;
}
else {
- center = t->center;
+ center = tc->center_local;
}
- ElementRotation_ex(t, td, mat, center);
+ ElementRotation_ex(t, tc, td, mat, center);
}
static void applyRotationValue(TransInfo *t, float angle, float axis[3])
{
- TransData *td = t->data;
float mat[3][3];
int i;
axis_angle_normalized_to_mat3(mat, axis, angle);
-
- for (i = 0; i < t->total; i++, td++) {
-
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- if (t->con.applyRot) {
- t->con.applyRot(t, td, axis, NULL);
- axis_angle_normalized_to_mat3(mat, axis, angle * td->factor);
- }
- else if (t->flag & T_PROP_EDIT) {
- axis_angle_normalized_to_mat3(mat, axis, angle * td->factor);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ if (t->con.applyRot) {
+ t->con.applyRot(t, tc, td, axis, NULL);
+ axis_angle_normalized_to_mat3(mat, axis, angle * td->factor);
+ }
+ else if (t->flag & T_PROP_EDIT) {
+ axis_angle_normalized_to_mat3(mat, axis, angle * td->factor);
+ }
+
+ ElementRotation(t, tc, td, mat, t->around);
}
-
- ElementRotation(t, td, mat, t->around);
}
}
@@ -3988,7 +4085,7 @@ static void applyRotation(TransInfo *t, const int UNUSED(mval[2]))
snapGridIncrement(t, &final);
if ((t->con.mode & CON_APPLY) && t->con.applyRot) {
- t->con.applyRot(t, NULL, t->axis, NULL);
+ t->con.applyRot(t, NULL, NULL, t->axis, NULL);
}
else {
/* reset axis if constraint is not set */
@@ -4057,7 +4154,6 @@ static void initTrackball(TransInfo *t)
static void applyTrackballValue(TransInfo *t, const float axis1[3], const float axis2[3], float angles[2])
{
- TransData *td = t->data;
float mat[3][3];
float axis[3];
float angle;
@@ -4068,18 +4164,21 @@ static void applyTrackballValue(TransInfo *t, const float axis1[3], const float
angle = normalize_v3(axis);
axis_angle_normalized_to_mat3(mat, axis, angle);
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (t->flag & T_PROP_EDIT) {
- axis_angle_normalized_to_mat3(mat, axis, td->factor * angle);
- }
+ if (t->flag & T_PROP_EDIT) {
+ axis_angle_normalized_to_mat3(mat, axis, td->factor * angle);
+ }
- ElementRotation(t, td, mat, t->around);
+ ElementRotation(t, tc, td, mat, t->around);
+ }
}
}
@@ -4334,81 +4433,83 @@ static void headerTranslation(TransInfo *t, const float vec[3], char str[UI_MAX_
static void applyTranslationValue(TransInfo *t, const float vec[3])
{
- TransData *td = t->data;
+ const bool apply_snap_align_rotation = usingSnappingNormal(t);// && (t->tsnap.status & POINT_INIT);
float tvec[3];
/* The ideal would be "apply_snap_align_rotation" only when a snap point is found
* so, maybe inside this function is not the best place to apply this rotation.
* but you need "handle snapping rotation before doing the translation" (really?) */
- const bool apply_snap_align_rotation = usingSnappingNormal(t);// && (t->tsnap.status & POINT_INIT);
- float pivot[3];
- if (apply_snap_align_rotation) {
- copy_v3_v3(pivot, t->tsnap.snapTarget);
- /* The pivot has to be in local-space (see T49494) */
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_m4_v3(ob->imat, pivot);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+
+ float pivot[3];
+ if (apply_snap_align_rotation) {
+ copy_v3_v3(pivot, t->tsnap.snapTarget);
+ /* The pivot has to be in local-space (see T49494) */
+ if (tc->use_local_mat) {
+ mul_m4_v3(tc->imat, pivot);
+ }
}
- }
- for (int i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
+ TransData *td = tc->data;
+ for (int i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- float rotate_offset[3] = {0};
- bool use_rotate_offset = false;
+ if (td->flag & TD_SKIP)
+ continue;
- /* handle snapping rotation before doing the translation */
- if (apply_snap_align_rotation) {
- float mat[3][3];
+ float rotate_offset[3] = {0};
+ bool use_rotate_offset = false;
- if (validSnappingNormal(t)) {
- const float *original_normal;
+ /* handle snapping rotation before doing the translation */
+ if (apply_snap_align_rotation) {
+ float mat[3][3];
- /* In pose mode, we want to align normals with Y axis of bones... */
- if (t->flag & T_POSE)
- original_normal = td->axismtx[1];
- else
- original_normal = td->axismtx[2];
+ if (validSnappingNormal(t)) {
+ const float *original_normal;
+
+ /* In pose mode, we want to align normals with Y axis of bones... */
+ if (t->flag & T_POSE)
+ original_normal = td->axismtx[1];
+ else
+ original_normal = td->axismtx[2];
+
+ rotation_between_vecs_to_mat3(mat, original_normal, t->tsnap.snapNormal);
+ }
+ else {
+ unit_m3(mat);
+ }
- rotation_between_vecs_to_mat3(mat, original_normal, t->tsnap.snapNormal);
+ ElementRotation_ex(t, tc, td, mat, pivot);
+
+ if (td->loc) {
+ use_rotate_offset = true;
+ sub_v3_v3v3(rotate_offset, td->loc, td->iloc);
+ }
+ }
+
+ if (t->con.applyVec) {
+ float pvec[3];
+ t->con.applyVec(t, tc, td, vec, tvec, pvec);
}
else {
- unit_m3(mat);
+ copy_v3_v3(tvec, vec);
}
- ElementRotation_ex(t, td, mat, pivot);
-
- if (td->loc) {
- use_rotate_offset = true;
- sub_v3_v3v3(rotate_offset, td->loc, td->iloc);
+ if (use_rotate_offset) {
+ add_v3_v3(tvec, rotate_offset);
}
- }
- if (t->con.applyVec) {
- float pvec[3];
- t->con.applyVec(t, td, vec, tvec, pvec);
- }
- else {
- copy_v3_v3(tvec, vec);
- }
+ mul_m3_v3(td->smtx, tvec);
+ mul_v3_fl(tvec, td->factor);
- if (use_rotate_offset) {
- add_v3_v3(tvec, rotate_offset);
- }
-
- mul_m3_v3(td->smtx, tvec);
- mul_v3_fl(tvec, td->factor);
-
- protectedTransBits(td->protectflag, tvec);
-
- if (td->loc)
- add_v3_v3v3(td->loc, td->iloc, tvec);
+ protectedTransBits(td->protectflag, tvec);
- constraintTransLim(t, td);
+ if (td->loc)
+ add_v3_v3v3(td->loc, td->iloc, tvec);
+
+ constraintTransLim(t, td);
+ }
}
}
@@ -4434,7 +4535,7 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2]))
if (t->con.mode & CON_APPLY) {
float pvec[3] = {0.0f, 0.0f, 0.0f};
- t->con.applyVec(t, NULL, t->values, value_final, pvec);
+ t->con.applyVec(t, NULL, NULL, t->values, value_final, pvec);
headerTranslation(t, pvec, str);
/* only so we have re-usable value with redo, see T46741. */
@@ -4478,7 +4579,7 @@ static void applyTranslation(TransInfo *t, const int UNUSED(mval[2]))
static void initShrinkFatten(TransInfo *t)
{
// If not in mesh edit mode, fallback to Resize
- if (t->obedit == NULL || t->obedit->type != OB_MESH) {
+ if ((t->flag & T_EDIT) == 0 || (t->obedit_type != OB_MESH)) {
initResize(t);
}
else {
@@ -4508,7 +4609,6 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
int i;
char str[UI_MAX_DRAW_STR];
size_t ofs = 0;
- TransData *td = t->data;
distance = -t->values[0];
@@ -4545,21 +4645,24 @@ static void applyShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
WM_bool_as_string((t->flag & T_ALT_TRANSFORM) != 0));
/* done with header string */
- for (i = 0; i < t->total; i++, td++) {
- float tdistance; /* temp dist */
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ float tdistance; /* temp dist */
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- /* get the final offset */
- tdistance = distance * td->factor;
- if (td->ext && (t->flag & T_ALT_TRANSFORM)) {
- tdistance *= td->ext->isize[0]; /* shell factor */
- }
+ /* get the final offset */
+ tdistance = distance * td->factor;
+ if (td->ext && (t->flag & T_ALT_TRANSFORM)) {
+ tdistance *= td->ext->isize[0]; /* shell factor */
+ }
- madd_v3_v3v3fl(td->loc, td->iloc, td->axismtx[2], tdistance);
+ madd_v3_v3v3fl(td->loc, td->iloc, td->axismtx[2], tdistance);
+ }
}
recalcData(t);
@@ -4599,7 +4702,6 @@ static void initTilt(TransInfo *t)
static void applyTilt(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
int i;
char str[UI_MAX_DRAW_STR];
@@ -4627,15 +4729,18 @@ static void applyTilt(TransInfo *t, const int UNUSED(mval[2]))
BLI_snprintf(str, sizeof(str), IFACE_("Tilt: %.2f° %s"), RAD2DEGF(final), t->proptext);
}
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (td->val) {
- *td->val = td->ival + final * td->factor;
+ if (td->val) {
+ *td->val = td->ival + final * td->factor;
+ }
}
}
@@ -4679,7 +4784,6 @@ static void initCurveShrinkFatten(TransInfo *t)
static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float ratio;
int i;
char str[UI_MAX_DRAW_STR];
@@ -4703,18 +4807,21 @@ static void applyCurveShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio);
}
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (td->val) {
- *td->val = td->ival * ratio;
- /* apply PET */
- *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
- if (*td->val <= 0.0f) *td->val = 0.001f;
+ if (td->val) {
+ *td->val = td->ival * ratio;
+ /* apply PET */
+ *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
+ if (*td->val <= 0.0f) *td->val = 0.001f;
+ }
}
}
@@ -4758,7 +4865,6 @@ static void initMaskShrinkFatten(TransInfo *t)
static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td;
float ratio;
int i;
bool initial_feather = false;
@@ -4787,35 +4893,41 @@ static void applyMaskShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
if (ratio > 1.0f) {
initial_feather = true;
- for (td = t->data, i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (td->ival >= 0.001f)
- initial_feather = false;
+ if (td->ival >= 0.001f)
+ initial_feather = false;
+ }
}
}
/* apply shrink/fatten */
- for (td = t->data, i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (td = tc->data, i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (td->val) {
- if (initial_feather)
- *td->val = td->ival + (ratio - 1.0f) * 0.01f;
- else
- *td->val = td->ival * ratio;
+ if (td->val) {
+ if (initial_feather)
+ *td->val = td->ival + (ratio - 1.0f) * 0.01f;
+ else
+ *td->val = td->ival * ratio;
- /* apply PET */
- *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
- if (*td->val <= 0.0f) *td->val = 0.001f;
+ /* apply PET */
+ *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
+ if (*td->val <= 0.0f) *td->val = 0.001f;
+ }
}
}
@@ -4859,7 +4971,6 @@ static void initGPShrinkFatten(TransInfo *t)
static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float ratio;
int i;
char str[UI_MAX_DRAW_STR];
@@ -4883,18 +4994,21 @@ static void applyGPShrinkFatten(TransInfo *t, const int UNUSED(mval[2]))
BLI_snprintf(str, sizeof(str), IFACE_("Shrink/Fatten: %3f"), ratio);
}
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (td->val) {
- *td->val = td->ival * ratio;
- /* apply PET */
- *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
- if (*td->val <= 0.0f) *td->val = 0.001f;
+ if (td->val) {
+ *td->val = td->ival * ratio;
+ /* apply PET */
+ *td->val = (*td->val * td->factor) + ((1.0f - td->factor) * td->ival);
+ if (*td->val <= 0.0f) *td->val = 0.001f;
+ }
}
}
@@ -4936,7 +5050,6 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
float distance;
int i;
char str[UI_MAX_DRAW_STR];
- TransData *td = t->data;
distance = t->values[0];
@@ -4960,35 +5073,38 @@ static void applyPushPull(TransInfo *t, const int UNUSED(mval[2]))
}
if (t->con.applyRot && t->con.mode & CON_APPLY) {
- t->con.applyRot(t, NULL, axis_global, NULL);
+ t->con.applyRot(t, NULL, NULL, axis_global, NULL);
}
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- sub_v3_v3v3(vec, t->center, td->center);
- if (t->con.applyRot && t->con.mode & CON_APPLY) {
- float axis[3];
- copy_v3_v3(axis, axis_global);
- t->con.applyRot(t, td, axis, NULL);
+ if (td->flag & TD_SKIP)
+ continue;
- mul_m3_v3(td->smtx, axis);
- if (isLockConstraint(t)) {
- float dvec[3];
- project_v3_v3v3(dvec, vec, axis);
- sub_v3_v3(vec, dvec);
- }
- else {
- project_v3_v3v3(vec, vec, axis);
+ sub_v3_v3v3(vec, tc->center_local, td->center);
+ if (t->con.applyRot && t->con.mode & CON_APPLY) {
+ float axis[3];
+ copy_v3_v3(axis, axis_global);
+ t->con.applyRot(t, tc, td, axis, NULL);
+
+ mul_m3_v3(td->smtx, axis);
+ if (isLockConstraint(t)) {
+ float dvec[3];
+ project_v3_v3v3(dvec, vec, axis);
+ sub_v3_v3(vec, dvec);
+ }
+ else {
+ project_v3_v3v3(vec, vec, axis);
+ }
}
- }
- normalize_v3_length(vec, distance * td->factor);
+ normalize_v3_length(vec, distance * td->factor);
- add_v3_v3v3(td->loc, td->iloc, vec);
+ add_v3_v3v3(td->loc, td->iloc, vec);
+ }
}
recalcData(t);
@@ -5026,7 +5142,6 @@ static void initBevelWeight(TransInfo *t)
static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float weight;
int i;
char str[UI_MAX_DRAW_STR];
@@ -5060,14 +5175,17 @@ static void applyBevelWeight(TransInfo *t, const int UNUSED(mval[2]))
BLI_snprintf(str, sizeof(str), IFACE_("Bevel Weight: %.3f %s"), weight, t->proptext);
}
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->val) {
- *td->val = td->ival + weight * td->factor;
- if (*td->val < 0.0f) *td->val = 0.0f;
- if (*td->val > 1.0f) *td->val = 1.0f;
+ if (td->val) {
+ *td->val = td->ival + weight * td->factor;
+ if (*td->val < 0.0f) *td->val = 0.0f;
+ if (*td->val > 1.0f) *td->val = 1.0f;
+ }
}
}
@@ -5106,7 +5224,6 @@ static void initCrease(TransInfo *t)
static void applyCrease(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float crease;
int i;
char str[UI_MAX_DRAW_STR];
@@ -5140,17 +5257,20 @@ static void applyCrease(TransInfo *t, const int UNUSED(mval[2]))
BLI_snprintf(str, sizeof(str), IFACE_("Crease: %.3f %s"), crease, t->proptext);
}
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (td->val) {
- *td->val = td->ival + crease * td->factor;
- if (*td->val < 0.0f) *td->val = 0.0f;
- if (*td->val > 1.0f) *td->val = 1.0f;
+ if (td->val) {
+ *td->val = td->ival + crease * td->factor;
+ if (*td->val < 0.0f) *td->val = 0.0f;
+ if (*td->val > 1.0f) *td->val = 1.0f;
+ }
}
}
@@ -5217,7 +5337,7 @@ static void headerBoneSize(TransInfo *t, const float vec[3], char str[UI_MAX_DRA
}
}
-static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3])
+static void ElementBoneSize(TransInfo *t, TransDataContainer *tc, TransData *td, float mat[3][3])
{
float tmat[3][3], smat[3][3], oldy;
float sizemat[3][3];
@@ -5226,7 +5346,7 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3])
mul_m3_m3m3(tmat, td->smtx, smat);
if (t->con.applySize) {
- t->con.applySize(t, td, tmat);
+ t->con.applySize(t, tc, td, tmat);
}
/* we've tucked the scale in loc */
@@ -5237,23 +5357,13 @@ static void ElementBoneSize(TransInfo *t, TransData *td, float mat[3][3])
td->loc[1] = oldy;
}
-static void applyBoneSize(TransInfo *t, const int mval[2])
+static void applyBoneSize(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float size[3], mat[3][3];
- float ratio;
+ float ratio = t->values[0];
int i;
char str[UI_MAX_DRAW_STR];
-
- // TRANSFORM_FIX_ME MOVE TO MOUSE INPUT
- /* for manipulator, center handle, the scaling can't be done relative to center */
- if ((t->flag & T_USES_MANIPULATOR) && t->con.mode == 0) {
- ratio = 1.0f - ((t->mouse.imval[0] - mval[0]) + (t->mouse.imval[1] - mval[1])) / 100.0f;
- }
- else {
- ratio = t->values[0];
- }
-
+
copy_v3_fl(size, ratio);
snapGridIncrement(t, size);
@@ -5267,23 +5377,26 @@ static void applyBoneSize(TransInfo *t, const int mval[2])
size_to_mat3(mat, size);
if (t->con.applySize) {
- t->con.applySize(t, NULL, mat);
+ t->con.applySize(t, NULL, NULL, mat);
}
copy_m3_m3(t->mat, mat); // used in manipulator
headerBoneSize(t, size, str);
-
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- ElementBoneSize(t, td, mat);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ ElementBoneSize(t, tc, td, mat);
+ }
}
-
+
recalcData(t);
ED_area_headerprint(t->sa, str);
@@ -5319,7 +5432,6 @@ static void initBoneEnvelope(TransInfo *t)
static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float ratio;
int i;
char str[UI_MAX_DRAW_STR];
@@ -5342,23 +5454,26 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
else {
BLI_snprintf(str, sizeof(str), IFACE_("Envelope: %3f"), ratio);
}
-
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- if (td->val) {
- /* if the old/original value was 0.0f, then just use ratio */
- if (td->ival)
- *td->val = td->ival * ratio;
- else
- *td->val = ratio;
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ if (td->val) {
+ /* if the old/original value was 0.0f, then just use ratio */
+ if (td->ival)
+ *td->val = td->ival * ratio;
+ else
+ *td->val = ratio;
+ }
}
}
-
+
recalcData(t);
ED_area_headerprint(t->sa, str);
@@ -5372,9 +5487,9 @@ static void applyBoneEnvelope(TransInfo *t, const int UNUSED(mval[2]))
* \{ */
static void slide_origdata_init_flag(
- TransInfo *t, SlideOrigData *sod)
+ TransInfo *t, TransDataContainer *tc, SlideOrigData *sod)
{
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
BMesh *bm = em->bm;
const bool has_layer_math = CustomData_has_math(&bm->ldata);
const int cd_loop_mdisp_offset = CustomData_get_offset(&bm->ldata, CD_MDISPS);
@@ -5395,10 +5510,10 @@ static void slide_origdata_init_flag(
}
static void slide_origdata_init_data(
- TransInfo *t, SlideOrigData *sod)
+ TransDataContainer *tc, SlideOrigData *sod)
{
if (sod->use_origfaces) {
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
BMesh *bm = em->bm;
sod->origfaces = BLI_ghash_ptr_new(__func__);
@@ -5459,11 +5574,11 @@ static void slide_origdata_create_data_vert(
}
static void slide_origdata_create_data(
- TransInfo *t, SlideOrigData *sod,
+ TransInfo *t, TransDataContainer *tc, SlideOrigData *sod,
TransDataGenericSlideVert *sv_array, unsigned int v_stride, unsigned int v_num)
{
if (sod->use_origfaces) {
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
BMesh *bm = em->bm;
unsigned int i;
TransDataGenericSlideVert *sv;
@@ -5495,15 +5610,15 @@ static void slide_origdata_create_data(
}
if (t->flag & T_MIRROR) {
- TransData *td = t->data;
+ TransData *td = tc->data;
TransDataGenericSlideVert *sv_mirror;
- sod->sv_mirror = MEM_callocN(sizeof(*sv_mirror) * t->total, __func__);
- sod->totsv_mirror = t->total;
+ sod->sv_mirror = MEM_callocN(sizeof(*sv_mirror) * tc->data_len, __func__);
+ sod->totsv_mirror = tc->data_len;
sv_mirror = sod->sv_mirror;
- for (i = 0; i < t->total; i++, td++) {
+ for (i = 0; i < tc->data_len; i++, td++) {
BMVert *eve = td->extra;
if (eve) {
sv_mirror->v = eve;
@@ -5657,12 +5772,12 @@ static void slide_origdata_interp_data_vert(
}
static void slide_origdata_interp_data(
- TransInfo *t, SlideOrigData *sod,
+ Object *obedit, SlideOrigData *sod,
TransDataGenericSlideVert *sv, unsigned int v_stride, unsigned int v_num,
bool is_final)
{
if (sod->use_origfaces) {
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
unsigned int i;
const bool has_mdisps = (sod->cd_loop_mdisp_offset != -1);
@@ -5725,7 +5840,7 @@ static void slide_origdata_free_date(
static void calcEdgeSlideCustomPoints(struct TransInfo *t)
{
- EdgeSlideData *sld = t->custom.mode.data;
+ EdgeSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data;
setCustomPoints(t, &t->mouse, sld->mval_end, sld->mval_start);
@@ -5793,6 +5908,7 @@ static bool bm_loop_calc_opposite_co(BMLoop *l_tmp,
BMLoop *l_last = l_tmp->prev;
BMLoop *l_iter;
float dist = FLT_MAX;
+ bool found = false;
l_iter = l_first;
do {
@@ -5811,12 +5927,13 @@ static bool bm_loop_calc_opposite_co(BMLoop *l_tmp,
if (tdist < dist) {
copy_v3_v3(r_co, tvec);
dist = tdist;
+ found = true;
}
}
}
} while ((l_iter = l_iter->next) != l_last);
- return (dist != FLT_MAX);
+ return found;
}
/**
@@ -5922,11 +6039,11 @@ static BMLoop *get_next_loop(BMVert *v, BMLoop *l,
* Calculate screenspace `mval_start` / `mval_end`, optionally slide direction.
*/
static void calcEdgeSlide_mval_range(
- TransInfo *t, EdgeSlideData *sld, const int *sv_table, const int loop_nr,
+ TransInfo *t, TransDataContainer *tc, EdgeSlideData *sld, const int *sv_table, const int loop_nr,
const float mval[2], const bool use_occlude_geometry, const bool use_calc_direction)
{
TransDataEdgeSlideVert *sv_array = sld->sv;
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
BMesh *bm = em->bm;
ARegion *ar = t->ar;
View3D *v3d = NULL;
@@ -5953,7 +6070,7 @@ static void calcEdgeSlide_mval_range(
unit_m4(projectMat);
}
else {
- ED_view3d_ob_project_mat_get(rv3d, t->obedit, projectMat);
+ ED_view3d_ob_project_mat_get(rv3d, tc->obedit, projectMat);
}
if (use_occlude_geometry) {
@@ -5995,7 +6112,9 @@ static void calcEdgeSlide_mval_range(
continue;
/* This test is only relevant if object is not wire-drawn! See [#32068]. */
- if (use_occlude_geometry && !BMBVH_EdgeVisible(bmbvh, e_other, ar, v3d, t->obedit)) {
+ if (use_occlude_geometry &&
+ !BMBVH_EdgeVisible(bmbvh, e_other, t->depsgraph, ar, v3d, tc->obedit))
+ {
continue;
}
@@ -6082,7 +6201,7 @@ static void calcEdgeSlide_mval_range(
}
static void calcEdgeSlide_even(
- TransInfo *t, EdgeSlideData *sld, const float mval[2])
+ TransInfo *t, TransDataContainer *tc, EdgeSlideData *sld, const float mval[2])
{
TransDataEdgeSlideVert *sv = sld->sv;
@@ -6107,7 +6226,7 @@ static void calcEdgeSlide_even(
unit_m4(projectMat);
}
else {
- ED_view3d_ob_project_mat_get(rv3d, t->obedit, projectMat);
+ ED_view3d_ob_project_mat_get(rv3d, tc->obedit, projectMat);
}
for (i = 0; i < sld->totsv; i++, sv++) {
@@ -6127,9 +6246,9 @@ static void calcEdgeSlide_even(
}
}
-static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool flipped, bool use_clamp)
+static bool createEdgeSlideVerts_double_side(TransInfo *t, TransDataContainer *tc)
{
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
BMesh *bm = em->bm;
BMIter iter;
BMEdge *e;
@@ -6144,13 +6263,9 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool f
View3D *v3d = NULL;
RegionView3D *rv3d = NULL;
- slide_origdata_init_flag(t, &sld->orig_data);
+ slide_origdata_init_flag(t, tc, &sld->orig_data);
- sld->use_even = use_even;
sld->curr_sv_index = 0;
- sld->flipped = flipped;
- if (!use_clamp)
- t->flag |= T_ALT_TRANSFORM;
/*ensure valid selection*/
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
@@ -6466,26 +6581,24 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool f
if (t->spacetype == SPACE_VIEW3D) {
v3d = t->sa ? t->sa->spacedata.first : NULL;
rv3d = t->ar ? t->ar->regiondata : NULL;
- use_occlude_geometry = (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE);
+ use_occlude_geometry = (v3d && TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE);
}
- calcEdgeSlide_mval_range(t, sld, sv_table, loop_nr, mval, use_occlude_geometry, true);
+ calcEdgeSlide_mval_range(t, tc, sld, sv_table, loop_nr, mval, use_occlude_geometry, true);
/* create copies of faces for customdata projection */
bmesh_edit_begin(bm, BMO_OPTYPE_FLAG_UNTAN_MULTIRES);
- slide_origdata_init_data(t, &sld->orig_data);
- slide_origdata_create_data(t, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv);
+ slide_origdata_init_data(tc, &sld->orig_data);
+ slide_origdata_create_data(t, tc, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv);
if (rv3d) {
- calcEdgeSlide_even(t, sld, mval);
+ calcEdgeSlide_even(t, tc, sld, mval);
}
sld->em = em;
-
- sld->perc = 0.0f;
-
- t->custom.mode.data = sld;
-
+
+ tc->custom.mode.data = sld;
+
MEM_freeN(sv_table);
return true;
@@ -6495,9 +6608,9 @@ static bool createEdgeSlideVerts_double_side(TransInfo *t, bool use_even, bool f
* A simple version of #createEdgeSlideVerts_double_side
* Which assumes the longest unselected.
*/
-static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool flipped, bool use_clamp)
+static bool createEdgeSlideVerts_single_side(TransInfo *t, TransDataContainer *tc)
{
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
BMesh *bm = em->bm;
BMIter iter;
BMEdge *e;
@@ -6517,15 +6630,9 @@ static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool f
rv3d = t->ar ? t->ar->regiondata : NULL;
}
- slide_origdata_init_flag(t, &sld->orig_data);
+ slide_origdata_init_flag(t, tc, &sld->orig_data);
- sld->use_even = use_even;
sld->curr_sv_index = 0;
- /* happens to be best for single-sided */
- sld->flipped = !flipped;
- if (!use_clamp)
- t->flag |= T_ALT_TRANSFORM;
-
/* ensure valid selection */
{
int i = 0, j = 0;
@@ -6669,25 +6776,23 @@ static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool f
if (t->spacetype == SPACE_VIEW3D) {
v3d = t->sa ? t->sa->spacedata.first : NULL;
rv3d = t->ar ? t->ar->regiondata : NULL;
- use_occlude_geometry = (v3d && t->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE);
+ use_occlude_geometry = (v3d && TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->dt > OB_WIRE && v3d->drawtype > OB_WIRE);
}
- calcEdgeSlide_mval_range(t, sld, sv_table, loop_nr, mval, use_occlude_geometry, false);
+ calcEdgeSlide_mval_range(t, tc, sld, sv_table, loop_nr, mval, use_occlude_geometry, false);
/* create copies of faces for customdata projection */
bmesh_edit_begin(bm, BMO_OPTYPE_FLAG_UNTAN_MULTIRES);
- slide_origdata_init_data(t, &sld->orig_data);
- slide_origdata_create_data(t, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv);
+ slide_origdata_init_data(tc, &sld->orig_data);
+ slide_origdata_create_data(t, tc, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv);
if (rv3d) {
- calcEdgeSlide_even(t, sld, mval);
+ calcEdgeSlide_even(t, tc, sld, mval);
}
sld->em = em;
- sld->perc = 0.0f;
-
- t->custom.mode.data = sld;
+ tc->custom.mode.data = sld;
MEM_freeN(sv_table);
@@ -6696,14 +6801,16 @@ static bool createEdgeSlideVerts_single_side(TransInfo *t, bool use_even, bool f
void projectEdgeSlideData(TransInfo *t, bool is_final)
{
- EdgeSlideData *sld = t->custom.mode.data;
- SlideOrigData *sod = &sld->orig_data;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ EdgeSlideData *sld = tc->custom.mode.data;
+ SlideOrigData *sod = &sld->orig_data;
- if (sod->use_origfaces == false) {
- return;
- }
+ if (sod->use_origfaces == false) {
+ return;
+ }
- slide_origdata_interp_data(t, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final);
+ slide_origdata_interp_data(tc->obedit, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final);
+ }
}
void freeEdgeSlideTempFaces(EdgeSlideData *sld)
@@ -6711,7 +6818,7 @@ void freeEdgeSlideTempFaces(EdgeSlideData *sld)
slide_origdata_free_date(&sld->orig_data);
}
-void freeEdgeSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data)
+void freeEdgeSlideVerts(TransInfo *UNUSED(t), TransDataContainer *UNUSED(tc), TransCustomData *custom_data)
{
EdgeSlideData *sld = custom_data->data;
@@ -6731,30 +6838,53 @@ void freeEdgeSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data)
static void initEdgeSlide_ex(TransInfo *t, bool use_double_side, bool use_even, bool flipped, bool use_clamp)
{
EdgeSlideData *sld;
- bool ok;
+ bool ok = false;
t->mode = TFM_EDGE_SLIDE;
t->transform = applyEdgeSlide;
t->handleEvent = handleEventEdgeSlide;
+ {
+ EdgeSlideParams *slp = MEM_callocN(sizeof(*slp), __func__);
+ slp->use_even = use_even;
+ slp->flipped = flipped;
+ /* happens to be best for single-sided */
+ if (use_double_side == false) {
+ slp->flipped = !flipped;
+ }
+ slp->perc = 0.0f;
+
+ if (!use_clamp) {
+ t->flag |= T_ALT_TRANSFORM;
+ }
+
+ t->custom.mode.data = slp;
+ t->custom.mode.use_free = true;
+ }
+
if (use_double_side) {
- ok = createEdgeSlideVerts_double_side(t, use_even, flipped, use_clamp);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ ok |= createEdgeSlideVerts_double_side(t, tc);
+ }
}
else {
- ok = createEdgeSlideVerts_single_side(t, use_even, flipped, use_clamp);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ ok |= createEdgeSlideVerts_single_side(t, tc);
+ }
}
if (!ok) {
t->state = TRANS_CANCEL;
return;
}
-
- sld = t->custom.mode.data;
- if (!sld)
- return;
-
- t->custom.mode.free_cb = freeEdgeSlideVerts;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ sld = tc->custom.mode.data;
+ if (!sld) {
+ continue;
+ }
+ tc->custom.mode.free_cb = freeEdgeSlideVerts;
+ }
/* set custom point first if you want value to be initialized by init */
calcEdgeSlideCustomPoints(t);
@@ -6781,20 +6911,20 @@ static void initEdgeSlide(TransInfo *t)
static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEvent *event)
{
if (t->mode == TFM_EDGE_SLIDE) {
- EdgeSlideData *sld = t->custom.mode.data;
+ EdgeSlideParams *slp = t->custom.mode.data;
- if (sld) {
+ if (slp) {
switch (event->type) {
case EKEY:
if (event->val == KM_PRESS) {
- sld->use_even = !sld->use_even;
+ slp->use_even = !slp->use_even;
calcEdgeSlideCustomPoints(t);
return TREDRAW_HARD;
}
break;
case FKEY:
if (event->val == KM_PRESS) {
- sld->flipped = !sld->flipped;
+ slp->flipped = !slp->flipped;
calcEdgeSlideCustomPoints(t);
return TREDRAW_HARD;
}
@@ -6808,6 +6938,7 @@ static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEven
}
break;
case EVT_MODAL_MAP:
+#if 0
switch (event->val) {
case TFM_MODAL_EDGESLIDE_DOWN:
sld->curr_sv_index = ((sld->curr_sv_index - 1) + sld->totsv) % sld->totsv;
@@ -6816,6 +6947,7 @@ static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEven
sld->curr_sv_index = (sld->curr_sv_index + 1) % sld->totsv;
return TREDRAW_HARD;
}
+#endif
break;
case MOUSEMOVE:
calcEdgeSlideCustomPoints(t);
@@ -6830,12 +6962,13 @@ static eRedrawFlag handleEventEdgeSlide(struct TransInfo *t, const struct wmEven
static void drawEdgeSlide(TransInfo *t)
{
- if ((t->mode == TFM_EDGE_SLIDE) && t->custom.mode.data) {
- EdgeSlideData *sld = t->custom.mode.data;
+ if ((t->mode == TFM_EDGE_SLIDE) && TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data) {
+ const EdgeSlideParams *slp = t->custom.mode.data;
+ EdgeSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data;
const bool is_clamp = !(t->flag & T_ALT_TRANSFORM);
/* Even mode */
- if ((sld->use_even == true) || (is_clamp == false)) {
+ if ((slp->use_even == true) || (is_clamp == false)) {
View3D *v3d = t->view;
const float line_size = UI_GetThemeValuef(TH_OUTLINE_WIDTH) + 0.5f;
@@ -6843,17 +6976,19 @@ static void drawEdgeSlide(TransInfo *t)
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+
+ gpuPushMatrix();
+ gpuMultMatrix(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat);
- glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT | GL_POINT_BIT);
- glPushMatrix();
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
- glMultMatrixf(t->obedit->obmat);
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
- if (sld->use_even == true) {
+ if (slp->use_even == true) {
float co_a[3], co_b[3], co_mark[3];
TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
- const float fac = (sld->perc + 1.0f) / 2.0f;
+ const float fac = (slp->perc + 1.0f) / 2.0f;
const float ctrl_size = UI_GetThemeValuef(TH_FACEDOT_SIZE) + 1.5f;
const float guide_size = ctrl_size - 0.5f;
const int alpha_shade = -30;
@@ -6862,39 +6997,35 @@ static void drawEdgeSlide(TransInfo *t)
add_v3_v3v3(co_b, curr_sv->v_co_orig, curr_sv->dir_side[1]);
glLineWidth(line_size);
- UI_ThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade);
- glBegin(GL_LINES);
+ immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade);
+ immBeginAtMost(GWN_PRIM_LINES, 4);
if (curr_sv->v_side[0]) {
- glVertex3fv(curr_sv->v_side[0]->co);
- glVertex3fv(curr_sv->v_co_orig);
+ immVertex3fv(pos, curr_sv->v_side[0]->co);
+ immVertex3fv(pos, curr_sv->v_co_orig);
}
if (curr_sv->v_side[1]) {
- glVertex3fv(curr_sv->v_side[1]->co);
- glVertex3fv(curr_sv->v_co_orig);
+ immVertex3fv(pos, curr_sv->v_side[1]->co);
+ immVertex3fv(pos, curr_sv->v_co_orig);
}
- glEnd();
+ immEnd();
- UI_ThemeColorShadeAlpha(TH_SELECT, -30, alpha_shade);
+ immUniformThemeColorShadeAlpha(TH_SELECT, -30, alpha_shade);
glPointSize(ctrl_size);
- glBegin(GL_POINTS);
- if (sld->flipped) {
- if (curr_sv->v_side[1]) glVertex3fv(curr_sv->v_side[1]->co);
+ immBegin(GWN_PRIM_POINTS, 1);
+ if (slp->flipped) {
+ if (curr_sv->v_side[1]) immVertex3fv(pos, curr_sv->v_side[1]->co);
}
else {
- if (curr_sv->v_side[0]) glVertex3fv(curr_sv->v_side[0]->co);
+ if (curr_sv->v_side[0]) immVertex3fv(pos, curr_sv->v_side[0]->co);
}
- glEnd();
+ immEnd();
- UI_ThemeColorShadeAlpha(TH_SELECT, 255, alpha_shade);
+ immUniformThemeColorShadeAlpha(TH_SELECT, 255, alpha_shade);
glPointSize(guide_size);
- glBegin(GL_POINTS);
-#if 0
- interp_v3_v3v3(co_mark, co_b, co_a, fac);
- glVertex3fv(co_mark);
-#endif
+ immBegin(GWN_PRIM_POINTS, 1);
interp_line_v3_v3v3v3(co_mark, co_b, curr_sv->v_co_orig, co_a, fac);
- glVertex3fv(co_mark);
- glEnd();
+ immVertex3fv(pos, co_mark);
+ immEnd();
}
else {
if (is_clamp == false) {
@@ -6904,9 +7035,10 @@ static void drawEdgeSlide(TransInfo *t)
const int alpha_shade = -160;
glLineWidth(line_size);
- UI_ThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade);
- glBegin(GL_LINES);
+ immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade);
+ immBegin(GWN_PRIM_LINES, sld->totsv * 2);
+ /* TODO(campbell): Loop over all verts */
sv = sld->sv;
for (i = 0; i < sld->totsv; i++, sv++) {
float a[3], b[3];
@@ -6923,18 +7055,19 @@ static void drawEdgeSlide(TransInfo *t)
add_v3_v3(a, sv->v_co_orig);
add_v3_v3(b, sv->v_co_orig);
- glVertex3fv(a);
- glVertex3fv(b);
+ immVertex3fv(pos, a);
+ immVertex3fv(pos, b);
}
- glEnd();
+ immEnd();
}
else {
BLI_assert(0);
}
}
- glPopMatrix();
- glPopAttrib();
+ immUnbindProgram();
+
+ gpuPopMatrix();
glDisable(GL_BLEND);
@@ -6946,38 +7079,43 @@ static void drawEdgeSlide(TransInfo *t)
static void doEdgeSlide(TransInfo *t, float perc)
{
- EdgeSlideData *sld = t->custom.mode.data;
- TransDataEdgeSlideVert *svlist = sld->sv, *sv;
- int i;
+ EdgeSlideParams *slp = t->custom.mode.data;
+ EdgeSlideData *sld_active = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data;
- sld->perc = perc;
- sv = svlist;
+ slp->perc = perc;
- if (sld->use_even == false) {
+ if (slp->use_even == false) {
const bool is_clamp = !(t->flag & T_ALT_TRANSFORM);
if (is_clamp) {
const int side_index = (perc < 0.0f);
const float perc_final = fabsf(perc);
- for (i = 0; i < sld->totsv; i++, sv++) {
- madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, sv->dir_side[side_index], perc_final);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ EdgeSlideData *sld = tc->custom.mode.data;
+ TransDataEdgeSlideVert *sv = sld->sv;
+ for (int i = 0; i < sld->totsv; i++, sv++) {
+ madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, sv->dir_side[side_index], perc_final);
+ }
+ sld->curr_side_unclamp = side_index;
}
-
- sld->curr_side_unclamp = side_index;
}
else {
- const int side_index = sld->curr_side_unclamp;
- const float perc_init = fabsf(perc) * ((sld->curr_side_unclamp == (perc < 0.0f)) ? 1 : -1);
- for (i = 0; i < sld->totsv; i++, sv++) {
- float dir_flip[3];
- float perc_final = perc_init;
- if (!is_zero_v3(sv->dir_side[side_index])) {
- copy_v3_v3(dir_flip, sv->dir_side[side_index]);
- }
- else {
- copy_v3_v3(dir_flip, sv->dir_side[!side_index]);
- perc_final *= -1;
+ const float perc_init = fabsf(perc) * ((sld_active->curr_side_unclamp == (perc < 0.0f)) ? 1 : -1);
+ const int side_index = sld_active->curr_side_unclamp;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ EdgeSlideData *sld = tc->custom.mode.data;
+ TransDataEdgeSlideVert *sv = sld->sv;
+ for (int i = 0; i < sld->totsv; i++, sv++) {
+ float dir_flip[3];
+ float perc_final = perc_init;
+ if (!is_zero_v3(sv->dir_side[side_index])) {
+ copy_v3_v3(dir_flip, sv->dir_side[side_index]);
+ }
+ else {
+ copy_v3_v3(dir_flip, sv->dir_side[!side_index]);
+ perc_final *= -1;
+ }
+ madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, dir_flip, perc_final);
}
- madd_v3_v3v3fl(sv->v->co, sv->v_co_orig, dir_flip, perc_final);
}
}
}
@@ -6990,24 +7128,28 @@ static void doEdgeSlide(TransInfo *t, float perc)
* \note len_v3v3(curr_sv->dir_side[0], curr_sv->dir_side[1])
* is the same as the distance between the original vert locations, same goes for the lines below.
*/
- TransDataEdgeSlideVert *curr_sv = &sld->sv[sld->curr_sv_index];
- const float curr_length_perc = curr_sv->edge_len * (((sld->flipped ? perc : -perc) + 1.0f) / 2.0f);
+ TransDataEdgeSlideVert *curr_sv = &sld_active->sv[sld_active->curr_sv_index];
+ const float curr_length_perc = curr_sv->edge_len * (((slp->flipped ? perc : -perc) + 1.0f) / 2.0f);
float co_a[3];
float co_b[3];
- for (i = 0; i < sld->totsv; i++, sv++) {
- if (sv->edge_len > FLT_EPSILON) {
- const float fac = min_ff(sv->edge_len, curr_length_perc) / sv->edge_len;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ EdgeSlideData *sld = tc->custom.mode.data;
+ TransDataEdgeSlideVert *sv = sld->sv;
+ for (int i = 0; i < sld->totsv; i++, sv++) {
+ if (sv->edge_len > FLT_EPSILON) {
+ const float fac = min_ff(sv->edge_len, curr_length_perc) / sv->edge_len;
- add_v3_v3v3(co_a, sv->v_co_orig, sv->dir_side[0]);
- add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_side[1]);
+ add_v3_v3v3(co_a, sv->v_co_orig, sv->dir_side[0]);
+ add_v3_v3v3(co_b, sv->v_co_orig, sv->dir_side[1]);
- if (sld->flipped) {
- interp_line_v3_v3v3v3(sv->v->co, co_b, sv->v_co_orig, co_a, fac);
- }
- else {
- interp_line_v3_v3v3v3(sv->v->co, co_a, sv->v_co_orig, co_b, fac);
+ if (slp->flipped) {
+ interp_line_v3_v3v3v3(sv->v->co, co_b, sv->v_co_orig, co_a, fac);
+ }
+ else {
+ interp_line_v3_v3v3v3(sv->v->co, co_a, sv->v_co_orig, co_b, fac);
+ }
}
}
}
@@ -7019,9 +7161,9 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
char str[UI_MAX_DRAW_STR];
size_t ofs = 0;
float final;
- EdgeSlideData *sld = t->custom.mode.data;
- bool flipped = sld->flipped;
- bool use_even = sld->use_even;
+ EdgeSlideParams *slp = t->custom.mode.data;
+ bool flipped = slp->flipped;
+ bool use_even = slp->use_even;
const bool is_clamp = !(t->flag & T_ALT_TRANSFORM);
const bool is_constrained = !(is_clamp == false || hasNumInput(&t->num));
@@ -7073,7 +7215,8 @@ static void applyEdgeSlide(TransInfo *t, const int UNUSED(mval[2]))
static void calcVertSlideCustomPoints(struct TransInfo *t)
{
- VertSlideData *sld = t->custom.mode.data;
+ VertSlideParams *slp = t->custom.mode.data;
+ VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data;
TransDataVertSlideVert *sv = &sld->sv[sld->curr_sv_index];
const float *co_orig_3d = sv->co_orig_3d;
@@ -7090,7 +7233,7 @@ static void calcVertSlideCustomPoints(struct TransInfo *t)
ARRAY_SET_ITEMS(mval_start, co_orig_2d[0] + mval_ofs[0], co_orig_2d[1] + mval_ofs[1]);
ARRAY_SET_ITEMS(mval_end, co_curr_2d[0] + mval_ofs[0], co_curr_2d[1] + mval_ofs[1]);
- if (sld->flipped && sld->use_even) {
+ if (slp->flipped && slp->use_even) {
setCustomPoints(t, &t->mouse, mval_start, mval_end);
}
else {
@@ -7108,7 +7251,8 @@ static void calcVertSlideCustomPoints(struct TransInfo *t)
*/
static void calcVertSlideMouseActiveVert(struct TransInfo *t, const int mval[2])
{
- VertSlideData *sld = t->custom.mode.data;
+ /* Active object may have no selected vertices. */
+ VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data;
float mval_fl[2] = {UNPACK2(mval)};
TransDataVertSlideVert *sv;
@@ -7135,7 +7279,7 @@ static void calcVertSlideMouseActiveVert(struct TransInfo *t, const int mval[2])
*/
static void calcVertSlideMouseActiveEdges(struct TransInfo *t, const int mval[2])
{
- VertSlideData *sld = t->custom.mode.data;
+ VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data;
float imval_fl[2] = {UNPACK2(t->mouse.imval)};
float mval_fl[2] = {UNPACK2(mval)};
@@ -7163,7 +7307,7 @@ static void calcVertSlideMouseActiveEdges(struct TransInfo *t, const int mval[2]
float dir_dot;
sub_v3_v3v3(tdir, sv->co_orig_3d, sv->co_link_orig_3d[j]);
- mul_mat3_m4_v3(t->obedit->obmat, tdir);
+ mul_mat3_m4_v3(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat, tdir);
project_plane_v3_v3v3(tdir, tdir, t->viewinv[2]);
normalize_v3(tdir);
@@ -7181,9 +7325,9 @@ static void calcVertSlideMouseActiveEdges(struct TransInfo *t, const int mval[2]
}
}
-static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool use_clamp)
+static bool createVertSlideVerts(TransInfo *t, TransDataContainer *tc)
{
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
BMesh *bm = em->bm;
BMIter iter;
BMIter eiter;
@@ -7193,13 +7337,9 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool
VertSlideData *sld = MEM_callocN(sizeof(*sld), "sld");
int j;
- slide_origdata_init_flag(t, &sld->orig_data);
+ slide_origdata_init_flag(t, tc, &sld->orig_data);
- sld->use_even = use_even;
sld->curr_sv_index = 0;
- sld->flipped = flipped;
- if (!use_clamp)
- t->flag |= T_ALT_TRANSFORM;
j = 0;
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
@@ -7262,14 +7402,12 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool
sld->totsv = j;
bmesh_edit_begin(bm, BMO_OPTYPE_FLAG_UNTAN_MULTIRES);
- slide_origdata_init_data(t, &sld->orig_data);
- slide_origdata_create_data(t, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv);
+ slide_origdata_init_data(tc, &sld->orig_data);
+ slide_origdata_create_data(t, tc, &sld->orig_data, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv);
sld->em = em;
- sld->perc = 0.0f;
-
- t->custom.mode.data = sld;
+ tc->custom.mode.data = sld;
/* most likely will be set below */
unit_m4(sld->proj_mat);
@@ -7281,9 +7419,12 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool
rv3d = ar ? ar->regiondata : NULL;
if (rv3d) {
- ED_view3d_ob_project_mat_get(rv3d, t->obedit, sld->proj_mat);
+ ED_view3d_ob_project_mat_get(rv3d, tc->obedit, sld->proj_mat);
}
+ }
+ /* XXX, calc vert slide across all objects */
+ if (tc == t->data_container) {
calcVertSlideMouseActiveVert(t, t->mval);
calcVertSlideMouseActiveEdges(t, t->mval);
}
@@ -7293,14 +7434,13 @@ static bool createVertSlideVerts(TransInfo *t, bool use_even, bool flipped, bool
void projectVertSlideData(TransInfo *t, bool is_final)
{
- VertSlideData *sld = t->custom.mode.data;
- SlideOrigData *sod = &sld->orig_data;
-
- if (sod->use_origfaces == false) {
- return;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ VertSlideData *sld = tc->custom.mode.data;
+ SlideOrigData *sod = &sld->orig_data;
+ if (sod->use_origfaces == true) {
+ slide_origdata_interp_data(tc->obedit, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final);
+ }
}
-
- slide_origdata_interp_data(t, sod, (TransDataGenericSlideVert *)sld->sv, sizeof(*sld->sv), sld->totsv, is_final);
}
void freeVertSlideTempFaces(VertSlideData *sld)
@@ -7308,7 +7448,7 @@ void freeVertSlideTempFaces(VertSlideData *sld)
slide_origdata_free_date(&sld->orig_data);
}
-void freeVertSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data)
+void freeVertSlideVerts(TransInfo *UNUSED(t), TransDataContainer *UNUSED(tc), TransCustomData *custom_data)
{
VertSlideData *sld = custom_data->data;
@@ -7335,23 +7475,38 @@ void freeVertSlideVerts(TransInfo *UNUSED(t), TransCustomData *custom_data)
static void initVertSlide_ex(TransInfo *t, bool use_even, bool flipped, bool use_clamp)
{
- VertSlideData *sld;
t->mode = TFM_VERT_SLIDE;
t->transform = applyVertSlide;
t->handleEvent = handleEventVertSlide;
- if (!createVertSlideVerts(t, use_even, flipped, use_clamp)) {
- t->state = TRANS_CANCEL;
- return;
+ {
+ VertSlideParams *slp = MEM_callocN(sizeof(*slp), __func__);
+ slp->use_even = use_even;
+ slp->flipped = flipped;
+ slp->perc = 0.0f;
+
+ if (!use_clamp) {
+ t->flag |= T_ALT_TRANSFORM;
+ }
+
+ t->custom.mode.data = slp;
+ t->custom.mode.use_free = true;
}
- sld = t->custom.mode.data;
+ bool ok = false;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ ok |= createVertSlideVerts(t, tc);
+ VertSlideData *sld = tc->custom.mode.data;
+ if (sld) {
+ tc->custom.mode.free_cb = freeVertSlideVerts;
+ }
+ }
- if (!sld)
+ if (ok == false) {
+ t->state = TRANS_CANCEL;
return;
-
- t->custom.mode.free_cb = freeVertSlideVerts;
+ }
/* set custom point first if you want value to be initialized by init */
calcVertSlideCustomPoints(t);
@@ -7378,14 +7533,14 @@ static void initVertSlide(TransInfo *t)
static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEvent *event)
{
if (t->mode == TFM_VERT_SLIDE) {
- VertSlideData *sld = t->custom.mode.data;
+ VertSlideParams *slp = t->custom.mode.data;
- if (sld) {
+ if (slp) {
switch (event->type) {
case EKEY:
if (event->val == KM_PRESS) {
- sld->use_even = !sld->use_even;
- if (sld->flipped) {
+ slp->use_even = !slp->use_even;
+ if (slp->flipped) {
calcVertSlideCustomPoints(t);
}
return TREDRAW_HARD;
@@ -7393,7 +7548,7 @@ static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEven
break;
case FKEY:
if (event->val == KM_PRESS) {
- sld->flipped = !sld->flipped;
+ slp->flipped = !slp->flipped;
calcVertSlideCustomPoints(t);
return TREDRAW_HARD;
}
@@ -7438,8 +7593,9 @@ static eRedrawFlag handleEventVertSlide(struct TransInfo *t, const struct wmEven
static void drawVertSlide(TransInfo *t)
{
- if ((t->mode == TFM_VERT_SLIDE) && t->custom.mode.data) {
- VertSlideData *sld = t->custom.mode.data;
+ if ((t->mode == TFM_VERT_SLIDE) && TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data) {
+ const VertSlideParams *slp = t->custom.mode.data;
+ VertSlideData *sld = TRANS_DATA_CONTAINER_FIRST_OK(t)->custom.mode.data;
const bool is_clamp = !(t->flag & T_ALT_TRANSFORM);
/* Non-Prop mode */
@@ -7456,21 +7612,24 @@ static void drawVertSlide(TransInfo *t)
glDisable(GL_DEPTH_TEST);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-
- glPushAttrib(GL_CURRENT_BIT | GL_LINE_BIT | GL_POINT_BIT);
- glPushMatrix();
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- glMultMatrixf(t->obedit->obmat);
+ gpuPushMatrix();
+ gpuMultMatrix(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat);
glLineWidth(line_size);
- UI_ThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade);
- glBegin(GL_LINES);
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformThemeColorShadeAlpha(TH_EDGE_SELECT, 80, alpha_shade);
+
+ immBegin(GWN_PRIM_LINES, sld->totsv * 2);
if (is_clamp) {
sv = sld->sv;
for (i = 0; i < sld->totsv; i++, sv++) {
- glVertex3fv(sv->co_orig_3d);
- glVertex3fv(sv->co_link_orig_3d[sv->co_link_curr]);
+ immVertex3fv(shdr_pos, sv->co_orig_3d);
+ immVertex3fv(shdr_pos, sv->co_link_orig_3d[sv->co_link_curr]);
}
}
else {
@@ -7483,21 +7642,21 @@ static void drawVertSlide(TransInfo *t)
add_v3_v3(a, sv->co_orig_3d);
add_v3_v3(b, sv->co_orig_3d);
- glVertex3fv(a);
- glVertex3fv(b);
+ immVertex3fv(shdr_pos, a);
+ immVertex3fv(shdr_pos, b);
}
}
- glEnd();
+ immEnd();
glPointSize(ctrl_size);
- glBegin(GL_POINTS);
- glVertex3fv((sld->flipped && sld->use_even) ?
+ immBegin(GWN_PRIM_POINTS, 1);
+ immVertex3fv(shdr_pos, (slp->flipped && slp->use_even) ?
curr_sv->co_link_orig_3d[curr_sv->co_link_curr] :
curr_sv->co_orig_3d);
- glEnd();
+ immEnd();
- glDisable(GL_BLEND);
+ immUnbindProgram();
/* direction from active vertex! */
if ((t->mval[0] != t->mouse.imval[0]) ||
@@ -7511,29 +7670,38 @@ static void drawVertSlide(TransInfo *t)
mval_ofs[0] = t->mval[0] - t->mouse.imval[0];
mval_ofs[1] = t->mval[1] - t->mouse.imval[1];
- mul_v3_m4v3(co_orig_3d, t->obedit->obmat, curr_sv->co_orig_3d);
+ mul_v3_m4v3(co_orig_3d, TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat, curr_sv->co_orig_3d);
zfac = ED_view3d_calc_zfac(t->ar->regiondata, co_orig_3d, NULL);
ED_view3d_win_to_delta(t->ar, mval_ofs, co_dest_3d, zfac);
- invert_m4_m4(t->obedit->imat, t->obedit->obmat);
- mul_mat3_m4_v3(t->obedit->imat, co_dest_3d);
+ invert_m4_m4(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->imat, TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->obmat);
+ mul_mat3_m4_v3(TRANS_DATA_CONTAINER_FIRST_OK(t)->obedit->imat, co_dest_3d);
add_v3_v3(co_dest_3d, curr_sv->co_orig_3d);
- glLineWidth(1);
- setlinestyle(1);
+ glLineWidth(1.0f);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
- cpack(0xffffff);
- glBegin(GL_LINES);
- glVertex3fv(curr_sv->co_orig_3d);
- glVertex3fv(co_dest_3d);
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex3fv(shdr_pos, curr_sv->co_orig_3d);
+ immVertex3fv(shdr_pos, co_dest_3d);
+ immEnd();
+
+ immUnbindProgram();
}
- glPopMatrix();
- glPopAttrib();
+ gpuPopMatrix();
if (v3d && v3d->zbuf)
glEnable(GL_DEPTH_TEST);
@@ -7543,41 +7711,46 @@ static void drawVertSlide(TransInfo *t)
static void doVertSlide(TransInfo *t, float perc)
{
- VertSlideData *sld = t->custom.mode.data;
- TransDataVertSlideVert *svlist = sld->sv, *sv;
- int i;
+ VertSlideParams *slp = t->custom.mode.data;
- sld->perc = perc;
- sv = svlist;
+ slp->perc = perc;
- if (sld->use_even == false) {
- for (i = 0; i < sld->totsv; i++, sv++) {
- interp_v3_v3v3(sv->v->co, sv->co_orig_3d, sv->co_link_orig_3d[sv->co_link_curr], perc);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ VertSlideData *sld = tc->custom.mode.data;
+ TransDataVertSlideVert *svlist = sld->sv, *sv;
+ int i;
+
+ sv = svlist;
+
+ if (slp->use_even == false) {
+ for (i = 0; i < sld->totsv; i++, sv++) {
+ interp_v3_v3v3(sv->v->co, sv->co_orig_3d, sv->co_link_orig_3d[sv->co_link_curr], perc);
+ }
}
- }
- else {
- TransDataVertSlideVert *sv_curr = &sld->sv[sld->curr_sv_index];
- const float edge_len_curr = len_v3v3(sv_curr->co_orig_3d, sv_curr->co_link_orig_3d[sv_curr->co_link_curr]);
- const float tperc = perc * edge_len_curr;
+ else {
+ TransDataVertSlideVert *sv_curr = &sld->sv[sld->curr_sv_index];
+ const float edge_len_curr = len_v3v3(sv_curr->co_orig_3d, sv_curr->co_link_orig_3d[sv_curr->co_link_curr]);
+ const float tperc = perc * edge_len_curr;
- for (i = 0; i < sld->totsv; i++, sv++) {
- float edge_len;
- float dir[3];
+ for (i = 0; i < sld->totsv; i++, sv++) {
+ float edge_len;
+ float dir[3];
- sub_v3_v3v3(dir, sv->co_link_orig_3d[sv->co_link_curr], sv->co_orig_3d);
- edge_len = normalize_v3(dir);
+ sub_v3_v3v3(dir, sv->co_link_orig_3d[sv->co_link_curr], sv->co_orig_3d);
+ edge_len = normalize_v3(dir);
- if (edge_len > FLT_EPSILON) {
- if (sld->flipped) {
- madd_v3_v3v3fl(sv->v->co, sv->co_link_orig_3d[sv->co_link_curr], dir, -tperc);
+ if (edge_len > FLT_EPSILON) {
+ if (slp->flipped) {
+ madd_v3_v3v3fl(sv->v->co, sv->co_link_orig_3d[sv->co_link_curr], dir, -tperc);
+ }
+ else {
+ madd_v3_v3v3fl(sv->v->co, sv->co_orig_3d, dir, tperc);
+ }
}
else {
- madd_v3_v3v3fl(sv->v->co, sv->co_orig_3d, dir, tperc);
+ copy_v3_v3(sv->v->co, sv->co_orig_3d);
}
}
- else {
- copy_v3_v3(sv->v->co, sv->co_orig_3d);
- }
}
}
}
@@ -7587,9 +7760,9 @@ static void applyVertSlide(TransInfo *t, const int UNUSED(mval[2]))
char str[UI_MAX_DRAW_STR];
size_t ofs = 0;
float final;
- VertSlideData *sld = t->custom.mode.data;
- const bool flipped = sld->flipped;
- const bool use_even = sld->use_even;
+ VertSlideParams *slp = t->custom.mode.data;
+ const bool flipped = slp->flipped;
+ const bool use_even = slp->use_even;
const bool is_clamp = !(t->flag & T_ALT_TRANSFORM);
const bool is_constrained = !(is_clamp == false || hasNumInput(&t->num));
@@ -7662,7 +7835,6 @@ static void initBoneRoll(TransInfo *t)
static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
int i;
char str[UI_MAX_DRAW_STR];
@@ -7688,14 +7860,17 @@ static void applyBoneRoll(TransInfo *t, const int UNUSED(mval[2]))
}
/* set roll values */
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- *(td->val) = td->ival - final;
+ *(td->val) = td->ival - final;
+ }
}
recalcData(t);
@@ -7729,7 +7904,6 @@ static void initBakeTime(TransInfo *t)
static void applyBakeTime(TransInfo *t, const int mval[2])
{
- TransData *td = t->data;
float time;
int i;
char str[UI_MAX_DRAW_STR];
@@ -7773,17 +7947,20 @@ static void applyBakeTime(TransInfo *t, const int mval[2])
BLI_snprintf(str, sizeof(str), IFACE_("Time: %.3f %s"), time, t->proptext);
}
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- if (td->val) {
- *td->val = td->ival + time * td->factor;
- if (td->ext->size && *td->val < *td->ext->size) *td->val = *td->ext->size;
- if (td->ext->quat && *td->val > *td->ext->quat) *td->val = *td->ext->quat;
+ if (td->val) {
+ *td->val = td->ival + time * td->factor;
+ if (td->ext->size && *td->val < *td->ext->size) *td->val = *td->ext->size;
+ if (td->ext->quat && *td->val > *td->ext->quat) *td->val = *td->ext->quat;
+ }
}
}
@@ -7806,14 +7983,13 @@ static void initMirror(TransInfo *t)
initMouseInputMode(t, &t->mouse, INPUT_NONE);
t->flag |= T_NULL_ONE;
- if (!t->obedit) {
+ if ((t->flag & T_EDIT) == 0) {
t->flag |= T_NO_ZERO;
}
}
static void applyMirror(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td;
float size[3], mat[3][3];
int i;
char str[UI_MAX_DRAW_STR];
@@ -7831,19 +8007,22 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2]))
size_to_mat3(mat, size);
if (t->con.applySize) {
- t->con.applySize(t, NULL, mat);
+ t->con.applySize(t, NULL, NULL, mat);
}
BLI_snprintf(str, sizeof(str), IFACE_("Mirror%s"), t->con.text);
- for (i = 0, td = t->data; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- ElementResize(t, td, mat);
+ ElementResize(t, tc, td, mat);
+ }
}
recalcData(t);
@@ -7855,14 +8034,17 @@ static void applyMirror(TransInfo *t, const int UNUSED(mval[2]))
size_to_mat3(mat, size);
- for (i = 0, td = t->data; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- ElementResize(t, td, mat);
+ ElementResize(t, tc, td, mat);
+ }
}
recalcData(t);
@@ -7893,42 +8075,43 @@ static void initAlign(TransInfo *t)
static void applyAlign(TransInfo *t, const int UNUSED(mval[2]))
{
- TransData *td = t->data;
float center[3];
int i;
- /* saving original center */
- copy_v3_v3(center, t->center);
- for (i = 0; i < t->total; i++, td++) {
- float mat[3][3], invmat[3][3];
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ /* saving original center */
+ copy_v3_v3(center, tc->center_local);
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ float mat[3][3], invmat[3][3];
- if (td->flag & TD_NOACTION)
- break;
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- /* around local centers */
- if (t->flag & (T_OBJECT | T_POSE)) {
- copy_v3_v3(t->center, td->center);
- }
- else {
- if (t->settings->selectmode & SCE_SELECT_FACE) {
- copy_v3_v3(t->center, td->center);
+ /* around local centers */
+ if (t->flag & (T_OBJECT | T_POSE)) {
+ copy_v3_v3(tc->center_local, td->center);
+ }
+ else {
+ if (t->settings->selectmode & SCE_SELECT_FACE) {
+ copy_v3_v3(tc->center_local, td->center);
+ }
}
- }
- invert_m3_m3(invmat, td->axismtx);
+ invert_m3_m3(invmat, td->axismtx);
- mul_m3_m3m3(mat, t->spacemtx, invmat);
+ mul_m3_m3m3(mat, t->spacemtx, invmat);
- ElementRotation(t, td, mat, t->around);
+ ElementRotation(t, tc, td, mat, t->around);
+ }
+ /* restoring original center */
+ copy_v3_v3(tc->center_local, center);
}
- /* restoring original center */
- copy_v3_v3(t->center, center);
-
recalcData(t);
ED_area_headerprint(t->sa, IFACE_("Align"));
@@ -7989,17 +8172,19 @@ static void headerSeqSlide(TransInfo *t, const float val[2], char str[UI_MAX_DRA
static void applySeqSlideValue(TransInfo *t, const float val[2])
{
- TransData *td = t->data;
int i;
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if (td->flag & TD_SKIP)
- continue;
+ if (td->flag & TD_SKIP)
+ continue;
- madd_v2_v2v2fl(td->loc, td->iloc, val, td->factor);
+ madd_v2_v2v2fl(td->loc, td->iloc, val, td->factor);
+ }
}
}
@@ -8012,7 +8197,7 @@ static void applySeqSlide(TransInfo *t, const int mval[2])
if (t->con.mode & CON_APPLY) {
float pvec[3] = {0.0f, 0.0f, 0.0f};
float tvec[3];
- t->con.applyVec(t, NULL, t->values, tvec, pvec);
+ t->con.applyVec(t, NULL, NULL, t->values, tvec, pvec);
copy_v3_v3(t->values, tvec);
}
else {
@@ -8232,56 +8417,58 @@ static void headerTimeTranslate(TransInfo *t, char str[UI_MAX_DRAW_STR])
static void applyTimeTranslateValue(TransInfo *t)
{
- TransData *td = t->data;
- TransData2D *td2d = t->data2d;
Scene *scene = t->scene;
int i;
-
+
const short autosnap = getAnimEdit_SnapMode(t);
const double secf = FPS;
float deltax, val /* , valprev */;
- /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */
- for (i = 0; i < t->total; i++, td++, td2d++) {
- /* it is assumed that td->extra is a pointer to the AnimData,
- * whose active action is where this keyframe comes from
- * (this is only valid when not in NLA)
- */
- AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ TransData2D *td2d = tc->data_2d;
+ /* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */
+ for (i = 0; i < tc->data_len; i++, td++, td2d++) {
+ /* it is assumed that td->extra is a pointer to the AnimData,
+ * whose active action is where this keyframe comes from
+ * (this is only valid when not in NLA)
+ */
+ AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
- /* valprev = *td->val; */ /* UNUSED */
+ /* valprev = *td->val; */ /* UNUSED */
- /* check if any need to apply nla-mapping */
- if (adt && (t->spacetype != SPACE_SEQ)) {
- deltax = t->values[0];
+ /* check if any need to apply nla-mapping */
+ if (adt && (t->spacetype != SPACE_SEQ)) {
+ deltax = t->values[0];
- if (autosnap == SACTSNAP_TSTEP) {
- deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf);
- }
- else if (autosnap == SACTSNAP_STEP) {
- deltax = floorf(deltax + 0.5f);
+ if (autosnap == SACTSNAP_TSTEP) {
+ deltax = (float)(floor(((double)deltax / secf) + 0.5) * secf);
+ }
+ else if (autosnap == SACTSNAP_STEP) {
+ deltax = floorf(deltax + 0.5f);
+ }
+
+ val = BKE_nla_tweakedit_remap(adt, td->ival, NLATIME_CONVERT_MAP);
+ val += deltax * td->factor;
+ *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
}
+ else {
+ deltax = val = t->values[0];
- val = BKE_nla_tweakedit_remap(adt, td->ival, NLATIME_CONVERT_MAP);
- val += deltax * td->factor;
- *(td->val) = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_UNMAP);
- }
- else {
- deltax = val = t->values[0];
+ if (autosnap == SACTSNAP_TSTEP) {
+ val = (float)(floor(((double)deltax / secf) + 0.5) * secf);
+ }
+ else if (autosnap == SACTSNAP_STEP) {
+ val = floorf(val + 0.5f);
+ }
- if (autosnap == SACTSNAP_TSTEP) {
- val = (float)(floor(((double)deltax / secf) + 0.5) * secf);
- }
- else if (autosnap == SACTSNAP_STEP) {
- val = floorf(val + 0.5f);
+ *(td->val) = td->ival + val;
}
- *(td->val) = td->ival + val;
+ /* apply nearest snapping */
+ doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
}
-
- /* apply nearest snapping */
- doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
}
}
@@ -8348,18 +8535,19 @@ static void initTimeSlide(TransInfo *t)
float min = 999999999.0f, max = -999999999.0f;
int i;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
+ float val = *(td->val);
- TransData *td = t->data;
- for (i = 0; i < t->total; i++, td++) {
- AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
- float val = *(td->val);
-
- /* strip/action time to global (mapped) time */
- if (adt)
- val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP);
-
- if (min > val) min = val;
- if (max < val) max = val;
+ /* strip/action time to global (mapped) time */
+ if (adt)
+ val = BKE_nla_tweakedit_remap(adt, val, NLATIME_CONVERT_MAP);
+
+ if (min > val) min = val;
+ if (max < val) max = val;
+ }
}
if (min == max) {
@@ -8412,7 +8600,6 @@ static void headerTimeSlide(TransInfo *t, const float sval, char str[UI_MAX_DRAW
static void applyTimeSlideValue(TransInfo *t, float sval)
{
- TransData *td = t->data;
int i;
const float *range = t->custom.mode.data;
float minx = range[0];
@@ -8427,44 +8614,47 @@ static void applyTimeSlideValue(TransInfo *t, float sval)
}
/* it doesn't matter whether we apply to t->data or t->data2d, but t->data2d is more convenient */
- for (i = 0; i < t->total; i++, td++) {
- /* it is assumed that td->extra is a pointer to the AnimData,
- * whose active action is where this keyframe comes from
- * (this is only valid when not in NLA)
- */
- AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
- float cval = t->values[0];
-
- /* only apply to data if in range */
- if ((sval > minx) && (sval < maxx)) {
- float cvalc = CLAMPIS(cval, minx, maxx);
- float ival = td->ival;
- float timefac;
-
- /* NLA mapping magic here works as follows:
- * - "ival" goes from strip time to global time
- * - calculation is performed into td->val in global time
- * (since sval and min/max are all in global time)
- * - "td->val" then gets put back into strip time
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ /* it is assumed that td->extra is a pointer to the AnimData,
+ * whose active action is where this keyframe comes from
+ * (this is only valid when not in NLA)
*/
- if (adt) {
- /* strip to global */
- ival = BKE_nla_tweakedit_remap(adt, ival, NLATIME_CONVERT_MAP);
- }
-
- /* left half? */
- if (ival < sval) {
- timefac = (sval - ival) / (sval - minx);
- *(td->val) = cvalc - timefac * (cvalc - minx);
- }
- else {
- timefac = (ival - sval) / (maxx - sval);
- *(td->val) = cvalc + timefac * (maxx - cvalc);
- }
-
- if (adt) {
- /* global to strip */
- *(td->val) = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_UNMAP);
+ AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
+ float cval = t->values[0];
+
+ /* only apply to data if in range */
+ if ((sval > minx) && (sval < maxx)) {
+ float cvalc = CLAMPIS(cval, minx, maxx);
+ float ival = td->ival;
+ float timefac;
+
+ /* NLA mapping magic here works as follows:
+ * - "ival" goes from strip time to global time
+ * - calculation is performed into td->val in global time
+ * (since sval and min/max are all in global time)
+ * - "td->val" then gets put back into strip time
+ */
+ if (adt) {
+ /* strip to global */
+ ival = BKE_nla_tweakedit_remap(adt, ival, NLATIME_CONVERT_MAP);
+ }
+
+ /* left half? */
+ if (ival < sval) {
+ timefac = (sval - ival) / (sval - minx);
+ *(td->val) = cvalc - timefac * (cvalc - minx);
+ }
+ else {
+ timefac = (ival - sval) / (maxx - sval);
+ *(td->val) = cvalc + timefac * (maxx - cvalc);
+ }
+
+ if (adt) {
+ /* global to strip */
+ *(td->val) = BKE_nla_tweakedit_remap(adt, *(td->val), NLATIME_CONVERT_UNMAP);
+ }
}
}
}
@@ -8525,8 +8715,8 @@ static void initTimeScale(TransInfo *t)
/* recalculate center2d to use CFRA and mouse Y, since that's
* what is used in time scale */
if ((t->flag & T_OVERRIDE_CENTER) == 0) {
- t->center[0] = t->scene->r.cfra;
- projectFloatView(t, t->center, center);
+ t->center_global[0] = t->scene->r.cfra;
+ projectFloatView(t, t->center_global, center);
center[1] = t->mouse.imval[1];
}
@@ -8567,39 +8757,40 @@ static void headerTimeScale(TransInfo *t, char str[UI_MAX_DRAW_STR])
static void applyTimeScaleValue(TransInfo *t)
{
Scene *scene = t->scene;
- TransData *td = t->data;
- TransData2D *td2d = t->data2d;
int i;
const short autosnap = getAnimEdit_SnapMode(t);
const double secf = FPS;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ TransData2D *td2d = tc->data_2d;
+ for (i = 0; i < tc->data_len; i++, td++, td2d++) {
+ /* it is assumed that td->extra is a pointer to the AnimData,
+ * whose active action is where this keyframe comes from
+ * (this is only valid when not in NLA)
+ */
+ AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
+ float startx = CFRA;
+ float fac = t->values[0];
- for (i = 0; i < t->total; i++, td++, td2d++) {
- /* it is assumed that td->extra is a pointer to the AnimData,
- * whose active action is where this keyframe comes from
- * (this is only valid when not in NLA)
- */
- AnimData *adt = (t->spacetype != SPACE_NLA) ? td->extra : NULL;
- float startx = CFRA;
- float fac = t->values[0];
-
- if (autosnap == SACTSNAP_TSTEP) {
- fac = (float)(floor((double)fac / secf + 0.5) * secf);
- }
- else if (autosnap == SACTSNAP_STEP) {
- fac = floorf(fac + 0.5f);
- }
+ if (autosnap == SACTSNAP_TSTEP) {
+ fac = (float)(floor((double)fac / secf + 0.5) * secf);
+ }
+ else if (autosnap == SACTSNAP_STEP) {
+ fac = floorf(fac + 0.5f);
+ }
- /* check if any need to apply nla-mapping */
- if (adt)
- startx = BKE_nla_tweakedit_remap(adt, startx, NLATIME_CONVERT_UNMAP);
+ /* check if any need to apply nla-mapping */
+ if (adt)
+ startx = BKE_nla_tweakedit_remap(adt, startx, NLATIME_CONVERT_UNMAP);
- /* now, calculate the new value */
- *(td->val) = ((td->ival - startx) * fac) + startx;
+ /* now, calculate the new value */
+ *(td->val) = ((td->ival - startx) * fac) + startx;
- /* apply nearest snapping */
- doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
+ /* apply nearest snapping */
+ doAnimEdit_SnapFrame(t, td, td2d, adt, autosnap);
+ }
}
}
@@ -8628,7 +8819,7 @@ bool checkUseAxisMatrix(TransInfo *t)
/* currently only checks for editmode */
if (t->flag & T_EDIT) {
if ((t->around == V3D_AROUND_LOCAL_ORIGINS) &&
- (ELEM(t->obedit->type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)))
+ (ELEM(t->obedit_type, OB_MESH, OB_CURVE, OB_MBALL, OB_ARMATURE)))
{
/* not all editmode supports axis-matrix */
return true;
diff --git a/source/blender/editors/transform/transform.h b/source/blender/editors/transform/transform.h
index 06a60456cdb..7686431d808 100644
--- a/source/blender/editors/transform/transform.h
+++ b/source/blender/editors/transform/transform.h
@@ -37,11 +37,17 @@
#include "ED_numinput.h"
#include "ED_view3d.h"
+#include "RE_engine.h"
+
#include "DNA_listBase.h"
+#include "DEG_depsgraph.h"
+
/* ************************** Types ***************************** */
+struct Depsgraph;
struct TransInfo;
+struct TransDataContainer;
struct TransData;
struct TransformOrientation;
struct TransSnap;
@@ -50,6 +56,7 @@ struct Object;
struct View3D;
struct ScrArea;
struct Scene;
+struct ViewLayer;
struct bConstraint;
struct wmKeyMap;
struct wmKeyConfig;
@@ -59,8 +66,11 @@ struct wmTimer;
struct ARegion;
struct ReportList;
struct EditBone;
+struct RenderEngineType;
struct SnapObjectContext;
+#include "DNA_object_enums.h"
+
/* transinfo->redraw */
typedef enum {
TREDRAW_NOTHING = 0,
@@ -100,7 +110,7 @@ typedef struct TransSnap {
* \note Return value can be anything,
* where the smallest absolute value defines whats closest.
*/
- float (*distance)(struct TransInfo *, const float p1[3], const float p2[3]);
+ float (*distance)(struct TransInfo *t, const float p1[3], const float p2[3]);
/**
* Re-usable snap context data.
@@ -118,14 +128,16 @@ typedef struct TransCon {
/* the one in TransInfo is not garanty to stay the same (Rotates change it) */
int mode; /* Mode flags of the Constraint */
void (*drawExtra)(struct TransInfo *t);
+
+ /* Note: if 'tc' is NULL, 'td' must also be NULL. */
/* For constraints that needs to draw differently from the other
* uses this instead of the generic draw function */
- void (*applyVec)(struct TransInfo *t, struct TransData *td, const float in[3], float out[3], float pvec[3]);
+ void (*applyVec)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, const float in[3], float out[3], float pvec[3]);
/* Apply function pointer for linear vectorial transformation */
/* The last three parameters are pointers to the in/out/printable vectors */
- void (*applySize)(struct TransInfo *t, struct TransData *td, float smat[3][3]);
+ void (*applySize)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, float smat[3][3]);
/* Apply function pointer for size transformation */
- void (*applyRot)(struct TransInfo *t, struct TransData *td, float vec[3], float *angle);
+ void (*applyRot)(struct TransInfo *t, struct TransDataContainer *tc, struct TransData *td, float vec[3], float *angle);
/* Apply function pointer for rotation transformation */
} TransCon;
@@ -261,10 +273,6 @@ typedef struct EdgeSlideData {
SlideOrigData orig_data;
- float perc;
-
- bool use_even;
- bool flipped;
int curr_sv_index;
@@ -272,6 +280,12 @@ typedef struct EdgeSlideData {
int curr_side_unclamp;
} EdgeSlideData;
+typedef struct EdgeSlideParams {
+ float perc;
+
+ bool use_even;
+ bool flipped;
+} EdgeSlideParams;
typedef struct TransDataVertSlideVert {
/* TransDataGenericSlideVert */
@@ -293,17 +307,19 @@ typedef struct VertSlideData {
SlideOrigData orig_data;
- float perc;
-
- bool use_even;
- bool flipped;
-
int curr_sv_index;
/* result of ED_view3d_ob_project_mat_get */
float proj_mat[4][4];
} VertSlideData;
+typedef struct VertSlideParams {
+ float perc;
+
+ bool use_even;
+ bool flipped;
+} VertSlideParams;
+
typedef struct BoneInitData {
struct EditBone *bone;
float tail[3];
@@ -364,16 +380,80 @@ typedef struct MouseInput {
typedef struct TransCustomData {
void *data;
- void (*free_cb)(struct TransInfo *, struct TransCustomData *);
+ void (*free_cb)(struct TransInfo *, struct TransDataContainer *tc, struct TransCustomData *custom_data);
unsigned int use_free : 1;
} TransCustomData;
typedef struct TransCenterData {
- float local[3], global[3];
+ float global[3];
unsigned int is_set : 1;
} TransCenterData;
+/**
+ * Rule of thumb for choosing between mode/type:
+ * - If transform mode uses the data, assign to `mode`
+ * (typically in transform.c).
+ * - If conversion uses the data as an extension to the #TransData, assign to `type`
+ * (typically in transform_conversion.c).
+ */
+typedef struct TransCustomDataContainer {
+ /** Owned by the mode (grab, scale, bend... ).*/
+ union {
+ TransCustomData mode, first_elem;
+ };
+ TransCustomData type;
+} TransCustomDataContainer;
+#define TRANS_CUSTOM_DATA_ELEM_MAX (sizeof(TransCustomDataContainer) / sizeof(TransCustomData))
+
+typedef struct TransDataContainer {
+ /**
+ * Use for cases we care about the active, eg: active vert of active mesh.
+ * if set this will _always_ be the first item in the array.
+ */
+ bool is_active;
+
+ /** Transformed data (array). */
+ TransData *data;
+ /** Total number of transformed data. */
+ int data_len;
+
+ /** Transformed data extension (array). */
+ TransDataExtension *data_ext;
+ /** Transformed data for 2d (array). */
+ TransData2D *data_2d;
+
+ struct Object *obedit;
+
+ /**
+ * Use when #T_LOCAL_MATRIX is set.
+ * Typically: 'obedit->obmat' or 'poseobj->obmat', but may be used elsewhere too.
+ */
+ bool use_local_mat;
+ float mat[4][4];
+ float imat[4][4];
+ /** 3x3 copies of matrices above. */
+ float mat3[3][3];
+ float imat3[3][3];
+
+ /** Normalized 'mat3' */
+ float mat3_unit[3][3];
+
+ /** if 't->flag & T_POSE', this denotes pose object */
+ struct Object *poseobj;
+
+ /** Center of transformation (in local-space), Calculated from #TransInfo.center_global. */
+ float center_local[3];
+
+ TransCustomDataContainer custom;
+} TransDataContainer;
+
typedef struct TransInfo {
+ TransDataContainer *data_container;
+ int data_container_len;
+ /** Combine length of all #TransDataContainer.data_len
+ * Use to check if nothing is selected or if we have a single selection. */
+ int data_len_all;
+
int mode; /* current mode */
int flag; /* generic flags for special behaviors */
int modifiers; /* special modifiers, by function, not key */
@@ -384,10 +464,6 @@ typedef struct TransInfo {
/* transform function pointer */
eRedrawFlag (*handleEvent)(struct TransInfo *, const struct wmEvent *);
/* event handler function pointer RETURN 1 if redraw is needed */
- int total; /* total number of transformed data */
- TransData *data; /* transformed data (array) */
- TransDataExtension *ext; /* transformed data extension (array) */
- TransData2D *data2d; /* transformed data for 2d (array) */
TransCon con; /* transformed constraint */
TransSnap tsnap;
NumInput num; /* numerical input */
@@ -397,7 +473,6 @@ typedef struct TransInfo {
char proptext[20]; /* proportional falloff text */
float aspect[3]; /* spaces using non 1:1 aspect, (uv's, f-curve, movie-clip... etc)
* use for conversion and snapping. */
- float center[3]; /* center of transformation (in local-space) */
float center_global[3]; /* center of transformation (in global-space) */
float center2d[2]; /* center in screen coordinates */
/* Lazy initialize center data for when we need other center values.
@@ -415,7 +490,8 @@ typedef struct TransInfo {
short persp;
short around;
char spacetype; /* spacetype where transforming is */
- char helpline; /* helpline modes (not to be confused with hotline) */
+ char helpline; /* Choice of custom cursor with or without a help line from the manipulator to the mouse position. */
+ short obedit_type; /* Avoid looking inside TransDataContainer obedit. */
float vec[3]; /* translation, to show for widget */
float mat[3][3]; /* rot/rescale, to show for widget */
@@ -423,36 +499,19 @@ typedef struct TransInfo {
float spacemtx[3][3]; /* orientation matrix of the current space */
char spacename[64]; /* name of the current space, MAX_NAME */
- struct Object *poseobj; /* if t->flag & T_POSE, this denotes pose object */
-
- /**
- * Rule of thumb for choosing between mode/type:
- * - If transform mode uses the data, assign to `mode`
- * (typically in transform.c).
- * - If conversion uses the data as an extension to the #TransData, assign to `type`
- * (typically in transform_conversion.c).
- */
- struct {
- /* owned by the mode (grab, scale, bend... )*/
- union {
- TransCustomData mode, first_elem;
- };
- /* owned by the type (mesh, armature, nla...) */
- TransCustomData type;
- } custom;
-#define TRANS_CUSTOM_DATA_ELEM_MAX (sizeof(((TransInfo *)NULL)->custom) / sizeof(TransCustomData))
-
/*************** NEW STUFF *********************/
short launch_event; /* event type used to launch transform */
short current_orientation;
- short twtype; /* backup from view3d, to restore on end */
+ TransformOrientation *custom_orientation; /* this gets used when current_orientation is V3D_MANIP_CUSTOM */
+ short twflag; /* backup from view3d, to restore on end */
short prop_mode;
short mirror;
float values[4];
+ float values_modal_offset[4]; /* Offset applied ontop of modal input. */
float auto_values[4];
float axis[3];
float axis_orig[3]; /* TransCon can change 'axis', store the original value here */
@@ -463,19 +522,22 @@ typedef struct TransInfo {
struct bContext *context; /* Only valid (non null) during an operator called function. */
struct ScrArea *sa;
struct ARegion *ar;
+ struct Depsgraph *depsgraph;
struct Scene *scene;
+ struct ViewLayer *view_layer;
struct ToolSettings *settings;
struct wmTimer *animtimer;
struct wmKeyMap *keymap; /* so we can do lookups for header text */
struct ReportList *reports; /* assign from the operator, or can be NULL */
int mval[2]; /* current mouse position */
float zfac; /* use for 3d view */
- struct Object *obedit;
- float obedit_mat[3][3]; /* normalized editmode matrix (T_EDIT only) */
void *draw_handle_apply;
void *draw_handle_view;
void *draw_handle_pixel;
void *draw_handle_cursor;
+
+ /** Typically for mode settings. */
+ TransCustomDataContainer custom;
} TransInfo;
@@ -496,8 +558,10 @@ typedef struct TransInfo {
#define T_CAMERA (1 << 4)
// trans on points, having no rotation/scale
#define T_POINTS (1 << 6)
- // for manipulator exceptions, like scaling using center point, drawing help lines
-#define T_USES_MANIPULATOR (1 << 7)
+/**
+ * Apply matrix #TransDataContainer.matrix, this avoids having to have duplicate check all over
+ * that happen to apply to spesiifc modes (edit & pose for eg). */
+#define T_LOCAL_MATRIX (1 << 7)
/* restrictions flags */
#define T_ALL_RESTRICTIONS ((1 << 8)|(1 << 9)|(1 << 10))
@@ -635,10 +699,14 @@ void flushTransSeq(TransInfo *t);
void flushTransTracking(TransInfo *t);
void flushTransMasking(TransInfo *t);
void flushTransPaintCurve(TransInfo *t);
-void restoreBones(TransInfo *t);
+void restoreBones(TransDataContainer *tc);
-/*********************** exported from transform_manipulator.c ********** */
-bool gimbal_axis(struct Object *ob, float gmat[3][3]); /* return 0 when no gimbal for selection */
+/*********************** transform_manipulator.c ********** */
+
+#define MANIPULATOR_AXIS_LINE_WIDTH 2.0f
+
+/* return 0 when no gimbal for selection */
+bool gimbal_axis(struct Object *ob, float gmat[3][3]);
/*********************** TransData Creation and General Handling *********** */
void createTransData(struct bContext *C, TransInfo *t);
@@ -652,7 +720,7 @@ bool transdata_check_local_islands(TransInfo *t, short around);
int count_set_pose_transflags(int *out_mode, short around, struct Object *ob);
/* auto-keying stuff used by special_aftertrans_update */
-void autokeyframe_ob_cb_func(struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode);
+void autokeyframe_ob_cb_func(struct bContext *C, struct Scene *scene, struct ViewLayer *view_layer, struct View3D *v3d, struct Object *ob, int tmode);
void autokeyframe_pose_cb_func(struct bContext *C, struct Scene *scene, struct View3D *v3d, struct Object *ob, int tmode, short targetless_ik);
/*********************** Constraints *****************************/
@@ -741,7 +809,9 @@ void setInputPostFct(MouseInput *mi, void (*post)(struct TransInfo *t, float val
/*********************** Generics ********************************/
+void initTransDataContainers_FromObjectData(TransInfo *t);
void initTransInfo(struct bContext *C, TransInfo *t, struct wmOperator *op, const struct wmEvent *event);
+void freeTransCustomDataForMode(TransInfo *t);
void postTrans(struct bContext *C, TransInfo *t);
void resetTransModal(TransInfo *t);
void resetTransRestrictions(TransInfo *t);
@@ -756,9 +826,7 @@ void restoreTransObjects(TransInfo *t);
void recalcData(TransInfo *t);
void calculateCenter2D(TransInfo *t);
-void calculateCenterGlobal(
- TransInfo *t, const float center_local[3],
- float r_center_global[3]);
+void calculateCenterLocal(TransInfo *t, const float center_global[3]);
const TransCenterData *transformCenter_from_type(TransInfo *t, int around);
void calculateCenter(TransInfo *t);
@@ -787,7 +855,7 @@ bool createSpaceNormalTangent(float mat[3][3], const float normal[3], const floa
struct TransformOrientation *addMatrixSpace(struct bContext *C, float mat[3][3],
const char *name, const bool overwrite);
-bool applyTransformOrientation(const struct bContext *C, float mat[3][3], char r_name[64], int index);
+bool applyTransformOrientation(const struct TransformOrientation *ts, float r_mat[3][3], char r_name[64]);
#define ORIENTATION_NONE 0
#define ORIENTATION_NORMAL 1
@@ -799,11 +867,11 @@ int getTransformOrientation_ex(const struct bContext *C, float normal[3], float
int getTransformOrientation(const struct bContext *C, float normal[3], float plane[3]);
void freeEdgeSlideTempFaces(EdgeSlideData *sld);
-void freeEdgeSlideVerts(TransInfo *t, TransCustomData *custom_data);
+void freeEdgeSlideVerts(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data);
void projectEdgeSlideData(TransInfo *t, bool is_final);
void freeVertSlideTempFaces(VertSlideData *sld);
-void freeVertSlideVerts(TransInfo *t, TransCustomData *custom_data);
+void freeVertSlideVerts(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data);
void projectVertSlideData(TransInfo *t, bool is_final);
@@ -814,4 +882,22 @@ bool checkUseAxisMatrix(TransInfo *t);
#define TRANSFORM_SNAP_MAX_PX 100.0f
#define TRANSFORM_DIST_INVALID -FLT_MAX
+/* Temp macros. */
+
+/* This is to be replaced, just to get things compiling early on. */
+#define TRANS_DATA_CONTAINER_FIRST_EVIL(t) (&(t)->data_container[0])
+#define TRANS_DATA_CONTAINER_FIRST_OK(t) (&(t)->data_container[0])
+/* For cases we _know_ there is only one handle. */
+#define TRANS_DATA_CONTAINER_FIRST_SINGLE(t) (BLI_assert((t)->data_container_len == 1), (&(t)->data_container[0]))
+
+#define FOREACH_TRANS_DATA_CONTAINER(t, th) \
+ for (TransDataContainer *tc = t->data_container, *tc_end = t->data_container + t->data_container_len; \
+ th != tc_end; \
+ th++)
+
+#define FOREACH_TRANS_DATA_CONTAINER_INDEX(t, th, i) \
+ for (TransDataContainer *tc = ((i = 0), t->data_container), *tc_end = t->data_container + t->data_container_len; \
+ th != tc_end; \
+ th++, i++)
+
#endif
diff --git a/source/blender/editors/transform/transform_constraints.c b/source/blender/editors/transform/transform_constraints.c
index 08bd36fe95c..bd03c0cedba 100644
--- a/source/blender/editors/transform/transform_constraints.c
+++ b/source/blender/editors/transform/transform_constraints.c
@@ -40,9 +40,11 @@
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "BLI_string.h"
@@ -331,7 +333,8 @@ static void planeProjection(TransInfo *t, const float in[3], float out[3])
*
*/
-static void applyAxisConstraintVec(TransInfo *t, TransData *td, const float in[3], float out[3], float pvec[3])
+static void applyAxisConstraintVec(
+ TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, const float in[3], float out[3], float pvec[3])
{
copy_v3_v3(out, in);
if (!td && t->con.mode & CON_APPLY) {
@@ -378,7 +381,8 @@ static void applyAxisConstraintVec(TransInfo *t, TransData *td, const float in[3
* Further down, that vector is mapped to each data's space.
*/
-static void applyObjectConstraintVec(TransInfo *t, TransData *td, const float in[3], float out[3], float pvec[3])
+static void applyObjectConstraintVec(
+ TransInfo *t, TransDataContainer *tc, TransData *td, const float in[3], float out[3], float pvec[3])
{
copy_v3_v3(out, in);
if (t->con.mode & CON_APPLY) {
@@ -426,7 +430,7 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, const float in
mul_m3_v3(td->axismtx, out);
if (t->flag & T_EDIT) {
- mul_m3_v3(t->obedit_mat, out);
+ mul_m3_v3(tc->mat3_unit, out);
}
}
}
@@ -436,7 +440,8 @@ static void applyObjectConstraintVec(TransInfo *t, TransData *td, const float in
* Generic callback for constant spatial constraints applied to resize motion
*/
-static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3])
+static void applyAxisConstraintSize(
+ TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float smat[3][3])
{
if (!td && t->con.mode & CON_APPLY) {
float tmat[3][3];
@@ -460,7 +465,8 @@ static void applyAxisConstraintSize(TransInfo *t, TransData *td, float smat[3][3
* Callback for object based spatial constraints applied to resize motion
*/
-static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3][3])
+static void applyObjectConstraintSize(
+ TransInfo *t, TransDataContainer *tc, TransData *td, float smat[3][3])
{
if (td && t->con.mode & CON_APPLY) {
float tmat[3][3];
@@ -480,7 +486,7 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3]
mul_m3_m3m3(tmat, smat, imat);
if (t->flag & T_EDIT) {
- mul_m3_m3m3(smat, t->obedit_mat, smat);
+ mul_m3_m3m3(smat, tc->mat3_unit, smat);
}
mul_m3_m3m3(smat, td->axismtx, tmat);
}
@@ -500,7 +506,7 @@ static void applyObjectConstraintSize(TransInfo *t, TransData *td, float smat[3]
* (ie: not doing counterclockwise rotations when the mouse moves clockwise).
*/
-static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], float *angle)
+static void applyAxisConstraintRot(TransInfo *t, TransDataContainer *UNUSED(tc), TransData *td, float vec[3], float *angle)
{
if (!td && t->con.mode & CON_APPLY) {
int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2);
@@ -542,7 +548,8 @@ static void applyAxisConstraintRot(TransInfo *t, TransData *td, float vec[3], fl
* (ie: not doing counterclockwise rotations when the mouse moves clockwise).
*/
-static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3], float *angle)
+static void applyObjectConstraintRot(
+ TransInfo *t, TransDataContainer *tc, TransData *td, float vec[3], float *angle)
{
if (t->con.mode & CON_APPLY) {
int mode = t->con.mode & (CON_AXIS0 | CON_AXIS1 | CON_AXIS2);
@@ -551,11 +558,11 @@ static void applyObjectConstraintRot(TransInfo *t, TransData *td, float vec[3],
/* on setup call, use first object */
if (td == NULL) {
- td = t->data;
+ td = tc->data;
}
if (t->flag & T_EDIT) {
- mul_m3_m3m3(tmp_axismtx, t->obedit_mat, td->axismtx);
+ mul_m3_m3m3(tmp_axismtx, tc->mat3_unit, td->axismtx);
axismtx = tmp_axismtx;
}
else {
@@ -605,20 +612,21 @@ void setConstraint(TransInfo *t, float space[3][3], int mode, const char text[])
/* applies individual td->axismtx constraints */
void setAxisMatrixConstraint(TransInfo *t, int mode, const char text[])
{
- if (t->total == 1) {
+ TransDataContainer *tc = t->data_container;
+ if (t->data_len_all == 1) {
float axismtx[3][3];
if (t->flag & T_EDIT) {
- mul_m3_m3m3(axismtx, t->obedit_mat, t->data->axismtx);
+ mul_m3_m3m3(axismtx, tc->mat3_unit, tc->data->axismtx);
}
else {
- copy_m3_m3(axismtx, t->data->axismtx);
+ copy_m3_m3(axismtx, tc->data->axismtx);
}
setConstraint(t, axismtx, mode, text);
}
else {
BLI_strncpy(t->con.text + 1, text, sizeof(t->con.text) - 1);
- copy_m3_m3(t->con.mtx, t->data->axismtx);
+ copy_m3_m3(t->con.mtx, tc->data->axismtx);
t->con.mode = mode;
getConstraintMatrix(t);
@@ -636,7 +644,9 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[])
{
/* edit-mode now allows local transforms too */
if (t->flag & T_EDIT) {
- setConstraint(t, t->obedit_mat, mode, text);
+ /* Use the active (first) edit object. */
+ TransDataContainer *tc = t->data_container;
+ setConstraint(t, tc->mat3_unit, mode, text);
}
else {
setAxisMatrixConstraint(t, mode, text);
@@ -651,7 +661,7 @@ void setLocalConstraint(TransInfo *t, int mode, const char text[])
*/
void setUserConstraint(TransInfo *t, short orientation, int mode, const char ftext[])
{
- char text[40];
+ char text[256];
switch (orientation) {
case V3D_MANIP_GLOBAL:
@@ -683,10 +693,15 @@ void setUserConstraint(TransInfo *t, short orientation, int mode, const char fte
BLI_snprintf(text, sizeof(text), ftext, IFACE_("gimbal"));
setConstraint(t, t->spacemtx, mode, text);
break;
- default: /* V3D_MANIP_CUSTOM */
- BLI_snprintf(text, sizeof(text), ftext, t->spacename);
+ case V3D_MANIP_CUSTOM:
+ {
+ char orientation_str[128];
+ BLI_snprintf(orientation_str, sizeof(orientation_str), "%s \"%s\"",
+ IFACE_("custom orientation"), t->custom_orientation->name);
+ BLI_snprintf(text, sizeof(text), ftext, orientation_str);
setConstraint(t, t->spacemtx, mode, text);
break;
+ }
}
t->con.orientation = orientation;
@@ -704,8 +719,6 @@ void drawConstraint(TransInfo *t)
return;
if (!(tc->mode & CON_APPLY))
return;
- if (t->flag & T_USES_MANIPULATOR)
- return;
if (t->flag & T_NO_CONSTRAINT)
return;
@@ -715,7 +728,6 @@ void drawConstraint(TransInfo *t)
else {
if (tc->mode & CON_SELECT) {
float vec[3];
- char col2[3] = {255, 255, 255};
int depth_test_enabled;
convertViewVec(t, vec, (t->mval[0] - t->con.imval[0]), (t->mval[1] - t->con.imval[1]));
@@ -725,18 +737,29 @@ void drawConstraint(TransInfo *t)
drawLine(t, t->center_global, tc->mtx[1], 'Y', 0);
drawLine(t, t->center_global, tc->mtx[2], 'Z', 0);
- glColor3ubv((GLubyte *)col2);
-
depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
if (depth_test_enabled)
glDisable(GL_DEPTH_TEST);
- setlinestyle(1);
- glBegin(GL_LINES);
- glVertex3fv(t->center_global);
- glVertex3fv(vec);
- glEnd();
- setlinestyle(0);
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 1.0f);
+ immUniform1f("dash_width", 2.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex3fv(shdr_pos, t->center_global);
+ immVertex3fv(shdr_pos, vec);
+ immEnd();
+
+ immUnbindProgram();
if (depth_test_enabled)
glEnable(GL_DEPTH_TEST);
@@ -762,8 +785,6 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
float tmat[4][4], imat[4][4];
int depth_test_enabled;
- UI_ThemeColor(TH_GRID);
-
if (t->spacetype == SPACE_VIEW3D && rv3d != NULL) {
copy_m4_m4(tmat, rv3d->viewmat);
invert_m4_m4(imat, tmat);
@@ -773,13 +794,13 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
unit_m4(imat);
}
- glPushMatrix();
+ gpuPushMatrix();
if (t->spacetype == SPACE_VIEW3D) {
/* pass */
}
else if (t->spacetype == SPACE_IMAGE) {
- glScalef(1.0f / t->aspect[0], 1.0f / t->aspect[1], 1.0f);
+ gpuScale2f(1.0f / t->aspect[0], 1.0f / t->aspect[1]);
}
else if (ELEM(t->spacetype, SPACE_IPO, SPACE_ACTION)) {
/* only scale y */
@@ -789,21 +810,28 @@ void drawPropCircle(const struct bContext *C, TransInfo *t)
float ysize = BLI_rctf_size_y(datamask);
float xmask = BLI_rcti_size_x(mask);
float ymask = BLI_rcti_size_y(mask);
- glScalef(1.0f, (ysize / xsize) * (xmask / ymask), 1.0f);
+ gpuScale2f(1.0f, (ysize / xsize) * (xmask / ymask));
}
depth_test_enabled = glIsEnabled(GL_DEPTH_TEST);
if (depth_test_enabled)
glDisable(GL_DEPTH_TEST);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformThemeColor(TH_GRID);
+
set_inverted_drawing(1);
- drawcircball(GL_LINE_LOOP, t->center_global, t->prop_size, imat);
+ imm_drawcircball(t->center_global, t->prop_size, imat, pos);
set_inverted_drawing(0);
+ immUnbindProgram();
+
if (depth_test_enabled)
glEnable(GL_DEPTH_TEST);
- glPopMatrix();
+ gpuPopMatrix();
}
}
@@ -816,57 +844,59 @@ static void drawObjectConstraint(TransInfo *t)
* Without drawing the first light, users have little clue what they are doing.
*/
short options = DRAWLIGHT;
- TransData *td = t->data;
int i;
float tmp_axismtx[3][3];
- for (i = 0; i < t->total; i++, td++) {
- float co[3];
- float (*axismtx)[3];
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ float co[3];
+ float (*axismtx)[3];
- if (t->flag & T_PROP_EDIT) {
- /* we're sorted, so skip the rest */
- if (td->factor == 0.0f) {
- break;
+ if (t->flag & T_PROP_EDIT) {
+ /* we're sorted, so skip the rest */
+ if (td->factor == 0.0f) {
+ break;
+ }
}
- }
- if (t->options & CTX_GPENCIL_STROKES) {
- /* only draw a constraint line for one point, otherwise we can't see anything */
- if ((options & DRAWLIGHT) == 0) {
- break;
+ if (t->options & CTX_GPENCIL_STROKES) {
+ /* only draw a constraint line for one point, otherwise we can't see anything */
+ if ((options & DRAWLIGHT) == 0) {
+ break;
+ }
}
- }
- if (t->flag & T_OBJECT) {
- copy_v3_v3(co, td->ob->obmat[3]);
- axismtx = td->axismtx;
- }
- else if (t->flag & T_EDIT) {
- mul_v3_m4v3(co, t->obedit->obmat, td->center);
+ if (t->flag & T_OBJECT) {
+ copy_v3_v3(co, td->ob->obmat[3]);
+ axismtx = td->axismtx;
+ }
+ else if (t->flag & T_EDIT) {
+ mul_v3_m4v3(co, tc->mat, td->center);
- mul_m3_m3m3(tmp_axismtx, t->obedit_mat, td->axismtx);
- axismtx = tmp_axismtx;
- }
- else if (t->flag & T_POSE) {
- mul_v3_m4v3(co, t->poseobj->obmat, td->center);
- axismtx = td->axismtx;
- }
- else {
- copy_v3_v3(co, td->center);
- axismtx = td->axismtx;
- }
+ mul_m3_m3m3(tmp_axismtx, tc->mat3_unit, td->axismtx);
+ axismtx = tmp_axismtx;
+ }
+ else if (t->flag & T_POSE) {
+ mul_v3_m4v3(co, tc->mat, td->center);
+ axismtx = td->axismtx;
+ }
+ else {
+ copy_v3_v3(co, td->center);
+ axismtx = td->axismtx;
+ }
- if (t->con.mode & CON_AXIS0) {
- drawLine(t, co, axismtx[0], 'X', options);
- }
- if (t->con.mode & CON_AXIS1) {
- drawLine(t, co, axismtx[1], 'Y', options);
- }
- if (t->con.mode & CON_AXIS2) {
- drawLine(t, co, axismtx[2], 'Z', options);
+ if (t->con.mode & CON_AXIS0) {
+ drawLine(t, co, axismtx[0], 'X', options);
+ }
+ if (t->con.mode & CON_AXIS1) {
+ drawLine(t, co, axismtx[1], 'Y', options);
+ }
+ if (t->con.mode & CON_AXIS2) {
+ drawLine(t, co, axismtx[2], 'Z', options);
+ }
+ options &= ~DRAWLIGHT;
}
- options &= ~DRAWLIGHT;
}
}
diff --git a/source/blender/editors/transform/transform_conversions.c b/source/blender/editors/transform/transform_conversions.c
index 60092a28e36..14dd147c309 100644
--- a/source/blender/editors/transform/transform_conversions.c
+++ b/source/blender/editors/transform/transform_conversions.c
@@ -68,10 +68,10 @@
#include "BKE_context.h"
#include "BKE_crazyspace.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_global.h"
#include "BKE_gpencil.h"
+#include "BKE_layer.h"
#include "BKE_key.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
@@ -118,6 +118,8 @@
#include "RNA_access.h"
#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
#include "transform.h"
#include "bmesh.h"
@@ -128,7 +130,7 @@
*/
static void transform_around_single_fallback(TransInfo *t)
{
- if ((t->total == 1) &&
+ if ((t->data_len_all == 1) &&
(ELEM(t->around, V3D_AROUND_CENTER_BOUNDS, V3D_AROUND_CENTER_MEAN, V3D_AROUND_ACTIVE)) &&
(ELEM(t->mode, TFM_RESIZE, TFM_ROTATION, TFM_TRACKBALL)))
{
@@ -169,45 +171,50 @@ static int trans_data_compare_rdist(const void *a, const void *b)
void sort_trans_data_dist(TransInfo *t)
{
- TransData *start = t->data;
- int i;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *start = tc->data;
+ int i;
- for (i = 0; i < t->total && start->flag & TD_SELECTED; i++)
- start++;
-
- if (i < t->total) {
- if (t->flag & T_PROP_CONNECTED)
- qsort(start, t->total - i, sizeof(TransData), trans_data_compare_dist);
- else
- qsort(start, t->total - i, sizeof(TransData), trans_data_compare_rdist);
+ for (i = 0; i < tc->data_len && start->flag & TD_SELECTED; i++) {
+ start++;
+ }
+
+ if (i < tc->data_len) {
+ if (t->flag & T_PROP_CONNECTED)
+ qsort(start, tc->data_len - i, sizeof(TransData), trans_data_compare_dist);
+ else
+ qsort(start, tc->data_len - i, sizeof(TransData), trans_data_compare_rdist);
+ }
}
}
static void sort_trans_data(TransInfo *t)
{
- TransData *sel, *unsel;
- TransData temp;
- unsel = t->data;
- sel = t->data;
- sel += t->total - 1;
- while (sel > unsel) {
- while (unsel->flag & TD_SELECTED) {
- unsel++;
- if (unsel == sel) {
- return;
- }
- }
- while (!(sel->flag & TD_SELECTED)) {
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *sel, *unsel;
+ TransData temp;
+ unsel = tc->data;
+ sel = tc->data;
+ sel += tc->data_len - 1;
+ while (sel > unsel) {
+ while (unsel->flag & TD_SELECTED) {
+ unsel++;
+ if (unsel == sel) {
+ return;
+ }
+ }
+ while (!(sel->flag & TD_SELECTED)) {
+ sel--;
+ if (unsel == sel) {
+ return;
+ }
+ }
+ temp = *unsel;
+ *unsel = *sel;
+ *sel = temp;
sel--;
- if (unsel == sel) {
- return;
- }
+ unsel++;
}
- temp = *unsel;
- *unsel = *sel;
- *sel = temp;
- sel--;
- unsel++;
}
}
@@ -215,7 +222,6 @@ static void sort_trans_data(TransInfo *t)
* warning; this is loops inside loop, has minor N^2 issues, but by sorting list it is OK */
static void set_prop_dist(TransInfo *t, const bool with_dist)
{
- TransData *tob;
int a;
float _proj_vec[3];
@@ -232,49 +238,52 @@ static void set_prop_dist(TransInfo *t, const bool with_dist)
}
}
- for (a = 0, tob = t->data; a < t->total; a++, tob++) {
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *tob = tc->data;
+ for (a = 0; a < tc->data_len; a++, tob++) {
- tob->rdist = 0.0f; // init, it was mallocced
+ tob->rdist = 0.0f; // init, it was mallocced
- if ((tob->flag & TD_SELECTED) == 0) {
- TransData *td;
- int i;
- float dist_sq, vec[3];
+ if ((tob->flag & TD_SELECTED) == 0) {
+ TransData *td;
+ int i;
+ float dist_sq, vec[3];
- tob->rdist = -1.0f; // signal for next loop
+ tob->rdist = -1.0f; // signal for next loop
- for (i = 0, td = t->data; i < t->total; i++, td++) {
- if (td->flag & TD_SELECTED) {
- if (use_island) {
- sub_v3_v3v3(vec, tob->iloc, td->iloc);
- }
- else {
- sub_v3_v3v3(vec, tob->center, td->center);
- }
- mul_m3_v3(tob->mtx, vec);
+ for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_SELECTED) {
+ if (use_island) {
+ sub_v3_v3v3(vec, tob->iloc, td->iloc);
+ }
+ else {
+ sub_v3_v3v3(vec, tob->center, td->center);
+ }
+ mul_m3_v3(tob->mtx, vec);
- if (proj_vec) {
- float vec_p[3];
- project_v3_v3v3(vec_p, vec, proj_vec);
- sub_v3_v3(vec, vec_p);
- }
+ if (proj_vec) {
+ float vec_p[3];
+ project_v3_v3v3(vec_p, vec, proj_vec);
+ sub_v3_v3(vec, vec_p);
+ }
- dist_sq = len_squared_v3(vec);
- if ((tob->rdist == -1.0f) || (dist_sq < SQUARE(tob->rdist))) {
- tob->rdist = sqrtf(dist_sq);
- if (use_island) {
- copy_v3_v3(tob->center, td->center);
- copy_m3_m3(tob->axismtx, td->axismtx);
+ dist_sq = len_squared_v3(vec);
+ if ((tob->rdist == -1.0f) || (dist_sq < SQUARE(tob->rdist))) {
+ tob->rdist = sqrtf(dist_sq);
+ if (use_island) {
+ copy_v3_v3(tob->center, td->center);
+ copy_m3_m3(tob->axismtx, td->axismtx);
+ }
}
}
+ else {
+ break; /* by definition transdata has selected items in beginning */
+ }
}
- else {
- break; /* by definition transdata has selected items in beginning */
+ if (with_dist) {
+ tob->dist = tob->rdist;
}
}
- if (with_dist) {
- tob->dist = tob->rdist;
- }
}
}
}
@@ -285,35 +294,41 @@ static void set_prop_dist(TransInfo *t, const bool with_dist)
static void createTransTexspace(TransInfo *t)
{
- Scene *scene = t->scene;
+ ViewLayer *view_layer = t->view_layer;
TransData *td;
Object *ob;
ID *id;
short *texflag;
- ob = OBACT;
+ ob = OBACT(view_layer);
if (ob == NULL) { // Shouldn't logically happen, but still...
- t->total = 0;
+ t->data_len_all = 0;
return;
}
id = ob->data;
if (id == NULL || !ELEM(GS(id->name), ID_ME, ID_CU, ID_MB)) {
BKE_report(t->reports, RPT_ERROR, "Unsupported object type for text-space transform");
- t->total = 0;
+ t->data_len_all = 0;
return;
}
if (BKE_object_obdata_is_libdata(ob)) {
BKE_report(t->reports, RPT_ERROR, "Linked data can't text-space transform");
- t->total = 0;
+ t->data_len_all = 0;
return;
}
- t->total = 1;
- td = t->data = MEM_callocN(sizeof(TransData), "TransTexspace");
- td->ext = t->ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
+
+ {
+ TransDataContainer *tc = t->data_container = MEM_callocN(sizeof(*t->data_container), __func__);
+ tc->data_len = 1;
+ td = tc->data = MEM_callocN(sizeof(TransData), "TransTexspace");
+ td->ext = tc->data_ext = MEM_callocN(sizeof(TransDataExtension), "TransTexspace");
+ }
+
+ t->data_len_all = 1;
td->flag = TD_SELECTED;
copy_v3_v3(td->center, ob->obmat[3]);
@@ -338,72 +353,77 @@ static void createTransTexspace(TransInfo *t)
static void createTransEdge(TransInfo *t)
{
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
- TransData *td = NULL;
- BMEdge *eed;
- BMIter iter;
- float mtx[3][3], smtx[3][3];
- int count = 0, countsel = 0;
- const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
- int cd_edge_float_offset;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) countsel++;
- if (is_prop_edit) count++;
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
+ TransData *td = NULL;
+ BMEdge *eed;
+ BMIter iter;
+ float mtx[3][3], smtx[3][3];
+ int count = 0, countsel = 0;
+ const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
+ int cd_edge_float_offset;
+
+ BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN)) {
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT)) countsel++;
+ if (is_prop_edit) count++;
+ }
}
- }
- if (countsel == 0)
- return;
+ if (countsel == 0) {
+ tc->data_len = 0;
+ continue;
+ }
- if (is_prop_edit) {
- t->total = count;
- }
- else {
- t->total = countsel;
- }
+ if (is_prop_edit) {
+ tc->data_len = count;
+ }
+ else {
+ tc->data_len = countsel;
+ }
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransCrease");
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransCrease");
- copy_m3_m4(mtx, t->obedit->obmat);
- pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
+ copy_m3_m4(mtx, tc->obedit->obmat);
+ pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
- /* create data we need */
- if (t->mode == TFM_BWEIGHT) {
- BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_EDGE_BWEIGHT);
- cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT);
- }
- else { //if (t->mode == TFM_CREASE) {
- BLI_assert(t->mode == TFM_CREASE);
- BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_EDGE_CREASE);
- cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE);
- }
+ /* create data we need */
+ if (t->mode == TFM_BWEIGHT) {
+ BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_BWEIGHT);
+ cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_BWEIGHT);
+ }
+ else { //if (t->mode == TFM_CREASE) {
+ BLI_assert(t->mode == TFM_CREASE);
+ BM_mesh_cd_flag_ensure(em->bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_EDGE_CREASE);
+ cd_edge_float_offset = CustomData_get_offset(&em->bm->edata, CD_CREASE);
+ }
- BLI_assert(cd_edge_float_offset != -1);
+ BLI_assert(cd_edge_float_offset != -1);
- BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
- if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && (BM_elem_flag_test(eed, BM_ELEM_SELECT) || is_prop_edit)) {
- float *fl_ptr;
- /* need to set center for center calculations */
- mid_v3_v3v3(td->center, eed->v1->co, eed->v2->co);
+ BM_ITER_MESH (eed, &iter, em->bm, BM_EDGES_OF_MESH) {
+ if (!BM_elem_flag_test(eed, BM_ELEM_HIDDEN) && (BM_elem_flag_test(eed, BM_ELEM_SELECT) || is_prop_edit)) {
+ float *fl_ptr;
+ /* need to set center for center calculations */
+ mid_v3_v3v3(td->center, eed->v1->co, eed->v2->co);
- td->loc = NULL;
- if (BM_elem_flag_test(eed, BM_ELEM_SELECT))
- td->flag = TD_SELECTED;
- else
- td->flag = 0;
+ td->loc = NULL;
+ if (BM_elem_flag_test(eed, BM_ELEM_SELECT))
+ td->flag = TD_SELECTED;
+ else
+ td->flag = 0;
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
- td->ext = NULL;
+ td->ext = NULL;
- fl_ptr = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_float_offset);
- td->val = fl_ptr;
- td->ival = *fl_ptr;
+ fl_ptr = BM_ELEM_CD_GET_VOID_P(eed, cd_edge_float_offset);
+ td->val = fl_ptr;
+ td->ival = *fl_ptr;
- td++;
+ td++;
+ }
}
}
}
@@ -521,7 +541,7 @@ static short apply_targetless_ik(Object *ob)
return apply;
}
-static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, TransData *td)
+static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, TransDataContainer *tc, TransData *td)
{
Bone *bone = pchan->bone;
float pmat[3][3], omat[3][3];
@@ -632,7 +652,7 @@ static void add_pose_transdata(TransInfo *t, bPoseChannel *pchan, Object *ob, Tr
normalize_m3(td->axismtx);
if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
- bArmature *arm = t->poseobj->data;
+ bArmature *arm = tc->poseobj->data;
if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) {
td->loc = NULL;
@@ -826,25 +846,25 @@ void transform_autoik_update(TransInfo *t, short mode)
}
}
- /* sanity checks (don't assume t->poseobj is set, or that it is an armature) */
- if (ELEM(NULL, t->poseobj, t->poseobj->pose))
- return;
-
/* apply to all pose-channels */
bool changed = false;
- for (pchan = t->poseobj->pose->chanbase.first; pchan; pchan = pchan->next) {
- changed |= pchan_autoik_adjust(pchan, *chainlen);
- }
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!DEG_depsgraph_use_legacy())
-#endif
- {
- if (changed) {
- /* TODO(sergey): Consider doing partial update only. */
- DAG_relations_tag_update(G.main);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+
+ /* sanity checks (don't assume t->poseobj is set, or that it is an armature) */
+ if (ELEM(NULL, tc->poseobj, tc->poseobj->pose)) {
+ continue;
+ }
+
+ for (pchan = tc->poseobj->pose->chanbase.first; pchan; pchan = pchan->next) {
+ changed |= pchan_autoik_adjust(pchan, *chainlen);
}
}
+
+ if (changed) {
+ /* TODO(sergey): Consider doing partial update only. */
+ DEG_relations_tag_update(G.main);
+ }
}
/* frees temporal IKs */
@@ -853,9 +873,7 @@ static void pose_grab_with_ik_clear(Object *ob)
bKinematicConstraint *data;
bPoseChannel *pchan;
bConstraint *con, *next;
-#ifdef WITH_LEGACY_DEPSGRAPH
- bool need_dependency_update = false;
-#endif
+ bool relations_changed = false;
for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
/* clear all temporary lock flags */
@@ -869,10 +887,9 @@ static void pose_grab_with_ik_clear(Object *ob)
if (con->type == CONSTRAINT_TYPE_KINEMATIC) {
data = con->data;
if (data->flag & CONSTRAINT_IK_TEMP) {
+ relations_changed = true;
+
/* iTaSC needs clear for removed constraints */
-#ifdef WITH_LEGACY_DEPSGRAPH
- need_dependency_update = true;
-#endif
BIK_clear_data(ob->pose);
BLI_remlink(&pchan->constraints, con);
@@ -887,12 +904,9 @@ static void pose_grab_with_ik_clear(Object *ob)
}
}
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!DEG_depsgraph_use_legacy() && need_dependency_update)
-#endif
- {
+ if (relations_changed) {
/* TODO(sergey): Consider doing partial update only. */
- DAG_relations_tag_update(G.main);
+ DEG_relations_tag_update(G.main);
}
}
@@ -1046,88 +1060,109 @@ static short pose_grab_with_ik(Object *ob)
/* iTaSC needs clear for new IK constraints */
if (tot_ik) {
BIK_clear_data(ob->pose);
-#ifdef WITH_LEGACY_DEPSGRAPH
- if (!DEG_depsgraph_use_legacy())
-#endif
- {
- /* TODO(sergey): Consuder doing partial update only. */
- DAG_relations_tag_update(G.main);
- }
+ /* TODO(sergey): Consuder doing partial update only. */
+ DEG_relations_tag_update(G.main);
}
return (tot_ik) ? 1 : 0;
}
-/* only called with pose mode active object now */
-static void createTransPose(TransInfo *t, Object *ob)
+/**
+ * When objects array is NULL, use 't->data_container' as is.
+ */
+static void createTransPose(TransInfo *t, Object **objects, uint objects_len)
{
- bArmature *arm;
- bPoseChannel *pchan;
- TransData *td;
- TransDataExtension *tdx;
- short ik_on = 0;
- int i;
+ if (objects != NULL) {
+ if (t->data_container) {
+ MEM_freeN(t->data_container);
+ }
+ t->data_container = MEM_callocN(sizeof(*t->data_container) * objects_len, __func__);
+ t->data_container_len = objects_len;
+ int th_index;
+ FOREACH_TRANS_DATA_CONTAINER_INDEX (t, tc, th_index) {
+ tc->poseobj = objects[th_index];
+ }
+ }
- t->total = 0;
+ t->data_len_all = 0;
- /* check validity of state */
- arm = BKE_armature_from_object(ob);
- if ((arm == NULL) || (ob->pose == NULL)) return;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ Object *ob = tc->poseobj;
- if (arm->flag & ARM_RESTPOS) {
- if (ELEM(t->mode, TFM_DUMMY, TFM_BONESIZE) == 0) {
- BKE_report(t->reports, RPT_ERROR, "Cannot change Pose when 'Rest Position' is enabled");
- return;
+ bArmature *arm;
+ bPoseChannel *pchan;
+ TransData *td;
+ TransDataExtension *tdx;
+ short ik_on = 0;
+ int i;
+
+
+ /* check validity of state */
+ arm = BKE_armature_from_object(tc->poseobj);
+ if ((arm == NULL) || (ob->pose == NULL)) {
+ continue;
}
- }
- /* do we need to add temporal IK chains? */
- if ((arm->flag & ARM_AUTO_IK) && t->mode == TFM_TRANSLATION) {
- ik_on = pose_grab_with_ik(ob);
- if (ik_on) t->flag |= T_AUTOIK;
- }
+ if (arm->flag & ARM_RESTPOS) {
+ if (ELEM(t->mode, TFM_DUMMY, TFM_BONESIZE) == 0) {
+ BKE_report(t->reports, RPT_ERROR, "Cannot change Pose when 'Rest Position' is enabled");
+ return;
+ }
+ }
- /* set flags and count total (warning, can change transform to rotate) */
- t->total = count_set_pose_transflags(&t->mode, t->around, ob);
+ /* do we need to add temporal IK chains? */
+ if ((arm->flag & ARM_AUTO_IK) && t->mode == TFM_TRANSLATION) {
+ ik_on = pose_grab_with_ik(ob);
+ if (ik_on) t->flag |= T_AUTOIK;
+ }
- if (t->total == 0) return;
+ /* set flags and count total (warning, can change transform to rotate) */
+ tc->data_len = count_set_pose_transflags(&t->mode, t->around, ob);
- t->flag |= T_POSE;
- t->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */
+ if (tc->data_len == 0) {
+ continue;
+ }
- /* disable PET, its not usable in pose mode yet [#32444] */
- t->flag &= ~T_PROP_EDIT_ALL;
+ tc->poseobj = ob; /* we also allow non-active objects to be transformed, in weightpaint */
- /* init trans data */
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransPoseBone");
- tdx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "TransPoseBoneExt");
- for (i = 0; i < t->total; i++, td++, tdx++) {
- td->ext = tdx;
- td->val = NULL;
- }
+ /* init trans data */
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransPoseBone");
+ tdx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "TransPoseBoneExt");
+ for (i = 0; i < tc->data_len; i++, td++, tdx++) {
+ td->ext = tdx;
+ td->val = NULL;
+ }
- /* use pose channels to fill trans data */
- td = t->data;
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- if (pchan->bone->flag & BONE_TRANSFORM) {
- add_pose_transdata(t, pchan, ob, td);
- td++;
+ /* use pose channels to fill trans data */
+ td = tc->data;
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ if (pchan->bone->flag & BONE_TRANSFORM) {
+ add_pose_transdata(t, pchan, ob, tc, td);
+ td++;
+ }
}
- }
- if (td != (t->data + t->total)) {
- BKE_report(t->reports, RPT_DEBUG, "Bone selection count error");
+ if (td != (tc->data + tc->data_len)) {
+ BKE_report(t->reports, RPT_DEBUG, "Bone selection count error");
+ }
+
+ /* initialize initial auto=ik chainlen's? */
+ if (ik_on) {
+ transform_autoik_update(t, 0);
+ }
}
- /* initialize initial auto=ik chainlen's? */
- if (ik_on) transform_autoik_update(t, 0);
+ t->flag |= T_POSE;
+ /* disable PET, its not usable in pose mode yet [#32444] */
+ t->flag &= ~T_PROP_EDIT_ALL;
+
}
-void restoreBones(TransInfo *t)
+void restoreBones(TransDataContainer *tc)
{
- bArmature *arm = t->obedit->data;
- BoneInitData *bid = t->custom.type.data;
+ bArmature *arm = tc->obedit->data;
+ BoneInitData *bid = tc->custom.type.data;
EditBone *ebo;
while (bid->bone) {
@@ -1168,226 +1203,230 @@ void restoreBones(TransInfo *t)
/* ********************* armature ************** */
static void createTransArmatureVerts(TransInfo *t)
{
- EditBone *ebo, *eboflip;
- bArmature *arm = t->obedit->data;
- ListBase *edbo = arm->edbo;
- TransData *td, *td_old;
- float mtx[3][3], smtx[3][3], bonemat[3][3];
- bool mirror = ((arm->flag & ARM_MIRROR_EDIT) != 0);
- int total_mirrored = 0, i;
- int oldtot;
- BoneInitData *bid;
-
- t->total = 0;
- for (ebo = edbo->first; ebo; ebo = ebo->next) {
- oldtot = t->total;
-
- if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
- if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
- if (ebo->flag & BONE_SELECTED)
- t->total++;
- }
- else if (t->mode == TFM_BONE_ROLL) {
- if (ebo->flag & BONE_SELECTED)
- t->total++;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ EditBone *ebo, *eboflip;
+ bArmature *arm = tc->obedit->data;
+ ListBase *edbo = arm->edbo;
+ TransData *td, *td_old;
+ float mtx[3][3], smtx[3][3], bonemat[3][3];
+ bool mirror = ((arm->flag & ARM_MIRROR_EDIT) != 0);
+ int total_mirrored = 0, i;
+ int oldtot;
+ BoneInitData *bid;
+
+ tc->data_len = 0;
+ for (ebo = edbo->first; ebo; ebo = ebo->next) {
+ oldtot = tc->data_len;
+
+ if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
+ if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
+ if (ebo->flag & BONE_SELECTED)
+ tc->data_len++;
+ }
+ else if (t->mode == TFM_BONE_ROLL) {
+ if (ebo->flag & BONE_SELECTED)
+ tc->data_len++;
+ }
+ else {
+ if (ebo->flag & BONE_TIPSEL)
+ tc->data_len++;
+ if (ebo->flag & BONE_ROOTSEL)
+ tc->data_len++;
+ }
}
- else {
- if (ebo->flag & BONE_TIPSEL)
- t->total++;
- if (ebo->flag & BONE_ROOTSEL)
- t->total++;
+
+ if (mirror && (oldtot < tc->data_len)) {
+ eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo);
+ if (eboflip)
+ total_mirrored++;
}
}
- if (mirror && (oldtot < t->total)) {
- eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo);
- if (eboflip)
- total_mirrored++;
+ if (!tc->data_len) {
+ continue;
}
- }
- if (!t->total) return;
+ transform_around_single_fallback(t);
- transform_around_single_fallback(t);
+ copy_m3_m4(mtx, tc->obedit->obmat);
+ pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
- copy_m3_m4(mtx, t->obedit->obmat);
- pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransEditBone");
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransEditBone");
+ if (mirror) {
+ tc->custom.type.data = bid = MEM_mallocN((total_mirrored + 1) * sizeof(BoneInitData), "BoneInitData");
+ tc->custom.type.use_free = true;
+ }
- if (mirror) {
- t->custom.type.data = bid = MEM_mallocN((total_mirrored + 1) * sizeof(BoneInitData), "BoneInitData");
- t->custom.type.use_free = true;
- }
+ i = 0;
- i = 0;
+ for (ebo = edbo->first; ebo; ebo = ebo->next) {
+ td_old = td;
+ ebo->oldlength = ebo->length; // length==0.0 on extrude, used for scaling radius of bone points
- for (ebo = edbo->first; ebo; ebo = ebo->next) {
- td_old = td;
- ebo->oldlength = ebo->length; // length==0.0 on extrude, used for scaling radius of bone points
+ if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
+ if (t->mode == TFM_BONE_ENVELOPE) {
+ if (ebo->flag & BONE_ROOTSEL) {
+ td->val = &ebo->rad_head;
+ td->ival = *td->val;
- if (EBONE_VISIBLE(arm, ebo) && !(ebo->flag & BONE_EDITMODE_LOCKED)) {
- if (t->mode == TFM_BONE_ENVELOPE) {
- if (ebo->flag & BONE_ROOTSEL) {
- td->val = &ebo->rad_head;
- td->ival = *td->val;
+ copy_v3_v3(td->center, ebo->head);
+ td->flag = TD_SELECTED;
- copy_v3_v3(td->center, ebo->head);
- td->flag = TD_SELECTED;
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
+ td->loc = NULL;
+ td->ext = NULL;
+ td->ob = tc->obedit;
- td->loc = NULL;
- td->ext = NULL;
- td->ob = t->obedit;
+ td++;
+ }
+ if (ebo->flag & BONE_TIPSEL) {
+ td->val = &ebo->rad_tail;
+ td->ival = *td->val;
+ copy_v3_v3(td->center, ebo->tail);
+ td->flag = TD_SELECTED;
- td++;
- }
- if (ebo->flag & BONE_TIPSEL) {
- td->val = &ebo->rad_tail;
- td->ival = *td->val;
- copy_v3_v3(td->center, ebo->tail);
- td->flag = TD_SELECTED;
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
+ td->loc = NULL;
+ td->ext = NULL;
+ td->ob = tc->obedit;
- td->loc = NULL;
- td->ext = NULL;
- td->ob = t->obedit;
+ td++;
+ }
- td++;
}
+ else if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
+ if (ebo->flag & BONE_SELECTED) {
+ if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) {
+ td->loc = NULL;
+ td->val = &ebo->dist;
+ td->ival = ebo->dist;
+ }
+ else {
+ // abusive storage of scale in the loc pointer :)
+ td->loc = &ebo->xwidth;
+ copy_v3_v3(td->iloc, td->loc);
+ td->val = NULL;
+ }
+ copy_v3_v3(td->center, ebo->head);
+ td->flag = TD_SELECTED;
- }
- else if (ELEM(t->mode, TFM_BONESIZE, TFM_BONE_ENVELOPE_DIST)) {
- if (ebo->flag & BONE_SELECTED) {
- if ((t->mode == TFM_BONE_ENVELOPE_DIST) || (arm->drawtype == ARM_ENVELOPE)) {
- td->loc = NULL;
- td->val = &ebo->dist;
- td->ival = ebo->dist;
- }
- else {
- // abusive storage of scale in the loc pointer :)
- td->loc = &ebo->xwidth;
- copy_v3_v3(td->iloc, td->loc);
- td->val = NULL;
- }
- copy_v3_v3(td->center, ebo->head);
- td->flag = TD_SELECTED;
-
- /* use local bone matrix */
- ED_armature_ebone_to_mat3(ebo, bonemat);
- mul_m3_m3m3(td->mtx, mtx, bonemat);
- invert_m3_m3(td->smtx, td->mtx);
+ /* use local bone matrix */
+ ED_armature_ebone_to_mat3(ebo, bonemat);
+ mul_m3_m3m3(td->mtx, mtx, bonemat);
+ invert_m3_m3(td->smtx, td->mtx);
- copy_m3_m3(td->axismtx, td->mtx);
- normalize_m3(td->axismtx);
+ copy_m3_m3(td->axismtx, td->mtx);
+ normalize_m3(td->axismtx);
- td->ext = NULL;
- td->ob = t->obedit;
+ td->ext = NULL;
+ td->ob = tc->obedit;
- td++;
+ td++;
+ }
}
- }
- else if (t->mode == TFM_BONE_ROLL) {
- if (ebo->flag & BONE_SELECTED) {
- td->loc = NULL;
- td->val = &(ebo->roll);
- td->ival = ebo->roll;
+ else if (t->mode == TFM_BONE_ROLL) {
+ if (ebo->flag & BONE_SELECTED) {
+ td->loc = NULL;
+ td->val = &(ebo->roll);
+ td->ival = ebo->roll;
- copy_v3_v3(td->center, ebo->head);
- td->flag = TD_SELECTED;
+ copy_v3_v3(td->center, ebo->head);
+ td->flag = TD_SELECTED;
- td->ext = NULL;
- td->ob = t->obedit;
+ td->ext = NULL;
+ td->ob = tc->obedit;
- td++;
- }
- }
- else {
- if (ebo->flag & BONE_TIPSEL) {
- copy_v3_v3(td->iloc, ebo->tail);
-
- /* Don't allow single selected tips to have a modified center,
- * causes problem with snapping (see T45974).
- * However, in rotation mode, we want to keep that 'rotate bone around root with
- * only its tip selected' behavior (see T46325). */
- if ((t->around == V3D_AROUND_LOCAL_ORIGINS) &&
- ((t->mode == TFM_ROTATION) || (ebo->flag & BONE_ROOTSEL)))
- {
- copy_v3_v3(td->center, ebo->head);
- }
- else {
- copy_v3_v3(td->center, td->iloc);
+ td++;
}
+ }
+ else {
+ if (ebo->flag & BONE_TIPSEL) {
+ copy_v3_v3(td->iloc, ebo->tail);
+
+ /* Don't allow single selected tips to have a modified center,
+ * causes problem with snapping (see T45974).
+ * However, in rotation mode, we want to keep that 'rotate bone around root with
+ * only its tip selected' behavior (see T46325). */
+ if ((t->around == V3D_AROUND_LOCAL_ORIGINS) &&
+ ((t->mode == TFM_ROTATION) || (ebo->flag & BONE_ROOTSEL)))
+ {
+ copy_v3_v3(td->center, ebo->head);
+ }
+ else {
+ copy_v3_v3(td->center, td->iloc);
+ }
- td->loc = ebo->tail;
- td->flag = TD_SELECTED;
- if (ebo->flag & BONE_EDITMODE_LOCKED)
- td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE;
+ td->loc = ebo->tail;
+ td->flag = TD_SELECTED;
+ if (ebo->flag & BONE_EDITMODE_LOCKED)
+ td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE;
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
- ED_armature_ebone_to_mat3(ebo, td->axismtx);
+ ED_armature_ebone_to_mat3(ebo, td->axismtx);
- if ((ebo->flag & BONE_ROOTSEL) == 0) {
- td->extra = ebo;
- td->ival = ebo->roll;
- }
+ if ((ebo->flag & BONE_ROOTSEL) == 0) {
+ td->extra = ebo;
+ td->ival = ebo->roll;
+ }
- td->ext = NULL;
- td->val = NULL;
- td->ob = t->obedit;
+ td->ext = NULL;
+ td->val = NULL;
+ td->ob = tc->obedit;
- td++;
- }
- if (ebo->flag & BONE_ROOTSEL) {
- copy_v3_v3(td->iloc, ebo->head);
- copy_v3_v3(td->center, td->iloc);
- td->loc = ebo->head;
- td->flag = TD_SELECTED;
- if (ebo->flag & BONE_EDITMODE_LOCKED)
- td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE;
+ td++;
+ }
+ if (ebo->flag & BONE_ROOTSEL) {
+ copy_v3_v3(td->iloc, ebo->head);
+ copy_v3_v3(td->center, td->iloc);
+ td->loc = ebo->head;
+ td->flag = TD_SELECTED;
+ if (ebo->flag & BONE_EDITMODE_LOCKED)
+ td->protectflag = OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE;
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
- ED_armature_ebone_to_mat3(ebo, td->axismtx);
+ ED_armature_ebone_to_mat3(ebo, td->axismtx);
- td->extra = ebo; /* to fix roll */
- td->ival = ebo->roll;
+ td->extra = ebo; /* to fix roll */
+ td->ival = ebo->roll;
- td->ext = NULL;
- td->val = NULL;
- td->ob = t->obedit;
+ td->ext = NULL;
+ td->val = NULL;
+ td->ob = tc->obedit;
- td++;
+ td++;
+ }
}
}
- }
- if (mirror && (td_old != td)) {
- eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo);
- if (eboflip) {
- bid[i].bone = eboflip;
- bid[i].dist = eboflip->dist;
- bid[i].rad_tail = eboflip->rad_tail;
- bid[i].roll = eboflip->roll;
- bid[i].xwidth = eboflip->xwidth;
- bid[i].zwidth = eboflip->zwidth;
- copy_v3_v3(bid[i].head, eboflip->head);
- copy_v3_v3(bid[i].tail, eboflip->tail);
- i++;
+ if (mirror && (td_old != td)) {
+ eboflip = ED_armature_ebone_get_mirrored(arm->edbo, ebo);
+ if (eboflip) {
+ bid[i].bone = eboflip;
+ bid[i].dist = eboflip->dist;
+ bid[i].rad_tail = eboflip->rad_tail;
+ bid[i].roll = eboflip->roll;
+ bid[i].xwidth = eboflip->xwidth;
+ bid[i].zwidth = eboflip->zwidth;
+ copy_v3_v3(bid[i].head, eboflip->head);
+ copy_v3_v3(bid[i].tail, eboflip->tail);
+ i++;
+ }
}
}
- }
- if (mirror) {
- /* trick to terminate iteration */
- bid[total_mirrored].bone = NULL;
+ if (mirror) {
+ /* trick to terminate iteration */
+ bid[total_mirrored].bone = NULL;
+ }
}
}
@@ -1395,72 +1434,76 @@ static void createTransArmatureVerts(TransInfo *t)
static void createTransMBallVerts(TransInfo *t)
{
- MetaBall *mb = (MetaBall *)t->obedit->data;
- MetaElem *ml;
- TransData *td;
- TransDataExtension *tx;
- float mtx[3][3], smtx[3][3];
- int count = 0, countsel = 0;
- const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
-
- /* count totals */
- for (ml = mb->editelems->first; ml; ml = ml->next) {
- if (ml->flag & SELECT) countsel++;
- if (is_prop_edit) count++;
- }
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ MetaBall *mb = (MetaBall *)tc->obedit->data;
+ MetaElem *ml;
+ TransData *td;
+ TransDataExtension *tx;
+ float mtx[3][3], smtx[3][3];
+ int count = 0, countsel = 0;
+ const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
+
+ /* count totals */
+ for (ml = mb->editelems->first; ml; ml = ml->next) {
+ if (ml->flag & SELECT) countsel++;
+ if (is_prop_edit) count++;
+ }
- /* note: in prop mode we need at least 1 selected */
- if (countsel == 0) return;
+ /* note: in prop mode we need at least 1 selected */
+ if (countsel == 0) {
+ continue;
+ }
- if (is_prop_edit) t->total = count;
- else t->total = countsel;
+ if (is_prop_edit) tc->data_len = count;
+ else tc->data_len = countsel;
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(MBall EditMode)");
- tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "MetaElement_TransExtension");
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(MBall EditMode)");
+ tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "MetaElement_TransExtension");
- copy_m3_m4(mtx, t->obedit->obmat);
- pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
+ copy_m3_m4(mtx, tc->obedit->obmat);
+ pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
- for (ml = mb->editelems->first; ml; ml = ml->next) {
- if (is_prop_edit || (ml->flag & SELECT)) {
- td->loc = &ml->x;
- copy_v3_v3(td->iloc, td->loc);
- copy_v3_v3(td->center, td->loc);
+ for (ml = mb->editelems->first; ml; ml = ml->next) {
+ if (is_prop_edit || (ml->flag & SELECT)) {
+ td->loc = &ml->x;
+ copy_v3_v3(td->iloc, td->loc);
+ copy_v3_v3(td->center, td->loc);
- quat_to_mat3(td->axismtx, ml->quat);
+ quat_to_mat3(td->axismtx, ml->quat);
- if (ml->flag & SELECT) td->flag = TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE;
- else td->flag = TD_USEQUAT;
+ if (ml->flag & SELECT) td->flag = TD_SELECTED | TD_USEQUAT | TD_SINGLESIZE;
+ else td->flag = TD_USEQUAT;
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
- td->ext = tx;
+ td->ext = tx;
- /* Radius of MetaElem (mass of MetaElem influence) */
- if (ml->flag & MB_SCALE_RAD) {
- td->val = &ml->rad;
- td->ival = ml->rad;
- }
- else {
- td->val = &ml->s;
- td->ival = ml->s;
- }
+ /* Radius of MetaElem (mass of MetaElem influence) */
+ if (ml->flag & MB_SCALE_RAD) {
+ td->val = &ml->rad;
+ td->ival = ml->rad;
+ }
+ else {
+ td->val = &ml->s;
+ td->ival = ml->s;
+ }
- /* expx/expy/expz determine "shape" of some MetaElem types */
- tx->size = &ml->expx;
- tx->isize[0] = ml->expx;
- tx->isize[1] = ml->expy;
- tx->isize[2] = ml->expz;
+ /* expx/expy/expz determine "shape" of some MetaElem types */
+ tx->size = &ml->expx;
+ tx->isize[0] = ml->expx;
+ tx->isize[1] = ml->expy;
+ tx->isize[2] = ml->expz;
- /* quat is used for rotation of MetaElem */
- tx->quat = ml->quat;
- copy_qt_qt(tx->iquat, ml->quat);
+ /* quat is used for rotation of MetaElem */
+ tx->quat = ml->quat;
+ copy_qt_qt(tx->iquat, ml->quat);
- tx->rot = NULL;
+ tx->rot = NULL;
- td++;
- tx++;
+ td++;
+ tx++;
+ }
}
}
}
@@ -1569,271 +1612,277 @@ static int bezt_select_to_transform_triple_flag(
static void createTransCurveVerts(TransInfo *t)
{
- Curve *cu = t->obedit->data;
- TransData *td = NULL;
- Nurb *nu;
- BezTriple *bezt;
- BPoint *bp;
- float mtx[3][3], smtx[3][3];
- int a;
- int count = 0, countsel = 0;
- const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
- short hide_handles = (cu->drawflag & CU_HIDE_HANDLES);
- ListBase *nurbs;
-
- /* to be sure */
- if (cu->editnurb == NULL) return;
#define SEL_F1 (1 << 0)
#define SEL_F2 (1 << 1)
#define SEL_F3 (1 << 2)
- /* count total of vertices, check identical as in 2nd loop for making transdata! */
- nurbs = BKE_curve_editNurbs_get(cu);
- for (nu = nurbs->first; nu; nu = nu->next) {
- if (nu->type == CU_BEZIER) {
- for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
- if (bezt->hide == 0) {
- const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles);
- if (bezt_tx & SEL_F1) { countsel++; }
- if (bezt_tx & SEL_F2) { countsel++; }
- if (bezt_tx & SEL_F3) { countsel++; }
- if (is_prop_edit) count += 3;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+
+ Curve *cu = tc->obedit->data;
+ TransData *td = NULL;
+ Nurb *nu;
+ BezTriple *bezt;
+ BPoint *bp;
+ float mtx[3][3], smtx[3][3];
+ int a;
+ int count = 0, countsel = 0;
+ const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
+ short hide_handles = (cu->drawflag & CU_HIDE_HANDLES);
+ ListBase *nurbs;
+
+ /* to be sure */
+ if (cu->editnurb == NULL) return;
+
+ /* count total of vertices, check identical as in 2nd loop for making transdata! */
+ nurbs = BKE_curve_editNurbs_get(cu);
+ for (nu = nurbs->first; nu; nu = nu->next) {
+ if (nu->type == CU_BEZIER) {
+ for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
+ if (bezt->hide == 0) {
+ const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles);
+ if (bezt_tx & SEL_F1) { countsel++; }
+ if (bezt_tx & SEL_F2) { countsel++; }
+ if (bezt_tx & SEL_F3) { countsel++; }
+ if (is_prop_edit) count += 3;
+ }
}
}
- }
- else {
- for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) {
- if (bp->hide == 0) {
- if (is_prop_edit) count++;
- if (bp->f1 & SELECT) countsel++;
+ else {
+ for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) {
+ if (bp->hide == 0) {
+ if (is_prop_edit) count++;
+ if (bp->f1 & SELECT) countsel++;
+ }
}
}
}
- }
- /* note: in prop mode we need at least 1 selected */
- if (countsel == 0) return;
+ /* note: in prop mode we need at least 1 selected */
+ if (countsel == 0) {
+ tc->data_len = 0;
+ continue;
+ }
- if (is_prop_edit) t->total = count;
- else t->total = countsel;
- t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Curve EditMode)");
+ if (is_prop_edit) tc->data_len = count;
+ else tc->data_len = countsel;
+ tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Curve EditMode)");
- transform_around_single_fallback(t);
+ transform_around_single_fallback(t);
- copy_m3_m4(mtx, t->obedit->obmat);
- pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
+ copy_m3_m4(mtx, tc->obedit->obmat);
+ pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
- td = t->data;
- for (nu = nurbs->first; nu; nu = nu->next) {
- if (nu->type == CU_BEZIER) {
- TransData *head, *tail;
- head = tail = td;
- for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
- if (bezt->hide == 0) {
- TransDataCurveHandleFlags *hdata = NULL;
- float axismtx[3][3];
+ td = tc->data;
+ for (nu = nurbs->first; nu; nu = nu->next) {
+ if (nu->type == CU_BEZIER) {
+ TransData *head, *tail;
+ head = tail = td;
+ for (a = 0, bezt = nu->bezt; a < nu->pntsu; a++, bezt++) {
+ if (bezt->hide == 0) {
+ TransDataCurveHandleFlags *hdata = NULL;
+ float axismtx[3][3];
- if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
- float normal[3], plane[3];
+ if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
+ float normal[3], plane[3];
- BKE_nurb_bezt_calc_normal(nu, bezt, normal);
- BKE_nurb_bezt_calc_plane(nu, bezt, plane);
+ BKE_nurb_bezt_calc_normal(nu, bezt, normal);
+ BKE_nurb_bezt_calc_plane(nu, bezt, plane);
- if (createSpaceNormalTangent(axismtx, normal, plane)) {
- /* pass */
- }
- else {
- normalize_v3(normal);
- axis_dominant_v3_to_m3(axismtx, normal);
- invert_m3(axismtx);
+ if (createSpaceNormalTangent(axismtx, normal, plane)) {
+ /* pass */
+ }
+ else {
+ normalize_v3(normal);
+ axis_dominant_v3_to_m3(axismtx, normal);
+ invert_m3(axismtx);
+ }
}
- }
- /* Elements that will be transform (not always a match to selection). */
- const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles);
+ /* Elements that will be transform (not always a match to selection). */
+ const int bezt_tx = bezt_select_to_transform_triple_flag(bezt, hide_handles);
+
+ if (is_prop_edit || bezt_tx & SEL_F1) {
+ copy_v3_v3(td->iloc, bezt->vec[0]);
+ td->loc = bezt->vec[0];
+ copy_v3_v3(td->center, bezt->vec[(hide_handles ||
+ (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
+ (bezt->f2 & SELECT)) ? 1 : 0]);
+ if (hide_handles) {
+ if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
+ else td->flag = 0;
+ }
+ else {
+ if (bezt->f1 & SELECT) td->flag = TD_SELECTED;
+ else td->flag = 0;
+ }
+ td->ext = NULL;
+ td->val = NULL;
- if (is_prop_edit || bezt_tx & SEL_F1) {
- copy_v3_v3(td->iloc, bezt->vec[0]);
- td->loc = bezt->vec[0];
- copy_v3_v3(td->center, bezt->vec[(hide_handles ||
- (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
- (bezt->f2 & SELECT)) ? 1 : 0]);
- if (hide_handles) {
- if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
- else td->flag = 0;
- }
- else {
- if (bezt->f1 & SELECT) td->flag = TD_SELECTED;
- else td->flag = 0;
- }
- td->ext = NULL;
- td->val = NULL;
+ hdata = initTransDataCurveHandles(td, bezt);
- hdata = initTransDataCurveHandles(td, bezt);
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
+ if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
+ copy_m3_m3(td->axismtx, axismtx);
+ }
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
- if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
- copy_m3_m3(td->axismtx, axismtx);
+ td++;
+ count++;
+ tail++;
}
- td++;
- count++;
- tail++;
- }
+ /* This is the Curve Point, the other two are handles */
+ if (is_prop_edit || bezt_tx & SEL_F2) {
+ copy_v3_v3(td->iloc, bezt->vec[1]);
+ td->loc = bezt->vec[1];
+ copy_v3_v3(td->center, td->loc);
+ if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
+ else td->flag = 0;
+ td->ext = NULL;
- /* This is the Curve Point, the other two are handles */
- if (is_prop_edit || bezt_tx & SEL_F2) {
- copy_v3_v3(td->iloc, bezt->vec[1]);
- td->loc = bezt->vec[1];
- copy_v3_v3(td->center, td->loc);
- if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
- else td->flag = 0;
- td->ext = NULL;
+ if (t->mode == TFM_CURVE_SHRINKFATTEN) { /* || t->mode==TFM_RESIZE) {*/ /* TODO - make points scale */
+ td->val = &(bezt->radius);
+ td->ival = bezt->radius;
+ }
+ else if (t->mode == TFM_TILT) {
+ td->val = &(bezt->alfa);
+ td->ival = bezt->alfa;
+ }
+ else {
+ td->val = NULL;
+ }
- if (t->mode == TFM_CURVE_SHRINKFATTEN) { /* || t->mode==TFM_RESIZE) {*/ /* TODO - make points scale */
- td->val = &(bezt->radius);
- td->ival = bezt->radius;
- }
- else if (t->mode == TFM_TILT) {
- td->val = &(bezt->alfa);
- td->ival = bezt->alfa;
- }
- else {
- td->val = NULL;
- }
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
+ if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
+ copy_m3_m3(td->axismtx, axismtx);
+ }
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
- if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
- copy_m3_m3(td->axismtx, axismtx);
+ if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0)
+ /* If the middle is selected but the sides arnt, this is needed */
+ if (hdata == NULL) { /* if the handle was not saved by the previous handle */
+ hdata = initTransDataCurveHandles(td, bezt);
+ }
+
+ td++;
+ count++;
+ tail++;
}
+ if (is_prop_edit || bezt_tx & SEL_F3) {
+ copy_v3_v3(td->iloc, bezt->vec[2]);
+ td->loc = bezt->vec[2];
+ copy_v3_v3(td->center, bezt->vec[(hide_handles ||
+ (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
+ (bezt->f2 & SELECT)) ? 1 : 2]);
+ if (hide_handles) {
+ if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
+ else td->flag = 0;
+ }
+ else {
+ if (bezt->f3 & SELECT) td->flag = TD_SELECTED;
+ else td->flag = 0;
+ }
+ td->ext = NULL;
+ td->val = NULL;
- if ((bezt_tx & SEL_F1) == 0 && (bezt_tx & SEL_F3) == 0)
- /* If the middle is selected but the sides arnt, this is needed */
if (hdata == NULL) { /* if the handle was not saved by the previous handle */
hdata = initTransDataCurveHandles(td, bezt);
}
- td++;
- count++;
- tail++;
- }
- if (is_prop_edit || bezt_tx & SEL_F3) {
- copy_v3_v3(td->iloc, bezt->vec[2]);
- td->loc = bezt->vec[2];
- copy_v3_v3(td->center, bezt->vec[(hide_handles ||
- (t->around == V3D_AROUND_LOCAL_ORIGINS) ||
- (bezt->f2 & SELECT)) ? 1 : 2]);
- if (hide_handles) {
- if (bezt->f2 & SELECT) td->flag = TD_SELECTED;
- else td->flag = 0;
- }
- else {
- if (bezt->f3 & SELECT) td->flag = TD_SELECTED;
- else td->flag = 0;
- }
- td->ext = NULL;
- td->val = NULL;
-
- if (hdata == NULL) { /* if the handle was not saved by the previous handle */
- hdata = initTransDataCurveHandles(td, bezt);
- }
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
+ if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
+ copy_m3_m3(td->axismtx, axismtx);
+ }
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
- if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
- copy_m3_m3(td->axismtx, axismtx);
+ td++;
+ count++;
+ tail++;
}
- td++;
- count++;
- tail++;
+ (void)hdata; /* quiet warning */
+ }
+ else if (is_prop_edit && head != tail) {
+ calc_distanceCurveVerts(head, tail - 1);
+ head = tail;
}
-
- (void)hdata; /* quiet warning */
}
- else if (is_prop_edit && head != tail) {
+ if (is_prop_edit && head != tail)
calc_distanceCurveVerts(head, tail - 1);
- head = tail;
- }
- }
- if (is_prop_edit && head != tail)
- calc_distanceCurveVerts(head, tail - 1);
- /* TODO - in the case of tilt and radius we can also avoid allocating the initTransDataCurveHandles
- * but for now just don't change handle types */
- if (ELEM(t->mode, TFM_CURVE_SHRINKFATTEN, TFM_TILT, TFM_DUMMY) == 0) {
- /* sets the handles based on their selection, do this after the data is copied to the TransData */
- BKE_nurb_handles_test(nu, !hide_handles);
+ /* TODO - in the case of tilt and radius we can also avoid allocating the initTransDataCurveHandles
+ * but for now just don't change handle types */
+ if (ELEM(t->mode, TFM_CURVE_SHRINKFATTEN, TFM_TILT, TFM_DUMMY) == 0) {
+ /* sets the handles based on their selection, do this after the data is copied to the TransData */
+ BKE_nurb_handles_test(nu, !hide_handles);
+ }
}
- }
- else {
- TransData *head, *tail;
- head = tail = td;
- for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) {
- if (bp->hide == 0) {
- if (is_prop_edit || (bp->f1 & SELECT)) {
- float axismtx[3][3];
-
- if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
- if (nu->pntsv == 1) {
- float normal[3], plane[3];
-
- BKE_nurb_bpoint_calc_normal(nu, bp, normal);
- BKE_nurb_bpoint_calc_plane(nu, bp, plane);
-
- if (createSpaceNormalTangent(axismtx, normal, plane)) {
- /* pass */
- }
- else {
- normalize_v3(normal);
- axis_dominant_v3_to_m3(axismtx, normal);
- invert_m3(axismtx);
+ else {
+ TransData *head, *tail;
+ head = tail = td;
+ for (a = nu->pntsu * nu->pntsv, bp = nu->bp; a > 0; a--, bp++) {
+ if (bp->hide == 0) {
+ if (is_prop_edit || (bp->f1 & SELECT)) {
+ float axismtx[3][3];
+
+ if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
+ if (nu->pntsv == 1) {
+ float normal[3], plane[3];
+
+ BKE_nurb_bpoint_calc_normal(nu, bp, normal);
+ BKE_nurb_bpoint_calc_plane(nu, bp, plane);
+
+ if (createSpaceNormalTangent(axismtx, normal, plane)) {
+ /* pass */
+ }
+ else {
+ normalize_v3(normal);
+ axis_dominant_v3_to_m3(axismtx, normal);
+ invert_m3(axismtx);
+ }
}
}
- }
- copy_v3_v3(td->iloc, bp->vec);
- td->loc = bp->vec;
- copy_v3_v3(td->center, td->loc);
- if (bp->f1 & SELECT) td->flag = TD_SELECTED;
- else td->flag = 0;
- td->ext = NULL;
+ copy_v3_v3(td->iloc, bp->vec);
+ td->loc = bp->vec;
+ copy_v3_v3(td->center, td->loc);
+ if (bp->f1 & SELECT) td->flag = TD_SELECTED;
+ else td->flag = 0;
+ td->ext = NULL;
- if (t->mode == TFM_CURVE_SHRINKFATTEN || t->mode == TFM_RESIZE) {
- td->val = &(bp->radius);
- td->ival = bp->radius;
- }
- else {
- td->val = &(bp->alfa);
- td->ival = bp->alfa;
- }
+ if (t->mode == TFM_CURVE_SHRINKFATTEN || t->mode == TFM_RESIZE) {
+ td->val = &(bp->radius);
+ td->ival = bp->radius;
+ }
+ else {
+ td->val = &(bp->alfa);
+ td->ival = bp->alfa;
+ }
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
- if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
- if (nu->pntsv == 1) {
- copy_m3_m3(td->axismtx, axismtx);
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
+ if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
+ if (nu->pntsv == 1) {
+ copy_m3_m3(td->axismtx, axismtx);
+ }
}
- }
- td++;
- count++;
- tail++;
+ td++;
+ count++;
+ tail++;
+ }
+ }
+ else if (is_prop_edit && head != tail) {
+ calc_distanceCurveVerts(head, tail - 1);
+ head = tail;
}
}
- else if (is_prop_edit && head != tail) {
+ if (is_prop_edit && head != tail)
calc_distanceCurveVerts(head, tail - 1);
- head = tail;
- }
}
- if (is_prop_edit && head != tail)
- calc_distanceCurveVerts(head, tail - 1);
}
}
-
#undef SEL_F1
#undef SEL_F2
#undef SEL_F3
@@ -1843,226 +1892,236 @@ static void createTransCurveVerts(TransInfo *t)
static void createTransLatticeVerts(TransInfo *t)
{
- Lattice *latt = ((Lattice *)t->obedit->data)->editlatt->latt;
- TransData *td = NULL;
- BPoint *bp;
- float mtx[3][3], smtx[3][3];
- int a;
- int count = 0, countsel = 0;
- const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- bp = latt->def;
- a = latt->pntsu * latt->pntsv * latt->pntsw;
- while (a--) {
- if (bp->hide == 0) {
- if (bp->f1 & SELECT) countsel++;
- if (is_prop_edit) count++;
+ Lattice *latt = ((Lattice *)tc->obedit->data)->editlatt->latt;
+ TransData *td = NULL;
+ BPoint *bp;
+ float mtx[3][3], smtx[3][3];
+ int a;
+ int count = 0, countsel = 0;
+ const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
+
+ bp = latt->def;
+ a = latt->pntsu * latt->pntsv * latt->pntsw;
+ while (a--) {
+ if (bp->hide == 0) {
+ if (bp->f1 & SELECT) countsel++;
+ if (is_prop_edit) count++;
+ }
+ bp++;
}
- bp++;
- }
- /* note: in prop mode we need at least 1 selected */
- if (countsel == 0) return;
+ /* note: in prop mode we need at least 1 selected */
+ if (countsel == 0) return;
- if (is_prop_edit) t->total = count;
- else t->total = countsel;
- t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Lattice EditMode)");
+ if (is_prop_edit) tc->data_len = count;
+ else tc->data_len = countsel;
+ tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Lattice EditMode)");
- copy_m3_m4(mtx, t->obedit->obmat);
- pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
+ copy_m3_m4(mtx, tc->obedit->obmat);
+ pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
- td = t->data;
- bp = latt->def;
- a = latt->pntsu * latt->pntsv * latt->pntsw;
- while (a--) {
- if (is_prop_edit || (bp->f1 & SELECT)) {
- if (bp->hide == 0) {
- copy_v3_v3(td->iloc, bp->vec);
- td->loc = bp->vec;
- copy_v3_v3(td->center, td->loc);
- if (bp->f1 & SELECT) {
- td->flag = TD_SELECTED;
- }
- else {
- td->flag = 0;
- }
- copy_m3_m3(td->smtx, smtx);
- copy_m3_m3(td->mtx, mtx);
+ td = tc->data;
+ bp = latt->def;
+ a = latt->pntsu * latt->pntsv * latt->pntsw;
+ while (a--) {
+ if (is_prop_edit || (bp->f1 & SELECT)) {
+ if (bp->hide == 0) {
+ copy_v3_v3(td->iloc, bp->vec);
+ td->loc = bp->vec;
+ copy_v3_v3(td->center, td->loc);
+ if (bp->f1 & SELECT) {
+ td->flag = TD_SELECTED;
+ }
+ else {
+ td->flag = 0;
+ }
+ copy_m3_m3(td->smtx, smtx);
+ copy_m3_m3(td->mtx, mtx);
- td->ext = NULL;
- td->val = NULL;
+ td->ext = NULL;
+ td->val = NULL;
- td++;
- count++;
+ td++;
+ count++;
+ }
}
+ bp++;
}
- bp++;
}
}
/* ******************* particle edit **************** */
static void createTransParticleVerts(bContext *C, TransInfo *t)
{
- TransData *td = NULL;
- TransDataExtension *tx;
- Object *ob = CTX_data_active_object(C);
- ParticleEditSettings *pset = PE_settings(t->scene);
- PTCacheEdit *edit = PE_get_current(t->scene, ob);
- ParticleSystem *psys = NULL;
- ParticleSystemModifierData *psmd = NULL;
- PTCacheEditPoint *point;
- PTCacheEditKey *key;
- float mat[4][4];
- int i, k, transformparticle;
- int count = 0, hasselected = 0;
- const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
-
- if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) return;
-
- psys = edit->psys;
-
- if (psys)
- psmd = psys_get_modifier(ob, psys);
-
- for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
- point->flag &= ~PEP_TRANSFORM;
- transformparticle = 0;
-
- if ((point->flag & PEP_HIDE) == 0) {
- for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
- if ((key->flag & PEK_HIDE) == 0) {
- if (key->flag & PEK_SELECT) {
- hasselected = 1;
- transformparticle = 1;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+
+ TransData *td = NULL;
+ TransDataExtension *tx;
+ Object *ob = CTX_data_active_object(C);
+ ParticleEditSettings *pset = PE_settings(t->scene);
+ PTCacheEdit *edit = PE_get_current(t->scene, ob);
+ ParticleSystem *psys = NULL;
+ ParticleSystemModifierData *psmd = NULL;
+ PTCacheEditPoint *point;
+ PTCacheEditKey *key;
+ float mat[4][4];
+ int i, k, transformparticle;
+ int count = 0, hasselected = 0;
+ const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
+
+ if (edit == NULL || t->settings->particle.selectmode == SCE_SELECT_PATH) return;
+
+ psys = edit->psys;
+
+ if (psys)
+ psmd = psys_get_modifier(ob, psys);
+
+ for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
+ point->flag &= ~PEP_TRANSFORM;
+ transformparticle = 0;
+
+ if ((point->flag & PEP_HIDE) == 0) {
+ for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
+ if ((key->flag & PEK_HIDE) == 0) {
+ if (key->flag & PEK_SELECT) {
+ hasselected = 1;
+ transformparticle = 1;
+ }
+ else if (is_prop_edit)
+ transformparticle = 1;
}
- else if (is_prop_edit)
- transformparticle = 1;
}
}
- }
- if (transformparticle) {
- count += point->totkey;
- point->flag |= PEP_TRANSFORM;
+ if (transformparticle) {
+ count += point->totkey;
+ point->flag |= PEP_TRANSFORM;
+ }
}
- }
- /* note: in prop mode we need at least 1 selected */
- if (hasselected == 0) return;
+ /* note: in prop mode we need at least 1 selected */
+ if (hasselected == 0) return;
- t->total = count;
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Particle Mode)");
+ tc->data_len = count;
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Particle Mode)");
- if (t->mode == TFM_BAKE_TIME)
- tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "Particle_TransExtension");
- else
- tx = t->ext = NULL;
+ if (t->mode == TFM_BAKE_TIME)
+ tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "Particle_TransExtension");
+ else
+ tx = tc->data_ext = NULL;
- unit_m4(mat);
+ unit_m4(mat);
- invert_m4_m4(ob->imat, ob->obmat);
+ invert_m4_m4(ob->imat, ob->obmat);
- for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
- TransData *head, *tail;
- head = tail = td;
+ for (i = 0, point = edit->points; i < edit->totpoint; i++, point++) {
+ TransData *head, *tail;
+ head = tail = td;
- if (!(point->flag & PEP_TRANSFORM)) continue;
+ if (!(point->flag & PEP_TRANSFORM)) continue;
- if (psys && !(psys->flag & PSYS_GLOBAL_HAIR))
- psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat);
+ if (psys && !(psys->flag & PSYS_GLOBAL_HAIR))
+ psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat);
- for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
- if (key->flag & PEK_USE_WCO) {
- copy_v3_v3(key->world_co, key->co);
- mul_m4_v3(mat, key->world_co);
- td->loc = key->world_co;
- }
- else
- td->loc = key->co;
+ for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
+ if (key->flag & PEK_USE_WCO) {
+ copy_v3_v3(key->world_co, key->co);
+ mul_m4_v3(mat, key->world_co);
+ td->loc = key->world_co;
+ }
+ else
+ td->loc = key->co;
- copy_v3_v3(td->iloc, td->loc);
- copy_v3_v3(td->center, td->loc);
+ copy_v3_v3(td->iloc, td->loc);
+ copy_v3_v3(td->center, td->loc);
- if (key->flag & PEK_SELECT)
- td->flag |= TD_SELECTED;
- else if (!is_prop_edit)
- td->flag |= TD_SKIP;
+ if (key->flag & PEK_SELECT)
+ td->flag |= TD_SELECTED;
+ else if (!is_prop_edit)
+ td->flag |= TD_SKIP;
- unit_m3(td->mtx);
- unit_m3(td->smtx);
+ unit_m3(td->mtx);
+ unit_m3(td->smtx);
- /* don't allow moving roots */
- if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR)))
- td->protectflag |= OB_LOCK_LOC;
+ /* don't allow moving roots */
+ if (k == 0 && pset->flag & PE_LOCK_FIRST && (!psys || !(psys->flag & PSYS_GLOBAL_HAIR)))
+ td->protectflag |= OB_LOCK_LOC;
- td->ob = ob;
- td->ext = tx;
- if (t->mode == TFM_BAKE_TIME) {
- td->val = key->time;
- td->ival = *(key->time);
- /* abuse size and quat for min/max values */
- td->flag |= TD_NO_EXT;
- if (k == 0) tx->size = NULL;
- else tx->size = (key - 1)->time;
+ td->ob = ob;
+ td->ext = tx;
+ if (t->mode == TFM_BAKE_TIME) {
+ td->val = key->time;
+ td->ival = *(key->time);
+ /* abuse size and quat for min/max values */
+ td->flag |= TD_NO_EXT;
+ if (k == 0) tx->size = NULL;
+ else tx->size = (key - 1)->time;
- if (k == point->totkey - 1) tx->quat = NULL;
- else tx->quat = (key + 1)->time;
- }
+ if (k == point->totkey - 1) tx->quat = NULL;
+ else tx->quat = (key + 1)->time;
+ }
- td++;
- if (tx)
- tx++;
- tail++;
+ td++;
+ if (tx)
+ tx++;
+ tail++;
+ }
+ if (is_prop_edit && head != tail)
+ calc_distanceCurveVerts(head, tail - 1);
}
- if (is_prop_edit && head != tail)
- calc_distanceCurveVerts(head, tail - 1);
}
}
void flushTransParticles(TransInfo *t)
{
- Scene *scene = t->scene;
- Object *ob = OBACT;
- PTCacheEdit *edit = PE_get_current(scene, ob);
- ParticleSystem *psys = edit->psys;
- ParticleSystemModifierData *psmd = NULL;
- PTCacheEditPoint *point;
- PTCacheEditKey *key;
- TransData *td;
- float mat[4][4], imat[4][4], co[3];
- int i, k;
- const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
-
- if (psys)
- psmd = psys_get_modifier(ob, psys);
-
- /* we do transform in world space, so flush world space position
- * back to particle local space (only for hair particles) */
- td = t->data;
- for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) {
- if (!(point->flag & PEP_TRANSFORM)) continue;
-
- if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
- psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat);
- invert_m4_m4(imat, mat);
-
- for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
- copy_v3_v3(co, key->world_co);
- mul_m4_v3(imat, co);
-
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- /* optimization for proportional edit */
- if (!is_prop_edit || !compare_v3v3(key->co, co, 0.0001f)) {
- copy_v3_v3(key->co, co);
- point->flag |= PEP_EDIT_RECALC;
+ Scene *scene = t->scene;
+ ViewLayer *view_layer = t->view_layer;
+ Object *ob = OBACT(view_layer);
+ PTCacheEdit *edit = PE_get_current(scene, ob);
+ ParticleSystem *psys = edit->psys;
+ ParticleSystemModifierData *psmd = NULL;
+ PTCacheEditPoint *point;
+ PTCacheEditKey *key;
+ TransData *td;
+ float mat[4][4], imat[4][4], co[3];
+ int i, k;
+ const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
+
+ if (psys)
+ psmd = psys_get_modifier(ob, psys);
+
+ /* we do transform in world space, so flush world space position
+ * back to particle local space (only for hair particles) */
+ td = tc->data;
+ for (i = 0, point = edit->points; i < edit->totpoint; i++, point++, td++) {
+ if (!(point->flag & PEP_TRANSFORM)) continue;
+
+ if (psys && !(psys->flag & PSYS_GLOBAL_HAIR)) {
+ psys_mat_hair_to_global(ob, psmd->dm_final, psys->part->from, psys->particles + i, mat);
+ invert_m4_m4(imat, mat);
+
+ for (k = 0, key = point->keys; k < point->totkey; k++, key++) {
+ copy_v3_v3(co, key->world_co);
+ mul_m4_v3(imat, co);
+
+
+ /* optimization for proportional edit */
+ if (!is_prop_edit || !compare_v3v3(key->co, co, 0.0001f)) {
+ copy_v3_v3(key->co, co);
+ point->flag |= PEP_EDIT_RECALC;
+ }
}
}
+ else
+ point->flag |= PEP_EDIT_RECALC;
}
- else
- point->flag |= PEP_EDIT_RECALC;
- }
- PE_update_object(scene, OBACT, 1);
+ PE_update_object(t->depsgraph, scene, OBACT(view_layer), 1);
+ }
}
/* ********************* mesh ****************** */
@@ -2472,243 +2531,248 @@ static void VertsToTransData(TransInfo *t, TransData *td, TransDataExtension *tx
static void createTransEditVerts(TransInfo *t)
{
- TransData *tob = NULL;
- TransDataExtension *tx = NULL;
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
- Mesh *me = t->obedit->data;
- BMesh *bm = em->bm;
- BMVert *eve;
- BMIter iter;
- float (*mappedcos)[3] = NULL, (*quats)[4] = NULL;
- float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL;
- float *dists = NULL;
- int a;
- const int prop_mode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0;
- int mirror = 0;
- int cd_vert_bweight_offset = -1;
- bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- struct TransIslandData *island_info = NULL;
- int island_info_tot;
- int *island_vert_map = NULL;
+ TransData *tob = NULL;
+ TransDataExtension *tx = NULL;
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
+ Mesh *me = tc->obedit->data;
+ BMesh *bm = em->bm;
+ BMVert *eve;
+ BMIter iter;
+ float (*mappedcos)[3] = NULL, (*quats)[4] = NULL;
+ float mtx[3][3], smtx[3][3], (*defmats)[3][3] = NULL, (*defcos)[3] = NULL;
+ float *dists = NULL;
+ int a;
+ const int prop_mode = (t->flag & T_PROP_EDIT) ? (t->flag & T_PROP_EDIT_ALL) : 0;
+ int mirror = 0;
+ int cd_vert_bweight_offset = -1;
+ bool use_topology = (me->editflag & ME_EDIT_MIRROR_TOPO) != 0;
- /* Even for translation this is needed because of island-orientation, see: T51651. */
- const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS);
- /* Original index of our connected vertex when connected distances are calculated.
- * Optional, allocate if needed. */
- int *dists_index = NULL;
+ struct TransIslandData *island_info = NULL;
+ int island_info_tot;
+ int *island_vert_map = NULL;
- if (t->flag & T_MIRROR) {
- EDBM_verts_mirror_cache_begin(em, 0, false, (t->flag & T_PROP_EDIT) == 0, use_topology);
- mirror = 1;
- }
+ /* Even for translation this is needed because of island-orientation, see: T51651. */
+ const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS);
+ /* Original index of our connected vertex when connected distances are calculated.
+ * Optional, allocate if needed. */
+ int *dists_index = NULL;
- /**
- * Quick check if we can transform.
- *
- * \note ignore modes here, even in edge/face modes, transform data is created by selected vertices.
- * \note in prop mode we need at least 1 selected.
- */
- if (bm->totvertsel == 0) {
- goto cleanup;
- }
+ if (t->flag & T_MIRROR) {
+ /* TODO(campbell): xform: We need support for many mirror objects at once! */
+ if (tc->is_active) {
+ EDBM_verts_mirror_cache_begin(em, 0, false, (t->flag & T_PROP_EDIT) == 0, use_topology);
+ mirror = 1;
+ }
+ }
- if (t->mode == TFM_BWEIGHT) {
- BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(t->obedit), ME_CDFLAG_VERT_BWEIGHT);
- cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
- }
+ /**
+ * Quick check if we can transform.
+ *
+ * \note ignore modes here, even in edge/face modes, transform data is created by selected vertices.
+ * \note in prop mode we need at least 1 selected.
+ */
+ if (bm->totvertsel == 0) {
+ goto cleanup;
+ }
- if (prop_mode) {
- unsigned int count = 0;
- BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
- if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
- count++;
- }
+ if (t->mode == TFM_BWEIGHT) {
+ BM_mesh_cd_flag_ensure(bm, BKE_mesh_from_object(tc->obedit), ME_CDFLAG_VERT_BWEIGHT);
+ cd_vert_bweight_offset = CustomData_get_offset(&bm->vdata, CD_BWEIGHT);
}
- t->total = count;
+ if (prop_mode) {
+ unsigned int count = 0;
+ BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
+ if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+ count++;
+ }
+ }
+
+ tc->data_len = count;
- /* allocating scratch arrays */
- if (prop_mode & T_PROP_CONNECTED) {
- dists = MEM_mallocN(em->bm->totvert * sizeof(float), __func__);
- if (is_island_center) {
- dists_index = MEM_mallocN(em->bm->totvert * sizeof(int), __func__);
+ /* allocating scratch arrays */
+ if (prop_mode & T_PROP_CONNECTED) {
+ dists = MEM_mallocN(em->bm->totvert * sizeof(float), __func__);
+ if (is_island_center) {
+ dists_index = MEM_mallocN(em->bm->totvert * sizeof(int), __func__);
+ }
}
}
- }
- else {
- t->total = bm->totvertsel;
- }
-
- tob = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Mesh EditMode)");
- if (ELEM(t->mode, TFM_SKIN_RESIZE, TFM_SHRINKFATTEN)) {
- /* warning, this is overkill, we only need 2 extra floats,
- * but this stores loads of extra stuff, for TFM_SHRINKFATTEN its even more overkill
- * since we may not use the 'alt' transform mode to maintain shell thickness,
- * but with generic transform code its hard to lazy init vars */
- tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension),
- "TransObData ext");
- }
+ else {
+ tc->data_len = bm->totvertsel;
+ }
- copy_m3_m4(mtx, t->obedit->obmat);
- /* we use a pseudoinverse so that when one of the axes is scaled to 0,
- * matrix inversion still works and we can still moving along the other */
- pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
+ tob = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Mesh EditMode)");
+ if (ELEM(t->mode, TFM_SKIN_RESIZE, TFM_SHRINKFATTEN)) {
+ /* warning, this is overkill, we only need 2 extra floats,
+ * but this stores loads of extra stuff, for TFM_SHRINKFATTEN its even more overkill
+ * since we may not use the 'alt' transform mode to maintain shell thickness,
+ * but with generic transform code its hard to lazy init vars */
+ tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "TransObData ext");
+ }
- if (prop_mode & T_PROP_CONNECTED) {
- editmesh_set_connectivity_distance(em->bm, mtx, dists, dists_index);
- }
+ copy_m3_m4(mtx, tc->obedit->obmat);
+ /* we use a pseudoinverse so that when one of the axes is scaled to 0,
+ * matrix inversion still works and we can still moving along the other */
+ pseudoinverse_m3_m3(smtx, mtx, PSEUDOINVERSE_EPSILON);
- if (is_island_center) {
- /* In this specific case, near-by vertices will need to know the island of the nearest connected vertex. */
- const bool calc_single_islands = (
- (prop_mode & T_PROP_CONNECTED) &&
- (t->around == V3D_AROUND_LOCAL_ORIGINS) &&
- (em->selectmode & SCE_SELECT_VERTEX));
+ if (prop_mode & T_PROP_CONNECTED) {
+ editmesh_set_connectivity_distance(em->bm, mtx, dists, dists_index);
+ }
- island_info = editmesh_islands_info_calc(em, &island_info_tot, &island_vert_map, calc_single_islands);
- }
+ if (is_island_center) {
+ /* In this specific case, near-by vertices will need to know the island of the nearest connected vertex. */
+ const bool calc_single_islands = (
+ (prop_mode & T_PROP_CONNECTED) &&
+ (t->around == V3D_AROUND_LOCAL_ORIGINS) &&
+ (em->selectmode & SCE_SELECT_VERTEX));
- /* detect CrazySpace [tm] */
- if (modifiers_getCageIndex(t->scene, t->obedit, NULL, 1) != -1) {
- int totleft = -1;
- if (modifiers_isCorrectableDeformed(t->scene, t->obedit)) {
- /* check if we can use deform matrices for modifier from the
- * start up to stack, they are more accurate than quats */
- totleft = BKE_crazyspace_get_first_deform_matrices_editbmesh(t->scene, t->obedit, em, &defmats, &defcos);
+ island_info = editmesh_islands_info_calc(em, &island_info_tot, &island_vert_map, calc_single_islands);
}
- /* if we still have more modifiers, also do crazyspace
- * correction with quats, relative to the coordinates after
- * the modifiers that support deform matrices (defcos) */
+ /* detect CrazySpace [tm] */
+ if (modifiers_getCageIndex(t->scene, tc->obedit, NULL, 1) != -1) {
+ int totleft = -1;
+ if (modifiers_isCorrectableDeformed(t->scene, tc->obedit)) {
+ /* check if we can use deform matrices for modifier from the
+ * start up to stack, they are more accurate than quats */
+ totleft = BKE_crazyspace_get_first_deform_matrices_editbmesh(t->depsgraph, t->scene, tc->obedit, em, &defmats, &defcos);
+ }
+
+ /* if we still have more modifiers, also do crazyspace
+ * correction with quats, relative to the coordinates after
+ * the modifiers that support deform matrices (defcos) */
#if 0 /* TODO, fix crazyspace+extrude so it can be enabled for general use - campbell */
- if ((totleft > 0) || (totleft == -1))
+ if ((totleft > 0) || (totleft == -1))
#else
- if (totleft > 0)
+ if (totleft > 0)
#endif
- {
- mappedcos = BKE_crazyspace_get_mapped_editverts(t->scene, t->obedit);
- quats = MEM_mallocN(em->bm->totvert * sizeof(*quats), "crazy quats");
- BKE_crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !prop_mode);
- if (mappedcos)
- MEM_freeN(mappedcos);
- }
+ {
+ mappedcos = BKE_crazyspace_get_mapped_editverts(t->depsgraph, t->scene, tc->obedit);
+ quats = MEM_mallocN(em->bm->totvert * sizeof(*quats), "crazy quats");
+ BKE_crazyspace_set_quats_editmesh(em, defcos, mappedcos, quats, !prop_mode);
+ if (mappedcos)
+ MEM_freeN(mappedcos);
+ }
- if (defcos) {
- MEM_freeN(defcos);
+ if (defcos) {
+ MEM_freeN(defcos);
+ }
}
- }
- /* find out which half we do */
- if (mirror) {
- BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
- if (BM_elem_flag_test(eve, BM_ELEM_SELECT) && eve->co[0] != 0.0f) {
- if (eve->co[0] < 0.0f) {
- t->mirror = -1;
- mirror = -1;
+ /* find out which half we do */
+ if (mirror) {
+ BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
+ if (BM_elem_flag_test(eve, BM_ELEM_SELECT) && eve->co[0] != 0.0f) {
+ if (eve->co[0] < 0.0f) {
+ t->mirror = -1;
+ mirror = -1;
+ }
+ break;
}
- break;
}
}
- }
- BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, a) {
- if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
- if (prop_mode || BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
- struct TransIslandData *v_island = NULL;
- float *bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_VOID_P(eve, cd_vert_bweight_offset) : NULL;
-
- if (island_info) {
- const int connected_index = (dists_index && dists_index[a] != -1) ? dists_index[a] : a;
- v_island = (island_vert_map[connected_index] != -1) ?
- &island_info[island_vert_map[connected_index]] : NULL;
- }
+ BM_ITER_MESH_INDEX (eve, &iter, bm, BM_VERTS_OF_MESH, a) {
+ if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+ if (prop_mode || BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
+ struct TransIslandData *v_island = NULL;
+ float *bweight = (cd_vert_bweight_offset != -1) ? BM_ELEM_CD_GET_VOID_P(eve, cd_vert_bweight_offset) : NULL;
+
+ if (island_info) {
+ const int connected_index = (dists_index && dists_index[a] != -1) ? dists_index[a] : a;
+ v_island = (island_vert_map[connected_index] != -1) ?
+ &island_info[island_vert_map[connected_index]] : NULL;
+ }
- VertsToTransData(t, tob, tx, em, eve, bweight, v_island);
- if (tx)
- tx++;
+ VertsToTransData(t, tob, tx, em, eve, bweight, v_island);
+ if (tx)
+ tx++;
- /* selected */
- if (BM_elem_flag_test(eve, BM_ELEM_SELECT))
- tob->flag |= TD_SELECTED;
+ /* selected */
+ if (BM_elem_flag_test(eve, BM_ELEM_SELECT))
+ tob->flag |= TD_SELECTED;
- if (prop_mode) {
- if (prop_mode & T_PROP_CONNECTED) {
- tob->dist = dists[a];
- }
- else {
- tob->flag |= TD_NOTCONNECTED;
- tob->dist = FLT_MAX;
+ if (prop_mode) {
+ if (prop_mode & T_PROP_CONNECTED) {
+ tob->dist = dists[a];
+ }
+ else {
+ tob->flag |= TD_NOTCONNECTED;
+ tob->dist = FLT_MAX;
+ }
}
- }
- /* CrazySpace */
- if (defmats || (quats && BM_elem_flag_test(eve, BM_ELEM_TAG))) {
- float mat[3][3], qmat[3][3], imat[3][3];
+ /* CrazySpace */
+ if (defmats || (quats && BM_elem_flag_test(eve, BM_ELEM_TAG))) {
+ float mat[3][3], qmat[3][3], imat[3][3];
- /* use both or either quat and defmat correction */
- if (quats && BM_elem_flag_test(eve, BM_ELEM_TAG)) {
- quat_to_mat3(qmat, quats[BM_elem_index_get(eve)]);
+ /* use both or either quat and defmat correction */
+ if (quats && BM_elem_flag_test(eve, BM_ELEM_TAG)) {
+ quat_to_mat3(qmat, quats[BM_elem_index_get(eve)]);
- if (defmats)
- mul_m3_series(mat, defmats[a], qmat, mtx);
+ if (defmats)
+ mul_m3_series(mat, defmats[a], qmat, mtx);
+ else
+ mul_m3_m3m3(mat, mtx, qmat);
+ }
else
- mul_m3_m3m3(mat, mtx, qmat);
- }
- else
- mul_m3_m3m3(mat, mtx, defmats[a]);
+ mul_m3_m3m3(mat, mtx, defmats[a]);
- invert_m3_m3(imat, mat);
+ invert_m3_m3(imat, mat);
- copy_m3_m3(tob->smtx, imat);
- copy_m3_m3(tob->mtx, mat);
- }
- else {
- copy_m3_m3(tob->smtx, smtx);
- copy_m3_m3(tob->mtx, mtx);
- }
+ copy_m3_m3(tob->smtx, imat);
+ copy_m3_m3(tob->mtx, mat);
+ }
+ else {
+ copy_m3_m3(tob->smtx, smtx);
+ copy_m3_m3(tob->mtx, mtx);
+ }
- /* Mirror? */
- if ((mirror > 0 && tob->iloc[0] > 0.0f) || (mirror < 0 && tob->iloc[0] < 0.0f)) {
- BMVert *vmir = EDBM_verts_mirror_get(em, eve); //t->obedit, em, eve, tob->iloc, a);
- if (vmir && vmir != eve) {
- tob->extra = vmir;
+ /* Mirror? */
+ if ((mirror > 0 && tob->iloc[0] > 0.0f) || (mirror < 0 && tob->iloc[0] < 0.0f)) {
+ BMVert *vmir = EDBM_verts_mirror_get(em, eve); //t->obedit, em, eve, tob->iloc, a);
+ if (vmir && vmir != eve) {
+ tob->extra = vmir;
+ }
}
+ tob++;
}
- tob++;
}
}
- }
-
- if (island_info) {
- MEM_freeN(island_info);
- MEM_freeN(island_vert_map);
- }
- if (mirror != 0) {
- tob = t->data;
- for (a = 0; a < t->total; a++, tob++) {
- if (ABS(tob->loc[0]) <= 0.00001f) {
- tob->flag |= TD_MIRROR_EDGE;
+ if (island_info) {
+ MEM_freeN(island_info);
+ MEM_freeN(island_vert_map);
+ }
+
+ if (mirror != 0) {
+ tob = tc->data;
+ for (a = 0; a < tc->data_len; a++, tob++) {
+ if (ABS(tob->loc[0]) <= 0.00001f) {
+ tob->flag |= TD_MIRROR_EDGE;
+ }
}
}
- }
cleanup:
- /* crazy space free */
- if (quats)
- MEM_freeN(quats);
- if (defmats)
- MEM_freeN(defmats);
- if (dists)
- MEM_freeN(dists);
- if (dists_index)
- MEM_freeN(dists_index);
-
- if (t->flag & T_MIRROR) {
- EDBM_verts_mirror_cache_end(em);
+ /* crazy space free */
+ if (quats)
+ MEM_freeN(quats);
+ if (defmats)
+ MEM_freeN(defmats);
+ if (dists)
+ MEM_freeN(dists);
+ if (dists_index)
+ MEM_freeN(dists_index);
+
+ if (t->flag & T_MIRROR) {
+ EDBM_verts_mirror_cache_end(em);
+ }
}
}
@@ -2716,40 +2780,43 @@ cleanup:
void flushTransNodes(TransInfo *t)
{
const float dpi_fac = UI_DPI_FAC;
- int a;
- TransData *td;
- TransData2D *td2d;
-
- applyGridAbsolute(t);
-
- /* flush to 2d vector from internally used 3d vector */
- for (a = 0, td = t->data, td2d = t->data2d; a < t->total; a++, td++, td2d++) {
- bNode *node = td->extra;
- float locx, locy;
- /* weirdo - but the node system is a mix of free 2d elements and dpi sensitive UI */
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ int a;
+ TransData *td;
+ TransData2D *td2d;
+
+ applyGridAbsolute(t);
+
+ /* flush to 2d vector from internally used 3d vector */
+ for (a = 0, td = tc->data, td2d = tc->data_2d; a < tc->data_len; a++, td++, td2d++) {
+ bNode *node = td->extra;
+ float locx, locy;
+
+ /* weirdo - but the node system is a mix of free 2d elements and dpi sensitive UI */
#ifdef USE_NODE_CENTER
- locx = (td2d->loc[0] - (BLI_rctf_size_x(&node->totr)) * +0.5f) / dpi_fac;
- locy = (td2d->loc[1] - (BLI_rctf_size_y(&node->totr)) * -0.5f) / dpi_fac;
+ locx = (td2d->loc[0] - (BLI_rctf_size_x(&node->totr)) * +0.5f) / dpi_fac;
+ locy = (td2d->loc[1] - (BLI_rctf_size_y(&node->totr)) * -0.5f) / dpi_fac;
#else
- locx = td2d->loc[0] / dpi_fac;
- locy = td2d->loc[1] / dpi_fac;
+ locx = td2d->loc[0] / dpi_fac;
+ locy = td2d->loc[1] / dpi_fac;
#endif
-
- /* account for parents (nested nodes) */
- if (node->parent) {
- nodeFromView(node->parent, locx, locy, &node->locx, &node->locy);
+
+ /* account for parents (nested nodes) */
+ if (node->parent) {
+ nodeFromView(node->parent, locx, locy, &node->locx, &node->locy);
+ }
+ else {
+ node->locx = locx;
+ node->locy = locy;
+ }
}
- else {
- node->locx = locx;
- node->locy = locy;
+
+ /* handle intersection with noodles */
+ if (tc->data_len == 1) {
+ ED_node_link_intersect_test(t->sa, 1);
}
}
-
- /* handle intersection with noodles */
- if (t->total == 1) {
- ED_node_link_intersect_test(t->sa, 1);
- }
}
/* *** SEQUENCE EDITOR *** */
@@ -2778,13 +2845,14 @@ BLI_INLINE void trans_update_seq(Scene *sce, Sequence *seq, int old_start, int s
void flushTransSeq(TransInfo *t)
{
ListBase *seqbasep = BKE_sequencer_editing_get(t->scene, false)->seqbasep; /* Editing null check already done */
+
int a, new_frame;
TransData *td = NULL;
TransData2D *td2d = NULL;
TransDataSeq *tdsq = NULL;
Sequence *seq;
-
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
/* prevent updating the same seq twice
* if the transdata order is changed this will mess up
@@ -2793,7 +2861,7 @@ void flushTransSeq(TransInfo *t)
int old_start_prev = 0, sel_flag_prev = 0;
/* flush to 2d vector from internally used 3d vector */
- for (a = 0, td = t->data, td2d = t->data2d; a < t->total; a++, td++, td2d++) {
+ for (a = 0, td = tc->data, td2d = tc->data_2d; a < tc->data_len; a++, td++, td2d++) {
int old_start;
tdsq = (TransDataSeq *)td->extra;
seq = tdsq->seq;
@@ -2866,8 +2934,8 @@ void flushTransSeq(TransInfo *t)
}
/* update effects inside meta's */
- for (a = 0, seq_prev = NULL, td = t->data, td2d = t->data2d;
- a < t->total;
+ for (a = 0, seq_prev = NULL, td = tc->data, td2d = tc->data_2d;
+ a < tc->data_len;
a++, td++, td2d++, seq_prev = seq)
{
tdsq = (TransDataSeq *)td->extra;
@@ -2883,7 +2951,7 @@ void flushTransSeq(TransInfo *t)
/* need to do the overlap check in a new loop otherwise adjacent strips
* will not be updated and we'll get false positives */
seq_prev = NULL;
- for (a = 0, td = t->data, td2d = t->data2d; a < t->total; a++, td++, td2d++) {
+ for (a = 0, td = tc->data, td2d = tc->data_2d; a < tc->data_len; a++, td++, td2d++) {
tdsq = (TransDataSeq *)td->extra;
seq = tdsq->seq;
@@ -2944,159 +3012,167 @@ static void createTransUVs(bContext *C, TransInfo *t)
Image *ima = CTX_data_edit_image(C);
Scene *scene = t->scene;
ToolSettings *ts = CTX_data_tool_settings(C);
- TransData *td = NULL;
- TransData2D *td2d = NULL;
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
- BMFace *efa;
- BMIter iter, liter;
- UvElementMap *elementmap = NULL;
- BLI_bitmap *island_enabled = NULL;
- struct { float co[2]; int co_num; } *island_center = NULL;
- int count = 0, countsel = 0, count_rejected = 0;
+
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
const bool is_prop_connected = (t->flag & T_PROP_CONNECTED) != 0;
const bool is_island_center = (t->around == V3D_AROUND_LOCAL_ORIGINS);
- const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
- if (!ED_space_image_show_uvedit(sima, t->obedit))
- return;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- /* count */
- if (is_prop_connected || is_island_center) {
- /* create element map with island information */
- const bool use_facesel = (ts->uv_flag & UV_SYNC_SELECTION) == 0;
- elementmap = BM_uv_element_map_create(em->bm, use_facesel, false, true);
- if (elementmap == NULL) {
- return;
- }
+ TransData *td = NULL;
+ TransData2D *td2d = NULL;
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
+ BMFace *efa;
+ BMIter iter, liter;
+ UvElementMap *elementmap = NULL;
+ BLI_bitmap *island_enabled = NULL;
+ struct { float co[2]; int co_num; } *island_center = NULL;
+ int count = 0, countsel = 0, count_rejected = 0;
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- if (is_prop_connected) {
- island_enabled = BLI_BITMAP_NEW(elementmap->totalIslands, "TransIslandData(UV Editing)");
+ if (!ED_space_image_show_uvedit(sima, tc->obedit)) {
+ continue;
}
- if (is_island_center) {
- island_center = MEM_callocN(sizeof(*island_center) * elementmap->totalIslands, __func__);
- }
- }
+ /* count */
+ if (is_prop_connected || is_island_center) {
+ /* create element map with island information */
+ const bool use_facesel = (ts->uv_flag & UV_SYNC_SELECTION) == 0;
+ elementmap = BM_uv_element_map_create(em->bm, use_facesel, false, true);
+ if (elementmap == NULL) {
+ return;
+ }
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- BMLoop *l;
+ if (is_prop_connected) {
+ island_enabled = BLI_BITMAP_NEW(elementmap->totalIslands, "TransIslandData(UV Editing)");
+ }
- if (!uvedit_face_visible_test(scene, ima, efa, tf)) {
- BM_elem_flag_disable(efa, BM_ELEM_TAG);
- continue;
+ if (is_island_center) {
+ island_center = MEM_callocN(sizeof(*island_center) * elementmap->totalIslands, __func__);
+ }
}
- BM_elem_flag_enable(efa, BM_ELEM_TAG);
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
- countsel++;
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ BMLoop *l;
- if (is_prop_connected || island_center) {
- UvElement *element = BM_uv_element_get(elementmap, efa, l);
+ if (!uvedit_face_visible_test(scene, tc->obedit, ima, efa)) {
+ BM_elem_flag_disable(efa, BM_ELEM_TAG);
+ continue;
+ }
- if (is_prop_connected) {
- BLI_BITMAP_ENABLE(island_enabled, element->island);
- }
+ BM_elem_flag_enable(efa, BM_ELEM_TAG);
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
+ countsel++;
- if (is_island_center) {
- if (element->flag == false) {
- MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- add_v2_v2(island_center[element->island].co, luv->uv);
- island_center[element->island].co_num++;
- element->flag = true;
+ if (is_prop_connected || island_center) {
+ UvElement *element = BM_uv_element_get(elementmap, efa, l);
+
+ if (is_prop_connected) {
+ BLI_BITMAP_ENABLE(island_enabled, element->island);
+ }
+
+ if (is_island_center) {
+ if (element->flag == false) {
+ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ add_v2_v2(island_center[element->island].co, luv->uv);
+ island_center[element->island].co_num++;
+ element->flag = true;
+ }
}
}
}
- }
- if (is_prop_edit) {
- count++;
+ if (is_prop_edit) {
+ count++;
+ }
}
}
- }
- /* note: in prop mode we need at least 1 selected */
- if (countsel == 0) {
- goto finally;
- }
+ /* note: in prop mode we need at least 1 selected */
+ if (countsel == 0) {
+ goto finally;
+ }
- if (is_island_center) {
- int i;
+ if (is_island_center) {
+ int i;
- for (i = 0; i < elementmap->totalIslands; i++) {
- mul_v2_fl(island_center[i].co, 1.0f / island_center[i].co_num);
- mul_v2_v2(island_center[i].co, t->aspect);
+ for (i = 0; i < elementmap->totalIslands; i++) {
+ mul_v2_fl(island_center[i].co, 1.0f / island_center[i].co_num);
+ mul_v2_v2(island_center[i].co, t->aspect);
+ }
}
- }
- t->total = (is_prop_edit) ? count : countsel;
- t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(UV Editing)");
- /* for each 2d uv coord a 3d vector is allocated, so that they can be
- * treated just as if they were 3d verts */
- t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransObData2D(UV Editing)");
+ tc->data_len = (is_prop_edit) ? count : countsel;
+ tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(UV Editing)");
+ /* for each 2d uv coord a 3d vector is allocated, so that they can be
+ * treated just as if they were 3d verts */
+ tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransObData2D(UV Editing)");
- if (sima->flag & SI_CLIP_UV)
- t->flag |= T_CLIP_UV;
+ if (sima->flag & SI_CLIP_UV)
+ t->flag |= T_CLIP_UV;
- td = t->data;
- td2d = t->data2d;
+ td = tc->data;
+ td2d = tc->data_2d;
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- BMLoop *l;
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ BMLoop *l;
- if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
- continue;
+ if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
+ continue;
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- const bool selected = uvedit_uv_select_test(scene, l, cd_loop_uv_offset);
- MLoopUV *luv;
- const float *center = NULL;
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ const bool selected = uvedit_uv_select_test(scene, l, cd_loop_uv_offset);
+ MLoopUV *luv;
+ const float *center = NULL;
- if (!is_prop_edit && !selected)
- continue;
+ if (!is_prop_edit && !selected)
+ continue;
- if (is_prop_connected || is_island_center) {
- UvElement *element = BM_uv_element_get(elementmap, efa, l);
+ if (is_prop_connected || is_island_center) {
+ UvElement *element = BM_uv_element_get(elementmap, efa, l);
- if (is_prop_connected) {
- if (!BLI_BITMAP_TEST(island_enabled, element->island)) {
- count_rejected++;
- continue;
+ if (is_prop_connected) {
+ if (!BLI_BITMAP_TEST(island_enabled, element->island)) {
+ count_rejected++;
+ continue;
+ }
}
- }
- if (is_island_center) {
- center = island_center[element->island].co;
+ if (is_island_center) {
+ center = island_center[element->island].co;
+ }
}
+
+ BM_elem_flag_enable(l, BM_ELEM_TAG);
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ UVsToTransData(t->aspect, td++, td2d++, luv->uv, center, selected);
}
-
- BM_elem_flag_enable(l, BM_ELEM_TAG);
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- UVsToTransData(t->aspect, td++, td2d++, luv->uv, center, selected);
}
- }
-
- if (is_prop_connected) {
- t->total -= count_rejected;
- }
- if (sima->flag & SI_LIVE_UNWRAP)
- ED_uvedit_live_unwrap_begin(t->scene, t->obedit);
+ if (is_prop_connected) {
+ tc->data_len -= count_rejected;
+ }
+ if (sima->flag & SI_LIVE_UNWRAP) {
+ /* TODO(campbell): xform: Only active object currently!
+ * it uses a static variable. */
+ if (tc->is_active) {
+ ED_uvedit_live_unwrap_begin(t->scene, tc->obedit);
+ }
+ }
finally:
- if (is_prop_connected || is_island_center) {
- BM_uv_element_map_free(elementmap);
+ if (is_prop_connected || is_island_center) {
+ BM_uv_element_map_free(elementmap);
- if (is_prop_connected) {
- MEM_freeN(island_enabled);
- }
+ if (is_prop_connected) {
+ MEM_freeN(island_enabled);
+ }
- if (island_center) {
- MEM_freeN(island_center);
+ if (island_center) {
+ MEM_freeN(island_center);
+ }
}
}
}
@@ -3104,37 +3180,38 @@ finally:
void flushTransUVs(TransInfo *t)
{
SpaceImage *sima = t->sa->spacedata.first;
- TransData2D *td;
- int a;
- float aspect_inv[2], size[2];
const bool use_pixel_snap = ((sima->flag & SI_PIXELSNAP) && (t->state != TRANS_CANCEL));
- aspect_inv[0] = 1.0f / t->aspect[0];
- aspect_inv[1] = 1.0f / t->aspect[1];
-
- if (use_pixel_snap) {
- int size_i[2];
- ED_space_image_get_size(sima, &size_i[0], &size_i[1]);
- size[0] = size_i[0];
- size[1] = size_i[1];
- }
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData2D *td;
+ int a;
+ float aspect_inv[2], size[2];
- /* flush to 2d vector from internally used 3d vector */
- for (a = 0, td = t->data2d; a < t->total; a++, td++) {
- td->loc2d[0] = td->loc[0] * aspect_inv[0];
- td->loc2d[1] = td->loc[1] * aspect_inv[1];
+ aspect_inv[0] = 1.0f / t->aspect[0];
+ aspect_inv[1] = 1.0f / t->aspect[1];
if (use_pixel_snap) {
- td->loc2d[0] = roundf(td->loc2d[0] * size[0]) / size[0];
- td->loc2d[1] = roundf(td->loc2d[1] * size[1]) / size[1];
+ int size_i[2];
+ ED_space_image_get_size(sima, &size_i[0], &size_i[1]);
+ size[0] = size_i[0];
+ size[1] = size_i[1];
+ }
+
+ /* flush to 2d vector from internally used 3d vector */
+ for (a = 0, td = tc->data_2d; a < tc->data_len; a++, td++) {
+ td->loc2d[0] = td->loc[0] * aspect_inv[0];
+ td->loc2d[1] = td->loc[1] * aspect_inv[1];
+
+ if (use_pixel_snap) {
+ td->loc2d[0] = roundf(td->loc2d[0] * size[0]) / size[0];
+ td->loc2d[1] = roundf(td->loc2d[1] * size[1]) / size[1];
+ }
}
}
}
bool clipUVTransform(TransInfo *t, float vec[2], const bool resize)
{
- TransData *td;
- int a;
bool clipx = true, clipy = true;
float min[2], max[2];
@@ -3142,39 +3219,45 @@ bool clipUVTransform(TransInfo *t, float vec[2], const bool resize)
max[0] = t->aspect[0];
max[1] = t->aspect[1];
- for (a = 0, td = t->data; a < t->total; a++, td++) {
- minmax_v2v2_v2(min, max, td->loc);
- }
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- if (resize) {
- if (min[0] < 0.0f && t->center[0] > 0.0f && t->center[0] < t->aspect[0] * 0.5f)
- vec[0] *= t->center[0] / (t->center[0] - min[0]);
- else if (max[0] > t->aspect[0] && t->center[0] < t->aspect[0])
- vec[0] *= (t->center[0] - t->aspect[0]) / (t->center[0] - max[0]);
- else
- clipx = 0;
+ TransData *td;
+ int a;
- if (min[1] < 0.0f && t->center[1] > 0.0f && t->center[1] < t->aspect[1] * 0.5f)
- vec[1] *= t->center[1] / (t->center[1] - min[1]);
- else if (max[1] > t->aspect[1] && t->center[1] < t->aspect[1])
- vec[1] *= (t->center[1] - t->aspect[1]) / (t->center[1] - max[1]);
- else
- clipy = 0;
- }
- else {
- if (min[0] < 0.0f)
- vec[0] -= min[0];
- else if (max[0] > t->aspect[0])
- vec[0] -= max[0] - t->aspect[0];
- else
- clipx = 0;
+ for (a = 0, td = tc->data; a < tc->data_len; a++, td++) {
+ minmax_v2v2_v2(min, max, td->loc);
+ }
- if (min[1] < 0.0f)
- vec[1] -= min[1];
- else if (max[1] > t->aspect[1])
- vec[1] -= max[1] - t->aspect[1];
- else
- clipy = 0;
+ if (resize) {
+ if (min[0] < 0.0f && t->center_global[0] > 0.0f && t->center_global[0] < t->aspect[0] * 0.5f)
+ vec[0] *= t->center_global[0] / (t->center_global[0] - min[0]);
+ else if (max[0] > t->aspect[0] && t->center_global[0] < t->aspect[0])
+ vec[0] *= (t->center_global[0] - t->aspect[0]) / (t->center_global[0] - max[0]);
+ else
+ clipx = 0;
+
+ if (min[1] < 0.0f && t->center_global[1] > 0.0f && t->center_global[1] < t->aspect[1] * 0.5f)
+ vec[1] *= t->center_global[1] / (t->center_global[1] - min[1]);
+ else if (max[1] > t->aspect[1] && t->center_global[1] < t->aspect[1])
+ vec[1] *= (t->center_global[1] - t->aspect[1]) / (t->center_global[1] - max[1]);
+ else
+ clipy = 0;
+ }
+ else {
+ if (min[0] < 0.0f)
+ vec[0] -= min[0];
+ else if (max[0] > t->aspect[0])
+ vec[0] -= max[0] - t->aspect[0];
+ else
+ clipx = 0;
+
+ if (min[1] < 0.0f)
+ vec[1] -= min[1];
+ else if (max[1] > t->aspect[1])
+ vec[1] -= max[1] - t->aspect[1];
+ else
+ clipy = 0;
+ }
}
return (clipx || clipy);
@@ -3182,18 +3265,18 @@ bool clipUVTransform(TransInfo *t, float vec[2], const bool resize)
void clipUVData(TransInfo *t)
{
- TransData *td = NULL;
- int a;
-
- for (a = 0, td = t->data; a < t->total; a++, td++) {
- if (td->flag & TD_NOACTION)
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (int a = 0; a < tc->data_len; a++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
- if ((td->flag & TD_SKIP) || (!td->loc))
- continue;
+ if ((td->flag & TD_SKIP) || (!td->loc))
+ continue;
- td->loc[0] = min_ff(max_ff(0.0f, td->loc[0]), t->aspect[0]);
- td->loc[1] = min_ff(max_ff(0.0f, td->loc[1]), t->aspect[1]);
+ td->loc[0] = min_ff(max_ff(0.0f, td->loc[0]), t->aspect[0]);
+ td->loc[1] = min_ff(max_ff(0.0f, td->loc[1]), t->aspect[1]);
+ }
}
}
@@ -3227,7 +3310,9 @@ static void createTransNlaData(bContext *C, TransInfo *t)
int filter;
int count = 0;
-
+
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* determine what type of data we are operating on */
if (ANIM_animdata_get_context(C, &ac) == 0)
return;
@@ -3287,12 +3372,12 @@ static void createTransNlaData(bContext *C, TransInfo *t)
}
/* allocate memory for data */
- t->total = count;
+ tc->data_len = count;
- t->data = MEM_callocN(t->total * sizeof(TransData), "TransData(NLA Editor)");
- td = t->data;
- t->custom.type.data = tdn = MEM_callocN(t->total * sizeof(TransDataNla), "TransDataNla (NLA Editor)");
- t->custom.type.use_free = true;
+ tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData(NLA Editor)");
+ td = tc->data;
+ tc->custom.type.data = tdn = MEM_callocN(tc->data_len * sizeof(TransDataNla), "TransDataNla (NLA Editor)");
+ tc->custom.type.use_free = true;
/* loop 2: build transdata array */
for (ale = anim_data.first; ale; ale = ale->next) {
@@ -3822,11 +3907,11 @@ typedef struct tGPFtransdata {
/* This function helps flush transdata written to tempdata into the gp-frames */
void flushTransIntFrameActionData(TransInfo *t)
{
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
tGPFtransdata *tfd = t->custom.type.data;
- int i;
/* flush data! */
- for (i = 0; i < t->total; i++, tfd++) {
+ for (int i = 0; i < tc->data_len; i++, tfd++) {
*(tfd->sdata) = round_fl_to_int(tfd->val);
}
}
@@ -3982,18 +4067,20 @@ static void createTransActionData(bContext *C, TransInfo *t)
ANIM_animdata_freelist(&anim_data);
return;
}
-
+
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* allocate memory for data */
- t->total = count;
+ tc->data_len = count;
- t->data = MEM_callocN(t->total * sizeof(TransData), "TransData(Action Editor)");
- t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "transdata2d");
- td = t->data;
- td2d = t->data2d;
+ tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData(Action Editor)");
+ tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "transdata2d");
+ td = tc->data;
+ td2d = tc->data_2d;
if (ELEM(ac.datatype, ANIMCONT_GPENCIL, ANIMCONT_MASK)) {
- t->custom.type.data = tfd = MEM_callocN(sizeof(tGPFtransdata) * count, "tGPFtransdata");
- t->custom.type.use_free = true;
+ tc->custom.type.data = tfd = MEM_callocN(sizeof(tGPFtransdata) * count, "tGPFtransdata");
+ tc->custom.type.use_free = true;
}
/* loop 2: build transdata array */
@@ -4038,7 +4125,7 @@ static void createTransActionData(bContext *C, TransInfo *t)
/* calculate distances for proportional editing */
if (is_prop_edit) {
- td = t->data;
+ td = tc->data;
for (ale = anim_data.first; ale; ale = ale->next) {
AnimData *adt;
@@ -4380,19 +4467,21 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
ANIM_animdata_freelist(&anim_data);
return;
}
-
+
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* allocate memory for data */
- t->total = count;
+ tc->data_len = count;
- t->data = MEM_callocN(t->total * sizeof(TransData), "TransData (Graph Editor)");
+ tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData (Graph Editor)");
/* for each 2d vert a 3d vector is allocated, so that they can be treated just as if they were 3d verts */
- t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransData2D (Graph Editor)");
- t->custom.type.data = MEM_callocN(t->total * sizeof(TransDataGraph), "TransDataGraph");
- t->custom.type.use_free = true;
+ tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D (Graph Editor)");
+ tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataGraph), "TransDataGraph");
+ tc->custom.type.use_free = true;
- td = t->data;
- td2d = t->data2d;
- tdg = t->custom.type.data;
+ td = tc->data;
+ td2d = tc->data_2d;
+ tdg = tc->custom.type.data;
/* precompute space-conversion matrices for dealing with non-uniform scaling of Graph Editor */
unit_m3(mtx);
@@ -4519,7 +4608,7 @@ static void createTransGraphEditData(bContext *C, TransInfo *t)
if (is_prop_edit) {
/* loop 2: build transdata arrays */
- td = t->data;
+ td = tc->data;
for (ale = anim_data.first; ale; ale = ale->next) {
AnimData *adt = ANIM_nla_mapping_get(&ac, ale);
@@ -4675,12 +4764,14 @@ static void beztmap_to_data(TransInfo *t, FCurve *fcu, BeztMap *bezms, int totve
TransData *td;
int i, j;
char *adjusted;
-
+
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* dynamically allocate an array of chars to mark whether an TransData's
* pointers have been fixed already, so that we don't override ones that are
* already done
*/
- adjusted = MEM_callocN(t->total, "beztmap_adjusted_map");
+ adjusted = MEM_callocN(tc->data_len, "beztmap_adjusted_map");
/* for each beztmap item, find if it is used anywhere */
bezm = bezms;
@@ -4688,9 +4779,9 @@ static void beztmap_to_data(TransInfo *t, FCurve *fcu, BeztMap *bezms, int totve
/* loop through transdata, testing if we have a hit
* for the handles (vec[0]/vec[2]), we must also check if they need to be swapped...
*/
- td2d = t->data2d;
- td = t->data;
- for (j = 0; j < t->total; j++, td2d++, td++) {
+ td2d = tc->data_2d;
+ td = tc->data;
+ for (j = 0; j < tc->data_len; j++, td2d++, td++) {
/* skip item if already marked */
if (adjusted[j] != 0) continue;
@@ -4793,9 +4884,11 @@ void flushTransGraphData(TransInfo *t)
double secf = FPS;
int a;
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* flush to 2d vector from internally used 3d vector */
- for (a = 0, td = t->data, td2d = t->data2d, tdg = t->custom.type.data;
- a < t->total;
+ for (a = 0, td = tc->data, td2d = tc->data_2d, tdg = tc->custom.type.data;
+ a < tc->data_len;
a++, td++, td2d++, tdg++)
{
AnimData *adt = (AnimData *)td->extra; /* pointers to relevant AnimData blocks are stored in the td->extra pointers */
@@ -5157,13 +5250,15 @@ static void SeqTransDataBounds(TransInfo *t, ListBase *seqbase, TransSeq *ts)
}
-static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
+static void freeSeqData(TransInfo *t, TransDataContainer *tc, TransCustomData *custom_data)
{
Editing *ed = BKE_sequencer_editing_get(t->scene, false);
if (ed != NULL) {
+
+
ListBase *seqbasep = ed->seqbasep;
- TransData *td = t->data;
+ TransData *td = tc->data;
int a;
/* prevent updating the same seq twice
@@ -5191,7 +5286,7 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
{
int overlap = 0;
- for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) {
+ for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) {
seq = ((TransDataSeq *)td->extra)->seq;
if ((seq != seq_prev) && (seq->depth == 0) && (seq->flag & SEQ_OVERLAP)) {
overlap = 1;
@@ -5204,8 +5299,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
for (seq = seqbasep->first; seq; seq = seq->next)
seq->tmp = NULL;
- td = t->data;
- for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) {
+ td = tc->data;
+ for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) {
seq = ((TransDataSeq *)td->extra)->seq;
if ((seq != seq_prev)) {
/* check effects strips, we cant change their time */
@@ -5228,8 +5323,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
if (t->flag & T_ALT_TRANSFORM) {
int minframe = MAXFRAME;
- td = t->data;
- for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) {
+ td = tc->data;
+ for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) {
seq = ((TransDataSeq *)td->extra)->seq;
if ((seq != seq_prev) && (seq->depth == 0)) {
minframe = min_ii(minframe, seq->startdisp);
@@ -5265,8 +5360,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
if (has_effect_any) {
/* update effects strips based on strips just moved in time */
- td = t->data;
- for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) {
+ td = tc->data;
+ for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) {
seq = ((TransDataSeq *)td->extra)->seq;
if ((seq != seq_prev)) {
if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) {
@@ -5278,8 +5373,8 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
if (has_effect_root) {
/* now if any effects _still_ overlap, we need to move them up */
- td = t->data;
- for (a = 0, seq_prev = NULL; a < t->total; a++, td++, seq_prev = seq) {
+ td = tc->data;
+ for (a = 0, seq_prev = NULL; a < tc->data_len; a++, td++, seq_prev = seq) {
seq = ((TransDataSeq *)td->extra)->seq;
if ((seq != seq_prev) && (seq->depth == 0)) {
if ((seq->type & SEQ_TYPE_EFFECT) && seq->seq1) {
@@ -5308,7 +5403,7 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
}
else {
/* Canceled, need to update the strips display */
- for (a = 0; a < t->total; a++, td++) {
+ for (a = 0; a < tc->data_len; a++, td++) {
seq = ((TransDataSeq *)td->extra)->seq;
if ((seq != seq_prev) && (seq->depth == 0)) {
if (seq->flag & SEQ_OVERLAP)
@@ -5327,9 +5422,9 @@ static void freeSeqData(TransInfo *t, TransCustomData *custom_data)
MEM_freeN(custom_data->data);
custom_data->data = NULL;
}
- if (t->data) {
- MEM_freeN(t->data); // XXX postTrans usually does this
- t->data = NULL;
+ if (tc->data) {
+ MEM_freeN(tc->data); // XXX postTrans usually does this
+ tc->data = NULL;
}
}
@@ -5348,12 +5443,14 @@ static void createTransSeqData(bContext *C, TransInfo *t)
int count = 0;
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
if (ed == NULL) {
- t->total = 0;
+ tc->data_len = 0;
return;
}
- t->custom.type.free_cb = freeSeqData;
+ tc->custom.type.free_cb = freeSeqData;
xmouse = (int)UI_view2d_region_to_view_x(v2d, t->mouse.imval[0]);
@@ -5392,18 +5489,18 @@ static void createTransSeqData(bContext *C, TransInfo *t)
count = SeqTransCount(t, NULL, ed->seqbasep, 0);
/* allocate memory for data */
- t->total = count;
+ tc->data_len = count;
/* stop if trying to build list if nothing selected */
if (count == 0) {
return;
}
- t->custom.type.data = ts = MEM_callocN(sizeof(TransSeq), "transseq");
- t->custom.type.use_free = true;
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransSeq TransData");
- td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransSeq TransData2D");
- ts->tdseq = tdsq = MEM_callocN(t->total * sizeof(TransDataSeq), "TransSeq TransDataSeq");
+ tc->custom.type.data = ts = MEM_callocN(sizeof(TransSeq), "transseq");
+ tc->custom.type.use_free = true;
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransSeq TransData");
+ td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransSeq TransData2D");
+ ts->tdseq = tdsq = MEM_callocN(tc->data_len * sizeof(TransDataSeq), "TransSeq TransDataSeq");
/* loop 2: build transdata array */
SeqToTransData_Recursive(t, ed->seqbasep, td, td2d, tdsq);
@@ -5532,11 +5629,11 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
if (skip_invert == false && constinv == false) {
ob->transflag |= OB_NO_CONSTRAINTS; /* BKE_object_where_is_calc_time checks this */
- BKE_object_where_is_calc(t->scene, ob);
+ BKE_object_where_is_calc(t->depsgraph, t->scene, ob);
ob->transflag &= ~OB_NO_CONSTRAINTS;
}
else
- BKE_object_where_is_calc(t->scene, ob);
+ BKE_object_where_is_calc(t->depsgraph, t->scene, ob);
td->ob = ob;
@@ -5603,84 +5700,97 @@ static void ObjectToTransData(TransInfo *t, TransData *td, Object *ob)
}
}
+static void trans_object_base_deps_flag_prepare(ViewLayer *view_layer)
+{
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ base->object->id.tag &= ~LIB_TAG_DOIT;
+ }
+}
+
+static void set_trans_object_base_deps_flag_cb(ID *id, void *UNUSED(user_data))
+{
+ /* Here we only handle object IDs. */
+ if (GS(id->name) != ID_OB) {
+ return;
+ }
+ id->tag |= LIB_TAG_DOIT;
+}
+
+static void flush_trans_object_base_deps_flag(Depsgraph *depsgraph, Object *object)
+{
+ object->id.tag |= LIB_TAG_DOIT;
+ DEG_foreach_dependent_ID(depsgraph, &object->id,
+ set_trans_object_base_deps_flag_cb, NULL);
+}
+
+static void trans_object_base_deps_flag_finish(ViewLayer *view_layer)
+{
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (base->object->id.tag & LIB_TAG_DOIT) {
+ base->flag_legacy |= BA_SNAP_FIX_DEPS_FIASCO;
+ }
+ }
+}
/* sets flags in Bases to define whether they take part in transform */
/* it deselects Bases, so we have to call the clear function always after */
static void set_trans_object_base_flags(TransInfo *t)
{
+ /* TODO(sergey): Get rid of global, use explicit main. */
+ Main *bmain = G.main;
+ ViewLayer *view_layer = t->view_layer;
Scene *scene = t->scene;
- View3D *v3d = t->view;
-
- /*
- * if Base selected and has parent selected:
- * base->flag = BA_WAS_SEL
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+ /* NOTE: if Base selected and has parent selected:
+ * base->flag_legacy = BA_WAS_SEL
*/
- Base *base;
-
- /* don't do it if we're not actually going to recalculate anything */
- if (t->mode == TFM_DUMMY)
+ /* Don't do it if we're not actually going to recalculate anything. */
+ if (t->mode == TFM_DUMMY) {
return;
-
- /* makes sure base flags and object flags are identical */
- BKE_scene_base_flag_to_objects(t->scene);
-
- /* Make sure depsgraph is here. */
- DAG_scene_relations_update(G.main, t->scene);
-
- /* handle pending update events, otherwise they got copied below */
- for (base = scene->base.first; base; base = base->next) {
- if (base->object->recalc & OB_RECALC_ALL) {
- /* TODO(sergey): Ideally, it's not needed. */
- BKE_object_handle_update(G.main->eval_ctx, t->scene, base->object);
- }
}
-
- for (base = scene->base.first; base; base = base->next) {
- base->flag &= ~BA_WAS_SEL;
-
- if (TESTBASELIB_BGMODE(v3d, scene, base)) {
+ /* Makes sure base flags and object flags are identical. */
+ BKE_scene_base_flag_to_objects(t->view_layer);
+ /* Make sure depsgraph is here. */
+ DEG_graph_relations_update(depsgraph, bmain, scene, view_layer);
+ /* Clear all flags we need. It will be used to detect dependencies. */
+ trans_object_base_deps_flag_prepare(view_layer);
+ /* Traverse all bases and set all possible flags. */
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ base->flag_legacy &= ~BA_WAS_SEL;
+ if (TESTBASELIB_BGMODE(base)) {
Object *ob = base->object;
Object *parsel = ob->parent;
-
- /* if parent selected, deselect */
- while (parsel) {
- if (parsel->flag & SELECT) {
- Base *parbase = BKE_scene_base_find(scene, parsel);
- if (parbase) { /* in rare cases this can fail */
- if (TESTBASELIB_BGMODE(v3d, scene, parbase)) {
+ /* If parent selected, deselect. */
+ while (parsel != NULL) {
+ if (parsel->base_flag & BASE_SELECTED) {
+ Base *parbase = BKE_view_layer_base_find(view_layer, parsel);
+ if (parbase != NULL) { /* in rare cases this can fail */
+ if (TESTBASELIB_BGMODE(parbase)) {
break;
}
}
}
parsel = parsel->parent;
}
-
- if (parsel) {
- /* rotation around local centers are allowed to propagate */
+ if (parsel != NULL) {
+ /* Rotation around local centers are allowed to propagate. */
if ((t->around == V3D_AROUND_LOCAL_ORIGINS) &&
(t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL))
{
- base->flag |= BA_TRANSFORM_CHILD;
+ base->flag_legacy |= BA_TRANSFORM_CHILD;
}
else {
- base->flag &= ~SELECT;
- base->flag |= BA_WAS_SEL;
+ base->flag &= ~BASE_SELECTED;
+ base->flag_legacy |= BA_WAS_SEL;
}
}
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
- }
- }
-
- /* all recalc flags get flushed to all layers, so a layer flip later on works fine */
- DAG_scene_flush_update(G.main, t->scene, -1, 0);
-
- /* and we store them temporal in base (only used for transform code) */
- /* this because after doing updates, the object->recalc is cleared */
- for (base = scene->base.first; base; base = base->next) {
- if (base->object->recalc & (OB_RECALC_OB | OB_RECALC_DATA)) {
- base->flag |= BA_SNAP_FIX_DEPS_FIASCO;
+ flush_trans_object_base_deps_flag(depsgraph, ob);
}
}
+ /* Store temporary bits in base indicating that base is being modified
+ * (directly or indirectly) by transforming objects.
+ */
+ trans_object_base_deps_flag_finish(view_layer);
}
static bool mark_children(Object *ob)
@@ -5701,78 +5811,69 @@ static bool mark_children(Object *ob)
static int count_proportional_objects(TransInfo *t)
{
int total = 0;
+ ViewLayer *view_layer = t->view_layer;
Scene *scene = t->scene;
- View3D *v3d = t->view;
- Base *base;
-
- /* rotations around local centers are allowed to propagate, so we take all objects */
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+ /* Clear all flags we need. It will be used to detect dependencies. */
+ trans_object_base_deps_flag_prepare(view_layer);
+ /* Rotations around local centers are allowed to propagate, so we take all objects. */
if (!((t->around == V3D_AROUND_LOCAL_ORIGINS) &&
(t->mode == TFM_ROTATION || t->mode == TFM_TRACKBALL)))
{
- /* mark all parents */
- for (base = scene->base.first; base; base = base->next) {
- if (TESTBASELIB_BGMODE(v3d, scene, base)) {
+ /* Mark all parents. */
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (TESTBASELIB_BGMODE(base)) {
Object *parent = base->object->parent;
-
/* flag all parents */
- while (parent) {
+ while (parent != NULL) {
parent->flag |= BA_TRANSFORM_PARENT;
parent = parent->parent;
}
}
}
-
- /* mark all children */
- for (base = scene->base.first; base; base = base->next) {
+ /* Mark all children. */
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
/* all base not already selected or marked that is editable */
- if ((base->object->flag & (SELECT | BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
- (BASE_EDITABLE_BGMODE(v3d, scene, base)))
+ if ((base->object->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
+ (base->flag & BASE_SELECTED) == 0 &&
+ (BASE_EDITABLE_BGMODE(base)))
{
mark_children(base->object);
}
}
}
-
- for (base = scene->base.first; base; base = base->next) {
+ /* Flush changed flags to all dependencies. */
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
Object *ob = base->object;
-
- /* if base is not selected, not a parent of selection or not a child of selection and it is editable */
- if ((ob->flag & (SELECT | BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
- (BASE_EDITABLE_BGMODE(v3d, scene, base)))
+ /* If base is not selected, not a parent of selection or not a child of
+ * selection and it is editable.
+ */
+ if ((ob->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
+ (base->flag & BASE_SELECTED) == 0 &&
+ (BASE_EDITABLE_BGMODE(base)))
{
-
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
-
+ flush_trans_object_base_deps_flag(depsgraph, ob);
total += 1;
}
}
-
-
- /* all recalc flags get flushed to all layers, so a layer flip later on works fine */
- DAG_scene_relations_update(G.main, t->scene);
- DAG_scene_flush_update(G.main, t->scene, -1, 0);
-
- /* and we store them temporal in base (only used for transform code) */
- /* this because after doing updates, the object->recalc is cleared */
- for (base = scene->base.first; base; base = base->next) {
- if (base->object->recalc & (OB_RECALC_OB | OB_RECALC_DATA)) {
- base->flag |= BA_SNAP_FIX_DEPS_FIASCO;
- }
- }
-
+ /* Store temporary bits in base indicating that base is being modified
+ * (directly or indirectly) by transforming objects.
+ */
+ trans_object_base_deps_flag_finish(view_layer);
return total;
}
static void clear_trans_object_base_flags(TransInfo *t)
{
- Scene *sce = t->scene;
+ ViewLayer *view_layer = t->view_layer;
Base *base;
- for (base = sce->base.first; base; base = base->next) {
- if (base->flag & BA_WAS_SEL)
- base->flag |= SELECT;
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ if (base->flag_legacy & BA_WAS_SEL) {
+ base->flag |= BASE_SELECTED;
+ }
- base->flag &= ~(BA_WAS_SEL | BA_SNAP_FIX_DEPS_FIASCO | BA_TEMP_TAG | BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT);
+ base->flag_legacy &= ~(BA_WAS_SEL | BA_SNAP_FIX_DEPS_FIASCO | BA_TEMP_TAG | BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT);
}
}
@@ -5780,7 +5881,7 @@ static void clear_trans_object_base_flags(TransInfo *t)
* tmode: should be a transform mode
*/
// NOTE: context may not always be available, so must check before using it as it's a luxury for a few cases
-void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob, int tmode)
+void autokeyframe_ob_cb_func(bContext *C, Scene *scene, ViewLayer *view_layer, View3D *v3d, Object *ob, int tmode)
{
ID *id = &ob->id;
FCurve *fcu;
@@ -5829,7 +5930,7 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
}
else if (ELEM(tmode, TFM_ROTATION, TFM_TRACKBALL)) {
if (v3d->around == V3D_AROUND_ACTIVE) {
- if (ob != OBACT)
+ if (ob != OBACT(view_layer))
do_loc = true;
}
else if (v3d->around == V3D_AROUND_CURSOR)
@@ -5840,7 +5941,7 @@ void autokeyframe_ob_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *ob,
}
else if (tmode == TFM_RESIZE) {
if (v3d->around == V3D_AROUND_ACTIVE) {
- if (ob != OBACT)
+ if (ob != OBACT(view_layer))
do_loc = true;
}
else if (v3d->around == V3D_AROUND_CURSOR)
@@ -6018,7 +6119,7 @@ void autokeyframe_pose_cb_func(bContext *C, Scene *scene, View3D *v3d, Object *o
*/
if (C && (ob->pose->avs.path_bakeflag & MOTIONPATH_BAKE_HAS_PATHS)) {
//ED_pose_clear_paths(C, ob); // XXX for now, don't need to clear
- ED_pose_recalculate_paths(scene, ob);
+ ED_pose_recalculate_paths(C, scene, ob);
}
}
else {
@@ -6129,39 +6230,42 @@ static void special_aftertrans_update__mesh(bContext *UNUSED(C), TransInfo *t)
{
/* so automerge supports mirror */
if ((t->scene->toolsettings->automerge) &&
- (t->obedit && t->obedit->type == OB_MESH))
+ ((t->flag & T_EDIT) && t->obedit_type == OB_MESH))
{
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
- BMesh *bm = em->bm;
- char hflag;
- bool has_face_sel = (bm->totfacesel != 0);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- if (t->flag & T_MIRROR) {
- TransData *td;
- int i;
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
+ BMesh *bm = em->bm;
+ char hflag;
+ bool has_face_sel = (bm->totfacesel != 0);
- /* rather then adjusting the selection (which the user would notice)
- * tag all mirrored verts, then automerge those */
- BM_mesh_elem_hflag_disable_all(bm, BM_VERT, BM_ELEM_TAG, false);
+ if (t->flag & T_MIRROR) {
+ TransData *td;
+ int i;
+
+ /* rather then adjusting the selection (which the user would notice)
+ * tag all mirrored verts, then automerge those */
+ BM_mesh_elem_hflag_disable_all(bm, BM_VERT, BM_ELEM_TAG, false);
- for (i = 0, td = t->data; i < t->total; i++, td++) {
- if (td->extra) {
- BM_elem_flag_enable((BMVert *)td->extra, BM_ELEM_TAG);
+ for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
+ if (td->extra) {
+ BM_elem_flag_enable((BMVert *)td->extra, BM_ELEM_TAG);
+ }
}
- }
- hflag = BM_ELEM_SELECT | BM_ELEM_TAG;
- }
- else {
- hflag = BM_ELEM_SELECT;
- }
+ hflag = BM_ELEM_SELECT | BM_ELEM_TAG;
+ }
+ else {
+ hflag = BM_ELEM_SELECT;
+ }
- EDBM_automerge(t->scene, t->obedit, true, hflag);
+ EDBM_automerge(t->scene, tc->obedit, true, hflag);
- /* Special case, this is needed or faces won't re-select.
- * Flush selected edges to faces. */
- if (has_face_sel && (em->selectmode == SCE_SELECT_FACE)) {
- EDBM_selectmode_flush_ex(em, SCE_SELECT_EDGE);
+ /* Special case, this is needed or faces won't re-select.
+ * Flush selected edges to faces. */
+ if (has_face_sel && (em->selectmode == SCE_SELECT_FACE)) {
+ EDBM_selectmode_flush_ex(em, SCE_SELECT_EDGE);
+ }
}
}
}
@@ -6177,52 +6281,55 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
// short redrawipo=0, resetslowpar=1;
const bool canceled = (t->state == TRANS_CANCEL);
const bool duplicate = (t->mode == TFM_TIME_DUPLICATE);
-
+
/* early out when nothing happened */
- if (t->total == 0 || t->mode == TFM_DUMMY)
+ if (t->data_len_all == 0 || t->mode == TFM_DUMMY) {
return;
-
+ }
+
if (t->spacetype == SPACE_VIEW3D) {
- if (t->obedit) {
+ if (t->flag & T_EDIT) {
/* Special Exception:
* We don't normally access 't->custom.mode' here, but its needed in this case. */
if (canceled == 0) {
/* we need to delete the temporary faces before automerging */
if (t->mode == TFM_EDGE_SLIDE) {
- EdgeSlideData *sld = t->custom.mode.data;
-
/* handle multires re-projection, done
* on transform completion since it's
* really slow -joeedh */
projectEdgeSlideData(t, true);
- /* free temporary faces to avoid automerging and deleting
- * during cleanup - psy-fi */
- freeEdgeSlideTempFaces(sld);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ EdgeSlideData *sld = tc->custom.mode.data;
+
+ /* free temporary faces to avoid automerging and deleting
+ * during cleanup - psy-fi */
+ freeEdgeSlideTempFaces(sld);
+ }
}
else if (t->mode == TFM_VERT_SLIDE) {
/* as above */
- VertSlideData *sld = t->custom.mode.data;
projectVertSlideData(t, true);
- freeVertSlideTempFaces(sld);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ VertSlideData *sld = tc->custom.mode.data;
+ freeVertSlideTempFaces(sld);
+ }
}
- if (t->obedit->type == OB_MESH) {
+ if (t->obedit_type == OB_MESH) {
special_aftertrans_update__mesh(C, t);
}
}
else {
if (t->mode == TFM_EDGE_SLIDE) {
- EdgeSlideData *sld = t->custom.mode.data;
-
- sld->perc = 0.0;
+ EdgeSlideParams *slp = t->custom.mode.data;
+ slp->perc = 0.0;
projectEdgeSlideData(t, false);
}
else if (t->mode == TFM_VERT_SLIDE) {
- VertSlideData *sld = t->custom.mode.data;
-
- sld->perc = 0.0;
+ EdgeSlideParams *slp = t->custom.mode.data;
+ slp->perc = 0.0;
projectVertSlideData(t, false);
}
}
@@ -6328,9 +6435,9 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
// fixme... some of this stuff is not good
if (ob) {
if (ob->pose || BKE_key_from_object(ob))
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
else
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
}
/* 3 cases here for curve cleanups:
@@ -6496,66 +6603,77 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
ED_nla_postop_refresh(&ac);
}
}
- else if (t->obedit) {
- if (t->obedit->type == OB_MESH) {
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
- /* table needs to be created for each edit command, since vertices can move etc */
- ED_mesh_mirror_spatial_table(t->obedit, em, NULL, NULL, 'e');
+ else if (t->flag & T_EDIT) {
+ if (t->obedit_type == OB_MESH) {
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
+ /* table needs to be created for each edit command, since vertices can move etc */
+ ED_mesh_mirror_spatial_table(tc->obedit, em, NULL, NULL, 'e');
+ /* TODO(campbell): xform: We need support for many mirror objects at once! */
+ break;
+ }
}
}
- else if ((t->flag & T_POSE) && (t->poseobj)) {
- bArmature *arm;
- bPoseChannel *pchan;
- short targetless_ik = 0;
+ else if (t->flag & T_POSE) {
- ob = t->poseobj;
- arm = ob->data;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- if ((t->flag & T_AUTOIK) && (t->options & CTX_AUTOCONFIRM)) {
- /* when running transform non-interactively (operator exec),
- * we need to update the pose otherwise no updates get called during
- * transform and the auto-ik is not applied. see [#26164] */
- struct Object *pose_ob = t->poseobj;
- BKE_pose_where_is(t->scene, pose_ob);
- }
+ bArmature *arm;
+ bPoseChannel *pchan;
+ short targetless_ik = 0;
- /* set BONE_TRANSFORM flags for autokey, manipulator draw might have changed them */
- if (!canceled && (t->mode != TFM_DUMMY))
- count_set_pose_transflags(&t->mode, t->around, ob);
+ ob = tc->poseobj;
+ arm = ob->data;
- /* if target-less IK grabbing, we calculate the pchan transforms and clear flag */
- if (!canceled && t->mode == TFM_TRANSLATION)
- targetless_ik = apply_targetless_ik(ob);
- else {
- /* not forget to clear the auto flag */
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- bKinematicConstraint *data = has_targetless_ik(pchan);
- if (data) data->flag &= ~CONSTRAINT_IK_AUTO;
+ if ((t->flag & T_AUTOIK) && (t->options & CTX_AUTOCONFIRM)) {
+ /* when running transform non-interactively (operator exec),
+ * we need to update the pose otherwise no updates get called during
+ * transform and the auto-ik is not applied. see [#26164] */
+ struct Object *pose_ob = tc->poseobj;
+ BKE_pose_where_is(t->depsgraph, t->scene, pose_ob);
}
- }
- if (t->mode == TFM_TRANSLATION)
- pose_grab_with_ik_clear(ob);
+ /* set BONE_TRANSFORM flags for autokey, manipulator draw might have changed them */
+ if (!canceled && (t->mode != TFM_DUMMY))
+ count_set_pose_transflags(&t->mode, t->around, ob);
- /* automatic inserting of keys and unkeyed tagging - only if transform wasn't canceled (or TFM_DUMMY) */
- if (!canceled && (t->mode != TFM_DUMMY)) {
- autokeyframe_pose_cb_func(C, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- }
- else if (arm->flag & ARM_DELAYDEFORM) {
- /* old optimize trick... this enforces to bypass the depgraph */
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- ob->recalc = 0; // is set on OK position already by recalcData()
- }
- else
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ /* if target-less IK grabbing, we calculate the pchan transforms and clear flag */
+ if (!canceled && t->mode == TFM_TRANSLATION)
+ targetless_ik = apply_targetless_ik(ob);
+ else {
+ /* not forget to clear the auto flag */
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ bKinematicConstraint *data = has_targetless_ik(pchan);
+ if (data) data->flag &= ~CONSTRAINT_IK_AUTO;
+ }
+ }
+
+ if (t->mode == TFM_TRANSLATION)
+ pose_grab_with_ik_clear(ob);
+ /* automatic inserting of keys and unkeyed tagging - only if transform wasn't canceled (or TFM_DUMMY) */
+ if (!canceled && (t->mode != TFM_DUMMY)) {
+ autokeyframe_pose_cb_func(C, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
+ else if (arm->flag & ARM_DELAYDEFORM) {
+ /* TODO(sergey): Armature is already updated by recalcData(), so we
+ * might save some time by skipping re-evaluating it. But this isn't
+ * possible yet within new dependency graph, and also other contexts
+ * might need to update their CoW copies.
+ */
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
+ else {
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
+ }
}
else if (t->options & CTX_PAINT_CURVE) {
/* pass */
}
- else if ((t->scene->basact) &&
- (ob = t->scene->basact->object) &&
+ else if ((t->view_layer->basact) &&
+ (ob = t->view_layer->basact->object) &&
(ob->mode & OB_MODE_PARTICLE_EDIT) &&
PE_get_current(t->scene, ob))
{
@@ -6566,8 +6684,10 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
BLI_assert(t->flag & (T_OBJECT | T_TEXTURE));
- for (i = 0; i < t->total; i++) {
- TransData *td = t->data + i;
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ for (i = 0; i < tc->data_len; i++) {
+ TransData *td = tc->data + i;
ListBase pidlist;
PTCacheID *pid;
ob = td->ob;
@@ -6588,17 +6708,17 @@ void special_aftertrans_update(bContext *C, TransInfo *t)
/* pointcache refresh */
if (BKE_ptcache_object_reset(t->scene, ob, PTCACHE_RESET_OUTDATED))
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
/* Needed for proper updating of "quick cached" dynamics. */
/* Creates troubles for moving animated objects without */
/* autokey though, probably needed is an anim sys override? */
/* Please remove if some other solution is found. -jahka */
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
/* Set autokey if necessary */
if (!canceled) {
- autokeyframe_ob_cb_func(C, t->scene, (View3D *)t->view, ob, t->mode);
+ autokeyframe_ob_cb_func(C, t->scene, t->view_layer, (View3D *)t->view, ob, t->mode);
}
/* restore rigid body transform */
@@ -6621,7 +6741,7 @@ int special_transform_moving(TransInfo *t)
else if (t->spacetype == SPACE_IPO) {
return G_TRANSFORM_FCURVES;
}
- else if (t->obedit || ((t->flag & T_POSE) && (t->poseobj))) {
+ else if ((t->flag & T_EDIT) || (t->flag & T_POSE)) {
return G_TRANSFORM_EDIT;
}
else if (t->flag & (T_OBJECT | T_TEXTURE)) {
@@ -6633,29 +6753,29 @@ int special_transform_moving(TransInfo *t)
static void createTransObject(bContext *C, TransInfo *t)
{
- Scene *scene = t->scene;
-
TransData *td = NULL;
TransDataExtension *tx;
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
set_trans_object_base_flags(t);
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* count */
- t->total = CTX_DATA_COUNT(C, selected_objects);
+ tc->data_len = CTX_DATA_COUNT(C, selected_objects);
- if (!t->total) {
+ if (!tc->data_len) {
/* clear here, main transform function escapes too */
clear_trans_object_base_flags(t);
return;
}
if (is_prop_edit) {
- t->total += count_proportional_objects(t);
+ tc->data_len += count_proportional_objects(t);
}
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransOb");
- tx = t->ext = MEM_callocN(t->total * sizeof(TransDataExtension), "TransObExtension");
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransOb");
+ tx = tc->data_ext = MEM_callocN(tc->data_len * sizeof(TransDataExtension), "TransObExtension");
CTX_DATA_BEGIN(C, Base *, base, selected_bases)
{
@@ -6684,15 +6804,16 @@ static void createTransObject(bContext *C, TransInfo *t)
CTX_DATA_END;
if (is_prop_edit) {
- View3D *v3d = t->view;
+ ViewLayer *view_layer = t->view_layer;
Base *base;
- for (base = scene->base.first; base; base = base->next) {
+ for (base = view_layer->object_bases.first; base; base = base->next) {
Object *ob = base->object;
/* if base is not selected, not a parent of selection or not a child of selection and it is editable */
- if ((ob->flag & (SELECT | BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
- BASE_EDITABLE_BGMODE(v3d, scene, base))
+ if ((ob->flag & (BA_TRANSFORM_CHILD | BA_TRANSFORM_PARENT)) == 0 &&
+ (base->flag & BASE_SELECTED) == 0 &&
+ BASE_EDITABLE_BGMODE(base))
{
td->protectflag = ob->protectflag;
td->ext = tx;
@@ -6774,7 +6895,9 @@ static void createTransNodeData(bContext *UNUSED(C), TransInfo *t)
SpaceNode *snode = t->sa->spacedata.first;
bNode *node;
- t->total = 0;
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ tc->data_len = 0;
if (!snode->edittree) {
return;
@@ -6787,15 +6910,15 @@ static void createTransNodeData(bContext *UNUSED(C), TransInfo *t)
for (node = snode->edittree->nodes.first; node; node = node->next) {
if (node->flag & NODE_SELECT && is_node_parent_select(node) == false) {
node->flag |= NODE_TRANSFORM;
- t->total++;
+ tc->data_len++;
}
else {
node->flag &= ~NODE_TRANSFORM;
}
}
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransNode TransData");
- td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransNode TransData2D");
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransNode TransData");
+ td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransNode TransData2D");
for (node = snode->edittree->nodes.first; node; node = node->next) {
if (node->flag & NODE_TRANSFORM) {
@@ -6980,7 +7103,7 @@ static void planeTrackToTransData(const int framenr, TransData *td, TransData2D
}
}
-static void transDataTrackingFree(TransInfo *UNUSED(t), TransCustomData *custom_data)
+static void transDataTrackingFree(TransInfo *UNUSED(t), TransDataContainer *UNUSED(tc), TransCustomData *custom_data)
{
if (custom_data->data) {
TransDataTracking *tdt = custom_data->data;
@@ -7005,22 +7128,24 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
TransDataTracking *tdt;
int framenr = ED_space_clip_get_clip_frame_number(sc);
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* count */
- t->total = 0;
+ tc->data_len = 0;
track = tracksbase->first;
while (track) {
if (TRACK_VIEW_SELECTED(sc, track) && (track->flag & TRACK_LOCKED) == 0) {
- t->total++; /* offset */
+ tc->data_len++; /* offset */
if (track->flag & SELECT)
- t->total++;
+ tc->data_len++;
if (track->pat_flag & SELECT)
- t->total += 4;
+ tc->data_len += 4;
if (track->search_flag & SELECT)
- t->total += 2;
+ tc->data_len += 2;
}
track = track->next;
@@ -7031,18 +7156,18 @@ static void createTransTrackingTracksData(bContext *C, TransInfo *t)
plane_track = plane_track->next)
{
if (PLANE_TRACK_VIEW_SELECTED(plane_track)) {
- t->total += 4;
+ tc->data_len += 4;
}
}
- if (t->total == 0)
+ if (tc->data_len == 0)
return;
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransTracking TransData");
- td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransTracking TransData2D");
- tdt = t->custom.type.data = MEM_callocN(t->total * sizeof(TransDataTracking), "TransTracking TransDataTracking");
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData");
+ td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransTracking TransData2D");
+ tdt = tc->custom.type.data = MEM_callocN(tc->data_len * sizeof(TransDataTracking), "TransTracking TransDataTracking");
- t->custom.type.free_cb = transDataTrackingFree;
+ tc->custom.type.free_cb = transDataTrackingFree;
/* create actual data */
track = tracksbase->first;
@@ -7144,8 +7269,10 @@ static void createTransTrackingCurvesData(bContext *C, TransInfo *t)
BKE_movieclip_get_size(clip, &sc->user, &width, &height);
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* count */
- t->total = 0;
+ tc->data_len = 0;
if ((sc->flag & SC_SHOW_GRAPH_TRACKS_MOTION) == 0) {
return;
@@ -7162,23 +7289,23 @@ static void createTransTrackingCurvesData(bContext *C, TransInfo *t)
continue;
if (marker->flag & MARKER_GRAPH_SEL_X)
- t->total += 1;
+ tc->data_len += 1;
if (marker->flag & MARKER_GRAPH_SEL_Y)
- t->total += 1;
+ tc->data_len += 1;
}
}
track = track->next;
}
- if (t->total == 0)
+ if (tc->data_len == 0)
return;
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransTracking TransData");
- td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransTracking TransData2D");
- t->custom.type.data = tdt = MEM_callocN(t->total * sizeof(TransDataTracking), "TransTracking TransDataTracking");
- t->custom.type.free_cb = transDataTrackingFree;
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransTracking TransData");
+ td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransTracking TransData2D");
+ tc->custom.type.data = tdt = MEM_callocN(tc->data_len * sizeof(TransDataTracking), "TransTracking TransDataTracking");
+ tc->custom.type.free_cb = transDataTrackingFree;
/* create actual data */
track = tracksbase->first;
@@ -7219,7 +7346,9 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
MovieClip *clip = ED_space_clip_get_clip(sc);
int width, height;
- t->total = 0;
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ tc->data_len = 0;
if (!clip)
return;
@@ -7240,12 +7369,14 @@ static void createTransTrackingData(bContext *C, TransInfo *t)
static void cancelTransTracking(TransInfo *t)
{
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
SpaceClip *sc = t->sa->spacedata.first;
int i, framenr = ED_space_clip_get_clip_frame_number(sc);
- TransDataTracking *tdt_array = t->custom.type.data;
+ TransDataTracking *tdt_array = tc->custom.type.data;
+
i = 0;
- while (i < t->total) {
+ while (i < tc->data_len) {
TransDataTracking *tdt = &tdt_array[i];
if (tdt->mode == transDataTracking_ModeTracks) {
@@ -7302,8 +7433,10 @@ void flushTransTracking(TransInfo *t)
if (t->state == TRANS_CANCEL)
cancelTransTracking(t);
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* flush to 2d vector from internally used 3d vector */
- for (a = 0, td = t->data, td2d = t->data2d, tdt = t->custom.type.data; a < t->total; a++, td2d++, td++, tdt++) {
+ for (a = 0, td = tc->data, td2d = tc->data_2d, tdt = tc->custom.type.data; a < tc->data_len; a++, td2d++, td++, tdt++) {
if (tdt->mode == transDataTracking_ModeTracks) {
float loc2d[2];
@@ -7569,7 +7702,9 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
const bool is_prop_edit = (t->flag & T_PROP_EDIT);
float asp[2];
- t->total = 0;
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ tc->data_len = 0;
if (!mask)
return;
@@ -7629,13 +7764,13 @@ static void createTransMaskingData(bContext *C, TransInfo *t)
ED_mask_get_aspect(t->sa, t->ar, &asp[0], &asp[1]);
- t->total = (is_prop_edit) ? count : countsel;
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransObData(Mask Editing)");
+ tc->data_len = (is_prop_edit) ? count : countsel;
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransObData(Mask Editing)");
/* for each 2d uv coord a 3d vector is allocated, so that they can be
* treated just as if they were 3d verts */
- td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransObData2D(Mask Editing)");
- t->custom.type.data = tdm = MEM_callocN(t->total * sizeof(TransDataMasking), "TransDataMasking(Mask Editing)");
- t->custom.type.use_free = true;
+ td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransObData2D(Mask Editing)");
+ tc->custom.type.data = tdm = MEM_callocN(tc->data_len * sizeof(TransDataMasking), "TransDataMasking(Mask Editing)");
+ tc->custom.type.use_free = true;
/* create data */
for (masklay = mask->masklayers.first; masklay; masklay = masklay->next) {
@@ -7692,12 +7827,14 @@ void flushTransMasking(TransInfo *t)
int a;
float asp[2], inv[2];
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
ED_mask_get_aspect(t->sa, t->ar, &asp[0], &asp[1]);
inv[0] = 1.0f / asp[0];
inv[1] = 1.0f / asp[1];
/* flush to 2d vector from internally used 3d vector */
- for (a = 0, td = t->data2d, tdm = t->custom.type.data; a < t->total; a++, td++, tdm++) {
+ for (a = 0, td = tc->data_2d, tdm = tc->custom.type.data; a < tc->data_len; a++, td++, tdm++) {
td->loc2d[0] = td->loc[0] * inv[0];
td->loc2d[1] = td->loc[1] * inv[1];
mul_m3_v2(tdm->parent_inverse_matrix, td->loc2d);
@@ -7816,7 +7953,9 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t)
int i;
int total = 0;
- t->total = 0;
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ tc->data_len = 0;
if (!paint || !paint->brush || !paint->brush->paint_curve)
return;
@@ -7842,11 +7981,11 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t)
if (!total)
return;
- t->total = total;
- td2d = t->data2d = MEM_callocN(t->total * sizeof(TransData2D), "TransData2D");
- td = t->data = MEM_callocN(t->total * sizeof(TransData), "TransData");
- t->custom.type.data = tdpc = MEM_callocN(t->total * sizeof(TransDataPaintCurve), "TransDataPaintCurve");
- t->custom.type.use_free = true;
+ tc->data_len = total;
+ td2d = tc->data_2d = MEM_callocN(tc->data_len * sizeof(TransData2D), "TransData2D");
+ td = tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData");
+ tc->custom.type.data = tdpc = MEM_callocN(tc->data_len * sizeof(TransDataPaintCurve), "TransDataPaintCurve");
+ tc->custom.type.use_free = true;
for (pcp = pc->points, i = 0; i < pc->tot_points; i++, pcp++) {
if (PC_IS_ANY_SEL(pcp)) {
@@ -7877,10 +8016,13 @@ static void createTransPaintCurveVerts(bContext *C, TransInfo *t)
void flushTransPaintCurve(TransInfo *t)
{
int i;
- TransData2D *td2d = t->data2d;
- TransDataPaintCurve *tdpc = t->custom.type.data;
- for (i = 0; i < t->total; i++, tdpc++, td2d++) {
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ TransData2D *td2d = tc->data_2d;
+ TransDataPaintCurve *tdpc = tc->custom.type.data;
+
+ for (i = 0; i < tc->data_len; i++, tdpc++, td2d++) {
PaintCurvePoint *pcp = tdpc->pcp;
copy_v2_v2(pcp->bez.vec[tdpc->id], td2d->loc);
}
@@ -7899,15 +8041,16 @@ static void createTransGPencil(bContext *C, TransInfo *t)
const bool is_prop_edit = (t->flag & T_PROP_EDIT) != 0;
const bool is_prop_edit_connected = (t->flag & T_PROP_CONNECTED) != 0;
-
-
+
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* == Grease Pencil Strokes to Transform Data ==
* Grease Pencil stroke points can be a mixture of 2D (screen-space),
* or 3D coordinates. However, they're always saved as 3D points.
* For now, we just do these without creating TransData2D for the 2D
* strokes. This may cause issues in future though.
*/
- t->total = 0;
+ tc->data_len = 0;
if (gpd == NULL)
return;
@@ -7936,11 +8079,11 @@ static void createTransGPencil(bContext *C, TransInfo *t)
if (is_prop_edit_connected) {
/* connected only - so only if selected */
if (gps->flag & GP_STROKE_SELECT)
- t->total += gps->totpoints;
+ tc->data_len += gps->totpoints;
}
else {
/* everything goes - connection status doesn't matter */
- t->total += gps->totpoints;
+ tc->data_len += gps->totpoints;
}
}
else {
@@ -7952,7 +8095,7 @@ static void createTransGPencil(bContext *C, TransInfo *t)
// TODO: 2D vs 3D?
for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
if (pt->flag & GP_SPOINT_SELECT)
- t->total++;
+ tc->data_len++;
}
}
}
@@ -7961,13 +8104,13 @@ static void createTransGPencil(bContext *C, TransInfo *t)
}
/* Stop trying if nothing selected */
- if (t->total == 0) {
+ if (tc->data_len == 0) {
return;
}
/* Allocate memory for data */
- t->data = MEM_callocN(t->total * sizeof(TransData), "TransData(GPencil)");
- td = t->data;
+ tc->data = MEM_callocN(tc->data_len * sizeof(TransData), "TransData(GPencil)");
+ td = tc->data;
unit_m3(smtx);
unit_m3(mtx);
@@ -8135,22 +8278,57 @@ static void createTransGPencil(bContext *C, TransInfo *t)
}
}
+static int countAndCleanTransDataContainer(TransInfo *t)
+{
+ BLI_assert(ELEM(t->data_len_all, 0, -1));
+ t->data_len_all = 0;
+ uint data_container_len_orig = t->data_container_len;
+ for (TransDataContainer *th_end = t->data_container - 1, *tc = t->data_container + (t->data_container_len - 1); tc != th_end; tc--) {
+ if (tc->data_len == 0) {
+ uint index = tc - t->data_container;
+ if (index + 1 != t->data_container_len) {
+ SWAP(TransDataContainer, t->data_container[index], t->data_container[t->data_container_len - 1]);
+ }
+ t->data_container_len -= 1;
+ }
+ else {
+ t->data_len_all += tc->data_len;
+ }
+ }
+ if (data_container_len_orig != t->data_container_len) {
+ t->data_container = MEM_reallocN(t->data_container, sizeof(*t->data_container) * t->data_container_len);
+ }
+ return t->data_len_all;
+}
+
void createTransData(bContext *C, TransInfo *t)
{
Scene *scene = t->scene;
- Object *ob = OBACT;
+ ViewLayer *view_layer = t->view_layer;
+ Object *ob = OBACT(view_layer);
+
+ t->data_len_all = -1;
/* if tests must match recalcData for correct updates */
if (t->options & CTX_TEXTURE) {
t->flag |= T_TEXTURE;
+
createTransTexspace(t);
+ countAndCleanTransDataContainer(t);
}
else if (t->options & CTX_EDGE) {
- t->ext = NULL;
+ /* Multi object editing. */
+ initTransDataContainers_FromObjectData(t);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ tc->data_ext = NULL;
+ }
t->flag |= T_EDIT;
+
createTransEdge(t);
- if (t->data && t->flag & T_PROP_EDIT) {
+ countAndCleanTransDataContainer(t);
+
+ if (t->data_len_all && t->flag & T_PROP_EDIT) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, 1);
sort_trans_data_dist(t);
@@ -8159,9 +8337,11 @@ void createTransData(bContext *C, TransInfo *t)
else if (t->options & CTX_GPENCIL_STROKES) {
t->options |= CTX_GPENCIL_STROKES;
t->flag |= T_POINTS;
+
createTransGPencil(C, t);
+ countAndCleanTransDataContainer(t);
- if (t->data && (t->flag & T_PROP_EDIT)) {
+ if (t->data_len_all && (t->flag & T_PROP_EDIT)) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, 1);
sort_trans_data_dist(t);
@@ -8170,22 +8350,32 @@ void createTransData(bContext *C, TransInfo *t)
else if (t->spacetype == SPACE_IMAGE) {
t->flag |= T_POINTS | T_2D_EDIT;
if (t->options & CTX_MASK) {
+
/* copied from below */
createTransMaskingData(C, t);
+ countAndCleanTransDataContainer(t);
- if (t->data && (t->flag & T_PROP_EDIT)) {
+ if (t->data_len_all && (t->flag & T_PROP_EDIT)) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, true);
sort_trans_data_dist(t);
}
}
else if (t->options & CTX_PAINT_CURVE) {
- if (!ELEM(t->mode, TFM_SHEAR, TFM_SHRINKFATTEN))
+ if (!ELEM(t->mode, TFM_SHEAR, TFM_SHRINKFATTEN)) {
createTransPaintCurveVerts(C, t);
+ countAndCleanTransDataContainer(t);
+ }
}
- else if (t->obedit) {
+ else if (t->obedit_type == OB_MESH) {
+
+ initTransDataContainers_FromObjectData(t);
createTransUVs(C, t);
- if (t->data && (t->flag & T_PROP_EDIT)) {
+ countAndCleanTransDataContainer(t);
+
+ t->flag |= T_EDIT;
+
+ if (t->data_len_all && (t->flag & T_PROP_EDIT)) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, 1);
sort_trans_data_dist(t);
@@ -8194,9 +8384,11 @@ void createTransData(bContext *C, TransInfo *t)
}
else if (t->spacetype == SPACE_ACTION) {
t->flag |= T_POINTS | T_2D_EDIT;
+
createTransActionData(C, t);
+ countAndCleanTransDataContainer(t);
- if (t->data && (t->flag & T_PROP_EDIT)) {
+ if (t->data_len_all && (t->flag & T_PROP_EDIT)) {
sort_trans_data(t); // makes selected become first in array
//set_prop_dist(t, false); /* don't do that, distance has been set in createTransActionData already */
sort_trans_data_dist(t);
@@ -8205,17 +8397,20 @@ void createTransData(bContext *C, TransInfo *t)
else if (t->spacetype == SPACE_NLA) {
t->flag |= T_POINTS | T_2D_EDIT;
createTransNlaData(C, t);
+ countAndCleanTransDataContainer(t);
}
else if (t->spacetype == SPACE_SEQ) {
t->flag |= T_POINTS | T_2D_EDIT;
t->num.flag |= NUM_NO_FRACTION; /* sequencer has no use for floating point transformations */
createTransSeqData(C, t);
+ countAndCleanTransDataContainer(t);
}
else if (t->spacetype == SPACE_IPO) {
t->flag |= T_POINTS | T_2D_EDIT;
createTransGraphEditData(C, t);
+ countAndCleanTransDataContainer(t);
- if (t->data && (t->flag & T_PROP_EDIT)) {
+ if (t->data_len_all && (t->flag & T_PROP_EDIT)) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, false); /* don't do that, distance has been set in createTransGraphEditData already */
sort_trans_data_dist(t);
@@ -8223,8 +8418,11 @@ void createTransData(bContext *C, TransInfo *t)
}
else if (t->spacetype == SPACE_NODE) {
t->flag |= T_POINTS | T_2D_EDIT;
+
createTransNodeData(C, t);
- if (t->data && (t->flag & T_PROP_EDIT)) {
+ countAndCleanTransDataContainer(t);
+
+ if (t->data_len_all && (t->flag & T_PROP_EDIT)) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, 1);
sort_trans_data_dist(t);
@@ -8232,34 +8430,42 @@ void createTransData(bContext *C, TransInfo *t)
}
else if (t->spacetype == SPACE_CLIP) {
t->flag |= T_POINTS | T_2D_EDIT;
- if (t->options & CTX_MOVIECLIP)
+ if (t->options & CTX_MOVIECLIP) {
createTransTrackingData(C, t);
+ countAndCleanTransDataContainer(t);
+ }
else if (t->options & CTX_MASK) {
/* copied from above */
createTransMaskingData(C, t);
+ countAndCleanTransDataContainer(t);
- if (t->data && (t->flag & T_PROP_EDIT)) {
+ if (t->data_len_all && (t->flag & T_PROP_EDIT)) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, true);
sort_trans_data_dist(t);
}
}
}
- else if (t->obedit) {
- t->ext = NULL;
- if (t->obedit->type == OB_MESH) {
+ else if (t->obedit_type != -1) {
+ /* Multi object editing. */
+ initTransDataContainers_FromObjectData(t);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ tc->data_ext = NULL;
+ }
+ if (t->obedit_type == OB_MESH) {
createTransEditVerts(t);
}
- else if (ELEM(t->obedit->type, OB_CURVE, OB_SURF)) {
+ else if (ELEM(t->obedit_type, OB_CURVE, OB_SURF)) {
createTransCurveVerts(t);
}
- else if (t->obedit->type == OB_LATTICE) {
+ else if (t->obedit_type == OB_LATTICE) {
createTransLatticeVerts(t);
}
- else if (t->obedit->type == OB_MBALL) {
+ else if (t->obedit_type == OB_MBALL) {
createTransMBallVerts(t);
}
- else if (t->obedit->type == OB_ARMATURE) {
+ else if (t->obedit_type == OB_ARMATURE) {
t->flag &= ~T_PROP_EDIT;
createTransArmatureVerts(t);
}
@@ -8267,12 +8473,14 @@ void createTransData(bContext *C, TransInfo *t)
printf("edit type not implemented!\n");
}
+ countAndCleanTransDataContainer(t);
+
t->flag |= T_EDIT | T_POINTS;
- if (t->data && t->flag & T_PROP_EDIT) {
- if (ELEM(t->obedit->type, OB_CURVE, OB_MESH)) {
+ if (t->data_len_all && t->flag & T_PROP_EDIT) {
+ if (ELEM(t->obedit_type, OB_CURVE, OB_MESH)) {
sort_trans_data(t); // makes selected become first in array
- if ((t->obedit->type == OB_MESH) && (t->flag & T_PROP_CONNECTED)) {
+ if ((t->obedit_type == OB_MESH) && (t->flag & T_PROP_CONNECTED)) {
/* already calculated by editmesh_set_connectivity_distance */
}
else {
@@ -8291,24 +8499,35 @@ void createTransData(bContext *C, TransInfo *t)
if (t->mode == TFM_BONESIZE) {
t->flag &= ~(T_EDIT | T_POINTS);
t->flag |= T_POSE;
- t->poseobj = ob; /* <- tsk tsk, this is going to give issues one day */
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ tc->poseobj = tc->obedit;
+ tc->obedit = NULL;
+ }
}
}
else if (ob && (ob->mode & OB_MODE_POSE)) {
// XXX this is currently limited to active armature only...
// XXX active-layer checking isn't done as that should probably be checked through context instead
- createTransPose(t, ob);
+
+ /* Multi object editing. */
+ initTransDataContainers_FromObjectData(t);
+ createTransPose(t, NULL, 0);
+ countAndCleanTransDataContainer(t);
}
else if (ob && (ob->mode & OB_MODE_WEIGHT_PAINT) && !(t->options & CTX_PAINT_CURVE)) {
/* important that ob_armature can be set even when its not selected [#23412]
* lines below just check is also visible */
Object *ob_armature = modifiers_isDeformedByArmature(ob);
if (ob_armature && ob_armature->mode & OB_MODE_POSE) {
- Base *base_arm = BKE_scene_base_find(t->scene, ob_armature);
+ Base *base_arm = BKE_view_layer_base_find(t->view_layer, ob_armature);
if (base_arm) {
- View3D *v3d = t->view;
- if (BASE_VISIBLE(v3d, base_arm)) {
- createTransPose(t, ob_armature);
+ if (BASE_VISIBLE(base_arm)) {
+ Object *objects[1];
+ objects[0] = ob_armature;
+ uint objects_len = 1;
+ createTransPose(t, objects, objects_len);
+ countAndCleanTransDataContainer(t);
}
}
@@ -8316,9 +8535,10 @@ void createTransData(bContext *C, TransInfo *t)
}
else if (ob && (ob->mode & OB_MODE_PARTICLE_EDIT) && PE_start_edit(PE_get_current(scene, ob))) {
createTransParticleVerts(C, t);
+ countAndCleanTransDataContainer(t);
t->flag |= T_POINTS;
- if (t->data && t->flag & T_PROP_EDIT) {
+ if (t->data_len_all && t->flag & T_PROP_EDIT) {
sort_trans_data(t); // makes selected become first in array
set_prop_dist(t, 1);
sort_trans_data_dist(t);
@@ -8328,13 +8548,15 @@ void createTransData(bContext *C, TransInfo *t)
if ((t->options & CTX_PAINT_CURVE) && !ELEM(t->mode, TFM_SHEAR, TFM_SHRINKFATTEN)) {
t->flag |= T_POINTS | T_2D_EDIT;
createTransPaintCurveVerts(C, t);
+ countAndCleanTransDataContainer(t);
}
}
else {
createTransObject(C, t);
+ countAndCleanTransDataContainer(t);
t->flag |= T_OBJECT;
- if (t->data && t->flag & T_PROP_EDIT) {
+ if (t->data_len_all && t->flag & T_PROP_EDIT) {
// selected objects are already first, no need to presort
set_prop_dist(t, 1);
sort_trans_data_dist(t);
@@ -8346,10 +8568,13 @@ void createTransData(bContext *C, TransInfo *t)
RegionView3D *rv3d = t->ar->regiondata;
if ((rv3d->persp == RV3D_CAMOB) && v3d->camera) {
/* we could have a flag to easily check an object is being transformed */
- if (v3d->camera->recalc) {
+ if (v3d->camera->id.tag & LIB_TAG_DOIT) {
t->flag |= T_CAMERA;
}
}
}
}
+
+ /* Check that 'countAndCleanTransDataContainer' ran. */
+ BLI_assert(t->data_len_all != -1);
}
diff --git a/source/blender/editors/transform/transform_generics.c b/source/blender/editors/transform/transform_generics.c
index 1ff602e075e..195c2ef3986 100644
--- a/source/blender/editors/transform/transform_generics.c
+++ b/source/blender/editors/transform/transform_generics.c
@@ -62,8 +62,8 @@
#include "RNA_access.h"
-#include "BIF_gl.h"
-#include "BIF_glutil.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
#include "BIK_api.h"
@@ -71,7 +71,6 @@
#include "BKE_action.h"
#include "BKE_armature.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_lattice.h"
#include "BKE_library.h"
@@ -82,6 +81,11 @@
#include "BKE_editmesh.h"
#include "BKE_tracking.h"
#include "BKE_mask.h"
+#include "BKE_workspace.h"
+#include "BKE_layer.h"
+#include "BKE_scene.h"
+
+#include "DEG_depsgraph.h"
#include "ED_anim_api.h"
#include "ED_armature.h"
@@ -102,6 +106,8 @@
#include "WM_types.h"
#include "WM_api.h"
+#include "RE_engine.h"
+
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -123,98 +129,101 @@ void getViewVector(TransInfo *t, float coord[3], float vec[3])
/* ************************** GENERICS **************************** */
-static void clipMirrorModifier(TransInfo *t, Object *ob)
+static void clipMirrorModifier(TransInfo *t)
{
- ModifierData *md = ob->modifiers.first;
- float tolerance[3] = {0.0f, 0.0f, 0.0f};
- int axis = 0;
-
- for (; md; md = md->next) {
- if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) {
- MirrorModifierData *mmd = (MirrorModifierData *) md;
-
- if (mmd->flag & MOD_MIR_CLIPPING) {
- axis = 0;
- if (mmd->flag & MOD_MIR_AXIS_X) {
- axis |= 1;
- tolerance[0] = mmd->tolerance;
- }
- if (mmd->flag & MOD_MIR_AXIS_Y) {
- axis |= 2;
- tolerance[1] = mmd->tolerance;
- }
- if (mmd->flag & MOD_MIR_AXIS_Z) {
- axis |= 4;
- tolerance[2] = mmd->tolerance;
- }
- if (axis) {
- float mtx[4][4], imtx[4][4];
- int i;
- TransData *td = t->data;
-
- if (mmd->mirror_ob) {
- float obinv[4][4];
-
- invert_m4_m4(obinv, mmd->mirror_ob->obmat);
- mul_m4_m4m4(mtx, obinv, ob->obmat);
- invert_m4_m4(imtx, mtx);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ Object *ob = tc->obedit;
+ ModifierData *md = ob->modifiers.first;
+ float tolerance[3] = {0.0f, 0.0f, 0.0f};
+ int axis = 0;
+
+ for (; md; md = md->next) {
+ if ((md->type == eModifierType_Mirror) && (md->mode & eModifierMode_Realtime)) {
+ MirrorModifierData *mmd = (MirrorModifierData *) md;
+
+ if (mmd->flag & MOD_MIR_CLIPPING) {
+ axis = 0;
+ if (mmd->flag & MOD_MIR_AXIS_X) {
+ axis |= 1;
+ tolerance[0] = mmd->tolerance;
}
-
- for (i = 0; i < t->total; i++, td++) {
- int clip;
- float loc[3], iloc[3];
-
- if (td->flag & TD_NOACTION)
- break;
- if (td->loc == NULL)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- copy_v3_v3(loc, td->loc);
- copy_v3_v3(iloc, td->iloc);
-
+ if (mmd->flag & MOD_MIR_AXIS_Y) {
+ axis |= 2;
+ tolerance[1] = mmd->tolerance;
+ }
+ if (mmd->flag & MOD_MIR_AXIS_Z) {
+ axis |= 4;
+ tolerance[2] = mmd->tolerance;
+ }
+ if (axis) {
+ float mtx[4][4], imtx[4][4];
+ int i;
+
if (mmd->mirror_ob) {
- mul_m4_v3(mtx, loc);
- mul_m4_v3(mtx, iloc);
+ float obinv[4][4];
+
+ invert_m4_m4(obinv, mmd->mirror_ob->obmat);
+ mul_m4_m4m4(mtx, obinv, ob->obmat);
+ invert_m4_m4(imtx, mtx);
}
-
- clip = 0;
- if (axis & 1) {
- if (fabsf(iloc[0]) <= tolerance[0] ||
- loc[0] * iloc[0] < 0.0f)
- {
- loc[0] = 0.0f;
- clip = 1;
+
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ int clip;
+ float loc[3], iloc[3];
+
+ if (td->flag & TD_NOACTION)
+ break;
+ if (td->loc == NULL)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ copy_v3_v3(loc, td->loc);
+ copy_v3_v3(iloc, td->iloc);
+
+ if (mmd->mirror_ob) {
+ mul_m4_v3(mtx, loc);
+ mul_m4_v3(mtx, iloc);
}
- }
-
- if (axis & 2) {
- if (fabsf(iloc[1]) <= tolerance[1] ||
- loc[1] * iloc[1] < 0.0f)
- {
- loc[1] = 0.0f;
- clip = 1;
+
+ clip = 0;
+ if (axis & 1) {
+ if (fabsf(iloc[0]) <= tolerance[0] ||
+ loc[0] * iloc[0] < 0.0f)
+ {
+ loc[0] = 0.0f;
+ clip = 1;
+ }
}
- }
- if (axis & 4) {
- if (fabsf(iloc[2]) <= tolerance[2] ||
- loc[2] * iloc[2] < 0.0f)
- {
- loc[2] = 0.0f;
- clip = 1;
+
+ if (axis & 2) {
+ if (fabsf(iloc[1]) <= tolerance[1] ||
+ loc[1] * iloc[1] < 0.0f)
+ {
+ loc[1] = 0.0f;
+ clip = 1;
+ }
}
- }
- if (clip) {
- if (mmd->mirror_ob) {
- mul_m4_v3(imtx, loc);
+ if (axis & 4) {
+ if (fabsf(iloc[2]) <= tolerance[2] ||
+ loc[2] * iloc[2] < 0.0f)
+ {
+ loc[2] = 0.0f;
+ clip = 1;
+ }
+ }
+ if (clip) {
+ if (mmd->mirror_ob) {
+ mul_m4_v3(imtx, loc);
+ }
+ copy_v3_v3(td->loc, loc);
}
- copy_v3_v3(td->loc, loc);
}
}
+
}
-
}
}
}
@@ -223,27 +232,29 @@ static void clipMirrorModifier(TransInfo *t, Object *ob)
/* assumes obedit set to mesh object */
static void editbmesh_apply_to_mirror(TransInfo *t)
{
- TransData *td = t->data;
- BMVert *eve;
- int i;
-
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_NOACTION)
- break;
- if (td->loc == NULL)
- break;
- if (td->flag & TD_SKIP)
- continue;
-
- eve = td->extra;
- if (eve) {
- eve->co[0] = -td->loc[0];
- eve->co[1] = td->loc[1];
- eve->co[2] = td->loc[2];
- }
-
- if (td->flag & TD_MIRROR_EDGE) {
- td->loc[0] = 0;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ BMVert *eve;
+ int i;
+
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_NOACTION)
+ break;
+ if (td->loc == NULL)
+ break;
+ if (td->flag & TD_SKIP)
+ continue;
+
+ eve = td->extra;
+ if (eve) {
+ eve->co[0] = -td->loc[0];
+ eve->co[1] = td->loc[1];
+ eve->co[2] = td->loc[2];
+ }
+
+ if (td->flag & TD_MIRROR_EDGE) {
+ td->loc[0] = 0;
+ }
}
}
}
@@ -338,7 +349,7 @@ static bool fcu_test_selected(FCurve *fcu)
/* helper for recalcData() - for Action Editor transforms */
static void recalcData_actedit(TransInfo *t)
{
- Scene *scene = t->scene;
+ ViewLayer *view_layer = t->view_layer;
SpaceAction *saction = (SpaceAction *)t->sa->spacedata.first;
bAnimContext ac = {NULL};
@@ -349,7 +360,8 @@ static void recalcData_actedit(TransInfo *t)
/* initialize relevant anim-context 'context' data from TransInfo data */
/* NOTE: sync this with the code in ANIM_animdata_get_context() */
ac.scene = t->scene;
- ac.obact = OBACT;
+ ac.view_layer = t->view_layer;
+ ac.obact = OBACT(view_layer);
ac.sa = t->sa;
ac.ar = t->ar;
ac.sl = (t->sa) ? t->sa->spacedata.first : NULL;
@@ -386,7 +398,7 @@ static void recalcData_actedit(TransInfo *t)
static void recalcData_graphedit(TransInfo *t)
{
SpaceIpo *sipo = (SpaceIpo *)t->sa->spacedata.first;
- Scene *scene;
+ ViewLayer *view_layer = t->view_layer;
ListBase anim_data = {NULL, NULL};
bAnimContext ac = {NULL};
@@ -397,8 +409,9 @@ static void recalcData_graphedit(TransInfo *t)
/* initialize relevant anim-context 'context' data from TransInfo data */
/* NOTE: sync this with the code in ANIM_animdata_get_context() */
- scene = ac.scene = t->scene;
- ac.obact = OBACT;
+ ac.scene = t->scene;
+ ac.view_layer = t->view_layer;
+ ac.obact = OBACT(view_layer);
ac.sa = t->sa;
ac.ar = t->ar;
ac.sl = (t->sa) ? t->sa->spacedata.first : NULL;
@@ -450,12 +463,14 @@ static void recalcData_nla(TransInfo *t)
Scene *scene = t->scene;
double secf = FPS;
int i;
-
+
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
/* for each strip we've got, perform some additional validation of the values that got set before
* using RNA to set the value (which does some special operations when setting these values to make
* sure that everything works ok)
*/
- for (i = 0; i < t->total; i++, tdn++) {
+ for (i = 0; i < tc->data_len; i++, tdn++) {
NlaStrip *strip = tdn->strip;
PointerRNA strip_ptr;
short pExceeded, nExceeded, iter;
@@ -660,7 +675,7 @@ static void recalcData_mask_common(TransInfo *t)
flushTransMasking(t);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
}
/* helper for recalcData() - for Image Editor transforms */
@@ -672,14 +687,18 @@ static void recalcData_image(TransInfo *t)
else if (t->options & CTX_PAINT_CURVE) {
flushTransPaintCurve(t);
}
- else if (t->obedit && t->obedit->type == OB_MESH) {
+ else if ((t->flag & T_EDIT) && t->obedit_type == OB_MESH) {
SpaceImage *sima = t->sa->spacedata.first;
flushTransUVs(t);
if (sima->flag & SI_LIVE_UNWRAP)
ED_uvedit_live_unwrap_re_solve();
-
- DAG_id_tag_update(t->obedit->data, 0);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ if (tc->data_len) {
+ DEG_id_tag_update(tc->obedit->data, 0);
+ }
+ }
}
}
@@ -722,7 +741,7 @@ static void recalcData_spaceclip(TransInfo *t)
track = track->next;
}
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
}
else if (t->options & CTX_MASK) {
recalcData_mask_common(t);
@@ -732,54 +751,59 @@ static void recalcData_spaceclip(TransInfo *t)
/* helper for recalcData() - for object transforms, typically in the 3D view */
static void recalcData_objects(TransInfo *t)
{
- Base *base = t->scene->basact;
+ Base *base = t->view_layer->basact;
+
+ if (t->obedit_type != -1) {
+ if (ELEM(t->obedit_type, OB_CURVE, OB_SURF)) {
- if (t->obedit) {
- if (ELEM(t->obedit->type, OB_CURVE, OB_SURF)) {
- Curve *cu = t->obedit->data;
- ListBase *nurbs = BKE_curve_editNurbs_get(cu);
- Nurb *nu = nurbs->first;
-
if (t->state != TRANS_CANCEL) {
- clipMirrorModifier(t, t->obedit);
+ clipMirrorModifier(t);
applyProject(t);
}
-
- DAG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */
-
- if (t->state == TRANS_CANCEL) {
- while (nu) {
- BKE_nurb_handles_calc(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
- nu = nu->next;
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ Curve *cu = tc->obedit->data;
+ ListBase *nurbs = BKE_curve_editNurbs_get(cu);
+ Nurb *nu = nurbs->first;
+
+ DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */
+
+ if (t->state == TRANS_CANCEL) {
+ while (nu) {
+ BKE_nurb_handles_calc(nu); /* Cant do testhandlesNurb here, it messes up the h1 and h2 flags */
+ nu = nu->next;
+ }
}
- }
- else {
- /* Normal updating */
- while (nu) {
- BKE_nurb_test2D(nu);
- BKE_nurb_handles_calc(nu);
- nu = nu->next;
+ else {
+ /* Normal updating */
+ while (nu) {
+ BKE_nurb_test2D(nu);
+ BKE_nurb_handles_calc(nu);
+ nu = nu->next;
+ }
}
}
}
- else if (t->obedit->type == OB_LATTICE) {
- Lattice *la = t->obedit->data;
-
+ else if (t->obedit_type == OB_LATTICE) {
+
if (t->state != TRANS_CANCEL) {
applyProject(t);
}
-
- DAG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */
-
- if (la->editlatt->latt->flag & LT_OUTSIDE) outside_lattice(la->editlatt->latt);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ Lattice *la = tc->obedit->data;
+ DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */
+ if (la->editlatt->latt->flag & LT_OUTSIDE) {
+ outside_lattice(la->editlatt->latt);
+ }
+ }
}
- else if (t->obedit->type == OB_MESH) {
- BMEditMesh *em = BKE_editmesh_from_object(t->obedit);
+ else if (t->obedit_type == OB_MESH) {
/* mirror modifier clipping? */
if (t->state != TRANS_CANCEL) {
/* apply clipping after so we never project past the clip plane [#25423] */
applyProject(t);
- clipMirrorModifier(t, t->obedit);
+ clipMirrorModifier(t);
}
if ((t->options & CTX_NO_MIRROR) == 0 && (t->flag & T_MIRROR))
editbmesh_apply_to_mirror(t);
@@ -791,135 +815,152 @@ static void recalcData_objects(TransInfo *t)
projectVertSlideData(t, false);
}
- DAG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */
-
- EDBM_mesh_normals_update(em);
- BKE_editmesh_tessface_calc(em);
- }
- else if (t->obedit->type == OB_ARMATURE) { /* no recalc flag, does pose */
- bArmature *arm = t->obedit->data;
- ListBase *edbo = arm->edbo;
- EditBone *ebo, *ebo_parent;
- TransData *td = t->data;
- int i;
-
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */
+ BMEditMesh *em = BKE_editmesh_from_object(tc->obedit);
+ EDBM_mesh_normals_update(em);
+ BKE_editmesh_tessface_calc(em);
+ }
+ }
+ else if (t->obedit_type == OB_ARMATURE) { /* no recalc flag, does pose */
+
if (t->state != TRANS_CANCEL) {
applyProject(t);
}
-
- /* Ensure all bones are correctly adjusted */
- for (ebo = edbo->first; ebo; ebo = ebo->next) {
- ebo_parent = (ebo->flag & BONE_CONNECTED) ? ebo->parent : NULL;
-
- if (ebo_parent) {
- /* If this bone has a parent tip that has been moved */
- if (ebo_parent->flag & BONE_TIPSEL) {
- copy_v3_v3(ebo->head, ebo_parent->tail);
- if (t->mode == TFM_BONE_ENVELOPE) ebo->rad_head = ebo_parent->rad_tail;
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ bArmature *arm = tc->obedit->data;
+ ListBase *edbo = arm->edbo;
+ EditBone *ebo, *ebo_parent;
+ TransData *td = tc->data;
+ int i;
+
+ /* Ensure all bones are correctly adjusted */
+ for (ebo = edbo->first; ebo; ebo = ebo->next) {
+ ebo_parent = (ebo->flag & BONE_CONNECTED) ? ebo->parent : NULL;
+
+ if (ebo_parent) {
+ /* If this bone has a parent tip that has been moved */
+ if (ebo_parent->flag & BONE_TIPSEL) {
+ copy_v3_v3(ebo->head, ebo_parent->tail);
+ if (t->mode == TFM_BONE_ENVELOPE) ebo->rad_head = ebo_parent->rad_tail;
+ }
+ /* If this bone has a parent tip that has NOT been moved */
+ else {
+ copy_v3_v3(ebo_parent->tail, ebo->head);
+ if (t->mode == TFM_BONE_ENVELOPE) ebo_parent->rad_tail = ebo->rad_head;
+ }
}
- /* If this bone has a parent tip that has NOT been moved */
- else {
- copy_v3_v3(ebo_parent->tail, ebo->head);
- if (t->mode == TFM_BONE_ENVELOPE) ebo_parent->rad_tail = ebo->rad_head;
+
+ /* on extrude bones, oldlength==0.0f, so we scale radius of points */
+ ebo->length = len_v3v3(ebo->head, ebo->tail);
+ if (ebo->oldlength == 0.0f) {
+ ebo->rad_head = 0.25f * ebo->length;
+ ebo->rad_tail = 0.10f * ebo->length;
+ ebo->dist = 0.25f * ebo->length;
+ if (ebo->parent) {
+ if (ebo->rad_head > ebo->parent->rad_tail)
+ ebo->rad_head = ebo->parent->rad_tail;
+ }
}
- }
-
- /* on extrude bones, oldlength==0.0f, so we scale radius of points */
- ebo->length = len_v3v3(ebo->head, ebo->tail);
- if (ebo->oldlength == 0.0f) {
- ebo->rad_head = 0.25f * ebo->length;
- ebo->rad_tail = 0.10f * ebo->length;
- ebo->dist = 0.25f * ebo->length;
- if (ebo->parent) {
- if (ebo->rad_head > ebo->parent->rad_tail)
- ebo->rad_head = ebo->parent->rad_tail;
+ else if (t->mode != TFM_BONE_ENVELOPE) {
+ /* if bones change length, lets do that for the deform distance as well */
+ ebo->dist *= ebo->length / ebo->oldlength;
+ ebo->rad_head *= ebo->length / ebo->oldlength;
+ ebo->rad_tail *= ebo->length / ebo->oldlength;
+ ebo->oldlength = ebo->length;
+
+ if (ebo_parent) {
+ ebo_parent->rad_tail = ebo->rad_head;
+ }
}
}
- else if (t->mode != TFM_BONE_ENVELOPE) {
- /* if bones change length, lets do that for the deform distance as well */
- ebo->dist *= ebo->length / ebo->oldlength;
- ebo->rad_head *= ebo->length / ebo->oldlength;
- ebo->rad_tail *= ebo->length / ebo->oldlength;
- ebo->oldlength = ebo->length;
- if (ebo_parent) {
- ebo_parent->rad_tail = ebo->rad_head;
- }
- }
- }
-
- if (!ELEM(t->mode, TFM_BONE_ROLL, TFM_BONE_ENVELOPE, TFM_BONE_ENVELOPE_DIST, TFM_BONESIZE)) {
- /* fix roll */
- for (i = 0; i < t->total; i++, td++) {
- if (td->extra) {
- float vec[3], up_axis[3];
- float qrot[4];
- float roll;
-
- ebo = td->extra;
+ if (!ELEM(t->mode, TFM_BONE_ROLL, TFM_BONE_ENVELOPE, TFM_BONE_ENVELOPE_DIST, TFM_BONESIZE)) {
+ /* fix roll */
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->extra) {
+ float vec[3], up_axis[3];
+ float qrot[4];
+ float roll;
- if (t->state == TRANS_CANCEL) {
- /* restore roll */
- ebo->roll = td->ival;
- }
- else {
- copy_v3_v3(up_axis, td->axismtx[2]);
+ ebo = td->extra;
+
+ if (t->state == TRANS_CANCEL) {
+ /* restore roll */
+ ebo->roll = td->ival;
+ }
+ else {
+ copy_v3_v3(up_axis, td->axismtx[2]);
- sub_v3_v3v3(vec, ebo->tail, ebo->head);
- normalize_v3(vec);
- rotation_between_vecs_to_quat(qrot, td->axismtx[1], vec);
- mul_qt_v3(qrot, up_axis);
+ sub_v3_v3v3(vec, ebo->tail, ebo->head);
+ normalize_v3(vec);
+ rotation_between_vecs_to_quat(qrot, td->axismtx[1], vec);
+ mul_qt_v3(qrot, up_axis);
- /* roll has a tendency to flip in certain orientations - [#34283], [#33974] */
- roll = ED_armature_ebone_roll_to_vector(ebo, up_axis, false);
- ebo->roll = angle_compat_rad(roll, td->ival);
+ /* roll has a tendency to flip in certain orientations - [#34283], [#33974] */
+ roll = ED_armature_ebone_roll_to_vector(ebo, up_axis, false);
+ ebo->roll = angle_compat_rad(roll, td->ival);
+ }
}
}
}
- }
-
- if (arm->flag & ARM_MIRROR_EDIT) {
- if (t->state != TRANS_CANCEL)
- ED_armature_edit_transform_mirror_update(t->obedit);
- else
- restoreBones(t);
+
+ if (arm->flag & ARM_MIRROR_EDIT) {
+ if (t->state != TRANS_CANCEL) {
+ ED_armature_edit_transform_mirror_update(tc->obedit);
+ }
+ else {
+ restoreBones(tc);
+ }
+ }
}
}
else {
if (t->state != TRANS_CANCEL) {
applyProject(t);
}
- DAG_id_tag_update(t->obedit->data, 0); /* sets recalc flags */
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ if (tc->data_len) {
+ DEG_id_tag_update(tc->obedit->data, 0); /* sets recalc flags */
+ }
+ }
}
+
}
- else if ((t->flag & T_POSE) && t->poseobj) {
- Object *ob = t->poseobj;
- bArmature *arm = ob->data;
-
- /* if animtimer is running, and the object already has animation data,
- * check if the auto-record feature means that we should record 'samples'
- * (i.e. uneditable animation values)
- *
- * context is needed for keying set poll() functions.
- */
- // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
- if ((t->animtimer) && (t->context) && IS_AUTOKEY_ON(t->scene)) {
- int targetless_ik = (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet!
-
- animrecord_check_state(t->scene, &ob->id, t->animtimer);
- autokeyframe_pose_cb_func(t->context, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
- }
-
- /* old optimize trick... this enforces to bypass the depgraph */
- if (!(arm->flag & ARM_DELAYDEFORM)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
- /* transformation of pose may affect IK tree, make sure it is rebuilt */
- BIK_clear_data(ob->pose);
+ else if (t->flag & T_POSE) {
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ Object *ob = tc->poseobj;
+ bArmature *arm = ob->data;
+
+ /* if animtimer is running, and the object already has animation data,
+ * check if the auto-record feature means that we should record 'samples'
+ * (i.e. uneditable animation values)
+ *
+ * context is needed for keying set poll() functions.
+ */
+ // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
+ if ((t->animtimer) && (t->context) && IS_AUTOKEY_ON(t->scene)) {
+ int targetless_ik = (t->flag & T_AUTOIK); // XXX this currently doesn't work, since flags aren't set yet!
+
+ animrecord_check_state(t->scene, &ob->id, t->animtimer);
+ autokeyframe_pose_cb_func(t->context, t->scene, (View3D *)t->view, ob, t->mode, targetless_ik);
+ }
+
+ /* old optimize trick... this enforces to bypass the depgraph */
+ if (!(arm->flag & ARM_DELAYDEFORM)) {
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA); /* sets recalc flags */
+ /* transformation of pose may affect IK tree, make sure it is rebuilt */
+ BIK_clear_data(ob->pose);
+ }
+ else {
+ BKE_pose_where_is(t->depsgraph, t->scene, ob);
+ }
}
- else
- BKE_pose_where_is(t->scene, ob);
}
- else if (base && (base->object->mode & OB_MODE_PARTICLE_EDIT) && PE_get_current(t->scene, base->object)) {
+ else if (base && (base->object->mode & OB_MODE_PARTICLE_EDIT) &&
+ PE_get_current(t->scene, base->object))
+ {
if (t->state != TRANS_CANCEL) {
applyProject(t);
}
@@ -931,34 +972,37 @@ static void recalcData_objects(TransInfo *t)
if (t->state != TRANS_CANCEL) {
applyProject(t);
}
-
- for (i = 0; i < t->total; i++) {
- TransData *td = t->data + i;
- Object *ob = td->ob;
-
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- /* if animtimer is running, and the object already has animation data,
- * check if the auto-record feature means that we should record 'samples'
- * (i.e. uneditable animation values)
- */
- // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
- if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
- animrecord_check_state(t->scene, &ob->id, t->animtimer);
- autokeyframe_ob_cb_func(t->context, t->scene, (View3D *)t->view, ob, t->mode);
- }
-
- /* sets recalc flags fully, instead of flushing existing ones
- * otherwise proxies don't function correctly
- */
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
- if (t->flag & T_TEXTURE)
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+
+ for (i = 0; i < tc->data_len; i++, td++) {
+ Object *ob = td->ob;
+
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ /* if animtimer is running, and the object already has animation data,
+ * check if the auto-record feature means that we should record 'samples'
+ * (i.e. uneditable animation values)
+ */
+ // TODO: autokeyframe calls need some setting to specify to add samples (FPoints) instead of keyframes?
+ if ((t->animtimer) && IS_AUTOKEY_ON(t->scene)) {
+ animrecord_check_state(t->scene, &ob->id, t->animtimer);
+ autokeyframe_ob_cb_func(t->context, t->scene, t->view_layer, (View3D *)t->view, ob, t->mode);
+ }
+
+ /* sets recalc flags fully, instead of flushing existing ones
+ * otherwise proxies don't function correctly
+ */
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
+
+ if (t->flag & T_TEXTURE)
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ }
}
}
}
@@ -970,7 +1014,9 @@ static void recalcData_sequencer(TransInfo *t)
int a;
Sequence *seq_prev = NULL;
- for (a = 0, td = t->data; a < t->total; a++, td++) {
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ for (a = 0, td = tc->data; a < tc->data_len; a++, td++) {
TransDataSeq *tdsq = (TransDataSeq *) td->extra;
Sequence *seq = tdsq->seq;
@@ -995,8 +1041,10 @@ static void recalcData_sequencer(TransInfo *t)
/* force recalculation of triangles during transformation */
static void recalcData_gpencil_strokes(TransInfo *t)
{
- TransData *td = t->data;
- for (int i = 0; i < t->total; i++, td++) {
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
+ TransData *td = tc->data;
+ for (int i = 0; i < tc->data_len; i++, td++) {
bGPDstroke *gps = td->extra;
if (gps != NULL) {
gps->flag |= GP_STROKE_RECALC_CACHES;
@@ -1055,11 +1103,8 @@ void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis
if (t->spacetype == SPACE_VIEW3D) {
View3D *v3d = t->view;
- glPushMatrix();
-
- //if (t->obedit) glLoadMatrixf(t->obedit->obmat); // sets opengl viewing
-
-
+ gpuPushMatrix();
+
copy_v3_v3(v3, dir);
mul_v3_fl(v3, v3d->far);
@@ -1073,15 +1118,20 @@ void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis
UI_GetThemeColor3ubv(TH_GRID, col);
}
UI_make_axis_color(col, col2, axis);
- glColor3ubv(col2);
-
- setlinestyle(0);
- glBegin(GL_LINES);
- glVertex3fv(v1);
- glVertex3fv(v2);
- glEnd();
-
- glPopMatrix();
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+ immUniformColor3ubv(col2);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex3fv(pos, v1);
+ immVertex3fv(pos, v2);
+ immEnd();
+
+ immUnbindProgram();
+
+ gpuPopMatrix();
}
}
@@ -1090,12 +1140,7 @@ void drawLine(TransInfo *t, const float center[3], const float dir[3], char axis
*/
void resetTransModal(TransInfo *t)
{
- if (t->mode == TFM_EDGE_SLIDE) {
- freeEdgeSlideVerts(t, &t->custom.mode);
- }
- else if (t->mode == TFM_VERT_SLIDE) {
- freeVertSlideVerts(t, &t->custom.mode);
- }
+ freeTransCustomDataForMode(t);
}
void resetTransRestrictions(TransInfo *t)
@@ -1117,6 +1162,53 @@ static int initTransInfo_edit_pet_to_flag(const int proportional)
}
}
+void initTransDataContainers_FromObjectData(TransInfo *t)
+{
+ const eObjectMode object_mode = OBACT(t->view_layer) ? OBACT(t->view_layer)->mode : OB_MODE_OBJECT;
+ const short object_type = OBACT(t->view_layer) ? OBACT(t->view_layer)->type : -1;
+
+ if ((object_mode & OB_MODE_EDIT) ||
+ ((object_mode & OB_MODE_POSE) && (object_type == OB_ARMATURE)))
+ {
+ if (t->data_container) {
+ MEM_freeN(t->data_container);
+ }
+ uint objects_len;
+ Object **objects = BKE_view_layer_array_from_objects_in_mode(
+ t->view_layer, &objects_len, {
+ .object_mode = object_mode,
+ .no_dup_data = true});
+ t->data_container = MEM_callocN(sizeof(*t->data_container) * objects_len, __func__);
+ t->data_container_len = objects_len;
+
+ for (int i = 0; i < objects_len; i++) {
+ TransDataContainer *tc = &t->data_container[i];
+ if (object_mode & OB_MODE_EDIT) {
+ tc->obedit = objects[i];
+ /* Check needed for UV's */
+ if ((t->flag & T_2D_EDIT) == 0) {
+ tc->use_local_mat = true;
+ }
+ }
+ else if (object_mode & OB_MODE_POSE) {
+ tc->poseobj = objects[i];
+ tc->use_local_mat = true;
+ }
+
+ if (tc->use_local_mat) {
+ BLI_assert((t->flag & T_2D_EDIT) == 0);
+ copy_m4_m4(tc->mat, objects[i]->obmat);
+ copy_m3_m4(tc->mat3, tc->mat);
+ invert_m4_m4(tc->imat, tc->mat);
+ invert_m3_m3(tc->imat3, tc->mat3);
+ normalize_m3_m3(tc->mat3_unit, tc->mat3);
+ }
+ /* Otherwise leave as zero. */
+ }
+ MEM_freeN(objects);
+ }
+}
+
/**
* Setup internal data, mouse, vectors
*
@@ -1126,34 +1218,38 @@ static int initTransInfo_edit_pet_to_flag(const int proportional)
*/
void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *event)
{
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
Scene *sce = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ const eObjectMode object_mode = OBACT(view_layer) ? OBACT(view_layer)->mode : OB_MODE_OBJECT;
+ const short object_type = OBACT(view_layer) ? OBACT(view_layer)->type : -1;
ToolSettings *ts = CTX_data_tool_settings(C);
ARegion *ar = CTX_wm_region(C);
ScrArea *sa = CTX_wm_area(C);
- Object *obedit = CTX_data_edit_object(C);
- Object *ob = CTX_data_active_object(C);
+
bGPdata *gpd = CTX_data_gpencil_data(C);
PropertyRNA *prop;
-
+
+ t->depsgraph = depsgraph;
t->scene = sce;
+ t->view_layer = view_layer;
t->sa = sa;
t->ar = ar;
- t->obedit = obedit;
t->settings = ts;
t->reports = op ? op->reports : NULL;
- if (obedit) {
- copy_m3_m4(t->obedit_mat, obedit->obmat);
- normalize_m3(t->obedit_mat);
- }
-
- t->data = NULL;
- t->ext = NULL;
-
t->helpline = HLP_NONE;
t->flag = 0;
-
+
+ t->obedit_type = (object_mode == OB_MODE_EDIT) ? object_type : -1;
+
+ /* Many kinds of transform only use a single handle. */
+ if (t->data_container == NULL) {
+ t->data_container = MEM_callocN(sizeof(*t->data_container), __func__);
+ t->data_container_len = 1;
+ }
+
t->redraw = TREDRAW_HARD; /* redraw first time */
if (event) {
@@ -1174,12 +1270,11 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->transform = NULL;
t->handleEvent = NULL;
- t->total = 0;
+ t->data_len_all = 0;
t->val = 0.0f;
zero_v3(t->vec);
- zero_v3(t->center);
zero_v3(t->center_global);
unit_m3(t->mat);
@@ -1243,10 +1338,9 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->animtimer = (animscreen) ? animscreen->animtimer : NULL;
/* turn manipulator off during transform */
- // FIXME: but don't do this when USING the manipulator...
if (t->flag & T_MODAL) {
- t->twtype = v3d->twtype;
- v3d->twtype = 0;
+ t->twflag = v3d->twflag;
+ v3d->twflag = 0;
}
if (v3d->flag & V3D_ALIGN) t->flag |= T_V3D_ALIGN;
@@ -1257,20 +1351,22 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->around = V3D_AROUND_CURSOR;
}
- t->current_orientation = v3d->twmode;
+ t->current_orientation = t->scene->orientation_type;
+ t->custom_orientation = BKE_scene_transform_orientation_find(
+ t->scene, t->scene->orientation_index_custom);
/* exceptional case */
if (t->around == V3D_AROUND_LOCAL_ORIGINS) {
if (ELEM(t->mode, TFM_ROTATION, TFM_RESIZE, TFM_TRACKBALL)) {
const bool use_island = transdata_check_local_islands(t, t->around);
- if (obedit && !use_island) {
+ if ((t->obedit_type != -1) && !use_island) {
t->options |= CTX_NO_PET;
}
}
}
- if (ob && ob->mode & OB_MODE_ALL_PAINT) {
+ if (object_mode & OB_MODE_ALL_PAINT) {
Paint *p = BKE_paint_get_active_from_context(C);
if (p && p->brush && (p->brush->flag & BRUSH_CURVE)) {
t->options |= CTX_PAINT_CURVE;
@@ -1299,7 +1395,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
t->view = &ar->v2d;
t->around = sima->around;
- if (ED_space_image_show_uvedit(sima, t->obedit)) {
+ if (ED_space_image_show_uvedit(sima, OBACT(t->view_layer))) {
/* UV transform */
}
else if (sima->mode == SI_MODE_MASK) {
@@ -1348,11 +1444,22 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
if (op && ((prop = RNA_struct_find_property(op->ptr, "constraint_orientation")) &&
RNA_property_is_set(op->ptr, prop)))
{
- t->current_orientation = RNA_property_enum_get(op->ptr, prop);
+ short orientation = RNA_property_enum_get(op->ptr, prop);
+ TransformOrientation *custom_orientation = NULL;
- if (t->current_orientation >= V3D_MANIP_CUSTOM + BIF_countTransformOrientation(C)) {
- t->current_orientation = V3D_MANIP_GLOBAL;
+ if (orientation >= V3D_MANIP_CUSTOM) {
+ if (orientation >= V3D_MANIP_CUSTOM + BIF_countTransformOrientation(C)) {
+ orientation = V3D_MANIP_GLOBAL;
+ }
+ else {
+ custom_orientation = BKE_scene_transform_orientation_find(
+ t->scene, orientation - V3D_MANIP_CUSTOM);
+ orientation = V3D_MANIP_CUSTOM;
+ }
}
+
+ t->current_orientation = orientation;
+ t->custom_orientation = custom_orientation;
}
if (op && ((prop = RNA_struct_find_property(op->ptr, "release_confirm")) &&
@@ -1378,7 +1485,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
// Need stuff to take it from edit mesh or whatnot here
else if (t->spacetype == SPACE_VIEW3D) {
- if (t->obedit && t->obedit->type == OB_MESH && (((Mesh *)t->obedit->data)->editflag & ME_EDIT_MIRROR_X)) {
+ /* TODO(campbell): xform, get mirror from each object. */
+ if (t->obedit_type == OB_MESH && (((Mesh *)OBACT(t->view_layer)->data)->editflag & ME_EDIT_MIRROR_X)) {
t->flag |= T_MIRROR;
t->mirror = 1;
}
@@ -1399,7 +1507,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
else if (t->spacetype == SPACE_ACTION) {
t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional_action);
}
- else if (t->obedit) {
+ else if (t->obedit_type != -1) {
t->flag |= initTransInfo_edit_pet_to_flag(ts->proportional);
}
else if (t->options & CTX_GPENCIL_STROKES) {
@@ -1414,7 +1522,7 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
}
}
}
- else if (t->obedit == NULL && ts->proportional_objects) {
+ else if ((t->obedit_type == -1) && ts->proportional_objects) {
t->flag |= T_PROP_EDIT;
}
}
@@ -1460,8 +1568,8 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
setTransformViewAspect(t, t->aspect);
if (op && (prop = RNA_struct_find_property(op->ptr, "center_override")) && RNA_property_is_set(op->ptr, prop)) {
- RNA_property_float_get_array(op->ptr, prop, t->center);
- mul_v3_v3(t->center, t->aspect);
+ RNA_property_float_get_array(op->ptr, prop, t->center_global);
+ mul_v3_v3(t->center_global, t->aspect);
t->flag |= T_OVERRIDE_CENTER;
}
@@ -1469,11 +1577,47 @@ void initTransInfo(bContext *C, TransInfo *t, wmOperator *op, const wmEvent *eve
initNumInput(&t->num);
}
+
+static void freeTransCustomData(
+ TransInfo *t, TransDataContainer *tc,
+ TransCustomData *custom_data)
+{
+ if (custom_data->free_cb) {
+ /* Can take over freeing t->data and data_2d etc... */
+ custom_data->free_cb(t, tc, custom_data);
+ BLI_assert(custom_data->data == NULL);
+ }
+ else if ((custom_data->data != NULL) && custom_data->use_free) {
+ MEM_freeN(custom_data->data);
+ custom_data->data = NULL;
+ }
+ /* In case modes are switched in the same transform session. */
+ custom_data->free_cb = false;
+ custom_data->use_free = false;
+}
+
+static void freeTransCustomDataContainer(TransInfo *t, TransDataContainer *tc, TransCustomDataContainer *tcdc)
+{
+ TransCustomData *custom_data = &tcdc->first_elem;
+ for (int i = 0; i < TRANS_CUSTOM_DATA_ELEM_MAX; i++, custom_data++) {
+ freeTransCustomData(t, tc, custom_data);
+ }
+}
+
+/**
+ * Needed for mode switching.
+ */
+void freeTransCustomDataForMode(TransInfo *t)
+{
+ freeTransCustomData(t, NULL, &t->custom.mode);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ freeTransCustomData(t, tc, &tc->custom.mode);
+ }
+}
+
/* Here I would suggest only TransInfo related issues, like free data & reset vars. Not redraws */
void postTrans(bContext *C, TransInfo *t)
{
- TransData *td;
-
if (t->draw_handle_view)
ED_region_draw_cb_exit(t->ar->type, t->draw_handle_view);
if (t->draw_handle_apply)
@@ -1484,46 +1628,37 @@ void postTrans(bContext *C, TransInfo *t)
WM_paint_cursor_end(CTX_wm_manager(C), t->draw_handle_cursor);
/* Free all custom-data */
- {
- TransCustomData *custom_data = &t->custom.first_elem;
- for (int i = 0; i < TRANS_CUSTOM_DATA_ELEM_MAX; i++, custom_data++) {
- if (custom_data->free_cb) {
- /* Can take over freeing t->data and data2d etc... */
- custom_data->free_cb(t, custom_data);
- BLI_assert(custom_data->data == NULL);
- }
- else if ((custom_data->data != NULL) && custom_data->use_free) {
- MEM_freeN(custom_data->data);
- custom_data->data = NULL;
- }
- }
+ freeTransCustomDataContainer(t, NULL, &t->custom);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ freeTransCustomDataContainer(t, tc, &tc->custom);
}
/* postTrans can be called when nothing is selected, so data is NULL already */
- if (t->data) {
-
- /* free data malloced per trans-data */
- if ((t->obedit && ELEM(t->obedit->type, OB_CURVE, OB_SURF)) ||
- (t->spacetype == SPACE_IPO))
- {
- int a;
- for (a = 0, td = t->data; a < t->total; a++, td++) {
- if (td->flag & TD_BEZTRIPLE) {
- MEM_freeN(td->hdata);
+ if (t->data_len_all != 0) {
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ /* free data malloced per trans-data */
+ if (ELEM(t->obedit_type, OB_CURVE, OB_SURF) ||
+ (t->spacetype == SPACE_IPO))
+ {
+ TransData *td = tc->data;
+ for (int a = 0; a < tc->data_len; a++, td++) {
+ if (td->flag & TD_BEZTRIPLE) {
+ MEM_freeN(td->hdata);
+ }
}
}
+ MEM_freeN(tc->data);
+
+ MEM_SAFE_FREE(tc->data_ext);
+ MEM_SAFE_FREE(tc->data_2d);
}
- MEM_freeN(t->data);
}
+ MEM_SAFE_FREE(t->data_container);
+ t->data_container = NULL;
+
BLI_freelistN(&t->tsnap.points);
- if (t->ext) MEM_freeN(t->ext);
- if (t->data2d) {
- MEM_freeN(t->data2d);
- t->data2d = NULL;
- }
-
if (t->spacetype == SPACE_IMAGE) {
if (t->options & (CTX_MASK | CTX_PAINT_CURVE)) {
/* pass */
@@ -1538,7 +1673,7 @@ void postTrans(bContext *C, TransInfo *t)
View3D *v3d = t->sa->spacedata.first;
/* restore manipulator */
if (t->flag & T_MODAL) {
- v3d->twtype = t->twtype;
+ v3d->twflag = t->twflag;
}
}
@@ -1551,9 +1686,11 @@ void postTrans(bContext *C, TransInfo *t)
void applyTransObjects(TransInfo *t)
{
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_SINGLE(t);
+
TransData *td;
-
- for (td = t->data; td < t->data + t->total; td++) {
+
+ for (td = tc->data; td < tc->data + tc->data_len; td++) {
copy_v3_v3(td->iloc, td->loc);
if (td->ext->rot) {
copy_v3_v3(td->ext->irot, td->ext->rot);
@@ -1602,25 +1739,29 @@ static void restoreElement(TransData *td)
void restoreTransObjects(TransInfo *t)
{
- TransData *td;
- TransData2D *td2d;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
- for (td = t->data; td < t->data + t->total; td++) {
- restoreElement(td);
- }
-
- for (td2d = t->data2d; t->data2d && td2d < t->data2d + t->total; td2d++) {
- if (td2d->h1) {
- td2d->h1[0] = td2d->ih1[0];
- td2d->h1[1] = td2d->ih1[1];
+ TransData *td;
+ TransData2D *td2d;
+
+ for (td = tc->data; td < tc->data + tc->data_len; td++) {
+ restoreElement(td);
}
- if (td2d->h2) {
- td2d->h2[0] = td2d->ih2[0];
- td2d->h2[1] = td2d->ih2[1];
+
+ for (td2d = tc->data_2d; tc->data_2d && td2d < tc->data_2d + tc->data_len; td2d++) {
+ if (td2d->h1) {
+ td2d->h1[0] = td2d->ih1[0];
+ td2d->h1[1] = td2d->ih1[1];
+ }
+ if (td2d->h2) {
+ td2d->h2[0] = td2d->ih2[0];
+ td2d->h2[1] = td2d->ih2[1];
+ }
}
- }
- unit_m3(t->mat);
+ unit_m3(t->mat);
+
+ }
recalcData(t);
}
@@ -1628,32 +1769,21 @@ void restoreTransObjects(TransInfo *t)
void calculateCenter2D(TransInfo *t)
{
BLI_assert(!is_zero_v3(t->aspect));
-
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- float vec[3];
-
- copy_v3_v3(vec, t->center);
- mul_m4_v3(ob->obmat, vec);
- projectFloatView(t, vec, t->center2d);
- }
- else {
- projectFloatView(t, t->center, t->center2d);
- }
+ projectFloatView(t, t->center_global, t->center2d);
}
-void calculateCenterGlobal(
- TransInfo *t, const float center_local[3],
- float r_center_global[3])
+void calculateCenterLocal(
+ TransInfo *t, const float center_global[3])
{
/* setting constraint center */
/* note, init functions may over-ride t->center */
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_v3_m4v3(r_center_global, ob->obmat, center_local);
- }
- else {
- copy_v3_v3(r_center_global, center_local);
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ if (tc->use_local_mat) {
+ mul_v3_m4v3(tc->center_local, tc->imat, center_global);
+ }
+ else {
+ copy_v3_v3(tc->center_local, center_global);
+ }
}
}
@@ -1665,16 +1795,7 @@ void calculateCenterCursor(TransInfo *t, float r_center[3])
copy_v3_v3(r_center, cursor);
/* If edit or pose mode, move cursor in local space */
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- float mat[3][3], imat[3][3];
-
- sub_v3_v3v3(r_center, r_center, ob->obmat[3]);
- copy_m3_m4(mat, ob->obmat);
- invert_m3_m3(imat, mat);
- mul_m3_v3(imat, r_center);
- }
- else if (t->options & CTX_PAINT_CURVE) {
+ if (t->options & CTX_PAINT_CURVE) {
if (ED_view3d_project_float_global(t->ar, cursor, r_center, V3D_PROJ_TEST_NOP) != V3D_PROJ_RET_OK) {
r_center[0] = t->ar->winx / 2.0f;
r_center[1] = t->ar->winy / 2.0f;
@@ -1748,13 +1869,22 @@ void calculateCenterMedian(TransInfo *t, float r_center[3])
{
float partial[3] = {0.0f, 0.0f, 0.0f};
int total = 0;
- int i;
-
- for (i = 0; i < t->total; i++) {
- if (t->data[i].flag & TD_SELECTED) {
- if (!(t->data[i].flag & TD_NOCENTER)) {
- add_v3_v3(partial, t->data[i].center);
- total++;
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ int i;
+ for (i = 0; i < tc->data_len; i++) {
+ if (tc->data[i].flag & TD_SELECTED) {
+ if (!(tc->data[i].flag & TD_NOCENTER)) {
+ if (tc->use_local_mat) {
+ float v[3];
+ mul_v3_m4v3(v, tc->mat, tc->data[i].center);
+ add_v3_v3(partial, v);
+ }
+ else {
+ add_v3_v3(partial, tc->data[i].center);
+ }
+ total++;
+ }
}
}
}
@@ -1769,16 +1899,28 @@ void calculateCenterBound(TransInfo *t, float r_center[3])
float max[3];
float min[3];
int i;
- for (i = 0; i < t->total; i++) {
- if (i) {
- if (t->data[i].flag & TD_SELECTED) {
- if (!(t->data[i].flag & TD_NOCENTER))
- minmax_v3v3_v3(min, max, t->data[i].center);
+ bool is_first = true;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ for (i = 0; i < tc->data_len; i++) {
+ if (is_first == false) {
+ if (tc->data[i].flag & TD_SELECTED) {
+ if (!(tc->data[i].flag & TD_NOCENTER)) {
+ if (tc->use_local_mat) {
+ float v[3];
+ mul_v3_m4v3(v, tc->mat, tc->data[i].center);
+ minmax_v3v3_v3(min, max, v);
+ }
+ else {
+ minmax_v3v3_v3(min, max, tc->data[i].center);
+ }
+ }
+ }
+ }
+ else {
+ copy_v3_v3(max, tc->data[i].center);
+ copy_v3_v3(min, tc->data[i].center);
+ is_first = false;
}
- }
- else {
- copy_v3_v3(max, t->data[i].center);
- copy_v3_v3(min, t->data[i].center);
}
}
mid_v3_v3v3(r_center, min, max);
@@ -1789,26 +1931,30 @@ void calculateCenterBound(TransInfo *t, float r_center[3])
*/
bool calculateCenterActive(TransInfo *t, bool select_only, float r_center[3])
{
+ TransDataContainer *tc = TRANS_DATA_CONTAINER_FIRST_OK(t);
+
bool ok = false;
- if (t->obedit) {
- if (ED_object_editmode_calc_active_center(t->obedit, select_only, r_center)) {
+ if (tc->obedit) {
+ if (ED_object_editmode_calc_active_center(tc->obedit, select_only, r_center)) {
+ mul_m4_v3(tc->obedit->obmat, r_center);
ok = true;
}
}
else if (t->flag & T_POSE) {
- Scene *scene = t->scene;
- Object *ob = OBACT;
+ ViewLayer *view_layer = t->view_layer;
+ Object *ob = OBACT(view_layer);
if (ob) {
bPoseChannel *pchan = BKE_pose_channel_active(ob);
if (pchan && (!select_only || (pchan->bone->flag & BONE_SELECTED))) {
copy_v3_v3(r_center, pchan->pose_head);
+ mul_m4_v3(tc->obedit->obmat, r_center);
ok = true;
}
}
}
else if (t->options & CTX_PAINT_CURVE) {
- Paint *p = BKE_paint_get_active(t->scene);
+ Paint *p = BKE_paint_get_active(t->scene, t->view_layer);
Brush *br = p->brush;
PaintCurve *pc = br->paint_curve;
copy_v3_v3(r_center, pc->points[pc->add_index - 1].bez.vec[1]);
@@ -1817,9 +1963,10 @@ bool calculateCenterActive(TransInfo *t, bool select_only, float r_center[3])
}
else {
/* object mode */
- Scene *scene = t->scene;
- Object *ob = OBACT;
- if (ob && (!select_only || (ob->flag & SELECT))) {
+ ViewLayer *view_layer = t->view_layer;
+ Object *ob = OBACT(view_layer);
+ Base *base = BASACT(view_layer);
+ if (ob && ((!select_only) || ((base->flag & BASE_SELECTED) != 0))) {
copy_v3_v3(r_center, ob->obmat[3]);
ok = true;
}
@@ -1866,14 +2013,13 @@ static void calculateCenter_FromAround(TransInfo *t, int around, float r_center[
void calculateCenter(TransInfo *t)
{
if ((t->flag & T_OVERRIDE_CENTER) == 0) {
- calculateCenter_FromAround(t, t->around, t->center);
+ calculateCenter_FromAround(t, t->around, t->center_global);
}
- calculateCenterGlobal(t, t->center, t->center_global);
+ calculateCenterLocal(t, t->center_global);
/* avoid calculating again */
{
TransCenterData *cd = &t->center_cache[t->around];
- copy_v3_v3(cd->local, t->center);
copy_v3_v3(cd->global, t->center_global);
cd->is_set = true;
}
@@ -1891,16 +2037,15 @@ void calculateCenter(TransInfo *t)
normalize_v3(axis);
/* 6.0 = 6 grid units */
- axis[0] = t->center[0] - 6.0f * axis[0];
- axis[1] = t->center[1] - 6.0f * axis[1];
- axis[2] = t->center[2] - 6.0f * axis[2];
+ axis[0] = t->center_global[0] - 6.0f * axis[0];
+ axis[1] = t->center_global[1] - 6.0f * axis[1];
+ axis[2] = t->center_global[2] - 6.0f * axis[2];
projectFloatView(t, axis, t->center2d);
/* rotate only needs correct 2d center, grab needs ED_view3d_calc_zfac() value */
if (t->mode == TFM_TRANSLATION) {
- copy_v3_v3(t->center, axis);
- copy_v3_v3(t->center_global, t->center);
+ copy_v3_v3(t->center_global, axis);
}
}
}
@@ -1934,8 +2079,7 @@ const TransCenterData *transformCenter_from_type(TransInfo *t, int around)
BLI_assert(around <= V3D_AROUND_ACTIVE);
TransCenterData *cd = &t->center_cache[around];
if (cd->is_set == false) {
- calculateCenter_FromAround(t, around, cd->local);
- calculateCenterGlobal(t, cd->local, cd->global);
+ calculateCenter_FromAround(t, around, cd->global);
cd->is_set = true;
}
return cd;
@@ -1943,7 +2087,6 @@ const TransCenterData *transformCenter_from_type(TransInfo *t, int around)
void calculatePropRatio(TransInfo *t)
{
- TransData *td = t->data;
int i;
float dist;
const bool connected = (t->flag & T_PROP_CONNECTED) != 0;
@@ -1952,75 +2095,79 @@ void calculatePropRatio(TransInfo *t)
if (t->flag & T_PROP_EDIT) {
const char *pet_id = NULL;
- for (i = 0; i < t->total; i++, td++) {
- if (td->flag & TD_SELECTED) {
- td->factor = 1.0f;
- }
- else if (t->flag & T_MIRROR && td->loc[0] * t->mirror < -0.00001f) {
- td->flag |= TD_SKIP;
- td->factor = 0.0f;
- restoreElement(td);
- }
- else if ((connected && (td->flag & TD_NOTCONNECTED || td->dist > t->prop_size)) ||
- (connected == 0 && td->rdist > t->prop_size))
- {
- /*
- * The elements are sorted according to their dist member in the array,
- * that means we can stop when it finds one element outside of the propsize.
- * do not set 'td->flag |= TD_NOACTION', the prop circle is being changed.
- */
-
- td->factor = 0.0f;
- restoreElement(td);
- }
- else {
- /* Use rdist for falloff calculations, it is the real distance */
- td->flag &= ~TD_NOACTION;
-
- if (connected)
- dist = (t->prop_size - td->dist) / t->prop_size;
- else
- dist = (t->prop_size - td->rdist) / t->prop_size;
-
- /*
- * Clamp to positive numbers.
- * Certain corner cases with connectivity and individual centers
- * can give values of rdist larger than propsize.
- */
- if (dist < 0.0f)
- dist = 0.0f;
-
- switch (t->prop_mode) {
- case PROP_SHARP:
- td->factor = dist * dist;
- break;
- case PROP_SMOOTH:
- td->factor = 3.0f * dist * dist - 2.0f * dist * dist * dist;
- break;
- case PROP_ROOT:
- td->factor = sqrtf(dist);
- break;
- case PROP_LIN:
- td->factor = dist;
- break;
- case PROP_CONST:
- td->factor = 1.0f;
- break;
- case PROP_SPHERE:
- td->factor = sqrtf(2 * dist - dist * dist);
- break;
- case PROP_RANDOM:
- td->factor = BLI_frand() * dist;
- break;
- case PROP_INVSQUARE:
- td->factor = dist * (2.0f - dist);
- break;
- default:
- td->factor = 1;
- break;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ if (td->flag & TD_SELECTED) {
+ td->factor = 1.0f;
+ }
+ else if (t->flag & T_MIRROR && td->loc[0] * t->mirror < -0.00001f) {
+ td->flag |= TD_SKIP;
+ td->factor = 0.0f;
+ restoreElement(td);
+ }
+ else if ((connected && (td->flag & TD_NOTCONNECTED || td->dist > t->prop_size)) ||
+ (connected == 0 && td->rdist > t->prop_size))
+ {
+ /*
+ * The elements are sorted according to their dist member in the array,
+ * that means we can stop when it finds one element outside of the propsize.
+ * do not set 'td->flag |= TD_NOACTION', the prop circle is being changed.
+ */
+
+ td->factor = 0.0f;
+ restoreElement(td);
+ }
+ else {
+ /* Use rdist for falloff calculations, it is the real distance */
+ td->flag &= ~TD_NOACTION;
+
+ if (connected)
+ dist = (t->prop_size - td->dist) / t->prop_size;
+ else
+ dist = (t->prop_size - td->rdist) / t->prop_size;
+
+ /*
+ * Clamp to positive numbers.
+ * Certain corner cases with connectivity and individual centers
+ * can give values of rdist larger than propsize.
+ */
+ if (dist < 0.0f)
+ dist = 0.0f;
+
+ switch (t->prop_mode) {
+ case PROP_SHARP:
+ td->factor = dist * dist;
+ break;
+ case PROP_SMOOTH:
+ td->factor = 3.0f * dist * dist - 2.0f * dist * dist * dist;
+ break;
+ case PROP_ROOT:
+ td->factor = sqrtf(dist);
+ break;
+ case PROP_LIN:
+ td->factor = dist;
+ break;
+ case PROP_CONST:
+ td->factor = 1.0f;
+ break;
+ case PROP_SPHERE:
+ td->factor = sqrtf(2 * dist - dist * dist);
+ break;
+ case PROP_RANDOM:
+ td->factor = BLI_frand() * dist;
+ break;
+ case PROP_INVSQUARE:
+ td->factor = dist * (2.0f - dist);
+ break;
+ default:
+ td->factor = 1;
+ break;
+ }
}
}
}
+
switch (t->prop_mode) {
case PROP_SHARP:
pet_id = N_("(Sharp)");
@@ -2055,8 +2202,11 @@ void calculatePropRatio(TransInfo *t)
}
}
else {
- for (i = 0; i < t->total; i++, td++) {
- td->factor = 1.0;
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ td->factor = 1.0;
+ }
}
}
}
diff --git a/source/blender/editors/transform/transform_input.c b/source/blender/editors/transform/transform_input.c
index 5f2e5a99090..799d2acb918 100644
--- a/source/blender/editors/transform/transform_input.c
+++ b/source/blender/editors/transform/transform_input.c
@@ -30,10 +30,13 @@
#include "DNA_screen_types.h"
+#include "BKE_context.h"
+
#include "BLI_math.h"
#include "BLI_utildefines.h"
#include "WM_types.h"
+#include "WM_api.h"
#include "transform.h"
@@ -341,6 +344,29 @@ void initMouseInputMode(TransInfo *t, MouseInput *mi, MouseInputMode mode)
break;
}
+ /* setup for the mouse cursor: either set a custom one,
+ * or hide it if it will be drawn with the helpline */
+ wmWindow *win = CTX_wm_window(t->context);
+ switch (t->helpline) {
+ case HLP_NONE:
+ /* INPUT_VECTOR, INPUT_CUSTOM_RATIO, INPUT_CUSTOM_RATIO_FLIP */
+ if (t->flag & T_MODAL) {
+ WM_cursor_set(win, BC_NSEW_SCROLLCURSOR);
+ }
+ break;
+ case HLP_SPRING:
+ case HLP_ANGLE:
+ case HLP_TRACKBALL:
+ case HLP_HARROW:
+ case HLP_VARROW:
+ if (t->flag & T_MODAL) {
+ WM_cursor_set(win, CURSOR_NONE);
+ }
+ break;
+ default:
+ break;
+ }
+
/* if we've allocated new data, free the old data
* less hassle then checking before every alloc above */
if (mi_data_prev && (mi_data_prev != mi->data)) {
@@ -391,6 +417,12 @@ void applyMouseInput(TransInfo *t, MouseInput *mi, const int mval[2], float outp
mi->apply(t, mi, mval_db, output);
}
+ if (!is_zero_v3(t->values_modal_offset)) {
+ float values_ofs[3];
+ mul_v3_m3v3(values_ofs, t->spacemtx, t->values_modal_offset);
+ add_v3_v3(t->values, values_ofs);
+ }
+
if (mi->post) {
mi->post(t, output);
}
diff --git a/source/blender/editors/transform/transform_manipulator.c b/source/blender/editors/transform/transform_manipulator.c
deleted file mode 100644
index 193a29928ef..00000000000
--- a/source/blender/editors/transform/transform_manipulator.c
+++ /dev/null
@@ -1,1981 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2005 Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/editors/transform/transform_manipulator.c
- * \ingroup edtransform
- */
-
-
-#include <stdlib.h>
-#include <string.h>
-#include <math.h>
-#include <float.h>
-
-#include "DNA_armature_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_gpencil_types.h"
-#include "DNA_lattice_types.h"
-#include "DNA_meta_types.h"
-#include "DNA_screen_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_view3d_types.h"
-
-#include "BLI_listbase.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "RNA_access.h"
-
-#include "BKE_action.h"
-#include "BKE_context.h"
-#include "BKE_curve.h"
-#include "BKE_global.h"
-#include "BKE_particle.h"
-#include "BKE_pointcache.h"
-#include "BKE_editmesh.h"
-#include "BKE_lattice.h"
-#include "BKE_gpencil.h"
-
-#include "BIF_gl.h"
-
-#include "WM_api.h"
-#include "WM_types.h"
-
-#include "ED_armature.h"
-#include "ED_curve.h"
-#include "ED_particle.h"
-#include "ED_view3d.h"
-#include "ED_gpencil.h"
-
-#include "UI_resources.h"
-
-/* local module include */
-#include "transform.h"
-
-#include "GPU_select.h"
-
-/* return codes for select, and drawing flags */
-
-#define MAN_TRANS_X (1 << 0)
-#define MAN_TRANS_Y (1 << 1)
-#define MAN_TRANS_Z (1 << 2)
-#define MAN_TRANS_C (MAN_TRANS_X | MAN_TRANS_Y | MAN_TRANS_Z)
-
-#define MAN_ROT_X (1 << 3)
-#define MAN_ROT_Y (1 << 4)
-#define MAN_ROT_Z (1 << 5)
-#define MAN_ROT_V (1 << 6)
-#define MAN_ROT_T (1 << 7)
-#define MAN_ROT_C (MAN_ROT_X | MAN_ROT_Y | MAN_ROT_Z | MAN_ROT_V | MAN_ROT_T)
-
-#define MAN_SCALE_X (1 << 8)
-#define MAN_SCALE_Y (1 << 9)
-#define MAN_SCALE_Z (1 << 10)
-#define MAN_SCALE_C (MAN_SCALE_X | MAN_SCALE_Y | MAN_SCALE_Z)
-
-/* color codes */
-
-#define MAN_RGB 0
-#define MAN_GHOST 1
-#define MAN_MOVECOL 2
-
-/* threshold for testing view aligned manipulator axis */
-#define TW_AXIS_DOT_MIN 0.02f
-#define TW_AXIS_DOT_MAX 0.1f
-
-struct TransformBounds {
- float center[3]; /* Center for transform widget. */
- float min[3], max[3]; /* Boundbox of selection for transform widget. */
-};
-
-/* transform widget center calc helper for below */
-static void calc_tw_center(struct TransformBounds *tbounds, const float co[3])
-{
- minmax_v3v3_v3(tbounds->min, tbounds->max, co);
- add_v3_v3(tbounds->center, co);
-}
-
-static void protectflag_to_drawflags(short protectflag, short *drawflags)
-{
- if (protectflag & OB_LOCK_LOCX)
- *drawflags &= ~MAN_TRANS_X;
- if (protectflag & OB_LOCK_LOCY)
- *drawflags &= ~MAN_TRANS_Y;
- if (protectflag & OB_LOCK_LOCZ)
- *drawflags &= ~MAN_TRANS_Z;
-
- if (protectflag & OB_LOCK_ROTX)
- *drawflags &= ~MAN_ROT_X;
- if (protectflag & OB_LOCK_ROTY)
- *drawflags &= ~MAN_ROT_Y;
- if (protectflag & OB_LOCK_ROTZ)
- *drawflags &= ~MAN_ROT_Z;
-
- if (protectflag & OB_LOCK_SCALEX)
- *drawflags &= ~MAN_SCALE_X;
- if (protectflag & OB_LOCK_SCALEY)
- *drawflags &= ~MAN_SCALE_Y;
- if (protectflag & OB_LOCK_SCALEZ)
- *drawflags &= ~MAN_SCALE_Z;
-}
-
-/* for pose mode */
-static void protectflag_to_drawflags_pchan(RegionView3D *rv3d, const bPoseChannel *pchan)
-{
- protectflag_to_drawflags(pchan->protectflag, &rv3d->twdrawflag);
-}
-
-/* for editmode*/
-static void protectflag_to_drawflags_ebone(RegionView3D *rv3d, const EditBone *ebo)
-{
- if (ebo->flag & BONE_EDITMODE_LOCKED) {
- protectflag_to_drawflags(OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE, &rv3d->twdrawflag);
- }
-}
-
-/* could move into BLI_math however this is only useful for display/editing purposes */
-static void axis_angle_to_gimbal_axis(float gmat[3][3], const float axis[3], const float angle)
-{
- /* X/Y are arbitrary axies, most importantly Z is the axis of rotation */
-
- float cross_vec[3];
- float quat[4];
-
- /* this is an un-scientific method to get a vector to cross with
- * XYZ intentionally YZX */
- cross_vec[0] = axis[1];
- cross_vec[1] = axis[2];
- cross_vec[2] = axis[0];
-
- /* X-axis */
- cross_v3_v3v3(gmat[0], cross_vec, axis);
- normalize_v3(gmat[0]);
- axis_angle_to_quat(quat, axis, angle);
- mul_qt_v3(quat, gmat[0]);
-
- /* Y-axis */
- axis_angle_to_quat(quat, axis, M_PI_2);
- copy_v3_v3(gmat[1], gmat[0]);
- mul_qt_v3(quat, gmat[1]);
-
- /* Z-axis */
- copy_v3_v3(gmat[2], axis);
-
- normalize_m3(gmat);
-}
-
-
-static bool test_rotmode_euler(short rotmode)
-{
- return (ELEM(rotmode, ROT_MODE_AXISANGLE, ROT_MODE_QUAT)) ? 0 : 1;
-}
-
-bool gimbal_axis(Object *ob, float gmat[3][3])
-{
- if (ob->mode & OB_MODE_POSE) {
- bPoseChannel *pchan = BKE_pose_channel_active(ob);
-
- if (pchan) {
- float mat[3][3], tmat[3][3], obmat[3][3];
- if (test_rotmode_euler(pchan->rotmode)) {
- eulO_to_gimbal_axis(mat, pchan->eul, pchan->rotmode);
- }
- else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
- axis_angle_to_gimbal_axis(mat, pchan->rotAxis, pchan->rotAngle);
- }
- else { /* quat */
- return 0;
- }
-
-
- /* apply bone transformation */
- mul_m3_m3m3(tmat, pchan->bone->bone_mat, mat);
-
- if (pchan->parent) {
- float parent_mat[3][3];
-
- copy_m3_m4(parent_mat, pchan->parent->pose_mat);
- mul_m3_m3m3(mat, parent_mat, tmat);
-
- /* needed if object transformation isn't identity */
- copy_m3_m4(obmat, ob->obmat);
- mul_m3_m3m3(gmat, obmat, mat);
- }
- else {
- /* needed if object transformation isn't identity */
- copy_m3_m4(obmat, ob->obmat);
- mul_m3_m3m3(gmat, obmat, tmat);
- }
-
- normalize_m3(gmat);
- return 1;
- }
- }
- else {
- if (test_rotmode_euler(ob->rotmode)) {
- eulO_to_gimbal_axis(gmat, ob->rot, ob->rotmode);
- }
- else if (ob->rotmode == ROT_MODE_AXISANGLE) {
- axis_angle_to_gimbal_axis(gmat, ob->rotAxis, ob->rotAngle);
- }
- else { /* quat */
- return 0;
- }
-
- if (ob->parent) {
- float parent_mat[3][3];
- copy_m3_m4(parent_mat, ob->parent->obmat);
- normalize_m3(parent_mat);
- mul_m3_m3m3(gmat, parent_mat, gmat);
- }
- return 1;
- }
-
- return 0;
-}
-
-
-/* centroid, boundbox, of selection */
-/* returns total items selected */
-static int calc_manipulator_stats(const bContext *C, struct TransformBounds *tbounds)
-{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
- Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- View3D *v3d = sa->spacedata.first;
- RegionView3D *rv3d = ar->regiondata;
- Base *base;
- Object *ob = OBACT;
- bGPdata *gpd = CTX_data_gpencil_data(C);
- const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE));
- int a, totsel = 0;
-
- /* transform widget matrix */
- unit_m4(rv3d->twmat);
-
- rv3d->twdrawflag = 0xFFFF;
-
- /* transform widget centroid/center */
- INIT_MINMAX(tbounds->min, tbounds->max);
- zero_v3(tbounds->center);
-
- if (is_gp_edit) {
- float diff_mat[4][4];
- float fpt[3];
-
- for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
- /* only editable and visible layers are considered */
- if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
-
- /* calculate difference matrix if parent object */
- if (gpl->parent != NULL) {
- ED_gpencil_parent_location(gpl, diff_mat);
- }
-
- for (bGPDstroke *gps = gpl->actframe->strokes.first; gps; gps = gps->next) {
- /* skip strokes that are invalid for current view */
- if (ED_gpencil_stroke_can_use(C, gps) == false) {
- continue;
- }
-
- /* we're only interested in selected points here... */
- if (gps->flag & GP_STROKE_SELECT) {
- bGPDspoint *pt;
- int i;
-
- /* Change selection status of all points, then make the stroke match */
- for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
- if (pt->flag & GP_SPOINT_SELECT) {
- if (gpl->parent == NULL) {
- calc_tw_center(tbounds, &pt->x);
- totsel++;
- }
- else {
- mul_v3_m4v3(fpt, diff_mat, &pt->x);
- calc_tw_center(tbounds, fpt);
- totsel++;
- }
- }
- }
- }
- }
- }
- }
-
-
- /* selection center */
- if (totsel) {
- mul_v3_fl(tbounds->center, 1.0f / (float)totsel);
- }
- }
- else if (obedit) {
- ob = obedit;
- if ((ob->lay & v3d->lay) == 0) return 0;
-
- if (obedit->type == OB_MESH) {
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BMEditSelection ese;
- float vec[3] = {0, 0, 0};
-
- /* USE LAST SELECTE WITH ACTIVE */
- if ((v3d->around == V3D_AROUND_ACTIVE) && BM_select_history_active_get(em->bm, &ese)) {
- BM_editselection_center(&ese, vec);
- calc_tw_center(tbounds, vec);
- totsel = 1;
- }
- else {
- BMesh *bm = em->bm;
- BMVert *eve;
-
- BMIter iter;
-
- BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
- if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
- if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
- totsel++;
- calc_tw_center(tbounds, eve->co);
- }
- }
- }
- }
- } /* end editmesh */
- else if (obedit->type == OB_ARMATURE) {
- bArmature *arm = obedit->data;
- EditBone *ebo;
-
- if ((v3d->around == V3D_AROUND_ACTIVE) && (ebo = arm->act_edbone)) {
- /* doesn't check selection or visibility intentionally */
- if (ebo->flag & BONE_TIPSEL) {
- calc_tw_center(tbounds, ebo->tail);
- totsel++;
- }
- if ((ebo->flag & BONE_ROOTSEL) ||
- ((ebo->flag & BONE_TIPSEL) == false)) /* ensure we get at least one point */
- {
- calc_tw_center(tbounds, ebo->head);
- totsel++;
- }
- protectflag_to_drawflags_ebone(rv3d, ebo);
- }
- else {
- for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
- if (EBONE_VISIBLE(arm, ebo)) {
- if (ebo->flag & BONE_TIPSEL) {
- calc_tw_center(tbounds, ebo->tail);
- totsel++;
- }
- if ((ebo->flag & BONE_ROOTSEL) &&
- /* don't include same point multiple times */
- ((ebo->flag & BONE_CONNECTED) &&
- (ebo->parent != NULL) &&
- (ebo->parent->flag & BONE_TIPSEL) &&
- EBONE_VISIBLE(arm, ebo->parent)) == 0)
- {
- calc_tw_center(tbounds, ebo->head);
- totsel++;
- }
- if (ebo->flag & BONE_SELECTED) {
- protectflag_to_drawflags_ebone(rv3d, ebo);
- }
- }
- }
- }
- }
- else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
- Curve *cu = obedit->data;
- float center[3];
-
- if (v3d->around == V3D_AROUND_ACTIVE && ED_curve_active_center(cu, center)) {
- calc_tw_center(tbounds, center);
- totsel++;
- }
- else {
- Nurb *nu;
- BezTriple *bezt;
- BPoint *bp;
- ListBase *nurbs = BKE_curve_editNurbs_get(cu);
-
- nu = nurbs->first;
- while (nu) {
- if (nu->type == CU_BEZIER) {
- bezt = nu->bezt;
- a = nu->pntsu;
- while (a--) {
- /* exceptions
- * if handles are hidden then only check the center points.
- * If the center knot is selected then only use this as the center point.
- */
- if (cu->drawflag & CU_HIDE_HANDLES) {
- if (bezt->f2 & SELECT) {
- calc_tw_center(tbounds, bezt->vec[1]);
- totsel++;
- }
- }
- else if (bezt->f2 & SELECT) {
- calc_tw_center(tbounds, bezt->vec[1]);
- totsel++;
- }
- else {
- if (bezt->f1 & SELECT) {
- calc_tw_center(
- tbounds,
- bezt->vec[(v3d->around == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 0]);
- totsel++;
- }
- if (bezt->f3 & SELECT) {
- calc_tw_center(
- tbounds,
- bezt->vec[(v3d->around == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 2]);
- totsel++;
- }
- }
- bezt++;
- }
- }
- else {
- bp = nu->bp;
- a = nu->pntsu * nu->pntsv;
- while (a--) {
- if (bp->f1 & SELECT) {
- calc_tw_center(tbounds, bp->vec);
- totsel++;
- }
- bp++;
- }
- }
- nu = nu->next;
- }
- }
- }
- else if (obedit->type == OB_MBALL) {
- MetaBall *mb = (MetaBall *)obedit->data;
- MetaElem *ml;
-
- if ((v3d->around == V3D_AROUND_ACTIVE) && (ml = mb->lastelem)) {
- calc_tw_center(tbounds, &ml->x);
- totsel++;
- }
- else {
- for (ml = mb->editelems->first; ml; ml = ml->next) {
- if (ml->flag & SELECT) {
- calc_tw_center(tbounds, &ml->x);
- totsel++;
- }
- }
- }
- }
- else if (obedit->type == OB_LATTICE) {
- Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
- BPoint *bp;
-
- if ((v3d->around == V3D_AROUND_ACTIVE) && (bp = BKE_lattice_active_point_get(lt))) {
- calc_tw_center(tbounds, bp->vec);
- totsel++;
- }
- else {
- bp = lt->def;
- a = lt->pntsu * lt->pntsv * lt->pntsw;
- while (a--) {
- if (bp->f1 & SELECT) {
- calc_tw_center(tbounds, bp->vec);
- totsel++;
- }
- bp++;
- }
- }
- }
-
- /* selection center */
- if (totsel) {
- mul_v3_fl(tbounds->center, 1.0f / (float)totsel);
- mul_m4_v3(obedit->obmat, tbounds->center);
- mul_m4_v3(obedit->obmat, tbounds->min);
- mul_m4_v3(obedit->obmat, tbounds->max);
- }
- }
- else if (ob && (ob->mode & OB_MODE_POSE)) {
- bPoseChannel *pchan;
- int mode = TFM_ROTATION; // mislead counting bones... bah. We don't know the manipulator mode, could be mixed
- bool ok = false;
-
- if ((ob->lay & v3d->lay) == 0) return 0;
-
- if ((v3d->around == V3D_AROUND_ACTIVE) && (pchan = BKE_pose_channel_active(ob))) {
- /* doesn't check selection or visibility intentionally */
- Bone *bone = pchan->bone;
- if (bone) {
- calc_tw_center(tbounds, pchan->pose_head);
- protectflag_to_drawflags_pchan(rv3d, pchan);
- totsel = 1;
- ok = true;
- }
- }
- else {
- totsel = count_set_pose_transflags(&mode, 0, ob);
-
- if (totsel) {
- /* use channels to get stats */
- for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
- Bone *bone = pchan->bone;
- if (bone && (bone->flag & BONE_TRANSFORM)) {
- calc_tw_center(tbounds, pchan->pose_head);
- protectflag_to_drawflags_pchan(rv3d, pchan);
- }
- }
- ok = true;
- }
- }
-
- if (ok) {
- mul_v3_fl(tbounds->center, 1.0f / (float)totsel);
- mul_m4_v3(ob->obmat, tbounds->center);
- mul_m4_v3(ob->obmat, tbounds->min);
- mul_m4_v3(ob->obmat, tbounds->max);
- }
- }
- else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) {
- /* pass */
- }
- else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) {
- PTCacheEdit *edit = PE_get_current(scene, ob);
- PTCacheEditPoint *point;
- PTCacheEditKey *ek;
- int k;
-
- if (edit) {
- point = edit->points;
- for (a = 0; a < edit->totpoint; a++, point++) {
- if (point->flag & PEP_HIDE) continue;
-
- for (k = 0, ek = point->keys; k < point->totkey; k++, ek++) {
- if (ek->flag & PEK_SELECT) {
- calc_tw_center(tbounds, (ek->flag & PEK_USE_WCO) ? ek->world_co : ek->co);
- totsel++;
- }
- }
- }
-
- /* selection center */
- if (totsel)
- mul_v3_fl(tbounds->center, 1.0f / (float)totsel);
- }
- }
- else {
-
- /* we need the one selected object, if its not active */
- ob = OBACT;
- if (ob && !(ob->flag & SELECT)) ob = NULL;
-
- for (base = scene->base.first; base; base = base->next) {
- if (TESTBASELIB(v3d, base)) {
- if (ob == NULL)
- ob = base->object;
- calc_tw_center(tbounds, base->object->obmat[3]);
- protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag);
- totsel++;
- }
- }
-
- /* selection center */
- if (totsel) {
- mul_v3_fl(tbounds->center, 1.0f / (float)totsel);
- }
- }
-
- /* global, local or normal orientation? */
- if (ob && totsel && !is_gp_edit) {
-
- switch (v3d->twmode) {
-
- case V3D_MANIP_GLOBAL:
- {
- break; /* nothing to do */
- }
- case V3D_MANIP_GIMBAL:
- {
- float mat[3][3];
- if (gimbal_axis(ob, mat)) {
- copy_m4_m3(rv3d->twmat, mat);
- break;
- }
- /* if not gimbal, fall through to normal */
- ATTR_FALLTHROUGH;
- }
- case V3D_MANIP_NORMAL:
- {
- if (obedit || ob->mode & OB_MODE_POSE) {
- float mat[3][3];
- ED_getTransformOrientationMatrix(C, mat, v3d->around);
- copy_m4_m3(rv3d->twmat, mat);
- break;
- }
- /* no break we define 'normal' as 'local' in Object mode */
- ATTR_FALLTHROUGH;
- }
- case V3D_MANIP_LOCAL:
- {
- if (ob->mode & OB_MODE_POSE) {
- /* each bone moves on its own local axis, but to avoid confusion,
- * use the active pones axis for display [#33575], this works as expected on a single bone
- * and users who select many bones will understand whats going on and what local means
- * when they start transforming */
- float mat[3][3];
- ED_getTransformOrientationMatrix(C, mat, v3d->around);
- copy_m4_m3(rv3d->twmat, mat);
- break;
- }
- copy_m4_m4(rv3d->twmat, ob->obmat);
- normalize_m4(rv3d->twmat);
- break;
- }
- case V3D_MANIP_VIEW:
- {
- float mat[3][3];
- copy_m3_m4(mat, rv3d->viewinv);
- normalize_m3(mat);
- copy_m4_m3(rv3d->twmat, mat);
- break;
- }
- default: /* V3D_MANIP_CUSTOM */
- {
- float mat[3][3];
- if (applyTransformOrientation(C, mat, NULL, v3d->twmode - V3D_MANIP_CUSTOM)) {
- copy_m4_m3(rv3d->twmat, mat);
- }
- break;
- }
- }
-
- }
-
- return totsel;
-}
-
-/* don't draw axis perpendicular to the view */
-static void test_manipulator_axis(const bContext *C)
-{
- RegionView3D *rv3d = CTX_wm_region_view3d(C);
- float view_vec[3], axis_vec[3];
- float idot;
- int i;
-
- const int twdrawflag_axis[3] = {
- (MAN_TRANS_X | MAN_SCALE_X),
- (MAN_TRANS_Y | MAN_SCALE_Y),
- (MAN_TRANS_Z | MAN_SCALE_Z)};
-
- ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], view_vec);
-
- for (i = 0; i < 3; i++) {
- normalize_v3_v3(axis_vec, rv3d->twmat[i]);
- rv3d->tw_idot[i] = idot = 1.0f - fabsf(dot_v3v3(view_vec, axis_vec));
- if (idot < TW_AXIS_DOT_MIN) {
- rv3d->twdrawflag &= ~twdrawflag_axis[i];
- }
- }
-}
-
-
-/* ******************** DRAWING STUFFIES *********** */
-
-static float screen_aligned(RegionView3D *rv3d, float mat[4][4])
-{
- glTranslate3fv(mat[3]);
-
- /* sets view screen aligned */
- glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
-
- return len_v3(mat[0]); /* draw scale */
-}
-
-
-/**
- * \param radring: Radius of doughnut rings.
- * \param radhole: Radius hole.
- * \param start: Starting segment (based on \a nrings).
- * \param end: End segment.
- * \param nsides: Number of points in ring.
- * \param nrings: Number of rings.
- */
-static void partial_doughnut(float radring, float radhole, int start, int end, int nsides, int nrings)
-{
- float theta, phi, theta1;
- float cos_theta, sin_theta;
- float cos_theta1, sin_theta1;
- float ring_delta, side_delta;
- int i, j, do_caps = true;
-
- if (start == 0 && end == nrings) do_caps = false;
-
- ring_delta = 2.0f * (float)M_PI / (float)nrings;
- side_delta = 2.0f * (float)M_PI / (float)nsides;
-
- theta = (float)M_PI + 0.5f * ring_delta;
- cos_theta = cosf(theta);
- sin_theta = sinf(theta);
-
- for (i = nrings - 1; i >= 0; i--) {
- theta1 = theta + ring_delta;
- cos_theta1 = cosf(theta1);
- sin_theta1 = sinf(theta1);
-
- if (do_caps && i == start) { // cap
- glBegin(GL_POLYGON);
- phi = 0.0;
- for (j = nsides; j >= 0; j--) {
- float cos_phi, sin_phi, dist;
-
- phi += side_delta;
- cos_phi = cosf(phi);
- sin_phi = sinf(phi);
- dist = radhole + radring * cos_phi;
-
- glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
- }
- glEnd();
- }
- if (i >= start && i <= end) {
- glBegin(GL_QUAD_STRIP);
- phi = 0.0;
- for (j = nsides; j >= 0; j--) {
- float cos_phi, sin_phi, dist;
-
- phi += side_delta;
- cos_phi = cosf(phi);
- sin_phi = sinf(phi);
- dist = radhole + radring * cos_phi;
-
- glVertex3f(cos_theta1 * dist, -sin_theta1 * dist, radring * sin_phi);
- glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi);
- }
- glEnd();
- }
-
- if (do_caps && i == end) { // cap
- glBegin(GL_POLYGON);
- phi = 0.0;
- for (j = nsides; j >= 0; j--) {
- float cos_phi, sin_phi, dist;
-
- phi -= side_delta;
- cos_phi = cosf(phi);
- sin_phi = sinf(phi);
- dist = radhole + radring * cos_phi;
-
- glVertex3f(cos_theta * dist, -sin_theta * dist, radring * sin_phi);
- }
- glEnd();
- }
-
-
- theta = theta1;
- cos_theta = cos_theta1;
- sin_theta = sin_theta1;
- }
-}
-
-static char axisBlendAngle(float idot)
-{
- if (idot > TW_AXIS_DOT_MAX) {
- return 255;
- }
- else if (idot < TW_AXIS_DOT_MIN) {
- return 0;
- }
- else {
- return (char)(255.0f * (idot - TW_AXIS_DOT_MIN) / (TW_AXIS_DOT_MAX - TW_AXIS_DOT_MIN));
- }
-}
-
-/* three colors can be set:
- * gray for ghosting
- * moving: in transform theme color
- * else the red/green/blue
- */
-static void manipulator_setcolor(View3D *v3d, char axis, int colcode, unsigned char alpha)
-{
- unsigned char col[4] = {0};
- col[3] = alpha;
-
- if (colcode == MAN_GHOST) {
- col[3] = 70;
- }
- else if (colcode == MAN_MOVECOL) {
- UI_GetThemeColor3ubv(TH_TRANSFORM, col);
- }
- else {
- switch (axis) {
- case 'C':
- UI_GetThemeColor3ubv(TH_TRANSFORM, col);
- if (v3d->twmode == V3D_MANIP_LOCAL) {
- col[0] = col[0] > 200 ? 255 : col[0] + 55;
- col[1] = col[1] > 200 ? 255 : col[1] + 55;
- col[2] = col[2] > 200 ? 255 : col[2] + 55;
- }
- else if (v3d->twmode == V3D_MANIP_NORMAL) {
- col[0] = col[0] < 55 ? 0 : col[0] - 55;
- col[1] = col[1] < 55 ? 0 : col[1] - 55;
- col[2] = col[2] < 55 ? 0 : col[2] - 55;
- }
- break;
- case 'X':
- UI_GetThemeColor3ubv(TH_AXIS_X, col);
- break;
- case 'Y':
- UI_GetThemeColor3ubv(TH_AXIS_Y, col);
- break;
- case 'Z':
- UI_GetThemeColor3ubv(TH_AXIS_Z, col);
- break;
- default:
- BLI_assert(0);
- break;
- }
- }
-
- glColor4ubv(col);
-}
-
-static void manipulator_axis_order(RegionView3D *rv3d, int r_axis_order[3])
-{
- float axis_values[3];
- float vec[3];
-
- ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], vec);
-
- axis_values[0] = -dot_v3v3(rv3d->twmat[0], vec);
- axis_values[1] = -dot_v3v3(rv3d->twmat[1], vec);
- axis_values[2] = -dot_v3v3(rv3d->twmat[2], vec);
-
- axis_sort_v3(axis_values, r_axis_order);
-}
-
-/* viewmatrix should have been set OK, also no shademode! */
-static void draw_manipulator_axes_single(View3D *v3d, RegionView3D *rv3d, int colcode,
- int flagx, int flagy, int flagz, int axis,
- const bool is_picksel)
-{
- switch (axis) {
- case 0:
- /* axes */
- if (flagx) {
- if (is_picksel) {
- if (flagx & MAN_SCALE_X) GPU_select_load_id(MAN_SCALE_X);
- else if (flagx & MAN_TRANS_X) GPU_select_load_id(MAN_TRANS_X);
- }
- else {
- manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->tw_idot[0]));
- }
- glBegin(GL_LINES);
- glVertex3f(0.2f, 0.0f, 0.0f);
- glVertex3f(1.0f, 0.0f, 0.0f);
- glEnd();
- }
- break;
- case 1:
- if (flagy) {
- if (is_picksel) {
- if (flagy & MAN_SCALE_Y) GPU_select_load_id(MAN_SCALE_Y);
- else if (flagy & MAN_TRANS_Y) GPU_select_load_id(MAN_TRANS_Y);
- }
- else {
- manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->tw_idot[1]));
- }
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.2f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glEnd();
- }
- break;
- case 2:
- if (flagz) {
- if (is_picksel) {
- if (flagz & MAN_SCALE_Z) GPU_select_load_id(MAN_SCALE_Z);
- else if (flagz & MAN_TRANS_Z) GPU_select_load_id(MAN_TRANS_Z);
- }
- else {
- manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->tw_idot[2]));
- }
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.2f);
- glVertex3f(0.0f, 0.0f, 1.0f);
- glEnd();
- }
- break;
- }
-}
-static void draw_manipulator_axes(View3D *v3d, RegionView3D *rv3d, int colcode,
- int flagx, int flagy, int flagz,
- const int axis_order[3], const bool is_picksel)
-{
- int i;
- for (i = 0; i < 3; i++) {
- draw_manipulator_axes_single(v3d, rv3d, colcode, flagx, flagy, flagz, axis_order[i], is_picksel);
- }
-}
-
-static void preOrthoFront(const bool ortho, float twmat[4][4], int axis)
-{
- if (ortho == false) {
- float omat[4][4];
- copy_m4_m4(omat, twmat);
- orthogonalize_m4(omat, axis);
- glPushMatrix();
- glMultMatrixf(omat);
- glFrontFace(is_negative_m4(omat) ? GL_CW : GL_CCW);
- }
-}
-
-static void postOrtho(const bool ortho)
-{
- if (ortho == false) {
- glPopMatrix();
- }
-}
-
-BLI_INLINE bool manipulator_rotate_is_visible(const int drawflags)
-{
- return (drawflags & (MAN_ROT_X | MAN_ROT_Y | MAN_ROT_Z));
-}
-
-static void draw_manipulator_rotate(
- View3D *v3d, RegionView3D *rv3d, const int drawflags, const int combo,
- const bool is_moving, const bool is_picksel)
-{
- double plane[4];
- float matt[4][4];
- float size, unitmat[4][4];
- float cywid = 0.33f * 0.01f * (float)U.tw_handlesize;
- float cusize = cywid * 0.65f;
- int arcs = (G.debug_value != 2);
- const int colcode = (is_moving) ? MAN_MOVECOL : MAN_RGB;
- bool ortho;
-
- /* skip drawing if all axes are locked */
- if (manipulator_rotate_is_visible(drawflags) == false) return;
-
- /* Init stuff */
- glDisable(GL_DEPTH_TEST);
- unit_m4(unitmat);
-
- /* prepare for screen aligned draw */
- size = len_v3(rv3d->twmat[0]);
- glPushMatrix();
- glTranslate3fv(rv3d->twmat[3]);
-
- if (arcs) {
- /* clipplane makes nice handles, calc here because of multmatrix but with translate! */
- copy_v3db_v3fl(plane, rv3d->viewinv[2]);
- plane[3] = -0.02f * size; // clip just a bit more
- glClipPlane(GL_CLIP_PLANE0, plane);
- }
- /* sets view screen aligned */
- glRotatef(-360.0f * saacos(rv3d->viewquat[0]) / (float)M_PI, rv3d->viewquat[1], rv3d->viewquat[2], rv3d->viewquat[3]);
-
- /* Screen aligned help circle */
- if (arcs) {
- if (is_picksel == false) {
- UI_ThemeColorShade(TH_BACK, -30);
- drawcircball(GL_LINE_LOOP, unitmat[3], size, unitmat);
- }
- }
-
- /* Screen aligned trackball rot circle */
- if (drawflags & MAN_ROT_T) {
- if (is_picksel) GPU_select_load_id(MAN_ROT_T);
- else UI_ThemeColor(TH_TRANSFORM);
-
- drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
- }
-
- /* Screen aligned view rot circle */
- if (drawflags & MAN_ROT_V) {
- if (is_picksel) GPU_select_load_id(MAN_ROT_V);
- else UI_ThemeColor(TH_TRANSFORM);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f * size, unitmat);
-
- if (is_moving) {
- float vec[3];
- vec[0] = 0; // XXX (float)(t->mouse.imval[0] - t->center2d[0]);
- vec[1] = 0; // XXX (float)(t->mouse.imval[1] - t->center2d[1]);
- vec[2] = 0.0f;
- normalize_v3_length(vec, 1.2f * size);
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.0f);
- glVertex3fv(vec);
- glEnd();
- }
- }
- glPopMatrix();
-
-
- ortho = is_orthogonal_m4(rv3d->twmat);
-
- /* apply the transform delta */
- if (is_moving) {
- copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
- // XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
- if (ortho) {
- glMultMatrixf(matt);
- glFrontFace(is_negative_m4(matt) ? GL_CW : GL_CCW);
- }
- }
- else {
- if (ortho) {
- glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
- glMultMatrixf(rv3d->twmat);
- }
- }
-
- /* axes */
- if (arcs == 0) {
- if (!is_picksel) {
- if ((combo & V3D_MANIP_SCALE) == 0) {
- /* axis */
- if ((drawflags & MAN_ROT_X) || (is_moving && (drawflags & MAN_ROT_Z))) {
- preOrthoFront(ortho, rv3d->twmat, 2);
- manipulator_setcolor(v3d, 'X', colcode, 255);
- glBegin(GL_LINES);
- glVertex3f(0.2f, 0.0f, 0.0f);
- glVertex3f(1.0f, 0.0f, 0.0f);
- glEnd();
- postOrtho(ortho);
- }
- if ((drawflags & MAN_ROT_Y) || (is_moving && (drawflags & MAN_ROT_X))) {
- preOrthoFront(ortho, rv3d->twmat, 0);
- manipulator_setcolor(v3d, 'Y', colcode, 255);
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.2f, 0.0f);
- glVertex3f(0.0f, 1.0f, 0.0f);
- glEnd();
- postOrtho(ortho);
- }
- if ((drawflags & MAN_ROT_Z) || (is_moving && (drawflags & MAN_ROT_Y))) {
- preOrthoFront(ortho, rv3d->twmat, 1);
- manipulator_setcolor(v3d, 'Z', colcode, 255);
- glBegin(GL_LINES);
- glVertex3f(0.0f, 0.0f, 0.2f);
- glVertex3f(0.0f, 0.0f, 1.0f);
- glEnd();
- postOrtho(ortho);
- }
- }
- }
- }
-
- if (arcs == 0 && is_moving) {
-
- /* Z circle */
- if (drawflags & MAN_ROT_Z) {
- preOrthoFront(ortho, matt, 2);
- if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
- else manipulator_setcolor(v3d, 'Z', colcode, 255);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
- postOrtho(ortho);
- }
- /* X circle */
- if (drawflags & MAN_ROT_X) {
- preOrthoFront(ortho, matt, 0);
- if (is_picksel) GPU_select_load_id(MAN_ROT_X);
- else manipulator_setcolor(v3d, 'X', colcode, 255);
- glRotatef(90.0, 0.0, 1.0, 0.0);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
- glRotatef(-90.0, 0.0, 1.0, 0.0);
- postOrtho(ortho);
- }
- /* Y circle */
- if (drawflags & MAN_ROT_Y) {
- preOrthoFront(ortho, matt, 1);
- if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
- else manipulator_setcolor(v3d, 'Y', colcode, 255);
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.0, unitmat);
- glRotatef(90.0, 1.0, 0.0, 0.0);
- postOrtho(ortho);
- }
- }
- // donut arcs
- if (arcs) {
- glEnable(GL_CLIP_PLANE0);
-
- /* Z circle */
- if (drawflags & MAN_ROT_Z) {
- preOrthoFront(ortho, rv3d->twmat, 2);
- if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
- else manipulator_setcolor(v3d, 'Z', colcode, 255);
- partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
- postOrtho(ortho);
- }
- /* X circle */
- if (drawflags & MAN_ROT_X) {
- preOrthoFront(ortho, rv3d->twmat, 0);
- if (is_picksel) GPU_select_load_id(MAN_ROT_X);
- else manipulator_setcolor(v3d, 'X', colcode, 255);
- glRotatef(90.0, 0.0, 1.0, 0.0);
- partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
- glRotatef(-90.0, 0.0, 1.0, 0.0);
- postOrtho(ortho);
- }
- /* Y circle */
- if (drawflags & MAN_ROT_Y) {
- preOrthoFront(ortho, rv3d->twmat, 1);
- if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
- else manipulator_setcolor(v3d, 'Y', colcode, 255);
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- partial_doughnut(cusize / 4.0f, 1.0f, 0, 48, 8, 48);
- glRotatef(90.0, 1.0, 0.0, 0.0);
- postOrtho(ortho);
- }
-
- glDisable(GL_CLIP_PLANE0);
- }
-
- if (arcs == 0) {
-
- /* Z handle on X axis */
- if (drawflags & MAN_ROT_Z) {
- preOrthoFront(ortho, rv3d->twmat, 2);
- glPushMatrix();
- if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
- else manipulator_setcolor(v3d, 'Z', colcode, 255);
-
- partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
-
- glPopMatrix();
- postOrtho(ortho);
- }
-
- /* Y handle on X axis */
- if (drawflags & MAN_ROT_Y) {
- preOrthoFront(ortho, rv3d->twmat, 1);
- glPushMatrix();
- if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
- else manipulator_setcolor(v3d, 'Y', colcode, 255);
-
- glRotatef(90.0, 1.0, 0.0, 0.0);
- glRotatef(90.0, 0.0, 0.0, 1.0);
- partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
-
- glPopMatrix();
- postOrtho(ortho);
- }
-
- /* X handle on Z axis */
- if (drawflags & MAN_ROT_X) {
- preOrthoFront(ortho, rv3d->twmat, 0);
- glPushMatrix();
- if (is_picksel) GPU_select_load_id(MAN_ROT_X);
- else manipulator_setcolor(v3d, 'X', colcode, 255);
-
- glRotatef(-90.0, 0.0, 1.0, 0.0);
- glRotatef(90.0, 0.0, 0.0, 1.0);
- partial_doughnut(0.7f * cusize, 1.0f, 31, 33, 8, 64);
-
- glPopMatrix();
- postOrtho(ortho);
- }
-
- }
-
- /* restore */
- glLoadMatrixf(rv3d->viewmat);
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
-
-}
-
-static void drawsolidcube(float size)
-{
- const float cube[8][3] = {
- {-1.0, -1.0, -1.0},
- {-1.0, -1.0, 1.0},
- {-1.0, 1.0, 1.0},
- {-1.0, 1.0, -1.0},
- { 1.0, -1.0, -1.0},
- { 1.0, -1.0, 1.0},
- { 1.0, 1.0, 1.0},
- { 1.0, 1.0, -1.0},
- };
- float n[3] = {0.0f};
-
- glPushMatrix();
- glScalef(size, size, size);
-
- glBegin(GL_QUADS);
- n[0] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[0]); glVertex3fv(cube[1]); glVertex3fv(cube[2]); glVertex3fv(cube[3]);
- n[0] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[1] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[0]); glVertex3fv(cube[4]); glVertex3fv(cube[5]); glVertex3fv(cube[1]);
- n[1] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[0] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[4]); glVertex3fv(cube[7]); glVertex3fv(cube[6]); glVertex3fv(cube[5]);
- n[0] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[1] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[7]); glVertex3fv(cube[3]); glVertex3fv(cube[2]); glVertex3fv(cube[6]);
- n[1] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[2] = 1.0;
- glNormal3fv(n);
- glVertex3fv(cube[1]); glVertex3fv(cube[5]); glVertex3fv(cube[6]); glVertex3fv(cube[2]);
- n[2] = 0;
- glEnd();
-
- glBegin(GL_QUADS);
- n[2] = -1.0;
- glNormal3fv(n);
- glVertex3fv(cube[7]); glVertex3fv(cube[4]); glVertex3fv(cube[0]); glVertex3fv(cube[3]);
- glEnd();
-
- glPopMatrix();
-}
-
-
-static void draw_manipulator_scale(
- View3D *v3d, RegionView3D *rv3d, const int drawflags, const int combo, const int colcode,
- const bool is_moving, const bool is_picksel)
-{
- float cywid = 0.25f * 0.01f * (float)U.tw_handlesize;
- float cusize = cywid * 0.75f, dz;
- int axis_order[3] = {2, 0, 1};
- int i;
-
- /* when called while moving in mixed mode, do not draw when... */
- if ((drawflags & MAN_SCALE_C) == 0) return;
-
- manipulator_axis_order(rv3d, axis_order);
-
- glDisable(GL_DEPTH_TEST);
-
- /* not in combo mode */
- if ((combo & (V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE)) == 0) {
- float size, unitmat[4][4];
- int shift = 0; // XXX
-
- /* center circle, do not add to selection when shift is pressed (planar constraint) */
- if (is_picksel && shift == 0) GPU_select_load_id(MAN_SCALE_C);
- else manipulator_setcolor(v3d, 'C', colcode, 255);
-
- glPushMatrix();
- size = screen_aligned(rv3d, rv3d->twmat);
- unit_m4(unitmat);
- drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
- glPopMatrix();
-
- dz = 1.0;
- }
- else {
- dz = 1.0f - 4.0f * cusize;
- }
-
- if (is_moving) {
- float matt[4][4];
-
- copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
- // XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
- glMultMatrixf(matt);
- glFrontFace(is_negative_m4(matt) ? GL_CW : GL_CCW);
- }
- else {
- glMultMatrixf(rv3d->twmat);
- glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
- }
-
- /* axis */
-
- /* in combo mode, this is always drawn as first type */
- draw_manipulator_axes(v3d, rv3d, colcode,
- drawflags & MAN_SCALE_X, drawflags & MAN_SCALE_Y, drawflags & MAN_SCALE_Z,
- axis_order, is_picksel);
-
-
- for (i = 0; i < 3; i++) {
- switch (axis_order[i]) {
- case 0: /* X cube */
- if (drawflags & MAN_SCALE_X) {
- glTranslatef(dz, 0.0, 0.0);
- if (is_picksel) GPU_select_load_id(MAN_SCALE_X);
- else manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->tw_idot[0]));
- drawsolidcube(cusize);
- glTranslatef(-dz, 0.0, 0.0);
- }
- break;
- case 1: /* Y cube */
- if (drawflags & MAN_SCALE_Y) {
- glTranslatef(0.0, dz, 0.0);
- if (is_picksel) GPU_select_load_id(MAN_SCALE_Y);
- else manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->tw_idot[1]));
- drawsolidcube(cusize);
- glTranslatef(0.0, -dz, 0.0);
- }
- break;
- case 2: /* Z cube */
- if (drawflags & MAN_SCALE_Z) {
- glTranslatef(0.0, 0.0, dz);
- if (is_picksel) GPU_select_load_id(MAN_SCALE_Z);
- else manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->tw_idot[2]));
- drawsolidcube(cusize);
- glTranslatef(0.0, 0.0, -dz);
- }
- break;
- }
- }
-
-#if 0 // XXX
- /* if shiftkey, center point as last, for selectbuffer order */
- if (is_picksel) {
- int shift = 0; // XXX
-
- if (shift) {
- glTranslatef(0.0, -dz, 0.0);
- GPU_select_load_id(MAN_SCALE_C);
- /* TODO: set glPointSize before drawing center point */
- glBegin(GL_POINTS);
- glVertex3f(0.0, 0.0, 0.0);
- glEnd();
- }
- }
-#endif
-
- /* restore */
- glLoadMatrixf(rv3d->viewmat);
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
- glFrontFace(GL_CCW);
-}
-
-
-static void draw_cone(GLUquadricObj *qobj, float len, float width)
-{
- glTranslatef(0.0, 0.0, -0.5f * len);
- gluCylinder(qobj, width, 0.0, len, 8, 1);
- gluQuadricOrientation(qobj, GLU_INSIDE);
- gluDisk(qobj, 0.0, width, 8, 1);
- gluQuadricOrientation(qobj, GLU_OUTSIDE);
- glTranslatef(0.0, 0.0, 0.5f * len);
-}
-
-static void draw_cylinder(GLUquadricObj *qobj, float len, float width)
-{
-
- width *= 0.8f; // just for beauty
-
- glTranslatef(0.0, 0.0, -0.5f * len);
- gluCylinder(qobj, width, width, len, 8, 1);
- gluQuadricOrientation(qobj, GLU_INSIDE);
- gluDisk(qobj, 0.0, width, 8, 1);
- gluQuadricOrientation(qobj, GLU_OUTSIDE);
- glTranslatef(0.0, 0.0, len);
- gluDisk(qobj, 0.0, width, 8, 1);
- glTranslatef(0.0, 0.0, -0.5f * len);
-}
-
-
-static void draw_manipulator_translate(
- View3D *v3d, RegionView3D *rv3d, int drawflags, int combo, int colcode,
- const bool UNUSED(is_moving), const bool is_picksel)
-{
- GLUquadricObj *qobj;
- float cylen = 0.01f * (float)U.tw_handlesize;
- float cywid = 0.25f * cylen, dz, size;
- float unitmat[4][4];
- int shift = 0; // XXX
- int axis_order[3] = {0, 1, 2};
- int i;
-
- /* when called while moving in mixed mode, do not draw when... */
- if ((drawflags & MAN_TRANS_C) == 0) return;
-
- manipulator_axis_order(rv3d, axis_order);
-
- // XXX if (moving) glTranslate3fv(t->vec);
- glDisable(GL_DEPTH_TEST);
-
- /* center circle, do not add to selection when shift is pressed (planar constraint) */
- if (is_picksel && shift == 0) GPU_select_load_id(MAN_TRANS_C);
- else manipulator_setcolor(v3d, 'C', colcode, 255);
-
- glPushMatrix();
- size = screen_aligned(rv3d, rv3d->twmat);
- unit_m4(unitmat);
- drawcircball(GL_LINE_LOOP, unitmat[3], 0.2f * size, unitmat);
- glPopMatrix();
-
- /* and now apply matrix, we move to local matrix drawing */
- glMultMatrixf(rv3d->twmat);
-
- /* axis */
- GPU_select_load_id(-1);
-
- // translate drawn as last, only axis when no combo with scale, or for ghosting
- if ((combo & V3D_MANIP_SCALE) == 0 || colcode == MAN_GHOST) {
- draw_manipulator_axes(v3d, rv3d, colcode,
- drawflags & MAN_TRANS_X, drawflags & MAN_TRANS_Y, drawflags & MAN_TRANS_Z,
- axis_order, is_picksel);
- }
-
-
- /* offset in combo mode, for rotate a bit more */
- if (combo & (V3D_MANIP_ROTATE)) dz = 1.0f + 2.0f * cylen;
- else if (combo & (V3D_MANIP_SCALE)) dz = 1.0f + 0.5f * cylen;
- else dz = 1.0f;
-
- qobj = gluNewQuadric();
- gluQuadricDrawStyle(qobj, GLU_FILL);
-
- for (i = 0; i < 3; i++) {
- switch (axis_order[i]) {
- case 0: /* Z Cone */
- if (drawflags & MAN_TRANS_Z) {
- glTranslatef(0.0, 0.0, dz);
- if (is_picksel) GPU_select_load_id(MAN_TRANS_Z);
- else manipulator_setcolor(v3d, 'Z', colcode, axisBlendAngle(rv3d->tw_idot[2]));
- draw_cone(qobj, cylen, cywid);
- glTranslatef(0.0, 0.0, -dz);
- }
- break;
- case 1: /* X Cone */
- if (drawflags & MAN_TRANS_X) {
- glTranslatef(dz, 0.0, 0.0);
- if (is_picksel) GPU_select_load_id(MAN_TRANS_X);
- else manipulator_setcolor(v3d, 'X', colcode, axisBlendAngle(rv3d->tw_idot[0]));
- glRotatef(90.0, 0.0, 1.0, 0.0);
- draw_cone(qobj, cylen, cywid);
- glRotatef(-90.0, 0.0, 1.0, 0.0);
- glTranslatef(-dz, 0.0, 0.0);
- }
- break;
- case 2: /* Y Cone */
- if (drawflags & MAN_TRANS_Y) {
- glTranslatef(0.0, dz, 0.0);
- if (is_picksel) GPU_select_load_id(MAN_TRANS_Y);
- else manipulator_setcolor(v3d, 'Y', colcode, axisBlendAngle(rv3d->tw_idot[1]));
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- draw_cone(qobj, cylen, cywid);
- glRotatef(90.0, 1.0, 0.0, 0.0);
- glTranslatef(0.0, -dz, 0.0);
- }
- break;
- }
- }
-
- gluDeleteQuadric(qobj);
- glLoadMatrixf(rv3d->viewmat);
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
-
-}
-
-static void draw_manipulator_rotate_cyl(
- View3D *v3d, RegionView3D *rv3d, int drawflags, const int combo, const int colcode,
- const bool is_moving, const bool is_picksel)
-{
- GLUquadricObj *qobj;
- float size;
- float cylen = 0.01f * (float)U.tw_handlesize;
- float cywid = 0.25f * cylen;
- int axis_order[3] = {2, 0, 1};
- int i;
-
- /* skip drawing if all axes are locked */
- if (manipulator_rotate_is_visible(drawflags) == false) return;
-
- manipulator_axis_order(rv3d, axis_order);
-
- /* prepare for screen aligned draw */
- glPushMatrix();
- size = screen_aligned(rv3d, rv3d->twmat);
-
- glDisable(GL_DEPTH_TEST);
-
- qobj = gluNewQuadric();
-
- /* Screen aligned view rot circle */
- if (drawflags & MAN_ROT_V) {
- float unitmat[4][4];
-
- unit_m4(unitmat);
-
- if (is_picksel) GPU_select_load_id(MAN_ROT_V);
- UI_ThemeColor(TH_TRANSFORM);
- drawcircball(GL_LINE_LOOP, unitmat[3], 1.2f * size, unitmat);
-
- if (is_moving) {
- float vec[3];
- vec[0] = 0; // XXX (float)(t->mouse.imval[0] - t->center2d[0]);
- vec[1] = 0; // XXX (float)(t->mouse.imval[1] - t->center2d[1]);
- vec[2] = 0.0f;
- normalize_v3_length(vec, 1.2f * size);
- glBegin(GL_LINES);
- glVertex3f(0.0, 0.0, 0.0);
- glVertex3fv(vec);
- glEnd();
- }
- }
- glPopMatrix();
-
- /* apply the transform delta */
- if (is_moving) {
- float matt[4][4];
- copy_m4_m4(matt, rv3d->twmat); // to copy the parts outside of [3][3]
- // XXX if (t->flag & T_USES_MANIPULATOR) {
- // XXX mul_m4_m3m4(matt, t->mat, rv3d->twmat);
- // XXX }
- glMultMatrixf(matt);
- }
- else {
- glMultMatrixf(rv3d->twmat);
- }
-
- glFrontFace(is_negative_m4(rv3d->twmat) ? GL_CW : GL_CCW);
-
- /* axis */
- if (is_picksel == false) {
-
- // only draw axis when combo didn't draw scale axes
- if ((combo & V3D_MANIP_SCALE) == 0) {
- draw_manipulator_axes(v3d, rv3d, colcode,
- drawflags & MAN_ROT_X, drawflags & MAN_ROT_Y, drawflags & MAN_ROT_Z,
- axis_order, is_picksel);
- }
-
- /* only has to be set when not in picking */
- gluQuadricDrawStyle(qobj, GLU_FILL);
- }
-
- for (i = 0; i < 3; i++) {
- switch (axis_order[i]) {
- case 0: /* X cylinder */
- if (drawflags & MAN_ROT_X) {
- glTranslatef(1.0, 0.0, 0.0);
- if (is_picksel) GPU_select_load_id(MAN_ROT_X);
- glRotatef(90.0, 0.0, 1.0, 0.0);
- manipulator_setcolor(v3d, 'X', colcode, 255);
- draw_cylinder(qobj, cylen, cywid);
- glRotatef(-90.0, 0.0, 1.0, 0.0);
- glTranslatef(-1.0, 0.0, 0.0);
- }
- break;
- case 1: /* Y cylinder */
- if (drawflags & MAN_ROT_Y) {
- glTranslatef(0.0, 1.0, 0.0);
- if (is_picksel) GPU_select_load_id(MAN_ROT_Y);
- glRotatef(-90.0, 1.0, 0.0, 0.0);
- manipulator_setcolor(v3d, 'Y', colcode, 255);
- draw_cylinder(qobj, cylen, cywid);
- glRotatef(90.0, 1.0, 0.0, 0.0);
- glTranslatef(0.0, -1.0, 0.0);
- }
- break;
- case 2: /* Z cylinder */
- if (drawflags & MAN_ROT_Z) {
- glTranslatef(0.0, 0.0, 1.0);
- if (is_picksel) GPU_select_load_id(MAN_ROT_Z);
- manipulator_setcolor(v3d, 'Z', colcode, 255);
- draw_cylinder(qobj, cylen, cywid);
- glTranslatef(0.0, 0.0, -1.0);
- }
- break;
- }
- }
-
- /* restore */
-
- gluDeleteQuadric(qobj);
- glLoadMatrixf(rv3d->viewmat);
-
- if (v3d->zbuf) glEnable(GL_DEPTH_TEST);
-
-}
-
-
-/* ********************************************* */
-
-/* main call, does calc centers & orientation too */
-static int drawflags = 0xFFFF; // only for the calls below, belongs in scene...?
-
-void BIF_draw_manipulator(const bContext *C)
-{
- ScrArea *sa = CTX_wm_area(C);
- ARegion *ar = CTX_wm_region(C);
- Scene *scene = CTX_data_scene(C);
- View3D *v3d = sa->spacedata.first;
- RegionView3D *rv3d = ar->regiondata;
- int totsel;
-
- const bool is_picksel = false;
-
- if (!(v3d->twflag & V3D_USE_MANIPULATOR)) return;
-
- if ((v3d->twtype & (V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE | V3D_MANIP_SCALE)) == 0) return;
-
- {
- struct TransformBounds tbounds;
- v3d->twflag &= ~V3D_DRAW_MANIPULATOR;
-
- totsel = calc_manipulator_stats(C, &tbounds);
- if (totsel == 0) return;
-
- v3d->twflag |= V3D_DRAW_MANIPULATOR;
-
- /* now we can define center */
- switch (v3d->around) {
- case V3D_AROUND_CENTER_BOUNDS:
- case V3D_AROUND_ACTIVE:
- {
- bGPdata *gpd = CTX_data_gpencil_data(C);
- Object *ob = OBACT;
-
- if (((v3d->around == V3D_AROUND_ACTIVE) && (scene->obedit == NULL)) &&
- ((gpd == NULL) || !(gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
- (ob && !(ob->mode & OB_MODE_POSE)))
- {
- copy_v3_v3(rv3d->twmat[3], ob->obmat[3]);
- }
- else {
- mid_v3_v3v3(rv3d->twmat[3], tbounds.min, tbounds.max);
- }
- break;
- }
- case V3D_AROUND_LOCAL_ORIGINS:
- case V3D_AROUND_CENTER_MEAN:
- copy_v3_v3(rv3d->twmat[3], tbounds.center);
- break;
- case V3D_AROUND_CURSOR:
- copy_v3_v3(rv3d->twmat[3], ED_view3d_cursor3d_get(scene, v3d));
- break;
- }
-
- mul_mat3_m4_fl(rv3d->twmat, ED_view3d_pixel_size(rv3d, rv3d->twmat[3]) * U.tw_size);
- }
-
- /* when looking through a selected camera, the manipulator can be at the
- * exact same position as the view, skip so we don't break selection */
- if (fabsf(mat4_to_scale(rv3d->twmat)) < 1e-7f)
- return;
-
- test_manipulator_axis(C);
- drawflags = rv3d->twdrawflag; /* set in calc_manipulator_stats */
-
- if (v3d->twflag & V3D_DRAW_MANIPULATOR) {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glLineWidth(1.0f);
-
- if (v3d->twtype & V3D_MANIP_ROTATE) {
- if (G.debug_value == 3) {
- if (G.moving & (G_TRANSFORM_OBJ | G_TRANSFORM_EDIT))
- draw_manipulator_rotate_cyl(v3d, rv3d, drawflags, v3d->twtype, MAN_MOVECOL, true, is_picksel);
- else
- draw_manipulator_rotate_cyl(v3d, rv3d, drawflags, v3d->twtype, MAN_RGB, false, is_picksel);
- }
- else {
- draw_manipulator_rotate(v3d, rv3d, drawflags, v3d->twtype, false, is_picksel);
- }
- }
- if (v3d->twtype & V3D_MANIP_SCALE) {
- draw_manipulator_scale(v3d, rv3d, drawflags, v3d->twtype, MAN_RGB, false, is_picksel);
- }
- if (v3d->twtype & V3D_MANIP_TRANSLATE) {
- draw_manipulator_translate(v3d, rv3d, drawflags, v3d->twtype, MAN_RGB, false, is_picksel);
- }
-
- glDisable(GL_BLEND);
- }
-}
-
-static int manipulator_selectbuf(Scene *scene, ScrArea *sa, ARegion *ar, const int mval[2], float hotspot)
-{
- View3D *v3d = sa->spacedata.first;
- RegionView3D *rv3d = ar->regiondata;
- rcti rect;
- GLuint buffer[64]; // max 4 items per select, so large enuf
- short hits;
- const bool is_picksel = true;
- const bool do_passes = GPU_select_query_check_active();
-
- /* when looking through a selected camera, the manipulator can be at the
- * exact same position as the view, skip so we don't break selection */
- if (fabsf(mat4_to_scale(rv3d->twmat)) < 1e-7f)
- return 0;
-
- rect.xmin = mval[0] - hotspot;
- rect.xmax = mval[0] + hotspot;
- rect.ymin = mval[1] - hotspot;
- rect.ymax = mval[1] + hotspot;
-
- ED_view3d_draw_setup_view(NULL, scene, ar, v3d, NULL, NULL, &rect);
-
- if (do_passes)
- GPU_select_begin(buffer, 64, &rect, GPU_SELECT_NEAREST_FIRST_PASS, 0);
- else
- GPU_select_begin(buffer, 64, &rect, GPU_SELECT_ALL, 0);
-
- /* do the drawing */
- if (v3d->twtype & V3D_MANIP_ROTATE) {
- if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, is_picksel);
- else draw_manipulator_rotate(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, false, is_picksel);
- }
- if (v3d->twtype & V3D_MANIP_SCALE)
- draw_manipulator_scale(v3d, rv3d, MAN_SCALE_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, is_picksel);
- if (v3d->twtype & V3D_MANIP_TRANSLATE)
- draw_manipulator_translate(v3d, rv3d, MAN_TRANS_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, is_picksel);
-
- hits = GPU_select_end();
-
- if (do_passes && (hits > 0)) {
- GPU_select_begin(buffer, 64, &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
-
- /* do the drawing */
- if (v3d->twtype & V3D_MANIP_ROTATE) {
- if (G.debug_value == 3) draw_manipulator_rotate_cyl(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, is_picksel);
- else draw_manipulator_rotate(v3d, rv3d, MAN_ROT_C & rv3d->twdrawflag, v3d->twtype, false, is_picksel);
- }
- if (v3d->twtype & V3D_MANIP_SCALE)
- draw_manipulator_scale(v3d, rv3d, MAN_SCALE_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, is_picksel);
- if (v3d->twtype & V3D_MANIP_TRANSLATE)
- draw_manipulator_translate(v3d, rv3d, MAN_TRANS_C & rv3d->twdrawflag, v3d->twtype, MAN_RGB, false, is_picksel);
-
- GPU_select_end();
- }
-
- ED_view3d_draw_setup_view(NULL, scene, ar, v3d, NULL, NULL, NULL);
-
- if (hits == 1) return buffer[3];
- else if (hits > 1) {
- GLuint val, dep, mindep = 0, mindeprot = 0, minval = 0, minvalrot = 0;
- int a;
-
- /* we compare the hits in buffer, but value centers highest */
- /* we also store the rotation hits separate (because of arcs) and return hits on other widgets if there are */
-
- for (a = 0; a < hits; a++) {
- dep = buffer[4 * a + 1];
- val = buffer[4 * a + 3];
-
- if (val == MAN_TRANS_C) {
- return MAN_TRANS_C;
- }
- else if (val == MAN_SCALE_C) {
- return MAN_SCALE_C;
- }
- else {
- if (val & MAN_ROT_C) {
- if (minvalrot == 0 || dep < mindeprot) {
- mindeprot = dep;
- minvalrot = val;
- }
- }
- else {
- if (minval == 0 || dep < mindep) {
- mindep = dep;
- minval = val;
- }
- }
- }
- }
-
- if (minval)
- return minval;
- else
- return minvalrot;
- }
- return 0;
-}
-
-static const char *manipulator_get_operator_name(int man_val)
-{
- if (man_val & MAN_TRANS_C) {
- return "TRANSFORM_OT_translate";
- }
- else if (man_val == MAN_ROT_T) {
- return "TRANSFORM_OT_trackball";
- }
- else if (man_val & MAN_ROT_C) {
- return "TRANSFORM_OT_rotate";
- }
- else if (man_val & MAN_SCALE_C) {
- return "TRANSFORM_OT_resize";
- }
-
- return NULL;
-}
-
-/* return 0; nothing happened */
-int BIF_do_manipulator(bContext *C, const struct wmEvent *event, wmOperator *op)
-{
- Scene *scene = CTX_data_scene(C);
- ScrArea *sa = CTX_wm_area(C);
- View3D *v3d = sa->spacedata.first;
- ARegion *ar = CTX_wm_region(C);
- int constraint_axis[3] = {0, 0, 0};
- int val;
- const bool use_planar = RNA_boolean_get(op->ptr, "use_planar_constraint");
-
- if (!(v3d->twflag & V3D_USE_MANIPULATOR)) return 0;
- if (!(v3d->twflag & V3D_DRAW_MANIPULATOR)) return 0;
-
- /* Force orientation */
- RNA_enum_set(op->ptr, "constraint_orientation", v3d->twmode);
-
- // find the hotspots first test narrow hotspot
- val = manipulator_selectbuf(scene, sa, ar, event->mval, 0.5f * (float)U.tw_hotspot);
- if (val) {
- wmOperatorType *ot;
- PointerRNA props_ptr;
- PropertyRNA *prop;
- const char *opname;
-
- // drawflags still global, for drawing call above
- drawflags = manipulator_selectbuf(scene, sa, ar, event->mval, 0.2f * (float)U.tw_hotspot);
- if (drawflags == 0) drawflags = val;
-
- /* Planar constraint doesn't make sense for rotation, give other keymaps a chance */
- if ((drawflags & MAN_ROT_C) && use_planar) {
- return 0;
- }
-
- opname = manipulator_get_operator_name(drawflags);
- ot = WM_operatortype_find(opname, true);
- WM_operator_properties_create_ptr(&props_ptr, ot);
-
- if (drawflags & MAN_TRANS_C) {
- switch (drawflags) {
- case MAN_TRANS_C:
- break;
- case MAN_TRANS_X:
- if (use_planar) {
- constraint_axis[1] = 1;
- constraint_axis[2] = 1;
- }
- else
- constraint_axis[0] = 1;
- break;
- case MAN_TRANS_Y:
- if (use_planar) {
- constraint_axis[0] = 1;
- constraint_axis[2] = 1;
- }
- else
- constraint_axis[1] = 1;
- break;
- case MAN_TRANS_Z:
- if (use_planar) {
- constraint_axis[0] = 1;
- constraint_axis[1] = 1;
- }
- else
- constraint_axis[2] = 1;
- break;
- }
- RNA_boolean_set_array(&props_ptr, "constraint_axis", constraint_axis);
- }
- else if (drawflags & MAN_SCALE_C) {
- switch (drawflags) {
- case MAN_SCALE_X:
- if (use_planar) {
- constraint_axis[1] = 1;
- constraint_axis[2] = 1;
- }
- else
- constraint_axis[0] = 1;
- break;
- case MAN_SCALE_Y:
- if (use_planar) {
- constraint_axis[0] = 1;
- constraint_axis[2] = 1;
- }
- else
- constraint_axis[1] = 1;
- break;
- case MAN_SCALE_Z:
- if (use_planar) {
- constraint_axis[0] = 1;
- constraint_axis[1] = 1;
- }
- else
- constraint_axis[2] = 1;
- break;
- }
- RNA_boolean_set_array(&props_ptr, "constraint_axis", constraint_axis);
- }
- else if (drawflags == MAN_ROT_T) {
- /* pass */
- }
- else if (drawflags & MAN_ROT_C) {
- switch (drawflags) {
- case MAN_ROT_X:
- constraint_axis[0] = 1;
- break;
- case MAN_ROT_Y:
- constraint_axis[1] = 1;
- break;
- case MAN_ROT_Z:
- constraint_axis[2] = 1;
- break;
- }
- RNA_boolean_set_array(&props_ptr, "constraint_axis", constraint_axis);
- }
-
- /* pass operator properties on to transform operators */
- prop = RNA_struct_find_property(op->ptr, "use_accurate");
- if (RNA_property_is_set(op->ptr, prop)) {
- RNA_property_boolean_set(&props_ptr, prop, RNA_property_boolean_get(op->ptr, prop));
- }
- prop = RNA_struct_find_property(op->ptr, "release_confirm");
- if (RNA_property_is_set(op->ptr, prop)) {
- RNA_property_boolean_set(&props_ptr, prop, RNA_property_boolean_get(op->ptr, prop));
- }
- prop = RNA_struct_find_property(op->ptr, "constraint_orientation");
- if (RNA_property_is_set(op->ptr, prop)) {
- RNA_property_enum_set(&props_ptr, prop, RNA_property_enum_get(op->ptr, prop));
- }
-
- WM_operator_name_call_ptr(C, ot, WM_OP_INVOKE_DEFAULT, &props_ptr);
- WM_operator_properties_free(&props_ptr);
- }
- /* after transform, restore drawflags */
- drawflags = 0xFFFF;
-
- return val;
-}
-
diff --git a/source/blender/editors/transform/transform_manipulator_2d.c b/source/blender/editors/transform/transform_manipulator_2d.c
new file mode 100644
index 00000000000..d2743f47000
--- /dev/null
+++ b/source/blender/editors/transform/transform_manipulator_2d.c
@@ -0,0 +1,382 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/transform/transform_manipulator_2d.c
+ * \ingroup edtransform
+ *
+ * \name 2D Transform Manipulator
+ *
+ * Used for UV/Image Editor
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+
+#include "DNA_meshdata_types.h"
+#include "DNA_object_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BKE_context.h"
+#include "BKE_editmesh.h"
+
+#include "RNA_access.h"
+
+#include "UI_resources.h"
+#include "UI_view2d.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "wm.h" /* XXX */
+
+#include "ED_image.h"
+#include "ED_screen.h"
+#include "ED_uvedit.h"
+#include "ED_manipulator_library.h"
+
+#include "transform.h" /* own include */
+
+/* axes as index */
+enum {
+ MAN2D_AXIS_TRANS_X = 0,
+ MAN2D_AXIS_TRANS_Y,
+
+ MAN2D_AXIS_LAST,
+};
+
+typedef struct ManipulatorGroup2D {
+ wmManipulator *translate_x,
+ *translate_y;
+
+ wmManipulator *cage;
+
+ /* Current origin in view space, used to update widget origin for possible view changes */
+ float origin[2];
+ float min[2];
+ float max[2];
+
+} ManipulatorGroup2D;
+
+
+/* **************** Utilities **************** */
+
+/* loop over axes */
+#define MAN2D_ITER_AXES_BEGIN(axis, axis_idx) \
+ { \
+ wmManipulator *axis; \
+ int axis_idx; \
+ for (axis_idx = 0; axis_idx < MAN2D_AXIS_LAST; axis_idx++) { \
+ axis = manipulator2d_get_axis_from_index(man, axis_idx);
+
+#define MAN2D_ITER_AXES_END \
+ } \
+ } ((void)0)
+
+static wmManipulator *manipulator2d_get_axis_from_index(const ManipulatorGroup2D *man, const short axis_idx)
+{
+ BLI_assert(IN_RANGE_INCL(axis_idx, (float)MAN2D_AXIS_TRANS_X, (float)MAN2D_AXIS_TRANS_Y));
+
+ switch (axis_idx) {
+ case MAN2D_AXIS_TRANS_X:
+ return man->translate_x;
+ case MAN2D_AXIS_TRANS_Y:
+ return man->translate_y;
+ }
+
+ return NULL;
+}
+
+static void manipulator2d_get_axis_color(const int axis_idx, float *r_col, float *r_col_hi)
+{
+ const float alpha = 0.6f;
+ const float alpha_hi = 1.0f;
+ int col_id;
+
+ switch (axis_idx) {
+ case MAN2D_AXIS_TRANS_X:
+ col_id = TH_AXIS_X;
+ break;
+ case MAN2D_AXIS_TRANS_Y:
+ col_id = TH_AXIS_Y;
+ break;
+ }
+
+ UI_GetThemeColor4fv(col_id, r_col);
+
+ copy_v4_v4(r_col_hi, r_col);
+ r_col[3] *= alpha;
+ r_col_hi[3] *= alpha_hi;
+}
+
+static ManipulatorGroup2D *manipulatorgroup2d_init(wmManipulatorGroup *mgroup)
+{
+ const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_2d", true);
+ const wmManipulatorType *wt_cage = WM_manipulatortype_find("MANIPULATOR_WT_cage_2d", true);
+
+ ManipulatorGroup2D *man = MEM_callocN(sizeof(ManipulatorGroup2D), __func__);
+
+ man->translate_x = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ man->translate_y = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL);
+ man->cage = WM_manipulator_new_ptr(wt_cage, mgroup, NULL);
+
+ RNA_enum_set(man->cage->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE |
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE |
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_ROTATE);
+
+ return man;
+}
+
+/**
+ * Calculates origin in view space, use with #manipulator2d_origin_to_region.
+ */
+static void manipulator2d_calc_bounds(const bContext *C, float *r_center, float *r_min, float *r_max)
+{
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Image *ima = ED_space_image(sima);
+
+ float min_buf[2], max_buf[2];
+ if (r_min == NULL) {
+ r_min = min_buf;
+ }
+ if (r_max == NULL) {
+ r_max = max_buf;
+ }
+
+ if (!ED_uvedit_minmax(CTX_data_scene(C), ima, CTX_data_edit_object(C), r_min, r_max)) {
+ zero_v2(r_min);
+ zero_v2(r_max);
+ }
+ mid_v2_v2v2(r_center, r_min, r_max);
+}
+
+/**
+ * Convert origin (or any other point) from view to region space.
+ */
+BLI_INLINE void manipulator2d_origin_to_region(ARegion *ar, float *r_origin)
+{
+ UI_view2d_view_to_region_fl(&ar->v2d, r_origin[0], r_origin[1], &r_origin[0], &r_origin[1]);
+}
+
+/**
+ * Custom handler for manipulator widgets
+ */
+static int manipulator2d_modal(
+ bContext *C, wmManipulator *widget, const wmEvent *UNUSED(event),
+ eWM_ManipulatorTweak UNUSED(tweak_flag))
+{
+ ARegion *ar = CTX_wm_region(C);
+ float origin[3];
+
+ manipulator2d_calc_bounds(C, origin, NULL, NULL);
+ manipulator2d_origin_to_region(ar, origin);
+ WM_manipulator_set_matrix_location(widget, origin);
+
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void ED_widgetgroup_manipulator2d_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ wmOperatorType *ot_translate = WM_operatortype_find("TRANSFORM_OT_translate", true);
+ ManipulatorGroup2D *man = manipulatorgroup2d_init(mgroup);
+ mgroup->customdata = man;
+
+ MAN2D_ITER_AXES_BEGIN(axis, axis_idx)
+ {
+ const float offset[3] = {0.0f, 0.2f};
+
+ float color[4], color_hi[4];
+ manipulator2d_get_axis_color(axis_idx, color, color_hi);
+
+ /* custom handler! */
+ WM_manipulator_set_fn_custom_modal(axis, manipulator2d_modal);
+ /* set up widget data */
+ RNA_float_set(axis->ptr, "angle", -M_PI_2 * axis_idx);
+ RNA_float_set(axis->ptr, "length", 0.8f);
+ WM_manipulator_set_matrix_offset_location(axis, offset);
+ WM_manipulator_set_line_width(axis, MANIPULATOR_AXIS_LINE_WIDTH);
+ WM_manipulator_set_scale(axis, U.manipulator_size);
+ WM_manipulator_set_color(axis, color);
+ WM_manipulator_set_color_highlight(axis, color_hi);
+
+ /* assign operator */
+ PointerRNA *ptr = WM_manipulator_operator_set(axis, 0, ot_translate, NULL);
+ int constraint[3] = {0};
+ constraint[(axis_idx + 1) % 2] = 1;
+ if (RNA_struct_find_property(ptr, "constraint_axis"))
+ RNA_boolean_set_array(ptr, "constraint_axis", constraint);
+ RNA_boolean_set(ptr, "release_confirm", 1);
+ }
+ MAN2D_ITER_AXES_END;
+
+ {
+ wmOperatorType *ot_resize = WM_operatortype_find("TRANSFORM_OT_resize", true);
+ wmOperatorType *ot_rotate = WM_operatortype_find("TRANSFORM_OT_rotate", true);
+ PointerRNA *ptr;
+
+ /* assign operator */
+ ptr = WM_manipulator_operator_set(man->cage, 0, ot_translate, NULL);
+ RNA_boolean_set(ptr, "release_confirm", 1);
+
+ int constraint_x[3] = {1, 0, 0};
+ int constraint_y[3] = {0, 1, 0};
+
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X, ot_resize, NULL);
+ PropertyRNA *prop_release_confirm = RNA_struct_find_property(ptr, "release_confirm");
+ PropertyRNA *prop_constraint_axis = RNA_struct_find_property(ptr, "constraint_axis");
+ RNA_property_boolean_set_array(ptr, prop_constraint_axis, constraint_x);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X, ot_resize, NULL);
+ RNA_property_boolean_set_array(ptr, prop_constraint_axis, constraint_x);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y, ot_resize, NULL);
+ RNA_property_boolean_set_array(ptr, prop_constraint_axis, constraint_y);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y, ot_resize, NULL);
+ RNA_property_boolean_set_array(ptr, prop_constraint_axis, constraint_y);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y, ot_resize, NULL);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y, ot_resize, NULL);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y, ot_resize, NULL);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y, ot_resize, NULL);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ ptr = WM_manipulator_operator_set(man->cage, ED_MANIPULATOR_CAGE2D_PART_ROTATE, ot_rotate, NULL);
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ }
+}
+
+void ED_widgetgroup_manipulator2d_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ManipulatorGroup2D *man = mgroup->customdata;
+ float origin[3];
+ manipulator2d_calc_bounds(C, origin, man->min, man->max);
+ copy_v2_v2(man->origin, origin);
+ bool show_cage = !equals_v2v2(man->min, man->max);
+
+ if (show_cage) {
+ man->cage->flag &= ~WM_MANIPULATOR_HIDDEN;
+ man->translate_x->flag |= WM_MANIPULATOR_HIDDEN;
+ man->translate_y->flag |= WM_MANIPULATOR_HIDDEN;
+ }
+ else {
+ man->cage->flag |= WM_MANIPULATOR_HIDDEN;
+ man->translate_x->flag &= ~WM_MANIPULATOR_HIDDEN;
+ man->translate_y->flag &= ~WM_MANIPULATOR_HIDDEN;
+ }
+
+ if (show_cage) {
+ wmManipulatorOpElem *mpop;
+ float mid[2];
+ const float *min = man->min;
+ const float *max = man->max;
+ mid_v2_v2v2(mid, min, max);
+
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X);
+ PropertyRNA *prop_center_override = RNA_struct_find_property(&mpop->ptr, "center_override");
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){max[0], mid[1], 0.0f});
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){min[0], mid[1], 0.0f});
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_Y);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){mid[0], max[1], 0.0f});
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_Y);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){mid[0], min[1], 0.0f});
+
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MIN_Y);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){max[0], max[1], 0.0f});
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MIN_X_MAX_Y);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){max[0], min[1], 0.0f});
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MIN_Y);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){min[0], max[1], 0.0f});
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_SCALE_MAX_X_MAX_Y);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){min[0], min[1], 0.0f});
+
+ mpop = WM_manipulator_operator_get(man->cage, ED_MANIPULATOR_CAGE2D_PART_ROTATE);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, (float[3]){mid[0], mid[1], 0.0f});
+ }
+}
+
+void ED_widgetgroup_manipulator2d_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ARegion *ar = CTX_wm_region(C);
+ ManipulatorGroup2D *man = mgroup->customdata;
+ float origin[3] = {UNPACK2(man->origin), 0.0f};
+ float origin_aa[3] = {UNPACK2(man->origin), 0.0f};
+
+ manipulator2d_origin_to_region(ar, origin);
+
+ MAN2D_ITER_AXES_BEGIN(axis, axis_idx)
+ {
+ WM_manipulator_set_matrix_location(axis, origin);
+ }
+ MAN2D_ITER_AXES_END;
+
+ UI_view2d_view_to_region_m4(&ar->v2d, man->cage->matrix_space);
+ WM_manipulator_set_matrix_offset_location(man->cage, origin_aa);
+ man->cage->matrix_offset[0][0] = (man->max[0] - man->min[0]);
+ man->cage->matrix_offset[1][1] = (man->max[1] - man->min[1]);
+}
+
+/* TODO (Julian)
+ * - Called on every redraw, better to do a more simple poll and check for selection in _refresh
+ * - UV editing only, could be expanded for other things.
+ */
+bool ED_widgetgroup_manipulator2d_poll(const bContext *C, wmManipulatorGroupType *UNUSED(wgt))
+{
+ if ((U.manipulator_flag & USER_MANIPULATOR_DRAW) == 0) {
+ return false;
+ }
+
+ SpaceImage *sima = CTX_wm_space_image(C);
+ Object *obedit = CTX_data_edit_object(C);
+
+ if (ED_space_image_show_uvedit(sima, obedit)) {
+ Image *ima = ED_space_image(sima);
+ Scene *scene = CTX_data_scene(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMFace *efa;
+ BMLoop *l;
+ BMIter iter, liter;
+
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+
+ /* check if there's a selected poly */
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
+ continue;
+
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
+ return true;
+ }
+ }
+ }
+ }
+
+ return false;
+}
diff --git a/source/blender/editors/transform/transform_manipulator_3d.c b/source/blender/editors/transform/transform_manipulator_3d.c
new file mode 100644
index 00000000000..afe40b94d9a
--- /dev/null
+++ b/source/blender/editors/transform/transform_manipulator_3d.c
@@ -0,0 +1,1725 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/editors/transform/transform_manipulator_2d.c
+ * \ingroup edtransform
+ *
+ * \name 3D Transform Manipulator
+ *
+ * Used for 3D View
+ */
+
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <float.h>
+
+#include "DNA_armature_types.h"
+#include "DNA_curve_types.h"
+#include "DNA_gpencil_types.h"
+#include "DNA_lattice_types.h"
+#include "DNA_meta_types.h"
+#include "DNA_screen_types.h"
+#include "DNA_scene_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_utildefines.h"
+
+#include "RNA_access.h"
+
+#include "BKE_action.h"
+#include "BKE_context.h"
+#include "BKE_curve.h"
+#include "BKE_global.h"
+#include "BKE_particle.h"
+#include "BKE_pointcache.h"
+#include "BKE_editmesh.h"
+#include "BKE_lattice.h"
+#include "BKE_gpencil.h"
+#include "BKE_scene.h"
+#include "BKE_workspace.h"
+
+#include "BIF_gl.h"
+
+#include "DEG_depsgraph.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "WM_message.h"
+
+#include "ED_armature.h"
+#include "ED_curve.h"
+#include "ED_object.h"
+#include "ED_particle.h"
+#include "ED_view3d.h"
+#include "ED_gpencil.h"
+#include "ED_screen.h"
+#include "ED_manipulator_library.h"
+
+#include "UI_resources.h"
+
+/* local module include */
+#include "transform.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "GPU_select.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+
+#include "DEG_depsgraph_query.h"
+
+/* return codes for select, and drawing flags */
+
+#define MAN_TRANS_X (1 << 0)
+#define MAN_TRANS_Y (1 << 1)
+#define MAN_TRANS_Z (1 << 2)
+#define MAN_TRANS_C (MAN_TRANS_X | MAN_TRANS_Y | MAN_TRANS_Z)
+
+#define MAN_ROT_X (1 << 3)
+#define MAN_ROT_Y (1 << 4)
+#define MAN_ROT_Z (1 << 5)
+#define MAN_ROT_C (MAN_ROT_X | MAN_ROT_Y | MAN_ROT_Z)
+
+#define MAN_SCALE_X (1 << 8)
+#define MAN_SCALE_Y (1 << 9)
+#define MAN_SCALE_Z (1 << 10)
+#define MAN_SCALE_C (MAN_SCALE_X | MAN_SCALE_Y | MAN_SCALE_Z)
+
+/* threshold for testing view aligned manipulator axis */
+#define TW_AXIS_DOT_MIN 0.02f
+#define TW_AXIS_DOT_MAX 0.1f
+
+/* axes as index */
+enum {
+ MAN_AXIS_TRANS_X = 0,
+ MAN_AXIS_TRANS_Y,
+ MAN_AXIS_TRANS_Z,
+ MAN_AXIS_TRANS_C,
+
+ MAN_AXIS_TRANS_XY,
+ MAN_AXIS_TRANS_YZ,
+ MAN_AXIS_TRANS_ZX,
+#define MAN_AXIS_RANGE_TRANS_START MAN_AXIS_TRANS_X
+#define MAN_AXIS_RANGE_TRANS_END (MAN_AXIS_TRANS_ZX + 1)
+
+ MAN_AXIS_ROT_X,
+ MAN_AXIS_ROT_Y,
+ MAN_AXIS_ROT_Z,
+ MAN_AXIS_ROT_C,
+ MAN_AXIS_ROT_T, /* trackball rotation */
+#define MAN_AXIS_RANGE_ROT_START MAN_AXIS_ROT_X
+#define MAN_AXIS_RANGE_ROT_END (MAN_AXIS_ROT_T + 1)
+
+ MAN_AXIS_SCALE_X,
+ MAN_AXIS_SCALE_Y,
+ MAN_AXIS_SCALE_Z,
+ MAN_AXIS_SCALE_C,
+ MAN_AXIS_SCALE_XY,
+ MAN_AXIS_SCALE_YZ,
+ MAN_AXIS_SCALE_ZX,
+#define MAN_AXIS_RANGE_SCALE_START MAN_AXIS_SCALE_X
+#define MAN_AXIS_RANGE_SCALE_END (MAN_AXIS_SCALE_ZX + 1)
+
+ MAN_AXIS_LAST = MAN_AXIS_RANGE_SCALE_END,
+};
+
+/* axis types */
+enum {
+ MAN_AXES_ALL = 0,
+ MAN_AXES_TRANSLATE,
+ MAN_AXES_ROTATE,
+ MAN_AXES_SCALE,
+};
+
+/* naming from old blender we may combine. */
+enum {
+ V3D_MANIP_TRANSLATE = 1,
+ V3D_MANIP_ROTATE = 2,
+ V3D_MANIP_SCALE = 4,
+};
+
+
+typedef struct ManipulatorGroup {
+ bool all_hidden;
+ int twtype;
+
+ struct wmManipulator *manipulators[MAN_AXIS_LAST];
+} ManipulatorGroup;
+
+/* -------------------------------------------------------------------- */
+/** \name Utilities
+ * \{ */
+
+/* loop over axes */
+#define MAN_ITER_AXES_BEGIN(axis, axis_idx) \
+ { \
+ wmManipulator *axis; \
+ int axis_idx; \
+ for (axis_idx = 0; axis_idx < MAN_AXIS_LAST; axis_idx++) { \
+ axis = manipulator_get_axis_from_index(man, axis_idx);
+
+#define MAN_ITER_AXES_END \
+ } \
+ } ((void)0)
+
+static wmManipulator *manipulator_get_axis_from_index(const ManipulatorGroup *man, const short axis_idx)
+{
+ BLI_assert(IN_RANGE_INCL(axis_idx, (float)MAN_AXIS_TRANS_X, (float)MAN_AXIS_LAST));
+ return man->manipulators[axis_idx];
+}
+
+static short manipulator_get_axis_type(const int axis_idx)
+{
+ if (axis_idx >= MAN_AXIS_RANGE_TRANS_START && axis_idx < MAN_AXIS_RANGE_TRANS_END) {
+ return MAN_AXES_TRANSLATE;
+ }
+ if (axis_idx >= MAN_AXIS_RANGE_ROT_START && axis_idx < MAN_AXIS_RANGE_ROT_END) {
+ return MAN_AXES_ROTATE;
+ }
+ if (axis_idx >= MAN_AXIS_RANGE_SCALE_START && axis_idx < MAN_AXIS_RANGE_SCALE_END) {
+ return MAN_AXES_SCALE;
+ }
+ BLI_assert(0);
+ return -1;
+}
+
+static uint manipulator_orientation_axis(const int axis_idx, bool *r_is_plane)
+{
+ switch (axis_idx) {
+ case MAN_AXIS_TRANS_YZ:
+ case MAN_AXIS_SCALE_YZ:
+ if (r_is_plane) {
+ *r_is_plane = true;
+ }
+ ATTR_FALLTHROUGH;
+ case MAN_AXIS_TRANS_X:
+ case MAN_AXIS_ROT_X:
+ case MAN_AXIS_SCALE_X:
+ return 0;
+
+ case MAN_AXIS_TRANS_ZX:
+ case MAN_AXIS_SCALE_ZX:
+ if (r_is_plane) {
+ *r_is_plane = true;
+ }
+ ATTR_FALLTHROUGH;
+ case MAN_AXIS_TRANS_Y:
+ case MAN_AXIS_ROT_Y:
+ case MAN_AXIS_SCALE_Y:
+ return 1;
+
+ case MAN_AXIS_TRANS_XY:
+ case MAN_AXIS_SCALE_XY:
+ if (r_is_plane) {
+ *r_is_plane = true;
+ }
+ ATTR_FALLTHROUGH;
+ case MAN_AXIS_TRANS_Z:
+ case MAN_AXIS_ROT_Z:
+ case MAN_AXIS_SCALE_Z:
+ return 2;
+ }
+ return 3;
+}
+
+static bool manipulator_is_axis_visible(
+ const RegionView3D *rv3d, const int twtype,
+ const float idot[3], const int axis_type, const int axis_idx)
+{
+ bool is_plane = false;
+ const uint aidx_norm = manipulator_orientation_axis(axis_idx, &is_plane);
+ /* don't draw axis perpendicular to the view */
+ if (aidx_norm < 3) {
+ float idot_axis = idot[aidx_norm];
+ if (is_plane) {
+ idot_axis = 1.0f - idot_axis;
+ }
+ if (idot_axis < TW_AXIS_DOT_MIN) {
+ return false;
+ }
+ }
+
+ if ((axis_type == MAN_AXES_TRANSLATE && !(twtype & V3D_MANIP_TRANSLATE)) ||
+ (axis_type == MAN_AXES_ROTATE && !(twtype & V3D_MANIP_ROTATE)) ||
+ (axis_type == MAN_AXES_SCALE && !(twtype & V3D_MANIP_SCALE)))
+ {
+ return false;
+ }
+
+ switch (axis_idx) {
+ case MAN_AXIS_TRANS_X:
+ return (rv3d->twdrawflag & MAN_TRANS_X);
+ case MAN_AXIS_TRANS_Y:
+ return (rv3d->twdrawflag & MAN_TRANS_Y);
+ case MAN_AXIS_TRANS_Z:
+ return (rv3d->twdrawflag & MAN_TRANS_Z);
+ case MAN_AXIS_TRANS_C:
+ return (rv3d->twdrawflag & MAN_TRANS_C);
+ case MAN_AXIS_ROT_X:
+ return (rv3d->twdrawflag & MAN_ROT_X);
+ case MAN_AXIS_ROT_Y:
+ return (rv3d->twdrawflag & MAN_ROT_Y);
+ case MAN_AXIS_ROT_Z:
+ return (rv3d->twdrawflag & MAN_ROT_Z);
+ case MAN_AXIS_ROT_C:
+ case MAN_AXIS_ROT_T:
+ return (rv3d->twdrawflag & MAN_ROT_C);
+ case MAN_AXIS_SCALE_X:
+ return (rv3d->twdrawflag & MAN_SCALE_X);
+ case MAN_AXIS_SCALE_Y:
+ return (rv3d->twdrawflag & MAN_SCALE_Y);
+ case MAN_AXIS_SCALE_Z:
+ return (rv3d->twdrawflag & MAN_SCALE_Z);
+ case MAN_AXIS_SCALE_C:
+ return (rv3d->twdrawflag & MAN_SCALE_C && (twtype & V3D_MANIP_TRANSLATE) == 0);
+ case MAN_AXIS_TRANS_XY:
+ return (rv3d->twdrawflag & MAN_TRANS_X &&
+ rv3d->twdrawflag & MAN_TRANS_Y &&
+ (twtype & V3D_MANIP_ROTATE) == 0);
+ case MAN_AXIS_TRANS_YZ:
+ return (rv3d->twdrawflag & MAN_TRANS_Y &&
+ rv3d->twdrawflag & MAN_TRANS_Z &&
+ (twtype & V3D_MANIP_ROTATE) == 0);
+ case MAN_AXIS_TRANS_ZX:
+ return (rv3d->twdrawflag & MAN_TRANS_Z &&
+ rv3d->twdrawflag & MAN_TRANS_X &&
+ (twtype & V3D_MANIP_ROTATE) == 0);
+ case MAN_AXIS_SCALE_XY:
+ return (rv3d->twdrawflag & MAN_SCALE_X &&
+ rv3d->twdrawflag & MAN_SCALE_Y &&
+ (twtype & V3D_MANIP_TRANSLATE) == 0 &&
+ (twtype & V3D_MANIP_ROTATE) == 0);
+ case MAN_AXIS_SCALE_YZ:
+ return (rv3d->twdrawflag & MAN_SCALE_Y &&
+ rv3d->twdrawflag & MAN_SCALE_Z &&
+ (twtype & V3D_MANIP_TRANSLATE) == 0 &&
+ (twtype & V3D_MANIP_ROTATE) == 0);
+ case MAN_AXIS_SCALE_ZX:
+ return (rv3d->twdrawflag & MAN_SCALE_Z &&
+ rv3d->twdrawflag & MAN_SCALE_X &&
+ (twtype & V3D_MANIP_TRANSLATE) == 0 &&
+ (twtype & V3D_MANIP_ROTATE) == 0);
+ }
+ return false;
+}
+
+static void manipulator_get_axis_color(
+ const int axis_idx, const float idot[3],
+ float r_col[4], float r_col_hi[4])
+{
+ /* alpha values for normal/highlighted states */
+ const float alpha = 0.6f;
+ const float alpha_hi = 1.0f;
+ float alpha_fac;
+
+ bool is_plane = false;
+ const int axis_idx_norm = manipulator_orientation_axis(axis_idx, &is_plane);
+ /* get alpha fac based on axis angle, to fade axis out when hiding it because it points towards view */
+ if (axis_idx_norm < 3) {
+ float idot_axis = idot[axis_idx_norm];
+ if (is_plane) {
+ idot_axis = 1.0f - idot_axis;
+ }
+ alpha_fac = (idot_axis > TW_AXIS_DOT_MAX) ?
+ 1.0f : (idot_axis < TW_AXIS_DOT_MIN) ?
+ 0.0f : ((idot_axis - TW_AXIS_DOT_MIN) / (TW_AXIS_DOT_MAX - TW_AXIS_DOT_MIN));
+ }
+ else {
+ /* trackball rotation axis is a special case, we only draw a slight overlay */
+ alpha_fac = (axis_idx == MAN_AXIS_ROT_T) ? 0.1f : 1.0f;
+ }
+
+ switch (axis_idx) {
+ case MAN_AXIS_TRANS_X:
+ case MAN_AXIS_ROT_X:
+ case MAN_AXIS_SCALE_X:
+ case MAN_AXIS_TRANS_YZ:
+ case MAN_AXIS_SCALE_YZ:
+ UI_GetThemeColor4fv(TH_AXIS_X, r_col);
+ break;
+ case MAN_AXIS_TRANS_Y:
+ case MAN_AXIS_ROT_Y:
+ case MAN_AXIS_SCALE_Y:
+ case MAN_AXIS_TRANS_ZX:
+ case MAN_AXIS_SCALE_ZX:
+ UI_GetThemeColor4fv(TH_AXIS_Y, r_col);
+ break;
+ case MAN_AXIS_TRANS_Z:
+ case MAN_AXIS_ROT_Z:
+ case MAN_AXIS_SCALE_Z:
+ case MAN_AXIS_TRANS_XY:
+ case MAN_AXIS_SCALE_XY:
+ UI_GetThemeColor4fv(TH_AXIS_Z, r_col);
+ break;
+ case MAN_AXIS_TRANS_C:
+ case MAN_AXIS_ROT_C:
+ case MAN_AXIS_SCALE_C:
+ case MAN_AXIS_ROT_T:
+ copy_v4_fl(r_col, 1.0f);
+ break;
+ }
+
+ copy_v4_v4(r_col_hi, r_col);
+
+ r_col[3] = alpha * alpha_fac;
+ r_col_hi[3] = alpha_hi * alpha_fac;
+}
+
+static void manipulator_get_axis_constraint(const int axis_idx, int r_axis[3])
+{
+ zero_v3_int(r_axis);
+
+ switch (axis_idx) {
+ case MAN_AXIS_TRANS_X:
+ case MAN_AXIS_ROT_X:
+ case MAN_AXIS_SCALE_X:
+ r_axis[0] = 1;
+ break;
+ case MAN_AXIS_TRANS_Y:
+ case MAN_AXIS_ROT_Y:
+ case MAN_AXIS_SCALE_Y:
+ r_axis[1] = 1;
+ break;
+ case MAN_AXIS_TRANS_Z:
+ case MAN_AXIS_ROT_Z:
+ case MAN_AXIS_SCALE_Z:
+ r_axis[2] = 1;
+ break;
+ case MAN_AXIS_TRANS_XY:
+ case MAN_AXIS_SCALE_XY:
+ r_axis[0] = r_axis[1] = 1;
+ break;
+ case MAN_AXIS_TRANS_YZ:
+ case MAN_AXIS_SCALE_YZ:
+ r_axis[1] = r_axis[2] = 1;
+ break;
+ case MAN_AXIS_TRANS_ZX:
+ case MAN_AXIS_SCALE_ZX:
+ r_axis[2] = r_axis[0] = 1;
+ break;
+ default:
+ break;
+ }
+}
+
+
+/* **************** Preparation Stuff **************** */
+
+/* transform widget center calc helper for below */
+static void calc_tw_center(struct TransformBounds *tbounds, const float co[3])
+{
+ minmax_v3v3_v3(tbounds->min, tbounds->max, co);
+ add_v3_v3(tbounds->center, co);
+
+ for (int i = 0; i < 3; i++) {
+ const float d = dot_v3v3(tbounds->axis[i], co);
+ tbounds->axis_min[i] = min_ff(d, tbounds->axis_min[i]);
+ tbounds->axis_max[i] = max_ff(d, tbounds->axis_max[i]);
+ }
+}
+
+static void protectflag_to_drawflags(short protectflag, short *drawflags)
+{
+ if (protectflag & OB_LOCK_LOCX)
+ *drawflags &= ~MAN_TRANS_X;
+ if (protectflag & OB_LOCK_LOCY)
+ *drawflags &= ~MAN_TRANS_Y;
+ if (protectflag & OB_LOCK_LOCZ)
+ *drawflags &= ~MAN_TRANS_Z;
+
+ if (protectflag & OB_LOCK_ROTX)
+ *drawflags &= ~MAN_ROT_X;
+ if (protectflag & OB_LOCK_ROTY)
+ *drawflags &= ~MAN_ROT_Y;
+ if (protectflag & OB_LOCK_ROTZ)
+ *drawflags &= ~MAN_ROT_Z;
+
+ if (protectflag & OB_LOCK_SCALEX)
+ *drawflags &= ~MAN_SCALE_X;
+ if (protectflag & OB_LOCK_SCALEY)
+ *drawflags &= ~MAN_SCALE_Y;
+ if (protectflag & OB_LOCK_SCALEZ)
+ *drawflags &= ~MAN_SCALE_Z;
+}
+
+/* for pose mode */
+static void protectflag_to_drawflags_pchan(RegionView3D *rv3d, const bPoseChannel *pchan)
+{
+ protectflag_to_drawflags(pchan->protectflag, &rv3d->twdrawflag);
+}
+
+/* for editmode*/
+static void protectflag_to_drawflags_ebone(RegionView3D *rv3d, const EditBone *ebo)
+{
+ if (ebo->flag & BONE_EDITMODE_LOCKED) {
+ protectflag_to_drawflags(OB_LOCK_LOC | OB_LOCK_ROT | OB_LOCK_SCALE, &rv3d->twdrawflag);
+ }
+}
+
+/* could move into BLI_math however this is only useful for display/editing purposes */
+static void axis_angle_to_gimbal_axis(float gmat[3][3], const float axis[3], const float angle)
+{
+ /* X/Y are arbitrary axies, most importantly Z is the axis of rotation */
+
+ float cross_vec[3];
+ float quat[4];
+
+ /* this is an un-scientific method to get a vector to cross with
+ * XYZ intentionally YZX */
+ cross_vec[0] = axis[1];
+ cross_vec[1] = axis[2];
+ cross_vec[2] = axis[0];
+
+ /* X-axis */
+ cross_v3_v3v3(gmat[0], cross_vec, axis);
+ normalize_v3(gmat[0]);
+ axis_angle_to_quat(quat, axis, angle);
+ mul_qt_v3(quat, gmat[0]);
+
+ /* Y-axis */
+ axis_angle_to_quat(quat, axis, M_PI_2);
+ copy_v3_v3(gmat[1], gmat[0]);
+ mul_qt_v3(quat, gmat[1]);
+
+ /* Z-axis */
+ copy_v3_v3(gmat[2], axis);
+
+ normalize_m3(gmat);
+}
+
+
+static bool test_rotmode_euler(short rotmode)
+{
+ return (ELEM(rotmode, ROT_MODE_AXISANGLE, ROT_MODE_QUAT)) ? 0 : 1;
+}
+
+bool gimbal_axis(Object *ob, float gmat[3][3])
+{
+ if (ob->mode & OB_MODE_POSE) {
+ bPoseChannel *pchan = BKE_pose_channel_active(ob);
+
+ if (pchan) {
+ float mat[3][3], tmat[3][3], obmat[3][3];
+ if (test_rotmode_euler(pchan->rotmode)) {
+ eulO_to_gimbal_axis(mat, pchan->eul, pchan->rotmode);
+ }
+ else if (pchan->rotmode == ROT_MODE_AXISANGLE) {
+ axis_angle_to_gimbal_axis(mat, pchan->rotAxis, pchan->rotAngle);
+ }
+ else { /* quat */
+ return 0;
+ }
+
+
+ /* apply bone transformation */
+ mul_m3_m3m3(tmat, pchan->bone->bone_mat, mat);
+
+ if (pchan->parent) {
+ float parent_mat[3][3];
+
+ copy_m3_m4(parent_mat, pchan->parent->pose_mat);
+ mul_m3_m3m3(mat, parent_mat, tmat);
+
+ /* needed if object transformation isn't identity */
+ copy_m3_m4(obmat, ob->obmat);
+ mul_m3_m3m3(gmat, obmat, mat);
+ }
+ else {
+ /* needed if object transformation isn't identity */
+ copy_m3_m4(obmat, ob->obmat);
+ mul_m3_m3m3(gmat, obmat, tmat);
+ }
+
+ normalize_m3(gmat);
+ return 1;
+ }
+ }
+ else {
+ if (test_rotmode_euler(ob->rotmode)) {
+ eulO_to_gimbal_axis(gmat, ob->rot, ob->rotmode);
+ }
+ else if (ob->rotmode == ROT_MODE_AXISANGLE) {
+ axis_angle_to_gimbal_axis(gmat, ob->rotAxis, ob->rotAngle);
+ }
+ else { /* quat */
+ return 0;
+ }
+
+ if (ob->parent) {
+ float parent_mat[3][3];
+ copy_m3_m4(parent_mat, ob->parent->obmat);
+ normalize_m3(parent_mat);
+ mul_m3_m3m3(gmat, parent_mat, gmat);
+ }
+ return 1;
+ }
+
+ return 0;
+}
+
+
+/* centroid, boundbox, of selection */
+/* returns total items selected */
+int ED_transform_calc_manipulator_stats(
+ const bContext *C, bool use_only_center,
+ struct TransformBounds *tbounds)
+{
+ const Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *obedit = CTX_data_edit_object(C);
+ View3D *v3d = sa->spacedata.first;
+ RegionView3D *rv3d = ar->regiondata;
+ Base *base;
+ Object *ob = OBACT(view_layer);
+ const Object *ob_eval = NULL;
+ const Object *obedit_eval = NULL;
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ const bool is_gp_edit = ((gpd) && (gpd->flag & GP_DATA_STROKE_EDITMODE));
+ int a, totsel = 0;
+
+ /* transform widget matrix */
+ unit_m4(rv3d->twmat);
+
+ unit_m3(rv3d->tw_axis_matrix);
+ zero_v3(rv3d->tw_axis_min);
+ zero_v3(rv3d->tw_axis_max);
+
+ rv3d->twdrawflag = 0xFFFF;
+
+ ob_eval = DEG_get_evaluated_object(depsgraph, ob);
+ obedit_eval = DEG_get_evaluated_object(depsgraph, obedit);
+
+ /* global, local or normal orientation?
+ * if we could check 'totsel' now, this should be skipped with no selection. */
+ if (ob && !is_gp_edit) {
+
+ switch (scene->orientation_type) {
+
+ case V3D_MANIP_GLOBAL:
+ {
+ break; /* nothing to do */
+ }
+ case V3D_MANIP_GIMBAL:
+ {
+ float mat[3][3];
+ if (gimbal_axis(ob, mat)) {
+ copy_m4_m3(rv3d->twmat, mat);
+ break;
+ }
+ /* if not gimbal, fall through to normal */
+ ATTR_FALLTHROUGH;
+ }
+ case V3D_MANIP_NORMAL:
+ {
+ if (obedit || ob->mode & OB_MODE_POSE) {
+ float mat[3][3];
+ ED_getTransformOrientationMatrix(C, mat, v3d->around);
+ copy_m4_m3(rv3d->twmat, mat);
+ break;
+ }
+ /* no break we define 'normal' as 'local' in Object mode */
+ ATTR_FALLTHROUGH;
+ }
+ case V3D_MANIP_LOCAL:
+ {
+ if (ob->mode & OB_MODE_POSE) {
+ /* each bone moves on its own local axis, but to avoid confusion,
+ * use the active pones axis for display [#33575], this works as expected on a single bone
+ * and users who select many bones will understand whats going on and what local means
+ * when they start transforming */
+ float mat[3][3];
+ ED_getTransformOrientationMatrix(C, mat, v3d->around);
+ copy_m4_m3(rv3d->twmat, mat);
+ break;
+ }
+ copy_m4_m4(rv3d->twmat, ob_eval->obmat);
+ normalize_m4(rv3d->twmat);
+ break;
+ }
+ case V3D_MANIP_VIEW:
+ {
+ float mat[3][3];
+ copy_m3_m4(mat, rv3d->viewinv);
+ normalize_m3(mat);
+ copy_m4_m3(rv3d->twmat, mat);
+ break;
+ }
+ case V3D_MANIP_CUSTOM:
+ {
+ TransformOrientation *custom_orientation = BKE_scene_transform_orientation_find(
+ scene, scene->orientation_index_custom);
+ float mat[3][3];
+
+ if (applyTransformOrientation(custom_orientation, mat, NULL)) {
+ copy_m4_m3(rv3d->twmat, mat);
+ }
+ break;
+ }
+ }
+ }
+
+ /* transform widget centroid/center */
+ INIT_MINMAX(tbounds->min, tbounds->max);
+ zero_v3(tbounds->center);
+
+ copy_m3_m4(tbounds->axis, rv3d->twmat);
+ if (ob && ob->mode & OB_MODE_EDIT) {
+ float diff_mat[3][3];
+ copy_m3_m4(diff_mat, ob_eval->obmat);
+ normalize_m3(diff_mat);
+ invert_m3(diff_mat);
+ mul_m3_m3m3(tbounds->axis, tbounds->axis, diff_mat);
+ normalize_m3(tbounds->axis);
+ }
+
+ for (int i = 0; i < 3; i++) {
+ tbounds->axis_min[i] = +FLT_MAX;
+ tbounds->axis_max[i] = -FLT_MAX;
+ }
+
+ if (is_gp_edit) {
+ float diff_mat[4][4];
+ float fpt[3];
+
+ for (bGPDlayer *gpl = gpd->layers.first; gpl; gpl = gpl->next) {
+ /* only editable and visible layers are considered */
+ if (gpencil_layer_is_editable(gpl) && (gpl->actframe != NULL)) {
+
+ /* calculate difference matrix if parent object */
+ if (gpl->parent != NULL) {
+ ED_gpencil_parent_location(gpl, diff_mat);
+ }
+
+ for (bGPDstroke *gps = gpl->actframe->strokes.first; gps; gps = gps->next) {
+ /* skip strokes that are invalid for current view */
+ if (ED_gpencil_stroke_can_use(C, gps) == false) {
+ continue;
+ }
+
+ /* we're only interested in selected points here... */
+ if (gps->flag & GP_STROKE_SELECT) {
+ bGPDspoint *pt;
+ int i;
+
+ /* Change selection status of all points, then make the stroke match */
+ for (i = 0, pt = gps->points; i < gps->totpoints; i++, pt++) {
+ if (pt->flag & GP_SPOINT_SELECT) {
+ if (gpl->parent == NULL) {
+ calc_tw_center(tbounds, &pt->x);
+ totsel++;
+ }
+ else {
+ mul_v3_m4v3(fpt, diff_mat, &pt->x);
+ calc_tw_center(tbounds, fpt);
+ totsel++;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+
+ /* selection center */
+ if (totsel) {
+ mul_v3_fl(tbounds->center, 1.0f / (float)totsel); /* centroid! */
+ }
+ }
+ else if (obedit) {
+ ob = obedit;
+ ob_eval = obedit_eval;
+ if (obedit->type == OB_MESH) {
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMEditSelection ese;
+ float vec[3] = {0, 0, 0};
+
+ /* USE LAST SELECTE WITH ACTIVE */
+ if ((v3d->around == V3D_AROUND_ACTIVE) && BM_select_history_active_get(em->bm, &ese)) {
+ BM_editselection_center(&ese, vec);
+ calc_tw_center(tbounds, vec);
+ totsel = 1;
+ }
+ else {
+ BMesh *bm = em->bm;
+ BMVert *eve;
+
+ BMIter iter;
+
+ BM_ITER_MESH (eve, &iter, bm, BM_VERTS_OF_MESH) {
+ if (!BM_elem_flag_test(eve, BM_ELEM_HIDDEN)) {
+ if (BM_elem_flag_test(eve, BM_ELEM_SELECT)) {
+ totsel++;
+ calc_tw_center(tbounds, eve->co);
+ }
+ }
+ }
+ }
+ } /* end editmesh */
+ else if (obedit->type == OB_ARMATURE) {
+ bArmature *arm = obedit->data;
+ EditBone *ebo;
+
+ if ((v3d->around == V3D_AROUND_ACTIVE) && (ebo = arm->act_edbone)) {
+ /* doesn't check selection or visibility intentionally */
+ if (ebo->flag & BONE_TIPSEL) {
+ calc_tw_center(tbounds, ebo->tail);
+ totsel++;
+ }
+ if ((ebo->flag & BONE_ROOTSEL) ||
+ ((ebo->flag & BONE_TIPSEL) == false)) /* ensure we get at least one point */
+ {
+ calc_tw_center(tbounds, ebo->head);
+ totsel++;
+ }
+ protectflag_to_drawflags_ebone(rv3d, ebo);
+ }
+ else {
+ for (ebo = arm->edbo->first; ebo; ebo = ebo->next) {
+ if (EBONE_VISIBLE(arm, ebo)) {
+ if (ebo->flag & BONE_TIPSEL) {
+ calc_tw_center(tbounds, ebo->tail);
+ totsel++;
+ }
+ if ((ebo->flag & BONE_ROOTSEL) &&
+ /* don't include same point multiple times */
+ ((ebo->flag & BONE_CONNECTED) &&
+ (ebo->parent != NULL) &&
+ (ebo->parent->flag & BONE_TIPSEL) &&
+ EBONE_VISIBLE(arm, ebo->parent)) == 0)
+ {
+ calc_tw_center(tbounds, ebo->head);
+ totsel++;
+ }
+ if (ebo->flag & BONE_SELECTED) {
+ protectflag_to_drawflags_ebone(rv3d, ebo);
+ }
+ }
+ }
+ }
+ }
+ else if (ELEM(obedit->type, OB_CURVE, OB_SURF)) {
+ Curve *cu = obedit->data;
+ float center[3];
+
+ if (v3d->around == V3D_AROUND_ACTIVE && ED_curve_active_center(cu, center)) {
+ calc_tw_center(tbounds, center);
+ totsel++;
+ }
+ else {
+ Nurb *nu;
+ BezTriple *bezt;
+ BPoint *bp;
+ ListBase *nurbs = BKE_curve_editNurbs_get(cu);
+
+ nu = nurbs->first;
+ while (nu) {
+ if (nu->type == CU_BEZIER) {
+ bezt = nu->bezt;
+ a = nu->pntsu;
+ while (a--) {
+ /* exceptions
+ * if handles are hidden then only check the center points.
+ * If the center knot is selected then only use this as the center point.
+ */
+ if (cu->drawflag & CU_HIDE_HANDLES) {
+ if (bezt->f2 & SELECT) {
+ calc_tw_center(tbounds, bezt->vec[1]);
+ totsel++;
+ }
+ }
+ else if (bezt->f2 & SELECT) {
+ calc_tw_center(tbounds, bezt->vec[1]);
+ totsel++;
+ }
+ else {
+ if (bezt->f1 & SELECT) {
+ calc_tw_center(tbounds, bezt->vec[(v3d->around == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 0]);
+ totsel++;
+ }
+ if (bezt->f3 & SELECT) {
+ calc_tw_center(tbounds, bezt->vec[(v3d->around == V3D_AROUND_LOCAL_ORIGINS) ? 1 : 2]);
+ totsel++;
+ }
+ }
+ bezt++;
+ }
+ }
+ else {
+ bp = nu->bp;
+ a = nu->pntsu * nu->pntsv;
+ while (a--) {
+ if (bp->f1 & SELECT) {
+ calc_tw_center(tbounds, bp->vec);
+ totsel++;
+ }
+ bp++;
+ }
+ }
+ nu = nu->next;
+ }
+ }
+ }
+ else if (obedit->type == OB_MBALL) {
+ MetaBall *mb = (MetaBall *)obedit->data;
+ MetaElem *ml;
+
+ if ((v3d->around == V3D_AROUND_ACTIVE) && (ml = mb->lastelem)) {
+ calc_tw_center(tbounds, &ml->x);
+ totsel++;
+ }
+ else {
+ for (ml = mb->editelems->first; ml; ml = ml->next) {
+ if (ml->flag & SELECT) {
+ calc_tw_center(tbounds, &ml->x);
+ totsel++;
+ }
+ }
+ }
+ }
+ else if (obedit->type == OB_LATTICE) {
+ Lattice *lt = ((Lattice *)obedit->data)->editlatt->latt;
+ BPoint *bp;
+
+ if ((v3d->around == V3D_AROUND_ACTIVE) && (bp = BKE_lattice_active_point_get(lt))) {
+ calc_tw_center(tbounds, bp->vec);
+ totsel++;
+ }
+ else {
+ bp = lt->def;
+ a = lt->pntsu * lt->pntsv * lt->pntsw;
+ while (a--) {
+ if (bp->f1 & SELECT) {
+ calc_tw_center(tbounds, bp->vec);
+ totsel++;
+ }
+ bp++;
+ }
+ }
+ }
+
+ /* selection center */
+ if (totsel) {
+ mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid!
+ mul_m4_v3(obedit_eval->obmat, tbounds->center);
+ mul_m4_v3(obedit_eval->obmat, tbounds->min);
+ mul_m4_v3(obedit_eval->obmat, tbounds->max);
+ }
+ }
+ else if (ob && (ob->mode & OB_MODE_POSE)) {
+ bPoseChannel *pchan;
+ int mode = TFM_ROTATION; // mislead counting bones... bah. We don't know the manipulator mode, could be mixed
+ bool ok = false;
+
+ if ((v3d->around == V3D_AROUND_ACTIVE) && (pchan = BKE_pose_channel_active(ob))) {
+ /* doesn't check selection or visibility intentionally */
+ Bone *bone = pchan->bone;
+ if (bone) {
+ calc_tw_center(tbounds, pchan->pose_head);
+ protectflag_to_drawflags_pchan(rv3d, pchan);
+ totsel = 1;
+ ok = true;
+ }
+ }
+ else {
+ totsel = count_set_pose_transflags(&mode, 0, ob);
+
+ if (totsel) {
+ /* use channels to get stats */
+ for (pchan = ob->pose->chanbase.first; pchan; pchan = pchan->next) {
+ Bone *bone = pchan->bone;
+ if (bone && (bone->flag & BONE_TRANSFORM)) {
+ calc_tw_center(tbounds, pchan->pose_head);
+ protectflag_to_drawflags_pchan(rv3d, pchan);
+ }
+ }
+ ok = true;
+ }
+ }
+
+ if (ok) {
+ mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid!
+ mul_m4_v3(ob_eval->obmat, tbounds->center);
+ mul_m4_v3(ob_eval->obmat, tbounds->min);
+ mul_m4_v3(ob_eval->obmat, tbounds->max);
+ }
+ }
+ else if (ob && (ob->mode & OB_MODE_ALL_PAINT)) {
+ /* pass */
+ }
+ else if (ob && ob->mode & OB_MODE_PARTICLE_EDIT) {
+ PTCacheEdit *edit = PE_get_current(scene, ob);
+ PTCacheEditPoint *point;
+ PTCacheEditKey *ek;
+ int k;
+
+ if (edit) {
+ point = edit->points;
+ for (a = 0; a < edit->totpoint; a++, point++) {
+ if (point->flag & PEP_HIDE) continue;
+
+ for (k = 0, ek = point->keys; k < point->totkey; k++, ek++) {
+ if (ek->flag & PEK_SELECT) {
+ calc_tw_center(tbounds, (ek->flag & PEK_USE_WCO) ? ek->world_co : ek->co);
+ totsel++;
+ }
+ }
+ }
+
+ /* selection center */
+ if (totsel)
+ mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid!
+ }
+ }
+ else {
+
+ /* we need the one selected object, if its not active */
+ base = BASACT(view_layer);
+ ob = OBACT(view_layer);
+ if (base && ((base->flag & BASE_SELECTED) == 0)) ob = NULL;
+
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ if (!TESTBASELIB(base)) {
+ continue;
+ }
+ const Object *base_object_eval = DEG_get_evaluated_object(depsgraph, base->object);
+ if (ob == NULL) {
+ ob = base->object;
+ ob_eval = base_object_eval;
+ }
+ if (use_only_center || base_object_eval->bb == NULL) {
+ calc_tw_center(tbounds, base_object_eval->obmat[3]);
+ }
+ else {
+ for (uint j = 0; j < 8; j++) {
+ float co[3];
+ mul_v3_m4v3(co, base_object_eval->obmat, base_object_eval->bb->vec[j]);
+ calc_tw_center(tbounds, co);
+ }
+ }
+ protectflag_to_drawflags(base->object->protectflag, &rv3d->twdrawflag);
+ totsel++;
+ }
+
+ /* selection center */
+ if (totsel) {
+ mul_v3_fl(tbounds->center, 1.0f / (float)totsel); // centroid!
+ }
+ }
+
+ if (totsel == 0) {
+ unit_m4(rv3d->twmat);
+ }
+ else {
+ copy_v3_v3(rv3d->tw_axis_min, tbounds->axis_min);
+ copy_v3_v3(rv3d->tw_axis_max, tbounds->axis_max);
+ copy_m3_m3(rv3d->tw_axis_matrix, tbounds->axis);
+ }
+
+ return totsel;
+}
+
+static void manipulator_get_idot(RegionView3D *rv3d, float r_idot[3])
+{
+ float view_vec[3], axis_vec[3];
+ ED_view3d_global_to_vector(rv3d, rv3d->twmat[3], view_vec);
+ for (int i = 0; i < 3; i++) {
+ normalize_v3_v3(axis_vec, rv3d->twmat[i]);
+ r_idot[i] = 1.0f - fabsf(dot_v3v3(view_vec, axis_vec));
+ }
+}
+
+static void manipulator_prepare_mat(
+ const bContext *C, View3D *v3d, RegionView3D *rv3d, const struct TransformBounds *tbounds)
+{
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+
+ switch (v3d->around) {
+ case V3D_AROUND_CENTER_BOUNDS:
+ case V3D_AROUND_ACTIVE:
+ {
+ bGPdata *gpd = CTX_data_gpencil_data(C);
+ Object *ob = OBACT(view_layer);
+
+ if (((v3d->around == V3D_AROUND_ACTIVE) && (OBEDIT_FROM_OBACT(ob) == NULL)) &&
+ ((gpd == NULL) || !(gpd->flag & GP_DATA_STROKE_EDITMODE)) &&
+ (!(ob->mode & OB_MODE_POSE)))
+ {
+ copy_v3_v3(rv3d->twmat[3], ob->obmat[3]);
+ }
+ else {
+ mid_v3_v3v3(rv3d->twmat[3], tbounds->min, tbounds->max);
+ }
+ break;
+ }
+ case V3D_AROUND_LOCAL_ORIGINS:
+ case V3D_AROUND_CENTER_MEAN:
+ copy_v3_v3(rv3d->twmat[3], tbounds->center);
+ break;
+ case V3D_AROUND_CURSOR:
+ copy_v3_v3(rv3d->twmat[3], ED_view3d_cursor3d_get(scene, v3d));
+ break;
+ }
+}
+
+/**
+ * Sets up \a r_start and \a r_len to define arrow line range.
+ * Needed to adjust line drawing for combined manipulator axis types.
+ */
+static void manipulator_line_range(const int twtype, const short axis_type, float *r_start, float *r_len)
+{
+ const float ofs = 0.2f;
+
+ *r_start = 0.2f;
+ *r_len = 1.0f;
+
+ switch (axis_type) {
+ case MAN_AXES_TRANSLATE:
+ if (twtype & V3D_MANIP_SCALE) {
+ *r_start = *r_len - ofs + 0.075f;
+ }
+ if (twtype & V3D_MANIP_ROTATE) {
+ *r_len += ofs;
+ }
+ break;
+ case MAN_AXES_SCALE:
+ if (twtype & (V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE)) {
+ *r_len -= ofs + 0.025f;
+ }
+ break;
+ }
+
+ *r_len -= *r_start;
+}
+
+static void manipulator_xform_message_subscribe(
+ wmManipulatorGroup *mgroup, struct wmMsgBus *mbus,
+ Scene *scene, bScreen *screen, ScrArea *sa, ARegion *ar, const void *type_fn)
+{
+ /* Subscribe to view properties */
+ wmMsgSubscribeValue msg_sub_value_mpr_tag_refresh = {
+ .owner = ar,
+ .user_data = mgroup->parent_mmap,
+ .notify = WM_manipulator_do_msg_notify_tag_refresh,
+ };
+
+ PointerRNA scene_ptr;
+ RNA_id_pointer_create(&scene->id, &scene_ptr);
+
+ {
+ const View3D *v3d = sa->spacedata.first;
+ extern PropertyRNA rna_Scene_transform_orientation;
+ extern PropertyRNA rna_Scene_cursor_location;
+ const PropertyRNA *props[] = {
+ &rna_Scene_transform_orientation,
+ (v3d->around == V3D_AROUND_CURSOR) ? &rna_Scene_cursor_location : NULL,
+ };
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ if (props[i]) {
+ WM_msg_subscribe_rna(mbus, &scene_ptr, props[i], &msg_sub_value_mpr_tag_refresh, __func__);
+ }
+ }
+ }
+
+ PointerRNA space_ptr;
+ RNA_pointer_create(&screen->id, &RNA_SpaceView3D, sa->spacedata.first, &space_ptr);
+
+ if (type_fn == TRANSFORM_WGT_manipulator) {
+ extern PropertyRNA rna_SpaceView3D_pivot_point;
+ const PropertyRNA *props[] = {
+ &rna_SpaceView3D_pivot_point
+ };
+ for (int i = 0; i < ARRAY_SIZE(props); i++) {
+ WM_msg_subscribe_rna(mbus, &space_ptr, props[i], &msg_sub_value_mpr_tag_refresh, __func__);
+ }
+ }
+ else if (type_fn == VIEW3D_WGT_xform_cage) {
+ /* pass */
+ }
+ else {
+ BLI_assert(0);
+ }
+
+ WM_msg_subscribe_rna_anon_prop(mbus, Window, view_layer, &msg_sub_value_mpr_tag_refresh);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Transform Manipulator
+ * \{ */
+
+static ManipulatorGroup *manipulatorgroup_init(wmManipulatorGroup *mgroup)
+{
+ ManipulatorGroup *man;
+
+ man = MEM_callocN(sizeof(ManipulatorGroup), "manipulator_data");
+
+ const wmManipulatorType *wt_arrow = WM_manipulatortype_find("MANIPULATOR_WT_arrow_3d", true);
+ const wmManipulatorType *wt_dial = WM_manipulatortype_find("MANIPULATOR_WT_dial_3d", true);
+ const wmManipulatorType *wt_prim = WM_manipulatortype_find("MANIPULATOR_WT_primitive_3d", true);
+
+#define MANIPULATOR_NEW_ARROW(v, draw_style) { \
+ man->manipulators[v] = WM_manipulator_new_ptr(wt_arrow, mgroup, NULL); \
+ RNA_enum_set(man->manipulators[v]->ptr, "draw_style", draw_style); \
+} ((void)0)
+#define MANIPULATOR_NEW_DIAL(v, draw_options) { \
+ man->manipulators[v] = WM_manipulator_new_ptr(wt_dial, mgroup, NULL); \
+ RNA_enum_set(man->manipulators[v]->ptr, "draw_options", draw_options); \
+} ((void)0)
+#define MANIPULATOR_NEW_PRIM(v, draw_style) { \
+ man->manipulators[v] = WM_manipulator_new_ptr(wt_prim, mgroup, NULL); \
+ RNA_enum_set(man->manipulators[v]->ptr, "draw_style", draw_style); \
+} ((void)0)
+
+ /* add/init widgets - order matters! */
+ MANIPULATOR_NEW_DIAL(MAN_AXIS_ROT_T, ED_MANIPULATOR_DIAL_DRAW_FLAG_FILL);
+
+ MANIPULATOR_NEW_DIAL(MAN_AXIS_SCALE_C, ED_MANIPULATOR_DIAL_DRAW_FLAG_NOP);
+
+ MANIPULATOR_NEW_ARROW(MAN_AXIS_SCALE_X, ED_MANIPULATOR_ARROW_STYLE_BOX);
+ MANIPULATOR_NEW_ARROW(MAN_AXIS_SCALE_Y, ED_MANIPULATOR_ARROW_STYLE_BOX);
+ MANIPULATOR_NEW_ARROW(MAN_AXIS_SCALE_Z, ED_MANIPULATOR_ARROW_STYLE_BOX);
+
+ MANIPULATOR_NEW_PRIM(MAN_AXIS_SCALE_XY, ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE);
+ MANIPULATOR_NEW_PRIM(MAN_AXIS_SCALE_YZ, ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE);
+ MANIPULATOR_NEW_PRIM(MAN_AXIS_SCALE_ZX, ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE);
+
+ MANIPULATOR_NEW_DIAL(MAN_AXIS_ROT_X, ED_MANIPULATOR_DIAL_DRAW_FLAG_CLIP);
+ MANIPULATOR_NEW_DIAL(MAN_AXIS_ROT_Y, ED_MANIPULATOR_DIAL_DRAW_FLAG_CLIP);
+ MANIPULATOR_NEW_DIAL(MAN_AXIS_ROT_Z, ED_MANIPULATOR_DIAL_DRAW_FLAG_CLIP);
+
+ /* init screen aligned widget last here, looks better, behaves better */
+ MANIPULATOR_NEW_DIAL(MAN_AXIS_ROT_C, ED_MANIPULATOR_DIAL_DRAW_FLAG_NOP);
+
+ MANIPULATOR_NEW_DIAL(MAN_AXIS_TRANS_C, ED_MANIPULATOR_DIAL_DRAW_FLAG_NOP);
+
+ MANIPULATOR_NEW_ARROW(MAN_AXIS_TRANS_X, ED_MANIPULATOR_ARROW_STYLE_NORMAL);
+ MANIPULATOR_NEW_ARROW(MAN_AXIS_TRANS_Y, ED_MANIPULATOR_ARROW_STYLE_NORMAL);
+ MANIPULATOR_NEW_ARROW(MAN_AXIS_TRANS_Z, ED_MANIPULATOR_ARROW_STYLE_NORMAL);
+
+ MANIPULATOR_NEW_PRIM(MAN_AXIS_TRANS_XY, ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE);
+ MANIPULATOR_NEW_PRIM(MAN_AXIS_TRANS_YZ, ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE);
+ MANIPULATOR_NEW_PRIM(MAN_AXIS_TRANS_ZX, ED_MANIPULATOR_PRIMITIVE_STYLE_PLANE);
+
+ return man;
+}
+
+/**
+ * Custom handler for manipulator widgets
+ */
+static int manipulator_modal(
+ bContext *C, wmManipulator *widget, const wmEvent *UNUSED(event),
+ eWM_ManipulatorTweak UNUSED(tweak_flag))
+{
+ const ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ View3D *v3d = sa->spacedata.first;
+ RegionView3D *rv3d = ar->regiondata;
+ struct TransformBounds tbounds;
+
+
+ if (ED_transform_calc_manipulator_stats(C, true, &tbounds)) {
+ manipulator_prepare_mat(C, v3d, rv3d, &tbounds);
+ WM_manipulator_set_matrix_location(widget, rv3d->twmat[3]);
+ }
+
+ ED_region_tag_redraw(ar);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+static void WIDGETGROUP_manipulator_setup(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ManipulatorGroup *man = manipulatorgroup_init(mgroup);
+ struct {
+ wmOperatorType *translate, *rotate, *trackball, *resize;
+ } ot_store = {NULL};
+
+ mgroup->customdata = man;
+
+ {
+ /* TODO: support mixing modes again? - it's supported but tool system makes it unobvious. */
+ man->twtype = 0;
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ ScrArea *sa = CTX_wm_area(C);
+ wmKeyMap *km = WM_keymap_find_all(C, workspace->tool.keymap, sa->spacetype, RGN_TYPE_WINDOW);
+ /* Weak, check first event */
+ wmKeyMapItem *kmi = km ? km->items.first : NULL;
+
+ if (kmi == NULL) {
+ man->twtype |= V3D_MANIP_TRANSLATE | V3D_MANIP_ROTATE | V3D_MANIP_SCALE;
+ }
+ else if (STREQ(kmi->idname, "TRANSFORM_OT_translate")) {
+ man->twtype |= V3D_MANIP_TRANSLATE;
+ }
+ else if (STREQ(kmi->idname, "TRANSFORM_OT_rotate")) {
+ man->twtype |= V3D_MANIP_ROTATE;
+ }
+ else if (STREQ(kmi->idname, "TRANSFORM_OT_resize")) {
+ man->twtype |= V3D_MANIP_SCALE;
+ }
+ BLI_assert(man->twtype != 0);
+ }
+
+ /* *** set properties for axes *** */
+
+ MAN_ITER_AXES_BEGIN(axis, axis_idx)
+ {
+ const short axis_type = manipulator_get_axis_type(axis_idx);
+ int constraint_axis[3] = {1, 0, 0};
+ PointerRNA *ptr;
+
+ manipulator_get_axis_constraint(axis_idx, constraint_axis);
+
+ /* custom handler! */
+ WM_manipulator_set_fn_custom_modal(axis, manipulator_modal);
+
+ switch (axis_idx) {
+ case MAN_AXIS_TRANS_X:
+ case MAN_AXIS_TRANS_Y:
+ case MAN_AXIS_TRANS_Z:
+ case MAN_AXIS_SCALE_X:
+ case MAN_AXIS_SCALE_Y:
+ case MAN_AXIS_SCALE_Z:
+ WM_manipulator_set_line_width(axis, MANIPULATOR_AXIS_LINE_WIDTH);
+ break;
+ case MAN_AXIS_ROT_X:
+ case MAN_AXIS_ROT_Y:
+ case MAN_AXIS_ROT_Z:
+ /* increased line width for better display */
+ WM_manipulator_set_line_width(axis, MANIPULATOR_AXIS_LINE_WIDTH + 1.0f);
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_DRAW_VALUE, true);
+ break;
+ case MAN_AXIS_TRANS_XY:
+ case MAN_AXIS_TRANS_YZ:
+ case MAN_AXIS_TRANS_ZX:
+ case MAN_AXIS_SCALE_XY:
+ case MAN_AXIS_SCALE_YZ:
+ case MAN_AXIS_SCALE_ZX:
+ {
+ const float ofs_ax = 7.0f;
+ const float ofs[3] = {ofs_ax, ofs_ax, 0.0f};
+ WM_manipulator_set_scale(axis, 0.07f);
+ WM_manipulator_set_matrix_offset_location(axis, ofs);
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_DRAW_OFFSET_SCALE, true);
+ break;
+ }
+ case MAN_AXIS_TRANS_C:
+ case MAN_AXIS_ROT_C:
+ case MAN_AXIS_SCALE_C:
+ case MAN_AXIS_ROT_T:
+ WM_manipulator_set_line_width(axis, MANIPULATOR_AXIS_LINE_WIDTH);
+ if (axis_idx == MAN_AXIS_ROT_T) {
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_DRAW_HOVER, true);
+ }
+ else if (axis_idx == MAN_AXIS_ROT_C) {
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_DRAW_VALUE, true);
+ }
+ else {
+ WM_manipulator_set_scale(axis, 0.2f);
+ }
+ break;
+ }
+
+ switch (axis_type) {
+ case MAN_AXES_TRANSLATE:
+ if (ot_store.translate == NULL) {
+ ot_store.translate = WM_operatortype_find("TRANSFORM_OT_translate", true);
+ }
+ ptr = WM_manipulator_operator_set(axis, 0, ot_store.translate, NULL);
+ break;
+ case MAN_AXES_ROTATE:
+ {
+ wmOperatorType *ot_rotate;
+ if (axis_idx == MAN_AXIS_ROT_T) {
+ if (ot_store.trackball == NULL) {
+ ot_store.trackball = WM_operatortype_find("TRANSFORM_OT_trackball", true);
+ }
+ ot_rotate = ot_store.trackball;
+ }
+ else {
+ if (ot_store.rotate == NULL) {
+ ot_store.rotate = WM_operatortype_find("TRANSFORM_OT_rotate", true);
+ }
+ ot_rotate = ot_store.rotate;
+ }
+ ptr = WM_manipulator_operator_set(axis, 0, ot_rotate, NULL);
+ break;
+ }
+ case MAN_AXES_SCALE:
+ {
+ if (ot_store.resize == NULL) {
+ ot_store.resize = WM_operatortype_find("TRANSFORM_OT_resize", true);
+ }
+ ptr = WM_manipulator_operator_set(axis, 0, ot_store.resize, NULL);
+ break;
+ }
+ }
+
+ {
+ PropertyRNA *prop;
+ if ((prop = RNA_struct_find_property(ptr, "constraint_axis"))) {
+ RNA_property_boolean_set_array(ptr, prop, constraint_axis);
+ }
+ }
+
+ RNA_boolean_set(ptr, "release_confirm", 1);
+ }
+ MAN_ITER_AXES_END;
+}
+
+static void WIDGETGROUP_manipulator_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ManipulatorGroup *man = mgroup->customdata;
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ View3D *v3d = sa->spacedata.first;
+ RegionView3D *rv3d = ar->regiondata;
+ struct TransformBounds tbounds;
+
+ /* skip, we don't draw anything anyway */
+ if ((man->all_hidden = (ED_transform_calc_manipulator_stats(C, true, &tbounds) == 0)))
+ return;
+
+ manipulator_prepare_mat(C, v3d, rv3d, &tbounds);
+
+ /* *** set properties for axes *** */
+
+ MAN_ITER_AXES_BEGIN(axis, axis_idx)
+ {
+ const short axis_type = manipulator_get_axis_type(axis_idx);
+ const int aidx_norm = manipulator_orientation_axis(axis_idx, NULL);
+
+ WM_manipulator_set_matrix_location(axis, rv3d->twmat[3]);
+
+ switch (axis_idx) {
+ case MAN_AXIS_TRANS_X:
+ case MAN_AXIS_TRANS_Y:
+ case MAN_AXIS_TRANS_Z:
+ case MAN_AXIS_SCALE_X:
+ case MAN_AXIS_SCALE_Y:
+ case MAN_AXIS_SCALE_Z:
+ {
+ float start_co[3] = {0.0f, 0.0f, 0.0f};
+ float len;
+
+ manipulator_line_range(man->twtype, axis_type, &start_co[2], &len);
+
+ WM_manipulator_set_matrix_rotation_from_z_axis(axis, rv3d->twmat[aidx_norm]);
+ RNA_float_set(axis->ptr, "length", len);
+ WM_manipulator_set_matrix_offset_location(axis, start_co);
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_DRAW_OFFSET_SCALE, true);
+ break;
+ }
+ case MAN_AXIS_ROT_X:
+ case MAN_AXIS_ROT_Y:
+ case MAN_AXIS_ROT_Z:
+ WM_manipulator_set_matrix_rotation_from_z_axis(axis, rv3d->twmat[aidx_norm]);
+ break;
+ case MAN_AXIS_TRANS_XY:
+ case MAN_AXIS_TRANS_YZ:
+ case MAN_AXIS_TRANS_ZX:
+ case MAN_AXIS_SCALE_XY:
+ case MAN_AXIS_SCALE_YZ:
+ case MAN_AXIS_SCALE_ZX:
+ {
+ const float *y_axis = rv3d->twmat[aidx_norm - 1 < 0 ? 2 : aidx_norm - 1];
+ const float *z_axis = rv3d->twmat[aidx_norm];
+ WM_manipulator_set_matrix_rotation_from_yz_axis(axis, y_axis, z_axis);
+ break;
+ }
+ }
+ }
+ MAN_ITER_AXES_END;
+}
+
+static void WIDGETGROUP_manipulator_message_subscribe(
+ const bContext *C, wmManipulatorGroup *mgroup, struct wmMsgBus *mbus)
+{
+ Scene *scene = CTX_data_scene(C);
+ bScreen *screen = CTX_wm_screen(C);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ manipulator_xform_message_subscribe(mgroup, mbus, scene, screen, sa, ar, TRANSFORM_WGT_manipulator);
+}
+
+static void WIDGETGROUP_manipulator_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ManipulatorGroup *man = mgroup->customdata;
+ // ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ // View3D *v3d = sa->spacedata.first;
+ RegionView3D *rv3d = ar->regiondata;
+ float idot[3];
+
+ /* when looking through a selected camera, the manipulator can be at the
+ * exact same position as the view, skip so we don't break selection */
+ if (man->all_hidden || fabsf(ED_view3d_pixel_size(rv3d, rv3d->twmat[3])) < 1e-6f) {
+ MAN_ITER_AXES_BEGIN(axis, axis_idx)
+ {
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_HIDDEN, true);
+ }
+ MAN_ITER_AXES_END;
+ return;
+ }
+ manipulator_get_idot(rv3d, idot);
+
+ /* *** set properties for axes *** */
+
+ MAN_ITER_AXES_BEGIN(axis, axis_idx)
+ {
+ const short axis_type = manipulator_get_axis_type(axis_idx);
+ /* XXX maybe unset _HIDDEN flag on redraw? */
+ if (manipulator_is_axis_visible(rv3d, man->twtype, idot, axis_type, axis_idx)) {
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_HIDDEN, false);
+ }
+ else {
+ WM_manipulator_set_flag(axis, WM_MANIPULATOR_HIDDEN, true);
+ continue;
+ }
+
+ float color[4], color_hi[4];
+ manipulator_get_axis_color(axis_idx, idot, color, color_hi);
+ WM_manipulator_set_color(axis, color);
+ WM_manipulator_set_color_highlight(axis, color_hi);
+
+ switch (axis_idx) {
+ case MAN_AXIS_TRANS_C:
+ case MAN_AXIS_ROT_C:
+ case MAN_AXIS_SCALE_C:
+ case MAN_AXIS_ROT_T:
+ WM_manipulator_set_matrix_rotation_from_z_axis(axis, rv3d->viewinv[2]);
+ break;
+ }
+ }
+ MAN_ITER_AXES_END;
+}
+
+static bool WIDGETGROUP_manipulator_poll(const struct bContext *C, struct wmManipulatorGroupType *wgt)
+{
+ /* it's a given we only use this in 3D view */
+ ScrArea *sa = CTX_wm_area(C);
+ View3D *v3d = sa->spacedata.first;
+ if (v3d && ((v3d->twflag & V3D_MANIPULATOR_DRAW)) == 0) {
+ return false;
+ }
+
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ if (!STREQ(workspace->tool.manipulator_group, "TRANSFORM_WGT_manipulator")) {
+ WM_manipulator_group_type_unlink_delayed_ptr(wgt);
+ return false;
+ }
+ return true;
+}
+
+void TRANSFORM_WGT_manipulator(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Transform Manipulator";
+ wgt->idname = "TRANSFORM_WGT_manipulator";
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_3D;
+
+ wgt->mmap_params.spaceid = SPACE_VIEW3D;
+ wgt->mmap_params.regionid = RGN_TYPE_WINDOW;
+
+ wgt->poll = WIDGETGROUP_manipulator_poll;
+ wgt->setup = WIDGETGROUP_manipulator_setup;
+ wgt->refresh = WIDGETGROUP_manipulator_refresh;
+ wgt->message_subscribe = WIDGETGROUP_manipulator_message_subscribe;
+ wgt->draw_prepare = WIDGETGROUP_manipulator_draw_prepare;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Scale Cage Manipulator
+ * \{ */
+
+struct XFormCageWidgetGroup {
+ wmManipulator *manipulator;
+};
+
+static bool WIDGETGROUP_xform_cage_poll(const bContext *C, wmManipulatorGroupType *wgt)
+{
+ ScrArea *sa = CTX_wm_area(C);
+ View3D *v3d = sa->spacedata.first;
+ if (v3d && ((v3d->twflag & V3D_MANIPULATOR_DRAW)) == 0) {
+ return false;
+ }
+
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ if (!STREQ(wgt->idname, workspace->tool.manipulator_group)) {
+ WM_manipulator_group_type_unlink_delayed_ptr(wgt);
+ return false;
+ }
+ return true;
+}
+
+static void WIDGETGROUP_xform_cage_setup(const bContext *UNUSED(C), wmManipulatorGroup *mgroup)
+{
+ struct XFormCageWidgetGroup *xmgroup = MEM_mallocN(sizeof(struct XFormCageWidgetGroup), __func__);
+ const wmManipulatorType *wt_cage = WM_manipulatortype_find("MANIPULATOR_WT_cage_3d", true);
+ xmgroup->manipulator = WM_manipulator_new_ptr(wt_cage, mgroup, NULL);
+ wmManipulator *mpr = xmgroup->manipulator;
+
+ RNA_enum_set(mpr->ptr, "transform",
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_SCALE |
+ ED_MANIPULATOR_CAGE2D_XFORM_FLAG_TRANSLATE);
+
+ mpr->color[0] = 1;
+ mpr->color_hi[0] = 1;
+
+ mgroup->customdata = xmgroup;
+
+ {
+ wmOperatorType *ot_resize = WM_operatortype_find("TRANSFORM_OT_resize", true);
+ PointerRNA *ptr;
+
+ /* assign operator */
+ PropertyRNA *prop_release_confirm = NULL;
+ PropertyRNA *prop_constraint_axis = NULL;
+
+ int i = ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z;
+ for (int x = 0; x < 3; x++) {
+ for (int y = 0; y < 3; y++) {
+ for (int z = 0; z < 3; z++) {
+ int constraint[3] = {x != 1, y != 1, z != 1};
+ ptr = WM_manipulator_operator_set(mpr, i, ot_resize, NULL);
+ if (prop_release_confirm == NULL) {
+ prop_release_confirm = RNA_struct_find_property(ptr, "release_confirm");
+ prop_constraint_axis = RNA_struct_find_property(ptr, "constraint_axis");
+ }
+ RNA_property_boolean_set(ptr, prop_release_confirm, true);
+ RNA_property_boolean_set_array(ptr, prop_constraint_axis, constraint);
+ i++;
+ }
+ }
+ }
+ }
+}
+
+static void WIDGETGROUP_xform_cage_refresh(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ ScrArea *sa = CTX_wm_area(C);
+ View3D *v3d = sa->spacedata.first;
+ ARegion *ar = CTX_wm_region(C);
+ RegionView3D *rv3d = ar->regiondata;
+
+ struct XFormCageWidgetGroup *xmgroup = mgroup->customdata;
+ wmManipulator *mpr = xmgroup->manipulator;
+
+ struct TransformBounds tbounds;
+
+ if ((ED_transform_calc_manipulator_stats(C, false, &tbounds) == 0) ||
+ equals_v3v3(rv3d->tw_axis_min, rv3d->tw_axis_max))
+ {
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, true);
+ }
+ else {
+ manipulator_prepare_mat(C, v3d, rv3d, &tbounds);
+
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_HIDDEN, false);
+ WM_manipulator_set_flag(mpr, WM_MANIPULATOR_GRAB_CURSOR, true);
+
+ float dims[3];
+ sub_v3_v3v3(dims, rv3d->tw_axis_max, rv3d->tw_axis_min);
+ RNA_float_set_array(mpr->ptr, "dimensions", dims);
+ mul_v3_fl(dims, 0.5f);
+
+ copy_m4_m3(mpr->matrix_offset, rv3d->tw_axis_matrix);
+ mid_v3_v3v3(mpr->matrix_offset[3], rv3d->tw_axis_max, rv3d->tw_axis_min);
+ mul_m3_v3(rv3d->tw_axis_matrix, mpr->matrix_offset[3]);
+
+ PropertyRNA *prop_center_override = NULL;
+ float center[3];
+ float center_global[3];
+ int i = ED_MANIPULATOR_CAGE3D_PART_SCALE_MIN_X_MIN_Y_MIN_Z;
+ for (int x = 0; x < 3; x++) {
+ center[0] = (float)(1 - x) * dims[0];
+ for (int y = 0; y < 3; y++) {
+ center[1] = (float)(1 - y) * dims[1];
+ for (int z = 0; z < 3; z++) {
+ center[2] = (float)(1 - z) * dims[2];
+ struct wmManipulatorOpElem *mpop = WM_manipulator_operator_get(mpr, i);
+ if (prop_center_override == NULL) {
+ prop_center_override = RNA_struct_find_property(&mpop->ptr, "center_override");
+ }
+ mul_v3_m4v3(center_global, mpr->matrix_offset, center);
+ RNA_property_float_set_array(&mpop->ptr, prop_center_override, center_global);
+ i++;
+ }
+ }
+ }
+ }
+}
+
+static void WIDGETGROUP_xform_cage_message_subscribe(
+ const bContext *C, wmManipulatorGroup *mgroup, struct wmMsgBus *mbus)
+{
+ Scene *scene = CTX_data_scene(C);
+ bScreen *screen = CTX_wm_screen(C);
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ manipulator_xform_message_subscribe(mgroup, mbus, scene, screen, sa, ar, VIEW3D_WGT_xform_cage);
+}
+
+static void WIDGETGROUP_xform_cage_draw_prepare(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ struct XFormCageWidgetGroup *xmgroup = mgroup->customdata;
+ wmManipulator *mpr = xmgroup->manipulator;
+
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+ if (ob && ob->mode & OB_MODE_EDIT) {
+ copy_m4_m4(mpr->matrix_space, ob->obmat);
+ }
+ else {
+ unit_m4(mpr->matrix_space);
+ }
+}
+
+void VIEW3D_WGT_xform_cage(wmManipulatorGroupType *wgt)
+{
+ wgt->name = "Transform Cage";
+ wgt->idname = "VIEW3D_WGT_xform_cage";
+
+ wgt->flag |= WM_MANIPULATORGROUPTYPE_3D;
+
+ wgt->mmap_params.spaceid = SPACE_VIEW3D;
+ wgt->mmap_params.regionid = RGN_TYPE_WINDOW;
+
+ wgt->poll = WIDGETGROUP_xform_cage_poll;
+ wgt->setup = WIDGETGROUP_xform_cage_setup;
+ wgt->refresh = WIDGETGROUP_xform_cage_refresh;
+ wgt->message_subscribe = WIDGETGROUP_xform_cage_message_subscribe;
+ wgt->draw_prepare = WIDGETGROUP_xform_cage_draw_prepare;
+}
+
+/** \} */
diff --git a/source/blender/editors/transform/transform_ops.c b/source/blender/editors/transform/transform_ops.c
index 46bd83b5d35..870c0e36a3b 100644
--- a/source/blender/editors/transform/transform_ops.c
+++ b/source/blender/editors/transform/transform_ops.c
@@ -160,11 +160,12 @@ const EnumPropertyItem rna_enum_transform_mode_types[] =
static int select_orientation_exec(bContext *C, wmOperator *op)
{
+ Scene *scene = CTX_data_scene(C);
int orientation = RNA_enum_get(op->ptr, "orientation");
- BIF_selectTransformOrientationValue(C, orientation);
-
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, CTX_wm_view3d(C));
+ BIF_selectTransformOrientationValue(scene, orientation);
+
+ WM_event_add_notifier(C, NC_SCENE | ND_TOOLSETTINGS, NULL);
return OPERATOR_FINISHED;
}
@@ -205,13 +206,10 @@ static void TRANSFORM_OT_select_orientation(struct wmOperatorType *ot)
static int delete_orientation_exec(bContext *C, wmOperator *UNUSED(op))
{
- View3D *v3d = CTX_wm_view3d(C);
- int selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
+ Scene *scene = CTX_data_scene(C);
+ BIF_removeTransformOrientationIndex(C, scene->orientation_index_custom);
- BIF_removeTransformOrientationIndex(C, selected_index);
-
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_VIEW3D, v3d);
- WM_event_add_notifier(C, NC_SCENE | NA_EDITED, CTX_data_scene(C));
+ WM_event_add_notifier(C, NC_SCENE | NA_EDITED, scene);
return OPERATOR_FINISHED;
}
@@ -223,18 +221,12 @@ static int delete_orientation_invoke(bContext *C, wmOperator *op, const wmEvent
static int delete_orientation_poll(bContext *C)
{
- int selected_index = -1;
- View3D *v3d = CTX_wm_view3d(C);
-
+ Scene *scene = CTX_data_scene(C);
+
if (ED_operator_areaactive(C) == 0)
return 0;
-
-
- if (v3d) {
- selected_index = (v3d->twmode - V3D_MANIP_CUSTOM);
- }
-
- return selected_index >= 0;
+
+ return (scene->orientation_type >= V3D_MANIP_CUSTOM) && (scene->orientation_index_custom != -1);
}
static void TRANSFORM_OT_delete_orientation(struct wmOperatorType *ot)
@@ -289,6 +281,9 @@ static void TRANSFORM_OT_create_orientation(struct wmOperatorType *ot)
RNA_def_string(ot->srna, "name", NULL, MAX_NAME, "Name", "Name of the new custom orientation");
RNA_def_boolean(ot->srna, "use_view", false, "Use View",
"Use the current view instead of the active object to create the new orientation");
+
+ WM_operatortype_props_advanced_begin(ot);
+
RNA_def_boolean(ot->srna, "use", false, "Use after creation", "Select orientation after its creation");
RNA_def_boolean(ot->srna, "overwrite", false, "Overwrite previous",
"Overwrite previously created orientation with same name");
@@ -319,7 +314,8 @@ static void transformops_loopsel_hack(bContext *C, wmOperator *op)
/* still switch if we were originally in face select mode */
if ((ts->selectmode != selectmode_orig) && (selectmode_orig != SCE_SELECT_FACE)) {
- BMEditMesh *em = BKE_editmesh_from_object(scene->obedit);
+ Object *obedit = CTX_data_edit_object(C);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
em->selectmode = ts->selectmode = selectmode_orig;
EDBM_selectmode_set(em);
}
@@ -483,7 +479,10 @@ static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
return OPERATOR_CANCELLED;
}
- if (RNA_struct_property_is_set(op->ptr, "value")) {
+ /* When modal, allow 'value' to set initial offset. */
+ if ((event == NULL) &&
+ RNA_struct_property_is_set(op->ptr, "value"))
+ {
return transform_exec(C, op);
}
else {
@@ -491,6 +490,15 @@ static int transform_invoke(bContext *C, wmOperator *op, const wmEvent *event)
WM_event_add_modal_handler(C, op);
op->flag |= OP_IS_MODAL_GRAB_CURSOR; // XXX maybe we want this with the manipulator only?
+
+ /* Use when modal input has some transformation to begin with. */
+ {
+ TransInfo *t = op->customdata;
+ if (UNLIKELY(!is_zero_v4(t->values_modal_offset))) {
+ transformApply(C, t);
+ }
+ }
+
return OPERATOR_RUNNING_MODAL;
}
}
@@ -599,6 +607,8 @@ static void TRANSFORM_OT_translate(struct wmOperatorType *ot)
RNA_def_float_vector_xyz(ot->srna, "value", 3, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_OPTIONS | P_GPENCIL_EDIT);
}
@@ -619,6 +629,8 @@ static void TRANSFORM_OT_resize(struct wmOperatorType *ot)
RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(
ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_GPENCIL_EDIT | P_CENTER);
}
@@ -650,6 +662,8 @@ static void TRANSFORM_OT_skin_resize(struct wmOperatorType *ot)
RNA_def_float_vector(ot->srna, "value", 3, VecOne, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_OPTIONS | P_NO_TEXSPACE);
}
@@ -671,6 +685,8 @@ static void TRANSFORM_OT_trackball(struct wmOperatorType *ot)
/* Maybe we could use float_vector_xyz here too? */
RNA_def_float_rotation(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
}
@@ -691,6 +707,8 @@ static void TRANSFORM_OT_rotate(struct wmOperatorType *ot)
RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(
ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_GEO_SNAP | P_GPENCIL_EDIT | P_CENTER);
}
@@ -715,6 +733,8 @@ static void TRANSFORM_OT_tilt(struct wmOperatorType *ot)
RNA_def_float_rotation(ot->srna, "value", 0, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
}
@@ -735,6 +755,8 @@ static void TRANSFORM_OT_bend(struct wmOperatorType *ot)
RNA_def_float_rotation(ot->srna, "value", 1, NULL, -FLT_MAX, FLT_MAX, "Angle", "", -M_PI * 2, M_PI * 2);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
}
@@ -755,6 +777,8 @@ static void TRANSFORM_OT_shear(struct wmOperatorType *ot)
RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Offset", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT);
// XXX Shear axis?
}
@@ -776,6 +800,8 @@ static void TRANSFORM_OT_push_pull(struct wmOperatorType *ot)
RNA_def_float(ot->srna, "value", 0, -FLT_MAX, FLT_MAX, "Distance", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_CENTER);
}
@@ -798,6 +824,8 @@ static void TRANSFORM_OT_shrink_fatten(struct wmOperatorType *ot)
RNA_def_boolean(ot->srna, "use_even_offset", true, "Offset Even", "Scale the offset to give more even thickness");
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP);
}
@@ -819,6 +847,8 @@ static void TRANSFORM_OT_tosphere(struct wmOperatorType *ot)
RNA_def_float_factor(ot->srna, "value", 0, 0, 1, "Factor", "", 0, 1);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_PROPORTIONAL | P_MIRROR | P_SNAP | P_GPENCIL_EDIT | P_CENTER);
}
@@ -863,6 +893,9 @@ static void TRANSFORM_OT_edge_slide(struct wmOperatorType *ot)
RNA_def_property_flag(prop, PROP_HIDDEN | PROP_SKIP_SAVE);
RNA_def_boolean(ot->srna, "use_even", false, "Even",
"Make the edge loop match the shape of the adjacent edge loop");
+
+ WM_operatortype_props_advanced_begin(ot);
+
RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
"When Even mode is active, flips between the two adjacent edge loops");
RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
@@ -889,6 +922,9 @@ static void TRANSFORM_OT_vert_slide(struct wmOperatorType *ot)
RNA_def_float_factor(ot->srna, "value", 0, -10.0f, 10.0f, "Factor", "", -1.0f, 1.0f);
RNA_def_boolean(ot->srna, "use_even", false, "Even",
"Make the edge loop match the shape of the adjacent edge loop");
+
+ WM_operatortype_props_advanced_begin(ot);
+
RNA_def_boolean(ot->srna, "flipped", false, "Flipped",
"When Even mode is active, flips between the two adjacent edge loops");
RNA_def_boolean(ot->srna, "use_clamp", true, "Clamp",
@@ -914,6 +950,8 @@ static void TRANSFORM_OT_edge_crease(struct wmOperatorType *ot)
RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_SNAP);
}
@@ -955,6 +993,8 @@ static void TRANSFORM_OT_edge_bevelweight(struct wmOperatorType *ot)
RNA_def_float_factor(ot->srna, "value", 0, -1.0f, 1.0f, "Factor", "", -1.0f, 1.0f);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_SNAP);
}
@@ -975,6 +1015,8 @@ static void TRANSFORM_OT_seq_slide(struct wmOperatorType *ot)
RNA_def_float_vector_xyz(ot->srna, "value", 2, NULL, -FLT_MAX, FLT_MAX, "Vector", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(ot, P_SNAP);
}
@@ -1000,6 +1042,8 @@ static void TRANSFORM_OT_transform(struct wmOperatorType *ot)
RNA_def_float_vector(ot->srna, "value", 4, NULL, -FLT_MAX, FLT_MAX, "Values", "", -FLT_MAX, FLT_MAX);
+ WM_operatortype_props_advanced_begin(ot);
+
Transform_Properties(
ot, P_AXIS | P_CONSTRAINT | P_PROPORTIONAL | P_MIRROR | P_ALIGN_SNAP | P_GPENCIL_EDIT | P_CENTER);
}
@@ -1066,6 +1110,8 @@ void transform_keymap_for_space(wmKeyConfig *keyconf, wmKeyMap *keymap, int spac
kmi = WM_keymap_add_item(keymap, "WM_OT_context_menu_enum", TABKEY, KM_PRESS, KM_SHIFT | KM_CTRL, 0);
RNA_string_set(kmi->ptr, "data_path", "tool_settings.snap_element");
+ /* Will fall-through to texture-space transform. */
+ kmi = WM_keymap_add_item(keymap, "OBJECT_OT_transform_axis_target", TKEY, KM_PRESS, KM_SHIFT, 0);
kmi = WM_keymap_add_item(keymap, OP_TRANSLATION, TKEY, KM_PRESS, KM_SHIFT, 0);
RNA_boolean_set(kmi->ptr, "texture_space", true);
diff --git a/source/blender/editors/transform/transform_orientations.c b/source/blender/editors/transform/transform_orientations.c
index 18b5e952a3d..9e6f4847b5b 100644
--- a/source/blender/editors/transform/transform_orientations.c
+++ b/source/blender/editors/transform/transform_orientations.c
@@ -38,6 +38,7 @@
#include "DNA_screen_types.h"
#include "DNA_space_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_math.h"
#include "BLI_listbase.h"
@@ -52,6 +53,8 @@
#include "BKE_report.h"
#include "BKE_main.h"
#include "BKE_screen.h"
+#include "BKE_scene.h"
+#include "BKE_workspace.h"
#include "BLT_translation.h"
@@ -63,14 +66,15 @@
void BIF_clearTransformOrientation(bContext *C)
{
+ Scene *scene = CTX_data_scene(C);
+ ListBase *transform_orientations = &scene->transform_spaces;
View3D *v3d = CTX_wm_view3d(C);
- ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- BLI_freelistN(transform_spaces);
-
- // Need to loop over all view3d
- if (v3d && v3d->twmode >= V3D_MANIP_CUSTOM) {
- v3d->twmode = V3D_MANIP_GLOBAL; /* fallback to global */
+ BLI_freelistN(transform_orientations);
+
+ if (v3d && scene->orientation_type == V3D_MANIP_CUSTOM) {
+ scene->orientation_type = V3D_MANIP_GLOBAL; /* fallback to global */
+ scene->orientation_index_custom = -1;
}
}
@@ -318,23 +322,24 @@ void BIF_createTransformOrientation(bContext *C, ReportList *reports,
TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
const char *name, const bool overwrite)
{
- ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
TransformOrientation *ts = NULL;
+ Scene *scene = CTX_data_scene(C);
+ ListBase *transform_orientations = &scene->transform_spaces;
char name_unique[sizeof(ts->name)];
if (overwrite) {
- ts = findOrientationName(transform_spaces, name);
+ ts = findOrientationName(transform_orientations, name);
}
else {
BLI_strncpy(name_unique, name, sizeof(name_unique));
- uniqueOrientationName(transform_spaces, name_unique);
+ uniqueOrientationName(transform_orientations, name_unique);
name = name_unique;
}
/* if not, create a new one */
if (ts == NULL) {
ts = MEM_callocN(sizeof(TransformOrientation), "UserTransSpace from matrix");
- BLI_addtail(transform_spaces, ts);
+ BLI_addtail(transform_orientations, ts);
BLI_strncpy(ts->name, name, sizeof(ts->name));
}
@@ -346,70 +351,54 @@ TransformOrientation *addMatrixSpace(bContext *C, float mat[3][3],
void BIF_removeTransformOrientation(bContext *C, TransformOrientation *target)
{
- Scene *scene = CTX_data_scene(C);
- ListBase *transform_spaces = &scene->transform_spaces;
- const int i = BLI_findindex(transform_spaces, target);
-
- if (i != -1) {
- Main *bmain = CTX_data_main(C);
- BKE_screen_view3d_main_twmode_remove(&bmain->screen, scene, i);
- BLI_freelinkN(transform_spaces, target);
- }
+ BKE_scene_transform_orientation_remove(CTX_data_scene(C), target);
}
void BIF_removeTransformOrientationIndex(bContext *C, int index)
{
- ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- TransformOrientation *ts = BLI_findlink(transform_spaces, index);
-
- if (ts) {
- BIF_removeTransformOrientation(C, ts);
- }
+ TransformOrientation *target = BKE_scene_transform_orientation_find(CTX_data_scene(C), index);
+ BIF_removeTransformOrientation(C, target);
}
void BIF_selectTransformOrientation(bContext *C, TransformOrientation *target)
{
- ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- const int i = BLI_findindex(transform_spaces, target);
+ Scene *scene = CTX_data_scene(C);
+ int index = BKE_scene_transform_orientation_get_index(scene, target);
- if (i != -1) {
- View3D *v3d = CTX_wm_view3d(C);
- v3d->twmode = V3D_MANIP_CUSTOM + i;
- }
+ BLI_assert(index != -1);
+
+ scene->orientation_type = V3D_MANIP_CUSTOM;
+ scene->orientation_index_custom = index;
}
-void BIF_selectTransformOrientationValue(bContext *C, int orientation)
+/**
+ * Activate a transform orientation in a 3D view based on an enum value.
+ *
+ * \param orientation: If this is #V3D_MANIP_CUSTOM or greater, the custom transform orientation
+ * with index \a orientation - #V3D_MANIP_CUSTOM gets activated.
+ */
+void BIF_selectTransformOrientationValue(Scene *scene, int orientation)
{
- View3D *v3d = CTX_wm_view3d(C);
- if (v3d) /* currently using generic poll */
- v3d->twmode = orientation;
+ const bool is_custom = orientation >= V3D_MANIP_CUSTOM;
+ scene->orientation_type = is_custom ? V3D_MANIP_CUSTOM : orientation;
+ scene->orientation_index_custom = is_custom ? (orientation - V3D_MANIP_CUSTOM) : -1;
}
int BIF_countTransformOrientation(const bContext *C)
{
- ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- return BLI_listbase_count(transform_spaces);
+ Scene *scene = CTX_data_scene(C);
+ ListBase *transform_orientations = &scene->transform_spaces;
+ return BLI_listbase_count(transform_orientations);
}
-bool applyTransformOrientation(const bContext *C, float mat[3][3], char *r_name, int index)
+bool applyTransformOrientation(const TransformOrientation *ts, float r_mat[3][3], char *r_name)
{
- ListBase *transform_spaces = &CTX_data_scene(C)->transform_spaces;
- TransformOrientation *ts = BLI_findlink(transform_spaces, index);
-
- BLI_assert(index >= 0);
-
- if (ts) {
- if (r_name) {
- BLI_strncpy(r_name, ts->name, MAX_NAME);
- }
-
- copy_m3_m3(mat, ts->mat);
- return true;
- }
- else {
- /* invalid index, can happen sometimes */
- return false;
+ if (r_name) {
+ BLI_strncpy(r_name, ts->name, MAX_NAME);
}
+ copy_m3_m3(r_mat, ts->mat);
+
+ return true;
}
static int count_bone_select(bArmature *arm, ListBase *lb, const bool do_it)
@@ -492,8 +481,10 @@ void initTransformOrientation(bContext *C, TransInfo *t)
unit_m3(t->spacemtx);
}
break;
- default: /* V3D_MANIP_CUSTOM */
- if (applyTransformOrientation(C, t->spacemtx, t->spacename, t->current_orientation - V3D_MANIP_CUSTOM)) {
+ case V3D_MANIP_CUSTOM:
+ BLI_strncpy(t->spacename, t->custom_orientation->name, sizeof(t->spacename));
+
+ if (applyTransformOrientation(t->custom_orientation, t->spacemtx, t->spacename)) {
/* pass */
}
else {
@@ -586,10 +577,10 @@ static unsigned int bm_mesh_faces_select_get_n(BMesh *bm, BMVert **elems, const
int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3], const short around)
{
- Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Object *obedit = CTX_data_edit_object(C);
Base *base;
- Object *ob = OBACT;
+ Object *ob = OBACT(view_layer);
int result = ORIENTATION_NONE;
const bool activeOnly = (around == V3D_AROUND_ACTIVE);
@@ -1061,16 +1052,16 @@ int getTransformOrientation_ex(const bContext *C, float normal[3], float plane[3
}
else {
/* we need the one selected object, if its not active */
- View3D *v3d = CTX_wm_view3d(C);
- ob = OBACT;
- if (ob && (ob->flag & SELECT)) {
+ base = BASACT(view_layer);
+ ob = OBACT(view_layer);
+ if (base && ((base->flag & BASE_SELECTED) != 0)) {
/* pass */
}
else {
/* first selected */
ob = NULL;
- for (base = scene->base.first; base; base = base->next) {
- if (TESTBASELIB(v3d, base)) {
+ for (base = view_layer->object_bases.first; base; base = base->next) {
+ if (TESTBASELIB(base)) {
ob = base->object;
break;
}
diff --git a/source/blender/editors/transform/transform_snap.c b/source/blender/editors/transform/transform_snap.c
index 660a3748191..7eff1b33acc 100644
--- a/source/blender/editors/transform/transform_snap.c
+++ b/source/blender/editors/transform/transform_snap.c
@@ -49,7 +49,7 @@
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
-#include "BIF_gl.h"
+#include "GPU_immediate.h"
#include "BKE_DerivedMesh.h"
#include "BKE_global.h"
@@ -70,6 +70,8 @@
#include "ED_view3d.h"
#include "ED_transform_snap_object_context.h"
+#include "DEG_depsgraph.h"
+
#include "UI_resources.h"
#include "UI_view2d.h"
@@ -163,36 +165,42 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
size = 2.5f * UI_GetThemeValuef(TH_VERTEX_SIZE);
invert_m4_m4(imat, rv3d->viewmat);
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_3D_UNIFORM_COLOR);
+
for (p = t->tsnap.points.first; p; p = p->next) {
if (p == t->tsnap.selectedPoint) {
- glColor4ubv(selectedCol);
+ immUniformColor4ubv(selectedCol);
}
else {
- glColor4ubv(col);
+ immUniformColor4ubv(col);
}
- drawcircball(GL_LINE_LOOP, p->co, ED_view3d_pixel_size(rv3d, p->co) * size * 0.75f, imat);
+ imm_drawcircball(p->co, ED_view3d_pixel_size(rv3d, p->co) * size * 0.75f, imat, pos);
}
if (t->tsnap.status & POINT_INIT) {
- glColor4ubv(activeCol);
+ immUniformColor4ubv(activeCol);
- drawcircball(GL_LINE_LOOP, t->tsnap.snapPoint, ED_view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat);
+ imm_drawcircball(t->tsnap.snapPoint, ED_view3d_pixel_size(rv3d, t->tsnap.snapPoint) * size, imat, pos);
}
/* draw normal if needed */
if (usingSnappingNormal(t) && validSnappingNormal(t)) {
- glColor4ubv(activeCol);
+ immUniformColor4ubv(activeCol);
- glBegin(GL_LINES);
- glVertex3f(t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
- glVertex3f(t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0],
- t->tsnap.snapPoint[1] + t->tsnap.snapNormal[1],
- t->tsnap.snapPoint[2] + t->tsnap.snapNormal[2]);
- glEnd();
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex3f(pos, t->tsnap.snapPoint[0], t->tsnap.snapPoint[1], t->tsnap.snapPoint[2]);
+ immVertex3f(pos, t->tsnap.snapPoint[0] + t->tsnap.snapNormal[0],
+ t->tsnap.snapPoint[1] + t->tsnap.snapNormal[1],
+ t->tsnap.snapPoint[2] + t->tsnap.snapNormal[2]);
+ immEnd();
}
-
+
+ immUnbindProgram();
+
if (v3d->zbuf)
glEnable(GL_DEPTH_TEST);
}
@@ -200,35 +208,7 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
else if (t->spacetype == SPACE_IMAGE) {
if (validSnap(t)) {
/* This will not draw, and Im nor sure why - campbell */
-#if 0
- float xuser_asp, yuser_asp;
- int wi, hi;
- float w, h;
-
- calc_image_view(G.sima, 'f'); // float
- myortho2(G.v2d->cur.xmin, G.v2d->cur.xmax, G.v2d->cur.ymin, G.v2d->cur.ymax);
- glLoadIdentity();
-
- ED_space_image_get_aspect(t->sa->spacedata.first, &xuser_aspx, &yuser_asp);
- ED_space_image_width(t->sa->spacedata.first, &wi, &hi);
- w = (((float)wi) / IMG_SIZE_FALLBACK) * G.sima->zoom * xuser_asp;
- h = (((float)hi) / IMG_SIZE_FALLBACK) * G.sima->zoom * yuser_asp;
-
- cpack(0xFFFFFF);
- glTranslate2fv(t->tsnap.snapPoint);
-
- //glRectf(0, 0, 1, 1);
-
- setlinestyle(0);
- cpack(0x0);
- fdrawline(-0.020 / w, 0, -0.1 / w, 0);
- fdrawline(0.1 / w, 0, 0.020 / w, 0);
- fdrawline(0, -0.020 / h, 0, -0.1 / h);
- fdrawline(0, 0.1 / h, 0, 0.020 / h);
-
- glTranslatef(-t->tsnap.snapPoint[0], -t->tsnap.snapPoint[1], 0.0f);
- setlinestyle(0);
-#endif
+ /* TODO: see 2.7x for non-working code */
}
}
else if (t->spacetype == SPACE_NODE) {
@@ -241,23 +221,29 @@ void drawSnapping(const struct bContext *C, TransInfo *t)
glEnable(GL_BLEND);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
for (p = t->tsnap.points.first; p; p = p->next) {
if (p == t->tsnap.selectedPoint) {
- glColor4ubv(selectedCol);
+ immUniformColor4ubv(selectedCol);
}
else {
- glColor4ubv(col);
+ immUniformColor4ubv(col);
}
- ED_node_draw_snap(&ar->v2d, p->co, size, 0);
+ ED_node_draw_snap(&ar->v2d, p->co, size, 0, pos);
}
if (t->tsnap.status & POINT_INIT) {
- glColor4ubv(activeCol);
+ immUniformColor4ubv(activeCol);
- ED_node_draw_snap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder);
+ ED_node_draw_snap(&ar->v2d, t->tsnap.snapPoint, size, t->tsnap.snapNodeBorder, pos);
}
-
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
}
}
@@ -286,73 +272,70 @@ void applyProject(TransInfo *t)
{
/* XXX FLICKER IN OBJECT MODE */
if ((t->tsnap.project) && activeSnap(t) && (t->flag & T_NO_PROJECT) == 0) {
- TransData *td = t->data;
float tvec[3];
- float imat[4][4];
int i;
-
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- invert_m4_m4(imat, ob->obmat);
- }
- for (i = 0; i < t->total; i++, td++) {
- float iloc[3], loc[3], no[3];
- float mval_fl[2];
- float dist_px = TRANSFORM_DIST_MAX_PX;
-
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td = tc->data;
+ for (i = 0; i < tc->data_len; i++, td++) {
+ float iloc[3], loc[3], no[3];
+ float mval_fl[2];
+ float dist_px = TRANSFORM_DIST_MAX_PX;
- if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f))
- continue;
-
- copy_v3_v3(iloc, td->loc);
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_m4_v3(ob->obmat, iloc);
- }
- else if (t->flag & T_OBJECT) {
- BKE_object_eval_transform_all(G.main->eval_ctx, t->scene, td->ob);
- copy_v3_v3(iloc, td->ob->obmat[3]);
- }
-
- if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
- if (snapObjectsTransform(
- t, mval_fl, &dist_px,
- loc, no))
- {
-// if (t->flag & (T_EDIT|T_POSE)) {
-// mul_m4_v3(imat, loc);
-// }
+ if (td->flag & TD_NOACTION)
+ break;
- sub_v3_v3v3(tvec, loc, iloc);
+ if (td->flag & TD_SKIP)
+ continue;
- mul_m3_v3(td->smtx, tvec);
+ if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f))
+ continue;
- add_v3_v3(td->loc, tvec);
+ copy_v3_v3(iloc, td->loc);
+ if (tc->use_local_mat) {
+ mul_m4_v3(tc->mat, iloc);
+ }
+ else if (t->flag & T_OBJECT) {
+ BKE_object_eval_transform_all(t->depsgraph, t->scene, td->ob);
+ copy_v3_v3(iloc, td->ob->obmat[3]);
+ }
- if (t->tsnap.align && (t->flag & T_OBJECT)) {
- /* handle alignment as well */
- const float *original_normal;
- float mat[3][3];
+ if (ED_view3d_project_float_global(t->ar, iloc, mval_fl, V3D_PROJ_TEST_NOP) == V3D_PROJ_RET_OK) {
+ if (snapObjectsTransform(
+ t, mval_fl, &dist_px,
+ loc, no))
+ {
+#if 0
+ if (tc->use_local_mat) {
+ mul_m4_v3(tc->imat, loc);
+ }
+#endif
- /* In pose mode, we want to align normals with Y axis of bones... */
- original_normal = td->axismtx[2];
+ sub_v3_v3v3(tvec, loc, iloc);
- rotation_between_vecs_to_mat3(mat, original_normal, no);
+ mul_m3_v3(td->smtx, tvec);
- transform_data_ext_rotate(td, mat, true);
+ add_v3_v3(td->loc, tvec);
- /* TODO support constraints for rotation too? see ElementRotation */
+ if (t->tsnap.align && (t->flag & T_OBJECT)) {
+ /* handle alignment as well */
+ const float *original_normal;
+ float mat[3][3];
+
+ /* In pose mode, we want to align normals with Y axis of bones... */
+ original_normal = td->axismtx[2];
+
+ rotation_between_vecs_to_mat3(mat, original_normal, no);
+
+ transform_data_ext_rotate(td, mat, true);
+
+ /* TODO support constraints for rotation too? see ElementRotation */
+ }
}
}
+
+ //XXX constraintTransLim(t, td);
}
-
- //XXX constraintTransLim(t, td);
}
}
}
@@ -361,9 +344,6 @@ void applyGridAbsolute(TransInfo *t)
{
float grid_size = 0.0f;
GearsType grid_action;
- TransData *td;
- float (*obmat)[4] = NULL;
- bool use_obmat = false;
int i;
if (!(activeSnap(t) && (ELEM(t->tsnap.mode, SCE_SNAP_MODE_INCREMENT, SCE_SNAP_MODE_GRID))))
@@ -382,42 +362,40 @@ void applyGridAbsolute(TransInfo *t)
if (grid_size == 0.0f)
return;
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- obmat = ob->obmat;
- use_obmat = true;
- }
-
- for (i = 0, td = t->data; i < t->total; i++, td++) {
- float iloc[3], loc[3], tvec[3];
-
- if (td->flag & TD_NOACTION)
- break;
-
- if (td->flag & TD_SKIP)
- continue;
-
- if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f))
- continue;
-
- copy_v3_v3(iloc, td->loc);
- if (use_obmat) {
- mul_m4_v3(obmat, iloc);
- }
- else if (t->flag & T_OBJECT) {
- BKE_object_eval_transform_all(G.main->eval_ctx, t->scene, td->ob);
- copy_v3_v3(iloc, td->ob->obmat[3]);
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td;
+
+ for (i = 0, td = tc->data; i < tc->data_len; i++, td++) {
+ float iloc[3], loc[3], tvec[3];
+
+ if (td->flag & TD_NOACTION)
+ break;
+
+ if (td->flag & TD_SKIP)
+ continue;
+
+ if ((t->flag & T_PROP_EDIT) && (td->factor == 0.0f))
+ continue;
+
+ copy_v3_v3(iloc, td->loc);
+ if (tc->use_local_mat) {
+ mul_m4_v3(tc->mat, iloc);
+ }
+ else if (t->flag & T_OBJECT) {
+ BKE_object_eval_transform_all(t->depsgraph, t->scene, td->ob);
+ copy_v3_v3(iloc, td->ob->obmat[3]);
+ }
+
+ mul_v3_v3fl(loc, iloc, 1.0f / grid_size);
+ loc[0] = roundf(loc[0]);
+ loc[1] = roundf(loc[1]);
+ loc[2] = roundf(loc[2]);
+ mul_v3_fl(loc, grid_size);
+
+ sub_v3_v3v3(tvec, loc, iloc);
+ mul_m3_v3(td->smtx, tvec);
+ add_v3_v3(td->loc, tvec);
}
-
- mul_v3_v3fl(loc, iloc, 1.0f / grid_size);
- loc[0] = roundf(loc[0]);
- loc[1] = roundf(loc[1]);
- loc[2] = roundf(loc[2]);
- mul_v3_fl(loc, grid_size);
-
- sub_v3_v3v3(tvec, loc, iloc);
- mul_m3_v3(td->smtx, tvec);
- add_v3_v3(td->loc, tvec);
}
}
@@ -515,9 +493,10 @@ static bool bm_face_is_snap_target(BMFace *f, void *UNUSED(user_data))
static void initSnappingMode(TransInfo *t)
{
ToolSettings *ts = t->settings;
- Object *obedit = t->obedit;
- Scene *scene = t->scene;
- Base *base_act = scene->basact;
+ /* All obedit types will match. */
+ const int obedit_type = t->data_container->obedit ? t->data_container->obedit->type : -1;
+ ViewLayer *view_layer = t->view_layer;
+ Base *base_act = view_layer->basact;
if (t->spacetype == SPACE_NODE) {
/* force project off when not supported */
@@ -546,10 +525,10 @@ static void initSnappingMode(TransInfo *t)
/* Edit mode */
if (t->tsnap.applySnap != NULL && // A snapping function actually exist
- (obedit != NULL && ELEM(obedit->type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE, OB_MBALL)) ) // Temporary limited to edit mode meshes, armature, curves, mballs
+ ((obedit_type != -1) && ELEM(obedit_type, OB_MESH, OB_ARMATURE, OB_CURVE, OB_LATTICE, OB_MBALL)) ) // Temporary limited to edit mode meshes, armature, curves, mballs
{
/* Exclude editmesh if using proportional edit */
- if ((obedit->type == OB_MESH) && (t->flag & T_PROP_EDIT)) {
+ if ((obedit_type == OB_MESH) && (t->flag & T_PROP_EDIT)) {
t->tsnap.modeSelect = SNAP_NOT_ACTIVE;
}
else {
@@ -558,13 +537,13 @@ static void initSnappingMode(TransInfo *t)
}
/* Particles edit mode*/
else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
- (obedit == NULL && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT))
+ ((obedit_type == -1) && base_act && base_act->object && base_act->object->mode & OB_MODE_PARTICLE_EDIT))
{
t->tsnap.modeSelect = SNAP_ALL;
}
/* Object mode */
else if (t->tsnap.applySnap != NULL && // A snapping function actually exist
- (obedit == NULL) ) // Object Mode
+ (obedit_type == -1) ) // Object Mode
{
/* In "Edit Strokes" mode, Snap tool can perform snap to selected or active objects (see T49632)
* TODO: perform self snap in gpencil_strokes */
@@ -598,8 +577,7 @@ static void initSnappingMode(TransInfo *t)
if (t->spacetype == SPACE_VIEW3D) {
if (t->tsnap.object_context == NULL) {
t->tsnap.object_context = ED_transform_snap_object_context_create_view3d(
- G.main, t->scene, 0,
- t->ar, t->view);
+ G.main, t->scene, t->depsgraph, 0, t->ar, t->view);
ED_transform_snap_object_context_set_editmesh_callbacks(
t->tsnap.object_context,
@@ -878,7 +856,8 @@ static float TranslationBetween(TransInfo *UNUSED(t), const float p1[3], const f
return len_squared_v3v3(p1, p2);
}
-static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3])
+static float RotationBetween(
+ TransInfo *t, const float p1[3], const float p2[3])
{
float angle, start[3], end[3];
@@ -889,7 +868,7 @@ static float RotationBetween(TransInfo *t, const float p1[3], const float p2[3])
if (t->con.applyRot != NULL && (t->con.mode & CON_APPLY)) {
float axis[3], tmp[3];
- t->con.applyRot(t, NULL, axis, NULL);
+ t->con.applyRot(t, NULL, NULL, axis, NULL);
project_v3_v3v3(tmp, end, axis);
sub_v3_v3v3(end, end, tmp);
@@ -992,14 +971,14 @@ static void CalcSnapGeometry(TransInfo *t, float *UNUSED(vec))
t->tsnap.status &= ~POINT_INIT;
}
}
- else if (t->spacetype == SPACE_IMAGE && t->obedit != NULL && t->obedit->type == OB_MESH) {
+ else if (t->spacetype == SPACE_IMAGE && t->obedit_type == OB_MESH) {
/* same as above but for UV's */
Image *ima = ED_space_image(t->sa->spacedata.first);
float co[2];
UI_view2d_region_to_view(&t->ar->v2d, t->mval[0], t->mval[1], &co[0], &co[1]);
- if (ED_uvedit_nearest_uv(t->scene, t->obedit, ima, co, t->tsnap.snapPoint)) {
+ if (ED_uvedit_nearest_uv(t->scene, TRANS_DATA_CONTAINER_FIRST_EVIL(t)->obedit, ima, co, t->tsnap.snapPoint)) {
t->tsnap.snapPoint[0] *= t->aspect[0];
t->tsnap.snapPoint[1] *= t->aspect[1];
@@ -1074,11 +1053,6 @@ static void TargetSnapActive(TransInfo *t)
/* Only need to calculate once */
if ((t->tsnap.status & TARGET_INIT) == 0) {
if (calculateCenterActive(t, true, t->tsnap.snapTarget)) {
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_m4_v3(ob->obmat, t->tsnap.snapTarget);
- }
-
TargetSnapOffset(t, NULL);
t->tsnap.status |= TARGET_INIT;
@@ -1096,23 +1070,30 @@ static void TargetSnapMedian(TransInfo *t)
{
// Only need to calculate once
if ((t->tsnap.status & TARGET_INIT) == 0) {
- TransData *td = NULL;
- int i;
+ int i_accum = 0;
t->tsnap.snapTarget[0] = 0;
t->tsnap.snapTarget[1] = 0;
t->tsnap.snapTarget[2] = 0;
-
- for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) {
- add_v3_v3(t->tsnap.snapTarget, td->center);
- }
-
- mul_v3_fl(t->tsnap.snapTarget, 1.0 / i);
-
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_m4_v3(ob->obmat, t->tsnap.snapTarget);
+
+ FOREACH_TRANS_DATA_CONTAINER (t, tc) {
+ TransData *td = tc->data;
+ int i;
+ for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
+ /* TODO(campbell): perform the global transformation once per TransDataContainer */
+ if (tc->use_local_mat) {
+ float v[3];
+ mul_v3_m4v3(v, tc->mat, td->center);
+ add_v3_v3(t->tsnap.snapTarget, v);
+ }
+ else {
+ add_v3_v3(t->tsnap.snapTarget, td->center);
+ }
+ }
+ i_accum += i;
}
+
+ mul_v3_fl(t->tsnap.snapTarget, 1.0 / i_accum);
TargetSnapOffset(t, NULL);
@@ -1125,25 +1106,45 @@ static void TargetSnapClosest(TransInfo *t)
// Only valid if a snap point has been selected
if (t->tsnap.status & POINT_INIT) {
float dist_closest = 0.0f;
- TransData *closest = NULL, *td = NULL;
+ TransData *closest = NULL;
/* Object mode */
if (t->flag & T_OBJECT) {
int i;
- for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) {
- struct BoundBox *bb = BKE_object_boundbox_get(td->ob);
-
- /* use boundbox if possible */
- if (bb) {
- int j;
-
- for (j = 0; j < 8; j++) {
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td = tc->data;
+ for (td = tc->data, i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
+ struct BoundBox *bb = BKE_object_boundbox_get(td->ob);
+
+ /* use boundbox if possible */
+ if (bb) {
+ int j;
+
+ for (j = 0; j < 8; j++) {
+ float loc[3];
+ float dist;
+
+ copy_v3_v3(loc, bb->vec[j]);
+ mul_m4_v3(td->ext->obmat, loc);
+
+ dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint);
+
+ if ((dist != TRANSFORM_DIST_INVALID) &&
+ (closest == NULL || fabsf(dist) < fabsf(dist_closest)))
+ {
+ copy_v3_v3(t->tsnap.snapTarget, loc);
+ closest = td;
+ dist_closest = dist;
+ }
+ }
+ }
+ /* use element center otherwise */
+ else {
float loc[3];
float dist;
-
- copy_v3_v3(loc, bb->vec[j]);
- mul_m4_v3(td->ext->obmat, loc);
-
+
+ copy_v3_v3(loc, td->center);
+
dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint);
if ((dist != TRANSFORM_DIST_INVALID) &&
@@ -1151,17 +1152,25 @@ static void TargetSnapClosest(TransInfo *t)
{
copy_v3_v3(t->tsnap.snapTarget, loc);
closest = td;
- dist_closest = dist;
}
}
}
- /* use element center otherwise */
- else {
+ }
+ }
+ else {
+ FOREACH_TRANS_DATA_CONTAINER(t, tc) {
+ TransData *td = tc->data;
+ int i;
+ for (i = 0; i < tc->data_len && td->flag & TD_SELECTED; i++, td++) {
float loc[3];
float dist;
-
+
copy_v3_v3(loc, td->center);
-
+
+ if (tc->use_local_mat) {
+ mul_m4_v3(tc->mat, loc);
+ }
+
dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint);
if ((dist != TRANSFORM_DIST_INVALID) &&
@@ -1169,34 +1178,11 @@ static void TargetSnapClosest(TransInfo *t)
{
copy_v3_v3(t->tsnap.snapTarget, loc);
closest = td;
+ dist_closest = dist;
}
}
}
}
- else {
- int i;
- for (td = t->data, i = 0; i < t->total && td->flag & TD_SELECTED; i++, td++) {
- float loc[3];
- float dist;
-
- copy_v3_v3(loc, td->center);
-
- if (t->flag & (T_EDIT | T_POSE)) {
- Object *ob = t->obedit ? t->obedit : t->poseobj;
- mul_m4_v3(ob->obmat, loc);
- }
-
- dist = t->tsnap.distance(t, loc, t->tsnap.snapPoint);
-
- if ((dist != TRANSFORM_DIST_INVALID) &&
- (closest == NULL || fabsf(dist) < fabsf(dist_closest)))
- {
- copy_v3_v3(t->tsnap.snapTarget, loc);
- closest = td;
- dist_closest = dist;
- }
- }
- }
TargetSnapOffset(t, closest);
diff --git a/source/blender/editors/transform/transform_snap_object.c b/source/blender/editors/transform/transform_snap_object.c
index 1293d26bc65..40b71410014 100644
--- a/source/blender/editors/transform/transform_snap_object.c
+++ b/source/blender/editors/transform/transform_snap_object.c
@@ -51,6 +51,10 @@
#include "BKE_editmesh.h"
#include "BKE_main.h"
#include "BKE_tracking.h"
+#include "BKE_context.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
#include "ED_transform.h"
#include "ED_transform_snap_object_context.h"
@@ -105,6 +109,8 @@ typedef struct SnapObjectData_EditMesh {
struct SnapObjectContext {
Main *bmain;
Scene *scene;
+ Depsgraph *depsgraph;
+
int flag;
/* Optional: when performing screen-space projection.
@@ -157,18 +163,18 @@ static void iter_snap_objects(
IterSnapObjsCallback sob_callback,
void *data)
{
- Base *base_act = sctx->scene->basact;
- for (Base *base = sctx->scene->base.first; base != NULL; base = base->next) {
- if ((BASE_VISIBLE_BGMODE(sctx->v3d_data.v3d, sctx->scene, base)) &&
- (base->flag & BA_SNAP_FIX_DEPS_FIASCO) == 0 &&
- !((snap_select == SNAP_NOT_SELECTED && (base->flag & (SELECT | BA_WAS_SEL))) ||
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph);
+ Base *base_act = view_layer->basact;
+ for (Base *base = view_layer->object_bases.first; base != NULL; base = base->next) {
+ if ((BASE_VISIBLE(base)) && (base->flag_legacy & BA_SNAP_FIX_DEPS_FIASCO) == 0 &&
+ !((snap_select == SNAP_NOT_SELECTED && ((base->flag & BASE_SELECTED) || (base->flag_legacy & BA_WAS_SEL))) ||
(snap_select == SNAP_NOT_ACTIVE && base == base_act)))
{
bool use_obedit;
Object *obj = base->object;
if (obj->transflag & OB_DUPLI) {
DupliObject *dupli_ob;
- ListBase *lb = object_duplilist(sctx->bmain->eval_ctx, sctx->scene, obj);
+ ListBase *lb = object_duplilist(sctx->depsgraph, sctx->scene, obj);
for (dupli_ob = lb->first; dupli_ob; dupli_ob = dupli_ob->next) {
use_obedit = obedit && dupli_ob->ob->data == obedit->data;
sob_callback(sctx, use_obedit, use_obedit ? obedit : dupli_ob->ob, dupli_ob->mat, data);
@@ -725,10 +731,10 @@ static bool raycastObj(
DerivedMesh *dm;
em = BKE_editmesh_from_object(ob);
if (em) {
- editbmesh_get_derived_cage_and_final(sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
+ editbmesh_get_derived_cage_and_final(sctx->depsgraph, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
}
else {
- dm = mesh_get_derived_final(sctx->scene, ob, CD_MASK_BAREMESH);
+ dm = mesh_get_derived_final(sctx->depsgraph, sctx->scene, ob, CD_MASK_BAREMESH);
}
retval = raycastDerivedMesh(
sctx,
@@ -817,7 +823,8 @@ static bool raycastObjects(
Object **r_ob, float r_obmat[4][4],
ListBase *r_hit_list)
{
- Object *obedit = use_object_edit_cage ? sctx->scene->obedit : NULL;
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph);
+ Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL;
struct RaycastObjUserData data = {
.ray_start = ray_start,
@@ -1348,7 +1355,7 @@ static bool snapArmature(
static bool snapCurve(
SnapData *snapdata,
- Object *ob, Curve *cu, float obmat[4][4],
+ Curve *cu, float obmat[4][4], bool use_obedit,
/* read/write args */
float *ray_depth, float *dist_px,
/* return args */
@@ -1366,12 +1373,12 @@ static bool snapCurve(
mul_m4_m4m4(lpmat, snapdata->pmat, obmat);
dist_px_sq = SQUARE(*dist_px);
- for (Nurb *nu = (ob->mode == OB_MODE_EDIT ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) {
+ for (Nurb *nu = (use_obedit ? cu->editnurb->nurbs.first : cu->nurb.first); nu; nu = nu->next) {
for (int u = 0; u < nu->pntsu; u++) {
switch (snapdata->snap_to) {
case SCE_SNAP_MODE_VERTEX:
{
- if (ob->mode == OB_MODE_EDIT) {
+ if (use_obedit) {
if (nu->bezt) {
/* don't snap to selected (moving) or hidden */
if (nu->bezt[u].f2 & SELECT || nu->bezt[u].hide != 0) {
@@ -1932,10 +1939,10 @@ static bool snapObject(
DerivedMesh *dm;
em = BKE_editmesh_from_object(ob);
if (em) {
- editbmesh_get_derived_cage_and_final(sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
+ editbmesh_get_derived_cage_and_final(sctx->depsgraph, sctx->scene, ob, em, CD_MASK_BAREMESH, &dm);
}
else {
- dm = mesh_get_derived_final(sctx->scene, ob, CD_MASK_BAREMESH);
+ dm = mesh_get_derived_final(sctx->depsgraph, sctx->scene, ob, CD_MASK_BAREMESH);
}
retval = snapDerivedMesh(
sctx, snapdata, ob, dm, obmat,
@@ -1956,7 +1963,7 @@ static bool snapObject(
else if (ob->type == OB_CURVE) {
retval = snapCurve(
snapdata,
- ob, ob->data, obmat,
+ ob->data, obmat, use_obedit,
ray_depth, dist_px,
r_loc, r_no);
}
@@ -2050,7 +2057,8 @@ static bool snapObjectsRay(
float r_loc[3], float r_no[3],
Object **r_ob, float r_obmat[4][4])
{
- Object *obedit = use_object_edit_cage ? sctx->scene->obedit : NULL;
+ ViewLayer *view_layer = DEG_get_evaluated_view_layer(sctx->depsgraph);
+ Object *obedit = use_object_edit_cage ? OBEDIT_FROM_VIEW_LAYER(view_layer) : NULL;
struct SnapObjUserData data = {
.snapdata = snapdata,
@@ -2075,7 +2083,7 @@ static bool snapObjectsRay(
* \{ */
SnapObjectContext *ED_transform_snap_object_context_create(
- Main *bmain, Scene *scene, int flag)
+ Main *bmain, Scene *scene, Depsgraph *depsgraph, int flag)
{
SnapObjectContext *sctx = MEM_callocN(sizeof(*sctx), __func__);
@@ -2083,6 +2091,7 @@ SnapObjectContext *ED_transform_snap_object_context_create(
sctx->bmain = bmain;
sctx->scene = scene;
+ sctx->depsgraph = depsgraph;
sctx->cache.object_map = BLI_ghash_ptr_new(__func__);
sctx->cache.mem_arena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, __func__);
@@ -2091,11 +2100,11 @@ SnapObjectContext *ED_transform_snap_object_context_create(
}
SnapObjectContext *ED_transform_snap_object_context_create_view3d(
- Main *bmain, Scene *scene, int flag,
+ Main *bmain, Scene *scene, Depsgraph *depsgraph, int flag,
/* extra args for view3d */
const ARegion *ar, const View3D *v3d)
{
- SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, flag);
+ SnapObjectContext *sctx = ED_transform_snap_object_context_create(bmain, scene, depsgraph, flag);
sctx->use_v3d = true;
sctx->v3d_data.ar = ar;
@@ -2359,6 +2368,7 @@ bool ED_transform_snap_object_project_view3d_ex(
ED_view3d_win_to_vector(ar, mval, ray_normal);
ED_view3d_clip_range_get(
+ sctx->depsgraph,
sctx->v3d_data.v3d, sctx->v3d_data.ar->regiondata,
&depth_range[0], &depth_range[1], false);
@@ -2426,6 +2436,7 @@ bool ED_transform_snap_object_project_all_view3d_ex(
float ray_start[3], ray_normal[3];
if (!ED_view3d_win_to_ray_ex(
+ sctx->depsgraph,
sctx->v3d_data.ar, sctx->v3d_data.v3d,
mval, NULL, ray_normal, ray_start, true))
{
diff --git a/source/blender/editors/undo/ed_undo.c b/source/blender/editors/undo/ed_undo.c
index d8b194e3336..3950b056e89 100644
--- a/source/blender/editors/undo/ed_undo.c
+++ b/source/blender/editors/undo/ed_undo.c
@@ -36,6 +36,7 @@
#include "CLG_log.h"
#include "DNA_scene_types.h"
+#include "DNA_object_types.h"
#include "BLI_utildefines.h"
@@ -46,6 +47,7 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_screen.h"
+#include "BKE_layer.h"
#include "BKE_undo_system.h"
#include "ED_gpencil.h"
@@ -302,12 +304,42 @@ void ED_OT_undo_redo(wmOperatorType *ot)
/** \} */
+struct OperatorRepeatContextHandle {
+ ScrArea *restore_area;
+ ARegion *restore_region;
+};
+
+/**
+ * Resets the context to the state \a op was executed in (or at least, was in when registering).
+ * #ED_operator_repeat_reset_context should be called when done repeating!
+ */
+const OperatorRepeatContextHandle *ED_operator_repeat_prepare_context(bContext *C, wmOperator *op)
+{
+ static OperatorRepeatContextHandle context_info;
+
+ context_info.restore_area = CTX_wm_area(C);
+ context_info.restore_region = CTX_wm_region(C);
+
+ CTX_wm_area_set(C, op->execution_area);
+ CTX_wm_region_set(C, op->execution_region);
+
+ return &context_info;
+}
+/**
+ * Resets context to the old state from before #ED_operator_repeat_prepare_context was called.
+ */
+void ED_operator_repeat_reset_context(bContext *C, const OperatorRepeatContextHandle *context_info)
+{
+ CTX_wm_area_set(C, context_info->restore_area);
+ CTX_wm_region_set(C, context_info->restore_region);
+}
+
/* -------------------------------------------------------------------- */
/** \name Operator Repeat
* \{ */
/* ui callbacks should call this rather than calling WM_operator_repeat() themselves */
-int ED_undo_operator_repeat(bContext *C, struct wmOperator *op)
+int ED_undo_operator_repeat(bContext *C, wmOperator *op)
{
int ret = 0;
@@ -316,12 +348,8 @@ int ED_undo_operator_repeat(bContext *C, struct wmOperator *op)
wmWindowManager *wm = CTX_wm_manager(C);
struct Scene *scene = CTX_data_scene(C);
- /* keep in sync with logic in view3d_panel_operator_redo() */
- ARegion *ar = CTX_wm_region(C);
- ARegion *ar1 = BKE_area_find_region_active_win(CTX_wm_area(C));
-
- if (ar1)
- CTX_wm_region_set(C, ar1);
+ const OperatorRepeatContextHandle *context_info;
+ context_info = ED_operator_repeat_prepare_context(C, op);
if ((WM_operator_repeat_check(C, op)) &&
(WM_operator_poll(C, op->type)) &&
@@ -334,8 +362,6 @@ int ED_undo_operator_repeat(bContext *C, struct wmOperator *op)
{
int retval;
- ED_viewport_render_kill_jobs(wm, CTX_data_main(C), true);
-
if (G.debug & G_DEBUG)
printf("redo_cb: operator redo %s\n", op->type->name);
@@ -369,8 +395,7 @@ int ED_undo_operator_repeat(bContext *C, struct wmOperator *op)
}
}
- /* set region back */
- CTX_wm_region_set(C, ar);
+ ED_operator_repeat_reset_context(C, context_info);
}
else {
CLOG_WARN(&LOG, "called with NULL 'op'");
@@ -495,3 +520,24 @@ void ED_OT_undo_history(wmOperatorType *ot)
}
/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Undo Helper Functions
+ * \{ */
+
+void ED_undo_object_set_active_or_warn(ViewLayer *view_layer, Object *ob, const char *info, CLG_LogRef *log)
+{
+ Object *ob_prev = OBACT(view_layer);
+ if (ob_prev != ob) {
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+ if (base != NULL) {
+ view_layer->basact = base;
+ }
+ else {
+ /* Should never fail, may not crash but can give odd behavior. */
+ CLOG_WARN(log, "'%s' failed to restore active object: '%s'", info, ob->id.name + 2);
+ }
+ }
+}
+
+/** \} */
diff --git a/source/blender/editors/undo/memfile_undo.c b/source/blender/editors/undo/memfile_undo.c
index bb81da74f88..d45470ab0a1 100644
--- a/source/blender/editors/undo/memfile_undo.c
+++ b/source/blender/editors/undo/memfile_undo.c
@@ -76,6 +76,7 @@ static bool memfile_undosys_step_encode(struct bContext *C, UndoStep *us_p)
MemFileUndoStep *us_prev = (MemFileUndoStep *)BKE_undosys_step_find_by_type(ustack, BKE_UNDOSYS_TYPE_MEMFILE);
us->data = BKE_memfile_undo_encode(bmain, us_prev ? us_prev->data : NULL);
us->step.data_size = us->data->undo_size;
+
return true;
}
@@ -84,8 +85,6 @@ static void memfile_undosys_step_decode(struct bContext *C, UndoStep *us_p, int
/* Loading the content will correctly switch into compatible non-object modes. */
ED_object_mode_set(C, OB_MODE_OBJECT);
- /* This is needed so undoing/redoing doesn't crash with threaded previews going */
- ED_viewport_render_kill_jobs(CTX_wm_manager(C), CTX_data_main(C), true);
MemFileUndoStep *us = (MemFileUndoStep *)us_p;
BKE_memfile_undo_decode(us->data, C);
diff --git a/source/blender/editors/util/CMakeLists.txt b/source/blender/editors/util/CMakeLists.txt
index 8657c876d47..24cfde90804 100644
--- a/source/blender/editors/util/CMakeLists.txt
+++ b/source/blender/editors/util/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../blenlib
../../blentranslation
../../bmesh
+ ../../depsgraph
../../imbuf
../../gpu
../../makesdna
@@ -62,6 +63,7 @@ set(SRC
../include/ED_lattice.h
../include/ED_logic.h
../include/ED_markers.h
+ ../include/ED_manipulator_library.h
../include/ED_mask.h
../include/ED_mball.h
../include/ED_mesh.h
@@ -73,6 +75,7 @@ set(SRC
../include/ED_particle.h
../include/ED_physics.h
../include/ED_render.h
+ ../include/ED_scene.h
../include/ED_screen.h
../include/ED_screen_types.h
../include/ED_sculpt.h
diff --git a/source/blender/editors/util/ed_transverts.c b/source/blender/editors/util/ed_transverts.c
index c3fb653979c..494ae769cf3 100644
--- a/source/blender/editors/util/ed_transverts.c
+++ b/source/blender/editors/util/ed_transverts.c
@@ -39,12 +39,13 @@
#include "BLI_math.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_lattice.h"
#include "BKE_editmesh.h"
#include "BKE_DerivedMesh.h"
#include "BKE_context.h"
+#include "DEG_depsgraph.h"
+
#include "ED_armature.h"
#include "ED_transverts.h" /* own include */
@@ -56,7 +57,7 @@ void ED_transverts_update_obedit(TransVertStore *tvs, Object *obedit)
const int mode = tvs->mode;
BLI_assert(ED_transverts_check_obedit(obedit) == true);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
if (obedit->type == OB_MESH) {
BMEditMesh *em = BKE_editmesh_from_object(obedit);
diff --git a/source/blender/editors/util/ed_util.c b/source/blender/editors/util/ed_util.c
index 03d0b4a8d48..61a70d2da42 100644
--- a/source/blender/editors/util/ed_util.c
+++ b/source/blender/editors/util/ed_util.c
@@ -35,6 +35,7 @@
#include "MEM_guardedalloc.h"
+#include "DNA_armature_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "DNA_screen_types.h"
@@ -55,9 +56,12 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_multires.h"
+#include "BKE_object.h"
#include "BKE_packedFile.h"
#include "BKE_paint.h"
#include "BKE_screen.h"
+#include "BKE_workspace.h"
+#include "BKE_layer.h"
#include "BKE_undo_system.h"
#include "ED_armature.h"
@@ -71,6 +75,8 @@
#include "ED_space_api.h"
#include "ED_util.h"
+#include "GPU_immediate.h"
+
#include "UI_interface.h"
#include "UI_resources.h"
@@ -84,11 +90,8 @@
void ED_editors_init(bContext *C)
{
- wmWindowManager *wm = CTX_wm_manager(C);
Main *bmain = CTX_data_main(C);
- Scene *sce = CTX_data_scene(C);
- Object *ob, *obact = (sce && sce->basact) ? sce->basact->object : NULL;
- ID *data;
+ wmWindowManager *wm = CTX_wm_manager(C);
if (wm->undo_stack == NULL) {
wm->undo_stack = BKE_undosys_stack_create();
@@ -103,21 +106,31 @@ void ED_editors_init(bContext *C)
/* toggle on modes for objects that were saved with these enabled. for
* e.g. linked objects we have to ensure that they are actually the
* active object in this scene. */
- for (ob = bmain->object.first; ob; ob = ob->id.next) {
- int mode = ob->mode;
-
- if (!ELEM(mode, OB_MODE_OBJECT, OB_MODE_POSE)) {
- ob->mode = OB_MODE_OBJECT;
- data = ob->data;
+ Object *obact = CTX_data_active_object(C);
+ if (obact != NULL) {
+ for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
+ int mode = ob->mode;
- if (ob == obact && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data)))
- ED_object_mode_toggle(C, mode);
+ if (mode == OB_MODE_OBJECT) {
+ /* pass */
+ }
+ else if (!BKE_object_has_mode_data(ob, mode)) {
+ /* For multi-edit mode we may already have mode data. */
+ ID *data = ob->data;
+ ob->mode = OB_MODE_OBJECT;
+ if ((ob == obact) && !ID_IS_LINKED(ob) && !(data && ID_IS_LINKED(data))) {
+ ED_object_mode_toggle(C, mode);
+ }
+ }
}
}
/* image editor paint mode */
- if (sce) {
- ED_space_image_paint_update(wm, sce);
+ {
+ Scene *sce = CTX_data_scene(C);
+ if (sce) {
+ ED_space_image_paint_update(wm, sce);
+ }
}
SWAP(int, reports->flag, reports_flag_prev);
@@ -127,11 +140,10 @@ void ED_editors_init(bContext *C)
void ED_editors_exit(bContext *C)
{
Main *bmain = CTX_data_main(C);
- Scene *sce;
if (!bmain)
return;
-
+
/* frees all editmode undos */
if (G.main->wm.first) {
wmWindowManager *wm = G.main->wm.first;
@@ -142,22 +154,19 @@ void ED_editors_exit(bContext *C)
}
}
- for (sce = bmain->scene.first; sce; sce = sce->id.next) {
- if (sce->obedit) {
- Object *ob = sce->obedit;
-
- if (ob) {
- if (ob->type == OB_MESH) {
- Mesh *me = ob->data;
- if (me->edit_btmesh) {
- EDBM_mesh_free(me->edit_btmesh);
- MEM_freeN(me->edit_btmesh);
- me->edit_btmesh = NULL;
- }
- }
- else if (ob->type == OB_ARMATURE) {
- ED_armature_edit_free(ob->data);
- }
+ for (Object *ob = bmain->object.first; ob; ob = ob->id.next) {
+ if (ob->type == OB_MESH) {
+ Mesh *me = ob->data;
+ if (me->edit_btmesh) {
+ EDBM_mesh_free(me->edit_btmesh);
+ MEM_freeN(me->edit_btmesh);
+ me->edit_btmesh = NULL;
+ }
+ }
+ else if (ob->type == OB_ARMATURE) {
+ bArmature *arm = ob->data;
+ if (arm->edbo) {
+ ED_armature_edit_free(ob->data);
}
}
}
@@ -328,16 +337,28 @@ void ED_region_draw_mouse_line_cb(const bContext *C, ARegion *ar, void *arg_info
{
wmWindow *win = CTX_wm_window(C);
const float *mval_src = (float *)arg_info;
- const int mval_dst[2] = {win->eventstate->x - ar->winrct.xmin,
- win->eventstate->y - ar->winrct.ymin};
-
- UI_ThemeColor(TH_VIEW_OVERLAY);
- setlinestyle(3);
- glBegin(GL_LINES);
- glVertex2iv(mval_dst);
- glVertex2fv(mval_src);
- glEnd();
- setlinestyle(0);
+ const float mval_dst[2] = {win->eventstate->x - ar->winrct.xmin,
+ win->eventstate->y - ar->winrct.ymin};
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 0); /* "simple" mode */
+ immUniformThemeColor(TH_VIEW_OVERLAY);
+ immUniform1f("dash_width", 6.0f);
+ immUniform1f("dash_factor", 0.5f);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2fv(shdr_pos, mval_src);
+ immVertex2fv(shdr_pos, mval_dst);
+ immEnd();
+
+ immUnbindProgram();
}
/**
diff --git a/source/blender/editors/uvedit/CMakeLists.txt b/source/blender/editors/uvedit/CMakeLists.txt
index 543ef0e0663..a933717fe98 100644
--- a/source/blender/editors/uvedit/CMakeLists.txt
+++ b/source/blender/editors/uvedit/CMakeLists.txt
@@ -24,6 +24,7 @@ set(INC
../../blenlib
../../blentranslation
../../bmesh
+ ../../depsgraph
../../gpu
../../makesdna
../../makesrna
diff --git a/source/blender/editors/uvedit/uvedit_buttons.c b/source/blender/editors/uvedit/uvedit_buttons.c
index ab415c0cb83..f037783bd5e 100644
--- a/source/blender/editors/uvedit/uvedit_buttons.c
+++ b/source/blender/editors/uvedit/uvedit_buttons.c
@@ -61,22 +61,19 @@
/* UV Utilities */
-static int uvedit_center(Scene *scene, BMEditMesh *em, Image *ima, float center[2])
+static int uvedit_center(Scene *scene, Object *obedit, BMEditMesh *em, Image *ima, float center[2])
{
BMFace *f;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
int tot = 0;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
zero_v2(center);
BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(f, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, f, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, f))
continue;
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
@@ -96,20 +93,17 @@ static int uvedit_center(Scene *scene, BMEditMesh *em, Image *ima, float center[
return tot;
}
-static void uvedit_translate(Scene *scene, BMEditMesh *em, Image *ima, float delta[2])
+static void uvedit_translate(Scene *scene, Object *obedit, BMEditMesh *em, Image *ima, float delta[2])
{
BMFace *f;
BMLoop *l;
BMIter iter, liter;
MLoopUV *luv;
- MTexPoly *tf;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_ITER_MESH (f, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(f, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, f, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, f))
continue;
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
@@ -140,7 +134,7 @@ static void uvedit_vertex_buttons(const bContext *C, uiBlock *block)
em = BKE_editmesh_from_object(obedit);
- if (uvedit_center(scene, em, ima, center)) {
+ if (uvedit_center(scene, obedit, em, ima, center)) {
float range_xy[2][2] = {
{-10.0f, 10.0f},
{-10.0f, 10.0f},
@@ -196,7 +190,7 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event)
em = BKE_editmesh_from_object(obedit);
ED_space_image_get_size(sima, &imx, &imy);
- uvedit_center(scene, em, ima, center);
+ uvedit_center(scene, obedit, em, ima, center);
if (sima->flag & SI_COORDFLOATS) {
delta[0] = uvedit_old_center[0] - center[0];
@@ -207,7 +201,7 @@ static void do_uvedit_vertex(bContext *C, void *UNUSED(arg), int event)
delta[1] = uvedit_old_center[1] / imy - center[1];
}
- uvedit_translate(scene, em, ima, delta);
+ uvedit_translate(scene, obedit, em, ima, delta);
WM_event_add_notifier(C, NC_IMAGE, sima->image);
}
diff --git a/source/blender/editors/uvedit/uvedit_draw.c b/source/blender/editors/uvedit/uvedit_draw.c
index 7b793697077..beaae691e5e 100644
--- a/source/blender/editors/uvedit/uvedit_draw.c
+++ b/source/blender/editors/uvedit/uvedit_draw.c
@@ -33,6 +33,8 @@
#include <stdlib.h>
#include <string.h>
+#include "MEM_guardedalloc.h"
+
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
@@ -49,12 +51,20 @@
#include "BKE_DerivedMesh.h"
#include "BKE_editmesh.h"
#include "BKE_material.h"
+#include "BKE_layer.h"
#include "BKE_scene.h"
-#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
+#include "GPU_batch.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+
#include "ED_image.h"
#include "ED_mesh.h"
#include "ED_uvedit.h"
@@ -65,12 +75,7 @@
#include "uvedit_intern.h"
-#include "GPU_basic_shader.h"
-
-/* use editmesh tessface */
-#define USE_EDBM_LOOPTRIS
-
-static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset);
+static void draw_uvs_lineloop_bmfaces(BMesh *bm, const int cd_loop_uv_offset, const uint shdr_pos);
void ED_image_draw_cursor(ARegion *ar, const float cursor[2])
{
@@ -81,38 +86,59 @@ void ED_image_draw_cursor(ARegion *ar, const float cursor[2])
mul_v2_fl(zoom, 256.0f * UI_DPI_FAC);
x_fac = zoom[0];
y_fac = zoom[1];
-
- cpack(0xFFFFFF);
- glTranslate2fv(cursor);
- fdrawline(-0.05f * x_fac, 0, 0, 0.05f * y_fac);
- fdrawline(0, 0.05f * y_fac, 0.05f * x_fac, 0.0f);
- fdrawline(0.05f * x_fac, 0.0f, 0.0f, -0.05f * y_fac);
- fdrawline(0.0f, -0.05f * y_fac, -0.05f * x_fac, 0.0f);
-
- setlinestyle(4);
- cpack(0xFF);
- fdrawline(-0.05f * x_fac, 0.0f, 0.0f, 0.05f * y_fac);
- fdrawline(0.0f, 0.05f * y_fac, 0.05f * x_fac, 0.0f);
- fdrawline(0.05f * x_fac, 0.0f, 0.0f, -0.05f * y_fac);
- fdrawline(0.0f, -0.05f * y_fac, -0.05f * x_fac, 0.0f);
-
-
- setlinestyle(0.0f);
- cpack(0x0);
- fdrawline(-0.020f * x_fac, 0.0f, -0.1f * x_fac, 0.0f);
- fdrawline(0.1f * x_fac, 0.0f, 0.020f * x_fac, 0.0f);
- fdrawline(0.0f, -0.020f * y_fac, 0.0f, -0.1f * y_fac);
- fdrawline(0.0f, 0.1f * y_fac, 0.0f, 0.020f * y_fac);
-
- setlinestyle(1);
- cpack(0xFFFFFF);
- fdrawline(-0.020f * x_fac, 0.0f, -0.1f * x_fac, 0.0f);
- fdrawline(0.1f * x_fac, 0.0f, 0.020f * x_fac, 0.0f);
- fdrawline(0.0f, -0.020f * y_fac, 0.0f, -0.1f * y_fac);
- fdrawline(0.0f, 0.1f * y_fac, 0.0f, 0.020f * y_fac);
-
- glTranslatef(-cursor[0], -cursor[1], 0.0);
- setlinestyle(0);
+
+ gpuTranslate2fv(cursor);
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 0.0f, 0.0f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 8.0f);
+
+ immBegin(GWN_PRIM_LINES, 8);
+
+ immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f);
+ immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac);
+
+ immVertex2f(shdr_pos, 0.0f, 0.05f * y_fac);
+ immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f);
+
+ immVertex2f(shdr_pos, 0.05f * x_fac, 0.0f);
+ immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac);
+
+ immVertex2f(shdr_pos, 0.0f, -0.05f * y_fac);
+ immVertex2f(shdr_pos, -0.05f * x_fac, 0.0f);
+
+ immEnd();
+
+ immUniformArray4fv("colors", (float *)(float[][4]){{1.0f, 1.0f, 1.0f, 1.0f}, {0.0f, 0.0f, 0.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 2.0f);
+
+ immBegin(GWN_PRIM_LINES, 8);
+
+ immVertex2f(shdr_pos, -0.020f * x_fac, 0.0f);
+ immVertex2f(shdr_pos, -0.1f * x_fac, 0.0f);
+
+ immVertex2f(shdr_pos, 0.1f * x_fac, 0.0f);
+ immVertex2f(shdr_pos, 0.020f * x_fac, 0.0f);
+
+ immVertex2f(shdr_pos, 0.0f, -0.020f * y_fac);
+ immVertex2f(shdr_pos, 0.0f, -0.1f * y_fac);
+
+ immVertex2f(shdr_pos, 0.0f, 0.1f * y_fac);
+ immVertex2f(shdr_pos, 0.0f, 0.020f * y_fac);
+
+ immEnd();
+
+ immUnbindProgram();
+
+ gpuTranslate2f(-cursor[0], -cursor[1]);
}
static int draw_uvs_face_check(Scene *scene)
@@ -136,46 +162,33 @@ static void draw_uvs_shadow(Object *obedit)
{
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMesh *bm = em->bm;
- BMFace *efa;
- BMIter iter;
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- /* draws the mesh when painting */
- UI_ThemeColor(TH_UV_SHADOW);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset);
- }
-}
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
-static int draw_uvs_dm_shadow(DerivedMesh *dm)
-{
- /* draw shadow mesh - this is the mesh with the modifier applied */
+ /* draws the mesh when painting */
+ immUniformThemeColor(TH_UV_SHADOW);
- if (dm && dm->drawUVEdges && CustomData_has_layer(&dm->loopData, CD_MLOOPUV)) {
- UI_ThemeColor(TH_UV_SHADOW);
- dm->drawUVEdges(dm);
- return 1;
- }
+ draw_uvs_lineloop_bmfaces(bm, cd_loop_uv_offset, pos);
- return 0;
+ immUnbindProgram();
}
-static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTexPoly *activetf)
+static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, Object *obedit, BMEditMesh *em, const BMFace *efa_act)
{
BMesh *bm = em->bm;
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
Image *ima = sima->image;
float aspx, aspy, col[4];
int i;
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
BLI_buffer_declare_static(vec2f, tf_uv_buf, BLI_BUFFER_NOP, BM_DEFAULT_NGON_STACK_SIZE);
BLI_buffer_declare_static(vec2f, tf_uvorig_buf, BLI_BUFFER_NOP, BM_DEFAULT_NGON_STACK_SIZE);
@@ -191,7 +204,6 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
const int efa_len = efa->len;
float (*tf_uv)[2] = (float (*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, efa_len);
float (*tf_uvorig)[2] = (float (*)[2])BLI_buffer_reinit_data(&tf_uvorig_buf, vec2f, efa_len);
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
@@ -203,28 +215,37 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
totarea += BM_face_calc_area(efa);
totuvarea += area_poly_v2(tf_uv, efa->len);
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
BM_elem_flag_enable(efa, BM_ELEM_TAG);
}
else {
- if (tf == activetf)
- activetf = NULL;
+ if (efa == efa_act) {
+ efa_act = NULL;
+ }
BM_elem_flag_disable(efa, BM_ELEM_TAG);
}
}
-
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
if (totarea < FLT_EPSILON || totuvarea < FLT_EPSILON) {
col[0] = 1.0;
col[1] = col[2] = 0.0;
- glColor3fv(col);
+
+ immUniformColor3fv(col);
+
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
- glBegin(GL_POLYGON);
+ immBegin(GWN_PRIM_TRI_FAN, efa->len);
+
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
}
- glEnd();
+
+ immEnd();
}
}
}
@@ -254,18 +275,23 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
areadiff = 1.0f - (area / uvarea);
weight_to_rgb(col, areadiff);
- glColor3fv(col);
+ immUniformColor3fv(col);
- /* TODO: USE_EDBM_LOOPTRIS */
- glBegin(GL_POLYGON);
+ /* TODO: use editmesh tessface */
+ immBegin(GWN_PRIM_TRI_FAN, efa->len);
+
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
}
- glEnd();
+
+ immEnd();
}
}
}
+
+ immUnbindProgram();
+
break;
}
case SI_UVDT_STRETCH_ANGLE:
@@ -278,11 +304,15 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
BLI_buffer_declare_static(vec2f, auv_buf, BLI_BUFFER_NOP, BM_DEFAULT_NGON_STACK_SIZE);
col[3] = 0.5f; /* hard coded alpha, not that nice */
-
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_SMOOTH_COLOR);
+
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
const int efa_len = efa->len;
float (*tf_uv)[2] = (float (*)[2])BLI_buffer_reinit_data(&tf_uv_buf, vec2f, efa_len);
float (*tf_uvorig)[2] = (float (*)[2])BLI_buffer_reinit_data(&tf_uvorig_buf, vec2f, efa_len);
@@ -319,24 +349,26 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
ang[i] = angle_normalized_v3v3(av[i], av[(i + 1) % efa_len]);
}
- /* TODO: USE_EDBM_LOOPTRIS */
- glBegin(GL_POLYGON);
+ /* TODO: use editmesh tessface */
+ immBegin(GWN_PRIM_TRI_FAN, efa->len);
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
a = fabsf(uvang[i] - ang[i]) / (float)M_PI;
weight_to_rgb(col, 1.0f - pow2f(1.0f - a));
- glColor3fv(col);
- glVertex2fv(luv->uv);
+ immAttrib3fv(color, col);
+ immVertex2fv(pos, luv->uv);
}
- glEnd();
+ immEnd();
}
else {
- if (tf == activetf)
- activetf = NULL;
+ if (efa == efa_act)
+ efa_act = NULL;
BM_elem_flag_disable(efa, BM_ELEM_TAG);
}
}
+ immUnbindProgram();
+
BLI_buffer_free(&uvang_buf);
BLI_buffer_free(&ang_buf);
BLI_buffer_free(&av_buf);
@@ -350,58 +382,62 @@ static void draw_uvs_stretch(SpaceImage *sima, Scene *scene, BMEditMesh *em, MTe
BLI_buffer_free(&tf_uvorig_buf);
}
-static void draw_uvs_lineloop_bmface(BMFace *efa, const int cd_loop_uv_offset)
+static void draw_uvs_lineloop_bmfaces(BMesh *bm, const int cd_loop_uv_offset, const uint shdr_pos)
{
- BMIter liter;
+ BMIter iter, liter;
+ BMFace *efa;
BMLoop *l;
MLoopUV *luv;
- glBegin(GL_LINE_LOOP);
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
+ /* For more efficiency first transfer the entire buffer to vram. */
+ Gwn_Batch *loop_batch = immBeginBatchAtMost(GWN_PRIM_LINE_LOOP, bm->totloop);
+
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
+ continue;
+
+ BM_ITER_ELEM(l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ immVertex2fv(shdr_pos, luv->uv);
+ }
+ }
+ immEnd();
+
+ /* Then draw each face contour separately. */
+ GWN_batch_program_use_begin(loop_batch);
+ unsigned int index = 0;
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
+ continue;
+
+ GWN_batch_draw_range_ex(loop_batch, index, efa->len, false);
+ index += efa->len;
}
- glEnd();
+ GWN_batch_program_use_end(loop_batch);
+ GWN_batch_discard(loop_batch);
+
+ immUnbindProgram();
+
+ immEnd();
}
-static void draw_uvs_lineloop_mpoly(Mesh *me, MPoly *mpoly)
+static void draw_uvs_lineloop_mpoly(Mesh *me, MPoly *mpoly, unsigned int pos)
{
MLoopUV *mloopuv;
int i;
- glBegin(GL_LINE_LOOP);
+ immBegin(GWN_PRIM_LINE_LOOP, mpoly->totloop);
+
mloopuv = &me->mloopuv[mpoly->loopstart];
for (i = mpoly->totloop; i != 0; i--, mloopuv++) {
- glVertex2fv(mloopuv->uv);
+ immVertex2fv(pos, mloopuv->uv);
}
- glEnd();
-}
-
-static void draw_uvs_other_mesh_texface(Object *ob, const Image *curimage, const int other_uv_filter)
-{
- Mesh *me = ob->data;
- MPoly *mpoly = me->mpoly;
- MTexPoly *mtpoly = me->mtpoly;
- int a;
-
- if (me->mloopuv == NULL) {
- return;
- }
-
- for (a = me->totpoly; a != 0; a--, mpoly++, mtpoly++) {
- if (other_uv_filter == SI_FILTER_ALL) {
- /* Nothing to compare, all UV faces are visible. */
- }
- else if (other_uv_filter == SI_FILTER_SAME_IMAGE) {
- if (mtpoly->tpage != curimage) {
- continue;
- }
- }
- draw_uvs_lineloop_mpoly(me, mpoly);
- }
+ immEnd();
}
-static void draw_uvs_other_mesh_new_shading(Object *ob, const Image *curimage, const int other_uv_filter)
+
+static void draw_uvs_other_mesh(Object *ob, const Image *curimage,
+ const int other_uv_filter, unsigned int pos)
{
Mesh *me = ob->data;
MPoly *mpoly = me->mpoly;
@@ -453,53 +489,42 @@ static void draw_uvs_other_mesh_new_shading(Object *ob, const Image *curimage, c
}
}
- draw_uvs_lineloop_mpoly(me, mpoly);
- }
-}
-static void draw_uvs_other_mesh(Object *ob, const Image *curimage, const bool new_shading_nodes,
- const int other_uv_filter)
-{
- if (new_shading_nodes) {
- draw_uvs_other_mesh_new_shading(ob, curimage, other_uv_filter);
- }
- else {
- draw_uvs_other_mesh_texface(ob, curimage, other_uv_filter);
+ draw_uvs_lineloop_mpoly(me, mpoly, pos);
}
}
-static void draw_uvs_other(Scene *scene, Object *obedit, const Image *curimage, const bool new_shading_nodes,
+static void draw_uvs_other(ViewLayer *view_layer, Object *obedit, const Image *curimage,
const int other_uv_filter)
{
- Base *base;
-
- UI_ThemeColor(TH_UV_OTHERS);
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- for (base = scene->base.first; base; base = base->next) {
- Object *ob = base->object;
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
- if (!(base->flag & SELECT)) continue;
- if (!(base->lay & scene->lay)) continue;
- if (ob->restrictflag & OB_RESTRICT_VIEW) continue;
+ immUniformThemeColor(TH_UV_OTHERS);
- if ((ob->type == OB_MESH) && (ob != obedit) && ((Mesh *)ob->data)->mloopuv) {
- draw_uvs_other_mesh(ob, curimage, new_shading_nodes, other_uv_filter);
+ for (Base *base = view_layer->object_bases.first; base; base = base->next) {
+ if (((base->flag & BASE_SELECTED) != 0) &&
+ ((base->flag & BASE_VISIBLED) != 0))
+ {
+ Object *ob = base->object;
+ if ((ob->type == OB_MESH) && (ob != obedit) && ((Mesh *)ob->data)->mloopuv) {
+ draw_uvs_other_mesh(ob, curimage, other_uv_filter, pos);
+ }
}
}
+ immUnbindProgram();
}
-static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob)
+static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, ViewLayer *view_layer, Object *ob)
{
- const bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene);
Image *curimage = ED_space_image(sima);
Mesh *me = ob->data;
Material *ma;
if (sima->flag & SI_DRAW_OTHER) {
- draw_uvs_other(scene, ob, curimage, new_shading_nodes, sima->other_uv_filter);
+ draw_uvs_other(view_layer, ob, curimage, sima->other_uv_filter);
}
- UI_ThemeColor(TH_UV_SHADOW);
-
ma = give_current_material(ob, ob->actcol);
if (me->mloopuv) {
@@ -512,24 +537,33 @@ static void draw_uvs_texpaint(SpaceImage *sima, Scene *scene, Object *ob)
mloopuv = me->mloopuv;
}
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformThemeColor(TH_UV_SHADOW);
+
mloopuv_base = mloopuv;
for (a = me->totpoly; a > 0; a--, mpoly++) {
if ((scene->toolsettings->uv_flag & UV_SHOW_SAME_IMAGE) && mpoly->mat_nr != ob->actcol - 1)
continue;
- glBegin(GL_LINE_LOOP);
+
+ immBegin(GWN_PRIM_LINE_LOOP, mpoly->totloop);
mloopuv = mloopuv_base + mpoly->loopstart;
for (b = 0; b < mpoly->totloop; b++, mloopuv++) {
- glVertex2fv(mloopuv->uv);
+ immVertex2fv(pos, mloopuv->uv);
}
- glEnd();
+
+ immEnd();
}
+
+ immUnbindProgram();
}
}
-#ifdef USE_EDBM_LOOPTRIS
-static void draw_uvs_looptri(BMEditMesh *em, unsigned int *r_loop_index, const int cd_loop_uv_offset)
+static void draw_uvs_looptri(BMEditMesh *em, unsigned int *r_loop_index, const int cd_loop_uv_offset, unsigned int pos)
{
unsigned int i = *r_loop_index;
BMFace *f = em->looptris[i][0]->f;
@@ -537,43 +571,34 @@ static void draw_uvs_looptri(BMEditMesh *em, unsigned int *r_loop_index, const i
unsigned int j;
for (j = 0; j < 3; j++) {
MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(em->looptris[i][j], cd_loop_uv_offset);
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
}
i++;
} while (i != em->tottri && (f == em->looptris[i][0]->f));
*r_loop_index = i - 1;
}
-#endif
/* draws uv's in the image space */
-static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
+static void draw_uvs(SpaceImage *sima, Scene *scene, ViewLayer *view_layer, Object *obedit, Depsgraph *depsgraph)
{
- const bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene);
ToolSettings *ts;
Mesh *me = obedit->data;
BMEditMesh *em = me->edit_btmesh;
BMesh *bm = em->bm;
BMFace *efa, *efa_act;
-#ifndef USE_EDBM_LOOPTRIS
- BMFace *activef;
-#endif
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf, *activetf = NULL;
MLoopUV *luv;
- DerivedMesh *finaldm, *cagedm;
- unsigned char col1[4], col2[4];
+ float col1[4], col2[4];
float pointsize;
int drawfaces, interpedges;
Image *ima = sima->image;
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
- efa_act = EDBM_uv_active_face_get(em, false, false, &activetf); /* will be set to NULL if hidden */
-#ifndef USE_EDBM_LOOPTRIS
- activef = BM_mesh_active_face_get(bm, false, false);
-#endif
+ unsigned int pos, color;
+
+ efa_act = EDBM_uv_active_face_get(em, false, false); /* will be set to NULL if hidden */
ts = scene->toolsettings;
drawfaces = draw_uvs_face_check(scene);
@@ -586,271 +611,278 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
if (sima->flag & SI_DRAW_OTHER) {
Image *curimage;
- if (new_shading_nodes) {
- if (efa_act) {
- ED_object_get_active_image(obedit, efa_act->mat_nr + 1, &curimage, NULL, NULL, NULL);
- }
- else {
- curimage = ima;
- }
+ if (efa_act) {
+ ED_object_get_active_image(obedit, efa_act->mat_nr + 1, &curimage, NULL, NULL, NULL);
}
else {
- curimage = (activetf) ? activetf->tpage : ima;
+ curimage = ima;
}
- draw_uvs_other(scene, obedit, curimage, new_shading_nodes, sima->other_uv_filter);
+ draw_uvs_other(view_layer, obedit, curimage, sima->other_uv_filter);
}
/* 1. draw shadow mesh */
if (sima->flag & SI_DRAWSHADOW) {
- DM_update_materials(em->derivedFinal, obedit);
- /* first try existing derivedmesh */
- if (!draw_uvs_dm_shadow(em->derivedFinal)) {
- /* create one if it does not exist */
- cagedm = editbmesh_get_derived_cage_and_final(
- scene, obedit, me->edit_btmesh, CD_MASK_BAREMESH | CD_MASK_MTFACE,
- &finaldm);
-
- /* when sync selection is enabled, all faces are drawn (except for hidden)
- * so if cage is the same as the final, theres no point in drawing this */
- if (!((ts->uv_flag & UV_SYNC_SELECTION) && (cagedm == finaldm)))
- draw_uvs_dm_shadow(finaldm);
-
- /* release derivedmesh again */
- if (cagedm != finaldm) cagedm->release(cagedm);
- finaldm->release(finaldm);
+ Object *ob_cage = DEG_get_evaluated_object(depsgraph, obedit);
+ /* XXX TODO: Need to check if shadow mesh is different than original mesh. */
+ bool is_cage_like_final_meshes = (ob_cage == obedit);
+
+ /* When sync selection is enabled, all faces are drawn (except for hidden)
+ * so if cage is the same as the final, there is no point in drawing this. */
+ if (((ts->uv_flag & UV_SYNC_SELECTION) == 0) || is_cage_like_final_meshes) {
+ draw_uvs_shadow(ob_cage);
}
}
-
+
/* 2. draw colored faces */
if (sima->flag & SI_DRAW_STRETCH) {
- draw_uvs_stretch(sima, scene, em, activetf);
+ draw_uvs_stretch(sima, scene, obedit, em, efa_act);
}
- else if (!(sima->flag & SI_NO_DRAWFACES)) {
- /* draw transparent faces */
- UI_GetThemeColor4ubv(TH_FACE, col1);
- UI_GetThemeColor4ubv(TH_FACE_SELECT, col2);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
-
-#ifdef USE_EDBM_LOOPTRIS
- {
- unsigned int i;
- for (i = 0; i < em->tottri; i++) {
+ else {
+ unsigned int tri_count = 0;
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
+ BM_elem_flag_enable(efa, BM_ELEM_TAG);
+ tri_count += efa->len - 2;
+ }
+ else {
+ BM_elem_flag_disable(efa, BM_ELEM_TAG);
+ }
+ }
+
+ if (tri_count && !(sima->flag & SI_NO_DRAWFACES)) {
+ /* draw transparent faces */
+ UI_GetThemeColor4fv(TH_FACE, col1);
+ UI_GetThemeColor4fv(TH_FACE_SELECT, col2);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable(GL_BLEND);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ Gwn_Batch *face_batch = immBeginBatch(GWN_PRIM_TRIS, tri_count * 3);
+ for (unsigned int i = 0; i < em->tottri; i++) {
efa = em->looptris[i][0]->f;
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (BM_elem_flag_test(efa, BM_ELEM_TAG)) {
const bool is_select = uvedit_face_select_test(scene, efa, cd_loop_uv_offset);
- BM_elem_flag_enable(efa, BM_ELEM_TAG);
- if (tf == activetf) {
+ if (efa == efa_act) {
/* only once */
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
- UI_ThemeColor4(TH_EDITMESH_ACTIVE);
+ float tmp_col[4];
+ UI_GetThemeColor4fv(TH_EDITMESH_ACTIVE, tmp_col);
+ immAttrib4fv(color, tmp_col);
}
else {
- glColor4ubv((GLubyte *)(is_select ? col2 : col1));
+ immAttrib4fv(color, is_select ? col2 : col1);
}
- glBegin(GL_TRIANGLES);
- draw_uvs_looptri(em, &i, cd_loop_uv_offset);
- glEnd();
-
- if (tf == activetf) {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- }
- }
- else {
- BM_elem_flag_disable(efa, BM_ELEM_TAG);
+ draw_uvs_looptri(em, &i, cd_loop_uv_offset, pos);
}
}
- }
-#else
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
- BM_elem_flag_enable(efa, BM_ELEM_TAG);
- if (tf == activetf) continue; /* important the temp boolean is set above */
+ immEnd();
- if (uvedit_face_select_test(scene, efa, cd_loop_uv_offset))
- glColor4ubv((GLubyte *)col2);
- else
- glColor4ubv((GLubyte *)col1);
-
- glBegin(GL_POLYGON);
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
- }
- glEnd();
- }
- else {
- if (tf == activetf)
- activetf = NULL;
- BM_elem_flag_disable(efa, BM_ELEM_TAG);
- }
- }
-#endif
- glDisable(GL_BLEND);
- }
- else {
- /* would be nice to do this within a draw loop but most below are optional, so it would involve too many checks */
-
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
+ /* XXX performance: we should not create and throw away result. */
+ GWN_batch_draw(face_batch);
+ GWN_batch_program_use_end(face_batch);
+ GWN_batch_discard(face_batch);
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
- BM_elem_flag_enable(efa, BM_ELEM_TAG);
- }
- else {
- if (tf == activetf)
- activetf = NULL;
- BM_elem_flag_disable(efa, BM_ELEM_TAG);
+ immUnbindProgram();
+
+ glDisable(GL_BLEND);
+ }
+ else {
+ if (efa_act && !uvedit_face_visible_test(scene, obedit, ima, efa_act)) {
+ efa_act = NULL;
}
}
-
}
/* 3. draw active face stippled */
-#ifndef USE_EDBM_LOOPTRIS
- if (activef) {
- tf = BM_ELEM_CD_GET_VOID_P(activef, cd_poly_tex_offset);
- if (uvedit_face_visible_test(scene, ima, activef, tf)) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- UI_ThemeColor4(TH_EDITMESH_ACTIVE);
+ /* (removed during OpenGL upgrade, reimplement if needed) */
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_QUARTTONE);
-
- glBegin(GL_POLYGON);
- BM_ITER_ELEM (l, &liter, activef, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
- }
- glEnd();
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- glDisable(GL_BLEND);
- }
- }
-#endif
-
/* 4. draw edges */
if (sima->flag & SI_SMOOTH_UV) {
glEnable(GL_LINE_SMOOTH);
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
- glLineWidth(1);
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
switch (sima->dt_uv) {
case SI_UVDT_DASH:
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
- continue;
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (tf) {
- cpack(0x111111);
-
- draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset);
+ {
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
- setlinestyle(2);
- cpack(0x909090);
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2] / UI_DPI_FAC, viewport_size[3] / UI_DPI_FAC);
- draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset);
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.56f, 0.56f, 0.56f, 1.0f}, {0.07f, 0.07f, 0.07f, 1.0f}}, 2);
+ immUniform1f("dash_width", 4.0f);
+ glLineWidth(1.0f);
- setlinestyle(0);
- }
- }
break;
+ }
case SI_UVDT_BLACK: /* black/white */
- case SI_UVDT_WHITE:
- if (sima->dt_uv == SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f);
- else glColor3f(0.0f, 0.0f, 0.0f);
-
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
- continue;
-
- draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset);
+ case SI_UVDT_WHITE:
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ if (sima->dt_uv == SI_UVDT_WHITE) {
+ immUniformColor3f(1.0f, 1.0f, 1.0f);
+ }
+ else {
+ immUniformColor3f(0.0f, 0.0f, 0.0f);
}
+ glLineWidth(1.0f);
+
break;
case SI_UVDT_OUTLINE:
- glLineWidth(3);
- cpack(0x0);
-
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
- if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
- continue;
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ imm_cpack(0x0);
+ glLineWidth(3.0f);
- draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset);
- }
-
- glLineWidth(1);
- UI_GetThemeColor4ubv(TH_WIRE_EDIT, col2);
- glColor4ubv((unsigned char *)col2);
+ break;
+ }
+
+ /* For more efficiency first transfer the entire buffer to vram. */
+ Gwn_Batch *loop_batch = immBeginBatchAtMost(GWN_PRIM_LINE_LOOP, bm->totloop);
+ Gwn_VertBuf *loop_vbo = loop_batch->verts[0];
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
+ continue;
+
+ BM_ITER_ELEM(l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ immVertex2fv(pos, luv->uv);
+ }
+ }
+ immEnd();
+
+ /* Then draw each face contour separately. */
+ if (loop_vbo->vertex_ct != 0) {
+ GWN_batch_program_use_begin(loop_batch);
+ unsigned int index = 0, loop_vbo_count;
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
+ continue;
+
+ GWN_batch_draw_range_ex(loop_batch, index, efa->len, false);
+ index += efa->len;
+ }
+ loop_vbo_count = index;
+ GWN_batch_program_use_end(loop_batch);
+ immUnbindProgram();
+
+
+ if (sima->dt_uv == SI_UVDT_OUTLINE) {
+ glLineWidth(1.0f);
+ UI_GetThemeColor4fv(TH_WIRE_EDIT, col2);
if (me->drawflag & ME_DRAWEDGES) {
- int sel, lastsel = -1;
- UI_GetThemeColor4ubv(TH_EDGE_SELECT, col1);
+ int sel;
+ UI_GetThemeColor4fv(TH_EDGE_SELECT, col1);
if (interpedges) {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+ /* Create a color buffer. */
+ static Gwn_VertFormat format = { 0 };
+ static uint shdr_col;
+ if (format.attrib_ct == 0) {
+ shdr_col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo_col = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo_col, loop_vbo_count);
+
+ index = 0;
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
- glBegin(GL_LINE_LOOP);
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ BM_ITER_ELEM(l, &liter, efa, BM_LOOPS_OF_FACE) {
sel = uvedit_uv_select_test(scene, l, cd_loop_uv_offset);
- glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2);
-
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
+ GWN_vertbuf_attr_set(vbo_col, shdr_col, index++, sel ? col1 : col2);
}
- glEnd();
}
+ /* Reuse the UV buffer and add the color buffer. */
+ GWN_batch_vertbuf_add_ex(loop_batch, vbo_col, true);
+
+ /* Now draw each face contour separately with another builtin program. */
+ GWN_batch_program_set_builtin(loop_batch, GPU_SHADER_2D_SMOOTH_COLOR);
+ gpuBindMatrices(loop_batch->interface);
+
+ GWN_batch_program_use_begin(loop_batch);
+ index = 0;
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
+ continue;
+
+ GWN_batch_draw_range_ex(loop_batch, index, efa->len, false);
+ index += efa->len;
+ }
+ GWN_batch_program_use_end(loop_batch);
}
else {
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+ Gwn_VertFormat *format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 4, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
+ /* Use batch here to avoid problems with `IMM_BUFFER_SIZE`. */
+ Gwn_Batch *flat_edges_batch = immBeginBatchAtMost(GWN_PRIM_LINES, loop_vbo_count * 2);
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
- glBegin(GL_LINES);
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ BM_ITER_ELEM(l, &liter, efa, BM_LOOPS_OF_FACE) {
sel = uvedit_edge_select_test(scene, l, cd_loop_uv_offset);
- if (sel != lastsel) {
- glColor4ubv(sel ? (GLubyte *)col1 : (GLubyte *)col2);
- lastsel = sel;
- }
+ immAttrib4fv(color, sel ? col1 : col2);
+
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
luv = BM_ELEM_CD_GET_VOID_P(l->next, cd_loop_uv_offset);
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
}
- glEnd();
}
+ immEnd();
+
+ GWN_batch_draw(flat_edges_batch);
+ GWN_batch_discard(flat_edges_batch);
+
+ immUnbindProgram();
}
}
else {
+ GWN_batch_uniform_4fv(loop_batch, "color", col2);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* no nice edges */
- BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
+ GWN_batch_program_use_begin(loop_batch);
+ index = 0;
+ BM_ITER_MESH(efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
-
- draw_uvs_lineloop_bmface(efa, cd_loop_uv_offset);
+
+ GWN_batch_draw_range_ex(loop_batch, index, efa->len, false);
+ index += efa->len;
}
+ GWN_batch_program_use_end(loop_batch);
+ immUnbindProgram();
}
-
- break;
+ }
}
+ else {
+ immUnbindProgram();
+ }
+
+ GWN_batch_discard(loop_batch);
if (sima->flag & SI_SMOOTH_UV) {
glDisable(GL_LINE_SMOOTH);
@@ -861,50 +893,80 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
if (drawfaces) {
float cent[2];
-
+ bool col_set = false;
+
+ Gwn_VertFormat *format = immVertexFormat();
+ pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ color = GWN_vertformat_attr_add(format, "color", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
+
pointsize = UI_GetThemeValuef(TH_FACEDOT_SIZE);
glPointSize(pointsize);
- glBegin(GL_POINTS);
+ immBeginAtMost(GWN_PRIM_POINTS, bm->totface);
/* unselected faces */
- UI_ThemeColor(TH_WIRE);
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
if (!uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) {
+ /* Only set color for the first face */
+ if (!col_set) {
+ UI_GetThemeColor3fv(TH_WIRE, col1);
+ immAttrib3fv(color, col1);
+
+ col_set = true;
+ }
+
uv_poly_center(efa, cent, cd_loop_uv_offset);
- glVertex2fv(cent);
+ immVertex2fv(pos, cent);
}
}
+ col_set = false;
+
/* selected faces */
- UI_ThemeColor(TH_FACE_DOT);
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
if (uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) {
+ /* Only set color for the first face */
+ if (!col_set) {
+ UI_GetThemeColor3fv(TH_FACE_DOT, col1);
+ immAttrib3fv(color, col1);
+
+ col_set = true;
+ }
+
uv_poly_center(efa, cent, cd_loop_uv_offset);
- glVertex2fv(cent);
+ immVertex2fv(pos, cent);
}
}
- glEnd();
+ immEnd();
+
+ immUnbindProgram();
}
/* 6. draw uv vertices */
if (drawfaces != 2) { /* 2 means Mesh Face Mode */
+ pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
/* unselected uvs */
- UI_ThemeColor(TH_VERTEX);
+ immUniformThemeColor(TH_VERTEX);
pointsize = UI_GetThemeValuef(TH_VERTEX_SIZE);
glPointSize(pointsize);
-
- glBegin(GL_POINTS);
+
+ immBeginAtMost(GWN_PRIM_POINTS, bm->totloop);
+
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
@@ -912,17 +974,19 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
if (!uvedit_uv_select_test(scene, l, cd_loop_uv_offset))
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
}
}
- glEnd();
+
+ immEnd();
/* pinned uvs */
/* give odd pointsizes odd pin pointsizes */
glPointSize(pointsize * 2 + (((int)pointsize % 2) ? (-1) : 0));
- cpack(0xFF);
+ imm_cpack(0xFF);
- glBegin(GL_POINTS);
+ immBeginAtMost(GWN_PRIM_POINTS, bm->totloop);
+
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
@@ -931,16 +995,18 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
if (luv->flag & MLOOPUV_PINNED)
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
}
}
- glEnd();
+
+ immEnd();
/* selected uvs */
- UI_ThemeColor(TH_VERTEX_SELECT);
+ immUniformThemeColor(TH_VERTEX_SELECT);
glPointSize(pointsize);
- glBegin(GL_POINTS);
+ immBeginAtMost(GWN_PRIM_POINTS, bm->totloop);
+
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_TAG))
continue;
@@ -949,15 +1015,20 @@ static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit)
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))
- glVertex2fv(luv->uv);
+ immVertex2fv(pos, luv->uv);
}
}
- glEnd();
+
+ immEnd();
+
+ immUnbindProgram();
}
}
-static void draw_uv_shadows_get(SpaceImage *sima, Object *ob, Object *obedit, bool *show_shadow, bool *show_texpaint)
+static void draw_uv_shadows_get(
+ SpaceImage *sima, Object *ob, Object *obedit,
+ bool *show_shadow, bool *show_texpaint)
{
*show_shadow = *show_texpaint = false;
@@ -973,7 +1044,9 @@ static void draw_uv_shadows_get(SpaceImage *sima, Object *ob, Object *obedit, bo
*show_texpaint = (ob && ob->type == OB_MESH && ob->mode == OB_MODE_TEXTURE_PAINT);
}
-void ED_uvedit_draw_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *obedit, Object *obact)
+void ED_uvedit_draw_main(
+ SpaceImage *sima,
+ ARegion *ar, Scene *scene, ViewLayer *view_layer, Object *obedit, Object *obact, Depsgraph *depsgraph)
{
ToolSettings *toolsettings = scene->toolsettings;
bool show_uvedit, show_uvshadow, show_texpaint_uvshadow;
@@ -982,12 +1055,21 @@ void ED_uvedit_draw_main(SpaceImage *sima, ARegion *ar, Scene *scene, Object *ob
draw_uv_shadows_get(sima, obact, obedit, &show_uvshadow, &show_texpaint_uvshadow);
if (show_uvedit || show_uvshadow || show_texpaint_uvshadow) {
- if (show_uvshadow)
+ if (show_uvshadow) {
draw_uvs_shadow(obedit);
- else if (show_uvedit)
- draw_uvs(sima, scene, obedit);
- else
- draw_uvs_texpaint(sima, scene, obact);
+ }
+ else if (show_uvedit) {
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *ob_iter = objects[ob_index];
+ draw_uvs(sima, scene, view_layer, ob_iter, depsgraph);
+ }
+ MEM_SAFE_FREE(objects);
+ }
+ else {
+ draw_uvs_texpaint(sima, scene, view_layer, obact);
+ }
if (show_uvedit && !(toolsettings->use_uv_sculpt))
ED_image_draw_cursor(ar, sima->cursor);
diff --git a/source/blender/editors/uvedit/uvedit_intern.h b/source/blender/editors/uvedit/uvedit_intern.h
index b5ff46e9219..e3db0162f10 100644
--- a/source/blender/editors/uvedit/uvedit_intern.h
+++ b/source/blender/editors/uvedit/uvedit_intern.h
@@ -32,7 +32,6 @@
#ifndef __UVEDIT_INTERN_H__
#define __UVEDIT_INTERN_H__
-struct MTexPoly;
struct Image;
struct Object;
struct Scene;
@@ -52,9 +51,10 @@ void uv_poly_center(struct BMFace *f, float r_cent[2], const int cd_loop_uv_off
/* find nearest */
typedef struct UvNearestHit {
+ /** Only for `*_multi(..)` versions of functions. */
+ struct Object *ob;
/** Always set if we have a hit. */
struct BMFace *efa;
- struct MTexPoly *tf;
struct BMLoop *l;
struct MLoopUV *luv, *luv_next;
/** Index of loop within face. */
@@ -66,15 +66,24 @@ typedef struct UvNearestHit {
#define UV_NEAREST_HIT_INIT { .dist_sq = FLT_MAX, }
bool uv_find_nearest_vert(
- struct Scene *scene, struct Image *ima, struct BMEditMesh *em,
+ struct Scene *scene, struct Image *ima, struct Object *obedit,
+ const float co[2], const float penalty_dist, struct UvNearestHit *hit_final);
+bool uv_find_nearest_vert_multi(
+ struct Scene *scene, struct Image *ima, struct Object **objects, const uint objects_len,
const float co[2], const float penalty_dist, struct UvNearestHit *hit_final);
bool uv_find_nearest_edge(
- struct Scene *scene, struct Image *ima, struct BMEditMesh *em,
+ struct Scene *scene, struct Image *ima, struct Object *obedit,
+ const float co[2], struct UvNearestHit *hit_final);
+bool uv_find_nearest_edge_multi(
+ struct Scene *scene, struct Image *ima, struct Object **objects, const uint objects_len,
const float co[2], struct UvNearestHit *hit_final);
bool uv_find_nearest_face(
- struct Scene *scene, struct Image *ima, struct BMEditMesh *em,
+ struct Scene *scene, struct Image *ima, struct Object *obedit,
+ const float co[2], struct UvNearestHit *hit_final);
+bool uv_find_nearest_face_multi(
+ struct Scene *scene, struct Image *ima, struct Object **objects, const uint objects_len,
const float co[2], struct UvNearestHit *hit_final);
/* utility tool functions */
diff --git a/source/blender/editors/uvedit/uvedit_ops.c b/source/blender/editors/uvedit/uvedit_ops.c
index 9c6f468532f..97075eba61e 100644
--- a/source/blender/editors/uvedit/uvedit_ops.c
+++ b/source/blender/editors/uvedit/uvedit_ops.c
@@ -29,6 +29,7 @@
* \ingroup eduv
*/
+
#include <stdlib.h>
#include <string.h>
#include <math.h>
@@ -56,7 +57,6 @@
#include "BKE_context.h"
#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BKE_library.h"
#include "BKE_main.h"
@@ -66,6 +66,9 @@
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_editmesh.h"
+#include "BKE_layer.h"
+
+#include "DEG_depsgraph.h"
#include "ED_image.h"
#include "ED_mesh.h"
@@ -87,7 +90,10 @@
#include "uvedit_intern.h"
-static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int action);
+static bool uv_select_is_any_selected(Scene *scene, Image *ima, Object *obedit);
+static bool uv_select_is_any_selected_multi(Scene *scene, Image *ima, Object **objects, const uint objects_len);
+static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, int action);
+static void uv_select_all_perform_multi(Scene *scene, Image *ima, Object **objects, const uint objects_len, int action);
static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object *obedit, const bool select);
static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object *obedit, const bool select);
@@ -189,144 +195,6 @@ void ED_object_assign_active_image(Main *bmain, Object *ob, int mat_nr, Image *i
//#define USE_SWITCH_ASPECT
-void ED_uvedit_assign_image(Main *UNUSED(bmain), Scene *scene, Object *obedit, Image *ima, Image *previma)
-{
- BMEditMesh *em;
- BMIter iter;
- MTexPoly *tf;
- bool update = false;
- const bool selected = !(scene->toolsettings->uv_flag & UV_SYNC_SELECTION);
-
- /* skip assigning these procedural images... */
- if (ima && (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE))
- return;
-
- /* verify we have a mesh we can work with */
- if (!obedit || (obedit->type != OB_MESH))
- return;
-
- em = BKE_editmesh_from_object(obedit);
- if (!em || !em->bm->totface) {
- return;
- }
-
- if (BKE_scene_use_new_shading_nodes(scene)) {
- /* new shading system, do not assign anything */
- }
- else {
- BMFace *efa;
-
- int cd_loop_uv_offset;
- int cd_poly_tex_offset;
-
- /* old shading system, assign image to selected faces */
-#ifdef USE_SWITCH_ASPECT
- float prev_aspect[2], fprev_aspect;
- float aspect[2], faspect;
-
- ED_image_get_uv_aspect(previma, prev_aspect, prev_aspect + 1);
- ED_image_get_uv_aspect(ima, aspect, aspect + 1);
-
- fprev_aspect = prev_aspect[0] / prev_aspect[1];
- faspect = aspect[0] / aspect[1];
-#endif
-
- /* ensure we have a uv map */
- if (!CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY)) {
- BM_data_layer_add(em->bm, &em->bm->pdata, CD_MTEXPOLY);
- BM_data_layer_add(em->bm, &em->bm->ldata, CD_MLOOPUV);
- /* make UVs all nice 0-1 */
- ED_mesh_uv_loop_reset_ex(obedit->data, CustomData_get_active_layer(&em->bm->pdata, CD_MTEXPOLY));
- update = true;
- }
-
- cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
-
- /* now assign to all visible faces */
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (uvedit_face_visible_test(scene, previma, efa, tf) &&
- (selected == true || uvedit_face_select_test(scene, efa, cd_loop_uv_offset)))
- {
- if (ima) {
- tf->tpage = ima;
-
- if (ima->id.us == 0) id_us_plus(&ima->id);
- else id_lib_extern(&ima->id);
-
-#ifdef USE_SWITCH_ASPECT
- /* we also need to correct the aspect of uvs */
- if (scene->toolsettings->uvcalc_flag & UVCALC_NO_ASPECT_CORRECT) {
- /* do nothing */
- }
- else {
- BMIter liter;
- BMLoop *l;
-
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-
- luv->uv[0] *= fprev_aspect;
- luv->uv[0] /= faspect;
- }
- }
-#endif
- }
- else {
- tf->tpage = NULL;
- }
-
- update = true;
- }
- }
-
- /* and update depdency graph */
- if (update) {
- DAG_id_tag_update(obedit->data, 0);
- }
- }
-
-}
-
-/* dotile - 1, set the tile flag (from the space image)
- * 2, set the tile index for the faces. */
-static bool uvedit_set_tile(Object *obedit, Image *ima, int curtile)
-{
- BMEditMesh *em;
- BMFace *efa;
- BMIter iter;
- MTexPoly *tf;
- int cd_poly_tex_offset;
-
- /* verify if we have something to do */
- if (!ima || !ED_uvedit_test(obedit))
- return false;
-
- if ((ima->tpageflag & IMA_TILES) == 0)
- return false;
-
- /* skip assigning these procedural images... */
- if (ima->type == IMA_TYPE_R_RESULT || ima->type == IMA_TYPE_COMPOSITE)
- return false;
-
- em = BKE_editmesh_from_object(obedit);
-
- cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
-
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (BM_elem_flag_test(efa, BM_ELEM_SELECT))
- tf->tile = curtile; /* set tile index */
- }
-
- DAG_id_tag_update(obedit->data, 0);
-
- return true;
-}
-
/** \} */
/* -------------------------------------------------------------------- */
@@ -380,14 +248,18 @@ bool uvedit_face_visible_nolocal(Scene *scene, BMFace *efa)
return (BM_elem_flag_test(efa, BM_ELEM_HIDDEN) == 0 && BM_elem_flag_test(efa, BM_ELEM_SELECT));
}
-bool uvedit_face_visible_test(Scene *scene, Image *ima, BMFace *efa, MTexPoly *tf)
+bool uvedit_face_visible_test(Scene *scene, Object *obedit, Image *ima, BMFace *efa)
{
ToolSettings *ts = scene->toolsettings;
- if (ts->uv_flag & UV_SHOW_SAME_IMAGE)
- return (tf->tpage == ima) ? uvedit_face_visible_nolocal(scene, efa) : false;
- else
+ if (ts->uv_flag & UV_SHOW_SAME_IMAGE) {
+ Image *face_image;
+ ED_object_get_active_image(obedit, efa->mat_nr + 1, &face_image, NULL, NULL, NULL);
+ return (face_image == ima) ? uvedit_face_visible_nolocal(scene, efa) : false;
+ }
+ else {
return uvedit_face_visible_nolocal(scene, efa);
+ }
}
bool uvedit_face_select_test(
@@ -701,18 +573,15 @@ bool ED_uvedit_minmax(Scene *scene, Image *ima, Object *obedit, float r_min[2],
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
bool changed = false;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
INIT_MINMAX2(r_min, r_max);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -751,17 +620,14 @@ static bool ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
unsigned int sel = 0;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
zero_v2(co);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -778,7 +644,7 @@ static bool ED_uvedit_median(Scene *scene, Image *ima, Object *obedit, float co[
return (sel != 0);
}
-static bool uvedit_center(Scene *scene, Image *ima, Object *obedit, float cent[2], char mode)
+bool ED_uvedit_center(Scene *scene, Image *ima, Object *obedit, float cent[2], char mode)
{
bool changed = false;
@@ -805,10 +671,10 @@ static bool uvedit_center(Scene *scene, Image *ima, Object *obedit, float cent[2
* \{ */
bool uv_find_nearest_edge(
- Scene *scene, Image *ima, BMEditMesh *em, const float co[2],
+ Scene *scene, Image *ima, Object *obedit, const float co[2],
UvNearestHit *hit)
{
- MTexPoly *tf;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
@@ -817,13 +683,11 @@ bool uv_find_nearest_edge(
bool found = false;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa)) {
continue;
}
BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
@@ -833,7 +697,6 @@ bool uv_find_nearest_edge(
const float dist_test_sq = dist_squared_to_line_segment_v2(co, luv->uv, luv_next->uv);
if (dist_test_sq < hit->dist_sq) {
- hit->tf = tf;
hit->efa = efa;
hit->l = l;
@@ -849,19 +712,34 @@ bool uv_find_nearest_edge(
return found;
}
+bool uv_find_nearest_edge_multi(
+ Scene *scene, Image *ima, Object **objects, const uint objects_len,
+ const float co[2], UvNearestHit *hit_final)
+{
+ bool found = false;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ if (uv_find_nearest_edge(scene, ima, obedit, co, hit_final)) {
+ hit_final->ob = obedit;
+ found = true;
+ }
+ }
+ return found;
+}
+
bool uv_find_nearest_face(
- Scene *scene, Image *ima, BMEditMesh *em, const float co[2],
+ Scene *scene, Image *ima, Object *obedit, const float co[2],
UvNearestHit *hit_final)
{
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool found = false;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
/* this will fill in hit.vert1 and hit.vert2 */
float dist_sq_init = hit_final->dist_sq;
UvNearestHit hit = *hit_final;
- if (uv_find_nearest_edge(scene, ima, em, co, &hit)) {
+ if (uv_find_nearest_edge(scene, ima, obedit, co, &hit)) {
hit.dist_sq = dist_sq_init;
hit.l = NULL;
hit.luv = hit.luv_next = NULL;
@@ -870,8 +748,7 @@ bool uv_find_nearest_face(
BMFace *efa;
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa)) {
continue;
}
@@ -893,6 +770,21 @@ bool uv_find_nearest_face(
return found;
}
+bool uv_find_nearest_face_multi(
+ Scene *scene, Image *ima, Object **objects, const uint objects_len,
+ const float co[2], UvNearestHit *hit_final)
+{
+ bool found = false;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ if (uv_find_nearest_face(scene, ima, obedit, co, hit_final)) {
+ hit_final->ob = obedit;
+ found = true;
+ }
+ }
+ return found;
+}
+
static bool uv_nearest_between(
const BMLoop *l, const float co[2],
const int cd_loop_uv_offset)
@@ -906,7 +798,7 @@ static bool uv_nearest_between(
}
bool uv_find_nearest_vert(
- Scene *scene, Image *ima, BMEditMesh *em,
+ Scene *scene, Image *ima, Object *obedit,
float const co[2], const float penalty_dist, UvNearestHit *hit_final)
{
bool found = false;
@@ -914,23 +806,22 @@ bool uv_find_nearest_vert(
/* this will fill in hit.vert1 and hit.vert2 */
float dist_sq_init = hit_final->dist_sq;
UvNearestHit hit = *hit_final;
- if (uv_find_nearest_edge(scene, ima, em, co, &hit)) {
+ if (uv_find_nearest_edge(scene, ima, obedit, co, &hit)) {
hit.dist_sq = dist_sq_init;
hit.l = NULL;
hit.luv = hit.luv_next = NULL;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMIter iter;
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa)) {
continue;
}
@@ -975,26 +866,38 @@ bool uv_find_nearest_vert(
return found;
}
+bool uv_find_nearest_vert_multi(
+ Scene *scene, Image *ima, Object **objects, const uint objects_len,
+ float const co[2], const float penalty_dist, UvNearestHit *hit_final)
+{
+ bool found = false;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ if (uv_find_nearest_vert(scene, ima, obedit, co, penalty_dist, hit_final)) {
+ hit_final->ob = obedit;
+ found = true;
+ }
+ }
+ return found;
+}
+
bool ED_uvedit_nearest_uv(Scene *scene, Object *obedit, Image *ima, const float co[2], float r_uv[2])
{
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
float mindist, dist;
bool found = false;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
mindist = 1e10f;
copy_v2_v2(r_uv, co);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1103,13 +1006,13 @@ static bool uv_select_edgeloop_edge_tag_faces(BMEditMesh *em, UvMapVert *first1,
}
static int uv_select_edgeloop(
- Scene *scene, Image *ima, BMEditMesh *em, UvNearestHit *hit,
+ Scene *scene, Image *ima, Object *obedit, UvNearestHit *hit,
const float limit[2], const bool extend)
{
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMIter iter, liter;
BMLoop *l;
- MTexPoly *tf;
UvVertMap *vmap;
UvMapVert *iterv_curr;
UvMapVert *iterv_next;
@@ -1117,7 +1020,6 @@ static int uv_select_edgeloop(
bool looking, select;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
/* setup */
BM_mesh_elem_table_ensure(em->bm, BM_FACE);
@@ -1126,7 +1028,7 @@ static int uv_select_edgeloop(
BM_mesh_elem_index_ensure(em->bm, BM_VERT | BM_FACE);
if (!extend) {
- uv_select_all_perform(scene, ima, em, SEL_DESELECT);
+ uv_select_all_perform(scene, ima, obedit, SEL_DESELECT);
}
BM_mesh_elem_hflag_disable_all(em->bm, BM_FACE, BM_ELEM_TAG, false);
@@ -1150,9 +1052,7 @@ static int uv_select_edgeloop(
/* find correct valence edges which are not tagged yet, but connect to tagged one */
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (!BM_elem_flag_test(efa, BM_ELEM_TAG) && uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_TAG) && uvedit_face_visible_test(scene, obedit, ima, efa)) {
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
/* check face not hidden and not tagged */
if (!(iterv_curr = uv_select_edgeloop_vertex_map_get(vmap, efa, l)))
@@ -1211,190 +1111,193 @@ static int uv_select_edgeloop(
/** \name Select Linked
* \{ */
-static void uv_select_linked(
- Scene *scene, Image *ima, BMEditMesh *em, const float limit[2], UvNearestHit *hit_final,
- bool extend, bool deselect, bool toggle, bool select_faces)
+static void uv_select_linked_multi(
+ Scene *scene, Image *ima, Object **objects, const uint objects_len, const float limit[2],
+ UvNearestHit *hit_final, bool extend, bool deselect, bool toggle, bool select_faces)
{
- BMFace *efa;
- BMLoop *l;
- BMIter iter, liter;
- MLoopUV *luv;
- UvVertMap *vmap;
- UvMapVert *vlist, *iterv, *startv;
- int i, stacksize = 0, *stack;
- unsigned int a;
- char *flag;
-
- const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
+ /* loop over objects, or just use hit_final->ob */
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ if (hit_final && ob_index != 0) {
+ break;
+ }
+ Object *obedit = hit_final ? hit_final->ob : objects[ob_index];
- BM_mesh_elem_table_ensure(em->bm, BM_FACE); /* we can use this too */
+ BMFace *efa;
+ BMLoop *l;
+ BMIter iter, liter;
+ MLoopUV *luv;
+ UvVertMap *vmap;
+ UvMapVert *vlist, *iterv, *startv;
+ int i, stacksize = 0, *stack;
+ unsigned int a;
+ char *flag;
- /* Note, we had 'use winding' so we don't consider overlapping islands as connected, see T44320
- * this made *every* projection split the island into front/back islands.
- * Keep 'use_winding' to false, see: T50970.
- *
- * Better solve this by having a delimit option for select-linked operator,
- * keeping island-select working as is. */
- vmap = BM_uv_vert_map_create(em->bm, limit, !select_faces, false);
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- if (vmap == NULL)
- return;
+ BM_mesh_elem_table_ensure(em->bm, BM_FACE); /* we can use this too */
- stack = MEM_mallocN(sizeof(*stack) * (em->bm->totface + 1), "UvLinkStack");
- flag = MEM_callocN(sizeof(*flag) * em->bm->totface, "UvLinkFlag");
+ /* Note, we had 'use winding' so we don't consider overlapping islands as connected, see T44320
+ * this made *every* projection split the island into front/back islands.
+ * Keep 'use_winding' to false, see: T50970.
+ *
+ * Better solve this by having a delimit option for select-linked operator,
+ * keeping island-select working as is. */
+ vmap = BM_uv_vert_map_create(em->bm, limit, !select_faces, false);
- if (hit_final == NULL) {
- /* Use existing selection */
- BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
+ if (vmap == NULL)
+ return;
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
- if (select_faces) {
- if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
- stack[stacksize] = a;
- stacksize++;
- flag[a] = 1;
- }
- }
- else {
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ stack = MEM_mallocN(sizeof(*stack) * (em->bm->totface + 1), "UvLinkStack");
+ flag = MEM_callocN(sizeof(*flag) * em->bm->totface, "UvLinkFlag");
- if (luv->flag & MLOOPUV_VERTSEL) {
+ if (hit_final == NULL) {
+ /* Use existing selection */
+ BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
+ if (select_faces) {
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT)) {
stack[stacksize] = a;
stacksize++;
flag[a] = 1;
+ }
+ }
+ else {
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- break;
+ if (luv->flag & MLOOPUV_VERTSEL) {
+ stack[stacksize] = a;
+ stacksize++;
+ flag[a] = 1;
+
+ break;
+ }
}
}
}
}
}
- }
- else {
- BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
- if (efa == hit_final->efa) {
- stack[stacksize] = a;
- stacksize++;
- flag[a] = 1;
- break;
+ else {
+ BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
+ if (efa == hit_final->efa) {
+ stack[stacksize] = a;
+ stacksize++;
+ flag[a] = 1;
+ break;
+ }
}
}
- }
- while (stacksize > 0) {
+ while (stacksize > 0) {
- stacksize--;
- a = stack[stacksize];
+ stacksize--;
+ a = stack[stacksize];
- efa = BM_face_at_index(em->bm, a);
+ efa = BM_face_at_index(em->bm, a);
- BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
+ BM_ITER_ELEM_INDEX (l, &liter, efa, BM_LOOPS_OF_FACE, i) {
- /* make_uv_vert_map_EM sets verts tmp.l to the indices */
- vlist = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
-
- startv = vlist;
+ /* make_uv_vert_map_EM sets verts tmp.l to the indices */
+ vlist = BM_uv_vert_map_at_index(vmap, BM_elem_index_get(l->v));
- for (iterv = vlist; iterv; iterv = iterv->next) {
- if (iterv->separate)
- startv = iterv;
- if (iterv->f == a)
- break;
- }
+ startv = vlist;
- for (iterv = startv; iterv; iterv = iterv->next) {
- if ((startv != iterv) && (iterv->separate))
- break;
- else if (!flag[iterv->f]) {
- flag[iterv->f] = 1;
- stack[stacksize] = iterv->f;
- stacksize++;
+ for (iterv = vlist; iterv; iterv = iterv->next) {
+ if (iterv->separate)
+ startv = iterv;
+ if (iterv->f == a)
+ break;
}
- }
- }
- }
- /* Toggling - if any of the linked vertices is selected (and visible), we deselect. */
- if ((toggle == true) && (extend == false) && (deselect == false)) {
- BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
- bool found_selected = false;
- if (!flag[a]) {
- continue;
+ for (iterv = startv; iterv; iterv = iterv->next) {
+ if ((startv != iterv) && (iterv->separate))
+ break;
+ else if (!flag[iterv->f]) {
+ flag[iterv->f] = 1;
+ stack[stacksize] = iterv->f;
+ stacksize++;
+ }
+ }
}
+ }
- if (select_faces) {
- if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
- found_selected = true;
+ /* Toggling - if any of the linked vertices is selected (and visible), we deselect. */
+ if ((toggle == true) && (extend == false) && (deselect == false)) {
+ BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
+ bool found_selected = false;
+ if (!flag[a]) {
+ continue;
}
- }
- else {
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- if (luv->flag & MLOOPUV_VERTSEL) {
+ if (select_faces) {
+ if (BM_elem_flag_test(efa, BM_ELEM_SELECT) && !BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) {
found_selected = true;
}
}
+ else {
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- if (found_selected) {
- deselect = true;
- break;
+ if (luv->flag & MLOOPUV_VERTSEL) {
+ found_selected = true;
+ }
+ }
+
+ if (found_selected) {
+ deselect = true;
+ break;
+ }
}
}
}
- }
#define SET_SELECTION(value) \
- if (select_faces) { \
- BM_face_select_set(em->bm, efa, value); \
- } \
- else { \
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { \
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); \
- luv->flag = (value) ? (luv->flag | MLOOPUV_VERTSEL) : (luv->flag & ~MLOOPUV_VERTSEL); \
+ if (select_faces) { \
+ BM_face_select_set(em->bm, efa, value); \
} \
- } (void)0
+ else { \
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) { \
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset); \
+ luv->flag = (value) ? (luv->flag | MLOOPUV_VERTSEL) : (luv->flag & ~MLOOPUV_VERTSEL); \
+ } \
+ } (void)0
- BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
- if (!flag[a]) {
- if (!extend && !deselect && !toggle) {
- SET_SELECTION(false);
+ BM_ITER_MESH_INDEX (efa, &iter, em->bm, BM_FACES_OF_MESH, a) {
+ if (!flag[a]) {
+ if (!extend && !deselect && !toggle) {
+ SET_SELECTION(false);
+ }
+ continue;
}
- continue;
- }
- if (!deselect) {
- SET_SELECTION(true);
- }
- else {
- SET_SELECTION(false);
+ if (!deselect) {
+ SET_SELECTION(true);
+ }
+ else {
+ SET_SELECTION(false);
+ }
}
- }
#undef SET_SELECTION
- MEM_freeN(stack);
- MEM_freeN(flag);
- BM_uv_vert_map_free(vmap);
+ MEM_freeN(stack);
+ MEM_freeN(flag);
+ BM_uv_vert_map_free(vmap);
+ }
}
/* WATCH IT: this returns first selected UV,
* not ideal in many cases since there could be multiple */
-static float *uv_sel_co_from_eve(Scene *scene, Image *ima, BMEditMesh *em, BMVert *eve)
+static float *uv_sel_co_from_eve(Scene *scene, Object *obedit, Image *ima, BMEditMesh *em, BMVert *eve)
{
BMIter liter;
BMLoop *l;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_ITER_ELEM (l, &liter, eve, BM_LOOPS_OF_VERT) {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(l->f, cd_poly_tex_offset);
-
- if (!uvedit_face_visible_test(scene, ima, l->f, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, l->f))
continue;
if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
@@ -1426,7 +1329,6 @@ static int uv_select_more_less(bContext *C, const bool select)
ToolSettings *ts = scene->toolsettings;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
if (ts->uv_flag & UV_SYNC_SELECTION) {
if (select) {
@@ -1447,9 +1349,7 @@ static int uv_select_more_less(bContext *C, const bool select)
/* mark loops to be selected */
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
#define IS_SEL 1
#define IS_UNSEL 2
@@ -1492,9 +1392,7 @@ static int uv_select_more_less(bContext *C, const bool select)
/* mark loops to be selected */
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- MTexPoly *tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
@@ -1565,11 +1463,9 @@ static void uv_weld_align(bContext *C, int tool)
SpaceImage *sima;
Scene *scene;
Image *ima;
- MTexPoly *tf;
float cent[2], min[2], max[2];
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
scene = CTX_data_scene(C);
ima = CTX_data_edit_image(C);
@@ -1583,9 +1479,7 @@ static void uv_weld_align(bContext *C, int tool)
BMLoop *l;
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1599,7 +1493,7 @@ static void uv_weld_align(bContext *C, int tool)
tool = (max[0] - min[0] >= max[1] - min[1]) ? 'y' : 'x';
}
- uvedit_center(scene, ima, obedit, cent, 0);
+ ED_uvedit_center(scene, ima, obedit, cent, 0);
if (tool == 'x' || tool == 'w') {
BMIter iter, liter;
@@ -1607,8 +1501,7 @@ static void uv_weld_align(bContext *C, int tool)
BMLoop *l;
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1627,8 +1520,7 @@ static void uv_weld_align(bContext *C, int tool)
BMLoop *l;
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1654,9 +1546,7 @@ static void uv_weld_align(bContext *C, int tool)
/* tag verts with a selected UV */
BM_ITER_MESH (eve, &iter, em->bm, BM_VERTS_OF_MESH) {
BM_ITER_ELEM (l, &liter, eve, BM_LOOPS_OF_VERT) {
- tf = BM_ELEM_CD_GET_VOID_P(l->f, cd_poly_tex_offset);
-
- if (!uvedit_face_visible_test(scene, ima, l->f, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, l->f))
continue;
if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
@@ -1725,8 +1615,10 @@ static void uv_weld_align(bContext *C, int tool)
if (BLI_array_len(eve_line) > 2) {
/* we know the returns from these must be valid */
- const float *uv_start = uv_sel_co_from_eve(scene, ima, em, eve_line[0]);
- const float *uv_end = uv_sel_co_from_eve(scene, ima, em, eve_line[BLI_array_len(eve_line) - 1]);
+ const float *uv_start = uv_sel_co_from_eve(
+ scene, obedit, ima, em, eve_line[0]);
+ const float *uv_end = uv_sel_co_from_eve(
+ scene, obedit, ima, em, eve_line[BLI_array_len(eve_line) - 1]);
/* For t & u modes */
float a = 0.0f;
@@ -1746,9 +1638,7 @@ static void uv_weld_align(bContext *C, int tool)
/* go over all verts except for endpoints */
for (i = 0; i < BLI_array_len(eve_line); i++) {
BM_ITER_ELEM (l, &liter, eve_line[i], BM_LOOPS_OF_VERT) {
- tf = BM_ELEM_CD_GET_VOID_P(l->f, cd_poly_tex_offset);
-
- if (!uvedit_face_visible_test(scene, ima, l->f, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, l->f))
continue;
if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
@@ -1782,7 +1672,7 @@ static void uv_weld_align(bContext *C, int tool)
uvedit_live_unwrap_update(sima, scene, obedit);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
}
@@ -1839,7 +1729,6 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
Object *obedit = CTX_data_edit_object(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
Image *ima;
- MTexPoly *tf;
int uv_a_index;
int uv_b_index;
float *uv_a;
@@ -1850,7 +1739,6 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
BMLoop *l;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
sima = CTX_wm_space_image(C);
scene = CTX_data_scene(C);
@@ -1864,8 +1752,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
/* TODO, use kd-tree as with MESH_OT_remove_doubles, this isn't optimal */
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1927,8 +1814,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
BLI_array_declare(loop_arr_unselected);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -1965,7 +1851,7 @@ static int uv_remove_doubles_exec(bContext *C, wmOperator *op)
}
uvedit_live_unwrap_update(sima, scene, obedit);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -2020,20 +1906,65 @@ static void UV_OT_weld(wmOperatorType *ot)
/** \name (De)Select All Operator
* \{ */
-static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int action)
+
+static bool uv_select_is_any_selected(Scene *scene, Image *ima, Object *obedit)
+{
+ ToolSettings *ts = scene->toolsettings;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMFace *efa;
+ BMLoop *l;
+ BMIter iter, liter;
+ MLoopUV *luv;
+
+ if (ts->uv_flag & UV_SYNC_SELECTION) {
+ return (em->bm->totvertsel || em->bm->totedgesel || em->bm->totfacesel);
+ }
+ else {
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa)) {
+ continue;
+ }
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ if (luv->flag & MLOOPUV_VERTSEL) {
+ return true;
+ }
+ }
+ }
+ }
+ return false;
+}
+
+static bool uv_select_is_any_selected_multi(Scene *scene, Image *ima, Object **objects, const uint objects_len)
+{
+ bool found = false;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ if (uv_select_is_any_selected(scene, ima, obedit)) {
+ found = true;
+ break;
+ }
+ }
+ return found;
+}
+
+static void uv_select_all_perform(Scene *scene, Image *ima, Object *obedit, int action)
{
ToolSettings *ts = scene->toolsettings;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
- if (ts->uv_flag & UV_SYNC_SELECTION) {
+ if (action == SEL_TOGGLE) {
+ action = uv_select_is_any_selected(scene, ima, obedit) ? SEL_DESELECT : SEL_SELECT;
+ }
+ if (ts->uv_flag & UV_SYNC_SELECTION) {
switch (action) {
case SEL_TOGGLE:
EDBM_select_toggle_all(em);
@@ -2051,30 +1982,8 @@ static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int
}
}
else {
- if (action == SEL_TOGGLE) {
- action = SEL_SELECT;
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
- continue;
-
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
-
- if (luv->flag & MLOOPUV_VERTSEL) {
- action = SEL_DESELECT;
- break;
- }
- }
- }
- }
-
-
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -2096,18 +2005,38 @@ static void uv_select_all_perform(Scene *scene, Image *ima, BMEditMesh *em, int
}
}
+static void uv_select_all_perform_multi(
+ Scene *scene, Image *ima, Object **objects, const uint objects_len, int action)
+{
+ if (action == SEL_TOGGLE) {
+ action = uv_select_is_any_selected_multi(scene, ima, objects, objects_len) ? SEL_DESELECT : SEL_SELECT;
+ }
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ uv_select_all_perform(scene, ima, obedit, action);
+ }
+}
+
static int uv_select_all_exec(bContext *C, wmOperator *op)
{
Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
Image *ima = CTX_data_edit_image(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
int action = RNA_enum_get(op->ptr, "action");
- uv_select_all_perform(scene, ima, em, action);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ uv_select_all_perform_multi(scene, ima, objects, objects_len, action);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
+
+ MEM_SAFE_FREE(objects);
return OPERATOR_FINISHED;
}
@@ -2156,18 +2085,17 @@ static bool uv_sticky_select(float *limit, int hitv[], int v, float *hituv[], fl
return false;
}
-static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loop)
+static int uv_mouse_select_multi(
+ bContext *C, Object **objects, uint objects_len,
+ const float co[2], bool extend, bool loop)
{
SpaceImage *sima = CTX_wm_space_image(C);
Scene *scene = CTX_data_scene(C);
ToolSettings *ts = scene->toolsettings;
- Object *obedit = CTX_data_edit_object(C);
Image *ima = CTX_data_edit_image(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
UvNearestHit hit = UV_NEAREST_HIT_INIT;
int i, selectmode, sticky, sync, *hitv = NULL;
@@ -2175,9 +2103,6 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
int flush = 0, hitlen = 0; /* 0 == don't flush, 1 == sel, -1 == desel; only use when selection sync is enabled */
float limit[2], **hituv = NULL;
- const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
-
/* notice 'limit' is the same no matter the zoom level, since this is like
* remove doubles and could annoying if it joined points when zoomed out.
* 'penalty' is in screen pixel space otherwise zooming in on a uv-vert and
@@ -2214,7 +2139,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
/* find nearest element */
if (loop) {
/* find edge */
- if (!uv_find_nearest_edge(scene, ima, em, co, &hit)) {
+ if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) {
return OPERATOR_CANCELLED;
}
@@ -2222,7 +2147,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
}
else if (selectmode == UV_SELECT_VERTEX) {
/* find vertex */
- if (!uv_find_nearest_vert(scene, ima, em, co, penalty_dist, &hit)) {
+ if (!uv_find_nearest_vert_multi(scene, ima, objects, objects_len, co, penalty_dist, &hit)) {
return OPERATOR_CANCELLED;
}
@@ -2238,7 +2163,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
}
else if (selectmode == UV_SELECT_EDGE) {
/* find edge */
- if (!uv_find_nearest_edge(scene, ima, em, co, &hit)) {
+ if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) {
return OPERATOR_CANCELLED;
}
@@ -2256,10 +2181,13 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
}
else if (selectmode == UV_SELECT_FACE) {
/* find face */
- if (!uv_find_nearest_face(scene, ima, em, co, &hit)) {
+ if (!uv_find_nearest_face_multi(scene, ima, objects, objects_len, co, &hit)) {
return OPERATOR_CANCELLED;
}
+ BMEditMesh *em = BKE_editmesh_from_object(hit.ob);
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+
/* make active */
BM_mesh_active_face_set(em->bm, hit.efa);
@@ -2276,7 +2204,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
hitlen = hit.efa->len;
}
else if (selectmode == UV_SELECT_ISLAND) {
- if (!uv_find_nearest_edge(scene, ima, em, co, &hit)) {
+ if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) {
return OPERATOR_CANCELLED;
}
@@ -2287,13 +2215,25 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
return OPERATOR_CANCELLED;
}
+ Object *obedit = hit.ob;
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+
/* do selection */
if (loop) {
- flush = uv_select_edgeloop(scene, ima, em, &hit, limit, extend);
+ if (!extend) {
+ /* TODO(MULTI_EDIT): We only need to de-select non-active */
+ uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT);
+ }
+ flush = uv_select_edgeloop(scene, ima, obedit, &hit, limit, extend);
}
else if (selectmode == UV_SELECT_ISLAND) {
+ if (!extend) {
+ /* TODO(MULTI_EDIT): We only need to de-select non-active */
+ uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT);
+ }
/* Current behavior of 'extend' is actually toggling, so pass extend flag as 'toggle' here */
- uv_select_linked(scene, ima, em, limit, &hit, false, false, extend, false);
+ uv_select_linked_multi(scene, ima, objects, objects_len, limit, &hit, false, false, extend, false);
}
else if (extend) {
if (selectmode == UV_SELECT_VERTEX) {
@@ -2328,8 +2268,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
BM_mesh_elem_index_ensure(em->bm, BM_VERT);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -2344,7 +2283,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
}
else {
/* deselect all */
- uv_select_all_perform(scene, ima, em, SEL_DESELECT);
+ uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT);
if (selectmode == UV_SELECT_VERTEX) {
/* select vertex */
@@ -2364,8 +2303,7 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
/* select sticky uvs */
if (sticky != SI_STICKY_DISABLE) {
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -2408,11 +2346,20 @@ static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loo
#endif
}
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
return OPERATOR_PASS_THROUGH | OPERATOR_FINISHED;
}
+static int uv_mouse_select(bContext *C, const float co[2], bool extend, bool loop)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len);
+ int ret = uv_mouse_select_multi(C, objects, objects_len, co, extend, loop);
+ MEM_freeN(objects);
+ return ret;
+}
static int uv_select_exec(bContext *C, wmOperator *op)
{
@@ -2517,9 +2464,8 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
SpaceImage *sima = CTX_wm_space_image(C);
Scene *scene = CTX_data_scene(C);
ToolSettings *ts = scene->toolsettings;
- Object *obedit = CTX_data_edit_object(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Image *ima = CTX_data_edit_image(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
float limit[2];
int extend, deselect;
bool select_faces = (ts->uv_flag & UV_SYNC_SELECTION) && (ts->selectmode & SCE_SELECT_FACE);
@@ -2535,6 +2481,9 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
deselect = RNA_boolean_get(op->ptr, "deselect");
uvedit_pixel_to_float(sima, limit, 0.05f);
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len);
+
if (pick) {
float co[2];
@@ -2550,15 +2499,34 @@ static int uv_select_linked_internal(bContext *C, wmOperator *op, const wmEvent
RNA_float_get_array(op->ptr, "location", co);
}
- if (!uv_find_nearest_edge(scene, ima, em, co, &hit)) {
+ if (!uv_find_nearest_edge_multi(scene, ima, objects, objects_len, co, &hit)) {
+ MEM_SAFE_FREE(objects);
return OPERATOR_CANCELLED;
}
}
- uv_select_linked(scene, ima, em, limit, pick ? &hit : NULL, extend, deselect, false, select_faces);
+ if (!extend) {
+ uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT);
+ }
- DAG_id_tag_update(obedit->data, 0);
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ uv_select_linked_multi(
+ scene, ima, objects, objects_len, limit, pick ? &hit : NULL,
+ extend, deselect, false, select_faces);
+
+ /* weak!, but works */
+ Object **objects_free = objects;
+ if (pick) {
+ objects = &hit.ob;
+ objects_len = 1;
+ }
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ DEG_id_tag_update(obedit->data, 0);
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
+
+ MEM_SAFE_FREE(objects_free);
return OPERATOR_FINISHED;
}
@@ -2632,12 +2600,10 @@ static int uv_select_split_exec(bContext *C, wmOperator *op)
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
bool changed = false;
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
if (ts->uv_flag & UV_SYNC_SELECTION) {
BKE_report(op->reports, RPT_ERROR, "Cannot split selection when sync selection is enabled");
@@ -2649,9 +2615,8 @@ static int uv_select_split_exec(bContext *C, wmOperator *op)
BM_ITER_MESH (efa, &iter, bm, BM_FACES_OF_MESH) {
bool is_sel = false;
bool is_unsel = false;
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
/* are we all selected? */
@@ -2796,7 +2761,6 @@ static void uv_select_flush_from_tag_face(SpaceImage *sima, Scene *scene, Object
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- /* MTexPoly *tf; */
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
if ((ts->uv_flag & UV_SYNC_SELECTION) == 0 && sima->sticky == SI_STICKY_VERTEX) {
@@ -2882,7 +2846,6 @@ static void uv_select_flush_from_tag_loop(SpaceImage *sima, Scene *scene, Object
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- /* MTexPoly *tf; */
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
@@ -2960,25 +2923,20 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
SpaceImage *sima = CTX_wm_space_image(C);
Scene *scene = CTX_data_scene(C);
ToolSettings *ts = scene->toolsettings;
- Object *obedit = CTX_data_edit_object(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Image *ima = CTX_data_edit_image(C);
ARegion *ar = CTX_wm_region(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
rctf rectf;
- bool changed, pinned, select, extend;
+ bool pinned, select, extend;
const bool use_face_center = (
(ts->uv_flag & UV_SYNC_SELECTION) ?
(ts->selectmode == SCE_SELECT_FACE) :
(ts->uv_selectmode == UV_SELECT_FACE));
- const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
-
/* get rectangle from operator */
WM_operator_properties_border_to_rctf(op, &rectf);
UI_view2d_region_to_view_rctf(&ar->v2d, &rectf, &rectf);
@@ -2988,81 +2946,96 @@ static int uv_border_select_exec(bContext *C, wmOperator *op)
extend = RNA_boolean_get(op->ptr, "extend");
pinned = RNA_boolean_get(op->ptr, "pinned");
- if (!extend)
- uv_select_all_perform(scene, ima, em, SEL_DESELECT);
+ bool changed_multi = false;
- /* do actual selection */
- if (use_face_center && !pinned) {
- /* handle face selection mode */
- float cent[2];
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len);
- changed = false;
+ /* don't indent to avoid diff noise! */
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- /* assume not touched */
- BM_elem_flag_disable(efa, BM_ELEM_TAG);
+ bool changed = false;
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
- uv_poly_center(efa, cent, cd_loop_uv_offset);
- if (BLI_rctf_isect_pt_v(&rectf, cent)) {
- BM_elem_flag_enable(efa, BM_ELEM_TAG);
- changed = true;
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+
+ if (!extend)
+ uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT);
+
+ /* do actual selection */
+ if (use_face_center && !pinned) {
+ /* handle face selection mode */
+ float cent[2];
+
+ changed = false;
+
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ /* assume not touched */
+ BM_elem_flag_disable(efa, BM_ELEM_TAG);
+
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
+ uv_poly_center(efa, cent, cd_loop_uv_offset);
+ if (BLI_rctf_isect_pt_v(&rectf, cent)) {
+ BM_elem_flag_enable(efa, BM_ELEM_TAG);
+ changed = true;
+ }
}
}
- }
- /* (de)selects all tagged faces and deals with sticky modes */
- if (changed) {
- uv_select_flush_from_tag_face(sima, scene, obedit, select);
+ /* (de)selects all tagged faces and deals with sticky modes */
+ if (changed) {
+ uv_select_flush_from_tag_face(sima, scene, obedit, select);
+ }
}
- }
- else {
- /* other selection modes */
- changed = true;
- BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false);
+ else {
+ /* other selection modes */
+ changed = true;
+ BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false);
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tf))
- continue;
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
+ continue;
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- if (!pinned || (ts->uv_flag & UV_SYNC_SELECTION)) {
+ if (!pinned || (ts->uv_flag & UV_SYNC_SELECTION)) {
- /* UV_SYNC_SELECTION - can't do pinned selection */
- if (BLI_rctf_isect_pt_v(&rectf, luv->uv)) {
- uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
- BM_elem_flag_enable(l->v, BM_ELEM_TAG);
+ /* UV_SYNC_SELECTION - can't do pinned selection */
+ if (BLI_rctf_isect_pt_v(&rectf, luv->uv)) {
+ uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
+ BM_elem_flag_enable(l->v, BM_ELEM_TAG);
+ }
}
- }
- else if (pinned) {
- if ((luv->flag & MLOOPUV_PINNED) && BLI_rctf_isect_pt_v(&rectf, luv->uv)) {
- uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
- BM_elem_flag_enable(l->v, BM_ELEM_TAG);
+ else if (pinned) {
+ if ((luv->flag & MLOOPUV_PINNED) && BLI_rctf_isect_pt_v(&rectf, luv->uv)) {
+ uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
+ BM_elem_flag_enable(l->v, BM_ELEM_TAG);
+ }
}
}
}
- }
- if (sima->sticky == SI_STICKY_VERTEX) {
- uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset);
+ if (sima->sticky == SI_STICKY_VERTEX) {
+ uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset);
+ }
}
- }
- if (changed) {
- uv_select_sync_flush(ts, em, select);
+ if (changed) {
+ changed_multi = true;
+
+ uv_select_sync_flush(ts, em, select);
- if (ts->uv_flag & UV_SYNC_SELECTION) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ if (ts->uv_flag & UV_SYNC_SELECTION) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
}
-
- return OPERATOR_FINISHED;
}
- return OPERATOR_CANCELLED;
-}
+ MEM_SAFE_FREE(objects);
+
+ return changed_multi ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+}
static void UV_OT_select_border(wmOperatorType *ot)
{
@@ -3216,102 +3189,112 @@ static void UV_OT_circle_select(wmOperatorType *ot)
/** \name Lasso Select Operator
* \{ */
-static bool do_lasso_select_mesh_uv(
- bContext *C, const int mcords[][2], short moves,
- const bool select, const bool extend)
+static bool do_lasso_select_mesh_uv(bContext *C, const int mcords[][2], short moves,
+ const bool select, const bool extend)
{
SpaceImage *sima = CTX_wm_space_image(C);
Image *ima = CTX_data_edit_image(C);
ARegion *ar = CTX_wm_region(C);
- Object *obedit = CTX_data_edit_object(C);
Scene *scene = CTX_data_scene(C);
ToolSettings *ts = scene->toolsettings;
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
const bool use_face_center = (
(ts->uv_flag & UV_SYNC_SELECTION) ?
(ts->selectmode == SCE_SELECT_FACE) :
(ts->uv_selectmode == UV_SELECT_FACE));
- const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BMIter iter, liter;
BMFace *efa;
BMLoop *l;
- MTexPoly *tf;
int screen_uv[2];
- bool changed = false;
+ bool changed_multi = false;
rcti rect;
BLI_lasso_boundbox(&rect, mcords, moves);
- if (!extend && select) {
- uv_select_all_perform(scene, ima, em, SEL_DESELECT);
- }
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len);
- if (use_face_center) { /* Face Center Sel */
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- BM_elem_flag_disable(efa, BM_ELEM_TAG);
- /* assume not touched */
- if (select != uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) {
- float cent[2];
- uv_poly_center(efa, cent, cd_loop_uv_offset);
+ /* don't indent to avoid diff noise! */
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
- if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]) &&
- BLI_rcti_isect_pt_v(&rect, screen_uv) &&
- BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED))
- {
- BM_elem_flag_enable(efa, BM_ELEM_TAG);
- changed = true;
+ bool changed = false;
+
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+
+ if (!extend && select) {
+ uv_select_all_perform_multi(scene, ima, objects, objects_len, SEL_DESELECT);
+ }
+
+ if (use_face_center) { /* Face Center Sel */
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ BM_elem_flag_disable(efa, BM_ELEM_TAG);
+ /* assume not touched */
+ if (select != uvedit_face_select_test(scene, efa, cd_loop_uv_offset)) {
+ float cent[2];
+ uv_poly_center(efa, cent, cd_loop_uv_offset);
+
+ if (UI_view2d_view_to_region_clip(&ar->v2d, cent[0], cent[1], &screen_uv[0], &screen_uv[1]) &&
+ BLI_rcti_isect_pt_v(&rect, screen_uv) &&
+ BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED))
+ {
+ BM_elem_flag_enable(efa, BM_ELEM_TAG);
+ changed = true;
+ }
}
}
- }
- /* (de)selects all tagged faces and deals with sticky modes */
- if (changed) {
- uv_select_flush_from_tag_face(sima, scene, obedit, select);
+ /* (de)selects all tagged faces and deals with sticky modes */
+ if (changed) {
+ uv_select_flush_from_tag_face(sima, scene, obedit, select);
+ }
}
- }
- else { /* Vert Sel */
- BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false);
+ else { /* Vert Sel */
+ BM_mesh_elem_hflag_disable_all(em->bm, BM_VERT, BM_ELEM_TAG, false);
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (uvedit_face_visible_test(scene, ima, efa, tf)) {
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- if ((select) != (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))) {
- MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- if (UI_view2d_view_to_region_clip(
- &ar->v2d,
- luv->uv[0], luv->uv[1],
- &screen_uv[0], &screen_uv[1]) &&
- BLI_rcti_isect_pt_v(&rect, screen_uv) &&
- BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED))
- {
- uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
- changed = true;
- BM_elem_flag_enable(l->v, BM_ELEM_TAG);
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (uvedit_face_visible_test(scene, obedit, ima, efa)) {
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ if ((select) != (uvedit_uv_select_test(scene, l, cd_loop_uv_offset))) {
+ MLoopUV *luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ if (UI_view2d_view_to_region_clip(
+ &ar->v2d,
+ luv->uv[0], luv->uv[1],
+ &screen_uv[0], &screen_uv[1]) &&
+ BLI_rcti_isect_pt_v(&rect, screen_uv) &&
+ BLI_lasso_is_point_inside(mcords, moves, screen_uv[0], screen_uv[1], V2D_IS_CLIPPED))
+ {
+ uvedit_uv_select_set(em, scene, l, select, false, cd_loop_uv_offset);
+ changed = true;
+ BM_elem_flag_enable(l->v, BM_ELEM_TAG);
+ }
}
}
}
}
- }
- if (sima->sticky == SI_STICKY_VERTEX) {
- uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset);
+ if (sima->sticky == SI_STICKY_VERTEX) {
+ uvedit_vertex_select_tagged(em, scene, select, cd_loop_uv_offset);
+ }
}
- }
- if (changed) {
- uv_select_sync_flush(scene->toolsettings, em, select);
+ if (changed) {
+ changed_multi = true;
+
+ uv_select_sync_flush(scene->toolsettings, em, select);
- if (ts->uv_flag & UV_SYNC_SELECTION) {
- WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ if (ts->uv_flag & UV_SYNC_SELECTION) {
+ WM_event_add_notifier(C, NC_GEOM | ND_SELECT, obedit->data);
+ }
}
}
- return changed;
+ return changed_multi;
}
static int uv_lasso_select_exec(bContext *C, wmOperator *op)
@@ -3376,7 +3359,7 @@ static void uv_snap_cursor_to_pixels(SpaceImage *sima)
static bool uv_snap_cursor_to_selection(Scene *scene, Image *ima, Object *obedit, SpaceImage *sima)
{
- return uvedit_center(scene, ima, obedit, sima->cursor, sima->around);
+ return ED_uvedit_center(scene, ima, obedit, sima->cursor, sima->around);
}
static int uv_snap_cursor_exec(bContext *C, wmOperator *op)
@@ -3438,16 +3421,13 @@ static bool uv_snap_uvs_to_cursor(Scene *scene, Image *ima, Object *obedit, cons
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tface;
MLoopUV *luv;
bool changed = false;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tface))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3468,16 +3448,13 @@ static bool uv_snap_uvs_offset(Scene *scene, Image *ima, Object *obedit, const f
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *mtexpoly;
MLoopUV *luv;
bool changed = false;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- mtexpoly = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, mtexpoly))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3499,17 +3476,14 @@ static bool uv_snap_uvs_to_adjacent_unselected(Scene *scene, Image *ima, Object
BMFace *f;
BMLoop *l, *lsub;
BMIter iter, liter, lsubiter;
- MTexPoly *tface;
MLoopUV *luv;
bool changed = false;
const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&bm->pdata, CD_MTEXPOLY);
/* index every vert that has a selected UV using it, but only once so as to
* get unique indices and to count how much to malloc */
BM_ITER_MESH (f, &iter, bm, BM_FACES_OF_MESH) {
- tface = BM_ELEM_CD_GET_VOID_P(f, cd_poly_tex_offset);
- if (uvedit_face_visible_test(scene, ima, f, tface)) {
+ if (uvedit_face_visible_test(scene, obedit, ima, f)) {
BM_elem_flag_enable(f, BM_ELEM_TAG);
BM_ITER_ELEM (l, &liter, f, BM_LOOPS_OF_FACE) {
BM_elem_flag_set(l, BM_ELEM_TAG, uvedit_uv_select_test(scene, l, cd_loop_uv_offset));
@@ -3557,22 +3531,19 @@ static bool uv_snap_uvs_to_pixels(SpaceImage *sima, Scene *scene, Object *obedit
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tface;
MLoopUV *luv;
int width = 0, height = 0;
float w, h;
bool changed = false;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
ED_space_image_get_size(sima, &width, &height);
w = (float)width;
h = (float)height;
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tface))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3606,7 +3577,7 @@ static int uv_snap_selection_exec(bContext *C, wmOperator *op)
case 2:
{
float center[2];
- if (uvedit_center(scene, ima, obedit, center, sima->around)) {
+ if (ED_uvedit_center(scene, ima, obedit, center, sima->around)) {
float offset[2];
sub_v2_v2v2(offset, sima->cursor, center);
changed = uv_snap_uvs_offset(scene, ima, obedit, offset);
@@ -3622,7 +3593,7 @@ static int uv_snap_selection_exec(bContext *C, wmOperator *op)
return OPERATOR_CANCELLED;
uvedit_live_unwrap_update(sima, scene, obedit);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -3666,16 +3637,13 @@ static int uv_pin_exec(bContext *C, wmOperator *op)
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tface;
MLoopUV *luv;
const bool clear = RNA_boolean_get(op->ptr, "clear");
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tface))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3728,15 +3696,12 @@ static int uv_select_pinned_exec(bContext *C, wmOperator *UNUSED(op))
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tface;
MLoopUV *luv;
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- tface = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
- if (!uvedit_face_visible_test(scene, ima, efa, tface))
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
@@ -3805,13 +3770,11 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
BMLoop *l;
BMIter iter, liter;
MLoopUV *luv;
- MTexPoly *tf;
const bool swap = RNA_boolean_get(op->ptr, "unselected");
Image *ima = sima ? sima->image : NULL;
const int use_face_center = (ts->uv_selectmode == UV_SELECT_FACE);
const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- const int cd_poly_tex_offset = CustomData_get_offset(&em->bm->pdata, CD_MTEXPOLY);
if (ts->uv_flag & UV_SYNC_SELECTION) {
EDBM_mesh_hide(em, swap);
@@ -3823,9 +3786,7 @@ static int uv_hide_exec(bContext *C, wmOperator *op)
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
int hide = 0;
- tf = BM_ELEM_CD_GET_VOID_P(efa, cd_poly_tex_offset);
-
- if (!uvedit_face_visible_test(scene, ima, efa, tf)) {
+ if (!uvedit_face_visible_test(scene, obedit, ima, efa)) {
continue;
}
@@ -4117,76 +4078,6 @@ static void UV_OT_cursor_set(wmOperatorType *ot)
/** \} */
/* -------------------------------------------------------------------- */
-/** \name Set Tile Operator
- * \{ */
-
-static int set_tile_exec(bContext *C, wmOperator *op)
-{
- Image *ima = CTX_data_edit_image(C);
- int tile[2];
- Object *obedit = CTX_data_edit_object(C);
-
- RNA_int_get_array(op->ptr, "tile", tile);
-
- if (uvedit_set_tile(obedit, ima, tile[0] + ima->xrep * tile[1])) {
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
- WM_event_add_notifier(C, NC_SPACE | ND_SPACE_IMAGE, NULL);
-
- return OPERATOR_FINISHED;
- }
-
- return OPERATOR_CANCELLED;
-}
-
-static int set_tile_invoke(bContext *C, wmOperator *op, const wmEvent *event)
-{
- SpaceImage *sima = CTX_wm_space_image(C);
- Image *ima = CTX_data_edit_image(C);
- ARegion *ar = CTX_wm_region(C);
- float fx, fy;
- int tile[2];
-
- if (!ima || !(ima->tpageflag & IMA_TILES))
- return OPERATOR_CANCELLED;
-
- UI_view2d_region_to_view(&ar->v2d, event->mval[0], event->mval[1], &fx, &fy);
-
- if (fx >= 0.0f && fy >= 0.0f && fx < 1.0f && fy < 1.0f) {
- fx = fx * ima->xrep;
- fy = fy * ima->yrep;
-
- tile[0] = fx;
- tile[1] = fy;
-
- sima->curtile = tile[1] * ima->xrep + tile[0];
- RNA_int_set_array(op->ptr, "tile", tile);
- }
-
- return set_tile_exec(C, op);
-}
-
-static void UV_OT_tile_set(wmOperatorType *ot)
-{
- /* identifiers */
- ot->name = "Set Tile";
- ot->description = "Set UV image tile coordinates";
- ot->idname = "UV_OT_tile_set";
-
- /* api callbacks */
- ot->exec = set_tile_exec;
- ot->invoke = set_tile_invoke;
- ot->poll = ED_operator_image_active;
-
- /* flags */
- ot->flag = OPTYPE_REGISTER | OPTYPE_UNDO;
-
- /* properties */
- RNA_def_int_vector(ot->srna, "tile", 2, NULL, 0, INT_MAX, "Tile", "Tile coordinate", 0, 10);
-}
-
-/** \} */
-
-/* -------------------------------------------------------------------- */
/** \name Seam from UV Islands Operator
* \{ */
@@ -4299,7 +4190,7 @@ static int uv_seams_from_islands_exec(bContext *C, wmOperator *op)
BM_uv_vert_map_free(vmap);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return OPERATOR_FINISHED;
@@ -4355,9 +4246,9 @@ static int uv_mark_seam_exec(bContext *C, wmOperator *op)
me->drawflag |= ME_DRAWSEAMS;
if (scene->toolsettings->edge_mode_live_unwrap)
- ED_unwrap_lscm(scene, ob, false);
+ ED_unwrap_lscm(scene, ob, false, false);
- DAG_id_tag_update(&me->id, 0);
+ DEG_id_tag_update(&me->id, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, me);
return OPERATOR_FINISHED;
@@ -4450,7 +4341,6 @@ void ED_operatortypes_uvedit(void)
WM_operatortype_append(UV_OT_hide);
WM_operatortype_append(UV_OT_cursor_set);
- WM_operatortype_append(UV_OT_tile_set);
}
void ED_keymap_uvedit(wmKeyConfig *keyconf)
@@ -4538,7 +4428,6 @@ void ED_keymap_uvedit(wmKeyConfig *keyconf)
/* cursor */
WM_keymap_add_item(keymap, "UV_OT_cursor_set", ACTIONMOUSE, KM_PRESS, 0, 0);
- WM_keymap_add_item(keymap, "UV_OT_tile_set", ACTIONMOUSE, KM_PRESS, KM_SHIFT, 0);
/* menus */
WM_keymap_add_menu(keymap, "IMAGE_MT_uvs_snap", SKEY, KM_PRESS, KM_SHIFT, 0);
diff --git a/source/blender/editors/uvedit/uvedit_smart_stitch.c b/source/blender/editors/uvedit/uvedit_smart_stitch.c
index 057417b898f..4c205818329 100644
--- a/source/blender/editors/uvedit/uvedit_smart_stitch.c
+++ b/source/blender/editors/uvedit/uvedit_smart_stitch.c
@@ -52,10 +52,11 @@
#include "BKE_context.h"
#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh_mapping.h"
#include "BKE_editmesh.h"
+#include "DEG_depsgraph.h"
+
#include "UI_interface.h"
#include "ED_mesh.h"
@@ -63,6 +64,8 @@
#include "ED_screen.h"
#include "ED_space_api.h"
+#include "GPU_batch.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
@@ -154,6 +157,8 @@ typedef struct StitchState {
bool snap_islands;
/* stitch at midpoints or at islands */
bool midpoints;
+ /* object for editmesh */
+ Object *obedit;
/* editmesh, cached for use in modal handler */
BMEditMesh *em;
/* clear seams of stitched edges after stitch */
@@ -1538,63 +1543,126 @@ static void stitch_calculate_edge_normal(BMEditMesh *em, UvEdge *edge, float *no
normalize_v2(normal);
}
+/**
+ */
+static void stitch_draw_vbo(Gwn_VertBuf *vbo, Gwn_PrimType prim_type, const float col[4])
+{
+ Gwn_Batch *batch = GWN_batch_create_ex(prim_type, vbo, NULL, GWN_BATCH_OWNS_VBO);
+ GWN_batch_program_set_builtin(batch, GPU_SHADER_2D_UNIFORM_COLOR);
+ GWN_batch_uniform_4fv(batch, "color", col);
+ GWN_batch_draw(batch);
+ GWN_batch_discard(batch);
+}
+
+/* TODO make things pretier : store batches inside StitchPreviewer instead of the bare verts pos */
static void stitch_draw(const bContext *UNUSED(C), ARegion *UNUSED(ar), void *arg)
{
- int i, index = 0;
+ int j, index = 0;
+ unsigned int num_line = 0, num_tri, tri_idx = 0, line_idx = 0;
StitchState *state = (StitchState *)arg;
StitchPreviewer *stitch_preview = state->stitch_preview;
+ Gwn_VertBuf *vbo, *vbo_line;
+ float col[4];
- glPushClientAttrib(GL_CLIENT_VERTEX_ARRAY_BIT);
- glEnableClientState(GL_VERTEX_ARRAY);
+ static Gwn_VertFormat format = { 0 };
+ static unsigned int pos_id;
+ if (format.attrib_ct == 0) {
+ pos_id = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
glEnable(GL_BLEND);
- UI_ThemeColor4(TH_STITCH_PREVIEW_ACTIVE);
- glVertexPointer(2, GL_FLOAT, 0, stitch_preview->static_tris);
- glDrawArrays(GL_TRIANGLES, 0, stitch_preview->num_static_tris * 3);
-
- glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_polys);
- for (i = 0; i < stitch_preview->num_polys; i++) {
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- UI_ThemeColor4(TH_STITCH_PREVIEW_FACE);
- glDrawArrays(GL_POLYGON, index, stitch_preview->uvs_per_polygon[i]);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- UI_ThemeColor4(TH_STITCH_PREVIEW_EDGE);
- glDrawArrays(GL_POLYGON, index, stitch_preview->uvs_per_polygon[i]);
-#if 0
- glPolygonMode(GL_FRONT_AND_BACK, GL_POINT);
- UI_ThemeColor4(TH_STITCH_PREVIEW_VERT);
- glDrawArrays(GL_POLYGON, index, stitch_preview->uvs_per_polygon[i]);
-#endif
-
- index += stitch_preview->uvs_per_polygon[i];
+ /* Static Tris */
+ UI_GetThemeColor4fv(TH_STITCH_PREVIEW_ACTIVE, col);
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, stitch_preview->num_static_tris * 3);
+ for (int i = 0; i < stitch_preview->num_static_tris * 3; i++) {
+ GWN_vertbuf_attr_set(vbo, pos_id, i, &stitch_preview->static_tris[i * 2]);
}
+ stitch_draw_vbo(vbo, GWN_PRIM_TRIS, col);
+
+
+ /* Preview Polys */
+ for (int i = 0; i < stitch_preview->num_polys; i++)
+ num_line += stitch_preview->uvs_per_polygon[i];
+
+ num_tri = num_line - 2 * stitch_preview->num_polys;
+
+ /* we need to convert the polys into triangles / lines */
+ vbo = GWN_vertbuf_create_with_format(&format);
+ vbo_line = GWN_vertbuf_create_with_format(&format);
+
+ GWN_vertbuf_data_alloc(vbo, num_tri * 3);
+ GWN_vertbuf_data_alloc(vbo_line, num_line * 2);
+
+ for (int i = 0; i < stitch_preview->num_polys; i++) {
+ BLI_assert(stitch_preview->uvs_per_polygon[i] >= 3);
+
+ /* Start line */
+ GWN_vertbuf_attr_set(vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[index]);
+ GWN_vertbuf_attr_set(vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[index + 2]);
+
+ for (j = 1; j < stitch_preview->uvs_per_polygon[i] - 1; ++j) {
+ GWN_vertbuf_attr_set(vbo, pos_id, tri_idx++, &stitch_preview->preview_polys[index]);
+ GWN_vertbuf_attr_set(vbo, pos_id, tri_idx++, &stitch_preview->preview_polys[index + (j + 0) * 2]);
+ GWN_vertbuf_attr_set(vbo, pos_id, tri_idx++, &stitch_preview->preview_polys[index + (j + 1) * 2]);
+
+ GWN_vertbuf_attr_set(vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[index + (j + 0) * 2]);
+ GWN_vertbuf_attr_set(vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[index + (j + 1) * 2]);
+ }
+
+ /* Closing line */
+ GWN_vertbuf_attr_set(vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[index]);
+ /* j = uvs_per_polygon[i] - 1*/
+ GWN_vertbuf_attr_set(vbo_line, pos_id, line_idx++, &stitch_preview->preview_polys[index + j * 2]);
+
+ index += stitch_preview->uvs_per_polygon[i] * 2;
+ }
+ UI_GetThemeColor4fv(TH_STITCH_PREVIEW_FACE, col);
+ stitch_draw_vbo(vbo, GWN_PRIM_TRIS, col);
+ UI_GetThemeColor4fv(TH_STITCH_PREVIEW_EDGE, col);
+ stitch_draw_vbo(vbo_line, GWN_PRIM_LINES, col);
+
glDisable(GL_BLEND);
- /* draw vert preview */
+
+ /* draw stitch vert/lines preview */
if (state->mode == STITCH_VERT) {
glPointSize(UI_GetThemeValuef(TH_VERTEX_SIZE) * 2.0f);
- UI_ThemeColor4(TH_STITCH_PREVIEW_STITCHABLE);
- glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_stitchable);
- glDrawArrays(GL_POINTS, 0, stitch_preview->num_stitchable);
+ UI_GetThemeColor4fv(TH_STITCH_PREVIEW_STITCHABLE, col);
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, stitch_preview->num_stitchable);
+ for (int i = 0; i < stitch_preview->num_stitchable; i++) {
+ GWN_vertbuf_attr_set(vbo, pos_id, i, &stitch_preview->preview_stitchable[i * 2]);
+ }
+ stitch_draw_vbo(vbo, GWN_PRIM_POINTS, col);
- UI_ThemeColor4(TH_STITCH_PREVIEW_UNSTITCHABLE);
- glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_unstitchable);
- glDrawArrays(GL_POINTS, 0, stitch_preview->num_unstitchable);
+ UI_GetThemeColor4fv(TH_STITCH_PREVIEW_UNSTITCHABLE, col);
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, stitch_preview->num_unstitchable);
+ for (int i = 0; i < stitch_preview->num_unstitchable; i++) {
+ GWN_vertbuf_attr_set(vbo, pos_id, i, &stitch_preview->preview_unstitchable[i * 2]);
+ }
+ stitch_draw_vbo(vbo, GWN_PRIM_POINTS, col);
}
else {
- UI_ThemeColor4(TH_STITCH_PREVIEW_STITCHABLE);
- glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_stitchable);
- glDrawArrays(GL_LINES, 0, 2 * stitch_preview->num_stitchable);
+ UI_GetThemeColor4fv(TH_STITCH_PREVIEW_STITCHABLE, col);
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, stitch_preview->num_stitchable * 2);
+ for (int i = 0; i < stitch_preview->num_stitchable * 2; i++) {
+ GWN_vertbuf_attr_set(vbo, pos_id, i, &stitch_preview->preview_stitchable[i * 2]);
+ }
+ stitch_draw_vbo(vbo, GWN_PRIM_LINES, col);
- UI_ThemeColor4(TH_STITCH_PREVIEW_UNSTITCHABLE);
- glVertexPointer(2, GL_FLOAT, 0, stitch_preview->preview_unstitchable);
- glDrawArrays(GL_LINES, 0, 2 * stitch_preview->num_unstitchable);
+ UI_GetThemeColor4fv(TH_STITCH_PREVIEW_UNSTITCHABLE, col);
+ vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, stitch_preview->num_unstitchable * 2);
+ for (int i = 0; i < stitch_preview->num_unstitchable * 2; i++) {
+ GWN_vertbuf_attr_set(vbo, pos_id, i, &stitch_preview->preview_unstitchable[i * 2]);
+ }
+ stitch_draw_vbo(vbo, GWN_PRIM_LINES, col);
}
-
- glPopClientAttrib();
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}
static UvEdge *uv_edge_get(BMLoop *l, StitchState *state)
@@ -1653,6 +1721,7 @@ static int stitch_init(bContext *C, wmOperator *op)
/* initialize state */
state->use_limit = RNA_boolean_get(op->ptr, "use_limit");
state->limit_dist = RNA_float_get(op->ptr, "limit");
+ state->obedit = obedit;
state->em = em;
state->snap_islands = RNA_boolean_get(op->ptr, "snap_islands");
state->static_island = RNA_int_get(op->ptr, "static_island");
@@ -2024,7 +2093,7 @@ static void stitch_exit(bContext *C, wmOperator *op, int finished)
ED_region_draw_cb_exit(CTX_wm_region(C)->type, state->draw_handle);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
state_delete(state);
@@ -2066,7 +2135,7 @@ static void stitch_select(bContext *C, Scene *scene, const wmEvent *event, Stitc
if (state->mode == STITCH_VERT) {
if (uv_find_nearest_vert(
- scene, ima, state->em, co, 0.0f, &hit))
+ scene, ima, state->obedit, co, 0.0f, &hit))
{
/* Add vertex to selection, deselect all common uv's of vert other
* than selected and update the preview. This behavior was decided so that
@@ -2080,7 +2149,7 @@ static void stitch_select(bContext *C, Scene *scene, const wmEvent *event, Stitc
}
else {
if (uv_find_nearest_edge(
- scene, ima, state->em, co, &hit))
+ scene, ima, state->obedit, co, &hit))
{
UvEdge *edge = uv_edge_get(hit.l, state);
stitch_select_edge(edge, state, false);
diff --git a/source/blender/editors/uvedit/uvedit_unwrap_ops.c b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
index bc38a1cd3bb..1442266a3aa 100644
--- a/source/blender/editors/uvedit/uvedit_unwrap_ops.c
+++ b/source/blender/editors/uvedit/uvedit_unwrap_ops.c
@@ -55,12 +55,15 @@
#include "BKE_subsurf.h"
#include "BKE_context.h"
#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BKE_main.h"
+#include "BKE_material.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_editmesh.h"
+#include "BKE_layer.h"
+
+#include "DEG_depsgraph.h"
#include "PIL_time.h"
@@ -100,9 +103,8 @@ static void modifier_unwrap_state(Object *obedit, Scene *scene, bool *r_use_subs
*r_use_subsurf = subsurf;
}
-static bool ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit)
+static bool ED_uvedit_ensure_uvs(bContext *C, Scene *UNUSED(scene), Object *obedit)
{
- Main *bmain = CTX_data_main(C);
BMEditMesh *em = BKE_editmesh_from_object(obedit);
BMFace *efa;
BMIter iter;
@@ -116,7 +118,7 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit)
if (ED_uvedit_test(obedit))
return 1;
- if (em && em->bm->totface && !CustomData_has_layer(&em->bm->pdata, CD_MTEXPOLY))
+ if (em && em->bm->totface && !CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV))
ED_mesh_uv_texture_add(obedit->data, NULL, true);
if (!ED_uvedit_test(obedit))
@@ -146,9 +148,6 @@ static bool ED_uvedit_ensure_uvs(bContext *C, Scene *scene, Object *obedit)
}
}
- if (ima)
- ED_uvedit_assign_image(bmain, scene, obedit, ima, NULL);
-
/* select new UV's (ignore UV_SYNC_SELECTION in this case) */
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
BMIter liter;
@@ -200,7 +199,22 @@ static bool uvedit_have_selection(Scene *scene, BMEditMesh *em, bool implicit)
return false;
}
-void ED_uvedit_get_aspect(Scene *scene, Object *ob, BMesh *bm, float *aspx, float *aspy)
+static bool uvedit_have_selection_multi(
+ Scene *scene, Object **objects, const uint objects_len, bool implicit)
+{
+ bool have_select = false;
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ if (uvedit_have_selection(scene, em, implicit)) {
+ have_select = true;
+ break;
+ }
+ }
+ return have_select;
+}
+
+void ED_uvedit_get_aspect(Scene *UNUSED(scene), Object *ob, BMesh *bm, float *aspx, float *aspy)
{
bool sloppy = true;
bool selected = false;
@@ -210,13 +224,7 @@ void ED_uvedit_get_aspect(Scene *scene, Object *ob, BMesh *bm, float *aspx, floa
efa = BM_mesh_active_face_get(bm, sloppy, selected);
if (efa) {
- if (BKE_scene_use_new_shading_nodes(scene)) {
- ED_object_get_active_image(ob, efa->mat_nr + 1, &ima, NULL, NULL, NULL);
- }
- else {
- MTexPoly *tf = CustomData_bmesh_get(&bm->pdata, efa->head.data, CD_MTEXPOLY);
- ima = tf->tpage;
- }
+ ED_object_get_active_image(ob, efa->mat_nr + 1, &ima, NULL, NULL, NULL);
ED_image_get_uv_aspect(ima, NULL, aspx, aspy);
}
@@ -257,9 +265,11 @@ static void construct_param_handle_face_add(ParamHandle *handle, Scene *scene,
param_face_add(handle, key, i, vkeys, co, uv, pin, select, efa->no);
}
-static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMesh *bm,
- const bool implicit, const bool fill, const bool sel,
- const bool correct_aspect)
+/* See: construct_param_handle_multi to handle multiple objects at once. */
+static ParamHandle *construct_param_handle(
+ Scene *scene, Object *ob, BMesh *bm,
+ const bool implicit, const bool fill, const bool sel,
+ const bool correct_aspect)
{
ParamHandle *handle;
BMFace *efa;
@@ -323,6 +333,89 @@ static ParamHandle *construct_param_handle(Scene *scene, Object *ob, BMesh *bm,
return handle;
}
+/**
+ * Version of #construct_param_handle_single that handles multiple objects.
+ */
+static ParamHandle *construct_param_handle_multi(
+ Scene *scene, Object **objects, const uint objects_len,
+ const bool implicit, const bool fill, const bool sel,
+ const bool correct_aspect)
+{
+ ParamHandle *handle;
+ BMFace *efa;
+ BMLoop *l;
+ BMEdge *eed;
+ BMIter iter, liter;
+ int i;
+
+
+ handle = param_construct_begin();
+
+ if (correct_aspect) {
+ Object *ob = objects[0];
+ BMEditMesh *em = BKE_editmesh_from_object(ob);
+ BMesh *bm = em->bm;
+ float aspx, aspy;
+
+ ED_uvedit_get_aspect(scene, ob, bm, &aspx, &aspy);
+ if (aspx != aspy) {
+ param_aspect_ratio(handle, aspx, aspy);
+ }
+ }
+
+ /* we need the vert indices */
+ EDBM_mesh_elem_index_ensure_multi(objects, objects_len, BM_VERT);
+
+ int offset = 0;
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ BMesh *bm = em->bm;
+
+ const int cd_loop_uv_offset = CustomData_get_offset(&bm->ldata, CD_MLOOPUV);
+
+ BM_ITER_MESH_INDEX (efa, &iter, bm, BM_FACES_OF_MESH, i) {
+
+ if ((BM_elem_flag_test(efa, BM_ELEM_HIDDEN)) || (sel && BM_elem_flag_test(efa, BM_ELEM_SELECT) == 0)) {
+ continue;
+ }
+
+ if (implicit) {
+ bool is_loopsel = false;
+
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ if (uvedit_uv_select_test(scene, l, cd_loop_uv_offset)) {
+ is_loopsel = true;
+ break;
+ }
+ }
+ if (is_loopsel == false) {
+ continue;
+ }
+ }
+
+ construct_param_handle_face_add(handle, scene, efa, i + offset, cd_loop_uv_offset);
+ }
+
+ if (!implicit) {
+ BM_ITER_MESH (eed, &iter, bm, BM_EDGES_OF_MESH) {
+ if (BM_elem_flag_test(eed, BM_ELEM_SEAM)) {
+ ParamKey vkeys[2];
+ vkeys[0] = (ParamKey)BM_elem_index_get(eed->v1);
+ vkeys[1] = (ParamKey)BM_elem_index_get(eed->v2);
+ param_edge_set_seam(handle, vkeys);
+ }
+ }
+ }
+ offset += bm->totface;
+ }
+
+ param_construct_end(handle, fill, implicit);
+
+ return handle;
+}
+
static void texface_from_original_index(BMFace *efa, int index, float **uv, ParamBool *pin, ParamBool *select,
Scene *scene, const int cd_loop_uv_offset)
@@ -570,7 +663,7 @@ static void minimize_stretch_iteration(bContext *C, wmOperator *op, bool interac
ms->lasttime = PIL_check_seconds_timer();
- DAG_id_tag_update(ms->obedit->data, 0);
+ DEG_id_tag_update(ms->obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ms->obedit->data);
}
}
@@ -593,7 +686,7 @@ static void minimize_stretch_exit(bContext *C, wmOperator *op, bool cancel)
param_stretch_end(ms->handle);
param_delete(ms->handle);
- DAG_id_tag_update(ms->obedit->data, 0);
+ DEG_id_tag_update(ms->obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, ms->obedit->data);
MEM_freeN(ms);
@@ -714,6 +807,7 @@ void UV_OT_minimize_stretch(wmOperatorType *ot)
/* ******************** Pack Islands operator **************** */
+
void ED_uvedit_pack_islands(Scene *scene, Object *ob, BMesh *bm, bool selected, bool correct_aspect, bool do_rotate)
{
ParamHandle *handle;
@@ -723,14 +817,29 @@ void ED_uvedit_pack_islands(Scene *scene, Object *ob, BMesh *bm, bool selected,
param_delete(handle);
}
+void ED_uvedit_pack_islands_multi(
+ Scene *scene, Object **objects, const uint objects_len,
+ bool selected, bool correct_aspect, bool do_rotate)
+{
+ ParamHandle *handle;
+ handle = construct_param_handle_multi(
+ scene, objects, objects_len, true, false, selected, correct_aspect);
+ param_pack(handle, scene->toolsettings->uvcalc_margin, do_rotate);
+ param_flush(handle);
+ param_delete(handle);
+}
+
static int pack_islands_exec(bContext *C, wmOperator *op)
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
bool do_rotate = RNA_boolean_get(op->ptr, "rotate");
- if (!uvedit_have_selection(scene, em, true)) {
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data_with_uvs(view_layer, &objects_len);
+
+ if (!uvedit_have_selection_multi(scene, objects, objects_len, true)) {
+ MEM_SAFE_FREE(objects);
return OPERATOR_CANCELLED;
}
@@ -739,10 +848,15 @@ static int pack_islands_exec(bContext *C, wmOperator *op)
else
RNA_float_set(op->ptr, "margin", scene->toolsettings->uvcalc_margin);
- ED_uvedit_pack_islands(scene, obedit, em->bm, true, true, do_rotate);
-
- DAG_id_tag_update(obedit->data, 0);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ ED_uvedit_pack_islands_multi(scene, objects, objects_len, true, true, do_rotate);
+
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ DEG_id_tag_update(obedit->data, 0);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ }
+
+ MEM_SAFE_FREE(objects);
return OPERATOR_FINISHED;
}
@@ -784,7 +898,7 @@ static int average_islands_scale_exec(bContext *C, wmOperator *UNUSED(op))
param_flush(handle);
param_delete(handle);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -855,7 +969,7 @@ void ED_uvedit_live_unwrap(Scene *scene, Object *obedit)
if (scene->toolsettings->edge_mode_live_unwrap &&
CustomData_has_layer(&em->bm->ldata, CD_MLOOPUV))
{
- ED_unwrap_lscm(scene, obedit, false); /* unwrap all not just sel */
+ ED_unwrap_lscm(scene, obedit, false, false); /* unwrap all not just sel */
}
}
@@ -1177,7 +1291,7 @@ static void uv_map_clip_correct(Scene *scene, Object *ob, BMEditMesh *em, wmOper
/* ******************** Unwrap operator **************** */
/* assumes UV Map is checked, doesn't run update funcs */
-void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel)
+void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel, const bool pack)
{
BMEditMesh *em = BKE_editmesh_from_object(obedit);
ParamHandle *handle;
@@ -1198,7 +1312,10 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel)
param_lscm_end(handle);
param_average(handle);
- param_pack(handle, scene->toolsettings->uvcalc_margin, false);
+
+ if (pack) {
+ param_pack(handle, scene->toolsettings->uvcalc_margin, false);
+ }
param_flush(handle);
@@ -1207,33 +1324,48 @@ void ED_unwrap_lscm(Scene *scene, Object *obedit, const short sel)
static int unwrap_exec(bContext *C, wmOperator *op)
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
int method = RNA_enum_get(op->ptr, "method");
const bool fill_holes = RNA_boolean_get(op->ptr, "fill_holes");
const bool correct_aspect = RNA_boolean_get(op->ptr, "correct_aspect");
const bool use_subsurf = RNA_boolean_get(op->ptr, "use_subsurf_data");
- bool use_subsurf_final;
float obsize[3];
bool implicit = false;
- if (!uvedit_have_selection(scene, em, implicit)) {
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
+
+ if (!uvedit_have_selection_multi(scene, objects, objects_len, implicit)) {
+ MEM_SAFE_FREE(objects);
return OPERATOR_CANCELLED;
}
-
+
/* add uvs if they don't exist yet */
- if (!ED_uvedit_ensure_uvs(C, scene, obedit)) {
- return OPERATOR_CANCELLED;
- }
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ bool use_subsurf_final;
- mat4_to_size(obsize, obedit->obmat);
- if (!(fabsf(obsize[0] - obsize[1]) < 1e-4f && fabsf(obsize[1] - obsize[2]) < 1e-4f))
- BKE_report(op->reports, RPT_INFO,
- "Object has non-uniform scale, unwrap will operate on a non-scaled version of the mesh");
- else if (is_negative_m4(obedit->obmat))
- BKE_report(op->reports, RPT_INFO,
- "Object has negative scale, unwrap will operate on a non-flipped version of the mesh");
+ if (!ED_uvedit_ensure_uvs(C, scene, obedit)) {
+ continue;
+ }
+
+ mat4_to_size(obsize, obedit->obmat);
+ if (!(fabsf(obsize[0] - obsize[1]) < 1e-4f && fabsf(obsize[1] - obsize[2]) < 1e-4f))
+ BKE_report(op->reports, RPT_INFO,
+ "Object has non-uniform scale, unwrap will operate on a non-scaled version of the mesh");
+ else if (is_negative_m4(obedit->obmat))
+ BKE_report(op->reports, RPT_INFO,
+ "Object has negative scale, unwrap will operate on a non-flipped version of the mesh");
+
+
+ /* double up the check here but better keep ED_unwrap_lscm interface simple and not
+ * pass operator for warning append */
+ modifier_unwrap_state(obedit, scene, &use_subsurf_final);
+ if (use_subsurf != use_subsurf_final) {
+ BKE_report(op->reports, RPT_INFO, "Subdivision Surface modifier needs to be first to work with unwrap");
+ }
+ }
/* remember last method for live unwrap */
if (RNA_struct_property_is_set(op->ptr, "method"))
@@ -1256,17 +1388,17 @@ static int unwrap_exec(bContext *C, wmOperator *op)
if (use_subsurf) scene->toolsettings->uvcalc_flag |= UVCALC_USESUBSURF;
else scene->toolsettings->uvcalc_flag &= ~UVCALC_USESUBSURF;
- /* double up the check here but better keep ED_unwrap_lscm interface simple and not
- * pass operator for warning append */
- modifier_unwrap_state(obedit, scene, &use_subsurf_final);
- if (use_subsurf != use_subsurf_final)
- BKE_report(op->reports, RPT_INFO, "Subdivision Surface modifier needs to be first to work with unwrap");
-
/* execute unwrap */
- ED_unwrap_lscm(scene, obedit, true);
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ ED_unwrap_lscm(scene, obedit, true, false);
+ DEG_id_tag_update(obedit->data, 0);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ }
- DAG_id_tag_update(obedit->data, 0);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ ED_uvedit_pack_islands_multi(scene, objects, objects_len, true, true, true);
+
+ MEM_SAFE_FREE(objects);
return OPERATOR_FINISHED;
}
@@ -1321,9 +1453,8 @@ static int uv_from_view_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSE
static int uv_from_view_exec(bContext *C, wmOperator *op)
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Scene *scene = CTX_data_scene(C);
- Object *obedit = CTX_data_edit_object(C);
- BMEditMesh *em = BKE_editmesh_from_object(obedit);
ARegion *ar = CTX_wm_region(C);
View3D *v3d = CTX_wm_view3d(C);
RegionView3D *rv3d = CTX_wm_region_view3d(C);
@@ -1333,69 +1464,90 @@ static int uv_from_view_exec(bContext *C, wmOperator *op)
BMIter iter, liter;
MLoopUV *luv;
float rotmat[4][4];
+ bool changed_multi = false;
- int cd_loop_uv_offset;
+ uint objects_len = 0;
+ Object **objects = BKE_view_layer_array_from_objects_in_edit_mode_unique_data(view_layer, &objects_len);
- /* add uvs if they don't exist yet */
- if (!ED_uvedit_ensure_uvs(C, scene, obedit)) {
- return OPERATOR_CANCELLED;
- }
+ for (uint ob_index = 0; ob_index < objects_len; ob_index++) {
+ Object *obedit = objects[ob_index];
+ BMEditMesh *em = BKE_editmesh_from_object(obedit);
+ bool changed = false;
- cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
+ /* add uvs if they don't exist yet */
+ if (!ED_uvedit_ensure_uvs(C, scene, obedit)) {
+ continue;
+ }
- if (RNA_boolean_get(op->ptr, "orthographic")) {
- uv_map_rotation_matrix(rotmat, rv3d, obedit, 90.0f, 0.0f, 1.0f);
-
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- if (!BM_elem_flag_test(efa, BM_ELEM_SELECT))
- continue;
+ const int cd_loop_uv_offset = CustomData_get_offset(&em->bm->ldata, CD_MLOOPUV);
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- BLI_uvproject_from_view_ortho(luv->uv, l->v->co, rotmat);
- }
- }
- }
- else if (camera) {
- const bool camera_bounds = RNA_boolean_get(op->ptr, "camera_bounds");
- struct ProjCameraInfo *uci = BLI_uvproject_camera_info(v3d->camera, obedit->obmat,
- camera_bounds ? (scene->r.xsch * scene->r.xasp) : 1.0f,
- camera_bounds ? (scene->r.ysch * scene->r.yasp) : 1.0f);
+ if (RNA_boolean_get(op->ptr, "orthographic")) {
+ uv_map_rotation_matrix(rotmat, rv3d, obedit, 90.0f, 0.0f, 1.0f);
- if (uci) {
BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
if (!BM_elem_flag_test(efa, BM_ELEM_SELECT))
continue;
BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- BLI_uvproject_from_camera(luv->uv, l->v->co, uci);
+ BLI_uvproject_from_view_ortho(luv->uv, l->v->co, rotmat);
}
+ changed = true;
}
-
- MEM_freeN(uci);
}
- }
- else {
- copy_m4_m4(rotmat, obedit->obmat);
+ else if (camera) {
+ const bool camera_bounds = RNA_boolean_get(op->ptr, "camera_bounds");
+ struct ProjCameraInfo *uci = BLI_uvproject_camera_info(
+ v3d->camera, obedit->obmat,
+ camera_bounds ? (scene->r.xsch * scene->r.xasp) : 1.0f,
+ camera_bounds ? (scene->r.ysch * scene->r.yasp) : 1.0f);
+
+ if (uci) {
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_SELECT))
+ continue;
+
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ BLI_uvproject_from_camera(luv->uv, l->v->co, uci);
+ }
+ changed = true;
+ }
- BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
- if (!BM_elem_flag_test(efa, BM_ELEM_SELECT))
- continue;
+ MEM_freeN(uci);
+ }
+ }
+ else {
+ copy_m4_m4(rotmat, obedit->obmat);
- BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
- luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
- BLI_uvproject_from_view(luv->uv, l->v->co, rv3d->persmat, rotmat, ar->winx, ar->winy);
+ BM_ITER_MESH (efa, &iter, em->bm, BM_FACES_OF_MESH) {
+ if (!BM_elem_flag_test(efa, BM_ELEM_SELECT))
+ continue;
+
+ BM_ITER_ELEM (l, &liter, efa, BM_LOOPS_OF_FACE) {
+ luv = BM_ELEM_CD_GET_VOID_P(l, cd_loop_uv_offset);
+ BLI_uvproject_from_view(luv->uv, l->v->co, rv3d->persmat, rotmat, ar->winx, ar->winy);
+ }
+ changed = true;
}
}
- }
- uv_map_clip_correct(scene, obedit, em, op);
+ if (changed) {
+ changed_multi = true;
+ uv_map_clip_correct(scene, obedit, em, op);
- DAG_id_tag_update(obedit->data, 0);
- WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ DEG_id_tag_update(obedit->data, 0);
+ WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
+ }
+ }
+ MEM_SAFE_FREE(objects);
- return OPERATOR_FINISHED;
+ if (changed_multi) {
+ return OPERATOR_FINISHED;
+ }
+ else {
+ return OPERATOR_CANCELLED;
+ }
}
static int uv_from_view_poll(bContext *C)
@@ -1445,7 +1597,7 @@ static int reset_exec(bContext *C, wmOperator *UNUSED(op))
ED_mesh_uv_loop_reset(C, me);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -1481,7 +1633,7 @@ static void uv_sphere_project(float target[2], float source[3], float center[3],
target[0] -= 1.0f;
}
-static void uv_map_mirror(BMEditMesh *em, BMFace *efa, MTexPoly *UNUSED(tf))
+static void uv_map_mirror(BMEditMesh *em, BMFace *efa)
{
BMLoop *l;
BMIter liter;
@@ -1519,7 +1671,6 @@ static int sphere_project_exec(bContext *C, wmOperator *op)
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
float center[3], rotmat[4][4];
@@ -1545,13 +1696,12 @@ static int sphere_project_exec(bContext *C, wmOperator *op)
uv_sphere_project(luv->uv, l->v->co, center, rotmat);
}
- tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
- uv_map_mirror(em, efa, tf);
+ uv_map_mirror(em, efa);
}
uv_map_clip_correct(scene, obedit, em, op);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -1600,7 +1750,6 @@ static int cylinder_project_exec(bContext *C, wmOperator *op)
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- MTexPoly *tf;
MLoopUV *luv;
float center[3], rotmat[4][4];
@@ -1626,13 +1775,12 @@ static int cylinder_project_exec(bContext *C, wmOperator *op)
uv_cylinder_project(luv->uv, l->v->co, center, rotmat);
}
- tf = CustomData_bmesh_get(&em->bm->pdata, efa->head.data, CD_MTEXPOLY);
- uv_map_mirror(em, efa, tf);
+ uv_map_mirror(em, efa);
}
uv_map_clip_correct(scene, obedit, em, op);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
@@ -1663,7 +1811,6 @@ void ED_uvedit_unwrap_cube_project(BMesh *bm, float cube_size, bool use_select,
BMFace *efa;
BMLoop *l;
BMIter iter, liter;
- /* MTexPoly *tf; */ /* UNUSED */
MLoopUV *luv;
float loc[3];
int cox, coy;
@@ -1733,7 +1880,7 @@ static int cube_project_exec(bContext *C, wmOperator *op)
uv_map_clip_correct(scene, obedit, em, op);
- DAG_id_tag_update(obedit->data, 0);
+ DEG_id_tag_update(obedit->data, 0);
WM_event_add_notifier(C, NC_GEOM | ND_DATA, obedit->data);
return OPERATOR_FINISHED;
diff --git a/source/blender/freestyle/CMakeLists.txt b/source/blender/freestyle/CMakeLists.txt
index f6b7efe978c..183eaf595ed 100644
--- a/source/blender/freestyle/CMakeLists.txt
+++ b/source/blender/freestyle/CMakeLists.txt
@@ -392,8 +392,8 @@ set(SRC
intern/scene_graph/NodeGroup.h
intern/scene_graph/NodeLight.cpp
intern/scene_graph/NodeLight.h
- intern/scene_graph/NodeSceneRenderLayer.cpp
- intern/scene_graph/NodeSceneRenderLayer.h
+ intern/scene_graph/NodeViewLayer.cpp
+ intern/scene_graph/NodeViewLayer.h
intern/scene_graph/NodeShape.cpp
intern/scene_graph/NodeShape.h
intern/scene_graph/NodeTransform.cpp
@@ -557,6 +557,7 @@ set(INC
../blenkernel
../blenlib
../blentranslation
+ ../depsgraph
../imbuf
../makesdna
../makesrna
diff --git a/source/blender/freestyle/FRS_freestyle.h b/source/blender/freestyle/FRS_freestyle.h
index a6382010ca7..58f1c343235 100644
--- a/source/blender/freestyle/FRS_freestyle.h
+++ b/source/blender/freestyle/FRS_freestyle.h
@@ -30,6 +30,7 @@ extern "C" {
#endif
struct Render;
+struct RenderLayer;
struct Material;
struct FreestyleConfig;
struct FreestyleLineStyle;
@@ -50,13 +51,13 @@ extern struct FreestyleGlobals g_freestyle;
void FRS_initialize(void);
void FRS_set_context(struct bContext *C);
void FRS_read_file(struct bContext *C);
-int FRS_is_freestyle_enabled(struct SceneRenderLayer *srl);
+int FRS_is_freestyle_enabled(struct ViewLayer *view_layer);
void FRS_init_stroke_renderer(struct Render *re);
void FRS_begin_stroke_rendering(struct Render *re);
-struct Render *FRS_do_stroke_rendering(struct Render *re, struct SceneRenderLayer *srl, int render);
+struct Render *FRS_do_stroke_rendering(struct Render *re, struct ViewLayer *view_layer, int render);
void FRS_end_stroke_rendering(struct Render *re);
void FRS_free_view_map_cache(void);
-void FRS_composite_result(struct Render *re, struct SceneRenderLayer *srl, struct Render *freestyle_render);
+void FRS_composite_result(struct Render *re, struct ViewLayer *view_layer, struct Render *freestyle_render);
void FRS_exit(void);
/* FreestyleConfig.linesets */
diff --git a/source/blender/freestyle/intern/application/Controller.cpp b/source/blender/freestyle/intern/application/Controller.cpp
index beb85798223..759f6456759 100644
--- a/source/blender/freestyle/intern/application/Controller.cpp
+++ b/source/blender/freestyle/intern/application/Controller.cpp
@@ -40,7 +40,7 @@ extern "C" {
#include "../scene_graph/NodeDrawingStyle.h"
#include "../scene_graph/NodeShape.h"
#include "../scene_graph/NodeTransform.h"
-#include "../scene_graph/NodeSceneRenderLayer.h"
+#include "../scene_graph/NodeViewLayer.h"
#include "../scene_graph/ScenePrettyPrinter.h"
#include "../scene_graph/VertexRep.h"
@@ -232,9 +232,9 @@ bool Controller::hitViewMapCache()
return false;
}
-int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
+int Controller::LoadMesh(Render *re, ViewLayer *view_layer)
{
- BlenderFileLoader loader(re, srl);
+ BlenderFileLoader loader(re, view_layer);
loader.setRenderMonitor(_pRenderMonitor);
@@ -301,7 +301,7 @@ int Controller::LoadMesh(Render *re, SceneRenderLayer *srl)
}
cam->setProjectionMatrix(proj);
_RootNode->AddChild(cam);
- _RootNode->AddChild(new NodeSceneRenderLayer(*re->scene, *srl));
+ _RootNode->AddChild(new NodeViewLayer(*re->scene, *view_layer));
sceneHashFunc.reset();
//blenderScene->accept(sceneHashFunc);
diff --git a/source/blender/freestyle/intern/application/Controller.h b/source/blender/freestyle/intern/application/Controller.h
index 154edaf1e53..0304c18b8a6 100644
--- a/source/blender/freestyle/intern/application/Controller.h
+++ b/source/blender/freestyle/intern/application/Controller.h
@@ -68,7 +68,7 @@ public:
//soc
void init_options();
- int LoadMesh(Render *re, SceneRenderLayer *srl);
+ int LoadMesh(Render *re, ViewLayer *view_layer);
int Load3DSFile(const char *iFileName);
void CloseFile();
void ComputeViewMap();
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index 1f5e2b63bfa..d571ca135a1 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
@@ -32,16 +32,16 @@
namespace Freestyle {
-BlenderFileLoader::BlenderFileLoader(Render *re, SceneRenderLayer *srl)
+BlenderFileLoader::BlenderFileLoader(Render *re, ViewLayer *view_layer)
{
_re = re;
- _srl = srl;
+ _view_layer = view_layer;
_Scene = NULL;
_numFacesRead = 0;
#if 0
_minEdgeSize = DBL_MAX;
#endif
- _smooth = (srl->freestyleConfig.flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) != 0;
+ _smooth = (view_layer->freestyle_config.flags & FREESTYLE_FACE_SMOOTHNESS_FLAG) != 0;
_pRenderMonitor = NULL;
}
@@ -52,8 +52,6 @@ BlenderFileLoader::~BlenderFileLoader()
NodeGroup *BlenderFileLoader::Load()
{
- ObjectInstanceRen *obi;
-
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "\n=== Importing triangular meshes into Blender ===" << endl;
}
@@ -81,6 +79,11 @@ NodeGroup *BlenderFileLoader::Load()
_z_offset = 0.f;
}
+ ViewLayer *view_layer = (ViewLayer*)BLI_findstring(&_re->scene->view_layers, _view_layer->name, offsetof(ViewLayer, name));
+ Depsgraph *depsgraph = DEG_graph_new(_re->scene, view_layer, DAG_EVAL_RENDER);
+
+ BKE_scene_graph_update_tagged(depsgraph, _re->main);
+
#if 0
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "Frustum: l " << _viewplane_left << " r " << _viewplane_right
@@ -90,34 +93,37 @@ NodeGroup *BlenderFileLoader::Load()
#endif
int id = 0;
- unsigned cnt = 1;
- unsigned cntStep = (unsigned)ceil(0.01f * _re->totinstance);
- for (obi = (ObjectInstanceRen *)_re->instancetable.first; obi; obi = obi->next) {
- if (_pRenderMonitor) {
- if (_pRenderMonitor->testBreak())
- break;
- if (cnt % cntStep == 0) {
- stringstream ss;
- ss << "Freestyle: Mesh loading " << (100 * cnt / _re->totinstance) << "%";
- _pRenderMonitor->setInfo(ss.str());
- _pRenderMonitor->progress((float)cnt / _re->totinstance);
- }
- cnt++;
+
+ DEG_OBJECT_ITER_BEGIN(
+ depsgraph, ob, DEG_ITER_OBJECT_MODE_RENDER,
+ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
+ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
+ DEG_ITER_OBJECT_FLAG_VISIBLE |
+ DEG_ITER_OBJECT_FLAG_DUPLI)
+ {
+ if (_pRenderMonitor && _pRenderMonitor->testBreak()) {
+ break;
}
- if (!(obi->lay & _srl->lay))
- continue;
- char *name = obi->ob->id.name;
- //printf("%c%c:%s\n", name[0], name[1], name+2);
- //print_m4("obi->mat", obi->mat);
+ bool apply_modifiers = true;
+ bool calc_undeformed = false;
+ bool calc_tessface = false;
+ Mesh *mesh = BKE_mesh_new_from_object(depsgraph,
+ _re->main,
+ _re->scene,
+ ob,
+ apply_modifiers,
+ calc_tessface,
+ calc_undeformed);
- if (obi->obr->totvlak > 0) {
- insertShapeNode(obi, ++id);
- }
- else if (G.debug & G_DEBUG_FREESTYLE) {
- cout << "Warning: " << (name + 2) << " is not a vlak-based object (ignored)" << endl;
+ if (mesh) {
+ insertShapeNode(ob, mesh, ++id);
+ BKE_libblock_free_ex(_re->main, &mesh->id, true, false);
}
}
+ DEG_OBJECT_ITER_END;
+
+ DEG_graph_free(depsgraph);
// Return the built scene.
return _Scene;
@@ -365,95 +371,86 @@ int BlenderFileLoader::testDegenerateTriangle(float v1[3], float v2[3], float v3
return 0;
}
-// Checks if edge rotation (if necessary) can prevent the given quad from
-// being decomposed into a degenerate triangle
-bool BlenderFileLoader::testEdgeRotation(float v1[3], float v2[3], float v3[3], float v4[3])
+static bool testEdgeMark(Mesh *me, FreestyleEdge *fed, const MLoopTri *lt, int i)
{
- if (testDegenerateTriangle(v1, v2, v3) == 2 || testDegenerateTriangle(v1, v3, v4) == 2) {
- if (testDegenerateTriangle(v1, v2, v4) == 2 || testDegenerateTriangle(v2, v3, v4) == 2) {
-#if 0
- if (G.debug & G_DEBUG_FREESTYLE) {
- printf("BlenderFileLoader::testEdgeRotation: edge rotation is unsuccessful.\n");
- }
-#endif
- return false;
- }
- return true;
+ MLoop *mloop = &me->mloop[lt->tri[i]];
+ MLoop *mloop_next = &me->mloop[lt->tri[(i+1)%3]];
+ MEdge *medge = &me->medge[mloop->e];
+
+ if (!ELEM(mloop_next->v, medge->v1, medge->v2)) {
+ /* Not an edge in the original mesh before triangulation. */
+ return false;
}
- return false;
+
+ return (fed[mloop->e].flag & FREESTYLE_EDGE_MARK) != 0;
}
-void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
+void BlenderFileLoader::insertShapeNode(Object *ob, Mesh *me, int id)
{
- ObjectRen *obr = obi->obr;
- char *name = obi->ob->id.name + 2;
+ char *name = ob->id.name + 2;
+
+ // Compute loop triangles
+ int tottri = poly_to_tri_count(me->totpoly, me->totloop);
+ MLoopTri *mlooptri = (MLoopTri*)MEM_malloc_arrayN(tottri, sizeof(*mlooptri), __func__);
+ BKE_mesh_recalc_looptri(
+ me->mloop, me->mpoly,
+ me->mvert,
+ me->totloop, me->totpoly,
+ mlooptri);
+
+ // Compute loop normals
+ BKE_mesh_calc_normals_split(me);
+ float (*lnors)[3] = NULL;
+
+ if (CustomData_has_layer(&me->ldata, CD_NORMAL)) {
+ lnors = (float(*)[3])CustomData_get_layer(&me->ldata, CD_NORMAL);
+ }
- // We parse vlak nodes and count the number of faces after the clipping by
- // the near and far view planes is applied (Note: mesh vertices are in the
- // camera coordinate system).
- VlakRen *vlr = NULL;
+ // Get other mesh data
+ MVert *mvert = me->mvert;
+ MLoop *mloop = me->mloop;
+ MPoly *mpoly = me->mpoly;
+ FreestyleEdge *fed = (FreestyleEdge*)CustomData_get_layer(&me->edata, CD_FREESTYLE_EDGE);
+ FreestyleFace *ffa = (FreestyleFace*)CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE);
+
+ // Compute matrix including camera transform
+ float obmat[4][4], nmat[4][4];
+ mul_m4_m4m4(obmat, _re->viewmat, ob->obmat);
+ invert_m4_m4(nmat, obmat);
+ transpose_m4(nmat);
+
+ // We count the number of triangles after the clipping by the near and far view
+ // planes is applied (Note: mesh vertices are in the camera coordinate system).
unsigned numFaces = 0;
- float v1[3], v2[3], v3[3], v4[3];
- float n1[3], n2[3], n3[3], n4[3], facenormal[3];
- int clip_1[3], clip_2[3];
- int wire_material = 0;
- for (int a = 0; a < obr->totvlak; a++) {
- if ((a & 255) == 0)
- vlr = obr->vlaknodes[a>>8].vlak;
- else
- vlr++;
- if (vlr->mat->mode & MA_ONLYCAST)
- continue;
- if (vlr->mat->material_type == MA_TYPE_WIRE) {
- wire_material = 1;
- continue;
- }
- copy_v3_v3(v1, vlr->v1->co);
- copy_v3_v3(v2, vlr->v2->co);
- copy_v3_v3(v3, vlr->v3->co);
- if (vlr->v4)
- copy_v3_v3(v4, vlr->v4->co);
- if (obi->flag & R_TRANSFORMED) {
- mul_m4_v3(obi->mat, v1);
- mul_m4_v3(obi->mat, v2);
- mul_m4_v3(obi->mat, v3);
- if (vlr->v4)
- mul_m4_v3(obi->mat, v4);
- }
+ float v1[3], v2[3], v3[3];
+ float n1[3], n2[3], n3[3], facenormal[3];
+ int clip[3];
+ for (int a = 0; a < tottri; a++) {
+ const MLoopTri *lt = &mlooptri[a];
+
+ copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co);
+ copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co);
+ copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co);
+
+ mul_m4_v3(obmat, v1);
+ mul_m4_v3(obmat, v2);
+ mul_m4_v3(obmat, v3);
+
v1[2] += _z_offset;
v2[2] += _z_offset;
v3[2] += _z_offset;
- if (vlr->v4)
- v4[2] += _z_offset;
-#if 0
- print_v3("v1", v1);
- print_v3("v2", v2);
- print_v3("v3", v3);
- if (vlr->v4)
- print_v3("v4", v4);
-#endif
- if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
- numFaces += countClippedFaces(v1, v2, v3, clip_1);
- if (vlr->v4)
- numFaces += countClippedFaces(v1, v3, v4, clip_2);
- }
- else {
- numFaces += countClippedFaces(v1, v2, v4, clip_1);
- numFaces += countClippedFaces(v2, v3, v4, clip_2);
- }
- }
- if (wire_material) {
- if (G.debug & G_DEBUG_FREESTYLE) {
- cout << "Warning: Object " << name << " has wire materials (ignored)" << endl;
- }
+
+ numFaces += countClippedFaces(v1, v2, v3, clip);
}
#if 0
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "numFaces " << numFaces << endl;
}
#endif
- if (numFaces == 0)
+ if (numFaces == 0) {
+ MEM_freeN(mlooptri);
return;
+ }
// We allocate memory for the meshes to be imported
NodeGroup *currentMesh = new NodeGroup;
@@ -496,107 +493,62 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
// We parse the vlak nodes again and import meshes while applying the clipping
// by the near and far view planes.
- int p;
- for (p = 0; p < obr->totvlak; ++p) { // we parse the faces of the mesh
- if ((p & 255) == 0)
- vlr = obr->vlaknodes[p>>8].vlak;
- else
- vlr++;
- if ((vlr->mat->mode & MA_ONLYCAST) || vlr->mat->material_type == MA_TYPE_WIRE)
- continue;
- copy_v3_v3(v1, vlr->v1->co);
- copy_v3_v3(v2, vlr->v2->co);
- copy_v3_v3(v3, vlr->v3->co);
- if (vlr->v4)
- copy_v3_v3(v4, vlr->v4->co);
- if (obi->flag & R_TRANSFORMED) {
- mul_m4_v3(obi->mat, v1);
- mul_m4_v3(obi->mat, v2);
- mul_m4_v3(obi->mat, v3);
- if (vlr->v4)
- mul_m4_v3(obi->mat, v4);
- }
+ for (int a = 0; a < tottri; a++) {
+ const MLoopTri *lt = &mlooptri[a];
+ const MPoly *mp = &mpoly[lt->poly];
+ Material *mat = give_current_material(ob, mp->mat_nr + 1);
+
+ copy_v3_v3(v1, mvert[mloop[lt->tri[0]].v].co);
+ copy_v3_v3(v2, mvert[mloop[lt->tri[1]].v].co);
+ copy_v3_v3(v3, mvert[mloop[lt->tri[2]].v].co);
+
+ mul_m4_v3(obmat, v1);
+ mul_m4_v3(obmat, v2);
+ mul_m4_v3(obmat, v3);
+
v1[2] += _z_offset;
v2[2] += _z_offset;
v3[2] += _z_offset;
- if (vlr->v4)
- v4[2] += _z_offset;
- if (_smooth && (vlr->flag & R_SMOOTH)) {
- copy_v3_v3(n1, vlr->v1->n);
- copy_v3_v3(n2, vlr->v2->n);
- copy_v3_v3(n3, vlr->v3->n);
- if (vlr->v4)
- copy_v3_v3(n4, vlr->v4->n);
- if (obi->flag & R_TRANSFORMED) {
- mul_m3_v3(obi->nmat, n1);
- mul_m3_v3(obi->nmat, n2);
- mul_m3_v3(obi->nmat, n3);
- normalize_v3(n1);
- normalize_v3(n2);
- normalize_v3(n3);
- if (vlr->v4) {
- mul_m3_v3(obi->nmat, n4);
- normalize_v3(n4);
- }
- }
+
+ if (_smooth && (mp->flag & ME_SMOOTH) && lnors) {
+ copy_v3_v3(n1, lnors[lt->tri[0]]);
+ copy_v3_v3(n2, lnors[lt->tri[1]]);
+ copy_v3_v3(n3, lnors[lt->tri[2]]);
+
+ mul_mat3_m4_v3(nmat, n1);
+ mul_mat3_m4_v3(nmat, n2);
+ mul_mat3_m4_v3(nmat, n3);
+
+ normalize_v3(n1);
+ normalize_v3(n2);
+ normalize_v3(n3);
}
else {
- RE_vlakren_get_normal(_re, obi, vlr, facenormal);
-#ifndef NDEBUG
- /* test if normals are inverted in rendering [T39669] */
- float tnor[3];
- if (vlr->v4)
- normal_quad_v3(tnor, v4, v3, v2, v1);
- else
- normal_tri_v3(tnor, v3, v2, v1);
- BLI_assert(dot_v3v3(tnor, facenormal) > 0.0f);
-#endif
+ normal_tri_v3(facenormal, v3, v2, v1);
+
copy_v3_v3(n1, facenormal);
copy_v3_v3(n2, facenormal);
copy_v3_v3(n3, facenormal);
- if (vlr->v4)
- copy_v3_v3(n4, facenormal);
}
- unsigned int numTris_1, numTris_2;
- bool edge_rotation;
- if (!vlr->v4 || !testEdgeRotation(v1, v2, v3, v4)) {
- numTris_1 = countClippedFaces(v1, v2, v3, clip_1);
- numTris_2 = (!vlr->v4) ? 0 : countClippedFaces(v1, v3, v4, clip_2);
- edge_rotation = false;
- }
- else {
- numTris_1 = countClippedFaces(v1, v2, v4, clip_1);
- numTris_2 = countClippedFaces(v2, v3, v4, clip_2);
- edge_rotation = true;
- if (G.debug & G_DEBUG_FREESTYLE) {
- printf("BlenderFileLoader::insertShapeNode: edge rotation is performed.\n");
- }
- }
- if (numTris_1 == 0 && numTris_2 == 0)
+ unsigned int numTris = countClippedFaces(v1, v2, v3, clip);
+ if (numTris == 0)
continue;
- bool fm, em1, em2, em3, em4;
- fm = (vlr->freestyle_face_mark) != 0;
- em1 = (vlr->freestyle_edge_mark & R_EDGE_V1V2) != 0;
- em2 = (vlr->freestyle_edge_mark & R_EDGE_V2V3) != 0;
- if (!vlr->v4) {
- em3 = (vlr->freestyle_edge_mark & R_EDGE_V3V1) != 0;
- em4 = false;
- }
- else {
- em3 = (vlr->freestyle_edge_mark & R_EDGE_V3V4) != 0;
- em4 = (vlr->freestyle_edge_mark & R_EDGE_V4V1) != 0;
+
+ bool fm = (ffa) ? (ffa[lt->poly].flag & FREESTYLE_FACE_MARK) != 0 : false;
+ bool em1 = false, em2 = false, em3 = false;
+
+ if (fed) {
+ em1 = testEdgeMark(me, fed, lt, 0);
+ em2 = testEdgeMark(me, fed, lt, 1);
+ em3 = testEdgeMark(me, fed, lt, 2);
}
- Material *mat = vlr->mat;
if (mat) {
tmpMat.setLine(mat->line_col[0], mat->line_col[1], mat->line_col[2], mat->line_col[3]);
tmpMat.setDiffuse(mat->r, mat->g, mat->b, mat->alpha);
- tmpMat.setSpecular(mat->specr, mat->specg, mat->specb, mat->spectra);
- float s = 1.0 * (mat->har + 1) / 4 ; // in Blender: [1;511] => in OpenGL: [0;128]
- if (s > 128.f)
- s = 128.f;
- tmpMat.setShininess(s);
+ tmpMat.setSpecular(mat->specr, mat->specg, mat->specb, 1.0f);
+ tmpMat.setShininess(128.f);
tmpMat.setPriority(mat->line_priority);
}
@@ -631,43 +583,19 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
float triCoords[5][3], triNormals[5][3];
bool edgeMarks[5]; // edgeMarks[i] is for the edge between i-th and (i+1)-th vertices
- if (numTris_1 > 0) {
- if (!edge_rotation) {
- clipTriangle(numTris_1, triCoords, v1, v2, v3, triNormals, n1, n2, n3,
- edgeMarks, em1, em2, (!vlr->v4) ? em3 : false, clip_1);
- }
- else {
- clipTriangle(numTris_1, triCoords, v1, v2, v4, triNormals, n1, n2, n4,
- edgeMarks, em1, false, em4, clip_1);
- }
- for (i = 0; i < numTris_1; i++) {
- addTriangle(&ls, triCoords[0], triCoords[i + 1], triCoords[i + 2],
- triNormals[0], triNormals[i + 1], triNormals[i + 2],
- fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i + 1],
- (i == numTris_1 - 1) ? edgeMarks[i + 2] : false);
- _numFacesRead++;
- }
- }
-
- if (numTris_2 > 0) {
- if (!edge_rotation) {
- clipTriangle(numTris_2, triCoords, v1, v3, v4, triNormals, n1, n3, n4,
- edgeMarks, false, em3, em4, clip_2);
- }
- else {
- clipTriangle(numTris_2, triCoords, v2, v3, v4, triNormals, n2, n3, n4,
- edgeMarks, em2, em3, false, clip_2);
- }
- for (i = 0; i < numTris_2; i++) {
- addTriangle(&ls, triCoords[0], triCoords[i + 1], triCoords[i + 2],
- triNormals[0], triNormals[i + 1], triNormals[i + 2],
- fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i + 1],
- (i == numTris_2 - 1) ? edgeMarks[i + 2] : false);
- _numFacesRead++;
- }
+ clipTriangle(numTris, triCoords, v1, v2, v3, triNormals, n1, n2, n3,
+ edgeMarks, em1, em2, em3, clip);
+ for (i = 0; i < numTris; i++) {
+ addTriangle(&ls, triCoords[0], triCoords[i + 1], triCoords[i + 2],
+ triNormals[0], triNormals[i + 1], triNormals[i + 2],
+ fm, (i == 0) ? edgeMarks[0] : false, edgeMarks[i + 1],
+ (i == numTris - 1) ? edgeMarks[i + 2] : false);
+ _numFacesRead++;
}
}
+ MEM_freeN(mlooptri);
+
// We might have several times the same vertex. We want a clean
// shape with no real-vertex. Here, we are making a cleaning pass.
float *cleanVertices = NULL;
@@ -806,8 +734,8 @@ void BlenderFileLoader::insertShapeNode(ObjectInstanceRen *obi, int id)
cleanNIndices, niSize, MIndices, viSize, 0, 0, 0);
// sets the id of the rep
rep->setId(Id(id, 0));
- rep->setName(obi->ob->id.name + 2);
- rep->setLibraryPath(obi->ob->id.lib ? obi->ob->id.lib->name : NULL);
+ rep->setName(ob->id.name + 2);
+ rep->setLibraryPath(ob->id.lib ? ob->id.lib->name : NULL);
const BBox<Vec3r> bbox = BBox<Vec3r>(Vec3r(ls.minBBox[0], ls.minBBox[1], ls.minBBox[2]),
Vec3r(ls.maxBBox[0], ls.maxBBox[1], ls.maxBBox[2]));
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
index 894f8eeeb4e..0542b7f45fd 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.h
@@ -40,19 +40,29 @@
#include "../system/RenderMonitor.h"
extern "C" {
+#include "MEM_guardedalloc.h"
+
#include "DNA_material_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_modifier_types.h"
+#include "DNA_object_types.h"
#include "DNA_scene_types.h"
-#include "renderdatabase.h"
#include "render_types.h"
+#include "BKE_customdata.h"
+#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_scene.h"
+#include "BLI_iterator.h"
+#include "BLI_listbase.h"
#include "BLI_math.h"
}
+#include "DEG_depsgraph_query.h"
+
#ifdef WITH_CXX_GUARDEDALLOC
#include "MEM_guardedalloc.h"
#endif
@@ -78,7 +88,7 @@ class BlenderFileLoader
{
public:
/*! Builds a MaxFileLoader */
- BlenderFileLoader(Render *re, SceneRenderLayer *srl);
+ BlenderFileLoader(Render *re, ViewLayer *view_layer);
virtual ~BlenderFileLoader();
/*! Loads the 3D scene and returns a pointer to the scene root node */
@@ -96,9 +106,8 @@ public:
inline void setRenderMonitor(RenderMonitor *iRenderMonitor) {_pRenderMonitor = iRenderMonitor;}
protected:
- void insertShapeNode(ObjectInstanceRen *obi, int id);
+ void insertShapeNode(Object *ob, Mesh *mesh, int id);
int testDegenerateTriangle(float v1[3], float v2[3], float v3[3]);
- bool testEdgeRotation(float v1[3], float v2[3], float v3[3], float v4[3]);
int countClippedFaces(float v1[3], float v2[3], float v3[3], int clip[3]);
void clipLine(float v1[3], float v2[3], float c[3], float z);
void clipTriangle(int numTris, float triCoords[][3], float v1[3], float v2[3], float v3[3],
@@ -114,7 +123,7 @@ protected:
unsigned n;
};
Render *_re;
- SceneRenderLayer *_srl;
+ ViewLayer *_view_layer;
NodeGroup *_Scene;
unsigned _numFacesRead;
#if 0
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
index 9c478c203e7..06f62f5a5dc 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.cpp
@@ -43,8 +43,9 @@ extern "C" {
#include "DNA_screen_types.h"
#include "DNA_scene_types.h"
+#include "BKE_collection.h"
#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
+#include "BKE_idprop.h"
#include "BKE_global.h"
#include "BKE_library.h" /* free_libblock */
#include "BKE_material.h"
@@ -59,6 +60,9 @@ extern "C" {
#include "BLI_math_vector.h"
#include "BLI_utildefines.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "RE_pipeline.h"
#include "render_types.h"
@@ -85,7 +89,7 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
freestyle_scene = BKE_scene_add(freestyle_bmain, name);
freestyle_scene->r.cfra = old_scene->r.cfra;
freestyle_scene->r.mode = old_scene->r.mode &
- ~(R_EDGE_FRS | R_SHADOW | R_SSS | R_PANORAMA | R_ENVMAP | R_MBLUR | R_BORDER);
+ ~(R_EDGE_FRS | R_PANORAMA | R_MBLUR | R_BORDER);
freestyle_scene->r.xsch = re->rectx; // old_scene->r.xsch
freestyle_scene->r.ysch = re->recty; // old_scene->r.ysch
freestyle_scene->r.xasp = 1.0f; // old_scene->r.xasp;
@@ -93,8 +97,6 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
freestyle_scene->r.tilex = old_scene->r.tilex;
freestyle_scene->r.tiley = old_scene->r.tiley;
freestyle_scene->r.size = 100; // old_scene->r.size
- //freestyle_scene->r.maximsize = old_scene->r.maximsize; /* DEPRECATED */
- freestyle_scene->r.ocres = old_scene->r.ocres;
freestyle_scene->r.color_mgt_flag = 0; // old_scene->r.color_mgt_flag;
freestyle_scene->r.scemode = old_scene->r.scemode & ~(R_SINGLE_LAYER | R_NO_FRAME_UPDATE | R_MULTIVIEW);
freestyle_scene->r.flag = old_scene->r.flag;
@@ -108,27 +110,39 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
freestyle_scene->r.safety.ymin = old_scene->r.safety.ymin;
freestyle_scene->r.safety.xmax = old_scene->r.safety.xmax;
freestyle_scene->r.safety.ymax = old_scene->r.safety.ymax;
- freestyle_scene->r.osa = old_scene->r.osa;
- freestyle_scene->r.filtertype = old_scene->r.filtertype;
- freestyle_scene->r.gauss = old_scene->r.gauss;
freestyle_scene->r.dither_intensity = old_scene->r.dither_intensity;
- BLI_strncpy(freestyle_scene->r.engine, old_scene->r.engine, sizeof(freestyle_scene->r.engine));
- freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA;
+ STRNCPY(freestyle_scene->r.engine, old_scene->r.engine);
+ if (G.debug & G_DEBUG_FREESTYLE) {
+ cout << "Stroke rendering engine : " << freestyle_scene->r.engine << endl;
+ }
+ freestyle_scene->r.im_format.planes = R_IMF_PLANES_RGBA;
freestyle_scene->r.im_format.imtype = R_IMF_IMTYPE_PNG;
+ // Copy ID properties, including Cycles render properties
+ if (old_scene->id.properties) {
+ freestyle_scene->id.properties = IDP_CopyProperty_ex(old_scene->id.properties, 0);
+ }
+
+ if (STREQ(freestyle_scene->r.engine, RE_engine_id_CYCLES)) {
+ /* Render with transparent background. */
+ PointerRNA freestyle_scene_ptr;
+ RNA_id_pointer_create(&freestyle_scene->id, &freestyle_scene_ptr);
+ PointerRNA freestyle_cycles_ptr = RNA_pointer_get(&freestyle_scene_ptr, "cycles");
+ RNA_boolean_set(&freestyle_cycles_ptr, "film_transparent", 1);
+ }
+
if (G.debug & G_DEBUG_FREESTYLE) {
printf("%s: %d thread(s)\n", __func__, BKE_render_num_threads(&freestyle_scene->r));
}
- // Render layer
- SceneRenderLayer *srl = (SceneRenderLayer *)freestyle_scene->r.layers.first;
- srl->layflag = SCE_LAY_SOLID | SCE_LAY_ZTRA;
-
BKE_scene_set_background(freestyle_bmain, freestyle_scene);
+ // Scene layer.
+ ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first;
+ view_layer->layflag = SCE_LAY_SOLID | SCE_LAY_ZTRA;
+
// Camera
- Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, OB_CAMERA, NULL);
- DAG_relations_tag_update(freestyle_bmain);
+ Object *object_camera = BKE_object_add(freestyle_bmain, freestyle_scene, view_layer, OB_CAMERA, NULL);
Camera *camera = (Camera *)object_camera->data;
camera->type = CAM_ORTHO;
@@ -148,14 +162,14 @@ BlenderStrokeRenderer::BlenderStrokeRenderer(Render *re, int render_count) : Str
// Reset serial mesh ID (used for BlenderStrokeRenderer::NewMesh())
_mesh_id = 0xffffffff;
- // Check if the rendering engine uses new shading nodes
- _use_shading_nodes = BKE_scene_use_new_shading_nodes(freestyle_scene);
-
// Create a bNodeTree-to-Material hash table
- if (_use_shading_nodes)
- _nodetree_hash = BLI_ghash_ptr_new("BlenderStrokeRenderer::_nodetree_hash");
- else
- _nodetree_hash = NULL;
+ _nodetree_hash = BLI_ghash_ptr_new("BlenderStrokeRenderer::_nodetree_hash");
+
+ // Depsgraph
+ freestyle_depsgraph = DEG_graph_new(freestyle_scene, view_layer, DAG_EVAL_RENDER);
+ DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &freestyle_scene->id, 0);
+ DEG_graph_id_tag_update(freestyle_bmain, freestyle_depsgraph, &object_camera->id, 0);
+ DEG_graph_tag_relations_update(freestyle_depsgraph);
}
BlenderStrokeRenderer::~BlenderStrokeRenderer()
@@ -166,7 +180,8 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer()
// compositor has finished.
// release objects and data blocks
- for (Base *b = (Base *)freestyle_scene->base.first; b; b = b->next) {
+ ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first;
+ for (Base *b = (Base *)view_layer->object_bases.first; b; b = b->next) {
Object *ob = b->object;
void *data = ob->data;
char *name = ob->id.name;
@@ -189,7 +204,14 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer()
cerr << "Warning: unexpected object in the scene: " << name[0] << name[1] << ":" << (name + 2) << endl;
}
}
- BLI_freelistN(&freestyle_scene->base);
+
+ // Make sure we don't have any bases which might reference freed objects.
+ FOREACH_SCENE_COLLECTION_BEGIN(freestyle_scene, sc)
+ {
+ BLI_freelistN(&sc->objects);
+ }
+ FOREACH_SCENE_COLLECTION_END;
+ BLI_freelistN(&view_layer->object_bases);
// release materials
Link *lnk = (Link *)freestyle_bmain->mat.first;
@@ -197,21 +219,13 @@ BlenderStrokeRenderer::~BlenderStrokeRenderer()
while (lnk)
{
Material *ma = (Material*)lnk;
- // We want to retain the linestyle mtexs, so let's detach them first
- for (int a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a]) {
- ma->mtex[a] = NULL;
- }
- else {
- break; // Textures are ordered, no empty slots between two textures
- }
- }
lnk = lnk->next;
BKE_libblock_free(freestyle_bmain, ma);
}
- if (_use_shading_nodes)
- BLI_ghash_free(_nodetree_hash, NULL, NULL);
+ BLI_ghash_free(_nodetree_hash, NULL, NULL);
+
+ DEG_graph_free(freestyle_depsgraph);
FreeStrokeGroups();
}
@@ -453,89 +467,13 @@ void BlenderStrokeRenderer::RenderStrokeRep(StrokeRep *iStrokeRep) const
void BlenderStrokeRenderer::RenderStrokeRepBasic(StrokeRep *iStrokeRep) const
{
- if (_use_shading_nodes) {
- bNodeTree *nt = iStrokeRep->getNodeTree();
- Material *ma = (Material *)BLI_ghash_lookup(_nodetree_hash, nt);
- if (!ma) {
- ma = BlenderStrokeRenderer::GetStrokeShader(freestyle_bmain, nt, false);
- BLI_ghash_insert(_nodetree_hash, nt, ma);
- }
-
- if (STREQ(freestyle_scene->r.engine, RE_engine_id_CYCLES)) {
- PointerRNA scene_ptr, freestyle_scene_ptr;
- RNA_pointer_create(NULL, &RNA_Scene, old_scene, &scene_ptr);
- RNA_pointer_create(NULL, &RNA_Scene, freestyle_scene, &freestyle_scene_ptr);
-
- PointerRNA cycles_ptr = RNA_pointer_get(&scene_ptr, "cycles");
- PointerRNA freestyle_cycles_ptr = RNA_pointer_get(&freestyle_scene_ptr, "cycles");
-
- int flag;
- RNA_STRUCT_BEGIN(&freestyle_cycles_ptr, prop)
- {
- flag = RNA_property_flag(prop);
- if (flag & PROP_HIDDEN)
- continue;
- RNA_property_copy(&freestyle_cycles_ptr, &cycles_ptr, prop, -1);
- }
- RNA_STRUCT_END;
-
- RNA_boolean_set(&freestyle_cycles_ptr, "film_transparent", 1);
- }
-
- iStrokeRep->setMaterial(ma);
- }
- else {
- bool has_mat = false;
- int a = 0;
-
- // Look for a good existing material
- for (Link *lnk = (Link *)freestyle_bmain->mat.first; lnk; lnk = lnk->next) {
- Material *ma = (Material*)lnk;
- bool texs_are_good = true;
- // as soon as textures differ it's not the right one
- for (int a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a] != iStrokeRep->getMTex(a)) {
- texs_are_good = false;
- break;
- }
- }
-
- if (texs_are_good) {
- iStrokeRep->setMaterial(ma);
- has_mat = true;
- break; // if textures are good, no need to search anymore
- }
- }
-
- // If still no material, create one
- if (!has_mat) {
- Material *ma = BKE_material_add(freestyle_bmain, "stroke_material");
- DAG_relations_tag_update(freestyle_bmain);
- ma->mode |= MA_VERTEXCOLP;
- ma->mode |= MA_TRANSP;
- ma->mode |= MA_SHLESS;
- ma->vcol_alpha = 1;
-
- id_us_min(&ma->id);
-
- // Textures
- while (iStrokeRep->getMTex(a)) {
- ma->mtex[a] = (MTex *)iStrokeRep->getMTex(a);
-
- // We'll generate both with tips and without tips
- // coordinates, on two different UV layers.
- if (ma->mtex[a]->texflag & MTEX_TIPS) {
- BLI_strncpy(ma->mtex[a]->uvname, uvNames[1], sizeof(ma->mtex[a]->uvname));
- }
- else {
- BLI_strncpy(ma->mtex[a]->uvname, uvNames[0], sizeof(ma->mtex[a]->uvname));
- }
- a++;
- }
-
- iStrokeRep->setMaterial(ma);
- }
+ bNodeTree *nt = iStrokeRep->getNodeTree();
+ Material *ma = (Material *)BLI_ghash_lookup(_nodetree_hash, nt);
+ if (!ma) {
+ ma = BlenderStrokeRenderer::GetStrokeShader(freestyle_bmain, nt, false);
+ BLI_ghash_insert(_nodetree_hash, nt, ma);
}
+ iStrokeRep->setMaterial(ma);
const vector<Strip*>& strips = iStrokeRep->getStrips();
const bool hasTex = iStrokeRep->hasTex();
@@ -674,8 +612,8 @@ int BlenderStrokeRenderer::get_stroke_count() const
void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
{
#if 0
- Object *object_mesh = BKE_object_add(freestyle_bmain, freestyle_scene, OB_MESH);
- DAG_relations_tag_update(freestyle_bmain);
+ Object *object_mesh = BKE_object_add(freestyle_bmain, freestyle_scene, (ViewLayer *)freestyle_scene->view_layers.first, OB_MESH);
+ DEG_relations_tag_update(freestyle_bmain);
#else
Object *object_mesh = NewMesh();
#endif
@@ -700,17 +638,13 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
if (hasTex) {
// First UV layer
- CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, uvNames[0]);
CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[0]);
- CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 0);
CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 0);
BKE_mesh_update_customdata_pointers(mesh, true);
loopsuv[0] = mesh->mloopuv;
// Second UV layer
- CustomData_add_layer_named(&mesh->pdata, CD_MTEXPOLY, CD_CALLOC, NULL, mesh->totpoly, uvNames[1]);
CustomData_add_layer_named(&mesh->ldata, CD_MLOOPUV, CD_CALLOC, NULL, mesh->totloop, uvNames[1]);
- CustomData_set_layer_active(&mesh->pdata, CD_MTEXPOLY, 1);
CustomData_set_layer_active(&mesh->ldata, CD_MLOOPUV, 1);
BKE_mesh_update_customdata_pointers(mesh, true);
loopsuv[1] = mesh->mloopuv;
@@ -922,7 +856,6 @@ void BlenderStrokeRenderer::GenerateStrokeMesh(StrokeGroup *group, bool hasTex)
Object *BlenderStrokeRenderer::NewMesh() const
{
Object *ob;
- Base *base;
char name[MAX_ID_NAME];
unsigned int mesh_id = get_stroke_mesh_id();
@@ -932,16 +865,14 @@ Object *BlenderStrokeRenderer::NewMesh() const
ob->data = BKE_mesh_add(freestyle_bmain, name);
ob->lay = 1;
- base = BKE_scene_base_add(freestyle_scene, ob);
- DAG_relations_tag_update(freestyle_bmain);
-#if 0
- BKE_scene_base_deselect_all(scene);
- BKE_scene_base_select(scene, base);
-#else
- (void)base;
-#endif
+ SceneCollection *sc_master = BKE_collection_master(&freestyle_scene->id);
+ BKE_collection_object_add(&freestyle_scene->id, sc_master, ob);
+ DEG_graph_tag_relations_update(freestyle_depsgraph);
- DAG_id_tag_update_ex(freestyle_bmain, &ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_graph_id_tag_update(freestyle_bmain,
+ freestyle_depsgraph,
+ &ob->id,
+ OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
return ob;
}
@@ -958,6 +889,8 @@ Render *BlenderStrokeRenderer::RenderScene(Render * /*re*/, bool render)
#endif
Render *freestyle_render = RE_NewSceneRender(freestyle_scene);
+ ViewLayer *view_layer = (ViewLayer *)freestyle_scene->view_layers.first;
+ DEG_graph_relations_update(freestyle_depsgraph, freestyle_bmain, freestyle_scene, view_layer);
RE_RenderFreestyleStrokes(freestyle_render, freestyle_bmain, freestyle_scene,
render && get_stroke_count() > 0);
diff --git a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
index ec53efa14cd..c7204293839 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
+++ b/source/blender/freestyle/intern/blender_interface/BlenderStrokeRenderer.h
@@ -29,6 +29,7 @@
#include "../system/FreestyleConfig.h"
extern "C" {
+struct Depsgraph;
struct GHash;
struct Main;
struct Material;
@@ -76,6 +77,7 @@ protected:
Main *freestyle_bmain;
Scene *old_scene;
Scene *freestyle_scene;
+ Depsgraph *freestyle_depsgraph;
bContext *_context;
float _width, _height;
float _z, _z_delta;
diff --git a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
index ea22633c50e..75687edd9f6 100644
--- a/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
+++ b/source/blender/freestyle/intern/blender_interface/FRS_freestyle.cpp
@@ -58,12 +58,12 @@ extern "C" {
#include "BLI_blenlib.h"
#include "BLI_math.h"
+#include "BLI_math_color_blend.h"
#include "BLI_callbacks.h"
#include "BPY_extern.h"
#include "renderpipeline.h"
-#include "pixelblending.h"
#include "FRS_freestyle.h"
@@ -283,19 +283,19 @@ static bool test_edge_type_conditions(struct edge_type_condition *conditions,
return true;
}
-static void prepare(Render *re, SceneRenderLayer *srl)
+static void prepare(Render *re, ViewLayer *view_layer)
{
// load mesh
re->i.infostr = IFACE_("Freestyle: Mesh loading");
re->stats_draw(re->sdh, &re->i);
re->i.infostr = NULL;
- if (controller->LoadMesh(re, srl)) // returns if scene cannot be loaded or if empty
+ if (controller->LoadMesh(re, view_layer)) // returns if scene cannot be loaded or if empty
return;
if (re->test_break(re->tbh))
return;
// add style modules
- FreestyleConfig *config = &srl->freestyleConfig;
+ FreestyleConfig *config = &view_layer->freestyle_config;
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "\n=== Rendering options ===" << endl;
@@ -359,7 +359,7 @@ static void prepare(Render *re, SceneRenderLayer *srl)
cout << " " << layer_count+1 << ": " << lineset->name << " - " <<
(lineset->linestyle ? (lineset->linestyle->id.name + 2) : "<NULL>") << endl;
}
- char *buffer = create_lineset_handler(srl->name, lineset->name);
+ char *buffer = create_lineset_handler(view_layer->name, lineset->name);
controller->InsertStyleModule(layer_count, lineset->name, buffer);
controller->toggleLayer(layer_count, true);
MEM_freeN(buffer);
@@ -445,7 +445,7 @@ static void prepare(Render *re, SceneRenderLayer *srl)
}
// set diffuse and z depth passes
- RenderLayer *rl = RE_GetRenderLayer(re->result, srl->name);
+ RenderLayer *rl = RE_GetRenderLayer(re->result, view_layer->name);
bool diffuse = false, z = false;
for (RenderPass *rpass = (RenderPass *)rl->passes.first; rpass; rpass = rpass->next) {
if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE)) {
@@ -473,7 +473,7 @@ static void prepare(Render *re, SceneRenderLayer *srl)
controller->ComputeViewMap();
}
-void FRS_composite_result(Render *re, SceneRenderLayer *srl, Render *freestyle_render)
+void FRS_composite_result(Render *re, ViewLayer *view_layer, Render *freestyle_render)
{
RenderLayer *rl;
float *src, *dest, *pixSrc, *pixDest;
@@ -503,7 +503,7 @@ void FRS_composite_result(Render *re, SceneRenderLayer *srl, Render *freestyle_r
}
#endif
- rl = RE_GetRenderLayer(re->result, srl->name);
+ rl = RE_GetRenderLayer(re->result, view_layer->name);
if (!rl) {
if (G.debug & G_DEBUG_FREESTYLE) {
cout << "No destination render layer to composite to" << endl;
@@ -530,19 +530,19 @@ void FRS_composite_result(Render *re, SceneRenderLayer *srl, Render *freestyle_r
pixSrc = src + 4 * (rectx * y + x);
if (pixSrc[3] > 0.0) {
pixDest = dest + 4 * (rectx * y + x);
- addAlphaOverFloat(pixDest, pixSrc);
+ blend_color_mix_float(pixDest, pixDest, pixSrc);
}
}
}
}
-static int displayed_layer_count(SceneRenderLayer *srl)
+static int displayed_layer_count(ViewLayer *view_layer)
{
int count = 0;
- switch (srl->freestyleConfig.mode) {
+ switch (view_layer->freestyle_config.mode) {
case FREESTYLE_CONTROL_SCRIPT_MODE:
- for (FreestyleModuleConfig *module = (FreestyleModuleConfig *)srl->freestyleConfig.modules.first;
+ for (FreestyleModuleConfig *module = (FreestyleModuleConfig *)view_layer->freestyle_config.modules.first;
module;
module = module->next)
{
@@ -551,7 +551,7 @@ static int displayed_layer_count(SceneRenderLayer *srl)
}
break;
case FREESTYLE_CONTROL_EDITOR_MODE:
- for (FreestyleLineSet *lineset = (FreestyleLineSet *)srl->freestyleConfig.linesets.first;
+ for (FreestyleLineSet *lineset = (FreestyleLineSet *)view_layer->freestyle_config.linesets.first;
lineset;
lineset = lineset->next)
{
@@ -563,9 +563,11 @@ static int displayed_layer_count(SceneRenderLayer *srl)
return count;
}
-int FRS_is_freestyle_enabled(SceneRenderLayer *srl)
+int FRS_is_freestyle_enabled(ViewLayer *view_layer)
{
- return (!(srl->layflag & SCE_LAY_DISABLE) && srl->layflag & SCE_LAY_FRS && displayed_layer_count(srl) > 0);
+ return ((view_layer->flag & VIEW_LAYER_RENDER) &&
+ (view_layer->flag & VIEW_LAYER_FREESTYLE) &&
+ displayed_layer_count(view_layer) > 0);
}
void FRS_init_stroke_renderer(Render *re)
@@ -587,7 +589,7 @@ void FRS_begin_stroke_rendering(Render *re)
init_camera(re);
}
-Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render)
+Render *FRS_do_stroke_rendering(Render *re, ViewLayer *view_layer, int render)
{
Render *freestyle_render = NULL;
@@ -596,12 +598,12 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render)
RenderMonitor monitor(re);
controller->setRenderMonitor(&monitor);
- controller->setViewMapCache((srl->freestyleConfig.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false);
+ controller->setViewMapCache((view_layer->freestyle_config.flags & FREESTYLE_VIEW_MAP_CACHE) ? true : false);
if (G.debug & G_DEBUG_FREESTYLE) {
cout << endl;
cout << "----------------------------------------------------------" << endl;
- cout << "| " << (re->scene->id.name + 2) << "|" << srl->name << endl;
+ cout << "| " << (re->scene->id.name + 2) << "|" << view_layer->name << endl;
cout << "----------------------------------------------------------" << endl;
}
@@ -610,7 +612,7 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render)
// - add style modules
// - set parameters
// - compute view map
- prepare(re, srl);
+ prepare(re, view_layer);
if (re->test_break(re->tbh)) {
controller->CloseFile();
@@ -635,7 +637,7 @@ Render *FRS_do_stroke_rendering(Render *re, SceneRenderLayer *srl, int render)
// composite result
if (freestyle_render) {
- FRS_composite_result(re, srl, freestyle_render);
+ FRS_composite_result(re, view_layer, freestyle_render);
RE_FreeRenderResult(freestyle_render->result);
freestyle_render->result = NULL;
}
diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp
index 9c462bb6b2b..6f5491fc8ef 100644
--- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp
+++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.cpp
@@ -51,7 +51,6 @@ IndexedFaceSet::IndexedFaceSet() : Rep()
_MISize = 0;
_TIndices = NULL;
_TISize = 0;
- _displayList = 0;
}
IndexedFaceSet::IndexedFaceSet(float *iVertices, unsigned iVSize, float *iNormals, unsigned iNSize,
@@ -150,8 +149,6 @@ IndexedFaceSet::IndexedFaceSet(float *iVertices, unsigned iVSize, float *iNormal
_TISize = iTISize;
_TIndices = iTIndices;
}
-
- _displayList = 0;
}
IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet& iBrother) : Rep(iBrother)
@@ -215,8 +212,6 @@ IndexedFaceSet::IndexedFaceSet(const IndexedFaceSet& iBrother) : Rep(iBrother)
_TIndices = new unsigned[_TISize];
memcpy(_TIndices, iBrother.tindices(), _TISize * sizeof(unsigned));
}
-
- _displayList = 0;
}
IndexedFaceSet::~IndexedFaceSet()
@@ -276,10 +271,6 @@ IndexedFaceSet::~IndexedFaceSet()
delete[] _TIndices;
_TIndices = NULL;
}
-
- // should find a way to deallocates the displayList
- // glDeleteLists(GLuint list, GLSizei range)
- _displayList = 0;
}
void IndexedFaceSet::accept(SceneVisitor& v)
diff --git a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h
index 8d7bf986bde..16dea6f907e 100644
--- a/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h
+++ b/source/blender/freestyle/intern/scene_graph/IndexedFaceSet.h
@@ -150,8 +150,6 @@ public:
std::swap(_MISize, ioOther._MISize);
std::swap(_TISize, ioOther._TISize);
- std::swap(_displayList, ioOther._displayList);
-
Rep::swap(ioOther);
}
@@ -173,12 +171,6 @@ public:
/*! Compute the Bounding Box */
virtual void ComputeBBox();
- /*! modifiers */
- inline void setDisplayList(unsigned int index)
- {
- _displayList = index;
- }
-
/*! Accessors */
virtual const float *vertices() const
{
@@ -280,11 +272,6 @@ public:
return _TISize;
}
- inline unsigned int displayList() const
- {
- return _displayList;
- }
-
protected:
float *_Vertices;
float *_Normals;
@@ -311,8 +298,6 @@ protected:
unsigned _MISize;
unsigned _TISize;
- unsigned int _displayList;
-
#ifdef WITH_CXX_GUARDEDALLOC
MEM_CXX_CLASS_ALLOC_FUNCS("Freestyle:IndexedFaceSet")
#endif
diff --git a/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp
deleted file mode 100644
index 24c56ff4e28..00000000000
--- a/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.cpp
- * \ingroup freestyle
- * \brief Class to represent a scene render layer in Blender.
- */
-
-#include "NodeSceneRenderLayer.h"
-
-namespace Freestyle {
-
-void NodeSceneRenderLayer::accept(SceneVisitor& v)
-{
- v.visitNodeSceneRenderLayer(*this);
-}
-
-} /* namespace Freestyle */
diff --git a/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h b/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h
deleted file mode 100644
index 8dc93d84201..00000000000
--- a/source/blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __FREESTYLE_NODE_SCENE_RENDER_LAYER_H__
-#define __FREESTYLE_NODE_SCENE_RENDER_LAYER_H__
-
-/** \file blender/freestyle/intern/scene_graph/NodeSceneRenderLayer.h
- * \ingroup freestyle
- * \brief Class to represent a scene render layer in Blender.
- */
-
-#include "Node.h"
-
-extern "C" {
-#include "DNA_scene_types.h" /* for Scene and SceneRenderLayer */
-}
-
-using namespace std;
-
-namespace Freestyle {
-
-class NodeSceneRenderLayer : public Node
-{
-public:
- inline NodeSceneRenderLayer(Scene& scene, SceneRenderLayer& srl) : Node(), _Scene(scene), _SceneRenderLayer(srl) {}
- virtual ~NodeSceneRenderLayer() {}
-
- inline struct Scene& scene() const
- {
- return _Scene;
- }
-
- inline struct SceneRenderLayer& sceneRenderLayer() const
- {
- return _SceneRenderLayer;
- }
-
- /*! Accept the corresponding visitor */
- virtual void accept(SceneVisitor& v);
-
-protected:
-
- Scene& _Scene;
- SceneRenderLayer& _SceneRenderLayer;
-};
-
-} /* namespace Freestyle */
-
-#endif // __FREESTYLE_NODE_SCENE_RENDER_LAYER_H__
diff --git a/source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp
new file mode 100644
index 00000000000..701c5caa91d
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.cpp
@@ -0,0 +1,35 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/freestyle/intern/scene_graph/NodeViewLayer.cpp
+ * \ingroup freestyle
+ * \brief Class to represent a scene render layer in Blender.
+ */
+
+#include "NodeViewLayer.h"
+
+namespace Freestyle {
+
+void NodeViewLayer::accept(SceneVisitor& v)
+{
+ v.visitNodeViewLayer(*this);
+}
+
+} /* namespace Freestyle */
diff --git a/source/blender/freestyle/intern/scene_graph/NodeViewLayer.h b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.h
new file mode 100644
index 00000000000..cc64fda60b6
--- /dev/null
+++ b/source/blender/freestyle/intern/scene_graph/NodeViewLayer.h
@@ -0,0 +1,66 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __FREESTYLE_NODE_VIEW_LAYER_H__
+#define __FREESTYLE_NODE_VIEW_LAYER_H__
+
+/** \file blender/freestyle/intern/scene_graph/NodeViewLayer.h
+ * \ingroup freestyle
+ * \brief Class to represent a view layer in Blender.
+ */
+
+#include "Node.h"
+
+extern "C" {
+#include "DNA_scene_types.h" /* for Scene and ViewLayer */
+}
+
+using namespace std;
+
+namespace Freestyle {
+
+class NodeViewLayer : public Node
+{
+public:
+ inline NodeViewLayer(Scene& scene, ViewLayer& view_layer) : Node(), _Scene(scene), _ViewLayer(view_layer) {}
+ virtual ~NodeViewLayer() {}
+
+ inline struct Scene& scene() const
+ {
+ return _Scene;
+ }
+
+ inline struct ViewLayer& sceneLayer() const
+ {
+ return _ViewLayer;
+ }
+
+ /*! Accept the corresponding visitor */
+ virtual void accept(SceneVisitor& v);
+
+protected:
+
+ Scene& _Scene;
+ ViewLayer& _ViewLayer;
+};
+
+} /* namespace Freestyle */
+
+#endif // __FREESTYLE_NODE_VIEW_LAYER_H__
diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
index 2af02ab5764..16c353678c1 100644
--- a/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
+++ b/source/blender/freestyle/intern/scene_graph/SceneHash.cpp
@@ -35,14 +35,14 @@ string SceneHash::toString()
return ss.str();
}
-void SceneHash::visitNodeSceneRenderLayer(NodeSceneRenderLayer& node)
+void SceneHash::visitNodeViewLayer(NodeViewLayer& node)
{
struct RenderData *r = &node.scene().r;
adler32((unsigned char *)&r->xsch, sizeof(r->xsch)); // resolution_x
adler32((unsigned char *)&r->ysch, sizeof(r->ysch)); // resolution_y
adler32((unsigned char *)&r->size, sizeof(r->size)); // resolution_percentage
- struct FreestyleConfig *config = &node.sceneRenderLayer().freestyleConfig;
+ struct FreestyleConfig *config = &node.sceneLayer().freestyle_config;
adler32((unsigned char *)&config->flags, sizeof(config->flags));
adler32((unsigned char *)&config->crease_angle, sizeof(config->crease_angle));
adler32((unsigned char *)&config->sphere_radius, sizeof(config->sphere_radius));
diff --git a/source/blender/freestyle/intern/scene_graph/SceneHash.h b/source/blender/freestyle/intern/scene_graph/SceneHash.h
index 9da711673f0..662b4bba8f1 100644
--- a/source/blender/freestyle/intern/scene_graph/SceneHash.h
+++ b/source/blender/freestyle/intern/scene_graph/SceneHash.h
@@ -26,7 +26,7 @@
*/
#include "IndexedFaceSet.h"
-#include "NodeSceneRenderLayer.h"
+#include "NodeViewLayer.h"
#include "NodeCamera.h"
#include "SceneVisitor.h"
@@ -49,7 +49,7 @@ public:
virtual ~SceneHash() {}
VISIT_DECL(NodeCamera)
- VISIT_DECL(NodeSceneRenderLayer)
+ VISIT_DECL(NodeViewLayer)
VISIT_DECL(IndexedFaceSet)
string toString();
diff --git a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h
index 712585c4064..d76e48980bf 100644
--- a/source/blender/freestyle/intern/scene_graph/SceneVisitor.h
+++ b/source/blender/freestyle/intern/scene_graph/SceneVisitor.h
@@ -56,7 +56,7 @@ class NodeLight;
class NodeCamera;
class NodeDrawingStyle;
class NodeTransform;
-class NodeSceneRenderLayer;
+class NodeViewLayer;
class Rep;
class LineRep;
@@ -88,7 +88,7 @@ public:
VISIT_COMPLETE_DEF(NodeCamera)
VISIT_COMPLETE_DEF(NodeDrawingStyle)
VISIT_COMPLETE_DEF(NodeTransform)
- VISIT_COMPLETE_DEF(NodeSceneRenderLayer)
+ VISIT_COMPLETE_DEF(NodeViewLayer)
VISIT_COMPLETE_DEF(Rep)
VISIT_COMPLETE_DEF(LineRep)
diff --git a/source/blender/freestyle/intern/stroke/Stroke.h b/source/blender/freestyle/intern/stroke/Stroke.h
index db96a27e073..c004d73e6fe 100644
--- a/source/blender/freestyle/intern/stroke/Stroke.h
+++ b/source/blender/freestyle/intern/stroke/Stroke.h
@@ -44,8 +44,7 @@
#endif
extern "C" {
-#include "DNA_material_types.h"
-
+struct MTex;
struct bNodeTree;
}
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 885ff2ff159..481133ba984 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -31,6 +31,9 @@ set(INC
../imbuf
../makesdna
../makesrna
+ ../draw
+
+ ../editors/include
# For node muting stuff...
../nodes
@@ -39,6 +42,7 @@ set(INC
../../../intern/glew-mx
../../../intern/guardedalloc
../../../intern/smoke/extern
+ ../../../intern/gawain
)
set(INC_SYS
@@ -47,20 +51,26 @@ set(INC_SYS
set(SRC
intern/gpu_basic_shader.c
+ intern/gpu_batch.c
+ intern/gpu_batch_presets.c
intern/gpu_buffers.c
intern/gpu_codegen.c
- intern/gpu_compositing.c
intern/gpu_debug.c
intern/gpu_draw.c
intern/gpu_extensions.c
intern/gpu_framebuffer.c
+ intern/gpu_immediate.c
+ intern/gpu_immediate_util.c
intern/gpu_init_exit.c
intern/gpu_material.c
+ intern/gpu_matrix.c
intern/gpu_select.c
intern/gpu_select_pick.c
intern/gpu_select_sample_query.c
intern/gpu_shader.c
intern/gpu_texture.c
+ intern/gpu_uniformbuffer.c
+ intern/gpu_viewport.c
shaders/gpu_shader_fx_lib.glsl
shaders/gpu_shader_fx_ssao_frag.glsl
@@ -69,7 +79,6 @@ set(SRC
shaders/gpu_shader_fx_dof_hq_frag.glsl
shaders/gpu_shader_fx_dof_hq_vert.glsl
shaders/gpu_shader_fx_dof_hq_geo.glsl
- shaders/gpu_shader_fx_vert.glsl
shaders/gpu_shader_material.glsl
shaders/gpu_shader_sep_gaussian_blur_frag.glsl
shaders/gpu_shader_sep_gaussian_blur_vert.glsl
@@ -85,23 +94,128 @@ set(SRC
shaders/gpu_shader_smoke_vert.glsl
GPU_basic_shader.h
+ GPU_batch.h
GPU_buffers.h
- GPU_compositing.h
GPU_debug.h
GPU_draw.h
GPU_extensions.h
GPU_framebuffer.h
GPU_glew.h
+ GPU_immediate.h
+ GPU_immediate_util.h
GPU_init_exit.h
+ GPU_legacy_stubs.h
GPU_material.h
+ GPU_matrix.h
GPU_select.h
GPU_shader.h
GPU_texture.h
+ GPU_uniformbuffer.h
+ GPU_viewport.h
+
intern/gpu_codegen.h
intern/gpu_private.h
intern/gpu_select_private.h
+ intern/gpu_shader_private.h
)
+data_to_c_simple(shaders/gpu_shader_depth_only_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_uniform_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_checker_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_diag_stripes_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_simple_lighting_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_flat_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_flat_id_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_widget_base_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_widget_base_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_widget_shadow_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_widget_shadow_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_nodelink_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_nodelink_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_flat_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_line_dashed_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_line_dashed_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_smooth_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_smooth_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_image_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_image_rect_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_image_multi_rect_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_desaturate_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_linear_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_shuffle_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_mask_uniform_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_modulate_alpha_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_alpha_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_varying_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_depth_linear_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_depth_copy_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_interlace_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_image_multisample_resolve_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_image_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_normal_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_flat_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_smooth_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_normal_smooth_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_smooth_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_passthrough_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl SRC)
+
+data_to_c_simple(shaders/gpu_shader_instance_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_screen_aligned_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_camera_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_distance_line_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_edges_variying_color_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_instance_edges_variying_color_vert.glsl SRC)
+
+data_to_c_simple(shaders/gpu_shader_3D_groundline_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_groundpoint_vert.glsl SRC)
+
+data_to_c_simple(shaders/gpu_shader_point_uniform_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_point_uniform_color_aa_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_point_varying_color_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_point_varying_size_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl SRC)
+
+data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_edges_front_back_ortho_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_edges_overlay_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_edges_overlay_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_edges_overlay_simple_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_edges_overlay_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_text_simple_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_text_simple_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_text_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_text_geom.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_text_frag.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_keyframe_diamond_vert.glsl SRC)
+data_to_c_simple(shaders/gpu_shader_keyframe_diamond_frag.glsl SRC)
+
data_to_c_simple(shaders/gpu_shader_geometry.glsl SRC)
data_to_c_simple(shaders/gpu_shader_fire_frag.glsl SRC)
data_to_c_simple(shaders/gpu_shader_smoke_frag.glsl SRC)
@@ -116,19 +230,6 @@ data_to_c_simple(shaders/gpu_shader_vertex.glsl SRC)
data_to_c_simple(shaders/gpu_shader_vertex_world.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)
-data_to_c_simple(shaders/gpu_shader_fx_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_ssao_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_dof_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_dof_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_dof_hq_frag.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_dof_hq_vert.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_dof_hq_geo.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_depth_resolve.glsl SRC)
-data_to_c_simple(shaders/gpu_shader_fx_lib.glsl SRC)
-
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-endif()
if(WITH_MOD_SMOKE)
add_definitions(-DWITH_SMOKE)
diff --git a/source/blender/gpu/GPU_basic_shader.h b/source/blender/gpu/GPU_basic_shader.h
index d9bf3d1ced3..dc378927e79 100644
--- a/source/blender/gpu/GPU_basic_shader.h
+++ b/source/blender/gpu/GPU_basic_shader.h
@@ -64,12 +64,6 @@ typedef enum GPUBasicShaderStipple {
GPU_SHADER_STIPPLE_HEXAGON = 3,
GPU_SHADER_STIPPLE_DIAG_STRIPES = 4,
GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP = 5,
- GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW = 6,
- GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW_SWAP = 7,
- GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN = 8,
- GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN_SWAP = 9,
- GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER = 10,
- GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER_SWAP = 11
} GPUBasicShaderStipple;
void GPU_basic_shaders_init(void);
@@ -132,9 +126,6 @@ void GPU_basic_shader_stipple(GPUBasicShaderStipple stipple_id);
void GPU_basic_shader_line_stipple(GLint stipple_factor, GLushort stipple_pattern);
void GPU_basic_shader_line_width(float line_width);
-bool GPU_basic_shader_use_glsl_get(void);
-void GPU_basic_shader_use_glsl_set(bool enabled);
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/gpu/GPU_batch.h b/source/blender/gpu/GPU_batch.h
new file mode 100644
index 00000000000..b706bdbf189
--- /dev/null
+++ b/source/blender/gpu/GPU_batch.h
@@ -0,0 +1,74 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/* Batched geometry rendering is powered by the Gawain library.
+ * This file contains any additions or modifications specific to Blender.
+ */
+
+#ifndef __GPU_BATCH_H__
+#define __GPU_BATCH_H__
+
+#include "../../../intern/gawain/gawain/gwn_batch.h"
+#include "../../../intern/gawain/gawain/gwn_batch_private.h"
+
+struct rctf;
+
+// TODO: CMake magic to do this:
+// #include "gawain/batch.h"
+
+#include "BLI_compiler_attrs.h"
+#include "BLI_sys_types.h"
+
+#include "GPU_shader.h"
+
+/* Extend GWN_batch_program_set to use Blender’s library of built-in shader programs. */
+
+/* gpu_batch.c */
+void GWN_batch_program_set_builtin(Gwn_Batch *batch, GPUBuiltinShader shader_id) ATTR_NONNULL(1);
+
+Gwn_Batch *GPU_batch_tris_from_poly_2d_encoded(
+ const uchar *polys_flat, uint polys_flat_len, const struct rctf *rect
+ ) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+Gwn_Batch *GPU_batch_wire_from_poly_2d_encoded(
+ const uchar *polys_flat, uint polys_flat_len, const struct rctf *rect
+ ) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1);
+
+void gpu_batch_init(void);
+void gpu_batch_exit(void);
+
+/* gpu_batch_presets.c */
+/* Only use by draw manager. Use the presets function instead for interface. */
+Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res) ATTR_WARN_UNUSED_RESULT;
+/* Replacement for gluSphere */
+Gwn_Batch *GPU_batch_preset_sphere(int lod) ATTR_WARN_UNUSED_RESULT;
+Gwn_Batch *GPU_batch_preset_sphere_wire(int lod) ATTR_WARN_UNUSED_RESULT;
+
+void gpu_batch_presets_init(void);
+void gpu_batch_presets_register(Gwn_Batch *preset_batch);
+void gpu_batch_presets_reset(void);
+void gpu_batch_presets_exit(void);
+
+#endif /* __GPU_BATCH_H__ */
diff --git a/source/blender/gpu/GPU_buffers.h b/source/blender/gpu/GPU_buffers.h
index 6ffaa29ead6..f496c92f283 100644
--- a/source/blender/gpu/GPU_buffers.h
+++ b/source/blender/gpu/GPU_buffers.h
@@ -32,191 +32,19 @@
#ifndef __GPU_BUFFERS_H__
#define __GPU_BUFFERS_H__
-#ifdef DEBUG
-/* #define DEBUG_VBO(X) printf(X)*/
-# define DEBUG_VBO(X)
-#else
-# define DEBUG_VBO(X)
-#endif
-
#include <stddef.h>
struct BMesh;
struct CCGElem;
struct CCGKey;
struct DMFlagMat;
-struct DerivedMesh;
-struct GSet;
-struct GPUVertPointLink;
-struct GPUDrawObject;
struct GridCommonGPUBuffer;
-struct PBVH;
+struct GSet;
+struct MLoop;
+struct MLoopTri;
+struct MPoly;
struct MVert;
-
-typedef struct GPUBuffer {
- size_t size; /* in bytes */
- unsigned int id; /* used with vertex buffer objects */
-} GPUBuffer;
-
-typedef struct GPUBufferMaterial {
- /* range of points used for this material */
- unsigned int start;
- unsigned int totelements;
- unsigned int totloops;
- unsigned int *polys; /* array of polygons for this material */
- unsigned int totpolys; /* total polygons in polys */
- unsigned int totvisiblepolys; /* total visible polygons */
-
- /* original material index */
- short mat_nr;
-} GPUBufferMaterial;
-
-void GPU_buffer_material_finalize(struct GPUDrawObject *gdo, GPUBufferMaterial *matinfo, int totmat);
-
-/* meshes are split up by material since changing materials requires
- * GL state changes that can't occur in the middle of drawing an
- * array.
- *
- * some simplifying assumptions are made:
- * - all quads are treated as two triangles.
- * - no vertex sharing is used; each triangle gets its own copy of the
- * vertices it uses (this makes it easy to deal with a vertex used
- * by faces with different properties, such as smooth/solid shading,
- * different MCols, etc.)
- *
- * to avoid confusion between the original MVert vertices and the
- * arrays of OpenGL vertices, the latter are referred to here and in
- * the source as `points'. similarly, the OpenGL triangles generated
- * for MFaces are referred to as triangles rather than faces.
- */
-typedef struct GPUDrawObject {
- GPUBuffer *points;
- GPUBuffer *normals;
- GPUBuffer *uv;
- GPUBuffer *uv_tex;
- GPUBuffer *colors;
- GPUBuffer *edges;
- GPUBuffer *uvedges;
- GPUBuffer *triangles; /* triangle index buffer */
-
- /* for each original vertex, the list of related points */
- struct GPUVertPointLink *vert_points;
-
- /* see: USE_GPU_POINT_LINK define */
-#if 0
- /* storage for the vert_points lists */
- struct GPUVertPointLink *vert_points_mem;
- int vert_points_usage;
-#endif
-
- int colType;
-
- GPUBufferMaterial *materials;
- int totmaterial;
-
- unsigned int tot_triangle_point;
- unsigned int tot_loose_point;
- /* different than total loops since ngons get tesselated still */
- unsigned int tot_loop_verts;
-
- /* caches of the original DerivedMesh values */
- unsigned int totvert;
- unsigned int totedge;
-
- unsigned int loose_edge_offset;
- unsigned int tot_loose_edge_drawn;
- unsigned int tot_edge_drawn;
-
- /* for subsurf, offset where drawing of interior edges starts */
- unsigned int interior_offset;
- unsigned int totinterior;
-} GPUDrawObject;
-
-/* currently unused */
-// #define USE_GPU_POINT_LINK
-
-typedef struct GPUVertPointLink {
-#ifdef USE_GPU_POINT_LINK
- struct GPUVertPointLink *next;
-#endif
- /* -1 means uninitialized */
- int point_index;
-} GPUVertPointLink;
-
-
-
-/* used for GLSL materials */
-typedef struct GPUAttrib {
- int index;
- int info_index;
- int size;
- int type;
-} GPUAttrib;
-
-void GPU_global_buffer_pool_free(void);
-void GPU_global_buffer_pool_free_unused(void);
-
-GPUBuffer *GPU_buffer_alloc(size_t size);
-void GPU_buffer_free(GPUBuffer *buffer);
-
-void GPU_drawobject_free(struct DerivedMesh *dm);
-
-/* flag that controls data type to fill buffer with, a modifier will prepare. */
-typedef enum {
- GPU_BUFFER_VERTEX = 0,
- GPU_BUFFER_NORMAL,
- GPU_BUFFER_COLOR,
- GPU_BUFFER_UV,
- GPU_BUFFER_UV_TEXPAINT,
- GPU_BUFFER_EDGE,
- GPU_BUFFER_UVEDGE,
- GPU_BUFFER_TRIANGLES
-} GPUBufferType;
-
-typedef enum {
- GPU_BINDING_ARRAY = 0,
- GPU_BINDING_INDEX = 1,
-} GPUBindingType;
-
-typedef enum {
- GPU_ATTR_INFO_SRGB = (1 << 0),
-} GPUAttrInfo;
-
-/* called before drawing */
-void GPU_vertex_setup(struct DerivedMesh *dm);
-void GPU_normal_setup(struct DerivedMesh *dm);
-void GPU_uv_setup(struct DerivedMesh *dm);
-void GPU_texpaint_uv_setup(struct DerivedMesh *dm);
-/* colType is the cddata MCol type to use! */
-void GPU_color_setup(struct DerivedMesh *dm, int colType);
-void GPU_buffer_bind_as_color(GPUBuffer *buffer);
-void GPU_edge_setup(struct DerivedMesh *dm); /* does not mix with other data */
-void GPU_uvedge_setup(struct DerivedMesh *dm);
-
-void GPU_triangle_setup(struct DerivedMesh *dm);
-
-int GPU_attrib_element_size(GPUAttrib data[], int numdata);
-void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numdata, int element_size);
-
-void GPU_buffer_bind(GPUBuffer *buffer, GPUBindingType binding);
-void GPU_buffer_unbind(GPUBuffer *buffer, GPUBindingType binding);
-
-/* can't lock more than one buffer at once */
-void *GPU_buffer_lock(GPUBuffer *buffer, GPUBindingType binding);
-void *GPU_buffer_lock_stream(GPUBuffer *buffer, GPUBindingType binding);
-void GPU_buffer_unlock(GPUBuffer *buffer, GPUBindingType binding);
-
-/* switch color rendering on=1/off=0 */
-void GPU_color_switch(int mode);
-
-/* used for drawing edges */
-void GPU_buffer_draw_elements(GPUBuffer *elements, unsigned int mode, int start, int count);
-
-/* called after drawing */
-void GPU_buffers_unbind(void);
-
-/* only unbind interleaved data */
-void GPU_interleaved_attrib_unbind(void);
+struct PBVH;
/* Buffers for non-DerivedMesh drawing */
typedef struct GPU_PBVH_Buffers GPU_PBVH_Buffers;
@@ -263,14 +91,10 @@ void GPU_pbvh_grid_buffers_update(
const int update_flags);
/* draw */
-void GPU_pbvh_buffers_draw(
- GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
- bool wireframe, bool fast);
+struct Gwn_Batch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast);
-/* debug PBVH draw*/
-void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf);
-void GPU_pbvh_BB_draw_init(void);
-void GPU_pbvh_BB_draw_end(void);
+/* debug PBVH draw */
+void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf, unsigned int pos);
bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, struct GSet *bm_faces, bool show_diffuse_color);
bool GPU_pbvh_buffers_mask_changed(GPU_PBVH_Buffers *buffers, bool show_mask);
@@ -278,4 +102,6 @@ bool GPU_pbvh_buffers_mask_changed(GPU_PBVH_Buffers *buffers, bool show_mask);
void GPU_pbvh_buffers_free(GPU_PBVH_Buffers *buffers);
void GPU_pbvh_multires_buffers_free(struct GridCommonGPUBuffer **grid_common_gpu_buffer);
+void GPU_pbvh_fix_linking(void);
+
#endif
diff --git a/source/blender/gpu/GPU_compositing.h b/source/blender/gpu/GPU_compositing.h
deleted file mode 100644
index d506d91a9aa..00000000000
--- a/source/blender/gpu/GPU_compositing.h
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2005 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Antony Riakiotakis.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPU_compositing.h
- * \ingroup gpu
- */
-
-#ifndef __GPU_COMPOSITING_H__
-#define __GPU_COMPOSITING_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* opaque handle for framebuffer compositing effects (defined in gpu_compositing.c )*/
-typedef struct GPUFX GPUFX;
-struct GPUDOFSettings;
-struct GPUSSAOSettings;
-struct GPUOffScreen;
-struct GPUFXSettings;
-struct rcti;
-struct Scene;
-struct GPUShader;
-enum eGPUFXFlags;
-
-/**** Public API *****/
-
-typedef enum GPUFXShaderEffect {
- /* Screen space ambient occlusion shader */
- GPU_SHADER_FX_SSAO = 1,
-
- /* depth of field passes. Yep, quite a complex effect */
- GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE = 2,
- GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_TWO = 3,
- GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE = 4,
- GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR = 5,
- GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FIVE = 6,
-
- /* high quality */
- GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_ONE = 7,
- GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_TWO = 8,
- GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_THREE = 9,
-
- GPU_SHADER_FX_DEPTH_RESOLVE = 10,
-} GPUFXShaderEffect;
-
-/* keep in synch with enum above! */
-#define MAX_FX_SHADERS 11
-
-/* generate a new FX compositor */
-GPUFX *GPU_fx_compositor_create(void);
-
-/* destroy a text compositor */
-void GPU_fx_compositor_destroy(GPUFX *fx);
-
-/* initialize a framebuffer with size taken from the viewport */
-bool GPU_fx_compositor_initialize_passes(
- GPUFX *fx, const struct rcti *rect, const struct rcti *scissor_rect,
- const struct GPUFXSettings *fx_settings);
-
-/* do compositing on the fx passes that have been initialized */
-bool GPU_fx_do_composite_pass(
- GPUFX *fx, float projmat[4][4], bool is_persp,
- struct Scene *scene, struct GPUOffScreen *ofs);
-
-/* bind new depth buffer for XRay pass */
-void GPU_fx_compositor_setup_XRay_pass(GPUFX *fx, bool do_xray);
-
-/* resolve a final depth buffer by compositing the XRay and normal depth buffers */
-void GPU_fx_compositor_XRay_resolve(GPUFX *fx);
-
-void GPU_fx_compositor_init_dof_settings(struct GPUDOFSettings *dof);
-void GPU_fx_compositor_init_ssao_settings(struct GPUSSAOSettings *ssao);
-
-
-/* initialize and cache the shader unform interface for effects */
-void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect effect);
-#ifdef __cplusplus
-}
-#endif
-
-#endif // __GPU_COMPOSITING_H__
diff --git a/source/blender/gpu/GPU_debug.h b/source/blender/gpu/GPU_debug.h
index 61b2bc591ce..c7a99d33654 100644
--- a/source/blender/gpu/GPU_debug.h
+++ b/source/blender/gpu/GPU_debug.h
@@ -41,24 +41,6 @@ extern "C" {
/* prints something if debug mode is active only */
void GPU_print_error_debug(const char *str);
-/* replacement for gluErrorString */
-const char *gpuErrorString(GLenum err);
-
-/* prints current OpenGL state */
-void GPU_state_print(void);
-
-void GPU_assert_no_gl_errors(const char *file, int line, const char *str);
-
-# define GPU_ASSERT_NO_GL_ERRORS(str) GPU_assert_no_gl_errors(__FILE__, __LINE__, (str))
-
-# define GPU_CHECK_ERRORS_AROUND(glProcCall) \
- ( \
- GPU_ASSERT_NO_GL_ERRORS("Pre: " #glProcCall), \
- (glProcCall), \
- GPU_ASSERT_NO_GL_ERRORS("Post: " #glProcCall) \
- )
-
-
/* inserts a debug marker message for the debug context messaging system */
void GPU_string_marker(const char *str);
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h
index 90b65af87c8..e26d973142b 100644
--- a/source/blender/gpu/GPU_draw.h
+++ b/source/blender/gpu/GPU_draw.h
@@ -39,76 +39,31 @@ extern "C" {
struct ImBuf;
struct Image;
struct ImageUser;
-struct MTexPoly;
struct Object;
struct Scene;
+struct ViewLayer;
struct View3D;
struct RegionView3D;
struct SmokeModifierData;
struct DupliObject;
-/* OpenGL drawing functions related to shading. These are also
- * shared with the game engine, where there were previously
- * duplicates of some of these functions. */
+#include "DNA_object_enums.h"
+
+/* OpenGL drawing functions related to shading. */
/* Initialize
* - sets the default Blender opengl state, if in doubt, check
* the contents of this function
- * - this is called when starting Blender, for opengl rendering,
- * and for switching back from the game engine for example. */
+ * - this is called when starting Blender, for opengl rendering. */
void GPU_state_init(void);
-/* Material drawing
- * - first the state is initialized by a particular object and
- * it's materials
- * - after this, materials can be quickly enabled by their number,
- * GPU_object_material_bind returns 0 if drawing should be skipped
- * - after drawing, the material must be disabled again */
-
-void GPU_begin_object_materials(struct View3D *v3d, struct RegionView3D *rv3d,
- struct Scene *scene, struct Object *ob, bool glsl, bool *do_alpha_after);
-void GPU_end_object_materials(void);
-bool GPU_object_materials_check(void);
-
-int GPU_object_material_bind(int nr, void *attribs);
-void GPU_object_material_unbind(void);
-int GPU_object_material_visible(int nr, void *attribs);
-
-void GPU_begin_dupli_object(struct DupliObject *dob);
-void GPU_end_dupli_object(void);
-
-void GPU_material_diffuse_get(int nr, float diff[4]);
-bool GPU_material_use_matcaps_get(void);
-
-void GPU_set_material_alpha_blend(int alphablend);
-int GPU_get_material_alpha_blend(void);
-
-/* TexFace drawing
- * - this is mutually exclusive with material drawing, a mesh should
- * be drawn using one or the other
- * - passing NULL clears the state again */
-
-int GPU_set_tpage(struct MTexPoly *mtexpoly, int mipmap, int transp);
-void GPU_clear_tpage(bool force);
+/* Programmable point size
+ * - shaders set their own point size when enabled
+ * - use glPointSize when disabled */
-/* Lights
- * - returns how many lights were enabled
- * - this affects fixed functions materials and texface, not glsl */
-
-int GPU_default_lights(void);
-int GPU_scene_object_lights(
- struct Scene *scene, struct Object *ob,
- int lay, float viewmat[4][4], int ortho);
-
-/* Text render
- * - based on moving uv coordinates */
-
-void GPU_render_text(
- struct MTexPoly *mtexpoly, int mode,
- const char *textstr, int textlen, unsigned int *col,
- const float *v_quad[4], const float *uv_quad[4],
- int glattrib);
+void GPU_enable_program_point_size(void);
+void GPU_disable_program_point_size(void);
/* Mipmap settings
* - these will free textures on changes */
@@ -131,11 +86,9 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap);
* - these deal with images bound as opengl textures */
void GPU_paint_update_image(struct Image *ima, struct ImageUser *iuser, int x, int y, int w, int h);
-void GPU_update_images_framechange(void);
-int GPU_update_image_time(struct Image *ima, double time);
int GPU_verify_image(
struct Image *ima, struct ImageUser *iuser,
- int textarget, int tftile, bool compare, bool mipmap, bool is_data);
+ int textarget, bool compare, bool mipmap, bool is_data);
void GPU_create_gl_tex(
unsigned int *bind, unsigned int *rect, float *frect, int rectw, int recth,
int textarget, bool mipmap, bool use_hight_bit_depth, struct Image *ima);
@@ -155,17 +108,23 @@ void GPU_create_smoke(struct SmokeModifierData *smd, int highres);
/* Delayed free of OpenGL buffers by main thread */
void GPU_free_unused_buffers(void);
-#ifdef WITH_OPENSUBDIV
-struct DerivedMesh;
-void GPU_draw_update_fvar_offset(struct DerivedMesh *dm);
-#endif
-
/* utilities */
void GPU_select_index_set(int index);
void GPU_select_index_get(int index, int *r_col);
int GPU_select_to_index(unsigned int col);
void GPU_select_to_index_array(unsigned int *col, const unsigned int size);
+typedef enum eGPUAttribMask {
+ GPU_DEPTH_BUFFER_BIT = (1 << 0),
+ GPU_ENABLE_BIT = (1 << 1),
+ GPU_SCISSOR_BIT = (1 << 2),
+ GPU_VIEWPORT_BIT = (1 << 3),
+ GPU_BLEND_BIT = (1 << 4),
+} eGPUAttribMask;
+
+void gpuPushAttrib(eGPUAttribMask mask);
+void gpuPopAttrib(void);
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/gpu/GPU_extensions.h b/source/blender/gpu/GPU_extensions.h
index 31ad8243c4b..d36b0ea15be 100644
--- a/source/blender/gpu/GPU_extensions.h
+++ b/source/blender/gpu/GPU_extensions.h
@@ -38,21 +38,16 @@ extern "C" {
/* GPU extensions support */
-void GPU_extensions_disable(void);
-
-bool GPU_legacy_support(void);
bool GPU_full_non_power_of_two_support(void);
-bool GPU_display_list_support(void);
bool GPU_bicubic_bump_support(void);
-bool GPU_geometry_shader_support(void);
-bool GPU_geometry_shader_support_via_extension(void);
-bool GPU_instanced_drawing_support(void);
int GPU_max_texture_size(void);
int GPU_max_textures(void);
float GPU_max_texture_anisotropy(void);
int GPU_max_color_texture_samples(void);
int GPU_max_cube_map_size(void);
+int GPU_max_ubo_binds(void);
+int GPU_max_ubo_size(void);
int GPU_color_depth(void);
void GPU_get_dfdy_factors(float fac[2]);
diff --git a/source/blender/gpu/GPU_framebuffer.h b/source/blender/gpu/GPU_framebuffer.h
index 2719b8fa6a8..61dd899f3d9 100644
--- a/source/blender/gpu/GPU_framebuffer.h
+++ b/source/blender/gpu/GPU_framebuffer.h
@@ -36,48 +36,163 @@
extern "C" {
#endif
+struct GPUTexture;
+
+typedef struct GPUAttachment {
+ struct GPUTexture *tex;
+ int mip, layer;
+} GPUAttachment;
+
+typedef enum GPUFrameBufferBits {
+ GPU_COLOR_BIT = (1 << 0),
+ GPU_DEPTH_BIT = (1 << 1),
+ GPU_STENCIL_BIT = (1 << 2),
+} GPUFrameBufferBits;
+
typedef struct GPUFrameBuffer GPUFrameBuffer;
typedef struct GPUOffScreen GPUOffScreen;
-struct GPUTexture;
/* GPU Framebuffer
* - this is a wrapper for an OpenGL framebuffer object (FBO). in practice
* multiple FBO's may be created, to get around limitations on the number
* of attached textures and the dimension requirements.
- * - after any of the GPU_framebuffer_* functions, GPU_framebuffer_restore must
- * be called before rendering to the window framebuffer again */
-
-void GPU_texture_bind_as_framebuffer(struct GPUTexture *tex);
+ * - actual FBO creation & config is deferred until GPU_framebuffer_bind or
+ * GPU_framebuffer_check_valid to allow creation & config while another
+ * opengl context is bound (since FBOs are not shared between ogl contexts).
+ */
GPUFrameBuffer *GPU_framebuffer_create(void);
-int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, char err_out[256]);
-void GPU_framebuffer_texture_detach(struct GPUTexture *tex);
-void GPU_framebuffer_slots_bind(GPUFrameBuffer *fb, int slot);
-void GPU_framebuffer_texture_unbind(GPUFrameBuffer *fb, struct GPUTexture *tex);
void GPU_framebuffer_free(GPUFrameBuffer *fb);
+void GPU_framebuffer_bind(GPUFrameBuffer *fb);
+void GPU_framebuffer_restore(void);
+
+bool GPU_framebuffer_bound(GPUFrameBuffer *fb);
bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256]);
-void GPU_framebuffer_bind_no_save(GPUFrameBuffer *fb, int slot);
+/* internal use only */
+unsigned int GPU_framebuffer_current_get(void);
-bool GPU_framebuffer_bound(GPUFrameBuffer *fb);
+#define GPU_FRAMEBUFFER_FREE_SAFE(fb) do { \
+ if (fb != NULL) { \
+ GPU_framebuffer_free(fb); \
+ fb = NULL; \
+ } \
+} while (0)
-void GPU_framebuffer_restore(void);
-void GPU_framebuffer_blur(
- GPUFrameBuffer *fb, struct GPUTexture *tex,
- GPUFrameBuffer *blurfb, struct GPUTexture *blurtex);
+/* Framebuffer setup : You need to call GPU_framebuffer_bind for theses
+ * to be effective. */
+
+void GPU_framebuffer_texture_attach(
+ GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int mip);
+void GPU_framebuffer_texture_layer_attach(
+ GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int layer, int mip);
+void GPU_framebuffer_texture_cubeface_attach(
+ GPUFrameBuffer *fb, struct GPUTexture *tex, int slot, int face, int mip);
+void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, struct GPUTexture *tex);
+void GPU_framebuffer_texture_detach_slot(
+ GPUFrameBuffer *fb, struct GPUTexture *tex, int type);
+
+/**
+ * How to use GPU_framebuffer_ensure_config().
+ *
+ * Example :
+ * GPU_framebuffer_ensure_config(&fb, {
+ * GPU_ATTACHMENT_TEXTURE(depth), // must be depth buffer
+ * GPU_ATTACHMENT_TEXTURE(tex1),
+ * GPU_ATTACHMENT_TEXTURE_CUBEFACE(tex2, 0),
+ * GPU_ATTACHMENT_TEXTURE_LAYER_MIP(tex2, 0, 0)
+ * })
+ *
+ * Note : Unspecified attachements (i.e: those beyond the last
+ * GPU_ATTACHMENT_* in GPU_framebuffer_ensure_config list)
+ * are left unchanged.
+ * Note : Make sure that the dimensions of your textures matches
+ * otherwise you will have an invalid framebuffer error.
+ **/
+#define GPU_framebuffer_ensure_config(_fb, ...) do { \
+ if (*(_fb) == NULL) { \
+ *(_fb) = GPU_framebuffer_create(); \
+ } \
+ GPUAttachment config[] = __VA_ARGS__; \
+ GPU_framebuffer_config_array(*(_fb), config, (sizeof(config) / sizeof(GPUAttachment))); \
+} while (0)
+
+void GPU_framebuffer_config_array(GPUFrameBuffer *fb, const GPUAttachment *config, int config_ct);
+
+#define GPU_ATTACHMENT_NONE \
+ {.tex = NULL, .layer = -1, .mip = 0}
+#define GPU_ATTACHMENT_LEAVE \
+ {.tex = NULL, .layer = -1, .mip = -1}
+#define GPU_ATTACHMENT_TEXTURE(_tex) \
+ {.tex = _tex, .layer = -1, .mip = 0}
+#define GPU_ATTACHMENT_TEXTURE_MIP(_tex, _mip) \
+ {.tex = _tex, .layer = -1, .mip = _mip}
+#define GPU_ATTACHMENT_TEXTURE_LAYER(_tex, _layer) \
+ {.tex = _tex, .layer = _layer, .mip = 0}
+#define GPU_ATTACHMENT_TEXTURE_LAYER_MIP(_tex, _layer, _mip) \
+ {.tex = _tex, .layer = _layer, .mip = _mip}
+#define GPU_ATTACHMENT_TEXTURE_CUBEFACE(_tex, _face) \
+ {.tex = _tex, .layer = _face, .mip = 0}
+#define GPU_ATTACHMENT_TEXTURE_CUBEFACE_MIP(_tex, _face, _mip) \
+ {.tex = _tex, .layer = _face, .mip = _mip}
+
+/* Framebuffer operations */
+
+void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h);
+
+void GPU_framebuffer_clear(
+ GPUFrameBuffer *fb, GPUFrameBufferBits buffers,
+ const float clear_col[4], float clear_depth, unsigned int clear_stencil);
+
+#define GPU_framebuffer_clear_color(fb, col) \
+ GPU_framebuffer_clear(fb, GPU_COLOR_BIT, col, 0.0f, 0x00)
+
+#define GPU_framebuffer_clear_depth(fb, depth) \
+ GPU_framebuffer_clear(fb, GPU_DEPTH_BIT, NULL, depth, 0x00)
+
+#define GPU_framebuffer_clear_color_depth(fb, col, depth) \
+ GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT, col, depth, 0x00)
+
+#define GPU_framebuffer_clear_stencil(fb, stencil) \
+ GPU_framebuffer_clear(fb, GPU_STENCIL_BIT, NULL, 0.0f, stencil)
+
+#define GPU_framebuffer_clear_depth_stencil(fb, depth, stencil) \
+ GPU_framebuffer_clear(fb, GPU_DEPTH_BIT | GPU_STENCIL_BIT, NULL, depth, stencil)
+
+#define GPU_framebuffer_clear_color_depth_stencil(fb, col, depth, stencil) \
+ GPU_framebuffer_clear(fb, GPU_COLOR_BIT | GPU_DEPTH_BIT | GPU_STENCIL_BIT, col, depth, stencil)
+
+void GPU_framebuffer_read_depth(GPUFrameBuffer *fb, int x, int y, int w, int h, float *data);
+void GPU_framebuffer_read_color(
+ GPUFrameBuffer *fb, int x, int y, int w, int h, int channels, int slot, float *data);
+
+void GPU_framebuffer_blit(
+ GPUFrameBuffer *fb_read, int read_slot,
+ GPUFrameBuffer *fb_write, int write_slot,
+ GPUFrameBufferBits blit_buffers);
+
+void GPU_framebuffer_recursive_downsample(
+ GPUFrameBuffer *fb, int max_lvl,
+ void (*callback)(void *userData, int level), void *userData);
/* GPU OffScreen
* - wrapper around framebuffer and texture for simple offscreen drawing
- * - changes size if graphics card can't support it */
+ */
-GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, char err_out[256]);
+GPUOffScreen *GPU_offscreen_create(int width, int height, int samples,
+ bool depth, bool high_bitdepth, char err_out[256]);
void GPU_offscreen_free(GPUOffScreen *ofs);
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save);
void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore);
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels);
+void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y);
int GPU_offscreen_width(const GPUOffScreen *ofs);
int GPU_offscreen_height(const GPUOffScreen *ofs);
-int GPU_offscreen_color_texture(const GPUOffScreen *ofs);
+struct GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *ofs);
+
+void GPU_offscreen_viewport_data_get(
+ GPUOffScreen *ofs,
+ GPUFrameBuffer **r_fb, struct GPUTexture **r_color, struct GPUTexture **r_depth);
#ifdef __cplusplus
}
diff --git a/source/blender/gpu/GPU_glew.h b/source/blender/gpu/GPU_glew.h
index 94217863fd6..afe1c9763ad 100644
--- a/source/blender/gpu/GPU_glew.h
+++ b/source/blender/gpu/GPU_glew.h
@@ -34,4 +34,8 @@
#include "glew-mx.h"
+#ifndef WITH_LEGACY_OPENGL
+#include "GPU_legacy_stubs.h"
+#endif
+
#endif /* __GPU_GLEW_H__ */
diff --git a/source/blender/gpu/GPU_immediate.h b/source/blender/gpu/GPU_immediate.h
new file mode 100644
index 00000000000..2a2692e6baf
--- /dev/null
+++ b/source/blender/gpu/GPU_immediate.h
@@ -0,0 +1,58 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ *
+ * Contributor(s): Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/* Immediate mode rendering is powered by the Gawain library.
+ * This file contains any additions or modifications specific to Blender.
+ */
+
+#ifndef __GPU_IMMEDIATE_H__
+#define __GPU_IMMEDIATE_H__
+
+#include "../../../intern/gawain/gawain/gwn_immediate.h"
+#include "../../../intern/gawain/gawain/gwn_imm_util.h"
+
+// TODO: CMake magic to do this:
+// #include "gawain/gwn_immediate.h"
+// #include "gawain/gwn_imm_util.h"
+
+#include "GPU_shader.h"
+
+/* Extend immBindProgram to use Blender’s library of built-in shader programs.
+ * Use immUnbindProgram() when done. */
+void immBindBuiltinProgram(GPUBuiltinShader shader_id);
+
+/*
+ * Extend immUniformColor to take Blender's themes
+ */
+void immUniformThemeColor(int color_id);
+void immUniformThemeColor3(int color_id);
+void immUniformThemeColorShade(int color_id, int offset);
+void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset);
+void immUniformThemeColorBlendShade(int color_id1, int color_id2, float fac, int offset);
+void immUniformThemeColorBlend(int color_id1, int color_id2, float fac);
+void immThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset);
+
+#endif /* __GPU_IMMEDIATE_H__ */
diff --git a/source/blender/gpu/GPU_immediate_util.h b/source/blender/gpu/GPU_immediate_util.h
new file mode 100644
index 00000000000..c31d477ff5b
--- /dev/null
+++ b/source/blender/gpu/GPU_immediate_util.h
@@ -0,0 +1,64 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file GPU_immediate_util.h
+ * \ingroup gpu
+ *
+ * Utility drawing functions (rough equivalent to OpenGL's GLU)
+ */
+
+#ifndef __GPU_IMMEDIATE_UTIL_H__
+#define __GPU_IMMEDIATE_UTIL_H__
+
+void imm_cpack(uint x);
+
+void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments);
+void imm_draw_circle_fill_2d(uint shdr_pos, float x, float y, float radius, int nsegments);
+
+void imm_draw_circle_wire_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments);
+void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float radius_x, float radius_y, int nsegments);
+
+/* use this version when Gwn_VertFormat has a vec3 position */
+void imm_draw_circle_wire_3d(uint pos, float x, float y, float radius, int nsegments);
+void imm_draw_circle_fill_3d(uint pos, float x, float y, float radius, int nsegments);
+
+void imm_draw_disk_partial_fill_2d(
+ uint pos, float x, float y,
+ float radius_inner, float radius_outer, int nsegments, float start, float sweep);
+
+void imm_draw_box_wire_2d(uint pos, float x1, float y1, float x2, float y2);
+void imm_draw_box_wire_3d(uint pos, float x1, float y1, float x2, float y2);
+
+void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2);
+
+void imm_draw_cube_fill_3d(uint pos, const float co[3], const float aspect[3]);
+void imm_draw_cube_wire_3d(uint pos, const float co[3], const float aspect[3]);
+
+void imm_draw_cylinder_fill_normal_3d(
+ uint pos, uint nor, float base, float top, float height,
+ int slices, int stacks);
+void imm_draw_cylinder_wire_3d(
+ uint pos, float base, float top, float height,
+ int slices, int stacks);
+void imm_draw_cylinder_fill_3d(
+ uint pos, float base, float top, float height,
+ int slices, int stacks);
+
+#endif /* __GPU_IMMEDIATE_UTIL_H__ */
diff --git a/source/blender/gpu/GPU_legacy_stubs.h b/source/blender/gpu/GPU_legacy_stubs.h
new file mode 100644
index 00000000000..a195eac9eec
--- /dev/null
+++ b/source/blender/gpu/GPU_legacy_stubs.h
@@ -0,0 +1,457 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2017 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Blender Foundation, Dalai Felinto.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file GPU_legacy_stubs.h
+ * \ingroup gpu
+ *
+ * This is to mark the transition to OpenGL core profile
+ * The idea is to allow Blender 2.8 to be built with OpenGL 3.3 even if it means breaking things
+ *
+ * This file should be removed in the future
+ */
+
+#ifndef __GPU_LEGACY_STUBS_H__
+#define __GPU_LEGACY_STUBS_H__
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic push
+# pragma GCC diagnostic ignored "-Wunused-parameter"
+# pragma GCC diagnostic ignored "-Wunused-function"
+#endif
+
+#include <stdlib.h> /* for abort(). */
+
+#include "BLI_utildefines.h"
+
+/**
+ * Empty function, use for breakpoint when a depreacated
+ * OpenGL function is called.
+ */
+static void gl_deprecated(void)
+{
+ BLI_assert(true);
+}
+
+#define _GL_BOOL BLI_INLINE GLboolean
+#define _GL_BOOL_RET { \
+ gl_deprecated(); \
+ return false; \
+}
+
+#define _GL_ENUM BLI_INLINE GLenum
+#define _GL_ENUM_RET { \
+ gl_deprecated(); \
+ return 0; \
+}
+
+#define _GL_INT BLI_INLINE GLint
+#define _GL_INT_RET { \
+ gl_deprecated(); \
+ return 0; \
+}
+
+
+#define _GL_UINT BLI_INLINE GLuint
+#define _GL_UINT_RET { \
+ gl_deprecated(); \
+ return 0; \
+}
+
+#define _GL_VOID BLI_INLINE void
+#define _GL_VOID_RET { \
+ gl_deprecated(); \
+}
+
+static bool disable_enable_check(GLenum cap)
+{
+ const bool is_deprecated = \
+ ELEM(
+ cap,
+ GL_ALPHA_TEST,
+ GL_LINE_STIPPLE,
+ GL_POINT_SPRITE,
+ GL_TEXTURE_1D,
+ GL_TEXTURE_2D,
+ GL_TEXTURE_GEN_S,
+ GL_TEXTURE_GEN_T,
+ -1
+ );
+
+ if (is_deprecated) {
+ gl_deprecated();
+ }
+
+ return is_deprecated;
+}
+
+_GL_VOID USE_CAREFULLY_glDisable (GLenum cap)
+{
+ if (!disable_enable_check(cap)) {
+ glDisable(cap);
+ }
+}
+#define glDisable USE_CAREFULLY_glDisable
+
+_GL_VOID USE_CAREFULLY_glEnable (GLenum cap)
+{
+ if (!disable_enable_check(cap)) {
+ glEnable(cap);
+ }
+}
+#define glEnable USE_CAREFULLY_glEnable
+
+/**
+ * Hand written cases
+ */
+
+_GL_VOID DO_NOT_USE_glClientActiveTexture (GLenum texture) _GL_VOID_RET
+
+
+/**
+ * List automatically generated from `gl-deprecated.h` and `glew.h`
+ */
+
+/**
+ * ENUM values
+ */
+#define DO_NOT_USE_GL_CURRENT_FOG_COORDINATE 0
+#define DO_NOT_USE_GL_FOG_COORDINATE 0
+#define DO_NOT_USE_GL_FOG_COORDINATE_ARRAY 0
+#define DO_NOT_USE_GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING 0
+#define DO_NOT_USE_GL_FOG_COORDINATE_ARRAY_POINTER 0
+#define DO_NOT_USE_GL_FOG_COORDINATE_ARRAY_STRIDE 0
+#define DO_NOT_USE_GL_FOG_COORDINATE_ARRAY_TYPE 0
+#define DO_NOT_USE_GL_FOG_COORDINATE_SOURCE 0
+#define DO_NOT_USE_GL_POINT_SIZE_GRANULARITY 0
+#define DO_NOT_USE_GL_POINT_SIZE_RANGE 0
+#define DO_NOT_USE_GL_SOURCE0_ALPHA 0
+#define DO_NOT_USE_GL_SOURCE0_RGB 0
+#define DO_NOT_USE_GL_SOURCE1_ALPHA 0
+#define DO_NOT_USE_GL_SOURCE1_RGB 0
+#define DO_NOT_USE_GL_SOURCE2_ALPHA 0
+#define DO_NOT_USE_GL_SOURCE2_RGB 0
+
+/**
+ * Functions
+ */
+_GL_VOID DO_NOT_USE_glAccum (GLenum op, GLfloat value) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glAlphaFunc (GLenum func, GLclampf ref) _GL_VOID_RET
+_GL_BOOL DO_NOT_USE_glAreTexturesResident (GLsizei n, const GLuint *textures, GLboolean *residences) _GL_BOOL_RET
+_GL_VOID DO_NOT_USE_glArrayElement (GLint i) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glBegin (GLenum mode) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glBitmap (GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig, GLfloat xmove, GLfloat ymove, const GLubyte *bitmap) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glCallList (GLuint list) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glCallLists (GLsizei n, GLenum type, const void *lists) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glClearAccum (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glClearIndex (GLfloat c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glClipPlane (GLenum plane, const GLdouble *equation) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3b (GLbyte red, GLbyte green, GLbyte blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3bv (const GLbyte *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3d (GLdouble red, GLdouble green, GLdouble blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3f (GLfloat red, GLfloat green, GLfloat blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3i (GLint red, GLint green, GLint blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3s (GLshort red, GLshort green, GLshort blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3ub (GLubyte red, GLubyte green, GLubyte blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3ubv (const GLubyte *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3ui (GLuint red, GLuint green, GLuint blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3uiv (const GLuint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3us (GLushort red, GLushort green, GLushort blue) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor3usv (const GLushort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4b (GLbyte red, GLbyte green, GLbyte blue, GLbyte alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4bv (const GLbyte *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4d (GLdouble red, GLdouble green, GLdouble blue, GLdouble alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4f (GLfloat red, GLfloat green, GLfloat blue, GLfloat alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4i (GLint red, GLint green, GLint blue, GLint alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4s (GLshort red, GLshort green, GLshort blue, GLshort alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4ub (GLubyte red, GLubyte green, GLubyte blue, GLubyte alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4ubv (const GLubyte *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4ui (GLuint red, GLuint green, GLuint blue, GLuint alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4uiv (const GLuint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4us (GLushort red, GLushort green, GLushort blue, GLushort alpha) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColor4usv (const GLushort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColorMaterial (GLenum face, GLenum mode) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glColorPointer (GLint size, GLenum type, GLsizei stride, const void *pointer) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glCopyPixels (GLint x, GLint y, GLsizei width, GLsizei height, GLenum type) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glDeleteLists (GLuint list, GLsizei range) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glDisableClientState (GLenum array) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glDrawPixels (GLsizei width, GLsizei height, GLenum format, GLenum type, const void *pixels) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEdgeFlag (GLboolean flag) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEdgeFlagPointer (GLsizei stride, const void *pointer) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEdgeFlagv (const GLboolean *flag) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEnableClientState (GLenum array) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEnd (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEndList (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord1d (GLdouble u) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord1dv (const GLdouble *u) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord1f (GLfloat u) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord1fv (const GLfloat *u) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord2d (GLdouble u, GLdouble v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord2dv (const GLdouble *u) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord2f (GLfloat u, GLfloat v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalCoord2fv (const GLfloat *u) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalMesh1 (GLenum mode, GLint i1, GLint i2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalMesh2 (GLenum mode, GLint i1, GLint i2, GLint j1, GLint j2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalPoint1 (GLint i) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glEvalPoint2 (GLint i, GLint j) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glFeedbackBuffer (GLsizei size, GLenum type, GLfloat *buffer) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glFogf (GLenum pname, GLfloat param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glFogfv (GLenum pname, const GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glFogi (GLenum pname, GLint param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glFogiv (GLenum pname, const GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glFrustum (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) _GL_VOID_RET
+_GL_UINT DO_NOT_USE_glGenLists (GLsizei range) _GL_UINT_RET
+_GL_VOID DO_NOT_USE_glGetClipPlane (GLenum plane, GLdouble *equation) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetLightfv (GLenum light, GLenum pname, GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetLightiv (GLenum light, GLenum pname, GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetMapdv (GLenum target, GLenum query, GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetMapfv (GLenum target, GLenum query, GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetMapiv (GLenum target, GLenum query, GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetMaterialfv (GLenum face, GLenum pname, GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetMaterialiv (GLenum face, GLenum pname, GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetPixelMapfv (GLenum map, GLfloat *values) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetPixelMapuiv (GLenum map, GLuint *values) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetPixelMapusv (GLenum map, GLushort *values) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetPolygonStipple (GLubyte *mask) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetTexEnvfv (GLenum target, GLenum pname, GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetTexEnviv (GLenum target, GLenum pname, GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetTexGendv (GLenum coord, GLenum pname, GLdouble *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetTexGenfv (GLenum coord, GLenum pname, GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glGetTexGeniv (GLenum coord, GLenum pname, GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexMask (GLuint mask) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexPointer (GLenum type, GLsizei stride, const void *pointer) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexd (GLdouble c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexdv (const GLdouble *c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexf (GLfloat c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexfv (const GLfloat *c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexi (GLint c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexiv (const GLint *c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexs (GLshort c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexsv (const GLshort *c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexub (GLubyte c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glIndexubv (const GLubyte *c) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glInitNames (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glInterleavedArrays (GLenum format, GLsizei stride, const void *pointer) _GL_VOID_RET
+_GL_BOOL DO_NOT_USE_glIsList (GLuint list) _GL_BOOL_RET
+_GL_VOID DO_NOT_USE_glLightModelf (GLenum pname, GLfloat param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLightModelfv (GLenum pname, const GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLightModeli (GLenum pname, GLint param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLightModeliv (GLenum pname, const GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLightf (GLenum light, GLenum pname, GLfloat param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLightfv (GLenum light, GLenum pname, const GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLighti (GLenum light, GLenum pname, GLint param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLightiv (GLenum light, GLenum pname, const GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLineStipple (GLint factor, GLushort pattern) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glListBase (GLuint base) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLoadIdentity (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLoadMatrixd (const GLdouble *m) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLoadMatrixf (const GLfloat *m) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glLoadName (GLuint name) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMap1d (GLenum target, GLdouble u1, GLdouble u2, GLint stride, GLint order, const GLdouble *points) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMap1f (GLenum target, GLfloat u1, GLfloat u2, GLint stride, GLint order, const GLfloat *points) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMap2d (GLenum target, GLdouble u1, GLdouble u2, GLint ustride, GLint uorder, GLdouble v1, GLdouble v2, GLint vstride, GLint vorder, const GLdouble *points) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMap2f (GLenum target, GLfloat u1, GLfloat u2, GLint ustride, GLint uorder, GLfloat v1, GLfloat v2, GLint vstride, GLint vorder, const GLfloat *points) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMapGrid1d (GLint un, GLdouble u1, GLdouble u2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMapGrid1f (GLint un, GLfloat u1, GLfloat u2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMapGrid2d (GLint un, GLdouble u1, GLdouble u2, GLint vn, GLdouble v1, GLdouble v2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMapGrid2f (GLint un, GLfloat u1, GLfloat u2, GLint vn, GLfloat v1, GLfloat v2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMaterialf (GLenum face, GLenum pname, GLfloat param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMaterialfv (GLenum face, GLenum pname, const GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMateriali (GLenum face, GLenum pname, GLint param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMaterialiv (GLenum face, GLenum pname, const GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMatrixMode (GLenum mode) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMultMatrixd (const GLdouble *m) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glMultMatrixf (const GLfloat *m) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNewList (GLuint list, GLenum mode) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3b (GLbyte nx, GLbyte ny, GLbyte nz) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3bv (const GLbyte *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3d (GLdouble nx, GLdouble ny, GLdouble nz) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3f (GLfloat nx, GLfloat ny, GLfloat nz) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3i (GLint nx, GLint ny, GLint nz) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3s (GLshort nx, GLshort ny, GLshort nz) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormal3sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glNormalPointer (GLenum type, GLsizei stride, const void *pointer) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glOrtho (GLdouble left, GLdouble right, GLdouble bottom, GLdouble top, GLdouble zNear, GLdouble zFar) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPassThrough (GLfloat token) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPixelMapfv (GLenum map, GLsizei mapsize, const GLfloat *values) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPixelMapuiv (GLenum map, GLsizei mapsize, const GLuint *values) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPixelMapusv (GLenum map, GLsizei mapsize, const GLushort *values) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPixelTransferf (GLenum pname, GLfloat param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPixelTransferi (GLenum pname, GLint param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPixelZoom (GLfloat xfactor, GLfloat yfactor) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPolygonStipple (const GLubyte *mask) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPopAttrib (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPopClientAttrib (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPopMatrix (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPopName (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPrioritizeTextures (GLsizei n, const GLuint *textures, const GLclampf *priorities) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPushAttrib (GLbitfield mask) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPushClientAttrib (GLbitfield mask) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPushMatrix (void) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glPushName (GLuint name) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2d (GLdouble x, GLdouble y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2f (GLfloat x, GLfloat y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2i (GLint x, GLint y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2s (GLshort x, GLshort y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos2sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3d (GLdouble x, GLdouble y, GLdouble z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3f (GLfloat x, GLfloat y, GLfloat z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3i (GLint x, GLint y, GLint z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3s (GLshort x, GLshort y, GLshort z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos3sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4i (GLint x, GLint y, GLint z, GLint w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4s (GLshort x, GLshort y, GLshort z, GLshort w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRasterPos4sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRectd (GLdouble x1, GLdouble y1, GLdouble x2, GLdouble y2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRectdv (const GLdouble *v1, const GLdouble *v2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRectf (GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRectfv (const GLfloat *v1, const GLfloat *v2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRecti (GLint x1, GLint y1, GLint x2, GLint y2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRectiv (const GLint *v1, const GLint *v2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRects (GLshort x1, GLshort y1, GLshort x2, GLshort y2) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRectsv (const GLshort *v1, const GLshort *v2) _GL_VOID_RET
+_GL_INT DO_NOT_USE_glRenderMode (GLenum mode) _GL_INT_RET
+_GL_VOID DO_NOT_USE_glRotated (GLdouble angle, GLdouble x, GLdouble y, GLdouble z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glRotatef (GLfloat angle, GLfloat x, GLfloat y, GLfloat z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glScaled (GLdouble x, GLdouble y, GLdouble z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glScalef (GLfloat x, GLfloat y, GLfloat z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glSelectBuffer (GLsizei size, GLuint *buffer) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glShadeModel (GLenum mode) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1d (GLdouble s) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1f (GLfloat s) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1i (GLint s) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1s (GLshort s) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord1sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2d (GLdouble s, GLdouble t) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2f (GLfloat s, GLfloat t) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2i (GLint s, GLint t) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2s (GLshort s, GLshort t) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord2sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3d (GLdouble s, GLdouble t, GLdouble r) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3f (GLfloat s, GLfloat t, GLfloat r) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3i (GLint s, GLint t, GLint r) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3s (GLshort s, GLshort t, GLshort r) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord3sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4d (GLdouble s, GLdouble t, GLdouble r, GLdouble q) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4f (GLfloat s, GLfloat t, GLfloat r, GLfloat q) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4i (GLint s, GLint t, GLint r, GLint q) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4s (GLshort s, GLshort t, GLshort r, GLshort q) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoord4sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexCoordPointer (GLint size, GLenum type, GLsizei stride, const void *pointer) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexEnvf (GLenum target, GLenum pname, GLfloat param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexEnvfv (GLenum target, GLenum pname, const GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexEnvi (GLenum target, GLenum pname, GLint param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexEnviv (GLenum target, GLenum pname, const GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexGend (GLenum coord, GLenum pname, GLdouble param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexGendv (GLenum coord, GLenum pname, const GLdouble *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexGenf (GLenum coord, GLenum pname, GLfloat param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexGenfv (GLenum coord, GLenum pname, const GLfloat *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexGeni (GLenum coord, GLenum pname, GLint param) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTexGeniv (GLenum coord, GLenum pname, const GLint *params) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTranslated (GLdouble x, GLdouble y, GLdouble z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glTranslatef (GLfloat x, GLfloat y, GLfloat z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2d (GLdouble x, GLdouble y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2f (GLfloat x, GLfloat y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2i (GLint x, GLint y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2s (GLshort x, GLshort y) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex2sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3d (GLdouble x, GLdouble y, GLdouble z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3f (GLfloat x, GLfloat y, GLfloat z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3i (GLint x, GLint y, GLint z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3s (GLshort x, GLshort y, GLshort z) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex3sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4d (GLdouble x, GLdouble y, GLdouble z, GLdouble w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4dv (const GLdouble *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4f (GLfloat x, GLfloat y, GLfloat z, GLfloat w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4fv (const GLfloat *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4i (GLint x, GLint y, GLint z, GLint w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4iv (const GLint *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4s (GLshort x, GLshort y, GLshort z, GLshort w) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertex4sv (const GLshort *v) _GL_VOID_RET
+_GL_VOID DO_NOT_USE_glVertexPointer (GLint size, GLenum type, GLsizei stride, const void *pointer) _GL_VOID_RET
+
+/**
+ * End of automatically generated list
+ */
+
+
+
+#undef _GL_BOOL
+#undef _GL_BOOL_RET
+#undef _GL_ENUM
+#undef _GL_ENUM_RET
+#undef _GL_INT
+#undef _GL_INT_RET
+#undef _GL_UINT
+#undef _GL_UINT_RET
+#undef _GL_VOID
+#undef _GL_VOID_RET
+
+#if defined(__GNUC__)
+# pragma GCC diagnostic pop
+#endif
+
+#endif /* __GPU_LEGACY_STUBS_H__ */
diff --git a/source/blender/gpu/GPU_material.h b/source/blender/gpu/GPU_material.h
index e229afd3323..95492016f25 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -43,30 +43,33 @@ extern "C" {
struct Image;
struct ImageUser;
+struct ListBase;
struct Material;
struct Object;
-struct Image;
struct Scene;
-struct SceneRenderLayer;
struct GPUVertexAttribs;
struct GPUNode;
struct GPUNodeLink;
struct GPUNodeStack;
struct GPUMaterial;
struct GPUTexture;
+struct GPUUniformBuffer;
struct GPULamp;
struct PreviewImage;
struct World;
+struct bNode;
+struct bNodeTree;
typedef struct GPUNode GPUNode;
typedef struct GPUNodeLink GPUNodeLink;
typedef struct GPUMaterial GPUMaterial;
-typedef struct GPULamp GPULamp;
+
typedef struct GPUParticleInfo GPUParticleInfo;
/* Functions to create GPU Materials nodes */
typedef enum GPUType {
+ /* Keep in sync with GPU_DATATYPE_STR */
/* The value indicates the number of elements in each type */
GPU_NONE = 0,
GPU_FLOAT = 1,
@@ -76,9 +79,16 @@ typedef enum GPUType {
GPU_MAT3 = 9,
GPU_MAT4 = 16,
+ /* Values not in GPU_DATATYPE_STR */
GPU_TEX2D = 1002,
- GPU_SHADOW2D = 1003,
- GPU_TEXCUBE = 1004,
+ GPU_TEX3D = 1003,
+ GPU_SHADOW2D = 1004,
+ GPU_TEXCUBE = 1005,
+
+ /* GLSL Struct types */
+ GPU_CLOSURE = 1006,
+
+ /* Opengl Attributes */
GPU_ATTRIB = 3001
} GPUType;
@@ -98,7 +108,10 @@ typedef enum GPUBuiltin {
GPU_PARTICLE_ANG_VELOCITY = (1 << 12),
GPU_LOC_TO_VIEW_MATRIX = (1 << 13),
GPU_INVERSE_LOC_TO_VIEW_MATRIX = (1 << 14),
- GPU_OBJECT_INFO = (1 << 15)
+ GPU_OBJECT_INFO = (1 << 15),
+ GPU_VOLUME_DENSITY = (1 << 16),
+ GPU_VOLUME_FLAME = (1 << 17),
+ GPU_VOLUME_TEMPERATURE = (1 << 18)
} GPUBuiltin;
typedef enum GPUOpenGLBuiltin {
@@ -123,14 +136,19 @@ typedef enum GPUBlendMode {
typedef struct GPUNodeStack {
GPUType type;
- const char *name;
float vec[4];
struct GPUNodeLink *link;
bool hasinput;
bool hasoutput;
short sockettype;
+ bool end;
} GPUNodeStack;
+typedef enum GPUMaterialStatus {
+ GPU_MAT_FAILED = 0,
+ GPU_MAT_QUEUED,
+ GPU_MAT_SUCCESS,
+} GPUMaterialStatus;
#define GPU_DYNAMIC_GROUP_FROM_TYPE(f) ((f) & 0xFFFF0000)
@@ -141,6 +159,7 @@ typedef struct GPUNodeStack {
#define GPU_DYNAMIC_GROUP_MIST 0x00050000
#define GPU_DYNAMIC_GROUP_WORLD 0x00060000
#define GPU_DYNAMIC_GROUP_MAT 0x00070000
+#define GPU_DYNAMIC_UBO 0x00080000
typedef enum GPUDynamicType {
@@ -200,6 +219,7 @@ typedef enum GPUDynamicType {
GPUNodeLink *GPU_attribute(CustomDataType type, const char *name);
GPUNodeLink *GPU_uniform(float *num);
GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *data);
+GPUNodeLink *GPU_uniform_buffer(float *num, GPUType gputype);
GPUNodeLink *GPU_image(struct Image *ima, struct ImageUser *iuser, bool is_data);
GPUNodeLink *GPU_cube_map(struct Image *ima, struct ImageUser *iuser, bool is_data);
GPUNodeLink *GPU_image_preview(struct PreviewImage *prv);
@@ -210,150 +230,48 @@ GPUNodeLink *GPU_opengl_builtin(GPUOpenGLBuiltin builtin);
void GPU_node_link_set_type(GPUNodeLink *link, GPUType type);
bool GPU_link(GPUMaterial *mat, const char *name, ...);
-bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
+bool GPU_stack_link(GPUMaterial *mat, struct bNode *node, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...);
+GPUNodeLink *GPU_uniformbuffer_link_out(
+ struct GPUMaterial *mat, struct bNode *node,
+ struct GPUNodeStack *stack, const int index);
void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link);
-void GPU_material_enable_alpha(GPUMaterial *material);
GPUBuiltin GPU_get_material_builtins(GPUMaterial *material);
-GPUBlendMode GPU_material_alpha_blend(GPUMaterial *material, float obcol[4]);
-/* High level functions to create and use GPU materials */
-GPUMaterial *GPU_material_world(struct Scene *scene, struct World *wo);
+void GPU_material_sss_profile_create(GPUMaterial *material, float *radii, short *falloff_type, float *sharpness);
+struct GPUUniformBuffer *GPU_material_sss_profile_get(
+ GPUMaterial *material, int sample_ct, struct GPUTexture **tex_profile);
-GPUMaterial *GPU_material_from_blender(struct Scene *scene, struct Material *ma, bool use_opensubdiv);
-GPUMaterial *GPU_material_matcap(struct Scene *scene, struct Material *ma, bool use_opensubdiv);
+/* High level functions to create and use GPU materials */
+GPUMaterial *GPU_material_from_nodetree_find(
+ struct ListBase *gpumaterials, const void *engine_type, int options);
+GPUMaterial *GPU_material_from_nodetree(
+ struct Scene *scene, struct bNodeTree *ntree, struct ListBase *gpumaterials, const void *engine_type, int options);
+void GPU_material_generate_pass(
+ GPUMaterial *mat, const char *vert_code, const char *geom_code, const char *frag_lib, const char *defines);
void GPU_material_free(struct ListBase *gpumaterial);
void GPU_materials_free(void);
-bool GPU_lamp_visible(GPULamp *lamp, struct SceneRenderLayer *srl, struct Material *ma);
-void GPU_material_bind(
- GPUMaterial *material, int oblay, int viewlay, double time, int mipmap,
- float viewmat[4][4], float viewinv[4][4], float cameraborder[4], bool scenelock);
-void GPU_material_bind_uniforms(
- GPUMaterial *material, float obmat[4][4], float viewmat[4][4], float obcol[4],
- float autobumpscale, GPUParticleInfo *pi, float object_info[3]);
-void GPU_material_unbind(GPUMaterial *material);
-bool GPU_material_bound(GPUMaterial *material);
struct Scene *GPU_material_scene(GPUMaterial *material);
GPUMatType GPU_Material_get_type(GPUMaterial *material);
+struct GPUPass *GPU_material_get_pass(GPUMaterial *material);
+struct ListBase *GPU_material_get_inputs(GPUMaterial *material);
+GPUMaterialStatus GPU_material_status(GPUMaterial *mat);
+
+struct GPUUniformBuffer *GPU_material_get_uniform_buffer(GPUMaterial *material);
+void GPU_material_create_uniform_buffer(GPUMaterial *material, struct ListBase *inputs);
+void GPU_material_uniform_buffer_tag_dirty(struct ListBase *gpumaterials);
void GPU_material_vertex_attributes(GPUMaterial *material,
struct GPUVertexAttribs *attrib);
bool GPU_material_do_color_management(GPUMaterial *mat);
-bool GPU_material_use_new_shading_nodes(GPUMaterial *mat);
-bool GPU_material_use_world_space_shading(GPUMaterial *mat);
-
-/* Exported shading */
-
-typedef struct GPUShadeInput {
- GPUMaterial *gpumat;
- struct Material *mat;
-
- GPUNodeLink *rgb, *specrgb, *vn, *view, *vcol, *ref;
- GPUNodeLink *alpha, *refl, *spec, *emit, *har, *amb;
- GPUNodeLink *spectra, *mir, *refcol;
-} GPUShadeInput;
-
-typedef struct GPUShadeResult {
- GPUNodeLink *diff, *spec, *combined, *alpha;
-} GPUShadeResult;
-
-void GPU_shadeinput_set(GPUMaterial *mat, struct Material *ma, GPUShadeInput *shi);
-void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr);
-
-/* Export GLSL shader */
-
-typedef enum GPUDataType {
- GPU_DATA_NONE = 0,
- GPU_DATA_1I = 1, /* 1 integer */
- GPU_DATA_1F = 2,
- GPU_DATA_2F = 3,
- GPU_DATA_3F = 4,
- GPU_DATA_4F = 5,
- GPU_DATA_9F = 6,
- GPU_DATA_16F = 7,
- GPU_DATA_4UB = 8,
-} GPUDataType;
-
-/* this structure gives information of each uniform found in the shader */
-typedef struct GPUInputUniform {
- struct GPUInputUniform *next, *prev;
- char varname[32]; /* name of uniform in shader */
- GPUDynamicType type; /* type of uniform, data format and calculation derive from it */
- GPUDataType datatype; /* type of uniform data */
- struct Object *lamp; /* when type=GPU_DYNAMIC_LAMP_... or GPU_DYNAMIC_SAMPLER_2DSHADOW */
- struct Image *image; /* when type=GPU_DYNAMIC_SAMPLER_2DIMAGE */
- struct Material *material;/* when type=GPU_DYNAMIC_MAT_... */
- int texnumber; /* when type=GPU_DYNAMIC_SAMPLER, texture number: 0.. */
- unsigned char *texpixels; /* for internally generated texture, pixel data in RGBA format */
- int texsize; /* size in pixel of the texture in texpixels buffer:
- * for 2D textures, this is S and T size (square texture) */
-} GPUInputUniform;
-
-typedef struct GPUInputAttribute {
- struct GPUInputAttribute *next, *prev;
- char varname[32]; /* name of attribute in shader */
- int type; /* from CustomData.type, data type derives from it */
- GPUDataType datatype; /* type of attribute data */
- const char *name; /* layer name */
- int number; /* generic attribute number */
-} GPUInputAttribute;
-
-typedef struct GPUShaderExport {
- ListBase uniforms;
- ListBase attributes;
- char *vertex;
- char *fragment;
-} GPUShaderExport;
-
-GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma);
-void GPU_free_shader_export(GPUShaderExport *shader);
-
-/* Lamps */
-
-GPULamp *GPU_lamp_from_blender(struct Scene *scene, struct Object *ob, struct Object *par);
-void GPU_lamp_free(struct Object *ob);
-
-bool GPU_lamp_has_shadow_buffer(GPULamp *lamp);
-void GPU_lamp_update_buffer_mats(GPULamp *lamp);
-void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[4][4], int *winsize, float winmat[4][4]);
-void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp);
-int GPU_lamp_shadow_buffer_type(GPULamp *lamp);
-int GPU_lamp_shadow_bind_code(GPULamp *lamp);
-float *GPU_lamp_dynpersmat(GPULamp *lamp);
-
-void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[4][4]);
-void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy);
-void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2,
- float coeff_const, float coeff_lin, float coeff_quad);
-void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend);
-int GPU_lamp_shadow_layer(GPULamp *lamp);
-GPUNodeLink *GPU_lamp_get_data(
- GPUMaterial *mat, GPULamp *lamp,
- GPUNodeLink **r_col, GPUNodeLink **r_lv, GPUNodeLink **r_dist, GPUNodeLink **r_shadow, GPUNodeLink **r_energy);
-
-/* World */
-void GPU_mist_update_enable(short enable);
-void GPU_mist_update_values(int type, float start, float dist, float inten, float color[3]);
-void GPU_horizon_update_color(float color[3]);
-void GPU_ambient_update_color(float color[3]);
-void GPU_zenith_update_color(float color[3]);
-
-struct GPUParticleInfo
-{
- float scalprops[4];
- float location[4];
- float velocity[3];
- float angular_velocity[3];
-};
-
-#ifdef WITH_OPENSUBDIV
-struct DerivedMesh;
-void GPU_material_update_fvar_offset(GPUMaterial *gpu_material,
- struct DerivedMesh *dm);
-#endif
+bool GPU_material_use_domain_surface(GPUMaterial *mat);
+bool GPU_material_use_domain_volume(GPUMaterial *mat);
+
+void GPU_pass_cache_garbage_collect(void);
+void GPU_pass_cache_free(void);
#ifdef __cplusplus
}
diff --git a/source/blender/gpu/GPU_matrix.h b/source/blender/gpu/GPU_matrix.h
new file mode 100644
index 00000000000..f22c0cd5c4d
--- /dev/null
+++ b/source/blender/gpu/GPU_matrix.h
@@ -0,0 +1,190 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Alexandr Kuznetsov, Jason Wilkins, Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file source/blender/gpu/GPU_matrix.h
+ * \ingroup gpu
+ */
+
+#ifndef __GPU_MATRIX_H__
+#define __GPU_MATRIX_H__
+
+#include "BLI_sys_types.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Gwn_ShaderInterface;
+
+void gpuMatrixReset(void); /* to Identity transform & empty stack */
+
+/* ModelView Matrix (2D or 3D) */
+
+void gpuPushMatrix(void); /* TODO: PushCopy vs PushIdentity? */
+void gpuPopMatrix(void);
+
+void gpuLoadIdentity(void);
+
+void gpuScaleUniform(float factor);
+
+
+/* 3D ModelView Matrix */
+
+void gpuLoadMatrix(const float m[4][4]);
+void gpuMultMatrix(const float m[4][4]);
+
+void gpuTranslate3f(float x, float y, float z);
+void gpuTranslate3fv(const float vec[3]);
+void gpuScale3f(float x, float y, float z);
+void gpuScale3fv(const float vec[3]);
+void gpuRotate3f(float deg, float x, float y, float z); /* axis of rotation should be a unit vector */
+void gpuRotate3fv(float deg, const float axis[3]); /* axis of rotation should be a unit vector */
+void gpuRotateAxis(float deg, char axis); /* TODO: enum for axis? */
+
+void gpuLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ);
+/* TODO: variant that takes eye[3], center[3], up[3] */
+
+
+/* 2D ModelView Matrix */
+
+void gpuTranslate2f(float x, float y);
+void gpuTranslate2fv(const float vec[2]);
+void gpuScale2f(float x, float y);
+void gpuScale2fv(const float vec[2]);
+void gpuRotate2D(float deg);
+
+/* Projection Matrix (2D or 3D) */
+
+void gpuPushProjectionMatrix(void);
+void gpuPopProjectionMatrix(void);
+
+/* 3D Projection Matrix */
+
+void gpuLoadIdentityProjectionMatrix(void);
+void gpuLoadProjectionMatrix(const float m[4][4]);
+
+void gpuOrtho(float left, float right, float bottom, float top, float near, float far);
+void gpuFrustum(float left, float right, float bottom, float top, float near, float far);
+void gpuPerspective(float fovy, float aspect, float near, float far);
+
+/* 3D Projection between Window and World Space */
+
+void gpuProject(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float win[3]);
+bool gpuUnProject(const float win[3], const float model[4][4], const float proj[4][4], const int view[4], float world[3]);
+
+/* 2D Projection Matrix */
+
+void gpuOrtho2D(float left, float right, float bottom, float top);
+
+
+/* functions to get matrix values */
+const float (*gpuGetModelViewMatrix(float m[4][4]))[4];
+const float (*gpuGetProjectionMatrix(float m[4][4]))[4];
+const float (*gpuGetModelViewProjectionMatrix(float m[4][4]))[4];
+
+const float (*gpuGetNormalMatrix(float m[3][3]))[3];
+const float (*gpuGetNormalMatrixInverse(float m[3][3]))[3];
+
+
+/* set uniform values for currently bound shader */
+void gpuBindMatrices(const struct Gwn_ShaderInterface *);
+bool gpuMatricesDirty(void); /* since last bind */
+
+
+/* Python API needs to be able to inspect the stack so errors raise exceptions instead of crashing. */
+#ifdef USE_GPU_PY_MATRIX_API
+int GPU_matrix_stack_level_get_model_view(void);
+int GPU_matrix_stack_level_get_projection(void);
+/* static assert ensures this doesn't change! */
+#define GPU_PY_MATRIX_STACK_LEN 31
+#endif /* USE_GPU_PY_MATRIX_API */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#ifndef SUPPRESS_GENERIC_MATRIX_API
+
+#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
+#define _GPU_MAT3_CONST_CAST(x) (_Generic((x), \
+ void *: (const float (*)[3])(x), \
+ float *: (const float (*)[3])(x), \
+ float [9]: (const float (*)[3])(x), \
+ float (*)[4]: (const float (*)[3])(x), \
+ float [4][4]: (const float (*)[3])(x), \
+ const void *: (const float (*)[3])(x), \
+ const float *: (const float (*)[3])(x), \
+ const float [9]: (const float (*)[3])(x), \
+ const float (*)[3]: (const float (*)[3])(x), \
+ const float [3][3]: (const float (*)[3])(x)) \
+)
+#define _GPU_MAT3_CAST(x) (_Generic((x), \
+ void *: (float (*)[3])(x), \
+ float *: (float (*)[3])(x), \
+ float [9]: (float (*)[3])(x), \
+ float (*)[3]: (float (*)[3])(x), \
+ float [3][3]: (float (*)[3])(x)) \
+)
+#define _GPU_MAT4_CONST_CAST(x) (_Generic((x), \
+ void *: (const float (*)[4])(x), \
+ float *: (const float (*)[4])(x), \
+ float [16]: (const float (*)[4])(x), \
+ float (*)[4]: (const float (*)[4])(x), \
+ float [4][4]: (const float (*)[4])(x), \
+ const void *: (const float (*)[4])(x), \
+ const float *: (const float (*)[4])(x), \
+ const float [16]: (const float (*)[4])(x), \
+ const float (*)[4]: (const float (*)[4])(x), \
+ const float [4][4]: (const float (*)[4])(x)) \
+)
+#define _GPU_MAT4_CAST(x) (_Generic((x), \
+ void *: (float (*)[4])(x), \
+ float *: (float (*)[4])(x), \
+ float [16]: (float (*)[4])(x), \
+ float (*)[4]: (float (*)[4])(x), \
+ float [4][4]: (float (*)[4])(x)) \
+)
+#else
+# define _GPU_MAT3_CONST_CAST(x) (const float (*)[3])(x)
+# define _GPU_MAT3_CAST(x) (float (*)[3])(x)
+# define _GPU_MAT4_CONST_CAST(x) (const float (*)[4])(x)
+# define _GPU_MAT4_CAST(x) (float (*)[4])(x)
+#endif /* C11 */
+
+/* make matrix inputs generic, to avoid warnings */
+# define gpuMultMatrix(x) gpuMultMatrix(_GPU_MAT4_CONST_CAST(x))
+# define gpuLoadMatrix(x) gpuLoadMatrix(_GPU_MAT4_CONST_CAST(x))
+# define gpuLoadProjectionMatrix(x) gpuLoadProjectionMatrix(_GPU_MAT4_CONST_CAST(x))
+# define gpuGetModelViewMatrix(x) gpuGetModelViewMatrix(_GPU_MAT4_CAST(x))
+# define gpuGetProjectionMatrix(x) gpuGetProjectionMatrix(_GPU_MAT4_CAST(x))
+# define gpuGetModelViewProjectionMatrix(x) gpuGetModelViewProjectionMatrix(_GPU_MAT4_CAST(x))
+# define gpuGetNormalMatrix(x) gpuGetNormalMatrix(_GPU_MAT3_CAST(x))
+# define gpuGetNormalMatrixInverse(x) gpuGetNormalMatrixInverse(_GPU_MAT3_CAST(x))
+#endif /* SUPPRESS_GENERIC_MATRIX_API */
+
+#endif /* __GPU_MATRIX_H__ */
diff --git a/source/blender/gpu/GPU_select.h b/source/blender/gpu/GPU_select.h
index 53f480bccd7..f1342a1f6b8 100644
--- a/source/blender/gpu/GPU_select.h
+++ b/source/blender/gpu/GPU_select.h
@@ -57,4 +57,7 @@ void GPU_select_cache_begin(void);
void GPU_select_cache_load_id(void);
void GPU_select_cache_end(void);
+/* utilities */
+const uint *GPU_select_buffer_near(const uint *buffer, int hits);
+
#endif
diff --git a/source/blender/gpu/GPU_shader.h b/source/blender/gpu/GPU_shader.h
index 5b94db6e120..2a672873d86 100644
--- a/source/blender/gpu/GPU_shader.h
+++ b/source/blender/gpu/GPU_shader.h
@@ -38,6 +38,7 @@ extern "C" {
typedef struct GPUShader GPUShader;
struct GPUTexture;
+struct GPUUniformBuffer;
/* GPU Shader
* - only for fragment shaders now
@@ -54,29 +55,32 @@ GPUShader *GPU_shader_create(
const char *fragcode,
const char *geocode,
const char *libcode,
- const char *defines,
- int input, int output, int number);
+ const char *defines);
GPUShader *GPU_shader_create_ex(
const char *vertexcode,
const char *fragcode,
const char *geocode,
const char *libcode,
const char *defines,
- int input, int output, int number,
const int flags);
void GPU_shader_free(GPUShader *shader);
void GPU_shader_bind(GPUShader *shader);
void GPU_shader_unbind(void);
+int GPU_shader_get_program(GPUShader *shader);
+
void *GPU_shader_get_interface(GPUShader *shader);
-void GPU_shader_set_interface(GPUShader *shader, void *interface);
+
int GPU_shader_get_uniform(GPUShader *shader, const char *name);
+int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin);
+int GPU_shader_get_uniform_block(GPUShader *shader, const char *name);
void GPU_shader_uniform_vector(GPUShader *shader, int location, int length,
int arraysize, const float *value);
void GPU_shader_uniform_vector_int(GPUShader *shader, int location, int length,
int arraysize, const int *value);
+void GPU_shader_uniform_buffer(GPUShader *shader, int location, struct GPUUniformBuffer *ubo);
void GPU_shader_uniform_texture(GPUShader *shader, int location, struct GPUTexture *tex);
void GPU_shader_uniform_int(GPUShader *shader, int location, int value);
void GPU_shader_geometry_stage_primitive_io(GPUShader *shader, int input, int output, int number);
@@ -85,15 +89,116 @@ int GPU_shader_get_attribute(GPUShader *shader, const char *name);
/* Builtin/Non-generated shaders */
typedef enum GPUBuiltinShader {
- GPU_SHADER_VSM_STORE = 0,
- GPU_SHADER_SEP_GAUSSIAN_BLUR = 1,
- GPU_SHADER_SMOKE = 2,
- GPU_SHADER_SMOKE_FIRE = 3,
- GPU_SHADER_SMOKE_COBA = 4,
+ GPU_SHADER_VSM_STORE,
+ GPU_SHADER_SEP_GAUSSIAN_BLUR,
+ GPU_SHADER_SMOKE,
+ GPU_SHADER_SMOKE_FIRE,
+ GPU_SHADER_SMOKE_COBA,
+
+ /* specialized drawing */
+ GPU_SHADER_TEXT,
+ GPU_SHADER_TEXT_SIMPLE,
+ GPU_SHADER_EDGES_FRONT_BACK_PERSP,
+ GPU_SHADER_EDGES_FRONT_BACK_ORTHO,
+ GPU_SHADER_EDGES_OVERLAY_SIMPLE,
+ GPU_SHADER_EDGES_OVERLAY,
+ GPU_SHADER_KEYFRAME_DIAMOND,
+ GPU_SHADER_SIMPLE_LIGHTING,
+ GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR,
+ GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR,
+ GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR_ALPHA,
+ /* for simple 2D drawing */
+ GPU_SHADER_2D_UNIFORM_COLOR,
+ GPU_SHADER_2D_FLAT_COLOR,
+ GPU_SHADER_2D_SMOOTH_COLOR,
+ GPU_SHADER_2D_SMOOTH_COLOR_DITHER,
+ GPU_SHADER_2D_IMAGE,
+ GPU_SHADER_2D_IMAGE_COLOR,
+ GPU_SHADER_2D_IMAGE_DESATURATE_COLOR,
+ GPU_SHADER_2D_IMAGE_ALPHA_COLOR,
+ GPU_SHADER_2D_IMAGE_ALPHA,
+ GPU_SHADER_2D_IMAGE_RECT_COLOR,
+ GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR,
+ GPU_SHADER_2D_IMAGE_MULTISAMPLE_2,
+ GPU_SHADER_2D_IMAGE_MULTISAMPLE_4,
+ GPU_SHADER_2D_IMAGE_MULTISAMPLE_8,
+ GPU_SHADER_2D_IMAGE_MULTISAMPLE_16,
+ GPU_SHADER_2D_CHECKER,
+ GPU_SHADER_2D_DIAG_STRIPES,
+ /* for simple 3D drawing */
+ GPU_SHADER_3D_UNIFORM_COLOR,
+ GPU_SHADER_3D_UNIFORM_COLOR_U32,
+ GPU_SHADER_3D_UNIFORM_COLOR_INSTANCE,
+ GPU_SHADER_3D_FLAT_COLOR,
+ GPU_SHADER_3D_FLAT_COLOR_U32, /* use for select-id's */
+ GPU_SHADER_3D_SMOOTH_COLOR,
+ GPU_SHADER_3D_DEPTH_ONLY,
+ GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR,
+ /* basic image drawing */
+ GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB,
+ GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR,
+ GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR,
+ GPU_SHADER_3D_IMAGE_MODULATE_ALPHA,
+ GPU_SHADER_3D_IMAGE_DEPTH,
+ GPU_SHADER_3D_IMAGE_DEPTH_COPY,
+ /* stereo 3d */
+ GPU_SHADER_2D_IMAGE_INTERLACE,
+ /* points */
+ GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR,
+ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
+ GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
+ GPU_SHADER_2D_POINT_UNIFORM_SIZE_VARYING_COLOR_OUTLINE_AA,
+ GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR,
+ GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR,
+ GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR,
+ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA,
+ GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA,
+ GPU_SHADER_3D_POINT_VARYING_SIZE_UNIFORM_COLOR,
+ GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR,
+ /* lines */
+ GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR,
+ GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR,
+ /* lamp drawing */
+ GPU_SHADER_3D_GROUNDPOINT,
+ GPU_SHADER_3D_GROUNDLINE,
+ GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR,
+ /* bone drawing */
+ GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR,
+ GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR,
+ /* camera drawing */
+ GPU_SHADER_CAMERA,
+ /* distance in front of objects */
+ GPU_SHADER_DISTANCE_LINES,
+ /* axis name */
+ GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS,
+ GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED,
+ /* instance */
+ GPU_SHADER_INSTANCE_UNIFORM_COLOR,
+ GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE, /* Uniformly scaled */
+ GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE, /* Uniformly scaled */
+ GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE,
+ GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR,
+ /* specialized for UI drawing */
+ GPU_SHADER_2D_WIDGET_BASE,
+ GPU_SHADER_2D_WIDGET_BASE_INST,
+ GPU_SHADER_2D_WIDGET_SHADOW,
+ GPU_SHADER_2D_NODELINK,
+ GPU_SHADER_2D_NODELINK_INST,
+
+ GPU_NUM_BUILTIN_SHADERS /* (not an actual shader) */
} GPUBuiltinShader;
+/* Keep these in sync with:
+ * gpu_shader_image_interlace_frag.glsl
+ * gpu_shader_image_rect_interlace_frag.glsl
+ **/
+typedef enum GPUInterlaceShader {
+ GPU_SHADER_INTERLACE_ROW = 0,
+ GPU_SHADER_INTERLACE_COLUMN = 1,
+ GPU_SHADER_INTERLACE_CHECKER = 2,
+} GPUInterlaceShader;
+
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader);
-GPUShader *GPU_shader_get_builtin_fx_shader(int effects, bool persp);
void GPU_shader_free_builtin_shaders(void);
diff --git a/source/blender/gpu/GPU_texture.h b/source/blender/gpu/GPU_texture.h
index 756fe79151b..a64b0a0a862 100644
--- a/source/blender/gpu/GPU_texture.h
+++ b/source/blender/gpu/GPU_texture.h
@@ -55,25 +55,115 @@ typedef struct GPUTexture GPUTexture;
* - if created with from_blender, will not free the texture
*/
-typedef enum GPUHDRType {
- GPU_HDR_NONE = 0,
- GPU_HDR_HALF_FLOAT = 1,
- GPU_HDR_FULL_FLOAT = (1 << 1),
-} GPUHDRType;
-
-GPUTexture *GPU_texture_create_1D(int w, const float *pixels, char err_out[256]);
-GPUTexture *GPU_texture_create_2D(int w, int h, const float *pixels, GPUHDRType hdr, char err_out[256]);
-GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const float *fpixels);
-GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256]);
-GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256]);
-GPUTexture *GPU_texture_create_2D_procedural(int w, int h, const float *pixels, bool repeat, char err_out[256]);
-GPUTexture *GPU_texture_create_1D_procedural(int w, const float *pixels, char err_out[256]);
+/* Wrapper to supported OpenGL/Vulkan texture internal storage
+ * If you need a type just uncomment it. Be aware that some formats
+ * are not supported by renderbuffers. All of the following formats
+ * are part of the OpenGL 3.3 core
+ * specification. */
+typedef enum GPUTextureFormat {
+ /* Formats texture & renderbuffer */
+ GPU_RGBA32F,
+ GPU_RGBA16F,
+ GPU_RGBA8,
+ GPU_RG32F,
+ GPU_RG16F,
+ GPU_RG16I,
+ GPU_RG16,
+ GPU_R32F,
+ GPU_R32UI,
+ GPU_R16F,
+ GPU_R16I,
+ GPU_R16UI,
+ GPU_RG8,
+ GPU_R8,
+#if 0
+ GPU_RGBA32I,
+ GPU_RGBA32UI,
+ GPU_RGBA16,
+ GPU_RGBA16I,
+ GPU_RGBA16UI,
+ GPU_RGBA8I,
+ GPU_RGBA8UI,
+ GPU_RG32I,
+ GPU_RG32UI,
+ GPU_RG16UI,
+ GPU_RG8I,
+ GPU_RG8UI,
+ GPU_R32I,
+ GPU_R16,
+ GPU_R8I,
+ GPU_R8UI,
+#endif
+
+ /* Special formats texture & renderbuffer */
+#if 0
+ GPU_RGB10_A2,
+ GPU_RGB10_A2UI,
+ GPU_DEPTH32F_STENCIL8,
+#endif
+ GPU_R11F_G11F_B10F,
+ GPU_DEPTH24_STENCIL8,
+
+ /* Texture only format */
+ GPU_RGB16F,
+#if 0
+ GPU_RGBA16_SNORM,
+ GPU_RGBA8_SNORM,
+ GPU_RGB32F,
+ GPU_RGB32I,
+ GPU_RGB32UI,
+ GPU_RGB16_SNORM,
+ GPU_RGB16I,
+ GPU_RGB16UI,
+ GPU_RGB16,
+ GPU_RGB8_SNORM,
+ GPU_RGB8,
+ GPU_RGB8I,
+ GPU_RGB8UI,
+ GPU_RG16_SNORM,
+ GPU_RG8_SNORM,
+ GPU_R16_SNORM,
+ GPU_R8_SNORM,
+#endif
+
+ /* Special formats texture only */
+#if 0
+ GPU_SRGB8_A8,
+ GPU_SRGB8,
+ GPU_RGB9_E5,
+ GPU_COMPRESSED_RG_RGTC2,
+ GPU_COMPRESSED_SIGNED_RG_RGTC2,
+ GPU_COMPRESSED_RED_RGTC1,
+ GPU_COMPRESSED_SIGNED_RED_RGTC1,
+#endif
+
+ /* Depth Formats */
+ GPU_DEPTH_COMPONENT32F,
+ GPU_DEPTH_COMPONENT24,
+ GPU_DEPTH_COMPONENT16,
+} GPUTextureFormat;
+
+unsigned int GPU_texture_memory_usage_get(void);
+
+GPUTexture *GPU_texture_create_1D(
+ int w, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
+GPUTexture *GPU_texture_create_2D(
+ int w, int h, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
GPUTexture *GPU_texture_create_2D_multisample(
- int w, int h, const float *pixels, GPUHDRType hdr, int samples, char err_out[256]);
-GPUTexture *GPU_texture_create_depth_multisample(int w, int h, int samples, char err_out[256]);
+ int w, int h, GPUTextureFormat data_type, const float *pixels, int samples, char err_out[256]);
+GPUTexture *GPU_texture_create_2D_array(
+ int w, int h, int d, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
+GPUTexture *GPU_texture_create_3D(
+ int w, int h, int d, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
+GPUTexture *GPU_texture_create_cube(
+ int w, GPUTextureFormat data_type, const float *pixels, char err_out[256]);
+
GPUTexture *GPU_texture_from_blender(
struct Image *ima, struct ImageUser *iuser, int textarget, bool is_data, double time, int mipmap);
GPUTexture *GPU_texture_from_preview(struct PreviewImage *prv, int mipmap);
+
+void GPU_texture_update(GPUTexture *tex, const float *pixels);
+
void GPU_invalid_tex_init(void);
void GPU_invalid_tex_bind(int mode);
void GPU_invalid_tex_free(void);
@@ -81,21 +171,28 @@ void GPU_invalid_tex_free(void);
void GPU_texture_free(GPUTexture *tex);
void GPU_texture_ref(GPUTexture *tex);
-
void GPU_texture_bind(GPUTexture *tex, int number);
void GPU_texture_unbind(GPUTexture *tex);
int GPU_texture_bound_number(GPUTexture *tex);
-void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter);
+void GPU_texture_generate_mipmap(GPUTexture *tex);
+void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare);
+void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter);
+void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter);
+void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat);
-struct GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex);
-int GPU_texture_framebuffer_attachment(GPUTexture *tex);
-void GPU_texture_framebuffer_set(GPUTexture *tex, struct GPUFrameBuffer *fb, int attachment);
+void GPU_texture_attach_framebuffer(GPUTexture *tex, struct GPUFrameBuffer *fb, int attachment);
+int GPU_texture_detach_framebuffer(GPUTexture *tex, struct GPUFrameBuffer *fb);
int GPU_texture_target(const GPUTexture *tex);
int GPU_texture_width(const GPUTexture *tex);
int GPU_texture_height(const GPUTexture *tex);
-int GPU_texture_depth(const GPUTexture *tex);
+GPUTextureFormat GPU_texture_format(const GPUTexture *tex);
+int GPU_texture_samples(const GPUTexture *tex);
+bool GPU_texture_cube(const GPUTexture *tex);
+bool GPU_texture_depth(const GPUTexture *tex);
+bool GPU_texture_stencil(const GPUTexture *tex);
+bool GPU_texture_integer(const GPUTexture *tex);
int GPU_texture_opengl_bindcode(const GPUTexture *tex);
#ifdef __cplusplus
diff --git a/source/blender/gpu/GPU_uniformbuffer.h b/source/blender/gpu/GPU_uniformbuffer.h
new file mode 100644
index 00000000000..c2480f8ba03
--- /dev/null
+++ b/source/blender/gpu/GPU_uniformbuffer.h
@@ -0,0 +1,59 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Clement Foucault.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file GPU_uniformbuffer.h
+ * \ingroup gpu
+ */
+
+#ifndef __GPU_UNIFORMBUFFER_H__
+#define __GPU_UNIFORMBUFFER_H__
+
+struct ListBase;
+
+typedef struct GPUUniformBuffer GPUUniformBuffer;
+typedef struct GPUUniformBufferDynamicItem GPUUniformBufferDynamicItem;
+
+GPUUniformBuffer *GPU_uniformbuffer_create(int size, const void *data, char err_out[256]);
+GPUUniformBuffer *GPU_uniformbuffer_dynamic_create(struct ListBase *inputs, char err_out[256]);
+
+void GPU_uniformbuffer_free(GPUUniformBuffer *ubo);
+
+void GPU_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data);
+void GPU_uniformbuffer_dynamic_update(GPUUniformBuffer *ubo_);
+
+void GPU_uniformbuffer_bind(GPUUniformBuffer *ubo, int number);
+void GPU_uniformbuffer_unbind(GPUUniformBuffer *ubo);
+
+int GPU_uniformbuffer_bindpoint(GPUUniformBuffer *ubo);
+
+bool GPU_uniformbuffer_is_empty(GPUUniformBuffer *ubo);
+bool GPU_uniformbuffer_is_dirty(GPUUniformBuffer *ubo);
+void GPU_uniformbuffer_tag_dirty(GPUUniformBuffer *ubo);
+
+#define GPU_UBO_BLOCK_NAME "nodeTree"
+
+#endif /* __GPU_UNIFORMBUFFER_H__ */
diff --git a/source/blender/gpu/GPU_viewport.h b/source/blender/gpu/GPU_viewport.h
new file mode 100644
index 00000000000..921cd0e7369
--- /dev/null
+++ b/source/blender/gpu/GPU_viewport.h
@@ -0,0 +1,130 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file GPU_viewport.h
+ * \ingroup gpu
+ */
+
+#ifndef __GPU_VIEWPORT_H__
+#define __GPU_VIEWPORT_H__
+
+#include <stdbool.h>
+
+#include "DNA_vec_types.h"
+
+#include "GPU_framebuffer.h"
+#include "GPU_texture.h"
+
+#define GPU_INFO_SIZE 512 /* IMA_MAX_RENDER_TEXT */
+
+typedef struct GPUViewport GPUViewport;
+
+/* Contains memory pools informations */
+typedef struct ViewportMemoryPool {
+ struct BLI_mempool *calls;
+ struct BLI_mempool *states;
+ struct BLI_mempool *shgroups;
+ struct BLI_mempool *uniforms;
+ struct BLI_mempool *passes;
+} ViewportMemoryPool;
+
+/* All FramebufferLists are just the same pointers with different names */
+typedef struct FramebufferList {
+ struct GPUFrameBuffer *framebuffers[0];
+} FramebufferList;
+
+typedef struct TextureList {
+ struct GPUTexture *textures[0];
+} TextureList;
+
+typedef struct PassList {
+ struct DRWPass *passes[0];
+} PassList;
+
+typedef struct StorageList {
+ void *storage[0]; /* custom structs from the engine */
+} StorageList;
+
+typedef struct ViewportEngineData {
+ void *engine_type;
+
+ FramebufferList *fbl;
+ TextureList *txl;
+ PassList *psl;
+ StorageList *stl;
+ char info[GPU_INFO_SIZE];
+
+ /* we may want to put this elsewhere */
+ struct DRWTextStore *text_draw_cache;
+
+ /* Profiling data */
+ double init_time;
+ double render_time;
+ double background_time;
+} ViewportEngineData;
+
+typedef struct ViewportEngineData_Info {
+ int fbl_len;
+ int txl_len;
+ int psl_len;
+ int stl_len;
+} ViewportEngineData_Info;
+
+GPUViewport *GPU_viewport_create(void);
+void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect);
+void GPU_viewport_unbind(GPUViewport *viewport);
+void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect);
+void GPU_viewport_free(GPUViewport *viewport);
+
+GPUViewport *GPU_viewport_create_from_offscreen(struct GPUOffScreen *ofs);
+void GPU_viewport_clear_from_offscreen(GPUViewport *viewport);
+
+ViewportMemoryPool *GPU_viewport_mempool_get(GPUViewport *viewport);
+struct DRWInstanceDataList *GPU_viewport_instance_data_list_get(GPUViewport *viewport);
+
+void *GPU_viewport_engine_data_create(GPUViewport *viewport, void *engine_type);
+void *GPU_viewport_engine_data_get(GPUViewport *viewport, void *engine_type);
+void *GPU_viewport_framebuffer_list_get(GPUViewport *viewport);
+void *GPU_viewport_texture_list_get(GPUViewport *viewport);
+void GPU_viewport_size_get(const GPUViewport *viewport, int size[2]);
+void GPU_viewport_size_set(GPUViewport *viewport, const int size[2]);
+
+/* Profiling */
+double *GPU_viewport_cache_time_get(GPUViewport *viewport);
+
+void GPU_viewport_tag_update(GPUViewport *viewport);
+bool GPU_viewport_do_update(GPUViewport *viewport);
+
+GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport);
+
+/* Texture pool */
+GPUTexture *GPU_viewport_texture_pool_query(GPUViewport *viewport, void *engine, int width, int height, int format);
+
+bool GPU_viewport_engines_data_validate(GPUViewport *viewport, unsigned int hash);
+void GPU_viewport_cache_release(GPUViewport *viewport);
+
+#endif // __GPU_VIEWPORT_H__
diff --git a/source/blender/gpu/intern/gpu_basic_shader.c b/source/blender/gpu/intern/gpu_basic_shader.c
index 8505bd847a0..620a06ae606 100644
--- a/source/blender/gpu/intern/gpu_basic_shader.c
+++ b/source/blender/gpu/intern/gpu_basic_shader.c
@@ -140,114 +140,6 @@ const GLubyte stipple_checker_8px[128] = {
0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255,
0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255, 0, 255};
-const GLubyte stipple_interlace_row[128] = {
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00,
- 0xff, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00};
-
-const GLubyte stipple_interlace_row_swap[128] = {
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff,
- 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff};
-
-const GLubyte stipple_interlace_column[128] = {
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55,
- 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55};
-
-const GLubyte stipple_interlace_column_swap[128] = {
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa,
- 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa};
-
-const GLubyte stipple_interlace_checker[128] = {
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa,
- 0x55, 0x55, 0x55, 0x55, 0xaa, 0xaa, 0xaa, 0xaa};
-
-const GLubyte stipple_interlace_checker_swap[128] = {
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55,
- 0xaa, 0xaa, 0xaa, 0xaa, 0x55, 0x55, 0x55, 0x55};
-
const GLubyte stipple_hexagon[128] = {
0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88, 0x88,
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22,
@@ -267,24 +159,6 @@ const GLubyte stipple_hexagon[128] = {
0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};
/* ********************************************* */
-/* GLSL State */
-
-static bool USE_GLSL = false;
-
-/**
- * \note this isn't part of the basic shader API,
- * only set from the command line once on startup.
- */
-void GPU_basic_shader_use_glsl_set(bool enabled)
-{
- USE_GLSL = enabled;
-}
-
-bool GPU_basic_shader_use_glsl_get(void)
-{
- return USE_GLSL;
-}
-
/* Init / exit */
void GPU_basic_shaders_init(void)
@@ -316,31 +190,6 @@ static bool solid_compatible_lighting(void)
return ((directional & enabled) == enabled);
}
-#if 0
-static int detect_options()
-{
- GLint two_sided;
- int options = 0;
-
- if (glIsEnabled(GL_TEXTURE_2D))
- options |= GPU_SHADER_TEXTURE_2D;
- if (glIsEnabled(GL_TEXTURE_RECTANGLE))
- options |= GPU_SHADER_TEXTURE_RECT;
- GPU_SHADER_TEXTURE_RECT
- if (glIsEnabled(GL_COLOR_MATERIAL))
- options |= GPU_SHADER_USE_COLOR;
-
- if (glIsEnabled(GL_LIGHTING))
- options |= GPU_SHADER_LIGHTING;
-
- glGetIntegerv(GL_LIGHT_MODEL_TWO_SIDE, &two_sided);
- if (two_sided == GL_TRUE)
- options |= GPU_SHADER_TWO_SIDED;
-
- return options;
-}
-#endif
-
static GPUShader *gpu_basic_shader(int options)
{
/* glsl code */
@@ -388,7 +237,7 @@ static GPUShader *gpu_basic_shader(int options)
datatoc_gpu_shader_basic_frag_glsl,
geom_glsl,
NULL,
- defines, 0, 0, 0);
+ defines);
if (shader) {
/* set texture map to first texture unit */
@@ -420,102 +269,16 @@ static void gpu_basic_shader_uniform_autoset(GPUShader *shader, int options)
void GPU_basic_shader_bind(int options)
{
- if (USE_GLSL) {
- if (options) {
- const int bound_options = GPU_MATERIAL_STATE.bound_options;
-
- /* texture options need to be set for basic shader too */
- if (options & GPU_SHADER_TEXTURE_2D) {
- glEnable(GL_TEXTURE_2D);
- }
- else if (bound_options & GPU_SHADER_TEXTURE_2D) {
- glDisable(GL_TEXTURE_2D);
- }
-
- if (options & GPU_SHADER_TEXTURE_RECT) {
- glEnable(GL_TEXTURE_RECTANGLE);
- }
- else if (bound_options & GPU_SHADER_TEXTURE_RECT) {
- glDisable(GL_TEXTURE_RECTANGLE);
- }
-
- GPUShader *shader = gpu_basic_shader(options);
+ if (options) {
+ GPUShader *shader = gpu_basic_shader(options);
- if (shader) {
- GPU_shader_bind(shader);
- gpu_basic_shader_uniform_autoset(shader, options);
- }
- }
- else {
- GPU_shader_unbind();
+ if (shader) {
+ GPU_shader_bind(shader);
+ gpu_basic_shader_uniform_autoset(shader, options);
}
}
else {
- const int bound_options = GPU_MATERIAL_STATE.bound_options;
-
- if (options & GPU_SHADER_LIGHTING) {
- glEnable(GL_LIGHTING);
-
- if (options & GPU_SHADER_USE_COLOR)
- glEnable(GL_COLOR_MATERIAL);
- else
- glDisable(GL_COLOR_MATERIAL);
-
- if (options & GPU_SHADER_TWO_SIDED)
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
- else
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
- }
- else if (bound_options & GPU_SHADER_LIGHTING) {
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
- }
-
- if (options & GPU_SHADER_TEXTURE_2D) {
- GLint env_mode = (options & (GPU_SHADER_USE_COLOR | GPU_SHADER_LIGHTING)) ? GL_MODULATE : GL_REPLACE;
- glEnable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode);
- }
- else if (bound_options & GPU_SHADER_TEXTURE_2D) {
- if ((options & GPU_SHADER_TEXTURE_RECT) == 0) {
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- }
- glDisable(GL_TEXTURE_2D);
- }
-
- if (options & GPU_SHADER_TEXTURE_RECT) {
- GLint env_mode = (options & (GPU_SHADER_USE_COLOR | GPU_SHADER_LIGHTING)) ? GL_MODULATE : GL_REPLACE;
- glEnable(GL_TEXTURE_RECTANGLE);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, env_mode);
- }
- else if (bound_options & GPU_SHADER_TEXTURE_RECT) {
- if ((options & GPU_SHADER_TEXTURE_2D) == 0) {
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- }
- glDisable(GL_TEXTURE_RECTANGLE);
- }
-
- if ((options & GPU_SHADER_LINE) && (options & GPU_SHADER_STIPPLE)) {
- glEnable(GL_LINE_STIPPLE);
- }
- else if ((bound_options & GPU_SHADER_LINE) && (bound_options & GPU_SHADER_STIPPLE)) {
- glDisable(GL_LINE_STIPPLE);
- }
-
- if (((options & GPU_SHADER_LINE) == 0) && (options & GPU_SHADER_STIPPLE)) {
- glEnable(GL_POLYGON_STIPPLE);
- }
- else if (((bound_options & GPU_SHADER_LINE) == 0) && (bound_options & GPU_SHADER_STIPPLE)) {
- glDisable(GL_POLYGON_STIPPLE);
- }
-
- if (options & GPU_SHADER_FLAT_NORMAL) {
- glShadeModel(GL_FLAT);
- }
- else if (bound_options & GPU_SHADER_FLAT_NORMAL) {
- glShadeModel(GL_SMOOTH);
- }
+ GPU_shader_unbind();
}
GPU_MATERIAL_STATE.bound_options = options;
@@ -544,175 +307,37 @@ void GPU_basic_shader_colors(
const float diffuse[3], const float specular[3],
int shininess, float alpha)
{
- float gl_diffuse[4], gl_specular[4];
-
- if (diffuse)
- copy_v3_v3(gl_diffuse, diffuse);
- else
- zero_v3(gl_diffuse);
- gl_diffuse[3] = alpha;
-
- if (specular)
- copy_v3_v3(gl_specular, specular);
- else
- zero_v3(gl_specular);
- gl_specular[3] = 1.0f;
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, gl_diffuse);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, gl_specular);
- glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, CLAMPIS(shininess, 1, 128));
+ UNUSED_VARS(diffuse, specular, shininess, alpha);
+ return;
}
void GPU_basic_shader_light_set(int light_num, GPULightData *light)
{
- int light_bit = (1 << light_num);
-
- /* note that light position is affected by the current modelview matrix! */
-
- GPU_MATERIAL_STATE.lights_enabled &= ~light_bit;
- GPU_MATERIAL_STATE.lights_directional &= ~light_bit;
-
- if (light) {
- float position[4], diffuse[4], specular[4];
-
- glEnable(GL_LIGHT0 + light_num);
-
- /* position */
- if (light->type == GPU_LIGHT_SUN) {
- copy_v3_v3(position, light->direction);
- position[3] = 0.0f;
- }
- else {
- copy_v3_v3(position, light->position);
- position[3] = 1.0f;
- }
- glLightfv(GL_LIGHT0 + light_num, GL_POSITION, position);
-
- /* energy */
- copy_v3_v3(diffuse, light->diffuse);
- copy_v3_v3(specular, light->specular);
- diffuse[3] = 1.0f;
- specular[3] = 1.0f;
- glLightfv(GL_LIGHT0 + light_num, GL_DIFFUSE, diffuse);
- glLightfv(GL_LIGHT0 + light_num, GL_SPECULAR, specular);
-
- /* attenuation */
- if (light->type == GPU_LIGHT_SUN) {
- glLightf(GL_LIGHT0 + light_num, GL_CONSTANT_ATTENUATION, 1.0f);
- glLightf(GL_LIGHT0 + light_num, GL_LINEAR_ATTENUATION, 0.0f);
- glLightf(GL_LIGHT0 + light_num, GL_QUADRATIC_ATTENUATION, 0.0f);
- }
- else {
- glLightf(GL_LIGHT0 + light_num, GL_CONSTANT_ATTENUATION, light->constant_attenuation);
- glLightf(GL_LIGHT0 + light_num, GL_LINEAR_ATTENUATION, light->linear_attenuation);
- glLightf(GL_LIGHT0 + light_num, GL_QUADRATIC_ATTENUATION, light->quadratic_attenuation);
- }
-
- /* spot */
- glLightfv(GL_LIGHT0 + light_num, GL_SPOT_DIRECTION, light->direction);
- if (light->type == GPU_LIGHT_SPOT) {
- glLightf(GL_LIGHT0 + light_num, GL_SPOT_CUTOFF, light->spot_cutoff);
- glLightf(GL_LIGHT0 + light_num, GL_SPOT_EXPONENT, light->spot_exponent);
- }
- else {
- glLightf(GL_LIGHT0 + light_num, GL_SPOT_CUTOFF, 180.0f);
- glLightf(GL_LIGHT0 + light_num, GL_SPOT_EXPONENT, 0.0f);
- }
-
- GPU_MATERIAL_STATE.lights_enabled |= light_bit;
- if (position[3] == 0.0f)
- GPU_MATERIAL_STATE.lights_directional |= light_bit;
- }
- else {
- /* TODO(sergey): Needs revisit. */
- if (USE_GLSL || true) {
- /* glsl shader needs these zero to skip them */
- const float zero[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-
- glLightfv(GL_LIGHT0 + light_num, GL_POSITION, zero);
- glLightfv(GL_LIGHT0 + light_num, GL_DIFFUSE, zero);
- glLightfv(GL_LIGHT0 + light_num, GL_SPECULAR, zero);
- }
-
- glDisable(GL_LIGHT0 + light_num);
- }
+ UNUSED_VARS(light_num, light);
+ return;
}
void GPU_basic_shader_light_set_viewer(bool local)
{
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (local) ? GL_TRUE: GL_FALSE);
+ UNUSED_VARS(local);
+ return;
}
void GPU_basic_shader_stipple(GPUBasicShaderStipple stipple_id)
{
- if (USE_GLSL) {
- glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_id"), stipple_id);
- }
- else {
- switch (stipple_id) {
- case GPU_SHADER_STIPPLE_HALFTONE:
- glPolygonStipple(stipple_halftone);
- return;
- case GPU_SHADER_STIPPLE_QUARTTONE:
- glPolygonStipple(stipple_quarttone);
- return;
- case GPU_SHADER_STIPPLE_CHECKER_8PX:
- glPolygonStipple(stipple_checker_8px);
- return;
- case GPU_SHADER_STIPPLE_HEXAGON:
- glPolygonStipple(stipple_hexagon);
- return;
- case GPU_SHADER_STIPPLE_DIAG_STRIPES_SWAP:
- glPolygonStipple(stipple_diag_stripes_neg);
- return;
- case GPU_SHADER_STIPPLE_DIAG_STRIPES:
- glPolygonStipple(stipple_diag_stripes_pos);
- return;
- case GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW:
- glPolygonStipple(stipple_interlace_row);
- return;
- case GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW_SWAP:
- glPolygonStipple(stipple_interlace_row_swap);
- return;
- case GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN:
- glPolygonStipple(stipple_interlace_column);
- return;
- case GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN_SWAP:
- glPolygonStipple(stipple_interlace_column_swap);
- return;
- case GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER:
- glPolygonStipple(stipple_interlace_checker);
- return;
- case GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER_SWAP:
- glPolygonStipple(stipple_interlace_checker_swap);
- return;
- default:
- glPolygonStipple(stipple_hexagon);
- return;
- }
- }
+ glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_id"), stipple_id);
}
void GPU_basic_shader_line_width(float line_width)
{
- if (USE_GLSL) {
- GPU_MATERIAL_STATE.line_width = line_width;
- if (GPU_MATERIAL_STATE.bound_options & GPU_SHADER_LINE) {
- glUniform1f(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "line_width"), line_width);
- }
- }
- else {
- glLineWidth(line_width);
+ GPU_MATERIAL_STATE.line_width = line_width;
+ if (GPU_MATERIAL_STATE.bound_options & GPU_SHADER_LINE) {
+ glUniform1f(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "line_width"), line_width);
}
}
void GPU_basic_shader_line_stipple(GLint stipple_factor, GLushort stipple_pattern)
{
- if (USE_GLSL) {
- glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_factor"), stipple_factor);
- glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_pattern"), stipple_pattern);
- }
- else {
- glLineStipple(stipple_factor, stipple_pattern);
- }
+ glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_factor"), stipple_factor);
+ glUniform1i(GPU_shader_get_uniform(gpu_basic_shader(GPU_MATERIAL_STATE.bound_options), "stipple_pattern"), stipple_pattern);
}
diff --git a/source/blender/gpu/intern/gpu_batch.c b/source/blender/gpu/intern/gpu_batch.c
new file mode 100644
index 00000000000..59d88e81822
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_batch.c
@@ -0,0 +1,281 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/gpu/intern/gpu_batch.c
+ * \ingroup gpu
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_rect.h"
+#include "BLI_math.h"
+#include "BLI_polyfill_2d.h"
+#include "BLI_sort_utils.h"
+
+
+#include "GPU_batch.h" /* own include */
+#include "gpu_shader_private.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Utilities
+ * \{ */
+
+void GWN_batch_program_set_builtin(Gwn_Batch *batch, GPUBuiltinShader shader_id)
+{
+ GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
+ GWN_batch_program_set(batch, shader->program, shader->interface);
+}
+
+/** \} */
+
+
+
+/* -------------------------------------------------------------------- */
+/** \name Batch Creation
+ * \{ */
+
+/**
+ * Creates triangles from a byte-array of polygons.
+ *
+ * See 'make_shape_2d_from_blend.py' utility to create data to pass to this function.
+ *
+ * \param polys_flat: Pairs of X, Y coordinates (repeating to signify closing the polygon).
+ * \param polys_flat_len: Length of the array (must be an even number).
+ * \param rect: Optional region to map the byte 0..255 coords to. When not set use -1..1.
+ */
+Gwn_Batch *GPU_batch_tris_from_poly_2d_encoded(
+ const uchar *polys_flat, uint polys_flat_len, const rctf *rect)
+{
+ const uchar (*polys)[2] = (const void *)polys_flat;
+ const uint polys_len = polys_flat_len / 2;
+ BLI_assert(polys_flat_len == polys_len * 2);
+
+ /* Over alloc in both cases */
+ float (*verts)[2] = MEM_mallocN(sizeof(*verts) * polys_len, __func__);
+ float (*verts_step)[2] = verts;
+ uint (*tris)[3] = MEM_mallocN(sizeof(*tris) * polys_len, __func__);
+ uint (*tris_step)[3] = tris;
+
+ const float range_uchar[2] = {
+ (rect ? (rect->xmax - rect->xmin) : 2.0f) / 255.0f,
+ (rect ? (rect->ymax - rect->ymin) : 2.0f) / 255.0f,
+ };
+ const float min_uchar[2] = {
+ (rect ? rect->xmin : -1.0f),
+ (rect ? rect->ymin : -1.0f),
+ };
+
+ uint i_poly = 0;
+ uint i_vert = 0;
+ while (i_poly != polys_len) {
+ for (uint j = 0; j < 2; j++) {
+ verts[i_vert][j] = min_uchar[j] + ((float)polys[i_poly][j] * range_uchar[j]);
+ }
+ i_vert++;
+ i_poly++;
+ if (polys[i_poly - 1][0] == polys[i_poly][0] &&
+ polys[i_poly - 1][1] == polys[i_poly][1])
+ {
+ const uint verts_step_len = (&verts[i_vert]) - verts_step;
+ BLI_assert(verts_step_len >= 3);
+ const uint tris_len = (verts_step_len - 2);
+ BLI_polyfill_calc(verts_step, verts_step_len, -1, tris_step);
+ /* offset indices */
+ if (verts_step != verts) {
+ uint *t = tris_step[0];
+ const uint offset = (verts_step - verts);
+ uint tot = tris_len * 3;
+ while (tot--) {
+ *t += offset;
+ t++;
+ }
+ BLI_assert(t == tris_step[tris_len]);
+ }
+ verts_step += verts_step_len;
+ tris_step += tris_len;
+ i_poly++;
+ /* ignore the duplicate point */
+ }
+ }
+
+ /* We have vertices and tris, make a batch from this. */
+ static Gwn_VertFormat format = {0};
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ const uint verts_len = (verts_step - verts);
+ const uint tris_len = (tris_step - tris);
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ GWN_vertbuf_data_alloc(vbo, verts_len);
+
+ Gwn_VertBufRaw pos_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step);
+
+ for (uint i = 0; i < verts_len; i++) {
+ copy_v2_v2(GWN_vertbuf_raw_step(&pos_step), verts[i]);
+ }
+
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tris_len, verts_len);
+ for (uint i = 0; i < tris_len; i++) {
+ GWN_indexbuf_add_tri_verts(&elb, UNPACK3(tris[i]));
+ }
+ Gwn_IndexBuf *indexbuf = GWN_indexbuf_build(&elb);
+
+ MEM_freeN(tris);
+ MEM_freeN(verts);
+
+ return GWN_batch_create_ex(
+ GWN_PRIM_TRIS, vbo,
+ indexbuf,
+ GWN_BATCH_OWNS_VBO | GWN_BATCH_OWNS_INDEX);
+}
+
+Gwn_Batch *GPU_batch_wire_from_poly_2d_encoded(
+ const uchar *polys_flat, uint polys_flat_len, const rctf *rect)
+{
+ const uchar (*polys)[2] = (const void *)polys_flat;
+ const uint polys_len = polys_flat_len / 2;
+ BLI_assert(polys_flat_len == polys_len * 2);
+
+ /* Over alloc */
+ /* Lines are pairs of (x, y) byte locations packed into an int32_t. */
+ int32_t *lines = MEM_mallocN(sizeof(*lines) * polys_len, __func__);
+ int32_t *lines_step = lines;
+
+ const float range_uchar[2] = {
+ (rect ? (rect->xmax - rect->xmin) : 2.0f) / 255.0f,
+ (rect ? (rect->ymax - rect->ymin) : 2.0f) / 255.0f,
+ };
+ const float min_uchar[2] = {
+ (rect ? rect->xmin : -1.0f),
+ (rect ? rect->ymin : -1.0f),
+ };
+
+ uint i_poly_prev = 0;
+ uint i_poly = 0;
+ while (i_poly != polys_len) {
+ i_poly++;
+ if (polys[i_poly - 1][0] == polys[i_poly][0] &&
+ polys[i_poly - 1][1] == polys[i_poly][1])
+ {
+ const uchar (*polys_step)[2] = polys + i_poly_prev;
+ const uint polys_step_len = i_poly - i_poly_prev;
+ BLI_assert(polys_step_len >= 2);
+ for (uint i_prev = polys_step_len - 1, i = 0; i < polys_step_len; i_prev = i++) {
+ union {
+ uint8_t as_u8[4];
+ uint16_t as_u16[2];
+ uint32_t as_u32;
+ } data;
+ data.as_u16[0] = *((const uint16_t *)polys_step[i_prev]);
+ data.as_u16[1] = *((const uint16_t *)polys_step[i]);
+ if (data.as_u16[0] > data.as_u16[1]) {
+ SWAP(uint16_t, data.as_u16[0], data.as_u16[1]);
+ }
+ *lines_step = data.as_u32;
+ lines_step++;
+ }
+ i_poly++;
+ i_poly_prev = i_poly;
+ /* ignore the duplicate point */
+ }
+ }
+
+ uint lines_len = lines_step - lines;
+
+ /* Hide Lines (we could make optional) */
+ {
+ qsort(lines, lines_len, sizeof(int32_t), BLI_sortutil_cmp_int);
+ lines_step = lines;
+
+ if (lines[0] != lines[1]) {
+ *lines_step++ = lines[0];
+ }
+ for (uint i_prev = 0, i = 1; i < lines_len; i_prev = i++) {
+ if (lines[i] != lines[i_prev]) {
+ *lines_step++ = lines[i];
+ }
+ }
+ lines_len = lines_step - lines;
+ }
+
+ /* We have vertices and tris, make a batch from this. */
+ static Gwn_VertFormat format = {0};
+ static struct { uint pos; } attr_id;
+ if (format.attrib_ct == 0) {
+ attr_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ }
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&format);
+ const uint vbo_len_capacity = lines_len * 2;
+ GWN_vertbuf_data_alloc(vbo, vbo_len_capacity);
+
+ Gwn_VertBufRaw pos_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, attr_id.pos, &pos_step);
+
+ for (uint i = 0; i < lines_len; i++) {
+ union {
+ uint8_t as_u8_pair[2][2];
+ uint32_t as_u32;
+ } data;
+ data.as_u32 = lines[i];
+ for (uint k = 0; k < 2; k++) {
+ float *pos_v2 = GWN_vertbuf_raw_step(&pos_step);
+ for (uint j = 0; j < 2; j++) {
+ pos_v2[j] = min_uchar[j] + ((float)data.as_u8_pair[k][j] * range_uchar[j]);
+ }
+ }
+ }
+ BLI_assert(vbo_len_capacity == GWN_vertbuf_raw_used(&pos_step));
+ MEM_freeN(lines);
+ return GWN_batch_create_ex(
+ GWN_PRIM_LINES, vbo,
+ NULL,
+ GWN_BATCH_OWNS_VBO);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Init/Exit
+ * \{ */
+
+void gpu_batch_init(void)
+{
+ gpu_batch_presets_init();
+}
+
+void gpu_batch_exit(void)
+{
+ gpu_batch_presets_exit();
+}
+
+/** \} */
diff --git a/source/blender/gpu/intern/gpu_batch_presets.c b/source/blender/gpu/intern/gpu_batch_presets.c
new file mode 100644
index 00000000000..10cbd16490b
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_batch_presets.c
@@ -0,0 +1,236 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/gpu/intern/gpu_batch_presets.c
+ * \ingroup gpu
+ */
+
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+#include "BLI_threads.h"
+#include "BLI_listbase.h"
+#include "MEM_guardedalloc.h"
+
+#include "UI_interface.h"
+
+#include "GPU_batch.h"
+#include "gpu_shader_private.h"
+
+/* Struct to store 3D Batches and their format */
+static struct {
+ struct {
+ Gwn_Batch *sphere_high;
+ Gwn_Batch *sphere_med;
+ Gwn_Batch *sphere_low;
+ Gwn_Batch *sphere_wire_low;
+ Gwn_Batch *sphere_wire_med;
+ } batch;
+
+ Gwn_VertFormat format;
+
+ struct {
+ uint pos, nor;
+ } attr_id;
+} g_presets_3d = {{0}};
+
+static ListBase presets_list = {NULL, NULL};
+
+/* -------------------------------------------------------------------- */
+/** \name 3D Primitives
+ * \{ */
+
+static Gwn_VertFormat *preset_3D_format(void)
+{
+ if (g_presets_3d.format.attrib_ct == 0) {
+ Gwn_VertFormat *format = &g_presets_3d.format;
+ g_presets_3d.attr_id.pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ g_presets_3d.attr_id.nor = GWN_vertformat_attr_add(format, "nor", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ }
+ return &g_presets_3d.format;
+}
+
+static void batch_sphere_lat_lon_vert(
+ Gwn_VertBufRaw *pos_step, Gwn_VertBufRaw *nor_step,
+ float lat, float lon)
+{
+ float pos[3];
+ pos[0] = sinf(lat) * cosf(lon);
+ pos[1] = cosf(lat);
+ pos[2] = sinf(lat) * sinf(lon);
+ copy_v3_v3(GWN_vertbuf_raw_step(pos_step), pos);
+ copy_v3_v3(GWN_vertbuf_raw_step(nor_step), pos);
+}
+
+/* Replacement for gluSphere */
+Gwn_Batch *gpu_batch_sphere(int lat_res, int lon_res)
+{
+ const float lon_inc = 2 * M_PI / lon_res;
+ const float lat_inc = M_PI / lat_res;
+ float lon, lat;
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(preset_3D_format());
+ const uint vbo_len = (lat_res - 1) * lon_res * 6;
+ GWN_vertbuf_data_alloc(vbo, vbo_len);
+
+ Gwn_VertBufRaw pos_step, nor_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, g_presets_3d.attr_id.pos, &pos_step);
+ GWN_vertbuf_attr_get_raw_data(vbo, g_presets_3d.attr_id.nor, &nor_step);
+
+ lon = 0.0f;
+ for (int i = 0; i < lon_res; i++, lon += lon_inc) {
+ lat = 0.0f;
+ for (int j = 0; j < lat_res; j++, lat += lat_inc) {
+ if (j != lat_res - 1) { /* Pole */
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat + lat_inc, lon + lon_inc);
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat + lat_inc, lon);
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat, lon);
+ }
+
+ if (j != 0) { /* Pole */
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat, lon + lon_inc);
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat + lat_inc, lon + lon_inc);
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat, lon);
+ }
+ }
+ }
+
+ BLI_assert(vbo_len == GWN_vertbuf_raw_used(&pos_step));
+ BLI_assert(vbo_len == GWN_vertbuf_raw_used(&nor_step));
+
+ return GWN_batch_create_ex(GWN_PRIM_TRIS, vbo, NULL, GWN_BATCH_OWNS_VBO);
+}
+
+static Gwn_Batch *batch_sphere_wire(int lat_res, int lon_res)
+{
+ const float lon_inc = 2 * M_PI / lon_res;
+ const float lat_inc = M_PI / lat_res;
+ float lon, lat;
+
+ Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(preset_3D_format());
+ const uint vbo_len = (lat_res * lon_res * 2) + ((lat_res - 1) * lon_res * 2);
+ GWN_vertbuf_data_alloc(vbo, vbo_len);
+
+ Gwn_VertBufRaw pos_step, nor_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, g_presets_3d.attr_id.pos, &pos_step);
+ GWN_vertbuf_attr_get_raw_data(vbo, g_presets_3d.attr_id.nor, &nor_step);
+
+ lon = 0.0f;
+ for (int i = 0; i < lon_res; i++, lon += lon_inc) {
+ lat = 0.0f;
+ for (int j = 0; j < lat_res; j++, lat += lat_inc) {
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat + lat_inc, lon);
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat, lon);
+
+ if (j != lat_res - 1) { /* Pole */
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat + lat_inc, lon + lon_inc);
+ batch_sphere_lat_lon_vert(&pos_step, &nor_step, lat + lat_inc, lon);
+ }
+ }
+ }
+
+ BLI_assert(vbo_len == GWN_vertbuf_raw_used(&pos_step));
+ BLI_assert(vbo_len == GWN_vertbuf_raw_used(&nor_step));
+
+ return GWN_batch_create_ex(GWN_PRIM_LINES, vbo, NULL, GWN_BATCH_OWNS_VBO);
+}
+
+Gwn_Batch *GPU_batch_preset_sphere(int lod)
+{
+ BLI_assert(lod >= 0 && lod <= 2);
+ BLI_assert(BLI_thread_is_main());
+
+ if (lod == 0) {
+ return g_presets_3d.batch.sphere_low;
+ }
+ else if (lod == 1) {
+ return g_presets_3d.batch.sphere_med;
+ }
+ else {
+ return g_presets_3d.batch.sphere_high;
+ }
+}
+
+Gwn_Batch *GPU_batch_preset_sphere_wire(int lod)
+{
+ BLI_assert(lod >= 0 && lod <= 1);
+ BLI_assert(BLI_thread_is_main());
+
+ if (lod == 0) {
+ return g_presets_3d.batch.sphere_wire_low;
+ }
+ else {
+ return g_presets_3d.batch.sphere_wire_med;
+ }
+}
+
+/** \} */
+
+
+void gpu_batch_presets_init(void)
+{
+ /* Hard coded resolution */
+ g_presets_3d.batch.sphere_low = gpu_batch_sphere(8, 16);
+ gpu_batch_presets_register(g_presets_3d.batch.sphere_low);
+
+ g_presets_3d.batch.sphere_med = gpu_batch_sphere(16, 10);
+ gpu_batch_presets_register(g_presets_3d.batch.sphere_med);
+
+ g_presets_3d.batch.sphere_high = gpu_batch_sphere(32, 24);
+ gpu_batch_presets_register(g_presets_3d.batch.sphere_high);
+
+ g_presets_3d.batch.sphere_wire_low = batch_sphere_wire(6, 8);
+ gpu_batch_presets_register(g_presets_3d.batch.sphere_wire_low);
+
+ g_presets_3d.batch.sphere_wire_med = batch_sphere_wire(8, 16);
+ gpu_batch_presets_register(g_presets_3d.batch.sphere_wire_med);
+}
+
+void gpu_batch_presets_register(Gwn_Batch *preset_batch)
+{
+ BLI_addtail(&presets_list, BLI_genericNodeN(preset_batch));
+}
+
+void gpu_batch_presets_reset(void)
+{
+ /* Reset vao caches for these every time we switch opengl context.
+ * This way they will draw correctly for each window. */
+ LinkData *link = presets_list.first;
+ for (link = presets_list.first; link; link = link->next) {
+ Gwn_Batch *preset = link->data;
+ gwn_batch_vao_cache_clear(preset);
+ }
+}
+
+void gpu_batch_presets_exit(void)
+{
+ LinkData *link;
+ while ((link = BLI_pophead(&presets_list))) {
+ Gwn_Batch *preset = link->data;
+ GWN_batch_discard(preset);
+ MEM_freeN(link);
+ }
+}
diff --git a/source/blender/gpu/intern/gpu_buffers.c b/source/blender/gpu/intern/gpu_buffers.c
index 38e847da967..9d2a0ceef4d 100644
--- a/source/blender/gpu/intern/gpu_buffers.c
+++ b/source/blender/gpu/intern/gpu_buffers.c
@@ -35,8 +35,6 @@
#include <stddef.h>
#include <string.h>
-#include "GPU_glew.h"
-
#include "MEM_guardedalloc.h"
#include "BLI_bitmap.h"
@@ -55,914 +53,29 @@
#include "GPU_buffers.h"
#include "GPU_draw.h"
-#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_batch.h"
#include "bmesh.h"
-typedef enum {
- GPU_BUFFER_VERTEX_STATE = (1 << 0),
- GPU_BUFFER_NORMAL_STATE = (1 << 1),
- GPU_BUFFER_TEXCOORD_UNIT_0_STATE = (1 << 2),
- GPU_BUFFER_TEXCOORD_UNIT_2_STATE = (1 << 3),
- GPU_BUFFER_COLOR_STATE = (1 << 4),
- GPU_BUFFER_ELEMENT_STATE = (1 << 5),
-} GPUBufferState;
-
-typedef struct {
- GLenum gl_buffer_type;
- int num_components; /* number of data components for one vertex */
-} GPUBufferTypeSettings;
-
-
-static size_t gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type);
-
-static const GPUBufferTypeSettings gpu_buffer_type_settings[] = {
- /* vertex */
- {GL_ARRAY_BUFFER, 3},
- /* normal */
- {GL_ARRAY_BUFFER, 4}, /* we copy 3 shorts per normal but we add a fourth for alignment */
- /* mcol */
- {GL_ARRAY_BUFFER, 4},
- /* uv */
- {GL_ARRAY_BUFFER, 2},
- /* uv for texpaint */
- {GL_ARRAY_BUFFER, 4},
- /* edge */
- {GL_ELEMENT_ARRAY_BUFFER, 2},
- /* uv edge */
- {GL_ELEMENT_ARRAY_BUFFER, 4},
- /* triangles, 1 point since we are allocating from tottriangle points, which account for all points */
- {GL_ELEMENT_ARRAY_BUFFER, 1},
-};
-
-#define MAX_GPU_ATTRIB_DATA 32
-
-#define BUFFER_OFFSET(n) ((GLubyte *)NULL + (n))
-
-static GPUBufferState GLStates = 0;
-static GPUAttrib attribData[MAX_GPU_ATTRIB_DATA] = { { -1, 0, 0 } };
-
static ThreadMutex buffer_mutex = BLI_MUTEX_INITIALIZER;
/* multires global buffer, can be used for many grids having the same grid size */
typedef struct GridCommonGPUBuffer {
- GPUBuffer *mres_buffer;
+ Gwn_IndexBuf *mres_buffer;
int mres_prev_gridsize;
- GLenum mres_prev_index_type;
unsigned mres_prev_totquad;
} GridCommonGPUBuffer;
-void GPU_buffer_material_finalize(GPUDrawObject *gdo, GPUBufferMaterial *matinfo, int totmat)
-{
- int i, curmat, curelement;
-
- /* count the number of materials used by this DerivedMesh */
- for (i = 0; i < totmat; i++) {
- if (matinfo[i].totelements > 0)
- gdo->totmaterial++;
- }
-
- /* allocate an array of materials used by this DerivedMesh */
- gdo->materials = MEM_mallocN(sizeof(GPUBufferMaterial) * gdo->totmaterial,
- "GPUDrawObject.materials");
-
- /* initialize the materials array */
- for (i = 0, curmat = 0, curelement = 0; i < totmat; i++) {
- if (matinfo[i].totelements > 0) {
- gdo->materials[curmat] = matinfo[i];
- gdo->materials[curmat].start = curelement;
- gdo->materials[curmat].mat_nr = i;
- gdo->materials[curmat].polys = MEM_mallocN(sizeof(int) * matinfo[i].totpolys, "GPUBufferMaterial.polys");
-
- curelement += matinfo[i].totelements;
- curmat++;
- }
- }
-
- MEM_freeN(matinfo);
-}
-
-
-/* stores recently-deleted buffers so that new buffers won't have to
- * be recreated as often
- *
- * only one instance of this pool is created, stored in
- * gpu_buffer_pool
- *
- * note that the number of buffers in the pool is usually limited to
- * MAX_FREE_GPU_BUFFERS, but this limit may be exceeded temporarily
- * when a GPUBuffer is released outside the main thread; due to OpenGL
- * restrictions it cannot be immediately released
- */
-typedef struct GPUBufferPool {
- /* number of allocated buffers stored */
- int totbuf;
- /* actual allocated length of the arrays */
- int maxsize;
- GPUBuffer **buffers;
-} GPUBufferPool;
-#define MAX_FREE_GPU_BUFFERS 8
-
-/* create a new GPUBufferPool */
-static GPUBufferPool *gpu_buffer_pool_new(void)
-{
- GPUBufferPool *pool;
-
- pool = MEM_callocN(sizeof(GPUBufferPool), "GPUBuffer_Pool");
-
- pool->maxsize = MAX_FREE_GPU_BUFFERS;
- pool->buffers = MEM_mallocN(sizeof(*pool->buffers) * pool->maxsize,
- "GPUBufferPool.buffers");
- return pool;
-}
-
-/* remove a GPUBuffer from the pool (does not free the GPUBuffer) */
-static void gpu_buffer_pool_remove_index(GPUBufferPool *pool, int index)
-{
- int i;
-
- if (!pool || index < 0 || index >= pool->totbuf)
- return;
-
- /* shift entries down, overwriting the buffer at `index' */
- for (i = index; i < pool->totbuf - 1; i++)
- pool->buffers[i] = pool->buffers[i + 1];
-
- /* clear the last entry */
- if (pool->totbuf > 0)
- pool->buffers[pool->totbuf - 1] = NULL;
-
- pool->totbuf--;
-}
-
-/* delete the last entry in the pool */
-static void gpu_buffer_pool_delete_last(GPUBufferPool *pool)
-{
- GPUBuffer *last;
-
- if (pool->totbuf <= 0)
- return;
-
- /* get the last entry */
- if (!(last = pool->buffers[pool->totbuf - 1]))
- return;
-
- /* delete the buffer's data */
- glDeleteBuffers(1, &last->id);
-
- /* delete the buffer and remove from pool */
- MEM_freeN(last);
- pool->totbuf--;
- pool->buffers[pool->totbuf] = NULL;
-}
-
-/* free a GPUBufferPool; also frees the data in the pool's
- * GPUBuffers */
-static void gpu_buffer_pool_free(GPUBufferPool *pool)
-{
- if (!pool)
- return;
-
- while (pool->totbuf)
- gpu_buffer_pool_delete_last(pool);
-
- MEM_freeN(pool->buffers);
- MEM_freeN(pool);
-}
-
-static void gpu_buffer_pool_free_unused(GPUBufferPool *pool)
-{
- if (!pool)
- return;
-
- BLI_mutex_lock(&buffer_mutex);
-
- while (pool->totbuf)
- gpu_buffer_pool_delete_last(pool);
-
- BLI_mutex_unlock(&buffer_mutex);
-}
-
-static GPUBufferPool *gpu_buffer_pool = NULL;
-static GPUBufferPool *gpu_get_global_buffer_pool(void)
-{
- /* initialize the pool */
- if (!gpu_buffer_pool)
- gpu_buffer_pool = gpu_buffer_pool_new();
-
- return gpu_buffer_pool;
-}
-
-void GPU_global_buffer_pool_free(void)
-{
- gpu_buffer_pool_free(gpu_buffer_pool);
- gpu_buffer_pool = NULL;
-}
-
-void GPU_global_buffer_pool_free_unused(void)
-{
- gpu_buffer_pool_free_unused(gpu_buffer_pool);
-}
-
-/* get a GPUBuffer of at least `size' bytes; uses one from the buffer
- * pool if possible, otherwise creates a new one
- *
- * Thread-unsafe version for internal usage only.
- */
-static GPUBuffer *gpu_buffer_alloc_intern(size_t size)
-{
- GPUBufferPool *pool;
- GPUBuffer *buf;
- int i, bestfit = -1;
- size_t bufsize;
-
- /* bad case, leads to leak of buf since buf->pointer will allocate
- * NULL, leading to return without cleanup. In any case better detect early
- * psy-fi */
- if (size == 0)
- return NULL;
-
- pool = gpu_get_global_buffer_pool();
-
- /* not sure if this buffer pool code has been profiled much,
- * seems to me that the graphics driver and system memory
- * management might do this stuff anyway. --nicholas
- */
-
- /* check the global buffer pool for a recently-deleted buffer
- * that is at least as big as the request, but not more than
- * twice as big */
- for (i = 0; i < pool->totbuf; i++) {
- bufsize = pool->buffers[i]->size;
-
- /* check for an exact size match */
- if (bufsize == size) {
- bestfit = i;
- break;
- }
- /* smaller buffers won't fit data and buffers at least
- * twice as big are a waste of memory */
- else if (bufsize > size && size > (bufsize / 2)) {
- /* is it closer to the required size than the
- * last appropriate buffer found. try to save
- * memory */
- if (bestfit == -1 || pool->buffers[bestfit]->size > bufsize) {
- bestfit = i;
- }
- }
- }
-
- /* if an acceptable buffer was found in the pool, remove it
- * from the pool and return it */
- if (bestfit != -1) {
- buf = pool->buffers[bestfit];
- gpu_buffer_pool_remove_index(pool, bestfit);
- return buf;
- }
-
- /* no acceptable buffer found in the pool, create a new one */
- buf = MEM_callocN(sizeof(GPUBuffer), "GPUBuffer");
- buf->size = size;
-
- glGenBuffers(1, &buf->id);
- glBindBuffer(GL_ARRAY_BUFFER, buf->id);
- glBufferData(GL_ARRAY_BUFFER, size, NULL, GL_STATIC_DRAW);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- return buf;
-}
-
-/* Same as above, but safe for threading. */
-GPUBuffer *GPU_buffer_alloc(size_t size)
-{
- GPUBuffer *buffer;
-
- if (size == 0) {
- /* Early out, no lock needed in this case. */
- return NULL;
- }
-
- BLI_mutex_lock(&buffer_mutex);
- buffer = gpu_buffer_alloc_intern(size);
- BLI_mutex_unlock(&buffer_mutex);
-
- return buffer;
-}
-
-/* release a GPUBuffer; does not free the actual buffer or its data,
- * but rather moves it to the pool of recently-freed buffers for
- * possible re-use
- *
- * Thread-unsafe version for internal usage only.
- */
-static void gpu_buffer_free_intern(GPUBuffer *buffer)
-{
- GPUBufferPool *pool;
- int i;
-
- if (!buffer)
- return;
-
- pool = gpu_get_global_buffer_pool();
-
- /* free the last used buffer in the queue if no more space, but only
- * if we are in the main thread. for e.g. rendering or baking it can
- * happen that we are in other thread and can't call OpenGL, in that
- * case cleanup will be done GPU_buffer_pool_free_unused */
- if (BLI_thread_is_main()) {
- /* in main thread, safe to decrease size of pool back
- * down to MAX_FREE_GPU_BUFFERS */
- while (pool->totbuf >= MAX_FREE_GPU_BUFFERS)
- gpu_buffer_pool_delete_last(pool);
- }
- else {
- /* outside of main thread, can't safely delete the
- * buffer, so increase pool size */
- if (pool->maxsize == pool->totbuf) {
- pool->maxsize += MAX_FREE_GPU_BUFFERS;
- pool->buffers = MEM_reallocN(pool->buffers,
- sizeof(GPUBuffer *) * pool->maxsize);
- }
- }
-
- /* shift pool entries up by one */
- for (i = pool->totbuf; i > 0; i--)
- pool->buffers[i] = pool->buffers[i - 1];
-
- /* insert the buffer into the beginning of the pool */
- pool->buffers[0] = buffer;
- pool->totbuf++;
-}
-
-/* Same as above, but safe for threading. */
-void GPU_buffer_free(GPUBuffer *buffer)
-{
- if (!buffer) {
- /* Early output, no need to lock in this case, */
- return;
- }
-
- BLI_mutex_lock(&buffer_mutex);
- gpu_buffer_free_intern(buffer);
- BLI_mutex_unlock(&buffer_mutex);
-}
-
-void GPU_drawobject_free(DerivedMesh *dm)
-{
- GPUDrawObject *gdo;
- int i;
-
- if (!dm || !(gdo = dm->drawObject))
- return;
-
- for (i = 0; i < gdo->totmaterial; i++) {
- if (gdo->materials[i].polys)
- MEM_freeN(gdo->materials[i].polys);
- }
-
- MEM_freeN(gdo->materials);
- if (gdo->vert_points)
- MEM_freeN(gdo->vert_points);
-#ifdef USE_GPU_POINT_LINK
- MEM_freeN(gdo->vert_points_mem);
-#endif
- GPU_buffer_free(gdo->points);
- GPU_buffer_free(gdo->normals);
- GPU_buffer_free(gdo->uv);
- GPU_buffer_free(gdo->uv_tex);
- GPU_buffer_free(gdo->colors);
- GPU_buffer_free(gdo->edges);
- GPU_buffer_free(gdo->uvedges);
- GPU_buffer_free(gdo->triangles);
-
- MEM_freeN(gdo);
- dm->drawObject = NULL;
-}
-
-static GPUBuffer *gpu_try_realloc(GPUBufferPool *pool, GPUBuffer *buffer, size_t size)
-{
- /* try freeing an entry from the pool
- * and reallocating the buffer */
- gpu_buffer_free_intern(buffer);
-
- buffer = NULL;
-
- while (pool->totbuf && !buffer) {
- gpu_buffer_pool_delete_last(pool);
- buffer = gpu_buffer_alloc_intern(size);
- }
-
- return buffer;
-}
-
-static GPUBuffer *gpu_buffer_setup(DerivedMesh *dm, GPUDrawObject *object,
- int type, void *user, GPUBuffer *buffer)
-{
- GPUBufferPool *pool;
- float *varray;
- int *mat_orig_to_new;
- int i;
- const GPUBufferTypeSettings *ts = &gpu_buffer_type_settings[type];
- GLenum target = ts->gl_buffer_type;
- size_t size = gpu_buffer_size_from_type(dm, type);
- GLboolean uploaded;
-
- pool = gpu_get_global_buffer_pool();
-
- BLI_mutex_lock(&buffer_mutex);
-
- /* alloc a GPUBuffer; fall back to legacy mode on failure */
- if (!buffer) {
- if (!(buffer = gpu_buffer_alloc_intern(size))) {
- BLI_mutex_unlock(&buffer_mutex);
- return NULL;
- }
- }
-
- mat_orig_to_new = MEM_mallocN(sizeof(*mat_orig_to_new) * dm->totmat,
- "GPU_buffer_setup.mat_orig_to_new");
- for (i = 0; i < object->totmaterial; i++) {
- /* map from original material index to new
- * GPUBufferMaterial index */
- mat_orig_to_new[object->materials[i].mat_nr] = i;
- }
-
- /* bind the buffer and discard previous data,
- * avoids stalling gpu */
- glBindBuffer(target, buffer->id);
- glBufferData(target, buffer->size, NULL, GL_STATIC_DRAW);
-
- /* attempt to map the buffer */
- if (!(varray = glMapBuffer(target, GL_WRITE_ONLY))) {
- buffer = gpu_try_realloc(pool, buffer, size);
-
- /* allocation still failed; unfortunately we need to exit */
- if (!(buffer && (varray = glMapBuffer(target, GL_WRITE_ONLY)))) {
- if (buffer)
- gpu_buffer_free_intern(buffer);
- BLI_mutex_unlock(&buffer_mutex);
- return NULL;
- }
- }
-
- uploaded = GL_FALSE;
-
- /* attempt to upload the data to the VBO */
- while (uploaded == GL_FALSE) {
- dm->copy_gpu_data(dm, type, varray, mat_orig_to_new, user);
- /* glUnmapBuffer returns GL_FALSE if
- * the data store is corrupted; retry
- * in that case */
- uploaded = glUnmapBuffer(target);
- }
- glBindBuffer(target, 0);
-
- MEM_freeN(mat_orig_to_new);
-
- BLI_mutex_unlock(&buffer_mutex);
-
- return buffer;
-}
-
-/* get the GPUDrawObject buffer associated with a type */
-static GPUBuffer **gpu_drawobject_buffer_from_type(GPUDrawObject *gdo, GPUBufferType type)
-{
- switch (type) {
- case GPU_BUFFER_VERTEX:
- return &gdo->points;
- case GPU_BUFFER_NORMAL:
- return &gdo->normals;
- case GPU_BUFFER_COLOR:
- return &gdo->colors;
- case GPU_BUFFER_UV:
- return &gdo->uv;
- case GPU_BUFFER_UV_TEXPAINT:
- return &gdo->uv_tex;
- case GPU_BUFFER_EDGE:
- return &gdo->edges;
- case GPU_BUFFER_UVEDGE:
- return &gdo->uvedges;
- case GPU_BUFFER_TRIANGLES:
- return &gdo->triangles;
- default:
- return NULL;
- }
-}
-
-/* get the amount of space to allocate for a buffer of a particular type */
-static size_t gpu_buffer_size_from_type(DerivedMesh *dm, GPUBufferType type)
-{
- const int components = gpu_buffer_type_settings[type].num_components;
- switch (type) {
- case GPU_BUFFER_VERTEX:
- return sizeof(float) * components * (dm->drawObject->tot_loop_verts + dm->drawObject->tot_loose_point);
- case GPU_BUFFER_NORMAL:
- return sizeof(short) * components * dm->drawObject->tot_loop_verts;
- case GPU_BUFFER_COLOR:
- return sizeof(char) * components * dm->drawObject->tot_loop_verts;
- case GPU_BUFFER_UV:
- return sizeof(float) * components * dm->drawObject->tot_loop_verts;
- case GPU_BUFFER_UV_TEXPAINT:
- return sizeof(float) * components * dm->drawObject->tot_loop_verts;
- case GPU_BUFFER_EDGE:
- return sizeof(int) * components * dm->drawObject->totedge;
- case GPU_BUFFER_UVEDGE:
- return sizeof(int) * components * dm->drawObject->tot_loop_verts;
- case GPU_BUFFER_TRIANGLES:
- return sizeof(int) * components * dm->drawObject->tot_triangle_point;
- default:
- return -1;
- }
-}
-
-/* call gpu_buffer_setup with settings for a particular type of buffer */
-static GPUBuffer *gpu_buffer_setup_type(DerivedMesh *dm, GPUBufferType type, GPUBuffer *buf)
-{
- void *user_data = NULL;
-
- /* special handling for MCol and UV buffers */
- if (type == GPU_BUFFER_COLOR) {
- if (!(user_data = DM_get_loop_data_layer(dm, dm->drawObject->colType)))
- return NULL;
- }
- else if (ELEM(type, GPU_BUFFER_UV, GPU_BUFFER_UV_TEXPAINT)) {
- if (!DM_get_loop_data_layer(dm, CD_MLOOPUV))
- return NULL;
- }
-
- buf = gpu_buffer_setup(dm, dm->drawObject, type, user_data, buf);
-
- return buf;
-}
-
-/* get the buffer of `type', initializing the GPUDrawObject and
- * buffer if needed */
-static GPUBuffer *gpu_buffer_setup_common(DerivedMesh *dm, GPUBufferType type, bool update)
-{
- GPUBuffer **buf;
-
- if (!dm->drawObject)
- dm->drawObject = dm->gpuObjectNew(dm);
-
- buf = gpu_drawobject_buffer_from_type(dm->drawObject, type);
- if (!(*buf))
- *buf = gpu_buffer_setup_type(dm, type, NULL);
- else if (update)
- *buf = gpu_buffer_setup_type(dm, type, *buf);
-
- return *buf;
-}
-
-void GPU_vertex_setup(DerivedMesh *dm)
-{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX, false))
- return;
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id);
- glVertexPointer(3, GL_FLOAT, 0, 0);
-
- GLStates |= GPU_BUFFER_VERTEX_STATE;
-}
-
-void GPU_normal_setup(DerivedMesh *dm)
-{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_NORMAL, false))
- return;
-
- glEnableClientState(GL_NORMAL_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->normals->id);
- glNormalPointer(GL_SHORT, 4 * sizeof(short), 0);
-
- GLStates |= GPU_BUFFER_NORMAL_STATE;
-}
-
-void GPU_uv_setup(DerivedMesh *dm)
-{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UV, false))
- return;
-
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->uv->id);
- glTexCoordPointer(2, GL_FLOAT, 0, 0);
-
- GLStates |= GPU_BUFFER_TEXCOORD_UNIT_0_STATE;
-}
-
-void GPU_texpaint_uv_setup(DerivedMesh *dm)
-{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UV_TEXPAINT, false))
- return;
-
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->uv_tex->id);
- glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), 0);
- glClientActiveTexture(GL_TEXTURE2);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, 4 * sizeof(float), BUFFER_OFFSET(2 * sizeof(float)));
- glClientActiveTexture(GL_TEXTURE0);
-
- GLStates |= GPU_BUFFER_TEXCOORD_UNIT_0_STATE | GPU_BUFFER_TEXCOORD_UNIT_2_STATE;
-}
-
-
-void GPU_color_setup(DerivedMesh *dm, int colType)
-{
- bool update = false;
-
- if (!dm->drawObject) {
- /* XXX Not really nice, but we need a valid gpu draw object to set the colType...
- * Else we would have to add a new param to gpu_buffer_setup_common. */
- dm->drawObject = dm->gpuObjectNew(dm);
- dm->dirty &= ~DM_DIRTY_MCOL_UPDATE_DRAW;
- dm->drawObject->colType = colType;
- }
- /* In paint mode, dm may stay the same during stroke, however we still want to update colors!
- * Also check in case we changed color type (i.e. which MCol cdlayer we use). */
- else if ((dm->dirty & DM_DIRTY_MCOL_UPDATE_DRAW) || (colType != dm->drawObject->colType)) {
- update = true;
- dm->dirty &= ~DM_DIRTY_MCOL_UPDATE_DRAW;
- dm->drawObject->colType = colType;
- }
-
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_COLOR, update))
- return;
-
- glEnableClientState(GL_COLOR_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->colors->id);
- glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
-
- GLStates |= GPU_BUFFER_COLOR_STATE;
-}
-
-void GPU_buffer_bind_as_color(GPUBuffer *buffer)
-{
- glEnableClientState(GL_COLOR_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, buffer->id);
- glColorPointer(4, GL_UNSIGNED_BYTE, 0, 0);
-
- GLStates |= GPU_BUFFER_COLOR_STATE;
-}
-
-
-void GPU_edge_setup(DerivedMesh *dm)
-{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_EDGE, false))
- return;
-
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_VERTEX, false))
- return;
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->points->id);
- glVertexPointer(3, GL_FLOAT, 0, 0);
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->edges->id);
-
- GLStates |= (GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_ELEMENT_STATE);
-}
-
-void GPU_uvedge_setup(DerivedMesh *dm)
-{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_UVEDGE, false))
- return;
-
- glEnableClientState(GL_VERTEX_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, dm->drawObject->uvedges->id);
- glVertexPointer(2, GL_FLOAT, 0, 0);
-
- GLStates |= GPU_BUFFER_VERTEX_STATE;
-}
-
-void GPU_triangle_setup(struct DerivedMesh *dm)
-{
- if (!gpu_buffer_setup_common(dm, GPU_BUFFER_TRIANGLES, false))
- return;
-
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, dm->drawObject->triangles->id);
- GLStates |= GPU_BUFFER_ELEMENT_STATE;
-}
-
-static int gpu_typesize(int type)
-{
- switch (type) {
- case GL_FLOAT:
- return sizeof(float);
- case GL_INT:
- return sizeof(int);
- case GL_UNSIGNED_INT:
- return sizeof(unsigned int);
- case GL_BYTE:
- return sizeof(char);
- case GL_UNSIGNED_BYTE:
- return sizeof(unsigned char);
- default:
- return 0;
- }
-}
-
-int GPU_attrib_element_size(GPUAttrib data[], int numdata)
-{
- int i, elementsize = 0;
-
- for (i = 0; i < numdata; i++) {
- int typesize = gpu_typesize(data[i].type);
- if (typesize != 0)
- elementsize += typesize * data[i].size;
- }
- return elementsize;
-}
-
-void GPU_interleaved_attrib_setup(GPUBuffer *buffer, GPUAttrib data[], int numdata, int element_size)
-{
- int i;
- int elementsize;
- size_t offset = 0;
-
- for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
- if (attribData[i].index != -1) {
- glDisableVertexAttribArray(attribData[i].index);
- }
- else
- break;
- }
- if (element_size == 0)
- elementsize = GPU_attrib_element_size(data, numdata);
- else
- elementsize = element_size;
-
- glBindBuffer(GL_ARRAY_BUFFER, buffer->id);
-
- for (i = 0; i < numdata; i++) {
- glEnableVertexAttribArray(data[i].index);
- int info = 0;
- if (data[i].type == GL_UNSIGNED_BYTE) {
- info |= GPU_ATTR_INFO_SRGB;
- }
- glUniform1i(data[i].info_index, info);
-
- glVertexAttribPointer(data[i].index, data[i].size, data[i].type,
- GL_TRUE, elementsize, BUFFER_OFFSET(offset));
- offset += data[i].size * gpu_typesize(data[i].type);
-
- attribData[i].index = data[i].index;
- attribData[i].size = data[i].size;
- attribData[i].type = data[i].type;
- }
-
- attribData[numdata].index = -1;
-}
-
-void GPU_interleaved_attrib_unbind(void)
-{
- int i;
- for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
- if (attribData[i].index != -1) {
- glDisableVertexAttribArray(attribData[i].index);
- }
- else
- break;
- }
- attribData[0].index = -1;
-}
-
-void GPU_buffers_unbind(void)
-{
- int i;
-
- if (GLStates & GPU_BUFFER_VERTEX_STATE)
- glDisableClientState(GL_VERTEX_ARRAY);
- if (GLStates & GPU_BUFFER_NORMAL_STATE)
- glDisableClientState(GL_NORMAL_ARRAY);
- if (GLStates & GPU_BUFFER_TEXCOORD_UNIT_0_STATE)
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- if (GLStates & GPU_BUFFER_TEXCOORD_UNIT_2_STATE) {
- glClientActiveTexture(GL_TEXTURE2);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glClientActiveTexture(GL_TEXTURE0);
- }
- if (GLStates & GPU_BUFFER_COLOR_STATE)
- glDisableClientState(GL_COLOR_ARRAY);
- if (GLStates & GPU_BUFFER_ELEMENT_STATE)
- glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
-
- GLStates &= ~(GPU_BUFFER_VERTEX_STATE | GPU_BUFFER_NORMAL_STATE |
- GPU_BUFFER_TEXCOORD_UNIT_0_STATE | GPU_BUFFER_TEXCOORD_UNIT_2_STATE |
- GPU_BUFFER_COLOR_STATE | GPU_BUFFER_ELEMENT_STATE);
-
- for (i = 0; i < MAX_GPU_ATTRIB_DATA; i++) {
- if (attribData[i].index != -1) {
- glDisableVertexAttribArray(attribData[i].index);
- }
- else
- break;
- }
- attribData[0].index = -1;
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-}
-
-void GPU_color_switch(int mode)
-{
- if (mode) {
- if (!(GLStates & GPU_BUFFER_COLOR_STATE))
- glEnableClientState(GL_COLOR_ARRAY);
- GLStates |= GPU_BUFFER_COLOR_STATE;
- }
- else {
- if (GLStates & GPU_BUFFER_COLOR_STATE)
- glDisableClientState(GL_COLOR_ARRAY);
- GLStates &= ~GPU_BUFFER_COLOR_STATE;
- }
-}
-
-static int gpu_binding_type_gl[] =
-{
- GL_ARRAY_BUFFER,
- GL_ELEMENT_ARRAY_BUFFER
-};
-
-void *GPU_buffer_lock(GPUBuffer *buffer, GPUBindingType binding)
-{
- float *varray;
- int bindtypegl;
-
- if (!buffer)
- return 0;
-
- bindtypegl = gpu_binding_type_gl[binding];
- glBindBuffer(bindtypegl, buffer->id);
- varray = glMapBuffer(bindtypegl, GL_WRITE_ONLY);
- return varray;
-}
-
-void *GPU_buffer_lock_stream(GPUBuffer *buffer, GPUBindingType binding)
-{
- float *varray;
- int bindtypegl;
-
- if (!buffer)
- return 0;
-
- bindtypegl = gpu_binding_type_gl[binding];
- glBindBuffer(bindtypegl, buffer->id);
- /* discard previous data, avoid stalling gpu */
- glBufferData(bindtypegl, buffer->size, 0, GL_STREAM_DRAW);
- varray = glMapBuffer(bindtypegl, GL_WRITE_ONLY);
- return varray;
-}
-
-void GPU_buffer_unlock(GPUBuffer *UNUSED(buffer), GPUBindingType binding)
-{
- int bindtypegl = gpu_binding_type_gl[binding];
- /* note: this operation can fail, could return
- * an error code from this function? */
- glUnmapBuffer(bindtypegl);
- glBindBuffer(bindtypegl, 0);
-}
-
-void GPU_buffer_bind(GPUBuffer *buffer, GPUBindingType binding)
-{
- int bindtypegl = gpu_binding_type_gl[binding];
- glBindBuffer(bindtypegl, buffer->id);
-}
-
-void GPU_buffer_unbind(GPUBuffer *UNUSED(buffer), GPUBindingType binding)
-{
- int bindtypegl = gpu_binding_type_gl[binding];
- glBindBuffer(bindtypegl, 0);
-}
-
-/* used for drawing edges */
-void GPU_buffer_draw_elements(GPUBuffer *UNUSED(elements), unsigned int mode, int start, int count)
-{
- glDrawElements(mode, count, GL_UNSIGNED_INT, BUFFER_OFFSET(start * sizeof(unsigned int)));
-}
-
-
/* XXX: the rest of the code in this file is used for optimized PBVH
* drawing and doesn't interact at all with the buffer code above */
-/* Convenience struct for building the VBO. */
-typedef struct {
- float co[3];
- short no[3];
-
- /* inserting this to align the 'color' field to a four-byte
- * boundary; drastically increases viewport performance on my
- * drivers (Gallium/Radeon) --nicholasbishop */
- char pad[2];
-
- unsigned char color[3];
-} VertexBufferFormat;
-
struct GPU_PBVH_Buffers {
- /* opengl buffer handles */
- GPUBuffer *vert_buf, *index_buf, *index_buf_fast;
- GLenum index_type;
+ Gwn_IndexBuf *index_buf, *index_buf_fast;
+ Gwn_VertBuf *vert_buf;
- int *baseelemarray;
- void **baseindex;
+ Gwn_Batch *triangles;
+ Gwn_Batch *triangles_fast;
/* mesh pointers in case buffer allocation fails */
const MPoly *mpoly;
@@ -995,10 +108,73 @@ struct GPU_PBVH_Buffers {
bool show_diffuse_color;
bool show_mask;
- bool use_matcaps;
float diffuse_color[4];
};
+static struct {
+ uint pos, nor, col;
+} g_vbo_id = {0};
+
+static void gpu_material_diffuse_get(int UNUSED(nr), float diff[4])
+{
+ /* TODO: sculpt diffuse color option not supported in 2.8 yet. */
+ diff[0] = 0.8f;
+ diff[1] = 0.8f;
+ diff[2] = 0.8f;
+ diff[3] = 1.0f;
+}
+
+/* Allocates a non-initialized buffer to be sent to GPU.
+ * Return is false it indicates that the memory map failed. */
+static bool gpu_pbvh_vert_buf_data_set(GPU_PBVH_Buffers *buffers, unsigned int vert_ct)
+{
+ if (buffers->vert_buf == NULL) {
+ /* Initialize vertex buffer */
+ /* match 'VertexBufferFormat' */
+
+ static Gwn_VertFormat format = {0};
+ if (format.attrib_ct == 0) {
+ g_vbo_id.pos = GWN_vertformat_attr_add(&format, "pos", GWN_COMP_F32, 3, GWN_FETCH_FLOAT);
+ g_vbo_id.nor = GWN_vertformat_attr_add(&format, "nor", GWN_COMP_I16, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ g_vbo_id.col = GWN_vertformat_attr_add(&format, "color", GWN_COMP_U8, 3, GWN_FETCH_INT_TO_FLOAT_UNIT);
+ }
+#if 0
+ buffers->vert_buf = GWN_vertbuf_create_with_format_ex(&format, GWN_USAGE_DYNAMIC);
+ GWN_vertbuf_data_alloc(buffers->vert_buf, vert_ct);
+ }
+ else if (vert_ct != buffers->vert_buf->vertex_ct) {
+ GWN_vertbuf_data_resize(buffers->vert_buf, vert_ct);
+ }
+#else
+ buffers->vert_buf = GWN_vertbuf_create_with_format_ex(&format, GWN_USAGE_STATIC);
+ }
+ GWN_vertbuf_data_alloc(buffers->vert_buf, vert_ct);
+#endif
+ return buffers->vert_buf->data != NULL;
+}
+
+static void gpu_pbvh_batch_init(GPU_PBVH_Buffers *buffers)
+{
+ /* force flushing to the GPU */
+ if (buffers->vert_buf->data) {
+ GWN_vertbuf_use(buffers->vert_buf);
+ }
+
+ if (buffers->triangles == NULL) {
+ buffers->triangles = GWN_batch_create(
+ GWN_PRIM_TRIS, buffers->vert_buf,
+ /* can be NULL */
+ buffers->index_buf);
+ }
+
+ if ((buffers->triangles_fast == NULL) && buffers->index_buf_fast) {
+ buffers->triangles_fast = GWN_batch_create(
+ GWN_PRIM_TRIS, buffers->vert_buf,
+ /* can be NULL */
+ buffers->index_buf_fast);
+ }
+}
+
static float gpu_color_from_mask(float mask)
{
return 1.0f - mask * 0.75f;
@@ -1040,25 +216,20 @@ void GPU_pbvh_mesh_buffers_update(
{
const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
- VertexBufferFormat *vert_data;
- int i;
buffers->vmask = vmask;
buffers->show_diffuse_color = show_diffuse_color;
buffers->show_mask = show_mask;
- buffers->use_matcaps = GPU_material_use_matcaps_get();
{
int totelem = (buffers->smooth ? totvert : (buffers->tot_tri * 3));
float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 0.8f};
- if (buffers->use_matcaps)
- diffuse_color[0] = diffuse_color[1] = diffuse_color[2] = 1.0;
- else if (show_diffuse_color) {
+ if (show_diffuse_color) {
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[0]];
const MPoly *mp = &buffers->mpoly[lt->poly];
- GPU_material_diffuse_get(mp->mat_nr + 1, diffuse_color);
+ gpu_material_diffuse_get(mp->mat_nr + 1, diffuse_color);
}
copy_v4_v4(buffers->diffuse_color, diffuse_color);
@@ -1067,35 +238,29 @@ void GPU_pbvh_mesh_buffers_update(
rgba_float_to_uchar(diffuse_color_ub, diffuse_color);
/* Build VBO */
- if (buffers->vert_buf)
- GPU_buffer_free(buffers->vert_buf);
- buffers->vert_buf = GPU_buffer_alloc(sizeof(VertexBufferFormat) * totelem);
- vert_data = GPU_buffer_lock(buffers->vert_buf, GPU_BINDING_ARRAY);
-
- if (vert_data) {
+ if (gpu_pbvh_vert_buf_data_set(buffers, totelem)) {
/* Vertex data is shared if smooth-shaded, but separate
* copies are made for flat shading because normals
* shouldn't be shared. */
if (buffers->smooth) {
- for (i = 0; i < totvert; ++i) {
+ for (uint i = 0; i < totvert; ++i) {
const MVert *v = &mvert[vert_indices[i]];
- VertexBufferFormat *out = vert_data + i;
-
- copy_v3_v3(out->co, v->co);
- memcpy(out->no, v->no, sizeof(short) * 3);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, i, v->co);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, i, v->no);
}
- for (i = 0; i < buffers->face_indices_len; i++) {
+ for (uint i = 0; i < buffers->face_indices_len; i++) {
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
for (uint j = 0; j < 3; j++) {
- VertexBufferFormat *out = vert_data + face_vert_indices[i][j];
-
+ int vidx = face_vert_indices[i][j];
if (vmask && show_mask) {
- uint v_index = buffers->mloop[lt->tri[j]].v;
- gpu_color_from_mask_copy(vmask[v_index], diffuse_color, out->color);
+ int v_index = buffers->mloop[lt->tri[j]].v;
+ uchar color_ub[3];
+ gpu_color_from_mask_copy(vmask[v_index], diffuse_color, color_ub);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vidx, color_ub);
}
else {
- copy_v3_v3_uchar(out->color, diffuse_color_ub);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vidx, diffuse_color_ub);
}
}
}
@@ -1104,8 +269,9 @@ void GPU_pbvh_mesh_buffers_update(
/* calculate normal for each polygon only once */
unsigned int mpoly_prev = UINT_MAX;
short no[3];
+ int vbo_index = 0;
- for (i = 0; i < buffers->face_indices_len; ++i) {
+ for (uint i = 0; i < buffers->face_indices_len; i++) {
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[i]];
const unsigned int vtri[3] = {
buffers->mloop[lt->tri[0]].v,
@@ -1136,22 +302,17 @@ void GPU_pbvh_mesh_buffers_update(
for (uint j = 0; j < 3; j++) {
const MVert *v = &mvert[vtri[j]];
- VertexBufferFormat *out = vert_data;
- copy_v3_v3(out->co, v->co);
- copy_v3_v3_short(out->no, no);
- copy_v3_v3_uchar(out->color, color_ub);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, vbo_index, v->co);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, vbo_index, no);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
- vert_data++;
+ vbo_index++;
}
}
}
- GPU_buffer_unlock(buffers->vert_buf, GPU_BINDING_ARRAY);
- }
- else {
- GPU_buffer_free(buffers->vert_buf);
- buffers->vert_buf = NULL;
+ gpu_pbvh_batch_init(buffers);
}
}
@@ -1166,16 +327,20 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(
const int face_indices_len)
{
GPU_PBVH_Buffers *buffers;
- unsigned short *tri_data;
- int i, j, tottri;
+ int i, tottri;
buffers = MEM_callocN(sizeof(GPU_PBVH_Buffers), "GPU_Buffers");
- buffers->index_type = GL_UNSIGNED_SHORT;
+
+ /* smooth or flat for all */
+#if 0
buffers->smooth = mpoly[looptri[face_indices[0]].poly].flag & ME_SMOOTH;
+#else
+ /* for DrawManager we dont support mixed smooth/flat */
+ buffers->smooth = (mpoly[0].flag & ME_SMOOTH) != 0;
+#endif
buffers->show_diffuse_color = false;
buffers->show_mask = true;
- buffers->use_matcaps = false;
/* Count the number of visible triangles */
for (i = 0, tottri = 0; i < face_indices_len; ++i) {
@@ -1200,35 +365,28 @@ GPU_PBVH_Buffers *GPU_pbvh_mesh_buffers_build(
* shading requires separate vertex normals so an index buffer is
* can't be used there. */
if (buffers->smooth) {
- buffers->index_buf = GPU_buffer_alloc(sizeof(unsigned short) * tottri * 3);
- buffers->is_index_buf_global = false;
- }
-
- if (buffers->index_buf) {
/* Fill the triangle buffer */
- tri_data = GPU_buffer_lock(buffers->index_buf, GPU_BINDING_INDEX);
- if (tri_data) {
- for (i = 0; i < face_indices_len; ++i) {
- const MLoopTri *lt = &looptri[face_indices[i]];
-
- /* Skip hidden faces */
- if (paint_is_face_hidden(lt, mvert, mloop))
- continue;
-
- for (j = 0; j < 3; ++j) {
- *tri_data = face_vert_indices[i][j];
- tri_data++;
- }
- }
- GPU_buffer_unlock(buffers->index_buf, GPU_BINDING_INDEX);
+ buffers->index_buf = NULL;
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tottri, INT_MAX);
+
+ for (i = 0; i < face_indices_len; ++i) {
+ const MLoopTri *lt = &looptri[face_indices[i]];
+
+ /* Skip hidden faces */
+ if (paint_is_face_hidden(lt, mvert, mloop))
+ continue;
+
+ GWN_indexbuf_add_tri_verts(&elb, UNPACK3(face_vert_indices[i]));
}
- else {
- if (!buffers->is_index_buf_global) {
- GPU_buffer_free(buffers->index_buf);
- }
- buffers->index_buf = NULL;
- buffers->is_index_buf_global = false;
+ buffers->index_buf = GWN_indexbuf_build(&elb);
+ }
+ else {
+ if (!buffers->is_index_buf_global) {
+ GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf);
}
+ buffers->index_buf = NULL;
+ buffers->is_index_buf_global = false;
}
buffers->tot_tri = tottri;
@@ -1251,61 +409,59 @@ void GPU_pbvh_grid_buffers_update(
{
const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
- VertexBufferFormat *vert_data;
int i, j, k, x, y;
buffers->show_diffuse_color = show_diffuse_color;
buffers->show_mask = show_mask;
- buffers->use_matcaps = GPU_material_use_matcaps_get();
buffers->smooth = grid_flag_mats[grid_indices[0]].flag & ME_SMOOTH;
/* Build VBO */
- if (buffers->vert_buf) {
+ if (buffers->index_buf) {
const int has_mask = key->has_mask;
float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f};
- if (buffers->use_matcaps)
- diffuse_color[0] = diffuse_color[1] = diffuse_color[2] = 1.0;
- else if (show_diffuse_color) {
+ if (show_diffuse_color) {
const DMFlagMat *flags = &grid_flag_mats[grid_indices[0]];
- GPU_material_diffuse_get(flags->mat_nr + 1, diffuse_color);
+ gpu_material_diffuse_get(flags->mat_nr + 1, diffuse_color);
}
copy_v4_v4(buffers->diffuse_color, diffuse_color);
- vert_data = GPU_buffer_lock_stream(buffers->vert_buf, GPU_BINDING_ARRAY);
- if (vert_data) {
+ uint vbo_index_offset = 0;
+ /* Build VBO */
+ if (gpu_pbvh_vert_buf_data_set(buffers, totgrid * key->grid_area)) {
for (i = 0; i < totgrid; ++i) {
- VertexBufferFormat *vd = vert_data;
CCGElem *grid = grids[grid_indices[i]];
+ int vbo_index = vbo_index_offset;
for (y = 0; y < key->grid_size; y++) {
for (x = 0; x < key->grid_size; x++) {
CCGElem *elem = CCG_grid_elem(key, grid, x, y);
-
- copy_v3_v3(vd->co, CCG_elem_co(key, elem));
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.pos, vbo_index, CCG_elem_co(key, elem));
+
if (buffers->smooth) {
- normal_float_to_short_v3(vd->no, CCG_elem_no(key, elem));
+ short no_short[3];
+ normal_float_to_short_v3(no_short, CCG_elem_no(key, elem));
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, vbo_index, no_short);
if (has_mask) {
+ uchar color_ub[3];
if (show_mask) {
gpu_color_from_mask_copy(*CCG_elem_mask(key, elem),
- diffuse_color, vd->color);
+ diffuse_color, color_ub);
}
else {
- unit_float_to_uchar_clamp_v3(vd->color, diffuse_color);
+ unit_float_to_uchar_clamp_v3(color_ub, diffuse_color);
}
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
}
}
- vd++;
+ vbo_index += 1;
}
}
if (!buffers->smooth) {
- /* for flat shading, recalc normals and set the last vertex of
- * each triangle in the index buffer to have the flat normal as
- * that is what opengl will use */
for (j = 0; j < key->grid_size - 1; j++) {
for (k = 0; k < key->grid_size - 1; k++) {
CCGElem *elems[4] = {
@@ -1322,10 +478,13 @@ void GPU_pbvh_grid_buffers_update(
CCG_elem_co(key, elems[2]),
CCG_elem_co(key, elems[3]));
- vd = vert_data + (j + 1) * key->grid_size + k;
- normal_float_to_short_v3(vd->no, fno);
+ vbo_index = vbo_index_offset + ((j + 1) * key->grid_size + k);
+ short no_short[3];
+ normal_float_to_short_v3(no_short, fno);
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.nor, vbo_index, no_short);
if (has_mask) {
+ uchar color_ub[3];
if (show_mask) {
gpu_color_from_mask_quad_copy(key,
elems[0],
@@ -1333,24 +492,21 @@ void GPU_pbvh_grid_buffers_update(
elems[2],
elems[3],
diffuse_color,
- vd->color);
+ color_ub);
}
else {
- unit_float_to_uchar_clamp_v3(vd->color, diffuse_color);
+ unit_float_to_uchar_clamp_v3(color_ub, diffuse_color);
}
+ GWN_vertbuf_attr_set(buffers->vert_buf, g_vbo_id.col, vbo_index, color_ub);
}
}
}
}
- vert_data += key->grid_area;
+ vbo_index_offset += key->grid_area;
}
- GPU_buffer_unlock(buffers->vert_buf, GPU_BINDING_ARRAY);
- }
- else {
- GPU_buffer_free(buffers->vert_buf);
- buffers->vert_buf = NULL;
+ gpu_pbvh_batch_init(buffers);
}
}
@@ -1365,57 +521,54 @@ void GPU_pbvh_grid_buffers_update(
/* Build the element array buffer of grid indices using either
* unsigned shorts or unsigned ints. */
-#define FILL_QUAD_BUFFER(type_, tot_quad_, buffer_) \
+#define FILL_QUAD_BUFFER(max_vert_, tot_quad_, buffer_) \
{ \
- type_ *tri_data; \
int offset = 0; \
int i, j, k; \
- buffer_ = GPU_buffer_alloc(sizeof(type_) * (tot_quad_) * 6); \
+ \
+ Gwn_IndexBufBuilder elb; \
+ GWN_indexbuf_init( \
+ &elb, GWN_PRIM_TRIS, tot_quad_ * 2, max_vert_); \
\
/* Fill the buffer */ \
- tri_data = GPU_buffer_lock(buffer_, GPU_BINDING_INDEX); \
- if (tri_data) { \
- for (i = 0; i < totgrid; ++i) { \
- BLI_bitmap *gh = NULL; \
- if (grid_hidden) \
- gh = grid_hidden[(grid_indices)[i]]; \
+ for (i = 0; i < totgrid; ++i) { \
+ BLI_bitmap *gh = NULL; \
+ if (grid_hidden) \
+ gh = grid_hidden[(grid_indices)[i]]; \
\
- for (j = 0; j < gridsize - 1; ++j) { \
- for (k = 0; k < gridsize - 1; ++k) { \
- /* Skip hidden grid face */ \
- if (gh && \
- paint_is_grid_face_hidden(gh, \
- gridsize, k, j)) \
- continue; \
- \
- *(tri_data++) = offset + j * gridsize + k + 1; \
- *(tri_data++) = offset + j * gridsize + k; \
- *(tri_data++) = offset + (j + 1) * gridsize + k; \
- \
- *(tri_data++) = offset + (j + 1) * gridsize + k + 1; \
- *(tri_data++) = offset + j * gridsize + k + 1; \
- *(tri_data++) = offset + (j + 1) * gridsize + k; \
- } \
- } \
- \
- offset += gridsize * gridsize; \
+ for (j = 0; j < gridsize - 1; ++j) { \
+ for (k = 0; k < gridsize - 1; ++k) { \
+ /* Skip hidden grid face */ \
+ if (gh && paint_is_grid_face_hidden( \
+ gh, gridsize, k, j)) \
+ { \
+ continue; \
+ } \
+ GWN_indexbuf_add_generic_vert(&elb, offset + j * gridsize + k + 1); \
+ GWN_indexbuf_add_generic_vert(&elb, offset + j * gridsize + k); \
+ GWN_indexbuf_add_generic_vert(&elb, offset + (j + 1) * gridsize + k); \
+ \
+ GWN_indexbuf_add_generic_vert(&elb, offset + (j + 1) * gridsize + k + 1); \
+ GWN_indexbuf_add_generic_vert(&elb, offset + j * gridsize + k + 1); \
+ GWN_indexbuf_add_generic_vert(&elb, offset + (j + 1) * gridsize + k); \
+ } \
} \
- GPU_buffer_unlock(buffer_, GPU_BINDING_INDEX); \
- } \
- else { \
- GPU_buffer_free(buffer_); \
- (buffer_) = NULL; \
+ \
+ offset += gridsize * gridsize; \
} \
+ buffer_ = GWN_indexbuf_build(&elb); \
} (void)0
/* end FILL_QUAD_BUFFER */
-static GPUBuffer *gpu_get_grid_buffer(
- int gridsize, GLenum *index_type, unsigned *totquad, GridCommonGPUBuffer **grid_common_gpu_buffer)
+static Gwn_IndexBuf *gpu_get_grid_buffer(
+ int gridsize, unsigned *totquad, GridCommonGPUBuffer **grid_common_gpu_buffer,
+ /* remove this arg when gawain gets base-vertex support! */
+ int totgrid)
{
/* used in the FILL_QUAD_BUFFER macro */
BLI_bitmap * const *grid_hidden = NULL;
const int *grid_indices = NULL;
- int totgrid = 1;
+ // int totgrid = 1;
GridCommonGPUBuffer *gridbuff = *grid_common_gpu_buffer;
@@ -1423,65 +576,48 @@ static GPUBuffer *gpu_get_grid_buffer(
*grid_common_gpu_buffer = gridbuff = MEM_mallocN(sizeof(GridCommonGPUBuffer), __func__);
gridbuff->mres_buffer = NULL;
gridbuff->mres_prev_gridsize = -1;
- gridbuff->mres_prev_index_type = 0;
gridbuff->mres_prev_totquad = 0;
}
/* VBO is already built */
if (gridbuff->mres_buffer && gridbuff->mres_prev_gridsize == gridsize) {
- *index_type = gridbuff->mres_prev_index_type;
*totquad = gridbuff->mres_prev_totquad;
return gridbuff->mres_buffer;
}
/* we can't reuse old, delete the existing buffer */
else if (gridbuff->mres_buffer) {
- GPU_buffer_free(gridbuff->mres_buffer);
+ GWN_indexbuf_discard(gridbuff->mres_buffer);
+ gridbuff->mres_buffer = NULL;
}
/* Build new VBO */
- *totquad = (gridsize - 1) * (gridsize - 1);
+ *totquad = (gridsize - 1) * (gridsize - 1) * totgrid;
+ int max_vert = gridsize * gridsize * totgrid;
- if (gridsize * gridsize < USHRT_MAX) {
- *index_type = GL_UNSIGNED_SHORT;
- FILL_QUAD_BUFFER(unsigned short, *totquad, gridbuff->mres_buffer);
- }
- else {
- *index_type = GL_UNSIGNED_INT;
- FILL_QUAD_BUFFER(unsigned int, *totquad, gridbuff->mres_buffer);
- }
+ FILL_QUAD_BUFFER(max_vert, *totquad, gridbuff->mres_buffer);
gridbuff->mres_prev_gridsize = gridsize;
- gridbuff->mres_prev_index_type = *index_type;
gridbuff->mres_prev_totquad = *totquad;
return gridbuff->mres_buffer;
}
-#define FILL_FAST_BUFFER(type_) \
+#define FILL_FAST_BUFFER() \
{ \
- type_ *buffer; \
- buffers->index_buf_fast = GPU_buffer_alloc(sizeof(type_) * 6 * totgrid); \
- buffer = GPU_buffer_lock(buffers->index_buf_fast, GPU_BINDING_INDEX); \
- if (buffer) { \
- int i; \
- for (i = 0; i < totgrid; i++) { \
- int currentquad = i * 6; \
- buffer[currentquad] = i * gridsize * gridsize + gridsize - 1; \
- buffer[currentquad + 1] = i * gridsize * gridsize; \
- buffer[currentquad + 2] = (i + 1) * gridsize * gridsize - gridsize; \
- buffer[currentquad + 3] = (i + 1) * gridsize * gridsize - 1; \
- buffer[currentquad + 4] = i * gridsize * gridsize + gridsize - 1; \
- buffer[currentquad + 5] = (i + 1) * gridsize * gridsize - gridsize; \
- } \
- GPU_buffer_unlock(buffers->index_buf_fast, GPU_BINDING_INDEX); \
- } \
- else { \
- GPU_buffer_free(buffers->index_buf_fast); \
- buffers->index_buf_fast = NULL; \
+ Gwn_IndexBufBuilder elb; \
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, 6 * totgrid, INT_MAX); \
+ for (int i = 0; i < totgrid; i++) { \
+ GWN_indexbuf_add_generic_vert(&elb, i * gridsize * gridsize + gridsize - 1); \
+ GWN_indexbuf_add_generic_vert(&elb, i * gridsize * gridsize); \
+ GWN_indexbuf_add_generic_vert(&elb, (i + 1) * gridsize * gridsize - gridsize); \
+ GWN_indexbuf_add_generic_vert(&elb, (i + 1) * gridsize * gridsize - 1); \
+ GWN_indexbuf_add_generic_vert(&elb, i * gridsize * gridsize + gridsize - 1); \
+ GWN_indexbuf_add_generic_vert(&elb, (i + 1) * gridsize * gridsize - gridsize); \
} \
+ buffers->index_buf_fast = GWN_indexbuf_build(&elb); \
} (void)0
GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(
- int *grid_indices, int totgrid, BLI_bitmap **grid_hidden, int gridsize, const CCGKey *key,
+ int *grid_indices, int totgrid, BLI_bitmap **grid_hidden, int gridsize, const CCGKey *UNUSED(key),
GridCommonGPUBuffer **grid_common_gpu_buffer)
{
GPU_PBVH_Buffers *buffers;
@@ -1494,7 +630,6 @@ GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(
buffers->show_diffuse_color = false;
buffers->show_mask = true;
- buffers->use_matcaps = false;
/* Count the number of quads */
totquad = BKE_pbvh_count_grid_quads(grid_hidden, grid_indices, totgrid, gridsize);
@@ -1504,39 +639,26 @@ GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(
return buffers;
/* create and fill indices of the fast buffer too */
- if (totgrid * gridsize * gridsize < USHRT_MAX) {
- FILL_FAST_BUFFER(unsigned short);
- }
- else {
- FILL_FAST_BUFFER(unsigned int);
- }
+ FILL_FAST_BUFFER();
if (totquad == fully_visible_totquad) {
buffers->index_buf = gpu_get_grid_buffer(
- gridsize, &buffers->index_type, &buffers->tot_quad, grid_common_gpu_buffer);
+ gridsize, &buffers->tot_quad, grid_common_gpu_buffer, totgrid);
buffers->has_hidden = false;
buffers->is_index_buf_global = true;
}
else {
+ uint max_vert = totgrid * gridsize * gridsize;
buffers->tot_quad = totquad;
- if (totgrid * gridsize * gridsize < USHRT_MAX) {
- buffers->index_type = GL_UNSIGNED_SHORT;
- FILL_QUAD_BUFFER(unsigned short, totquad, buffers->index_buf);
- }
- else {
- buffers->index_type = GL_UNSIGNED_INT;
- FILL_QUAD_BUFFER(unsigned int, totquad, buffers->index_buf);
- }
+ FILL_QUAD_BUFFER(max_vert, totquad, buffers->index_buf);
- buffers->has_hidden = true;
+ buffers->has_hidden = false;
buffers->is_index_buf_global = false;
}
+#ifdef USE_BASE_ELEM
/* Build coord/normal VBO */
- if (buffers->index_buf)
- buffers->vert_buf = GPU_buffer_alloc(sizeof(VertexBufferFormat) * totgrid * key->grid_area);
-
if (GLEW_ARB_draw_elements_base_vertex /* 3.2 */) {
int i;
buffers->baseelemarray = MEM_mallocN(sizeof(int) * totgrid * 2, "GPU_PBVH_Buffers.baseelemarray");
@@ -1547,6 +669,7 @@ GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(
buffers->baseindex[i] = NULL;
}
}
+#endif
return buffers;
}
@@ -1559,32 +682,44 @@ GPU_PBVH_Buffers *GPU_pbvh_grid_buffers_build(
* index '*v_index' in the 'vert_data' array and '*v_index' is
* incremented.
*/
-static void gpu_bmesh_vert_to_buffer_copy(BMVert *v,
- VertexBufferFormat *vert_data,
- int *v_index,
- const float fno[3],
- const float *fmask,
- const int cd_vert_mask_offset,
- const float diffuse_color[4],
- const bool show_mask)
+static void gpu_bmesh_vert_to_buffer_copy__gwn(
+ BMVert *v,
+ Gwn_VertBuf *vert_buf,
+ int *v_index,
+ const float fno[3],
+ const float *fmask,
+ const int cd_vert_mask_offset,
+ const float diffuse_color[4],
+ const bool show_mask)
{
if (!BM_elem_flag_test(v, BM_ELEM_HIDDEN)) {
- VertexBufferFormat *vd = &vert_data[*v_index];
/* Set coord, normal, and mask */
- copy_v3_v3(vd->co, v->co);
- normal_float_to_short_v3(vd->no, fno ? fno : v->no);
+ GWN_vertbuf_attr_set(vert_buf, g_vbo_id.pos, *v_index, v->co);
- float effective_mask;
- if (show_mask) {
- effective_mask = fmask ? *fmask
- : BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset);
- }
- else {
- effective_mask = 0.0f;
+ {
+ short no_short[3];
+ normal_float_to_short_v3(no_short, fno ? fno : v->no);
+ GWN_vertbuf_attr_set(vert_buf, g_vbo_id.nor, *v_index, no_short);
}
- gpu_color_from_mask_copy(effective_mask, diffuse_color, vd->color);
+ {
+ uchar color_ub[3];
+ float effective_mask;
+ if (show_mask) {
+ effective_mask = fmask ? *fmask
+ : BM_ELEM_CD_GET_FLOAT(v, cd_vert_mask_offset);
+ }
+ else {
+ effective_mask = 0.0f;
+ }
+
+ gpu_color_from_mask_copy(
+ effective_mask,
+ diffuse_color,
+ color_ub);
+ GWN_vertbuf_attr_set(vert_buf, g_vbo_id.col, *v_index, color_ub);
+ }
/* Assign index for use in the triangle index buffer */
/* note: caller must set: bm->elem_index_dirty |= BM_VERT; */
@@ -1643,8 +778,6 @@ void GPU_pbvh_bmesh_buffers_update(
{
const bool show_diffuse_color = (update_flags & GPU_PBVH_BUFFERS_SHOW_DIFFUSE_COLOR) != 0;
const bool show_mask = (update_flags & GPU_PBVH_BUFFERS_SHOW_MASK) != 0;
- VertexBufferFormat *vert_data;
- void *tri_data;
int tottri, totvert, maxvert = 0;
float diffuse_color[4] = {0.8f, 0.8f, 0.8f, 1.0f};
@@ -1653,7 +786,6 @@ void GPU_pbvh_bmesh_buffers_update(
buffers->show_diffuse_color = show_diffuse_color;
buffers->show_mask = show_mask;
- buffers->use_matcaps = GPU_material_use_matcaps_get();
/* Count visible triangles */
tottri = gpu_bmesh_face_visible_count(bm_faces);
@@ -1670,27 +802,19 @@ void GPU_pbvh_bmesh_buffers_update(
return;
}
- if (buffers->use_matcaps)
- diffuse_color[0] = diffuse_color[1] = diffuse_color[2] = 1.0;
- else if (show_diffuse_color) {
+ if (show_diffuse_color) {
/* due to dynamic nature of dyntopo, only get first material */
GSetIterator gs_iter;
BMFace *f;
BLI_gsetIterator_init(&gs_iter, bm_faces);
f = BLI_gsetIterator_getKey(&gs_iter);
- GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color);
+ gpu_material_diffuse_get(f->mat_nr + 1, diffuse_color);
}
copy_v4_v4(buffers->diffuse_color, diffuse_color);
- /* Initialize vertex buffer */
- if (buffers->vert_buf)
- GPU_buffer_free(buffers->vert_buf);
- buffers->vert_buf = GPU_buffer_alloc(sizeof(VertexBufferFormat) * totvert);
-
/* Fill vertex buffer */
- vert_data = GPU_buffer_lock(buffers->vert_buf, GPU_BINDING_ARRAY);
- if (vert_data) {
+ if (gpu_pbvh_vert_buf_data_set(buffers, totvert)) {
int v_index = 0;
if (buffers->smooth) {
@@ -1701,17 +825,19 @@ void GPU_pbvh_bmesh_buffers_update(
bm->elem_index_dirty |= BM_VERT;
GSET_ITER (gs_iter, bm_unique_verts) {
- gpu_bmesh_vert_to_buffer_copy(BLI_gsetIterator_getKey(&gs_iter),
- vert_data, &v_index, NULL, NULL,
- cd_vert_mask_offset, diffuse_color,
- show_mask);
+ gpu_bmesh_vert_to_buffer_copy__gwn(
+ BLI_gsetIterator_getKey(&gs_iter),
+ buffers->vert_buf, &v_index, NULL, NULL,
+ cd_vert_mask_offset, diffuse_color,
+ show_mask);
}
GSET_ITER (gs_iter, bm_other_verts) {
- gpu_bmesh_vert_to_buffer_copy(BLI_gsetIterator_getKey(&gs_iter),
- vert_data, &v_index, NULL, NULL,
- cd_vert_mask_offset, diffuse_color,
- show_mask);
+ gpu_bmesh_vert_to_buffer_copy__gwn(
+ BLI_gsetIterator_getKey(&gs_iter),
+ buffers->vert_buf, &v_index, NULL, NULL,
+ cd_vert_mask_offset, diffuse_color,
+ show_mask);
}
maxvert = v_index;
@@ -1741,10 +867,11 @@ void GPU_pbvh_bmesh_buffers_update(
fmask /= 3.0f;
for (i = 0; i < 3; i++) {
- gpu_bmesh_vert_to_buffer_copy(v[i], vert_data,
- &v_index, f->no, &fmask,
- cd_vert_mask_offset, diffuse_color,
- show_mask);
+ gpu_bmesh_vert_to_buffer_copy__gwn(
+ v[i], buffers->vert_buf,
+ &v_index, f->no, &fmask,
+ cd_vert_mask_offset, diffuse_color,
+ show_mask);
}
}
}
@@ -1752,32 +879,26 @@ void GPU_pbvh_bmesh_buffers_update(
buffers->tot_tri = tottri;
}
- GPU_buffer_unlock(buffers->vert_buf, GPU_BINDING_ARRAY);
-
/* gpu_bmesh_vert_to_buffer_copy sets dirty index values */
bm->elem_index_dirty |= BM_VERT;
}
else {
/* Memory map failed */
- GPU_buffer_free(buffers->vert_buf);
- buffers->vert_buf = NULL;
return;
}
if (buffers->smooth) {
- const int use_short = (maxvert < USHRT_MAX);
+ /* Fill the triangle buffer */
+ buffers->index_buf = NULL;
+ Gwn_IndexBufBuilder elb;
+ GWN_indexbuf_init(&elb, GWN_PRIM_TRIS, tottri, maxvert);
/* Initialize triangle index buffer */
- if (buffers->index_buf && !buffers->is_index_buf_global)
- GPU_buffer_free(buffers->index_buf);
buffers->is_index_buf_global = false;
- buffers->index_buf = GPU_buffer_alloc((use_short ?
- sizeof(unsigned short) :
- sizeof(unsigned int)) * 3 * tottri);
/* Fill triangle index buffer */
- tri_data = GPU_buffer_lock(buffers->index_buf, GPU_BINDING_INDEX);
- if (tri_data) {
+
+ {
GSetIterator gs_iter;
GSET_ITER (gs_iter, bm_faces) {
@@ -1789,46 +910,30 @@ void GPU_pbvh_bmesh_buffers_update(
l_iter = l_first = BM_FACE_FIRST_LOOP(f);
do {
- BMVert *v = l_iter->v;
- if (use_short) {
- unsigned short *elem = tri_data;
- (*elem) = BM_elem_index_get(v);
- elem++;
- tri_data = elem;
- }
- else {
- unsigned int *elem = tri_data;
- (*elem) = BM_elem_index_get(v);
- elem++;
- tri_data = elem;
- }
+ GWN_indexbuf_add_generic_vert(&elb, BM_elem_index_get(l_iter->v));
} while ((l_iter = l_iter->next) != l_first);
}
}
- GPU_buffer_unlock(buffers->index_buf, GPU_BINDING_INDEX);
-
buffers->tot_tri = tottri;
- buffers->index_type = (use_short ?
- GL_UNSIGNED_SHORT :
- GL_UNSIGNED_INT);
- }
- else {
- /* Memory map failed */
- if (!buffers->is_index_buf_global) {
- GPU_buffer_free(buffers->index_buf);
+
+ if (buffers->index_buf == NULL) {
+ buffers->index_buf = GWN_indexbuf_build(&elb);
+ }
+ else {
+ GWN_indexbuf_build_in_place(&elb, buffers->index_buf);
}
- buffers->index_buf = NULL;
- buffers->is_index_buf_global = false;
}
}
else if (buffers->index_buf) {
if (!buffers->is_index_buf_global) {
- GPU_buffer_free(buffers->index_buf);
+ GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf);
}
buffers->index_buf = NULL;
buffers->is_index_buf_global = false;
}
+
+ gpu_pbvh_batch_init(buffers);
}
GPU_PBVH_Buffers *GPU_pbvh_bmesh_buffers_build(bool smooth_shading)
@@ -1840,172 +945,31 @@ GPU_PBVH_Buffers *GPU_pbvh_bmesh_buffers_build(bool smooth_shading)
buffers->smooth = smooth_shading;
buffers->show_diffuse_color = false;
buffers->show_mask = true;
- buffers->use_matcaps = false;
return buffers;
}
-void GPU_pbvh_buffers_draw(
- GPU_PBVH_Buffers *buffers, DMSetMaterial setMaterial,
- bool wireframe, bool fast)
+Gwn_Batch *GPU_pbvh_buffers_batch_get(GPU_PBVH_Buffers *buffers, bool fast)
{
- bool do_fast = fast && buffers->index_buf_fast;
- /* sets material from the first face, to solve properly face would need to
- * be sorted in buckets by materials */
- if (setMaterial) {
- if (buffers->face_indices_len) {
- const MLoopTri *lt = &buffers->looptri[buffers->face_indices[0]];
- const MPoly *mp = &buffers->mpoly[lt->poly];
- if (!setMaterial(mp->mat_nr + 1, NULL))
- return;
- }
- else if (buffers->totgrid) {
- const DMFlagMat *f = &buffers->grid_flag_mats[buffers->grid_indices[0]];
- if (!setMaterial(f->mat_nr + 1, NULL))
- return;
- }
- else {
- if (!setMaterial(1, NULL))
- return;
- }
- }
-
- if (buffers->vert_buf) {
- char *base = NULL;
- char *index_base = NULL;
- /* weak inspection of bound options, should not be necessary ideally */
- const int bound_options_old = GPU_basic_shader_bound_options();
- int bound_options_new = 0;
- glEnableClientState(GL_VERTEX_ARRAY);
- if (!wireframe) {
- glEnableClientState(GL_NORMAL_ARRAY);
- glEnableClientState(GL_COLOR_ARRAY);
-
- bound_options_new |= GPU_SHADER_USE_COLOR;
- }
-
- GPU_buffer_bind(buffers->vert_buf, GPU_BINDING_ARRAY);
-
- if (do_fast) {
- GPU_buffer_bind(buffers->index_buf_fast, GPU_BINDING_INDEX);
- }
- else if (buffers->index_buf) {
- GPU_buffer_bind(buffers->index_buf, GPU_BINDING_INDEX);
- }
-
- if (wireframe) {
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- }
- else {
- if ((buffers->smooth == false) && (buffers->face_indices_len == 0)) {
- bound_options_new |= GPU_SHADER_FLAT_NORMAL;
- }
- }
-
- if (bound_options_new & ~bound_options_old) {
- GPU_basic_shader_bind(bound_options_old | bound_options_new);
- }
-
- if (buffers->tot_quad) {
- const char *offset = base;
- const bool drawall = !(buffers->has_hidden || do_fast);
-
- if (GLEW_ARB_draw_elements_base_vertex && drawall) {
-
- glVertexPointer(3, GL_FLOAT, sizeof(VertexBufferFormat),
- offset + offsetof(VertexBufferFormat, co));
- if (!wireframe) {
- glNormalPointer(GL_SHORT, sizeof(VertexBufferFormat),
- offset + offsetof(VertexBufferFormat, no));
- glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VertexBufferFormat),
- offset + offsetof(VertexBufferFormat, color));
- }
-
- glMultiDrawElementsBaseVertex(GL_TRIANGLES, buffers->baseelemarray, buffers->index_type,
- (const void * const *)buffers->baseindex,
- buffers->totgrid, &buffers->baseelemarray[buffers->totgrid]);
- }
- else {
- int i, last = drawall ? buffers->totgrid : 1;
-
- /* we could optimize this to one draw call, but it would need more memory */
- for (i = 0; i < last; i++) {
- glVertexPointer(3, GL_FLOAT, sizeof(VertexBufferFormat),
- offset + offsetof(VertexBufferFormat, co));
- if (!wireframe) {
- glNormalPointer(GL_SHORT, sizeof(VertexBufferFormat),
- offset + offsetof(VertexBufferFormat, no));
- glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VertexBufferFormat),
- offset + offsetof(VertexBufferFormat, color));
- }
-
- if (do_fast)
- glDrawElements(GL_TRIANGLES, buffers->totgrid * 6, buffers->index_type, index_base);
- else
- glDrawElements(GL_TRIANGLES, buffers->tot_quad * 6, buffers->index_type, index_base);
-
- offset += buffers->gridkey.grid_area * sizeof(VertexBufferFormat);
- }
- }
- }
- else if (buffers->tot_tri) {
- int totelem = buffers->tot_tri * 3;
-
- glVertexPointer(3, GL_FLOAT, sizeof(VertexBufferFormat),
- (void *)(base + offsetof(VertexBufferFormat, co)));
-
- if (!wireframe) {
- glNormalPointer(GL_SHORT, sizeof(VertexBufferFormat),
- (void *)(base + offsetof(VertexBufferFormat, no)));
- glColorPointer(3, GL_UNSIGNED_BYTE, sizeof(VertexBufferFormat),
- (void *)(base + offsetof(VertexBufferFormat, color)));
- }
-
- if (buffers->index_buf)
- glDrawElements(GL_TRIANGLES, totelem, buffers->index_type, index_base);
- else
- glDrawArrays(GL_TRIANGLES, 0, totelem);
- }
-
- if (wireframe)
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-
- GPU_buffer_unbind(buffers->vert_buf, GPU_BINDING_ARRAY);
- if (buffers->index_buf || do_fast)
- GPU_buffer_unbind(do_fast ? buffers->index_buf_fast : buffers->index_buf, GPU_BINDING_INDEX);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- if (!wireframe) {
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- }
-
- if (bound_options_new & ~bound_options_old) {
- GPU_basic_shader_bind(bound_options_old);
- }
- }
+ return (fast && buffers->triangles_fast) ?
+ buffers->triangles_fast : buffers->triangles;
}
-bool GPU_pbvh_buffers_diffuse_changed(
- GPU_PBVH_Buffers *buffers, GSet *bm_faces, bool show_diffuse_color)
+bool GPU_pbvh_buffers_diffuse_changed(GPU_PBVH_Buffers *buffers, GSet *bm_faces, bool show_diffuse_color)
{
float diffuse_color[4];
- bool use_matcaps = GPU_material_use_matcaps_get();
if (buffers->show_diffuse_color != show_diffuse_color)
return true;
- if (buffers->use_matcaps != use_matcaps)
- return true;
-
- if ((buffers->show_diffuse_color == false) || use_matcaps)
+ if (buffers->show_diffuse_color == false)
return false;
if (buffers->looptri) {
const MLoopTri *lt = &buffers->looptri[buffers->face_indices[0]];
const MPoly *mp = &buffers->mpoly[lt->poly];
- GPU_material_diffuse_get(mp->mat_nr + 1, diffuse_color);
+ gpu_material_diffuse_get(mp->mat_nr + 1, diffuse_color);
}
else if (buffers->use_bmesh) {
/* due to dynamic nature of dyntopo, only get first material */
@@ -2015,7 +979,7 @@ bool GPU_pbvh_buffers_diffuse_changed(
BLI_gsetIterator_init(&gs_iter, bm_faces);
f = BLI_gsetIterator_getKey(&gs_iter);
- GPU_material_diffuse_get(f->mat_nr + 1, diffuse_color);
+ gpu_material_diffuse_get(f->mat_nr + 1, diffuse_color);
}
else {
return false;
@@ -2024,7 +988,7 @@ bool GPU_pbvh_buffers_diffuse_changed(
else {
const DMFlagMat *flags = &buffers->grid_flag_mats[buffers->grid_indices[0]];
- GPU_material_diffuse_get(flags->mat_nr + 1, diffuse_color);
+ gpu_material_diffuse_get(flags->mat_nr + 1, diffuse_color);
}
return !equals_v3v3(diffuse_color, buffers->diffuse_color);
@@ -2038,16 +1002,20 @@ bool GPU_pbvh_buffers_mask_changed(GPU_PBVH_Buffers *buffers, bool show_mask)
void GPU_pbvh_buffers_free(GPU_PBVH_Buffers *buffers)
{
if (buffers) {
- if (buffers->vert_buf)
- GPU_buffer_free(buffers->vert_buf);
- if (buffers->index_buf && !buffers->is_index_buf_global)
- GPU_buffer_free(buffers->index_buf);
- if (buffers->index_buf_fast)
- GPU_buffer_free(buffers->index_buf_fast);
+ GWN_BATCH_DISCARD_SAFE(buffers->triangles);
+ GWN_BATCH_DISCARD_SAFE(buffers->triangles_fast);
+ if (!buffers->is_index_buf_global) {
+ GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf);
+ }
+ GWN_INDEXBUF_DISCARD_SAFE(buffers->index_buf_fast);
+ GWN_VERTBUF_DISCARD_SAFE(buffers->vert_buf);
+
+#ifdef USE_BASE_ELEM
if (buffers->baseelemarray)
MEM_freeN(buffers->baseelemarray);
if (buffers->baseindex)
MEM_freeN(buffers->baseindex);
+#endif
MEM_freeN(buffers);
}
@@ -2060,7 +1028,7 @@ void GPU_pbvh_multires_buffers_free(GridCommonGPUBuffer **grid_common_gpu_buffer
if (gridbuff) {
if (gridbuff->mres_buffer) {
BLI_mutex_lock(&buffer_mutex);
- gpu_buffer_free_intern(gridbuff->mres_buffer);
+ GWN_INDEXBUF_DISCARD_SAFE(gridbuff->mres_buffer);
BLI_mutex_unlock(&buffer_mutex);
}
MEM_freeN(gridbuff);
@@ -2069,59 +1037,61 @@ void GPU_pbvh_multires_buffers_free(GridCommonGPUBuffer **grid_common_gpu_buffer
}
/* debug function, draws the pbvh BB */
-void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf)
+void GPU_pbvh_BB_draw(float min[3], float max[3], bool leaf, unsigned int pos)
{
- const float quads[4][4][3] = {
- {
- {min[0], min[1], min[2]},
- {max[0], min[1], min[2]},
- {max[0], min[1], max[2]},
- {min[0], min[1], max[2]}
- },
+ if (leaf)
+ immUniformColor4f(0.0, 1.0, 0.0, 0.5);
+ else
+ immUniformColor4f(1.0, 0.0, 0.0, 0.5);
- {
- {min[0], min[1], min[2]},
- {min[0], max[1], min[2]},
- {min[0], max[1], max[2]},
- {min[0], min[1], max[2]}
- },
+ /* TODO(merwin): revisit this after we have mutable VertexBuffers
+ * could keep a static batch & index buffer, change the VBO contents per draw
+ */
- {
- {max[0], max[1], min[2]},
- {max[0], min[1], min[2]},
- {max[0], min[1], max[2]},
- {max[0], max[1], max[2]}
- },
+ immBegin(GWN_PRIM_LINES, 24);
- {
- {max[0], max[1], min[2]},
- {min[0], max[1], min[2]},
- {min[0], max[1], max[2]},
- {max[0], max[1], max[2]}
- },
- };
+ /* top */
+ immVertex3f(pos, min[0], min[1], max[2]);
+ immVertex3f(pos, min[0], max[1], max[2]);
- if (leaf)
- glColor4f(0.0, 1.0, 0.0, 0.5);
- else
- glColor4f(1.0, 0.0, 0.0, 0.5);
+ immVertex3f(pos, min[0], max[1], max[2]);
+ immVertex3f(pos, max[0], max[1], max[2]);
- glVertexPointer(3, GL_FLOAT, 0, &quads[0][0][0]);
- glDrawArrays(GL_QUADS, 0, 16);
-}
+ immVertex3f(pos, max[0], max[1], max[2]);
+ immVertex3f(pos, max[0], min[1], max[2]);
-void GPU_pbvh_BB_draw_init(void)
-{
- glPushAttrib(GL_ENABLE_BIT);
- glDisable(GL_CULL_FACE);
- glEnableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- glEnable(GL_BLEND);
+ immVertex3f(pos, max[0], min[1], max[2]);
+ immVertex3f(pos, min[0], min[1], max[2]);
+
+ /* bottom */
+ immVertex3f(pos, min[0], min[1], min[2]);
+ immVertex3f(pos, min[0], max[1], min[2]);
+
+ immVertex3f(pos, min[0], max[1], min[2]);
+ immVertex3f(pos, max[0], max[1], min[2]);
+
+ immVertex3f(pos, max[0], max[1], min[2]);
+ immVertex3f(pos, max[0], min[1], min[2]);
+
+ immVertex3f(pos, max[0], min[1], min[2]);
+ immVertex3f(pos, min[0], min[1], min[2]);
+
+ /* sides */
+ immVertex3f(pos, min[0], min[1], min[2]);
+ immVertex3f(pos, min[0], min[1], max[2]);
+
+ immVertex3f(pos, min[0], max[1], min[2]);
+ immVertex3f(pos, min[0], max[1], max[2]);
+
+ immVertex3f(pos, max[0], max[1], min[2]);
+ immVertex3f(pos, max[0], max[1], max[2]);
+
+ immVertex3f(pos, max[0], min[1], min[2]);
+ immVertex3f(pos, max[0], min[1], max[2]);
+
+ immEnd();
}
-void GPU_pbvh_BB_draw_end(void)
+void GPU_pbvh_fix_linking()
{
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- glPopAttrib();
}
diff --git a/source/blender/gpu/intern/gpu_codegen.c b/source/blender/gpu/intern/gpu_codegen.c
index b5512aa108d..7a4af0521bb 100644
--- a/source/blender/gpu/intern/gpu_codegen.c
+++ b/source/blender/gpu/intern/gpu_codegen.c
@@ -36,17 +36,23 @@
#include "DNA_customdata_types.h"
#include "DNA_image_types.h"
#include "DNA_material_types.h"
+#include "DNA_node_types.h"
#include "BLI_blenlib.h"
+#include "BLI_hash_mm2a.h"
+#include "BLI_linklist.h"
#include "BLI_utildefines.h"
#include "BLI_dynstr.h"
#include "BLI_ghash.h"
+#include "PIL_time.h"
+
#include "GPU_extensions.h"
#include "GPU_glew.h"
#include "GPU_material.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
+#include "GPU_uniformbuffer.h"
#include "BLI_sys_types.h" /* for intptr_t support */
@@ -62,6 +68,50 @@ extern char datatoc_gpu_shader_geometry_glsl[];
static char *glsl_material_library = NULL;
+/* -------------------- GPUPass Cache ------------------ */
+/**
+ * Internal shader cache: This prevent the shader recompilation / stall when
+ * using undo/redo AND also allows for GPUPass reuse if the Shader code is the
+ * same for 2 different Materials. Unused GPUPasses are free by Garbage collection.
+ **/
+
+static LinkNode *pass_cache = NULL; /* GPUPass */
+
+static uint32_t gpu_pass_hash(const char *vert, const char *geom, const char *frag, const char *defs)
+{
+ BLI_HashMurmur2A hm2a;
+ BLI_hash_mm2a_init(&hm2a, 0);
+ BLI_hash_mm2a_add(&hm2a, (unsigned char *)frag, strlen(frag));
+ BLI_hash_mm2a_add(&hm2a, (unsigned char *)vert, strlen(vert));
+ if (defs)
+ BLI_hash_mm2a_add(&hm2a, (unsigned char *)defs, strlen(defs));
+ if (geom)
+ BLI_hash_mm2a_add(&hm2a, (unsigned char *)geom, strlen(geom));
+
+ return BLI_hash_mm2a_end(&hm2a);
+}
+
+/* Search by hash then by exact string match. */
+static GPUPass *gpu_pass_cache_lookup(
+ const char *vert, const char *geom, const char *frag, const char *defs, uint32_t hash)
+{
+ for (LinkNode *ln = pass_cache; ln; ln = ln->next) {
+ GPUPass *pass = (GPUPass *)ln->link;
+ if (pass->hash == hash) {
+ /* Note: Could be made faster if that becomes a real bottleneck. */
+ if ((defs != NULL) && (strcmp(pass->defines, defs) != 0)) { /* Pass */ }
+ else if ((geom != NULL) && (strcmp(pass->geometrycode, geom) != 0)) { /* Pass */ }
+ else if ((strcmp(pass->fragmentcode, frag) == 0) &&
+ (strcmp(pass->vertexcode, vert) == 0))
+ {
+ return pass;
+ }
+ }
+ }
+ return NULL;
+}
+
+/* -------------------- GPU Codegen ------------------ */
/* type definitions and constants */
@@ -88,7 +138,7 @@ typedef struct GPUFunction {
/* Indices match the GPUType enum */
static const char *GPU_DATATYPE_STR[17] = {
"", "float", "vec2", "vec3", "vec4",
- NULL, NULL, NULL, NULL, "mat3", NULL, NULL, NULL, NULL, NULL, NULL, "mat4",
+ NULL, NULL, NULL, NULL, "mat3", NULL, NULL, NULL, NULL, NULL, NULL, "mat4"
};
/* GLSL code parsing for finding function definitions.
@@ -172,7 +222,7 @@ static void gpu_parse_functions_string(GHash *hash, char *code)
/* test for type */
type = GPU_NONE;
- for (i = 1; i <= 16; i++) {
+ for (i = 1; i < ARRAY_SIZE(GPU_DATATYPE_STR); i++) {
if (GPU_DATATYPE_STR[i] && gpu_str_prefix(code, GPU_DATATYPE_STR[i])) {
type = i;
break;
@@ -188,6 +238,13 @@ static void gpu_parse_functions_string(GHash *hash, char *code)
if (!type && gpu_str_prefix(code, "sampler2D")) {
type = GPU_TEX2D;
}
+ if (!type && gpu_str_prefix(code, "sampler3D")) {
+ type = GPU_TEX3D;
+ }
+
+ if (!type && gpu_str_prefix(code, "Closure")) {
+ type = GPU_CLOSURE;
+ }
if (type) {
/* add parameter */
@@ -350,6 +407,8 @@ static void codegen_convert_datatype(DynStr *ds, int from, int to, const char *t
BLI_dynstr_appendf(ds, "vec4(%s.r, %s.r, %s.r, %s.g)", name, name, name, name);
else if (from == GPU_FLOAT)
BLI_dynstr_appendf(ds, "vec4(%s, %s, %s, 1.0)", name, name, name);
+ else /* can happen with closure */
+ BLI_dynstr_append(ds, name);
}
}
@@ -412,6 +471,12 @@ const char *GPU_builtin_name(GPUBuiltin builtin)
return "unfparticleangvel";
else if (builtin == GPU_OBJECT_INFO)
return "unfobjectinfo";
+ else if (builtin == GPU_VOLUME_DENSITY)
+ return "sampdensity";
+ else if (builtin == GPU_VOLUME_FLAME)
+ return "sampflame";
+ else if (builtin == GPU_VOLUME_TEMPERATURE)
+ return "unftemperature";
else
return "";
}
@@ -500,12 +565,16 @@ static void codegen_set_unique_ids(ListBase *nodes)
BLI_ghash_free(definehash, NULL, NULL);
}
-static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
+/**
+ * It will create an UBO for GPUMaterial if there is any GPU_DYNAMIC_UBO.
+ */
+static int codegen_process_uniforms_functions(GPUMaterial *material, DynStr *ds, ListBase *nodes)
{
GPUNode *node;
GPUInput *input;
const char *name;
int builtins = 0;
+ ListBase ubo_inputs = {NULL, NULL};
/* print uniforms */
for (node = nodes->first; node; node = node->next) {
@@ -525,7 +594,14 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
builtins |= input->builtin;
name = GPU_builtin_name(input->builtin);
- if (gpu_str_prefix(name, "unf")) {
+ if (gpu_str_prefix(name, "samp")) {
+ if ((input->builtin == GPU_VOLUME_DENSITY) ||
+ (input->builtin == GPU_VOLUME_FLAME))
+ {
+ BLI_dynstr_appendf(ds, "uniform sampler3D %s;\n", name);
+ }
+ }
+ else if (gpu_str_prefix(name, "unf")) {
BLI_dynstr_appendf(ds, "uniform %s %s;\n",
GPU_DATATYPE_STR[input->type], name);
}
@@ -536,14 +612,23 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
}
}
}
+ else if (input->source == GPU_SOURCE_STRUCT) {
+ /* Add other struct here if needed. */
+ BLI_dynstr_appendf(ds, "Closure strct%d = CLOSURE_DEFAULT;\n", input->id);
+ }
else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
- if (input->dynamicvec) {
+ if (input->dynamictype == GPU_DYNAMIC_UBO) {
+ if (!input->link) {
+ /* We handle the UBOuniforms separately. */
+ BLI_addtail(&ubo_inputs, BLI_genericNodeN(input));
+ }
+ }
+ else if (input->dynamicvec) {
/* only create uniforms for dynamic vectors */
BLI_dynstr_appendf(ds, "uniform %s unf%d;\n",
GPU_DATATYPE_STR[input->type], input->id);
}
else {
- /* for others use const so the compiler can do folding */
BLI_dynstr_appendf(ds, "const %s cons%d = ",
GPU_DATATYPE_STR[input->type], input->id);
codegen_print_datatype(ds, input->type, input->vec);
@@ -569,6 +654,22 @@ static int codegen_print_uniforms_functions(DynStr *ds, ListBase *nodes)
}
}
+ /* Handle the UBO block separately. */
+ if ((material != NULL) && !BLI_listbase_is_empty(&ubo_inputs)) {
+ GPU_material_create_uniform_buffer(material, &ubo_inputs);
+
+ /* Inputs are sorted */
+ BLI_dynstr_appendf(ds, "\nlayout (std140) uniform %s {\n", GPU_UBO_BLOCK_NAME);
+
+ for (LinkData *link = ubo_inputs.first; link; link = link->next) {
+ input = link->data;
+ BLI_dynstr_appendf(ds, "\t%s unf%d;\n",
+ GPU_DATATYPE_STR[input->type], input->id);
+ }
+ BLI_dynstr_append(ds, "};\n");
+ BLI_freelistN(&ubo_inputs);
+ }
+
BLI_dynstr_append(ds, "\n");
return builtins;
@@ -594,8 +695,13 @@ static void codegen_declare_tmps(DynStr *ds, ListBase *nodes)
/* declare temporary variables for node output storage */
for (output = node->outputs.first; output; output = output->next) {
- BLI_dynstr_appendf(ds, "\t%s tmp%d;\n",
- GPU_DATATYPE_STR[output->type], output->id);
+ if (output->type == GPU_CLOSURE) {
+ BLI_dynstr_appendf(ds, "\tClosure tmp%d;\n", output->id);
+ }
+ else {
+ BLI_dynstr_appendf(ds, "\t%s tmp%d;\n",
+ GPU_DATATYPE_STR[output->type], output->id);
+ }
}
}
@@ -622,11 +728,26 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
"tmp", input->link->output->id);
}
else if (input->source == GPU_SOURCE_BUILTIN) {
- if (input->builtin == GPU_VIEW_NORMAL)
+ if (input->builtin == GPU_INVERSE_VIEW_MATRIX)
+ BLI_dynstr_append(ds, "viewinv");
+ else if (input->builtin == GPU_VIEW_MATRIX)
+ BLI_dynstr_append(ds, "viewmat");
+ else if (input->builtin == GPU_CAMERA_TEXCO_FACTORS)
+ BLI_dynstr_append(ds, "camtexfac");
+ else if (input->builtin == GPU_OBJECT_MATRIX)
+ BLI_dynstr_append(ds, "objmat");
+ else if (input->builtin == GPU_INVERSE_OBJECT_MATRIX)
+ BLI_dynstr_append(ds, "objinv");
+ else if (input->builtin == GPU_VIEW_POSITION)
+ BLI_dynstr_append(ds, "viewposition");
+ else if (input->builtin == GPU_VIEW_NORMAL)
BLI_dynstr_append(ds, "facingnormal");
else
BLI_dynstr_append(ds, GPU_builtin_name(input->builtin));
}
+ else if (input->source == GPU_SOURCE_STRUCT) {
+ BLI_dynstr_appendf(ds, "strct%d", input->id);
+ }
else if (input->source == GPU_SOURCE_VEC_UNIFORM) {
if (input->dynamicvec)
BLI_dynstr_appendf(ds, "unf%d", input->id);
@@ -655,12 +776,11 @@ static void codegen_call_functions(DynStr *ds, ListBase *nodes, GPUOutput *final
BLI_dynstr_append(ds, ");\n");
}
- BLI_dynstr_append(ds, "\n\tgl_FragColor = ");
- codegen_convert_datatype(ds, finaloutput->type, GPU_VEC4, "tmp", finaloutput->id);
+ BLI_dynstr_appendf(ds, "\n\treturn tmp%d", finaloutput->id);
BLI_dynstr_append(ds, ";\n");
}
-static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
+static char *code_generate_fragment(GPUMaterial *material, ListBase *nodes, GPUOutput *output)
{
DynStr *ds = BLI_dynstr_new();
char *code;
@@ -677,17 +797,29 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
#endif
codegen_set_unique_ids(nodes);
- builtins = codegen_print_uniforms_functions(ds, nodes);
+ builtins = codegen_process_uniforms_functions(material, ds, nodes);
#if 0
if (G.debug & G_DEBUG)
BLI_dynstr_appendf(ds, "/* %s */\n", name);
#endif
- BLI_dynstr_append(ds, "void main()\n{\n");
-
+ BLI_dynstr_append(ds, "Closure nodetree_exec(void)\n{\n");
+
+ if (builtins & GPU_VIEW_MATRIX)
+ BLI_dynstr_append(ds, "\tmat4 viewmat = ViewMatrix;\n");
+ if (builtins & GPU_CAMERA_TEXCO_FACTORS)
+ BLI_dynstr_append(ds, "\tvec4 camtexfac = CameraTexCoFactors;\n");
+ if (builtins & GPU_OBJECT_MATRIX)
+ BLI_dynstr_append(ds, "\tmat4 objmat = ModelMatrix;\n");
+ if (builtins & GPU_INVERSE_OBJECT_MATRIX)
+ BLI_dynstr_append(ds, "\tmat4 objinv = ModelMatrixInverse;\n");
+ if (builtins & GPU_INVERSE_VIEW_MATRIX)
+ BLI_dynstr_append(ds, "\tmat4 viewinv = ViewMatrixInverse;\n");
if (builtins & GPU_VIEW_NORMAL)
- BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing? varnormal: -varnormal;\n");
+ BLI_dynstr_append(ds, "\tvec3 facingnormal = gl_FrontFacing? viewNormal: -viewNormal;\n");
+ if (builtins & GPU_VIEW_POSITION)
+ BLI_dynstr_append(ds, "\tvec3 viewposition = viewPosition;\n");
/* Calculate tangent space. */
#ifdef WITH_OPENSUBDIV
@@ -722,6 +854,17 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
BLI_dynstr_append(ds, "}\n");
+ /* XXX This cannot go into gpu_shader_material.glsl because main() would be parsed and generate error */
+ /* Old glsl mode compat. */
+ BLI_dynstr_append(ds, "#ifndef NODETREE_EXEC\n");
+ BLI_dynstr_append(ds, "out vec4 fragColor;\n");
+ BLI_dynstr_append(ds, "void main()\n");
+ BLI_dynstr_append(ds, "{\n");
+ BLI_dynstr_append(ds, "\tClosure cl = nodetree_exec();\n");
+ BLI_dynstr_append(ds, "\tfragColor = vec4(cl.radiance, cl.opacity);\n");
+ BLI_dynstr_append(ds, "}\n");
+ BLI_dynstr_append(ds, "#endif\n\n");
+
/* create shader */
code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);
@@ -733,103 +876,108 @@ static char *code_generate_fragment(ListBase *nodes, GPUOutput *output)
return code;
}
-static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
+static const char *attrib_prefix_get(CustomDataType type)
+{
+ switch (type) {
+ case CD_ORCO: return "orco";
+ case CD_MTFACE: return "u";
+ case CD_TANGENT: return "t";
+ case CD_MCOL: return "c";
+ case CD_AUTO_FROM_NAME: return "a";
+ default: BLI_assert(false && "Gwn_VertAttr Prefix type not found : This should not happen!"); return "";
+ }
+}
+
+static char *code_generate_vertex(ListBase *nodes, const char *vert_code, bool use_geom)
{
DynStr *ds = BLI_dynstr_new();
GPUNode *node;
GPUInput *input;
char *code;
- char *vertcode = NULL;
-
+
for (node = nodes->first; node; node = node->next) {
for (input = node->inputs.first; input; input = input->next) {
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
-#ifdef WITH_OPENSUBDIV
- bool skip_opensubdiv = ELEM(input->attribtype, CD_MTFACE, CD_TANGENT);
- if (skip_opensubdiv) {
- BLI_dynstr_appendf(ds, "#ifndef USE_OPENSUBDIV\n");
+ /* XXX FIXME : see notes in mesh_render_data_create() */
+ /* NOTE : Replicate changes to mesh_render_data_create() in draw_cache_impl_mesh.c */
+ if (input->attribtype == CD_ORCO) {
+ /* orco is computed from local positions, see bellow */
+ BLI_dynstr_appendf(ds, "uniform vec3 OrcoTexCoFactors[2];\n");
}
-#endif
- BLI_dynstr_appendf(ds, "%s %s att%d;\n",
- GLEW_VERSION_3_0 ? "in" : "attribute",
- GPU_DATATYPE_STR[input->type], input->attribid);
- BLI_dynstr_appendf(ds, "uniform int att%d_info;\n", input->attribid);
- BLI_dynstr_appendf(ds, "%s %s var%d;\n",
- GLEW_VERSION_3_0 ? "out" : "varying",
- GPU_DATATYPE_STR[input->type], input->attribid);
-#ifdef WITH_OPENSUBDIV
- if (skip_opensubdiv) {
- BLI_dynstr_appendf(ds, "#endif\n");
+ else if (input->attribname[0] == '\0') {
+ BLI_dynstr_appendf(ds, "in %s %s;\n", GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype));
+ BLI_dynstr_appendf(ds, "#define att%d %s\n", input->attribid, attrib_prefix_get(input->attribtype));
}
-#endif
+ else {
+ unsigned int hash = BLI_ghashutil_strhash_p(input->attribname);
+ BLI_dynstr_appendf(ds, "in %s %s%u;\n",
+ GPU_DATATYPE_STR[input->type], attrib_prefix_get(input->attribtype), hash);
+ BLI_dynstr_appendf(ds, "#define att%d %s%u\n",
+ input->attribid, attrib_prefix_get(input->attribtype), hash);
+ /* Auto attrib can be vertex color byte buffer.
+ * We need to know and convert them to linear space in VS. */
+ if (!use_geom && input->attribtype == CD_AUTO_FROM_NAME) {
+ BLI_dynstr_appendf(ds, "uniform bool ba%u;\n", hash);
+ BLI_dynstr_appendf(ds, "#define att%d_is_srgb ba%u\n", input->attribid, hash);
+ }
+ }
+ BLI_dynstr_appendf(ds, "out %s var%d%s;\n",
+ GPU_DATATYPE_STR[input->type], input->attribid, use_geom ? "g" : "");
}
}
}
BLI_dynstr_append(ds, "\n");
- switch (type) {
- case GPU_MATERIAL_TYPE_MESH:
- vertcode = datatoc_gpu_shader_vertex_glsl;
- break;
- case GPU_MATERIAL_TYPE_WORLD:
- vertcode = datatoc_gpu_shader_vertex_world_glsl;
- break;
- default:
- fprintf(stderr, "invalid material type, set one after GPU_material_construct_begin\n");
- break;
- }
+ BLI_dynstr_append(ds,
+ "#define ATTRIB\n"
+ "uniform mat3 NormalMatrix;\n"
+ "vec3 srgb_to_linear_attrib(vec3 c) {\n"
+ "\tc = max(c, vec3(0.0));\n"
+ "\tvec3 c1 = c * (1.0 / 12.92);\n"
+ "\tvec3 c2 = pow((c + 0.055) * (1.0 / 1.055), vec3(2.4));\n"
+ "\treturn mix(c1, c2, step(vec3(0.04045), c));\n"
+ "}\n\n"
+ );
- BLI_dynstr_append(ds, vertcode);
-
- for (node = nodes->first; node; node = node->next)
- for (input = node->inputs.first; input; input = input->next)
+ BLI_dynstr_append(ds, "void pass_attrib(in vec3 position) {\n");
+
+ for (node = nodes->first; node; node = node->next) {
+ for (input = node->inputs.first; input; input = input->next) {
if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
if (input->attribtype == CD_TANGENT) { /* silly exception */
-#ifdef WITH_OPENSUBDIV
- BLI_dynstr_appendf(ds, "#ifndef USE_OPENSUBDIV\n");
-#endif
BLI_dynstr_appendf(
- ds, "\tvar%d.xyz = normalize(gl_NormalMatrix * att%d.xyz);\n",
- input->attribid, input->attribid);
+ ds, "\tvar%d%s.xyz = normalize(NormalMatrix * att%d.xyz);\n",
+ input->attribid, use_geom ? "g" : "", input->attribid);
BLI_dynstr_appendf(
- ds, "\tvar%d.w = att%d.w;\n",
- input->attribid, input->attribid);
-#ifdef WITH_OPENSUBDIV
- BLI_dynstr_appendf(ds, "#endif\n");
-#endif
+ ds, "\tvar%d%s.w = att%d.w;\n",
+ input->attribid, use_geom ? "g" : "", input->attribid);
}
- else {
-#ifdef WITH_OPENSUBDIV
- bool is_mtface = input->attribtype == CD_MTFACE;
- if (is_mtface) {
- BLI_dynstr_appendf(ds, "#ifndef USE_OPENSUBDIV\n");
- }
-#endif
- BLI_dynstr_appendf(ds, "\tset_var_from_attr(att%d, att%d_info, var%d);\n",
- input->attribid, input->attribid, input->attribid);
-#ifdef WITH_OPENSUBDIV
- if (is_mtface) {
- BLI_dynstr_appendf(ds, "#endif\n");
- }
-#endif
+ else if (input->attribtype == CD_ORCO) {
+ BLI_dynstr_appendf(ds, "\tvar%d%s = OrcoTexCoFactors[0] + position * OrcoTexCoFactors[1];\n",
+ input->attribid, use_geom ? "g" : "");
}
- }
- /* unfortunately special handling is needed here because we abuse gl_Color/gl_SecondaryColor flat shading */
- else if (input->source == GPU_SOURCE_OPENGL_BUILTIN) {
- if (input->oglbuiltin == GPU_MATCAP_NORMAL) {
- /* remap to 0.0 - 1.0 range. This is done because OpenGL 2.0 clamps colors
- * between shader stages and we want the full range of the normal */
- BLI_dynstr_appendf(ds, "\tvec3 matcapcol = vec3(0.5) * varnormal + vec3(0.5);\n");
- BLI_dynstr_appendf(ds, "\tgl_FrontSecondaryColor = vec4(matcapcol, 1.0);\n");
+ else if (input->attribtype == CD_MCOL) {
+ BLI_dynstr_appendf(ds, "\tvar%d%s = srgb_to_linear_attrib(att%d);\n",
+ input->attribid, use_geom ? "g" : "", input->attribid);
}
- else if (input->oglbuiltin == GPU_COLOR) {
- BLI_dynstr_appendf(ds, "\tgl_FrontColor = gl_Color;\n");
+ else if (input->attribtype == CD_AUTO_FROM_NAME) {
+ BLI_dynstr_appendf(ds, "\tvar%d%s = (att%d_is_srgb) ? srgb_to_linear_attrib(att%d) : att%d;\n",
+ input->attribid, use_geom ? "g" : "",
+ input->attribid, input->attribid, input->attribid);
+ }
+ else {
+ BLI_dynstr_appendf(ds, "\tvar%d%s = att%d;\n",
+ input->attribid, use_geom ? "g" : "", input->attribid);
}
}
+ }
+ }
BLI_dynstr_append(ds, "}\n");
+ BLI_dynstr_append(ds, vert_code);
+
code = BLI_dynstr_get_cstring(ds);
BLI_dynstr_free(ds);
@@ -841,65 +989,49 @@ static char *code_generate_vertex(ListBase *nodes, const GPUMatType type)
return code;
}
-static char *code_generate_geometry(ListBase *nodes, bool use_opensubdiv)
+static char *code_generate_geometry(ListBase *nodes, const char *geom_code)
{
-#ifdef WITH_OPENSUBDIV
- if (use_opensubdiv) {
- DynStr *ds = BLI_dynstr_new();
- GPUNode *node;
- GPUInput *input;
- char *code;
+ DynStr *ds = BLI_dynstr_new();
+ GPUNode *node;
+ GPUInput *input;
+ char *code;
- /* Generate varying declarations. */
- for (node = nodes->first; node; node = node->next) {
- for (input = node->inputs.first; input; input = input->next) {
- if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
- if (input->attribtype == CD_MTFACE) {
- /* NOTE: For now we are using varying on purpose,
- * otherwise we are not able to write to the varying.
- */
- BLI_dynstr_appendf(ds, "%s %s var%d%s;\n",
- "varying",
- GPU_DATATYPE_STR[input->type],
- input->attribid,
- "");
- BLI_dynstr_appendf(ds, "uniform int fvar%d_offset;\n",
- input->attribid);
- }
- }
- }
- }
+ /* Create prototype because attributes cannot be declared before layout. */
+ BLI_dynstr_appendf(ds, "void pass_attrib(in int vert);\n");
+ BLI_dynstr_append(ds, "#define ATTRIB\n");
- BLI_dynstr_append(ds, datatoc_gpu_shader_geometry_glsl);
+ BLI_dynstr_append(ds, geom_code);
- /* Generate varying assignments. */
- for (node = nodes->first; node; node = node->next) {
- for (input = node->inputs.first; input; input = input->next) {
- if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
- if (input->attribtype == CD_MTFACE) {
- BLI_dynstr_appendf(
- ds,
- "\tINTERP_FACE_VARYING_ATT_2(var%d, "
- "int(texelFetch(FVarDataOffsetBuffer, fvar%d_offset).r), st);\n",
- input->attribid,
- input->attribid);
- }
- }
+ /* Generate varying declarations. */
+ for (node = nodes->first; node; node = node->next) {
+ for (input = node->inputs.first; input; input = input->next) {
+ if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
+ BLI_dynstr_appendf(ds, "in %s var%dg[];\n",
+ GPU_DATATYPE_STR[input->type],
+ input->attribid);
+ BLI_dynstr_appendf(ds, "out %s var%d;\n",
+ GPU_DATATYPE_STR[input->type],
+ input->attribid);
}
}
+ }
- BLI_dynstr_append(ds, "}\n");
- code = BLI_dynstr_get_cstring(ds);
- BLI_dynstr_free(ds);
+ /* Generate varying assignments. */
+ BLI_dynstr_appendf(ds, "void pass_attrib(in int vert) {\n");
+ for (node = nodes->first; node; node = node->next) {
+ for (input = node->inputs.first; input; input = input->next) {
+ if (input->source == GPU_SOURCE_ATTRIB && input->attribfirst) {
+ /* TODO let shader choose what to do depending on what the attrib is. */
+ BLI_dynstr_appendf(ds, "\tvar%d = var%dg[vert];\n", input->attribid, input->attribid);
+ }
+ }
+ }
+ BLI_dynstr_append(ds, "}\n");
- //if (G.debug & G_DEBUG) printf("%s\n", code);
+ code = BLI_dynstr_get_cstring(ds);
+ BLI_dynstr_free(ds);
- return code;
- }
-#else
- UNUSED_VARS(nodes, use_opensubdiv);
-#endif
- return NULL;
+ return code;
}
void GPU_code_generate_glsl_lib(void)
@@ -928,15 +1060,13 @@ GPUShader *GPU_pass_shader(GPUPass *pass)
return pass->shader;
}
-static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
+static void gpu_nodes_extract_dynamic_inputs(GPUShader *shader, ListBase *inputs, ListBase *nodes)
{
- GPUShader *shader = pass->shader;
GPUNode *node;
GPUInput *next, *input;
- ListBase *inputs = &pass->inputs;
int extract, z;
- memset(inputs, 0, sizeof(*inputs));
+ BLI_listbase_clear(inputs);
if (!shader)
return;
@@ -951,26 +1081,9 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
/* attributes don't need to be bound, they already have
* an id that the drawing functions will use */
if (input->source == GPU_SOURCE_ATTRIB) {
-#ifdef WITH_OPENSUBDIV
- /* We do need mtface attributes for later, so we can
- * update face-varuing variables offset in the texture
- * buffer for proper sampling from the shader.
- *
- * We don't do anything about attribute itself, we
- * only use it to learn which uniform name is to be
- * updated.
- *
- * TODO(sergey): We can add ad extra uniform input
- * for the offset, which will be purely internal and
- * which would avoid having such an exceptions.
- */
- if (input->attribtype != CD_MTFACE) {
- continue;
- }
-#else
continue;
-#endif
}
+
if (input->source == GPU_SOURCE_BUILTIN ||
input->source == GPU_SOURCE_OPENGL_BUILTIN)
{
@@ -995,14 +1108,6 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
if (extract)
input->shaderloc = GPU_shader_get_uniform(shader, input->shadername);
-#ifdef WITH_OPENSUBDIV
- if (input->source == GPU_SOURCE_ATTRIB &&
- input->attribtype == CD_MTFACE)
- {
- extract = 1;
- }
-#endif
-
/* extract nodes */
if (extract) {
BLI_remlink(&node->inputs, input);
@@ -1014,11 +1119,10 @@ static void gpu_nodes_extract_dynamic_inputs(GPUPass *pass, ListBase *nodes)
GPU_shader_unbind();
}
-void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
+void GPU_pass_bind(GPUPass *pass, ListBase *inputs, double time, int mipmap)
{
GPUInput *input;
GPUShader *shader = pass->shader;
- ListBase *inputs = &pass->inputs;
if (!shader)
return;
@@ -1043,11 +1147,10 @@ void GPU_pass_bind(GPUPass *pass, double time, int mipmap)
}
}
-void GPU_pass_update_uniforms(GPUPass *pass)
+void GPU_pass_update_uniforms(GPUPass *pass, ListBase *inputs)
{
GPUInput *input;
GPUShader *shader = pass->shader;
- ListBase *inputs = &pass->inputs;
if (!shader)
return;
@@ -1068,11 +1171,10 @@ void GPU_pass_update_uniforms(GPUPass *pass)
}
}
-void GPU_pass_unbind(GPUPass *pass)
+void GPU_pass_unbind(GPUPass *pass, ListBase *inputs)
{
GPUInput *input;
GPUShader *shader = pass->shader;
- ListBase *inputs = &pass->inputs;
if (!shader)
return;
@@ -1135,7 +1237,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
name = outnode->name;
input = outnode->inputs.first;
- if ((STREQ(name, "set_value") || STREQ(name, "set_rgb")) &&
+ if ((STREQ(name, "set_value") || STREQ(name, "set_rgb") || STREQ(name, "set_rgba")) &&
(input->type == type))
{
input = MEM_dupallocN(outnode->inputs.first);
@@ -1194,7 +1296,7 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
#if 0
input->tex = GPU_texture_create_2D(link->texturesize, link->texturesize, link->ptr2, NULL);
#endif
- input->tex = GPU_texture_create_2D(link->texturesize, 1, link->ptr1, GPU_HDR_NONE, NULL);
+ input->tex = GPU_texture_create_2D(link->texturesize, 1, GPU_RGBA8, link->ptr1, NULL);
input->textarget = GL_TEXTURE_2D;
MEM_freeN(link->ptr1);
@@ -1235,6 +1337,12 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
BLI_strncpy(input->attribname, link->attribname, sizeof(input->attribname));
MEM_freeN(link);
}
+ else if (type == GPU_CLOSURE) {
+ input->type = type;
+ input->source = GPU_SOURCE_STRUCT;
+
+ MEM_freeN(link);
+ }
else {
/* uniform vector */
input->type = type;
@@ -1246,21 +1354,100 @@ static void gpu_node_input_link(GPUNode *node, GPUNodeLink *link, const GPUType
input->dynamictype = link->dynamictype;
input->dynamicdata = link->ptr2;
}
+
MEM_freeN(link);
}
BLI_addtail(&node->inputs, input);
}
-static void gpu_node_input_socket(GPUNode *node, GPUNodeStack *sock)
+
+static const char *gpu_uniform_set_function_from_type(eNodeSocketDatatype type)
{
- GPUNodeLink *link;
+ switch (type) {
+ case SOCK_FLOAT:
+ return "set_value";
+ case SOCK_VECTOR:
+ return "set_rgb";
+ case SOCK_RGBA:
+ return "set_rgba";
+ default:
+ BLI_assert(!"No gpu function for non-supported eNodeSocketDatatype");
+ return NULL;
+ }
+}
+
+/**
+ * Link stack uniform buffer.
+ * This is called for the input/output sockets that are note connected.
+ */
+static GPUNodeLink *gpu_uniformbuffer_link(
+ GPUMaterial *mat, bNode *node, GPUNodeStack *stack, const int index, const eNodeSocketInOut in_out)
+{
+ bNodeSocket *socket;
+
+ /* Some nodes can have been create on the fly and does
+ * not have an original to point to. (i.e. the bump from
+ * ntree_shader_relink_displacement). In this case just
+ * revert to static constant folding. */
+ if (node->original == NULL) {
+ return NULL;
+ }
+ if (in_out == SOCK_IN) {
+ socket = BLI_findlink(&node->original->inputs, index);
+ }
+ else {
+ socket = BLI_findlink(&node->original->outputs, index);
+ }
+
+ BLI_assert(socket != NULL);
+ BLI_assert(socket->in_out == in_out);
+
+ if ((socket->flag & SOCK_HIDE_VALUE) == 0) {
+ GPUNodeLink *link;
+ switch (socket->type) {
+ case SOCK_FLOAT:
+ {
+ bNodeSocketValueFloat *socket_data = socket->default_value;
+ link = GPU_uniform_buffer(&socket_data->value, GPU_FLOAT);
+ break;
+ }
+ case SOCK_VECTOR:
+ {
+ bNodeSocketValueRGBA *socket_data = socket->default_value;
+ link = GPU_uniform_buffer(socket_data->value, GPU_VEC3);
+ break;
+ }
+ case SOCK_RGBA:
+ {
+ bNodeSocketValueRGBA *socket_data = socket->default_value;
+ link = GPU_uniform_buffer(socket_data->value, GPU_VEC4);
+ break;
+ }
+ default:
+ return NULL;
+ break;
+ }
+
+ if (in_out == SOCK_IN) {
+ GPU_link(mat, gpu_uniform_set_function_from_type(socket->type), link, &stack->link);
+ }
+ return link;
+ }
+ return NULL;
+}
+
+static void gpu_node_input_socket(GPUMaterial *material, bNode *bnode, GPUNode *node, GPUNodeStack *sock, const int index)
+{
if (sock->link) {
gpu_node_input_link(node, sock->link, sock->type);
}
+ else if ((material != NULL) && (gpu_uniformbuffer_link(material, bnode, sock, index, SOCK_IN) != NULL)) {
+ gpu_node_input_link(node, sock->link, sock->type);
+ }
else {
- link = GPU_node_link_create();
+ GPUNodeLink *link = GPU_node_link_create();
link->ptr1 = sock->vec;
gpu_node_input_link(node, link, sock->type);
}
@@ -1286,7 +1473,7 @@ static void gpu_node_output(GPUNode *node, const GPUType type, GPUNodeLink **lin
BLI_addtail(&node->outputs, output);
}
-static void gpu_inputs_free(ListBase *inputs)
+void GPU_inputs_free(ListBase *inputs)
{
GPUInput *input;
@@ -1304,7 +1491,7 @@ static void gpu_node_free(GPUNode *node)
{
GPUOutput *output;
- gpu_inputs_free(&node->inputs);
+ GPU_inputs_free(&node->inputs);
for (output = node->outputs.first; output; output = output->next)
if (output->link) {
@@ -1327,7 +1514,7 @@ static void gpu_nodes_free(ListBase *nodes)
/* vertex attributes */
-static void gpu_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *attribs)
+void GPU_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *attribs)
{
GPUNode *node;
GPUInput *input;
@@ -1368,26 +1555,20 @@ static void gpu_nodes_get_vertex_attributes(ListBase *nodes, GPUVertexAttribs *a
}
}
-static void gpu_nodes_get_builtin_flag(ListBase *nodes, int *builtin)
-{
- GPUNode *node;
- GPUInput *input;
-
- *builtin = 0;
-
- for (node = nodes->first; node; node = node->next)
- for (input = node->inputs.first; input; input = input->next)
- if (input->source == GPU_SOURCE_BUILTIN)
- *builtin |= input->builtin;
-}
-
/* varargs linking */
GPUNodeLink *GPU_attribute(const CustomDataType type, const char *name)
{
GPUNodeLink *link = GPU_node_link_create();
- link->attribtype = type;
+ /* Fall back to the UV layer, which matches old behavior. */
+ if (type == CD_AUTO_FROM_NAME && name[0] == '\0') {
+ link->attribtype = CD_MTFACE;
+ }
+ else {
+ link->attribtype = type;
+ }
+
link->attribname = name;
return link;
@@ -1416,6 +1597,21 @@ GPUNodeLink *GPU_dynamic_uniform(float *num, GPUDynamicType dynamictype, void *d
return link;
}
+/**
+ * Add uniform to UBO struct of GPUMaterial.
+ */
+GPUNodeLink *GPU_uniform_buffer(float *num, GPUType gputype)
+{
+ GPUNodeLink *link = GPU_node_link_create();
+ link->ptr1 = num;
+ link->ptr2 = NULL;
+ link->dynamic = true;
+ link->dynamictype = GPU_DYNAMIC_UBO;
+ link->type = gputype;
+
+ return link;
+}
+
GPUNodeLink *GPU_image(Image *ima, ImageUser *iuser, bool is_data)
{
GPUNodeLink *link = GPU_node_link_create();
@@ -1526,7 +1722,7 @@ bool GPU_link(GPUMaterial *mat, const char *name, ...)
return true;
}
-bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...)
+bool GPU_stack_link(GPUMaterial *material, bNode *bnode, const char *name, GPUNodeStack *in, GPUNodeStack *out, ...)
{
GPUNode *node;
GPUFunction *function;
@@ -1545,16 +1741,20 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
totout = 0;
if (in) {
- for (i = 0; in[i].type != GPU_NONE; i++) {
- gpu_node_input_socket(node, &in[i]);
- totin++;
+ for (i = 0; !in[i].end; i++) {
+ if (in[i].type != GPU_NONE) {
+ gpu_node_input_socket(material, bnode, node, &in[i], i);
+ totin++;
+ }
}
}
-
+
if (out) {
- for (i = 0; out[i].type != GPU_NONE; i++) {
- gpu_node_output(node, out[i].type, &out[i].link);
- totout++;
+ for (i = 0; !out[i].end; i++) {
+ if (out[i].type != GPU_NONE) {
+ gpu_node_output(node, out[i].type, &out[i].link);
+ totout++;
+ }
}
}
@@ -1572,7 +1772,7 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
if (totin == 0) {
link = va_arg(params, GPUNodeLink *);
if (link->socket)
- gpu_node_input_socket(node, link->socket);
+ gpu_node_input_socket(NULL, NULL, node, link->socket, -1);
else
gpu_node_input_link(node, link, function->paramtype[i]);
}
@@ -1582,8 +1782,8 @@ bool GPU_stack_link(GPUMaterial *mat, const char *name, GPUNodeStack *in, GPUNod
}
va_end(params);
- gpu_material_add_node(mat, node);
-
+ gpu_material_add_node(material, node);
+
return true;
}
@@ -1608,6 +1808,11 @@ int GPU_link_changed(GPUNodeLink *link)
return 0;
}
+GPUNodeLink *GPU_uniformbuffer_link_out(GPUMaterial *mat, bNode *node, GPUNodeStack *stack, const int index)
+{
+ return gpu_uniformbuffer_link(mat, node, stack, index, SOCK_OUT);
+}
+
/* Pass create/free */
static void gpu_nodes_tag(GPUNodeLink *link)
@@ -1628,7 +1833,7 @@ static void gpu_nodes_tag(GPUNodeLink *link)
gpu_nodes_tag(input->link);
}
-static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
+void GPU_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
{
GPUNode *node, *next;
@@ -1647,91 +1852,97 @@ static void gpu_nodes_prune(ListBase *nodes, GPUNodeLink *outlink)
}
}
-GPUPass *GPU_generate_pass(
- ListBase *nodes, GPUNodeLink *outlink,
- GPUVertexAttribs *attribs, int *builtins,
- const GPUMatType type, const char *UNUSED(name),
- const bool use_opensubdiv,
- const bool use_new_shading)
+GPUPass *GPU_generate_pass_new(
+ GPUMaterial *material,
+ GPUNodeLink *frag_outlink, struct GPUVertexAttribs *attribs,
+ ListBase *nodes, ListBase *inputs,
+ const char *vert_code, const char *geom_code,
+ const char *frag_lib, const char *defines)
{
+ char *vertexcode, *geometrycode, *fragmentcode;
GPUShader *shader;
GPUPass *pass;
- char *vertexcode, *geometrycode, *fragmentcode;
-#if 0
- if (!FUNCTION_LIB) {
- GPU_nodes_free(nodes);
- return NULL;
+ /* prune unused nodes */
+ GPU_nodes_prune(nodes, frag_outlink);
+
+ GPU_nodes_get_vertex_attributes(nodes, attribs);
+
+ /* generate code */
+ char *fragmentgen = code_generate_fragment(material, nodes, frag_outlink->output);
+ char *tmp = BLI_strdupcat(frag_lib, glsl_material_library);
+
+ vertexcode = code_generate_vertex(nodes, vert_code, (geom_code != NULL));
+ geometrycode = (geom_code) ? code_generate_geometry(nodes, geom_code) : NULL;
+ fragmentcode = BLI_strdupcat(tmp, fragmentgen);
+
+ MEM_freeN(fragmentgen);
+ MEM_freeN(tmp);
+
+ /* Cache lookup: Reuse shaders already compiled */
+ uint32_t hash = gpu_pass_hash(vertexcode, geometrycode, fragmentcode, defines);
+ pass = gpu_pass_cache_lookup(vertexcode, geometrycode, fragmentcode, defines, hash);
+ if (pass) {
+ /* Cache hit. Reuse the same GPUPass and GPUShader. */
+ shader = pass->shader;
+ pass->refcount += 1;
+
+ MEM_SAFE_FREE(vertexcode);
+ MEM_SAFE_FREE(fragmentcode);
+ MEM_SAFE_FREE(geometrycode);
+ }
+ else {
+ /* Cache miss. (Re)compile the shader. */
+ shader = GPU_shader_create(vertexcode,
+ fragmentcode,
+ geometrycode,
+ NULL,
+ defines);
+
+ /* We still create a pass even if shader compilation
+ * fails to avoid trying to compile again and again. */
+ pass = MEM_callocN(sizeof(GPUPass), "GPUPass");
+ pass->shader = shader;
+ pass->refcount = 1;
+ pass->hash = hash;
+ pass->vertexcode = vertexcode;
+ pass->fragmentcode = fragmentcode;
+ pass->geometrycode = geometrycode;
+ pass->libcode = glsl_material_library;
+ pass->defines = (defines) ? BLI_strdup(defines) : NULL;
+
+ BLI_linklist_prepend(&pass_cache, pass);
}
-#endif
- /* prune unused nodes */
- gpu_nodes_prune(nodes, outlink);
-
- gpu_nodes_get_vertex_attributes(nodes, attribs);
- gpu_nodes_get_builtin_flag(nodes, builtins);
-
- /* generate code and compile with opengl */
- fragmentcode = code_generate_fragment(nodes, outlink->output);
- vertexcode = code_generate_vertex(nodes, type);
- geometrycode = code_generate_geometry(nodes, use_opensubdiv);
-
- int flags = GPU_SHADER_FLAGS_NONE;
- if (use_opensubdiv) {
- flags |= GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV;
- }
- if (use_new_shading) {
- flags |= GPU_SHADER_FLAGS_NEW_SHADING;
- }
- shader = GPU_shader_create_ex(vertexcode,
- fragmentcode,
- geometrycode,
- glsl_material_library,
- NULL,
- 0,
- 0,
- 0,
- flags);
-
- /* failed? */
+ /* did compilation failed ? */
if (!shader) {
- if (fragmentcode)
- MEM_freeN(fragmentcode);
- if (vertexcode)
- MEM_freeN(vertexcode);
- memset(attribs, 0, sizeof(*attribs));
- memset(builtins, 0, sizeof(*builtins));
gpu_nodes_free(nodes);
+ /* Pass will not be used. Don't increment refcount. */
+ pass->refcount--;
return NULL;
}
-
- /* create pass */
- pass = MEM_callocN(sizeof(GPUPass), "GPUPass");
-
- pass->output = outlink->output;
- pass->shader = shader;
- pass->fragmentcode = fragmentcode;
- pass->geometrycode = geometrycode;
- pass->vertexcode = vertexcode;
- pass->libcode = glsl_material_library;
-
- /* extract dynamic inputs and throw away nodes */
- gpu_nodes_extract_dynamic_inputs(pass, nodes);
- gpu_nodes_free(nodes);
+ else {
+ gpu_nodes_extract_dynamic_inputs(shader, inputs, nodes);
+ return pass;
+ }
+}
- return pass;
+void GPU_pass_release(GPUPass *pass)
+{
+ BLI_assert(pass->refcount > 0);
+ pass->refcount--;
}
-void GPU_pass_free(GPUPass *pass)
+static void gpu_pass_free(GPUPass *pass)
{
- GPU_shader_free(pass->shader);
- gpu_inputs_free(&pass->inputs);
- if (pass->fragmentcode)
- MEM_freeN(pass->fragmentcode);
- if (pass->geometrycode)
- MEM_freeN(pass->geometrycode);
- if (pass->vertexcode)
- MEM_freeN(pass->vertexcode);
+ BLI_assert(pass->refcount == 0);
+ if (pass->shader) {
+ GPU_shader_free(pass->shader);
+ }
+ MEM_SAFE_FREE(pass->fragmentcode);
+ MEM_SAFE_FREE(pass->geometrycode);
+ MEM_SAFE_FREE(pass->vertexcode);
+ MEM_SAFE_FREE(pass->defines);
MEM_freeN(pass);
}
@@ -1740,3 +1951,34 @@ void GPU_pass_free_nodes(ListBase *nodes)
gpu_nodes_free(nodes);
}
+void GPU_pass_cache_garbage_collect(void)
+{
+ static int lasttime = 0;
+ const int shadercollectrate = 60; /* hardcoded for now. */
+ int ctime = (int)PIL_check_seconds_timer();
+
+ if (ctime < shadercollectrate + lasttime)
+ return;
+
+ lasttime = ctime;
+
+ LinkNode *next, **prev_ln = &pass_cache;
+ for (LinkNode *ln = pass_cache; ln; ln = next) {
+ GPUPass *pass = (GPUPass *)ln->link;
+ next = ln->next;
+ if (pass->refcount == 0) {
+ gpu_pass_free(pass);
+ /* Remove from list */
+ MEM_freeN(ln);
+ *prev_ln = next;
+ }
+ else {
+ prev_ln = &ln->next;
+ }
+ }
+}
+
+void GPU_pass_cache_free(void)
+{
+ BLI_linklist_free(pass_cache, (LinkNodeFreeFP)gpu_pass_free);
+}
diff --git a/source/blender/gpu/intern/gpu_codegen.h b/source/blender/gpu/intern/gpu_codegen.h
index 7af17f9122d..328da36c3de 100644
--- a/source/blender/gpu/intern/gpu_codegen.h
+++ b/source/blender/gpu/intern/gpu_codegen.h
@@ -57,7 +57,8 @@ typedef enum GPUDataSource {
GPU_SOURCE_OPENGL_BUILTIN,
GPU_SOURCE_TEX_PIXEL,
GPU_SOURCE_TEX,
- GPU_SOURCE_ATTRIB
+ GPU_SOURCE_ATTRIB,
+ GPU_SOURCE_STRUCT
} GPUDataSource;
typedef enum {
@@ -156,35 +157,45 @@ typedef struct GPUInput {
} GPUInput;
struct GPUPass {
- struct GPUPass *next, *prev;
-
- ListBase inputs;
- struct GPUOutput *output;
struct GPUShader *shader;
char *fragmentcode;
char *geometrycode;
char *vertexcode;
+ char *defines;
const char *libcode;
+ unsigned int refcount; /* Orphaned GPUPasses gets freed by the garbage collector. */
+ uint32_t hash; /* Identity hash generated from all GLSL code. */
};
typedef struct GPUPass GPUPass;
-GPUPass *GPU_generate_pass(ListBase *nodes, struct GPUNodeLink *outlink,
- struct GPUVertexAttribs *attribs, int *builtin,
- const GPUMatType type, const char *name,
- const bool use_opensubdiv,
- const bool use_new_shading);
+GPUPass *GPU_generate_pass_new(
+ GPUMaterial *material,
+ GPUNodeLink *frag_outlink, struct GPUVertexAttribs *attribs,
+ ListBase *nodes, ListBase *inputs,
+ const char *vert_code, const char *geom_code,
+ const char *frag_lib, const char *defines);
+GPUPass *GPU_generate_pass(
+ ListBase *nodes, ListBase *inputs, struct GPUNodeLink *outlink,
+ struct GPUVertexAttribs *attribs, int *builtin,
+ const GPUMatType type, const char *name,
+ const bool use_opensubdiv);
struct GPUShader *GPU_pass_shader(GPUPass *pass);
-void GPU_pass_bind(GPUPass *pass, double time, int mipmap);
-void GPU_pass_update_uniforms(GPUPass *pass);
-void GPU_pass_unbind(GPUPass *pass);
+void GPU_nodes_get_vertex_attributes(ListBase *nodes, struct GPUVertexAttribs *attribs);
+void GPU_nodes_prune(ListBase *nodes, struct GPUNodeLink *outlink);
-void GPU_pass_free(GPUPass *pass);
+void GPU_pass_bind(GPUPass *pass, ListBase *inputs, double time, int mipmap);
+void GPU_pass_update_uniforms(GPUPass *pass, ListBase *inputs);
+void GPU_pass_unbind(GPUPass *pass, ListBase *inputs);
+
+void GPU_pass_release(GPUPass *pass);
void GPU_pass_free_nodes(ListBase *nodes);
+void GPU_inputs_free(ListBase *inputs);
+
void gpu_codegen_init(void);
void gpu_codegen_exit(void);
diff --git a/source/blender/gpu/intern/gpu_compositing.c b/source/blender/gpu/intern/gpu_compositing.c
deleted file mode 100644
index 2f2a16f9e1d..00000000000
--- a/source/blender/gpu/intern/gpu_compositing.c
+++ /dev/null
@@ -1,1461 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2006 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Antony Riakiotakis.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/gpu/intern/gpu_compositing.c
- * \ingroup gpu
- *
- * System that manages framebuffer compositing.
- */
-
-#include "BLI_sys_types.h"
-#include "BLI_rect.h"
-#include "BLI_math.h"
-
-#include "BLI_rand.h"
-
-#include "DNA_vec_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_gpu_types.h"
-
-#include "GPU_compositing.h"
-#include "GPU_extensions.h"
-#include "GPU_framebuffer.h"
-#include "GPU_glew.h"
-#include "GPU_shader.h"
-#include "GPU_texture.h"
-
-#include "MEM_guardedalloc.h"
-
-static const float fullscreencos[4][2] = {{-1.0f, -1.0f}, {1.0f, -1.0f}, {-1.0f, 1.0f}, {1.0f, 1.0f}};
-static const float fullscreenuvs[4][2] = {{0.0f, 0.0f}, {1.0f, 0.0f}, {0.0f, 1.0f}, {1.0f, 1.0f}};
-
-
-/* shader interfaces (legacy GL 2 style, without uniform buffer objects) */
-
-typedef struct {
- int ssao_uniform;
- int ssao_color_uniform;
- int color_uniform;
- int depth_uniform;
- int viewvecs_uniform;
- int ssao_sample_params_uniform;
- int ssao_concentric_tex;
- int ssao_jitter_uniform;
-} GPUSSAOShaderInterface;
-
-typedef struct {
- int invrendertargetdim_uniform;
- int color_uniform;
- int dof_uniform;
- int depth_uniform;
- int viewvecs_uniform;
-} GPUDOFHQPassOneInterface;
-
-typedef struct {
- int rendertargetdim_uniform;
- int color_uniform;
- int coc_uniform;
- int select_uniform;
- int dof_uniform;
-} GPUDOFHQPassTwoInterface;
-
-typedef struct {
- int dof_uniform;
- int invrendertargetdim_uniform;
- int color_uniform;
- int far_uniform;
- int near_uniform;
- int viewvecs_uniform;
- int depth_uniform;
-} GPUDOFHQPassThreeInterface;
-
-typedef struct {
- int dof_uniform;
- int invrendertargetdim_uniform;
- int color_uniform;
- int depth_uniform;
- int viewvecs_uniform;
-} GPUDOFPassOneInterface;
-
-typedef struct {
- int dof_uniform;
- int invrendertargetdim_uniform;
- int color_uniform;
- int depth_uniform;
- int viewvecs_uniform;
-} GPUDOFPassTwoInterface;
-
-typedef struct {
- int near_coc_downsampled;
- int near_coc_blurred;
-} GPUDOFPassThreeInterface;
-
-typedef struct {
- int near_coc_downsampled;
- int invrendertargetdim_uniform;
-} GPUDOFPassFourInterface;
-
-typedef struct {
- int medium_blurred_uniform;
- int high_blurred_uniform;
- int dof_uniform;
- int invrendertargetdim_uniform;
- int original_uniform;
- int depth_uniform;
- int viewvecs_uniform;
-} GPUDOFPassFiveInterface;
-
-typedef struct {
- int depth_uniform;
-} GPUDepthResolveInterface;
-
-
-struct GPUFX {
- /* we borrow the term gbuffer from deferred rendering however this is just a regular
- * depth/color framebuffer. Could be extended later though */
- GPUFrameBuffer *gbuffer;
-
- /* dimensions of the gbuffer */
- int gbuffer_dim[2];
-
- /* texture bound to the first color attachment of the gbuffer */
- GPUTexture *color_buffer;
-
- /* second texture used for ping-pong compositing */
- GPUTexture *color_buffer_sec;
- /* texture bound to the depth attachment of the gbuffer */
- GPUTexture *depth_buffer;
- GPUTexture *depth_buffer_xray;
-
- /* texture used for jittering for various effects */
- GPUTexture *jitter_buffer;
-
- /* all those buffers below have to coexist.
- * Fortunately they are all quarter sized (1/16th of memory) of original framebuffer */
- int dof_downsampled_w;
- int dof_downsampled_h;
-
- /* texture used for near coc and color blurring calculation */
- GPUTexture *dof_near_coc_buffer;
- /* blurred near coc buffer. */
- GPUTexture *dof_near_coc_blurred_buffer;
- /* final near coc buffer. */
- GPUTexture *dof_near_coc_final_buffer;
-
- /* half size blur buffer */
- GPUTexture *dof_half_downsampled_near;
- GPUTexture *dof_half_downsampled_far;
- /* high quality dof texture downsamplers. 6 levels means 64 pixels wide - should be enough */
- GPUTexture *dof_nearfar_coc;
- GPUTexture *dof_near_blur;
- GPUTexture *dof_far_blur;
-
- /* for high quality we use again a spiral texture with radius adapted */
- bool dof_high_quality;
-
- /* texture used for ssao */
- int ssao_sample_count_cache;
- GPUTexture *ssao_spiral_samples_tex;
-
-
- GPUFXSettings settings;
-
- /* or-ed flags of enabled effects */
- int effects;
-
- /* number of passes, needed to detect if ping pong buffer allocation is needed */
- int num_passes;
-
- /* we have a stencil, restore the previous state */
- bool restore_stencil;
-
- unsigned int vbuffer;
-};
-
-#if 0
-/* concentric mapping, see "A Low Distortion Map Between Disk and Square" and
- * http://psgraphics.blogspot.nl/2011/01/improved-code-for-concentric-map.html */
-static GPUTexture * create_concentric_sample_texture(int side)
-{
- GPUTexture *tex;
- float midpoint = 0.5f * (side - 1);
- float *texels = (float *)MEM_mallocN(sizeof(float) * 2 * side * side, "concentric_tex");
- int i, j;
-
- for (i = 0; i < side; i++) {
- for (j = 0; j < side; j++) {
- int index = (i * side + j) * 2;
- float a = 1.0f - i / midpoint;
- float b = 1.0f - j / midpoint;
- float phi, r;
- if (a * a > b * b) {
- r = a;
- phi = (M_PI_4) * (b / a);
- }
- else {
- r = b;
- phi = M_PI_2 - (M_PI_4) * (a / b);
- }
- texels[index] = r * cos(phi);
- texels[index + 1] = r * sin(phi);
- }
- }
-
- tex = GPU_texture_create_1D_procedural(side * side, texels, NULL);
- MEM_freeN(texels);
- return tex;
-}
-#endif
-
-static GPUTexture *create_spiral_sample_texture(int numsaples)
-{
- GPUTexture *tex;
- float (*texels)[2] = MEM_mallocN(sizeof(float[2]) * numsaples, "concentric_tex");
- const float numsaples_inv = 1.0f / numsaples;
- int i;
- /* arbitrary number to ensure we don't get conciding samples every circle */
- const float spirals = 7.357;
-
- for (i = 0; i < numsaples; i++) {
- float r = (i + 0.5f) * numsaples_inv;
- float phi = r * spirals * (float)(2.0 * M_PI);
- texels[i][0] = r * cosf(phi);
- texels[i][1] = r * sinf(phi);
- }
-
- tex = GPU_texture_create_1D_procedural(numsaples, (float *)texels, NULL);
- MEM_freeN(texels);
- return tex;
-}
-
-/* generate a new FX compositor */
-GPUFX *GPU_fx_compositor_create(void)
-{
- GPUFX *fx = MEM_callocN(sizeof(GPUFX), "GPUFX compositor");
-
- glGenBuffers(1, &fx->vbuffer);
- glBindBuffer(GL_ARRAY_BUFFER, fx->vbuffer);
- glBufferData(GL_ARRAY_BUFFER, 16 * sizeof(float), NULL, GL_STATIC_DRAW);
- glBufferSubData(GL_ARRAY_BUFFER, 0, 8 * sizeof(float), fullscreencos);
- glBufferSubData(GL_ARRAY_BUFFER, 8 * sizeof(float), 8 * sizeof(float), fullscreenuvs);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- return fx;
-}
-
-static void cleanup_fx_dof_buffers(GPUFX *fx)
-{
- if (fx->dof_near_coc_blurred_buffer) {
- GPU_texture_free(fx->dof_near_coc_blurred_buffer);
- fx->dof_near_coc_blurred_buffer = NULL;
- }
- if (fx->dof_near_coc_buffer) {
- GPU_texture_free(fx->dof_near_coc_buffer);
- fx->dof_near_coc_buffer = NULL;
- }
- if (fx->dof_near_coc_final_buffer) {
- GPU_texture_free(fx->dof_near_coc_final_buffer);
- fx->dof_near_coc_final_buffer = NULL;
- }
-
- if (fx->dof_half_downsampled_near) {
- GPU_texture_free(fx->dof_half_downsampled_near);
- fx->dof_half_downsampled_near = NULL;
- }
- if (fx->dof_half_downsampled_far) {
- GPU_texture_free(fx->dof_half_downsampled_far);
- fx->dof_half_downsampled_far = NULL;
- }
- if (fx->dof_nearfar_coc) {
- GPU_texture_free(fx->dof_nearfar_coc);
- fx->dof_nearfar_coc = NULL;
- }
- if (fx->dof_near_blur) {
- GPU_texture_free(fx->dof_near_blur);
- fx->dof_near_blur = NULL;
- }
- if (fx->dof_far_blur) {
- GPU_texture_free(fx->dof_far_blur);
- fx->dof_far_blur = NULL;
- }
-}
-
-static void cleanup_fx_gl_data(GPUFX *fx, bool do_fbo)
-{
- if (fx->color_buffer) {
- GPU_framebuffer_texture_detach(fx->color_buffer);
- GPU_texture_free(fx->color_buffer);
- fx->color_buffer = NULL;
- }
-
- if (fx->color_buffer_sec) {
- GPU_framebuffer_texture_detach(fx->color_buffer_sec);
- GPU_texture_free(fx->color_buffer_sec);
- fx->color_buffer_sec = NULL;
- }
-
- if (fx->depth_buffer) {
- GPU_framebuffer_texture_detach(fx->depth_buffer);
- GPU_texture_free(fx->depth_buffer);
- fx->depth_buffer = NULL;
- }
-
- if (fx->depth_buffer_xray) {
- GPU_framebuffer_texture_detach(fx->depth_buffer_xray);
- GPU_texture_free(fx->depth_buffer_xray);
- fx->depth_buffer_xray = NULL;
- }
-
- cleanup_fx_dof_buffers(fx);
-
- if (fx->ssao_spiral_samples_tex) {
- GPU_texture_free(fx->ssao_spiral_samples_tex);
- fx->ssao_spiral_samples_tex = NULL;
- }
-
- if (fx->jitter_buffer && do_fbo) {
- GPU_texture_free(fx->jitter_buffer);
- fx->jitter_buffer = NULL;
- }
-
- if (fx->gbuffer && do_fbo) {
- GPU_framebuffer_free(fx->gbuffer);
- fx->gbuffer = NULL;
- }
-}
-
-/* destroy a text compositor */
-void GPU_fx_compositor_destroy(GPUFX *fx)
-{
- cleanup_fx_gl_data(fx, true);
- glDeleteBuffers(1, &fx->vbuffer);
- MEM_freeN(fx);
-}
-
-static GPUTexture * create_jitter_texture(void)
-{
- float jitter[64 * 64][2];
- int i;
-
- for (i = 0; i < 64 * 64; i++) {
- jitter[i][0] = 2.0f * BLI_frand() - 1.0f;
- jitter[i][1] = 2.0f * BLI_frand() - 1.0f;
- normalize_v2(jitter[i]);
- }
-
- return GPU_texture_create_2D_procedural(64, 64, &jitter[0][0], true, NULL);
-}
-
-
-bool GPU_fx_compositor_initialize_passes(
- GPUFX *fx, const rcti *rect, const rcti *scissor_rect,
- const GPUFXSettings *fx_settings)
-{
- int w = BLI_rcti_size_x(rect), h = BLI_rcti_size_y(rect);
- char err_out[256];
- int num_passes = 0;
- char fx_flag;
-
- fx->effects = 0;
-
- if (!GLEW_EXT_framebuffer_object)
- return false;
-
- if (!fx_settings) {
- cleanup_fx_gl_data(fx, true);
- return false;
- }
-
- fx_flag = fx_settings->fx_flag;
-
- /* disable effects if no options passed for them */
- if (!fx_settings->dof) {
- fx_flag &= ~GPU_FX_FLAG_DOF;
- }
- if (!fx_settings->ssao || fx_settings->ssao->samples < 1) {
- fx_flag &= ~GPU_FX_FLAG_SSAO;
- }
-
- if (!fx_flag) {
- cleanup_fx_gl_data(fx, true);
- return false;
- }
-
- /* scissor is missing when drawing offscreen, in that case, dimensions match exactly. In opposite case
- * add one to match viewport dimensions */
- if (scissor_rect) {
- w++;
- h++;
- }
-
- fx->num_passes = 0;
- /* dof really needs a ping-pong buffer to work */
- if (fx_flag & GPU_FX_FLAG_DOF)
- num_passes++;
-
- if (fx_flag & GPU_FX_FLAG_SSAO)
- num_passes++;
-
- if (!fx->gbuffer) {
- fx->gbuffer = GPU_framebuffer_create();
-
- if (!fx->gbuffer) {
- return false;
- }
- }
-
- /* try creating the jitter texture */
- if (!fx->jitter_buffer)
- fx->jitter_buffer = create_jitter_texture();
-
- /* check if color buffers need recreation */
- if (!fx->color_buffer || !fx->depth_buffer || w != fx->gbuffer_dim[0] || h != fx->gbuffer_dim[1]) {
- cleanup_fx_gl_data(fx, false);
-
- if (!(fx->color_buffer = GPU_texture_create_2D(w, h, NULL, GPU_HDR_NONE, err_out))) {
- printf(".256%s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
-
- if (!(fx->depth_buffer = GPU_texture_create_depth(w, h, err_out))) {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- }
-
- if (fx_flag & GPU_FX_FLAG_SSAO) {
- if (fx_settings->ssao->samples != fx->ssao_sample_count_cache || !fx->ssao_spiral_samples_tex) {
- if (fx_settings->ssao->samples < 1)
- fx_settings->ssao->samples = 1;
-
- fx->ssao_sample_count_cache = fx_settings->ssao->samples;
-
- if (fx->ssao_spiral_samples_tex) {
- GPU_texture_free(fx->ssao_spiral_samples_tex);
- }
-
- fx->ssao_spiral_samples_tex = create_spiral_sample_texture(fx_settings->ssao->samples);
- }
- }
- else {
- if (fx->ssao_spiral_samples_tex) {
- GPU_texture_free(fx->ssao_spiral_samples_tex);
- fx->ssao_spiral_samples_tex = NULL;
- }
- }
-
- /* create textures for dof effect */
- if (fx_flag & GPU_FX_FLAG_DOF) {
- bool dof_high_quality = (fx_settings->dof->high_quality != 0) &&
- GPU_geometry_shader_support() && GPU_instanced_drawing_support();
-
- /* cleanup buffers if quality setting has changed (no need to keep more buffers around than necessary ) */
- if (dof_high_quality != fx->dof_high_quality)
- cleanup_fx_dof_buffers(fx);
-
- if (dof_high_quality) {
- fx->dof_downsampled_w = w / 2;
- fx->dof_downsampled_h = h / 2;
-
- if (!fx->dof_half_downsampled_near || !fx->dof_nearfar_coc || !fx->dof_near_blur ||
- !fx->dof_far_blur || !fx->dof_half_downsampled_far)
- {
-
- if (!(fx->dof_half_downsampled_near = GPU_texture_create_2D(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- if (!(fx->dof_half_downsampled_far = GPU_texture_create_2D(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- if (!(fx->dof_nearfar_coc = GPU_texture_create_2D_procedural(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, false, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
-
-
- if (!(fx->dof_near_blur = GPU_texture_create_2D(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_HALF_FLOAT, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
-
- if (!(fx->dof_far_blur = GPU_texture_create_2D(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_HALF_FLOAT, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- }
- }
- else {
- fx->dof_downsampled_w = w / 4;
- fx->dof_downsampled_h = h / 4;
-
- if (!fx->dof_near_coc_buffer || !fx->dof_near_coc_blurred_buffer || !fx->dof_near_coc_final_buffer) {
-
- if (!(fx->dof_near_coc_buffer = GPU_texture_create_2D(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- if (!(fx->dof_near_coc_blurred_buffer = GPU_texture_create_2D(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- if (!(fx->dof_near_coc_final_buffer = GPU_texture_create_2D(
- fx->dof_downsampled_w, fx->dof_downsampled_h, NULL, GPU_HDR_NONE, err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- }
- }
-
- fx->dof_high_quality = dof_high_quality;
- }
- else {
- /* cleanup unnecessary buffers */
- cleanup_fx_dof_buffers(fx);
- }
-
- /* we need to pass data between shader stages, allocate an extra color buffer */
- if (num_passes > 1) {
- if (!fx->color_buffer_sec) {
- if (!(fx->color_buffer_sec = GPU_texture_create_2D(w, h, NULL, GPU_HDR_NONE, err_out))) {
- printf(".256%s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return false;
- }
- }
- }
- else {
- if (fx->color_buffer_sec) {
- GPU_framebuffer_texture_detach(fx->color_buffer_sec);
- GPU_texture_free(fx->color_buffer_sec);
- fx->color_buffer_sec = NULL;
- }
- }
-
- /* bind the buffers */
-
- /* first depth buffer, because system assumes read/write buffers */
- if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, err_out))
- printf("%.256s\n", err_out);
-
- if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->color_buffer, 0, err_out))
- printf("%.256s\n", err_out);
-
- if (!GPU_framebuffer_check_valid(fx->gbuffer, err_out))
- printf("%.256s\n", err_out);
-
- GPU_texture_bind_as_framebuffer(fx->color_buffer);
-
- /* enable scissor test. It's needed to ensure sculpting works correctly */
- if (scissor_rect) {
- int w_sc = BLI_rcti_size_x(scissor_rect) + 1;
- int h_sc = BLI_rcti_size_y(scissor_rect) + 1;
- glPushAttrib(GL_SCISSOR_BIT);
- glEnable(GL_SCISSOR_TEST);
- glScissor(scissor_rect->xmin - rect->xmin, scissor_rect->ymin - rect->ymin,
- w_sc, h_sc);
- fx->restore_stencil = true;
- }
- else {
- fx->restore_stencil = false;
- }
-
- fx->effects = fx_flag;
-
- if (fx_settings)
- fx->settings = *fx_settings;
- fx->gbuffer_dim[0] = w;
- fx->gbuffer_dim[1] = h;
-
- fx->num_passes = num_passes;
-
- return true;
-}
-
-static void gpu_fx_bind_render_target(int *passes_left, GPUFX *fx, struct GPUOffScreen *ofs, GPUTexture *target)
-{
- if ((*passes_left)-- == 1) {
- GPU_framebuffer_texture_unbind(fx->gbuffer, NULL);
- if (ofs) {
- GPU_offscreen_bind(ofs, false);
- }
- else
- GPU_framebuffer_restore();
- }
- else {
- /* bind the ping buffer to the color buffer */
- GPU_framebuffer_texture_attach(fx->gbuffer, target, 0, NULL);
- }
-}
-
-void GPU_fx_compositor_setup_XRay_pass(GPUFX *fx, bool do_xray)
-{
- char err_out[256];
-
- if (do_xray) {
- if (!fx->depth_buffer_xray &&
- !(fx->depth_buffer_xray = GPU_texture_create_depth(fx->gbuffer_dim[0], fx->gbuffer_dim[1], err_out)))
- {
- printf("%.256s\n", err_out);
- cleanup_fx_gl_data(fx, true);
- return;
- }
- }
- else {
- if (fx->depth_buffer_xray) {
- GPU_framebuffer_texture_detach(fx->depth_buffer_xray);
- GPU_texture_free(fx->depth_buffer_xray);
- fx->depth_buffer_xray = NULL;
- }
- return;
- }
-
- GPU_framebuffer_texture_detach(fx->depth_buffer);
-
- /* first depth buffer, because system assumes read/write buffers */
- if (!GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer_xray, 0, err_out))
- printf("%.256s\n", err_out);
-}
-
-
-void GPU_fx_compositor_XRay_resolve(GPUFX *fx)
-{
- GPUShader *depth_resolve_shader;
- GPU_framebuffer_texture_detach(fx->depth_buffer_xray);
-
- /* attach regular framebuffer */
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->depth_buffer, 0, NULL);
-
- /* full screen quad where we will always write to depth buffer */
- glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_SCISSOR_BIT);
- glDepthFunc(GL_ALWAYS);
- /* disable scissor from sculpt if any */
- glDisable(GL_SCISSOR_TEST);
- /* disable writing to color buffer, it's depth only pass */
- glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
-
- /* set up quad buffer */
- glBindBuffer(GL_ARRAY_BUFFER, fx->vbuffer);
- glVertexPointer(2, GL_FLOAT, 0, NULL);
- glTexCoordPointer(2, GL_FLOAT, 0, ((GLubyte *)NULL + 8 * sizeof(float)));
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- depth_resolve_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_RESOLVE, false);
-
- if (depth_resolve_shader) {
- GPUDepthResolveInterface *interface = GPU_shader_get_interface(depth_resolve_shader);
-
- GPU_shader_bind(depth_resolve_shader);
-
- GPU_texture_bind(fx->depth_buffer_xray, 0);
- GPU_texture_filter_mode(fx->depth_buffer_xray, false, true);
- GPU_shader_uniform_texture(depth_resolve_shader, interface->depth_uniform, fx->depth_buffer_xray);
-
- /* draw */
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- /* disable bindings */
- GPU_texture_filter_mode(fx->depth_buffer_xray, true, false);
- GPU_texture_unbind(fx->depth_buffer_xray);
-
- GPU_shader_unbind();
- }
-
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- glPopAttrib();
-}
-
-
-bool GPU_fx_do_composite_pass(
- GPUFX *fx, float projmat[4][4], bool is_persp,
- struct Scene *scene, struct GPUOffScreen *ofs)
-{
- GPUTexture *src, *target;
- int numslots = 0;
- float invproj[4][4];
- int i;
- float dfdyfac[2];
- /* number of passes left. when there are no more passes, the result is passed to the frambuffer */
- int passes_left = fx->num_passes;
- /* view vectors for the corners of the view frustum. Can be used to recreate the world space position easily */
- float viewvecs[3][4] = {
- {-1.0f, -1.0f, -1.0f, 1.0f},
- {1.0f, -1.0f, -1.0f, 1.0f},
- {-1.0f, 1.0f, -1.0f, 1.0f}
- };
-
- if (fx->effects == 0)
- return false;
-
- GPU_get_dfdy_factors(dfdyfac);
- /* first, unbind the render-to-texture framebuffer */
- GPU_framebuffer_texture_detach(fx->color_buffer);
- GPU_framebuffer_texture_detach(fx->depth_buffer);
-
- if (fx->restore_stencil)
- glPopAttrib();
-
- src = fx->color_buffer;
- target = fx->color_buffer_sec;
-
- /* set up quad buffer */
- glBindBuffer(GL_ARRAY_BUFFER, fx->vbuffer);
- glVertexPointer(2, GL_FLOAT, 0, NULL);
- glTexCoordPointer(2, GL_FLOAT, 0, ((GLubyte *)NULL + 8 * sizeof(float)));
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
-
- /* full screen FX pass */
-
- /* invert the view matrix */
- invert_m4_m4(invproj, projmat);
-
- /* convert the view vectors to view space */
- for (i = 0; i < 3; i++) {
- mul_m4_v4(invproj, viewvecs[i]);
- /* normalized trick see http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer */
- mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][3]);
- if (is_persp)
- mul_v3_fl(viewvecs[i], 1.0f / viewvecs[i][2]);
- viewvecs[i][3] = 1.0;
- }
-
- /* we need to store the differences */
- viewvecs[1][0] -= viewvecs[0][0];
- viewvecs[1][1] = viewvecs[2][1] - viewvecs[0][1];
-
- /* calculate a depth offset as well */
- if (!is_persp) {
- float vec_far[] = {-1.0f, -1.0f, 1.0f, 1.0f};
- mul_m4_v4(invproj, vec_far);
- mul_v3_fl(vec_far, 1.0f / vec_far[3]);
- viewvecs[1][2] = vec_far[2] - viewvecs[0][2];
- }
-
- /* set invalid color in case shader fails */
- glColor3f(1.0, 0.0, 1.0);
- glDisable(GL_DEPTH_TEST);
-
- /* ssao pass */
- if (fx->effects & GPU_FX_FLAG_SSAO) {
- GPUShader *ssao_shader;
- ssao_shader = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_SSAO, is_persp);
- if (ssao_shader) {
- const GPUSSAOSettings *fx_ssao = fx->settings.ssao;
- /* adjust attenuation to be scale invariant */
- float attenuation = fx_ssao->attenuation / (fx_ssao->distance_max * fx_ssao->distance_max);
- float ssao_params[4] = {fx_ssao->distance_max, fx_ssao->factor, attenuation, 0.0f};
- float sample_params[3];
-
- sample_params[0] = fx->ssao_sample_count_cache;
- /* multiplier so we tile the random texture on screen */
- sample_params[1] = fx->gbuffer_dim[0] / 64.0;
- sample_params[2] = fx->gbuffer_dim[1] / 64.0;
-
- ssao_params[3] = (passes_left == 1 && !ofs) ? dfdyfac[0] : dfdyfac[1];
-
- GPUSSAOShaderInterface *interface = GPU_shader_get_interface(ssao_shader);
-
- GPU_shader_bind(ssao_shader);
-
- GPU_shader_uniform_vector(ssao_shader, interface->ssao_uniform, 4, 1, ssao_params);
- GPU_shader_uniform_vector(ssao_shader, interface->ssao_color_uniform, 4, 1, fx_ssao->color);
- GPU_shader_uniform_vector(ssao_shader, interface->viewvecs_uniform, 4, 3, viewvecs[0]);
- GPU_shader_uniform_vector(ssao_shader, interface->ssao_sample_params_uniform, 3, 1, sample_params);
-
- GPU_texture_bind(src, numslots++);
- GPU_shader_uniform_texture(ssao_shader, interface->color_uniform, src);
-
- GPU_texture_bind(fx->depth_buffer, numslots++);
- GPU_texture_filter_mode(fx->depth_buffer, false, true);
- GPU_shader_uniform_texture(ssao_shader, interface->depth_uniform, fx->depth_buffer);
-
- GPU_texture_bind(fx->jitter_buffer, numslots++);
- GPU_shader_uniform_texture(ssao_shader, interface->ssao_jitter_uniform, fx->jitter_buffer);
-
- GPU_texture_bind(fx->ssao_spiral_samples_tex, numslots++);
- GPU_shader_uniform_texture(ssao_shader, interface->ssao_concentric_tex, fx->ssao_spiral_samples_tex);
-
- /* draw */
- gpu_fx_bind_render_target(&passes_left, fx, ofs, target);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- /* disable bindings */
- GPU_texture_unbind(src);
- GPU_texture_filter_mode(fx->depth_buffer, true, false);
- GPU_texture_unbind(fx->depth_buffer);
- GPU_texture_unbind(fx->jitter_buffer);
- GPU_texture_unbind(fx->ssao_spiral_samples_tex);
-
- /* may not be attached, in that case this just returns */
- if (target) {
- GPU_framebuffer_texture_detach(target);
- if (ofs) {
- GPU_offscreen_bind(ofs, false);
- }
- else {
- GPU_framebuffer_restore();
- }
- }
-
- /* swap here, after src/target have been unbound */
- SWAP(GPUTexture *, target, src);
- numslots = 0;
- }
- }
-
- /* second pass, dof */
- if (fx->effects & GPU_FX_FLAG_DOF) {
- const GPUDOFSettings *fx_dof = fx->settings.dof;
- float dof_params[4];
- float scale = scene->unit.system ? scene->unit.scale_length : 1.0f;
- /* this is factor that converts to the scene scale. focal length and sensor are expressed in mm
- * unit.scale_length is how many meters per blender unit we have. We want to convert to blender units though
- * because the shader reads coordinates in world space, which is in blender units.
- * Note however that focus_distance is already in blender units and shall not be scaled here (see T48157). */
- float scale_camera = 0.001f / scale;
- /* we want radius here for the aperture number */
- float aperture = 0.5f * scale_camera * fx_dof->focal_length / fx_dof->fstop;
-
- dof_params[0] = aperture * fabsf(scale_camera * fx_dof->focal_length /
- (fx_dof->focus_distance - scale_camera * fx_dof->focal_length));
- dof_params[1] = fx_dof->focus_distance;
- dof_params[2] = fx->gbuffer_dim[0] / (scale_camera * fx_dof->sensor);
- dof_params[3] = fx_dof->num_blades;
-
- if (fx->dof_high_quality) {
- GPUShader *dof_shader_pass1, *dof_shader_pass2, *dof_shader_pass3;
-
- /* custom shaders close to the effect described in CryEngine 3 Graphics Gems */
- dof_shader_pass1 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_ONE, is_persp);
- dof_shader_pass2 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_TWO, is_persp);
- dof_shader_pass3 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_THREE, is_persp);
-
- /* error occured, restore framebuffers and return */
- if (!(dof_shader_pass1 && dof_shader_pass2 && dof_shader_pass3)) {
- GPU_framebuffer_texture_unbind(fx->gbuffer, NULL);
- GPU_framebuffer_restore();
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- GPU_shader_unbind();
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- return false;
- }
-
- /* pass first, downsample the color buffer to near/far targets and calculate coc texture */
- {
- float invrendertargetdim[2] = {1.0f / fx->dof_downsampled_w, 1.0f / fx->dof_downsampled_h};
-
- GPUDOFHQPassOneInterface *interface = GPU_shader_get_interface(dof_shader_pass1);
-
- GPU_shader_bind(dof_shader_pass1);
-
- GPU_shader_uniform_vector(dof_shader_pass1, interface->dof_uniform, 4, 1, dof_params);
- GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
- GPU_shader_uniform_vector(dof_shader_pass1, interface->viewvecs_uniform, 4, 3, viewvecs[0]);
-
- GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
-
- GPU_texture_bind(fx->depth_buffer, numslots++);
- GPU_texture_filter_mode(fx->depth_buffer, false, false);
- GPU_shader_uniform_texture(dof_shader_pass1, interface->depth_uniform, fx->depth_buffer);
-
- GPU_texture_bind(src, numslots++);
- /* disable filtering for the texture so custom downsample can do the right thing */
- GPU_texture_filter_mode(src, false, false);
- GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, src);
-
- /* target is the downsampled coc buffer */
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_near, 0, NULL);
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_half_downsampled_far, 1, NULL);
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_nearfar_coc, 2, NULL);
- /* binding takes care of setting the viewport to the downsampled size */
- GPU_framebuffer_slots_bind(fx->gbuffer, 0);
-
- GPU_framebuffer_check_valid(fx->gbuffer, NULL);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- /* disable bindings */
- GPU_texture_filter_mode(src, false, true);
- GPU_texture_unbind(src);
- GPU_texture_filter_mode(fx->depth_buffer, true, false);
- GPU_texture_unbind(fx->depth_buffer);
-
- GPU_framebuffer_texture_detach(fx->dof_half_downsampled_near);
- GPU_framebuffer_texture_detach(fx->dof_half_downsampled_far);
- GPU_framebuffer_texture_detach(fx->dof_nearfar_coc);
- GPU_framebuffer_texture_unbind(fx->gbuffer, fx->dof_half_downsampled_near);
-
- numslots = 0;
- }
-
- /* second pass, shoot quads for every pixel in the downsampled buffers, scaling according
- * to circle of confusion */
- {
- int rendertargetdim[2] = {fx->dof_downsampled_w, fx->dof_downsampled_h};
- float selection[2] = {0.0f, 1.0f};
-
- GPUDOFHQPassTwoInterface *interface = GPU_shader_get_interface(dof_shader_pass2);
-
- GPU_shader_bind(dof_shader_pass2);
-
- GPU_shader_uniform_vector(dof_shader_pass2, interface->dof_uniform, 4, 1, dof_params);
- GPU_shader_uniform_vector_int(dof_shader_pass2, interface->rendertargetdim_uniform, 2, 1, rendertargetdim);
- GPU_shader_uniform_vector(dof_shader_pass2, interface->select_uniform, 2, 1, selection);
-
- GPU_texture_bind(fx->dof_nearfar_coc, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass2, interface->coc_uniform, fx->dof_nearfar_coc);
-
- GPU_texture_bind(fx->dof_half_downsampled_far, numslots++);
- GPU_texture_bind(fx->dof_half_downsampled_near, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_half_downsampled_far);
- GPU_texture_filter_mode(fx->dof_half_downsampled_far, false, false);
-
- /* target is the downsampled coc buffer */
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_far_blur, 0, NULL);
- GPU_texture_bind_as_framebuffer(fx->dof_far_blur);
-
- glDisable(GL_DEPTH_TEST);
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE);
- glPointSize(1.0f);
- /* have to clear the buffer unfortunately */
- glClearColor(0.0, 0.0, 0.0, 0.0);
- glClear(GL_COLOR_BUFFER_BIT);
- /* the draw call we all waited for, draw a point per pixel, scaled per circle of confusion */
- glDrawArraysInstancedARB(GL_POINTS, 0, 1, fx->dof_downsampled_w * fx->dof_downsampled_h);
-
- GPU_texture_unbind(fx->dof_half_downsampled_far);
- GPU_framebuffer_texture_detach(fx->dof_far_blur);
-
- GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_half_downsampled_near);
- GPU_texture_filter_mode(fx->dof_half_downsampled_near, false, false);
-
- selection[0] = 1.0f;
- selection[1] = 0.0f;
-
- GPU_shader_uniform_vector(dof_shader_pass2, interface->select_uniform, 2, 1, selection);
-
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_blur, 0, NULL);
- /* have to clear the buffer unfortunately */
- glClear(GL_COLOR_BUFFER_BIT);
- /* the draw call we all waited for, draw a point per pixel, scaled per circle of confusion */
- glDrawArraysInstancedARB(GL_POINTS, 0, 1, fx->dof_downsampled_w * fx->dof_downsampled_h);
-
- /* disable bindings */
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glDisable(GL_BLEND);
-
- GPU_framebuffer_texture_detach(fx->dof_near_blur);
-
- GPU_texture_unbind(fx->dof_half_downsampled_near);
- GPU_texture_unbind(fx->dof_nearfar_coc);
-
- GPU_framebuffer_texture_unbind(fx->gbuffer, fx->dof_far_blur);
- }
-
- /* third pass, accumulate the near/far blur fields */
- {
- float invrendertargetdim[2] = {1.0f / fx->dof_downsampled_w, 1.0f / fx->dof_downsampled_h};
-
- GPUDOFHQPassThreeInterface *interface = GPU_shader_get_interface(dof_shader_pass3);
-
- GPU_shader_bind(dof_shader_pass3);
-
- GPU_shader_uniform_vector(dof_shader_pass3, interface->dof_uniform, 4, 1, dof_params);
-
- GPU_shader_uniform_vector(dof_shader_pass3, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
- GPU_shader_uniform_vector(dof_shader_pass3, interface->viewvecs_uniform, 4, 3, viewvecs[0]);
-
- GPU_texture_bind(fx->dof_near_blur, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass3, interface->near_uniform, fx->dof_near_blur);
- GPU_texture_filter_mode(fx->dof_near_blur, false, true);
-
- GPU_texture_bind(fx->dof_far_blur, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass3, interface->far_uniform, fx->dof_far_blur);
- GPU_texture_filter_mode(fx->dof_far_blur, false, true);
-
- GPU_texture_bind(fx->depth_buffer, numslots++);
- GPU_texture_filter_mode(fx->depth_buffer, false, false);
- GPU_shader_uniform_texture(dof_shader_pass3, interface->depth_uniform, fx->depth_buffer);
-
- GPU_texture_bind(src, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass3, interface->color_uniform, src);
-
- /* if this is the last pass, prepare for rendering on the frambuffer */
- gpu_fx_bind_render_target(&passes_left, fx, ofs, target);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- /* disable bindings */
- GPU_texture_unbind(fx->dof_near_blur);
- GPU_texture_unbind(fx->dof_far_blur);
- GPU_texture_unbind(src);
- GPU_texture_filter_mode(fx->depth_buffer, true, false);
- GPU_texture_unbind(fx->depth_buffer);
-
- /* may not be attached, in that case this just returns */
- if (target) {
- GPU_framebuffer_texture_detach(target);
- if (ofs) {
- GPU_offscreen_bind(ofs, false);
- }
- else {
- GPU_framebuffer_restore();
- }
- }
-
- numslots = 0;
- }
- }
- else {
- GPUShader *dof_shader_pass1, *dof_shader_pass2, *dof_shader_pass3, *dof_shader_pass4, *dof_shader_pass5;
-
- /* DOF effect has many passes but most of them are performed
- * on a texture whose dimensions are 4 times less than the original
- * (16 times lower than original screen resolution).
- * Technique used is not very exact but should be fast enough and is based
- * on "Practical Post-Process Depth of Field"
- * see http://http.developer.nvidia.com/GPUGems3/gpugems3_ch28.html */
- dof_shader_pass1 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE, is_persp);
- dof_shader_pass2 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_TWO, is_persp);
- dof_shader_pass3 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE, is_persp);
- dof_shader_pass4 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR, is_persp);
- dof_shader_pass5 = GPU_shader_get_builtin_fx_shader(GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FIVE, is_persp);
-
- /* error occured, restore framebuffers and return */
- if (!(dof_shader_pass1 && dof_shader_pass2 && dof_shader_pass3 && dof_shader_pass4 && dof_shader_pass5)) {
- GPU_framebuffer_texture_unbind(fx->gbuffer, NULL);
- GPU_framebuffer_restore();
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- GPU_shader_unbind();
- glBindBuffer(GL_ARRAY_BUFFER, 0);
- return false;
- }
-
- /* pass first, first level of blur in low res buffer */
- {
- float invrendertargetdim[2] = {1.0f / fx->gbuffer_dim[0], 1.0f / fx->gbuffer_dim[1]};
-
- GPUDOFPassOneInterface *interface = GPU_shader_get_interface(dof_shader_pass1);
-
- GPU_shader_bind(dof_shader_pass1);
-
- GPU_shader_uniform_vector(dof_shader_pass1, interface->dof_uniform, 4, 1, dof_params);
- GPU_shader_uniform_vector(dof_shader_pass1, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
- GPU_shader_uniform_vector(dof_shader_pass1, interface->viewvecs_uniform, 4, 3, viewvecs[0]);
-
- GPU_texture_bind(src, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass1, interface->color_uniform, src);
-
- GPU_texture_bind(fx->depth_buffer, numslots++);
- GPU_texture_filter_mode(fx->depth_buffer, false, true);
- GPU_shader_uniform_texture(dof_shader_pass1, interface->depth_uniform, fx->depth_buffer);
-
- /* target is the downsampled coc buffer */
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, NULL);
- /* binding takes care of setting the viewport to the downsampled size */
- GPU_texture_bind_as_framebuffer(fx->dof_near_coc_buffer);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- /* disable bindings */
- GPU_texture_unbind(src);
- GPU_texture_filter_mode(fx->depth_buffer, true, false);
- GPU_texture_unbind(fx->depth_buffer);
-
- GPU_framebuffer_texture_detach(fx->dof_near_coc_buffer);
- numslots = 0;
- }
-
- /* second pass, gaussian blur the downsampled image */
- {
- float invrendertargetdim[2] = {1.0f / GPU_texture_width(fx->dof_near_coc_blurred_buffer),
- 1.0f / GPU_texture_height(fx->dof_near_coc_blurred_buffer)};
- float tmp = invrendertargetdim[0];
- invrendertargetdim[0] = 0.0f;
-
- GPUDOFPassTwoInterface *interface = GPU_shader_get_interface(dof_shader_pass2);
-
- dof_params[2] = GPU_texture_width(fx->dof_near_coc_blurred_buffer) / (scale_camera * fx_dof->sensor);
-
- /* Blurring vertically */
- GPU_shader_bind(dof_shader_pass2);
-
- GPU_shader_uniform_vector(dof_shader_pass2, interface->dof_uniform, 4, 1, dof_params);
- GPU_shader_uniform_vector(dof_shader_pass2, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
- GPU_shader_uniform_vector(dof_shader_pass2, interface->viewvecs_uniform, 4, 3, viewvecs[0]);
-
- GPU_texture_bind(fx->depth_buffer, numslots++);
- GPU_texture_filter_mode(fx->depth_buffer, false, true);
- GPU_shader_uniform_texture(dof_shader_pass2, interface->depth_uniform, fx->depth_buffer);
-
- GPU_texture_bind(fx->dof_near_coc_buffer, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_near_coc_buffer);
-
- /* use final buffer as a temp here */
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, NULL);
-
- /* Drawing quad */
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- /* *unbind/detach */
- GPU_texture_unbind(fx->dof_near_coc_buffer);
- GPU_framebuffer_texture_detach(fx->dof_near_coc_final_buffer);
-
- /* Blurring horizontally */
- invrendertargetdim[0] = tmp;
- invrendertargetdim[1] = 0.0f;
- GPU_shader_uniform_vector(dof_shader_pass2, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
-
- GPU_texture_bind(fx->dof_near_coc_final_buffer, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass2, interface->color_uniform, fx->dof_near_coc_final_buffer);
-
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_blurred_buffer, 0, NULL);
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
-
- /* *unbind/detach */
- GPU_texture_filter_mode(fx->depth_buffer, true, false);
- GPU_texture_unbind(fx->depth_buffer);
-
- GPU_texture_unbind(fx->dof_near_coc_final_buffer);
- GPU_framebuffer_texture_detach(fx->dof_near_coc_blurred_buffer);
-
- dof_params[2] = fx->gbuffer_dim[0] / (scale_camera * fx_dof->sensor);
-
- numslots = 0;
- }
-
- /* third pass, calculate near coc */
- {
- GPUDOFPassThreeInterface *interface = GPU_shader_get_interface(dof_shader_pass3);
-
- GPU_shader_bind(dof_shader_pass3);
-
- GPU_texture_bind(fx->dof_near_coc_buffer, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass3, interface->near_coc_downsampled, fx->dof_near_coc_buffer);
-
- GPU_texture_bind(fx->dof_near_coc_blurred_buffer, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass3, interface->near_coc_blurred, fx->dof_near_coc_blurred_buffer);
-
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_final_buffer, 0, NULL);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- /* disable bindings */
- GPU_texture_unbind(fx->dof_near_coc_buffer);
- GPU_texture_unbind(fx->dof_near_coc_blurred_buffer);
-
- /* unbinding here restores the size to the original */
- GPU_framebuffer_texture_detach(fx->dof_near_coc_final_buffer);
-
- numslots = 0;
- }
-
- /* fourth pass blur final coc once to eliminate discontinuities */
- {
- float invrendertargetdim[2] = {1.0f / GPU_texture_width(fx->dof_near_coc_blurred_buffer),
- 1.0f / GPU_texture_height(fx->dof_near_coc_blurred_buffer)};
-
- GPUDOFPassFourInterface *interface = GPU_shader_get_interface(dof_shader_pass4);
-
- GPU_shader_bind(dof_shader_pass4);
-
- GPU_texture_bind(fx->dof_near_coc_final_buffer, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass4, interface->near_coc_downsampled, fx->dof_near_coc_final_buffer);
- GPU_shader_uniform_vector(dof_shader_pass4, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
-
- GPU_framebuffer_texture_attach(fx->gbuffer, fx->dof_near_coc_buffer, 0, NULL);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- /* disable bindings */
- GPU_texture_unbind(fx->dof_near_coc_final_buffer);
-
- /* unbinding here restores the size to the original */
- GPU_framebuffer_texture_unbind(fx->gbuffer, fx->dof_near_coc_buffer);
- GPU_framebuffer_texture_detach(fx->dof_near_coc_buffer);
-
- numslots = 0;
- }
-
- /* final pass, merge blurred layers according to final calculated coc */
- {
- float invrendertargetdim[2] = {1.0f / fx->gbuffer_dim[0], 1.0f / fx->gbuffer_dim[1]};
-
- GPUDOFPassFiveInterface *interface = GPU_shader_get_interface(dof_shader_pass5);
-
- GPU_shader_bind(dof_shader_pass5);
-
- GPU_shader_uniform_vector(dof_shader_pass5, interface->dof_uniform, 4, 1, dof_params);
- GPU_shader_uniform_vector(dof_shader_pass5, interface->invrendertargetdim_uniform, 2, 1, invrendertargetdim);
- GPU_shader_uniform_vector(dof_shader_pass5, interface->viewvecs_uniform, 4, 3, viewvecs[0]);
-
- GPU_texture_bind(src, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass5, interface->original_uniform, src);
-
- GPU_texture_bind(fx->dof_near_coc_blurred_buffer, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass5, interface->high_blurred_uniform, fx->dof_near_coc_blurred_buffer);
-
- GPU_texture_bind(fx->dof_near_coc_buffer, numslots++);
- GPU_shader_uniform_texture(dof_shader_pass5, interface->medium_blurred_uniform, fx->dof_near_coc_buffer);
-
- GPU_texture_bind(fx->depth_buffer, numslots++);
- GPU_texture_filter_mode(fx->depth_buffer, false, true);
- GPU_shader_uniform_texture(dof_shader_pass5, interface->depth_uniform, fx->depth_buffer);
-
- /* if this is the last pass, prepare for rendering on the frambuffer */
- gpu_fx_bind_render_target(&passes_left, fx, ofs, target);
-
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
- /* disable bindings */
- GPU_texture_unbind(fx->dof_near_coc_buffer);
- GPU_texture_unbind(fx->dof_near_coc_blurred_buffer);
- GPU_texture_unbind(src);
- GPU_texture_filter_mode(fx->depth_buffer, true, false);
- GPU_texture_unbind(fx->depth_buffer);
-
- /* may not be attached, in that case this just returns */
- if (target) {
- GPU_framebuffer_texture_detach(target);
- if (ofs) {
- GPU_offscreen_bind(ofs, false);
- }
- else {
- GPU_framebuffer_restore();
- }
- }
-
- SWAP(GPUTexture *, target, src);
- numslots = 0;
- }
- }
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- glBindBuffer(GL_ARRAY_BUFFER, 0);
-
- GPU_shader_unbind();
-
- return true;
-}
-
-void GPU_fx_compositor_init_dof_settings(GPUDOFSettings *fx_dof)
-{
- fx_dof->fstop = 128.0f;
- fx_dof->focal_length = 1.0f;
- fx_dof->focus_distance = 1.0f;
- fx_dof->sensor = 1.0f;
- fx_dof->num_blades = 6;
-}
-
-void GPU_fx_compositor_init_ssao_settings(GPUSSAOSettings *fx_ssao)
-{
- fx_ssao->factor = 1.0f;
- fx_ssao->distance_max = 0.2f;
- fx_ssao->attenuation = 1.0f;
- fx_ssao->samples = 20;
-}
-
-void GPU_fx_shader_init_interface(struct GPUShader *shader, GPUFXShaderEffect effect)
-{
- if (!shader)
- return;
-
- switch (effect) {
- case GPU_SHADER_FX_SSAO:
- {
- GPUSSAOShaderInterface *interface = MEM_mallocN(sizeof(GPUSSAOShaderInterface), "GPUSSAOShaderInterface");
-
- interface->ssao_uniform = GPU_shader_get_uniform(shader, "ssao_params");
- interface->ssao_color_uniform = GPU_shader_get_uniform(shader, "ssao_color");
- interface->color_uniform = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer");
- interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs");
- interface->ssao_sample_params_uniform = GPU_shader_get_uniform(shader, "ssao_sample_params");
- interface->ssao_concentric_tex = GPU_shader_get_uniform(shader, "ssao_concentric_tex");
- interface->ssao_jitter_uniform = GPU_shader_get_uniform(shader, "jitter_tex");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_ONE:
- {
- GPUDOFHQPassOneInterface *interface = MEM_mallocN(sizeof(GPUDOFHQPassOneInterface), "GPUDOFHQPassOneInterface");
-
- interface->invrendertargetdim_uniform = GPU_shader_get_uniform(shader, "invrendertargetdim");
- interface->color_uniform = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->dof_uniform = GPU_shader_get_uniform(shader, "dof_params");
- interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer");
- interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_TWO:
- {
- GPUDOFHQPassTwoInterface *interface = MEM_mallocN(sizeof(GPUDOFHQPassTwoInterface), "GPUDOFHQPassTwoInterface");
-
- interface->rendertargetdim_uniform = GPU_shader_get_uniform(shader, "rendertargetdim");
- interface->color_uniform = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->coc_uniform = GPU_shader_get_uniform(shader, "cocbuffer");
- interface->select_uniform = GPU_shader_get_uniform(shader, "layerselection");
- interface->dof_uniform = GPU_shader_get_uniform(shader, "dof_params");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_THREE:
- {
- GPUDOFHQPassThreeInterface *interface = MEM_mallocN(sizeof(GPUDOFHQPassThreeInterface), "GPUDOFHQPassThreeInterface");
-
- interface->dof_uniform = GPU_shader_get_uniform(shader, "dof_params");
- interface->invrendertargetdim_uniform = GPU_shader_get_uniform(shader, "invrendertargetdim");
- interface->color_uniform = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->far_uniform = GPU_shader_get_uniform(shader, "farbuffer");
- interface->near_uniform = GPU_shader_get_uniform(shader, "nearbuffer");
- interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs");
- interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE:
- {
- GPUDOFPassOneInterface *interface = MEM_mallocN(sizeof(GPUDOFPassOneInterface), "GPUDOFPassOneInterface");
-
- interface->dof_uniform = GPU_shader_get_uniform(shader, "dof_params");
- interface->invrendertargetdim_uniform = GPU_shader_get_uniform(shader, "invrendertargetdim");
- interface->color_uniform = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer");
- interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_TWO:
- {
- GPUDOFPassTwoInterface *interface = MEM_mallocN(sizeof(GPUDOFPassTwoInterface), "GPUDOFPassTwoInterface");
-
- interface->dof_uniform = GPU_shader_get_uniform(shader, "dof_params");
- interface->invrendertargetdim_uniform = GPU_shader_get_uniform(shader, "invrendertargetdim");
- interface->color_uniform = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer");
- interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE:
- {
- GPUDOFPassThreeInterface *interface = MEM_mallocN(sizeof(GPUDOFPassThreeInterface), "GPUDOFPassThreeInterface");
-
- interface->near_coc_downsampled = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->near_coc_blurred = GPU_shader_get_uniform(shader, "blurredcolorbuffer");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR:
- {
- GPUDOFPassFourInterface *interface = MEM_mallocN(sizeof(GPUDOFPassFourInterface), "GPUDOFPassFourInterface");
-
- interface->near_coc_downsampled = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->invrendertargetdim_uniform = GPU_shader_get_uniform(shader, "invrendertargetdim");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FIVE:
- {
- GPUDOFPassFiveInterface *interface = MEM_mallocN(sizeof(GPUDOFPassFiveInterface), "GPUDOFPassFiveInterface");
-
- interface->medium_blurred_uniform = GPU_shader_get_uniform(shader, "mblurredcolorbuffer");
- interface->high_blurred_uniform = GPU_shader_get_uniform(shader, "blurredcolorbuffer");
- interface->dof_uniform = GPU_shader_get_uniform(shader, "dof_params");
- interface->invrendertargetdim_uniform = GPU_shader_get_uniform(shader, "invrendertargetdim");
- interface->original_uniform = GPU_shader_get_uniform(shader, "colorbuffer");
- interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer");
- interface->viewvecs_uniform = GPU_shader_get_uniform(shader, "viewvecs");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
-
- case GPU_SHADER_FX_DEPTH_RESOLVE:
- {
- GPUDepthResolveInterface *interface = MEM_mallocN(sizeof(GPUDepthResolveInterface), "GPUDepthResolveInterface");
-
- interface->depth_uniform = GPU_shader_get_uniform(shader, "depthbuffer");
-
- GPU_shader_set_interface(shader, interface);
- break;
- }
-
- default:
- break;
- }
-}
-
diff --git a/source/blender/gpu/intern/gpu_debug.c b/source/blender/gpu/intern/gpu_debug.c
index 859aab9565f..8aea87ef659 100644
--- a/source/blender/gpu/intern/gpu_debug.c
+++ b/source/blender/gpu/intern/gpu_debug.c
@@ -20,7 +20,7 @@
*
* The Original Code is: all of this file.
*
- * Contributor(s): Brecht Van Lommel, Jason Wilkins.
+ * Contributor(s): Brecht Van Lommel, Jason Wilkins, Mike Erwin.
*
* ***** END GPL LICENSE BLOCK *****
*/
@@ -44,122 +44,18 @@
#include <stdlib.h>
#include <string.h>
-#define CASE_CODE_RETURN_STR(code) case code: return #code;
+#ifndef __APPLE__ /* only non-Apple systems implement OpenGL debug callbacks */
-static const char *gpu_gl_error_symbol(GLenum err)
-{
- switch (err) {
- CASE_CODE_RETURN_STR(GL_NO_ERROR)
- CASE_CODE_RETURN_STR(GL_INVALID_ENUM)
- CASE_CODE_RETURN_STR(GL_INVALID_VALUE)
- CASE_CODE_RETURN_STR(GL_INVALID_OPERATION)
- CASE_CODE_RETURN_STR(GL_STACK_OVERFLOW)
- CASE_CODE_RETURN_STR(GL_STACK_UNDERFLOW)
- CASE_CODE_RETURN_STR(GL_OUT_OF_MEMORY)
-
-#if GL_ARB_imaging
- CASE_CODE_RETURN_STR(GL_TABLE_TOO_LARGE)
-#endif
-
-#if defined(WITH_GLU)
- CASE_CODE_RETURN_STR(GLU_INVALID_ENUM)
- CASE_CODE_RETURN_STR(GLU_INVALID_VALUE)
- CASE_CODE_RETURN_STR(GLU_OUT_OF_MEMORY)
-#endif
+/* control whether we use older AMD_debug_output extension
+ * some supported GPU + OS combos do not have the newer extensions */
+# define LEGACY_DEBUG 1
- default:
- return "<unknown error>";
- }
-}
-
-#undef CASE_CODE_RETURN_STR
-
-
-static bool gpu_report_gl_errors(const char *file, int line, const char *str)
-{
- GLenum gl_error = glGetError();
-
- if (gl_error == GL_NO_ERROR) {
- return true;
- }
- else {
- /* glGetError should have cleared the error flag, so if we get the
- * same flag twice that means glGetError itself probably triggered
- * the error. This happens on Windows if the GL context is invalid.
- */
- {
- GLenum new_error = glGetError();
- if (gl_error == new_error) {
- fprintf(stderr, "GL: Possible context invalidation issue\n");
- return false;
- }
- }
-
- fprintf(stderr,
- "%s:%d: ``%s'' -> GL Error (0x%04X - %s): %s\n",
- file, line, str, gl_error,
- gpu_gl_error_symbol(gl_error),
- gpuErrorString(gl_error));
-
- return false;
- }
-}
-
-
-const char *gpuErrorString(GLenum err)
-{
- switch (err) {
- case GL_NO_ERROR:
- return "No Error";
-
- case GL_INVALID_ENUM:
- return "Invalid Enumeration";
-
- case GL_INVALID_VALUE:
- return "Invalid Value";
-
- case GL_INVALID_OPERATION:
- return "Invalid Operation";
-
- case GL_STACK_OVERFLOW:
- return "Stack Overflow";
-
- case GL_STACK_UNDERFLOW:
- return "Stack Underflow";
-
- case GL_OUT_OF_MEMORY:
- return "Out of Memory";
-
-#if GL_ARB_imaging
- case GL_TABLE_TOO_LARGE:
- return "Table Too Large";
-#endif
-
-#if defined(WITH_GLU)
- case GLU_INVALID_ENUM:
- return "Invalid Enum (GLU)";
-
- case GLU_INVALID_VALUE:
- return "Invalid Value (GLU)";
-
- case GLU_OUT_OF_MEMORY:
- return "Out of Memory (GLU)";
-#endif
-
- default:
- return "<unknown error>";
- }
-}
-
-
-/* Debug callbacks need the same calling convention as OpenGL functions.
- */
-#if defined(_WIN32) && !defined(_WIN32_WCE) && !defined(__SCITECH_SNAP__)
- /* Win32 but not WinCE */
-# define APIENTRY __stdcall
-#else
-# define APIENTRY
-#endif
+/* Debug callbacks need the same calling convention as OpenGL functions. */
+# if defined(_WIN32)
+# define APIENTRY __stdcall
+# else
+# define APIENTRY
+# endif
static const char *source_name(GLenum source)
@@ -189,32 +85,11 @@ static const char *message_type_name(GLenum message)
}
}
-static const char *category_name_amd(GLenum category)
-{
- switch (category) {
- case GL_DEBUG_CATEGORY_API_ERROR_AMD: return "API error";
- case GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD: return "window system";
- case GL_DEBUG_CATEGORY_DEPRECATION_AMD: return "deprecated behavior";
- case GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD: return "undefined behavior";
- case GL_DEBUG_CATEGORY_PERFORMANCE_AMD: return "performance";
- case GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD: return "shader compiler";
- case GL_DEBUG_CATEGORY_APPLICATION_AMD: return "application";
- case GL_DEBUG_CATEGORY_OTHER_AMD: return "other";
- default: return "???";
- }
-}
-
-
static void APIENTRY gpu_debug_proc(
GLenum source, GLenum type, GLuint UNUSED(id),
GLenum severity, GLsizei UNUSED(length),
const GLchar *message, const GLvoid *UNUSED(userParm))
{
- if (type == GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR) {
- /* Blender 2.7x uses OpenGL 2.1, we don't care if features are deprecated */
- return;
- }
-
bool backtrace = false;
switch (severity) {
@@ -233,18 +108,28 @@ static void APIENTRY gpu_debug_proc(
}
}
+# if LEGACY_DEBUG
+
+static const char *category_name_amd(GLenum category)
+{
+ switch (category) {
+ case GL_DEBUG_CATEGORY_API_ERROR_AMD: return "API error";
+ case GL_DEBUG_CATEGORY_WINDOW_SYSTEM_AMD: return "window system";
+ case GL_DEBUG_CATEGORY_DEPRECATION_AMD: return "deprecated behavior";
+ case GL_DEBUG_CATEGORY_UNDEFINED_BEHAVIOR_AMD: return "undefined behavior";
+ case GL_DEBUG_CATEGORY_PERFORMANCE_AMD: return "performance";
+ case GL_DEBUG_CATEGORY_SHADER_COMPILER_AMD: return "shader compiler";
+ case GL_DEBUG_CATEGORY_APPLICATION_AMD: return "application";
+ case GL_DEBUG_CATEGORY_OTHER_AMD: return "other";
+ default: return "???";
+ }
+}
-#ifndef GLEW_ES_ONLY
static void APIENTRY gpu_debug_proc_amd(
GLuint UNUSED(id), GLenum category,
GLenum severity, GLsizei UNUSED(length),
const GLchar *message, GLvoid *UNUSED(userParm))
{
- if (category == GL_DEBUG_CATEGORY_DEPRECATION_AMD) {
- /* Blender 2.7x uses OpenGL 2.1, we don't care if features are deprecated */
- return;
- }
-
bool backtrace = false;
switch (severity) {
@@ -261,148 +146,88 @@ static void APIENTRY gpu_debug_proc_amd(
fflush(stderr);
}
}
-#endif
+# endif /* LEGACY_DEBUG */
-
-#undef APIENTRY
+# undef APIENTRY
+#endif /* not Apple */
void gpu_debug_init(void)
{
+#ifdef __APPLE__
+ fprintf(stderr, "OpenGL debug callback is not available on Apple.\n");
+#else /* not Apple */
const char success[] = "Successfully hooked OpenGL debug callback.";
-#if !defined(WITH_GLEW_ES) && !defined(GLEW_ES_ONLY)
- if (GLEW_VERSION_4_3) {
- fprintf(stderr, "Using OpenGL 4.3 debug facilities\n");
- glEnable(GL_DEBUG_OUTPUT);
- glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
- glDebugMessageCallback((GLDEBUGPROC)gpu_debug_proc, mxGetCurrentContext());
- glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
- GPU_string_marker(success);
- return;
- }
-#endif
-
- if (GLEW_KHR_debug) {
-#ifndef GLEW_ES_ONLY
- fprintf(stderr, "Using KHR_debug extension\n");
+ if (GLEW_VERSION_4_3 || GLEW_KHR_debug) {
+ fprintf(stderr, "Using %s\n", GLEW_VERSION_4_3 ? "OpenGL 4.3 debug facilities" : "KHR_debug extension");
glEnable(GL_DEBUG_OUTPUT);
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
- glDebugMessageCallback((GLDEBUGPROC)gpu_debug_proc, mxGetCurrentContext());
+ glDebugMessageCallback((GLDEBUGPROC)gpu_debug_proc, NULL);
glDebugMessageControl(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
GPU_string_marker(success);
-#endif
- return;
}
-
-#ifndef GLEW_ES_ONLY
- if (GLEW_ARB_debug_output) {
+ else if (GLEW_ARB_debug_output) {
fprintf(stderr, "Using ARB_debug_output extension\n");
glEnable(GL_DEBUG_OUTPUT_SYNCHRONOUS);
- glDebugMessageCallbackARB((GLDEBUGPROCARB)gpu_debug_proc, mxGetCurrentContext());
+ glDebugMessageCallbackARB((GLDEBUGPROCARB)gpu_debug_proc, NULL);
glDebugMessageControlARB(GL_DONT_CARE, GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
GPU_string_marker(success);
-
- return;
}
-
- if (GLEW_AMD_debug_output) {
+# if LEGACY_DEBUG
+ else if (GLEW_AMD_debug_output) {
fprintf(stderr, "Using AMD_debug_output extension\n");
- glDebugMessageCallbackAMD(gpu_debug_proc_amd, mxGetCurrentContext());
+ glDebugMessageCallbackAMD(gpu_debug_proc_amd, NULL);
glDebugMessageEnableAMD(GL_DONT_CARE, GL_DONT_CARE, 0, NULL, GL_TRUE);
GPU_string_marker(success);
-
- return;
}
-#endif
-
- fprintf(stderr, "Failed to hook OpenGL debug callback.\n");
-
- return;
+# endif
+ else {
+ fprintf(stderr, "Failed to hook OpenGL debug callback.\n");
+ }
+#endif /* not Apple */
}
void gpu_debug_exit(void)
{
-#ifndef WITH_GLEW_ES
-#ifndef GLEW_ES_ONLY
- if (GLEW_VERSION_4_3) {
- glDebugMessageCallback(NULL, NULL);
-
- return;
- }
-#endif
-#endif
-
- if (GLEW_KHR_debug) {
-#ifndef GLEW_ES_ONLY
+#ifndef __APPLE__
+ if (GLEW_VERSION_4_3 || GLEW_KHR_debug) {
glDebugMessageCallback(NULL, NULL);
-#endif
- return;
}
-
-#ifndef GLEW_ES_ONLY
- if (GLEW_ARB_debug_output) {
+ else if (GLEW_ARB_debug_output) {
glDebugMessageCallbackARB(NULL, NULL);
-
- return;
}
-
- if (GLEW_AMD_debug_output) {
+# if LEGACY_DEBUG
+ else if (GLEW_AMD_debug_output) {
glDebugMessageCallbackAMD(NULL, NULL);
-
- return;
}
+# endif
#endif
-
- return;
}
void GPU_string_marker(const char *buf)
{
-#ifndef WITH_GLEW_ES
-#ifndef GLEW_ES_ONLY
- if (GLEW_VERSION_4_3) {
- glDebugMessageInsert(
- GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0,
- GL_DEBUG_SEVERITY_NOTIFICATION, -1, buf);
-
- return;
- }
-#endif
-#endif
-
- if (GLEW_KHR_debug) {
-#ifndef GLEW_ES_ONLY
+#ifdef __APPLE__
+ UNUSED_VARS(buf);
+#else /* not Apple */
+ if (GLEW_VERSION_4_3 || GLEW_KHR_debug) {
glDebugMessageInsert(
GL_DEBUG_SOURCE_APPLICATION, GL_DEBUG_TYPE_MARKER, 0,
GL_DEBUG_SEVERITY_NOTIFICATION, -1, buf);
-#endif
- return;
}
-
-#ifndef GLEW_ES_ONLY
- if (GLEW_ARB_debug_output) {
+ else if (GLEW_ARB_debug_output) {
glDebugMessageInsertARB(
GL_DEBUG_SOURCE_APPLICATION_ARB, GL_DEBUG_TYPE_OTHER_ARB, 0,
GL_DEBUG_SEVERITY_LOW_ARB, -1, buf);
-
- return;
}
-
- if (GLEW_AMD_debug_output) {
+# if LEGACY_DEBUG
+ else if (GLEW_AMD_debug_output) {
glDebugMessageInsertAMD(
GL_DEBUG_CATEGORY_APPLICATION_AMD, GL_DEBUG_SEVERITY_LOW_AMD, 0,
0, buf);
-
- return;
}
-
- if (GLEW_GREMEDY_string_marker) {
- glStringMarkerGREMEDY(0, buf);
-
- return;
- }
-#endif
+# endif
+#endif /* not Apple */
}
void GPU_print_error_debug(const char *str)
@@ -410,406 +235,3 @@ void GPU_print_error_debug(const char *str)
if (G.debug & G_DEBUG)
fprintf(stderr, "GPU: %s\n", str);
}
-
-
-void GPU_assert_no_gl_errors(const char *file, int line, const char *str)
-{
- if (G.debug) {
- GLboolean gl_ok = gpu_report_gl_errors(file, line, str);
-
- BLI_assert(gl_ok);
- (void) gl_ok;
- }
-}
-
-
-static void gpu_state_print_fl_ex(const char *name, GLenum type)
-{
-#define MAX_ARRAY_SIZE 64
-
- const unsigned char err_mark[4] = {0xff, 0xff, 0xff, 0xff};
-
- float value[MAX_ARRAY_SIZE];
- int a;
-
- memset(value, 0xff, sizeof(value));
- glGetFloatv(type, value);
-
- if (glGetError() == GL_NO_ERROR) {
- printf("%s: ", name);
- for (a = 0; a < MAX_ARRAY_SIZE; a++) {
- if (memcmp(&value[a], err_mark, sizeof(value[a])) == 0) {
- break;
- }
- printf("%.2f ", value[a]);
- }
- printf("\n");
- }
-
-#undef MAX_ARRAY_SIZE
-}
-
-#define gpu_state_print_fl(val) gpu_state_print_fl_ex(#val, val)
-
-void GPU_state_print(void)
-{
- GPU_ASSERT_NO_GL_ERRORS("GPU_state_print"); /* clear any errors */
-
- gpu_state_print_fl(GL_ACCUM_ALPHA_BITS);
- gpu_state_print_fl(GL_ACCUM_BLUE_BITS);
- gpu_state_print_fl(GL_ACCUM_CLEAR_VALUE);
- gpu_state_print_fl(GL_ACCUM_GREEN_BITS);
- gpu_state_print_fl(GL_ACCUM_RED_BITS);
- gpu_state_print_fl(GL_ACTIVE_TEXTURE);
- gpu_state_print_fl(GL_ALIASED_LINE_WIDTH_RANGE);
- gpu_state_print_fl(GL_ALIASED_POINT_SIZE_RANGE);
- gpu_state_print_fl(GL_ALPHA_BIAS);
- gpu_state_print_fl(GL_ALPHA_BITS);
- gpu_state_print_fl(GL_ALPHA_SCALE);
- gpu_state_print_fl(GL_ALPHA_TEST);
- gpu_state_print_fl(GL_ALPHA_TEST_FUNC);
- gpu_state_print_fl(GL_ALPHA_TEST_REF);
- gpu_state_print_fl(GL_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_ATTRIB_STACK_DEPTH);
- gpu_state_print_fl(GL_AUTO_NORMAL);
- gpu_state_print_fl(GL_AUX_BUFFERS);
- gpu_state_print_fl(GL_BLEND);
- gpu_state_print_fl(GL_BLEND_COLOR);
- gpu_state_print_fl(GL_BLEND_DST_ALPHA);
- gpu_state_print_fl(GL_BLEND_DST_RGB);
- gpu_state_print_fl(GL_BLEND_EQUATION_ALPHA);
- gpu_state_print_fl(GL_BLEND_EQUATION_RGB);
- gpu_state_print_fl(GL_BLEND_SRC_ALPHA);
- gpu_state_print_fl(GL_BLEND_SRC_RGB);
- gpu_state_print_fl(GL_BLUE_BIAS);
- gpu_state_print_fl(GL_BLUE_BITS);
- gpu_state_print_fl(GL_BLUE_SCALE);
- gpu_state_print_fl(GL_CLIENT_ACTIVE_TEXTURE);
- gpu_state_print_fl(GL_CLIENT_ATTRIB_STACK_DEPTH);
- gpu_state_print_fl(GL_CLIP_PLANE0);
- gpu_state_print_fl(GL_COLOR_ARRAY);
- gpu_state_print_fl(GL_COLOR_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_COLOR_ARRAY_SIZE);
- gpu_state_print_fl(GL_COLOR_ARRAY_STRIDE);
- gpu_state_print_fl(GL_COLOR_ARRAY_TYPE);
- gpu_state_print_fl(GL_COLOR_CLEAR_VALUE);
- gpu_state_print_fl(GL_COLOR_LOGIC_OP);
- gpu_state_print_fl(GL_COLOR_MATERIAL);
- gpu_state_print_fl(GL_COLOR_MATERIAL_FACE);
- gpu_state_print_fl(GL_COLOR_MATERIAL_PARAMETER);
- gpu_state_print_fl(GL_COLOR_MATRIX);
- gpu_state_print_fl(GL_COLOR_MATRIX_STACK_DEPTH);
- gpu_state_print_fl(GL_COLOR_SUM);
- gpu_state_print_fl(GL_COLOR_TABLE);
- gpu_state_print_fl(GL_COLOR_WRITEMASK);
- gpu_state_print_fl(GL_NUM_COMPRESSED_TEXTURE_FORMATS);
- gpu_state_print_fl(GL_COMPRESSED_TEXTURE_FORMATS);
- gpu_state_print_fl(GL_CONVOLUTION_1D);
- gpu_state_print_fl(GL_CONVOLUTION_2D);
- gpu_state_print_fl(GL_CULL_FACE);
- gpu_state_print_fl(GL_CULL_FACE_MODE);
- gpu_state_print_fl(GL_CURRENT_COLOR);
- gpu_state_print_fl(GL_CURRENT_FOG_COORD);
- gpu_state_print_fl(GL_CURRENT_INDEX);
- gpu_state_print_fl(GL_CURRENT_NORMAL);
- gpu_state_print_fl(GL_CURRENT_PROGRAM);
- gpu_state_print_fl(GL_CURRENT_RASTER_COLOR);
- gpu_state_print_fl(GL_CURRENT_RASTER_DISTANCE);
- gpu_state_print_fl(GL_CURRENT_RASTER_INDEX);
- gpu_state_print_fl(GL_CURRENT_RASTER_POSITION);
- gpu_state_print_fl(GL_CURRENT_RASTER_POSITION_VALID);
- gpu_state_print_fl(GL_CURRENT_RASTER_SECONDARY_COLOR);
- gpu_state_print_fl(GL_CURRENT_RASTER_TEXTURE_COORDS);
- gpu_state_print_fl(GL_CURRENT_SECONDARY_COLOR);
- gpu_state_print_fl(GL_CURRENT_TEXTURE_COORDS);
- gpu_state_print_fl(GL_DEPTH_BIAS);
- gpu_state_print_fl(GL_DEPTH_BITS);
- gpu_state_print_fl(GL_DEPTH_CLEAR_VALUE);
- gpu_state_print_fl(GL_DEPTH_FUNC);
- gpu_state_print_fl(GL_DEPTH_RANGE);
- gpu_state_print_fl(GL_DEPTH_SCALE);
- gpu_state_print_fl(GL_DEPTH_TEST);
- gpu_state_print_fl(GL_DEPTH_WRITEMASK);
- gpu_state_print_fl(GL_DITHER);
- gpu_state_print_fl(GL_DOUBLEBUFFER);
- gpu_state_print_fl(GL_DRAW_BUFFER);
- gpu_state_print_fl(GL_DRAW_BUFFER0);
- gpu_state_print_fl(GL_EDGE_FLAG);
- gpu_state_print_fl(GL_EDGE_FLAG_ARRAY);
- gpu_state_print_fl(GL_EDGE_FLAG_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_EDGE_FLAG_ARRAY_STRIDE);
- gpu_state_print_fl(GL_ELEMENT_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_FEEDBACK_BUFFER_SIZE);
- gpu_state_print_fl(GL_FEEDBACK_BUFFER_TYPE);
- gpu_state_print_fl(GL_FOG);
- gpu_state_print_fl(GL_FOG_COLOR);
- gpu_state_print_fl(GL_FOG_COORD_ARRAY);
- gpu_state_print_fl(GL_FOG_COORD_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_FOG_COORD_ARRAY_STRIDE);
- gpu_state_print_fl(GL_FOG_COORD_ARRAY_TYPE);
- gpu_state_print_fl(GL_FOG_COORD_SRC);
- gpu_state_print_fl(GL_FOG_DENSITY);
- gpu_state_print_fl(GL_FOG_END);
- gpu_state_print_fl(GL_FOG_HINT);
- gpu_state_print_fl(GL_FOG_INDEX);
- gpu_state_print_fl(GL_FOG_MODE);
- gpu_state_print_fl(GL_FOG_START);
- gpu_state_print_fl(GL_FRAGMENT_PROGRAM_ARB); /* TODO: remove ARB program support */
- gpu_state_print_fl(GL_FRAGMENT_SHADER_DERIVATIVE_HINT);
- gpu_state_print_fl(GL_FRONT_FACE);
- gpu_state_print_fl(GL_GENERATE_MIPMAP_HINT);
- gpu_state_print_fl(GL_GREEN_BIAS);
- gpu_state_print_fl(GL_GREEN_BITS);
- gpu_state_print_fl(GL_GREEN_SCALE);
- gpu_state_print_fl(GL_HISTOGRAM);
- gpu_state_print_fl(GL_INDEX_ARRAY);
- gpu_state_print_fl(GL_INDEX_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_INDEX_ARRAY_STRIDE);
- gpu_state_print_fl(GL_INDEX_ARRAY_TYPE);
- gpu_state_print_fl(GL_INDEX_BITS);
- gpu_state_print_fl(GL_INDEX_CLEAR_VALUE);
- gpu_state_print_fl(GL_INDEX_LOGIC_OP);
- gpu_state_print_fl(GL_INDEX_MODE);
- gpu_state_print_fl(GL_INDEX_OFFSET);
- gpu_state_print_fl(GL_INDEX_SHIFT);
- gpu_state_print_fl(GL_INDEX_WRITEMASK);
- gpu_state_print_fl(GL_LIGHT0);
- gpu_state_print_fl(GL_LIGHT1);
- gpu_state_print_fl(GL_LIGHT2);
- gpu_state_print_fl(GL_LIGHT3);
- gpu_state_print_fl(GL_LIGHT4);
- gpu_state_print_fl(GL_LIGHT5);
- gpu_state_print_fl(GL_LIGHT6);
- gpu_state_print_fl(GL_LIGHT7);
- gpu_state_print_fl(GL_LIGHTING);
- gpu_state_print_fl(GL_LIGHT_MODEL_AMBIENT);
- gpu_state_print_fl(GL_LIGHT_MODEL_COLOR_CONTROL);
- gpu_state_print_fl(GL_LIGHT_MODEL_LOCAL_VIEWER);
- gpu_state_print_fl(GL_LIGHT_MODEL_TWO_SIDE);
- gpu_state_print_fl(GL_LINE_SMOOTH);
- gpu_state_print_fl(GL_LINE_SMOOTH_HINT);
- gpu_state_print_fl(GL_LINE_STIPPLE);
- gpu_state_print_fl(GL_LINE_STIPPLE_PATTERN);
- gpu_state_print_fl(GL_LINE_STIPPLE_REPEAT);
- gpu_state_print_fl(GL_LINE_WIDTH);
- gpu_state_print_fl(GL_LINE_WIDTH_GRANULARITY);
- gpu_state_print_fl(GL_LINE_WIDTH_RANGE);
- gpu_state_print_fl(GL_LIST_BASE);
- gpu_state_print_fl(GL_LIST_INDEX);
- gpu_state_print_fl(GL_LIST_MODE);
- gpu_state_print_fl(GL_LOGIC_OP);
- gpu_state_print_fl(GL_LOGIC_OP_MODE);
- gpu_state_print_fl(GL_MAP1_COLOR_4);
- gpu_state_print_fl(GL_MAP1_GRID_DOMAIN);
- gpu_state_print_fl(GL_MAP1_GRID_SEGMENTS);
- gpu_state_print_fl(GL_MAP1_INDEX);
- gpu_state_print_fl(GL_MAP1_NORMAL);
- gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_1);
- gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_2);
- gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_3);
- gpu_state_print_fl(GL_MAP1_TEXTURE_COORD_4);
- gpu_state_print_fl(GL_MAP1_VERTEX_3);
- gpu_state_print_fl(GL_MAP1_VERTEX_4);
- gpu_state_print_fl(GL_MAP2_COLOR_4);
- gpu_state_print_fl(GL_MAP2_GRID_DOMAIN);
- gpu_state_print_fl(GL_MAP2_GRID_SEGMENTS);
- gpu_state_print_fl(GL_MAP2_INDEX);
- gpu_state_print_fl(GL_MAP2_NORMAL);
- gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_1);
- gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_2);
- gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_3);
- gpu_state_print_fl(GL_MAP2_TEXTURE_COORD_4);
- gpu_state_print_fl(GL_MAP2_VERTEX_3);
- gpu_state_print_fl(GL_MAP2_VERTEX_4);
- gpu_state_print_fl(GL_MAP_COLOR);
- gpu_state_print_fl(GL_MAP_STENCIL);
- gpu_state_print_fl(GL_MATRIX_MODE);
- gpu_state_print_fl(GL_MAX_3D_TEXTURE_SIZE);
- gpu_state_print_fl(GL_MAX_ATTRIB_STACK_DEPTH);
- gpu_state_print_fl(GL_MAX_CLIENT_ATTRIB_STACK_DEPTH);
- gpu_state_print_fl(GL_MAX_CLIP_PLANES);
- gpu_state_print_fl(GL_MAX_COLOR_MATRIX_STACK_DEPTH);
- gpu_state_print_fl(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS);
- gpu_state_print_fl(GL_MAX_CUBE_MAP_TEXTURE_SIZE);
- gpu_state_print_fl(GL_MAX_DRAW_BUFFERS);
- gpu_state_print_fl(GL_MAX_ELEMENTS_INDICES);
- gpu_state_print_fl(GL_MAX_ELEMENTS_VERTICES);
- gpu_state_print_fl(GL_MAX_EVAL_ORDER);
- gpu_state_print_fl(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS);
- gpu_state_print_fl(GL_MAX_LIGHTS);
- gpu_state_print_fl(GL_MAX_LIST_NESTING);
- gpu_state_print_fl(GL_MAX_MODELVIEW_STACK_DEPTH);
- gpu_state_print_fl(GL_MAX_NAME_STACK_DEPTH);
- gpu_state_print_fl(GL_MAX_PIXEL_MAP_TABLE);
- gpu_state_print_fl(GL_MAX_PROJECTION_STACK_DEPTH);
- gpu_state_print_fl(GL_MAX_TEXTURE_COORDS);
- gpu_state_print_fl(GL_MAX_TEXTURE_IMAGE_UNITS);
- gpu_state_print_fl(GL_MAX_TEXTURE_LOD_BIAS);
- gpu_state_print_fl(GL_MAX_TEXTURE_SIZE);
- gpu_state_print_fl(GL_MAX_TEXTURE_STACK_DEPTH);
- gpu_state_print_fl(GL_MAX_TEXTURE_UNITS);
- gpu_state_print_fl(GL_MAX_VARYING_FLOATS);
- gpu_state_print_fl(GL_MAX_VERTEX_ATTRIBS);
- gpu_state_print_fl(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS);
- gpu_state_print_fl(GL_MAX_VERTEX_UNIFORM_COMPONENTS);
- gpu_state_print_fl(GL_MAX_VIEWPORT_DIMS);
- gpu_state_print_fl(GL_MINMAX);
- gpu_state_print_fl(GL_MODELVIEW_MATRIX);
- gpu_state_print_fl(GL_MODELVIEW_STACK_DEPTH);
- gpu_state_print_fl(GL_MULTISAMPLE);
- gpu_state_print_fl(GL_NAME_STACK_DEPTH);
- gpu_state_print_fl(GL_NORMALIZE);
- gpu_state_print_fl(GL_NORMAL_ARRAY);
- gpu_state_print_fl(GL_NORMAL_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_NORMAL_ARRAY_STRIDE);
- gpu_state_print_fl(GL_NORMAL_ARRAY_TYPE);
- gpu_state_print_fl(GL_NUM_COMPRESSED_TEXTURE_FORMATS);
- gpu_state_print_fl(GL_PACK_ALIGNMENT);
- gpu_state_print_fl(GL_PACK_IMAGE_HEIGHT);
- gpu_state_print_fl(GL_PACK_LSB_FIRST);
- gpu_state_print_fl(GL_PACK_ROW_LENGTH);
- gpu_state_print_fl(GL_PACK_SKIP_IMAGES);
- gpu_state_print_fl(GL_PACK_SKIP_PIXELS);
- gpu_state_print_fl(GL_PACK_SKIP_ROWS);
- gpu_state_print_fl(GL_PACK_SWAP_BYTES);
- gpu_state_print_fl(GL_PERSPECTIVE_CORRECTION_HINT);
- gpu_state_print_fl(GL_PIXEL_MAP_A_TO_A_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_B_TO_B_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_G_TO_G_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_I_TO_A_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_I_TO_B_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_I_TO_G_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_I_TO_I_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_I_TO_R_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_R_TO_R_SIZE);
- gpu_state_print_fl(GL_PIXEL_MAP_S_TO_S_SIZE);
- gpu_state_print_fl(GL_PIXEL_PACK_BUFFER_BINDING);
- gpu_state_print_fl(GL_PIXEL_UNPACK_BUFFER_BINDING);
- gpu_state_print_fl(GL_POINT_DISTANCE_ATTENUATION);
- gpu_state_print_fl(GL_POINT_FADE_THRESHOLD_SIZE);
- gpu_state_print_fl(GL_POINT_SIZE);
- gpu_state_print_fl(GL_POINT_SIZE_GRANULARITY);
- gpu_state_print_fl(GL_POINT_SIZE_MAX);
- gpu_state_print_fl(GL_POINT_SIZE_MIN);
- gpu_state_print_fl(GL_POINT_SIZE_RANGE);
- gpu_state_print_fl(GL_POINT_SMOOTH);
- gpu_state_print_fl(GL_POINT_SMOOTH_HINT);
- gpu_state_print_fl(GL_POINT_SPRITE);
- gpu_state_print_fl(GL_POLYGON_MODE);
- gpu_state_print_fl(GL_POLYGON_OFFSET_FACTOR);
- gpu_state_print_fl(GL_POLYGON_OFFSET_FILL);
- gpu_state_print_fl(GL_POLYGON_OFFSET_LINE);
- gpu_state_print_fl(GL_POLYGON_OFFSET_POINT);
- gpu_state_print_fl(GL_POLYGON_OFFSET_UNITS);
- gpu_state_print_fl(GL_POLYGON_SMOOTH);
- gpu_state_print_fl(GL_POLYGON_SMOOTH_HINT);
- gpu_state_print_fl(GL_POLYGON_STIPPLE);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_ALPHA_BIAS);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_ALPHA_SCALE);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_BLUE_BIAS);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_BLUE_SCALE);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_COLOR_TABLE);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_GREEN_BIAS);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_GREEN_SCALE);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_RED_BIAS);
- gpu_state_print_fl(GL_POST_COLOR_MATRIX_RED_SCALE);
- gpu_state_print_fl(GL_POST_CONVOLUTION_ALPHA_BIAS);
- gpu_state_print_fl(GL_POST_CONVOLUTION_ALPHA_SCALE);
- gpu_state_print_fl(GL_POST_CONVOLUTION_BLUE_BIAS);
- gpu_state_print_fl(GL_POST_CONVOLUTION_BLUE_SCALE);
- gpu_state_print_fl(GL_POST_CONVOLUTION_COLOR_TABLE);
- gpu_state_print_fl(GL_POST_CONVOLUTION_GREEN_BIAS);
- gpu_state_print_fl(GL_POST_CONVOLUTION_GREEN_SCALE);
- gpu_state_print_fl(GL_POST_CONVOLUTION_RED_BIAS);
- gpu_state_print_fl(GL_POST_CONVOLUTION_RED_SCALE);
- gpu_state_print_fl(GL_PROJECTION_MATRIX);
- gpu_state_print_fl(GL_PROJECTION_STACK_DEPTH);
- gpu_state_print_fl(GL_READ_BUFFER);
- gpu_state_print_fl(GL_RED_BIAS);
- gpu_state_print_fl(GL_RED_BITS);
- gpu_state_print_fl(GL_RED_SCALE);
- gpu_state_print_fl(GL_RENDER_MODE);
- gpu_state_print_fl(GL_RESCALE_NORMAL);
- gpu_state_print_fl(GL_RGBA_MODE);
- gpu_state_print_fl(GL_SAMPLES);
- gpu_state_print_fl(GL_SAMPLE_BUFFERS);
- gpu_state_print_fl(GL_SAMPLE_COVERAGE_INVERT);
- gpu_state_print_fl(GL_SAMPLE_COVERAGE_VALUE);
- gpu_state_print_fl(GL_SCISSOR_BOX);
- gpu_state_print_fl(GL_SCISSOR_TEST);
- gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY);
- gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_SIZE);
- gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_STRIDE);
- gpu_state_print_fl(GL_SECONDARY_COLOR_ARRAY_TYPE);
- gpu_state_print_fl(GL_SELECTION_BUFFER_SIZE);
- gpu_state_print_fl(GL_SEPARABLE_2D);
- gpu_state_print_fl(GL_SHADE_MODEL);
- gpu_state_print_fl(GL_SMOOTH_LINE_WIDTH_GRANULARITY);
- gpu_state_print_fl(GL_SMOOTH_LINE_WIDTH_RANGE);
- gpu_state_print_fl(GL_SMOOTH_POINT_SIZE_GRANULARITY);
- gpu_state_print_fl(GL_SMOOTH_POINT_SIZE_RANGE);
- gpu_state_print_fl(GL_STENCIL_BACK_FAIL);
- gpu_state_print_fl(GL_STENCIL_BACK_FUNC);
- gpu_state_print_fl(GL_STENCIL_BACK_PASS_DEPTH_FAIL);
- gpu_state_print_fl(GL_STENCIL_BACK_PASS_DEPTH_PASS);
- gpu_state_print_fl(GL_STENCIL_BACK_REF);
- gpu_state_print_fl(GL_STENCIL_BACK_VALUE_MASK);
- gpu_state_print_fl(GL_STENCIL_BACK_WRITEMASK);
- gpu_state_print_fl(GL_STENCIL_BITS);
- gpu_state_print_fl(GL_STENCIL_CLEAR_VALUE);
- gpu_state_print_fl(GL_STENCIL_FAIL);
- gpu_state_print_fl(GL_STENCIL_FUNC);
- gpu_state_print_fl(GL_STENCIL_PASS_DEPTH_FAIL);
- gpu_state_print_fl(GL_STENCIL_PASS_DEPTH_PASS);
- gpu_state_print_fl(GL_STENCIL_REF);
- gpu_state_print_fl(GL_STENCIL_TEST);
- gpu_state_print_fl(GL_STENCIL_VALUE_MASK);
- gpu_state_print_fl(GL_STENCIL_WRITEMASK);
- gpu_state_print_fl(GL_STEREO);
- gpu_state_print_fl(GL_SUBPIXEL_BITS);
- gpu_state_print_fl(GL_TEXTURE_1D);
- gpu_state_print_fl(GL_TEXTURE_2D);
- gpu_state_print_fl(GL_TEXTURE_3D);
- gpu_state_print_fl(GL_TEXTURE_BINDING_1D);
- gpu_state_print_fl(GL_TEXTURE_BINDING_2D);
- gpu_state_print_fl(GL_TEXTURE_BINDING_3D);
- gpu_state_print_fl(GL_TEXTURE_BINDING_CUBE_MAP);
- gpu_state_print_fl(GL_TEXTURE_COMPRESSION_HINT);
- gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY);
- gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_SIZE);
- gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_STRIDE);
- gpu_state_print_fl(GL_TEXTURE_COORD_ARRAY_TYPE);
- gpu_state_print_fl(GL_TEXTURE_CUBE_MAP);
- gpu_state_print_fl(GL_TEXTURE_GEN_Q);
- gpu_state_print_fl(GL_TEXTURE_GEN_R);
- gpu_state_print_fl(GL_TEXTURE_GEN_S);
- gpu_state_print_fl(GL_TEXTURE_GEN_T);
- gpu_state_print_fl(GL_TEXTURE_MATRIX);
- gpu_state_print_fl(GL_TEXTURE_STACK_DEPTH);
- gpu_state_print_fl(GL_TRANSPOSE_COLOR_MATRIX);
- gpu_state_print_fl(GL_TRANSPOSE_MODELVIEW_MATRIX);
- gpu_state_print_fl(GL_TRANSPOSE_PROJECTION_MATRIX);
- gpu_state_print_fl(GL_TRANSPOSE_TEXTURE_MATRIX);
- gpu_state_print_fl(GL_UNPACK_ALIGNMENT);
- gpu_state_print_fl(GL_UNPACK_IMAGE_HEIGHT);
- gpu_state_print_fl(GL_UNPACK_LSB_FIRST);
- gpu_state_print_fl(GL_UNPACK_ROW_LENGTH);
- gpu_state_print_fl(GL_UNPACK_SKIP_IMAGES);
- gpu_state_print_fl(GL_UNPACK_SKIP_PIXELS);
- gpu_state_print_fl(GL_UNPACK_SKIP_ROWS);
- gpu_state_print_fl(GL_UNPACK_SWAP_BYTES);
- gpu_state_print_fl(GL_VERTEX_ARRAY);
- gpu_state_print_fl(GL_VERTEX_ARRAY_BUFFER_BINDING);
- gpu_state_print_fl(GL_VERTEX_ARRAY_SIZE);
- gpu_state_print_fl(GL_VERTEX_ARRAY_STRIDE);
- gpu_state_print_fl(GL_VERTEX_ARRAY_TYPE);
- gpu_state_print_fl(GL_VERTEX_PROGRAM_POINT_SIZE);
- gpu_state_print_fl(GL_VERTEX_PROGRAM_TWO_SIDE);
- gpu_state_print_fl(GL_VIEWPORT);
- gpu_state_print_fl(GL_ZOOM_X);
- gpu_state_print_fl(GL_ZOOM_Y);
-}
-
-#undef gpu_state_print_fl
diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c
index 514f2f71bd7..7bfebb702a1 100644
--- a/source/blender/gpu/intern/gpu_draw.c
+++ b/source/blender/gpu/intern/gpu_draw.c
@@ -31,15 +31,13 @@
* Utility functions for dealing with OpenGL texture & material context,
* mipmap generation and light objects.
*
- * These are some obscure rendering functions shared between the
- * game engine and the blender, in this module to avoid duplication
+ * These are some obscure rendering functions shared between the game engine (not anymore)
+ * and the blender, in this module to avoid duplication
* and abstract them away from the rest a bit.
*/
#include <string.h>
-#include "GPU_glew.h"
-
#include "BLI_blenlib.h"
#include "BLI_hash.h"
#include "BLI_linklist.h"
@@ -72,15 +70,12 @@
#include "BKE_node.h"
#include "BKE_scene.h"
#include "BKE_DerivedMesh.h"
-#ifdef WITH_GAMEENGINE
-# include "BKE_object.h"
-#endif
#include "GPU_basic_shader.h"
-#include "GPU_buffers.h"
#include "GPU_draw.h"
#include "GPU_extensions.h"
#include "GPU_material.h"
+#include "GPU_matrix.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
@@ -99,141 +94,20 @@
extern Material defmaterial; /* from material.c */
-/* Text Rendering */
-
-static void gpu_mcol(unsigned int ucol)
-{
- /* mcol order is swapped */
- const char *cp = (char *)&ucol;
- glColor3ub(cp[3], cp[2], cp[1]);
-}
-
-void GPU_render_text(
- MTexPoly *mtexpoly, int mode,
- const char *textstr, int textlen, unsigned int *col,
- const float *v_quad[4], const float *uv_quad[4],
- int glattrib)
-{
- if ((mode & GEMAT_TEXT) && (textlen > 0) && mtexpoly->tpage) {
- const float *v1 = v_quad[0];
- const float *v2 = v_quad[1];
- const float *v3 = v_quad[2];
- const float *v4 = v_quad[3];
- Image *ima = (Image *)mtexpoly->tpage;
- const size_t textlen_st = textlen;
- float centerx, centery, sizex, sizey, transx, transy, movex, movey, advance;
-
- /* multiline */
- float line_start = 0.0f, line_height;
-
- if (v4)
- line_height = max_ffff(v1[1], v2[1], v3[1], v4[2]) - min_ffff(v1[1], v2[1], v3[1], v4[2]);
- else
- line_height = max_fff(v1[1], v2[1], v3[1]) - min_fff(v1[1], v2[1], v3[1]);
- line_height *= 1.2f; /* could be an option? */
- /* end multiline */
-
-
- /* color has been set */
- if (mtexpoly->mode & TF_OBCOL)
- col = NULL;
- else if (!col)
- glColor3f(1.0f, 1.0f, 1.0f);
-
- glPushMatrix();
-
- /* get the tab width */
- ImBuf *first_ibuf = BKE_image_get_first_ibuf(ima);
- matrixGlyph(first_ibuf, ' ', &centerx, &centery,
- &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
-
- float advance_tab = advance * 4; /* tab width could also be an option */
-
-
- for (size_t index = 0; index < textlen_st; ) {
- unsigned int character;
- float uv[4][2];
-
- /* lets calculate offset stuff */
- character = BLI_str_utf8_as_unicode_and_size_safe(textstr + index, &index);
-
- if (character == '\n') {
- glTranslatef(line_start, -line_height, 0.0f);
- line_start = 0.0f;
- continue;
- }
- else if (character == '\t') {
- glTranslatef(advance_tab, 0.0f, 0.0f);
- line_start -= advance_tab; /* so we can go back to the start of the line */
- continue;
-
- }
- else if (character > USHRT_MAX) {
- /* not much we can do here bmfonts take ushort */
- character = '?';
- }
-
- /* space starts at offset 1 */
- /* character = character - ' ' + 1; */
- matrixGlyph(first_ibuf, character, & centerx, &centery,
- &sizex, &sizey, &transx, &transy, &movex, &movey, &advance);
-
- uv[0][0] = (uv_quad[0][0] - centerx) * sizex + transx;
- uv[0][1] = (uv_quad[0][1] - centery) * sizey + transy;
- uv[1][0] = (uv_quad[1][0] - centerx) * sizex + transx;
- uv[1][1] = (uv_quad[1][1] - centery) * sizey + transy;
- uv[2][0] = (uv_quad[2][0] - centerx) * sizex + transx;
- uv[2][1] = (uv_quad[2][1] - centery) * sizey + transy;
-
- glBegin(GL_POLYGON);
- if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[0]);
- else glTexCoord2fv(uv[0]);
- if (col) gpu_mcol(col[0]);
- glVertex3f(sizex * v1[0] + movex, sizey * v1[1] + movey, v1[2]);
-
- if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[1]);
- else glTexCoord2fv(uv[1]);
- if (col) gpu_mcol(col[1]);
- glVertex3f(sizex * v2[0] + movex, sizey * v2[1] + movey, v2[2]);
-
- if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[2]);
- else glTexCoord2fv(uv[2]);
- if (col) gpu_mcol(col[2]);
- glVertex3f(sizex * v3[0] + movex, sizey * v3[1] + movey, v3[2]);
-
- if (v4) {
- uv[3][0] = (uv_quad[3][0] - centerx) * sizex + transx;
- uv[3][1] = (uv_quad[3][1] - centery) * sizey + transy;
-
- if (glattrib >= 0) glVertexAttrib2fv(glattrib, uv[3]);
- else glTexCoord2fv(uv[3]);
- if (col) gpu_mcol(col[3]);
- glVertex3f(sizex * v4[0] + movex, sizey * v4[1] + movey, v4[2]);
- }
- glEnd();
-
- glTranslatef(advance, 0.0f, 0.0f);
- line_start -= advance; /* so we can go back to the start of the line */
- }
- glPopMatrix();
-
- BKE_image_release_ibuf(ima, first_ibuf, NULL);
- }
-}
-
-/* Checking powers of two for images since OpenGL ES requires it */
-
+//* Checking powers of two for images since OpenGL ES requires it */
+#ifdef WITH_DDS
static bool is_power_of_2_resolution(int w, int h)
{
return is_power_of_2_i(w) && is_power_of_2_i(h);
}
+#endif
static bool is_over_resolution_limit(GLenum textarget, int w, int h)
{
int size = (textarget == GL_TEXTURE_2D) ?
GPU_max_texture_size() : GPU_max_cube_map_size();
int reslimit = (U.glreslimit != 0) ?
- min_ii(U.glreslimit, size) : size;
+ min_ii(U.glreslimit, size) : size;
return (w > reslimit || h > reslimit);
}
@@ -253,10 +127,6 @@ static int smaller_power_of_2_limit(int num)
/* Current OpenGL state caching for GPU_set_tpage */
static struct GPUTextureState {
- int curtile, tile;
- int curtilemode, tilemode;
- int curtileXRep, tileXRep;
- int curtileYRep, tileYRep;
Image *ima, *curima;
/* also controls min/mag filtering */
@@ -269,8 +139,7 @@ static struct GPUTextureState {
int alphablend;
float anisotropic;
int gpu_mipmap;
- MTexPoly *lasttface;
-} GTS = {0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, 1, 0, 0, -1, 1.0f, 0, NULL};
+} GTS = {NULL, NULL, 1, 0, 0, -1, 1.0f, 0};
/* Mipmap settings */
@@ -279,36 +148,13 @@ void GPU_set_gpu_mipmapping(int gpu_mipmap)
int old_value = GTS.gpu_mipmap;
/* only actually enable if it's supported */
- GTS.gpu_mipmap = gpu_mipmap && GLEW_EXT_framebuffer_object;
+ GTS.gpu_mipmap = gpu_mipmap;
if (old_value != GTS.gpu_mipmap) {
GPU_free_images();
}
}
-static void gpu_generate_mipmap(GLenum target)
-{
- const bool is_ati = GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY);
- int target_enabled = 0;
-
- /* work around bug in ATI driver, need to have GL_TEXTURE_2D enabled
- * http://www.opengl.org/wiki/Common_Mistakes#Automatic_mipmap_generation */
- if (is_ati) {
- target_enabled = glIsEnabled(target);
- if (!target_enabled)
- glEnable(target);
- }
-
- /* TODO: simplify when we transition to GL >= 3 */
- if (GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object)
- glGenerateMipmap(target);
- else if (GLEW_EXT_framebuffer_object)
- glGenerateMipmapEXT(target);
-
- if (is_ati && !target_enabled)
- glDisable(target);
-}
-
void GPU_set_mipmap(bool mipmap)
{
if (GTS.domipmap != mipmap) {
@@ -381,28 +227,6 @@ float GPU_get_anisotropic(void)
/* Set OpenGL state for an MTFace */
-static void gpu_make_repbind(Image *ima)
-{
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- if (ibuf == NULL)
- return;
-
- if (ima->repbind) {
- glDeleteTextures(ima->totbind, (GLuint *)ima->repbind);
- MEM_freeN(ima->repbind);
- ima->repbind = NULL;
- ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
- }
-
- ima->totbind = ima->xrep * ima->yrep;
-
- if (ima->totbind > 1) {
- ima->repbind = MEM_callocN(sizeof(int) * ima->totbind, "repbind");
- }
-
- BKE_image_release_ibuf(ima, ibuf, NULL);
-}
-
static unsigned int *gpu_get_image_bindcode(Image *ima, GLenum textarget)
{
unsigned int *bind = 0;
@@ -415,104 +239,6 @@ static unsigned int *gpu_get_image_bindcode(Image *ima, GLenum textarget)
return bind;
}
-void GPU_clear_tpage(bool force)
-{
- if (GTS.lasttface == NULL && !force)
- return;
-
- GTS.lasttface = NULL;
- GTS.curtile = 0;
- GTS.curima = NULL;
- if (GTS.curtilemode != 0) {
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- }
- GTS.curtilemode = 0;
- GTS.curtileXRep = 0;
- GTS.curtileYRep = 0;
- GTS.alphablend = -1;
-
- glDisable(GL_BLEND);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- glDisable(GL_ALPHA_TEST);
-}
-
-static void gpu_set_alpha_blend(GPUBlendMode alphablend)
-{
- if (alphablend == GPU_BLEND_SOLID) {
- glDisable(GL_BLEND);
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- else if (alphablend == GPU_BLEND_ADD) {
- glEnable(GL_BLEND);
- glBlendFunc(GL_ONE, GL_ONE);
- glDisable(GL_ALPHA_TEST);
- glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
- }
- else if (ELEM(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ALPHA_SORT)) {
- glEnable(GL_BLEND);
- glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
-
- /* for OpenGL render we use the alpha channel, this makes alpha blend correct */
- glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
-
- /* if U.glalphaclip == 1.0, some cards go bonkers...
- * turn off alpha test in this case */
-
- /* added after 2.45 to clip alpha */
- if (U.glalphaclip == 1.0f) {
- glDisable(GL_ALPHA_TEST);
- }
- else {
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, U.glalphaclip);
- }
- }
- else if (alphablend == GPU_BLEND_CLIP) {
- glDisable(GL_BLEND);
- glDisable(GL_SAMPLE_ALPHA_TO_COVERAGE);
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, 0.5f);
- }
- else if (alphablend == GPU_BLEND_ALPHA_TO_COVERAGE) {
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, U.glalphaclip);
- glEnable(GL_SAMPLE_ALPHA_TO_COVERAGE);
- }
-}
-
-static void gpu_verify_alpha_blend(int alphablend)
-{
- /* verify alpha blending modes */
- if (GTS.alphablend == alphablend)
- return;
-
- gpu_set_alpha_blend(alphablend);
- GTS.alphablend = alphablend;
-}
-
-static void gpu_verify_reflection(Image *ima)
-{
- if (ima && (ima->flag & IMA_REFLECT)) {
- /* enable reflection mapping */
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP);
-
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- }
- else {
- /* disable reflection mapping */
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- }
-}
-
typedef struct VerifyThreadData {
ImBuf *ibuf;
float *srgb_frect;
@@ -534,8 +260,6 @@ static void gpu_verify_high_bit_srgb_buffer_slice(float *srgb_frect,
ibuf->x, height,
ibuf->x, ibuf->x);
IMB_buffer_float_unpremultiply(current_srgb_frect, ibuf->x, height);
- /* Clamp buffer colors to 1.0 to avoid artifacts due to glu for hdr images. */
- IMB_buffer_float_clamp(current_srgb_frect, ibuf->x, height);
}
static void verify_thread_do(void *data_v,
@@ -567,7 +291,7 @@ static void gpu_verify_high_bit_srgb_buffer(float *srgb_frect,
int GPU_verify_image(
Image *ima, ImageUser *iuser,
- int textarget, int tftile, bool compare, bool mipmap, bool is_data)
+ int textarget, bool compare, bool mipmap, bool is_data)
{
unsigned int *bind = NULL;
int tpx = 0, tpy = 0;
@@ -577,46 +301,12 @@ int GPU_verify_image(
/* flag to determine whether deep format is used */
bool use_high_bit_depth = false, do_color_management = false;
- /* initialize tile mode and number of repeats */
GTS.ima = ima;
- GTS.tilemode = (ima && (ima->tpageflag & (IMA_TILES | IMA_TWINANIM)));
- GTS.tileXRep = 0;
- GTS.tileYRep = 0;
-
- /* setting current tile according to frame */
- if (ima && (ima->tpageflag & IMA_TWINANIM))
- GTS.tile = ima->lastframe;
- else
- GTS.tile = tftile;
-
- GTS.tile = MAX2(0, GTS.tile);
-
- if (ima) {
- GTS.tileXRep = ima->xrep;
- GTS.tileYRep = ima->yrep;
- }
- /* if same image & tile, we're done */
- if (compare && ima == GTS.curima && GTS.curtile == GTS.tile &&
- GTS.tilemode == GTS.curtilemode && GTS.curtileXRep == GTS.tileXRep &&
- GTS.curtileYRep == GTS.tileYRep)
- {
+ if (compare && ima == GTS.curima) {
return (ima != NULL);
}
- /* if tiling mode or repeat changed, change texture matrix to fit */
- if (GTS.tilemode != GTS.curtilemode || GTS.curtileXRep != GTS.tileXRep ||
- GTS.curtileYRep != GTS.tileYRep)
- {
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
-
- if (ima && (ima->tpageflag & IMA_TILES))
- glScalef(ima->xrep, ima->yrep, 1.0f);
-
- glMatrixMode(GL_MODELVIEW);
- }
-
/* check if we have a valid image */
if (ima == NULL || ima->ok == 0)
return 0;
@@ -652,48 +342,8 @@ int GPU_verify_image(
GPU_free_image(ima);
ima->tpageflag &= ~IMA_TPAGE_REFRESH;
}
-
- if (GTS.tilemode) {
- /* tiled mode */
- if (ima->repbind == NULL) gpu_make_repbind(ima);
- if (GTS.tile >= ima->totbind) GTS.tile = 0;
-
- /* this happens when you change repeat buttons */
- if (ima->repbind && textarget == GL_TEXTURE_2D) bind = &ima->repbind[GTS.tile];
- else bind = gpu_get_image_bindcode(ima, textarget);
-
- if (*bind == 0) {
- short texwindx = ibuf->x / ima->xrep;
- short texwindy = ibuf->y / ima->yrep;
-
- if (GTS.tile >= ima->xrep * ima->yrep)
- GTS.tile = ima->xrep * ima->yrep - 1;
-
- short texwinsy = GTS.tile / ima->xrep;
- short texwinsx = GTS.tile - texwinsy * ima->xrep;
-
- texwinsx *= texwindx;
- texwinsy *= texwindy;
-
- tpx = texwindx;
- tpy = texwindy;
- if (use_high_bit_depth) {
- if (do_color_management) {
- srgb_frect = MEM_mallocN(ibuf->x * ibuf->y * sizeof(float) * 4, "floar_buf_col_cor");
- gpu_verify_high_bit_srgb_buffer(srgb_frect, ibuf);
- frect = srgb_frect + (4 * (texwinsy * ibuf->x + texwinsx));
- }
- else {
- frect = ibuf->rect_float + (ibuf->channels * (texwinsy * ibuf->x + texwinsx));
- }
- }
- else {
- rect = ibuf->rect + texwinsy * ibuf->x + texwinsx;
- }
- }
- }
- else {
+ {
/* regular image mode */
bind = gpu_get_image_bindcode(ima, textarget);
@@ -722,57 +372,22 @@ int GPU_verify_image(
const int rectw = tpx;
const int recth = tpy;
- unsigned *tilerect = NULL;
- float *ftilerect = NULL;
-
- /* for tiles, copy only part of image into buffer */
- if (GTS.tilemode) {
- if (use_high_bit_depth) {
- ftilerect = MEM_mallocN(rectw * recth * sizeof(*ftilerect), "tilerect");
-
- for (int y = 0; y < recth; y++) {
- const float *frectrow = &frect[y * ibuf->x];
- float *ftilerectrow = &ftilerect[y * rectw];
-
- memcpy(ftilerectrow, frectrow, tpx * sizeof(*frectrow));
- }
-
- frect = ftilerect;
- }
- else {
- tilerect = MEM_mallocN(rectw * recth * sizeof(*tilerect), "tilerect");
-
- for (int y = 0; y < recth; y++) {
- const unsigned *rectrow = &rect[y * ibuf->x];
- unsigned *tilerectrow = &tilerect[y * rectw];
-
- memcpy(tilerectrow, rectrow, tpx * sizeof(*rectrow));
- }
-
- rect = tilerect;
- }
- }
-
#ifdef WITH_DDS
if (ibuf->ftype == IMB_FTYPE_DDS)
GPU_create_gl_tex_compressed(bind, rect, rectw, recth, textarget, mipmap, ima, ibuf);
else
#endif
GPU_create_gl_tex(bind, rect, frect, rectw, recth, textarget, mipmap, use_high_bit_depth, ima);
-
+
/* mark as non-color data texture */
if (*bind) {
if (is_data)
- ima->tpageflag |= IMA_GLBIND_IS_DATA;
+ ima->tpageflag |= IMA_GLBIND_IS_DATA;
else
- ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
+ ima->tpageflag &= ~IMA_GLBIND_IS_DATA;
}
/* clean up */
- if (tilerect)
- MEM_freeN(tilerect);
- if (ftilerect)
- MEM_freeN(ftilerect);
if (srgb_frect)
MEM_freeN(srgb_frect);
@@ -858,30 +473,6 @@ void GPU_create_gl_tex(
int tpx = rectw;
int tpy = recth;
- /* scale if not a power of two. this is not strictly necessary for newer
- * GPUs (OpenGL version >= 2.0) since they support non-power-of-two-textures
- * Then don't bother scaling for hardware that supports NPOT textures! */
- if (textarget == GL_TEXTURE_2D &&
- ((!GPU_full_non_power_of_two_support() && !is_power_of_2_resolution(rectw, recth)) ||
- is_over_resolution_limit(textarget, rectw, recth)))
- {
- rectw = smaller_power_of_2_limit(rectw);
- recth = smaller_power_of_2_limit(recth);
-
- if (use_high_bit_depth) {
- ibuf = IMB_allocFromBuffer(NULL, frect, tpx, tpy);
- IMB_scaleImBuf(ibuf, rectw, recth);
-
- frect = ibuf->rect_float;
- }
- else {
- ibuf = IMB_allocFromBuffer(rect, NULL, tpx, tpy);
- IMB_scaleImBuf(ibuf, rectw, recth);
-
- rect = ibuf->rect;
- }
- }
-
/* create image */
glGenTextures(1, (GLuint *)bind);
glBindTexture(textarget, *bind);
@@ -889,7 +480,7 @@ void GPU_create_gl_tex(
if (textarget == GL_TEXTURE_2D) {
if (use_high_bit_depth) {
if (GLEW_ARB_texture_float)
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
else
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16, rectw, recth, 0, GL_RGBA, GL_FLOAT, frect);
}
@@ -900,7 +491,7 @@ void GPU_create_gl_tex(
if (GPU_get_mipmap() && mipmap) {
if (GTS.gpu_mipmap) {
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ glGenerateMipmap(GL_TEXTURE_2D);
}
else {
int i;
@@ -918,7 +509,7 @@ void GPU_create_gl_tex(
ImBuf *mip = ibuf->mipmap[i - 1];
if (use_high_bit_depth) {
if (GLEW_ARB_texture_float)
- glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA16F_ARB, mip->x, mip->y, 0, GL_RGBA, GL_FLOAT, mip->rect_float);
+ glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA16F, mip->x, mip->y, 0, GL_RGBA, GL_FLOAT, mip->rect_float);
else
glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA16, mip->x, mip->y, 0, GL_RGBA, GL_FLOAT, mip->rect_float);
}
@@ -940,7 +531,7 @@ void GPU_create_gl_tex(
if (h == w && is_power_of_2_i(h) && !is_over_resolution_limit(textarget, h, w)) {
void **cube_map = gpu_gen_cube_map(rect, frect, rectw, recth, use_high_bit_depth);
- GLenum informat = use_high_bit_depth ? (GLEW_ARB_texture_float ? GL_RGBA16F_ARB : GL_RGBA16) : GL_RGBA8;
+ GLenum informat = use_high_bit_depth ? (GLEW_ARB_texture_float ? GL_RGBA16F : GL_RGBA16) : GL_RGBA8;
GLenum type = use_high_bit_depth ? GL_FLOAT : GL_UNSIGNED_BYTE;
if (cube_map)
@@ -951,7 +542,7 @@ void GPU_create_gl_tex(
if (GPU_get_mipmap() && mipmap) {
if (GTS.gpu_mipmap) {
- gpu_generate_mipmap(GL_TEXTURE_CUBE_MAP);
+ glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
}
else {
if (!ibuf) {
@@ -975,7 +566,7 @@ void GPU_create_gl_tex(
if (mip_cube_map) {
for (int j = 0; j < 6; j++) {
glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + j, i,
- informat, mipw, miph, 0, GL_RGBA, type, mip_cube_map[j]);
+ informat, mipw, miph, 0, GL_RGBA, type, mip_cube_map[j]);
}
}
gpu_del_cube_map(mip_cube_map);
@@ -1056,7 +647,7 @@ bool GPU_upload_dxt_texture(ImBuf *ibuf)
size = ((width + 3) / 4) * ((height + 3) / 4) * blocksize;
glCompressedTexImage2D(GL_TEXTURE_2D, i, format, width, height,
- 0, size, ibuf->dds_data.data + offset);
+ 0, size, ibuf->dds_data.data + offset);
offset += size;
width >>= 1;
@@ -1091,62 +682,6 @@ void GPU_create_gl_tex_compressed(
}
#endif
}
-static void gpu_verify_repeat(Image *ima)
-{
- /* set either clamp or repeat in X/Y */
- if (ima->tpageflag & IMA_CLAMP_U)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- else
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
-
- if (ima->tpageflag & IMA_CLAMP_V)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- else
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
-}
-
-int GPU_set_tpage(MTexPoly *mtexpoly, int mipmap, int alphablend)
-{
- /* check if we need to clear the state */
- if (mtexpoly == NULL) {
- GPU_clear_tpage(false);
- return 0;
- }
-
- Image *ima = mtexpoly->tpage;
- GTS.lasttface = mtexpoly;
-
- gpu_verify_alpha_blend(alphablend);
- gpu_verify_reflection(ima);
-
- if (GPU_verify_image(ima, NULL, GL_TEXTURE_2D, mtexpoly->tile, 1, mipmap, false)) {
- GTS.curtile = GTS.tile;
- GTS.curima = GTS.ima;
- GTS.curtilemode = GTS.tilemode;
- GTS.curtileXRep = GTS.tileXRep;
- GTS.curtileYRep = GTS.tileYRep;
-
- glEnable(GL_TEXTURE_2D);
- }
- else {
- glDisable(GL_TEXTURE_2D);
-
- GTS.curtile = 0;
- GTS.curima = NULL;
- GTS.curtilemode = 0;
- GTS.curtileXRep = 0;
- GTS.curtileYRep = 0;
-
- return 0;
- }
-
- gpu_verify_repeat(ima);
-
- /* Did this get lost in the image recode? */
- /* BKE_image_tag_time(ima);*/
-
- return 1;
-}
/* these two functions are called on entering and exiting texture paint mode,
* temporary disabling/enabling mipmapping on all images for quick texture
@@ -1206,9 +741,7 @@ void GPU_paint_set_mipmap(bool mipmap)
/* check if image has been downscaled and do scaled partial update */
static bool gpu_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x, int y, int w, int h)
{
- if ((!GPU_full_non_power_of_two_support() && !is_power_of_2_resolution(ibuf->x, ibuf->y)) ||
- is_over_resolution_limit(GL_TEXTURE_2D, ibuf->x, ibuf->y))
- {
+ if (is_over_resolution_limit(GL_TEXTURE_2D, ibuf->x, ibuf->y)) {
int x_limit = smaller_power_of_2_limit(ibuf->x);
int y_limit = smaller_power_of_2_limit(ibuf->y);
@@ -1261,7 +794,7 @@ static bool gpu_check_scaled_image(ImBuf *ibuf, Image *ima, float *frect, int x,
}
if (GPU_get_mipmap()) {
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ glGenerateMipmap(GL_TEXTURE_2D);
}
else {
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1277,8 +810,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
{
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
- if (ima->repbind ||
- (!GTS.gpu_mipmap && GPU_get_mipmap()) ||
+ if ((!GTS.gpu_mipmap && GPU_get_mipmap()) ||
(ima->bindcode[TEXTARGET_TEXTURE_2D] == 0) ||
(ibuf == NULL) ||
(w == 0) || (h == 0))
@@ -1296,7 +828,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
float *buffer = MEM_mallocN(w * h * sizeof(float) * 4, "temp_texpaint_float_buf");
bool is_data = (ima->tpageflag & IMA_GLBIND_IS_DATA) != 0;
IMB_partial_rect_from_float(ibuf, buffer, x, y, w, h, is_data);
-
+
if (gpu_check_scaled_image(ibuf, ima, buffer, x, y, w, h)) {
MEM_freeN(buffer);
BKE_image_release_ibuf(ima, ibuf, NULL);
@@ -1311,7 +843,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
/* we have already accounted for the case where GTS.gpu_mipmap is false
* so we will be using GPU mipmap generation here */
if (GPU_get_mipmap()) {
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ glGenerateMipmap(GL_TEXTURE_2D);
}
else {
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1337,7 +869,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
glPixelStorei(GL_UNPACK_SKIP_ROWS, y);
glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, w, h, GL_RGBA,
- GL_UNSIGNED_BYTE, ibuf->rect);
+ GL_UNSIGNED_BYTE, ibuf->rect);
glPixelStorei(GL_UNPACK_ROW_LENGTH, row_length);
glPixelStorei(GL_UNPACK_SKIP_PIXELS, skip_pixels);
@@ -1345,7 +877,7 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
/* see comment above as to why we are using gpu mipmap generation here */
if (GPU_get_mipmap()) {
- gpu_generate_mipmap(GL_TEXTURE_2D);
+ glGenerateMipmap(GL_TEXTURE_2D);
}
else {
ima->tpageflag &= ~IMA_MIPMAP_COMPLETE;
@@ -1355,61 +887,6 @@ void GPU_paint_update_image(Image *ima, ImageUser *iuser, int x, int y, int w, i
BKE_image_release_ibuf(ima, ibuf, NULL);
}
-void GPU_update_images_framechange(void)
-{
- for (Image *ima = G.main->image.first; ima; ima = ima->id.next) {
- if (ima->tpageflag & IMA_TWINANIM) {
- if (ima->twend >= ima->xrep * ima->yrep)
- ima->twend = ima->xrep * ima->yrep - 1;
-
- /* check: is bindcode not in the array? free. (to do) */
-
- ima->lastframe++;
- if (ima->lastframe > ima->twend)
- ima->lastframe = ima->twsta;
- }
- }
-}
-
-int GPU_update_image_time(Image *ima, double time)
-{
- if (!ima)
- return 0;
-
- if (ima->lastupdate < 0)
- ima->lastupdate = 0;
-
- if (ima->lastupdate > (float)time)
- ima->lastupdate = (float)time;
-
- int inc = 0;
-
- if (ima->tpageflag & IMA_TWINANIM) {
- if (ima->twend >= ima->xrep * ima->yrep) ima->twend = ima->xrep * ima->yrep - 1;
-
- /* check: is the bindcode not in the array? Then free. (still to do) */
-
- float diff = (float)((float)time - ima->lastupdate);
- inc = (int)(diff * (float)ima->animspeed);
-
- ima->lastupdate += ((float)inc / (float)ima->animspeed);
-
- int newframe = ima->lastframe + inc;
-
- if (newframe > (int)ima->twend) {
- if (ima->twend - ima->twsta != 0)
- newframe = (int)ima->twsta - 1 + (newframe - ima->twend) % (ima->twend - ima->twsta);
- else
- newframe = ima->twsta;
- }
-
- ima->lastframe = newframe;
- }
-
- return inc;
-}
-
-
void GPU_free_smoke(SmokeModifierData *smd)
{
if (smd->type & MOD_SMOKE_TYPE_DOMAIN && smd->domain) {
@@ -1437,31 +914,60 @@ void GPU_create_smoke(SmokeModifierData *smd, int highres)
if (smoke_has_colors(sds->fluid)) {
float *data = MEM_callocN(sizeof(float) * sds->total_cells * 4, "smokeColorTexture");
smoke_get_rgba(sds->fluid, data, 0);
- sds->tex = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 4, data);
+ sds->tex = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], GPU_RGBA8, data, NULL);
MEM_freeN(data);
}
/* density only */
else {
- sds->tex = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, smoke_get_density(sds->fluid));
+ sds->tex = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2],
+ GPU_R8, smoke_get_density(sds->fluid), NULL);
+
+ /* Swizzle the RGBA components to read the Red channel so
+ * that the shader stay the same for colored and non color
+ * density textures. */
+ GPU_texture_bind(sds->tex, 0);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R, GL_RED);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G, GL_RED);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A, GL_RED);
+ GPU_texture_unbind(sds->tex);
}
- sds->tex_flame = (smoke_has_fuel(sds->fluid)) ? GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, smoke_get_flame(sds->fluid)) : NULL;
+ sds->tex_flame = (smoke_has_fuel(sds->fluid)) ?
+ GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2],
+ GPU_R8, smoke_get_flame(sds->fluid), NULL) :
+ NULL;
}
else if (!sds->tex && highres) {
/* rgba texture for color + density */
if (smoke_turbulence_has_colors(sds->wt)) {
float *data = MEM_callocN(sizeof(float) * smoke_turbulence_get_cells(sds->wt) * 4, "smokeColorTexture");
smoke_turbulence_get_rgba(sds->wt, data, 0);
- sds->tex = GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 4, data);
+ sds->tex = GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], GPU_RGBA8, data, NULL);
MEM_freeN(data);
}
/* density only */
else {
- sds->tex = GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 1, smoke_turbulence_get_density(sds->wt));
+ sds->tex = GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2],
+ GPU_R8, smoke_turbulence_get_density(sds->wt), NULL);
+
+ /* Swizzle the RGBA components to read the Red channel so
+ * that the shader stay the same for colored and non color
+ * density textures. */
+ GPU_texture_bind(sds->tex, 0);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_R, GL_RED);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_G, GL_RED);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_B, GL_RED);
+ glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_SWIZZLE_A, GL_RED);
+ GPU_texture_unbind(sds->tex);
}
- sds->tex_flame = (smoke_turbulence_has_fuel(sds->wt)) ? GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2], 1, smoke_turbulence_get_flame(sds->wt)) : NULL;
+ sds->tex_flame = (smoke_turbulence_has_fuel(sds->wt)) ?
+ GPU_texture_create_3D(sds->res_wt[0], sds->res_wt[1], sds->res_wt[2],
+ GPU_R8, smoke_turbulence_get_flame(sds->wt), NULL) :
+ NULL;
}
- sds->tex_shadow = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2], 1, sds->shadow);
+ sds->tex_shadow = GPU_texture_create_3D(sds->res[0], sds->res[1], sds->res[2],
+ GPU_R8, sds->shadow, NULL);
}
#else // WITH_SMOKE
(void)highres;
@@ -1499,9 +1005,6 @@ void GPU_free_unused_buffers(void)
BLI_linklist_free(image_free_queue, NULL);
image_free_queue = NULL;
- /* vbo buffers */
- GPU_global_buffer_pool_free_unused();
-
BLI_thread_unlock(LOCK_OPENGL);
}
@@ -1525,14 +1028,6 @@ void GPU_free_image(Image *ima)
}
}
- /* free repeated image binding */
- if (ima->repbind) {
- glDeleteTextures(ima->totbind, (GLuint *)ima->repbind);
-
- MEM_freeN(ima->repbind);
- ima->repbind = NULL;
- }
-
ima->tpageflag &= ~(IMA_MIPMAP_COMPLETE | IMA_GLBIND_IS_DATA);
}
@@ -1576,7 +1071,7 @@ void GPU_free_images_old(void)
if ((ima->flag & IMA_NOCOLLECT) == 0 && ctime - ima->lastused > U.textimeout) {
/* If it's in GL memory, deallocate and set time tag to current time
* This gives textures a "second chance" to be used before dying. */
- if (BKE_image_has_bindcode(ima) || ima->repbind) {
+ if (BKE_image_has_bindcode(ima)) {
GPU_free_image(ima);
ima->lastused = ctime;
}
@@ -1589,679 +1084,7 @@ void GPU_free_images_old(void)
}
}
-
-/* OpenGL Materials */
-
-#define FIXEDMAT 8
-
-/* OpenGL state caching for materials */
-
-typedef struct GPUMaterialFixed {
- float diff[3];
- float spec[3];
- int hard;
- float alpha;
-} GPUMaterialFixed;
-
-static struct GPUMaterialState {
- GPUMaterialFixed (*matbuf);
- GPUMaterialFixed matbuf_fixed[FIXEDMAT];
- int totmat;
-
- /* set when called inside GPU_begin_object_materials / GPU_end_object_materials
- * otherwise calling GPU_object_material_bind returns zero */
- bool is_enabled;
-
- Material **gmatbuf;
- Material *gmatbuf_fixed[FIXEDMAT];
- Material *gboundmat;
- Object *gob;
- DupliObject *dob;
- Scene *gscene;
- int glay;
- bool gscenelock;
- float (*gviewmat)[4];
- float (*gviewinv)[4];
- float (*gviewcamtexcofac);
-
- bool backface_culling;
- bool two_sided_lighting;
-
- GPUBlendMode *alphablend;
- GPUBlendMode alphablend_fixed[FIXEDMAT];
- bool use_alpha_pass, is_alpha_pass;
- bool use_matcaps;
-
- int lastmatnr, lastretval;
- GPUBlendMode lastalphablend;
- bool is_opensubdiv;
-} GMS = {NULL};
-
-/* fixed function material, alpha handed by caller */
-static void gpu_material_to_fixed(
- GPUMaterialFixed *smat, const Material *bmat, const int gamma, const Object *ob,
- const int new_shading_nodes, const bool dimdown)
-{
- if (bmat->mode & MA_SHLESS) {
- copy_v3_v3(smat->diff, &bmat->r);
-
- if (gamma)
- linearrgb_to_srgb_v3_v3(smat->diff, smat->diff);
-
- zero_v3(smat->spec);
- smat->alpha = 1.0f;
- smat->hard = 0;
- }
- else if (new_shading_nodes) {
- copy_v3_v3(smat->diff, &bmat->r);
- copy_v3_v3(smat->spec, &bmat->specr);
- smat->alpha = 1.0f;
- smat->hard = CLAMPIS(bmat->har, 0, 128);
-
- if (dimdown) {
- mul_v3_fl(smat->diff, 0.8f);
- mul_v3_fl(smat->spec, 0.5f);
- }
-
- if (gamma) {
- linearrgb_to_srgb_v3_v3(smat->diff, smat->diff);
- linearrgb_to_srgb_v3_v3(smat->spec, smat->spec);
- }
- }
- else {
- mul_v3_v3fl(smat->diff, &bmat->r, bmat->ref + bmat->emit);
-
- if (bmat->shade_flag & MA_OBCOLOR)
- mul_v3_v3(smat->diff, ob->col);
-
- mul_v3_v3fl(smat->spec, &bmat->specr, bmat->spec);
- smat->hard = CLAMPIS(bmat->har, 1, 128);
- smat->alpha = 1.0f;
-
- if (gamma) {
- linearrgb_to_srgb_v3_v3(smat->diff, smat->diff);
- linearrgb_to_srgb_v3_v3(smat->spec, smat->spec);
- }
- }
-}
-
-static Material *gpu_active_node_material(Material *ma)
-{
- if (ma && ma->use_nodes && ma->nodetree) {
- bNode *node = nodeGetActiveID(ma->nodetree, ID_MA);
-
- if (node)
- return (Material *)node->id;
- else
- return NULL;
- }
-
- return ma;
-}
-
-void GPU_begin_dupli_object(DupliObject *dob)
-{
- GMS.dob = dob;
-}
-
-void GPU_end_dupli_object(void)
-{
- GMS.dob = NULL;
-}
-
-void GPU_begin_object_materials(
- View3D *v3d, RegionView3D *rv3d, Scene *scene, Object *ob,
- bool glsl, bool *do_alpha_after)
-{
- Material *ma;
- GPUMaterial *gpumat;
- GPUBlendMode alphablend;
- DupliObject *dob;
- int a;
- const bool gamma = BKE_scene_check_color_management_enabled(scene);
- 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 */
- bool use_opensubdiv = false;
-
-#ifdef WITH_OPENSUBDIV
- {
- DerivedMesh *derivedFinal = NULL;
- if (ob->type == OB_MESH) {
- Mesh *me = ob->data;
- BMEditMesh *em = me->edit_btmesh;
- if (em != NULL) {
- derivedFinal = em->derivedFinal;
- }
- else {
- derivedFinal = ob->derivedFinal;
- }
- }
- else {
- derivedFinal = ob->derivedFinal;
- }
-
- if (derivedFinal != NULL && derivedFinal->type == DM_TYPE_CCGDM) {
- CCGDerivedMesh *ccgdm = (CCGDerivedMesh *) derivedFinal;
- use_opensubdiv = ccgdm->useGpuBackend;
- }
- }
-#endif
-
-#ifdef WITH_GAMEENGINE
- if (rv3d->rflag & RV3D_IS_GAME_ENGINE) {
- ob = BKE_object_lod_matob_get(ob, scene);
- }
-#endif
-
- /* initialize state */
- /* DupliObject must be restored */
- dob = GMS.dob;
- memset(&GMS, 0, sizeof(GMS));
- GMS.is_enabled = true;
- GMS.dob = dob;
- GMS.lastmatnr = -1;
- GMS.lastretval = -1;
- GMS.lastalphablend = GPU_BLEND_SOLID;
- GMS.use_matcaps = use_matcap;
-
- GMS.backface_culling = (v3d->flag2 & V3D_BACKFACE_CULLING) != 0;
-
- GMS.two_sided_lighting = false;
- if (ob && ob->type == OB_MESH)
- GMS.two_sided_lighting = (((Mesh *)ob->data)->flag & ME_TWOSIDED) != 0;
-
- GMS.gob = ob;
- GMS.gscene = scene;
- GMS.is_opensubdiv = use_opensubdiv;
- GMS.totmat = use_matcap ? 1 : ob->totcol + 1; /* materials start from 1, default material is 0 */
- GMS.glay = (v3d->localvd) ? v3d->localvd->lay : v3d->lay; /* keep lamps visible in local view */
- GMS.gscenelock = (v3d->scenelock != 0);
- GMS.gviewmat = rv3d->viewmat;
- GMS.gviewinv = rv3d->viewinv;
- GMS.gviewcamtexcofac = rv3d->viewcamtexcofac;
-
- /* alpha pass setup. there's various cases to handle here:
- * - object transparency on: only solid materials draw in the first pass,
- * and only transparent in the second 'alpha' pass.
- * - object transparency off: for glsl we draw both in a single pass, and
- * for solid we don't use transparency at all. */
- GMS.use_alpha_pass = (do_alpha_after != NULL);
- GMS.is_alpha_pass = (v3d->transp != false);
- if (GMS.use_alpha_pass)
- *do_alpha_after = false;
-
- if (GMS.totmat > FIXEDMAT) {
- GMS.matbuf = MEM_callocN(sizeof(GPUMaterialFixed) * GMS.totmat, "GMS.matbuf");
- GMS.gmatbuf = MEM_callocN(sizeof(*GMS.gmatbuf) * GMS.totmat, "GMS.matbuf");
- GMS.alphablend = MEM_callocN(sizeof(*GMS.alphablend) * GMS.totmat, "GMS.matbuf");
- }
- else {
- GMS.matbuf = GMS.matbuf_fixed;
- GMS.gmatbuf = GMS.gmatbuf_fixed;
- GMS.alphablend = GMS.alphablend_fixed;
- }
-
- /* viewport material, setup in space_view3d, defaults to matcap using ma->preview now */
- if (use_matcap) {
- GMS.gmatbuf[0] = v3d->defmaterial;
- GPU_material_matcap(scene, v3d->defmaterial, use_opensubdiv);
-
- /* do material 1 too, for displists! */
- memcpy(&GMS.matbuf[1], &GMS.matbuf[0], sizeof(GPUMaterialFixed));
-
- GMS.alphablend[0] = GPU_BLEND_SOLID;
- }
- else {
-
- /* no materials assigned? */
- if (ob->totcol == 0) {
- gpu_material_to_fixed(&GMS.matbuf[0], &defmaterial, 0, ob, new_shading_nodes, true);
-
- /* do material 1 too, for displists! */
- memcpy(&GMS.matbuf[1], &GMS.matbuf[0], sizeof(GPUMaterialFixed));
-
- if (glsl) {
- GMS.gmatbuf[0] = &defmaterial;
- GPU_material_from_blender(GMS.gscene, &defmaterial, GMS.is_opensubdiv);
- }
-
- GMS.alphablend[0] = GPU_BLEND_SOLID;
- }
-
- /* setup materials */
- for (a = 1; a <= ob->totcol; a++) {
- /* find a suitable material */
- ma = give_current_material(ob, a);
- if (!glsl && !new_shading_nodes) ma = gpu_active_node_material(ma);
- if (ma == NULL) ma = &defmaterial;
-
- /* create glsl material if requested */
- gpumat = glsl ? GPU_material_from_blender(GMS.gscene, ma, GMS.is_opensubdiv) : NULL;
-
- if (gpumat) {
- /* do glsl only if creating it succeed, else fallback */
- GMS.gmatbuf[a] = ma;
- alphablend = GPU_material_alpha_blend(gpumat, ob->col);
- }
- else {
- /* fixed function opengl materials */
- gpu_material_to_fixed(&GMS.matbuf[a], ma, gamma, ob, new_shading_nodes, false);
-
- if (GMS.use_alpha_pass && ((ma->mode & MA_TRANSP) || (new_shading_nodes && ma->alpha != 1.0f))) {
- GMS.matbuf[a].alpha = ma->alpha;
- alphablend = (ma->alpha == 1.0f) ? GPU_BLEND_SOLID: GPU_BLEND_ALPHA;
- }
- else {
- GMS.matbuf[a].alpha = 1.0f;
- alphablend = GPU_BLEND_SOLID;
- }
- }
-
- /* setting 'do_alpha_after = true' indicates this object needs to be
- * drawn in a second alpha pass for improved blending */
- if (do_alpha_after && !GMS.is_alpha_pass)
- if (ELEM(alphablend, GPU_BLEND_ALPHA, GPU_BLEND_ADD, GPU_BLEND_ALPHA_SORT))
- *do_alpha_after = true;
-
- GMS.alphablend[a] = alphablend;
- }
- }
-
- /* let's start with a clean state */
- GPU_object_material_unbind();
-}
-
-static int gpu_get_particle_info(GPUParticleInfo *pi)
-{
- DupliObject *dob = GMS.dob;
- if (dob->particle_system) {
- int ind;
- if (dob->persistent_id[0] < dob->particle_system->totpart)
- ind = dob->persistent_id[0];
- else {
- ind = dob->particle_system->child[dob->persistent_id[0] - dob->particle_system->totpart].parent;
- }
- if (ind >= 0) {
- ParticleData *p = &dob->particle_system->particles[ind];
-
- pi->scalprops[0] = ind;
- pi->scalprops[1] = GMS.gscene->r.cfra - p->time;
- pi->scalprops[2] = p->lifetime;
- pi->scalprops[3] = p->size;
-
- copy_v3_v3(pi->location, p->state.co);
- pi->location[3] = BLI_hash_int_01(ind);
-
- copy_v3_v3(pi->velocity, p->state.vel);
- copy_v3_v3(pi->angular_velocity, p->state.ave);
- return 1;
- }
- else return 0;
- }
- else
- return 0;
-}
-
-static void GPU_get_object_info(float oi[3], Material *mat)
-{
- Object *ob = GMS.gob;
- oi[0] = ob->index;
- oi[1] = mat->index;
- unsigned int random;
- if (GMS.dob) {
- random = GMS.dob->random_id;
- }
- else {
- random = BLI_hash_int_2d(BLI_hash_string(GMS.gob->id.name + 2), 0);
- }
- oi[2] = random * (1.0f / (float)0xFFFFFFFF);
-}
-
-int GPU_object_material_bind(int nr, void *attribs)
-{
- GPUVertexAttribs *gattribs = attribs;
-
- /* no GPU_begin_object_materials, use default material */
- if (!GMS.matbuf) {
- memset(&GMS, 0, sizeof(GMS));
-
- float diffuse[3], specular[3];
- mul_v3_v3fl(diffuse, &defmaterial.r, defmaterial.ref + defmaterial.emit);
- mul_v3_v3fl(specular, &defmaterial.specr, defmaterial.spec);
- GPU_basic_shader_colors(diffuse, specular, 35, 1.0f);
-
- if (GMS.two_sided_lighting)
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_TWO_SIDED);
- else
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING);
-
- return 0;
- }
-
- /* prevent index to use un-initialized array items */
- if (nr >= GMS.totmat)
- nr = 0;
-
- if (gattribs)
- memset(gattribs, 0, sizeof(*gattribs));
-
- /* keep current material */
- if (nr == GMS.lastmatnr)
- return GMS.lastretval;
-
- /* unbind glsl material */
- if (GMS.gboundmat) {
- if (GMS.is_alpha_pass) glDepthMask(0);
- GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat, GMS.is_opensubdiv));
- GMS.gboundmat = NULL;
- }
-
- /* draw materials with alpha in alpha pass */
- GMS.lastmatnr = nr;
- GMS.lastretval = 1;
-
- if (GMS.use_alpha_pass) {
- GMS.lastretval = ELEM(GMS.alphablend[nr], GPU_BLEND_SOLID, GPU_BLEND_CLIP);
- if (GMS.is_alpha_pass)
- GMS.lastretval = !GMS.lastretval;
- }
- else
- GMS.lastretval = !GMS.is_alpha_pass;
-
- if (GMS.lastretval) {
- /* for alpha pass, use alpha blend */
- GPUBlendMode alphablend = GMS.alphablend[nr];
-
- if (gattribs && GMS.gmatbuf[nr]) {
- /* bind glsl material and get attributes */
- Material *mat = GMS.gmatbuf[nr];
- GPUParticleInfo partile_info;
- float object_info[3] = {0};
-
- float auto_bump_scale;
-
- GPUMaterial *gpumat = GPU_material_from_blender(GMS.gscene, mat, GMS.is_opensubdiv);
- GPU_material_vertex_attributes(gpumat, gattribs);
-
- if (GMS.dob) {
- gpu_get_particle_info(&partile_info);
- }
-
- if (GPU_get_material_builtins(gpumat) & GPU_OBJECT_INFO) {
- GPU_get_object_info(object_info, mat);
- }
-
- GPU_material_bind(
- gpumat, GMS.gob->lay, GMS.glay, 1.0, !(GMS.gob->mode & OB_MODE_TEXTURE_PAINT),
- GMS.gviewmat, GMS.gviewinv, GMS.gviewcamtexcofac, GMS.gscenelock);
-
- auto_bump_scale = GMS.gob->derivedFinal != NULL ? GMS.gob->derivedFinal->auto_bump_scale : 1.0f;
- GPU_material_bind_uniforms(gpumat, GMS.gob->obmat, GMS.gviewmat, GMS.gob->col, auto_bump_scale, &partile_info, object_info);
- GMS.gboundmat = mat;
-
- /* for glsl use alpha blend mode, unless it's set to solid and
- * we are already drawing in an alpha pass */
- if (mat->game.alpha_blend != GPU_BLEND_SOLID)
- alphablend = mat->game.alpha_blend;
-
- if (GMS.is_alpha_pass) glDepthMask(1);
-
- if (GMS.backface_culling) {
- if (mat->game.flag)
- glEnable(GL_CULL_FACE);
- else
- glDisable(GL_CULL_FACE);
- }
-
- if (GMS.use_matcaps)
- glColor3f(1.0f, 1.0f, 1.0f);
- }
- else {
- /* or do fixed function opengl material */
- GPU_basic_shader_colors(
- GMS.matbuf[nr].diff,
- GMS.matbuf[nr].spec, GMS.matbuf[nr].hard, GMS.matbuf[nr].alpha);
-
- if (GMS.two_sided_lighting)
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING | GPU_SHADER_TWO_SIDED);
- else
- GPU_basic_shader_bind(GPU_SHADER_LIGHTING);
- }
-
- /* set (alpha) blending mode */
- GPU_set_material_alpha_blend(alphablend);
- }
-
- return GMS.lastretval;
-}
-
-int GPU_object_material_visible(int nr, void *attribs)
-{
- GPUVertexAttribs *gattribs = attribs;
- int visible;
-
- if (!GMS.matbuf)
- return 0;
-
- if (gattribs)
- memset(gattribs, 0, sizeof(*gattribs));
-
- if (nr >= GMS.totmat)
- nr = 0;
-
- if (GMS.use_alpha_pass) {
- visible = ELEM(GMS.alphablend[nr], GPU_BLEND_SOLID, GPU_BLEND_CLIP);
- if (GMS.is_alpha_pass)
- visible = !visible;
- }
- else
- visible = !GMS.is_alpha_pass;
-
- return visible;
-}
-
-void GPU_set_material_alpha_blend(int alphablend)
-{
- if (GMS.lastalphablend == alphablend)
- return;
-
- gpu_set_alpha_blend(alphablend);
- GMS.lastalphablend = alphablend;
-}
-
-int GPU_get_material_alpha_blend(void)
-{
- return GMS.lastalphablend;
-}
-
-void GPU_object_material_unbind(void)
-{
- GMS.lastmatnr = -1;
- GMS.lastretval = 1;
-
- if (GMS.gboundmat) {
- if (GMS.backface_culling)
- glDisable(GL_CULL_FACE);
-
- if (GMS.is_alpha_pass) glDepthMask(0);
- GPU_material_unbind(GPU_material_from_blender(GMS.gscene, GMS.gboundmat, GMS.is_opensubdiv));
- GMS.gboundmat = NULL;
- }
- else
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
- GPU_set_material_alpha_blend(GPU_BLEND_SOLID);
-}
-
-void GPU_material_diffuse_get(int nr, float diff[4])
-{
- /* prevent index to use un-initialized array items */
- if (nr >= GMS.totmat)
- nr = 0;
-
- /* no GPU_begin_object_materials, use default material */
- if (!GMS.matbuf) {
- mul_v3_v3fl(diff, &defmaterial.r, defmaterial.ref + defmaterial.emit);
- }
- else {
- copy_v3_v3(diff, GMS.matbuf[nr].diff);
- diff[3] = GMS.matbuf[nr].alpha;
- }
-}
-
-bool GPU_material_use_matcaps_get(void)
-{
- return GMS.use_matcaps;
-}
-
-bool GPU_object_materials_check(void)
-{
- return GMS.is_enabled;
-}
-
-void GPU_end_object_materials(void)
-{
- GPU_object_material_unbind();
-
- GMS.is_enabled = false;
-
- if (GMS.matbuf && GMS.matbuf != GMS.matbuf_fixed) {
- MEM_freeN(GMS.matbuf);
- MEM_freeN(GMS.gmatbuf);
- MEM_freeN(GMS.alphablend);
- }
-
- GMS.matbuf = NULL;
- GMS.gmatbuf = NULL;
- GMS.alphablend = NULL;
- GMS.two_sided_lighting = false;
-
- /* resetting the texture matrix after the scaling needed for tiled textures */
- if (GTS.tilemode) {
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- }
-}
-
-/* Lights */
-
-int GPU_default_lights(void)
-{
- /* initialize */
- if (U.light[0].flag == 0 && U.light[1].flag == 0 && U.light[2].flag == 0) {
- U.light[0].flag = 1;
- U.light[0].vec[0] = -0.3; U.light[0].vec[1] = 0.3; U.light[0].vec[2] = 0.9;
- U.light[0].col[0] = 0.8; U.light[0].col[1] = 0.8; U.light[0].col[2] = 0.8;
- U.light[0].spec[0] = 0.5; U.light[0].spec[1] = 0.5; U.light[0].spec[2] = 0.5;
- U.light[0].spec[3] = 1.0;
-
- U.light[1].flag = 0;
- U.light[1].vec[0] = 0.5; U.light[1].vec[1] = 0.5; U.light[1].vec[2] = 0.1;
- U.light[1].col[0] = 0.4; U.light[1].col[1] = 0.4; U.light[1].col[2] = 0.8;
- U.light[1].spec[0] = 0.3; U.light[1].spec[1] = 0.3; U.light[1].spec[2] = 0.5;
- U.light[1].spec[3] = 1.0;
-
- U.light[2].flag = 0;
- U.light[2].vec[0] = 0.3; U.light[2].vec[1] = -0.3; U.light[2].vec[2] = -0.2;
- U.light[2].col[0] = 0.8; U.light[2].col[1] = 0.5; U.light[2].col[2] = 0.4;
- U.light[2].spec[0] = 0.5; U.light[2].spec[1] = 0.4; U.light[2].spec[2] = 0.3;
- U.light[2].spec[3] = 1.0;
- }
-
- GPU_basic_shader_light_set_viewer(false);
-
- int count = 0;
-
- for (int a = 0; a < 8; a++) {
- if (a < 3 && U.light[a].flag) {
- GPULightData light = {0};
-
- light.type = GPU_LIGHT_SUN;
-
- normalize_v3_v3(light.direction, U.light[a].vec);
- copy_v3_v3(light.diffuse, U.light[a].col);
- copy_v3_v3(light.specular, U.light[a].spec);
-
- GPU_basic_shader_light_set(a, &light);
-
- count++;
- }
- else
- GPU_basic_shader_light_set(a, NULL);
- }
-
- return count;
-}
-
-int GPU_scene_object_lights(Scene *scene, Object *ob, int lay, float viewmat[4][4], int ortho)
-{
- /* disable all lights */
- for (int count = 0; count < 8; count++)
- GPU_basic_shader_light_set(count, NULL);
-
- /* view direction for specular is not computed correct by default in
- * opengl, so we set the settings ourselves */
- GPU_basic_shader_light_set_viewer(!ortho);
-
- int count = 0;
-
- for (Base *base = scene->base.first; base; base = base->next) {
- if (base->object->type != OB_LAMP)
- continue;
-
- if (!(base->lay & lay) || !(base->lay & ob->lay))
- continue;
-
- Lamp *la = base->object->data;
-
- /* setup lamp transform */
- glPushMatrix();
- glLoadMatrixf((float *)viewmat);
-
- /* setup light */
- GPULightData light = {0};
-
- mul_v3_v3fl(light.diffuse, &la->r, la->energy);
- mul_v3_v3fl(light.specular, &la->r, la->energy);
-
- if (la->type == LA_SUN) {
- /* directional sun light */
- light.type = GPU_LIGHT_SUN;
- normalize_v3_v3(light.direction, base->object->obmat[2]);
- }
- else {
- /* other lamps with position attenuation */
- copy_v3_v3(light.position, base->object->obmat[3]);
-
- light.constant_attenuation = 1.0f;
- light.linear_attenuation = la->att1 / la->dist;
- light.quadratic_attenuation = la->att2 / (la->dist * la->dist);
-
- if (la->type == LA_SPOT) {
- light.type = GPU_LIGHT_SPOT;
- negate_v3_v3(light.direction, base->object->obmat[2]);
- normalize_v3(light.direction);
- light.spot_cutoff = RAD2DEGF(la->spotsize * 0.5f);
- light.spot_exponent = 128.0f * la->spotblend;
- }
- else
- light.type = GPU_LIGHT_POINT;
- }
-
- GPU_basic_shader_light_set(count, &light);
-
- glPopMatrix();
-
- count++;
- if (count == 8)
- break;
- }
-
- return count;
-}
-
-static void gpu_multisample(bool enable)
+static void gpu_disable_multisample(void)
{
#ifdef __linux__
/* changing multisample from the default (enabled) causes problems on some
@@ -2277,115 +1100,51 @@ static void gpu_multisample(bool enable)
}
if (toggle_ok) {
- if (enable)
- glEnable(GL_MULTISAMPLE);
- else
- glDisable(GL_MULTISAMPLE);
+ glDisable(GL_MULTISAMPLE);
}
#else
- if (enable)
- glEnable(GL_MULTISAMPLE);
- else
- glDisable(GL_MULTISAMPLE);
+ glDisable(GL_MULTISAMPLE);
#endif
}
/* Default OpenGL State
*
- * This is called on startup, for opengl offscreen render and to restore state
- * for the game engine. Generally we should always return to this state when
+ * This is called on startup, for opengl offscreen render.
+ * Generally we should always return to this state when
* temporarily modifying the state for drawing, though that are (undocumented)
* exceptions that we should try to get rid of. */
void GPU_state_init(void)
{
- float mat_ambient[] = { 0.0, 0.0, 0.0, 0.0 };
- float mat_specular[] = { 0.5, 0.5, 0.5, 1.0 };
-
- glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, mat_ambient);
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_specular);
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
- glMateriali(GL_FRONT_AND_BACK, GL_SHININESS, 35);
- glColorMaterial(GL_FRONT_AND_BACK, GL_DIFFUSE);
-
- GPU_default_lights();
-
+ GPU_disable_program_point_size();
+
+ glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
+
glDepthFunc(GL_LEQUAL);
- /* scaling matrices */
- glEnable(GL_NORMALIZE);
- glDisable(GL_ALPHA_TEST);
glDisable(GL_BLEND);
glDisable(GL_DEPTH_TEST);
- glDisable(GL_FOG);
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
- glDisable(GL_LOGIC_OP);
+ glDisable(GL_COLOR_LOGIC_OP);
glDisable(GL_STENCIL_TEST);
- glDisable(GL_TEXTURE_1D);
- glDisable(GL_TEXTURE_2D);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-
- /* default disabled, enable should be local per function */
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- glPixelTransferi(GL_MAP_COLOR, GL_FALSE);
- glPixelTransferi(GL_RED_SCALE, 1);
- glPixelTransferi(GL_RED_BIAS, 0);
- glPixelTransferi(GL_GREEN_SCALE, 1);
- glPixelTransferi(GL_GREEN_BIAS, 0);
- glPixelTransferi(GL_BLUE_SCALE, 1);
- glPixelTransferi(GL_BLUE_BIAS, 0);
- glPixelTransferi(GL_ALPHA_SCALE, 1);
- glPixelTransferi(GL_ALPHA_BIAS, 0);
-
- glPixelTransferi(GL_DEPTH_BIAS, 0);
- glPixelTransferi(GL_DEPTH_SCALE, 1);
- glDepthRange(0.0, 1.0);
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
+ glDepthRange(0.0, 1.0);
glFrontFace(GL_CCW);
glCullFace(GL_BACK);
glDisable(GL_CULL_FACE);
- gpu_multisample(false);
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ gpu_disable_multisample();
}
-#ifdef WITH_OPENSUBDIV
-/* Update face-varying variables offset which might be
- * different from mesh to mesh sharing the same material.
- */
-void GPU_draw_update_fvar_offset(DerivedMesh *dm)
+void GPU_enable_program_point_size(void)
{
- /* Sanity check to be sure we only do this for OpenSubdiv draw. */
- BLI_assert(dm->type == DM_TYPE_CCGDM);
- BLI_assert(GMS.is_opensubdiv);
-
- for (int i = 0; i < GMS.totmat; ++i) {
- Material *material = GMS.gmatbuf[i];
- GPUMaterial *gpu_material;
-
- if (material == NULL) {
- continue;
- }
-
- gpu_material = GPU_material_from_blender(GMS.gscene,
- material,
- GMS.is_opensubdiv);
-
- GPU_material_update_fvar_offset(gpu_material, dm);
- }
+ glEnable(GL_PROGRAM_POINT_SIZE);
}
-#endif
+void GPU_disable_program_point_size(void)
+{
+ glDisable(GL_PROGRAM_POINT_SIZE);
+}
/** \name Framebuffer color depth, for selection codes
* \{ */
@@ -2502,10 +1261,10 @@ void GPU_select_to_index_array(unsigned int *col, const unsigned int size)
{
#define INDEX_BUF_ARRAY(INDEX_FROM_BUF_BITS) \
for (i = size; i--; col++) { \
- if ((c = *col)) { \
- *col = INDEX_FROM_BUF_BITS(c); \
- } \
- } ((void)0)
+ if ((c = *col)) { \
+ *col = INDEX_FROM_BUF_BITS(c); \
+ } \
+ } ((void)0)
if (size > 0) {
unsigned int i, c;
@@ -2533,4 +1292,173 @@ void GPU_select_to_index_array(unsigned int *col, const unsigned int size)
#undef INDEX_BUF_ARRAY
}
+#define STATE_STACK_DEPTH 16
+
+typedef struct {
+ eGPUAttribMask mask;
+
+ /* GL_ENABLE_BIT */
+ unsigned int is_blend : 1;
+ unsigned int is_cull_face : 1;
+ unsigned int is_depth_test : 1;
+ unsigned int is_dither : 1;
+ unsigned int is_lighting : 1;
+ unsigned int is_line_smooth : 1;
+ unsigned int is_color_logic_op : 1;
+ unsigned int is_multisample : 1;
+ unsigned int is_polygon_offset_line : 1;
+ unsigned int is_polygon_offset_fill : 1;
+ unsigned int is_polygon_smooth : 1;
+ unsigned int is_sample_alpha_to_coverage : 1;
+ unsigned int is_scissor_test : 1;
+ unsigned int is_stencil_test : 1;
+
+ bool is_clip_plane[6];
+
+ /* GL_DEPTH_BUFFER_BIT */
+ /* unsigned int is_depth_test : 1; */
+ int depth_func;
+ double depth_clear_value;
+ bool depth_write_mask;
+
+ /* GL_SCISSOR_BIT */
+ int scissor_box[4];
+ /* unsigned int is_scissor_test : 1; */
+
+ /* GL_VIEWPORT_BIT */
+ int viewport[4];
+ double near_far[2];
+} GPUAttribValues;
+
+typedef struct {
+ GPUAttribValues attrib_stack[STATE_STACK_DEPTH];
+ unsigned int top;
+} GPUAttribStack;
+
+static GPUAttribStack state = {
+ .top = 0
+};
+
+#define AttribStack state
+#define Attrib state.attrib_stack[state.top]
+
+/**
+ * Replacement for glPush/PopAttributes
+ *
+ * We don't need to cover all the options of legacy OpenGL
+ * but simply the ones used by Blender.
+ */
+void gpuPushAttrib(eGPUAttribMask mask)
+{
+ Attrib.mask = mask;
+
+ if ((mask & GPU_DEPTH_BUFFER_BIT) != 0) {
+ Attrib.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
+ glGetIntegerv(GL_DEPTH_FUNC, &Attrib.depth_func);
+ glGetDoublev(GL_DEPTH_CLEAR_VALUE, &Attrib.depth_clear_value);
+ glGetBooleanv(GL_DEPTH_WRITEMASK, (GLboolean *)&Attrib.depth_write_mask);
+ }
+
+ if ((mask & GPU_ENABLE_BIT) != 0) {
+ Attrib.is_blend = glIsEnabled(GL_BLEND);
+
+ for (int i = 0; i < 6; i++) {
+ Attrib.is_clip_plane[i] = glIsEnabled(GL_CLIP_PLANE0 + i);
+ }
+
+ Attrib.is_cull_face = glIsEnabled(GL_CULL_FACE);
+ Attrib.is_depth_test = glIsEnabled(GL_DEPTH_TEST);
+ Attrib.is_dither = glIsEnabled(GL_DITHER);
+ Attrib.is_line_smooth = glIsEnabled(GL_LINE_SMOOTH);
+ Attrib.is_color_logic_op = glIsEnabled(GL_COLOR_LOGIC_OP);
+ Attrib.is_multisample = glIsEnabled(GL_MULTISAMPLE);
+ Attrib.is_polygon_offset_line = glIsEnabled(GL_POLYGON_OFFSET_LINE);
+ Attrib.is_polygon_offset_fill = glIsEnabled(GL_POLYGON_OFFSET_FILL);
+ Attrib.is_polygon_smooth = glIsEnabled(GL_POLYGON_SMOOTH);
+ Attrib.is_sample_alpha_to_coverage = glIsEnabled(GL_SAMPLE_ALPHA_TO_COVERAGE);
+ Attrib.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
+ Attrib.is_stencil_test = glIsEnabled(GL_STENCIL_TEST);
+ }
+
+ if ((mask & GPU_SCISSOR_BIT) != 0) {
+ Attrib.is_scissor_test = glIsEnabled(GL_SCISSOR_TEST);
+ glGetIntegerv(GL_SCISSOR_BOX, (GLint *)&Attrib.scissor_box);
+ }
+
+ if ((mask & GPU_VIEWPORT_BIT) != 0) {
+ glGetDoublev(GL_DEPTH_RANGE, (GLdouble *)&Attrib.near_far);
+ glGetIntegerv(GL_VIEWPORT, (GLint *)&Attrib.viewport);
+ }
+
+ if ((mask & GPU_BLEND_BIT) != 0) {
+ Attrib.is_blend = glIsEnabled(GL_BLEND);
+ }
+
+ BLI_assert(AttribStack.top < STATE_STACK_DEPTH);
+ AttribStack.top++;
+}
+
+static void restore_mask(GLenum cap, const bool value)
+{
+ if (value) {
+ glEnable(cap);
+ }
+ else {
+ glDisable(cap);
+ }
+}
+
+void gpuPopAttrib(void)
+{
+ BLI_assert(AttribStack.top > 0);
+ AttribStack.top--;
+
+ GLint mask = Attrib.mask;
+
+ if ((mask & GPU_DEPTH_BUFFER_BIT) != 0) {
+ restore_mask(GL_DEPTH_TEST, Attrib.is_depth_test);
+ glDepthFunc(Attrib.depth_func);
+ glClearDepth(Attrib.depth_clear_value);
+ glDepthMask(Attrib.depth_write_mask);
+ }
+
+ if ((mask & GPU_ENABLE_BIT) != 0) {
+ restore_mask(GL_BLEND, Attrib.is_blend);
+
+ for (int i = 0; i < 6; i++) {
+ restore_mask(GL_CLIP_PLANE0 + i, Attrib.is_clip_plane[i]);
+ }
+
+ restore_mask(GL_CULL_FACE, Attrib.is_cull_face);
+ restore_mask(GL_DEPTH_TEST, Attrib.is_depth_test);
+ restore_mask(GL_DITHER, Attrib.is_dither);
+ restore_mask(GL_LINE_SMOOTH, Attrib.is_line_smooth);
+ restore_mask(GL_COLOR_LOGIC_OP, Attrib.is_color_logic_op);
+ restore_mask(GL_MULTISAMPLE, Attrib.is_multisample);
+ restore_mask(GL_POLYGON_OFFSET_LINE, Attrib.is_polygon_offset_line);
+ restore_mask(GL_POLYGON_OFFSET_FILL, Attrib.is_polygon_offset_fill);
+ restore_mask(GL_POLYGON_SMOOTH, Attrib.is_polygon_smooth);
+ restore_mask(GL_SAMPLE_ALPHA_TO_COVERAGE, Attrib.is_sample_alpha_to_coverage);
+ restore_mask(GL_SCISSOR_TEST, Attrib.is_scissor_test);
+ restore_mask(GL_STENCIL_TEST, Attrib.is_stencil_test);
+ }
+
+ if ((mask & GPU_VIEWPORT_BIT) != 0) {
+ glViewport(Attrib.viewport[0], Attrib.viewport[1], Attrib.viewport[2], Attrib.viewport[3]);
+ glDepthRange(Attrib.near_far[0], Attrib.near_far[1]);
+ }
+
+ if ((mask & GPU_SCISSOR_BIT) != 0) {
+ restore_mask(GL_SCISSOR_TEST, Attrib.is_scissor_test);
+ glScissor(Attrib.scissor_box[0], Attrib.scissor_box[1], Attrib.scissor_box[2], Attrib.scissor_box[3]);
+ }
+
+ if ((mask & GPU_BLEND_BIT) != 0) {
+ restore_mask(GL_BLEND, Attrib.is_blend);
+ }
+}
+
+#undef Attrib
+#undef AttribStack
+
/** \} */
diff --git a/source/blender/gpu/intern/gpu_extensions.c b/source/blender/gpu/intern/gpu_extensions.c
index e0ce87d0e68..73e86c1b391 100644
--- a/source/blender/gpu/intern/gpu_extensions.c
+++ b/source/blender/gpu/intern/gpu_extensions.c
@@ -56,14 +56,11 @@
/* Extensions support */
/* -- extension: version of GL that absorbs it
+ * EXT_gpu_shader4: 3.0
* ARB_framebuffer object: 3.0
- * EXT_framebuffer_object: 3.0
- * EXT_framebuffer_blit: 3.0
- * EXT_framebuffer_multisample: 3.0
* EXT_framebuffer_multisample_blit_scaled: ???
* ARB_draw_instanced: 3.1
* ARB_texture_multisample: 3.2
- * EXT_geometry_shader4: 3.2
* ARB_texture_query_lod: 4.0
*/
@@ -71,7 +68,8 @@ static struct GPUGlobal {
GLint maxtexsize;
GLint maxcubemapsize;
GLint maxtextures;
- bool extdisabled;
+ GLint maxubosize;
+ GLint maxubobinds;
int colordepth;
int samples_color_texture_max;
GPUDeviceType device;
@@ -93,11 +91,6 @@ bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
/* GPU Extensions */
-void GPU_extensions_disable(void)
-{
- GG.extdisabled = true;
-}
-
int GPU_max_texture_size(void)
{
return GG.maxtexsize;
@@ -123,6 +116,16 @@ int GPU_max_cube_map_size(void)
return GG.maxcubemapsize;
}
+int GPU_max_ubo_binds(void)
+{
+ return GG.maxubobinds;
+}
+
+int GPU_max_ubo_size(void)
+{
+ return GG.maxubosize;
+}
+
void GPU_get_dfdy_factors(float fac[2])
{
copy_v2_v2(fac, GG.dfdyfactors);
@@ -130,8 +133,11 @@ void GPU_get_dfdy_factors(float fac[2])
void gpu_extensions_init(void)
{
- /* BLI_assert(GLEW_VERSION_2_1); */
- /* ^-- maybe a bit extreme? */
+ /* during 2.8 development each platform has its own OpenGL minimum requirements
+ * final 2.8 release will be unified on OpenGL 3.3 core profile, no required extensions
+ * see developer.blender.org/T49012 for details
+ */
+ BLI_assert(GLEW_VERSION_3_3);
glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS, &GG.maxtextures);
@@ -143,11 +149,22 @@ void gpu_extensions_init(void)
else
GG.max_anisotropy = 1.0f;
+ glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_BLOCKS, &GG.maxubobinds);
+ glGetIntegerv(GL_MAX_UNIFORM_BLOCK_SIZE, &GG.maxubosize);
+
+#ifndef NDEBUG
+ GLint ret;
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE, &ret);
+ /* We expect FRONT_LEFT to be the default buffer. */
+ BLI_assert(ret == GL_FRAMEBUFFER_DEFAULT);
+#endif
+
GLint r, g, b;
- glGetIntegerv(GL_RED_BITS, &r);
- glGetIntegerv(GL_GREEN_BITS, &g);
- glGetIntegerv(GL_BLUE_BITS, &b);
- GG.colordepth = r + g + b; /* assumes same depth for RGB */
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_RED_SIZE, &r);
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_GREEN_SIZE, &g);
+ glGetFramebufferAttachmentParameteriv(GL_FRAMEBUFFER, GL_FRONT_LEFT, GL_FRAMEBUFFER_ATTACHMENT_BLUE_SIZE, &b);
+ GG.colordepth = r + g + b; /* Assumes same depth for RGB. */
if (GLEW_VERSION_3_2 || GLEW_ARB_texture_multisample) {
glGetIntegerv(GL_MAX_COLOR_TEXTURE_SAMPLES, &GG.samples_color_texture_max);
@@ -201,10 +218,6 @@ void gpu_extensions_init(void)
GG.driver = GPU_DRIVER_ANY;
}
- /* make sure double side isn't used by default and only getting enabled in places where it's
- * really needed to prevent different unexpected behaviors like with intel gme965 card (sergey) */
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE);
-
#ifdef _WIN32
GG.os = GPU_OS_WIN;
#elif defined(__APPLE__)
@@ -246,43 +259,6 @@ void gpu_extensions_exit(void)
GPU_invalid_tex_free();
}
-bool GPU_legacy_support(void)
-{
- /* return whether or not current GL context is compatible with legacy OpenGL */
- static bool checked = false;
- static bool support = true;
-
- if (!checked) {
- if (GLEW_VERSION_3_2) {
- GLint profile;
- glGetIntegerv(GL_CONTEXT_PROFILE_MASK, &profile);
-
- if (G.debug & G_DEBUG_GPU) {
- printf("GL_CONTEXT_PROFILE_MASK = %#x (%s profile)\n", (unsigned int)profile,
- (profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT) ? "compatibility" :
- (profile & GL_CONTEXT_CORE_PROFILE_BIT) ? "core" : "unknown");
- }
-
- if (profile == 0) {
- /* workaround for nVidia's Linux driver */
- support = GLEW_ARB_compatibility;
- }
- else {
- support = profile & GL_CONTEXT_COMPATIBILITY_PROFILE_BIT;
- }
- }
- else if (GLEW_VERSION_3_1) {
- support = GLEW_ARB_compatibility;
- }
-
- /* any OpenGL version <= 3.0 is legacy, so support remains true */
-
- checked = true;
- }
-
- return support;
-}
-
bool GPU_full_non_power_of_two_support(void)
{
/* always supported on full GL but still relevant for OpenGL ES 2.0 where
@@ -290,39 +266,11 @@ bool GPU_full_non_power_of_two_support(void)
return true;
}
-bool GPU_display_list_support(void)
-{
- /* deprecated in GL 3
- * supported on older GL and compatibility profile
- * still queried by game engine
- */
- return true;
-}
-
bool GPU_bicubic_bump_support(void)
{
return GLEW_VERSION_4_0 || (GLEW_ARB_texture_query_lod && GLEW_VERSION_3_0);
}
-bool GPU_geometry_shader_support(void)
-{
- /* in GL 3.2 geometry shaders are fully supported
- * core profile clashes with our other shaders so accept compatibility only
- * other GL versions can use EXT_geometry_shader4 if available
- */
- return (GLEW_VERSION_3_2 && GPU_legacy_support()) || GLEW_EXT_geometry_shader4;
-}
-
-bool GPU_geometry_shader_support_via_extension(void)
-{
- return GLEW_EXT_geometry_shader4 && !(GLEW_VERSION_3_2 && GPU_legacy_support());
-}
-
-bool GPU_instanced_drawing_support(void)
-{
- return GLEW_VERSION_3_1 || GLEW_ARB_draw_instanced;
-}
-
int GPU_color_depth(void)
{
return GG.colordepth;
@@ -330,12 +278,14 @@ int GPU_color_depth(void)
bool GPU_mem_stats_supported(void)
{
- return (GLEW_NVX_gpu_memory_info || (GLEW_ATI_meminfo)) && (G.debug & G_DEBUG_GPU_MEM);
+ return (GLEW_NVX_gpu_memory_info || GLEW_ATI_meminfo) && (G.debug & G_DEBUG_GPU_MEM);
}
void GPU_mem_stats_get(int *totalmem, int *freemem)
{
+ /* TODO(merwin): use Apple's platform API to get this info */
+
if (GLEW_NVX_gpu_memory_info) {
/* returned value in Kb */
glGetIntegerv(GL_GPU_MEMORY_INFO_TOTAL_AVAILABLE_MEMORY_NVX, totalmem);
diff --git a/source/blender/gpu/intern/gpu_framebuffer.c b/source/blender/gpu/intern/gpu_framebuffer.c
index e7a8beae5cc..75576c35f51 100644
--- a/source/blender/gpu/intern/gpu_framebuffer.c
+++ b/source/blender/gpu/intern/gpu_framebuffer.c
@@ -28,70 +28,138 @@
#include "MEM_guardedalloc.h"
#include "BLI_blenlib.h"
+#include "BLI_threads.h"
#include "BLI_utildefines.h"
+#include "BLI_math_base.h"
#include "BKE_global.h"
-#include "GPU_debug.h"
-#include "GPU_glew.h"
+#include "GPU_batch.h"
+#include "GPU_draw.h"
+#include "GPU_extensions.h"
#include "GPU_framebuffer.h"
+#include "GPU_matrix.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
-static struct GPUFrameBufferGlobal {
- GLuint currentfb;
-} GG = {0};
+static ThreadLocal(GLuint) g_currentfb;
-/* Number of maximum output slots.
- * We support 4 outputs for now (usually we wouldn't need more to preserve fill rate) */
-#define GPU_FB_MAX_SLOTS 4
+typedef enum {
+ GPU_FB_DEPTH_ATTACHMENT = 0,
+ GPU_FB_DEPTH_STENCIL_ATTACHMENT,
+ GPU_FB_COLOR_ATTACHMENT0,
+ GPU_FB_COLOR_ATTACHMENT1,
+ GPU_FB_COLOR_ATTACHMENT2,
+ GPU_FB_COLOR_ATTACHMENT3,
+ GPU_FB_COLOR_ATTACHMENT4,
+ /* Number of maximum output slots.
+ * We support 5 outputs for now (usually we wouldn't need more to preserve fill rate). */
+ /* Keep in mind that GL max is GL_MAX_DRAW_BUFFERS and is at least 8, corresponding to
+ * the maximum number of COLOR attachments specified by glDrawBuffers. */
+ GPU_FB_MAX_ATTACHEMENT
+} GPUAttachmentType;
+
+#define GPU_FB_MAX_COLOR_ATTACHMENT (GPU_FB_MAX_ATTACHEMENT - GPU_FB_COLOR_ATTACHMENT0)
+
+#define GPU_FB_DIRTY_DRAWBUFFER (1 << 15)
+
+#define GPU_FB_ATTACHEMENT_IS_DIRTY(flag, type) ((flag & (1 << type)) != 0)
+#define GPU_FB_ATTACHEMENT_SET_DIRTY(flag, type) (flag |= (1 << type))
struct GPUFrameBuffer {
GLuint object;
- GPUTexture *colortex[GPU_FB_MAX_SLOTS];
- GPUTexture *depthtex;
+ GPUAttachment attachments[GPU_FB_MAX_ATTACHEMENT];
+ uint16_t dirty_flag;
+ int width, height;
+ bool multisample;
+ /* TODO Check that we always use the right context when binding
+ * (FBOs are not shared accross ogl contexts). */
+ // void *ctx;
};
+static GLenum convert_attachment_type_to_gl(GPUAttachmentType type)
+{
+ static const GLenum table[] = {
+ [GPU_FB_DEPTH_ATTACHMENT] = GL_DEPTH_ATTACHMENT,
+ [GPU_FB_DEPTH_STENCIL_ATTACHMENT] = GL_DEPTH_STENCIL_ATTACHMENT,
+ [GPU_FB_COLOR_ATTACHMENT0] = GL_COLOR_ATTACHMENT0,
+ [GPU_FB_COLOR_ATTACHMENT1] = GL_COLOR_ATTACHMENT1,
+ [GPU_FB_COLOR_ATTACHMENT2] = GL_COLOR_ATTACHMENT2,
+ [GPU_FB_COLOR_ATTACHMENT3] = GL_COLOR_ATTACHMENT3,
+ [GPU_FB_COLOR_ATTACHMENT4] = GL_COLOR_ATTACHMENT4
+ };
+ return table[type];
+}
+
+static GPUAttachmentType attachment_type_from_tex(GPUTexture *tex, int slot)
+{
+ switch (GPU_texture_format(tex)) {
+ case GPU_DEPTH_COMPONENT32F:
+ case GPU_DEPTH_COMPONENT24:
+ case GPU_DEPTH_COMPONENT16:
+ return GPU_FB_DEPTH_ATTACHMENT;
+ case GPU_DEPTH24_STENCIL8:
+ return GPU_FB_DEPTH_STENCIL_ATTACHMENT;
+ default:
+ return GPU_FB_COLOR_ATTACHMENT0 + slot;
+ }
+}
+
+static GLenum convert_buffer_bits_to_gl(GPUFrameBufferBits bits)
+{
+ GLbitfield mask = 0;
+ mask |= (bits & GPU_DEPTH_BIT) ? GL_DEPTH_BUFFER_BIT : 0;
+ mask |= (bits & GPU_STENCIL_BIT) ? GL_STENCIL_BUFFER_BIT : 0;
+ mask |= (bits & GPU_COLOR_BIT) ? GL_COLOR_BUFFER_BIT : 0;
+ return mask;
+}
+
+static GPUTexture *framebuffer_get_depth_tex(GPUFrameBuffer *fb)
+{
+ if (fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex)
+ return fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex;
+ else
+ return fb->attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex;;
+}
+
+static GPUTexture *framebuffer_get_color_tex(GPUFrameBuffer *fb, int slot)
+{
+ return fb->attachments[GPU_FB_COLOR_ATTACHMENT0 + slot].tex;
+}
+
static void gpu_print_framebuffer_error(GLenum status, char err_out[256])
{
+ const char *format = "GPUFrameBuffer: framebuffer status %s\n";
const char *err = "unknown";
+#define format_status(X) \
+ case GL_FRAMEBUFFER_##X: err = "GL_FRAMEBUFFER_"#X; \
+ break;
+
switch (status) {
- case GL_FRAMEBUFFER_COMPLETE_EXT:
- break;
- case GL_INVALID_OPERATION:
- err = "Invalid operation";
- break;
- case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
- err = "Incomplete attachment";
- break;
- case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
- err = "Unsupported framebuffer format";
- break;
- case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
- err = "Missing attachment";
- break;
- case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
- err = "Attached images must have same dimensions";
- break;
- case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
- err = "Attached images must have same format";
- break;
- case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
- err = "Missing draw buffer";
- break;
- case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
- err = "Missing read buffer";
- break;
+ /* success */
+ format_status(COMPLETE)
+ /* errors shared by OpenGL desktop & ES */
+ format_status(INCOMPLETE_ATTACHMENT)
+ format_status(INCOMPLETE_MISSING_ATTACHMENT)
+ format_status(UNSUPPORTED)
+#if 0 /* for OpenGL ES only */
+ format_status(INCOMPLETE_DIMENSIONS)
+#else /* for desktop GL only */
+ format_status(INCOMPLETE_DRAW_BUFFER)
+ format_status(INCOMPLETE_READ_BUFFER)
+ format_status(INCOMPLETE_MULTISAMPLE)
+ format_status(UNDEFINED)
+#endif
}
+#undef format_status
+
if (err_out) {
- BLI_snprintf(err_out, 256, "GPUFrameBuffer: framebuffer incomplete error %d '%s'",
- (int)status, err);
+ BLI_snprintf(err_out, 256, format, err);
}
else {
- fprintf(stderr, "GPUFrameBuffer: framebuffer incomplete error %d '%s'\n",
- (int)status, err);
+ fprintf(stderr, format, err);
}
}
@@ -99,348 +167,480 @@ static void gpu_print_framebuffer_error(GLenum status, char err_out[256])
GPUFrameBuffer *GPU_framebuffer_create(void)
{
- GPUFrameBuffer *fb;
+ /* We generate the FB object later at first use in order to
+ * create the framebuffer in the right opengl context. */
+ return MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");;
+}
- if (!(GLEW_VERSION_3_0 || GLEW_ARB_framebuffer_object ||
- (GLEW_EXT_framebuffer_object && GLEW_EXT_framebuffer_blit)))
- {
- return NULL;
+static void gpu_framebuffer_init(GPUFrameBuffer *fb)
+{
+ glGenFramebuffers(1, &fb->object);
+}
+
+void GPU_framebuffer_free(GPUFrameBuffer *fb)
+{
+ for (GPUAttachmentType type = 0; type < GPU_FB_MAX_ATTACHEMENT; type++) {
+ if (fb->attachments[type].tex != NULL) {
+ GPU_framebuffer_texture_detach(fb, fb->attachments[type].tex);
+ }
}
-
- fb = MEM_callocN(sizeof(GPUFrameBuffer), "GPUFrameBuffer");
- glGenFramebuffersEXT(1, &fb->object);
- if (!fb->object) {
- fprintf(stderr, "GPUFFrameBuffer: framebuffer gen failed. %d\n",
- (int)glGetError());
- GPU_framebuffer_free(fb);
- return NULL;
+ /* This restores the framebuffer if it was bound */
+ glDeleteFramebuffers(1, &fb->object);
+
+ if (g_currentfb == fb->object) {
+ g_currentfb = 0;
}
- /* make sure no read buffer is enabled, so completeness check will not fail. We set those at binding time */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
- glReadBuffer(GL_NONE);
- glDrawBuffer(GL_NONE);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
- return fb;
+ MEM_freeN(fb);
}
-int GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, char err_out[256])
-{
- GLenum attachment;
- GLenum error;
+/* ---------- Attach ----------- */
- if (slot >= GPU_FB_MAX_SLOTS) {
+static void gpu_framebuffer_texture_attach_ex(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip)
+{
+ if (slot >= GPU_FB_MAX_COLOR_ATTACHMENT) {
fprintf(stderr,
"Attaching to index %d framebuffer slot unsupported. "
- "Use at most %d\n", slot, GPU_FB_MAX_SLOTS);
- return 0;
- }
-
- if ((G.debug & G_DEBUG)) {
- if (GPU_texture_bound_number(tex) != -1) {
- fprintf(stderr,
- "Feedback loop warning!: "
- "Attempting to attach texture to framebuffer while still bound to texture unit for drawing!\n");
- }
+ "Use at most %d\n", slot, GPU_FB_MAX_COLOR_ATTACHMENT);
+ return;
}
- if (GPU_texture_depth(tex))
- attachment = GL_DEPTH_ATTACHMENT_EXT;
- else
- attachment = GL_COLOR_ATTACHMENT0_EXT + slot;
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
- GG.currentfb = fb->object;
+ GPUAttachmentType type = attachment_type_from_tex(tex, slot);
+ GPUAttachment *attachment = &fb->attachments[type];
- /* Clean glError buffer. */
- while (glGetError() != GL_NO_ERROR) {}
-
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment,
- GPU_texture_target(tex), GPU_texture_opengl_bindcode(tex), 0);
-
- error = glGetError();
+ if ((attachment->tex == tex) &&
+ (attachment->mip == mip) &&
+ (attachment->layer == layer))
+ {
+ return; /* Exact same texture already bound here. */
+ }
+ else if (attachment->tex != NULL) {
+ GPU_framebuffer_texture_detach(fb, attachment->tex);
+ }
- if (error == GL_INVALID_OPERATION) {
- GPU_framebuffer_restore();
- gpu_print_framebuffer_error(error, err_out);
- return 0;
+ if (attachment->tex == NULL) {
+ GPU_texture_attach_framebuffer(tex, fb, type);
}
- if (GPU_texture_depth(tex))
- fb->depthtex = tex;
- else
- fb->colortex[slot] = tex;
+ attachment->tex = tex;
+ attachment->mip = mip;
+ attachment->layer = layer;
+ GPU_FB_ATTACHEMENT_SET_DIRTY(fb->dirty_flag, type);
+}
- GPU_texture_framebuffer_set(tex, fb, slot);
+void GPU_framebuffer_texture_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int mip)
+{
+ gpu_framebuffer_texture_attach_ex(fb, tex, slot, -1, mip);
+}
- return 1;
+void GPU_framebuffer_texture_layer_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int layer, int mip)
+{
+ /* NOTE: We could support 1D ARRAY texture. */
+ BLI_assert(GPU_texture_target(tex) == GL_TEXTURE_2D_ARRAY);
+ gpu_framebuffer_texture_attach_ex(fb, tex, slot, layer, mip);
}
-void GPU_framebuffer_texture_detach(GPUTexture *tex)
+void GPU_framebuffer_texture_cubeface_attach(GPUFrameBuffer *fb, GPUTexture *tex, int slot, int face, int mip)
{
- GLenum attachment;
- GPUFrameBuffer *fb = GPU_texture_framebuffer(tex);
- int fb_attachment = GPU_texture_framebuffer_attachment(tex);
+ BLI_assert(GPU_texture_cube(tex));
+ gpu_framebuffer_texture_attach_ex(fb, tex, slot, face, mip);
+}
- if (!fb)
- return;
+/* ---------- Detach ----------- */
- if (GG.currentfb != fb->object) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
- GG.currentfb = fb->object;
- }
+void GPU_framebuffer_texture_detach_slot(GPUFrameBuffer *fb, GPUTexture *tex, int type)
+{
+ GPUAttachment *attachment = &fb->attachments[type];
- if (GPU_texture_depth(tex)) {
- fb->depthtex = NULL;
- attachment = GL_DEPTH_ATTACHMENT_EXT;
- }
- else {
- BLI_assert(fb->colortex[fb_attachment] == tex);
- fb->colortex[fb_attachment] = NULL;
- attachment = GL_COLOR_ATTACHMENT0_EXT + fb_attachment;
+ if (attachment->tex != tex) {
+ fprintf(stderr,
+ "Warning, attempting to detach Texture %p from framebuffer %p "
+ "but texture is not attached.\n", tex, fb);
+ return;
}
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, attachment, GPU_texture_target(tex), 0, 0);
+ attachment->tex = NULL;
+ GPU_FB_ATTACHEMENT_SET_DIRTY(fb->dirty_flag, type);
+}
- GPU_texture_framebuffer_set(tex, NULL, -1);
+void GPU_framebuffer_texture_detach(GPUFrameBuffer *fb, GPUTexture *tex)
+{
+ GPUAttachmentType type = GPU_texture_detach_framebuffer(tex, fb);
+ GPU_framebuffer_texture_detach_slot(fb, tex, type);
}
-void GPU_texture_bind_as_framebuffer(GPUTexture *tex)
+/* ---------- Config (Attach & Detach) ----------- */
+
+/**
+ * First GPUAttachment in *config is always the depth/depth_stencil buffer.
+ * Following GPUAttachments are color buffers.
+ * Setting GPUAttachment.mip to -1 will leave the texture in this slot.
+ * Setting GPUAttachment.tex to NULL will detach the texture in this slot.
+ **/
+void GPU_framebuffer_config_array(GPUFrameBuffer *fb, const GPUAttachment *config, int config_ct)
{
- GPUFrameBuffer *fb = GPU_texture_framebuffer(tex);
- int fb_attachment = GPU_texture_framebuffer_attachment(tex);
+ if (config[0].tex) {
+ BLI_assert(GPU_texture_depth(config[0].tex));
+ gpu_framebuffer_texture_attach_ex(fb, config[0].tex, 0, config[0].layer, config[0].mip);
+ }
+ else if (config[0].mip == -1) {
+ /* Leave texture attached */
+ }
+ else if (fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex != NULL) {
+ GPU_framebuffer_texture_detach(fb, fb->attachments[GPU_FB_DEPTH_ATTACHMENT].tex);
+ }
+ else if (fb->attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex != NULL) {
+ GPU_framebuffer_texture_detach(fb, fb->attachments[GPU_FB_DEPTH_STENCIL_ATTACHMENT].tex);
+ }
- if (!fb) {
- fprintf(stderr, "Error, texture not bound to framebuffer!\n");
- return;
+ int slot = 0;
+ for (int i = 1; i < config_ct; ++i, ++slot) {
+ if (config[i].tex != NULL) {
+ BLI_assert(GPU_texture_depth(config[i].tex) == false);
+ gpu_framebuffer_texture_attach_ex(fb, config[i].tex, slot, config[i].layer, config[i].mip);
+ }
+ else if (config[i].mip != -1) {
+ GPUTexture *tex = framebuffer_get_color_tex(fb, slot);
+ if (tex != NULL) {
+ GPU_framebuffer_texture_detach(fb, tex);
+ }
+ }
}
+}
- /* push attributes */
- glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT);
- glDisable(GL_SCISSOR_TEST);
+/* ---------- Bind / Restore ----------- */
- /* bind framebuffer */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
+static void gpu_framebuffer_attachment_attach(GPUAttachment *attach, GPUAttachmentType attach_type)
+{
+ int tex_bind = GPU_texture_opengl_bindcode(attach->tex);
+ GLenum gl_attachment = convert_attachment_type_to_gl(attach_type);
- if (GPU_texture_depth(tex)) {
- glDrawBuffer(GL_NONE);
- glReadBuffer(GL_NONE);
+ if (attach->layer > -1) {
+ if (GPU_texture_cube(attach->tex)) {
+ glFramebufferTexture2D(GL_FRAMEBUFFER, gl_attachment, GL_TEXTURE_CUBE_MAP_POSITIVE_X + attach->layer,
+ tex_bind, attach->mip);
+ }
+ else {
+ glFramebufferTextureLayer(GL_FRAMEBUFFER, gl_attachment, tex_bind, attach->mip, attach->layer);
+ }
}
else {
- /* last bound prevails here, better allow explicit control here too */
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + fb_attachment);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + fb_attachment);
- }
-
- if (GPU_texture_target(tex) == GL_TEXTURE_2D_MULTISAMPLE) {
- glEnable(GL_MULTISAMPLE);
+ glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, tex_bind, attach->mip);
}
+}
- /* push matrices and set default viewport and matrix */
- glViewport(0, 0, GPU_texture_width(tex), GPU_texture_height(tex));
- GG.currentfb = fb->object;
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
+static void gpu_framebuffer_attachment_detach(GPUAttachment *UNUSED(attachment), GPUAttachmentType attach_type)
+{
+ GLenum gl_attachment = convert_attachment_type_to_gl(attach_type);
+ glFramebufferTexture(GL_FRAMEBUFFER, gl_attachment, 0, 0);
}
-void GPU_framebuffer_slots_bind(GPUFrameBuffer *fb, int slot)
+static void gpu_framebuffer_update_attachments(GPUFrameBuffer *fb)
{
- int numslots = 0, i;
- GLenum attachments[4];
-
- if (!fb->colortex[slot]) {
- fprintf(stderr, "Error, framebuffer slot empty!\n");
- return;
- }
-
- for (i = 0; i < 4; i++) {
- if (fb->colortex[i]) {
- attachments[numslots] = GL_COLOR_ATTACHMENT0_EXT + i;
+ GLenum gl_attachments[GPU_FB_MAX_COLOR_ATTACHMENT];
+ int numslots = 0;
+
+ BLI_assert(g_currentfb == fb->object);
+
+ /* Update attachments */
+ for (GPUAttachmentType type = 0; type < GPU_FB_MAX_ATTACHEMENT; ++type) {
+
+ if (type >= GPU_FB_COLOR_ATTACHMENT0) {
+ if (fb->attachments[type].tex) {
+ gl_attachments[numslots] = convert_attachment_type_to_gl(type);
+ }
+ else {
+ gl_attachments[numslots] = GL_NONE;
+ }
numslots++;
}
+
+ if (GPU_FB_ATTACHEMENT_IS_DIRTY(fb->dirty_flag, type) == false) {
+ continue;
+ }
+ else if (fb->attachments[type].tex != NULL) {
+ gpu_framebuffer_attachment_attach(&fb->attachments[type], type);
+
+ fb->multisample = (GPU_texture_samples(fb->attachments[type].tex) > 0);
+ fb->width = GPU_texture_width(fb->attachments[type].tex);
+ fb->height = GPU_texture_height(fb->attachments[type].tex);
+ }
+ else {
+ gpu_framebuffer_attachment_detach(&fb->attachments[type], type);
+ }
}
-
- /* push attributes */
- glPushAttrib(GL_ENABLE_BIT | GL_VIEWPORT_BIT);
- glDisable(GL_SCISSOR_TEST);
+ fb->dirty_flag = 0;
- /* bind framebuffer */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
+ /* Update draw buffers (color targets)
+ * This state is saved in the FBO */
+ if (numslots)
+ glDrawBuffers(numslots, gl_attachments);
+ else
+ glDrawBuffer(GL_NONE);
+}
- /* last bound prevails here, better allow explicit control here too */
- glDrawBuffers(numslots, attachments);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + slot);
+void GPU_framebuffer_bind(GPUFrameBuffer *fb)
+{
+ if (fb->object == 0)
+ gpu_framebuffer_init(fb);
- /* push matrices and set default viewport and matrix */
- glViewport(0, 0, GPU_texture_width(fb->colortex[slot]), GPU_texture_height(fb->colortex[slot]));
- GG.currentfb = fb->object;
+ if (g_currentfb != fb->object)
+ glBindFramebuffer(GL_FRAMEBUFFER, fb->object);
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
-}
+ g_currentfb = fb->object;
+ if (fb->dirty_flag != 0)
+ gpu_framebuffer_update_attachments(fb);
-void GPU_framebuffer_texture_unbind(GPUFrameBuffer *UNUSED(fb), GPUTexture *UNUSED(tex))
-{
- /* restore matrix */
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
+ /* TODO manually check for errors? */
+#if 0
+ char err_out[256];
+ if (!GPU_framebuffer_check_valid(fb, err_out)) {
+ printf("Invalid %s\n", err_out);
+ }
+#endif
+
+ if (fb->multisample)
+ glEnable(GL_MULTISAMPLE);
- /* restore attributes */
- glPopAttrib();
+ glViewport(0, 0, fb->width, fb->height);
}
-void GPU_framebuffer_bind_no_save(GPUFrameBuffer *fb, int slot)
+void GPU_framebuffer_restore(void)
{
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
- /* last bound prevails here, better allow explicit control here too */
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT + slot);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT + slot);
-
- /* push matrices and set default viewport and matrix */
- glViewport(0, 0, GPU_texture_width(fb->colortex[slot]), GPU_texture_height(fb->colortex[slot]));
- GG.currentfb = fb->object;
- GG.currentfb = fb->object;
+ if (g_currentfb != 0) {
+ glBindFramebuffer(GL_FRAMEBUFFER, 0);
+ g_currentfb = 0;
+ }
}
bool GPU_framebuffer_bound(GPUFrameBuffer *fb)
{
- return fb->object == GG.currentfb;
+ return (fb->object == g_currentfb) && (fb->object != 0);
+}
+
+unsigned int GPU_framebuffer_current_get(void)
+{
+ return g_currentfb;
}
bool GPU_framebuffer_check_valid(GPUFrameBuffer *fb, char err_out[256])
{
- GLenum status;
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
- GG.currentfb = fb->object;
-
- /* Clean glError buffer. */
- while (glGetError() != GL_NO_ERROR) {}
-
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ if (!GPU_framebuffer_bound(fb))
+ GPU_framebuffer_bind(fb);
+
+ GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
+
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
GPU_framebuffer_restore();
gpu_print_framebuffer_error(status, err_out);
return false;
}
-
+
return true;
}
-void GPU_framebuffer_free(GPUFrameBuffer *fb)
+/* ---------- Framebuffer Operations ----------- */
+
+#define CHECK_FRAMEBUFFER_IS_BOUND(_fb) \
+ BLI_assert(GPU_framebuffer_bound(_fb)); \
+ UNUSED_VARS_NDEBUG(_fb);
+
+/* Needs to be done after binding. */
+void GPU_framebuffer_viewport_set(GPUFrameBuffer *fb, int x, int y, int w, int h)
{
- int i;
- if (fb->depthtex)
- GPU_framebuffer_texture_detach(fb->depthtex);
+ CHECK_FRAMEBUFFER_IS_BOUND(fb);
- for (i = 0; i < GPU_FB_MAX_SLOTS; i++) {
- if (fb->colortex[i]) {
- GPU_framebuffer_texture_detach(fb->colortex[i]);
- }
- }
+ glViewport(x, y, w, h);
+}
- if (fb->object) {
- glDeleteFramebuffersEXT(1, &fb->object);
+void GPU_framebuffer_clear(
+ GPUFrameBuffer *fb, GPUFrameBufferBits buffers,
+ const float clear_col[4], float clear_depth, unsigned int clear_stencil)
+{
+ CHECK_FRAMEBUFFER_IS_BOUND(fb);
- if (GG.currentfb == fb->object) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- GG.currentfb = 0;
- }
+ if (buffers & GPU_COLOR_BIT) {
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ glClearColor(clear_col[0], clear_col[1], clear_col[2], clear_col[3]);
+ }
+ if (buffers & GPU_DEPTH_BIT) {
+ glDepthMask(GL_TRUE);
+ glClearDepth(clear_depth);
+ }
+ if (buffers & GPU_STENCIL_BIT) {
+ glStencilMask(clear_stencil);
}
- MEM_freeN(fb);
+ GLbitfield mask = convert_buffer_bits_to_gl(buffers);
+ glClear(mask);
}
-void GPU_framebuffer_restore(void)
+void GPU_framebuffer_read_depth(GPUFrameBuffer *fb, int x, int y, int w, int h, float *data)
+{
+ CHECK_FRAMEBUFFER_IS_BOUND(fb);
+
+ GLenum type = GL_DEPTH_COMPONENT;
+ glReadBuffer(GL_COLOR_ATTACHMENT0); /* This is OK! */
+ glReadPixels(x, y, w, h, type, GL_FLOAT, data);
+}
+
+void GPU_framebuffer_read_color(
+ GPUFrameBuffer *fb, int x, int y, int w, int h, int channels, int slot, float *data)
{
- if (GG.currentfb != 0) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- GG.currentfb = 0;
+ CHECK_FRAMEBUFFER_IS_BOUND(fb);
+
+ GLenum type;
+ switch (channels) {
+ case 1: type = GL_RED; break;
+ case 2: type = GL_RG; break;
+ case 3: type = GL_RGB; break;
+ case 4: type = GL_RGBA; break;
+ default:
+ BLI_assert(false && "wrong number of read channels");
+ return;
}
+ glReadBuffer(GL_COLOR_ATTACHMENT0 + slot);
+ glReadPixels(x, y, w, h, type, GL_FLOAT, data);
}
-void GPU_framebuffer_blur(
- GPUFrameBuffer *fb, GPUTexture *tex,
- GPUFrameBuffer *blurfb, GPUTexture *blurtex)
+/* read_slot and write_slot are only used for color buffers. */
+void GPU_framebuffer_blit(
+ GPUFrameBuffer *fb_read, int read_slot,
+ GPUFrameBuffer *fb_write, int write_slot,
+ GPUFrameBufferBits blit_buffers)
{
- const float scaleh[2] = {1.0f / GPU_texture_width(blurtex), 0.0f};
- const float scalev[2] = {0.0f, 1.0f / GPU_texture_height(tex)};
+ BLI_assert(blit_buffers != 0);
- GPUShader *blur_shader = GPU_shader_get_builtin_shader(GPU_SHADER_SEP_GAUSSIAN_BLUR);
- int scale_uniform, texture_source_uniform;
+ GLuint prev_fb = g_currentfb;
- if (!blur_shader)
- return;
+ /* Framebuffers must be up to date. This simplify this function. */
+ if (fb_read->dirty_flag != 0 || fb_read->object == 0) {
+ GPU_framebuffer_bind(fb_read);
+ }
+ if (fb_write->dirty_flag != 0 || fb_write->object == 0) {
+ GPU_framebuffer_bind(fb_write);
+ }
- scale_uniform = GPU_shader_get_uniform(blur_shader, "ScaleU");
- texture_source_uniform = GPU_shader_get_uniform(blur_shader, "textureSource");
-
- /* Blurring horizontally */
+ const bool do_color = (blit_buffers & GPU_COLOR_BIT);
+ const bool do_depth = (blit_buffers & GPU_DEPTH_BIT);
+ const bool do_stencil = (blit_buffers & GPU_STENCIL_BIT);
- /* We do the bind ourselves rather than using GPU_framebuffer_texture_bind() to avoid
- * pushing unnecessary matrices onto the OpenGL stack. */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, blurfb->object);
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
-
- /* avoid warnings from texture binding */
- GG.currentfb = blurfb->object;
-
- GPU_shader_bind(blur_shader);
- GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, scaleh);
- GPU_shader_uniform_texture(blur_shader, texture_source_uniform, tex);
- glViewport(0, 0, GPU_texture_width(blurtex), GPU_texture_height(blurtex));
-
- /* Preparing to draw quad */
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
-
- glDisable(GL_DEPTH_TEST);
-
- GPU_texture_bind(tex, 0);
-
- /* Drawing quad */
- glBegin(GL_QUADS);
- glTexCoord2d(0, 0); glVertex2f(1, 1);
- glTexCoord2d(1, 0); glVertex2f(-1, 1);
- glTexCoord2d(1, 1); glVertex2f(-1, -1);
- glTexCoord2d(0, 1); glVertex2f(1, -1);
- glEnd();
-
- /* Blurring vertically */
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, fb->object);
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
-
- GG.currentfb = fb->object;
-
- glViewport(0, 0, GPU_texture_width(tex), GPU_texture_height(tex));
- GPU_shader_uniform_vector(blur_shader, scale_uniform, 2, 1, scalev);
- GPU_shader_uniform_texture(blur_shader, texture_source_uniform, blurtex);
- GPU_texture_bind(blurtex, 0);
+ GPUTexture *read_tex = (do_depth || do_stencil)
+ ? framebuffer_get_depth_tex(fb_read)
+ : framebuffer_get_color_tex(fb_read, read_slot);
+ GPUTexture *write_tex = (do_depth || do_stencil)
+ ? framebuffer_get_depth_tex(fb_write)
+ : framebuffer_get_color_tex(fb_write, read_slot);
+
+ if (do_depth) {
+ BLI_assert(GPU_texture_depth(read_tex) && GPU_texture_depth(write_tex));
+ BLI_assert(GPU_texture_format(read_tex) == GPU_texture_format(write_tex));
+ }
+ if (do_stencil) {
+ BLI_assert(GPU_texture_stencil(read_tex) && GPU_texture_stencil(write_tex));
+ BLI_assert(GPU_texture_format(read_tex) == GPU_texture_format(write_tex));
+ }
+ if (GPU_texture_samples(write_tex) != 0 ||
+ GPU_texture_samples(read_tex) != 0)
+ {
+ /* Can only blit multisample textures to another texture of the same size. */
+ BLI_assert((fb_read->width == fb_write->width) &&
+ (fb_read->height == fb_write->height));
+ }
+
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fb_read->object);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fb_write->object);
+
+ if (do_color) {
+ glReadBuffer(GL_COLOR_ATTACHMENT0 + read_slot);
+ glDrawBuffer(GL_COLOR_ATTACHMENT0 + write_slot);
+ /* XXX we messed with the glDrawBuffer, this will reset the
+ * glDrawBuffers the next time we bind fb_write. */
+ fb_write->dirty_flag = GPU_FB_DIRTY_DRAWBUFFER;
+ }
+
+ GLbitfield mask = convert_buffer_bits_to_gl(blit_buffers);
+
+ glBlitFramebuffer(0, 0, fb_read->width, fb_read->height,
+ 0, 0, fb_write->width, fb_write->height,
+ mask, GL_NEAREST);
+
+ /* Restore previous framebuffer */
+ if (fb_write->object == prev_fb) {
+ GPU_framebuffer_bind(fb_write); /* To update drawbuffers */
+ }
+ else {
+ glBindFramebuffer(GL_FRAMEBUFFER, prev_fb);
+ g_currentfb = prev_fb;
+ }
+}
+
+/**
+ * Use this if you need to custom downsample your texture and use the previous mip level as input.
+ * This function only takes care of the correct texture handling. It execute the callback for each texture level.
+ **/
+void GPU_framebuffer_recursive_downsample(
+ GPUFrameBuffer *fb, int max_lvl,
+ void (*callback)(void *userData, int level), void *userData)
+{
+ /* Framebuffer must be up to date and bound. This simplify this function. */
+ if (g_currentfb != fb->object || fb->dirty_flag != 0 || fb->object == 0) {
+ GPU_framebuffer_bind(fb);
+ }
+ /* HACK: We make the framebuffer appear not bound in order to
+ * not trigger any error in GPU_texture_bind(). */
+ GLuint prev_fb = g_currentfb;
+ g_currentfb = 0;
+
+ int i;
+ int current_dim[2] = {fb->width, fb->height};
+ for (i = 1; i < max_lvl + 1; i++) {
+ /* calculate next viewport size */
+ current_dim[0] = max_ii(current_dim[0] / 2, 1);
+ current_dim[1] = max_ii(current_dim[1] / 2, 1);
+
+ for (GPUAttachmentType type = 0; type < GPU_FB_MAX_ATTACHEMENT; ++type) {
+ if (fb->attachments[type].tex != NULL) {
+ /* bind next level for rendering but first restrict fetches only to previous level */
+ GPUTexture *tex = fb->attachments[type].tex;
+ GPU_texture_bind(tex, 0);
+ glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_BASE_LEVEL, i - 1);
+ glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_MAX_LEVEL, i - 1);
+ GPU_texture_unbind(tex);
+ /* copy attachment and replace miplevel. */
+ GPUAttachment attachment = fb->attachments[type];
+ attachment.mip = i;
+ gpu_framebuffer_attachment_attach(&attachment, type);
+ }
+ }
- glBegin(GL_QUADS);
- glTexCoord2d(0, 0); glVertex2f(1, 1);
- glTexCoord2d(1, 0); glVertex2f(-1, 1);
- glTexCoord2d(1, 1); glVertex2f(-1, -1);
- glTexCoord2d(0, 1); glVertex2f(1, -1);
- glEnd();
+ BLI_assert(GL_FRAMEBUFFER_COMPLETE == glCheckFramebufferStatus(GL_FRAMEBUFFER));
+
+ glViewport(0, 0, current_dim[0], current_dim[1]);
+ callback(userData, i);
+
+ if (current_dim[0] == 1 && current_dim[1] == 1)
+ break;
+ }
- GPU_shader_unbind();
+ for (GPUAttachmentType type = 0; type < GPU_FB_MAX_ATTACHEMENT; ++type) {
+ if (fb->attachments[type].tex != NULL) {
+ /* reset mipmap level range */
+ GPUTexture *tex = fb->attachments[type].tex;
+ GPU_texture_bind(tex, 0);
+ glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_BASE_LEVEL, 0);
+ glTexParameteri(GPU_texture_target(tex), GL_TEXTURE_MAX_LEVEL, i - 1);
+ GPU_texture_unbind(tex);
+ /* Reattach original level */
+ /* NOTE: This is not necessary but this makes the FBO config
+ * remain in sync with the GPUFrameBuffer config. */
+ gpu_framebuffer_attachment_attach(&fb->attachments[type], type);
+ }
+ }
+
+ g_currentfb = prev_fb;
}
/* GPUOffScreen */
@@ -451,63 +651,42 @@ struct GPUOffScreen {
GPUTexture *depth;
};
-GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, char err_out[256])
+GPUOffScreen *GPU_offscreen_create(int width, int height, int samples, bool depth, bool high_bitdepth, char err_out[256])
{
GPUOffScreen *ofs;
ofs = MEM_callocN(sizeof(GPUOffScreen), "GPUOffScreen");
- ofs->fb = GPU_framebuffer_create();
- if (!ofs->fb) {
- GPU_offscreen_free(ofs);
- return NULL;
- }
+ ofs->color = GPU_texture_create_2D_multisample(width, height,
+ (high_bitdepth) ? GPU_RGBA16F : GPU_RGBA8, NULL, samples, err_out);
- if (samples) {
- if (!GLEW_EXT_framebuffer_multisample ||
- !GLEW_ARB_texture_multisample ||
- /* Only needed for GPU_offscreen_read_pixels.
- * We could add an arg if we intend to use multi-sample
- * offscreen buffers w/o reading their pixels */
- !GLEW_EXT_framebuffer_blit ||
- /* This is required when blitting from a multi-sampled buffers,
- * even though we're not scaling. */
- !GLEW_EXT_framebuffer_multisample_blit_scaled)
- {
- samples = 0;
- }
+ if (depth) {
+ ofs->depth = GPU_texture_create_2D_multisample(width, height, GPU_DEPTH24_STENCIL8, NULL, samples, err_out);
}
- ofs->depth = GPU_texture_create_depth_multisample(width, height, samples, err_out);
- if (!ofs->depth) {
+ if ((depth && !ofs->depth) || !ofs->color) {
GPU_offscreen_free(ofs);
return NULL;
}
- if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->depth, 0, err_out)) {
- GPU_offscreen_free(ofs);
- return NULL;
- }
+ gpuPushAttrib(GPU_VIEWPORT_BIT);
- ofs->color = GPU_texture_create_2D_multisample(width, height, NULL, GPU_HDR_NONE, samples, err_out);
- if (!ofs->color) {
- GPU_offscreen_free(ofs);
- return NULL;
- }
+ GPU_framebuffer_ensure_config(&ofs->fb, {
+ GPU_ATTACHMENT_TEXTURE(ofs->depth),
+ GPU_ATTACHMENT_TEXTURE(ofs->color)
+ });
- if (!GPU_framebuffer_texture_attach(ofs->fb, ofs->color, 0, err_out)) {
- GPU_offscreen_free(ofs);
- return NULL;
- }
-
/* check validity at the very end! */
if (!GPU_framebuffer_check_valid(ofs->fb, err_out)) {
GPU_offscreen_free(ofs);
+ gpuPopAttrib();
return NULL;
}
GPU_framebuffer_restore();
+ gpuPopAttrib();
+
return ofs;
}
@@ -525,20 +704,37 @@ void GPU_offscreen_free(GPUOffScreen *ofs)
void GPU_offscreen_bind(GPUOffScreen *ofs, bool save)
{
- glDisable(GL_SCISSOR_TEST);
- if (save)
- GPU_texture_bind_as_framebuffer(ofs->color);
- else {
- GPU_framebuffer_bind_no_save(ofs->fb, 0);
+ if (save) {
+ gpuPushAttrib(GPU_SCISSOR_BIT | GPU_VIEWPORT_BIT);
}
+ glDisable(GL_SCISSOR_TEST);
+ GPU_framebuffer_bind(ofs->fb);
}
-void GPU_offscreen_unbind(GPUOffScreen *ofs, bool restore)
+void GPU_offscreen_unbind(GPUOffScreen *UNUSED(ofs), bool restore)
{
- if (restore)
- GPU_framebuffer_texture_unbind(ofs->fb, ofs->color);
GPU_framebuffer_restore();
- glEnable(GL_SCISSOR_TEST);
+ if (restore) {
+ gpuPopAttrib();
+ }
+}
+
+void GPU_offscreen_draw_to_screen(GPUOffScreen *ofs, int x, int y)
+{
+ const int w = GPU_texture_width(ofs->color);
+ const int h = GPU_texture_height(ofs->color);
+
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, ofs->fb->object);
+ GLenum status = glCheckFramebufferStatus(GL_READ_FRAMEBUFFER);
+
+ if (status == GL_FRAMEBUFFER_COMPLETE) {
+ glBlitFramebuffer(0, 0, w, h, x, y, x + w, y + h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ }
+ else {
+ gpu_print_framebuffer_error(status, NULL);
+ }
+
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
}
void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
@@ -546,74 +742,46 @@ void GPU_offscreen_read_pixels(GPUOffScreen *ofs, int type, void *pixels)
const int w = GPU_texture_width(ofs->color);
const int h = GPU_texture_height(ofs->color);
+ BLI_assert(type == GL_UNSIGNED_BYTE || type == GL_FLOAT);
+
if (GPU_texture_target(ofs->color) == GL_TEXTURE_2D_MULTISAMPLE) {
/* For a multi-sample texture,
* we need to create an intermediate buffer to blit to,
* before its copied using 'glReadPixels' */
-
- /* not needed since 'ofs' needs to be bound to the framebuffer already */
-// #define USE_FBO_CTX_SWITCH
-
GLuint fbo_blit = 0;
GLuint tex_blit = 0;
- GLenum status;
/* create texture for new 'fbo_blit' */
glGenTextures(1, &tex_blit);
- if (!tex_blit) {
- goto finally;
- }
-
glBindTexture(GL_TEXTURE_2D, tex_blit);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_RGBA, type, 0);
-
-#ifdef USE_FBO_CTX_SWITCH
- /* read from multi-sample buffer */
- glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, ofs->color->fb->object);
- glFramebufferTexture2DEXT(
- GL_READ_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT + ofs->color->fb_attachment,
- GL_TEXTURE_2D_MULTISAMPLE, ofs->color->bindcode, 0);
- status = glCheckFramebufferStatusEXT(GL_READ_FRAMEBUFFER_EXT);
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- goto finally;
- }
-#endif
+ glTexImage2D(GL_TEXTURE_2D, 0, (type == GL_FLOAT) ? GL_RGBA16F : GL_RGBA8,
+ w, h, 0, GL_RGBA, type, 0);
/* write into new single-sample buffer */
- glGenFramebuffersEXT(1, &fbo_blit);
- glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, fbo_blit);
- glFramebufferTexture2DEXT(
- GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_2D, tex_blit, 0);
- status = glCheckFramebufferStatusEXT(GL_DRAW_FRAMEBUFFER_EXT);
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
+ glGenFramebuffers(1, &fbo_blit);
+ glBindFramebuffer(GL_DRAW_FRAMEBUFFER, fbo_blit);
+ glFramebufferTexture2D(GL_DRAW_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
+ GL_TEXTURE_2D, tex_blit, 0);
+
+ GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);
+ if (status != GL_FRAMEBUFFER_COMPLETE) {
goto finally;
}
/* perform the copy */
- glBlitFramebufferEXT(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
+ glBlitFramebuffer(0, 0, w, h, 0, 0, w, h, GL_COLOR_BUFFER_BIT, GL_NEAREST);
/* read the results */
- glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, fbo_blit);
+ glBindFramebuffer(GL_READ_FRAMEBUFFER, fbo_blit);
glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
-#ifdef USE_FBO_CTX_SWITCH
/* restore the original frame-bufer */
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, ofs->color->fb->object);
-#undef USE_FBO_CTX_SWITCH
-#endif
-
+ glBindFramebuffer(GL_FRAMEBUFFER, ofs->fb->object);
finally:
/* cleanup */
- if (tex_blit) {
- glDeleteTextures(1, &tex_blit);
- }
- if (fbo_blit) {
- glDeleteFramebuffersEXT(1, &fbo_blit);
- }
-
- GPU_ASSERT_NO_GL_ERRORS("Read Multi-Sample Pixels");
+ glDeleteTextures(1, &tex_blit);
+ glDeleteFramebuffers(1, &fbo_blit);
}
else {
glReadPixels(0, 0, w, h, GL_RGBA, type, pixels);
@@ -630,8 +798,17 @@ int GPU_offscreen_height(const GPUOffScreen *ofs)
return GPU_texture_height(ofs->color);
}
-int GPU_offscreen_color_texture(const GPUOffScreen *ofs)
+GPUTexture *GPU_offscreen_color_texture(const GPUOffScreen *ofs)
{
- return GPU_texture_opengl_bindcode(ofs->color);
+ return ofs->color;
}
+/* only to be used by viewport code! */
+void GPU_offscreen_viewport_data_get(
+ GPUOffScreen *ofs,
+ GPUFrameBuffer **r_fb, GPUTexture **r_color, GPUTexture **r_depth)
+{
+ *r_fb = ofs->fb;
+ *r_color = ofs->color;
+ *r_depth = ofs->depth;
+}
diff --git a/source/blender/gpu/intern/gpu_immediate.c b/source/blender/gpu/intern/gpu_immediate.c
new file mode 100644
index 00000000000..5f22b7f9279
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_immediate.c
@@ -0,0 +1,88 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+#include "UI_resources.h"
+#include "BLI_utildefines.h"
+
+#include "gpu_shader_private.h"
+
+void immBindBuiltinProgram(GPUBuiltinShader shader_id)
+{
+ GPUShader *shader = GPU_shader_get_builtin_shader(shader_id);
+ immBindProgram(shader->program, shader->interface);
+}
+
+void immUniformThemeColor(int color_id)
+{
+ float color[4];
+ UI_GetThemeColor4fv(color_id, color);
+ immUniformColor4fv(color);
+}
+
+void immUniformThemeColor3(int color_id)
+{
+ float color[3];
+ UI_GetThemeColor3fv(color_id, color);
+ immUniformColor3fv(color);
+}
+
+void immUniformThemeColorShade(int color_id, int offset)
+{
+ float color[4];
+ UI_GetThemeColorShade4fv(color_id, offset, color);
+ immUniformColor4fv(color);
+}
+
+void immUniformThemeColorShadeAlpha(int color_id, int color_offset, int alpha_offset)
+{
+ float color[4];
+ UI_GetThemeColorShadeAlpha4fv(color_id, color_offset, alpha_offset, color);
+ immUniformColor4fv(color);
+}
+
+void immUniformThemeColorBlendShade(int color_id1, int color_id2, float fac, int offset)
+{
+ float color[4];
+ UI_GetThemeColorBlendShade4fv(color_id1, color_id2, fac, offset, color);
+ immUniformColor4fv(color);
+}
+
+void immUniformThemeColorBlend(int color_id1, int color_id2, float fac)
+{
+ uint8_t color[3];
+ UI_GetThemeColorBlend3ubv(color_id1, color_id2, fac, color);
+ immUniformColor3ubv(color);
+}
+
+void immThemeColorShadeAlpha(int colorid, int coloffset, int alphaoffset)
+{
+ unsigned char col[4];
+ UI_GetThemeColorShadeAlpha4ubv(colorid, coloffset, alphaoffset, col);
+ immUniformColor4ub(col[0], col[1], col[2], col[3]);
+}
diff --git a/source/blender/gpu/intern/gpu_immediate_util.c b/source/blender/gpu/intern/gpu_immediate_util.c
new file mode 100644
index 00000000000..bad878ef4bf
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_immediate_util.c
@@ -0,0 +1,424 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file source/blender/gpu/intern/gpu_immediate_util.c
+ * \ingroup gpu
+ */
+
+#include <stdio.h>
+#include <string.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_math.h"
+
+#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+
+static const float cube_coords[8][3] = {
+ {-1, -1, -1},
+ {-1, -1, +1},
+ {-1, +1, -1},
+ {-1, +1, +1},
+ {+1, -1, -1},
+ {+1, -1, +1},
+ {+1, +1, -1},
+ {+1, +1, +1},
+};
+static const int cube_quad_index[6][4] = {
+ {0, 1, 3, 2},
+ {0, 2, 6, 4},
+ {0, 4, 5, 1},
+ {1, 5, 7, 3},
+ {2, 3, 7, 6},
+ {4, 6, 7, 5},
+};
+static const int cube_line_index[12][2] = {
+ {0, 1},
+ {0, 2},
+ {0, 4},
+ {1, 3},
+ {1, 5},
+ {2, 3},
+ {2, 6},
+ {3, 7},
+ {4, 5},
+ {4, 6},
+ {5, 7},
+ {6, 7},
+};
+
+/**
+ * Pack color into 3 bytes
+ *
+ * This define converts a numerical value to the equivalent 24-bit
+ * color, while not being endian-sensitive. On little-endians, this
+ * is the same as doing a 'naive' indexing, on big-endian, it is not!
+ *
+ * \note BGR format (i.e. 0xBBGGRR)...
+ *
+ * \param x color.
+ */
+void imm_cpack(unsigned int x)
+{
+ immUniformColor3ub(((x) & 0xFF),
+ (((x) >> 8) & 0xFF),
+ (((x) >> 16) & 0xFF));
+}
+
+static void imm_draw_circle(
+ Gwn_PrimType prim_type, const uint shdr_pos, float x, float y, float rad_x, float rad_y, int nsegments)
+{
+ immBegin(prim_type, nsegments);
+ for (int i = 0; i < nsegments; ++i) {
+ const float angle = (float)(2 * M_PI) * ((float)i / (float)nsegments);
+ immVertex2f(shdr_pos, x + (rad_x * cosf(angle)), y + (rad_y * sinf(angle)));
+ }
+ immEnd();
+}
+
+/**
+ * Draw a circle outline with the given \a radius.
+ * The circle is centered at \a x, \a y and drawn in the XY plane.
+ *
+ * \param shdr_pos The vertex attribute number for position.
+ * \param x Horizontal center.
+ * \param y Vertical center.
+ * \param radius The circle's radius.
+ * \param nsegments The number of segments to use in drawing (more = smoother).
+ */
+void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float rad, int nsegments)
+{
+ imm_draw_circle(GWN_PRIM_LINE_LOOP, shdr_pos, x, y, rad, rad, nsegments);
+}
+
+/**
+ * Draw a filled circle with the given \a radius.
+ * The circle is centered at \a x, \a y and drawn in the XY plane.
+ *
+ * \param shdr_pos The vertex attribute number for position.
+ * \param x Horizontal center.
+ * \param y Vertical center.
+ * \param radius The circle's radius.
+ * \param nsegments The number of segments to use in drawing (more = smoother).
+ */
+void imm_draw_circle_fill_2d(uint shdr_pos, float x, float y, float rad, int nsegments)
+{
+ imm_draw_circle(GWN_PRIM_TRI_FAN, shdr_pos, x, y, rad, rad, nsegments);
+}
+
+void imm_draw_circle_wire_aspect_2d(uint shdr_pos, float x, float y, float rad_x, float rad_y, int nsegments)
+{
+ imm_draw_circle(GWN_PRIM_LINE_LOOP, shdr_pos, x, y, rad_x, rad_y, nsegments);
+}
+void imm_draw_circle_fill_aspect_2d(uint shdr_pos, float x, float y, float rad_x, float rad_y, int nsegments)
+{
+ imm_draw_circle(GWN_PRIM_TRI_FAN, shdr_pos, x, y, rad_x, rad_y, nsegments);
+}
+
+/**
+ * \note We could have `imm_draw_lined_disk_partial` but currently there is no need.
+ */
+static void imm_draw_disk_partial(
+ Gwn_PrimType prim_type, unsigned pos, float x, float y,
+ float rad_inner, float rad_outer, int nsegments, float start, float sweep)
+{
+ /* shift & reverse angle, increase 'nsegments' to match gluPartialDisk */
+ const float angle_start = -(DEG2RADF(start)) + (float)(M_PI / 2);
+ const float angle_end = -(DEG2RADF(sweep) - angle_start);
+ nsegments += 1;
+ immBegin(prim_type, nsegments * 2);
+ for (int i = 0; i < nsegments; ++i) {
+ const float angle = interpf(angle_start, angle_end, ((float)i / (float)(nsegments - 1)));
+ const float angle_sin = sinf(angle);
+ const float angle_cos = cosf(angle);
+ immVertex2f(pos, x + rad_inner * angle_cos, y + rad_inner * angle_sin);
+ immVertex2f(pos, x + rad_outer * angle_cos, y + rad_outer * angle_sin);
+ }
+ immEnd();
+}
+
+/**
+ * Draw a filled arc with the given inner and outer radius.
+ * The circle is centered at \a x, \a y and drawn in the XY plane.
+ *
+ * \note Arguments are `gluPartialDisk` compatible.
+ *
+ * \param pos: The vertex attribute number for position.
+ * \param x: Horizontal center.
+ * \param y: Vertical center.
+ * \param radius_inner: The inner circle's radius.
+ * \param radius_outer: The outer circle's radius (can be zero).
+ * \param nsegments: The number of segments to use in drawing (more = smoother).
+ * \param start: Specifies the starting angle, in degrees, of the disk portion.
+ * \param sweep: Specifies the sweep angle, in degrees, of the disk portion.
+ */
+void imm_draw_disk_partial_fill_2d(
+ unsigned pos, float x, float y,
+ float rad_inner, float rad_outer, int nsegments, float start, float sweep)
+{
+ imm_draw_disk_partial(GWN_PRIM_TRI_STRIP, pos, x, y, rad_inner, rad_outer, nsegments, start, sweep);
+}
+
+static void imm_draw_circle_3D(
+ Gwn_PrimType prim_type, unsigned pos, float x, float y,
+ float rad, int nsegments)
+{
+ immBegin(prim_type, nsegments);
+ for (int i = 0; i < nsegments; ++i) {
+ float angle = (float)(2 * M_PI) * ((float)i / (float)nsegments);
+ immVertex3f(pos, x + rad * cosf(angle), y + rad * sinf(angle), 0.0f);
+ }
+ immEnd();
+}
+
+void imm_draw_circle_wire_3d(unsigned pos, float x, float y, float rad, int nsegments)
+{
+ imm_draw_circle_3D(GWN_PRIM_LINE_LOOP, pos, x, y, rad, nsegments);
+}
+
+void imm_draw_circle_fill_3d(unsigned pos, float x, float y, float rad, int nsegments)
+{
+ imm_draw_circle_3D(GWN_PRIM_TRI_FAN, pos, x, y, rad, nsegments);
+}
+
+/**
+* Draw a lined box.
+*
+* \param pos The vertex attribute number for position.
+* \param x1 left.
+* \param y1 bottom.
+* \param x2 right.
+* \param y2 top.
+*/
+void imm_draw_box_wire_2d(unsigned pos, float x1, float y1, float x2, float y2)
+{
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex2f(pos, x1, y1);
+ immVertex2f(pos, x1, y2);
+ immVertex2f(pos, x2, y2);
+ immVertex2f(pos, x2, y1);
+ immEnd();
+}
+
+void imm_draw_box_wire_3d(unsigned pos, float x1, float y1, float x2, float y2)
+{
+ /* use this version when Gwn_VertFormat has a vec3 position */
+ immBegin(GWN_PRIM_LINE_LOOP, 4);
+ immVertex3f(pos, x1, y1, 0.0f);
+ immVertex3f(pos, x1, y2, 0.0f);
+ immVertex3f(pos, x2, y2, 0.0f);
+ immVertex3f(pos, x2, y1, 0.0f);
+ immEnd();
+}
+
+/**
+ * Draw a standard checkerboard to indicate transparent backgrounds.
+ */
+void imm_draw_box_checker_2d(float x1, float y1, float x2, float y2)
+{
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ immBindBuiltinProgram(GPU_SHADER_2D_CHECKER);
+
+ immUniform4f("color1", 0.15f, 0.15f, 0.15f, 1.0f);
+ immUniform4f("color2", 0.2f, 0.2f, 0.2f, 1.0f);
+ immUniform1i("size", 8);
+
+ immRectf(pos, x1, y1, x2, y2);
+
+ immUnbindProgram();
+}
+
+void imm_draw_cube_fill_3d(uint pos, const float co[3], const float aspect[3])
+{
+ float coords[ARRAY_SIZE(cube_coords)][3];
+
+ for (int i = 0; i < ARRAY_SIZE(cube_coords); i++) {
+ madd_v3_v3v3v3(coords[i], co, cube_coords[i], aspect);
+ }
+
+ immBegin(GWN_PRIM_TRIS, ARRAY_SIZE(cube_quad_index) * 3 * 2);
+ for (int i = 0; i < ARRAY_SIZE(cube_quad_index); i++) {
+ immVertex3fv(pos, coords[cube_quad_index[i][0]]);
+ immVertex3fv(pos, coords[cube_quad_index[i][1]]);
+ immVertex3fv(pos, coords[cube_quad_index[i][2]]);
+
+ immVertex3fv(pos, coords[cube_quad_index[i][0]]);
+ immVertex3fv(pos, coords[cube_quad_index[i][2]]);
+ immVertex3fv(pos, coords[cube_quad_index[i][3]]);
+ }
+ immEnd();
+}
+
+void imm_draw_cube_wire_3d(uint pos, const float co[3], const float aspect[3])
+{
+ float coords[ARRAY_SIZE(cube_coords)][3];
+
+ for (int i = 0; i < ARRAY_SIZE(cube_coords); i++) {
+ madd_v3_v3v3v3(coords[i], co, cube_coords[i], aspect);
+ }
+
+ immBegin(GWN_PRIM_LINES, ARRAY_SIZE(cube_line_index) * 2);
+ for (int i = 0; i < ARRAY_SIZE(cube_line_index); i++) {
+ immVertex3fv(pos, coords[cube_line_index[i][0]]);
+ immVertex3fv(pos, coords[cube_line_index[i][1]]);
+ }
+ immEnd();
+}
+
+/**
+* Draw a cylinder. Replacement for gluCylinder.
+* _warning_ : Slow, better use it only if you no other choices.
+*
+* \param pos The vertex attribute number for position.
+* \param nor The vertex attribute number for normal.
+* \param base Specifies the radius of the cylinder at z = 0.
+* \param top Specifies the radius of the cylinder at z = height.
+* \param height Specifies the height of the cylinder.
+* \param slices Specifies the number of subdivisions around the z axis.
+* \param stacks Specifies the number of subdivisions along the z axis.
+*/
+void imm_draw_cylinder_fill_normal_3d(
+ unsigned int pos, unsigned int nor, float base, float top, float height, int slices, int stacks)
+{
+ immBegin(GWN_PRIM_TRIS, 6 * slices * stacks);
+ for (int i = 0; i < slices; ++i) {
+ const float angle1 = (float)(2 * M_PI) * ((float)i / (float)slices);
+ const float angle2 = (float)(2 * M_PI) * ((float)(i + 1) / (float)slices);
+ const float cos1 = cosf(angle1);
+ const float sin1 = sinf(angle1);
+ const float cos2 = cosf(angle2);
+ const float sin2 = sinf(angle2);
+
+ for (int j = 0; j < stacks; ++j) {
+ float fac1 = (float)j / (float)stacks;
+ float fac2 = (float)(j + 1) / (float)stacks;
+ float r1 = base * (1.f - fac1) + top * fac1;
+ float r2 = base * (1.f - fac2) + top * fac2;
+ float h1 = height * ((float)j / (float)stacks);
+ float h2 = height * ((float)(j + 1) / (float)stacks);
+
+ float v1[3] = {r1 *cos2, r1 * sin2, h1};
+ float v2[3] = {r2 *cos2, r2 * sin2, h2};
+ float v3[3] = {r2 *cos1, r2 * sin1, h2};
+ float v4[3] = {r1 *cos1, r1 * sin1, h1};
+ float n1[3], n2[3];
+
+ /* calc normals */
+ sub_v3_v3v3(n1, v2, v1);
+ normalize_v3(n1);
+ n1[0] = cos1; n1[1] = sin1; n1[2] = 1 - n1[2];
+
+ sub_v3_v3v3(n2, v3, v4);
+ normalize_v3(n2);
+ n2[0] = cos2; n2[1] = sin2; n2[2] = 1 - n2[2];
+
+ /* first tri */
+ immAttrib3fv(nor, n2);
+ immVertex3fv(pos, v1);
+ immVertex3fv(pos, v2);
+ immAttrib3fv(nor, n1);
+ immVertex3fv(pos, v3);
+
+ /* second tri */
+ immVertex3fv(pos, v3);
+ immVertex3fv(pos, v4);
+ immAttrib3fv(nor, n2);
+ immVertex3fv(pos, v1);
+ }
+ }
+ immEnd();
+}
+
+void imm_draw_cylinder_wire_3d(unsigned int pos, float base, float top, float height, int slices, int stacks)
+{
+ immBegin(GWN_PRIM_LINES, 6 * slices * stacks);
+ for (int i = 0; i < slices; ++i) {
+ const float angle1 = (float)(2 * M_PI) * ((float)i / (float)slices);
+ const float angle2 = (float)(2 * M_PI) * ((float)(i + 1) / (float)slices);
+ const float cos1 = cosf(angle1);
+ const float sin1 = sinf(angle1);
+ const float cos2 = cosf(angle2);
+ const float sin2 = sinf(angle2);
+
+ for (int j = 0; j < stacks; ++j) {
+ float fac1 = (float)j / (float)stacks;
+ float fac2 = (float)(j + 1) / (float)stacks;
+ float r1 = base * (1.f - fac1) + top * fac1;
+ float r2 = base * (1.f - fac2) + top * fac2;
+ float h1 = height * ((float)j / (float)stacks);
+ float h2 = height * ((float)(j + 1) / (float)stacks);
+
+ float v1[3] = {r1 * cos2, r1 * sin2, h1};
+ float v2[3] = {r2 * cos2, r2 * sin2, h2};
+ float v3[3] = {r2 * cos1, r2 * sin1, h2};
+ float v4[3] = {r1 * cos1, r1 * sin1, h1};
+
+ immVertex3fv(pos, v1);
+ immVertex3fv(pos, v2);
+
+ immVertex3fv(pos, v2);
+ immVertex3fv(pos, v3);
+
+ immVertex3fv(pos, v1);
+ immVertex3fv(pos, v4);
+ }
+ }
+ immEnd();
+}
+
+void imm_draw_cylinder_fill_3d(unsigned int pos, float base, float top, float height, int slices, int stacks)
+{
+ immBegin(GWN_PRIM_TRIS, 6 * slices * stacks);
+ for (int i = 0; i < slices; ++i) {
+ const float angle1 = (float)(2 * M_PI) * ((float)i / (float)slices);
+ const float angle2 = (float)(2 * M_PI) * ((float)(i + 1) / (float)slices);
+ const float cos1 = cosf(angle1);
+ const float sin1 = sinf(angle1);
+ const float cos2 = cosf(angle2);
+ const float sin2 = sinf(angle2);
+
+ for (int j = 0; j < stacks; ++j) {
+ float fac1 = (float)j / (float)stacks;
+ float fac2 = (float)(j + 1) / (float)stacks;
+ float r1 = base * (1.f - fac1) + top * fac1;
+ float r2 = base * (1.f - fac2) + top * fac2;
+ float h1 = height * ((float)j / (float)stacks);
+ float h2 = height * ((float)(j + 1) / (float)stacks);
+
+ float v1[3] = {r1 * cos2, r1 * sin2, h1};
+ float v2[3] = {r2 * cos2, r2 * sin2, h2};
+ float v3[3] = {r2 * cos1, r2 * sin1, h2};
+ float v4[3] = {r1 * cos1, r1 * sin1, h1};
+
+ /* first tri */
+ immVertex3fv(pos, v1);
+ immVertex3fv(pos, v2);
+ immVertex3fv(pos, v3);
+
+ /* second tri */
+ immVertex3fv(pos, v3);
+ immVertex3fv(pos, v4);
+ immVertex3fv(pos, v1);
+ }
+ }
+ immEnd();
+}
diff --git a/source/blender/gpu/intern/gpu_init_exit.c b/source/blender/gpu/intern/gpu_init_exit.c
index c72c83b6b07..c2f14687ff5 100644
--- a/source/blender/gpu/intern/gpu_init_exit.c
+++ b/source/blender/gpu/intern/gpu_init_exit.c
@@ -30,8 +30,10 @@
*/
#include "BLI_sys_types.h"
+#include "GPU_buffers.h"
#include "GPU_init_exit.h" /* interface */
-
+#include "GPU_immediate.h"
+#include "GPU_batch.h"
#include "BKE_global.h"
#include "intern/gpu_codegen.h"
@@ -59,14 +61,28 @@ void GPU_init(void)
if (G.debug & G_DEBUG_GPU)
gpu_debug_init();
+ gpu_batch_init();
+
+ if (!G.background) {
+ immInit();
+ }
+
+ GPU_pbvh_fix_linking();
}
void GPU_exit(void)
{
+ if (!G.background) {
+ immDestroy();
+ }
+
+ gpu_batch_exit();
+
if (G.debug & G_DEBUG_GPU)
gpu_debug_exit();
+
gpu_codegen_exit();
gpu_extensions_exit(); /* must come last */
diff --git a/source/blender/gpu/intern/gpu_material.c b/source/blender/gpu/intern/gpu_material.c
index edb6c9a29f9..c346d20632b 100644
--- a/source/blender/gpu/intern/gpu_material.c
+++ b/source/blender/gpu/intern/gpu_material.c
@@ -45,12 +45,14 @@
#include "BLI_math.h"
#include "BLI_blenlib.h"
#include "BLI_utildefines.h"
+#include "BLI_rand.h"
#include "BKE_anim.h"
#include "BKE_colorband.h"
#include "BKE_colortools.h"
#include "BKE_global.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_scene.h"
@@ -63,6 +65,9 @@
#include "GPU_material.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
+#include "GPU_uniformbuffer.h"
+
+#include "DRW_engine.h"
#include "gpu_codegen.h"
@@ -72,32 +77,17 @@
/* Structs */
-typedef enum DynMatProperty {
- DYN_LAMP_CO = 1,
- DYN_LAMP_VEC = 2,
- DYN_LAMP_IMAT = 4,
- DYN_LAMP_PERSMAT = 8,
-} DynMatProperty;
-
-static struct GPUWorld {
- float mistenabled;
- float mistype;
- float miststart;
- float mistdistance;
- float mistintensity;
- float mistcol[4];
- float horicol[3];
- float ambcol[4];
- float zencol[3];
-} GPUWorld;
-
struct GPUMaterial {
- Scene *scene;
+ Scene *scene; /* DEPRECATED was only usefull for lamps */
Material *ma;
/* material for mesh surface, worlds or something else.
* some code generation is done differently depending on the use case */
- int type;
+ int type; /* DEPRECATED */
+ GPUMaterialStatus status;
+
+ const void *engine_type; /* attached engine type */
+ int options; /* to identify shader variations (shadow, probe, world background...) */
/* for creating the material */
ListBase nodes;
@@ -105,6 +95,7 @@ struct GPUMaterial {
/* for binding the material */
GPUPass *pass;
+ ListBase inputs; /* GPUInput */
GPUVertexAttribs attribs;
int builtins;
int alpha, obcolalpha;
@@ -124,360 +115,69 @@ struct GPUMaterial {
int objectinfoloc;
- ListBase lamps;
- bool bound;
-
bool is_opensubdiv;
-};
-
-struct GPULamp {
- Scene *scene;
- Object *ob;
- Object *par;
- Lamp *la;
-
- int type, mode, lay, hide;
-
- float dynenergy, dyncol[3];
- float energy, col[3];
-
- float co[3], vec[3];
- float dynco[3], dynvec[3];
- float obmat[4][4];
- float imat[4][4];
- float dynimat[4][4];
- float spotsi, spotbl, k;
- float spotvec[2];
- float dyndist, dynatt1, dynatt2;
- float dist, att1, att2;
- float coeff_const, coeff_lin, coeff_quad;
- float shadow_color[3];
-
- float bias, d, clipend;
- int size;
-
- int falloff_type;
- struct CurveMapping *curfalloff;
-
- float winmat[4][4];
- float viewmat[4][4];
- float persmat[4][4];
- float dynpersmat[4][4];
-
- GPUFrameBuffer *fb;
- GPUFrameBuffer *blurfb;
- GPUTexture *tex;
- GPUTexture *depthtex;
- GPUTexture *blurtex;
-
- ListBase materials;
+ /* XXX: Should be in Material. But it depends on the output node
+ * used and since the output selection is difference for GPUMaterial...
+ */
+ int domain;
+
+ /* Used by 2.8 pipeline */
+ GPUUniformBuffer *ubo; /* UBOs for shader uniforms. */
+
+ /* Eevee SSS */
+ GPUUniformBuffer *sss_profile; /* UBO containing SSS profile. */
+ GPUTexture *sss_tex_profile; /* Texture containing SSS profile. */
+ float *sss_radii; /* UBO containing SSS profile. */
+ int sss_samples;
+ short int *sss_falloff;
+ float *sss_sharpness;
+ bool sss_dirty;
};
-/* Forward declaration so shade_light_textures() can use this, while still keeping the code somewhat organized */
-static void texture_rgb_blend(
- GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg,
- int blendtype, GPUNodeLink **in);
+enum {
+ GPU_DOMAIN_SURFACE = (1 << 0),
+ GPU_DOMAIN_VOLUME = (1 << 1),
+ GPU_DOMAIN_SSS = (1 << 2)
+};
/* Functions */
-static GPUMaterial *GPU_material_construct_begin(Material *ma)
-{
- GPUMaterial *material = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial");
-
- material->ma = ma;
-
- return material;
-}
-
-static void gpu_material_set_attrib_id(GPUMaterial *material)
-{
- GPUVertexAttribs *attribs = &material->attribs;
- GPUPass *pass = material->pass;
- if (!pass) {
- attribs->totlayer = 0;
- return;
- }
-
- GPUShader *shader = GPU_pass_shader(pass);
- if (!shader) {
- attribs->totlayer = 0;
- return;
- }
-
- /* convert from attribute number to the actual id assigned by opengl,
- * in case the attrib does not get a valid index back, it was probably
- * removed by the glsl compiler by dead code elimination */
-
- int b = 0;
- for (int a = 0; a < attribs->totlayer; a++) {
- char name[32];
- BLI_snprintf(name, sizeof(name), "att%d", attribs->layer[a].attribid);
- attribs->layer[a].glindex = GPU_shader_get_attribute(shader, name);
-
- BLI_snprintf(name, sizeof(name), "att%d_info", attribs->layer[a].attribid);
- attribs->layer[a].glinfoindoex = GPU_shader_get_uniform(shader, name);
-
- if (attribs->layer[a].glindex >= 0) {
- attribs->layer[b] = attribs->layer[a];
- b++;
- }
- }
-
- attribs->totlayer = b;
-}
-
-static int gpu_material_construct_end(GPUMaterial *material, const char *passname)
-{
- if (material->outlink) {
- GPUNodeLink *outlink = material->outlink;
- material->pass = GPU_generate_pass(&material->nodes, outlink,
- &material->attribs, &material->builtins, material->type,
- passname,
- material->is_opensubdiv,
- GPU_material_use_new_shading_nodes(material));
-
- if (!material->pass)
- return 0;
-
- gpu_material_set_attrib_id(material);
-
- GPUShader *shader = GPU_pass_shader(material->pass);
-
- if (material->builtins & GPU_VIEW_MATRIX)
- material->viewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_VIEW_MATRIX));
- if (material->builtins & GPU_INVERSE_VIEW_MATRIX)
- material->invviewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_INVERSE_VIEW_MATRIX));
- if (material->builtins & GPU_OBJECT_MATRIX)
- material->obmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBJECT_MATRIX));
- if (material->builtins & GPU_INVERSE_OBJECT_MATRIX)
- material->invobmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_INVERSE_OBJECT_MATRIX));
- if (material->builtins & GPU_LOC_TO_VIEW_MATRIX)
- material->localtoviewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_LOC_TO_VIEW_MATRIX));
- if (material->builtins & GPU_INVERSE_LOC_TO_VIEW_MATRIX)
- material->invlocaltoviewmatloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_INVERSE_LOC_TO_VIEW_MATRIX));
- if (material->builtins & GPU_OBCOLOR)
- material->obcolloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBCOLOR));
- if (material->builtins & GPU_AUTO_BUMPSCALE)
- material->obautobumpscaleloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_AUTO_BUMPSCALE));
- if (material->builtins & GPU_CAMERA_TEXCO_FACTORS)
- material->cameratexcofacloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_CAMERA_TEXCO_FACTORS));
- if (material->builtins & GPU_PARTICLE_SCALAR_PROPS)
- material->partscalarpropsloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_SCALAR_PROPS));
- if (material->builtins & GPU_PARTICLE_LOCATION)
- material->partcoloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_LOCATION));
- if (material->builtins & GPU_PARTICLE_VELOCITY)
- material->partvel = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_VELOCITY));
- if (material->builtins & GPU_PARTICLE_ANG_VELOCITY)
- material->partangvel = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_PARTICLE_ANG_VELOCITY));
- if (material->builtins & GPU_OBJECT_INFO)
- material->objectinfoloc = GPU_shader_get_uniform(shader, GPU_builtin_name(GPU_OBJECT_INFO));
- return 1;
- }
- else {
- GPU_pass_free_nodes(&material->nodes);
- }
-
- return 0;
-}
-
void GPU_material_free(ListBase *gpumaterial)
{
for (LinkData *link = gpumaterial->first; link; link = link->next) {
GPUMaterial *material = link->data;
- if (material->pass)
- GPU_pass_free(material->pass);
-
- for (LinkData *nlink = material->lamps.first; nlink; nlink = nlink->next) {
- GPULamp *lamp = nlink->data;
-
- if (material->ma) {
- Material *ma = material->ma;
-
- LinkData *next = NULL;
- for (LinkData *mlink = lamp->materials.first; mlink; mlink = next) {
- next = mlink->next;
- if (mlink->data == ma)
- BLI_freelinkN(&lamp->materials, mlink);
- }
- }
- }
-
- BLI_freelistN(&material->lamps);
-
- MEM_freeN(material);
- }
+ /* Cancel / wait any pending lazy compilation. */
+ DRW_deferred_shader_remove(material);
- BLI_freelistN(gpumaterial);
-}
+ GPU_pass_free_nodes(&material->nodes);
+ GPU_inputs_free(&material->inputs);
-bool GPU_lamp_visible(GPULamp *lamp, SceneRenderLayer *srl, Material *ma)
-{
- if (lamp->hide)
- return false;
- else if (srl && srl->light_override)
- return BKE_group_object_exists(srl->light_override, lamp->ob);
- else if (ma && ma->group)
- return BKE_group_object_exists(ma->group, lamp->ob);
- else
- return true;
-}
+ if (material->pass)
+ GPU_pass_release(material->pass);
-void GPU_material_bind(
- GPUMaterial *material, int oblay, int viewlay, double time, int mipmap,
- float viewmat[4][4], float viewinv[4][4], float camerafactors[4], bool scenelock)
-{
- if (material->pass) {
- GPUShader *shader = GPU_pass_shader(material->pass);
- SceneRenderLayer *srl = scenelock ? BLI_findlink(&material->scene->r.layers, material->scene->r.actlay) : NULL;
-
- if (srl)
- viewlay &= srl->lay;
-
- /* handle layer lamps */
- if (material->type == GPU_MATERIAL_TYPE_MESH) {
- for (LinkData *nlink = material->lamps.first; nlink; nlink = nlink->next) {
- GPULamp *lamp = nlink->data;
-
- if ((lamp->lay & viewlay) && (!(lamp->mode & LA_LAYER) || (lamp->lay & oblay)) &&
- GPU_lamp_visible(lamp, srl, material->ma))
- {
- lamp->dynenergy = lamp->energy;
- copy_v3_v3(lamp->dyncol, lamp->col);
- }
- else {
- lamp->dynenergy = 0.0f;
- lamp->dyncol[0] = lamp->dyncol[1] = lamp->dyncol[2] = 0.0f;
- }
-
- if (material->dynproperty & DYN_LAMP_VEC) {
- copy_v3_v3(lamp->dynvec, lamp->vec);
- normalize_v3(lamp->dynvec);
- negate_v3(lamp->dynvec);
- mul_mat3_m4_v3(viewmat, lamp->dynvec);
- }
-
- if (material->dynproperty & DYN_LAMP_CO) {
- copy_v3_v3(lamp->dynco, lamp->co);
- mul_m4_v3(viewmat, lamp->dynco);
- }
-
- if (material->dynproperty & DYN_LAMP_IMAT) {
- mul_m4_m4m4(lamp->dynimat, lamp->imat, viewinv);
- }
-
- if (material->dynproperty & DYN_LAMP_PERSMAT) {
- /* The lamp matrices are already updated if we're using shadow buffers */
- if (!GPU_lamp_has_shadow_buffer(lamp)) {
- GPU_lamp_update_buffer_mats(lamp);
- }
- mul_m4_m4m4(lamp->dynpersmat, lamp->persmat, viewinv);
- }
- }
+ if (material->ubo != NULL) {
+ GPU_uniformbuffer_free(material->ubo);
}
-
- /* note material must be bound before setting uniforms */
- GPU_pass_bind(material->pass, time, mipmap);
- /* handle per material built-ins */
- if (material->builtins & GPU_VIEW_MATRIX) {
- GPU_shader_uniform_vector(shader, material->viewmatloc, 16, 1, (float *)viewmat);
- }
- if (material->builtins & GPU_INVERSE_VIEW_MATRIX) {
- GPU_shader_uniform_vector(shader, material->invviewmatloc, 16, 1, (float *)viewinv);
- }
- if (material->builtins & GPU_CAMERA_TEXCO_FACTORS) {
- if (camerafactors) {
- GPU_shader_uniform_vector(shader, material->cameratexcofacloc, 4, 1, (float *)camerafactors);
- }
- else {
- /* use default, no scaling no offset */
- float borders[4] = {1.0f, 1.0f, 0.0f, 0.0f};
- GPU_shader_uniform_vector(shader, material->cameratexcofacloc, 4, 1, (float *)borders);
- }
+ if (material->sss_tex_profile != NULL) {
+ GPU_texture_free(material->sss_tex_profile);
}
- GPU_pass_update_uniforms(material->pass);
-
- material->bound = 1;
- }
-}
-
-GPUBuiltin GPU_get_material_builtins(GPUMaterial *material)
-{
- return material->builtins;
-}
-
-void GPU_material_bind_uniforms(
- GPUMaterial *material, float obmat[4][4], float viewmat[4][4], float obcol[4],
- float autobumpscale, GPUParticleInfo *pi, float object_info[3])
-{
- if (material->pass) {
- GPUShader *shader = GPU_pass_shader(material->pass);
- float invmat[4][4], col[4];
- float localtoviewmat[4][4];
- float invlocaltoviewmat[4][4];
-
- /* handle per object builtins */
- if (material->builtins & GPU_OBJECT_MATRIX) {
- GPU_shader_uniform_vector(shader, material->obmatloc, 16, 1, (float *)obmat);
- }
- if (material->builtins & GPU_INVERSE_OBJECT_MATRIX) {
- invert_m4_m4(invmat, obmat);
- GPU_shader_uniform_vector(shader, material->invobmatloc, 16, 1, (float *)invmat);
- }
- if (material->builtins & GPU_LOC_TO_VIEW_MATRIX) {
- if (viewmat) {
- mul_m4_m4m4(localtoviewmat, viewmat, obmat);
- GPU_shader_uniform_vector(shader, material->localtoviewmatloc, 16, 1, (float *)localtoviewmat);
- }
- }
- if (material->builtins & GPU_INVERSE_LOC_TO_VIEW_MATRIX) {
- if (viewmat) {
- mul_m4_m4m4(localtoviewmat, viewmat, obmat);
- invert_m4_m4(invlocaltoviewmat, localtoviewmat);
- GPU_shader_uniform_vector(shader, material->invlocaltoviewmatloc, 16, 1, (float *)invlocaltoviewmat);
- }
- }
- if (material->builtins & GPU_OBCOLOR) {
- copy_v4_v4(col, obcol);
- CLAMP(col[3], 0.0f, 1.0f);
- GPU_shader_uniform_vector(shader, material->obcolloc, 4, 1, col);
- }
- if (material->builtins & GPU_AUTO_BUMPSCALE) {
- GPU_shader_uniform_vector(shader, material->obautobumpscaleloc, 1, 1, &autobumpscale);
- }
- if (material->builtins & GPU_PARTICLE_SCALAR_PROPS) {
- GPU_shader_uniform_vector(shader, material->partscalarpropsloc, 4, 1, pi->scalprops);
- }
- if (material->builtins & GPU_PARTICLE_LOCATION) {
- GPU_shader_uniform_vector(shader, material->partcoloc, 4, 1, pi->location);
- }
- if (material->builtins & GPU_PARTICLE_VELOCITY) {
- GPU_shader_uniform_vector(shader, material->partvel, 3, 1, pi->velocity);
- }
- if (material->builtins & GPU_PARTICLE_ANG_VELOCITY) {
- GPU_shader_uniform_vector(shader, material->partangvel, 3, 1, pi->angular_velocity);
- }
- if (material->builtins & GPU_OBJECT_INFO) {
- GPU_shader_uniform_vector(shader, material->objectinfoloc, 3, 1, object_info);
+ if (material->sss_profile != NULL) {
+ GPU_uniformbuffer_free(material->sss_profile);
}
+ MEM_freeN(material);
}
-}
-void GPU_material_unbind(GPUMaterial *material)
-{
- if (material->pass) {
- material->bound = 0;
- GPU_pass_unbind(material->pass);
- }
+ BLI_freelistN(gpumaterial);
}
-bool GPU_material_bound(GPUMaterial *material)
+GPUBuiltin GPU_get_material_builtins(GPUMaterial *material)
{
- return material->bound;
+ return material->builtins;
}
Scene *GPU_material_scene(GPUMaterial *material)
@@ -490,1735 +190,478 @@ GPUMatType GPU_Material_get_type(GPUMaterial *material)
return material->type;
}
-
-void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs)
+GPUPass *GPU_material_get_pass(GPUMaterial *material)
{
- *attribs = material->attribs;
+ return material->pass;
}
-void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
+ListBase *GPU_material_get_inputs(GPUMaterial *material)
{
- if (!material->outlink)
- material->outlink = link;
+ return &material->inputs;
}
-void GPU_material_enable_alpha(GPUMaterial *material)
+GPUUniformBuffer *GPU_material_get_uniform_buffer(GPUMaterial *material)
{
- material->alpha = 1;
+ return material->ubo;
}
-GPUBlendMode GPU_material_alpha_blend(GPUMaterial *material, float obcol[4])
+/**
+ * Create dynamic UBO from parameters
+ * \param ListBase of BLI_genericNodeN(GPUInput)
+ */
+void GPU_material_create_uniform_buffer(GPUMaterial *material, ListBase *inputs)
{
- if (material->alpha || (material->obcolalpha && obcol[3] < 1.0f))
- return GPU_BLEND_ALPHA;
- else
- return GPU_BLEND_SOLID;
+ material->ubo = GPU_uniformbuffer_dynamic_create(inputs, NULL);
}
-void gpu_material_add_node(GPUMaterial *material, GPUNode *node)
+void GPU_material_uniform_buffer_tag_dirty(ListBase *gpumaterials)
{
- BLI_addtail(&material->nodes, node);
+ for (LinkData *link = gpumaterials->first; link; link = link->next) {
+ GPUMaterial *material = link->data;
+ if (material->ubo != NULL) {
+ GPU_uniformbuffer_tag_dirty(material->ubo);
+ }
+ if (material->sss_profile != NULL) {
+ material->sss_dirty = true;
+ }
+ }
}
-/* Code generation */
+/* Eevee Subsurface scattering. */
+/* Based on Separable SSS. by Jorge Jimenez and Diego Gutierrez */
-bool GPU_material_do_color_management(GPUMaterial *mat)
-{
- if (!BKE_scene_check_color_management_enabled(mat->scene))
- return false;
+#define SSS_SAMPLES 65
+#define SSS_EXPONENT 2.0f /* Importance sampling exponent */
- return true;
-}
+typedef struct GPUSssKernelData {
+ float kernel[SSS_SAMPLES][4];
+ float param[3], max_radius;
+ int samples;
+} GPUSssKernelData;
-bool GPU_material_use_new_shading_nodes(GPUMaterial *mat)
+static void sss_calculate_offsets(GPUSssKernelData *kd, int count, float exponent)
{
- return BKE_scene_use_new_shading_nodes(mat->scene);
-}
-
-bool GPU_material_use_world_space_shading(GPUMaterial *mat)
-{
- return BKE_scene_use_world_space_shading(mat->scene);
+ float step = 2.0f / (float)(count - 1);
+ for (int i = 0; i < count; i++) {
+ float o = ((float)i) * step - 1.0f;
+ float sign = (o < 0.0f) ? -1.0f : 1.0f;
+ float ofs = sign * fabsf(powf(o, exponent));
+ kd->kernel[i][3] = ofs;
+ }
}
-static GPUNodeLink *lamp_get_visibility(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **lv, GPUNodeLink **dist)
+#define GAUSS_TRUNCATE 12.46f
+static float gaussian_profile(float r, float radius)
{
- GPUNodeLink *visifac;
-
- /* from get_lamp_visibility */
- if (lamp->type == LA_SUN || lamp->type == LA_HEMI) {
- mat->dynproperty |= DYN_LAMP_VEC;
- GPU_link(mat, "lamp_visibility_sun_hemi",
- GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), lv, dist, &visifac);
- return visifac;
- }
- else {
- mat->dynproperty |= DYN_LAMP_CO;
- GPU_link(mat, "lamp_visibility_other",
- GPU_builtin(GPU_VIEW_POSITION),
- GPU_dynamic_uniform(lamp->dynco, GPU_DYNAMIC_LAMP_DYNCO, lamp->ob), lv, dist, &visifac);
-
- if (lamp->type == LA_AREA)
- return visifac;
-
- switch (lamp->falloff_type) {
- case LA_FALLOFF_CONSTANT:
- break;
- case LA_FALLOFF_INVLINEAR:
- GPU_link(mat, "lamp_falloff_invlinear",
- GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, &visifac);
- break;
- case LA_FALLOFF_INVSQUARE:
- GPU_link(mat, "lamp_falloff_invsquare",
- GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob), *dist, &visifac);
- break;
- case LA_FALLOFF_SLIDERS:
- GPU_link(mat, "lamp_falloff_sliders",
- GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob),
- GPU_dynamic_uniform(&lamp->att1, GPU_DYNAMIC_LAMP_ATT1, lamp->ob),
- GPU_dynamic_uniform(&lamp->att2, GPU_DYNAMIC_LAMP_ATT2, lamp->ob), *dist, &visifac);
- break;
- case LA_FALLOFF_INVCOEFFICIENTS:
- GPU_link(mat, "lamp_falloff_invcoefficients",
- GPU_dynamic_uniform(&lamp->coeff_const, GPU_DYNAMIC_LAMP_COEFFCONST, lamp->ob),
- GPU_dynamic_uniform(&lamp->coeff_lin, GPU_DYNAMIC_LAMP_COEFFLIN, lamp->ob),
- GPU_dynamic_uniform(&lamp->coeff_quad, GPU_DYNAMIC_LAMP_COEFFQUAD, lamp->ob), *dist, &visifac);
- break;
- case LA_FALLOFF_CURVE:
- {
- float *array;
- int size;
-
- curvemapping_initialize(lamp->curfalloff);
- curvemapping_table_RGBA(lamp->curfalloff, &array, &size);
- GPU_link(mat, "lamp_falloff_curve",
- GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob),
- GPU_texture(size, array), *dist, &visifac);
-
- break;
- }
- }
-
- if (lamp->mode & LA_SPHERE)
- GPU_link(mat, "lamp_visibility_sphere",
- GPU_dynamic_uniform(&lamp->dist, GPU_DYNAMIC_LAMP_DISTANCE, lamp->ob),
- *dist, visifac, &visifac);
-
- if (lamp->type == LA_SPOT) {
- GPUNodeLink *inpr;
+ const float v = radius * radius * (0.25f * 0.25f);
+ const float Rm = sqrtf(v * GAUSS_TRUNCATE);
- if (lamp->mode & LA_SQUARE) {
- mat->dynproperty |= DYN_LAMP_VEC | DYN_LAMP_IMAT;
- GPU_link(mat, "lamp_visibility_spot_square",
- GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->dynimat, GPU_DYNAMIC_LAMP_DYNIMAT, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->spotvec, GPU_DYNAMIC_LAMP_SPOTSCALE, lamp->ob), *lv, &inpr);
- }
- else {
- mat->dynproperty |= DYN_LAMP_VEC | DYN_LAMP_IMAT;
- GPU_link(mat, "lamp_visibility_spot_circle",
- GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->dynimat, GPU_DYNAMIC_LAMP_DYNIMAT, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->spotvec, GPU_DYNAMIC_LAMP_SPOTSCALE, lamp->ob), *lv, &inpr);
- }
-
- GPU_link(mat, "lamp_visibility_spot",
- GPU_dynamic_uniform(&lamp->spotsi, GPU_DYNAMIC_LAMP_SPOTSIZE, lamp->ob),
- GPU_dynamic_uniform(&lamp->spotbl, GPU_DYNAMIC_LAMP_SPOTBLEND, lamp->ob),
- inpr, visifac, &visifac);
- }
-
- GPU_link(mat, "lamp_visibility_clamp", visifac, &visifac);
-
- return visifac;
+ if (r >= Rm) {
+ return 0.0f;
}
+ return expf(-r * r / (2.0f * v)) / (2.0f * M_PI * v);
}
-#if 0
-static void area_lamp_vectors(LampRen *lar)
+#define BURLEY_TRUNCATE 16.0f
+#define BURLEY_TRUNCATE_CDF 0.9963790093708328f // cdf(BURLEY_TRUNCATE)
+static float burley_profile(float r, float d)
{
- float xsize = 0.5f * lar->area_size, ysize = 0.5f * lar->area_sizey;
-
- /* make it smaller, so area light can be multisampled */
- float multifac = 1.0f / sqrtf((float)lar->ray_totsamp);
- xsize *= multifac;
- ysize *= multifac;
-
- /* corner vectors */
- lar->area[0][0] = lar->co[0] - xsize * lar->mat[0][0] - ysize * lar->mat[1][0];
- lar->area[0][1] = lar->co[1] - xsize * lar->mat[0][1] - ysize * lar->mat[1][1];
- lar->area[0][2] = lar->co[2] - xsize * lar->mat[0][2] - ysize * lar->mat[1][2];
-
- /* corner vectors */
- lar->area[1][0] = lar->co[0] - xsize * lar->mat[0][0] + ysize * lar->mat[1][0];
- lar->area[1][1] = lar->co[1] - xsize * lar->mat[0][1] + ysize * lar->mat[1][1];
- lar->area[1][2] = lar->co[2] - xsize * lar->mat[0][2] + ysize * lar->mat[1][2];
-
- /* corner vectors */
- lar->area[2][0] = lar->co[0] + xsize * lar->mat[0][0] + ysize * lar->mat[1][0];
- lar->area[2][1] = lar->co[1] + xsize * lar->mat[0][1] + ysize * lar->mat[1][1];
- lar->area[2][2] = lar->co[2] + xsize * lar->mat[0][2] + ysize * lar->mat[1][2];
-
- /* corner vectors */
- lar->area[3][0] = lar->co[0] + xsize * lar->mat[0][0] - ysize * lar->mat[1][0];
- lar->area[3][1] = lar->co[1] + xsize * lar->mat[0][1] - ysize * lar->mat[1][1];
- lar->area[3][2] = lar->co[2] + xsize * lar->mat[0][2] - ysize * lar->mat[1][2];
- /* only for correction button size, matrix size works on energy */
- lar->areasize = lar->dist * lar->dist / (4.0f * xsize * ysize);
+ float exp_r_3_d = expf(-r / (3.0f * d));
+ float exp_r_d = exp_r_3_d * exp_r_3_d * exp_r_3_d;
+ return (exp_r_d + exp_r_3_d) / (4.0f * d);
}
-#endif
-static void ramp_blend(
- GPUMaterial *mat, GPUNodeLink *fac, GPUNodeLink *col1, GPUNodeLink *col2, int type,
- GPUNodeLink **r_col)
+static float cubic_profile(float r, float radius, float sharpness)
{
- static const char *names[] = {"mix_blend", "mix_add", "mix_mult", "mix_sub",
- "mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light",
- "mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat",
- "mix_val", "mix_color", "mix_soft", "mix_linear"};
-
- GPU_link(mat, names[type], fac, col1, col2, r_col);
-}
+ float Rm = radius * (1.0f + sharpness);
-static void BKE_colorband_eval_blend(
- GPUMaterial *mat, ColorBand *coba, GPUNodeLink *fac, float rampfac, int type,
- GPUNodeLink *incol, GPUNodeLink **r_col)
-{
- GPUNodeLink *tmp, *alpha, *col;
- float *array;
- int size;
-
- /* do colorband */
- BKE_colorband_evaluate_table_rgba(coba, &array, &size);
- GPU_link(mat, "valtorgb", fac, GPU_texture(size, array), &col, &tmp);
-
- /* use alpha in fac */
- GPU_link(mat, "mtex_alpha_from_col", col, &alpha);
- GPU_link(mat, "math_multiply", alpha, GPU_uniform(&rampfac), &fac);
-
- /* blending method */
- ramp_blend(mat, fac, incol, col, type, r_col);
-}
-
-static void ramp_diffuse_result(GPUShadeInput *shi, GPUNodeLink **diff)
-{
- Material *ma = shi->mat;
- GPUMaterial *mat = shi->gpumat;
-
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS)) {
- if (ma->ramp_col) {
- if (ma->rampin_col == MA_RAMP_IN_RESULT) {
- GPUNodeLink *fac;
- GPU_link(mat, "ramp_rgbtobw", *diff, &fac);
-
- /* colorband + blend */
- BKE_colorband_eval_blend(mat, ma->ramp_col, fac, ma->rampfac_col, ma->rampblend_col, *diff, diff);
- }
- }
+ if (r >= Rm) {
+ return 0.0f;
}
-}
+ /* custom variation with extra sharpness, to match the previous code */
+ const float y = 1.0f / (1.0f + sharpness);
+ float Rmy, ry, ryinv;
-static void add_to_diffuse(
- GPUMaterial *mat, Material *ma, GPUShadeInput *shi, GPUNodeLink *is, GPUNodeLink *rgb,
- GPUNodeLink **r_diff)
-{
- GPUNodeLink *fac, *tmp, *addcol;
-
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) &&
- ma->ramp_col && (ma->mode & MA_RAMP_COL))
- {
- /* MA_RAMP_IN_RESULT is exceptional */
- if (ma->rampin_col == MA_RAMP_IN_RESULT) {
- addcol = shi->rgb;
- }
- else {
- /* input */
- switch (ma->rampin_col) {
- case MA_RAMP_IN_ENERGY:
- GPU_link(mat, "ramp_rgbtobw", rgb, &fac);
- break;
- case MA_RAMP_IN_SHADER:
- fac = is;
- break;
- case MA_RAMP_IN_NOR:
- GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
- break;
- default:
- GPU_link(mat, "set_value_zero", &fac);
- break;
- }
+ Rmy = powf(Rm, y);
+ ry = powf(r, y);
+ ryinv = (r > 0.0f) ? powf(r, y - 1.0f) : 0.0f;
- /* colorband + blend */
- BKE_colorband_eval_blend(mat, ma->ramp_col, fac, ma->rampfac_col, ma->rampblend_col, shi->rgb, &addcol);
- }
- }
- else
- addcol = shi->rgb;
+ const float Rmy5 = (Rmy * Rmy) * (Rmy * Rmy) * Rmy;
+ const float f = Rmy - ry;
+ const float num = f * (f * f) * (y * ryinv);
- /* output to */
- GPU_link(mat, "shade_madd", *r_diff, rgb, addcol, r_diff);
+ return (10.0f * num) / (Rmy5 * M_PI);
}
-static void ramp_spec_result(GPUShadeInput *shi, GPUNodeLink **spec)
+static float eval_profile(float r, short falloff_type, float sharpness, float param)
{
- Material *ma = shi->mat;
- GPUMaterial *mat = shi->gpumat;
+ r = fabsf(r);
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_RAMPS) &&
- ma->ramp_spec && ma->rampin_spec == MA_RAMP_IN_RESULT)
+ if (falloff_type == SHD_SUBSURFACE_BURLEY ||
+ falloff_type == SHD_SUBSURFACE_RANDOM_WALK)
{
- GPUNodeLink *fac;
- GPU_link(mat, "ramp_rgbtobw", *spec, &fac);
-
- /* colorband + blend */
- BKE_colorband_eval_blend(mat, ma->ramp_spec, fac, ma->rampfac_spec, ma->rampblend_spec, *spec, spec);
+ return burley_profile(r, param) / BURLEY_TRUNCATE_CDF;
}
-}
-
-static void do_specular_ramp(GPUShadeInput *shi, GPUNodeLink *is, GPUNodeLink *t, GPUNodeLink **spec)
-{
- Material *ma = shi->mat;
- GPUMaterial *mat = shi->gpumat;
- GPUNodeLink *fac, *tmp;
-
- *spec = shi->specrgb;
-
- /* MA_RAMP_IN_RESULT is exception */
- if (ma->ramp_spec && (ma->rampin_spec != MA_RAMP_IN_RESULT)) {
-
- /* input */
- switch (ma->rampin_spec) {
- case MA_RAMP_IN_ENERGY:
- fac = t;
- break;
- case MA_RAMP_IN_SHADER:
- fac = is;
- break;
- case MA_RAMP_IN_NOR:
- GPU_link(mat, "vec_math_dot", shi->view, shi->vn, &tmp, &fac);
- break;
- default:
- GPU_link(mat, "set_value_zero", &fac);
- break;
- }
-
- /* colorband + blend */
- BKE_colorband_eval_blend(mat, ma->ramp_spec, fac, ma->rampfac_spec, ma->rampblend_spec, *spec, spec);
+ else if (falloff_type == SHD_SUBSURFACE_CUBIC) {
+ return cubic_profile(r, param, sharpness);
+ }
+ else {
+ return gaussian_profile(r, param);
}
}
-static void add_user_list(ListBase *list, void *data)
-{
- LinkData *link = MEM_callocN(sizeof(LinkData), "GPULinkData");
- link->data = data;
- BLI_addtail(list, link);
-}
-
-static void shade_light_textures(GPUMaterial *mat, GPULamp *lamp, GPUNodeLink **rgb)
+/* Resolution for each sample of the precomputed kernel profile */
+#define INTEGRAL_RESOLUTION 32
+static float eval_integral(float x0, float x1, short falloff_type, float sharpness, float param)
{
- for (int i = 0; i < MAX_MTEX; ++i) {
- MTex *mtex = lamp->la->mtex[i];
-
- if (mtex && mtex->tex && (mtex->tex->type & TEX_IMAGE) && mtex->tex->ima) {
- mat->dynproperty |= DYN_LAMP_PERSMAT;
-
- float one = 1.0f;
- GPUNodeLink *tex_rgb;
+ const float range = x1 - x0;
+ const float step = range / INTEGRAL_RESOLUTION;
+ float integral = 0.0f;
- GPU_link(mat, "shade_light_texture",
- GPU_builtin(GPU_VIEW_POSITION),
- GPU_image(mtex->tex->ima, &mtex->tex->iuser, false),
- GPU_dynamic_uniform((float *)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
- &tex_rgb);
- texture_rgb_blend(mat, tex_rgb, *rgb, GPU_uniform(&one), GPU_uniform(&mtex->colfac), mtex->blendtype, rgb);
- }
+ for (int i = 0; i < INTEGRAL_RESOLUTION; ++i) {
+ float x = x0 + range * ((float)i + 0.5f) / (float)INTEGRAL_RESOLUTION;
+ float y = eval_profile(x, falloff_type, sharpness, param);
+ integral += y * step;
}
+
+ return integral;
}
+#undef INTEGRAL_RESOLUTION
-static void shade_one_light(GPUShadeInput *shi, GPUShadeResult *shr, GPULamp *lamp)
+static void compute_sss_kernel(
+ GPUSssKernelData *kd, float *radii, int sample_ct, int falloff_type, float sharpness)
{
- Material *ma = shi->mat;
- GPUMaterial *mat = shi->gpumat;
- GPUNodeLink *lv, *dist, *is, *inp, *i;
- GPUNodeLink *outcol, *specfac, *t, *shadfac = NULL, *lcol;
- float one = 1.0f;
-
- if ((lamp->mode & LA_ONLYSHADOW) && !(ma->mode & MA_SHADOW))
- return;
-
- GPUNodeLink *vn = shi->vn;
- GPUNodeLink *view = shi->view;
+ float rad[3];
+ /* Minimum radius */
+ rad[0] = MAX2(radii[0], 1e-15f);
+ rad[1] = MAX2(radii[1], 1e-15f);
+ rad[2] = MAX2(radii[2], 1e-15f);
- GPUNodeLink *visifac = lamp_get_visibility(mat, lamp, &lv, &dist);
+ /* Christensen-Burley fitting */
+ float l[3], d[3];
-#if 0
- if (ma->mode & MA_TANGENT_V)
- GPU_link(mat, "shade_tangent_v", lv, GPU_attribute(CD_TANGENT, ""), &vn);
-#endif
-
- GPU_link(mat, "shade_inp", vn, lv, &inp);
+ if (falloff_type == SHD_SUBSURFACE_BURLEY ||
+ falloff_type == SHD_SUBSURFACE_RANDOM_WALK)
+ {
+ mul_v3_v3fl(l, rad, 0.25f * M_1_PI);
+ const float A = 1.0f;
+ const float s = 1.9f - A + 3.5f * (A - 0.8f) * (A - 0.8f);
+ /* XXX 0.6f Out of nowhere to match cycles! Empirical! Can be tweak better. */
+ mul_v3_v3fl(d, l, 0.6f / s);
+ mul_v3_v3fl(rad, d, BURLEY_TRUNCATE);
+ kd->max_radius = MAX3(rad[0], rad[1], rad[2]);
- if (lamp->mode & LA_NO_DIFF) {
- GPU_link(mat, "shade_is_no_diffuse", &is);
+ copy_v3_v3(kd->param, d);
}
- else if (lamp->type == LA_HEMI) {
- GPU_link(mat, "shade_is_hemi", inp, &is);
+ else if (falloff_type == SHD_SUBSURFACE_CUBIC) {
+ copy_v3_v3(kd->param, rad);
+ mul_v3_fl(rad, 1.0f + sharpness);
+ kd->max_radius = MAX3(rad[0], rad[1], rad[2]);
}
else {
- if (lamp->type == LA_AREA) {
- float area[4][4] = {{0.0f}}, areasize = 0.0f;
-
- mat->dynproperty |= DYN_LAMP_VEC | DYN_LAMP_CO;
- GPU_link(mat, "shade_inp_area",
- GPU_builtin(GPU_VIEW_POSITION),
- GPU_dynamic_uniform(lamp->dynco, GPU_DYNAMIC_LAMP_DYNCO, lamp->ob),
- GPU_dynamic_uniform(lamp->dynvec, GPU_DYNAMIC_LAMP_DYNVEC, lamp->ob), vn,
- GPU_uniform((float *)area),
- GPU_uniform(&areasize),
- GPU_uniform(&lamp->k), &inp);
- }
+ kd->max_radius = MAX3(rad[0], rad[1], rad[2]);
- is = inp; /* Lambert */
-
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS)) {
- if (ma->diff_shader == MA_DIFF_ORENNAYAR)
- GPU_link(mat, "shade_diffuse_oren_nayer", inp, vn, lv, view,
- GPU_uniform(&ma->roughness), &is);
- else if (ma->diff_shader == MA_DIFF_TOON)
- GPU_link(mat, "shade_diffuse_toon", vn, lv, view,
- GPU_uniform(&ma->param[0]), GPU_uniform(&ma->param[1]), &is);
- else if (ma->diff_shader == MA_DIFF_MINNAERT)
- GPU_link(mat, "shade_diffuse_minnaert", inp, vn, view,
- GPU_uniform(&ma->darkness), &is);
- else if (ma->diff_shader == MA_DIFF_FRESNEL)
- GPU_link(mat, "shade_diffuse_fresnel", vn, lv, view,
- GPU_uniform(&ma->param[0]), GPU_uniform(&ma->param[1]), &is);
- }
+ copy_v3_v3(kd->param, rad);
}
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADERS))
- if (ma->shade_flag & MA_CUBIC)
- GPU_link(mat, "shade_cubic", is, &is);
-
- i = is;
- GPU_link(mat, "shade_visifac", i, visifac, shi->refl, &i);
-
- GPU_link(mat, "set_rgb", GPU_dynamic_uniform(lamp->dyncol, GPU_DYNAMIC_LAMP_DYNCOL, lamp->ob), &lcol);
- shade_light_textures(mat, lamp, &lcol);
- GPU_link(mat, "shade_mul_value_v3",
- GPU_dynamic_uniform(&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob), lcol, &lcol);
-
-#if 0
- if (ma->mode & MA_TANGENT_VN)
- GPU_link(mat, "shade_tangent_v_spec", GPU_attribute(CD_TANGENT, ""), &vn);
-#endif
+ /* Compute samples locations on the 1d kernel [-1..1] */
+ sss_calculate_offsets(kd, sample_ct, SSS_EXPONENT);
- /* this replaces if (i > 0.0) conditional until that is supported */
- /* done in shade_visifac now, GPU_link(mat, "mtex_value_clamp_positive", i, &i); */
-
- if ((ma->mode & MA_SHADOW) && GPU_lamp_has_shadow_buffer(lamp)) {
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS)) {
- mat->dynproperty |= DYN_LAMP_PERSMAT;
-
- if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE) {
- GPU_link(mat, "test_shadowbuf_vsm",
- GPU_builtin(GPU_VIEW_POSITION),
- GPU_dynamic_texture(lamp->tex, GPU_DYNAMIC_SAMPLER_2DSHADOW, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
- GPU_uniform(&lamp->bias), GPU_uniform(&lamp->la->bleedbias), inp, &shadfac);
- }
- else {
- GPU_link(mat, "test_shadowbuf",
- GPU_builtin(GPU_VIEW_POSITION),
- GPU_dynamic_texture(lamp->tex, GPU_DYNAMIC_SAMPLER_2DSHADOW, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
- GPU_uniform(&lamp->bias), inp, &shadfac);
- }
-
- if (lamp->mode & LA_ONLYSHADOW) {
- GPUNodeLink *shadrgb;
- GPU_link(mat, "shade_only_shadow", i, shadfac,
- GPU_dynamic_uniform(&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob),
- GPU_uniform(lamp->shadow_color), &shadrgb);
-
- if (!(lamp->mode & LA_NO_DIFF)) {
- GPU_link(mat, "shade_only_shadow_diffuse", shadrgb, shi->rgb,
- shr->diff, &shr->diff);
- }
-
- if (!(lamp->mode & LA_NO_SPEC)) {
- GPU_link(mat, "shade_only_shadow_specular", shadrgb, shi->specrgb,
- shr->spec, &shr->spec);
- }
-
- add_user_list(&mat->lamps, lamp);
- add_user_list(&lamp->materials, shi->gpumat->ma);
- return;
- }
- }
- }
- else if ((mat->scene->gm.flag & GAME_GLSL_NO_SHADOWS) && (lamp->mode & LA_ONLYSHADOW)) {
- add_user_list(&mat->lamps, lamp);
- add_user_list(&lamp->materials, shi->gpumat->ma);
- return;
- }
- else
- GPU_link(mat, "set_value", GPU_uniform(&one), &shadfac);
-
- if (GPU_link_changed(shi->refl) || ma->ref != 0.0f) {
- if (!(lamp->mode & LA_NO_DIFF)) {
- GPUNodeLink *rgb;
- GPU_link(mat, "shade_mul_value", i, lcol, &rgb);
- GPU_link(mat, "mtex_value_invert", shadfac, &shadfac);
- GPU_link(mat, "mix_mult", shadfac, rgb, GPU_uniform(lamp->shadow_color), &rgb);
- GPU_link(mat, "mtex_value_invert", shadfac, &shadfac);
- add_to_diffuse(mat, ma, shi, is, rgb, &shr->diff);
- }
- }
+ /* Weights sum for normalization */
+ float sum[3] = {0.0f, 0.0f, 0.0f};
- if (mat->scene->gm.flag & GAME_GLSL_NO_SHADERS) {
- /* pass */
- }
- else if (!(lamp->mode & LA_NO_SPEC) && !(lamp->mode & LA_ONLYSHADOW) &&
- (GPU_link_changed(shi->spec) || ma->spec != 0.0f))
- {
- if (lamp->type == LA_HEMI) {
- GPU_link(mat, "shade_hemi_spec", vn, lv, view, GPU_uniform(&ma->spec), shi->har, visifac, &t);
- GPU_link(mat, "shade_add_spec", t, lcol, shi->specrgb, &outcol);
- GPU_link(mat, "shade_add_clamped", shr->spec, outcol, &shr->spec);
+ /* Compute integral of each sample footprint */
+ for (int i = 0; i < sample_ct; i++) {
+ float x0, x1;
+
+ if (i == 0) {
+ x0 = kd->kernel[0][3] - fabsf(kd->kernel[0][3] - kd->kernel[1][3]) / 2.0f;
}
else {
- if (ma->spec_shader == MA_SPEC_PHONG) {
- GPU_link(mat, "shade_phong_spec", vn, lv, view, shi->har, &specfac);
- }
- else if (ma->spec_shader == MA_SPEC_COOKTORR) {
- GPU_link(mat, "shade_cooktorr_spec", vn, lv, view, shi->har, &specfac);
- }
- else if (ma->spec_shader == MA_SPEC_BLINN) {
- GPU_link(mat, "shade_blinn_spec", vn, lv, view,
- GPU_uniform(&ma->refrac), shi->har, &specfac);
- }
- else if (ma->spec_shader == MA_SPEC_WARDISO) {
- GPU_link(mat, "shade_wardiso_spec", vn, lv, view,
- GPU_uniform(&ma->rms), &specfac);
- }
- else {
- GPU_link(mat, "shade_toon_spec", vn, lv, view,
- GPU_uniform(&ma->param[2]), GPU_uniform(&ma->param[3]), &specfac);
- }
-
- if (lamp->type == LA_AREA)
- GPU_link(mat, "shade_spec_area_inp", specfac, inp, &specfac);
-
- GPU_link(mat, "shade_spec_t", shadfac, shi->spec, visifac, specfac, &t);
-
- if (ma->mode & MA_RAMP_SPEC) {
- GPUNodeLink *spec;
- do_specular_ramp(shi, specfac, t, &spec);
- GPU_link(mat, "shade_add_spec", t, lcol, spec, &outcol);
- GPU_link(mat, "shade_add_clamped", shr->spec, outcol, &shr->spec);
- }
- else {
- GPU_link(mat, "shade_add_spec", t, lcol, shi->specrgb, &outcol);
- GPU_link(mat, "shade_add_clamped", shr->spec, outcol, &shr->spec);
- }
+ x0 = (kd->kernel[i - 1][3] + kd->kernel[i][3]) / 2.0f;
}
- }
- add_user_list(&mat->lamps, lamp);
- add_user_list(&lamp->materials, shi->gpumat->ma);
-}
-
-static void material_lights(GPUShadeInput *shi, GPUShadeResult *shr)
-{
- Base *base;
- Scene *sce_iter;
-
- for (SETLOOPER(shi->gpumat->scene, sce_iter, base)) {
- Object *ob = base->object;
-
- if (ob->type == OB_LAMP) {
- GPULamp *lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob, NULL);
- if (lamp)
- shade_one_light(shi, shr, lamp);
+ if (i == sample_ct - 1) {
+ x1 = kd->kernel[sample_ct - 1][3] + fabsf(kd->kernel[sample_ct - 2][3] - kd->kernel[sample_ct - 1][3]) / 2.0f;
+ }
+ else {
+ x1 = (kd->kernel[i][3] + kd->kernel[i + 1][3]) / 2.0f;
}
- if (ob->transflag & OB_DUPLI) {
- ListBase *lb = object_duplilist(G.main->eval_ctx, shi->gpumat->scene, ob);
-
- for (DupliObject *dob = lb->first; dob; dob = dob->next) {
- Object *ob_iter = dob->ob;
+ x0 *= kd->max_radius;
+ x1 *= kd->max_radius;
- if (ob_iter->type == OB_LAMP) {
- float omat[4][4];
- copy_m4_m4(omat, ob_iter->obmat);
- copy_m4_m4(ob_iter->obmat, dob->mat);
+ kd->kernel[i][0] = eval_integral(x0, x1, falloff_type, sharpness, kd->param[0]);
+ kd->kernel[i][1] = eval_integral(x0, x1, falloff_type, sharpness, kd->param[1]);
+ kd->kernel[i][2] = eval_integral(x0, x1, falloff_type, sharpness, kd->param[2]);
- GPULamp *lamp = GPU_lamp_from_blender(shi->gpumat->scene, ob_iter, ob);
- if (lamp)
- shade_one_light(shi, shr, lamp);
+ sum[0] += kd->kernel[i][0];
+ sum[1] += kd->kernel[i][1];
+ sum[2] += kd->kernel[i][2];
+ }
- copy_m4_m4(ob_iter->obmat, omat);
- }
+ for (int i = 0; i < 3; ++i) {
+ if (sum[i] > 0.0f) {
+ /* Normalize */
+ for (int j = 0; j < sample_ct; j++) {
+ kd->kernel[j][i] /= sum[i];
}
-
- free_object_duplilist(lb);
+ }
+ else {
+ /* Avoid 0 kernel sum. */
+ kd->kernel[sample_ct / 2][i] = 1.0f;
}
}
- /* prevent only shadow lamps from producing negative colors.*/
- GPU_link(shi->gpumat, "shade_clamp_positive", shr->spec, &shr->spec);
- GPU_link(shi->gpumat, "shade_clamp_positive", shr->diff, &shr->diff);
-}
-
-static void texture_rgb_blend(
- GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg,
- int blendtype, GPUNodeLink **in)
-{
- switch (blendtype) {
- case MTEX_BLEND:
- GPU_link(mat, "mtex_rgb_blend", out, tex, fact, facg, in);
- break;
- case MTEX_MUL:
- GPU_link(mat, "mtex_rgb_mul", out, tex, fact, facg, in);
- break;
- case MTEX_SCREEN:
- GPU_link(mat, "mtex_rgb_screen", out, tex, fact, facg, in);
- break;
- case MTEX_OVERLAY:
- GPU_link(mat, "mtex_rgb_overlay", out, tex, fact, facg, in);
- break;
- case MTEX_SUB:
- GPU_link(mat, "mtex_rgb_sub", out, tex, fact, facg, in);
- break;
- case MTEX_ADD:
- GPU_link(mat, "mtex_rgb_add", out, tex, fact, facg, in);
- break;
- case MTEX_DIV:
- GPU_link(mat, "mtex_rgb_div", out, tex, fact, facg, in);
- break;
- case MTEX_DIFF:
- GPU_link(mat, "mtex_rgb_diff", out, tex, fact, facg, in);
- break;
- case MTEX_DARK:
- GPU_link(mat, "mtex_rgb_dark", out, tex, fact, facg, in);
- break;
- case MTEX_LIGHT:
- GPU_link(mat, "mtex_rgb_light", out, tex, fact, facg, in);
- break;
- case MTEX_BLEND_HUE:
- GPU_link(mat, "mtex_rgb_hue", out, tex, fact, facg, in);
- break;
- case MTEX_BLEND_SAT:
- GPU_link(mat, "mtex_rgb_sat", out, tex, fact, facg, in);
- break;
- case MTEX_BLEND_VAL:
- GPU_link(mat, "mtex_rgb_val", out, tex, fact, facg, in);
- break;
- case MTEX_BLEND_COLOR:
- GPU_link(mat, "mtex_rgb_color", out, tex, fact, facg, in);
- break;
- case MTEX_SOFT_LIGHT:
- GPU_link(mat, "mtex_rgb_soft", out, tex, fact, facg, in);
- break;
- case MTEX_LIN_LIGHT:
- GPU_link(mat, "mtex_rgb_linear", out, tex, fact, facg, in);
- break;
- default:
- GPU_link(mat, "set_rgb_zero", &in);
- break;
+ /* Put center sample at the start of the array (to sample first) */
+ float tmpv[4];
+ copy_v4_v4(tmpv, kd->kernel[sample_ct / 2]);
+ for (int i = sample_ct / 2; i > 0; i--) {
+ copy_v4_v4(kd->kernel[i], kd->kernel[i - 1]);
}
-}
+ copy_v4_v4(kd->kernel[0], tmpv);
-static void texture_value_blend(
- GPUMaterial *mat, GPUNodeLink *tex, GPUNodeLink *out, GPUNodeLink *fact, GPUNodeLink *facg,
- int blendtype, GPUNodeLink **in)
-{
- switch (blendtype) {
- case MTEX_BLEND:
- GPU_link(mat, "mtex_value_blend", out, tex, fact, facg, in);
- break;
- case MTEX_MUL:
- GPU_link(mat, "mtex_value_mul", out, tex, fact, facg, in);
- break;
- case MTEX_SCREEN:
- GPU_link(mat, "mtex_value_screen", out, tex, fact, facg, in);
- break;
- case MTEX_SUB:
- GPU_link(mat, "mtex_value_sub", out, tex, fact, facg, in);
- break;
- case MTEX_ADD:
- GPU_link(mat, "mtex_value_add", out, tex, fact, facg, in);
- break;
- case MTEX_DIV:
- GPU_link(mat, "mtex_value_div", out, tex, fact, facg, in);
- break;
- case MTEX_DIFF:
- GPU_link(mat, "mtex_value_diff", out, tex, fact, facg, in);
- break;
- case MTEX_DARK:
- GPU_link(mat, "mtex_value_dark", out, tex, fact, facg, in);
- break;
- case MTEX_LIGHT:
- GPU_link(mat, "mtex_value_light", out, tex, fact, facg, in);
- break;
- default:
- GPU_link(mat, "set_value_zero", &in);
- break;
- }
+ kd->samples = sample_ct;
}
-static void do_material_tex(GPUShadeInput *shi)
+#define INTEGRAL_RESOLUTION 512
+static void compute_sss_translucence_kernel(
+ const GPUSssKernelData *kd, int resolution, short falloff_type, float sharpness, float **output)
{
- Material *ma = shi->mat;
- GPUMaterial *mat = shi->gpumat;
- MTex *mtex;
- Tex *tex;
- GPUNodeLink *texco, *tin, *trgb, *tnor, *tcol, *stencil, *tnorfac;
- GPUNodeLink *texco_norm, *texco_orco, *texco_object;
- GPUNodeLink *texco_global, *texco_uv = NULL;
- GPUNodeLink *newnor, *orn;
- float one = 1.0f;
- int rgbnor, talpha;
- bool init_done = false;
- int iBumpSpacePrev = 0; /* Not necessary, quieting gcc warning. */
- GPUNodeLink *vNorg, *vNacc, *fPrevMagnitude;
- int iFirstTimeNMap = 1;
- bool found_deriv_map = false;
-
- GPU_link(mat, "set_value", GPU_uniform(&one), &stencil);
-
- GPU_link(mat, "texco_norm", GPU_builtin(GPU_VIEW_NORMAL), &texco_norm);
- GPU_link(mat, "texco_orco", GPU_attribute(CD_ORCO, ""), &texco_orco);
- GPU_link(mat, "texco_object", GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
- GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
- GPU_builtin(GPU_VIEW_POSITION), &texco_object);
-#if 0
- GPU_link(mat, "texco_tangent", GPU_attribute(CD_TANGENT, ""), &texco_tangent);
-#endif
- GPU_link(mat, "texco_global", GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
- GPU_builtin(GPU_VIEW_POSITION), &texco_global);
-
- orn = texco_norm;
-
- /* go over texture slots */
- for (int tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) {
- /* separate tex switching */
- if (ma->septex & (1 << tex_nr)) continue;
-
- if (ma->mtex[tex_nr]) {
- mtex = ma->mtex[tex_nr];
-
- tex = mtex->tex;
- if (tex == NULL) continue;
-
- /* which coords */
- if (mtex->texco == TEXCO_ORCO)
- texco = texco_orco;
- else if (mtex->texco == TEXCO_OBJECT)
- texco = texco_object;
- else if (mtex->texco == TEXCO_NORM)
- texco = orn;
- else if (mtex->texco == TEXCO_TANGENT)
- texco = texco_object;
- else if (mtex->texco == TEXCO_GLOB)
- texco = texco_global;
- else if (mtex->texco == TEXCO_REFL) {
- GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref);
- texco = shi->ref;
- }
- else if (mtex->texco == TEXCO_UV) {
- if (1) { //!(texco_uv && strcmp(mtex->uvname, lastuvname) == 0)) {
- GPU_link(mat, "texco_uv", GPU_attribute(CD_MTFACE, mtex->uvname), &texco_uv);
- /*lastuvname = mtex->uvname;*/ /*UNUSED*/
- }
- texco = texco_uv;
- }
- else
- continue;
-
- /* in case of uv, this would just undo a multiplication in texco_uv */
- if (mtex->texco != TEXCO_UV)
- GPU_link(mat, "mtex_2d_mapping", texco, &texco);
-
- if (mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f)
- GPU_link(mat, "mtex_mapping_size", texco, GPU_uniform(mtex->size), &texco);
-
- float ofs[3] = {
- mtex->ofs[0] + 0.5f - 0.5f * mtex->size[0],
- mtex->ofs[1] + 0.5f - 0.5f * mtex->size[1],
- 0.0f
- };
-
- if (ofs[0] != 0.0f || ofs[1] != 0.0f || ofs[2] != 0.0f)
- GPU_link(mat, "mtex_mapping_ofs", texco, GPU_uniform(ofs), &texco);
-
- talpha = 0;
-
- if (tex && tex->ima &&
- ((tex->type == TEX_IMAGE) ||
- ((tex->type == TEX_ENVMAP) && (mtex->texco == TEXCO_REFL))))
- {
- if (tex->type == TEX_IMAGE) {
- GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), &tin, &trgb);
- }
- else {
- GPU_link(mat, "mtex_cube_map_refl",
- GPU_cube_map(tex->ima, &tex->iuser, false), shi->view, shi->vn,
- GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
- GPU_builtin(GPU_VIEW_MATRIX), &tin, &trgb);
- }
- rgbnor = TEX_RGB;
-
- talpha = ((tex->imaflag & TEX_USEALPHA) && tex->ima && (tex->ima->flag & IMA_IGNORE_ALPHA) == 0);
- }
- else {
- continue;
- }
+ float (*texels)[4];
+ texels = MEM_callocN(sizeof(float) * 4 * resolution, "compute_sss_translucence_kernel");
+ *output = (float *)texels;
- /* texture output */
- if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
- GPU_link(mat, "mtex_rgbtoint", trgb, &tin);
- rgbnor -= TEX_RGB;
- }
+ /* Last texel should be black, hence the - 1. */
+ for (int i = 0; i < resolution - 1; ++i) {
+ /* Distance from surface. */
+ float d = kd->max_radius * ((float)i + 0.00001f) / ((float)resolution);
- if (mtex->texflag & MTEX_NEGATIVE) {
- if (rgbnor & TEX_RGB)
- GPU_link(mat, "mtex_rgb_invert", trgb, &trgb);
- else
- GPU_link(mat, "mtex_value_invert", tin, &tin);
- }
+ /* For each distance d we compute the radiance incomming from an hypothetic parallel plane. */
+ /* Compute radius of the footprint on the hypothetic plane */
+ float r_fp = sqrtf(kd->max_radius * kd->max_radius - d * d);
+ float r_step = r_fp / INTEGRAL_RESOLUTION;
+ float area_accum = 0.0f;
+ for (float r = 0.0f; r < r_fp; r += r_step) {
+ /* Compute distance to the "shading" point through the medium. */
+ /* r_step * 0.5f to put sample between the area borders */
+ float dist = hypotf(r + r_step * 0.5f, d);
- if (mtex->texflag & MTEX_STENCIL) {
- if (rgbnor & TEX_RGB)
- GPU_link(mat, "mtex_rgb_stencil", stencil, trgb, &stencil, &trgb);
- else
- GPU_link(mat, "mtex_value_stencil", stencil, tin, &stencil, &tin);
- }
+ float profile[3];
+ profile[0] = eval_profile(dist, falloff_type, sharpness, kd->param[0]);
+ profile[1] = eval_profile(dist, falloff_type, sharpness, kd->param[1]);
+ profile[2] = eval_profile(dist, falloff_type, sharpness, kd->param[2]);
- /* mapping */
- if (mtex->mapto & (MAP_COL | MAP_COLSPEC | MAP_COLMIR)) {
- /* stencil maps on the texture control slider, not texture intensity value */
- if ((rgbnor & TEX_RGB) == 0) {
- GPU_link(mat, "set_rgb", GPU_uniform(&mtex->r), &tcol);
- }
- else {
- GPU_link(mat, "set_rgba", trgb, &tcol);
-
- if (mtex->mapto & MAP_ALPHA)
- GPU_link(mat, "set_value", stencil, &tin);
- else if (talpha)
- GPU_link(mat, "mtex_alpha_from_col", trgb, &tin);
- else
- GPU_link(mat, "set_value_one", &tin);
- }
-
- if ((tex->type == TEX_IMAGE) ||
- ((tex->type == TEX_ENVMAP) && (mtex->texco == TEXCO_REFL)))
- {
- if (GPU_material_do_color_management(mat)) {
- GPU_link(mat, "srgb_to_linearrgb", tcol, &tcol);
- }
- }
-
- if (mtex->mapto & MAP_COL) {
- GPUNodeLink *colfac;
-
- if (mtex->colfac == 1.0f) colfac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->colfac), stencil, &colfac);
-
- texture_rgb_blend(mat, tcol, shi->rgb, tin, colfac, mtex->blendtype, &shi->rgb);
- }
-
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_COLSPEC)) {
- GPUNodeLink *colspecfac;
-
- if (mtex->colspecfac == 1.0f) colspecfac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->colspecfac), stencil, &colspecfac);
-
- texture_rgb_blend(mat, tcol, shi->specrgb, tin, colspecfac, mtex->blendtype, &shi->specrgb);
- }
-
- if (mtex->mapto & MAP_COLMIR) {
- GPUNodeLink *colmirfac;
-
- if (mtex->mirrfac == 1.0f) colmirfac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->mirrfac), stencil, &colmirfac);
-
- /* exception for envmap only */
- if (tex->type == TEX_ENVMAP && mtex->blendtype == MTEX_BLEND) {
- GPU_link(mat, "mtex_mirror", tcol, shi->refcol, tin, colmirfac, &shi->refcol);
- }
- else
- texture_rgb_blend(mat, tcol, shi->mir, tin, colmirfac, mtex->blendtype, &shi->mir);
- }
- }
-
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && (mtex->mapto & MAP_NORM)) {
- if (tex->type == TEX_IMAGE) {
- found_deriv_map = tex->imaflag & TEX_DERIVATIVEMAP;
-
- if (tex->imaflag & TEX_NORMALMAP) {
- /* normalmap image */
- GPU_link(mat, "mtex_normal", texco, GPU_image(tex->ima, &tex->iuser, true), &tnor);
-
- if (mtex->norfac < 0.0f)
- GPU_link(mat, "mtex_negate_texnormal", tnor, &tnor);
-
- if (mtex->normapspace == MTEX_NSPACE_TANGENT) {
- if (iFirstTimeNMap != 0) {
- // use unnormalized normal (this is how we bake it - closer to gamedev)
- GPUNodeLink *vNegNorm;
- GPU_link(mat, "vec_math_negate",
- GPU_builtin(GPU_VIEW_NORMAL), &vNegNorm);
- GPU_link(mat, "mtex_nspace_tangent",
- GPU_attribute(CD_TANGENT, ""), vNegNorm, tnor, &newnor);
- iFirstTimeNMap = 0;
- }
- else { /* otherwise use accumulated perturbations */
- GPU_link(mat, "mtex_nspace_tangent",
- GPU_attribute(CD_TANGENT, ""), shi->vn, tnor, &newnor);
- }
- }
- else if (mtex->normapspace == MTEX_NSPACE_OBJECT) {
- /* transform normal by object then view matrix */
- GPU_link(mat, "mtex_nspace_object", tnor, &newnor);
- }
- else if (mtex->normapspace == MTEX_NSPACE_WORLD) {
- /* transform normal by view matrix */
- GPU_link(mat, "mtex_nspace_world", GPU_builtin(GPU_VIEW_MATRIX), tnor, &newnor);
- }
- else {
- /* no transform, normal in camera space */
- newnor = tnor;
- }
-
- float norfac = min_ff(fabsf(mtex->norfac), 1.0f);
-
- if (norfac == 1.0f && !GPU_link_changed(stencil)) {
- shi->vn = newnor;
- }
- else {
- tnorfac = GPU_uniform(&norfac);
-
- if (GPU_link_changed(stencil))
- GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
-
- GPU_link(mat, "mtex_blend_normal", tnorfac, shi->vn, newnor, &shi->vn);
- }
-
- }
- else if (found_deriv_map ||
- (mtex->texflag & (MTEX_3TAP_BUMP | MTEX_5TAP_BUMP | MTEX_BICUBIC_BUMP)))
- {
- /* ntap bumpmap image */
- int iBumpSpace;
- float ima_x, ima_y;
-
- float imag_tspace_dimension_x = 1024.0f; /* only used for texture space variant */
- float aspect = 1.0f;
-
- GPUNodeLink *vR1, *vR2;
- GPUNodeLink *dBs, *dBt, *fDet;
-
- float hScale = 0.1f; /* compatibility adjustment factor for all bumpspace types */
- if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
- hScale = 13.0f; /* factor for scaling texspace bumps */
- else if (found_deriv_map)
- hScale = 1.0f;
-
- /* resolve texture resolution */
- if ((mtex->texflag & MTEX_BUMP_TEXTURESPACE) || found_deriv_map) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
- ima_x = 512.0f; ima_y = 512.0f; /* prevent calling textureSize, glsl 1.3 only */
- if (ibuf) {
- ima_x = ibuf->x;
- ima_y = ibuf->y;
- aspect = (float)ima_y / ima_x;
- }
- BKE_image_release_ibuf(tex->ima, ibuf, NULL);
- }
-
- /* The negate on norfac is done because the
- * normal in the renderer points inward which corresponds
- * to inverting the bump map. Should this ever change
- * this negate must be removed. */
- float norfac = -hScale * mtex->norfac;
- if (found_deriv_map) {
- float fVirtDim = sqrtf(fabsf(ima_x * mtex->size[0] * ima_y * mtex->size[1]));
- norfac /= MAX2(fVirtDim, FLT_EPSILON);
- }
-
- tnorfac = GPU_uniform(&norfac);
-
- if (found_deriv_map)
- GPU_link(mat, "math_multiply", tnorfac, GPU_builtin(GPU_AUTO_BUMPSCALE), &tnorfac);
-
- if (GPU_link_changed(stencil))
- GPU_link(mat, "math_multiply", tnorfac, stencil, &tnorfac);
-
- if (!init_done) {
- /* copy shi->vn to vNorg and vNacc, set magnitude to 1 */
- GPU_link(mat, "mtex_bump_normals_init", shi->vn, &vNorg, &vNacc, &fPrevMagnitude);
- iBumpSpacePrev = 0;
- init_done = true;
- }
-
- // find current bump space
- if (mtex->texflag & MTEX_BUMP_OBJECTSPACE)
- iBumpSpace = 1;
- else if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
- iBumpSpace = 2;
- else
- iBumpSpace = 4; /* ViewSpace */
-
- /* re-initialize if bump space changed */
- if (iBumpSpacePrev != iBumpSpace) {
- GPUNodeLink *surf_pos = GPU_builtin(GPU_VIEW_POSITION);
-
- if (mtex->texflag & MTEX_BUMP_OBJECTSPACE)
- GPU_link(mat, "mtex_bump_init_objspace",
- surf_pos, vNorg,
- GPU_builtin(GPU_VIEW_MATRIX),
- GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
- GPU_builtin(GPU_OBJECT_MATRIX),
- GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
- fPrevMagnitude, vNacc,
- &fPrevMagnitude, &vNacc,
- &vR1, &vR2, &fDet);
-
- else if (mtex->texflag & MTEX_BUMP_TEXTURESPACE)
- GPU_link(mat, "mtex_bump_init_texturespace",
- surf_pos, vNorg,
- fPrevMagnitude, vNacc,
- &fPrevMagnitude, &vNacc,
- &vR1, &vR2, &fDet);
-
- else
- GPU_link(mat, "mtex_bump_init_viewspace",
- surf_pos, vNorg,
- fPrevMagnitude, vNacc,
- &fPrevMagnitude, &vNacc,
- &vR1, &vR2, &fDet);
-
- iBumpSpacePrev = iBumpSpace;
- }
-
-
- if (found_deriv_map) {
- GPU_link(mat, "mtex_bump_deriv",
- texco, GPU_image(tex->ima, &tex->iuser, true),
- GPU_uniform(&ima_x), GPU_uniform(&ima_y), tnorfac,
- &dBs, &dBt);
- }
- else if (mtex->texflag & MTEX_3TAP_BUMP)
- GPU_link(mat, "mtex_bump_tap3",
- texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
- &dBs, &dBt);
- else if (mtex->texflag & MTEX_5TAP_BUMP)
- GPU_link(mat, "mtex_bump_tap5",
- texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
- &dBs, &dBt);
- else if (mtex->texflag & MTEX_BICUBIC_BUMP) {
- if (GPU_bicubic_bump_support()) {
- GPU_link(mat, "mtex_bump_bicubic",
- texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
- &dBs, &dBt);
- }
- else {
- GPU_link(mat, "mtex_bump_tap5",
- texco, GPU_image(tex->ima, &tex->iuser, true), tnorfac,
- &dBs, &dBt);
- }
- }
-
-
- if (mtex->texflag & MTEX_BUMP_TEXTURESPACE) {
- float imag_tspace_dimension_y = aspect * imag_tspace_dimension_x;
- GPU_link(mat, "mtex_bump_apply_texspace",
- fDet, dBs, dBt, vR1, vR2,
- GPU_image(tex->ima, &tex->iuser, true), texco,
- GPU_uniform(&imag_tspace_dimension_x),
- GPU_uniform(&imag_tspace_dimension_y), vNacc,
- &vNacc, &shi->vn);
- }
- else
- GPU_link(mat, "mtex_bump_apply",
- fDet, dBs, dBt, vR1, vR2, vNacc,
- &vNacc, &shi->vn);
-
- }
- }
-
- GPU_link(mat, "vec_math_negate", shi->vn, &orn);
- }
+ /* Since the profile and configuration are radially symetrical we
+ * can just evaluate it once and weight it accordingly */
+ float r_next = r + r_step;
+ float disk_area = (M_PI * r_next * r_next) - (M_PI * r * r);
- if ((mtex->mapto & MAP_VARS)) {
- if (rgbnor & TEX_RGB) {
- if (talpha)
- GPU_link(mat, "mtex_alpha_from_col", trgb, &tin);
- else
- GPU_link(mat, "mtex_rgbtoint", trgb, &tin);
- }
-
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_REF) {
- GPUNodeLink *difffac;
-
- if (mtex->difffac == 1.0f) difffac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->difffac), stencil, &difffac);
-
- texture_value_blend(
- mat, GPU_uniform(&mtex->def_var), shi->refl, tin, difffac,
- mtex->blendtype, &shi->refl);
- GPU_link(mat, "mtex_value_clamp_positive", shi->refl, &shi->refl);
- }
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_SPEC) {
- GPUNodeLink *specfac;
-
- if (mtex->specfac == 1.0f) specfac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->specfac), stencil, &specfac);
-
- texture_value_blend(
- mat, GPU_uniform(&mtex->def_var), shi->spec, tin, specfac,
- mtex->blendtype, &shi->spec);
- GPU_link(mat, "mtex_value_clamp_positive", shi->spec, &shi->spec);
- }
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_EMIT) {
- GPUNodeLink *emitfac;
-
- if (mtex->emitfac == 1.0f) emitfac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->emitfac), stencil, &emitfac);
-
- texture_value_blend(
- mat, GPU_uniform(&mtex->def_var), shi->emit, tin, emitfac,
- mtex->blendtype, &shi->emit);
- GPU_link(mat, "mtex_value_clamp_positive", shi->emit, &shi->emit);
- }
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_HAR) {
- GPUNodeLink *hardfac;
-
- if (mtex->hardfac == 1.0f) hardfac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->hardfac), stencil, &hardfac);
-
- GPU_link(mat, "mtex_har_divide", shi->har, &shi->har);
- texture_value_blend(
- mat, GPU_uniform(&mtex->def_var), shi->har, tin, hardfac,
- mtex->blendtype, &shi->har);
- GPU_link(mat, "mtex_har_multiply_clamp", shi->har, &shi->har);
- }
- if (mtex->mapto & MAP_ALPHA) {
- GPUNodeLink *alphafac;
-
- if (mtex->alphafac == 1.0f) alphafac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->alphafac), stencil, &alphafac);
-
- texture_value_blend(
- mat, GPU_uniform(&mtex->def_var), shi->alpha, tin, alphafac,
- mtex->blendtype, &shi->alpha);
- GPU_link(mat, "mtex_value_clamp", shi->alpha, &shi->alpha);
- }
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_EXTRA_TEX) && mtex->mapto & MAP_AMB) {
- GPUNodeLink *ambfac;
-
- if (mtex->ambfac == 1.0f) ambfac = stencil;
- else GPU_link(mat, "math_multiply", GPU_uniform(&mtex->ambfac), stencil, &ambfac);
-
- texture_value_blend(
- mat, GPU_uniform(&mtex->def_var), shi->amb, tin, ambfac,
- mtex->blendtype, &shi->amb);
- GPU_link(mat, "mtex_value_clamp", shi->amb, &shi->amb);
- }
- }
+ mul_v3_fl(profile, disk_area);
+ add_v3_v3(texels[i], profile);
+ area_accum += disk_area;
}
+ /* Normalize over the disk. */
+ mul_v3_fl(texels[i], 1.0f / (area_accum));
}
-}
-
-void GPU_shadeinput_set(GPUMaterial *mat, Material *ma, GPUShadeInput *shi)
-{
- float one = 1.0f;
-
- memset(shi, 0, sizeof(*shi));
-
- shi->gpumat = mat;
- shi->mat = ma;
-
- GPU_link(mat, "set_rgb", GPU_dynamic_uniform(&ma->r, GPU_DYNAMIC_MAT_DIFFRGB, ma), &shi->rgb);
- GPU_link(mat, "set_rgb", GPU_dynamic_uniform(&ma->specr, GPU_DYNAMIC_MAT_SPECRGB, ma), &shi->specrgb);
- GPU_link(mat, "set_rgb", GPU_dynamic_uniform(&ma->mirr, GPU_DYNAMIC_MAT_MIR, ma), &shi->mir);
- GPU_link(mat, "set_rgba_zero", &shi->refcol);
- GPU_link(mat, "shade_norm", GPU_builtin(GPU_VIEW_NORMAL), &shi->vn);
-
- if (mat->alpha)
- GPU_link(mat, "set_value", GPU_dynamic_uniform(&ma->alpha, GPU_DYNAMIC_MAT_ALPHA, ma), &shi->alpha);
- else
- GPU_link(mat, "set_value", GPU_uniform(&one), &shi->alpha);
-
- GPU_link(mat, "set_value", GPU_dynamic_uniform(&ma->ref, GPU_DYNAMIC_MAT_REF, ma), &shi->refl);
- GPU_link(mat, "set_value", GPU_dynamic_uniform(&ma->spec, GPU_DYNAMIC_MAT_SPEC, ma), &shi->spec);
- GPU_link(mat, "set_value", GPU_dynamic_uniform(&ma->emit, GPU_DYNAMIC_MAT_EMIT, ma), &shi->emit);
- GPU_link(mat, "set_value", GPU_dynamic_uniform((float *)&ma->har, GPU_DYNAMIC_MAT_HARD, ma), &shi->har);
- GPU_link(mat, "set_value", GPU_dynamic_uniform(&ma->amb, GPU_DYNAMIC_MAT_AMB, ma), &shi->amb);
- GPU_link(mat, "set_value", GPU_uniform(&ma->spectra), &shi->spectra);
- GPU_link(mat, "shade_view", GPU_builtin(GPU_VIEW_POSITION), &shi->view);
- GPU_link(mat, "vcol_attribute", GPU_attribute(CD_MCOL, ""), &shi->vcol);
- if (GPU_material_do_color_management(mat))
- GPU_link(mat, "srgb_to_linearrgb", shi->vcol, &shi->vcol);
- GPU_link(mat, "texco_refl", shi->vn, shi->view, &shi->ref);
-}
-void GPU_mist_update_enable(short enable)
-{
- GPUWorld.mistenabled = (float)enable;
-}
+ /* Normalize */
+ for (int j = resolution - 2; j > 0; j--) {
+ texels[j][0] /= (texels[0][0] > 0.0f) ? texels[0][0] : 1.0f;
+ texels[j][1] /= (texels[0][1] > 0.0f) ? texels[0][1] : 1.0f;
+ texels[j][2] /= (texels[0][2] > 0.0f) ? texels[0][2] : 1.0f;
+ }
-void GPU_mist_update_values(int type, float start, float dist, float inten, float color[3])
-{
- GPUWorld.mistype = (float)type;
- GPUWorld.miststart = start;
- GPUWorld.mistdistance = dist;
- GPUWorld.mistintensity = inten;
- copy_v3_v3(GPUWorld.mistcol, color);
- GPUWorld.mistcol[3] = 1.0f;
-}
+ /* First texel should be white */
+ texels[0][0] = (texels[0][0] > 0.0f) ? 1.0f : 0.0f;
+ texels[0][1] = (texels[0][1] > 0.0f) ? 1.0f : 0.0f;
+ texels[0][2] = (texels[0][2] > 0.0f) ? 1.0f : 0.0f;
-void GPU_horizon_update_color(float color[3])
-{
- copy_v3_v3(GPUWorld.horicol, color);
+ /* dim the last few texels for smoother transition */
+ mul_v3_fl(texels[resolution - 2], 0.25f);
+ mul_v3_fl(texels[resolution - 3], 0.5f);
+ mul_v3_fl(texels[resolution - 4], 0.75f);
}
+#undef INTEGRAL_RESOLUTION
-void GPU_ambient_update_color(float color[3])
+void GPU_material_sss_profile_create(GPUMaterial *material, float *radii, short *falloff_type, float *sharpness)
{
- copy_v3_v3(GPUWorld.ambcol, color);
- GPUWorld.ambcol[3] = 1.0f;
-}
+ material->sss_radii = radii;
+ material->sss_falloff = falloff_type;
+ material->sss_sharpness = sharpness;
+ material->sss_dirty = true;
-void GPU_zenith_update_color(float color[3])
-{
- copy_v3_v3(GPUWorld.zencol, color);
+ /* Update / Create UBO */
+ if (material->sss_profile == NULL) {
+ material->sss_profile = GPU_uniformbuffer_create(sizeof(GPUSssKernelData), NULL, NULL);
+ }
}
-void GPU_shaderesult_set(GPUShadeInput *shi, GPUShadeResult *shr)
+struct GPUUniformBuffer *GPU_material_sss_profile_get(GPUMaterial *material, int sample_ct, GPUTexture **tex_profile)
{
- GPUMaterial *mat = shi->gpumat;
- GPUNodeLink *emit, *ulinfac, *ulogfac, *mistfac;
- Material *ma = shi->mat;
- World *world = mat->scene->world;
- float linfac, logfac;
-
- memset(shr, 0, sizeof(*shr));
-
- if (ma->mode & MA_VERTEXCOLP)
- shi->rgb = shi->vcol;
-
- do_material_tex(shi);
-
- if ((mat->scene->gm.flag & GAME_GLSL_NO_LIGHTS) || (ma->mode & MA_SHLESS)) {
- GPU_link(mat, "set_rgb", shi->rgb, &shr->diff);
- GPU_link(mat, "set_rgb_zero", &shr->spec);
- GPU_link(mat, "set_value", shi->alpha, &shr->alpha);
- shr->combined = shr->diff;
- }
- else {
- if (GPU_link_changed(shi->emit) || ma->emit != 0.0f) {
- if ((ma->mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == MA_VERTEXCOL) {
- GPU_link(mat, "shade_add", shi->emit, shi->vcol, &emit);
- GPU_link(mat, "shade_mul", emit, shi->rgb, &shr->diff);
- }
- else
- GPU_link(mat, "shade_mul_value", shi->emit, shi->rgb, &shr->diff);
- }
- else
- GPU_link(mat, "set_rgb_zero", &shr->diff);
+ if (material->sss_radii == NULL)
+ return NULL;
- GPU_link(mat, "set_rgb_zero", &shr->spec);
+ if (material->sss_dirty || (material->sss_samples != sample_ct)) {
+ GPUSssKernelData kd;
- material_lights(shi, shr);
+ float sharpness = (material->sss_sharpness != NULL) ? *material->sss_sharpness : 0.0f;
- shr->combined = shr->diff;
+ /* XXX Black magic but it seems to fit. Maybe because we integrate -1..1 */
+ sharpness *= 0.5f;
- GPU_link(mat, "set_value", shi->alpha, &shr->alpha);
+ compute_sss_kernel(&kd, material->sss_radii, sample_ct, *material->sss_falloff, sharpness);
- if (world) {
- /* exposure correction */
- if (world->exp != 0.0f || world->range != 1.0f) {
- linfac = 1.0f + powf((2.0f * world->exp + 0.5f), -10);
- logfac = logf((linfac - 1.0f) / linfac) / world->range;
+ /* Update / Create UBO */
+ GPU_uniformbuffer_update(material->sss_profile, &kd);
- GPU_link(mat, "set_value", GPU_uniform(&linfac), &ulinfac);
- GPU_link(mat, "set_value", GPU_uniform(&logfac), &ulogfac);
+ /* Update / Create Tex */
+ float *translucence_profile;
+ compute_sss_translucence_kernel(&kd, 64, *material->sss_falloff, sharpness, &translucence_profile);
- GPU_link(mat, "shade_exposure_correct", shr->combined,
- ulinfac, ulogfac, &shr->combined);
- GPU_link(mat, "shade_exposure_correct", shr->spec,
- ulinfac, ulogfac, &shr->spec);
- }
-
- /* environment lighting */
- if (!(mat->scene->gm.flag & GAME_GLSL_NO_ENV_LIGHTING) &&
- (world->mode & WO_ENV_LIGHT) &&
- (mat->scene->r.mode & R_SHADOW) &&
- !BKE_scene_use_new_shading_nodes(mat->scene))
- {
- if ((world->ao_env_energy != 0.0f) && (GPU_link_changed(shi->amb) || ma->amb != 0.0f) &&
- (GPU_link_changed(shi->refl) || ma->ref != 0.0f))
- {
- if (world->aocolor != WO_AOPLAIN) {
- if (!(is_zero_v3(&world->horr) & is_zero_v3(&world->zenr))) {
- GPUNodeLink *fcol, *f;
- GPU_link(mat, "math_multiply", shi->amb, shi->refl, &f);
- GPU_link(mat, "math_multiply", f, GPU_uniform(&world->ao_env_energy), &f);
- GPU_link(mat, "shade_mul_value", f, shi->rgb, &fcol);
- GPU_link(mat, "env_apply", shr->combined,
- GPU_dynamic_uniform(GPUWorld.horicol, GPU_DYNAMIC_HORIZON_COLOR, NULL),
- GPU_dynamic_uniform(GPUWorld.zencol, GPU_DYNAMIC_ZENITH_COLOR, NULL), fcol,
- GPU_builtin(GPU_VIEW_MATRIX), shi->vn, &shr->combined);
- }
- }
- else {
- GPUNodeLink *f;
- GPU_link(mat, "math_multiply", shi->amb, shi->refl, &f);
- GPU_link(mat, "math_multiply", f, GPU_uniform(&world->ao_env_energy), &f);
- GPU_link(mat, "shade_maddf", shr->combined, f, shi->rgb, &shr->combined);
- }
- }
- }
-
- /* ambient color */
- if (GPU_link_changed(shi->amb) || ma->amb != 0.0f) {
- GPU_link(mat, "shade_maddf", shr->combined, GPU_uniform(&ma->amb),
- GPU_dynamic_uniform(GPUWorld.ambcol, GPU_DYNAMIC_AMBIENT_COLOR, NULL),
- &shr->combined);
- }
+ if (material->sss_tex_profile != NULL) {
+ GPU_texture_free(material->sss_tex_profile);
}
- if (ma->mode & MA_TRANSP && (ma->mode & (MA_ZTRANSP | MA_RAYTRANSP))) {
- if (GPU_link_changed(shi->spectra) || ma->spectra != 0.0f) {
- GPU_link(mat, "alpha_spec_correction", shr->spec, shi->spectra,
- shi->alpha, &shr->alpha);
- }
- }
+ material->sss_tex_profile = GPU_texture_create_1D(64, GPU_RGBA16F, translucence_profile, NULL);
- if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shi, &shr->combined);
- if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shi, &shr->spec);
+ MEM_freeN(translucence_profile);
- if (GPU_link_changed(shi->refcol))
- GPU_link(mat, "shade_add_mirror", shi->mir, shi->refcol, shr->combined, &shr->combined);
-
- if (GPU_link_changed(shi->spec) || ma->spec != 0.0f)
- GPU_link(mat, "shade_add", shr->combined, shr->spec, &shr->combined);
+ material->sss_samples = sample_ct;
+ material->sss_dirty = false;
}
- GPU_link(mat, "mtex_alpha_to_col", shr->combined, shr->alpha, &shr->combined);
-
- if (ma->shade_flag & MA_OBCOLOR)
- GPU_link(mat, "shade_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined);
-
- if (!(ma->mode & MA_NOMIST)) {
- GPU_link(mat, "shade_mist_factor", GPU_builtin(GPU_VIEW_POSITION),
- GPU_dynamic_uniform(&GPUWorld.mistenabled, GPU_DYNAMIC_MIST_ENABLE, NULL),
- GPU_dynamic_uniform(&GPUWorld.miststart, GPU_DYNAMIC_MIST_START, NULL),
- GPU_dynamic_uniform(&GPUWorld.mistdistance, GPU_DYNAMIC_MIST_DISTANCE, NULL),
- GPU_dynamic_uniform(&GPUWorld.mistype, GPU_DYNAMIC_MIST_TYPE, NULL),
- GPU_dynamic_uniform(&GPUWorld.mistintensity, GPU_DYNAMIC_MIST_INTENSITY, NULL), &mistfac);
-
- GPU_link(mat, "mix_blend", mistfac, shr->combined,
- GPU_dynamic_uniform(GPUWorld.mistcol, GPU_DYNAMIC_MIST_COLOR, NULL), &shr->combined);
+ if (tex_profile != NULL) {
+ *tex_profile = material->sss_tex_profile;
}
+ return material->sss_profile;
+}
- if (!mat->alpha) {
- if (world && (GPU_link_changed(shr->alpha) || ma->alpha != 1.0f))
- GPU_link(mat, "shade_world_mix", GPU_dynamic_uniform(GPUWorld.horicol, GPU_DYNAMIC_HORIZON_COLOR, NULL),
- shr->combined, &shr->combined);
-
- GPU_link(mat, "shade_alpha_opaque", shr->combined, &shr->combined);
- }
+#undef SSS_EXPONENT
+#undef SSS_SAMPLES
- if (ma->shade_flag & MA_OBCOLOR) {
- mat->obcolalpha = 1;
- GPU_link(mat, "shade_alpha_obcolor", shr->combined, GPU_builtin(GPU_OBCOLOR), &shr->combined);
- }
+void GPU_material_vertex_attributes(GPUMaterial *material, GPUVertexAttribs *attribs)
+{
+ *attribs = material->attribs;
}
-static GPUNodeLink *GPU_blender_material(GPUMaterial *mat, Material *ma)
+void GPU_material_output_link(GPUMaterial *material, GPUNodeLink *link)
{
- GPUShadeInput shi;
- GPUShadeResult shr;
-
- GPU_shadeinput_set(mat, ma, &shi);
- GPU_shaderesult_set(&shi, &shr);
-
- return shr.combined;
+ if (!material->outlink)
+ material->outlink = link;
}
-static GPUNodeLink *gpu_material_diffuse_bsdf(GPUMaterial *mat, Material *ma)
+void gpu_material_add_node(GPUMaterial *material, GPUNode *node)
{
- static float roughness = 0.0f;
- GPUNodeLink *outlink;
-
- GPU_link(mat, "node_bsdf_diffuse",
- GPU_uniform(&ma->r), GPU_uniform(&roughness), GPU_builtin(GPU_VIEW_NORMAL), &outlink);
-
- return outlink;
+ BLI_addtail(&material->nodes, node);
}
-static GPUNodeLink *gpu_material_preview_matcap(GPUMaterial *mat, Material *ma)
+/* Return true if the material compilation has not yet begin or begin. */
+GPUMaterialStatus GPU_material_status(GPUMaterial *mat)
{
- GPUNodeLink *outlink;
-
- /* some explanations here:
- * matcap normal holds the normal remapped to the 0.0 - 1.0 range. To take advantage of flat shading, we abuse
- * the built in secondary color of opengl. Color is just the regular color, which should include mask value too.
- * This also needs flat shading so we use the primary opengl color built-in */
- GPU_link(mat, "material_preview_matcap", GPU_uniform(&ma->r), GPU_image_preview(ma->preview),
- GPU_opengl_builtin(GPU_MATCAP_NORMAL), GPU_opengl_builtin(GPU_COLOR), &outlink);
-
- return outlink;
+ return mat->status;
}
-/* new solid draw mode with glsl matcaps */
-GPUMaterial *GPU_material_matcap(Scene *scene, Material *ma, bool use_opensubdiv)
-{
- GPUMaterial *mat;
- GPUNodeLink *outlink;
- LinkData *link;
-
- for (link = ma->gpumaterial.first; link; link = link->next) {
- GPUMaterial *current_material = (GPUMaterial *)link->data;
- if (current_material->scene == scene &&
- current_material->is_opensubdiv == use_opensubdiv)
- {
- return current_material;
- }
- }
-
- /* allocate material */
- mat = GPU_material_construct_begin(ma);
- mat->scene = scene;
- mat->type = GPU_MATERIAL_TYPE_MESH;
- mat->is_opensubdiv = use_opensubdiv;
+/* Code generation */
- if (ma->preview && ma->preview->rect[0]) {
- outlink = gpu_material_preview_matcap(mat, ma);
- }
- else {
- outlink = gpu_material_diffuse_bsdf(mat, ma);
- }
-
- GPU_material_output_link(mat, outlink);
+bool GPU_material_do_color_management(GPUMaterial *mat)
+{
+ if (!BKE_scene_check_color_management_enabled(mat->scene))
+ return false;
- gpu_material_construct_end(mat, "matcap_pass");
-
- /* note that even if building the shader fails in some way, we still keep
- * it to avoid trying to compile again and again, and simple do not use
- * the actual shader on drawing */
-
- link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink");
- link->data = mat;
- BLI_addtail(&ma->gpumaterial, link);
-
- return mat;
+ return true;
}
-static void do_world_tex(GPUShadeInput *shi, struct World *wo, GPUNodeLink **hor, GPUNodeLink **zen, GPUNodeLink **blend)
+bool GPU_material_use_domain_surface(GPUMaterial *mat)
{
- GPUMaterial *mat = shi->gpumat;
- GPUNodeLink *texco, *tin, *trgb, *stencil, *tcol, *zenfac;
- MTex *mtex;
- Tex *tex;
- float ofs[3], zero = 0.0f;
- int tex_nr, rgbnor;
-
- GPU_link(mat, "set_value_one", &stencil);
- /* go over texture slots */
- for (tex_nr = 0; tex_nr < MAX_MTEX; tex_nr++) {
- if (wo->mtex[tex_nr]) {
- mtex = wo->mtex[tex_nr];
- tex = mtex->tex;
- if (tex == NULL || !tex->ima || (tex->type != TEX_IMAGE && tex->type != TEX_ENVMAP))
- continue;
- /* which coords */
- if (mtex->texco == TEXCO_VIEW || mtex->texco == TEXCO_GLOB) {
- if (tex->type == TEX_IMAGE)
- texco = GPU_builtin(GPU_VIEW_POSITION);
- else if (tex->type == TEX_ENVMAP)
- GPU_link(mat, "background_transform_to_world", GPU_builtin(GPU_VIEW_POSITION), &texco);
- }
- else if (mtex->texco == TEXCO_EQUIRECTMAP || mtex->texco == TEXCO_ANGMAP) {
- if ((tex->type == TEX_IMAGE && wo->skytype & WO_SKYREAL) || tex->type == TEX_ENVMAP)
- GPU_link(mat, "background_transform_to_world", GPU_builtin(GPU_VIEW_POSITION), &texco);
- else
- texco = GPU_builtin(GPU_VIEW_POSITION);
- }
- else
- continue;
- GPU_link(mat, "texco_norm", texco, &texco);
- if (tex->type == TEX_IMAGE && !(wo->skytype & WO_SKYREAL)) {
- GPU_link(mat, "mtex_2d_mapping", texco, &texco);
- }
- if (mtex->size[0] != 1.0f || mtex->size[1] != 1.0f || mtex->size[2] != 1.0f) {
- float size[3] = { mtex->size[0], mtex->size[1], mtex->size[2] };
- if (tex->type == TEX_ENVMAP) {
- size[1] = mtex->size[2];
- size[2] = mtex->size[1];
- }
- GPU_link(mat, "mtex_mapping_size", texco, GPU_uniform(size), &texco);
- }
- ofs[0] = mtex->ofs[0] + 0.5f - 0.5f * mtex->size[0];
- if (tex->type == TEX_ENVMAP) {
- ofs[1] = -mtex->ofs[2] + 0.5f - 0.5f * mtex->size[2];
- ofs[2] = mtex->ofs[1] + 0.5f - 0.5f * mtex->size[1];
- }
- else {
- ofs[1] = mtex->ofs[1] + 0.5f - 0.5f * mtex->size[1];
- ofs[2] = 0.0;
- }
- if (ofs[0] != 0.0f || ofs[1] != 0.0f || ofs[2] != 0.0f)
- GPU_link(mat, "mtex_mapping_ofs", texco, GPU_uniform(ofs), &texco);
- if (mtex->texco == TEXCO_EQUIRECTMAP) {
- GPU_link(mat, "node_tex_environment_equirectangular", texco, GPU_image(tex->ima, &tex->iuser, false), &trgb);
- }
- else if (mtex->texco == TEXCO_ANGMAP) {
- GPU_link(mat, "node_tex_environment_mirror_ball", texco, GPU_image(tex->ima, &tex->iuser, false), &trgb);
- }
- else {
- if (tex->type == TEX_ENVMAP)
- GPU_link(mat, "mtex_cube_map", texco, GPU_cube_map(tex->ima, &tex->iuser, false), &tin, &trgb);
- else if (tex->type == TEX_IMAGE)
- GPU_link(mat, "mtex_image", texco, GPU_image(tex->ima, &tex->iuser, false), &tin, &trgb);
- }
- rgbnor = TEX_RGB;
- if (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)
- if (GPU_material_do_color_management(mat))
- GPU_link(mat, "srgb_to_linearrgb", trgb, &trgb);
- /* texture output */
- if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
- GPU_link(mat, "mtex_rgbtoint", trgb, &tin);
- rgbnor -= TEX_RGB;
- }
- if (mtex->texflag & MTEX_NEGATIVE) {
- if (rgbnor & TEX_RGB)
- GPU_link(mat, "mtex_rgb_invert", trgb, &trgb);
- else
- GPU_link(mat, "mtex_value_invert", tin, &tin);
- }
- if (mtex->texflag & MTEX_STENCIL) {
- if (rgbnor & TEX_RGB)
- GPU_link(mat, "mtex_rgb_stencil", stencil, trgb, &stencil, &trgb);
- else
- GPU_link(mat, "mtex_value_stencil", stencil, tin, &stencil, &tin);
- }
- else {
- if (rgbnor & TEX_RGB)
- GPU_link(mat, "mtex_alpha_multiply_value", trgb, stencil, &trgb);
- else
- GPU_link(mat, "math_multiply", stencil, tin, &tin);
- }
- /* color mapping */
- if (mtex->mapto & (WOMAP_HORIZ + WOMAP_ZENUP + WOMAP_ZENDOWN)) {
- if ((rgbnor & TEX_RGB) == 0)
- GPU_link(mat, "set_rgb", GPU_uniform(&mtex->r), &trgb);
- else
- GPU_link(mat, "mtex_alpha_from_col", trgb, &tin);
- GPU_link(mat, "set_rgb", trgb, &tcol);
- if (mtex->mapto & WOMAP_HORIZ) {
- texture_rgb_blend(mat, tcol, *hor, tin, GPU_uniform(&mtex->colfac), mtex->blendtype, hor);
- }
- if (mtex->mapto & (WOMAP_ZENUP + WOMAP_ZENDOWN)) {
- GPU_link(mat, "set_value_zero", &zenfac);
- if (wo->skytype & WO_SKYREAL) {
- if (mtex->mapto & WOMAP_ZENUP) {
- if (mtex->mapto & WOMAP_ZENDOWN) {
- GPU_link(mat, "world_zen_mapping", shi->view, GPU_uniform(&mtex->zenupfac),
- GPU_uniform(&mtex->zendownfac), &zenfac);
- }
- else {
- GPU_link(mat, "world_zen_mapping", shi->view, GPU_uniform(&mtex->zenupfac),
- GPU_uniform(&zero), &zenfac);
- }
- }
- else if (mtex->mapto & WOMAP_ZENDOWN) {
- GPU_link(mat, "world_zen_mapping", shi->view, GPU_uniform(&zero),
- GPU_uniform(&mtex->zendownfac), &zenfac);
- }
- }
- else {
- if (mtex->mapto & WOMAP_ZENUP)
- GPU_link(mat, "set_value", GPU_uniform(&mtex->zenupfac), &zenfac);
- else if (mtex->mapto & WOMAP_ZENDOWN)
- GPU_link(mat, "set_value", GPU_uniform(&mtex->zendownfac), &zenfac);
- }
- texture_rgb_blend(mat, tcol, *zen, tin, zenfac, mtex->blendtype, zen);
- }
- }
- if (mtex->mapto & WOMAP_BLEND && wo->skytype & WO_SKYBLEND) {
- if (rgbnor & TEX_RGB)
- GPU_link(mat, "mtex_rgbtoint", trgb, &tin);
- texture_value_blend(mat, GPU_uniform(&mtex->def_var), *blend, tin, GPU_uniform(&mtex->blendfac), mtex->blendtype, blend);
- }
- }
- }
+ return (mat->domain & GPU_DOMAIN_SURFACE);
}
-static void gpu_material_old_world(struct GPUMaterial *mat, struct World *wo)
+bool GPU_material_use_domain_volume(GPUMaterial *mat)
{
- GPUShadeInput shi;
- GPUShadeResult shr;
- GPUNodeLink *hor, *zen, *ray, *blend;
-
- shi.gpumat = mat;
+ return (mat->domain & GPU_DOMAIN_VOLUME);
+}
- for (int i = 0; i < MAX_MTEX; i++) {
- if (wo->mtex[i] && wo->mtex[i]->tex) {
- wo->skytype |= WO_SKYTEX;
- break;
- }
- }
- if ((wo->skytype & (WO_SKYBLEND + WO_SKYTEX)) == 0) {
- GPU_link(mat, "set_rgb", GPU_dynamic_uniform(&wo->horr, GPU_DYNAMIC_HORIZON_COLOR, NULL), &shr.combined);
- }
- else {
- GPU_link(mat, "set_rgb_zero", &shi.rgb);
- GPU_link(mat, "background_transform_to_world", GPU_builtin(GPU_VIEW_POSITION), &ray);
- if (wo->skytype & WO_SKYPAPER)
- GPU_link(mat, "world_paper_view", GPU_builtin(GPU_VIEW_POSITION), &shi.view);
- else
- GPU_link(mat, "shade_view", ray, &shi.view);
- if (wo->skytype & WO_SKYBLEND) {
- if (wo->skytype & WO_SKYPAPER) {
- if (wo->skytype & WO_SKYREAL)
- GPU_link(mat, "world_blend_paper_real", GPU_builtin(GPU_VIEW_POSITION), &blend);
- else
- GPU_link(mat, "world_blend_paper", GPU_builtin(GPU_VIEW_POSITION), &blend);
- }
- else {
- if (wo->skytype & WO_SKYREAL)
- GPU_link(mat, "world_blend_real", ray, &blend);
- else
- GPU_link(mat, "world_blend", ray, &blend);
- }
- }
- else {
- GPU_link(mat, "set_value_zero", &blend);
+GPUMaterial *GPU_material_from_nodetree_find(
+ ListBase *gpumaterials, const void *engine_type, int options)
+{
+ for (LinkData *link = gpumaterials->first; link; link = link->next) {
+ GPUMaterial *current_material = (GPUMaterial *)link->data;
+ if (current_material->engine_type == engine_type &&
+ current_material->options == options)
+ {
+ return current_material;
}
- GPU_link(mat, "set_rgb", GPU_dynamic_uniform(&wo->horr, GPU_DYNAMIC_HORIZON_COLOR, NULL), &hor);
- GPU_link(mat, "set_rgb", GPU_dynamic_uniform(&wo->zenr, GPU_DYNAMIC_ZENITH_COLOR, NULL), &zen);
- do_world_tex(&shi, wo, &hor, &zen, &blend);
- if (wo->skytype & WO_SKYBLEND)
- GPU_link(mat, "node_mix_shader", blend, hor, zen, &shi.rgb);
- else
- GPU_link(mat, "set_rgb", hor, &shi.rgb);
- GPU_link(mat, "set_rgb", shi.rgb, &shr.combined);
}
- GPU_material_output_link(mat, shr.combined);
+
+ return NULL;
}
-GPUMaterial *GPU_material_world(struct Scene *scene, struct World *wo)
+/**
+ * \note Caller must use #GPU_material_from_nodetree_find to re-use existing materials,
+ * This is enforced since constructing other arguments to this function may be expensive
+ * so only do this when they are needed.
+ */
+GPUMaterial *GPU_material_from_nodetree(
+ Scene *scene, struct bNodeTree *ntree, ListBase *gpumaterials, const void *engine_type, int options)
{
LinkData *link;
- GPUMaterial *mat;
+ bool has_volume_output, has_surface_output;
- for (link = wo->gpumaterial.first; link; link = link->next)
- if (((GPUMaterial *)link->data)->scene == scene)
- return link->data;
+ /* Caller must re-use materials. */
+ BLI_assert(GPU_material_from_nodetree_find(gpumaterials, engine_type, options) == NULL);
/* allocate material */
- mat = GPU_material_construct_begin(NULL);
+ GPUMaterial *mat = MEM_callocN(sizeof(GPUMaterial), "GPUMaterial");;
mat->scene = scene;
- mat->type = GPU_MATERIAL_TYPE_WORLD;
-
- /* create nodes */
- if (BKE_scene_use_new_shading_nodes(scene) && wo->nodetree && wo->use_nodes) {
- ntreeGPUMaterialNodes(wo->nodetree, mat, NODE_NEW_SHADING);
+ mat->engine_type = engine_type;
+ mat->options = options;
+
+ ntreeGPUMaterialNodes(ntree, mat, NODE_NEW_SHADING | NODE_NEWER_SHADING);
+ ntreeGPUMaterialDomain(ntree, &has_surface_output, &has_volume_output);
+
+ if (has_surface_output) {
+ mat->domain |= GPU_DOMAIN_SURFACE;
}
- else {
- gpu_material_old_world(mat, wo);
+ if (has_volume_output) {
+ mat->domain |= GPU_DOMAIN_VOLUME;
}
- if (GPU_material_do_color_management(mat))
- if (mat->outlink)
- GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink);
+ if (mat->outlink) {
+ /* Prune the unused nodes and extract attribs before compiling so the
+ * generated VBOs are ready to accept the future shader. */
+ GPU_nodes_prune(&mat->nodes, mat->outlink);
+ GPU_nodes_get_vertex_attributes(&mat->nodes, &mat->attribs);
+ mat->status = GPU_MAT_QUEUED;
+ }
- gpu_material_construct_end(mat, wo->id.name);
-
/* note that even if building the shader fails in some way, we still keep
* it to avoid trying to compile again and again, and simple do not use
* the actual shader on drawing */
link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink");
link->data = mat;
- BLI_addtail(&wo->gpumaterial, link);
+ BLI_addtail(gpumaterials, link);
return mat;
}
-
-GPUMaterial *GPU_material_from_blender(Scene *scene, Material *ma, bool use_opensubdiv)
+void GPU_material_generate_pass(
+ GPUMaterial *mat, const char *vert_code, const char *geom_code, const char *frag_lib, const char *defines)
{
- GPUMaterial *mat;
- GPUNodeLink *outlink;
- LinkData *link;
-
- for (link = ma->gpumaterial.first; link; link = link->next) {
- GPUMaterial *current_material = (GPUMaterial *)link->data;
- if (current_material->scene == scene &&
- current_material->is_opensubdiv == use_opensubdiv)
- {
- return current_material;
- }
- }
-
- /* allocate material */
- mat = GPU_material_construct_begin(ma);
- mat->scene = scene;
- mat->type = GPU_MATERIAL_TYPE_MESH;
- mat->is_opensubdiv = use_opensubdiv;
-
- /* render pipeline option */
- bool new_shading_nodes = BKE_scene_use_new_shading_nodes(scene);
- if (!new_shading_nodes && (ma->mode & MA_TRANSP))
- GPU_material_enable_alpha(mat);
- else if (new_shading_nodes && ma->alpha < 1.0f)
- GPU_material_enable_alpha(mat);
-
- if (!(scene->gm.flag & GAME_GLSL_NO_NODES) && ma->nodetree && ma->use_nodes) {
- /* create nodes */
- if (new_shading_nodes)
- ntreeGPUMaterialNodes(ma->nodetree, mat, NODE_NEW_SHADING);
- else
- ntreeGPUMaterialNodes(ma->nodetree, mat, NODE_OLD_SHADING);
+ BLI_assert(mat->pass == NULL); /* Only run once! */
+ if (mat->outlink) {
+ mat->pass = GPU_generate_pass_new(
+ mat, mat->outlink, &mat->attribs, &mat->nodes, &mat->inputs, vert_code, geom_code, frag_lib, defines);
+ mat->status = (mat->pass) ? GPU_MAT_SUCCESS : GPU_MAT_FAILED;
}
else {
- if (new_shading_nodes) {
- /* create simple diffuse material instead of nodes */
- outlink = gpu_material_diffuse_bsdf(mat, ma);
- }
- else {
- /* create blender material */
- outlink = GPU_blender_material(mat, ma);
- }
-
- GPU_material_output_link(mat, outlink);
+ mat->status = GPU_MAT_FAILED;
}
-
- if (GPU_material_do_color_management(mat))
- if (mat->outlink)
- GPU_link(mat, "linearrgb_to_srgb", mat->outlink, &mat->outlink);
-
- gpu_material_construct_end(mat, ma->id.name);
-
- /* note that even if building the shader fails in some way, we still keep
- * it to avoid trying to compile again and again, and simple do not use
- * the actual shader on drawing */
-
- link = MEM_callocN(sizeof(LinkData), "GPUMaterialLink");
- link->data = mat;
- BLI_addtail(&ma->gpumaterial, link);
-
- return mat;
}
void GPU_materials_free(void)
{
- Object *ob;
Material *ma;
World *wo;
extern Material defmaterial;
@@ -2230,684 +673,4 @@ void GPU_materials_free(void)
GPU_material_free(&wo->gpumaterial);
GPU_material_free(&defmaterial.gpumaterial);
-
- for (ob = G.main->object.first; ob; ob = ob->id.next)
- GPU_lamp_free(ob);
-}
-
-/* Lamps and shadow buffers */
-
-static void gpu_lamp_calc_winmat(GPULamp *lamp)
-{
- float temp, angle, pixsize, wsize;
-
- if (lamp->type == LA_SUN) {
- wsize = lamp->la->shadow_frustum_size;
- orthographic_m4(lamp->winmat, -wsize, wsize, -wsize, wsize, lamp->d, lamp->clipend);
- }
- else if (lamp->type == LA_SPOT) {
- angle = saacos(lamp->spotsi);
- temp = 0.5f * lamp->size * cosf(angle) / sinf(angle);
- pixsize = lamp->d / temp;
- wsize = pixsize * 0.5f * lamp->size;
- /* compute shadows according to X and Y scaling factors */
- perspective_m4(
- lamp->winmat,
- -wsize * lamp->spotvec[0], wsize * lamp->spotvec[0],
- -wsize * lamp->spotvec[1], wsize * lamp->spotvec[1],
- lamp->d, lamp->clipend);
- }
-}
-
-void GPU_lamp_update(GPULamp *lamp, int lay, int hide, float obmat[4][4])
-{
- float mat[4][4];
- float obmat_scale[3];
-
- lamp->lay = lay;
- lamp->hide = hide;
-
- normalize_m4_m4_ex(mat, obmat, obmat_scale);
-
- copy_v3_v3(lamp->vec, mat[2]);
- copy_v3_v3(lamp->co, mat[3]);
- copy_m4_m4(lamp->obmat, mat);
- invert_m4_m4(lamp->imat, mat);
-
- if (lamp->type == LA_SPOT) {
- /* update spotlamp scale on X and Y axis */
- lamp->spotvec[0] = obmat_scale[0] / obmat_scale[2];
- lamp->spotvec[1] = obmat_scale[1] / obmat_scale[2];
- }
-
- if (GPU_lamp_has_shadow_buffer(lamp)) {
- /* makeshadowbuf */
- gpu_lamp_calc_winmat(lamp);
- }
-}
-
-void GPU_lamp_update_colors(GPULamp *lamp, float r, float g, float b, float energy)
-{
- lamp->energy = energy;
- if (lamp->mode & LA_NEG) lamp->energy = -lamp->energy;
-
- lamp->col[0] = r;
- lamp->col[1] = g;
- lamp->col[2] = b;
-}
-
-void GPU_lamp_update_distance(GPULamp *lamp, float distance, float att1, float att2,
- float coeff_const, float coeff_lin, float coeff_quad)
-{
- lamp->dist = distance;
- lamp->att1 = att1;
- lamp->att2 = att2;
- lamp->coeff_const = coeff_const;
- lamp->coeff_lin = coeff_lin;
- lamp->coeff_quad = coeff_quad;
}
-
-void GPU_lamp_update_spot(GPULamp *lamp, float spotsize, float spotblend)
-{
- lamp->spotsi = cosf(spotsize * 0.5f);
- lamp->spotbl = (1.0f - lamp->spotsi) * spotblend;
-}
-
-static void gpu_lamp_from_blender(Scene *scene, Object *ob, Object *par, Lamp *la, GPULamp *lamp)
-{
- lamp->scene = scene;
- lamp->ob = ob;
- lamp->par = par;
- lamp->la = la;
-
- /* add_render_lamp */
- lamp->mode = la->mode;
- lamp->type = la->type;
-
- lamp->energy = la->energy;
- if (lamp->mode & LA_NEG) lamp->energy = -lamp->energy;
-
- lamp->col[0] = la->r;
- lamp->col[1] = la->g;
- lamp->col[2] = la->b;
-
- GPU_lamp_update(lamp, ob->lay, (ob->restrictflag & OB_RESTRICT_RENDER), ob->obmat);
-
- lamp->spotsi = la->spotsize;
- if (lamp->mode & LA_HALO)
- if (lamp->spotsi > DEG2RADF(170.0f))
- lamp->spotsi = DEG2RADF(170.0f);
- lamp->spotsi = cosf(lamp->spotsi * 0.5f);
- lamp->spotbl = (1.0f - lamp->spotsi) * la->spotblend;
- lamp->k = la->k;
-
- lamp->dist = la->dist;
- lamp->falloff_type = la->falloff_type;
- lamp->att1 = la->att1;
- lamp->att2 = la->att2;
- lamp->coeff_const = la->coeff_const;
- lamp->coeff_lin = la->coeff_lin;
- lamp->coeff_quad = la->coeff_quad;
- lamp->curfalloff = la->curfalloff;
-
- /* initshadowbuf */
- lamp->bias = 0.02f * la->bias;
- lamp->size = la->bufsize;
- lamp->d = la->clipsta;
- lamp->clipend = la->clipend;
-
- /* arbitrary correction for the fact we do no soft transition */
- lamp->bias *= 0.25f;
-}
-
-static void gpu_lamp_shadow_free(GPULamp *lamp)
-{
- if (lamp->tex) {
- GPU_texture_free(lamp->tex);
- lamp->tex = NULL;
- }
- if (lamp->depthtex) {
- GPU_texture_free(lamp->depthtex);
- lamp->depthtex = NULL;
- }
- if (lamp->fb) {
- GPU_framebuffer_free(lamp->fb);
- lamp->fb = NULL;
- }
- if (lamp->blurtex) {
- GPU_texture_free(lamp->blurtex);
- lamp->blurtex = NULL;
- }
- if (lamp->blurfb) {
- GPU_framebuffer_free(lamp->blurfb);
- lamp->blurfb = NULL;
- }
-}
-
-GPULamp *GPU_lamp_from_blender(Scene *scene, Object *ob, Object *par)
-{
- Lamp *la;
- GPULamp *lamp;
- LinkData *link;
-
- for (link = ob->gpulamp.first; link; link = link->next) {
- lamp = (GPULamp *)link->data;
-
- if (lamp->par == par && lamp->scene == scene)
- return link->data;
- }
-
- lamp = MEM_callocN(sizeof(GPULamp), "GPULamp");
-
- link = MEM_callocN(sizeof(LinkData), "GPULampLink");
- link->data = lamp;
- BLI_addtail(&ob->gpulamp, link);
-
- la = ob->data;
- gpu_lamp_from_blender(scene, ob, par, la, lamp);
-
- if ((la->type == LA_SPOT && (la->mode & (LA_SHAD_BUF | LA_SHAD_RAY))) ||
- (la->type == LA_SUN && (la->mode & LA_SHAD_RAY)))
- {
- /* opengl */
- lamp->fb = GPU_framebuffer_create();
- if (!lamp->fb) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE) {
- /* Shadow depth map */
- lamp->depthtex = GPU_texture_create_depth(lamp->size, lamp->size, NULL);
- if (!lamp->depthtex) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- if (!GPU_framebuffer_texture_attach(lamp->fb, lamp->depthtex, 0, NULL)) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- /* Shadow color map */
- lamp->tex = GPU_texture_create_vsm_shadow_map(lamp->size, NULL);
- if (!lamp->tex) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- if (!GPU_framebuffer_texture_attach(lamp->fb, lamp->tex, 0, NULL)) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- if (!GPU_framebuffer_check_valid(lamp->fb, NULL)) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- /* FBO and texture for blurring */
- lamp->blurfb = GPU_framebuffer_create();
- if (!lamp->blurfb) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- lamp->blurtex = GPU_texture_create_vsm_shadow_map(lamp->size * 0.5, NULL);
- if (!lamp->blurtex) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- if (!GPU_framebuffer_texture_attach(lamp->blurfb, lamp->blurtex, 0, NULL)) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- /* we need to properly bind to test for completeness */
- GPU_texture_bind_as_framebuffer(lamp->blurtex);
-
- if (!GPU_framebuffer_check_valid(lamp->blurfb, NULL)) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- GPU_framebuffer_texture_unbind(lamp->blurfb, lamp->blurtex);
- }
- else {
- lamp->tex = GPU_texture_create_depth(lamp->size, lamp->size, NULL);
- if (!lamp->tex) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- if (!GPU_framebuffer_texture_attach(lamp->fb, lamp->tex, 0, NULL)) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
-
- if (!GPU_framebuffer_check_valid(lamp->fb, NULL)) {
- gpu_lamp_shadow_free(lamp);
- return lamp;
- }
- }
-
- GPU_framebuffer_restore();
-
- lamp->shadow_color[0] = la->shdwr;
- lamp->shadow_color[1] = la->shdwg;
- lamp->shadow_color[2] = la->shdwb;
- }
- else {
- lamp->shadow_color[0] = 1.0;
- lamp->shadow_color[1] = 1.0;
- lamp->shadow_color[2] = 1.0;
- }
-
- return lamp;
-}
-
-void GPU_lamp_free(Object *ob)
-{
- GPULamp *lamp;
- LinkData *link;
- LinkData *nlink;
- Material *ma;
-
- for (link = ob->gpulamp.first; link; link = link->next) {
- lamp = link->data;
-
- while (lamp->materials.first) {
- nlink = lamp->materials.first;
- ma = nlink->data;
- BLI_freelinkN(&lamp->materials, nlink);
-
- if (ma->gpumaterial.first)
- GPU_material_free(&ma->gpumaterial);
- }
-
- gpu_lamp_shadow_free(lamp);
-
- MEM_freeN(lamp);
- }
-
- BLI_freelistN(&ob->gpulamp);
-}
-
-bool GPU_lamp_has_shadow_buffer(GPULamp *lamp)
-{
- return (!(lamp->scene->gm.flag & GAME_GLSL_NO_SHADOWS) &&
- !(lamp->scene->gm.flag & GAME_GLSL_NO_LIGHTS) &&
- lamp->tex && lamp->fb);
-}
-
-void GPU_lamp_update_buffer_mats(GPULamp *lamp)
-{
- float rangemat[4][4], persmat[4][4];
-
- /* initshadowbuf */
- invert_m4_m4(lamp->viewmat, lamp->obmat);
- normalize_v3(lamp->viewmat[0]);
- normalize_v3(lamp->viewmat[1]);
- normalize_v3(lamp->viewmat[2]);
-
- /* makeshadowbuf */
- mul_m4_m4m4(persmat, lamp->winmat, lamp->viewmat);
-
- /* opengl depth buffer is range 0.0..1.0 instead of -1.0..1.0 in blender */
- unit_m4(rangemat);
- rangemat[0][0] = 0.5f;
- rangemat[1][1] = 0.5f;
- rangemat[2][2] = 0.5f;
- rangemat[3][0] = 0.5f;
- rangemat[3][1] = 0.5f;
- rangemat[3][2] = 0.5f;
-
- mul_m4_m4m4(lamp->persmat, rangemat, persmat);
-}
-
-void GPU_lamp_shadow_buffer_bind(GPULamp *lamp, float viewmat[4][4], int *winsize, float winmat[4][4])
-{
- GPU_lamp_update_buffer_mats(lamp);
-
- /* opengl */
- glDisable(GL_SCISSOR_TEST);
- GPU_texture_bind_as_framebuffer(lamp->tex);
- if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE)
- GPU_shader_bind(GPU_shader_get_builtin_shader(GPU_SHADER_VSM_STORE));
-
- /* set matrices */
- copy_m4_m4(viewmat, lamp->viewmat);
- copy_m4_m4(winmat, lamp->winmat);
- *winsize = lamp->size;
-}
-
-void GPU_lamp_shadow_buffer_unbind(GPULamp *lamp)
-{
- if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE) {
- GPU_shader_unbind();
- GPU_framebuffer_blur(lamp->fb, lamp->tex, lamp->blurfb, lamp->blurtex);
- }
-
- GPU_framebuffer_texture_unbind(lamp->fb, lamp->tex);
- GPU_framebuffer_restore();
- glEnable(GL_SCISSOR_TEST);
-}
-
-int GPU_lamp_shadow_buffer_type(GPULamp *lamp)
-{
- return lamp->la->shadowmap_type;
-}
-
-int GPU_lamp_shadow_bind_code(GPULamp *lamp)
-{
- return lamp->tex ? GPU_texture_opengl_bindcode(lamp->tex) : -1;
-}
-
-float *GPU_lamp_dynpersmat(GPULamp *lamp)
-{
- return &lamp->dynpersmat[0][0];
-}
-
-int GPU_lamp_shadow_layer(GPULamp *lamp)
-{
- if (lamp->fb && lamp->tex && (lamp->mode & (LA_LAYER | LA_LAYER_SHADOW)))
- return lamp->lay;
- else
- return -1;
-}
-
-GPUNodeLink *GPU_lamp_get_data(
- GPUMaterial *mat, GPULamp *lamp,
- GPUNodeLink **r_col, GPUNodeLink **r_lv, GPUNodeLink **r_dist, GPUNodeLink **r_shadow, GPUNodeLink **r_energy)
-{
- GPUNodeLink *visifac;
-
- *r_col = GPU_dynamic_uniform(lamp->dyncol, GPU_DYNAMIC_LAMP_DYNCOL, lamp->ob);
- *r_energy = GPU_dynamic_uniform(&lamp->dynenergy, GPU_DYNAMIC_LAMP_DYNENERGY, lamp->ob);
- visifac = lamp_get_visibility(mat, lamp, r_lv, r_dist);
-
- shade_light_textures(mat, lamp, r_col);
-
- if (GPU_lamp_has_shadow_buffer(lamp)) {
- GPUNodeLink *vn, *inp;
-
- GPU_link(mat, "shade_norm", GPU_builtin(GPU_VIEW_NORMAL), &vn);
- GPU_link(mat, "shade_inp", vn, *r_lv, &inp);
- mat->dynproperty |= DYN_LAMP_PERSMAT;
-
- if (lamp->la->shadowmap_type == LA_SHADMAP_VARIANCE) {
- GPU_link(mat, "shadows_only_vsm",
- GPU_builtin(GPU_VIEW_POSITION),
- GPU_dynamic_texture(lamp->tex, GPU_DYNAMIC_SAMPLER_2DSHADOW, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
- GPU_uniform(&lamp->bias), GPU_uniform(&lamp->la->bleedbias),
- GPU_uniform(lamp->shadow_color), inp, r_shadow);
- }
- else {
- GPU_link(mat, "shadows_only",
- GPU_builtin(GPU_VIEW_POSITION),
- GPU_dynamic_texture(lamp->tex, GPU_DYNAMIC_SAMPLER_2DSHADOW, lamp->ob),
- GPU_dynamic_uniform((float *)lamp->dynpersmat, GPU_DYNAMIC_LAMP_DYNPERSMAT, lamp->ob),
- GPU_uniform(&lamp->bias), GPU_uniform(lamp->shadow_color), inp, r_shadow);
- }
- }
- else {
- GPU_link(mat, "set_rgb_one", r_shadow);
- }
-
- /* ensure shadow buffer and lamp textures will be updated */
- add_user_list(&mat->lamps, lamp);
- add_user_list(&lamp->materials, mat->ma);
-
- return visifac;
-}
-
-/* export the GLSL shader */
-
-GPUShaderExport *GPU_shader_export(struct Scene *scene, struct Material *ma)
-{
- static struct {
- GPUBuiltin gputype;
- GPUDynamicType dynamictype;
- GPUDataType datatype;
- } builtins[] = {
- { GPU_VIEW_MATRIX, GPU_DYNAMIC_OBJECT_VIEWMAT, GPU_DATA_16F },
- { GPU_INVERSE_VIEW_MATRIX, GPU_DYNAMIC_OBJECT_VIEWIMAT, GPU_DATA_16F },
- { GPU_OBJECT_MATRIX, GPU_DYNAMIC_OBJECT_MAT, GPU_DATA_16F },
- { GPU_INVERSE_OBJECT_MATRIX, GPU_DYNAMIC_OBJECT_IMAT, GPU_DATA_16F },
- { GPU_LOC_TO_VIEW_MATRIX, GPU_DYNAMIC_OBJECT_LOCTOVIEWMAT, GPU_DATA_16F },
- { GPU_INVERSE_LOC_TO_VIEW_MATRIX, GPU_DYNAMIC_OBJECT_LOCTOVIEWIMAT, GPU_DATA_16F },
- { GPU_OBCOLOR, GPU_DYNAMIC_OBJECT_COLOR, GPU_DATA_4F },
- { GPU_AUTO_BUMPSCALE, GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE, GPU_DATA_1F },
- { 0 }
- };
-
- GPUShaderExport *shader = NULL;
- GPUInput *input;
- int liblen, fraglen;
-
- /* TODO(sergey): How to determine whether we need OSD or not here? */
- GPUMaterial *mat = GPU_material_from_blender(scene, ma, false);
- GPUPass *pass = (mat) ? mat->pass : NULL;
-
- if (pass && pass->fragmentcode && pass->vertexcode) {
- shader = MEM_callocN(sizeof(GPUShaderExport), "GPUShaderExport");
-
- for (input = pass->inputs.first; input; input = input->next) {
- GPUInputUniform *uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform");
-
- if (input->ima) {
- /* image sampler uniform */
- uniform->type = GPU_DYNAMIC_SAMPLER_2DIMAGE;
- uniform->datatype = GPU_DATA_1I;
- uniform->image = input->ima;
- uniform->texnumber = input->texid;
- BLI_strncpy(uniform->varname, input->shadername, sizeof(uniform->varname));
- }
- else if (input->tex) {
- /* generated buffer */
- uniform->texnumber = input->texid;
- uniform->datatype = GPU_DATA_1I;
- BLI_strncpy(uniform->varname, input->shadername, sizeof(uniform->varname));
-
- switch (input->textype) {
- case GPU_SHADOW2D:
- uniform->type = GPU_DYNAMIC_SAMPLER_2DSHADOW;
- uniform->lamp = input->dynamicdata;
- break;
- case GPU_TEX2D:
- if (GPU_texture_opengl_bindcode(input->tex)) {
- uniform->type = GPU_DYNAMIC_SAMPLER_2DBUFFER;
- glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(input->tex));
- uniform->texsize = GPU_texture_width(input->tex) * GPU_texture_height(input->tex);
- uniform->texpixels = MEM_mallocN(uniform->texsize * 4, "RGBApixels");
- glGetTexImage(GL_TEXTURE_2D, 0, GL_RGBA, GL_UNSIGNED_BYTE, uniform->texpixels);
- glBindTexture(GL_TEXTURE_2D, 0);
- }
- break;
-
- case GPU_NONE:
- case GPU_TEXCUBE:
- case GPU_FLOAT:
- case GPU_VEC2:
- case GPU_VEC3:
- case GPU_VEC4:
- case GPU_MAT3:
- case GPU_MAT4:
- case GPU_ATTRIB:
- break;
- }
- }
- else {
- uniform->type = input->dynamictype;
- BLI_strncpy(uniform->varname, input->shadername, sizeof(uniform->varname));
- switch (input->type) {
- case GPU_FLOAT:
- uniform->datatype = GPU_DATA_1F;
- break;
- case GPU_VEC2:
- uniform->datatype = GPU_DATA_2F;
- break;
- case GPU_VEC3:
- uniform->datatype = GPU_DATA_3F;
- break;
- case GPU_VEC4:
- uniform->datatype = GPU_DATA_4F;
- break;
- case GPU_MAT3:
- uniform->datatype = GPU_DATA_9F;
- break;
- case GPU_MAT4:
- uniform->datatype = GPU_DATA_16F;
- break;
-
- case GPU_NONE:
- case GPU_TEX2D:
- case GPU_TEXCUBE:
- case GPU_SHADOW2D:
- case GPU_ATTRIB:
- break;
- }
-
- if (GPU_DYNAMIC_GROUP_FROM_TYPE(uniform->type) == GPU_DYNAMIC_GROUP_LAMP)
- uniform->lamp = input->dynamicdata;
-
- if (GPU_DYNAMIC_GROUP_FROM_TYPE(uniform->type) == GPU_DYNAMIC_GROUP_MAT)
- uniform->material = input->dynamicdata;
- }
-
- if (uniform->type != GPU_DYNAMIC_NONE)
- BLI_addtail(&shader->uniforms, uniform);
- else
- MEM_freeN(uniform);
- }
-
- /* process builtin uniform */
- for (int i = 0; builtins[i].gputype; i++) {
- if (mat->builtins & builtins[i].gputype) {
- GPUInputUniform *uniform = MEM_callocN(sizeof(GPUInputUniform), "GPUInputUniform");
- uniform->type = builtins[i].dynamictype;
- uniform->datatype = builtins[i].datatype;
- BLI_strncpy(uniform->varname, GPU_builtin_name(builtins[i].gputype), sizeof(uniform->varname));
- BLI_addtail(&shader->uniforms, uniform);
- }
- }
-
- /* now link fragment shader with library shader */
- /* TBD: remove the function that are not used in the main function */
- liblen = (pass->libcode) ? strlen(pass->libcode) : 0;
- fraglen = strlen(pass->fragmentcode);
- shader->fragment = (char *)MEM_mallocN(liblen + fraglen + 1, "GPUFragShader");
- if (pass->libcode)
- memcpy(shader->fragment, pass->libcode, liblen);
- memcpy(&shader->fragment[liblen], pass->fragmentcode, fraglen);
- shader->fragment[liblen + fraglen] = 0;
-
- // export the attribute
- for (int i = 0; i < mat->attribs.totlayer; i++) {
- GPUInputAttribute *attribute = MEM_callocN(sizeof(GPUInputAttribute), "GPUInputAttribute");
- attribute->type = mat->attribs.layer[i].type;
- attribute->number = mat->attribs.layer[i].glindex;
- BLI_snprintf(attribute->varname, sizeof(attribute->varname), "att%d", mat->attribs.layer[i].attribid);
-
- switch (attribute->type) {
- case CD_TANGENT:
- attribute->datatype = GPU_DATA_4F;
- break;
- case CD_MTFACE:
- attribute->datatype = GPU_DATA_2F;
- attribute->name = mat->attribs.layer[i].name;
- break;
- case CD_MCOL:
- attribute->datatype = GPU_DATA_4UB;
- attribute->name = mat->attribs.layer[i].name;
- break;
- case CD_ORCO:
- attribute->datatype = GPU_DATA_3F;
- break;
- }
-
- if (attribute->datatype != GPU_DATA_NONE)
- BLI_addtail(&shader->attributes, attribute);
- else
- MEM_freeN(attribute);
- }
-
- /* export the vertex shader */
- shader->vertex = BLI_strdup(pass->vertexcode);
- }
-
- return shader;
-}
-
-void GPU_free_shader_export(GPUShaderExport *shader)
-{
- if (shader == NULL)
- return;
-
- for (GPUInputUniform *uniform = shader->uniforms.first; uniform; uniform = uniform->next)
- if (uniform->texpixels)
- MEM_freeN(uniform->texpixels);
-
- BLI_freelistN(&shader->uniforms);
- BLI_freelistN(&shader->attributes);
-
- if (shader->vertex)
- MEM_freeN(shader->vertex);
- if (shader->fragment)
- MEM_freeN(shader->fragment);
-
- MEM_freeN(shader);
-}
-
-#ifdef WITH_OPENSUBDIV
-void GPU_material_update_fvar_offset(GPUMaterial *gpu_material,
- DerivedMesh *dm)
-{
- GPUPass *pass = gpu_material->pass;
- GPUShader *shader = (pass != NULL ? pass->shader : NULL);
- ListBase *inputs = (pass != NULL ? &pass->inputs : NULL);
- GPUInput *input;
-
- if (shader == NULL) {
- return;
- }
-
- GPU_shader_bind(shader);
-
- for (input = inputs->first;
- input != NULL;
- input = input->next)
- {
- if (input->source == GPU_SOURCE_ATTRIB &&
- input->attribtype == CD_MTFACE)
- {
- char name[64];
- /* TODO(sergey): This will work for until names are
- * consistent, we'll need to solve this somehow in the future.
- */
- int layer_index;
- int location;
-
- if (input->attribname[0] != '\0') {
- layer_index = CustomData_get_named_layer(&dm->loopData,
- CD_MLOOPUV,
- input->attribname);
- }
- else {
- layer_index = CustomData_get_active_layer(&dm->loopData,
- CD_MLOOPUV);
- }
-
- BLI_snprintf(name, sizeof(name),
- "fvar%d_offset",
- input->attribid);
- location = GPU_shader_get_uniform(shader, name);
- GPU_shader_uniform_int(shader, location, layer_index);
- }
- }
-
- GPU_shader_unbind();
-}
-#endif
diff --git a/source/blender/gpu/intern/gpu_matrix.c b/source/blender/gpu/intern/gpu_matrix.c
new file mode 100644
index 00000000000..b6214f2778b
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_matrix.c
@@ -0,0 +1,649 @@
+/*
+ * ***** 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 ipmlied 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2012 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Alexandr Kuznetsov, Jason Wilkins, Mike Erwin
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file source/blender/gpu/intern/gpu_matrix.c
+ * \ingroup gpu
+ */
+
+#include "../../../intern/gawain/gawain/gwn_shader_interface.h"
+
+#define SUPPRESS_GENERIC_MATRIX_API
+#define USE_GPU_PY_MATRIX_API /* only so values are declared */
+#include "GPU_matrix.h"
+#undef USE_GPU_PY_MATRIX_API
+
+#include "BLI_math_matrix.h"
+#include "BLI_math_rotation.h"
+#include "BLI_math_vector.h"
+
+
+#define DEBUG_MATRIX_BIND 0
+
+#define MATRIX_STACK_DEPTH 32
+
+typedef float Mat4[4][4];
+typedef float Mat3[3][3];
+
+typedef struct MatrixStack {
+ Mat4 stack[MATRIX_STACK_DEPTH];
+ unsigned int top;
+} MatrixStack;
+
+typedef struct {
+ MatrixStack model_view_stack;
+ MatrixStack projection_stack;
+
+ bool dirty;
+
+ /* TODO: cache of derived matrices (Normal, MVP, inverse MVP, etc)
+ * generate as needed for shaders, invalidate when original matrices change
+ *
+ * TODO: separate Model from View transform? Batches/objects have model,
+ * camera/eye has view & projection
+ */
+} MatrixState;
+
+#define MATRIX_4X4_IDENTITY {{1.0f, 0.0f, 0.0f, 0.0f}, \
+ {0.0f, 1.0f, 0.0f, 0.0f}, \
+ {0.0f, 0.0f, 1.0f, 0.0f}, \
+ {0.0f, 0.0f, 0.0f, 1.0f}}
+
+static MatrixState state = {
+ .model_view_stack = {{MATRIX_4X4_IDENTITY}, 0},
+ .projection_stack = {{MATRIX_4X4_IDENTITY}, 0},
+ .dirty = true
+};
+
+#undef MATRIX_4X4_IDENTITY
+
+#define ModelViewStack state.model_view_stack
+#define ModelView ModelViewStack.stack[ModelViewStack.top]
+
+#define ProjectionStack state.projection_stack
+#define Projection ProjectionStack.stack[ProjectionStack.top]
+
+void gpuMatrixReset(void)
+{
+ state.model_view_stack.top = 0;
+ state.projection_stack.top = 0;
+ unit_m4(ModelView);
+ unit_m4(Projection);
+ state.dirty = true;
+}
+
+#ifdef WITH_GPU_SAFETY
+
+/* Check if matrix is numerically good */
+static void checkmat(cosnt float *m)
+{
+ const int n = 16;
+ for (int i = 0; i < n; i++) {
+#if _MSC_VER
+ BLI_assert(_finite(m[i]));
+#else
+ BLI_assert(!isinf(m[i]));
+#endif
+ }
+}
+
+#define CHECKMAT(m) checkmat((const float*)m)
+
+#else
+
+#define CHECKMAT(m)
+
+#endif
+
+
+void gpuPushMatrix(void)
+{
+ BLI_assert(ModelViewStack.top + 1 < MATRIX_STACK_DEPTH);
+ ModelViewStack.top++;
+ copy_m4_m4(ModelView, ModelViewStack.stack[ModelViewStack.top - 1]);
+}
+
+void gpuPopMatrix(void)
+{
+ BLI_assert(ModelViewStack.top > 0);
+ ModelViewStack.top--;
+ state.dirty = true;
+}
+
+void gpuPushProjectionMatrix(void)
+{
+ BLI_assert(ProjectionStack.top + 1 < MATRIX_STACK_DEPTH);
+ ProjectionStack.top++;
+ copy_m4_m4(Projection, ProjectionStack.stack[ProjectionStack.top - 1]);
+}
+
+void gpuPopProjectionMatrix(void)
+{
+ BLI_assert(ProjectionStack.top > 0);
+ ProjectionStack.top--;
+ state.dirty = true;
+}
+
+void gpuLoadMatrix(const float m[4][4])
+{
+ copy_m4_m4(ModelView, m);
+ CHECKMAT(ModelView3D);
+ state.dirty = true;
+}
+
+void gpuLoadIdentityProjectionMatrix(void)
+{
+ unit_m4(Projection);
+ CHECKMAT(Projection3D);
+ state.dirty = true;
+}
+
+void gpuLoadProjectionMatrix(const float m[4][4])
+{
+ copy_m4_m4(Projection, m);
+ CHECKMAT(Projection3D);
+ state.dirty = true;
+}
+
+void gpuLoadIdentity(void)
+{
+ unit_m4(ModelView);
+ state.dirty = true;
+}
+
+void gpuTranslate2f(float x, float y)
+{
+ Mat4 m;
+ unit_m4(m);
+ m[3][0] = x;
+ m[3][1] = y;
+ gpuMultMatrix(m);
+}
+
+void gpuTranslate2fv(const float vec[2])
+{
+ gpuTranslate2f(vec[0], vec[1]);
+}
+
+void gpuTranslate3f(float x, float y, float z)
+{
+#if 1
+ translate_m4(ModelView, x, y, z);
+ CHECKMAT(ModelView);
+#else /* above works well in early testing, below is generic version */
+ Mat4 m;
+ unit_m4(m);
+ m[3][0] = x;
+ m[3][1] = y;
+ m[3][2] = z;
+ gpuMultMatrix(m);
+#endif
+ state.dirty = true;
+}
+
+void gpuTranslate3fv(const float vec[3])
+{
+ gpuTranslate3f(vec[0], vec[1], vec[2]);
+}
+
+void gpuScaleUniform(float factor)
+{
+ Mat4 m;
+ scale_m4_fl(m, factor);
+ gpuMultMatrix(m);
+}
+
+void gpuScale2f(float x, float y)
+{
+ Mat4 m = {{0.0f}};
+ m[0][0] = x;
+ m[1][1] = y;
+ m[2][2] = 1.0f;
+ m[3][3] = 1.0f;
+ gpuMultMatrix(m);
+}
+
+void gpuScale2fv(const float vec[2])
+{
+ gpuScale2f(vec[0], vec[1]);
+}
+
+void gpuScale3f(float x, float y, float z)
+{
+ Mat4 m = {{0.0f}};
+ m[0][0] = x;
+ m[1][1] = y;
+ m[2][2] = z;
+ m[3][3] = 1.0f;
+ gpuMultMatrix(m);
+}
+
+void gpuScale3fv(const float vec[3])
+{
+ gpuScale3f(vec[0], vec[1], vec[2]);
+}
+
+void gpuMultMatrix(const float m[4][4])
+{
+ mul_m4_m4_post(ModelView, m);
+ CHECKMAT(ModelView);
+ state.dirty = true;
+}
+
+void gpuRotate2D(float deg)
+{
+ /* essentially RotateAxis('Z')
+ * TODO: simpler math for 2D case
+ */
+ rotate_m4(ModelView, 'Z', DEG2RADF(deg));
+}
+
+void gpuRotate3f(float deg, float x, float y, float z)
+{
+ const float axis[3] = {x, y, z};
+ gpuRotate3fv(deg, axis);
+}
+
+void gpuRotate3fv(float deg, const float axis[3])
+{
+ Mat4 m;
+ axis_angle_to_mat4(m, axis, DEG2RADF(deg));
+ gpuMultMatrix(m);
+}
+
+void gpuRotateAxis(float deg, char axis)
+{
+ /* rotate_m4 works in place */
+ rotate_m4(ModelView, axis, DEG2RADF(deg));
+ CHECKMAT(ModelView);
+ state.dirty = true;
+}
+
+static void mat4_ortho_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
+{
+ m[0][0] = 2.0f / (right - left);
+ m[1][0] = 0.0f;
+ m[2][0] = 0.0f;
+ m[3][0] = -(right + left) / (right - left);
+
+ m[0][1] = 0.0f;
+ m[1][1] = 2.0f / (top - bottom);
+ m[2][1] = 0.0f;
+ m[3][1] = -(top + bottom) / (top - bottom);
+
+ m[0][2] = 0.0f;
+ m[1][2] = 0.0f;
+ m[2][2] = -2.0f / (far - near);
+ m[3][2] = -(far + near) / (far - near);
+
+ m[0][3] = 0.0f;
+ m[1][3] = 0.0f;
+ m[2][3] = 0.0f;
+ m[3][3] = 1.0f;
+
+ state.dirty = true;
+}
+
+static void mat4_frustum_set(float m[4][4], float left, float right, float bottom, float top, float near, float far)
+{
+ m[0][0] = 2.0f * near / (right - left);
+ m[1][0] = 0.0f;
+ m[2][0] = (right + left) / (right - left);
+ m[3][0] = 0.0f;
+
+ m[0][1] = 0.0f;
+ m[1][1] = 2.0f * near / (top - bottom);
+ m[2][1] = (top + bottom) / (top - bottom);
+ m[3][1] = 0.0f;
+
+ m[0][2] = 0.0f;
+ m[1][2] = 0.0f;
+ m[2][2] = -(far + near) / (far - near);
+ m[3][2] = -2.0f * far * near / (far - near);
+
+ m[0][3] = 0.0f;
+ m[1][3] = 0.0f;
+ m[2][3] = -1.0f;
+ m[3][3] = 0.0f;
+
+ state.dirty = true;
+}
+
+static void mat4_look_from_origin(float m[4][4], float lookdir[3], float camup[3])
+{
+/* This function is loosely based on Mesa implementation.
+ *
+ * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
+ * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice including the dates of first publication and
+ * either this permission notice or a reference to
+ * http://oss.sgi.com/projects/FreeB/
+ * shall be included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+ * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+ * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+ * SOFTWARE.
+ *
+ * Except as contained in this notice, the name of Silicon Graphics, Inc.
+ * shall not be used in advertising or otherwise to promote the sale, use or
+ * other dealings in this Software without prior written authorization from
+ * Silicon Graphics, Inc.
+ */
+
+ float side[3];
+
+ normalize_v3(lookdir);
+
+ cross_v3_v3v3(side, lookdir, camup);
+
+ normalize_v3(side);
+
+ cross_v3_v3v3(camup, side, lookdir);
+
+ m[0][0] = side[0];
+ m[1][0] = side[1];
+ m[2][0] = side[2];
+ m[3][0] = 0.0f;
+
+ m[0][1] = camup[0];
+ m[1][1] = camup[1];
+ m[2][1] = camup[2];
+ m[3][1] = 0.0f;
+
+ m[0][2] = -lookdir[0];
+ m[1][2] = -lookdir[1];
+ m[2][2] = -lookdir[2];
+ m[3][2] = 0.0f;
+
+ m[0][3] = 0.0f;
+ m[1][3] = 0.0f;
+ m[2][3] = 0.0f;
+ m[3][3] = 1.0f;
+
+ state.dirty = true;
+}
+
+void gpuOrtho(float left, float right, float bottom, float top, float near, float far)
+{
+ mat4_ortho_set(Projection, left, right, bottom, top, near, far);
+ CHECKMAT(Projection);
+ state.dirty = true;
+}
+
+void gpuOrtho2D(float left, float right, float bottom, float top)
+{
+ Mat4 m;
+ mat4_ortho_set(m, left, right, bottom, top, -1.0f, 1.0f);
+ CHECKMAT(Projection2D);
+ state.dirty = true;
+}
+
+void gpuFrustum(float left, float right, float bottom, float top, float near, float far)
+{
+ mat4_frustum_set(Projection, left, right, bottom, top, near, far);
+ CHECKMAT(Projection);
+ state.dirty = true;
+}
+
+void gpuPerspective(float fovy, float aspect, float near, float far)
+{
+ float half_height = tanf(fovy * (float)(M_PI / 360.0)) * near;
+ float half_width = half_height * aspect;
+ gpuFrustum(-half_width, +half_width, -half_height, +half_height, near, far);
+}
+
+void gpuLookAt(float eyeX, float eyeY, float eyeZ, float centerX, float centerY, float centerZ, float upX, float upY, float upZ)
+{
+ Mat4 cm;
+ float lookdir[3];
+ float camup[3] = {upX, upY, upZ};
+
+ lookdir[0] = centerX - eyeX;
+ lookdir[1] = centerY - eyeY;
+ lookdir[2] = centerZ - eyeZ;
+
+ mat4_look_from_origin(cm, lookdir, camup);
+
+ gpuMultMatrix(cm);
+ gpuTranslate3f(-eyeX, -eyeY, -eyeZ);
+}
+
+void gpuProject(const float world[3], const float model[4][4], const float proj[4][4], const int view[4], float win[3])
+{
+ float v[4];
+
+ mul_v4_m4v3(v, model, world);
+ mul_m4_v4(proj, v);
+
+ if (v[3] != 0.0f) {
+ mul_v3_fl(v, 1.0f / v[3]);
+ }
+
+ win[0] = view[0] + (view[2] * (v[0] + 1)) * 0.5f;
+ win[1] = view[1] + (view[3] * (v[1] + 1)) * 0.5f;
+ win[2] = (v[2] + 1) * 0.5f;
+}
+
+bool gpuUnProject(const float win[3], const float model[4][4], const float proj[4][4], const int view[4], float world[3])
+{
+ float pm[4][4];
+ float in[4];
+ float out[4];
+
+ mul_m4_m4m4(pm, proj, model);
+
+ if (!invert_m4(pm)) {
+ zero_v3(world);
+ return false;
+ }
+
+ in[0] = win[0];
+ in[1] = win[1];
+ in[2] = win[2];
+ in[3] = 1;
+
+ /* Map x and y from window coordinates */
+ in[0] = (in[0] - view[0]) / view[2];
+ in[1] = (in[1] - view[1]) / view[3];
+
+ /* Map to range -1 to +1 */
+ in[0] = 2 * in[0] - 1;
+ in[1] = 2 * in[1] - 1;
+ in[2] = 2 * in[2] - 1;
+
+ mul_v4_m4v3(out, pm, in);
+
+ if (out[3] == 0.0f) {
+ copy_v3_v3(world, out);
+ return false;
+ }
+
+ mul_v3_v3fl(world, out, 1.0f / out[3]);
+ return true;
+}
+
+const float (*gpuGetModelViewMatrix(float m[4][4]))[4]
+{
+ if (m) {
+ copy_m4_m4(m, ModelView);
+ return m;
+ }
+ else {
+ return ModelView;
+ }
+}
+
+const float (*gpuGetProjectionMatrix(float m[4][4]))[4]
+{
+ if (m) {
+ copy_m4_m4(m, Projection);
+ return m;
+ }
+ else {
+ return Projection;
+ }
+}
+
+const float (*gpuGetModelViewProjectionMatrix(float m[4][4]))[4]
+{
+ if (m == NULL) {
+ static Mat4 temp;
+ m = temp;
+ }
+
+ mul_m4_m4m4(m, Projection, ModelView);
+ return m;
+}
+
+const float (*gpuGetNormalMatrix(float m[3][3]))[3]
+{
+ if (m == NULL) {
+ static Mat3 temp3;
+ m = temp3;
+ }
+
+ copy_m3_m4(m, (const float (*)[4])gpuGetModelViewMatrix(NULL));
+
+ invert_m3(m);
+ transpose_m3(m);
+
+ return m;
+}
+
+const float (*gpuGetNormalMatrixInverse(float m[3][3]))[3]
+{
+ if (m == NULL) {
+ static Mat3 temp3;
+ m = temp3;
+ }
+
+ gpuGetNormalMatrix(m);
+ invert_m3(m);
+
+ return m;
+}
+
+void gpuBindMatrices(const Gwn_ShaderInterface *shaderface)
+{
+ /* set uniform values to matrix stack values
+ * call this before a draw call if desired matrices are dirty
+ * call glUseProgram before this, as glUniform expects program to be bound
+ */
+
+ const Gwn_ShaderInput *MV = GWN_shaderinterface_uniform_builtin(shaderface, GWN_UNIFORM_MODELVIEW);
+ const Gwn_ShaderInput *P = GWN_shaderinterface_uniform_builtin(shaderface, GWN_UNIFORM_PROJECTION);
+ const Gwn_ShaderInput *MVP = GWN_shaderinterface_uniform_builtin(shaderface, GWN_UNIFORM_MVP);
+
+ const Gwn_ShaderInput *N = GWN_shaderinterface_uniform_builtin(shaderface, GWN_UNIFORM_NORMAL);
+ const Gwn_ShaderInput *MV_inv = GWN_shaderinterface_uniform_builtin(shaderface, GWN_UNIFORM_MODELVIEW_INV);
+ const Gwn_ShaderInput *P_inv = GWN_shaderinterface_uniform_builtin(shaderface, GWN_UNIFORM_PROJECTION_INV);
+
+ if (MV) {
+#if DEBUG_MATRIX_BIND
+ puts("setting MV matrix");
+#endif
+
+ glUniformMatrix4fv(MV->location, 1, GL_FALSE, (const float *)gpuGetModelViewMatrix(NULL));
+ }
+
+ if (P) {
+#if DEBUG_MATRIX_BIND
+ puts("setting P matrix");
+#endif
+
+ glUniformMatrix4fv(P->location, 1, GL_FALSE, (const float *)gpuGetProjectionMatrix(NULL));
+ }
+
+ if (MVP) {
+#if DEBUG_MATRIX_BIND
+ puts("setting MVP matrix");
+#endif
+
+ glUniformMatrix4fv(MVP->location, 1, GL_FALSE, (const float *)gpuGetModelViewProjectionMatrix(NULL));
+ }
+
+ if (N) {
+#if DEBUG_MATRIX_BIND
+ puts("setting normal matrix");
+#endif
+
+ glUniformMatrix3fv(N->location, 1, GL_FALSE, (const float *)gpuGetNormalMatrix(NULL));
+ }
+
+ if (MV_inv) {
+ Mat4 m;
+ gpuGetModelViewMatrix(m);
+ invert_m4(m);
+ glUniformMatrix4fv(MV_inv->location, 1, GL_FALSE, (const float *)m);
+ }
+
+ if (P_inv) {
+ Mat4 m;
+ gpuGetProjectionMatrix(m);
+ invert_m4(m);
+ glUniformMatrix4fv(P_inv->location, 1, GL_FALSE, (const float *)m);
+ }
+
+ state.dirty = false;
+}
+
+bool gpuMatricesDirty(void)
+{
+ return state.dirty;
+}
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Python API Helpers
+ * \{ */
+BLI_STATIC_ASSERT(GPU_PY_MATRIX_STACK_LEN + 1 == MATRIX_STACK_DEPTH, "define mismatch");
+
+/* Return int since caller is may subtract. */
+
+int GPU_matrix_stack_level_get_model_view(void)
+{
+ return (int)state.model_view_stack.top;
+}
+
+int GPU_matrix_stack_level_get_projection(void)
+{
+ return (int)state.projection_stack.top;
+}
+
+/** \} */
diff --git a/source/blender/gpu/intern/gpu_select.c b/source/blender/gpu/intern/gpu_select.c
index 291a552a041..7023e44d289 100644
--- a/source/blender/gpu/intern/gpu_select.c
+++ b/source/blender/gpu/intern/gpu_select.c
@@ -187,12 +187,7 @@ uint GPU_select_end(void)
*/
bool GPU_select_query_check_active(void)
{
- return ((U.gpu_select_method == USER_SELECT_USE_OCCLUSION_QUERY) ||
- ((U.gpu_select_method == USER_SELECT_AUTO) &&
- (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY) ||
- /* unsupported by nouveau, gallium 0.4, see: T47940 */
- GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_UNIX, GPU_DRIVER_OPENSOURCE))));
-
+ return ELEM(U.gpu_select_method, USER_SELECT_USE_OCCLUSION_QUERY, USER_SELECT_AUTO);
}
/* ----------------------------------------------------------------------------
@@ -232,3 +227,29 @@ bool GPU_select_is_cached(void)
{
return g_select_state.use_cache && gpu_select_pick_is_cached();
}
+
+
+/* ----------------------------------------------------------------------------
+ * Utilities
+ */
+
+/**
+ * Helper function, nothing special but avoids doing inline since hit's aren't sorted by depth
+ * and purpose of 4x buffer indices isn't so clear.
+ *
+ * Note that comparing depth as uint is fine.
+ */
+const uint *GPU_select_buffer_near(const uint *buffer, int hits)
+{
+ const uint *buffer_near = NULL;
+ uint depth_min = (uint)-1;
+ for (int i = 0; i < hits; i++) {
+ if (buffer[1] < depth_min) {
+ BLI_assert(buffer[3] != -1);
+ depth_min = buffer[1];
+ buffer_near = buffer;
+ }
+ buffer += 4;
+ }
+ return buffer_near;
+}
diff --git a/source/blender/gpu/intern/gpu_select_pick.c b/source/blender/gpu/intern/gpu_select_pick.c
index 3e65e2987e6..4aef80934ad 100644
--- a/source/blender/gpu/intern/gpu_select_pick.c
+++ b/source/blender/gpu/intern/gpu_select_pick.c
@@ -31,6 +31,8 @@
#include <stdlib.h>
#include <float.h>
+#include "GPU_immediate.h"
+#include "GPU_draw.h"
#include "GPU_select.h"
#include "GPU_extensions.h"
#include "GPU_glew.h"
@@ -316,8 +318,8 @@ void gpu_select_pick_begin(
/* Restrict OpenGL operations for when we don't have cache */
if (ps->is_cached == false) {
+ gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT);
- glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_VIEWPORT_BIT);
/* disable writing to the framebuffer */
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
@@ -334,10 +336,6 @@ void gpu_select_pick_begin(
glDepthFunc(GL_LEQUAL);
}
- /* set just in case */
- glPixelTransferf(GL_DEPTH_BIAS, 0.0);
- glPixelTransferf(GL_DEPTH_SCALE, 1.0);
-
float viewport[4];
glGetFloatv(GL_SCISSOR_BOX, viewport);
@@ -542,7 +540,7 @@ uint gpu_select_pick_end(void)
/* force finishing last pass */
gpu_select_pick_load_id(ps->gl.prev_id);
}
- glPopAttrib();
+ gpuPopAttrib();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
diff --git a/source/blender/gpu/intern/gpu_select_sample_query.c b/source/blender/gpu/intern/gpu_select_sample_query.c
index 9bb96ea67a2..12390e5cdb0 100644
--- a/source/blender/gpu/intern/gpu_select_sample_query.c
+++ b/source/blender/gpu/intern/gpu_select_sample_query.c
@@ -32,6 +32,8 @@
#include <stdlib.h>
+#include "GPU_immediate.h"
+#include "GPU_draw.h"
#include "GPU_select.h"
#include "GPU_extensions.h"
#include "GPU_glew.h"
@@ -42,6 +44,8 @@
#include "BLI_utildefines.h"
+#include "PIL_time.h"
+
#include "gpu_select_private.h"
@@ -94,7 +98,7 @@ void gpu_select_query_begin(
g_query_state.id = MEM_mallocN(g_query_state.num_of_queries * sizeof(*g_query_state.id), "gpu selection ids");
glGenQueries(g_query_state.num_of_queries, g_query_state.queries);
- glPushAttrib(GL_DEPTH_BUFFER_BIT | GL_VIEWPORT_BIT);
+ gpuPushAttrib(GPU_DEPTH_BUFFER_BIT | GPU_VIEWPORT_BIT | GPU_SCISSOR_BIT);
/* disable writing to the framebuffer */
glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
@@ -112,6 +116,7 @@ void gpu_select_query_begin(
glDepthMask(GL_FALSE);
}
else if (mode == GPU_SELECT_NEAREST_FIRST_PASS) {
+ glDisable(GL_SCISSOR_TEST); /* allows fast clear */
glClear(GL_DEPTH_BUFFER_BIT);
glEnable(GL_DEPTH_TEST);
glDepthMask(GL_TRUE);
@@ -171,7 +176,16 @@ uint gpu_select_query_end(void)
}
for (i = 0; i < g_query_state.active_query; i++) {
- uint result;
+ uint result = 0;
+ /* Wait until the result is available. */
+ while (result == 0) {
+ glGetQueryObjectuiv(g_query_state.queries[i], GL_QUERY_RESULT_AVAILABLE, &result);
+ if (result == 0) {
+ /* (fclem) Not sure if this is better than calling
+ * glGetQueryObjectuiv() indefinitely. */
+ PIL_sleep_ms(1);
+ }
+ }
glGetQueryObjectuiv(g_query_state.queries[i], GL_QUERY_RESULT, &result);
if (result > 0) {
if (g_query_state.mode != GPU_SELECT_NEAREST_SECOND_PASS) {
@@ -206,7 +220,7 @@ uint gpu_select_query_end(void)
glDeleteQueries(g_query_state.num_of_queries, g_query_state.queries);
MEM_freeN(g_query_state.queries);
MEM_freeN(g_query_state.id);
- glPopAttrib();
+ gpuPopAttrib();
glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
return hits;
diff --git a/source/blender/gpu/intern/gpu_shader.c b/source/blender/gpu/intern/gpu_shader.c
index b579f87698c..02baa2e58cb 100644
--- a/source/blender/gpu/intern/gpu_shader.c
+++ b/source/blender/gpu/intern/gpu_shader.c
@@ -30,22 +30,129 @@
#include "BLI_utildefines.h"
#include "BLI_math_base.h"
#include "BLI_math_vector.h"
+#include "BLI_path_util.h"
+#include "BKE_appdir.h"
#include "BKE_global.h"
-#include "GPU_compositing.h"
-#include "GPU_debug.h"
+#include "DNA_space_types.h"
+
#include "GPU_extensions.h"
-#include "GPU_glew.h"
+#include "GPU_matrix.h"
#include "GPU_shader.h"
#include "GPU_texture.h"
-#include "GPU_material.h"
+#include "GPU_uniformbuffer.h"
+
+#include "gpu_shader_private.h"
-/* TODO(sergey): Find better default values for this constants. */
-#define MAX_DEFINE_LENGTH 1024
-#define MAX_EXT_DEFINE_LENGTH 1024
+/* Adjust these constants as needed. */
+#define MAX_DEFINE_LENGTH 256
+#define MAX_EXT_DEFINE_LENGTH 256
/* Non-generated shaders */
+extern char datatoc_gpu_shader_depth_only_frag_glsl[];
+extern char datatoc_gpu_shader_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_checker_frag_glsl[];
+extern char datatoc_gpu_shader_diag_stripes_frag_glsl[];
+extern char datatoc_gpu_shader_simple_lighting_frag_glsl[];
+extern char datatoc_gpu_shader_simple_lighting_flat_color_frag_glsl[];
+extern char datatoc_gpu_shader_simple_lighting_smooth_color_frag_glsl[];
+extern char datatoc_gpu_shader_simple_lighting_smooth_color_alpha_frag_glsl[];
+extern char datatoc_gpu_shader_flat_color_frag_glsl[];
+extern char datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl[];
+extern char datatoc_gpu_shader_flat_id_frag_glsl[];
+extern char datatoc_gpu_shader_2D_vert_glsl[];
+extern char datatoc_gpu_shader_2D_flat_color_vert_glsl[];
+extern char datatoc_gpu_shader_2D_smooth_color_uniform_alpha_vert_glsl[];
+extern char datatoc_gpu_shader_2D_smooth_color_vert_glsl[];
+extern char datatoc_gpu_shader_2D_smooth_color_frag_glsl[];
+extern char datatoc_gpu_shader_2D_smooth_color_dithered_frag_glsl[];
+extern char datatoc_gpu_shader_2D_image_vert_glsl[];
+extern char datatoc_gpu_shader_2D_image_rect_vert_glsl[];
+extern char datatoc_gpu_shader_2D_image_multi_rect_vert_glsl[];
+extern char datatoc_gpu_shader_2D_widget_base_vert_glsl[];
+extern char datatoc_gpu_shader_2D_widget_base_frag_glsl[];
+extern char datatoc_gpu_shader_2D_widget_shadow_vert_glsl[];
+extern char datatoc_gpu_shader_2D_widget_shadow_frag_glsl[];
+extern char datatoc_gpu_shader_2D_nodelink_frag_glsl[];
+extern char datatoc_gpu_shader_2D_nodelink_vert_glsl[];
+
+extern char datatoc_gpu_shader_3D_image_vert_glsl[];
+extern char datatoc_gpu_shader_image_frag_glsl[];
+extern char datatoc_gpu_shader_image_linear_frag_glsl[];
+extern char datatoc_gpu_shader_image_color_frag_glsl[];
+extern char datatoc_gpu_shader_image_desaturate_frag_glsl[];
+extern char datatoc_gpu_shader_image_varying_color_frag_glsl[];
+extern char datatoc_gpu_shader_image_alpha_color_frag_glsl[];
+extern char datatoc_gpu_shader_image_shuffle_color_frag_glsl[];
+extern char datatoc_gpu_shader_image_interlace_frag_glsl[];
+extern char datatoc_gpu_shader_image_mask_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_image_modulate_alpha_frag_glsl[];
+extern char datatoc_gpu_shader_image_depth_linear_frag_glsl[];
+extern char datatoc_gpu_shader_image_depth_copy_frag_glsl[];
+extern char datatoc_gpu_shader_image_multisample_resolve_frag_glsl[];
+extern char datatoc_gpu_shader_3D_vert_glsl[];
+extern char datatoc_gpu_shader_3D_normal_vert_glsl[];
+extern char datatoc_gpu_shader_3D_flat_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_smooth_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_normal_flat_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_normal_smooth_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_smooth_color_frag_glsl[];
+extern char datatoc_gpu_shader_3D_passthrough_vert_glsl[];
+extern char datatoc_gpu_shader_3D_clipped_uniform_color_vert_glsl[];
+
+extern char datatoc_gpu_shader_instance_vert_glsl[];
+extern char datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl[];
+extern char datatoc_gpu_shader_instance_variying_size_variying_id_vert_glsl[];
+extern char datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl[];
+extern char datatoc_gpu_shader_instance_screenspace_variying_color_vert_glsl[];
+extern char datatoc_gpu_shader_instance_screen_aligned_vert_glsl[];
+extern char datatoc_gpu_shader_instance_camera_vert_glsl[];
+extern char datatoc_gpu_shader_instance_distance_line_vert_glsl[];
+extern char datatoc_gpu_shader_instance_edges_variying_color_geom_glsl[];
+extern char datatoc_gpu_shader_instance_edges_variying_color_vert_glsl[];
+extern char datatoc_gpu_shader_instance_mball_handles_vert_glsl[];
+
+extern char datatoc_gpu_shader_3D_groundpoint_vert_glsl[];
+extern char datatoc_gpu_shader_3D_groundline_geom_glsl[];
+
+extern char datatoc_gpu_shader_point_uniform_color_frag_glsl[];
+extern char datatoc_gpu_shader_point_uniform_color_aa_frag_glsl[];
+extern char datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl[];
+extern char datatoc_gpu_shader_point_varying_color_outline_aa_frag_glsl[];
+extern char datatoc_gpu_shader_point_varying_color_frag_glsl[];
+extern char datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_point_varying_size_vert_glsl[];
+extern char datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl[];
+extern char datatoc_gpu_shader_3D_point_uniform_size_aa_vert_glsl[];
+extern char datatoc_gpu_shader_3D_point_uniform_size_outline_aa_vert_glsl[];
+extern char datatoc_gpu_shader_2D_point_varying_size_varying_color_vert_glsl[];
+extern char datatoc_gpu_shader_2D_point_uniform_size_aa_vert_glsl[];
+extern char datatoc_gpu_shader_2D_point_uniform_size_outline_aa_vert_glsl[];
+extern char datatoc_gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert_glsl[];
+
+extern char datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl[];
+extern char datatoc_gpu_shader_2D_line_dashed_frag_glsl[];
+extern char datatoc_gpu_shader_2D_line_dashed_geom_glsl[];
+extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_legacy_vert_glsl[];
+extern char datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl[];
+
+extern char datatoc_gpu_shader_edges_front_back_persp_vert_glsl[];
+extern char datatoc_gpu_shader_edges_front_back_persp_geom_glsl[];
+extern char datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl[];
+extern char datatoc_gpu_shader_edges_front_back_ortho_vert_glsl[];
+extern char datatoc_gpu_shader_edges_overlay_vert_glsl[];
+extern char datatoc_gpu_shader_edges_overlay_geom_glsl[];
+extern char datatoc_gpu_shader_edges_overlay_simple_geom_glsl[];
+extern char datatoc_gpu_shader_edges_overlay_frag_glsl[];
+extern char datatoc_gpu_shader_text_vert_glsl[];
+extern char datatoc_gpu_shader_text_geom_glsl[];
+extern char datatoc_gpu_shader_text_frag_glsl[];
+extern char datatoc_gpu_shader_text_simple_vert_glsl[];
+extern char datatoc_gpu_shader_text_simple_geom_glsl[];
+extern char datatoc_gpu_shader_keyframe_diamond_vert_glsl[];
+extern char datatoc_gpu_shader_keyframe_diamond_frag_glsl[];
+
extern char datatoc_gpu_shader_fire_frag_glsl[];
extern char datatoc_gpu_shader_smoke_vert_glsl[];
extern char datatoc_gpu_shader_smoke_frag_glsl[];
@@ -53,51 +160,23 @@ extern char datatoc_gpu_shader_vsm_store_vert_glsl[];
extern char datatoc_gpu_shader_vsm_store_frag_glsl[];
extern char datatoc_gpu_shader_sep_gaussian_blur_vert_glsl[];
extern char datatoc_gpu_shader_sep_gaussian_blur_frag_glsl[];
-extern char datatoc_gpu_shader_fx_vert_glsl[];
-extern char datatoc_gpu_shader_fx_ssao_frag_glsl[];
-extern char datatoc_gpu_shader_fx_dof_frag_glsl[];
-extern char datatoc_gpu_shader_fx_dof_vert_glsl[];
-extern char datatoc_gpu_shader_fx_dof_hq_frag_glsl[];
-extern char datatoc_gpu_shader_fx_dof_hq_vert_glsl[];
-extern char datatoc_gpu_shader_fx_dof_hq_geo_glsl[];
-extern char datatoc_gpu_shader_fx_depth_resolve_glsl[];
-extern char datatoc_gpu_shader_fx_lib_glsl[];
-
-static struct GPUShadersGlobal {
- struct {
- GPUShader *vsm_store;
- GPUShader *sep_gaussian_blur;
- GPUShader *smoke;
- GPUShader *smoke_fire;
- GPUShader *smoke_coba;
- /* cache for shader fx. Those can exist in combinations so store them here */
- GPUShader *fx_shaders[MAX_FX_SHADERS * 2];
- } shaders;
-} GG = {{NULL}};
-
-/* GPUShader */
-
-struct GPUShader {
- GLuint program; /* handle for full program (links shader stages below) */
-
- GLuint vertex; /* handle for vertex shader */
- GLuint geometry; /* handle for geometry shader */
- GLuint fragment; /* handle for fragment shader */
-
- int totattrib; /* total number of attributes */
- int uniforms; /* required uniforms */
-
- void *uniform_interface; /* cached uniform interface for shader. Data depends on shader */
-};
+
+/* cache of built-in shaders (each is created on first use) */
+static GPUShader *builtin_shaders[GPU_NUM_BUILTIN_SHADERS] = { NULL };
+
+typedef struct {
+ const char *vert;
+ const char *frag;
+ const char *geom; /* geometry stage runs between vert & frag, but is less common, so it goes last */
+} GPUShaderStages;
static void shader_print_errors(const char *task, const char *log, const char **code, int totcode)
{
- int i;
int line = 1;
fprintf(stderr, "GPUShader: %s error:\n", task);
- for (i = 0; i < totcode; i++) {
+ for (int i = 0; i < totcode; i++) {
const char *c, *pos, *end = code[i] + strlen(code[i]);
if (G.debug & G_DEBUG) {
@@ -120,76 +199,23 @@ static void shader_print_errors(const char *task, const char *log, const char **
static const char *gpu_shader_version(void)
{
- if (GLEW_VERSION_3_2) {
- if (GLEW_ARB_compatibility) {
- return "#version 150 compatibility\n";
- /* highest version that is widely supported
- * gives us native geometry shaders!
- * use compatibility profile so we can continue using builtin shader input/output names
- */
- }
- else {
- return "#version 130\n";
- /* latest version that is compatible with existing shaders */
- }
- }
- else if (GLEW_VERSION_3_1) {
- if (GLEW_ARB_compatibility) {
- return "#version 140\n";
- /* also need the ARB_compatibility extension, handled below */
- }
- else {
- return "#version 130\n";
- /* latest version that is compatible with existing shaders */
- }
- }
- else if (GLEW_VERSION_3_0) {
- return "#version 130\n";
- /* GLSL 1.3 has modern syntax/keywords/datatypes so use if available
- * older features are deprecated but still available without compatibility extension or profile
- */
- }
- else {
- return "#version 120\n";
- /* minimum supported */
- }
+ return "#version 330\n";
}
-
-static void gpu_shader_standard_extensions(char defines[MAX_EXT_DEFINE_LENGTH], bool use_geometry_shader)
+static void gpu_shader_standard_extensions(char defines[MAX_EXT_DEFINE_LENGTH])
{
/* enable extensions for features that are not part of our base GLSL version
* don't use an extension for something already available!
*/
if (GLEW_ARB_texture_query_lod) {
- /* a #version 400 feature, but we use #version 150 maximum so use extension */
+ /* a #version 400 feature, but we use #version 330 maximum so use extension */
strcat(defines, "#extension GL_ARB_texture_query_lod: enable\n");
}
-
- if (use_geometry_shader && GPU_geometry_shader_support_via_extension()) {
- strcat(defines, "#extension GL_EXT_geometry_shader4: enable\n");
- }
-
- if (GLEW_VERSION_3_1 && !GLEW_VERSION_3_2 && GLEW_ARB_compatibility) {
- strcat(defines, "#extension GL_ARB_compatibility: enable\n");
- }
-
- if (!GLEW_VERSION_3_1) {
- if (GLEW_ARB_draw_instanced) {
- strcat(defines, "#extension GL_ARB_draw_instanced: enable\n");
- }
-
- if (!GLEW_VERSION_3_0 && GLEW_EXT_gpu_shader4) {
- strcat(defines, "#extension GL_EXT_gpu_shader4: enable\n");
- /* TODO: maybe require this? shaders become so much nicer */
- }
- }
}
static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH],
- bool use_opensubdiv,
- bool use_new_shading)
+ bool use_opensubdiv)
{
/* some useful defines to detect GPU type */
if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
@@ -207,10 +233,6 @@ static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH],
if (GPU_bicubic_bump_support())
strcat(defines, "#define BUMP_BICUBIC\n");
- if (GLEW_VERSION_3_0) {
- strcat(defines, "#define BIT_OPERATIONS\n");
- }
-
#ifdef WITH_OPENSUBDIV
/* TODO(sergey): Check whether we actually compiling shader for
* the OpenSubdiv mesh.
@@ -232,10 +254,6 @@ static void gpu_shader_standard_defines(char defines[MAX_DEFINE_LENGTH],
UNUSED_VARS(use_opensubdiv);
#endif
- if (use_new_shading) {
- strcat(defines, "#define USE_NEW_SHADING\n");
- }
-
return;
}
@@ -243,37 +261,71 @@ GPUShader *GPU_shader_create(const char *vertexcode,
const char *fragcode,
const char *geocode,
const char *libcode,
- const char *defines,
- int input,
- int output,
- int number)
+ const char *defines)
{
return GPU_shader_create_ex(vertexcode,
fragcode,
geocode,
libcode,
defines,
- input,
- output,
- number,
GPU_SHADER_FLAGS_NONE);
}
+#define DEBUG_SHADER_NONE ""
+#define DEBUG_SHADER_VERTEX "vert"
+#define DEBUG_SHADER_FRAGMENT "frag"
+#define DEBUG_SHADER_GEOMETRY "geom"
+
+/**
+ * Dump GLSL shaders to disk
+ *
+ * This is used for profiling shader performance externally and debug if shader code is correct.
+ * If called with no code, it simply bumps the shader index, so different shaders for the same
+ * program share the same index.
+ */
+static void gpu_dump_shaders(const char **code, const int num_shaders, const char *extension)
+{
+ if ((G.debug & G_DEBUG_GPU_SHADERS) == 0) {
+ return;
+ }
+
+ /* We use the same shader index for shaders in the same program.
+ * So we call this function once before calling for the invidual shaders. */
+ static int shader_index = 0;
+ if (code == NULL) {
+ shader_index++;
+ BLI_assert(STREQ(DEBUG_SHADER_NONE, extension));
+ return;
+ }
+
+ /* Determine the full path of the new shader. */
+ char shader_path[FILE_MAX];
+
+ char file_name[512] = {'\0'};
+ sprintf(file_name, "%04d.%s", shader_index, extension);
+
+ BLI_join_dirfile(shader_path, sizeof(shader_path), BKE_tempdir_session(), file_name);
+
+ /* Write shader to disk. */
+ FILE *f = fopen(shader_path, "w");
+ if (f == NULL) {
+ printf("Error writing to file: %s\n", shader_path);
+ }
+ for (int j = 0; j < num_shaders; j++) {
+ fprintf(f, "%s", code[j]);
+ }
+ fclose(f);
+ printf("Shader file written to disk: %s\n", shader_path);
+}
+
GPUShader *GPU_shader_create_ex(const char *vertexcode,
const char *fragcode,
const char *geocode,
const char *libcode,
const char *defines,
- int input,
- int output,
- int number,
const int flags)
{
#ifdef WITH_OPENSUBDIV
- /* TODO(sergey): used to add #version 150 to the geometry shader.
- * Could safely be renamed to "use_geometry_code" since it's very
- * likely any of geometry code will want to use GLSL 1.5.
- */
bool use_opensubdiv = (flags & GPU_SHADER_FLAGS_SPECIAL_OPENSUBDIV) != 0;
#else
UNUSED_VARS(flags);
@@ -286,10 +338,8 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
char standard_defines[MAX_DEFINE_LENGTH] = "";
char standard_extensions[MAX_EXT_DEFINE_LENGTH] = "";
- if (geocode && !GPU_geometry_shader_support())
- return NULL;
-
shader = MEM_callocN(sizeof(GPUShader), "GPUShader");
+ gpu_dump_shaders(NULL, 0, DEBUG_SHADER_NONE);
if (vertexcode)
shader->vertex = glCreateShader(GL_VERTEX_SHADER);
@@ -311,9 +361,8 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
}
gpu_shader_standard_defines(standard_defines,
- use_opensubdiv,
- (flags & GPU_SHADER_FLAGS_NEW_SHADING) != 0);
- gpu_shader_standard_extensions(standard_extensions, geocode != NULL);
+ use_opensubdiv);
+ gpu_shader_standard_extensions(standard_extensions);
if (vertexcode) {
const char *source[5];
@@ -327,6 +376,8 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
if (defines) source[num_source++] = defines;
source[num_source++] = vertexcode;
+ gpu_dump_shaders(source, num_source, DEBUG_SHADER_VERTEX);
+
glAttachShader(shader->program, shader->vertex);
glShaderSource(shader->vertex, num_source, source, NULL);
@@ -366,6 +417,8 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
if (libcode) source[num_source++] = libcode;
source[num_source++] = fragcode;
+ gpu_dump_shaders(source, num_source, DEBUG_SHADER_FRAGMENT);
+
glAttachShader(shader->program, shader->fragment);
glShaderSource(shader->fragment, num_source, source, NULL);
@@ -392,6 +445,8 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
if (defines) source[num_source++] = defines;
source[num_source++] = geocode;
+ gpu_dump_shaders(source, num_source, DEBUG_SHADER_GEOMETRY);
+
glAttachShader(shader->program, shader->geometry);
glShaderSource(shader->geometry, num_source, source, NULL);
@@ -405,20 +460,12 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
GPU_shader_free(shader);
return NULL;
}
-
- if (!use_opensubdiv) {
- GPU_shader_geometry_stage_primitive_io(shader, input, output, number);
- }
}
#ifdef WITH_OPENSUBDIV
if (use_opensubdiv) {
glBindAttribLocation(shader->program, 0, "position");
glBindAttribLocation(shader->program, 1, "normal");
- GPU_shader_geometry_stage_primitive_io(shader,
- GL_LINES_ADJACENCY_EXT,
- GL_TRIANGLE_STRIP,
- 4);
}
#endif
@@ -436,38 +483,54 @@ GPUShader *GPU_shader_create_ex(const char *vertexcode,
return NULL;
}
+ shader->interface = GWN_shaderinterface_create(shader->program);
+
#ifdef WITH_OPENSUBDIV
/* TODO(sergey): Find a better place for this. */
- if (use_opensubdiv && GLEW_VERSION_4_1) {
- glProgramUniform1i(shader->program,
- glGetUniformLocation(shader->program, "FVarDataOffsetBuffer"),
- 30); /* GL_TEXTURE30 */
-
- glProgramUniform1i(shader->program,
- glGetUniformLocation(shader->program, "FVarDataBuffer"),
- 31); /* GL_TEXTURE31 */
+ if (use_opensubdiv) {
+ if (GLEW_VERSION_4_1) {
+ glProgramUniform1i(shader->program,
+ GWN_shaderinterface_uniform(shader->interface, "FVarDataOffsetBuffer")->location,
+ 30); /* GL_TEXTURE30 */
+
+ glProgramUniform1i(shader->program,
+ GWN_shaderinterface_uniform(shader->interface, "FVarDataBuffer")->location,
+ 31); /* GL_TEXTURE31 */
+ }
+ else {
+ glUseProgram(shader->program);
+ glUniform1i(GWN_shaderinterface_uniform(shader->interface, "FVarDataOffsetBuffer")->location, 30);
+ glUniform1i(GWN_shaderinterface_uniform(shader->interface, "FVarDataBuffer")->location, 31);
+ glUseProgram(0);
+ }
}
#endif
return shader;
}
+#undef DEBUG_SHADER_GEOMETRY
+#undef DEBUG_SHADER_FRAGMENT
+#undef DEBUG_SHADER_VERTEX
+#undef DEBUG_SHADER_NONE
+
void GPU_shader_bind(GPUShader *shader)
{
- GPU_ASSERT_NO_GL_ERRORS("Pre Shader Bind");
+ BLI_assert(shader && shader->program);
+
glUseProgram(shader->program);
- GPU_ASSERT_NO_GL_ERRORS("Post Shader Bind");
+ gpuBindMatrices(shader->interface);
}
void GPU_shader_unbind(void)
{
- GPU_ASSERT_NO_GL_ERRORS("Pre Shader Unbind");
glUseProgram(0);
- GPU_ASSERT_NO_GL_ERRORS("Post Shader Unbind");
}
void GPU_shader_free(GPUShader *shader)
{
+ BLI_assert(shader);
+
if (shader->vertex)
glDeleteShader(shader->vertex);
if (shader->geometry)
@@ -477,25 +540,43 @@ void GPU_shader_free(GPUShader *shader)
if (shader->program)
glDeleteProgram(shader->program);
- if (shader->uniform_interface)
- MEM_freeN(shader->uniform_interface);
+ if (shader->interface)
+ GWN_shaderinterface_discard(shader->interface);
MEM_freeN(shader);
}
int GPU_shader_get_uniform(GPUShader *shader, const char *name)
{
- return glGetUniformLocation(shader->program, name);
+ BLI_assert(shader && shader->program);
+ const Gwn_ShaderInput *uniform = GWN_shaderinterface_uniform(shader->interface, name);
+ return uniform ? uniform->location : -1;
+}
+
+int GPU_shader_get_builtin_uniform(GPUShader *shader, int builtin)
+{
+ BLI_assert(shader && shader->program);
+ const Gwn_ShaderInput *uniform = GWN_shaderinterface_uniform_builtin(shader->interface, builtin);
+ return uniform ? uniform->location : -1;
+}
+
+int GPU_shader_get_uniform_block(GPUShader *shader, const char *name)
+{
+ BLI_assert(shader && shader->program);
+
+ const Gwn_ShaderInput *ubo = GWN_shaderinterface_ubo(shader->interface, name);
+ return ubo ? ubo->location : -1;
}
void *GPU_shader_get_interface(GPUShader *shader)
{
- return shader->uniform_interface;
+ return shader->interface;
}
-void GPU_shader_set_interface(GPUShader *shader, void *interface)
+/* Clement : Temp */
+int GPU_shader_get_program(GPUShader *shader)
{
- shader->uniform_interface = interface;
+ return (int)shader->program;
}
void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int length, int arraysize, const float *value)
@@ -503,16 +584,12 @@ void GPU_shader_uniform_vector(GPUShader *UNUSED(shader), int location, int leng
if (location == -1 || value == NULL)
return;
- GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Vector");
-
if (length == 1) glUniform1fv(location, arraysize, value);
else if (length == 2) glUniform2fv(location, arraysize, value);
else if (length == 3) glUniform3fv(location, arraysize, value);
else if (length == 4) glUniform4fv(location, arraysize, value);
else if (length == 9) glUniformMatrix3fv(location, arraysize, 0, value);
else if (length == 16) glUniformMatrix4fv(location, arraysize, 0, value);
-
- GPU_ASSERT_NO_GL_ERRORS("Post Uniform Vector");
}
void GPU_shader_uniform_vector_int(GPUShader *UNUSED(shader), int location, int length, int arraysize, const int *value)
@@ -520,14 +597,10 @@ void GPU_shader_uniform_vector_int(GPUShader *UNUSED(shader), int location, int
if (location == -1)
return;
- GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Vector");
-
if (length == 1) glUniform1iv(location, arraysize, value);
else if (length == 2) glUniform2iv(location, arraysize, value);
else if (length == 3) glUniform3iv(location, arraysize, value);
else if (length == 4) glUniform4iv(location, arraysize, value);
-
- GPU_ASSERT_NO_GL_ERRORS("Post Uniform Vector");
}
void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value)
@@ -535,225 +608,296 @@ void GPU_shader_uniform_int(GPUShader *UNUSED(shader), int location, int value)
if (location == -1)
return;
- GPU_CHECK_ERRORS_AROUND(glUniform1i(location, value));
+ glUniform1i(location, value);
}
-void GPU_shader_geometry_stage_primitive_io(GPUShader *shader, int input, int output, int number)
+void GPU_shader_uniform_buffer(GPUShader *shader, int location, GPUUniformBuffer *ubo)
{
- if (GPU_geometry_shader_support_via_extension()) {
- /* geometry shaders must provide this info themselves for #version 150 and up */
- glProgramParameteriEXT(shader->program, GL_GEOMETRY_INPUT_TYPE_EXT, input);
- glProgramParameteriEXT(shader->program, GL_GEOMETRY_OUTPUT_TYPE_EXT, output);
- glProgramParameteriEXT(shader->program, GL_GEOMETRY_VERTICES_OUT_EXT, number);
+ int bindpoint = GPU_uniformbuffer_bindpoint(ubo);
+
+ if (location == -1) {
+ return;
}
+
+ glUniformBlockBinding(shader->program, location, bindpoint);
}
void GPU_shader_uniform_texture(GPUShader *UNUSED(shader), int location, GPUTexture *tex)
{
- GLenum arbnumber;
int number = GPU_texture_bound_number(tex);
- int bindcode = GPU_texture_opengl_bindcode(tex);
- int target = GPU_texture_target(tex);
- if (number >= GPU_max_textures()) {
- fprintf(stderr, "Not enough texture slots.\n");
+ if (number == -1) {
+ fprintf(stderr, "Texture is not bound.\n");
+ BLI_assert(0);
return;
}
-
- if (number == -1)
- return;
if (location == -1)
return;
- GPU_ASSERT_NO_GL_ERRORS("Pre Uniform Texture");
-
- arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + number);
-
- if (number != 0) glActiveTexture(arbnumber);
- if (bindcode != 0)
- glBindTexture(target, bindcode);
- else
- GPU_invalid_tex_bind(target);
glUniform1i(location, number);
- glEnable(target);
- if (number != 0) glActiveTexture(GL_TEXTURE0);
-
- GPU_ASSERT_NO_GL_ERRORS("Post Uniform Texture");
}
int GPU_shader_get_attribute(GPUShader *shader, const char *name)
{
- int index;
-
- GPU_CHECK_ERRORS_AROUND(index = glGetAttribLocation(shader->program, name));
-
- return index;
+ BLI_assert(shader && shader->program);
+ const Gwn_ShaderInput *attrib = GWN_shaderinterface_attr(shader->interface, name);
+ return attrib ? attrib->location : -1;
}
GPUShader *GPU_shader_get_builtin_shader(GPUBuiltinShader shader)
{
- GPUShader *retval = NULL;
-
- switch (shader) {
- case GPU_SHADER_VSM_STORE:
- if (!GG.shaders.vsm_store)
- GG.shaders.vsm_store = GPU_shader_create(
- datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl,
- NULL, NULL, NULL, 0, 0, 0);
- retval = GG.shaders.vsm_store;
- break;
- case GPU_SHADER_SEP_GAUSSIAN_BLUR:
- if (!GG.shaders.sep_gaussian_blur)
- GG.shaders.sep_gaussian_blur = GPU_shader_create(
- datatoc_gpu_shader_sep_gaussian_blur_vert_glsl,
- datatoc_gpu_shader_sep_gaussian_blur_frag_glsl,
- NULL, NULL, NULL, 0, 0, 0);
- retval = GG.shaders.sep_gaussian_blur;
- break;
- case GPU_SHADER_SMOKE:
- if (!GG.shaders.smoke)
- GG.shaders.smoke = GPU_shader_create(
- datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_smoke_frag_glsl,
- NULL, NULL, NULL, 0, 0, 0);
- retval = GG.shaders.smoke;
- break;
- case GPU_SHADER_SMOKE_FIRE:
- if (!GG.shaders.smoke_fire)
- GG.shaders.smoke_fire = GPU_shader_create(
- datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_fire_frag_glsl,
- NULL, NULL, NULL, 0, 0, 0);
- retval = GG.shaders.smoke_fire;
- break;
- case GPU_SHADER_SMOKE_COBA:
- if (!GG.shaders.smoke_coba)
- GG.shaders.smoke_coba = GPU_shader_create(
- datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_smoke_frag_glsl,
- NULL, NULL, "#define USE_COBA;\n", 0, 0, 0);
- retval = GG.shaders.smoke_coba;
- break;
- }
-
- if (retval == NULL)
- printf("Unable to create a GPUShader for builtin shader: %u\n", shader);
-
- return retval;
-}
-
-#define MAX_DEFINES 100
-
-GPUShader *GPU_shader_get_builtin_fx_shader(int effect, bool persp)
-{
- int offset;
- char defines[MAX_DEFINES] = "";
- /* avoid shaders out of range */
- if (effect >= MAX_FX_SHADERS)
- return NULL;
-
- offset = 2 * effect;
-
- if (persp) {
- offset += 1;
- strcat(defines, "#define PERSP_MATRIX\n");
- }
-
- if (!GG.shaders.fx_shaders[offset]) {
- GPUShader *shader = NULL;
-
- switch (effect) {
- case GPU_SHADER_FX_SSAO:
- shader = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_ssao_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ BLI_assert(shader != GPU_NUM_BUILTIN_SHADERS); /* don't be a troll */
+
+ static const GPUShaderStages builtin_shader_stages[GPU_NUM_BUILTIN_SHADERS] = {
+ [GPU_SHADER_VSM_STORE] = { datatoc_gpu_shader_vsm_store_vert_glsl, datatoc_gpu_shader_vsm_store_frag_glsl },
+ [GPU_SHADER_SEP_GAUSSIAN_BLUR] = { datatoc_gpu_shader_sep_gaussian_blur_vert_glsl,
+ datatoc_gpu_shader_sep_gaussian_blur_frag_glsl },
+ [GPU_SHADER_SMOKE] = { datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_smoke_frag_glsl },
+ [GPU_SHADER_SMOKE_FIRE] = { datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_smoke_frag_glsl },
+ [GPU_SHADER_SMOKE_COBA] = { datatoc_gpu_shader_smoke_vert_glsl, datatoc_gpu_shader_smoke_frag_glsl },
+
+ [GPU_SHADER_TEXT] = { datatoc_gpu_shader_text_vert_glsl,
+ datatoc_gpu_shader_text_frag_glsl,
+ datatoc_gpu_shader_text_geom_glsl },
+ [GPU_SHADER_TEXT_SIMPLE] = { datatoc_gpu_shader_text_simple_vert_glsl,
+ datatoc_gpu_shader_text_frag_glsl,
+ datatoc_gpu_shader_text_simple_geom_glsl },
+ [GPU_SHADER_KEYFRAME_DIAMOND] = { datatoc_gpu_shader_keyframe_diamond_vert_glsl,
+ datatoc_gpu_shader_keyframe_diamond_frag_glsl },
+ [GPU_SHADER_EDGES_FRONT_BACK_PERSP] = { datatoc_gpu_shader_edges_front_back_persp_vert_glsl,
+ /* this version is */ datatoc_gpu_shader_flat_color_frag_glsl,
+ /* magical but slooow */ datatoc_gpu_shader_edges_front_back_persp_geom_glsl },
+ [GPU_SHADER_EDGES_FRONT_BACK_ORTHO] = { datatoc_gpu_shader_edges_front_back_ortho_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl },
+ [GPU_SHADER_EDGES_OVERLAY_SIMPLE] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_edges_overlay_frag_glsl,
+ datatoc_gpu_shader_edges_overlay_simple_geom_glsl },
+ [GPU_SHADER_EDGES_OVERLAY] = { datatoc_gpu_shader_edges_overlay_vert_glsl,
+ datatoc_gpu_shader_edges_overlay_frag_glsl,
+ datatoc_gpu_shader_edges_overlay_geom_glsl },
+ [GPU_SHADER_SIMPLE_LIGHTING] = { datatoc_gpu_shader_3D_normal_vert_glsl, datatoc_gpu_shader_simple_lighting_frag_glsl },
+ /* Use 'USE_FLAT_NORMAL' to make flat shader from smooth */
+ [GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR] = { datatoc_gpu_shader_3D_normal_smooth_color_vert_glsl, datatoc_gpu_shader_simple_lighting_smooth_color_frag_glsl },
+ [GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR] = { datatoc_gpu_shader_3D_normal_smooth_color_vert_glsl, datatoc_gpu_shader_simple_lighting_smooth_color_frag_glsl },
+ [GPU_SHADER_SIMPLE_LIGHTING_SMOOTH_COLOR_ALPHA] = { datatoc_gpu_shader_3D_normal_smooth_color_vert_glsl, datatoc_gpu_shader_simple_lighting_smooth_color_alpha_frag_glsl },
+
+ [GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_image_vert_glsl,
+ datatoc_gpu_shader_image_mask_uniform_color_frag_glsl },
+ [GPU_SHADER_3D_IMAGE_MODULATE_ALPHA] = { datatoc_gpu_shader_3D_image_vert_glsl,
+ datatoc_gpu_shader_image_modulate_alpha_frag_glsl },
+ [GPU_SHADER_3D_IMAGE_DEPTH] = { datatoc_gpu_shader_3D_image_vert_glsl,
+ datatoc_gpu_shader_image_depth_linear_frag_glsl },
+ [GPU_SHADER_3D_IMAGE_DEPTH_COPY] = { datatoc_gpu_shader_3D_image_vert_glsl,
+ datatoc_gpu_shader_image_depth_copy_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_MULTISAMPLE_2] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_MULTISAMPLE_4] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_MULTISAMPLE_8] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_MULTISAMPLE_16] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_image_multisample_resolve_frag_glsl },
+
+ [GPU_SHADER_2D_IMAGE_INTERLACE] = { datatoc_gpu_shader_2D_image_vert_glsl,
+ datatoc_gpu_shader_image_interlace_frag_glsl },
+ [GPU_SHADER_2D_CHECKER] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_checker_frag_glsl },
+
+ [GPU_SHADER_2D_DIAG_STRIPES] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_diag_stripes_frag_glsl },
+
+ [GPU_SHADER_2D_UNIFORM_COLOR] = { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
+ [GPU_SHADER_2D_FLAT_COLOR] = { datatoc_gpu_shader_2D_flat_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl },
+ [GPU_SHADER_2D_SMOOTH_COLOR] = { datatoc_gpu_shader_2D_smooth_color_vert_glsl,
+ datatoc_gpu_shader_2D_smooth_color_frag_glsl },
+ [GPU_SHADER_2D_SMOOTH_COLOR_DITHER] = { datatoc_gpu_shader_2D_smooth_color_vert_glsl,
+ datatoc_gpu_shader_2D_smooth_color_dithered_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_LINEAR_TO_SRGB] = { datatoc_gpu_shader_2D_image_vert_glsl,
+ datatoc_gpu_shader_image_linear_frag_glsl },
+ [GPU_SHADER_2D_IMAGE] = { datatoc_gpu_shader_2D_image_vert_glsl,
+ datatoc_gpu_shader_image_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
+ datatoc_gpu_shader_image_color_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_DESATURATE_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
+ datatoc_gpu_shader_image_desaturate_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_ALPHA_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
+ datatoc_gpu_shader_image_alpha_color_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR] = { datatoc_gpu_shader_2D_image_vert_glsl,
+ datatoc_gpu_shader_image_shuffle_color_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_RECT_COLOR] = { datatoc_gpu_shader_2D_image_rect_vert_glsl,
+ datatoc_gpu_shader_image_color_frag_glsl },
+ [GPU_SHADER_2D_IMAGE_MULTI_RECT_COLOR] = { datatoc_gpu_shader_2D_image_multi_rect_vert_glsl,
+ datatoc_gpu_shader_image_varying_color_frag_glsl },
+
+ [GPU_SHADER_3D_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
+ [GPU_SHADER_3D_UNIFORM_COLOR_U32] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
+ [GPU_SHADER_3D_FLAT_COLOR] = { datatoc_gpu_shader_3D_flat_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl },
+ [GPU_SHADER_3D_FLAT_COLOR_U32] = { datatoc_gpu_shader_3D_flat_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl },
+ [GPU_SHADER_3D_SMOOTH_COLOR] = { datatoc_gpu_shader_3D_smooth_color_vert_glsl,
+ datatoc_gpu_shader_3D_smooth_color_frag_glsl },
+ [GPU_SHADER_3D_DEPTH_ONLY] = { datatoc_gpu_shader_3D_vert_glsl, datatoc_gpu_shader_depth_only_frag_glsl },
+ [GPU_SHADER_3D_CLIPPED_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_clipped_uniform_color_vert_glsl,
+ datatoc_gpu_shader_uniform_color_frag_glsl },
+
+ [GPU_SHADER_3D_GROUNDPOINT] = { datatoc_gpu_shader_3D_groundpoint_vert_glsl, datatoc_gpu_shader_point_uniform_color_frag_glsl },
+ [GPU_SHADER_3D_GROUNDLINE] = { datatoc_gpu_shader_3D_passthrough_vert_glsl,
+ datatoc_gpu_shader_uniform_color_frag_glsl,
+ datatoc_gpu_shader_3D_groundline_geom_glsl },
+
+ [GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR] = { datatoc_gpu_shader_2D_line_dashed_uniform_color_vert_glsl,
+ datatoc_gpu_shader_2D_line_dashed_frag_glsl,
+ datatoc_gpu_shader_2D_line_dashed_geom_glsl },
+ [GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_line_dashed_uniform_color_vert_glsl,
+ datatoc_gpu_shader_2D_line_dashed_frag_glsl,
+ datatoc_gpu_shader_2D_line_dashed_geom_glsl },
+
+ [GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR] =
+ { datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl,
+ datatoc_gpu_shader_simple_lighting_frag_glsl},
+ [GPU_SHADER_3D_OBJECTSPACE_VARIYING_COLOR] = { datatoc_gpu_shader_instance_objectspace_variying_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl},
+ [GPU_SHADER_3D_SCREENSPACE_VARIYING_COLOR] = { datatoc_gpu_shader_instance_screenspace_variying_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl},
+ [GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS] = { datatoc_gpu_shader_instance_screen_aligned_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl},
+ [GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED] = { datatoc_gpu_shader_instance_screen_aligned_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl},
+
+ [GPU_SHADER_CAMERA] = { datatoc_gpu_shader_instance_camera_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl},
+ [GPU_SHADER_DISTANCE_LINES] = { datatoc_gpu_shader_instance_distance_line_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl},
+
+ [GPU_SHADER_2D_POINT_FIXED_SIZE_UNIFORM_COLOR] =
+ { datatoc_gpu_shader_2D_vert_glsl, datatoc_gpu_shader_point_uniform_color_frag_glsl },
+ [GPU_SHADER_2D_POINT_VARYING_SIZE_VARYING_COLOR] =
+ { datatoc_gpu_shader_2D_point_varying_size_varying_color_vert_glsl,
+ datatoc_gpu_shader_point_varying_color_frag_glsl },
+ [GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] =
+ { datatoc_gpu_shader_2D_point_uniform_size_aa_vert_glsl,
+ datatoc_gpu_shader_point_uniform_color_aa_frag_glsl },
+ [GPU_SHADER_2D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA] =
+ { datatoc_gpu_shader_2D_point_uniform_size_outline_aa_vert_glsl,
+ datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl },
+ [GPU_SHADER_2D_POINT_UNIFORM_SIZE_VARYING_COLOR_OUTLINE_AA] =
+ { datatoc_gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert_glsl,
+ datatoc_gpu_shader_point_varying_color_outline_aa_frag_glsl },
+ [GPU_SHADER_3D_POINT_FIXED_SIZE_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_vert_glsl,
+ datatoc_gpu_shader_point_uniform_color_frag_glsl },
+ [GPU_SHADER_3D_POINT_FIXED_SIZE_VARYING_COLOR] = { datatoc_gpu_shader_3D_point_fixed_size_varying_color_vert_glsl,
+ datatoc_gpu_shader_point_varying_color_frag_glsl },
+ [GPU_SHADER_3D_POINT_VARYING_SIZE_UNIFORM_COLOR] = { datatoc_gpu_shader_3D_point_varying_size_vert_glsl,
+ datatoc_gpu_shader_point_uniform_color_frag_glsl },
+ [GPU_SHADER_3D_POINT_VARYING_SIZE_VARYING_COLOR] =
+ { datatoc_gpu_shader_3D_point_varying_size_varying_color_vert_glsl,
+ datatoc_gpu_shader_point_varying_color_frag_glsl },
+ [GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_AA] =
+ { datatoc_gpu_shader_3D_point_uniform_size_aa_vert_glsl,
+ datatoc_gpu_shader_point_uniform_color_aa_frag_glsl },
+ [GPU_SHADER_3D_POINT_UNIFORM_SIZE_UNIFORM_COLOR_OUTLINE_AA] =
+ { datatoc_gpu_shader_3D_point_uniform_size_outline_aa_vert_glsl,
+ datatoc_gpu_shader_point_uniform_color_outline_aa_frag_glsl },
+
+ [GPU_SHADER_INSTANCE_UNIFORM_COLOR] = { datatoc_gpu_shader_instance_vert_glsl, datatoc_gpu_shader_uniform_color_frag_glsl },
+ [GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE] =
+ { datatoc_gpu_shader_instance_variying_size_variying_id_vert_glsl,
+ datatoc_gpu_shader_flat_id_frag_glsl },
+ [GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE] =
+ { datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl },
+ [GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SCALE] =
+ { datatoc_gpu_shader_instance_variying_size_variying_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl },
+ [GPU_SHADER_INSTANCE_EDGES_VARIYING_COLOR] = { datatoc_gpu_shader_instance_edges_variying_color_vert_glsl,
+ datatoc_gpu_shader_flat_color_frag_glsl,
+ datatoc_gpu_shader_instance_edges_variying_color_geom_glsl},
+
+ [GPU_SHADER_2D_WIDGET_BASE] = { datatoc_gpu_shader_2D_widget_base_vert_glsl,
+ datatoc_gpu_shader_2D_widget_base_frag_glsl},
+ [GPU_SHADER_2D_WIDGET_BASE_INST] = { datatoc_gpu_shader_2D_widget_base_vert_glsl,
+ datatoc_gpu_shader_2D_widget_base_frag_glsl},
+ [GPU_SHADER_2D_WIDGET_SHADOW] = { datatoc_gpu_shader_2D_widget_shadow_vert_glsl,
+ datatoc_gpu_shader_2D_widget_shadow_frag_glsl },
+ [GPU_SHADER_2D_NODELINK] = { datatoc_gpu_shader_2D_nodelink_vert_glsl,
+ datatoc_gpu_shader_2D_nodelink_frag_glsl },
+ [GPU_SHADER_2D_NODELINK_INST] = { datatoc_gpu_shader_2D_nodelink_vert_glsl,
+ datatoc_gpu_shader_2D_nodelink_frag_glsl },
+ };
+
+ if (builtin_shaders[shader] == NULL) {
+ /* just a few special cases */
+ const char *defines = NULL;
+ switch (shader) {
+ case GPU_SHADER_2D_IMAGE_MULTISAMPLE_2:
+ defines = "#define SAMPLES 2\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_ONE:
- strcat(defines, "#define FIRST_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ case GPU_SHADER_2D_IMAGE_MULTISAMPLE_4:
+ defines = "#define SAMPLES 4\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_TWO:
- strcat(defines, "#define SECOND_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ case GPU_SHADER_2D_IMAGE_MULTISAMPLE_8:
+ defines = "#define SAMPLES 8\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_THREE:
- strcat(defines, "#define THIRD_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ case GPU_SHADER_2D_IMAGE_MULTISAMPLE_16:
+ defines = "#define SAMPLES 16\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FOUR:
- strcat(defines, "#define FOURTH_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ case GPU_SHADER_2D_WIDGET_BASE_INST:
+ case GPU_SHADER_2D_NODELINK_INST:
+ defines = "#define USE_INSTANCE\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_PASS_FIVE:
- strcat(defines, "#define FIFTH_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_vert_glsl, datatoc_gpu_shader_fx_dof_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ case GPU_SHADER_SMOKE_COBA:
+ defines = "#define USE_COBA\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_ONE:
- strcat(defines, "#define FIRST_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_hq_vert_glsl, datatoc_gpu_shader_fx_dof_hq_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ case GPU_SHADER_INSTANCE_VARIYING_ID_VARIYING_SIZE:
+ case GPU_SHADER_INSTANCE_VARIYING_COLOR_VARIYING_SIZE:
+ defines = "#define UNIFORM_SCALE\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_TWO:
- strcat(defines, "#define SECOND_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_hq_vert_glsl, datatoc_gpu_shader_fx_dof_hq_frag_glsl, datatoc_gpu_shader_fx_dof_hq_geo_glsl, datatoc_gpu_shader_fx_lib_glsl,
- defines, GL_POINTS, GL_TRIANGLE_STRIP, 4);
+ case GPU_SHADER_3D_INSTANCE_SCREEN_ALIGNED_AXIS:
+ defines = "#define AXIS_NAME\n";
break;
-
- case GPU_SHADER_FX_DEPTH_OF_FIELD_HQ_PASS_THREE:
- strcat(defines, "#define THIRD_PASS\n");
- shader = GPU_shader_create(datatoc_gpu_shader_fx_dof_hq_vert_glsl, datatoc_gpu_shader_fx_dof_hq_frag_glsl, NULL, datatoc_gpu_shader_fx_lib_glsl, defines, 0, 0, 0);
+ case GPU_SHADER_3D_OBJECTSPACE_SIMPLE_LIGHTING_VARIYING_COLOR:
+ defines = "#define USE_INSTANCE_COLOR\n";
break;
-
- case GPU_SHADER_FX_DEPTH_RESOLVE:
- shader = GPU_shader_create(datatoc_gpu_shader_fx_vert_glsl, datatoc_gpu_shader_fx_depth_resolve_glsl, NULL, NULL, defines, 0, 0, 0);
+ case GPU_SHADER_3D_FLAT_COLOR_U32:
+ case GPU_SHADER_3D_UNIFORM_COLOR_U32:
+ defines = "#define USE_COLOR_U32\n";
+ break;
+ case GPU_SHADER_SIMPLE_LIGHTING_FLAT_COLOR:
+ defines = "#define USE_FLAT_NORMAL\n";
+ break;
+ default:
break;
}
- GG.shaders.fx_shaders[offset] = shader;
- GPU_fx_shader_init_interface(shader, effect);
- }
-
- return GG.shaders.fx_shaders[offset];
-}
-
+ const GPUShaderStages *stages = builtin_shader_stages + shader;
-void GPU_shader_free_builtin_shaders(void)
-{
- int i;
-
- if (GG.shaders.vsm_store) {
- GPU_shader_free(GG.shaders.vsm_store);
- GG.shaders.vsm_store = NULL;
- }
+ if (shader == GPU_SHADER_EDGES_FRONT_BACK_PERSP && !GLEW_VERSION_3_2) {
+ /* TODO: remove after switch to core profile (maybe) */
+ static const GPUShaderStages legacy_fancy_edges =
+ { datatoc_gpu_shader_edges_front_back_persp_legacy_vert_glsl,
+ datatoc_gpu_shader_flat_color_alpha_test_0_frag_glsl };
+ stages = &legacy_fancy_edges;
+ }
- if (GG.shaders.sep_gaussian_blur) {
- GPU_shader_free(GG.shaders.sep_gaussian_blur);
- GG.shaders.sep_gaussian_blur = NULL;
- }
+ if (shader == GPU_SHADER_3D_LINE_DASHED_UNIFORM_COLOR && !GLEW_VERSION_3_2) {
+ /* Dashed need geometry shader, which are not supported by legacy OpenGL, fallback to solid lines. */
+ /* TODO: remove after switch to core profile (maybe) */
+ static const GPUShaderStages legacy_dashed_lines = { datatoc_gpu_shader_3D_line_dashed_uniform_color_legacy_vert_glsl,
+ datatoc_gpu_shader_2D_line_dashed_frag_glsl };
+ stages = &legacy_dashed_lines;
+ }
- if (GG.shaders.smoke) {
- GPU_shader_free(GG.shaders.smoke);
- GG.shaders.smoke = NULL;
+ /* common case */
+ builtin_shaders[shader] = GPU_shader_create(stages->vert, stages->frag, stages->geom, NULL, defines);
}
- if (GG.shaders.smoke_fire) {
- GPU_shader_free(GG.shaders.smoke_fire);
- GG.shaders.smoke_fire = NULL;
- }
+ return builtin_shaders[shader];
+}
- if (GG.shaders.smoke_coba) {
- GPU_shader_free(GG.shaders.smoke_coba);
- GG.shaders.smoke_coba = NULL;
- }
+#define MAX_DEFINES 100
- for (i = 0; i < 2 * MAX_FX_SHADERS; ++i) {
- if (GG.shaders.fx_shaders[i]) {
- GPU_shader_free(GG.shaders.fx_shaders[i]);
- GG.shaders.fx_shaders[i] = NULL;
+void GPU_shader_free_builtin_shaders(void)
+{
+ for (int i = 0; i < GPU_NUM_BUILTIN_SHADERS; ++i) {
+ if (builtin_shaders[i]) {
+ GPU_shader_free(builtin_shaders[i]);
+ builtin_shaders[i] = NULL;
}
}
}
-
-
diff --git a/source/blender/gpu/intern/gpu_shader_private.h b/source/blender/gpu/intern/gpu_shader_private.h
new file mode 100644
index 00000000000..67d8c6e6213
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_shader_private.h
@@ -0,0 +1,42 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file gpu_shader_private.h
+ * \ingroup gpu
+ */
+
+#ifndef __GPU_SHADER_PRIVATE_H__
+#define __GPU_SHADER_PRIVATE_H__
+
+#include "GPU_glew.h"
+#include "gawain/gwn_shader_interface.h"
+
+struct GPUShader {
+ GLuint program; /* handle for full program (links shader stages below) */
+
+ GLuint vertex; /* handle for vertex shader */
+ GLuint geometry; /* handle for geometry shader */
+ GLuint fragment; /* handle for fragment shader */
+
+ Gwn_ShaderInterface *interface; /* cached uniform & attrib interface for shader */
+};
+
+#endif /* __GPU_SHADER_PRIVATE_H__ */
+
diff --git a/source/blender/gpu/intern/gpu_texture.c b/source/blender/gpu/intern/gpu_texture.c
index f50465189b2..19e26dcce8c 100644
--- a/source/blender/gpu/intern/gpu_texture.c
+++ b/source/blender/gpu/intern/gpu_texture.c
@@ -48,10 +48,25 @@ static struct GPUTextureGlobal {
GPUTexture *invalid_tex_3D;
} GG = {NULL, NULL, NULL};
-/* GPUTexture */
+/* Maximum number of FBOs a texture can be attached to. */
+#define GPU_TEX_MAX_FBO_ATTACHED 8
+
+typedef enum GPUTextureFormatFlag {
+ GPU_FORMAT_DEPTH = (1 << 0),
+ GPU_FORMAT_STENCIL = (1 << 1),
+ GPU_FORMAT_INTEGER = (1 << 2),
+ GPU_FORMAT_FLOAT = (1 << 3),
+
+ GPU_FORMAT_1D = (1 << 10),
+ GPU_FORMAT_2D = (1 << 11),
+ GPU_FORMAT_3D = (1 << 12),
+ GPU_FORMAT_CUBE = (1 << 13),
+ GPU_FORMAT_ARRAY = (1 << 14),
+} GPUTextureFormatFlag;
+/* GPUTexture */
struct GPUTexture {
- int w, h; /* width/height */
+ int w, h, d; /* width/height/depth */
int number; /* number for multitexture binding */
int refcount; /* reference count */
GLenum target; /* GL_TEXTURE_* */
@@ -60,326 +75,549 @@ struct GPUTexture {
GLuint bindcode; /* opengl identifier for texture */
int fromblender; /* we got the texture from Blender */
- GPUFrameBuffer *fb; /* GPUFramebuffer this texture is attached to */
- int fb_attachment; /* slot the texture is attached to */
- int depth; /* is a depth texture? if 3D how deep? */
-};
+ GPUTextureFormat format;
+ GPUTextureFormatFlag format_flag;
-static unsigned char *GPU_texture_convert_pixels(int length, const float *fpixels)
-{
- unsigned char *pixels, *p;
- const float *fp = fpixels;
- const int len = 4 * length;
+ unsigned int bytesize; /* number of byte for one pixel */
+ int components; /* number of color/alpha channels */
+ int samples; /* number of samples for multisamples textures. 0 if not multisample target */
- p = pixels = MEM_callocN(sizeof(unsigned char) * len, "GPUTexturePixels");
+ int fb_attachment[GPU_TEX_MAX_FBO_ATTACHED];
+ GPUFrameBuffer *fb[GPU_TEX_MAX_FBO_ATTACHED];
+};
- for (int a = 0; a < len; a++, p++, fp++)
- *p = unit_float_to_uchar_clamp((*fp));
+/* ------ Memory Management ------- */
+/* Records every texture allocation / free
+ * to estimate the Texture Pool Memory consumption */
+static unsigned int memory_usage;
- return pixels;
+static unsigned int gpu_texture_memory_footprint_compute(GPUTexture *tex)
+{
+ int samp = max_ii(tex->samples, 1);
+ switch (tex->target) {
+ case GL_TEXTURE_1D:
+ return tex->bytesize * tex->w * samp;
+ case GL_TEXTURE_1D_ARRAY:
+ case GL_TEXTURE_2D:
+ return tex->bytesize * tex->w * tex->h * samp;
+ case GL_TEXTURE_2D_ARRAY:
+ case GL_TEXTURE_3D:
+ return tex->bytesize * tex->w * tex->h * tex->d * samp;
+ case GL_TEXTURE_CUBE_MAP:
+ return tex->bytesize * 6 * tex->w * tex->h * samp;
+ case GL_TEXTURE_CUBE_MAP_ARRAY:
+ return tex->bytesize * 6 * tex->w * tex->h * tex->d * samp;
+ default:
+ return 0;
+ }
}
-static void gpu_glTexSubImageEmpty(GLenum target, GLenum format, int x, int y, int w, int h)
+static void gpu_texture_memory_footprint_add(GPUTexture *tex)
{
- void *pixels = MEM_callocN(sizeof(char) * 4 * w * h, "GPUTextureEmptyPixels");
+ memory_usage += gpu_texture_memory_footprint_compute(tex);
+}
- if (target == GL_TEXTURE_1D)
- glTexSubImage1D(target, 0, x, w, format, GL_UNSIGNED_BYTE, pixels);
- else
- glTexSubImage2D(target, 0, x, y, w, h, format, GL_UNSIGNED_BYTE, pixels);
-
- MEM_freeN(pixels);
+static void gpu_texture_memory_footprint_remove(GPUTexture *tex)
+{
+ memory_usage -= gpu_texture_memory_footprint_compute(tex);
}
-static GPUTexture *GPU_texture_create_nD(
- int w, int h, int n, const float *fpixels, int depth,
- GPUHDRType hdr_type, int components, int samples,
- char err_out[256])
+unsigned int GPU_texture_memory_usage_get(void)
{
- GLenum type, format, internalformat;
- void *pixels = NULL;
+ return memory_usage;
+}
- if (samples) {
- CLAMP_MAX(samples, GPU_max_color_texture_samples());
- }
+/* -------------------------------- */
- GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
- tex->w = w;
- tex->h = h;
- tex->number = -1;
- tex->refcount = 1;
- tex->target = (n == 1) ? GL_TEXTURE_1D : (samples ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D);
- tex->target_base = (n == 1) ? GL_TEXTURE_1D : GL_TEXTURE_2D;
- tex->depth = depth;
- tex->fb_attachment = -1;
+static GLenum gpu_texture_get_format(
+ int components, GPUTextureFormat data_type,
+ GLenum *format, GLenum *data_format, GPUTextureFormatFlag *format_flag, unsigned int *bytesize)
+{
+ if (ELEM(data_type, GPU_DEPTH_COMPONENT24,
+ GPU_DEPTH_COMPONENT16,
+ GPU_DEPTH_COMPONENT32F))
+ {
+ *format_flag |= GPU_FORMAT_DEPTH;
+ *data_format = GL_FLOAT;
+ *format = GL_DEPTH_COMPONENT;
+ }
+ else if (data_type == GPU_DEPTH24_STENCIL8) {
+ *format_flag |= GPU_FORMAT_DEPTH | GPU_FORMAT_STENCIL;
+ *data_format = GL_UNSIGNED_INT_24_8;
+ *format = GL_DEPTH_STENCIL;
+ }
+ else {
+ /* Integer formats */
+ if (ELEM(data_type, GPU_RG16I, GPU_R16I, GPU_R16UI, GPU_R32UI)) {
+ if (ELEM(data_type, GPU_R16UI, GPU_R32UI)) {
+ *data_format = GL_UNSIGNED_INT;
+ }
+ else {
+ *data_format = GL_INT;
+ }
- glGenTextures(1, &tex->bindcode);
+ *format_flag |= GPU_FORMAT_INTEGER;
- if (!tex->bindcode) {
- if (err_out) {
- BLI_snprintf(err_out, 256, "GPUTexture: texture create failed: %d",
- (int)glGetError());
+ switch (components) {
+ case 1: *format = GL_RED_INTEGER; break;
+ case 2: *format = GL_RG_INTEGER; break;
+ case 3: *format = GL_RGB_INTEGER; break;
+ case 4: *format = GL_RGBA_INTEGER; break;
+ default: break;
+ }
}
else {
- fprintf(stderr, "GPUTexture: texture create failed: %d\n",
- (int)glGetError());
+ *data_format = GL_FLOAT;
+ *format_flag |= GPU_FORMAT_FLOAT;
+
+ switch (components) {
+ case 1: *format = GL_RED; break;
+ case 2: *format = GL_RG; break;
+ case 3: *format = GL_RGB; break;
+ case 4: *format = GL_RGBA; break;
+ default: break;
+ }
}
- GPU_texture_free(tex);
- return NULL;
}
- if (!GPU_full_non_power_of_two_support()) {
- tex->w = power_of_2_max_i(tex->w);
- tex->h = power_of_2_max_i(tex->h);
+ switch (data_type) {
+ case GPU_RGBA32F:
+ *bytesize = 32;
+ break;
+ case GPU_RG32F:
+ case GPU_RGBA16F:
+ *bytesize = 16;
+ break;
+ case GPU_RGB16F:
+ *bytesize = 12;
+ break;
+ case GPU_RG16F:
+ case GPU_RG16I:
+ case GPU_RG16:
+ case GPU_DEPTH24_STENCIL8:
+ case GPU_DEPTH_COMPONENT32F:
+ case GPU_RGBA8:
+ case GPU_R11F_G11F_B10F:
+ case GPU_R32F:
+ case GPU_R32UI:
+ *bytesize = 4;
+ break;
+ case GPU_DEPTH_COMPONENT24:
+ *bytesize = 3;
+ break;
+ case GPU_DEPTH_COMPONENT16:
+ case GPU_R16F:
+ case GPU_R16I:
+ case GPU_RG8:
+ *bytesize = 2;
+ break;
+ case GPU_R8:
+ *bytesize = 1;
+ break;
+ default:
+ *bytesize = 0;
+ break;
}
- tex->number = 0;
- glBindTexture(tex->target, tex->bindcode);
-
- if (depth) {
- type = GL_UNSIGNED_BYTE;
- format = GL_DEPTH_COMPONENT;
- internalformat = GL_DEPTH_COMPONENT;
+ /* You can add any of the available type to this list
+ * For available types see GPU_texture.h */
+ switch (data_type) {
+ /* Formats texture & renderbuffer */
+ case GPU_RGBA32F: return GL_RGBA32F;
+ case GPU_RGBA16F: return GL_RGBA16F;
+ case GPU_RG32F: return GL_RG32F;
+ case GPU_RGB16F: return GL_RGB16F;
+ case GPU_RG16F: return GL_RG16F;
+ case GPU_RG16I: return GL_RG16I;
+ case GPU_RG16: return GL_RG16;
+ case GPU_RGBA8: return GL_RGBA8;
+ case GPU_R32F: return GL_R32F;
+ case GPU_R32UI: return GL_R32UI;
+ case GPU_R16F: return GL_R16F;
+ case GPU_R16I: return GL_R16I;
+ case GPU_R16UI: return GL_R16UI;
+ case GPU_RG8: return GL_RG8;
+ case GPU_R8: return GL_R8;
+ /* Special formats texture & renderbuffer */
+ case GPU_R11F_G11F_B10F: return GL_R11F_G11F_B10F;
+ case GPU_DEPTH24_STENCIL8: return GL_DEPTH24_STENCIL8;
+ /* Texture only format */
+ /* ** Add Format here **/
+ /* Special formats texture only */
+ /* ** Add Format here **/
+ /* Depth Formats */
+ case GPU_DEPTH_COMPONENT32F: return GL_DEPTH_COMPONENT32F;
+ case GPU_DEPTH_COMPONENT24: return GL_DEPTH_COMPONENT24;
+ case GPU_DEPTH_COMPONENT16: return GL_DEPTH_COMPONENT16;
+ default:
+ fprintf(stderr, "Texture format incorrect or unsupported\n");
+ return 0;
}
- else {
- type = GL_FLOAT;
-
- if (components == 4) {
- format = GL_RGBA;
- switch (hdr_type) {
- case GPU_HDR_NONE:
- internalformat = GL_RGBA8;
- break;
- /* the following formats rely on ARB_texture_float or OpenGL 3.0 */
- case GPU_HDR_HALF_FLOAT:
- internalformat = GL_RGBA16F_ARB;
- break;
- case GPU_HDR_FULL_FLOAT:
- internalformat = GL_RGBA32F_ARB;
- break;
- default:
- break;
- }
- }
- else if (components == 2) {
- /* these formats rely on ARB_texture_rg or OpenGL 3.0 */
- format = GL_RG;
- switch (hdr_type) {
- case GPU_HDR_NONE:
- internalformat = GL_RG8;
- break;
- case GPU_HDR_HALF_FLOAT:
- internalformat = GL_RG16F;
- break;
- case GPU_HDR_FULL_FLOAT:
- internalformat = GL_RG32F;
- break;
- default:
- break;
- }
- }
+}
- if (fpixels && hdr_type == GPU_HDR_NONE) {
- type = GL_UNSIGNED_BYTE;
- pixels = GPU_texture_convert_pixels(w * h, fpixels);
- }
+static int gpu_texture_get_component_count(GPUTextureFormat format)
+{
+ switch (format) {
+ case GPU_RGBA8:
+ case GPU_RGBA16F:
+ case GPU_RGBA32F:
+ return 4;
+ case GPU_RGB16F:
+ case GPU_R11F_G11F_B10F:
+ return 3;
+ case GPU_RG8:
+ case GPU_RG16:
+ case GPU_RG16F:
+ case GPU_RG16I:
+ case GPU_RG32F:
+ return 2;
+ default:
+ return 1;
}
+}
- if (tex->target == GL_TEXTURE_1D) {
- glTexImage1D(tex->target, 0, internalformat, tex->w, 0, format, type, NULL);
+static float *GPU_texture_3D_rescale(GPUTexture *tex, int w, int h, int d, int channels, const float *fpixels)
+{
+ const unsigned int xf = w / tex->w, yf = h / tex->h, zf = d / tex->d;
+ float *nfpixels = MEM_mallocN(channels * sizeof(float) * tex->w * tex->h * tex->d, "GPUTexture Rescaled 3Dtex");
- if (fpixels) {
- glTexSubImage1D(tex->target, 0, 0, w, format, type,
- pixels ? pixels : fpixels);
+ if (nfpixels) {
+ GPU_print_error_debug("You need to scale a 3D texture, feel the pain!");
- if (tex->w > w) {
- gpu_glTexSubImageEmpty(tex->target, format, w, 0, tex->w - w, 1);
+ for (unsigned k = 0; k < tex->d; k++) {
+ for (unsigned j = 0; j < tex->h; j++) {
+ for (unsigned i = 0; i < tex->w; i++) {
+ /* obviously doing nearest filtering here,
+ * it's going to be slow in any case, let's not make it worse */
+ float xb = i * xf;
+ float yb = j * yf;
+ float zb = k * zf;
+ unsigned int offset = k * (tex->w * tex->h) + i * tex->h + j;
+ unsigned int offset_orig = (zb) * (w * h) + (xb) * h + (yb);
+
+ if (channels == 4) {
+ nfpixels[offset * 4] = fpixels[offset_orig * 4];
+ nfpixels[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
+ nfpixels[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
+ nfpixels[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
+ }
+ else
+ nfpixels[offset] = fpixels[offset_orig];
+ }
}
}
}
- else {
- if (samples) {
- glTexImage2DMultisample(tex->target, samples, internalformat, tex->w, tex->h, true);
- }
- else {
- glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0,
- format, type, NULL);
- }
- if (fpixels) {
- glTexSubImage2D(tex->target, 0, 0, 0, w, h,
- format, type, pixels ? pixels : fpixels);
+ return nfpixels;
+}
- if (tex->w > w) {
- gpu_glTexSubImageEmpty(tex->target, format, w, 0, tex->w - w, tex->h);
- }
- if (tex->h > h) {
- gpu_glTexSubImageEmpty(tex->target, format, 0, h, w, tex->h - h);
- }
- }
+/* This tries to allocate video memory for a given texture
+ * If alloc fails, lower the resolution until it fits. */
+static bool gpu_texture_try_alloc(
+ GPUTexture *tex, GLenum proxy, GLenum internalformat, GLenum format, GLenum data_format,
+ int channels, bool try_rescale, const float *fpixels, float **rescaled_fpixels)
+{
+ int r_width;
+
+ switch (proxy) {
+ case GL_PROXY_TEXTURE_1D:
+ glTexImage1D(proxy, 0, internalformat, tex->w, 0, format, data_format, NULL);
+ break;
+ case GL_PROXY_TEXTURE_1D_ARRAY:
+ case GL_PROXY_TEXTURE_2D:
+ glTexImage2D(proxy, 0, internalformat, tex->w, tex->h, 0, format, data_format, NULL);
+ break;
+ case GL_PROXY_TEXTURE_2D_ARRAY:
+ case GL_PROXY_TEXTURE_3D:
+ glTexImage3D(proxy, 0, internalformat, tex->w, tex->h, tex->d, 0, format, data_format, NULL);
+ break;
}
- if (pixels)
- MEM_freeN(pixels);
+ glGetTexLevelParameteriv(proxy, 0, GL_TEXTURE_WIDTH, &r_width);
- if (depth) {
- glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
- glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
- glTexParameteri(tex->target_base, GL_DEPTH_TEXTURE_MODE, GL_INTENSITY);
- }
- else {
- glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- }
+ if (r_width == 0 && try_rescale) {
+ const int w = tex->w, h = tex->h, d = tex->d;
- if (tex->target_base != GL_TEXTURE_1D) {
- glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ /* Find largest texture possible */
+ while (r_width == 0) {
+ tex->w /= 2;
+ tex->h /= 2;
+ tex->d /= 2;
+
+ /* really unlikely to happen but keep this just in case */
+ if (tex->w == 0) break;
+ if (tex->h == 0 && proxy != GL_PROXY_TEXTURE_1D) break;
+ if (tex->d == 0 && proxy == GL_PROXY_TEXTURE_3D) break;
+
+ if (proxy == GL_PROXY_TEXTURE_1D)
+ glTexImage1D(proxy, 0, internalformat, tex->w, 0, format, data_format, NULL);
+ else if (proxy == GL_PROXY_TEXTURE_2D)
+ glTexImage2D(proxy, 0, internalformat, tex->w, tex->h, 0, format, data_format, NULL);
+ else if (proxy == GL_PROXY_TEXTURE_3D)
+ glTexImage3D(proxy, 0, internalformat, tex->w, tex->h, tex->d, 0, format, data_format, NULL);
+
+ glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
+ }
+
+ /* Rescale */
+ if (r_width > 0) {
+ switch (proxy) {
+ case GL_PROXY_TEXTURE_1D:
+ case GL_PROXY_TEXTURE_2D:
+ /* Do nothing for now */
+ return false;
+ case GL_PROXY_TEXTURE_3D:
+ *rescaled_fpixels = GPU_texture_3D_rescale(tex, w, h, d, channels, fpixels);
+ return (bool)*rescaled_fpixels;
+ }
+ }
}
- else
- glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- return tex;
+ return (r_width > 0);
}
-
-GPUTexture *GPU_texture_create_3D(int w, int h, int depth, int channels, const float *fpixels)
+static GPUTexture *GPU_texture_create_nD(
+ int w, int h, int d, int n, const float *fpixels,
+ GPUTextureFormat data_type, int samples,
+ const bool can_rescale, char err_out[256])
{
- GLenum type, format, internalformat;
- void *pixels = NULL;
+ if (samples) {
+ CLAMP_MAX(samples, GPU_max_color_texture_samples());
+ }
GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
tex->w = w;
tex->h = h;
- tex->depth = depth;
+ tex->d = d;
+ tex->samples = samples;
tex->number = -1;
tex->refcount = 1;
- tex->target = GL_TEXTURE_3D;
- tex->target_base = GL_TEXTURE_3D;
+ tex->format = data_type;
+ tex->components = gpu_texture_get_component_count(data_type);
+ tex->format_flag = 0;
+
+ if (n == 2) {
+ if (d == 0)
+ tex->target_base = tex->target = GL_TEXTURE_2D;
+ else
+ tex->target_base = tex->target = GL_TEXTURE_2D_ARRAY;
+ }
+ else if (n == 1) {
+ if (h == 0)
+ tex->target_base = tex->target = GL_TEXTURE_1D;
+ else
+ tex->target_base = tex->target = GL_TEXTURE_1D_ARRAY;
+ }
+ else if (n == 3) {
+ tex->target_base = tex->target = GL_TEXTURE_3D;
+ }
+ else {
+ /* should never happen */
+ MEM_freeN(tex);
+ return NULL;
+ }
+
+ if (samples && n == 2 && d == 0)
+ tex->target = GL_TEXTURE_2D_MULTISAMPLE;
+
+ GLenum format, internalformat, data_format;
+ internalformat = gpu_texture_get_format(tex->components, data_type, &format, &data_format,
+ &tex->format_flag, &tex->bytesize);
+ gpu_texture_memory_footprint_add(tex);
+
+ /* Generate Texture object */
glGenTextures(1, &tex->bindcode);
if (!tex->bindcode) {
- fprintf(stderr, "GPUTexture: texture create failed: %d\n",
- (int)glGetError());
+ if (err_out)
+ BLI_snprintf(err_out, 256, "GPUTexture: texture create failed");
+ else
+ fprintf(stderr, "GPUTexture: texture create failed");
GPU_texture_free(tex);
return NULL;
}
- tex->number = 0;
glBindTexture(tex->target, tex->bindcode);
- GPU_ASSERT_NO_GL_ERRORS("3D glBindTexture");
+ /* Check if texture fit in VRAM */
+ GLenum proxy = GL_PROXY_TEXTURE_2D;
+
+ if (n == 2) {
+ if (d > 0)
+ proxy = GL_PROXY_TEXTURE_2D_ARRAY;
+ }
+ else if (n == 1) {
+ if (h == 0)
+ proxy = GL_PROXY_TEXTURE_1D;
+ else
+ proxy = GL_PROXY_TEXTURE_1D_ARRAY;
+ }
+ else if (n == 3) {
+ proxy = GL_PROXY_TEXTURE_3D;
+ }
- type = GL_FLOAT;
- if (channels == 4) {
- format = GL_RGBA;
- internalformat = GL_RGBA8;
+ float *rescaled_fpixels = NULL;
+ bool valid = gpu_texture_try_alloc(tex, proxy, internalformat, format, data_format, tex->components, can_rescale,
+ fpixels, &rescaled_fpixels);
+ if (!valid) {
+ if (err_out)
+ BLI_snprintf(err_out, 256, "GPUTexture: texture alloc failed");
+ else
+ fprintf(stderr, "GPUTexture: texture alloc failed. Not enough Video Memory.");
+ GPU_texture_free(tex);
+ return NULL;
+ }
+
+ /* Upload Texture */
+ const float *pix = (rescaled_fpixels) ? rescaled_fpixels : fpixels;
+
+ if (tex->target == GL_TEXTURE_2D ||
+ tex->target == GL_TEXTURE_2D_MULTISAMPLE ||
+ tex->target == GL_TEXTURE_1D_ARRAY)
+ {
+ if (samples) {
+ glTexImage2DMultisample(tex->target, samples, internalformat, tex->w, tex->h, true);
+ if (pix)
+ glTexSubImage2D(tex->target, 0, 0, 0, tex->w, tex->h, format, data_format, pix);
+ }
+ else {
+ glTexImage2D(tex->target, 0, internalformat, tex->w, tex->h, 0, format, data_format, pix);
+ }
+ }
+ else if (tex->target == GL_TEXTURE_1D) {
+ glTexImage1D(tex->target, 0, internalformat, tex->w, 0, format, data_format, pix);
}
else {
- format = GL_RED;
- internalformat = GL_INTENSITY8;
+ glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->d, 0, format, data_format, pix);
}
- /* 3D textures are quite heavy, test if it's possible to create them first */
- glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
+ if (rescaled_fpixels)
+ MEM_freeN(rescaled_fpixels);
- bool rescale = false;
- int r_width;
+ /* Texture Parameters */
+ if (GPU_texture_stencil(tex) || /* Does not support filtering */
+ GPU_texture_integer(tex) || /* Does not support filtering */
+ GPU_texture_depth(tex))
+ {
+ glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+ }
+ else {
+ glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ }
- glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
+ if (GPU_texture_depth(tex)) {
+ glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, GL_NONE);
+ glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
+ }
- while (r_width == 0) {
- rescale = true;
- tex->w /= 2;
- tex->h /= 2;
- tex->depth /= 2;
- glTexImage3D(GL_PROXY_TEXTURE_3D, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, NULL);
- glGetTexLevelParameteriv(GL_PROXY_TEXTURE_3D, 0, GL_TEXTURE_WIDTH, &r_width);
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ if (n > 1) {
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ }
+ if (n > 2) {
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
}
- /* really unlikely to happen but keep this just in case */
- tex->w = max_ii(tex->w, 1);
- tex->h = max_ii(tex->h, 1);
- tex->depth = max_ii(tex->depth, 1);
+ glBindTexture(tex->target, 0);
-#if 0
- if (fpixels)
- pixels = GPU_texture_convert_pixels(w*h*depth, fpixels);
-#endif
+ return tex;
+}
- GPU_ASSERT_NO_GL_ERRORS("3D glTexImage3D");
+static GPUTexture *GPU_texture_cube_create(
+ int w, int d,
+ const float *fpixels_px, const float *fpixels_py, const float *fpixels_pz,
+ const float *fpixels_nx, const float *fpixels_ny, const float *fpixels_nz,
+ GPUTextureFormat data_type,
+ char err_out[256])
+{
+ GLenum format, internalformat, data_format;
- /* hardcore stuff, 3D texture rescaling - warning, this is gonna hurt your performance a lot, but we need it
- * for gooseberry */
- if (rescale && fpixels) {
- /* FIXME: should these be floating point? */
- const unsigned int xf = w / tex->w, yf = h / tex->h, zf = depth / tex->depth;
- float *tex3d = MEM_mallocN(channels * sizeof(float) * tex->w * tex->h * tex->depth, "tex3d");
+ GPUTexture *tex = MEM_callocN(sizeof(GPUTexture), "GPUTexture");
+ tex->w = w;
+ tex->h = w;
+ tex->d = d;
+ tex->samples = 0;
+ tex->number = -1;
+ tex->refcount = 1;
+ tex->format = data_type;
+ tex->components = gpu_texture_get_component_count(data_type);
+ tex->format_flag = GPU_FORMAT_CUBE;
- GPU_print_error_debug("You need to scale a 3D texture, feel the pain!");
+ if (d == 0) {
+ tex->target_base = tex->target = GL_TEXTURE_CUBE_MAP;
+ }
+ else {
+ BLI_assert(false && "Cubemap array Not implemented yet");
+ // tex->target_base = tex->target = GL_TEXTURE_CUBE_MAP_ARRAY;
+ }
- for (unsigned k = 0; k < tex->depth; k++) {
- for (unsigned j = 0; j < tex->h; j++) {
- for (unsigned i = 0; i < tex->w; i++) {
- /* obviously doing nearest filtering here,
- * it's going to be slow in any case, let's not make it worse */
- float xb = i * xf;
- float yb = j * yf;
- float zb = k * zf;
- unsigned int offset = k * (tex->w * tex->h) + i * tex->h + j;
- unsigned int offset_orig = (zb) * (w * h) + (xb) * h + (yb);
+ internalformat = gpu_texture_get_format(tex->components, data_type, &format, &data_format,
+ &tex->format_flag, &tex->bytesize);
- if (channels == 4) {
- tex3d[offset * 4] = fpixels[offset_orig * 4];
- tex3d[offset * 4 + 1] = fpixels[offset_orig * 4 + 1];
- tex3d[offset * 4 + 2] = fpixels[offset_orig * 4 + 2];
- tex3d[offset * 4 + 3] = fpixels[offset_orig * 4 + 3];
- }
- else
- tex3d[offset] = fpixels[offset_orig];
- }
- }
- }
+ gpu_texture_memory_footprint_add(tex);
- glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, tex3d);
+ /* Generate Texture object */
+ glGenTextures(1, &tex->bindcode);
- MEM_freeN(tex3d);
+ if (!tex->bindcode) {
+ if (err_out)
+ BLI_snprintf(err_out, 256, "GPUTexture: texture create failed");
+ else
+ fprintf(stderr, "GPUTexture: texture create failed");
+ GPU_texture_free(tex);
+ return NULL;
+ }
+
+ glBindTexture(tex->target, tex->bindcode);
+
+ /* Upload Texture */
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, internalformat, tex->w, tex->h, 0, format, data_format, fpixels_px);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, internalformat, tex->w, tex->h, 0, format, data_format, fpixels_py);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, internalformat, tex->w, tex->h, 0, format, data_format, fpixels_pz);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, internalformat, tex->w, tex->h, 0, format, data_format, fpixels_nx);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, internalformat, tex->w, tex->h, 0, format, data_format, fpixels_ny);
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, internalformat, tex->w, tex->h, 0, format, data_format, fpixels_nz);
+
+ /* Texture Parameters */
+ if (GPU_texture_stencil(tex) || /* Does not support filtering */
+ GPU_texture_integer(tex) || /* Does not support filtering */
+ GPU_texture_depth(tex))
+ {
+ glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
}
else {
- if (fpixels) {
- glTexImage3D(tex->target, 0, internalformat, tex->w, tex->h, tex->depth, 0, format, type, fpixels);
- GPU_ASSERT_NO_GL_ERRORS("3D glTexSubImage3D");
- }
+ glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
}
+ if (GPU_texture_depth(tex)) {
+ glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, GL_NONE);
+ glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
+ }
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
-
- if (pixels)
- MEM_freeN(pixels);
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
- GPU_texture_unbind(tex);
+ glBindTexture(tex->target, 0);
return tex;
}
-GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget, bool is_data, double time, int mipmap)
+GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget, bool is_data, double UNUSED(time), int mipmap)
{
int gputt;
/* this binds a texture, so that's why to restore it to 0 */
- GLint bindcode = GPU_verify_image(ima, iuser, textarget, 0, 0, mipmap, is_data);
- GPU_update_image_time(ima, time);
+ GLint bindcode = GPU_verify_image(ima, iuser, textarget, 0, mipmap, is_data);
/* see GPUInput::textarget: it can take two values - GL_TEXTURE_2D and GL_TEXTURE_CUBE_MAP
* these values are correct for glDisable, so textarget can be safely used in
* GPU_texture_bind/GPU_texture_unbind through tex->target_base */
+ /* (is any of this obsolete now that we don't glEnable/Disable textures?) */
if (textarget == GL_TEXTURE_2D)
gputt = TEXTARGET_TEXTURE_2D;
else
@@ -398,14 +636,17 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget
tex->target = textarget;
tex->target_base = textarget;
tex->fromblender = 1;
+ tex->format = -1;
+ tex->components = -1;
+ tex->samples = 0;
ima->gputexture[gputt] = tex;
if (!glIsTexture(tex->bindcode)) {
- GPU_ASSERT_NO_GL_ERRORS("Blender Texture Not Loaded");
+ GPU_print_error_debug("Blender Texture Not Loaded");
}
else {
- GLint w, h, border;
+ GLint w, h;
GLenum gettarget;
@@ -417,10 +658,8 @@ GPUTexture *GPU_texture_from_blender(Image *ima, ImageUser *iuser, int textarget
glBindTexture(textarget, tex->bindcode);
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_WIDTH, &w);
glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_HEIGHT, &h);
- glGetTexLevelParameteriv(gettarget, 0, GL_TEXTURE_BORDER, &border);
-
- tex->w = w - border;
- tex->h = h - border;
+ tex->w = w;
+ tex->h = h;
}
glBindTexture(textarget, 0);
@@ -452,11 +691,13 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
tex->refcount = 1;
tex->target = GL_TEXTURE_2D;
tex->target_base = GL_TEXTURE_2D;
+ tex->format = -1;
+ tex->components = -1;
prv->gputexture[0] = tex;
if (!glIsTexture(tex->bindcode)) {
- GPU_ASSERT_NO_GL_ERRORS("Blender Texture Not Loaded");
+ GPU_print_error_debug("Blender Texture Not Loaded");
}
else {
GLint w, h;
@@ -475,114 +716,96 @@ GPUTexture *GPU_texture_from_preview(PreviewImage *prv, int mipmap)
}
-GPUTexture *GPU_texture_create_1D(int w, const float *fpixels, char err_out[256])
+GPUTexture *GPU_texture_create_1D(
+ int w, GPUTextureFormat data_type, const float *pixels, char err_out[256])
{
- GPUTexture *tex = GPU_texture_create_nD(w, 1, 1, fpixels, 0, GPU_HDR_NONE, 4, 0, err_out);
-
- if (tex)
- GPU_texture_unbind(tex);
-
- return tex;
+ return GPU_texture_create_nD(w, 0, 0, 1, pixels, data_type, 0, false, err_out);
}
-GPUTexture *GPU_texture_create_2D(int w, int h, const float *fpixels, GPUHDRType hdr, char err_out[256])
+GPUTexture *GPU_texture_create_2D(
+ int w, int h, GPUTextureFormat data_type, const float *pixels, char err_out[256])
{
- GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0, hdr, 4, 0, err_out);
-
- if (tex)
- GPU_texture_unbind(tex);
-
- return tex;
+ return GPU_texture_create_nD(w, h, 0, 2, pixels, data_type, 0, false, err_out);
}
+
GPUTexture *GPU_texture_create_2D_multisample(
- int w, int h, const float *fpixels, GPUHDRType hdr, int samples, char err_out[256])
+ int w, int h, GPUTextureFormat data_type, const float *pixels, int samples, char err_out[256])
{
- GPUTexture *tex = GPU_texture_create_nD(w, h, 2, fpixels, 0, hdr, 4, samples, err_out);
-
- if (tex)
- GPU_texture_unbind(tex);
-
- return tex;
+ return GPU_texture_create_nD(w, h, 0, 2, pixels, data_type, samples, false, err_out);
}
-GPUTexture *GPU_texture_create_depth(int w, int h, char err_out[256])
+GPUTexture *GPU_texture_create_2D_array(
+ int w, int h, int d, GPUTextureFormat data_type, const float *pixels, char err_out[256])
{
- GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1, GPU_HDR_NONE, 1, 0, err_out);
-
- if (tex)
- GPU_texture_unbind(tex);
-
- return tex;
-}
-GPUTexture *GPU_texture_create_depth_multisample(int w, int h, int samples, char err_out[256])
-{
- GPUTexture *tex = GPU_texture_create_nD(w, h, 2, NULL, 1, GPU_HDR_NONE, 1, samples, err_out);
-
- if (tex)
- GPU_texture_unbind(tex);
-
- return tex;
+ return GPU_texture_create_nD(w, h, d, 2, pixels, data_type, 0, false, err_out);
}
-/**
- * A shadow map for VSM needs two components (depth and depth^2)
- */
-GPUTexture *GPU_texture_create_vsm_shadow_map(int size, char err_out[256])
+GPUTexture *GPU_texture_create_3D(
+ int w, int h, int d, GPUTextureFormat data_type, const float *pixels, char err_out[256])
{
- GPUTexture *tex = GPU_texture_create_nD(size, size, 2, NULL, 0, GPU_HDR_FULL_FLOAT, 2, 0, err_out);
-
- if (tex) {
- /* Now we tweak some of the settings */
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
-
- GPU_texture_unbind(tex);
- }
-
- return tex;
+ return GPU_texture_create_nD(w, h, d, 3, pixels, data_type, 0, true, err_out);
}
-GPUTexture *GPU_texture_create_2D_procedural(int w, int h, const float *pixels, bool repeat, char err_out[256])
+GPUTexture *GPU_texture_create_cube(
+ int w, GPUTextureFormat data_type, const float *fpixels, char err_out[256])
{
- GPUTexture *tex = GPU_texture_create_nD(w, h, 2, pixels, 0, GPU_HDR_HALF_FLOAT, 2, 0, err_out);
-
- if (tex) {
- /* Now we tweak some of the settings */
- if (repeat) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
- }
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-
- GPU_texture_unbind(tex);
+ const float *fpixels_px, *fpixels_py, *fpixels_pz, *fpixels_nx, *fpixels_ny, *fpixels_nz;
+ const int channels = gpu_texture_get_component_count(data_type);
+
+ if (fpixels) {
+ fpixels_px = fpixels + 0 * w * w * channels;
+ fpixels_nx = fpixels + 1 * w * w * channels;
+ fpixels_py = fpixels + 2 * w * w * channels;
+ fpixels_ny = fpixels + 3 * w * w * channels;
+ fpixels_pz = fpixels + 4 * w * w * channels;
+ fpixels_nz = fpixels + 5 * w * w * channels;
+ }
+ else {
+ fpixels_px = fpixels_py = fpixels_pz = fpixels_nx = fpixels_ny = fpixels_nz = NULL;
}
- return tex;
+ return GPU_texture_cube_create(w, 0, fpixels_px, fpixels_py, fpixels_pz, fpixels_nx, fpixels_ny, fpixels_nz,
+ data_type, err_out);
}
-GPUTexture *GPU_texture_create_1D_procedural(int w, const float *pixels, char err_out[256])
+void GPU_texture_update(GPUTexture *tex, const float *pixels)
{
- GPUTexture *tex = GPU_texture_create_nD(w, 0, 1, pixels, 0, GPU_HDR_HALF_FLOAT, 2, 0, err_out);
+ BLI_assert(tex->format > -1);
+ BLI_assert(tex->components > -1);
- if (tex) {
- /* Now we tweak some of the settings */
- glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_WRAP_S, GL_REPEAT);
- glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ GLenum format, data_format;
+ gpu_texture_get_format(tex->components, tex->format, &format, &data_format,
+ &tex->format_flag, &tex->bytesize);
+
+ glBindTexture(tex->target, tex->bindcode);
- GPU_texture_unbind(tex);
+ switch (tex->target) {
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_2D_MULTISAMPLE:
+ case GL_TEXTURE_1D_ARRAY:
+ glTexSubImage2D(tex->target, 0, 0, 0, tex->w, tex->h, format, data_format, pixels);
+ break;
+ case GL_TEXTURE_1D:
+ glTexSubImage1D(tex->target, 0, 0, tex->w, format, data_format, pixels);
+ break;
+ case GL_TEXTURE_3D:
+ case GL_TEXTURE_2D_ARRAY:
+ glTexSubImage3D(tex->target, 0, 0, 0, 0, tex->w, tex->h, tex->d, format, data_format, pixels);
+ break;
+ default:
+ BLI_assert(!"tex->target mode not supported");
}
- return tex;
+ glBindTexture(tex->target, 0);
}
void GPU_invalid_tex_init(void)
{
+ memory_usage = 0;
const float color[4] = {1.0f, 0.0f, 1.0f, 1.0f};
- GG.invalid_tex_1D = GPU_texture_create_1D(1, color, NULL);
- GG.invalid_tex_2D = GPU_texture_create_2D(1, 1, color, GPU_HDR_NONE, NULL);
- GG.invalid_tex_3D = GPU_texture_create_3D(1, 1, 1, 4, color);
+ GG.invalid_tex_1D = GPU_texture_create_1D(1, GPU_RGBA8, color, NULL);
+ GG.invalid_tex_2D = GPU_texture_create_2D(1, 1, GPU_RGBA8, color, NULL);
+ GG.invalid_tex_3D = GPU_texture_create_3D(1, 1, 1, GPU_RGBA8, color, NULL);
}
void GPU_invalid_tex_bind(int mode)
@@ -610,61 +833,45 @@ void GPU_invalid_tex_free(void)
GPU_texture_free(GG.invalid_tex_3D);
}
-
void GPU_texture_bind(GPUTexture *tex, int number)
{
+ BLI_assert(number >= 0);
+
if (number >= GPU_max_textures()) {
fprintf(stderr, "Not enough texture slots.\n");
return;
}
if ((G.debug & G_DEBUG)) {
- if (tex->fb && GPU_framebuffer_bound(tex->fb)) {
- fprintf(stderr, "Feedback loop warning!: Attempting to bind texture attached to current framebuffer!\n");
+ for (int i = 0; i < GPU_TEX_MAX_FBO_ATTACHED; ++i) {
+ if (tex->fb[i] && GPU_framebuffer_bound(tex->fb[i])) {
+ fprintf(stderr, "Feedback loop warning!: Attempting to bind "
+ "texture attached to current framebuffer!\n");
+ BLI_assert(0); /* Should never happen! */
+ break;
+ }
}
}
- if (number < 0)
- return;
-
- GPU_ASSERT_NO_GL_ERRORS("Pre Texture Bind");
+ glActiveTexture(GL_TEXTURE0 + number);
- GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + number);
- if (number != 0) glActiveTexture(arbnumber);
- if (tex->bindcode != 0) {
- glBindTexture(tex->target_base, tex->bindcode);
- }
+ if (tex->bindcode != 0)
+ glBindTexture(tex->target, tex->bindcode);
else
GPU_invalid_tex_bind(tex->target_base);
- glEnable(tex->target_base);
- if (number != 0) glActiveTexture(GL_TEXTURE0);
tex->number = number;
-
- GPU_ASSERT_NO_GL_ERRORS("Post Texture Bind");
}
void GPU_texture_unbind(GPUTexture *tex)
{
- if (tex->number >= GPU_max_textures()) {
- fprintf(stderr, "Not enough texture slots.\n");
- return;
- }
-
if (tex->number == -1)
return;
-
- GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind");
- GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number);
- if (tex->number != 0) glActiveTexture(arbnumber);
- glBindTexture(tex->target_base, 0);
- glDisable(tex->target_base);
- if (tex->number != 0) glActiveTexture(GL_TEXTURE0);
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ glBindTexture(tex->target, 0);
tex->number = -1;
-
- GPU_ASSERT_NO_GL_ERRORS("Post Texture Unbind");
}
int GPU_texture_bound_number(GPUTexture *tex)
@@ -672,39 +879,79 @@ int GPU_texture_bound_number(GPUTexture *tex)
return tex->number;
}
-void GPU_texture_filter_mode(GPUTexture *tex, bool compare, bool use_filter)
+#define WARN_NOT_BOUND(_tex) do { \
+ if (_tex->number == -1) { \
+ fprintf(stderr, "Warning : Trying to set parameter on a texture not bound.\n"); \
+ BLI_assert(0); \
+ return; \
+ } \
+} while (0);
+
+void GPU_texture_generate_mipmap(GPUTexture *tex)
{
- if (tex->number >= GPU_max_textures()) {
- fprintf(stderr, "Not enough texture slots.\n");
- return;
- }
+ WARN_NOT_BOUND(tex);
- if (tex->number == -1)
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ glGenerateMipmap(tex->target_base);
+}
+
+void GPU_texture_compare_mode(GPUTexture *tex, bool use_compare)
+{
+ WARN_NOT_BOUND(tex);
+
+ /* Could become an assertion ? (fclem) */
+ if (!GPU_texture_depth(tex))
return;
- GPU_ASSERT_NO_GL_ERRORS("Pre Texture Unbind");
+ GLenum mode = (use_compare) ? GL_COMPARE_REF_TO_TEXTURE : GL_NONE;
- GLenum arbnumber = (GLenum)((GLuint)GL_TEXTURE0 + tex->number);
- if (tex->number != 0) glActiveTexture(arbnumber);
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ glTexParameteri(tex->target_base, GL_TEXTURE_COMPARE_MODE, mode);
+}
- if (tex->depth) {
- if (compare)
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
- else
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_NONE);
- }
+void GPU_texture_filter_mode(GPUTexture *tex, bool use_filter)
+{
+ WARN_NOT_BOUND(tex);
- if (use_filter) {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- }
- else {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- }
- if (tex->number != 0) glActiveTexture(GL_TEXTURE0);
+ /* Stencil and integer format does not support filtering. */
+ BLI_assert(!use_filter || !(GPU_texture_stencil(tex) || GPU_texture_integer(tex)));
+
+ GLenum filter = (use_filter) ? GL_LINEAR : GL_NEAREST;
+
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, filter);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, filter);
+}
+
+void GPU_texture_mipmap_mode(GPUTexture *tex, bool use_mipmap, bool use_filter)
+{
+ WARN_NOT_BOUND(tex);
+
+ /* Stencil and integer format does not support filtering. */
+ BLI_assert((!use_filter && !use_mipmap) || !(GPU_texture_stencil(tex) || GPU_texture_integer(tex)));
+
+ GLenum filter = (use_filter) ? GL_LINEAR : GL_NEAREST;
+ GLenum mipmap = (use_filter)
+ ? (use_mipmap) ? GL_LINEAR_MIPMAP_LINEAR : GL_LINEAR
+ : (use_mipmap) ? GL_NEAREST_MIPMAP_LINEAR : GL_NEAREST;
+
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MIN_FILTER, mipmap);
+ glTexParameteri(tex->target_base, GL_TEXTURE_MAG_FILTER, filter);
+}
+
+void GPU_texture_wrap_mode(GPUTexture *tex, bool use_repeat)
+{
+ WARN_NOT_BOUND(tex);
- GPU_ASSERT_NO_GL_ERRORS("Post Texture Unbind");
+ GLenum repeat = (use_repeat) ? GL_REPEAT : GL_CLAMP_TO_EDGE;
+
+ glActiveTexture(GL_TEXTURE0 + tex->number);
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_S, repeat);
+ if (tex->target_base != GL_TEXTURE_1D)
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_T, repeat);
+ if (tex->target_base == GL_TEXTURE_3D)
+ glTexParameteri(tex->target_base, GL_TEXTURE_WRAP_R, repeat);
}
void GPU_texture_free(GPUTexture *tex)
@@ -715,11 +962,17 @@ void GPU_texture_free(GPUTexture *tex)
fprintf(stderr, "GPUTexture: negative refcount\n");
if (tex->refcount == 0) {
- if (tex->fb)
- GPU_framebuffer_texture_detach(tex);
+ for (int i = 0; i < GPU_TEX_MAX_FBO_ATTACHED; ++i) {
+ if (tex->fb[i] != NULL) {
+ GPU_framebuffer_texture_detach_slot(tex->fb[i], tex, tex->fb_attachment[i]);
+ }
+ }
+
if (tex->bindcode && !tex->fromblender)
glDeleteTextures(1, &tex->bindcode);
+ gpu_texture_memory_footprint_remove(tex);
+
MEM_freeN(tex);
}
}
@@ -744,29 +997,64 @@ int GPU_texture_height(const GPUTexture *tex)
return tex->h;
}
-int GPU_texture_depth(const GPUTexture *tex)
+GPUTextureFormat GPU_texture_format(const GPUTexture *tex)
{
- return tex->depth;
+ return tex->format;
}
-int GPU_texture_opengl_bindcode(const GPUTexture *tex)
+int GPU_texture_samples(const GPUTexture *tex)
{
- return tex->bindcode;
+ return tex->samples;
}
-GPUFrameBuffer *GPU_texture_framebuffer(GPUTexture *tex)
+bool GPU_texture_depth(const GPUTexture *tex)
{
- return tex->fb;
+ return (tex->format_flag & GPU_FORMAT_DEPTH) != 0;
}
-int GPU_texture_framebuffer_attachment(GPUTexture *tex)
+bool GPU_texture_stencil(const GPUTexture *tex)
{
- return tex->fb_attachment;
+ return (tex->format_flag & GPU_FORMAT_STENCIL) != 0;
}
-void GPU_texture_framebuffer_set(GPUTexture *tex, GPUFrameBuffer *fb, int attachment)
+bool GPU_texture_integer(const GPUTexture *tex)
{
- tex->fb = fb;
- tex->fb_attachment = attachment;
+ return (tex->format_flag & GPU_FORMAT_INTEGER) != 0;
}
+bool GPU_texture_cube(const GPUTexture *tex)
+{
+ return (tex->format_flag & GPU_FORMAT_CUBE) != 0;
+}
+
+int GPU_texture_opengl_bindcode(const GPUTexture *tex)
+{
+ return tex->bindcode;
+}
+
+void GPU_texture_attach_framebuffer(GPUTexture *tex, GPUFrameBuffer *fb, int attachment)
+{
+ for (int i = 0; i < GPU_TEX_MAX_FBO_ATTACHED; ++i) {
+ if (tex->fb[i] == NULL) {
+ tex->fb[i] = fb;
+ tex->fb_attachment[i] = attachment;
+ return;
+ }
+ }
+
+ BLI_assert(!"Error: Texture: Not enough Framebuffer slots");
+}
+
+/* Return previous attachment point */
+int GPU_texture_detach_framebuffer(GPUTexture *tex, GPUFrameBuffer *fb)
+{
+ for (int i = 0; i < GPU_TEX_MAX_FBO_ATTACHED; ++i) {
+ if (tex->fb[i] == fb) {
+ tex->fb[i] = NULL;
+ return tex->fb_attachment[i];
+ }
+ }
+
+ BLI_assert(!"Error: Texture: Framebuffer is not attached");
+ return 0;
+}
diff --git a/source/blender/gpu/intern/gpu_uniformbuffer.c b/source/blender/gpu/intern/gpu_uniformbuffer.c
new file mode 100644
index 00000000000..afd43600d9b
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_uniformbuffer.c
@@ -0,0 +1,378 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Clement Foucault.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file gpu_uniformbuffer.c
+ * \ingroup gpu
+ */
+
+#include <string.h>
+#include "MEM_guardedalloc.h"
+
+#include "BLI_blenlib.h"
+
+#include "gpu_codegen.h"
+
+#include "GPU_extensions.h"
+#include "GPU_glew.h"
+#include "GPU_material.h"
+#include "GPU_uniformbuffer.h"
+
+typedef enum GPUUniformBufferFlag {
+ GPU_UBO_FLAG_INITIALIZED = (1 << 0),
+ GPU_UBO_FLAG_DIRTY = (1 << 1),
+} GPUUniformBufferFlag;
+
+typedef enum GPUUniformBufferType {
+ GPU_UBO_STATIC = 0,
+ GPU_UBO_DYNAMIC = 1,
+} GPUUniformBufferType;
+
+struct GPUUniformBuffer {
+ int size; /* in bytes */
+ GLuint bindcode; /* opengl identifier for UBO */
+ int bindpoint; /* current binding point */
+ GPUUniformBufferType type;
+};
+
+#define GPUUniformBufferStatic GPUUniformBuffer
+
+typedef struct GPUUniformBufferDynamic {
+ GPUUniformBuffer buffer;
+ ListBase items; /* GPUUniformBufferDynamicItem */
+ void *data;
+ char flag;
+} GPUUniformBufferDynamic;
+
+struct GPUUniformBufferDynamicItem {
+ struct GPUUniformBufferDynamicItem *next, *prev;
+ GPUType gputype;
+ float *data;
+ int size;
+};
+
+
+/* Prototypes */
+static GPUType get_padded_gpu_type(struct LinkData *link);
+static void gpu_uniformbuffer_inputs_sort(struct ListBase *inputs);
+
+static GPUUniformBufferDynamicItem *gpu_uniformbuffer_populate(
+ GPUUniformBufferDynamic *ubo, const GPUType gputype, float *num);
+
+/* Only support up to this type, if you want to extend it, make sure the
+ * padding logic is correct for the new types. */
+#define MAX_UBO_GPU_TYPE GPU_VEC4
+
+static void gpu_uniformbuffer_initialize(GPUUniformBuffer *ubo, const void *data)
+{
+ glBindBuffer(GL_UNIFORM_BUFFER, ubo->bindcode);
+ glBufferData(GL_UNIFORM_BUFFER, ubo->size, data, GL_DYNAMIC_DRAW);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+}
+
+GPUUniformBuffer *GPU_uniformbuffer_create(int size, const void *data, char err_out[256])
+{
+ GPUUniformBuffer *ubo = MEM_callocN(sizeof(GPUUniformBufferStatic), "GPUUniformBufferStatic");
+ ubo->size = size;
+ ubo->bindpoint = -1;
+
+ /* Generate Buffer object */
+ glGenBuffers(1, &ubo->bindcode);
+
+ if (!ubo->bindcode) {
+ if (err_out)
+ BLI_snprintf(err_out, 256, "GPUUniformBuffer: UBO create failed");
+ GPU_uniformbuffer_free(ubo);
+ return NULL;
+ }
+
+ if (ubo->size > GPU_max_ubo_size()) {
+ if (err_out)
+ BLI_snprintf(err_out, 256, "GPUUniformBuffer: UBO too big");
+ GPU_uniformbuffer_free(ubo);
+ return NULL;
+ }
+
+ gpu_uniformbuffer_initialize(ubo, data);
+ return ubo;
+}
+
+/**
+ * Create dynamic UBO from parameters
+ * Return NULL if failed to create or if \param inputs is empty.
+ *
+ * \param inputs ListBase of BLI_genericNodeN(GPUInput)
+ */
+GPUUniformBuffer *GPU_uniformbuffer_dynamic_create(ListBase *inputs, char err_out[256])
+{
+ /* There is no point on creating an UBO if there is no arguments. */
+ if (BLI_listbase_is_empty(inputs)) {
+ return NULL;
+ }
+
+ GPUUniformBufferDynamic *ubo = MEM_callocN(sizeof(GPUUniformBufferDynamic), "GPUUniformBufferDynamic");
+ ubo->buffer.type = GPU_UBO_DYNAMIC;
+ ubo->buffer.bindpoint = -1;
+ ubo->flag = GPU_UBO_FLAG_DIRTY;
+
+ /* Generate Buffer object. */
+ glGenBuffers(1, &ubo->buffer.bindcode);
+
+ if (!ubo->buffer.bindcode) {
+ if (err_out)
+ BLI_snprintf(err_out, 256, "GPUUniformBuffer: UBO create failed");
+ GPU_uniformbuffer_free(&ubo->buffer);
+ return NULL;
+ }
+
+ if (ubo->buffer.size > GPU_max_ubo_size()) {
+ if (err_out)
+ BLI_snprintf(err_out, 256, "GPUUniformBuffer: UBO too big");
+ GPU_uniformbuffer_free(&ubo->buffer);
+ return NULL;
+ }
+
+ /* Make sure we comply to the ubo alignment requirements. */
+ gpu_uniformbuffer_inputs_sort(inputs);
+
+ for (LinkData *link = inputs->first; link; link = link->next) {
+ GPUInput *input = link->data;
+ GPUType gputype = get_padded_gpu_type(link);
+ gpu_uniformbuffer_populate(ubo, gputype, input->dynamicvec);
+ }
+
+ ubo->data = MEM_mallocN(ubo->buffer.size, __func__);
+
+ /* Initialize buffer data. */
+ GPU_uniformbuffer_dynamic_update(&ubo->buffer);
+ return &ubo->buffer;
+}
+
+/**
+ * Free the data, and clean the items list.
+ */
+static void gpu_uniformbuffer_dynamic_reset(GPUUniformBufferDynamic *ubo)
+{
+ ubo->buffer.size = 0;
+ if (ubo->data) {
+ MEM_freeN(ubo->data);
+ }
+ BLI_freelistN(&ubo->items);
+}
+
+void GPU_uniformbuffer_free(GPUUniformBuffer *ubo)
+{
+ if (ubo->type == GPU_UBO_DYNAMIC) {
+ gpu_uniformbuffer_dynamic_reset((GPUUniformBufferDynamic *)ubo);
+ }
+
+ glDeleteBuffers(1, &ubo->bindcode);
+ MEM_freeN(ubo);
+}
+
+static void gpu_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data)
+{
+ glBindBuffer(GL_UNIFORM_BUFFER, ubo->bindcode);
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, ubo->size, data);
+ glBindBuffer(GL_UNIFORM_BUFFER, 0);
+}
+
+void GPU_uniformbuffer_update(GPUUniformBuffer *ubo, const void *data)
+{
+ BLI_assert(ubo->type == GPU_UBO_STATIC);
+ gpu_uniformbuffer_update(ubo, data);
+}
+
+/**
+ * We need to recalculate the internal data, and re-generate it
+ * from its populated items.
+ */
+void GPU_uniformbuffer_dynamic_update(GPUUniformBuffer *ubo_)
+{
+ BLI_assert(ubo_->type == GPU_UBO_DYNAMIC);
+ GPUUniformBufferDynamic *ubo = (GPUUniformBufferDynamic *)ubo_;
+
+ float *offset = ubo->data;
+ for (GPUUniformBufferDynamicItem *item = ubo->items.first; item; item = item->next) {
+ memcpy(offset, item->data, item->size);
+ offset += item->gputype;
+ }
+
+ if (ubo->flag & GPU_UBO_FLAG_INITIALIZED) {
+ gpu_uniformbuffer_update(ubo_, ubo->data);
+ }
+ else {
+ ubo->flag |= GPU_UBO_FLAG_INITIALIZED;
+ gpu_uniformbuffer_initialize(ubo_, ubo->data);
+ }
+
+ ubo->flag &= ~GPU_UBO_FLAG_DIRTY;
+}
+
+/**
+ * We need to pad some data types (vec3) on the C side
+ * To match the GPU expected memory block alignment.
+ */
+static GPUType get_padded_gpu_type(LinkData *link)
+{
+ GPUInput *input = link->data;
+ GPUType gputype = input->type;
+
+ /* Unless the vec3 is followed by a float we need to treat it as a vec4. */
+ if (gputype == GPU_VEC3 &&
+ (link->next != NULL) &&
+ (((GPUInput *)link->next->data)->type != GPU_FLOAT))
+ {
+ gputype = GPU_VEC4;
+ }
+
+ return gputype;
+}
+
+/**
+ * Returns 1 if the first item shold be after second item.
+ * We make sure the vec4 uniforms come first.
+ */
+static int inputs_cmp(const void *a, const void *b)
+{
+ const LinkData *link_a = a, *link_b = b;
+ const GPUInput *input_a = link_a->data, *input_b = link_b->data;
+ return input_a->type < input_b->type ? 1 : 0;
+}
+
+/**
+ * Make sure we respect the expected alignment of UBOs.
+ * vec4, pad vec3 as vec4, then vec2, then floats.
+ */
+static void gpu_uniformbuffer_inputs_sort(ListBase *inputs)
+{
+ /* Order them as vec4, vec3, vec2, float. */
+ BLI_listbase_sort(inputs, inputs_cmp);
+
+ /* Creates a lookup table for the different types; */
+ LinkData *inputs_lookup[MAX_UBO_GPU_TYPE + 1] = {NULL};
+ GPUType cur_type = MAX_UBO_GPU_TYPE + 1;
+
+ for (LinkData *link = inputs->first; link; link = link->next) {
+ GPUInput *input = link->data;
+ if (input->type == cur_type) {
+ continue;
+ }
+ else {
+ inputs_lookup[input->type] = link;
+ cur_type = input->type;
+ }
+ }
+
+ /* If there is no GPU_VEC3 there is no need for alignment. */
+ if (inputs_lookup[GPU_VEC3] == NULL) {
+ return;
+ }
+
+ LinkData *link = inputs_lookup[GPU_VEC3];
+ while (link != NULL && ((GPUInput *)link->data)->type == GPU_VEC3) {
+ LinkData *link_next = link->next;
+
+ /* If GPU_VEC3 is followed by nothing or a GPU_FLOAT, no need for aligment. */
+ if ((link_next == NULL) ||
+ ((GPUInput *)link_next->data)->type == GPU_FLOAT)
+ {
+ break;
+ }
+
+ /* If there is a float, move it next to current vec3. */
+ if (inputs_lookup[GPU_FLOAT] != NULL) {
+ LinkData *float_input = inputs_lookup[GPU_FLOAT];
+ inputs_lookup[GPU_FLOAT] = float_input->next;
+
+ BLI_remlink(inputs, float_input);
+ BLI_insertlinkafter(inputs, link, float_input);
+ }
+
+ link = link_next;
+ }
+}
+
+/**
+ * This may now happen from the main thread, so we can't update the UBO
+ * We simply flag it as dirty
+ */
+static GPUUniformBufferDynamicItem *gpu_uniformbuffer_populate(
+ GPUUniformBufferDynamic *ubo, const GPUType gputype, float *num)
+{
+ BLI_assert(gputype <= MAX_UBO_GPU_TYPE);
+ GPUUniformBufferDynamicItem *item = MEM_callocN(sizeof(GPUUniformBufferDynamicItem), __func__);
+
+ item->gputype = gputype;
+ item->data = num;
+ item->size = gputype * sizeof(float);
+ ubo->buffer.size += item->size;
+
+ ubo->flag |= GPU_UBO_FLAG_DIRTY;
+ BLI_addtail(&ubo->items, item);
+
+ return item;
+}
+
+void GPU_uniformbuffer_bind(GPUUniformBuffer *ubo, int number)
+{
+ if (number >= GPU_max_ubo_binds()) {
+ fprintf(stderr, "Not enough UBO slots.\n");
+ return;
+ }
+
+ if (ubo->type == GPU_UBO_DYNAMIC) {
+ GPUUniformBufferDynamic *ubo_dynamic = (GPUUniformBufferDynamic *)ubo;
+ if (ubo_dynamic->flag & GPU_UBO_FLAG_DIRTY) {
+ GPU_uniformbuffer_dynamic_update(ubo);
+ }
+ }
+
+ if (ubo->bindcode != 0) {
+ glBindBufferBase(GL_UNIFORM_BUFFER, number, ubo->bindcode);
+ }
+
+ ubo->bindpoint = number;
+}
+
+void GPU_uniformbuffer_unbind(GPUUniformBuffer *ubo)
+{
+ ubo->bindpoint = -1;
+}
+
+int GPU_uniformbuffer_bindpoint(GPUUniformBuffer *ubo)
+{
+ return ubo->bindpoint;
+}
+
+void GPU_uniformbuffer_tag_dirty(GPUUniformBuffer *ubo_)
+{
+ BLI_assert(ubo_->type == GPU_UBO_DYNAMIC);
+ GPUUniformBufferDynamic *ubo = (GPUUniformBufferDynamic *)ubo_;
+ ubo->flag |= GPU_UBO_FLAG_DIRTY;
+}
+
+#undef MAX_UBO_GPU_TYPE
diff --git a/source/blender/gpu/intern/gpu_viewport.c b/source/blender/gpu/intern/gpu_viewport.c
new file mode 100644
index 00000000000..0bf215f31a8
--- /dev/null
+++ b/source/blender/gpu/intern/gpu_viewport.c
@@ -0,0 +1,644 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2006 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s):
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/gpu/intern/gpu_viewport.c
+ * \ingroup gpu
+ *
+ * System that manages viewport drawing.
+ */
+
+#include <string.h>
+
+#include "BLI_listbase.h"
+#include "BLI_rect.h"
+#include "BLI_string.h"
+#include "BLI_mempool.h"
+
+#include "BIF_gl.h"
+
+#include "DNA_vec_types.h"
+#include "DNA_userdef_types.h"
+
+#include "BKE_global.h"
+
+#include "GPU_framebuffer.h"
+#include "GPU_glew.h"
+#include "GPU_immediate.h"
+#include "GPU_texture.h"
+#include "GPU_viewport.h"
+#include "GPU_draw.h"
+
+#include "DRW_engine.h"
+
+#include "MEM_guardedalloc.h"
+
+static const int default_fbl_len = (sizeof(DefaultFramebufferList)) / sizeof(void *);
+static const int default_txl_len = (sizeof(DefaultTextureList)) / sizeof(void *);
+
+/* Maximum number of simultaneous engine enabled at the same time.
+ * Setting it lower than the real number will do lead to
+ * higher VRAM usage due to sub-efficient buffer reuse. */
+#define MAX_ENGINE_BUFFER_SHARING 5
+
+typedef struct ViewportTempTexture {
+ struct ViewportTempTexture *next, *prev;
+ void *user[MAX_ENGINE_BUFFER_SHARING];
+ GPUTexture *texture;
+} ViewportTempTexture;
+
+struct GPUViewport {
+ int size[2];
+ int samples;
+ int flag;
+
+ ListBase data; /* ViewportEngineData wrapped in LinkData */
+ unsigned int data_hash; /* If hash mismatch we free all ViewportEngineData in this viewport */
+
+ DefaultFramebufferList *fbl;
+ DefaultTextureList *txl;
+
+ ViewportMemoryPool vmempool; /* Used for rendering data structure. */
+ struct DRWInstanceDataList *idatalist; /* Used for rendering data structure. */
+
+ ListBase tex_pool; /* ViewportTempTexture list : Temporary textures shared across draw engines */
+
+ /* Profiling data */
+ double cache_time;
+};
+
+enum {
+ DO_UPDATE = (1 << 0),
+};
+
+static void gpu_viewport_buffers_free(FramebufferList *fbl, int fbl_len, TextureList *txl, int txl_len);
+static void gpu_viewport_storage_free(StorageList *stl, int stl_len);
+static void gpu_viewport_passes_free(PassList *psl, int psl_len);
+static void gpu_viewport_texture_pool_free(GPUViewport *viewport);
+static void gpu_viewport_default_fb_create(GPUViewport *viewport);
+
+void GPU_viewport_tag_update(GPUViewport *viewport)
+{
+ viewport->flag |= DO_UPDATE;
+}
+
+bool GPU_viewport_do_update(GPUViewport *viewport)
+{
+ bool ret = (viewport->flag & DO_UPDATE);
+ viewport->flag &= ~DO_UPDATE;
+ return ret;
+}
+
+GPUViewport *GPU_viewport_create(void)
+{
+ GPUViewport *viewport = MEM_callocN(sizeof(GPUViewport), "GPUViewport");
+ viewport->fbl = MEM_callocN(sizeof(DefaultFramebufferList), "FramebufferList");
+ viewport->txl = MEM_callocN(sizeof(DefaultTextureList), "TextureList");
+ viewport->idatalist = DRW_instance_data_list_create();
+
+ viewport->size[0] = viewport->size[1] = -1;
+
+ return viewport;
+}
+
+GPUViewport *GPU_viewport_create_from_offscreen(struct GPUOffScreen *ofs)
+{
+ GPUViewport *viewport = GPU_viewport_create();
+ GPUTexture *color, *depth;
+ GPUFrameBuffer *fb;
+ viewport->size[0] = GPU_offscreen_width(ofs);
+ viewport->size[1] = GPU_offscreen_height(ofs);
+
+ GPU_offscreen_viewport_data_get(ofs, &fb, &color, &depth);
+
+ if (GPU_texture_samples(color)) {
+ viewport->txl->multisample_color = color;
+ viewport->txl->multisample_depth = depth;
+ viewport->fbl->multisample_fb = fb;
+ gpu_viewport_default_fb_create(viewport);
+ }
+ else {
+ viewport->fbl->default_fb = fb;
+ viewport->txl->color = color;
+ viewport->txl->depth = depth;
+ GPU_framebuffer_ensure_config(&viewport->fbl->color_only_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(viewport->txl->color)
+ });
+ GPU_framebuffer_ensure_config(&viewport->fbl->depth_only_fb, {
+ GPU_ATTACHMENT_TEXTURE(viewport->txl->depth),
+ GPU_ATTACHMENT_NONE
+ });
+ }
+
+ return viewport;
+}
+/**
+ * Clear vars assigned from offscreen, so we don't free data owned by `GPUOffScreen`.
+ */
+void GPU_viewport_clear_from_offscreen(GPUViewport *viewport)
+{
+ DefaultFramebufferList *dfbl = viewport->fbl;
+ DefaultTextureList *dtxl = viewport->txl;
+
+ if (dfbl->multisample_fb) {
+ /* GPUViewport expect the final result to be in default_fb but
+ * GPUOffscreen wants it in its multisample_fb, so we sync it back. */
+ GPU_framebuffer_blit(dfbl->default_fb, 0, dfbl->multisample_fb, 0, GPU_COLOR_BIT | GPU_DEPTH_BIT);
+ dfbl->multisample_fb = NULL;
+ dtxl->multisample_color = NULL;
+ dtxl->multisample_depth = NULL;
+ }
+ else {
+ viewport->fbl->default_fb = NULL;
+ dtxl->color = NULL;
+ dtxl->depth = NULL;
+ }
+}
+
+void *GPU_viewport_engine_data_create(GPUViewport *viewport, void *engine_type)
+{
+ LinkData *ld = MEM_callocN(sizeof(LinkData), "LinkData");
+ ViewportEngineData *data = MEM_callocN(sizeof(ViewportEngineData), "ViewportEngineData");
+ int fbl_len, txl_len, psl_len, stl_len;
+
+ DRW_engine_viewport_data_size_get(engine_type, &fbl_len, &txl_len, &psl_len, &stl_len);
+
+ data->engine_type = engine_type;
+
+ data->fbl = MEM_callocN((sizeof(void *) * fbl_len) + sizeof(FramebufferList), "FramebufferList");
+ data->txl = MEM_callocN((sizeof(void *) * txl_len) + sizeof(TextureList), "TextureList");
+ data->psl = MEM_callocN((sizeof(void *) * psl_len) + sizeof(PassList), "PassList");
+ data->stl = MEM_callocN((sizeof(void *) * stl_len) + sizeof(StorageList), "StorageList");
+
+ ld->data = data;
+ BLI_addtail(&viewport->data, ld);
+
+ return data;
+}
+
+static void gpu_viewport_engines_data_free(GPUViewport *viewport)
+{
+ int fbl_len, txl_len, psl_len, stl_len;
+
+ LinkData *next;
+ for (LinkData *link = viewport->data.first; link; link = next) {
+ next = link->next;
+ ViewportEngineData *data = link->data;
+ DRW_engine_viewport_data_size_get(data->engine_type, &fbl_len, &txl_len, &psl_len, &stl_len);
+
+ gpu_viewport_buffers_free(data->fbl, fbl_len, data->txl, txl_len);
+ gpu_viewport_passes_free(data->psl, psl_len);
+ gpu_viewport_storage_free(data->stl, stl_len);
+
+ MEM_freeN(data->fbl);
+ MEM_freeN(data->txl);
+ MEM_freeN(data->psl);
+ MEM_freeN(data->stl);
+
+ /* We could handle this in the DRW module */
+ if (data->text_draw_cache) {
+ extern void DRW_text_cache_destroy(struct DRWTextStore *dt);
+ DRW_text_cache_destroy(data->text_draw_cache);
+ data->text_draw_cache = NULL;
+ }
+
+ MEM_freeN(data);
+
+ BLI_remlink(&viewport->data, link);
+ MEM_freeN(link);
+ }
+
+ gpu_viewport_texture_pool_free(viewport);
+}
+
+void *GPU_viewport_engine_data_get(GPUViewport *viewport, void *engine_type)
+{
+ for (LinkData *link = viewport->data.first; link; link = link->next) {
+ ViewportEngineData *vdata = link->data;
+ if (vdata->engine_type == engine_type) {
+ return vdata;
+ }
+ }
+ return NULL;
+}
+
+ViewportMemoryPool *GPU_viewport_mempool_get(GPUViewport *viewport)
+{
+ return &viewport->vmempool;
+}
+
+struct DRWInstanceDataList *GPU_viewport_instance_data_list_get(GPUViewport *viewport)
+{
+ return viewport->idatalist;
+}
+
+void *GPU_viewport_framebuffer_list_get(GPUViewport *viewport)
+{
+ return viewport->fbl;
+}
+
+void *GPU_viewport_texture_list_get(GPUViewport *viewport)
+{
+ return viewport->txl;
+}
+
+void GPU_viewport_size_get(const GPUViewport *viewport, int size[2])
+{
+ size[0] = viewport->size[0];
+ size[1] = viewport->size[1];
+}
+
+/**
+ * Special case, this is needed for when we have a viewport without a frame-buffer output
+ * (occlusion queries for eg) but still need to set the size since it may be used for other calculations.
+ */
+void GPU_viewport_size_set(GPUViewport *viewport, const int size[2])
+{
+ viewport->size[0] = size[0];
+ viewport->size[1] = size[1];
+}
+
+double *GPU_viewport_cache_time_get(GPUViewport *viewport)
+{
+ return &viewport->cache_time;
+}
+
+/**
+ * Try to find a texture coresponding to params into the texture pool.
+ * If no texture was found, create one and add it to the pool.
+ */
+GPUTexture *GPU_viewport_texture_pool_query(GPUViewport *viewport, void *engine, int width, int height, int format)
+{
+ GPUTexture *tex;
+
+ for (ViewportTempTexture *tmp_tex = viewport->tex_pool.first; tmp_tex; tmp_tex = tmp_tex->next) {
+ if ((GPU_texture_format(tmp_tex->texture) == format) &&
+ (GPU_texture_width(tmp_tex->texture) == width) &&
+ (GPU_texture_height(tmp_tex->texture) == height))
+ {
+ /* Search if the engine is not already using this texture */
+ for (int i = 0; i < MAX_ENGINE_BUFFER_SHARING; ++i) {
+ if (tmp_tex->user[i] == engine) {
+ break;
+ }
+
+ if (tmp_tex->user[i] == NULL) {
+ tmp_tex->user[i] = engine;
+ return tmp_tex->texture;
+ }
+ }
+ }
+ }
+
+ tex = GPU_texture_create_2D(width, height, format, NULL, NULL);
+ GPU_texture_bind(tex, 0);
+ /* Doing filtering for depth does not make sense when not doing shadow mapping,
+ * and enabling texture filtering on integer texture make them unreadable. */
+ bool do_filter = !GPU_texture_depth(tex) && !GPU_texture_integer(tex);
+ GPU_texture_filter_mode(tex, do_filter);
+ GPU_texture_unbind(tex);
+
+ ViewportTempTexture *tmp_tex = MEM_callocN(sizeof(ViewportTempTexture), "ViewportTempTexture");
+ tmp_tex->texture = tex;
+ tmp_tex->user[0] = engine;
+ BLI_addtail(&viewport->tex_pool, tmp_tex);
+
+ return tex;
+}
+
+static void gpu_viewport_texture_pool_clear_users(GPUViewport *viewport)
+{
+ ViewportTempTexture *tmp_tex_next;
+
+ for (ViewportTempTexture *tmp_tex = viewport->tex_pool.first; tmp_tex; tmp_tex = tmp_tex_next) {
+ tmp_tex_next = tmp_tex->next;
+ bool no_user = true;
+ for (int i = 0; i < MAX_ENGINE_BUFFER_SHARING; ++i) {
+ if (tmp_tex->user[i] != NULL) {
+ tmp_tex->user[i] = NULL;
+ no_user = false;
+ }
+ }
+
+ if (no_user) {
+ GPU_texture_free(tmp_tex->texture);
+ BLI_freelinkN(&viewport->tex_pool, tmp_tex);
+ }
+ }
+}
+
+static void gpu_viewport_texture_pool_free(GPUViewport *viewport)
+{
+ for (ViewportTempTexture *tmp_tex = viewport->tex_pool.first; tmp_tex; tmp_tex = tmp_tex->next) {
+ GPU_texture_free(tmp_tex->texture);
+ }
+
+ BLI_freelistN(&viewport->tex_pool);
+}
+
+bool GPU_viewport_engines_data_validate(GPUViewport *viewport, unsigned int hash)
+{
+ bool dirty = false;
+
+ if (viewport->data_hash != hash) {
+ gpu_viewport_engines_data_free(viewport);
+ dirty = true;
+ }
+
+ viewport->data_hash = hash;
+
+ return dirty;
+}
+
+void GPU_viewport_cache_release(GPUViewport *viewport)
+{
+ for (LinkData *link = viewport->data.first; link; link = link->next) {
+ ViewportEngineData *data = link->data;
+ int psl_len;
+ DRW_engine_viewport_data_size_get(data->engine_type, NULL, NULL, &psl_len, NULL);
+ gpu_viewport_passes_free(data->psl, psl_len);
+ }
+}
+
+static void gpu_viewport_default_fb_create(GPUViewport *viewport)
+{
+ DefaultFramebufferList *dfbl = viewport->fbl;
+ DefaultTextureList *dtxl = viewport->txl;
+ int *size = viewport->size;
+ bool ok = true;
+
+ dtxl->color = GPU_texture_create_2D(size[0], size[1], GPU_RGBA8, NULL, NULL);
+ dtxl->depth = GPU_texture_create_2D(size[0], size[1], GPU_DEPTH24_STENCIL8, NULL, NULL);
+
+ if (!(dtxl->depth && dtxl->color)) {
+ ok = false;
+ goto cleanup;
+ }
+
+ GPU_framebuffer_ensure_config(&dfbl->default_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_TEXTURE(dtxl->color)
+ });
+
+ GPU_framebuffer_ensure_config(&dfbl->depth_only_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->depth),
+ GPU_ATTACHMENT_NONE
+ });
+
+ GPU_framebuffer_ensure_config(&dfbl->color_only_fb, {
+ GPU_ATTACHMENT_NONE,
+ GPU_ATTACHMENT_TEXTURE(dtxl->color)
+ });
+
+ ok = ok && GPU_framebuffer_check_valid(dfbl->default_fb, NULL);
+ ok = ok && GPU_framebuffer_check_valid(dfbl->color_only_fb, NULL);
+ ok = ok && GPU_framebuffer_check_valid(dfbl->depth_only_fb, NULL);
+
+cleanup:
+ if (!ok) {
+ GPU_viewport_free(viewport);
+ DRW_opengl_context_disable();
+ return;
+ }
+
+ GPU_framebuffer_restore();
+}
+
+static void gpu_viewport_default_multisample_fb_create(GPUViewport *viewport)
+{
+ DefaultFramebufferList *dfbl = viewport->fbl;
+ DefaultTextureList *dtxl = viewport->txl;
+ int *size = viewport->size;
+ int samples = viewport->samples;
+ bool ok = true;
+
+ dtxl->multisample_color = GPU_texture_create_2D_multisample(size[0], size[1], GPU_RGBA8, NULL, samples, NULL);
+ dtxl->multisample_depth = GPU_texture_create_2D_multisample(size[0], size[1], GPU_DEPTH24_STENCIL8, NULL, samples, NULL);
+
+ if (!(dtxl->multisample_depth && dtxl->multisample_color)) {
+ ok = false;
+ goto cleanup;
+ }
+
+ GPU_framebuffer_ensure_config(&dfbl->multisample_fb, {
+ GPU_ATTACHMENT_TEXTURE(dtxl->multisample_depth),
+ GPU_ATTACHMENT_TEXTURE(dtxl->multisample_color)
+ });
+
+ ok = ok && GPU_framebuffer_check_valid(dfbl->multisample_fb, NULL);
+
+cleanup:
+ if (!ok) {
+ GPU_viewport_free(viewport);
+ DRW_opengl_context_disable();
+ return;
+ }
+
+ GPU_framebuffer_restore();
+}
+
+void GPU_viewport_bind(GPUViewport *viewport, const rcti *rect)
+{
+ DefaultFramebufferList *dfbl = viewport->fbl;
+ int fbl_len, txl_len;
+
+ /* add one pixel because of scissor test */
+ int rect_w = BLI_rcti_size_x(rect) + 1;
+ int rect_h = BLI_rcti_size_y(rect) + 1;
+
+ DRW_opengl_context_enable();
+
+ if (dfbl->default_fb) {
+ if (rect_w != viewport->size[0] || rect_h != viewport->size[1] || U.ogl_multisamples != viewport->samples) {
+ gpu_viewport_buffers_free(
+ (FramebufferList *)viewport->fbl, default_fbl_len,
+ (TextureList *)viewport->txl, default_txl_len);
+
+ for (LinkData *link = viewport->data.first; link; link = link->next) {
+ ViewportEngineData *data = link->data;
+ DRW_engine_viewport_data_size_get(data->engine_type, &fbl_len, &txl_len, NULL, NULL);
+ gpu_viewport_buffers_free(data->fbl, fbl_len, data->txl, txl_len);
+ }
+
+ gpu_viewport_texture_pool_free(viewport);
+ }
+ }
+
+ viewport->size[0] = rect_w;
+ viewport->size[1] = rect_h;
+ viewport->samples = U.ogl_multisamples;
+
+ gpu_viewport_texture_pool_clear_users(viewport);
+
+ /* Multisample Buffer */
+ if (viewport->samples > 0) {
+ if (!dfbl->default_fb) {
+ gpu_viewport_default_multisample_fb_create(viewport);
+ }
+ }
+
+ if (!dfbl->default_fb) {
+ gpu_viewport_default_fb_create(viewport);
+ }
+}
+
+void GPU_viewport_draw_to_screen(GPUViewport *viewport, const rcti *rect)
+{
+ DefaultFramebufferList *dfbl = viewport->fbl;
+
+ if (dfbl->default_fb == NULL)
+ return;
+
+ DefaultTextureList *dtxl = viewport->txl;
+
+ GPUTexture *color = dtxl->color;
+
+ const float w = (float)GPU_texture_width(color);
+ const float h = (float)GPU_texture_height(color);
+
+ BLI_assert(w == BLI_rcti_size_x(rect) + 1);
+ BLI_assert(h == BLI_rcti_size_y(rect) + 1);
+
+ /* wmOrtho for the screen has this same offset */
+ const float halfx = GLA_PIXEL_OFS / w;
+ const float halfy = GLA_PIXEL_OFS / h;
+
+ float x1 = rect->xmin;
+ float x2 = rect->xmin + w;
+ float y1 = rect->ymin;
+ float y2 = rect->ymin + h;
+
+ GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR);
+ GPU_shader_bind(shader);
+
+ GPU_texture_bind(color, 0);
+ glUniform1i(GPU_shader_get_uniform(shader, "image"), 0);
+ glUniform4f(GPU_shader_get_uniform(shader, "rect_icon"), halfx, halfy, 1.0f + halfx, 1.0f + halfy);
+ glUniform4f(GPU_shader_get_uniform(shader, "rect_geom"), x1, y1, x2, y2);
+ glUniform4f(GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_COLOR), 1.0f, 1.0f, 1.0f, 1.0f);
+
+ GWN_draw_primitive(GWN_PRIM_TRI_STRIP, 4);
+
+ GPU_texture_unbind(color);
+}
+
+void GPU_viewport_unbind(GPUViewport *UNUSED(viewport))
+{
+ GPU_framebuffer_restore();
+ DRW_opengl_context_disable();
+}
+
+
+GPUTexture *GPU_viewport_color_texture(GPUViewport *viewport)
+{
+ DefaultFramebufferList *dfbl = viewport->fbl;
+
+ if (dfbl->default_fb) {
+ DefaultTextureList *dtxl = viewport->txl;
+ return dtxl->color;
+ }
+
+ return NULL;
+}
+
+static void gpu_viewport_buffers_free(
+ FramebufferList *fbl, int fbl_len,
+ TextureList *txl, int txl_len)
+{
+ for (int i = 0; i < fbl_len; i++) {
+ GPUFrameBuffer *fb = fbl->framebuffers[i];
+ if (fb) {
+ GPU_framebuffer_free(fb);
+ fbl->framebuffers[i] = NULL;
+ }
+ }
+ for (int i = 0; i < txl_len; i++) {
+ GPUTexture *tex = txl->textures[i];
+ if (tex) {
+ GPU_texture_free(tex);
+ txl->textures[i] = NULL;
+ }
+ }
+}
+
+static void gpu_viewport_storage_free(StorageList *stl, int stl_len)
+{
+ for (int i = 0; i < stl_len; i++) {
+ void *storage = stl->storage[i];
+ if (storage) {
+ MEM_freeN(storage);
+ stl->storage[i] = NULL;
+ }
+ }
+}
+
+static void gpu_viewport_passes_free(PassList *psl, int psl_len)
+{
+ for (int i = 0; i < psl_len; i++) {
+ struct DRWPass *pass = psl->passes[i];
+ if (pass) {
+ DRW_pass_free(pass);
+ psl->passes[i] = NULL;
+ }
+ }
+}
+
+/* Must be executed inside Drawmanager Opengl Context. */
+void GPU_viewport_free(GPUViewport *viewport)
+{
+ gpu_viewport_engines_data_free(viewport);
+
+ gpu_viewport_buffers_free(
+ (FramebufferList *)viewport->fbl, default_fbl_len,
+ (TextureList *)viewport->txl, default_txl_len);
+
+ gpu_viewport_texture_pool_free(viewport);
+
+ MEM_freeN(viewport->fbl);
+ MEM_freeN(viewport->txl);
+
+ if (viewport->vmempool.calls != NULL) {
+ BLI_mempool_destroy(viewport->vmempool.calls);
+ }
+ if (viewport->vmempool.states != NULL) {
+ BLI_mempool_destroy(viewport->vmempool.states);
+ }
+ if (viewport->vmempool.shgroups != NULL) {
+ BLI_mempool_destroy(viewport->vmempool.shgroups);
+ }
+ if (viewport->vmempool.uniforms != NULL) {
+ BLI_mempool_destroy(viewport->vmempool.uniforms);
+ }
+ if (viewport->vmempool.passes != NULL) {
+ BLI_mempool_destroy(viewport->vmempool.passes);
+ }
+
+ DRW_instance_data_list_free(viewport->idatalist);
+ MEM_freeN(viewport->idatalist);
+
+ MEM_freeN(viewport);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl
new file mode 100644
index 00000000000..769e2b0e37c
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_flat_color_vert.glsl
@@ -0,0 +1,13 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec2 pos;
+in vec4 color;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
new file mode 100644
index 00000000000..9fdf8ececc5
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_multi_rect_vert.glsl
@@ -0,0 +1,48 @@
+/**
+ * Simple shader that just draw multiple icons at the specified locations
+ * does not need any vertex input (producing less call to immBegin/End)
+ **/
+
+/* Same as ICON_DRAW_CACHE_SIZE */
+#define MAX_CALLS 16
+
+uniform vec4 calls_data[MAX_CALLS * 3];
+
+out vec2 texCoord_interp;
+flat out vec4 finalColor;
+
+void main()
+{
+ /* Rendering 2 triangle per icon. */
+ int i = gl_VertexID / 6;
+ int v = gl_VertexID % 6;
+
+ vec4 pos = calls_data[i*3];
+ vec4 tex = calls_data[i*3+1];
+ finalColor = calls_data[i*3+2];
+
+ /* TODO Remove this */
+ if (v == 2) v = 4;
+ else if (v == 3) v = 0;
+ else if (v == 5) v = 2;
+
+ if (v == 0) {
+ pos.xy = pos.xw;
+ tex.xy = tex.xw;
+ }
+ else if (v == 1) {
+ pos.xy = pos.xz;
+ tex.xy = tex.xz;
+ }
+ else if (v == 2) {
+ pos.xy = pos.yw;
+ tex.xy = tex.yw;
+ }
+ else {
+ pos.xy = pos.yz;
+ tex.xy = tex.yz;
+ }
+
+ gl_Position = vec4(pos.xy, 0.0f, 1.0f);
+ texCoord_interp = tex.xy;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
new file mode 100644
index 00000000000..118f4e3b187
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_rect_vert.glsl
@@ -0,0 +1,35 @@
+/**
+ * Simple shader that just draw one icon at the specified location
+ * does not need any vertex input (producing less call to immBegin/End)
+ **/
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec4 rect_icon;
+uniform vec4 rect_geom;
+
+out vec2 texCoord_interp;
+
+void main()
+{
+ vec2 uv;
+ vec2 co;
+ if (gl_VertexID == 0) {
+ co = rect_geom.xw;
+ uv = rect_icon.xw;
+ }
+ else if (gl_VertexID == 1) {
+ co = rect_geom.xy;
+ uv = rect_icon.xy;
+ }
+ else if (gl_VertexID == 2) {
+ co = rect_geom.zw;
+ uv = rect_icon.zw;
+ }
+ else {
+ co = rect_geom.zy;
+ uv = rect_icon.zy;
+ }
+
+ gl_Position = ModelViewProjectionMatrix * vec4(co, 0.0f, 1.0f);
+ texCoord_interp = uv;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
new file mode 100644
index 00000000000..228f3f1da19
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_image_vert.glsl
@@ -0,0 +1,13 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+/* Keep in sync with intern/opencolorio/gpu_shader_display_transform_vertex.glsl */
+in vec2 texCoord;
+in vec2 pos;
+out vec2 texCoord_interp;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos.xy, 0.0f, 1.0f);
+ texCoord_interp = texCoord;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
new file mode 100644
index 00000000000..7caf00f58fd
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_frag.glsl
@@ -0,0 +1,54 @@
+
+/*
+ * Fragment Shader for dashed lines, with uniform multi-color(s), or any single-color, and any thickness.
+ *
+ * Dashed is performed in screen space.
+ */
+
+uniform float dash_width;
+
+/* Simple mode, discarding non-dash parts (so no need for blending at all). */
+uniform float dash_factor; /* if > 1.0, solid line. */
+
+/* More advanced mode, allowing for complex, multi-colored patterns. Enabled when num_colors > 0. */
+/* Note: max number of steps/colors in pattern is 32! */
+uniform int num_colors; /* Enabled if > 0, 1 for solid line. */
+uniform vec4 colors[32];
+
+noperspective in float distance_along_line;
+noperspective in vec4 color_geom;
+
+out vec4 fragColor;
+
+void main()
+{
+ /* Multi-color option. */
+ if (num_colors > 0) {
+ /* Solid line case, simple. */
+ if (num_colors == 1) {
+ fragColor = colors[0];
+ }
+ /* Actually dashed line... */
+ else {
+ float normalized_distance = fract(distance_along_line / dash_width);
+ fragColor = colors[int(normalized_distance * num_colors)];
+ }
+ }
+ /* Single color option. */
+ else {
+ /* Solid line case, simple. */
+ if (dash_factor >= 1.0f) {
+ fragColor = color_geom;
+ }
+ /* Actually dashed line... */
+ else {
+ float normalized_distance = fract(distance_along_line / dash_width);
+ if (normalized_distance <= dash_factor) {
+ fragColor = color_geom;
+ }
+ else {
+ discard;
+ }
+ }
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl
new file mode 100644
index 00000000000..db4bdf0a9f0
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_geom.glsl
@@ -0,0 +1,56 @@
+
+/*
+ * Geometry Shader for dashed lines, with uniform multi-color(s), or any single-color, and unary thickness.
+ *
+ * Dashed is performed in screen space.
+ */
+
+
+/* Make to be used with dynamic batching so no Model Matrix needed */
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec2 viewport_size;
+
+/* Uniforms from fragment shader, used here to optimize out useless computation in case of solid line. */
+uniform float dash_factor; /* if > 1.0, solid line. */
+uniform int num_colors; /* Enabled if > 0, 1 for solid line. */
+
+layout(lines) in;
+
+in vec4 color_vert[];
+
+layout(line_strip, max_vertices = 2) out;
+noperspective out float distance_along_line;
+noperspective out vec4 color_geom;
+
+void main()
+{
+ vec4 v1 = gl_in[0].gl_Position;
+ vec4 v2 = gl_in[1].gl_Position;
+
+ gl_Position = v1;
+ color_geom = color_vert[0];
+ distance_along_line = 0.0f;
+ EmitVertex();
+
+ gl_Position = v2;
+ color_geom = color_vert[1];
+ if ((num_colors == 1) || (dash_factor >= 1.0f)) {
+ /* Solid line, optimize out distance computation! */
+ distance_along_line = 0.0f;
+ }
+ else {
+ vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
+
+ vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
+
+ distance_along_line = distance(p1, p2);
+ }
+ EmitVertex();
+
+ EndPrimitive();
+
+ /* Note: we could also use similar approach as diag_stripes_frag, but this would give us dashed 'anchored'
+ * to the screen, and not to one end of the line... */
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
new file mode 100644
index 00000000000..f5c611586aa
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_uniform_color_vert.glsl
@@ -0,0 +1,21 @@
+
+/*
+ * Vertex Shader for dashed lines with 2D coordinates, with uniform multi-colors or uniform single-color,
+ * and unary thickness.
+ *
+ * Dashed is performed in screen space.
+ */
+
+uniform mat4 ModelViewProjectionMatrix;
+
+uniform vec4 color;
+
+in vec2 pos;
+
+out vec4 color_vert;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ color_vert = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl
new file mode 100644
index 00000000000..20c72f4407d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_line_dashed_width_geom.glsl
@@ -0,0 +1,59 @@
+
+// Draw dashed lines, perforated in screen space, with non-unary width.
+
+/* Make to be used with dynamic batching so no Model Matrix needed */
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec2 viewport_size;
+
+/* Width of the generated 'line'. */
+uniform float width; /* in pixels, screen space. */
+
+/* Uniforms from fragment shader, used here to optimize out useless computation in case of solid line. */
+uniform float dash_factor; /* if > 1.0, solid line. */
+uniform int num_colors; /* Enabled if > 0, 1 for solid line. */
+
+layout(lines) in;
+
+layout(triangle_strip, max_vertices = 4) out;
+noperspective out float distance_along_line;
+
+void main()
+{
+ vec4 v1 = gl_in[0].gl_Position;
+ vec4 v2 = gl_in[1].gl_Position;
+
+ /* Width, from 2D screen space in pixels, to ModelViewProjection space of each input vertices. */
+ float w1 = (width / viewport_size) * v1.w * 2.0;
+ float w2 = (width / viewport_size) * v2.w * 2.0;
+
+ /* Normalized vector parallel to screen and orthogonal to line. */
+ vec4 wdir = normalize(vec4(v1.y - v2.y, v2.x - v1.x, 0.0, 0.0))
+
+ distance_along_line = 0.0f;
+ gl_Position = v1 + (wdir * w1);
+ EmitVertex();
+
+ gl_Position = v1 - (wdir * w1);
+ EmitVertex();
+
+ if ((num_colors == 1) || (dash_factor >= 1.0f)) {
+ /* Solid line, optimize out distance computation! */
+ distance_along_line = 0.0f;
+ }
+ else {
+ vec2 p1 = (v1.xy / v1.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p1 = p1 * viewport_size; // <- 'virtual' screen coordinates.
+
+ vec2 p2 = (v2.xy / v2.w) * 0.5 + 0.5; // <- device coordinates in [0..1] range.
+ p2 = p2 * viewport_size; // <- 'virtual' screen coordinates.
+
+ distance_along_line = distance(p1, p2);
+ }
+ gl_Position = v2 + (wdir * w2);
+ EmitVertex();
+
+ gl_Position = v2 - (wdir * w2);
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl
new file mode 100644
index 00000000000..1497f9eeeb1
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_frag.glsl
@@ -0,0 +1,10 @@
+
+in float colorGradient;
+in vec4 finalColor;
+
+out vec4 fragColor;
+
+void main() {
+ fragColor = finalColor;
+ fragColor.a *= smoothstep(1.0, 0.1, abs(colorGradient));
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
new file mode 100644
index 00000000000..4a9f5f94321
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_nodelink_vert.glsl
@@ -0,0 +1,107 @@
+/**
+ * 2D Quadratic Bezier thick line drawing
+ **/
+
+#define MID_VERTEX 57
+
+/* u is position along the curve, defining the tangent space.
+ * v is "signed" distance (compressed to [0..1] range) from the pos in expand direction */
+in vec2 uv;
+in vec2 pos; /* verts position in the curve tangent space */
+in vec2 expand;
+
+#ifdef USE_INSTANCE
+/* Instance attrib */
+in vec2 P0;
+in vec2 P1;
+in vec2 P2;
+in vec2 P3;
+in ivec4 colid_doarrow;
+
+uniform vec4 colors[6];
+
+#define colStart colors[colid_doarrow[0]]
+#define colEnd colors[colid_doarrow[1]]
+#define colShadow colors[colid_doarrow[2]]
+#define doArrow (colid_doarrow[3] != 0)
+
+#else
+/* Single curve drawcall, use uniform. */
+uniform vec2 bezierPts[4];
+
+#define P0 bezierPts[0]
+#define P1 bezierPts[1]
+#define P2 bezierPts[2]
+#define P3 bezierPts[3]
+
+uniform vec4 colors[3];
+uniform bool doArrow;
+
+#define colShadow colors[0]
+#define colStart colors[1]
+#define colEnd colors[2]
+
+#endif
+
+uniform float expandSize;
+uniform float arrowSize;
+uniform mat4 ModelViewProjectionMatrix;
+
+out float colorGradient;
+out vec4 finalColor;
+
+void main(void)
+{
+ float t = uv.x;
+ float t2 = t * t;
+ float t2_3 = 3.0 * t2;
+ float one_minus_t = 1.0 - t;
+ float one_minus_t2 = one_minus_t * one_minus_t;
+ float one_minus_t2_3 = 3.0 * one_minus_t2;
+
+ vec2 point = (P0 * one_minus_t2 * one_minus_t +
+ P1 * one_minus_t2_3 * t +
+ P2 * t2_3 * one_minus_t +
+ P3 * t2 * t);
+
+ vec2 tangent = ((P1 - P0) * one_minus_t2_3 +
+ (P2 - P1) * 6.0 * (t - t2) +
+ (P3 - P2) * t2_3);
+
+ /* tangent space at t */
+ tangent = normalize(tangent);
+ vec2 normal = tangent.yx * vec2(-1.0, 1.0);
+
+ /* Position vertex on the curve tangent space */
+ point += (pos.x * tangent + pos.y * normal) * arrowSize;
+
+ gl_Position = ModelViewProjectionMatrix * vec4(point, 0.0, 1.0);
+
+ vec2 exp_axis = expand.x * tangent + expand.y * normal;
+
+ /* rotate & scale the expand axis */
+ exp_axis = ModelViewProjectionMatrix[0].xy * exp_axis.xx +
+ ModelViewProjectionMatrix[1].xy * exp_axis.yy;
+
+
+ float expand_dist = (uv.y * 2.0 - 1.0);
+ colorGradient = expand_dist;
+
+ if (gl_VertexID < MID_VERTEX) {
+ /* Shadow pass */
+ finalColor = colShadow;
+ }
+ else {
+ /* Second pass */
+ finalColor = mix(colStart, colEnd, uv.x);
+ expand_dist *= 0.5;
+ }
+
+ /* Expand into a line */
+ gl_Position.xy += exp_axis * expandSize * expand_dist;
+
+ /* if arrow */
+ if (expand.y != 1.0 && !doArrow) {
+ gl_Position.xy *= 0.0;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl
new file mode 100644
index 00000000000..1f833cfb7be
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_aa_vert.glsl
@@ -0,0 +1,21 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform float size;
+
+in vec2 pos;
+out vec2 radii;
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+
+ // convert to PointCoord units
+ radii /= size;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl
new file mode 100644
index 00000000000..99bdeb22904
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_outline_aa_vert.glsl
@@ -0,0 +1,24 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform float size;
+uniform float outlineWidth;
+
+in vec2 pos;
+out vec4 radii;
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
+
+ // convert to PointCoord units
+ radii /= size;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl
new file mode 100644
index 00000000000..5fad95236df
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_uniform_size_varying_color_outline_aa_vert.glsl
@@ -0,0 +1,27 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform float size;
+uniform float outlineWidth;
+
+in vec2 pos;
+in vec4 color;
+out vec4 radii;
+out vec4 fillColor;
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
+ fillColor = color;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
+
+ // convert to PointCoord units
+ radii /= size;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl
new file mode 100644
index 00000000000..d6aacf0cdc5
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_point_varying_size_varying_color_vert.glsl
@@ -0,0 +1,14 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec2 pos;
+in float size;
+in vec4 color;
+out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ gl_PointSize = size;
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl
new file mode 100644
index 00000000000..145ed16248a
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_dithered_frag.glsl
@@ -0,0 +1,20 @@
+
+noperspective in vec4 finalColor;
+out vec4 fragColor;
+
+/* 4x4 bayer matrix prepared for 8bit UNORM precision error. */
+#define P(x) (((x + 0.5) * (1.0 / 16.0) - 0.5) * (1.0 / 255.0))
+const vec4 dither_mat4x4[4] = vec4[4](
+ vec4( P(0.0), P(8.0), P(2.0), P(10.0)),
+ vec4(P(12.0), P(4.0), P(14.0), P(6.0)),
+ vec4( P(3.0), P(11.0), P(1.0), P(9.0)),
+ vec4(P(15.0), P(7.0), P(13.0), P(5.0))
+);
+
+void main()
+{
+ ivec2 tx1 = ivec2(gl_FragCoord.xy) % 4;
+ ivec2 tx2 = ivec2(gl_FragCoord.xy) % 2;
+ float dither_noise = dither_mat4x4[tx1.x][tx1.y];
+ fragColor = finalColor + dither_noise;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
new file mode 100644
index 00000000000..4a4bfb6a616
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_frag.glsl
@@ -0,0 +1,8 @@
+
+noperspective in vec4 finalColor;
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = finalColor;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
new file mode 100644
index 00000000000..fe91f4d0902
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_smooth_color_vert.glsl
@@ -0,0 +1,13 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec2 pos;
+in vec4 color;
+
+noperspective out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl
new file mode 100644
index 00000000000..89e3c52f9f8
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_vert.glsl
@@ -0,0 +1,9 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec2 pos;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl
new file mode 100644
index 00000000000..a356014d025
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_frag.glsl
@@ -0,0 +1,40 @@
+uniform vec3 checkerColorAndSize;
+
+noperspective in vec4 finalColor;
+noperspective in float butCo;
+flat in float discardFac;
+
+out vec4 fragColor;
+
+vec4 do_checkerboard()
+{
+ float size = checkerColorAndSize.z;
+ vec2 phase = mod(gl_FragCoord.xy, size * 2.0);
+
+ if ((phase.x > size && phase.y < size) ||
+ (phase.x < size && phase.y > size))
+ {
+ return vec4(checkerColorAndSize.xxx, 1.0);
+ }
+ else {
+ return vec4(checkerColorAndSize.yyy, 1.0);
+ }
+}
+
+void main()
+{
+ if (min(1.0, -butCo) > discardFac) {
+ discard;
+ }
+
+ fragColor = finalColor;
+
+ if (butCo > 0.5) {
+ vec4 checker = do_checkerboard();
+ fragColor = mix(checker, fragColor, fragColor.a);
+ }
+
+ if (butCo > 0.0) {
+ fragColor.a = 1.0;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
new file mode 100644
index 00000000000..dcd23413c77
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_base_vert.glsl
@@ -0,0 +1,202 @@
+#define BIT_RANGE(x) uint((1 << x) - 1)
+
+/* 2 bits for corner */
+/* Attention! Not the same order as in UI_interface.h!
+ * Ordered by drawing order. */
+#define BOTTOM_LEFT 0u
+#define BOTTOM_RIGHT 1u
+#define TOP_RIGHT 2u
+#define TOP_LEFT 3u
+#define CNR_FLAG_RANGE BIT_RANGE(2)
+
+/* 4bits for corner id */
+#define CORNER_VEC_OFS 2u
+#define CORNER_VEC_RANGE BIT_RANGE(4)
+const vec2 cornervec[36] = vec2[36](
+ vec2(0.0, 1.0), vec2(0.02, 0.805), vec2(0.067, 0.617), vec2(0.169, 0.45), vec2(0.293, 0.293), vec2(0.45, 0.169), vec2(0.617, 0.076), vec2(0.805, 0.02), vec2(1.0, 0.0),
+ vec2(-1.0, 0.0), vec2(-0.805, 0.02), vec2(-0.617, 0.067), vec2(-0.45, 0.169), vec2(-0.293, 0.293), vec2(-0.169, 0.45), vec2(-0.076, 0.617), vec2(-0.02, 0.805), vec2(0.0, 1.0),
+ vec2(0.0, -1.0), vec2(-0.02, -0.805), vec2(-0.067, -0.617), vec2(-0.169, -0.45), vec2(-0.293, -0.293), vec2(-0.45, -0.169), vec2(-0.617, -0.076), vec2(-0.805, -0.02), vec2(-1.0, 0.0),
+ vec2(1.0, 0.0), vec2(0.805, -0.02), vec2(0.617, -0.067), vec2(0.45, -0.169), vec2(0.293, -0.293), vec2(0.169, -0.45), vec2(0.076, -0.617), vec2(0.02, -0.805), vec2(0.0, -1.0)
+);
+
+/* 4bits for jitter id */
+#define JIT_OFS 6u
+#define JIT_RANGE BIT_RANGE(4)
+const vec2 jit[9] = vec2[9](
+ vec2( 0.468813, -0.481430), vec2(-0.155755, -0.352820),
+ vec2( 0.219306, -0.238501), vec2(-0.393286, -0.110949),
+ vec2(-0.024699, 0.013908), vec2( 0.343805, 0.147431),
+ vec2(-0.272855, 0.269918), vec2( 0.095909, 0.388710),
+ vec2( 0.0, 0.0)
+);
+
+/* 2bits for other flags */
+#define INNER_FLAG uint(1 << 10) /* is inner vert */
+#define EMBOSS_FLAG uint(1 << 11) /* is emboss vert */
+
+/* 2bits for color */
+#define COLOR_OFS 12u
+#define COLOR_RANGE BIT_RANGE(2)
+#define COLOR_INNER 0u
+#define COLOR_EDGE 1u
+#define COLOR_EMBOSS 2u
+
+/* 2bits for trias type */
+#define TRIA_FLAG uint(1 << 14) /* is tria vert */
+#define TRIA_FIRST INNER_FLAG /* is first tria (reuse INNER_FLAG) */
+
+/* We can reuse the CORNER_* bits for tria */
+#define TRIA_VEC_RANGE BIT_RANGE(6)
+const vec2 triavec[37] = vec2[37](
+ /* ROUNDBOX_TRIA_ARROWS */
+ vec2(-0.352077, 0.532607), vec2(-0.352077, -0.549313), vec2( 0.330000, -0.008353),
+ vec2( 0.352077, 0.532607), vec2( 0.352077, -0.549313), vec2(-0.330000, -0.008353),
+ /* ROUNDBOX_TRIA_SCROLL - circle tria (triangle strip) */
+ vec2(0.000000, 1.000000),
+ vec2(0.382684, 0.923879), vec2(-0.382683, 0.923880),
+ vec2(0.707107, 0.707107), vec2(-0.707107, 0.707107),
+ vec2(0.923879, 0.382684), vec2(-0.923879, 0.382684),
+ vec2(1.000000, 0.000000), vec2(-1.000000, 0.000000),
+ vec2(0.923879, -0.382684), vec2(-0.923879, -0.382684),
+ vec2(0.707107, -0.707107), vec2(-0.707107, -0.707107),
+ vec2(0.382684, -0.923879), vec2(-0.382683, -0.923880),
+ vec2(0.000000, -1.000000),
+ /* ROUNDBOX_TRIA_MENU - menu arrows */
+ vec2(-0.33, 0.16), vec2(0.33, 0.16), vec2(0.0, 0.82),
+ vec2(0.0, -0.82), vec2(-0.33, -0.16), vec2(0.33, -0.16),
+ /* ROUNDBOX_TRIA_CHECK - check mark */
+ vec2(-0.578579, 0.253369), vec2(-0.392773, 0.412794), vec2(-0.004241, -0.328551),
+ vec2(-0.003001, 0.034320), vec2(1.055313, 0.864744), vec2(0.866408, 1.026895),
+ /* ROUNDBOX_TRIA_HOLD_ACTION_ARROW - hold action arrows */
+#define OY (-0.2 / 2)
+#define SC (0.35 * 2)
+// vec2(-0.5 + SC, 1.0 + OY), vec2( 0.5, 1.0 + OY), vec2( 0.5, 0.0 + OY + SC),
+ vec2( 0.5 - SC, 1.0 + OY), vec2(-0.5, 1.0 + OY), vec2(-0.5, 0.0 + OY + SC)
+#undef OY
+#undef SC
+);
+
+uniform mat4 ModelViewProjectionMatrix;
+
+#define MAX_PARAM 11
+#ifdef USE_INSTANCE
+#define MAX_INSTANCE 6
+uniform vec4 parameters[MAX_PARAM * MAX_INSTANCE];
+#else
+uniform vec4 parameters[MAX_PARAM];
+#endif
+
+/* gl_InstanceID is 0 if not drawing instances. */
+#define recti parameters[gl_InstanceID * MAX_PARAM + 0]
+#define rect parameters[gl_InstanceID * MAX_PARAM + 1]
+#define radsi parameters[gl_InstanceID * MAX_PARAM + 2].x
+#define rads parameters[gl_InstanceID * MAX_PARAM + 2].y
+#define faci parameters[gl_InstanceID * MAX_PARAM + 2].zw
+#define roundCorners parameters[gl_InstanceID * MAX_PARAM + 3]
+#define colorInner1 parameters[gl_InstanceID * MAX_PARAM + 4]
+#define colorInner2 parameters[gl_InstanceID * MAX_PARAM + 5]
+#define colorEdge parameters[gl_InstanceID * MAX_PARAM + 6]
+#define colorEmboss parameters[gl_InstanceID * MAX_PARAM + 7]
+#define colorTria parameters[gl_InstanceID * MAX_PARAM + 8]
+#define tria1Center parameters[gl_InstanceID * MAX_PARAM + 9].xy
+#define tria2Center parameters[gl_InstanceID * MAX_PARAM + 9].zw
+#define tria1Size parameters[gl_InstanceID * MAX_PARAM + 10].x
+#define tria2Size parameters[gl_InstanceID * MAX_PARAM + 10].y
+#define shadeDir parameters[gl_InstanceID * MAX_PARAM + 10].z
+#define alphaDiscard parameters[gl_InstanceID * MAX_PARAM + 10].w
+
+/* We encode alpha check and discard factor together. */
+#define doAlphaCheck (alphaDiscard < 0.0)
+#define discardFactor abs(alphaDiscard)
+
+in uint vflag;
+
+noperspective out vec4 finalColor;
+noperspective out float butCo;
+flat out float discardFac;
+
+vec2 do_widget(void)
+{
+ uint cflag = vflag & CNR_FLAG_RANGE;
+ uint vofs = (vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE;
+
+ vec2 v = cornervec[cflag * 9u + vofs];
+
+ bool is_inner = (vflag & INNER_FLAG) != 0u;
+
+ /* Scale by corner radius */
+ v *= roundCorners[cflag] * ((is_inner) ? radsi : rads);
+
+ /* Position to corner */
+ vec4 rct = (is_inner) ? recti : rect;
+ if (cflag == BOTTOM_LEFT)
+ v += rct.xz;
+ else if (cflag == BOTTOM_RIGHT)
+ v += rct.yz;
+ else if (cflag == TOP_RIGHT)
+ v += rct.yw;
+ else /* (cflag == TOP_LEFT) */
+ v += rct.xw;
+
+ vec2 uv = faci * (v - recti.xz);
+
+ /* compute uv and color gradient */
+ uint color_id = (vflag >> COLOR_OFS) & COLOR_RANGE;
+ if (color_id == COLOR_INNER) {
+ float fac = clamp((shadeDir > 0.0) ? uv.y : uv.x, 0.0, 1.0);
+
+ if (doAlphaCheck) {
+ finalColor = colorInner1;
+ butCo = uv.x;
+ }
+ else {
+ finalColor = mix(colorInner2, colorInner1, fac);
+ butCo = -abs(uv.x);
+ }
+ }
+ else if (color_id == COLOR_EDGE) {
+ finalColor = colorEdge;
+ butCo = -abs(uv.x);
+ }
+ else /* (color_id == COLOR_EMBOSS) */ {
+ finalColor = colorEmboss;
+ butCo = -abs(uv.x);
+ }
+
+ bool is_emboss = (vflag & EMBOSS_FLAG) != 0u;
+ v.y -= (is_emboss) ? 1.0f : 0.0;
+
+ return v;
+}
+
+vec2 do_tria()
+{
+ uint vofs = vflag & TRIA_VEC_RANGE;
+
+ vec2 v = triavec[vofs];
+
+ finalColor = colorTria;
+ butCo = -1.0;
+
+ bool is_tria_first = (vflag & TRIA_FIRST) != 0u;
+
+ if (is_tria_first)
+ v = v * tria1Size + tria1Center;
+ else
+ v = v * tria2Size + tria2Center;
+
+ return v;
+}
+
+void main()
+{
+ discardFac = discardFactor;
+ bool is_tria = (vflag & TRIA_FLAG) != 0u;
+
+ vec2 v = (is_tria) ? do_tria() : do_widget();
+
+ /* Antialiasing offset */
+ v += jit[(vflag >> JIT_OFS) & JIT_RANGE];
+
+ gl_Position = ModelViewProjectionMatrix * vec4(v, 0.0, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl
new file mode 100644
index 00000000000..fc4d055a903
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_frag.glsl
@@ -0,0 +1,13 @@
+
+in float shadowFalloff;
+
+out vec4 fragColor;
+
+uniform float alpha;
+
+void main()
+{
+ fragColor = vec4(0.0);
+ /* Manual curve fit of the falloff curve of previous drawing method. */
+ fragColor.a = alpha * (shadowFalloff * shadowFalloff * 0.722 + shadowFalloff * 0.277);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl
new file mode 100644
index 00000000000..f6be496ac4f
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_2D_widget_shadow_vert.glsl
@@ -0,0 +1,64 @@
+#define BIT_RANGE(x) uint((1 << x) - 1)
+
+/* 2 bits for corner */
+/* Attention! Not the same order as in UI_interface.h!
+ * Ordered by drawing order. */
+#define BOTTOM_LEFT 0u
+#define BOTTOM_RIGHT 1u
+#define TOP_RIGHT 2u
+#define TOP_LEFT 3u
+#define CNR_FLAG_RANGE BIT_RANGE(2)
+
+/* 4bits for corner id */
+#define CORNER_VEC_OFS 2u
+#define CORNER_VEC_RANGE BIT_RANGE(4)
+const vec2 cornervec[36] = vec2[36](
+ vec2(0.0, 1.0), vec2(0.02, 0.805), vec2(0.067, 0.617), vec2(0.169, 0.45), vec2(0.293, 0.293), vec2(0.45, 0.169), vec2(0.617, 0.076), vec2(0.805, 0.02), vec2(1.0, 0.0),
+ vec2(-1.0, 0.0), vec2(-0.805, 0.02), vec2(-0.617, 0.067), vec2(-0.45, 0.169), vec2(-0.293, 0.293), vec2(-0.169, 0.45), vec2(-0.076, 0.617), vec2(-0.02, 0.805), vec2(0.0, 1.0),
+ vec2(0.0, -1.0), vec2(-0.02, -0.805), vec2(-0.067, -0.617), vec2(-0.169, -0.45), vec2(-0.293, -0.293), vec2(-0.45, -0.169), vec2(-0.617, -0.076), vec2(-0.805, -0.02), vec2(-1.0, 0.0),
+ vec2(1.0, 0.0), vec2(0.805, -0.02), vec2(0.617, -0.067), vec2(0.45, -0.169), vec2(0.293, -0.293), vec2(0.169, -0.45), vec2(0.076, -0.617), vec2(0.02, -0.805), vec2(0.0, -1.0)
+);
+
+#define INNER_FLAG uint(1 << 10) /* is inner vert */
+
+uniform mat4 ModelViewProjectionMatrix;
+
+uniform vec4 parameters[4];
+/* radi and rad per corner */
+#define recti parameters[0]
+#define rect parameters[1]
+#define radsi parameters[2].x
+#define rads parameters[2].y
+#define roundCorners parameters[3]
+
+in uint vflag;
+
+out float shadowFalloff;
+
+void main()
+{
+ uint cflag = vflag & CNR_FLAG_RANGE;
+ uint vofs = (vflag >> CORNER_VEC_OFS) & CORNER_VEC_RANGE;
+
+ vec2 v = cornervec[cflag * 9u + vofs];
+
+ bool is_inner = (vflag & INNER_FLAG) != 0u;
+
+ shadowFalloff = (is_inner) ? 1.0 : 0.0;
+
+ /* Scale by corner radius */
+ v *= roundCorners[cflag] * ((is_inner) ? radsi : rads);
+
+ /* Position to corner */
+ vec4 rct = (is_inner) ? recti : rect;
+ if (cflag == BOTTOM_LEFT)
+ v += rct.xz;
+ else if (cflag == BOTTOM_RIGHT)
+ v += rct.yz;
+ else if (cflag == TOP_RIGHT)
+ v += rct.yw;
+ else /* (cflag == TOP_LEFT) */
+ v += rct.xw;
+
+ gl_Position = ModelViewProjectionMatrix * vec4(v, 0.0, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl
new file mode 100644
index 00000000000..84e44837264
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_clipped_uniform_color_vert.glsl
@@ -0,0 +1,12 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat4 ModelMatrix;
+uniform vec4 ClipPlane;
+
+in vec3 pos;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_ClipDistance[0] = dot(ModelMatrix * vec4(pos, 1.0), ClipPlane);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
new file mode 100644
index 00000000000..7db7e28d8e6
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_flat_color_vert.glsl
@@ -0,0 +1,26 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+#if defined(USE_COLOR_U32)
+in uint color;
+#else
+in vec4 color;
+#endif
+
+flat out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+#if defined(USE_COLOR_U32)
+ finalColor = vec4(
+ ((color ) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 8) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 16) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 24) ) * (1.0f / 255.0f));
+#else
+ finalColor = color;
+#endif
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl b/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl
new file mode 100644
index 00000000000..f16fa21b342
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_groundline_geom.glsl
@@ -0,0 +1,16 @@
+
+/* Make to be used with dynamic batching so no Model Matrix needed */
+uniform mat4 ViewProjectionMatrix;
+
+layout(points) in;
+layout(line_strip, max_vertices = 2) out;
+
+void main()
+{
+ vec3 vert = gl_in[0].gl_Position.xyz;
+ gl_Position = ViewProjectionMatrix * vec4(vert.xyz, 1.0);
+ EmitVertex();
+ gl_Position = ViewProjectionMatrix * vec4(vert.xy, 0.0, 1.0);
+ EmitVertex();
+ EndPrimitive();
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl
new file mode 100644
index 00000000000..55f410eb25d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_groundpoint_vert.glsl
@@ -0,0 +1,11 @@
+
+/* Made to be used with dynamic batching so no Model Matrix needed */
+uniform mat4 ViewProjectionMatrix;
+
+in vec3 pos;
+
+void main()
+{
+ gl_Position = ViewProjectionMatrix * vec4(pos.xy, 0.0, 1.0);
+ gl_PointSize = 2.0;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
new file mode 100644
index 00000000000..eb877ab20b6
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_image_vert.glsl
@@ -0,0 +1,12 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec2 texCoord;
+in vec3 pos;
+out vec2 texCoord_interp;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos.xyz, 1.0f);
+ texCoord_interp = texCoord;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl
new file mode 100644
index 00000000000..84fbf977846
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_legacy_vert.glsl
@@ -0,0 +1,26 @@
+
+/*
+ * Vertex Shader for dashed lines with 3D coordinates, with uniform multi-colors or uniform single-color,
+ * and unary thickness.
+ *
+ * Legacy version, without geometry shader support, always produce solid lines!
+ */
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform vec2 viewport_size;
+
+uniform vec4 color;
+
+in vec3 pos;
+noperspective out float distance_along_line;
+noperspective out vec4 color_geom;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ /* Hack - prevent stupid GLSL compiler to optimize out unused viewport_size uniform, which gives crash! */
+ distance_along_line = viewport_size.x * 0.000001f - viewport_size.x * 0.0000009f;
+
+ color_geom = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
new file mode 100644
index 00000000000..2fe08896585
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_line_dashed_uniform_color_vert.glsl
@@ -0,0 +1,21 @@
+
+/*
+ * Vertex Shader for dashed lines with 3D coordinates, with uniform multi-colors or uniform single-color,
+ * and unary thickness.
+ *
+ * Dashed is performed in screen space.
+ */
+
+uniform mat4 ModelViewProjectionMatrix;
+
+uniform vec4 color;
+
+in vec3 pos;
+
+out vec4 color_vert;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ color_vert = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
new file mode 100644
index 00000000000..e6b8fed7265
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_normal_smooth_color_vert.glsl
@@ -0,0 +1,22 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat3 NormalMatrix;
+
+in vec3 pos;
+in vec3 nor;
+in vec4 color;
+
+#ifdef USE_FLAT_NORMAL
+flat out vec3 normal;
+flat out vec4 finalColor;
+#else
+out vec3 normal;
+out vec4 finalColor;
+#endif
+
+void main()
+{
+ normal = normalize(NormalMatrix * nor);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
new file mode 100644
index 00000000000..a3f447a85f9
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_normal_vert.glsl
@@ -0,0 +1,13 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat3 NormalMatrix;
+
+in vec3 pos;
+in vec3 nor;
+out vec3 normal;
+
+void main()
+{
+ normal = normalize(NormalMatrix * nor);
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl
new file mode 100644
index 00000000000..60793bf56b6
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_passthrough_vert.glsl
@@ -0,0 +1,8 @@
+
+/* Does Nothing */
+in vec3 pos;
+
+void main()
+{
+ gl_Position = vec4(pos, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl
new file mode 100644
index 00000000000..2fe9c0623fa
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_fixed_size_varying_color_vert.glsl
@@ -0,0 +1,12 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in vec4 color;
+out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl
new file mode 100644
index 00000000000..ebc945fcf35
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_aa_vert.glsl
@@ -0,0 +1,21 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform float size;
+
+in vec3 pos;
+out vec2 radii;
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_PointSize = size;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+
+ // convert to PointCoord units
+ radii /= size;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl
new file mode 100644
index 00000000000..0d6b90cfba4
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_uniform_size_outline_aa_vert.glsl
@@ -0,0 +1,24 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+uniform float size;
+uniform float outlineWidth;
+
+in vec3 pos;
+out vec4 radii;
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_PointSize = size;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * size;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - 1.0;
+ radii[2] = radius - outlineWidth;
+ radii[3] = radius - outlineWidth - 1.0;
+
+ // convert to PointCoord units
+ radii /= size;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl
new file mode 100644
index 00000000000..e14b9535c89
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_varying_color_vert.glsl
@@ -0,0 +1,14 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in float size;
+in vec4 color;
+out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_PointSize = size;
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl
new file mode 100644
index 00000000000..e4f173ab617
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_point_varying_size_vert.glsl
@@ -0,0 +1,11 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in float size;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ gl_PointSize = size;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
new file mode 100644
index 00000000000..41fdefd22e8
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_frag.glsl
@@ -0,0 +1,8 @@
+
+in vec4 finalColor;
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = finalColor;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
new file mode 100644
index 00000000000..a1feb2f75b7
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_smooth_color_vert.glsl
@@ -0,0 +1,13 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in vec4 color;
+
+out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
new file mode 100644
index 00000000000..059473ebb74
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_3D_vert.glsl
@@ -0,0 +1,9 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+
+void main()
+{
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
index 01a335af048..5f7455582cd 100644
--- a/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_basic_frag.glsl
@@ -20,12 +20,10 @@
#define STIPPLE_HEXAGON 3
#define STIPPLE_DIAG_STRIPES 4
#define STIPPLE_DIAG_STRIPES_SWAP 5
-#define STIPPLE_S3D_INTERLACE_ROW 6
-#define STIPPLE_S3D_INTERLACE_ROW_SWAP 7
-#define STIPPLE_S3D_INTERLACE_COLUMN 8
-#define STIPPLE_S3D_INTERLACE_COLUMN_SWAP 9
-#define STIPPLE_S3D_INTERLACE_CHECKERBOARD 10
-#define STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP 11
+
+#ifndef NO_SPECULAR
+uniform mat4 ProjectionMatrix;
+#endif
#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
#if defined(USE_FLAT_NORMAL)
@@ -58,7 +56,7 @@ uniform sampler2D_default texture_map;
#ifdef USE_STIPPLE
uniform int stipple_id;
#if defined(DRAW_LINE)
-varying in float t;
+varying float t;
uniform int stipple_pattern;
#endif
#endif
@@ -74,14 +72,9 @@ void main()
/* We have to use mod function and integer casting.
* This can be optimized further with the bitwise operations
* when GLSL 1.3 is supported. */
- if (stipple_id == STIPPLE_HALFTONE ||
- stipple_id == STIPPLE_S3D_INTERLACE_CHECKERBOARD ||
- stipple_id == STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP)
- {
+ if (stipple_id == STIPPLE_HALFTONE) {
int result = int(mod(gl_FragCoord.x + gl_FragCoord.y, 2));
bool dis = result == 0;
- if (stipple_id == STIPPLE_S3D_INTERLACE_CHECKERBOARD_SWAP)
- dis = !dis;
if (dis)
discard;
}
@@ -116,22 +109,6 @@ void main()
if (!((16 - modx > mody && mody > 8 - modx) || mody > 24 - modx))
discard;
}
- else if (stipple_id == STIPPLE_S3D_INTERLACE_ROW || stipple_id == STIPPLE_S3D_INTERLACE_ROW_SWAP) {
- int result = int(mod(gl_FragCoord.y, 2));
- bool dis = result == 0;
- if (stipple_id == STIPPLE_S3D_INTERLACE_ROW_SWAP)
- dis = !dis;
- if (dis)
- discard;
- }
- else if (stipple_id == STIPPLE_S3D_INTERLACE_COLUMN || stipple_id == STIPPLE_S3D_INTERLACE_COLUMN_SWAP) {
- int result = int(mod(gl_FragCoord.x, 2));
- bool dis = result != 0;
- if (stipple_id == STIPPLE_S3D_INTERLACE_COLUMN_SWAP)
- dis = !dis;
- if (dis)
- discard;
- }
else if (stipple_id == STIPPLE_HEXAGON) {
int mody = int(mod(gl_FragCoord.y, 2));
int modx = int(mod(gl_FragCoord.x, 4));
@@ -190,7 +167,7 @@ void main()
#ifndef NO_SPECULAR
/* view vector computation, depends on orthographics or perspective */
- vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position) : vec3(0.0, 0.0, -1.0);
+ vec3 V = (ProjectionMatrix[3][3] == 0.0) ? normalize(varying_position) : vec3(0.0, 0.0, -1.0);
#endif
for (int i = 0; i < NUM_SCENE_LIGHTS; i++) {
diff --git a/source/blender/gpu/shaders/gpu_shader_basic_geom.glsl b/source/blender/gpu/shaders/gpu_shader_basic_geom.glsl
index a88681a5fd3..13f05b340bf 100644
--- a/source/blender/gpu/shaders/gpu_shader_basic_geom.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_basic_geom.glsl
@@ -14,9 +14,9 @@ layout(line_strip, max_vertices = 10) out;
layout(triangle_strip, max_vertices = 6) out;
#endif
-varying out float t;
-varying in vec4 varying_vertex_color_line[];
-varying out vec4 varying_vertex_color;
+out float t;
+in vec4 varying_vertex_color_line[];
+out vec4 varying_vertex_color;
uniform ivec4 viewport;
uniform float line_width;
diff --git a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
index 42fbdadf1d1..dbf6c267f14 100644
--- a/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_basic_vert.glsl
@@ -1,4 +1,8 @@
+uniform mat4 ModelViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform mat3 NormalMatrix;
+
#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
#if defined(USE_FLAT_NORMAL)
varying vec3 eyespace_vert_pos;
@@ -29,15 +33,15 @@ varying float gl_ClipDistance[6];
void main()
{
- vec4 co = gl_ModelViewMatrix * gl_Vertex;
+ vec4 co = ModelViewMatrix * gl_Vertex;
#if defined(USE_SOLID_LIGHTING) || defined(USE_SCENE_LIGHTING)
#if !defined(USE_FLAT_NORMAL)
- varying_normal = normalize(gl_NormalMatrix * gl_Normal);
+ varying_normal = normalize(NormalMatrix * gl_Normal);
#endif
#if defined(USE_FLAT_NORMAL)
/* transform vertex into eyespace */
- eyespace_vert_pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
+ eyespace_vert_pos = (ModelViewMatrix * gl_Vertex).xyz;
#endif
#ifndef USE_SOLID_LIGHTING
@@ -45,7 +49,7 @@ void main()
#endif
#endif
- gl_Position = gl_ProjectionMatrix * co;
+ gl_Position = ProjectionMatrix * co;
#ifdef CLIP_WORKAROUND
int i;
diff --git a/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl b/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl
new file mode 100644
index 00000000000..545f6d19e21
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_checker_frag.glsl
@@ -0,0 +1,20 @@
+
+uniform vec4 color1;
+uniform vec4 color2;
+uniform int size;
+
+out vec4 fragColor;
+
+void main()
+{
+ vec2 phase = mod(gl_FragCoord.xy, (size*2));
+
+ if ((phase.x > size && phase.y < size) ||
+ (phase.x < size && phase.y > size))
+ {
+ fragColor = color1;
+ }
+ else {
+ fragColor = color2;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl b/source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl
new file mode 100644
index 00000000000..60e71e19004
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_depth_only_frag.glsl
@@ -0,0 +1,6 @@
+
+void main()
+{
+ // no color output, only depth (line below is implicit)
+ // gl_FragDepth = gl_FragCoord.z;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl b/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl
new file mode 100644
index 00000000000..beb71c58100
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_diag_stripes_frag.glsl
@@ -0,0 +1,20 @@
+
+uniform vec4 color1;
+uniform vec4 color2;
+uniform int size1;
+uniform int size2;
+
+out vec4 fragColor;
+
+void main()
+{
+ float phase = mod((gl_FragCoord.x + gl_FragCoord.y), (size1 + size2));
+
+ if (phase < size1)
+ {
+ fragColor = color1;
+ }
+ else {
+ fragColor = color2;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl
new file mode 100644
index 00000000000..4ed7ed56c11
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_ortho_vert.glsl
@@ -0,0 +1,54 @@
+
+// Draw "fancy" wireframe, displaying front-facing, back-facing and
+// silhouette lines differently.
+// Mike Erwin, April 2015
+
+uniform bool drawFront = true;
+uniform bool drawBack = true;
+uniform bool drawSilhouette = true;
+
+uniform vec4 frontColor;
+uniform vec4 backColor;
+uniform vec4 silhouetteColor;
+
+uniform vec3 eye; // direction we are looking
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+
+// normals of faces this edge joins (object coords)
+in vec3 N1;
+in vec3 N2;
+
+flat out vec4 finalColor;
+
+// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
+
+// to discard an entire line, set both endpoints to nowhere
+// and it won't produce any fragments
+const vec4 nowhere = vec4(vec3(0.0), 1.0);
+
+void main()
+{
+ bool face_1_front = dot(N1, eye) > 0.0;
+ bool face_2_front = dot(N2, eye) > 0.0;
+
+ vec4 position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ if (face_1_front && face_2_front) {
+ // front-facing edge
+ gl_Position = drawFront ? position : nowhere;
+ finalColor = frontColor;
+ }
+ else if (face_1_front || face_2_front) {
+ // exactly one face is front-facing, silhouette edge
+ gl_Position = drawSilhouette ? position : nowhere;
+ finalColor = silhouetteColor;
+ }
+ else {
+ // back-facing edge
+ gl_Position = drawBack ? position : nowhere;
+ finalColor = backColor;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl
new file mode 100644
index 00000000000..e7632fcad15
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_geom.glsl
@@ -0,0 +1,60 @@
+
+// Draw "fancy" wireframe, displaying front-facing, back-facing and
+// silhouette lines differently.
+// Mike Erwin, April 2015
+
+// After working with this shader a while, convinced we should make
+// separate shaders for perpective & ortho. (Oct 2016)
+
+// Due to perspective, the line segment's endpoints might disagree on
+// whether the adjacent faces are front facing. This geometry shader
+// decides which edge type to use if endpoints disagree.
+
+uniform mat4 ProjectionMatrix;
+
+uniform bool drawFront = true;
+uniform bool drawBack = true;
+uniform bool drawSilhouette = true;
+
+uniform vec4 frontColor;
+uniform vec4 backColor;
+uniform vec4 silhouetteColor;
+
+layout(lines) in;
+layout(line_strip, max_vertices = 2) out;
+
+in vec4 MV_pos[];
+in float edgeClass[];
+
+flat out vec4 finalColor;
+
+void emitLine(vec4 color)
+{
+ gl_Position = ProjectionMatrix * MV_pos[0];
+ EmitVertex();
+ gl_Position = ProjectionMatrix * MV_pos[1];
+ finalColor = color;
+ EmitVertex();
+ EndPrimitive();
+}
+
+void main()
+{
+ float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
+
+ if (finalEdgeClass > 0.0f) {
+ // front-facing edge
+ if (drawFront)
+ emitLine(frontColor);
+ }
+ else if (finalEdgeClass < 0.0f) {
+ // back-facing edge
+ if (drawBack)
+ emitLine(backColor);
+ }
+ else {
+ // exactly one face is front-facing, silhouette edge
+ if (drawSilhouette)
+ emitLine(silhouetteColor);
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl
new file mode 100644
index 00000000000..30b3bdb890d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_legacy_vert.glsl
@@ -0,0 +1,68 @@
+
+// Draw "fancy" wireframe, displaying front-facing, back-facing and
+// silhouette lines differently.
+// Mike Erwin, April 2015
+
+// After working with this shader a while, convinced we should make
+// separate shaders for perpective & ortho. (Oct 2016)
+
+// This shader is an imperfect stepping stone until all platforms are
+// ready for geometry shaders.
+
+// Due to perspective, the line segment's endpoints might disagree on
+// whether the adjacent faces are front facing. Need to use a geometry
+// shader or pass in an extra position attribute (the other endpoint)
+// to do this properly.
+
+uniform bool drawFront = true;
+uniform bool drawBack = true;
+uniform bool drawSilhouette = true;
+
+uniform vec4 frontColor;
+uniform vec4 backColor;
+uniform vec4 silhouetteColor;
+
+uniform mat4 ModelViewMatrix;
+uniform mat4 ModelViewProjectionMatrix;
+uniform mat3 NormalMatrix;
+
+in vec3 pos;
+
+// normals of faces this edge joins (object coords)
+in vec3 N1;
+in vec3 N2;
+
+flat out vec4 finalColor;
+
+// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
+
+// to discard an entire line, set its color to invisible
+// (must have GL_BLEND enabled, or discard in fragment shader)
+const vec4 invisible = vec4(0.0);
+
+bool front(vec3 N)
+{
+ vec4 xformed = ModelViewMatrix * vec4(pos, 1.0);
+ return dot(NormalMatrix * N, normalize(-xformed.xyz)) > 0.0;
+}
+
+void main()
+{
+ bool face_1_front = front(N1);
+ bool face_2_front = front(N2);
+
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+
+ if (face_1_front && face_2_front) {
+ // front-facing edge
+ finalColor = drawFront ? frontColor : invisible;
+ }
+ else if (face_1_front || face_2_front) {
+ // exactly one face is front-facing, silhouette edge
+ finalColor = drawSilhouette ? silhouetteColor : invisible;
+ }
+ else {
+ // back-facing edge
+ finalColor = drawBack ? backColor : invisible;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl
new file mode 100644
index 00000000000..e1fb78dd1a9
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_front_back_persp_vert.glsl
@@ -0,0 +1,44 @@
+
+// Draw "fancy" wireframe, displaying front-facing, back-facing and
+// silhouette lines differently.
+// Mike Erwin, April 2015
+
+// After working with this shader a while, convinced we should make
+// separate shaders for perpective & ortho. (Oct 2016)
+
+// Due to perspective, the line segment's endpoints might disagree on
+// whether the adjacent faces are front facing. We use a geometry
+// shader to resolve this properly.
+
+uniform mat4 ModelViewMatrix;
+uniform mat3 NormalMatrix;
+
+in vec3 pos;
+in vec3 N1, N2; // normals of faces this edge joins (object coords)
+
+out vec4 MV_pos;
+out float edgeClass;
+
+// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
+
+bool front(vec3 N, vec3 eye)
+{
+ return dot(NormalMatrix * N, eye) > 0.0;
+}
+
+void main()
+{
+ MV_pos = ModelViewMatrix * vec4(pos, 1.0);
+
+ vec3 eye = normalize(-MV_pos.xyz);
+
+ bool face_1_front = front(N1, eye);
+ bool face_2_front = front(N2, eye);
+
+ if (face_1_front && face_2_front)
+ edgeClass = 1.0; // front-facing edge
+ else if (face_1_front || face_2_front)
+ edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
+ else
+ edgeClass = -1.0; // back-facing edge
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl
new file mode 100644
index 00000000000..0538c037dcf
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_frag.glsl
@@ -0,0 +1,20 @@
+
+#define SMOOTH 1
+
+const float transitionWidth = 1.0;
+
+uniform vec4 fillColor = vec4(0);
+uniform vec4 outlineColor = vec4(0,0,0,1);
+
+noperspective in vec3 distanceToOutline;
+
+out vec4 FragColor;
+
+void main() {
+ float edgeness = min(min(distanceToOutline.x, distanceToOutline.y), distanceToOutline.z);
+#if SMOOTH
+ FragColor = mix(outlineColor, fillColor, smoothstep(0, transitionWidth, edgeness));
+#else
+ FragColor = (edgeness <= 0) ? outlineColor : fillColor;
+#endif
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl
new file mode 100644
index 00000000000..ad0dccb6c81
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_geom.glsl
@@ -0,0 +1,67 @@
+layout(triangles) in;
+layout(triangle_strip, max_vertices=3) out;
+
+uniform float outlineWidth = 1.0;
+uniform vec2 viewportSize;
+
+in vec4 pos_xformed[];
+in float widthModulator[];
+
+noperspective out vec3 distanceToOutline;
+
+// project to screen space
+vec2 proj(int axis) {
+ vec4 pos = pos_xformed[axis];
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+float dist(vec2 pos[3], int v) {
+ // current vertex position
+ vec2 vpos = pos[v];
+ // endpoints of opposite edge
+ vec2 e1 = pos[(v + 1) % 3];
+ vec2 e2 = pos[(v + 2) % 3];
+
+ float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
+ return abs_det / distance(e2, e1);
+}
+
+vec3 distance[3];
+
+void clearEdge(int v) {
+ float distant = 10 * outlineWidth;
+ for (int i = 0; i < 3; ++i)
+ distance[i][v] += distant;
+}
+
+void modulateEdge(int v) {
+ float offset = min(widthModulator[v],1) * outlineWidth;
+ for (int i = 0; i < 3; ++i)
+ distance[i][v] -= offset;
+}
+
+void main() {
+ vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
+
+ for (int v = 0; v < 3; ++v)
+ distance[v] = vec3(0);
+
+ for (int v = 0; v < 3; ++v) {
+ if (widthModulator[v] > 0) {
+ distance[v][v] = dist(pos, v);
+ modulateEdge(v);
+ }
+ }
+
+ for (int v = 0; v < 3; ++v)
+ if (widthModulator[v] <= 0)
+ clearEdge(v);
+
+ for (int v = 0; v < 3; ++v) {
+ gl_Position = pos_xformed[v];
+ distanceToOutline = distance[v];
+ EmitVertex();
+ }
+
+ EndPrimitive();
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl
new file mode 100644
index 00000000000..ec692e210c2
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_simple_geom.glsl
@@ -0,0 +1,52 @@
+layout(triangles) in;
+layout(triangle_strip, max_vertices=3) out;
+
+uniform float outlineWidth = 1.0;
+uniform vec2 viewportSize;
+
+noperspective out vec3 distanceToOutline;
+
+// project to screen space
+vec2 proj(int axis) {
+ vec4 pos = gl_in[axis].gl_Position;
+ return (0.5 * (pos.xy / pos.w) + 0.5) * viewportSize;
+}
+
+float dist(vec2 pos[3], int v) {
+ // current vertex position
+ vec2 vpos = pos[v];
+ // endpoints of opposite edge
+ vec2 e1 = pos[(v + 1) % 3];
+ vec2 e2 = pos[(v + 2) % 3];
+
+ float abs_det = length(cross(vec3(vpos - e1, 0), vec3(vpos - e2, 0))); // could simplify
+ return abs_det / distance(e2, e1);
+}
+
+vec3 distance[3];
+
+void modulateEdge(int v) {
+ float offset = 0.5 * outlineWidth;
+ for (int i = 0; i < 3; ++i)
+ distance[i][v] -= offset;
+}
+
+void main() {
+ vec2 pos[3] = vec2[3](proj(0), proj(1), proj(2));
+
+ for (int v = 0; v < 3; ++v)
+ distance[v] = vec3(0);
+
+ for (int v = 0; v < 3; ++v) {
+ distance[v][v] = dist(pos, v);
+ modulateEdge(v);
+ }
+
+ for (int v = 0; v < 3; ++v) {
+ gl_Position = gl_in[v].gl_Position;
+ distanceToOutline = distance[v];
+ EmitVertex();
+ }
+
+ EndPrimitive();
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl b/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
new file mode 100644
index 00000000000..fb1d0aafe05
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_edges_overlay_vert.glsl
@@ -0,0 +1,13 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec3 pos;
+in float edgeWidthModulator;
+
+out vec4 pos_xformed;
+out float widthModulator;
+
+void main() {
+ pos_xformed = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ widthModulator = edgeWidthModulator;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl
index 3819203bcd9..fc9cafb6b02 100644
--- a/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fire_frag.glsl
@@ -1,17 +1,15 @@
-varying vec3 coords;
+in vec3 coords;
+out vec4 fragColor;
uniform sampler3D flame_texture;
uniform sampler1D spectrum_texture;
void main()
{
- float flame = texture3D(flame_texture, coords).r;
- vec4 emission = texture1D(spectrum_texture, flame);
+ float flame = texture(flame_texture, coords).r;
+ vec4 emission = texture(spectrum_texture, flame);
- vec4 color;
- color.rgb = emission.a * emission.rgb;
- color.a = emission.a;
-
- gl_FragColor = color;
+ fragColor.rgb = emission.a * emission.rgb;
+ fragColor.a = emission.a;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl
new file mode 100644
index 00000000000..cefae1021d2
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_flat_color_alpha_test_0_frag.glsl
@@ -0,0 +1,11 @@
+
+flat in vec4 finalColor;
+out vec4 fragColor;
+
+void main()
+{
+ if (finalColor.a > 0.0)
+ fragColor = finalColor;
+ else
+ discard;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
new file mode 100644
index 00000000000..d738ed5ddb2
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_flat_color_frag.glsl
@@ -0,0 +1,8 @@
+
+flat in vec4 finalColor;
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = finalColor;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl b/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl
new file mode 100644
index 00000000000..aa6f30531ae
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_flat_id_frag.glsl
@@ -0,0 +1,8 @@
+
+flat in uint finalId;
+out uint fragId;
+
+void main()
+{
+ fragId = finalId;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl b/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl
index e04cd7d3306..c4e7cff2b0b 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_depth_resolve.glsl
@@ -1,9 +1,10 @@
uniform sampler2D depthbuffer;
-varying vec4 uvcoordsvar;
+
+in vec4 uvcoordsvar;
void main(void)
{
- float depth = texture2D(depthbuffer, uvcoordsvar.xy).r;
+ float depth = texture(depthbuffer, uvcoordsvar.xy).r;
/* XRay background, discard */
if (depth >= 1.0) {
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
index 338ef6d51a7..15d30e75969 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_frag.glsl
@@ -17,17 +17,18 @@ uniform vec4 dof_params;
uniform vec4 viewvecs[3];
// coordinates on framebuffer in normalized (0.0-1.0) uv space
-varying vec4 uvcoordsvar;
+in vec4 uvcoordsvar;
/* color texture coordinates, offset by a small amount */
-varying vec2 color_uv1;
-varying vec2 color_uv2;
+in vec2 color_uv1;
+in vec2 color_uv2;
-varying vec2 depth_uv1;
-varying vec2 depth_uv2;
-varying vec2 depth_uv3;
-varying vec2 depth_uv4;
+in vec2 depth_uv1;
+in vec2 depth_uv2;
+in vec2 depth_uv3;
+in vec2 depth_uv4;
+out vec4 FragColor;
float calculate_far_coc(in float zdepth)
{
@@ -63,85 +64,85 @@ void first_pass()
offset_row[2] = 3.0 * offset_row[0];
/* heavily blur the image */
- vec4 color = texture2D(colorbuffer, color_uv1);
- color += texture2D(colorbuffer, color_uv1 + offset_row[1]);
- color += texture2D(colorbuffer, color_uv2);
- color += texture2D(colorbuffer, color_uv2 + offset_row[1]);
+ vec4 color = texture(colorbuffer, color_uv1);
+ color += texture(colorbuffer, color_uv1 + offset_row[1]);
+ color += texture(colorbuffer, color_uv2);
+ color += texture(colorbuffer, color_uv2 + offset_row[1]);
color /= 4.0;
- depth.r = texture2D(depthbuffer, depth_uv1).r;
- depth.g = texture2D(depthbuffer, depth_uv2).r;
- depth.b = texture2D(depthbuffer, depth_uv3).r;
- depth.a = texture2D(depthbuffer, depth_uv4).r;
+ depth.r = texture(depthbuffer, depth_uv1).r;
+ depth.g = texture(depthbuffer, depth_uv2).r;
+ depth.b = texture(depthbuffer, depth_uv3).r;
+ depth.a = texture(depthbuffer, depth_uv4).r;
zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
coc = calculate_near_coc(zdepth);
- depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[0]).r;
- depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[0]).r;
- depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[0]).r;
- depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[0]).r;
+ depth.r = texture(depthbuffer, depth_uv1 + offset_row[0]).r;
+ depth.g = texture(depthbuffer, depth_uv2 + offset_row[0]).r;
+ depth.b = texture(depthbuffer, depth_uv3 + offset_row[0]).r;
+ depth.a = texture(depthbuffer, depth_uv4 + offset_row[0]).r;
zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
coc = max(calculate_near_coc(zdepth), coc);
- depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[1]).r;
- depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[1]).r;
- depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[1]).r;
- depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[1]).r;
+ depth.r = texture(depthbuffer, depth_uv1 + offset_row[1]).r;
+ depth.g = texture(depthbuffer, depth_uv2 + offset_row[1]).r;
+ depth.b = texture(depthbuffer, depth_uv3 + offset_row[1]).r;
+ depth.a = texture(depthbuffer, depth_uv4 + offset_row[1]).r;
zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
coc = max(calculate_near_coc(zdepth), coc);
- depth.r = texture2D(depthbuffer, depth_uv1 + offset_row[2]).r;
- depth.g = texture2D(depthbuffer, depth_uv2 + offset_row[2]).r;
- depth.b = texture2D(depthbuffer, depth_uv3 + offset_row[2]).r;
- depth.a = texture2D(depthbuffer, depth_uv4 + offset_row[2]).r;
+ depth.r = texture(depthbuffer, depth_uv1 + offset_row[2]).r;
+ depth.g = texture(depthbuffer, depth_uv2 + offset_row[2]).r;
+ depth.b = texture(depthbuffer, depth_uv3 + offset_row[2]).r;
+ depth.a = texture(depthbuffer, depth_uv4 + offset_row[2]).r;
zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
coc = max(calculate_near_coc(zdepth), coc);
final_coc = max(max(coc.x, coc.y), max(coc.z, coc.w));
- gl_FragColor = vec4(color.rgb, final_coc);
+ FragColor = vec4(color.rgb, final_coc);
}
/* second pass, gaussian blur the downsampled image */
void second_pass()
{
- vec4 depth = vec4(texture2D(depthbuffer, uvcoordsvar.xy).r);
+ vec4 depth = vec4(texture(depthbuffer, uvcoordsvar.xy).r);
/* clever sampling to sample 2 pixels at once. Of course it's not real gaussian sampling this way */
- vec4 color = texture2D(colorbuffer, uvcoordsvar.xy) * 0.3125;
- color += texture2D(colorbuffer, uvcoordsvar.xy + invrendertargetdim) * 0.234375;
- color += texture2D(colorbuffer, uvcoordsvar.xy + 2.5 * invrendertargetdim) * 0.09375;
- color += texture2D(colorbuffer, uvcoordsvar.xy + 4.5 * invrendertargetdim) * 0.015625;
- color += texture2D(colorbuffer, uvcoordsvar.xy - invrendertargetdim) * 0.234375;
- color += texture2D(colorbuffer, uvcoordsvar.xy - 2.5 * invrendertargetdim) * 0.09375;
- color += texture2D(colorbuffer, uvcoordsvar.xy - 4.5 * invrendertargetdim) * 0.015625;
-
- gl_FragColor = color;
+ vec4 color = texture(colorbuffer, uvcoordsvar.xy) * 0.3125;
+ color += texture(colorbuffer, uvcoordsvar.xy + invrendertargetdim) * 0.234375;
+ color += texture(colorbuffer, uvcoordsvar.xy + 2.5 * invrendertargetdim) * 0.09375;
+ color += texture(colorbuffer, uvcoordsvar.xy + 4.5 * invrendertargetdim) * 0.015625;
+ color += texture(colorbuffer, uvcoordsvar.xy - invrendertargetdim) * 0.234375;
+ color += texture(colorbuffer, uvcoordsvar.xy - 2.5 * invrendertargetdim) * 0.09375;
+ color += texture(colorbuffer, uvcoordsvar.xy - 4.5 * invrendertargetdim) * 0.015625;
+
+ FragColor = color;
}
/* third pass, calculate the final coc from blurred and unblurred images */
void third_pass()
{
- vec4 color = texture2D(colorbuffer, uvcoordsvar.xy);
- vec4 color_blurred = texture2D(blurredcolorbuffer, uvcoordsvar.xy);
+ vec4 color = texture(colorbuffer, uvcoordsvar.xy);
+ vec4 color_blurred = texture(blurredcolorbuffer, uvcoordsvar.xy);
float coc = 2.0 * max(color_blurred.a, color.a); -color.a;
- gl_FragColor = vec4(color.rgb, coc);
+ FragColor = vec4(color.rgb, coc);
}
/* fourth pass, blur the final coc once to get rid of discontinuities */
void fourth_pass()
{
- vec4 color = texture2D(colorbuffer, uvcoordsvar.xz);
- color += texture2D(colorbuffer, uvcoordsvar.yz);
- color += texture2D(colorbuffer, uvcoordsvar.xw);
- color += texture2D(colorbuffer, uvcoordsvar.yw);
+ vec4 color = texture(colorbuffer, uvcoordsvar.xz);
+ color += texture(colorbuffer, uvcoordsvar.yz);
+ color += texture(colorbuffer, uvcoordsvar.xw);
+ color += texture(colorbuffer, uvcoordsvar.yw);
- gl_FragColor = color / 4.0;
+ FragColor = color / 4.0;
}
vec4 small_sample_blur(in sampler2D colorbuffer, in vec2 uv, in vec4 color)
@@ -150,10 +151,10 @@ vec4 small_sample_blur(in sampler2D colorbuffer, in vec2 uv, in vec4 color)
vec4 result = weight * color;
weight *= 4.0;
- result += weight * texture2D(colorbuffer, uv + color_uv1.xy);
- result += weight * texture2D(colorbuffer, uv - color_uv1.xy);
- result += weight * texture2D(colorbuffer, uv + color_uv1.yx);
- result += weight * texture2D(colorbuffer, uv - color_uv1.yx);
+ result += weight * texture(colorbuffer, uv + color_uv1.xy);
+ result += weight * texture(colorbuffer, uv - color_uv1.xy);
+ result += weight * texture(colorbuffer, uv + color_uv1.yx);
+ result += weight * texture(colorbuffer, uv - color_uv1.yx);
return result;
}
@@ -163,11 +164,11 @@ vec4 small_sample_blur(in sampler2D colorbuffer, in vec2 uv, in vec4 color)
void fifth_pass()
{
vec4 factors;
- vec4 color_orig = texture2D(colorbuffer, uvcoordsvar.xy);
- vec4 highblurred = texture2D(blurredcolorbuffer, uvcoordsvar.xy);
- vec4 mediumblurred = texture2D(mblurredcolorbuffer, uvcoordsvar.xy);
+ vec4 color_orig = texture(colorbuffer, uvcoordsvar.xy);
+ vec4 highblurred = texture(blurredcolorbuffer, uvcoordsvar.xy);
+ vec4 mediumblurred = texture(mblurredcolorbuffer, uvcoordsvar.xy);
vec4 smallblurred = small_sample_blur(colorbuffer, uvcoordsvar.xy, color_orig);
- float depth = texture2D(depthbuffer, uvcoordsvar.xy).r;
+ float depth = texture(depthbuffer, uvcoordsvar.xy).r;
float zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), vec4(depth)).r;
float coc_far = clamp(calculate_far_coc(zdepth), 0.0, 1.0);
@@ -188,7 +189,7 @@ void fifth_pass()
color /= dot(factors, vec4(1.0));
/* using original color is not correct, but use that for now because alpha of
* blurred buffers uses CoC instead */
- gl_FragColor = vec4(color.rgb, color_orig.a);
+ FragColor = vec4(color.rgb, color_orig.a);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl
index 182113367d3..c41c1d0820b 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_frag.glsl
@@ -14,24 +14,28 @@ uniform sampler2D depthbuffer;
uniform sampler2D cocbuffer;
-/* this includes focal distance in x and aperture size in y */
+/* this includes aperture size in x and focal distance in y */
uniform vec4 dof_params;
/* viewvectors for reconstruction of world space */
uniform vec4 viewvecs[3];
/* initial uv coordinate */
-varying vec2 uvcoord;
+in vec2 uvcoord;
/* coordinate used for calculating radius et al set in geometry shader */
-varying vec2 particlecoord;
-varying vec4 color;
+in vec2 particlecoord;
+flat in vec4 color;
/* downsampling coordinates */
-varying vec2 downsample1;
-varying vec2 downsample2;
-varying vec2 downsample3;
-varying vec2 downsample4;
+in vec2 downsample1;
+in vec2 downsample2;
+in vec2 downsample3;
+in vec2 downsample4;
+
+layout(location = 0) out vec4 fragData0;
+layout(location = 1) out vec4 fragData1;
+layout(location = 2) out vec4 fragData2;
#define M_PI 3.1415926535897932384626433832795
@@ -55,15 +59,15 @@ void downsample_pass()
float far_coc, near_coc;
/* custom downsampling. We need to be careful to sample nearest here to avoid leaks */
- vec4 color1 = texture2D(colorbuffer, downsample1);
- vec4 color2 = texture2D(colorbuffer, downsample2);
- vec4 color3 = texture2D(colorbuffer, downsample3);
- vec4 color4 = texture2D(colorbuffer, downsample4);
+ vec4 color1 = texture(colorbuffer, downsample1);
+ vec4 color2 = texture(colorbuffer, downsample2);
+ vec4 color3 = texture(colorbuffer, downsample3);
+ vec4 color4 = texture(colorbuffer, downsample4);
- depth.r = texture2D(depthbuffer, downsample1).r;
- depth.g = texture2D(depthbuffer, downsample2).r;
- depth.b = texture2D(depthbuffer, downsample3).r;
- depth.a = texture2D(depthbuffer, downsample4).r;
+ depth.r = texture(depthbuffer, downsample1).r;
+ depth.g = texture(depthbuffer, downsample2).r;
+ depth.b = texture(depthbuffer, downsample3).r;
+ depth.a = texture(depthbuffer, downsample4).r;
zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), depth);
coc = calculate_coc(zdepth);
@@ -82,16 +86,16 @@ void downsample_pass()
float norm_far = dot(far_weights, vec4(1.0));
/* now write output to weighted buffers. */
- gl_FragData[0] = color1 * near_weights.x + color2 * near_weights.y + color3 * near_weights.z +
+ fragData0 = color1 * near_weights.x + color2 * near_weights.y + color3 * near_weights.z +
color4 * near_weights.w;
- gl_FragData[1] = color1 * far_weights.x + color2 * far_weights.y + color3 * far_weights.z +
+ fragData1 = color1 * far_weights.x + color2 * far_weights.y + color3 * far_weights.z +
color4 * far_weights.w;
if (norm_near > 0.0)
- gl_FragData[0] /= norm_near;
+ fragData0 /= norm_near;
if (norm_far > 0.0)
- gl_FragData[1] /= norm_far;
- gl_FragData[2] = vec4(near_coc, far_coc, 0.0, 1.0);
+ fragData1 /= norm_far;
+ fragData2 = vec4(near_coc, far_coc, 0.0, 1.0);
}
/* accumulate color in the near/far blur buffers */
@@ -102,36 +106,36 @@ void accumulate_pass(void) {
if (dof_params.w == 0.0)
r = 1.0;
else
- r = cos(M_PI / dof_params.w) /
- (cos(theta - (2.0 * M_PI / dof_params.w) * floor((dof_params.w * theta + M_PI) / (2.0 * M_PI))));
+ r = cos(M_PI / dof_params.w) /
+ (cos(theta - (2.0 * M_PI / dof_params.w) * floor((dof_params.w * theta + M_PI) / (2.0 * M_PI))));
if (dot(particlecoord, particlecoord) > r * r)
discard;
- gl_FragData[0] = color;
+ fragData0 = color;
}
-#define MERGE_THRESHOLD 4.0
+#define MERGE_THRESHOLD 4.0
/* combine the passes, */
void final_pass(void) {
vec4 finalcolor;
float totalweight;
- float depth = texture2D(depthbuffer, uvcoord).r;
+ float depth = texture(depthbuffer, uvcoord).r;
vec4 zdepth = get_view_space_z_from_depth(vec4(viewvecs[0].z), vec4(viewvecs[1].z), vec4(depth));
float coc_near = calculate_coc(zdepth).r;
float coc_far = max(-coc_near, 0.0);
coc_near = max(coc_near, 0.0);
- vec4 farcolor = texture2D(farbuffer, uvcoord);
+ vec4 farcolor = texture(farbuffer, uvcoord);
float farweight = farcolor.a;
if (farweight > 0.0)
farcolor /= farweight;
- vec4 nearcolor = texture2D(nearbuffer, uvcoord);
+ vec4 nearcolor = texture(nearbuffer, uvcoord);
- vec4 srccolor = texture2D(colorbuffer, uvcoord);
+ vec4 srccolor = texture(colorbuffer, uvcoord);
- vec4 coc = texture2D(cocbuffer, uvcoord);
+ vec4 coc = texture(cocbuffer, uvcoord);
float mixfac = smoothstep(1.0, MERGE_THRESHOLD, coc_far);
finalcolor = mix(srccolor, farcolor, mixfac);
@@ -152,7 +156,9 @@ void final_pass(void) {
finalcolor = mix(finalcolor, nearcolor, nearweight / totalweight);
}
- gl_FragData[0] = finalcolor;
+ fragData0 = finalcolor;
+ // fragData0 = vec4(nearweight, farweight, 0.0, 1.0);
+ // fragData0 = vec4(nearcolor.rgb, 1.0);
}
void main()
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_geo.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_geo.glsl
index 4c650e7695f..52d0a9be499 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_geo.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_geo.glsl
@@ -5,27 +5,14 @@ uniform vec2 layerselection;
uniform sampler2D cocbuffer;
-#if __VERSION__ >= 150
- layout(points) in;
- layout(triangle_strip, max_vertices = 4) out;
-
- #define POS gl_in[0].gl_Position
-#else
- /* use the EXT_geometry_shader4 way */
- #define POS gl_PositionIn[0]
-#endif
-
-/* initial uv coordinate */
-#if __VERSION__ < 130
- varying in vec2 uvcoord[];
- varying out vec2 particlecoord;
- varying out vec4 color;
- #define textureLod texture2DLod
-#else
- in vec2 uvcoord[];
- out vec2 particlecoord;
- out vec4 color;
-#endif
+layout(points) in;
+layout(triangle_strip, max_vertices = 4) out;
+
+#define POS gl_in[0].gl_Position
+
+in vec2 uvcoord[];
+out vec2 particlecoord;
+flat out vec4 color;
#define M_PI 3.1415926535897932384626433832795
@@ -46,21 +33,23 @@ void main()
vec2 offset_far = vec2(offset_val * 0.5) / vec2(rendertargetdim.x, rendertargetdim.y);
- gl_Position = POS + vec4(-offset_far.x, -offset_far.y, 0.0, 0.0);
color = colortex;
+
+ gl_Position = POS + vec4(-offset_far.x, -offset_far.y, 0.0, 0.0);
particlecoord = vec2(-1.0, -1.0);
EmitVertex();
+
gl_Position = POS + vec4(-offset_far.x, offset_far.y, 0.0, 0.0);
particlecoord = vec2(-1.0, 1.0);
- color = colortex;
EmitVertex();
+
gl_Position = POS + vec4(offset_far.x, -offset_far.y, 0.0, 0.0);
particlecoord = vec2(1.0, -1.0);
- color = colortex;
EmitVertex();
+
gl_Position = POS + vec4(offset_far.x, offset_far.y, 0.0, 0.0);
particlecoord = vec2(1.0, 1.0);
- color = colortex;
EmitVertex();
+
EndPrimitive();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_vert.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_vert.glsl
index 09a0c75facc..1dd5bf42b25 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_hq_vert.glsl
@@ -1,27 +1,31 @@
-uniform vec2 invrendertargetdim;
-uniform ivec2 rendertargetdim;
+
+in vec2 pos;
+in vec2 uvs;
/* initial uv coordinate */
-varying vec2 uvcoord;
+out vec2 uvcoord;
/* coordinate used for calculating radius et al set in geometry shader */
-varying vec2 particlecoord;
+out vec2 particlecoord;
/* downsampling coordinates */
-varying vec2 downsample1;
-varying vec2 downsample2;
-varying vec2 downsample3;
-varying vec2 downsample4;
+out vec2 downsample1;
+out vec2 downsample2;
+out vec2 downsample3;
+out vec2 downsample4;
+
+uniform vec2 invrendertargetdim;
+uniform ivec2 rendertargetdim;
void vert_dof_downsample()
{
/* gather pixels from neighbors. half dimensions means we offset half a pixel to
* get this right though it's possible we may lose a pixel at some point */
- downsample1 = gl_MultiTexCoord0.xy + vec2(-0.5, -0.5) * invrendertargetdim;
- downsample2 = gl_MultiTexCoord0.xy + vec2(-0.5, 0.5) * invrendertargetdim;
- downsample3 = gl_MultiTexCoord0.xy + vec2(0.5, 0.5) * invrendertargetdim;
- downsample4 = gl_MultiTexCoord0.xy + vec2(0.5, -0.5) * invrendertargetdim;
+ downsample1 = uvs.xy + vec2(-0.5, -0.5) * invrendertargetdim;
+ downsample2 = uvs.xy + vec2(-0.5, 0.5) * invrendertargetdim;
+ downsample3 = uvs.xy + vec2(0.5, 0.5) * invrendertargetdim;
+ downsample4 = uvs.xy + vec2(0.5, -0.5) * invrendertargetdim;
- gl_Position = gl_Vertex;
+ gl_Position = vec4(pos, 0.0, 1.0);
}
/* geometry shading pass, calculate a texture coordinate based on the indexed id */
@@ -42,8 +46,8 @@ void vert_dof_coc_scatter_pass()
void vert_dof_final()
{
- uvcoord = gl_MultiTexCoord0.xy;
- gl_Position = gl_Vertex;
+ uvcoord = uvs;
+ gl_Position = vec4(pos, 0.0, 1.0);
}
void main()
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
index 63b57d5775c..0fcab6302e4 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_dof_vert.glsl
@@ -1,51 +1,54 @@
uniform vec2 invrendertargetdim;
-//texture coordinates for framebuffer read
-varying vec4 uvcoordsvar;
+in vec2 pos;
+in vec2 uvs;
+
+/* texture coordinates for framebuffer read */
+out vec4 uvcoordsvar;
/* color texture coordinates, offset by a small amount */
-varying vec2 color_uv1;
-varying vec2 color_uv2;
+out vec2 color_uv1;
+out vec2 color_uv2;
-varying vec2 depth_uv1;
-varying vec2 depth_uv2;
-varying vec2 depth_uv3;
-varying vec2 depth_uv4;
+out vec2 depth_uv1;
+out vec2 depth_uv2;
+out vec2 depth_uv3;
+out vec2 depth_uv4;
//very simple shader for gull screen FX, just pass values on
void vert_generic()
{
- uvcoordsvar = gl_MultiTexCoord0;
- gl_Position = gl_Vertex;
+ uvcoordsvar = vec4(uvs, 0.0, 0.0);
+ gl_Position = vec4(pos, 0.0, 1.0);
}
void vert_dof_first_pass()
{
/* we offset the texture coordinates by 1.5 pixel,
* then we reuse that to sample the surrounding pixels */
- color_uv1 = gl_MultiTexCoord0.xy + vec2(-1.5, -1.5) * invrendertargetdim;
- color_uv2 = gl_MultiTexCoord0.xy + vec2(0.5, -1.5) * invrendertargetdim;
+ color_uv1 = uvs.xy + vec2(-1.5, -1.5) * invrendertargetdim;
+ color_uv2 = uvs.xy + vec2(0.5, -1.5) * invrendertargetdim;
- depth_uv1 = gl_MultiTexCoord0.xy + vec2(-1.5, -1.5) * invrendertargetdim;
- depth_uv2 = gl_MultiTexCoord0.xy + vec2(-0.5, -1.5) * invrendertargetdim;
- depth_uv3 = gl_MultiTexCoord0.xy + vec2(0.5, -1.5) * invrendertargetdim;
- depth_uv4 = gl_MultiTexCoord0.xy + vec2(1.5, -1.5) * invrendertargetdim;
+ depth_uv1 = uvs.xy + vec2(-1.5, -1.5) * invrendertargetdim;
+ depth_uv2 = uvs.xy + vec2(-0.5, -1.5) * invrendertargetdim;
+ depth_uv3 = uvs.xy + vec2(0.5, -1.5) * invrendertargetdim;
+ depth_uv4 = uvs.xy + vec2(1.5, -1.5) * invrendertargetdim;
- gl_Position = gl_Vertex;
+ gl_Position = vec4(pos, 0.0, 1.0);
}
void vert_dof_fourth_pass()
{
vec4 halfpixel = vec4(-0.5, 0.5, -0.5, 0.5);
- uvcoordsvar = gl_MultiTexCoord0.xxyy +
+ uvcoordsvar = uvs.xxyy +
halfpixel *
vec4(invrendertargetdim.x,
invrendertargetdim.x,
invrendertargetdim.y,
invrendertargetdim.y);
- gl_Position = gl_Vertex;
+ gl_Position = vec4(pos, 0.0, 1.0);
}
void vert_dof_fifth_pass()
@@ -53,8 +56,8 @@ void vert_dof_fifth_pass()
vec4 halfpixel = vec4(-0.5, 0.5, -0.5, 0.5);
color_uv1 = vec2(0.5, 1.5) * invrendertargetdim;
- uvcoordsvar = gl_MultiTexCoord0;
- gl_Position = gl_Vertex;
+ uvcoordsvar = vec4(uvs, 0.0, 0.0);
+ gl_Position = vec4(pos, 0.0, 1.0);
}
void main()
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl b/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
index 1dc49b52be1..7aa6786d292 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_lib.glsl
@@ -1,14 +1,17 @@
+uniform mat4 ProjectionMatrix;
+
/* simple depth reconstruction, see http://www.derschmale.com/2014/01/26/reconstructing-positions-from-the-depth-buffer
* we change the factors from the article to fit the OpennGL model. */
#ifdef PERSP_MATRIX
+
/* perspective camera code */
vec3 get_view_space_from_depth(in vec2 uvcoords, in vec3 viewvec_origin, in vec3 viewvec_diff, in float depth)
{
float d = 2.0 * depth - 1.0;
- float zview = -gl_ProjectionMatrix[3][2] / (d + gl_ProjectionMatrix[2][2]);
+ float zview = -ProjectionMatrix[3][2] / (d + ProjectionMatrix[2][2]);
return zview * (viewvec_origin + vec3(uvcoords, 0.0) * viewvec_diff);
}
@@ -18,7 +21,7 @@ vec4 get_view_space_z_from_depth(in vec4 near, in vec4 range, in vec4 depth)
vec4 d = 2.0 * depth - vec4(1.0);
/* return positive value, so sign differs! */
- return vec4(gl_ProjectionMatrix[3][2]) / (d + vec4(gl_ProjectionMatrix[2][2]));
+ return vec4(ProjectionMatrix[3][2]) / (d + vec4(ProjectionMatrix[2][2]));
}
#else
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
index f19ff4ec65a..4904010c841 100644
--- a/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_fx_ssao_frag.glsl
@@ -1,3 +1,4 @@
+
// color buffer
uniform sampler2D colorbuffer;
@@ -9,8 +10,10 @@ uniform sampler1D ssao_concentric_tex;
// depth buffer
uniform sampler2D depthbuffer;
+
// coordinates on framebuffer in normalized (0.0-1.0) uv space
-varying vec4 uvcoordsvar;
+in vec4 uvcoordsvar;
+out vec4 FragColor;
/* ssao_params.x : pixel scale for the ssao radious */
/* ssao_params.y : factor for the ssao darkening */
@@ -33,7 +36,7 @@ vec3 calculate_view_space_normal(in vec3 viewposition)
float calculate_ssao_factor(float depth)
{
/* take the normalized ray direction here */
- vec2 rotX = texture2D(jitter_tex, uvcoordsvar.xy * ssao_sample_params.yz).rg;
+ vec2 rotX = texture(jitter_tex, uvcoordsvar.xy * ssao_sample_params.yz).rg;
vec2 rotY = vec2(-rotX.y, rotX.x);
/* occlusion is zero in full depth */
@@ -46,9 +49,9 @@ float calculate_ssao_factor(float depth)
/* find the offset in screen space by multiplying a point
* in camera space at the depth of the point by the projection matrix. */
vec2 offset;
- float homcoord = gl_ProjectionMatrix[2][3] * position.z + gl_ProjectionMatrix[3][3];
- offset.x = gl_ProjectionMatrix[0][0] * ssao_params.x / homcoord;
- offset.y = gl_ProjectionMatrix[1][1] * ssao_params.x / homcoord;
+ float homcoord = ProjectionMatrix[2][3] * position.z + ProjectionMatrix[3][3];
+ offset.x = ProjectionMatrix[0][0] * ssao_params.x / homcoord;
+ offset.y = ProjectionMatrix[1][1] * ssao_params.x / homcoord;
/* convert from -1.0...1.0 range to 0.0..1.0 for easy use with texture coordinates */
offset *= 0.5;
@@ -57,7 +60,7 @@ float calculate_ssao_factor(float depth)
int num_samples = int(ssao_sample_params.x);
for (x = 0; x < num_samples; x++) {
- vec2 dir_sample = texture1D(ssao_concentric_tex, (float(x) + 0.5) / ssao_sample_params.x).rg;
+ vec2 dir_sample = texture(ssao_concentric_tex, (float(x) + 0.5) / ssao_sample_params.x).rg;
/* rotate with random direction to get jittered result */
vec2 dir_jittered = vec2(dot(dir_sample, rotX), dot(dir_sample, rotY));
@@ -67,7 +70,7 @@ float calculate_ssao_factor(float depth)
if (uvcoords.x > 1.0 || uvcoords.x < 0.0 || uvcoords.y > 1.0 || uvcoords.y < 0.0)
continue;
- float depth_new = texture2D(depthbuffer, uvcoords).r;
+ float depth_new = texture(depthbuffer, uvcoords).r;
if (depth_new != 1.0) {
vec3 pos_new = get_view_space_from_depth(uvcoords, viewvecs[0].xyz, viewvecs[1].xyz, depth_new);
vec3 dir = pos_new - position;
@@ -87,8 +90,8 @@ float calculate_ssao_factor(float depth)
void main()
{
- float depth = texture2D(depthbuffer, uvcoordsvar.xy).r;
- vec4 scene_col = texture2D(colorbuffer, uvcoordsvar.xy);
+ float depth = texture(depthbuffer, uvcoordsvar.xy).r;
+ vec4 scene_col = texture(colorbuffer, uvcoordsvar.xy);
vec3 final_color = mix(scene_col.rgb, ssao_color.rgb, calculate_ssao_factor(depth));
- gl_FragColor = vec4(final_color.rgb, scene_col.a);
+ FragColor = vec4(final_color.rgb, scene_col.a);
}
diff --git a/source/blender/gpu/shaders/gpu_shader_fx_vert.glsl b/source/blender/gpu/shaders/gpu_shader_fx_vert.glsl
deleted file mode 100644
index 5194e414520..00000000000
--- a/source/blender/gpu/shaders/gpu_shader_fx_vert.glsl
+++ /dev/null
@@ -1,9 +0,0 @@
-varying vec4 uvcoordsvar;
-
-//very simple shader for full screen FX, just pass values on
-
-void main()
-{
- uvcoordsvar = gl_MultiTexCoord0;
- gl_Position = gl_Vertex;
-}
diff --git a/source/blender/gpu/shaders/gpu_shader_geometry.glsl b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
index fe630dbeddb..705b79cbf56 100644
--- a/source/blender/gpu/shaders/gpu_shader_geometry.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_geometry.glsl
@@ -1,10 +1,11 @@
+
+uniform mat4 ProjectionMatrix;
+
uniform int PrimitiveIdBase;
uniform int osd_active_uv_offset;
-#if __VERSION__ >= 150
- layout(lines_adjacency) in;
- layout(triangle_strip, max_vertices = 4) out;
-#endif
+layout(lines_adjacency) in;
+layout(triangle_strip, max_vertices = 4) out;
in block {
VertexData v;
@@ -31,17 +32,12 @@ uniform int osd_fvar_count;
tessCoord.t); \
}
-#ifdef USE_NEW_SHADING
# define INTERP_FACE_VARYING_ATT_2(result, fvarOffset, tessCoord) \
{ \
vec2 tmp; \
INTERP_FACE_VARYING_2(tmp, fvarOffset, tessCoord); \
result = vec3(tmp, 0); \
}
-#else
-# define INTERP_FACE_VARYING_ATT_2(result, fvarOffset, tessCoord) \
- INTERP_FACE_VARYING_2(result, fvarOffset, tessCoord)
-#endif
uniform samplerBuffer FVarDataBuffer;
uniform isamplerBuffer FVarDataOffsetBuffer;
@@ -69,7 +65,7 @@ void emit_flat(int index, vec3 normal)
set_mtface_vertex_attrs(st);
- gl_Position = gl_ProjectionMatrix * inpt[index].v.position;
+ gl_Position = ProjectionMatrix * inpt[index].v.position;
EmitVertex();
}
@@ -90,7 +86,7 @@ void emit_smooth(int index)
set_mtface_vertex_attrs(st);
- gl_Position = gl_ProjectionMatrix * inpt[index].v.position;
+ gl_Position = ProjectionMatrix * inpt[index].v.position;
EmitVertex();
}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
new file mode 100644
index 00000000000..727c3c0a832
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_alpha_color_frag.glsl
@@ -0,0 +1,11 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform vec4 color;
+uniform sampler2D image;
+
+void main()
+{
+ fragColor = texture(image, texCoord_interp).r * color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
new file mode 100644
index 00000000000..ef8935cc7ba
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_color_frag.glsl
@@ -0,0 +1,11 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform vec4 color;
+uniform sampler2D image;
+
+void main()
+{
+ fragColor = texture(image, texCoord_interp) * color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl
new file mode 100644
index 00000000000..10f4dfd5a87
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_depth_copy_frag.glsl
@@ -0,0 +1,12 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform sampler2D image;
+
+void main()
+{
+ float depth = texture(image, texCoord_interp).r;
+ fragColor = vec4(depth);
+ gl_FragDepth = depth;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl
new file mode 100644
index 00000000000..bcbe1f577fd
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_depth_linear_frag.glsl
@@ -0,0 +1,16 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform float znear;
+uniform float zfar;
+uniform sampler2D image;
+
+void main()
+{
+ float depth = texture(image, texCoord_interp).r;
+
+ /* normalize */
+ fragColor.rgb = vec3((2.0f * znear) / (zfar + znear - (depth * (zfar - znear))));
+ fragColor.a = 1.0f;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl
new file mode 100644
index 00000000000..1ac0d68b35f
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_desaturate_frag.glsl
@@ -0,0 +1,14 @@
+
+uniform float factor;
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform vec4 color;
+uniform sampler2D image;
+
+void main()
+{
+ vec4 tex = texture(image, texCoord_interp);
+ tex.rgb = ((0.3333333 * factor) * vec3(tex.r + tex.g + tex.b)) + (tex.rgb * (1.0 - factor));
+ fragColor = tex * color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl
new file mode 100644
index 00000000000..6eeab8ca7e8
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_frag.glsl
@@ -0,0 +1,10 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform sampler2D image;
+
+void main()
+{
+ fragColor = texture(image, texCoord_interp);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
new file mode 100644
index 00000000000..d95645f58e5
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_interlace_frag.glsl
@@ -0,0 +1,34 @@
+
+/* Keep these in sync with GPU_shader.h */
+#define INTERLACE_ROW 0
+#define INTERLACE_COLUMN 1
+#define INTERLACE_CHECKERBOARD 2
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform int interlace_id;
+uniform sampler2D image_a;
+uniform sampler2D image_b;
+
+bool interlace()
+{
+ if (interlace_id == INTERLACE_CHECKERBOARD) {
+ return (int(gl_FragCoord.x + gl_FragCoord.y) & 1) != 0;
+ }
+ else if (interlace_id == INTERLACE_ROW) {
+ return (int(gl_FragCoord.y) & 1) != 0;
+ }
+ else if (interlace_id == INTERLACE_COLUMN) {
+ return (int(gl_FragCoord.x) & 1) != 0;
+ }
+}
+
+void main()
+{
+ if (interlace()) {
+ fragColor = texture(image_a, texCoord_interp);
+ } else {
+ fragColor = texture(image_b, texCoord_interp);
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl
new file mode 100644
index 00000000000..97eb3afc177
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_linear_frag.glsl
@@ -0,0 +1,30 @@
+
+/* Display a linear image texture into sRGB space */
+
+uniform sampler2D image;
+
+in vec2 texCoord_interp;
+
+out vec4 fragColor;
+
+float linearrgb_to_srgb(float c)
+{
+ if (c < 0.0031308)
+ return (c < 0.0) ? 0.0 : c * 12.92;
+ else
+ return 1.055 * pow(c, 1.0 / 2.4) - 0.055;
+}
+
+void linearrgb_to_srgb(vec4 col_from, out vec4 col_to)
+{
+ col_to.r = linearrgb_to_srgb(col_from.r);
+ col_to.g = linearrgb_to_srgb(col_from.g);
+ col_to.b = linearrgb_to_srgb(col_from.b);
+ col_to.a = col_from.a;
+}
+
+void main() {
+ fragColor = texture(image, texCoord_interp.st);
+
+ linearrgb_to_srgb(fragColor, fragColor);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl
new file mode 100644
index 00000000000..4a45d03175e
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_mask_uniform_color_frag.glsl
@@ -0,0 +1,12 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform sampler2D image;
+uniform vec4 color;
+
+void main()
+{
+ fragColor.a = texture(image, texCoord_interp).a * color.a;
+ fragColor.rgb = color.rgb;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
new file mode 100644
index 00000000000..51092d56e5e
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_modulate_alpha_frag.glsl
@@ -0,0 +1,12 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform float alpha;
+uniform sampler2D image;
+
+void main()
+{
+ fragColor = texture(image, texCoord_interp);
+ fragColor.a *= alpha;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl
new file mode 100644
index 00000000000..57362c88320
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_multisample_resolve_frag.glsl
@@ -0,0 +1,124 @@
+
+uniform sampler2DMS depthMulti;
+uniform sampler2DMS colorMulti;
+
+out vec4 fragColor;
+
+#if SAMPLES > 16
+#error "Too many samples"
+#endif
+
+// #define USE_DEPTH_WEIGHTING
+
+void main()
+{
+ ivec2 texel = ivec2(gl_FragCoord.xy);
+
+ bvec4 b1, b2, b3, b4;
+ vec4 w1, w2, w3, w4;
+ vec4 d1, d2, d3, d4;
+ vec4 c1, c2, c3, c4, c5, c6, c7, c8;
+ vec4 c9, c10, c11, c12, c13, c14, c15, c16;
+ d1 = d2 = d3 = d4 = vec4(1.0);
+ w1 = w2 = w3 = w4 = vec4(0.0);
+ c1 = c2 = c3 = c4 = c5 = c6 = c7 = c8 = vec4(0.0);
+ c9 = c10 = c11 = c12 = c13 = c14 = c15 = c16 = vec4(0.0);
+
+ /* Depth */
+
+ d1.x = texelFetch(depthMulti, texel, 0).r;
+ d1.y = texelFetch(depthMulti, texel, 1).r;
+#if SAMPLES > 2
+ d1.z = texelFetch(depthMulti, texel, 2).r;
+ d1.w = texelFetch(depthMulti, texel, 3).r;
+#endif
+#if SAMPLES > 4
+ d2.x = texelFetch(depthMulti, texel, 4).r;
+ d2.y = texelFetch(depthMulti, texel, 5).r;
+ d2.z = texelFetch(depthMulti, texel, 6).r;
+ d2.w = texelFetch(depthMulti, texel, 7).r;
+#endif
+#if SAMPLES > 8
+ d3.x = texelFetch(depthMulti, texel, 8).r;
+ d3.y = texelFetch(depthMulti, texel, 9).r;
+ d3.z = texelFetch(depthMulti, texel, 10).r;
+ d3.w = texelFetch(depthMulti, texel, 11).r;
+ d4.x = texelFetch(depthMulti, texel, 12).r;
+ d4.y = texelFetch(depthMulti, texel, 13).r;
+ d4.z = texelFetch(depthMulti, texel, 14).r;
+ d4.w = texelFetch(depthMulti, texel, 15).r;
+#endif
+
+ /* COLOR */
+ b1 = notEqual(d1, vec4(1.0));
+ if (any(b1)) {
+ c1 = texelFetch(colorMulti, texel, 0);
+ c2 = texelFetch(colorMulti, texel, 1);
+#if SAMPLES > 2
+ c3 = texelFetch(colorMulti, texel, 2);
+ c4 = texelFetch(colorMulti, texel, 3);
+#endif
+ w1 = vec4(b1);
+ }
+#if SAMPLES > 4
+ b2 = notEqual(d2, vec4(1.0));
+ if (any(b2)) {
+ c5 = texelFetch(colorMulti, texel, 4);
+ c6 = texelFetch(colorMulti, texel, 5);
+ c7 = texelFetch(colorMulti, texel, 6);
+ c8 = texelFetch(colorMulti, texel, 7);
+ w2 = vec4(b2);
+ }
+#endif
+#if SAMPLES > 8
+ b3 = notEqual(d3, vec4(1.0));
+ if (any(b3)) {
+ c9 = texelFetch(colorMulti, texel, 8);
+ c10 = texelFetch(colorMulti, texel, 9);
+ c11 = texelFetch(colorMulti, texel, 10);
+ c12 = texelFetch(colorMulti, texel, 11);
+ w3 = vec4(b3);
+ }
+ b4 = notEqual(d4, vec4(1.0));
+ if (any(b4)) {
+ c13 = texelFetch(colorMulti, texel, 12);
+ c14 = texelFetch(colorMulti, texel, 13);
+ c15 = texelFetch(colorMulti, texel, 14);
+ c16 = texelFetch(colorMulti, texel, 15);
+ w4 = vec4(b4);
+ }
+#endif
+
+#if SAMPLES > 8
+ d1 = min(d1, min(d3, d4));
+#endif
+#if SAMPLES > 4
+ d1 = min(d1, d2);
+#endif
+#if SAMPLES > 2
+ d1.xy = min(d1.xy, d1.zw);
+#endif
+ gl_FragDepth = min(d1.x, d1.y);
+
+#ifdef USE_DEPTH_WEIGHTING
+ c1 *= w1.x; c2 *= w1.y; c3 *= w1.z; c4 *= w1.w;
+ c5 *= w2.x; c6 *= w2.y; c7 *= w2.z; c8 *= w2.w;
+ c9 *= w3.x; c10 *= w3.y; c11 *= w3.z; c12 *= w3.w;
+ c13 *= w4.x; c14 *= w4.y; c15 *= w4.z; c16 *= w4.w;
+#endif
+
+ c1 = c1 + c2;
+#if SAMPLES > 2
+ c1 += c3 + c4;
+#endif
+#if SAMPLES > 4
+ c1 += c5 + c6 + c7 + c8;
+#endif
+#if SAMPLES > 8
+ c1 += c9 + c10 + c11 + c12 + c13 + c14 + c15 + c16;
+#endif
+
+ const float inv_samples = 1.0 / float(SAMPLES);
+
+ fragColor = c1 * inv_samples;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl
new file mode 100644
index 00000000000..64662247d69
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_shuffle_color_frag.glsl
@@ -0,0 +1,16 @@
+
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform sampler2D image;
+uniform vec4 color;
+uniform vec4 shuffle;
+
+void main()
+{
+ vec4 sample = texture(image, texCoord_interp);
+ fragColor = vec4(sample.r * shuffle.r +
+ sample.g * shuffle.g +
+ sample.b * shuffle.b +
+ sample.a * shuffle.a) * color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl
new file mode 100644
index 00000000000..37686092700
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_image_varying_color_frag.glsl
@@ -0,0 +1,11 @@
+
+in vec2 texCoord_interp;
+flat in vec4 finalColor;
+out vec4 fragColor;
+
+uniform sampler2D image;
+
+void main()
+{
+ fragColor = texture(image, texCoord_interp) * finalColor;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
new file mode 100644
index 00000000000..aec8fd9b0a1
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_camera_vert.glsl
@@ -0,0 +1,50 @@
+
+uniform mat4 ViewProjectionMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in float pos;
+
+/* ---- Per instance Attribs ---- */
+in vec3 color;
+in vec4 corners[2]; /* trouble fetching vec2 */
+in float depth;
+in vec4 tria;
+in mat4 InstanceModelMatrix;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ vec3 pPos;
+
+ if (pos == 1.0) {
+ pPos = vec3(corners[0].xy, depth);
+ }
+ else if (pos == 2.0) {
+ pPos = vec3(corners[0].zw, depth);
+ }
+ else if (pos == 3.0) {
+ pPos = vec3(corners[1].xy, depth);
+ }
+ else if (pos == 4.0) {
+ pPos = vec3(corners[1].zw, depth);
+ }
+ else if (pos == 5.0) {
+ pPos = vec3(tria.xy, depth);
+ }
+ else if (pos == 6.0) {
+ vec2 ofs = tria.xy - corners[0].xy;
+ ofs.x = -ofs.x;
+ pPos = vec3(corners[1].zw + ofs, depth);
+ }
+ else if (pos == 7.0) {
+ pPos = vec3(tria.zw, depth);
+ }
+ else {
+ pPos = vec3(0.0);
+ }
+
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pPos, 1.0);
+
+ finalColor = vec4(color, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
new file mode 100644
index 00000000000..ced5bb7f684
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_distance_line_vert.glsl
@@ -0,0 +1,25 @@
+
+uniform mat4 ViewProjectionMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+
+/* ---- Per instance Attribs ---- */
+in vec3 color;
+in float start;
+in float end;
+in mat4 InstanceModelMatrix;
+
+uniform float size;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ float len = end - start;
+ vec3 sta = vec3(0.0, 0.0, -start);
+
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos * -len + sta, 1.0);
+ gl_PointSize = size;
+ finalColor = vec4(color, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl
new file mode 100644
index 00000000000..e26f419b8cd
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_geom.glsl
@@ -0,0 +1,57 @@
+
+// Draw "fancy" wireframe, displaying front-facing, back-facing and
+// silhouette lines differently.
+// Mike Erwin, April 2015
+
+// After working with this shader a while, convinced we should make
+// separate shaders for perpective & ortho. (Oct 2016)
+
+// Due to perspective, the line segment's endpoints might disagree on
+// whether the adjacent faces are front facing. This geometry shader
+// decides which edge type to use if endpoints disagree.
+
+uniform mat4 ProjectionMatrix;
+
+uniform bool drawFront = true;
+uniform bool drawBack = true;
+uniform bool drawSilhouette = true;
+
+layout(lines) in;
+layout(line_strip, max_vertices = 2) out;
+
+in vec4 MV_pos[];
+in float edgeClass[];
+in vec3 fCol[];
+
+flat out vec4 finalColor;
+
+void emitLine(vec4 color)
+{
+ gl_Position = ProjectionMatrix * MV_pos[0];
+ EmitVertex();
+ gl_Position = ProjectionMatrix * MV_pos[1];
+ finalColor = color;
+ EmitVertex();
+ EndPrimitive();
+}
+
+void main()
+{
+ float finalEdgeClass = max(edgeClass[0], edgeClass[1]);
+
+ if (finalEdgeClass > 0.0f) {
+ // front-facing edge
+ if (drawFront)
+ emitLine(vec4(fCol[0], 0.75));
+ }
+ else if (finalEdgeClass < 0.0f) {
+ // back-facing edge
+ if (drawBack)
+ emitLine(vec4(fCol[0], 0.5));
+ }
+ else {
+ // exactly one face is front-facing, silhouette edge
+ if (drawSilhouette)
+ emitLine(vec4(fCol[0], 1.0));
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
new file mode 100644
index 00000000000..fa30c9fb1ed
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_edges_variying_color_vert.glsl
@@ -0,0 +1,63 @@
+
+// Draw "fancy" wireframe, displaying front-facing, back-facing and
+// silhouette lines differently.
+// Mike Erwin, April 2015
+
+// After working with this shader a while, convinced we should make
+// separate shaders for perpective & ortho. (Oct 2016)
+
+// Due to perspective, the line segment's endpoints might disagree on
+// whether the adjacent faces are front facing. We use a geometry
+// shader to resolve this properly.
+
+uniform mat4 ViewMatrix;
+uniform mat4 ProjectionMatrix;
+
+in vec3 pos;
+in vec3 N1, N2; // normals of faces this edge joins (object coords)
+
+/* instance attrib */
+in vec3 color;
+in mat4 InstanceModelMatrix;
+
+out vec4 MV_pos;
+out float edgeClass;
+out vec3 fCol;
+
+// TODO: in float angle; // [-pi .. +pi], + peak, 0 flat, - valley
+
+bool front(mat3 NormalMatrix, vec3 N, vec3 eye)
+{
+ return dot(NormalMatrix * N, eye) > 0.0;
+}
+
+void main()
+{
+ vec3 eye;
+
+ mat4 ModelViewMatrix = ViewMatrix * InstanceModelMatrix;
+
+ MV_pos = ModelViewMatrix * vec4(pos, 1.0);
+
+ mat3 NormalMatrix = transpose(inverse(mat3(ModelViewMatrix)));
+
+ /* if persp */
+ if (ProjectionMatrix[3][3] == 0.0) {
+ eye = normalize(-MV_pos.xyz);
+ }
+ else {
+ eye = vec3(0.0, 0.0, 1.0);
+ }
+
+ bool face_1_front = front(NormalMatrix, N1, eye);
+ bool face_2_front = front(NormalMatrix, N2, eye);
+
+ if (face_1_front && face_2_front)
+ edgeClass = 1.0; // front-facing edge
+ else if (face_1_front || face_2_front)
+ edgeClass = 0.0; // exactly one face is front-facing, silhouette edge
+ else
+ edgeClass = -1.0; // back-facing edge
+
+ fCol = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
new file mode 100644
index 00000000000..9876717b297
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_objectspace_variying_color_vert.glsl
@@ -0,0 +1,27 @@
+
+uniform mat4 ViewMatrix;
+uniform mat4 ViewProjectionMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+in vec3 nor;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec4 color;
+
+out vec3 normal;
+flat out vec4 finalColor;
+
+void main()
+{
+ mat4 ModelViewProjectionMatrix = ViewProjectionMatrix * InstanceModelMatrix;
+ /* This is slow and run per vertex, but it's still faster than
+ * doing it per instance on CPU and sending it on via instance attrib */
+ mat3 NormalMatrix = transpose(inverse(mat3(ViewMatrix * InstanceModelMatrix)));
+
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 1.0);
+ normal = NormalMatrix * nor;
+
+ finalColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl
new file mode 100644
index 00000000000..2ee74b3eae0
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_screen_aligned_vert.glsl
@@ -0,0 +1,32 @@
+
+uniform mat4 ViewProjectionMatrix;
+uniform vec3 screen_vecs[2];
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos; /* using Z as axis id */
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec3 color;
+in float size;
+
+flat out vec4 finalColor;
+
+void main()
+{
+ vec3 offset = vec3(0.0);
+
+#ifdef AXIS_NAME
+ if (pos.z == 0.0)
+ offset = vec3(1.125, 0.0, 0.0);
+ else if (pos.z == 1.0)
+ offset = vec3(0.0, 1.125, 0.0);
+ else
+ offset = vec3(0.0, 0.0, 1.125);
+ offset *= size;
+#endif
+
+ vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
+ gl_Position = ViewProjectionMatrix * (InstanceModelMatrix * vec4(offset, 1.0) + vec4(screen_pos * size, 0.0));
+ finalColor = vec4(color, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
new file mode 100644
index 00000000000..ba0ac29fb79
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_screenspace_variying_color_vert.glsl
@@ -0,0 +1,29 @@
+
+uniform mat4 ViewProjectionMatrix;
+uniform vec3 screen_vecs[2];
+uniform float size;
+uniform float pixel_size;
+
+/* ---- Instanciated Attribs ---- */
+in vec2 pos;
+
+/* ---- Per instance Attribs ---- */
+in vec3 world_pos;
+in vec3 color;
+
+flat out vec4 finalColor;
+
+float mul_project_m4_v3_zfac(in vec3 co)
+{
+ return (ViewProjectionMatrix[0][3] * co.x) +
+ (ViewProjectionMatrix[1][3] * co.y) +
+ (ViewProjectionMatrix[2][3] * co.z) + ViewProjectionMatrix[3][3];
+}
+
+void main()
+{
+ float pix_size = mul_project_m4_v3_zfac(world_pos) * pixel_size;
+ vec3 screen_pos = screen_vecs[0].xyz * pos.x + screen_vecs[1].xyz * pos.y;
+ gl_Position = ViewProjectionMatrix * vec4(world_pos + screen_pos * size * pix_size, 1.0);
+ finalColor = vec4(color, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
new file mode 100644
index 00000000000..10a2ba61a2c
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_color_vert.glsl
@@ -0,0 +1,22 @@
+
+uniform mat4 ViewProjectionMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+in vec3 color;
+#ifdef UNIFORM_SCALE
+in float size;
+#else
+in vec3 size;
+#endif
+
+flat out vec4 finalColor;
+
+void main()
+{
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos * size, 1.0);
+ finalColor = vec4(color, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
new file mode 100644
index 00000000000..49750dddb3c
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_variying_size_variying_id_vert.glsl
@@ -0,0 +1,23 @@
+
+uniform mat4 ViewProjectionMatrix;
+uniform int baseId;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+#ifdef UNIFORM_SCALE
+in float size;
+#else
+in vec3 size;
+#endif
+in int callId;
+
+flat out uint finalId;
+
+void main()
+{
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos * size, 1.0);
+ finalId = uint(baseId + callId);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
new file mode 100644
index 00000000000..eac167e8045
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_instance_vert.glsl
@@ -0,0 +1,13 @@
+
+uniform mat4 ViewProjectionMatrix;
+
+/* ---- Instanciated Attribs ---- */
+in vec3 pos;
+
+/* ---- Per instance Attribs ---- */
+in mat4 InstanceModelMatrix;
+
+void main()
+{
+ gl_Position = ViewProjectionMatrix * InstanceModelMatrix * vec4(pos, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl
new file mode 100644
index 00000000000..7f445369833
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_frag.glsl
@@ -0,0 +1,31 @@
+
+in vec4 radii;
+in vec4 finalColor;
+in vec4 finalOutlineColor;
+out vec4 fragColor;
+
+void main() {
+ vec2 quad = abs(gl_PointCoord - vec2(0.5));
+ float dist = quad.x + quad.y;
+
+// transparent outside of point
+// --- 0 ---
+// smooth transition
+// --- 1 ---
+// pure outline color
+// --- 2 ---
+// smooth transition
+// --- 3 ---
+// pure point color
+// ...
+// dist = 0 at center of point
+
+ float mid_stroke = 0.5 * (radii[1] + radii[2]);
+
+ vec4 backgroundColor = vec4(finalOutlineColor.rgb, 0.0);
+
+ if (dist > mid_stroke)
+ fragColor = mix(finalOutlineColor, backgroundColor, smoothstep(radii[1], radii[0], dist));
+ else
+ fragColor = mix(finalColor, finalOutlineColor, smoothstep(radii[3], radii[2], dist));
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl
new file mode 100644
index 00000000000..c49832bf9b4
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_keyframe_diamond_vert.glsl
@@ -0,0 +1,34 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+const float pixel_fudge = sqrt(2.0);
+const float outline_width = 1.15 * pixel_fudge;
+
+in vec2 pos;
+in float size;
+in vec4 color;
+in vec4 outlineColor;
+out vec4 finalColor;
+out vec4 finalOutlineColor;
+out vec4 radii;
+
+void main() {
+ gl_Position = ModelViewProjectionMatrix * vec4(pos, 0.0, 1.0);
+
+ // pass through unchanged
+ gl_PointSize = size + pixel_fudge; // 0.5 pixel_fudge on either side
+ finalColor = color;
+ finalOutlineColor = outlineColor;
+
+ // calculate concentric radii in pixels
+ float radius = 0.5 * gl_PointSize;
+
+ // start at the outside and progress toward the center
+ radii[0] = radius;
+ radii[1] = radius - pixel_fudge;
+ radii[2] = radius - outline_width;
+ radii[3] = radius - outline_width - pixel_fudge;
+
+ // convert to PointCoord units
+ radii /= size;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_material.glsl b/source/blender/gpu/shaders/gpu_shader_material.glsl
index a0ca719e207..45701f090fa 100644
--- a/source/blender/gpu/shaders/gpu_shader_material.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_material.glsl
@@ -1,12 +1,47 @@
+
+uniform mat4 ModelMatrix;
+uniform mat4 ModelMatrixInverse;
+uniform mat4 ModelViewMatrix;
+uniform mat4 ModelViewMatrixInverse;
+uniform mat3 NormalMatrix;
+
+/* Old glsl mode compat. */
+
+#ifndef CLOSURE_DEFAULT
+
+struct Closure {
+ vec3 radiance;
+ float opacity;
+};
+
+#define CLOSURE_DEFAULT Closure(vec3(0.0), 1.0)
+
+Closure closure_mix(Closure cl1, Closure cl2, float fac)
+{
+ Closure cl;
+ cl.radiance = mix(cl1.radiance, cl2.radiance, fac);
+ cl.opacity = mix(cl1.opacity, cl2.opacity, fac);
+ return cl;
+}
+
+Closure closure_add(Closure cl1, Closure cl2)
+{
+ Closure cl;
+ cl.radiance = cl1.radiance + cl2.radiance;
+ cl.opacity = cl1.opacity + cl2.opacity;
+ return cl;
+}
+
+Closure nodetree_exec(void); /* Prototype */
+
+#endif /* CLOSURE_DEFAULT */
+
+
/* Converters */
float convert_rgba_to_float(vec4 color)
{
-#ifdef USE_NEW_SHADING
- return color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
-#else
- return (color.r + color.g + color.b) / 3.0;
-#endif
+ return dot(color.rgb, vec3(0.2126, 0.7152, 0.0722));
}
float exp_blender(float f)
@@ -53,7 +88,7 @@ void rgb_to_hsv(vec4 rgb, out vec4 outcol)
h = 0.0;
}
else {
- c = (vec3(cmax, cmax, cmax) - rgb.xyz) / cdelta;
+ c = (vec3(cmax) - rgb.xyz) / cdelta;
if (rgb.x == cmax) h = c[2] - c[1];
else if (rgb.y == cmax) h = 2.0 + c[0] - c[2];
@@ -155,56 +190,15 @@ void color_to_blender_normal_new_shading(vec3 color, out vec3 normal)
normal.y = -2.0 * ((color.g) - 0.5);
normal.z = -2.0 * ((color.b) - 0.5);
}
-
+#ifndef M_PI
#define M_PI 3.14159265358979323846
-#define M_1_PI 0.31830988618379069
+#endif
+#ifndef M_1_PI
+#define M_1_PI 0.318309886183790671538
+#endif
/*********** SHADER NODES ***************/
-void vcol_attribute(vec4 attvcol, out vec4 vcol)
-{
- vcol = vec4(attvcol.x, attvcol.y, attvcol.z, 1.0);
-}
-
-void uv_attribute(vec2 attuv, out vec3 uv)
-{
- uv = vec3(attuv * 2.0 - vec2(1.0, 1.0), 0.0);
-}
-
-void geom(
- vec3 co, vec3 nor, mat4 viewinvmat, vec3 attorco, vec2 attuv, vec4 attvcol,
- out vec3 global, out vec3 local, out vec3 view, out vec3 orco, out vec3 uv,
- out vec3 normal, out vec4 vcol, out float vcol_alpha, out float frontback)
-{
- local = co;
- view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(local) : vec3(0.0, 0.0, -1.0);
- global = (viewinvmat * vec4(local, 1.0)).xyz;
- orco = attorco;
- uv_attribute(attuv, uv);
- normal = -normalize(nor); /* blender render normal is negated */
- vcol_attribute(attvcol, vcol);
- srgb_to_linearrgb(vcol, vcol);
- vcol_alpha = attvcol.a;
- frontback = (gl_FrontFacing) ? 1.0 : 0.0;
-}
-
-void particle_info(
- vec4 sprops, vec4 loc, vec3 vel, vec3 avel,
- out float index, out float random, out float age,
- out float life_time, out vec3 location,
- out float size, out vec3 velocity, out vec3 angular_velocity)
-{
- index = sprops.x;
- random = loc.w;
- age = sprops.y;
- life_time = sprops.z;
- size = sprops.w;
-
- location = loc.xyz;
- velocity = vel;
- angular_velocity = avel;
-}
-
void vect_normalize(vec3 vin, out vec3 vout)
{
vout = normalize(vin);
@@ -272,17 +266,6 @@ void camera(vec3 co, out vec3 outview, out float outdepth, out float outdist)
outview = normalize(co);
}
-void lamp(
- vec4 col, float energy, vec3 lv, float dist, vec3 shadow, float visifac,
- out vec4 outcol, out vec3 outlv, out float outdist, out vec4 outshadow, out float outvisifac)
-{
- outcol = col * energy;
- outlv = lv;
- outdist = dist;
- outshadow = vec4(shadow, 1.0);
- outvisifac = visifac;
-}
-
void math_add(float val1, float val2, out float outval)
{
outval = val1 + val2;
@@ -421,13 +404,13 @@ void squeeze(float val, float width, float center, out float outval)
void vec_math_add(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
outvec = v1 + v2;
- outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) / 3.0;
+ outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) * 0.333333;
}
void vec_math_sub(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
outvec = v1 - v2;
- outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) / 3.0;
+ outval = (abs(outvec[0]) + abs(outvec[1]) + abs(outvec[2])) * 0.333333;
}
void vec_math_average(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
@@ -443,7 +426,7 @@ void vec_math_mix(float strength, vec3 v1, vec3 v2, out vec3 outvec)
void vec_math_dot(vec3 v1, vec3 v2, out vec3 outvec, out float outval)
{
- outvec = vec3(0, 0, 0);
+ outvec = vec3(0);
outval = dot(v1, v2);
}
@@ -485,9 +468,9 @@ void normal_new_shading(vec3 dir, vec3 nor, out vec3 outnor, out float outdot)
void curves_vec(float fac, vec3 vec, sampler2D curvemap, out vec3 outvec)
{
- outvec.x = texture2D(curvemap, vec2((vec.x + 1.0) * 0.5, 0.0)).x;
- outvec.y = texture2D(curvemap, vec2((vec.y + 1.0) * 0.5, 0.0)).y;
- outvec.z = texture2D(curvemap, vec2((vec.z + 1.0) * 0.5, 0.0)).z;
+ outvec.x = texture(curvemap, vec2((vec.x + 1.0) * 0.5, 0.0)).x;
+ outvec.y = texture(curvemap, vec2((vec.y + 1.0) * 0.5, 0.0)).y;
+ outvec.z = texture(curvemap, vec2((vec.z + 1.0) * 0.5, 0.0)).z;
if (fac != 1.0)
outvec = (outvec * fac) + (vec * (1.0 - fac));
@@ -496,9 +479,9 @@ void curves_vec(float fac, vec3 vec, sampler2D curvemap, out vec3 outvec)
void curves_rgb(float fac, vec4 col, sampler2D curvemap, out vec4 outcol)
{
- outcol.r = texture2D(curvemap, vec2(texture2D(curvemap, vec2(col.r, 0.0)).a, 0.0)).r;
- outcol.g = texture2D(curvemap, vec2(texture2D(curvemap, vec2(col.g, 0.0)).a, 0.0)).g;
- outcol.b = texture2D(curvemap, vec2(texture2D(curvemap, vec2(col.b, 0.0)).a, 0.0)).b;
+ outcol.r = texture(curvemap, vec2(texture(curvemap, vec2(col.r, 0.0)).a, 0.0)).r;
+ outcol.g = texture(curvemap, vec2(texture(curvemap, vec2(col.g, 0.0)).a, 0.0)).g;
+ outcol.b = texture(curvemap, vec2(texture(curvemap, vec2(col.b, 0.0)).a, 0.0)).b;
if (fac != 1.0)
outcol = (outcol * fac) + (col * (1.0 - fac));
@@ -818,22 +801,19 @@ void mix_linear(float fac, vec4 col1, vec4 col2, out vec4 outcol)
void valtorgb(float fac, sampler2D colormap, out vec4 outcol, out float outalpha)
{
- outcol = texture2D(colormap, vec2(fac, 0.0));
+ outcol = texture(colormap, vec2(fac, 0.0));
outalpha = outcol.a;
}
void rgbtobw(vec4 color, out float outval)
{
-#ifdef USE_NEW_SHADING
- outval = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
-#else
- outval = color.r * 0.35 + color.g * 0.45 + color.b * 0.2; /* keep these factors in sync with texture.h:RGBTOBW */
-#endif
+ vec3 factors = vec3(0.2126, 0.7152, 0.0722);
+ outval = dot(color.rgb, factors);
}
void invert(float fac, vec4 col, out vec4 outcol)
{
- outcol.xyz = mix(col.xyz, vec3(1.0, 1.0, 1.0) - col.xyz, fac);
+ outcol.xyz = mix(col.xyz, vec3(1.0) - col.xyz, fac);
outcol.w = col.w;
}
@@ -911,56 +891,6 @@ void output_node(vec4 rgb, float alpha, out vec4 outrgb)
/*********** TEXTURES ***************/
-void texture_flip_blend(vec3 vec, out vec3 outvec)
-{
- outvec = vec.yxz;
-}
-
-void texture_blend_lin(vec3 vec, out float outval)
-{
- outval = (1.0 + vec.x) / 2.0;
-}
-
-void texture_blend_quad(vec3 vec, out float outval)
-{
- outval = max((1.0 + vec.x) / 2.0, 0.0);
- outval *= outval;
-}
-
-void texture_wood_sin(vec3 vec, out float value, out vec4 color, out vec3 normal)
-{
- float a = sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z) * 20.0;
- float wi = 0.5 + 0.5 * sin(a);
-
- value = wi;
- color = vec4(wi, wi, wi, 1.0);
- normal = vec3(0.0, 0.0, 0.0);
-}
-
-void texture_image(vec3 vec, sampler2D ima, out float value, out vec4 color, out vec3 normal)
-{
- color = texture2D(ima, (vec.xy + vec2(1.0, 1.0)) * 0.5);
- value = color.a;
-
- normal.x = 2.0 * (color.r - 0.5);
- normal.y = 2.0 * (0.5 - color.g);
- normal.z = 2.0 * (color.b - 0.5);
-}
-
-/************* MTEX *****************/
-
-void texco_orco(vec3 attorco, out vec3 orco)
-{
- orco = attorco;
-}
-
-void texco_uv(vec2 attuv, out vec3 uv)
-{
- /* disabled for now, works together with leaving out mtex_2d_mapping */
- // uv = vec3(attuv*2.0 - vec2(1.0, 1.0), 0.0); */
- uv = vec3(attuv, 0.0);
-}
-
void texco_norm(vec3 normal, out vec3 outnormal)
{
/* corresponds to shi->orn, which is negated so cancels
@@ -968,436 +898,11 @@ void texco_norm(vec3 normal, out vec3 outnormal)
outnormal = normalize(normal);
}
-void texco_tangent(vec4 tangent, out vec3 outtangent)
-{
- outtangent = normalize(tangent.xyz);
-}
-
-void texco_global(mat4 viewinvmat, vec3 co, out vec3 global)
-{
- global = (viewinvmat * vec4(co, 1.0)).xyz;
-}
-
-void texco_object(mat4 viewinvmat, mat4 obinvmat, vec3 co, out vec3 object)
-{
- object = (obinvmat * (viewinvmat * vec4(co, 1.0))).xyz;
-}
-
-void texco_refl(vec3 vn, vec3 view, out vec3 ref)
-{
- ref = view - 2.0 * dot(vn, view) * vn;
-}
-
-void shade_norm(vec3 normal, out vec3 outnormal)
-{
- /* blender render normal is negated */
- outnormal = -normalize(normal);
-}
-
-void mtex_mirror(vec3 tcol, vec4 refcol, float tin, float colmirfac, out vec4 outrefcol)
-{
- outrefcol = mix(refcol, vec4(1.0, tcol), tin * colmirfac);
-}
-
-void mtex_rgb_blend(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm;
-
- fact *= facg;
- facm = 1.0 - fact;
-
- incol = fact * texcol + facm * outcol;
-}
-
-void mtex_rgb_mul(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm;
-
- fact *= facg;
- facm = 1.0 - fact;
-
- incol = (facm + fact * texcol) * outcol;
-}
-
-void mtex_rgb_screen(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm;
-
- fact *= facg;
- facm = 1.0 - fact;
-
- incol = vec3(1.0) - (vec3(facm) + fact * (vec3(1.0) - texcol)) * (vec3(1.0) - outcol);
-}
-
-void mtex_rgb_overlay(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm;
-
- fact *= facg;
- facm = 1.0 - fact;
-
- if (outcol.r < 0.5)
- incol.r = outcol.r * (facm + 2.0 * fact * texcol.r);
- else
- incol.r = 1.0 - (facm + 2.0 * fact * (1.0 - texcol.r)) * (1.0 - outcol.r);
-
- if (outcol.g < 0.5)
- incol.g = outcol.g * (facm + 2.0 * fact * texcol.g);
- else
- incol.g = 1.0 - (facm + 2.0 * fact * (1.0 - texcol.g)) * (1.0 - outcol.g);
-
- if (outcol.b < 0.5)
- incol.b = outcol.b * (facm + 2.0 * fact * texcol.b);
- else
- incol.b = 1.0 - (facm + 2.0 * fact * (1.0 - texcol.b)) * (1.0 - outcol.b);
-}
-
-void mtex_rgb_sub(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- incol = -fact * facg * texcol + outcol;
-}
-
-void mtex_rgb_add(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- incol = fact * facg * texcol + outcol;
-}
-
-void mtex_rgb_div(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm;
-
- fact *= facg;
- facm = 1.0 - fact;
-
- if (texcol.r != 0.0) incol.r = facm * outcol.r + fact * outcol.r / texcol.r;
- if (texcol.g != 0.0) incol.g = facm * outcol.g + fact * outcol.g / texcol.g;
- if (texcol.b != 0.0) incol.b = facm * outcol.b + fact * outcol.b / texcol.b;
-}
-
-void mtex_rgb_diff(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm;
-
- fact *= facg;
- facm = 1.0 - fact;
-
- incol = facm * outcol + fact * abs(texcol - outcol);
-}
-
-void mtex_rgb_dark(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm, col;
-
- fact *= facg;
- facm = 1.0 - fact;
-
- incol.r = min(outcol.r, texcol.r) * fact + outcol.r * facm;
- incol.g = min(outcol.g, texcol.g) * fact + outcol.g * facm;
- incol.b = min(outcol.b, texcol.b) * fact + outcol.b * facm;
-}
-
-void mtex_rgb_light(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- float facm, col;
-
- fact *= facg;
-
- col = fact * texcol.r;
- if (col > outcol.r) incol.r = col; else incol.r = outcol.r;
- col = fact * texcol.g;
- if (col > outcol.g) incol.g = col; else incol.g = outcol.g;
- col = fact * texcol.b;
- if (col > outcol.b) incol.b = col; else incol.b = outcol.b;
-}
-
-void mtex_rgb_hue(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- vec4 col;
-
- mix_hue(fact * facg, vec4(outcol, 1.0), vec4(texcol, 1.0), col);
- incol.rgb = col.rgb;
-}
-
-void mtex_rgb_sat(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- vec4 col;
-
- mix_sat(fact * facg, vec4(outcol, 1.0), vec4(texcol, 1.0), col);
- incol.rgb = col.rgb;
-}
-
-void mtex_rgb_val(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- vec4 col;
-
- mix_val(fact * facg, vec4(outcol, 1.0), vec4(texcol, 1.0), col);
- incol.rgb = col.rgb;
-}
-
-void mtex_rgb_color(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- vec4 col;
-
- mix_color(fact * facg, vec4(outcol, 1.0), vec4(texcol, 1.0), col);
- incol.rgb = col.rgb;
-}
-
-void mtex_rgb_soft(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- vec4 col;
-
- mix_soft(fact * facg, vec4(outcol, 1.0), vec4(texcol, 1.0), col);
- incol.rgb = col.rgb;
-}
-
-void mtex_rgb_linear(vec3 outcol, vec3 texcol, float fact, float facg, out vec3 incol)
-{
- fact *= facg;
-
- if (texcol.r > 0.5)
- incol.r = outcol.r + fact * (2.0 * (texcol.r - 0.5));
- else
- incol.r = outcol.r + fact * (2.0 * (texcol.r) - 1.0);
-
- if (texcol.g > 0.5)
- incol.g = outcol.g + fact * (2.0 * (texcol.g - 0.5));
- else
- incol.g = outcol.g + fact * (2.0 * (texcol.g) - 1.0);
-
- if (texcol.b > 0.5)
- incol.b = outcol.b + fact * (2.0 * (texcol.b - 0.5));
- else
- incol.b = outcol.b + fact * (2.0 * (texcol.b) - 1.0);
-}
-
-void mtex_value_vars(inout float fact, float facg, out float facm)
-{
- fact *= abs(facg);
- facm = 1.0 - fact;
-
- if (facg < 0.0) {
- float tmp = fact;
- fact = facm;
- facm = tmp;
- }
-}
-
-void mtex_value_blend(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- incol = fact * texcol + facm * outcol;
-}
-
-void mtex_value_mul(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- facm = 1.0 - facg;
- incol = (facm + fact * texcol) * outcol;
-}
-
-void mtex_value_screen(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- facm = 1.0 - facg;
- incol = 1.0 - (facm + fact * (1.0 - texcol)) * (1.0 - outcol);
-}
-
-void mtex_value_sub(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- fact = -fact;
- incol = fact * texcol + outcol;
-}
-
-void mtex_value_add(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- fact = fact;
- incol = fact * texcol + outcol;
-}
-
-void mtex_value_div(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- if (texcol != 0.0)
- incol = facm * outcol + fact * outcol / texcol;
- else
- incol = 0.0;
-}
-
-void mtex_value_diff(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- incol = facm * outcol + fact * abs(texcol - outcol);
-}
-
-void mtex_value_dark(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- incol = facm * outcol + fact * min(outcol, texcol);
-}
-
-void mtex_value_light(float outcol, float texcol, float fact, float facg, out float incol)
-{
- float facm;
- mtex_value_vars(fact, facg, facm);
-
- float col = fact * texcol;
- if (col > outcol) incol = col; else incol = outcol;
-}
-
-void mtex_value_clamp_positive(float fac, out float outfac)
-{
- outfac = max(fac, 0.0);
-}
-
-void mtex_value_clamp(float fac, out float outfac)
-{
- outfac = clamp(fac, 0.0, 1.0);
-}
-
-void mtex_har_divide(float har, out float outhar)
-{
- outhar = har / 128.0;
-}
-
-void mtex_har_multiply_clamp(float har, out float outhar)
-{
- har *= 128.0;
-
- if (har < 1.0) outhar = 1.0;
- else if (har > 511.0) outhar = 511.0;
- else outhar = har;
-}
-
-void mtex_alpha_from_col(vec4 col, out float alpha)
-{
- alpha = col.a;
-}
-
-void mtex_alpha_to_col(vec4 col, float alpha, out vec4 outcol)
-{
- outcol = vec4(col.rgb, alpha);
-}
-
-void mtex_alpha_multiply_value(vec4 col, float value, out vec4 outcol)
-{
- outcol = vec4(col.rgb, col.a * value);
-}
-
-void mtex_rgbtoint(vec4 rgb, out float intensity)
-{
- intensity = dot(vec3(0.35, 0.45, 0.2), rgb.rgb);
-}
-
-void mtex_value_invert(float invalue, out float outvalue)
-{
- outvalue = 1.0 - invalue;
-}
-
-void mtex_rgb_invert(vec4 inrgb, out vec4 outrgb)
-{
- outrgb = vec4(vec3(1.0) - inrgb.rgb, inrgb.a);
-}
-
-void mtex_value_stencil(float stencil, float intensity, out float outstencil, out float outintensity)
-{
- float fact = intensity;
- outintensity = intensity * stencil;
- outstencil = stencil * fact;
-}
-
-void mtex_rgb_stencil(float stencil, vec4 rgb, out float outstencil, out vec4 outrgb)
-{
- float fact = rgb.a;
- outrgb = vec4(rgb.rgb, rgb.a * stencil);
- outstencil = stencil * fact;
-}
-
-void mtex_mapping_ofs(vec3 texco, vec3 ofs, out vec3 outtexco)
-{
- outtexco = texco + ofs;
-}
-
-void mtex_mapping_size(vec3 texco, vec3 size, out vec3 outtexco)
-{
- outtexco = size * texco;
-}
-
-void mtex_2d_mapping(vec3 vec, out vec3 outvec)
-{
- outvec = vec3(vec.xy * 0.5 + vec2(0.5), vec.z);
-}
-
vec3 mtex_2d_mapping(vec3 vec)
{
return vec3(vec.xy * 0.5 + vec2(0.5), vec.z);
}
-void mtex_cube_map(vec3 co, samplerCube ima, out float value, out vec4 color)
-{
- color = textureCube(ima, co);
- value = 1.0;
-}
-
-void mtex_cube_map_refl_from_refldir(
- samplerCube ima, vec3 reflecteddirection, out float value, out vec4 color)
-{
- color = textureCube(ima, reflecteddirection);
- value = color.a;
-}
-
-void mtex_cube_map_refl(
- samplerCube ima, vec3 vp, vec3 vn, mat4 viewmatrixinverse, mat4 viewmatrix,
- out float value, out vec4 color)
-{
- vec3 viewdirection = vec3(viewmatrixinverse * vec4(vp, 0.0));
- vec3 normaldirection = normalize(vec3(vec4(vn, 0.0) * viewmatrix));
- vec3 reflecteddirection = reflect(viewdirection, normaldirection);
- color = textureCube(ima, reflecteddirection);
- value = 1.0;
-}
-
-void mtex_image(vec3 texco, sampler2D ima, out float value, out vec4 color)
-{
- color = texture2D(ima, texco.xy);
- value = 1.0;
-}
-
-void mtex_normal(vec3 texco, sampler2D ima, out vec3 normal)
-{
- // The invert of the red channel is to make
- // the normal map compliant with the outside world.
- // It needs to be done because in Blender
- // the normal used points inward.
- // Should this ever change this negate must be removed.
- vec4 color = texture2D(ima, texco.xy);
- normal = 2.0 * (vec3(-color.r, color.g, color.b) - vec3(-0.5, 0.5, 0.5));
-}
-
-void mtex_bump_normals_init(vec3 vN, out vec3 vNorg, out vec3 vNacc, out float fPrevMagnitude)
-{
- vNorg = vN;
- vNacc = vN;
- fPrevMagnitude = 1.0;
-}
-
/** helper method to extract the upper left 3x3 matrix from a 4x4 matrix */
mat3 to_mat3(mat4 m4)
{
@@ -1408,976 +913,6 @@ mat3 to_mat3(mat4 m4)
return m3;
}
-void mtex_bump_init_objspace(
- vec3 surf_pos, vec3 surf_norm,
- mat4 mView, mat4 mViewInv, mat4 mObj, mat4 mObjInv,
- float fPrevMagnitude_in, vec3 vNacc_in,
- out float fPrevMagnitude_out, out vec3 vNacc_out,
- out vec3 vR1, out vec3 vR2, out float fDet)
-{
- mat3 obj2view = to_mat3(gl_ModelViewMatrix);
- mat3 view2obj = to_mat3(gl_ModelViewMatrixInverse);
-
- vec3 vSigmaS = view2obj * dFdx(surf_pos);
- vec3 vSigmaT = view2obj * dFdy(surf_pos);
- vec3 vN = normalize(surf_norm * obj2view);
-
- vR1 = cross(vSigmaT, vN);
- vR2 = cross(vN, vSigmaS);
- fDet = dot(vSigmaS, vR1);
-
- /* pretransform vNacc (in mtex_bump_apply) using the inverse transposed */
- vR1 = vR1 * view2obj;
- vR2 = vR2 * view2obj;
- vN = vN * view2obj;
-
- float fMagnitude = abs(fDet) * length(vN);
- vNacc_out = vNacc_in * (fMagnitude / fPrevMagnitude_in);
- fPrevMagnitude_out = fMagnitude;
-}
-
-void mtex_bump_init_texturespace(
- vec3 surf_pos, vec3 surf_norm,
- float fPrevMagnitude_in, vec3 vNacc_in,
- out float fPrevMagnitude_out, out vec3 vNacc_out,
- out vec3 vR1, out vec3 vR2, out float fDet)
-{
- vec3 vSigmaS = dFdx(surf_pos);
- vec3 vSigmaT = dFdy(surf_pos);
- vec3 vN = surf_norm; /* normalized interpolated vertex normal */
-
- vR1 = normalize(cross(vSigmaT, vN));
- vR2 = normalize(cross(vN, vSigmaS));
- fDet = sign(dot(vSigmaS, vR1));
-
- float fMagnitude = abs(fDet);
- vNacc_out = vNacc_in * (fMagnitude / fPrevMagnitude_in);
- fPrevMagnitude_out = fMagnitude;
-}
-
-void mtex_bump_init_viewspace(
- vec3 surf_pos, vec3 surf_norm,
- float fPrevMagnitude_in, vec3 vNacc_in,
- out float fPrevMagnitude_out, out vec3 vNacc_out,
- out vec3 vR1, out vec3 vR2, out float fDet)
-{
- vec3 vSigmaS = dFdx(surf_pos);
- vec3 vSigmaT = dFdy(surf_pos);
- vec3 vN = surf_norm; /* normalized interpolated vertex normal */
-
- vR1 = cross(vSigmaT, vN);
- vR2 = cross(vN, vSigmaS);
- fDet = dot(vSigmaS, vR1);
-
- float fMagnitude = abs(fDet);
- vNacc_out = vNacc_in * (fMagnitude / fPrevMagnitude_in);
- fPrevMagnitude_out = fMagnitude;
-}
-
-void mtex_bump_tap3(
- vec3 texco, sampler2D ima, float hScale,
- out float dBs, out float dBt)
-{
- vec2 STll = texco.xy;
- vec2 STlr = texco.xy + dFdx(texco.xy);
- vec2 STul = texco.xy + dFdy(texco.xy);
-
- float Hll, Hlr, Hul;
- rgbtobw(texture2D(ima, STll), Hll);
- rgbtobw(texture2D(ima, STlr), Hlr);
- rgbtobw(texture2D(ima, STul), Hul);
-
- dBs = hScale * (Hlr - Hll);
- dBt = hScale * (Hul - Hll);
-}
-
-#ifdef BUMP_BICUBIC
-
-void mtex_bump_bicubic(
- vec3 texco, sampler2D ima, float hScale,
- out float dBs, out float dBt )
-{
- float Hl;
- float Hr;
- float Hd;
- float Hu;
-
- vec2 TexDx = dFdx(texco.xy);
- vec2 TexDy = dFdy(texco.xy);
-
- vec2 STl = texco.xy - 0.5 * TexDx;
- vec2 STr = texco.xy + 0.5 * TexDx;
- vec2 STd = texco.xy - 0.5 * TexDy;
- vec2 STu = texco.xy + 0.5 * TexDy;
-
- rgbtobw(texture2D(ima, STl), Hl);
- rgbtobw(texture2D(ima, STr), Hr);
- rgbtobw(texture2D(ima, STd), Hd);
- rgbtobw(texture2D(ima, STu), Hu);
-
- vec2 dHdxy = vec2(Hr - Hl, Hu - Hd);
- float fBlend = clamp(1.0 - textureQueryLOD(ima, texco.xy).x, 0.0, 1.0);
- if (fBlend != 0.0) {
- // the derivative of the bicubic sampling of level 0
- ivec2 vDim;
- vDim = textureSize(ima, 0);
-
- // taking the fract part of the texture coordinate is a hardcoded wrap mode.
- // this is acceptable as textures use wrap mode exclusively in 3D view elsewhere in blender.
- // this is done so that we can still get a valid texel with uvs outside the 0,1 range
- // by texelFetch below, as coordinates are clamped when using this function.
- vec2 fTexLoc = vDim * fract(texco.xy) - vec2(0.5, 0.5);
- ivec2 iTexLoc = ivec2(floor(fTexLoc));
- vec2 t = clamp(fTexLoc - iTexLoc, 0.0, 1.0); // sat just to be pedantic
-
-/*******************************************************************************************
- * This block will replace the one below when one channel textures are properly supported. *
- *******************************************************************************************
- vec4 vSamplesUL = textureGather(ima, (iTexLoc+ivec2(-1,-1) + vec2(0.5,0.5))/vDim);
- vec4 vSamplesUR = textureGather(ima, (iTexLoc+ivec2(1,-1) + vec2(0.5,0.5))/vDim);
- vec4 vSamplesLL = textureGather(ima, (iTexLoc+ivec2(-1,1) + vec2(0.5,0.5))/vDim);
- vec4 vSamplesLR = textureGather(ima, (iTexLoc+ivec2(1,1) + vec2(0.5,0.5))/vDim);
-
- mat4 H = mat4(vSamplesUL.w, vSamplesUL.x, vSamplesLL.w, vSamplesLL.x,
- vSamplesUL.z, vSamplesUL.y, vSamplesLL.z, vSamplesLL.y,
- vSamplesUR.w, vSamplesUR.x, vSamplesLR.w, vSamplesLR.x,
- vSamplesUR.z, vSamplesUR.y, vSamplesLR.z, vSamplesLR.y);
- */
- ivec2 iTexLocMod = iTexLoc + ivec2(-1, -1);
-
- mat4 H;
-
- for (int i = 0; i < 4; i++) {
- for (int j = 0; j < 4; j++) {
- ivec2 iTexTmp = iTexLocMod + ivec2(i, j);
-
- // wrap texture coordinates manually for texelFetch to work on uvs oitside the 0,1 range.
- // this is guaranteed to work since we take the fractional part of the uv above.
- iTexTmp.x = (iTexTmp.x < 0) ? iTexTmp.x + vDim.x : ((iTexTmp.x >= vDim.x) ? iTexTmp.x - vDim.x : iTexTmp.x);
- iTexTmp.y = (iTexTmp.y < 0) ? iTexTmp.y + vDim.y : ((iTexTmp.y >= vDim.y) ? iTexTmp.y - vDim.y : iTexTmp.y);
-
- rgbtobw(texelFetch(ima, iTexTmp, 0), H[i][j]);
- }
- }
-
- float x = t.x, y = t.y;
- float x2 = x * x, x3 = x2 * x, y2 = y * y, y3 = y2 * y;
-
- vec4 X = vec4(-0.5 * (x3 + x) + x2, 1.5 * x3 - 2.5 * x2 + 1, -1.5 * x3 + 2 * x2 + 0.5 * x, 0.5 * (x3 - x2));
- vec4 Y = vec4(-0.5 * (y3 + y) + y2, 1.5 * y3 - 2.5 * y2 + 1, -1.5 * y3 + 2 * y2 + 0.5 * y, 0.5 * (y3 - y2));
- vec4 dX = vec4(-1.5 * x2 + 2 * x - 0.5, 4.5 * x2 - 5 * x, -4.5 * x2 + 4 * x + 0.5, 1.5 * x2 - x);
- vec4 dY = vec4(-1.5 * y2 + 2 * y - 0.5, 4.5 * y2 - 5 * y, -4.5 * y2 + 4 * y + 0.5, 1.5 * y2 - y);
-
- // complete derivative in normalized coordinates (mul by vDim)
- vec2 dHdST = vDim * vec2(dot(Y, H * dX), dot(dY, H * X));
-
- // transform derivative to screen-space
- vec2 dHdxy_bicubic = vec2(dHdST.x * TexDx.x + dHdST.y * TexDx.y,
- dHdST.x * TexDy.x + dHdST.y * TexDy.y);
-
- // blend between the two
- dHdxy = dHdxy * (1 - fBlend) + dHdxy_bicubic * fBlend;
- }
-
- dBs = hScale * dHdxy.x;
- dBt = hScale * dHdxy.y;
-}
-
-#endif
-
-void mtex_bump_tap5(
- vec3 texco, sampler2D ima, float hScale,
- out float dBs, out float dBt)
-{
- vec2 TexDx = dFdx(texco.xy);
- vec2 TexDy = dFdy(texco.xy);
-
- vec2 STc = texco.xy;
- vec2 STl = texco.xy - 0.5 * TexDx;
- vec2 STr = texco.xy + 0.5 * TexDx;
- vec2 STd = texco.xy - 0.5 * TexDy;
- vec2 STu = texco.xy + 0.5 * TexDy;
-
- float Hc, Hl, Hr, Hd, Hu;
- rgbtobw(texture2D(ima, STc), Hc);
- rgbtobw(texture2D(ima, STl), Hl);
- rgbtobw(texture2D(ima, STr), Hr);
- rgbtobw(texture2D(ima, STd), Hd);
- rgbtobw(texture2D(ima, STu), Hu);
-
- dBs = hScale * (Hr - Hl);
- dBt = hScale * (Hu - Hd);
-}
-
-void mtex_bump_deriv(
- vec3 texco, sampler2D ima, float ima_x, float ima_y, float hScale,
- out float dBs, out float dBt)
-{
- float s = 1.0; // negate this if flipped texture coordinate
- vec2 TexDx = dFdx(texco.xy);
- vec2 TexDy = dFdy(texco.xy);
-
- // this variant using a derivative map is described here
- // http://mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html
- vec2 dim = vec2(ima_x, ima_y);
- vec2 dBduv = hScale * dim * (2.0 * texture2D(ima, texco.xy).xy - 1.0);
-
- dBs = dBduv.x * TexDx.x + s * dBduv.y * TexDx.y;
- dBt = dBduv.x * TexDy.x + s * dBduv.y * TexDy.y;
-}
-
-void mtex_bump_apply(
- float fDet, float dBs, float dBt, vec3 vR1, vec3 vR2, vec3 vNacc_in,
- out vec3 vNacc_out, out vec3 perturbed_norm)
-{
- vec3 vSurfGrad = sign(fDet) * (dBs * vR1 + dBt * vR2);
-
- vNacc_out = vNacc_in - vSurfGrad;
- perturbed_norm = normalize(vNacc_out);
-}
-
-void mtex_bump_apply_texspace(
- float fDet, float dBs, float dBt, vec3 vR1, vec3 vR2,
- sampler2D ima, vec3 texco, float ima_x, float ima_y, vec3 vNacc_in,
- out vec3 vNacc_out, out vec3 perturbed_norm)
-{
- vec2 TexDx = dFdx(texco.xy);
- vec2 TexDy = dFdy(texco.xy);
-
- vec3 vSurfGrad = sign(fDet) * (
- dBs / length(vec2(ima_x * TexDx.x, ima_y * TexDx.y)) * vR1 +
- dBt / length(vec2(ima_x * TexDy.x, ima_y * TexDy.y)) * vR2);
-
- vNacc_out = vNacc_in - vSurfGrad;
- perturbed_norm = normalize(vNacc_out);
-}
-
-void mtex_negate_texnormal(vec3 normal, out vec3 outnormal)
-{
- outnormal = vec3(-normal.x, -normal.y, normal.z);
-}
-
-void mtex_nspace_tangent(vec4 tangent, vec3 normal, vec3 texnormal, out vec3 outnormal)
-{
- vec3 B = tangent.w * cross(normal, tangent.xyz);
-
- outnormal = texnormal.x * tangent.xyz + texnormal.y * B + texnormal.z * normal;
- outnormal = normalize(outnormal);
-}
-
-void mtex_nspace_world(mat4 viewmat, vec3 texnormal, out vec3 outnormal)
-{
- outnormal = normalize((viewmat * vec4(texnormal, 0.0)).xyz);
-}
-
-void mtex_nspace_object(vec3 texnormal, out vec3 outnormal)
-{
- outnormal = normalize(gl_NormalMatrix * texnormal);
-}
-
-void mtex_blend_normal(float norfac, vec3 normal, vec3 newnormal, out vec3 outnormal)
-{
- outnormal = (1.0 - norfac) * normal + norfac * newnormal;
- outnormal = normalize(outnormal);
-}
-
-/******* MATERIAL *********/
-
-void lamp_visibility_sun_hemi(vec3 lampvec, out vec3 lv, out float dist, out float visifac)
-{
- lv = lampvec;
- dist = 1.0;
- visifac = 1.0;
-}
-
-void lamp_visibility_other(vec3 co, vec3 lampco, out vec3 lv, out float dist, out float visifac)
-{
- lv = co - lampco;
- dist = length(lv);
- lv = normalize(lv);
- visifac = 1.0;
-}
-
-void lamp_falloff_invlinear(float lampdist, float dist, out float visifac)
-{
- visifac = lampdist / (lampdist + dist);
-}
-
-void lamp_falloff_invsquare(float lampdist, float dist, out float visifac)
-{
- visifac = lampdist / (lampdist + dist * dist);
-}
-
-void lamp_falloff_sliders(float lampdist, float ld1, float ld2, float dist, out float visifac)
-{
- float lampdistkw = lampdist * lampdist;
-
- visifac = lampdist / (lampdist + ld1 * dist);
- visifac *= lampdistkw / (lampdistkw + ld2 * dist * dist);
-}
-
-void lamp_falloff_invcoefficients(float coeff_const, float coeff_lin, float coeff_quad, float dist, out float visifac)
-{
- vec3 coeff = vec3(coeff_const, coeff_lin, coeff_quad);
- vec3 d_coeff = vec3(1.0, dist, dist * dist);
- float visifac_r = dot(coeff, d_coeff);
- if (visifac_r > 0.0)
- visifac = 1.0 / visifac_r;
- else
- visifac = 0.0;
-}
-
-void lamp_falloff_curve(float lampdist, sampler2D curvemap, float dist, out float visifac)
-{
- visifac = texture2D(curvemap, vec2(dist / lampdist, 0.0)).x;
-}
-
-void lamp_visibility_sphere(float lampdist, float dist, float visifac, out float outvisifac)
-{
- float t = lampdist - dist;
-
- outvisifac = visifac * max(t, 0.0) / lampdist;
-}
-
-void lamp_visibility_spot_square(vec3 lampvec, mat4 lampimat, vec2 scale, vec3 lv, out float inpr)
-{
- if (dot(lv, lampvec) > 0.0) {
- vec3 lvrot = (lampimat * vec4(lv, 0.0)).xyz;
- /* without clever non-uniform scale, we could do: */
- // float x = max(abs(lvrot.x / lvrot.z), abs(lvrot.y / lvrot.z));
- float x = max(abs((lvrot.x / scale.x) / lvrot.z), abs((lvrot.y / scale.y) / lvrot.z));
-
- inpr = 1.0 / sqrt(1.0 + x * x);
- }
- else
- inpr = 0.0;
-}
-
-void lamp_visibility_spot_circle(vec3 lampvec, mat4 lampimat, vec2 scale, vec3 lv, out float inpr)
-{
- /* without clever non-uniform scale, we could do: */
- // inpr = dot(lv, lampvec);
- if (dot(lv, lampvec) > 0.0) {
- vec3 lvrot = (lampimat * vec4(lv, 0.0)).xyz;
- float x = abs(lvrot.x / lvrot.z);
- float y = abs(lvrot.y / lvrot.z);
-
- float ellipse = abs((x * x) / (scale.x * scale.x) + (y * y) / (scale.y * scale.y));
-
- inpr = 1.0 / sqrt(1.0 + ellipse);
- }
- else
- inpr = 0.0;
-}
-
-void lamp_visibility_spot(float spotsi, float spotbl, float inpr, float visifac, out float outvisifac)
-{
- float t = spotsi;
-
- if (inpr <= t) {
- outvisifac = 0.0;
- }
- else {
- t = inpr - t;
-
- /* soft area */
- if (spotbl != 0.0)
- inpr *= smoothstep(0.0, 1.0, t / spotbl);
-
- outvisifac = visifac * inpr;
- }
-}
-
-void lamp_visibility_clamp(float visifac, out float outvisifac)
-{
- outvisifac = (visifac < 0.001) ? 0.0 : visifac;
-}
-
-void world_paper_view(vec3 vec, out vec3 outvec)
-{
- vec3 nvec = normalize(vec);
- outvec = (gl_ProjectionMatrix[3][3] == 0.0) ? vec3(nvec.x, 0.0, nvec.y) : vec3(0.0, 0.0, -1.0);
-}
-
-void world_zen_mapping(vec3 view, float zenup, float zendown, out float zenfac)
-{
- if (view.z >= 0.0)
- zenfac = zenup;
- else
- zenfac = zendown;
-}
-
-void world_blend_paper_real(vec3 vec, out float blend)
-{
- blend = abs(vec.y);
-}
-
-void world_blend_paper(vec3 vec, out float blend)
-{
- blend = (vec.y + 1.0) * 0.5;
-}
-
-void world_blend_real(vec3 vec, out float blend)
-{
- blend = abs(normalize(vec).z);
-}
-
-void world_blend(vec3 vec, out float blend)
-{
- blend = (normalize(vec).z + 1) * 0.5;
-}
-
-void shade_view(vec3 co, out vec3 view)
-{
- /* handle perspective/orthographic */
- view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(co) : vec3(0.0, 0.0, -1.0);
-}
-
-void shade_tangent_v(vec3 lv, vec3 tang, out vec3 vn)
-{
- vec3 c = cross(lv, tang);
- vec3 vnor = cross(c, tang);
-
- vn = -normalize(vnor);
-}
-
-void shade_inp(vec3 vn, vec3 lv, out float inp)
-{
- inp = dot(vn, lv);
-}
-
-void shade_is_no_diffuse(out float is)
-{
- is = 0.0;
-}
-
-void shade_is_hemi(float inp, out float is)
-{
- is = 0.5 * inp + 0.5;
-}
-
-float area_lamp_energy(mat4 area, vec3 co, vec3 vn)
-{
- vec3 vec[4], c[4];
- float rad[4], fac;
-
- vec[0] = normalize(co - area[0].xyz);
- vec[1] = normalize(co - area[1].xyz);
- vec[2] = normalize(co - area[2].xyz);
- vec[3] = normalize(co - area[3].xyz);
-
- c[0] = normalize(cross(vec[0], vec[1]));
- c[1] = normalize(cross(vec[1], vec[2]));
- c[2] = normalize(cross(vec[2], vec[3]));
- c[3] = normalize(cross(vec[3], vec[0]));
-
- rad[0] = acos(dot(vec[0], vec[1]));
- rad[1] = acos(dot(vec[1], vec[2]));
- rad[2] = acos(dot(vec[2], vec[3]));
- rad[3] = acos(dot(vec[3], vec[0]));
-
- fac = rad[0] * dot(vn, c[0]);
- fac += rad[1] * dot(vn, c[1]);
- fac += rad[2] * dot(vn, c[2]);
- fac += rad[3] * dot(vn, c[3]);
-
- return max(fac, 0.0);
-}
-
-void shade_inp_area(
- vec3 position, vec3 lampco, vec3 lampvec, vec3 vn, mat4 area, float areasize, float k,
- out float inp)
-{
- vec3 co = position;
- vec3 vec = co - lampco;
-
- if (dot(vec, lampvec) < 0.0) {
- inp = 0.0;
- }
- else {
- float intens = area_lamp_energy(area, co, vn);
-
- inp = pow(intens * areasize, k);
- }
-}
-
-void shade_diffuse_oren_nayer(float nl, vec3 n, vec3 l, vec3 v, float rough, out float is)
-{
- vec3 h = normalize(v + l);
- float nh = max(dot(n, h), 0.0);
- float nv = max(dot(n, v), 0.0);
- float realnl = dot(n, l);
-
- if (realnl < 0.0) {
- is = 0.0;
- }
- else if (nl < 0.0) {
- is = 0.0;
- }
- else {
- float vh = max(dot(v, h), 0.0);
- float Lit_A = acos(realnl);
- float View_A = acos(nv);
-
- vec3 Lit_B = normalize(l - realnl * n);
- vec3 View_B = normalize(v - nv * n);
-
- float t = max(dot(Lit_B, View_B), 0.0);
-
- float a, b;
-
- if (Lit_A > View_A) {
- a = Lit_A;
- b = View_A;
- }
- else {
- a = View_A;
- b = Lit_A;
- }
-
- float A = 1.0 - (0.5 * ((rough * rough) / ((rough * rough) + 0.33)));
- float B = 0.45 * ((rough * rough) / ((rough * rough) + 0.09));
-
- b *= 0.95;
- is = nl * (A + (B * t * sin(a) * tan(b)));
- }
-}
-
-void shade_diffuse_toon(vec3 n, vec3 l, vec3 v, float size, float tsmooth, out float is)
-{
- float rslt = dot(n, l);
- float ang = acos(rslt);
-
- if (ang < size) is = 1.0;
- else if (ang > (size + tsmooth) || tsmooth == 0.0) is = 0.0;
- else is = 1.0 - ((ang - size) / tsmooth);
-}
-
-void shade_diffuse_minnaert(float nl, vec3 n, vec3 v, float darkness, out float is)
-{
- if (nl <= 0.0) {
- is = 0.0;
- }
- else {
- float nv = max(dot(n, v), 0.0);
-
- if (darkness <= 1.0)
- is = nl * pow(max(nv * nl, 0.1), darkness - 1.0);
- else
- is = nl * pow(1.0001 - nv, darkness - 1.0);
- }
-}
-
-float fresnel_fac(vec3 view, vec3 vn, float grad, float fac)
-{
- float t1, t2;
- float ffac;
-
- if (fac == 0.0) {
- ffac = 1.0;
- }
- else {
- t1 = dot(view, vn);
- if (t1 > 0.0) t2 = 1.0 + t1;
- else t2 = 1.0 - t1;
-
- t2 = grad + (1.0 - grad) * pow(t2, fac);
-
- if (t2 < 0.0) ffac = 0.0;
- else if (t2 > 1.0) ffac = 1.0;
- else ffac = t2;
- }
-
- return ffac;
-}
-
-void shade_diffuse_fresnel(vec3 vn, vec3 lv, vec3 view, float fac_i, float fac, out float is)
-{
- is = fresnel_fac(lv, vn, fac_i, fac);
-}
-
-void shade_cubic(float is, out float outis)
-{
- if (is > 0.0 && is < 1.0)
- outis = smoothstep(0.0, 1.0, is);
- else
- outis = is;
-}
-
-void shade_visifac(float i, float visifac, float refl, out float outi)
-{
- /*if (i > 0.0)*/
- outi = max(i * visifac * refl, 0.0);
- /*else
- outi = i;*/
-}
-
-void shade_tangent_v_spec(vec3 tang, out vec3 vn)
-{
- vn = tang;
-}
-
-void shade_add_to_diffuse(float i, vec3 lampcol, vec3 col, out vec3 outcol)
-{
- if (i > 0.0)
- outcol = i * lampcol * col;
- else
- outcol = vec3(0.0, 0.0, 0.0);
-}
-
-void shade_hemi_spec(vec3 vn, vec3 lv, vec3 view, float spec, float hard, float visifac, out float t)
-{
- lv += view;
- lv = normalize(lv);
-
- t = dot(vn, lv);
- t = 0.5 * t + 0.5;
-
- t = visifac * spec * pow(t, hard);
-}
-
-void shade_phong_spec(vec3 n, vec3 l, vec3 v, float hard, out float specfac)
-{
- vec3 h = normalize(l + v);
- float rslt = max(dot(h, n), 0.0);
-
- specfac = pow(rslt, hard);
-}
-
-void shade_cooktorr_spec(vec3 n, vec3 l, vec3 v, float hard, out float specfac)
-{
- vec3 h = normalize(v + l);
- float nh = dot(n, h);
-
- if (nh < 0.0) {
- specfac = 0.0;
- }
- else {
- float nv = max(dot(n, v), 0.0);
- float i = pow(nh, hard);
-
- i = i / (0.1 + nv);
- specfac = i;
- }
-}
-
-void shade_blinn_spec(vec3 n, vec3 l, vec3 v, float refrac, float spec_power, out float specfac)
-{
- if (refrac < 1.0) {
- specfac = 0.0;
- }
- else if (spec_power == 0.0) {
- specfac = 0.0;
- }
- else {
- if (spec_power < 100.0)
- spec_power = sqrt(1.0 / spec_power);
- else
- spec_power = 10.0 / spec_power;
-
- vec3 h = normalize(v + l);
- float nh = dot(n, h);
- if (nh < 0.0) {
- specfac = 0.0;
- }
- else {
- float nv = max(dot(n, v), 0.01);
- float nl = dot(n, l);
- if (nl <= 0.01) {
- specfac = 0.0;
- }
- else {
- float vh = max(dot(v, h), 0.01);
-
- float a = 1.0;
- float b = (2.0 * nh * nv) / vh;
- float c = (2.0 * nh * nl) / vh;
-
- float g = 0.0;
-
- if (a < b && a < c) g = a;
- else if (b < a && b < c) g = b;
- else if (c < a && c < b) g = c;
-
- float p = sqrt(((refrac * refrac) + (vh * vh) - 1.0));
- float f = ((((p - vh) * (p - vh)) / ((p + vh) * (p + vh))) *
- (1.0 + ((((vh * (p + vh)) - 1.0) * ((vh * (p + vh)) - 1.0)) /
- (((vh * (p - vh)) + 1.0) * ((vh * (p - vh)) + 1.0)))));
- float ang = acos(nh);
-
- specfac = max(f * g * exp_blender((-(ang * ang) / (2.0 * spec_power * spec_power))), 0.0);
- }
- }
- }
-}
-
-void shade_wardiso_spec(vec3 n, vec3 l, vec3 v, float rms, out float specfac)
-{
- vec3 h = normalize(l + v);
- float nh = max(dot(n, h), 0.001);
- float nv = max(dot(n, v), 0.001);
- float nl = max(dot(n, l), 0.001);
- float angle = tan(acos(nh));
- float alpha = max(rms, 0.001);
-
- specfac = nl * (1.0 / (4.0 * M_PI * alpha * alpha)) * (exp_blender(-(angle * angle) / (alpha * alpha)) / (sqrt(nv * nl)));
-}
-
-void shade_toon_spec(vec3 n, vec3 l, vec3 v, float size, float tsmooth, out float specfac)
-{
- vec3 h = normalize(l + v);
- float rslt = dot(h, n);
- float ang = acos(rslt);
-
- if (ang < size) rslt = 1.0;
- else if (ang >= (size + tsmooth) || tsmooth == 0.0) rslt = 0.0;
- else rslt = 1.0 - ((ang - size) / tsmooth);
-
- specfac = rslt;
-}
-
-void shade_spec_area_inp(float specfac, float inp, out float outspecfac)
-{
- outspecfac = specfac * inp;
-}
-
-void shade_spec_t(float shadfac, float spec, float visifac, float specfac, out float t)
-{
- t = shadfac * spec * visifac * specfac;
-}
-
-void shade_add_spec(float t, vec3 lampcol, vec3 speccol, out vec3 outcol)
-{
- outcol = t * lampcol * speccol;
-}
-
-void shade_add_mirror(vec3 mir, vec4 refcol, vec3 combined, out vec3 result)
-{
- result = mir * refcol.gba + (vec3(1.0) - mir * refcol.rrr) * combined;
-}
-
-void alpha_spec_correction(vec3 spec, float spectra, float alpha, out float outalpha)
-{
- if (spectra > 0.0) {
- float t = clamp(max(max(spec.r, spec.g), spec.b) * spectra, 0.0, 1.0);
- outalpha = (1.0 - t) * alpha + t;
- }
- else {
- outalpha = alpha;
- }
-}
-
-void shade_add(vec4 col1, vec4 col2, out vec4 outcol)
-{
- outcol = col1 + col2;
-}
-
-void shade_madd(vec4 col, vec4 col1, vec4 col2, out vec4 outcol)
-{
- outcol = col + col1 * col2;
-}
-
-void shade_add_clamped(vec4 col1, vec4 col2, out vec4 outcol)
-{
- outcol = col1 + max(col2, vec4(0.0, 0.0, 0.0, 0.0));
-}
-
-void shade_madd_clamped(vec4 col, vec4 col1, vec4 col2, out vec4 outcol)
-{
- outcol = col + max(col1 * col2, vec4(0.0, 0.0, 0.0, 0.0));
-}
-
-void env_apply(vec4 col, vec3 hor, vec3 zen, vec4 f, mat4 vm, vec3 vn, out vec4 outcol)
-{
- vec3 vv = normalize(vm[2].xyz);
- float skyfac = 0.5 * (1.0 + dot(vn, -vv));
- outcol = col + f * vec4(mix(hor, zen, skyfac), 0);
-}
-
-void shade_maddf(vec4 col, float f, vec4 col1, out vec4 outcol)
-{
- outcol = col + f * col1;
-}
-
-void shade_mul(vec4 col1, vec4 col2, out vec4 outcol)
-{
- outcol = col1 * col2;
-}
-
-void shade_mul_value(float fac, vec4 col, out vec4 outcol)
-{
- outcol = col * fac;
-}
-
-void shade_mul_value_v3(float fac, vec3 col, out vec3 outcol)
-{
- outcol = col * fac;
-}
-
-void shade_obcolor(vec4 col, vec4 obcol, out vec4 outcol)
-{
- outcol = vec4(col.rgb * obcol.rgb, col.a);
-}
-
-void ramp_rgbtobw(vec3 color, out float outval)
-{
- outval = color.r * 0.3 + color.g * 0.58 + color.b * 0.12;
-}
-
-void shade_only_shadow(float i, float shadfac, float energy, vec3 shadcol, out vec3 outshadrgb)
-{
- outshadrgb = i * energy * (1.0 - shadfac) * (vec3(1.0) - shadcol);
-}
-
-void shade_only_shadow_diffuse(vec3 shadrgb, vec3 rgb, vec4 diff, out vec4 outdiff)
-{
- outdiff = diff - vec4(rgb * shadrgb, 0.0);
-}
-
-void shade_only_shadow_specular(vec3 shadrgb, vec3 specrgb, vec4 spec, out vec4 outspec)
-{
- outspec = spec - vec4(specrgb * shadrgb, 0.0);
-}
-
-void shade_clamp_positive(vec4 col, out vec4 outcol)
-{
- outcol = max(col, vec4(0.0));
-}
-
-void test_shadowbuf(
- vec3 rco, sampler2DShadow shadowmap, mat4 shadowpersmat, float shadowbias, float inp,
- out float result)
-{
- if (inp <= 0.0) {
- result = 0.0;
- }
- else {
- vec4 co = shadowpersmat * vec4(rco, 1.0);
-
- //float bias = (1.5 - inp*inp)*shadowbias;
- co.z -= shadowbias * co.w;
-
- if (co.w > 0.0 && co.x > 0.0 && co.x / co.w < 1.0 && co.y > 0.0 && co.y / co.w < 1.0)
- result = shadow2DProj(shadowmap, co).x;
- else
- result = 1.0;
- }
-}
-
-void test_shadowbuf_vsm(
- vec3 rco, sampler2D shadowmap, mat4 shadowpersmat, float shadowbias, float bleedbias, float inp,
- out float result)
-{
- if (inp <= 0.0) {
- result = 0.0;
- }
- else {
- vec4 co = shadowpersmat * vec4(rco, 1.0);
- if (co.w > 0.0 && co.x > 0.0 && co.x / co.w < 1.0 && co.y > 0.0 && co.y / co.w < 1.0) {
- vec2 moments = texture2DProj(shadowmap, co).rg;
- float dist = co.z / co.w;
- float p = 0.0;
-
- if (dist <= moments.x)
- p = 1.0;
-
- float variance = moments.y - (moments.x * moments.x);
- variance = max(variance, shadowbias / 10.0);
-
- float d = moments.x - dist;
- float p_max = variance / (variance + d * d);
-
- // Now reduce light-bleeding by removing the [0, x] tail and linearly rescaling (x, 1]
- p_max = clamp((p_max - bleedbias) / (1.0 - bleedbias), 0.0, 1.0);
-
- result = max(p, p_max);
- }
- else {
- result = 1.0;
- }
- }
-}
-
-void shadows_only(
- vec3 rco, sampler2DShadow shadowmap, mat4 shadowpersmat,
- float shadowbias, vec3 shadowcolor, float inp,
- out vec3 result)
-{
- result = vec3(1.0);
-
- if (inp > 0.0) {
- float shadfac;
-
- test_shadowbuf(rco, shadowmap, shadowpersmat, shadowbias, inp, shadfac);
- result -= (1.0 - shadfac) * (vec3(1.0) - shadowcolor);
- }
-}
-
-void shadows_only_vsm(
- vec3 rco, sampler2D shadowmap, mat4 shadowpersmat,
- float shadowbias, float bleedbias, vec3 shadowcolor, float inp,
- out vec3 result)
-{
- result = vec3(1.0);
-
- if (inp > 0.0) {
- float shadfac;
-
- test_shadowbuf_vsm(rco, shadowmap, shadowpersmat, shadowbias, bleedbias, inp, shadfac);
- result -= (1.0 - shadfac) * (vec3(1.0) - shadowcolor);
- }
-}
-
-void shade_light_texture(vec3 rco, sampler2D cookie, mat4 shadowpersmat, out vec4 result)
-{
-
- vec4 co = shadowpersmat * vec4(rco, 1.0);
-
- result = texture2DProj(cookie, co);
-}
-
-void shade_exposure_correct(vec3 col, float linfac, float logfac, out vec3 outcol)
-{
- outcol = linfac * (1.0 - exp(col * logfac));
-}
-
-void shade_mist_factor(
- vec3 co, float enable, float miststa, float mistdist, float misttype, float misi,
- out float outfac)
-{
- if (enable == 1.0) {
- float fac, zcor;
-
- zcor = (gl_ProjectionMatrix[3][3] == 0.0) ? length(co) : -co[2];
-
- fac = clamp((zcor - miststa) / mistdist, 0.0, 1.0);
- if (misttype == 0.0) fac *= fac;
- else if (misttype == 1.0) ;
- else fac = sqrt(fac);
-
- outfac = 1.0 - (1.0 - fac) * (1.0 - misi);
- }
- else {
- outfac = 0.0;
- }
-}
-
-void shade_world_mix(vec3 hor, vec4 col, out vec4 outcol)
-{
- float fac = clamp(col.a, 0.0, 1.0);
- outcol = vec4(mix(hor, col.rgb, fac), col.a);
-}
-
-void shade_alpha_opaque(vec4 col, out vec4 outcol)
-{
- outcol = vec4(col.rgb, 1.0);
-}
-
-void shade_alpha_obcolor(vec4 col, vec4 obcol, out vec4 outcol)
-{
- outcol = vec4(col.rgb, col.a * obcol.a);
-}
-
/*********** NEW SHADER UTILITIES **************/
float fresnel_dielectric_0(float eta)
@@ -2423,7 +958,15 @@ float hypot(float x, float y)
void generated_from_orco(vec3 orco, out vec3 generated)
{
- generated = orco * 0.5 + vec3(0.5);
+#ifdef VOLUMETRICS
+#ifdef MESH_SHADER
+ generated = volumeObjectLocalCoord;
+#else
+ generated = worldPosition;
+#endif
+#else
+ generated = orco;
+#endif
}
int floor_to_int(float x)
@@ -2436,7 +979,6 @@ int quick_floor(float x)
return int(x) - ((x < 0) ? 1 : 0);
}
-#ifdef BIT_OPERATIONS
float integer_noise(int n)
{
int nn;
@@ -2500,7 +1042,6 @@ vec3 cellnoise_color(vec3 p)
return vec3(r, g, b);
}
-#endif // BIT_OPERATIONS
float floorfrac(float x, out int i)
{
@@ -2508,316 +1049,338 @@ float floorfrac(float x, out int i)
return x - i;
}
+/* bsdfs */
-/* Principled BSDF operations */
-
-float sqr(float a)
+void convert_metallic_to_specular_tinted(
+ vec3 basecol, float metallic, float specular_fac, float specular_tint,
+ out vec3 diffuse, out vec3 f0)
{
- return a*a;
+ vec3 dielectric = vec3(0.034) * specular_fac * 2.0;
+ float lum = dot(basecol, vec3(0.3, 0.6, 0.1)); /* luminance approx. */
+ vec3 tint = lum > 0 ? basecol / lum : vec3(1.0); /* normalize lum. to isolate hue+sat */
+ f0 = mix(dielectric * mix(vec3(1.0), tint, specular_tint), basecol, metallic);
+ diffuse = mix(basecol, vec3(0.0), metallic);
}
-float schlick_fresnel(float u)
+#ifndef VOLUMETRICS
+void node_bsdf_diffuse(vec4 color, float roughness, vec3 N, out Closure result)
{
- float m = clamp(1.0 - u, 0.0, 1.0);
- float m2 = m * m;
- return m2 * m2 * m; // pow(m,5)
+ vec3 vN = normalize(mat3(ViewMatrix) * N);
+ result = CLOSURE_DEFAULT;
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ eevee_closure_diffuse(N, color.rgb, 1.0, result.radiance);
+ result.radiance *= color.rgb;
}
-float GTR1(float NdotH, float a)
+void node_bsdf_glossy(vec4 color, float roughness, vec3 N, float ssr_id, out Closure result)
{
- if (a >= 1.0) {
- return M_1_PI;
- }
-
- a = max(a, 0.001);
- float a2 = a*a;
- float t = 1.0 + (a2 - 1.0) * NdotH*NdotH;
- return (a2 - 1.0) / (M_PI * log(a2) * t);
+ vec3 out_spec, ssr_spec;
+ eevee_closure_glossy(N, vec3(1.0), int(ssr_id), roughness, 1.0, out_spec, ssr_spec);
+ vec3 vN = normalize(mat3(ViewMatrix) * N);
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec * color.rgb;
+ result.ssr_data = vec4(ssr_spec * color.rgb, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
}
-float GTR2(float NdotH, float a)
+void node_bsdf_anisotropic(
+ vec4 color, float roughness, float anisotropy, float rotation, vec3 N, vec3 T,
+ out Closure result)
{
- float a2 = a*a;
- float t = 1.0 + (a2 - 1.0) * NdotH*NdotH;
- return a2 / (M_PI * t*t);
+ node_bsdf_diffuse(color, 0.0, N, result);
}
-float GTR2_aniso(float NdotH, float HdotX, float HdotY, float ax, float ay)
+void node_bsdf_glass(vec4 color, float roughness, float ior, vec3 N, float ssr_id, out Closure result)
{
- return 1.0 / (M_PI * ax*ay * sqr(sqr(HdotX / ax) + sqr(HdotY / ay) + NdotH*NdotH));
+ vec3 out_spec, out_refr, ssr_spec;
+ vec3 refr_color = (refractionDepth > 0.0) ? color.rgb * color.rgb : color.rgb; /* Simulate 2 transmission event */
+ eevee_closure_glass(N, vec3(1.0), int(ssr_id), roughness, 1.0, ior, out_spec, out_refr, ssr_spec);
+ out_refr *= refr_color;
+ out_spec *= color.rgb;
+ float fresnel = F_eta(ior, dot(N, cameraVec));
+ vec3 vN = normalize(mat3(ViewMatrix) * N);
+ result = CLOSURE_DEFAULT;
+ result.radiance = mix(out_refr, out_spec, fresnel);
+ result.ssr_data = vec4(ssr_spec * color.rgb * fresnel, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
}
-float smithG_GGX(float NdotV, float alphaG)
+void node_bsdf_toon(vec4 color, float size, float tsmooth, vec3 N, out Closure result)
{
- float a = alphaG*alphaG;
- float b = NdotV*NdotV;
- return 1.0 / (NdotV + sqrt(a + b - a * b));
-}
-
-vec3 rotate_vector(vec3 p, vec3 n, float theta) {
- return (
- p * cos(theta) + cross(n, p) *
- sin(theta) + n * dot(p, n) *
- (1.0 - cos(theta))
- );
+ node_bsdf_diffuse(color, 0.0, N, result);
}
-
-/*********** NEW SHADER NODES ***************/
-
-#define NUM_LIGHTS 3
-
-/* bsdfs */
-
-void node_bsdf_diffuse(vec4 color, float roughness, vec3 N, out vec4 result)
+void node_bsdf_principled_clearcoat(vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
+ float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
+ float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, float ssr_id,
+ float sss_id, vec3 sss_scale, out Closure result)
{
- /* ambient light */
- vec3 L = vec3(0.2);
+ metallic = saturate(metallic);
+ transmission = saturate(transmission);
- /* directional lights */
- for (int i = 0; i < NUM_LIGHTS; i++) {
- vec3 light_position = gl_LightSource[i].position.xyz;
- vec3 light_diffuse = gl_LightSource[i].diffuse.rgb;
+ vec3 diffuse, f0, out_diff, out_spec, out_trans, out_refr, ssr_spec;
+ convert_metallic_to_specular_tinted(base_color.rgb, metallic, specular, specular_tint, diffuse, f0);
- float bsdf = max(dot(N, light_position), 0.0);
- L += light_diffuse * bsdf;
- }
+ transmission *= 1.0 - metallic;
+ subsurface *= 1.0 - metallic;
+
+ clearcoat *= 0.25;
+ clearcoat *= 1.0 - transmission;
- result = vec4(L * color.rgb, 1.0);
+#ifdef USE_SSS
+ diffuse = mix(diffuse, vec3(0.0), subsurface);
+#else
+ diffuse = mix(diffuse, subsurface_color.rgb, subsurface);
+#endif
+ f0 = mix(f0, vec3(1.0), transmission);
+
+ float sss_scalef = dot(sss_scale, vec3(1.0 / 3.0));
+ eevee_closure_principled(N, diffuse, f0, int(ssr_id), roughness,
+ CN, clearcoat, clearcoat_roughness, 1.0, sss_scalef, ior,
+ out_diff, out_trans, out_spec, out_refr, ssr_spec);
+
+ vec3 refr_color = base_color.rgb;
+ refr_color *= (refractionDepth > 0.0) ? refr_color : vec3(1.0); /* Simulate 2 transmission event */
+
+ float fresnel = F_eta(ior, dot(N, cameraVec));
+ vec3 refr_spec_color = base_color.rgb * fresnel;
+ /* This bit maybe innacurate. */
+ out_refr = out_refr * refr_color * (1.0 - fresnel) + out_spec * refr_spec_color;
+
+ ssr_spec = mix(ssr_spec, refr_spec_color, transmission);
+
+ vec3 vN = normalize(mat3(ViewMatrix) * N);
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_spec + out_diff * diffuse;
+ result.radiance = mix(result.radiance, out_refr, transmission);
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
+#ifdef USE_SSS
+ result.sss_data.a = sss_scalef;
+ result.sss_data.rgb = out_diff + out_trans;
+#ifdef USE_SSS_ALBEDO
+ result.sss_albedo.rgb = mix(vec3(0.0), subsurface_color.rgb, subsurface);
+#else
+ result.sss_data.rgb *= mix(vec3(0.0), subsurface_color.rgb, subsurface);
+#endif
+ result.sss_data.rgb *= (1.0 - transmission);
+#endif
}
-void node_bsdf_glossy(vec4 color, float roughness, vec3 N, out vec4 result)
+void node_bsdf_translucent(vec4 color, vec3 N, out Closure result)
{
- /* ambient light */
- vec3 L = vec3(0.2);
-
- /* directional lights */
- for (int i = 0; i < NUM_LIGHTS; i++) {
- vec3 light_position = gl_LightSource[i].position.xyz;
- vec3 H = gl_LightSource[i].halfVector.xyz;
- vec3 light_diffuse = gl_LightSource[i].diffuse.rgb;
- vec3 light_specular = gl_LightSource[i].specular.rgb;
-
- /* we mix in some diffuse so low roughness still shows up */
- float r2 = roughness * roughness;
- float bsdf = 0.5 * pow(max(dot(N, H), 0.0), 1.0 / r2);
- bsdf += 0.5 * max(dot(N, light_position), 0.0);
- L += light_specular * bsdf;
- }
-
- result = vec4(L * color.rgb, 1.0);
+ node_bsdf_diffuse(color, 0.0, -N, result);
}
-void node_bsdf_anisotropic(
- vec4 color, float roughness, float anisotropy, float rotation, vec3 N, vec3 T,
- out vec4 result)
+void node_bsdf_transparent(vec4 color, out Closure result)
{
- node_bsdf_diffuse(color, 0.0, N, result);
+ /* this isn't right */
+ result = CLOSURE_DEFAULT;
+ result.radiance = vec3(0.0);
+ result.opacity = 0.0;
+ result.ssr_id = TRANSPARENT_CLOSURE_FLAG;
}
-void node_bsdf_glass(vec4 color, float roughness, float ior, vec3 N, out vec4 result)
+void node_bsdf_velvet(vec4 color, float sigma, vec3 N, out Closure result)
{
node_bsdf_diffuse(color, 0.0, N, result);
}
-void node_bsdf_toon(vec4 color, float size, float tsmooth, vec3 N, out vec4 result)
-{
+void node_subsurface_scattering(
+ vec4 color, float scale, vec3 radius, float sharpen, float texture_blur, vec3 N, float sss_id,
+ out Closure result)
+{
+#if defined(USE_SSS)
+ vec3 out_diff, out_trans;
+ vec3 vN = normalize(mat3(ViewMatrix) * N);
+ result = CLOSURE_DEFAULT;
+ result.ssr_data = vec4(0.0);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = -1;
+ result.sss_data.a = scale;
+ eevee_closure_subsurface(N, color.rgb, 1.0, scale, out_diff, out_trans);
+ result.sss_data.rgb = out_diff + out_trans;
+#ifdef USE_SSS_ALBEDO
+ /* Not perfect for texture_blur not exaclty equal to 0.0 or 1.0. */
+ result.sss_albedo.rgb = mix(color.rgb, vec3(1.0), texture_blur);
+ result.sss_data.rgb *= mix(vec3(1.0), color.rgb, texture_blur);
+#else
+ result.sss_data.rgb *= color.rgb;
+#endif
+#else
node_bsdf_diffuse(color, 0.0, N, result);
+#endif
}
-void node_bsdf_principled(vec4 base_color, float subsurface, vec3 subsurface_radius, vec4 subsurface_color, float metallic, float specular,
- float specular_tint, float roughness, float anisotropic, float anisotropic_rotation, float sheen, float sheen_tint, float clearcoat,
- float clearcoat_roughness, float ior, float transmission, float transmission_roughness, vec3 N, vec3 CN, vec3 T, vec3 I, out vec4 result)
+void node_bsdf_refraction(vec4 color, float roughness, float ior, vec3 N, out Closure result)
{
- /* ambient light */
- // TODO: set ambient light to an appropriate value
- vec3 L = mix(0.1, 0.03, metallic) * mix(base_color.rgb, subsurface_color.rgb, subsurface * (1.0 - metallic));
-
- float eta = (2.0 / (1.0 - sqrt(0.08 * specular))) - 1.0;
-
- /* set the viewing vector */
- vec3 V = (gl_ProjectionMatrix[3][3] == 0.0) ? -normalize(I) : vec3(0.0, 0.0, 1.0);
-
- /* get the tangent */
- vec3 Tangent = T;
- if (T == vec3(0.0)) {
- // if no tangent is set, use a default tangent
- if(N.x != N.y || N.x != N.z) {
- Tangent = vec3(N.z-N.y, N.x-N.z, N.y-N.x); // (1,1,1) x N
- }
- else {
- Tangent = vec3(N.z-N.y, N.x+N.z, -N.y-N.x); // (-1,1,1) x N
- }
- }
-
- /* rotate tangent */
- if (anisotropic_rotation != 0.0) {
- Tangent = rotate_vector(Tangent, N, anisotropic_rotation * 2.0 * M_PI);
- }
-
- /* calculate the tangent and bitangent */
- vec3 Y = normalize(cross(N, Tangent));
- vec3 X = cross(Y, N);
-
- /* fresnel normalization parameters */
- float F0 = fresnel_dielectric_0(eta);
- float F0_norm = 1.0 / (1.0 - F0);
-
- /* directional lights */
- for (int i = 0; i < NUM_LIGHTS; i++) {
- vec3 light_position_world = gl_LightSource[i].position.xyz;
- vec3 light_position = normalize(light_position_world);
-
- vec3 H = normalize(light_position + V);
-
- vec3 light_diffuse = gl_LightSource[i].diffuse.rgb;
- vec3 light_specular = gl_LightSource[i].specular.rgb;
-
- float NdotL = dot(N, light_position);
- float NdotV = dot(N, V);
- float LdotH = dot(light_position, H);
-
- vec3 diffuse_and_specular_bsdf = vec3(0.0);
- if (NdotL >= 0.0 && NdotV >= 0.0) {
- float NdotH = dot(N, H);
-
- float Cdlum = 0.3 * base_color.r + 0.6 * base_color.g + 0.1 * base_color.b; // luminance approx.
-
- vec3 Ctint = Cdlum > 0 ? base_color.rgb / Cdlum : vec3(1.0); // normalize lum. to isolate hue+sat
- vec3 Cspec0 = mix(specular * 0.08 * mix(vec3(1.0), Ctint, specular_tint), base_color.rgb, metallic);
- vec3 Csheen = mix(vec3(1.0), Ctint, sheen_tint);
-
- // Diffuse fresnel - go from 1 at normal incidence to .5 at grazing
- // and mix in diffuse retro-reflection based on roughness
-
- float FL = schlick_fresnel(NdotL), FV = schlick_fresnel(NdotV);
- float Fd90 = 0.5 + 2.0 * LdotH*LdotH * roughness;
- float Fd = mix(1.0, Fd90, FL) * mix(1.0, Fd90, FV);
-
- // Based on Hanrahan-Krueger brdf approximation of isotropic bssrdf
- // 1.25 scale is used to (roughly) preserve albedo
- // Fss90 used to "flatten" retroreflection based on roughness
- float Fss90 = LdotH*LdotH * roughness;
- float Fss = mix(1.0, Fss90, FL) * mix(1.0, Fss90, FV);
- float ss = 1.25 * (Fss * (1.0 / (NdotL + NdotV) - 0.5) + 0.5);
-
- // specular
- float aspect = sqrt(1.0 - anisotropic * 0.9);
- float a = sqr(roughness);
- float ax = max(0.001, a / aspect);
- float ay = max(0.001, a * aspect);
- float Ds = GTR2_aniso(NdotH, dot(H, X), dot(H, Y), ax, ay); //GTR2(NdotH, a);
- float FH = (fresnel_dielectric_cos(LdotH, eta) - F0) * F0_norm;
- vec3 Fs = mix(Cspec0, vec3(1.0), FH);
- float roughg = sqr(roughness * 0.5 + 0.5);
- float Gs = smithG_GGX(NdotL, roughg) * smithG_GGX(NdotV, roughg);
-
- // sheen
- vec3 Fsheen = schlick_fresnel(LdotH) * sheen * Csheen;
-
- vec3 diffuse_bsdf = (mix(Fd * base_color.rgb, ss * subsurface_color.rgb, subsurface) + Fsheen) * light_diffuse;
- vec3 specular_bsdf = Gs * Fs * Ds * light_specular;
- diffuse_and_specular_bsdf = diffuse_bsdf * (1.0 - metallic) + specular_bsdf;
- }
- diffuse_and_specular_bsdf *= max(NdotL, 0.0);
+ vec3 out_refr;
+ color.rgb *= (refractionDepth > 0.0) ? color.rgb : vec3(1.0); /* Simulate 2 absorption event. */
+ eevee_closure_refraction(N, roughness, ior, out_refr);
+ vec3 vN = normalize(mat3(ViewMatrix) * N);
+ result = CLOSURE_DEFAULT;
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.radiance = out_refr * color.rgb;
+ result.ssr_id = REFRACT_CLOSURE_FLAG;
+}
- float CNdotL = dot(CN, light_position);
- float CNdotV = dot(CN, V);
+#endif /* VOLUMETRICS */
- vec3 clearcoat_bsdf = vec3(0.0);
- if (CNdotL >= 0.0 && CNdotV >= 0.0 && clearcoat > 0.0) {
- float CNdotH = dot(CN, H);
- //float FH = schlick_fresnel(LdotH);
+/* emission */
- // clearcoat (ior = 1.5 -> F0 = 0.04)
- float Dr = GTR1(CNdotH, sqr(clearcoat_roughness));
- float Fr = fresnel_dielectric_cos(LdotH, 1.5); //mix(0.04, 1.0, FH);
- float Gr = smithG_GGX(CNdotL, 0.25) * smithG_GGX(CNdotV, 0.25);
+void node_emission(vec4 color, float strength, vec3 vN, out Closure result)
+{
+#ifndef VOLUMETRICS
+ color *= strength;
+ result = CLOSURE_DEFAULT;
+ result.radiance = color.rgb;
+ result.opacity = color.a;
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+#else
+ result = Closure(vec3(0.0), vec3(0.0), color.rgb * strength, 0.0);
+#endif
+}
- clearcoat_bsdf = clearcoat * Gr * Fr * Dr * vec3(0.25) * light_specular;
- }
- clearcoat_bsdf *= max(CNdotL, 0.0);
+/* background */
- L += diffuse_and_specular_bsdf + clearcoat_bsdf;
- }
+void background_transform_to_world(vec3 viewvec, out vec3 worldvec)
+{
+ vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
+ vec4 co_homogenous = (ProjectionMatrixInverse * v);
- result = vec4(L, 1.0);
+ vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
+#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
+ worldvec = (ViewMatrixInverse * co).xyz;
+#else
+ worldvec = (ModelViewMatrixInverse * co).xyz;
+#endif
}
-void node_bsdf_translucent(vec4 color, vec3 N, out vec4 result)
+void node_background(vec4 color, float strength, out Closure result)
{
- node_bsdf_diffuse(color, 0.0, N, result);
+#ifndef VOLUMETRICS
+ color *= strength;
+ result = CLOSURE_DEFAULT;
+ result.radiance = color.rgb;
+ result.opacity = color.a;
+#else
+ result = CLOSURE_DEFAULT;
+#endif
}
-void node_bsdf_transparent(vec4 color, out vec4 result)
-{
- /* this isn't right */
- result.r = color.r;
- result.g = color.g;
- result.b = color.b;
- result.a = 0.0;
-}
+/* volumes */
-void node_bsdf_velvet(vec4 color, float sigma, vec3 N, out vec4 result)
+void node_volume_scatter(vec4 color, float density, float anisotropy, out Closure result)
{
- node_bsdf_diffuse(color, 0.0, N, result);
+#ifdef VOLUMETRICS
+ result = Closure(vec3(0.0), color.rgb * density, vec3(0.0), anisotropy);
+#else
+ result = CLOSURE_DEFAULT;
+#endif
}
-void node_subsurface_scattering(
- vec4 color, float scale, vec3 radius, float sharpen, float texture_blur, vec3 N,
- out vec4 result)
+void node_volume_absorption(vec4 color, float density, out Closure result)
{
- node_bsdf_diffuse(color, 0.0, N, result);
+#ifdef VOLUMETRICS
+ result = Closure((1.0 - color.rgb) * density, vec3(0.0), vec3(0.0), 0.0);
+#else
+ result = CLOSURE_DEFAULT;
+#endif
}
-void node_bsdf_hair(vec4 color, float offset, float roughnessu, float roughnessv, vec3 tangent, out vec4 result)
+void node_blackbody(float temperature, sampler2D spectrummap, out vec4 color)
{
- result = color;
+ if(temperature >= 12000.0) {
+ color = vec4(0.826270103, 0.994478524, 1.56626022, 1.0);
+ }
+ else if(temperature < 965.0) {
+ color = vec4(4.70366907, 0.0, 0.0, 1.0);
+ }
+ else {
+ float t = (temperature - 965.0) / (12000.0 - 965.0);
+ color = vec4(texture(spectrummap, vec2(t, 0.0)).rgb, 1.0);
+ }
}
-void node_bsdf_refraction(vec4 color, float roughness, float ior, vec3 N, out vec4 result)
+void node_volume_principled(
+ vec4 color,
+ float density,
+ float anisotropy,
+ vec4 absorption_color,
+ float emission_strength,
+ vec4 emission_color,
+ float blackbody_intensity,
+ vec4 blackbody_tint,
+ float temperature,
+ float density_attribute,
+ vec4 color_attribute,
+ float temperature_attribute,
+ sampler2D spectrummap,
+ out Closure result)
{
- node_bsdf_diffuse(color, 0.0, N, result);
-}
+#ifdef VOLUMETRICS
+ vec3 absorption_coeff = vec3(0.0);
+ vec3 scatter_coeff = vec3(0.0);
+ vec3 emission_coeff = vec3(0.0);
-void node_ambient_occlusion(vec4 color, out vec4 result)
-{
- result = color;
-}
+ /* Compute density. */
+ density = max(density, 0.0);
-/* emission */
+ if(density > 1e-5) {
+ density = max(density * density_attribute, 0.0);
+ }
-void node_emission(vec4 color, float strength, vec3 N, out vec4 result)
-{
- result = color * strength;
-}
+ if(density > 1e-5) {
+ /* Compute scattering and absorption coefficients. */
+ vec3 scatter_color = color.rgb * color_attribute.rgb;
-/* background */
+ scatter_coeff = scatter_color * density;
+ absorption_color.rgb = sqrt(max(absorption_color.rgb, 0.0));
+ absorption_coeff = max(1.0 - scatter_color, 0.0) * max(1.0 - absorption_color.rgb, 0.0) * density;
+ }
-void background_transform_to_world(vec3 viewvec, out vec3 worldvec)
-{
- vec4 v = (gl_ProjectionMatrix[3][3] == 0.0) ? vec4(viewvec, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
- vec4 co_homogenous = (gl_ProjectionMatrixInverse * v);
+ /* Compute emission. */
+ emission_strength = max(emission_strength, 0.0);
- vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
- worldvec = (gl_ModelViewMatrixInverse * co).xyz;
-}
+ if(emission_strength > 1e-5) {
+ emission_coeff += emission_strength * emission_color.rgb;
+ }
-void node_background(vec4 color, float strength, vec3 N, out vec4 result)
-{
- result = color * strength;
+ if(blackbody_intensity > 1e-3) {
+ /* Add temperature from attribute. */
+ float T = max(temperature * max(temperature_attribute, 0.0), 0.0);
+
+ /* Stefan-Boltzman law. */
+ float T4 = (T * T) * (T * T);
+ float sigma = 5.670373e-8 * 1e-6 / M_PI;
+ float intensity = sigma * mix(1.0, T4, blackbody_intensity);
+
+ if(intensity > 1e-5) {
+ vec4 bb;
+ node_blackbody(T, spectrummap, bb);
+ emission_coeff += bb.rgb * blackbody_tint.rgb * intensity;
+ }
+ }
+
+ result = Closure(absorption_coeff, scatter_coeff, emission_coeff, anisotropy);
+#else
+ result = CLOSURE_DEFAULT;
+#endif
}
/* closures */
-void node_mix_shader(float fac, vec4 shader1, vec4 shader2, out vec4 shader)
+void node_mix_shader(float fac, Closure shader1, Closure shader2, out Closure shader)
{
- shader = mix(shader1, shader2, fac);
+ shader = closure_mix(shader1, shader2, fac);
}
-void node_add_shader(vec4 shader1, vec4 shader2, out vec4 shader)
+void node_add_shader(Closure shader1, Closure shader2, out Closure shader)
{
- shader = shader1 + shader2;
+ shader = closure_add(shader1, shader2);
}
/* fresnel */
@@ -2825,7 +1388,7 @@ void node_add_shader(vec4 shader1, vec4 shader2, out vec4 shader)
void node_fresnel(float ior, vec3 N, vec3 I, out float result)
{
/* handle perspective/orthographic */
- vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
+ vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
float eta = max(ior, 0.00001);
result = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? eta : 1.0 / eta);
@@ -2837,7 +1400,7 @@ void node_layer_weight(float blend, vec3 N, vec3 I, out float fresnel, out float
{
/* fresnel */
float eta = max(1.0 - blend, 0.00001);
- vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
+ vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
fresnel = fresnel_dielectric(I_view, N, (gl_FrontFacing) ? 1.0 / eta : eta);
@@ -2867,11 +1430,67 @@ void node_gamma(vec4 col, float gamma, out vec4 outcol)
/* geometry */
+void node_attribute_volume_density(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf)
+{
+#if defined(MESH_SHADER) && defined(VOLUMETRICS)
+ vec3 cos = volumeObjectLocalCoord;
+#else
+ vec3 cos = vec3(0.0);
+#endif
+ outvec = texture(tex, cos).aaa;
+ outcol = vec4(outvec, 1.0);
+ outf = dot(vec3(1.0 / 3.0), outvec);
+}
+
+void node_attribute_volume_color(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf)
+{
+#if defined(MESH_SHADER) && defined(VOLUMETRICS)
+ vec3 cos = volumeObjectLocalCoord;
+#else
+ vec3 cos = vec3(0.0);
+#endif
+
+ vec4 value = texture(tex, cos).rgba;
+ /* Density is premultiplied for interpolation, divide it out here. */
+ if (value.a > 1e-8)
+ value.rgb /= value.a;
+
+ outvec = value.rgb;
+ outcol = vec4(outvec, 1.0);
+ outf = dot(vec3(1.0 / 3.0), outvec);
+}
+
+void node_attribute_volume_flame(sampler3D tex, out vec4 outcol, out vec3 outvec, out float outf)
+{
+#if defined(MESH_SHADER) && defined(VOLUMETRICS)
+ vec3 cos = volumeObjectLocalCoord;
+#else
+ vec3 cos = vec3(0.0);
+#endif
+ outf = texture(tex, cos).r;
+ outvec = vec3(outf, outf, outf);
+ outcol = vec4(outf, outf, outf, 1.0);
+}
+
+void node_attribute_volume_temperature(sampler3D tex, vec2 temperature, out vec4 outcol, out vec3 outvec, out float outf)
+{
+#if defined(MESH_SHADER) && defined(VOLUMETRICS)
+ vec3 cos = volumeObjectLocalCoord;
+#else
+ vec3 cos = vec3(0.0);
+#endif
+ float flame = texture(tex, cos).r;
+
+ outf = (flame > 0.01) ? temperature.x + flame * (temperature.y - temperature.x): 0.0;
+ outvec = vec3(outf, outf, outf);
+ outcol = vec4(outf, outf, outf, 1.0);
+}
+
void node_attribute(vec3 attr, out vec4 outcol, out vec3 outvec, out float outf)
{
outcol = vec4(attr, 1.0);
outvec = attr;
- outf = (attr.x + attr.y + attr.z) / 3.0;
+ outf = dot(vec3(1.0 / 3.0), attr);
}
void node_uvmap(vec3 attr_uv, out vec3 outvec)
@@ -2879,19 +1498,47 @@ void node_uvmap(vec3 attr_uv, out vec3 outvec)
outvec = attr_uv;
}
+void tangent_orco_x(vec3 orco_in, out vec3 orco_out)
+{
+ orco_out = vec3(0.0, (orco_in.z - 0.5) * -0.5, (orco_in.y - 0.5) * 0.5);
+}
+
+void tangent_orco_y(vec3 orco_in, out vec3 orco_out)
+{
+ orco_out = vec3((orco_in.z - 0.5) * -0.5, 0.0, (orco_in.x - 0.5) * 0.5);
+}
+
+void tangent_orco_z(vec3 orco_in, out vec3 orco_out)
+{
+ orco_out = vec3((orco_in.y - 0.5) * -0.5, (orco_in.x - 0.5) * 0.5, 0.0);
+}
+
+void node_tangentmap(vec4 attr_tangent, mat4 toworld, out vec3 tangent)
+{
+ tangent = (toworld * vec4(attr_tangent.xyz, 0.0)).xyz;
+}
+
+void node_tangent(vec3 N, vec3 orco, mat4 objmat, mat4 toworld, out vec3 T)
+{
+ N = (toworld * vec4(N, 0.0)).xyz;
+ T = (objmat * vec4(orco, 0.0)).xyz;
+ T = cross(N, normalize(cross(T, N)));
+}
+
void node_geometry(
- vec3 I, vec3 N, mat4 toworld,
+ vec3 I, vec3 N, vec3 orco, mat4 objmat, mat4 toworld,
out vec3 position, out vec3 normal, out vec3 tangent,
out vec3 true_normal, out vec3 incoming, out vec3 parametric,
out float backfacing, out float pointiness)
{
- position = (toworld * vec4(I, 1.0)).xyz;
+ position = worldPosition;
normal = (toworld * vec4(N, 0.0)).xyz;
- tangent = vec3(0.0);
+ tangent_orco_z(orco, orco);
+ node_tangent(N, orco, objmat, toworld, tangent);
true_normal = normal;
/* handle perspective/orthographic */
- vec3 I_view = (gl_ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
+ vec3 I_view = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
incoming = -(toworld * vec4(I_view, 0.0)).xyz;
parametric = vec3(0.0);
@@ -2905,16 +1552,15 @@ void node_tex_coord(
out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object,
out vec3 camera, out vec3 window, out vec3 reflection)
{
- generated = attr_orco * 0.5 + vec3(0.5);
+ generated = attr_orco;
normal = normalize((obinvmat * (viewinvmat * vec4(N, 0.0))).xyz);
uv = attr_uv;
object = (obinvmat * (viewinvmat * vec4(I, 1.0))).xyz;
camera = vec3(I.xy, -I.z);
- vec4 projvec = gl_ProjectionMatrix * vec4(I, 1.0);
+ vec4 projvec = ProjectionMatrix * vec4(I, 1.0);
window = vec3(mtex_2d_mapping(projvec.xyz / projvec.w).xy * camerafac.xy + camerafac.zw, 0.0);
- vec3 shade_I;
- shade_view(I, shade_I);
+ vec3 shade_I = (ProjectionMatrix[3][3] == 0.0) ? normalize(I) : vec3(0.0, 0.0, -1.0);
vec3 view_reflection = reflect(shade_I, normalize(N));
reflection = (viewinvmat * vec4(view_reflection, 0.0)).xyz;
}
@@ -2925,13 +1571,18 @@ void node_tex_coord_background(
out vec3 generated, out vec3 normal, out vec3 uv, out vec3 object,
out vec3 camera, out vec3 window, out vec3 reflection)
{
- vec4 v = (gl_ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
- vec4 co_homogenous = (gl_ProjectionMatrixInverse * v);
+ vec4 v = (ProjectionMatrix[3][3] == 0.0) ? vec4(I, 1.0) : vec4(0.0, 0.0, 1.0, 1.0);
+ vec4 co_homogenous = (ProjectionMatrixInverse * v);
vec4 co = vec4(co_homogenous.xyz / co_homogenous.w, 0.0);
co = normalize(co);
- vec3 coords = (gl_ModelViewMatrixInverse * co).xyz;
+
+#if defined(WORLD_BACKGROUND) || defined(PROBE_CAPTURE)
+ vec3 coords = (ViewMatrixInverse * co).xyz;
+#else
+ vec3 coords = (ModelViewMatrixInverse * co).xyz;
+#endif
generated = coords;
normal = -coords;
@@ -2939,13 +1590,17 @@ void node_tex_coord_background(
object = coords;
camera = vec3(co.xy, -co.z);
- window = (gl_ProjectionMatrix[3][3] == 0.0) ?
+ window = (ProjectionMatrix[3][3] == 0.0) ?
vec3(mtex_2d_mapping(I).xy * camerafac.xy + camerafac.zw, 0.0) :
vec3(vec2(0.5) * camerafac.xy + camerafac.zw, 0.0);
reflection = -coords;
}
+#if defined(WORLD_BACKGROUND) || (defined(PROBE_CAPTURE) && !defined(MESH_SHADER))
+#define node_tex_coord node_tex_coord_background
+#endif
+
/* textures */
float calc_gradient(vec3 p, int gradient_type)
@@ -3015,7 +1670,6 @@ void node_tex_checker(vec3 co, vec4 color1, vec4 color2, float scale, out vec4 c
fac = check ? 1.0 : 0.0;
}
-#ifdef BIT_OPERATIONS
vec2 calc_brick_texture(vec3 p, float mortar_size, float mortar_smooth, float bias,
float brick_width, float row_height,
float offset_amount, int offset_frequency,
@@ -3051,7 +1705,6 @@ vec2 calc_brick_texture(vec3 p, float mortar_size, float mortar_smooth, float bi
return vec2(tint, smoothstep(0.0, mortar_smooth, min_dist));
}
}
-#endif
void node_tex_brick(vec3 co,
vec4 color1, vec4 color2,
@@ -3062,7 +1715,6 @@ void node_tex_brick(vec3 co,
float squash_amount, float squash_frequency,
out vec4 color, out float fac)
{
-#ifdef BIT_OPERATIONS
vec2 f2 = calc_brick_texture(co * scale,
mortar_size, mortar_smooth, bias,
brick_width, row_height,
@@ -3076,10 +1728,6 @@ void node_tex_brick(vec3 co,
}
color = mix(color1, mortar, f);
fac = f;
-#else
- color = vec4(1.0);
- fac = 1.0;
-#endif
}
void node_tex_clouds(vec3 co, float size, out vec4 color, out float fac)
@@ -3094,7 +1742,15 @@ void node_tex_environment_equirectangular(vec3 co, sampler2D ima, out vec4 color
float u = -atan(nco.y, nco.x) / (2.0 * M_PI) + 0.5;
float v = atan(nco.z, hypot(nco.x, nco.y)) / M_PI + 0.5;
- color = texture2D(ima, vec2(u, v));
+ /* Fix pole bleeding */
+ float half_width = 0.5 / float(textureSize(ima, 0).x);
+ v = clamp(v, half_width, 1.0 - half_width);
+
+ /* Fix u = 0 seam */
+ /* This is caused by texture filtering, since uv don't have smooth derivatives
+ * at u = 0 or 2PI, hardware filtering is using the smallest mipmap for certain
+ * texels. So we force the highest mipmap and don't do anisotropic filtering. */
+ color = textureLod(ima, vec2(u, v), 0.0);
}
void node_tex_environment_mirror_ball(vec3 co, sampler2D ima, out vec4 color)
@@ -3110,7 +1766,7 @@ void node_tex_environment_mirror_ball(vec3 co, sampler2D ima, out vec4 color)
float u = 0.5 * (nco.x + 1.0);
float v = 0.5 * (nco.z + 1.0);
- color = texture2D(ima, vec2(u, v));
+ color = texture(ima, vec2(u, v));
}
void node_tex_environment_empty(vec3 co, out vec4 color)
@@ -3120,7 +1776,7 @@ void node_tex_environment_empty(vec3 co, out vec4 color)
void node_tex_image(vec3 co, sampler2D ima, out vec4 color, out float alpha)
{
- color = texture2D(ima, co.xy);
+ color = texture(ima, co.xy);
alpha = color.a;
}
@@ -3194,21 +1850,21 @@ void node_tex_image_box(vec3 texco,
if(signed_N.x < 0.0) {
uv.x = 1.0 - uv.x;
}
- color += weight.x * texture2D(ima, uv);
+ color += weight.x * texture(ima, uv);
}
if (weight.y > 0.0) {
vec2 uv = texco.xz;
if(signed_N.y > 0.0) {
uv.x = 1.0 - uv.x;
}
- color += weight.y * texture2D(ima, uv);
+ color += weight.y * texture(ima, uv);
}
if (weight.z > 0.0) {
vec2 uv = texco.yx;
if(signed_N.z > 0.0) {
uv.x = 1.0 - uv.x;
}
- color += weight.z * texture2D(ima, uv);
+ color += weight.z * texture(ima, uv);
}
alpha = color.a;
@@ -3281,7 +1937,6 @@ void node_tex_magic(vec3 co, float scale, float distortion, float depth, out vec
fac = (color.x + color.y + color.z) / 3.0;
}
-#ifdef BIT_OPERATIONS
float noise_fade(float t)
{
return t * t * t * (t * (t * 6.0 - 15.0) + 10.0);
@@ -3356,10 +2011,9 @@ float noise_turbulence(vec3 p, float octaves, int hard)
float fscale = 1.0;
float amp = 1.0;
float sum = 0.0;
- int i, n;
octaves = clamp(octaves, 0.0, 16.0);
- n = int(octaves);
- for (i = 0; i <= n; i++) {
+ int n = int(octaves);
+ for (int i = 0; i <= n; i++) {
float t = noise(fscale * p);
if (hard != 0) {
t = abs(2.0 * t - 1.0);
@@ -3369,7 +2023,7 @@ float noise_turbulence(vec3 p, float octaves, int hard)
fscale *= 2.0;
}
float rmd = octaves - floor(octaves);
- if (rmd != 0.0) {
+ if (rmd != 0.0) {
float t = noise(fscale * p);
if (hard != 0) {
t = abs(2.0 * t - 1.0);
@@ -3384,11 +2038,9 @@ float noise_turbulence(vec3 p, float octaves, int hard)
return sum;
}
}
-#endif // BIT_OPERATIONS
void node_tex_noise(vec3 co, float scale, float detail, float distortion, out vec4 color, out float fac)
{
-#ifdef BIT_OPERATIONS
vec3 p = co * scale;
int hard = 0;
if (distortion != 0.0) {
@@ -3404,15 +2056,8 @@ void node_tex_noise(vec3 co, float scale, float detail, float distortion, out ve
noise_turbulence(vec3(p.y, p.x, p.z), detail, hard),
noise_turbulence(vec3(p.y, p.z, p.x), detail, hard),
1);
-#else // BIT_OPERATIONS
- color = vec4(1.0);
- fac = 1.0;
-#endif // BIT_OPERATIONS
}
-
-#ifdef BIT_OPERATIONS
-
/* Musgrave fBm
*
* H: fractal increment parameter
@@ -3428,9 +2073,8 @@ float noise_musgrave_fBm(vec3 p, float H, float lacunarity, float octaves)
float value = 0.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
- int i;
- for (i = 0; i < int(octaves); i++) {
+ for (int i = 0; i < int(octaves); i++) {
value += snoise(p) * pwr;
pwr *= pwHL;
p *= lacunarity;
@@ -3456,9 +2100,8 @@ float noise_musgrave_multi_fractal(vec3 p, float H, float lacunarity, float octa
float value = 1.0;
float pwr = 1.0;
float pwHL = pow(lacunarity, -H);
- int i;
- for (i = 0; i < int(octaves); i++) {
+ for (int i = 0; i < int(octaves); i++) {
value *= (pwr * snoise(p) + 1.0);
pwr *= pwHL;
p *= lacunarity;
@@ -3484,13 +2127,12 @@ float noise_musgrave_hetero_terrain(vec3 p, float H, float lacunarity, float oct
float value, increment, rmd;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
- int i;
/* first unscaled octave of function; later octaves are scaled */
value = offset + snoise(p);
p *= lacunarity;
- for (i = 1; i < int(octaves); i++) {
+ for (int i = 1; i < int(octaves); i++) {
increment = (snoise(p) + offset) * pwr * value;
value += increment;
pwr *= pwHL;
@@ -3519,13 +2161,12 @@ float noise_musgrave_hybrid_multi_fractal(vec3 p, float H, float lacunarity, flo
float result, signal, weight, rmd;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
- int i;
result = snoise(p) + offset;
weight = gain * result;
p *= lacunarity;
- for (i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
+ for (int i = 1; (weight > 0.001f) && (i < int(octaves)); i++) {
if (weight > 1.0)
weight = 1.0;
@@ -3556,14 +2197,13 @@ float noise_musgrave_ridged_multi_fractal(vec3 p, float H, float lacunarity, flo
float result, signal, weight;
float pwHL = pow(lacunarity, -H);
float pwr = pwHL;
- int i;
signal = offset - abs(snoise(p));
signal *= signal;
result = signal;
weight = 1.0;
- for (i = 1; i < int(octaves); i++) {
+ for (int i = 1; i < int(octaves); i++) {
p *= lacunarity;
weight = clamp(signal * gain, 0.0, 1.0);
signal = offset - abs(snoise(p));
@@ -3585,19 +2225,18 @@ float svm_musgrave(int type,
float gain,
vec3 p)
{
- if (type == 0 /*NODE_MUSGRAVE_MULTIFRACTAL*/)
+ if (type == 0 /* NODE_MUSGRAVE_MULTIFRACTAL */)
return intensity * noise_musgrave_multi_fractal(p, dimension, lacunarity, octaves);
- else if (type == 1 /*NODE_MUSGRAVE_FBM*/)
+ else if (type == 1 /* NODE_MUSGRAVE_FBM */)
return intensity * noise_musgrave_fBm(p, dimension, lacunarity, octaves);
- else if (type == 2 /*NODE_MUSGRAVE_HYBRID_MULTIFRACTAL*/)
+ else if (type == 2 /* NODE_MUSGRAVE_HYBRID_MULTIFRACTAL */)
return intensity * noise_musgrave_hybrid_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
- else if (type == 3 /*NODE_MUSGRAVE_RIDGED_MULTIFRACTAL*/)
+ else if (type == 3 /* NODE_MUSGRAVE_RIDGED_MULTIFRACTAL */)
return intensity * noise_musgrave_ridged_multi_fractal(p, dimension, lacunarity, octaves, offset, gain);
- else if (type == 4 /*NODE_MUSGRAVE_HETERO_TERRAIN*/)
+ else if (type == 4 /* NODE_MUSGRAVE_HETERO_TERRAIN */)
return intensity * noise_musgrave_hetero_terrain(p, dimension, lacunarity, octaves, offset);
return 0.0;
}
-#endif // #ifdef BIT_OPERATIONS
void node_tex_musgrave(vec3 co,
float scale,
@@ -3610,7 +2249,6 @@ void node_tex_musgrave(vec3 co,
out vec4 color,
out float fac)
{
-#ifdef BIT_OPERATIONS
fac = svm_musgrave(int(type),
dimension,
lacunarity,
@@ -3619,9 +2257,6 @@ void node_tex_musgrave(vec3 co,
1.0,
gain,
co * scale);
-#else
- fac = 1.0;
-#endif
color = vec4(fac, fac, fac, 1.0);
}
@@ -3633,7 +2268,6 @@ void node_tex_sky(vec3 co, out vec4 color)
void node_tex_voronoi(vec3 co, float scale, float coloring, out vec4 color, out float fac)
{
-#ifdef BIT_OPERATIONS
vec3 p = co * scale;
int xx, yy, zz, xi, yi, zi;
float da[4];
@@ -3698,13 +2332,8 @@ void node_tex_voronoi(vec3 co, float scale, float coloring, out vec4 color, out
color = vec4(cellnoise_color(pa[0]), 1);
fac = (color.x + color.y + color.z) * (1.0 / 3.0);
}
-#else // BIT_OPERATIONS
- color = vec4(1.0);
- fac = 1.0;
-#endif // BIT_OPERATIONS
}
-#ifdef BIT_OPERATIONS
float calc_wave(vec3 p, float distortion, float detail, float detail_scale, int wave_type, int wave_profile)
{
float n;
@@ -3726,22 +2355,16 @@ float calc_wave(vec3 p, float distortion, float detail, float detail_scale, int
return (n < 0.0) ? n + 1.0 : n;
}
}
-#endif // BIT_OPERATIONS
void node_tex_wave(
vec3 co, float scale, float distortion, float detail, float detail_scale, float wave_type, float wave_profile,
out vec4 color, out float fac)
{
-#ifdef BIT_OPERATIONS
float f;
f = calc_wave(co * scale, distortion, detail, detail_scale, int(wave_type), int(wave_profile));
color = vec4(f, f, f, 1.0);
fac = f;
-#else // BIT_OPERATIONS
- color = vec4(1.0);
- fac = 1;
-#endif // BIT_OPERATIONS
}
/* light path */
@@ -3761,13 +2384,21 @@ void node_light_path(
out float transparent_depth,
out float transmission_depth)
{
+#ifndef PROBE_CAPTURE
is_camera_ray = 1.0;
- is_shadow_ray = 0.0;
- is_diffuse_ray = 0.0;
is_glossy_ray = 0.0;
- is_singular_ray = 0.0;
+ is_diffuse_ray = 0.0;
is_reflection_ray = 0.0;
is_transmission_ray = 0.0;
+#else
+ is_camera_ray = 0.0;
+ is_glossy_ray = 1.0;
+ is_diffuse_ray = 1.0;
+ is_reflection_ray = 1.0;
+ is_transmission_ray = 1.0;
+#endif
+ is_shadow_ray = 0.0;
+ is_singular_ray = 0.0;
ray_length = 1.0;
ray_depth = 1.0;
diffuse_depth = 1.0;
@@ -3866,37 +2497,51 @@ void node_vector_displacement_world(vec4 vector, float midlevel, float scale, ou
/* output */
-void node_output_material(vec4 surface, vec4 volume, vec3 displacement, out vec4 result)
+void node_output_material(Closure surface, Closure volume, vec3 displacement, out Closure result)
{
+#ifdef VOLUMETRICS
+ result = volume;
+#else
result = surface;
+#endif
}
-void node_output_world(vec4 surface, vec4 volume, out vec4 result)
+uniform float backgroundAlpha;
+
+void node_output_world(Closure surface, Closure volume, out Closure result)
{
- result = surface;
+#ifndef VOLUMETRICS
+ result.radiance = surface.radiance;
+ result.opacity = backgroundAlpha;
+#else
+ result = volume;
+#endif /* VOLUMETRICS */
}
-/* ********************** matcap style render ******************** */
+#ifndef VOLUMETRICS
+/* TODO : clean this ifdef mess */
+/* EEVEE output */
+void world_normals_get(out vec3 N)
+{
+ N = gl_FrontFacing ? worldNormal : -worldNormal;
+}
-void material_preview_matcap(vec4 color, sampler2D ima, vec4 N, vec4 mask, out vec4 result)
+void node_eevee_specular(
+ vec4 diffuse, vec4 specular, float roughness, vec4 emissive, float transp, vec3 normal,
+ float clearcoat, float clearcoat_roughness, vec3 clearcoat_normal,
+ float occlusion, float ssr_id, out Closure result)
{
- vec3 normal;
- vec2 tex;
-
-#ifndef USE_OPENSUBDIV
- /* remap to 0.0 - 1.0 range. This is done because OpenGL 2.0 clamps colors
- * between shader stages and we want the full range of the normal */
- normal = vec3(2.0, 2.0, 2.0) * vec3(N.x, N.y, N.z) - vec3(1.0, 1.0, 1.0);
- if (normal.z < 0.0) {
- normal.z = 0.0;
- }
- normal = normalize(normal);
-#else
- normal = inpt.v.normal;
- mask = vec4(1.0, 1.0, 1.0, 1.0);
-#endif
+ vec3 out_diff, out_spec, ssr_spec;
+ eevee_closure_default(normal, diffuse.rgb, specular.rgb, int(ssr_id), roughness, occlusion,
+ out_diff, out_spec, ssr_spec);
- tex.x = 0.5 + 0.49 * normal.x;
- tex.y = 0.5 + 0.49 * normal.y;
- result = texture2D(ima, tex) * mask;
+ vec3 vN = normalize(mat3(ViewMatrix) * normal);
+ result = CLOSURE_DEFAULT;
+ result.radiance = out_diff * diffuse.rgb + out_spec + emissive.rgb;
+ result.opacity = 1.0 - transp;
+ result.ssr_data = vec4(ssr_spec, roughness);
+ result.ssr_normal = normal_encode(vN, viewCameraVec);
+ result.ssr_id = int(ssr_id);
}
+
+#endif /* VOLUMETRICS */
diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl
new file mode 100644
index 00000000000..fef81cf58fe
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_aa_frag.glsl
@@ -0,0 +1,24 @@
+
+uniform vec4 color;
+
+in vec2 radii;
+out vec4 fragColor;
+
+void main() {
+ float dist = length(gl_PointCoord - vec2(0.5));
+
+// transparent outside of point
+// --- 0 ---
+// smooth transition
+// --- 1 ---
+// pure point color
+// ...
+// dist = 0 at center of point
+
+ fragColor.rgb = color.rgb;
+ fragColor.a = mix(color.a, 0.0, smoothstep(radii[1], radii[0], dist));
+
+ if (fragColor.a == 0.0) {
+ discard;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl
new file mode 100644
index 00000000000..852c76fcb26
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_frag.glsl
@@ -0,0 +1,17 @@
+
+uniform vec4 color;
+
+out vec4 fragColor;
+
+void main()
+{
+ vec2 centered = gl_PointCoord - vec2(0.5);
+ float dist_squared = dot(centered, centered);
+ const float rad_squared = 0.25;
+
+ // round point with jaggy edges
+ if (dist_squared > rad_squared)
+ discard;
+
+ fragColor = color;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl
new file mode 100644
index 00000000000..eae5ee633ae
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_point_uniform_color_outline_aa_frag.glsl
@@ -0,0 +1,36 @@
+
+uniform vec4 color;
+uniform vec4 outlineColor;
+
+in vec4 radii;
+out vec4 fragColor;
+
+void main() {
+ float dist = length(gl_PointCoord - vec2(0.5));
+
+// transparent outside of point
+// --- 0 ---
+// smooth transition
+// --- 1 ---
+// pure outline color
+// --- 2 ---
+// smooth transition
+// --- 3 ---
+// pure point color
+// ...
+// dist = 0 at center of point
+
+ float midStroke = 0.5 * (radii[1] + radii[2]);
+
+ if (dist > midStroke) {
+ fragColor.rgb = outlineColor.rgb;
+ fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
+ }
+ else {
+ fragColor = mix(color, outlineColor, smoothstep(radii[3], radii[2], dist));
+ }
+
+ if (fragColor.a == 0.0) {
+ discard;
+ }
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl
new file mode 100644
index 00000000000..2d2724bb686
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_frag.glsl
@@ -0,0 +1,16 @@
+
+in vec4 finalColor;
+out vec4 fragColor;
+
+void main()
+{
+ vec2 centered = gl_PointCoord - vec2(0.5);
+ float dist_squared = dot(centered, centered);
+ const float rad_squared = 0.25;
+
+ // round point with jaggy edges
+ if (dist_squared > rad_squared)
+ discard;
+
+ fragColor = finalColor;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl b/source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl
new file mode 100644
index 00000000000..9b7d4bfc6d6
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_point_varying_color_outline_aa_frag.glsl
@@ -0,0 +1,31 @@
+
+uniform vec4 outlineColor;
+
+in vec4 radii;
+in vec4 fillColor;
+out vec4 fragColor;
+
+void main() {
+ float dist = length(gl_PointCoord - vec2(0.5));
+
+// transparent outside of point
+// --- 0 ---
+// smooth transition
+// --- 1 ---
+// pure outline color
+// --- 2 ---
+// smooth transition
+// --- 3 ---
+// pure fill color
+// ...
+// dist = 0 at center of point
+
+ float midStroke = 0.5 * (radii[1] + radii[2]);
+
+ if (dist > midStroke) {
+ fragColor.rgb = outlineColor.rgb;
+ fragColor.a = mix(outlineColor.a, 0.0, smoothstep(radii[1], radii[0], dist));
+ }
+ else
+ fragColor = mix(fillColor, outlineColor, smoothstep(radii[3], radii[2], dist));
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl
index b485d2cce86..78241a798a2 100644
--- a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_frag.glsl
@@ -1,16 +1,19 @@
uniform vec2 ScaleU;
uniform sampler2D textureSource;
+in vec2 texCoord_interp;
+out vec4 fragColor;
+
void main()
{
vec4 color = vec4(0.0);
- color += texture2D(textureSource, gl_TexCoord[0].st + vec2(-3.0 * ScaleU.x, -3.0 * ScaleU.y)) * 0.015625;
- color += texture2D(textureSource, gl_TexCoord[0].st + vec2(-2.0 * ScaleU.x, -2.0 * ScaleU.y)) * 0.09375;
- color += texture2D(textureSource, gl_TexCoord[0].st + vec2(-1.0 * ScaleU.x, -1.0 * ScaleU.y)) * 0.234375;
- color += texture2D(textureSource, gl_TexCoord[0].st + vec2(0.0, 0.0)) * 0.3125;
- color += texture2D(textureSource, gl_TexCoord[0].st + vec2(1.0 * ScaleU.x, 1.0 * ScaleU.y)) * 0.234375;
- color += texture2D(textureSource, gl_TexCoord[0].st + vec2(2.0 * ScaleU.x, 2.0 * ScaleU.y)) * 0.09375;
- color += texture2D(textureSource, gl_TexCoord[0].st + vec2(3.0 * ScaleU.x, 3.0 * ScaleU.y)) * 0.015625;
+ color += texture(textureSource, texCoord_interp.st + vec2(-3.0 * ScaleU.x, -3.0 * ScaleU.y)) * 0.015625;
+ color += texture(textureSource, texCoord_interp.st + vec2(-2.0 * ScaleU.x, -2.0 * ScaleU.y)) * 0.09375;
+ color += texture(textureSource, texCoord_interp.st + vec2(-1.0 * ScaleU.x, -1.0 * ScaleU.y)) * 0.234375;
+ color += texture(textureSource, texCoord_interp.st + vec2(0.0, 0.0)) * 0.3125;
+ color += texture(textureSource, texCoord_interp.st + vec2(1.0 * ScaleU.x, 1.0 * ScaleU.y)) * 0.234375;
+ color += texture(textureSource, texCoord_interp.st + vec2(2.0 * ScaleU.x, 2.0 * ScaleU.y)) * 0.09375;
+ color += texture(textureSource, texCoord_interp.st + vec2(3.0 * ScaleU.x, 3.0 * ScaleU.y)) * 0.015625;
- gl_FragColor = color;
+ fragColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl
index 5d00108b052..fca39852c2a 100644
--- a/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_sep_gaussian_blur_vert.glsl
@@ -1,6 +1,14 @@
+out vec2 texCoord_interp;
+
void main()
{
- gl_Position = ftransform();
- gl_TexCoord[0] = gl_MultiTexCoord0;
+ const vec4 vert[3] = vec4[3](
+ vec3(-1.0, -1.0, 0.0, 0.0),
+ vec3( 3.0, -1.0, 2.0, 0.0),
+ vec3(-1.0, 3.0, 0.0, 2.0)
+ );
+
+ gl_Position = vec4(vert[gl_VertexID].xy, 0.0, 1.0);
+ texCoord_interp = vert[gl_VertexID].zw;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
new file mode 100644
index 00000000000..d65768eff4d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_frag.glsl
@@ -0,0 +1,18 @@
+
+#ifndef USE_INSTANCE_COLOR
+uniform vec4 color;
+#endif
+uniform vec3 light;
+
+in vec3 normal;
+#ifdef USE_INSTANCE_COLOR
+flat in vec4 finalColor;
+# define color finalColor
+#endif
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = color;
+ fragColor.xyz *= clamp(dot(normalize(normal), light), 0.0, 1.0);
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl
new file mode 100644
index 00000000000..6b13f408c84
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_alpha_frag.glsl
@@ -0,0 +1,14 @@
+
+uniform vec3 light;
+uniform float alpha;
+uniform float global;
+
+in vec3 normal;
+in vec4 finalColor;
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = finalColor * (global + (1.0 - global) * max(0.0, dot(normalize(normal), light)));
+ fragColor.a = alpha;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl
new file mode 100644
index 00000000000..58c5f292647
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_simple_lighting_smooth_color_frag.glsl
@@ -0,0 +1,16 @@
+
+uniform vec3 light;
+
+#ifdef USE_FLAT_NORMAL
+flat in vec3 normal;
+flat in vec4 finalColor;
+#else
+in vec3 normal;
+in vec4 finalColor;
+#endif
+out vec4 fragColor;
+
+void main()
+{
+ fragColor = finalColor * max(0.0, dot(normalize(normal), light));
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl
index 6ded453225e..b57bd5b6a37 100644
--- a/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_smoke_frag.glsl
@@ -1,5 +1,6 @@
-varying vec3 coords;
+in vec3 coords;
+out vec4 fragColor;
uniform vec3 active_color;
uniform float step_size;
@@ -16,7 +17,7 @@ uniform sampler3D color_band_texture;
void main()
{
/* compute color and density from volume texture */
- vec4 soot = texture3D(soot_texture, coords);
+ vec4 soot = texture(soot_texture, coords);
#ifndef USE_COBA
vec3 soot_color;
@@ -24,7 +25,7 @@ void main()
soot_color = active_color * soot.rgb / soot.a;
}
else {
- soot_color = vec3(0, 0, 0);
+ soot_color = vec3(0);
}
float soot_density = density_scale * soot.a;
@@ -33,16 +34,14 @@ void main()
float soot_alpha = 1.0 - soot_transmittance;
/* shade */
- float shadow = texture3D(shadow_texture, coords).r;
+ float shadow = texture(shadow_texture, coords).r;
soot_color *= soot_transmittance * shadow;
/* premultiply alpha */
- vec4 color = vec4(soot_alpha * soot_color, soot_alpha);
+ fragColor = vec4(soot_alpha * soot_color, soot_alpha);
#else
- float color_band = texture3D(color_band_texture, coords).r;
- vec4 transfer_function = texture1D(transfer_texture, color_band);
- vec4 color = transfer_function * density_scale;
+ float color_band = texture(color_band_texture, coords).r;
+ vec4 transfer_function = texture(transfer_texture, color_band);
+ fragColor = transfer_function * density_scale;
#endif
-
- gl_FragColor = color;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl b/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl
index 297486ae26a..8c30e9baf9e 100644
--- a/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_smoke_vert.glsl
@@ -1,5 +1,7 @@
-varying vec3 coords;
+uniform mat4 ModelViewProjectionMatrix;
+
+out vec3 coords;
uniform vec3 min_location;
uniform vec3 invsize;
@@ -7,6 +9,7 @@ uniform vec3 ob_sizei;
void main()
{
- gl_Position = gl_ModelViewProjectionMatrix * vec4(gl_Vertex.xyz * ob_sizei, 1.0);
+ // TODO: swap gl_Vertex for vec3 pos, update smoke setup code
+ gl_Position = ModelViewProjectionMatrix * vec4(gl_Vertex.xyz * ob_sizei, 1.0);
coords = (gl_Vertex.xyz - min_location) * invsize;
}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_frag.glsl b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
new file mode 100644
index 00000000000..fbfa4cfcc9d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_text_frag.glsl
@@ -0,0 +1,74 @@
+
+flat in vec4 color_flat;
+flat in vec4 texCoord_rect;
+noperspective in vec2 texCoord_interp;
+out vec4 fragColor;
+
+uniform sampler2D glyph;
+
+const vec2 offsets4[4] = vec2[4](
+ vec2(-0.5, 0.5), vec2( 0.5, 0.5),
+ vec2(-0.5, -0.5), vec2(-0.5, -0.5)
+);
+
+const vec2 offsets16[16] = vec2[16](
+ vec2(-1.5, 1.5), vec2(-0.5, 1.5), vec2( 0.5, 1.5), vec2( 1.5, 1.5),
+ vec2(-1.5, 0.5), vec2(-0.5, 0.5), vec2( 0.5, 0.5), vec2( 1.5, 0.5),
+ vec2(-1.5, -0.5), vec2(-0.5, -0.5), vec2( 0.5, -0.5), vec2( 1.5, -0.5),
+ vec2(-1.5, -1.5), vec2(-0.5, -1.5), vec2( 0.5, -1.5), vec2( 1.5, -1.5)
+);
+
+#define sample_glyph_offset(texco, texel, ofs) texture(glyph, texco + ofs * texel).r
+
+void main()
+{
+ // input color replaces texture color
+ fragColor.rgb = color_flat.rgb;
+
+ vec2 texel = 1.0 / vec2(textureSize(glyph, 0));
+ vec2 texco = mix(abs(texCoord_rect.xy), abs(texCoord_rect.zw), texCoord_interp);
+
+ // modulate input alpha & texture alpha
+ if (texCoord_rect.x > 0) {
+ fragColor.a = texture(glyph, texco).r;
+ }
+ else {
+ fragColor.a = 0.0;
+
+ if (texCoord_rect.w > 0) {
+ /* 3x3 blur */
+ /* Manual unroll for perf. (stupid glsl compiler) */
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[0]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[1]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[2]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets4[3]);
+ fragColor.a *= (1.0 / 4.0);
+ }
+ else {
+ /* 5x5 blur */
+ /* Manual unroll for perf. (stupid glsl compiler) */
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 0]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 1]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 2]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 3]);
+
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 4]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 5]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 6]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 7]);
+
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 8]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[ 9]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[10]) * 2.0;
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[11]);
+
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[12]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[13]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[14]);
+ fragColor.a += sample_glyph_offset(texco, texel, offsets16[15]);
+ fragColor.a *= (1.0 / 20.0);
+ }
+ }
+
+ fragColor.a *= color_flat.a;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
new file mode 100644
index 00000000000..0acd2106f7a
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_text_geom.glsl
@@ -0,0 +1,37 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+layout(points) in;
+layout(triangle_strip, max_vertices = 4) out;
+
+in vec4 pos_rect[];
+in vec4 tex_rect[];
+in vec4 color[];
+
+flat out vec4 color_flat;
+flat out vec4 texCoord_rect;
+noperspective out vec2 texCoord_interp;
+
+void main()
+{
+ color_flat = color[0];
+ texCoord_rect = tex_rect[0];
+
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xy, 0.0, 1.0));
+ texCoord_interp = vec2(0.0, 0.0);
+ EmitVertex();
+
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zy, 0.0, 1.0));
+ texCoord_interp = vec2(1.0, 0.0);
+ EmitVertex();
+
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].xw, 0.0, 1.0));
+ texCoord_interp = vec2(0.0, 1.0);
+ EmitVertex();
+
+ gl_Position = (ModelViewProjectionMatrix * vec4(pos_rect[0].zw, 0.0, 1.0));
+ texCoord_interp = vec2(1.0, 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
new file mode 100644
index 00000000000..8903fd1df57
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_text_simple_geom.glsl
@@ -0,0 +1,36 @@
+
+layout(points) in;
+layout(triangle_strip, max_vertices = 4) out;
+
+in vec4 pos_rect[];
+in vec4 tex_rect[];
+in vec4 color[];
+
+flat out vec4 color_flat;
+flat out vec4 texCoord_rect;
+noperspective out vec2 texCoord_interp;
+
+void main()
+{
+ color_flat = color[0];
+ texCoord_rect = tex_rect[0];
+ gl_Position.zw = vec2(0.0, 1.0);
+
+ gl_Position.xy = pos_rect[0].xy;
+ texCoord_interp = vec2(0.0, 0.0);
+ EmitVertex();
+
+ gl_Position.xy = pos_rect[0].zy;
+ texCoord_interp = vec2(1.0, 0.0);
+ EmitVertex();
+
+ gl_Position.xy = pos_rect[0].xw;
+ texCoord_interp = vec2(0.0, 1.0);
+ EmitVertex();
+
+ gl_Position.xy = pos_rect[0].zw;
+ texCoord_interp = vec2(1.0, 1.0);
+ EmitVertex();
+
+ EndPrimitive();
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
new file mode 100644
index 00000000000..4a2cde71e07
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_text_simple_vert.glsl
@@ -0,0 +1,22 @@
+
+/* Simpler version of gpu_shader_text_vert that supports only 2D translation. */
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec4 pos; /* rect */
+in vec4 tex; /* rect */
+in vec4 col;
+
+out vec4 pos_rect;
+out vec4 tex_rect;
+out vec4 color;
+
+void main()
+{
+ /* Manual mat4*vec2 */
+ pos_rect = ModelViewProjectionMatrix[0].xyxy * pos.xxzz;
+ pos_rect += ModelViewProjectionMatrix[1].xyxy * pos.yyww;
+ pos_rect += ModelViewProjectionMatrix[3].xyxy;
+ tex_rect = tex;
+ color = col;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_text_vert.glsl b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
new file mode 100644
index 00000000000..338156f5b68
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_text_vert.glsl
@@ -0,0 +1,17 @@
+
+uniform mat4 ModelViewProjectionMatrix;
+
+in vec4 pos; /* rect */
+in vec4 tex; /* rect */
+in vec4 col;
+
+out vec4 pos_rect;
+out vec4 tex_rect;
+out vec4 color;
+
+void main()
+{
+ pos_rect = pos;
+ tex_rect = tex;
+ color = col;
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
new file mode 100644
index 00000000000..118a661863d
--- /dev/null
+++ b/source/blender/gpu/shaders/gpu_shader_uniform_color_frag.glsl
@@ -0,0 +1,21 @@
+
+#if defined(USE_COLOR_U32)
+uniform uint color;
+#else
+uniform vec4 color;
+#endif
+
+out vec4 fragColor;
+
+void main()
+{
+#if defined(USE_COLOR_U32)
+ fragColor = vec4(
+ ((color ) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 8) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 16) & uint(0xFF)) * (1.0f / 255.0f),
+ ((color >> 24) ) * (1.0f / 255.0f));
+#else
+ fragColor = color;
+#endif
+}
diff --git a/source/blender/gpu/shaders/gpu_shader_vertex.glsl b/source/blender/gpu/shaders/gpu_shader_vertex.glsl
index db0068d2f3d..2a6c137e195 100644
--- a/source/blender/gpu/shaders/gpu_shader_vertex.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_vertex.glsl
@@ -1,3 +1,8 @@
+
+uniform mat4 ModelViewMatrix;
+uniform mat4 ProjectionMatrix;
+uniform mat3 NormalMatrix;
+
#ifdef USE_OPENSUBDIV
in vec3 normal;
in vec4 position;
@@ -7,8 +12,8 @@ out block {
} outpt;
#endif
-varying vec3 varposition;
-varying vec3 varnormal;
+out vec3 varposition;
+out vec3 varnormal;
#ifdef CLIP_WORKAROUND
varying float gl_ClipDistance[6];
@@ -42,11 +47,7 @@ void srgb_to_linearrgb(vec4 col_from, out vec4 col_to)
bool is_srgb(int info)
{
-#ifdef USE_NEW_SHADING
return (info == 1)? true: false;
-#else
- return false;
-#endif
}
void set_var_from_attr(float attr, int info, out float var)
@@ -89,11 +90,11 @@ void main()
vec3 normal = gl_Normal;
#endif
- vec4 co = gl_ModelViewMatrix * position;
+ vec4 co = ModelViewMatrix * position;
varposition = co.xyz;
- varnormal = normalize(gl_NormalMatrix * normal);
- gl_Position = gl_ProjectionMatrix * co;
+ varnormal = normalize(NormalMatrix * normal);
+ gl_Position = ProjectionMatrix * co;
#ifdef CLIP_WORKAROUND
int i;
diff --git a/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl b/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl
index d45a4b316a8..af2e4ba19a2 100644
--- a/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_vertex_world.glsl
@@ -1,7 +1,6 @@
-varying vec3 varposition;
-varying vec3 varnormal;
-
+out vec3 varposition;
+out vec3 varnormal;
/* Color, keep in sync with: gpu_shader_vertex.glsl */
@@ -30,11 +29,7 @@ void srgb_to_linearrgb(vec4 col_from, out vec4 col_to)
bool is_srgb(int info)
{
-#ifdef USE_NEW_SHADING
return (info == 1)? true: false;
-#else
- return false;
-#endif
}
void set_var_from_attr(float attr, int info, out float var)
diff --git a/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl b/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl
index 3761bf350eb..6aad94bbf59 100644
--- a/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_vsm_store_frag.glsl
@@ -2,7 +2,8 @@
* This fragment shader was initially found at http://fabiensanglard.net/shadowmappingVSM/index.php
*/
-varying vec4 v_position;
+in vec4 v_position;
+out vec4 fragColor;
void main()
{
@@ -17,5 +18,6 @@ void main()
float dy = dFdy(depth);
moment2 += 0.25 * (dx * dx + dy * dy);
- gl_FragColor = vec4(moment1, moment2, 0.0, 0.0);
+ fragColor = vec4(moment1, moment2, 0.0, 0.0);
+ // TODO: write to a 2-component target --^
}
diff --git a/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl b/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl
index 224c3e78adc..def835156f7 100644
--- a/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl
+++ b/source/blender/gpu/shaders/gpu_shader_vsm_store_vert.glsl
@@ -1,7 +1,10 @@
-varying vec4 v_position;
+
+uniform mat4 ModelViewProjectionMatrix;
+
+out vec4 v_position;
void main()
{
- gl_Position = ftransform();
+ gl_Position = ModelViewProjectionMatrix * gl_Vertex;
v_position = gl_Position;
}
diff --git a/source/blender/ikplugin/BIK_api.h b/source/blender/ikplugin/BIK_api.h
index 177be074897..2a7a473db51 100644
--- a/source/blender/ikplugin/BIK_api.h
+++ b/source/blender/ikplugin/BIK_api.h
@@ -43,6 +43,7 @@ struct bPoseChannel;
struct bPose;
struct Scene;
struct bConstraint;
+struct Depsgraph;
enum BIK_ParamType {
BIK_PARAM_TYPE_FLOAT = 0,
@@ -61,8 +62,8 @@ struct BIK_ParamValue {
};
typedef struct BIK_ParamValue BIK_ParamValue;
-void BIK_initialize_tree(struct Scene *scene, struct Object *ob, float ctime);
-void BIK_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime);
+void BIK_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime);
+void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime);
void BIK_release_tree(struct Scene *scene, struct Object *ob, float ctime);
void BIK_clear_data(struct bPose *pose);
void BIK_clear_cache(struct bPose *pose);
diff --git a/source/blender/ikplugin/intern/ikplugin_api.c b/source/blender/ikplugin/intern/ikplugin_api.c
index 0f81fb34a63..9330f969ae7 100644
--- a/source/blender/ikplugin/intern/ikplugin_api.c
+++ b/source/blender/ikplugin/intern/ikplugin_api.c
@@ -89,20 +89,20 @@ static IKPlugin *get_plugin(bPose *pose)
/*----------------------------------------*/
/* Plugin API */
-void BIK_initialize_tree(Scene *scene, Object *ob, float ctime)
+void BIK_initialize_tree(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
{
IKPlugin *plugin = get_plugin(ob->pose);
if (plugin && plugin->initialize_tree_func)
- plugin->initialize_tree_func(scene, ob, ctime);
+ plugin->initialize_tree_func(depsgraph, scene, ob, ctime);
}
-void BIK_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime)
+void BIK_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan, float ctime)
{
IKPlugin *plugin = get_plugin(ob->pose);
if (plugin && plugin->execute_tree_func)
- plugin->execute_tree_func(scene, ob, pchan, ctime);
+ plugin->execute_tree_func(depsgraph, scene, ob, pchan, ctime);
}
void BIK_release_tree(struct Scene *scene, Object *ob, float ctime)
diff --git a/source/blender/ikplugin/intern/ikplugin_api.h b/source/blender/ikplugin/intern/ikplugin_api.h
index cd32bf26242..1c55639c33b 100644
--- a/source/blender/ikplugin/intern/ikplugin_api.h
+++ b/source/blender/ikplugin/intern/ikplugin_api.h
@@ -38,14 +38,15 @@
extern "C" {
#endif
+struct Depsgraph;
struct Object;
-struct bPoseChannel;
struct Scene;
+struct bPoseChannel;
struct IKPlugin {
- void (*initialize_tree_func)(struct Scene *scene, struct Object *ob, float ctime);
- void (*execute_tree_func)(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime);
+ void (*initialize_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime);
+ void (*execute_tree_func)(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan, float ctime);
void (*release_tree_func)(struct Scene *scene, struct Object *ob, float ctime);
void (*remove_armature_func)(struct bPose *pose);
void (*clear_cache)(struct bPose *pose);
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.c b/source/blender/ikplugin/intern/iksolver_plugin.c
index f837789914e..8ad07d85639 100644
--- a/source/blender/ikplugin/intern/iksolver_plugin.c
+++ b/source/blender/ikplugin/intern/iksolver_plugin.c
@@ -252,7 +252,7 @@ static void where_is_ik_bone(bPoseChannel *pchan, float ik_mat[3][3]) // nr =
/* called from within the core BKE_pose_where_is loop, all animsystems and constraints
* were executed & assigned. Now as last we do an IK pass */
-static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
+static void execute_posetree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, PoseTree *tree)
{
float R_parmat[3][3], identity[3][3];
float iR_parmat[3][3];
@@ -394,7 +394,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
/* 1.0=ctime, we pass on object for auto-ik (owner-type here is object, even though
* strictly speaking, it is a posechannel)
*/
- BKE_constraint_target_matrix_get(scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0);
+ BKE_constraint_target_matrix_get(depsgraph, scene, target->con, 0, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0);
/* and set and transform goal */
mul_m4_m4m4(goal, goalinv, rootmat);
@@ -405,7 +405,7 @@ static void execute_posetree(struct Scene *scene, Object *ob, PoseTree *tree)
/* same for pole vector target */
if (data->poletar) {
- BKE_constraint_target_matrix_get(scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0);
+ BKE_constraint_target_matrix_get(depsgraph, scene, target->con, 1, CONSTRAINT_OBTYPE_OBJECT, ob, rootmat, 1.0);
if (data->flag & CONSTRAINT_IK_SETANGLE) {
/* don't solve IK when we are setting the pole angle */
@@ -534,7 +534,7 @@ static void free_posetree(PoseTree *tree)
///----------------------------------------
/// Plugin API for legacy iksolver
-void iksolver_initialize_tree(struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime))
+void iksolver_initialize_tree(struct Depsgraph *UNUSED(depsgraph), struct Scene *UNUSED(scene), struct Object *ob, float UNUSED(ctime))
{
bPoseChannel *pchan;
@@ -545,7 +545,7 @@ void iksolver_initialize_tree(struct Scene *UNUSED(scene), struct Object *ob, fl
ob->pose->flag &= ~POSE_WAS_REBUILT;
}
-void iksolver_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
+void iksolver_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
{
while (pchan_root->iktree.first) {
PoseTree *tree = pchan_root->iktree.first;
@@ -558,13 +558,13 @@ void iksolver_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan
/* 4. walk over the tree for regular solving */
for (a = 0; a < tree->totchannel; a++) {
if (!(tree->pchan[a]->flag & POSE_DONE)) // successive trees can set the flag
- BKE_pose_where_is_bone(scene, ob, tree->pchan[a], ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, scene, ob, tree->pchan[a], ctime, 1);
/* tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is() */
tree->pchan[a]->flag |= POSE_CHAIN;
}
/* 5. execute the IK solver */
- execute_posetree(scene, ob, tree);
+ execute_posetree(depsgraph, scene, ob, tree);
/* 6. apply the differences to the channels,
* we need to calculate the original differences first */
diff --git a/source/blender/ikplugin/intern/iksolver_plugin.h b/source/blender/ikplugin/intern/iksolver_plugin.h
index 07264280a25..9925d3c45d4 100644
--- a/source/blender/ikplugin/intern/iksolver_plugin.h
+++ b/source/blender/ikplugin/intern/iksolver_plugin.h
@@ -40,8 +40,11 @@
extern "C" {
#endif
-void iksolver_initialize_tree(struct Scene *scene, struct Object *ob, float ctime);
-void iksolver_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime);
+void iksolver_initialize_tree(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime);
+void iksolver_execute_tree(
+ struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob,
+ struct bPoseChannel *pchan_root, float ctime);
#ifdef __cplusplus
}
diff --git a/source/blender/ikplugin/intern/itasc_plugin.cpp b/source/blender/ikplugin/intern/itasc_plugin.cpp
index d58340965a7..af303556090 100644
--- a/source/blender/ikplugin/intern/itasc_plugin.cpp
+++ b/source/blender/ikplugin/intern/itasc_plugin.cpp
@@ -90,6 +90,7 @@ typedef void (*ErrorCallback)(const iTaSC::ConstraintValues *values, unsigned in
// one structure for each target in the scene
struct IK_Target {
+ struct Depsgraph *bldepsgraph;
struct Scene *blscene;
iTaSC::MovingFrame* target;
iTaSC::ConstraintSet* constraint;
@@ -107,6 +108,7 @@ struct IK_Target {
float eeRest[4][4]; //end effector initial pose relative to armature
IK_Target() {
+ bldepsgraph = NULL;
blscene = NULL;
target = NULL;
constraint = NULL;
@@ -157,6 +159,7 @@ struct IK_Channel {
};
struct IK_Scene {
+ struct Depsgraph *bldepsgraph;
struct Scene *blscene;
IK_Scene* next;
int numchan; // number of channel in pchan
@@ -177,6 +180,7 @@ struct IK_Scene {
std::vector<IK_Target*> targets;
IK_Scene() {
+ bldepsgraph = NULL;
blscene = NULL;
next = NULL;
channels = NULL;
@@ -550,7 +554,7 @@ static bool target_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Fram
bConstraint *constraint = (bConstraint *)target->blenderConstraint;
float tarmat[4][4];
- BKE_constraint_target_matrix_get(target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0);
+ BKE_constraint_target_matrix_get(target->bldepsgraph, target->blscene, constraint, 0, CONSTRAINT_OBTYPE_OBJECT, target->owner, tarmat, 1.0);
// rootmat contains the target pose in world coordinate
// if enforce is != 1.0, blend the target position with the end effector position
@@ -619,7 +623,7 @@ static bool base_callback(const iTaSC::Timestamp& timestamp, const iTaSC::Frame&
IK_Channel &rootchan = ikscene->channels[0];
// get polar target matrix in world space
- BKE_constraint_target_matrix_get(ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0);
+ BKE_constraint_target_matrix_get(ikscene->bldepsgraph, ikscene->blscene, ikscene->polarConstraint, 1, CONSTRAINT_OBTYPE_OBJECT, ikscene->blArmature, mat, 1.0);
// convert to armature space
mul_m4_m4m4(polemat, imat, mat);
// get the target in world space (was computed before as target object are defined before base object)
@@ -863,7 +867,7 @@ static bool joint_callback(const iTaSC::Timestamp& timestamp, iTaSC::ConstraintV
}
// build array of joint corresponding to IK chain
-static int convert_channels(IK_Scene *ikscene, PoseTree *tree, float ctime)
+static int convert_channels(struct Depsgraph *depsgraph, IK_Scene *ikscene, PoseTree *tree, float ctime)
{
IK_Channel *ikchan;
bPoseChannel *pchan;
@@ -880,7 +884,7 @@ static int convert_channels(IK_Scene *ikscene, PoseTree *tree, float ctime)
// this is because some of the pose data (e.g. pose head) don't have corresponding
// joint angles and can't be applied to the iTaSC armature dynamically
if (!(pchan->flag & POSE_DONE))
- BKE_pose_where_is_bone(ikscene->blscene, ikscene->blArmature, pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, ikscene->blscene, ikscene->blArmature, pchan, ctime, 1);
// tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is()
pchan->flag |= (POSE_DONE | POSE_CHAIN);
@@ -1056,7 +1060,7 @@ static void BKE_pose_rest(IK_Scene *ikscene)
}
}
-static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, float ctime)
+static IK_Scene *convert_tree(struct Depsgraph *depsgraph, Scene *blscene, Object *ob, bPoseChannel *pchan, float ctime)
{
PoseTree *tree = (PoseTree *)pchan->iktree.first;
PoseTarget *target;
@@ -1068,12 +1072,11 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f
IK_Scene *ikscene;
IK_Channel *ikchan;
KDL::Frame initPose;
- KDL::Rotation boneRot;
Bone *bone;
int a, numtarget;
unsigned int t;
float length;
- bool ret = true, ingame;
+ bool ret = true;
double *rot;
float start[3];
@@ -1082,6 +1085,7 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f
ikscene = new IK_Scene;
ikscene->blscene = blscene;
+ ikscene->bldepsgraph = depsgraph;
arm = new iTaSC::Armature();
scene = new iTaSC::Scene();
ikscene->channels = new IK_Channel[tree->totchannel];
@@ -1089,26 +1093,13 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f
ikscene->armature = arm;
ikscene->scene = scene;
ikparam = (bItasc *)ob->pose->ikparam;
- ingame = (ob->pose->flag & POSE_GAME_ENGINE);
+
if (!ikparam) {
// you must have our own copy
ikparam = &DefIKParam;
}
- else if (ingame) {
- // tweak the param when in game to have efficient stepping
- // using fixed substep is not effecient since frames in the GE are often
- // shorter than in animation => move to auto step automatically and set
- // the target substep duration via min/max
- if (!(ikparam->flag & ITASC_AUTO_STEP)) {
- float timestep = blscene->r.frs_sec_base / blscene->r.frs_sec;
- if (ikparam->numstep > 0)
- timestep /= ikparam->numstep;
- // with equal min and max, the algorythm will take this step and the indicative substep most of the time
- ikparam->minstep = ikparam->maxstep = timestep;
- ikparam->flag |= ITASC_AUTO_STEP;
- }
- }
- if ((ikparam->flag & ITASC_SIMULATION) && !ingame)
+
+ if (ikparam->flag & ITASC_SIMULATION)
// no cache in animation mode
ikscene->cache = new iTaSC::Cache();
@@ -1134,16 +1125,9 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f
std::vector<double> weights;
double weight[3];
// build the array of joints corresponding to the IK chain
- convert_channels(ikscene, tree, ctime);
- if (ingame) {
- // in the GE, set the initial joint angle to match the current pose
- // this will update the jointArray in ikscene
- convert_pose(ikscene);
- }
- else {
- // in Blender, the rest pose is always 0 for joints
- BKE_pose_rest(ikscene);
- }
+ convert_channels(depsgraph, ikscene, tree, ctime);
+ // in Blender, the rest pose is always 0 for joints
+ BKE_pose_rest(ikscene);
rot = ikscene->jointArray(0);
for (a = 0, ikchan = ikscene->channels; a < tree->totchannel; ++a, ++ikchan) {
@@ -1439,6 +1423,7 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f
for (t = 0; t < ikscene->targets.size(); t++) {
IK_Target *iktarget = ikscene->targets[t];
iktarget->blscene = blscene;
+ iktarget->bldepsgraph = depsgraph;
condata = (bKinematicConstraint *)iktarget->blenderConstraint->data;
pchan = tree->pchan[iktarget->channel];
unsigned int controltype, bonecnt;
@@ -1526,7 +1511,7 @@ static IK_Scene *convert_tree(Scene *blscene, Object *ob, bPoseChannel *pchan, f
return ikscene;
}
-static void create_scene(Scene *scene, Object *ob, float ctime)
+static void create_scene(struct Depsgraph *depsgraph, Scene *scene, Object *ob, float ctime)
{
bPoseChannel *pchan;
@@ -1537,7 +1522,7 @@ static void create_scene(Scene *scene, Object *ob, float ctime)
if (tree) {
IK_Data *ikdata = get_ikdata(ob->pose);
// convert tree in iTaSC::Scene
- IK_Scene *ikscene = convert_tree(scene, ob, pchan, ctime);
+ IK_Scene *ikscene = convert_tree(depsgraph, scene, ob, pchan, ctime);
if (ikscene) {
ikscene->next = ikdata->first;
ikdata->first = ikscene;
@@ -1576,7 +1561,7 @@ static int init_scene(Object *ob)
return 0;
}
-static void execute_scene(Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, float ctime, float frtime)
+static void execute_scene(struct Depsgraph *depsgraph, Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, float ctime, float frtime)
{
int i;
IK_Channel *ikchan;
@@ -1592,7 +1577,7 @@ static void execute_scene(Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, fl
// in animation mode, we must get the bone position from action and constraints
for (i = 0, ikchan = ikscene->channels; i < ikscene->numchan; i++, ++ikchan) {
if (!(ikchan->pchan->flag & POSE_DONE))
- BKE_pose_where_is_bone(blscene, ikscene->blArmature, ikchan->pchan, ctime, 1);
+ BKE_pose_where_is_bone(depsgraph, blscene, ikscene->blArmature, ikchan->pchan, ctime, 1);
// tell blender that this channel was controlled by IK, it's cleared on each BKE_pose_where_is()
ikchan->pchan->flag |= (POSE_DONE | POSE_CHAIN);
ikchan->jointValid = 0;
@@ -1744,7 +1729,7 @@ static void execute_scene(Scene *blscene, IK_Scene *ikscene, bItasc *ikparam, fl
//---------------------------------------------------
// plugin interface
//
-void itasc_initialize_tree(struct Scene *scene, Object *ob, float ctime)
+void itasc_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, float ctime)
{
bPoseChannel *pchan;
int count = 0;
@@ -1764,13 +1749,13 @@ void itasc_initialize_tree(struct Scene *scene, Object *ob, float ctime)
// if at least one tree, create the scenes from the PoseTree stored in the channels
// postpone until execute_tree: this way the pose constraint are included
if (count)
- create_scene(scene, ob, ctime);
+ create_scene(depsgraph, scene, ob, ctime);
itasc_update_param(ob->pose);
// make sure we don't rebuilt until the user changes something important
ob->pose->flag &= ~POSE_WAS_REBUILT;
}
-void itasc_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
+void itasc_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, Object *ob, bPoseChannel *pchan_root, float ctime)
{
if (ob->pose->ikdata) {
IK_Data *ikdata = (IK_Data *)ob->pose->ikdata;
@@ -1781,13 +1766,7 @@ void itasc_execute_tree(struct Scene *scene, Object *ob, bPoseChannel *pchan_ro
for (IK_Scene *ikscene = ikdata->first; ikscene; ikscene = ikscene->next) {
if (ikscene->channels[0].pchan == pchan_root) {
float timestep = scene->r.frs_sec_base / scene->r.frs_sec;
- if (ob->pose->flag & POSE_GAME_ENGINE) {
- timestep = ob->pose->ctime;
- // limit the timestep to avoid excessive number of iteration
- if (timestep > 0.2f)
- timestep = 0.2f;
- }
- execute_scene(scene, ikscene, ikparam, ctime, timestep);
+ execute_scene(depsgraph, scene, ikscene, ikparam, ctime, timestep);
break;
}
}
diff --git a/source/blender/ikplugin/intern/itasc_plugin.h b/source/blender/ikplugin/intern/itasc_plugin.h
index bcd95bc31ca..0ab9a67dce4 100644
--- a/source/blender/ikplugin/intern/itasc_plugin.h
+++ b/source/blender/ikplugin/intern/itasc_plugin.h
@@ -40,8 +40,8 @@
extern "C" {
#endif
-void itasc_initialize_tree(struct Scene *scene, struct Object *ob, float ctime);
-void itasc_execute_tree(struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime);
+void itasc_initialize_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, float ctime);
+void itasc_execute_tree(struct Depsgraph *depsgraph, struct Scene *scene, struct Object *ob, struct bPoseChannel *pchan_root, float ctime);
void itasc_release_tree(struct Scene *scene, struct Object *ob, float ctime);
void itasc_clear_data(struct bPose *pose);
void itasc_clear_cache(struct bPose *pose);
diff --git a/source/blender/imbuf/intern/indexer.c b/source/blender/imbuf/intern/indexer.c
index eaf4dfd84b4..2bda07bdbbe 100644
--- a/source/blender/imbuf/intern/indexer.c
+++ b/source/blender/imbuf/intern/indexer.c
@@ -1041,7 +1041,7 @@ static IndexBuildContext *index_fallback_create_context(struct anim *anim, IMB_T
/* since timecode indices only work with ffmpeg right now,
* don't know a sensible fallback here...
*
- * so no proxies, no game to play...
+ * so no proxies...
*/
if (proxy_sizes_in_use == IMB_PROXY_NONE) {
return NULL;
diff --git a/source/blender/imbuf/intern/thumbs.c b/source/blender/imbuf/intern/thumbs.c
index 2fa5b5a0170..86e1fba9af7 100644
--- a/source/blender/imbuf/intern/thumbs.c
+++ b/source/blender/imbuf/intern/thumbs.c
@@ -44,10 +44,10 @@
#include "BLI_threads.h"
#include BLI_SYSTEM_PID_H
-#include "BLO_readfile.h"
-
#include "DNA_space_types.h" /* For FILE_MAX_LIBEXTRA */
+#include "BLO_readfile.h"
+
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
#include "IMB_thumbs.h"
diff --git a/source/blender/imbuf/intern/thumbs_blend.c b/source/blender/imbuf/intern/thumbs_blend.c
index d04f5fc87e6..efcd7d1f35f 100644
--- a/source/blender/imbuf/intern/thumbs_blend.c
+++ b/source/blender/imbuf/intern/thumbs_blend.c
@@ -32,6 +32,7 @@
#include "BLI_endian_switch.h"
#include "BLI_fileops.h"
#include "BLI_linklist.h"
+#include "BLI_listbase.h" /* Needed due to import of BLO_readfile.h */
#include "BLO_blend_defs.h"
#include "BLO_readfile.h"
diff --git a/source/blender/makesdna/DNA_ID.h b/source/blender/makesdna/DNA_ID.h
index 80640d8dffe..acf054a94d5 100644
--- a/source/blender/makesdna/DNA_ID.h
+++ b/source/blender/makesdna/DNA_ID.h
@@ -96,14 +96,104 @@ enum {
IDP_STRING_SUB_BYTE = 1, /* arbitrary byte array, _not_ null terminated */
};
+/* IDP_GROUP */
+enum {
+ IDP_GROUP_SUB_NONE = 0, /* default */
+ IDP_GROUP_SUB_MODE_OBJECT = 1, /* object mode settings */
+ IDP_GROUP_SUB_MODE_EDIT = 2, /* mesh edit mode settings */
+ IDP_GROUP_SUB_ENGINE_RENDER = 3, /* render engine settings */
+ IDP_GROUP_SUB_OVERRIDE = 4, /* data override */
+ IDP_GROUP_SUB_MODE_PAINT_WEIGHT = 5, /* weight paint mode settings */
+ IDP_GROUP_SUB_MODE_PAINT_VERTEX = 6, /* vertex paint mode settings */
+};
+
/*->flag*/
enum {
+ /* This IDProp may be statically overridden. Should only be used/be relevant for custom properties. */
+ IDP_FLAG_OVERRIDABLE_STATIC = 1 << 0,
+
IDP_FLAG_GHOST = 1 << 7, /* this means the property is set but RNA will return false when checking
* 'RNA_property_is_set', currently this is a runtime flag */
};
/* add any future new id property types here.*/
+
+/* Static ID override structs. */
+
+typedef struct IDOverrideStaticPropertyOperation {
+ struct IDOverrideStaticPropertyOperation *next, *prev;
+
+ /* Type of override. */
+ short operation;
+ short flag;
+ short pad_s1[2];
+
+ /* Sub-item references, if needed (for arrays or collections only).
+ * We need both reference and local values to allow e.g. insertion into collections (constraints, modifiers...).
+ * In collection case, if names are defined, they are used in priority.
+ * Names are pointers (instead of char[64]) to save some space, NULL when unset.
+ * Indices are -1 when unset. */
+ char *subitem_reference_name;
+ char *subitem_local_name;
+ int subitem_reference_index;
+ int subitem_local_index;
+} IDOverrideStaticPropertyOperation;
+
+/* IDOverridePropertyOperation->operation. */
+enum {
+ /* Basic operations. */
+ IDOVERRIDESTATIC_OP_NOOP = 0, /* Special value, forbids any overriding. */
+
+ IDOVERRIDESTATIC_OP_REPLACE = 1, /* Fully replace local value by reference one. */
+
+ /* Numeric-only operations. */
+ IDOVERRIDESTATIC_OP_ADD = 101, /* Add local value to reference one. */
+ /* Subtract local value from reference one (needed due to unsigned values etc.). */
+ IDOVERRIDESTATIC_OP_SUBTRACT = 102,
+ /* Multiply reference value by local one (more useful than diff for scales and the like). */
+ IDOVERRIDESTATIC_OP_MULTIPLY = 103,
+
+ /* Collection-only operations. */
+ IDOVERRIDESTATIC_OP_INSERT_AFTER = 201, /* Insert after given reference's subitem. */
+ IDOVERRIDESTATIC_OP_INSERT_BEFORE = 202, /* Insert before given reference's subitem. */
+ /* We can add more if needed (move, delete, ...). */
+};
+
+/* IDOverridePropertyOperation->flag. */
+enum {
+ IDOVERRIDESTATIC_FLAG_MANDATORY = 1 << 0, /* User cannot remove that override operation. */
+ IDOVERRIDESTATIC_FLAG_LOCKED = 1 << 1, /* User cannot change that override operation. */
+};
+
+/* A single overriden property, contain all operations on this one. */
+typedef struct IDOverrideStaticProperty {
+ struct IDOverrideStaticProperty *next, *prev;
+
+ /* Path from ID to overridden property. *Does not* include indices/names for final arrays/collections items. */
+ char *rna_path;
+
+ ListBase operations; /* List of overriding operations (IDOverridePropertyOperation) applied to this property. */
+} IDOverrideStaticProperty;
+
+/* Main container for all overriding data info of a data-block. */
+typedef struct IDOverrideStatic {
+ struct ID *reference; /* Reference linked ID which this one overrides. */
+ ListBase properties; /* List of IDOverrideProperty structs. */
+
+ short flag;
+ short pad[3];
+
+ /* Read/write data. */
+ /* Temp ID storing extra override data (used for differential operations only currently).
+ * Always NULL outside of read/write context. */
+ struct ID *storage;
+} IDOverrideStatic;
+
+enum eStaticOverride_Flag {
+ STATICOVERRIDE_AUTO = 1 << 0, /* Allow automatic generation of overriding rules. */
+};
+
/* watch it: Sequence has identical beginning. */
/**
* ID is the first thing included in all serializable types. It
@@ -134,6 +224,13 @@ typedef struct ID {
int pad;
IDProperty *properties;
+ IDOverrideStatic *override_static; /* Reference linked ID which this one overrides. */
+
+ /* Only set for datablocks which are coming from copy-on-write, points to
+ * the original version of it.
+ */
+ void *orig_id;
+
void *py_instance;
} ID;
@@ -257,6 +354,8 @@ typedef enum ID_Type {
ID_PAL = MAKE_ID2('P', 'L'), /* Palette */
ID_PC = MAKE_ID2('P', 'C'), /* PaintCurve */
ID_CF = MAKE_ID2('C', 'F'), /* CacheFile */
+ ID_WS = MAKE_ID2('W', 'S'), /* WorkSpace */
+ ID_LP = MAKE_ID2('L', 'P'), /* LightProbe */
} ID_Type;
/* Only used as 'placeholder' in .blend files for directly linked datablocks. */
@@ -280,7 +379,7 @@ typedef enum ID_Type {
#define ID_REAL_USERS(id) (((ID *)id)->us - ID_FAKE_USERS(id))
#define ID_EXTRA_USERS(id) (((ID *)id)->tag & LIB_TAG_EXTRAUSER ? 1 : 0)
-#define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM))
+#define ID_CHECK_UNDO(id) ((GS((id)->name) != ID_SCR) && (GS((id)->name) != ID_WM) && (GS((id)->name) != ID_WS))
#define ID_BLEND_PATH(_bmain, _id) ((_id)->lib ? (_id)->lib->filepath : (_bmain)->name)
@@ -288,6 +387,16 @@ typedef enum ID_Type {
#define ID_IS_LINKED(_id) (((ID *)(_id))->lib != NULL)
+#define ID_IS_STATIC_OVERRIDE(_id) (((ID *)(_id))->override_static != NULL && \
+ ((ID *)(_id))->override_static->reference != NULL)
+
+#define ID_IS_STATIC_OVERRIDE_TEMPLATE(_id) (((ID *)(_id))->override_static != NULL && \
+ ((ID *)(_id))->override_static->reference == NULL)
+
+#define ID_IS_STATIC_OVERRIDE_AUTO(_id) (!ID_IS_LINKED((_id)) && \
+ ID_IS_STATIC_OVERRIDE((_id)) && \
+ (((ID *)(_id))->override_static->flag & STATICOVERRIDE_AUTO))
+
#ifdef GS
# undef GS
#endif
@@ -299,7 +408,7 @@ typedef enum ID_Type {
/* id->flag (persitent). */
enum {
- LIB_FAKEUSER = 1 << 9,
+ LIB_FAKEUSER = 1 << 9,
};
/**
@@ -334,6 +443,11 @@ enum {
/* RESET_NEVER tag datablock as a place-holder (because the real one could not be linked from its library e.g.). */
LIB_TAG_MISSING = 1 << 6,
+ /* RESET_NEVER tag datablock as being up-to-date regarding its reference. */
+ LIB_TAG_OVERRIDESTATIC_REFOK = 1 << 9,
+ /* RESET_NEVER tag datablock as needing an auto-override execution, if enabled. */
+ LIB_TAG_OVERRIDESTATIC_AUTOREFRESH = 1 << 17,
+
/* tag datablock has having an extra user. */
LIB_TAG_EXTRAUSER = 1 << 2,
/* tag datablock has having actually increased usercount for the extra virtual user. */
@@ -348,21 +462,36 @@ enum {
/* RESET_AFTER_USE tag existing data before linking so we know what is new. */
LIB_TAG_PRE_EXISTING = 1 << 11,
+ /* The datablock is a copy-on-write/localized version. */
+ LIB_TAG_COPY_ON_WRITE = 1 << 12,
+ LIB_TAG_COPY_ON_WRITE_EVAL = 1 << 13,
+ LIB_TAG_LOCALIZED = 1 << 14,
+
/* RESET_NEVER tag datablock for freeing etc. behavior (usually set when copying real one into temp/runtime one). */
- LIB_TAG_NO_MAIN = 1 << 12, /* Datablock is not listed in Main database. */
- LIB_TAG_NO_USER_REFCOUNT = 1 << 13, /* Datablock does not refcount usages of other IDs. */
+ LIB_TAG_NO_MAIN = 1 << 15, /* Datablock is not listed in Main database. */
+ LIB_TAG_NO_USER_REFCOUNT = 1 << 16, /* Datablock does not refcount usages of other IDs. */
/* Datablock was not allocated by standard system (BKE_libblock_alloc), do not free its memory
* (usual type-specific freeing is called though). */
- LIB_TAG_NOT_ALLOCATED = 1 << 14,
+ LIB_TAG_NOT_ALLOCATED = 1 << 17,
};
+/* WARNING - when adding flags check on PSYS_RECALC */
enum {
/* RESET_AFTER_USE, used by update code (depsgraph). */
ID_RECALC_NONE = 0,
+ /* Generic recalc flag, when nothing else matches. */
ID_RECALC = 1 << 0,
- ID_RECALC_DATA = 1 << 1,
- ID_RECALC_SKIP_ANIM_TAG = 1 << 2,
- ID_RECALC_ALL = (ID_RECALC | ID_RECALC_DATA),
+ /* Per-component update flags. */
+ ID_RECALC_ANIMATION = 1 << 1,
+ ID_RECALC_DRAW = 1 << 2,
+ ID_RECALC_DRAW_CACHE = 1 << 3,
+ ID_RECALC_GEOMETRY = 1 << 4,
+ ID_RECALC_TRANSFORM = 1 << 5,
+ ID_RECALC_COLLECTIONS = 1 << 6,
+ ID_RECALC_COPY_ON_WRITE = 1 << 7,
+ ID_RECALC_TIME = 1 << 8,
+ /* Special flag to check if SOMETHING was changed. */
+ ID_RECALC_ALL = (~(int)0),
};
/* To filter ID types (filter_id) */
@@ -400,9 +529,11 @@ enum {
FILTER_ID_WO = (1 << 26),
FILTER_ID_PA = (1 << 27),
FILTER_ID_CF = (1 << 28),
+ FILTER_ID_WS = (1 << 29),
+ FILTER_ID_LP = (1u << 31),
};
-/* IMPORTANT: this enum matches the order currently use in set_lisbasepointers,
+/* IMPORTANT: this enum matches the order currently use in set_listbasepointers,
* keep them in sync! */
enum {
INDEX_ID_LI = 0,
@@ -431,12 +562,14 @@ enum {
INDEX_ID_BR,
INDEX_ID_PA,
INDEX_ID_SPK,
+ INDEX_ID_LP,
INDEX_ID_WO,
INDEX_ID_MC,
INDEX_ID_SCR,
INDEX_ID_OB,
INDEX_ID_LS,
INDEX_ID_SCE,
+ INDEX_ID_WS,
INDEX_ID_WM,
INDEX_ID_MSK,
INDEX_ID_NULL,
diff --git a/source/blender/makesdna/DNA_action_types.h b/source/blender/makesdna/DNA_action_types.h
index 1691038e13c..3c035ae0bc8 100644
--- a/source/blender/makesdna/DNA_action_types.h
+++ b/source/blender/makesdna/DNA_action_types.h
@@ -180,6 +180,18 @@ typedef enum eMotionPaths_BakeFlag {
MOTIONPATH_BAKE_HAS_PATHS = (1 << 2)
} eMotionPath_BakeFlag;
+/* runtime */
+#
+#
+typedef struct bPoseChannelDrawData {
+ float solid_color[4];
+ float wire_color[4];
+
+ int bbone_matrix_len;
+ /* keep last */
+ float bbone_matrix[0][4][4];
+} bPoseChannelDrawData;
+
/* ************************************************ */
/* Poses */
@@ -238,6 +250,8 @@ typedef struct bPoseChannel {
float chan_mat[4][4]; /* matrix result of loc/quat/size, and where we put deform in, see next line */
float pose_mat[4][4]; /* constraints accumulate here. in the end, pose_mat = bone->arm_mat * chan_mat
* this matrix is object space */
+ float disp_mat[4][4]; /* for display, pose_mat with bone length applied */
+ float disp_tail_mat[4][4]; /* for display, pose_mat with bone length applied and translated to tail*/
float constinv[4][4]; /* inverse result of constraints.
* doesn't include effect of restposition, parent, and local transform*/
@@ -259,8 +273,10 @@ typedef struct bPoseChannel {
struct bPoseChannel *bbone_prev; /* next/prev bones to use as handle references when calculating bbones (optional) */
struct bPoseChannel *bbone_next;
-
+
void *temp; /* use for outliner */
+ /* Runtime data for color and bbone segment matrix. */
+ bPoseChannelDrawData *draw_data;
} bPoseChannel;
@@ -418,8 +434,7 @@ typedef enum ePose_Flags {
POSE_RECALCPATHS = (1 << 4),
/* set by BKE_pose_rebuild to give a chance to the IK solver to rebuild IK tree */
POSE_WAS_REBUILT = (1 << 5),
- /* set by game_copy_pose to indicate that this pose is used in the game engine */
- POSE_GAME_ENGINE = (1 << 6),
+ POSE_FLAG_DEPRECATED = (1 << 6), /* deprecated. */
/* pose constraint flags needs to be updated */
POSE_CONSTRAINTS_NEED_UPDATE_FLAGS = (1 << 7),
} ePose_Flags;
@@ -665,6 +680,9 @@ typedef struct SpaceAction {
char mode, autosnap; /* mode: editing context; autosnap: automatic keyframe snapping mode */
short flag; /* flag: bitmapped settings; */
float timeslide; /* for Time-Slide transform mode drawing - current frame? */
+
+ int cache_display; /* (eTimeline_Cache_Flag) */
+ int pad;
} SpaceAction;
/* SpaceAction flag */
@@ -709,6 +727,8 @@ typedef enum eAnimEdit_Context {
SACTCONT_MASK = 4,
/* cache file */
SACTCONT_CACHEFILE = 5,
+ /* timeline - replacement for the standalone "timeline editor" */
+ SACTCONT_TIMELINE = 6,
} eAnimEdit_Context;
/* SpaceAction AutoSnap Settings (also used by other Animation Editors) */
@@ -727,6 +747,17 @@ typedef enum eAnimEdit_AutoSnap {
SACTSNAP_TSTEP = 5
} eAnimEdit_AutoSnap;
+/* SAction->cache_display */
+typedef enum eTimeline_Cache_Flag {
+ TIME_CACHE_DISPLAY = (1 << 0),
+ TIME_CACHE_SOFTBODY = (1 << 1),
+ TIME_CACHE_PARTICLES = (1 << 2),
+ TIME_CACHE_CLOTH = (1 << 3),
+ TIME_CACHE_SMOKE = (1 << 4),
+ TIME_CACHE_DYNAMICPAINT = (1 << 5),
+ TIME_CACHE_RIGIDBODY = (1 << 6),
+} eTimeline_Cache_Flag;
+
/* ************************************************ */
/* Legacy Data */
diff --git a/source/blender/makesdna/DNA_actuator_types.h b/source/blender/makesdna/DNA_actuator_types.h
deleted file mode 100644
index 6bdea21da1e..00000000000
--- a/source/blender/makesdna/DNA_actuator_types.h
+++ /dev/null
@@ -1,583 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file DNA_actuator_types.h
- * \ingroup DNA
- *
- * #bActuator type is specifically for use by Object logic-bricks in the game-engine.
- */
-
-#ifndef __DNA_ACTUATOR_TYPES_H__
-#define __DNA_ACTUATOR_TYPES_H__
-
-struct Object;
-struct Mesh;
-struct Scene;
-struct Group;
-struct Text;
-
-/* ****************** ACTUATORS ********************* */
-
-/* unused now, moved to editobjectactuator in 2.02. Still needed for dna */
-typedef struct bAddObjectActuator {
- int time, pad;
- struct Object *ob;
-} bAddObjectActuator;
-
-typedef struct bActionActuator {
- struct bAction *act; /* Pointer to action */
- short type, flag; /* Playback type */ // not in use
- float sta, end; /* Start & End frames */
- char name[64]; /* For property-driven playback, MAX_NAME */
- char frameProp[64]; /* Set this property to the actions current frame, MAX_NAME */
- short blendin; /* Number of frames of blending */
- short priority; /* Execution priority */
- short layer; /* Animation layer */
- short end_reset; /* Ending the actuator (negative pulse) wont reset the action to its starting frame */
- short strideaxis; /* Displacement axis */
- short blend_mode; /* Layer blending mode */
- float stridelength; /* Displacement incurred by cycle */ // not in use
- float layer_weight; /* How much of the previous layer to use for blending. (<0 = disable, 0 = add mode) */
-} bActionActuator;
-
-typedef struct Sound3D {
- float min_gain;
- float max_gain;
- float reference_distance;
- float max_distance;
- float rolloff_factor;
- float cone_inner_angle;
- float cone_outer_angle;
- float cone_outer_gain;
-} Sound3D;
-
-typedef struct bSoundActuator {
- short flag, sndnr;
- int pad1, pad2;
- short pad3[2];
- float volume, pitch;
- struct bSound *sound;
- struct Sound3D sound3D;
- short type, pad4;
- short pad5, pad6[1];
-} bSoundActuator;
-
-typedef struct bEditObjectActuator {
- int time;
- short type, flag;
- struct Object *ob;
- struct Mesh *me;
- char name[64]; /* MAX_NAME */
- float linVelocity[3]; /* initial lin. velocity on creation */
- float angVelocity[3]; /* initial ang. velocity on creation */
- float mass;
- short localflag; /* flag for the lin & ang. vel: apply locally */
- short dyn_operation;
- short upflag, trackflag; /* flag for up axis and track axis */
- int pad;
-} bEditObjectActuator;
-
-typedef struct bSceneActuator {
- short type, pad1;
- int pad;
- struct Scene *scene;
- struct Object *camera;
-} bSceneActuator;
-
-typedef struct bPropertyActuator {
- int pad, type;
- char name[64], value[64]; /* MAX_NAME */
- struct Object *ob;
-} bPropertyActuator;
-
-typedef struct bObjectActuator {
- short flag, type, otype;
- short damping;
- float forceloc[3], forcerot[3];
- float pad[3], pad1[3];
- float dloc[3], drot[3]; /* angle in radians */
- float linearvelocity[3], angularvelocity[3];
- struct Object *reference;
-} bObjectActuator;
-
-/* deprecated, handled by bActionActuator now */
-typedef struct bIpoActuator {
- short flag, type;
- float sta, end;
- char name[64]; /* MAX_NAME */
- char frameProp[64]; /* Set this property to the actions current frame, MAX_NAME */
-
- short pad1, pad2, pad3, pad4;
-
-} bIpoActuator;
-
-typedef struct bCameraActuator {
- struct Object *ob;
- float height, min, max;
- float damping;
- short pad1, axis;
- float pad2;
-} bCameraActuator;
-
-typedef struct bConstraintActuator {
- short type, mode;
- short flag, damp;
- short time, rotdamp;
- int pad;
- float minloc[3], maxloc[3];
- float minrot[3], maxrot[3];
- char matprop[64]; /* MAX_NAME */
-} bConstraintActuator;
-
-typedef struct bGroupActuator {
- short flag, type;
- int sta, end;
- char name[64]; /* property or groupkey, MAX_NAME */
-
- short pad[3], cur, butsta, butend;/* not referenced, can remove? */
- /* struct Group *group; not used, remove */
-
-} bGroupActuator;
-
-/* I added a few extra fields here, to facilitate conversions */
-typedef struct bRandomActuator {
- int seed;
- int distribution;
- int int_arg_1;
- int int_arg_2;
- float float_arg_1;
- float float_arg_2;
- char propname[64]; /* MAX_NAME */
-} bRandomActuator;
-
-typedef struct bMessageActuator {
- char toPropName[64]; /* Send to all objects with this propertyname. Empty to broadcast. MAX_NAME. */
- struct Object *toObject;/* (Possible future use) pointer to a single destination object. */
- char subject[64]; /* Message Subject to send. MAX_NAME. */
- short bodyType, pad1; /* bodyType is either 'User defined text' or PropName */
- int pad2;
- char body[64]; /* Either User Defined Text or our PropName to send value of, MAX_NAME */
-} bMessageActuator;
-
-typedef struct bGameActuator {
- short flag, type;
- int sta, end;
- char filename[64];
- char loadaniname[64];
-} bGameActuator;
-
-typedef struct bVisibilityActuator {
- /** bit 0: Is this object visible?
- ** bit 1: Apply recursively
- ** bit 2: Is this object an occluder? */
- int flag;
-} bVisibilityActuator;
-
-typedef struct bTwoDFilterActuator {
- char pad[4];
- /* Tells what type of 2D Filter */
- short type;
- /* (flag == 0) means 2D filter is activate and
- * (flag != 0) means 2D filter is inactive */
- short flag;
- int int_arg;
- /* a float argument */
- float float_arg;
- struct Text *text;
-} bTwoDFilterActuator;
-
-typedef struct bParentActuator {
- char pad[2];
- short flag;
- int type;
- struct Object *ob;
-} bParentActuator;
-
-typedef struct bStateActuator {
- int type; /* 0=Set, 1=Add, 2=Rem, 3=Chg */
- unsigned int mask; /* the bits to change */
-} bStateActuator;
-
-typedef struct bArmatureActuator {
- char posechannel[64]; /* MAX_NAME */
- char constraint[64]; /* MAX_NAME */
- int type; /* 0=run, 1=enable, 2=disable, 3=set target, 4=set weight */
- float weight;
- float influence;
- float pad;
- struct Object *target;
- struct Object *subtarget;
-} bArmatureActuator;
-
-typedef struct bSteeringActuator {
- char pad[5];
- char flag;
- short facingaxis;
- int type; /* 0=seek, 1=flee, 2=path following */
- float dist;
- float velocity;
- float acceleration;
- float turnspeed;
- int updateTime;
- struct Object *target;
- struct Object *navmesh;
-} bSteeringActuator;
-
-typedef struct bMouseActuator {
- short type; /* 0=Visibility, 1=Look */
- short flag;
-
- int object_axis[2];
- float threshold[2];
- float sensitivity[2];
- float limit_x[2];
- float limit_y[2];
-} bMouseActuator;
-
-
-typedef struct bActuator {
- struct bActuator *next, *prev, *mynew;
- short type;
- /**
- * Tells what type of actuator data \ref data holds.
- */
- short flag;
- short otype, go;
- char name[64]; /* MAX_NAME */
-
- /**
- * data must point to an object actuator type struct.
- */
- void *data;
-
- /**
- * For ipo's and props: to find out which object the actuator
- * belongs to */
- struct Object *ob;
-
-} bActuator;
-
-/* objectactuator->flag */
-#define ACT_FORCE_LOCAL 1
-#define ACT_TORQUE_LOCAL 2
-#define ACT_SERVO_LIMIT_X 2
-#define ACT_DLOC_LOCAL 4
-#define ACT_SERVO_LIMIT_Y 4
-#define ACT_DROT_LOCAL 8
-#define ACT_SERVO_LIMIT_Z 8
-#define ACT_LIN_VEL_LOCAL 16
-#define ACT_ANG_VEL_LOCAL 32
-//#define ACT_ADD_LIN_VEL_LOCAL 64
-#define ACT_ADD_LIN_VEL 64
-#define ACT_ADD_CHAR_LOC 128
-#define ACT_CHAR_JUMP 256
-
-/* objectactuator->type */
-#define ACT_OBJECT_NORMAL 0
-#define ACT_OBJECT_SERVO 1
-#define ACT_OBJECT_CHARACTER 2
-
-/* actuator->type */
-#define ACT_OBJECT 0
-#define ACT_IPO 1
-#define ACT_LAMP 2
-#define ACT_CAMERA 3
-#define ACT_MATERIAL 4
-#define ACT_SOUND 5
-#define ACT_PROPERTY 6
- /* these two obsolete since 2.02 */
-#define ACT_ADD_OBJECT 7
-#define ACT_END_OBJECT 8
-
-#define ACT_CONSTRAINT 9
-#define ACT_EDIT_OBJECT 10
-#define ACT_SCENE 11
-#define ACT_GROUP 12
-#define ACT_RANDOM 13
-#define ACT_MESSAGE 14
-#define ACT_ACTION 15 /* __ NLA */
-#define ACT_GAME 17
-#define ACT_VISIBILITY 18
-#define ACT_2DFILTER 19
-#define ACT_PARENT 20
-#define ACT_SHAPEACTION 21
-#define ACT_STATE 22
-#define ACT_ARMATURE 23
-#define ACT_STEERING 24
-#define ACT_MOUSE 25
-
-/* actuator flag */
-#define ACT_SHOW 1
-#define ACT_DEL 2
-#define ACT_NEW 4
-#define ACT_LINKED 8
-#define ACT_VISIBLE 16
-#define ACT_PIN 32
-#define ACT_DEACTIVATE 64
-
-/* link codes */
-#define LINK_SENSOR 0
-#define LINK_CONTROLLER 1
-#define LINK_ACTUATOR 2
-
-/* keyboardsensor->type */
-#define SENS_ALL_KEYS 1
-
-/* actionactuator->type */
-#define ACT_ACTION_PLAY 0
-#define ACT_ACTION_PINGPONG 1
-#define ACT_ACTION_FLIPPER 2
-#define ACT_ACTION_LOOP_STOP 3
-#define ACT_ACTION_LOOP_END 4
-#define ACT_ACTION_KEY2KEY 5
-#define ACT_ACTION_FROM_PROP 6
-#define ACT_ACTION_MOTION 7
-
-/* actionactuator->blend_mode */
-#define ACT_ACTION_BLEND 0
-#define ACT_ACTION_ADD 1
-
-/* ipoactuator->type */
-/* used for conversion from 2.01 */
-#define ACT_IPO_FROM_PROP 6
-
-/* groupactuator->type */
-#define ACT_GROUP_PLAY 0
-#define ACT_GROUP_PINGPONG 1
-#define ACT_GROUP_FLIPPER 2
-#define ACT_GROUP_LOOP_STOP 3
-#define ACT_GROUP_LOOP_END 4
-#define ACT_GROUP_FROM_PROP 5
-#define ACT_GROUP_SET 6
-
-/* ipoactuator->flag */
-#define ACT_IPOFORCE (1 << 0)
-#define ACT_IPOEND (1 << 1)
-#define ACT_IPOLOCAL (1 << 2)
-#define ACT_IPOCHILD (1 << 4)
-#define ACT_IPOADD (1 << 5)
-
-/* property actuator->type */
-#define ACT_PROP_ASSIGN 0
-#define ACT_PROP_ADD 1
-#define ACT_PROP_COPY 2
-#define ACT_PROP_TOGGLE 3
-#define ACT_PROP_LEVEL 4
-
-/* constraint flag */
-#define ACT_CONST_NONE 0
-#define ACT_CONST_LOCX 1
-#define ACT_CONST_LOCY 2
-#define ACT_CONST_LOCZ 4
-#define ACT_CONST_ROTX 8
-#define ACT_CONST_ROTY 16
-#define ACT_CONST_ROTZ 32
-#define ACT_CONST_NORMAL 64
-#define ACT_CONST_MATERIAL 128
-#define ACT_CONST_PERMANENT 256
-#define ACT_CONST_DISTANCE 512
-#define ACT_CONST_LOCAL 1024
-#define ACT_CONST_DOROTFH 2048
-
-/* constraint mode */
-#define ACT_CONST_DIRPX 1
-#define ACT_CONST_DIRPY 2
-#define ACT_CONST_DIRPZ 4
-#define ACT_CONST_DIRNX 8
-#define ACT_CONST_DIRNY 16
-#define ACT_CONST_DIRNZ 32
-
-/* constraint type */
-#define ACT_CONST_TYPE_LOC 0
-#define ACT_CONST_TYPE_DIST 1
-#define ACT_CONST_TYPE_ORI 2
-#define ACT_CONST_TYPE_FH 3
-
-/* editObjectActuator->type */
-#define ACT_EDOB_ADD_OBJECT 0
-#define ACT_EDOB_END_OBJECT 1
-#define ACT_EDOB_REPLACE_MESH 2
-#define ACT_EDOB_TRACK_TO 3
-#define ACT_EDOB_DYNAMICS 4
-
-/* editObjectActuator->localflag */
-#define ACT_EDOB_LOCAL_LINV 2
-#define ACT_EDOB_LOCAL_ANGV 4
-
-/* editObjectActuator->flag */
-#define ACT_TRACK_3D 1
-
-/* editObjectActuator->upflag */
-#define ACT_TRACK_UP_X 0
-#define ACT_TRACK_UP_Y 1
-#define ACT_TRACK_UP_Z 2
-
-/* editObjectActuator->trackflag */
-#define ACT_TRACK_TRAXIS_X 0
-#define ACT_TRACK_TRAXIS_Y 1
-#define ACT_TRACK_TRAXIS_Z 2
-#define ACT_TRACK_TRAXIS_NEGX 3
-#define ACT_TRACK_TRAXIS_NEGY 4
-#define ACT_TRACK_TRAXIS_NEGZ 5
-
-/* editObjectActuator->flag for replace mesh actuator */
-#define ACT_EDOB_REPLACE_MESH_NOGFX 2 /* use for replace mesh actuator */
-#define ACT_EDOB_REPLACE_MESH_PHYS 4
-
-/* editObjectActuator->dyn_operation */
-#define ACT_EDOB_RESTORE_DYN 0
-#define ACT_EDOB_SUSPEND_DYN 1
-#define ACT_EDOB_ENABLE_RB 2
-#define ACT_EDOB_DISABLE_RB 3
-#define ACT_EDOB_SET_MASS 4
-
-
-/* SceneActuator->type */
-#define ACT_SCENE_RESTART 0
-#define ACT_SCENE_SET 1
-#define ACT_SCENE_CAMERA 2
-#define ACT_SCENE_ADD_FRONT 3
-#define ACT_SCENE_ADD_BACK 4
-#define ACT_SCENE_REMOVE 5
-#define ACT_SCENE_SUSPEND 6
-#define ACT_SCENE_RESUME 7
-
-
-/* randomAct->distribution */
-#define ACT_RANDOM_BOOL_CONST 0
-#define ACT_RANDOM_BOOL_UNIFORM 1
-#define ACT_RANDOM_BOOL_BERNOUILLI 2
-#define ACT_RANDOM_INT_CONST 3
-#define ACT_RANDOM_INT_UNIFORM 4
-#define ACT_RANDOM_INT_POISSON 5
-#define ACT_RANDOM_FLOAT_CONST 6
-#define ACT_RANDOM_FLOAT_UNIFORM 7
-#define ACT_RANDOM_FLOAT_NORMAL 8
-#define ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL 9
-
-/* SoundActuator->flag */
-#define ACT_SND_3D_SOUND 1
-
-/* SoundActuator->type */
-#define ACT_SND_PLAY_STOP_SOUND 0
-#define ACT_SND_PLAY_END_SOUND 1
-#define ACT_SND_LOOP_STOP_SOUND 2
-#define ACT_SND_LOOP_END_SOUND 3
-#define ACT_SND_LOOP_BIDIRECTIONAL_SOUND 4
-#define ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND 5
-
-/* messageactuator->type */
-#define ACT_MESG_MESG 0
-#define ACT_MESG_PROP 1
-
-/* gameactuator->type */
-#define ACT_GAME_LOAD 0
-#define ACT_GAME_START 1
-#define ACT_GAME_RESTART 2
-#define ACT_GAME_QUIT 3
-#define ACT_GAME_SAVECFG 4
-#define ACT_GAME_LOADCFG 5
-#define ACT_GAME_SCREENSHOT 6
-
-/* visibilityact->flag */
-/* Set means the object will become invisible */
-#define ACT_VISIBILITY_INVISIBLE (1 << 0)
-#define ACT_VISIBILITY_RECURSIVE (1 << 1)
-#define ACT_VISIBILITY_OCCLUSION (1 << 2)
-
-/* twodfilter->type */
-#define ACT_2DFILTER_ENABLED -2
-#define ACT_2DFILTER_DISABLED -1
-#define ACT_2DFILTER_NOFILTER 0
-#define ACT_2DFILTER_MOTIONBLUR 1
-#define ACT_2DFILTER_BLUR 2
-#define ACT_2DFILTER_SHARPEN 3
-#define ACT_2DFILTER_DILATION 4
-#define ACT_2DFILTER_EROSION 5
-#define ACT_2DFILTER_LAPLACIAN 6
-#define ACT_2DFILTER_SOBEL 7
-#define ACT_2DFILTER_PREWITT 8
-#define ACT_2DFILTER_GRAYSCALE 9
-#define ACT_2DFILTER_SEPIA 10
-#define ACT_2DFILTER_INVERT 11
-#define ACT_2DFILTER_CUSTOMFILTER 12
-#define ACT_2DFILTER_NUMBER_OF_FILTERS 13
-
-/* parentactuator->type */
-#define ACT_PARENT_SET 0
-#define ACT_PARENT_REMOVE 1
-
-/* parentactuator->flag */
-#define ACT_PARENT_COMPOUND 1
-#define ACT_PARENT_GHOST 2
-
-/* armatureactuator->type */
-#define ACT_ARM_RUN 0
-#define ACT_ARM_ENABLE 1
-#define ACT_ARM_DISABLE 2
-#define ACT_ARM_SETTARGET 3
-#define ACT_ARM_SETWEIGHT 4
-#define ACT_ARM_SETINFLUENCE 5
-/* update this define if more types are added */
-#define ACT_ARM_MAXTYPE 5
-
-/* stateactuator->type */
-#define ACT_STATE_SET 0
-#define ACT_STATE_ADD 1
-#define ACT_STATE_REMOVE 2
-#define ACT_STATE_CHANGE 3
-
-/* steeringactuator->type */
-#define ACT_STEERING_SEEK 0
-#define ACT_STEERING_FLEE 1
-#define ACT_STEERING_PATHFOLLOWING 2
-/* steeringactuator->flag */
-#define ACT_STEERING_SELFTERMINATED 1
-#define ACT_STEERING_ENABLEVISUALIZATION 2
-#define ACT_STEERING_AUTOMATICFACING 4
-#define ACT_STEERING_NORMALUP 8
-#define ACT_STEERING_LOCKZVEL 16
-
-/* mouseactuator->type */
-#define ACT_MOUSE_VISIBILITY 0
-#define ACT_MOUSE_LOOK 1
-
-/* mouseactuator->flag */
-#define ACT_MOUSE_VISIBLE (1 << 0)
-#define ACT_MOUSE_USE_AXIS_X (1 << 1)
-#define ACT_MOUSE_USE_AXIS_Y (1 << 2)
-#define ACT_MOUSE_RESET_X (1 << 3)
-#define ACT_MOUSE_RESET_Y (1 << 4)
-#define ACT_MOUSE_LOCAL_X (1 << 5)
-#define ACT_MOUSE_LOCAL_Y (1 << 6)
-
-/* mouseactuator->object_axis */
-#define ACT_MOUSE_OBJECT_AXIS_X 0
-#define ACT_MOUSE_OBJECT_AXIS_Y 1
-#define ACT_MOUSE_OBJECT_AXIS_Z 2
-
-#endif /* __DNA_ACTUATOR_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_anim_types.h b/source/blender/makesdna/DNA_anim_types.h
index cea1a1cf40f..13656c543ce 100644
--- a/source/blender/makesdna/DNA_anim_types.h
+++ b/source/blender/makesdna/DNA_anim_types.h
@@ -488,11 +488,13 @@ typedef struct FCurve {
/* value cache + settings */
float curval; /* value stored from last time curve was evaluated (not threadsafe, debug display only!) */
+ /* Value which comes from original DNA ddatablock at a time f-curve was evaluated. */
+ float orig_dna_val;
short flag; /* user-editable settings for this curve */
short extend; /* value-extending mode for this curve (does not cover */
char auto_smoothing; /* auto-handle smoothing mode */
- char pad[7];
+ char pad[3];
/* RNA - data link */
int array_index; /* if applicable, the index of the RNA-array item to get */
@@ -960,6 +962,8 @@ typedef enum eAnimData_Flag {
typedef enum eAnimData_Recalc {
ADT_RECALC_DRIVERS = (1 << 0),
ADT_RECALC_ANIM = (1 << 1),
+ /* Only apply f-curve value if its original DNA value matches current DNA value. */
+ ADT_RECALC_CHECK_ORIG_DNA = (1 << 2),
ADT_RECALC_ALL = (ADT_RECALC_DRIVERS | ADT_RECALC_ANIM)
} eAnimData_Recalc;
diff --git a/source/blender/makesdna/DNA_armature_types.h b/source/blender/makesdna/DNA_armature_types.h
index 757c0eb8394..9e278c63904 100644
--- a/source/blender/makesdna/DNA_armature_types.h
+++ b/source/blender/makesdna/DNA_armature_types.h
@@ -99,8 +99,6 @@ typedef struct bArmature {
Bone *act_bone; /* active bone */
struct EditBone *act_edbone; /* active editbone (in editmode) */
- void *sketch; /* sketch struct for etch-a-ton */
-
int flag;
int drawtype;
int gevertdeformer; /* how vertex deformation is handled in the ge */
diff --git a/source/blender/makesdna/DNA_camera_types.h b/source/blender/makesdna/DNA_camera_types.h
index 52e40cbc098..c90599bb5cc 100644
--- a/source/blender/makesdna/DNA_camera_types.h
+++ b/source/blender/makesdna/DNA_camera_types.h
@@ -34,6 +34,8 @@
#include "DNA_defs.h"
#include "DNA_gpu_types.h"
+#include "DNA_movieclip_types.h"
+#include "DNA_image_types.h"
#include "DNA_ID.h"
#ifdef __cplusplus
@@ -59,6 +61,20 @@ typedef struct CameraStereoSettings {
float pole_merge_angle_to;
} CameraStereoSettings;
+/* Background Picture */
+typedef struct CameraBGImage {
+ struct CameraBGImage *next, *prev;
+
+ struct Image *ima;
+ struct ImageUser iuser;
+ struct MovieClip *clip;
+ struct MovieClipUser cuser;
+ float offset[2], scale, rotation;
+ float alpha;
+ short flag;
+ short source;
+} CameraBGImage;
+
typedef struct Camera {
ID id;
struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
@@ -82,9 +98,19 @@ typedef struct Camera {
struct Object *dof_ob;
struct GPUDOFSettings gpu_dof;
+ /* CameraBGImage reference images */
+ struct ListBase bg_images;
+
char sensor_fit;
char pad[7];
+ /* runtime only, used for drawing */
+ float drwcorners[4][2];
+ float drwtria[2][2];
+ float drwdepth, pad1;
+ float drwfocusmat[4][4];
+ float drwnormalmat[4][4];
+
/* Stereo settings */
struct CameraStereoSettings stereo;
} Camera;
@@ -124,6 +150,7 @@ enum {
#endif
CAM_SHOWSENSOR = (1 << 8),
CAM_SHOW_SAFE_CENTER = (1 << 9),
+ CAM_SHOW_BG_IMAGE = (1 << 10),
};
/* yafray: dof sampling switch */
@@ -159,6 +186,32 @@ enum {
CAM_S3D_POLE_MERGE = (1 << 1),
};
+/* CameraBGImage->flag */
+/* may want to use 1 for select ? */
+enum {
+ CAM_BGIMG_FLAG_EXPANDED = (1 << 1),
+ CAM_BGIMG_FLAG_CAMERACLIP = (1 << 2),
+ CAM_BGIMG_FLAG_DISABLED = (1 << 3),
+ CAM_BGIMG_FLAG_FOREGROUND = (1 << 4),
+
+ /* Camera framing options */
+ CAM_BGIMG_FLAG_CAMERA_ASPECT = (1 << 5), /* don't stretch to fit the camera view */
+ CAM_BGIMG_FLAG_CAMERA_CROP = (1 << 6), /* crop out the image */
+
+ /* Axis flip options */
+ CAM_BGIMG_FLAG_FLIP_X = (1 << 7),
+ CAM_BGIMG_FLAG_FLIP_Y = (1 << 8),
+};
+
+#define CAM_BGIMG_FLAG_EXPANDED (CAM_BGIMG_FLAG_EXPANDED | CAM_BGIMG_FLAG_CAMERACLIP)
+
+/* CameraBGImage->source */
+/* may want to use 1 for select ?*/
+enum {
+ CAM_BGIMG_SOURCE_IMAGE = 0,
+ CAM_BGIMG_SOURCE_MOVIE = 1,
+};
+
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/makesdna/DNA_constraint_types.h b/source/blender/makesdna/DNA_constraint_types.h
index 4c4440ad573..f0f8c3fe2bd 100644
--- a/source/blender/makesdna/DNA_constraint_types.h
+++ b/source/blender/makesdna/DNA_constraint_types.h
@@ -488,7 +488,7 @@ typedef enum eBConstraint_Types {
CONSTRAINT_TYPE_DISTLIMIT = 14, /* limit distance */
CONSTRAINT_TYPE_STRETCHTO = 15, /* claiming this to be mine :) is in tuhopuu bjornmose */
CONSTRAINT_TYPE_MINMAX = 16, /* floor constraint */
- CONSTRAINT_TYPE_RIGIDBODYJOINT = 17, /* rigidbody constraint */
+ /* CONSTRAINT_TYPE_DEPRECATED = 17 */
CONSTRAINT_TYPE_CLAMPTO = 18, /* clampto constraint */
CONSTRAINT_TYPE_TRANSFORM = 19, /* transformation (loc/rot/size -> loc/rot/size) constraint */
CONSTRAINT_TYPE_SHRINKWRAP = 20, /* shrinkwrap (loc/rot) constraint */
@@ -526,6 +526,8 @@ typedef enum eBConstraint_Flags {
CONSTRAINT_OFF = (1<<9),
/* use bbone curve shape when calculating headtail values */
CONSTRAINT_BBONE_SHAPE = (1<<10),
+ /* That constraint has been inserted in local override (i.e. it can be fully edited!). */
+ CONSTRAINT_STATICOVERRIDE_LOCAL = (1 << 11),
} eBConstraint_Flags;
/* bConstraint->ownspace/tarspace */
@@ -841,10 +843,6 @@ typedef enum eObjectSolver_Flags {
OBJECTSOLVER_ACTIVECLIP = (1<<0)
} eObjectSolver_Flags;
-/* Rigid-Body Constraint */
-#define CONSTRAINT_DRAW_PIVOT 0x40
-#define CONSTRAINT_DISABLE_LINKED_COLLISION 0x80
-
/* ObjectSolver Constraint -> flag */
typedef enum eStretchTo_Flags {
STRETCHTOCON_USE_BULGE_MIN = (1 << 0),
diff --git a/source/blender/makesdna/DNA_controller_types.h b/source/blender/makesdna/DNA_controller_types.h
deleted file mode 100644
index 154542d60c5..00000000000
--- a/source/blender/makesdna/DNA_controller_types.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file DNA_controller_types.h
- * \ingroup DNA
- *
- * #bController type is specifically for use by Object logic-bricks in the game-engine.
- */
-
-#ifndef __DNA_CONTROLLER_TYPES_H__
-#define __DNA_CONTROLLER_TYPES_H__
-
-struct bActuator;
-struct Text;
-struct bSensor;
-
-/* ****************** CONTROLLERS ********************* */
-
-typedef struct bExpressionCont {
- char str[128];
-} bExpressionCont;
-
-typedef struct bPythonCont {
- struct Text *text;
- char module[64];
- int mode;
- int flag; /* only used for debug now */
-} bPythonCont;
-
-typedef struct bController {
- struct bController *next, *prev, *mynew;
- short type, flag, inputs, totlinks;
- short otype, totslinks, pad2, pad3;
-
- char name[64];
- void *data;
-
- struct bActuator **links;
-
- struct bSensor **slinks;
- short val, valo;
- unsigned int state_mask;
-
-} bController;
-
-/* controller->type */
-#define CONT_LOGIC_AND 0
-#define CONT_LOGIC_OR 1
-#define CONT_EXPRESSION 2
-#define CONT_PYTHON 3
-#define CONT_LOGIC_NAND 4
-#define CONT_LOGIC_NOR 5
-#define CONT_LOGIC_XOR 6
-#define CONT_LOGIC_XNOR 7
-
-/* controller->flag */
-#define CONT_SHOW 1
-#define CONT_DEL 2
-#define CONT_NEW 4
-#define CONT_MASK 8
-#define CONT_PRIO 16
-#define CONT_DEACTIVATE 32
-
-/* pyctrl->flag */
-#define CONT_PY_DEBUG 1
-
-/* pyctrl->mode */
-#define CONT_PY_SCRIPT 0
-#define CONT_PY_MODULE 1
-
-#endif /* __DNA_CONTROLLER_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_curve_types.h b/source/blender/makesdna/DNA_curve_types.h
index 91b64b793c1..fd0170b9766 100644
--- a/source/blender/makesdna/DNA_curve_types.h
+++ b/source/blender/makesdna/DNA_curve_types.h
@@ -265,6 +265,7 @@ typedef struct Curve {
char pad2[2];
+ void *batch_cache;
} Curve;
#define CURVE_VFONT_ANY(cu) \
diff --git a/source/blender/makesdna/DNA_customdata_types.h b/source/blender/makesdna/DNA_customdata_types.h
index 2d1ffaa53eb..0e0b1d669d9 100644
--- a/source/blender/makesdna/DNA_customdata_types.h
+++ b/source/blender/makesdna/DNA_customdata_types.h
@@ -92,13 +92,13 @@ typedef enum CustomDataType {
CD_MCOL = 6,
CD_ORIGINDEX = 7,
CD_NORMAL = 8,
-/* CD_POLYINDEX = 9, */
+ CD_FACEMAP = 9, /* exclusive face group, each face can only be part of one */
CD_PROP_FLT = 10,
CD_PROP_INT = 11,
CD_PROP_STR = 12,
CD_ORIGSPACE = 13, /* for modifier stack face location mapping */
CD_ORCO = 14,
- CD_MTEXPOLY = 15,
+/* CD_MTEXPOLY = 15, */ /* deprecated */
CD_MLOOPUV = 16,
CD_MLOOPCOL = 17,
CD_TANGENT = 18,
@@ -143,13 +143,13 @@ typedef enum CustomDataType {
#define CD_MASK_MCOL (1 << CD_MCOL)
#define CD_MASK_ORIGINDEX (1 << CD_ORIGINDEX)
#define CD_MASK_NORMAL (1 << CD_NORMAL)
-// #define CD_MASK_POLYINDEX (1 << CD_POLYINDEX)
+#define CD_MASK_FACEMAP (1 << CD_FACEMAP)
#define CD_MASK_PROP_FLT (1 << CD_PROP_FLT)
#define CD_MASK_PROP_INT (1 << CD_PROP_INT)
#define CD_MASK_PROP_STR (1 << CD_PROP_STR)
#define CD_MASK_ORIGSPACE (1 << CD_ORIGSPACE)
#define CD_MASK_ORCO (1 << CD_ORCO)
-#define CD_MASK_MTEXPOLY (1 << CD_MTEXPOLY)
+// #define CD_MASK_MTEXPOLY (1 << CD_MTEXPOLY) /* DEPRECATED */
#define CD_MASK_MLOOPUV (1 << CD_MLOOPUV)
#define CD_MASK_MLOOPCOL (1 << CD_MLOOPCOL)
#define CD_MASK_TANGENT (1 << CD_TANGENT)
diff --git a/source/blender/makesdna/DNA_defs.h b/source/blender/makesdna/DNA_defs.h
index fc9dd8f06a9..bfa8da02707 100644
--- a/source/blender/makesdna/DNA_defs.h
+++ b/source/blender/makesdna/DNA_defs.h
@@ -44,6 +44,12 @@
# endif
#endif
+#ifdef __GNUC__
+# define DNA_PRIVATE_ATTR __attribute__ ((deprecated))
+#else
+# define DNA_PRIVATE_ATTR
+#endif
+
/* poison pragma */
#ifdef DNA_DEPRECATED_ALLOW
diff --git a/source/blender/makesdna/DNA_dynamicpaint_types.h b/source/blender/makesdna/DNA_dynamicpaint_types.h
index 17553e98817..ecdcb2398ac 100644
--- a/source/blender/makesdna/DNA_dynamicpaint_types.h
+++ b/source/blender/makesdna/DNA_dynamicpaint_types.h
@@ -177,7 +177,7 @@ typedef struct DynamicPaintCanvasSettings {
/* flags */
enum {
MOD_DPAINT_PART_RAD = 1 << 0, /* use particle radius */
- MOD_DPAINT_USE_MATERIAL = 1 << 1, /* use object material */
+ //MOD_DPAINT_USE_MATERIAL = 1 << 1, /* DNA_DEPRECATED */
MOD_DPAINT_ABS_ALPHA = 1 << 2, /* don't increase alpha unless paint alpha is higher than existing */
MOD_DPAINT_ERASE = 1 << 3, /* removes paint */
@@ -231,7 +231,6 @@ typedef struct DynamicPaintBrushSettings {
struct DynamicPaintModifierData *pmd; /* for fast RNA access */
struct DerivedMesh *dm;
struct ParticleSystem *psys;
- struct Material *mat;
int flags;
int collision;
diff --git a/source/blender/makesdna/DNA_fileglobal_types.h b/source/blender/makesdna/DNA_fileglobal_types.h
index b2ab0d2a08d..ed9640c365f 100644
--- a/source/blender/makesdna/DNA_fileglobal_types.h
+++ b/source/blender/makesdna/DNA_fileglobal_types.h
@@ -32,9 +32,6 @@
#ifndef __DNA_FILEGLOBAL_TYPES_H__
#define __DNA_FILEGLOBAL_TYPES_H__
-struct bScreen;
-struct Scene;
-
/**
* FileGlobal stores a part of the current user-interface settings at
* the moment of saving, and the file-specific settings.
@@ -46,6 +43,9 @@ typedef struct FileGlobal {
char pad[6];
struct bScreen *curscreen;
struct Scene *curscene;
+ struct ViewLayer *cur_view_layer;
+ void *pad1;
+
int fileflags;
int globalf;
uint64_t build_commit_timestamp; /* commit timestamp from buildinfo */
diff --git a/source/blender/makesdna/DNA_gpencil_types.h b/source/blender/makesdna/DNA_gpencil_types.h
index a62538d1032..d5a5a1d5d4a 100644
--- a/source/blender/makesdna/DNA_gpencil_types.h
+++ b/source/blender/makesdna/DNA_gpencil_types.h
@@ -128,7 +128,7 @@ typedef enum eGPDpalettecolor_Flag {
PC_COLOR_LOCKED = (1 << 2),
/* do onion skinning */
PC_COLOR_ONIONSKIN = (1 << 3),
- /* "volumetric" strokes (i.e. GLU Quadric discs in 3D) */
+ /* "volumetric" strokes */
PC_COLOR_VOLUMETRIC = (1 << 4),
/* Use High quality fill */
PC_COLOR_HQ_FILL = (1 << 5)
@@ -273,7 +273,7 @@ typedef enum eGPDlayer_Flag {
GP_LAYER_GHOST_PREVCOL = (1 << 8),
/* use custom color for ghosts after current frame */
GP_LAYER_GHOST_NEXTCOL = (1 << 9),
- /* "volumetric" strokes (i.e. GLU Quadric discs in 3D) */
+ /* "volumetric" strokes */
GP_LAYER_VOLUMETRIC = (1 << 10),
/* Use high quality fill (instead of buggy legacy OpenGL Fill) */
GP_LAYER_HQ_FILL = (1 << 11),
@@ -300,6 +300,7 @@ typedef struct bGPdata {
short sbuffer_sflag; /* flags for stroke that cache represents */
void *sbuffer; /* stroke buffer (can hold GP_STROKE_BUFFER_MAX) */
float scolor[4]; /* buffer color using palettes */
+ float sfill[4]; /* buffer fill color */
char pad[6]; /* padding for compiler alignment error */
short sflag; /* settings for palette color */
diff --git a/source/blender/makesdna/DNA_gpu_types.h b/source/blender/makesdna/DNA_gpu_types.h
index 967cb7284dc..be34309572f 100644
--- a/source/blender/makesdna/DNA_gpu_types.h
+++ b/source/blender/makesdna/DNA_gpu_types.h
@@ -38,6 +38,8 @@ typedef struct GPUDOFSettings {
float fstop;
float focal_length;
float sensor;
+ float rotation;
+ float ratio;
int num_blades;
int high_quality;
} GPUDOFSettings;
diff --git a/source/blender/makesdna/DNA_group_types.h b/source/blender/makesdna/DNA_group_types.h
index 45dd0cb9ff2..57db668b282 100644
--- a/source/blender/makesdna/DNA_group_types.h
+++ b/source/blender/makesdna/DNA_group_types.h
@@ -42,9 +42,6 @@ struct Object;
typedef struct GroupObject {
struct GroupObject *next, *prev;
struct Object *ob;
- void *lampren; /* used while render */
- short recalc; /* copy of ob->recalc, used to set animated groups OK */
- char pad[6];
} GroupObject;
@@ -60,6 +57,13 @@ typedef struct Group {
* on the last used scene */
unsigned int layer;
float dupli_ofs[3];
+
+ struct SceneCollection *collection;
+ struct ViewLayer *view_layer;
} Group;
+
+#define GROUP_MASTER_COLLECTION(_group) \
+ (((LayerCollection *)(_group)->view_layer->layer_collections.first)->scene_collection)
+
#endif /* __DNA_GROUP_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_image_types.h b/source/blender/makesdna/DNA_image_types.h
index b4bc26f45cd..3d29c5b3833 100644
--- a/source/blender/makesdna/DNA_image_types.h
+++ b/source/blender/makesdna/DNA_image_types.h
@@ -116,23 +116,18 @@ typedef struct Image {
int lastframe;
/* texture page */
- short tpageflag, totbind;
- short xrep, yrep;
- short twsta, twend;
+ short tpageflag;
+ short pad2;
unsigned int bindcode[2]; /* only for current image... 2 = TEXTARGET_COUNT */
- char pad1[4];
- unsigned int *repbind; /* for repeat of parts of images */
-
+ unsigned int pad3;
+
struct PackedFile *packedfile DNA_DEPRECATED; /* deprecated */
struct ListBase packedfiles;
struct PreviewImage *preview;
- /* game engine tile animation */
- float lastupdate;
int lastused;
- short animspeed;
-
short ok;
+ short pad4[3];
/* for generated images */
int gen_x, gen_y;
@@ -168,7 +163,7 @@ enum {
#ifdef DNA_DEPRECATED
IMA_DO_PREMUL = (1 << 2), /* deprecated, should not be used */
#endif
- IMA_REFLECT = (1 << 4),
+ //IMA_REFLECT = (1 << 4), /* deprecated */
IMA_NOCOLLECT = (1 << 5),
//IMA_DONE_TAG = (1 << 6), // UNUSED
IMA_OLD_PREMUL = (1 << 7),
@@ -184,12 +179,12 @@ enum {
};
/* Image.tpageflag */
-#define IMA_TILES 1
-#define IMA_TWINANIM 2
-#define IMA_COLCYCLE 4 /* Depreciated */
+//#define IMA_TILES 1 /* Deprecated */
+//#define IMA_TWINANIM 2 /* Deprecated */
+#define IMA_COLCYCLE 4 /* Deprecated */
#define IMA_MIPMAP_COMPLETE 8 /* all mipmap levels in OpenGL texture set? */
-#define IMA_CLAMP_U 16
-#define IMA_CLAMP_V 32
+//#define IMA_CLAMP_U 16 /* Deprecated */
+//#define IMA_CLAMP_V 32 /* Deprecated */
#define IMA_TPAGE_REFRESH 64
#define IMA_GLBIND_IS_DATA 128 /* opengl image texture bound as non-color data */
diff --git a/source/blender/makesdna/DNA_lamp_types.h b/source/blender/makesdna/DNA_lamp_types.h
index a2e39f93875..43606cbcd9d 100644
--- a/source/blender/makesdna/DNA_lamp_types.h
+++ b/source/blender/makesdna/DNA_lamp_types.h
@@ -67,45 +67,30 @@ typedef struct Lamp {
short pad2;
float clipsta, clipend;
- float bias, soft, compressthresh, bleedbias, pad5;
+ float bias, soft, bleedbias, bleedexp;
short bufsize, samp, buffers, filtertype;
char bufflag, buftype;
- short ray_samp, ray_sampy, ray_sampz;
- short ray_samp_type;
short area_shape;
float area_size, area_sizey, area_sizez;
- float adapt_thresh;
- short ray_samp_method;
- short shadowmap_type;
/* texact is for buttons */
short texact, shadhalostep;
- /* sun/sky */
- short sun_effect_type;
- short skyblendtype;
- float horizon_brightness;
- float spread;
- float sun_brightness;
- float sun_size;
- float backscattered_light;
- float sun_intensity;
- float atm_turbidity;
- float atm_inscattering_factor;
- float atm_extinction_factor;
- float atm_distance_factor;
- float skyblendfac;
- float sky_exposure;
- float shadow_frustum_size; /* BGE Only */
- short sky_colorspace;
- char pad4[2];
-
struct Ipo *ipo DNA_DEPRECATED; /* old animation system, deprecated for 2.5 */
- struct MTex *mtex[18]; /* MAX_MTEX */
short pr_texture, use_nodes;
char pad6[4];
+ /* Eevee */
+ float cascade_max_dist;
+ float cascade_exponent;
+ float cascade_fade;
+ int cascade_count;
+
+ float contact_dist, contact_bias, contact_spread, contact_thickness;
+
+ float spec_fac, pad;
+
/* preview */
struct PreviewImage *preview;
@@ -130,36 +115,28 @@ typedef struct Lamp {
#define LA_AREA 4
/* mode */
-#define LA_SHAD_BUF (1 << 0)
-#define LA_HALO (1 << 1)
-#define LA_LAYER (1 << 2)
-#define LA_QUAD (1 << 3) /* no longer used */
-#define LA_NEG (1 << 4)
-#define LA_ONLYSHADOW (1 << 5)
-#define LA_SPHERE (1 << 6)
+#define LA_SHADOW (1 << 0)
+/* #define LA_HALO (1 << 1) */ /* not used anymore */
+/* #define LA_LAYER (1 << 2) */ /* not used anymore */
+/* #define LA_QUAD (1 << 3) */ /* not used anymore */
+/* #define LA_NEG (1 << 4) */ /* not used anymore */
+/* #define LA_ONLYSHADOW(1 << 5) */ /* not used anymore */
+/* #define LA_SPHERE (1 << 6) */ /* not used anymore */
#define LA_SQUARE (1 << 7)
-#define LA_TEXTURE (1 << 8)
-#define LA_OSATEX (1 << 9)
+/* #define LA_TEXTURE (1 << 8) */ /* not used anymore */
+/* #define LA_OSATEX (1 << 9) */ /* not used anymore */
/* #define LA_DEEP_SHADOW (1 << 10) */ /* not used anywhere */
-#define LA_NO_DIFF (1 << 11)
-#define LA_NO_SPEC (1 << 12)
-#define LA_SHAD_RAY (1 << 13)
+/* #define LA_NO_DIFF (1 << 11) */ /* not used anywhere */
+/* #define LA_NO_SPEC (1 << 12) */ /* not used anywhere */
+/* #define LA_SHAD_RAY (1 << 13) */ /* not used anywhere - cleaned */
/* yafray: lamp shadowbuffer flag, softlight */
/* Since it is used with LOCAL lamp, can't use LA_SHAD */
-/* #define LA_YF_SOFT (1 << 14) */ /* no longer used */
-#define LA_LAYER_SHADOW (1 << 15)
-#define LA_SHAD_TEX (1 << 16)
+/* #define LA_YF_SOFT (1 << 14) */ /* not used anymore */
+/* #define LA_LAYER_SHADOW (1 << 15) */ /* not used anymore */
+/* #define LA_SHAD_TEX (1 << 16) */ /* not used anymore */
#define LA_SHOW_CONE (1 << 17)
-#define LA_SHOW_SHADOW_BOX (1 << 18)
-
-/* layer_shadow */
-#define LA_LAYER_SHADOW_BOTH 0
-#define LA_LAYER_SHADOW_CAST 1
-#define LA_LAYER_SHADOW_RECEIVE 2
-
-/* sun effect type*/
-#define LA_SUN_EFFECT_SKY 1
-#define LA_SUN_EFFECT_AP 2
+/* #define LA_SHOW_SHADOW_BOX (1 << 18) */
+#define LA_SHAD_CONTACT (1 << 19)
/* falloff_type */
#define LA_FALLOFF_CONSTANT 0
@@ -169,47 +146,11 @@ typedef struct Lamp {
#define LA_FALLOFF_SLIDERS 4
#define LA_FALLOFF_INVCOEFFICIENTS 5
-
-/* buftype, no flag */
-#define LA_SHADBUF_REGULAR 0
-#define LA_SHADBUF_IRREGULAR 1
-#define LA_SHADBUF_HALFWAY 2
-#define LA_SHADBUF_DEEP 3
-
-/* bufflag, auto clipping */
-#define LA_SHADBUF_AUTO_START 1
-#define LA_SHADBUF_AUTO_END 2
-
-/* filtertype */
-#define LA_SHADBUF_BOX 0
-#define LA_SHADBUF_TENT 1
-#define LA_SHADBUF_GAUSS 2
-
/* area shape */
#define LA_AREA_SQUARE 0
#define LA_AREA_RECT 1
#define LA_AREA_CUBE 2
#define LA_AREA_BOX 3
-/* ray_samp_method */
-#define LA_SAMP_CONSTANT 0
-#define LA_SAMP_HALTON 1
-#define LA_SAMP_HAMMERSLEY 2
-
-
-/* ray_samp_type */
-// #define LA_SAMP_ROUND 1 // UNUSED
-#define LA_SAMP_UMBRA 2
-#define LA_SAMP_DITHER 4
-#define LA_SAMP_JITTER 8
-
-/* mapto */
-#define LAMAP_COL 1
-#define LAMAP_SHAD 2
-
-/* shadowmap_type */
-#define LA_SHADMAP_SIMPLE 0
-#define LA_SHADMAP_VARIANCE 1
-
#endif /* __DNA_LAMP_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_lattice_types.h b/source/blender/makesdna/DNA_lattice_types.h
index 242d6f0feeb..28a401676fc 100644
--- a/source/blender/makesdna/DNA_lattice_types.h
+++ b/source/blender/makesdna/DNA_lattice_types.h
@@ -69,6 +69,7 @@ typedef struct Lattice {
char vgroup[64]; /* multiply the influence, MAX_VGROUP_NAME */
struct EditLatt *editlatt;
+ void *batch_cache;
} Lattice;
/* ***************** LATTICE ********************* */
diff --git a/source/blender/makesdna/DNA_layer_types.h b/source/blender/makesdna/DNA_layer_types.h
new file mode 100644
index 00000000000..b3309a2e10f
--- /dev/null
+++ b/source/blender/makesdna/DNA_layer_types.h
@@ -0,0 +1,149 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Dalai Felinto
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file DNA_layer_types.h
+ * \ingroup DNA
+ */
+
+#ifndef __DNA_LAYER_TYPES_H__
+#define __DNA_LAYER_TYPES_H__
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include "DNA_freestyle_types.h"
+#include "DNA_listBase.h"
+
+typedef struct Base {
+ struct Base *next, *prev;
+ short flag;
+ short refcount;
+ short sx, sy;
+ struct Object *object;
+ unsigned int lay;
+ int flag_legacy;
+ struct IDProperty *collection_properties; /* used by depsgraph, flushed from collection-tree */
+} Base;
+
+typedef struct CollectionOverride {
+ struct CollectionOverride *next, *prev;
+ char name[64]; /* MAX_NAME */
+ /* TODO proper data */
+} CollectionOverride;
+
+typedef struct ViewLayerEngineData {
+ struct ViewLayerEngineData *next, *prev;
+ struct DrawEngineType *engine_type;
+ void *storage;
+ void (*free)(void *storage);
+} ViewLayerEngineData;
+
+typedef struct LayerCollection {
+ struct LayerCollection *next, *prev;
+ struct SceneCollection *scene_collection;
+ short flag;
+ /* TODO(sergey): Get rid of this once we've got CoW in DEG, */
+ short flag_evaluated;
+ short pad[2];
+ ListBase object_bases; /* (ObjectBase *)LinkData->data - synced with collection->objects */
+ ListBase overrides;
+ ListBase layer_collections; /* synced with collection->collections */
+ struct IDProperty *properties; /* overrides */
+ struct IDProperty *properties_evaluated;
+} LayerCollection;
+
+typedef struct ViewLayer {
+ struct ViewLayer *next, *prev;
+ char name[64]; /* MAX_NAME */
+ short active_collection;
+ short flag;
+ short pad[2];
+ ListBase object_bases; /* ObjectBase */
+ struct SceneStats *stats; /* default allocated now */
+ struct Base *basact;
+ ListBase layer_collections; /* LayerCollection */
+ struct IDProperty *properties; /* overrides */
+ struct IDProperty *properties_evaluated;
+
+ /* Old SceneRenderLayer data. */
+ int layflag;
+ int passflag; /* pass_xor has to be after passflag */
+ int pass_xor;
+ float pass_alpha_threshold;
+
+ struct IDProperty *id_properties; /* Equivalent to datablocks ID properties. */
+
+ struct FreestyleConfig freestyle_config;
+
+ /* Runtime data */
+ ListBase drawdata; /* ViewLayerEngineData */
+ struct Base **object_bases_array;
+} ViewLayer;
+
+typedef struct SceneCollection {
+ struct SceneCollection *next, *prev;
+ char name[64]; /* MAX_NAME */
+ int active_object_index; /* for UI */
+ char type;
+ char pad[3];
+ ListBase objects; /* (Object *)LinkData->data */
+ ListBase scene_collections; /* nested collections */
+} SceneCollection;
+
+/* Base->flag */
+enum {
+ BASE_SELECTED = (1 << 0),
+ BASE_VISIBLED = (1 << 1),
+ BASE_SELECTABLED = (1 << 2),
+ BASE_FROMDUPLI = (1 << 3),
+ BASE_DIRTY_ENGINE_SETTINGS = (1 << 4),
+ BASE_FROM_SET = (1 << 5), /* To be set only by the depsgraph */
+};
+
+/* LayerCollection->flag */
+enum {
+ COLLECTION_VIEWPORT = (1 << 0), /* Only used for group collections. */
+ COLLECTION_SELECTABLE = (1 << 1),
+ COLLECTION_DISABLED = (1 << 2),
+ COLLECTION_RENDER = (1 << 3), /* Only used for group collections. */
+};
+
+/* ViewLayer->flag */
+enum {
+ VIEW_LAYER_RENDER = (1 << 0),
+ VIEW_LAYER_ENGINE_DIRTY = (1 << 1),
+ VIEW_LAYER_FREESTYLE = (1 << 2),
+};
+
+/* SceneCollection->type */
+enum {
+ COLLECTION_TYPE_NONE = 0,
+ COLLECTION_TYPE_GROUP_INTERNAL = 1,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DNA_LAYER_TYPES_H__ */
+
diff --git a/source/blender/makesdna/DNA_lightprobe_types.h b/source/blender/makesdna/DNA_lightprobe_types.h
new file mode 100644
index 00000000000..3eee6d4b192
--- /dev/null
+++ b/source/blender/makesdna/DNA_lightprobe_types.h
@@ -0,0 +1,113 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ *
+ */
+
+/** \file DNA_lightprobe_types.h
+ * \ingroup DNA
+ */
+
+#ifndef __DNA_LIGHTPROBE_TYPES_H__
+#define __DNA_LIGHTPROBE_TYPES_H__
+
+#include "DNA_defs.h"
+#include "DNA_listBase.h"
+#include "DNA_ID.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+struct Object;
+struct AnimData;
+
+typedef struct LightProbe {
+ ID id;
+ struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
+
+ char type; /* For realtime probe objects */
+ char flag; /* General purpose flags for probes */
+ char attenuation_type; /* Attenuation type */
+ char parallax_type; /* Parallax type */
+
+ float distinf; /* Influence Radius */
+ float distpar; /* Parallax Radius */
+ float falloff; /* Influence falloff */
+
+ float clipsta, clipend;
+
+ float vis_bias, vis_bleedbias; /* VSM visibility biases */
+ float vis_blur;
+
+ float intensity; /* Intensity multiplier */
+
+ int grid_resolution_x; /* Irradiance grid resolution */
+ int grid_resolution_y;
+ int grid_resolution_z;
+ int pad1;
+
+ struct Object *parallax_ob; /* Object to use as a parallax origin */
+ struct Image *image; /* Image to use on as lighting data */
+ struct Group *visibility_grp; /* Object visibility group, inclusive or exclusive */
+
+ float data_draw_size;
+
+ /* Runtime display data */
+ float distfalloff, distgridinf;
+ float pad;
+} LightProbe;
+
+/* Probe->type */
+enum {
+ LIGHTPROBE_TYPE_CUBE = 0,
+ LIGHTPROBE_TYPE_PLANAR = 1,
+ LIGHTPROBE_TYPE_GRID = 2,
+};
+
+/* Probe->flag */
+enum {
+ LIGHTPROBE_FLAG_CUSTOM_PARALLAX = (1 << 0),
+ LIGHTPROBE_FLAG_SHOW_INFLUENCE = (1 << 1),
+ LIGHTPROBE_FLAG_SHOW_PARALLAX = (1 << 2),
+ LIGHTPROBE_FLAG_SHOW_CLIP_DIST = (1 << 3),
+ LIGHTPROBE_FLAG_SHOW_DATA = (1 << 4),
+ LIGHTPROBE_FLAG_INVERT_GROUP = (1 << 5),
+};
+
+/* Probe->display */
+enum {
+ LIGHTPROBE_DISP_WIRE = 0,
+ LIGHTPROBE_DISP_SHADED = 1,
+ LIGHTPROBE_DISP_DIFFUSE = 2,
+ LIGHTPROBE_DISP_REFLECTIVE = 3,
+};
+
+/* Probe->parallax && Probe->attenuation_type*/
+enum {
+ LIGHTPROBE_SHAPE_ELIPSOID = 0,
+ LIGHTPROBE_SHAPE_BOX = 1,
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __DNA_LIGHTPROBE_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_material_types.h b/source/blender/makesdna/DNA_material_types.h
index 0c500e366a7..564e6aee3fc 100644
--- a/source/blender/makesdna/DNA_material_types.h
+++ b/source/blender/makesdna/DNA_material_types.h
@@ -40,199 +40,79 @@
#define MAX_MTEX 18
#endif
-struct MTex;
struct Image;
-struct ColorBand;
-struct Group;
struct bNodeTree;
struct AnimData;
struct Ipo;
/* WATCH IT: change type? also make changes in ipo.h */
-typedef struct VolumeSettings {
- float density;
- float emission;
- float scattering;
- float reflection;
-
- float emission_col[3];
- float transmission_col[3];
- float reflection_col[3];
-
- float density_scale;
- float depth_cutoff;
- float asymmetry;
-
- short stepsize_type;
- short shadeflag;
- short shade_type;
- short precache_resolution;
-
- float stepsize;
- float ms_diff;
- float ms_intensity;
- float ms_spread;
-} VolumeSettings;
-
-/* Game Engine Options (old Texface mode, transp and flag) */
-typedef struct GameSettings {
- int flag;
- int alpha_blend;
- int face_orientation;
- int pad1;
-} GameSettings;
-
typedef struct TexPaintSlot {
struct Image *ima; /* image to be painted on */
char *uvname; /* customdata index for uv layer, MAX_NAME*/
- int index; /* index for mtex slot in material for blender internal */
+ int valid; /* do we have a valid image and UV map */
int pad;
} TexPaintSlot;
+/* Clay engine */
+
+/* MaterialRuntimeClay.flag */
+#define CLAY_OUTDATED 1
+
+/* MaterialEngineSettingsClay.type */
+#define CLAY_MATCAP_NONE 0
+#define CLAY_MATCAP_SIMPLE 1
+#define CLAY_MATCAP_COMPLETE 2
+
typedef struct Material {
ID id;
struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
- short material_type, flag;
- /* note, keep this below synced with render_types.h */
+ short flag, pad1[7];
+
+ /* Colors from Blender Internal that we are still using. */
float r, g, b;
float specr, specg, specb;
- float mirr, mirg, mirb;
- float ambr, ambb, ambg;
- float amb, emit, ang, spectra, ray_mirror;
- float alpha, ref, spec, zoffs, add;
- float translucency;
- /* end synced with render_types.h */
-
- struct VolumeSettings vol;
- struct GameSettings game;
-
- float fresnel_mir, fresnel_mir_i;
- float fresnel_tra, fresnel_tra_i;
- float filter; /* filter added, for raytrace transparency and transmissivity */
- float tx_limit, tx_falloff;
- short ray_depth, ray_depth_tra;
- short har;
- char seed1, seed2;
-
- float gloss_mir, gloss_tra;
- short samp_gloss_mir, samp_gloss_tra;
- float adapt_thresh_mir, adapt_thresh_tra;
- float aniso_gloss_mir;
- float dist_mir;
- short fadeto_mir;
- short shade_flag; /* like Cubic interpolation */
-
- int mode, mode_l; /* mode_l is the or-ed result of all layer modes */
- int mode2, mode2_l; /* additional mode flags */
- short flarec, starc, linec, ringc;
- float hasize, flaresize, subsize, flareboost;
- float strand_sta, strand_end, strand_ease, strand_surfnor;
- float strand_min, strand_widthfade;
- char strand_uvname[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
-
- float sbias; /* shadow bias to prevent terminator prob */
- float lbias; /* factor to multiply lampbias with (0.0 = no mult) */
- float shad_alpha; /* in use for irregular shadowbuffer */
- int septex;
-
- /* for buttons and render*/
- char rgbsel, texact, pr_type, use_nodes;
- short pr_lamp, pr_texture, ml_flag; /* ml_flag is for disable base material */
-
- /* mapping */
- char mapflag, pad;
-
- /* shaders */
- short diff_shader, spec_shader;
- float roughness, refrac;
- /* XXX param[4] needs review and improvement (shader system as whole anyway)
- * This is nasty reused variable for different goals and not easy to RNAify nicely. -jesterKing */
- float param[4]; /* size, smooth, size, smooth, for toonshader, 0 (fac) and 1 (fresnel) also for fresnel shader */
- float rms;
- float darkness;
-
- /* runtime - OR'd from 'mtex' */
- short texco, mapto;
-
- /* ramp colors */
- struct ColorBand *ramp_col;
- struct ColorBand *ramp_spec;
- char rampin_col, rampin_spec;
- char rampblend_col, rampblend_spec;
- short ramp_show, pad3;
- float rampfac_col, rampfac_spec;
-
- struct MTex *mtex[18]; /* MAX_MTEX */
- struct bNodeTree *nodetree;
- struct Ipo *ipo DNA_DEPRECATED; /* old animation system, deprecated for 2.5 */
- struct Group *group; /* light group */
- struct PreviewImage *preview;
+ float alpha, ray_mirror, spec, gloss_mir;
- /* dynamic properties */
- float friction, fh, reflect;
- float fhdist, xyfrict;
- short dynamode, pad2;
+ /* Ror buttons and render. */
+ char pr_type, use_nodes;
+ short pr_lamp, pr_texture;
- /* subsurface scattering */
- float sss_radius[3], sss_col[3];
- float sss_error, sss_scale, sss_ior;
- float sss_colfac, sss_texfac;
- float sss_front, sss_back;
- short sss_flag, sss_preset;
+ /* Index for render passes. */
+ short index;
- int mapto_textured; /* render-time cache to optimize texture lookups */
- short shadowonly_flag; /* "shadowsonly" type */
- short index; /* custom index for render passes */
+ struct bNodeTree *nodetree;
+ struct Ipo *ipo DNA_DEPRECATED; /* old animation system, deprecated for 2.5 */
+ struct PreviewImage *preview;
- /* Freestyle line settings */
+ /* Freestyle line settings. */
float line_col[4];
short line_priority;
short vcol_alpha;
- /* texture painting */
+ /* Texture painting slots. */
short paint_active_slot;
short paint_clone_slot;
short tot_slots;
- short pad4[3];
-
- /* multiple tangent (Normal Map node) */
- char nmap_tangent_names[9][64]; /* [MAX_MTFACE+1][MAX_NAME]; +1 for empty name */
- int nmap_tangent_names_count, pad5;
-
- struct TexPaintSlot *texpaintslot; /* cached slot for painting. Make sure to recalculate before use
- * with refresh_texpaint_image_cache */
- ListBase gpumaterial; /* runtime */
+ short pad2[3];
+
+ /* Transparency. */
+ float alpha_threshold;
+ float refract_depth;
+ char blend_method;
+ char blend_shadow;
+ char blend_flag;
+ char pad3[5];
+
+ /* Cached slots for texture painting, must be refreshed in
+ * refresh_texpaint_image_cache before using. */
+ struct TexPaintSlot *texpaintslot;
+
+ /* Runtime cache for GLSL materials. */
+ ListBase gpumaterial;
} Material;
-
-/* **************** GAME PROPERTIES ********************* */
-// Blend Transparency Options - alpha_blend /* match GPU_material::GPUBlendMode */
-#define GEMAT_SOLID 0 /* GPU_BLEND_SOLID */
-#define GEMAT_ADD 1 /* GPU_BLEND_ADD */
-#define GEMAT_ALPHA 2 /* GPU_BLEND_ALPHA */
-#define GEMAT_CLIP 4 /* GPU_BLEND_CLIP */
-#define GEMAT_ALPHA_SORT 8 /* GPU_BLEND_ALPHA_SORT */
-#define GEMAT_ALPHA_TO_COVERAGE 16 /* GPU_BLEND_ALPHA_TO_COVERAGE */
-
-// Game Options - flag
-#define GEMAT_BACKCULL 16 /* KX_BACKCULL */
-#define GEMAT_SHADED 32 /* KX_LIGHT */
-#define GEMAT_TEXT 64 /* RAS_RENDER_3DPOLYGON_TEXT */
-#define GEMAT_NOPHYSICS 128
-#define GEMAT_INVISIBLE 256
-
-// Face Orientation Options - face_orientation
-#define GEMAT_NORMAL 0
-#define GEMAT_HALO 512 /* BILLBOARD_SCREENALIGNED */
-#define GEMAT_BILLBOARD 1024 /* BILLBOARD_AXISALIGNED */
-#define GEMAT_SHADOW 2048 /* SHADOW */
-
-// Use Textures - not defined directly in the UI
-#define GEMAT_TEX 4096 /* KX_TEX */
-
-
/* **************** MATERIAL ********************* */
/* maximum number of materials per material array.
@@ -241,12 +121,6 @@ typedef struct Material {
* -1 because for active material we store the index + 1 */
#define MAXMAT (32767-1)
-/* material_type */
-#define MA_TYPE_SURFACE 0
-#define MA_TYPE_HALO 1
-#define MA_TYPE_VOLUME 2
-#define MA_TYPE_WIRE 3
-
/* flag */
/* for render */
#define MA_IS_USED 1
@@ -258,101 +132,7 @@ typedef struct Material {
*/
#define MA_DS_SHOW_TEXS 4
-/* mode (is int) */
-#define MA_TRACEBLE 1
-#define MA_SHADOW 2
-#define MA_SHLESS 4
-#define MA_WIRE 8 /* deprecated */
-#define MA_VERTEXCOL 16
-#define MA_HALO_SOFT 16
-#define MA_HALO 32 /* deprecated */
-#define MA_ZTRANSP 64
-#define MA_VERTEXCOLP 128
-#define MA_ZINV 256
-#define MA_HALO_RINGS 256
-#define MA_ENV 512
-#define MA_HALO_LINES 512
-#define MA_ONLYSHADOW 1024
-#define MA_HALO_XALPHA 1024
-#define MA_STAR 0x800
-#define MA_FACETEXTURE 0x800
-#define MA_HALOTEX 0x1000
-#define MA_HALOPUNO 0x2000
-#define MA_ONLYCAST 0x2000
-#define MA_NOMIST 0x4000
-#define MA_HALO_SHADE 0x4000
-#define MA_HALO_FLARE 0x8000
-#define MA_TRANSP 0x10000
-#define MA_RAYTRANSP 0x20000
-#define MA_RAYMIRROR 0x40000
-#define MA_SHADOW_TRA 0x80000
-#define MA_RAMP_COL 0x100000
-#define MA_RAMP_SPEC 0x200000
-#define MA_RAYBIAS 0x400000
-#define MA_FULL_OSA 0x800000
-#define MA_TANGENT_STR 0x1000000
-#define MA_SHADBUF 0x2000000
- /* note; we drop MA_TANGENT_STR later to become tangent_u */
-#define MA_TANGENT_V 0x4000000
-/* qdn: a bit clumsy this, tangents needed for normal maps separated from shading */
-#define MA_NORMAP_TANG 0x8000000
-#define MA_GROUP_NOLAY 0x10000000
-#define MA_FACETEXTURE_ALPHA 0x20000000
-#define MA_STR_B_UNITS 0x40000000
-#define MA_STR_SURFDIFF 0x80000000
-
-#define MA_MODE_MASK 0x6fffffff /* all valid mode bits */
-#define MA_MODE_PIPELINE (MA_TRANSP | MA_ZTRANSP | MA_RAYTRANSP \
- | MA_TRACEBLE | MA_FULL_OSA | MA_ENV | MA_ZINV \
- | MA_ONLYCAST | MA_SHADBUF)
-
-/* mode2 (is int) */
-#define MA_CASTSHADOW (1 << 0)
-#define MA_MODE2_PIPELINE (MA_CASTSHADOW)
-#define MA_TANGENT_CONCRETE (1 << 1)
-
-/* mapflag */
-#define MA_MAPFLAG_UVPROJECT (1 << 0)
-
-/* ray mirror fadeout */
-#define MA_RAYMIR_FADETOSKY 0
-#define MA_RAYMIR_FADETOMAT 1
-
-/* shadowonly_flag */
-#define MA_SO_OLD 0
-#define MA_SO_SHADOW 1
-#define MA_SO_SHADED 2
-
-/* shade_flag */
-#define MA_CUBIC 1
-#define MA_OBCOLOR 2
-#define MA_APPROX_OCCLUSION 4
-#define MA_GROUP_LOCAL 8
-
-/* diff_shader */
-#define MA_DIFF_LAMBERT 0
-#define MA_DIFF_ORENNAYAR 1
-#define MA_DIFF_TOON 2
-#define MA_DIFF_MINNAERT 3
-#define MA_DIFF_FRESNEL 4
-
-/* spec_shader */
-#define MA_SPEC_COOKTORR 0
-#define MA_SPEC_PHONG 1
-#define MA_SPEC_BLINN 2
-#define MA_SPEC_TOON 3
-#define MA_SPEC_WARDISO 4
-
-/* dynamode */
-// #define MA_DRAW_DYNABUTS 1 /* deprecated */
-#define MA_FH_NOR 2
-
/* ramps */
-#define MA_RAMP_IN_SHADER 0
-#define MA_RAMP_IN_ENERGY 1
-#define MA_RAMP_IN_NOR 2
-#define MA_RAMP_IN_RESULT 3
-
#define MA_RAMP_BLEND 0
#define MA_RAMP_ADD 1
#define MA_RAMP_MULT 2
@@ -394,38 +174,7 @@ typedef struct Material {
/* mapto */
#define MAP_COL 1
-#define MAP_NORM 2
-#define MAP_COLSPEC 4
-#define MAP_COLMIR 8
-#define MAP_VARS (0xFFF0)
-#define MAP_REF 16
-#define MAP_SPEC 32
-#define MAP_EMIT 64
#define MAP_ALPHA 128
-#define MAP_HAR 256
-#define MAP_RAYMIRR 512
-#define MAP_TRANSLU 1024
-#define MAP_AMB 2048
-#define MAP_DISPLACE 4096
-#define MAP_WARP 8192
-// #define MAP_LAYER 16384 /* unused */
-
-/* volume mapto - reuse definitions for now - a bit naughty! */
-#define MAP_DENSITY 128
-#define MAP_EMISSION 64
-#define MAP_EMISSION_COL 1
-#define MAP_SCATTERING 16
-#define MAP_TRANSMISSION_COL 8
-#define MAP_REFLECTION_COL 4
-#define MAP_REFLECTION 32
-
-
-/* mapto for halo */
-//#define MAP_HA_COL 1
-//#define MAP_HA_ALPHA 128
-//#define MAP_HA_HAR 256
-//#define MAP_HA_SIZE 2
-//#define MAP_HA_ADD 64
/* pmapto */
/* init */
@@ -458,24 +207,31 @@ typedef struct Material {
#define MA_HAIR 10
#define MA_ATMOS 11
-/* sss_flag */
-#define MA_DIFF_SSS 1
-
-/* vol_stepsize_type */
-#define MA_VOL_STEP_RANDOMIZED 0
-#define MA_VOL_STEP_CONSTANT 1
-#define MA_VOL_STEP_ADAPTIVE 2
-
-/* vol_shadeflag */
-#define MA_VOL_RECV_EXT_SHADOW 1
-#define MA_VOL_PRECACHESHADING 8
-
-/* vol_shading_type */
-#define MA_VOL_SHADE_SHADELESS 0
-#define MA_VOL_SHADE_SHADOWED 2
-#define MA_VOL_SHADE_SHADED 1
-#define MA_VOL_SHADE_MULTIPLE 3
-#define MA_VOL_SHADE_SHADEDPLUSMULTIPLE 4
+/* blend_method */
+enum {
+ MA_BM_SOLID,
+ MA_BM_ADD,
+ MA_BM_MULTIPLY,
+ MA_BM_CLIP,
+ MA_BM_HASHED,
+ MA_BM_BLEND,
+};
+
+/* blend_flag */
+enum {
+ MA_BL_HIDE_BACKSIDE = (1 << 0),
+ MA_BL_SS_REFRACTION = (1 << 1),
+ MA_BL_SS_SUBSURFACE = (1 << 2),
+ MA_BL_TRANSLUCENCY = (1 << 3),
+};
+
+/* blend_shadow */
+enum {
+ MA_BS_NONE = 0,
+ MA_BS_SOLID,
+ MA_BS_CLIP,
+ MA_BS_HASHED,
+};
#endif
diff --git a/source/blender/makesdna/DNA_mesh_types.h b/source/blender/makesdna/DNA_mesh_types.h
index 39e56925903..d951f67a7c4 100644
--- a/source/blender/makesdna/DNA_mesh_types.h
+++ b/source/blender/makesdna/DNA_mesh_types.h
@@ -52,6 +52,30 @@ struct Material;
struct Mesh;
struct Multires;
+#
+#
+typedef struct EditMeshData {
+ /** when set, \a vertexNos, polyNos are lazy initialized */
+ const float (*vertexCos)[3];
+
+ /** lazy initialize (when \a vertexCos is set) */
+ float const (*vertexNos)[3];
+ float const (*polyNos)[3];
+ /** also lazy init but dont depend on \a vertexCos */
+ const float (*polyCos)[3];
+} EditMeshData;
+
+/* not saved in file! */
+typedef struct MeshRuntime {
+ struct EditMeshData *edit_data;
+ void *batch_cache;
+
+ int64_t cd_dirty_vert;
+ int64_t cd_dirty_edge;
+ int64_t cd_dirty_loop;
+ int64_t cd_dirty_poly;
+} MeshRuntime;
+
typedef struct Mesh {
ID id;
struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
@@ -66,7 +90,6 @@ typedef struct Mesh {
/* BMESH ONLY */
/*new face structures*/
struct MPoly *mpoly;
- struct MTexPoly *mtpoly;
struct MLoop *mloop;
struct MLoopUV *mloopuv;
struct MLoopCol *mloopcol;
@@ -127,6 +150,8 @@ typedef struct Mesh {
short totcol;
struct Multires *mr DNA_DEPRECATED; /* deprecated multiresolution modeling data, only keep for loading old files */
+
+ MeshRuntime runtime;
} Mesh;
/* deprecated by MTFace, only here for file reading */
diff --git a/source/blender/makesdna/DNA_meshdata_types.h b/source/blender/makesdna/DNA_meshdata_types.h
index 8bb711339f7..6d38fe22ea1 100644
--- a/source/blender/makesdna/DNA_meshdata_types.h
+++ b/source/blender/makesdna/DNA_meshdata_types.h
@@ -186,22 +186,9 @@ typedef struct MVertTri {
unsigned int tri[3];
} MVertTri;
-
-typedef struct MTexPoly {
- struct Image *tpage;
- char flag, transp;
- short mode, tile, pad;
-} MTexPoly;
-
-/* can copy from/to MTexPoly/MTFace */
-#define ME_MTEXFACE_CPY(dst, src) \
-{ \
- (dst)->tpage = (src)->tpage; \
- (dst)->flag = (src)->flag; \
- (dst)->transp = (src)->transp; \
- (dst)->mode = (src)->mode; \
- (dst)->tile = (src)->tile; \
-} (void)0
+//typedef struct MTexPoly {
+// void *pad;
+//} MTexPoly;
typedef struct MLoopUV {
float uv[2];
@@ -256,9 +243,6 @@ typedef struct MSelect {
/*tessellation uv face data*/
typedef struct MTFace {
float uv[4][2];
- struct Image *tpage;
- char flag, transp;
- short mode, tile, unwrap;
} MTFace;
/*Custom Data Properties*/
@@ -463,58 +447,4 @@ enum {
ME_FSEL = 2,
};
-/* mtface->flag */
-enum {
- // TF_SELECT = (1 << 0), /* use MFace hide flag (after 2.43), should be able to reuse after 2.44 */
- // TF_ACTIVE = (1 << 1), /* deprecated! */
- TF_SEL1 = (1 << 2),
- TF_SEL2 = (1 << 3),
- TF_SEL3 = (1 << 4),
- TF_SEL4 = (1 << 5),
-};
-
-/* mtface->mode */
-enum {
- TF_DYNAMIC = (1 << 0),
- TF_ALPHASORT = (1 << 1),
- TF_TEX = (1 << 2),
- TF_SHAREDVERT = (1 << 3),
- TF_LIGHT = (1 << 4),
-
- TF_CONVERTED = (1 << 5), /* tface converted to material */
-
- TF_SHAREDCOL = (1 << 6),
- // TF_TILES = (1 << 7), /* deprecated */
- TF_BILLBOARD = (1 << 8),
- TF_TWOSIDE = (1 << 9),
- TF_INVISIBLE = (1 << 10),
-
- TF_OBCOL = (1 << 11),
- TF_BILLBOARD2 = (1 << 12), /* with Z axis constraint */
- TF_SHADOW = (1 << 13),
- TF_BMFONT = (1 << 14),
-};
-
-/* mtface->transp, values 1-4 are used as flags in the GL, WARNING, TF_SUB cant work with this */
-enum {
- TF_SOLID = 0,
- TF_ADD = (1 << 0),
- TF_ALPHA = (1 << 1),
- TF_CLIP = (1 << 2), /* clipmap alpha/binary alpha all or nothing! */
-
- TF_SUB = 3, /* sub is not available in the user interface anymore */
-};
-
-/* mtface->unwrap */
-enum {
- TF_DEPRECATED1 = (1 << 0),
- TF_DEPRECATED2 = (1 << 1),
- TF_DEPRECATED3 = (1 << 2),
- TF_DEPRECATED4 = (1 << 3),
- TF_PIN1 = (1 << 4),
- TF_PIN2 = (1 << 5),
- TF_PIN3 = (1 << 6),
- TF_PIN4 = (1 << 7),
-};
-
#endif /* __DNA_MESHDATA_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_meta_types.h b/source/blender/makesdna/DNA_meta_types.h
index 68d16700a73..fade313e29e 100644
--- a/source/blender/makesdna/DNA_meta_types.h
+++ b/source/blender/makesdna/DNA_meta_types.h
@@ -59,7 +59,6 @@ typedef struct MetaElem {
float len; /* old, only used for backwards compat. use dimensions now */
float *mat, *imat; /* matrix and inverted matrix */
-
} MetaElem;
typedef struct MetaBall {
@@ -93,6 +92,8 @@ typedef struct MetaBall {
/* used in editmode */
/*ListBase edit_elems;*/
MetaElem *lastelem;
+
+ void *batch_cache;
} MetaBall;
/* **************** METABALL ********************* */
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 258acbab31a..cfa101b0b6e 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -105,7 +105,9 @@ typedef struct ModifierData {
struct ModifierData *next, *prev;
int type, mode;
- int stackindex, pad;
+ int stackindex;
+ short flag;
+ short pad;
char name[64]; /* MAX_NAME */
/* XXX for timing info set by caller... solve later? (ton) */
@@ -115,6 +117,11 @@ typedef struct ModifierData {
} ModifierData;
typedef enum {
+ /* This modifier has been inserted in local override, and hence can be fully edited. */
+ eModifierFlag_StaticOverride_Local = (1 << 0),
+} ModifierFlag;
+
+typedef enum {
eSubsurfModifierFlag_Incremental = (1 << 0),
eSubsurfModifierFlag_DebugIncr = (1 << 1),
eSubsurfModifierFlag_ControlEdges = (1 << 2),
@@ -419,8 +426,7 @@ typedef struct UVProjectModifierData {
/* the objects which do the projecting */
struct Object *projectors[10]; /* MOD_UVPROJECT_MAXPROJECTORS */
- struct Image *image; /* the image to project */
- int flags;
+ int pad2;
int num_projectors;
float aspectx, aspecty;
float scalex, scaley;
diff --git a/source/blender/makesdna/DNA_node_types.h b/source/blender/makesdna/DNA_node_types.h
index 8ae1a79f8f7..b5a3752072b 100644
--- a/source/blender/makesdna/DNA_node_types.h
+++ b/source/blender/makesdna/DNA_node_types.h
@@ -221,8 +221,11 @@ typedef struct bNode {
* and replacing all uses with per-instance data.
*/
short preview_xsize, preview_ysize; /* reserved size of the preview rect */
- int pad2;
+ short pad2[2];
struct uiBlock *block; /* runtime during drawing */
+
+ float ssr_id; /* XXX: eevee only, id of screen space reflection layer, needs to be a float to feed GPU_uniform. */
+ float sss_id; /* XXX: eevee only, id of screen subsurface scatter layer, needs to be a float to feed GPU_uniform. */
} bNode;
/* node->flag */
@@ -650,11 +653,6 @@ typedef struct NodeTwoFloats {
float x, y;
} NodeTwoFloats;
-typedef struct NodeGeometry {
- char uvname[64]; /* MAX_CUSTOMDATA_LAYER_NAME */
- char colname[64];
-} NodeGeometry;
-
typedef struct NodeVertexCol {
char name[64];
} NodeVertexCol;
diff --git a/source/blender/makesdna/DNA_object_enums.h b/source/blender/makesdna/DNA_object_enums.h
index 58f9e29297f..524c85948f3 100644
--- a/source/blender/makesdna/DNA_object_enums.h
+++ b/source/blender/makesdna/DNA_object_enums.h
@@ -46,4 +46,7 @@ typedef enum eObjectMode {
/* Any mode that uses Object.sculpt. */
#define OB_MODE_ALL_SCULPT (OB_MODE_SCULPT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT)
+/* Any mode that has data we need to free when switching modes, see: #ED_object_mode_generic_exit */
+#define OB_MODE_ALL_MODE_DATA (OB_MODE_EDIT | OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_SCULPT)
+
#endif /* __DNA_OBJECT_ENUMS_H__ */
diff --git a/source/blender/makesdna/DNA_object_force_types.h b/source/blender/makesdna/DNA_object_force_types.h
index 47467917315..16c96073469 100644
--- a/source/blender/makesdna/DNA_object_force_types.h
+++ b/source/blender/makesdna/DNA_object_force_types.h
@@ -112,6 +112,12 @@ typedef struct PartDeflect {
float f_noise; /* noise of force */
int seed; /* noise random seed */
+ /* Display Size */
+ float drawvec1[4]; /* Runtime only : start of the curve or draw scale */
+ float drawvec2[4]; /* Runtime only : end of the curve */
+ float drawvec_falloff_min[3], pad1; /* Runtime only */
+ float drawvec_falloff_max[3], pad2; /* Runtime only */
+
struct Object *f_source; /* force source object */
} PartDeflect;
@@ -212,59 +218,6 @@ typedef struct SBVertex {
float vec[4];
} SBVertex;
-typedef struct BulletSoftBody {
- int flag; /* various boolean options */
- float linStiff; /* linear stiffness 0..1 */
- float angStiff; /* angular stiffness 0..1 */
- float volume; /* volume preservation 0..1 */
-
- int viterations; /* Velocities solver iterations */
- int piterations; /* Positions solver iterations */
- int diterations; /* Drift solver iterations */
- int citerations; /* Cluster solver iterations */
-
- float kSRHR_CL; /* Soft vs rigid hardness [0,1] (cluster only) */
- float kSKHR_CL; /* Soft vs kinetic hardness [0,1] (cluster only) */
- float kSSHR_CL; /* Soft vs soft hardness [0,1] (cluster only) */
- float kSR_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
-
- float kSK_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- float kSS_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- float kVCF; /* Velocities correction factor (Baumgarte) */
- float kDP; /* Damping coefficient [0,1] */
-
- float kDG; /* Drag coefficient [0,+inf] */
- float kLF; /* Lift coefficient [0,+inf] */
- float kPR; /* Pressure coefficient [-inf,+inf] */
- float kVC; /* Volume conversation coefficient [0,+inf] */
-
- float kDF; /* Dynamic friction coefficient [0,1] */
- float kMT; /* Pose matching coefficient [0,1] */
- float kCHR; /* Rigid contacts hardness [0,1] */
- float kKHR; /* Kinetic contacts hardness [0,1] */
-
- float kSHR; /* Soft contacts hardness [0,1] */
- float kAHR; /* Anchors hardness [0,1] */
- int collisionflags; /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
- int numclusteriterations; /* number of iterations to refine collision clusters*/
- float welding; /* welding limit to remove duplicate/nearby vertices, 0.0..0.01 */
- float margin; /* margin specific to softbody */
-} BulletSoftBody;
-
-/* BulletSoftBody.flag */
-#define OB_BSB_SHAPE_MATCHING 2
-// #define OB_BSB_UNUSED 4
-#define OB_BSB_BENDING_CONSTRAINTS 8
-#define OB_BSB_AERO_VPOINT 16 /* aero model, Vertex normals are oriented toward velocity*/
-// #define OB_BSB_AERO_VTWOSIDE 32 /* aero model, Vertex normals are flipped to match velocity */
-
-/* BulletSoftBody.collisionflags */
-#define OB_BSB_COL_SDF_RS 2 /* SDF based rigid vs soft */
-#define OB_BSB_COL_CL_RS 4 /* Cluster based rigid vs soft */
-#define OB_BSB_COL_CL_SS 8 /* Cluster based soft vs soft */
-#define OB_BSB_COL_VF_SS 16 /* Vertex/Face based soft vs soft */
-
-
typedef struct SoftBody {
/* dynamic data */
int totpoint, totspring;
diff --git a/source/blender/makesdna/DNA_object_types.h b/source/blender/makesdna/DNA_object_types.h
index e0b4d117bd1..94187b2f2c6 100644
--- a/source/blender/makesdna/DNA_object_types.h
+++ b/source/blender/makesdna/DNA_object_types.h
@@ -67,6 +67,31 @@ typedef struct bDeformGroup {
/* need this flag for locking weights */
char flag, pad[7];
} bDeformGroup;
+
+/* Face Maps*/
+typedef struct bFaceMap {
+ struct bFaceMap *next, *prev;
+ char name[64]; /* MAX_VGROUP_NAME */
+ char flag;
+ char pad[7];
+} bFaceMap;
+
+/* Object Runtime display data */
+struct ObjectEngineData;
+typedef void (*ObjectEngineDataInitCb)(struct ObjectEngineData *engine_data);
+typedef void (*ObjectEngineDataFreeCb)(struct ObjectEngineData *engine_data);
+
+#
+#
+typedef struct ObjectEngineData {
+ struct ObjectEngineData *next, *prev;
+ struct DrawEngineType *engine_type;
+ /* Only nested data, NOT the engine data itself. */
+ ObjectEngineDataFreeCb free;
+ /* Accumulated recalc flags, which corresponds to ID->recalc flags. */
+ int recalc;
+} ObjectEngineData;
+
#define MAX_VGROUP_NAME 64
/* bDeformGroup->flag */
@@ -145,9 +170,10 @@ typedef struct Object {
ListBase effect DNA_DEPRECATED; // XXX deprecated... keep for readfile
ListBase defbase; /* list of bDeformGroup (vertex groups) names and flag only */
ListBase modifiers; /* list of ModifierData structures */
+ ListBase fmaps; /* list of facemaps */
int mode; /* Local object mode */
- int restore_mode; /* Keep track of what mode to return to after toggling a mode */
+ int restore_mode;
/* materials */
struct Material **mat; /* material slots */
@@ -186,47 +212,18 @@ typedef struct Object {
short transflag, protectflag; /* transformation settings and transform locks */
short trackflag, upflag;
short nlaflag; /* used for DopeSheet filtering settings (expanded/collapsed) */
- short scaflag; /* ui state for game logic */
- char scavisflag; /* more display settings for game logic */
- char depsflag;
+ short pad[2];
/* did last modifier stack generation need mapping support? */
char lastNeedMapping; /* bool */
- char pad;
+ char duplicator_visibility_flag;
/* dupli-frame settings */
int dupon, dupoff, dupsta, dupend;
- /* during realtime */
-
- /* note that inertia is only called inertia for historical reasons
- * and is not changed to avoid DNA surgery. It actually reflects the
- * Size value in the GameButtons (= radius) */
-
- float mass, damping, inertia;
- /* The form factor k is introduced to give the user more control
- * and to fix incompatibility problems.
- * For rotational symmetric objects, the inertia value can be
- * expressed as: Theta = k * m * r^2
- * where m = Mass, r = Radius
- * For a Sphere, the form factor is by default = 0.4
- */
-
- float formfactor;
- float rdamping;
- float margin;
- float max_vel; /* clamp the maximum velocity 0.0 is disabled */
- float min_vel; /* clamp the minimum velocity 0.0 is disabled */
- float max_angvel; /* clamp the maximum angular velocity, 0.0 is disabled */
- float min_angvel; /* clamp the minimum angular velocity, 0.0 is disabled */
- float obstacleRad;
-
- /* "Character" physics properties */
- float step_height;
- float jump_speed;
- float fall_speed;
- unsigned char max_jumps;
- char pad2[3];
+ /* Depsgraph */
+ short base_flag; /* used by depsgraph, flushed from base */
+ short pad8;
/** Collision mask settings */
unsigned short col_group, col_mask;
@@ -241,67 +238,69 @@ typedef struct Object {
char empty_drawtype;
float empty_drawsize;
float dupfacesca; /* dupliface scale */
-
- ListBase prop; /* game logic property list (not to be confused with IDProperties) */
- ListBase sensors; /* game logic sensors */
- ListBase controllers; /* game logic controllers */
- ListBase actuators; /* game logic actuators */
float sf; /* sf is time-offset */
short index; /* custom index, for renderpasses */
unsigned short actdef; /* current deformation group, note: index starts at 1 */
+ unsigned short actfmap; /* current face map, note: index starts at 1 */
+ unsigned char pad5[6];
float col[4]; /* object color */
- int gameflag;
- int gameflag2;
-
char restrictflag; /* for restricting view, select, render etc. accessible in outliner */
- char recalc; /* dependency flag */
+ char pad3;
short softflag; /* softbody settings */
- float anisotropicFriction[3];
+ int pad2;
ListBase constraints; /* object constraints */
ListBase nlastrips DNA_DEPRECATED; // XXX deprecated... old animation system
ListBase hooks DNA_DEPRECATED; // XXX deprecated... old animation system
ListBase particlesystem; /* particle systems */
- struct BulletSoftBody *bsoft; /* settings for game engine bullet soft body */
struct PartDeflect *pd; /* particle deflector/attractor/collision data */
struct SoftBody *soft; /* if exists, saved in file */
struct Group *dup_group; /* object duplicator for group */
+ void *pad10;
- char body_type; /* for now used to temporarily holds the type of collision object */
+ char pad4;
char shapeflag; /* flag for pinning */
short shapenr; /* current shape key for menu or pinned */
float smoothresh; /* smoothresh is phong interpolation ray_shadow correction in render */
struct FluidsimSettings *fluidsimSettings; /* if fluidsim enabled, store additional settings */
- /* Runtime valuated curve-specific data, not stored in the file */
- struct CurveCache *curve_cache;
-
struct DerivedMesh *derivedDeform, *derivedFinal;
+ void *pad7;
uint64_t lastDataMask; /* the custom data layer mask that was last used to calculate derivedDeform and derivedFinal */
uint64_t customdata_mask; /* (extra) custom data layer mask to use for creating derivedmesh, set by depsgraph */
- unsigned int state; /* bit masks of game controllers that are active */
- unsigned int init_state; /* bit masks of initial state as recorded by the users */
+
+ /* Runtime valuated curve-specific data, not stored in the file */
+ struct CurveCache *curve_cache;
ListBase gpulamp; /* runtime, for glsl lamp display only */
ListBase pc_ids;
- ListBase *duplilist; /* for temporary dupli list storage, only for use by RNA API */
struct RigidBodyOb *rigidbody_object; /* settings for Bullet rigid body */
struct RigidBodyCon *rigidbody_constraint; /* settings for Bullet constraint */
float ima_ofs[2]; /* offset for image empties */
ImageUser *iuser; /* must be non-null when oject is an empty image */
- void *pad3;
ListBase lodlevels; /* contains data for levels of detail */
LodLevel *currentlod;
struct PreviewImage *preview;
+
+ struct IDProperty *base_collection_properties; /* used by depsgraph, flushed from base */
+
+ ListBase drawdata; /* runtime, ObjectEngineData */
+ int pad6;
+ int select_color;
+
+ /* Mesh structure createrd during object evaluaiton.
+ * It has all modifiers applied.
+ */
+ struct Mesh *mesh_evaluated;
} Object;
/* Warning, this is not used anymore because hooks are now modifiers */
@@ -340,6 +339,7 @@ typedef struct DupliObject {
struct ParticleSystem *particle_system;
unsigned int random_id;
unsigned int pad;
+ struct IDProperty *collection_properties;
} DupliObject;
/* **************** OBJECT ********************* */
@@ -360,6 +360,7 @@ enum {
OB_CAMERA = 11,
OB_SPEAKER = 12,
+ OB_LIGHTPROBE = 13,
/* OB_WAVE = 21, */
OB_LATTICE = 22,
@@ -380,10 +381,10 @@ enum {
/* is this ID type used as object data */
#define OB_DATA_SUPPORT_ID(_id_type) \
- (ELEM(_id_type, ID_ME, ID_CU, ID_MB, ID_LA, ID_SPK, ID_CA, ID_LT, ID_AR))
+ (ELEM(_id_type, ID_ME, ID_CU, ID_MB, ID_LA, ID_SPK, ID_LP, ID_CA, ID_LT, ID_AR))
#define OB_DATA_SUPPORT_ID_CASE \
- ID_ME: case ID_CU: case ID_MB: case ID_LA: case ID_SPK: case ID_CA: case ID_LT: case ID_AR
+ ID_ME: case ID_CU: case ID_MB: case ID_LA: case ID_SPK: case ID_LP: case ID_CA: case ID_LT: case ID_AR
/* partype: first 4 bits: type */
enum {
@@ -433,8 +434,6 @@ enum {
OB_NEGZ = 5,
};
-/* gameflag in game.h */
-
/* dt: no flags */
enum {
OB_BOUNDBOX = 1,
@@ -443,8 +442,6 @@ enum {
OB_MATERIAL = 4,
OB_TEXTURE = 5,
OB_RENDER = 6,
-
- OB_PAINT = 100, /* temporary used in draw code */
};
/* dtx: flags (short) */
@@ -515,12 +512,6 @@ enum {
#define BA_TRANSFORM_CHILD (1 << 8) /* child of a transformed object */
#define BA_TRANSFORM_PARENT (1 << 13) /* parent of a transformed object */
-
-/* an initial attempt as making selection more specific! */
-#define BA_DESELECT 0
-#define BA_SELECT 1
-
-
#define OB_FROMDUPLI (1 << 9)
#define OB_DONE (1 << 10) /* unknown state, clear before use */
/* #define OB_RADIO (1 << 11) */ /* deprecated */
@@ -543,90 +534,6 @@ enum {
/* collision masks */
#define OB_MAX_COL_MASKS 16
-/* ob->gameflag */
-enum {
- OB_DYNAMIC = 1 << 0,
- OB_CHILD = 1 << 1,
- OB_ACTOR = 1 << 2,
- OB_INERTIA_LOCK_X = 1 << 3,
- OB_INERTIA_LOCK_Y = 1 << 4,
- OB_INERTIA_LOCK_Z = 1 << 5,
- OB_DO_FH = 1 << 6,
- OB_ROT_FH = 1 << 7,
- OB_ANISOTROPIC_FRICTION = 1 << 8,
- OB_GHOST = 1 << 9,
- OB_RIGID_BODY = 1 << 10,
- OB_BOUNDS = 1 << 11,
-
- OB_COLLISION_RESPONSE = 1 << 12,
- OB_SECTOR = 1 << 13,
- OB_PROP = 1 << 14,
- OB_MAINACTOR = 1 << 15,
-
- OB_COLLISION = 1 << 16,
- OB_SOFT_BODY = 1 << 17,
- OB_OCCLUDER = 1 << 18,
- OB_SENSOR = 1 << 19,
- OB_NAVMESH = 1 << 20,
- OB_HASOBSTACLE = 1 << 21,
- OB_CHARACTER = 1 << 22,
-
- OB_RECORD_ANIMATION = 1 << 23,
-};
-
-/* ob->gameflag2 */
-enum {
- OB_NEVER_DO_ACTIVITY_CULLING = 1 << 0,
- OB_LOCK_RIGID_BODY_X_AXIS = 1 << 2,
- OB_LOCK_RIGID_BODY_Y_AXIS = 1 << 3,
- OB_LOCK_RIGID_BODY_Z_AXIS = 1 << 4,
- OB_LOCK_RIGID_BODY_X_ROT_AXIS = 1 << 5,
- OB_LOCK_RIGID_BODY_Y_ROT_AXIS = 1 << 6,
- OB_LOCK_RIGID_BODY_Z_ROT_AXIS = 1 << 7,
-
-/* OB_LIFE = OB_PROP | OB_DYNAMIC | OB_ACTOR | OB_MAINACTOR | OB_CHILD, */
-};
-
-/* ob->body_type */
-enum {
- OB_BODY_TYPE_NO_COLLISION = 0,
- OB_BODY_TYPE_STATIC = 1,
- OB_BODY_TYPE_DYNAMIC = 2,
- OB_BODY_TYPE_RIGID = 3,
- OB_BODY_TYPE_SOFT = 4,
- OB_BODY_TYPE_OCCLUDER = 5,
- OB_BODY_TYPE_SENSOR = 6,
- OB_BODY_TYPE_NAVMESH = 7,
- OB_BODY_TYPE_CHARACTER = 8,
-};
-
-/* ob->depsflag */
-enum {
- OB_DEPS_EXTRA_OB_RECALC = 1 << 0,
- OB_DEPS_EXTRA_DATA_RECALC = 1 << 1,
-};
-
-/* ob->scavisflag */
-enum {
- OB_VIS_SENS = 1 << 0,
- OB_VIS_CONT = 1 << 1,
- OB_VIS_ACT = 1 << 2,
-};
-
-/* ob->scaflag */
-enum {
- OB_SHOWSENS = 1 << 6,
- OB_SHOWACT = 1 << 7,
- OB_ADDSENS = 1 << 8,
- OB_ADDCONT = 1 << 9,
- OB_ADDACT = 1 << 10,
- OB_SHOWCONT = 1 << 11,
- OB_ALLSTATE = 1 << 12,
- OB_INITSTBIT = 1 << 13,
- OB_DEBUGSTATE = 1 << 14,
- OB_SHOWSTATE = 1 << 15,
-};
-
/* ob->restrictflag */
enum {
OB_RESTRICT_VIEW = 1 << 0,
@@ -673,7 +580,13 @@ enum {
OB_LOCK_ROTW = 1 << 9,
OB_LOCK_ROT4D = 1 << 10,
};
-
+
+/* ob->duplicator_visibility_flag */
+enum {
+ OB_DUPLI_FLAG_VIEWPORT = 1 << 0,
+ OB_DUPLI_FLAG_RENDER = 1 << 1,
+};
+
#define MAX_DUPLI_RECUR 8
#ifdef __cplusplus
diff --git a/source/blender/makesdna/DNA_outliner_types.h b/source/blender/makesdna/DNA_outliner_types.h
index 984e3334414..b968bcebeb5 100644
--- a/source/blender/makesdna/DNA_outliner_types.h
+++ b/source/blender/makesdna/DNA_outliner_types.h
@@ -38,6 +38,9 @@ struct ID;
typedef struct TreeStoreElem {
short type, nr, flag, used;
+
+ /* XXX We actually also store non-ID data in this pointer for identifying
+ * the TreeStoreElem for a TreeElement when rebuilding the tree. Ugly! */
struct ID *id;
} TreeStoreElem;
@@ -50,11 +53,14 @@ typedef struct TreeStore {
} TreeStore;
/* TreeStoreElem->flag */
-#define TSE_CLOSED 1
-#define TSE_SELECTED 2
-#define TSE_TEXTBUT 4
-#define TSE_CHILDSEARCH 8
-#define TSE_SEARCHMATCH 16
+enum {
+ TSE_CLOSED = (1 << 0),
+ TSE_SELECTED = (1 << 1),
+ TSE_TEXTBUT = (1 << 2),
+ TSE_CHILDSEARCH = (1 << 3),
+ TSE_SEARCHMATCH = (1 << 4),
+ TSE_HIGHLIGHTED = (1 << 5),
+};
/* TreeStoreElem->types */
#define TSE_NLA 1 /* NO ID */
@@ -78,7 +84,7 @@ typedef struct TreeStore {
#define TSE_PROXY 18
#define TSE_R_LAYER_BASE 19
#define TSE_R_LAYER 20
-#define TSE_R_PASS 21
+/* #define TSE_R_PASS 21 */ /* UNUSED */
#define TSE_LINKED_MAT 22
/* NOTE, is used for light group */
#define TSE_LINKED_LAMP 23
@@ -96,6 +102,10 @@ typedef struct TreeStore {
#define TSE_KEYMAP_ITEM 35 /* NO ID */
#define TSE_ID_BASE 36 /* NO ID */
#define TSE_GP_LAYER 37 /* NO ID */
+#define TSE_LAYER_COLLECTION 38
+#define TSE_SCENE_COLLECTION 39
+#define TSE_LAYER_COLLECTION_BASE 40
+#define TSE_SCENE_OBJECTS_BASE 41
/* Check whether given TreeStoreElem should have a real ID in its ->id member. */
diff --git a/source/blender/makesdna/DNA_particle_types.h b/source/blender/makesdna/DNA_particle_types.h
index 9dbd1a18703..2c330501820 100644
--- a/source/blender/makesdna/DNA_particle_types.h
+++ b/source/blender/makesdna/DNA_particle_types.h
@@ -166,8 +166,9 @@ typedef struct ParticleSettings {
short type, from, distr, texact;
/* physics modes */
short phystype, rotmode, avemode, reactevent;
- int draw, pad1;
- short draw_as, draw_size, childtype, pad2;
+ int draw;
+ float draw_size;
+ short draw_as, pad1, childtype, pad2;
short ren_as, subframes, draw_col;
/* number of path segments, power of 2 except */
short draw_step, ren_step;
@@ -187,11 +188,6 @@ typedef struct ParticleSettings {
/* draw color */
float color_vec_max;
- /* simplification */
- short simplify_flag, simplify_refsize;
- float simplify_rate, simplify_transition;
- float simplify_viewport;
-
/* time and emission */
float sta, end, lifetime, randlife;
float timetweak, courant_target;
@@ -259,7 +255,9 @@ typedef struct ParticleSettings {
/* modified dm support */
short use_modifier_stack;
- short pad5[3];
+
+ short pad5;
+ int pad8;
float twist;
float pad6;
@@ -310,9 +308,6 @@ typedef struct ParticleSystem {
short vgroup[13], vg_neg, rt3; /* vertex groups, 0==disable, 1==starting index */
char pad[6];
- /* temporary storage during render */
- struct ParticleRenderData *renderdata;
-
/* point cache */
struct PointCache *pointcache;
struct ListBase ptcaches;
@@ -329,6 +324,8 @@ typedef struct ParticleSystem {
float dt_frac; /* current time step, as a fraction of a frame */
float lattice_strength; /* influence of the lattice modifier */
+
+ void *batch_cache;
} ParticleSystem;
typedef enum eParticleDrawFlag {
diff --git a/source/blender/makesdna/DNA_property_types.h b/source/blender/makesdna/DNA_property_types.h
deleted file mode 100644
index 77cd7c3e102..00000000000
--- a/source/blender/makesdna/DNA_property_types.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file DNA_property_types.h
- * \ingroup DNA
- * \since mar-2001
- * \author nzc
- * \attention Renderrecipe and scene decription. The fact that there is a
- * hierarchy here is a bit strange, and not desirable.
- *
- * #bProperty type is specifically for use by Objects game-logic.
- */
-
-#ifndef __DNA_PROPERTY_TYPES_H__
-#define __DNA_PROPERTY_TYPES_H__
-
-/* ********************* PROPERTY ************************ */
-
-typedef struct bProperty {
- struct bProperty *next, *prev;
- char name[64]; /* MAX_NAME */
- short type, flag;
- int data; /* data should be 4 bytes to store int,float stuff */
- void *poin; /* references data unless its a string which is malloc'd */
-
-} bProperty;
-
-/* property->type XXX Game Property, not RNA */
-#define GPROP_BOOL 0
-#define GPROP_INT 1
-#define GPROP_FLOAT 2
-#define GPROP_STRING 3
-// #define GPROP_VECTOR 4 // UNUSED
-#define GPROP_TIME 5
-
-/* property->flag */
-#define PROP_DEBUG 1
-
-#define MAX_PROPSTRING 128
-
-#endif /* __DNA_PROPERTY_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_scene_types.h b/source/blender/makesdna/DNA_scene_types.h
index d2b71c727c5..2f3d5a82730 100644
--- a/source/blender/makesdna/DNA_scene_types.h
+++ b/source/blender/makesdna/DNA_scene_types.h
@@ -47,6 +47,8 @@ extern "C" {
#include "DNA_ID.h"
#include "DNA_freestyle_types.h"
#include "DNA_gpu_types.h"
+#include "DNA_layer_types.h"
+#include "DNA_material_types.h"
#include "DNA_userdef_types.h"
struct CurveMapping;
@@ -65,19 +67,11 @@ struct bGPdata;
struct bGPDbrush;
struct MovieClip;
struct ColorSpace;
+struct SceneCollection;
/* ************************************************************* */
/* Scene Data */
-/* Base - Wrapper for referencing Objects in a Scene */
-typedef struct Base {
- struct Base *next, *prev;
- unsigned int lay, selcol;
- int flag;
- short sx, sy;
- struct Object *object;
-} Base;
-
/* ************************************************************* */
/* Output Format Data */
@@ -189,27 +183,25 @@ typedef struct AudioData {
typedef struct SceneRenderLayer {
struct SceneRenderLayer *next, *prev;
- char name[64]; /* MAX_NAME */
+ char name[64] DNA_DEPRECATED; /* MAX_NAME */
- struct Material *mat_override;
- struct Group *light_override;
+ struct Material *mat_override DNA_DEPRECATED; /* Converted to ViewLayer override. */
- unsigned int lay; /* Scene.lay itself has priority over this */
- unsigned int lay_zmask; /* has to be after lay, this is for Z-masking */
- unsigned int lay_exclude; /* not used by internal, exclude */
- int layflag;
+ unsigned int lay DNA_DEPRECATED; /* Converted to LayerCollection cycles camera visibility override. */
+ unsigned int lay_zmask DNA_DEPRECATED; /* Converted to LayerCollection cycles holdout override. */
+ unsigned int lay_exclude DNA_DEPRECATED;
+ int layflag DNA_DEPRECATED; /* Converted to ViewLayer layflag and flag. */
/* pass_xor has to be after passflag */
- /* note, this is treestore element 'nr' in outliner, short still... */
- int passflag;
- int pass_xor;
+ int passflag DNA_DEPRECATED; /* pass_xor has to be after passflag */
+ int pass_xor DNA_DEPRECATED; /* Converted to ViewLayer passflag and flag. */
- int samples;
- float pass_alpha_threshold;
+ int samples DNA_DEPRECATED; /* Converted to ViewLayer override. */
+ float pass_alpha_threshold DNA_DEPRECATED; /* Converted to ViewLayer pass_alpha_threshold. */
- IDProperty *prop;
+ IDProperty *prop DNA_DEPRECATED; /* Converted to ViewLayer id_properties. */
- struct FreestyleConfig freestyleConfig;
+ struct FreestyleConfig freestyleConfig DNA_DEPRECATED; /* Converted to ViewLayer freestyleConfig. */
} SceneRenderLayer;
/* SceneRenderLayer.layflag */
@@ -555,6 +547,12 @@ typedef enum eBakePassFilter {
#define R_BAKE_PASS_FILTER_ALL (~0)
+/* RenderEngineSettingsClay.options */
+typedef enum ClayFlagSettings {
+ CLAY_USE_AO = (1 << 0),
+ CLAY_USE_HSV = (1 << 1),
+} ClayFlagSettings;
+
/* *************************************************************** */
/* Render Data */
@@ -573,29 +571,14 @@ typedef struct RenderData {
float framelen, blurfac;
- /** For UR edge rendering: give the edges this color */
- float edgeR, edgeG, edgeB;
-
-
- /* standalone player */ // XXX deprecated since 2.5
- short fullscreen DNA_DEPRECATED, xplay DNA_DEPRECATED, yplay DNA_DEPRECATED;
- short freqplay DNA_DEPRECATED;
- /* standalone player */ // XXX deprecated since 2.5
- short depth DNA_DEPRECATED, attrib DNA_DEPRECATED;
-
-
int frame_step; /* frames to jump during render/playback */
short stereomode DNA_DEPRECATED; /* standalone player stereo settings */ // XXX deprecated since 2.5
short dimensionspreset; /* for the dimensions presets menu */
- short filtertype; /* filter is box, tent, gauss, mitch, etc */
-
short size; /* size in % */
- short maximsize DNA_DEPRECATED; /* max in Kb */
-
short pad6;
/* from buttons: */
@@ -609,15 +592,6 @@ typedef struct RenderData {
int ysch;
/**
- * The number of part to use in the x direction
- */
- short xparts DNA_DEPRECATED;
- /**
- * The number of part to use in the y direction
- */
- short yparts DNA_DEPRECATED;
-
- /**
* render tile dimensions
*/
int tilex, tiley;
@@ -642,22 +616,6 @@ typedef struct RenderData {
int mode;
/**
- * Flags for raytrace settings. Use bit-masking to access the settings.
- */
- int raytrace_options;
-
- /**
- * Raytrace acceleration structure
- */
- short raytrace_structure;
-
- short pad1;
-
- /* octree resolution */
- short ocres;
- short pad4;
-
- /**
* What to do with the sky/background. Picks sky/premul/key
* blending for the background
*/
@@ -668,7 +626,7 @@ typedef struct RenderData {
*/
short osa;
- short frs_sec, edgeint;
+ short frs_sec, pad[7];
/* safety, border and display rect */
@@ -676,11 +634,9 @@ typedef struct RenderData {
rcti disprect;
/* information on different layers to be rendered */
- ListBase layers;
- short actlay;
-
- /* number of mblur samples */
- short mblur_samples;
+ ListBase layers DNA_DEPRECATED; /* Converted to Scene->view_layers. */
+ short actlay DNA_DEPRECATED; /* Converted to Scene->active_layer. */
+ short pad1;
/**
* Adjustment factors for the aspect ratio in the x direction, was a short in 2.45
@@ -697,18 +653,13 @@ typedef struct RenderData {
/* color management settings - color profiles, gamma correction, etc */
int color_mgt_flag;
- /** post-production settings. deprecated, but here for upwards compat (initialized to 1) */
- float postgamma, posthue, postsat;
-
/* Dither noise intensity */
float dither_intensity;
/* Bake Render options */
- short bake_osa, bake_filter, bake_mode, bake_flag;
- short bake_normal_space, bake_quad_split;
- float bake_maxdist, bake_biasdist;
- short bake_samples, bake_pad;
- float bake_user_scale, bake_pad1;
+ short bake_mode, bake_flag;
+ short bake_filter, bake_samples;
+ float bake_biasdist, bake_user_scale;
/* path to render output */
char pic[1024]; /* 1024 = FILE_MAX */
@@ -731,28 +682,11 @@ typedef struct RenderData {
char pad5[5];
/* render simplify */
- int simplify_flag;
short simplify_subsurf;
short simplify_subsurf_render;
- short simplify_shadowsamples, pad9;
+ short pad9, pad10;
float simplify_particles;
float simplify_particles_render;
- float simplify_aosss;
-
- /* cineon */
- short cineonwhite DNA_DEPRECATED, cineonblack DNA_DEPRECATED; /*deprecated*/
- float cineongamma DNA_DEPRECATED; /*deprecated*/
-
- /* jpeg2000 */
- short jp2_preset DNA_DEPRECATED, jp2_depth DNA_DEPRECATED; /*deprecated*/
- int rpad3;
-
- /* Dome variables */ // XXX deprecated since 2.5
- short domeres DNA_DEPRECATED, domemode DNA_DEPRECATED; // XXX deprecated since 2.5
- short domeangle DNA_DEPRECATED, dometilt DNA_DEPRECATED; // XXX deprecated since 2.5
- float domeresbuf DNA_DEPRECATED; // XXX deprecated since 2.5
- float pad2;
- struct Text *dometext DNA_DEPRECATED; // XXX deprecated since 2.5
/* Freestyle line thickness options */
int line_thickness_mode;
@@ -760,6 +694,7 @@ typedef struct RenderData {
/* render engine */
char engine[32];
+ int pad2;
/* Cycles baking */
struct BakeData bake;
@@ -799,180 +734,6 @@ typedef struct RenderProfile {
} RenderProfile;
-/* *************************************************************** */
-/* Game Engine - Dome */
-
-typedef struct GameDome {
- short res, mode;
- short angle, tilt;
- float resbuf, pad2;
- struct Text *warptext;
-} GameDome;
-
-/* GameDome.mode */
-#define DOME_FISHEYE 1
-#define DOME_TRUNCATED_FRONT 2
-#define DOME_TRUNCATED_REAR 3
-#define DOME_ENVMAP 4
-#define DOME_PANORAM_SPH 5
-#define DOME_NUM_MODES 6
-
-/* *************************************************************** */
-/* Game Engine */
-
-typedef struct GameFraming {
- float col[3];
- char type, pad1, pad2, pad3;
-} GameFraming;
-
-/* GameFraming.type */
-#define SCE_GAMEFRAMING_BARS 0
-#define SCE_GAMEFRAMING_EXTEND 1
-#define SCE_GAMEFRAMING_SCALE 2
-
-typedef struct RecastData {
- float cellsize;
- float cellheight;
- float agentmaxslope;
- float agentmaxclimb;
- float agentheight;
- float agentradius;
- float edgemaxlen;
- float edgemaxerror;
- float regionminsize;
- float regionmergesize;
- int vertsperpoly;
- float detailsampledist;
- float detailsamplemaxerror;
- char partitioning;
- char pad1;
- short pad2;
-} RecastData;
-
-/* RecastData.partitioning */
-#define RC_PARTITION_WATERSHED 0
-#define RC_PARTITION_MONOTONE 1
-#define RC_PARTITION_LAYERS 2
-
-typedef struct GameData {
-
- /* standalone player */
- struct GameFraming framing;
- short playerflag, xplay, yplay, freqplay;
- short depth, attrib, rt1, rt2;
- short aasamples, pad4[3];
-
- /* stereo/dome mode */
- struct GameDome dome;
- short stereoflag, stereomode;
- float eyeseparation;
- RecastData recastData;
-
-
- /* physics (it was in world)*/
- float gravity; /*Gravitation constant for the game world*/
-
- /*
- * Radius of the activity bubble, in Manhattan length. Objects
- * outside the box are activity-culled. */
- float activityBoxRadius;
-
- /*
- * bit 3: (gameengine): Activity culling is enabled.
- * bit 5: (gameengine) : enable Bullet DBVT tree for view frustum culling
- */
- int flag;
- short mode, matmode;
- short occlusionRes; /* resolution of occlusion Z buffer in pixel */
- short physicsEngine;
- short exitkey;
- short vsync; /* Controls vsync: off, on, or adaptive (if supported) */
- short ticrate, maxlogicstep, physubstep, maxphystep;
- short obstacleSimulation;
- short raster_storage;
- float levelHeight;
- float deactivationtime, lineardeactthreshold, angulardeactthreshold;
-
- /* Scene LoD */
- short lodflag, pad2;
- int scehysteresis, pad5;
-
-} GameData;
-
-/* GameData.stereoflag */
-#define STEREO_NOSTEREO 1
-#define STEREO_ENABLED 2
-#define STEREO_DOME 3
-
-/* GameData.stereomode */
-//#define STEREO_NOSTEREO 1
-#define STEREO_QUADBUFFERED 2
-#define STEREO_ABOVEBELOW 3
-#define STEREO_INTERLACED 4
-#define STEREO_ANAGLYPH 5
-#define STEREO_SIDEBYSIDE 6
-#define STEREO_VINTERLACE 7
-//#define STEREO_DOME 8
-#define STEREO_3DTVTOPBOTTOM 9
-
-/* GameData.physicsEngine */
-#define WOPHY_NONE 0
-#define WOPHY_BULLET 5
-
-/* obstacleSimulation */
-#define OBSTSIMULATION_NONE 0
-#define OBSTSIMULATION_TOI_rays 1
-#define OBSTSIMULATION_TOI_cells 2
-
-/* GameData.raster_storage */
-#define RAS_STORE_AUTO 0
-/* #define RAS_STORE_IMMEDIATE 1 */ /* DEPRECATED */
-#define RAS_STORE_VA 2
-#define RAS_STORE_VBO 3
-
-/* GameData.vsync */
-#define VSYNC_ON 0
-#define VSYNC_OFF 1
-#define VSYNC_ADAPTIVE 2
-
-/* GameData.flag */
-#define GAME_RESTRICT_ANIM_UPDATES (1 << 0)
-#define GAME_ENABLE_ALL_FRAMES (1 << 1)
-#define GAME_SHOW_DEBUG_PROPS (1 << 2)
-#define GAME_SHOW_FRAMERATE (1 << 3)
-#define GAME_SHOW_PHYSICS (1 << 4)
-#define GAME_DISPLAY_LISTS (1 << 5)
-#define GAME_GLSL_NO_LIGHTS (1 << 6)
-#define GAME_GLSL_NO_SHADERS (1 << 7)
-#define GAME_GLSL_NO_SHADOWS (1 << 8)
-#define GAME_GLSL_NO_RAMPS (1 << 9)
-#define GAME_GLSL_NO_NODES (1 << 10)
-#define GAME_GLSL_NO_EXTRA_TEX (1 << 11)
-#define GAME_IGNORE_DEPRECATION_WARNINGS (1 << 12)
-#define GAME_ENABLE_ANIMATION_RECORD (1 << 13)
-#define GAME_SHOW_MOUSE (1 << 14)
-#define GAME_GLSL_NO_COLOR_MANAGEMENT (1 << 15)
-#define GAME_SHOW_OBSTACLE_SIMULATION (1 << 16)
-#define GAME_NO_MATERIAL_CACHING (1 << 17)
-#define GAME_GLSL_NO_ENV_LIGHTING (1 << 18)
-/* Note: GameData.flag is now an int (max 32 flags). A short could only take 16 flags */
-
-/* GameData.playerflag */
-#define GAME_PLAYER_FULLSCREEN (1 << 0)
-#define GAME_PLAYER_DESKTOP_RESOLUTION (1 << 1)
-
-/* GameData.matmode */
-enum {
-#ifdef DNA_DEPRECATED
- GAME_MAT_TEXFACE = 0, /* deprecated */
-#endif
- GAME_MAT_MULTITEX = 1,
- GAME_MAT_GLSL = 2,
-};
-
-/* GameData.lodflag */
-#define SCE_LOD_USE_HYST (1 << 0)
-
/* UV Paint */
/* ToolSettings.uv_sculpt_settings */
#define UV_SCULPT_LOCK_BORDERS 1
@@ -1268,17 +1029,6 @@ typedef enum eGP_Interpolate_Type {
GP_IPO_SINE = 12,
} eGP_Interpolate_Type;
-
-/* *************************************************************** */
-/* Transform Orientations */
-
-typedef struct TransformOrientation {
- struct TransformOrientation *next, *prev;
- char name[64]; /* MAX_NAME */
- float mat[3][3];
- int pad;
-} TransformOrientation;
-
/* *************************************************************** */
/* Unified Paint Settings
*/
@@ -1458,7 +1208,6 @@ typedef struct ToolSettings {
float vgroup_weight;
float doublimit; /* remove doubles limit */
- float normalsize; /* size of normals */
short automerge;
/* Selection Mode for Mesh */
@@ -1483,6 +1232,8 @@ typedef struct ToolSettings {
char gpencil_v2d_align; /* : General 2D Editor */
char gpencil_seq_align; /* : Sequencer Preview */
char gpencil_ima_align; /* : Image Editor */
+
+ char _pad3[4];
/* Grease Pencil Sculpt */
struct GP_BrushEdit_Settings gp_sculpt;
@@ -1512,37 +1263,10 @@ typedef struct ToolSettings {
/* Multires */
char multires_subdiv_type;
- /* Skeleton generation */
- short skgen_resolution;
- float skgen_threshold_internal;
- float skgen_threshold_external;
- float skgen_length_ratio;
- float skgen_length_limit;
- float skgen_angle_limit;
- float skgen_correlation_limit;
- float skgen_symmetry_limit;
- float skgen_retarget_angle_weight;
- float skgen_retarget_length_weight;
- float skgen_retarget_distance_weight;
- short skgen_options;
- char skgen_postpro;
- char skgen_postpro_passes;
- char skgen_subdivisions[3];
- char skgen_multi_level;
-
- /* Skeleton Sketching */
- struct Object *skgen_template;
- char bone_sketching;
- char bone_sketching_convert;
- char skgen_subdivision_number;
- char skgen_retarget_options;
- char skgen_retarget_roll;
- char skgen_side_string[8];
- char skgen_num_string[8];
-
/* Alt+RMB option */
char edge_mode;
char edge_mode_live_unwrap;
+ char _pad1;
/* Transform */
char snap_mode, snap_node_mode;
@@ -1562,10 +1286,11 @@ typedef struct ToolSettings {
char vgroupsubset; /* subset selection filter in wpaint */
/* UV painting */
- int use_uv_sculpt;
- int uv_sculpt_settings;
- int uv_sculpt_tool;
- int uv_relax_method;
+ char _pad2[2];
+ char use_uv_sculpt;
+ char uv_sculpt_settings;
+ char uv_sculpt_tool;
+ char uv_relax_method;
/* XXX: these sculpt_paint_* fields are deprecated, use the
* unified_paint_settings field instead! */
short sculpt_paint_settings DNA_DEPRECATED; short pad5;
@@ -1639,9 +1364,9 @@ typedef struct Scene {
struct Scene *set;
- ListBase base;
- struct Base *basact; /* active base */
- struct Object *obedit; /* name replaces old G.obedit */
+ ListBase base DNA_DEPRECATED;
+ struct Base *basact DNA_DEPRECATED; /* active base */
+ void *_pad1;
float cursor[3]; /* 3d cursor location */
char _pad[4];
@@ -1660,17 +1385,20 @@ typedef struct Scene {
struct Editing *ed; /* sequence editor data is allocated here */
struct ToolSettings *toolsettings; /* default allocated now */
- struct SceneStats *stats; /* default allocated now */
+ void *pad2;
struct DisplaySafeAreas safe_areas;
/* migrate or replace? depends on some internal things... */
/* no, is on the right place (ton) */
struct RenderData r;
struct AudioData audio;
-
+
ListBase markers;
ListBase transform_spaces;
-
+
+ int orientation_index_custom;
+ int orientation_type;
+
void *sound_scene;
void *playback_handle;
void *sound_scrub_handle;
@@ -1679,19 +1407,12 @@ typedef struct Scene {
void *fps_info; /* (runtime) info/cache used for presenting playback framerate info to the user */
/* none of the dependency graph vars is mean to be saved */
- struct Depsgraph *depsgraph;
- void *pad1;
- struct DagForest *theDag;
- short dagflags;
- short pad3;
+ struct GHash *depsgraph_hash;
+ int pad7;
/* User-Defined KeyingSets */
int active_keyingset; /* index of the active KeyingSet. first KeyingSet has index 1, 'none' active is 0, 'add new' is -1 */
ListBase keyingsets; /* KeyingSets for this scene */
-
- /* Game Settings */
- struct GameFraming framing DNA_DEPRECATED; // XXX deprecated since 2.5
- struct GameData gm;
/* Units */
struct UnitSettings unit;
@@ -1717,6 +1438,12 @@ typedef struct Scene {
struct RigidBodyWorld *rigidbody_world;
struct PreviewImage *preview;
+
+ ListBase view_layers;
+ struct SceneCollection *collection;
+
+ IDProperty *collection_properties; /* settings to be overriden by layer collections */
+ IDProperty *layer_properties; /* settings to be override by workspaces */
} Scene;
/* **************** RENDERDATA ********************* */
@@ -1730,25 +1457,25 @@ typedef struct Scene {
/* RenderData.mode */
#define R_OSA 0x0001
-#define R_SHADOW 0x0002
-#define R_GAMMA 0x0004
-#define R_ORTHO 0x0008
-#define R_ENVMAP 0x0010
-#define R_EDGE 0x0020
-#define R_FIELDS 0x0040
-#define R_FIELDSTILL 0x0080
+/* #define R_SHADOW 0x0002 */
+/* #define R_GAMMA 0x0004 */
+#define R_ORTHO 0x0008
+/* #define R_ENVMAP 0x0010 */
+/* #define R_EDGE 0x0020 */
+/* #define R_FIELDS 0x0040 */
+/*#define R_FIELDSTILL 0x0080 */
/*#define R_RADIO 0x0100 */ /* deprecated */
#define R_BORDER 0x0200
-#define R_PANORAMA 0x0400 /* deprecated as scene option, still used in renderer */
+#define R_PANORAMA 0x0400
#define R_CROP 0x0800
/* Disable camera switching: runtime (DURIAN_CAMERA_SWITCH) */
#define R_NO_CAMERA_SWITCH 0x1000
-#define R_ODDFIELD 0x2000
+/* #define R_ODDFIELD 0x2000 */
#define R_MBLUR 0x4000
/* unified was here */
-#define R_RAYTRACE 0x10000
+/* #define R_RAYTRACE 0x10000 */
/* R_GAUSS is obsolete, but used to retrieve setting from old files */
-#define R_GAUSS 0x20000
+/* #define R_GAUSS 0x20000 */
/* fbuf obsolete... */
/*#define R_FBUF 0x40000*/
/* threads obsolete... is there for old files, now use for autodetect threads */
@@ -1756,14 +1483,14 @@ typedef struct Scene {
/* Use the same flag for autothreads */
#define R_FIXED_THREADS 0x80000
-#define R_SPEED 0x100000
-#define R_SSS 0x200000
+/* #define R_SPEED 0x100000 */
+/* #define R_SSS 0x200000 */
#define R_NO_OVERWRITE 0x400000 /* skip existing files */
#define R_TOUCH 0x800000 /* touch files before rendering */
#define R_SIMPLIFY 0x1000000
#define R_EDGE_FRS 0x2000000 /* R_EDGE reserved for Freestyle */
#define R_PERSISTENT_DATA 0x4000000 /* keep data around for re-render */
-#define R_USE_WS_SHADING 0x8000000 /* use world space interpretation of lighting data */
+/* #define R_USE_WS_SHADING 0x8000000 */ /* use world space interpretation of lighting data */
/* RenderData.seq_flag */
enum {
@@ -1780,7 +1507,7 @@ enum {
#define R_OUTPUT_NONE 3
/*#define R_OUTPUT_FORKED 4*/
-/* RenderData.filtertype */
+/* RenderData.filtertype (used for nodes) */
#define R_FILTER_BOX 0
#define R_FILTER_TENT 1
#define R_FILTER_QUAD 2
@@ -1788,19 +1515,7 @@ enum {
#define R_FILTER_CATROM 4
#define R_FILTER_GAUSS 5
#define R_FILTER_MITCH 6
-#define R_FILTER_FAST_GAUSS 7 /* note, this is only used for nodes at the moment */
-
-/* RenderData.raytrace_structure */
-#define R_RAYSTRUCTURE_AUTO 0
-#define R_RAYSTRUCTURE_OCTREE 1
-#define R_RAYSTRUCTURE_BLIBVH 2 /* removed */
-#define R_RAYSTRUCTURE_VBVH 3
-#define R_RAYSTRUCTURE_SIMD_SVBVH 4 /* needs SIMD */
-#define R_RAYSTRUCTURE_SIMD_QBVH 5 /* needs SIMD */
-
-/* RenderData.raytrace_options */
-#define R_RAYTRACE_USE_LOCAL_COORDS 0x0001
-#define R_RAYTRACE_USE_INSTANCES 0x0002
+#define R_FILTER_FAST_GAUSS 7
/* RenderData.scemode (int now) */
#define R_DOSEQ 0x0001
@@ -1812,12 +1527,12 @@ enum {
#define R_MATNODE_PREVIEW 0x0020
#define R_DOCOMP 0x0040
#define R_COMP_CROP 0x0080
-#define R_FREE_IMAGE 0x0100
+/* #define R_FREE_IMAGE 0x0100 */
#define R_SINGLE_LAYER 0x0200
#define R_EXR_TILE_FILE 0x0400
/* #define R_COMP_FREE 0x0800 */
#define R_NO_IMAGE_LOAD 0x1000
-#define R_NO_TEX 0x2000
+/* #define R_NO_TEX 0x2000 */
#define R_NO_FRAME_UPDATE 0x4000
#define R_FULL_SAMPLE 0x8000
/* #define R_DEPRECATED 0x10000 */
@@ -1880,12 +1595,12 @@ enum {
/* bake_mode: same as RE_BAKE_xxx defines */
/* RenderData.bake_flag */
#define R_BAKE_CLEAR 1
-#define R_BAKE_OSA 2
+/* #define R_BAKE_OSA 2 */ /* deprecated */
#define R_BAKE_TO_ACTIVE 4
-#define R_BAKE_NORMALIZE 8
+/* #define R_BAKE_NORMALIZE 8 */ /* deprecated */
#define R_BAKE_MULTIRES 16
#define R_BAKE_LORES_MESH 32
-#define R_BAKE_VCOL 64
+/* #define R_BAKE_VCOL 64 */ /* deprecated */
#define R_BAKE_USERSCALE 128
#define R_BAKE_CAGE 256
#define R_BAKE_SPLIT_MAT 512
@@ -1897,9 +1612,6 @@ enum {
#define R_BAKE_SPACE_OBJECT 2
#define R_BAKE_SPACE_TANGENT 3
-/* RenderData.simplify_flag */
-#define R_SIMPLE_NO_TRIANGULATE 1
-
/* RenderData.line_thickness_mode */
#define R_LINE_THICKNESS_ABSOLUTE 1
#define R_LINE_THICKNESS_RELATIVE 2
@@ -1907,8 +1619,9 @@ enum {
/* sequencer seq_prev_type seq_rend_type */
/* RenderData.engine (scene.c) */
-extern const char *RE_engine_id_BLENDER_RENDER;
-extern const char *RE_engine_id_BLENDER_GAME;
+extern const char *RE_engine_id_BLENDER_CLAY;
+extern const char *RE_engine_id_BLENDER_EEVEE;
+extern const char *RE_engine_id_BLENDER_WORKBENCH;
extern const char *RE_engine_id_CYCLES;
/* **************** SCENE ********************* */
@@ -1927,39 +1640,37 @@ extern const char *RE_engine_id_CYCLES;
#define MINAFRAME -1048574
#define MINAFRAMEF -1048574.0f
-/* depricate this! */
-#define TESTBASE(v3d, base) ( \
- ((base)->flag & SELECT) && \
- ((base)->lay & v3d->lay) && \
- (((base)->object->restrictflag & OB_RESTRICT_VIEW) == 0))
-#define TESTBASELIB(v3d, base) ( \
- ((base)->flag & SELECT) && \
- ((base)->lay & v3d->lay) && \
+/* deprecate this! */
+#define TESTBASE(base) ( \
+ (((base)->flag & BASE_SELECTED) != 0) && \
+ (((base)->flag & BASE_VISIBLED) != 0))
+#define TESTBASELIB(base) ( \
+ (((base)->flag & BASE_SELECTED) != 0) && \
((base)->object->id.lib == NULL) && \
- (((base)->object->restrictflag & OB_RESTRICT_VIEW) == 0))
-#define TESTBASELIB_BGMODE(v3d, scene, base) ( \
- ((base)->flag & SELECT) && \
- ((base)->lay & (v3d ? v3d->lay : scene->lay)) && \
+ (((base)->flag & BASE_VISIBLED) != 0))
+#define TESTBASELIB_BGMODE(base) ( \
+ (((base)->flag & BASE_SELECTED) != 0) && \
((base)->object->id.lib == NULL) && \
- (((base)->object->restrictflag & OB_RESTRICT_VIEW) == 0))
-#define BASE_EDITABLE_BGMODE(v3d, scene, base) ( \
- ((base)->lay & (v3d ? v3d->lay : scene->lay)) && \
+ (((base)->flag & BASE_VISIBLED) != 0))
+#define BASE_EDITABLE_BGMODE(base) ( \
((base)->object->id.lib == NULL) && \
- (((base)->object->restrictflag & OB_RESTRICT_VIEW) == 0))
-#define BASE_SELECTABLE(v3d, base) ( \
- (base->lay & v3d->lay) && \
- (base->object->restrictflag & (OB_RESTRICT_SELECT | OB_RESTRICT_VIEW)) == 0)
-#define BASE_VISIBLE(v3d, base) ( \
- (base->lay & v3d->lay) && \
- (base->object->restrictflag & OB_RESTRICT_VIEW) == 0)
-#define BASE_VISIBLE_BGMODE(v3d, scene, base) ( \
- (base->lay & (v3d ? v3d->lay : scene->lay)) && \
- (base->object->restrictflag & OB_RESTRICT_VIEW) == 0)
-
-#define FIRSTBASE scene->base.first
-#define LASTBASE scene->base.last
-#define BASACT (scene->basact)
-#define OBACT (BASACT ? BASACT->object: NULL)
+ (((base)->flag & BASE_VISIBLED) != 0))
+#define BASE_SELECTABLE(base) \
+ (((base)->flag & BASE_SELECTABLED) != 0)
+#define BASE_VISIBLE(base) ( \
+ ((base)->flag & BASE_VISIBLED) != 0)
+
+#define FIRSTBASE(_view_layer) ((_view_layer)->object_bases.first)
+#define LASTBASE(_view_layer) ((_view_layer)->object_bases.last)
+#define BASACT(_view_layer) ((_view_layer)->basact)
+#define OBACT(_view_layer) (BASACT(_view_layer) ? BASACT(_view_layer)->object: NULL)
+
+#define OBEDIT_FROM_WORKSPACE(workspace, _view_layer) \
+ (((workspace)->object_mode & OD_MODE_EDIT) ? OBACT(_view_layer) : NULL)
+#define OBEDIT_FROM_OBACT(ob) \
+ ((ob) ? (((ob)->mode & OB_MODE_EDIT) ? ob : NULL) : NULL)
+#define OBEDIT_FROM_VIEW_LAYER(view_layer) \
+ OBEDIT_FROM_OBACT(OBACT(view_layer))
#define V3D_CAMERA_LOCAL(v3d) ((!(v3d)->scenelock && (v3d)->camera) ? (v3d)->camera : NULL)
#define V3D_CAMERA_SCENE(scene, v3d) ((!(v3d)->scenelock && (v3d)->camera) ? (v3d)->camera : (scene)->camera)
@@ -2290,15 +2001,6 @@ typedef enum eGPencil_Placement_Flags {
#define BONE_SKETCHING_QUICK 2
#define BONE_SKETCHING_ADJUST 4
-/* ToolSettings.bone_sketching_convert */
-#define SK_CONVERT_CUT_FIXED 0
-#define SK_CONVERT_CUT_LENGTH 1
-#define SK_CONVERT_CUT_ADAPTATIVE 2
-#define SK_CONVERT_RETARGET 3
-
-/* ToolSettings.skgen_retarget_options */
-#define SK_RETARGET_AUTONAME 1
-
/* ToolSettings.skgen_retarget_roll */
#define SK_RETARGET_ROLL_NONE 0
#define SK_RETARGET_ROLL_VIEW 1
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index a7718883438..7392a56722e 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -30,6 +30,7 @@
#ifndef __DNA_SCREEN_TYPES_H__
#define __DNA_SCREEN_TYPES_H__
+#include "DNA_defs.h"
#include "DNA_listBase.h"
#include "DNA_view2d_types.h"
#include "DNA_vec_types.h"
@@ -43,20 +44,28 @@ struct ARegionType;
struct PanelType;
struct Scene;
struct uiLayout;
+struct wmDrawBuffer;
struct wmTimer;
struct wmTooltipState;
+
+/* TODO Doing this is quite ugly :)
+ * Once the top-bar is merged bScreen should be refactored to use ScrAreaMap. */
+#define AREAMAP_FROM_SCREEN(screen) ((ScrAreaMap *)&(screen)->vertbase)
+
typedef struct bScreen {
ID id;
-
+
+ /* TODO Should become ScrAreaMap now.
+ * ** NOTE: KEEP ORDER IN SYNC WITH ScrAreaMap! (see AREAMAP_FROM_SCREEN macro above) ** */
ListBase vertbase; /* screens have vertices/edges to define areas */
ListBase edgebase;
ListBase areabase;
+
ListBase regionbase; /* screen level regions (menus), runtime only */
-
- struct Scene *scene;
- struct Scene *newscene; /* temporary when switching */
-
+
+ struct Scene *scene DNA_DEPRECATED;
+
short winid; /* winid from WM, starts with 1 */
short redraws_flag; /* user-setting for which editors get redrawn during anim playback (used to be time->redraws) */
@@ -67,18 +76,18 @@ typedef struct bScreen {
char do_draw_gesture; /* notifier for gesture draw. */
char do_draw_paintcursor; /* notifier for paint cursor draw. */
char do_draw_drag; /* notifier for dragging draw. */
- char swap; /* indicator to survive swap-exchange systems */
char skip_handling; /* set to delay screen handling after switching back from maximized area */
char scrubbing; /* set when scrubbing to avoid some costly updates */
- char pad[6];
+ char pad[3];
- short mainwin; /* screensize subwindow, for screenedges and global menus */
- short subwinactive; /* active subwindow */
+ struct ARegion *active_region; /* active region that has mouse focus */
struct wmTimer *animtimer; /* if set, screen has timer handler added in window */
void *context; /* context callback */
struct wmTooltipState *tool_tip; /* runtime */
+
+ PreviewImage *preview;
} bScreen;
typedef struct ScrVert {
@@ -96,6 +105,14 @@ typedef struct ScrEdge {
int pad;
} ScrEdge;
+typedef struct ScrAreaMap {
+ /* ** NOTE: KEEP ORDER IN SYNC WITH LISTBASES IN bScreen! ** */
+
+ ListBase vertbase; /* ScrVert - screens have vertices/edges to define areas */
+ ListBase edgebase; /* ScrEdge */
+ ListBase areabase; /* ScrArea */
+} ScrAreaMap;
+
typedef struct Panel { /* the part from uiBlock that needs saved in file */
struct Panel *next, *prev;
@@ -194,6 +211,13 @@ typedef struct uiList { /* some list UI data need to be saved in file
uiListDyn *dyn_data;
} uiList;
+typedef struct TransformOrientation {
+ struct TransformOrientation *next, *prev;
+ char name[64]; /* MAX_NAME */
+ float mat[3][3];
+ int pad;
+} TransformOrientation;
+
typedef struct uiPreview { /* some preview UI data need to be saved in file */
struct uiPreview *next, *prev;
@@ -202,6 +226,28 @@ typedef struct uiPreview { /* some preview UI data need to be saved in
short pad1[3];
} uiPreview;
+/* These two lines with # tell makesdna this struct can be excluded.
+ * Should be: #ifndef WITH_TOPBAR_WRITING */
+#
+#
+typedef struct ScrGlobalAreaData {
+ /* Global areas have a non-dynamic size. That means, changing the window
+ * size doesn't affect their size at all. However, they can still be
+ * 'collapsed', by changing this value. Ignores DPI (ED_area_global_size_y
+ * and winx/winy don't) */
+ short cur_fixed_height;
+ /* For global areas, this is the min and max size they can use depending on
+ * if they are 'collapsed' or not. Value is set on area creation and not
+ * touched afterwards. */
+ short size_min, size_max;
+
+ short flag; /* GlobalAreaFlag */
+} ScrGlobalAreaData;
+
+enum GlobalAreaFlag {
+ GLOBAL_AREA_IS_HIDDEN = (1 << 0),
+};
+
typedef struct ScrArea {
struct ScrArea *next, *prev;
@@ -210,10 +256,15 @@ typedef struct ScrArea {
rcti totrct; /* rect bound by v1 v2 v3 v4 */
- char spacetype, butspacetype; /* SPACE_..., butspacetype is button arg */
+ char spacetype; /* eSpace_Type (SPACE_FOO) */
+ /* Temporarily used while switching area type, otherwise this should be
+ * SPACE_EMPTY. Also, versioning uses it to nicely replace deprecated
+ * editors. It's been there for ages, name doesn't fit any more... */
+ char butspacetype; /* eSpace_Type (SPACE_FOO) */
+
short winx, winy; /* size */
-
- short headertype; /* OLD! 0=no header, 1= down, 2= up */
+
+ short headertype DNA_DEPRECATED;/* OLD! 0=no header, 1= down, 2= up */
short do_refresh; /* private, for spacetype refresh callback */
short flag;
short region_active_win; /* index of last used region of 'RGN_TYPE_WINDOW'
@@ -222,6 +273,9 @@ typedef struct ScrArea {
struct SpaceType *type; /* callbacks for this space type */
+ /* Non-NULL if this area is global. */
+ ScrGlobalAreaData *global;
+
/* A list of space links (editors) that were open in this area before. When
* changing the editor type, we try to reuse old editor data from this list.
* The first item is the active/visible one.
@@ -244,7 +298,7 @@ typedef struct ARegion {
rcti drawrct; /* runtime for partial redraw, same or smaller than winrct */
short winx, winy; /* size */
- short swinid;
+ short visible; /* region is currently visible on screen */
short regiontype; /* window, header, etc. identifier for drawing */
short alignment; /* how it should split */
short flag; /* hide, ... */
@@ -254,10 +308,9 @@ typedef struct ARegion {
short do_draw; /* private, cached notifier events */
short do_draw_overlay; /* private, cached notifier events */
- short swap; /* private, indicator to survive swap-exchange */
short overlap; /* private, set for indicate drawing overlapped */
short flagfullscreen; /* temporary copy of flag settings for clean fullscreen */
- short pad;
+ short pad1, pad2;
struct ARegionType *type; /* callbacks for this region type */
@@ -268,24 +321,25 @@ typedef struct ARegion {
ListBase ui_previews; /* uiPreview */
ListBase handlers; /* wmEventHandler */
ListBase panels_category; /* Panel categories runtime */
-
+
+ struct wmManipulatorMap *manipulator_map; /* manipulator-map of this region */
struct wmTimer *regiontimer; /* blend in/out */
-
+ struct wmDrawBuffer *draw_buffer;
+
char *headerstr; /* use this string to draw info */
void *regiondata; /* XXX 2.50, need spacedata equivalent? */
} ARegion;
-/* swap */
-#define WIN_BACK_OK 1
-#define WIN_FRONT_OK 2
-// #define WIN_EQUAL 3 // UNUSED
-
/* area->flag */
enum {
HEADER_NO_PULLDOWN = (1 << 0),
// AREA_FLAG_DEPRECATED_1 = (1 << 1),
// AREA_FLAG_DEPRECATED_2 = (1 << 2),
- AREA_TEMP_INFO = (1 << 3),
+#ifdef DNA_DEPRECATED_ALLOW
+ AREA_TEMP_INFO = (1 << 3), /* versioned to make slot reusable */
+#endif
+ /* update size of regions within the area */
+ AREA_FLAG_REGION_SIZE_UPDATE = (1 << 3),
// AREA_FLAG_DEPRECATED_4 = (1 << 4),
// AREA_FLAG_DEPRECATED_5 = (1 << 5),
/* used to check if we should switch back to prevspace (of a different type) */
@@ -301,9 +355,6 @@ enum {
#define AREAMINX 32
#define HEADERY 26
-#define HEADERDOWN 1
-#define HEADERTOP 2
-
/* screen->state */
enum {
SCREENNORMAL = 0,
@@ -403,8 +454,14 @@ enum {
#define RGN_SPLIT_PREV 32
/* region flag */
-#define RGN_FLAG_HIDDEN 1
-#define RGN_FLAG_TOO_SMALL 2
+enum {
+ RGN_FLAG_HIDDEN = (1 << 0),
+ RGN_FLAG_TOO_SMALL = (1 << 1),
+ /* Force delayed reinit of region size data, so that region size is calculated
+ * just big enough to show all its content (if enough space is available).
+ * Note that only ED_region_header supports this right now. */
+ RGN_FLAG_DYNAMIC_SIZE = (1 << 2),
+};
/* region do_draw */
#define RGN_DRAW 1
diff --git a/source/blender/makesdna/DNA_sensor_types.h b/source/blender/makesdna/DNA_sensor_types.h
deleted file mode 100644
index 37064854920..00000000000
--- a/source/blender/makesdna/DNA_sensor_types.h
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file DNA_sensor_types.h
- * \ingroup DNA
- * \since mar-2001
- * \author nzc
- *
- * #bSensor type is specifically for use by Object logic-bricks in the game-engine.
- */
-
-#ifndef __DNA_SENSOR_TYPES_H__
-#define __DNA_SENSOR_TYPES_H__
-
-struct Object;
-struct Material;
-
-/* ****************** SENSORS ********************* */
-
-typedef struct bNearSensor {
- char name[64]; /* MAX_NAME */
- float dist, resetdist;
- int lastval, pad;
-} bNearSensor;
-
-/**
- * Defines the settings of a mouse sensor.
- */
-typedef struct bMouseSensor {
- /**
- * The type of key this sensor listens to.
- */
- short type;
- short flag;
- short pad1;
- short mode; /* flag to choose material or property */
- char propname[64];
- char matname[64];
-} bMouseSensor;
-
-/* DEPRECATED */
-typedef struct bTouchSensor {
- char name[64]; /* MAX_NAME */
- struct Material *ma;
- float dist, pad;
-} bTouchSensor;
-
-typedef struct bKeyboardSensor {
- short key, qual;
- short type, qual2;
- /**
- * Name of the target property
- */
- char targetName[64]; /* MAX_NAME */
- /**
- * Name of the toggle property
- */
- char toggleName[64]; /* MAX_NAME */
-} bKeyboardSensor;
-
-typedef struct bPropertySensor {
- int type;
- int pad;
- char name[64]; /* MAX_NAME */
- char value[64];
- char maxvalue[64];
-} bPropertySensor;
-
-typedef struct bActuatorSensor {
- int type;
- int pad;
- char name[64]; /* MAX_NAME */
-} bActuatorSensor;
-
-typedef struct bDelaySensor {
- short delay;
- short duration;
- short flag;
- short pad;
-} bDelaySensor;
-
-typedef struct bCollisionSensor {
- char name[64]; /* property name. MAX_NAME */
- char materialName[64]; /* material */
- // struct Material *ma; // XXX remove materialName
- short damptimer, damp;
- short mode; /* flag to choose material or property */
- short pad2;
-} bCollisionSensor;
-
-typedef struct bRadarSensor {
- char name[64]; /* MAX_NAME */
- float angle;
- float range;
- short flag, axis;
-} bRadarSensor;
-
-typedef struct bRandomSensor {
- char name[64]; /* MAX_NAME */
- int seed;
- int delay;
-} bRandomSensor;
-
-typedef struct bRaySensor {
- char name[64]; /* MAX_NAME */
- float range;
- char propname[64];
- char matname[64];
- //struct Material *ma; // XXX remove materialName
- short mode;
- short pad1;
- int axisflag;
-} bRaySensor;
-
-typedef struct bArmatureSensor {
- char posechannel[64]; /* MAX_NAME */
- char constraint[64]; /* MAX_NAME */
- int type;
- float value;
-} bArmatureSensor;
-
-typedef struct bMessageSensor {
- /**
- * (Possible future use) pointer to a single sender object
- */
- struct Object *fromObject;
-
- /**
- * Can be used to filter on subjects like this
- */
- char subject[64];
-
- /**
- * (Possible future use) body to filter on
- */
- char body[64];
-} bMessageSensor;
-
-typedef struct bSensor {
- struct bSensor *next, *prev;
- /* pulse and freq are the bool toggle and frame count for pulse mode */
- short type, otype, flag, pulse;
- short freq, totlinks, pad1, pad2; /* freq makes reference to skipped ticks between 2 active pulses */
- char name[64]; /* MAX_NAME */
- void *data;
-
- struct bController **links;
-
- struct Object *ob;
-
- /* just add here, to avoid align errors... */
- short invert; /* Whether or not to invert the output. */
- short level; /* Whether the sensor is level base (edge by default) */
- short tap;
- short pad;
-} bSensor;
-
-typedef struct bJoystickSensor {
- char name[64]; /* MAX_NAME */
- char type;
- char joyindex;
- short flag;
- short axis;
- short axis_single;
- int axisf;
- int button;
- int hat;
- int hatf;
- int precision;
-} bJoystickSensor;
-
-/* bMouseSensor->type: uses blender event defines */
-
-/* bMouseSensor->flag: only pulse for now */
-#define SENS_MOUSE_FOCUS_PULSE 1
-
-/* propertysensor->type */
-#define SENS_PROP_EQUAL 0
-#define SENS_PROP_NEQUAL 1
-#define SENS_PROP_INTERVAL 2
-#define SENS_PROP_CHANGED 3
-#define SENS_PROP_EXPRESSION 4
-#define SENS_PROP_LESSTHAN 5
-#define SENS_PROP_GREATERTHAN 6
-
-/* raysensor->axisflag */
-/* flip x and y to make y default!!! */
-#define SENS_RAY_X_AXIS 1
-#define SENS_RAY_Y_AXIS 0
-#define SENS_RAY_Z_AXIS 2
-#define SENS_RAY_NEG_X_AXIS 3
-#define SENS_RAY_NEG_Y_AXIS 4
-#define SENS_RAY_NEG_Z_AXIS 5
-//#define SENS_RAY_NEGATIVE_AXIS 1
-
-/* bRadarSensor->axis */
-#define SENS_RADAR_X_AXIS 0
-#define SENS_RADAR_Y_AXIS 1
-#define SENS_RADAR_Z_AXIS 2
-#define SENS_RADAR_NEG_X_AXIS 3
-#define SENS_RADAR_NEG_Y_AXIS 4
-#define SENS_RADAR_NEG_Z_AXIS 5
-
-/* bMessageSensor->type */
-#define SENS_MESG_MESG 0
-#define SENS_MESG_PROP 1
-
-/* bArmatureSensor->type */
-#define SENS_ARM_STATE_CHANGED 0
-#define SENS_ARM_LIN_ERROR_BELOW 1
-#define SENS_ARM_LIN_ERROR_ABOVE 2
-#define SENS_ARM_ROT_ERROR_BELOW 3
-#define SENS_ARM_ROT_ERROR_ABOVE 4
-/* update this when adding new type */
-#define SENS_ARM_MAXTYPE 4
-
-/* sensor->type */
-#define SENS_ALWAYS 0
-#define SENS_TOUCH 1 /* DEPRECATED */
-#define SENS_NEAR 2
-#define SENS_KEYBOARD 3
-#define SENS_PROPERTY 4
-#define SENS_MOUSE 5
-#define SENS_COLLISION 6
-#define SENS_RADAR 7
-#define SENS_RANDOM 8
-#define SENS_RAY 9
-#define SENS_MESSAGE 10
-#define SENS_JOYSTICK 11
-#define SENS_ACTUATOR 12
-#define SENS_DELAY 13
-#define SENS_ARMATURE 14
-/* sensor->flag */
-#define SENS_SHOW 1
-#define SENS_DEL 2
-#define SENS_NEW 4
-#define SENS_NOT 8
-#define SENS_VISIBLE 16
-#define SENS_PIN 32
-#define SENS_DEACTIVATE 64
-
-/* sensor->pulse */
-#define SENS_PULSE_CONT 0
-#define SENS_PULSE_REPEAT 1
-//#define SENS_PULSE_ONCE 2
-#define SENS_NEG_PULSE_MODE 4
-
-/* sensor->suppress */
-#define SENS_SUPPRESS_POSITIVE (1 << 0)
-#define SENS_SUPPRESS_NEGATIVE (1 << 1)
-
-/* collision, ray sensor modes: */
-/* A little bit fake: when property is active, the first bit is
- * reset. Bite me :) So we don't actually use it, so we comment it out
- * ... The reason for this is that we need to be backward compatible,
- * and have a proper default value for this thing.
- * */
-#define SENS_COLLISION_PROPERTY 0
-#define SENS_COLLISION_MATERIAL 1
-#define SENS_COLLISION_PULSE 2
-
-/* ray specific mode */
-/* X-Ray means that the ray will traverse objects that don't have the property/material */
-#define SENS_RAY_PROPERTY 0
-#define SENS_RAY_MATERIAL 1
-#define SENS_RAY_XRAY 2
-
-/* Some stuff for the mouse sensor Type: */
-#define BL_SENS_MOUSE_LEFT_BUTTON 1
-#define BL_SENS_MOUSE_MIDDLE_BUTTON 2
-#define BL_SENS_MOUSE_RIGHT_BUTTON 4
-#define BL_SENS_MOUSE_WHEEL_UP 5
-#define BL_SENS_MOUSE_WHEEL_DOWN 6
-#define BL_SENS_MOUSE_MOVEMENT 8
-#define BL_SENS_MOUSE_MOUSEOVER 16
-#define BL_SENS_MOUSE_MOUSEOVER_ANY 32
-
-/* Joystick sensor - sorted by axis types */
-#define SENS_JOY_ANY_EVENT 1
-
-#define SENS_JOY_BUTTON 0 /* axis type */
-
-#define SENS_JOY_AXIS 1 /* axis type */
-#define SENS_JOY_X_AXIS 0
-#define SENS_JOY_Y_AXIS 1
-#define SENS_JOY_NEG_X_AXIS 2
-#define SENS_JOY_NEG_Y_AXIS 3
-#define SENS_JOY_PRECISION 4
-
-#define SENS_JOY_HAT 2 /* axis type */
-#define SENS_JOY_HAT_DIR 0
-#define SENS_JOY_HAT_UP 1
-#define SENS_JOY_HAT_RIGHT 2
-#define SENS_JOY_HAT_DOWN 4
-#define SENS_JOY_HAT_LEFT 8
-
-#define SENS_JOY_HAT_UP_RIGHT SENS_JOY_HAT_UP | SENS_JOY_HAT_RIGHT
-#define SENS_JOY_HAT_DOWN_RIGHT SENS_JOY_HAT_DOWN | SENS_JOY_HAT_RIGHT
-#define SENS_JOY_HAT_UP_LEFT SENS_JOY_HAT_UP | SENS_JOY_HAT_LEFT
-#define SENS_JOY_HAT_DOWN_LEFT SENS_JOY_HAT_DOWN | SENS_JOY_HAT_LEFT
-
-
-#define SENS_JOY_AXIS_SINGLE 3 /* axis type */
-
-
-#define SENS_DELAY_REPEAT 1
-// should match JOYINDEX_MAX in SCA_JoystickDefines.h */
-#define SENS_JOY_MAXINDEX 8
-
-#endif /* __DNA_SENSOR_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_space_types.h b/source/blender/makesdna/DNA_space_types.h
index 693917939ef..795cd0ee974 100644
--- a/source/blender/makesdna/DNA_space_types.h
+++ b/source/blender/makesdna/DNA_space_types.h
@@ -67,6 +67,10 @@ struct MovieClipScopes;
struct Mask;
struct BLI_mempool;
+/* TODO 2.8: We don't write the topbar to files currently. Uncomment this
+ * define to enable writing (should become the default in a bit). */
+//#define WITH_TOPBAR_WRITING
+
/* SpaceLink (Base) ==================================== */
@@ -124,9 +128,9 @@ typedef struct SpaceButs {
short mainb, mainbo, mainbuser; /* context tabs */
short re_align, align; /* align for panels */
short preview; /* preview is signal to refresh */
- /* texture context selector (material, lamp, particles, world, other) */
- short texture_context, texture_context_prev;
- char flag, pad[7];
+ char flag;
+ char collection_context;
+ char pad[2];
void *path; /* runtime */
int pathflag, dataicon; /* runtime */
@@ -144,7 +148,7 @@ typedef struct SpaceButs {
#define CONTEXT_SHADING 3
#define CONTEXT_EDITING 4
#define CONTEXT_SCRIPT 5
-#define CONTEXT_LOGIC 6
+//#define CONTEXT_LOGIC 6
/* sbuts->mainb old (deprecated) */
#ifdef DNA_DEPRECATED_ALLOW
@@ -156,7 +160,7 @@ typedef struct SpaceButs {
#define BUTS_WORLD 5
#define BUTS_RENDER 6
#define BUTS_EDIT 7
-#define BUTS_GAME 8
+// #define BUTS_GAME 8
#define BUTS_FPAINT 9
#define BUTS_RADIO 10
#define BUTS_SCRIPT 11
@@ -180,8 +184,10 @@ typedef enum eSpaceButtons_Context {
BCONTEXT_MODIFIER = 10,
BCONTEXT_CONSTRAINT = 11,
BCONTEXT_BONE_CONSTRAINT = 12,
- BCONTEXT_RENDER_LAYER = 13,
-
+ BCONTEXT_VIEW_LAYER = 13,
+ BCONTEXT_COLLECTION = 14,
+ BCONTEXT_WORKSPACE = 15,
+
/* always as last... */
BCONTEXT_TOT
} eSpaceButtons_Context;
@@ -196,15 +202,11 @@ typedef enum eSpaceButtons_Flag {
SB_SHADING_CONTEXT = (1 << 4),
} eSpaceButtons_Flag;
-/* sbuts->texture_context */
-typedef enum eSpaceButtons_Texture_Context {
- SB_TEXC_MATERIAL = 0,
- SB_TEXC_WORLD = 1,
- SB_TEXC_LAMP = 2,
- SB_TEXC_PARTICLES = 3,
- SB_TEXC_OTHER = 4,
- SB_TEXC_LINESTYLE = 5,
-} eSpaceButtons_Texture_Context;
+/* sbuts->collection_context */
+typedef enum eSpaceButtons_Collection_Context {
+ SB_COLLECTION_CTX_VIEW_LAYER = 0,
+ SB_COLLECTION_CTX_GROUP = 1,
+} eSpaceButtons_Collection_Context;
/* sbuts->align */
typedef enum eSpaceButtons_Align {
@@ -256,6 +258,9 @@ typedef struct SpaceOops {
struct TreeStoreElem search_tse;
short flag, outlinevis, storeflag, search_flags;
+ int filter;
+ char filter_state;
+ char pad[3];
/* pointers to treestore elements, grouped by (id, type, nr) in hashtable for faster searching */
void *treehash;
@@ -271,23 +276,68 @@ typedef enum eSpaceOutliner_Flag {
SO_SKIP_SORT_ALPHA = (1 << 4),
} eSpaceOutliner_Flag;
+/* SpaceOops->filter */
+typedef enum eSpaceOutliner_Filter {
+ SO_FILTER_SEARCH = (1 << 0),
+ SO_FILTER_ENABLE = (1 << 1),
+ SO_FILTER_NO_OBJECT = (1 << 2),
+ SO_FILTER_NO_OB_CONTENT = (1 << 3), /* Not only mesh, but modifiers, constraints, ... */
+ SO_FILTER_NO_CHILDREN = (1 << 4),
+
+ SO_FILTER_OB_TYPE = (1 << 5),
+ SO_FILTER_NO_OB_MESH = (1 << 6),
+ SO_FILTER_NO_OB_ARMATURE = (1 << 7),
+ SO_FILTER_NO_OB_EMPTY = (1 << 8),
+ SO_FILTER_NO_OB_LAMP = (1 << 9),
+ SO_FILTER_NO_OB_CAMERA = (1 << 10),
+ SO_FILTER_NO_OB_OTHERS = (1 << 11),
+
+ SO_FILTER_OB_STATE = (1 << 12),
+ SO_FILTER_OB_STATE_VISIBLE = (1 << 13), /* Not set via DNA. */
+ SO_FILTER_OB_STATE_SELECTED = (1 << 14), /* Not set via DNA. */
+ SO_FILTER_OB_STATE_ACTIVE = (1 << 15), /* Not set via DNA. */
+ SO_FILTER_NO_COLLECTION = (1 << 16),
+} eSpaceOutliner_Filter;
+
+#define SO_FILTER_NO_OB_ALL (SO_FILTER_NO_OB_MESH | \
+ SO_FILTER_NO_OB_ARMATURE | \
+ SO_FILTER_NO_OB_EMPTY | \
+ SO_FILTER_NO_OB_LAMP | \
+ SO_FILTER_NO_OB_CAMERA | \
+ SO_FILTER_NO_OB_OTHERS)
+
+#define SO_FILTER_ANY (SO_FILTER_NO_OBJECT | \
+ SO_FILTER_NO_OB_CONTENT | \
+ SO_FILTER_NO_CHILDREN | \
+ SO_FILTER_OB_TYPE | \
+ SO_FILTER_OB_STATE | \
+ SO_FILTER_NO_COLLECTION)
+
+/* SpaceOops->filter_state */
+typedef enum eSpaceOutliner_StateFilter {
+ SO_FILTER_OB_VISIBLE = 0,
+ SO_FILTER_OB_SELECTED = 1,
+ SO_FILTER_OB_ACTIVE = 2,
+} eSpaceOutliner_StateFilter;
+
/* SpaceOops->outlinevis */
typedef enum eSpaceOutliner_Mode {
- SO_ALL_SCENES = 0,
- SO_CUR_SCENE = 1,
- SO_VISIBLE = 2,
- SO_SELECTED = 3,
- SO_ACTIVE = 4,
- SO_SAME_TYPE = 5,
- SO_GROUPS = 6,
- SO_LIBRARIES = 7,
- /* SO_VERSE_SESSION = 8, */ /* deprecated! */
- /* SO_VERSE_MS = 9, */ /* deprecated! */
- SO_SEQUENCE = 10,
- SO_DATABLOCKS = 11,
- SO_USERDEF = 12,
- /* SO_KEYMAP = 13, */ /* deprecated! */
- SO_ID_ORPHANS = 14,
+ SO_SCENES = 0,
+ /* SO_CUR_SCENE = 1, */ /* deprecated! */
+ /* SO_VISIBLE = 2, */ /* deprecated! */
+ /* SO_SELECTED = 3, */ /* deprecated! */
+ /* SO_ACTIVE = 4, */ /* deprecated! */
+ /* SO_SAME_TYPE = 5, */ /* deprecated! */
+ SO_GROUPS = 6,
+ SO_LIBRARIES = 7,
+ /* SO_VERSE_SESSION = 8, */ /* deprecated! */
+ /* SO_VERSE_MS = 9, */ /* deprecated! */
+ SO_SEQUENCE = 10,
+ SO_DATABLOCKS = 11,
+ /* SO_USERDEF = 12, */ /* deprecated! */
+ /* SO_KEYMAP = 13, */ /* deprecated! */
+ SO_ID_ORPHANS = 14,
+ SO_COLLECTIONS = 15,
} eSpaceOutliner_Mode;
/* SpaceOops->storeflag */
@@ -419,40 +469,6 @@ typedef enum eSpaceNla_Flag {
/* Timeline =============================================== */
-/* Pointcache drawing data */
-# /* Only store the data array in the cache to avoid constant reallocation. */
-# /* No need to store when saved. */
-typedef struct SpaceTimeCache {
- struct SpaceTimeCache *next, *prev;
- float *array;
-} SpaceTimeCache;
-
-/* Timeline View */
-typedef struct SpaceTime {
- SpaceLink *next, *prev;
- ListBase regionbase; /* storage of regions for inactive spaces */
- int spacetype;
- float blockscale DNA_DEPRECATED;
-
- View2D v2d DNA_DEPRECATED; /* deprecated, copied to region */
-
- ListBase caches;
-
- int cache_display;
- int flag;
-} SpaceTime;
-
-
-/* time->flag */
-typedef enum eTimeline_Flag {
- /* show timing in frames instead of in seconds */
- TIME_DRAWFRAMES = (1 << 0),
- /* show time indicator box beside the frame number */
- TIME_CFRA_NUM = (1 << 1),
- /* only keyframes from active/selected channels get shown */
- TIME_ONLYACTSEL = (1 << 2),
-} eTimeline_Flag;
-
/* time->redraws (now screen->redraws_flag) */
typedef enum eScreen_Redraws_Flag {
TIME_REGION = (1 << 0),
@@ -469,18 +485,6 @@ typedef enum eScreen_Redraws_Flag {
TIME_FOLLOW = (1 << 15),
} eScreen_Redraws_Flag;
-/* time->cache */
-typedef enum eTimeline_Cache_Flag {
- TIME_CACHE_DISPLAY = (1 << 0),
- TIME_CACHE_SOFTBODY = (1 << 1),
- TIME_CACHE_PARTICLES = (1 << 2),
- TIME_CACHE_CLOTH = (1 << 3),
- TIME_CACHE_SMOKE = (1 << 4),
- TIME_CACHE_DYNAMICPAINT = (1 << 5),
- TIME_CACHE_RIGIDBODY = (1 << 6),
-} eTimeline_Cache_Flag;
-
-
/* Sequence Editor ======================================= */
/* Sequencer */
@@ -715,7 +719,7 @@ typedef enum eFileSel_Params_Flag {
FILE_LINK = (1 << 2),
FILE_HIDE_DOT = (1 << 3),
FILE_AUTOSELECT = (1 << 4),
- FILE_ACTIVELAY = (1 << 5),
+ FILE_ACTIVE_COLLECTION = (1 << 5),
/* FILE_ATCURSOR = (1 << 6), */ /* deprecated */
FILE_DIRSEL_ONLY = (1 << 7),
FILE_FILTER = (1 << 8),
@@ -944,7 +948,7 @@ typedef enum eSpaceImage_Sticky {
/* SpaceImage->flag */
typedef enum eSpaceImage_Flag {
/* SI_BE_SQUARE = (1 << 0), */ /* deprecated */
- SI_EDITTILE = (1 << 1), /* XXX - not used but should be? */
+/* SI_EDITTILE = (1 << 1), */ /* deprecated */
SI_CLIP_UV = (1 << 2),
/* SI_DRAWTOOL = (1 << 3), */ /* deprecated */
SI_NO_DRAWFACES = (1 << 4),
@@ -1158,14 +1162,14 @@ typedef enum eSpaceNode_Flag {
SNODE_AUTO_RENDER = (1 << 5),
// SNODE_SHOW_HIGHLIGHT = (1 << 6), DNA_DEPRECATED
// SNODE_USE_HIDDEN_PREVIEW = (1 << 10), DNA_DEPRECATED December2013
- SNODE_NEW_SHADERS = (1 << 11),
+// SNODE_NEW_SHADERS = (1 << 11), DNA_DEPRECATED
SNODE_PIN = (1 << 12),
SNODE_SKIP_INSOFFSET = (1 << 13), /* automatically offset following nodes in a chain on insertion */
} eSpaceNode_Flag;
/* snode->texfrom */
typedef enum eSpaceNode_TexFrom {
- SNODE_TEX_OBJECT = 0,
+ /* SNODE_TEX_OBJECT = 0, */
SNODE_TEX_WORLD = 1,
SNODE_TEX_BRUSH = 2,
SNODE_TEX_LINESTYLE = 3,
@@ -1184,23 +1188,6 @@ enum {
SNODE_INSERTOFS_DIR_LEFT = 1,
};
-/* Game Logic Editor ===================================== */
-
-/* Logic Editor */
-typedef struct SpaceLogic {
- SpaceLink *next, *prev;
- ListBase regionbase; /* storage of regions for inactive spaces */
- int spacetype;
- float blockscale DNA_DEPRECATED;
-
- short blockhandler[8] DNA_DEPRECATED;
-
- short flag, scaflag;
- int pad;
-
- struct bGPdata *gpd; /* grease-pencil data */
-} SpaceLogic;
-
/* Console ================================================ */
/* Console content */
@@ -1300,6 +1287,7 @@ typedef struct SpaceClip {
MaskSpaceInfo mask_info;
} SpaceClip;
+
/* SpaceClip->flag */
typedef enum eSpaceClip_Flag {
SC_SHOW_MARKER_PATTERN = (1 << 0),
@@ -1348,6 +1336,22 @@ typedef enum eSpaceClip_GPencil_Source {
SC_GPENCIL_SRC_TRACK = 1,
} eSpaceClip_GPencil_Source;
+
+/* Top Bar ======================================= */
+
+/* These two lines with # tell makesdna this struct can be excluded.
+ * Should be: #ifndef WITH_TOPBAR_WRITING */
+#
+#
+typedef struct SpaceTopBar {
+ SpaceLink *next, *prev;
+ ListBase regionbase; /* storage of regions for inactive spaces */
+ int spacetype;
+
+ int pad;
+} SpaceTopBar;
+
+
/* **************** SPACE DEFINES ********************* */
/* space types, moved from DNA_screen_types.h */
@@ -1371,14 +1375,15 @@ typedef enum eSpace_Type {
SPACE_NLA = 13,
/* TODO: fully deprecate */
SPACE_SCRIPT = 14, /* Deprecated */
- SPACE_TIME = 15,
+ SPACE_TIME = 15, /* Deprecated */
SPACE_NODE = 16,
- SPACE_LOGIC = 17,
+ SPACE_LOGIC = 17, /* deprecated */
SPACE_CONSOLE = 18,
SPACE_USERPREF = 19,
SPACE_CLIP = 20,
-
- SPACEICONMAX = SPACE_CLIP
+ SPACE_TOPBAR = 21,
+
+ SPACEICONMAX = SPACE_TOPBAR
} eSpace_Type;
/* use for function args */
diff --git a/source/blender/makesdna/DNA_texture_types.h b/source/blender/makesdna/DNA_texture_types.h
index 0eb54a9b5b3..f5267f20d2c 100644
--- a/source/blender/makesdna/DNA_texture_types.h
+++ b/source/blender/makesdna/DNA_texture_types.h
@@ -45,13 +45,11 @@ extern "C" {
struct AnimData;
struct Ipo;
struct ColorBand;
-struct EnvMap;
struct Object;
struct Tex;
struct Image;
struct PreviewImage;
struct ImBuf;
-struct Ocean;
struct CurveMapping;
typedef struct MTex {
@@ -121,21 +119,6 @@ typedef struct ColorBand {
CBData data[32];
} ColorBand;
-typedef struct EnvMap {
- struct Object *object;
- struct Image *ima; /* type ENV_LOAD */
- struct ImBuf *cube[6]; /* these images are dynamic, not part of the main struct */
- float imat[4][4];
- float obimat[3][3];
- short type, stype;
- float clipsta, clipend;
- float viewscale; /* viewscale is for planar envmaps to zoom in or out */
- unsigned int notlay;
- short cuberes, depth;
- int ok, lastframe;
- short recalc, lastsize;
-} EnvMap;
-
typedef struct PointDensity {
short flag;
@@ -172,38 +155,6 @@ typedef struct PointDensity {
struct CurveMapping *falloff_curve; /* falloff density curve */
} PointDensity;
-typedef struct VoxelData {
- int resol[3];
- int interp_type;
- short file_format;
- short flag;
- short extend;
- short smoked_type;
- short hair_type;
- short data_type;
- int _pad;
-
- struct Object *object; /* for rendering smoke sims */
- float int_multiplier;
- int still_frame;
- char source_path[1024]; /* 1024 = FILE_MAX */
-
- /* temporary data */
- float *dataset;
- int cachedframe;
- int ok;
-
-} VoxelData;
-
-typedef struct OceanTex {
- struct Object *object;
- char oceanmod[64];
-
- int output;
- int pad;
-
-} OceanTex;
-
typedef struct Tex {
ID id;
struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
@@ -254,11 +205,7 @@ typedef struct Tex {
struct Ipo *ipo DNA_DEPRECATED; /* old animation system, deprecated for 2.5 */
struct Image *ima;
struct ColorBand *coba;
- struct EnvMap *env;
struct PreviewImage *preview;
- struct PointDensity *pd;
- struct VoxelData *vd;
- struct OceanTex *ot;
char use_nodes;
char pad[7];
@@ -316,13 +263,13 @@ typedef struct ColorMapping {
#define TEX_NOISE 7
#define TEX_IMAGE 8
//#define TEX_PLUGIN 9 /* Deprecated */
-#define TEX_ENVMAP 10
+//#define TEX_ENVMAP 10 /* Deprecated */
#define TEX_MUSGRAVE 11
#define TEX_VORONOI 12
#define TEX_DISTNOISE 13
-#define TEX_POINTDENSITY 14
-#define TEX_VOXELDATA 15
-#define TEX_OCEAN 16
+//#define TEX_POINTDENSITY 14 /* Deprecated */
+//#define TEX_VOXELDATA 15 /* Deprecated */
+//#define TEX_OCEAN 16 /* Deprecated */
/* musgrave stype */
#define TEX_MFRACTAL 0
@@ -549,22 +496,6 @@ enum {
COLBAND_HUE_CCW = 3,
};
-/* **************** EnvMap ********************* */
-
-/* type */
-#define ENV_CUBE 0
-#define ENV_PLANE 1
-#define ENV_SPHERE 2
-
-/* stype */
-#define ENV_STATIC 0
-#define ENV_ANIM 1
-#define ENV_LOAD 2
-
-/* ok */
-#define ENV_NORMAL 1
-#define ENV_OSA 2
-
/* **************** PointDensity ********************* */
/* source */
@@ -592,9 +523,9 @@ enum {
/* noise_influence */
#define TEX_PD_NOISE_STATIC 0
-#define TEX_PD_NOISE_VEL 1
-#define TEX_PD_NOISE_AGE 2
-#define TEX_PD_NOISE_TIME 3
+/* #define TEX_PD_NOISE_VEL 1 */ /* Deprecated */
+/* #define TEX_PD_NOISE_AGE 2 */ /* Deprecated */
+/* #define TEX_PD_NOISE_TIME 3 */ /* Deprecated */
/* color_source */
enum {
@@ -613,55 +544,6 @@ enum {
#define POINT_DATA_LIFE 2
#define POINT_DATA_COLOR 4
-/******************** Voxel Data *****************************/
-/* flag */
-#define TEX_VD_STILL 1
-
-/* interpolation */
-#define TEX_VD_NEARESTNEIGHBOR 0
-#define TEX_VD_LINEAR 1
-#define TEX_VD_QUADRATIC 2
-#define TEX_VD_TRICUBIC_CATROM 3
-#define TEX_VD_TRICUBIC_BSPLINE 4
-#define TEX_VD_TRICUBIC_SLOW 5
-
-/* file format */
-#define TEX_VD_BLENDERVOXEL 0
-#define TEX_VD_RAW_8BIT 1
-#define TEX_VD_RAW_16BIT 2
-#define TEX_VD_IMAGE_SEQUENCE 3
-#define TEX_VD_SMOKE 4
-#define TEX_VD_HAIR 5
-/* for voxels which use VoxelData->source_path */
-#define TEX_VD_IS_SOURCE_PATH(_format) (ELEM(_format, TEX_VD_BLENDERVOXEL, TEX_VD_RAW_8BIT, TEX_VD_RAW_16BIT))
-
-/* smoke data types */
-#define TEX_VD_SMOKEDENSITY 0
-#define TEX_VD_SMOKEHEAT 1
-#define TEX_VD_SMOKEVEL 2
-#define TEX_VD_SMOKEFLAME 3
-
-#define TEX_VD_HAIRDENSITY 0
-#define TEX_VD_HAIRVELOCITY 1
-#define TEX_VD_HAIRENERGY 2
-#define TEX_VD_HAIRRESTDENSITY 3
-
-/* data_type */
-#define TEX_VD_INTENSITY 0
-#define TEX_VD_RGBA_PREMUL 1
-
-/******************** Ocean *****************************/
-/* output */
-#define TEX_OCN_DISPLACEMENT 1
-#define TEX_OCN_FOAM 2
-#define TEX_OCN_JPLUS 3
-#define TEX_OCN_EMINUS 4
-#define TEX_OCN_EPLUS 5
-
-/* flag */
-#define TEX_OCN_GENERATE_NORMALS 1
-#define TEX_OCN_XZ 2
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/makesdna/DNA_userdef_types.h b/source/blender/makesdna/DNA_userdef_types.h
index a7759a1d143..88cbd848387 100644
--- a/source/blender/makesdna/DNA_userdef_types.h
+++ b/source/blender/makesdna/DNA_userdef_types.h
@@ -131,6 +131,8 @@ typedef struct uiWidgetColors {
short shaded;
short shadetop, shadedown;
short alpha_check;
+ float roundness;
+ float pad;
} uiWidgetColors;
typedef struct uiWidgetStateColors {
@@ -140,6 +142,8 @@ typedef struct uiWidgetStateColors {
char inner_key_sel[4];
char inner_driven[4];
char inner_driven_sel[4];
+ char inner_overridden[4];
+ char inner_overridden_sel[4];
float blend, pad;
} uiWidgetStateColors;
@@ -160,9 +164,9 @@ typedef struct uiGradientColors {
typedef struct ThemeUI {
/* Interface Elements (buttons, menus, icons) */
- uiWidgetColors wcol_regular, wcol_tool, wcol_text;
+ uiWidgetColors wcol_regular, wcol_tool, wcol_toolbar_item, wcol_text;
uiWidgetColors wcol_radio, wcol_option, wcol_toggle;
- uiWidgetColors wcol_num, wcol_numslider;
+ uiWidgetColors wcol_num, wcol_numslider, wcol_tab;
uiWidgetColors wcol_menu, wcol_pulldown, wcol_menu_back, wcol_menu_item, wcol_tooltip;
uiWidgetColors wcol_box, wcol_scroll, wcol_progress, wcol_list_item, wcol_pie_menu;
@@ -176,13 +180,24 @@ typedef struct ThemeUI {
float menu_shadow_fac;
short menu_shadow_width;
- short pad[3];
+ char editor_outline[4];
+ short pad[1];
char iconfile[256]; // FILE_MAXFILE length
float icon_alpha;
+ float icon_saturation;
+ char _pad[4];
/* Axis Colors */
char xaxis[4], yaxis[4], zaxis[4];
+
+ /* Manipulator Colors. */
+ char manipulator_hi[4];
+ char manipulator_primary[4];
+ char manipulator_secondary[4];
+ char manipulator_a[4];
+ char manipulator_b[4];
+ char pad2[4];
} ThemeUI;
/* try to put them all in one, if needed a special struct can be created as well
@@ -387,11 +402,11 @@ typedef struct bTheme {
ThemeSpace toops;
ThemeSpace ttime;
ThemeSpace tnode;
- ThemeSpace tlogic;
ThemeSpace tuserpref;
ThemeSpace tconsole;
ThemeSpace tclip;
-
+ ThemeSpace ttopbar;
+
/* 20 sets of bone colors for this theme */
ThemeWireColor tarm[20];
/*ThemeWireColor tobj[20];*/
@@ -456,7 +471,7 @@ typedef struct UserDef {
short versions;
short dbl_click_time;
- short gameflags;
+ short pad;
short wheellinescroll;
int uiflag; /* eUserpref_UI_Flag */
int uiflag2; /* eUserpref_UI_Flag2 */
@@ -472,12 +487,16 @@ typedef struct UserDef {
int audioformat;
int audiochannels;
+ float ui_scale; /* setting for UI scale */
+ int ui_line_width; /* setting for UI line width */
+ int dpi; /* runtime, full DPI divided by pixelsize */
+ float dpi_fac; /* runtime, multiplier to scale UI elements based on DPI */
+ float pixelsize; /* runtime, line width and point size based on DPI */
+ int virtual_pixel; /* deprecated, for forward compatibility */
+
int scrollback; /* console scrollback limit */
- int dpi; /* range 48-128? */
- float ui_scale; /* interface scale */
- int ui_line_width; /* interface line width */
char node_margin; /* node insert offset (aka auto-offset) margin, but might be useful for later stuff as well */
- char pad2;
+ char pad2[5];
short transopts; /* eUserpref_Translation_Flags */
short menuthreshold1, menuthreshold2;
@@ -501,9 +520,9 @@ typedef struct UserDef {
short gp_settings; /* eGP_UserdefSettings */
short tb_leftmouse, tb_rightmouse;
struct SolidLight light[3];
- short tw_hotspot, tw_flag, tw_handlesize, tw_size;
+ short manipulator_flag, manipulator_size;
+ short pad6[3];
short textimeout, texcollectrate;
- short wmdrawmethod; /* eWM_DrawMethod */
short dragthreshold;
int memcachelimit;
int prefetchframes;
@@ -557,7 +576,7 @@ typedef struct UserDef {
float gpencil_new_layer_col[4]; /* default color for newly created Grease Pencil layers */
short tweak_threshold;
- char navigation_mode, pad;
+ char navigation_mode, pad10;
char author[80]; /* author name for file formats supporting it */
@@ -568,8 +587,6 @@ typedef struct UserDef {
int compute_device_id;
float fcu_inactive_alpha; /* opacity of inactive F-Curves in F-Curve Editor */
- float pixelsize; /* private, set by GHOST, to multiply DPI with */
- int virtual_pixel; /* virtual pixelsize mode */
short pie_interaction_type; /* if keeping a pie menu spawn button pressed after this time, it turns into
* a drag/release pie menu */
@@ -607,7 +624,7 @@ typedef enum eUserPref_Flag {
USER_FLAG_DEPRECATED_1 = (1 << 1), /* cleared */
USER_FLAG_DEPRECATED_2 = (1 << 2), /* cleared */
USER_FLAG_DEPRECATED_3 = (1 << 3), /* cleared */
- USER_SCENEGLOBAL = (1 << 4),
+/* USER_SCENEGLOBAL = (1 << 4), deprecated */
USER_TRACKBALL = (1 << 5),
USER_FLAG_DEPRECATED_6 = (1 << 6), /* cleared */
USER_FLAG_DEPRECATED_7 = (1 << 7), /* cleared */
@@ -776,15 +793,6 @@ typedef enum eDupli_ID_Flags {
USER_DUP_PSYS = (1 << 11)
} eDupli_ID_Flags;
-/* UserDef.gameflags */
-typedef enum eOpenGL_RenderingOptions {
- USER_GL_RENDER_DEPRECATED_0 = (1 << 0),
- USER_GL_RENDER_DEPRECATED_1 = (1 << 1),
- USER_DISABLE_MIPMAP = (1 << 2),
- USER_GL_RENDER_DEPRECATED_3 = (1 << 3),
- USER_GL_RENDER_DEPRECATED_4 = (1 << 4),
-} eOpenGL_RenderingOptions;
-
/* selection method for opengl gpu_select_method */
typedef enum eOpenGL_SelectOptions {
USER_SELECT_AUTO = 0,
@@ -792,16 +800,6 @@ typedef enum eOpenGL_SelectOptions {
USER_SELECT_USE_SELECT_RENDERMODE = 2
} eOpenGL_SelectOptions;
-/* wm draw method.
- * UserDef.wmdrawmethod */
-typedef enum eWM_DrawMethod {
- USER_DRAW_TRIPLE = 0,
- USER_DRAW_OVERLAP = 1,
- USER_DRAW_FULL = 2,
- USER_DRAW_AUTOMATIC = 3,
- USER_DRAW_OVERLAP_FLIP = 4,
-} eWM_DrawMethod;
-
/* text draw options
* UserDef.text_render */
typedef enum eText_Draw_Options {
@@ -817,6 +815,12 @@ typedef enum eGP_UserdefSettings {
GP_PAINT_DOSIMPLIFY = (1 << 1),
} eGP_UserdefSettings;
+enum {
+ USER_MANIPULATOR_DRAW = (1 << 0),
+ USER_MANIPULATOR_DRAW_NAVIGATE = (1 << 1),
+ USER_MANIPULATOR_SHADED = (1 << 8),
+};
+
/* Color Picker Types.
* UserDef.color_picker_type */
typedef enum eColorPicker_Types {
diff --git a/source/blender/makesdna/DNA_view2d_types.h b/source/blender/makesdna/DNA_view2d_types.h
index 3319fed8cdd..a0480aa361b 100644
--- a/source/blender/makesdna/DNA_view2d_types.h
+++ b/source/blender/makesdna/DNA_view2d_types.h
@@ -64,6 +64,11 @@ typedef struct View2D {
int tab_num; /* number of tabs stored */
int tab_cur; /* current tab */
+ /* Usually set externally (as in, not in view2d files). */
+ char alpha_vert, alpha_hor; /* alpha of vertical and horizontal scrollbars (range is [0, 255]) */
+ short size_vert, size_hor; /* Dynamic size for scrollers without scale markers (no V2D_SCROLL_SCALE_FOO) */
+ short pad;
+
/* animated smooth view */
struct SmoothView2DStore *sms;
struct wmTimer *smooth_timer;
diff --git a/source/blender/makesdna/DNA_view3d_types.h b/source/blender/makesdna/DNA_view3d_types.h
index b9894d46b5b..406f7434033 100644
--- a/source/blender/makesdna/DNA_view3d_types.h
+++ b/source/blender/makesdna/DNA_view3d_types.h
@@ -44,7 +44,7 @@ struct bGPdata;
struct SmoothView3DStore;
struct wmTimer;
struct Material;
-struct GPUFX;
+struct GPUViewport;
/* This is needed to not let VC choke on near and far... old
* proprietary MS extensions... */
@@ -65,23 +65,6 @@ struct GPUFX;
/* The near/far thing is a Win EXCEPTION. Thus, leave near/far in the
* code, and patch for windows. */
-
-/* Background Picture in 3D-View */
-typedef struct BGpic {
- struct BGpic *next, *prev;
-
- struct Image *ima;
- struct ImageUser iuser;
- struct MovieClip *clip;
- struct MovieClipUser cuser;
- float xof, yof, size, blend, rotation;
- short view;
- short flag;
- short source;
- char pad[6];
-} BGpic;
-
-/* ********************************* */
typedef struct RegionView3D {
@@ -111,8 +94,13 @@ typedef struct RegionView3D {
struct wmTimer *smooth_timer;
- /* transform widget matrix */
+ /* transform manipulator matrix */
float twmat[4][4];
+ /* min/max dot product on twmat xyz axis. */
+ float tw_axis_min[3], tw_axis_max[3];
+ float tw_axis_matrix[3][3];
+
+ float gridview;
float viewquat[4]; /* view rotation, must be kept normalized */
float dist; /* distance from 'ofs' along -viewinv[2] vector, where result is negative as is 'ofs' */
@@ -130,7 +118,7 @@ typedef struct RegionView3D {
char pad[3];
float ofs_lock[2]; /* normalized offset for locked view: (-1, -1) bottom left, (1, 1) upper right */
- short twdrawflag;
+ short twdrawflag; /* XXX can easily get rid of this (Julian) */
short rflag;
@@ -138,17 +126,39 @@ typedef struct RegionView3D {
float lviewquat[4];
short lpersp, lview; /* lpersp can never be set to 'RV3D_CAMOB' */
- float gridview;
- float tw_idot[3]; /* manipulator runtime: (1 - dot) product with view vector (used to check view alignment) */
-
-
/* active rotation from NDOF or elsewhere */
float rot_angle;
float rot_axis[3];
-
- struct GPUFX *compositor;
} RegionView3D;
+/* 3D Viewport Shading setings */
+typedef struct View3DShading {
+ short flag;
+ short color_type;
+
+ short light;
+ short studio_light;
+
+ float shadow_intensity;
+ float single_color[3];
+} View3DShading;
+
+/* 3D Viewport Overlay setings */
+typedef struct View3DOverlay {
+ int flag;
+
+ /* Edit mode settings */
+ int edit_flag;
+ float normals_length;
+ float backwire_opacity;
+
+ /* Paint mode settings */
+ int paint_flag;
+
+ /* Armature edit/pose mode settings */
+ int arm_flag;
+} View3DOverlay;
+
/* 3D ViewPort Struct */
typedef struct View3D {
struct SpaceLink *next, *prev;
@@ -173,9 +183,6 @@ typedef struct View3D {
struct Object *camera, *ob_centre;
rctf render_border;
- struct ListBase bgpicbase;
- struct BGpic *bgpic DNA_DEPRECATED; /* deprecated, use bgpicbase, only kept for do_versions(...) */
-
struct View3D *localvd; /* allocated backup of its self while in localview */
char ob_centre_bone[64]; /* optional string for armature bone to define center, MAXBONENAME */
@@ -183,13 +190,9 @@ typedef struct View3D {
unsigned int lay;
int layact;
- /**
- * The drawing mode for the 3d display. Set to OB_BOUNDBOX, OB_WIRE, OB_SOLID,
- * OB_TEXTURE, OB_MATERIAL or OB_RENDER */
- short drawtype;
short ob_centre_cursor; /* optional bool for 3d cursor to define center */
short scenelock, around;
- short flag, flag2;
+ short flag, flag2, pad2;
float lens, grid;
float near, far;
@@ -202,22 +205,16 @@ typedef struct View3D {
short gridsubdiv; /* Number of subdivisions in the grid between each highlighted grid line */
char gridflag;
- /* transform widget info */
- char twtype, twmode, twflag;
+ /* transform manipulator info */
+ char twtype, _pad5, twflag;
short flag3;
-
- /* afterdraw, for xray & transparent */
- struct ListBase afterdraw_transp;
- struct ListBase afterdraw_xray;
- struct ListBase afterdraw_xraytransp;
/* drawflags, denoting state */
char zbuf, transp, xray;
char multiview_eye; /* multiview current eye - for internal use */
- /* built-in shader effects (eGPUFXFlags) */
char pad3[4];
/* note, 'fx_settings.dof' is currently _not_ allocated,
@@ -225,13 +222,11 @@ typedef struct View3D {
struct GPUFXSettings fx_settings;
void *properties_storage; /* Nkey panel stores stuff here (runtime only!) */
- /* Allocated per view, not library data (used by matcap). */
- struct Material *defmaterial;
/* XXX deprecated? */
struct bGPdata *gpd DNA_DEPRECATED; /* Grease-Pencil Data (annotation layers) */
- /* multiview - stereo 3d */
+ /* Stereoscopy settings */
short stereo3d_flag;
char stereo3d_camera;
char pad4;
@@ -239,12 +234,13 @@ typedef struct View3D {
float stereo3d_volume_alpha;
float stereo3d_convergence_alpha;
- /* Previous viewport draw type.
- * Runtime-only, set in the rendered viewport toggle operator.
- */
- short prev_drawtype;
- short pad1;
- float pad2;
+ /* Display settings */
+ short drawtype; /* Shading mode (OB_SOLID, OB_TEXTURE, ..) */
+ short prev_drawtype; /* Runtime, for toggle between rendered viewport. */
+ int pad5;
+
+ View3DShading shading;
+ View3DOverlay overlay;
} View3D;
@@ -255,7 +251,7 @@ typedef struct View3D {
/* View3D->flag (short) */
/*#define V3D_DISPIMAGE 1*/ /*UNUSED*/
-#define V3D_DISPBGPICS 2
+/*#define V3D_DISPBGPICS 2*/ /* UNUSED */
#define V3D_HIDE_HELPLINES 4
#define V3D_INVALID_BACKBUF 8
@@ -274,7 +270,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 */
+/*#define RV3D_IS_GAME_ENGINE 32 *//* UNUSED */
/**
* Disable zbuffer offset, skip calls to #ED_view3d_polygon_offset.
* Use when precise surface depth is needed and picking bias isn't, see T45434).
@@ -315,12 +311,60 @@ typedef struct View3D {
#define V3D_SOLID_MATCAP (1 << 12) /* user flag */
#define V3D_SHOW_SOLID_MATCAP (1 << 13) /* runtime flag */
#define V3D_OCCLUDE_WIRE (1 << 14)
-#define V3D_SHADELESS_TEX (1 << 15)
+#define V3D_SHOW_MODE_SHADE_OVERRIDE (1 << 15)
/* View3d->flag3 (short) */
#define V3D_SHOW_WORLD (1 << 0)
+/* View3DShading->light */
+enum {
+ V3D_LIGHTING_FLAT = 0,
+ V3D_LIGHTING_STUDIO = 1,
+ V3D_LIGHTING_SCENE = 2
+};
+
+/* View3DShading->flag */
+enum {
+ V3D_SHADING_OBJECT_OVERLAP = (1 << 0),
+ V3D_SHADING_SHADOW = (1 << 2),
+};
+
+/* View3DShading->single_color_type */
+enum {
+ V3D_SHADING_MATERIAL_COLOR = 0,
+ V3D_SHADING_RANDOM_COLOR = 1,
+ V3D_SHADING_SINGLE_COLOR = 2,
+ V3D_SHADING_OBJECT_COLOR = 3,
+};
+
+/* View3DOverlay->flag */
+enum {
+ V3D_OVERLAY_FACE_ORIENTATION = (1 << 0),
+ V3D_OVERLAY_HIDE_CURSOR = (1 << 1),
+};
+
+/* View3DOverlay->edit_flag */
+enum {
+ V3D_OVERLAY_EDIT_VERT_NORMALS = (1 << 0),
+ V3D_OVERLAY_EDIT_LOOP_NORMALS = (1 << 1),
+ V3D_OVERLAY_EDIT_FACE_NORMALS = (1 << 2),
+
+ V3D_OVERLAY_EDIT_OCCLUDE_WIRE = (1 << 3),
+
+ V3D_OVERLAY_EDIT_WEIGHT = (1 << 4),
+};
+
+/* View3DOverlay->arm_flag */
+enum {
+ V3D_OVERLAY_ARM_TRANSP_BONES = (1 << 0),
+};
+
+/* View3DOverlay->paint_flag */
+enum {
+ V3D_OVERLAY_PAINT_WIRE = (1 << 0),
+};
+
/* View3D->around */
enum {
/* center of the bounding box */
@@ -351,49 +395,19 @@ enum {
#define V3D_SHOW_Y 4
#define V3D_SHOW_Z 8
-/* View3d->twtype (bits, we can combine them) */
-#define V3D_MANIP_TRANSLATE 1
-#define V3D_MANIP_ROTATE 2
-#define V3D_MANIP_SCALE 4
-
-/* View3d->twmode */
+/* Scene.orientation_type */
#define V3D_MANIP_GLOBAL 0
#define V3D_MANIP_LOCAL 1
#define V3D_MANIP_NORMAL 2
#define V3D_MANIP_VIEW 3
#define V3D_MANIP_GIMBAL 4
-#define V3D_MANIP_CUSTOM 5 /* anything of value 5 or higher is custom */
-
-/* View3d->twflag */
- /* USE = user setting, DRAW = based on selection */
-#define V3D_USE_MANIPULATOR 1
-#define V3D_DRAW_MANIPULATOR 2
-/* #define V3D_CALC_MANIPULATOR 4 */ /*UNUSED*/
+#define V3D_MANIP_CUSTOM 5
-/* BGPic->flag */
-/* may want to use 1 for select ? */
+/* View3d->twflag (also) */
enum {
- V3D_BGPIC_EXPANDED = (1 << 1),
- V3D_BGPIC_CAMERACLIP = (1 << 2),
- V3D_BGPIC_DISABLED = (1 << 3),
- V3D_BGPIC_FOREGROUND = (1 << 4),
-
- /* Camera framing options */
- V3D_BGPIC_CAMERA_ASPECT = (1 << 5), /* don't stretch to fit the camera view */
- V3D_BGPIC_CAMERA_CROP = (1 << 6), /* crop out the image */
-
- /* Axis flip options */
- V3D_BGPIC_FLIP_X = (1 << 7),
- V3D_BGPIC_FLIP_Y = (1 << 8),
+ V3D_MANIPULATOR_DRAW = (1 << 0),
};
-#define V3D_BGPIC_EXPANDED (V3D_BGPIC_EXPANDED | V3D_BGPIC_CAMERACLIP)
-
-/* BGPic->source */
-/* may want to use 1 for select ?*/
-#define V3D_BGPIC_IMAGE 0
-#define V3D_BGPIC_MOVIE 1
-
#define RV3D_CAMZOOM_MIN -30
#define RV3D_CAMZOOM_MAX 600
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index 20470ba862e..7d7fa5fcf23 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -32,6 +32,7 @@
#define __DNA_WINDOWMANAGER_TYPES_H__
#include "DNA_listBase.h"
+#include "DNA_screen_types.h"
#include "DNA_vec_types.h"
#include "DNA_userdef_types.h"
@@ -41,6 +42,7 @@
struct wmWindowManager;
struct wmWindow;
+struct wmMsgBus;
struct wmEvent;
struct wmGesture;
struct wmOperatorType;
@@ -159,12 +161,15 @@ typedef struct wmWindowManager {
char is_interface_locked; /* indicates whether interface is locked for user interaction */
char par[7];
+
+ struct wmMsgBus *message_bus;
+
} wmWindowManager;
/* wmWindowManager.initialized */
enum {
- WM_INIT_WINDOW = (1<<0),
- WM_INIT_KEYMAP = (1<<1),
+ WM_WINDOW_IS_INITIALIZED = (1<<0),
+ WM_KEYMAP_IS_INITIALIZED = (1<<1),
};
/* IME is win32 only! */
@@ -179,10 +184,18 @@ typedef struct wmWindow {
struct wmWindow *next, *prev;
void *ghostwin; /* don't want to include ghost.h stuff */
+ void *gwnctx; /* don't want to include gawin stuff */
+
+ struct Scene *scene; /* The scene displayed in this window. */
+ struct Scene *new_scene; /* temporary when switching */
+
+ struct WorkSpaceInstanceHook *workspace_hook;
- struct bScreen *screen; /* active screen */
- struct bScreen *newscreen; /* temporary when switching */
- char screenname[64]; /* MAX_ID_NAME for matching window with active screen after file read */
+ /** Global areas aren't part of the screen, but part of the window directly.
+ * \note Code assumes global areas with fixed height, fixed width not supported yet */
+ ScrAreaMap global_areas;
+
+ struct bScreen *screen DNA_DEPRECATED;
short posx, posy, sizex, sizey; /* window coords */
short windowstate; /* borderless, full */
@@ -193,8 +206,7 @@ typedef struct wmWindow {
short modalcursor; /* the current modal cursor */
short grabcursor; /* cursor grab mode */
short addmousemove; /* internal: tag this for extra mousemove event, makes cursors/buttons active on UI switching */
- short multisamples; /* amount of samples for OpenGL FSA the ghost window was created with, if zero no FSA */
- short pad[3];
+ short pad[4];
int winid; /* winid also in screens, is for retrieving this window after read */
@@ -204,22 +216,16 @@ typedef struct wmWindow {
struct wmEvent *eventstate; /* storage for event system */
- struct wmSubWindow *curswin; /* internal for wm_subwindow.c only */
-
struct wmGesture *tweak; /* internal for wm_operators.c */
/* Input Method Editor data - complex character input (esp. for asian character input)
* Currently WIN32, runtime-only data */
struct wmIMEData *ime_data;
- int drawmethod, drawfail; /* internal for wm_draw.c only */
- ListBase drawdata; /* internal for wm_draw.c only */
-
ListBase queue; /* all events (ghost level events were handled) */
ListBase handlers; /* window+screen handlers, handled last */
ListBase modalhandlers; /* priority handlers, handled first */
- ListBase subwindows; /* opengl stuff for sub windows, see notes in wm_subwindow.c */
ListBase gesture; /* gesture stuff */
struct Stereo3dFormat *stereo3d_format; /* properties for stereoscopic displays */
@@ -311,6 +317,7 @@ typedef struct wmKeyMap {
char idname[64]; /* global editor keymaps, or for more per space/region */
short spaceid; /* same IDs as in DNA_space_types.h */
short regionid; /* see above */
+ char owner_id[64]; /* optional, see: #wmOwnerID */
short flag; /* general flags */
short kmi_id; /* last kmi id */
@@ -371,6 +378,10 @@ typedef struct wmOperator {
struct uiLayout *layout; /* runtime for drawing */
short flag, pad[3];
+ /* Screen context the operator was finished in. It gets temporarily
+ * restored during operator repeat. Only set for registered operators. */
+ struct ScrArea *execution_area;
+ struct ARegion *execution_region;
} wmOperator;
/* operator type return flags: exec(), invoke() modal(), return values */
diff --git a/source/blender/makesdna/DNA_workspace_types.h b/source/blender/makesdna/DNA_workspace_types.h
new file mode 100644
index 00000000000..4cc3929b4ea
--- /dev/null
+++ b/source/blender/makesdna/DNA_workspace_types.h
@@ -0,0 +1,163 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file DNA_workspace_types.h
+ * \ingroup DNA
+ *
+ * Use API in BKE_workspace.h!
+ * Struct members marked with DNA_PRIVATE_WORKSPACE will throw a
+ * warning saying it's deprecated when used outside of workspace.c.
+ */
+
+#ifndef __DNA_WORKSPACE_TYPES_H__
+#define __DNA_WORKSPACE_TYPES_H__
+
+#include "DNA_scene_types.h"
+
+/* Same logic as DNA_DEPRECATED_ALLOW, but throws 'deprecated'
+ * warnings if DNA_PRIVATE_WORKSPACE_ALLOW is not defined */
+#ifdef DNA_PRIVATE_WORKSPACE_ALLOW
+ /* allow use of private items */
+# define DNA_PRIVATE_WORKSPACE
+#else
+# ifndef DNA_PRIVATE_WORKSPACE
+# define DNA_PRIVATE_WORKSPACE DNA_PRIVATE_ATTR
+# endif
+#endif
+
+#ifdef DNA_PRIVATE_READ_WRITE_ALLOW
+# define DNA_PRIVATE_WORKSPACE_READ_WRITE
+#else
+# ifndef DNA_PRIVATE_WORKSPACE_READ_WRITE
+# define DNA_PRIVATE_WORKSPACE_READ_WRITE DNA_PRIVATE_WORKSPACE
+# endif
+#endif
+
+/* Currently testing, allow to disable. */
+#define USE_WORKSPACE_TOOL
+
+typedef struct bToolDef {
+ /* One of these must be defined. */
+ char keymap[64];
+ char manipulator_group[64];
+ char data_block[64];
+
+ int spacetype;
+ /* index when a tool is a member of a group */
+ int index;
+} bToolDef;
+
+/**
+ * \brief Wrapper for bScreen.
+ *
+ * bScreens are IDs and thus stored in a main list-base. We also want to store a list-base of them within the
+ * workspace (so each workspace can have its own set of screen-layouts) which would mess with the next/prev pointers.
+ * So we use this struct to wrap a bScreen pointer with another pair of next/prev pointers.
+ */
+typedef struct WorkSpaceLayout {
+ struct WorkSpaceLayout *next, *prev;
+
+ struct bScreen *screen DNA_PRIVATE_WORKSPACE;
+ /* The name of this layout, we override the RNA name of the screen with this (but not ID name itself) */
+ char name[64] DNA_PRIVATE_WORKSPACE; /* MAX_NAME */
+} WorkSpaceLayout;
+
+/** Optional tags, which features to use, aligned with #bAddon names by convention. */
+typedef struct wmOwnerID {
+ struct wmOwnerID *next, *prev;
+ char name[64] DNA_PRIVATE_WORKSPACE; /* MAX_NAME */
+} wmOwnerID;
+
+typedef struct WorkSpace {
+ ID id;
+
+ ListBase layouts DNA_PRIVATE_WORKSPACE; /* WorkSpaceLayout */
+ /* Store for each hook (so for each window) which layout has
+ * been activated the last time this workspace was visible. */
+ ListBase hook_layout_relations DNA_PRIVATE_WORKSPACE_READ_WRITE; /* WorkSpaceDataRelation */
+ ListBase scene_viewlayer_relations DNA_PRIVATE_WORKSPACE_READ_WRITE; /* WorkSpaceDataRelation */
+
+ /* Feature tagging (use for addons) */
+ ListBase owner_ids DNA_PRIVATE_WORKSPACE_READ_WRITE; /* wmOwnerID */
+
+ int pad;
+ int flags DNA_PRIVATE_WORKSPACE; /* enum eWorkSpaceFlags */
+
+ /* should be: '#ifdef USE_WORKSPACE_TOOL'. */
+ bToolDef tool;
+
+ struct ViewLayer *view_layer DNA_DEPRECATED;
+} WorkSpace;
+
+/* internal struct, but exported for read/write */
+#if defined(DNA_PRIVATE_READ_WRITE_ALLOW) || defined(DNA_PRIVATE_WORKSPACE_ALLOW)
+
+/**
+ * Generic (and simple/primitive) struct for storing a history of assignments/relations
+ * of workspace data to non-workspace data in a listbase inside the workspace.
+ *
+ * Using this we can restore the old state of a workspace if the user switches back to it.
+ *
+ * Usage
+ * =====
+ * When activating a workspace, it should activate the screen-layout that was active in that
+ * workspace before *in this window*.
+ * More concretely:
+ * * There are two windows, win1 and win2.
+ * * Both show workspace ws1, but both also had workspace ws2 activated at some point before.
+ * * Last time ws2 was active in win1, screen-layout sl1 was activated.
+ * * Last time ws2 was active in win2, screen-layout sl2 was activated.
+ * * When changing from ws1 to ws2 in win1, screen-layout sl1 should be activated again.
+ * * When changing from ws1 to ws2 in win2, screen-layout sl2 should be activated again.
+ * So that means we have to store the active screen-layout in a per workspace, per window
+ * relation. This struct is used to store an active screen-layout for each window within the
+ * workspace.
+ * To find the screen-layout to activate for this window-workspace combination, simply lookup
+ * the WorkSpaceDataRelation with the workspace-hook of the window set as parent.
+ */
+typedef struct WorkSpaceDataRelation {
+ struct WorkSpaceDataRelation *next, *prev;
+
+ /* the data used to identify the relation (e.g. to find screen-layout (= value) from/for a hook) */
+ void *parent;
+ /* The value for this parent-data/workspace relation */
+ void *value;
+} WorkSpaceDataRelation;
+
+#endif /* DNA_PRIVATE_WORKSPACE_READ_WRITE */
+
+/**
+ * Little wrapper to store data that is going to be per window, but comming from the workspace.
+ * It allows us to keep workspace and window data completely separate.
+ */
+typedef struct WorkSpaceInstanceHook {
+ WorkSpace *active DNA_PRIVATE_WORKSPACE;
+ struct WorkSpaceLayout *act_layout DNA_PRIVATE_WORKSPACE;
+
+ /* Needed because we can't change workspaces/layouts in running handler loop, it would break context. */
+ WorkSpace *temp_workspace_store;
+ struct WorkSpaceLayout *temp_layout_store;
+} WorkSpaceInstanceHook;
+
+typedef enum eWorkSpaceFlags {
+ WORKSPACE_USE_FILTER_BY_ORIGIN = (1 << 1),
+} eWorkSpaceFlags;
+
+#endif /* __DNA_WORKSPACE_TYPES_H__ */
diff --git a/source/blender/makesdna/DNA_world_types.h b/source/blender/makesdna/DNA_world_types.h
index 5fd4c9fd407..ac93033609d 100644
--- a/source/blender/makesdna/DNA_world_types.h
+++ b/source/blender/makesdna/DNA_world_types.h
@@ -47,8 +47,7 @@ struct MTex;
/**
* World defines general modeling data such as a background fill,
- * gravity, color model etc. It mixes game-data, rendering
- * data and modeling data. */
+ * gravity, color model etc. It mixes rendering data and modeling data. */
typedef struct World {
ID id;
struct AnimData *adt; /* animation data (must be immediately after id for utilities to use it) */
@@ -57,8 +56,6 @@ typedef struct World {
short texact, mistype;
float horr, horg, horb;
- float zenr, zeng, zenb;
- float ambr, ambg, ambb;
/**
* Exposure= mult factor. unused now, but maybe back later. Kept in to be upward compat.
@@ -67,60 +64,25 @@ typedef struct World {
*/
float exposure, exp, range;
float linfac, logfac;
-
- /**
- * Gravitation constant for the game world
- */
- float gravity; // XXX moved to scene->gamedata in 2.5
-
- /**
- * Radius of the activity bubble, in Manhattan length. Objects
- * outside the box are activity-culled. */
- float activityBoxRadius; // XXX moved to scene->gamedata in 2.5
- short skytype;
/**
* Some world modes
* bit 0: Do mist
- * bit 1: Do stars
- * bit 2: (reserved) depth of field
- * bit 3: (gameengine): Activity culling is enabled.
- * bit 4: ambient occlusion
- * bit 5: (gameengine) : enable Bullet DBVT tree for view frustum culling
*/
short mode; // partially moved to scene->gamedata in 2.5
- short occlusionRes; /* resolution of occlusion Z buffer in pixel */ // XXX moved to scene->gamedata in 2.5
- short physicsEngine; /* here it's aligned */ // XXX moved to scene->gamedata in 2.5
- short ticrate, maxlogicstep, physubstep, maxphystep; // XXX moved to scene->gamedata in 2.5
-
+ short pad2[3];
+
float misi, miststa, mistdist, misthi;
-
- float starr DNA_DEPRECATED, starg DNA_DEPRECATED, starb DNA_DEPRECATED, stark DNA_DEPRECATED; /* Deprecated */
- float starsize DNA_DEPRECATED, starmindist DNA_DEPRECATED;
- float stardist DNA_DEPRECATED, starcolnoise DNA_DEPRECATED;
-
- /* unused now: DOF */
- short dofsta, dofend, dofmin, dofmax;
-
+
/* ambient occlusion */
- float aodist, aodistfac, aoenergy, aobias;
- short aomode, aosamp, aomix, aocolor;
- float ao_adapt_thresh, ao_adapt_speed_fac;
- float ao_approx_error, ao_approx_correction;
- float ao_indirect_energy, ao_env_energy, ao_pad2;
- short ao_indirect_bounces, ao_pad;
- short ao_samp_method, ao_gather_method, ao_approx_passes;
-
- /* assorted settings (in the middle of ambient occlusion settings for padding reasons) */
- short flag;
-
- /* ambient occlusion (contd...) */
- float *aosphere, *aotables;
+ float aodist, aoenergy;
+ /* assorted settings */
+ short flag, pad3[3];
struct Ipo *ipo DNA_DEPRECATED; /* old animation system, deprecated for 2.5 */
- struct MTex *mtex[18]; /* MAX_MTEX */
- short pr_texture, use_nodes, pad[2];
+ short pr_texture, use_nodes, pad;
+ short update_flag; /* XXX temporary flag waiting for depsgraph proper tagging */
/* previews */
struct PreviewImage *preview;
@@ -128,71 +90,28 @@ typedef struct World {
/* nodes */
struct bNodeTree *nodetree;
+ float mistend, pad1; /* runtime : miststa + mistdist, used for drawing camera */
ListBase gpumaterial; /* runtime */
} World;
/* **************** WORLD ********************* */
-/* skytype */
-#define WO_SKYBLEND 1
-#define WO_SKYREAL 2
-#define WO_SKYPAPER 4
-/* while render: */
-#define WO_SKYTEX 8
-#define WO_ZENUP 16
-
/* mode */
#define WO_MIST 1
//#define WO_STARS 2 /* deprecated */
/*#define WO_DOF 4*/
-#define WO_ACTIVITY_CULLING 8
-#define WO_ENV_LIGHT 16
-#define WO_DBVT_CULLING 32
+//#define WO_ACTIVITY_CULLING 8 /* deprecated */
+//#define WO_ENV_LIGHT 16
+//#define WO_DBVT_CULLING 32 /* deprecated */
#define WO_AMB_OCC 64
-#define WO_INDIRECT_LIGHT 128
+//#define WO_INDIRECT_LIGHT 128
-/* aomix */
enum {
- WO_AOADD = 0,
-#ifdef DNA_DEPRECATED
- WO_AOSUB = 1, /* deprecated */
- WO_AOADDSUB = 2, /* deprecated */
-#endif
- WO_AOMUL = 3,
+ WO_MIST_QUADRATIC = 0,
+ WO_MIST_LINEAR = 1,
+ WO_MIST_INVERSE_QUADRATIC = 2,
};
-/* ao_samp_method - methods for sampling the AO hemi */
-#define WO_AOSAMP_CONSTANT 0
-#define WO_AOSAMP_HALTON 1
-#define WO_AOSAMP_HAMMERSLEY 2
-
-/* aomode (use distances & random sampling modes) */
-#define WO_AODIST 1
-#define WO_AORNDSMP 2
-#define WO_AOCACHE 4
-
-/* aocolor */
-#define WO_AOPLAIN 0
-#define WO_AOSKYCOL 1
-#define WO_AOSKYTEX 2
-
-/* ao_gather_method */
-#define WO_AOGATHER_RAYTRACE 0
-#define WO_AOGATHER_APPROX 1
-
-/* texco (also in DNA_material_types.h) */
-#define TEXCO_ANGMAP 64
-#define TEXCO_H_SPHEREMAP 256
-#define TEXCO_H_TUBEMAP 1024
-#define TEXCO_EQUIRECTMAP 2048
-
-/* mapto */
-#define WOMAP_BLEND 1
-#define WOMAP_HORIZ 2
-#define WOMAP_ZENUP 4
-#define WOMAP_ZENDOWN 8
-// #define WOMAP_MIST 16 /* Deprecated */
-
/* flag */
#define WO_DS_EXPAND (1<<0)
/* NOTE: this must have the same value as MA_DS_SHOW_TEXS,
diff --git a/source/blender/makesdna/intern/dna_genfile.c b/source/blender/makesdna/intern/dna_genfile.c
index 2e21223d042..c9385f98584 100644
--- a/source/blender/makesdna/intern/dna_genfile.c
+++ b/source/blender/makesdna/intern/dna_genfile.c
@@ -313,10 +313,52 @@ BLI_INLINE const char *pad_up_4(const char *ptr)
}
/**
+ * Temporary DNA doversion for files that were created with Blender 2.80
+ * between October 2016, and November 2017 (>=280.0 and < 280.2).
+ *
+ * /note This would be way more efficient if we can get the version from SDNA
+ * So we could return true if version == 280 && subversion < 2.
+ *
+ * Returns true if we need to do the DNA renaming.
+ */
+static bool need_doversion_280(SDNA *sdna, int *data, const bool data_alloc)
+{
+ if (data_alloc == false) {
+ return false;
+ }
+
+ bool active_layer = false, render_layers = false;
+
+ const char *cp = (char *)data;
+ for (int nr = 0; nr < sdna->nr_names; nr++) {
+ if (strcmp(cp, "active_layer") == 0) {
+ active_layer = true;
+ if (active_layer && render_layers) {
+ return true;
+ }
+ }
+ else if (strcmp(cp, "render_layers") == 0) {
+ render_layers = true;
+ if (active_layer && render_layers) {
+ return true;
+ }
+ }
+
+ while (*cp) cp++;
+ cp++;
+ }
+
+ /* If someone adds only one of them to the DNA, don't! */
+ BLI_assert(!(active_layer || render_layers));
+ return false;
+}
+
+/**
* In sdna->data the data, now we convert that to something understandable
*/
static bool init_structDNA(
SDNA *sdna, bool do_endian_swap,
+ bool data_alloc,
const char **r_error_message)
{
int *data, *verg, gravity_fix = -1;
@@ -361,6 +403,10 @@ static bool init_structDNA(
*r_error_message = "NAME error in SDNA file";
return false;
}
+
+ /* Temporary DNA doversion for files that were created with Blender 2.80
+ * between 280.0 and 280.2. */
+ const bool doversion_280 = need_doversion_280(sdna, data, data_alloc);
cp = (char *)data;
for (int nr = 0; nr < sdna->nr_names; nr++) {
@@ -375,6 +421,28 @@ static bool init_structDNA(
gravity_fix = nr;
}
}
+ else if (doversion_280) {
+ if (strcmp(cp, "*render_layer") == 0) {
+ /* WorkSpace. */
+ sdna->names[nr] = "*view_layer";
+ }
+ else if (strcmp(cp, "*scene_layer") == 0) {
+ /* ParticleEditSettings. */
+ sdna->names[nr] = "*view_layer";
+ }
+ else if (strcmp(cp, "render_layers") == 0) {
+ /* Scene. */
+ sdna->names[nr] = "view_layers";
+ }
+ else if (strcmp(cp, "active_layer") == 0) {
+ /* Scene. */
+ sdna->names[nr] = "active_view_layer";
+ }
+ else if (strcmp(cp, "*cur_render_layer") == 0) {
+ /* FileGlobal. */
+ sdna->names[nr] = "*cur_view_layer";
+ }
+ }
while (*cp) cp++;
cp++;
@@ -412,6 +480,14 @@ static bool init_structDNA(
/* struct Screen was already used by X, 'bScreen' replaces the old IrisGL 'Screen' struct */
if (strcmp("bScreen", cp) == 0) sdna->types[nr] = cp + 1;
}
+ else if (doversion_280) {
+ if (strcmp(cp, "SceneLayer") == 0) {
+ sdna->types[nr] = "ViewLayer";
+ }
+ else if (strcmp(cp, "SceneLayerEngineData") == 0) {
+ sdna->types[nr] = "ViewLayerEngineData";
+ }
+ }
while (*cp) cp++;
cp++;
@@ -554,7 +630,7 @@ SDNA *DNA_sdna_from_data(
sdna->data_alloc = data_alloc;
- if (init_structDNA(sdna, do_endian_swap, &error_message)) {
+ if (init_structDNA(sdna, do_endian_swap, data_alloc, &error_message)) {
return sdna;
}
else {
diff --git a/source/blender/makesdna/intern/makesdna.c b/source/blender/makesdna/intern/makesdna.c
index a5f474b93bf..c1f8341ddc6 100644
--- a/source/blender/makesdna/intern/makesdna.c
+++ b/source/blender/makesdna/intern/makesdna.c
@@ -100,10 +100,6 @@ static const char *includefiles[] = {
"DNA_sequence_types.h",
"DNA_effect_types.h",
"DNA_outliner_types.h",
- "DNA_property_types.h",
- "DNA_sensor_types.h",
- "DNA_controller_types.h",
- "DNA_actuator_types.h",
"DNA_sound_types.h",
"DNA_group_types.h",
"DNA_armature_types.h",
@@ -130,6 +126,10 @@ static const char *includefiles[] = {
"DNA_freestyle_types.h",
"DNA_linestyle_types.h",
"DNA_cachefile_types.h",
+ "DNA_layer_types.h",
+ "DNA_workspace_types.h",
+ "DNA_lightprobe_types.h",
+
/* see comment above before editing! */
/* empty string to indicate end of includefiles */
@@ -504,6 +504,17 @@ static int preprocess_include(char *maindata, int len)
a -= 13;
cp += 13;
}
+ else if (strncmp("DNA_PRIVATE_WORKSPACE", cp, 21) == 0) {
+ /* Check for DNA_PRIVATE_WORKSPACE_READ_WRITE */
+ if (strncmp("_READ_WRITE", cp + 21, 11) == 0) {
+ a -= 31;
+ cp += 31;
+ }
+ else {
+ a -= 20;
+ cp += 20;
+ }
+ }
else {
md[0] = cp[0];
md++;
@@ -1313,10 +1324,6 @@ int main(int argc, char **argv)
#include "DNA_sequence_types.h"
#include "DNA_effect_types.h"
#include "DNA_outliner_types.h"
-#include "DNA_property_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
#include "DNA_sound_types.h"
#include "DNA_group_types.h"
#include "DNA_armature_types.h"
@@ -1343,4 +1350,8 @@ int main(int argc, char **argv)
#include "DNA_freestyle_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_cachefile_types.h"
+#include "DNA_layer_types.h"
+#include "DNA_workspace_types.h"
+#include "DNA_lightprobe_types.h"
+
/* end of list */
diff --git a/source/blender/makesrna/RNA_access.h b/source/blender/makesrna/RNA_access.h
index e512aebfa71..70a6759b4e8 100644
--- a/source/blender/makesrna/RNA_access.h
+++ b/source/blender/makesrna/RNA_access.h
@@ -39,6 +39,9 @@ extern "C" {
struct bContext;
struct ID;
+struct IDOverrideStatic;
+struct IDOverrideStaticProperty;
+struct IDOverrideStaticPropertyOperation;
struct ListBase;
struct Main;
struct ReportList;
@@ -106,6 +109,7 @@ extern StructRNA RNA_ClothCollisionSettings;
extern StructRNA RNA_ClothModifier;
extern StructRNA RNA_ClothSettings;
extern StructRNA RNA_CloudsTexture;
+extern StructRNA RNA_CollectionEngineSettings;
extern StructRNA RNA_CollectionProperty;
extern StructRNA RNA_CollisionModifier;
extern StructRNA RNA_CollisionSensor;
@@ -204,6 +208,8 @@ extern StructRNA RNA_CurveMapPoint;
extern StructRNA RNA_CurveMapping;
extern StructRNA RNA_CurveModifier;
extern StructRNA RNA_CurvePoint;
+extern StructRNA RNA_Depsgraph;
+extern StructRNA RNA_DepsgraphIter;
extern StructRNA RNA_DampedTrackConstraint;
extern StructRNA RNA_DataTransferModifier;
extern StructRNA RNA_DecimateModifier;
@@ -228,11 +234,10 @@ extern StructRNA RNA_EffectSequence;
extern StructRNA RNA_EffectorWeights;
extern StructRNA RNA_EnumProperty;
extern StructRNA RNA_EnumPropertyItem;
-extern StructRNA RNA_EnvironmentMap;
-extern StructRNA RNA_EnvironmentMapTexture;
extern StructRNA RNA_Event;
extern StructRNA RNA_ExplodeModifier;
extern StructRNA RNA_ExpressionController;
+extern StructRNA RNA_FaceMap;
extern StructRNA RNA_FCurve;
extern StructRNA RNA_FCurveSample;
extern StructRNA RNA_FFmpegSettings;
@@ -270,14 +275,6 @@ extern StructRNA RNA_GPencilStroke;
extern StructRNA RNA_GPencilStrokePoint;
extern StructRNA RNA_GPencilSculptSettings;
extern StructRNA RNA_GPencilSculptBrush;
-extern StructRNA RNA_GameBooleanProperty;
-extern StructRNA RNA_GameFloatProperty;
-extern StructRNA RNA_GameIntProperty;
-extern StructRNA RNA_GameObjectSettings;
-extern StructRNA RNA_GameProperty;
-extern StructRNA RNA_GameSoftBodySettings;
-extern StructRNA RNA_GameStringProperty;
-extern StructRNA RNA_GameTimerProperty;
extern StructRNA RNA_GaussianBlurSequence;
extern StructRNA RNA_GlowSequence;
extern StructRNA RNA_GreasePencil;
@@ -287,6 +284,8 @@ extern StructRNA RNA_HemiLamp;
extern StructRNA RNA_Histogram;
extern StructRNA RNA_HookModifier;
extern StructRNA RNA_ID;
+extern StructRNA RNA_IDOverrideStatic;
+extern StructRNA RNA_IDOverrideStaticProperty;
extern StructRNA RNA_IKParam;
extern StructRNA RNA_Image;
extern StructRNA RNA_ImageFormatSettings;
@@ -320,6 +319,8 @@ extern StructRNA RNA_LaplacianSmoothModifier;
extern StructRNA RNA_Lattice;
extern StructRNA RNA_LatticeModifier;
extern StructRNA RNA_LatticePoint;
+extern StructRNA RNA_LayerCollection;
+extern StructRNA RNA_LayerCollectionOverride;
extern StructRNA RNA_Library;
extern StructRNA RNA_LimitDistanceConstraint;
extern StructRNA RNA_LimitLocationConstraint;
@@ -373,19 +374,14 @@ extern StructRNA RNA_LineStyleThicknessModifier_Tangent;
extern StructRNA RNA_LockedTrackConstraint;
extern StructRNA RNA_Macro;
extern StructRNA RNA_MagicTexture;
+extern StructRNA RNA_Manipulator;
+extern StructRNA RNA_ManipulatorProperties;
extern StructRNA RNA_MarbleTexture;
extern StructRNA RNA_MaskModifier;
extern StructRNA RNA_MaskSequence;
extern StructRNA RNA_Material;
-extern StructRNA RNA_MaterialHalo;
-extern StructRNA RNA_MaterialPhysics;
extern StructRNA RNA_MaterialRaytraceMirror;
-extern StructRNA RNA_MaterialRaytraceTransparency;
extern StructRNA RNA_MaterialSlot;
-extern StructRNA RNA_MaterialStrand;
-extern StructRNA RNA_MaterialSubsurfaceScattering;
-extern StructRNA RNA_MaterialTextureSlot;
-extern StructRNA RNA_MaterialVolume;
extern StructRNA RNA_Mask;
extern StructRNA RNA_MaskLayer;
extern StructRNA RNA_Menu;
@@ -479,12 +475,11 @@ extern StructRNA RNA_ParticleSystemModifier;
extern StructRNA RNA_ParticleTarget;
extern StructRNA RNA_PivotConstraint;
extern StructRNA RNA_PointCache;
-extern StructRNA RNA_PointDensity;
-extern StructRNA RNA_PointDensityTexture;
extern StructRNA RNA_PointLamp;
extern StructRNA RNA_PointerProperty;
extern StructRNA RNA_Pose;
extern StructRNA RNA_PoseBone;
+extern StructRNA RNA_LightProbe;
extern StructRNA RNA_Property;
extern StructRNA RNA_PropertyGroup;
extern StructRNA RNA_PropertyGroupItem;
@@ -500,12 +495,13 @@ extern StructRNA RNA_RenderLayer;
extern StructRNA RNA_RenderPass;
extern StructRNA RNA_RenderResult;
extern StructRNA RNA_RenderSettings;
+extern StructRNA RNA_RenderEngineSettings;
+extern StructRNA RNA_RenderEngineSettingsClay;
extern StructRNA RNA_RigidBodyWorld;
extern StructRNA RNA_RigidBodyObject;
extern StructRNA RNA_RigidBodyJointConstraint;
extern StructRNA RNA_SPHFluidSettings;
extern StructRNA RNA_Scene;
-extern StructRNA RNA_SceneGameData;
extern StructRNA RNA_SceneRenderLayer;
extern StructRNA RNA_SceneSequence;
extern StructRNA RNA_SceneObjects;
@@ -575,14 +571,12 @@ extern StructRNA RNA_SpaceFileBrowser;
extern StructRNA RNA_SpaceGraphEditor;
extern StructRNA RNA_SpaceImageEditor;
extern StructRNA RNA_SpaceInfo;
-extern StructRNA RNA_SpaceLogicEditor;
extern StructRNA RNA_SpaceNLA;
extern StructRNA RNA_SpaceNodeEditor;
extern StructRNA RNA_SpaceOutliner;
extern StructRNA RNA_SpaceProperties;
extern StructRNA RNA_SpaceSequenceEditor;
extern StructRNA RNA_SpaceTextEditor;
-extern StructRNA RNA_SpaceTimeline;
extern StructRNA RNA_SpaceUVEditor;
extern StructRNA RNA_SpaceUserPreferences;
extern StructRNA RNA_SpaceView3D;
@@ -656,7 +650,6 @@ extern StructRNA RNA_ThemeSpaceGradient;
extern StructRNA RNA_ThemeSpaceListGeneric;
extern StructRNA RNA_ThemeStyle;
extern StructRNA RNA_ThemeTextEditor;
-extern StructRNA RNA_ThemeTimeline;
extern StructRNA RNA_ThemeUserInterface;
extern StructRNA RNA_ThemeUserPreferences;
extern StructRNA RNA_ThemeView3D;
@@ -671,6 +664,7 @@ extern StructRNA RNA_TransformSequence;
extern StructRNA RNA_UILayout;
extern StructRNA RNA_UIList;
extern StructRNA RNA_UIPieMenu;
+extern StructRNA RNA_uiPopover;
extern StructRNA RNA_UIPopupMenu;
extern StructRNA RNA_UVWarpModifier;
extern StructRNA RNA_UVProjectModifier;
@@ -690,18 +684,21 @@ extern StructRNA RNA_VertexGroup;
extern StructRNA RNA_VertexGroupElement;
extern StructRNA RNA_VertexPaint;
extern StructRNA RNA_VoronoiTexture;
-extern StructRNA RNA_VoxelData;
-extern StructRNA RNA_VoxelDataTexture;
extern StructRNA RNA_WarpModifier;
extern StructRNA RNA_WaveModifier;
extern StructRNA RNA_VertexWeightEditModifier;
extern StructRNA RNA_VertexWeightMixModifier;
extern StructRNA RNA_VertexWeightProximityModifier;
+extern StructRNA RNA_View3DOverlay;
+extern StructRNA RNA_View3DShading;
+extern StructRNA RNA_ViewLayer;
extern StructRNA RNA_Window;
extern StructRNA RNA_WindowManager;
extern StructRNA RNA_WipeSequence;
extern StructRNA RNA_WireframeModifier;
extern StructRNA RNA_WoodTexture;
+extern StructRNA RNA_WorkSpace;
+extern StructRNA RNA_wmOwnerIDs;
extern StructRNA RNA_World;
extern StructRNA RNA_WorldAmbientOcclusion;
extern StructRNA RNA_WorldLighting;
@@ -880,6 +877,10 @@ bool RNA_property_editable_index(PointerRNA *ptr, PropertyRNA *prop, int index);
bool RNA_property_editable_flag(PointerRNA *ptr, PropertyRNA *prop); /* without lib check, only checks the flag */
bool RNA_property_animateable(PointerRNA *ptr, PropertyRNA *prop);
bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop);
+bool RNA_property_overridable_get(PointerRNA *ptr, PropertyRNA *prop);
+bool RNA_property_overridable_static_set(PointerRNA *ptr, PropertyRNA *prop, const bool is_overridable);
+bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop);
+bool RNA_property_comparable(PointerRNA *ptr, PropertyRNA *prop);
bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop); /* slow, use with care */
void RNA_property_update(struct bContext *C, PointerRNA *ptr, PropertyRNA *prop);
@@ -1031,7 +1032,7 @@ char *RNA_path_property_py(struct PointerRNA *ptr, struct PropertyRNA *prop, int
* call RNA_struct_find_property. The names have to exist as RNA properties
* for the type in the pointer, if they do not exist an error will be printed.
*
- * There is no support for pointers and collections here yet, these can be
+ * There is no support for pointers and collections here yet, these can be
* added when ID properties support them. */
int RNA_boolean_get(PointerRNA *ptr, const char *name);
@@ -1223,17 +1224,77 @@ StructRNA *ID_code_to_RNA_type(short idcode);
void _RNA_warning(const char *format, ...) ATTR_PRINTF_FORMAT(1, 2);
-/* Equals test (skips pointers and collections)
- * is_strict false assumes uninitialized properties are equal */
+/* Equals test. */
+
+/* Note: In practice, EQ_STRICT and EQ_COMPARE have same behavior currently, and will yield same result. */
+typedef enum eRNACompareMode {
+ /* Only care about equality, not full comparison. */
+ RNA_EQ_STRICT, /* set/unset ignored */
+ RNA_EQ_UNSET_MATCH_ANY, /* unset property matches anything */
+ RNA_EQ_UNSET_MATCH_NONE, /* unset property never matches set property */
+ /* Full comparison. */
+ RNA_EQ_COMPARE,
+} eRNACompareMode;
+
+bool RNA_property_equals(struct PointerRNA *ptr_a, struct PointerRNA *ptr_b, struct PropertyRNA *prop, eRNACompareMode mode);
+bool RNA_struct_equals(struct PointerRNA *ptr_a, struct PointerRNA *ptr_b, eRNACompareMode mode);
+
+/* Override. */
+
+/* flags for RNA_struct_override_matches. */
+typedef enum eRNAOverrideMatch {
+ /* Do not compare properties that are not overridable. */
+ RNA_OVERRIDE_COMPARE_IGNORE_NON_OVERRIDABLE = 1 << 0,
+ /* Do not compare properties that are already overridden. */
+ RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN = 1 << 1,
+
+ /* Create new property override if needed and possible. */
+ RNA_OVERRIDE_COMPARE_CREATE = 1 << 16,
+ /* Restore property's value(s) to reference ones if needed and possible. */
+ RNA_OVERRIDE_COMPARE_RESTORE = 1 << 17,
+} eRNAOverrideMatch;
+
+typedef enum eRNAOverrideMatchResult {
+ /* Some new property overrides were created to take into account differences between local and reference. */
+ RNA_OVERRIDE_MATCH_RESULT_CREATED = 1 << 0,
+ /* Some properties were reset to reference values. */
+ RNA_OVERRIDE_MATCH_RESULT_RESTORED = 1 << 1,
+} eRNAOverrideMatchResult;
+
+typedef enum eRNAOverrideStatus {
+ RNA_OVERRIDE_STATUS_OVERRIDABLE = 1 << 0, /* The property is overridable. */
+ RNA_OVERRIDE_STATUS_OVERRIDDEN = 1 << 1, /* The property is overridden. */
+ RNA_OVERRIDE_STATUS_MANDATORY = 1 << 2, /* Overriding this property is mandatory when creating an override. */
+ RNA_OVERRIDE_STATUS_LOCKED = 1 << 3, /* The override status of this property is locked. */
+} eRNAOverrideStatus;
+
+bool RNA_struct_override_matches(
+ struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, const char *root_path,
+ struct IDOverrideStatic *override, const eRNAOverrideMatch flags,
+ eRNAOverrideMatchResult *r_report_flags);
+
+bool RNA_struct_override_store(
+ struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, PointerRNA *ptr_storage,
+ struct IDOverrideStatic *override);
+
+void RNA_struct_override_apply(
+ struct PointerRNA *ptr_local, struct PointerRNA *ptr_override, struct PointerRNA *ptr_storage,
+ struct IDOverrideStatic *override);
+
+struct IDOverrideStaticProperty *RNA_property_override_property_find(PointerRNA *ptr, PropertyRNA *prop);
+struct IDOverrideStaticProperty *RNA_property_override_property_get(PointerRNA *ptr, PropertyRNA *prop, bool *r_created);
+
+struct IDOverrideStaticPropertyOperation *RNA_property_override_property_operation_find(
+ PointerRNA *ptr, PropertyRNA *prop, const int index, const bool strict, bool *r_strict);
+struct IDOverrideStaticPropertyOperation *RNA_property_override_property_operation_get(
+ PointerRNA *ptr, PropertyRNA *prop, const short operation, const int index,
+ const bool strict, bool *r_strict, bool *r_created);
+
+eRNAOverrideStatus RNA_property_override_status(PointerRNA *ptr, PropertyRNA *prop, const int index);
+
+void RNA_struct_state_owner_set(const char *name);
+const char *RNA_struct_state_owner_get(void);
-typedef enum eRNAEqualsMode {
- RNA_EQ_STRICT, /* set/unset ignored */
- RNA_EQ_UNSET_MATCH_ANY, /* unset property matches anything */
- RNA_EQ_UNSET_MATCH_NONE /* unset property never matches set property */
-} eRNAEqualsMode;
-
-bool RNA_property_equals(struct PointerRNA *a, struct PointerRNA *b, struct PropertyRNA *prop, eRNAEqualsMode mode);
-bool RNA_struct_equals(struct PointerRNA *a, struct PointerRNA *b, eRNAEqualsMode mode);
#ifdef __cplusplus
}
diff --git a/source/blender/makesrna/RNA_define.h b/source/blender/makesrna/RNA_define.h
index 5f71f2ccdcf..4e32651d356 100644
--- a/source/blender/makesrna/RNA_define.h
+++ b/source/blender/makesrna/RNA_define.h
@@ -37,6 +37,14 @@
extern "C" {
#endif
+#ifdef UNIT_TEST
+#define RNA_MAX_ARRAY_LENGTH 64
+#else
+#define RNA_MAX_ARRAY_LENGTH 32
+#endif
+
+#define RNA_MAX_ARRAY_DIMENSION 3
+
/* Blender RNA */
BlenderRNA *RNA_create(void);
@@ -169,6 +177,8 @@ void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *update
void RNA_def_property_editable_func(PropertyRNA *prop, const char *editable);
void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editable);
+void RNA_def_property_override_funcs(PropertyRNA *prop, const char *diff, const char *store, const char *apply);
+
void RNA_def_property_update_runtime(PropertyRNA *prop, const void *func);
void RNA_def_property_poll_runtime(PropertyRNA *prop, const void *func);
diff --git a/source/blender/makesrna/RNA_enum_types.h b/source/blender/makesrna/RNA_enum_types.h
index 0f4e20a02ab..07663b39649 100644
--- a/source/blender/makesrna/RNA_enum_types.h
+++ b/source/blender/makesrna/RNA_enum_types.h
@@ -62,6 +62,9 @@ extern const EnumPropertyItem rna_enum_constraint_type_items[];
extern const EnumPropertyItem rna_enum_boidrule_type_items[];
extern const EnumPropertyItem rna_enum_sequence_modifier_type_items[];
+extern const EnumPropertyItem rna_enum_collection_type_items[];
+extern const EnumPropertyItem rna_enum_layer_collection_mode_settings_type_items[];
+
extern const EnumPropertyItem rna_enum_modifier_triangulate_quad_method_items[];
extern const EnumPropertyItem rna_enum_modifier_triangulate_ngon_method_items[];
@@ -107,6 +110,7 @@ extern const EnumPropertyItem rna_enum_motionpath_bake_location_items[];
extern const EnumPropertyItem rna_enum_event_value_items[];
extern const EnumPropertyItem rna_enum_event_type_items[];
extern const EnumPropertyItem rna_enum_operator_return_items[];
+extern const EnumPropertyItem rna_enum_operator_property_tags[];
extern const EnumPropertyItem rna_enum_brush_sculpt_tool_items[];
extern const EnumPropertyItem rna_enum_brush_vertex_tool_items[];
@@ -161,9 +165,7 @@ extern const EnumPropertyItem rna_enum_property_type_items[];
extern const EnumPropertyItem rna_enum_property_subtype_items[];
extern const EnumPropertyItem rna_enum_property_unit_items[];
-extern const EnumPropertyItem rna_enum_gameproperty_type_items[];
-
-extern const EnumPropertyItem rna_enum_viewport_shade_items[];
+extern const EnumPropertyItem rna_enum_shading_type_items[];
extern const EnumPropertyItem rna_enum_navigation_mode_items[];
diff --git a/source/blender/makesrna/RNA_types.h b/source/blender/makesrna/RNA_types.h
index 705d3914a52..5d6f309ad65 100644
--- a/source/blender/makesrna/RNA_types.h
+++ b/source/blender/makesrna/RNA_types.h
@@ -108,6 +108,8 @@ typedef enum PropertyUnit {
#define RNA_TRANSLATION_PREC_DEFAULT 5
+#define RNA_STACK_ARRAY 32
+
/* also update enums in bpy_props.c when adding items here
* watch it: these values are written to files as part of
* node socket button subtypes!
@@ -156,7 +158,7 @@ typedef enum PropertySubType {
/* Make sure enums are updated with these */
/* HIGHEST FLAG IN USE: 1 << 31
- * FREE FLAGS: 2, 3, 7, 9, 11, 13, 14, 15, 30 */
+ * FREE FLAGS: 11, 13, 14, 15, 30 */
typedef enum PropertyFlag {
/* editable means the property is editable in the user
* interface, properties are editable by default except
@@ -174,6 +176,15 @@ typedef enum PropertyFlag {
* and collections */
PROP_ANIMATABLE = (1 << 1),
+ /* Means the property can be overriden by a local 'proxy' of some linked datablock. */
+ PROP_OVERRIDABLE_STATIC = (1 << 2),
+ /* The property supports insertion (collections only). */
+ PROP_OVERRIDABLE_STATIC_INSERTION = (1 << 9),
+
+ /* Forbid usage of this property in comparison (& hence override) code.
+ * Useful e.g. for collections of data like mesh's geometry, particles, etc. */
+ PROP_NO_COMPARISON = (1 << 3),
+
/* This flag means when the property's widget is in 'textedit' mode, it will be updated
* after every typed char, instead of waiting final validation. Used e.g. for text searchbox.
* It will also cause UI_BUT_VALUE_CLEAR to be set for text buttons. We could add an own flag
@@ -208,6 +219,13 @@ typedef enum PropertyFlag {
* but setting NULL on a mesh object is not possible. So, if its not NULL, setting NULL cant be done! */
PROP_NEVER_UNLINK = (1 << 25),
+ /* Pointers to data that is not owned by the struct.
+ * Typical example: Bone.parent, Bone.child, etc., and nearly all ID pointers.
+ * This is crucial information for processes that walk the whole data of an ID e.g. (like static override).
+ * Note that all ID pointers are enforced to this by default, this probably will need to be rechecked
+ * (see ugly infamous NodeTrees of mat/tex/scene/etc.). */
+ PROP_PTR_NO_OWNERSHIP = (1 << 7),
+
/* flag contains multiple enums.
* note: not to be confused with prop->enumbitflags
* this exposes the flag as multiple options in python and the UI.
@@ -232,7 +250,7 @@ typedef enum PropertyFlag {
PROP_IDPROPERTY = (1 << 10), /* This is an IDProperty, not a DNA one. */
PROP_DYNAMIC = (1 << 17), /* for dynamic arrays, and retvals of type string */
PROP_ENUM_NO_CONTEXT = (1 << 24), /* for enum that shouldn't be contextual */
- PROP_ENUM_NO_TRANSLATE = (1 << 29), /* for enums not to be translated (e.g. renderlayers' names in nodes) */
+ PROP_ENUM_NO_TRANSLATE = (1 << 29), /* for enums not to be translated (e.g. viewlayers' names in nodes) */
} PropertyFlag;
/* Function parameters flags.
@@ -282,6 +300,7 @@ typedef struct CollectionPropertyIterator {
union {
ArrayIterator array;
ListBaseIterator listbase;
+ void *custom;
} internal;
int idprop;
int level;
@@ -492,7 +511,6 @@ typedef struct ExtensionRNA {
StructRNA *srna;
StructCallbackFunc call;
StructFreeFunc free;
-
} ExtensionRNA;
#ifdef __cplusplus
diff --git a/source/blender/makesrna/intern/CMakeLists.txt b/source/blender/makesrna/intern/CMakeLists.txt
index 743d192f0c5..5e815e16a82 100644
--- a/source/blender/makesrna/intern/CMakeLists.txt
+++ b/source/blender/makesrna/intern/CMakeLists.txt
@@ -32,7 +32,6 @@ endif()
set(DEFSRC
rna_ID.c
rna_action.c
- rna_actuator.c
rna_animation.c
rna_animviz.c
rna_armature.c
@@ -44,7 +43,6 @@ set(DEFSRC
rna_color.c
rna_constraint.c
rna_context.c
- rna_controller.c
rna_curve.c
rna_depsgraph.c
rna_dynamicpaint.c
@@ -56,6 +54,7 @@ set(DEFSRC
rna_key.c
rna_lamp.c
rna_lattice.c
+ rna_layer.c
rna_linestyle.c
rna_main.c
rna_mask.c
@@ -72,14 +71,13 @@ set(DEFSRC
rna_palette.c
rna_particle.c
rna_pose.c
- rna_property.c
+ rna_lightprobe.c
rna_render.c
rna_rigidbody.c
rna_rna.c
rna_scene.c
rna_screen.c
rna_sculpt_paint.c
- rna_sensor.c
rna_sequencer.c
rna_smoke.c
rna_sound.c
@@ -94,16 +92,16 @@ set(DEFSRC
rna_userdef.c
rna_vfont.c
rna_wm.c
+ rna_wm_manipulator.c
+ rna_workspace.c
rna_world.c
)
set(APISRC
rna_action_api.c
- rna_actuator_api.c
rna_animation_api.c
rna_armature_api.c
rna_camera_api.c
- rna_controller_api.c
rna_curve_api.c
rna_fcurve_api.c
rna_image_api.c
@@ -116,7 +114,6 @@ set(APISRC
rna_object_api.c
rna_pose_api.c
rna_scene_api.c
- rna_sensor_api.c
rna_sequencer_api.c
rna_sound_api.c
rna_space_api.c
@@ -124,6 +121,7 @@ set(APISRC
rna_ui_api.c
rna_vfont_api.c
rna_wm_api.c
+ rna_wm_manipulator_api.c
)
string(REGEX REPLACE "rna_([a-zA-Z0-9_-]*).c" "${CMAKE_CURRENT_BINARY_DIR}/rna_\\1_gen.c" GENSRC "${DEFSRC}")
@@ -188,8 +186,8 @@ if(WITH_PYTHON)
)
endif()
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
+if(WITH_CLAY_ENGINE)
+ add_definitions(-DWITH_CLAY_ENGINE)
endif()
if(WITH_IMAGE_OPENEXR)
@@ -225,7 +223,7 @@ if(WITH_IMAGE_FRAMESERVER)
endif()
if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
+ add_definitions(-DWITH_AUDASPACE)
list(APPEND INC_SYS
${AUDASPACE_C_INCLUDE_DIRS}
@@ -334,6 +332,7 @@ blender_include_dirs(
../../bmesh
../../blentranslation
../../depsgraph
+ ../../draw
../../gpu
../../imbuf
../../ikplugin
diff --git a/source/blender/makesrna/intern/makesrna.c b/source/blender/makesrna/intern/makesrna.c
index dcaaec707e2..0b2efe27059 100644
--- a/source/blender/makesrna/intern/makesrna.c
+++ b/source/blender/makesrna/intern/makesrna.c
@@ -2995,6 +2995,28 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
}
break;
}
+ case PROP_POINTER:
+ {
+ PointerPropertyRNA *pprop = (PointerPropertyRNA *)prop;
+
+ /* XXX This systematically enforces that flag on ID pointers... we'll probably have to revisit. :/ */
+ StructRNA *type = rna_find_struct((const char *)pprop->type);
+ if (type && (type->flag & STRUCT_ID)) {
+ prop->flag |= PROP_PTR_NO_OWNERSHIP;
+ }
+ break;
+ }
+ case PROP_COLLECTION:
+ {
+ CollectionPropertyRNA *cprop = (CollectionPropertyRNA *)prop;
+
+ /* XXX This systematically enforces that flag on ID pointers... we'll probably have to revisit. :/ */
+ StructRNA *type = rna_find_struct((const char *)cprop->item_type);
+ if (type && (type->flag & STRUCT_ID)) {
+ prop->flag |= PROP_PTR_NO_OWNERSHIP;
+ }
+ break;
+ }
default:
break;
}
@@ -3025,12 +3047,15 @@ static void rna_generate_property(FILE *f, StructRNA *srna, const char *nest, Pr
prop->arraylength[1],
prop->arraylength[2],
prop->totarraylength);
- fprintf(f, "\t%s%s, %d, %s, %s,\n",
+ fprintf(f, "\t%s%s, %d, %s, %s, %s, %s, %s,\n",
(prop->flag & PROP_CONTEXT_UPDATE) ? "(UpdateFunc)" : "",
rna_function_string(prop->update),
prop->noteflag,
rna_function_string(prop->editable),
- rna_function_string(prop->itemeditable));
+ rna_function_string(prop->itemeditable),
+ rna_function_string(prop->override_diff),
+ rna_function_string(prop->override_store),
+ rna_function_string(prop->override_apply));
if (prop->flag_internal & PROP_INTERN_RAW_ACCESS) rna_set_raw_offset(f, srna, prop);
else fprintf(f, "\t0, -1");
@@ -3325,7 +3350,6 @@ static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_action.c", "rna_action_api.c", RNA_def_action},
{"rna_animation.c", "rna_animation_api.c", RNA_def_animation},
{"rna_animviz.c", NULL, RNA_def_animviz},
- {"rna_actuator.c", "rna_actuator_api.c", RNA_def_actuator},
{"rna_armature.c", "rna_armature_api.c", RNA_def_armature},
{"rna_boid.c", NULL, RNA_def_boid},
{"rna_brush.c", NULL, RNA_def_brush},
@@ -3335,9 +3359,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_color.c", NULL, RNA_def_color},
{"rna_constraint.c", NULL, RNA_def_constraint},
{"rna_context.c", NULL, RNA_def_context},
- {"rna_controller.c", "rna_controller_api.c", RNA_def_controller},
{"rna_curve.c", "rna_curve_api.c", RNA_def_curve},
- {"rna_depsgraph.c", NULL, RNA_def_depsgraph},
{"rna_dynamicpaint.c", NULL, RNA_def_dynamic_paint},
{"rna_fcurve.c", "rna_fcurve_api.c", RNA_def_fcurve},
{"rna_fluidsim.c", NULL, RNA_def_fluidsim},
@@ -3347,6 +3369,7 @@ static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_key.c", NULL, RNA_def_key},
{"rna_lamp.c", NULL, RNA_def_lamp},
{"rna_lattice.c", "rna_lattice_api.c", RNA_def_lattice},
+ {"rna_layer.c", NULL, RNA_def_view_layer},
{"rna_linestyle.c", NULL, RNA_def_linestyle},
{"rna_main.c", "rna_main_api.c", RNA_def_main},
{"rna_material.c", "rna_material_api.c", RNA_def_material},
@@ -3357,17 +3380,17 @@ static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_nodetree.c", NULL, RNA_def_nodetree},
{"rna_object.c", "rna_object_api.c", RNA_def_object},
{"rna_object_force.c", NULL, RNA_def_object_force},
+ {"rna_depsgraph.c", NULL, RNA_def_depsgraph},
{"rna_packedfile.c", NULL, RNA_def_packedfile},
{"rna_palette.c", NULL, RNA_def_palette},
{"rna_particle.c", NULL, RNA_def_particle},
{"rna_pose.c", "rna_pose_api.c", RNA_def_pose},
- {"rna_property.c", NULL, RNA_def_gameproperty},
+ {"rna_lightprobe.c", NULL, RNA_def_lightprobe},
{"rna_render.c", NULL, RNA_def_render},
{"rna_rigidbody.c", NULL, RNA_def_rigidbody},
{"rna_scene.c", "rna_scene_api.c", RNA_def_scene},
{"rna_screen.c", NULL, RNA_def_screen},
{"rna_sculpt_paint.c", NULL, RNA_def_sculpt_paint},
- {"rna_sensor.c", "rna_sensor_api.c", RNA_def_sensor},
{"rna_sequencer.c", "rna_sequencer_api.c", RNA_def_sequencer},
{"rna_smoke.c", NULL, RNA_def_smoke},
{"rna_space.c", "rna_space_api.c", RNA_def_space},
@@ -3380,6 +3403,8 @@ static RNAProcessItem PROCESS_ITEMS[] = {
{"rna_userdef.c", NULL, RNA_def_userdef},
{"rna_vfont.c", "rna_vfont_api.c", RNA_def_vfont},
{"rna_wm.c", "rna_wm_api.c", RNA_def_wm},
+ {"rna_wm_manipulator.c", "rna_wm_manipulator_api.c", RNA_def_wm_manipulator},
+ {"rna_workspace.c", NULL, RNA_def_workspace},
{"rna_world.c", NULL, RNA_def_world},
{"rna_movieclip.c", NULL, RNA_def_movieclip},
{"rna_tracking.c", NULL, RNA_def_tracking},
@@ -3710,6 +3735,9 @@ static const char *cpp_classes = ""
" operator void*() { return ptr.data; }\n"
" operator bool() { return ptr.data != NULL; }\n"
"\n"
+" bool operator==(const Pointer &other) { return ptr.data == other.ptr.data; }\n"
+" bool operator!=(const Pointer &other) { return ptr.data != other.ptr.data; }\n"
+"\n"
" PointerRNA ptr;\n"
"};\n"
"\n"
diff --git a/source/blender/makesrna/intern/rna_ID.c b/source/blender/makesrna/intern/rna_ID.c
index cdea0502d12..27c3cee422c 100644
--- a/source/blender/makesrna/intern/rna_ID.c
+++ b/source/blender/makesrna/intern/rna_ID.c
@@ -75,6 +75,7 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
{ID_PC, "PAINTCURVE", ICON_CURVE_BEZCURVE, "Paint Curve", ""},
{ID_PAL, "PALETTE", ICON_COLOR, "Palette", ""},
{ID_PA, "PARTICLE", ICON_PARTICLE_DATA, "Particle", ""},
+ {ID_LT, "LIGHT_PROBE", ICON_RADIO, "Light Probe", ""},
{ID_SCE, "SCENE", ICON_SCENE_DATA, "Scene", ""},
{ID_SCR, "SCREEN", ICON_SPLITSCREEN, "Screen", ""},
{ID_SO, "SOUND", ICON_PLAY_AUDIO, "Sound", ""},
@@ -83,6 +84,7 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
{ID_TE, "TEXTURE", ICON_TEXTURE_DATA, "Texture", ""},
{ID_WM, "WINDOWMANAGER", ICON_FULLSCREEN, "Window Manager", ""},
{ID_WO, "WORLD", ICON_WORLD_DATA, "World", ""},
+ {ID_WS, "WORKSPACE", ICON_NONE, "Workspace", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -96,14 +98,42 @@ const EnumPropertyItem rna_enum_id_type_items[] = {
#include "BKE_idprop.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_library_override.h"
#include "BKE_library_remap.h"
#include "BKE_animsys.h"
#include "BKE_material.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h" /* XXX, remove me */
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "WM_api.h"
+void rna_ID_override_static_property_operation_refname_get(PointerRNA *ptr, char *value)
+{
+ IDOverrideStaticPropertyOperation *opop = ptr->data;
+ strcpy(value, (opop->subitem_reference_name == NULL) ? "" : opop->subitem_reference_name);
+}
+
+int rna_ID_override_static_property_operation_refname_length(PointerRNA *ptr)
+{
+ IDOverrideStaticPropertyOperation *opop = ptr->data;
+ return (opop->subitem_reference_name == NULL) ? 0 : strlen(opop->subitem_reference_name);
+}
+
+void rna_ID_override_static_property_operation_locname_get(PointerRNA *ptr, char *value)
+{
+ IDOverrideStaticPropertyOperation *opop = ptr->data;
+ strcpy(value, (opop->subitem_local_name == NULL) ? "" : opop->subitem_local_name);
+}
+
+int rna_ID_override_static_property_operation_locname_length(PointerRNA *ptr)
+{
+ IDOverrideStaticPropertyOperation *opop = ptr->data;
+ return (opop->subitem_local_name == NULL) ? 0 : strlen(opop->subitem_local_name);
+}
+
+
/* name functions that ignore the first two ID characters */
void rna_ID_name_get(PointerRNA *ptr, char *value)
{
@@ -167,6 +197,7 @@ short RNA_type_to_ID_code(const StructRNA *type)
if (base_type == &RNA_ParticleSettings) return ID_PA;
if (base_type == &RNA_Palette) return ID_PAL;
if (base_type == &RNA_PaintCurve) return ID_PC;
+ if (base_type == &RNA_LightProbe) return ID_LP;
if (base_type == &RNA_Scene) return ID_SCE;
if (base_type == &RNA_Screen) return ID_SCR;
if (base_type == &RNA_Sound) return ID_SO;
@@ -174,6 +205,7 @@ short RNA_type_to_ID_code(const StructRNA *type)
if (base_type == &RNA_Texture) return ID_TE;
if (base_type == &RNA_Text) return ID_TXT;
if (base_type == &RNA_VectorFont) return ID_VF;
+ if (base_type == &RNA_WorkSpace) return ID_WS;
if (base_type == &RNA_World) return ID_WO;
if (base_type == &RNA_WindowManager) return ID_WM;
@@ -209,6 +241,7 @@ StructRNA *ID_code_to_RNA_type(short idcode)
case ID_PA: return &RNA_ParticleSettings;
case ID_PAL: return &RNA_Palette;
case ID_PC: return &RNA_PaintCurve;
+ case ID_LP: return &RNA_LightProbe;
case ID_SCE: return &RNA_Scene;
case ID_SCR: return &RNA_Screen;
case ID_SO: return &RNA_Sound;
@@ -218,6 +251,7 @@ StructRNA *ID_code_to_RNA_type(short idcode)
case ID_VF: return &RNA_VectorFont;
case ID_WM: return &RNA_WindowManager;
case ID_WO: return &RNA_World;
+ case ID_WS: return &RNA_WorkSpace;
/* deprecated */
case ID_IP: break;
@@ -304,6 +338,15 @@ static ID *rna_ID_copy(ID *id, Main *bmain)
return NULL;
}
+static ID *rna_ID_override_create(ID *id, Main *bmain)
+{
+ if (id->lib == NULL) {
+ return NULL;
+ }
+
+ return BKE_override_static_create_from_id(bmain, id);
+}
+
static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
{
/* XXX, new function for this! */
@@ -342,7 +385,7 @@ static void rna_ID_update_tag(ID *id, ReportList *reports, int flag)
}
}
- DAG_id_tag_update(id, flag);
+ DEG_id_tag_update(id, flag);
}
static void rna_ID_user_clear(ID *id)
@@ -378,14 +421,14 @@ static struct ID *rna_ID_make_local(struct ID *self, Main *bmain, int clear_prox
static AnimData * rna_ID_animation_data_create(ID *id, Main *bmain)
{
AnimData *adt = BKE_animdata_add_id(id);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
return adt;
}
static void rna_ID_animation_data_free(ID *id, Main *bmain)
{
BKE_animdata_free(id, true);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
#ifdef WITH_PYTHON
@@ -451,7 +494,7 @@ static Material *rna_IDMaterials_pop_id(ID *id, Main *bmain, ReportList *reports
return NULL;
}
- DAG_id_tag_update(id, OB_RECALC_DATA);
+ DEG_id_tag_update(id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
@@ -462,7 +505,7 @@ static void rna_IDMaterials_clear_id(ID *id, int remove_material_slot)
{
BKE_material_clear_id(G.main, id, remove_material_slot);
- DAG_id_tag_update(id, OB_RECALC_DATA);
+ DEG_id_tag_update(id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, id);
WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, id);
}
@@ -755,6 +798,27 @@ static PointerRNA rna_IDPreview_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_ImagePreview, prv_img);
}
+static int rna_ID_is_updated_get(PointerRNA *ptr)
+{
+ ID *id = (ID *)ptr->data;
+ /* TODO(sergey): Do we need to limit some of flags here? */
+ return ((id->recalc & ID_RECALC_ALL) != 0);
+}
+
+static int rna_ID_is_updated_data_get(PointerRNA *ptr)
+{
+ ID *id = (ID *)ptr->data;
+ if (GS(id->name) != ID_OB) {
+ return 0;
+ }
+ Object *object = (Object *)id;
+ ID *data = object->data;
+ if (data == NULL) {
+ return 0;
+ }
+ return ((data->recalc & ID_RECALC_ALL) != 0);
+}
+
static IDProperty *rna_IDPropertyWrapPtr_idprops(PointerRNA *ptr, bool UNUSED(create))
{
if (ptr == NULL) {
@@ -959,6 +1023,107 @@ static void rna_def_image_preview(BlenderRNA *brna)
RNA_def_function_ui_description(func, "Reload the preview from its source path");
}
+static void rna_def_ID_override_static_property_operation(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static const EnumPropertyItem static_override_property_operation_items[] = {
+ {IDOVERRIDESTATIC_OP_NOOP, "NOOP", 0, "No-Op", "Does nothing, prevents adding actual overrides (NOT USED)"},
+ {IDOVERRIDESTATIC_OP_REPLACE, "REPLACE", 0, "Replace", "Replace value of reference by overriding one"},
+ {IDOVERRIDESTATIC_OP_ADD, "DIFF_ADD", 0, "Differential",
+ "Stores and apply difference between reference and local value (NOT USED)"},
+ {IDOVERRIDESTATIC_OP_SUBTRACT, "DIFF_SUB", 0, "Differential",
+ "Stores and apply difference between reference and local value (NOT USED)"},
+ {IDOVERRIDESTATIC_OP_MULTIPLY, "FACT_MULTIPLY", 0, "Factor",
+ "Stores and apply multiplication factor between reference and local value (NOT USED)"},
+ {IDOVERRIDESTATIC_OP_INSERT_AFTER, "INSERT_AFTER", 0, "Insert After",
+ "Insert a new item into collection after the one referenced in subitem_reference_name or _index"},
+ {IDOVERRIDESTATIC_OP_INSERT_BEFORE, "INSERT_BEFORE", 0, "Insert Before",
+ "Insert a new item into collection after the one referenced in subitem_reference_name or _index (NOT USED)"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static const EnumPropertyItem static_override_property_flag_items[] = {
+ {IDOVERRIDESTATIC_FLAG_MANDATORY, "MANDATORY", 0, "Mandatory",
+ "For templates, prevents the user from removing pre-defined operation (NOT USED)"},
+ {IDOVERRIDESTATIC_FLAG_LOCKED, "LOCKED", 0, "Locked",
+ "Prevents the user from modifying that override operation (NOT USED)"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ srna = RNA_def_struct(brna, "IDOverrideStaticPropertyOperation", NULL);
+ RNA_def_struct_ui_text(srna, "ID Static Override Property Operation",
+ "Description of an override operation over an overridden property");
+
+ prop = RNA_def_enum(srna, "operation", static_override_property_operation_items, IDOVERRIDESTATIC_OP_REPLACE,
+ "Operation", "What override operation is performed");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
+
+ prop = RNA_def_enum(srna, "flag", static_override_property_flag_items, 0,
+ "Flags", "Optional flags (NOT USED)");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
+
+ prop = RNA_def_string(srna, "subitem_reference_name", NULL, INT_MAX, "Subitem Reference Name",
+ "Used to handle insertions into collection");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
+ RNA_def_property_string_funcs(prop, "rna_ID_override_static_property_operation_refname_get",
+ "rna_ID_override_static_property_operation_refname_length", NULL);
+
+ prop = RNA_def_string(srna, "subitem_local_name", NULL, INT_MAX, "Subitem Local Name",
+ "Used to handle insertions into collection");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
+ RNA_def_property_string_funcs(prop, "rna_ID_override_static_property_operation_locname_get",
+ "rna_ID_override_static_property_operation_locname_length", NULL);
+
+ prop = RNA_def_int(srna, "subitem_reference_index", -1, -1, INT_MAX, "Subitem Reference Index",
+ "Used to handle insertions into collection", -1, INT_MAX);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
+
+ prop = RNA_def_int(srna, "subitem_local_index", -1, -1, INT_MAX, "Subitem Local Index",
+ "Used to handle insertions into collection", -1, INT_MAX);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
+}
+
+static void rna_def_ID_override_static_property(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "IDOverrideStaticProperty", NULL);
+ RNA_def_struct_ui_text(srna, "ID Static Override Property", "Description of an overridden property");
+
+ /* String pointer, we *should* add get/set/etc. But NULL rna_path would be a nasty bug anyway... */
+ prop = RNA_def_string(srna, "rna_path", NULL, INT_MAX, "RNA Path",
+ "RNA path leading to that property, from owning ID");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* For now. */
+
+ RNA_def_collection(srna, "operations", "IDOverrideStaticPropertyOperation", "Operations",
+ "List of overriding operations for a property");
+
+ rna_def_ID_override_static_property_operation(brna);
+}
+
+static void rna_def_ID_override_static(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "IDOverrideStatic", NULL);
+ RNA_def_struct_ui_text(srna, "ID Static Override", "Struct gathering all data needed by statically overridden IDs");
+
+ RNA_def_pointer(srna, "reference", "ID", "Reference ID", "Linked ID used as reference by this override");
+
+ prop = RNA_def_boolean(srna, "auto_generate", true, "Auto Generate Override",
+ "Automatically generate overriding operations by detecting changes in properties");
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", STATICOVERRIDE_AUTO);
+
+ RNA_def_collection(srna, "properties", "IDOverrideStaticProperty", "Properties",
+ "List of overridden properties");
+
+ rna_def_ID_override_static_property(brna);
+}
+
static void rna_def_ID(BlenderRNA *brna)
{
StructRNA *srna;
@@ -1006,13 +1171,13 @@ static void rna_def_ID(BlenderRNA *brna)
"(initial state is undefined)");
prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "recalc", ID_RECALC);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_ID_is_updated_get", NULL);
RNA_def_property_ui_text(prop, "Is Updated", "Data-block is tagged for recalculation");
prop = RNA_def_property(srna, "is_updated_data", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "recalc", ID_RECALC_DATA);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_ID_is_updated_data_get", NULL);
RNA_def_property_ui_text(prop, "Is Updated Data", "Data-block data is tagged for recalculation");
prop = RNA_def_property(srna, "is_library_indirect", PROP_BOOLEAN, PROP_NONE);
@@ -1025,6 +1190,9 @@ static void rna_def_ID(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Library", "Library file the data-block is linked from");
+ prop = RNA_def_pointer(srna, "override_static", "IDOverrideStatic", "Static Override", "Static override data");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
prop = RNA_def_pointer(srna, "preview", "ImagePreview", "Preview",
"Preview image and icon of this data-block (None if not supported for this type of data)");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -1037,6 +1205,12 @@ static void rna_def_ID(BlenderRNA *brna)
parm = RNA_def_pointer(func, "id", "ID", "", "New copy of the ID");
RNA_def_function_return(func, parm);
+ func = RNA_def_function(srna, "override_create", "rna_ID_override_create");
+ RNA_def_function_ui_description(func, "Create an overridden local copy of this linked data-block (not supported for all data-blocks)");
+ RNA_def_function_flag(func, FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "id", "ID", "", "New overridden local copy of the ID");
+ RNA_def_function_return(func, parm);
+
func = RNA_def_function(srna, "user_clear", "rna_ID_user_clear");
RNA_def_function_ui_description(func, "Clear the user count of a data-block so its not saved, "
"on reload the data will be removed");
@@ -1141,6 +1315,7 @@ void RNA_def_ID(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Any Type", "RNA type used for pointers to any possible data");
rna_def_ID(brna);
+ rna_def_ID_override_static(brna);
rna_def_image_preview(brna);
rna_def_ID_properties(brna);
rna_def_ID_materials(brna);
diff --git a/source/blender/makesrna/intern/rna_access.c b/source/blender/makesrna/intern/rna_access.c
index 80e377ad8e1..7bf00ef65f6 100644
--- a/source/blender/makesrna/intern/rna_access.c
+++ b/source/blender/makesrna/intern/rna_access.c
@@ -34,6 +34,8 @@
#include "DNA_ID.h"
#include "DNA_scene_types.h"
+#include "DNA_constraint_types.h"
+#include "DNA_modifier_types.h"
#include "DNA_windowmanager_types.h"
#include "BLI_blenlib.h"
@@ -42,6 +44,10 @@
#include "BLI_ghash.h"
#include "BLI_math.h"
+#ifdef DEBUG_OVERRIDE_TIMEIT
+# include "PIL_time_utildefines.h"
+#endif
+
#include "BLF_api.h"
#include "BLT_translation.h"
@@ -51,18 +57,21 @@
#include "BKE_idprop.h"
#include "BKE_fcurve.h"
#include "BKE_library.h"
+#include "BKE_library_override.h"
#include "BKE_main.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
#include "WM_api.h"
+#include "WM_message.h"
/* flush updates */
#include "DNA_object_types.h"
-#include "BKE_depsgraph.h"
#include "WM_types.h"
#include "rna_internal.h"
@@ -431,7 +440,7 @@ static PropertyRNA *arraytypemap[IDP_NUMTYPES] = {
(PropertyRNA *)&rna_PropertyGroupItem_double_array
};
-IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
+static void *rna_idproperty_check_ex(PropertyRNA **prop, PointerRNA *ptr, const bool return_rnaprop)
{
/* This is quite a hack, but avoids some complexity in the API. we
* pass IDProperty structs as PropertyRNA pointers to the outside.
@@ -453,8 +462,9 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
return idprop;
}
- else
- return NULL;
+ else {
+ return return_rnaprop ? *prop : NULL;
+ }
}
{
@@ -469,6 +479,19 @@ IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
}
}
+/* This function only returns an IDProperty,
+ * or NULL (in case IDProp could not be found, or prop is a real RNA property). */
+IDProperty *rna_idproperty_check(PropertyRNA **prop, PointerRNA *ptr)
+{
+ return rna_idproperty_check_ex(prop, ptr, false);
+}
+
+/* This function always return the valid, real data pointer, be it a regular RNA property one, or an IDProperty one. */
+PropertyRNA *rna_ensure_property_realdata(PropertyRNA **prop, PointerRNA *ptr)
+{
+ return rna_idproperty_check_ex(prop, ptr, true);
+}
+
static PropertyRNA *rna_ensure_property(PropertyRNA *prop)
{
/* the quick version if we don't need the idproperty */
@@ -1830,7 +1853,8 @@ bool RNA_property_editable(PointerRNA *ptr, PropertyRNA *prop)
return ((flag & PROP_EDITABLE) &&
(flag & PROP_REGISTER) == 0 &&
- (!id || !ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)));
+ (!id || ((!ID_IS_LINKED(id) || (prop->flag & PROP_LIB_EXCEPTION)) &&
+ (!id->override_static || RNA_property_overridable_get(ptr, prop)))));
}
/**
@@ -1856,11 +1880,19 @@ bool RNA_property_editable_info(PointerRNA *ptr, PropertyRNA *prop, const char *
}
/* property from linked data-block */
- if (id && ID_IS_LINKED(id) && (prop->flag & PROP_LIB_EXCEPTION) == 0) {
- if (!(*r_info)[0]) {
- *r_info = N_("Can't edit this property from a linked data-block");
+ if (id) {
+ if (ID_IS_LINKED(id) && (prop->flag & PROP_LIB_EXCEPTION) == 0) {
+ if (!(*r_info)[0]) {
+ *r_info = N_("Can't edit this property from a linked data-block.");
+ }
+ return false;
+ }
+ if (id->override_static != NULL && !RNA_property_overridable_get(ptr, prop)) {
+ if (!(*r_info)[0]) {
+ *r_info = N_("Can't edit this property from an override data-block.");
+ }
+ return false;
}
- return false;
}
return ((flag & PROP_EDITABLE) && (flag & PROP_REGISTER) == 0);
@@ -1934,6 +1966,70 @@ bool RNA_property_animated(PointerRNA *ptr, PropertyRNA *prop)
return false;
}
+/** \note Does not take into account editable status, this has to be checked separately
+ * (using RNA_property_edtiable_flag() usually). */
+bool RNA_property_overridable_get(PointerRNA *ptr, PropertyRNA *prop)
+{
+ if (prop->magic == RNA_MAGIC) {
+ /* Special handling for insertions of constraints or modifiers... */
+ /* TODO Note We may want to add a more generic system to RNA (like a special property in struct of items)
+ * if we get more overrideable collections, for now we can live with those special-cases handling I think. */
+ if (RNA_struct_is_a(ptr->type, &RNA_Constraint)) {
+ bConstraint *con = ptr->data;
+ if (con->flag & CONSTRAINT_STATICOVERRIDE_LOCAL) {
+ return true;
+ }
+ }
+ else if (RNA_struct_is_a(ptr->type, &RNA_Modifier)) {
+ ModifierData *mod = ptr->data;
+ if (mod->flag & eModifierFlag_StaticOverride_Local) {
+ return true;
+ }
+ }
+ /* If this is a RNA-defined property (real or 'virtual' IDProp), we want to use RNA prop flag. */
+ return !(prop->flag & PROP_NO_COMPARISON) && (prop->flag & PROP_OVERRIDABLE_STATIC);
+ }
+ else {
+ /* If this is a real 'pure' IDProp (aka custom property), we want to use the IDProp flag. */
+ return !(prop->flag & PROP_NO_COMPARISON) && (((IDProperty *)prop)->flag & IDP_FLAG_OVERRIDABLE_STATIC);
+ }
+}
+
+/* Should only be used for custom properties */
+bool RNA_property_overridable_static_set(PointerRNA *UNUSED(ptr), PropertyRNA *prop, const bool is_overridable)
+{
+ /* Only works for pure custom properties IDProps. */
+ if (prop->magic != RNA_MAGIC) {
+ IDProperty *idprop = (IDProperty *)prop;
+
+ idprop->flag = is_overridable ? (idprop->flag | IDP_FLAG_OVERRIDABLE_STATIC) :
+ (idprop->flag & ~IDP_FLAG_OVERRIDABLE_STATIC);
+ return true;
+ }
+
+ return false;
+}
+
+
+bool RNA_property_overridden(PointerRNA *ptr, PropertyRNA *prop)
+{
+ char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
+ ID *id = ptr->id.data;
+
+ if (rna_path == NULL || id == NULL || id->override_static == NULL) {
+ return false;
+ }
+
+ return (BKE_override_static_property_find(id->override_static, rna_path) != NULL);
+}
+
+bool RNA_property_comparable(PointerRNA *UNUSED(ptr), PropertyRNA *prop)
+{
+ prop = rna_ensure_property(prop);
+
+ return !(prop->flag & PROP_NO_COMPARISON);
+}
+
/* this function is to check if its possible to create a valid path from the ID
* its slow so don't call in a loop */
bool RNA_property_path_from_ID_check(PointerRNA *ptr, PropertyRNA *prop)
@@ -1968,7 +2064,7 @@ static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerR
* parts of the code that need it still, so we have this exception */
if (prop->flag & PROP_CONTEXT_UPDATE) {
if (C) {
- if (prop->flag & PROP_CONTEXT_PROPERTY_UPDATE) {
+ if ((prop->flag & PROP_CONTEXT_PROPERTY_UPDATE) == PROP_CONTEXT_PROPERTY_UPDATE) {
((ContextPropUpdateFunc)prop->update)(C, ptr, prop);
}
else {
@@ -1979,14 +2075,24 @@ static void rna_property_update(bContext *C, Main *bmain, Scene *scene, PointerR
else
prop->update(bmain, scene, ptr);
}
+#if 0
if (prop->noteflag)
WM_main_add_notifier(prop->noteflag, ptr->id.data);
+#else
+ /* if C is NULL, we're updating from animation.
+ * avoid slow-down from f-curves by not publishing (for now). */
+ if (C != NULL) {
+ struct wmMsgBus *mbus = CTX_wm_message_bus(C);
+ /* we could add NULL check, for now don't */
+ WM_msg_publish_rna(mbus, ptr, prop);
+ }
+#endif
}
if (!is_rna || (prop->flag & PROP_IDPROPERTY)) {
/* WARNING! This is so property drivers update the display!
* not especially nice */
- DAG_id_tag_update(ptr->id.data, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
WM_main_add_notifier(NC_WINDOW, NULL);
/* Not nice as well, but the only way to make sure material preview
* is updated with custom nodes.
@@ -7005,120 +7111,47 @@ bool RNA_property_reset(PointerRNA *ptr, PropertyRNA *prop, int index)
}
}
+static bool rna_property_override_operation_apply(
+ PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage,
+ PropertyRNA *prop_local, PropertyRNA *prop_override, PropertyRNA *prop_storage,
+ IDOverrideStaticPropertyOperation *opop);
+
bool RNA_property_copy(PointerRNA *ptr, PointerRNA *fromptr, PropertyRNA *prop, int index)
{
- int len, fromlen;
- PropertyRNA *fromprop = prop;
+ if (!RNA_property_editable(ptr, prop)) {
+ return false;
+ }
- if (prop->magic != RNA_MAGIC) {
- /* In case of IDProperty, we have to find the *real* idprop of ptr,
- * since prop in this case is just a fake wrapper around actual IDProp data, and not a 'real' PropertyRNA. */
- prop = (PropertyRNA *)rna_idproperty_find(ptr, ((IDProperty *)fromprop)->name);
+ PropertyRNA *prop_dst = prop;
+ PropertyRNA *prop_src = prop;
- /* its possible the custom-prop doesn't exist on this data-block */
- if (prop == NULL) {
- return false;
- }
+ /* Ensure we get real property data, be it an actual RNA property, or an IDProperty in disguise. */
+ prop_dst = rna_ensure_property_realdata(&prop_dst, ptr);
+ prop_src = rna_ensure_property_realdata(&prop_src, fromptr);
- /* Even though currently we now prop will always be the 'fromprop', this might not be the case in the future. */
- if (prop == fromprop) {
- fromprop = (PropertyRNA *)rna_idproperty_find(fromptr, ((IDProperty *)prop)->name);
- }
+ /* IDprops: destination may not exist, if source does and is set, try to create it. */
+ /* Note: this is sort of quick hack/bandage to fix the issue, we need to rethink how IDProps are handled
+ * in 'diff' RNA code completely, imho... */
+ if (prop_src != NULL && prop_dst == NULL && RNA_property_is_set(fromptr, prop)) {
+ BLI_assert(prop_src->magic != RNA_MAGIC);
+ IDProperty *idp_dst = RNA_struct_idprops(ptr, true);
+ IDProperty *prop_idp_dst = IDP_CopyProperty((IDProperty *)prop_src);
+ IDP_AddToGroup(idp_dst, prop_idp_dst);
+ rna_idproperty_touch(prop_idp_dst);
+ /* Nothing else to do here... */
+ return true;
}
- /* get the length of the array to work with */
- len = RNA_property_array_length(ptr, prop);
- fromlen = RNA_property_array_length(fromptr, fromprop);
-
- if (len != fromlen)
+ if (ELEM(NULL, prop_dst, prop_src)) {
return false;
-
- /* get and set the default values as appropriate for the various types */
- switch (RNA_property_type(prop)) {
- case PROP_BOOLEAN:
- if (len) {
- if (index == -1) {
- int *tmparray = MEM_callocN(sizeof(int) * len, "copy - boolean");
-
- RNA_property_boolean_get_array(fromptr, fromprop, tmparray);
- RNA_property_boolean_set_array(ptr, prop, tmparray);
-
- MEM_freeN(tmparray);
- }
- else {
- int value = RNA_property_boolean_get_index(fromptr, fromprop, index);
- RNA_property_boolean_set_index(ptr, prop, index, value);
- }
- }
- else {
- int value = RNA_property_boolean_get(fromptr, fromprop);
- RNA_property_boolean_set(ptr, prop, value);
- }
- return true;
- case PROP_INT:
- if (len) {
- if (index == -1) {
- int *tmparray = MEM_callocN(sizeof(int) * len, "copy - int");
-
- RNA_property_int_get_array(fromptr, fromprop, tmparray);
- RNA_property_int_set_array(ptr, prop, tmparray);
-
- MEM_freeN(tmparray);
- }
- else {
- int value = RNA_property_int_get_index(fromptr, fromprop, index);
- RNA_property_int_set_index(ptr, prop, index, value);
- }
- }
- else {
- int value = RNA_property_int_get(fromptr, fromprop);
- RNA_property_int_set(ptr, prop, value);
- }
- return true;
- case PROP_FLOAT:
- if (len) {
- if (index == -1) {
- float *tmparray = MEM_callocN(sizeof(float) * len, "copy - float");
-
- RNA_property_float_get_array(fromptr, fromprop, tmparray);
- RNA_property_float_set_array(ptr, prop, tmparray);
-
- MEM_freeN(tmparray);
- }
- else {
- float value = RNA_property_float_get_index(fromptr, fromprop, index);
- RNA_property_float_set_index(ptr, prop, index, value);
- }
- }
- else {
- float value = RNA_property_float_get(fromptr, fromprop);
- RNA_property_float_set(ptr, prop, value);
- }
- return true;
- case PROP_ENUM:
- {
- int value = RNA_property_enum_get(fromptr, fromprop);
- RNA_property_enum_set(ptr, prop, value);
- return true;
- }
- case PROP_POINTER:
- {
- PointerRNA value = RNA_property_pointer_get(fromptr, fromprop);
- RNA_property_pointer_set(ptr, prop, value);
- return true;
- }
- case PROP_STRING:
- {
- char *value = RNA_property_string_get_alloc(fromptr, fromprop, NULL, 0, NULL);
- RNA_property_string_set(ptr, prop, value);
- MEM_freeN(value);
- return true;
- }
- default:
- return false;
}
- return false;
+ IDOverrideStaticPropertyOperation opop = {
+ .operation = IDOVERRIDESTATIC_OP_REPLACE,
+ .subitem_reference_index = index,
+ .subitem_local_index = index
+ };
+ return rna_property_override_operation_apply(ptr, fromptr, NULL, prop_dst, prop_src, NULL, &opop);
}
/* use RNA_warning macro which includes __func__ suffix */
@@ -7143,177 +7176,683 @@ void _RNA_warning(const char *format, ...)
#endif
}
-bool RNA_property_equals(PointerRNA *a, PointerRNA *b, PropertyRNA *prop, eRNAEqualsMode mode)
+static int rna_property_override_diff(
+ PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop, PropertyRNA *prop_a, PropertyRNA *prop_b, const char *rna_path,
+ eRNACompareMode mode, IDOverrideStatic *override, const int flags, eRNAOverrideMatchResult *r_report_flags);
+
+bool RNA_property_equals(PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop, eRNACompareMode mode)
+{
+ BLI_assert(ELEM(mode, RNA_EQ_STRICT, RNA_EQ_UNSET_MATCH_ANY, RNA_EQ_UNSET_MATCH_NONE));
+
+ return (rna_property_override_diff(ptr_a, ptr_b, prop, NULL, NULL, NULL, mode, NULL, 0, NULL) == 0);
+}
+
+bool RNA_struct_equals(PointerRNA *ptr_a, PointerRNA *ptr_b, eRNACompareMode mode)
+{
+ CollectionPropertyIterator iter;
+ PropertyRNA *iterprop;
+ bool equals = true;
+
+ if (ptr_a == NULL && ptr_b == NULL)
+ return true;
+ else if (ptr_a == NULL || ptr_b == NULL)
+ return false;
+ else if (ptr_a->type != ptr_b->type)
+ return false;
+
+ iterprop = RNA_struct_iterator_property(ptr_a->type);
+
+ RNA_property_collection_begin(ptr_a, iterprop, &iter);
+ for (; iter.valid; RNA_property_collection_next(&iter)) {
+ PropertyRNA *prop = iter.ptr.data;
+
+ if (!RNA_property_equals(ptr_a, ptr_b, prop, mode)) {
+ equals = false;
+ break;
+ }
+ }
+ RNA_property_collection_end(&iter);
+
+ return equals;
+}
+
+/* Low-level functions, also used by non-override RNA API like copy or equality check. */
+
+/** Generic RNA property diff function.
+ *
+ * \note about \a prop and \a prop_a/prop_b parameters: the former is exptected to be an 'un-resolved' one,
+ * while the two laters are expected to be fully resolved ones (i.e. to be the IDProps when they should be, etc.).
+ * When \a prop is given, \a prop_a and \a prop_b should always be NULL, and vice-versa.
+ * This is necessary, because we cannot perform 'set/unset' checks on resolved properties
+ * (unset IDProps would merely be NULL then).
+ *
+ * \note When there is no equality, but we cannot determine an order (greater than/lesser than), we return 1.
+ */
+static int rna_property_override_diff(
+ PointerRNA *ptr_a, PointerRNA *ptr_b, PropertyRNA *prop, PropertyRNA *prop_a, PropertyRNA *prop_b,
+ const char *rna_path, eRNACompareMode mode,
+ IDOverrideStatic *override, const int flags, eRNAOverrideMatchResult *r_report_flags)
{
- int len, fromlen;
+ if (prop != NULL) {
+ BLI_assert(prop_a == NULL && prop_b == NULL);
+ prop_a = prop;
+ prop_b = prop;
+ }
+
+ if (ELEM(NULL, prop_a, prop_b)) {
+ return (prop_a == prop_b) ? 0 : 1;
+ }
+
+ if (!RNA_property_comparable(ptr_a, prop_a) || !RNA_property_comparable(ptr_b, prop_b)) {
+ return 0;
+ }
if (mode == RNA_EQ_UNSET_MATCH_ANY) {
/* uninitialized properties are assumed to match anything */
- if (!RNA_property_is_set(a, prop) || !RNA_property_is_set(b, prop))
- return true;
+ if (!RNA_property_is_set(ptr_a, prop_a) || !RNA_property_is_set(ptr_b, prop_b)) {
+ return 0;
+ }
}
else if (mode == RNA_EQ_UNSET_MATCH_NONE) {
/* unset properties never match set properties */
- if (RNA_property_is_set(a, prop) != RNA_property_is_set(b, prop))
- return false;
+ if (RNA_property_is_set(ptr_a, prop_a) != RNA_property_is_set(ptr_b, prop_b)) {
+ return 1;
+ }
+ }
+
+ if (prop != NULL) {
+ /* Ensure we get real property data, be it an actual RNA property, or an IDProperty in disguise. */
+ prop_a = rna_ensure_property_realdata(&prop_a, ptr_a);
+ prop_b = rna_ensure_property_realdata(&prop_b, ptr_b);
+
+ if (ELEM(NULL, prop_a, prop_b)) {
+ return (prop_a == prop_b) ? 0 : 1;
+ }
+ }
+
+ /* Check if we are working with arrays. */
+ const bool is_array_a = RNA_property_array_check(prop_a);
+ const bool is_array_b = RNA_property_array_check(prop_b);
+
+ if (is_array_a != is_array_b) {
+ /* Should probably never happen actually... */
+ BLI_assert(0);
+ return is_array_a ? 1 : -1;
+ }
+
+ /* Get the length of the array to work with. */
+ const int len_a = RNA_property_array_length(ptr_a, prop_a);
+ const int len_b = RNA_property_array_length(ptr_b, prop_b);
+
+ if (len_a != len_b) {
+ /* Do not handle override in that case, we do not support insertion/deletion from arrays for now. */
+ return len_a > len_b ? 1 : -1;
+ }
+
+ if (is_array_a && len_a == 0) {
+ /* Empty arrays, will happen in some case with dynamic ones. */
+ return 0;
+ }
+
+ RNAPropOverrideDiff override_diff = NULL;
+ /* Special case for IDProps, we use default callback then. */
+ if (prop_a->magic != RNA_MAGIC) {
+ override_diff = rna_property_override_diff_default;
+ if (prop_b->magic == RNA_MAGIC && prop_b->override_diff != override_diff) {
+ override_diff = NULL;
+ }
+ }
+ else if (prop_b->magic != RNA_MAGIC) {
+ override_diff = rna_property_override_diff_default;
+ if (prop_a->override_diff != override_diff) {
+ override_diff = NULL;
+ }
+ }
+ else if (prop_a->override_diff == prop_b->override_diff) {
+ override_diff = prop_a->override_diff;
+ }
+
+ if (override_diff == NULL) {
+#ifndef NDEBUG
+ printf("'%s' gives unmatching or NULL RNA diff callbacks, should not happen (%d vs. %d).\n",
+ rna_path ? rna_path : (prop_a->magic != RNA_MAGIC ? ((IDProperty *)prop_a)->name : prop_a->identifier),
+ prop_a->magic == RNA_MAGIC, prop_b->magic == RNA_MAGIC);
+#endif
+ BLI_assert(0);
+ return 1;
+ }
+
+ bool override_changed = false;
+ int diff_flags = flags;
+ if (!RNA_property_overridable_get(ptr_a, prop_a)) {
+ diff_flags &= ~RNA_OVERRIDE_COMPARE_CREATE;
+ }
+ const int diff = override_diff(
+ ptr_a, ptr_b, prop_a, prop_b, len_a, len_b,
+ mode, override, rna_path, diff_flags, &override_changed);
+ if (override_changed && r_report_flags) {
+ *r_report_flags |= RNA_OVERRIDE_MATCH_RESULT_CREATED;
+ }
+
+ return diff;
+}
+
+/* Modify local data-block to make it ready for override application (only needed for diff operations, where we use
+ * the local data-block's data as second operand). */
+static bool rna_property_override_operation_store(
+ PointerRNA *ptr_local, PointerRNA *ptr_reference, PointerRNA *ptr_storage,
+ PropertyRNA *prop_local, PropertyRNA *prop_reference, PropertyRNA *prop_storage,
+ IDOverrideStaticProperty *op)
+{
+ int len_local, len_reference, len_storage = 0;
+ bool changed = false;
+
+ if (ptr_storage == NULL) {
+ return changed;
}
/* get the length of the array to work with */
- len = RNA_property_array_length(a, prop);
- fromlen = RNA_property_array_length(b, prop);
+ len_local = RNA_property_array_length(ptr_local, prop_local);
+ len_reference = RNA_property_array_length(ptr_reference, prop_reference);
+ if (prop_storage) {
+ len_storage = RNA_property_array_length(ptr_storage, prop_storage);
+ }
+
+ if (len_local != len_reference || len_local != len_storage) {
+ /* Do not handle override in that case, we do not support insertion/deletion from arrays for now. */
+ return changed;
+ }
+
+ BLI_assert(prop_local->override_store == prop_reference->override_store &&
+ (!ptr_storage || prop_local->override_store == prop_storage->override_store) &&
+ prop_local->override_store != NULL);
+
+ for (IDOverrideStaticPropertyOperation *opop = op->operations.first; opop; opop = opop->next) {
+ /* Only needed for diff operations. */
+ if (!ELEM(opop->operation, IDOVERRIDESTATIC_OP_ADD, IDOVERRIDESTATIC_OP_SUBTRACT, IDOVERRIDESTATIC_OP_MULTIPLY)) {
+ continue;
+ }
+
+ if (prop_local->override_store(
+ ptr_local, ptr_reference, ptr_storage, prop_local, prop_reference, prop_storage,
+ len_local, len_reference, len_storage, opop))
+ {
+ changed = true;
+ }
+ }
+
+ return changed;
+}
- if (len != fromlen)
+static bool rna_property_override_operation_apply(
+ PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage,
+ PropertyRNA *prop_local, PropertyRNA *prop_override, PropertyRNA *prop_storage,
+ IDOverrideStaticPropertyOperation *opop)
+{
+ int len_local, len_reference, len_storage = 0;
+
+ const short override_op = opop->operation;
+
+ if (override_op == IDOVERRIDESTATIC_OP_NOOP) {
+ return true;
+ }
+
+ if (ELEM(override_op, IDOVERRIDESTATIC_OP_ADD, IDOVERRIDESTATIC_OP_SUBTRACT, IDOVERRIDESTATIC_OP_MULTIPLY) && !ptr_storage) {
+ /* We cannot apply 'diff' override operations without some refference storage.
+ * This should typically only happen at read time of .blend file... */
+ return false;
+ }
+
+ if (ELEM(override_op, IDOVERRIDESTATIC_OP_ADD, IDOVERRIDESTATIC_OP_SUBTRACT, IDOVERRIDESTATIC_OP_MULTIPLY) && !prop_storage) {
+ /* We cannot apply 'diff' override operations without some refference storage.
+ * This should typically only happen at read time of .blend file... */
+ return false;
+ }
+
+ RNAPropOverrideApply override_apply = NULL;
+ /* Special case for IDProps, we use default callback then. */
+ if (prop_local->magic != RNA_MAGIC) {
+ override_apply = rna_property_override_apply_default;
+ if (prop_override->magic == RNA_MAGIC && prop_override->override_apply != override_apply) {
+ override_apply = NULL;
+ }
+ }
+ else if (prop_override->magic != RNA_MAGIC) {
+ override_apply = rna_property_override_apply_default;
+ if (prop_local->override_apply != override_apply) {
+ override_apply = NULL;
+ }
+ }
+ else if (prop_local->override_apply == prop_override->override_apply) {
+ override_apply = prop_local->override_apply;
+ }
+
+ if (ptr_storage && prop_storage->magic == RNA_MAGIC && prop_storage->override_apply != override_apply) {
+ override_apply = NULL;
+ }
+
+ if (override_apply == NULL) {
+#ifndef NDEBUG
+ printf("'%s' gives unmatching or NULL RNA copy callbacks, should not happen (%d vs. %d).\n",
+ prop_local->magic != RNA_MAGIC ? ((IDProperty *)prop_local)->name : prop_local->identifier,
+ prop_local->magic == RNA_MAGIC, prop_override->magic == RNA_MAGIC);
+#endif
+ BLI_assert(0);
return false;
+ }
+
+ /* get the length of the array to work with */
+ len_local = RNA_property_array_length(ptr_local, prop_local);
+ len_reference = RNA_property_array_length(ptr_override, prop_override);
+ if (ptr_storage) {
+ len_storage = RNA_property_array_length(ptr_storage, prop_storage);
+ }
+
+ if (len_local != len_reference || (ptr_storage && len_local != len_storage)) {
+ /* Do not handle override in that case, we do not support insertion/deletion from arrays for now. */
+ return false;
+ }
/* get and set the default values as appropriate for the various types */
- switch (RNA_property_type(prop)) {
- case PROP_BOOLEAN:
- {
- if (len) {
- int fixed_a[16], fixed_b[16];
- int *array_a, *array_b;
- bool equals;
+ return override_apply(
+ ptr_local, ptr_override, ptr_storage,
+ prop_local, prop_override, prop_storage,
+ len_local, len_reference, len_storage,
+ opop);
+}
+
+/**
+ * Check whether reference and local overriden data match (are the same),
+ * with respect to given restrictive sets of properties.
+ * If requested, will generate needed new property overrides, and/or restore values from reference.
+ *
+ * \param r_report_flags If given, will be set with flags matching actions taken by the function on \a ptr_local.
+ *
+ * \return True if _resulting_ \a ptr_local does match \a ptr_reference.
+ */
+bool RNA_struct_override_matches(
+ PointerRNA *ptr_local, PointerRNA *ptr_reference, const char *root_path,
+ IDOverrideStatic *override, const eRNAOverrideMatch flags,
+ eRNAOverrideMatchResult *r_report_flags)
+{
+ CollectionPropertyIterator iter;
+ PropertyRNA *iterprop;
+ bool matching = true;
+
+ BLI_assert(ptr_local->type == ptr_reference->type);
+ BLI_assert(ptr_local->id.data && ptr_reference->id.data);
+
+ const bool ignore_non_overridable = (flags & RNA_OVERRIDE_COMPARE_IGNORE_NON_OVERRIDABLE) != 0;
+ const bool ignore_overridden = (flags & RNA_OVERRIDE_COMPARE_IGNORE_OVERRIDDEN) != 0;
+ const bool do_create = (flags & RNA_OVERRIDE_COMPARE_CREATE) != 0;
+ const bool do_restore = (flags & RNA_OVERRIDE_COMPARE_RESTORE) != 0;
+
+//#define DEBUG_OVERRIDE_TIMEIT
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ static float _sum_time_global = 0.0f;
+ static float _num_time_global = 0.0f;
+ double _timeit_time_global;
+ static float _sum_time_diffing = 0.0f;
+ static float _delta_time_diffing = 0.0f;
+ static int _num_delta_time_diffing = 0.0f;
+ static float _num_time_diffing = 0.0f;
+ double _timeit_time_diffing;
+
+ if (!root_path) {
+ _delta_time_diffing = 0.0f;
+ _num_delta_time_diffing = 0;
+ _timeit_time_global = PIL_check_seconds_timer();
+ }
+#endif
- array_a = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_a;
- array_b = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_b;
+ iterprop = RNA_struct_iterator_property(ptr_local->type);
- RNA_property_boolean_get_array(a, prop, array_a);
- RNA_property_boolean_get_array(b, prop, array_b);
+ for (RNA_property_collection_begin(ptr_local, iterprop, &iter); iter.valid; RNA_property_collection_next(&iter)) {
+ PropertyRNA *prop_local = iter.ptr.data;
+ PropertyRNA *prop_reference = iter.ptr.data;
- equals = memcmp(array_a, array_b, sizeof(int) * len) == 0;
+ /* Ensure we get real property data, be it an actual RNA property, or an IDProperty in disguise. */
+ prop_local = rna_ensure_property_realdata(&prop_local, ptr_local);
+ prop_reference = rna_ensure_property_realdata(&prop_reference, ptr_reference);
- if (array_a != fixed_a) MEM_freeN(array_a);
- if (array_b != fixed_b) MEM_freeN(array_b);
+ if (ELEM(NULL, prop_local, prop_reference)) {
+ continue;
+ }
- return equals;
+ if (ignore_non_overridable && !RNA_property_overridable_get(ptr_local, prop_local)) {
+ continue;
+ }
+
+#if 0 /* This actually makes things slower, since it has to check for animation paths etc! */
+ if (RNA_property_animated(ptr_local, prop_local)) {
+ /* We cannot do anything here really, animation is some kind of dynamic overrides that has
+ * precedence over static one... */
+ continue;
+ }
+#endif
+
+#define RNA_PATH_BUFFSIZE 8192
+#define RNA_PATH_PRINTF(_str, ...) \
+ if (BLI_snprintf(rna_path, RNA_PATH_BUFFSIZE, \
+ (_str), __VA_ARGS__) >= RNA_PATH_BUFFSIZE) \
+ { rna_path = BLI_sprintfN((_str), __VA_ARGS__); }(void)0
+#define RNA_PATH_FREE \
+ if (rna_path != rna_path_buffer) MEM_freeN(rna_path)
+
+ char rna_path_buffer[RNA_PATH_BUFFSIZE];
+ char *rna_path = rna_path_buffer;
+
+ /* XXX TODO this will have to be refined to handle collections insertions, and array items */
+ if (root_path) {
+ /* Inlined building, much much more efficient. */
+ if (prop_local->magic == RNA_MAGIC) {
+ RNA_PATH_PRINTF("%s.%s", root_path, RNA_property_identifier(prop_local));
}
else {
- int value = RNA_property_boolean_get(a, prop);
- return value == RNA_property_boolean_get(b, prop);
+ RNA_PATH_PRINTF("%s[\"%s\"]", root_path, RNA_property_identifier(prop_local));
}
}
+ else {
+ /* This is rather slow, but is not much called, so not really worth optimizing. */
+ rna_path = RNA_path_from_ID_to_property(ptr_local, prop_local);
+ }
+ if (rna_path == NULL) {
+ continue;
+ }
- case PROP_INT:
- {
- if (len) {
- int fixed_a[16], fixed_b[16];
- int *array_a, *array_b;
- bool equals;
+// printf("Override Checking %s\n", rna_path);
- array_a = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_a;
- array_b = (len > 16) ? MEM_mallocN(sizeof(int) * len, "RNA equals") : fixed_b;
+ if (ignore_overridden && BKE_override_static_property_find(override, rna_path) != NULL) {
+ RNA_PATH_FREE;
+ continue;
+ }
- RNA_property_int_get_array(a, prop, array_a);
- RNA_property_int_get_array(b, prop, array_b);
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ if (!root_path) {
+ _timeit_time_diffing = PIL_check_seconds_timer();
+ }
+#endif
- equals = memcmp(array_a, array_b, sizeof(int) * len) == 0;
+ eRNAOverrideMatchResult report_flags = 0;
+ const int diff = rna_property_override_diff(
+ ptr_local, ptr_reference, NULL, prop_local, prop_reference, rna_path,
+ RNA_EQ_STRICT, override, flags, &report_flags);
- if (array_a != fixed_a) MEM_freeN(array_a);
- if (array_b != fixed_b) MEM_freeN(array_b);
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ if (!root_path) {
+ const float _delta_time = (float)(PIL_check_seconds_timer() - _timeit_time_diffing);
+ _delta_time_diffing += _delta_time;
+ _num_delta_time_diffing++;
+ }
+#endif
- return equals;
+ matching = matching && diff == 0;
+ if (r_report_flags) {
+ *r_report_flags |= report_flags;
+ }
+
+ if (diff != 0) {
+ /* XXX TODO: refine this for per-item overriding of arrays... */
+ IDOverrideStaticProperty *op = BKE_override_static_property_find(override, rna_path);
+ IDOverrideStaticPropertyOperation *opop = op ? op->operations.first : NULL;
+
+ if (do_restore && (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) == 0) {
+ /* We are allowed to restore to reference's values. */
+ if (ELEM(NULL, op, opop) || opop->operation == IDOVERRIDESTATIC_OP_NOOP) {
+ /* We should restore that property to its reference value */
+ if (RNA_property_editable(ptr_local, prop_local)) {
+ IDOverrideStaticPropertyOperation opop_tmp = {
+ .operation = IDOVERRIDESTATIC_OP_REPLACE,
+ .subitem_reference_index = -1,
+ .subitem_local_index = -1
+ };
+ rna_property_override_operation_apply(ptr_local, ptr_reference, NULL,
+ prop_local, prop_reference, NULL, &opop_tmp);
+ if (r_report_flags) {
+ *r_report_flags |= RNA_OVERRIDE_MATCH_RESULT_RESTORED;
+ }
+ }
+ else {
+ /* Too noisy for now, this triggers on runtime props like transform matrices etc. */
+ /* BLI_assert(!"We have differences between reference and overriding data on non-editable property."); */
+ matching = false;
+ }
+ }
}
- else {
- int value = RNA_property_int_get(a, prop);
- return value == RNA_property_int_get(b, prop);
+ else if ((report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) == 0 && ELEM(NULL, op, opop)) {
+ /* This property is not overridden, and differs from reference, so we have no match. */
+ matching = false;
+ if (!(do_create || do_restore)) {
+ /* Since we have no 'changing' action allowed, we can break here. */
+ MEM_SAFE_FREE(rna_path);
+ break;
+ }
}
}
- case PROP_FLOAT:
- {
- if (len) {
- float fixed_a[16], fixed_b[16];
- float *array_a, *array_b;
- bool equals;
+ RNA_PATH_FREE;
- array_a = (len > 16) ? MEM_mallocN(sizeof(float) * len, "RNA equals") : fixed_a;
- array_b = (len > 16) ? MEM_mallocN(sizeof(float) * len, "RNA equals") : fixed_b;
+#undef RNA_PATH_BUFFSIZE
+#undef RNA_PATH_PRINTF
+#undef RNA_PATH_FREE
+ }
+ RNA_property_collection_end(&iter);
- RNA_property_float_get_array(a, prop, array_a);
- RNA_property_float_get_array(b, prop, array_b);
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ if (!root_path) {
+ const float _delta_time = (float)(PIL_check_seconds_timer() - _timeit_time_global);
+ _sum_time_global += _delta_time;
+ _num_time_global++;
+ _sum_time_diffing += _delta_time_diffing;
+ _num_time_diffing++;
+ printf("ID: %s\n", ((ID *)ptr_local->id.data)->name);
+ printf("time end (%s): %.6f\n", __func__, _delta_time);
+ printf("time averaged (%s): %.6f (total: %.6f, in %d runs)\n", __func__,
+ (_sum_time_global / _num_time_global), _sum_time_global, (int)_num_time_global);
+ printf("diffing time end (%s): %.6f (in %d runs)\n", __func__, _delta_time_diffing, _num_delta_time_diffing);
+ printf("diffing time averaged (%s): %.6f (total: %.6f, in %d runs)\n", __func__,
+ (_sum_time_diffing / _num_time_diffing), _sum_time_diffing, (int)_num_time_diffing);
+ }
+#endif
+
+ return matching;
+}
- equals = memcmp(array_a, array_b, sizeof(float) * len) == 0;
- if (array_a != fixed_a) MEM_freeN(array_a);
- if (array_b != fixed_b) MEM_freeN(array_b);
+/** Store needed second operands into \a storage data-block for differential override operations. */
+bool RNA_struct_override_store(
+ PointerRNA *ptr_local, PointerRNA *ptr_reference, PointerRNA *ptr_storage, IDOverrideStatic *override)
+{
+ bool changed = false;
- return equals;
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ TIMEIT_START_AVERAGED(RNA_struct_override_store);
+#endif
+ for (IDOverrideStaticProperty *op = override->properties.first; op; op = op->next) {
+ /* Simplified for now! */
+ PointerRNA data_reference, data_local;
+ PropertyRNA *prop_reference, *prop_local;
+
+ if (RNA_path_resolve_property(ptr_local, op->rna_path, &data_local, &prop_local) &&
+ RNA_path_resolve_property(ptr_reference, op->rna_path, &data_reference, &prop_reference))
+ {
+ PointerRNA data_storage;
+ PropertyRNA *prop_storage = NULL;
+
+ /* It is totally OK if this does not success, only a subset of override operations actually need storage. */
+ if (ptr_storage && (ptr_storage->id.data != NULL)) {
+ RNA_path_resolve_property(ptr_storage, op->rna_path, &data_storage, &prop_storage);
}
- else {
- float value = RNA_property_float_get(a, prop);
- return value == RNA_property_float_get(b, prop);
+
+ if (rna_property_override_operation_store(&data_local, &data_reference, &data_storage,
+ prop_reference, prop_local, prop_storage, op))
+ {
+ changed = true;
}
}
+ }
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ TIMEIT_END_AVERAGED(RNA_struct_override_store);
+#endif
- case PROP_ENUM:
- {
- int value = RNA_property_enum_get(a, prop);
- return value == RNA_property_enum_get(b, prop);
- }
+ return changed;
+}
- case PROP_STRING:
+static void rna_property_override_apply_ex(
+ PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage,
+ PropertyRNA *prop_local, PropertyRNA *prop_override, PropertyRNA *prop_storage,
+ IDOverrideStaticProperty *op, const bool do_insert)
+{
+ for (IDOverrideStaticPropertyOperation *opop = op->operations.first; opop; opop = opop->next) {
+ if (!do_insert != !ELEM(opop->operation, IDOVERRIDESTATIC_OP_INSERT_AFTER, IDOVERRIDESTATIC_OP_INSERT_BEFORE)) {
+ if (!do_insert) {
+ printf("Skipping insert override operations in first pass (%s)!\n", op->rna_path);
+ }
+ continue;
+ }
+ if (!rna_property_override_operation_apply(ptr_local, ptr_override, ptr_storage,
+ prop_local, prop_override, prop_storage, opop))
{
- char fixed_a[128], fixed_b[128];
- int len_a, len_b;
- char *value_a = RNA_property_string_get_alloc(a, prop, fixed_a, sizeof(fixed_a), &len_a);
- char *value_b = RNA_property_string_get_alloc(b, prop, fixed_b, sizeof(fixed_b), &len_b);
- bool equals = STREQ(value_a, value_b);
+ /* TODO No assert here, would be much much better to just report as warning,
+ * failing override applications will probably be fairly common! */
+ BLI_assert(0);
+ }
+ }
+}
- if (value_a != fixed_a) MEM_freeN(value_a);
- if (value_b != fixed_b) MEM_freeN(value_b);
+/** Apply given \a override operations on \a ptr_local, using \a ptr_override
+ * (and \a ptr_storage form differential ops) as source. */
+void RNA_struct_override_apply(
+ PointerRNA *ptr_local, PointerRNA *ptr_override, PointerRNA *ptr_storage, IDOverrideStatic *override)
+{
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ TIMEIT_START_AVERAGED(RNA_struct_override_apply);
+#endif
+ /* Note: Applying insert operations in a separate pass is mandatory.
+ * We could optimize this later, but for now, as inneficient as it is, don't think this is a critical point.
+ */
+ bool do_insert = false;
+ for (int i = 0; i < 2; i++, do_insert = true) {
+ for (IDOverrideStaticProperty *op = override->properties.first; op; op = op->next) {
+ /* Simplified for now! */
+ PointerRNA data_override, data_local;
+ PropertyRNA *prop_override, *prop_local;
+
+ if (RNA_path_resolve_property(ptr_local, op->rna_path, &data_local, &prop_local) &&
+ RNA_path_resolve_property(ptr_override, op->rna_path, &data_override, &prop_override))
+ {
+ PointerRNA data_storage;
+ PropertyRNA *prop_storage = NULL;
- return equals;
- }
+ /* It is totally OK if this does not success, only a subset of override operations actually need storage. */
+ if (ptr_storage && (ptr_storage->id.data != NULL)) {
+ RNA_path_resolve_property(ptr_storage, op->rna_path, &data_storage, &prop_storage);
+ }
- case PROP_POINTER:
- {
- if (!STREQ(RNA_property_identifier(prop), "rna_type")) {
- PointerRNA propptr_a = RNA_property_pointer_get(a, prop);
- PointerRNA propptr_b = RNA_property_pointer_get(b, prop);
- return RNA_struct_equals(&propptr_a, &propptr_b, mode);
+ rna_property_override_apply_ex(
+ &data_local, &data_override, prop_storage ? &data_storage : NULL,
+ prop_local, prop_override, prop_storage, op, do_insert);
}
- break;
+#ifndef NDEBUG
+ else {
+ printf("Failed to apply static override operation to '%s.%s' (could not resolve some properties)\n",
+ ((ID *)ptr_override->id.data)->name, op->rna_path);
+ }
+#endif
}
+ }
+#ifdef DEBUG_OVERRIDE_TIMEIT
+ TIMEIT_END_AVERAGED(RNA_struct_override_apply);
+#endif
+}
- default:
- break;
+IDOverrideStaticProperty *RNA_property_override_property_find(PointerRNA *ptr, PropertyRNA *prop)
+{
+ ID *id = ptr->id.data;
+
+ if (!id || !id->override_static) {
+ return NULL;
}
- return true;
+ char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
+ if (rna_path) {
+ IDOverrideStaticProperty *op = BKE_override_static_property_find(id->override_static, rna_path);
+ MEM_freeN(rna_path);
+ return op;
+ }
+ return NULL;
}
-bool RNA_struct_equals(PointerRNA *a, PointerRNA *b, eRNAEqualsMode mode)
+IDOverrideStaticProperty *RNA_property_override_property_get(PointerRNA *ptr, PropertyRNA *prop, bool *r_created)
{
- CollectionPropertyIterator iter;
-// CollectionPropertyRNA *citerprop; /* UNUSED */
- PropertyRNA *iterprop;
- bool equals = true;
+ ID *id = ptr->id.data;
- if (a == NULL && b == NULL)
- return true;
- else if (a == NULL || b == NULL)
- return false;
- else if (a->type != b->type)
- return false;
+ if (!id || !id->override_static) {
+ return NULL;
+ }
+
+ char *rna_path = RNA_path_from_ID_to_property(ptr, prop);
+ if (rna_path) {
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(id->override_static, rna_path, r_created);
+ MEM_freeN(rna_path);
+ return op;
+ }
+ return NULL;
+}
- iterprop = RNA_struct_iterator_property(a->type);
-// citerprop = (CollectionPropertyRNA *)rna_ensure_property(iterprop); /* UNUSED */
+IDOverrideStaticPropertyOperation *RNA_property_override_property_operation_find(
+ PointerRNA *ptr, PropertyRNA *prop, const int index, const bool strict, bool *r_strict)
+{
+ IDOverrideStaticProperty *op = RNA_property_override_property_find(ptr, prop);
- RNA_property_collection_begin(a, iterprop, &iter);
- for (; iter.valid; RNA_property_collection_next(&iter)) {
- PropertyRNA *prop = iter.ptr.data;
+ if (!op) {
+ return NULL;
+ }
- if (!RNA_property_equals(a, b, prop, mode)) {
- equals = false;
- break;
+ return BKE_override_static_property_operation_find(op, NULL, NULL, index, index, strict, r_strict);
+}
+
+IDOverrideStaticPropertyOperation *RNA_property_override_property_operation_get(
+ PointerRNA *ptr, PropertyRNA *prop, const short operation, const int index,
+ const bool strict, bool *r_strict, bool *r_created)
+{
+ IDOverrideStaticProperty *op = RNA_property_override_property_get(ptr, prop, NULL);
+
+ if (!op) {
+ return NULL;
+ }
+
+ return BKE_override_static_property_operation_get(op, operation, NULL, NULL, index, index, strict, r_strict, r_created);
+}
+
+eRNAOverrideStatus RNA_property_override_status(PointerRNA *ptr, PropertyRNA *prop, const int index)
+{
+ int override_status = 0;
+
+ if (!ptr || !prop || !ptr->id.data || !((ID *)ptr->id.data)->override_static) {
+ return override_status;
+ }
+
+ if (RNA_property_overridable_get(ptr, prop) && RNA_property_editable_flag(ptr, prop)) {
+ override_status |= RNA_OVERRIDE_STATUS_OVERRIDABLE;
+ }
+
+ IDOverrideStaticPropertyOperation *opop = RNA_property_override_property_operation_find(ptr, prop, index, false, NULL);
+ if (opop != NULL) {
+ override_status |= RNA_OVERRIDE_STATUS_OVERRIDDEN;
+ if (opop->flag & IDOVERRIDESTATIC_FLAG_MANDATORY) {
+ override_status |= RNA_OVERRIDE_STATUS_MANDATORY;
+ }
+ if (opop->flag & IDOVERRIDESTATIC_FLAG_LOCKED) {
+ override_status |= RNA_OVERRIDE_STATUS_LOCKED;
}
}
- RNA_property_collection_end(&iter);
- return equals;
+ return override_status;
}
+
bool RNA_path_resolved_create(
PointerRNA *ptr, struct PropertyRNA *prop,
const int prop_index,
@@ -7332,3 +7871,22 @@ bool RNA_path_resolved_create(
return false;
}
}
+
+static char rna_struct_state_owner[64];
+void RNA_struct_state_owner_set(const char *name)
+{
+ if (name) {
+ BLI_strncpy(rna_struct_state_owner, name, sizeof(rna_struct_state_owner));
+ }
+ else {
+ rna_struct_state_owner[0] = '\0';
+ }
+}
+
+const char *RNA_struct_state_owner_get(void)
+{
+ if (rna_struct_state_owner[0]) {
+ return rna_struct_state_owner;
+ }
+ return NULL;
+}
diff --git a/source/blender/makesrna/intern/rna_actuator.c b/source/blender/makesrna/intern/rna_actuator.c
deleted file mode 100644
index 26ec813a14f..00000000000
--- a/source/blender/makesrna/intern/rna_actuator.c
+++ /dev/null
@@ -1,2220 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Blender Foundation (2008).
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/makesrna/intern/rna_actuator.c
- * \ingroup RNA
- */
-
-
-#include <stdlib.h>
-
-#include "DNA_constraint_types.h"
-#include "DNA_object_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_scene_types.h" /* for MAXFRAME */
-
-#include "BLI_math.h"
-#include "BLI_string_utils.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "RNA_define.h"
-#include "RNA_access.h"
-#include "RNA_enum_types.h"
-
-#include "rna_internal.h"
-
-#include "WM_types.h"
-
-/* Always keep in alphabetical order */
-static const EnumPropertyItem actuator_type_items[] = {
- {ACT_ACTION, "ACTION", 0, "Action", ""},
- {ACT_ARMATURE, "ARMATURE", 0, "Armature", ""},
- {ACT_CAMERA, "CAMERA", 0, "Camera", ""},
- {ACT_CONSTRAINT, "CONSTRAINT", 0, "Constraint", ""},
- {ACT_EDIT_OBJECT, "EDIT_OBJECT", 0, "Edit Object", ""},
- {ACT_2DFILTER, "FILTER_2D", 0, "Filter 2D", ""},
- {ACT_GAME, "GAME", 0, "Game", ""},
- {ACT_MESSAGE, "MESSAGE", 0, "Message", ""},
- {ACT_OBJECT, "MOTION", 0, "Motion", ""},
- {ACT_MOUSE, "MOUSE", 0, "Mouse", ""},
- {ACT_PARENT, "PARENT", 0, "Parent", ""},
- {ACT_PROPERTY, "PROPERTY", 0, "Property", ""},
- {ACT_RANDOM, "RANDOM", 0, "Random", ""},
- {ACT_SCENE, "SCENE", 0, "Scene", ""},
- {ACT_SOUND, "SOUND", 0, "Sound", ""},
- {ACT_STATE, "STATE", 0, "State", ""},
- {ACT_STEERING, "STEERING", 0, "Steering", ""},
- {ACT_VISIBILITY, "VISIBILITY", 0, "Visibility", ""},
- {0, NULL, 0, NULL, NULL}
-};
-
-#ifdef RNA_RUNTIME
-
-#include "BKE_sca.h"
-
-static StructRNA *rna_Actuator_refine(struct PointerRNA *ptr)
-{
- bActuator *actuator = (bActuator *)ptr->data;
-
- switch (actuator->type) {
- case ACT_ACTION:
- return &RNA_ActionActuator;
- case ACT_OBJECT:
- return &RNA_ObjectActuator;
- case ACT_CAMERA:
- return &RNA_CameraActuator;
- case ACT_SOUND:
- return &RNA_SoundActuator;
- case ACT_PROPERTY:
- return &RNA_PropertyActuator;
- case ACT_CONSTRAINT:
- return &RNA_ConstraintActuator;
- case ACT_EDIT_OBJECT:
- return &RNA_EditObjectActuator;
- case ACT_SCENE:
- return &RNA_SceneActuator;
- case ACT_RANDOM:
- return &RNA_RandomActuator;
- case ACT_MESSAGE:
- return &RNA_MessageActuator;
- case ACT_GAME:
- return &RNA_GameActuator;
- case ACT_VISIBILITY:
- return &RNA_VisibilityActuator;
- case ACT_2DFILTER:
- return &RNA_Filter2DActuator;
- case ACT_PARENT:
- return &RNA_ParentActuator;
- case ACT_STATE:
- return &RNA_StateActuator;
- case ACT_ARMATURE:
- return &RNA_ArmatureActuator;
- case ACT_STEERING:
- return &RNA_SteeringActuator;
- case ACT_MOUSE:
- return &RNA_MouseActuator;
- default:
- return &RNA_Actuator;
- }
-}
-
-static void rna_Actuator_name_set(PointerRNA *ptr, const char *value)
-{
- Object *ob = ptr->id.data;
- bActuator *act = ptr->data;
- BLI_strncpy_utf8(act->name, value, sizeof(act->name));
- BLI_uniquename(&ob->actuators, act, DATA_("Actuator"), '.', offsetof(bActuator, name), sizeof(act->name));
-}
-
-static void rna_Actuator_type_set(struct PointerRNA *ptr, int value)
-{
- bActuator *act = (bActuator *)ptr->data;
-
- if (value != act->type) {
- act->type = value;
- init_actuator(act);
- }
-}
-
-static void rna_ConstraintActuator_type_set(struct PointerRNA *ptr, int value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
-
- if (value != ca->type) {
- ca->type = value;
- switch (ca->type) {
- case ACT_CONST_TYPE_ORI:
- /* negative axis not supported in the orientation mode */
- if (ELEM(ca->mode, ACT_CONST_DIRNX, ACT_CONST_DIRNY, ACT_CONST_DIRNZ))
- ca->mode = ACT_CONST_NONE;
- break;
-
- case ACT_CONST_TYPE_LOC:
- case ACT_CONST_TYPE_DIST:
- case ACT_CONST_TYPE_FH:
- default:
- break;
- }
- }
-}
-
-static float rna_ConstraintActuator_limitmin_get(struct PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->flag & ACT_CONST_LOCX) fp = ca->minloc;
- else if (ca->flag & ACT_CONST_LOCY) fp = ca->minloc + 1;
- else if (ca->flag & ACT_CONST_LOCZ) fp = ca->minloc + 2;
- else if (ca->flag & ACT_CONST_ROTX) fp = ca->minrot;
- else if (ca->flag & ACT_CONST_ROTY) fp = ca->minrot + 1;
- else fp = ca->minrot + 2;
-
- return *fp;
-}
-
-static void rna_ConstraintActuator_limitmin_set(struct PointerRNA *ptr, float value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->flag & ACT_CONST_LOCX) fp = ca->minloc;
- else if (ca->flag & ACT_CONST_LOCY) fp = ca->minloc + 1;
- else if (ca->flag & ACT_CONST_LOCZ) fp = ca->minloc + 2;
- else if (ca->flag & ACT_CONST_ROTX) fp = ca->minrot;
- else if (ca->flag & ACT_CONST_ROTY) fp = ca->minrot + 1;
- else fp = ca->minrot + 2;
-
- *fp = value;
-}
-
-static float rna_ConstraintActuator_limitmax_get(struct PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->flag & ACT_CONST_LOCX) fp = ca->maxloc;
- else if (ca->flag & ACT_CONST_LOCY) fp = ca->maxloc + 1;
- else if (ca->flag & ACT_CONST_LOCZ) fp = ca->maxloc + 2;
- else if (ca->flag & ACT_CONST_ROTX) fp = ca->maxrot;
- else if (ca->flag & ACT_CONST_ROTY) fp = ca->maxrot + 1;
- else fp = ca->maxrot + 2;
-
- return *fp;
-}
-
-static void rna_ConstraintActuator_limitmax_set(struct PointerRNA *ptr, float value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->flag & ACT_CONST_LOCX) fp = ca->maxloc;
- else if (ca->flag & ACT_CONST_LOCY) fp = ca->maxloc + 1;
- else if (ca->flag & ACT_CONST_LOCZ) fp = ca->maxloc + 2;
- else if (ca->flag & ACT_CONST_ROTX) fp = ca->maxrot;
- else if (ca->flag & ACT_CONST_ROTY) fp = ca->maxrot + 1;
- else fp = ca->maxrot + 2;
-
- *fp = value;
-}
-
-static float rna_ConstraintActuator_distance_get(struct PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->minloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->minloc + 1;
- else fp = ca->minloc + 2;
-
- return *fp;
-}
-
-static void rna_ConstraintActuator_distance_set(struct PointerRNA *ptr, float value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->minloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->minloc + 1;
- else fp = ca->minloc + 2;
-
- *fp = value;
-}
-
-static float rna_ConstraintActuator_range_get(struct PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->maxloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->maxloc + 1;
- else fp = ca->maxloc + 2;
-
- return *fp;
-}
-
-static void rna_ConstraintActuator_range_set(struct PointerRNA *ptr, float value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->maxloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->maxloc + 1;
- else fp = ca->maxloc + 2;
-
- *fp = value;
-}
-
-static float rna_ConstraintActuator_fhheight_get(struct PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->minloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->minloc + 1;
- else fp = ca->minloc + 2;
-
- return *fp;
-}
-
-static void rna_ConstraintActuator_fhheight_set(struct PointerRNA *ptr, float value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->minloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->minloc + 1;
- else fp = ca->minloc + 2;
-
- *fp = value;
-}
-
-static float rna_ConstraintActuator_spring_get(struct PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->maxloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->maxloc + 1;
- else fp = ca->maxloc + 2;
-
- return *fp;
-}
-
-static void rna_ConstraintActuator_spring_set(struct PointerRNA *ptr, float value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
- float *fp;
-
- if (ca->mode & (ACT_CONST_DIRPX | ACT_CONST_DIRNX)) fp = ca->maxloc;
- else if (ca->mode & (ACT_CONST_DIRPY | ACT_CONST_DIRNY)) fp = ca->maxloc + 1;
- else fp = ca->maxloc + 2;
-
- *fp = value;
-}
-/* ConstraintActuator uses the same property for Material and Property.
- * Therefore we need to clear the property when "use_material_detect" mode changes */
-static void rna_Actuator_constraint_detect_material_set(struct PointerRNA *ptr, int value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bConstraintActuator *ca = act->data;
-
- short old_value = (ca->flag & ACT_CONST_MATERIAL) ? 1 : 0;
-
- if (old_value != value) {
- ca->flag ^= ACT_CONST_MATERIAL;
- ca->matprop[0] = '\0';
- }
-}
-
-static void rna_ActionActuator_add_set(struct PointerRNA *ptr, int value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bActionActuator *aa = act->data;
-
- if (value == 1) {
- aa->flag &= ~ACT_IPOFORCE;
- aa->flag |= ACT_IPOADD;
- }
- else {
- aa->flag &= ~ACT_IPOADD;
- }
-}
-
-static void rna_ActionActuator_force_set(struct PointerRNA *ptr, int value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bActionActuator *aa = act->data;
-
- if (value == 1) {
- aa->flag &= ~ACT_IPOADD;
- aa->flag |= ACT_IPOFORCE;
- }
- else {
- aa->flag &= ~ACT_IPOFORCE;
- }
-}
-
-static void rna_ObjectActuator_type_set(struct PointerRNA *ptr, int value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bObjectActuator *oa = act->data;
- if (value != oa->type) {
- oa->type = value;
- switch (oa->type) {
- case ACT_OBJECT_NORMAL:
- memset(oa, 0, sizeof(bObjectActuator));
- oa->flag = ACT_FORCE_LOCAL | ACT_TORQUE_LOCAL | ACT_DLOC_LOCAL | ACT_DROT_LOCAL;
- oa->type = ACT_OBJECT_NORMAL;
- break;
-
- case ACT_OBJECT_SERVO:
- memset(oa, 0, sizeof(bObjectActuator));
- oa->flag = ACT_LIN_VEL_LOCAL;
- oa->type = ACT_OBJECT_SERVO;
- oa->forcerot[0] = 30.0f;
- oa->forcerot[1] = 0.5f;
- oa->forcerot[2] = 0.0f;
- break;
-
- case ACT_OBJECT_CHARACTER:
- memset(oa, 0, sizeof(bObjectActuator));
- oa->flag = ACT_DLOC_LOCAL | ACT_DROT_LOCAL;
- oa->type = ACT_OBJECT_CHARACTER;
- break;
- }
- }
-}
-
-static void rna_ObjectActuator_integralcoefficient_set(struct PointerRNA *ptr, float value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bObjectActuator *oa = act->data;
-
- oa->forcerot[1] = value;
- oa->forcerot[0] = 60.0f * oa->forcerot[1];
-}
-
-static void rna_StateActuator_state_set(PointerRNA *ptr, const int *values)
-{
- bActuator *act = (bActuator *)ptr->data;
- bStateActuator *sa = act->data;
-
- int i, tot = 0;
-
- /* ensure we always have some state selected */
- for (i = 0; i < OB_MAX_STATES; i++)
- if (values[i])
- tot++;
-
- if (tot == 0)
- return;
-
- for (i = 0; i < OB_MAX_STATES; i++) {
- if (values[i]) sa->mask |= (1 << i);
- else sa->mask &= ~(1 << i);
- }
-}
-
-/* Always keep in alphabetical order */
-const EnumPropertyItem *rna_Actuator_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
-{
- EnumPropertyItem *item = NULL;
- Object *ob = NULL;
- int totitem = 0;
-
- if (ptr->type == &RNA_Actuator || RNA_struct_is_a(ptr->type, &RNA_Actuator)) {
- ob = (Object *)ptr->id.data;
- }
- else {
- /* can't use ob from ptr->id.data because that enum is also used by operators */
- ob = CTX_data_active_object(C);
- }
-
- if (ob != NULL) {
- if (ob->type == OB_ARMATURE) {
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_ARMATURE);
- }
- }
-
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_ACTION);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_CAMERA);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_CONSTRAINT);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_EDIT_OBJECT);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_2DFILTER);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_GAME);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_MESSAGE);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_MOUSE);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_OBJECT);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_PARENT);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_PROPERTY);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_RANDOM);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_SCENE);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_STEERING);
-
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_SOUND);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_STATE);
- RNA_enum_items_add_value(&item, &totitem, actuator_type_items, ACT_VISIBILITY);
-
- RNA_enum_item_end(&item, &totitem);
- *r_free = true;
-
- return item;
-}
-
-static void rna_Actuator_Armature_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
-{
- bActuator *act = (bActuator *)ptr->data;
- bArmatureActuator *aa = act->data;
- Object *ob = (Object *)ptr->id.data;
-
- char *posechannel = aa->posechannel;
- char *constraint = aa->constraint;
-
- /* check that bone exist in the active object */
- if (ob->type == OB_ARMATURE && ob->pose) {
- bPoseChannel *pchan;
- bPose *pose = ob->pose;
- for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
- if (STREQ(pchan->name, posechannel)) {
- /* found it, now look for constraint channel */
- bConstraint *con;
- for (con = pchan->constraints.first; con; con = con->next) {
- if (STREQ(con->name, constraint)) {
- /* found it, all ok */
- return;
- }
- }
- /* didn't find constraint, make empty */
- constraint[0] = 0;
- return;
- }
- }
- }
- /* didn't find any */
- posechannel[0] = 0;
- constraint[0] = 0;
-}
-
-static void rna_SteeringActuator_navmesh_set(PointerRNA *ptr, PointerRNA value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bSteeringActuator *sa = (bSteeringActuator *) act->data;
-
- Object *obj = value.data;
- if (obj && obj->body_type == OB_BODY_TYPE_NAVMESH)
- sa->navmesh = obj;
- else
- sa->navmesh = NULL;
-}
-
-/* note: the following set functions exists only to avoid id refcounting */
-static void rna_Actuator_editobject_mesh_set(PointerRNA *ptr, PointerRNA value)
-{
- bActuator *act = (bActuator *)ptr->data;
- bEditObjectActuator *eoa = (bEditObjectActuator *) act->data;
-
- eoa->me = value.data;
-}
-
-#else
-
-static void rna_def_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "Actuator", NULL);
- RNA_def_struct_ui_text(srna, "Actuator", "Actuator to apply actions in the game engine");
- RNA_def_struct_sdna(srna, "bActuator");
- RNA_def_struct_refine_func(srna, "rna_Actuator_refine");
-
- prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Name", "");
- RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Actuator_name_set");
- RNA_def_struct_name_property(srna, prop);
-
- prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_enum_items(prop, actuator_type_items);
- RNA_def_property_enum_funcs(prop, NULL, "rna_Actuator_type_set", "rna_Actuator_type_itemf");
- RNA_def_property_ui_text(prop, "Type", "");
-
- prop = RNA_def_property(srna, "pin", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_PIN);
- RNA_def_property_ui_text(prop, "Pinned", "Display when not linked to a visible states controller");
- RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_SHOW);
- RNA_def_property_ui_text(prop, "Expanded", "Set actuator expanded in the user interface");
- RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
-
- prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ACT_DEACTIVATE);
- RNA_def_property_ui_text(prop, "Active", "Set the active state of the actuator");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- RNA_api_actuator(srna);
-}
-
-static void rna_def_action_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_ACTION_PLAY, "PLAY", 0, "Play", ""},
- {ACT_ACTION_PINGPONG, "PINGPONG", 0, "Ping Pong", ""},
- {ACT_ACTION_FLIPPER, "FLIPPER", 0, "Flipper", ""},
- {ACT_ACTION_LOOP_STOP, "LOOPSTOP", 0, "Loop Stop", ""},
- {ACT_ACTION_LOOP_END, "LOOPEND", 0, "Loop End", ""},
- {ACT_ACTION_FROM_PROP, "PROPERTY", 0, "Property", ""},
-#ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
- {ACT_ACTION_MOTION, "MOTION", 0, "Displacement", ""},
-#endif
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_blend_items[] = {
- {ACT_ACTION_BLEND, "BLEND", 0, "Blend", ""},
- {ACT_ACTION_ADD, "ADD", 0, "Add", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "ActionActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Action Actuator", "Actuator to control the object movement");
- RNA_def_struct_sdna_from(srna, "bActionActuator", "data");
-
- prop = RNA_def_property(srna, "play_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Action Type", "Action playback type");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "act");
- RNA_def_property_struct_type(prop, "Action");
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
- RNA_def_property_ui_text(prop, "Action", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_continue_last_frame", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "end_reset", 1);
- RNA_def_property_ui_text(prop, "Continue",
- "Restore last frame when switching on/off, otherwise play from the start each time");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "name");
- RNA_def_property_ui_text(prop, "Property", "Use this property to define the Action position");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sta");
- RNA_def_property_ui_range(prop, 0.0, MAXFRAME, 100, 2);
- RNA_def_property_ui_text(prop, "Start Frame", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "frame_end", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "end");
- RNA_def_property_ui_range(prop, 0.0, MAXFRAME, 100, 2);
- RNA_def_property_ui_text(prop, "End Frame", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "frame_blend_in", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "blendin");
- RNA_def_property_range(prop, 0, 32767);
- RNA_def_property_ui_text(prop, "Blendin", "Number of frames of motion blending");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "priority", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 0, 100);
- RNA_def_property_ui_text(prop, "Priority",
- "Execution priority - lower numbers will override actions with higher numbers "
- "(with 2 or more actions at once, the overriding channels must be lower in the stack)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "layer", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 0, 32766); /* This should match BL_ActionManager::MAX_ACTION_LAYERS - 1 */
- RNA_def_property_ui_text(prop, "Layer", "The animation layer to play the action on");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "layer_weight", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_ui_text(prop, "Layer Weight",
- "How much of the previous layer to blend into this one");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "frame_property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "frameProp");
- RNA_def_property_ui_text(prop, "Frame Property", "Assign the action's current frame number to this property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* booleans */
- prop = RNA_def_property(srna, "use_additive", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_IPOADD);
- RNA_def_property_boolean_funcs(prop, NULL, "rna_ActionActuator_add_set");
- RNA_def_property_ui_text(prop, "Add",
- "Action is added to the current loc/rot/scale in global or local coordinate according to "
- "Local flag");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_force", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_IPOFORCE);
- RNA_def_property_boolean_funcs(prop, NULL, "rna_ActionActuator_force_set");
- RNA_def_property_ui_text(prop, "Force",
- "Apply Action as a global or local force depending on the local option "
- "(dynamic objects only)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_IPOLOCAL);
- RNA_def_property_ui_text(prop, "L", "Let the Action act in local coordinates, used in Force and Add mode");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "apply_to_children", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_IPOCHILD);
- RNA_def_property_ui_text(prop, "Child", "Update Action on all children Objects as well");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "blend_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "blend_mode");
- RNA_def_property_enum_items(prop, prop_blend_items);
- RNA_def_property_ui_text(prop, "Blend Mode", "How this layer is blended with previous layers");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
-#ifdef __NLA_ACTION_BY_MOTION_ACTUATOR
- prop = RNA_def_property(srna, "stride_length", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "stridelength");
- RNA_def_property_range(prop, 0.0, 2500.0);
- RNA_def_property_ui_text(prop, "Cycle", "Distance covered by a single cycle of the action");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-#endif
-}
-
-static void rna_def_object_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_OBJECT_NORMAL, "OBJECT_NORMAL", 0, "Simple Motion", ""},
- {ACT_OBJECT_SERVO, "OBJECT_SERVO", 0, "Servo Control", ""},
- {ACT_OBJECT_CHARACTER, "OBJECT_CHARACTER", 0, "Character Motion", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "ObjectActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Motion Actuator", "Actuator to control the object movement");
- RNA_def_struct_sdna_from(srna, "bObjectActuator", "data");
-
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_enum_funcs(prop, NULL, "rna_ObjectActuator_type_set", NULL);
- RNA_def_property_ui_text(prop, "Motion Type", "Specify the motion system");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "reference_object", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "reference");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Reference Object",
- "Reference object for velocity calculation, leave empty for world reference");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "damping", PROP_INT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0, 1000, 1, 1);
- RNA_def_property_ui_text(prop, "Damping Frames", "Number of frames to reach the target velocity");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "proportional_coefficient", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "forcerot[0]");
- RNA_def_property_ui_range(prop, 0.0, 200.0, 10, 2);
- RNA_def_property_ui_text(prop, "Proportional Coefficient", "Typical value is 60x integral coefficient");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "integral_coefficient", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "forcerot[1]");
- RNA_def_property_ui_range(prop, 0.0, 3.0, 10, 2);
- RNA_def_property_float_funcs(prop, NULL, "rna_ObjectActuator_integralcoefficient_set", NULL);
- RNA_def_property_ui_text(prop, "Integral Coefficient",
- "Low value (0.01) for slow response, high value (0.5) for fast response");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "derivate_coefficient", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "forcerot[2]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 10, 2);
- RNA_def_property_ui_text(prop, "Derivate Coefficient", "Not required, high values can cause instability");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Servo Limit */
- prop = RNA_def_property(srna, "force_max_x", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "dloc[0]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 1, 2);
- RNA_def_property_ui_text(prop, "Max", "Upper limit for X force");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "force_min_x", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "drot[0]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 1, 2);
- RNA_def_property_ui_text(prop, "Min", "Lower limit for X force");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "force_max_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "dloc[1]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 1, 2);
- RNA_def_property_ui_text(prop, "Max", "Upper limit for Y force");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "force_min_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "drot[1]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 1, 2);
- RNA_def_property_ui_text(prop, "Min", "Lower limit for Y force");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "force_max_z", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "dloc[2]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 1, 2);
- RNA_def_property_ui_text(prop, "Max", "Upper limit for Z force");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "force_min_z", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "drot[2]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 1, 2);
- RNA_def_property_ui_text(prop, "Min", "Lower limit for Z force");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* floats 3 Arrays*/
- prop = RNA_def_property(srna, "offset_location", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "dloc");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Loc", "Location");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "offset_rotation", PROP_FLOAT, PROP_EULER);
- RNA_def_property_float_sdna(prop, NULL, "drot");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Rot", "Rotation");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "force", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "forceloc");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Force", "Force");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "torque", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "forcerot");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Torque", "Torque");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "linear_velocity", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "linearvelocity");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Linear Velocity",
- "Linear velocity (in Servo mode it sets the target relative linear velocity, it will be "
- "achieved by automatic application of force - Null velocity is a valid target)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "angular_velocity", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "angularvelocity");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Angular Velocity", "Angular velocity");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* booleans */
- prop = RNA_def_property(srna, "use_local_location", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_DLOC_LOCAL);
- RNA_def_property_ui_text(prop, "L", "Location is defined in local coordinates");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local_rotation", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_DROT_LOCAL);
- RNA_def_property_ui_text(prop, "L", "Rotation is defined in local coordinates");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local_force", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_FORCE_LOCAL);
- RNA_def_property_ui_text(prop, "L", "Force is defined in local coordinates");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local_torque", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_TORQUE_LOCAL);
- RNA_def_property_ui_text(prop, "L", "Torque is defined in local coordinates");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local_linear_velocity", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_LIN_VEL_LOCAL);
- RNA_def_property_ui_text(prop, "L", "Velocity is defined in local coordinates");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local_angular_velocity", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_ANG_VEL_LOCAL);
- RNA_def_property_ui_text(prop, "L", "Angular velocity is defined in local coordinates");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_add_linear_velocity", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_ADD_LIN_VEL);
- RNA_def_property_ui_text(prop, "Add", "Toggles between ADD and SET linV");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_add_character_location", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_ADD_CHAR_LOC);
- RNA_def_property_ui_text(prop, "Add", "Toggle between ADD and SET character location");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_servo_limit_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_SERVO_LIMIT_X);
- RNA_def_property_ui_text(prop, "X", "Set limit to force along the X axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_servo_limit_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_SERVO_LIMIT_Y);
- RNA_def_property_ui_text(prop, "Y", "Set limit to force along the Y axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_servo_limit_z", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_SERVO_LIMIT_Z);
- RNA_def_property_ui_text(prop, "Z", "Set limit to force along the Z axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_character_jump", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CHAR_JUMP);
- RNA_def_property_ui_text(prop, "Jump", "Make the character jump using the settings in the physics properties");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_camera_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_axis_items[] = {
- {OB_POSX, "POS_X", 0, "+X", "Camera tries to get behind the X axis"},
- {OB_POSY, "POS_Y", 0, "+Y", "Camera tries to get behind the Y axis"},
- {OB_NEGX, "NEG_X", 0, "-X", "Camera tries to get behind the -X axis"},
- {OB_NEGY, "NEG_Y", 0, "-Y", "Camera tries to get behind the -Y axis"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "CameraActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Camera Actuator", "");
- RNA_def_struct_sdna_from(srna, "bCameraActuator", "data");
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "ob");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Camera Object", "Look at this Object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* floats */
- prop = RNA_def_property(srna, "height", PROP_FLOAT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0.0, 20.0, 1, 2);
- RNA_def_property_ui_text(prop, "Height", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "min", PROP_FLOAT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0.0, 20.0, 1, 2);
- RNA_def_property_ui_text(prop, "Min", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "max", PROP_FLOAT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0.0, 20.0, 1, 2);
- RNA_def_property_ui_text(prop, "Max", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "damping", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "damping");
- RNA_def_property_range(prop, 0, 10.0);
- RNA_def_property_ui_range(prop, 0, 5.0, 1, 2);
- RNA_def_property_ui_text(prop, "Damping", "Strength of the constraint that drives the camera behind the target");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* +x/+y/-x/-y */
- prop = RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "axis");
- RNA_def_property_enum_items(prop, prop_axis_items);
- RNA_def_property_ui_text(prop, "Axis", "Axis the Camera will try to get behind");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_sound_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_SND_PLAY_STOP_SOUND, "PLAYSTOP", 0, "Play Stop", ""},
- {ACT_SND_PLAY_END_SOUND, "PLAYEND", 0, "Play End", ""},
- {ACT_SND_LOOP_STOP_SOUND, "LOOPSTOP", 0, "Loop Stop", ""},
- {ACT_SND_LOOP_END_SOUND, "LOOPEND", 0, "Loop End", ""},
- {ACT_SND_LOOP_BIDIRECTIONAL_SOUND, "LOOPBIDIRECTIONAL", 0, "Loop Bidirectional", ""},
- {ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND, "LOOPBIDIRECTIONALSTOP", 0, "Loop Bidirectional Stop", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "SoundActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Sound Actuator", "Actuator to handle sound");
- RNA_def_struct_sdna_from(srna, "bSoundActuator", "data");
-
- prop = RNA_def_property(srna, "sound", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Sound");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_struct_ui_text(srna, "Sound", "Sound file");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Play Mode", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "volume", PROP_FLOAT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
- RNA_def_property_range(prop, 0.0, 2.0);
- RNA_def_property_ui_text(prop, "Volume", "Initial volume of the sound");
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_SOUND);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "pitch", PROP_FLOAT, PROP_NONE);
- RNA_def_property_ui_range(prop, -12.0, 12.0, 1, 2);
- RNA_def_property_ui_text(prop, "Pitch", "Pitch of the sound");
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_SOUND);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* floats - 3D Parameters */
- prop = RNA_def_property(srna, "gain_3d_min", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.min_gain");
- RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
- RNA_def_property_ui_text(prop, "Minimum Gain", "The minimum gain of the sound, no matter how far it is away");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "gain_3d_max", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.max_gain");
- RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
- RNA_def_property_ui_text(prop, "Maximum Gain", "The maximum gain of the sound, no matter how near it is");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "distance_3d_reference", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.reference_distance");
- RNA_def_property_ui_range(prop, 0.0, FLT_MAX, 1, 2);
- RNA_def_property_ui_text(prop, "Reference Distance", "The distance where the sound has a gain of 1.0");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "distance_3d_max", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.max_distance");
- RNA_def_property_ui_range(prop, 0.0, FLT_MAX, 1, 2);
- RNA_def_property_ui_text(prop, "Maximum Distance", "The maximum distance at which you can hear the sound");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "rolloff_factor_3d", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.rolloff_factor");
- RNA_def_property_ui_range(prop, 0.0, 5.0, 1, 2);
- RNA_def_property_ui_text(prop, "Rolloff", "The influence factor on volume depending on distance");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "cone_outer_gain_3d", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.cone_outer_gain");
- RNA_def_property_ui_range(prop, 0.0, 1.0, 1, 2);
- RNA_def_property_ui_text(prop, "Cone Outer Gain",
- "The gain outside the outer cone (the gain in the outer cone will be interpolated "
- "between this value and the normal gain in the inner cone)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "cone_outer_angle_3d", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.cone_outer_angle");
- RNA_def_property_ui_range(prop, 0.0, DEG2RADF(360.0f), 1, 2);
- RNA_def_property_ui_text(prop, "Cone Outer Angle", "The angle of the outer cone");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "cone_inner_angle_3d", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "sound3D.cone_inner_angle");
- RNA_def_property_ui_range(prop, 0.0, DEG2RADF(360.0f), 1, 2);
- RNA_def_property_ui_text(prop, "Cone Inner Angle", "The angle of the inner cone");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* booleans */
- prop = RNA_def_property(srna, "use_sound_3d", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_SND_3D_SOUND);
- RNA_def_property_ui_text(prop, "3D Sound", "Enable/Disable 3D Sound");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_property_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_PROP_ASSIGN, "ASSIGN", 0, "Assign", ""},
- {ACT_PROP_ADD, "ADD", 0, "Add", ""},
- {ACT_PROP_COPY, "COPY", 0, "Copy", ""},
- {ACT_PROP_TOGGLE, "TOGGLE", 0, "Toggle", "For bool/int/float/timer properties only"},
- {ACT_PROP_LEVEL, "LEVEL", 0, "Level", "For bool/int/float/timer properties only"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "PropertyActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Property Actuator", "Actuator to handle properties");
- RNA_def_struct_sdna_from(srna, "bPropertyActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Mode", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "name");
- RNA_def_property_ui_text(prop, "Property", "The name of the property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Value", "The name of the property or the value to use (use \"\" around strings)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Copy Mode */
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "ob");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Object", "Copy from this Object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /*XXX add even magic'er property lookup (need to look for the property list of the target object) */
- prop = RNA_def_property(srna, "object_property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "value");
- RNA_def_property_ui_text(prop, "Property Name", "Copy this property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_constraint_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_CONST_TYPE_LOC, "LOC", 0, "Location Constraint", ""},
- {ACT_CONST_TYPE_DIST, "DIST", 0, "Distance Constraint", ""},
- {ACT_CONST_TYPE_ORI, "ORI", 0, "Orientation Constraint", ""},
- {ACT_CONST_TYPE_FH, "FH", 0, "Force Field Constraint", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_limit_items[] = {
- {ACT_CONST_NONE, "NONE", 0, "None", ""},
- {ACT_CONST_LOCX, "LOCX", 0, "Loc X", ""},
- {ACT_CONST_LOCY, "LOCY", 0, "Loc Y", ""},
- {ACT_CONST_LOCZ, "LOCZ", 0, "Loc Z", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_direction_items[] = {
- {ACT_CONST_NONE, "NONE", 0, "None", ""},
- {ACT_CONST_DIRPX, "DIRPX", 0, "X axis", ""},
- {ACT_CONST_DIRPY, "DIRPY", 0, "Y axis", ""},
- {ACT_CONST_DIRPZ, "DIRPZ", 0, "Z axis", ""},
- {ACT_CONST_DIRNX, "DIRNX", 0, "-X axis", ""},
- {ACT_CONST_DIRNY, "DIRNY", 0, "-Y axis", ""},
- {ACT_CONST_DIRNZ, "DIRNZ", 0, "-Z axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_direction_pos_items[] = {
- {ACT_CONST_NONE, "NONE", 0, "None", ""},
- {ACT_CONST_DIRPX, "DIRPX", 0, "X axis", ""},
- {ACT_CONST_DIRPY, "DIRPY", 0, "Y axis", ""},
- {ACT_CONST_DIRPZ, "DIRPZ", 0, "Z axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "ConstraintActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Constraint Actuator", "Actuator to handle Constraints");
- RNA_def_struct_sdna_from(srna, "bConstraintActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_enum_funcs(prop, NULL, "rna_ConstraintActuator_type_set", NULL);
- RNA_def_property_ui_text(prop, "Constraints Mode", "The type of the constraint");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "limit", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "flag");
- RNA_def_property_enum_items(prop, prop_limit_items);
- RNA_def_property_ui_text(prop, "Limit", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "direction", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, prop_direction_items);
- RNA_def_property_ui_text(prop, "Direction", "Direction of the ray");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "direction_axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, prop_direction_items);
- RNA_def_property_ui_text(prop, "Direction", "Select the axis to be aligned along the reference direction");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_CONST_TYPE_LOC */
- prop = RNA_def_property(srna, "limit_min", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_funcs(prop, "rna_ConstraintActuator_limitmin_get",
- "rna_ConstraintActuator_limitmin_set", NULL);
- RNA_def_property_ui_range(prop, -2000.f, 2000.f, 1, 2);
- RNA_def_property_ui_text(prop, "Min", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "limit_max", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_funcs(prop, "rna_ConstraintActuator_limitmax_get",
- "rna_ConstraintActuator_limitmax_set", NULL);
- RNA_def_property_ui_range(prop, -2000.f, 2000.f, 1, 2);
- RNA_def_property_ui_text(prop, "Max", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "damping", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "damp");
- RNA_def_property_ui_range(prop, 0, 100, 1, 1);
- RNA_def_property_ui_text(prop, "Damping", "Damping factor: time constant (in frame) of low pass filter");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_CONST_TYPE_DIST */
- prop = RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_funcs(prop, "rna_ConstraintActuator_range_get", "rna_ConstraintActuator_range_set", NULL);
- RNA_def_property_ui_range(prop, 0.f, 2000.f, 1, 2);
- RNA_def_property_ui_text(prop, "Range", "Maximum length of ray");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_funcs(prop, "rna_ConstraintActuator_distance_get",
- "rna_ConstraintActuator_distance_set", NULL);
- RNA_def_property_ui_range(prop, -2000.f, 2000.f, 1, 2);
- RNA_def_property_ui_text(prop, "Distance", "Keep this distance to target");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /*XXX to use a pointer or add a material lookup */
- prop = RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "matprop");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Material", "Ray detects only Objects with this material");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /*XXX add magic property lookup */
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "matprop");
- RNA_def_property_ui_text(prop, "Property", "Ray detects only Objects with this property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "time", PROP_INT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0, 1000, 1, 2);
- RNA_def_property_ui_text(prop, "Time", "Maximum activation time in frame, 0 for unlimited");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "damping_rotation", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "rotdamp");
- RNA_def_property_ui_range(prop, 0, 100, 1, 1);
- RNA_def_property_ui_text(prop, "RotDamp", "Use a different damping for orientation");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_CONST_TYPE_ORI */
- prop = RNA_def_property(srna, "direction_axis_pos", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, prop_direction_pos_items);
- RNA_def_property_ui_text(prop, "Direction", "Select the axis to be aligned along the reference direction");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "rotation_max", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "maxrot");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -2000.0, 2000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Reference Direction", "Reference Direction");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "angle_min", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "minloc[0]");
- RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
- RNA_def_property_ui_text(prop, "Min Angle",
- "Minimum angle to maintain with target direction "
- "(no correction is done if angle with target direction is between min and max)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "angle_max", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "maxloc[0]");
- RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
- RNA_def_property_ui_text(prop, "Max Angle",
- "Maximum angle allowed with target direction "
- "(no correction is done if angle with target direction is between min and max)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_CONST_TYPE_FH */
- prop = RNA_def_property(srna, "fh_height", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_funcs(prop, "rna_ConstraintActuator_fhheight_get",
- "rna_ConstraintActuator_fhheight_set", NULL);
- RNA_def_property_ui_range(prop, 0.01, 2000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Distance", "Height of the force field area");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "fh_force", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_funcs(prop, "rna_ConstraintActuator_spring_get", "rna_ConstraintActuator_spring_set", NULL);
- RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 2);
- RNA_def_property_ui_text(prop, "Force", "Spring force within the force field area");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "fh_damping", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "maxrot[0]");
- RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 2);
- RNA_def_property_ui_text(prop, "Damping", "Damping factor of the force field spring");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* booleans */
- prop = RNA_def_property(srna, "use_force_distance", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_DISTANCE);
- RNA_def_property_ui_text(prop, "Force Distance", "Force distance of object to point of impact of ray");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_LOCAL);
- RNA_def_property_ui_text(prop, "L", "Set ray along object's axis or global axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_normal", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_NORMAL);
- RNA_def_property_ui_text(prop, "N",
- "Set object axis along (local axis) or parallel (global axis) to the normal at "
- "hit position");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_persistent", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_PERMANENT);
- RNA_def_property_ui_text(prop, "PER", "Persistent actuator: stays active even if ray does not reach target");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /*XXX to use an enum instead of a flag if possible */
- prop = RNA_def_property(srna, "use_material_detect", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_MATERIAL);
- RNA_def_property_ui_text(prop, "M/P", "Detect material instead of property");
- RNA_def_property_boolean_funcs(prop, NULL, "rna_Actuator_constraint_detect_material_set");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_fh_paralel_axis", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_DOROTFH);
- RNA_def_property_ui_text(prop, "Rot Fh", "Keep object axis parallel to normal");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_fh_normal", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_CONST_NORMAL);
- RNA_def_property_ui_text(prop, "N", "Add a horizontal spring force on slopes");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_edit_object_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_dyn_items[] = {
- {ACT_EDOB_RESTORE_DYN, "RESTOREDYN", 0, "Restore Dynamics", ""},
- {ACT_EDOB_SUSPEND_DYN, "SUSPENDDYN", 0, "Suspend Dynamics", ""},
- {ACT_EDOB_ENABLE_RB, "ENABLERIGIDBODY", 0, "Enable Rigid Body", ""},
- {ACT_EDOB_DISABLE_RB, "DISABLERIGIDBODY", 0, "Disable Rigid Body", ""},
- {ACT_EDOB_SET_MASS, "SETMASS", 0, "Set Mass", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_EDOB_ADD_OBJECT, "ADDOBJECT", 0, "Add Object", ""},
- {ACT_EDOB_END_OBJECT, "ENDOBJECT", 0, "End Object", ""},
- {ACT_EDOB_REPLACE_MESH, "REPLACEMESH", 0, "Replace Mesh", ""},
- {ACT_EDOB_TRACK_TO, "TRACKTO", 0, "Track to", ""},
- {ACT_EDOB_DYNAMICS, "DYNAMICS", 0, "Dynamics", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_track_axis_items[] = {
- {ACT_TRACK_TRAXIS_X, "TRACKAXISX", 0, "X axis", ""},
- {ACT_TRACK_TRAXIS_Y, "TRACKAXISY", 0, "Y axis", ""},
- {ACT_TRACK_TRAXIS_Z, "TRACKAXISZ", 0, "Z axis", ""},
- {ACT_TRACK_TRAXIS_NEGX, "TRACKAXISNEGX", 0, "-X axis", ""},
- {ACT_TRACK_TRAXIS_NEGY, "TRACKAXISNEGY", 0, "-Y axis", ""},
- {ACT_TRACK_TRAXIS_NEGZ, "TRACKAXISNEGZ", 0, "-Z axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_up_axis_items[] = {
- {ACT_TRACK_UP_X, "UPAXISX", 0, "X axis", ""},
- {ACT_TRACK_UP_Y, "UPAXISY", 0, "Y axis", ""},
- {ACT_TRACK_UP_Z, "UPAXISZ", 0, "Z axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "EditObjectActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Edit Object Actuator", "Actuator used to edit objects");
- RNA_def_struct_sdna_from(srna, "bEditObjectActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Edit Object", "The mode of the actuator");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "dynamic_operation", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "dyn_operation");
- RNA_def_property_enum_items(prop, prop_dyn_items);
- RNA_def_property_ui_text(prop, "Dynamic Operation", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "up_axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "upflag");
- RNA_def_property_enum_items(prop, prop_up_axis_items);
- RNA_def_property_ui_text(prop, "Up Axis", "The axis that points upward");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "track_axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "trackflag");
- RNA_def_property_enum_items(prop, prop_track_axis_items);
- RNA_def_property_ui_text(prop, "Track Axis", "The axis that points to the target object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "ob");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Object", "Add this Object and all its children (can't be on a visible layer)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "track_object", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "ob");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Object", "Track to this Object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "mesh", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Mesh");
- RNA_def_property_pointer_sdna(prop, NULL, "me");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Mesh",
- "Replace the existing, when left blank 'Phys' will remake the existing physics mesh");
- /* note: custom set function is ONLY to avoid rna setting a user for this. */
- RNA_def_property_pointer_funcs(prop, NULL, "rna_Actuator_editobject_mesh_set", NULL, NULL);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "time", PROP_INT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0, 2000, 1, 1);
- RNA_def_property_ui_text(prop, "Time", "Duration the new Object lives or the track takes");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0, 10000, 1, 2);
- RNA_def_property_ui_text(prop, "Mass", "The mass of the object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* floats 3 Arrays*/
- prop = RNA_def_property(srna, "linear_velocity", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "linVelocity");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -100.0, 100.0, 10, 2);
- RNA_def_property_ui_text(prop, "Linear Velocity", "Velocity upon creation");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "angular_velocity", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "angVelocity");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 2);
- RNA_def_property_ui_text(prop, "Angular Velocity", "Angular velocity upon creation");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* booleans */
- prop = RNA_def_property(srna, "use_local_linear_velocity", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "localflag", ACT_EDOB_LOCAL_LINV);
- RNA_def_property_ui_text(prop, "L", "Apply the transformation locally");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_local_angular_velocity", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "localflag", ACT_EDOB_LOCAL_ANGV);
- RNA_def_property_ui_text(prop, "L", "Apply the rotation locally");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_replace_display_mesh", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ACT_EDOB_REPLACE_MESH_NOGFX);
- RNA_def_property_ui_text(prop, "Gfx", "Replace the display mesh");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_replace_physics_mesh", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_EDOB_REPLACE_MESH_PHYS);
- RNA_def_property_ui_text(prop, "Phys",
- "Replace the physics mesh (triangle bounds only - compound shapes not supported)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_3d_tracking", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_TRACK_3D);
- RNA_def_property_ui_text(prop, "3D", "Enable 3D tracking");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_scene_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_SCENE_RESTART, "RESTART", 0, "Restart", ""},
- {ACT_SCENE_SET, "SET", 0, "Set Scene", ""},
- {ACT_SCENE_CAMERA, "CAMERA", 0, "Set Camera", ""},
- {ACT_SCENE_ADD_FRONT, "ADDFRONT", 0, "Add Overlay Scene", ""},
- {ACT_SCENE_ADD_BACK, "ADDBACK", 0, "Add Background Scene", ""},
- {ACT_SCENE_REMOVE, "REMOVE", 0, "Remove Scene", ""},
- {ACT_SCENE_SUSPEND, "SUSPEND", 0, "Suspend Scene", ""},
- {ACT_SCENE_RESUME, "RESUME", 0, "Resume Scene", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "SceneActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Scene Actuator", "");
- RNA_def_struct_sdna_from(srna, "bSceneActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Mode", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Camera_object_poll");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Camera Object", "Set this Camera (leave empty to refer to self object)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Scene");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Scene", "Scene to be added/removed/paused/resumed");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_random_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_distribution_items[] = {
- {ACT_RANDOM_BOOL_CONST, "BOOL_CONSTANT", 0, "Bool Constant", ""},
- {ACT_RANDOM_BOOL_UNIFORM, "BOOL_UNIFORM", 0, "Bool Uniform", ""},
- {ACT_RANDOM_BOOL_BERNOUILLI, "BOOL_BERNOUILLI", 0, "Bool Bernoulli", ""},
- {ACT_RANDOM_INT_CONST, "INT_CONSTANT", 0, "Int Constant", ""},
- {ACT_RANDOM_INT_UNIFORM, "INT_UNIFORM", 0, "Int Uniform", ""},
- {ACT_RANDOM_INT_POISSON, "INT_POISSON", 0, "Int Poisson", ""},
- {ACT_RANDOM_FLOAT_CONST, "FLOAT_CONSTANT", 0, "Float Constant", ""},
- {ACT_RANDOM_FLOAT_UNIFORM, "FLOAT_UNIFORM", 0, "Float Uniform", ""},
- {ACT_RANDOM_FLOAT_NORMAL, "FLOAT_NORMAL", 0, "Float Normal", ""},
- {ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL, "FLOAT_NEGATIVE_EXPONENTIAL", 0, "Float Neg. Exp.", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "RandomActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Random Actuator", "");
- RNA_def_struct_sdna_from(srna, "bRandomActuator", "data");
-
- prop = RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
- RNA_def_property_ui_range(prop, 0, 1000, 1, 1);
- RNA_def_property_range(prop, 0, MAXFRAME);
- RNA_def_property_ui_text(prop, "Seed",
- "Initial seed of the random generator, use Python for more freedom "
- "(choose 0 for not random)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "propname");
- RNA_def_property_ui_text(prop, "Property", "Assign the random value to this property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "distribution", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, prop_distribution_items);
- RNA_def_property_ui_text(prop, "Distribution", "Choose the type of distribution");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* arguments for the distribution */
- /* int_arg_1, int_arg_2, float_arg_1, float_arg_2 */
-
- /* ACT_RANDOM_BOOL_CONST */
- prop = RNA_def_property(srna, "use_always_true", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "int_arg_1", 1);
- RNA_def_property_ui_text(prop, "Always True", "Always false or always true");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_BOOL_UNIFORM */
- /* label => "Choose between true and false, 50% chance each" */
-
- /* ACT_RANDOM_BOOL_BERNOUILLI */
- prop = RNA_def_property(srna, "chance", PROP_FLOAT, PROP_PERCENTAGE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_1");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_ui_text(prop, "Chance", "Pick a number between 0 and 1, success if it's below this value");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_INT_CONST */
- prop = RNA_def_property(srna, "int_value", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "int_arg_1");
- RNA_def_property_ui_range(prop, -1000, 1000, 1, 1);
- RNA_def_property_ui_text(prop, "Value", "Always return this number");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_INT_UNIFORM */
- prop = RNA_def_property(srna, "int_min", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "int_arg_1");
- RNA_def_property_range(prop, -1000, 1000);
- RNA_def_property_ui_text(prop, "Min", "Choose a number from a range: lower boundary of the range");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "int_max", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "int_arg_2");
- RNA_def_property_range(prop, -1000, 1000);
- RNA_def_property_ui_text(prop, "Max", "Choose a number from a range: upper boundary of the range");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_INT_POISSON */
- prop = RNA_def_property(srna, "int_mean", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_1");
- RNA_def_property_range(prop, 0.01, 100.0);
- RNA_def_property_ui_text(prop, "Mean", "Expected mean value of the distribution");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_FLOAT_CONST */
- prop = RNA_def_property(srna, "float_value", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_1");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_ui_text(prop, "Value", "Always return this number");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_FLOAT_UNIFORM */
- prop = RNA_def_property(srna, "float_min", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_1");
- RNA_def_property_range(prop, -1000.0, 1000.0);
- RNA_def_property_ui_text(prop, "Min", "Choose a number from a range: lower boundary of the range");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "float_max", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_2");
- RNA_def_property_range(prop, -1000.0, 1000.0);
- RNA_def_property_ui_text(prop, "Max", "Choose a number from a range: upper boundary of the range");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_FLOAT_NORMAL */
- prop = RNA_def_property(srna, "float_mean", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_1");
- RNA_def_property_range(prop, -1000.0, 1000.0);
- RNA_def_property_ui_text(prop, "Mean", "A normal distribution: mean of the distribution");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "standard_derivation", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_2");
- RNA_def_property_range(prop, -1000.0, 1000.0);
- RNA_def_property_ui_text(prop, "SD", "A normal distribution: standard deviation of the distribution");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL */
- prop = RNA_def_property(srna, "half_life_time", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg_1");
- RNA_def_property_range(prop, -1000.0, 1000.0);
- RNA_def_property_ui_text(prop, "Half-Life Time", "Negative exponential dropoff");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_message_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_body_type_items[] = {
- {ACT_MESG_MESG, "TEXT", 0, "Text", ""},
- {ACT_MESG_PROP, "PROPERTY", 0, "Property", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "MessageActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Message Actuator", "");
- RNA_def_struct_sdna_from(srna, "bMessageActuator", "data");
-
- prop = RNA_def_property(srna, "to_property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "toPropName");
- RNA_def_property_ui_text(prop, "To",
- "Optional, send message to objects with this name only, or empty to broadcast");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "subject", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Subject", "Optional, message subject (this is what can be filtered on)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "body_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "bodyType");
- RNA_def_property_enum_items(prop, prop_body_type_items);
- RNA_def_property_ui_text(prop, "Body", "Toggle message type: either Text or a PropertyName");
-
- /* ACT_MESG_MESG */
- prop = RNA_def_property(srna, "body_message", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "body");
- RNA_def_property_ui_text(prop, "Body", "Optional, message body Text");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_MESG_PROP */
- prop = RNA_def_property(srna, "body_property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "body");
- RNA_def_property_ui_text(prop, "Prop Name", "The message body will be set by the Property Value");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_game_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
-/* {ACT_GAME_LOAD, "LOAD", 0, "Load Game", ""}, */
-/* {ACT_GAME_START, "START", 0, "Start Loaded Game", ""}, */
-/* keeping the load/start hacky for compatibility with 2.49 */
-/* ideally we could use ACT_GAME_START again and do a do_version() */
-
- {ACT_GAME_LOAD, "START", 0, "Start Game From File", ""},
- {ACT_GAME_RESTART, "RESTART", 0, "Restart Game", ""},
- {ACT_GAME_QUIT, "QUIT", 0, "Quit Game", ""},
- {ACT_GAME_SAVECFG, "SAVECFG", 0, "Save bge.logic.globalDict", ""},
- {ACT_GAME_LOADCFG, "LOADCFG", 0, "Load bge.logic.globalDict", ""},
- {ACT_GAME_SCREENSHOT, "SCREENSHOT", 0, "Screenshot", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "GameActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Game Actuator", "");
- RNA_def_struct_sdna_from(srna, "bGameActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Game", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* ACT_GAME_LOAD */
- prop = RNA_def_property(srna, "filename", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_ui_text(prop, "File",
- "The file to use, depending on the mode (e.g. the blend file to load or a destination "
- "for saving a screenshot) - use the \"//\" prefix for a relative path");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
- /*XXX to do: an operator that calls file_browse with relative_path on and blender filtering active */
-}
-
-static void rna_def_visibility_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "VisibilityActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Visibility Actuator", "Actuator to set visibility and occlusion of the object");
- RNA_def_struct_sdna_from(srna, "bVisibilityActuator", "data");
-
- prop = RNA_def_property(srna, "use_visible", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ACT_VISIBILITY_INVISIBLE);
- RNA_def_property_ui_text(prop, "Visible",
- "Set the objects visible (initialized from the object render restriction toggle in "
- "physics button)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_occlusion", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_VISIBILITY_OCCLUSION);
- RNA_def_property_ui_text(prop, "Occlusion",
- "Set the object to occlude objects behind it (initialized from the object type in "
- "physics button)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "apply_to_children", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_VISIBILITY_RECURSIVE);
- RNA_def_property_ui_text(prop, "Children",
- "Set all the children of this object to the same visibility/occlusion recursively");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_twodfilter_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_2DFILTER_ENABLED, "ENABLE", 0, "Enable Filter", ""},
- {ACT_2DFILTER_DISABLED, "DISABLE", 0, "Disable Filter", ""},
- {ACT_2DFILTER_NOFILTER, "REMOVE", 0, "Remove Filter", ""},
- {ACT_2DFILTER_MOTIONBLUR, "MOTIONBLUR", 0, "Motion Blur", ""},
- {ACT_2DFILTER_BLUR, "BLUR", 0, "Blur", ""},
- {ACT_2DFILTER_SHARPEN, "SHARPEN", 0, "Sharpen", ""},
- {ACT_2DFILTER_DILATION, "DILATION", 0, "Dilation", ""},
- {ACT_2DFILTER_EROSION, "EROSION", 0, "Erosion", ""},
- {ACT_2DFILTER_LAPLACIAN, "LAPLACIAN", 0, "Laplacian", ""},
- {ACT_2DFILTER_SOBEL, "SOBEL", 0, "Sobel", ""},
- {ACT_2DFILTER_PREWITT, "PREWITT", 0, "Prewitt", ""},
- {ACT_2DFILTER_GRAYSCALE, "GRAYSCALE", 0, "Gray Scale", ""},
- {ACT_2DFILTER_SEPIA, "SEPIA", 0, "Sepia", ""},
- {ACT_2DFILTER_INVERT, "INVERT", 0, "Invert", ""},
- {ACT_2DFILTER_CUSTOMFILTER, "CUSTOMFILTER", 0, "Custom Filter", ""},
-/* {ACT_2DFILTER_NUMBER_OF_FILTERS, "", 0, "Do not use it. Sentinel", ""}, */
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "Filter2DActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Filter 2D Actuator", "Actuator to apply screen graphic effects");
- RNA_def_struct_sdna_from(srna, "bTwoDFilterActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Filter 2D Type", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "glsl_shader", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "text");
- RNA_def_property_struct_type(prop, "Text");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Script", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "filter_pass", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "int_arg");
- RNA_def_property_ui_text(prop, "Pass Number", "Set filter order");
- RNA_def_property_range(prop, 0, 99); /*MAX_RENDER_PASS-1 */
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "motion_blur_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "float_arg");
- RNA_def_property_ui_text(prop, "Value", "Motion blur factor");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* booleans */
- prop = RNA_def_property(srna, "use_motion_blur", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", 1);
- RNA_def_property_ui_text(prop, "Enable", "Enable/Disable Motion Blur");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_parent_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_PARENT_SET, "SETPARENT", 0, "Set Parent", ""},
- {ACT_PARENT_REMOVE, "REMOVEPARENT", 0, "Remove Parent", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "ParentActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Parent Actuator", "");
- RNA_def_struct_sdna_from(srna, "bParentActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Scene", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "ob");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Parent Object", "Set this object as parent");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* booleans */
- prop = RNA_def_property(srna, "use_compound", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ACT_PARENT_COMPOUND);
- RNA_def_property_ui_text(prop, "Compound",
- "Add this object shape to the parent shape "
- "(only if the parent shape is already compound)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_ghost", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", ACT_PARENT_GHOST);
- RNA_def_property_ui_text(prop, "Ghost", "Make this object ghost while parented");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_state_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_STATE_SET, "SET", 0, "Set State", ""},
- {ACT_STATE_ADD, "ADD", 0, "Add State", ""},
- {ACT_STATE_REMOVE, "REMOVE", 0, "Remove State", ""},
- {ACT_STATE_CHANGE, "CHANGE", 0, "Change State", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "StateActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "State Actuator", "Actuator to handle states");
- RNA_def_struct_sdna_from(srna, "bStateActuator", "data");
-
- prop = RNA_def_property(srna, "operation", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Operation", "Select the bit operation on object state mask");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "states", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "mask", 1);
- RNA_def_property_array(prop, OB_MAX_STATES);
- RNA_def_property_ui_text(prop, "State", "");
- RNA_def_property_boolean_funcs(prop, NULL, "rna_StateActuator_state_set");
-}
-
-static void rna_def_armature_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_ARM_RUN, "RUN", 0, "Run Armature", ""},
- {ACT_ARM_ENABLE, "ENABLE", 0, "Enable", ""},
- {ACT_ARM_DISABLE, "DISABLE", 0, "Disable", ""},
- {ACT_ARM_SETTARGET, "SETTARGET", 0, "Set Target", ""},
- {ACT_ARM_SETWEIGHT, "SETWEIGHT", 0, "Set Weight", ""},
- {ACT_ARM_SETINFLUENCE, "SETINFLUENCE", 0, "Set Influence", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "ArmatureActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Armature Actuator", "");
- RNA_def_struct_sdna_from(srna, "bArmatureActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Constraint Type", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "bone", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "posechannel");
- RNA_def_property_ui_text(prop, "Bone", "Bone on which the constraint is defined");
- RNA_def_property_update(prop, NC_LOGIC, "rna_Actuator_Armature_update");
-
- prop = RNA_def_property(srna, "constraint", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "constraint");
- RNA_def_property_ui_text(prop, "Constraint", "Name of the constraint to control");
- RNA_def_property_update(prop, NC_LOGIC, "rna_Actuator_Armature_update");
-
- prop = RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Target", "Set this object as the target of the constraint");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "secondary_target", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "subtarget");
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Secondary Target",
- "Set this object as the secondary target of the constraint "
- "(only IK polar target at the moment)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "weight");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_ui_text(prop, "Weight", "Weight of this constraint");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "influence", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "influence");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_ui_text(prop, "Influence", "Influence of this constraint");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_steering_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_STEERING_SEEK, "SEEK", 0, "Seek", ""},
- {ACT_STEERING_FLEE, "FLEE", 0, "Flee", ""},
- {ACT_STEERING_PATHFOLLOWING, "PATHFOLLOWING", 0, "Path following", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem facingaxis_items[] = {
- {1, "X", 0, "X", ""},
- {2, "Y", 0, "Y", ""},
- {3, "Z", 0, "Z", ""},
- {4, "NEG_X", 0, "-X", ""},
- {5, "NEG_Y", 0, "-Y", ""},
- {6, "NEG_Z", 0, "-Z", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "SteeringActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Steering Actuator", "");
- RNA_def_struct_sdna_from(srna, "bSteeringActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Behavior", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "velocity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "velocity");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Velocity", "Velocity magnitude");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "acceleration", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "acceleration");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Acceleration", "Max acceleration");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "turn_speed", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "turnspeed");
- RNA_def_property_range(prop, 0.0, 720.0);
- RNA_def_property_ui_text(prop, "Turn Speed", "Max turn speed");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "dist");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Dist", "Relax distance");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "target");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Target Object", "Target object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "self_terminated", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_STEERING_SELFTERMINATED);
- RNA_def_property_ui_text(prop, "Self Terminated", "Terminate when target is reached");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_visualization", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_STEERING_ENABLEVISUALIZATION);
- RNA_def_property_ui_text(prop, "Visualize", "Enable debug visualization for 'Path following'");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "update_period", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "updateTime");
- RNA_def_property_ui_range(prop, -1, 100000, 1, 1);
- RNA_def_property_ui_text(prop, "Update period", "Path update period");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "navmesh", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_sdna(prop, NULL, "navmesh");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Navigation Mesh Object", "Navigation mesh");
- RNA_def_property_pointer_funcs(prop, NULL, "rna_SteeringActuator_navmesh_set", NULL, NULL);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "facing", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_STEERING_AUTOMATICFACING);
- RNA_def_property_ui_text(prop, "Facing", "Enable automatic facing");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "facing_axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "facingaxis");
- RNA_def_property_enum_items(prop, facingaxis_items);
- RNA_def_property_ui_text(prop, "Axis", "Axis for automatic facing");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "normal_up", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_STEERING_NORMALUP);
- RNA_def_property_ui_text(prop, "N", "Use normal of the navmesh to set \"UP\" vector");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "lock_z_velocity", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_STEERING_LOCKZVEL);
- RNA_def_property_ui_text(prop, "Lock Z velocity", "Disable simulation of linear motion along Z axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_mouse_actuator(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_type_items[] = {
- {ACT_MOUSE_VISIBILITY, "VISIBILITY", 0, "Visibility", ""},
- {ACT_MOUSE_LOOK, "LOOK", 0, "Look", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_object_axis_items[] = {
- {ACT_MOUSE_OBJECT_AXIS_X, "OBJECT_AXIS_X", 0, "X Axis", ""},
- {ACT_MOUSE_OBJECT_AXIS_Y, "OBJECT_AXIS_Y", 0, "Y Axis", ""},
- {ACT_MOUSE_OBJECT_AXIS_Z, "OBJECT_AXIS_Z", 0, "Z Axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "MouseActuator", "Actuator");
- RNA_def_struct_ui_text(srna, "Mouse Actuator", "");
- RNA_def_struct_sdna_from(srna, "bMouseActuator", "data");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Mode", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Visibility */
- prop = RNA_def_property(srna, "visible", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_VISIBLE);
- RNA_def_property_ui_text(prop, "Visible", "Make mouse cursor visible");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Mouse Look */
- prop = RNA_def_property(srna, "use_axis_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_USE_AXIS_X);
- RNA_def_property_ui_text(prop, "Use X Axis", "Calculate mouse movement on the X axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_axis_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_USE_AXIS_Y);
- RNA_def_property_ui_text(prop, "Use Y Axis", "Calculate mouse movement on the Y axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "reset_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_RESET_X);
- RNA_def_property_ui_text(prop, "Reset",
- "Reset the cursor's X position to the center of the screen space after calculating");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "reset_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_RESET_Y);
- RNA_def_property_ui_text(prop, "Reset",
- "Reset the cursor's Y position to the center of the screen space after calculating");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "local_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_LOCAL_X);
- RNA_def_property_ui_text(prop, "Local", "Apply rotation locally");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "local_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", ACT_MOUSE_LOCAL_Y);
- RNA_def_property_ui_text(prop, "Local", "Apply rotation locally");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "threshold_x", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "threshold[0]");
- RNA_def_property_ui_range(prop, 0, 0.5, 1, 3);
- RNA_def_property_ui_text(prop, "Threshold", "Amount of X motion before mouse movement will register");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "threshold_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "threshold[1]");
- RNA_def_property_ui_range(prop, 0, 0.5, 1, 3);
- RNA_def_property_ui_text(prop, "Threshold", "Amount of Y motion before mouse movement will register");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "object_axis_x", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "object_axis[0]");
- RNA_def_property_enum_items(prop, prop_object_axis_items);
- RNA_def_property_ui_text(prop, "Object Axis", "Local object axis mouse movement in the X direction will apply to");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "object_axis_y", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "object_axis[1]");
- RNA_def_property_enum_items(prop, prop_object_axis_items);
- RNA_def_property_ui_text(prop, "Object Axis", "Local object axis mouse movement in the Y direction will apply to");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "sensitivity_x", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sensitivity[0]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 0.2, 3);
- RNA_def_property_ui_text(prop, "Sensitivity", "Sensitivity of the X axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "sensitivity_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sensitivity[1]");
- RNA_def_property_ui_range(prop, -100.0, 100.0, 0.2, 3);
- RNA_def_property_ui_text(prop, "Sensitivity", "Sensitivity of the Y axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "min_x", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "limit_x[0]");
- RNA_def_property_ui_range(prop, DEG2RADF(-3600.0f), 0.0, 9, 3);
- RNA_def_property_ui_text(prop, "Min", "Maximum negative rotation allowed by X mouse movement (0 for infinite)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "max_x", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "limit_x[1]");
- RNA_def_property_ui_range(prop, 0.0, DEG2RADF(3600.0f), 9, 3);
- RNA_def_property_ui_text(prop, "Max", "Maximum positive rotation allowed by X mouse movement (0 for infinite)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "min_y", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "limit_y[0]");
- RNA_def_property_ui_range(prop, DEG2RADF(-3600.0f), 0.0, 9, 3);
- RNA_def_property_ui_text(prop, "Min", "Maximum negative rotation allowed by Y mouse movement (0 for infinite)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "max_y", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "limit_y[1]");
- RNA_def_property_ui_range(prop, 0.0, DEG2RADF(3600.0f), 9, 3);
- RNA_def_property_ui_text(prop, "Max", "Maximum positive rotation allowed by Y mouse movement (0 for infinite)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-void RNA_def_actuator(BlenderRNA *brna)
-{
- rna_def_actuator(brna);
-
- rna_def_action_actuator(brna);
- rna_def_object_actuator(brna);
- rna_def_camera_actuator(brna);
- rna_def_sound_actuator(brna);
- rna_def_property_actuator(brna);
- rna_def_constraint_actuator(brna);
- rna_def_edit_object_actuator(brna);
- rna_def_scene_actuator(brna);
- rna_def_random_actuator(brna);
- rna_def_message_actuator(brna);
- rna_def_game_actuator(brna);
- rna_def_visibility_actuator(brna);
- rna_def_twodfilter_actuator(brna);
- rna_def_parent_actuator(brna);
- rna_def_state_actuator(brna);
- rna_def_armature_actuator(brna);
- rna_def_steering_actuator(brna);
- rna_def_mouse_actuator(brna);
-}
-
-#endif
diff --git a/source/blender/makesrna/intern/rna_actuator_api.c b/source/blender/makesrna/intern/rna_actuator_api.c
deleted file mode 100644
index 23fdd8a1d5b..00000000000
--- a/source/blender/makesrna/intern/rna_actuator_api.c
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2010 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/makesrna/intern/rna_actuator_api.c
- * \ingroup RNA
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "WM_types.h"
-#include "RNA_define.h"
-
-#include "rna_internal.h" /* own include */
-
-#ifdef RNA_RUNTIME
-
-#include "BKE_sca.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
-
-static void rna_Actuator_link(bActuator *act, bController *cont)
-{
- link_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks, sizeof(bActuator *));
-}
-
-static void rna_Actuator_unlink(bActuator *act, bController *cont)
-{
- unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
-}
-
-#else
-
-void RNA_api_actuator(StructRNA *srna)
-{
- FunctionRNA *func;
- PropertyRNA *parm;
-
- func = RNA_def_function(srna, "link", "rna_Actuator_link");
- RNA_def_function_ui_description(func, "Link the actuator to a controller");
- parm = RNA_def_pointer(func, "controller", "Controller", "", "Controller to link to");
- RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- RNA_def_property_update(parm, NC_LOGIC, NULL);
-
- func = RNA_def_function(srna, "unlink", "rna_Actuator_unlink");
- RNA_def_function_ui_description(func, "Unlink the actuator from a controller");
- parm = RNA_def_pointer(func, "controller", "Controller", "", "Controller to unlink from");
- RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- RNA_def_property_update(parm, NC_LOGIC, NULL);
-}
-
-#endif
-
diff --git a/source/blender/makesrna/intern/rna_animation.c b/source/blender/makesrna/intern/rna_animation.c
index 6779e74700d..6eed4153e0d 100644
--- a/source/blender/makesrna/intern/rna_animation.c
+++ b/source/blender/makesrna/intern/rna_animation.c
@@ -73,10 +73,11 @@ const EnumPropertyItem rna_enum_keying_flag_items[] = {
#include "BLI_math_base.h"
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_nla.h"
+#include "DEG_depsgraph.h"
+
#include "DNA_object_types.h"
#include "WM_api.h"
@@ -88,7 +89,7 @@ static void rna_AnimData_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Point
/* tag for refresh so that scheduled updates (e.g. action changed) will
* get computed and reflected in the scene [#34869]
*/
- DAG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA);
}
static int rna_AnimData_action_editable(PointerRNA *ptr, const char **UNUSED(r_info))
@@ -114,7 +115,7 @@ static void rna_AnimData_action_set(PointerRNA *ptr, PointerRNA value)
adt = BKE_animdata_from_id(ownerId);
if (adt) {
adt->recalc |= ADT_RECALC_ANIM;
- DAG_id_tag_update(ownerId, OB_RECALC_TIME);
+ DEG_id_tag_update(ownerId, OB_RECALC_TIME);
}
}
@@ -584,6 +585,34 @@ static FCurve *rna_Driver_find(AnimData *adt, ReportList *reports, const char *d
return list_find_fcurve(&adt->drivers, data_path, index);
}
+bool rna_AnimaData_override_apply(
+ PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *ptr_storage,
+ PropertyRNA *prop_dst, PropertyRNA *prop_src, PropertyRNA *UNUSED(prop_storage),
+ const int len_dst, const int len_src, const int len_storage,
+ IDOverrideStaticPropertyOperation *opop)
+{
+ BLI_assert(len_dst == len_src && (!ptr_storage || len_dst == len_storage) && len_dst == 0);
+ BLI_assert(opop->operation == IDOVERRIDESTATIC_OP_REPLACE && "Unsupported RNA override operation on animdata pointer");
+ UNUSED_VARS_NDEBUG(ptr_storage, len_dst, len_src, len_storage, opop);
+
+ /* AnimData is a special case, since you cannot edit/replace it, it's either existent or not. */
+ AnimData *adt_dst = RNA_property_pointer_get(ptr_dst, prop_dst).data;
+ AnimData *adt_src = RNA_property_pointer_get(ptr_src, prop_src).data;
+
+ if (adt_dst == NULL && adt_src != NULL) {
+ /* Copy anim data from reference into final local ID. */
+ BKE_animdata_copy_id(NULL, ptr_dst->id.data, ptr_src->id.data, false, true);
+ return true;
+ }
+ else if (adt_dst != NULL && adt_src == NULL) {
+ /* Override has cleared/removed anim data from its reference. */
+ BKE_animdata_free(ptr_dst->id.data, true);
+ return true;
+ }
+
+ return false;
+}
+
#else
/* helper function for Keying Set -> keying settings */
@@ -998,6 +1027,8 @@ void rna_def_animdata_common(StructRNA *srna)
prop = RNA_def_property(srna, "animation_data", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "adt");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
+ RNA_def_property_override_funcs(prop, NULL, NULL, "rna_AnimaData_override_apply");
RNA_def_property_ui_text(prop, "Animation Data", "Animation data for this data-block");
}
@@ -1021,7 +1052,7 @@ static void rna_def_animdata(BlenderRNA *brna)
/* Active Action */
prop = RNA_def_property(srna, "action", PROP_POINTER, PROP_NONE);
/* this flag as well as the dynamic test must be defined for this to be editable... */
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT | PROP_OVERRIDABLE_STATIC);
RNA_def_property_pointer_funcs(prop, NULL, "rna_AnimData_action_set", NULL, "rna_Action_id_poll");
RNA_def_property_editable_func(prop, "rna_AnimData_action_editable");
RNA_def_property_ui_text(prop, "Action", "Active Action for this data-block");
diff --git a/source/blender/makesrna/intern/rna_armature.c b/source/blender/makesrna/intern/rna_armature.c
index 7feca708fe8..1747d2fbc23 100644
--- a/source/blender/makesrna/intern/rna_armature.c
+++ b/source/blender/makesrna/intern/rna_armature.c
@@ -44,18 +44,19 @@
#ifdef RNA_RUNTIME
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_idprop.h"
#include "BKE_main.h"
#include "ED_armature.h"
#include "BKE_armature.h"
+#include "DEG_depsgraph.h"
+
static void rna_Armature_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
ID *id = ptr->id.data;
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
/*WM_main_add_notifier(NC_OBJECT|ND_POSE, NULL); */
}
@@ -146,6 +147,7 @@ static void rna_Armature_redraw_data(Main *UNUSED(bmain), Scene *UNUSED(scene),
{
ID *id = ptr->id.data;
+ DEG_id_tag_update(id, DEG_TAG_COPY_ON_WRITE);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
}
@@ -173,7 +175,7 @@ static void rna_Bone_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Po
bArmature *arm = (bArmature *)id;
if (arm->flag & ARM_HAS_VIZ_DEPS) {
- DAG_id_tag_update(id, OB_RECALC_DATA);
+ DEG_id_tag_update(id, OB_RECALC_DATA);
}
}
else if (GS(id->name) == ID_OB) {
@@ -181,7 +183,7 @@ static void rna_Bone_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Po
bArmature *arm = (bArmature *)ob->data;
if (arm->flag & ARM_HAS_VIZ_DEPS) {
- DAG_id_tag_update(id, OB_RECALC_DATA);
+ DEG_id_tag_update(id, OB_RECALC_DATA);
}
}
}
@@ -725,6 +727,7 @@ static void rna_def_bone(BlenderRNA *brna)
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Bone");
RNA_def_property_pointer_sdna(prop, NULL, "parent");
+ RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_ui_text(prop, "Parent", "Parent bone (in same Armature)");
RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
@@ -732,6 +735,7 @@ static void rna_def_bone(BlenderRNA *brna)
prop = RNA_def_property(srna, "children", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "childbase", NULL);
RNA_def_property_struct_type(prop, "Bone");
+ RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_ui_text(prop, "Children", "Bones which are children of this bone");
rna_def_bone_common(srna, 0);
@@ -986,11 +990,6 @@ static void rna_def_armature(BlenderRNA *brna)
{ARM_WIRE, "WIRE", 0, "Wire", "Display bones as thin wires, showing subdivision and B-Splines"},
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem prop_vdeformer[] = {
- {ARM_VDEF_BLENDER, "BLENDER", 0, "Blender", "Use Blender's armature vertex deformation"},
- {ARM_VDEF_BGE_CPU, "BGE_CPU", 0, "BGE", "Use vertex deformation code optimized for the BGE"},
- {0, NULL, 0, NULL, NULL}
- };
static const EnumPropertyItem prop_ghost_type_items[] = {
{ARM_GHOST_CUR, "CURRENT_FRAME", 0, "Around Frame",
"Display Ghosts of poses within a fixed number of frames around the current frame"},
@@ -1047,13 +1046,6 @@ static void rna_def_armature(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
- prop = RNA_def_property(srna, "deform_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "gevertdeformer");
- RNA_def_property_enum_items(prop, prop_vdeformer);
- RNA_def_property_ui_text(prop, "Vertex Deformer", "Vertex Deformer Method (Game Engine only)");
- RNA_def_property_update(prop, 0, "rna_Armature_redraw_data");
- RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
-
/* XXX deprecated ....... old animviz for armatures only */
prop = RNA_def_property(srna, "ghost_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "ghosttype");
diff --git a/source/blender/makesrna/intern/rna_boid.c b/source/blender/makesrna/intern/rna_boid.c
index fd3694e7c45..98ca58e0edd 100644
--- a/source/blender/makesrna/intern/rna_boid.c
+++ b/source/blender/makesrna/intern/rna_boid.c
@@ -87,9 +87,11 @@ static const EnumPropertyItem boidruleset_type_items[] = {
#include "BLI_math_base.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_particle.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
static void rna_Boids_reset(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
if (ptr->type == &RNA_ParticleSystem) {
@@ -97,10 +99,10 @@ static void rna_Boids_reset(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRN
psys->recalc = PSYS_RECALC_RESET;
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
}
else
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA | PSYS_RECALC_RESET);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA | PSYS_RECALC_RESET);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
}
@@ -111,12 +113,12 @@ static void rna_Boids_reset_deps(Main *bmain, Scene *UNUSED(scene), PointerRNA *
psys->recalc = PSYS_RECALC_RESET;
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
}
else
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA | PSYS_RECALC_RESET);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA | PSYS_RECALC_RESET);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
}
diff --git a/source/blender/makesrna/intern/rna_brush.c b/source/blender/makesrna/intern/rna_brush.c
index 1fd17afdc60..d227d7a3dbe 100644
--- a/source/blender/makesrna/intern/rna_brush.c
+++ b/source/blender/makesrna/intern/rna_brush.c
@@ -44,8 +44,8 @@
#include "WM_types.h"
static const EnumPropertyItem prop_direction_items[] = {
- {0, "ADD", 0, "Add", "Add effect of brush"},
- {BRUSH_DIR_IN, "SUBTRACT", 0, "Subtract", "Subtract effect of brush"},
+ {0, "ADD", ICON_ZOOMIN, "Add", "Add effect of brush"},
+ {BRUSH_DIR_IN, "SUBTRACT", ICON_ZOOMOUT, "Subtract", "Subtract effect of brush"},
{0, NULL, 0, NULL, NULL}
};
@@ -371,17 +371,23 @@ static void rna_Brush_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerR
/*WM_main_add_notifier(NC_SPACE|ND_SPACE_VIEW3D, NULL); */
}
-static void rna_Brush_main_tex_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Brush_main_tex_update(bContext *C, PointerRNA *ptr)
{
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Brush *br = (Brush *)ptr->data;
- BKE_paint_invalidate_overlay_tex(scene, br->mtex.tex);
+ BKE_paint_invalidate_overlay_tex(scene, view_layer, br->mtex.tex);
rna_Brush_update(bmain, scene, ptr);
}
-static void rna_Brush_secondary_tex_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Brush_secondary_tex_update(bContext *C, PointerRNA *ptr)
{
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Brush *br = (Brush *)ptr->data;
- BKE_paint_invalidate_overlay_tex(scene, br->mask_mtex.tex);
+ BKE_paint_invalidate_overlay_tex(scene, view_layer, br->mask_mtex.tex);
rna_Brush_update(bmain, scene, ptr);
}
@@ -436,14 +442,17 @@ static void rna_Brush_icon_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
WM_main_add_notifier(NC_BRUSH | NA_EDITED, br);
}
-static void rna_TextureSlot_brush_angle_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_TextureSlot_brush_angle_update(bContext *C, PointerRNA *ptr)
{
+ Scene *scene = CTX_data_scene(C);
MTex *mtex = ptr->data;
/* skip invalidation of overlay for stencil mode */
- if (mtex->mapping != MTEX_MAP_MODE_STENCIL)
- BKE_paint_invalidate_overlay_tex(scene, mtex->tex);
+ if (mtex->mapping != MTEX_MAP_MODE_STENCIL) {
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ BKE_paint_invalidate_overlay_tex(scene, view_layer, mtex->tex);
+ }
- rna_TextureSlot_update(bmain, scene, ptr);
+ rna_TextureSlot_update(C, ptr);
}
static void rna_Brush_set_size(PointerRNA *ptr, int value)
@@ -657,39 +666,46 @@ static void rna_def_brush_texture_slot(BlenderRNA *brna)
RNA_def_property_float_sdna(prop, NULL, "rot");
RNA_def_property_range(prop, 0, M_PI * 2);
RNA_def_property_ui_text(prop, "Angle", "Brush texture rotation");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_TextureSlot_brush_angle_update");
prop = RNA_def_property(srna, "map_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "brush_map_mode");
RNA_def_property_enum_items(prop, prop_map_mode_items);
RNA_def_property_ui_text(prop, "Mode", "");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "tex_paint_map_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "brush_map_mode");
RNA_def_property_enum_items(prop, prop_tex_paint_map_mode_items);
RNA_def_property_ui_text(prop, "Mode", "");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "mask_map_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "brush_map_mode");
RNA_def_property_enum_items(prop, prop_mask_paint_map_mode_items);
RNA_def_property_ui_text(prop, "Mode", "");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "use_rake", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "brush_angle_mode", MTEX_ANGLE_RAKE);
RNA_def_property_ui_text(prop, "Rake", "");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "use_random", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "brush_angle_mode", MTEX_ANGLE_RANDOM);
RNA_def_property_ui_text(prop, "Random", "");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "random_angle", PROP_FLOAT, PROP_ANGLE);
RNA_def_property_range(prop, 0, M_PI * 2);
RNA_def_property_ui_text(prop, "Random Angle", "Brush texture random angle");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
TEXTURE_CAPABILITY(has_texture_angle_source, "Has Texture Angle Source");
@@ -1366,7 +1382,7 @@ static void rna_def_brush(BlenderRNA *brna)
prop = RNA_def_property(srna, "texture", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "mtex.tex");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Texture", "");
RNA_def_property_update(prop, NC_TEXTURE, "rna_Brush_main_tex_update");
@@ -1378,7 +1394,7 @@ static void rna_def_brush(BlenderRNA *brna)
prop = RNA_def_property(srna, "mask_texture", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "mask_mtex.tex");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Mask Texture", "");
RNA_def_property_update(prop, NC_TEXTURE, "rna_Brush_secondary_tex_update");
diff --git a/source/blender/makesrna/intern/rna_cachefile.c b/source/blender/makesrna/intern/rna_cachefile.c
index 73928d377f1..c0aa1f2a9f4 100644
--- a/source/blender/makesrna/intern/rna_cachefile.c
+++ b/source/blender/makesrna/intern/rna_cachefile.c
@@ -37,7 +37,6 @@
#include "BLI_string.h"
#include "BKE_cachefile.h"
-#include "BKE_depsgraph.h"
#include "DEG_depsgraph.h"
@@ -52,7 +51,7 @@ static void rna_CacheFile_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
CacheFile *cache_file = (CacheFile *)ptr->data;
- DAG_id_tag_update(&cache_file->id, 0);
+ DEG_id_tag_update(&cache_file->id, 0);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
UNUSED_VARS(bmain, scene);
@@ -63,7 +62,7 @@ static void rna_CacheFile_update_handle(Main *bmain, Scene *scene, PointerRNA *p
CacheFile *cache_file = ptr->data;
if ((cache_file->flag & CACHEFILE_DIRTY) != 0) {
- BKE_cachefile_clean(scene, cache_file);
+ BKE_cachefile_clean(bmain, cache_file);
BLI_freelistN(&cache_file->object_paths);
cache_file->flag &= ~CACHEFILE_DIRTY;
}
diff --git a/source/blender/makesrna/intern/rna_camera.c b/source/blender/makesrna/intern/rna_camera.c
index 981ae75e7c5..146a8e2738d 100644
--- a/source/blender/makesrna/intern/rna_camera.c
+++ b/source/blender/makesrna/intern/rna_camera.c
@@ -30,20 +30,22 @@
#include "BLI_math.h"
+#include "RNA_access.h"
#include "RNA_define.h"
#include "rna_internal.h"
+#include "WM_api.h"
#include "WM_types.h"
#ifdef RNA_RUNTIME
#include "BKE_camera.h"
-#include "BKE_depsgraph.h"
#include "BKE_object.h"
#include "BKE_sequencer.h"
-#include "WM_api.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
static float rna_Camera_angle_get(PointerRNA *ptr)
{
@@ -87,14 +89,43 @@ static void rna_Camera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointer
{
Camera *camera = (Camera *)ptr->id.data;
- DAG_id_tag_update(&camera->id, 0);
+ DEG_id_tag_update(&camera->id, 0);
}
static void rna_Camera_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
Camera *camera = (Camera *)ptr->id.data;
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(&camera->id, 0);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(&camera->id, 0);
+}
+
+static CameraBGImage *rna_Camera_background_images_new(Camera *cam)
+{
+ CameraBGImage *bgpic = BKE_camera_background_image_new(cam);
+
+ WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
+
+ return bgpic;
+}
+
+static void rna_Camera_background_images_remove(Camera *cam, ReportList *reports, PointerRNA *bgpic_ptr)
+{
+ CameraBGImage *bgpic = bgpic_ptr->data;
+ if (BLI_findindex(&cam->bg_images, bgpic) == -1) {
+ BKE_report(reports, RPT_ERROR, "Background image cannot be removed");
+ }
+
+ BKE_camera_background_image_remove(cam, bgpic);
+ RNA_POINTER_INVALIDATE(bgpic_ptr);
+
+ WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
+}
+
+static void rna_Camera_background_images_clear(Camera *cam)
+{
+ BKE_camera_background_image_clear(cam);
+
+ WM_main_add_notifier(NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, cam);
}
static void rna_Camera_dof_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
@@ -107,6 +138,161 @@ static void rna_Camera_dof_update(Main *UNUSED(bmain), Scene *scene, PointerRNA
#else
+static void rna_def_camera_background_image(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static const EnumPropertyItem bgpic_source_items[] = {
+ {CAM_BGIMG_SOURCE_IMAGE, "IMAGE", 0, "Image", ""},
+ {CAM_BGIMG_SOURCE_MOVIE, "MOVIE_CLIP", 0, "Movie Clip", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static const EnumPropertyItem bgpic_camera_frame_items[] = {
+ {0, "STRETCH", 0, "Stretch", ""},
+ {CAM_BGIMG_FLAG_CAMERA_ASPECT, "FIT", 0, "Fit", ""},
+ {CAM_BGIMG_FLAG_CAMERA_ASPECT | CAM_BGIMG_FLAG_CAMERA_CROP, "CROP", 0, "Crop", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static const EnumPropertyItem bgpic_draw_depth_items[] = {
+ {0, "BACK", 0, "Back", ""},
+ {CAM_BGIMG_FLAG_FOREGROUND, "FRONT", 0, "Front", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ srna = RNA_def_struct(brna, "CameraBackgroundImage", NULL);
+ RNA_def_struct_sdna(srna, "CameraBGImage");
+ RNA_def_struct_ui_text(srna, "Background Image", "Image and settings for display in the 3D View background");
+
+ prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "source");
+ RNA_def_property_enum_items(prop, bgpic_source_items);
+ RNA_def_property_ui_text(prop, "Background Source", "Data source used for background");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "ima");
+ RNA_def_property_ui_text(prop, "Image", "Image displayed and edited in this space");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "clip");
+ RNA_def_property_ui_text(prop, "MovieClip", "Movie clip displayed and edited in this space");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_pointer_sdna(prop, NULL, "iuser");
+ RNA_def_property_ui_text(prop, "Image User",
+ "Parameters defining which layer, pass and frame of the image is displayed");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "clip_user", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_struct_type(prop, "MovieClipUser");
+ RNA_def_property_pointer_sdna(prop, NULL, "cuser");
+ RNA_def_property_ui_text(prop, "Clip User", "Parameters defining which frame of the movie clip is displayed");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_XYZ);
+ RNA_def_property_float_sdna(prop, NULL, "offset");
+ RNA_def_property_ui_text(prop, "Offset", "");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "scale");
+ RNA_def_property_ui_text(prop, "Scale", "Scale the background image");
+ RNA_def_property_range(prop, 0.0, FLT_MAX);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_ANGLE);
+ RNA_def_property_float_sdna(prop, NULL, "rotation");
+ RNA_def_property_ui_text(prop, "Rotation", "Rotation for the background image (ortho view only)");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "use_flip_x", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FLIP_X);
+ RNA_def_property_ui_text(prop, "Flip Horizontally", "Flip the background image horizontally");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "use_flip_y", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FLIP_Y);
+ RNA_def_property_ui_text(prop, "Flip Vertically", "Flip the background image vertically");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "alpha");
+ RNA_def_property_ui_text(prop, "Alpha", "Image opacity to blend the image against the background color");
+ RNA_def_property_range(prop, 0.0, 1.0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_EXPANDED);
+ RNA_def_property_ui_text(prop, "Show Expanded", "Show the expanded in the user interface");
+ RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
+
+ prop = RNA_def_property(srna, "use_camera_clip", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_CAMERACLIP);
+ RNA_def_property_ui_text(prop, "Camera Clip", "Use movie clip from active scene camera");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "show_background_image", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_DISABLED);
+ RNA_def_property_ui_text(prop, "Show Background Image", "Show this image as background");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "show_on_foreground", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_BGIMG_FLAG_FOREGROUND);
+ RNA_def_property_ui_text(prop, "Show On Foreground", "Show this image in front of objects in viewport");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ /* expose 1 flag as a enum of 2 items */
+ prop = RNA_def_property(srna, "draw_depth", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
+ RNA_def_property_enum_items(prop, bgpic_draw_depth_items);
+ RNA_def_property_ui_text(prop, "Depth", "Draw under or over everything");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ /* expose 2 flags as a enum of 3 items */
+ prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
+ RNA_def_property_enum_items(prop, bgpic_camera_frame_items);
+ RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+}
+
+
+static void rna_def_camera_background_images(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "CameraBackgroundImages");
+ srna = RNA_def_struct(brna, "CameraBackgroundImages", NULL);
+ RNA_def_struct_sdna(srna, "Camera");
+ RNA_def_struct_ui_text(srna, "Background Images", "Collection of background images");
+
+ func = RNA_def_function(srna, "new", "rna_Camera_background_images_new");
+ RNA_def_function_ui_description(func, "Add new background image");
+ parm = RNA_def_pointer(func, "image", "CameraBackgroundImage", "", "Image displayed as viewport background");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_Camera_background_images_remove");
+ RNA_def_function_ui_description(func, "Remove background image");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "image", "CameraBackgroundImage", "", "Image displayed as viewport background");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+
+ func = RNA_def_function(srna, "clear", "rna_Camera_background_images_clear");
+ RNA_def_function_ui_description(func, "Remove all background images");
+}
+
static void rna_def_camera_stereo_data(BlenderRNA *brna)
{
StructRNA *srna;
@@ -381,6 +567,12 @@ void RNA_def_camera(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Show Sensor Size", "Show sensor size (film gate) in Camera view");
RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
+ prop = RNA_def_property(srna, "show_background_images", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", CAM_SHOW_BG_IMAGE);
+ RNA_def_property_ui_text(prop, "Display Background Images",
+ "Display reference images behind objects in the 3D View");
+ RNA_def_property_update(prop, NC_CAMERA | ND_DRAW_RENDER_VIEWPORT, NULL);
+
prop = RNA_def_property(srna, "lens_unit", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
RNA_def_property_enum_items(prop, prop_lens_unit_items);
@@ -399,8 +591,17 @@ void RNA_def_camera(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "GPU Depth Of Field", "");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
+ prop = RNA_def_property(srna, "background_images", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "bg_images", NULL);
+ RNA_def_property_struct_type(prop, "CameraBackgroundImage");
+ RNA_def_property_ui_text(prop, "Background Images", "List of background images");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
rna_def_animdata_common(srna);
+ rna_def_camera_background_image(brna);
+ rna_def_camera_background_images(brna, prop);
+
/* Nested Data */
RNA_define_animate_sdna(true);
diff --git a/source/blender/makesrna/intern/rna_cloth.c b/source/blender/makesrna/intern/rna_cloth.c
index 0ac5bf899a3..3d1a1458102 100644
--- a/source/blender/makesrna/intern/rna_cloth.c
+++ b/source/blender/makesrna/intern/rna_cloth.c
@@ -46,19 +46,20 @@
#ifdef RNA_RUNTIME
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
static void rna_cloth_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
}
static void rna_cloth_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
rna_cloth_update(bmain, scene, ptr);
}
@@ -70,7 +71,7 @@ static void rna_cloth_pinning_changed(Main *UNUSED(bmain), Scene *UNUSED(scene),
cloth_free_modifier(clmd);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
}
diff --git a/source/blender/makesrna/intern/rna_color.c b/source/blender/makesrna/intern/rna_color.c
index d51436df563..f895cfbbf0c 100644
--- a/source/blender/makesrna/intern/rna_color.c
+++ b/source/blender/makesrna/intern/rna_color.c
@@ -54,13 +54,14 @@
#include "BKE_colorband.h"
#include "BKE_colortools.h"
-#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BKE_movieclip.h"
#include "BKE_node.h"
#include "BKE_sequencer.h"
#include "BKE_linestyle.h"
+#include "DEG_depsgraph.h"
+
#include "ED_node.h"
#include "IMB_colormanagement.h"
@@ -159,17 +160,6 @@ static char *rna_ColorRamp_path(PointerRNA *ptr)
ID *id = ptr->id.data;
switch (GS(id->name)) {
- case ID_MA: /* material has 2 cases - diffuse and specular */
- {
- Material *ma = (Material *)id;
-
- if (ptr->data == ma->ramp_col)
- path = BLI_strdup("diffuse_ramp");
- else if (ptr->data == ma->ramp_spec)
- path = BLI_strdup("specular_ramp");
- break;
- }
-
case ID_NT:
{
bNodeTree *ntree = (bNodeTree *)id;
@@ -244,22 +234,6 @@ static char *rna_ColorRampElement_path(PointerRNA *ptr)
ID *id = ptr->id.data;
switch (GS(id->name)) {
- case ID_MA: /* 2 cases for material - diffuse and spec */
- {
- Material *ma = (Material *)id;
-
- /* try diffuse first */
- if (ma->ramp_col) {
- RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_col, &ramp_ptr);
- COLRAMP_GETPATH;
- }
- /* try specular if not diffuse */
- if (!path && ma->ramp_spec) {
- RNA_pointer_create(id, &RNA_ColorRamp, ma->ramp_spec, &ramp_ptr);
- COLRAMP_GETPATH;
- }
- break;
- }
case ID_NT:
{
bNodeTree *ntree = (bNodeTree *)id;
@@ -315,7 +289,7 @@ static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *
{
Material *ma = ptr->id.data;
- DAG_id_tag_update(&ma->id, 0);
+ DEG_id_tag_update(&ma->id, 0);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
break;
}
@@ -335,7 +309,7 @@ static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *
{
Tex *tex = ptr->id.data;
- DAG_id_tag_update(&tex->id, 0);
+ DEG_id_tag_update(&tex->id, 0);
WM_main_add_notifier(NC_TEXTURE, tex);
break;
}
@@ -350,7 +324,7 @@ static void rna_ColorRamp_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *
{
ParticleSettings *part = ptr->id.data;
- DAG_id_tag_update(&part->id, OB_RECALC_DATA | PSYS_RECALC_REDO);
+ DEG_id_tag_update(&part->id, OB_RECALC_DATA | PSYS_RECALC_REDO);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, part);
}
default:
@@ -446,7 +420,7 @@ static void rna_ColorManagedDisplaySettings_display_device_update(Main *UNUSED(b
IMB_colormanagement_validate_settings(&scene->display_settings, &scene->view_settings);
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
}
}
@@ -581,7 +555,7 @@ static void rna_ColorManagedColorspaceSettings_reload_update(Main *UNUSED(bmain)
if (GS(id->name) == ID_IM) {
Image *ima = (Image *) id;
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
BKE_image_signal(ima, NULL, IMA_SIGNAL_COLORMANAGE);
@@ -664,7 +638,7 @@ static void rna_ColorManagement_update(Main *UNUSED(bmain), Scene *UNUSED(scene)
return;
if (GS(id->name) == ID_SCE) {
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_SCENE | ND_SEQUENCER, NULL);
}
}
diff --git a/source/blender/makesrna/intern/rna_constraint.c b/source/blender/makesrna/intern/rna_constraint.c
index b602c90c82c..f964550e30d 100644
--- a/source/blender/makesrna/intern/rna_constraint.c
+++ b/source/blender/makesrna/intern/rna_constraint.c
@@ -100,8 +100,8 @@ const EnumPropertyItem rna_enum_constraint_type_items[] = {
"Use to animate an object/bone following a path"},
{CONSTRAINT_TYPE_PIVOT, "PIVOT", ICON_CONSTRAINT_DATA, "Pivot",
"Change pivot point for transforms (buggy)"},
- {CONSTRAINT_TYPE_RIGIDBODYJOINT, "RIGID_BODY_JOINT", ICON_CONSTRAINT_DATA, "Rigid Body Joint",
- "Use to define a Rigid Body Constraint (for Game Engine use only)"},
+ /* {CONSTRAINT_TYPE_RIGIDBODYJOINT, "RIGID_BODY_JOINT", ICON_CONSTRAINT_DATA, "Rigid Body Joint",
+ "Use to define a Rigid Body Constraint (for Game Engine use only)"}, */
/* {CONSTRAINT_TYPE_PYTHON, "SCRIPT", ICON_CONSTRAINT_DATA, "Script",
"Custom constraint(s) written in Python (Not yet implemented)"}, */
{CONSTRAINT_TYPE_SHRINKWRAP, "SHRINKWRAP", ICON_CONSTRAINT_DATA, "Shrinkwrap",
@@ -154,7 +154,6 @@ static const EnumPropertyItem space_object_items[] = {
#include "BKE_action.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#ifdef WITH_ALEMBIC
# include "ABC_alembic.h"
@@ -191,8 +190,6 @@ static StructRNA *rna_ConstraintType_refine(struct PointerRNA *ptr)
return &RNA_StretchToConstraint;
case CONSTRAINT_TYPE_MINMAX:
return &RNA_FloorConstraint;
- case CONSTRAINT_TYPE_RIGIDBODYJOINT:
- return &RNA_RigidBodyJointConstraint;
case CONSTRAINT_TYPE_CLAMPTO:
return &RNA_ClampToConstraint;
case CONSTRAINT_TYPE_TRANSFORM:
@@ -1324,178 +1321,6 @@ static void rna_def_constraint_stretch_to(BlenderRNA *brna)
RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
}
-static void rna_def_constraint_rigid_body_joint(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem pivot_items[] = {
- {CONSTRAINT_RB_BALL, "BALL", 0, "Ball", "Allow rotations around all axes"},
- {CONSTRAINT_RB_HINGE, "HINGE", 0, "Hinge", "Work in one plane, allow rotations around one axis only"},
- {CONSTRAINT_RB_CONETWIST, "CONE_TWIST", 0, "Cone Twist",
- "Allow rotations around all axes with limits for the cone and twist axes"},
- {CONSTRAINT_RB_GENERIC6DOF, "GENERIC_6_DOF", 0, "Generic 6 DoF",
- "No constraints by default, limits can be set individually"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "RigidBodyJointConstraint", "Constraint");
- RNA_def_struct_ui_text(srna, "Rigid Body Joint Constraint", "For use with the Game Engine");
- RNA_def_struct_sdna_from(srna, "bRigidBodyJointConstraint", "data");
-
- prop = RNA_def_property(srna, "target", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "tar");
- RNA_def_property_ui_text(prop, "Target", "Target Object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_dependency_update");
-
- prop = RNA_def_property(srna, "child", PROP_POINTER, PROP_NONE);
- RNA_def_property_ui_text(prop, "Child Object", "Child object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_dependency_update");
-
- prop = RNA_def_property(srna, "pivot_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, pivot_items);
- RNA_def_property_ui_text(prop, "Pivot Type", "");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "pivot_x", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "pivX");
- RNA_def_property_range(prop, -1000.0, 1000.f);
- RNA_def_property_ui_text(prop, "Pivot X", "Offset pivot on X");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "pivot_y", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "pivY");
- RNA_def_property_range(prop, -1000.0, 1000.f);
- RNA_def_property_ui_text(prop, "Pivot Y", "Offset pivot on Y");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "pivot_z", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "pivZ");
- RNA_def_property_range(prop, -1000.0, 1000.f);
- RNA_def_property_ui_text(prop, "Pivot Z", "Offset pivot on Z");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "axis_x", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "axX");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Axis X", "Rotate pivot on X axis");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "axis_y", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "axY");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Axis Y", "Rotate pivot on Y axis");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "axis_z", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "axZ");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Axis Z", "Rotate pivot on Z axis");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "use_linked_collision", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_DISABLE_LINKED_COLLISION);
- RNA_def_property_ui_text(prop, "Disable Linked Collision", "Disable collision between linked bodies");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "show_pivot", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_DRAW_PIVOT);
- RNA_def_property_ui_text(prop, "Draw Pivot", "Display the pivot point and rotation in 3D view");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
-
- /* Limits */
- /* Limit Min/Max */
- prop = RNA_def_property(srna, "limit_min_x", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "minLimit[0]");
- RNA_def_property_ui_text(prop, "Minimum Limit X", "");
-
- prop = RNA_def_property(srna, "limit_min_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "minLimit[1]");
- RNA_def_property_ui_text(prop, "Minimum Limit Y", "");
-
- prop = RNA_def_property(srna, "limit_min_z", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "minLimit[2]");
- RNA_def_property_ui_text(prop, "Minimum Limit Z", "");
-
- prop = RNA_def_property(srna, "limit_max_x", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "maxLimit[0]");
- RNA_def_property_ui_text(prop, "Maximum Limit X", "");
-
- prop = RNA_def_property(srna, "limit_max_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "maxLimit[1]");
- RNA_def_property_ui_text(prop, "Maximum Limit Y", "");
-
- prop = RNA_def_property(srna, "limit_max_z", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "maxLimit[2]");
- RNA_def_property_ui_text(prop, "Maximum Limit Z", "");
-
- /* Limit Min/Max for angle */
- prop = RNA_def_property(srna, "limit_angle_min_x", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "minLimit[3]");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Minimum Angular Limit X", "");
-
- prop = RNA_def_property(srna, "limit_angle_min_y", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "minLimit[4]");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Minimum Angular Limit Y", "");
-
- prop = RNA_def_property(srna, "limit_angle_min_z", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "minLimit[5]");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Minimum Angular Limit Z", "");
-
- prop = RNA_def_property(srna, "limit_angle_max_x", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "maxLimit[3]");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Maximum Angular Limit X", "");
-
- prop = RNA_def_property(srna, "limit_angle_max_y", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "maxLimit[4]");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Maximum Angular Limit Y", "");
-
- prop = RNA_def_property(srna, "limit_angle_max_z", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "maxLimit[5]");
- RNA_def_property_range(prop, -M_PI * 2, M_PI * 2);
- RNA_def_property_ui_text(prop, "Maximum Angular Limit Z", "");
-
- /* Limit Booleans */
- prop = RNA_def_property(srna, "use_limit_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", 1);
- RNA_def_property_ui_text(prop, "Limit X", "Use minimum/maximum X limit");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "use_limit_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", 2);
- RNA_def_property_ui_text(prop, "Limit Y", "Use minimum/maximum y limit");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "use_limit_z", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", 4);
- RNA_def_property_ui_text(prop, "Limit Z", "Use minimum/maximum z limit");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "use_angular_limit_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", 8);
- RNA_def_property_ui_text(prop, "Angular X Limit", "Use minimum/maximum X angular limit");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "use_angular_limit_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", 16);
- RNA_def_property_ui_text(prop, "Angular Y Limit", "Use minimum/maximum Y angular limit");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-
- prop = RNA_def_property(srna, "use_angular_limit_z", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", 32);
- RNA_def_property_ui_text(prop, "Angular Z Limit", "Use minimum/maximum Z angular limit");
- RNA_def_property_update(prop, NC_OBJECT | ND_CONSTRAINT, "rna_Constraint_update");
-}
-
static void rna_def_constraint_clamp_to(BlenderRNA *brna)
{
StructRNA *srna;
@@ -2536,10 +2361,12 @@ void RNA_def_constraint(BlenderRNA *brna)
/* flags */
prop = RNA_def_property(srna, "mute", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_OFF);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Disable", "Enable/Disable Constraint");
prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", CONSTRAINT_EXPAND);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Expanded", "Constraint's panel is expanded in UI");
RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
@@ -2596,7 +2423,6 @@ void RNA_def_constraint(BlenderRNA *brna)
rna_def_constraint_minmax(brna);
rna_def_constraint_track_to(brna);
rna_def_constraint_kinematic(brna);
- rna_def_constraint_rigid_body_joint(brna);
rna_def_constraint_clamp_to(brna);
rna_def_constraint_distance_limit(brna);
rna_def_constraint_size_limit(brna);
diff --git a/source/blender/makesrna/intern/rna_context.c b/source/blender/makesrna/intern/rna_context.c
index 4bbf31d6500..fd128548ed1 100644
--- a/source/blender/makesrna/intern/rna_context.c
+++ b/source/blender/makesrna/intern/rna_context.c
@@ -39,6 +39,8 @@
#ifdef RNA_RUNTIME
+#include "RE_engine.h"
+
static PointerRNA rna_Context_manager_get(PointerRNA *ptr)
{
bContext *C = (bContext *)ptr->data;
@@ -51,6 +53,12 @@ static PointerRNA rna_Context_window_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_Window, CTX_wm_window(C));
}
+static PointerRNA rna_Context_workspace_get(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_WorkSpace, CTX_wm_workspace(C));
+}
+
static PointerRNA rna_Context_screen_get(PointerRNA *ptr)
{
bContext *C = (bContext *)ptr->data;
@@ -95,18 +103,70 @@ static PointerRNA rna_Context_region_data_get(PointerRNA *ptr)
return PointerRNA_NULL;
}
+static PointerRNA rna_Context_manipulator_group_get(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ PointerRNA newptr;
+ RNA_pointer_create(NULL, &RNA_ManipulatorGroup, CTX_wm_manipulator_group(C), &newptr);
+ return newptr;
+}
+
static PointerRNA rna_Context_main_get(PointerRNA *ptr)
{
bContext *C = (bContext *)ptr->data;
return rna_pointer_inherit_refine(ptr, &RNA_BlendData, CTX_data_main(C));
}
+static PointerRNA rna_Context_depsgraph_get(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_Depsgraph, CTX_data_depsgraph(C));
+}
+
static PointerRNA rna_Context_scene_get(PointerRNA *ptr)
{
bContext *C = (bContext *)ptr->data;
return rna_pointer_inherit_refine(ptr, &RNA_Scene, CTX_data_scene(C));
}
+static PointerRNA rna_Context_view_layer_get(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ Scene *scene = CTX_data_scene(C);
+ PointerRNA scene_ptr;
+
+ RNA_id_pointer_create(&scene->id, &scene_ptr);
+ return rna_pointer_inherit_refine(&scene_ptr, &RNA_ViewLayer, CTX_data_view_layer(C));
+}
+
+static void rna_Context_engine_get(PointerRNA *ptr, char *value)
+ {
+ bContext *C = (bContext *)ptr->data;
+ RenderEngineType *engine_type = CTX_data_engine_type(C);
+ strcpy(value, engine_type->idname);
+}
+
+static int rna_Context_engine_length(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ RenderEngineType *engine_type = CTX_data_engine_type(C);
+ return strlen(engine_type->idname);
+}
+
+static PointerRNA rna_Context_scene_collection_get(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ ptr->id.data = CTX_data_scene(C);
+ return rna_pointer_inherit_refine(ptr, &RNA_SceneCollection, CTX_data_scene_collection(C));
+}
+
+static PointerRNA rna_Context_layer_collection_get(PointerRNA *ptr)
+{
+ bContext *C = (bContext *)ptr->data;
+ ptr->id.data = CTX_data_scene(C);
+ return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, CTX_data_layer_collection(C));
+}
+
static PointerRNA rna_Context_tool_settings_get(PointerRNA *ptr)
{
bContext *C = (bContext *)ptr->data;
@@ -167,6 +227,11 @@ void RNA_def_context(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "Window");
RNA_def_property_pointer_funcs(prop, "rna_Context_window_get", NULL, NULL, NULL);
+ prop = RNA_def_property(srna, "workspace", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "WorkSpace");
+ RNA_def_property_pointer_funcs(prop, "rna_Context_workspace_get", NULL, NULL, NULL);
+
prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_struct_type(prop, "Screen");
@@ -192,17 +257,46 @@ void RNA_def_context(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "RegionView3D");
RNA_def_property_pointer_funcs(prop, "rna_Context_region_data_get", NULL, NULL, NULL);
+ prop = RNA_def_property(srna, "manipulator_group", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "ManipulatorGroup");
+ RNA_def_property_pointer_funcs(prop, "rna_Context_manipulator_group_get", NULL, NULL, NULL);
+
/* Data */
prop = RNA_def_property(srna, "blend_data", PROP_POINTER, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_struct_type(prop, "BlendData");
RNA_def_property_pointer_funcs(prop, "rna_Context_main_get", NULL, NULL, NULL);
+ prop = RNA_def_property(srna, "depsgraph", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "Depsgraph");
+ RNA_def_property_pointer_funcs(prop, "rna_Context_depsgraph_get", NULL, NULL, NULL);
+
prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_struct_type(prop, "Scene");
RNA_def_property_pointer_funcs(prop, "rna_Context_scene_get", NULL, NULL, NULL);
+ prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "ViewLayer");
+ RNA_def_property_pointer_funcs(prop, "rna_Context_view_layer_get", NULL, NULL, NULL);
+
+ prop = RNA_def_property(srna, "engine", PROP_STRING, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_string_funcs(prop, "rna_Context_engine_get", "rna_Context_engine_length", NULL);
+
+ prop = RNA_def_property(srna, "scene_collection", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "SceneCollection");
+ RNA_def_property_pointer_funcs(prop, "rna_Context_scene_collection_get", NULL, NULL, NULL);
+
+ prop = RNA_def_property(srna, "layer_collection", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "LayerCollection");
+ RNA_def_property_pointer_funcs(prop, "rna_Context_layer_collection_get", NULL, NULL, NULL);
+
prop = RNA_def_property(srna, "tool_settings", PROP_POINTER, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_struct_type(prop, "ToolSettings");
diff --git a/source/blender/makesrna/intern/rna_controller.c b/source/blender/makesrna/intern/rna_controller.c
deleted file mode 100644
index bdb3daedebb..00000000000
--- a/source/blender/makesrna/intern/rna_controller.c
+++ /dev/null
@@ -1,327 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Blender Foundation (2008).
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/makesrna/intern/rna_controller.c
- * \ingroup RNA
- */
-
-#include <stdlib.h>
-
-#include "DNA_object_types.h"
-#include "DNA_controller_types.h"
-
-#include "BLI_string_utils.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "RNA_define.h"
-#include "RNA_enum_types.h"
-
-#include "rna_internal.h"
-
-#include "WM_types.h"
-
-const EnumPropertyItem rna_enum_controller_type_items[] = {
- {CONT_LOGIC_AND, "LOGIC_AND", 0, "And", "Logic And"},
- {CONT_LOGIC_OR, "LOGIC_OR", 0, "Or", "Logic Or"},
- {CONT_LOGIC_NAND, "LOGIC_NAND", 0, "Nand", "Logic Nand"},
- {CONT_LOGIC_NOR, "LOGIC_NOR", 0, "Nor", "Logic Nor"},
- {CONT_LOGIC_XOR, "LOGIC_XOR", 0, "Xor", "Logic Xor"},
- {CONT_LOGIC_XNOR, "LOGIC_XNOR", 0, "Xnor", "Logic Xnor"},
- {CONT_EXPRESSION, "EXPRESSION", 0, "Expression", ""},
- {CONT_PYTHON, "PYTHON", 0, "Python", ""},
- {0, NULL, 0, NULL, NULL}
-};
-
-#ifdef RNA_RUNTIME
-
-#include "BKE_sca.h"
-#include "DNA_actuator_types.h"
-
-static StructRNA *rna_Controller_refine(struct PointerRNA *ptr)
-{
- bController *controller = (bController *)ptr->data;
-
- switch (controller->type) {
- case CONT_LOGIC_AND:
- return &RNA_AndController;
- case CONT_LOGIC_OR:
- return &RNA_OrController;
- case CONT_LOGIC_NAND:
- return &RNA_NandController;
- case CONT_LOGIC_NOR:
- return &RNA_NorController;
- case CONT_LOGIC_XOR:
- return &RNA_XorController;
- case CONT_LOGIC_XNOR:
- return &RNA_XnorController;
- case CONT_EXPRESSION:
- return &RNA_ExpressionController;
- case CONT_PYTHON:
- return &RNA_PythonController;
- default:
- return &RNA_Controller;
- }
-}
-
-static void rna_Constroller_name_set(PointerRNA *ptr, const char *value)
-{
- Object *ob = ptr->id.data;
- bController *cont = ptr->data;
- BLI_strncpy_utf8(cont->name, value, sizeof(cont->name));
- BLI_uniquename(&ob->controllers, cont, DATA_("Controller"), '.', offsetof(bController, name), sizeof(cont->name));
-}
-
-static void rna_Controller_type_set(struct PointerRNA *ptr, int value)
-{
- bController *cont = (bController *)ptr->data;
-
- if (value != cont->type) {
- cont->type = value;
- init_controller(cont);
- }
-}
-
-static void rna_Controller_mode_set(struct PointerRNA *ptr, int value)
-{
- bController *cont = (bController *)ptr->data;
- bPythonCont *pycon = (bPythonCont *)cont->data;
-
- /* if mode changed and previous mode were Script */
- if (value != pycon->mode && pycon->mode == CONT_PY_SCRIPT) {
- /* clear script to avoid it to get linked with the controller */
- pycon->text = NULL;
- }
- pycon->mode = value;
-}
-
-static int rna_Controller_state_number_get(struct PointerRNA *ptr)
-{
- bController *cont = (bController *)ptr->data;
- int bit;
-
- for (bit = 0; bit < 32; bit++) {
- if (cont->state_mask & (1u << bit))
- return bit + 1;
- }
- return 0;
-}
-
-static void rna_Controller_state_number_set(struct PointerRNA *ptr, const int value)
-{
- bController *cont = (bController *)ptr->data;
- if (value < 1 || value > OB_MAX_STATES)
- return;
-
- cont->state_mask = (1 << (value - 1));
-}
-
-static void rna_Controller_actuators_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
-{
- bController *cont = (bController *)ptr->data;
- rna_iterator_array_begin(iter, cont->links, sizeof(bActuator *), (int)cont->totlinks, 0, NULL);
-}
-
-static int rna_Controller_actuators_length(PointerRNA *ptr)
-{
- bController *cont = (bController *)ptr->data;
- return (int) cont->totlinks;
-}
-
-#if 0 /* editable is set to false, comment for now. */
-static void rna_Controller_state_get(PointerRNA *ptr, int *values)
-{
- bController *cont = (bController *)ptr->data;
- int i;
-
- memset(values, 0, sizeof(int) * OB_MAX_STATES);
- for (i = 0; i < OB_MAX_STATES; i++)
- values[i] = (cont->state_mask & (1 << i));
-}
-
-static void rna_Controller_state_set(PointerRNA *ptr, const int *values)
-{
- bController *cont = (bController *)ptr->data;
- int i, tot = 0;
-
- /* ensure we always have some state selected */
- for (i = 0; i < OB_MAX_STATES; i++)
- if (values[i])
- tot++;
-
- if (tot == 0)
- return;
-
- /* only works for one state at once */
- if (tot > 1)
- return;
-
- for (i = 0; i < OB_MAX_STATES; i++) {
- if (values[i]) cont->state_mask |= (1 << i);
- else cont->state_mask &= ~(1 << i);
- }
-}
-#endif
-
-#else
-
-void RNA_def_controller(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem python_controller_modes[] = {
- {CONT_PY_SCRIPT, "SCRIPT", 0, "Script", ""},
- {CONT_PY_MODULE, "MODULE", 0, "Module", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- /* Controller */
- srna = RNA_def_struct(brna, "Controller", NULL);
- RNA_def_struct_sdna(srna, "bController");
- RNA_def_struct_refine_func(srna, "rna_Controller_refine");
- RNA_def_struct_ui_text(srna, "Controller",
- "Game engine logic brick to process events, connecting sensors to actuators");
-
- RNA_api_controller(srna);
-
- prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Name", "");
- RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Constroller_name_set");
- RNA_def_struct_name_property(srna, prop);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_enum_funcs(prop, NULL, "rna_Controller_type_set", NULL);
- RNA_def_property_enum_items(prop, rna_enum_controller_type_items);
- RNA_def_property_ui_text(prop, "Type", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", CONT_SHOW);
- RNA_def_property_ui_text(prop, "Expanded", "Set controller expanded in the user interface");
- RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", CONT_DEACTIVATE);
- RNA_def_property_ui_text(prop, "Active", "Set the active state of the controller");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_priority", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", CONT_PRIO);
- RNA_def_property_ui_text(prop, "Priority",
- "Mark controller for execution before all non-marked controllers "
- "(good for startup scripts)");
- RNA_def_property_ui_icon(prop, ICON_BOOKMARKS, 1);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "actuators", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
- RNA_def_property_struct_type(prop, "Actuator");
- RNA_def_property_ui_text(prop, "Actuators", "The list containing the actuators connected to the controller");
- RNA_def_property_collection_funcs(prop, "rna_Controller_actuators_begin", "rna_iterator_array_next",
- "rna_iterator_array_end", "rna_iterator_array_dereference_get",
- "rna_Controller_actuators_length", NULL, NULL, NULL);
-
- /* State */
-
- /* array of OB_MAX_STATES */
- /*prop = RNA_def_property(srna, "states", PROP_BOOLEAN, PROP_LAYER_MEMBER); */
- /*RNA_def_property_array(prop, OB_MAX_STATES); */
- /*RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
- /*RNA_def_property_ui_text(prop, "", "Set Controller state index (1 to 30)"); */
- /*RNA_def_property_boolean_funcs(prop, "rna_Controller_state_get", "rna_Controller_state_set"); */
- /*RNA_def_property_update(prop, NC_LOGIC, NULL); */
-
- /* number of the state */
- prop = RNA_def_property(srna, "states", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "state_mask");
- RNA_def_property_range(prop, 1, OB_MAX_STATES);
- RNA_def_property_ui_text(prop, "", "Set Controller state index (1 to 30)");
- RNA_def_property_int_funcs(prop, "rna_Controller_state_number_get", "rna_Controller_state_number_set", NULL);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Expression Controller */
- srna = RNA_def_struct(brna, "ExpressionController", "Controller");
- RNA_def_struct_sdna_from(srna, "bExpressionCont", "data");
- RNA_def_struct_ui_text(srna, "Expression Controller",
- "Controller passing on events based on the evaluation of an expression");
-
- prop = RNA_def_property(srna, "expression", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "str");
- RNA_def_property_ui_text(prop, "Expression", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Python Controller */
- srna = RNA_def_struct(brna, "PythonController", "Controller");
- RNA_def_struct_sdna_from(srna, "bPythonCont", "data");
- RNA_def_struct_ui_text(srna, "Python Controller", "Controller executing a python script");
-
- prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, python_controller_modes);
- RNA_def_property_enum_funcs(prop, NULL, "rna_Controller_mode_set", NULL);
- RNA_def_property_ui_text(prop, "Execution Method", "Python script type (textblock or module - faster)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "text", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Text");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Text", "Text data-block with the python script");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "module", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Module",
- "Module name and function to run, e.g. \"someModule.main\" "
- "(internal texts and external python files can be used)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_debug", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", CONT_PY_DEBUG);
- RNA_def_property_ui_text(prop, "D",
- "Continuously reload the module from disk for editing external modules "
- "without restarting");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Other Controllers */
- srna = RNA_def_struct(brna, "AndController", "Controller");
- RNA_def_struct_ui_text(srna, "And Controller", "Controller passing on events based on a logical AND operation");
-
- srna = RNA_def_struct(brna, "OrController", "Controller");
- RNA_def_struct_ui_text(srna, "Or Controller", "Controller passing on events based on a logical OR operation");
-
- srna = RNA_def_struct(brna, "NorController", "Controller");
- RNA_def_struct_ui_text(srna, "Nor Controller", "Controller passing on events based on a logical NOR operation");
-
- srna = RNA_def_struct(brna, "NandController", "Controller");
- RNA_def_struct_ui_text(srna, "Nand Controller", "Controller passing on events based on a logical NAND operation");
-
- srna = RNA_def_struct(brna, "XorController", "Controller");
- RNA_def_struct_ui_text(srna, "Xor Controller", "Controller passing on events based on a logical XOR operation");
-
- srna = RNA_def_struct(brna, "XnorController", "Controller");
- RNA_def_struct_ui_text(srna, "Xnor Controller", "Controller passing on events based on a logical XNOR operation");
-}
-
-#endif
diff --git a/source/blender/makesrna/intern/rna_controller_api.c b/source/blender/makesrna/intern/rna_controller_api.c
deleted file mode 100644
index 639d6a330a5..00000000000
--- a/source/blender/makesrna/intern/rna_controller_api.c
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2010 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/makesrna/intern/rna_controller_api.c
- * \ingroup RNA
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "WM_types.h"
-#include "RNA_define.h"
-
-#include "rna_internal.h" /* own include */
-
-#ifdef RNA_RUNTIME
-
-#include "BKE_sca.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
-
-static void rna_Controller_link(bController *cont, bSensor *sens, bActuator *act)
-{
- if (sens)
- link_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks, sizeof(bController *));
- if (act)
- link_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks, sizeof(bActuator *));
-}
-
-static void rna_Controller_unlink(bController *cont, bSensor *sens, bActuator *act)
-{
- if (sens)
- unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
- if (act)
- unlink_logicbricks((void **)&act, (void ***)&(cont->links), &cont->totlinks);
-}
-
-#else
-
-void RNA_api_controller(StructRNA *srna)
-{
- FunctionRNA *func;
- PropertyRNA *parm;
-
- func = RNA_def_function(srna, "link", "rna_Controller_link");
- RNA_def_function_ui_description(func, "Link the controller with a sensor/actuator");
- parm = RNA_def_pointer(func, "sensor", "Sensor", "", "Sensor to link the controller to");
- RNA_def_property_update(parm, NC_LOGIC, NULL);
- parm = RNA_def_pointer(func, "actuator", "Actuator", "", "Actuator to link the controller to");
- RNA_def_property_update(parm, NC_LOGIC, NULL);
-
- func = RNA_def_function(srna, "unlink", "rna_Controller_unlink");
- RNA_def_function_ui_description(func, "Unlink the controller from a sensor/actuator");
- parm = RNA_def_pointer(func, "sensor", "Sensor", "", "Sensor to unlink the controller from");
- RNA_def_property_update(parm, NC_LOGIC, NULL);
- parm = RNA_def_pointer(func, "actuator", "Actuator", "", "Actuator to unlink the controller from");
- RNA_def_property_update(parm, NC_LOGIC, NULL);
-}
-
-#endif
-
diff --git a/source/blender/makesrna/intern/rna_curve.c b/source/blender/makesrna/intern/rna_curve.c
index 45b312a742d..894af338c12 100644
--- a/source/blender/makesrna/intern/rna_curve.c
+++ b/source/blender/makesrna/intern/rna_curve.c
@@ -124,9 +124,11 @@ static const EnumPropertyItem curve2d_fill_mode_items[] = {
#include "DNA_object_types.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "WM_api.h"
#include "MEM_guardedalloc.h"
@@ -338,7 +340,7 @@ static void rna_BPoint_array_begin(CollectionPropertyIterator *iter, PointerRNA
static void rna_Curve_update_data_id(Main *UNUSED(bmain), Scene *UNUSED(scene), ID *id)
{
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
}
@@ -349,7 +351,7 @@ static void rna_Curve_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
static void rna_Curve_update_deps(Main *bmain, Scene *scene, PointerRNA *ptr)
{
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
rna_Curve_update_data(bmain, scene, ptr);
}
@@ -638,7 +640,7 @@ static void rna_Curve_spline_remove(Curve *cu, ReportList *reports, PointerRNA *
BKE_nurb_free(nu);
RNA_POINTER_INVALIDATE(nu_ptr);
- DAG_id_tag_update(&cu->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&cu->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_GEOM | ND_DATA, NULL);
}
@@ -648,7 +650,7 @@ static void rna_Curve_spline_clear(Curve *cu)
BKE_nurbList_free(nurbs);
- DAG_id_tag_update(&cu->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&cu->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_GEOM | ND_DATA, NULL);
}
diff --git a/source/blender/makesrna/intern/rna_curve_api.c b/source/blender/makesrna/intern/rna_curve_api.c
index be6808567bb..b518b0cb5b0 100644
--- a/source/blender/makesrna/intern/rna_curve_api.c
+++ b/source/blender/makesrna/intern/rna_curve_api.c
@@ -47,8 +47,14 @@ static void rna_Curve_transform(Curve *cu, float *mat, int shape_keys)
{
BKE_curve_transform(cu, (float (*)[4])mat, shape_keys, true);
- DAG_id_tag_update(&cu->id, 0);
+ DEG_id_tag_update(&cu->id, 0);
}
+
+static void rna_Curve_update_gpu_tag(Curve *cu)
+{
+ BKE_curve_batch_cache_dirty(cu, BKE_CURVE_BATCH_DIRTY_ALL);
+}
+
#else
void RNA_api_curve(StructRNA *srna)
@@ -67,6 +73,8 @@ void RNA_api_curve(StructRNA *srna)
"has had invalid indices corrected (to default 0)");
parm = RNA_def_boolean(func, "result", 0, "Result", "");
RNA_def_function_return(func, parm);
+
+ RNA_def_function(srna, "update_gpu_tag", "rna_Curve_update_gpu_tag");
}
#endif
diff --git a/source/blender/makesrna/intern/rna_define.c b/source/blender/makesrna/intern/rna_define.c
index c8a6a503fd9..03e58f8f78e 100644
--- a/source/blender/makesrna/intern/rna_define.c
+++ b/source/blender/makesrna/intern/rna_define.c
@@ -1270,6 +1270,14 @@ PropertyRNA *RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier
#endif
}
+ /* Override handling. */
+ if (DefRNA.preprocess) {
+ prop->override_diff = (RNAPropOverrideDiff)"rna_property_override_diff_default";
+ prop->override_store = (RNAPropOverrideStore)"rna_property_override_store_default";
+ prop->override_apply = (RNAPropOverrideApply)"rna_property_override_apply_default";
+ }
+ /* TODO: do we want that for runtime-defined stuff too? I’d say no, but... maybe yes :/ */
+
rna_addtail(&cont->properties, prop);
return prop;
@@ -2222,6 +2230,29 @@ void RNA_def_property_editable_array_func(PropertyRNA *prop, const char *editabl
if (editable) prop->itemeditable = (ItemEditableFunc)editable;
}
+/**
+ * Set custom callbacks for override operations handling.
+ *
+ * \note \a diff callback will also be used by RNA comparison/equality functions.
+ */
+void RNA_def_property_override_funcs(PropertyRNA *prop, const char *diff, const char *store, const char *apply)
+{
+ if (!DefRNA.preprocess) {
+ fprintf(stderr, "%s: only during preprocessing.\n", __func__);
+ return;
+ }
+
+ if (diff) {
+ prop->override_diff = (RNAPropOverrideDiff)diff;
+ }
+ if (store) {
+ prop->override_store = (RNAPropOverrideStore)store;
+ }
+ if (apply) {
+ prop->override_apply = (RNAPropOverrideApply)apply;
+ }
+}
+
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
{
if (!DefRNA.preprocess) {
diff --git a/source/blender/makesrna/intern/rna_depsgraph.c b/source/blender/makesrna/intern/rna_depsgraph.c
index c6b18d8d387..f3c8da39db0 100644
--- a/source/blender/makesrna/intern/rna_depsgraph.c
+++ b/source/blender/makesrna/intern/rna_depsgraph.c
@@ -34,16 +34,99 @@
#include "rna_internal.h"
-#include "DEG_depsgraph.h"
+#include "DNA_object_types.h"
-#include "BKE_depsgraph.h"
+#include "DEG_depsgraph.h"
#define STATS_MAX_SIZE 16384
#ifdef RNA_RUNTIME
+#include "BLI_iterator.h"
+
#include "DEG_depsgraph_build.h"
#include "DEG_depsgraph_debug.h"
+#include "DEG_depsgraph_query.h"
+
+#include "MEM_guardedalloc.h"
+
+/* **************** Depsgraph **************** */
+
+static PointerRNA rna_DepsgraphIter_object_get(PointerRNA *ptr)
+{
+ BLI_Iterator *iterator = ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_Object, iterator->current);
+}
+
+static PointerRNA rna_DepsgraphIter_instance_object_get(PointerRNA *ptr)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ Object *instance_object = NULL;
+ if (deg_iter->dupli_object_current != NULL) {
+ instance_object = deg_iter->dupli_object_current->ob;
+ }
+ return rna_pointer_inherit_refine(ptr, &RNA_Object, instance_object);
+}
+
+static PointerRNA rna_DepsgraphIter_parent_get(PointerRNA *ptr)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ Object *dupli_parent = NULL;
+ if (deg_iter->dupli_object_current != NULL) {
+ dupli_parent = deg_iter->dupli_parent;
+ }
+ return rna_pointer_inherit_refine(ptr, &RNA_Object, dupli_parent);
+}
+
+static PointerRNA rna_DepsgraphIter_particle_system_get(PointerRNA *ptr)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_ParticleSystem,
+ deg_iter->dupli_object_current->particle_system);
+}
+
+static void rna_DepsgraphIter_persistent_id_get(PointerRNA *ptr, int *persistent_id)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ memcpy(persistent_id, deg_iter->dupli_object_current->persistent_id,
+ sizeof(deg_iter->dupli_object_current->persistent_id));
+}
+
+static void rna_DepsgraphIter_orco_get(PointerRNA *ptr, float *orco)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ memcpy(orco, deg_iter->dupli_object_current->orco,
+ sizeof(deg_iter->dupli_object_current->orco));
+}
+
+static unsigned int rna_DepsgraphIter_random_id_get(PointerRNA *ptr)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ return deg_iter->dupli_object_current->random_id;
+}
+
+static void rna_DepsgraphIter_uv_get(PointerRNA *ptr, float *uv)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ memcpy(uv, deg_iter->dupli_object_current->uv,
+ sizeof(deg_iter->dupli_object_current->uv));
+}
+
+static int rna_DepsgraphIter_is_instance_get(PointerRNA *ptr)
+{
+ BLI_Iterator *iterator = ptr->data;
+ DEGObjectIterData *deg_iter = (DEGObjectIterData *)iterator->data;
+ return (deg_iter->dupli_object_current != NULL);
+}
+
+/* **************** Depsgraph **************** */
static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *depsgraph,
const char *filename)
@@ -79,20 +162,200 @@ static void rna_Depsgraph_debug_stats(Depsgraph *depsgraph, char *result)
DEG_stats_simple(depsgraph, &outer, &ops, &rels);
BLI_snprintf(result, STATS_MAX_SIZE,
"Approx %lu Operations, %lu Relations, %lu Outer Nodes",
- ops, rels, outer);
+ ops, rels, outer);
+}
+
+/* Iteration over objects, simple version */
+
+static void rna_Depsgraph_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
+ DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
+
+ data->graph = (Depsgraph *)ptr->data;
+ data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
+ DEG_ITER_OBJECT_FLAG_VISIBLE |
+ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET;
+ data->mode = DEG_ITER_OBJECT_MODE_RENDER;
+
+ ((BLI_Iterator *)iter->internal.custom)->valid = true;
+ DEG_iterator_objects_begin(iter->internal.custom, data);
+ iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
+}
+
+static void rna_Depsgraph_objects_next(CollectionPropertyIterator *iter)
+{
+ DEG_iterator_objects_next(iter->internal.custom);
+ iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
+}
+
+static void rna_Depsgraph_objects_end(CollectionPropertyIterator *iter)
+{
+ DEG_iterator_objects_end(iter->internal.custom);
+ MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
+ MEM_freeN(iter->internal.custom);
+}
+
+static PointerRNA rna_Depsgraph_objects_get(CollectionPropertyIterator *iter)
+{
+ Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
+}
+
+/* Iteration over objects, extended version
+ *
+ * Contains extra information about duplicator and persistent ID.
+ */
+
+static void rna_Depsgraph_duplis_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
+ DEGObjectIterData *data = MEM_callocN(sizeof(DEGObjectIterData), __func__);
+
+ data->graph = (Depsgraph *)ptr->data;
+ data->flag = DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
+ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
+ DEG_ITER_OBJECT_FLAG_VISIBLE |
+ DEG_ITER_OBJECT_FLAG_DUPLI;
+ data->mode = DEG_ITER_OBJECT_MODE_RENDER;
+
+ ((BLI_Iterator *)iter->internal.custom)->valid = true;
+ DEG_iterator_objects_begin(iter->internal.custom, data);
+ iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
+}
+
+static void rna_Depsgraph_duplis_next(CollectionPropertyIterator *iter)
+{
+ DEG_iterator_objects_next(iter->internal.custom);
+ iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
+}
+
+static void rna_Depsgraph_duplis_end(CollectionPropertyIterator *iter)
+{
+ DEG_iterator_objects_end(iter->internal.custom);
+ MEM_freeN(((BLI_Iterator *)iter->internal.custom)->data);
+ MEM_freeN(iter->internal.custom);
+}
+
+static PointerRNA rna_Depsgraph_duplis_get(CollectionPropertyIterator *iter)
+{
+ BLI_Iterator *iterator = (BLI_Iterator *)iter->internal.custom;
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_DepsgraphIter, iterator);
+}
+
+static ID *rna_Depsgraph_id_eval_get(Depsgraph *depsgraph, ID *id_orig)
+{
+ return DEG_get_evaluated_id(depsgraph, id_orig);
+}
+
+static PointerRNA rna_Depsgraph_scene_get(PointerRNA *ptr)
+{
+ Depsgraph *depsgraph = (Depsgraph *)ptr->data;
+ Scene *scene = DEG_get_input_scene(depsgraph);
+ return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene);
+}
+
+static PointerRNA rna_Depsgraph_view_layer_get(PointerRNA *ptr)
+{
+ Depsgraph *depsgraph = (Depsgraph *)ptr->data;
+ ViewLayer *view_layer = DEG_get_input_view_layer(depsgraph);
+ return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer);
+}
+
+static PointerRNA rna_Depsgraph_scene_eval_get(PointerRNA *ptr)
+{
+ Depsgraph *depsgraph = (Depsgraph *)ptr->data;
+ Scene *scene_eval = DEG_get_evaluated_scene(depsgraph);
+ return rna_pointer_inherit_refine(ptr, &RNA_Scene, scene_eval);
+}
+
+static PointerRNA rna_Depsgraph_view_layer_eval_get(PointerRNA *ptr)
+{
+ Depsgraph *depsgraph = (Depsgraph *)ptr->data;
+ ViewLayer *view_layer_eval = DEG_get_evaluated_view_layer(depsgraph);
+ return rna_pointer_inherit_refine(ptr, &RNA_ViewLayer, view_layer_eval);
}
#else
+static void rna_def_depsgraph_iter(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "DepsgraphIter", NULL);
+ RNA_def_struct_ui_text(srna, "Dependency Graph Iterator",
+ "Extended information about dependency graph object iterator");
+
+ prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_ui_text(prop, "Object", "Object the iterator points to");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_object_get", NULL, NULL, NULL);
+
+ prop = RNA_def_property(srna, "instance_object", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_ui_text(prop, "Instance Object", "Object which is being instanced by this iterator");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_instance_object_get", NULL, NULL, NULL);
+
+ prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_ui_text(prop, "Parent", "Parent of the duplication list");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_parent_get", NULL, NULL, NULL);
+
+ prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "ParticleSystem");
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Particle System", "Particle system that this object was instanced from");
+ RNA_def_property_pointer_funcs(prop, "rna_DepsgraphIter_particle_system_get", NULL, NULL, NULL);
+
+ prop = RNA_def_property(srna, "persistent_id", PROP_INT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Persistent ID",
+ "Persistent identifier for inter-frame matching of objects with motion blur");
+ RNA_def_property_array(prop, 2 * MAX_DUPLI_RECUR);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_int_funcs(prop, "rna_DepsgraphIter_persistent_id_get", NULL, NULL);
+
+ prop = RNA_def_property(srna, "orco", PROP_FLOAT, PROP_TRANSLATION);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ /* Seems system is not smart enough to figure that getter function should return
+ * array for PROP_TRANSLATION.
+ */
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Generated Coordinates", "Generated coordinates in parent object space");
+ RNA_def_property_float_funcs(prop, "rna_DepsgraphIter_orco_get", NULL, NULL);
+
+ prop = RNA_def_property(srna, "random_id", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Dupli random id", "Random id for this dupli object");
+ RNA_def_property_int_funcs(prop, "rna_DepsgraphIter_random_id_get", NULL, NULL);
+
+ prop = RNA_def_property(srna, "uv", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "UV Coordinates", "UV coordinates in parent object space");
+ RNA_def_property_array(prop, 2);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_float_funcs(prop, "rna_DepsgraphIter_uv_get", NULL, NULL);
+
+ prop = RNA_def_property(srna, "is_instance", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE | PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Is Instance", "Denotes whether the object is ocming from dupli-list");
+ RNA_def_property_boolean_funcs(prop, "rna_DepsgraphIter_is_instance_get", NULL);
+}
+
static void rna_def_depsgraph(BlenderRNA *brna)
{
StructRNA *srna;
FunctionRNA *func;
PropertyRNA *parm;
+ PropertyRNA *prop;
srna = RNA_def_struct(brna, "Depsgraph", NULL);
RNA_def_struct_ui_text(srna, "Dependency Graph", "");
+ /* Debug helpers. */
+
func = RNA_def_function(srna, "debug_relations_graphviz", "rna_Depsgraph_debug_relations_graphviz");
parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
"File in which to store graphviz debug output");
@@ -114,10 +377,66 @@ static void rna_def_depsgraph(BlenderRNA *brna)
parm = RNA_def_string(func, "result", NULL, STATS_MAX_SIZE, "result", "");
RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
RNA_def_function_output(func, parm);
+
+ /* Queries for original datablockls (the ones depsgraph is built for). */
+
+ prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Scene");
+ RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_get", NULL, NULL, NULL);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
+
+ prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "ViewLayer");
+ RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_get", NULL, NULL, NULL);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
+
+ /* Queries for evaluated datablockls (the ones depsgraph is evaluating). */
+
+ func = RNA_def_function(srna, "id_eval_get", "rna_Depsgraph_id_eval_get");
+ parm = RNA_def_pointer(func, "id", "ID", "", "Original ID to get evaluated complementary part for");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_pointer(func, "id_eval", "ID", "", "Evaluated ID for the given original one");
+ RNA_def_function_return(func, parm);
+
+ prop = RNA_def_property(srna, "scene_eval", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Scene");
+ RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_scene_eval_get", NULL, NULL, NULL);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Scene", "Original scene dependency graph is built for");
+
+ prop = RNA_def_property(srna, "view_layer_eval", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "ViewLayer");
+ RNA_def_property_pointer_funcs(prop, "rna_Depsgraph_view_layer_eval_get", NULL, NULL, NULL);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "View Layer", "Original view layer dependency graph is built for");
+
+ /* Iterators. */
+
+ prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_collection_funcs(prop,
+ "rna_Depsgraph_objects_begin",
+ "rna_Depsgraph_objects_next",
+ "rna_Depsgraph_objects_end",
+ "rna_Depsgraph_objects_get",
+ NULL, NULL, NULL, NULL);
+
+ /* TODO(sergey): Find a better name. */
+ prop = RNA_def_property(srna, "duplis", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "DepsgraphIter");
+ RNA_def_property_collection_funcs(prop,
+ "rna_Depsgraph_duplis_begin",
+ "rna_Depsgraph_duplis_next",
+ "rna_Depsgraph_duplis_end",
+ "rna_Depsgraph_duplis_get",
+ NULL, NULL, NULL, NULL);
}
void RNA_def_depsgraph(BlenderRNA *brna)
{
+ rna_def_depsgraph_iter(brna);
rna_def_depsgraph(brna);
}
diff --git a/source/blender/makesrna/intern/rna_dynamicpaint.c b/source/blender/makesrna/intern/rna_dynamicpaint.c
index 94fda7097ee..aeb845ddcf7 100644
--- a/source/blender/makesrna/intern/rna_dynamicpaint.c
+++ b/source/blender/makesrna/intern/rna_dynamicpaint.c
@@ -55,9 +55,10 @@ const EnumPropertyItem rna_enum_prop_dynamicpaint_type_items[] = {
#ifdef RNA_RUNTIME
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_particle.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
static char *rna_DynamicPaintCanvasSettings_path(PointerRNA *ptr)
{
@@ -98,7 +99,7 @@ static char *rna_DynamicPaintSurface_path(PointerRNA *ptr)
static void rna_DynamicPaint_redoModifier(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
}
static void rna_DynamicPaintSurfaces_updateFrames(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
@@ -160,7 +161,7 @@ static void rna_DynamicPaintSurfaces_changeFormat(Main *bmain, Scene *scene, Poi
static void rna_DynamicPaint_reset_dependency(Main *bmain, Scene *scene, PointerRNA *ptr)
{
rna_DynamicPaintSurface_reset(bmain, scene, ptr);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
static PointerRNA rna_PaintSurface_active_get(PointerRNA *ptr)
@@ -824,18 +825,6 @@ static void rna_def_dynamic_paint_brush_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Paint Alpha", "Paint alpha");
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_DynamicPaint_redoModifier");
- prop = RNA_def_property(srna, "use_material", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_DPAINT_USE_MATERIAL);
- RNA_def_property_ui_text(prop, "Use object material", "Use object material to define color and influence");
- RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_DynamicPaint_redoModifier");
-
- prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "mat");
- RNA_def_property_ui_text(prop, "Material",
- "Material to use (if not defined, material linked to the mesh is used)");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, "rna_DynamicPaint_redoModifier");
-
prop = RNA_def_property(srna, "use_absolute_alpha", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_DPAINT_ABS_ALPHA);
RNA_def_property_ui_text(prop, "Absolute Alpha",
diff --git a/source/blender/makesrna/intern/rna_fcurve.c b/source/blender/makesrna/intern/rna_fcurve.c
index c8ee6e15689..275a7463630 100644
--- a/source/blender/makesrna/intern/rna_fcurve.c
+++ b/source/blender/makesrna/intern/rna_fcurve.c
@@ -127,9 +127,11 @@ static StructRNA *rna_FModifierType_refine(struct PointerRNA *ptr)
/* ****************************** */
#include "BKE_fcurve.h"
-#include "BKE_depsgraph.h"
#include "BKE_animsys.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
static void rna_ChannelDriver_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
{
ID *id = ptr->id.data;
@@ -138,8 +140,8 @@ static void rna_ChannelDriver_update_data(Main *bmain, Scene *scene, PointerRNA
driver->flag &= ~DRIVER_FLAG_INVALID;
/* TODO: this really needs an update guard... */
- DAG_relations_tag_update(bmain);
- DAG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update(id, OB_RECALC_OB | OB_RECALC_DATA);
WM_main_add_notifier(NC_SCENE | ND_FRAME, scene);
}
@@ -588,7 +590,7 @@ static void rna_FModifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
ID *id = ptr->id.data;
FModifier *fcm = (FModifier *)ptr->data;
AnimData *adt = BKE_animdata_from_id(id);
- DAG_id_tag_update(id, (GS(id->name) == ID_OB) ? OB_RECALC_OB : OB_RECALC_DATA);
+ DEG_id_tag_update(id, (GS(id->name) == ID_OB) ? OB_RECALC_OB : OB_RECALC_DATA);
if (adt != NULL) {
adt->recalc |= ADT_RECALC_ANIM;
}
@@ -1471,6 +1473,7 @@ static void rna_def_drivertarget(BlenderRNA *brna)
prop = RNA_def_property(srna, "id", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "ID");
RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_editable_func(prop, "rna_DriverTarget_id_editable");
/* note: custom set function is ONLY to avoid rna setting a user for this. */
RNA_def_property_pointer_funcs(prop, NULL, "rna_DriverTarget_id_set", "rna_DriverTarget_id_typef", NULL);
diff --git a/source/blender/makesrna/intern/rna_fluidsim.c b/source/blender/makesrna/intern/rna_fluidsim.c
index c7cfde18723..a75aceb6f7e 100644
--- a/source/blender/makesrna/intern/rna_fluidsim.c
+++ b/source/blender/makesrna/intern/rna_fluidsim.c
@@ -46,7 +46,6 @@
#include "DNA_scene_types.h"
#include "DNA_particle_types.h"
-#include "BKE_depsgraph.h"
#include "BKE_fluidsim.h"
#include "BKE_global.h"
#include "BKE_main.h"
@@ -54,6 +53,8 @@
#include "BKE_particle.h"
#include "BKE_pointcache.h"
+#include "DEG_depsgraph.h"
+
static StructRNA *rna_FluidSettings_refine(struct PointerRNA *ptr)
{
FluidsimSettings *fss = (FluidsimSettings *)ptr->data;
@@ -82,7 +83,7 @@ static void rna_fluid_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerR
{
Object *ob = ptr->id.data;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
}
diff --git a/source/blender/makesrna/intern/rna_group.c b/source/blender/makesrna/intern/rna_group.c
index aa02a3c159d..bf64bb1181f 100644
--- a/source/blender/makesrna/intern/rna_group.c
+++ b/source/blender/makesrna/intern/rna_group.c
@@ -49,13 +49,14 @@ static PointerRNA rna_Group_objects_get(CollectionPropertyIterator *iter)
{
ListBaseIterator *internal = &iter->internal.listbase;
- /* we are actually iterating a GroupObject list, so override get */
- return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((GroupObject *)internal->link)->ob);
+ /* we are actually iterating a ObjectBase list, so override get */
+ Base *base = (Base *)internal->link;
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
}
-static void rna_Group_objects_link(Group *group, bContext *C, ReportList *reports, Object *object)
+static void rna_Group_objects_link(Group *group, ReportList *reports, Object *object)
{
- if (!BKE_group_object_add(group, object, CTX_data_scene(C), NULL)) {
+ if (!BKE_group_object_add(group, object)) {
BKE_reportf(reports, RPT_ERROR, "Object '%s' already in group '%s'", object->id.name + 2, group->id.name + 2);
return;
}
@@ -63,9 +64,9 @@ static void rna_Group_objects_link(Group *group, bContext *C, ReportList *report
WM_main_add_notifier(NC_OBJECT | ND_DRAW, &object->id);
}
-static void rna_Group_objects_unlink(Group *group, bContext *C, ReportList *reports, Object *object)
+static void rna_Group_objects_unlink(Group *group, ReportList *reports, Object *object)
{
- if (!BKE_group_object_unlink(group, object, CTX_data_scene(C), NULL)) {
+ if (!BKE_group_object_unlink(group, object)) {
BKE_reportf(reports, RPT_ERROR, "Object '%s' not in group '%s'", object->id.name + 2, group->id.name + 2);
return;
}
@@ -91,7 +92,7 @@ static void rna_def_group_objects(BlenderRNA *brna, PropertyRNA *cprop)
/* add object */
func = RNA_def_function(srna, "link", "rna_Group_objects_link");
- RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
RNA_def_function_ui_description(func, "Add this object to a group");
/* object to add */
parm = RNA_def_pointer(func, "object", "Object", "", "Object to add");
@@ -100,7 +101,7 @@ static void rna_def_group_objects(BlenderRNA *brna, PropertyRNA *cprop)
/* remove object */
func = RNA_def_function(srna, "unlink", "rna_Group_objects_unlink");
RNA_def_function_ui_description(func, "Remove this object to a group");
- RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
/* object to remove */
parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
@@ -124,20 +125,18 @@ void RNA_def_group(BlenderRNA *brna)
RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, RNA_TRANSLATION_PREC_DEFAULT);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
- prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER);
- RNA_def_property_boolean_sdna(prop, NULL, "layer", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Dupli Layers", "Layers visible when this group is instanced as a dupli");
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
-
prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "gobject", NULL);
+ RNA_def_property_collection_sdna(prop, NULL, "view_layer->object_bases", NULL);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_ui_text(prop, "Objects", "A collection of this groups objects");
RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_Group_objects_get", NULL, NULL, NULL, NULL);
-
rna_def_group_objects(brna, prop);
+ prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "ViewLayer");
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "View Layer", "Group internal view layer");
}
#endif
diff --git a/source/blender/makesrna/intern/rna_image.c b/source/blender/makesrna/intern/rna_image.c
index eeb6160cc57..c554ab8e0fd 100644
--- a/source/blender/makesrna/intern/rna_image.c
+++ b/source/blender/makesrna/intern/rna_image.c
@@ -33,9 +33,10 @@
#include "BLI_math_base.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_image.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -70,19 +71,6 @@ static const EnumPropertyItem image_source_items[] = {
#include "IMB_imbuf.h"
#include "IMB_imbuf_types.h"
-static void rna_Image_animated_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
-{
- Image *ima = (Image *)ptr->data;
- int nr;
-
- if (ima->flag & IMA_TWINANIM) {
- nr = ima->xrep * ima->yrep;
- if (ima->twsta >= nr) ima->twsta = 1;
- if (ima->twend >= nr) ima->twend = nr - 1;
- if (ima->twsta > ima->twend) ima->twsta = 1;
- }
-}
-
static int rna_Image_is_stereo_3d_get(PointerRNA *ptr)
{
return BKE_image_is_stereo((Image *)ptr->data);
@@ -105,7 +93,7 @@ static void rna_Image_source_set(PointerRNA *ptr, int value)
if (value != ima->source) {
ima->source = value;
BKE_image_signal(ima, NULL, IMA_SIGNAL_SRC_CHANGE);
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
}
}
@@ -135,7 +123,7 @@ static void rna_Image_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene), P
Image *ima = ptr->id.data;
BKE_image_signal(ima, NULL, IMA_SIGNAL_RELOAD);
WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
}
static void rna_Image_generated_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
@@ -148,7 +136,7 @@ static void rna_Image_colormanage_update(Main *UNUSED(bmain), Scene *UNUSED(scen
{
Image *ima = ptr->id.data;
BKE_image_signal(ima, NULL, IMA_SIGNAL_COLORMANAGE);
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
WM_main_add_notifier(NC_IMAGE | ND_DISPLAY, &ima->id);
WM_main_add_notifier(NC_IMAGE | NA_EDITED, &ima->id);
}
@@ -178,7 +166,7 @@ static void rna_ImageUser_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *
if (ptr->id.data) {
/* Update material or texture for render preview. */
- DAG_id_tag_update(ptr->id.data, 0);
+ DEG_id_tag_update(ptr->id.data, 0);
}
}
@@ -648,11 +636,6 @@ static void rna_def_image(BlenderRNA *brna)
{IMA_TYPE_COMPOSITE, "COMPOSITING", 0, "Compositing", ""},
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem prop_mapping_items[] = {
- {0, "UV", 0, "UV Coordinates", "Use UV coordinates for mapping the image"},
- {IMA_REFLECT, "REFLECTION", 0, "Reflection", "Use reflection mapping for mapping the image"},
- {0, NULL, 0, NULL, NULL}
- };
static const EnumPropertyItem prop_field_order_items[] = {
{0, "EVEN", 0, "Upper First", "Upper field first"},
{IMA_STD_FIELD, "ODD", 0, "Lower First", "Lower field first"},
@@ -669,6 +652,7 @@ static void rna_def_image(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_IMAGE_DATA);
prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_string_sdna(prop, NULL, "name");
RNA_def_property_ui_text(prop, "File Name", "Image/Movie file name");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_reload_update");
@@ -708,6 +692,7 @@ static void rna_def_image(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Packed Files", "Collection of packed images");
prop = RNA_def_property(srna, "field_order", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
RNA_def_property_enum_items(prop, prop_field_order_items);
RNA_def_property_ui_text(prop, "Field Order", "Order of video fields (select which lines are displayed first)");
@@ -715,6 +700,7 @@ static void rna_def_image(BlenderRNA *brna)
/* booleans */
prop = RNA_def_property(srna, "use_fields", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_FIELDS);
RNA_def_property_ui_text(prop, "Fields", "Use fields of the image");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_fields_update");
@@ -722,36 +708,43 @@ static void rna_def_image(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_view_as_render", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_VIEW_AS_RENDER);
RNA_def_property_ui_text(prop, "View as Render", "Apply render part of display transformation when displaying this image on the screen");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
prop = RNA_def_property(srna, "use_alpha", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", IMA_IGNORE_ALPHA);
RNA_def_property_ui_text(prop, "Use Alpha", "Use the alpha channel information from the image or make image fully opaque");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_colormanage_update");
prop = RNA_def_property(srna, "use_deinterlace", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_DEINTERLACE);
RNA_def_property_ui_text(prop, "Deinterlace", "Deinterlace movie file on load");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_reload_update");
prop = RNA_def_property(srna, "use_multiview", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_sdna(prop, NULL, "flag", IMA_USE_VIEWS);
RNA_def_property_ui_text(prop, "Use Multi-View", "Use Multiple Views (when available)");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_views_format_update");
prop = RNA_def_property(srna, "is_stereo_3d", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_funcs(prop, "rna_Image_is_stereo_3d_get", NULL);
RNA_def_property_ui_text(prop, "Stereo 3D", "Image has left and right views");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "is_multiview", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_funcs(prop, "rna_Image_is_multiview_get", NULL);
RNA_def_property_ui_text(prop, "Multiple Views", "Image has more than one view");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "is_dirty", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_boolean_funcs(prop, "rna_Image_dirty_get", NULL);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Dirty", "Image has changed and is not saved");
@@ -793,14 +786,8 @@ static void rna_def_image(BlenderRNA *brna)
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_generated_update");
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- /* realtime properties */
- prop = RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
- RNA_def_property_enum_items(prop, prop_mapping_items);
- RNA_def_property_ui_text(prop, "Mapping", "Mapping type to use for this image in the game engine");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
-
prop = RNA_def_property(srna, "display_aspect", PROP_FLOAT, PROP_XYZ);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_float_sdna(prop, NULL, "aspx");
RNA_def_property_array(prop, 2);
RNA_def_property_range(prop, 0.1f, FLT_MAX);
@@ -808,57 +795,6 @@ static void rna_def_image(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Display Aspect", "Display Aspect for this image, does not affect rendering");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
- prop = RNA_def_property(srna, "use_animation", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TWINANIM);
- RNA_def_property_ui_text(prop, "Animated", "Use as animated texture in the game engine");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_animated_update");
-
- prop = RNA_def_property(srna, "frame_start", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "twsta");
- RNA_def_property_range(prop, 0, 255);
- RNA_def_property_ui_text(prop, "Animation Start", "Start frame of an animated texture");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_animated_update");
-
- prop = RNA_def_property(srna, "frame_end", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "twend");
- RNA_def_property_range(prop, 0, 255);
- RNA_def_property_ui_text(prop, "Animation End", "End frame of an animated texture");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_animated_update");
-
- prop = RNA_def_property(srna, "fps", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "animspeed");
- RNA_def_property_range(prop, 1, 100);
- RNA_def_property_ui_text(prop, "Animation Speed", "Speed of the animation in frames per second");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
-
- prop = RNA_def_property(srna, "use_tiles", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_TILES);
- RNA_def_property_ui_text(prop, "Tiles",
- "Use of tilemode for faces (default shift-LMB to pick the tile for selected faces)");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
-
- prop = RNA_def_property(srna, "tiles_x", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "xrep");
- RNA_def_property_range(prop, 1, 16);
- RNA_def_property_ui_text(prop, "Tiles X", "Degree of repetition in the X direction");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
-
- prop = RNA_def_property(srna, "tiles_y", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "yrep");
- RNA_def_property_range(prop, 1, 16);
- RNA_def_property_ui_text(prop, "Tiles Y", "Degree of repetition in the Y direction");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
-
- prop = RNA_def_property(srna, "use_clamp_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_U);
- RNA_def_property_ui_text(prop, "Clamp X", "Disable texture repeating horizontally");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
-
- prop = RNA_def_property(srna, "use_clamp_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "tpageflag", IMA_CLAMP_V);
- RNA_def_property_ui_text(prop, "Clamp Y", "Disable texture repeating vertically");
- RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, NULL);
-
prop = RNA_def_property(srna, "bindcode", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "bindcode");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -893,6 +829,7 @@ static void rna_def_image(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_float_vector(srna, "resolution", 2, NULL, 0, 0, "Resolution", "X/Y pixels per meter", 0, 0);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_float_funcs(prop, "rna_Image_resolution_get", "rna_Image_resolution_set", NULL);
prop = RNA_def_property(srna, "frame_duration", PROP_INT, PROP_UNSIGNED);
@@ -927,12 +864,14 @@ static void rna_def_image(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Color Space Settings", "Input color space settings");
prop = RNA_def_property(srna, "alpha_mode", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_enum_items(prop, alpha_mode_items);
RNA_def_property_ui_text(prop, "Alpha Mode", "Representation of alpha information in the RGBA pixels");
RNA_def_property_update(prop, NC_IMAGE | ND_DISPLAY, "rna_Image_colormanage_update");
/* multiview */
prop = RNA_def_property(srna, "views_format", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_enum_sdna(prop, NULL, "views_format");
RNA_def_property_enum_items(prop, rna_enum_views_format_items);
RNA_def_property_ui_text(prop, "Views Format", "Mode to load image views");
diff --git a/source/blender/makesrna/intern/rna_image_api.c b/source/blender/makesrna/intern/rna_image_api.c
index 61f1edc0af5..7f0ddf04724 100644
--- a/source/blender/makesrna/intern/rna_image_api.c
+++ b/source/blender/makesrna/intern/rna_image_api.c
@@ -56,9 +56,6 @@
#include "IMB_imbuf.h"
#include "IMB_colormanagement.h"
-#include "GPU_draw.h"
-#include "GPU_debug.h"
-
#include "DNA_image_types.h"
#include "DNA_scene_types.h"
@@ -251,6 +248,8 @@ static int rna_Image_gl_load(Image *image, ReportList *reports, int frame, int f
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, (GLint)filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, (GLint)mag);
+ /* TODO(merwin): validate input (dimensions, filter, mag) before calling OpenGL
+ * instead of trusting input & testing for error after */
error = glGetError();
if (error) {
diff --git a/source/blender/makesrna/intern/rna_internal.h b/source/blender/makesrna/intern/rna_internal.h
index 2d513bd60b4..11ad39a2dd1 100644
--- a/source/blender/makesrna/intern/rna_internal.h
+++ b/source/blender/makesrna/intern/rna_internal.h
@@ -35,13 +35,19 @@
#define RNA_MAGIC ((int)~0)
+struct Depsgraph;
+struct FreestyleSettings;
struct ID;
+struct IDOverrideStatic;
+struct IDOverrideStaticProperty;
+struct IDOverrideStaticPropertyOperation;
struct IDProperty;
struct Main;
struct Mesh;
struct Object;
struct ReportList;
struct SDNA;
+struct ViewLayer;
/* Data structures used during define */
@@ -145,7 +151,6 @@ void RNA_def_depsgraph(struct BlenderRNA *brna);
void RNA_def_dynamic_paint(struct BlenderRNA *brna);
void RNA_def_fluidsim(struct BlenderRNA *brna);
void RNA_def_fcurve(struct BlenderRNA *brna);
-void RNA_def_gameproperty(struct BlenderRNA *brna);
void RNA_def_gpencil(struct BlenderRNA *brna);
void RNA_def_group(struct BlenderRNA *brna);
void RNA_def_image(struct BlenderRNA *brna);
@@ -166,10 +171,12 @@ void RNA_def_packedfile(struct BlenderRNA *brna);
void RNA_def_palette(struct BlenderRNA *brna);
void RNA_def_particle(struct BlenderRNA *brna);
void RNA_def_pose(struct BlenderRNA *brna);
+void RNA_def_lightprobe(struct BlenderRNA *brna);
void RNA_def_render(struct BlenderRNA *brna);
void RNA_def_rigidbody(struct BlenderRNA *brna);
void RNA_def_rna(struct BlenderRNA *brna);
void RNA_def_scene(struct BlenderRNA *brna);
+void RNA_def_view_layer(struct BlenderRNA *brna);
void RNA_def_screen(struct BlenderRNA *brna);
void RNA_def_sculpt_paint(struct BlenderRNA *brna);
void RNA_def_sensor(struct BlenderRNA *brna);
@@ -186,6 +193,8 @@ void RNA_def_ui(struct BlenderRNA *brna);
void RNA_def_userdef(struct BlenderRNA *brna);
void RNA_def_vfont(struct BlenderRNA *brna);
void RNA_def_wm(struct BlenderRNA *brna);
+void RNA_def_wm_manipulator(struct BlenderRNA *brna);
+void RNA_def_workspace(struct BlenderRNA *brna);
void RNA_def_world(struct BlenderRNA *brna);
void RNA_def_movieclip(struct BlenderRNA *brna);
void RNA_def_tracking(struct BlenderRNA *brna);
@@ -195,6 +204,12 @@ void RNA_def_mask(struct BlenderRNA *brna);
void rna_def_animdata_common(struct StructRNA *srna);
+bool rna_AnimaData_override_apply(
+ struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, struct PointerRNA *ptr_storage,
+ struct PropertyRNA *prop_local, struct PropertyRNA *prop_reference, struct PropertyRNA *prop_storage,
+ const int len_local, const int len_reference, const int len_storage,
+ struct IDOverrideStaticPropertyOperation *opop);
+
void rna_def_animviz_common(struct StructRNA *srna);
void rna_def_motionpath_common(struct StructRNA *srna);
@@ -205,7 +220,7 @@ void rna_def_mtex_common(struct BlenderRNA *brna, struct StructRNA *srna, const
const char *activeset, const char *activeeditable, const char *structname,
const char *structname_slots, const char *update, const char *update_index);
void rna_def_texpaint_slots(struct BlenderRNA *brna, struct StructRNA *srna);
-void rna_def_render_layer_common(struct StructRNA *srna, int scene);
+void rna_def_view_layer_common(struct StructRNA *srna, int scene);
void rna_def_actionbone_group_common(struct StructRNA *srna, int update_flag, const char *update_cb);
void rna_ActionGroup_colorset_set(struct PointerRNA *ptr, int value);
@@ -234,10 +249,33 @@ void rna_object_vcollayer_name_set(struct PointerRNA *ptr, const char *value, ch
PointerRNA rna_object_shapekey_index_get(struct ID *id, int value);
int rna_object_shapekey_index_set(struct ID *id, PointerRNA value, int current);
+/* ViewLayer related functions defined in rna_scene.c but required in rna_layer.c */
+void rna_def_freestyle_settings(struct BlenderRNA *brna);
+struct PointerRNA rna_FreestyleLineSet_linestyle_get(struct PointerRNA *ptr);
+void rna_FreestyleLineSet_linestyle_set(struct PointerRNA *ptr, struct PointerRNA value);
+struct FreestyleLineSet *rna_FreestyleSettings_lineset_add(
+ struct ID *id, struct FreestyleSettings *config, struct Main *bmain, const char *name);
+void rna_FreestyleSettings_lineset_remove(
+ struct ID *id, struct FreestyleSettings *config, struct ReportList *reports, struct PointerRNA *lineset_ptr);
+struct PointerRNA rna_FreestyleSettings_active_lineset_get(struct PointerRNA *ptr);
+void rna_FreestyleSettings_active_lineset_index_range(
+ struct PointerRNA *ptr, int *min, int *max, int *softmin, int *softmax);
+int rna_FreestyleSettings_active_lineset_index_get(struct PointerRNA *ptr);
+void rna_FreestyleSettings_active_lineset_index_set(struct PointerRNA *ptr, int value);
+struct FreestyleModuleConfig *rna_FreestyleSettings_module_add(struct ID *id, struct FreestyleSettings *config);
+void rna_FreestyleSettings_module_remove(
+ struct ID *id, struct FreestyleSettings *config, struct ReportList *reports, struct PointerRNA *module_ptr);
+
+void rna_Scene_use_view_map_cache_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
+void rna_Scene_glsl_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
+void rna_Scene_freestyle_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
+void rna_ViewLayer_name_set(struct PointerRNA *ptr, const char *value);
+void rna_ViewLayer_pass_update(struct Main *bmain, struct Scene *activescene, struct PointerRNA *ptr);
+
/* named internal so as not to conflict with obj.update() rna func */
void rna_Object_internal_update_data(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
void rna_Mesh_update_draw(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
-void rna_TextureSlot_update(struct Main *bmain, struct Scene *scene, struct PointerRNA *ptr);
+void rna_TextureSlot_update(struct bContext *C, struct PointerRNA *ptr);
/* basic poll functions for object types */
int rna_Armature_object_poll(struct PointerRNA *ptr, struct PointerRNA value);
@@ -268,6 +306,8 @@ void RNA_api_image(struct StructRNA *srna);
void RNA_api_lattice(struct StructRNA *srna);
void RNA_api_operator(struct StructRNA *srna);
void RNA_api_macro(struct StructRNA *srna);
+void RNA_api_manipulator(struct StructRNA *srna);
+void RNA_api_manipulatorgroup(struct StructRNA *srna);
void RNA_api_keyconfig(struct StructRNA *srna);
void RNA_api_keyconfigs(struct StructRNA *srna);
void RNA_api_keyingset(struct StructRNA *srna);
@@ -280,7 +320,7 @@ void RNA_api_material(StructRNA *srna);
void RNA_api_mesh(struct StructRNA *srna);
void RNA_api_meta(struct StructRNA *srna);
void RNA_api_object(struct StructRNA *srna);
-void RNA_api_object_base(struct StructRNA *srna);
+void RNA_api_object_base_legacy(struct StructRNA *srna);
void RNA_api_pose(struct StructRNA *srna);
void RNA_api_pose_channel(struct StructRNA *srna);
void RNA_api_scene(struct StructRNA *srna);
@@ -336,6 +376,8 @@ void RNA_def_main_masks(BlenderRNA *brna, PropertyRNA *cprop);
void RNA_def_main_linestyles(BlenderRNA *brna, PropertyRNA *cprop);
void RNA_def_main_cachefiles(BlenderRNA *brna, PropertyRNA *cprop);
void RNA_def_main_paintcurves(BlenderRNA *brna, PropertyRNA *cprop);
+void RNA_def_main_workspaces(BlenderRNA *brna, PropertyRNA *cprop);
+void RNA_def_main_lightprobes(BlenderRNA *brna, PropertyRNA *cprop);
/* ID Properties */
@@ -357,6 +399,34 @@ extern StructRNA RNA_PropertyGroup;
#endif
struct IDProperty *rna_idproperty_check(struct PropertyRNA **prop, struct PointerRNA *ptr);
+struct PropertyRNA *rna_ensure_property_realdata(struct PropertyRNA **prop, struct PointerRNA *ptr);
+
+/* Override default callbacks. */
+/* Default override callbacks for all types. */
+/* TODO: Maybe at some point we'll want to write that in direct RNA-generated code instead
+ * (like we do for default get/set/etc.)?
+ * Not obvious though, those are fairly more complicated than basic SDNA access.
+ */
+int rna_property_override_diff_default(
+ struct PointerRNA *ptr_a, struct PointerRNA *ptr_b,
+ struct PropertyRNA *prop_a, struct PropertyRNA *prop_b,
+ const int len_a, const int len_b,
+ const int mode,
+ struct IDOverrideStatic *override, const char *rna_path,
+ const int flags, bool *r_override_changed);
+
+bool rna_property_override_store_default(
+ struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, struct PointerRNA *ptr_storage,
+ struct PropertyRNA *prop_local, struct PropertyRNA *prop_reference, struct PropertyRNA *prop_storage,
+ const int len_local, const int len_reference, const int len_storage,
+ struct IDOverrideStaticPropertyOperation *opop);
+
+bool rna_property_override_apply_default(
+ struct PointerRNA *ptr_dst, struct PointerRNA *ptr_src, struct PointerRNA *ptr_storage,
+ struct PropertyRNA *prop_dst, struct PropertyRNA *prop_src, struct PropertyRNA *prop_storage,
+ const int len_dst, const int len_src, const int len_storage,
+ struct IDOverrideStaticPropertyOperation *opop);
+
/* Builtin Property Callbacks */
@@ -403,8 +473,8 @@ PointerRNA rna_pointer_inherit_refine(struct PointerRNA *ptr, struct StructRNA *
int rna_parameter_size(struct PropertyRNA *parm);
struct Mesh *rna_Main_meshes_new_from_object(
- struct Main *bmain, struct ReportList *reports, struct Scene *sce,
- struct Object *ob, int apply_modifiers, int settings, int calc_tessface, int calc_undeformed);
+ struct Main *bmain, struct ReportList *reports, struct Depsgraph *depsgraph,
+ struct Object *ob, int apply_modifiers, int calc_tessface, int calc_undeformed);
/* XXX, these should not need to be defined here~! */
struct MTex *rna_mtex_texture_slots_add(struct ID *self, struct bContext *C, struct ReportList *reports);
diff --git a/source/blender/makesrna/intern/rna_internal_types.h b/source/blender/makesrna/intern/rna_internal_types.h
index d93f3308b2a..88efff30481 100644
--- a/source/blender/makesrna/intern/rna_internal_types.h
+++ b/source/blender/makesrna/intern/rna_internal_types.h
@@ -40,20 +40,14 @@ struct PointerRNA;
struct FunctionRNA;
struct CollectionPropertyIterator;
struct bContext;
+struct IDOverrideStatic;
+struct IDOverrideStaticProperty;
+struct IDOverrideStaticPropertyOperation;
struct IDProperty;
struct GHash;
struct Main;
struct Scene;
-#ifdef UNIT_TEST
-#define RNA_MAX_ARRAY_LENGTH 64
-#else
-#define RNA_MAX_ARRAY_LENGTH 32
-#endif
-
-#define RNA_MAX_ARRAY_DIMENSION 3
-
-
/* store local properties here */
#define RNA_IDP_UI "_RNA_UI"
@@ -126,6 +120,54 @@ typedef void (*PropStringSetFuncEx)(struct PointerRNA *ptr, struct PropertyRNA *
typedef int (*PropEnumGetFuncEx)(struct PointerRNA *ptr, struct PropertyRNA *prop);
typedef void (*PropEnumSetFuncEx)(struct PointerRNA *ptr, struct PropertyRNA *prop, int value);
+/* Handling override operations, and also comparison. */
+
+/**
+ * If \a override is NULL, merely do comparison between prop_a from ptr_a and prop_b from ptr_b,
+ * following comparison mode given.
+ * If \a override and \a rna_path are not NULL, it will add a new override operation for overridable properties
+ * that differ and have not yet been overridden (and set accordingly \a r_override_changed if given).
+ *
+ * \note Given PropertyRNA are final (in case of IDProps...).
+ * \note In non-array cases, \a len values are 0.
+ * \note \a override, \a rna_path and \a r_override_changed may be NULL pointers.
+ */
+typedef int (*RNAPropOverrideDiff)(
+ struct PointerRNA *ptr_a, struct PointerRNA *ptr_b,
+ struct PropertyRNA *prop_a, struct PropertyRNA *prop_b,
+ const int len_a, const int len_b,
+ const int mode,
+ struct IDOverrideStatic *override, const char *rna_path,
+ const int flags, bool *r_override_changed);
+
+/**
+ * Only used for differential override (add, sub, etc.).
+ * Store into storage the value needed to transform reference's value into local's value.
+ *
+ * \note Given PropertyRNA are final (in case of IDProps...).
+ * \note In non-array cases, \a len values are 0.
+ * \note Might change given override operation (e.g. change 'add' one into 'sub'), in case computed storage value
+ * is out of range (or even change it to basic 'set' operation if nothing else works).
+ */
+typedef bool (*RNAPropOverrideStore)(
+ struct PointerRNA *ptr_local, struct PointerRNA *ptr_reference, struct PointerRNA *ptr_storage,
+ struct PropertyRNA *prop_local, struct PropertyRNA *prop_reference, struct PropertyRNA *prop_storage,
+ const int len_local, const int len_reference, const int len_storage,
+ struct IDOverrideStaticPropertyOperation *opop);
+
+/**
+ * Apply given override operation from src to dst (using value from storage as second operand
+ * for differential operations).
+ *
+ * \note Given PropertyRNA are final (in case of IDProps...).
+ * \note In non-array cases, \a len values are 0.
+ */
+typedef bool (*RNAPropOverrideApply)(
+ struct PointerRNA *ptr_dst, struct PointerRNA *ptr_src, struct PointerRNA *ptr_storage,
+ struct PropertyRNA *prop_dst, struct PropertyRNA *prop_src, struct PropertyRNA *prop_storage,
+ const int len_dst, const int len_src, const int len_storage,
+ struct IDOverrideStaticPropertyOperation *opop);
+
/* Container - generic abstracted container of RNA properties */
typedef struct ContainerRNA {
void *next, *prev;
@@ -203,6 +245,11 @@ struct PropertyRNA {
/* callback for testing if array-item editable (if applicable) */
ItemEditableFunc itemeditable;
+ /* Override handling callbacks (diff is also used for comparison). */
+ RNAPropOverrideDiff override_diff;
+ RNAPropOverrideStore override_store;
+ RNAPropOverrideApply override_apply;
+
/* raw access */
int rawoffset;
RawPropertyType rawtype;
diff --git a/source/blender/makesrna/intern/rna_key.c b/source/blender/makesrna/intern/rna_key.c
index e65011d34d7..472298a3053 100644
--- a/source/blender/makesrna/intern/rna_key.c
+++ b/source/blender/makesrna/intern/rna_key.c
@@ -51,10 +51,11 @@
#include "DNA_object_types.h"
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_key.h"
#include "BKE_main.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
@@ -486,7 +487,7 @@ static void rna_Key_update_data(Main *bmain, Scene *UNUSED(scene), PointerRNA *p
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (BKE_key_from_object(ob) == key) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
}
}
@@ -712,7 +713,7 @@ static void rna_def_keyblock(BlenderRNA *brna)
prop = RNA_def_property(srna, "relative_key", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "ShapeKey");
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL | PROP_PTR_NO_OWNERSHIP);
RNA_def_property_pointer_funcs(prop, "rna_ShapeKey_relative_key_get",
"rna_ShapeKey_relative_key_set", NULL, NULL);
RNA_def_property_ui_text(prop, "Relative Key", "Shape used as a relative key");
diff --git a/source/blender/makesrna/intern/rna_lamp.c b/source/blender/makesrna/intern/rna_lamp.c
index f29fa44d306..5bb24f0270d 100644
--- a/source/blender/makesrna/intern/rna_lamp.c
+++ b/source/blender/makesrna/intern/rna_lamp.c
@@ -45,10 +45,11 @@
#include "MEM_guardedalloc.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_texture.h"
+#include "DEG_depsgraph.h"
+
#include "ED_node.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -62,54 +63,6 @@ static void rna_Lamp_buffer_size_set(PointerRNA *ptr, int value)
la->bufsize &= (~15); /* round to multiple of 16 */
}
-static PointerRNA rna_Lamp_sky_settings_get(PointerRNA *ptr)
-{
- return rna_pointer_inherit_refine(ptr, &RNA_LampSkySettings, ptr->id.data);
-}
-
-static void rna_Lamp_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
-{
- Lamp *la = (Lamp *)ptr->data;
- rna_iterator_array_begin(iter, (void *)la->mtex, sizeof(MTex *), MAX_MTEX, 0, NULL);
-}
-
-static PointerRNA rna_Lamp_active_texture_get(PointerRNA *ptr)
-{
- Lamp *la = (Lamp *)ptr->data;
- Tex *tex;
-
- tex = give_current_lamp_texture(la);
- return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
-}
-
-static void rna_Lamp_active_texture_set(PointerRNA *ptr, PointerRNA value)
-{
- Lamp *la = (Lamp *)ptr->data;
-
- set_current_lamp_texture(la, value.data);
-}
-
-static int rna_use_shadow_get(PointerRNA *ptr)
-{
- Lamp *la = (Lamp *)ptr->data;
-
- if (la->type == LA_SPOT) {
- return (la->mode & (LA_SHAD_BUF | LA_SHAD_RAY)) != 0;
- }
- else {
- return (la->mode & LA_SHAD_RAY) != 0;
- }
-}
-
-static void rna_use_shadow_set(PointerRNA *ptr, int value)
-{
- Lamp *la = (Lamp *)ptr->data;
- la->mode &= ~(LA_SHAD_BUF | LA_SHAD_RAY);
- if (value) {
- la->mode |= LA_SHAD_RAY;
- }
-}
-
static StructRNA *rna_Lamp_refine(struct PointerRNA *ptr)
{
Lamp *la = (Lamp *)ptr->data;
@@ -134,7 +87,7 @@ static void rna_Lamp_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRN
{
Lamp *la = ptr->id.data;
- DAG_id_tag_update(&la->id, 0);
+ DEG_id_tag_update(&la->id, 0);
WM_main_add_notifier(NC_LAMP | ND_LIGHTING, la);
}
@@ -142,18 +95,10 @@ static void rna_Lamp_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
{
Lamp *la = ptr->id.data;
- DAG_id_tag_update(&la->id, 0);
+ DEG_id_tag_update(&la->id, 0);
WM_main_add_notifier(NC_LAMP | ND_LIGHTING_DRAW, la);
}
-static void rna_Lamp_sky_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
-{
- Lamp *la = ptr->id.data;
-
- DAG_id_tag_update(&la->id, 0);
- WM_main_add_notifier(NC_LAMP | ND_SKY, la);
-}
-
static void rna_Lamp_use_nodes_update(bContext *C, PointerRNA *ptr)
{
Lamp *la = (Lamp *)ptr->data;
@@ -175,167 +120,6 @@ const EnumPropertyItem rna_enum_lamp_type_items[] = {
{0, NULL, 0, NULL, NULL}
};
-static void rna_def_lamp_mtex(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_texture_coordinates_items[] = {
- {TEXCO_GLOB, "GLOBAL", 0, "Global", "Use global coordinates for the texture coordinates"},
- {TEXCO_VIEW, "VIEW", 0, "View", "Use view coordinates for the texture coordinates"},
- {TEXCO_OBJECT, "OBJECT", 0, "Object", "Use linked object's coordinates for texture coordinates"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "LampTextureSlot", "TextureSlot");
- RNA_def_struct_sdna(srna, "MTex");
- RNA_def_struct_ui_text(srna, "Lamp Texture Slot", "Texture slot for textures in a Lamp data-block");
-
- prop = RNA_def_property(srna, "texture_coords", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "texco");
- RNA_def_property_enum_items(prop, prop_texture_coordinates_items);
- RNA_def_property_ui_text(prop, "Texture Coordinates", "");
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "object");
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Object", "Object to use for mapping with Object texture coordinates");
-
- prop = RNA_def_property(srna, "use_map_color", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", LAMAP_COL);
- RNA_def_property_ui_text(prop, "Color", "Let the texture affect the basic color of the lamp");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "use_map_shadow", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", LAMAP_SHAD);
- RNA_def_property_ui_text(prop, "Shadow", "Let the texture affect the shadow color of the lamp");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "color_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "colfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Color Factor", "Amount texture affects color values");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "shadow_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "shadowfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Shadow Factor", "Amount texture affects shadow");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-}
-
-static void rna_def_lamp_sky_settings(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_skycolorspace_items[] = {
- {0, "SMPTE", 0, "SMPTE", ""},
- {1, "REC709", 0, "REC709", ""},
- {2, "CIE", 0, "CIE", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "LampSkySettings", NULL);
- RNA_def_struct_sdna(srna, "Lamp");
- RNA_def_struct_nested(brna, srna, "SunLamp");
- RNA_def_struct_ui_text(srna, "Lamp Sky Settings", "Sky related settings for a sun lamp");
-
- prop = RNA_def_property(srna, "sky_color_space", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "sky_colorspace");
- RNA_def_property_enum_items(prop, prop_skycolorspace_items);
- RNA_def_property_ui_text(prop, "Sky Color Space", "Color space to use for internal XYZ->RGB color conversion");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "sky_blend_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "skyblendtype");
- RNA_def_property_enum_items(prop, rna_enum_ramp_blend_items);
- RNA_def_property_ui_text(prop, "Sky Blend Mode", "Blend mode for combining sun sky with world sky");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- /* Number values */
-
- prop = RNA_def_property(srna, "horizon_brightness", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 20.0f);
- RNA_def_property_ui_text(prop, "Horizon Brightness", "Horizon brightness");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "spread", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 10.0f);
- RNA_def_property_ui_text(prop, "Horizon Spread", "Horizon Spread");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "sun_brightness", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 10.0f);
- RNA_def_property_ui_text(prop, "Sun Brightness", "Sun brightness");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "sun_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 10.0f);
- RNA_def_property_ui_text(prop, "Sun Size", "Sun size");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "backscattered_light", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, -1.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Backscattered Light", "Backscattered light");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "sun_intensity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 10.0f);
- RNA_def_property_ui_text(prop, "Sun Intensity", "Sun intensity");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "atmosphere_turbidity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "atm_turbidity");
- RNA_def_property_range(prop, 1.0f, 30.0f);
- RNA_def_property_ui_range(prop, 2.0f, 10.0f, 1, 2);
- RNA_def_property_ui_text(prop, "Atmosphere Turbidity", "Sky turbidity");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "atmosphere_inscattering", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "atm_inscattering_factor");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Atmosphere Inscatter", "Scatter contribution factor");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "atmosphere_extinction", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "atm_extinction_factor");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Atmosphere Extinction", "Extinction scattering contribution factor");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "atmosphere_distance_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "atm_distance_factor");
- RNA_def_property_range(prop, 0.0f, 500.0f);
- RNA_def_property_ui_text(prop, "Atmosphere Distance Factor",
- "Multiplier to convert blender units to physical distance");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "sky_blend", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "skyblendfac");
- RNA_def_property_range(prop, 0.0f, 2.0f);
- RNA_def_property_ui_text(prop, "Sky Blend", "Blend factor with sky");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "sky_exposure", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 20.0f);
- RNA_def_property_ui_text(prop, "Sky Exposure", "Strength of sky shading exponential exposure correction");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- /* boolean */
-
- prop = RNA_def_property(srna, "use_sky", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "sun_effect_type", LA_SUN_EFFECT_SKY);
- RNA_def_property_ui_text(prop, "Sky", "Apply sun effect on sky");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-
- prop = RNA_def_property(srna, "use_atmosphere", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "sun_effect_type", LA_SUN_EFFECT_AP);
- RNA_def_property_ui_text(prop, "Atmosphere", "Apply sun effect on atmosphere");
- RNA_def_property_update(prop, 0, "rna_Lamp_sky_update");
-}
-
static void rna_def_lamp(BlenderRNA *brna)
{
StructRNA *srna;
@@ -371,26 +155,6 @@ static void rna_def_lamp(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Color", "Light color");
RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
- prop = RNA_def_property(srna, "use_own_layer", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_LAYER);
- RNA_def_property_ui_text(prop, "Layer", "Illuminate objects only on the same layers the lamp is on");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "use_negative", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_NEG);
- RNA_def_property_ui_text(prop, "Negative", "Cast negative light");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "use_specular", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "mode", LA_NO_SPEC);
- RNA_def_property_ui_text(prop, "Specular", "Create specular highlights");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "use_diffuse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "mode", LA_NO_DIFF);
- RNA_def_property_ui_text(prop, "Diffuse", "Do diffuse shading");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
/* nodes */
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
@@ -405,11 +169,6 @@ static void rna_def_lamp(BlenderRNA *brna)
/* common */
rna_def_animdata_common(srna);
-
- /* textures */
- rna_def_mtex_common(brna, srna, "rna_Lamp_mtex_begin", "rna_Lamp_active_texture_get",
- "rna_Lamp_active_texture_set", NULL, "LampTextureSlot", "LampTextureSlots",
- "rna_Lamp_draw_update", "rna_Lamp_draw_update");
}
static void rna_def_lamp_falloff(StructRNA *srna)
@@ -436,11 +195,6 @@ static void rna_def_lamp_falloff(StructRNA *srna)
RNA_def_property_ui_text(prop, "Falloff Curve", "Custom Lamp Falloff Curve");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "use_sphere", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SPHERE);
- RNA_def_property_ui_text(prop, "Sphere", "Set light intensity to zero beyond lamp distance");
- RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
-
prop = RNA_def_property(srna, "linear_attenuation", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "att1");
RNA_def_property_range(prop, 0.0f, 1.0f);
@@ -475,77 +229,12 @@ static void rna_def_lamp_falloff(StructRNA *srna)
RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
}
-static void rna_def_lamp_shadow(StructRNA *srna, int spot, int area)
+static void rna_def_lamp_shadow(StructRNA *srna, int sun)
{
PropertyRNA *prop;
- static const EnumPropertyItem prop_shadow_items[] = {
- {0, "NOSHADOW", 0, "No Shadow", ""},
- {LA_SHAD_RAY, "RAY_SHADOW", 0, "Ray Shadow", "Use ray tracing for shadow"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_spot_shadow_items[] = {
- {0, "NOSHADOW", 0, "No Shadow", ""},
- {LA_SHAD_BUF, "BUFFER_SHADOW", 0, "Buffer Shadow", "Let spotlight produce shadows using shadow buffer"},
- {LA_SHAD_RAY, "RAY_SHADOW", 0, "Ray Shadow", "Use ray tracing for shadow"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_ray_sampling_method_items[] = {
- {LA_SAMP_HALTON, "ADAPTIVE_QMC", 0, "Adaptive QMC", ""},
- {LA_SAMP_HAMMERSLEY, "CONSTANT_QMC", 0, "Constant QMC", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_spot_ray_sampling_method_items[] = {
- {LA_SAMP_HALTON, "ADAPTIVE_QMC", 0, "Adaptive QMC", ""},
- {LA_SAMP_HAMMERSLEY, "CONSTANT_QMC", 0, "Constant QMC", ""},
- {LA_SAMP_CONSTANT, "CONSTANT_JITTERED", 0, "Constant Jittered", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_shadbuftype_items[] = {
- {LA_SHADBUF_REGULAR, "REGULAR", 0, "Classical", "Classic shadow buffer"},
- {LA_SHADBUF_HALFWAY, "HALFWAY", 0, "Classic-Halfway",
- "Regular buffer, averaging the closest and 2nd closest Z value to reducing "
- "bias artifacts"},
- {LA_SHADBUF_IRREGULAR, "IRREGULAR", 0, "Irregular",
- "Irregular buffer produces sharp shadow always, but it doesn't show up for raytracing"},
- {LA_SHADBUF_DEEP, "DEEP", 0, "Deep",
- "Deep shadow buffer supports transparency and better filtering, at the cost of "
- "more memory usage and processing time"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_shadbuffiltertype_items[] = {
- {LA_SHADBUF_BOX, "BOX", 0, "Box", "Apply the Box filter to shadow buffer samples"},
- {LA_SHADBUF_TENT, "TENT", 0, "Tent", "Apply the Tent Filter to shadow buffer samples"},
- {LA_SHADBUF_GAUSS, "GAUSS", 0, "Gauss", "Apply the Gauss filter to shadow buffer samples"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_numbuffer_items[] = {
- {1, "BUFFERS_1", 0, "1", "Only one buffer rendered"},
- {4, "BUFFERS_4", 0, "4", "Render 4 buffers for better AA, this quadruples memory usage"},
- {9, "BUFFERS_9", 0, "9", "Render 9 buffers for better AA, this uses nine times more memory"},
- {0, NULL, 0, NULL, NULL}
- };
-
- /* GE only */
- static const EnumPropertyItem prop_ge_shadowbuffer_type_items[] = {
- {LA_SHADMAP_SIMPLE, "SIMPLE", 0, "Simple", "Simple shadow maps"},
- {LA_SHADMAP_VARIANCE, "VARIANCE", 0, "Variance", "Variance shadow maps"},
- {0, NULL, 0, NULL, NULL}
- };
-
prop = RNA_def_property(srna, "use_shadow", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_funcs(prop, "rna_use_shadow_get", "rna_use_shadow_set");
- RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
-
- prop = RNA_def_property(srna, "shadow_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, (spot) ? prop_spot_shadow_items : prop_shadow_items);
+ RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SHADOW);
RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
prop = RNA_def_property(srna, "shadow_buffer_size", PROP_INT, PROP_NONE);
@@ -557,19 +246,6 @@ static void rna_def_lamp_shadow(StructRNA *srna, int spot, int area)
RNA_def_property_int_funcs(prop, NULL, "rna_Lamp_buffer_size_set", NULL);
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "shadow_filter_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "filtertype");
- RNA_def_property_enum_items(prop, prop_shadbuffiltertype_items);
- RNA_def_property_ui_text(prop, "Shadow Filter Type", "Type of shadow filter (Buffer Shadows)");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "shadow_sample_buffers", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "buffers");
- RNA_def_property_enum_items(prop, prop_numbuffer_items);
- RNA_def_property_ui_text(prop, "Shadow Sample Buffers",
- "Number of shadow buffers to render for better AA, this increases memory usage");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
prop = RNA_def_property(srna, "shadow_buffer_clip_start", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, NULL, "clipsta");
RNA_def_property_range(prop, 0.0f, 9999.0f);
@@ -586,8 +262,9 @@ static void rna_def_lamp_shadow(StructRNA *srna, int spot, int area)
prop = RNA_def_property(srna, "shadow_buffer_bias", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "bias");
- RNA_def_property_range(prop, 0.001f, 5.0f);
- RNA_def_property_ui_text(prop, "Shadow Buffer Bias", "Shadow buffer sampling bias");
+ RNA_def_property_range(prop, 0.001f, 9999.0f);
+ RNA_def_property_ui_range(prop, 0.001f, 5.0f, 1.0, 3);
+ RNA_def_property_ui_text(prop, "Shadow Buffer Bias", "Bias for reducing self shadowing");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
prop = RNA_def_property(srna, "shadow_buffer_bleed_bias", PROP_FLOAT, PROP_NONE);
@@ -596,6 +273,12 @@ static void rna_def_lamp_shadow(StructRNA *srna, int spot, int area)
RNA_def_property_ui_text(prop, "Shadow Buffer Bleed Bias", "Bias for reducing light-bleed on variance shadow maps");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
+ prop = RNA_def_property(srna, "shadow_buffer_exp", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "bleedexp");
+ RNA_def_property_range(prop, 1.0f, 9999.0f);
+ RNA_def_property_ui_text(prop, "Shadow Buffer Exponent", "Bias for reducing light-bleed on exponential shadow maps");
+ RNA_def_property_update(prop, 0, "rna_Lamp_update");
+
prop = RNA_def_property(srna, "shadow_buffer_soft", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "soft");
RNA_def_property_range(prop, 0.0f, 100.0f);
@@ -608,88 +291,86 @@ static void rna_def_lamp_shadow(StructRNA *srna, int spot, int area)
RNA_def_property_ui_text(prop, "Samples", "Number of shadow buffer samples");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "shadow_buffer_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "buftype");
- RNA_def_property_enum_items(prop, prop_shadbuftype_items);
- RNA_def_property_ui_text(prop, "Shadow Buffer Type", "Type of shadow buffer");
+ prop = RNA_def_property(srna, "shadow_color", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_float_sdna(prop, NULL, "shdwr");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Shadow Color", "Color of shadows cast by the lamp");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "ge_shadow_buffer_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "shadowmap_type");
- RNA_def_property_enum_items(prop, prop_ge_shadowbuffer_type_items);
- RNA_def_property_ui_text(prop, "Shadow Map Type", "The shadow mapping algorithm used");
+ prop = RNA_def_property(srna, "shadow_soft_size", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "area_size");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
+ RNA_def_property_ui_text(prop, "Shadow Soft Size", "Light size for ray shadow sampling (Raytraced shadows)");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
+ /* Eevee */
+ prop = RNA_def_property(srna, "use_contact_shadow", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SHAD_CONTACT);
+ RNA_def_property_ui_text(prop, "Contact Shadow", "Use screen space raytracing to have correct shadowing "
+ "near occluder, or for small features that does not appear "
+ "in shadow maps");
+ RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "use_auto_clip_start", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bufflag", LA_SHADBUF_AUTO_START);
- RNA_def_property_ui_text(prop, "Autoclip Start",
- "Automatic calculation of clipping-start, based on visible vertices");
- RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
-
- prop = RNA_def_property(srna, "use_auto_clip_end", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bufflag", LA_SHADBUF_AUTO_END);
- RNA_def_property_ui_text(prop, "Autoclip End", "Automatic calculation of clipping-end, based on visible vertices");
- RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
-
- prop = RNA_def_property(srna, "compression_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "compressthresh");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Compress", "Deep shadow map compression threshold");
+ prop = RNA_def_property(srna, "specular_factor", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "spec_fac");
+ RNA_def_property_range(prop, 0.0f, 9999.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.01, 2);
+ RNA_def_property_ui_text(prop, "Specular Factor", "Specular reflection multiplier");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "shadow_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "shdwr");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Shadow Color", "Color of shadows cast by the lamp");
+ prop = RNA_def_property(srna, "contact_shadow_distance", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "contact_dist");
+ RNA_def_property_range(prop, 0.0f, 9999.0f);
+ RNA_def_property_ui_text(prop, "Contact Shadow Distance", "World space distance in which to search for "
+ "screen space occluder");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "use_only_shadow", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_ONLYSHADOW);
- RNA_def_property_ui_text(prop, "Only Shadow", "Cast shadows only, without illuminating objects");
+ prop = RNA_def_property(srna, "contact_shadow_bias", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "contact_bias");
+ RNA_def_property_range(prop, 0.001f, 9999.0f);
+ RNA_def_property_ui_range(prop, 0.001f, 5.0f, 1.0, 3);
+ RNA_def_property_ui_text(prop, "Contact Shadow Bias", "Bias to avoid self shadowing");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "shadow_ray_sample_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "ray_samp_method");
- RNA_def_property_enum_items(prop, (area) ? prop_spot_ray_sampling_method_items : prop_ray_sampling_method_items);
- RNA_def_property_ui_text(prop, "Shadow Ray Sampling Method",
- "Method for generating shadow samples: Adaptive QMC is fastest, "
- "Constant QMC is less noisy but slower");
+ prop = RNA_def_property(srna, "contact_shadow_soft_size", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "contact_spread");
+ RNA_def_property_range(prop, 0.0f, 9999.0f);
+ RNA_def_property_ui_text(prop, "Contact Shadow Soft", "Control how soft the contact shadows will be");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, (area) ? "shadow_ray_samples_x" : "shadow_ray_samples", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "ray_samp");
- RNA_def_property_range(prop, 1, 64);
- RNA_def_property_ui_text(prop, (area) ? "Shadow Ray Samples" : "Shadow Ray Samples X",
- "Number of samples taken extra (samples x samples)");
+ prop = RNA_def_property(srna, "contact_shadow_thickness", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "contact_thickness");
+ RNA_def_property_range(prop, 0.0f, 9999.0f);
+ RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
+ RNA_def_property_ui_text(prop, "Contact Shadow Thickness", "Pixel thickness used to detect occlusion");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- if (area) {
- prop = RNA_def_property(srna, "shadow_ray_samples_y", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "ray_sampy");
- RNA_def_property_range(prop, 1, 64);
- RNA_def_property_ui_text(prop, "Shadow Ray Samples Y",
- "Number of samples taken extra (samples x samples)");
+ if (sun) {
+ prop = RNA_def_property(srna, "shadow_cascade_max_distance", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "cascade_max_dist");
+ RNA_def_property_range(prop, 0.0f, 9999.0f);
+ RNA_def_property_ui_text(prop, "Cascade Max Distance", "End distance of the cascaded shadow map (only in perspective view)");
RNA_def_property_update(prop, 0, "rna_Lamp_update");
- }
- prop = RNA_def_property(srna, "shadow_adaptive_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "adapt_thresh");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Shadow Adaptive Threshold", "Threshold for Adaptive Sampling (Raytraced shadows)");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
+ prop = RNA_def_property(srna, "shadow_cascade_count", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "cascade_count");
+ RNA_def_property_range(prop, 1, 4);
+ RNA_def_property_ui_text(prop, "Cascade Count", "Number of texture used by the cascaded shadow map");
+ RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "shadow_soft_size", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "area_size");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0, 100, 0.1, 3);
- RNA_def_property_ui_text(prop, "Shadow Soft Size", "Light size for ray shadow sampling (Raytraced shadows)");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
+ prop = RNA_def_property(srna, "shadow_cascade_exponent", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "cascade_exponent");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Exponential Distribution", "Higher value increase resolution towards the viewpoint");
+ RNA_def_property_update(prop, 0, "rna_Lamp_update");
- prop = RNA_def_property(srna, "use_shadow_layer", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_LAYER_SHADOW);
- RNA_def_property_ui_text(prop, "Shadow Layer", "Objects on the same layers only cast shadows");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
+ prop = RNA_def_property(srna, "shadow_cascade_fade", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "cascade_fade");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Cascade Fade", "How smooth is the transition between each cascade");
+ RNA_def_property_update(prop, 0, "rna_Lamp_update");
+ }
}
static void rna_def_point_lamp(BlenderRNA *brna)
@@ -702,7 +383,7 @@ static void rna_def_point_lamp(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_LAMP_POINT);
rna_def_lamp_falloff(srna);
- rna_def_lamp_shadow(srna, 0, 0);
+ rna_def_lamp_shadow(srna, 0);
}
static void rna_def_area_lamp(BlenderRNA *brna)
@@ -721,22 +402,8 @@ static void rna_def_area_lamp(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Area Lamp", "Directional area lamp");
RNA_def_struct_ui_icon(srna, ICON_LAMP_AREA);
- rna_def_lamp_shadow(srna, 0, 1);
-
- prop = RNA_def_property(srna, "use_umbra", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "ray_samp_type", LA_SAMP_UMBRA);
- RNA_def_property_ui_text(prop, "Umbra", "Emphasize parts that are fully shadowed (Constant Jittered sampling)");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "use_dither", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "ray_samp_type", LA_SAMP_DITHER);
- RNA_def_property_ui_text(prop, "Dither", "Use 2x2 dithering for sampling (Constant Jittered sampling)");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "use_jitter", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "ray_samp_type", LA_SAMP_JITTER);
- RNA_def_property_ui_text(prop, "Jitter", "Use noise for sampling (Constant Jittered sampling)");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
+ rna_def_lamp_shadow(srna, 0);
+ rna_def_lamp_falloff(srna);
prop = RNA_def_property(srna, "shape", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "area_shape");
@@ -758,12 +425,6 @@ static void rna_def_area_lamp(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Size Y",
"Size of the area of the area Lamp in the Y direction for Rectangle shapes");
RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
-
- prop = RNA_def_property(srna, "gamma", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "k");
- RNA_def_property_ui_range(prop, 0.001, 2.0, 0.1, 3);
- RNA_def_property_ui_text(prop, "Gamma", "Light gamma correction value");
- RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
}
static void rna_def_spot_lamp(BlenderRNA *brna)
@@ -777,30 +438,13 @@ static void rna_def_spot_lamp(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_LAMP_SPOT);
rna_def_lamp_falloff(srna);
- rna_def_lamp_shadow(srna, 1, 0);
+ rna_def_lamp_shadow(srna, 0);
prop = RNA_def_property(srna, "use_square", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SQUARE);
RNA_def_property_ui_text(prop, "Square", "Cast a square spot light shape");
RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
- prop = RNA_def_property(srna, "use_halo", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_HALO);
- RNA_def_property_ui_text(prop, "Halo", "Render spotlight with a volumetric halo");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "halo_intensity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "haint");
- RNA_def_property_ui_range(prop, 0, 5.0, 0.1, 3);
- RNA_def_property_ui_text(prop, "Halo Intensity", "Brightness of the spotlight's halo cone");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
- prop = RNA_def_property(srna, "halo_step", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "shadhalostep");
- RNA_def_property_range(prop, 0, 12);
- RNA_def_property_ui_text(prop, "Halo Step", "Volumetric halo sampling frequency");
- RNA_def_property_update(prop, 0, "rna_Lamp_update");
-
prop = RNA_def_property(srna, "spot_blend", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "spotblend");
RNA_def_property_range(prop, 0.0f, 1.0f);
@@ -823,36 +467,13 @@ static void rna_def_spot_lamp(BlenderRNA *brna)
static void rna_def_sun_lamp(BlenderRNA *brna)
{
StructRNA *srna;
- PropertyRNA *prop;
srna = RNA_def_struct(brna, "SunLamp", "Lamp");
RNA_def_struct_sdna(srna, "Lamp");
RNA_def_struct_ui_text(srna, "Sun Lamp", "Constant direction parallel ray lamp");
RNA_def_struct_ui_icon(srna, ICON_LAMP_SUN);
- rna_def_lamp_shadow(srna, 0, 0);
-
- /* sky */
- prop = RNA_def_property(srna, "sky", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "LampSkySettings");
- RNA_def_property_pointer_funcs(prop, "rna_Lamp_sky_settings_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Sky Settings", "Sky related settings for sun lamps");
-
- rna_def_lamp_sky_settings(brna);
-
- /* BGE Only */
- prop = RNA_def_property(srna, "shadow_frustum_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "shadow_frustum_size");
- RNA_def_property_ui_range(prop, 0.001, 100.0, 2, 1);
- RNA_def_property_ui_text(prop, "Frustum Size", "Size of the frustum used for creating the shadow map");
- RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
-
- prop = RNA_def_property(srna, "show_shadow_box", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", LA_SHOW_SHADOW_BOX);
- RNA_def_property_ui_text(prop, "Show Shadow Box",
- "Draw a box in 3D view to visualize which objects are contained in it");
- RNA_def_property_update(prop, 0, "rna_Lamp_draw_update");
+ rna_def_lamp_shadow(srna, 1);
}
static void rna_def_hemi_lamp(BlenderRNA *brna)
@@ -873,7 +494,6 @@ void RNA_def_lamp(BlenderRNA *brna)
rna_def_spot_lamp(brna);
rna_def_sun_lamp(brna);
rna_def_hemi_lamp(brna);
- rna_def_lamp_mtex(brna);
}
#endif
diff --git a/source/blender/makesrna/intern/rna_lattice.c b/source/blender/makesrna/intern/rna_lattice.c
index 9424ddf7d0e..904a6289fc1 100644
--- a/source/blender/makesrna/intern/rna_lattice.c
+++ b/source/blender/makesrna/intern/rna_lattice.c
@@ -43,11 +43,12 @@
#include "DNA_scene_types.h"
#include "BLI_string.h"
-#include "BKE_depsgraph.h"
#include "BKE_lattice.h"
#include "BKE_main.h"
#include "BKE_deform.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
#include "ED_lattice.h"
@@ -97,7 +98,7 @@ static void rna_Lattice_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), P
{
ID *id = ptr->id.data;
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
}
@@ -119,7 +120,7 @@ static void rna_Lattice_update_data_editlatt(Main *UNUSED(bmain), Scene *UNUSED(
BLI_strncpy(lt_em->vgroup, lt->vgroup, sizeof(lt_em->vgroup));
}
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
}
diff --git a/source/blender/makesrna/intern/rna_lattice_api.c b/source/blender/makesrna/intern/rna_lattice_api.c
index 2ea59d31262..5637f8d9248 100644
--- a/source/blender/makesrna/intern/rna_lattice_api.c
+++ b/source/blender/makesrna/intern/rna_lattice_api.c
@@ -45,8 +45,14 @@ static void rna_Lattice_transform(Lattice *lt, float *mat, int shape_keys)
{
BKE_lattice_transform(lt, (float (*)[4])mat, shape_keys);
- DAG_id_tag_update(&lt->id, 0);
+ DEG_id_tag_update(&lt->id, 0);
}
+
+static void rna_Lattice_update_gpu_tag(Lattice *lt)
+{
+ BKE_lattice_batch_cache_dirty(lt, BKE_LATTICE_BATCH_DIRTY_ALL);
+}
+
#else
void RNA_api_lattice(StructRNA *srna)
@@ -59,6 +65,8 @@ void RNA_api_lattice(StructRNA *srna)
parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
RNA_def_boolean(func, "shape_keys", 0, "", "Transform Shape Keys");
+
+ RNA_def_function(srna, "update_gpu_tag", "rna_Lattice_update_gpu_tag");
}
#endif
diff --git a/source/blender/makesrna/intern/rna_layer.c b/source/blender/makesrna/intern/rna_layer.c
new file mode 100644
index 00000000000..c9728e82442
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_layer.c
@@ -0,0 +1,2036 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_layer.c
+ * \ingroup RNA
+ */
+
+#include "DNA_scene_types.h"
+#include "DNA_layer_types.h"
+#include "DNA_view3d_types.h"
+
+#include "BLI_math.h"
+#include "BLI_string_utils.h"
+
+#include "BLT_translation.h"
+
+#include "ED_object.h"
+#include "ED_render.h"
+
+#include "RE_engine.h"
+
+#include "DRW_engine.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_define.h"
+
+#include "rna_internal.h"
+
+const EnumPropertyItem rna_enum_collection_type_items[] = {
+ {COLLECTION_TYPE_NONE, "NONE", 0, "Normal", ""},
+ {COLLECTION_TYPE_GROUP_INTERNAL, "GROUP_INTERNAL", 0, "Group Internal", ""},
+ {0, NULL, 0, NULL, NULL}
+};
+
+#ifdef RNA_RUNTIME
+
+#include "DNA_group_types.h"
+#include "DNA_object_types.h"
+
+#include "RNA_access.h"
+
+#include "BKE_idprop.h"
+#include "BKE_layer.h"
+#include "BKE_node.h"
+#include "BKE_scene.h"
+#include "BKE_mesh.h"
+
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
+static StructRNA *rna_SceneCollection_refine(PointerRNA *ptr)
+{
+ SceneCollection *scene_collection = (SceneCollection *)ptr->data;
+ switch (scene_collection->type) {
+ case COLLECTION_TYPE_GROUP_INTERNAL:
+ case COLLECTION_TYPE_NONE:
+ return &RNA_SceneCollection;
+ default:
+ BLI_assert(!"Collection type not fully implemented");
+ break;
+ }
+ return &RNA_SceneCollection;
+}
+
+static void rna_SceneCollection_name_set(PointerRNA *ptr, const char *value)
+{
+ Scene *scene = (Scene *)ptr->id.data;
+ SceneCollection *sc = (SceneCollection *)ptr->data;
+ BKE_collection_rename(&scene->id, sc, value);
+}
+
+static PointerRNA rna_SceneCollection_objects_get(CollectionPropertyIterator *iter)
+{
+ ListBaseIterator *internal = &iter->internal.listbase;
+
+ /* we are actually iterating a LinkData list, so override get */
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((LinkData *)internal->link)->data);
+}
+
+static int rna_SceneCollection_move_above(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
+{
+ if (!BKE_collection_move_above(id, sc_dst, sc_src)) {
+ return 0;
+ }
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return 1;
+}
+
+static int rna_SceneCollection_move_below(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
+{
+ if (!BKE_collection_move_below(id, sc_dst, sc_src)) {
+ return 0;
+ }
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return 1;
+}
+
+static int rna_SceneCollection_move_into(ID *id, SceneCollection *sc_src, Main *bmain, SceneCollection *sc_dst)
+{
+ if (!BKE_collection_move_into(id, sc_dst, sc_src)) {
+ return 0;
+ }
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return 1;
+}
+
+static SceneCollection *rna_SceneCollection_duplicate(
+ ID *id, SceneCollection *scene_collection, Main *bmain, bContext *C, ReportList *reports)
+{
+ if (scene_collection == BKE_collection_master(id)) {
+ BKE_report(reports, RPT_ERROR, "The master collection can't be duplicated");
+ return NULL;
+ }
+
+ SceneCollection *scene_collection_new = BKE_collection_duplicate(id, scene_collection);
+
+ DEG_relations_tag_update(bmain);
+ /* Don't use id here, since the layer collection may come from a group. */
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, CTX_data_scene(C));
+
+ return scene_collection_new;
+}
+
+static SceneCollection *rna_SceneCollection_new(
+ ID *id, SceneCollection *sc_parent, Main *bmain, const char *name)
+{
+ SceneCollection *sc = BKE_collection_add(id, sc_parent, COLLECTION_TYPE_NONE, name);
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return sc;
+}
+
+static void rna_SceneCollection_remove(
+ ID *id, SceneCollection *sc_parent, Main *bmain, ReportList *reports, PointerRNA *sc_ptr)
+{
+ SceneCollection *sc = sc_ptr->data;
+
+ const int index = BLI_findindex(&sc_parent->scene_collections, sc);
+ if (index == -1) {
+ BKE_reportf(reports, RPT_ERROR, "Collection '%s' is not a sub-collection of '%s'",
+ sc->name, sc_parent->name);
+ return;
+ }
+
+ if (!BKE_collection_remove(id, sc)) {
+ BKE_reportf(reports, RPT_ERROR, "Collection '%s' could not be removed from collection '%s'",
+ sc->name, sc_parent->name);
+ return;
+ }
+
+ RNA_POINTER_INVALIDATE(sc_ptr);
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+}
+
+static int rna_SceneCollection_objects_active_index_get(PointerRNA *ptr)
+{
+ SceneCollection *sc = (SceneCollection *)ptr->data;
+ return sc->active_object_index;
+}
+
+static void rna_SceneCollection_objects_active_index_set(PointerRNA *ptr, int value)
+{
+ SceneCollection *sc = (SceneCollection *)ptr->data;
+ sc->active_object_index = value;
+}
+
+static void rna_SceneCollection_objects_active_index_range(
+ PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
+{
+ SceneCollection *sc = (SceneCollection *)ptr->data;
+ *min = 0;
+ *max = max_ii(0, BLI_listbase_count(&sc->objects) - 1);
+}
+
+void rna_SceneCollection_object_link(
+ ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
+{
+ Scene *scene = (Scene *)id;
+
+ if (BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
+ BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in collection '%s'", ob->id.name + 2, sc->name);
+ return;
+ }
+
+ BKE_collection_object_add(&scene->id, sc, ob);
+
+ /* TODO(sergey): Only update relations for the current scene. */
+ DEG_relations_tag_update(bmain);
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
+}
+
+static void rna_SceneCollection_object_unlink(
+ ID *id, SceneCollection *sc, Main *bmain, ReportList *reports, Object *ob)
+{
+ Scene *scene = (Scene *)id;
+
+ if (!BLI_findptr(&sc->objects, ob, offsetof(LinkData, data))) {
+ BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in collection '%s'", ob->id.name + 2, sc->name);
+ return;
+ }
+
+ BKE_collection_object_remove(bmain, &scene->id, sc, ob, false);
+
+ /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
+ DEG_relations_tag_update(bmain);
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
+}
+
+/****** layer collection engine settings *******/
+
+#define RNA_LAYER_ENGINE_GET_SET(_TYPE_, _ENGINE_, _NAME_) \
+static _TYPE_ rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_get(PointerRNA *ptr) \
+{ \
+ IDProperty *props = (IDProperty *)ptr->data; \
+ return BKE_collection_engine_property_value_get_##_TYPE_(props, #_NAME_); \
+} \
+ \
+static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_set(PointerRNA *ptr, _TYPE_ value) \
+{ \
+ IDProperty *props = (IDProperty *)ptr->data; \
+ BKE_collection_engine_property_value_set_##_TYPE_(props, #_NAME_, value); \
+}
+
+#define RNA_LAYER_ENGINE_GET_SET_ARRAY(_TYPE_, _ENGINE_, _NAME_, _LEN_) \
+static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_get(PointerRNA *ptr, _TYPE_ *values) \
+{ \
+ IDProperty *props = (IDProperty *)ptr->data; \
+ IDProperty *idprop = IDP_GetPropertyFromGroup(props, #_NAME_); \
+ if (idprop != NULL) { \
+ memcpy(values, IDP_Array(idprop), sizeof(_TYPE_) * idprop->len); \
+ } \
+} \
+ \
+static void rna_LayerEngineSettings_##_ENGINE_##_##_NAME_##_set(PointerRNA *ptr, const _TYPE_ *values) \
+{ \
+ IDProperty *props = (IDProperty *)ptr->data; \
+ BKE_collection_engine_property_value_set_##_TYPE_##_array(props, #_NAME_, values); \
+}
+
+#define RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(float, Clay, _NAME_)
+
+#define RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT_ARRAY(_NAME_, _LEN_) \
+ RNA_LAYER_ENGINE_GET_SET_ARRAY(float, Clay, _NAME_, _LEN_)
+
+#define RNA_LAYER_ENGINE_CLAY_GET_SET_INT(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(int, Clay, _NAME_)
+
+#define RNA_LAYER_ENGINE_CLAY_GET_SET_BOOL(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(bool, Clay, _NAME_)
+
+#define RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(float, Eevee, _NAME_)
+
+#define RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT_ARRAY(_NAME_, _LEN_) \
+ RNA_LAYER_ENGINE_GET_SET_ARRAY(float, Eevee, _NAME_, _LEN_)
+
+#define RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(int, Eevee, _NAME_)
+
+#define RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(bool, Eevee, _NAME_)
+
+#define RNA_LAYER_ENGINE_WORKBENCH_GET_SET_FLOAT_ARRAY(_NAME_, _LEN_) \
+ RNA_LAYER_ENGINE_GET_SET_ARRAY(float, Workbench, _NAME_, _LEN_)
+
+#define RNA_LAYER_ENGINE_WORKBENCH_GET_SET_FLOAT(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(float, Workbench, _NAME_)
+
+#define RNA_LAYER_ENGINE_WORKBENCH_GET_SET_INT(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(int, Workbench, _NAME_)
+
+#define RNA_LAYER_ENGINE_WORKBENCH_GET_SET_BOOL(_NAME_) \
+ RNA_LAYER_ENGINE_GET_SET(bool, Workbench, _NAME_)
+
+/* clay engine */
+#ifdef WITH_CLAY_ENGINE
+/* ViewLayer settings. */
+RNA_LAYER_ENGINE_CLAY_GET_SET_INT(ssao_samples)
+
+/* LayerCollection settings. */
+RNA_LAYER_ENGINE_CLAY_GET_SET_INT(matcap_icon)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_rotation)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_hue)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_saturation)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(matcap_value)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_factor_cavity)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_factor_edge)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_distance)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(ssao_attenuation)
+RNA_LAYER_ENGINE_CLAY_GET_SET_FLOAT(hair_brightness_randomness)
+#endif /* WITH_CLAY_ENGINE */
+
+/* workbench engine */
+/* Collection settings */
+RNA_LAYER_ENGINE_WORKBENCH_GET_SET_FLOAT(random_object_color_saturation)
+RNA_LAYER_ENGINE_WORKBENCH_GET_SET_FLOAT(random_object_color_value)
+/* View Layer settings */
+RNA_LAYER_ENGINE_WORKBENCH_GET_SET_FLOAT_ARRAY(light_direction, 3)
+
+/* eevee engine */
+/* ViewLayer settings. */
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_enable)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_use_bent_normals)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(gtao_bounce)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_factor)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_quality)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(gtao_distance)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(dof_enable)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_max_size)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bokeh_threshold)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(bloom_enable)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_threshold)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT_ARRAY(bloom_color, 3)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_knee)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_radius)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_clamp)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(bloom_intensity)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(motion_blur_enable)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(motion_blur_samples)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(motion_blur_shutter)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_enable)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_start)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_end)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_tile_size)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_samples)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_sample_distribution)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_lights)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(volumetric_light_clamp)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_shadows)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(volumetric_shadow_samples)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(volumetric_colored_transmittance)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(sss_enable)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(sss_samples)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(sss_jitter_threshold)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(sss_separate_albedo)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_refraction)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_enable)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(ssr_halfres)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_quality)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_max_roughness)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_thickness)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_border_fade)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_FLOAT(ssr_firefly_fac)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(shadow_method)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(shadow_cube_size)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(shadow_cascade_size)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(shadow_high_bitdepth)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(taa_samples)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(taa_render_samples)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_BOOL(taa_reprojection)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(gi_diffuse_bounces)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(gi_cubemap_resolution)
+RNA_LAYER_ENGINE_EEVEE_GET_SET_INT(gi_visibility_resolution)
+
+#undef RNA_LAYER_ENGINE_GET_SET
+
+static void rna_ViewLayerEngineSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
+{
+ Scene *scene = CTX_data_scene(C);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+}
+
+static void rna_LayerCollectionEngineSettings_update(bContext *UNUSED(C), PointerRNA *ptr)
+{
+ ID *id = ptr->id.data;
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+
+ /* Instead of passing 'noteflag' to the rna update function, we handle the notifier ourselves.
+ * We need to do this because the LayerCollection may be coming from different ID types (Scene or Group)
+ * and when using NC_SCENE the id most match the active scene for the listener to receive the notification.*/
+
+ WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, NULL);
+}
+
+/***********************************/
+
+static void engine_settings_use(IDProperty *root, IDProperty *props, PointerRNA *props_ptr, const char *identifier)
+{
+ PropertyRNA *prop = RNA_struct_find_property(props_ptr, identifier);
+
+ switch (RNA_property_type(prop)) {
+ case PROP_FLOAT:
+ {
+ float value = BKE_collection_engine_property_value_get_float(props, identifier);
+ BKE_collection_engine_property_add_float(root, identifier, value);
+ break;
+ }
+ case PROP_ENUM:
+ {
+ int value = BKE_collection_engine_property_value_get_int(props, identifier);
+ BKE_collection_engine_property_add_int(root, identifier, value);
+ break;
+ }
+ case PROP_INT:
+ {
+ int value = BKE_collection_engine_property_value_get_int(props, identifier);
+ BKE_collection_engine_property_add_int(root, identifier, value);
+ break;
+ }
+ case PROP_BOOLEAN:
+ {
+ int value = BKE_collection_engine_property_value_get_int(props, identifier);
+ BKE_collection_engine_property_add_bool(root, identifier, value);
+ break;
+ }
+ case PROP_STRING:
+ case PROP_POINTER:
+ case PROP_COLLECTION:
+ default:
+ break;
+ }
+}
+
+static StructRNA *rna_ViewLayerSettings_refine(PointerRNA *ptr)
+{
+ IDProperty *props = (IDProperty *)ptr->data;
+ BLI_assert(props && props->type == IDP_GROUP);
+
+ switch (props->subtype) {
+ case IDP_GROUP_SUB_ENGINE_RENDER:
+#ifdef WITH_CLAY_ENGINE
+ if (STREQ(props->name, RE_engine_id_BLENDER_CLAY)) {
+ return &RNA_ViewLayerEngineSettingsClay;
+ }
+#endif
+ if (STREQ(props->name, RE_engine_id_BLENDER_EEVEE)) {
+ return &RNA_ViewLayerEngineSettingsEevee;
+ }
+ else if (STREQ(props->name, RE_engine_id_BLENDER_WORKBENCH)) {
+ return &RNA_ViewLayerEngineSettingsWorkbench;
+ }
+ break;
+ default:
+ BLI_assert(!"Mode not fully implemented");
+ break;
+ }
+
+ return &RNA_ViewLayerSettings;
+}
+
+static void rna_ViewLayerSettings_name_get(PointerRNA *ptr, char *value)
+{
+ IDProperty *props = (IDProperty *)ptr->data;
+ strcpy(value, props->name);
+}
+
+static int rna_ViewLayerSettings_name_length(PointerRNA *ptr)
+{
+ IDProperty *props = (IDProperty *)ptr->data;
+ return strnlen(props->name, sizeof(props->name));
+}
+
+static void rna_ViewLayerSettings_use(ID *id, IDProperty *props, const char *identifier)
+{
+ Scene *scene = (Scene *)id;
+ PointerRNA scene_props_ptr;
+ IDProperty *scene_props;
+
+ scene_props = BKE_view_layer_engine_scene_get(scene, props->name);
+ RNA_pointer_create(id, &RNA_ViewLayerSettings, scene_props, &scene_props_ptr);
+
+ engine_settings_use(props, scene_props, &scene_props_ptr, identifier);
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+}
+
+static void rna_ViewLayerSettings_unuse(ID *id, IDProperty *props, const char *identifier)
+{
+ IDProperty *prop_to_remove = IDP_GetPropertyFromGroup(props, identifier);
+ IDP_FreeFromGroup(props, prop_to_remove);
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+}
+
+static StructRNA *rna_LayerCollectionSettings_refine(PointerRNA *ptr)
+{
+ IDProperty *props = (IDProperty *)ptr->data;
+ BLI_assert(props && props->type == IDP_GROUP);
+
+ switch (props->subtype) {
+ case IDP_GROUP_SUB_ENGINE_RENDER:
+#ifdef WITH_CLAY_ENGINE
+ if (STREQ(props->name, RE_engine_id_BLENDER_CLAY)) {
+ return &RNA_LayerCollectionEngineSettingsClay;
+ }
+#endif
+ if (STREQ(props->name, RE_engine_id_BLENDER_WORKBENCH)) {
+ return &RNA_LayerCollectionEngineSettingsWorkbench;
+ }
+ if (STREQ(props->name, RE_engine_id_BLENDER_EEVEE)) {
+ /* printf("Mode not fully implemented\n"); */
+ return &RNA_LayerCollectionSettings;
+ }
+ break;
+ default:
+ BLI_assert(!"Mode not fully implemented");
+ break;
+ }
+
+ return &RNA_LayerCollectionSettings;
+}
+
+static void rna_LayerCollectionSettings_name_get(PointerRNA *ptr, char *value)
+{
+ IDProperty *props = (IDProperty *)ptr->data;
+ strcpy(value, props->name);
+}
+
+static int rna_LayerCollectionSettings_name_length(PointerRNA *ptr)
+{
+ IDProperty *props = (IDProperty *)ptr->data;
+ return strnlen(props->name, sizeof(props->name));
+}
+
+static void rna_LayerCollectionSettings_use(ID *id, IDProperty *props, const char *identifier)
+{
+ Scene *scene = (Scene *)id;
+ PointerRNA scene_props_ptr;
+ IDProperty *scene_props;
+
+ scene_props = BKE_layer_collection_engine_scene_get(scene, props->name);
+ RNA_pointer_create(id, &RNA_LayerCollectionSettings, scene_props, &scene_props_ptr);
+ engine_settings_use(props, scene_props, &scene_props_ptr, identifier);
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+}
+
+static void rna_LayerCollectionSettings_unuse(ID *id, IDProperty *props, const char *identifier)
+{
+ IDProperty *prop_to_remove = IDP_GetPropertyFromGroup(props, identifier);
+ IDP_FreeFromGroup(props, prop_to_remove);
+
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+}
+
+static void rna_LayerCollection_name_get(PointerRNA *ptr, char *value)
+{
+ SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
+ strcpy(value, sc->name);
+}
+
+static int rna_LayerCollection_name_length(PointerRNA *ptr)
+{
+ SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
+ return strnlen(sc->name, sizeof(sc->name));
+}
+
+static void rna_LayerCollection_name_set(PointerRNA *ptr, const char *value)
+{
+ ID *owner_id = (ID *)ptr->id.data;
+ SceneCollection *sc = ((LayerCollection *)ptr->data)->scene_collection;
+ BKE_collection_rename(owner_id, sc, value);
+}
+
+static PointerRNA rna_LayerCollection_objects_get(CollectionPropertyIterator *iter)
+{
+ ListBaseIterator *internal = &iter->internal.listbase;
+ Base *base = ((LinkData *)internal->link)->data;
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
+}
+
+static int rna_LayerCollection_move_above(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
+{
+ if (!BKE_layer_collection_move_above(id, lc_dst, lc_src)) {
+ return 0;
+ }
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return 1;
+}
+
+static int rna_LayerCollection_move_below(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
+{
+ if (!BKE_layer_collection_move_below(id, lc_dst, lc_src)) {
+ return 0;
+ }
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return 1;
+}
+
+static int rna_LayerCollection_move_into(ID *id, LayerCollection *lc_src, Main *bmain, LayerCollection *lc_dst)
+{
+ if (!BKE_layer_collection_move_into(id, lc_dst, lc_src)) {
+ return 0;
+ }
+
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return 1;
+}
+
+static void rna_LayerCollection_flag_update(bContext *C, PointerRNA *ptr)
+{
+ ID *id = ptr->id.data;
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+ WM_event_add_notifier(C, NC_SCENE | ND_OB_SELECT, CTX_data_scene(C));
+}
+
+static Group *rna_LayerCollection_create_group(
+ ID *id, LayerCollection *layer_collection, Main *bmain, bContext *C, ReportList *reports)
+{
+ Group *group;
+ Scene *scene = (Scene *)id;
+ SceneCollection *scene_collection = layer_collection->scene_collection;
+
+ /* The master collection can't be converted. */
+ if (scene_collection == BKE_collection_master(&scene->id)) {
+ BKE_report(reports, RPT_ERROR, "The master collection can't be converted to group");
+ return NULL;
+ }
+
+ group = BKE_collection_group_create(bmain, scene, layer_collection);
+ if (group == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Failed to convert collection %s", scene_collection->name);
+ return NULL;
+ }
+
+ DEG_relations_tag_update(bmain);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(&scene->id, 0);
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, scene);
+ return group;
+}
+
+static LayerCollection *rna_LayerCollection_duplicate(
+ ID *id, LayerCollection *layer_collection, Main *bmain, bContext *C, ReportList *reports)
+{
+ if (layer_collection->scene_collection == BKE_collection_master(id)) {
+ BKE_report(reports, RPT_ERROR, "The master collection can't be duplicated");
+ return NULL;
+ }
+
+ LayerCollection *layer_collection_new = BKE_layer_collection_duplicate(id, layer_collection);
+
+ DEG_relations_tag_update(bmain);
+ /* Don't use id here, since the layer collection may come from a group. */
+ WM_event_add_notifier(C, NC_SCENE | ND_LAYER, CTX_data_scene(C));
+
+ return layer_collection_new;
+}
+
+static int rna_LayerCollections_active_collection_index_get(PointerRNA *ptr)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ return view_layer->active_collection;
+}
+
+static void rna_LayerCollections_active_collection_index_set(PointerRNA *ptr, int value)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ int num_collections = BKE_layer_collection_count(view_layer);
+ view_layer->active_collection = min_ff(value, num_collections - 1);
+}
+
+static void rna_LayerCollections_active_collection_index_range(
+ PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ *min = 0;
+ *max = max_ii(0, BKE_layer_collection_count(view_layer) - 1);
+}
+
+static PointerRNA rna_LayerCollections_active_collection_get(PointerRNA *ptr)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ LayerCollection *lc = BKE_layer_collection_get_active(view_layer);
+ return rna_pointer_inherit_refine(ptr, &RNA_LayerCollection, lc);
+}
+
+static void rna_LayerCollections_active_collection_set(PointerRNA *ptr, PointerRNA value)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ LayerCollection *lc = (LayerCollection *)value.data;
+ const int index = BKE_layer_collection_findindex(view_layer, lc);
+ if (index != -1) view_layer->active_collection = index;
+}
+
+LayerCollection * rna_ViewLayer_collection_link(
+ ID *id, ViewLayer *view_layer, Main *bmain, SceneCollection *sc)
+{
+ Scene *scene = (Scene *)id;
+ LayerCollection *lc = BKE_collection_link(view_layer, sc);
+
+ DEG_relations_tag_update(bmain);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, scene);
+
+ return lc;
+}
+
+static void rna_ViewLayer_collection_unlink(
+ ID *id, ViewLayer *view_layer, Main *bmain, ReportList *reports, LayerCollection *lc)
+{
+ Scene *scene = (Scene *)id;
+
+ if (BLI_findindex(&view_layer->layer_collections, lc) == -1) {
+ BKE_reportf(reports, RPT_ERROR, "Layer collection '%s' is not in '%s'",
+ lc->scene_collection->name, view_layer->name);
+ return;
+ }
+
+ BKE_collection_unlink(view_layer, lc);
+
+ DEG_relations_tag_update(bmain);
+ /* TODO(sergey): Use proper flag for tagging here. */
+ DEG_id_tag_update(id, 0);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER | ND_OB_ACTIVE, scene);
+}
+
+static PointerRNA rna_LayerObjects_active_object_get(PointerRNA *ptr)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_Object, view_layer->basact ? view_layer->basact->object : NULL);
+}
+
+static void rna_LayerObjects_active_object_set(PointerRNA *ptr, PointerRNA value)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ if (value.data)
+ view_layer->basact = BKE_view_layer_base_find(view_layer, (Object *)value.data);
+ else
+ view_layer->basact = NULL;
+}
+
+static char *rna_ViewLayer_path(PointerRNA *ptr)
+{
+ ViewLayer *srl = (ViewLayer *)ptr->data;
+ char name_esc[sizeof(srl->name) * 2];
+
+ BLI_strescape(name_esc, srl->name, sizeof(name_esc));
+ return BLI_sprintfN("view_layers[\"%s\"]", name_esc);
+}
+
+static IDProperty *rna_ViewLayer_idprops(PointerRNA *ptr, bool create)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+
+ if (create && !view_layer->id_properties) {
+ IDPropertyTemplate val = {0};
+ view_layer->id_properties = IDP_New(IDP_GROUP, &val, "ViewLayer ID properties");
+ }
+
+ return view_layer->id_properties;
+}
+
+static void rna_ViewLayer_update_render_passes(ID *id)
+{
+ Scene *scene = (Scene *)id;
+ if (scene->nodetree)
+ ntreeCompositUpdateRLayers(scene->nodetree);
+}
+
+static PointerRNA rna_ViewLayer_objects_get(CollectionPropertyIterator *iter)
+{
+ ListBaseIterator *internal = &iter->internal.listbase;
+
+ /* we are actually iterating a ObjectBase list, so override get */
+ Base *base = (Base *)internal->link;
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, base->object);
+}
+
+static int rna_ViewLayer_objects_selected_skip(CollectionPropertyIterator *iter, void *UNUSED(data))
+{
+ ListBaseIterator *internal = &iter->internal.listbase;
+ Base *base = (Base *)internal->link;
+
+ if ((base->flag & BASE_SELECTED) != 0) {
+ return 0;
+ }
+
+ return 1;
+};
+
+static PointerRNA rna_ViewLayer_depsgraph_get(PointerRNA *ptr)
+{
+ ID *id = ptr->id.data;
+ if (GS(id->name) == ID_SCE) {
+ Scene *scene = (Scene *)id;
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, false);
+ return rna_pointer_inherit_refine(ptr, &RNA_Depsgraph, depsgraph);
+ }
+ return PointerRNA_NULL;
+}
+
+static void rna_LayerObjects_selected_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ rna_iterator_listbase_begin(iter, &view_layer->object_bases, rna_ViewLayer_objects_selected_skip);
+}
+
+static void rna_ViewLayer_update_tagged(ViewLayer *UNUSED(view_layer), bContext *C)
+{
+ Depsgraph *graph = CTX_data_depsgraph(C);
+ DEG_OBJECT_ITER_BEGIN(
+ graph, ob, DEG_ITER_OBJECT_MODE_VIEWPORT,
+ DEG_ITER_OBJECT_FLAG_LINKED_DIRECTLY |
+ DEG_ITER_OBJECT_FLAG_LINKED_VIA_SET |
+ DEG_ITER_OBJECT_FLAG_LINKED_INDIRECTLY |
+ DEG_ITER_OBJECT_FLAG_VISIBLE |
+ DEG_ITER_OBJECT_FLAG_DUPLI)
+ {
+ /* Don't do anything, we just need to run the iterator to flush
+ * the base info to the objects. */
+ UNUSED_VARS(ob);
+ }
+ DEG_OBJECT_ITER_END;
+}
+
+static void rna_ObjectBase_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ Base *base = (Base *)ptr->data;
+ short mode = (base->flag & BASE_SELECTED) ? BA_SELECT : BA_DESELECT;
+ ED_object_base_select(base, mode);
+}
+
+#else
+
+static void rna_def_scene_collections(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "SceneCollections");
+ srna = RNA_def_struct(brna, "SceneCollections", NULL);
+ RNA_def_struct_sdna(srna, "SceneCollection");
+ RNA_def_struct_ui_text(srna, "Scene Collection", "Collection of scene collections");
+
+ func = RNA_def_function(srna, "new", "rna_SceneCollection_new");
+ RNA_def_function_ui_description(func, "Add a collection to scene");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_string(func, "name", NULL, 0, "", "New name for the collection (not unique)");
+ parm = RNA_def_pointer(func, "result", "SceneCollection", "", "Newly created collection");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_SceneCollection_remove");
+ RNA_def_function_ui_description(func, "Remove a collection and move its objects to the master collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "collection", "SceneCollection", "", "Collection to remove");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+}
+
+static void rna_def_collection_objects(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+ PropertyRNA *prop;
+
+ RNA_def_property_srna(cprop, "CollectionObjects");
+ srna = RNA_def_struct(brna, "CollectionObjects", NULL);
+ RNA_def_struct_sdna(srna, "SceneCollection");
+ RNA_def_struct_ui_text(srna, "Collection Objects", "Objects of a collection");
+
+ prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_funcs(prop, "rna_SceneCollection_objects_active_index_get",
+ "rna_SceneCollection_objects_active_index_set",
+ "rna_SceneCollection_objects_active_index_range");
+ RNA_def_property_ui_text(prop, "Active Object Index", "Active index in collection objects array");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL);
+
+ func = RNA_def_function(srna, "link", "rna_SceneCollection_object_link");
+ RNA_def_function_ui_description(func, "Link an object to collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "object", "Object", "", "Object to add to collection");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "unlink", "rna_SceneCollection_object_unlink");
+ RNA_def_function_ui_description(func, "Unlink object from collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove from collection");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+}
+
+static void rna_def_scene_collection(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ srna = RNA_def_struct(brna, "SceneCollection", NULL);
+ RNA_def_struct_ui_text(srna, "Scene Collection", "Collection");
+ RNA_def_struct_ui_icon(srna, ICON_COLLAPSEMENU);
+ RNA_def_struct_refine_func(srna, "rna_SceneCollection_refine");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_SceneCollection_name_set");
+ RNA_def_property_ui_text(prop, "Name", "Collection name");
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL);
+
+ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, rna_enum_collection_type_items);
+ RNA_def_property_ui_text(prop, "Type", "Type of collection");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "scene_collections", NULL);
+ RNA_def_property_struct_type(prop, "SceneCollection");
+ RNA_def_property_ui_text(prop, "SceneCollections", "");
+ rna_def_scene_collections(brna, prop);
+
+ prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "objects", NULL);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_SceneCollection_objects_get", NULL, NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Objects", "All the objects directly added to this collection (not including sub-collection objects)");
+ rna_def_collection_objects(brna, prop);
+
+ /* Functions */
+ func = RNA_def_function(srna, "move_above", "rna_SceneCollection_move_above");
+ RNA_def_function_ui_description(func, "Move collection after another");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "sc_dst", "SceneCollection", "Collection", "Reference collection above which the collection will move");
+ parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "move_below", "rna_SceneCollection_move_below");
+ RNA_def_function_ui_description(func, "Move collection before another");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "sc_dst", "SceneCollection", "Collection", "Reference collection below which the collection will move");
+ parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "move_into", "rna_SceneCollection_move_into");
+ RNA_def_function_ui_description(func, "Move collection into another");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "sc_dst", "SceneCollection", "Collection", "Collection to insert into");
+ parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "duplicate", "rna_SceneCollection_duplicate");
+ RNA_def_function_ui_description(func, "Create a copy of the collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "result", "SceneCollection", "", "Newly created collection");
+ RNA_def_function_return(func, parm);
+}
+
+static void rna_def_layer_collection_override(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "LayerCollectionOverride", NULL);
+ RNA_def_struct_sdna(srna, "CollectionOverride");
+ RNA_def_struct_ui_text(srna, "Collection Override", "Collection Override");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Name", "Collection name");
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL);
+}
+
+
+#ifdef WITH_CLAY_ENGINE
+static void rna_def_view_layer_engine_settings_clay(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "ViewLayerEngineSettingsClay", "ViewLayerSettings");
+ RNA_def_struct_ui_text(srna, "Clay Scene Layer Settings", "Clay Engine settings");
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+
+ /* see RNA_LAYER_ENGINE_GET_SET macro */
+ prop = RNA_def_property(srna, "ssao_samples", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Clay_ssao_samples_get",
+ "rna_LayerEngineSettings_Clay_ssao_samples_set", NULL);
+ RNA_def_property_ui_text(prop, "Samples", "Number of samples");
+ RNA_def_property_range(prop, 1, 500);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+}
+#endif /* WITH_CLAY_ENGINE */
+
+static void rna_def_view_layer_engine_settings_eevee(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ /* Keep in sync with eevee_private.h */
+ static const EnumPropertyItem eevee_shadow_method_items[] = {
+ {1, "ESM", 0, "ESM", "Exponential Shadow Mapping"},
+ {2, "VSM", 0, "VSM", "Variance Shadow Mapping"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static const EnumPropertyItem eevee_shadow_size_items[] = {
+ {64, "64", 0, "64px", ""},
+ {128, "128", 0, "128px", ""},
+ {256, "256", 0, "256px", ""},
+ {512, "512", 0, "512px", ""},
+ {1024, "1024", 0, "1024px", ""},
+ {2048, "2048", 0, "2048px", ""},
+ {4096, "4096", 0, "4096px", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static const EnumPropertyItem eevee_gi_visibility_size_items[] = {
+ {8, "8", 0, "8px", ""},
+ {16, "16", 0, "16px", ""},
+ {32, "32", 0, "32px", ""},
+ {64, "64", 0, "64px", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static const EnumPropertyItem eevee_volumetric_tile_size_items[] = {
+ {2, "2", 0, "2px", ""},
+ {4, "4", 0, "4px", ""},
+ {8, "8", 0, "8px", ""},
+ {16, "16", 0, "16px", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ srna = RNA_def_struct(brna, "ViewLayerEngineSettingsEevee", "ViewLayerSettings");
+ RNA_def_struct_ui_text(srna, "Eevee Scene Layer Settings", "Eevee Engine settings");
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+
+ /* see RNA_LAYER_ENGINE_GET_SET macro */
+
+ /* Indirect Lighting */
+ prop = RNA_def_property(srna, "gi_diffuse_bounces", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_gi_diffuse_bounces_get",
+ "rna_LayerEngineSettings_Eevee_gi_diffuse_bounces_set", NULL);
+ RNA_def_property_ui_text(prop, "Diffuse Bounces", "Number of time the light is reinjected inside light grids, "
+ "0 disable indirect diffuse light");
+ RNA_def_property_range(prop, 0, INT_MAX);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "gi_cubemap_resolution", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Eevee_gi_cubemap_resolution_get",
+ "rna_LayerEngineSettings_Eevee_gi_cubemap_resolution_set", NULL);
+ RNA_def_property_enum_items(prop, eevee_shadow_size_items);
+ RNA_def_property_ui_text(prop, "Cubemap Size", "Size of every cubemaps");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "gi_visibility_resolution", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Eevee_gi_visibility_resolution_get",
+ "rna_LayerEngineSettings_Eevee_gi_visibility_resolution_set", NULL);
+ RNA_def_property_enum_items(prop, eevee_gi_visibility_size_items);
+ RNA_def_property_ui_text(prop, "Irradiance Visibility Size",
+ "Size of the shadow map applied to each irradiance sample");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Temporal Anti-Aliasing (super sampling) */
+ prop = RNA_def_property(srna, "taa_samples", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_taa_samples_get",
+ "rna_LayerEngineSettings_Eevee_taa_samples_set", NULL);
+ RNA_def_property_ui_text(prop, "Viewport Samples", "Number of samples, unlimited if 0");
+ RNA_def_property_range(prop, 0, INT_MAX);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "taa_render_samples", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_taa_render_samples_get",
+ "rna_LayerEngineSettings_Eevee_taa_render_samples_set", NULL);
+ RNA_def_property_ui_text(prop, "Render Samples", "Number of samples per pixels for rendering");
+ RNA_def_property_range(prop, 1, INT_MAX);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "taa_reprojection", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_taa_reprojection_get",
+ "rna_LayerEngineSettings_Eevee_taa_reprojection_set");
+ RNA_def_property_ui_text(prop, "Viewport Denoising", "Denoise image using temporal reprojection "
+ "(can leave some ghosting)");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Screen Space Subsurface Scattering */
+ prop = RNA_def_property(srna, "sss_enable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_sss_enable_get",
+ "rna_LayerEngineSettings_Eevee_sss_enable_set");
+ RNA_def_property_ui_text(prop, "Subsurface Scattering", "Enable screen space subsurface scattering");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "sss_samples", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_sss_samples_get",
+ "rna_LayerEngineSettings_Eevee_sss_samples_set", NULL);
+ RNA_def_property_ui_text(prop, "Samples", "Number of samples to compute the scattering effect");
+ RNA_def_property_range(prop, 1, 32);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "sss_jitter_threshold", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_sss_jitter_threshold_get",
+ "rna_LayerEngineSettings_Eevee_sss_jitter_threshold_set", NULL);
+ RNA_def_property_ui_text(prop, "Jitter Threshold", "Rotate samples that are below this threshold");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "sss_separate_albedo", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_sss_separate_albedo_get",
+ "rna_LayerEngineSettings_Eevee_sss_separate_albedo_set");
+ RNA_def_property_ui_text(prop, "Separate Albedo", "Avoid albedo being blured by the subsurface scattering "
+ "but uses more video memory");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Screen Space Reflection */
+ prop = RNA_def_property(srna, "ssr_enable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_enable_get",
+ "rna_LayerEngineSettings_Eevee_ssr_enable_set");
+ RNA_def_property_ui_text(prop, "Screen Space Reflections", "Enable screen space reflection");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssr_refraction", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_refraction_get",
+ "rna_LayerEngineSettings_Eevee_ssr_refraction_set");
+ RNA_def_property_ui_text(prop, "Screen Space Refractions", "Enable screen space Refractions");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssr_halfres", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_halfres_get",
+ "rna_LayerEngineSettings_Eevee_ssr_halfres_set");
+ RNA_def_property_ui_text(prop, "Half Res Trace", "Raytrace at a lower resolution");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssr_quality", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_quality_get",
+ "rna_LayerEngineSettings_Eevee_ssr_quality_set", NULL);
+ RNA_def_property_ui_text(prop, "Trace Quality", "Quality of the screen space raytracing");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssr_max_roughness", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_max_roughness_get",
+ "rna_LayerEngineSettings_Eevee_ssr_max_roughness_set", NULL);
+ RNA_def_property_ui_text(prop, "Max Roughness", "Do not raytrace reflections for roughness above this value");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssr_thickness", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_thickness_get",
+ "rna_LayerEngineSettings_Eevee_ssr_thickness_set", NULL);
+ RNA_def_property_ui_text(prop, "Thickness", "Pixel thickness used to detect intersection");
+ RNA_def_property_range(prop, 1e-6f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 5, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssr_border_fade", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_border_fade_get",
+ "rna_LayerEngineSettings_Eevee_ssr_border_fade_set", NULL);
+ RNA_def_property_ui_text(prop, "Edge Fading", "Screen percentage used to fade the SSR");
+ RNA_def_property_range(prop, 0.0f, 0.5f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssr_firefly_fac", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_ssr_firefly_fac_get",
+ "rna_LayerEngineSettings_Eevee_ssr_firefly_fac_set", NULL);
+ RNA_def_property_ui_text(prop, "Clamp", "Clamp pixel intensity to remove noise (0 to disabled)");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Volumetrics */
+ prop = RNA_def_property(srna, "volumetric_enable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_enable_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_enable_set");
+ RNA_def_property_ui_text(prop, "Volumetrics", "Enable scattering and absorbance of volumetric material");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_start", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_start_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_start_set", NULL);
+ RNA_def_property_ui_text(prop, "Start", "Start distance of the volumetric effect");
+ RNA_def_property_range(prop, 1e-6f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_end", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_end_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_end_set", NULL);
+ RNA_def_property_ui_text(prop, "End", "End distance of the volumetric effect");
+ RNA_def_property_range(prop, 1e-6f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_tile_size", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_tile_size_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_tile_size_set", NULL);
+ RNA_def_property_enum_items(prop, eevee_volumetric_tile_size_items);
+ RNA_def_property_ui_text(prop, "Tile Size", "Control the quality of the volumetric effects "
+ "(lower size increase vram usage and quality)");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_samples", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_samples_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_samples_set", NULL);
+ RNA_def_property_ui_text(prop, "Samples", "Number of samples to compute volumetric effects");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_range(prop, 1, 256);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_sample_distribution", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_sample_distribution_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_sample_distribution_set", NULL);
+ RNA_def_property_ui_text(prop, "Exponential Sampling", "Distribute more samples closer to the camera");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_lights", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_lights_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_lights_set");
+ RNA_def_property_ui_text(prop, "Volumetric Lighting", "Enable scene lamps interactions with volumetrics");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_light_clamp", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_light_clamp_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_light_clamp_set", NULL);
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_text(prop, "Clamp", "Maximum light contribution, reducing noise");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_shadows", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_shadows_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_shadows_set");
+ RNA_def_property_ui_text(prop, "Volumetric Shadows", "Generate shadows from volumetric material (Very expensive)");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_shadow_samples", PROP_INT, PROP_NONE);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_shadow_samples_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_shadow_samples_set", NULL);
+ RNA_def_property_range(prop, 1, 128);
+ RNA_def_property_ui_text(prop, "Volumetric Shadow Samples", "Number of samples to compute volumetric shadowing");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "volumetric_colored_transmittance", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_volumetric_colored_transmittance_get",
+ "rna_LayerEngineSettings_Eevee_volumetric_colored_transmittance_set");
+ RNA_def_property_ui_text(prop, "Colored Transmittance", "Enable wavelength dependent volumetric transmittance");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Ambient Occlusion */
+ prop = RNA_def_property(srna, "gtao_enable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_enable_get",
+ "rna_LayerEngineSettings_Eevee_gtao_enable_set");
+ RNA_def_property_ui_text(prop, "Ambient Occlusion", "Enable ambient occlusion to simulate medium scale indirect shadowing");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "gtao_use_bent_normals", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_use_bent_normals_get",
+ "rna_LayerEngineSettings_Eevee_gtao_use_bent_normals_set");
+ RNA_def_property_ui_text(prop, "Bent Normals", "Compute main non occluded direction to sample the environment");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "gtao_bounce", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_bounce_get",
+ "rna_LayerEngineSettings_Eevee_gtao_bounce_set");
+ RNA_def_property_ui_text(prop, "Bounces Approximation", "An approximation to simulate light bounces "
+ "giving less occlusion on brighter objects");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "gtao_factor", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_factor_get", "rna_LayerEngineSettings_Eevee_gtao_factor_set", NULL);
+ RNA_def_property_ui_text(prop, "Factor", "Factor for ambient occlusion blending");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.1f, 2);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "gtao_quality", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_quality_get", "rna_LayerEngineSettings_Eevee_gtao_quality_set", NULL);
+ RNA_def_property_ui_text(prop, "Trace Quality", "Quality of the horizon search");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "gtao_distance", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_gtao_distance_get", "rna_LayerEngineSettings_Eevee_gtao_distance_set", NULL);
+ RNA_def_property_ui_text(prop, "Distance", "Distance of object that contribute to the ambient occlusion effect");
+ RNA_def_property_range(prop, 0.0f, 100000.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ /* Depth of Field */
+ prop = RNA_def_property(srna, "dof_enable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_dof_enable_get",
+ "rna_LayerEngineSettings_Eevee_dof_enable_set");
+ RNA_def_property_ui_text(prop, "Depth of Field", "Enable depth of field using the values from the active camera");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bokeh_max_size", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bokeh_max_size_get",
+ "rna_LayerEngineSettings_Eevee_bokeh_max_size_set", NULL);
+ RNA_def_property_ui_text(prop, "Max Size", "Max size of the bokeh shape for the depth of field (lower is faster)");
+ RNA_def_property_range(prop, 0.0f, 2000.0f);
+ RNA_def_property_ui_range(prop, 2.0f, 200.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bokeh_threshold", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bokeh_threshold_get",
+ "rna_LayerEngineSettings_Eevee_bokeh_threshold_set", NULL);
+ RNA_def_property_ui_text(prop, "Sprite Threshold", "Brightness threshold for using sprite base depth of field");
+ RNA_def_property_range(prop, 0.0f, 100000.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Bloom */
+ prop = RNA_def_property(srna, "bloom_enable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_bloom_enable_get",
+ "rna_LayerEngineSettings_Eevee_bloom_enable_set");
+ RNA_def_property_ui_text(prop, "Bloom", "High brighness pixels generate a glowing effect");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bloom_threshold", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bloom_threshold_get",
+ "rna_LayerEngineSettings_Eevee_bloom_threshold_set", NULL);
+ RNA_def_property_ui_text(prop, "Threshold", "Filters out pixels under this level of brightness");
+ RNA_def_property_range(prop, 0.0f, 100000.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bloom_color", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bloom_color_get",
+ "rna_LayerEngineSettings_Eevee_bloom_color_set", NULL);
+ RNA_def_property_ui_text(prop, "Color", "Color applied to the bloom effect");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bloom_knee", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bloom_knee_get",
+ "rna_LayerEngineSettings_Eevee_bloom_knee_set", NULL);
+ RNA_def_property_ui_text(prop, "Knee", "Makes transition between under/over-threshold gradual");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bloom_radius", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bloom_radius_get",
+ "rna_LayerEngineSettings_Eevee_bloom_radius_set", NULL);
+ RNA_def_property_ui_text(prop, "Radius", "Bloom spread distance");
+ RNA_def_property_range(prop, 0.0f, 100.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bloom_clamp", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bloom_clamp_get",
+ "rna_LayerEngineSettings_Eevee_bloom_clamp_set", NULL);
+ RNA_def_property_ui_text(prop, "Clamp", "Maximum intensity a bloom pixel can have");
+ RNA_def_property_range(prop, 0.0f, 1000.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "bloom_intensity", PROP_FLOAT, PROP_UNSIGNED);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_bloom_intensity_get",
+ "rna_LayerEngineSettings_Eevee_bloom_intensity_set", NULL);
+ RNA_def_property_ui_text(prop, "Intensity", "Blend factor");
+ RNA_def_property_range(prop, 0.0f, 10000.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Motion blur */
+ prop = RNA_def_property(srna, "motion_blur_enable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_motion_blur_enable_get",
+ "rna_LayerEngineSettings_Eevee_motion_blur_enable_set");
+ RNA_def_property_ui_text(prop, "Motion Blur", "Enable motion blur effect (only in camera view)");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "motion_blur_samples", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_funcs(prop, "rna_LayerEngineSettings_Eevee_motion_blur_samples_get",
+ "rna_LayerEngineSettings_Eevee_motion_blur_samples_set", NULL);
+ RNA_def_property_ui_text(prop, "Samples", "Number of samples to take with motion blur");
+ RNA_def_property_range(prop, 1, 64);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "motion_blur_shutter", PROP_FLOAT, PROP_UNSIGNED);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Eevee_motion_blur_shutter_get",
+ "rna_LayerEngineSettings_Eevee_motion_blur_shutter_set", NULL);
+ RNA_def_property_ui_text(prop, "Shutter", "Time taken in frames between shutter open and close");
+ RNA_def_property_ui_range(prop, 0.01f, 2.0f, 1, 2);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ /* Shadows */
+ prop = RNA_def_property(srna, "shadow_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Eevee_shadow_method_get", "rna_LayerEngineSettings_Eevee_shadow_method_set", NULL);
+ RNA_def_property_enum_items(prop, eevee_shadow_method_items);
+ RNA_def_property_ui_text(prop, "Method", "Technique use to compute the shadows");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "shadow_cube_size", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Eevee_shadow_cube_size_get", "rna_LayerEngineSettings_Eevee_shadow_cube_size_set", NULL);
+ RNA_def_property_enum_items(prop, eevee_shadow_size_items);
+ RNA_def_property_ui_text(prop, "Cube Shadows Resolution", "Size of point and area lamps shadow maps");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "shadow_cascade_size", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Eevee_shadow_cascade_size_get", "rna_LayerEngineSettings_Eevee_shadow_cascade_size_set", NULL);
+ RNA_def_property_enum_items(prop, eevee_shadow_size_items);
+ RNA_def_property_ui_text(prop, "Directional Shadows Resolution", "Size of sun lamps shadow maps");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ prop = RNA_def_property(srna, "shadow_high_bitdepth", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_LayerEngineSettings_Eevee_shadow_high_bitdepth_get", "rna_LayerEngineSettings_Eevee_shadow_high_bitdepth_set");
+ RNA_def_property_ui_text(prop, "High Bitdepth", "Use 32bit shadows");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+}
+
+#ifdef WITH_CLAY_ENGINE
+static void rna_def_layer_collection_engine_settings_clay(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ static const EnumPropertyItem clay_matcap_items[] = {
+ {ICON_MATCAP_01, "01", ICON_MATCAP_01, "", ""},
+ {ICON_MATCAP_02, "02", ICON_MATCAP_02, "", ""},
+ {ICON_MATCAP_03, "03", ICON_MATCAP_03, "", ""},
+ {ICON_MATCAP_04, "04", ICON_MATCAP_04, "", ""},
+ {ICON_MATCAP_05, "05", ICON_MATCAP_05, "", ""},
+ {ICON_MATCAP_06, "06", ICON_MATCAP_06, "", ""},
+ {ICON_MATCAP_07, "07", ICON_MATCAP_07, "", ""},
+ {ICON_MATCAP_08, "08", ICON_MATCAP_08, "", ""},
+ {ICON_MATCAP_09, "09", ICON_MATCAP_09, "", ""},
+ {ICON_MATCAP_10, "10", ICON_MATCAP_10, "", ""},
+ {ICON_MATCAP_11, "11", ICON_MATCAP_11, "", ""},
+ {ICON_MATCAP_12, "12", ICON_MATCAP_12, "", ""},
+ {ICON_MATCAP_13, "13", ICON_MATCAP_13, "", ""},
+ {ICON_MATCAP_14, "14", ICON_MATCAP_14, "", ""},
+ {ICON_MATCAP_15, "15", ICON_MATCAP_15, "", ""},
+ {ICON_MATCAP_16, "16", ICON_MATCAP_16, "", ""},
+ {ICON_MATCAP_17, "17", ICON_MATCAP_17, "", ""},
+ {ICON_MATCAP_18, "18", ICON_MATCAP_18, "", ""},
+ {ICON_MATCAP_19, "19", ICON_MATCAP_19, "", ""},
+ {ICON_MATCAP_20, "20", ICON_MATCAP_20, "", ""},
+ {ICON_MATCAP_21, "21", ICON_MATCAP_21, "", ""},
+ {ICON_MATCAP_22, "22", ICON_MATCAP_22, "", ""},
+ {ICON_MATCAP_23, "23", ICON_MATCAP_23, "", ""},
+ {ICON_MATCAP_24, "24", ICON_MATCAP_24, "", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ srna = RNA_def_struct(brna, "LayerCollectionEngineSettingsClay", "LayerCollectionSettings");
+ RNA_def_struct_ui_text(srna, "Collections Clay Engine Settings", "Engine specific settings for this collection");
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+
+ /* see RNA_LAYER_ENGINE_GET_SET macro */
+ prop = RNA_def_property(srna, "matcap_icon", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_funcs(prop, "rna_LayerEngineSettings_Clay_matcap_icon_get", "rna_LayerEngineSettings_Clay_matcap_icon_set", NULL);
+ RNA_def_property_enum_items(prop, clay_matcap_items);
+ RNA_def_property_ui_text(prop, "Matcap", "Image to use for Material Capture by this material");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "matcap_rotation", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_matcap_rotation_get", "rna_LayerEngineSettings_Clay_matcap_rotation_set", NULL);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Matcap Rotation", "Orientation of the matcap on the model");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "matcap_hue", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_matcap_hue_get", "rna_LayerEngineSettings_Clay_matcap_hue_set", NULL);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Matcap Hue Shift", "Hue correction of the matcap");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "matcap_saturation", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_matcap_saturation_get", "rna_LayerEngineSettings_Clay_matcap_saturation_set", NULL);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Matcap Saturation", "Saturation correction of the matcap");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "matcap_value", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_matcap_value_get", "rna_LayerEngineSettings_Clay_matcap_value_set", NULL);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Matcap Value", "Value correction of the matcap");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssao_factor_cavity", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_ssao_factor_cavity_get", "rna_LayerEngineSettings_Clay_ssao_factor_cavity_set", NULL);
+ RNA_def_property_ui_text(prop, "Cavity Strength", "Strength of the Cavity effect");
+ RNA_def_property_range(prop, 0.0f, 250.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssao_factor_edge", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_ssao_factor_edge_get", "rna_LayerEngineSettings_Clay_ssao_factor_edge_set", NULL);
+ RNA_def_property_ui_text(prop, "Edge Strength", "Strength of the Edge effect");
+ RNA_def_property_range(prop, 0.0f, 250.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssao_distance", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_ssao_distance_get", "rna_LayerEngineSettings_Clay_ssao_distance_set", NULL);
+ RNA_def_property_ui_text(prop, "Distance", "Distance of object that contribute to the Cavity/Edge effect");
+ RNA_def_property_range(prop, 0.0f, 100000.0f);
+ RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "ssao_attenuation", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_ssao_attenuation_get", "rna_LayerEngineSettings_Clay_ssao_attenuation_set", NULL);
+ RNA_def_property_ui_text(prop, "Attenuation", "Attenuation constant");
+ RNA_def_property_range(prop, 1.0f, 100000.0f);
+ RNA_def_property_ui_range(prop, 1.0f, 100.0f, 1, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "hair_brightness_randomness", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Clay_hair_brightness_randomness_get", "rna_LayerEngineSettings_Clay_hair_brightness_randomness_set", NULL);
+ RNA_def_property_ui_text(prop, "Hair Brightness Randomness", "Brightness randomness for hair");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+}
+#endif /* WITH_CLAY_ENGINE */
+
+/* Workbench engine */
+static void rna_def_view_layer_engine_settings_workbench(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "ViewLayerEngineSettingsWorkbench", "ViewLayerSettings");
+ RNA_def_struct_ui_text(srna, "Workbench Scene Layer Settings", "Workbench Engine settings");
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+ prop = RNA_def_property(srna, "light_direction", PROP_FLOAT, PROP_DIRECTION);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Workbench_light_direction_get", "rna_LayerEngineSettings_Workbench_light_direction_set", NULL);
+ RNA_def_property_ui_text(prop, "Light Direction", "Direction of the light for shadow calculation");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_ViewLayerEngineSettings_update");
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+}
+
+static void rna_def_layer_collection_engine_settings_workbench(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "LayerCollectionEngineSettingsWorkbench", "LayerCollectionSettings");
+ RNA_def_struct_ui_text(srna, "Collections Workbench Engine Settings", "Workbench specific settings for this collection");
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+
+ prop = RNA_def_property(srna, "random_object_color_saturation", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Workbench_random_object_color_saturation_get", "rna_LayerEngineSettings_Workbench_random_object_color_saturation_set", NULL);
+ RNA_def_property_ui_text(prop, "Random Saturation", "Random Object Color Saturation");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ prop = RNA_def_property(srna, "random_object_color_value", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_funcs(prop, "rna_LayerEngineSettings_Workbench_random_object_color_value_get", "rna_LayerEngineSettings_Workbench_random_object_color_value_set", NULL);
+ RNA_def_property_ui_text(prop, "Random Value", "Random Object Color Value");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_LayerCollectionEngineSettings_update");
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+}
+
+static void rna_def_view_layer_settings(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ srna = RNA_def_struct(brna, "ViewLayerSettings", NULL);
+ RNA_def_struct_sdna(srna, "IDProperty");
+ RNA_def_struct_ui_text(srna, "Scene Layer Settings",
+ "Engine specific settings that can be overriden by ViewLayer");
+ RNA_def_struct_refine_func(srna, "rna_ViewLayerSettings_refine");
+
+ RNA_define_verify_sdna(0);
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_ViewLayerSettings_name_get", "rna_ViewLayerSettings_name_length", NULL);
+ RNA_def_property_ui_text(prop, "Name", "Engine Name");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_struct_name_property(srna, prop);
+
+ func = RNA_def_function(srna, "use", "rna_ViewLayerSettings_use");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+ RNA_def_function_ui_description(func, "Initialize this property to use");
+ parm = RNA_def_string(func, "identifier", NULL, 0, "Property Name", "Name of the property to set");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "unuse", "rna_ViewLayerSettings_unuse");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+ RNA_def_function_ui_description(func, "Remove the property");
+ parm = RNA_def_string(func, "identifier", NULL, 0, "Property Name", "Name of the property to unset");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+#ifdef WITH_CLAY_ENGINE
+ rna_def_view_layer_engine_settings_clay(brna);
+#endif
+ rna_def_view_layer_engine_settings_workbench(brna);
+ rna_def_view_layer_engine_settings_eevee(brna);
+
+ RNA_define_verify_sdna(1);
+}
+
+static void rna_def_layer_collection_settings(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ srna = RNA_def_struct(brna, "LayerCollectionSettings", NULL);
+ RNA_def_struct_sdna(srna, "IDProperty");
+ RNA_def_struct_ui_text(srna, "Layer Collection Settings",
+ "Engine specific settings that can be overriden by LayerCollection");
+ RNA_def_struct_refine_func(srna, "rna_LayerCollectionSettings_refine");
+
+ RNA_define_verify_sdna(0);
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_LayerCollectionSettings_name_get", "rna_LayerCollectionSettings_name_length", NULL);
+ RNA_def_property_ui_text(prop, "Name", "Engine Name");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_struct_name_property(srna, prop);
+
+ func = RNA_def_function(srna, "use", "rna_LayerCollectionSettings_use");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+ RNA_def_function_ui_description(func, "Initialize this property to use");
+ parm = RNA_def_string(func, "identifier", NULL, 0, "Property Name", "Name of the property to set");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "unuse", "rna_LayerCollectionSettings_unuse");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+ RNA_def_function_ui_description(func, "Remove the property");
+ parm = RNA_def_string(func, "identifier", NULL, 0, "Property Name", "Name of the property to unset");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+#ifdef WITH_CLAY_ENGINE
+ rna_def_layer_collection_engine_settings_clay(brna);
+#endif
+
+ rna_def_layer_collection_engine_settings_workbench(brna);
+
+ RNA_define_verify_sdna(1);
+}
+
+static void rna_def_layer_collection(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ srna = RNA_def_struct(brna, "LayerCollection", NULL);
+ RNA_def_struct_ui_text(srna, "Layer Collection", "Layer collection");
+ RNA_def_struct_ui_icon(srna, ICON_COLLAPSEMENU);
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_LayerCollection_name_get", "rna_LayerCollection_name_length", "rna_LayerCollection_name_set");
+ RNA_def_property_ui_text(prop, "Name", "Collection name");
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, NULL);
+
+ prop = RNA_def_property(srna, "collection", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_pointer_sdna(prop, NULL, "scene_collection");
+ RNA_def_property_struct_type(prop, "SceneCollection");
+ RNA_def_property_ui_text(prop, "Collection", "Collection this layer collection is wrapping");
+
+ prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "layer_collections", NULL);
+ RNA_def_property_struct_type(prop, "LayerCollection");
+ RNA_def_property_ui_text(prop, "Layer Collections", "");
+
+ prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_LayerCollection_objects_get", NULL, NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Objects", "All the objects directly or indirectly added to this collection (not including sub-collection objects)");
+
+ prop = RNA_def_property(srna, "overrides", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "overrides", NULL);
+ RNA_def_property_struct_type(prop, "LayerCollectionOverride");
+ RNA_def_property_ui_text(prop, "Collection Overrides", "");
+
+ /* Override settings */
+ prop = RNA_def_property(srna, "engine_overrides", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "properties->data.group", NULL);
+ RNA_def_property_struct_type(prop, "LayerCollectionSettings");
+ RNA_def_property_ui_text(prop, "Collection Settings", "Override of engine specific render settings");
+
+ /* Functions */
+ func = RNA_def_function(srna, "move_above", "rna_LayerCollection_move_above");
+ RNA_def_function_ui_description(func, "Move collection after another");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "lc_dst", "LayerCollection", "Collection", "Reference collection above which the collection will move");
+ parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "move_below", "rna_LayerCollection_move_below");
+ RNA_def_function_ui_description(func, "Move collection before another");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "lc_dst", "LayerCollection", "Collection", "Reference collection below which the collection will move");
+ parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "move_into", "rna_LayerCollection_move_into");
+ RNA_def_function_ui_description(func, "Move collection into another");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "lc_dst", "LayerCollection", "Collection", "Collection to insert into");
+ parm = RNA_def_boolean(func, "result", false, "Result", "Whether the operation succeded");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "create_group", "rna_LayerCollection_create_group");
+ RNA_def_function_ui_description(func, "Enable or disable a collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "result", "Group", "", "Newly created Group");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "duplicate", "rna_LayerCollection_duplicate");
+ RNA_def_function_ui_description(func, "Create a copy of the collection");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "result", "LayerCollection", "", "Newly created collection");
+ RNA_def_function_return(func, parm);
+
+ /* Flags */
+ prop = RNA_def_property(srna, "selectable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", COLLECTION_SELECTABLE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, 1);
+ RNA_def_property_ui_text(prop, "Selectable", "Restrict selection");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_LayerCollection_flag_update");
+
+ prop = RNA_def_property(srna, "visible_viewport", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", COLLECTION_VIEWPORT);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, 1);
+ RNA_def_property_ui_text(prop, "Viewport Visibility", "");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_LayerCollection_flag_update");
+
+ prop = RNA_def_property(srna, "visible_render", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", COLLECTION_RENDER);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
+ RNA_def_property_ui_text(prop, "Render Visibility", "Control");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_LayerCollection_flag_update");
+
+ prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", COLLECTION_DISABLED);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_ui_text(prop, "Enabled", "Enable or disable collection");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER_CONTENT, "rna_LayerCollection_flag_update");
+}
+
+static void rna_def_layer_collections(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ FunctionRNA *func;
+ PropertyRNA *prop;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "LayerCollections");
+ srna = RNA_def_struct(brna, "LayerCollections", NULL);
+ RNA_def_struct_sdna(srna, "ViewLayer");
+ RNA_def_struct_ui_text(srna, "Layer Collections", "Collections of render layer");
+
+ prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_int_sdna(prop, NULL, "active_collection");
+ RNA_def_property_int_funcs(prop, "rna_LayerCollections_active_collection_index_get",
+ "rna_LayerCollections_active_collection_index_set",
+ "rna_LayerCollections_active_collection_index_range");
+ RNA_def_property_ui_text(prop, "Active Collection Index", "Active index in layer collection array");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
+
+ prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "LayerCollection");
+ RNA_def_property_pointer_funcs(prop, "rna_LayerCollections_active_collection_get",
+ "rna_LayerCollections_active_collection_set", NULL, NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
+ RNA_def_property_ui_text(prop, "Active Layer Collection", "Active Layer Collection");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
+
+ func = RNA_def_function(srna, "link", "rna_ViewLayer_collection_link");
+ RNA_def_function_ui_description(func, "Link a collection to render layer");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_pointer(func, "scene_collection", "SceneCollection", "", "Collection to add to render layer");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_pointer(func, "result", "LayerCollection", "", "Newly created layer collection");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "unlink", "rna_ViewLayer_collection_unlink");
+ RNA_def_function_ui_description(func, "Unlink a collection from render layer");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "layer_collection", "LayerCollection", "", "Layer collection to remove from render layer");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+}
+
+static void rna_def_layer_objects(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ RNA_def_property_srna(cprop, "LayerObjects");
+ srna = RNA_def_struct(brna, "LayerObjects", NULL);
+ RNA_def_struct_sdna(srna, "ViewLayer");
+ RNA_def_struct_ui_text(srna, "Layer Objects", "Collections of objects");
+
+ prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_pointer_funcs(prop, "rna_LayerObjects_active_object_get", "rna_LayerObjects_active_object_set", NULL, NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
+ RNA_def_property_ui_text(prop, "Active Object", "Active object for this layer");
+ /* Could call: ED_object_base_activate(C, rl->basact);
+ * but would be a bad level call and it seems the notifier is enough */
+ RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, NULL);
+
+ prop = RNA_def_property(srna, "selected", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_collection_funcs(prop, "rna_LayerObjects_selected_begin", "rna_iterator_listbase_next",
+ "rna_iterator_listbase_end", "rna_ViewLayer_objects_get",
+ NULL, NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Selected Objects", "All the selected objects of this layer");
+}
+
+static void rna_def_object_base(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "ObjectBase", NULL);
+ RNA_def_struct_sdna(srna, "Base");
+ RNA_def_struct_ui_text(srna, "Object Base", "An object instance in a render layer");
+ RNA_def_struct_ui_icon(srna, ICON_OBJECT_DATA);
+
+ prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "object");
+ RNA_def_property_ui_text(prop, "Object", "Object this base links to");
+
+ prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", BASE_SELECTED);
+ RNA_def_property_ui_text(prop, "Select", "Object base selection state");
+ RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ObjectBase_select_update");
+}
+
+void RNA_def_view_layer(BlenderRNA *brna)
+{
+ FunctionRNA *func;
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "ViewLayer", NULL);
+ RNA_def_struct_ui_text(srna, "Render Layer", "Render layer");
+ RNA_def_struct_ui_icon(srna, ICON_RENDER_RESULT);
+ RNA_def_struct_path_func(srna, "rna_ViewLayer_path");
+ RNA_def_struct_idprops_func(srna, "rna_ViewLayer_idprops");
+
+ rna_def_view_layer_common(srna, 1);
+
+ func = RNA_def_function(srna, "update_render_passes", "rna_ViewLayer_update_render_passes");
+ RNA_def_function_ui_description(func, "Requery the enabled render passes from the render engine");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF);
+
+ prop = RNA_def_property(srna, "collections", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "layer_collections", NULL);
+ RNA_def_property_struct_type(prop, "LayerCollection");
+ RNA_def_property_ui_text(prop, "Layer Collections", "");
+ rna_def_layer_collections(brna, prop);
+
+ prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "object_bases", NULL);
+ RNA_def_property_struct_type(prop, "Object");
+ RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_ViewLayer_objects_get", NULL, NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Objects", "All the objects in this layer");
+ rna_def_layer_objects(brna, prop);
+
+ /* layer options */
+ prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", VIEW_LAYER_RENDER);
+ RNA_def_property_ui_text(prop, "Enabled", "Disable or enable the render layer");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
+
+ prop = RNA_def_property(srna, "use_freestyle", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", VIEW_LAYER_FREESTYLE);
+ RNA_def_property_ui_text(prop, "Freestyle", "Render stylized strokes in this Layer");
+ RNA_def_property_update(prop, NC_SCENE | ND_LAYER, NULL);
+
+ /* Freestyle */
+ rna_def_freestyle_settings(brna);
+
+ prop = RNA_def_property(srna, "freestyle_settings", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_pointer_sdna(prop, NULL, "freestyle_config");
+ RNA_def_property_struct_type(prop, "FreestyleSettings");
+ RNA_def_property_ui_text(prop, "Freestyle Settings", "");
+
+ /* Override settings */
+ prop = RNA_def_property(srna, "engine_overrides", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "properties->data.group", NULL);
+ RNA_def_property_struct_type(prop, "ViewLayerSettings");
+ RNA_def_property_ui_text(prop, "Layer Settings", "Override of engine specific render settings");
+
+ /* debug update routine */
+ func = RNA_def_function(srna, "update", "rna_ViewLayer_update_tagged");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ RNA_def_function_ui_description(func,
+ "Update data tagged to be updated from previous access to data or operators");
+
+ /* Dependency Graph */
+ prop = RNA_def_property(srna, "depsgraph", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "Depsgraph");
+ RNA_def_property_ui_text(prop, "Dependency Graph", "Dependencies in the scene data");
+ RNA_def_property_pointer_funcs(prop, "rna_ViewLayer_depsgraph_get", NULL, NULL, NULL);
+
+ /* Nested Data */
+ /* *** Non-Animated *** */
+ RNA_define_animate_sdna(false);
+ rna_def_scene_collection(brna);
+ rna_def_layer_collection(brna);
+ rna_def_layer_collection_override(brna);
+ rna_def_object_base(brna);
+ RNA_define_animate_sdna(true);
+ /* *** Animated *** */
+ rna_def_view_layer_settings(brna);
+ rna_def_layer_collection_settings(brna);
+}
+
+#endif
diff --git a/source/blender/makesrna/intern/rna_lightprobe.c b/source/blender/makesrna/intern/rna_lightprobe.c
new file mode 100644
index 00000000000..675615d6c1f
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_lightprobe.c
@@ -0,0 +1,224 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Blender Foundation.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_lightprobe.c
+ * \ingroup RNA
+ */
+
+#include <stdlib.h>
+
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "rna_internal.h"
+
+#include "DNA_lightprobe_types.h"
+
+#include "WM_types.h"
+
+#ifdef RNA_RUNTIME
+
+#include "MEM_guardedalloc.h"
+
+#include "BKE_main.h"
+#include "DEG_depsgraph.h"
+
+#include "DNA_object_types.h"
+#include "DNA_group_types.h"
+
+#include "WM_api.h"
+
+static void rna_LightProbe_recalc(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+}
+
+#else
+
+static EnumPropertyItem parallax_type_items[] = {
+ {LIGHTPROBE_SHAPE_ELIPSOID, "ELIPSOID", ICON_NONE, "Sphere", ""},
+ {LIGHTPROBE_SHAPE_BOX, "BOX", ICON_NONE, "Box", ""},
+ {0, NULL, 0, NULL, NULL}
+};
+
+static EnumPropertyItem lightprobe_type_items[] = {
+ {LIGHTPROBE_TYPE_CUBE, "CUBEMAP", ICON_NONE, "Reflection Cubemap", "Capture reflections"},
+ {LIGHTPROBE_TYPE_PLANAR, "PLANAR", ICON_NONE, "Reflection Plane", ""},
+ {LIGHTPROBE_TYPE_GRID, "GRID", ICON_NONE, "Irradiance Volume", "Volume used for precomputing indirect lighting"},
+ {0, NULL, 0, NULL, NULL}
+};
+
+static void rna_def_lightprobe(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "LightProbe", "ID");
+ RNA_def_struct_ui_text(srna, "LightProbe", "Light Probe data-block for lighting capture objects");
+ RNA_def_struct_ui_icon(srna, ICON_RADIO);
+
+ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, lightprobe_type_items);
+ RNA_def_property_ui_text(prop, "Type", "Type of light probe");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "clipsta");
+ RNA_def_property_range(prop, 1e-6f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
+ RNA_def_property_ui_text(prop, "Clip Start",
+ "Probe clip start, below which objects will not appear in reflections");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "clipend");
+ RNA_def_property_range(prop, 1e-6f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.001f, FLT_MAX, 10, 3);
+ RNA_def_property_ui_text(prop, "Clip End",
+ "Probe clip end, beyond which objects will not appear in reflections");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "show_clip", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", LIGHTPROBE_FLAG_SHOW_CLIP_DIST);
+ RNA_def_property_ui_text(prop, "Clipping", "Show the clipping distances in the 3D view");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "influence_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "attenuation_type");
+ RNA_def_property_enum_items(prop, parallax_type_items);
+ RNA_def_property_ui_text(prop, "Type", "Type of parallax volume");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "show_influence", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", LIGHTPROBE_FLAG_SHOW_INFLUENCE);
+ RNA_def_property_ui_text(prop, "Influence", "Show the influence volume in the 3D view");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "influence_distance", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "distinf");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_text(prop, "Influence Distance", "Influence distance of the probe");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Falloff", "Control how fast the probe influence decreases");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "use_custom_parallax", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", LIGHTPROBE_FLAG_CUSTOM_PARALLAX);
+ RNA_def_property_ui_text(prop, "Use Custom Parallax", "Enable custom settings for the parallax correction volume");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "show_parallax", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", LIGHTPROBE_FLAG_SHOW_PARALLAX);
+ RNA_def_property_ui_text(prop, "Parallax", "Show the parallax correction volume in the 3D view");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "parallax_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, parallax_type_items);
+ RNA_def_property_ui_text(prop, "Type", "Type of parallax volume");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "parallax_distance", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "distpar");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_text(prop, "Parallax Radius", "Lowest corner of the parallax bounding box");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ /* irradiance grid */
+ prop = RNA_def_property(srna, "grid_resolution_x", PROP_INT, PROP_NONE);
+ RNA_def_property_range(prop, 1, 256);
+ RNA_def_property_ui_text(prop, "Resolution X", "Number of sample along the x axis of the volume");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "grid_resolution_y", PROP_INT, PROP_NONE);
+ RNA_def_property_range(prop, 1, 256);
+ RNA_def_property_ui_text(prop, "Resolution Y", "Number of sample along the y axis of the volume");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "grid_resolution_z", PROP_INT, PROP_NONE);
+ RNA_def_property_range(prop, 1, 256);
+ RNA_def_property_ui_text(prop, "Resolution Z", "Number of sample along the z axis of the volume");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "visibility_buffer_bias", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "vis_bias");
+ RNA_def_property_range(prop, 0.001f, 9999.0f);
+ RNA_def_property_ui_range(prop, 0.001f, 5.0f, 1.0, 3);
+ RNA_def_property_ui_text(prop, "Visibility Bias", "Bias for reducing self shadowing");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "visibility_bleed_bias", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "vis_bleedbias");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Visibility Bleed Bias", "Bias for reducing light-bleed on variance shadow maps");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "visibility_blur", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "vis_blur");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_text(prop, "Visibility Blur", "Filter size of the visibilty blur");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "intensity");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.0f, 3.0f, 1.0, 3);
+ RNA_def_property_ui_text(prop, "Intensity", "Modify the intensity of the lighting captured by this probe");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "visibility_group", PROP_POINTER, PROP_NONE);
+ RNA_def_property_pointer_sdna(prop, NULL, "visibility_grp");
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Visibility Group", "Restrict objects visible for this probe");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ prop = RNA_def_property(srna, "invert_visibility_group", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", LIGHTPROBE_FLAG_INVERT_GROUP);
+ RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_ui_text(prop, "Invert Group", "Invert visibility group");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, "rna_LightProbe_recalc");
+
+ /* Data preview */
+ prop = RNA_def_property(srna, "show_data", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", LIGHTPROBE_FLAG_SHOW_DATA);
+ RNA_def_property_ui_text(prop, "Show Data", "Show captured lighting data into the 3D view for debuging purpose");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ prop = RNA_def_property(srna, "data_draw_size", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_range(prop, 0.05f, 10.0f);
+ RNA_def_property_ui_text(prop, "Data Draw Size", "Size of the spheres to debug captured light");
+ RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING, NULL);
+
+ /* common */
+ rna_def_animdata_common(srna);
+}
+
+
+void RNA_def_lightprobe(BlenderRNA *brna)
+{
+ rna_def_lightprobe(brna);
+}
+
+#endif
+
diff --git a/source/blender/makesrna/intern/rna_linestyle.c b/source/blender/makesrna/intern/rna_linestyle.c
index bcd8ab054ae..e138d0d98d8 100644
--- a/source/blender/makesrna/intern/rna_linestyle.c
+++ b/source/blender/makesrna/intern/rna_linestyle.c
@@ -101,7 +101,8 @@ const EnumPropertyItem rna_enum_linestyle_geometry_modifier_type_items[] = {
#include "BKE_linestyle.h"
#include "BKE_texture.h"
-#include "BKE_depsgraph.h"
+
+#include "DEG_depsgraph.h"
#include "ED_node.h"
@@ -323,7 +324,7 @@ static void rna_LineStyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
{
FreestyleLineStyle *linestyle = ptr->id.data;
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
}
@@ -347,7 +348,7 @@ static LineStyleModifier *rna_LineStyle_color_modifier_add(FreestyleLineStyle *l
return NULL;
}
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
return modifier;
@@ -365,7 +366,7 @@ static void rna_LineStyle_color_modifier_remove(FreestyleLineStyle *linestyle, R
RNA_POINTER_INVALIDATE(modifier_ptr);
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
}
@@ -379,7 +380,7 @@ static LineStyleModifier *rna_LineStyle_alpha_modifier_add(FreestyleLineStyle *l
return NULL;
}
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
return modifier;
@@ -397,7 +398,7 @@ static void rna_LineStyle_alpha_modifier_remove(FreestyleLineStyle *linestyle, R
RNA_POINTER_INVALIDATE(modifier_ptr);
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
}
@@ -411,7 +412,7 @@ static LineStyleModifier *rna_LineStyle_thickness_modifier_add(FreestyleLineStyl
return NULL;
}
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
return modifier;
@@ -429,7 +430,7 @@ static void rna_LineStyle_thickness_modifier_remove(FreestyleLineStyle *linestyl
RNA_POINTER_INVALIDATE(modifier_ptr);
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
}
@@ -443,7 +444,7 @@ static LineStyleModifier *rna_LineStyle_geometry_modifier_add(FreestyleLineStyle
return NULL;
}
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
return modifier;
@@ -461,7 +462,7 @@ static void rna_LineStyle_geometry_modifier_remove(FreestyleLineStyle *linestyle
RNA_POINTER_INVALIDATE(modifier_ptr);
- DAG_id_tag_update(&linestyle->id, 0);
+ DEG_id_tag_update(&linestyle->id, 0);
WM_main_add_notifier(NC_LINESTYLE, linestyle);
}
diff --git a/source/blender/makesrna/intern/rna_main.c b/source/blender/makesrna/intern/rna_main.c
index 94687b6fd46..6479826b7b3 100644
--- a/source/blender/makesrna/intern/rna_main.c
+++ b/source/blender/makesrna/intern/rna_main.c
@@ -293,6 +293,18 @@ static void rna_Main_paintcurves_begin(CollectionPropertyIterator *iter, Pointer
rna_iterator_listbase_begin(iter, &bmain->paintcurves, NULL);
}
+static void rna_Main_workspaces_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ Main *bmain = (Main *)ptr->data;
+ rna_iterator_listbase_begin(iter, &bmain->workspaces, NULL);
+}
+
+static void rna_Main_lightprobes_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ Main *bmain = (Main *)ptr->data;
+ rna_iterator_listbase_begin(iter, &bmain->lightprobe, NULL);
+}
+
static void rna_Main_version_get(PointerRNA *ptr, int *value)
{
Main *bmain = (Main *)ptr->data;
@@ -368,6 +380,8 @@ void RNA_def_main(BlenderRNA *brna)
{"linestyles", "FreestyleLineStyle", "rna_Main_linestyle_begin", "Line Styles", "Line Style data-blocks", RNA_def_main_linestyles},
{"cache_files", "CacheFile", "rna_Main_cachefiles_begin", "Cache Files", "Cache Files data-blocks", RNA_def_main_cachefiles},
{"paint_curves", "PaintCurve", "rna_Main_paintcurves_begin", "Paint Curves", "Paint Curves data-blocks", RNA_def_main_paintcurves},
+ {"workspaces", "WorkSpace", "rna_Main_workspaces_begin", "Workspaces", "Workspace data-blocks", RNA_def_main_workspaces},
+ {"lightprobes", "LightProbe", "rna_Main_lightprobes_begin", "LightProbes", "LightProbe data-blocks", RNA_def_main_lightprobes},
{NULL, NULL, NULL, NULL, NULL, NULL}
};
diff --git a/source/blender/makesrna/intern/rna_main_api.c b/source/blender/makesrna/intern/rna_main_api.c
index 4aa4eddaddb..41970a69c6c 100644
--- a/source/blender/makesrna/intern/rna_main_api.c
+++ b/source/blender/makesrna/intern/rna_main_api.c
@@ -78,12 +78,16 @@
#include "BKE_paint.h"
#include "BKE_font.h"
#include "BKE_node.h"
-#include "BKE_depsgraph.h"
#include "BKE_speaker.h"
+#include "BKE_lightprobe.h"
#include "BKE_movieclip.h"
#include "BKE_mask.h"
#include "BKE_gpencil.h"
#include "BKE_linestyle.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
#include "DNA_armature_types.h"
#include "DNA_camera_types.h"
@@ -93,6 +97,7 @@
#include "DNA_mesh_types.h"
#include "DNA_speaker_types.h"
#include "DNA_sound_types.h"
+#include "DNA_lightprobe_types.h"
#include "DNA_text_types.h"
#include "DNA_texture_types.h"
#include "DNA_group_types.h"
@@ -115,6 +120,8 @@
# include "BPY_extern.h"
#endif
+#include "WM_api.h"
+
static void rna_idname_validate(const char *name, char *r_name)
{
@@ -170,14 +177,15 @@ static void rna_Main_scenes_remove(Main *bmain, bContext *C, ReportList *reports
(scene_new = scene->id.next))
{
if (do_unlink) {
- bScreen *sc = CTX_wm_screen(C);
- if (sc->scene == scene) {
+ wmWindow *win = CTX_wm_window(C);
+
+ if (WM_window_get_active_scene(win) == scene) {
#ifdef WITH_PYTHON
BPy_BEGIN_ALLOW_THREADS;
#endif
- ED_screen_set_scene(C, sc, scene_new);
+ WM_window_change_active_scene(bmain, C, win, scene_new);
#ifdef WITH_PYTHON
BPy_END_ALLOW_THREADS;
@@ -241,7 +249,6 @@ static Object *rna_Main_objects_new(Main *bmain, ReportList *reports, const char
}
ob = BKE_object_add_only_object(bmain, type, safe_name);
- id_us_min(&ob->id);
ob->data = data;
test_object_materials(ob, ob->data);
@@ -291,11 +298,12 @@ static Mesh *rna_Main_meshes_new(Main *bmain, const char *name)
}
/* copied from Mesh_getFromObject and adapted to RNA interface */
-/* settings: 1 - preview, 2 - render */
Mesh *rna_Main_meshes_new_from_object(
- Main *bmain, ReportList *reports, Scene *sce,
- Object *ob, int apply_modifiers, int settings, int calc_tessface, int calc_undeformed)
+ Main *bmain, ReportList *reports, Depsgraph *depsgraph,
+ Object *ob, int apply_modifiers, int calc_tessface, int calc_undeformed)
{
+ Scene *sce = DEG_get_evaluated_scene(depsgraph);
+
switch (ob->type) {
case OB_FONT:
case OB_CURVE:
@@ -308,7 +316,7 @@ Mesh *rna_Main_meshes_new_from_object(
return NULL;
}
- return BKE_mesh_new_from_object(bmain, sce, ob, apply_modifiers, settings, calc_tessface, calc_undeformed);
+ return BKE_mesh_new_from_object(depsgraph, bmain, sce, ob, apply_modifiers, calc_tessface, calc_undeformed);
}
static Lamp *rna_Main_lamps_new(Main *bmain, const char *name, int type)
@@ -544,7 +552,7 @@ static MovieClip *rna_Main_movieclip_load(Main *bmain, ReportList *reports, cons
}
if (clip != NULL) {
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
else {
BKE_reportf(reports, RPT_ERROR, "Cannot read '%s': %s", filepath,
@@ -573,13 +581,23 @@ static FreestyleLineStyle *rna_Main_linestyles_new(Main *bmain, const char *name
return linestyle;
}
+static LightProbe *rna_Main_lightprobe_new(Main *bmain, const char *name)
+{
+ char safe_name[MAX_ID_NAME - 2];
+ rna_idname_validate(name, safe_name);
+
+ LightProbe *probe = BKE_lightprobe_add(bmain, safe_name);
+ id_us_min(&probe->id);
+ return probe;
+}
+
/* tag and is_updated functions, all the same */
#define RNA_MAIN_ID_TAG_FUNCS_DEF(_func_name, _listbase_name, _id_type) \
static void rna_Main_##_func_name##_tag(Main *bmain, int value) { \
BKE_main_id_tag_listbase(&bmain->_listbase_name, LIB_TAG_DOIT, value); \
} \
static int rna_Main_##_func_name##_is_updated_get(PointerRNA *ptr) { \
- return DAG_id_type_tagged(ptr->data, _id_type) != 0; \
+ return DEG_id_type_tagged(ptr->data, _id_type) != 0; \
}
RNA_MAIN_ID_TAG_FUNCS_DEF(cameras, camera, ID_CA)
@@ -615,6 +633,8 @@ RNA_MAIN_ID_TAG_FUNCS_DEF(masks, mask, ID_MSK)
RNA_MAIN_ID_TAG_FUNCS_DEF(linestyle, linestyle, ID_LS)
RNA_MAIN_ID_TAG_FUNCS_DEF(cachefiles, cachefiles, ID_CF)
RNA_MAIN_ID_TAG_FUNCS_DEF(paintcurves, paintcurves, ID_PC)
+RNA_MAIN_ID_TAG_FUNCS_DEF(workspaces, workspaces, ID_WS)
+RNA_MAIN_ID_TAG_FUNCS_DEF(lightprobes, lightprobe, ID_LP)
#undef RNA_MAIN_ID_TAG_FUNCS_DEF
@@ -857,12 +877,6 @@ void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop)
PropertyRNA *parm;
PropertyRNA *prop;
- static const EnumPropertyItem mesh_type_items[] = {
- {eModifierMode_Realtime, "PREVIEW", 0, "Preview", "Apply modifier preview settings"},
- {eModifierMode_Render, "RENDER", 0, "Render", "Apply modifier render settings"},
- {0, NULL, 0, NULL, NULL}
- };
-
RNA_def_property_srna(cprop, "BlendDataMeshes");
srna = RNA_def_struct(brna, "BlendDataMeshes", NULL);
RNA_def_struct_sdna(srna, "Main");
@@ -879,14 +893,12 @@ void RNA_def_main_meshes(BlenderRNA *brna, PropertyRNA *cprop)
func = RNA_def_function(srna, "new_from_object", "rna_Main_meshes_new_from_object");
RNA_def_function_ui_description(func, "Add a new mesh created from object with modifiers applied");
RNA_def_function_flag(func, FUNC_USE_REPORTS);
- parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate modifiers");
+ parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "Dependency Graph", "Evaluated dependency graph within wich to evaluate modifiers");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_pointer(func, "object", "Object", "", "Object to create mesh from");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_boolean(func, "apply_modifiers", 0, "", "Apply modifiers");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
- RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
RNA_def_boolean(func, "calc_tessface", true, "Calculate Tessellation", "Calculate tessellation faces");
RNA_def_boolean(func, "calc_undeformed", false, "Calculate Undeformed", "Calculate undeformed vertex coordinates");
parm = RNA_def_pointer(func, "mesh", "Mesh", "",
@@ -1676,6 +1688,7 @@ void RNA_def_main_particles(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_boolean_funcs(prop, "rna_Main_particles_is_updated_get", NULL);
}
+
void RNA_def_main_palettes(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
@@ -1927,4 +1940,68 @@ void RNA_def_main_linestyles(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_property_boolean_funcs(prop, "rna_Main_linestyle_is_updated_get", NULL);
}
+void RNA_def_main_workspaces(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+ PropertyRNA *prop;
+
+ RNA_def_property_srna(cprop, "BlendDataWorkSpaces");
+ srna = RNA_def_struct(brna, "BlendDataWorkSpaces", NULL);
+ RNA_def_struct_sdna(srna, "Main");
+ RNA_def_struct_ui_text(srna, "Main Workspaces", "Collection of workspaces");
+
+ func = RNA_def_function(srna, "tag", "rna_Main_workspaces_tag");
+ parm = RNA_def_boolean(func, "value", 0, "Value", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_Main_workspaces_is_updated_get", NULL);
+}
+
+void RNA_def_main_lightprobes(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ FunctionRNA *func;
+ PropertyRNA *parm;
+ PropertyRNA *prop;
+
+ RNA_def_property_srna(cprop, "BlendDataProbes");
+ srna = RNA_def_struct(brna, "BlendDataProbes", NULL);
+ RNA_def_struct_sdna(srna, "Main");
+ RNA_def_struct_ui_text(srna, "Main Light Probes", "Collection of light probes");
+
+ func = RNA_def_function(srna, "new", "rna_Main_lightprobe_new");
+ RNA_def_function_ui_description(func, "Add a new probe to the main database");
+ parm = RNA_def_string(func, "name", "Probe", 0, "", "New name for the data-block");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ /* return type */
+ parm = RNA_def_pointer(func, "lightprobe", "LightProbe", "", "New light probe data-block");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_Main_ID_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(func, "Remove a probe from the current blendfile");
+ parm = RNA_def_pointer(func, "lightprobe", "LightProbe", "", "Probe to remove");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+ RNA_def_boolean(func, "do_unlink", true, "",
+ "Unlink all usages of this probe before deleting it "
+ "(WARNING: will also delete objects instancing that light probe data)");
+ RNA_def_boolean(func, "do_id_user", true, "",
+ "Decrement user counter of all datablocks used by this light probe");
+ RNA_def_boolean(func, "do_ui_user", true, "",
+ "Make sure interface does not reference this light probe");
+
+ func = RNA_def_function(srna, "tag", "rna_Main_lightprobes_tag");
+ parm = RNA_def_boolean(func, "value", 0, "Value", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ prop = RNA_def_property(srna, "is_updated", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_Main_lightprobes_is_updated_get", NULL);
+}
+
#endif
diff --git a/source/blender/makesrna/intern/rna_mask.c b/source/blender/makesrna/intern/rna_mask.c
index c266e0e7f31..564232c3dd4 100644
--- a/source/blender/makesrna/intern/rna_mask.c
+++ b/source/blender/makesrna/intern/rna_mask.c
@@ -56,9 +56,10 @@
#include "DNA_movieclip_types.h"
-#include "BKE_depsgraph.h"
#include "BKE_mask.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "WM_api.h"
@@ -68,7 +69,7 @@ static void rna_Mask_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
Mask *mask = ptr->id.data;
WM_main_add_notifier(NC_MASK | ND_DATA, mask);
- DAG_id_tag_update( &mask->id, 0);
+ DEG_id_tag_update( &mask->id, 0);
}
static void rna_Mask_update_parent(Main *bmain, Scene *scene, PointerRNA *ptr)
@@ -448,7 +449,7 @@ static void rna_MaskLayer_spline_remove(ID *id, MaskLayer *mask_layer, ReportLis
RNA_POINTER_INVALIDATE(spline_ptr);
- DAG_id_tag_update(&mask->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&mask->id, OB_RECALC_DATA);
}
static void rna_Mask_start_frame_set(PointerRNA *ptr, int value)
@@ -522,7 +523,7 @@ static void rna_MaskSpline_points_add(ID *id, MaskSpline *spline, int count)
}
WM_main_add_notifier(NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
}
static void rna_MaskSpline_point_remove(ID *id, MaskSpline *spline, ReportList *reports, PointerRNA *point_ptr)
@@ -582,7 +583,7 @@ static void rna_MaskSpline_point_remove(ID *id, MaskSpline *spline, ReportList *
BKE_mask_layer_shape_changed_remove(layer, BKE_mask_layer_shape_spline_to_index(layer, spline) + point_index, 1);
WM_main_add_notifier(NC_MASK | ND_DATA, mask);
- DAG_id_tag_update(&mask->id, 0);
+ DEG_id_tag_update(&mask->id, 0);
RNA_POINTER_INVALIDATE(point_ptr);
}
diff --git a/source/blender/makesrna/intern/rna_material.c b/source/blender/makesrna/intern/rna_material.c
index 1959a017e43..7dc76120097 100644
--- a/source/blender/makesrna/intern/rna_material.c
+++ b/source/blender/makesrna/intern/rna_material.c
@@ -38,22 +38,6 @@
#include "WM_api.h"
#include "WM_types.h"
-static const EnumPropertyItem prop_texture_coordinates_items[] = {
- {TEXCO_GLOB, "GLOBAL", 0, "Global", "Use global coordinates for the texture coordinates"},
- {TEXCO_OBJECT, "OBJECT", 0, "Object", "Use linked object's coordinates for texture coordinates"},
- {TEXCO_UV, "UV", 0, "UV", "Use UV coordinates for texture coordinates"},
- {TEXCO_ORCO, "ORCO", 0, "Generated", "Use the original undeformed coordinates of the object"},
- {TEXCO_STRAND, "STRAND", 0, "Strand / Particle",
- "Use normalized strand texture coordinate (1D) or particle age (X) and trail position (Y)"},
- {TEXCO_WINDOW, "WINDOW", 0, "Window", "Use screen coordinates as texture coordinates"},
- {TEXCO_NORM, "NORMAL", 0, "Normal", "Use normal vector as texture coordinates"},
- {TEXCO_REFL, "REFLECTION", 0, "Reflection", "Use reflection vector as texture coordinates"},
- {TEXCO_STRESS, "STRESS", 0, "Stress",
- "Use the difference of edge lengths compared to original coordinates of the mesh"},
- {TEXCO_TANGENT, "TANGENT", 0, "Tangent", "Use the optional tangent vector as texture coordinates"},
- {0, NULL, 0, NULL, NULL}
-};
-
const EnumPropertyItem rna_enum_ramp_blend_items[] = {
{MA_RAMP_BLEND, "MIX", 0, "Mix", ""},
{MA_RAMP_ADD, "ADD", 0, "Add", ""},
@@ -87,22 +71,26 @@ const EnumPropertyItem rna_enum_ramp_blend_items[] = {
#include "BKE_colorband.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_material.h"
#include "BKE_texture.h"
#include "BKE_node.h"
#include "BKE_paint.h"
+#include "BKE_scene.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "ED_node.h"
#include "ED_image.h"
-#include "BKE_scene.h"
+#include "ED_screen.h"
static void rna_Material_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Material *ma = ptr->id.data;
- DAG_id_tag_update(&ma->id, 0);
+ DEG_id_tag_update(&ma->id, DEG_TAG_COPY_ON_WRITE);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, ma);
}
@@ -120,7 +108,7 @@ static void rna_Material_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
{
Material *ma = ptr->id.data;
- DAG_id_tag_update(&ma->id, 0);
+ DEG_id_tag_update(&ma->id, DEG_TAG_COPY_ON_WRITE);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
}
@@ -129,47 +117,6 @@ static PointerRNA rna_Material_mirror_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_MaterialRaytraceMirror, ptr->id.data);
}
-static PointerRNA rna_Material_transp_get(PointerRNA *ptr)
-{
- return rna_pointer_inherit_refine(ptr, &RNA_MaterialRaytraceTransparency, ptr->id.data);
-}
-
-static PointerRNA rna_Material_halo_get(PointerRNA *ptr)
-{
- return rna_pointer_inherit_refine(ptr, &RNA_MaterialHalo, ptr->id.data);
-}
-
-static PointerRNA rna_Material_sss_get(PointerRNA *ptr)
-{
- return rna_pointer_inherit_refine(ptr, &RNA_MaterialSubsurfaceScattering, ptr->id.data);
-}
-
-static PointerRNA rna_Material_strand_get(PointerRNA *ptr)
-{
- return rna_pointer_inherit_refine(ptr, &RNA_MaterialStrand, ptr->id.data);
-}
-
-static PointerRNA rna_Material_physics_get(PointerRNA *ptr)
-{
- return rna_pointer_inherit_refine(ptr, &RNA_MaterialPhysics, ptr->id.data);
-}
-
-static void rna_Material_type_set(PointerRNA *ptr, int value)
-{
- Material *ma = (Material *)ptr->data;
-
- if (ma->material_type == MA_TYPE_HALO && value != MA_TYPE_HALO)
- ma->mode &= ~(MA_STAR | MA_HALO_XALPHA | MA_ZINV | MA_ENV);
-
- ma->material_type = value;
-}
-
-static void rna_Material_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
-{
- Material *ma = (Material *)ptr->data;
- rna_iterator_array_begin(iter, (void *)ma->mtex, sizeof(MTex *), MAX_MTEX, 0, NULL);
-}
-
static void rna_Material_texpaint_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
Material *ma = (Material *)ptr->data;
@@ -199,181 +146,47 @@ static void rna_Material_active_paint_texture_index_update(Main *bmain, Scene *s
if (ma->texpaintslot) {
Image *image = ma->texpaintslot[ma->paint_active_slot].ima;
for (sc = bmain->screen.first; sc; sc = sc->id.next) {
+ wmWindow *win = ED_screen_window_find(sc, bmain->wm.first);
+ if (win == NULL) {
+ continue;
+ }
+
+ Object *obedit = NULL;
+ {
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
+ obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
+ }
+
ScrArea *sa;
for (sa = sc->areabase.first; sa; sa = sa->next) {
SpaceLink *sl;
for (sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_IMAGE) {
SpaceImage *sima = (SpaceImage *)sl;
-
- if (!sima->pin)
- ED_space_image_set(sima, scene, scene->obedit, image);
+ if (!sima->pin) {
+ ED_space_image_set(sima, scene, obedit, image);
+ }
}
}
}
}
}
- DAG_id_tag_update(&ma->id, 0);
+ DEG_id_tag_update(&ma->id, 0);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING, ma);
}
-static PointerRNA rna_Material_active_texture_get(PointerRNA *ptr)
-{
- Material *ma = (Material *)ptr->data;
- Tex *tex;
-
- tex = give_current_material_texture(ma);
- return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
-}
-
-static void rna_Material_active_texture_set(PointerRNA *ptr, PointerRNA value)
-{
- Material *ma = (Material *)ptr->data;
-
- set_current_material_texture(ma, value.data);
-}
-
-static int rna_Material_active_texture_editable(PointerRNA *ptr, const char **UNUSED(r_info))
-{
- Material *ma = (Material *)ptr->id.data;
-
- return has_current_material_texture(ma) ? PROP_EDITABLE : 0;
-}
-
-static PointerRNA rna_Material_active_node_material_get(PointerRNA *ptr)
-{
- Material *ma = give_node_material((Material *)ptr->data);
- return rna_pointer_inherit_refine(ptr, &RNA_Material, ma);
-}
-
-static void rna_Material_active_node_material_set(PointerRNA *ptr, PointerRNA value)
-{
- Material *ma = (Material *)ptr->data;
- Material *ma_act = value.data;
-
- nodeSetActiveID(ma->nodetree, ID_MA, &ma_act->id);
-}
-
-static void rna_MaterialStrand_start_size_range(PointerRNA *ptr, float *min, float *max,
- float *UNUSED(softmin), float *UNUSED(softmax))
-{
- Material *ma = (Material *)ptr->id.data;
-
- if (ma->mode & MA_STR_B_UNITS) {
- *min = 0.0001f;
- *max = 2.0f;
- }
- else {
- *min = 0.25f;
- *max = 20.0f;
- }
-}
-
-static void rna_MaterialStrand_end_size_range(PointerRNA *ptr, float *min, float *max,
- float *UNUSED(softmin), float *UNUSED(softmax))
-{
- Material *ma = (Material *)ptr->id.data;
-
- if (ma->mode & MA_STR_B_UNITS) {
- *min = 0.0001f;
- *max = 1.0f;
- }
- else {
- *min = 0.25f;
- *max = 10.0f;
- }
-}
-
-static int rna_MaterialTextureSlot_use_get(PointerRNA *ptr)
-{
- Material *ma = (Material *)ptr->id.data;
- MTex *mtex = (MTex *)ptr->data;
- int a;
-
- for (a = 0; a < MAX_MTEX; a++)
- if (ma->mtex[a] == mtex)
- return (ma->septex & (1 << a)) == 0;
-
- return 0;
-}
-
-static void rna_MaterialTextureSlot_use_set(PointerRNA *ptr, int value)
-{
- Material *ma = (Material *)ptr->id.data;
- MTex *mtex = (MTex *)ptr->data;
- int a;
-
- for (a = 0; a < MAX_MTEX; a++) {
- if (ma->mtex[a] == mtex) {
- if (value)
- ma->septex &= ~(1 << a);
- else
- ma->septex |= (1 << a);
- }
- }
-}
-
-static void rna_Material_use_diffuse_ramp_set(PointerRNA *ptr, int value)
-{
- Material *ma = (Material *)ptr->data;
-
- if (value) ma->mode |= MA_RAMP_COL;
- else ma->mode &= ~MA_RAMP_COL;
-
- if ((ma->mode & MA_RAMP_COL) && ma->ramp_col == NULL)
- ma->ramp_col = BKE_colorband_add(false);
-}
-
-static void rna_Material_use_specular_ramp_set(PointerRNA *ptr, int value)
-{
- Material *ma = (Material *)ptr->data;
-
- if (value) ma->mode |= MA_RAMP_SPEC;
- else ma->mode &= ~MA_RAMP_SPEC;
-
- if ((ma->mode & MA_RAMP_SPEC) && ma->ramp_spec == NULL)
- ma->ramp_spec = BKE_colorband_add(false);
-}
-
static void rna_Material_use_nodes_update(bContext *C, PointerRNA *ptr)
{
Material *ma = (Material *)ptr->data;
+ Main *bmain = CTX_data_main(C);
if (ma->use_nodes && ma->nodetree == NULL)
ED_node_shader_default(C, &ma->id);
-
- rna_Material_draw_update(CTX_data_main(C), CTX_data_scene(C), ptr);
-}
-static const EnumPropertyItem *rna_Material_texture_coordinates_itemf(bContext *UNUSED(C), PointerRNA *ptr,
- PropertyRNA *UNUSED(prop), bool *r_free)
-{
- Material *ma = (Material *)ptr->id.data;
- EnumPropertyItem *item = NULL;
- int totitem = 0;
-
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_GLOB);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_OBJECT);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_ORCO);
-
- if (ma->material_type == MA_TYPE_VOLUME) {
- /* pass */
- }
- else if (ELEM(ma->material_type, MA_TYPE_SURFACE, MA_TYPE_HALO, MA_TYPE_WIRE)) {
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_UV);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_STRAND);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_WINDOW);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_NORM);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_REFL);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_STRESS);
- RNA_enum_items_add_value(&item, &totitem, prop_texture_coordinates_items, TEXCO_TANGENT);
- }
-
- RNA_enum_item_end(&item, &totitem);
- *r_free = true;
-
- return item;
+ DEG_relations_tag_update(bmain);
+ rna_Material_draw_update(bmain, CTX_data_scene(C), ptr);
}
MTex *rna_mtex_texture_slots_add(ID *self_id, struct bContext *C, ReportList *reports)
@@ -428,7 +241,7 @@ void rna_mtex_texture_slots_clear(ID *self_id, struct bContext *C, ReportList *r
id_us_min((ID *)mtex_ar[index]->tex);
MEM_freeN(mtex_ar[index]);
mtex_ar[index] = NULL;
- DAG_id_tag_update(self_id, 0);
+ DEG_id_tag_update(self_id, 0);
}
/* for redraw only */
@@ -437,467 +250,10 @@ void rna_mtex_texture_slots_clear(ID *self_id, struct bContext *C, ReportList *r
#else
-static void rna_def_material_mtex(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_mapping_items[] = {
- {MTEX_FLAT, "FLAT", 0, "Flat", "Map X and Y coordinates directly"},
- {MTEX_CUBE, "CUBE", 0, "Cube", "Map using the normal vector"},
- {MTEX_TUBE, "TUBE", 0, "Tube", "Map with Z as central axis"},
- {MTEX_SPHERE, "SPHERE", 0, "Sphere", "Map with Z as central axis"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_x_mapping_items[] = {
- {0, "NONE", 0, "None", ""},
- {1, "X", 0, "X", ""},
- {2, "Y", 0, "Y", ""},
- {3, "Z", 0, "Z", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_y_mapping_items[] = {
- {0, "NONE", 0, "None", ""},
- {1, "X", 0, "X", ""},
- {2, "Y", 0, "Y", ""},
- {3, "Z", 0, "Z", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_z_mapping_items[] = {
- {0, "NONE", 0, "None", ""},
- {1, "X", 0, "X", ""},
- {2, "Y", 0, "Y", ""},
- {3, "Z", 0, "Z", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_normal_map_space_items[] = {
- {MTEX_NSPACE_CAMERA, "CAMERA", 0, "Camera", ""},
- {MTEX_NSPACE_WORLD, "WORLD", 0, "World", ""},
- {MTEX_NSPACE_OBJECT, "OBJECT", 0, "Object", ""},
- {MTEX_NSPACE_TANGENT, "TANGENT", 0, "Tangent", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_bump_method_items[] = {
- {0, "BUMP_ORIGINAL", 0, "Original", ""},
- {MTEX_COMPAT_BUMP, "BUMP_COMPATIBLE", 0, "Compatible", ""},
- {MTEX_3TAP_BUMP, "BUMP_LOW_QUALITY", 0, "Low Quality", "Use 3 tap filtering"},
- {MTEX_5TAP_BUMP, "BUMP_MEDIUM_QUALITY", 0, "Medium Quality", "Use 5 tap filtering"},
- {MTEX_BICUBIC_BUMP, "BUMP_BEST_QUALITY", 0,
- "Best Quality", "Use bicubic filtering (requires OpenGL 3.0+, it will fall back on "
- "medium setting for other systems)"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_bump_space_items[] = {
- {0, "BUMP_VIEWSPACE", 0, "ViewSpace", ""},
- {MTEX_BUMP_OBJECTSPACE, "BUMP_OBJECTSPACE", 0, "ObjectSpace", ""},
- {MTEX_BUMP_TEXTURESPACE, "BUMP_TEXTURESPACE", 0, "TextureSpace", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "MaterialTextureSlot", "TextureSlot");
- RNA_def_struct_sdna(srna, "MTex");
- RNA_def_struct_ui_text(srna, "Material Texture Slot", "Texture slot for textures in a Material data-block");
-
- prop = RNA_def_property(srna, "texture_coords", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "texco");
- RNA_def_property_enum_items(prop, prop_texture_coordinates_items);
- RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Material_texture_coordinates_itemf");
- RNA_def_property_ui_text(prop, "Texture Coordinates", "");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "object");
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Object", "Object to use for mapping with Object texture coordinates");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "uvname");
- RNA_def_property_ui_text(prop, "UV Map", "UV map to use for mapping with UV texture coordinates");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_from_dupli", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_DUPLI_MAPTO);
- RNA_def_property_ui_text(prop, "From Dupli",
- "Dupli's instanced from verts, faces or particles, inherit texture coordinate "
- "from their parent");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_to_bounds", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_MAPTO_BOUNDS);
- RNA_def_property_ui_text(prop, "Map to Bounds",
- "Map coordinates in object bounds");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_from_original", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_OB_DUPLI_ORIG);
- RNA_def_property_ui_text(prop, "From Original",
- "Dupli's derive their object coordinates from the original object's transformation");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_color_diffuse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COL);
- RNA_def_property_ui_text(prop, "Diffuse Color", "The texture affects basic color of the material");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_normal", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_NORM);
- RNA_def_property_ui_text(prop, "Normal", "The texture affects the rendered normal");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_color_spec", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COLSPEC);
- RNA_def_property_ui_text(prop, "Specular Color", "The texture affects the specularity color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_mirror", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_COLMIR);
- RNA_def_property_ui_text(prop, "Mirror", "The texture affects the mirror color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_diffuse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_REF);
- RNA_def_property_ui_text(prop, "Diffuse", "The texture affects the value of diffuse reflectivity");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_specular", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_SPEC);
- RNA_def_property_ui_text(prop, "Specular", "The texture affects the value of specular reflectivity");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_ambient", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_AMB);
- RNA_def_property_ui_text(prop, "Ambient", "The texture affects the value of ambient");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_hardness", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_HAR);
- RNA_def_property_ui_text(prop, "Hardness", "The texture affects the hardness value");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_raymir", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_RAYMIRR);
- RNA_def_property_ui_text(prop, "Ray-Mirror", "The texture affects the ray-mirror value");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_alpha", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_ALPHA);
- RNA_def_property_ui_text(prop, "Alpha", "The texture affects the alpha value");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_emit", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMIT);
- RNA_def_property_ui_text(prop, "Emit", "The texture affects the emit value");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_translucency", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_TRANSLU);
- RNA_def_property_ui_text(prop, "Translucency", "The texture affects the translucency value");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_displacement", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_DISPLACE);
- RNA_def_property_ui_text(prop, "Displacement", "Let the texture displace the surface");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_warp", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_WARP);
- RNA_def_property_ui_text(prop, "Warp", "Let the texture warp texture coordinates of next channels");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "mapping_x", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "projx");
- RNA_def_property_enum_items(prop, prop_x_mapping_items);
- RNA_def_property_ui_text(prop, "X Mapping", "");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "mapping_y", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "projy");
- RNA_def_property_enum_items(prop, prop_y_mapping_items);
- RNA_def_property_ui_text(prop, "Y Mapping", "");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "mapping_z", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "projz");
- RNA_def_property_enum_items(prop, prop_z_mapping_items);
- RNA_def_property_ui_text(prop, "Z Mapping", "");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, prop_mapping_items);
- RNA_def_property_ui_text(prop, "Mapping", "");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "normal_map_space", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "normapspace");
- RNA_def_property_enum_items(prop, prop_normal_map_space_items);
- RNA_def_property_ui_text(prop, "Normal Map Space", "Set space of normal map image");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "normal_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "norfac");
- RNA_def_property_ui_range(prop, -5, 5, 10, 3);
- RNA_def_property_ui_text(prop, "Normal Factor", "Amount texture affects normal values");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "displacement_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "dispfac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Displacement Factor", "Amount texture displaces the surface");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "warp_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "warpfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Warp Factor", "Amount texture affects texture coordinates of next channels");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_color_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "colspecfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Specular Color Factor", "Amount texture affects specular color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_color_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "colfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Diffuse Color Factor", "Amount texture affects diffuse color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "mirror_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "mirrfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Mirror Factor", "Amount texture affects mirror color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "alpha_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "alphafac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Alpha Factor", "Amount texture affects alpha");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "difffac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Diffuse Factor", "Amount texture affects diffuse reflectivity");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "specfac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Specular Factor", "Amount texture affects specular reflectivity");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "emit_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "emitfac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Emit Factor", "Amount texture affects emission");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "hardness_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "hardfac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Hardness Factor", "Amount texture affects hardness");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "raymir_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "raymirrfac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Ray Mirror Factor", "Amount texture affects ray mirror");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "translucency_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "translfac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Translucency Factor", "Amount texture affects translucency");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "ambient_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ambfac");
- RNA_def_property_ui_range(prop, -1, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Ambient Factor", "Amount texture affects ambient");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- /* volume material */
- prop = RNA_def_property(srna, "use_map_color_emission", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMISSION_COL);
- RNA_def_property_ui_text(prop, "Emission Color", "The texture affects the color of emission");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_color_reflection", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_REFLECTION_COL);
- RNA_def_property_ui_text(prop, "Reflection Color", "The texture affects the color of scattered light");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_color_transmission", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_TRANSMISSION_COL);
- RNA_def_property_ui_text(prop, "Transmission Color",
- "The texture affects the result color after other light has been scattered/absorbed");
- RNA_def_property_update(prop, NC_TEXTURE, NULL);
-
- prop = RNA_def_property(srna, "use_map_density", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_DENSITY);
- RNA_def_property_ui_text(prop, "Density", "The texture affects the volume's density");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_emission", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_EMISSION);
- RNA_def_property_ui_text(prop, "Emission", "The texture affects the volume's emission");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_scatter", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_SCATTERING);
- RNA_def_property_ui_text(prop, "Scattering", "The texture affects the volume's scattering");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_map_reflect", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", MAP_REFLECTION);
- RNA_def_property_ui_text(prop, "Reflection", "The texture affects the reflected light's brightness");
- RNA_def_property_update(prop, NC_TEXTURE, NULL);
-
- prop = RNA_def_property(srna, "emission_color_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "colemitfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Emission Color Factor", "Amount texture affects emission color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "reflection_color_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "colreflfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Reflection Color Factor", "Amount texture affects color of out-scattered light");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "transmission_color_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "coltransfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Transmission Color Factor",
- "Amount texture affects result color after light has been scattered/absorbed");
- RNA_def_property_update(prop, NC_TEXTURE, NULL);
-
- prop = RNA_def_property(srna, "density_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "densfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Density Factor", "Amount texture affects density");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "emission_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "emitfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Emission Factor", "Amount texture affects emission");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "scattering_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "scatterfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Scattering Factor", "Amount texture affects scattering");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "reflection_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "reflfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Reflection Factor", "Amount texture affects brightness of out-scattered light");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- /* end volume material */
-
- prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_funcs(prop, "rna_MaterialTextureSlot_use_get", "rna_MaterialTextureSlot_use_set");
- RNA_def_property_ui_text(prop, "Enabled", "Enable this material texture slot");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "bump_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "texflag");
- RNA_def_property_enum_items(prop, prop_bump_method_items);
- RNA_def_property_ui_text(prop, "Bump Method", "Method to use for bump mapping");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "bump_objectspace", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "texflag");
- RNA_def_property_enum_items(prop, prop_bump_space_items);
- RNA_def_property_ui_text(prop, "Bump Space", "Space to apply bump mapping in");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-static void rna_def_material_gamesettings(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_alpha_blend_items[] = {
- {GEMAT_SOLID, "OPAQUE", 0, "Opaque", "Render color of textured face as color"},
- {GEMAT_ADD, "ADD", 0, "Add", "Render face transparent and add color of face"},
- {GEMAT_CLIP, "CLIP", 0, "Alpha Clip", "Use the image alpha values clipped with no blending (binary alpha)"},
- {GEMAT_ALPHA, "ALPHA", 0, "Alpha Blend",
- "Render polygon transparent, depending on alpha channel of the texture"},
- {GEMAT_ALPHA_SORT, "ALPHA_SORT", 0, "Alpha Sort",
- "Sort faces for correct alpha drawing (slow, use Alpha Clip instead when possible)"},
- {GEMAT_ALPHA_TO_COVERAGE, "ALPHA_ANTIALIASING", 0, "Alpha Anti-Aliasing",
- "Use textures alpha as anti-aliasing mask, requires multi-sample OpenGL display"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_face_orientation_items[] = {
- {GEMAT_NORMAL, "NORMAL", 0, "Normal", "No transformation"},
- {GEMAT_HALO, "HALO", 0, "Halo", "Screen aligned billboard"},
- {GEMAT_BILLBOARD, "BILLBOARD", 0, "Billboard", "Billboard with Z-axis constraint"},
- {GEMAT_SHADOW, "SHADOW", 0, "Shadow", "Faces are used for shadow"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "MaterialGameSettings", NULL);
- RNA_def_struct_sdna(srna, "GameSettings");
- RNA_def_struct_nested(brna, srna, "Material");
- RNA_def_struct_ui_text(srna, "Material Game Settings", "Game Engine settings for a Material data-block");
-
- prop = RNA_def_property(srna, "use_backface_culling", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GEMAT_BACKCULL); /* use bitflags */
- RNA_def_property_ui_text(prop, "Backface Culling", "Hide Back of the face in Game Engine ");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "text", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GEMAT_TEXT); /* use bitflags */
- RNA_def_property_ui_text(prop, "Text", "Use material as text in Game Engine ");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "invisible", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GEMAT_INVISIBLE); /* use bitflags */
- RNA_def_property_ui_text(prop, "Invisible", "Make face invisible");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "alpha_blend", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "alpha_blend");
- RNA_def_property_enum_items(prop, prop_alpha_blend_items);
- RNA_def_property_ui_text(prop, "Blend Mode", "Blend Mode for Transparent Faces");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "face_orientation", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, prop_face_orientation_items);
- RNA_def_property_ui_text(prop, "Face Orientations", "Especial face orientation options");
-
- prop = RNA_def_property(srna, "physics", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GEMAT_NOPHYSICS); /* use bitflags */
- RNA_def_property_ui_text(prop, "Physics", "Use physics properties of materials ");
-}
-
static void rna_def_material_colors(StructRNA *srna)
{
PropertyRNA *prop;
- static const EnumPropertyItem prop_ramp_input_items[] = {
- {MA_RAMP_IN_SHADER, "SHADER", 0, "Shader", ""},
- {MA_RAMP_IN_ENERGY, "ENERGY", 0, "Energy", ""},
- {MA_RAMP_IN_NOR, "NORMAL", 0, "Normal", ""},
- {MA_RAMP_IN_RESULT, "RESULT", 0, "Result", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
prop = RNA_def_property(srna, "diffuse_color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_float_sdna(prop, NULL, "r");
RNA_def_property_array(prop, 3);
@@ -910,84 +266,17 @@ static void rna_def_material_colors(StructRNA *srna)
RNA_def_property_ui_text(prop, "Specular Color", "Specular color of the material");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "mirror_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "mirr");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Mirror Color", "Mirror color of the material");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
+ prop = RNA_def_property(srna, "specular_intensity", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "spec");
+ RNA_def_property_range(prop, 0, 1);
+ RNA_def_property_ui_text(prop, "Specular Intensity", "How intense (bright) the specular reflection is");
+ RNA_def_property_update(prop, 0, "rna_Material_draw_update");
+
prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Alpha", "Alpha transparency of the material");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "specular_alpha", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "spectra");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Specular Alpha", "Alpha transparency for specular areas");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- /* Color bands */
- prop = RNA_def_property(srna, "use_diffuse_ramp", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAMP_COL);
- RNA_def_property_boolean_funcs(prop, NULL, "rna_Material_use_diffuse_ramp_set");
- RNA_def_property_ui_text(prop, "Use Diffuse Ramp", "Toggle diffuse ramp operations");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_ramp", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "ramp_col");
- RNA_def_property_struct_type(prop, "ColorRamp");
- RNA_def_property_ui_text(prop, "Diffuse Ramp", "Color ramp used to affect diffuse shading");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_specular_ramp", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAMP_SPEC);
- RNA_def_property_boolean_funcs(prop, NULL, "rna_Material_use_specular_ramp_set");
- RNA_def_property_ui_text(prop, "Use Specular Ramp", "Toggle specular ramp operations");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_ramp", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "ramp_spec");
- RNA_def_property_struct_type(prop, "ColorRamp");
- RNA_def_property_ui_text(prop, "Specular Ramp", "Color ramp used to affect specular shading");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_ramp_blend", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "rampblend_col");
- RNA_def_property_enum_items(prop, rna_enum_ramp_blend_items);
- RNA_def_property_ui_text(prop, "Diffuse Ramp Blend", "Blending method of the ramp and the diffuse color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_ramp_blend", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "rampblend_spec");
- RNA_def_property_enum_items(prop, rna_enum_ramp_blend_items);
- RNA_def_property_ui_text(prop, "Specular Ramp Blend", "Blending method of the ramp and the specular color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_ramp_input", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "rampin_col");
- RNA_def_property_enum_items(prop, prop_ramp_input_items);
- RNA_def_property_ui_text(prop, "Diffuse Ramp Input", "How the ramp maps on the surface");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_ramp_input", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "rampin_spec");
- RNA_def_property_enum_items(prop, prop_ramp_input_items);
- RNA_def_property_ui_text(prop, "Specular Ramp Input", "How the ramp maps on the surface");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_ramp_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "rampfac_col");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Diffuse Ramp Factor", "Blending factor (also uses alpha in Colorband)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_ramp_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "rampfac_spec");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Specular Ramp Factor", "Blending factor (also uses alpha in Colorband)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
/* Freestyle line color */
prop = RNA_def_property(srna, "line_color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_float_sdna(prop, NULL, "line_col");
@@ -1003,768 +292,28 @@ static void rna_def_material_colors(StructRNA *srna)
RNA_def_property_update(prop, 0, "rna_Material_update");
}
-static void rna_def_material_diffuse(StructRNA *srna)
-{
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_diff_shader_items[] = {
- {MA_DIFF_LAMBERT, "LAMBERT", 0, "Lambert", "Use a Lambertian shader"},
- {MA_DIFF_ORENNAYAR, "OREN_NAYAR", 0, "Oren-Nayar", "Use an Oren-Nayar shader"},
- {MA_DIFF_TOON, "TOON", 0, "Toon", "Use a toon shader"},
- {MA_DIFF_MINNAERT, "MINNAERT", 0, "Minnaert", "Use a Minnaert shader"},
- {MA_DIFF_FRESNEL, "FRESNEL", 0, "Fresnel", "Use a Fresnel shader"},
- {0, NULL, 0, NULL, NULL}
- };
-
- prop = RNA_def_property(srna, "diffuse_shader", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "diff_shader");
- RNA_def_property_enum_items(prop, prop_diff_shader_items);
- RNA_def_property_ui_text(prop, "Diffuse Shader Model", "");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_intensity", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "ref");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Diffuse Intensity", "Amount of diffuse reflection");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "roughness", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 3.14f);
- RNA_def_property_ui_text(prop, "Roughness", "Oren-Nayar Roughness");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_toon_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "param[0]");
- RNA_def_property_range(prop, 0.0f, 3.14f);
- RNA_def_property_ui_text(prop, "Diffuse Toon Size", "Size of diffuse toon area");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_toon_smooth", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "param[1]");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Diffuse Toon Smooth", "Smoothness of diffuse toon area");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_fresnel", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "param[1]");
- RNA_def_property_range(prop, 0.0f, 5.0f);
- RNA_def_property_ui_text(prop, "Diffuse Fresnel", "Power of Fresnel");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "diffuse_fresnel_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "param[0]");
- RNA_def_property_range(prop, 0.0f, 5.0f);
- RNA_def_property_ui_text(prop, "Diffuse Fresnel Factor", "Blending factor of Fresnel");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "darkness", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 2.0f);
- RNA_def_property_ui_text(prop, "Darkness", "Minnaert darkness");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
static void rna_def_material_raymirror(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
- static const EnumPropertyItem prop_fadeto_mir_items[] = {
- {MA_RAYMIR_FADETOSKY, "FADE_TO_SKY", 0, "Sky", ""},
- {MA_RAYMIR_FADETOMAT, "FADE_TO_MATERIAL", 0, "Material", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
srna = RNA_def_struct(brna, "MaterialRaytraceMirror", NULL);
RNA_def_struct_sdna(srna, "Material");
RNA_def_struct_nested(brna, srna, "Material");
RNA_def_struct_ui_text(srna, "Material Raytrace Mirror", "Raytraced reflection settings for a Material data-block");
- prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAYMIRROR); /* use bitflags */
- RNA_def_property_ui_text(prop, "Enabled", "Enable raytraced reflections");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
prop = RNA_def_property(srna, "reflect_factor", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "ray_mirror");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Reflectivity", "Amount of mirror reflection for raytrace");
RNA_def_property_update(prop, 0, "rna_Material_update");
- prop = RNA_def_property(srna, "fresnel", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "fresnel_mir");
- RNA_def_property_range(prop, 0.0f, 5.0f);
- RNA_def_property_ui_text(prop, "Fresnel", "Power of Fresnel for mirror reflection");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "fresnel_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "fresnel_mir_i");
- RNA_def_property_range(prop, 0.0f, 5.0f);
- RNA_def_property_ui_text(prop, "Fresnel Factor", "Blending factor for Fresnel");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
prop = RNA_def_property(srna, "gloss_factor", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "gloss_mir");
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Gloss Amount",
"The shininess of the reflection (values < 1.0 give diffuse, blurry reflections)");
RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "gloss_anisotropic", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "aniso_gloss_mir");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Gloss Anisotropy",
- "The shape of the reflection, from 0.0 (circular) to 1.0 "
- "(fully stretched along the tangent");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "gloss_samples", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "samp_gloss_mir");
- RNA_def_property_range(prop, 0, 1024);
- RNA_def_property_ui_text(prop, "Gloss Samples", "Number of cone samples averaged for blurry reflections");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "gloss_threshold", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "adapt_thresh_mir");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Gloss Threshold",
- "Threshold for adaptive sampling (if a sample contributes less than "
- "this amount [as a percentage], sampling is stopped)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "ray_depth");
- RNA_def_property_ui_range(prop, 0, 100, 1, 3);
- RNA_def_property_ui_text(prop, "Depth", "Maximum allowed number of light inter-reflections");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "dist_mir");
- RNA_def_property_range(prop, 0.0f, 10000.0f);
- RNA_def_property_ui_text(prop, "Maximum Distance",
- "Maximum distance of reflected rays (reflections further than this "
- "range fade to sky color or material color)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "fade_to", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "fadeto_mir");
- RNA_def_property_enum_items(prop, prop_fadeto_mir_items);
- RNA_def_property_ui_text(prop, "Fade-out Color",
- "The color that rays with no intersection within the Max Distance take "
- "(material color can be best for indoor scenes, sky color for outdoor)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-static void rna_def_material_raytra(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "MaterialRaytraceTransparency", NULL);
- RNA_def_struct_sdna(srna, "Material");
- RNA_def_struct_nested(brna, srna, "Material");
- RNA_def_struct_ui_text(srna, "Material Raytrace Transparency",
- "Raytraced refraction settings for a Material data-block");
-
- prop = RNA_def_property(srna, "ior", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ang");
- RNA_def_property_range(prop, 0.25f, 4.0f);
- RNA_def_property_ui_text(prop, "IOR", "Angular index of refraction for raytraced refraction");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "fresnel", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "fresnel_tra");
- RNA_def_property_range(prop, 0.0f, 5.0f);
- RNA_def_property_ui_text(prop, "Fresnel", "Power of Fresnel for transparency (Ray or ZTransp)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "fresnel_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "fresnel_tra_i");
- RNA_def_property_range(prop, 1.0f, 5.0f);
- RNA_def_property_ui_text(prop, "Fresnel Factor", "Blending factor for Fresnel");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "gloss_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "gloss_tra");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Gloss Amount",
- "The clarity of the refraction. Values < 1.0 give diffuse, blurry refractions");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "gloss_samples", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "samp_gloss_tra");
- RNA_def_property_range(prop, 0, 1024);
- RNA_def_property_ui_text(prop, "Gloss Samples", "Number of cone samples averaged for blurry refractions");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "gloss_threshold", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "adapt_thresh_tra");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Gloss Threshold",
- "Threshold for adaptive sampling. If a sample contributes less than "
- "this amount (as a percentage), sampling is stopped");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "ray_depth_tra");
- RNA_def_property_ui_range(prop, 0, 100, 1, 3);
- RNA_def_property_ui_text(prop, "Depth", "Maximum allowed number of light inter-refractions");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "filter", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "filter");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Filter",
- "Amount to blend in the material's diffuse color in raytraced "
- "transparency (simulating absorption)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "depth_max", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "tx_limit");
- RNA_def_property_range(prop, 0.0f, 100.0f);
- RNA_def_property_ui_text(prop, "Limit",
- "Maximum depth for light to travel through the transparent material "
- "before becoming fully filtered (0.0 is disabled)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "falloff", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "tx_falloff");
- RNA_def_property_range(prop, 0.1f, 10.0f);
- RNA_def_property_ui_text(prop, "Falloff", "Falloff power for transmissivity filter effect (1.0 is linear)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-static void rna_def_material_volume(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_lighting_items[] = {
- {MA_VOL_SHADE_SHADELESS, "SHADELESS", 0, "Shadeless", "Do not calculate lighting and shadows"},
- {MA_VOL_SHADE_SHADOWED, "SHADOWED", 0, "Shadowed", ""},
- {MA_VOL_SHADE_SHADED, "SHADED", 0, "Shaded", ""},
- {MA_VOL_SHADE_MULTIPLE, "MULTIPLE_SCATTERING", 0, "Multiple Scattering", ""},
- {MA_VOL_SHADE_SHADEDPLUSMULTIPLE, "SHADED_PLUS_MULTIPLE_SCATTERING", 0, "Shaded + Multiple Scattering", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_stepsize_items[] = {
- {MA_VOL_STEP_RANDOMIZED, "RANDOMIZED", 0, "Randomized", ""},
- {MA_VOL_STEP_CONSTANT, "CONSTANT", 0, "Constant", ""},
- /*{MA_VOL_STEP_ADAPTIVE, "ADAPTIVE", 0, "Adaptive", ""}, */
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "MaterialVolume", NULL);
- RNA_def_struct_sdna(srna, "VolumeSettings");
- RNA_def_struct_nested(brna, srna, "Material");
- RNA_def_struct_ui_text(srna, "Material Volume", "Volume rendering settings for a Material data-block");
-
- prop = RNA_def_property(srna, "step_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "stepsize_type");
- RNA_def_property_enum_items(prop, prop_stepsize_items);
- RNA_def_property_ui_text(prop, "Step Calculation", "Method of calculating the steps through the volume");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "step_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "stepsize");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.001f, 1.0f, 1, 3);
- RNA_def_property_ui_text(prop, "Step Size", "Distance between subsequent volume depth samples");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "light_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "shade_type");
- RNA_def_property_enum_items(prop, prop_lighting_items);
- RNA_def_property_ui_text(prop, "Lighting Mode",
- "Method of shading, attenuating, and scattering light through the volume");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_external_shadows", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "shadeflag", MA_VOL_RECV_EXT_SHADOW); /* use bitflags */
- RNA_def_property_ui_text(prop, "External Shadows", "Receive shadows from sources outside the volume (temporary)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_light_cache", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "shadeflag", MA_VOL_PRECACHESHADING); /* use bitflags */
- RNA_def_property_ui_text(prop, "Light Cache",
- "Pre-calculate the shading information into a voxel grid, "
- "speeds up shading at slightly less accuracy");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "cache_resolution", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "precache_resolution");
- RNA_def_property_range(prop, 1, 1024);
- RNA_def_property_ui_text(prop, "Resolution",
- "Resolution of the voxel grid, low resolutions are faster, "
- "high resolutions use more memory");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "ms_diffusion", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ms_diff");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_text(prop, "Diffusion", "Diffusion factor, the strength of the blurring effect");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "ms_spread", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ms_spread");
- RNA_def_property_range(prop, 0, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.0f, 1.0f, 1, 3);
- RNA_def_property_ui_text(prop, "Spread", "Proportional distance over which the light is diffused");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "ms_intensity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ms_intensity");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_text(prop, "Intensity", "Multiplier for multiple scattered light energy");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "depth_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "depth_cutoff");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Depth Cutoff",
- "Stop ray marching early if transmission drops below this luminance - "
- "higher values give speedups in dense volumes at the expense of accuracy");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "density", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "density");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Density", "The base density of the volume");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "density_scale", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "density_scale");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
- RNA_def_property_ui_text(prop, "Density Scale", "Multiplier for the material's density");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "scattering", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "scattering");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
- RNA_def_property_ui_text(prop, "Scattering",
- "Amount of light that gets scattered out by the volume - "
- "the more out-scattering, the shallower the light will penetrate");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "transmission_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "transmission_col");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Transmission Color",
- "Result color of the volume, after other light has been scattered/absorbed");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "reflection_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "reflection_col");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Reflection Color",
- "Color of light scattered out of the volume (does not affect transmission)");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "reflection", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "reflection");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.0f, 100.0f, 1, 3);
- RNA_def_property_ui_text(prop, "Reflection",
- "Multiplier to make out-scattered light brighter or darker (non-physically correct)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "emission_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "emission_col");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Emission Color", "Color of emitted light");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "emission", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "emission");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.0f, 10.0f, 1, 3);
- RNA_def_property_ui_text(prop, "Emission", "Amount of light that gets emitted by the volume");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "asymmetry", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "asymmetry");
- RNA_def_property_range(prop, -1.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Asymmetry",
- "Back scattering (-1.0) to Forward scattering (1.0) and the range in between");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-
-static void rna_def_material_halo(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "MaterialHalo", NULL);
- RNA_def_struct_sdna(srna, "Material");
- RNA_def_struct_nested(brna, srna, "Material");
- RNA_def_struct_ui_text(srna, "Material Halo", "Halo particle effect settings for a Material data-block");
-
- prop = RNA_def_property(srna, "size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "hasize");
- RNA_def_property_range(prop, 0.0f, 100.0f);
- RNA_def_property_ui_text(prop, "Size", "Dimension of the halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "hardness", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "har");
- RNA_def_property_range(prop, 0, 127);
- RNA_def_property_ui_text(prop, "Hardness", "Hardness of the halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "add", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "add");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Add", "Strength of the add effect");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "ring_count", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "ringc");
- RNA_def_property_range(prop, 0, 24);
- RNA_def_property_ui_text(prop, "Rings", "Number of rings rendered over the halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "line_count", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "linec");
- RNA_def_property_range(prop, 0, 250);
- RNA_def_property_ui_text(prop, "Line Number", "Number of star shaped lines rendered over the halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "star_tip_count", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "starc");
- RNA_def_property_range(prop, 3, 50);
- RNA_def_property_ui_text(prop, "Star Tips", "Number of points on the star shaped halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "seed1");
- RNA_def_property_range(prop, 0, 255);
- RNA_def_property_ui_text(prop, "Seed", "Randomize ring dimension and line location");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_flare_mode", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_FLARE); /* use bitflags */
- RNA_def_property_ui_text(prop, "Flare", "Render halo as a lens flare");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "flare_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "flaresize");
- RNA_def_property_range(prop, 0.1f, 25.0f);
- RNA_def_property_ui_text(prop, "Flare Size", "Factor by which the flare is larger than the halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "flare_subflare_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "subsize");
- RNA_def_property_range(prop, 0.1f, 25.0f);
- RNA_def_property_ui_text(prop, "Flare Subsize", "Dimension of the sub-flares, dots and circles");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "flare_boost", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "flareboost");
- RNA_def_property_range(prop, 0.1f, 10.0f);
- RNA_def_property_ui_text(prop, "Flare Boost", "Give the flare extra strength");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "flare_seed", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "seed2");
- RNA_def_property_range(prop, 0, 255);
- RNA_def_property_ui_text(prop, "Flare Seed", "Offset in the flare seed table");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "flare_subflare_count", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "flarec");
- RNA_def_property_range(prop, 1, 32);
- RNA_def_property_ui_text(prop, "Flares Sub", "Number of sub-flares");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_ring", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_RINGS);
- RNA_def_property_ui_text(prop, "Rings", "Render rings over halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_lines", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_LINES);
- RNA_def_property_ui_text(prop, "Lines", "Render star shaped lines over halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_star", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_STAR);
- RNA_def_property_ui_text(prop, "Star", "Render halo as a star");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_texture", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALOTEX);
- RNA_def_property_ui_text(prop, "Texture", "Give halo a texture");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_vertex_normal", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALOPUNO);
- RNA_def_property_ui_text(prop, "Vertex Normal", "Use the vertex normal to specify the dimension of the halo");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_extreme_alpha", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_XALPHA);
- RNA_def_property_ui_text(prop, "Extreme Alpha", "Use extreme alpha");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_shaded", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_SHADE);
- RNA_def_property_ui_text(prop, "Shaded", "Let halo receive light and shadows from external objects");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_soft", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_HALO_SOFT);
- RNA_def_property_ui_text(prop, "Soft", "Soften the edges of halos at intersections with other geometry");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-static void rna_def_material_sss(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "MaterialSubsurfaceScattering", NULL);
- RNA_def_struct_sdna(srna, "Material");
- RNA_def_struct_nested(brna, srna, "Material");
- RNA_def_struct_ui_text(srna, "Material Subsurface Scattering",
- "Diffuse subsurface scattering settings for a Material data-block");
-
- prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_COLOR | PROP_UNIT_LENGTH);
- RNA_def_property_float_sdna(prop, NULL, "sss_radius");
- RNA_def_property_range(prop, 0.001, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.001, 10000, 1, 3);
- RNA_def_property_ui_text(prop, "Radius", "Mean red/green/blue scattering path length");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "sss_col");
- RNA_def_property_ui_text(prop, "Color", "Scattering color");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "error_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sss_error");
- RNA_def_property_ui_range(prop, 0.0001, 10, 1, 3);
- RNA_def_property_ui_text(prop, "Error Tolerance", "Error tolerance (low values are slower and higher quality)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sss_scale");
- RNA_def_property_ui_range(prop, 0.001, 1000, 1, 3);
- RNA_def_property_ui_text(prop, "Scale", "Object scale factor");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "ior", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sss_ior");
- RNA_def_property_ui_range(prop, 0.1, 2, 1, 3);
- RNA_def_property_ui_text(prop, "IOR", "Index of refraction (higher values are denser)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "color_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "sss_colfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Color Factor", "Blend factor for SSS colors");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "texture_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "sss_texfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Texture Factor", "Texture scattering blend factor");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "front", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sss_front");
- RNA_def_property_range(prop, 0, 2);
- RNA_def_property_ui_text(prop, "Front", "Front scattering weight");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "back", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sss_back");
- RNA_def_property_range(prop, 0, 10);
- RNA_def_property_ui_text(prop, "Back", "Back scattering weight");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "sss_flag", MA_DIFF_SSS);
- RNA_def_property_ui_text(prop, "Enabled", "Enable diffuse subsurface scattering effects in a material");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-static void rna_def_material_specularity(StructRNA *srna)
-{
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_specular_shader_items[] = {
- {MA_SPEC_COOKTORR, "COOKTORR", 0, "CookTorr", "Use a Cook-Torrance shader"},
- {MA_SPEC_PHONG, "PHONG", 0, "Phong", "Use a Phong shader"},
- {MA_SPEC_BLINN, "BLINN", 0, "Blinn", "Use a Blinn shader"},
- {MA_SPEC_TOON, "TOON", 0, "Toon", "Use a toon shader"},
- {MA_SPEC_WARDISO, "WARDISO", 0, "WardIso", "Use a Ward anisotropic shader"},
- {0, NULL, 0, NULL, NULL}
- };
-
- prop = RNA_def_property(srna, "specular_shader", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "spec_shader");
- RNA_def_property_enum_items(prop, prop_specular_shader_items);
- RNA_def_property_ui_text(prop, "Specular Shader Model", "");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_intensity", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "spec");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Specular Intensity", "How intense (bright) the specular reflection is");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- /* NOTE: "har", "param", etc are used for multiple purposes depending on
- * settings. This should be fixed in DNA once, for RNA we just expose them
- * multiple times, which may give somewhat strange changes in the outliner,
- * but in the UI they are never visible at the same time. */
-
- prop = RNA_def_property(srna, "specular_hardness", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "har");
- RNA_def_property_range(prop, 1, 511);
- RNA_def_property_ui_text(prop, "Specular Hardness", "How hard (sharp) the specular reflection is");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "specular_ior", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "refrac");
- RNA_def_property_range(prop, 1, 10);
- RNA_def_property_ui_text(prop, "Specular IOR", "Specular index of refraction");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_toon_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "param[2]");
- RNA_def_property_range(prop, 0.0f, 1.53f);
- RNA_def_property_ui_text(prop, "Specular Toon Size", "Size of specular toon area");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_toon_smooth", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "param[3]");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Specular Toon Smooth", "Smoothness of specular toon area");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "specular_slope", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "rms");
- RNA_def_property_range(prop, 0, 0.4);
- RNA_def_property_ui_text(prop, "Specular Slope", "The standard deviation of surface slope");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-static void rna_def_material_strand(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "MaterialStrand", NULL);
- RNA_def_struct_sdna(srna, "Material");
- RNA_def_struct_nested(brna, srna, "Material");
- RNA_def_struct_ui_text(srna, "Material Strand", "Strand settings for a Material data-block");
-
- prop = RNA_def_property(srna, "use_tangent_shading", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TANGENT_STR);
- RNA_def_property_ui_text(prop, "Tangent Shading", "Use direction of strands as normal for tangent-shading");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- /* this flag is only set when rendering, not to be edited manually */
- prop = RNA_def_property(srna, "use_surface_diffuse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_STR_SURFDIFF);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Surface Diffuse", "Make diffuse shading more similar to shading the surface");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "blend_distance", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "strand_surfnor");
- RNA_def_property_range(prop, 0, 10);
- RNA_def_property_ui_text(prop, "Blend Distance", "Worldspace distance over which to blend in the surface normal");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_blender_units", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_STR_B_UNITS);
- RNA_def_property_ui_text(prop, "Blender Units", "Use Blender units for widths instead of pixels");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "root_size", PROP_FLOAT, PROP_UNSIGNED);
- RNA_def_property_float_sdna(prop, NULL, "strand_sta");
- RNA_def_property_float_funcs(prop, NULL, NULL, "rna_MaterialStrand_start_size_range");
- RNA_def_property_ui_range(prop, 0, 10.0f, 10, 5);
- RNA_def_property_ui_text(prop, "Root Size", "Start size of strands in pixels or Blender units");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "tip_size", PROP_FLOAT, PROP_UNSIGNED);
- RNA_def_property_float_sdna(prop, NULL, "strand_end");
- RNA_def_property_ui_range(prop, 0, 10.0f, 10, 5);
- RNA_def_property_float_funcs(prop, NULL, NULL, "rna_MaterialStrand_end_size_range");
- RNA_def_property_ui_text(prop, "Tip Size", "End size of strands in pixels or Blender units");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "size_min", PROP_FLOAT, PROP_UNSIGNED);
- RNA_def_property_float_sdna(prop, NULL, "strand_min");
- RNA_def_property_range(prop, 0.001, 10);
- RNA_def_property_ui_text(prop, "Minimum Size", "Minimum size of strands in pixels");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "shape", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "strand_ease");
- RNA_def_property_range(prop, -0.9, 0.9);
- RNA_def_property_ui_text(prop, "Shape", "Positive values make strands rounder, negative ones make strands spiky");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "width_fade", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "strand_widthfade");
- RNA_def_property_range(prop, 0, 2);
- RNA_def_property_ui_text(prop, "Width Fade", "Transparency along the width of the strand");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "strand_uvname");
- RNA_def_property_ui_text(prop, "UV Map", "Name of UV map to override");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-}
-
-static void rna_def_material_physics(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "MaterialPhysics", NULL);
- RNA_def_struct_sdna(srna, "Material");
- RNA_def_struct_nested(brna, srna, "Material");
- RNA_def_struct_ui_text(srna, "Material Physics", "Physics settings for a Material data-block");
-
- prop = RNA_def_property(srna, "friction", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "friction");
- RNA_def_property_range(prop, 0, 100);
- RNA_def_property_ui_text(prop, "Friction", "Coulomb friction coefficient, when inside the physics distance area");
-
- prop = RNA_def_property(srna, "elasticity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "reflect");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Elasticity", "Elasticity of collisions");
-
- /* FH/Force Field Settings */
- prop = RNA_def_property(srna, "use_fh_normal", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "dynamode", MA_FH_NOR);
- RNA_def_property_ui_text(prop, "Align to Normal",
- "Align dynamic game objects along the surface normal, "
- "when inside the physics distance area");
-
- prop = RNA_def_property(srna, "fh_force", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "fh");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_range(prop, 0.0, 1.0, 10, 2);
- RNA_def_property_ui_text(prop, "Force", "Upward spring force, when inside the physics distance area");
-
- prop = RNA_def_property(srna, "fh_distance", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "fhdist");
- RNA_def_property_range(prop, 0, 20);
- RNA_def_property_ui_text(prop, "Distance", "Distance of the physics area");
-
- prop = RNA_def_property(srna, "fh_damping", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "xyfrict");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Damping", "Damping of the spring force, when inside the physics distance area");
}
void RNA_def_material(BlenderRNA *brna)
@@ -1772,20 +321,6 @@ void RNA_def_material(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
- static const EnumPropertyItem prop_type_items[] = {
- {MA_TYPE_SURFACE, "SURFACE", 0, "Surface", "Render object as a surface"},
- {MA_TYPE_WIRE, "WIRE", 0, "Wire", "Render the edges of faces as wires (not supported in raytracing)"},
- {MA_TYPE_VOLUME, "VOLUME", 0, "Volume", "Render object as a volume"},
- {MA_TYPE_HALO, "HALO", 0, "Halo", "Render object as halo particles"},
- {0, NULL, 0, NULL, NULL}
- };
- static const EnumPropertyItem transparency_items[] = {
- {0, "MASK", 0, "Mask", "Mask the background"},
- {MA_ZTRANSP, "Z_TRANSPARENCY", 0, "Z Transparency", "Use alpha buffer for transparent faces"},
- {MA_RAYTRANSP, "RAYTRACE", 0, "Raytrace", "Use raytracing for transparent refraction rendering"},
- {0, NULL, 0, NULL, NULL}
- };
-
/* Render Preview Types */
static const EnumPropertyItem preview_type_items[] = {
{MA_FLAT, "FLAT", ICON_MATPLANE, "Flat", "Flat XY plane"},
@@ -1797,11 +332,21 @@ void RNA_def_material(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem prop_shadows_only_items[] = {
- {MA_SO_OLD, "SHADOW_ONLY_OLD", 0, "Shadow and Distance", "Old shadow only method"},
- {MA_SO_SHADOW, "SHADOW_ONLY", 0, "Shadow Only", "Improved shadow only method"},
- {MA_SO_SHADED, "SHADOW_ONLY_SHADED", 0, "Shadow and Shading",
- "Improved shadow only method which also renders lightless areas as shadows"},
+ static EnumPropertyItem prop_eevee_blend_items[] = {
+ {MA_BM_SOLID, "OPAQUE", 0, "Opaque", "Render surface without transparency"},
+ {MA_BM_ADD, "ADD", 0, "Additive", "Render surface and blend the result with additive blending"},
+ {MA_BM_MULTIPLY, "MULTIPLY", 0, "Multiply", "Render surface and blend the result with multiplicative blending"},
+ {MA_BM_CLIP, "CLIP", 0, "Alpha Clip", "Use the alpha threshold to clip the visibility (binary visibility)"},
+ {MA_BM_HASHED, "HASHED", 0, "Alpha Hashed", "Use noise to dither the binary visibility (works well with multi-samples)"},
+ {MA_BM_BLEND, "BLEND", 0, "Alpha Blend", "Render polygon transparent, depending on alpha channel of the texture"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ static EnumPropertyItem prop_eevee_blend_shadow_items[] = {
+ {MA_BS_NONE, "NONE", 0, "None", "Material will cast no shadow"},
+ {MA_BS_SOLID, "OPAQUE", 0, "Opaque", "Material will cast shadows without transparency"},
+ {MA_BS_CLIP, "CLIP", 0, "Clip", "Use the alpha threshold to clip the visibility (binary visibility)"},
+ {MA_BS_HASHED, "HASHED", 0, "Hashed", "Use noise to dither the binary visibility and use filtering to reduce the noise"},
{0, NULL, 0, NULL, NULL}
};
@@ -1810,234 +355,63 @@ void RNA_def_material(BlenderRNA *brna)
"Material data-block to define the appearance of geometric objects for rendering");
RNA_def_struct_ui_icon(srna, ICON_MATERIAL_DATA);
- prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "material_type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Type", "Material type defining how the object is rendered");
- RNA_def_property_enum_funcs(prop, NULL, "rna_Material_type_set", NULL);
+ /* Blending (only Eevee for now) */
+ prop = RNA_def_property(srna, "blend_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, prop_eevee_blend_items);
+ RNA_def_property_ui_text(prop, "Blend Mode", "Blend Mode for Transparent Faces");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "use_transparency", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TRANSP);
- RNA_def_property_ui_text(prop, "Transparency", "Render material as transparent");
+ prop = RNA_def_property(srna, "transparent_shadow_method", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "blend_shadow");
+ RNA_def_property_enum_items(prop, prop_eevee_blend_shadow_items);
+ RNA_def_property_ui_text(prop, "Transparent Shadow", "Shadow method for transparent material");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "transparency_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, transparency_items);
- RNA_def_property_ui_text(prop, "Transparency Method", "Method to use for rendering transparency");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- /* For Preview Render */
- prop = RNA_def_property(srna, "preview_render_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "pr_type");
- RNA_def_property_enum_items(prop, preview_type_items);
- RNA_def_property_ui_text(prop, "Preview render type", "Type of preview render");
- RNA_def_property_update(prop, 0, "rna_Material_update_previews");
-
- prop = RNA_def_property(srna, "ambient", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "amb");
+ prop = RNA_def_property(srna, "alpha_threshold", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Ambient", "Amount of global ambient color the material receives");
- RNA_def_property_update(prop, 0, "rna_Material_update");
+ RNA_def_property_ui_text(prop, "Clip Threshold", "A pixel is rendered only if its alpha value is above this threshold");
+ RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "emit", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0, FLT_MAX);
- RNA_def_property_ui_range(prop, 0, 2.0f, 1, 2);
- RNA_def_property_ui_text(prop, "Emit", "Amount of light to emit");
+ prop = RNA_def_property(srna, "transparent_hide_backside", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "blend_flag", MA_BL_HIDE_BACKSIDE);
+ RNA_def_property_ui_text(prop, "Hide Backside", "Limit transparency to a single layer "
+ "(avoids transparency sorting problems)");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "translucency", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Translucency", "Amount of diffuse shading on the back side");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_cubic", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_CUBIC);
- RNA_def_property_ui_text(prop, "Cubic Interpolation",
- "Use cubic interpolation for diffuse values, for smoother transitions");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_object_color", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_OBCOLOR);
- RNA_def_property_ui_text(prop, "Object Color", "Modulate the result with a per-object color");
+ prop = RNA_def_property(srna, "use_screen_refraction", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "blend_flag", MA_BL_SS_REFRACTION);
+ RNA_def_property_ui_text(prop, "Screen Space Refraction", "Use raytraced screen space refractions");
RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "shadow_ray_bias", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "sbias");
- RNA_def_property_range(prop, 0, 0.25);
- RNA_def_property_ui_text(prop, "Shadow Ray Bias",
- "Shadow raytracing bias to prevent terminator problems on shadow boundary");
-
- prop = RNA_def_property(srna, "shadow_buffer_bias", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "lbias");
- RNA_def_property_range(prop, 0, 10);
- RNA_def_property_ui_text(prop, "Shadow Buffer Bias", "Factor to multiply shadow buffer bias with (0 is ignore)");
-
- prop = RNA_def_property(srna, "shadow_cast_alpha", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "shad_alpha");
- RNA_def_property_range(prop, 0.001, 1);
- RNA_def_property_ui_text(prop, "Shadow Casting Alpha",
- "Shadow casting alpha, in use for Irregular and Deep shadow buffer");
- RNA_def_property_update(prop, 0, "rna_Material_update");
+ prop = RNA_def_property(srna, "use_screen_subsurface", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "blend_flag", MA_BL_SS_SUBSURFACE);
+ RNA_def_property_ui_text(prop, "Screen Space Subsurface Scattering", "Use post process subsurface scattering");
+ RNA_def_property_update(prop, 0, "rna_Material_draw_update");
- prop = RNA_def_property(srna, "light_group", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "group");
- RNA_def_property_struct_type(prop, "Group");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Light Group", "Limit lighting to lamps in this Group");
- RNA_def_property_update(prop, 0, "rna_Material_update");
+ prop = RNA_def_property(srna, "use_sss_translucency", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "blend_flag", MA_BL_TRANSLUCENCY);
+ RNA_def_property_ui_text(prop, "Subsurface Translucency", "Add translucency effect to subsurface");
+ RNA_def_property_update(prop, 0, "rna_Material_draw_update");
+
+ prop = RNA_def_property(srna, "refraction_depth", PROP_FLOAT, PROP_DISTANCE);
+ RNA_def_property_float_sdna(prop, NULL, "refract_depth");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_text(prop, "Refraction Depth", "Approximate the thickness of the object to compute two refraction "
+ "event (0 is disabled)");
+ RNA_def_property_update(prop, 0, "rna_Material_draw_update");
+ /* For Preview Render */
+ prop = RNA_def_property(srna, "preview_render_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "pr_type");
+ RNA_def_property_enum_items(prop, preview_type_items);
+ RNA_def_property_ui_text(prop, "Preview render type", "Type of preview render");
+ RNA_def_property_update(prop, 0, "rna_Material_update_previews");
+
prop = RNA_def_property(srna, "pass_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "index");
RNA_def_property_ui_text(prop, "Pass Index", "Index number for the \"Material Index\" render pass");
RNA_def_property_update(prop, NC_OBJECT, "rna_Material_update");
- /* flags */
-
- prop = RNA_def_property(srna, "use_light_group_exclusive", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_GROUP_NOLAY);
- RNA_def_property_ui_text(prop, "Light Group Exclusive",
- "Material uses the light group exclusively - these lamps are excluded "
- "from other scene lighting");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_light_group_local", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_GROUP_LOCAL);
- RNA_def_property_ui_text(prop, "Light Group Local", "When linked in, material uses local light group with the same name");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_raytrace", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TRACEBLE);
- RNA_def_property_ui_text(prop, "Traceable",
- "Include this material and geometry that uses it in raytracing calculations");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_shadows", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHADOW);
- RNA_def_property_ui_text(prop, "Shadows", "Allow this material to receive shadows");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_shadeless", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHLESS);
- RNA_def_property_ui_text(prop, "Shadeless", "Make this material insensitive to light or shadow");
- RNA_def_property_update(prop, 0, "rna_Material_draw_update");
-
- prop = RNA_def_property(srna, "use_vertex_color_light", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_VERTEXCOL);
- RNA_def_property_ui_text(prop, "Vertex Color Light", "Add vertex colors as additional lighting");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_vertex_color_paint", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_VERTEXCOLP);
- RNA_def_property_ui_text(prop, "Vertex Color Paint",
- "Replace object base color with vertex colors (multiply with "
- "'texture face' face assigned textures)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "invert_z", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ZINV);
- RNA_def_property_ui_text(prop, "Invert Z Depth",
- "Render material's faces with an inverted Z buffer (scanline only)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "offset_z", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "zoffs");
- RNA_def_property_ui_text(prop, "Z Offset", "Give faces an artificial offset in the Z buffer for Z transparency");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_sky", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ENV);
- RNA_def_property_ui_text(prop, "Sky",
- "Render this material with zero alpha, with sky background in place (scanline only)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_only_shadow", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ONLYSHADOW);
- RNA_def_property_ui_text(prop, "Only Shadow",
- "Render shadows as the material's alpha value, making the material "
- "transparent except for shadowed areas");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "shadow_only_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "shadowonly_flag");
- RNA_def_property_enum_items(prop, prop_shadows_only_items);
- RNA_def_property_ui_text(prop, "Shadow Type", "How to draw shadows");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_face_texture", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_FACETEXTURE);
- RNA_def_property_ui_text(prop, "Face Textures",
- "Replace the object's base color with color from UV map image textures");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_face_texture_alpha", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_FACETEXTURE_ALPHA);
- RNA_def_property_ui_text(prop, "Face Textures Alpha",
- "Replace the object's base alpha value with alpha from UV map image textures");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_cast_shadows", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode2", MA_CASTSHADOW);
- RNA_def_property_ui_text(prop, "Cast Shadows",
- "Allow this material to cast shadows");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_cast_shadows_only", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_ONLYCAST);
- RNA_def_property_ui_text(prop, "Cast Shadows Only",
- "Make objects with this material appear invisible (not rendered), only casting shadows");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_mist", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "mode", MA_NOMIST);
- RNA_def_property_ui_text(prop, "Use Mist", "Use mist with this material (in world settings)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_transparent_shadows", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHADOW_TRA);
- RNA_def_property_ui_text(prop, "Receive Transparent Shadows",
- "Allow this object to receive transparent shadows cast through other objects");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_ray_shadow_bias", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_RAYBIAS);
- RNA_def_property_ui_text(prop, "Ray Shadow Bias",
- "Prevent raytraced shadow errors on surfaces with smooth shaded normals "
- "(terminator problem)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_full_oversampling", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_FULL_OSA);
- RNA_def_property_ui_text(prop, "Full Oversampling",
- "Force this material to render full shading/textures for all anti-aliasing samples");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_cast_buffer_shadows", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_SHADBUF);
- RNA_def_property_ui_text(prop, "Cast Buffer Shadows",
- "Allow this material to cast shadows from shadow buffer lamps");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_cast_approximate", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "shade_flag", MA_APPROX_OCCLUSION);
- RNA_def_property_ui_text(prop, "Cast Approximate",
- "Allow this material to cast shadows when using approximate ambient occlusion");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_tangent_shading", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", MA_TANGENT_V);
- RNA_def_property_ui_text(prop, "Tangent Shading",
- "Use the material's tangent vector instead of the normal for shading "
- "- for anisotropic shading effects");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
- prop = RNA_def_property(srna, "use_uv_project", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapflag", MA_MAPFLAG_UVPROJECT);
- RNA_def_property_ui_text(prop, "UV Project",
- "Use to ensure UV interpolation is correct for camera projections (use with UV project modifier)");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
/* nested structs */
prop = RNA_def_property(srna, "raytrace_mirror", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
@@ -2045,49 +419,6 @@ void RNA_def_material(BlenderRNA *brna)
RNA_def_property_pointer_funcs(prop, "rna_Material_mirror_get", NULL, NULL, NULL);
RNA_def_property_ui_text(prop, "Raytrace Mirror", "Raytraced reflection settings for the material");
- prop = RNA_def_property(srna, "raytrace_transparency", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "MaterialRaytraceTransparency");
- RNA_def_property_pointer_funcs(prop, "rna_Material_transp_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Raytrace Transparency", "Raytraced transparency settings for the material");
-
- prop = RNA_def_property(srna, "volume", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "vol");
- RNA_def_property_struct_type(prop, "MaterialVolume");
- RNA_def_property_ui_text(prop, "Volume", "Volume settings for the material");
-
- prop = RNA_def_property(srna, "halo", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "MaterialHalo");
- RNA_def_property_pointer_funcs(prop, "rna_Material_halo_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Halo", "Halo settings for the material");
-
- prop = RNA_def_property(srna, "subsurface_scattering", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "MaterialSubsurfaceScattering");
- RNA_def_property_pointer_funcs(prop, "rna_Material_sss_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Subsurface Scattering", "Subsurface scattering settings for the material");
-
- prop = RNA_def_property(srna, "strand", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "MaterialStrand");
- RNA_def_property_pointer_funcs(prop, "rna_Material_strand_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Strand", "Strand settings for the material");
-
- prop = RNA_def_property(srna, "physics", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "MaterialPhysics");
- RNA_def_property_pointer_funcs(prop, "rna_Material_physics_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Physics", "Game physics settings");
-
- /* game settings */
- prop = RNA_def_property(srna, "game_settings", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "game");
- RNA_def_property_struct_type(prop, "MaterialGameSettings");
- RNA_def_property_ui_text(prop, "Game Settings", "Game material settings");
-
/* nodetree */
prop = RNA_def_property(srna, "node_tree", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "nodetree");
@@ -2100,43 +431,12 @@ void RNA_def_material(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Use Nodes", "Use shader nodes to render the material");
RNA_def_property_update(prop, 0, "rna_Material_use_nodes_update");
- prop = RNA_def_property(srna, "active_node_material", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Material");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_pointer_funcs(prop, "rna_Material_active_node_material_get",
- "rna_Material_active_node_material_set", NULL, NULL);
- RNA_def_property_ui_text(prop, "Material", "Active node material");
- RNA_def_property_update(prop, NC_MATERIAL, NULL);
-
/* common */
rna_def_animdata_common(srna);
- rna_def_mtex_common(brna, srna, "rna_Material_mtex_begin", "rna_Material_active_texture_get",
- "rna_Material_active_texture_set", "rna_Material_active_texture_editable",
- "MaterialTextureSlot", "MaterialTextureSlots", "rna_Material_update", "rna_Material_update");
-
rna_def_texpaint_slots(brna, srna);
- /* only material has this one */
- prop = RNA_def_property(srna, "use_textures", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "septex", 1);
- RNA_def_property_array(prop, 18);
- RNA_def_property_ui_text(prop, "Use Textures", "Enable/Disable each texture");
- RNA_def_property_update(prop, 0, "rna_Material_update");
-
rna_def_material_colors(srna);
- rna_def_material_diffuse(srna);
- rna_def_material_specularity(srna);
-
- /* nested structs */
rna_def_material_raymirror(brna);
- rna_def_material_raytra(brna);
- rna_def_material_volume(brna);
- rna_def_material_halo(brna);
- rna_def_material_sss(brna);
- rna_def_material_mtex(brna);
- rna_def_material_strand(brna);
- rna_def_material_physics(brna);
- rna_def_material_gamesettings(brna);
RNA_api_material(srna);
}
@@ -2219,9 +519,9 @@ static void rna_def_tex_slot(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "UV Map", "Name of UV map");
RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Material_update");
- prop = RNA_def_property(srna, "index", PROP_INT, PROP_NONE);
+ prop = RNA_def_property(srna, "valid", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Index", "Index of MTex slot in the material");
+ RNA_def_property_ui_text(prop, "Valid", "Slot has a valid image and UV map");
}
diff --git a/source/blender/makesrna/intern/rna_mesh.c b/source/blender/makesrna/intern/rna_mesh.c
index e115485b192..9ec196034f3 100644
--- a/source/blender/makesrna/intern/rna_mesh.c
+++ b/source/blender/makesrna/intern/rna_mesh.c
@@ -68,11 +68,12 @@ const EnumPropertyItem rna_enum_mesh_delimit_mode_items[] = {
#include "BLI_math.h"
#include "BKE_customdata.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_mesh.h"
#include "BKE_report.h"
+#include "DEG_depsgraph.h"
+
#include "ED_mesh.h" /* XXX Bad level call */
#include "WM_api.h"
@@ -186,12 +187,10 @@ static void rna_MeshEdgeLayer_name_set(PointerRNA *ptr, const char *value)
rna_cd_layer_name_set(rna_mesh_edata(ptr), (CustomDataLayer *)ptr->data, value);
}
#endif
-#if 0
static void rna_MeshPolyLayer_name_set(PointerRNA *ptr, const char *value)
{
rna_cd_layer_name_set(rna_mesh_pdata(ptr), (CustomDataLayer *)ptr->data, value);
}
-#endif
static void rna_MeshLoopLayer_name_set(PointerRNA *ptr, const char *value)
{
rna_cd_layer_name_set(rna_mesh_ldata(ptr), (CustomDataLayer *)ptr->data, value);
@@ -224,7 +223,7 @@ static void rna_Mesh_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
/* cheating way for importers to avoid slow updates */
if (id->us > 0) {
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, id);
}
}
@@ -238,6 +237,20 @@ static void rna_Mesh_update_data_edit_color(Main *bmain, Scene *scene, PointerRN
}
}
+static void rna_Mesh_update_data_edit_weight(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ BKE_mesh_batch_cache_dirty(rna_mesh(ptr), BKE_MESH_BATCH_DIRTY_ALL);
+
+ rna_Mesh_update_data(bmain, scene, ptr);
+}
+
+
+static void rna_Mesh_update_data_edit_active_color(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ BKE_mesh_batch_cache_dirty(rna_mesh(ptr), BKE_MESH_BATCH_DIRTY_ALL);
+
+ rna_Mesh_update_data(bmain, scene, ptr);
+}
static void rna_Mesh_update_select(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
ID *id = ptr->id.data;
@@ -263,6 +276,9 @@ static void rna_Mesh_update_vertmask(Main *bmain, Scene *scene, PointerRNA *ptr)
if ((me->editflag & ME_EDIT_PAINT_VERT_SEL) && (me->editflag & ME_EDIT_PAINT_FACE_SEL)) {
me->editflag &= ~ME_EDIT_PAINT_FACE_SEL;
}
+
+ BKE_mesh_batch_cache_dirty(me, BKE_MESH_BATCH_DIRTY_ALL);
+
rna_Mesh_update_draw(bmain, scene, ptr);
}
@@ -272,6 +288,9 @@ static void rna_Mesh_update_facemask(Main *bmain, Scene *scene, PointerRNA *ptr)
if ((me->editflag & ME_EDIT_PAINT_VERT_SEL) && (me->editflag & ME_EDIT_PAINT_FACE_SEL)) {
me->editflag &= ~ME_EDIT_PAINT_VERT_SEL;
}
+
+ BKE_mesh_batch_cache_dirty(me, BKE_MESH_BATCH_DIRTY_ALL);
+
rna_Mesh_update_draw(bmain, scene, ptr);
}
@@ -758,13 +777,6 @@ static void rna_CustomDataLayer_active_set(PointerRNA *ptr, CustomData *data, in
if (render) CustomData_set_layer_render(data, type, n);
else CustomData_set_layer_active(data, type, n);
- /* sync loop layer */
- if (type == CD_MTEXPOLY) {
- CustomData *ldata = rna_mesh_ldata(ptr);
- if (render) CustomData_set_layer_render(ldata, CD_MLOOPUV, n);
- else CustomData_set_layer_active(ldata, CD_MLOOPUV, n);
- }
-
BKE_mesh_update_customdata_pointers(me, true);
}
@@ -869,6 +881,36 @@ static int rna_MeshUVLoopLayer_data_length(PointerRNA *ptr)
return (me->edit_btmesh) ? 0 : me->totloop;
}
+static int rna_MeshUVLoopLayer_active_render_get(PointerRNA *ptr)
+{
+ return rna_CustomDataLayer_active_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPUV, 1);
+}
+
+static int rna_MeshUVLoopLayer_active_get(PointerRNA *ptr)
+{
+ return rna_CustomDataLayer_active_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPUV, 0);
+}
+
+static int rna_MeshUVLoopLayer_clone_get(PointerRNA *ptr)
+{
+ return rna_CustomDataLayer_clone_get(ptr, rna_mesh_ldata(ptr), CD_MLOOPUV);
+}
+
+static void rna_MeshUVLoopLayer_active_render_set(PointerRNA *ptr, int value)
+{
+ rna_CustomDataLayer_active_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPUV, 1);
+}
+
+static void rna_MeshUVLoopLayer_active_set(PointerRNA *ptr, int value)
+{
+ rna_CustomDataLayer_active_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPUV, 0);
+}
+
+static void rna_MeshUVLoopLayer_clone_set(PointerRNA *ptr, int value)
+{
+ rna_CustomDataLayer_clone_set(ptr, rna_mesh_ldata(ptr), value, CD_MLOOPUV);
+}
+
/* face uv_textures */
DEFINE_CUSTOMDATA_LAYER_COLLECTION(tessface_uv_texture, fdata, CD_MTFACE)
@@ -920,57 +962,6 @@ static void rna_MeshTextureFaceLayer_clone_set(PointerRNA *ptr, int value)
rna_CustomDataLayer_clone_set(ptr, rna_mesh_fdata(ptr), value, CD_MTFACE);
}
-/* poly uv_textures */
-
-DEFINE_CUSTOMDATA_LAYER_COLLECTION(uv_texture, pdata, CD_MTEXPOLY)
-DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(uv_texture, pdata, CD_MTEXPOLY, active, MeshTexturePolyLayer)
-DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(uv_texture, pdata, CD_MTEXPOLY, clone, MeshTexturePolyLayer)
-DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(uv_texture, pdata, CD_MTEXPOLY, stencil, MeshTexturePolyLayer)
-DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(uv_texture, pdata, CD_MTEXPOLY, render, MeshTexturePolyLayer)
-
-static void rna_MeshTexturePolyLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
-{
- Mesh *me = rna_mesh(ptr);
- CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
- rna_iterator_array_begin(iter, layer->data, sizeof(MTexPoly), (me->edit_btmesh) ? 0 : me->totpoly, 0, NULL);
-}
-
-static int rna_MeshTexturePolyLayer_data_length(PointerRNA *ptr)
-{
- Mesh *me = rna_mesh(ptr);
- return (me->edit_btmesh) ? 0 : me->totpoly;
-}
-
-static int rna_MeshTexturePolyLayer_active_render_get(PointerRNA *ptr)
-{
- return rna_CustomDataLayer_active_get(ptr, rna_mesh_pdata(ptr), CD_MTEXPOLY, 1);
-}
-
-static int rna_MeshTexturePolyLayer_active_get(PointerRNA *ptr)
-{
- return rna_CustomDataLayer_active_get(ptr, rna_mesh_pdata(ptr), CD_MTEXPOLY, 0);
-}
-
-static int rna_MeshTexturePolyLayer_clone_get(PointerRNA *ptr)
-{
- return rna_CustomDataLayer_clone_get(ptr, rna_mesh_pdata(ptr), CD_MTEXPOLY);
-}
-
-static void rna_MeshTexturePolyLayer_active_render_set(PointerRNA *ptr, int value)
-{
- rna_CustomDataLayer_active_set(ptr, rna_mesh_pdata(ptr), value, CD_MTEXPOLY, 1);
-}
-
-static void rna_MeshTexturePolyLayer_active_set(PointerRNA *ptr, int value)
-{
- rna_CustomDataLayer_active_set(ptr, rna_mesh_pdata(ptr), value, CD_MTEXPOLY, 0);
-}
-
-static void rna_MeshTexturePolyLayer_clone_set(PointerRNA *ptr, int value)
-{
- rna_CustomDataLayer_clone_set(ptr, rna_mesh_pdata(ptr), value, CD_MTEXPOLY);
-}
-
/* vertex_color_layers */
DEFINE_CUSTOMDATA_LAYER_COLLECTION(tessface_vertex_color, fdata, CD_MCOL)
@@ -1194,42 +1185,75 @@ static int rna_MeshPaintMaskLayer_data_length(PointerRNA *ptr)
/* End paint mask */
-static void rna_TexturePoly_image_set(PointerRNA *ptr, PointerRNA value)
+/* Face maps */
+
+DEFINE_CUSTOMDATA_LAYER_COLLECTION(face_map, pdata, CD_FACEMAP)
+DEFINE_CUSTOMDATA_LAYER_COLLECTION_ACTIVEITEM(face_map, pdata, CD_FACEMAP, active, MeshFaceMapLayer)
+
+static char *rna_MeshFaceMapLayer_path(PointerRNA *ptr)
{
- MTexPoly *tf = (MTexPoly *)ptr->data;
- ID *id = value.data;
+ CustomDataLayer *cdl = ptr->data;
+ char name_esc[sizeof(cdl->name) * 2];
+ BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
+ return BLI_sprintfN("face_maps[\"%s\"]", name_esc);
+}
- if (id) {
- /* special exception here, individual faces don't count
- * as reference, but we do ensure the refcount is not zero */
- if (id->us == 0)
- id_us_plus(id);
- else
- id_lib_extern(id);
+static void rna_MeshFaceMapLayer_data_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ Mesh *me = rna_mesh(ptr);
+ CustomDataLayer *layer = (CustomDataLayer *)ptr->data;
+ rna_iterator_array_begin(iter, layer->data, sizeof(int), me->totpoly, 0, NULL);
+}
+
+static int rna_MeshFaceMapLayer_data_length(PointerRNA *ptr)
+{
+ Mesh *me = rna_mesh(ptr);
+ return me->totpoly;
+}
+
+static PointerRNA rna_Mesh_face_map_new(struct Mesh *me, ReportList *reports, const char *name)
+{
+ if (BKE_mesh_ensure_facemap_customdata(me) == false) {
+ BKE_report(reports, RPT_ERROR, "Currently only single face-map layers are supported");
+ return PointerRNA_NULL;
}
- tf->tpage = (struct Image *)id;
+ CustomData *pdata = rna_mesh_pdata_helper(me);
+
+ int index = CustomData_get_layer_index(pdata, CD_FACEMAP);
+ BLI_assert(index != -1);
+ CustomDataLayer *cdl = &pdata->layers[index];
+ rna_cd_layer_name_set(pdata, cdl, name);
+
+ PointerRNA ptr;
+ RNA_pointer_create(&me->id, &RNA_MeshFaceMapLayer, cdl, &ptr);
+ return ptr;
}
-/* while this is supposed to be readonly,
- * keep it to support importers that only make tessfaces */
-static void rna_TextureFace_image_set(PointerRNA *ptr, PointerRNA value)
-{
- MTFace *tf = (MTFace *)ptr->data;
- ID *id = value.data;
-
- if (id) {
- /* special exception here, individual faces don't count
- * as reference, but we do ensure the refcount is not zero */
- if (id->us == 0)
- id_us_plus(id);
- else
- id_lib_extern(id);
+static void rna_Mesh_face_map_remove(struct Mesh *me, ReportList *reports, struct CustomDataLayer *layer)
+{
+ /* just for sanity check */
+ {
+ CustomData *pdata = rna_mesh_pdata_helper(me);
+ int index = CustomData_get_layer_index(pdata, CD_FACEMAP);
+ if (index != -1) {
+ CustomDataLayer *layer_test = &pdata->layers[index];
+ if (layer != layer_test) {
+ /* don't show name, its likely freed memory */
+ BKE_report(reports, RPT_ERROR, "FaceMap not in mesh");
+ return;
+ }
+ }
}
- tf->tpage = (struct Image *)id;
+ if (BKE_mesh_clear_facemap_customdata(me) == false) {
+ BKE_reportf(reports, RPT_ERROR, "Error removing face-map");
+ }
}
+/* End face maps */
+
+
static int rna_MeshTessFace_verts_get_length(PointerRNA *ptr, int length[RNA_MAX_ARRAY_DIMENSION])
{
MFace *face = (MFace *)ptr->data;
@@ -1380,14 +1404,6 @@ static char *rna_MeshTextureFaceLayer_path(PointerRNA *ptr)
return BLI_sprintfN("tessface_uv_textures[\"%s\"]", name_esc);
}
-static char *rna_MeshTexturePolyLayer_path(PointerRNA *ptr)
-{
- CustomDataLayer *cdl = ptr->data;
- char name_esc[sizeof(cdl->name) * 2];
- BLI_strescape(name_esc, cdl->name, sizeof(name_esc));
- return BLI_sprintfN("uv_textures[\"%s\"]", name_esc);
-}
-
static char *rna_VertCustomData_data_path(PointerRNA *ptr, const char *collection, int type)
{
CustomDataLayer *cdl;
@@ -1483,11 +1499,6 @@ static char *rna_MeshTextureFace_path(PointerRNA *ptr)
return rna_FaceCustomData_data_path(ptr, "tessface_uv_textures", CD_MTFACE);
}
-static char *rna_MeshTexturePoly_path(PointerRNA *ptr)
-{
- return rna_PolyCustomData_data_path(ptr, "uv_textures", CD_MTEXPOLY);
-}
-
static char *rna_MeshColorLayer_path(PointerRNA *ptr)
{
CustomDataLayer *cdl = ptr->data;
@@ -1675,6 +1686,12 @@ void rna_MeshStringProperty_s_set(PointerRNA *ptr, const char *value)
MStringProperty *ms = (MStringProperty *)ptr->data;
BLI_strncpy(ms->s, value, sizeof(ms->s));
}
+
+static char *rna_MeshFaceMap_path(PointerRNA *ptr)
+{
+ return rna_PolyCustomData_data_path(ptr, "face_maps", CD_FACEMAP);
+}
+
/***************************************/
static int rna_Mesh_tot_vert_get(PointerRNA *ptr)
@@ -1768,23 +1785,23 @@ DEFINE_CUSTOMDATA_PROPERTY_API(polygon, int, CD_PROP_INT, pdata, totpoly, MeshPo
DEFINE_CUSTOMDATA_PROPERTY_API(polygon, string, CD_PROP_STR, pdata, totpoly, MeshPolygonStringPropertyLayer)
#undef DEFINE_CUSTOMDATA_PROPERTY_API
-static PointerRNA rna_Mesh_uv_texture_new(struct Mesh *me, const char *name)
+static PointerRNA rna_Mesh_uv_layers_new(struct Mesh *me, const char *name)
{
PointerRNA ptr;
- CustomData *pdata;
+ CustomData *ldata;
CustomDataLayer *cdl = NULL;
int index = ED_mesh_uv_texture_add(me, name, false);
if (index != -1) {
- pdata = rna_mesh_pdata_helper(me);
- cdl = &pdata->layers[CustomData_get_layer_index_n(pdata, CD_MTEXPOLY, index)];
+ ldata = rna_mesh_ldata_helper(me);
+ cdl = &ldata->layers[CustomData_get_layer_index_n(ldata, CD_MLOOPUV, index)];
}
- RNA_pointer_create(&me->id, &RNA_MeshTexturePolyLayer, cdl, &ptr);
+ RNA_pointer_create(&me->id, &RNA_MeshUVLoopLayer, cdl, &ptr);
return ptr;
}
-static void rna_Mesh_uv_texture_layers_remove(struct Mesh *me, ReportList *reports, CustomDataLayer *layer)
+static void rna_Mesh_uv_layers_remove(struct Mesh *me, ReportList *reports, CustomDataLayer *layer)
{
if (ED_mesh_uv_texture_remove_named(me, layer->name) == false) {
BKE_reportf(reports, RPT_ERROR, "Texture layer '%s' not found", layer->name);
@@ -1859,14 +1876,14 @@ static void UNUSED_FUNCTION(rna_mesh_unused)(void)
(void)rna_Mesh_uv_layer_render_index_get;
(void)rna_Mesh_uv_layer_render_index_set;
(void)rna_Mesh_uv_layer_render_set;
- (void)rna_Mesh_uv_texture_render_get;
- (void)rna_Mesh_uv_texture_render_index_get;
- (void)rna_Mesh_uv_texture_render_index_set;
- (void)rna_Mesh_uv_texture_render_set;
(void)rna_Mesh_vertex_color_render_get;
(void)rna_Mesh_vertex_color_render_index_get;
(void)rna_Mesh_vertex_color_render_index_set;
(void)rna_Mesh_vertex_color_render_set;
+ (void)rna_Mesh_face_map_index_range;
+ (void)rna_Mesh_face_map_active_index_set;
+ (void)rna_Mesh_face_map_active_index_get;
+ (void)rna_Mesh_face_map_active_set;
/* end unused function block */
}
@@ -1894,7 +1911,7 @@ static void rna_def_mvert_group(BlenderRNA *brna)
prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Weight", "Vertex Weight");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_weight");
}
static void rna_def_mvert(BlenderRNA *brna)
@@ -2264,6 +2281,24 @@ static void rna_def_mloopuv(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Name", "Name of UV map");
RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+ prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_MeshUVLoopLayer_active_get", "rna_MeshUVLoopLayer_active_set");
+ RNA_def_property_ui_text(prop, "Active", "Set the map as active for display and editing");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
+ prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "active_rnd", 0);
+ RNA_def_property_boolean_funcs(prop, "rna_MeshUVLoopLayer_active_render_get",
+ "rna_MeshUVLoopLayer_active_render_set");
+ RNA_def_property_ui_text(prop, "Active Render", "Set the map as active for rendering");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
+ prop = RNA_def_property(srna, "active_clone", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "active_clone", 0);
+ RNA_def_property_boolean_funcs(prop, "rna_MeshUVLoopLayer_clone_get", "rna_MeshUVLoopLayer_clone_set");
+ RNA_def_property_ui_text(prop, "Active Clone", "Set the map as active for cloning");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
srna = RNA_def_struct(brna, "MeshUVLoop", NULL);
RNA_def_struct_sdna(srna, "MLoopUV");
RNA_def_struct_path_func(srna, "rna_MeshUVLoop_path");
@@ -2333,13 +2368,6 @@ static void rna_def_mtface(BlenderRNA *brna)
RNA_def_struct_path_func(srna, "rna_MeshTextureFace_path");
RNA_def_struct_ui_icon(srna, ICON_FACESEL_HLT);
- prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "tpage");
- RNA_def_property_pointer_funcs(prop, NULL, "rna_TextureFace_image_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Image", "");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
/* these are for editing only, access at loops now */
#if 0
prop = RNA_def_property(srna, "select_uv", PROP_BOOLEAN, PROP_NONE);
@@ -2394,84 +2422,6 @@ static void rna_def_mtface(BlenderRNA *brna)
}
-static void rna_def_mtexpoly(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-#if 0 /* BMESH_TODO: needed later when do another todo */
- int uv_dim[] = {4, 2};
-#endif
-
- srna = RNA_def_struct(brna, "MeshTexturePolyLayer", NULL);
- RNA_def_struct_ui_text(srna, "Mesh UV Map", "UV map with assigned image textures in a Mesh data-block");
- RNA_def_struct_sdna(srna, "CustomDataLayer");
- RNA_def_struct_path_func(srna, "rna_MeshTexturePolyLayer_path");
- RNA_def_struct_ui_icon(srna, ICON_GROUP_UVS);
-
- prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
- RNA_def_struct_name_property(srna, prop);
- RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshUVLayer_name_set");
- RNA_def_property_ui_text(prop, "Name", "Name of UV map");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
- prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_funcs(prop, "rna_MeshTexturePolyLayer_active_get", "rna_MeshTexturePolyLayer_active_set");
- RNA_def_property_ui_text(prop, "Active", "Set the map as active for display and editing");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
- prop = RNA_def_property(srna, "active_render", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "active_rnd", 0);
- RNA_def_property_boolean_funcs(prop, "rna_MeshTexturePolyLayer_active_render_get",
- "rna_MeshTexturePolyLayer_active_render_set");
- RNA_def_property_ui_text(prop, "Active Render", "Set the map as active for rendering");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
- prop = RNA_def_property(srna, "active_clone", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "active_clone", 0);
- RNA_def_property_boolean_funcs(prop, "rna_MeshTexturePolyLayer_clone_get", "rna_MeshTexturePolyLayer_clone_set");
- RNA_def_property_ui_text(prop, "Active Clone", "Set the map as active for cloning");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
- prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_struct_type(prop, "MeshTexturePoly");
- RNA_def_property_ui_text(prop, "Data", "");
- RNA_def_property_collection_funcs(prop, "rna_MeshTexturePolyLayer_data_begin", "rna_iterator_array_next",
- "rna_iterator_array_end", "rna_iterator_array_get",
- "rna_MeshTexturePolyLayer_data_length", NULL, NULL, NULL);
-
- srna = RNA_def_struct(brna, "MeshTexturePoly", NULL);
- RNA_def_struct_sdna(srna, "MTexPoly");
- RNA_def_struct_ui_text(srna, "Mesh UV Map Face", "UV map and image texture for a face");
- RNA_def_struct_path_func(srna, "rna_MeshTexturePoly_path");
- RNA_def_struct_ui_icon(srna, ICON_FACESEL_HLT);
-
- prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "tpage");
- RNA_def_property_pointer_funcs(prop, NULL, "rna_TexturePoly_image_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Image", "");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
-#if 0 /* moved to MeshUVLoopLayer */
- prop = RNA_def_property(srna, "select_uv", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", TF_SEL1);
- RNA_def_property_array(prop, 4);
- RNA_def_property_ui_text(prop, "UV Selected", "");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
-
- prop = RNA_def_property(srna, "pin_uv", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "unwrap", TF_PIN1);
- RNA_def_property_array(prop, 4);
- RNA_def_property_ui_text(prop, "UV Pinned", "");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_select");
-
- prop = RNA_def_property(srna, "uv_raw", PROP_FLOAT, PROP_NONE);
- RNA_def_property_multi_array(prop, 2, uv_dim);
- RNA_def_property_float_sdna(prop, NULL, "uv");
- RNA_def_property_ui_text(prop, "UV", "Fixed size UV coordinates array");
-#endif
-}
-
static void rna_def_mcol(BlenderRNA *brna)
{
StructRNA *srna;
@@ -2938,13 +2888,13 @@ static void rna_def_loop_colors(BlenderRNA *brna, PropertyRNA *cprop)
"rna_Mesh_vertex_color_active_set", NULL, NULL);
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
RNA_def_property_ui_text(prop, "Active Vertex Color Layer", "Active vertex color layer");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_funcs(prop, "rna_Mesh_vertex_color_active_index_get",
"rna_Mesh_vertex_color_active_index_set", "rna_Mesh_vertex_color_index_range");
RNA_def_property_ui_text(prop, "Active Vertex Color Index", "Active vertex color index");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_active_color");
}
static void rna_def_uv_layers(BlenderRNA *brna, PropertyRNA *cprop)
@@ -2952,14 +2902,27 @@ static void rna_def_uv_layers(BlenderRNA *brna, PropertyRNA *cprop)
StructRNA *srna;
PropertyRNA *prop;
- /* FunctionRNA *func; */
- /* PropertyRNA *parm; */
+ FunctionRNA *func;
+ PropertyRNA *parm;
RNA_def_property_srna(cprop, "UVLoopLayers");
srna = RNA_def_struct(brna, "UVLoopLayers", NULL);
RNA_def_struct_sdna(srna, "Mesh");
RNA_def_struct_ui_text(srna, "UV Loop Layers", "Collection of uv loop layers");
+ func = RNA_def_function(srna, "new", "rna_Mesh_uv_layers_new");
+ RNA_def_function_ui_description(func, "Add a UV map layer to Mesh");
+ RNA_def_string(func, "name", "UVMap", 0, "", "UV map name");
+ parm = RNA_def_pointer(func, "layer", "MeshUVLoopLayer", "", "The newly created layer");
+ RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_Mesh_uv_layers_remove");
+ RNA_def_function_ui_description(func, "Remove a vertex color layer");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "layer", "MeshUVLoopLayer", "", "The layer to remove");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "MeshUVLoopLayer");
RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_layer_active_get",
@@ -3124,7 +3087,6 @@ static void rna_def_tessface_uv_textures(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
RNA_def_function_return(func, parm);
-
prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "MeshTextureFaceLayer");
RNA_def_property_pointer_funcs(prop, "rna_Mesh_tessface_uv_texture_active_get",
@@ -3134,49 +3096,7 @@ static void rna_def_tessface_uv_textures(BlenderRNA *brna, PropertyRNA *cprop)
prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_funcs(prop, "rna_Mesh_tessface_uv_texture_active_index_get",
- "rna_Mesh_tessface_uv_texture_active_index_set", "rna_Mesh_uv_texture_index_range");
- RNA_def_property_ui_text(prop, "Active UV Map Index", "Active UV Map index");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-}
-
-
-static void rna_def_uv_textures(BlenderRNA *brna, PropertyRNA *cprop)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- FunctionRNA *func;
- PropertyRNA *parm;
-
- RNA_def_property_srna(cprop, "UVTextures");
- srna = RNA_def_struct(brna, "UVTextures", NULL);
- RNA_def_struct_sdna(srna, "Mesh");
- RNA_def_struct_ui_text(srna, "UV Maps", "Collection of UV maps");
-
- func = RNA_def_function(srna, "new", "rna_Mesh_uv_texture_new");
- RNA_def_function_ui_description(func, "Add a UV map layer to Mesh");
- RNA_def_string(func, "name", "UVMap", 0, "", "UV map name");
- parm = RNA_def_pointer(func, "layer", "MeshTexturePolyLayer", "", "The newly created layer");
- RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
- RNA_def_function_return(func, parm);
-
- func = RNA_def_function(srna, "remove", "rna_Mesh_uv_texture_layers_remove");
- RNA_def_function_ui_description(func, "Remove a vertex color layer");
- RNA_def_function_flag(func, FUNC_USE_REPORTS);
- parm = RNA_def_pointer(func, "layer", "MeshTexturePolyLayer", "", "The layer to remove");
- RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
-
- prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "MeshTexturePolyLayer");
- RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_active_get",
- "rna_Mesh_uv_texture_active_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
- RNA_def_property_ui_text(prop, "Active UV Map", "Active UV Map");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
- prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_active_index_get",
- "rna_Mesh_uv_texture_active_index_set", "rna_Mesh_uv_texture_index_range");
+ "rna_Mesh_tessface_uv_texture_active_index_set", "rna_Mesh_uv_layer_index_range");
RNA_def_property_ui_text(prop, "Active UV Map Index", "Active UV Map index");
RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}
@@ -3259,6 +3179,79 @@ static void rna_def_paint_mask(BlenderRNA *brna, PropertyRNA *UNUSED(cprop))
RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
}
+static void rna_def_face_map(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "MeshFaceMapLayer", NULL);
+ RNA_def_struct_ui_text(srna, "Mesh Face Map Layer", "Per-face map index");
+ RNA_def_struct_sdna(srna, "CustomDataLayer");
+ RNA_def_struct_path_func(srna, "rna_MeshFaceMapLayer_path");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_MeshPolyLayer_name_set");
+ RNA_def_property_ui_text(prop, "Name", "Name of face-map layer");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
+ prop = RNA_def_property(srna, "data", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "MeshFaceMap");
+ RNA_def_property_ui_text(prop, "Data", "");
+ RNA_def_property_collection_funcs(prop, "rna_MeshFaceMapLayer_data_begin", "rna_iterator_array_next",
+ "rna_iterator_array_end", "rna_iterator_array_get",
+ "rna_MeshFaceMapLayer_data_length", NULL, NULL, NULL);
+
+ /* FaceMap struct */
+ srna = RNA_def_struct(brna, "MeshFaceMap", NULL);
+ RNA_def_struct_sdna(srna, "MIntProperty");
+ RNA_def_struct_ui_text(srna, "Int Property", "");
+ RNA_def_struct_path_func(srna, "rna_MeshFaceMap_path");
+
+ prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "i");
+ RNA_def_property_ui_text(prop, "Value", "");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+}
+
+static void rna_def_face_maps(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ RNA_def_property_srna(cprop, "MeshFaceMapLayers");
+ srna = RNA_def_struct(brna, "MeshFaceMapLayers", NULL);
+ RNA_def_struct_ui_text(srna, "Mesh Face Map Layer", "Per-face map index");
+ RNA_def_struct_sdna(srna, "Mesh");
+ RNA_def_struct_ui_text(srna, "Mesh FaceMaps", "Collection of mesh face-maps");
+
+ /* add this since we only ever have one layer anyway, don't bother with active_index */
+ prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "MeshFaceMapLayer");
+ RNA_def_property_pointer_funcs(prop, "rna_Mesh_face_map_active_get",
+ NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Active FaceMap Layer", "");
+ RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ func = RNA_def_function(srna, "new", "rna_Mesh_face_map_new");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(func, "Add a float property layer to Mesh");
+ RNA_def_string(func, "name", "Face Map", 0, "", "Face map name");
+ parm = RNA_def_pointer(func, "layer", "MeshFaceMapLayer", "", "The newly created layer");
+ RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_Mesh_face_map_remove");
+ RNA_def_function_ui_description(func, "Remove a face map layer");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "layer", "MeshFaceMapLayer", "", "The layer to remove");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
+}
+
static void rna_def_mesh(BlenderRNA *brna)
{
StructRNA *srna;
@@ -3348,41 +3341,6 @@ static void rna_def_mesh(BlenderRNA *brna)
"All UV maps for tessellated faces (read-only, for use by renderers)");
rna_def_tessface_uv_textures(brna, prop);
- /* UV maps */
- prop = RNA_def_property(srna, "uv_textures", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "pdata.layers", "pdata.totlayer");
- RNA_def_property_collection_funcs(prop, "rna_Mesh_uv_textures_begin", NULL, NULL, NULL,
- "rna_Mesh_uv_textures_length", NULL, NULL, NULL);
- RNA_def_property_struct_type(prop, "MeshTexturePolyLayer");
- RNA_def_property_ui_text(prop, "UV Maps", "All UV maps");
- rna_def_uv_textures(brna, prop);
-
- prop = RNA_def_property(srna, "uv_texture_clone", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "MeshTexturePolyLayer");
- RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_clone_get",
- "rna_Mesh_uv_texture_clone_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Clone UV Map", "UV map to be used as cloning source");
-
- prop = RNA_def_property(srna, "uv_texture_clone_index", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_clone_index_get",
- "rna_Mesh_uv_texture_clone_index_set", "rna_Mesh_uv_texture_index_range");
- RNA_def_property_ui_text(prop, "Clone UV Map Index", "Clone UV map index");
-
- prop = RNA_def_property(srna, "uv_texture_stencil", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "MeshTexturePolyLayer");
- RNA_def_property_pointer_funcs(prop, "rna_Mesh_uv_texture_stencil_get",
- "rna_Mesh_uv_texture_stencil_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Mask UV Map", "UV map to mask the painted area");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
- prop = RNA_def_property(srna, "uv_texture_stencil_index", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_funcs(prop, "rna_Mesh_uv_texture_stencil_index_get",
- "rna_Mesh_uv_texture_stencil_index_set", "rna_Mesh_uv_texture_index_range");
- RNA_def_property_ui_text(prop, "Mask UV Map Index", "Mask UV map index");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data");
-
/* Tessellated face colors - used by renderers */
prop = RNA_def_property(srna, "tessface_vertex_colors", PROP_COLLECTION, PROP_NONE);
@@ -3453,6 +3411,15 @@ static void rna_def_mesh(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "String Property Layers", "");
rna_def_polygon_string_layers(brna, prop);
+ /* face-maps */
+ prop = RNA_def_property(srna, "face_maps", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "pdata.layers", "pdata.totlayer");
+ RNA_def_property_collection_funcs(prop, "rna_Mesh_face_maps_begin", NULL, NULL, NULL,
+ "rna_Mesh_face_maps_length", NULL, NULL, NULL);
+ RNA_def_property_struct_type(prop, "MeshFaceMapLayer");
+ RNA_def_property_ui_text(prop, "FaceMap", "");
+ rna_def_face_maps(brna, prop);
+
/* Skin vertices */
prop = RNA_def_property(srna, "skin_vertices", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "vdata.layers", "vdata.totlayer");
@@ -3549,26 +3516,6 @@ static void rna_def_mesh(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Draw Faces", "Display all faces as shades in the 3D view and UV editor");
RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
- prop = RNA_def_property(srna, "show_normal_face", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWNORMALS);
- RNA_def_property_ui_text(prop, "Draw Normals", "Display face normals as lines");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
-
- prop = RNA_def_property(srna, "show_normal_loop", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAW_LNORMALS);
- RNA_def_property_ui_text(prop, "Draw Split Normals", "Display vertex-per-face normals as lines");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
-
- prop = RNA_def_property(srna, "show_normal_vertex", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAW_VNORMALS);
- RNA_def_property_ui_text(prop, "Draw Vertex Normals", "Display vertex normals as lines");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_draw");
-
- prop = RNA_def_property(srna, "show_weight", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWEIGHT);
- RNA_def_property_ui_text(prop, "Show Weights", "Draw weights in editmode");
- RNA_def_property_update(prop, 0, "rna_Mesh_update_data_edit_color"); /* needs to rebuild 'dm' */
-
prop = RNA_def_property(srna, "show_edge_crease", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "drawflag", ME_DRAWCREASES);
RNA_def_property_ui_text(prop, "Draw Creases", "Display creases created for Subdivision Surface modifier");
@@ -3723,10 +3670,10 @@ void RNA_def_mesh(BlenderRNA *brna)
rna_def_mpolygon(brna);
rna_def_mloopuv(brna);
rna_def_mtface(brna);
- rna_def_mtexpoly(brna);
rna_def_mcol(brna);
rna_def_mloopcol(brna);
rna_def_mproperties(brna);
+ rna_def_face_map(brna);
}
#endif
diff --git a/source/blender/makesrna/intern/rna_mesh_api.c b/source/blender/makesrna/intern/rna_mesh_api.c
index 9b0a25560f9..f1f7c9a3b99 100644
--- a/source/blender/makesrna/intern/rna_mesh_api.c
+++ b/source/blender/makesrna/intern/rna_mesh_api.c
@@ -48,6 +48,7 @@
#include "DNA_mesh_types.h"
#include "BKE_mesh.h"
+#include "BKE_mesh_tangent.h"
#include "BKE_mesh_mapping.h"
#include "ED_mesh.h"
@@ -92,7 +93,7 @@ static void rna_Mesh_calc_tangents(Mesh *mesh, ReportList *reports, const char *
BKE_mesh_calc_normals_split(mesh);
}
- BKE_mesh_loop_tangents(mesh, uvmap, r_looptangents, reports);
+ BKE_mesh_calc_loop_tangent_single(mesh, uvmap, r_looptangents, reports);
}
static void rna_Mesh_free_tangents(Mesh *mesh)
@@ -172,7 +173,7 @@ static void rna_Mesh_normals_split_custom_set(Mesh *mesh, ReportList *reports, i
rna_Mesh_normals_split_custom_do(mesh, loopnors, false);
- DAG_id_tag_update(&mesh->id, 0);
+ DEG_id_tag_update(&mesh->id, 0);
}
static void rna_Mesh_normals_split_custom_set_from_vertices(
@@ -190,14 +191,14 @@ static void rna_Mesh_normals_split_custom_set_from_vertices(
rna_Mesh_normals_split_custom_do(mesh, vertnors, true);
- DAG_id_tag_update(&mesh->id, 0);
+ DEG_id_tag_update(&mesh->id, 0);
}
static void rna_Mesh_transform(Mesh *mesh, float *mat, int shape_keys)
{
BKE_mesh_transform(mesh, (float (*)[4])mat, shape_keys);
- DAG_id_tag_update(&mesh->id, 0);
+ DEG_id_tag_update(&mesh->id, 0);
}
static void rna_Mesh_flip_normals(Mesh *mesh)
@@ -206,7 +207,7 @@ static void rna_Mesh_flip_normals(Mesh *mesh)
BKE_mesh_tessface_clear(mesh);
BKE_mesh_calc_normals(mesh);
- DAG_id_tag_update(&mesh->id, 0);
+ DEG_id_tag_update(&mesh->id, 0);
}
static void rna_Mesh_split_faces(Mesh *mesh, int free_loop_normals)
@@ -214,6 +215,12 @@ static void rna_Mesh_split_faces(Mesh *mesh, int free_loop_normals)
BKE_mesh_split_faces(mesh, free_loop_normals != 0);
}
+static void rna_Mesh_update_gpu_tag(Mesh *mesh)
+{
+ BKE_mesh_batch_cache_dirty(mesh, BKE_MESH_BATCH_DIRTY_ALL);
+}
+
+
#else
void RNA_api_mesh(StructRNA *srna)
@@ -304,6 +311,8 @@ void RNA_api_mesh(StructRNA *srna)
RNA_def_boolean(func, "calc_tessface", 0, "Calculate Tessellation", "Force recalculation of tessellation faces");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ RNA_def_function(srna, "update_gpu_tag", "rna_Mesh_update_gpu_tag");
+
func = RNA_def_function(srna, "unit_test_compare", "rna_Mesh_unit_test_compare");
RNA_def_pointer(func, "mesh", "Mesh", "", "Mesh to compare to");
/* return value */
diff --git a/source/blender/makesrna/intern/rna_mesh_utils.h b/source/blender/makesrna/intern/rna_mesh_utils.h
index 93b3fd6579e..a85e2095121 100644
--- a/source/blender/makesrna/intern/rna_mesh_utils.h
+++ b/source/blender/makesrna/intern/rna_mesh_utils.h
@@ -101,12 +101,6 @@
for (layer = data->layers + layer_index, a = 0; layer_index + a < data->totlayer; layer++, a++) { \
if (value.data == layer) { \
CustomData_set_layer_##active_type(data, layer_type, a); \
- \
- /* keep loops in sync */ \
- if (layer_type == CD_MTEXPOLY) { \
- CustomData *ldata = rna_mesh_ldata_helper(me); \
- CustomData_set_layer_##active_type(ldata, CD_MLOOPUV, a); \
- } \
BKE_mesh_update_customdata_pointers(me, true); \
return; \
} \
@@ -131,11 +125,6 @@
CustomData *data = rna_mesh_##customdata_type(ptr); \
if (data) { \
CustomData_set_layer_##active_type(data, layer_type, value); \
- /* keep loops in sync */ \
- if (layer_type == CD_MTEXPOLY) { \
- CustomData *ldata = rna_mesh_ldata_helper(me); \
- CustomData_set_layer_##active_type(ldata, CD_MLOOPUV, value); \
- } \
BKE_mesh_update_customdata_pointers(me, true); \
} \
}
diff --git a/source/blender/makesrna/intern/rna_meta.c b/source/blender/makesrna/intern/rna_meta.c
index 1a45db1e45f..124f3a2fbe2 100644
--- a/source/blender/makesrna/intern/rna_meta.c
+++ b/source/blender/makesrna/intern/rna_meta.c
@@ -47,8 +47,10 @@
#include "DNA_object_types.h"
#include "BKE_mball.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
+#include "BKE_scene.h"
+
+#include "DEG_depsgraph.h"
#include "WM_types.h"
#include "WM_api.h"
@@ -103,7 +105,7 @@ static void rna_MetaBall_update_data(Main *bmain, Scene *scene, PointerRNA *ptr)
if (ob->data == mb)
BKE_mball_properties_copy(scene, ob);
- DAG_id_tag_update(&mb->id, 0);
+ DEG_id_tag_update(&mb->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, mb);
}
}
@@ -121,7 +123,7 @@ static MetaElem *rna_MetaBall_elements_new(MetaBall *mb, int type)
/* cheating way for importers to avoid slow updates */
if (mb->id.us > 0) {
- DAG_id_tag_update(&mb->id, 0);
+ DEG_id_tag_update(&mb->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, &mb->id);
}
@@ -142,7 +144,7 @@ static void rna_MetaBall_elements_remove(MetaBall *mb, ReportList *reports, Poin
/* cheating way for importers to avoid slow updates */
if (mb->id.us > 0) {
- DAG_id_tag_update(&mb->id, 0);
+ DEG_id_tag_update(&mb->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, &mb->id);
}
}
@@ -153,7 +155,7 @@ static void rna_MetaBall_elements_clear(MetaBall *mb)
/* cheating way for importers to avoid slow updates */
if (mb->id.us > 0) {
- DAG_id_tag_update(&mb->id, 0);
+ DEG_id_tag_update(&mb->id, 0);
WM_main_add_notifier(NC_GEOM | ND_DATA, &mb->id);
}
}
diff --git a/source/blender/makesrna/intern/rna_meta_api.c b/source/blender/makesrna/intern/rna_meta_api.c
index 4c3fa787b94..53bb3ef2334 100644
--- a/source/blender/makesrna/intern/rna_meta_api.c
+++ b/source/blender/makesrna/intern/rna_meta_api.c
@@ -47,7 +47,12 @@ static void rna_Meta_transform(struct MetaBall *mb, float *mat)
{
BKE_mball_transform(mb, (float (*)[4])mat, true);
- DAG_id_tag_update(&mb->id, 0);
+ DEG_id_tag_update(&mb->id, 0);
+}
+
+static void rna_Mball_update_gpu_tag(MetaBall *mb)
+{
+ BKE_mball_batch_cache_dirty(mb, BKE_MBALL_BATCH_DIRTY_ALL);
}
#else
@@ -60,6 +65,8 @@ void RNA_api_meta(StructRNA *srna)
RNA_def_function_ui_description(func, "Transform meta elements by a matrix");
parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ RNA_def_function(srna, "update_gpu_tag", "rna_Mball_update_gpu_tag");
}
#endif
diff --git a/source/blender/makesrna/intern/rna_modifier.c b/source/blender/makesrna/intern/rna_modifier.c
index 0ebd29b200c..b1716f6a176 100644
--- a/source/blender/makesrna/intern/rna_modifier.c
+++ b/source/blender/makesrna/intern/rna_modifier.c
@@ -286,12 +286,14 @@ const EnumPropertyItem rna_enum_axis_flag_xyz_items[] = {
#include "BKE_cachefile.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_library.h"
#include "BKE_modifier.h"
#include "BKE_object.h"
#include "BKE_particle.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#ifdef WITH_ALEMBIC
# include "ABC_alembic.h"
#endif
@@ -453,14 +455,14 @@ static char *rna_Modifier_path(PointerRNA *ptr)
static void rna_Modifier_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ptr->id.data);
}
static void rna_Modifier_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
rna_Modifier_update(bmain, scene, ptr);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
/* Vertex Groups */
@@ -793,11 +795,11 @@ static void rna_CurveModifier_dependency_update(Main *bmain, Scene *scene, Point
{
CurveModifierData *cmd = (CurveModifierData *)ptr->data;
rna_Modifier_update(bmain, scene, ptr);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
if (cmd->object != NULL) {
Curve *curve = cmd->object->data;
if ((curve->flag & CU_PATH) == 0) {
- DAG_id_tag_update(&curve->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&curve->id, OB_RECALC_DATA);
}
}
}
@@ -806,11 +808,11 @@ static void rna_ArrayModifier_dependency_update(Main *bmain, Scene *scene, Point
{
ArrayModifierData *amd = (ArrayModifierData *)ptr->data;
rna_Modifier_update(bmain, scene, ptr);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
if (amd->curve_ob != NULL) {
Curve *curve = amd->curve_ob->data;
if ((curve->flag & CU_PATH) == 0) {
- DAG_id_tag_update(&curve->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&curve->id, OB_RECALC_DATA);
}
}
}
@@ -933,19 +935,19 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_src_itemf(
if (ob_src) {
DerivedMesh *dm_src;
- CustomData *pdata;
+ CustomData *ldata;
int num_data, i;
dm_src = object_get_derived_final(ob_src, false);
if (dm_src != NULL) {
- pdata = dm_src->getPolyDataLayout(dm_src);
- num_data = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
+ ldata = dm_src->getLoopDataLayout(dm_src);
+ num_data = CustomData_number_of_layers(ldata, CD_MLOOPUV);
RNA_enum_item_add_separator(&item, &totitem);
for (i = 0; i < num_data; i++) {
tmp_item.value = i;
- tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(pdata, CD_MTEXPOLY, i);
+ tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(ldata, CD_MLOOPUV, i);
RNA_enum_item_add(&item, &totitem, &tmp_item);
}
}
@@ -1024,18 +1026,18 @@ static const EnumPropertyItem *rna_DataTransferModifier_layers_select_dst_itemf(
if (ob_dst && ob_dst->data) {
Mesh *me_dst;
- CustomData *pdata;
+ CustomData *ldata;
int num_data, i;
me_dst = ob_dst->data;
- pdata = &me_dst->pdata;
- num_data = CustomData_number_of_layers(pdata, CD_MTEXPOLY);
+ ldata = &me_dst->ldata;
+ num_data = CustomData_number_of_layers(ldata, CD_MLOOPUV);
RNA_enum_item_add_separator(&item, &totitem);
for (i = 0; i < num_data; i++) {
tmp_item.value = i;
- tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(pdata, CD_MTEXPOLY, i);
+ tmp_item.identifier = tmp_item.name = CustomData_get_layer_name(ldata, CD_MLOOPUV, i);
RNA_enum_item_add(&item, &totitem, &tmp_item);
}
}
@@ -1852,7 +1854,7 @@ static void rna_def_modifier_armature(BlenderRNA *brna)
prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "Object", "Armature object to deform with");
RNA_def_property_pointer_funcs(prop, NULL, "rna_ArmatureModifier_object_set", NULL, "rna_Armature_object_poll");
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_OVERRIDABLE_STATIC);
RNA_def_property_update(prop, 0, "rna_Modifier_dependency_update");
prop = RNA_def_property(srna, "use_bone_envelopes", PROP_BOOLEAN, PROP_NONE);
@@ -2282,11 +2284,6 @@ static void rna_def_modifier_uvproject(BlenderRNA *brna)
"rna_iterator_array_end", "rna_iterator_array_get", NULL, NULL, NULL, NULL);
RNA_def_property_ui_text(prop, "Projectors", "");
- prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
- RNA_def_property_ui_text(prop, "Image", "");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, 0, "rna_Modifier_update");
-
prop = RNA_def_property(srna, "aspect_x", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "aspectx");
RNA_def_property_flag(prop, PROP_PROPORTIONAL);
@@ -2319,11 +2316,6 @@ static void rna_def_modifier_uvproject(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Vertical Scale", "");
RNA_def_property_update(prop, 0, "rna_Modifier_update");
- prop = RNA_def_property(srna, "use_image_override", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flags", MOD_UVPROJECT_OVERRIDEIMAGE);
- RNA_def_property_ui_text(prop, "Override Image", "Override faces' current images with the given image");
- RNA_def_property_update(prop, 0, "rna_Modifier_update");
-
srna = RNA_def_struct(brna, "UVProjector", NULL);
RNA_def_struct_ui_text(srna, "UVProjector", "UV projector used by the UV project modifier");
@@ -4930,12 +4922,13 @@ void RNA_def_modifier(BlenderRNA *brna)
prop = RNA_def_property(srna, "show_viewport", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_Realtime);
RNA_def_property_ui_text(prop, "Realtime", "Display modifier in viewport");
- RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
+ RNA_def_property_flag(prop, PROP_LIB_EXCEPTION | PROP_OVERRIDABLE_STATIC);
RNA_def_property_update(prop, 0, "rna_Modifier_update");
RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, 0);
prop = RNA_def_property(srna, "show_render", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_Render);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Render", "Use modifier during render");
RNA_def_property_ui_icon(prop, ICON_SCENE, 0);
RNA_def_property_update(prop, NC_OBJECT | ND_MODIFIER, NULL);
@@ -4954,6 +4947,7 @@ void RNA_def_modifier(BlenderRNA *brna)
prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", eModifierMode_Expanded);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Expanded", "Set modifier expanded in the user interface");
RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
diff --git a/source/blender/makesrna/intern/rna_movieclip.c b/source/blender/makesrna/intern/rna_movieclip.c
index d63f3fe76f8..c663119eb42 100644
--- a/source/blender/makesrna/intern/rna_movieclip.c
+++ b/source/blender/makesrna/intern/rna_movieclip.c
@@ -49,7 +49,7 @@
#ifdef RNA_RUNTIME
-#include "BKE_depsgraph.h"
+#include "DEG_depsgraph.h"
#include "ED_clip.h"
@@ -61,7 +61,7 @@ static void rna_MovieClip_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scene
MovieClip *clip = (MovieClip *)ptr->id.data;
BKE_movieclip_reload(clip);
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
}
static void rna_MovieClip_size_get(PointerRNA *ptr, int *values)
diff --git a/source/blender/makesrna/intern/rna_nla.c b/source/blender/makesrna/intern/rna_nla.c
index f1c02896447..1301762a4bc 100644
--- a/source/blender/makesrna/intern/rna_nla.c
+++ b/source/blender/makesrna/intern/rna_nla.c
@@ -50,7 +50,6 @@
/* needed for some of the validation stuff... */
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_fcurve.h"
#include "BKE_nla.h"
diff --git a/source/blender/makesrna/intern/rna_nodetree.c b/source/blender/makesrna/intern/rna_nodetree.c
index 773ca307a8c..79a1ce73071 100644
--- a/source/blender/makesrna/intern/rna_nodetree.c
+++ b/source/blender/makesrna/intern/rna_nodetree.c
@@ -66,6 +66,9 @@
#include "NOD_composite.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
const EnumPropertyItem rna_enum_node_socket_in_out_items[] = {
{ SOCK_IN, "IN", 0, "Input", "" },
{ SOCK_OUT, "OUT", 0, "Output", "" },
@@ -187,6 +190,8 @@ static const EnumPropertyItem node_sampler_type_items[] = {
#include "ED_node.h"
#include "ED_render.h"
+#include "GPU_material.h"
+
#include "NOD_common.h"
#include "NOD_socket.h"
@@ -2299,13 +2304,31 @@ static void rna_NodeSocketStandard_vector_range(PointerRNA *ptr, float *min, flo
*softmax = dval->max;
}
+static void rna_NodeSocket_value_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+{
+ bNodeTree *ntree = (bNodeTree *)ptr->id.data;
+ bNodeSocket *sock = ptr->data;
+
+ if (ntree->type == NTREE_SHADER) {
+ DEG_id_tag_update_ex(bmain, &ntree->id, DEG_TAG_SHADING_UPDATE);
+ WM_main_add_notifier(NC_MATERIAL | ND_SHADING, NULL);
+
+ if (sock->type == SOCK_STRING) {
+ rna_NodeSocket_update(bmain, scene, ptr);
+ }
+ }
+ else {
+ rna_NodeSocket_update(bmain, scene, ptr);
+ }
+}
+
/* using a context update function here, to avoid searching the node if possible */
static void rna_NodeSocketStandard_value_update(struct bContext *C, PointerRNA *ptr)
{
bNode *node;
/* default update */
- rna_NodeSocket_update(CTX_data_main(C), CTX_data_scene(C), ptr);
+ rna_NodeSocket_value_update(CTX_data_main(C), CTX_data_scene(C), ptr);
/* try to use node from context, faster */
node = CTX_data_pointer_get(C, "node").data;
@@ -2316,14 +2339,6 @@ static void rna_NodeSocketStandard_value_update(struct bContext *C, PointerRNA *
/* fall back to searching node in the tree */
nodeFindNode(ntree, sock, &node, NULL);
}
-
- if (node) {
- nodeSynchronizeID(node, true);
-
- /* extra update for sockets that get synced to material */
- if (node->id && ELEM(node->type, SH_NODE_MATERIAL, SH_NODE_MATERIAL_EXT))
- WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, node->id);
- }
}
@@ -2479,17 +2494,6 @@ static void rna_Node_tex_image_update(Main *bmain, Scene *UNUSED(scene), Pointer
WM_main_add_notifier(NC_IMAGE, NULL);
}
-static void rna_Node_material_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
-{
- bNodeTree *ntree = (bNodeTree *)ptr->id.data;
- bNode *node = (bNode *)ptr->data;
-
- if (node->id)
- nodeSetActive(ntree, node);
-
- ED_node_tag_update_nodetree(bmain, ntree, node);
-}
-
static void rna_NodeGroup_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
bNodeTree *ntree = (bNodeTree *)ptr->id.data;
@@ -2751,7 +2755,7 @@ static const EnumPropertyItem *rna_Node_image_view_itemf(bContext *UNUSED(C), Po
return item;
}
-static const EnumPropertyItem *rna_Node_scene_layer_itemf(bContext *UNUSED(C), PointerRNA *ptr,
+static const EnumPropertyItem *rna_Node_view_layer_itemf(bContext *UNUSED(C), PointerRNA *ptr,
PropertyRNA *UNUSED(prop), bool *r_free)
{
bNode *node = (bNode *)ptr->data;
@@ -2764,7 +2768,7 @@ static const EnumPropertyItem *rna_Node_scene_layer_itemf(bContext *UNUSED(C), P
return DummyRNA_NULL_items;
}
- rl = sce->r.layers.first;
+ rl = sce->view_layers.first;
item = renderresult_layers_add_enum(rl);
*r_free = true;
@@ -2772,7 +2776,7 @@ static const EnumPropertyItem *rna_Node_scene_layer_itemf(bContext *UNUSED(C), P
return item;
}
-static void rna_Node_scene_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Node_view_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
rna_Node_update(bmain, scene, ptr);
if (scene->nodetree != NULL) {
@@ -3112,12 +3116,12 @@ static int point_density_vertex_color_source_from_shader(NodeShaderTexPointDensi
}
void rna_ShaderNodePointDensity_density_cache(bNode *self,
- Scene *scene,
- int settings)
+ Depsgraph *depsgraph)
{
NodeShaderTexPointDensity *shader_point_density = self->storage;
PointDensity *pd = &shader_point_density->pd;
- if (scene == NULL) {
+
+ if (depsgraph == NULL) {
return;
}
@@ -3149,14 +3153,11 @@ void rna_ShaderNodePointDensity_density_cache(bNode *self,
shader_point_density->cached_resolution = shader_point_density->resolution;
/* Single-threaded sampling of the voxel domain. */
- RE_point_density_cache(scene,
- pd,
- settings == 1);
+ RE_point_density_cache(depsgraph, pd);
}
void rna_ShaderNodePointDensity_density_calc(bNode *self,
- Scene *scene,
- int settings,
+ Depsgraph *depsgraph,
int *length,
float **values)
{
@@ -3164,7 +3165,7 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
PointDensity *pd = &shader_point_density->pd;
const int resolution = shader_point_density->cached_resolution;
- if (scene == NULL) {
+ if (depsgraph == NULL) {
*length = 0;
return;
}
@@ -3177,10 +3178,7 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
}
/* Single-threaded sampling of the voxel domain. */
- RE_point_density_sample(scene, pd,
- resolution,
- settings == 1,
- *values);
+ RE_point_density_sample(depsgraph, pd, resolution, *values);
/* We're done, time to clean up. */
BKE_texture_pointdensity_free_data(pd);
@@ -3189,19 +3187,20 @@ void rna_ShaderNodePointDensity_density_calc(bNode *self,
}
void rna_ShaderNodePointDensity_density_minmax(bNode *self,
- Scene *scene,
- int settings,
+ Depsgraph *depsgraph,
float r_min[3],
float r_max[3])
{
NodeShaderTexPointDensity *shader_point_density = self->storage;
PointDensity *pd = &shader_point_density->pd;
- if (scene == NULL) {
+
+ if (depsgraph == NULL) {
zero_v3(r_min);
zero_v3(r_max);
return;
}
- RE_point_density_minmax(scene, pd, settings == 1, r_min, r_max);
+
+ RE_point_density_minmax(depsgraph, pd, r_min, r_max);
}
#else
@@ -3216,7 +3215,7 @@ static const EnumPropertyItem prop_image_view_items[] = {
{0, NULL, 0, NULL, NULL}
};
-static const EnumPropertyItem prop_scene_layer_items[] = {
+static const EnumPropertyItem prop_view_layer_items[] = {
{ 0, "PLACEHOLDER", 0, "Placeholder", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -3530,33 +3529,6 @@ static void def_sh_output_linestyle(StructRNA *srna)
def_mix_rgb(srna);
}
-static void def_sh_material(StructRNA *srna)
-{
- PropertyRNA *prop;
-
- prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "id");
- RNA_def_property_struct_type(prop, "Material");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Material", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_material_update");
-
- prop = RNA_def_property(srna, "use_diffuse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_DIFF);
- RNA_def_property_ui_text(prop, "Diffuse", "Material Node outputs Diffuse");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-
- prop = RNA_def_property(srna, "use_specular", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_SPEC);
- RNA_def_property_ui_text(prop, "Specular", "Material Node outputs Specular");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-
- prop = RNA_def_property(srna, "invert_normal", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "custom1", SH_NODE_MAT_NEG);
- RNA_def_property_ui_text(prop, "Invert Normal", "Material Node uses inverted normal");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-}
-
static void def_sh_mapping(StructRNA *srna)
{
static const EnumPropertyItem prop_vect_type_items[] = {
@@ -3619,36 +3591,6 @@ static void def_sh_mapping(StructRNA *srna)
RNA_def_property_update(prop, 0, "rna_Mapping_Node_update");
}
-static void def_sh_geometry(StructRNA *srna)
-{
- PropertyRNA *prop;
-
- RNA_def_struct_sdna_from(srna, "NodeGeometry", "storage");
-
- prop = RNA_def_property(srna, "uv_layer", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "uvname");
- RNA_def_property_ui_text(prop, "UV Map", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-
- prop = RNA_def_property(srna, "color_layer", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "colname");
- RNA_def_property_ui_text(prop, "Vertex Color Layer", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-}
-
-static void def_sh_lamp(StructRNA *srna)
-{
- PropertyRNA *prop;
-
- prop = RNA_def_property(srna, "lamp_object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "id");
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
- RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Lamp_object_poll");
- RNA_def_property_ui_text(prop, "Lamp Object", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_update");
-}
-
static void def_sh_attribute(StructRNA *srna)
{
PropertyRNA *prop;
@@ -4123,13 +4065,6 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
{0, NULL, 0, NULL, NULL}
};
- /* TODO(sergey): Use some mnemonic names for the hardcoded values here. */
- static const EnumPropertyItem calc_mode_items[] = {
- {0, "VIEWPORT", 0, "Viewport", "Canculate density using viewport settings"},
- {1, "RENDER", 0, "Render", "Canculate duplis using render settings"},
- {0, NULL, 0, NULL, NULL}
- };
-
prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "id");
RNA_def_property_struct_type(prop, "Object");
@@ -4191,13 +4126,11 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
func = RNA_def_function(srna, "cache_point_density", "rna_ShaderNodePointDensity_density_cache");
RNA_def_function_ui_description(func, "Cache point density data for later calculation");
- RNA_def_pointer(func, "scene", "Scene", "", "");
- RNA_def_enum(func, "settings", calc_mode_items, 1, "", "Calculate density for rendering");
+ RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
func = RNA_def_function(srna, "calc_point_density", "rna_ShaderNodePointDensity_density_calc");
RNA_def_function_ui_description(func, "Calculate point density");
- RNA_def_pointer(func, "scene", "Scene", "", "");
- RNA_def_enum(func, "settings", calc_mode_items, 1, "", "Calculate density for rendering");
+ RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
/* TODO, See how array size of 0 works, this shouldnt be used. */
parm = RNA_def_float_array(func, "rgba_values", 1, NULL, 0, 0, "", "RGBA Values", 0, 0);
RNA_def_parameter_flags(parm, PROP_DYNAMIC, 0);
@@ -4205,8 +4138,7 @@ static void def_sh_tex_pointdensity(StructRNA *srna)
func = RNA_def_function(srna, "calc_point_density_minmax", "rna_ShaderNodePointDensity_density_minmax");
RNA_def_function_ui_description(func, "Calculate point density");
- RNA_def_pointer(func, "scene", "Scene", "", "");
- RNA_def_enum(func, "settings", calc_mode_items, 1, "", "Calculate density for rendering");
+ RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
parm = RNA_def_property(func, "min", PROP_FLOAT, PROP_COORDS);
RNA_def_property_array(parm, 3);
RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0);
@@ -4888,15 +4820,15 @@ static void def_cmp_render_layers(StructRNA *srna)
RNA_def_property_struct_type(prop, "Scene");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
RNA_def_property_ui_text(prop, "Scene", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_scene_layer_update");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_view_layer_update");
prop = RNA_def_property(srna, "layer", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "custom1");
- RNA_def_property_enum_items(prop, prop_scene_layer_items);
- RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_scene_layer_itemf");
+ RNA_def_property_enum_items(prop, prop_view_layer_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Node_view_layer_itemf");
RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE);
RNA_def_property_ui_text(prop, "Layer", "");
- RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_scene_layer_update");
+ RNA_def_property_update(prop, NC_NODE | NA_EDITED, "rna_Node_view_layer_update");
}
static void rna_def_cmp_output_file_slot_file(BlenderRNA *brna)
diff --git a/source/blender/makesrna/intern/rna_object.c b/source/blender/makesrna/intern/rna_object.c
index 49d8bd796d9..68df1cae4aa 100644
--- a/source/blender/makesrna/intern/rna_object.c
+++ b/source/blender/makesrna/intern/rna_object.c
@@ -29,15 +29,14 @@
#include "DNA_action_types.h"
#include "DNA_customdata_types.h"
-#include "DNA_controller_types.h"
#include "DNA_group_types.h"
#include "DNA_material_types.h"
#include "DNA_mesh_types.h"
#include "DNA_object_force_types.h"
#include "DNA_object_types.h"
-#include "DNA_property_types.h"
#include "DNA_scene_types.h"
#include "DNA_meta_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_utildefines.h"
#include "BLI_listbase.h"
@@ -48,6 +47,7 @@
#include "BKE_editmesh.h"
#include "BKE_group.h" /* needed for BKE_group_object_exists() */
#include "BKE_object_deform.h"
+#include "BKE_object_facemap.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -97,28 +97,27 @@ static const EnumPropertyItem parent_type_items[] = {
{0, NULL, 0, NULL, NULL}
};
-#ifndef RNA_RUNTIME
+#define DUPLI_ITEMS_SHARED \
+ {0, "NONE", 0, "None", ""}, \
+ {OB_DUPLIFRAMES, "FRAMES", 0, "Frames", "Make copy of object for every frame"}, \
+ {OB_DUPLIVERTS, "VERTS", 0, "Verts", "Duplicate child objects on all vertices"}, \
+ {OB_DUPLIFACES, "FACES", 0, "Faces", "Duplicate child objects on all faces"}
+
+#define DUPLI_ITEM_GROUP \
+ {OB_DUPLIGROUP, "GROUP", 0, "Group", "Enable group instancing"}
static const EnumPropertyItem dupli_items[] = {
- {0, "NONE", 0, "None", ""},
- {OB_DUPLIFRAMES, "FRAMES", 0, "Frames", "Make copy of object for every frame"},
- {OB_DUPLIVERTS, "VERTS", 0, "Verts", "Duplicate child objects on all vertices"},
- {OB_DUPLIFACES, "FACES", 0, "Faces", "Duplicate child objects on all faces"},
- {OB_DUPLIGROUP, "GROUP", 0, "Group", "Enable group instancing"},
+ DUPLI_ITEMS_SHARED,
+ DUPLI_ITEM_GROUP,
{0, NULL, 0, NULL, NULL}
};
-#endif
-
-static const EnumPropertyItem collision_bounds_items[] = {
- {OB_BOUND_BOX, "BOX", ICON_MESH_CUBE, "Box", ""},
- {OB_BOUND_SPHERE, "SPHERE", ICON_MESH_UVSPHERE, "Sphere", ""},
- {OB_BOUND_CYLINDER, "CYLINDER", ICON_MESH_CYLINDER, "Cylinder", ""},
- {OB_BOUND_CONE, "CONE", ICON_MESH_CONE, "Cone", ""},
- {OB_BOUND_CONVEX_HULL, "CONVEX_HULL", ICON_MESH_ICOSPHERE, "Convex Hull", ""},
- {OB_BOUND_TRIANGLE_MESH, "TRIANGLE_MESH", ICON_MESH_MONKEY, "Triangle Mesh", ""},
- {OB_BOUND_CAPSULE, "CAPSULE", ICON_MESH_CAPSULE, "Capsule", ""},
- /*{OB_DYN_MESH, "DYNAMIC_MESH", 0, "Dynamic Mesh", ""}, */
+#ifdef RNA_RUNTIME
+static EnumPropertyItem dupli_items_nogroup[] = {
+ DUPLI_ITEMS_SHARED,
{0, NULL, 0, NULL, NULL}
};
+#endif
+#undef DUPLI_ITEMS_SHARED
+#undef DUPLI_ITEM_GROUP
const EnumPropertyItem rna_enum_metaelem_type_items[] = {
{MB_BALL, "BALL", ICON_META_BALL, "Ball", ""},
@@ -148,6 +147,7 @@ const EnumPropertyItem rna_enum_object_type_items[] = {
{OB_CAMERA, "CAMERA", 0, "Camera", ""},
{OB_LAMP, "LAMP", 0, "Lamp", ""},
{OB_SPEAKER, "SPEAKER", 0, "Speaker", ""},
+ {OB_LIGHTPROBE, "LIGHT_PROBE", 0, "Probe", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -174,25 +174,28 @@ const EnumPropertyItem rna_enum_object_axis_items[] = {
#include "DNA_key_types.h"
#include "DNA_constraint_types.h"
+#include "DNA_ID.h"
#include "DNA_lattice_types.h"
#include "DNA_node_types.h"
#include "BKE_armature.h"
-#include "BKE_bullet.h"
#include "BKE_constraint.h"
#include "BKE_context.h"
#include "BKE_curve.h"
-#include "BKE_depsgraph.h"
#include "BKE_effect.h"
#include "BKE_global.h"
#include "BKE_key.h"
#include "BKE_object.h"
#include "BKE_material.h"
#include "BKE_mesh.h"
+#include "BKE_modifier.h"
#include "BKE_particle.h"
#include "BKE_scene.h"
#include "BKE_deform.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_object.h"
#include "ED_particle.h"
#include "ED_curve.h"
@@ -200,12 +203,12 @@ const EnumPropertyItem rna_enum_object_axis_items[] = {
static void rna_Object_internal_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_id_tag_update(ptr->id.data, OB_RECALC_OB);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_OB);
}
static void rna_Object_internal_update_draw(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_id_tag_update(ptr->id.data, OB_RECALC_OB);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_OB);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ptr->id.data);
}
@@ -218,7 +221,28 @@ static void rna_Object_matrix_world_update(Main *bmain, Scene *scene, PointerRNA
static void rna_Object_hide_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
- DAG_id_type_tag(bmain, ID_OB);
+ DEG_id_type_tag(bmain, ID_OB);
+}
+
+static int rna_Object_is_visible_get(PointerRNA *ptr)
+{
+ Object *ob = ptr->id.data;
+ /* The duplicators final visibility is not evaluated by depsgraph, so it's
+ * in ob->base_flag & VISIBLED. Instead we need to take into account whether
+ * we are rendering or not, and the ob->duplicator_visibility_flag.
+ * However for this assessor we don't know if we are rendering, so we just
+ * ignore the duplicator visibility
+ */
+ return BKE_object_is_visible(ob, OB_VISIBILITY_CHECK_UNKNOWN_RENDER_MODE);
+}
+
+static void rna_Object_collection_properties_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ Object *ob = ptr->data;
+
+ if (ob->base_collection_properties != NULL) {
+ rna_iterator_listbase_begin(iter, &ob->base_collection_properties->data.group, NULL);
+ }
}
static void rna_Object_matrix_local_get(PointerRNA *ptr, float values[16])
@@ -261,22 +285,24 @@ static void rna_Object_matrix_basis_set(PointerRNA *ptr, const float values[16])
void rna_Object_internal_update_data(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ptr->id.data);
}
-static void rna_Object_active_shape_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Object_active_shape_update(bContext *C, PointerRNA *ptr)
{
Object *ob = ptr->id.data;
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
- if (scene->obedit == ob) {
+ if (CTX_data_edit_object(C) == ob) {
/* exit/enter editmode to get new shape */
switch (ob->type) {
case OB_MESH:
EDBM_mesh_load(ob);
EDBM_mesh_make(ob, scene->toolsettings->selectmode, true);
- DAG_id_tag_update(ob->data, 0);
+ DEG_id_tag_update(ob->data, 0);
EDBM_mesh_normals_update(((Mesh *)ob->data)->edit_btmesh);
BKE_editmesh_tessface_calc(((Mesh *)ob->data)->edit_btmesh);
@@ -298,75 +324,11 @@ static void rna_Object_active_shape_update(Main *bmain, Scene *scene, PointerRNA
static void rna_Object_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_id_tag_update(ptr->id.data, OB_RECALC_OB);
- DAG_relations_tag_update(bmain);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_OB);
+ DEG_relations_tag_update(bmain);
WM_main_add_notifier(NC_OBJECT | ND_PARENT, ptr->id.data);
}
-/* when changing the selection flag the scene needs updating */
-static void rna_Object_select_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
-{
- if (scene) {
- Object *ob = (Object *)ptr->id.data;
- short mode = (ob->flag & SELECT) ? BA_SELECT : BA_DESELECT;
- ED_base_object_select(BKE_scene_base_find(scene, ob), mode);
- }
-}
-
-static void rna_Base_select_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
-{
- Base *base = (Base *)ptr->data;
- short mode = (base->flag & BA_SELECT) ? BA_SELECT : BA_DESELECT;
- ED_base_object_select(base, mode);
-}
-
-static void rna_Object_layer_update__internal(Main *bmain, Scene *scene, Base *base, Object *ob)
-{
- /* try to avoid scene sort */
- if (scene == NULL) {
- /* pass - unlikely but when running scripts on startup it happens */
- }
- else if ((ob->lay & scene->lay) && (base->lay & scene->lay)) {
- /* pass */
- }
- else if ((ob->lay & scene->lay) == 0 && (base->lay & scene->lay) == 0) {
- /* pass */
- }
- else {
- DAG_relations_tag_update(bmain);
- }
-
- DAG_id_type_tag(bmain, ID_OB);
-}
-
-static void rna_Object_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
- Base *base;
-
- base = scene ? BKE_scene_base_find(scene, ob) : NULL;
- if (!base)
- return;
-
- SWAP(unsigned int, base->lay, ob->lay);
-
- rna_Object_layer_update__internal(bmain, scene, base, ob);
- ob->lay = base->lay;
-
- WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, scene);
-}
-
-static void rna_Base_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
-{
- Base *base = (Base *)ptr->data;
- Object *ob = (Object *)base->object;
-
- rna_Object_layer_update__internal(bmain, scene, base, ob);
- ob->lay = base->lay;
-
- WM_main_add_notifier(NC_SCENE | ND_LAYER_CONTENT, scene);
-}
-
static void rna_Object_data_set(PointerRNA *ptr, PointerRNA value)
{
Object *ob = (Object *)ptr->data;
@@ -431,6 +393,7 @@ static StructRNA *rna_Object_data_typef(PointerRNA *ptr)
case OB_LATTICE: return &RNA_Lattice;
case OB_ARMATURE: return &RNA_Armature;
case OB_SPEAKER: return &RNA_Speaker;
+ case OB_LIGHTPROBE: return &RNA_LightProbe;
default: return &RNA_ID;
}
}
@@ -493,37 +456,28 @@ static void rna_Object_empty_draw_type_set(PointerRNA *ptr, int value)
BKE_object_empty_draw_type_set(ob, value);
}
-static const EnumPropertyItem *rna_Object_collision_bounds_itemf(bContext *UNUSED(C), PointerRNA *ptr,
- PropertyRNA *UNUSED(prop), bool *r_free)
+static void rna_Object_parent_bone_set(PointerRNA *ptr, const char *value)
{
Object *ob = (Object *)ptr->data;
- EnumPropertyItem *item = NULL;
- int totitem = 0;
- if (ob->body_type != OB_BODY_TYPE_CHARACTER) {
- RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_TRIANGLE_MESH);
- }
- RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_CONVEX_HULL);
-
- if (ob->body_type != OB_BODY_TYPE_SOFT) {
- RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_CONE);
- RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_CYLINDER);
- RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_SPHERE);
- RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_BOX);
- RNA_enum_items_add_value(&item, &totitem, collision_bounds_items, OB_BOUND_CAPSULE);
- }
-
- RNA_enum_item_end(&item, &totitem);
- *r_free = true;
-
- return item;
+ ED_object_parent(ob, ob->parent, ob->partype, value);
}
-static void rna_Object_parent_bone_set(PointerRNA *ptr, const char *value)
+static const EnumPropertyItem *rna_Object_dupli_type_itemf(
+ bContext *UNUSED(C), PointerRNA *ptr,
+ PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
{
Object *ob = (Object *)ptr->data;
+ const EnumPropertyItem *item;
- ED_object_parent(ob, ob->parent, ob->partype, value);
+ if (ob->type == OB_EMPTY) {
+ item = dupli_items;
+ }
+ else {
+ item = dupli_items_nogroup;
+ }
+
+ return item;
}
static void rna_Object_dup_group_set(PointerRNA *ptr, PointerRNA value)
@@ -535,9 +489,15 @@ static void rna_Object_dup_group_set(PointerRNA *ptr, PointerRNA value)
* thus causing a cycle/infinite-recursion leading to crashes on load [#25298]
*/
if (BKE_group_object_exists(grp, ob) == 0) {
- id_us_min(&ob->dup_group->id);
- ob->dup_group = grp;
- id_us_plus(&ob->dup_group->id);
+ if (ob->type == OB_EMPTY) {
+ id_us_min(&ob->dup_group->id);
+ ob->dup_group = grp;
+ id_us_plus(&ob->dup_group->id);
+ }
+ else {
+ BKE_report(NULL, RPT_ERROR,
+ "Only empty objects support group instances");
+ }
}
else {
BKE_report(NULL, RPT_ERROR,
@@ -625,6 +585,87 @@ void rna_object_vgroup_name_set(PointerRNA *ptr, const char *value, char *result
result[0] = '\0';
}
+static void rna_FaceMap_name_set(PointerRNA *ptr, const char *value)
+{
+ Object *ob = (Object *)ptr->id.data;
+ bFaceMap *fmap = (bFaceMap *)ptr->data;
+ BLI_strncpy_utf8(fmap->name, value, sizeof(fmap->name));
+ BKE_object_facemap_unique_name(ob, fmap);
+}
+
+static int rna_FaceMap_index_get(PointerRNA *ptr)
+{
+ Object *ob = (Object *)ptr->id.data;
+
+ return BLI_findindex(&ob->fmaps, ptr->data);
+}
+
+static PointerRNA rna_Object_active_face_map_get(PointerRNA *ptr)
+{
+ Object *ob = (Object *)ptr->id.data;
+ return rna_pointer_inherit_refine(ptr, &RNA_FaceMap, BLI_findlink(&ob->fmaps, ob->actfmap - 1));
+}
+
+static int rna_Object_active_face_map_index_get(PointerRNA *ptr)
+{
+ Object *ob = (Object *)ptr->id.data;
+ return ob->actfmap - 1;
+}
+
+static void rna_Object_active_face_map_index_set(PointerRNA *ptr, int value)
+{
+ Object *ob = (Object *)ptr->id.data;
+ ob->actfmap = value + 1;
+}
+
+static void rna_Object_active_face_map_index_range(PointerRNA *ptr, int *min, int *max,
+ int *UNUSED(softmin), int *UNUSED(softmax))
+{
+ Object *ob = (Object *)ptr->id.data;
+
+ *min = 0;
+ *max = max_ii(0, BLI_listbase_count(&ob->fmaps) - 1);
+}
+
+void rna_object_BKE_object_facemap_name_index_get(PointerRNA *ptr, char *value, int index)
+{
+ Object *ob = (Object *)ptr->id.data;
+ bFaceMap *fmap;
+
+ fmap = BLI_findlink(&ob->fmaps, index - 1);
+
+ if (fmap) BLI_strncpy(value, fmap->name, sizeof(fmap->name));
+ else value[0] = '\0';
+}
+
+int rna_object_BKE_object_facemap_name_index_length(PointerRNA *ptr, int index)
+{
+ Object *ob = (Object *)ptr->id.data;
+ bFaceMap *fmap;
+
+ fmap = BLI_findlink(&ob->fmaps, index - 1);
+ return (fmap) ? strlen(fmap->name) : 0;
+}
+
+void rna_object_BKE_object_facemap_name_index_set(PointerRNA *ptr, const char *value, short *index)
+{
+ Object *ob = (Object *)ptr->id.data;
+ *index = BKE_object_facemap_name_index(ob, value) + 1;
+}
+
+void rna_object_fmap_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
+{
+ Object *ob = (Object *)ptr->id.data;
+ bFaceMap *fmap = BKE_object_facemap_find_name(ob, value);
+ if (fmap) {
+ BLI_strncpy(result, value, maxlen); /* no need for BLI_strncpy_utf8, since this matches an existing group */
+ return;
+ }
+
+ result[0] = '\0';
+}
+
+
void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *result, int maxlen)
{
Object *ob = (Object *)ptr->id.data;
@@ -635,10 +676,10 @@ void rna_object_uvlayer_name_set(PointerRNA *ptr, const char *value, char *resul
if (ob->type == OB_MESH && ob->data) {
me = (Mesh *)ob->data;
- for (a = 0; a < me->pdata.totlayer; a++) {
- layer = &me->pdata.layers[a];
+ for (a = 0; a < me->ldata.totlayer; a++) {
+ layer = &me->ldata.layers[a];
- if (layer->type == CD_MTEXPOLY && STREQ(layer->name, value)) {
+ if (layer->type == CD_MLOOPUV && STREQ(layer->name, value)) {
BLI_strncpy(result, value, maxlen);
return;
}
@@ -712,7 +753,7 @@ static void rna_Object_active_material_set(PointerRNA *ptr, PointerRNA value)
{
Object *ob = (Object *)ptr->id.data;
- DAG_id_tag_update(value.data, 0);
+ DEG_id_tag_update(value.data, 0);
assign_material(ob, value.data, ob->actcol, BKE_MAT_ASSIGN_EXISTING);
}
@@ -754,9 +795,14 @@ static void rna_Object_active_particle_system_index_set(PointerRNA *ptr, int val
static void rna_Object_particle_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
{
+ /* TODO: Disabled for now, because bContext is not available. */
+#if 0
Object *ob = (Object *)ptr->id.data;
-
- PE_current_changed(scene, ob);
+ PE_current_changed(NULL, scene, ob);
+#else
+ (void) scene;
+ (void) ptr;
+#endif
}
/* rotation - axis-angle */
@@ -945,7 +991,7 @@ static void rna_MaterialSlot_update(Main *bmain, Scene *scene, PointerRNA *ptr)
WM_main_add_notifier(NC_OBJECT | ND_OB_SHADING, ptr->id.data);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING_LINKS, NULL);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
static char *rna_MaterialSlot_path(PointerRNA *ptr)
@@ -962,122 +1008,6 @@ static char *rna_MaterialSlot_path(PointerRNA *ptr)
*
* logic from check_body_type()
* */
-static int rna_GameObjectSettings_physics_type_get(PointerRNA *ptr)
-{
- Object *ob = (Object *)ptr->id.data;
-
- /* determine the body_type setting based on flags */
- if (!(ob->gameflag & OB_COLLISION)) {
- if (ob->gameflag & OB_OCCLUDER) {
- ob->body_type = OB_BODY_TYPE_OCCLUDER;
- }
- else if (ob->gameflag & OB_NAVMESH) {
- ob->body_type = OB_BODY_TYPE_NAVMESH;
- }
- else {
- ob->body_type = OB_BODY_TYPE_NO_COLLISION;
- }
- }
- else if (ob->gameflag & OB_CHARACTER) {
- ob->body_type = OB_BODY_TYPE_CHARACTER;
- }
- else if (ob->gameflag & OB_SENSOR) {
- ob->body_type = OB_BODY_TYPE_SENSOR;
- }
- else if (!(ob->gameflag & OB_DYNAMIC)) {
- ob->body_type = OB_BODY_TYPE_STATIC;
- }
- else if (!(ob->gameflag & (OB_RIGID_BODY | OB_SOFT_BODY))) {
- ob->body_type = OB_BODY_TYPE_DYNAMIC;
- }
- else if (ob->gameflag & OB_RIGID_BODY) {
- ob->body_type = OB_BODY_TYPE_RIGID;
- }
- else {
- ob->body_type = OB_BODY_TYPE_SOFT;
- /* create the structure here because we display soft body buttons in the main panel */
- if (!ob->bsoft)
- ob->bsoft = bsbNew();
- }
-
- return ob->body_type;
-}
-
-static void rna_GameObjectSettings_physics_type_set(PointerRNA *ptr, int value)
-{
- Object *ob = (Object *)ptr->id.data;
- const int gameflag_prev = ob->gameflag;
- ob->body_type = value;
-
- switch (ob->body_type) {
- case OB_BODY_TYPE_SENSOR:
- ob->gameflag |= OB_SENSOR | OB_COLLISION;
- ob->gameflag &= ~(OB_OCCLUDER | OB_CHARACTER | OB_DYNAMIC | OB_RIGID_BODY | OB_SOFT_BODY | OB_ACTOR |
- OB_ANISOTROPIC_FRICTION | OB_DO_FH | OB_ROT_FH | OB_COLLISION_RESPONSE | OB_NAVMESH);
- break;
- case OB_BODY_TYPE_OCCLUDER:
- ob->gameflag |= OB_OCCLUDER;
- ob->gameflag &= ~(OB_SENSOR | OB_RIGID_BODY | OB_SOFT_BODY | OB_COLLISION | OB_CHARACTER | OB_DYNAMIC | OB_NAVMESH);
- break;
- case OB_BODY_TYPE_NAVMESH:
- ob->gameflag |= OB_NAVMESH;
- ob->gameflag &= ~(OB_SENSOR | OB_RIGID_BODY | OB_SOFT_BODY | OB_COLLISION | OB_CHARACTER | OB_DYNAMIC | OB_OCCLUDER);
-
- if (ob->type == OB_MESH) {
- /* could be moved into mesh UI but for now ensure mesh data layer */
- BKE_mesh_ensure_navmesh(ob->data);
- }
-
- break;
- case OB_BODY_TYPE_NO_COLLISION:
- ob->gameflag &= ~(OB_SENSOR | OB_RIGID_BODY | OB_SOFT_BODY | OB_COLLISION | OB_CHARACTER | OB_OCCLUDER | OB_DYNAMIC | OB_NAVMESH);
- break;
- case OB_BODY_TYPE_CHARACTER:
- ob->gameflag |= OB_COLLISION | OB_CHARACTER;
- ob->gameflag &= ~(OB_SENSOR | OB_OCCLUDER | OB_DYNAMIC | OB_RIGID_BODY | OB_SOFT_BODY | OB_ACTOR |
- OB_ANISOTROPIC_FRICTION | OB_DO_FH | OB_ROT_FH | OB_COLLISION_RESPONSE | OB_NAVMESH);
- /* When we switch to character physics and the collision bounds is set to triangle mesh
- * we have to change collision bounds because triangle mesh is not supported by Characters */
- if ((ob->gameflag & OB_BOUNDS) && ob->collision_boundtype == OB_BOUND_TRIANGLE_MESH) {
- ob->boundtype = ob->collision_boundtype = OB_BOUND_BOX;
- }
- break;
- case OB_BODY_TYPE_STATIC:
- ob->gameflag |= OB_COLLISION;
- ob->gameflag &= ~(OB_DYNAMIC | OB_RIGID_BODY | OB_SOFT_BODY | OB_OCCLUDER | OB_CHARACTER | OB_SENSOR | OB_NAVMESH);
- break;
- case OB_BODY_TYPE_DYNAMIC:
- ob->gameflag |= OB_COLLISION | OB_DYNAMIC | OB_ACTOR;
- ob->gameflag &= ~(OB_RIGID_BODY | OB_SOFT_BODY | OB_OCCLUDER | OB_CHARACTER | OB_SENSOR | OB_NAVMESH);
- break;
- case OB_BODY_TYPE_RIGID:
- ob->gameflag |= OB_COLLISION | OB_DYNAMIC | OB_RIGID_BODY | OB_ACTOR;
- ob->gameflag &= ~(OB_SOFT_BODY | OB_OCCLUDER | OB_CHARACTER | OB_SENSOR | OB_NAVMESH);
- break;
- default:
- case OB_BODY_TYPE_SOFT:
- ob->gameflag |= OB_COLLISION | OB_DYNAMIC | OB_SOFT_BODY | OB_ACTOR;
- ob->gameflag &= ~(OB_RIGID_BODY | OB_OCCLUDER | OB_CHARACTER | OB_SENSOR | OB_NAVMESH);
-
- /* assume triangle mesh, if no bounds chosen for soft body */
- if ((ob->gameflag & OB_BOUNDS) && (ob->boundtype < OB_BOUND_TRIANGLE_MESH)) {
- ob->boundtype = OB_BOUND_TRIANGLE_MESH;
- }
- /* create a BulletSoftBody structure if not already existing */
- if (!ob->bsoft)
- ob->bsoft = bsbNew();
- break;
- }
-
- if ((gameflag_prev & OB_NAVMESH) != (ob->gameflag & OB_NAVMESH)) {
- if (ob->type == OB_MESH) {
- /* this is needed to refresh the derived meshes draw func */
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
- }
- }
-
- WM_main_add_notifier(NC_OBJECT | ND_DRAW, ptr->id.data);
-}
static PointerRNA rna_Object_active_particle_system_get(PointerRNA *ptr)
{
@@ -1086,160 +1016,6 @@ static PointerRNA rna_Object_active_particle_system_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_ParticleSystem, psys);
}
-static PointerRNA rna_Object_game_settings_get(PointerRNA *ptr)
-{
- return rna_pointer_inherit_refine(ptr, &RNA_GameObjectSettings, ptr->id.data);
-}
-
-
-static unsigned int rna_Object_layer_validate__internal(const int *values, unsigned int lay)
-{
- int i, tot = 0;
-
- /* ensure we always have some layer selected */
- for (i = 0; i < 20; i++)
- if (values[i])
- tot++;
-
- if (tot == 0)
- return 0;
-
- for (i = 0; i < 20; i++) {
- if (values[i]) lay |= (1 << i);
- else lay &= ~(1 << i);
- }
-
- return lay;
-}
-
-static void rna_Object_layer_set(PointerRNA *ptr, const int *values)
-{
- Object *ob = (Object *)ptr->data;
- unsigned int lay;
-
- lay = rna_Object_layer_validate__internal(values, ob->lay);
- if (lay)
- ob->lay = lay;
-}
-
-static void rna_Base_layer_set(PointerRNA *ptr, const int *values)
-{
- Base *base = (Base *)ptr->data;
-
- unsigned int lay;
- lay = rna_Object_layer_validate__internal(values, base->lay);
- if (lay)
- base->lay = lay;
-
- /* rna_Base_layer_update updates the objects layer */
-}
-
-static void rna_GameObjectSettings_state_get(PointerRNA *ptr, int *values)
-{
- Object *ob = (Object *)ptr->data;
- int i;
- int all_states = (ob->scaflag & OB_ALLSTATE) ? 1 : 0;
-
- memset(values, 0, sizeof(int) * OB_MAX_STATES);
- for (i = 0; i < OB_MAX_STATES; i++) {
- values[i] = (ob->state & (1 << i)) ? 1 : 0 | all_states;
- }
-}
-
-static void rna_GameObjectSettings_state_set(PointerRNA *ptr, const int *values)
-{
- Object *ob = (Object *)ptr->data;
- int i, tot = 0;
-
- /* ensure we always have some state selected */
- for (i = 0; i < OB_MAX_STATES; i++)
- if (values[i])
- tot++;
-
- if (tot == 0)
- return;
-
- for (i = 0; i < OB_MAX_STATES; i++) {
- if (values[i]) ob->state |= (1 << i);
- else ob->state &= ~(1 << i);
- }
-}
-
-static void rna_GameObjectSettings_used_state_get(PointerRNA *ptr, int *values)
-{
- Object *ob = (Object *)ptr->data;
- bController *cont;
-
- memset(values, 0, sizeof(int) * OB_MAX_STATES);
- for (cont = ob->controllers.first; cont; cont = cont->next) {
- int i;
-
- for (i = 0; i < OB_MAX_STATES; i++) {
- if (cont->state_mask & (1 << i))
- values[i] = 1;
- }
- }
-}
-
-static void rna_GameObjectSettings_col_group_get(PointerRNA *ptr, int *values)
-{
- Object *ob = (Object *)ptr->data;
- int i;
-
- for (i = 0; i < OB_MAX_COL_MASKS; i++) {
- values[i] = (ob->col_group & (1 << i)) != 0;
- }
-}
-
-static void rna_GameObjectSettings_col_group_set(PointerRNA *ptr, const int *values)
-{
- Object *ob = (Object *)ptr->data;
- int i, tot = 0;
-
- /* ensure we always have some group selected */
- for (i = 0; i < OB_MAX_COL_MASKS; i++)
- if (values[i])
- tot++;
-
- if (tot == 0)
- return;
-
- for (i = 0; i < OB_MAX_COL_MASKS; i++) {
- if (values[i]) ob->col_group |= (1 << i);
- else ob->col_group &= ~(1 << i);
- }
-}
-
-static void rna_GameObjectSettings_col_mask_get(PointerRNA *ptr, int *values)
-{
- Object *ob = (Object *)ptr->data;
- int i;
-
- for (i = 0; i < OB_MAX_COL_MASKS; i++) {
- values[i] = (ob->col_mask & (1 << i)) != 0;
- }
-}
-
-static void rna_GameObjectSettings_col_mask_set(PointerRNA *ptr, const int *values)
-{
- Object *ob = (Object *)ptr->data;
- int i, tot = 0;
-
- /* ensure we always have some mask selected */
- for (i = 0; i < OB_MAX_COL_MASKS; i++)
- if (values[i])
- tot++;
-
- if (tot == 0)
- return;
-
- for (i = 0; i < OB_MAX_COL_MASKS; i++) {
- if (values[i]) ob->col_mask |= (1 << i);
- else ob->col_mask &= ~(1 << i);
- }
-}
-
-
static void rna_Object_active_shape_key_index_range(PointerRNA *ptr, int *min, int *max,
int *UNUSED(softmin), int *UNUSED(softmax))
{
@@ -1359,6 +1135,54 @@ static void rna_Object_constraints_clear(Object *object)
WM_main_add_notifier(NC_OBJECT | ND_CONSTRAINT | NA_REMOVED, object);
}
+bool rna_Object_constraints_override_apply(
+ PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *UNUSED(ptr_storage),
+ PropertyRNA *UNUSED(prop_dst), PropertyRNA *UNUSED(prop_src), PropertyRNA *UNUSED(prop_storage),
+ const int UNUSED(len_dst), const int UNUSED(len_src), const int UNUSED(len_storage),
+ IDOverrideStaticPropertyOperation *opop)
+{
+ BLI_assert(opop->operation == IDOVERRIDESTATIC_OP_INSERT_AFTER &&
+ "Unsupported RNA override operation on constraints collection");
+
+ Object *ob_dst = (Object *)ptr_dst->id.data;
+ Object *ob_src = (Object *)ptr_src->id.data;
+
+ /* Remember that insertion operations are defined and stored in correct order, which means that
+ * even if we insert several items in a row, we alays insert first one, then second one, etc.
+ * So we should always find 'anchor' constraint in both _src *and* _dst> */
+ bConstraint *con_anchor = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ con_anchor = BLI_findstring(&ob_dst->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
+ }
+ if (con_anchor == NULL && opop->subitem_local_index >= 0) {
+ con_anchor = BLI_findlink(&ob_dst->constraints, opop->subitem_local_index);
+ }
+ /* Otherwise we just insert in first position. */
+
+ bConstraint *con_src = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ con_src = BLI_findstring(&ob_src->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
+ }
+ if (con_src == NULL && opop->subitem_local_index >= 0) {
+ con_src = BLI_findlink(&ob_src->constraints, opop->subitem_local_index);
+ }
+ con_src = con_src ? con_src->next : ob_src->constraints.first;
+
+ BLI_assert(con_src != NULL);
+
+ bConstraint *con_dst = BKE_constraint_duplicate_ex(con_src, 0, true);
+
+ /* This handles NULL anchor as expected by adding at head of list. */
+ BLI_insertlinkafter(&ob_dst->constraints, con_anchor, con_dst);
+
+ /* This should actually *not* be needed in typical cases. However, if overridden source was edited,
+ * we *may* have some new conflicting names. */
+ BKE_constraint_unique_name(con_dst, &ob_dst->constraints);
+
+// printf("%s: We inserted a constraint...\n", __func__);
+ return true;
+}
+
static ModifierData *rna_Object_modifier_new(Object *object, bContext *C, ReportList *reports,
const char *name, int type)
{
@@ -1385,6 +1209,55 @@ static void rna_Object_modifier_clear(Object *object, bContext *C)
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, object);
}
+bool rna_Object_modifiers_override_apply(
+ PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *UNUSED(ptr_storage),
+ PropertyRNA *UNUSED(prop_dst), PropertyRNA *UNUSED(prop_src), PropertyRNA *UNUSED(prop_storage),
+ const int UNUSED(len_dst), const int UNUSED(len_src), const int UNUSED(len_storage),
+ IDOverrideStaticPropertyOperation *opop)
+{
+ BLI_assert(opop->operation == IDOVERRIDESTATIC_OP_INSERT_AFTER &&
+ "Unsupported RNA override operation on modifiers collection");
+
+ Object *ob_dst = (Object *)ptr_dst->id.data;
+ Object *ob_src = (Object *)ptr_src->id.data;
+
+ /* Remember that insertion operations are defined and stored in correct order, which means that
+ * even if we insert several items in a row, we alays insert first one, then second one, etc.
+ * So we should always find 'anchor' constraint in both _src *and* _dst> */
+ ModifierData *mod_anchor = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ mod_anchor = BLI_findstring(&ob_dst->modifiers, opop->subitem_local_name, offsetof(ModifierData, name));
+ }
+ if (mod_anchor == NULL && opop->subitem_local_index >= 0) {
+ mod_anchor = BLI_findlink(&ob_dst->modifiers, opop->subitem_local_index);
+ }
+ /* Otherwise we just insert in first position. */
+
+ ModifierData *mod_src = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ mod_src = BLI_findstring(&ob_src->modifiers, opop->subitem_local_name, offsetof(ModifierData, name));
+ }
+ if (mod_src == NULL && opop->subitem_local_index >= 0) {
+ mod_src = BLI_findlink(&ob_src->modifiers, opop->subitem_local_index);
+ }
+ mod_src = mod_src ? mod_src->next : ob_src->modifiers.first;
+
+ BLI_assert(mod_src != NULL);
+
+ ModifierData *mod_dst = modifier_new(mod_src->type);
+ modifier_copyData(mod_src, mod_dst);
+
+ /* This handles NULL anchor as expected by adding at head of list. */
+ BLI_insertlinkafter(&ob_dst->modifiers, mod_anchor, mod_dst);
+
+ /* This should actually *not* be needed in typical cases. However, if overridden source was edited,
+ * we *may* have some new conflicting names. */
+ modifier_unique_name(&ob_dst->modifiers, mod_dst);
+
+// printf("%s: We inserted a modifier...\n", __func__);
+ return true;
+}
+
static void rna_Object_boundbox_get(PointerRNA *ptr, float *values)
{
Object *ob = (Object *)ptr->id.data;
@@ -1469,6 +1342,69 @@ static float rna_VertexGroup_weight(ID *id, bDeformGroup *dg, ReportList *report
return weight;
}
+static bFaceMap *rna_Object_fmap_new(Object *ob, const char *name)
+{
+ bFaceMap *fmap = BKE_object_facemap_add_name(ob, name);
+
+ WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
+
+ return fmap;
+}
+
+static void rna_Object_fmap_remove(Object *ob, ReportList *reports, PointerRNA *fmap_ptr)
+{
+ bFaceMap *fmap = fmap_ptr->data;
+ if (BLI_findindex(&ob->fmaps, fmap) == -1) {
+ BKE_reportf(reports, RPT_ERROR, "FaceMap '%s' not in object '%s'", fmap->name, ob->id.name + 2);
+ return;
+ }
+
+ BKE_object_facemap_remove(ob, fmap);
+ RNA_POINTER_INVALIDATE(fmap_ptr);
+
+ WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
+}
+
+
+static void rna_Object_fmap_clear(Object *ob)
+{
+ BKE_object_facemap_clear(ob);
+
+ WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
+}
+
+
+static void rna_FaceMap_face_add(ID *id, bFaceMap *fmap, ReportList *reports, int index_len,
+ int *index)
+{
+ Object *ob = (Object *)id;
+
+ if (BKE_object_is_in_editmode(ob)) {
+ BKE_report(reports, RPT_ERROR, "FaceMap.add(): cannot be called while object is in edit mode");
+ return;
+ }
+
+ while (index_len--)
+ ED_object_facemap_face_add(ob, fmap, *index++);
+
+ WM_main_add_notifier(NC_GEOM | ND_DATA, (ID *)ob->data);
+}
+
+static void rna_FaceMap_face_remove(ID *id, bFaceMap *fmap, ReportList *reports, int index_len, int *index)
+{
+ Object *ob = (Object *)id;
+
+ if (BKE_object_is_in_editmode(ob)) {
+ BKE_report(reports, RPT_ERROR, "FaceMap.add(): cannot be called while object is in edit mode");
+ return;
+ }
+
+ while (index_len--)
+ ED_object_facemap_face_remove(ob, fmap, *index++);
+
+ WM_main_add_notifier(NC_GEOM | ND_DATA, (ID *)ob->data);
+}
+
/* generic poll functions */
int rna_Lattice_object_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
{
@@ -1512,16 +1448,6 @@ int rna_Object_use_dynamic_topology_sculpting_get(PointerRNA *ptr)
return (ss && ss->bm);
}
-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
static void rna_def_vertex_group(BlenderRNA *brna)
@@ -1588,6 +1514,49 @@ static void rna_def_vertex_group(BlenderRNA *brna)
RNA_def_function_return(func, parm);
}
+static void rna_def_face_map(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+ FunctionRNA *func;
+
+ srna = RNA_def_struct(brna, "FaceMap", NULL);
+ RNA_def_struct_sdna(srna, "bFaceMap");
+ RNA_def_struct_ui_text(srna, "Face Map", "Group of faces, each face can only be part of one map");
+ RNA_def_struct_ui_icon(srna, ICON_MOD_TRIANGULATE);
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Name", "Face map name");
+ RNA_def_struct_name_property(srna, prop);
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_FaceMap_name_set");
+ /* update data because modifiers may use [#24761] */
+ RNA_def_property_update(prop, NC_GEOM | ND_DATA | NA_RENAME, "rna_Object_internal_update_data");
+
+ prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
+ RNA_def_property_ui_text(prop, "Select", "Face-map selection state (for tools to use)");
+ /* important not to use a notifier here, creates a feedback loop! */
+
+ prop = RNA_def_property(srna, "index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_int_funcs(prop, "rna_FaceMap_index_get", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Index", "Index number of the face map");
+
+ func = RNA_def_function(srna, "add", "rna_FaceMap_face_add");
+ RNA_def_function_ui_description(func, "Add vertices to the group");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
+ /* TODO, see how array size of 0 works, this shouldnt be used */
+ prop = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List", 0, 0);
+ RNA_def_parameter_flags(prop, PROP_DYNAMIC, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "remove", "rna_FaceMap_face_remove");
+ RNA_def_function_ui_description(func, "Remove a vertex from the group");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
+ /* TODO, see how array size of 0 works, this shouldnt be used */
+ prop = RNA_def_int_array(func, "index", 1, NULL, 0, 0, "", "Index List", 0, 0);
+ RNA_def_parameter_flags(prop, PROP_DYNAMIC, PARM_REQUIRED);
+}
+
static void rna_def_material_slot(BlenderRNA *brna)
{
StructRNA *srna;
@@ -1629,313 +1598,6 @@ static void rna_def_material_slot(BlenderRNA *brna)
RNA_def_struct_path_func(srna, "rna_MaterialSlot_path");
}
-static void rna_def_object_game_settings(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem body_type_items[] = {
- {OB_BODY_TYPE_NO_COLLISION, "NO_COLLISION", 0, "No Collision", "Disable collision for this object"},
- {OB_BODY_TYPE_STATIC, "STATIC", 0, "Static", "Stationary object"},
- {OB_BODY_TYPE_DYNAMIC, "DYNAMIC", 0, "Dynamic", "Linear physics"},
- {OB_BODY_TYPE_RIGID, "RIGID_BODY", 0, "Rigid Body", "Linear and angular physics"},
- {OB_BODY_TYPE_SOFT, "SOFT_BODY", 0, "Soft Body", "Soft body"},
- {OB_BODY_TYPE_OCCLUDER, "OCCLUDER", 0, "Occluder", "Occluder for optimizing scene rendering"},
- {OB_BODY_TYPE_SENSOR, "SENSOR", 0, "Sensor",
- "Collision Sensor, detects static and dynamic objects but not the other "
- "collision sensor objects"},
- {OB_BODY_TYPE_NAVMESH, "NAVMESH", 0, "Navigation Mesh", "Navigation mesh"},
- {OB_BODY_TYPE_CHARACTER, "CHARACTER", 0, "Character",
- "Simple kinematic physics appropriate for game characters"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "GameObjectSettings", NULL);
- RNA_def_struct_sdna(srna, "Object");
- RNA_def_struct_nested(brna, srna, "Object");
- RNA_def_struct_ui_text(srna, "Game Object Settings", "Game engine related settings for the object");
- RNA_def_struct_ui_icon(srna, ICON_GAME);
-
- /* logic */
-
- prop = RNA_def_property(srna, "sensors", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_struct_type(prop, "Sensor");
- RNA_def_property_ui_text(prop, "Sensors", "Game engine sensor to detect events");
-
- prop = RNA_def_property(srna, "controllers", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_struct_type(prop, "Controller");
- RNA_def_property_ui_text(prop, "Controllers",
- "Game engine controllers to process events, connecting sensors to actuators");
-
- prop = RNA_def_property(srna, "actuators", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_struct_type(prop, "Actuator");
- RNA_def_property_ui_text(prop, "Actuators", "Game engine actuators to act on events");
-
- prop = RNA_def_property(srna, "properties", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "prop", NULL);
- RNA_def_property_struct_type(prop, "GameProperty"); /* rna_property.c */
- RNA_def_property_ui_text(prop, "Properties", "Game engine properties");
-
- prop = RNA_def_property(srna, "show_sensors", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", OB_SHOWSENS);
- RNA_def_property_ui_text(prop, "Show Sensors", "Shows sensors for this object in the user interface");
-
- prop = RNA_def_property(srna, "show_controllers", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", OB_SHOWCONT);
- RNA_def_property_ui_text(prop, "Show Controllers", "Shows controllers for this object in the user interface");
-
- prop = RNA_def_property(srna, "show_actuators", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", OB_SHOWACT);
- RNA_def_property_ui_text(prop, "Show Actuators", "Shows actuators for this object in the user interface");
-
- /* physics */
-
- prop = RNA_def_property(srna, "physics_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "body_type");
- RNA_def_property_enum_items(prop, body_type_items);
- RNA_def_property_enum_default(prop, OB_BODY_TYPE_STATIC);
- RNA_def_property_enum_funcs(prop, "rna_GameObjectSettings_physics_type_get",
- "rna_GameObjectSettings_physics_type_set", NULL);
- RNA_def_property_ui_text(prop, "Physics Type", "Select the type of physical representation");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_record_animation", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_RECORD_ANIMATION);
- RNA_def_property_ui_text(prop, "Record Animation", "Record animation objects without physics");
-
- prop = RNA_def_property(srna, "use_actor", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_ACTOR);
- RNA_def_property_ui_text(prop, "Actor", "Object is detected by the Near and Radar sensor");
-
- prop = RNA_def_property(srna, "use_ghost", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_GHOST);
- RNA_def_property_ui_text(prop, "Ghost", "Object does not react to collisions, like a ghost");
-
- prop = RNA_def_property(srna, "mass", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.01, 10000.0);
- RNA_def_property_float_default(prop, 1.0f);
- RNA_def_property_ui_text(prop, "Mass", "Mass of the object");
-
- prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_NONE | PROP_UNIT_LENGTH);
- RNA_def_property_float_sdna(prop, NULL, "inertia");
- RNA_def_property_range(prop, 0.01f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.01f, 10.0f, 1, 3);
- RNA_def_property_float_default(prop, 1.0f);
- RNA_def_property_ui_text(prop, "Radius", "Radius of bounding sphere and material physics");
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
-
- prop = RNA_def_property(srna, "use_sleep", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_COLLISION_RESPONSE);
- RNA_def_property_ui_text(prop, "No Sleeping", "Disable auto (de)activation in physics simulation");
-
- prop = RNA_def_property(srna, "damping", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "damping");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_float_default(prop, 0.04f);
- RNA_def_property_ui_text(prop, "Damping", "General movement damping");
-
- prop = RNA_def_property(srna, "rotation_damping", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "rdamping");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_float_default(prop, 0.1f);
- RNA_def_property_ui_text(prop, "Rotation Damping", "General rotation damping");
-
- prop = RNA_def_property(srna, "velocity_min", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "min_vel");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Velocity Min", "Clamp velocity to this minimum speed (except when totally still), "
- "in distance per second");
-
- prop = RNA_def_property(srna, "velocity_max", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "max_vel");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Velocity Max", "Clamp velocity to this maximum speed, "
- "in distance per second");
-
- prop = RNA_def_property(srna, "angular_velocity_min", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "min_angvel");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Angular Velocity Min",
- "Clamp angular velocity to this minimum speed (except when totally still), "
- "in angle per second");
-
- prop = RNA_def_property(srna, "angular_velocity_max", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "max_angvel");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Angular Velocity Max", "Clamp angular velocity to this maximum speed, "
- "in angle per second");
-
- /* Character physics */
- prop = RNA_def_property(srna, "step_height", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "step_height");
- RNA_def_property_range(prop, 0.01, 1.0);
- RNA_def_property_float_default(prop, 0.15f);
- RNA_def_property_ui_text(prop, "Step Height", "Maximum height of steps the character can run over");
-
- prop = RNA_def_property(srna, "jump_speed", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "jump_speed");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_float_default(prop, 10.0f);
- RNA_def_property_ui_text(prop, "Jump Force", "Upward velocity applied to the character when jumping");
-
- prop = RNA_def_property(srna, "fall_speed", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "fall_speed");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_float_default(prop, 55.0f);
- RNA_def_property_ui_text(prop, "Fall Speed Max", "Maximum speed at which the character will fall");
-
- prop = RNA_def_property(srna, "jump_max", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "max_jumps");
- RNA_def_property_range(prop, 1, CHAR_MAX);
- RNA_def_property_ui_range(prop, 1, 10, 1, 1);
- RNA_def_property_int_default(prop, 1);
- RNA_def_property_ui_text(prop, "Max Jumps",
- "The maximum number of jumps the character can make before it hits the ground");
-
- /* Collision Masks */
- prop = RNA_def_property(srna, "collision_group", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "col_group", 1);
- RNA_def_property_array(prop, OB_MAX_COL_MASKS);
- RNA_def_property_ui_text(prop, "Collision Group", "The collision group of the object");
- RNA_def_property_boolean_funcs(prop, "rna_GameObjectSettings_col_group_get", "rna_GameObjectSettings_col_group_set");
-
- prop = RNA_def_property(srna, "collision_mask", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "col_mask", 1);
- RNA_def_property_array(prop, OB_MAX_COL_MASKS);
- RNA_def_property_ui_text(prop, "Collision Mask", "The groups this object can collide with");
- RNA_def_property_boolean_funcs(prop, "rna_GameObjectSettings_col_mask_get", "rna_GameObjectSettings_col_mask_set");
-
- /* lock position */
- prop = RNA_def_property(srna, "lock_location_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag2", OB_LOCK_RIGID_BODY_X_AXIS);
- RNA_def_property_ui_text(prop, "Lock X Axis", "Disable simulation of linear motion along the X axis");
-
- prop = RNA_def_property(srna, "lock_location_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag2", OB_LOCK_RIGID_BODY_Y_AXIS);
- RNA_def_property_ui_text(prop, "Lock Y Axis", "Disable simulation of linear motion along the Y axis");
-
- prop = RNA_def_property(srna, "lock_location_z", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag2", OB_LOCK_RIGID_BODY_Z_AXIS);
- RNA_def_property_ui_text(prop, "Lock Z Axis", "Disable simulation of linear motion along the Z axis");
-
-
- /* lock rotation */
- prop = RNA_def_property(srna, "lock_rotation_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag2", OB_LOCK_RIGID_BODY_X_ROT_AXIS);
- RNA_def_property_ui_text(prop, "Lock X Rotation Axis", "Disable simulation of angular motion along the X axis");
-
- prop = RNA_def_property(srna, "lock_rotation_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag2", OB_LOCK_RIGID_BODY_Y_ROT_AXIS);
- RNA_def_property_ui_text(prop, "Lock Y Rotation Axis", "Disable simulation of angular motion along the Y axis");
-
- prop = RNA_def_property(srna, "lock_rotation_z", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag2", OB_LOCK_RIGID_BODY_Z_ROT_AXIS);
- RNA_def_property_ui_text(prop, "Lock Z Rotation Axis", "Disable simulation of angular motion along the Z axis");
-
- /* is this used anywhere ? */
- prop = RNA_def_property(srna, "use_activity_culling", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "gameflag2", OB_NEVER_DO_ACTIVITY_CULLING);
- RNA_def_property_ui_text(prop, "Lock Z Rotation Axis", "Disable simulation of angular motion along the Z axis");
-
-
- prop = RNA_def_property(srna, "use_material_physics_fh", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_DO_FH);
- RNA_def_property_ui_text(prop, "Use Material Force Field", "React to force field physics settings in materials");
-
- prop = RNA_def_property(srna, "use_rotate_from_normal", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_ROT_FH);
- RNA_def_property_ui_text(prop, "Rotate From Normal",
- "Use face normal to rotate object, so that it points away from the surface");
-
- prop = RNA_def_property(srna, "form_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "formfactor");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_float_default(prop, 0.4f);
- RNA_def_property_ui_text(prop, "Form Factor", "Form factor scales the inertia tensor");
-
- prop = RNA_def_property(srna, "use_anisotropic_friction", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_ANISOTROPIC_FRICTION);
- RNA_def_property_ui_text(prop, "Anisotropic Friction", "Enable anisotropic friction");
-
- prop = RNA_def_property(srna, "friction_coefficients", PROP_FLOAT, PROP_XYZ);
- RNA_def_property_float_sdna(prop, NULL, "anisotropicFriction");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_ui_text(prop, "Friction Coefficients",
- "Relative friction coefficients in the in the X, Y and Z directions, "
- "when anisotropic friction is enabled");
-
- prop = RNA_def_property(srna, "use_collision_bounds", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_BOUNDS);
- RNA_def_property_ui_text(prop, "Use Collision Bounds", "Specify a collision bounds type other than the default");
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
-
- prop = RNA_def_property(srna, "collision_bounds_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "collision_boundtype");
- RNA_def_property_enum_items(prop, collision_bounds_items);
- RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Object_collision_bounds_itemf");
- RNA_def_property_ui_text(prop, "Collision Shape", "Select the collision shape that better fits the object");
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
-
- prop = RNA_def_property(srna, "use_collision_compound", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_CHILD);
- RNA_def_property_ui_text(prop, "Collision Compound", "Add children to form a compound collision object");
-
- prop = RNA_def_property(srna, "collision_margin", PROP_FLOAT, PROP_NONE | PROP_UNIT_LENGTH);
- RNA_def_property_float_sdna(prop, NULL, "margin");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_float_default(prop, 0.04f);
- RNA_def_property_ui_text(prop, "Collision Margin",
- "Extra margin around object for collision detection, small amount required "
- "for stability");
-
- prop = RNA_def_property(srna, "soft_body", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "bsoft");
- RNA_def_property_ui_text(prop, "Soft Body Settings", "Settings for Bullet soft body simulation");
-
- prop = RNA_def_property(srna, "use_obstacle_create", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gameflag", OB_HASOBSTACLE);
- RNA_def_property_ui_text(prop, "Create obstacle", "Create representation for obstacle simulation");
-
- prop = RNA_def_property(srna, "obstacle_radius", PROP_FLOAT, PROP_NONE | PROP_UNIT_LENGTH);
- RNA_def_property_float_sdna(prop, NULL, "obstacleRad");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_float_default(prop, 1.0f);
- RNA_def_property_ui_text(prop, "Obstacle Radius", "Radius of object representation in obstacle simulation");
-
- /* state */
-
- prop = RNA_def_property(srna, "states_visible", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "state", 1);
- RNA_def_property_array(prop, OB_MAX_STATES);
- RNA_def_property_ui_text(prop, "State", "State determining which controllers are displayed");
- RNA_def_property_boolean_funcs(prop, "rna_GameObjectSettings_state_get", "rna_GameObjectSettings_state_set");
-
- prop = RNA_def_property(srna, "used_states", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_array(prop, OB_MAX_STATES);
- RNA_def_property_ui_text(prop, "Used State", "States which are being used by controllers");
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_boolean_funcs(prop, "rna_GameObjectSettings_used_state_get", NULL);
-
- prop = RNA_def_property(srna, "states_initial", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "init_state", 1);
- RNA_def_property_array(prop, OB_MAX_STATES);
- RNA_def_property_ui_text(prop, "Initial State", "Initial state when the game starts");
-
- prop = RNA_def_property(srna, "show_debug_state", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", OB_DEBUGSTATE);
- RNA_def_property_ui_text(prop, "Debug State", "Print state debug info in the game engine");
- RNA_def_property_ui_icon(prop, ICON_INFO, 0);
-
- prop = RNA_def_property(srna, "use_all_states", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", OB_ALLSTATE);
- RNA_def_property_ui_text(prop, "All", "Set all state bits");
-
- prop = RNA_def_property(srna, "show_state_panel", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", OB_SHOWSTATE);
- RNA_def_property_ui_text(prop, "States", "Show state panel");
- RNA_def_property_ui_icon(prop, ICON_DISCLOSURE_TRI_RIGHT, 1);
-}
-
static void rna_def_object_constraints(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
@@ -2115,55 +1777,55 @@ static void rna_def_object_vertex_groups(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_function_ui_description(func, "Delete all vertex groups from object");
}
-
-static void rna_def_object_lodlevel(BlenderRNA *brna)
+/* object.face_maps */
+static void rna_def_object_face_maps(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
+
PropertyRNA *prop;
- srna = RNA_def_struct(brna, "LodLevel", NULL);
- RNA_def_struct_sdna(srna, "LodLevel");
-
- prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "distance");
- RNA_def_property_range(prop, 0.0, FLT_MAX);
- RNA_def_property_ui_text(prop, "Distance", "Distance to begin using this level of detail");
- RNA_def_property_update(prop, NC_OBJECT | ND_LOD, "rna_Object_lod_distance_update");
+ FunctionRNA *func;
+ PropertyRNA *parm;
- prop = RNA_def_property(srna, "object_hysteresis_percentage", PROP_INT, PROP_PERCENTAGE);
- RNA_def_property_int_sdna(prop, NULL, "obhysteresis");
- RNA_def_property_range(prop, 0, 100);
- RNA_def_property_ui_range(prop, 0, 100, 10, 1);
- RNA_def_property_ui_text(prop, "Hysteresis %",
- "Minimum distance change required to transition to the previous level of detail");
- RNA_def_property_update(prop, NC_OBJECT | ND_LOD, NULL);
+ RNA_def_property_srna(cprop, "FaceMaps");
+ srna = RNA_def_struct(brna, "FaceMaps", NULL);
+ RNA_def_struct_sdna(srna, "Object");
+ RNA_def_struct_ui_text(srna, "Face Maps", "Collection of face maps");
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "source");
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Object", "Object to use for this level of detail");
- RNA_def_property_update(prop, NC_OBJECT | ND_LOD, NULL);
+ prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "FaceMap");
+ RNA_def_property_pointer_funcs(prop, "rna_Object_active_face_map_get",
+ "rna_Object_active_face_map_set", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Active Face Map", "Face maps of the object");
+ RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Object_internal_update_data");
- prop = RNA_def_property(srna, "use_mesh", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flags", OB_LOD_USE_MESH);
- RNA_def_property_ui_text(prop, "Use Mesh", "Use the mesh from this object at this level of detail");
- RNA_def_property_ui_icon(prop, ICON_MESH_DATA, 0);
- RNA_def_property_update(prop, NC_OBJECT | ND_LOD, NULL);
+ prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_int_sdna(prop, NULL, "actfmap");
+ RNA_def_property_int_funcs(prop, "rna_Object_active_face_map_index_get",
+ "rna_Object_active_face_map_index_set",
+ "rna_Object_active_face_map_index_range");
+ RNA_def_property_ui_text(prop, "Active Face Map Index", "Active index in face map array");
+ RNA_def_property_update(prop, NC_GEOM | ND_DATA, "rna_Object_internal_update_data");
+
+ /* face maps */ /* add_face_map */
+ func = RNA_def_function(srna, "new", "rna_Object_fmap_new");
+ RNA_def_function_ui_description(func, "Add face map to object");
+ RNA_def_string(func, "name", "Map", 0, "", "face map name"); /* optional */
+ parm = RNA_def_pointer(func, "fmap", "FaceMap", "", "New face map");
+ RNA_def_function_return(func, parm);
- prop = RNA_def_property(srna, "use_material", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flags", OB_LOD_USE_MAT);
- RNA_def_property_ui_text(prop, "Use Material", "Use the material from this object at this level of detail");
- RNA_def_property_ui_icon(prop, ICON_MATERIAL, 0);
- RNA_def_property_update(prop, NC_OBJECT | ND_LOD, NULL);
+ func = RNA_def_function(srna, "remove", "rna_Object_fmap_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(func, "Delete vertex group from object");
+ parm = RNA_def_pointer(func, "group", "FaceMap", "", "Face map to remove");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_property_clear_flag(parm, PROP_THICK_WRAP);
- prop = RNA_def_property(srna, "use_object_hysteresis", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flags", OB_LOD_USE_HYST);
- RNA_def_property_ui_text(prop, "Hysteresis Override", "Override LoD Hysteresis scene setting for this LoD level");
- RNA_def_property_update(prop, NC_OBJECT | ND_LOD, NULL);
+ func = RNA_def_function(srna, "clear", "rna_Object_fmap_clear");
+ RNA_def_function_ui_description(func, "Delete all vertex groups from object");
}
-
static void rna_def_object(BlenderRNA *brna)
{
StructRNA *srna;
@@ -2239,26 +1901,12 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Mode", "Object interaction mode");
- prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "lay", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Layers", "Layers the object is on");
- RNA_def_property_boolean_funcs(prop, NULL, "rna_Object_layer_set");
- RNA_def_property_flag(prop, PROP_LIB_EXCEPTION);
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_layer_update");
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-
prop = RNA_def_property(srna, "layers_local_view", PROP_BOOLEAN, PROP_LAYER_MEMBER);
RNA_def_property_boolean_sdna(prop, NULL, "lay", 0x01000000);
RNA_def_property_array(prop, 8);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Local View Layers", "3D local view layers the object is on");
- prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SELECT);
- RNA_def_property_ui_text(prop, "Select", "Object selection state");
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_select_update");
-
/* for data access */
prop = RNA_def_property(srna, "bound_box", PROP_FLOAT, PROP_NONE);
RNA_def_property_multi_array(prop, 2, boundbox_dimsize);
@@ -2271,7 +1919,7 @@ static void rna_def_object(BlenderRNA *brna)
/* parent */
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_funcs(prop, NULL, "rna_Object_parent_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK | PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Parent", "Parent Object");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
@@ -2349,6 +1997,7 @@ static void rna_def_object(BlenderRNA *brna)
prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
RNA_def_property_float_sdna(prop, NULL, "loc");
RNA_def_property_editable_array_func(prop, "rna_Object_location_editable");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Location", "Location of the object");
RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
@@ -2356,6 +2005,7 @@ static void rna_def_object(BlenderRNA *brna)
prop = RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
RNA_def_property_float_sdna(prop, NULL, "quat");
RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_float_array_default(prop, default_quat);
RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions");
RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
@@ -2369,12 +2019,14 @@ static void rna_def_object(BlenderRNA *brna)
"rna_Object_rotation_axis_angle_set", NULL);
RNA_def_property_editable_array_func(prop, "rna_Object_rotation_4d_editable");
RNA_def_property_float_array_default(prop, default_axisAngle);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Axis-Angle Rotation", "Angle of Rotation for Axis-Angle rotation representation");
RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
prop = RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
RNA_def_property_float_sdna(prop, NULL, "rot");
RNA_def_property_editable_array_func(prop, "rna_Object_rotation_euler_editable");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
@@ -2387,7 +2039,7 @@ static void rna_def_object(BlenderRNA *brna)
prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "size");
- RNA_def_property_flag(prop, PROP_PROPORTIONAL);
+ RNA_def_property_flag(prop, PROP_PROPORTIONAL | PROP_OVERRIDABLE_STATIC);
RNA_def_property_editable_array_func(prop, "rna_Object_scale_editable");
RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, 3);
RNA_def_property_float_array_default(prop, default_scale);
@@ -2514,22 +2166,19 @@ static void rna_def_object(BlenderRNA *brna)
prop = RNA_def_property(srna, "modifiers", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Modifier");
RNA_def_property_ui_text(prop, "Modifiers", "Modifiers affecting the geometric data of the object");
+ RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Object_modifiers_override_apply");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC | PROP_OVERRIDABLE_STATIC_INSERTION);
rna_def_object_modifiers(brna, prop);
/* constraints */
prop = RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Constraint");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC | PROP_OVERRIDABLE_STATIC_INSERTION);
RNA_def_property_ui_text(prop, "Constraints", "Constraints affecting the transformation of the object");
+ RNA_def_property_override_funcs(prop, NULL, NULL, "rna_Object_constraints_override_apply");
/* RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, NULL, "constraints__add", "constraints__remove"); */
rna_def_object_constraints(brna, prop);
- /* game engine */
- prop = RNA_def_property(srna, "game", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "GameObjectSettings");
- RNA_def_property_pointer_funcs(prop, "rna_Object_game_settings_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Game Settings", "Game engine related settings for the object");
-
/* vertex groups */
prop = RNA_def_property(srna, "vertex_groups", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "defbase", NULL);
@@ -2537,6 +2186,14 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Vertex Groups", "Vertex groups of the object");
rna_def_object_vertex_groups(brna, prop);
+
+ /* face maps */
+ prop = RNA_def_property(srna, "face_maps", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "fmaps", NULL);
+ RNA_def_property_struct_type(prop, "FaceMap");
+ RNA_def_property_ui_text(prop, "Face Maps", "Maps of faces of the object");
+ rna_def_object_face_maps(brna, prop);
+
/* empty */
prop = RNA_def_property(srna, "empty_draw_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "empty_drawtype");
@@ -2613,24 +2270,41 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Rigid Body Constraint", "Constraint constraining rigid bodies");
/* restrict */
- prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_VIEW);
- RNA_def_property_ui_text(prop, "Restrict View", "Restrict visibility in the viewport");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_VIEW_OFF, 1);
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_hide_update");
-
- prop = RNA_def_property(srna, "hide_select", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_SELECT);
- RNA_def_property_ui_text(prop, "Restrict Select", "Restrict selection in the viewport");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_SELECT_OFF, 1);
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, NULL);
-
prop = RNA_def_property(srna, "hide_render", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "restrictflag", OB_RESTRICT_RENDER);
RNA_def_property_ui_text(prop, "Restrict Render", "Restrict renderability");
RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_hide_update");
+ prop = RNA_def_property(srna, "show_duplicator_for_render", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "duplicator_visibility_flag", OB_DUPLI_FLAG_RENDER);
+ RNA_def_property_ui_text(prop, "Render Duplicator", "Make duplicator visible when rendering");
+
+ prop = RNA_def_property(srna, "show_duplicator_for_viewport", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "duplicator_visibility_flag", OB_DUPLI_FLAG_VIEWPORT);
+ RNA_def_property_ui_text(prop, "Show Duplicator", "Make duplicator visible in the viewport");
+
+ prop = RNA_def_property(srna, "is_visible", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_Object_is_visible_get", NULL);
+ RNA_def_property_ui_text(prop, "Visible", "Visible to camera rays, set only on objects evaluated by depsgraph");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "collection_properties", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "base_collection_properties->data.group", NULL);
+ RNA_def_property_collection_funcs(prop,
+ "rna_Object_collection_properties_begin",
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ NULL);
+ RNA_def_property_struct_type(prop, "LayerCollectionSettings");
+ RNA_def_property_flag(prop, PROP_NO_COMPARISON); /* XXX see T53800. */
+ RNA_def_property_ui_text(prop, "Collection Settings",
+ "Engine specific render settings to be overridden by collections");
+
/* anim */
rna_def_animdata_common(srna);
@@ -2651,20 +2325,12 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_range(prop, MINAFRAMEF, MAXFRAMEF);
RNA_def_property_ui_text(prop, "Slow Parent Offset", "Delay in the parent relationship");
RNA_def_property_update(prop, NC_OBJECT | ND_TRANSFORM, "rna_Object_internal_update");
-
- /* depsgraph hack */
- prop = RNA_def_property(srna, "use_extra_recalc_object", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "depsflag", OB_DEPS_EXTRA_OB_RECALC);
- RNA_def_property_ui_text(prop, "Extra Object Update", "Refresh this object again on frame changes, dependency graph hack");
-
- prop = RNA_def_property(srna, "use_extra_recalc_data", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "depsflag", OB_DEPS_EXTRA_DATA_RECALC);
- RNA_def_property_ui_text(prop, "Extra Data Update", "Refresh this object's data again on frame changes, dependency graph hack");
-
+
/* duplicates */
prop = RNA_def_property(srna, "dupli_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_bitflag_sdna(prop, NULL, "transflag");
RNA_def_property_enum_items(prop, dupli_items);
+ RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_Object_dupli_type_itemf");
RNA_def_property_ui_text(prop, "Dupli Type", "If not None, object duplication method to use");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_dependency_update");
@@ -2723,11 +2389,6 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Dupli Frames Off", "Recurring frames to exclude from the Dupliframes");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Object_internal_update");
- prop = RNA_def_property(srna, "dupli_list", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "duplilist", NULL);
- RNA_def_property_struct_type(prop, "DupliObject");
- RNA_def_property_ui_text(prop, "Dupli list", "Object duplis");
-
prop = RNA_def_property(srna, "is_duplicator", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "transflag", OB_DUPLI);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -2805,6 +2466,7 @@ static void rna_def_object(BlenderRNA *brna)
prop = RNA_def_property(srna, "pose", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "pose");
RNA_def_property_struct_type(prop, "Pose");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Pose", "Current pose for armatures");
/* shape keys */
@@ -2827,6 +2489,7 @@ static void rna_def_object(BlenderRNA *brna)
prop = RNA_def_property(srna, "active_shape_key_index", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "shapenr");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE); /* XXX this is really unpredictable... */
RNA_def_property_int_funcs(prop, "rna_Object_active_shape_key_index_get", "rna_Object_active_shape_key_index_set",
"rna_Object_active_shape_key_index_range");
@@ -2839,12 +2502,16 @@ static void rna_def_object(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Dynamic Topology Sculpting", NULL);
- /* Levels of Detail */
- prop = RNA_def_property(srna, "lod_levels", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "lodlevels", NULL);
- RNA_def_property_struct_type(prop, "LodLevel");
- RNA_def_property_ui_text(prop, "Level of Detail Levels", "A collection of detail levels to automatically switch between");
- RNA_def_property_update(prop, NC_OBJECT | ND_LOD, NULL);
+ /* Base Settings */
+ prop = RNA_def_property(srna, "is_from_duplicator", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "base_flag", BASE_FROMDUPLI);
+ RNA_def_property_ui_text(prop, "Base from Duplicator", "Object comes from a duplicator");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "is_from_set", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "base_flag", BASE_FROM_SET);
+ RNA_def_property_ui_text(prop, "Base from Set", "Object comes from a background set");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_api_object(srna);
}
@@ -2907,54 +2574,16 @@ static void rna_def_dupli_object(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Dupli random id", "Random id for this dupli object");
}
-static void rna_def_object_base(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "ObjectBase", NULL);
- RNA_def_struct_sdna(srna, "Base");
- RNA_def_struct_ui_text(srna, "Object Base", "An object instance in a scene");
- RNA_def_struct_ui_icon(srna, ICON_OBJECT_DATA);
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "object");
- RNA_def_property_ui_text(prop, "Object", "Object this base links to");
-
- /* same as object layer */
- prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "lay", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Layers", "Layers the object base is on");
- RNA_def_property_boolean_funcs(prop, NULL, "rna_Base_layer_set");
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Base_layer_update");
-
- prop = RNA_def_property(srna, "layers_local_view", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "lay", 0x01000000);
- RNA_def_property_array(prop, 8);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Local View Layers", "3D local view layers the object base is on");
-
- prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", BA_SELECT);
- RNA_def_property_ui_text(prop, "Select", "Object base selection state");
- RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Base_select_update");
-
- RNA_api_object_base(srna);
-}
-
void RNA_def_object(BlenderRNA *brna)
{
rna_def_object(brna);
RNA_define_animate_sdna(false);
- rna_def_object_game_settings(brna);
- rna_def_object_base(brna);
rna_def_vertex_group(brna);
+ rna_def_face_map(brna);
rna_def_material_slot(brna);
rna_def_dupli_object(brna);
RNA_define_animate_sdna(true);
- rna_def_object_lodlevel(brna);
}
#endif
diff --git a/source/blender/makesrna/intern/rna_object_api.c b/source/blender/makesrna/intern/rna_object_api.c
index 9b8a98a8831..04507d1ed7e 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -40,10 +40,13 @@
#include "RNA_define.h"
#include "DNA_constraint_types.h"
+#include "DNA_layer_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
+
+#include "DEG_depsgraph.h"
#include "rna_internal.h" /* own include */
@@ -88,7 +91,61 @@ static const EnumPropertyItem space_items[] = {
#include "MEM_guardedalloc.h"
-#include "DEG_depsgraph.h"
+static void rna_Object_select_set(Object *ob, bContext *C, ReportList *reports, int action)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (!base) {
+ BKE_reportf(reports, RPT_ERROR, "Object '%s' not in View Layer '%s'!", ob->id.name + 2, view_layer->name);
+ return;
+ }
+
+ if (action == 2) { /* TOGGLE */
+ if ((base->flag & BASE_SELECTED) != 0) {
+ action = 1; /* DESELECT */
+ }
+ else {
+ action = 0; /* SELECT */
+ }
+ }
+
+ switch (action) {
+ case 1: /* DESELECT */
+ base->flag &= ~BASE_SELECTED;
+ break;
+ case 0: /* SELECT */
+ default:
+ BKE_view_layer_base_select(view_layer, base);
+ break;
+ }
+}
+
+static int rna_Object_select_get(Object *ob, bContext *C, ReportList *reports)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (!base) {
+ BKE_reportf(reports, RPT_ERROR, "Object '%s' not in Render Layer '%s'!", ob->id.name + 2, view_layer->name);
+ return -1;
+ }
+
+ return ((base->flag & BASE_SELECTED) != 0) ? 1 : 0;
+}
+
+static int rna_Object_visible_get(Object *ob, bContext *C, ReportList *reports)
+{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Base *base = BKE_view_layer_base_find(view_layer, ob);
+
+ if (!base) {
+ BKE_reportf(reports, RPT_ERROR, "Object '%s' not in Render Layer '%s'!", ob->id.name + 2, view_layer->name);
+ return -1;
+ }
+
+ return ((base->flag & BASE_VISIBLED) != 0) ? 1 : 0;
+}
/* Convert a given matrix from a space to another (using the object and/or a bone as reference). */
static void rna_Object_mat_convert_space(Object *ob, ReportList *reports, bPoseChannel *pchan,
@@ -140,89 +197,12 @@ static void rna_Object_camera_fit_coords(
/* copied from Mesh_getFromObject and adapted to RNA interface */
/* settings: 0 - preview, 1 - render */
static Mesh *rna_Object_to_mesh(
- Object *ob, ReportList *reports, Scene *sce,
- int apply_modifiers, int settings, int calc_tessface, int calc_undeformed)
-{
- return rna_Main_meshes_new_from_object(G.main, reports, sce, ob, apply_modifiers, settings, calc_tessface, calc_undeformed);
-}
-
-/* mostly a copy from convertblender.c */
-static void dupli_render_particle_set(Scene *scene, Object *ob, int level, int enable)
+ Object *ob, bContext *C, ReportList *reports, Depsgraph *depsgraph,
+ int apply_modifiers, int calc_tessface, int calc_undeformed)
{
- /* ugly function, but we need to set particle systems to their render
- * settings before calling object_duplilist, to get render level duplis */
- Group *group;
- GroupObject *go;
- ParticleSystem *psys;
- DerivedMesh *dm;
- float mat[4][4];
-
- unit_m4(mat);
-
- if (level >= MAX_DUPLI_RECUR)
- return;
-
- if (ob->transflag & OB_DUPLIPARTS) {
- for (psys = ob->particlesystem.first; psys; psys = psys->next) {
- if (ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
- if (enable)
- psys_render_set(ob, psys, mat, mat, 1, 1, 0.f);
- else
- psys_render_restore(ob, psys);
- }
- }
-
- if (enable) {
- /* this is to make sure we get render level duplis in groups:
- * the derivedmesh must be created before init_render_mesh,
- * since object_duplilist does dupliparticles before that */
- dm = mesh_create_derived_render(scene, ob, CD_MASK_BAREMESH | CD_MASK_MLOOPUV | CD_MASK_MLOOPCOL);
- dm->release(dm);
-
- for (psys = ob->particlesystem.first; psys; psys = psys->next)
- psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
- }
- }
+ Main *bmain = CTX_data_main(C);
- if (ob->dup_group == NULL) return;
- group = ob->dup_group;
-
- for (go = group->gobject.first; go; go = go->next)
- dupli_render_particle_set(scene, go->ob, level + 1, enable);
-}
-/* When no longer needed, duplilist should be freed with Object.free_duplilist */
-static void rna_Object_create_duplilist(Object *ob, ReportList *reports, Scene *sce, int settings)
-{
- bool for_render = (settings == DAG_EVAL_RENDER);
- EvaluationContext eval_ctx;
- DEG_evaluation_context_init(&eval_ctx, settings);
-
- if (!(ob->transflag & OB_DUPLI)) {
- BKE_report(reports, RPT_ERROR, "Object does not have duplis");
- return;
- }
-
- /* free duplilist if a user forgets to */
- if (ob->duplilist) {
- BKE_report(reports, RPT_WARNING, "Object.dupli_list has not been freed");
-
- free_object_duplilist(ob->duplilist);
- ob->duplilist = NULL;
- }
- if (for_render)
- dupli_render_particle_set(sce, ob, 0, 1);
- ob->duplilist = object_duplilist(&eval_ctx, sce, ob);
- if (for_render)
- dupli_render_particle_set(sce, ob, 0, 0);
- /* ob->duplilist should now be freed with Object.free_duplilist */
-}
-
-static void rna_Object_free_duplilist(Object *ob)
-{
- if (ob->duplilist) {
- free_object_duplilist(ob->duplilist);
- ob->duplilist = NULL;
- }
+ return rna_Main_meshes_new_from_object(bmain, reports, depsgraph, ob, apply_modifiers, calc_tessface, calc_undeformed);
}
static PointerRNA rna_Object_shape_key_add(Object *ob, bContext *C, ReportList *reports,
@@ -261,17 +241,12 @@ static void rna_Object_shape_key_remove(
return;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
RNA_POINTER_INVALIDATE(kb_ptr);
}
-static int rna_Object_is_visible(Object *ob, Scene *sce)
-{
- return !(ob->restrictflag & OB_RESTRICT_VIEW) && (ob->lay & sce->lay);
-}
-
#if 0
static void rna_Mesh_assign_verts_to_group(Object *ob, bDeformGroup *group, int *indices, int totindex,
float weight, int assignmode)
@@ -419,13 +394,6 @@ finally:
free_bvhtree_from_mesh(&treeData);
}
-/* ObjectBase */
-
-static void rna_ObjectBase_layers_from_view(Base *base, View3D *v3d)
-{
- base->lay = base->object->lay = v3d->lay;
-}
-
static int rna_Object_is_modified(Object *ob, Scene *scene, int settings)
{
return BKE_object_is_modified(scene, ob) & settings;
@@ -476,6 +444,7 @@ void rna_Object_dm_info(struct Object *ob, int type, char *result)
static int rna_Object_update_from_editmode(Object *ob)
{
+ /* fail gracefully if we aren't in edit-mode. */
return ED_object_editmode_load(ob);
}
#else /* RNA_RUNTIME */
@@ -491,13 +460,6 @@ void RNA_api_object(StructRNA *srna)
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem dupli_eval_mode_items[] = {
- {DAG_EVAL_VIEWPORT, "VIEWPORT", 0, "Viewport", "Generate duplis using viewport settings"},
- {DAG_EVAL_PREVIEW, "PREVIEW", 0, "Preview", "Generate duplis using preview settings"},
- {DAG_EVAL_RENDER, "RENDER", 0, "Render", "Generate duplis using render settings"},
- {0, NULL, 0, NULL, NULL}
- };
-
#ifndef NDEBUG
static const EnumPropertyItem mesh_dm_info_items[] = {
{0, "SOURCE", 0, "Source", "Source mesh"},
@@ -507,6 +469,32 @@ void RNA_api_object(StructRNA *srna)
};
#endif
+ static EnumPropertyItem object_select_items[] = {
+ {0, "SELECT", 0, "Select", "Select object from the active render layer"},
+ {1, "DESELECT", 0, "Deselect", "Deselect object from the active render layer"},
+ {2, "TOGGLE", 0, "Toggle", "Toggle object selection from the active render layer"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+ /* Special wrapper to access the base selection value */
+ func = RNA_def_function(srna, "select_set", "rna_Object_select_set");
+ RNA_def_function_ui_description(func, "Select the object (for the active render layer)");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ parm = RNA_def_enum(func, "action", object_select_items, 0, "Action", "Select mode");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "select_get", "rna_Object_select_get");
+ RNA_def_function_ui_description(func, "Get the object selection for the active render layer");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ parm = RNA_def_boolean(func, "result", 0, "", "Object selected");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "visible_get", "rna_Object_visible_get");
+ RNA_def_function_ui_description(func, "Get the object visibility for the active render layer");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
+ parm = RNA_def_boolean(func, "result", 0, "", "Object visible");
+ RNA_def_function_return(func, parm);
+
/* Matrix space conversion */
func = RNA_def_function(srna, "convert_space", "rna_Object_mat_convert_space");
RNA_def_function_ui_description(func, "Convert (transform) the given matrix from one space to another");
@@ -558,32 +546,17 @@ void RNA_api_object(StructRNA *srna)
/* mesh */
func = RNA_def_function(srna, "to_mesh", "rna_Object_to_mesh");
RNA_def_function_ui_description(func, "Create a Mesh data-block with modifiers applied");
- RNA_def_function_flag(func, FUNC_USE_REPORTS);
- parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate modifiers");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS | FUNC_USE_CONTEXT);
+ parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "Dependency Graph", "Evaluated dependency graph within wich to evaluate modifiers");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_boolean(func, "apply_modifiers", 0, "", "Apply modifiers");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- parm = RNA_def_enum(func, "settings", mesh_type_items, 0, "", "Modifier settings to apply");
- RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
RNA_def_boolean(func, "calc_tessface", true, "Calculate Tessellation", "Calculate tessellation faces");
RNA_def_boolean(func, "calc_undeformed", false, "Calculate Undeformed", "Calculate undeformed vertex coordinates");
parm = RNA_def_pointer(func, "mesh", "Mesh", "",
"Mesh created from object, remove it if it is only used for export");
RNA_def_function_return(func, parm);
- /* duplis */
- func = RNA_def_function(srna, "dupli_list_create", "rna_Object_create_duplilist");
- RNA_def_function_ui_description(func, "Create a list of dupli objects for this object, needs to "
- "be freed manually with free_dupli_list to restore the "
- "objects real matrix and layers");
- parm = RNA_def_pointer(func, "scene", "Scene", "", "Scene within which to evaluate duplis");
- RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
- RNA_def_enum(func, "settings", dupli_eval_mode_items, 0, "", "Generate texture coordinates for rendering");
- RNA_def_function_flag(func, FUNC_USE_REPORTS);
-
- func = RNA_def_function(srna, "dupli_list_clear", "rna_Object_free_duplilist");
- RNA_def_function_ui_description(func, "Free the list of dupli objects");
-
/* Armature */
func = RNA_def_function(srna, "find_armature", "modifiers_isDeformedByArmature");
RNA_def_function_ui_description(func, "Find armature influencing this object as a parent or via a modifier");
@@ -661,12 +634,6 @@ void RNA_api_object(StructRNA *srna)
RNA_def_function_output(func, parm);
/* View */
- func = RNA_def_function(srna, "is_visible", "rna_Object_is_visible");
- RNA_def_function_ui_description(func, "Determine if object is visible in a given scene");
- parm = RNA_def_pointer(func, "scene", "Scene", "", "");
- RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
- parm = RNA_def_boolean(func, "result", 0, "", "Object visibility");
- RNA_def_function_return(func, parm);
/* utility function for checking if the object is modified */
func = RNA_def_function(srna, "is_modified", "rna_Object_is_modified");
@@ -709,17 +676,4 @@ void RNA_api_object(StructRNA *srna)
RNA_def_function_ui_description(func, "Release memory used by caches associated with this object. Intended to be used by render engines only");
}
-
-void RNA_api_object_base(StructRNA *srna)
-{
- FunctionRNA *func;
- PropertyRNA *parm;
-
- func = RNA_def_function(srna, "layers_from_view", "rna_ObjectBase_layers_from_view");
- RNA_def_function_ui_description(func,
- "Sets the object layers from a 3D View (use when adding an object in local view)");
- parm = RNA_def_pointer(func, "view", "SpaceView3D", "", "");
- RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
-}
-
#endif /* RNA_RUNTIME */
diff --git a/source/blender/makesrna/intern/rna_object_force.c b/source/blender/makesrna/intern/rna_object_force.c
index c9c3372000f..3a61accfad3 100644
--- a/source/blender/makesrna/intern/rna_object_force.c
+++ b/source/blender/makesrna/intern/rna_object_force.c
@@ -94,10 +94,13 @@ static const EnumPropertyItem empty_vortex_shape_items[] = {
#include "DNA_modifier_types.h"
#include "DNA_texture_types.h"
+#include "BKE_collection.h"
#include "BKE_context.h"
#include "BKE_modifier.h"
#include "BKE_pointcache.h"
-#include "BKE_depsgraph.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "ED_object.h"
@@ -105,65 +108,45 @@ static void rna_Cache_change(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerR
{
Object *ob = (Object *)ptr->id.data;
PointCache *cache = (PointCache *)ptr->data;
- PTCacheID *pid = NULL;
- ListBase pidlist;
if (!ob)
return;
cache->flag |= PTCACHE_OUTDATED;
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
-
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ PTCacheID pid = BKE_ptcache_id_find(ob, NULL, cache);
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache)
- break;
- }
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
- if (pid) {
+ if (pid.cache) {
/* Just make sure this wasn't changed. */
- if (pid->type == PTCACHE_TYPE_SMOKE_DOMAIN)
+ if (pid.type == PTCACHE_TYPE_SMOKE_DOMAIN)
cache->step = 1;
- BKE_ptcache_update_info(pid);
+ BKE_ptcache_update_info(&pid);
}
-
- BLI_freelistN(&pidlist);
}
static void rna_Cache_toggle_disk_cache(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointCache *cache = (PointCache *)ptr->data;
- PTCacheID *pid = NULL;
- ListBase pidlist;
if (!ob)
return;
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
-
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache)
- break;
- }
+ PTCacheID pid = BKE_ptcache_id_find(ob, NULL, cache);
/* smoke can only use disk cache */
- if (pid && pid->type != PTCACHE_TYPE_SMOKE_DOMAIN)
- BKE_ptcache_toggle_disk_cache(pid);
+ if (pid.cache && pid.type != PTCACHE_TYPE_SMOKE_DOMAIN)
+ BKE_ptcache_toggle_disk_cache(&pid);
else
cache->flag ^= PTCACHE_DISK_CACHE;
-
- BLI_freelistN(&pidlist);
}
static void rna_Cache_idname_change(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Object *ob = (Object *)ptr->id.data;
PointCache *cache = (PointCache *)ptr->data;
- PTCacheID *pid = NULL, *pid2 = NULL;
- ListBase pidlist;
bool use_new_name = true;
if (!ob)
@@ -171,23 +154,22 @@ static void rna_Cache_idname_change(Main *UNUSED(bmain), Scene *UNUSED(scene), P
/* TODO: check for proper characters */
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
-
if (cache->flag & PTCACHE_EXTERNAL) {
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache)
- break;
- }
-
- if (!pid)
- return;
+ PTCacheID pid = BKE_ptcache_id_find(ob, NULL, cache);
- BKE_ptcache_load_external(pid);
+ if (pid.cache) {
+ BKE_ptcache_load_external(&pid);
+ }
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_POINTCACHE, ob);
}
else {
+ PTCacheID *pid = NULL, *pid2 = NULL;
+ ListBase pidlist;
+
+ BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
+
for (pid = pidlist.first; pid; pid = pid->next) {
if (pid->cache == cache)
pid2 = pid;
@@ -213,9 +195,9 @@ static void rna_Cache_idname_change(Main *UNUSED(bmain), Scene *UNUSED(scene), P
BLI_strncpy(cache->prev_name, cache->name, sizeof(cache->prev_name));
}
- }
- BLI_freelistN(&pidlist);
+ BLI_freelistN(&pidlist);
+ }
}
static void rna_Cache_list_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
@@ -236,43 +218,27 @@ static void rna_Cache_active_point_cache_index_range(PointerRNA *ptr, int *min,
{
Object *ob = ptr->id.data;
PointCache *cache = ptr->data;
- PTCacheID *pid;
- ListBase pidlist;
-
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
+ PTCacheID pid = BKE_ptcache_id_find(ob, NULL, cache);
*min = 0;
*max = 0;
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache) {
- *max = max_ii(0, BLI_listbase_count(pid->ptcaches) - 1);
- break;
- }
+ if (pid.cache) {
+ *max = max_ii(0, BLI_listbase_count(pid.ptcaches) - 1);
}
-
- BLI_freelistN(&pidlist);
}
static int rna_Cache_active_point_cache_index_get(PointerRNA *ptr)
{
Object *ob = ptr->id.data;
PointCache *cache = ptr->data;
- PTCacheID *pid;
- ListBase pidlist;
+ PTCacheID pid = BKE_ptcache_id_find(ob, NULL, cache);
int num = 0;
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
-
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache) {
- num = BLI_findindex(pid->ptcaches, cache);
- break;
- }
+ if (pid.cache) {
+ num = BLI_findindex(pid.ptcaches, cache);
}
- BLI_freelistN(&pidlist);
-
return num;
}
@@ -280,19 +246,11 @@ static void rna_Cache_active_point_cache_index_set(struct PointerRNA *ptr, int v
{
Object *ob = ptr->id.data;
PointCache *cache = ptr->data;
- PTCacheID *pid;
- ListBase pidlist;
-
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
+ PTCacheID pid = BKE_ptcache_id_find(ob, NULL, cache);
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache) {
- *(pid->cache_ptr) = BLI_findlink(pid->ptcaches, value);
- break;
- }
+ if (pid.cache) {
+ *(pid.cache_ptr) = BLI_findlink(pid.ptcaches, value);
}
-
- BLI_freelistN(&pidlist);
}
static void rna_PointCache_frame_step_range(PointerRNA *ptr, int *min, int *max,
@@ -300,22 +258,14 @@ static void rna_PointCache_frame_step_range(PointerRNA *ptr, int *min, int *max,
{
Object *ob = ptr->id.data;
PointCache *cache = ptr->data;
- PTCacheID *pid;
- ListBase pidlist;
+ PTCacheID pid = BKE_ptcache_id_find(ob, NULL, cache);
*min = 1;
*max = 20;
- BKE_ptcache_ids_from_object(&pidlist, ob, NULL, 0);
-
- for (pid = pidlist.first; pid; pid = pid->next) {
- if (pid->cache == cache) {
- *max = pid->max_step;
- break;
- }
+ if (pid.cache) {
+ *max = pid.max_step;
}
-
- BLI_freelistN(&pidlist);
}
static char *rna_CollisionSettings_path(PointerRNA *UNUSED(ptr))
@@ -499,7 +449,7 @@ static void rna_FieldSettings_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
part->pd2->tex = NULL;
}
- DAG_id_tag_update(&part->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME | PSYS_RECALC_RESET);
+ DEG_id_tag_update(&part->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME | PSYS_RECALC_RESET);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
@@ -511,7 +461,7 @@ static void rna_FieldSettings_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
ob->pd->tex = NULL;
}
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
}
}
@@ -547,7 +497,7 @@ static void rna_FieldSettings_type_set(PointerRNA *ptr, int value)
static void rna_FieldSettings_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
if (particle_id_check(ptr)) {
- DAG_id_tag_update((ID *)ptr->id.data, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME | PSYS_RECALC_RESET);
+ DEG_id_tag_update((ID *)ptr->id.data, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME | PSYS_RECALC_RESET);
}
else {
Object *ob = (Object *)ptr->id.data;
@@ -563,12 +513,12 @@ static void rna_FieldSettings_dependency_update(Main *bmain, Scene *scene, Point
rna_FieldSettings_shape_update(bmain, scene, ptr);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
if (ob->type == OB_CURVE && ob->pd->forcefield == PFIELD_GUIDE)
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
else
- DAG_id_tag_update(&ob->id, OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
}
@@ -605,23 +555,23 @@ static void rna_EffectorWeight_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
if (id && GS(id->name) == ID_SCE) {
Scene *scene = (Scene *)id;
- Base *base;
-
- for (base = scene->base.first; base; base = base->next) {
- BKE_ptcache_object_reset(scene, base->object, PTCACHE_RESET_DEPSGRAPH);
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
+ {
+ BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH);
}
+ FOREACH_SCENE_OBJECT_END;
}
else {
- DAG_id_tag_update(id, OB_RECALC_DATA | PSYS_RECALC_RESET);
+ DEG_id_tag_update(id, OB_RECALC_DATA | PSYS_RECALC_RESET);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
}
static void rna_EffectorWeight_dependency_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
- DAG_id_tag_update((ID *)ptr->id.data, OB_RECALC_DATA | PSYS_RECALC_RESET);
+ DEG_id_tag_update((ID *)ptr->id.data, OB_RECALC_DATA | PSYS_RECALC_RESET);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
@@ -718,7 +668,7 @@ static void rna_CollisionSettings_update(Main *UNUSED(bmain), Scene *UNUSED(scen
{
Object *ob = (Object *)ptr->id.data;
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
+ DEG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, ob);
}
@@ -726,13 +676,13 @@ static void rna_softbody_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Point
{
Object *ob = (Object *)ptr->id.data;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
}
static void rna_softbody_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
rna_softbody_update(bmain, scene, ptr);
}
@@ -1509,78 +1459,6 @@ static void rna_def_field(BlenderRNA *brna)
/* falloff_power, use_max_distance, maximum_distance */
}
-static void rna_def_game_softbody(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "GameSoftBodySettings", NULL);
- RNA_def_struct_sdna(srna, "BulletSoftBody");
- RNA_def_struct_ui_text(srna, "Game Soft Body Settings",
- "Soft body simulation settings for an object in the game engine");
-
- /* Floats */
-
- prop = RNA_def_property(srna, "linear_stiffness", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "linStiff");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Linear Stiffness", "Linear stiffness of the soft body links");
-
- prop = RNA_def_property(srna, "dynamic_friction", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "kDF");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Friction", "Dynamic Friction");
-
- prop = RNA_def_property(srna, "shape_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "kMT");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Threshold", "Shape matching threshold");
-
- prop = RNA_def_property(srna, "collision_margin", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "margin");
- RNA_def_property_range(prop, 0.01f, 1.0f);
- RNA_def_property_ui_text(prop, "Margin",
- "Collision margin for soft body. Small value makes the algorithm unstable");
-
- prop = RNA_def_property(srna, "weld_threshold", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "welding");
- RNA_def_property_range(prop, 0.0f, 0.01f);
- RNA_def_property_ui_text(prop, "Welding",
- "Welding threshold: distance between nearby vertices to be considered equal "
- "=> set to 0.0 to disable welding test and speed up scene loading "
- "(ok if the mesh has no duplicates)");
-
- /* Integers */
-
- prop = RNA_def_property(srna, "location_iterations", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "piterations");
- RNA_def_property_range(prop, 0, 10);
- RNA_def_property_ui_text(prop, "Position Iterations", "Position solver iterations");
-
- prop = RNA_def_property(srna, "cluster_iterations", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "numclusteriterations");
- RNA_def_property_range(prop, 1, 128);
- RNA_def_property_ui_text(prop, "Cluster Iterations", "Number of cluster iterations");
-
- /* Booleans */
-
- prop = RNA_def_property(srna, "use_shape_match", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", OB_BSB_SHAPE_MATCHING);
- RNA_def_property_ui_text(prop, "Shape Match", "Enable soft body shape matching goal");
-
- prop = RNA_def_property(srna, "use_bending_constraints", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", OB_BSB_BENDING_CONSTRAINTS);
- RNA_def_property_ui_text(prop, "Bending Const", "Enable bending constraints");
-
- prop = RNA_def_property(srna, "use_cluster_rigid_to_softbody", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "collisionflags", OB_BSB_COL_CL_RS);
- RNA_def_property_ui_text(prop, "Rigid to Soft Body", "Enable cluster collision between soft and rigid body");
-
- prop = RNA_def_property(srna, "use_cluster_soft_to_softbody", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "collisionflags", OB_BSB_COL_CL_SS);
- RNA_def_property_ui_text(prop, "Soft to Soft Body", "Enable cluster collision between soft and soft body");
-}
-
static void rna_def_softbody(BlenderRNA *brna)
{
StructRNA *srna;
@@ -1704,7 +1582,7 @@ static void rna_def_softbody(BlenderRNA *brna)
prop = RNA_def_property(srna, "spring_length", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "springpreload");
RNA_def_property_range(prop, 0.0f, 200.0f);
- RNA_def_property_ui_text(prop, "SL", "Alter spring length to shrink/blow up (unit %) 0 to disable");
+ RNA_def_property_ui_text(prop, "view_layer", "Alter spring length to shrink/blow up (unit %) 0 to disable");
RNA_def_property_update(prop, 0, "rna_softbody_update");
prop = RNA_def_property(srna, "aero", PROP_INT, PROP_NONE);
@@ -1901,7 +1779,6 @@ void RNA_def_object_force(BlenderRNA *brna)
rna_def_collision(brna);
rna_def_effector_weight(brna);
rna_def_field(brna);
- rna_def_game_softbody(brna);
rna_def_softbody(brna);
}
diff --git a/source/blender/makesrna/intern/rna_particle.c b/source/blender/makesrna/intern/rna_particle.c
index 2710a184367..f0d5a7e7c2e 100644
--- a/source/blender/makesrna/intern/rna_particle.c
+++ b/source/blender/makesrna/intern/rna_particle.c
@@ -135,7 +135,6 @@ static const EnumPropertyItem part_hair_ren_as_items[] = {
#include "BKE_cloth.h"
#include "BKE_colortools.h"
#include "BKE_deform.h"
-#include "BKE_depsgraph.h"
#include "BKE_DerivedMesh.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_effect.h"
@@ -145,6 +144,9 @@ static const EnumPropertyItem part_hair_ren_as_items[] = {
#include "BKE_pointcache.h"
#include "BKE_texture.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
/* use for object space hair get/set */
static void rna_ParticleHairKey_location_object_info(PointerRNA *ptr, ParticleSystemModifierData **psmd_pt,
ParticleData **pa_pt)
@@ -323,27 +325,18 @@ static void rna_ParticleSystem_co_hair(ParticleSystem *particlesystem, Object *o
ParticleData *pars = NULL;
ParticleCacheKey *cache = NULL;
int totchild = 0;
- int path_nbr = 0;
int totpart;
int max_k = 0;
- int step_nbr = 0;
if (particlesystem == NULL)
return;
part = particlesystem->part;
pars = particlesystem->particles;
+ totpart = particlesystem->totcached;
+ totchild = particlesystem->totchildcache;
- if (particlesystem->renderdata) {
- step_nbr = part->ren_step;
- totchild = particlesystem->totchild;
- }
- else {
- step_nbr = part->draw_step;
- totchild = (int)((float)particlesystem->totchild * (float)(part->disp) / 100.0f);
- }
-
- if (part == NULL || pars == NULL || !psys_check_enabled(object, particlesystem, particlesystem->renderdata != NULL))
+ if (part == NULL || pars == NULL)
return;
if (part->ren_as == PART_DRAW_OB || part->ren_as == PART_DRAW_GR || part->ren_as == PART_DRAW_NOT)
@@ -353,47 +346,28 @@ static void rna_ParticleSystem_co_hair(ParticleSystem *particlesystem, Object *o
if (part->type == PART_HAIR && !particlesystem->childcache)
totchild = 0;
- totpart = particlesystem->totpart;
-
- if (particle_no >= totpart + totchild)
- return;
-
- if (part->ren_as == PART_DRAW_PATH && particlesystem->pathcache)
- path_nbr = 1 << step_nbr;
- if (part->kink == PART_KINK_SPIRAL)
- path_nbr += part->kink_extra_steps;
-
if (particle_no < totpart) {
+ cache = particlesystem->pathcache[particle_no];
+ max_k = (int)cache->segments;
+ }
+ else if (particle_no < totpart + totchild) {
+ cache = particlesystem->childcache[particle_no - totpart];
- if (path_nbr) {
- cache = particlesystem->pathcache[particle_no];
+ if (cache->segments < 0)
+ max_k = 0;
+ else
max_k = (int)cache->segments;
- }
-
}
else {
-
- if (path_nbr) {
- cache = particlesystem->childcache[particle_no - totpart];
-
- if (cache->segments < 0)
- max_k = 0;
- else
- max_k = (int)cache->segments;
- }
+ return;
}
- /*strands key loop data stored in cache + step->co*/
- if (path_nbr) {
- if (step >= 0 && step <= path_nbr) {
- if (step <= max_k) {
- copy_v3_v3(n_co, (cache + step)->co);
- mul_m4_v3(particlesystem->imat, n_co);
- mul_m4_v3(object->obmat, n_co);
- }
- }
+ /* Strands key loop data stored in cache + step->co. */
+ if (step >= 0 && step <= max_k) {
+ copy_v3_v3(n_co, (cache + step)->co);
+ mul_m4_v3(particlesystem->imat, n_co);
+ mul_m4_v3(object->obmat, n_co);
}
-
}
@@ -459,20 +433,13 @@ static int rna_ParticleSystem_tessfaceidx_on_emitter(ParticleSystem *particlesys
}
part = particlesystem->part;
-
- if (particlesystem->renderdata) {
- totchild = particlesystem->totchild;
- }
- else {
- totchild = (int)((float)particlesystem->totchild * (float)(part->disp) / 100.0f);
- }
+ totpart = particlesystem->totcached;
+ totchild = particlesystem->totchildcache;
/* can happen for disconnected/global hair */
if (part->type == PART_HAIR && !particlesystem->childcache)
totchild = 0;
- totpart = particlesystem->totpart;
-
if (particle_no >= totpart + totchild)
return num;
@@ -612,30 +579,6 @@ static void rna_ParticleSystem_mcol_on_emitter(ParticleSystem *particlesystem, R
}
}
-static void rna_ParticleSystem_set_resolution(ParticleSystem *particlesystem, Scene *scene, Object *object, int resolution)
-{
- if (resolution == eModifierMode_Render) {
- ParticleSystemModifierData *psmd = psys_get_modifier(object, particlesystem);
- float mat[4][4];
-
- unit_m4(mat);
-
- psys_render_set(object, particlesystem, mat, mat, 1, 1, 0.f);
- psmd->flag &= ~eParticleSystemFlag_psys_updated;
- particle_system_update(scene, object, particlesystem, true);
- }
- else {
- ParticleSystemModifierData *psmd = psys_get_modifier(object, particlesystem);
-
- if (particlesystem->renderdata) {
- psys_render_restore(object, particlesystem);
- }
-
- psmd->flag &= ~eParticleSystemFlag_psys_updated;
- particle_system_update(scene, object, particlesystem, false);
- }
-}
-
static void particle_recalc(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr, short flag)
{
if (ptr->type == &RNA_ParticleSystem) {
@@ -643,10 +586,10 @@ static void particle_recalc(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRN
psys->recalc = flag;
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
}
else
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA | flag);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA | flag);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
}
@@ -657,7 +600,7 @@ static void rna_Particle_redo(Main *bmain, Scene *scene, PointerRNA *ptr)
static void rna_Particle_redo_dependency(Main *bmain, Scene *scene, PointerRNA *ptr)
{
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
rna_Particle_redo(bmain, scene, ptr);
}
@@ -668,14 +611,14 @@ static void rna_Particle_reset(Main *bmain, Scene *scene, PointerRNA *ptr)
static void rna_Particle_reset_dependency(Main *bmain, Scene *scene, PointerRNA *ptr)
{
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
rna_Particle_reset(bmain, scene, ptr);
}
static void rna_Particle_change_type(Main *bmain, Scene *scene, PointerRNA *ptr)
{
particle_recalc(bmain, scene, ptr, PSYS_RECALC_RESET | PSYS_RECALC_TYPE);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
static void rna_Particle_change_physics(Main *bmain, Scene *scene, PointerRNA *ptr)
@@ -692,7 +635,7 @@ static void rna_Particle_cloth_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
{
Object *ob = (Object *)ptr->id.data;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
}
@@ -737,8 +680,8 @@ static void rna_Particle_target_reset(Main *bmain, Scene *UNUSED(scene), Pointer
psys->recalc = PSYS_RECALC_RESET;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- DAG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
}
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
@@ -753,7 +696,7 @@ static void rna_Particle_target_redo(Main *UNUSED(bmain), Scene *UNUSED(scene),
psys->recalc = PSYS_RECALC_REDO;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
}
}
@@ -774,9 +717,10 @@ static void rna_Particle_hair_dynamics_update(Main *bmain, Scene *scene, Pointer
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
}
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
- DAG_relations_tag_update(bmain);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_relations_tag_update(bmain);
}
+
static PointerRNA rna_particle_settings_get(PointerRNA *ptr)
{
ParticleSystem *psys = (ParticleSystem *)ptr->data;
@@ -2309,11 +2253,6 @@ static void rna_def_particle_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Size", "Show particle size");
RNA_def_property_update(prop, 0, "rna_Particle_redo");
- prop = RNA_def_property(srna, "use_render_emitter", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_EMITTER);
- RNA_def_property_ui_text(prop, "Emitter", "Render emitter Object also");
- RNA_def_property_update(prop, 0, "rna_Particle_redo");
-
prop = RNA_def_property(srna, "show_health", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "draw", PART_DRAW_HEALTH);
RNA_def_property_ui_text(prop, "Health", "Draw boid health");
@@ -2401,10 +2340,10 @@ static void rna_def_particle_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Draw Color", "Draw additional particle data as a color");
RNA_def_property_update(prop, 0, "rna_Particle_redo");
- prop = RNA_def_property(srna, "draw_size", PROP_INT, PROP_PIXEL);
+ prop = RNA_def_property(srna, "draw_size", PROP_FLOAT, PROP_NONE);
RNA_def_property_range(prop, 0, 1000);
RNA_def_property_ui_range(prop, 0, 100, 1, -1);
- RNA_def_property_ui_text(prop, "Draw Size", "Size of particles on viewport in pixels (0=default)");
+ RNA_def_property_ui_text(prop, "Draw Size", "Size of particles on viewport in BU");
RNA_def_property_update(prop, 0, "rna_Particle_redo");
prop = RNA_def_property(srna, "child_type", PROP_ENUM, PROP_NONE);
@@ -2562,33 +2501,6 @@ static void rna_def_particle_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Billboard Velocity Tail", "Scale billboards by velocity");
RNA_def_property_update(prop, 0, "rna_Particle_redo");
- /* simplification */
- prop = RNA_def_property(srna, "use_simplify", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "simplify_flag", PART_SIMPLIFY_ENABLE);
- RNA_def_property_ui_text(prop, "Child Simplification",
- "Remove child strands as the object becomes smaller on the screen");
-
- prop = RNA_def_property(srna, "use_simplify_viewport", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "simplify_flag", PART_SIMPLIFY_VIEWPORT);
- RNA_def_property_ui_text(prop, "Viewport", "");
-
- prop = RNA_def_property(srna, "simplify_refsize", PROP_INT, PROP_PIXEL);
- RNA_def_property_int_sdna(prop, NULL, "simplify_refsize");
- RNA_def_property_range(prop, 1, SHRT_MAX);
- RNA_def_property_ui_text(prop, "Reference Size", "Reference size in pixels, after which simplification begins");
-
- prop = RNA_def_property(srna, "simplify_rate", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Rate", "Speed of simplification");
-
- prop = RNA_def_property(srna, "simplify_transition", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_ui_text(prop, "Transition", "Transition period for fading out strands");
-
- prop = RNA_def_property(srna, "simplify_viewport", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.0f, 0.999f);
- RNA_def_property_ui_text(prop, "Rate", "Speed of Simplification");
-
/* general values */
prop = RNA_def_property(srna, "frame_start", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "sta"); /*optional if prop names are the same */
@@ -3285,12 +3197,6 @@ static void rna_def_particle_system(BlenderRNA *brna)
FunctionRNA *func;
PropertyRNA *parm;
- static const EnumPropertyItem resolution_items[] = {
- {eModifierMode_Realtime, "PREVIEW", 0, "Preview", "Apply modifier preview settings"},
- {eModifierMode_Render, "RENDER", 0, "Render", "Apply modifier render settings"},
- {0, NULL, 0, NULL, NULL}
- };
-
srna = RNA_def_struct(brna, "ParticleSystem", NULL);
RNA_def_struct_ui_text(srna, "Particle System", "Particle system in an object");
RNA_def_struct_ui_icon(srna, ICON_PARTICLE_DATA);
@@ -3314,11 +3220,13 @@ static void rna_def_particle_system(BlenderRNA *brna)
prop = RNA_def_property(srna, "particles", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "particles", "totpart");
RNA_def_property_struct_type(prop, "Particle");
+ RNA_def_property_flag(prop, PROP_NO_COMPARISON);
RNA_def_property_ui_text(prop, "Particles", "Particles generated by the particle system");
prop = RNA_def_property(srna, "child_particles", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "child", "totchild");
RNA_def_property_struct_type(prop, "ChildParticle");
+ RNA_def_property_flag(prop, PROP_NO_COMPARISON);
RNA_def_property_ui_text(prop, "Child Particles", "Child particles generated by the particle system");
prop = RNA_def_property(srna, "seed", PROP_INT, PROP_UNSIGNED);
@@ -3601,13 +3509,6 @@ static void rna_def_particle_system(BlenderRNA *brna)
RNA_def_struct_path_func(srna, "rna_ParticleSystem_path");
- /* set viewport or render resolution */
- func = RNA_def_function(srna, "set_resolution", "rna_ParticleSystem_set_resolution");
- RNA_def_function_ui_description(func, "Set the resolution to use for the number of particles");
- RNA_def_pointer(func, "scene", "Scene", "", "Scene");
- RNA_def_pointer(func, "object", "Object", "", "Object");
- RNA_def_enum(func, "resolution", resolution_items, 0, "", "Resolution settings to apply");
-
/* extract cached hair location data */
func = RNA_def_function(srna, "co_hair", "rna_ParticleSystem_co_hair");
RNA_def_function_ui_description(func, "Obtain cache hair data");
diff --git a/source/blender/makesrna/intern/rna_pose.c b/source/blender/makesrna/intern/rna_pose.c
index ac27a6c21a5..014ac426b54 100644
--- a/source/blender/makesrna/intern/rna_pose.c
+++ b/source/blender/makesrna/intern/rna_pose.c
@@ -106,9 +106,11 @@ const EnumPropertyItem rna_enum_color_sets_items[] = {
#include "BKE_context.h"
#include "BKE_constraint.h"
-#include "BKE_depsgraph.h"
#include "BKE_idprop.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_object.h"
#include "ED_armature.h"
@@ -120,7 +122,8 @@ static void rna_Pose_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRN
{
/* XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); */
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ WM_main_add_notifier(NC_OBJECT | ND_POSE, ptr->id.data);
}
static void rna_Pose_IK_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
@@ -128,7 +131,9 @@ static void rna_Pose_IK_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Pointe
/* XXX when to use this? ob->pose->flag |= (POSE_LOCKED|POSE_DO_UNLOCK); */
Object *ob = ptr->id.data;
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ WM_main_add_notifier(NC_OBJECT | ND_POSE, ptr->id.data);
+
BIK_clear_data(ob->pose);
}
@@ -233,13 +238,13 @@ static void rna_Pose_ik_solver_update(Main *bmain, Scene *UNUSED(scene), Pointer
bPose *pose = ptr->data;
BKE_pose_tag_recalc(bmain, pose); /* checks & sorts pose channels */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
BKE_pose_update_constraint_flags(pose);
object_test_constraints(ob);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA | OB_RECALC_OB);
}
/* rotation - axis-angle */
@@ -349,7 +354,7 @@ static void rna_Itasc_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerR
itasc->maxvel = 100.f;
BIK_update_param(ob->pose);
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
static void rna_Itasc_update_rebuild(Main *bmain, Scene *scene, PointerRNA *ptr)
@@ -560,6 +565,54 @@ static void rna_PoseChannel_constraints_remove(ID *id, bPoseChannel *pchan, Repo
}
}
+bool rna_PoseChannel_constraints_override_apply(
+ PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *UNUSED(ptr_storage),
+ PropertyRNA *UNUSED(prop_dst), PropertyRNA *UNUSED(prop_src), PropertyRNA *UNUSED(prop_storage),
+ const int UNUSED(len_dst), const int UNUSED(len_src), const int UNUSED(len_storage),
+ IDOverrideStaticPropertyOperation *opop)
+{
+ BLI_assert(opop->operation == IDOVERRIDESTATIC_OP_INSERT_AFTER &&
+ "Unsupported RNA override operation on constraints collection");
+
+ bPoseChannel *pchan_dst = (bPoseChannel *)ptr_dst->data;
+ bPoseChannel *pchan_src = (bPoseChannel *)ptr_src->data;
+
+ /* Remember that insertion operations are defined and stored in correct order, which means that
+ * even if we insert several items in a row, we alays insert first one, then second one, etc.
+ * So we should always find 'anchor' constraint in both _src *and* _dst> */
+ bConstraint *con_anchor = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ con_anchor = BLI_findstring(&pchan_dst->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
+ }
+ if (con_anchor == NULL && opop->subitem_local_index >= 0) {
+ con_anchor = BLI_findlink(&pchan_dst->constraints, opop->subitem_local_index);
+ }
+ /* Otherwise we just insert in first position. */
+
+ bConstraint *con_src = NULL;
+ if (opop->subitem_local_name && opop->subitem_local_name[0]) {
+ con_src = BLI_findstring(&pchan_src->constraints, opop->subitem_local_name, offsetof(bConstraint, name));
+ }
+ if (con_src == NULL && opop->subitem_local_index >= 0) {
+ con_src = BLI_findlink(&pchan_src->constraints, opop->subitem_local_index);
+ }
+ con_src = con_src ? con_src->next : pchan_src->constraints.first;
+
+ BLI_assert(con_src != NULL);
+
+ bConstraint *con_dst = BKE_constraint_duplicate_ex(con_src, 0, true);
+
+ /* This handles NULL anchor as expected by adding at head of list. */
+ BLI_insertlinkafter(&pchan_dst->constraints, con_anchor, con_dst);
+
+ /* This should actually *not* be needed in typical cases. However, if overridden source was edited,
+ * we *may* have some new conflicting names. */
+ BKE_constraint_unique_name(con_dst, &pchan_dst->constraints);
+
+// printf("%s: We inserted a constraint...\n", __func__);
+ return true;
+}
+
static int rna_PoseChannel_proxy_editable(PointerRNA *ptr, const char **r_info)
{
Object *ob = (Object *)ptr->id.data;
@@ -671,7 +724,7 @@ static void rna_PoseChannel_matrix_set(PointerRNA *ptr, const float *values)
Object *ob = (Object *)ptr->id.data;
float tmat[4][4];
- BKE_armature_mat_pose_to_bone_ex(ob, pchan, (float (*)[4])values, tmat);
+ BKE_armature_mat_pose_to_bone_ex(NULL, ob, pchan, (float (*)[4])values, tmat);
BKE_pchan_apply_mat4(pchan, tmat, false); /* no compat for predictable result */
}
@@ -803,7 +856,9 @@ static void rna_def_pose_channel(BlenderRNA *brna)
/* Bone Constraints */
prop = RNA_def_property(srna, "constraints", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "Constraint");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC | PROP_OVERRIDABLE_STATIC_INSERTION);
RNA_def_property_ui_text(prop, "Constraints", "Constraints that act on this PoseChannel");
+ RNA_def_property_override_funcs(prop, NULL, NULL, "rna_PoseChannel_constraints_override_apply");
rna_def_pose_channel_constraints(brna, prop);
@@ -821,22 +876,26 @@ static void rna_def_pose_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "bone", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_struct_type(prop, "Bone");
+ RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Bone", "Bone associated with this PoseBone");
prop = RNA_def_property(srna, "parent", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "PoseBone");
+ RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Parent", "Parent of this pose bone");
prop = RNA_def_property(srna, "child", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "PoseBone");
+ RNA_def_property_flag(prop, PROP_PTR_NO_OWNERSHIP);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Child", "Child of this pose bone");
/* Transformation settings */
prop = RNA_def_property(srna, "location", PROP_FLOAT, PROP_TRANSLATION);
RNA_def_property_float_sdna(prop, NULL, "loc");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_editable_array_func(prop, "rna_PoseChannel_location_editable");
RNA_def_property_ui_text(prop, "Location", "");
RNA_def_property_ui_range(prop, -FLT_MAX, FLT_MAX, 1, RNA_TRANSLATION_PREC_DEFAULT);
@@ -844,7 +903,7 @@ static void rna_def_pose_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "size");
- RNA_def_property_flag(prop, PROP_PROPORTIONAL);
+ RNA_def_property_flag(prop, PROP_PROPORTIONAL | PROP_OVERRIDABLE_STATIC);
RNA_def_property_editable_array_func(prop, "rna_PoseChannel_scale_editable");
RNA_def_property_float_array_default(prop, default_scale);
RNA_def_property_ui_text(prop, "Scale", "");
@@ -852,6 +911,7 @@ static void rna_def_pose_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "rotation_quaternion", PROP_FLOAT, PROP_QUATERNION);
RNA_def_property_float_sdna(prop, NULL, "quat");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_4d_editable");
RNA_def_property_float_array_default(prop, default_quat);
RNA_def_property_ui_text(prop, "Quaternion Rotation", "Rotation in Quaternions");
@@ -861,6 +921,7 @@ static void rna_def_pose_channel(BlenderRNA *brna)
* having a single one is better for Keyframing and other property-management situations...
*/
prop = RNA_def_property(srna, "rotation_axis_angle", PROP_FLOAT, PROP_AXISANGLE);
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_array(prop, 4);
RNA_def_property_float_funcs(prop, "rna_PoseChannel_rotation_axis_angle_get",
"rna_PoseChannel_rotation_axis_angle_set", NULL);
@@ -871,6 +932,7 @@ static void rna_def_pose_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "rotation_euler", PROP_FLOAT, PROP_EULER);
RNA_def_property_float_sdna(prop, NULL, "eul");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_editable_array_func(prop, "rna_PoseChannel_rotation_euler_editable");
RNA_def_property_ui_text(prop, "Euler Rotation", "Rotation in Eulers");
RNA_def_property_update(prop, NC_OBJECT | ND_POSE, "rna_Pose_update");
@@ -899,7 +961,7 @@ static void rna_def_pose_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "bbone_custom_handle_start", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "bbone_prev");
RNA_def_property_struct_type(prop, "PoseBone");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_PTR_NO_OWNERSHIP);
RNA_def_property_ui_text(prop, "B-Bone Start Handle",
"Bone that serves as the start handle for the B-Bone curve");
RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
@@ -915,7 +977,7 @@ static void rna_def_pose_channel(BlenderRNA *brna)
prop = RNA_def_property(srna, "bbone_custom_handle_end", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "bbone_next");
RNA_def_property_struct_type(prop, "PoseBone");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_PTR_NO_OWNERSHIP);
RNA_def_property_ui_text(prop, "B-Bone End Handle",
"Bone that serves as the end handle for the B-Bone curve");
RNA_def_property_editable_func(prop, "rna_PoseChannel_proxy_editable");
@@ -1397,6 +1459,7 @@ static void rna_def_pose(BlenderRNA *brna)
prop = RNA_def_property(srna, "bones", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "chanbase", NULL);
RNA_def_property_struct_type(prop, "PoseBone");
+ RNA_def_property_flag(prop, PROP_OVERRIDABLE_STATIC);
RNA_def_property_ui_text(prop, "Pose Bones", "Individual pose bones for the armature");
/* can be removed, only for fast lookup */
RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL, "rna_PoseBones_lookup_string", NULL);
diff --git a/source/blender/makesrna/intern/rna_property.c b/source/blender/makesrna/intern/rna_property.c
deleted file mode 100644
index 7ee792b5d1f..00000000000
--- a/source/blender/makesrna/intern/rna_property.c
+++ /dev/null
@@ -1,203 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Blender Foundation (2008).
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/makesrna/intern/rna_property.c
- * \ingroup RNA
- */
-
-
-#include <stdlib.h>
-
-#include "DNA_property_types.h"
-#include "DNA_object_types.h"
-
-#include "BLI_path_util.h"
-#include "BLI_string_utils.h"
-
-#include "BLT_translation.h"
-
-#include "RNA_define.h"
-#include "RNA_enum_types.h"
-
-#include "rna_internal.h"
-
-
-#include "WM_types.h"
-
-const EnumPropertyItem rna_enum_gameproperty_type_items[] = {
- {GPROP_BOOL, "BOOL", 0, "Boolean", "Boolean Property"},
- {GPROP_INT, "INT", 0, "Integer", "Integer Property"},
- {GPROP_FLOAT, "FLOAT", 0, "Float", "Floating-Point Property"},
- {GPROP_STRING, "STRING", 0, "String", "String Property"},
- {GPROP_TIME, "TIMER", 0, "Timer", "Timer Property"},
- {0, NULL, 0, NULL, NULL}
-};
-
-
-#ifdef RNA_RUNTIME
-
-#include "BKE_property.h"
-
-static StructRNA *rna_GameProperty_refine(struct PointerRNA *ptr)
-{
- bProperty *property = (bProperty *)ptr->data;
-
- switch (property->type) {
- case GPROP_BOOL:
- return &RNA_GameBooleanProperty;
- case GPROP_INT:
- return &RNA_GameIntProperty;
- case GPROP_FLOAT:
- return &RNA_GameFloatProperty;
- case GPROP_STRING:
- return &RNA_GameStringProperty;
- case GPROP_TIME:
- return &RNA_GameTimerProperty;
- default:
- return &RNA_GameProperty;
- }
-}
-
-/* for both float and timer */
-static float rna_GameFloatProperty_value_get(PointerRNA *ptr)
-{
- bProperty *prop = (bProperty *)(ptr->data);
- return *(float *)(&prop->data);
-}
-
-static void rna_GameFloatProperty_value_set(PointerRNA *ptr, float value)
-{
- bProperty *prop = (bProperty *)(ptr->data);
- CLAMP(value, -10000.0f, 10000.0f);
- *(float *)(&prop->data) = value;
-}
-
-static void rna_GameProperty_type_set(PointerRNA *ptr, int value)
-{
- bProperty *prop = (bProperty *)(ptr->data);
-
- if (prop->type != value) {
- prop->type = value;
- BKE_bproperty_init(prop);
- }
-}
-
-static void rna_GameProperty_name_set(PointerRNA *ptr, const char *value)
-{
- Object *ob = ptr->id.data;
- bProperty *prop = ptr->data;
- BLI_strncpy_utf8(prop->name, value, sizeof(prop->name));
-
- BLI_uniquename(&ob->prop, prop, DATA_("Property"), '.', offsetof(bProperty, name), sizeof(prop->name));
-}
-
-
-#else
-
-void RNA_def_gameproperty(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- /* Base Struct for GameProperty */
- srna = RNA_def_struct(brna, "GameProperty", NULL);
- RNA_def_struct_ui_text(srna, "Game Property", "Game engine user defined object property");
- RNA_def_struct_sdna(srna, "bProperty");
- RNA_def_struct_refine_func(srna, "rna_GameProperty_refine");
-
- prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Name", "Available as GameObject attributes in the game engine's python API");
- RNA_def_struct_name_property(srna, prop);
- RNA_def_property_string_funcs(prop, NULL, NULL, "rna_GameProperty_name_set");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, rna_enum_gameproperty_type_items);
- RNA_def_property_ui_text(prop, "Type", "");
- RNA_def_property_enum_funcs(prop, NULL, "rna_GameProperty_type_set", NULL);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_debug", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", PROP_DEBUG);
- RNA_def_property_ui_text(prop, "Debug", "Print debug information for this property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* GameBooleanProperty */
- srna = RNA_def_struct(brna, "GameBooleanProperty", "GameProperty");
- RNA_def_struct_ui_text(srna, "Game Boolean Property", "Game engine user defined Boolean property");
- RNA_def_struct_sdna(srna, "bProperty");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "value", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "data", 1);
- RNA_def_property_ui_text(prop, "Value", "Property value");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* GameIntProperty */
- srna = RNA_def_struct(brna, "GameIntProperty", "GameProperty");
- RNA_def_struct_ui_text(srna, "Game Integer Property", "Game engine user defined integer number property");
- RNA_def_struct_sdna(srna, "bProperty");
-
- prop = RNA_def_property(srna, "value", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "data");
- RNA_def_property_ui_text(prop, "Value", "Property value");
- RNA_def_property_range(prop, -10000, 10000);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* GameFloatProperty */
- srna = RNA_def_struct(brna, "GameFloatProperty", "GameProperty");
- RNA_def_struct_ui_text(srna, "Game Float Property", "Game engine user defined floating point number property");
- RNA_def_struct_sdna(srna, "bProperty");
-
- prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
- /* RNA_def_property_float_sdna(prop, NULL, "data"); */
- RNA_def_property_ui_text(prop, "Value", "Property value");
- RNA_def_property_range(prop, -10000, 10000);
- RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* GameTimerProperty */
- srna = RNA_def_struct(brna, "GameTimerProperty", "GameProperty");
- RNA_def_struct_ui_text(srna, "Game Timer Property", "Game engine user defined timer property");
- RNA_def_struct_sdna(srna, "bProperty");
-
- prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
- /* RNA_def_property_float_sdna(prop, NULL, "data"); */
- RNA_def_property_ui_text(prop, "Value", "Property value");
- RNA_def_property_range(prop, -10000, 10000);
- RNA_def_property_float_funcs(prop, "rna_GameFloatProperty_value_get", "rna_GameFloatProperty_value_set", NULL);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* GameStringProperty */
- srna = RNA_def_struct(brna, "GameStringProperty", "GameProperty");
- RNA_def_struct_ui_text(srna, "Game String Property", "Game engine user defined text string property");
- RNA_def_struct_sdna(srna, "bProperty");
-
- prop = RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "poin");
- RNA_def_property_string_maxlength(prop, MAX_PROPSTRING);
- RNA_def_property_ui_text(prop, "Value", "Property value");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-#endif
-
diff --git a/source/blender/makesrna/intern/rna_render.c b/source/blender/makesrna/intern/rna_render.c
index 98ae6eb0480..ae774f8d41a 100644
--- a/source/blender/makesrna/intern/rna_render.c
+++ b/source/blender/makesrna/intern/rna_render.c
@@ -33,6 +33,8 @@
#include "BLI_utildefines.h"
#include "BLI_path_util.h"
+#include "DEG_depsgraph.h"
+
#include "BKE_scene.h"
#include "BKE_image.h"
@@ -164,24 +166,24 @@ static void engine_update(RenderEngine *engine, Main *bmain, Scene *scene)
RNA_parameter_list_free(&list);
}
-static void engine_render(RenderEngine *engine, struct Scene *scene)
+static void engine_render_to_image(RenderEngine *engine, Depsgraph *depsgraph)
{
- extern FunctionRNA rna_RenderEngine_render_func;
+ extern FunctionRNA rna_RenderEngine_render_to_image_func;
PointerRNA ptr;
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
- func = &rna_RenderEngine_render_func;
+ func = &rna_RenderEngine_render_to_image_func;
RNA_parameter_list_create(&list, &ptr, func);
- RNA_parameter_set_lookup(&list, "scene", &scene);
+ RNA_parameter_set_lookup(&list, "depsgraph", &depsgraph);
engine->type->ext.call(NULL, &ptr, func, &list);
RNA_parameter_list_free(&list);
}
-static void engine_bake(RenderEngine *engine, struct Scene *scene,
+static void engine_bake(RenderEngine *engine, struct Depsgraph *depsgraph, struct Scene *scene,
struct Object *object, const int pass_type, const int pass_filter,
const int object_id, const struct BakePixel *pixel_array,
const int num_pixels, const int depth, void *result)
@@ -195,6 +197,7 @@ static void engine_bake(RenderEngine *engine, struct Scene *scene,
func = &rna_RenderEngine_bake_func;
RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "depsgraph", &depsgraph);
RNA_parameter_set_lookup(&list, "scene", &scene);
RNA_parameter_set_lookup(&list, "object", &object);
RNA_parameter_set_lookup(&list, "pass_type", &pass_type);
@@ -226,15 +229,15 @@ static void engine_view_update(RenderEngine *engine, const struct bContext *cont
RNA_parameter_list_free(&list);
}
-static void engine_view_draw(RenderEngine *engine, const struct bContext *context)
+static void engine_render_to_view(RenderEngine *engine, const struct bContext *context)
{
- extern FunctionRNA rna_RenderEngine_view_draw_func;
+ extern FunctionRNA rna_RenderEngine_render_to_view_func;
PointerRNA ptr;
ParameterList list;
FunctionRNA *func;
RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
- func = &rna_RenderEngine_view_draw_func;
+ func = &rna_RenderEngine_render_to_view_func;
RNA_parameter_list_create(&list, &ptr, func);
RNA_parameter_set_lookup(&list, "context", &context);
@@ -261,7 +264,24 @@ static void engine_update_script_node(RenderEngine *engine, struct bNodeTree *nt
RNA_parameter_list_free(&list);
}
-static void engine_update_render_passes(RenderEngine *engine, struct Scene *scene, struct SceneRenderLayer *srl)
+static void engine_collection_settings_create(RenderEngine *engine, struct IDProperty *props)
+{
+ extern FunctionRNA rna_RenderEngine_collection_settings_create_func;
+ PointerRNA ptr;
+ ParameterList list;
+ FunctionRNA *func;
+
+ RNA_pointer_create(NULL, engine->type->ext.srna, engine, &ptr);
+ func = &rna_RenderEngine_collection_settings_create_func;
+
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "props", &props);
+ engine->type->ext.call(NULL, &ptr, func, &list);
+
+ RNA_parameter_list_free(&list);
+}
+
+static void engine_update_render_passes(RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer)
{
extern FunctionRNA rna_RenderEngine_update_render_passes_func;
PointerRNA ptr;
@@ -273,7 +293,7 @@ static void engine_update_render_passes(RenderEngine *engine, struct Scene *scen
RNA_parameter_list_create(&list, &ptr, func);
RNA_parameter_set_lookup(&list, "scene", &scene);
- RNA_parameter_set_lookup(&list, "renderlayer", &srl);
+ RNA_parameter_set_lookup(&list, "renderlayer", &view_layer);
engine->type->ext.call(NULL, &ptr, func, &list);
RNA_parameter_list_free(&list);
@@ -303,7 +323,7 @@ static StructRNA *rna_RenderEngine_register(
RenderEngineType *et, dummyet = {NULL};
RenderEngine dummyengine = {NULL};
PointerRNA dummyptr;
- int have_function[7];
+ int have_function[8];
/* setup dummy engine & engine type to store static properties in */
dummyengine.type = &dummyet;
@@ -340,14 +360,15 @@ static StructRNA *rna_RenderEngine_register(
RNA_struct_blender_type_set(et->ext.srna, et);
et->update = (have_function[0]) ? engine_update : NULL;
- et->render = (have_function[1]) ? engine_render : NULL;
+ et->render_to_image = (have_function[1]) ? engine_render_to_image : NULL;
et->bake = (have_function[2]) ? engine_bake : NULL;
et->view_update = (have_function[3]) ? engine_view_update : NULL;
- et->view_draw = (have_function[4]) ? engine_view_draw : NULL;
+ et->render_to_view = (have_function[4]) ? engine_render_to_view : NULL;
et->update_script_node = (have_function[5]) ? engine_update_script_node : NULL;
et->update_render_passes = (have_function[6]) ? engine_update_render_passes : NULL;
+ et->collection_settings_create = (have_function[7]) ? engine_collection_settings_create : NULL;
- BLI_addtail(&R_engines, et);
+ RE_engines_register(bmain, et);
return et->ext.srna;
}
@@ -484,14 +505,17 @@ static void rna_def_render_engine(BlenderRNA *brna)
RNA_def_pointer(func, "data", "BlendData", "", "");
RNA_def_pointer(func, "scene", "Scene", "", "");
- func = RNA_def_function(srna, "render", NULL);
+ func = RNA_def_function(srna, "render_to_image", NULL);
RNA_def_function_ui_description(func, "Render scene into an image");
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
- RNA_def_pointer(func, "scene", "Scene", "", "");
+ parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
func = RNA_def_function(srna, "bake", NULL);
RNA_def_function_ui_description(func, "Bake passes");
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+ parm = RNA_def_pointer(func, "depsgraph", "Depsgraph", "", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
parm = RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
parm = RNA_def_pointer(func, "object", "Object", "", "");
@@ -518,7 +542,7 @@ static void rna_def_render_engine(BlenderRNA *brna)
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
RNA_def_pointer(func, "context", "Context", "", "");
- func = RNA_def_function(srna, "view_draw", NULL);
+ func = RNA_def_function(srna, "render_to_view", NULL);
RNA_def_function_ui_description(func, "Draw viewport render");
RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
RNA_def_pointer(func, "context", "Context", "", "");
@@ -530,6 +554,19 @@ static void rna_def_render_engine(BlenderRNA *brna)
parm = RNA_def_pointer(func, "node", "Node", "", "");
RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
+ func = RNA_def_function(srna, "update_render_passes", NULL);
+ RNA_def_function_ui_description(func, "Update the render passes that will be generated");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+ parm = RNA_def_pointer(func, "scene", "Scene", "", "");
+ parm = RNA_def_pointer(func, "renderlayer", "ViewLayer", "", "");
+
+ /* per-collection engine settings initialization */
+ func = RNA_def_function(srna, "collection_settings_create", NULL);
+ RNA_def_function_ui_description(func, "Create the per collection settings for the engine");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+ parm = RNA_def_pointer(func, "collection_settings", "LayerCollectionSettings", "", "");
+ RNA_def_parameter_flags(parm, 0, PARM_RNAPTR);
+
/* tag for redraw */
func = RNA_def_function(srna, "tag_redraw", "engine_tag_redraw");
RNA_def_function_ui_description(func, "Request redraw for viewport rendering");
@@ -538,12 +575,6 @@ static void rna_def_render_engine(BlenderRNA *brna)
func = RNA_def_function(srna, "tag_update", "engine_tag_update");
RNA_def_function_ui_description(func, "Request update call for viewport rendering");
- func = RNA_def_function(srna, "update_render_passes", NULL);
- RNA_def_function_ui_description(func, "Update the render passes that will be generated");
- RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
- parm = RNA_def_pointer(func, "scene", "Scene", "", "");
- parm = RNA_def_pointer(func, "renderlayer", "SceneRenderLayer", "", "");
-
func = RNA_def_function(srna, "begin_result", "RE_engine_begin_result");
RNA_def_function_ui_description(func, "Create render result to write linear floating point render layers and passes");
parm = RNA_def_int(func, "x", 0, 0, INT_MAX, "X", "", 0, INT_MAX);
@@ -720,7 +751,7 @@ static void rna_def_render_engine(BlenderRNA *brna)
RNA_def_function_ui_description(func, "Register a render pass that will be part of the render with the current settings");
prop = RNA_def_pointer(func, "scene", "Scene", "", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- prop = RNA_def_pointer(func, "srl", "SceneRenderLayer", "", "");
+ prop = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
prop = RNA_def_string(func, "name", NULL, MAX_NAME, "Name", "");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
@@ -901,7 +932,7 @@ static void rna_def_render_layer(BlenderRNA *brna)
RNA_define_verify_sdna(0);
- rna_def_render_layer_common(srna, 0);
+ rna_def_view_layer_common(srna, 0);
prop = RNA_def_property(srna, "passes", PROP_COLLECTION, PROP_NONE);
RNA_def_property_struct_type(prop, "RenderPass");
diff --git a/source/blender/makesrna/intern/rna_rigidbody.c b/source/blender/makesrna/intern/rna_rigidbody.c
index 4c3301d5f9e..d252c04742f 100644
--- a/source/blender/makesrna/intern/rna_rigidbody.c
+++ b/source/blender/makesrna/intern/rna_rigidbody.c
@@ -91,7 +91,6 @@ static const EnumPropertyItem rigidbody_mesh_source_items[] = {
# include "RBI_api.h"
#endif
-#include "BKE_depsgraph.h"
#include "BKE_rigidbody.h"
#include "WM_api.h"
diff --git a/source/blender/makesrna/intern/rna_rna.c b/source/blender/makesrna/intern/rna_rna.c
index b1b7965286f..8cd0f94f546 100644
--- a/source/blender/makesrna/intern/rna_rna.c
+++ b/source/blender/makesrna/intern/rna_rna.c
@@ -106,6 +106,9 @@ const EnumPropertyItem rna_enum_property_unit_items[] = {
#ifdef RNA_RUNTIME
#include "MEM_guardedalloc.h"
#include "BLI_ghash.h"
+#include "BLI_string.h"
+
+#include "BKE_library_override.h"
/* Struct */
@@ -564,6 +567,13 @@ static int rna_Property_animatable_get(PointerRNA *ptr)
return (prop->flag & PROP_ANIMATABLE) != 0;
}
+static int rna_Property_overridable_get(PointerRNA *ptr)
+{
+ PropertyRNA *prop = (PropertyRNA *)ptr->data;
+
+ return (prop->flag & PROP_OVERRIDABLE_STATIC) != 0;
+}
+
static int rna_Property_use_output_get(PointerRNA *ptr)
{
PropertyRNA *prop = (PropertyRNA *)ptr->data;
@@ -1082,6 +1092,1229 @@ static int rna_BlenderRNA_structs_lookup_string(PointerRNA *ptr, const char *key
return false;
}
+/* Default override (and compare) callbacks. */
+
+/* Ensures it makes sense to go inside the pointers to compare their content
+ * (if they are IDs, or have different names or RNA type, then this would be meaningless). */
+static bool rna_property_override_diff_propptr_validate_diffing(
+ PointerRNA *propptr_a, PointerRNA *propptr_b,
+ bool *r_is_id, bool *r_is_null, bool *r_is_type_diff,
+ char **r_propname_a, char *propname_a_buff, size_t propname_a_buff_size,
+ char **r_propname_b, char *propname_b_buff, size_t propname_b_buff_size)
+{
+ BLI_assert(propptr_a != NULL);
+
+ bool is_valid_for_diffing = true;
+ const bool do_force_name = r_propname_a != NULL;
+
+ if (do_force_name) {
+ BLI_assert(r_propname_a != NULL);
+ BLI_assert(r_propname_b != NULL);
+ }
+
+ *r_is_id = *r_is_null = *r_is_type_diff = false;
+
+ /* Beware, PointerRNA_NULL has no type and is considered a 'blank page'! */
+ if (propptr_a->type == NULL) {
+ if (propptr_b == NULL || propptr_b->type == NULL) {
+ *r_is_null = true;
+ }
+ else {
+ *r_is_id = RNA_struct_is_ID(propptr_b->type);
+ *r_is_null = true;
+ *r_is_type_diff = true;
+ }
+ is_valid_for_diffing = false;
+ }
+ else {
+ *r_is_id = RNA_struct_is_ID(propptr_a->type);
+ *r_is_null = *r_is_type_diff = (ELEM(NULL, propptr_b, propptr_b->type));
+ is_valid_for_diffing = !(*r_is_id || *r_is_null);
+ }
+
+ if (propptr_b == NULL || propptr_a->type != propptr_b->type) {
+ *r_is_type_diff = true;
+ is_valid_for_diffing = false;
+// printf("%s: different pointer RNA types\n", rna_path ? rna_path : "<UNKNOWN>");
+ }
+
+ /* We do a generic quick first comparison checking for "name" and/or "type" properties.
+ * We assume that is any of those are false, then we are not handling the same data.
+ * This helps a lot in static override case, especially to detect inserted items in collections. */
+ if (is_valid_for_diffing || do_force_name) {
+ PropertyRNA *nameprop_a = RNA_struct_name_property(propptr_a->type);
+ PropertyRNA *nameprop_b = (propptr_b != NULL) ? RNA_struct_name_property(propptr_b->type) : NULL;
+
+ int propname_a_len = 0, propname_b_len = 0;
+ char *propname_a = NULL;
+ char *propname_b = NULL;
+ char buff_a[4096];
+ char buff_b[4096];
+ if (nameprop_a != NULL) {
+ if (r_propname_a == NULL && propname_a_buff == NULL) {
+ propname_a_buff = buff_a;
+ propname_a_buff_size = sizeof(buff_a);
+ }
+
+ propname_a = RNA_property_string_get_alloc(
+ propptr_a, nameprop_a, propname_a_buff, propname_a_buff_size, &propname_a_len);
+// printf("propname_a = %s\n", propname_a ? propname_a : "<NONE>");
+
+ if (r_propname_a != NULL) {
+ *r_propname_a = propname_a;
+ }
+ }
+// else printf("item of type %s a has no name property!\n", propptr_a->type->name);
+ if (nameprop_b != NULL) {
+ if (r_propname_b == NULL && propname_b_buff == NULL) {
+ propname_b_buff = buff_b;
+ propname_b_buff_size = sizeof(buff_b);
+ }
+
+ propname_b = RNA_property_string_get_alloc(
+ propptr_b, nameprop_b, propname_b_buff, propname_b_buff_size, &propname_b_len);
+
+ if (r_propname_b != NULL) {
+ *r_propname_b = propname_b;
+ }
+ }
+ if (propname_a != NULL && propname_b != NULL) {
+ if (propname_a_len != propname_b_len ||
+ propname_a[0] != propname_b[0] ||
+ !STREQ(propname_a, propname_b))
+ {
+ is_valid_for_diffing = false;
+// printf("%s: different names\n", rna_path ? rna_path : "<UNKNOWN>");
+ }
+ }
+ }
+
+ if (*r_is_id) {
+ BLI_assert(propptr_a->data == propptr_a->id.data && propptr_b->data == propptr_b->id.data);
+ }
+
+ return is_valid_for_diffing;
+}
+
+/* Used for both Pointer and Collection properties. */
+static int rna_property_override_diff_propptr(
+ PointerRNA *propptr_a, PointerRNA *propptr_b, eRNACompareMode mode, const bool no_ownership,
+ IDOverrideStatic *override, const char *rna_path, const int flags, bool *r_override_changed)
+{
+ const bool do_create = override != NULL && (flags & RNA_OVERRIDE_COMPARE_CREATE) != 0 && rna_path != NULL;
+
+ bool is_id = false;
+ bool is_null = false;
+ bool is_type_diff = false;
+ /* If false, it means that the whole data itself is different, so no point in going inside of it at all! */
+ bool is_valid_for_diffing = rna_property_override_diff_propptr_validate_diffing(
+ propptr_a, propptr_b, &is_id, &is_null, &is_type_diff,
+ NULL, NULL, 0, NULL, NULL, 0);
+
+ if (is_id) {
+ BLI_assert(no_ownership); /* For now, once we deal with nodetrees we'll want to get rid of that one. */
+ }
+
+ if (override) {
+ if (no_ownership /* || is_id */ || is_null || is_type_diff || !is_valid_for_diffing) {
+ /* In case this pointer prop does not own its data (or one is NULL), do not compare structs!
+ * This is a quite safe path to infinite loop, among other nasty issues.
+ * Instead, just compare pointers themselves. */
+ const int comp = (propptr_a->data != propptr_b->data);
+
+ if (do_create && comp != 0) {
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) { /* If not yet overridden... */
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ }
+
+ return comp;
+ }
+ else {
+ eRNAOverrideMatchResult report_flags = 0;
+ const bool match = RNA_struct_override_matches(propptr_a, propptr_b, rna_path, override, flags, &report_flags);
+ if (r_override_changed && (report_flags & RNA_OVERRIDE_MATCH_RESULT_CREATED) != 0) {
+ *r_override_changed = true;
+ }
+ return !match;
+ }
+ }
+ else {
+ /* We could also use is_diff_pointer, but then we potentially lose the gt/lt info -
+ * and don't think performances are critical here for now anyway... */
+ return !RNA_struct_equals(propptr_a, propptr_b, mode);
+ }
+}
+
+int rna_property_override_diff_default(PointerRNA *ptr_a, PointerRNA *ptr_b,
+ PropertyRNA *prop_a, PropertyRNA *prop_b,
+ const int len_a, const int len_b,
+ const int mode,
+ IDOverrideStatic *override, const char *rna_path,
+ const int flags, bool *r_override_changed)
+{
+ BLI_assert(len_a == len_b);
+
+ /* Note: at this point, we are sure that when len_a is zero, we are not handling an (empty) array. */
+
+ const bool do_create = override != NULL && (flags & RNA_OVERRIDE_COMPARE_CREATE) != 0 && rna_path != NULL;
+
+ switch (RNA_property_type(prop_a)) {
+ case PROP_BOOLEAN:
+ {
+ if (len_a) {
+ int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ int *array_a, *array_b;
+
+ array_a = (len_a > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_a;
+ array_b = (len_b > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_b, "RNA equals") : array_stack_b;
+
+ RNA_property_boolean_get_array(ptr_a, prop_a, array_a);
+ RNA_property_boolean_get_array(ptr_b, prop_b, array_b);
+
+ const int comp = memcmp(array_a, array_b, sizeof(int) * len_a);
+
+ if (do_create && comp != 0) {
+ /* XXX TODO this will have to be refined to handle array items */
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) {
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ else {
+ /* Already overriden prop, we'll have to check arrays items etc. */
+ }
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+
+ return comp;
+ }
+ else {
+ const int value_a = RNA_property_boolean_get(ptr_a, prop_a);
+ const int value_b = RNA_property_boolean_get(ptr_b, prop_b);
+ const int comp = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
+
+ if (do_create && comp != 0) {
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) { /* If not yet overridden... */
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ }
+
+ return comp;
+ }
+ }
+
+ case PROP_INT:
+ {
+ if (len_a) {
+ int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ int *array_a, *array_b;
+
+ array_a = (len_a > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_a, "RNA equals") : array_stack_a;
+ array_b = (len_b > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(int) * len_b, "RNA equals") : array_stack_b;
+
+ RNA_property_int_get_array(ptr_a, prop_a, array_a);
+ RNA_property_int_get_array(ptr_b, prop_b, array_b);
+
+ const int comp = memcmp(array_a, array_b, sizeof(int) * len_a);
+
+ if (do_create && comp != 0) {
+ /* XXX TODO this will have to be refined to handle array items */
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) {
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ else {
+ /* Already overriden prop, we'll have to check arrays items etc. */
+ }
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+
+ return comp;
+ }
+ else {
+ const int value_a = RNA_property_int_get(ptr_a, prop_a);
+ const int value_b = RNA_property_int_get(ptr_b, prop_b);
+ const int comp = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
+
+ if (do_create && comp != 0) {
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) { /* If not yet overridden... */
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ }
+
+ return comp;
+ }
+ }
+
+ case PROP_FLOAT:
+ {
+ if (len_a) {
+ float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ float *array_a, *array_b;
+
+ array_a = (len_a > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(float) * len_a, "RNA equals") : array_stack_a;
+ array_b = (len_b > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(float) * len_b, "RNA equals") : array_stack_b;
+
+ RNA_property_float_get_array(ptr_a, prop_a, array_a);
+ RNA_property_float_get_array(ptr_b, prop_b, array_b);
+
+ const int comp = memcmp(array_a, array_b, sizeof(float) * len_a);
+
+ if (do_create && comp != 0) {
+ /* XXX TODO this will have to be refined to handle array items */
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) {
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE,
+ NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ else {
+ /* Already overriden prop, we'll have to check arrays items etc. */
+ }
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+
+ return comp;
+ }
+ else {
+ const float value_a = RNA_property_float_get(ptr_a, prop_a);
+ const float value_b = RNA_property_float_get(ptr_b, prop_b);
+ const int comp = (value_a < value_b) ? -1 : (value_a > value_b) ? 1 : 0;
+
+ if (do_create && comp != 0) {
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) { /* If not yet overridden... */
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE,
+ NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ }
+
+ return comp ;
+ }
+ }
+
+ case PROP_ENUM:
+ {
+ const int value_a = RNA_property_enum_get(ptr_a, prop_a);
+ const int value_b = RNA_property_enum_get(ptr_b, prop_b);
+ const int comp = value_a != value_b;
+
+ if (do_create && comp != 0) {
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) { /* If not yet overridden... */
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ }
+
+ return comp;
+ }
+
+ case PROP_STRING:
+ {
+ char fixed_a[4096], fixed_b[4096];
+ int len_str_a, len_str_b;
+ char *value_a = RNA_property_string_get_alloc(ptr_a, prop_a, fixed_a, sizeof(fixed_a), &len_str_a);
+ char *value_b = RNA_property_string_get_alloc(ptr_b, prop_b, fixed_b, sizeof(fixed_b), &len_str_b);
+ /* TODO we could do a check on length too, but then we would not have a 'real' string comparison...
+ * Maybe behind a eRNAOverrideMatch flag? */
+// const int comp = len_str_a < len_str_b ? -1 : len_str_a > len_str_b ? 1 : strcmp(value_a, value_b);
+ const int comp = strcmp(value_a, value_b);
+
+ if (do_create && comp != 0) {
+ bool created = false;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (op != NULL && created) { /* If not yet overridden... */
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_REPLACE, NULL, NULL, -1, -1, true, NULL, NULL);
+ if (r_override_changed) {
+ *r_override_changed = created;
+ }
+ }
+ }
+
+ if (value_a != fixed_a) MEM_freeN(value_a);
+ if (value_b != fixed_b) MEM_freeN(value_b);
+
+ return comp;
+ }
+
+ case PROP_POINTER:
+ {
+ if (STREQ(RNA_property_identifier(prop_a), "rna_type")) {
+ /* Dummy 'pass' answer, this is a meta-data and must be ignored... */
+ return 0;
+ }
+ else {
+ PointerRNA propptr_a = RNA_property_pointer_get(ptr_a, prop_a);
+ PointerRNA propptr_b = RNA_property_pointer_get(ptr_b, prop_b);
+ const bool no_ownership = (RNA_property_flag(prop_a) & PROP_PTR_NO_OWNERSHIP) != 0;
+ return rna_property_override_diff_propptr(
+ &propptr_a, &propptr_b, mode, no_ownership,
+ override, rna_path, flags, r_override_changed);
+ }
+ break;
+ }
+
+ case PROP_COLLECTION:
+ {
+ /* Note: we assume we only insert in ptr_a (i.e. we can only get new items in ptr_a),
+ * and that we never remove anything. */
+ const bool use_insertion = (RNA_property_flag(prop_a) & PROP_OVERRIDABLE_STATIC_INSERTION) && do_create;
+ bool equals = true;
+ bool abort = false;
+ bool is_first_insert = true;
+ int idx_a = 0;
+ int idx_b = 0;
+
+#define RNA_PATH_BUFFSIZE 8192
+
+ char extended_rna_path_buffer[RNA_PATH_BUFFSIZE];
+ char *extended_rna_path = extended_rna_path_buffer;
+
+#define RNA_PATH_PRINTF(_str, ...) \
+ if (BLI_snprintf(extended_rna_path_buffer, RNA_PATH_BUFFSIZE, \
+ (_str), __VA_ARGS__) >= RNA_PATH_BUFFSIZE - 1) \
+ { extended_rna_path = BLI_sprintfN((_str), __VA_ARGS__); }(void)0
+#define RNA_PATH_FREE() \
+ if (extended_rna_path != extended_rna_path_buffer) MEM_freeN(extended_rna_path)
+
+ CollectionPropertyIterator iter_a, iter_b;
+ RNA_property_collection_begin(ptr_a, prop_a, &iter_a);
+ RNA_property_collection_begin(ptr_b, prop_b, &iter_b);
+
+ char buff_a[4096];
+ char buff_prev_a[4096] = {0};
+ char buff_b[4096];
+ char *propname_a = NULL;
+ char *prev_propname_a = buff_prev_a;
+ char *propname_b = NULL;
+
+ for (; iter_a.valid && !abort; ) {
+ bool is_valid_for_diffing;
+ bool is_valid_for_insertion;
+ do {
+ bool is_id = false, is_null = false, is_type_diff = false;
+
+ is_valid_for_insertion = use_insertion;
+
+ /* If false, it means that the whole data itself is different, so no point in going inside of it at all! */
+ if (iter_b.valid) {
+ is_valid_for_diffing = rna_property_override_diff_propptr_validate_diffing(
+ &iter_a.ptr, &iter_b.ptr, &is_id, &is_null, &is_type_diff,
+ &propname_a, buff_a, sizeof(buff_a),
+ &propname_b, buff_b, sizeof(buff_b));
+ }
+ else {
+ is_valid_for_diffing = false;
+ if (is_valid_for_insertion) {
+ /* We still need propname from 'a' item... */
+ rna_property_override_diff_propptr_validate_diffing(
+ &iter_a.ptr, NULL, &is_id, &is_null, &is_type_diff,
+ &propname_a, buff_a, sizeof(buff_a),
+ &propname_b, buff_b, sizeof(buff_b));
+ }
+ }
+
+ /* We do not support insertion of IDs for now, neither handle NULL pointers. */
+ if (is_id || is_valid_for_diffing) {
+ is_valid_for_insertion = false;
+ }
+
+#if 0
+ if (rna_path) {
+ printf("Checking %s, %s [%d] vs %s [%d]; diffing: %d; insert: %d (could be used: %d, do_create: %d)\n",
+ rna_path, propname_a ? propname_a : "", idx_a, propname_b ? propname_b : "", idx_b,
+ is_valid_for_diffing, is_valid_for_insertion,
+ (RNA_property_flag(prop_a) & PROP_OVERRIDABLE_STATIC_INSERTION) != 0, do_create);
+ }
+#endif
+
+ if (!(is_valid_for_diffing || is_valid_for_insertion)) {
+ /* Differences we cannot handle, we can break here
+ * (we do not support replacing ID pointers in collections e.g.). */
+ equals = false;
+ abort = true;
+ break;
+ }
+
+ /* There may be a propname defined in some cases, while no actual name set
+ * (e.g. happens with point cache), in that case too we want to fall back to index.
+ * Note that we do not need the RNA path for insertion operations. */
+ if (is_valid_for_diffing) {
+ if ((propname_a != NULL && propname_a[0] != '\0') &&
+ (propname_b != NULL && propname_b[0] != '\0'))
+ {
+ if (rna_path) {
+ /* In case of name, either it is valid for diffing, and _a and _b are identical,
+ * or it is valid for insertion, and we need to use _a. */
+ char esc_item_name[RNA_PATH_BUFFSIZE];
+ BLI_strescape(esc_item_name, propname_a, RNA_PATH_BUFFSIZE);
+ RNA_PATH_PRINTF("%s[\"%s\"]", rna_path, esc_item_name);
+ }
+ }
+ else { /* Based on index... */
+ if (rna_path) {
+ /* In case of indices, we need _a one for insertion, but _b ones for in-depth diffing.
+ * Insertion always happen once all 'replace' operations have been done,
+ * otherwise local and reference paths for those would have to be different! */
+ RNA_PATH_PRINTF("%s[%d]", rna_path, is_valid_for_insertion ? idx_a : idx_b);
+ }
+ }
+ }
+
+ /* Collections do not support replacement of their data (since they do not support removing),
+ * only in *some* cases, insertion.
+ * We also assume then that _a data is the one where things are inserted. */
+ if (is_valid_for_insertion && use_insertion) {
+ bool created;
+ IDOverrideStaticProperty *op = BKE_override_static_property_get(override, rna_path, &created);
+
+ if (is_first_insert) {
+ /* We need to clean up all possible existing insertion operations, otherwise we'd end up
+ * with a mess of ops everytime something changes. */
+ for (IDOverrideStaticPropertyOperation *opop = op->operations.first;
+ opop != NULL;)
+ {
+ IDOverrideStaticPropertyOperation *opop_next = opop->next;
+ if (ELEM(opop->operation,
+ IDOVERRIDESTATIC_OP_INSERT_AFTER, IDOVERRIDESTATIC_OP_INSERT_BEFORE))
+ {
+ BKE_override_static_property_operation_delete(op, opop);
+ }
+ opop = opop_next;
+ }
+ is_first_insert = false;
+ }
+
+ BKE_override_static_property_operation_get(
+ op, IDOVERRIDESTATIC_OP_INSERT_AFTER,
+ NULL, prev_propname_a, -1, idx_a - 1, true, NULL, NULL);
+// printf("%s: Adding insertion op override after '%s'/%d\n", rna_path, prev_propname_a, idx_a - 1);
+ }
+ else if (is_valid_for_diffing) {
+ if (equals || do_create) {
+ const bool no_ownership = (RNA_property_flag(prop_a) & PROP_PTR_NO_OWNERSHIP) != 0;
+ const int eq = rna_property_override_diff_propptr(
+ &iter_a.ptr, &iter_b.ptr, mode, no_ownership,
+ override, extended_rna_path, flags, r_override_changed);
+ equals = equals && eq;
+ }
+ }
+
+ if (prev_propname_a != buff_prev_a) {
+ MEM_freeN(prev_propname_a);
+ prev_propname_a = buff_prev_a;
+ }
+ prev_propname_a[0] = '\0';
+ if (propname_a != NULL &&
+ BLI_strncpy_rlen(prev_propname_a, propname_a, sizeof(buff_prev_a)) >= sizeof(buff_prev_a) - 1)
+ {
+ prev_propname_a = BLI_strdup(propname_a);
+ }
+ if (propname_a != buff_a) {
+ MEM_SAFE_FREE(propname_a);
+ propname_a = buff_a;
+ }
+ propname_a[0] = '\0';
+ if (propname_b != buff_b) {
+ MEM_SAFE_FREE(propname_b);
+ propname_b = buff_b;
+ }
+ propname_b[0] = '\0';
+ RNA_PATH_FREE();
+
+ if (!do_create && !equals) {
+ abort = true; /* Early out in case we do not want to loop over whole collection. */
+ break;
+ }
+
+ if (!(use_insertion && !is_valid_for_diffing)) {
+ break;
+ }
+
+ if (iter_a.valid) {
+ RNA_property_collection_next(&iter_a);
+ idx_a++;
+ }
+ } while (iter_a.valid);
+
+ if (iter_a.valid) {
+ RNA_property_collection_next(&iter_a);
+ idx_a++;
+ }
+ if (iter_b.valid) {
+ RNA_property_collection_next(&iter_b);
+ idx_b++;
+ }
+
+#undef RNA_PATH_BUFFSIZE
+#undef RNA_PATH_PRINTF
+#undef RNA_PATH_FREE
+ }
+
+ equals = equals && !(iter_a.valid || iter_b.valid) && !abort; /* Not same number of items in both collections... */
+ RNA_property_collection_end(&iter_a);
+ RNA_property_collection_end(&iter_b);
+
+ return (equals == false);
+ }
+
+ default:
+ break;
+ }
+
+ return 0;
+}
+
+bool rna_property_override_store_default(
+ PointerRNA *ptr_local, PointerRNA *ptr_reference, PointerRNA *ptr_storage,
+ PropertyRNA *prop_local, PropertyRNA *prop_reference, PropertyRNA *prop_storage,
+ const int len_local, const int len_reference, const int len_storage,
+ IDOverrideStaticPropertyOperation *opop)
+{
+ BLI_assert(len_local == len_reference && (!ptr_storage || len_local == len_storage));
+ UNUSED_VARS_NDEBUG(len_reference, len_storage);
+
+ bool changed = false;
+ const int index = opop->subitem_reference_index;
+
+ if (!ELEM(opop->operation, IDOVERRIDESTATIC_OP_ADD, IDOVERRIDESTATIC_OP_SUBTRACT, IDOVERRIDESTATIC_OP_MULTIPLY)) {
+ return changed;
+ }
+
+ /* XXX TODO About range limits.
+ * Ideally, it woudl be great to get rid of RNA range in that specific case.
+ * However, this won't be that easy and will add yet another layer of complexity in generated code,
+ * not to mention that we could most likely *not* bypass custom setters anyway.
+ * So for now, if needed second operand value is not in valid range, we simply fall back
+ * to a mere REPLACE operation.
+ * Time will say whether this is acceptable limitation or not. */
+ switch (RNA_property_type(prop_local)) {
+ case PROP_BOOLEAN:
+ /* TODO support boolean ops? Really doubt this would ever be useful though... */
+ BLI_assert(0 && "Boolean properties support no override diff operation");
+ break;
+ case PROP_INT:
+ {
+ int prop_min, prop_max;
+ RNA_property_int_range(ptr_local, prop_local, &prop_min, &prop_max);
+
+ if (len_local) {
+ if (index == -1) {
+ int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ int *array_a, *array_b;
+
+ array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
+ RNA_property_int_get_array(ptr_reference, prop_reference, array_a);
+
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ bool do_set = true;
+ array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
+ RNA_property_int_get_array(ptr_local, prop_local, array_b);
+ for (int i = len_local; i--;) {
+ array_b[i] = fac * (array_b[i] - array_a[i]);
+ if (array_b[i] < prop_min || array_b[i] > prop_max) {
+ opop->operation = other_op;
+ for (int j = len_local; j--;) {
+ array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
+ if (array_b[j] < prop_min || array_b[j] > prop_max) {
+ /* We failed to find a suitable diff op,
+ * fall back to plain REPLACE one. */
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ do_set = false;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ if (do_set) {
+ changed = true;
+ RNA_property_int_set_array(ptr_storage, prop_storage, array_b);
+ }
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ }
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on integer");
+ break;
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ }
+ else {
+ const int value = RNA_property_int_get_index(ptr_reference, prop_reference, index);
+
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ int b = fac * (RNA_property_int_get_index(ptr_local, prop_local, index) - value);
+ if (b < prop_min || b > prop_max) {
+ opop->operation = other_op;
+ b = -b;
+ if (b < prop_min || b > prop_max) {
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ break;
+ }
+ }
+ changed = true;
+ RNA_property_int_set_index(ptr_storage, prop_storage, index, b);
+ break;
+ }
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on integer");
+ break;
+ }
+ }
+ }
+ else {
+ const int value = RNA_property_int_get(ptr_reference, prop_reference);
+
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const int fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1 : -1;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ int b = fac * (RNA_property_int_get(ptr_local, prop_local) - value);
+ if (b < prop_min || b > prop_max) {
+ opop->operation = other_op;
+ b = -b;
+ if (b < prop_min || b > prop_max) {
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ break;
+ }
+ }
+ changed = true;
+ RNA_property_int_set(ptr_storage, prop_storage, b);
+ break;
+ }
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on integer");
+ break;
+ }
+ }
+ break;
+ }
+ case PROP_FLOAT:
+ {
+ float prop_min, prop_max;
+ RNA_property_float_range(ptr_local, prop_local, &prop_min, &prop_max);
+
+ if (len_local) {
+ if (index == -1) {
+ float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ float *array_a, *array_b;
+
+ array_a = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_local, __func__) : array_stack_a;
+
+ RNA_property_float_get_array(ptr_reference, prop_reference, array_a);
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0 : -1.0;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ bool do_set = true;
+ array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
+ RNA_property_float_get_array(ptr_local, prop_local, array_b);
+ for (int i = len_local; i--;) {
+ array_b[i] = fac * (array_b[i] - array_a[i]);
+ if (array_b[i] < prop_min || array_b[i] > prop_max) {
+ opop->operation = other_op;
+ for (int j = len_local; j--;) {
+ array_b[j] = j >= i ? -array_b[j] : fac * (array_a[j] - array_b[j]);
+ if (array_b[j] < prop_min || array_b[j] > prop_max) {
+ /* We failed to find a suitable diff op,
+ * fall back to plain REPLACE one. */
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ do_set = false;
+ break;
+ }
+ }
+ break;
+ }
+ }
+ if (do_set) {
+ changed = true;
+ RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
+ }
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ }
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ {
+ bool do_set = true;
+ array_b = (len_local > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_local, __func__) : array_stack_b;
+ RNA_property_float_get_array(ptr_local, prop_local, array_b);
+ for (int i = len_local; i--;) {
+ array_b[i] = array_a[i] == 0.0f ? array_b[i] : array_b[i] / array_a[i];
+ if (array_b[i] < prop_min || array_b[i] > prop_max) {
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ do_set = false;
+ break;
+ }
+ }
+ if (do_set) {
+ changed = true;
+ RNA_property_float_set_array(ptr_storage, prop_storage, array_b);
+ }
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ }
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on float");
+ break;
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ }
+ else {
+ const float value = RNA_property_float_get_index(ptr_reference, prop_reference, index);
+
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0f : -1.0f;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ float b = fac * (RNA_property_float_get_index(ptr_local, prop_local, index) - value);
+ if (b < prop_min || b > prop_max) {
+ opop->operation = other_op;
+ b = -b;
+ if (b < prop_min || b > prop_max) {
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ break;
+ }
+ }
+ changed = true;
+ RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
+ break;
+ }
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ {
+ const float b = RNA_property_float_get_index(ptr_local, prop_local, index) / (value == 0.0f ? 1.0f : value);
+ if (b < prop_min || b > prop_max) {
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ break;
+ }
+ changed = true;
+ RNA_property_float_set_index(ptr_storage, prop_storage, index, b);
+ break;
+ }
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on float");
+ break;
+ }
+ }
+ }
+ else {
+ const float value = RNA_property_float_get(ptr_reference, prop_reference);
+
+ switch (opop->operation) {
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ {
+ const float fac = opop->operation == IDOVERRIDESTATIC_OP_ADD ? 1.0f : -1.0f;
+ const int other_op = opop->operation == IDOVERRIDESTATIC_OP_ADD ? IDOVERRIDESTATIC_OP_SUBTRACT : IDOVERRIDESTATIC_OP_ADD;
+ float b = fac * (RNA_property_float_get(ptr_local, prop_local) - value);
+ if (b < prop_min || b > prop_max) {
+ opop->operation = other_op;
+ b = -b;
+ if (b < prop_min || b > prop_max) {
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ break;
+ }
+ }
+ changed = true;
+ RNA_property_float_set(ptr_storage, prop_storage, b);
+ break;
+ }
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ {
+ const float b = RNA_property_float_get(ptr_local, prop_local) / (value == 0.0f ? 1.0f : value);
+ if (b < prop_min || b > prop_max) {
+ opop->operation = IDOVERRIDESTATIC_OP_REPLACE;
+ break;
+ }
+ changed = true;
+ RNA_property_float_set(ptr_storage, prop_storage, b);
+ break;
+ }
+ default:
+ BLI_assert(0 && "Unsupported RNA override diff operation on float");
+ break;
+ }
+ }
+ return true;
+ }
+ case PROP_ENUM:
+ /* TODO support add/sub, for bitflags? */
+ BLI_assert(0 && "Enum properties support no override diff operation");
+ break;
+ case PROP_POINTER:
+ BLI_assert(0 && "Pointer properties support no override diff operation");
+ break;
+ case PROP_STRING:
+ BLI_assert(0 && "String properties support no override diff operation");
+ break;
+ case PROP_COLLECTION:
+ /* XXX TODO support this of course... */
+ BLI_assert(0 && "Collection properties support no override diff operation");
+ break;
+ default:
+ break;
+ }
+
+ return changed;
+}
+
+bool rna_property_override_apply_default(
+ PointerRNA *ptr_dst, PointerRNA *ptr_src, PointerRNA *ptr_storage,
+ PropertyRNA *prop_dst, PropertyRNA *prop_src, PropertyRNA *prop_storage,
+ const int len_dst, const int len_src, const int len_storage,
+ IDOverrideStaticPropertyOperation *opop)
+{
+ BLI_assert(len_dst == len_src && (!ptr_storage || len_dst == len_storage));
+ UNUSED_VARS_NDEBUG(len_src, len_storage);
+
+ const int index = opop->subitem_reference_index;
+ const short override_op = opop->operation;
+
+ switch (RNA_property_type(prop_dst)) {
+ case PROP_BOOLEAN:
+ if (len_dst) {
+ if (index == -1) {
+ int array_stack_a[RNA_STACK_ARRAY];
+ int *array_a;
+
+ array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
+
+ RNA_property_boolean_get_array(ptr_src, prop_src, array_a);
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_boolean_set_array(ptr_dst, prop_dst, array_a);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on boolean");
+ return false;
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ }
+ else {
+ const int value = RNA_property_boolean_get_index(ptr_src, prop_src, index);
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_boolean_set_index(ptr_dst, prop_dst, index, value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on boolean");
+ return false;
+ }
+ }
+ }
+ else {
+ const int value = RNA_property_boolean_get(ptr_src, prop_src);
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_boolean_set(ptr_dst, prop_dst, value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on boolean");
+ return false;
+ }
+ }
+ return true;
+ case PROP_INT:
+ if (len_dst) {
+ if (index == -1) {
+ int array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ int *array_a, *array_b;
+
+ array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_int_get_array(ptr_src, prop_src, array_a);
+ RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ RNA_property_int_get_array(ptr_dst, prop_dst, array_a);
+ array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
+ RNA_property_int_get_array(ptr_storage, prop_storage, array_b);
+ if (override_op == IDOVERRIDESTATIC_OP_ADD) {
+ for (int i = len_dst; i--;) array_a[i] += array_b[i];
+ }
+ else {
+ for (int i = len_dst; i--;) array_a[i] -= array_b[i];
+ }
+ RNA_property_int_set_array(ptr_dst, prop_dst, array_a);
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on integer");
+ return false;
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ }
+ else {
+ const int storage_value = ptr_storage ? RNA_property_int_get_index(ptr_storage, prop_storage, index) : 0;
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_int_set_index(ptr_dst, prop_dst, index,
+ RNA_property_int_get_index(ptr_src, prop_src, index));
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ RNA_property_int_set_index(ptr_dst, prop_dst, index,
+ RNA_property_int_get_index(ptr_dst, prop_dst, index) - storage_value);
+ break;
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ RNA_property_int_set_index(ptr_dst, prop_dst, index,
+ RNA_property_int_get_index(ptr_dst, prop_dst, index) - storage_value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on integer");
+ return false;
+ }
+ }
+ }
+ else {
+ const int storage_value = ptr_storage ? RNA_property_int_get(ptr_storage, prop_storage) : 0;
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_src, prop_src));
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_dst, prop_dst) + storage_value);
+ break;
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ RNA_property_int_set(ptr_dst, prop_dst, RNA_property_int_get(ptr_dst, prop_dst) - storage_value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on integer");
+ return false;
+ }
+ }
+ return true;
+ case PROP_FLOAT:
+ if (len_dst) {
+ if (index == -1) {
+ float array_stack_a[RNA_STACK_ARRAY], array_stack_b[RNA_STACK_ARRAY];
+ float *array_a, *array_b;
+
+ array_a = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_a) * len_dst, __func__) : array_stack_a;
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_float_get_array(ptr_src, prop_src, array_a);
+ RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ RNA_property_float_get_array(ptr_dst, prop_dst, array_a);
+ array_b = (len_dst > RNA_STACK_ARRAY) ? MEM_mallocN(sizeof(*array_b) * len_dst, __func__) : array_stack_b;
+ RNA_property_float_get_array(ptr_storage, prop_storage, array_b);
+ if (override_op == IDOVERRIDESTATIC_OP_ADD) {
+ for (int i = len_dst; i--;) array_a[i] += array_b[i];
+ }
+ else if (override_op == IDOVERRIDESTATIC_OP_SUBTRACT) {
+ for (int i = len_dst; i--;) array_a[i] -= array_b[i];
+ }
+ else {
+ for (int i = len_dst; i--;) array_a[i] *= array_b[i];
+ }
+ RNA_property_float_set_array(ptr_dst, prop_dst, array_a);
+ if (array_b != array_stack_b) MEM_freeN(array_b);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on float");
+ return false;
+ }
+
+ if (array_a != array_stack_a) MEM_freeN(array_a);
+ }
+ else {
+ const float storage_value = ptr_storage ? RNA_property_float_get_index(ptr_storage, prop_storage, index) : 0.0f;
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_float_set_index(ptr_dst, prop_dst, index,
+ RNA_property_float_get_index(ptr_src, prop_src, index));
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ RNA_property_float_set_index(ptr_dst, prop_dst, index,
+ RNA_property_float_get_index(ptr_dst, prop_dst, index) + storage_value);
+ break;
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ RNA_property_float_set_index(ptr_dst, prop_dst, index,
+ RNA_property_float_get_index(ptr_dst, prop_dst, index) - storage_value);
+ break;
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ RNA_property_float_set_index(ptr_dst, prop_dst, index,
+ RNA_property_float_get_index(ptr_dst, prop_dst, index) * storage_value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on float");
+ return false;
+ }
+ }
+ }
+ else {
+ const float storage_value = ptr_storage ? RNA_property_float_get(ptr_storage, prop_storage) : 0.0f;
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_src, prop_src));
+ break;
+ case IDOVERRIDESTATIC_OP_ADD:
+ RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) + storage_value);
+ break;
+ case IDOVERRIDESTATIC_OP_SUBTRACT:
+ RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) - storage_value);
+ break;
+ case IDOVERRIDESTATIC_OP_MULTIPLY:
+ RNA_property_float_set(ptr_dst, prop_dst, RNA_property_float_get(ptr_dst, prop_dst) * storage_value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on float");
+ return false;
+ }
+ }
+ return true;
+ case PROP_ENUM:
+ {
+ const int value = RNA_property_enum_get(ptr_src, prop_src);
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_enum_set(ptr_dst, prop_dst, value);
+ break;
+ /* TODO support add/sub, for bitflags? */
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on enum");
+ return false;
+ }
+ return true;
+ }
+ case PROP_POINTER:
+ {
+ PointerRNA value = RNA_property_pointer_get(ptr_src, prop_src);
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_pointer_set(ptr_dst, prop_dst, value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on pointer");
+ return false;
+ }
+ return true;
+ }
+ case PROP_STRING:
+ {
+ char buff[256];
+ char *value = RNA_property_string_get_alloc(ptr_src, prop_src, buff, sizeof(buff), NULL);
+
+ switch (override_op) {
+ case IDOVERRIDESTATIC_OP_REPLACE:
+ RNA_property_string_set(ptr_dst, prop_dst, value);
+ break;
+ default:
+ BLI_assert(0 && "Unsupported RNA override operation on string");
+ return false;
+ }
+
+ if (value != buff) MEM_freeN(value);
+ return true;
+ }
+ case PROP_COLLECTION:
+ {
+ BLI_assert(!"You need to define a specific override apply callback for enums.");
+ return false;
+ }
+ default:
+ BLI_assert(0);
+ return false;
+ }
+
+ return false;
+}
+
+
#else
@@ -1259,6 +2492,11 @@ static void rna_def_property(BlenderRNA *brna)
RNA_def_property_boolean_funcs(prop, "rna_Property_animatable_get", NULL);
RNA_def_property_ui_text(prop, "Animatable", "Property is animatable through RNA");
+ prop = RNA_def_property(srna, "is_overridable", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_boolean_funcs(prop, "rna_Property_overridable_get", NULL);
+ RNA_def_property_ui_text(prop, "Overridable", "Property is overridable through RNA");
+
prop = RNA_def_property(srna, "is_required", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_boolean_funcs(prop, "rna_Property_is_required_get", NULL);
diff --git a/source/blender/makesrna/intern/rna_scene.c b/source/blender/makesrna/intern/rna_scene.c
index 07e1c85c788..b2fca51ce38 100644
--- a/source/blender/makesrna/intern/rna_scene.c
+++ b/source/blender/makesrna/intern/rna_scene.c
@@ -32,10 +32,13 @@
#include "DNA_particle_types.h"
#include "DNA_rigidbody_types.h"
#include "DNA_scene_types.h"
+#include "DNA_layer_types.h"
#include "DNA_linestyle_types.h"
#include "DNA_userdef_types.h"
#include "DNA_world_types.h"
#include "DNA_gpencil_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_screen_types.h" /* TransformOrientation */
#include "IMB_imbuf_types.h"
@@ -47,8 +50,12 @@
#include "BKE_editmesh.h"
#include "BKE_paint.h"
+#include "ED_object.h"
+
#include "GPU_extensions.h"
+#include "DRW_engine.h"
+
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -66,6 +73,7 @@
#endif
#include "ED_render.h"
+#include "ED_transform.h"
#include "WM_api.h"
#include "WM_types.h"
@@ -430,8 +438,21 @@ static const EnumPropertyItem rna_enum_gpencil_interpolation_mode_items[] = {
{0, NULL, 0, NULL, NULL}
};
+
#endif
+static const EnumPropertyItem transform_orientation_items[] = {
+ {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", "Align the transformation axes to world space"},
+ {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", "Align the transformation axes to the selected objects' local space"},
+ {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal",
+ "Align the transformation axes to average normal of selected elements "
+ "(bone Y axis for pose mode)"},
+ {V3D_MANIP_GIMBAL, "GIMBAL", 0, "Gimbal", "Align each axis to the Euler rotation axis as used for input"},
+ {V3D_MANIP_VIEW, "VIEW", 0, "View", "Align the transformation axes to the window"},
+ // {V3D_MANIP_CUSTOM, "CUSTOM", 0, "Custom", "Use a custom transform orientation"},
+ {0, NULL, 0, NULL, NULL}
+};
+
#ifdef RNA_RUNTIME
#include "DNA_anim_types.h"
@@ -440,22 +461,24 @@ static const EnumPropertyItem rna_enum_gpencil_interpolation_mode_items[] = {
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
#include "DNA_text_types.h"
+#include "DNA_workspace_types.h"
#include "RNA_access.h"
#include "MEM_guardedalloc.h"
#include "BKE_brush.h"
+#include "BKE_collection.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_node.h"
#include "BKE_pointcache.h"
#include "BKE_scene.h"
-#include "BKE_depsgraph.h"
#include "BKE_mesh.h"
#include "BKE_sound.h"
#include "BKE_screen.h"
@@ -470,6 +493,11 @@ static const EnumPropertyItem rna_enum_gpencil_interpolation_mode_items[] = {
#include "ED_mesh.h"
#include "ED_keyframing.h"
#include "ED_image.h"
+#include "ED_scene.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
#ifdef WITH_FREESTYLE
#include "FRS_freestyle.h"
@@ -605,110 +633,38 @@ static void rna_SpaceImageEditor_uv_sculpt_update(Main *bmain, Scene *scene, Poi
ED_space_image_uv_sculpt_update(bmain->wm.first, scene);
}
-static int rna_Scene_object_bases_lookup_string(PointerRNA *ptr, const char *key, PointerRNA *r_ptr)
-{
- Scene *scene = (Scene *)ptr->data;
- Base *base;
- for (base = scene->base.first; base; base = base->next) {
- if (STREQLEN(base->object->id.name + 2, key, sizeof(base->object->id.name) - 2)) {
- *r_ptr = rna_pointer_inherit_refine(ptr, &RNA_ObjectBase, base);
- return true;
- }
- }
+/* Read-only Iterator of all the scene objects. */
- return false;
-}
-
-static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
+static void rna_Scene_objects_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
{
- ListBaseIterator *internal = &iter->internal.listbase;
+ Scene *scene = (Scene *)ptr->data;
+ iter->internal.custom = MEM_callocN(sizeof(BLI_Iterator), __func__);
- /* we are actually iterating a Base list, so override get */
- return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ((Base *)internal->link)->object);
+ ((BLI_Iterator *)iter->internal.custom)->valid = true;
+ BKE_scene_objects_iterator_begin(iter->internal.custom, (void *)scene);
+ iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
}
-static Base *rna_Scene_object_link(Scene *scene, bContext *C, ReportList *reports, Object *ob)
+static void rna_Scene_objects_next(CollectionPropertyIterator *iter)
{
- Scene *scene_act = CTX_data_scene(C);
- Base *base;
-
- if (BKE_scene_base_find(scene, ob)) {
- BKE_reportf(reports, RPT_ERROR, "Object '%s' is already in scene '%s'", ob->id.name + 2, scene->id.name + 2);
- return NULL;
- }
-
- base = BKE_scene_base_add(scene, ob);
- id_us_plus(&ob->id);
-
- /* this is similar to what object_add_type and BKE_object_add do */
- base->lay = scene->lay;
-
- /* when linking to an inactive scene don't touch the layer */
- if (scene == scene_act)
- ob->lay = base->lay;
-
- /* TODO(sergey): Only update relations for the current scene. */
- DAG_relations_tag_update(CTX_data_main(C));
- DAG_id_tag_update(&ob->id, OB_RECALC_OB | OB_RECALC_DATA | OB_RECALC_TIME);
-
- /* slows down importers too much, run scene.update() */
- /* DAG_srelations_tag_update(G.main); */
-
- WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene);
-
- return base;
+ BKE_scene_objects_iterator_next(iter->internal.custom);
+ iter->valid = ((BLI_Iterator *)iter->internal.custom)->valid;
}
-static void rna_Scene_object_unlink(Scene *scene, ReportList *reports, Object *ob)
+static void rna_Scene_objects_end(CollectionPropertyIterator *iter)
{
- Base *base = BKE_scene_base_find(scene, ob);
- if (!base) {
- BKE_reportf(reports, RPT_ERROR, "Object '%s' is not in this scene '%s'", ob->id.name + 2, scene->id.name + 2);
- return;
- }
- if (base == scene->basact && ob->mode != OB_MODE_OBJECT) {
- BKE_reportf(reports, RPT_ERROR, "Object '%s' must be in object mode to unlink", ob->id.name + 2);
- return;
- }
- if (scene->basact == base) {
- scene->basact = NULL;
- }
-
- BKE_scene_base_unlink(scene, base);
- MEM_freeN(base);
-
- id_us_min(&ob->id);
-
- /* needed otherwise the depgraph will contain freed objects which can crash, see [#20958] */
- DAG_relations_tag_update(G.main);
-
- WM_main_add_notifier(NC_SCENE | ND_OB_ACTIVE, scene);
+ BKE_scene_objects_iterator_end(iter->internal.custom);
+ MEM_freeN(iter->internal.custom);
}
-static void rna_Scene_skgen_etch_template_set(PointerRNA *ptr, PointerRNA value)
+static PointerRNA rna_Scene_objects_get(CollectionPropertyIterator *iter)
{
- ToolSettings *ts = (ToolSettings *)ptr->data;
- if (value.data && ((Object *)value.data)->type == OB_ARMATURE)
- ts->skgen_template = value.data;
- else
- ts->skgen_template = NULL;
+ Object *ob = ((BLI_Iterator *)iter->internal.custom)->current;
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Object, ob);
}
-static PointerRNA rna_Scene_active_object_get(PointerRNA *ptr)
-{
- Scene *scene = (Scene *)ptr->data;
- return rna_pointer_inherit_refine(ptr, &RNA_Object, scene->basact ? scene->basact->object : NULL);
-}
-
-static void rna_Scene_active_object_set(PointerRNA *ptr, PointerRNA value)
-{
- Scene *scene = (Scene *)ptr->data;
- if (value.data)
- scene->basact = BKE_scene_base_find(scene, (Object *)value.data);
- else
- scene->basact = NULL;
-}
+/* End of read-only Iterator of all the scene objects. */
static void rna_Scene_set_set(PointerRNA *ptr, PointerRNA value)
{
@@ -728,11 +684,25 @@ static void rna_Scene_set_set(PointerRNA *ptr, PointerRNA value)
scene->set = set;
}
+void rna_Scene_set_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ Scene *scene = (Scene *)ptr->id.data;
+
+ DEG_relations_tag_update(bmain);
+ DEG_id_tag_update_ex(bmain, &scene->id, 0);
+ if (scene->set != NULL) {
+ /* Objects which are pulled into main scene's depsgraph needs to have
+ * their base flags updated.
+ */
+ DEG_id_tag_update_ex(bmain, &scene->set->id, 0);
+ }
+}
+
static void rna_Scene_layer_set(PointerRNA *ptr, const int *values)
{
Scene *scene = (Scene *)ptr->data;
- scene->lay = ED_view3d_scene_layer_set(scene->lay, values, &scene->layact);
+ scene->lay = ED_view3d_view_layer_set(scene->lay, values, &scene->layact);
}
static int rna_Scene_active_layer_get(PointerRNA *ptr)
@@ -744,19 +714,21 @@ static int rna_Scene_active_layer_get(PointerRNA *ptr)
static void rna_Scene_view3d_update(Main *bmain, Scene *UNUSED(scene_unused), PointerRNA *ptr)
{
+ wmWindowManager *wm = bmain->wm.first;
Scene *scene = (Scene *)ptr->data;
- BKE_screen_view3d_main_sync(&bmain->screen, scene);
+ WM_windows_scene_data_sync(&wm->windows, scene);
}
-static void rna_Scene_layer_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Scene_layer_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
- rna_Scene_view3d_update(bmain, scene, ptr);
/* XXX We would need do_time=true here, else we can have update issues like [#36289]...
* However, this has too much drawbacks (like slower layer switch, undesired updates...).
* That's TODO for future DAG updates.
*/
- DAG_on_visible_update(bmain, false);
+ DEG_on_visible_update(bmain, false);
+
+ /* No need to sync scene data here (WM_windows_scene_data_sync), handled through notifier. */
}
static void rna_Scene_fps_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
@@ -1065,17 +1037,6 @@ static int rna_RenderSettings_is_movie_format_get(PointerRNA *ptr)
return BKE_imtype_is_movie(rd->im_format.imtype);
}
-static int rna_RenderSettings_save_buffers_get(PointerRNA *ptr)
-{
- RenderData *rd = (RenderData *)ptr->data;
- Scene *scene = (Scene *)ptr->id.data;
-
- if (!BKE_scene_use_new_shading_nodes(scene))
- return (rd->scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) != 0;
- else
- return (rd->scemode & R_EXR_TILE_FILE) != 0;
-}
-
static void rna_ImageFormatSettings_file_format_set(PointerRNA *ptr, int value)
{
ImageFormatData *imf = (ImageFormatData *)ptr->data;
@@ -1334,73 +1295,6 @@ static void rna_FFmpegSettings_codec_settings_update(Main *UNUSED(bmain), Scene
}
#endif
-static int rna_RenderSettings_active_layer_index_get(PointerRNA *ptr)
-{
- RenderData *rd = (RenderData *)ptr->data;
- return rd->actlay;
-}
-
-static void rna_RenderSettings_active_layer_index_set(PointerRNA *ptr, int value)
-{
- RenderData *rd = (RenderData *)ptr->data;
- int num_layers = BLI_listbase_count(&rd->layers);
- rd->actlay = min_ff(value, num_layers - 1);
-}
-
-static void rna_RenderSettings_active_layer_index_range(
- PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
-{
- RenderData *rd = (RenderData *)ptr->data;
-
- *min = 0;
- *max = max_ii(0, BLI_listbase_count(&rd->layers) - 1);
-}
-
-static PointerRNA rna_RenderSettings_active_layer_get(PointerRNA *ptr)
-{
- RenderData *rd = (RenderData *)ptr->data;
- SceneRenderLayer *srl = BLI_findlink(&rd->layers, rd->actlay);
-
- return rna_pointer_inherit_refine(ptr, &RNA_SceneRenderLayer, srl);
-}
-
-static void rna_RenderSettings_active_layer_set(PointerRNA *ptr, PointerRNA value)
-{
- RenderData *rd = (RenderData *)ptr->data;
- SceneRenderLayer *srl = (SceneRenderLayer *)value.data;
- const int index = BLI_findindex(&rd->layers, srl);
- if (index != -1) rd->actlay = index;
-}
-
-static SceneRenderLayer *rna_RenderLayer_new(ID *id, RenderData *UNUSED(rd), const char *name)
-{
- Scene *scene = (Scene *)id;
- SceneRenderLayer *srl = BKE_scene_add_render_layer(scene, name);
-
- DAG_id_tag_update(&scene->id, 0);
- WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- return srl;
-}
-
-static void rna_RenderLayer_remove(
- ID *id, RenderData *UNUSED(rd), Main *bmain, ReportList *reports, PointerRNA *srl_ptr)
-{
- SceneRenderLayer *srl = srl_ptr->data;
- Scene *scene = (Scene *)id;
-
- if (!BKE_scene_remove_render_layer(bmain, scene, srl)) {
- BKE_reportf(reports, RPT_ERROR, "Render layer '%s' could not be removed from scene '%s'",
- srl->name, scene->id.name + 2);
- return;
- }
-
- RNA_POINTER_INVALIDATE(srl_ptr);
-
- DAG_id_tag_update(&scene->id, 0);
- WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
-}
-
static int rna_RenderSettings_active_view_index_get(PointerRNA *ptr)
{
RenderData *rd = (RenderData *)ptr->data;
@@ -1465,13 +1359,29 @@ static void rna_RenderView_remove(
WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
}
+static void rna_RenderSettings_views_format_set(PointerRNA *ptr, int value)
+{
+ RenderData *rd = (RenderData *)ptr->data;
+
+ if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW &&
+ value == SCE_VIEWS_FORMAT_STEREO_3D)
+ {
+ /* make sure the actview is visible */
+ if (rd->actview > 1) rd->actview = 1;
+ }
+
+ rd->views_format = value;
+}
+
static void rna_RenderSettings_engine_set(PointerRNA *ptr, int value)
{
RenderData *rd = (RenderData *)ptr->data;
RenderEngineType *type = BLI_findlink(&R_engines, value);
- if (type)
+ if (type) {
BLI_strncpy_utf8(rd->engine, type->idname, sizeof(rd->engine));
+ DEG_id_tag_update(ptr->id.data, DEG_TAG_COPY_ON_WRITE);
+ }
}
static const EnumPropertyItem *rna_RenderSettings_engine_itemf(
@@ -1513,73 +1423,71 @@ static void rna_RenderSettings_engine_update(Main *bmain, Scene *UNUSED(unused),
ED_render_engine_changed(bmain);
}
-static void rna_Scene_glsl_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+static int rna_RenderSettings_multiple_engines_get(PointerRNA *UNUSED(ptr))
{
- Scene *scene = (Scene *)ptr->id.data;
+ return (BLI_listbase_count(&R_engines) > 1);
+}
- DAG_id_tag_update(&scene->id, 0);
+static int rna_RenderSettings_use_spherical_stereo_get(PointerRNA *ptr)
+{
+ Scene *scene = (Scene *)ptr->id.data;
+ return BKE_scene_use_spherical_stereo(scene);
}
-static void rna_Scene_freestyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+void rna_Scene_glsl_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Scene *scene = (Scene *)ptr->id.data;
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
}
-static void rna_Scene_use_view_map_cache_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
+static void rna_Scene_world_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
-#ifdef WITH_FREESTYLE
- FRS_free_view_map_cache();
-#endif
+ Scene *sc = (Scene *)ptr->id.data;
+
+ rna_Scene_glsl_update(bmain, scene, ptr);
+ WM_main_add_notifier(NC_WORLD | ND_WORLD, &sc->id);
}
-static IDProperty *rna_SceneRenderLayer_idprops(PointerRNA *ptr, bool create)
+void rna_Scene_freestyle_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
- SceneRenderLayer *srl = (SceneRenderLayer *)ptr->data;
+ Scene *scene = (Scene *)ptr->id.data;
- if (create && !srl->prop) {
- IDPropertyTemplate val = {0};
- srl->prop = IDP_New(IDP_GROUP, &val, "SceneRenderLayer ID properties");
- }
+ DEG_id_tag_update(&scene->id, 0);
+}
- return srl->prop;
+void rna_Scene_use_view_map_cache_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
+{
+#ifdef WITH_FREESTYLE
+ FRS_free_view_map_cache();
+#endif
}
-static void rna_SceneRenderLayer_name_set(PointerRNA *ptr, const char *value)
+void rna_ViewLayer_name_set(PointerRNA *ptr, const char *value)
{
Scene *scene = (Scene *)ptr->id.data;
- SceneRenderLayer *rl = (SceneRenderLayer *)ptr->data;
- char oldname[sizeof(rl->name)];
+ ViewLayer *view_layer = (ViewLayer *)ptr->data;
+ char oldname[sizeof(view_layer->name)];
- BLI_strncpy(oldname, rl->name, sizeof(rl->name));
+ BLI_strncpy(oldname, view_layer->name, sizeof(view_layer->name));
- BLI_strncpy_utf8(rl->name, value, sizeof(rl->name));
- BLI_uniquename(&scene->r.layers, rl, DATA_("RenderLayer"), '.', offsetof(SceneRenderLayer, name), sizeof(rl->name));
+ BLI_strncpy_utf8(view_layer->name, value, sizeof(view_layer->name));
+ BLI_uniquename(&scene->view_layers, view_layer, DATA_("ViewLayer"), '.', offsetof(ViewLayer, name), sizeof(view_layer->name));
if (scene->nodetree) {
bNode *node;
- int index = BLI_findindex(&scene->r.layers, rl);
+ int index = BLI_findindex(&scene->view_layers, view_layer);
for (node = scene->nodetree->nodes.first; node; node = node->next) {
if (node->type == CMP_NODE_R_LAYERS && node->id == NULL) {
if (node->custom1 == index)
- BLI_strncpy(node->name, rl->name, NODE_MAXSTR);
+ BLI_strncpy(node->name, view_layer->name, NODE_MAXSTR);
}
}
}
/* fix all the animation data which may link to this */
- BKE_animdata_fix_paths_rename_all(NULL, "render.layers", oldname, rl->name);
-}
-
-static char *rna_SceneRenderLayer_path(PointerRNA *ptr)
-{
- SceneRenderLayer *srl = (SceneRenderLayer *)ptr->data;
- char name_esc[sizeof(srl->name) * 2];
-
- BLI_strescape(name_esc, srl->name, sizeof(name_esc));
- return BLI_sprintfN("render.layers[\"%s\"]", name_esc);
+ BKE_animdata_fix_paths_rename_all(NULL, "view_layers", oldname, view_layer->name);
}
static void rna_SceneRenderView_name_set(PointerRNA *ptr, const char *value)
@@ -1590,62 +1498,7 @@ static void rna_SceneRenderView_name_set(PointerRNA *ptr, const char *value)
BLI_uniquename(&scene->r.views, rv, DATA_("RenderView"), '.', offsetof(SceneRenderView, name), sizeof(rv->name));
}
-static char *rna_SceneRenderView_path(PointerRNA *ptr)
-{
- SceneRenderView *srv = (SceneRenderView *)ptr->data;
- return BLI_sprintfN("render.views[\"%s\"]", srv->name);
-}
-
-static void rna_RenderSettings_views_format_set(PointerRNA *ptr, int value)
-{
- RenderData *rd = (RenderData *)ptr->data;
-
- if (rd->views_format == SCE_VIEWS_FORMAT_MULTIVIEW &&
- value == SCE_VIEWS_FORMAT_STEREO_3D)
- {
- /* make sure the actview is visible */
- if (rd->actview > 1) rd->actview = 1;
- }
-
- rd->views_format = value;
-}
-
-static int rna_RenderSettings_multiple_engines_get(PointerRNA *UNUSED(ptr))
-{
- return (BLI_listbase_count(&R_engines) > 1);
-}
-
-static int rna_RenderSettings_use_shading_nodes_get(PointerRNA *ptr)
-{
- Scene *scene = (Scene *)ptr->id.data;
- return BKE_scene_use_new_shading_nodes(scene);
-}
-
-static int rna_RenderSettings_use_spherical_stereo_get(PointerRNA *ptr)
-{
- Scene *scene = (Scene *)ptr->id.data;
- return BKE_scene_use_spherical_stereo(scene);
-}
-
-static int rna_RenderSettings_use_game_engine_get(PointerRNA *ptr)
-{
- RenderData *rd = (RenderData *)ptr->data;
- RenderEngineType *type;
-
- for (type = R_engines.first; type; type = type->next)
- if (STREQ(type->idname, rd->engine))
- return (type->flag & RE_GAME) != 0;
-
- return 0;
-}
-
-static void rna_SceneRenderLayer_layer_set(PointerRNA *ptr, const int *values)
-{
- SceneRenderLayer *rl = (SceneRenderLayer *)ptr->data;
- rl->lay = ED_view3d_scene_layer_set(rl->lay, values, NULL);
-}
-
-static void rna_SceneRenderLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr)
+void rna_ViewLayer_pass_update(Main *bmain, Scene *activescene, PointerRNA *ptr)
{
Scene *scene = (Scene *)ptr->id.data;
@@ -1655,11 +1508,10 @@ static void rna_SceneRenderLayer_pass_update(Main *bmain, Scene *activescene, Po
rna_Scene_glsl_update(bmain, activescene, ptr);
}
-static void rna_SceneRenderLayer_update_render_passes(ID *id)
+static char *rna_SceneRenderView_path(PointerRNA *ptr)
{
- Scene *scene = (Scene *)id;
- if (scene->nodetree)
- ntreeCompositUpdateRLayers(scene->nodetree);
+ SceneRenderView *srv = (SceneRenderView *)ptr->data;
+ return BLI_sprintfN("render.views[\"%s\"]", srv->name);
}
static void rna_Scene_use_nodes_update(bContext *C, PointerRNA *ptr)
@@ -1673,43 +1525,52 @@ static void rna_Scene_use_nodes_update(bContext *C, PointerRNA *ptr)
static void rna_Physics_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Scene *scene = (Scene *)ptr->id.data;
- Base *base;
-
- for (base = scene->base.first; base; base = base->next)
- BKE_ptcache_object_reset(scene, base->object, PTCACHE_RESET_DEPSGRAPH);
+ FOREACH_SCENE_OBJECT_BEGIN(scene, ob)
+ {
+ BKE_ptcache_object_reset(scene, ob, PTCACHE_RESET_DEPSGRAPH);
+ }
+ FOREACH_SCENE_OBJECT_END;
}
static void rna_Scene_editmesh_select_mode_set(PointerRNA *ptr, const int *value)
{
- Scene *scene = (Scene *)ptr->id.data;
ToolSettings *ts = (ToolSettings *)ptr->data;
int flag = (value[0] ? SCE_SELECT_VERTEX : 0) | (value[1] ? SCE_SELECT_EDGE : 0) | (value[2] ? SCE_SELECT_FACE : 0);
if (flag) {
ts->selectmode = flag;
- if (scene->basact) {
- Mesh *me = BKE_mesh_from_object(scene->basact->object);
- if (me && me->edit_btmesh && me->edit_btmesh->selectmode != flag) {
- me->edit_btmesh->selectmode = flag;
- EDBM_selectmode_set(me->edit_btmesh);
+ /* Update select mode in all the workspaces in mesh edit mode. */
+ wmWindowManager *wm = G.main->wm.first;
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+
+ if (view_layer && view_layer->basact) {
+ Mesh *me = BKE_mesh_from_object(view_layer->basact->object);
+ if (me && me->edit_btmesh && me->edit_btmesh->selectmode != flag) {
+ me->edit_btmesh->selectmode = flag;
+ EDBM_selectmode_set(me->edit_btmesh);
+ }
}
}
}
}
-static void rna_Scene_editmesh_select_mode_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_Scene_editmesh_select_mode_update(bContext *C, PointerRNA *UNUSED(ptr))
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Mesh *me = NULL;
- if (scene->basact) {
- me = BKE_mesh_from_object(scene->basact->object);
+ if (view_layer->basact) {
+ me = BKE_mesh_from_object(view_layer->basact->object);
if (me && me->edit_btmesh == NULL)
me = NULL;
}
- WM_main_add_notifier(NC_GEOM | ND_SELECT, me);
- WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL);
+ if (me) {
+ DEG_id_tag_update(&me->id, DEG_TAG_SELECT_UPDATE);
+ WM_main_add_notifier(NC_SCENE | ND_TOOLSETTINGS, NULL);
+ }
}
static void object_simplify_update(Object *ob)
@@ -1725,7 +1586,7 @@ static void object_simplify_update(Object *ob)
for (md = ob->modifiers.first; md; md = md->next) {
if (ELEM(md->type, eModifierType_Subsurf, eModifierType_Multires, eModifierType_ParticleSystem)) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
}
@@ -1740,33 +1601,39 @@ static void object_simplify_update(Object *ob)
}
}
-static void rna_Scene_use_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_Scene_use_simplify_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Scene *sce = ptr->id.data;
Scene *sce_iter;
Base *base;
- BKE_main_id_tag_listbase(&bmain->object, LIB_TAG_DOIT, true);
- for (SETLOOPER(sce, sce_iter, base))
+ FOREACH_SCENE_OBJECT_BEGIN(sce, ob)
+ {
+ object_simplify_update(ob);
+ }
+ FOREACH_SCENE_OBJECT_END;
+
+ for (SETLOOPER_SET_ONLY(sce, sce_iter, base)) {
object_simplify_update(base->object);
+ }
WM_main_add_notifier(NC_GEOM | ND_DATA, NULL);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&sce->id, 0);
}
-static void rna_Scene_simplify_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
+static void rna_Scene_simplify_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
Scene *sce = ptr->id.data;
if (sce->r.mode & R_SIMPLIFY)
- rna_Scene_use_simplify_update(bmain, sce, ptr);
+ rna_Scene_use_simplify_update(bmain, scene, ptr);
}
static void rna_SceneRenderData_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Scene *sce = ptr->id.data;
- DAG_id_tag_update(&sce->id, 0);
+ DEG_id_tag_update(&sce->id, 0);
}
static void rna_Scene_use_persistent_data_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
@@ -1820,26 +1687,7 @@ static void rna_Scene_sync_mode_set(PointerRNA *ptr, int value)
}
}
-static int rna_GameSettings_auto_start_get(PointerRNA *UNUSED(ptr))
-{
- return (G.fileflags & G_FILE_AUTOPLAY) != 0;
-}
-
-static void rna_GameSettings_auto_start_set(PointerRNA *UNUSED(ptr), int value)
-{
- if (value)
- G.fileflags |= G_FILE_AUTOPLAY;
- else
- G.fileflags &= ~G_FILE_AUTOPLAY;
-}
-
-static void rna_GameSettings_exit_key_set(PointerRNA *ptr, int value)
-{
- GameData *gm = (GameData *)ptr->data;
- if (ISKEYBOARD(value))
- gm->exitkey = value;
-}
static TimeMarker *rna_TimeLine_add(Scene *scene, const char name[], int frame)
{
@@ -1896,9 +1744,11 @@ static KeyingSet *rna_Scene_keying_set_new(Scene *sce, ReportList *reports, cons
}
}
-static void rna_UnifiedPaintSettings_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_UnifiedPaintSettings_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Brush *br = BKE_paint_brush(BKE_paint_get_active(scene));
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Brush *br = BKE_paint_brush(BKE_paint_get_active(scene, view_layer));
WM_main_add_notifier(NC_BRUSH | NA_EDITED, br);
}
@@ -1921,11 +1771,11 @@ static void rna_UnifiedPaintSettings_unprojected_radius_set(PointerRNA *ptr, flo
ups->unprojected_radius = value;
}
-static void rna_UnifiedPaintSettings_radius_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_UnifiedPaintSettings_radius_update(bContext *C, PointerRNA *ptr)
{
/* changing the unified size should invalidate the overlay but also update the brush */
BKE_paint_invalidate_overlay_all();
- rna_UnifiedPaintSettings_update(bmain, scene, ptr);
+ rna_UnifiedPaintSettings_update(C, ptr);
}
static char *rna_UnifiedPaintSettings_path(PointerRNA *UNUSED(ptr))
@@ -1939,18 +1789,19 @@ static char *rna_CurvePaintSettings_path(PointerRNA *UNUSED(ptr))
}
/* generic function to recalc geometry */
-static void rna_EditMesh_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_EditMesh_update(bContext *C, PointerRNA *UNUSED(ptr))
{
+ ViewLayer *view_layer = CTX_data_view_layer(C);
Mesh *me = NULL;
- if (scene->basact) {
- me = BKE_mesh_from_object(scene->basact->object);
+ if (view_layer->basact) {
+ me = BKE_mesh_from_object(view_layer->basact->object);
if (me && me->edit_btmesh == NULL)
me = NULL;
}
if (me) {
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&me->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_GEOM | ND_DATA, me);
}
}
@@ -1965,11 +1816,13 @@ static char *rna_MeshStatVis_path(PointerRNA *UNUSED(ptr))
* is not for general use and only for the few cases where changing scene
* settings and NOT for general purpose updates, possibly this should be
* given its own notifier. */
-static void rna_Scene_update_active_object_data(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_Scene_update_active_object_data(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+
if (ob) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, &ob->id);
}
}
@@ -1980,7 +1833,7 @@ static void rna_SceneCamera_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Po
Object *camera = scene->camera;
if (camera)
- DAG_id_tag_update(&camera->id, 0);
+ DEG_id_tag_update(&camera->id, 0);
}
static void rna_SceneSequencer_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
@@ -1994,14 +1847,14 @@ static char *rna_ToolSettings_path(PointerRNA *UNUSED(ptr))
return BLI_strdup("tool_settings");
}
-static PointerRNA rna_FreestyleLineSet_linestyle_get(PointerRNA *ptr)
+PointerRNA rna_FreestyleLineSet_linestyle_get(PointerRNA *ptr)
{
FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data;
return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineStyle, lineset->linestyle);
}
-static void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value)
+void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value)
{
FreestyleLineSet *lineset = (FreestyleLineSet *)ptr->data;
@@ -2011,19 +1864,19 @@ static void rna_FreestyleLineSet_linestyle_set(PointerRNA *ptr, PointerRNA value
id_us_plus(&lineset->linestyle->id);
}
-static FreestyleLineSet *rna_FreestyleSettings_lineset_add(
+FreestyleLineSet *rna_FreestyleSettings_lineset_add(
ID *id, FreestyleSettings *config, Main *bmain, const char *name)
{
Scene *scene = (Scene *)id;
FreestyleLineSet *lineset = BKE_freestyle_lineset_add(bmain, (FreestyleConfig *)config, name);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
return lineset;
}
-static void rna_FreestyleSettings_lineset_remove(
+void rna_FreestyleSettings_lineset_remove(
ID *id, FreestyleSettings *config, ReportList *reports, PointerRNA *lineset_ptr)
{
FreestyleLineSet *lineset = lineset_ptr->data;
@@ -2036,18 +1889,18 @@ static void rna_FreestyleSettings_lineset_remove(
RNA_POINTER_INVALIDATE(lineset_ptr);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
}
-static PointerRNA rna_FreestyleSettings_active_lineset_get(PointerRNA *ptr)
+PointerRNA rna_FreestyleSettings_active_lineset_get(PointerRNA *ptr)
{
FreestyleConfig *config = (FreestyleConfig *)ptr->data;
FreestyleLineSet *lineset = BKE_freestyle_lineset_get_active(config);
return rna_pointer_inherit_refine(ptr, &RNA_FreestyleLineSet, lineset);
}
-static void rna_FreestyleSettings_active_lineset_index_range(
+void rna_FreestyleSettings_active_lineset_index_range(
PointerRNA *ptr, int *min, int *max, int *UNUSED(softmin), int *UNUSED(softmax))
{
FreestyleConfig *config = (FreestyleConfig *)ptr->data;
@@ -2056,30 +1909,30 @@ static void rna_FreestyleSettings_active_lineset_index_range(
*max = max_ii(0, BLI_listbase_count(&config->linesets) - 1);
}
-static int rna_FreestyleSettings_active_lineset_index_get(PointerRNA *ptr)
+int rna_FreestyleSettings_active_lineset_index_get(PointerRNA *ptr)
{
FreestyleConfig *config = (FreestyleConfig *)ptr->data;
return BKE_freestyle_lineset_get_active_index(config);
}
-static void rna_FreestyleSettings_active_lineset_index_set(PointerRNA *ptr, int value)
+void rna_FreestyleSettings_active_lineset_index_set(PointerRNA *ptr, int value)
{
FreestyleConfig *config = (FreestyleConfig *)ptr->data;
BKE_freestyle_lineset_set_active_index(config, value);
}
-static FreestyleModuleConfig *rna_FreestyleSettings_module_add(ID *id, FreestyleSettings *config)
+FreestyleModuleConfig *rna_FreestyleSettings_module_add(ID *id, FreestyleSettings *config)
{
Scene *scene = (Scene *)id;
FreestyleModuleConfig *module = BKE_freestyle_module_add((FreestyleConfig *)config);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
return module;
}
-static void rna_FreestyleSettings_module_remove(
+void rna_FreestyleSettings_module_remove(
ID *id, FreestyleSettings *config, ReportList *reports, PointerRNA *module_ptr)
{
Scene *scene = (Scene *)id;
@@ -2095,7 +1948,7 @@ static void rna_FreestyleSettings_module_remove(
RNA_POINTER_INVALIDATE(module_ptr);
- DAG_id_tag_update(&scene->id, 0);
+ DEG_id_tag_update(&scene->id, 0);
WM_main_add_notifier(NC_SCENE | ND_RENDER_OPTIONS, NULL);
}
@@ -2114,13 +1967,6 @@ char *rna_GPUDOF_path(PointerRNA *ptr)
return BLI_strdup("");
}
-static void rna_GPUFXSettings_fx_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
-{
- GPUFXSettings *fx_settings = ptr->data;
-
- BKE_screen_gpu_fx_validate(fx_settings);
-}
-
static void rna_GPUDOFSettings_blades_set(PointerRNA *ptr, const int value)
{
GPUDOFSettings *dofsettings = (GPUDOFSettings *)ptr->data;
@@ -2164,9 +2010,98 @@ static void rna_Stereo3dFormat_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
static int rna_gpu_is_hq_supported_get(PointerRNA *UNUSED(ptr))
{
- return GPU_instanced_drawing_support() && GPU_geometry_shader_support();
+ return true;
}
+static ViewLayer *rna_ViewLayer_new(
+ ID *id, Scene *UNUSED(sce), Main *bmain, const char *name)
+{
+ Scene *scene = (Scene *)id;
+ ViewLayer *view_layer = BKE_view_layer_add(scene, name);
+
+ DEG_id_tag_update(&scene->id, 0);
+ DEG_relations_tag_update(bmain);
+ WM_main_add_notifier(NC_SCENE | ND_LAYER, NULL);
+
+ return view_layer;
+}
+
+static void rna_ViewLayer_remove(
+ ID *id, Scene *UNUSED(sce), Main *bmain, ReportList *reports, PointerRNA *sl_ptr)
+{
+ Scene *scene = (Scene *)id;
+ ViewLayer *view_layer = sl_ptr->data;
+
+ if (ED_scene_view_layer_delete(bmain, scene, view_layer, reports)) {
+ RNA_POINTER_INVALIDATE(sl_ptr);
+ }
+}
+
+static int rna_Scene_transform_orientation_get(PointerRNA *ptr)
+{
+ Scene *scene = ptr->data;
+ /* convert to enum value */
+ return (scene->orientation_type == V3D_MANIP_CUSTOM) ?
+ (scene->orientation_type + scene->orientation_index_custom) : scene->orientation_type;
+}
+
+void rna_Scene_transform_orientation_set(PointerRNA *ptr, int value)
+{
+ Scene *scene = ptr->data;
+ BIF_selectTransformOrientationValue(scene, value);
+}
+
+static PointerRNA rna_Scene_current_orientation_get(PointerRNA *ptr)
+{
+ Scene *scene = ptr->data;
+ TransformOrientation *orientation;
+
+ if (scene->orientation_type < V3D_MANIP_CUSTOM) {
+ orientation = NULL;
+ }
+ else {
+ orientation = BKE_scene_transform_orientation_find(scene, scene->orientation_index_custom);
+ }
+
+ return rna_pointer_inherit_refine(ptr, &RNA_TransformOrientation, orientation);
+}
+
+const EnumPropertyItem *rna_TransformOrientation_itemf(
+ bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
+{
+ EnumPropertyItem tmp = {0, "", 0, "", ""};
+ EnumPropertyItem *item = NULL;
+ int i = V3D_MANIP_CUSTOM, totitem = 0;
+
+ RNA_enum_items_add(&item, &totitem, transform_orientation_items);
+
+ Scene *scene;
+ if (ptr->type == &RNA_Scene) {
+ scene = ptr->data;
+ }
+ else {
+ scene = CTX_data_scene(C);
+ }
+ const ListBase *transform_orientations = scene ? &scene->transform_spaces : NULL;
+
+ if (transform_orientations && (BLI_listbase_is_empty(transform_orientations) == false)) {
+ RNA_enum_item_add_separator(&item, &totitem);
+
+ for (TransformOrientation *ts = transform_orientations->first; ts; ts = ts->next) {
+ tmp.identifier = ts->name;
+ tmp.name = ts->name;
+ tmp.value = i++;
+ RNA_enum_item_add(&item, &totitem, &tmp);
+ }
+ }
+
+ RNA_enum_item_end(&item, &totitem);
+ *r_free = true;
+
+ return item;
+}
+
+
#else
/* Grease Pencil Interpolation tool settings */
@@ -2476,22 +2411,6 @@ static void rna_def_tool_settings(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem retarget_roll_items[] = {
- {SK_RETARGET_ROLL_NONE, "NONE", 0, "None", "Don't adjust roll"},
- {SK_RETARGET_ROLL_VIEW, "VIEW", 0, "View", "Roll bones to face the view"},
- {SK_RETARGET_ROLL_JOINT, "JOINT", 0, "Joint", "Roll bone to original joint plane offset"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem sketch_convert_items[] = {
- {SK_CONVERT_CUT_FIXED, "FIXED", 0, "Fixed", "Subdivide stroke in fixed number of bones"},
- {SK_CONVERT_CUT_LENGTH, "LENGTH", 0, "Length", "Subdivide stroke in bones of specific length"},
- {SK_CONVERT_CUT_ADAPTATIVE, "ADAPTIVE", 0, "Adaptive",
- "Subdivide stroke adaptively, with more subdivision in curvier parts"},
- {SK_CONVERT_RETARGET, "RETARGET", 0, "Retarget", "Retarget template bone chain to stroke"},
- {0, NULL, 0, NULL, NULL}
- };
-
static const EnumPropertyItem edge_tag_items[] = {
{EDGE_MODE_SELECT, "SELECT", 0, "Select", ""},
{EDGE_MODE_TAG_SEAM, "SEAM", 0, "Tag Seam", ""},
@@ -2544,6 +2463,7 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Sculpt", "");
prop = RNA_def_property(srna, "use_auto_normalize", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_boolean_sdna(prop, NULL, "auto_normalize", 1);
RNA_def_property_ui_text(prop, "WPaint Auto-Normalize",
"Ensure all bone-deforming vertex groups add up "
@@ -2551,6 +2471,7 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data");
prop = RNA_def_property(srna, "use_multipaint", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_boolean_sdna(prop, NULL, "multipaint", 1);
RNA_def_property_ui_text(prop, "WPaint Multi-Paint",
"Paint across the weights of all selected bones, "
@@ -2558,12 +2479,14 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data");
prop = RNA_def_property(srna, "vertex_group_user", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_enum_sdna(prop, NULL, "weightuser");
RNA_def_property_enum_items(prop, draw_groupuser_items);
RNA_def_property_ui_text(prop, "Mask Non-Group Vertices", "Display unweighted vertices");
RNA_def_property_update(prop, 0, "rna_Scene_update_active_object_data");
prop = RNA_def_property(srna, "vertex_group_subset", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_enum_sdna(prop, NULL, "vgroupsubset");
RNA_def_property_enum_items(prop, vertex_group_select_items);
RNA_def_property_ui_text(prop, "Subset", "Filter Vertex groups for Display");
@@ -2659,13 +2582,6 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Proportional Size", "Display size for proportional editing circle");
RNA_def_property_range(prop, 0.00001, 5000.0);
- prop = RNA_def_property(srna, "normal_size", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "normalsize");
- RNA_def_property_ui_text(prop, "Normal Size", "Display size for normals in the 3D view");
- RNA_def_property_range(prop, 0.00001, 1000.0);
- RNA_def_property_ui_range(prop, 0.01, 10.0, 10.0, 2);
- RNA_def_property_update(prop, NC_GEOM | ND_DATA, NULL);
-
prop = RNA_def_property(srna, "double_threshold", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, NULL, "doublimit");
RNA_def_property_ui_text(prop, "Double Threshold", "Limit for removing duplicates and 'Auto Merge'");
@@ -2874,6 +2790,7 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_array(prop, 3);
RNA_def_property_boolean_funcs(prop, NULL, "rna_Scene_editmesh_select_mode_set");
RNA_def_property_ui_text(prop, "Mesh Selection Mode", "Which mesh elements selection works on");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_Scene_editmesh_select_mode_update");
prop = RNA_def_property(srna, "vertex_group_weight", PROP_FLOAT, PROP_FACTOR);
@@ -2890,72 +2807,6 @@ static void rna_def_tool_settings(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "edge_mode_live_unwrap", 1);
RNA_def_property_ui_text(prop, "Live Unwrap", "Changing edges seam re-calculates UV unwrap");
- /* etch-a-ton */
- prop = RNA_def_property(srna, "use_bone_sketching", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bone_sketching", BONE_SKETCHING);
- RNA_def_property_ui_text(prop, "Use Bone Sketching", "Use sketching to create and edit bones");
-/* RNA_def_property_ui_icon(prop, ICON_EDIT, 0); */
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "use_etch_quick", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bone_sketching", BONE_SKETCHING_QUICK);
- RNA_def_property_ui_text(prop, "Quick Sketching", "Automatically convert and delete on stroke end");
-
- prop = RNA_def_property(srna, "use_etch_overdraw", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bone_sketching", BONE_SKETCHING_ADJUST);
- RNA_def_property_ui_text(prop, "Overdraw Sketching", "Adjust strokes by drawing near them");
-
- prop = RNA_def_property(srna, "use_etch_autoname", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "skgen_retarget_options", SK_RETARGET_AUTONAME);
- RNA_def_property_ui_text(prop, "Autoname Bones",
- "Automatically generate values to replace &N and &S suffix placeholders in template names");
-
- prop = RNA_def_property(srna, "etch_number", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "skgen_num_string");
- RNA_def_property_ui_text(prop, "Number", "Text to replace &N with (e.g. 'Finger.&N' -> 'Finger.1' or 'Finger.One')");
-
- prop = RNA_def_property(srna, "etch_side", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "skgen_num_string");
- RNA_def_property_ui_text(prop, "Side", "Text to replace &S with (e.g. 'Arm.&S' -> 'Arm.R' or 'Arm.Right')");
-
- prop = RNA_def_property(srna, "etch_template", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "skgen_template");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_funcs(prop, NULL, "rna_Scene_skgen_etch_template_set", NULL, NULL);
- RNA_def_property_ui_text(prop, "Template", "Template armature that will be retargeted to the stroke");
-
- prop = RNA_def_property(srna, "etch_subdivision_number", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "skgen_subdivision_number");
- RNA_def_property_range(prop, 1, 255);
- RNA_def_property_ui_text(prop, "Subdivisions", "Number of bones in the subdivided stroke");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "etch_adaptive_limit", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "skgen_correlation_limit");
- RNA_def_property_range(prop, 0.00001, 1.0);
- RNA_def_property_ui_range(prop, 0.01, 1.0, 0.01, 2);
- RNA_def_property_ui_text(prop, "Limit", "Correlation threshold for number of bones in the subdivided stroke");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "etch_length_limit", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "skgen_length_limit");
- RNA_def_property_range(prop, 0.00001, 100000.0);
- RNA_def_property_ui_range(prop, 0.001, 100.0, 0.1, 3);
- RNA_def_property_ui_text(prop, "Length", "Maximum length of the subdivided bones");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "etch_roll_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "skgen_retarget_roll");
- RNA_def_property_enum_items(prop, retarget_roll_items);
- RNA_def_property_ui_text(prop, "Retarget roll mode", "Method used to adjust the roll of bones when retargeting");
-
- prop = RNA_def_property(srna, "etch_convert_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "bone_sketching_convert");
- RNA_def_property_enum_items(prop, sketch_convert_items);
- RNA_def_property_ui_text(prop, "Stroke conversion method", "Method used to convert stroke to bones");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
/* Unified Paint Settings */
prop = RNA_def_property(srna, "unified_paint_settings", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
@@ -3009,6 +2860,7 @@ static void rna_def_unified_paint_settings(BlenderRNA *brna)
* from the active brush */
prop = RNA_def_property(srna, "size", PROP_INT, PROP_PIXEL);
RNA_def_property_int_funcs(prop, NULL, "rna_UnifiedPaintSettings_size_set", NULL);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_range(prop, 1, MAX_BRUSH_PIXEL_RADIUS * 10);
RNA_def_property_ui_range(prop, 1, MAX_BRUSH_PIXEL_RADIUS, 1, -1);
RNA_def_property_ui_text(prop, "Radius", "Radius of the brush");
@@ -3016,6 +2868,7 @@ static void rna_def_unified_paint_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "unprojected_radius", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_funcs(prop, NULL, "rna_UnifiedPaintSettings_unprojected_radius_set", NULL);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_range(prop, 0.001, FLT_MAX);
RNA_def_property_ui_range(prop, 0.001, 1, 0, -1);
RNA_def_property_ui_text(prop, "Unprojected Radius", "Radius of brush in Blender units");
@@ -3023,6 +2876,7 @@ static void rna_def_unified_paint_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "strength", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "alpha");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_float_default(prop, 0.5f);
RNA_def_property_range(prop, 0.0f, 10.0f);
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3);
@@ -3031,6 +2885,7 @@ static void rna_def_unified_paint_settings(BlenderRNA *brna)
prop = RNA_def_property(srna, "weight", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_float_sdna(prop, NULL, "weight");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_float_default(prop, 0.5f);
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_range(prop, 0.0f, 1.0f, 0.001, 3);
@@ -3038,12 +2893,14 @@ static void rna_def_unified_paint_settings(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_UnifiedPaintSettings_update");
prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_range(prop, 0.0, 1.0);
RNA_def_property_float_sdna(prop, NULL, "rgb");
RNA_def_property_ui_text(prop, "Color", "");
RNA_def_property_update(prop, 0, "rna_UnifiedPaintSettings_update");
prop = RNA_def_property(srna, "secondary_color", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_range(prop, 0.0, 1.0);
RNA_def_property_float_sdna(prop, NULL, "secondary_rgb");
RNA_def_property_ui_text(prop, "Secondary Color", "");
@@ -3185,6 +3042,7 @@ static void rna_def_statvis(BlenderRNA *brna)
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_items(prop, stat_type);
RNA_def_property_ui_text(prop, "Type", "Type of data to visualize/check");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
@@ -3195,6 +3053,7 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
RNA_def_property_ui_range(prop, 0.0f, DEG2RADF(180.0f), 0.001, 3);
RNA_def_property_ui_text(prop, "Overhang Min", "Minimum angle to display");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
prop = RNA_def_property(srna, "overhang_max", PROP_FLOAT, PROP_ANGLE);
@@ -3203,12 +3062,14 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
RNA_def_property_ui_range(prop, 0.0f, DEG2RADF(180.0f), 10, 3);
RNA_def_property_ui_text(prop, "Overhang Max", "Maximum angle to display");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
prop = RNA_def_property(srna, "overhang_axis", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "overhang_axis");
RNA_def_property_enum_items(prop, rna_enum_object_axis_items);
RNA_def_property_ui_text(prop, "Axis", "");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
@@ -3219,6 +3080,7 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, 1000.0);
RNA_def_property_ui_range(prop, 0.0f, 100.0, 0.001, 3);
RNA_def_property_ui_text(prop, "Thickness Min", "Minimum for measuring thickness");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
prop = RNA_def_property(srna, "thickness_max", PROP_FLOAT, PROP_DISTANCE);
@@ -3227,12 +3089,14 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, 1000.0);
RNA_def_property_ui_range(prop, 0.0f, 100.0, 0.001, 3);
RNA_def_property_ui_text(prop, "Thickness Max", "Maximum for measuring thickness");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
prop = RNA_def_property(srna, "thickness_samples", PROP_INT, PROP_UNSIGNED);
RNA_def_property_int_sdna(prop, NULL, "thickness_samples");
RNA_def_property_range(prop, 1, 32);
RNA_def_property_ui_text(prop, "Samples", "Number of samples to test per face");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
/* distort */
@@ -3242,6 +3106,7 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
RNA_def_property_ui_range(prop, 0.0f, DEG2RADF(180.0f), 10, 3);
RNA_def_property_ui_text(prop, "Distort Min", "Minimum angle to display");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
prop = RNA_def_property(srna, "distort_max", PROP_FLOAT, PROP_ANGLE);
@@ -3250,6 +3115,7 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, DEG2RADF(180.0f));
RNA_def_property_ui_range(prop, 0.0f, DEG2RADF(180.0f), 10, 3);
RNA_def_property_ui_text(prop, "Distort Max", "Maximum angle to display");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
/* sharp */
@@ -3259,6 +3125,7 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, -DEG2RADF(180.0f), DEG2RADF(180.0f));
RNA_def_property_ui_range(prop, -DEG2RADF(180.0f), DEG2RADF(180.0f), 10, 3);
RNA_def_property_ui_text(prop, "Distort Min", "Minimum angle to display");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
prop = RNA_def_property(srna, "sharp_max", PROP_FLOAT, PROP_ANGLE);
@@ -3267,6 +3134,7 @@ static void rna_def_statvis(BlenderRNA *brna)
RNA_def_property_range(prop, -DEG2RADF(180.0f), DEG2RADF(180.0f));
RNA_def_property_ui_range(prop, -DEG2RADF(180.0f), DEG2RADF(180.0f), 10, 3);
RNA_def_property_ui_text(prop, "Distort Max", "Maximum angle to display");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, 0, "rna_EditMesh_update");
}
@@ -3314,67 +3182,19 @@ static void rna_def_unit_settings(BlenderRNA *brna)
RNA_def_property_update(prop, NC_WINDOW, NULL);
}
-void rna_def_render_layer_common(StructRNA *srna, int scene)
+void rna_def_view_layer_common(StructRNA *srna, int scene)
{
PropertyRNA *prop;
prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
- if (scene) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_SceneRenderLayer_name_set");
+ if (scene) RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ViewLayer_name_set");
else RNA_def_property_string_sdna(prop, NULL, "name");
RNA_def_property_ui_text(prop, "Name", "Render layer name");
RNA_def_struct_name_property(srna, prop);
if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- prop = RNA_def_property(srna, "material_override", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "mat_override");
- RNA_def_property_struct_type(prop, "Material");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Material Override",
- "Material to override all other materials in this render layer");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "light_override", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "light_override");
- RNA_def_property_struct_type(prop, "Group");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Light Override", "Group to override all other lights in this render layer");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- /* layers */
- prop = RNA_def_property(srna, "layers", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "lay", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Visible Layers", "Scene layers included in this render layer");
- if (scene) RNA_def_property_boolean_funcs(prop, NULL, "rna_SceneRenderLayer_layer_set");
- else RNA_def_property_boolean_funcs(prop, NULL, "rna_RenderLayer_layer_set");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- /* this seems to be too much trouble with depsgraph updates/etc. currently (20140423) */
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
-
- prop = RNA_def_property(srna, "layers_zmask", PROP_BOOLEAN, PROP_LAYER);
- RNA_def_property_boolean_sdna(prop, NULL, "lay_zmask", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Zmask Layers", "Zmask scene layers for solid faces");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "layers_exclude", PROP_BOOLEAN, PROP_LAYER);
- RNA_def_property_boolean_sdna(prop, NULL, "lay_exclude", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Exclude Layers", "Exclude scene layers from having any influence");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
if (scene) {
- prop = RNA_def_property(srna, "samples", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_ui_text(prop, "Samples", "Override number of render samples for this render layer, "
- "0 will use the scene setting");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
prop = RNA_def_property(srna, "pass_alpha_threshold", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_ui_text(prop, "Alpha Threshold",
"Z, Index, normal, UV and vector passes are only affected by surfaces with "
@@ -3383,12 +3203,6 @@ void rna_def_render_layer_common(StructRNA *srna, int scene)
}
/* layer options */
- prop = RNA_def_property(srna, "use", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "layflag", SCE_LAY_DISABLE);
- RNA_def_property_ui_text(prop, "Enabled", "Disable or enable the render layer");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
prop = RNA_def_property(srna, "use_zmask", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_ZMASK);
RNA_def_property_ui_text(prop, "Zmask", "Only render what's in front of the solid z values");
@@ -3450,247 +3264,161 @@ void rna_def_render_layer_common(StructRNA *srna, int scene)
if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- prop = RNA_def_property(srna, "use_freestyle", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "layflag", SCE_LAY_FRS);
- RNA_def_property_ui_text(prop, "Freestyle", "Render stylized strokes in this Layer");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_freestyle_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
/* passes */
prop = RNA_def_property(srna, "use_pass_combined", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_COMBINED);
RNA_def_property_ui_text(prop, "Combined", "Deliver full combined RGBA buffer");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_z", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_Z);
RNA_def_property_ui_text(prop, "Z", "Deliver Z values pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_vector", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_VECTOR);
RNA_def_property_ui_text(prop, "Vector", "Deliver speed vector pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_normal", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_NORMAL);
RNA_def_property_ui_text(prop, "Normal", "Deliver normal pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_uv", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_UV);
RNA_def_property_ui_text(prop, "UV", "Deliver texture UV pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_mist", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_MIST);
RNA_def_property_ui_text(prop, "Mist", "Deliver mist factor pass (0.0-1.0)");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_object_index", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_INDEXOB);
RNA_def_property_ui_text(prop, "Object Index", "Deliver object index pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_material_index", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_INDEXMA);
RNA_def_property_ui_text(prop, "Material Index", "Deliver material index pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "use_pass_color", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_RGBA);
- RNA_def_property_ui_text(prop, "Color", "Deliver shade-less color pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "use_pass_diffuse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_DIFFUSE);
- RNA_def_property_ui_text(prop, "Diffuse", "Deliver diffuse pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_specular", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_SPEC);
RNA_def_property_ui_text(prop, "Specular", "Deliver specular pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_shadow", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_SHADOW);
RNA_def_property_ui_text(prop, "Shadow", "Deliver shadow pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_ambient_occlusion", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_AO);
RNA_def_property_ui_text(prop, "AO", "Deliver AO pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- prop = RNA_def_property(srna, "use_pass_reflection", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_REFLECT);
- RNA_def_property_ui_text(prop, "Reflection", "Deliver raytraced reflection pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "use_pass_refraction", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_REFRACT);
- RNA_def_property_ui_text(prop, "Refraction", "Deliver raytraced refraction pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
prop = RNA_def_property(srna, "use_pass_emit", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_EMIT);
RNA_def_property_ui_text(prop, "Emit", "Deliver emission pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_environment", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_ENVIRONMENT);
RNA_def_property_ui_text(prop, "Environment", "Deliver environment lighting pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_indirect", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_INDIRECT);
RNA_def_property_ui_text(prop, "Indirect", "Deliver indirect lighting pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_specular", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_SPEC);
- RNA_def_property_ui_text(prop, "Specular Exclude", "Exclude specular pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_shadow", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_SHADOW);
- RNA_def_property_ui_text(prop, "Shadow Exclude", "Exclude shadow pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_ambient_occlusion", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_AO);
- RNA_def_property_ui_text(prop, "AO Exclude", "Exclude AO pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_reflection", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_REFLECT);
- RNA_def_property_ui_text(prop, "Reflection Exclude", "Exclude raytraced reflection pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_refraction", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_REFRACT);
- RNA_def_property_ui_text(prop, "Refraction Exclude", "Exclude raytraced refraction pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_emit", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_EMIT);
- RNA_def_property_ui_text(prop, "Emit Exclude", "Exclude emission pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_environment", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_ENVIRONMENT);
- RNA_def_property_ui_text(prop, "Environment Exclude", "Exclude environment pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
- else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
-
- prop = RNA_def_property(srna, "exclude_indirect", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pass_xor", SCE_PASS_INDIRECT);
- RNA_def_property_ui_text(prop, "Indirect Exclude", "Exclude indirect pass from combined");
- RNA_def_property_ui_icon(prop, ICON_RESTRICT_RENDER_OFF, 1);
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_diffuse_direct", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_DIFFUSE_DIRECT);
RNA_def_property_ui_text(prop, "Diffuse Direct", "Deliver diffuse direct pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_diffuse_indirect", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_DIFFUSE_INDIRECT);
RNA_def_property_ui_text(prop, "Diffuse Indirect", "Deliver diffuse indirect pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_diffuse_color", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_DIFFUSE_COLOR);
RNA_def_property_ui_text(prop, "Diffuse Color", "Deliver diffuse color pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_glossy_direct", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_GLOSSY_DIRECT);
RNA_def_property_ui_text(prop, "Glossy Direct", "Deliver glossy direct pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_glossy_indirect", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_GLOSSY_INDIRECT);
RNA_def_property_ui_text(prop, "Glossy Indirect", "Deliver glossy indirect pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_glossy_color", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_GLOSSY_COLOR);
RNA_def_property_ui_text(prop, "Glossy Color", "Deliver glossy color pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_transmission_direct", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_TRANSM_DIRECT);
RNA_def_property_ui_text(prop, "Transmission Direct", "Deliver transmission direct pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_transmission_indirect", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_TRANSM_INDIRECT);
RNA_def_property_ui_text(prop, "Transmission Indirect", "Deliver transmission indirect pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_transmission_color", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_TRANSM_COLOR);
RNA_def_property_ui_text(prop, "Transmission Color", "Deliver transmission color pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_subsurface_direct", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_SUBSURFACE_DIRECT);
RNA_def_property_ui_text(prop, "Subsurface Direct", "Deliver subsurface direct pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_subsurface_indirect", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_SUBSURFACE_INDIRECT);
RNA_def_property_ui_text(prop, "Subsurface Indirect", "Deliver subsurface indirect pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
prop = RNA_def_property(srna, "use_pass_subsurface_color", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "passflag", SCE_PASS_SUBSURFACE_COLOR);
RNA_def_property_ui_text(prop, "Subsurface Color", "Deliver subsurface color pass");
- if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_SceneRenderLayer_pass_update");
+ if (scene) RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_ViewLayer_pass_update");
else RNA_def_property_clear_flag(prop, PROP_EDITABLE);
}
@@ -3760,7 +3488,7 @@ static void rna_def_freestyle_linesets(BlenderRNA *brna, PropertyRNA *cprop)
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
}
-static void rna_def_freestyle_settings(BlenderRNA *brna)
+void rna_def_freestyle_settings(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
@@ -4053,8 +3781,8 @@ static void rna_def_freestyle_settings(BlenderRNA *brna)
srna = RNA_def_struct(brna, "FreestyleSettings", NULL);
RNA_def_struct_sdna(srna, "FreestyleConfig");
- RNA_def_struct_nested(brna, srna, "SceneRenderLayer");
- RNA_def_struct_ui_text(srna, "Freestyle Settings", "Freestyle settings for a SceneRenderLayer data-block");
+ RNA_def_struct_nested(brna, srna, "ViewLayer");
+ RNA_def_struct_ui_text(srna, "Freestyle Settings", "Freestyle settings for a ViewLayer data-block");
prop = RNA_def_property(srna, "modules", PROP_COLLECTION, PROP_NONE);
RNA_def_property_collection_sdna(prop, NULL, "modules", NULL);
@@ -4130,124 +3858,6 @@ static void rna_def_freestyle_settings(BlenderRNA *brna)
rna_def_freestyle_linesets(brna, prop);
}
-static void rna_def_scene_game_recast_data(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem rna_enum_partitioning_items[] = {
- {RC_PARTITION_WATERSHED, "WATERSHED", 0, "Watershed", "Classic Recast partitioning method generating the nicest tessellation"},
- {RC_PARTITION_MONOTONE, "MONOTONE", 0, "Monotone", "Fastest navmesh generation method, may create long thin polygons"},
- {RC_PARTITION_LAYERS, "LAYERS", 0, "Layers", "Reasonably fast method that produces better triangles than monotone partitioning"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "SceneGameRecastData", NULL);
- RNA_def_struct_sdna(srna, "RecastData");
- RNA_def_struct_nested(brna, srna, "Scene");
- RNA_def_struct_ui_text(srna, "Recast Data", "Recast data for a Game data-block");
-
- prop = RNA_def_property(srna, "cell_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "cellsize");
- RNA_def_property_ui_range(prop, 0.1, 1, 1, 2);
- RNA_def_property_float_default(prop, 0.3f);
- RNA_def_property_ui_text(prop, "Cell Size", "Rasterized cell size");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "cell_height", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "cellheight");
- RNA_def_property_ui_range(prop, 0.1, 1, 1, 2);
- RNA_def_property_float_default(prop, 0.2f);
- RNA_def_property_ui_text(prop, "Cell Height", "Rasterized cell height");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "agent_height", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "agentheight");
- RNA_def_property_ui_range(prop, 0.1, 5, 1, 2);
- RNA_def_property_float_default(prop, 2.0f);
- RNA_def_property_ui_text(prop, "Agent Height", "Minimum height where the agent can still walk");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "agent_radius", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "agentradius");
- RNA_def_property_ui_range(prop, 0.1, 5, 1, 2);
- RNA_def_property_float_default(prop, 0.6f);
- RNA_def_property_ui_text(prop, "Agent Radius", "Radius of the agent");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "climb_max", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "agentmaxclimb");
- RNA_def_property_ui_range(prop, 0.1, 5, 1, 2);
- RNA_def_property_float_default(prop, 0.9f);
- RNA_def_property_ui_text(prop, "Max Climb", "Maximum height between grid cells the agent can climb");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "slope_max", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_float_sdna(prop, NULL, "agentmaxslope");
- RNA_def_property_range(prop, 0, M_PI_2);
- RNA_def_property_float_default(prop, M_PI_4);
- RNA_def_property_ui_text(prop, "Max Slope", "Maximum walkable slope angle");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
-
- prop = RNA_def_property(srna, "region_min_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "regionminsize");
- RNA_def_property_ui_range(prop, 0, 150, 1, 2);
- RNA_def_property_float_default(prop, 8.0f);
- RNA_def_property_ui_text(prop, "Min Region Size", "Minimum regions size (smaller regions will be deleted)");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "region_merge_size", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "regionmergesize");
- RNA_def_property_ui_range(prop, 0, 150, 1, 2);
- RNA_def_property_float_default(prop, 20.0f);
- RNA_def_property_ui_text(prop, "Merged Region Size", "Minimum regions size (smaller regions will be merged)");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "partitioning", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "partitioning");
- RNA_def_property_enum_items(prop, rna_enum_partitioning_items);
- RNA_def_property_enum_default(prop, RC_PARTITION_WATERSHED);
- RNA_def_property_ui_text(prop, "Partitioning", "Choose partitioning method");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "edge_max_len", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "edgemaxlen");
- RNA_def_property_ui_range(prop, 0, 50, 1, 2);
- RNA_def_property_float_default(prop, 12.0f);
- RNA_def_property_ui_text(prop, "Max Edge Length", "Maximum contour edge length");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "edge_max_error", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "edgemaxerror");
- RNA_def_property_ui_range(prop, 0.1, 3.0, 1, 2);
- RNA_def_property_float_default(prop, 1.3f);
- RNA_def_property_ui_text(prop, "Max Edge Error", "Maximum distance error from contour to cells");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "verts_per_poly", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "vertsperpoly");
- RNA_def_property_ui_range(prop, 3, 12, 1, -1);
- RNA_def_property_int_default(prop, 6);
- RNA_def_property_ui_text(prop, "Verts Per Poly", "Max number of vertices per polygon");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "sample_dist", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "detailsampledist");
- RNA_def_property_ui_range(prop, 0.0, 16.0, 1, 2);
- RNA_def_property_float_default(prop, 6.0f);
- RNA_def_property_ui_text(prop, "Sample Distance", "Detail mesh sample spacing");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "sample_max_error", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "detailsamplemaxerror");
- RNA_def_property_ui_range(prop, 0.0, 16.0, 1, 2);
- RNA_def_property_float_default(prop, 1.0f);
- RNA_def_property_ui_text(prop, "Max Sample Error", "Detail mesh simplification max sample error");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-}
-
-
static void rna_def_bake_data(BlenderRNA *brna)
{
StructRNA *srna;
@@ -4411,498 +4021,6 @@ static void rna_def_bake_data(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
}
-static void rna_def_scene_game_data(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem aasamples_items[] = {
- {0, "SAMPLES_0", 0, "Off", ""},
- {2, "SAMPLES_2", 0, "2x", ""},
- {4, "SAMPLES_4", 0, "4x", ""},
- {8, "SAMPLES_8", 0, "8x", ""},
- {16, "SAMPLES_16", 0, "16x", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem framing_types_items[] = {
- {SCE_GAMEFRAMING_BARS, "LETTERBOX", 0, "Letterbox",
- "Show the entire viewport in the display window, using bar horizontally or vertically"},
- {SCE_GAMEFRAMING_EXTEND, "EXTEND", 0, "Extend",
- "Show the entire viewport in the display window, viewing more horizontally "
- "or vertically"},
- {SCE_GAMEFRAMING_SCALE, "SCALE", 0, "Scale", "Stretch or squeeze the viewport to fill the display window"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem dome_modes_items[] = {
- {DOME_FISHEYE, "FISHEYE", 0, "Fisheye", ""},
- {DOME_TRUNCATED_FRONT, "TRUNCATED_FRONT", 0, "Front-Truncated", ""},
- {DOME_TRUNCATED_REAR, "TRUNCATED_REAR", 0, "Rear-Truncated", ""},
- {DOME_ENVMAP, "ENVMAP", 0, "Cube Map", ""},
- {DOME_PANORAM_SPH, "PANORAM_SPH", 0, "Spherical Panoramic", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem stereo_modes_items[] = {
- {STEREO_QUADBUFFERED, "QUADBUFFERED", 0, "Quad-Buffer", ""},
- {STEREO_ABOVEBELOW, "ABOVEBELOW", 0, "Above-Below", ""},
- {STEREO_INTERLACED, "INTERLACED", 0, "Interlaced", ""},
- {STEREO_ANAGLYPH, "ANAGLYPH", 0, "Anaglyph", ""},
- {STEREO_SIDEBYSIDE, "SIDEBYSIDE", 0, "Side-by-side", ""},
- {STEREO_VINTERLACE, "VINTERLACE", 0, "Vinterlace", ""},
- {STEREO_3DTVTOPBOTTOM, "3DTVTOPBOTTOM", 0, "3DTV Top-Bottom", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem stereo_items[] = {
- {STEREO_NOSTEREO, "NONE", 0, "None", "Disable Stereo and Dome environments"},
- {STEREO_ENABLED, "STEREO", 0, "Stereo", "Enable Stereo environment"},
- {STEREO_DOME, "DOME", 0, "Dome", "Enable Dome environment"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem physics_engine_items[] = {
- {WOPHY_NONE, "NONE", 0, "None", "Don't use a physics engine"},
- {WOPHY_BULLET, "BULLET", 0, "Bullet", "Use the Bullet physics engine"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem material_items[] = {
- {GAME_MAT_MULTITEX, "MULTITEXTURE", 0, "Multitexture", "Multitexture materials"},
- {GAME_MAT_GLSL, "GLSL", 0, "GLSL", "OpenGL shading language shaders"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem obstacle_simulation_items[] = {
- {OBSTSIMULATION_NONE, "NONE", 0, "None", ""},
- {OBSTSIMULATION_TOI_rays, "RVO_RAYS", 0, "RVO (rays)", ""},
- {OBSTSIMULATION_TOI_cells, "RVO_CELLS", 0, "RVO (cells)", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem vsync_items[] = {
- {VSYNC_OFF, "OFF", 0, "Off", "Disable vsync"},
- {VSYNC_ON, "ON", 0, "On", "Enable vsync"},
- {VSYNC_ADAPTIVE, "ADAPTIVE", 0, "Adaptive", "Enable adaptive vsync (if supported)"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem storage_items[] = {
- {RAS_STORE_AUTO, "AUTO", 0, "Auto Select", "Choose the best supported mode"},
- {RAS_STORE_VA, "VERTEX_ARRAY", 0, "Vertex Arrays", "Usually the best choice (good performance with display lists)"},
- {RAS_STORE_VBO, "VERTEX_BUFFER_OBJECT", 0, "Vertex Buffer Objects",
- "Typically slower than vertex arrays with display lists, requires at least OpenGL 1.4"},
- {0, NULL, 0, NULL, NULL}};
-
- srna = RNA_def_struct(brna, "SceneGameData", NULL);
- RNA_def_struct_sdna(srna, "GameData");
- RNA_def_struct_nested(brna, srna, "Scene");
- RNA_def_struct_ui_text(srna, "Game Data", "Game data for a Scene data-block");
-
- prop = RNA_def_property(srna, "resolution_x", PROP_INT, PROP_PIXEL);
- RNA_def_property_int_sdna(prop, NULL, "xplay");
- RNA_def_property_range(prop, 4, 10000);
- RNA_def_property_int_default(prop, 640);
- RNA_def_property_ui_text(prop, "Resolution X", "Number of horizontal pixels in the screen");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "resolution_y", PROP_INT, PROP_PIXEL);
- RNA_def_property_int_sdna(prop, NULL, "yplay");
- RNA_def_property_range(prop, 4, 10000);
- RNA_def_property_int_default(prop, 480);
- RNA_def_property_ui_text(prop, "Resolution Y", "Number of vertical pixels in the screen");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "vsync", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "vsync");
- RNA_def_property_enum_items(prop, vsync_items);
- RNA_def_property_ui_text(prop, "Vsync", "Change vsync settings");
-
- prop = RNA_def_property(srna, "samples", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "aasamples");
- RNA_def_property_enum_items(prop, aasamples_items);
- RNA_def_property_ui_text(prop, "AA Samples", "The number of AA Samples to use for MSAA");
-
- prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "depth");
- RNA_def_property_range(prop, 8, 32);
- RNA_def_property_int_default(prop, 32);
- RNA_def_property_ui_text(prop, "Bits", "Display bit depth of full screen display");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "exit_key", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "exitkey");
- RNA_def_property_enum_items(prop, rna_enum_event_type_items);
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
- RNA_def_property_enum_default(prop, ESCKEY);
- RNA_def_property_enum_funcs(prop, NULL, "rna_GameSettings_exit_key_set", NULL);
- RNA_def_property_ui_text(prop, "Exit Key", "The key that exits the Game Engine");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "raster_storage", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "raster_storage");
- RNA_def_property_enum_items(prop, storage_items);
- RNA_def_property_ui_text(prop, "Storage", "Set the storage mode used by the rasterizer");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- /* Do we need it here ? (since we already have it in World */
- prop = RNA_def_property(srna, "frequency", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "freqplay");
- RNA_def_property_range(prop, 4, 2000);
- RNA_def_property_int_default(prop, 60);
- RNA_def_property_ui_text(prop, "Freq", "Display clock frequency of fullscreen display");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "show_fullscreen", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "playerflag", GAME_PLAYER_FULLSCREEN);
- RNA_def_property_ui_text(prop, "Fullscreen", "Start player in a new fullscreen display");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "use_desktop", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "playerflag", GAME_PLAYER_DESKTOP_RESOLUTION);
- RNA_def_property_ui_text(prop, "Desktop", "Use the current desktop resolution in fullscreen mode");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- /* Framing */
- prop = RNA_def_property(srna, "frame_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "framing.type");
- RNA_def_property_enum_items(prop, framing_types_items);
- RNA_def_property_ui_text(prop, "Framing Types", "Select the type of Framing you want");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "frame_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "framing.col");
- RNA_def_property_range(prop, 0.0f, 1.0f);
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Framing Color", "Set color of the bars");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- /* Stereo */
- prop = RNA_def_property(srna, "stereo", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "stereoflag");
- RNA_def_property_enum_items(prop, stereo_items);
- RNA_def_property_ui_text(prop, "Stereo Options", "");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "stereo_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "stereomode");
- RNA_def_property_enum_items(prop, stereo_modes_items);
- RNA_def_property_enum_default(prop, STEREO_ANAGLYPH);
- RNA_def_property_ui_text(prop, "Stereo Mode", "Stereographic techniques");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "stereo_eye_separation", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "eyeseparation");
- RNA_def_property_range(prop, 0.01, 5.0);
- RNA_def_property_float_default(prop, 0.1f);
- RNA_def_property_ui_text(prop, "Eye Separation",
- "Set the distance between the eyes - the camera focal distance/30 should be fine");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- /* Dome */
- prop = RNA_def_property(srna, "dome_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "dome.mode");
- RNA_def_property_enum_items(prop, dome_modes_items);
- RNA_def_property_ui_text(prop, "Dome Mode", "Dome physical configurations");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "dome_tessellation", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "dome.res");
- RNA_def_property_ui_range(prop, 1, 8, 1, 1);
- RNA_def_property_int_default(prop, 4);
- RNA_def_property_ui_text(prop, "Tessellation", "Tessellation level - check the generated mesh in wireframe mode");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "dome_buffer_resolution", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "dome.resbuf");
- RNA_def_property_ui_range(prop, 0.1, 1.0, 0.1, 2);
- RNA_def_property_float_default(prop, 1.0f);
- RNA_def_property_ui_text(prop, "Buffer Resolution", "Buffer Resolution - decrease it to increase speed");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "dome_angle", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "dome.angle");
- RNA_def_property_ui_range(prop, 90, 250, 1, 1);
- RNA_def_property_int_default(prop, 180);
- RNA_def_property_ui_text(prop, "Angle", "Field of View of the Dome - it only works in mode Fisheye and Truncated");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "dome_tilt", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "dome.tilt");
- RNA_def_property_ui_range(prop, -180, 180, 1, 1);
- RNA_def_property_ui_text(prop, "Tilt", "Camera rotation in horizontal axis");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "dome_text", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "dome.warptext");
- RNA_def_property_struct_type(prop, "Text");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Warp Data", "Custom Warp Mesh data file");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- /* physics */
- prop = RNA_def_property(srna, "physics_engine", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "physicsEngine");
- RNA_def_property_enum_items(prop, physics_engine_items);
- RNA_def_property_enum_default(prop, WOPHY_BULLET);
- RNA_def_property_ui_text(prop, "Physics Engine", "Physics engine used for physics simulation in the game engine");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "physics_gravity", PROP_FLOAT, PROP_ACCELERATION);
- RNA_def_property_float_sdna(prop, NULL, "gravity");
- RNA_def_property_ui_range(prop, 0.0, 25.0, 1, 2);
- RNA_def_property_range(prop, 0.0, 10000.0);
- RNA_def_property_float_default(prop, 9.8f);
- RNA_def_property_ui_text(prop, "Physics Gravity",
- "Gravitational constant used for physics simulation in the game engine");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "occlusion_culling_resolution", PROP_INT, PROP_PIXEL);
- RNA_def_property_int_sdna(prop, NULL, "occlusionRes");
- RNA_def_property_range(prop, 128.0, 1024.0);
- RNA_def_property_int_default(prop, 128);
- RNA_def_property_ui_text(prop, "Occlusion Resolution",
- "Size of the occlusion buffer, use higher value for better precision (slower)");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "fps", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "ticrate");
- RNA_def_property_ui_range(prop, 1, 60, 1, 1);
- RNA_def_property_range(prop, 1, 10000);
- RNA_def_property_int_default(prop, 60);
- RNA_def_property_ui_text(prop, "Frames Per Second",
- "Nominal number of game frames per second "
- "(physics fixed timestep = 1/fps, independently of actual frame rate)");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "logic_step_max", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "maxlogicstep");
- RNA_def_property_range(prop, 1, 10000);
- RNA_def_property_ui_range(prop, 1, 50, 1, 1);
- RNA_def_property_int_default(prop, 5);
- RNA_def_property_ui_text(prop, "Max Logic Steps",
- "Maximum number of logic frame per game frame if graphics slows down the game, "
- "higher value allows better synchronization with physics");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "physics_step_max", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "maxphystep");
- RNA_def_property_range(prop, 1, 10000);
- RNA_def_property_ui_range(prop, 1, 50, 1, 1);
- RNA_def_property_int_default(prop, 5);
- RNA_def_property_ui_text(prop, "Max Physics Steps",
- "Maximum number of physics step per game frame if graphics slows down the game, "
- "higher value allows physics to keep up with realtime");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "physics_step_sub", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "physubstep");
- RNA_def_property_range(prop, 1, 50);
- RNA_def_property_ui_range(prop, 1, 5, 1, 1);
- RNA_def_property_int_default(prop, 1);
- RNA_def_property_ui_text(prop, "Physics Sub Steps",
- "Number of simulation substep per physic timestep, "
- "higher value give better physics precision");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "deactivation_linear_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "lineardeactthreshold");
- RNA_def_property_ui_range(prop, 0.001, 10000.0, 2, 3);
- RNA_def_property_range(prop, 0.001, 10000.0);
- RNA_def_property_float_default(prop, 0.8f);
- RNA_def_property_ui_text(prop, "Deactivation Linear Threshold",
- "Linear velocity that an object must be below before the deactivation timer can start");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "deactivation_angular_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "angulardeactthreshold");
- RNA_def_property_ui_range(prop, 0.001, 10000.0, 2, 3);
- RNA_def_property_range(prop, 0.001, 10000.0);
- RNA_def_property_float_default(prop, 1.0f);
- RNA_def_property_ui_text(prop, "Deactivation Angular Threshold",
- "Angular velocity that an object must be below before the deactivation timer can start");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "deactivation_time", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "deactivationtime");
- RNA_def_property_ui_range(prop, 0.0, 60.0, 1, 1);
- RNA_def_property_range(prop, 0.0, 60.0);
- RNA_def_property_ui_text(prop, "Deactivation Time",
- "Amount of time (in seconds) after which objects with a velocity less than the given "
- "threshold will deactivate (0.0 means no deactivation)");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- /* mode */
- /* not used *//* deprecated !!!!!!!!!!!!! */
- prop = RNA_def_property(srna, "use_occlusion_culling", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_DBVT_CULLING);
- RNA_def_property_ui_text(prop, "DBVT Culling",
- "Use optimized Bullet DBVT tree for view frustum and occlusion culling (more efficient, "
- "but it can waste unnecessary CPU if the scene doesn't have occluder objects)");
-
- /* not used *//* deprecated !!!!!!!!!!!!! */
- prop = RNA_def_property(srna, "use_activity_culling", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_ACTIVITY_CULLING);
- RNA_def_property_ui_text(prop, "Activity Culling", "Activity culling is enabled");
-
- /* not used *//* deprecated !!!!!!!!!!!!! */
- prop = RNA_def_property(srna, "activity_culling_box_radius", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "activityBoxRadius");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Box Radius",
- "Radius of the activity bubble, in Manhattan length "
- "(objects outside the box are activity-culled)");
-
- /* booleans */
- prop = RNA_def_property(srna, "show_debug_properties", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_SHOW_DEBUG_PROPS);
- RNA_def_property_ui_text(prop, "Show Debug Properties",
- "Show properties marked for debugging while the game runs");
-
- prop = RNA_def_property(srna, "show_framerate_profile", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_SHOW_FRAMERATE);
- RNA_def_property_ui_text(prop, "Show Framerate and Profile",
- "Show framerate and profiling information while the game runs");
-
- prop = RNA_def_property(srna, "show_physics_visualization", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_SHOW_PHYSICS);
- RNA_def_property_ui_text(prop, "Show Physics Visualization",
- "Show a visualization of physics bounds and interactions");
-
- prop = RNA_def_property(srna, "show_mouse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_SHOW_MOUSE);
- RNA_def_property_ui_text(prop, "Show Mouse", "Start player with a visible mouse cursor");
-
- prop = RNA_def_property(srna, "use_frame_rate", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_ENABLE_ALL_FRAMES);
- RNA_def_property_ui_text(prop, "Use Frame Rate",
- "Respect the frame rate from the Physics panel in the world properties "
- "rather than rendering as many frames as possible");
-
- prop = RNA_def_property(srna, "use_display_lists", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_DISPLAY_LISTS);
- RNA_def_property_ui_text(prop, "Display Lists",
- "Use display lists to speed up rendering by keeping geometry on the GPU");
-
- prop = RNA_def_property(srna, "use_deprecation_warnings", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_IGNORE_DEPRECATION_WARNINGS);
- RNA_def_property_ui_text(prop, "Deprecation Warnings",
- "Print warnings when using deprecated features in the python API");
-
- prop = RNA_def_property(srna, "use_animation_record", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_ENABLE_ANIMATION_RECORD);
- RNA_def_property_ui_text(prop, "Record Animation", "Record animation to F-Curves");
-
- prop = RNA_def_property(srna, "use_auto_start", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_funcs(prop, "rna_GameSettings_auto_start_get", "rna_GameSettings_auto_start_set");
- RNA_def_property_ui_text(prop, "Auto Start", "Automatically start game at load time");
-
- prop = RNA_def_property(srna, "use_restrict_animation_updates", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_RESTRICT_ANIM_UPDATES);
- RNA_def_property_ui_text(prop, "Restrict Animation Updates",
- "Restrict the number of animation updates to the animation FPS (this is "
- "better for performance, but can cause issues with smooth playback)");
-
- /* materials */
- prop = RNA_def_property(srna, "material_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "matmode");
- RNA_def_property_enum_items(prop, material_items);
- RNA_def_property_ui_text(prop, "Material Mode", "Material mode to use for rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, NULL);
-
- prop = RNA_def_property(srna, "use_glsl_lights", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_LIGHTS);
- RNA_def_property_ui_text(prop, "GLSL Lights", "Use lights for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_glsl_shaders", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_SHADERS);
- RNA_def_property_ui_text(prop, "GLSL Shaders", "Use shaders for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_glsl_shadows", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_SHADOWS);
- RNA_def_property_ui_text(prop, "GLSL Shadows", "Use shadows for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_glsl_ramps", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_RAMPS);
- RNA_def_property_ui_text(prop, "GLSL Ramps", "Use ramps for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_glsl_nodes", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_NODES);
- RNA_def_property_ui_text(prop, "GLSL Nodes", "Use nodes for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_glsl_color_management", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_COLOR_MANAGEMENT);
- RNA_def_property_ui_text(prop, "GLSL Color Management", "Use color management for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_glsl_extra_textures", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_EXTRA_TEX);
- RNA_def_property_ui_text(prop, "GLSL Extra Textures",
- "Use extra textures like normal or specular maps for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_glsl_environment_lighting", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_GLSL_NO_ENV_LIGHTING);
- RNA_def_property_ui_text(prop, "GLSL Environment Lighting", "Use environment lighting for GLSL rendering");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_material_caching", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", GAME_NO_MATERIAL_CACHING);
- RNA_def_property_ui_text(prop, "Use Material Caching",
- "Cache materials in the converter (this is faster, but can cause problems with older "
- "Singletexture and Multitexture games)");
-
- /* obstacle simulation */
- prop = RNA_def_property(srna, "obstacle_simulation", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "obstacleSimulation");
- RNA_def_property_enum_items(prop, obstacle_simulation_items);
- RNA_def_property_ui_text(prop, "Obstacle simulation", "Simulation used for obstacle avoidance in the game engine");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "level_height", PROP_FLOAT, PROP_ACCELERATION);
- RNA_def_property_float_sdna(prop, NULL, "levelHeight");
- RNA_def_property_range(prop, 0.0f, 200.0f);
- RNA_def_property_float_default(prop, 2.0f);
- RNA_def_property_ui_text(prop, "Level height",
- "Max difference in heights of obstacles to enable their interaction");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "show_obstacle_simulation", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", GAME_SHOW_OBSTACLE_SIMULATION);
- RNA_def_property_ui_text(prop, "Visualization", "Enable debug visualization for obstacle simulation");
-
- /* Recast Settings */
- prop = RNA_def_property(srna, "recast_data", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "recastData");
- RNA_def_property_struct_type(prop, "SceneGameRecastData");
- RNA_def_property_ui_text(prop, "Recast Data", "");
-
- /* Nestled Data */
- rna_def_scene_game_recast_data(brna);
-
- /* LoD */
- prop = RNA_def_property(srna, "use_scene_hysteresis", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "lodflag", SCE_LOD_USE_HYST);
- RNA_def_property_ui_text(prop, "Hysteresis", "Use LoD Hysteresis setting for the scene");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-
- prop = RNA_def_property(srna, "scene_hysteresis_percentage", PROP_INT, PROP_PERCENTAGE);
- RNA_def_property_int_sdna(prop, NULL, "scehysteresis");
- RNA_def_property_range(prop, 0, 100);
- RNA_def_property_ui_range(prop, 0, 100, 10, 1);
- RNA_def_property_int_default(prop, 10);
- RNA_def_property_ui_text(prop, "Hysteresis %",
- "Minimum distance change required to transition to the previous level of detail");
- RNA_def_property_update(prop, NC_SCENE, NULL);
-}
-
static void rna_def_gpu_dof_fx(BlenderRNA *brna)
{
StructRNA *srna;
@@ -4910,7 +4028,6 @@ static void rna_def_gpu_dof_fx(BlenderRNA *brna)
srna = RNA_def_struct(brna, "GPUDOFSettings", NULL);
RNA_def_struct_ui_text(srna, "GPU DOF", "Settings for GPU based depth of field");
- RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
RNA_def_struct_path_func(srna, "rna_GPUDOF_path");
prop = RNA_def_property(srna, "focus_distance", PROP_FLOAT, PROP_DISTANCE);
@@ -4944,11 +4061,23 @@ static void rna_def_gpu_dof_fx(BlenderRNA *brna)
RNA_def_property_int_funcs(prop, NULL, "rna_GPUDOFSettings_blades_set", NULL);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update");
+ prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_ANGLE);
+ RNA_def_property_ui_text(prop, "Rotation", "Rotation of blades in apperture");
+ RNA_def_property_range(prop, -M_PI, M_PI);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "ratio", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Ratio", "Distortion to simulate anamorphic lens bokeh");
+ RNA_def_property_range(prop, 0.0000001f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 1.0f, 2.0f, 0.1, 3);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
prop = RNA_def_property(srna, "use_high_quality", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "high_quality", 1);
RNA_def_property_ui_text(prop, "High Quality", "Use high quality depth of field");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUDOFSettings_update");
+ /* NOTE: high quality is always supported */
prop = RNA_def_property(srna, "is_hq_supported", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_gpu_is_hq_supported_get", NULL);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -4963,7 +4092,6 @@ static void rna_def_gpu_ssao_fx(BlenderRNA *brna)
srna = RNA_def_struct(brna, "GPUSSAOSettings", NULL);
RNA_def_struct_ui_text(srna, "GPU SSAO", "Settings for GPU based screen space ambient occlusion");
- RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
prop = RNA_def_property(srna, "factor", PROP_FLOAT, PROP_NONE);
RNA_def_property_ui_text(prop, "Strength", "Strength of the SSAO effect");
@@ -5004,7 +4132,6 @@ static void rna_def_gpu_fx(BlenderRNA *brna)
srna = RNA_def_struct(brna, "GPUFXSettings", NULL);
RNA_def_struct_ui_text(srna, "GPU FX Settings", "Settings for GPU based compositing");
- RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
prop = RNA_def_property(srna, "dof", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
@@ -5015,7 +4142,7 @@ static void rna_def_gpu_fx(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "fx_flag", GPU_FX_FLAG_DOF);
RNA_def_property_ui_text(prop, "Depth Of Field",
"Use depth of field on viewport using the values from active camera");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUFXSettings_fx_update");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "ssao", PROP_POINTER, PROP_NONE);
@@ -5026,80 +4153,32 @@ static void rna_def_gpu_fx(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_ssao", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "fx_flag", GPU_FX_FLAG_SSAO);
RNA_def_property_ui_text(prop, "SSAO", "Use screen space ambient occlusion of field on viewport");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_GPUFXSettings_fx_update");
-}
-
-
-static void rna_def_scene_render_layer(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
- FunctionRNA *func;
-
- srna = RNA_def_struct(brna, "SceneRenderLayer", NULL);
- RNA_def_struct_ui_text(srna, "Scene Render Layer", "Render layer");
- RNA_def_struct_ui_icon(srna, ICON_RENDERLAYERS);
- RNA_def_struct_path_func(srna, "rna_SceneRenderLayer_path");
- RNA_def_struct_idprops_func(srna, "rna_SceneRenderLayer_idprops");
-
- rna_def_render_layer_common(srna, 1);
-
- func = RNA_def_function(srna, "update_render_passes", "rna_SceneRenderLayer_update_render_passes");
- RNA_def_function_ui_description(func, "Requery the enabled render passes from the render engine");
- RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_NO_SELF);
-
- /* Freestyle */
- rna_def_freestyle_settings(brna);
-
- prop = RNA_def_property(srna, "freestyle_settings", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "freestyleConfig");
- RNA_def_property_struct_type(prop, "FreestyleSettings");
- RNA_def_property_ui_text(prop, "Freestyle Settings", "");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
}
-/* Render Layers */
-static void rna_def_render_layers(BlenderRNA *brna, PropertyRNA *cprop)
+static void rna_def_view_layers(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
- PropertyRNA *prop;
-
FunctionRNA *func;
PropertyRNA *parm;
- RNA_def_property_srna(cprop, "RenderLayers");
- srna = RNA_def_struct(brna, "RenderLayers", NULL);
- RNA_def_struct_sdna(srna, "RenderData");
+ RNA_def_property_srna(cprop, "ViewLayers");
+ srna = RNA_def_struct(brna, "ViewLayers", NULL);
+ RNA_def_struct_sdna(srna, "Scene");
RNA_def_struct_ui_text(srna, "Render Layers", "Collection of render layers");
- prop = RNA_def_property(srna, "active_index", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "actlay");
- RNA_def_property_int_funcs(prop, "rna_RenderSettings_active_layer_index_get",
- "rna_RenderSettings_active_layer_index_set",
- "rna_RenderSettings_active_layer_index_range");
- RNA_def_property_ui_text(prop, "Active Layer Index", "Active index in render layer array");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "SceneRenderLayer");
- RNA_def_property_pointer_funcs(prop, "rna_RenderSettings_active_layer_get",
- "rna_RenderSettings_active_layer_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
- RNA_def_property_ui_text(prop, "Active Render Layer", "Active Render Layer");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- func = RNA_def_function(srna, "new", "rna_RenderLayer_new");
- RNA_def_function_ui_description(func, "Add a render layer to scene");
- RNA_def_function_flag(func, FUNC_USE_SELF_ID);
- parm = RNA_def_string(func, "name", "RenderLayer", 0, "", "New name for the render layer (not unique)");
+ func = RNA_def_function(srna, "new", "rna_ViewLayer_new");
+ RNA_def_function_ui_description(func, "Add a view layer to scene");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN);
+ parm = RNA_def_string(func, "name", "ViewLayer", 0, "", "New name for the view layer (not unique)");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- parm = RNA_def_pointer(func, "result", "SceneRenderLayer", "", "Newly created render layer");
+ parm = RNA_def_pointer(func, "result", "ViewLayer", "", "Newly created view layer");
RNA_def_function_return(func, parm);
- func = RNA_def_function(srna, "remove", "rna_RenderLayer_remove");
- RNA_def_function_ui_description(func, "Remove a render layer");
- RNA_def_function_flag(func, FUNC_USE_MAIN | FUNC_USE_REPORTS | FUNC_USE_SELF_ID);
- parm = RNA_def_pointer(func, "layer", "SceneRenderLayer", "", "Render layer to remove");
+ func = RNA_def_function(srna, "remove", "rna_ViewLayer_remove");
+ RNA_def_function_ui_description(func, "Remove a view layer");
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_pointer(func, "layer", "ViewLayer", "", "View layer to remove");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
}
@@ -5665,17 +4744,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
- static const EnumPropertyItem pixel_filter_items[] = {
- {R_FILTER_BOX, "BOX", 0, "Box", "Use a box filter for anti-aliasing"},
- {R_FILTER_TENT, "TENT", 0, "Tent", "Use a tent filter for anti-aliasing"},
- {R_FILTER_QUAD, "QUADRATIC", 0, "Quadratic", "Use a quadratic filter for anti-aliasing"},
- {R_FILTER_CUBIC, "CUBIC", 0, "Cubic", "Use a cubic filter for anti-aliasing"},
- {R_FILTER_CATROM, "CATMULLROM", 0, "Catmull-Rom", "Use a Catmull-Rom filter for anti-aliasing"},
- {R_FILTER_GAUSS, "GAUSSIAN", 0, "Gaussian", "Use a Gaussian filter for anti-aliasing"},
- {R_FILTER_MITCH, "MITCHELL", 0, "Mitchell-Netravali", "Use a Mitchell-Netravali filter for anti-aliasing"},
- {0, NULL, 0, NULL, NULL}
- };
-
static const EnumPropertyItem alpha_mode_items[] = {
{R_ADDSKY, "SKY", 0, "Sky", "Transparent pixels are filled with sky color"},
{R_ALPHAPREMUL, "TRANSPARENT", 0, "Transparent", "World background is transparent with premultiplied alpha"},
@@ -5689,41 +4757,15 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
{R_OUTPUT_NONE, "NONE", 0, "Keep UI", "Images are rendered without forcing UI changes"},
{0, NULL, 0, NULL, NULL}
};
-
+
/* Bake */
static const EnumPropertyItem bake_mode_items[] = {
- {RE_BAKE_ALL, "FULL", 0, "Full Render", "Bake everything"},
- {RE_BAKE_AO, "AO", 0, "Ambient Occlusion", "Bake ambient occlusion"},
- {RE_BAKE_SHADOW, "SHADOW", 0, "Shadow", "Bake shadows"},
+ //{RE_BAKE_AO, "AO", 0, "Ambient Occlusion", "Bake ambient occlusion"},
{RE_BAKE_NORMALS, "NORMALS", 0, "Normals", "Bake normals"},
- {RE_BAKE_TEXTURE, "TEXTURE", 0, "Textures", "Bake textures"},
{RE_BAKE_DISPLACEMENT, "DISPLACEMENT", 0, "Displacement", "Bake displacement"},
- {RE_BAKE_DERIVATIVE, "DERIVATIVE", 0, "Derivative", "Bake derivative map"},
- {RE_BAKE_VERTEX_COLORS, "VERTEX_COLORS", 0, "Vertex Colors", "Bake vertex colors"},
- {RE_BAKE_EMIT, "EMIT", 0, "Emission", "Bake Emit values (glow)"},
- {RE_BAKE_ALPHA, "ALPHA", 0, "Alpha", "Bake Alpha values (transparency)"},
- {RE_BAKE_MIRROR_INTENSITY, "MIRROR_INTENSITY", 0, "Mirror Intensity", "Bake Mirror values"},
- {RE_BAKE_MIRROR_COLOR, "MIRROR_COLOR", 0, "Mirror Colors", "Bake Mirror colors"},
- {RE_BAKE_SPEC_INTENSITY, "SPEC_INTENSITY", 0, "Specular Intensity", "Bake Specular values"},
- {RE_BAKE_SPEC_COLOR, "SPEC_COLOR", 0, "Specular Colors", "Bake Specular colors"},
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem bake_normal_space_items[] = {
- {R_BAKE_SPACE_CAMERA, "CAMERA", 0, "Camera", "Bake the normals in camera space"},
- {R_BAKE_SPACE_WORLD, "WORLD", 0, "World", "Bake the normals in world space"},
- {R_BAKE_SPACE_OBJECT, "OBJECT", 0, "Object", "Bake the normals in object space"},
- {R_BAKE_SPACE_TANGENT, "TANGENT", 0, "Tangent", "Bake the normals in tangent space"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem bake_qyad_split_items[] = {
- {0, "AUTO", 0, "Automatic", "Split quads to give the least distortion while baking"},
- {1, "FIXED", 0, "Fixed", "Split quads predictably (0,1,2) (0,2,3)"},
- {2, "FIXED_ALT", 0, "Fixed Alternate", "Split quads predictably (1,2,3) (1,3,0)"},
- {0, NULL, 0, NULL, NULL}
- };
-
static const EnumPropertyItem pixel_size_items[] = {
{0, "AUTO", 0, "Automatic", "Automatic pixel size, depends on the UI scale"},
{1, "1", 0, "1x", "Render at full resolution"},
@@ -5733,23 +4775,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem octree_resolution_items[] = {
- {64, "64", 0, "64", ""},
- {128, "128", 0, "128", ""},
- {256, "256", 0, "256", ""},
- {512, "512", 0, "512", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem raytrace_structure_items[] = {
- {R_RAYSTRUCTURE_AUTO, "AUTO", 0, "Auto", "Automatically select acceleration structure"},
- {R_RAYSTRUCTURE_OCTREE, "OCTREE", 0, "Octree", "Use old Octree structure"},
- {R_RAYSTRUCTURE_VBVH, "VBVH", 0, "vBVH", "Use vBVH"},
- {R_RAYSTRUCTURE_SIMD_SVBVH, "SIMD_SVBVH", 0, "SIMD SVBVH", "Use SIMD SVBVH"},
- {R_RAYSTRUCTURE_SIMD_QBVH, "SIMD_QBVH", 0, "SIMD QBVH", "Use SIMD QBVH"},
- {0, NULL, 0, NULL, NULL}
- };
-
static const EnumPropertyItem fixed_oversample_items[] = {
{5, "5", 0, "5", ""},
{8, "8", 0, "8", ""},
@@ -5757,13 +4782,7 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
{16, "16", 0, "16", ""},
{0, NULL, 0, NULL, NULL}
};
-
- static const EnumPropertyItem field_order_items[] = {
- {0, "EVEN_FIRST", 0, "Upper First", "Upper field first"},
- {R_ODDFIELD, "ODD_FIRST", 0, "Lower First", "Lower field first"},
- {0, NULL, 0, NULL, NULL}
- };
-
+
static const EnumPropertyItem threads_mode_items[] = {
{0, "AUTO", 0, "Auto-detect", "Automatically determine the number of threads, based on CPUs"},
{R_FIXED_THREADS, "FIXED", 0, "Fixed", "Manually determine the number of threads"},
@@ -5771,7 +4790,7 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
};
static const EnumPropertyItem engine_items[] = {
- {0, "BLENDER_RENDER", 0, "Blender Render", "Use the Blender internal rendering engine for rendering"},
+ {0, "BLENDER_EEVEE", 0, "Eevee", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -5921,50 +4940,19 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Dither Intensity",
"Amount of dithering noise added to the rendered image to break up banding");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "pixel_filter_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "filtertype");
- RNA_def_property_enum_items(prop, pixel_filter_items);
- RNA_def_property_ui_text(prop, "Pixel Filter", "Reconstruction filter used for combining anti-aliasing samples");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
+
prop = RNA_def_property(srna, "filter_size", PROP_FLOAT, PROP_PIXEL);
RNA_def_property_float_sdna(prop, NULL, "gauss");
- RNA_def_property_range(prop, 0.5f, 1.5f);
+ RNA_def_property_range(prop, 0.0f, 500.0f);
+ RNA_def_property_ui_range(prop, 0.01f, 10.0f, 1, 2);
RNA_def_property_ui_text(prop, "Filter Size", "Width over which the reconstruction filter combines samples");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
+
prop = RNA_def_property(srna, "alpha_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "alphamode");
RNA_def_property_enum_items(prop, alpha_mode_items);
RNA_def_property_ui_text(prop, "Alpha Mode", "Representation of alpha information in the RGBA pixels");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "octree_resolution", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "ocres");
- RNA_def_property_enum_items(prop, octree_resolution_items);
- RNA_def_property_ui_text(prop, "Octree Resolution",
- "Resolution of raytrace accelerator, use higher resolutions for larger scenes");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "raytrace_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "raytrace_structure");
- RNA_def_property_enum_items(prop, raytrace_structure_items);
- RNA_def_property_ui_text(prop, "Raytrace Acceleration Structure", "Type of raytrace accelerator structure");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "use_instances", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "raytrace_options", R_RAYTRACE_USE_INSTANCES);
- RNA_def_property_ui_text(prop, "Use Instances",
- "Instance support leads to effective memory reduction when using duplicates");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "use_local_coords", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "raytrace_options", R_RAYTRACE_USE_LOCAL_COORDS);
- RNA_def_property_ui_text(prop, "Use Local Coords",
- "Vertex coordinates are stored locally on each primitive "
- "(increases memory usage, but may have impact on speed)");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
prop = RNA_def_property(srna, "use_antialiasing", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", R_OSA);
@@ -5977,73 +4965,7 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_enum_items(prop, fixed_oversample_items);
RNA_def_property_ui_text(prop, "Anti-Aliasing Samples", "Amount of anti-aliasing samples per pixel");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "use_fields", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_FIELDS);
- RNA_def_property_ui_text(prop, "Fields", "Render image to two fields per frame, for interlaced TV output");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "field_order", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, field_order_items);
- RNA_def_property_ui_text(prop, "Field Order",
- "Order of video fields (select which lines get rendered first, "
- "to create smooth motion for TV output)");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "use_fields_still", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_FIELDSTILL);
- RNA_def_property_ui_text(prop, "Fields Still", "Disable the time difference between fields");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- /* rendering features */
- prop = RNA_def_property(srna, "use_shadows", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_SHADOW);
- RNA_def_property_ui_text(prop, "Shadows", "Calculate shadows while rendering");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_envmaps", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_ENVMAP);
- RNA_def_property_ui_text(prop, "Environment Maps", "Calculate environment maps while rendering");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_sss", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_SSS);
- RNA_def_property_ui_text(prop, "Subsurface Scattering", "Calculate sub-surface scattering in materials rendering");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
- prop = RNA_def_property(srna, "use_world_space_shading", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_USE_WS_SHADING);
- RNA_def_property_ui_text(prop, "World Space Shading", "Use world space interpretation of lighting data for node materials");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_raytrace", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_RAYTRACE);
- RNA_def_property_ui_text(prop, "Raytracing",
- "Pre-calculate the raytrace accelerator and render raytracing effects");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_textures", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "scemode", R_NO_TEX);
- RNA_def_property_ui_text(prop, "Textures", "Use textures to affect material properties");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "use_edge_enhance", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", R_EDGE);
- RNA_def_property_ui_text(prop, "Edge", "Create a toon outline around the edges of geometry");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "edge_threshold", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "edgeint");
- RNA_def_property_range(prop, 0, 255);
- RNA_def_property_ui_text(prop, "Edge Threshold", "Threshold for drawing outlines on geometry edges");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
- prop = RNA_def_property(srna, "edge_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "edgeR");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Edge Color", "Edge color");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
prop = RNA_def_property(srna, "use_freestyle", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
@@ -6075,13 +4997,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
- prop = RNA_def_property(srna, "motion_blur_samples", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "mblur_samples");
- RNA_def_property_range(prop, 1, 32);
- RNA_def_property_ui_text(prop, "Motion Samples", "Number of scene samples to take with motion blur");
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, "rna_Scene_glsl_update");
-
prop = RNA_def_property(srna, "motion_blur_shutter", PROP_FLOAT, PROP_UNSIGNED);
RNA_def_property_float_sdna(prop, NULL, "blurfac");
RNA_def_property_ui_range(prop, 0.01f, 2.0f, 1, 2);
@@ -6098,12 +5013,8 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_border", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", R_BORDER);
RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_ui_text(prop, "Border",
- "Render a user-defined border region, within the frame size "
- "(note that this disables save_buffers and full_sample)");
+ RNA_def_property_ui_text(prop, "Border", "Render a user-defined border region, within the frame size ");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
-
prop = RNA_def_property(srna, "border_min_x", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "border.xmin");
@@ -6191,15 +5102,8 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Movie Format", "When true the format is a movie");
- prop = RNA_def_property(srna, "use_free_image_textures", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scemode", R_FREE_IMAGE);
- RNA_def_property_ui_text(prop, "Free Image Textures",
- "Free all image textures from memory after render, to save memory before compositing");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
prop = RNA_def_property(srna, "use_save_buffers", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "scemode", R_EXR_TILE_FILE);
- RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_save_buffers_get", NULL);
RNA_def_property_ui_text(prop, "Save Buffers",
"Save tiles for all RenderLayers and SceneNodes to files in the temp directory "
"(saves memory, required for Full Sample)");
@@ -6247,46 +5151,17 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Bake Mode", "Choose shading information to bake into the image");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
- prop = RNA_def_property(srna, "bake_normal_space", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "bake_normal_space");
- RNA_def_property_enum_items(prop, bake_normal_space_items);
- RNA_def_property_ui_text(prop, "Normal Space", "Choose normal space for baking");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "bake_quad_split", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, bake_qyad_split_items);
- RNA_def_property_ui_text(prop, "Quad Split", "Choose the method used to split a quad into 2 triangles for baking");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
- prop = RNA_def_property(srna, "bake_aa_mode", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "bake_osa");
- RNA_def_property_enum_items(prop, fixed_oversample_items);
- RNA_def_property_ui_text(prop, "Anti-Aliasing Level", "");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
prop = RNA_def_property(srna, "use_bake_selected_to_active", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "bake_flag", R_BAKE_TO_ACTIVE);
RNA_def_property_ui_text(prop, "Selected to Active",
"Bake shading on the surface of selected objects to the active object");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
- prop = RNA_def_property(srna, "use_bake_normalize", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bake_flag", R_BAKE_NORMALIZE);
- RNA_def_property_ui_text(prop, "Normalized",
- "With displacement normalize to the distance, with ambient occlusion "
- "normalize without using material settings");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
prop = RNA_def_property(srna, "use_bake_clear", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "bake_flag", R_BAKE_CLEAR);
RNA_def_property_ui_text(prop, "Clear", "Clear Images before baking");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
- prop = RNA_def_property(srna, "use_bake_antialiasing", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bake_flag", R_BAKE_OSA);
- RNA_def_property_ui_text(prop, "Anti-Aliasing", "Enables Anti-aliasing");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
prop = RNA_def_property(srna, "bake_margin", PROP_INT, PROP_PIXEL);
RNA_def_property_int_sdna(prop, NULL, "bake_filter");
RNA_def_property_range(prop, 0, 64);
@@ -6294,13 +5169,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
"Extends the baked result as a post process filter");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
- prop = RNA_def_property(srna, "bake_distance", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "bake_maxdist");
- RNA_def_property_range(prop, 0.0, 1000.0);
- RNA_def_property_ui_text(prop, "Distance",
- "Maximum distance from active object to other object (in blender units)");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
prop = RNA_def_property(srna, "bake_bias", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "bake_biasdist");
RNA_def_property_range(prop, 0.0, 1000.0);
@@ -6325,12 +5193,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Samples", "Number of samples used for ambient occlusion baking from multires");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
- prop = RNA_def_property(srna, "use_bake_to_vertex_color", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "bake_flag", R_BAKE_VCOL);
- RNA_def_property_ui_text(prop, "Bake to Vertex Color",
- "Bake to vertex colors instead of to a UV-mapped image");
- RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
-
prop = RNA_def_property(srna, "use_bake_user_scale", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "bake_flag", R_BAKE_USERSCALE);
RNA_def_property_ui_text(prop, "User scale", "Use a user scale for the derivative map");
@@ -6461,14 +5323,14 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
prop = RNA_def_property(srna, "sequencer_gl_preview", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "seq_prev_type");
- RNA_def_property_enum_items(prop, rna_enum_viewport_shade_items);
+ RNA_def_property_enum_items(prop, rna_enum_shading_type_items);
RNA_def_property_ui_text(prop, "Sequencer Preview Shading", "Method to draw in the sequencer view");
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SceneSequencer_update");
#if 0 /* UNUSED, see R_SEQ_GL_REND comment */
prop = RNA_def_property(srna, "sequencer_gl_render", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "seq_rend_type");
- RNA_def_property_enum_items(prop, rna_enum_viewport_shade_items);
+ RNA_def_property_enum_items(prop, rna_enum_shading_type_items);
/* XXX Label and tooltips are obviously wrong! */
RNA_def_property_ui_text(prop, "Sequencer Preview Shading", "Method to draw in the sequencer view");
#endif
@@ -6483,18 +5345,9 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Depth of Field", "Use depth of field using the values from scene strip active camera");
RNA_def_property_update(prop, NC_SCENE | ND_SEQUENCER, "rna_SceneSequencer_update");
- /* layers */
- prop = RNA_def_property(srna, "layers", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "layers", NULL);
- RNA_def_property_struct_type(prop, "SceneRenderLayer");
- RNA_def_property_ui_text(prop, "Render Layers", "");
- rna_def_render_layers(brna, prop);
-
-
prop = RNA_def_property(srna, "use_single_layer", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "scemode", R_SINGLE_LAYER);
- RNA_def_property_ui_text(prop, "Single Layer", "Only render the active layer");
- RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
+ RNA_def_property_ui_text(prop, "Render Single Layer", "Only render the active layer");
RNA_def_property_update(prop, NC_SCENE | ND_RENDER_OPTIONS, NULL);
/* views (stereoscopy et al) */
@@ -6537,21 +5390,11 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Multiple Engines", "More than one rendering engine is available");
- prop = RNA_def_property(srna, "use_shading_nodes", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_use_shading_nodes_get", NULL);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Use Shading Nodes", "Active render engine uses new shading nodes system");
-
prop = RNA_def_property(srna, "use_spherical_stereo", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_use_spherical_stereo_get", NULL);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Use Spherical Stereo", "Active render engine supports spherical stereo rendering");
- prop = RNA_def_property(srna, "use_game_engine", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_funcs(prop, "rna_RenderSettings_use_game_engine_get", NULL);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Use Game Engine", "Current rendering engine is a game engine");
-
/* simplify */
prop = RNA_def_property(srna, "use_simplify", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", R_SIMPLIFY);
@@ -6580,21 +5423,6 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Simplify Child Particles", "Global child particles percentage during rendering");
RNA_def_property_update(prop, 0, "rna_Scene_simplify_update");
- prop = RNA_def_property(srna, "simplify_shadow_samples", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "simplify_shadowsamples");
- RNA_def_property_ui_range(prop, 1, 16, 1, -1);
- RNA_def_property_ui_text(prop, "Simplify Shadow Samples", "Global maximum shadow samples");
- RNA_def_property_update(prop, 0, "rna_Scene_simplify_update");
-
- prop = RNA_def_property(srna, "simplify_ao_sss", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "simplify_aosss");
- RNA_def_property_ui_text(prop, "Simplify AO and SSS", "Global approximate AO and SSS quality factor");
- RNA_def_property_update(prop, 0, "rna_Scene_simplify_update");
-
- prop = RNA_def_property(srna, "use_simplify_triangulate", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "simplify_flag", R_SIMPLE_NO_TRIANGULATE);
- RNA_def_property_ui_text(prop, "Skip Quad to Triangles", "Disable non-planar quads being triangulated");
-
/* persistent data */
prop = RNA_def_property(srna, "use_persistent_data", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "mode", R_PERSISTENT_DATA);
@@ -6637,61 +5465,11 @@ static void rna_def_scene_render_data(BlenderRNA *brna)
static void rna_def_scene_objects(BlenderRNA *brna, PropertyRNA *cprop)
{
StructRNA *srna;
- PropertyRNA *prop;
- FunctionRNA *func;
- PropertyRNA *parm;
-
RNA_def_property_srna(cprop, "SceneObjects");
srna = RNA_def_struct(brna, "SceneObjects", NULL);
RNA_def_struct_sdna(srna, "Scene");
- RNA_def_struct_ui_text(srna, "Scene Objects", "Collection of scene objects");
-
- func = RNA_def_function(srna, "link", "rna_Scene_object_link");
- RNA_def_function_ui_description(func, "Link object to scene, run scene.update() after");
- RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
- parm = RNA_def_pointer(func, "object", "Object", "", "Object to add to scene");
- RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
- parm = RNA_def_pointer(func, "base", "ObjectBase", "", "The newly created base");
- RNA_def_function_return(func, parm);
-
- func = RNA_def_function(srna, "unlink", "rna_Scene_object_unlink");
- RNA_def_function_ui_description(func, "Unlink object from scene");
- RNA_def_function_flag(func, FUNC_USE_REPORTS);
- parm = RNA_def_pointer(func, "object", "Object", "", "Object to remove from scene");
- RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
-
- prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_pointer_funcs(prop, "rna_Scene_active_object_get", "rna_Scene_active_object_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_UNLINK);
- RNA_def_property_ui_text(prop, "Active Object", "Active object for this scene");
- /* Could call: ED_base_object_activate(C, scene->basact);
- * but would be a bad level call and it seems the notifier is enough */
- RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, NULL);
-}
-
-
-/* scene.bases.* */
-static void rna_def_scene_bases(BlenderRNA *brna, PropertyRNA *cprop)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
-/* FunctionRNA *func; */
-/* PropertyRNA *parm; */
-
- RNA_def_property_srna(cprop, "SceneBases");
- srna = RNA_def_struct(brna, "SceneBases", NULL);
- RNA_def_struct_sdna(srna, "Scene");
- RNA_def_struct_ui_text(srna, "Scene Bases", "Collection of scene bases");
-
- prop = RNA_def_property(srna, "active", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "ObjectBase");
- RNA_def_property_pointer_sdna(prop, NULL, "basact");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Active Base", "Active object base in the scene");
- RNA_def_property_update(prop, NC_SCENE | ND_OB_ACTIVE, NULL);
+ RNA_def_struct_ui_text(srna, "Scene Objects", "All the of scene objects");
}
/* scene.timeline_markers */
@@ -6914,33 +5692,28 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
RNA_def_property_pointer_funcs(prop, NULL, "rna_Scene_set_set", NULL, NULL);
RNA_def_property_ui_text(prop, "Background Scene", "Background set scene");
- RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_glsl_update");
+ RNA_def_property_update(prop, NC_SCENE | NA_EDITED, "rna_Scene_set_update");
prop = RNA_def_property(srna, "world", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "World", "World used for rendering the scene");
- RNA_def_property_update(prop, NC_SCENE | ND_WORLD, "rna_Scene_glsl_update");
+ RNA_def_property_update(prop, NC_SCENE | ND_WORLD, "rna_Scene_world_update");
prop = RNA_def_property(srna, "cursor_location", PROP_FLOAT, PROP_XYZ_LENGTH);
RNA_def_property_float_sdna(prop, NULL, "cursor");
RNA_def_property_ui_text(prop, "Cursor Location", "3D cursor location");
RNA_def_property_ui_range(prop, -10000.0, 10000.0, 10, 4);
RNA_def_property_update(prop, NC_WINDOW, NULL);
-
- /* Bases/Objects */
- prop = RNA_def_property(srna, "object_bases", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "base", NULL);
- RNA_def_property_struct_type(prop, "ObjectBase");
- RNA_def_property_ui_text(prop, "Bases", "");
- RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, NULL, NULL, NULL,
- "rna_Scene_object_bases_lookup_string", NULL);
- rna_def_scene_bases(brna, prop);
prop = RNA_def_property(srna, "objects", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "base", NULL);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_ui_text(prop, "Objects", "");
- RNA_def_property_collection_funcs(prop, NULL, NULL, NULL, "rna_Scene_objects_get", NULL, NULL, NULL, NULL);
+ RNA_def_property_collection_funcs(prop,
+ "rna_Scene_objects_begin",
+ "rna_Scene_objects_next",
+ "rna_Scene_objects_end",
+ "rna_Scene_objects_get",
+ NULL, NULL, NULL, NULL);
rna_def_scene_objects(brna, prop);
/* Layers */
@@ -6990,6 +5763,7 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_int_sdna(prop, NULL, "r.sfra");
RNA_def_property_int_funcs(prop, NULL, "rna_Scene_start_frame_set", NULL);
RNA_def_property_range(prop, MINFRAME, MAXFRAME);
+ RNA_def_property_int_default(prop, 1);
RNA_def_property_ui_text(prop, "Start Frame", "First frame of the playback/rendering range");
RNA_def_property_update(prop, NC_SCENE | ND_FRAME_RANGE, NULL);
@@ -6998,6 +5772,7 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_int_sdna(prop, NULL, "r.efra");
RNA_def_property_int_funcs(prop, NULL, "rna_Scene_end_frame_set", NULL);
RNA_def_property_range(prop, MINFRAME, MAXFRAME);
+ RNA_def_property_int_default(prop, 250);
RNA_def_property_ui_text(prop, "End Frame", "Final frame of the playback/rendering range");
RNA_def_property_update(prop, NC_SCENE | ND_FRAME_RANGE, NULL);
@@ -7084,14 +5859,17 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_GRAPH, NULL);
/* Frame dropping flag for playback and sync enum */
+#if 0 /* XXX: Is this actually needed? */
prop = RNA_def_property(srna, "use_frame_drop", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", SCE_FRAME_DROP);
RNA_def_property_ui_text(prop, "Frame Dropping", "Play back dropping frames if frame display is too slow");
RNA_def_property_update(prop, NC_SCENE, NULL);
+#endif
prop = RNA_def_property(srna, "sync_mode", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_funcs(prop, "rna_Scene_sync_mode_get", "rna_Scene_sync_mode_set", NULL);
RNA_def_property_enum_items(prop, sync_mode_items);
+ RNA_def_property_enum_default(prop, AUDIO_SYNC);
RNA_def_property_ui_text(prop, "Sync Mode", "How to sync playback");
RNA_def_property_update(prop, NC_SCENE, NULL);
@@ -7179,7 +5957,20 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "r");
RNA_def_property_struct_type(prop, "RenderSettings");
RNA_def_property_ui_text(prop, "Render Data", "");
-
+
+ /* Render Engine Data */
+ prop = RNA_def_property(srna, "layer_properties", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "layer_properties->data.group", NULL);
+ RNA_def_property_struct_type(prop, "ViewLayerSettings");
+ RNA_def_property_ui_text(prop, "Layer Settings",
+ "Engine specific render settings to be overridden by layers");
+
+ prop = RNA_def_property(srna, "collection_properties", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "collection_properties->data.group", NULL);
+ RNA_def_property_struct_type(prop, "LayerCollectionSettings");
+ RNA_def_property_ui_text(prop, "Collection Settings",
+ "Engine specific render settings to be overridden by collections");
+
/* Safe Areas */
prop = RNA_def_property(srna, "safe_areas", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "safe_areas");
@@ -7194,17 +5985,33 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Timeline Markers", "Markers used in all timelines for the current scene");
rna_def_timeline_markers(brna, prop);
+ /* Orientations */
+ prop = RNA_def_property(srna, "transform_orientation", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "orientation_type");
+ RNA_def_property_enum_items(prop, transform_orientation_items);
+ RNA_def_property_enum_funcs(prop, "rna_Scene_transform_orientation_get", "rna_Scene_transform_orientation_set",
+ "rna_TransformOrientation_itemf");
+ RNA_def_property_ui_text(prop, "Transform Orientation", "Transformation orientation");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "current_orientation", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "TransformOrientation");
+ RNA_def_property_pointer_funcs(prop, "rna_Scene_current_orientation_get", NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Current Transform Orientation", "Current transformation orientation");
+
/* Audio Settings */
prop = RNA_def_property(srna, "use_audio", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_funcs(prop, "rna_Scene_use_audio_get", "rna_Scene_use_audio_set");
RNA_def_property_ui_text(prop, "Audio Muted", "Play back of audio from Sequence Editor will be muted");
RNA_def_property_update(prop, NC_SCENE, NULL);
+#if 0 /* XXX: Is this actually needed? */
prop = RNA_def_property(srna, "use_audio_sync", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "audio.flag", AUDIO_SYNC);
RNA_def_property_ui_text(prop, "Audio Sync",
"Play back and sync with audio clock, dropping frames if frame display is too slow");
RNA_def_property_update(prop, NC_SCENE, NULL);
+#endif
prop = RNA_def_property(srna, "use_audio_scrub", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "audio.flag", AUDIO_SCRUB);
@@ -7240,15 +6047,10 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SCENE, NULL);
RNA_def_property_float_funcs(prop, NULL, "rna_Scene_volume_set", NULL);
- /* Game Settings */
- prop = RNA_def_property(srna, "game_settings", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "gm");
- RNA_def_property_struct_type(prop, "SceneGameData");
- RNA_def_property_ui_text(prop, "Game Data", "");
-
/* Statistics */
func = RNA_def_function(srna, "statistics", "ED_info_stats_string");
+ parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "Active layer");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
parm = RNA_def_string(func, "statistics", NULL, 0, "Statistics", "");
RNA_def_function_return(func, parm);
@@ -7259,12 +6061,6 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_REFCOUNT);
RNA_def_property_ui_text(prop, "Grease Pencil Data", "Grease Pencil data-block");
RNA_def_property_update(prop, NC_GPENCIL | ND_DATA | NA_EDITED, NULL);
-
- /* Transform Orientations */
- prop = RNA_def_property(srna, "orientations", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "transform_spaces", NULL);
- RNA_def_property_struct_type(prop, "TransformOrientation");
- RNA_def_property_ui_text(prop, "Transform Orientations", "");
/* active MovieClip */
prop = RNA_def_property(srna, "active_clip", PROP_POINTER, PROP_NONE);
@@ -7290,10 +6086,18 @@ void RNA_def_scene(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "ColorManagedSequencerColorspaceSettings");
RNA_def_property_ui_text(prop, "Sequencer Color Space Settings", "Settings of color space sequencer is working in");
- /* Dependency Graph */
- prop = RNA_def_property(srna, "depsgraph", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Depsgraph");
- RNA_def_property_ui_text(prop, "Dependency Graph", "Dependencies in the scene data");
+ /* Layer and Collections */
+ prop = RNA_def_property(srna, "view_layers", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "view_layers", NULL);
+ RNA_def_property_struct_type(prop, "ViewLayer");
+ RNA_def_property_ui_text(prop, "View Layers", "");
+ rna_def_view_layers(brna, prop);
+
+ prop = RNA_def_property(srna, "master_collection", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_pointer_sdna(prop, NULL, "collection");
+ RNA_def_property_struct_type(prop, "SceneCollection");
+ RNA_def_property_ui_text(prop, "Master Collection", "Collection that contains all other collections");
/* Nestled Data */
/* *** Non-Animated *** */
@@ -7306,14 +6110,12 @@ void RNA_def_scene(BlenderRNA *brna)
rna_def_statvis(brna);
rna_def_unit_settings(brna);
rna_def_scene_image_format_data(brna);
- rna_def_scene_game_data(brna);
rna_def_transform_orientation(brna);
rna_def_selected_uv_element(brna);
rna_def_display_safe_areas(brna);
RNA_define_animate_sdna(true);
/* *** Animated *** */
rna_def_scene_render_data(brna);
- rna_def_scene_render_layer(brna);
rna_def_gpu_fx(brna);
rna_def_scene_render_view(brna);
diff --git a/source/blender/makesrna/intern/rna_scene_api.c b/source/blender/makesrna/intern/rna_scene_api.c
index e6d030877d7..ca7d153066f 100644
--- a/source/blender/makesrna/intern/rna_scene_api.c
+++ b/source/blender/makesrna/intern/rna_scene_api.c
@@ -60,7 +60,6 @@ const EnumPropertyItem rna_enum_abc_compression_items[] = {
#ifdef RNA_RUNTIME
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_editmesh.h"
#include "BKE_global.h"
#include "BKE_image.h"
@@ -86,8 +85,13 @@ static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subf
BPy_BEGIN_ALLOW_THREADS;
#endif
- /* It's possible that here we're including layers which were never visible before. */
- BKE_scene_update_for_newframe_ex(bmain->eval_ctx, bmain, scene, (1 << 20) - 1, true);
+ for (ViewLayer *view_layer = scene->view_layers.first;
+ view_layer != NULL;
+ view_layer = view_layer->next)
+ {
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
+ }
#ifdef WITH_PYTHON
BPy_END_ALLOW_THREADS;
@@ -99,7 +103,7 @@ static void rna_Scene_frame_set(Scene *scene, Main *bmain, int frame, float subf
* redrawing while the data is being modified for render */
if (!G.is_rendering) {
/* cant use NC_SCENE|ND_FRAME because this causes wm_event_do_notifiers to call
- * BKE_scene_update_for_newframe which will loose any un-keyed changes [#24690] */
+ * BKE_scene_graph_update_for_newframe which will loose any un-keyed changes [#24690] */
/* WM_main_add_notifier(NC_SCENE|ND_FRAME, scene); */
/* instead just redraw the views */
@@ -127,7 +131,13 @@ static void rna_Scene_update_tagged(Scene *scene, Main *bmain)
BPy_BEGIN_ALLOW_THREADS;
#endif
- BKE_scene_update_tagged(bmain->eval_ctx, bmain, scene);
+ for (ViewLayer *view_layer = scene->view_layers.first;
+ view_layer != NULL;
+ view_layer = view_layer->next)
+ {
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+ BKE_scene_graph_update_tagged(depsgraph, bmain);
+ }
#ifdef WITH_PYTHON
BPy_END_ALLOW_THREADS;
@@ -153,14 +163,16 @@ static void rna_SceneRender_get_frame_path(RenderData *rd, int frame, int previe
}
static void rna_Scene_ray_cast(
- Scene *scene, float origin[3], float direction[3], float ray_dist,
+ Scene *scene, ViewLayer *view_layer,
+ float origin[3], float direction[3], float ray_dist,
int *r_success, float r_location[3], float r_normal[3], int *r_index,
Object **r_ob, float r_obmat[16])
{
normalize_v3(direction);
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
SnapObjectContext *sctx = ED_transform_snap_object_context_create(
- G.main, scene, 0);
+ G.main, scene, depsgraph, 0);
bool ret = ED_transform_snap_object_project_ray_ex(
sctx,
@@ -292,6 +304,8 @@ void RNA_api_scene(StructRNA *srna)
/* Ray Cast */
func = RNA_def_function(srna, "ray_cast", "rna_Scene_ray_cast");
RNA_def_function_ui_description(func, "Cast a ray onto in object space");
+ parm = RNA_def_pointer(func, "view_layer", "ViewLayer", "", "Scene Layer");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
/* ray start and end */
parm = RNA_def_float_vector(func, "origin", 3, NULL, -FLT_MAX, FLT_MAX, "", "", -1e4, 1e4);
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
@@ -317,6 +331,7 @@ void RNA_api_scene(StructRNA *srna)
parm = RNA_def_float_matrix(func, "matrix", 4, 4, NULL, 0.0f, 0.0f, "", "Matrix", 0.0f, 0.0f);
RNA_def_function_output(func, parm);
+
#ifdef WITH_ALEMBIC
/* XXX Deprecated, will be removed in 2.8 in favour of calling the export operator. */
func = RNA_def_function(srna, "alembic_export", "rna_Scene_alembic_export");
@@ -345,7 +360,7 @@ void RNA_api_scene(StructRNA *srna)
RNA_def_boolean(func, "export_hair", 1, "Export Hair", "Exports hair particle systems as animated curves");
RNA_def_boolean(func, "export_particles", 1, "Export Particles", "Exports non-hair particle systems");
RNA_def_enum(func, "compression_type", rna_enum_abc_compression_items, 0, "Compression", "");
- RNA_def_boolean(func, "packuv" , 0, "Export with packed UV islands", "Export with packed UV islands");
+ RNA_def_boolean(func, "packuv", 0, "Export with packed UV islands", "Export with packed UV islands");
RNA_def_float(func, "scale", 1.0f, 0.0001f, 1000.0f, "Scale", "Value by which to enlarge or shrink the objects with respect to the world's origin", 0.0001f, 1000.0f);
RNA_def_boolean(func, "triangulate", 0, "Triangulate", "Export Polygons (Quads & NGons) as Triangles");
RNA_def_enum(func, "quad_method", rna_enum_modifier_triangulate_quad_method_items, 0, "Quad Method", "Method for splitting the quads into triangles");
diff --git a/source/blender/makesrna/intern/rna_screen.c b/source/blender/makesrna/intern/rna_screen.c
index ce6d60a4ae7..83d8e730e3e 100644
--- a/source/blender/makesrna/intern/rna_screen.c
+++ b/source/blender/makesrna/intern/rna_screen.c
@@ -35,6 +35,7 @@
#include "DNA_screen_types.h"
#include "DNA_scene_types.h"
+#include "DNA_workspace_types.h"
const EnumPropertyItem rna_enum_region_type_items[] = {
{RGN_TYPE_WINDOW, "WINDOW", 0, "Window", ""},
@@ -56,7 +57,9 @@ const EnumPropertyItem rna_enum_region_type_items[] = {
#ifdef RNA_RUNTIME
#include "BKE_global.h"
-#include "BKE_depsgraph.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
#include "UI_view2d.h"
@@ -64,55 +67,66 @@ const EnumPropertyItem rna_enum_region_type_items[] = {
# include "BPY_extern.h"
#endif
-static void rna_Screen_scene_set(PointerRNA *ptr, PointerRNA value)
-{
- bScreen *sc = (bScreen *)ptr->data;
- if (value.data == NULL)
- return;
+static void rna_Screen_redraw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+{
+ bScreen *screen = (bScreen *)ptr->data;
- sc->newscene = value.data;
+ /* the settings for this are currently only available from a menu in the TimeLine,
+ * hence refresh=SPACE_ACTION, as timeline is now in there
+ */
+ ED_screen_animation_timer_update(screen, screen->redraws_flag, SPACE_ACTION);
}
-static void rna_Screen_scene_update(bContext *C, PointerRNA *ptr)
+static int rna_Screen_is_animation_playing_get(PointerRNA *UNUSED(ptr))
{
- bScreen *sc = (bScreen *)ptr->data;
-
- /* exception: must use context so notifier gets to the right window */
- if (sc->newscene) {
-#ifdef WITH_PYTHON
- BPy_BEGIN_ALLOW_THREADS;
-#endif
-
- ED_screen_set_scene(C, sc, sc->newscene);
-
-#ifdef WITH_PYTHON
- BPy_END_ALLOW_THREADS;
-#endif
+ /* can be NULL on file load, T42619 */
+ wmWindowManager *wm = G.main->wm.first;
+ return wm ? (ED_screen_animation_playing(wm) != NULL) : 0;
+}
- WM_event_add_notifier(C, NC_SCENE | ND_SCENEBROWSE, sc->newscene);
+static int rna_region_alignment_get(PointerRNA *ptr)
+{
+ ARegion *region = ptr->data;
+ return (region->alignment & ~RGN_SPLIT_PREV);
+}
- if (G.debug & G_DEBUG)
- printf("scene set %p\n", sc->newscene);
+static void rna_Screen_layout_name_get(PointerRNA *ptr, char *value)
+{
+ const bScreen *screen = ptr->data;
+ const WorkSpaceLayout *layout = BKE_workspace_layout_find_global(G.main, screen, NULL);
- sc->newscene = NULL;
+ if (layout) {
+ const char *name = BKE_workspace_layout_name_get(layout);
+ strcpy(value, name);
+ }
+ else {
+ value[0] = '\0';
}
}
-static void rna_Screen_redraw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
+static int rna_Screen_layout_name_length(PointerRNA *ptr)
{
- bScreen *screen = (bScreen *)ptr->data;
+ const bScreen *screen = ptr->data;
+ const WorkSpaceLayout *layout = BKE_workspace_layout_find_global(G.main, screen, NULL);
- /* the settings for this are currently only available from a menu in the TimeLine, hence refresh=SPACE_TIME */
- ED_screen_animation_timer_update(screen, screen->redraws_flag, SPACE_TIME);
-}
+ if (layout) {
+ const char *name = BKE_workspace_layout_name_get(layout);
+ return strlen(name);
+ }
+ return 0;
+}
-static int rna_Screen_is_animation_playing_get(PointerRNA *UNUSED(ptr))
+static void rna_Screen_layout_name_set(PointerRNA *ptr, const char *value)
{
- /* can be NULL on file load, T42619 */
- wmWindowManager *wm = G.main->wm.first;
- return wm ? (ED_screen_animation_playing(wm) != NULL) : 0;
+ bScreen *screen = ptr->data;
+ WorkSpace *workspace;
+ WorkSpaceLayout *layout = BKE_workspace_layout_find_global(G.main, screen, &workspace);
+
+ if (layout) {
+ BKE_workspace_layout_name_set(workspace, layout, value);
+ }
}
static int rna_Screen_fullscreen_get(PointerRNA *ptr)
@@ -124,21 +138,41 @@ static int rna_Screen_fullscreen_get(PointerRNA *ptr)
/* UI compatible list: should not be needed, but for now we need to keep EMPTY
* at least in the static version of this enum for python scripts. */
static const EnumPropertyItem *rna_Area_type_itemf(bContext *UNUSED(C), PointerRNA *UNUSED(ptr),
- PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
+ PropertyRNA *UNUSED(prop), bool *r_free)
{
+ EnumPropertyItem *item = NULL;
+ int totitem = 0;
+
/* +1 to skip SPACE_EMPTY */
- return rna_enum_space_type_items + 1;
+ for (const EnumPropertyItem *item_from = rna_enum_space_type_items + 1; item_from->identifier; item_from++) {
+ if (ELEM(item_from->value, SPACE_TOPBAR)) {
+ continue;
+ }
+ RNA_enum_item_add(&item, &totitem, item_from);
+ }
+ RNA_enum_item_end(&item, &totitem);
+ *r_free = true;
+
+ return item;
}
static int rna_Area_type_get(PointerRNA *ptr)
{
ScrArea *sa = (ScrArea *)ptr->data;
- /* read from this instead of 'spacetype' for correct reporting: T41435 */
- return sa->butspacetype;
+ /* Usually 'spacetype' is used. It lags behind a bit while switching area
+ * type though, then we use 'butspacetype' instead (T41435). */
+ return (sa->butspacetype == SPACE_EMPTY) ? sa->spacetype : sa->butspacetype;
}
static void rna_Area_type_set(PointerRNA *ptr, int value)
{
+ if (ELEM(value, SPACE_TOPBAR)) {
+ /* Special case: An area can not be set to show the top-bar editor (or
+ * other global areas). However it should still be possible to identify
+ * its type from Python. */
+ return;
+ }
+
ScrArea *sa = (ScrArea *)ptr->data;
sa->butspacetype = value;
}
@@ -152,7 +186,7 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
/* XXX this call still use context, so we trick it to work in the right context */
for (win = wm->windows.first; win; win = win->next) {
- if (sc == win->screen) {
+ if (sc == WM_window_get_active_screen(win)) {
wmWindow *prevwin = CTX_wm_window(C);
ScrArea *prevsa = CTX_wm_area(C);
ARegion *prevar = CTX_wm_region(C);
@@ -164,9 +198,12 @@ static void rna_Area_type_update(bContext *C, PointerRNA *ptr)
ED_area_newspace(C, sa, sa->butspacetype, true);
ED_area_tag_redraw(sa);
+ /* Unset so that rna_Area_type_get uses spacetype instead. */
+ sa->butspacetype = SPACE_EMPTY;
+
/* It is possible that new layers becomes visible. */
if (sa->spacetype == SPACE_VIEW3D) {
- DAG_on_visible_update(CTX_data_main(C), false);
+ DEG_on_visible_update(CTX_data_main(C), false);
}
CTX_wm_window_set(C, prevwin);
@@ -323,15 +360,23 @@ static void rna_def_region(BlenderRNA *brna)
StructRNA *srna;
PropertyRNA *prop;
+ static const EnumPropertyItem alignment_types[] = {
+ {RGN_ALIGN_NONE, "NONE", 0, "None", "Don't use any fixed alignment, fill available space"},
+ {RGN_ALIGN_TOP, "TOP", 0, "Top", ""},
+ {RGN_ALIGN_BOTTOM, "BOTTOM", 0, "Bottom", ""},
+ {RGN_ALIGN_LEFT, "LEFT", 0, "Left", ""},
+ {RGN_ALIGN_RIGHT, "RIGHT", 0, "Right", ""},
+ {RGN_ALIGN_HSPLIT, "HORIZONTAL_SPLIT", 0, "Horizontal Split", ""},
+ {RGN_ALIGN_VSPLIT, "VERTICAL_SPLIT", 0, "Vertical Split", ""},
+ {RGN_ALIGN_FLOAT, "FLOAT", 0, "Float", "Region floats on screen, doesn't use any fixed alignment"},
+ {RGN_ALIGN_QSPLIT, "QUAD_SPLIT", 0, "Quad Split", "Region is split horizontally and vertically"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
srna = RNA_def_struct(brna, "Region", NULL);
RNA_def_struct_ui_text(srna, "Region", "Region in a subdivided screen area");
RNA_def_struct_sdna(srna, "ARegion");
- prop = RNA_def_property(srna, "id", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "swinid");
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Region ID", "Unique ID for this region");
-
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "regiontype");
RNA_def_property_enum_items(prop, rna_enum_region_type_items);
@@ -364,6 +409,12 @@ static void rna_def_region(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_ui_text(prop, "View2D", "2D view of the region");
+ prop = RNA_def_property(srna, "alignment", PROP_ENUM, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_enum_items(prop, alignment_types);
+ RNA_def_property_enum_funcs(prop, "rna_region_alignment_get", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Alignment", "Alignment of the region within the area");
+
RNA_def_function(srna, "tag_redraw", "ED_region_tag_redraw");
}
@@ -377,13 +428,11 @@ static void rna_def_screen(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Screen", "Screen data-block, defining the layout of areas in a window");
RNA_def_struct_ui_icon(srna, ICON_SPLITSCREEN);
- /* pointers */
- prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
- RNA_def_property_pointer_funcs(prop, NULL, "rna_Screen_scene_set", NULL, NULL);
- RNA_def_property_ui_text(prop, "Scene", "Active scene to be edited in the screen");
- RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
- RNA_def_property_update(prop, 0, "rna_Screen_scene_update");
+ prop = RNA_def_property(srna, "layout_name", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_funcs(prop, "rna_Screen_layout_name_get", "rna_Screen_layout_name_length",
+ "rna_Screen_layout_name_set");
+ RNA_def_property_ui_text(prop, "Layout Name", "The name of the layout that refers to the screen");
+ RNA_def_struct_name_property(srna, prop);
/* collections */
prop = RNA_def_property(srna, "areas", PROP_COLLECTION, PROP_NONE);
diff --git a/source/blender/makesrna/intern/rna_sculpt_paint.c b/source/blender/makesrna/intern/rna_sculpt_paint.c
index 6dbfc3634b2..03a728120eb 100644
--- a/source/blender/makesrna/intern/rna_sculpt_paint.c
+++ b/source/blender/makesrna/intern/rna_sculpt_paint.c
@@ -106,10 +106,10 @@ const EnumPropertyItem rna_enum_symmetrize_direction_items[] = {
#include "BKE_DerivedMesh.h"
#include "BKE_pointcache.h"
#include "BKE_particle.h"
-#include "BKE_depsgraph.h"
#include "BKE_pbvh.h"
+#include "BKE_object.h"
-#include "GPU_buffers.h"
+#include "DEG_depsgraph.h"
#include "ED_particle.h"
@@ -152,9 +152,11 @@ static PointerRNA rna_ParticleBrush_curve_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_CurveMapping, NULL);
}
-static void rna_ParticleEdit_redo(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_ParticleEdit_redo(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = (scene->basact) ? scene->basact->object : NULL;
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
PTCacheEdit *edit = PE_get_current(scene, ob);
if (!edit)
@@ -163,21 +165,23 @@ static void rna_ParticleEdit_redo(Main *UNUSED(bmain), Scene *scene, PointerRNA
psys_free_path_cache(edit->psys, edit);
}
-static void rna_ParticleEdit_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_ParticleEdit_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = (scene->basact) ? scene->basact->object : NULL;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
- if (ob) DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ if (ob) DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
+
static void rna_ParticleEdit_tool_set(PointerRNA *ptr, int value)
{
ParticleEditSettings *pset = (ParticleEditSettings *)ptr->data;
/* redraw hair completely if weight brush is/was used */
- if ((pset->brushtype == PE_BRUSH_WEIGHT || value == PE_BRUSH_WEIGHT) && pset->scene) {
- Object *ob = (pset->scene->basact) ? pset->scene->basact->object : NULL;
+ if ((pset->brushtype == PE_BRUSH_WEIGHT || value == PE_BRUSH_WEIGHT) && pset->object) {
+ Object *ob = pset->object;
if (ob) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
}
}
@@ -187,9 +191,10 @@ static void rna_ParticleEdit_tool_set(PointerRNA *ptr, int value)
static const EnumPropertyItem *rna_ParticleEdit_tool_itemf(bContext *C, PointerRNA *UNUSED(ptr),
PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
{
- Scene *scene = CTX_data_scene(C);
- Object *ob = (scene->basact) ? scene->basact->object : NULL;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
#if 0
+ Scene *scene = CTX_data_scene(C);
PTCacheEdit *edit = PE_get_current(scene, ob);
ParticleSystem *psys = edit ? edit->psys : NULL;
#else
@@ -257,12 +262,14 @@ static int rna_Brush_mode_poll(PointerRNA *ptr, PointerRNA value)
return brush->ob_mode & mode;
}
-static void rna_Sculpt_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_Sculpt_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = (scene->basact) ? scene->basact->object : NULL;
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
if (ob) {
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
WM_main_add_notifier(NC_OBJECT | ND_MODIFIER, ob);
if (ob->sculpt) {
@@ -272,11 +279,13 @@ static void rna_Sculpt_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNU
}
}
-static void rna_Sculpt_ShowDiffuseColor_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_Sculpt_ShowDiffuseColor_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = (scene->basact) ? scene->basact->object : NULL;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
if (ob && ob->sculpt) {
+ Scene *scene = CTX_data_scene(C);
Sculpt *sd = scene->toolsettings->sculpt;
ob->sculpt->show_diffuse_color = ((sd->flags & SCULPT_SHOW_DIFFUSE) != 0);
@@ -287,12 +296,14 @@ static void rna_Sculpt_ShowDiffuseColor_update(Main *UNUSED(bmain), Scene *scene
}
}
-static void rna_Sculpt_ShowMask_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_Sculpt_ShowMask_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *object = (scene->basact) ? scene->basact->object : NULL;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *object = OBACT(view_layer);
if (object == NULL || object->sculpt == NULL) {
return;
}
+ Scene *scene = CTX_data_scene(C);
Sculpt *sd = scene->toolsettings->sculpt;
object->sculpt->show_mask = ((sd->flags & SCULPT_HIDE_MASK) == 0);
if (object->sculpt->pbvh != NULL) {
@@ -347,55 +358,60 @@ static void rna_ImaPaint_viewport_update(Main *UNUSED(bmain), Scene *UNUSED(scen
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
-static void rna_ImaPaint_mode_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_ImaPaint_mode_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = OBACT;
+ Scene *scene = CTX_data_scene(C);\
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
if (ob && ob->type == OB_MESH) {
/* of course we need to invalidate here */
BKE_texpaint_slots_refresh_object(scene, ob);
/* we assume that changing the current mode will invalidate the uv layers so we need to refresh display */
- GPU_drawobject_free(ob->derivedFinal);
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
}
-static void rna_ImaPaint_stencil_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_ImaPaint_stencil_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = OBACT;
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
if (ob && ob->type == OB_MESH) {
- GPU_drawobject_free(ob->derivedFinal);
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
}
-static void rna_ImaPaint_canvas_update(Main *bmain, Scene *scene, PointerRNA *UNUSED(ptr))
+static void rna_ImaPaint_canvas_update(bContext *C, PointerRNA *UNUSED(ptr))
{
- Object *ob = OBACT;
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
+ Object *obedit = OBEDIT_FROM_OBACT(ob);
bScreen *sc;
Image *ima = scene->toolsettings->imapaint.canvas;
for (sc = bmain->screen.first; sc; sc = sc->id.next) {
ScrArea *sa;
for (sa = sc->areabase.first; sa; sa = sa->next) {
- SpaceLink *sl;
- for (sl = sa->spacedata.first; sl; sl = sl->next) {
- if (sl->spacetype == SPACE_IMAGE) {
- SpaceImage *sima = (SpaceImage *)sl;
+ SpaceLink *slink;
+ for (slink = sa->spacedata.first; slink; slink = slink->next) {
+ if (slink->spacetype == SPACE_IMAGE) {
+ SpaceImage *sima = (SpaceImage *)slink;
if (!sima->pin)
- ED_space_image_set(sima, scene, scene->obedit, ima);
+ ED_space_image_set(sima, scene, obedit, ima);
}
}
}
}
if (ob && ob->type == OB_MESH) {
- GPU_drawobject_free(ob->derivedFinal);
BKE_paint_proj_mesh_data_check(scene, ob, NULL, NULL, NULL, NULL);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
@@ -600,17 +616,20 @@ static void rna_def_sculpt(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Use Deform Only",
"Use only deformation modifiers (temporary disable all "
"constructive modifiers except multi-resolution)");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_update");
prop = RNA_def_property(srna, "show_diffuse_color", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flags", SCULPT_SHOW_DIFFUSE);
RNA_def_property_ui_text(prop, "Show Diffuse Color",
"Show diffuse color of object and overlay sculpt mask on top of it");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_ShowDiffuseColor_update");
prop = RNA_def_property(srna, "show_mask", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flags", SCULPT_HIDE_MASK);
RNA_def_property_ui_text(prop, "Show Mask", "Show mask as overlay on object");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_ShowMask_update");
prop = RNA_def_property(srna, "detail_size", PROP_FLOAT, PROP_PIXEL);
@@ -636,6 +655,7 @@ static void rna_def_sculpt(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Smooth Shading",
"Show faces in dynamic-topology mode with smooth "
"shading rather than flat shaded");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_Sculpt_update");
prop = RNA_def_property(srna, "symmetrize_direction", PROP_ENUM, PROP_NONE);
@@ -761,12 +781,12 @@ static void rna_def_image_paint(BlenderRNA *brna)
prop = RNA_def_property(srna, "stencil_image", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "stencil");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Stencil Image", "Image used as stencil");
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ImaPaint_stencil_update");
prop = RNA_def_property(srna, "canvas", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Canvas", "Image used as canvas");
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ImaPaint_canvas_update");
@@ -808,6 +828,7 @@ static void rna_def_image_paint(BlenderRNA *brna)
RNA_def_property_range(prop, 512, 16384);
prop = RNA_def_property(srna, "mode", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_enum_items(prop, paint_type_items);
RNA_def_property_ui_text(prop, "Mode", "Mode of operation for projection painting");
RNA_def_property_update(prop, NC_SCENE | ND_TOOLSETTINGS, "rna_ImaPaint_mode_update");
@@ -887,6 +908,7 @@ static void rna_def_particle_edit(BlenderRNA *brna)
RNA_def_property_enum_bitflag_sdna(prop, NULL, "selectmode");
RNA_def_property_enum_items(prop, select_mode_items);
RNA_def_property_ui_text(prop, "Selection Mode", "Particle select and display mode");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ParticleEdit_update");
prop = RNA_def_property(srna, "use_preserve_length", PROP_BOOLEAN, PROP_NONE);
@@ -909,6 +931,7 @@ static void rna_def_particle_edit(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_fade_time", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", PE_FADE_TIME);
RNA_def_property_ui_text(prop, "Fade Time", "Fade paths and keys further away from current frame");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ParticleEdit_update");
prop = RNA_def_property(srna, "use_auto_velocity", PROP_BOOLEAN, PROP_NONE);
@@ -916,6 +939,7 @@ static void rna_def_particle_edit(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Auto Velocity", "Calculate point velocities automatically");
prop = RNA_def_property(srna, "show_particles", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_boolean_sdna(prop, NULL, "flag", PE_DRAW_PART);
RNA_def_property_ui_text(prop, "Draw Particles", "Draw actual particles");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ParticleEdit_redo");
@@ -936,6 +960,7 @@ static void rna_def_particle_edit(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Brush", "");
prop = RNA_def_property(srna, "draw_step", PROP_INT, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_range(prop, 1, 10);
RNA_def_property_ui_text(prop, "Steps", "How many steps to draw the path with");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ParticleEdit_redo");
@@ -943,9 +968,11 @@ static void rna_def_particle_edit(BlenderRNA *brna)
prop = RNA_def_property(srna, "fade_frames", PROP_INT, PROP_NONE);
RNA_def_property_range(prop, 1, 100);
RNA_def_property_ui_text(prop, "Frames", "How many frames to fade");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ParticleEdit_update");
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_enum_sdna(prop, NULL, "edittype");
RNA_def_property_enum_items(prop, edit_type_items);
RNA_def_property_ui_text(prop, "Type", "");
@@ -966,7 +993,7 @@ static void rna_def_particle_edit(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Object", "The edited object");
prop = RNA_def_property(srna, "shape_object", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Shape Object", "Outer shape to use for tools");
RNA_def_property_pointer_funcs(prop, NULL, NULL, NULL, "rna_Mesh_object_poll");
RNA_def_property_update(prop, NC_OBJECT | ND_DRAW, "rna_ParticleEdit_redo");
diff --git a/source/blender/makesrna/intern/rna_sensor.c b/source/blender/makesrna/intern/rna_sensor.c
deleted file mode 100644
index 735df471721..00000000000
--- a/source/blender/makesrna/intern/rna_sensor.c
+++ /dev/null
@@ -1,939 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Blender Foundation (2008).
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/makesrna/intern/rna_sensor.c
- * \ingroup RNA
- */
-
-#include <stdlib.h>
-
-#include "DNA_constraint_types.h"
-#include "DNA_object_types.h"
-#include "DNA_sensor_types.h"
-
-#include "BLI_utildefines.h"
-#include "BLI_math.h"
-#include "BLI_string_utils.h"
-
-#include "BLT_translation.h"
-
-#include "RNA_define.h"
-#include "RNA_enum_types.h"
-#include "RNA_access.h"
-
-#include "rna_internal.h"
-
-#include "WM_types.h"
-
-/* Always keep in alphabetical order */
-static const EnumPropertyItem sensor_type_items[] = {
- {SENS_ACTUATOR, "ACTUATOR", 0, "Actuator", ""},
- {SENS_ALWAYS, "ALWAYS", 0, "Always", ""},
- {SENS_ARMATURE, "ARMATURE", 0, "Armature", ""},
- {SENS_COLLISION, "COLLISION", 0, "Collision", ""},
- {SENS_DELAY, "DELAY", 0, "Delay", ""},
- {SENS_JOYSTICK, "JOYSTICK", 0, "Joystick", ""},
- {SENS_KEYBOARD, "KEYBOARD", 0, "Keyboard", ""},
- {SENS_MESSAGE, "MESSAGE", 0, "Message", ""},
- {SENS_MOUSE, "MOUSE", 0, "Mouse", ""},
- {SENS_NEAR, "NEAR", 0, "Near", ""},
- {SENS_PROPERTY, "PROPERTY", 0, "Property", ""},
- {SENS_RADAR, "RADAR", 0, "Radar", ""},
- {SENS_RANDOM, "RANDOM", 0, "Random", ""},
- {SENS_RAY, "RAY", 0, "Ray", ""},
- {0, NULL, 0, NULL, NULL}
-};
-
-#ifdef RNA_RUNTIME
-
-#include "BKE_sca.h"
-#include "DNA_controller_types.h"
-
-static StructRNA *rna_Sensor_refine(struct PointerRNA *ptr)
-{
- bSensor *sensor = (bSensor *)ptr->data;
-
- switch (sensor->type) {
- case SENS_ALWAYS:
- return &RNA_AlwaysSensor;
- case SENS_NEAR:
- return &RNA_NearSensor;
- case SENS_KEYBOARD:
- return &RNA_KeyboardSensor;
- case SENS_PROPERTY:
- return &RNA_PropertySensor;
- case SENS_ARMATURE:
- return &RNA_ArmatureSensor;
- case SENS_MOUSE:
- return &RNA_MouseSensor;
- case SENS_COLLISION:
- return &RNA_CollisionSensor;
- case SENS_RADAR:
- return &RNA_RadarSensor;
- case SENS_RANDOM:
- return &RNA_RandomSensor;
- case SENS_RAY:
- return &RNA_RaySensor;
- case SENS_MESSAGE:
- return &RNA_MessageSensor;
- case SENS_JOYSTICK:
- return &RNA_JoystickSensor;
- case SENS_ACTUATOR:
- return &RNA_ActuatorSensor;
- case SENS_DELAY:
- return &RNA_DelaySensor;
- default:
- return &RNA_Sensor;
- }
-}
-
-static void rna_Sensor_name_set(PointerRNA *ptr, const char *value)
-{
- Object *ob = ptr->id.data;
- bSensor *sens = ptr->data;
- BLI_strncpy_utf8(sens->name, value, sizeof(sens->name));
- BLI_uniquename(&ob->sensors, sens, DATA_("Sensor"), '.', offsetof(bSensor, name), sizeof(sens->name));
-}
-
-static void rna_Sensor_type_set(struct PointerRNA *ptr, int value)
-{
- bSensor *sens = (bSensor *)ptr->data;
- if (value != sens->type) {
- sens->type = value;
- init_sensor(sens);
- }
-}
-
-/* Always keep in alphabetical order */
-
-static void rna_Sensor_controllers_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
-{
- bSensor *sens = (bSensor *)ptr->data;
- rna_iterator_array_begin(iter, sens->links, sizeof(bController *), (int)sens->totlinks, 0, NULL);
-}
-
-static int rna_Sensor_controllers_length(PointerRNA *ptr)
-{
- bSensor *sens = (bSensor *)ptr->data;
- return (int) sens->totlinks;
-}
-
-const EnumPropertyItem *rna_Sensor_type_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
-{
- EnumPropertyItem *item = NULL;
- Object *ob = NULL;
- int totitem = 0;
-
- if (ptr->type == &RNA_Sensor || RNA_struct_is_a(ptr->type, &RNA_Sensor)) {
- ob = (Object *)ptr->id.data;
- }
- else {
- /* can't use ob from ptr->id.data because that enum is also used by operators */
- ob = CTX_data_active_object(C);
- }
-
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ACTUATOR);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ALWAYS);
-
- if (ob != NULL) {
- if (ob->type == OB_ARMATURE) {
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_ARMATURE);
- }
- }
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_COLLISION);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_DELAY);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_JOYSTICK);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_KEYBOARD);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MESSAGE);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_MOUSE);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_NEAR);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_PROPERTY);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RADAR);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RANDOM);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_RAY);
- RNA_enum_items_add_value(&item, &totitem, sensor_type_items, SENS_TOUCH);
-
- RNA_enum_item_end(&item, &totitem);
- *r_free = true;
-
- return item;
-}
-
-static void rna_Sensor_keyboard_key_set(struct PointerRNA *ptr, int value)
-{
- bSensor *sens = (bSensor *)ptr->data;
- bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
-
- if (ISKEYBOARD(value))
- ks->key = value;
- else
- ks->key = 0;
-}
-
-static void rna_Sensor_keyboard_modifier_set(struct PointerRNA *ptr, int value)
-{
- bSensor *sens = (bSensor *)ptr->data;
- bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
-
- if (ISKEYBOARD(value))
- ks->qual = value;
- else
- ks->qual = 0;
-}
-
-static void rna_Sensor_keyboard_modifier2_set(struct PointerRNA *ptr, int value)
-{
- bSensor *sens = (bSensor *)ptr->data;
- bKeyboardSensor *ks = (bKeyboardSensor *)sens->data;
-
- if (ISKEYBOARD(value))
- ks->qual2 = value;
- else
- ks->qual2 = 0;
-}
-
-static void rna_Sensor_tap_set(struct PointerRNA *ptr, int value)
-{
- bSensor *sens = (bSensor *)ptr->data;
-
- sens->tap = value;
- if (sens->tap == 1)
- sens->level = 0;
-}
-
-static void rna_Sensor_level_set(struct PointerRNA *ptr, int value)
-{
- bSensor *sens = (bSensor *)ptr->data;
-
- sens->level = value;
- if (sens->level == 1)
- sens->tap = 0;
-}
-
-static void rna_Sensor_Armature_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
-{
- bSensor *sens = (bSensor *)ptr->data;
- bArmatureSensor *as = sens->data;
- Object *ob = (Object *)ptr->id.data;
-
- char *posechannel = as->posechannel;
- char *constraint = as->constraint;
-
- /* check that bone exist in the active object */
- if (ob->type == OB_ARMATURE && ob->pose) {
- bPoseChannel *pchan;
- bPose *pose = ob->pose;
- for (pchan = pose->chanbase.first; pchan; pchan = pchan->next) {
- if (STREQ(pchan->name, posechannel)) {
- /* found it, now look for constraint channel */
- bConstraint *con;
- for (con = pchan->constraints.first; con; con = con->next) {
- if (STREQ(con->name, constraint)) {
- /* found it, all ok */
- return;
- }
- }
- /* didn't find constraint, make empty */
- constraint[0] = 0;
- return;
- }
- }
- }
- /* didn't find any */
- posechannel[0] = 0;
- constraint[0] = 0;
-}
-#else
-
-static void rna_def_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "Sensor", NULL);
- RNA_def_struct_ui_text(srna, "Sensor", "Game engine logic brick to detect events");
- RNA_def_struct_sdna(srna, "bSensor");
- RNA_def_struct_refine_func(srna, "rna_Sensor_refine");
-
- prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Name", "Sensor name");
- RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Sensor_name_set");
- RNA_def_struct_name_property(srna, prop);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
- RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
- RNA_def_property_enum_items(prop, sensor_type_items);
- RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_type_set", "rna_Sensor_type_itemf");
- RNA_def_property_ui_text(prop, "Type", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "pin", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_PIN);
- RNA_def_property_ui_text(prop, "Pinned", "Display when not linked to a visible states controller");
- RNA_def_property_ui_icon(prop, ICON_UNPINNED, 1);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SENS_DEACTIVATE);
- RNA_def_property_ui_text(prop, "Active", "Set active state of the sensor");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_SHOW);
- RNA_def_property_ui_text(prop, "Expanded", "Set sensor expanded in the user interface");
- RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_ui_text(prop, "Invert Output", "Invert the level(output) of this sensor");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_level", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "level", 1);
- RNA_def_property_ui_text(prop, "Level",
- "Level detector, trigger controllers of new states "
- "(only applicable upon logic state transition)");
- RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_level_set");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_pulse_true_level", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_PULSE_REPEAT);
- RNA_def_property_ui_text(prop, "Pulse True Level", "Activate TRUE level triggering (pulse mode)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_pulse_false_level", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "pulse", SENS_NEG_PULSE_MODE);
- RNA_def_property_ui_text(prop, "Pulse False Level", "Activate FALSE level triggering (pulse mode)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "tick_skip", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "freq");
- RNA_def_property_ui_text(prop, "Skip",
- "Number of logic ticks skipped between 2 active pulses "
- "(0 = pulse every logic tick, 1 = skip 1 logic tick between pulses, etc.)");
- RNA_def_property_range(prop, 0, 10000);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_tap", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "tap", 1);
- RNA_def_property_boolean_funcs(prop, NULL, "rna_Sensor_tap_set");
- RNA_def_property_ui_text(prop, "Tap",
- "Trigger controllers only for an instant, even while the sensor remains true");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "controllers", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "links", NULL);
- RNA_def_property_struct_type(prop, "Controller");
- RNA_def_property_ui_text(prop, "Controllers", "The list containing the controllers connected to the sensor");
- RNA_def_property_collection_funcs(prop, "rna_Sensor_controllers_begin", "rna_iterator_array_next",
- "rna_iterator_array_end", "rna_iterator_array_dereference_get",
- "rna_Sensor_controllers_length", NULL, NULL, NULL);
-
-
- RNA_api_sensor(srna);
-}
-
-static void rna_def_always_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- srna = RNA_def_struct(brna, "AlwaysSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Always Sensor", "Sensor to generate continuous pulses");
-}
-
-static void rna_def_near_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "NearSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Near Sensor", "Sensor to detect nearby objects");
- RNA_def_struct_sdna_from(srna, "bNearSensor", "data");
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "name");
- RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "dist");
- RNA_def_property_ui_text(prop, "Distance", "Trigger distance");
- RNA_def_property_range(prop, 0.0f, 10000.0f);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "reset_distance", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "resetdist");
- RNA_def_property_ui_text(prop, "Reset Distance", "The distance where the sensor forgets the actor");
- RNA_def_property_range(prop, 0.0f, 10000.0f);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_mouse_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem mouse_event_items[] = {
- {BL_SENS_MOUSE_LEFT_BUTTON, "LEFTCLICK", 0, "Left Button", ""},
- {BL_SENS_MOUSE_MIDDLE_BUTTON, "MIDDLECLICK", 0, "Middle Button", ""},
- {BL_SENS_MOUSE_RIGHT_BUTTON, "RIGHTCLICK", 0, "Right Button", ""},
- {BL_SENS_MOUSE_WHEEL_UP, "WHEELUP", 0, "Wheel Up", ""},
- {BL_SENS_MOUSE_WHEEL_DOWN, "WHEELDOWN", 0, "Wheel Down", ""},
- {BL_SENS_MOUSE_MOVEMENT, "MOVEMENT", 0, "Movement", ""},
- {BL_SENS_MOUSE_MOUSEOVER, "MOUSEOVER", 0, "Mouse Over", ""},
- {BL_SENS_MOUSE_MOUSEOVER_ANY, "MOUSEOVERANY", 0, "Mouse Over Any", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_mouse_type_items[] = {
- {SENS_COLLISION_PROPERTY, "PROPERTY", ICON_LOGIC, "Property", "Use a property for ray intersections"},
- {SENS_COLLISION_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Use a material for ray intersections"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "MouseSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Mouse Sensor", "Sensor to detect mouse events");
- RNA_def_struct_sdna_from(srna, "bMouseSensor", "data");
-
- prop = RNA_def_property(srna, "mouse_event", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, mouse_event_items);
- RNA_def_property_ui_text(prop, "Mouse Event", "Type of event this mouse sensor should trigger on");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_pulse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_MOUSE_FOCUS_PULSE);
- RNA_def_property_ui_text(prop, "Pulse", "Moving the mouse over a different object generates a pulse");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_material", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, prop_mouse_type_items);
- RNA_def_property_ui_text(prop, "M/P", "Toggle collision on material or property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "propname");
- RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "matname");
- RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_x_ray", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_RAY_XRAY);
- RNA_def_property_ui_text(prop, "X-Ray", "Toggle X-Ray option (see through objects that don't have the property)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_keyboard_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "KeyboardSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Keyboard Sensor", "Sensor to detect keyboard events");
- RNA_def_struct_sdna_from(srna, "bKeyboardSensor", "data");
-
- prop = RNA_def_property(srna, "key", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "key");
- RNA_def_property_enum_items(prop, rna_enum_event_type_items);
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
- RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_key_set", NULL);
- RNA_def_property_ui_text(prop, "Key", "");
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_ID_WINDOWMANAGER);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "modifier_key_1", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "qual");
- RNA_def_property_enum_items(prop, rna_enum_event_type_items);
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
- RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier_set", NULL);
- RNA_def_property_ui_text(prop, "Modifier Key", "Modifier key code");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "modifier_key_2", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "qual2");
- RNA_def_property_enum_items(prop, rna_enum_event_type_items);
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
- RNA_def_property_enum_funcs(prop, NULL, "rna_Sensor_keyboard_modifier2_set", NULL);
- RNA_def_property_ui_text(prop, "Second Modifier Key", "Modifier key code");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "target", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "targetName");
- RNA_def_property_ui_text(prop, "Target", "Property that receives the keystrokes in case a string is logged");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "log", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "toggleName");
- RNA_def_property_ui_text(prop, "Log Toggle", "Property that indicates whether to log keystrokes as a string");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_all_keys", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "type", 1);
- RNA_def_property_ui_text(prop, "All Keys", "Trigger this sensor on any keystroke");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_property_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
- static const EnumPropertyItem prop_type_items[] = {
- {SENS_PROP_EQUAL, "PROPEQUAL", 0, "Equal", ""},
- {SENS_PROP_NEQUAL, "PROPNEQUAL", 0, "Not Equal", ""},
- {SENS_PROP_INTERVAL, "PROPINTERVAL", 0, "Interval", ""},
- {SENS_PROP_CHANGED, "PROPCHANGED", 0, "Changed", ""},
- /* {SENS_PROP_EXPRESSION, "PROPEXPRESSION", 0, "Expression", ""}, NOT_USED_IN_UI */
- {SENS_PROP_LESSTHAN, "PROPLESSTHAN", 0, "Less Than", ""},
- {SENS_PROP_GREATERTHAN, "PROPGREATERTHAN", 0, "Greater Than", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "PropertySensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Property Sensor", "Sensor to detect values and changes in values of properties");
- RNA_def_struct_sdna_from(srna, "bPropertySensor", "data");
-
- prop = RNA_def_property(srna, "evaluation_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Evaluation Type", "Type of property evaluation");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "name");
- RNA_def_property_ui_text(prop, "Property", "");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "value", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "value");
- RNA_def_property_ui_text(prop, "Value", "Check for this value in types in Equal, Not Equal, Less Than and Greater Than types");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "value_min", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "value");
- RNA_def_property_ui_text(prop, "Minimum Value", "Minimum value in Interval type");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "value_max", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "maxvalue");
- RNA_def_property_ui_text(prop, "Maximum Value", "Maximum value in Interval type");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_armature_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
- static const EnumPropertyItem prop_type_items[] = {
- {SENS_ARM_STATE_CHANGED, "STATECHG", 0, "State Changed", ""},
- {SENS_ARM_LIN_ERROR_BELOW, "LINERRORBELOW", 0, "Lin error below", ""},
- {SENS_ARM_LIN_ERROR_ABOVE, "LINERRORABOVE", 0, "Lin error above", ""},
- {SENS_ARM_ROT_ERROR_BELOW, "ROTERRORBELOW", 0, "Rot error below", ""},
- {SENS_ARM_ROT_ERROR_ABOVE, "ROTERRORABOVE", 0, "Rot error above", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "ArmatureSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Armature Sensor", "Sensor to detect values and changes in values of IK solver");
- RNA_def_struct_sdna_from(srna, "bArmatureSensor", "data");
-
- prop = RNA_def_property(srna, "test_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_type_items);
- RNA_def_property_ui_text(prop, "Test", "Type of value and test");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "bone", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "posechannel");
- RNA_def_property_ui_text(prop, "Bone Name", "Identify the bone to check value from");
- RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
-
- prop = RNA_def_property(srna, "constraint", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "constraint");
- RNA_def_property_ui_text(prop, "Constraint Name", "Identify the bone constraint to check value from");
- RNA_def_property_update(prop, NC_LOGIC, "rna_Sensor_Armature_update");
-
- prop = RNA_def_property(srna, "value", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "value");
- RNA_def_property_ui_text(prop, "Compare Value", "Value to be used in comparison");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_actuator_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "ActuatorSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Actuator Sensor", "Sensor to detect state modifications of actuators");
- RNA_def_struct_sdna_from(srna, "bActuatorSensor", "data");
-
- /* XXX if eventually have Logics using RNA 100%, we could use the actuator data-block isntead of its name */
- prop = RNA_def_property(srna, "actuator", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "name");
- RNA_def_property_ui_text(prop, "Actuator", "Actuator name, actuator active state modifications will be detected");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_delay_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "DelaySensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Delay Sensor", "Sensor to send delayed events");
- RNA_def_struct_sdna_from(srna, "bDelaySensor", "data");
-
- prop = RNA_def_property(srna, "delay", PROP_INT, PROP_NONE);
- RNA_def_property_ui_text(prop, "Delay",
- "Delay in number of logic tics before the positive trigger (default 60 per second)");
- RNA_def_property_range(prop, 0, 5000);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "duration", PROP_INT, PROP_NONE);
- RNA_def_property_ui_text(prop, "Duration",
- "If >0, delay in number of logic tics before the negative trigger following "
- "the positive trigger");
- RNA_def_property_range(prop, 0, 5000);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_repeat", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_DELAY_REPEAT);
- RNA_def_property_ui_text(prop, "Repeat",
- "Toggle repeat option (if selected, the sensor restarts after Delay+Duration "
- "logic tics)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_collision_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "CollisionSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Collision Sensor",
- "Sensor to detect objects colliding with the current object, with more settings than "
- "the Touch sensor");
- RNA_def_struct_sdna_from(srna, "bCollisionSensor", "data");
-
- prop = RNA_def_property(srna, "use_pulse", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_PULSE);
- RNA_def_property_ui_text(prop, "Pulse", "Change to the set of colliding objects generates pulse");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_material", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_COLLISION_MATERIAL);
- RNA_def_property_ui_text(prop, "M/P", "Toggle collision on material or property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "name");
- RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /*XXX to make a setFunction to create a lookup with all materials in Blend File (not only this object mat.) */
- prop = RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "materialName");
- RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
-#if 0
- /* XXX either use a data-block look up to store the string name (material)
- * or to do a doversion and use a material pointer. */
- prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Material");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_pointer_sdna(prop, NULL, "ma");
- RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
-#endif
-}
-
-static void rna_def_radar_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
- static const EnumPropertyItem axis_items[] = {
- {SENS_RADAR_X_AXIS, "XAXIS", 0, "+X axis", ""},
- {SENS_RADAR_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
- {SENS_RADAR_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
- {SENS_RADAR_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
- {SENS_RADAR_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
- {SENS_RADAR_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "RadarSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Radar Sensor",
- "Sensor to detect objects in a cone shaped radar emanating from the current object");
- RNA_def_struct_sdna_from(srna, "bRadarSensor", "data");
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "name");
- RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, axis_items);
- RNA_def_property_ui_text(prop, "Axis", "Along which axis the radar cone is cast");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "angle", PROP_FLOAT, PROP_ANGLE);
- RNA_def_property_range(prop, 0.0, DEG2RADF(179.9f));
- RNA_def_property_ui_text(prop, "Angle", "Opening angle of the radar cone");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "range");
- RNA_def_property_range(prop, 0.0, 10000.0);
- RNA_def_property_ui_text(prop, "Distance", "Depth of the radar cone");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_random_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "RandomSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Random Sensor", "Sensor to send random events");
- RNA_def_struct_sdna_from(srna, "bRandomSensor", "data");
-
- prop = RNA_def_property(srna, "seed", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 0, 1000);
- RNA_def_property_ui_text(prop, "Seed", "Initial seed of the generator (choose 0 for not random)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_ray_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
- static const EnumPropertyItem axis_items[] = {
- {SENS_RAY_X_AXIS, "XAXIS", 0, "+X axis", ""},
- {SENS_RAY_Y_AXIS, "YAXIS", 0, "+Y axis", ""},
- {SENS_RAY_Z_AXIS, "ZAXIS", 0, "+Z axis", ""},
- {SENS_RAY_NEG_X_AXIS, "NEGXAXIS", 0, "-X axis", ""},
- {SENS_RAY_NEG_Y_AXIS, "NEGYAXIS", 0, "-Y axis", ""},
- {SENS_RAY_NEG_Z_AXIS, "NEGZAXIS", 0, "-Z axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_ray_type_items[] = {
- {SENS_COLLISION_PROPERTY, "PROPERTY", ICON_LOGIC, "Property", "Use a property for ray intersections"},
- {SENS_COLLISION_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Use a material for ray intersections"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "RaySensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Ray Sensor",
- "Sensor to detect intersections with a ray emanating from the current object");
- RNA_def_struct_sdna_from(srna, "bRaySensor", "data");
-
- prop = RNA_def_property(srna, "ray_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "mode");
- RNA_def_property_enum_items(prop, prop_ray_type_items);
- RNA_def_property_ui_text(prop, "Ray Type", "Toggle collision on material or property");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "property", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "propname");
- RNA_def_property_ui_text(prop, "Property", "Only look for objects with this property (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "material", PROP_STRING, PROP_NONE);
- RNA_def_property_string_sdna(prop, NULL, "matname");
- RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
-#if 0
- /* XXX either use a data-block look up to store the string name (material)
- * or to do a doversion and use a material pointer. */
- prop = RNA_def_property(srna, "material", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "Material");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_pointer_sdna(prop, NULL, "ma");
- RNA_def_property_ui_text(prop, "Material", "Only look for objects with this material (blank = all objects)");
-#endif
-
- prop = RNA_def_property(srna, "use_x_ray", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", SENS_RAY_XRAY);
- RNA_def_property_ui_text(prop, "X-Ray Mode",
- "Toggle X-Ray option (see through objects that don't have the property)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "range", PROP_FLOAT, PROP_NONE);
- RNA_def_property_range(prop, 0.01, 10000.0);
- RNA_def_property_ui_text(prop, "Range", "Sense objects no farther than this distance");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "axisflag");
- RNA_def_property_enum_items(prop, axis_items);
- RNA_def_property_ui_text(prop, "Axis", "Along which axis the ray is cast");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_message_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "MessageSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Message Sensor", "Sensor to detect incoming messages");
- RNA_def_struct_sdna_from(srna, "bMessageSensor", "data");
-
- prop = RNA_def_property(srna, "subject", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Subject",
- "Optional subject filter: only accept messages with this subject, "
- "or empty to accept all");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-static void rna_def_joystick_sensor(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem event_type_joystick_items[] = {
- {SENS_JOY_BUTTON, "BUTTON", 0, "Button", ""},
- {SENS_JOY_AXIS, "AXIS", 0, "Axis", ""},
- {SENS_JOY_HAT, "HAT", 0, "Hat", ""},
- {SENS_JOY_AXIS_SINGLE, "AXIS_SINGLE", 0, "Single Axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem axis_direction_items[] = {
- {SENS_JOY_X_AXIS, "RIGHTAXIS", 0, "Right Axis", ""},
- {SENS_JOY_Y_AXIS, "UPAXIS", 0, "Up Axis", ""},
- {SENS_JOY_NEG_X_AXIS, "LEFTAXIS", 0, "Left Axis", ""},
- {SENS_JOY_NEG_Y_AXIS, "DOWNAXIS", 0, "Down Axis", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem hat_direction_items[] = {
- {SENS_JOY_HAT_UP, "UP", 0, "Up", ""},
- {SENS_JOY_HAT_DOWN, "DOWN", 0, "Down", ""},
- {SENS_JOY_HAT_LEFT, "LEFT", 0, "Left", ""},
- {SENS_JOY_HAT_RIGHT, "RIGHT", 0, "Right", ""},
-
- {SENS_JOY_HAT_UP_RIGHT, "UPRIGHT", 0, "Up/Right", ""},
- {SENS_JOY_HAT_DOWN_LEFT, "DOWNLEFT", 0, "Down/Left", ""},
- {SENS_JOY_HAT_UP_LEFT, "UPLEFT", 0, "Up/Left", ""},
- {SENS_JOY_HAT_DOWN_RIGHT, "DOWNRIGHT", 0, "Down/Right", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "JoystickSensor", "Sensor");
- RNA_def_struct_ui_text(srna, "Joystick Sensor", "Sensor to detect joystick events");
- RNA_def_struct_sdna_from(srna, "bJoystickSensor", "data");
-
- prop = RNA_def_property(srna, "joystick_index", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "joyindex");
- RNA_def_property_ui_text(prop, "Index", "Which joystick to use");
- RNA_def_property_range(prop, 0, SENS_JOY_MAXINDEX - 1);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "event_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, event_type_joystick_items);
- RNA_def_property_translation_context(prop, BLT_I18NCONTEXT_UI_EVENTS);
- RNA_def_property_ui_text(prop, "Event Type", "The type of event this joystick sensor is triggered on");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "use_all_events", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SENS_JOY_ANY_EVENT);
- RNA_def_property_ui_text(prop, "All Events",
- "Triggered by all events on this joystick's current type (axis/button/hat)");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Button */
- prop = RNA_def_property(srna, "button_number", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "button");
- RNA_def_property_ui_text(prop, "Button Number", "Which button to use");
- RNA_def_property_range(prop, 0, 18);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Axis */
- prop = RNA_def_property(srna, "axis_number", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "axis");
- RNA_def_property_ui_text(prop, "Axis Number", "Which axis pair to use, 1 is usually the main direction input");
- RNA_def_property_range(prop, 1, 8);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "axis_threshold", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "precision");
- RNA_def_property_ui_text(prop, "Axis Threshold", "Precision of the axis");
- RNA_def_property_range(prop, 0, 32768);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "axis_direction", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "axisf");
- RNA_def_property_enum_items(prop, axis_direction_items);
- RNA_def_property_ui_text(prop, "Axis Direction", "The direction of the axis");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Single Axis */
- prop = RNA_def_property(srna, "single_axis_number", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "axis_single");
- RNA_def_property_ui_text(prop, "Axis Number", "Single axis (vertical/horizontal/other) to detect");
- RNA_def_property_range(prop, 1, 16);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* Hat */
- prop = RNA_def_property(srna, "hat_number", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "hat");
- RNA_def_property_ui_text(prop, "Hat Number", "Which hat to use");
- RNA_def_property_range(prop, 1, 2);
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "hat_direction", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "hatf");
- RNA_def_property_enum_items(prop, hat_direction_items);
- RNA_def_property_ui_text(prop, "Hat Direction", "Hat direction");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-}
-
-void RNA_def_sensor(BlenderRNA *brna)
-{
- rna_def_sensor(brna);
-
- rna_def_always_sensor(brna);
- rna_def_near_sensor(brna);
- rna_def_mouse_sensor(brna);
- rna_def_keyboard_sensor(brna);
- rna_def_property_sensor(brna);
- rna_def_armature_sensor(brna);
- rna_def_actuator_sensor(brna);
- rna_def_delay_sensor(brna);
- rna_def_collision_sensor(brna);
- rna_def_radar_sensor(brna);
- rna_def_random_sensor(brna);
- rna_def_ray_sensor(brna);
- rna_def_message_sensor(brna);
- rna_def_joystick_sensor(brna);
-}
-
-#endif
diff --git a/source/blender/makesrna/intern/rna_sensor_api.c b/source/blender/makesrna/intern/rna_sensor_api.c
deleted file mode 100644
index b0c4109b1df..00000000000
--- a/source/blender/makesrna/intern/rna_sensor_api.c
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2010 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/makesrna/intern/rna_sensor_api.c
- * \ingroup RNA
- */
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "BLI_utildefines.h"
-
-#include "RNA_define.h"
-
-#include "rna_internal.h" /* own include */
-
-#include "WM_types.h"
-
-#ifdef RNA_RUNTIME
-
-#include "BKE_sca.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-
-static void rna_Sensor_link(bSensor *sens, bController *cont)
-{
- link_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks, sizeof(bController *));
-}
-
-static void rna_Sensor_unlink(bSensor *sens, bController *cont)
-{
- unlink_logicbricks((void **)&cont, (void ***)&(sens->links), &sens->totlinks);
-}
-
-#else
-
-void RNA_api_sensor(StructRNA *srna)
-{
- FunctionRNA *func;
- PropertyRNA *parm;
-
- func = RNA_def_function(srna, "link", "rna_Sensor_link");
- RNA_def_function_ui_description(func, "Link the sensor to a controller");
- parm = RNA_def_pointer(func, "controller", "Controller", "", "Controller to link to");
- RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- RNA_def_property_update(parm, NC_LOGIC, NULL);
-
- func = RNA_def_function(srna, "unlink", "rna_Sensor_unlink");
- RNA_def_function_ui_description(func, "Unlink the sensor from a controller");
- parm = RNA_def_pointer(func, "controller", "Controller", "", "Controller to unlink from");
- RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
- RNA_def_property_update(parm, NC_LOGIC, NULL);
-}
-
-#endif
-
diff --git a/source/blender/makesrna/intern/rna_smoke.c b/source/blender/makesrna/intern/rna_smoke.c
index 38c297def32..d5580ae35ad 100644
--- a/source/blender/makesrna/intern/rna_smoke.c
+++ b/source/blender/makesrna/intern/rna_smoke.c
@@ -54,21 +54,23 @@
#include "BKE_colorband.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_particle.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "smoke_API.h"
static void rna_Smoke_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
}
static void rna_Smoke_dependency_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
rna_Smoke_update(bmain, scene, ptr);
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
static void rna_Smoke_resetCache(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
@@ -76,7 +78,7 @@ static void rna_Smoke_resetCache(Main *UNUSED(bmain), Scene *UNUSED(scene), Poin
SmokeDomainSettings *settings = (SmokeDomainSettings *)ptr->data;
if (settings->smd && settings->smd->domain)
settings->point_cache[0]->flag |= PTCACHE_OUTDATED;
- DAG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
+ DEG_id_tag_update(ptr->id.data, OB_RECALC_DATA);
}
static void rna_Smoke_cachetype_set(struct PointerRNA *ptr, int value)
diff --git a/source/blender/makesrna/intern/rna_sound.c b/source/blender/makesrna/intern/rna_sound.c
index 6aacede5816..0c1391fd2f7 100644
--- a/source/blender/makesrna/intern/rna_sound.c
+++ b/source/blender/makesrna/intern/rna_sound.c
@@ -32,7 +32,6 @@
#include "rna_internal.h"
#include "DNA_sound_types.h"
-#include "DNA_property_types.h"
#ifdef RNA_RUNTIME
diff --git a/source/blender/makesrna/intern/rna_space.c b/source/blender/makesrna/intern/rna_space.c
index d6a304f4dfe..8dba90d0a2b 100644
--- a/source/blender/makesrna/intern/rna_space.c
+++ b/source/blender/makesrna/intern/rna_space.c
@@ -45,6 +45,7 @@
#include "DNA_sequence_types.h"
#include "DNA_mask_types.h"
#include "DNA_view3d_types.h"
+#include "DNA_workspace_types.h"
#include "RNA_access.h"
#include "RNA_define.h"
@@ -74,7 +75,7 @@ const EnumPropertyItem rna_enum_space_type_items[] = {
/* Animation */
{0, "", ICON_NONE, "Animation", ""},
- {SPACE_TIME, "TIMELINE", ICON_TIME, "Timeline", "Timeline and playback controls"},
+ //{SPACE_ACTION, "TIMELINE", ICON_TIME, "Timeline", "Timeline and playback controls (NOTE: Switch to 'Timeline' mode)"}, /* XXX */
{SPACE_IPO, "GRAPH_EDITOR", ICON_IPO, "Graph Editor", "Edit drivers and keyframe interpolation"},
{SPACE_ACTION, "DOPESHEET_EDITOR", ICON_ACTION, "Dope Sheet", "Adjust timing of keyframes"},
{SPACE_NLA, "NLA_EDITOR", ICON_NLA, "NLA Editor", "Combine and layer Actions"},
@@ -82,11 +83,12 @@ const EnumPropertyItem rna_enum_space_type_items[] = {
/* Scripting */
{0, "", ICON_NONE, "Scripting", ""},
{SPACE_TEXT, "TEXT_EDITOR", ICON_TEXT, "Text Editor", "Edit scripts and in-file documentation"},
- {SPACE_LOGIC, "LOGIC_EDITOR", ICON_LOGIC, "Logic Editor", "Game logic editing"},
{SPACE_CONSOLE, "CONSOLE", ICON_CONSOLE, "Python Console", "Interactive programmatic console for "
"advanced editing and script development"},
{SPACE_INFO, "INFO", ICON_INFO, "Info", "Main menu bar and list of error messages "
"(drag down to expand and display)"},
+ /* Special case: Top-bar isn't supposed to be a regular editor for the user. */
+ {SPACE_TOPBAR, "TOPBAR", ICON_NONE, "Top Bar", "Global bar at the top of the screen for global per-window settings"},
/* Data */
{0, "", ICON_NONE, "Data", ""},
@@ -158,18 +160,6 @@ static const EnumPropertyItem draw_channels_items[] = {
{0, NULL, 0, NULL, NULL}
};
-static const EnumPropertyItem transform_orientation_items[] = {
- {V3D_MANIP_GLOBAL, "GLOBAL", 0, "Global", "Align the transformation axes to world space"},
- {V3D_MANIP_LOCAL, "LOCAL", 0, "Local", "Align the transformation axes to the selected objects' local space"},
- {V3D_MANIP_NORMAL, "NORMAL", 0, "Normal",
- "Align the transformation axes to average normal of selected elements "
- "(bone Y axis for pose mode)"},
- {V3D_MANIP_GIMBAL, "GIMBAL", 0, "Gimbal", "Align each axis to the Euler rotation axis as used for input"},
- {V3D_MANIP_VIEW, "VIEW", 0, "View", "Align the transformation axes to the window"},
- // {V3D_MANIP_CUSTOM, "CUSTOM", 0, "Custom", "Use a custom transform orientation"},
- {0, NULL, 0, NULL, NULL}
-};
-
#ifndef RNA_RUNTIME
static const EnumPropertyItem autosnap_items[] = {
{SACTSNAP_OFF, "NONE", 0, "No Auto-Snap", ""},
@@ -185,16 +175,21 @@ static const EnumPropertyItem autosnap_items[] = {
};
#endif
-const EnumPropertyItem rna_enum_viewport_shade_items[] = {
- {OB_BOUNDBOX, "BOUNDBOX", ICON_BBOX, "Bounding Box", "Display the object's local bounding boxes only"},
+const EnumPropertyItem rna_enum_shading_type_items[] = {
{OB_WIRE, "WIREFRAME", ICON_WIRE, "Wireframe", "Display the object as wire edges"},
- {OB_SOLID, "SOLID", ICON_SOLID, "Solid", "Display the object solid, lit with default OpenGL lights"},
+ {OB_SOLID, "SOLID", ICON_SOLID, "Single Color", "Display the object or material in a single color"},
{OB_TEXTURE, "TEXTURED", ICON_POTATO, "Texture", "Display the object solid, with a texture"},
{OB_MATERIAL, "MATERIAL", ICON_MATERIAL_DATA, "Material", "Display objects solid, with GLSL material"},
{OB_RENDER, "RENDERED", ICON_SMOOTH, "Rendered", "Display render preview"},
{0, NULL, 0, NULL, NULL}
};
+const EnumPropertyItem rna_enum_viewport_lighting_items[] = {
+ {V3D_LIGHTING_FLAT, "FLAT", 0, "Flat Lighting", "Display using flat lighting"},
+ {V3D_LIGHTING_STUDIO, "STUDIO", 0, "Studio Lighting", "Display using studio lighting"},
+ /* {V3D_LIGHTING_SCENE, "SCENE", 0, "Scene Lighting", "Display using scene lighting"}, */
+ {0, NULL, 0, NULL, NULL}
+};
const EnumPropertyItem rna_enum_clip_editor_mode_items[] = {
{SC_MODE_TRACKING, "TRACKING", ICON_ANIM_DATA, "Tracking", "Show tracking and solving tools"},
@@ -206,7 +201,8 @@ const EnumPropertyItem rna_enum_clip_editor_mode_items[] = {
static const EnumPropertyItem buttons_context_items[] = {
{BCONTEXT_SCENE, "SCENE", ICON_SCENE_DATA, "Scene", "Scene"},
{BCONTEXT_RENDER, "RENDER", ICON_SCENE, "Render", "Render"},
- {BCONTEXT_RENDER_LAYER, "RENDER_LAYER", ICON_RENDERLAYERS, "Render Layers", "Render layers"},
+ {BCONTEXT_VIEW_LAYER, "VIEW_LAYER", ICON_RENDER_RESULT, "View Layer", "View layer"},
+ {BCONTEXT_COLLECTION, "COLLECTION", ICON_COLLAPSEMENU, "Collection", "Collection"},
{BCONTEXT_WORLD, "WORLD", ICON_WORLD, "World", "World"},
{BCONTEXT_OBJECT, "OBJECT", ICON_OBJECT_DATA, "Object", "Object"},
{BCONTEXT_CONSTRAINT, "CONSTRAINT", ICON_CONSTRAINT, "Constraints", "Object constraints"},
@@ -218,21 +214,16 @@ static const EnumPropertyItem buttons_context_items[] = {
{BCONTEXT_TEXTURE, "TEXTURE", ICON_TEXTURE, "Texture", "Texture"},
{BCONTEXT_PARTICLE, "PARTICLES", ICON_PARTICLES, "Particles", "Particle"},
{BCONTEXT_PHYSICS, "PHYSICS", ICON_PHYSICS, "Physics", "Physics"},
+ {BCONTEXT_WORKSPACE, "WORKSPACE", ICON_SPLITSCREEN, "Workspace", "Workspace"},
{0, NULL, 0, NULL, NULL}
};
-/* Actually populated dynamically trough a function, but helps for context-less access (e.g. doc, i18n...). */
-static const EnumPropertyItem buttons_texture_context_items[] = {
- {SB_TEXC_MATERIAL, "MATERIAL", ICON_MATERIAL, "", "Show material textures"},
- {SB_TEXC_WORLD, "WORLD", ICON_WORLD, "", "Show world textures"},
- {SB_TEXC_LAMP, "LAMP", ICON_LAMP, "", "Show lamp textures"},
- {SB_TEXC_PARTICLES, "PARTICLES", ICON_PARTICLES, "", "Show particles textures"},
- {SB_TEXC_LINESTYLE, "LINESTYLE", ICON_LINE_DATA, "", "Show linestyle textures"},
- {SB_TEXC_OTHER, "OTHER", ICON_TEXTURE, "", "Show other data textures"},
+static const EnumPropertyItem buttons_collection_context_items[] = {
+ {SB_COLLECTION_CTX_VIEW_LAYER, "VIEW_LAYER", ICON_RENDER_RESULT, "", "Show material textures"},
+ {SB_COLLECTION_CTX_GROUP, "GROUP", ICON_GROUP, "", "Show world textures"},
{0, NULL, 0, NULL, NULL}
};
-
static const EnumPropertyItem fileselectparams_recursion_level_items[] = {
{0, "NONE", 0, "None", "Only list current directory's content, with no recursion"},
{1, "BLEND", 0, "Blend File", "List .blend files' content"},
@@ -263,17 +254,23 @@ const EnumPropertyItem rna_enum_file_sort_items[] = {
#include "BKE_brush.h"
#include "BKE_colortools.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
+#include "BKE_global.h"
#include "BKE_nla.h"
#include "BKE_paint.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_icons.h"
+#include "BKE_workspace.h"
+
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "ED_buttons.h"
#include "ED_fileselect.h"
#include "ED_image.h"
#include "ED_node.h"
+#include "ED_transform.h"
#include "ED_screen.h"
#include "ED_view3d.h"
#include "ED_sequencer.h"
@@ -313,12 +310,8 @@ static StructRNA *rna_Space_refine(struct PointerRNA *ptr)
return &RNA_SpaceDopeSheetEditor;
case SPACE_NLA:
return &RNA_SpaceNLA;
- case SPACE_TIME:
- return &RNA_SpaceTimeline;
case SPACE_NODE:
return &RNA_SpaceNodeEditor;
- case SPACE_LOGIC:
- return &RNA_SpaceLogicEditor;
case SPACE_CONSOLE:
return &RNA_SpaceConsole;
case SPACE_USERPREF:
@@ -413,64 +406,15 @@ static void rna_Space_view2d_sync_update(Main *UNUSED(bmain), Scene *UNUSED(scen
}
}
-static PointerRNA rna_CurrentOrientation_get(PointerRNA *ptr)
-{
- Scene *scene = ((bScreen *)ptr->id.data)->scene;
- View3D *v3d = (View3D *)ptr->data;
-
- if (v3d->twmode < V3D_MANIP_CUSTOM)
- return rna_pointer_inherit_refine(ptr, &RNA_TransformOrientation, NULL);
- else
- return rna_pointer_inherit_refine(ptr, &RNA_TransformOrientation,
- BLI_findlink(&scene->transform_spaces, v3d->twmode - V3D_MANIP_CUSTOM));
-}
-
-const EnumPropertyItem *rna_TransformOrientation_itemf(
- bContext *C, PointerRNA *ptr, PropertyRNA *UNUSED(prop), bool *r_free)
-{
- Scene *scene = NULL;
- ListBase *transform_spaces;
- TransformOrientation *ts = NULL;
- EnumPropertyItem tmp = {0, "", 0, "", ""};
- EnumPropertyItem *item = NULL;
- int i = V3D_MANIP_CUSTOM, totitem = 0;
-
- RNA_enum_items_add(&item, &totitem, transform_orientation_items);
-
- if (ptr->type == &RNA_SpaceView3D)
- scene = ((bScreen *)ptr->id.data)->scene;
- else
- scene = CTX_data_scene(C); /* can't use scene from ptr->id.data because that enum is also used by operators */
-
- if (scene) {
- transform_spaces = &scene->transform_spaces;
- ts = transform_spaces->first;
- }
-
- if (ts) {
- RNA_enum_item_add_separator(&item, &totitem);
-
- for (; ts; ts = ts->next) {
- tmp.identifier = ts->name;
- tmp.name = ts->name;
- tmp.value = i++;
- RNA_enum_item_add(&item, &totitem, &tmp);
- }
- }
-
- RNA_enum_item_end(&item, &totitem);
- *r_free = true;
-
- return item;
-}
-
/* Space 3D View */
static void rna_SpaceView3D_camera_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
View3D *v3d = (View3D *)(ptr->data);
if (v3d->scenelock) {
+ wmWindowManager *wm = bmain->wm.first;
+
scene->camera = v3d->camera;
- BKE_screen_view3d_main_sync(&bmain->screen, scene);
+ WM_windows_scene_data_sync(&wm->windows, scene);
}
}
@@ -482,8 +426,10 @@ static void rna_SpaceView3D_lock_camera_and_layers_set(PointerRNA *ptr, int valu
v3d->scenelock = value;
if (value) {
+ Scene *scene = ED_screen_scene_find(sc, G.main->wm.first);
int bit;
- v3d->lay = sc->scene->lay;
+
+ v3d->lay = scene->lay;
/* seek for layact */
bit = 0;
while (bit < 32) {
@@ -493,15 +439,15 @@ static void rna_SpaceView3D_lock_camera_and_layers_set(PointerRNA *ptr, int valu
}
bit++;
}
- v3d->camera = sc->scene->camera;
+ v3d->camera = scene->camera;
}
}
static void rna_View3D_CursorLocation_get(PointerRNA *ptr, float *values)
{
View3D *v3d = (View3D *)(ptr->data);
- bScreen *sc = (bScreen *)ptr->id.data;
- Scene *scene = (Scene *)sc->scene;
+ bScreen *screen = ptr->id.data;
+ Scene *scene = ED_screen_scene_find(screen, G.main->wm.first);
const float *loc = ED_view3d_cursor3d_get(scene, v3d);
copy_v3_v3(values, loc);
@@ -510,18 +456,18 @@ static void rna_View3D_CursorLocation_get(PointerRNA *ptr, float *values)
static void rna_View3D_CursorLocation_set(PointerRNA *ptr, const float *values)
{
View3D *v3d = (View3D *)(ptr->data);
- bScreen *sc = (bScreen *)ptr->id.data;
- Scene *scene = (Scene *)sc->scene;
+ bScreen *screen = ptr->id.data;
+ Scene *scene = ED_screen_scene_find(screen, G.main->wm.first);
float *cursor = ED_view3d_cursor3d_get(scene, v3d);
copy_v3_v3(cursor, values);
}
-static float rna_View3D_GridScaleUnit_get(PointerRNA *ptr)
+static float rna_View3DOverlay_GridScaleUnit_get(PointerRNA *ptr)
{
View3D *v3d = (View3D *)(ptr->data);
- bScreen *sc = (bScreen *)ptr->id.data;
- Scene *scene = (Scene *)sc->scene;
+ bScreen *screen = ptr->id.data;
+ Scene *scene = ED_screen_scene_find(screen, G.main->wm.first);
return ED_view3d_grid_scale(scene, v3d, NULL);
}
@@ -530,7 +476,7 @@ static void rna_SpaceView3D_layer_set(PointerRNA *ptr, const int *values)
{
View3D *v3d = (View3D *)(ptr->data);
- v3d->lay = ED_view3d_scene_layer_set(v3d->lay, values, &v3d->layact);
+ v3d->lay = ED_view3d_view_layer_set(v3d->lay, values, &v3d->layact);
}
static int rna_SpaceView3D_active_layer_get(PointerRNA *ptr)
@@ -542,10 +488,10 @@ static int rna_SpaceView3D_active_layer_get(PointerRNA *ptr)
static void rna_SpaceView3D_layer_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
{
- DAG_on_visible_update(bmain, false);
+ DEG_on_visible_update(bmain, false);
}
-static void rna_SpaceView3D_viewport_shade_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
+static void rna_3DViewShading_type_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *ptr)
{
View3D *v3d = (View3D *)(ptr->data);
ScrArea *sa = rna_area_from_space(ptr);
@@ -553,23 +499,6 @@ static void rna_SpaceView3D_viewport_shade_update(Main *bmain, Scene *UNUSED(sce
ED_view3d_shade_update(bmain, v3d, sa);
}
-static void rna_SpaceView3D_matcap_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
-{
- View3D *v3d = (View3D *)(ptr->data);
-
- if (v3d->defmaterial) {
- Material *ma = v3d->defmaterial;
-
- if (ma->preview)
- BKE_previewimg_free(&ma->preview);
-
- if (ma->gpumaterial.first)
- GPU_material_free(&ma->gpumaterial);
-
- WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, ma);
- }
-}
-
static void rna_SpaceView3D_matcap_enable(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
View3D *v3d = (View3D *)(ptr->data);
@@ -703,20 +632,28 @@ static void rna_RegionView3D_view_matrix_set(PointerRNA *ptr, const float *value
ED_view3d_from_m4(mat, rv3d->ofs, rv3d->viewquat, &rv3d->dist);
}
-static int rna_SpaceView3D_viewport_shade_get(PointerRNA *ptr)
+static int rna_3DViewShading_type_get(PointerRNA *ptr)
{
- Scene *scene = ((bScreen *)ptr->id.data)->scene;
+ bScreen *screen = ptr->id.data;
+ Scene *scene = WM_windows_scene_get_from_screen(G.main->wm.first, screen);
RenderEngineType *type = RE_engines_find(scene->r.engine);
View3D *v3d = (View3D *)ptr->data;
- int drawtype = v3d->drawtype;
- if (drawtype == OB_RENDER && !(type && type->view_draw))
- return OB_SOLID;
+ if (BKE_scene_uses_blender_eevee(scene)) {
+ if (v3d->drawtype == OB_MATERIAL) {
+ return OB_RENDER;
+ }
+ }
+ else if (v3d->drawtype == OB_RENDER) {
+ if (!(type && type->render_to_view)) {
+ return OB_MATERIAL;
+ }
+ }
- return drawtype;
+ return v3d->drawtype;
}
-static void rna_SpaceView3D_viewport_shade_set(PointerRNA *ptr, int value)
+static void rna_3DViewShading_type_set(PointerRNA *ptr, int value)
{
View3D *v3d = (View3D *)ptr->data;
if (value != v3d->drawtype && value == OB_RENDER) {
@@ -725,23 +662,29 @@ static void rna_SpaceView3D_viewport_shade_set(PointerRNA *ptr, int value)
v3d->drawtype = value;
}
-static const EnumPropertyItem *rna_SpaceView3D_viewport_shade_itemf(bContext *UNUSED(C), PointerRNA *ptr,
- PropertyRNA *UNUSED(prop), bool *r_free)
+static const EnumPropertyItem *rna_3DViewShading_type_itemf(
+ bContext *C, PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop), bool *r_free)
{
- Scene *scene = ((bScreen *)ptr->id.data)->scene;
+ wmWindow *win = CTX_wm_window(C);
+ Scene *scene = WM_window_get_active_scene(win);
RenderEngineType *type = RE_engines_find(scene->r.engine);
EnumPropertyItem *item = NULL;
int totitem = 0;
- RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_BOUNDBOX);
- RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_WIRE);
- RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_SOLID);
- RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_TEXTURE);
- RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_MATERIAL);
+ RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_type_items, OB_SOLID);
+ RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_type_items, OB_TEXTURE);
- if (type && type->view_draw)
- RNA_enum_items_add_value(&item, &totitem, rna_enum_viewport_shade_items, OB_RENDER);
+ if (BKE_scene_uses_blender_eevee(scene)) {
+ RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_type_items, OB_RENDER);
+ }
+ else {
+ RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_type_items, OB_MATERIAL);
+ if (type && type->render_to_view) {
+ RNA_enum_items_add_value(&item, &totitem, rna_enum_shading_type_items, OB_RENDER);
+ }
+ }
RNA_enum_item_end(&item, &totitem);
*r_free = true;
@@ -749,10 +692,11 @@ static const EnumPropertyItem *rna_SpaceView3D_viewport_shade_itemf(bContext *UN
return item;
}
-static const EnumPropertyItem *rna_SpaceView3D_stereo3d_camera_itemf(bContext *UNUSED(C), PointerRNA *ptr,
- PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
+static const EnumPropertyItem *rna_SpaceView3D_stereo3d_camera_itemf(
+ bContext *C, PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
{
- Scene *scene = ((bScreen *)ptr->id.data)->scene;
+ Scene *scene = CTX_data_scene(C);
if (scene->r.views_format == SCE_VIEWS_FORMAT_MULTIVIEW)
return multiview_camera_items;
@@ -760,6 +704,26 @@ static const EnumPropertyItem *rna_SpaceView3D_stereo3d_camera_itemf(bContext *U
return stereo3d_camera_items;
}
+static PointerRNA rna_SpaceView3D_shading_get(PointerRNA *ptr)
+{
+ return rna_pointer_inherit_refine(ptr, &RNA_View3DShading, ptr->data);
+}
+
+static char *rna_View3DShading_path(PointerRNA *UNUSED(ptr))
+{
+ return BLI_sprintfN("shading");
+}
+
+static PointerRNA rna_SpaceView3D_overlay_get(PointerRNA *ptr)
+{
+ return rna_pointer_inherit_refine(ptr, &RNA_View3DOverlay, ptr->data);
+}
+
+static char *rna_View3DOverlay_path(PointerRNA *UNUSED(ptr))
+{
+ return BLI_sprintfN("overlay");
+}
+
/* Space Image Editor */
static PointerRNA rna_SpaceImageEditor_uvedit_get(PointerRNA *ptr)
@@ -820,22 +784,30 @@ static int rna_SpaceImageEditor_show_uvedit_get(PointerRNA *ptr)
{
SpaceImage *sima = (SpaceImage *)(ptr->data);
bScreen *sc = (bScreen *)ptr->id.data;
- return ED_space_image_show_uvedit(sima, sc->scene->obedit);
+ wmWindow *win = ED_screen_window_find(sc, G.main->wm.first);
+ ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+ Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
+ return ED_space_image_show_uvedit(sima, obedit);
}
static int rna_SpaceImageEditor_show_maskedit_get(PointerRNA *ptr)
{
SpaceImage *sima = (SpaceImage *)(ptr->data);
bScreen *sc = (bScreen *)ptr->id.data;
- return ED_space_image_check_show_maskedit(sc->scene, sima);
+ wmWindow *win = ED_screen_window_find(sc, G.main->wm.first);
+ ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+ return ED_space_image_check_show_maskedit(sima, view_layer);
}
static void rna_SpaceImageEditor_image_set(PointerRNA *ptr, PointerRNA value)
{
SpaceImage *sima = (SpaceImage *)(ptr->data);
bScreen *sc = (bScreen *)ptr->id.data;
-
- ED_space_image_set(sima, sc->scene, sc->scene->obedit, (Image *)value.data);
+ wmWindow *win;
+ Scene *scene = ED_screen_scene_find_with_window(sc, G.main->wm.first, &win);
+ ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+ Object *obedit = OBEDIT_FROM_VIEW_LAYER(view_layer);
+ ED_space_image_set(sima, scene, obedit, (Image *)value.data);
}
static void rna_SpaceImageEditor_mask_set(PointerRNA *ptr, PointerRNA value)
@@ -845,8 +817,9 @@ static void rna_SpaceImageEditor_mask_set(PointerRNA *ptr, PointerRNA value)
ED_space_image_set_mask(NULL, sima, (Mask *)value.data);
}
-static const EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(bContext *UNUSED(C), PointerRNA *ptr,
- PropertyRNA *UNUSED(prop), bool *r_free)
+static const EnumPropertyItem *rna_SpaceImageEditor_draw_channels_itemf(
+ bContext *UNUSED(C), PointerRNA *ptr,
+ PropertyRNA *UNUSED(prop), bool *r_free)
{
SpaceImage *sima = (SpaceImage *)ptr->data;
EnumPropertyItem *item = NULL;
@@ -967,8 +940,9 @@ static void rna_SpaceImageEditor_scopes_update(struct bContext *C, struct Pointe
ED_space_image_release_buffer(sima, ibuf, lock);
}
-static const EnumPropertyItem *rna_SpaceImageEditor_pivot_itemf(bContext *UNUSED(C), PointerRNA *ptr,
- PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
+static const EnumPropertyItem *rna_SpaceImageEditor_pivot_itemf(
+ bContext *UNUSED(C), PointerRNA *ptr,
+ PropertyRNA *UNUSED(prop), bool *UNUSED(r_free))
{
static const EnumPropertyItem pivot_items[] = {
{V3D_AROUND_CENTER_BOUNDS, "CENTER", ICON_ROTATE, "Bounding Box Center", ""},
@@ -1070,8 +1044,9 @@ static void rna_SpaceProperties_context_set(PointerRNA *ptr, int value)
sbuts->mainbuser = value;
}
-static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSED(C), PointerRNA *ptr,
- PropertyRNA *UNUSED(prop), bool *r_free)
+static const EnumPropertyItem *rna_SpaceProperties_context_itemf(
+ bContext *UNUSED(C), PointerRNA *ptr,
+ PropertyRNA *UNUSED(prop), bool *r_free)
{
SpaceButs *sbuts = (SpaceButs *)(ptr->data);
EnumPropertyItem *item = NULL;
@@ -1081,8 +1056,8 @@ static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSE
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_RENDER);
}
- if (sbuts->pathflag & (1 << BCONTEXT_RENDER_LAYER)) {
- RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_RENDER_LAYER);
+ if (sbuts->pathflag & (1 << BCONTEXT_VIEW_LAYER)) {
+ RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_VIEW_LAYER);
}
if (sbuts->pathflag & (1 << BCONTEXT_SCENE)) {
@@ -1093,6 +1068,14 @@ static const EnumPropertyItem *rna_SpaceProperties_context_itemf(bContext *UNUSE
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_WORLD);
}
+ if (sbuts->pathflag & (1 << BCONTEXT_WORKSPACE)) {
+ RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_WORKSPACE);
+ }
+
+ if (sbuts->pathflag & (1 << BCONTEXT_COLLECTION)) {
+ RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_COLLECTION);
+ }
+
if (sbuts->pathflag & (1 << BCONTEXT_OBJECT)) {
RNA_enum_items_add_value(&item, &totitem, buttons_context_items, BCONTEXT_OBJECT);
}
@@ -1157,49 +1140,6 @@ static void rna_SpaceProperties_align_set(PointerRNA *ptr, int value)
sbuts->re_align = 1;
}
-static const EnumPropertyItem *rna_SpaceProperties_texture_context_itemf(bContext *C, PointerRNA *UNUSED(ptr),
- PropertyRNA *UNUSED(prop), bool *r_free)
-{
- EnumPropertyItem *item = NULL;
- int totitem = 0;
-
- if (ED_texture_context_check_world(C)) {
- RNA_enum_items_add_value(&item, &totitem, buttons_texture_context_items, SB_TEXC_WORLD);
- }
-
- if (ED_texture_context_check_lamp(C)) {
- RNA_enum_items_add_value(&item, &totitem, buttons_texture_context_items, SB_TEXC_LAMP);
- }
- else if (ED_texture_context_check_material(C)) {
- RNA_enum_items_add_value(&item, &totitem, buttons_texture_context_items, SB_TEXC_MATERIAL);
- }
-
- if (ED_texture_context_check_particles(C)) {
- RNA_enum_items_add_value(&item, &totitem, buttons_texture_context_items, SB_TEXC_PARTICLES);
- }
-
- if (ED_texture_context_check_linestyle(C)) {
- RNA_enum_items_add_value(&item, &totitem, buttons_texture_context_items, SB_TEXC_LINESTYLE);
- }
-
- if (ED_texture_context_check_others(C)) {
- RNA_enum_items_add_value(&item, &totitem, buttons_texture_context_items, SB_TEXC_OTHER);
- }
-
- RNA_enum_item_end(&item, &totitem);
- *r_free = true;
-
- return item;
-}
-
-static void rna_SpaceProperties_texture_context_set(PointerRNA *ptr, int value)
-{
- SpaceButs *sbuts = (SpaceButs *)(ptr->data);
-
- /* User action, no need to keep "better" value in prev here! */
- sbuts->texture_context = sbuts->texture_context_prev = value;
-}
-
/* Space Console */
static void rna_ConsoleLine_body_get(PointerRNA *ptr, char *value)
{
@@ -1274,10 +1214,12 @@ static void rna_SpaceDopeSheetEditor_action_set(PointerRNA *ptr, PointerRNA valu
}
}
-static void rna_SpaceDopeSheetEditor_action_update(Main *bmain, Scene *scene, PointerRNA *ptr)
+static void rna_SpaceDopeSheetEditor_action_update(bContext *C, PointerRNA *ptr)
{
SpaceAction *saction = (SpaceAction *)(ptr->data);
- Object *obact = (scene->basact) ? scene->basact->object : NULL;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Main *bmain = CTX_data_main(C);
+ Object *obact = OBACT(view_layer);
/* we must set this action to be the one used by active object (if not pinned) */
if (obact /* && saction->pin == 0*/) {
@@ -1343,16 +1285,18 @@ static void rna_SpaceDopeSheetEditor_action_update(Main *bmain, Scene *scene, Po
}
/* force depsgraph flush too */
- DAG_id_tag_update(&obact->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&obact->id, OB_RECALC_OB | OB_RECALC_DATA);
/* Update relations as well, so new time source dependency is added. */
- DAG_relations_tag_update(bmain);
+ DEG_relations_tag_update(bmain);
}
}
-static void rna_SpaceDopeSheetEditor_mode_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
+static void rna_SpaceDopeSheetEditor_mode_update(bContext *C, PointerRNA *ptr)
{
SpaceAction *saction = (SpaceAction *)(ptr->data);
- Object *obact = (scene->basact) ? scene->basact->object : NULL;
+ ScrArea *sa = CTX_wm_area(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *obact = OBACT(view_layer);
/* special exceptions for ShapeKey Editor mode */
if (saction->mode == SACTCONT_SHAPEKEY) {
@@ -1379,7 +1323,25 @@ static void rna_SpaceDopeSheetEditor_mode_update(Main *UNUSED(bmain), Scene *sce
else
saction->action = NULL;
}
-
+
+ /* Collapse summary channel and hide channel list for timeline */
+ if (saction->mode == SACTCONT_TIMELINE) {
+ saction->ads.flag |= ADS_FLAG_SUMMARY_COLLAPSED;
+ }
+
+ if (sa && sa->spacedata.first == saction) {
+ ARegion *channels_region = BKE_area_find_region_type(sa, RGN_TYPE_CHANNELS);
+ if (channels_region) {
+ if (saction->mode == SACTCONT_TIMELINE) {
+ channels_region->flag |= RGN_FLAG_HIDDEN;
+ }
+ else {
+ channels_region->flag &= ~RGN_FLAG_HIDDEN;
+ }
+ ED_region_visibility_change_update(C, channels_region);
+ }
+ }
+
/* recalculate extents of channel list */
saction->flag |= SACTION_TEMP_NEEDCHANSYNC;
}
@@ -1414,59 +1376,6 @@ static void rna_Sequencer_view_type_update(Main *UNUSED(bmain), Scene *UNUSED(sc
ED_area_tag_refresh(sa);
}
-static float rna_BackgroundImage_opacity_get(PointerRNA *ptr)
-{
- BGpic *bgpic = (BGpic *)ptr->data;
- return 1.0f - bgpic->blend;
-}
-
-static void rna_BackgroundImage_opacity_set(PointerRNA *ptr, float value)
-{
- BGpic *bgpic = (BGpic *)ptr->data;
- bgpic->blend = 1.0f - value;
-}
-
-/* radius internally (expose as a distance value) */
-static float rna_BackgroundImage_size_get(PointerRNA *ptr)
-{
- BGpic *bgpic = ptr->data;
- return bgpic->size * 2.0f;
-}
-
-static void rna_BackgroundImage_size_set(PointerRNA *ptr, float value)
-{
- BGpic *bgpic = ptr->data;
- bgpic->size = value * 0.5f;
-}
-
-static BGpic *rna_BackgroundImage_new(View3D *v3d)
-{
- BGpic *bgpic = ED_view3d_background_image_new(v3d);
-
- WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, v3d);
-
- return bgpic;
-}
-
-static void rna_BackgroundImage_remove(View3D *v3d, ReportList *reports, PointerRNA *bgpic_ptr)
-{
- BGpic *bgpic = bgpic_ptr->data;
- if (BLI_findindex(&v3d->bgpicbase, bgpic) == -1) {
- BKE_report(reports, RPT_ERROR, "Background image cannot be removed");
- }
-
- ED_view3d_background_image_remove(v3d, bgpic);
- RNA_POINTER_INVALIDATE(bgpic_ptr);
-
- WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, v3d);
-}
-
-static void rna_BackgroundImage_clear(View3D *v3d)
-{
- ED_view3d_background_image_clear(v3d);
- WM_main_add_notifier(NC_SPACE | ND_SPACE_VIEW3D, v3d);
-}
-
/* Space Node Editor */
static void rna_SpaceNodeEditor_node_tree_set(PointerRNA *ptr, const PointerRNA value)
@@ -1507,8 +1416,9 @@ static int rna_SpaceNodeEditor_tree_type_poll(void *Cv, bNodeTreeType *type)
else
return true;
}
-static const EnumPropertyItem *rna_SpaceNodeEditor_tree_type_itemf(bContext *C, PointerRNA *UNUSED(ptr),
- PropertyRNA *UNUSED(prop), bool *r_free)
+static const EnumPropertyItem *rna_SpaceNodeEditor_tree_type_itemf(
+ bContext *C, PointerRNA *UNUSED(ptr),
+ PropertyRNA *UNUSED(prop), bool *r_free)
{
return rna_node_tree_type_itemf(C, rna_SpaceNodeEditor_tree_type_poll, r_free);
}
@@ -1919,6 +1829,7 @@ static void rna_def_space(BlenderRNA *brna)
prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "spacetype");
RNA_def_property_enum_items(prop, rna_enum_space_type_items);
+ /* When making this editable, take care for the special case of global areas (see rna_Area_type_set). */
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_ui_text(prop, "Type", "Space data type");
@@ -2100,23 +2011,24 @@ static void rna_def_space_outliner(BlenderRNA *brna)
PropertyRNA *prop;
static const EnumPropertyItem display_mode_items[] = {
- {SO_ALL_SCENES, "ALL_SCENES", 0, "All Scenes", "Display data-blocks in all scenes"},
- {SO_CUR_SCENE, "CURRENT_SCENE", 0, "Current Scene", "Display data-blocks in current scene"},
- {SO_VISIBLE, "VISIBLE_LAYERS", 0, "Visible Layers", "Display data-blocks in visible layers"},
- {SO_SELECTED, "SELECTED", 0, "Selected", "Display data-blocks of selected, visible objects"},
- {SO_ACTIVE, "ACTIVE", 0, "Active", "Display data-blocks of active object"},
- {SO_SAME_TYPE, "SAME_TYPES", 0, "Same Types",
- "Display data-blocks of all objects of same type as selected object"},
+ {SO_COLLECTIONS, "COLLECTIONS", 0, "Collections", "Display collections in the view layer"},
+ {SO_SCENES, "SCENES", 0, "Scenes", "Display scenes and their view layers, collections and objects"},
{SO_GROUPS, "GROUPS", 0, "Groups", "Display groups and their data-blocks"},
{SO_SEQUENCE, "SEQUENCE", 0, "Sequence", "Display sequence data-blocks"},
{SO_LIBRARIES, "LIBRARIES", 0, "Blender File", "Display data of current file and linked libraries"},
{SO_DATABLOCKS, "DATABLOCKS", 0, "Data-Blocks", "Display all raw data-blocks"},
- {SO_USERDEF, "USER_PREFERENCES", 0, "User Preferences", "Display user preference data"},
{SO_ID_ORPHANS, "ORPHAN_DATA", 0, "Orphan Data",
"Display data-blocks which are unused and/or will be lost when the file is reloaded"},
{0, NULL, 0, NULL, NULL}
};
+ static const EnumPropertyItem filter_state_items[] = {
+ {SO_FILTER_OB_VISIBLE, "VISIBLE", ICON_RESTRICT_VIEW_OFF, "Visible", "Show visible objects"},
+ {SO_FILTER_OB_SELECTED, "SELECTED", ICON_RESTRICT_SELECT_OFF, "Selected", "Show selected objects"},
+ {SO_FILTER_OB_ACTIVE, "ACTIVE", ICON_LAYER_ACTIVE, "Active", "Show only the active object"},
+ {0, NULL, 0, NULL, NULL}
+ };
+
srna = RNA_def_struct(brna, "SpaceOutliner", "Space");
RNA_def_struct_sdna(srna, "SpaceOops");
RNA_def_struct_ui_text(srna, "Space Outliner", "Outliner space data");
@@ -2136,227 +2048,354 @@ static void rna_def_space_outliner(BlenderRNA *brna)
prop = RNA_def_property(srna, "use_filter_case_sensitive", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "search_flags", SO_FIND_CASE_SENSITIVE);
RNA_def_property_ui_text(prop, "Case Sensitive Matches Only", "Only use case sensitive matches of search string");
+ RNA_def_property_ui_icon(prop, ICON_SYNTAX_OFF, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_filter_complete", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "search_flags", SO_FIND_COMPLETE);
RNA_def_property_ui_text(prop, "Complete Matches Only", "Only use complete matches of search string");
+ RNA_def_property_ui_icon(prop, ICON_OUTLINER_DATA_FONT, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "use_sort_alpha", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SO_SKIP_SORT_ALPHA);
RNA_def_property_ui_text(prop, "Sort Alphabetically", "");
+ RNA_def_property_ui_icon(prop, ICON_SORTALPHA, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
prop = RNA_def_property(srna, "show_restrict_columns", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", SO_HIDE_RESTRICTCOLS);
RNA_def_property_ui_text(prop, "Show Restriction Columns", "Show column");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ /* Filters. */
+ prop = RNA_def_property(srna, "use_filter_search", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "filter", SO_FILTER_SEARCH);
+ RNA_def_property_ui_text(prop, "Search Name", "Filter searched elements");
+ RNA_def_property_ui_icon(prop, ICON_VIEWZOOM, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filters", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "filter", SO_FILTER_ENABLE);
+ RNA_def_property_ui_text(prop, "Use Filters", "Use filters");
+ RNA_def_property_ui_icon(prop, ICON_FILTER, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OBJECT);
+ RNA_def_property_ui_text(prop, "Filter Objects", "Show objects");
+ RNA_def_property_ui_icon(prop, ICON_OBJECT_DATA, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object_content", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_CONTENT);
+ RNA_def_property_ui_text(prop, "Filter Objects Contents", "Show what is inside the objects elements");
+ RNA_def_property_ui_icon(prop, ICON_MODIFIER, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_children", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_CHILDREN);
+ RNA_def_property_ui_text(prop, "Filter Objects Children", "Show children");
+ RNA_def_property_ui_icon(prop, ICON_PLUS, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_collection", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_COLLECTION);
+ RNA_def_property_ui_text(prop, "Filter Collections", "Show collections");
+ RNA_def_property_ui_icon(prop, ICON_COLLAPSEMENU, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ /* Filters object state. */
+ prop = RNA_def_property(srna, "use_filter_object_state", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "filter", SO_FILTER_OB_STATE);
+ RNA_def_property_ui_text(prop, "Filter Object State", "Filter objects based on their state (visible, ...)."
+ "This can be slow");
+ RNA_def_property_ui_icon(prop, ICON_LAYER_USED, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "filter_state", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "filter_state");
+ RNA_def_property_enum_items(prop, filter_state_items);
+ RNA_def_property_ui_text(prop, "State Filter", "");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ /* Filters object type. */
+ prop = RNA_def_property(srna, "use_filter_object_type", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "filter", SO_FILTER_OB_TYPE);
+ RNA_def_property_ui_text(prop, "Filter Object Type", "Show specific objects types");
+ RNA_def_property_ui_icon(prop, ICON_MESH_CUBE, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object_mesh", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_MESH);
+ RNA_def_property_ui_text(prop, "Show Meshes", "Show mesh objects");
+ RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_MESH, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object_armature", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_ARMATURE);
+ RNA_def_property_ui_text(prop, "Show Armatures", "Show armature objects");
+ RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_ARMATURE, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object_empty", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_EMPTY);
+ RNA_def_property_ui_text(prop, "Show Empties", "Show empty objects");
+ RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_EMPTY, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object_lamp", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_LAMP);
+ RNA_def_property_ui_text(prop, "Show Lamps", "Show lamps objects");
+ RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_LAMP, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object_camera", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_CAMERA);
+ RNA_def_property_ui_text(prop, "Show Cameras", "Show camera objects");
+ RNA_def_property_ui_icon(prop, ICON_OUTLINER_OB_CAMERA, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
+
+ prop = RNA_def_property(srna, "use_filter_object_others", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "filter", SO_FILTER_NO_OB_OTHERS);
+ RNA_def_property_ui_text(prop, "Show Other Objects", "Show curves, lattices, light probes, fonts, ...");
+ RNA_def_property_ui_icon(prop, ICON_ZOOMIN, 0);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_OUTLINER, NULL);
}
-static void rna_def_background_image(BlenderRNA *brna)
+static void rna_def_space_view3d_shading(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
- /* note: combinations work but don't flip so arnt that useful */
- static const EnumPropertyItem bgpic_axis_items[] = {
- {0, "", 0, N_("X Axis"), ""},
- {(1 << RV3D_VIEW_LEFT), "LEFT", 0, "Left", "Show background image while looking to the left"},
- {(1 << RV3D_VIEW_RIGHT), "RIGHT", 0, "Right", "Show background image while looking to the right"},
- /*{(1<<RV3D_VIEW_LEFT)|(1<<RV3D_VIEW_RIGHT), "LEFT_RIGHT", 0, "Left/Right", ""},*/
- {0, "", 0, N_("Y Axis"), ""},
- {(1 << RV3D_VIEW_BACK), "BACK", 0, "Back", "Show background image in back view"},
- {(1 << RV3D_VIEW_FRONT), "FRONT", 0, "Front", "Show background image in front view"},
- /*{(1<<RV3D_VIEW_BACK)|(1<<RV3D_VIEW_FRONT), "BACK_FRONT", 0, "Back/Front", ""},*/
- {0, "", 0, N_("Z Axis"), ""},
- {(1 << RV3D_VIEW_BOTTOM), "BOTTOM", 0, "Bottom", "Show background image in bottom view"},
- {(1 << RV3D_VIEW_TOP), "TOP", 0, "Top", "Show background image in top view"},
- /*{(1<<RV3D_VIEW_BOTTOM)|(1<<RV3D_VIEW_TOP), "BOTTOM_TOP", 0, "Top/Bottom", ""},*/
- {0, "", 0, N_("Other"), ""},
- {0, "ALL", 0, "All Views", "Show background image in all views"},
- {(1 << RV3D_VIEW_CAMERA), "CAMERA", 0, "Camera", "Show background image in camera view"},
+ static const EnumPropertyItem color_type_items[] = {
+ {V3D_SHADING_SINGLE_COLOR, "SINGLE", 0, "Single", "Show scene in a single color"},
+ {V3D_SHADING_OBJECT_COLOR, "OBJECT", 0, "Object", "Show Object color"},
+ {V3D_SHADING_MATERIAL_COLOR, "MATERIAL", 0, "Material", "Show Material color"},
+ {V3D_SHADING_RANDOM_COLOR, "RANDOM", 0, "Random", "Show random object color"},
{0, NULL, 0, NULL, NULL}
};
-
- static const EnumPropertyItem bgpic_source_items[] = {
- {V3D_BGPIC_IMAGE, "IMAGE", 0, "Image", ""},
- {V3D_BGPIC_MOVIE, "MOVIE_CLIP", 0, "Movie Clip", ""},
+ static const EnumPropertyItem studio_lighting_items[] = {
+ {0, "01", ICON_STUDIOLIGHT_01, "", ""},
+ {1, "02", ICON_STUDIOLIGHT_02, "", ""},
+ {2, "03", ICON_STUDIOLIGHT_03, "", ""},
+ {3, "04", ICON_STUDIOLIGHT_04, "", ""},
+ {4, "05", ICON_STUDIOLIGHT_05, "", ""},
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem bgpic_camera_frame_items[] = {
- {0, "STRETCH", 0, "Stretch", ""},
- {V3D_BGPIC_CAMERA_ASPECT, "FIT", 0, "Fit", ""},
- {V3D_BGPIC_CAMERA_ASPECT | V3D_BGPIC_CAMERA_CROP, "CROP", 0, "Crop", ""},
- {0, NULL, 0, NULL, NULL}
- };
+ srna = RNA_def_struct(brna, "View3DShading", NULL);
+ RNA_def_struct_sdna(srna, "View3D");
+ RNA_def_struct_nested(brna, srna, "SpaceView3D");
+ RNA_def_struct_path_func(srna, "rna_View3DShading_path");
+ RNA_def_struct_ui_text(srna, "3D View Shading Settings", "Settings for shading in the 3D viewport");
- static const EnumPropertyItem bgpic_draw_depth_items[] = {
- {0, "BACK", 0, "Back", ""},
- {V3D_BGPIC_FOREGROUND, "FRONT", 0, "Front", ""},
- {0, NULL, 0, NULL, NULL}
- };
+ prop = RNA_def_property(srna, "type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "drawtype");
+ RNA_def_property_enum_items(prop, rna_enum_shading_type_items);
+ RNA_def_property_enum_funcs(prop, "rna_3DViewShading_type_get", "rna_3DViewShading_type_set",
+ "rna_3DViewShading_type_itemf");
+ RNA_def_property_ui_text(prop, "Viewport Shading", "Method to display/shade objects in the 3D View");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_3DViewShading_type_update");
- srna = RNA_def_struct(brna, "BackgroundImage", NULL);
- RNA_def_struct_sdna(srna, "BGpic");
- RNA_def_struct_ui_text(srna, "Background Image", "Image and settings for display in the 3D View background");
+ prop = RNA_def_property(srna, "light", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "shading.light");
+ RNA_def_property_enum_items(prop, rna_enum_viewport_lighting_items);
+ RNA_def_property_ui_text(prop, "Lighting", "Lighting Method for Solid/Texture Viewport Shading");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "source");
- RNA_def_property_enum_items(prop, bgpic_source_items);
- RNA_def_property_ui_text(prop, "Background Source", "Data source used for background");
+ prop = RNA_def_property(srna, "show_object_overlap", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "shading.flag", V3D_SHADING_OBJECT_OVERLAP);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Object Overlap", "Show Object Overlap");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "ima");
- RNA_def_property_ui_text(prop, "Image", "Image displayed and edited in this space");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ prop = RNA_def_property(srna, "studio_light", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "shading.studio_light");
+ RNA_def_property_enum_items(prop, studio_lighting_items);
+ RNA_def_property_ui_text(prop, "Studiolight", "Studio lighting setup");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "clip", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "clip");
- RNA_def_property_ui_text(prop, "MovieClip", "Movie clip displayed and edited in this space");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ prop = RNA_def_property(srna, "color_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "shading.color_type");
+ RNA_def_property_enum_items(prop, color_type_items);
+ RNA_def_property_ui_text(prop, "Color", "Color Type");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "iuser");
- RNA_def_property_ui_text(prop, "Image User",
- "Parameters defining which layer, pass and frame of the image is displayed");
+ prop = RNA_def_property(srna, "single_color", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_float_sdna(prop, NULL, "shading.single_color");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Color", "Color for single color mode");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "clip_user", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_struct_type(prop, "MovieClipUser");
- RNA_def_property_pointer_sdna(prop, NULL, "cuser");
- RNA_def_property_ui_text(prop, "Clip User", "Parameters defining which frame of the movie clip is displayed");
+ prop = RNA_def_property(srna, "show_shadows", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "shading.flag", V3D_SHADING_SHADOW);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Shadow", "Show Shadow");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "offset_x", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "xof");
- RNA_def_property_ui_text(prop, "X Offset", "Offset image horizontally from the world origin");
+ prop = RNA_def_property(srna, "shadow_intensity", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "shading.shadow_intensity");
+ RNA_def_property_float_default(prop, 0.5);
+ RNA_def_property_ui_text(prop, "Shadow Intensity", "Darkness of shadows");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_ui_range(prop, 0.00f, 1.0f, 1, 3);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+}
+
+static void rna_def_space_view3d_overlay(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "View3DOverlay", NULL);
+ RNA_def_struct_sdna(srna, "View3D");
+ RNA_def_struct_nested(brna, srna, "SpaceView3D");
+ RNA_def_struct_path_func(srna, "rna_View3DOverlay_path");
+ RNA_def_struct_ui_text(srna, "3D View Overlay Settings", "Settings for display of overlays in the 3D viewport");
- prop = RNA_def_property(srna, "offset_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "yof");
- RNA_def_property_ui_text(prop, "Y Offset", "Offset image vertically from the world origin");
+ prop = RNA_def_property(srna, "show_overlays", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "flag2", V3D_RENDER_OVERRIDE);
+ RNA_def_property_ui_text(prop, "Show Overlays", "Display overlays like manipulators and outlines");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "size", PROP_FLOAT, PROP_DISTANCE);
- RNA_def_property_float_sdna(prop, NULL, "size");
- RNA_def_property_float_funcs(prop, "rna_BackgroundImage_size_get", "rna_BackgroundImage_size_set", NULL);
- RNA_def_property_ui_text(prop, "Size", "Size of the background image (ortho view only)");
- RNA_def_property_range(prop, 0.0, FLT_MAX);
+ prop = RNA_def_property(srna, "show_floor", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_FLOOR);
+ RNA_def_property_ui_text(prop, "Display Grid Floor", "Show the ground plane grid in perspective view");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "show_axis_x", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_X);
+ RNA_def_property_ui_text(prop, "Display X Axis", "Show the X axis line in perspective view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "rotation", PROP_FLOAT, PROP_EULER);
- RNA_def_property_float_sdna(prop, NULL, "rotation");
- RNA_def_property_ui_text(prop, "Rotation", "Rotation for the background image (ortho view only)");
+ prop = RNA_def_property(srna, "show_axis_y", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_Y);
+ RNA_def_property_ui_text(prop, "Display Y Axis", "Show the Y axis line in perspective view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "use_flip_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_X);
- RNA_def_property_ui_text(prop, "Flip Horizontally", "Flip the background image horizontally");
+ prop = RNA_def_property(srna, "show_axis_z", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_Z);
+ RNA_def_property_ui_text(prop, "Display Z Axis", "Show the Z axis line in perspective view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "use_flip_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FLIP_Y);
- RNA_def_property_ui_text(prop, "Flip Vertically", "Flip the background image vertically");
+ prop = RNA_def_property(srna, "grid_scale", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_float_sdna(prop, NULL, "grid");
+ RNA_def_property_ui_text(prop, "Grid Scale", "Distance between 3D View grid lines");
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_ui_range(prop, 0.001f, 1000.0f, 0.1f, 3);
+ RNA_def_property_float_default(prop, 1.0f);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "opacity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "blend");
- RNA_def_property_float_funcs(prop, "rna_BackgroundImage_opacity_get", "rna_BackgroundImage_opacity_set", NULL);
- RNA_def_property_ui_text(prop, "Opacity", "Image opacity to blend the image against the background color");
- RNA_def_property_range(prop, 0.0, 1.0);
+ prop = RNA_def_property(srna, "grid_lines", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "gridlines");
+ RNA_def_property_ui_text(prop, "Grid Lines", "Number of grid lines to display in perspective view");
+ RNA_def_property_range(prop, 0, 1024);
+ RNA_def_property_int_default(prop, 16);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "view_axis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "view");
- RNA_def_property_enum_items(prop, bgpic_axis_items);
- RNA_def_property_ui_text(prop, "Image Axis", "The axis to display the image on");
+ prop = RNA_def_property(srna, "grid_subdivisions", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "gridsubdiv");
+ RNA_def_property_ui_text(prop, "Grid Subdivisions", "Number of subdivisions between grid lines");
+ RNA_def_property_range(prop, 1, 1024);
+ RNA_def_property_int_default(prop, 10);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "grid_scale_unit", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_float_funcs(prop, "rna_View3DOverlay_GridScaleUnit_get", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Grid Scale Unit", "Grid cell size scaled by scene unit system settings");
+
+ prop = RNA_def_property(srna, "show_outline_selected", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SELECT_OUTLINE);
+ RNA_def_property_ui_text(prop, "Outline Selected",
+ "Show an outline highlight around selected objects in non-wireframe views");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "show_expanded", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_EXPANDED);
- RNA_def_property_ui_text(prop, "Show Expanded", "Show the expanded in the user interface");
- RNA_def_property_ui_icon(prop, ICON_TRIA_RIGHT, 1);
+ prop = RNA_def_property(srna, "show_all_objects_origin", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_DRAW_CENTERS);
+ RNA_def_property_ui_text(prop, "All Object Origins",
+ "Show the object origin center dot for all (selected and unselected) objects");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "use_camera_clip", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_CAMERACLIP);
- RNA_def_property_ui_text(prop, "Camera Clip", "Use movie clip from active scene camera");
+ prop = RNA_def_property(srna, "show_relationship_lines", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", V3D_HIDE_HELPLINES);
+ RNA_def_property_ui_text(prop, "Relationship Lines",
+ "Show dashed lines indicating parent or constraint relationships");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "show_background_image", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", V3D_BGPIC_DISABLED);
- RNA_def_property_ui_text(prop, "Show Background Image", "Show this image as background");
+ /* TODO: this should become a per object setting? */
+ prop = RNA_def_property(srna, "show_backface_culling", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_BACKFACE_CULLING);
+ RNA_def_property_ui_text(prop, "Backface Culling", "Use back face culling to hide the back side of faces");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "show_on_foreground", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_BGPIC_FOREGROUND);
- RNA_def_property_ui_text(prop, "Show On Foreground", "Show this image in front of objects in viewport");
+ prop = RNA_def_property(srna, "show_cursor", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_negative_sdna(prop, NULL, "overlay.flag", V3D_OVERLAY_HIDE_CURSOR);
+ RNA_def_property_ui_text(prop, "Show 3D Cursor", "Display 3D Cursor Overlay");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- /* expose 1 flag as a enum of 2 items */
- prop = RNA_def_property(srna, "draw_depth", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
- RNA_def_property_enum_items(prop, bgpic_draw_depth_items);
- RNA_def_property_ui_text(prop, "Depth", "Draw under or over everything");
+ prop = RNA_def_property(srna, "show_face_orientation", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.flag", V3D_OVERLAY_FACE_ORIENTATION);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_ui_text(prop, "Face Orientation", "Show the Face Orientation Overlay");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- /* expose 2 flags as a enum of 3 items */
- prop = RNA_def_property(srna, "frame_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_bitflag_sdna(prop, NULL, "flag");
- RNA_def_property_enum_items(prop, bgpic_camera_frame_items);
- RNA_def_property_ui_text(prop, "Frame Method", "How the image fits in the camera frame");
+ prop = RNA_def_property(srna, "show_paint_wire", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.paint_flag", V3D_OVERLAY_PAINT_WIRE);
+ RNA_def_property_ui_text(prop, "Show Wire", "Use wireframe display in painting modes");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-}
-static void rna_def_backgroundImages(BlenderRNA *brna, PropertyRNA *cprop)
-{
- StructRNA *srna;
- FunctionRNA *func;
- PropertyRNA *parm;
+ prop = RNA_def_property(srna, "show_occlude_wire", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_OCCLUDE_WIRE);
+ RNA_def_property_ui_text(prop, "Hidden Wire", "Use hidden wireframe display in edit mode");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- RNA_def_property_srna(cprop, "BackgroundImages");
- srna = RNA_def_struct(brna, "BackgroundImages", NULL);
- RNA_def_struct_sdna(srna, "View3D");
- RNA_def_struct_ui_text(srna, "Background Images", "Collection of background images");
+ prop = RNA_def_property(srna, "show_weight", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_WEIGHT);
+ RNA_def_property_ui_text(prop, "Show Weights", "Draw weights in editmode");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- func = RNA_def_function(srna, "new", "rna_BackgroundImage_new");
- RNA_def_function_ui_description(func, "Add new background image");
- parm = RNA_def_pointer(func, "image", "BackgroundImage", "", "Image displayed as viewport background");
- RNA_def_function_return(func, parm);
+ prop = RNA_def_property(srna, "show_face_normals", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_FACE_NORMALS);
+ RNA_def_property_ui_text(prop, "Draw Normals", "Display face normals as lines");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- func = RNA_def_function(srna, "remove", "rna_BackgroundImage_remove");
- RNA_def_function_ui_description(func, "Remove background image");
- RNA_def_function_flag(func, FUNC_USE_REPORTS);
- parm = RNA_def_pointer(func, "image", "BackgroundImage", "", "Image displayed as viewport background");
- RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
- RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+ prop = RNA_def_property(srna, "show_vertex_normals", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_VERT_NORMALS);
+ RNA_def_property_ui_text(prop, "Draw Vertex Normals", "Display vertex normals as lines");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- func = RNA_def_function(srna, "clear", "rna_BackgroundImage_clear");
- RNA_def_function_ui_description(func, "Remove all background images");
-}
+ prop = RNA_def_property(srna, "show_split_normals", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.edit_flag", V3D_OVERLAY_EDIT_LOOP_NORMALS);
+ RNA_def_property_ui_text(prop, "Draw Split Normals", "Display vertex-per-face normals as lines");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ prop = RNA_def_property(srna, "normals_length", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "overlay.normals_length");
+ RNA_def_property_ui_text(prop, "Normal Size", "Display size for normals in the 3D view");
+ RNA_def_property_range(prop, 0.00001, 1000.0);
+ RNA_def_property_ui_range(prop, 0.01, 10.0, 10.0, 2);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "backwire_opacity", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_sdna(prop, NULL, "overlay.backwire_opacity");
+ RNA_def_property_ui_text(prop, "Backwire Opacity", "Opacity when rendering transparent wires");
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+
+ prop = RNA_def_property(srna, "transparent_bones", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "overlay.arm_flag", V3D_OVERLAY_ARM_TRANSP_BONES);
+ RNA_def_property_ui_text(prop, "Transparent Bones", "Display bones as transparent");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+}
static void rna_def_space_view3d(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
- static const EnumPropertyItem manipulators_items[] = {
- {V3D_MANIP_TRANSLATE, "TRANSLATE", ICON_MAN_TRANS, "Translate",
- "Use the manipulator for movement transformations"},
- {V3D_MANIP_ROTATE, "ROTATE", ICON_MAN_ROT, "Rotate",
- "Use the manipulator for rotation transformations"},
- {V3D_MANIP_SCALE, "SCALE", ICON_MAN_SCALE, "Scale",
- "Use the manipulator for scale transformations"},
- {0, NULL, 0, NULL, NULL}
- };
-
static const EnumPropertyItem rv3d_persp_items[] = {
{RV3D_PERSP, "PERSP", 0, "Perspective", ""},
{RV3D_ORTHO, "ORTHO", 0, "Orthographic", ""},
@@ -2462,14 +2501,6 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Lock to Cursor", "3D View center is locked to the cursor's position");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "viewport_shade", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "drawtype");
- RNA_def_property_enum_items(prop, rna_enum_viewport_shade_items);
- RNA_def_property_enum_funcs(prop, "rna_SpaceView3D_viewport_shade_get", "rna_SpaceView3D_viewport_shade_set",
- "rna_SpaceView3D_viewport_shade_itemf");
- RNA_def_property_ui_text(prop, "Viewport Shading", "Method to display/shade objects in the 3D View");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_viewport_shade_update");
-
prop = RNA_def_property(srna, "local_view", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "localvd");
RNA_def_property_ui_text(prop, "Local View",
@@ -2505,71 +2536,6 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Clip End", "3D View far clipping distance");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "grid_scale", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "grid");
- RNA_def_property_ui_text(prop, "Grid Scale", "Distance between 3D View grid lines");
- RNA_def_property_range(prop, 0.0f, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.001f, 1000.0f, 0.1f, 3);
- RNA_def_property_float_default(prop, 1.0f);
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "grid_lines", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "gridlines");
- RNA_def_property_ui_text(prop, "Grid Lines", "Number of grid lines to display in perspective view");
- RNA_def_property_range(prop, 0, 1024);
- RNA_def_property_int_default(prop, 16);
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "grid_subdivisions", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "gridsubdiv");
- RNA_def_property_ui_text(prop, "Grid Subdivisions", "Number of subdivisions between grid lines");
- RNA_def_property_range(prop, 1, 1024);
- RNA_def_property_int_default(prop, 10);
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "grid_scale_unit", PROP_FLOAT, PROP_NONE);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_float_funcs(prop, "rna_View3D_GridScaleUnit_get", NULL, NULL);
- RNA_def_property_ui_text(prop, "Grid Scale Unit", "Grid cell size scaled by scene unit system settings");
-
- prop = RNA_def_property(srna, "show_floor", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_FLOOR);
- RNA_def_property_ui_text(prop, "Display Grid Floor", "Show the ground plane grid in perspective view");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "show_axis_x", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_X);
- RNA_def_property_ui_text(prop, "Display X Axis", "Show the X axis line in perspective view");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "show_axis_y", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_Y);
- RNA_def_property_ui_text(prop, "Display Y Axis", "Show the Y axis line in perspective view");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "show_axis_z", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "gridflag", V3D_SHOW_Z);
- RNA_def_property_ui_text(prop, "Display Z Axis", "Show the Z axis line in perspective view");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "show_outline_selected", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_SELECT_OUTLINE);
- RNA_def_property_ui_text(prop, "Outline Selected",
- "Show an outline highlight around selected objects in non-wireframe views");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "show_all_objects_origin", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_DRAW_CENTERS);
- RNA_def_property_ui_text(prop, "All Object Origins",
- "Show the object origin center dot for all (selected and unselected) objects");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "show_relationship_lines", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", V3D_HIDE_HELPLINES);
- RNA_def_property_ui_text(prop, "Relationship Lines",
- "Show dashed lines indicating parent or constraint relationships");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
prop = RNA_def_property(srna, "show_grease_pencil", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_SHOW_GPENCIL);
RNA_def_property_ui_text(prop, "Show Grease Pencil",
@@ -2581,14 +2547,9 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Textured Solid", "Display face-assigned textures in solid view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "show_backface_culling", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_BACKFACE_CULLING);
- RNA_def_property_ui_text(prop, "Backface Culling", "Use back face culling to hide the back side of faces");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "show_textured_shadeless", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_SHADELESS_TEX);
- RNA_def_property_ui_text(prop, "Shadeless", "Show shadeless texture without lighting in textured draw mode");
+ prop = RNA_def_property(srna, "show_mode_shade_override", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_SHOW_MODE_SHADE_OVERRIDE);
+ RNA_def_property_ui_text(prop, "Full Shading", "Use full shading for mode drawing (to view final result)");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "show_occlude_wire", PROP_BOOLEAN, PROP_NONE);
@@ -2601,11 +2562,6 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Lock Camera to View", "Enable view navigation within the camera view");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "show_only_render", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag2", V3D_RENDER_OVERRIDE);
- RNA_def_property_ui_text(prop, "Only Render", "Display only objects which will be rendered");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
prop = RNA_def_property(srna, "show_world", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "flag3", V3D_SHOW_WORLD);
RNA_def_property_ui_text(prop, "World Background", "Display world colors in the background");
@@ -2617,19 +2573,6 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_icon(prop, ICON_ORTHO, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "background_images", PROP_COLLECTION, PROP_NONE);
- RNA_def_property_collection_sdna(prop, NULL, "bgpicbase", NULL);
- RNA_def_property_struct_type(prop, "BackgroundImage");
- RNA_def_property_ui_text(prop, "Background Images", "List of background images");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- rna_def_backgroundImages(brna, prop);
-
- prop = RNA_def_property(srna, "show_background_images", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", V3D_DISPBGPICS);
- RNA_def_property_ui_text(prop, "Display Background Images",
- "Display reference images behind objects in the 3D View");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
prop = RNA_def_property(srna, "pivot_point", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "around");
RNA_def_property_enum_items(prop, pivot_items_full);
@@ -2643,30 +2586,11 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_pivot_update");
prop = RNA_def_property(srna, "show_manipulator", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "twflag", V3D_USE_MANIPULATOR);
+ RNA_def_property_boolean_sdna(prop, NULL, "twflag", V3D_MANIPULATOR_DRAW);
RNA_def_property_ui_text(prop, "Manipulator", "Use a 3D manipulator widget for controlling transforms");
RNA_def_property_ui_icon(prop, ICON_MANIPUL, 0);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
- prop = RNA_def_property(srna, "transform_manipulators", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "twtype");
- RNA_def_property_enum_items(prop, manipulators_items);
- RNA_def_property_flag(prop, PROP_ENUM_FLAG);
- RNA_def_property_ui_text(prop, "Transform Manipulators", "Transformation manipulators");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "transform_orientation", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "twmode");
- RNA_def_property_enum_items(prop, transform_orientation_items);
- RNA_def_property_enum_funcs(prop, NULL, NULL, "rna_TransformOrientation_itemf");
- RNA_def_property_ui_text(prop, "Transform Orientation", "Transformation orientation");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
-
- prop = RNA_def_property(srna, "current_orientation", PROP_POINTER, PROP_NONE);
- RNA_def_property_struct_type(prop, "TransformOrientation");
- RNA_def_property_pointer_funcs(prop, "rna_CurrentOrientation_get", NULL, NULL, NULL);
- RNA_def_property_ui_text(prop, "Current Transform Orientation", "Current transformation orientation");
-
prop = RNA_def_property(srna, "lock_camera_and_layers", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "scenelock", 1);
RNA_def_property_boolean_funcs(prop, NULL, "rna_SpaceView3D_lock_camera_and_layers_set");
@@ -2749,7 +2673,7 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_enum_sdna(prop, NULL, "matcap_icon");
RNA_def_property_enum_items(prop, view3d_matcap_items);
RNA_def_property_ui_text(prop, "Matcap", "Image to use for Material Capture, active objects only");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, "rna_SpaceView3D_matcap_update");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
prop = RNA_def_property(srna, "fx_settings", PROP_POINTER, PROP_NONE);
RNA_def_property_ui_text(prop, "FX Options", "Options used for real time compositing");
@@ -2795,6 +2719,22 @@ static void rna_def_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Volume Alpha", "Opacity (alpha) of the cameras' frustum volume");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_VIEW3D, NULL);
+ /* Nested Structs */
+ prop = RNA_def_property(srna, "shading", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_struct_type(prop, "View3DShading");
+ RNA_def_property_pointer_funcs(prop, "rna_SpaceView3D_shading_get", NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Shading Settings", "Settings for shading in the 3D viewport");
+
+ prop = RNA_def_property(srna, "overlay", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_struct_type(prop, "View3DOverlay");
+ RNA_def_property_pointer_funcs(prop, "rna_SpaceView3D_overlay_get", NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Overlay Settings", "Settings for display of overlays in the 3D viewport");
+
+ rna_def_space_view3d_shading(brna);
+ rna_def_space_view3d_overlay(brna);
+
/* *** Animated *** */
RNA_define_animate_sdna(true);
/* region */
@@ -2932,17 +2872,10 @@ static void rna_def_space_buttons(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Align", "Arrangement of the panels");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL);
- prop = RNA_def_property(srna, "texture_context", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_items(prop, buttons_texture_context_items);
- RNA_def_property_enum_funcs(prop, NULL, "rna_SpaceProperties_texture_context_set",
- "rna_SpaceProperties_texture_context_itemf");
- RNA_def_property_ui_text(prop, "Texture Context", "Type of texture data to display and edit");
- RNA_def_property_update(prop, NC_TEXTURE, NULL);
-
- prop = RNA_def_property(srna, "use_limited_texture_context", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", SB_TEX_USER_LIMITED);
- RNA_def_property_ui_text(prop, "Limited Texture Context",
- "Use the limited version of texture user (for 'old shading' mode)");
+ prop = RNA_def_property(srna, "collection_context", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, buttons_collection_context_items);
+ RNA_def_property_ui_text(prop, "Collection Context", "Which collection we want to show");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_PROPERTIES, NULL);
/* pinned data */
prop = RNA_def_property(srna, "pin_id", PROP_POINTER, PROP_NONE);
@@ -3117,7 +3050,7 @@ static void rna_def_space_sequencer(BlenderRNA *brna)
static const EnumPropertyItem view_type_items[] = {
{SEQ_VIEW_SEQUENCE, "SEQUENCER", ICON_SEQ_SEQUENCER, "Sequencer", ""},
{SEQ_VIEW_PREVIEW, "PREVIEW", ICON_SEQ_PREVIEW, "Image Preview", ""},
- {SEQ_VIEW_SEQUENCE_PREVIEW, "SEQUENCER_PREVIEW", ICON_SEQ_SPLITVIEW, "Sequencer and Image Preview", ""},
+ {SEQ_VIEW_SEQUENCE_PREVIEW, "SEQUENCER_PREVIEW", ICON_SEQ_SPLITVIEW, "Sequencer/Preview", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -3408,7 +3341,8 @@ static void rna_def_space_dopesheet(BlenderRNA *brna)
PropertyRNA *prop;
/* XXX: action-editor is currently for object-level only actions, so show that using object-icon hint */
- static const EnumPropertyItem mode_items[] = {
+ static EnumPropertyItem mode_items[] = {
+ {SACTCONT_TIMELINE, "TIMELINE", ICON_TIME, "Timeline", "Timeline and playback controls"},
{SACTCONT_DOPESHEET, "DOPESHEET", ICON_OOPS, "Dope Sheet", "Edit all keyframes in scene"},
{SACTCONT_ACTION, "ACTION", ICON_OBJECT_DATA, "Action Editor", "Edit keyframes in active object's Object-level action"},
{SACTCONT_SHAPEKEY, "SHAPEKEY", ICON_SHAPEKEY_DATA, "Shape Key Editor", "Edit keyframes in active object's Shape Keys action"},
@@ -3429,6 +3363,7 @@ static void rna_def_space_dopesheet(BlenderRNA *brna)
RNA_def_property_pointer_funcs(prop, NULL, "rna_SpaceDopeSheetEditor_action_set", NULL,
"rna_Action_actedit_assign_poll");
RNA_def_property_ui_text(prop, "Action", "Action displayed and edited in this space");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_ANIMATION | ND_KEYFRAME | NA_EDITED, "rna_SpaceDopeSheetEditor_action_update");
/* mode */
@@ -3436,6 +3371,7 @@ static void rna_def_space_dopesheet(BlenderRNA *brna)
RNA_def_property_enum_sdna(prop, NULL, "mode");
RNA_def_property_enum_items(prop, mode_items);
RNA_def_property_ui_text(prop, "Mode", "Editing context being displayed");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_DOPESHEET, "rna_SpaceDopeSheetEditor_mode_update");
/* display */
@@ -3497,6 +3433,42 @@ static void rna_def_space_dopesheet(BlenderRNA *brna)
RNA_def_property_enum_items(prop, autosnap_items);
RNA_def_property_ui_text(prop, "Auto Snap", "Automatic time snapping settings for transformations");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_DOPESHEET, NULL);
+
+ /* displaying cache status */
+ prop = RNA_def_property(srna, "show_cache", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_DISPLAY);
+ RNA_def_property_ui_text(prop, "Show Cache", "Show the status of cached frames in the timeline");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
+
+ prop = RNA_def_property(srna, "cache_softbody", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_SOFTBODY);
+ RNA_def_property_ui_text(prop, "Softbody", "Show the active object's softbody point cache");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
+
+ prop = RNA_def_property(srna, "cache_particles", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_PARTICLES);
+ RNA_def_property_ui_text(prop, "Particles", "Show the active object's particle point cache");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
+
+ prop = RNA_def_property(srna, "cache_cloth", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_CLOTH);
+ RNA_def_property_ui_text(prop, "Cloth", "Show the active object's cloth point cache");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
+
+ prop = RNA_def_property(srna, "cache_smoke", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_SMOKE);
+ RNA_def_property_ui_text(prop, "Smoke", "Show the active object's smoke cache");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
+
+ prop = RNA_def_property(srna, "cache_dynamicpaint", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_DYNAMICPAINT);
+ RNA_def_property_ui_text(prop, "Dynamic Paint", "Show the active object's Dynamic Paint cache");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
+
+ prop = RNA_def_property(srna, "cache_rigidbody", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_RIGIDBODY);
+ RNA_def_property_ui_text(prop, "Rigid Body", "Show the active object's Rigid Body cache");
+ RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
}
static void rna_def_space_graph(BlenderRNA *brna)
@@ -3700,63 +3672,6 @@ static void rna_def_space_nla(BlenderRNA *brna)
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NLA, NULL);
}
-static void rna_def_space_time(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "SpaceTimeline", "Space");
- RNA_def_struct_sdna(srna, "SpaceTime");
- RNA_def_struct_ui_text(srna, "Space Timeline Editor", "Timeline editor space data");
-
- /* view settings */
- prop = RNA_def_property(srna, "show_frame_indicator", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", TIME_CFRA_NUM);
- RNA_def_property_ui_text(prop, "Show Frame Number Indicator",
- "Show frame number beside the current frame indicator line");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- prop = RNA_def_property(srna, "show_seconds", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "flag", TIME_DRAWFRAMES);
- RNA_def_property_ui_text(prop, "Show Seconds", "Show timing in seconds not frames");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- /* displaying cache status */
- prop = RNA_def_property(srna, "show_cache", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_DISPLAY);
- RNA_def_property_ui_text(prop, "Show Cache", "Show the status of cached frames in the timeline");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- prop = RNA_def_property(srna, "cache_softbody", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_SOFTBODY);
- RNA_def_property_ui_text(prop, "Softbody", "Show the active object's softbody point cache");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- prop = RNA_def_property(srna, "cache_particles", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_PARTICLES);
- RNA_def_property_ui_text(prop, "Particles", "Show the active object's particle point cache");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- prop = RNA_def_property(srna, "cache_cloth", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_CLOTH);
- RNA_def_property_ui_text(prop, "Cloth", "Show the active object's cloth point cache");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- prop = RNA_def_property(srna, "cache_smoke", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_SMOKE);
- RNA_def_property_ui_text(prop, "Smoke", "Show the active object's smoke cache");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- prop = RNA_def_property(srna, "cache_dynamicpaint", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_DYNAMICPAINT);
- RNA_def_property_ui_text(prop, "Dynamic Paint", "Show the active object's Dynamic Paint cache");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-
- prop = RNA_def_property(srna, "cache_rigidbody", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "cache_display", TIME_CACHE_RIGIDBODY);
- RNA_def_property_ui_text(prop, "Rigid Body", "Show the active object's Rigid Body cache");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_TIME, NULL);
-}
static void rna_def_console_line(BlenderRNA *brna)
{
@@ -3879,6 +3794,7 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
"Particles Settings", "Show/hide Particle Settings data-blocks"},
{FILTER_ID_PAL, "PALETTE", ICON_COLOR, "Palettes", "Show/hide Palette data-blocks"},
{FILTER_ID_PC, "PAINT_CURVE", ICON_CURVE_BEZCURVE, "Paint Curves", "Show/hide Paint Curve data-blocks"},
+ {FILTER_ID_LP, "LIGHT_PROBE", ICON_RADIO, "Light Probes", "Show/hide Light Probe data-blocks"},
{FILTER_ID_SCE, "SCENE", ICON_SCENE_DATA, "Scenes", "Show/hide Scene data-blocks"},
{FILTER_ID_SPK, "SPEAKER", ICON_SPEAKER, "Speakers", "Show/hide Speaker data-blocks"},
{FILTER_ID_SO, "SOUND", ICON_SOUND, "Sounds", "Show/hide Sound data-blocks"},
@@ -3886,6 +3802,7 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
{FILTER_ID_TXT, "TEXT", ICON_TEXT, "Texts", "Show/hide Text data-blocks"},
{FILTER_ID_VF, "FONT", ICON_FONT_DATA, "Fonts", "Show/hide Font data-blocks"},
{FILTER_ID_WO, "WORLD", ICON_WORLD_DATA, "Worlds", "Show/hide World data-blocks"},
+ {FILTER_ID_WS, "WORK_SPACE", ICON_NONE, "Workspaces", "Show/hide workspace data-blocks"},
{0, NULL, 0, NULL, NULL}
};
@@ -3903,7 +3820,7 @@ static void rna_def_fileselect_params(BlenderRNA *brna)
"Show/hide materials, nodetrees, textures and Freestyle's linestyles"},
{FILTER_ID_IM | FILTER_ID_MC | FILTER_ID_MSK | FILTER_ID_SO,
"IMAGE", ICON_IMAGE_DATA, "Images & Sounds", "Show/hide images, movie clips, sounds and masks"},
- {FILTER_ID_CA | FILTER_ID_LA | FILTER_ID_SPK | FILTER_ID_WO,
+ {FILTER_ID_CA | FILTER_ID_LA | FILTER_ID_SPK | FILTER_ID_WO | FILTER_ID_WS,
"ENVIRONMENT", ICON_WORLD_DATA, "Environment", "Show/hide worlds, lamps, cameras and speakers"},
{FILTER_ID_BR | FILTER_ID_GD | FILTER_ID_PA | FILTER_ID_PAL | FILTER_ID_PC | FILTER_ID_TXT | FILTER_ID_VF | FILTER_ID_CF,
"MISC", ICON_GREASEPENCIL, "Miscellaneous", "Show/hide other data types"},
@@ -4298,7 +4215,6 @@ static void rna_def_space_node(BlenderRNA *brna)
PropertyRNA *prop;
static const EnumPropertyItem texture_id_type_items[] = {
- {SNODE_TEX_OBJECT, "OBJECT", ICON_OBJECT_DATA, "Object", "Edit texture nodes from Object"},
{SNODE_TEX_WORLD, "WORLD", ICON_WORLD_DATA, "World", "Edit texture nodes from World"},
{SNODE_TEX_BRUSH, "BRUSH", ICON_BRUSH_DATA, "Brush", "Edit texture nodes from Brush"},
#ifdef WITH_FREESTYLE
@@ -4418,14 +4334,10 @@ static void rna_def_space_node(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Backdrop Zoom", "Backdrop zoom factor");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
- prop = RNA_def_property(srna, "backdrop_x", PROP_FLOAT, PROP_NONE);
+ prop = RNA_def_property(srna, "backdrop_offset", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "xof");
- RNA_def_property_ui_text(prop, "Backdrop X", "Backdrop X offset");
- RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
-
- prop = RNA_def_property(srna, "backdrop_y", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "yof");
- RNA_def_property_ui_text(prop, "Backdrop Y", "Backdrop Y offset");
+ RNA_def_property_array(prop, 2);
+ RNA_def_property_ui_text(prop, "Backdrop Offset", "Backdrop offset");
RNA_def_property_update(prop, NC_SPACE | ND_SPACE_NODE_VIEW, NULL);
prop = RNA_def_property(srna, "backdrop_channels", PROP_ENUM, PROP_NONE);
@@ -4458,75 +4370,6 @@ static void rna_def_space_node(BlenderRNA *brna)
RNA_api_space_node(srna);
}
-static void rna_def_space_logic(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "SpaceLogicEditor", "Space");
- RNA_def_struct_sdna(srna, "SpaceLogic");
- RNA_def_struct_ui_text(srna, "Space Logic Editor", "Logic editor space data");
-
- /* sensors */
- prop = RNA_def_property(srna, "show_sensors_selected_objects", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_SENS_SEL);
- RNA_def_property_ui_text(prop, "Show Selected Object", "Show sensors of all selected objects");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_sensors_active_object", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_SENS_ACT);
- RNA_def_property_ui_text(prop, "Show Active Object", "Show sensors of active object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_sensors_linked_controller", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_SENS_LINK);
- RNA_def_property_ui_text(prop, "Show Linked to Controller", "Show linked objects to the controller");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_sensors_active_states", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_SENS_STATE);
- RNA_def_property_ui_text(prop, "Show Active States", "Show only sensors connected to active states");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* controllers */
- prop = RNA_def_property(srna, "show_controllers_selected_objects", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_CONT_SEL);
- RNA_def_property_ui_text(prop, "Show Selected Object", "Show controllers of all selected objects");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_controllers_active_object", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_CONT_ACT);
- RNA_def_property_ui_text(prop, "Show Active Object", "Show controllers of active object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_controllers_linked_controller", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_CONT_LINK);
- RNA_def_property_ui_text(prop, "Show Linked to Controller", "Show linked objects to sensor/actuator");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- /* actuators */
- prop = RNA_def_property(srna, "show_actuators_selected_objects", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_ACT_SEL);
- RNA_def_property_ui_text(prop, "Show Selected Object", "Show actuators of all selected objects");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_actuators_active_object", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_ACT_ACT);
- RNA_def_property_ui_text(prop, "Show Active Object", "Show actuators of active object");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_actuators_linked_controller", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_ACT_LINK);
- RNA_def_property_ui_text(prop, "Show Linked to Actuator", "Show linked objects to the actuator");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
- prop = RNA_def_property(srna, "show_actuators_active_states", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "scaflag", BUTS_ACT_STATE);
- RNA_def_property_ui_text(prop, "Show Active States", "Show only actuators connected to active states");
- RNA_def_property_update(prop, NC_LOGIC, NULL);
-
-}
-
static void rna_def_space_clip(BlenderRNA *brna)
{
StructRNA *srna;
@@ -4799,20 +4642,17 @@ void RNA_def_space(BlenderRNA *brna)
rna_def_filemenu_entry(brna);
rna_def_space_filebrowser(brna);
rna_def_space_outliner(brna);
- rna_def_background_image(brna);
rna_def_space_view3d(brna);
rna_def_space_buttons(brna);
rna_def_space_dopesheet(brna);
rna_def_space_graph(brna);
rna_def_space_nla(brna);
- rna_def_space_time(brna);
rna_def_space_console(brna);
rna_def_console_line(brna);
rna_def_space_info(brna);
rna_def_space_userpref(brna);
rna_def_node_tree_path(brna);
rna_def_space_node(brna);
- rna_def_space_logic(brna);
rna_def_space_clip(brna);
}
diff --git a/source/blender/makesrna/intern/rna_space_api.c b/source/blender/makesrna/intern/rna_space_api.c
index 8f771eda99d..f1206b7130f 100644
--- a/source/blender/makesrna/intern/rna_space_api.c
+++ b/source/blender/makesrna/intern/rna_space_api.c
@@ -31,9 +31,12 @@
#ifdef RNA_RUNTIME
+#include "BKE_global.h"
+
+#include "ED_screen.h"
#include "ED_text.h"
-static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d)
+static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d, bContext *C)
{
bScreen *sc = (bScreen *)id;
@@ -43,11 +46,20 @@ static void rna_RegionView3D_update(ID *id, RegionView3D *rv3d)
area_region_from_regiondata(sc, rv3d, &sa, &ar);
if (sa && ar && sa->spacetype == SPACE_VIEW3D) {
- View3D *v3d;
-
- v3d = (View3D *)sa->spacedata.first;
-
- ED_view3d_update_viewmat(sc->scene, v3d, ar, NULL, NULL, NULL);
+ View3D *v3d = sa->spacedata.first;
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wmWindow *win;
+
+ for (win = wm->windows.first; win; win = win->next) {
+ if (WM_window_get_active_screen(win) == sc) {
+ Scene *scene = WM_window_get_active_scene(win);
+ ViewLayer *view_layer = WM_window_get_active_view_layer(win);
+ Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+
+ ED_view3d_update_viewmat(depsgraph, scene, v3d, ar, NULL, NULL, NULL);
+ break;
+ }
+ }
}
}
@@ -71,7 +83,7 @@ void RNA_api_region_view3d(StructRNA *srna)
FunctionRNA *func;
func = RNA_def_function(srna, "update", "rna_RegionView3D_update");
- RNA_def_function_flag(func, FUNC_USE_SELF_ID);
+ RNA_def_function_flag(func, FUNC_USE_SELF_ID | FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Recalculate the view matrices");
}
diff --git a/source/blender/makesrna/intern/rna_speaker.c b/source/blender/makesrna/intern/rna_speaker.c
index f47b54c2d95..f37b75b3db2 100644
--- a/source/blender/makesrna/intern/rna_speaker.c
+++ b/source/blender/makesrna/intern/rna_speaker.c
@@ -41,7 +41,6 @@
#include "MEM_guardedalloc.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "WM_api.h"
diff --git a/source/blender/makesrna/intern/rna_texture.c b/source/blender/makesrna/intern/rna_texture.c
index 39674724889..5449b67c040 100644
--- a/source/blender/makesrna/intern/rna_texture.c
+++ b/source/blender/makesrna/intern/rna_texture.c
@@ -67,19 +67,14 @@ const EnumPropertyItem rna_enum_texture_type_items[] = {
{TEX_CLOUDS, "CLOUDS", ICON_TEXTURE, "Clouds", "Procedural - create a cloud-like fractal noise texture"},
{TEX_DISTNOISE, "DISTORTED_NOISE", ICON_TEXTURE,
"Distorted Noise", "Procedural - noise texture distorted by two noise algorithms"},
- {TEX_ENVMAP, "ENVIRONMENT_MAP", ICON_IMAGE_DATA,
- "Environment Map", "Create a render of the environment mapped to a texture"},
{TEX_IMAGE, "IMAGE", ICON_IMAGE_DATA, "Image or Movie", "Allow for images or movies to be used as textures"},
{TEX_MAGIC, "MAGIC", ICON_TEXTURE, "Magic", "Procedural - color texture based on trigonometric functions"},
{TEX_MARBLE, "MARBLE", ICON_TEXTURE, "Marble", "Procedural - marble-like noise texture with wave generated bands"},
{TEX_MUSGRAVE, "MUSGRAVE", ICON_TEXTURE, "Musgrave", "Procedural - highly flexible fractal noise texture"},
{TEX_NOISE, "NOISE", ICON_TEXTURE, "Noise",
"Procedural - random noise, gives a different result every time, for every frame, for every pixel"},
- {TEX_OCEAN, "OCEAN", ICON_TEXTURE, "Ocean", "Use a texture generated by an Ocean modifier"},
- {TEX_POINTDENSITY, "POINT_DENSITY", ICON_TEXTURE, "Point Density", ""},
{TEX_STUCCI, "STUCCI", ICON_TEXTURE, "Stucci", "Procedural - create a fractal noise texture"},
{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"},
{0, NULL, 0, NULL, NULL}
};
@@ -114,11 +109,12 @@ static const EnumPropertyItem blend_type_items[] = {
#include "BKE_colorband.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BKE_texture.h"
#include "BKE_main.h"
+#include "DEG_depsgraph.h"
+
#include "ED_node.h"
#include "ED_render.h"
@@ -133,8 +129,6 @@ static StructRNA *rna_Texture_refine(struct PointerRNA *ptr)
return &RNA_CloudsTexture;
case TEX_DISTNOISE:
return &RNA_DistortedNoiseTexture;
- case TEX_ENVMAP:
- return &RNA_EnvironmentMapTexture;
case TEX_IMAGE:
return &RNA_ImageTexture;
case TEX_MAGIC:
@@ -145,18 +139,12 @@ static StructRNA *rna_Texture_refine(struct PointerRNA *ptr)
return &RNA_MusgraveTexture;
case TEX_NOISE:
return &RNA_NoiseTexture;
- case TEX_POINTDENSITY:
- return &RNA_PointDensityTexture;
case TEX_STUCCI:
return &RNA_StucciTexture;
case TEX_VORONOI:
return &RNA_VoronoiTexture;
- case TEX_VOXELDATA:
- return &RNA_VoxelDataTexture;
case TEX_WOOD:
return &RNA_WoodTexture;
- case TEX_OCEAN:
- return &RNA_OceanTexture;
default:
return &RNA_Texture;
}
@@ -169,7 +157,7 @@ static void rna_Texture_update(Main *bmain, Scene *UNUSED(scene), PointerRNA *pt
if (GS(id->name) == ID_TE) {
Tex *tex = ptr->id.data;
- DAG_id_tag_update(&tex->id, 0);
+ DEG_id_tag_update(&tex->id, 0);
WM_main_add_notifier(NC_TEXTURE, tex);
WM_main_add_notifier(NC_MATERIAL | ND_SHADING_DRAW, NULL);
}
@@ -191,31 +179,12 @@ static void rna_Color_mapping_update(Main *UNUSED(bmain), Scene *UNUSED(scene),
/* nothing to do */
}
-static void rna_Texture_voxeldata_update(Main *bmain, Scene *scene, PointerRNA *ptr)
-{
- Tex *tex = ptr->id.data;
-
- tex->vd->ok = 0;
- rna_Texture_update(bmain, scene, ptr);
-}
-
-static void rna_Texture_voxeldata_image_update(Main *bmain, Scene *scene, PointerRNA *ptr)
-{
- Tex *tex = ptr->id.data;
-
- if (tex->ima) { /* may be getting cleared too */
- tex->ima->source = IMA_SRC_SEQUENCE;
- }
- rna_Texture_voxeldata_update(bmain, scene, ptr);
-}
-
-
/* Used for Texture Properties, used (also) for/in Nodes */
static void rna_Texture_nodes_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
Tex *tex = ptr->id.data;
- DAG_id_tag_update(&tex->id, 0);
+ DEG_id_tag_update(&tex->id, 0);
WM_main_add_notifier(NC_TEXTURE | ND_NODES, tex);
}
@@ -226,11 +195,11 @@ static void rna_Texture_type_set(PointerRNA *ptr, int value)
BKE_texture_type_set(tex, value);
}
-void rna_TextureSlot_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
+void rna_TextureSlot_update(bContext *C, PointerRNA *ptr)
{
ID *id = ptr->id.data;
- DAG_id_tag_update(id, 0);
+ DEG_id_tag_update(id, 0);
switch (GS(id->name)) {
case ID_MA:
@@ -246,8 +215,10 @@ void rna_TextureSlot_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
break;
case ID_BR:
{
+ Scene *scene = CTX_data_scene(C);
MTex *mtex = ptr->data;
- BKE_paint_invalidate_overlay_tex(scene, mtex->tex);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ BKE_paint_invalidate_overlay_tex(scene, view_layer, mtex->tex);
WM_main_add_notifier(NC_BRUSH, id);
break;
}
@@ -264,7 +235,7 @@ void rna_TextureSlot_update(Main *UNUSED(bmain), Scene *scene, PointerRNA *ptr)
if (mtex->mapto & PAMAP_CHILD)
recalc |= PSYS_RECALC_CHILD;
- DAG_id_tag_update(id, recalc);
+ DEG_id_tag_update(id, recalc);
WM_main_add_notifier(NC_OBJECT | ND_PARTICLE | NA_EDITED, NULL);
break;
}
@@ -430,54 +401,6 @@ static void rna_ImageTexture_mipmap_set(PointerRNA *ptr, int value)
else tex->imaflag &= ~TEX_MIPMAP;
}
-static void rna_Envmap_update_generic(Main *bmain, Scene *scene, PointerRNA *ptr)
-{
- Tex *tex = ptr->id.data;
- if (tex->env) {
- ED_preview_kill_jobs(bmain->wm.first, bmain);
- BKE_texture_envmap_free_data(tex->env);
- }
- rna_Texture_update(bmain, scene, ptr);
-}
-
-static PointerRNA rna_PointDensity_psys_get(PointerRNA *ptr)
-{
- PointDensity *pd = ptr->data;
- Object *ob = pd->object;
- ParticleSystem *psys = NULL;
- PointerRNA value;
-
- if (ob && pd->psys)
- psys = BLI_findlink(&ob->particlesystem, pd->psys - 1);
-
- RNA_pointer_create(&ob->id, &RNA_ParticleSystem, psys, &value);
- return value;
-}
-
-static void rna_PointDensity_psys_set(PointerRNA *ptr, PointerRNA value)
-{
- PointDensity *pd = ptr->data;
- Object *ob = pd->object;
-
- if (ob && value.id.data == ob)
- pd->psys = BLI_findindex(&ob->particlesystem, value.data) + 1;
-}
-
-static char *rna_PointDensity_path(PointerRNA *UNUSED(ptr))
-{
- return BLI_sprintfN("point_density");
-}
-
-static char *rna_VoxelData_path(PointerRNA *UNUSED(ptr))
-{
- return BLI_sprintfN("voxel_data");
-}
-
-static char *rna_OceanTex_path(PointerRNA *UNUSED(ptr))
-{
- return BLI_sprintfN("ocean");
-}
-
#else
static void rna_def_texmapping(BlenderRNA *brna)
@@ -649,7 +572,7 @@ static void rna_def_mtex(BlenderRNA *brna)
prop = RNA_def_property(srna, "texture", PROP_POINTER, PROP_NONE);
RNA_def_property_pointer_sdna(prop, NULL, "tex");
RNA_def_property_struct_type(prop, "Texture");
- RNA_def_property_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Texture", "Texture data-block used by this texture slot");
RNA_def_property_update(prop, NC_MATERIAL | ND_SHADING_LINKS, "rna_TextureSlot_update");
@@ -657,6 +580,7 @@ static void rna_def_mtex(BlenderRNA *brna)
RNA_def_property_string_funcs(prop, "rna_TextureSlot_name_get", "rna_TextureSlot_name_length", NULL);
RNA_def_property_ui_text(prop, "Name", "Texture slot name");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_struct_name_property(srna, prop);
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
@@ -664,12 +588,13 @@ static void rna_def_mtex(BlenderRNA *brna)
prop = RNA_def_property(srna, "offset", PROP_FLOAT, PROP_TRANSLATION);
RNA_def_property_float_sdna(prop, NULL, "ofs");
RNA_def_property_ui_range(prop, -10, 10, 10, RNA_TRANSLATION_PREC_DEFAULT);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Offset", "Fine tune of the texture mapping X, Y and Z locations");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "scale", PROP_FLOAT, PROP_XYZ);
RNA_def_property_float_sdna(prop, NULL, "size");
- RNA_def_property_flag(prop, PROP_PROPORTIONAL);
+ RNA_def_property_flag(prop, PROP_PROPORTIONAL | PROP_CONTEXT_UPDATE);
RNA_def_property_ui_range(prop, -100, 100, 10, 2);
RNA_def_property_ui_text(prop, "Size", "Set scaling for the texture's X, Y and Z sizes");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
@@ -677,6 +602,7 @@ static void rna_def_mtex(BlenderRNA *brna)
prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
RNA_def_property_float_sdna(prop, NULL, "r");
RNA_def_property_array(prop, 3);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Color",
"Default color for textures that don't return RGB or when RGB to intensity is enabled");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
@@ -684,26 +610,31 @@ static void rna_def_mtex(BlenderRNA *brna)
prop = RNA_def_property(srna, "blend_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "blendtype");
RNA_def_property_enum_items(prop, blend_type_items);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Blend Type", "Mode used to apply the texture");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "use_stencil", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_STENCIL);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Stencil", "Use this texture as a blending value on the next texture");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "invert", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_NEGATIVE);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "Negate", "Invert the values of the texture to reverse its effect");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "use_rgb_to_intensity", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "texflag", MTEX_RGBTOINT);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_text(prop, "RGB to Intensity", "Convert texture RGB values to intensity (gray) values");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
prop = RNA_def_property(srna, "default_value", PROP_FLOAT, PROP_NONE);
RNA_def_property_float_sdna(prop, NULL, "def_var");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_ui_range(prop, 0, 1, 10, 3);
RNA_def_property_ui_text(prop, "Default Value",
"Value to use for Ref, Spec, Amb, Emit, Alpha, RayMir, TransLu and Hard");
@@ -712,6 +643,7 @@ static void rna_def_mtex(BlenderRNA *brna)
prop = RNA_def_property(srna, "output_node", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "which_output");
RNA_def_property_enum_items(prop, output_node_items);
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
RNA_def_property_enum_funcs(prop, "rna_TextureSlot_output_node_get", NULL, "rna_TextureSlot_output_node_itemf");
RNA_def_property_ui_text(prop, "Output Node", "Which output node to use, for node-based textures");
RNA_def_property_update(prop, 0, "rna_TextureSlot_update");
@@ -738,7 +670,7 @@ static void rna_def_filter_common(StructRNA *srna)
RNA_def_property_ui_text(prop, "Filter", "Texture filter to use for sampling image");
RNA_def_property_update(prop, 0, "rna_Texture_update");
- prop = RNA_def_property(srna, "filter_probes", PROP_INT, PROP_NONE);
+ prop = RNA_def_property(srna, "filter_lightprobes", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "afmax");
RNA_def_property_range(prop, 1, 256);
RNA_def_property_ui_text(prop, "Filter Probes",
@@ -767,94 +699,6 @@ static void rna_def_filter_common(StructRNA *srna)
RNA_def_property_update(prop, 0, "rna_Texture_update");
}
-static void rna_def_environment_map(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem prop_source_items[] = {
- {ENV_STATIC, "STATIC", 0, "Static", "Calculate environment map only once"},
- {ENV_ANIM, "ANIMATED", 0, "Animated", "Calculate environment map at each rendering"},
- {ENV_LOAD, "IMAGE_FILE", 0, "Image File", "Load a saved environment map image from disk"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_mapping_items[] = {
- {ENV_CUBE, "CUBE", 0, "Cube", "Use environment map with six cube sides"},
- {ENV_PLANE, "PLANE", 0, "Plane", "Only one side is rendered, with Z axis pointing in direction of image"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "EnvironmentMap", NULL);
- RNA_def_struct_sdna(srna, "EnvMap");
- RNA_def_struct_ui_text(srna, "EnvironmentMap",
- "Environment map created by the renderer and cached for subsequent renders");
-
- prop = RNA_def_property(srna, "source", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "stype");
- RNA_def_property_enum_items(prop, prop_source_items);
- RNA_def_property_ui_text(prop, "Source", "");
- RNA_def_property_update(prop, 0, "rna_Envmap_update_generic");
-
- prop = RNA_def_property(srna, "viewpoint_object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "object");
- RNA_def_property_ui_text(prop, "Viewpoint Object", "Object to use as the environment map's viewpoint location");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "mapping", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "type");
- RNA_def_property_enum_items(prop, prop_mapping_items);
- RNA_def_property_ui_text(prop, "Mapping", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "clip_start", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "clipsta");
- RNA_def_property_range(prop, 0.001, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.01, 50, 100, 2);
- RNA_def_property_ui_text(prop, "Clip Start", "Objects nearer than this are not visible to map");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "clip_end", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "clipend");
- RNA_def_property_range(prop, 0.01, FLT_MAX);
- RNA_def_property_ui_range(prop, 0.10, 20000, 100, 2);
- RNA_def_property_ui_text(prop, "Clip End", "Objects further than this are not visible to map");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "zoom", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "viewscale");
- RNA_def_property_range(prop, 0.1, 5.0);
- RNA_def_property_ui_range(prop, 0.5, 1.5, 1, 2);
- RNA_def_property_ui_text(prop, "Zoom", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "layers_ignore", PROP_BOOLEAN, PROP_LAYER_MEMBER);
- RNA_def_property_boolean_sdna(prop, NULL, "notlay", 1);
- RNA_def_property_array(prop, 20);
- RNA_def_property_ui_text(prop, "Ignore Layers",
- "Hide objects on these layers when generating the Environment Map");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "resolution", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "cuberes");
- RNA_def_property_range(prop, 50, 4096);
- RNA_def_property_ui_text(prop, "Resolution", "Pixel resolution of the rendered environment map");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "depth", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_range(prop, 0, 5);
- RNA_def_property_ui_text(prop, "Depth", "Number of times a map will be rendered recursively (mirror effects)");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "is_valid", PROP_BOOLEAN, 0);
- RNA_def_property_boolean_sdna(prop, NULL, "ok", 2);
- RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Validity", "True if this map is ready for use, False if it needs rendering");
-
- RNA_api_environment_map(srna);
-}
-
static const EnumPropertyItem prop_noise_basis_items[] = {
{TEX_BLENDER, "BLENDER_ORIGINAL", 0, "Blender Original",
"Noise algorithm - Blender original: Smooth interpolated noise"},
@@ -1360,43 +1204,6 @@ static void rna_def_texture_image(BlenderRNA *brna)
RNA_def_property_boolean_sdna(prop, NULL, "imaflag", TEX_NORMALMAP);
RNA_def_property_ui_text(prop, "Normal Map", "Use image RGB values for normal mapping");
RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- /* Derivative Map */
- prop = RNA_def_property(srna, "use_derivative_map", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "imaflag", TEX_DERIVATIVEMAP);
- RNA_def_property_ui_text(prop, "Derivative Map", "Use red and green as derivative values");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-}
-
-static void rna_def_texture_environment_map(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- srna = RNA_def_struct(brna, "EnvironmentMapTexture", "Texture");
- RNA_def_struct_ui_text(srna, "Environment Map", "Environment map texture");
- RNA_def_struct_sdna(srna, "Tex");
-
- prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "ima");
- RNA_def_property_struct_type(prop, "Image");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Image", "Source image file to read the environment map from");
- RNA_def_property_update(prop, 0, "rna_Envmap_update_generic");
-
- prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "iuser");
- RNA_def_property_ui_text(prop, "Image User",
- "Parameters defining which layer, pass and frame of the image is displayed");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- rna_def_filter_common(srna);
-
- prop = RNA_def_property(srna, "environment_map", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "env");
- RNA_def_property_struct_type(prop, "EnvironmentMap");
- RNA_def_property_ui_text(prop, "Environment Map", "Get the environment map associated with this texture");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
}
static void rna_def_texture_musgrave(BlenderRNA *brna)
@@ -1621,407 +1428,6 @@ static void rna_def_texture_distorted_noise(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_Texture_update");
}
-static void rna_def_texture_pointdensity(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem point_source_items[] = {
- {TEX_PD_PSYS, "PARTICLE_SYSTEM", 0, "Particle System", "Generate point density from a particle system"},
- {TEX_PD_OBJECT, "OBJECT", 0, "Object Vertices", "Generate point density from an object's vertices"},
- /*{TEX_PD_FILE, "FILE", 0, "File", ""}, */
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem particle_cache_items[] = {
- {TEX_PD_OBJECTLOC, "OBJECT_LOCATION", 0, "Emit Object Location", ""},
- {TEX_PD_OBJECTSPACE, "OBJECT_SPACE", 0, "Emit Object Space", ""},
- {TEX_PD_WORLDSPACE, "WORLD_SPACE", 0, "Global Space", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem vertex_cache_items[] = {
- {TEX_PD_OBJECTLOC, "OBJECT_LOCATION", 0, "Object Location", ""},
- {TEX_PD_OBJECTSPACE, "OBJECT_SPACE", 0, "Object Space", ""},
- {TEX_PD_WORLDSPACE, "WORLD_SPACE", 0, "Global Space", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem falloff_items[] = {
- {TEX_PD_FALLOFF_STD, "STANDARD", 0, "Standard", ""},
- {TEX_PD_FALLOFF_SMOOTH, "SMOOTH", 0, "Smooth", ""},
- {TEX_PD_FALLOFF_SOFT, "SOFT", 0, "Soft", ""},
- {TEX_PD_FALLOFF_CONSTANT, "CONSTANT", 0, "Constant", "Density is constant within lookup radius"},
- {TEX_PD_FALLOFF_ROOT, "ROOT", 0, "Root", ""},
- {TEX_PD_FALLOFF_PARTICLE_AGE, "PARTICLE_AGE", 0, "Particle Age", ""},
- {TEX_PD_FALLOFF_PARTICLE_VEL, "PARTICLE_VELOCITY", 0, "Particle Velocity", ""},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem particle_color_source_items[] = {
- {TEX_PD_COLOR_CONSTANT, "CONSTANT", 0, "Constant", ""},
- {TEX_PD_COLOR_PARTAGE, "PARTICLE_AGE", 0, "Particle Age", "Lifetime mapped as 0.0 - 1.0 intensity"},
- {TEX_PD_COLOR_PARTSPEED, "PARTICLE_SPEED", 0, "Particle Speed",
- "Particle speed (absolute magnitude of velocity) mapped as 0.0-1.0 intensity"},
- {TEX_PD_COLOR_PARTVEL, "PARTICLE_VELOCITY", 0, "Particle Velocity", "XYZ velocity mapped to RGB colors"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem vertex_color_source_items[] = {
- {TEX_PD_COLOR_CONSTANT, "CONSTANT", 0, "Constant", ""},
- {TEX_PD_COLOR_VERTCOL, "VERTEX_COLOR", 0, "Vertex Color", "Vertex color layer"},
- {TEX_PD_COLOR_VERTWEIGHT, "VERTEX_WEIGHT", 0, "Vertex Weight", "Vertex group weight"},
- {TEX_PD_COLOR_VERTNOR, "VERTEX_NORMAL", 0, "Vertex Normal", "XYZ normal vector mapped to RGB colors"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem turbulence_influence_items[] = {
- {TEX_PD_NOISE_STATIC, "STATIC", 0, "Static",
- "Noise patterns will remain unchanged, faster and suitable for stills"},
- {TEX_PD_NOISE_VEL, "PARTICLE_VELOCITY", 0, "Particle Velocity",
- "Turbulent noise driven by particle velocity"},
- {TEX_PD_NOISE_AGE, "PARTICLE_AGE", 0, "Particle Age",
- "Turbulent noise driven by the particle's age between birth and death"},
- {TEX_PD_NOISE_TIME, "GLOBAL_TIME", 0, "Global Time", "Turbulent noise driven by the global current frame"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "PointDensity", NULL);
- RNA_def_struct_sdna(srna, "PointDensity");
- RNA_def_struct_ui_text(srna, "PointDensity", "Point density settings");
- RNA_def_struct_path_func(srna, "rna_PointDensity_path");
-
- prop = RNA_def_property(srna, "point_source", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "source");
- RNA_def_property_enum_items(prop, point_source_items);
- RNA_def_property_ui_text(prop, "Point Source", "Point data to use as renderable point density");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "object");
- RNA_def_property_ui_text(prop, "Object", "Object to take point data from");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "particle_system", PROP_POINTER, PROP_NONE);
- RNA_def_property_ui_text(prop, "Particle System", "Particle System to render as points");
- RNA_def_property_struct_type(prop, "ParticleSystem");
- RNA_def_property_pointer_funcs(prop, "rna_PointDensity_psys_get", "rna_PointDensity_psys_set", NULL, NULL);
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "particle_cache_space", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "psys_cache_space");
- RNA_def_property_enum_items(prop, particle_cache_items);
- RNA_def_property_ui_text(prop, "Particle Cache", "Coordinate system to cache particles in");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "vertex_cache_space", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "ob_cache_space");
- RNA_def_property_enum_items(prop, vertex_cache_items);
- RNA_def_property_ui_text(prop, "Vertices Cache", "Coordinate system to cache vertices in");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "radius", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "radius");
- RNA_def_property_range(prop, 0.001, FLT_MAX);
- RNA_def_property_ui_text(prop, "Radius", "Radius from the shaded sample to look for points within");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "falloff", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "falloff_type");
- RNA_def_property_enum_items(prop, falloff_items);
- RNA_def_property_ui_text(prop, "Falloff", "Method of attenuating density by distance from the point");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "falloff_soft", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "falloff_softness");
- RNA_def_property_range(prop, 0.01, FLT_MAX);
- RNA_def_property_ui_text(prop, "Softness", "Softness of the 'soft' falloff option");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "particle_color_source", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "color_source");
- RNA_def_property_enum_items(prop, particle_color_source_items);
- RNA_def_property_ui_text(prop, "Color Source", "Data to derive color results from");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "vertex_color_source", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "ob_color_source");
- RNA_def_property_enum_items(prop, vertex_color_source_items);
- RNA_def_property_ui_text(prop, "Color Source", "Data to derive color results from");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "vertex_attribute_name", PROP_STRING, PROP_NONE);
- RNA_def_property_ui_text(prop, "Vertex Attribute Name", "Vertex attribute to use for color");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "speed_scale", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "speed_scale");
- RNA_def_property_range(prop, 0.001, 100.0);
- RNA_def_property_ui_text(prop, "Scale", "Multiplier to bring particle speed within an acceptable range");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "falloff_speed_scale", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "falloff_speed_scale");
- RNA_def_property_range(prop, 0.001, 100.0);
- RNA_def_property_ui_text(prop, "Velocity Scale", "Multiplier to bring particle speed within an acceptable range");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
-
- prop = RNA_def_property(srna, "color_ramp", PROP_POINTER, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "coba");
- RNA_def_property_struct_type(prop, "ColorRamp");
- RNA_def_property_ui_text(prop, "Color Ramp", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "falloff_curve", PROP_POINTER, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "falloff_curve");
- RNA_def_property_struct_type(prop, "CurveMapping");
- RNA_def_property_ui_text(prop, "Falloff Curve", "");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "use_falloff_curve", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", TEX_PD_FALLOFF_CURVE);
- RNA_def_property_ui_text(prop, "Falloff Curve", "Use a custom falloff curve");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- /* Turbulence */
- prop = RNA_def_property(srna, "use_turbulence", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", TEX_PD_TURBULENCE);
- RNA_def_property_ui_text(prop, "Turbulence", "Add directed noise to the density at render-time");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "turbulence_scale", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "noise_size");
- RNA_def_property_range(prop, 0.01, FLT_MAX);
- RNA_def_property_ui_text(prop, "Size", "Scale of the added turbulent noise");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "turbulence_strength", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "noise_fac");
- RNA_def_property_range(prop, 0.01, FLT_MAX);
- RNA_def_property_ui_text(prop, "Turbulence Strength", "Strength of the added turbulent noise");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "turbulence_depth", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "noise_depth");
- RNA_def_property_range(prop, 0, 30);
- RNA_def_property_ui_text(prop, "Depth", "Level of detail in the added turbulent noise");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "turbulence_influence", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "noise_influence");
- RNA_def_property_enum_items(prop, turbulence_influence_items);
- RNA_def_property_ui_text(prop, "Turbulence Influence", "Method for driving added turbulent noise");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "noise_basis", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "noise_basis");
- RNA_def_property_enum_items(prop, prop_noise_basis_items);
- RNA_def_property_ui_text(prop, "Noise Basis", "Noise formula used for turbulence");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
-
- srna = RNA_def_struct(brna, "PointDensityTexture", "Texture");
- RNA_def_struct_sdna(srna, "Tex");
- RNA_def_struct_ui_text(srna, "Point Density", "Settings for the Point Density texture");
-
- prop = RNA_def_property(srna, "point_density", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "pd");
- RNA_def_property_struct_type(prop, "PointDensity");
- RNA_def_property_ui_text(prop, "Point Density", "The point density settings associated with this texture");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-}
-
-static void rna_def_texture_voxeldata(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem interpolation_type_items[] = {
- {TEX_VD_NEARESTNEIGHBOR, "NEREASTNEIGHBOR", 0, "Nearest Neighbor",
- "No interpolation, fast but blocky and low quality"},
- {TEX_VD_LINEAR, "TRILINEAR", 0, "Linear", "Good smoothness and speed"},
- {TEX_VD_QUADRATIC, "QUADRATIC", 0, "Quadratic", "Mid-range quality and speed"},
- {TEX_VD_TRICUBIC_CATROM, "TRICUBIC_CATROM", 0, "Cubic Catmull-Rom", "High quality interpolation, but slower"},
- {TEX_VD_TRICUBIC_BSPLINE, "TRICUBIC_BSPLINE", 0, "Cubic B-Spline",
- "Smoothed high quality interpolation, but slower"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem file_format_items[] = {
- {TEX_VD_BLENDERVOXEL, "BLENDER_VOXEL", 0, "Blender Voxel", "Default binary voxel file format"},
- {TEX_VD_RAW_8BIT, "RAW_8BIT", 0, "8 bit RAW", "8 bit grayscale binary data"},
- /*{TEX_VD_RAW_16BIT, "RAW_16BIT", 0, "16 bit RAW", ""}, */
- {TEX_VD_IMAGE_SEQUENCE, "IMAGE_SEQUENCE", 0, "Image Sequence",
- "Generate voxels from a sequence of image slices"},
- {TEX_VD_SMOKE, "SMOKE", 0, "Smoke", "Render voxels from a Blender smoke simulation"},
- {TEX_VD_HAIR, "HAIR", 0, "Hair", "Render voxels from a Blender hair simulation"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem voxeldata_extension[] = {
- {TEX_EXTEND, "EXTEND", 0, "Extend", "Extend by repeating edge pixels of the image"},
- {TEX_CLIP, "CLIP", 0, "Clip", "Clip to image size and set exterior pixels as transparent"},
- {TEX_REPEAT, "REPEAT", 0, "Repeat", "Cause the image to repeat horizontally and vertically"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem smoked_type_items[] = {
- {TEX_VD_SMOKEDENSITY, "SMOKEDENSITY", 0, "Smoke", "Use smoke density and color as texture data"},
- {TEX_VD_SMOKEFLAME, "SMOKEFLAME", 0, "Flame", "Use flame temperature as texture data"},
- {TEX_VD_SMOKEHEAT, "SMOKEHEAT", 0, "Heat", "Use smoke heat as texture data. Values from -2.0 to 2.0 are used"},
- {TEX_VD_SMOKEVEL, "SMOKEVEL", 0, "Velocity", "Use smoke velocity as texture data"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem hair_type_items[] = {
- {TEX_VD_HAIRDENSITY, "HAIRDENSITY", 0, "Density", "Use hair density as texture data"},
- {TEX_VD_HAIRRESTDENSITY, "HAIRRESTDENSITY", 0, "Rest Density", "Use hair rest density as texture data"},
- {TEX_VD_HAIRVELOCITY, "HAIRVELOCITY", 0, "Velocity", "Use hair velocity as texture data"},
- {TEX_VD_HAIRENERGY, "HAIRENERGY", 0, "Energy", "Use potential hair energy as texture data"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "VoxelData", NULL);
- RNA_def_struct_sdna(srna, "VoxelData");
- RNA_def_struct_ui_text(srna, "VoxelData", "Voxel data settings");
- RNA_def_struct_path_func(srna, "rna_VoxelData_path");
-
- prop = RNA_def_property(srna, "interpolation", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "interp_type");
- RNA_def_property_enum_items(prop, interpolation_type_items);
- RNA_def_property_ui_text(prop, "Interpolation", "Method to interpolate/smooth values between voxel cells");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "smoke_data_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "smoked_type");
- RNA_def_property_enum_items(prop, smoked_type_items);
- RNA_def_property_ui_text(prop, "Source", "Simulation value to be used as a texture");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
- prop = RNA_def_property(srna, "hair_data_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "hair_type");
- RNA_def_property_enum_items(prop, hair_type_items);
- RNA_def_property_ui_text(prop, "Source", "Simulation value to be used as a texture");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
- prop = RNA_def_property(srna, "extension", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "extend");
- RNA_def_property_enum_items(prop, voxeldata_extension);
- RNA_def_property_ui_text(prop, "Extension", "How the texture is extrapolated past its original bounds");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "intensity", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "int_multiplier");
- RNA_def_property_range(prop, 0.01, FLT_MAX);
- RNA_def_property_ui_text(prop, "Intensity", "Multiplier for intensity values");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "file_format", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "file_format");
- RNA_def_property_enum_items(prop, file_format_items);
- RNA_def_property_ui_text(prop, "File Format", "Format of the source data set to render");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
- prop = RNA_def_property(srna, "filepath", PROP_STRING, PROP_FILEPATH);
- RNA_def_property_string_sdna(prop, NULL, "source_path");
- RNA_def_property_ui_text(prop, "Source Path", "The external source data file to use");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
- prop = RNA_def_property(srna, "resolution", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "resol");
- RNA_def_property_range(prop, 1, 100000);
- RNA_def_property_ui_text(prop, "Resolution", "Resolution of the voxel grid");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
- prop = RNA_def_property(srna, "use_still_frame", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", TEX_VD_STILL);
- RNA_def_property_ui_text(prop, "Still Frame Only", "Always render a still frame from the voxel data sequence");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
- prop = RNA_def_property(srna, "still_frame", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "still_frame");
- RNA_def_property_range(prop, -MAXFRAME, MAXFRAME);
- RNA_def_property_ui_text(prop, "Still Frame Number", "The frame number to always use");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
- prop = RNA_def_property(srna, "domain_object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "object");
- RNA_def_property_ui_text(prop, "Domain Object", "Object used as the smoke simulation domain");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-
-
- srna = RNA_def_struct(brna, "VoxelDataTexture", "Texture");
- RNA_def_struct_sdna(srna, "Tex");
- RNA_def_struct_ui_text(srna, "Voxel Data", "Settings for the Voxel Data texture");
-
- prop = RNA_def_property(srna, "voxel_data", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "vd");
- RNA_def_property_struct_type(prop, "VoxelData");
- RNA_def_property_ui_text(prop, "Voxel Data", "The voxel data associated with this texture");
- RNA_def_property_update(prop, 0, "rna_Texture_update");
-
- prop = RNA_def_property(srna, "image", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "ima");
- RNA_def_property_struct_type(prop, "Image");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Image", "");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_image_update");
-
- prop = RNA_def_property(srna, "image_user", PROP_POINTER, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "iuser");
- RNA_def_property_ui_text(prop, "Image User",
- "Parameters defining which layer, pass and frame of the image is displayed");
- RNA_def_property_update(prop, 0, "rna_Texture_voxeldata_update");
-}
-
-static void rna_def_texture_ocean(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem ocean_output_items[] = {
- {TEX_OCN_DISPLACEMENT, "DISPLACEMENT", 0, "Displacement", "Output 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", "Output 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;
@@ -2122,13 +1528,9 @@ static void rna_def_texture(BlenderRNA *brna)
rna_def_texture_stucci(brna);
rna_def_texture_noise(brna);
rna_def_texture_image(brna);
- rna_def_texture_environment_map(brna);
rna_def_texture_musgrave(brna);
rna_def_texture_voronoi(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);
@@ -2138,7 +1540,6 @@ void RNA_def_texture(BlenderRNA *brna)
{
rna_def_texture(brna);
rna_def_mtex(brna);
- rna_def_environment_map(brna);
rna_def_texmapping(brna);
rna_def_colormapping(brna);
}
diff --git a/source/blender/makesrna/intern/rna_texture_api.c b/source/blender/makesrna/intern/rna_texture_api.c
index a8fcf0ca3b6..1d513a494d7 100644
--- a/source/blender/makesrna/intern/rna_texture_api.c
+++ b/source/blender/makesrna/intern/rna_texture_api.c
@@ -45,30 +45,6 @@
#include "RE_pipeline.h"
#include "RE_shader_ext.h"
-static void save_envmap(struct EnvMap *env, bContext *C, ReportList *reports, const char *filepath,
- struct Scene *scene, float layout[12])
-{
- if (scene == NULL) {
- scene = CTX_data_scene(C);
- }
-
- RE_WriteEnvmapResult(reports, scene, env, filepath, scene->r.im_format.imtype, layout);
-}
-
-static void clear_envmap(struct EnvMap *env, bContext *C)
-{
- Main *bmain = CTX_data_main(C);
- Tex *tex;
-
- BKE_texture_envmap_free_data(env);
-
- for (tex = bmain->tex.first; tex; tex = tex->id.next)
- if (tex->env == env) {
- WM_event_add_notifier(C, NC_TEXTURE | NA_EDITED, tex);
- break;
- }
-}
-
static void texture_evaluate(struct Tex *tex, float value[3], float r_color[4])
{
TexResult texres = {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
@@ -102,31 +78,4 @@ void RNA_api_texture(StructRNA *srna)
}
-void RNA_api_environment_map(StructRNA *srna)
-{
- FunctionRNA *func;
- PropertyRNA *parm;
-
- static const float default_layout[] = {0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1};
-
- func = RNA_def_function(srna, "clear", "clear_envmap");
- RNA_def_function_ui_description(func, "Discard the environment map and free it from memory");
- RNA_def_function_flag(func, FUNC_USE_CONTEXT);
-
-
- func = RNA_def_function(srna, "save", "save_envmap");
- RNA_def_function_ui_description(func, "Save the environment map to disc using the scene render settings");
- RNA_def_function_flag(func, FUNC_USE_CONTEXT | FUNC_USE_REPORTS);
-
- parm = RNA_def_string_file_name(func, "filepath", NULL, FILE_MAX, "File path", "Location of the output file");
- RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
-
- RNA_def_pointer(func, "scene", "Scene", "", "Overrides the scene from which image parameters are taken");
-
- RNA_def_float_array(func, "layout", 12, default_layout, 0.0f, 1000.0f, "File layout",
- "Flat array describing the X,Y position of each cube face in the "
- "output image, where 1 is the size of a face - order is [+Z -Z +Y -X -Y +X] "
- "(use -1 to skip a face)", 0.0f, 1000.0f);
-}
-
#endif
diff --git a/source/blender/makesrna/intern/rna_timeline.c b/source/blender/makesrna/intern/rna_timeline.c
index a732b550261..45f90d13477 100644
--- a/source/blender/makesrna/intern/rna_timeline.c
+++ b/source/blender/makesrna/intern/rna_timeline.c
@@ -74,7 +74,7 @@ static void rna_def_timeline_marker(BlenderRNA *brna)
prop = RNA_def_property(srna, "camera", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Object");
RNA_def_property_flag(prop, PROP_EDITABLE | PROP_ID_SELF_CHECK);
- RNA_def_property_ui_text(prop, "Camera", "Camera this timeline sets to active");
+ RNA_def_property_ui_text(prop, "Camera", "Camera that becomes active on this frame");
#endif
}
diff --git a/source/blender/makesrna/intern/rna_tracking.c b/source/blender/makesrna/intern/rna_tracking.c
index f44f7336cdf..ccc118edfb6 100644
--- a/source/blender/makesrna/intern/rna_tracking.c
+++ b/source/blender/makesrna/intern/rna_tracking.c
@@ -51,9 +51,10 @@
#include "DNA_anim_types.h"
#include "BKE_animsys.h"
-#include "BKE_depsgraph.h"
#include "BKE_node.h"
+#include "DEG_depsgraph.h"
+
#include "IMB_imbuf.h"
#include "WM_api.h"
@@ -426,7 +427,7 @@ static void rna_tracking_flushUpdate(Main *UNUSED(bmain), Scene *scene, PointerR
WM_main_add_notifier(NC_SCENE | ND_NODES, NULL);
WM_main_add_notifier(NC_SCENE, NULL);
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
}
static void rna_tracking_resetIntrinsics(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
@@ -515,7 +516,7 @@ static void rna_trackingObject_flushUpdate(Main *UNUSED(bmain), Scene *UNUSED(sc
MovieClip *clip = (MovieClip *)ptr->id.data;
WM_main_add_notifier(NC_OBJECT | ND_TRANSFORM, NULL);
- DAG_id_tag_update(&clip->id, 0);
+ DEG_id_tag_update(&clip->id, 0);
}
static void rna_trackingMarker_frame_set(PointerRNA *ptr, int value)
diff --git a/source/blender/makesrna/intern/rna_ui.c b/source/blender/makesrna/intern/rna_ui.c
index f2527a8a5e9..bb4f6719fbc 100644
--- a/source/blender/makesrna/intern/rna_ui.c
+++ b/source/blender/makesrna/intern/rna_ui.c
@@ -267,6 +267,13 @@ static StructRNA *rna_Panel_register(
else
BLI_addtail(&art->paneltypes, pt);
+ {
+ const char *owner_id = RNA_struct_state_owner_get();
+ if (owner_id) {
+ BLI_strncpy(pt->owner_id, owner_id, sizeof(pt->owner_id));
+ }
+ }
+
/* update while blender is running */
WM_main_add_notifier(NC_WINDOW, NULL);
@@ -561,7 +568,7 @@ static void rna_Header_unregister(Main *UNUSED(bmain), StructRNA *type)
if (!ht)
return;
- if (!(art = region_type_find(NULL, ht->space_type, RGN_TYPE_HEADER)))
+ if (!(art = region_type_find(NULL, ht->space_type, ht->region_type)))
return;
RNA_struct_free_extension(type, &ht->ext);
@@ -585,6 +592,7 @@ static StructRNA *rna_Header_register(
/* setup dummy header & header type to store static properties in */
dummyheader.type = &dummyht;
+ dummyht.region_type = RGN_TYPE_HEADER; /* RGN_TYPE_HEADER by default, may be overridden */
RNA_pointer_create(NULL, &RNA_Header, &dummyheader, &dummyhtr);
/* validate the python class */
@@ -597,7 +605,7 @@ static StructRNA *rna_Header_register(
return NULL;
}
- if (!(art = region_type_find(reports, dummyht.space_type, RGN_TYPE_HEADER)))
+ if (!(art = region_type_find(reports, dummyht.space_type, dummyht.region_type)))
return NULL;
/* check if we have registered this header type before, and remove it */
@@ -773,6 +781,13 @@ static StructRNA *rna_Menu_register(
mt->poll = (have_function[0]) ? menu_poll : NULL;
mt->draw = (have_function[1]) ? menu_draw : NULL;
+ {
+ const char *owner_id = RNA_struct_state_owner_get();
+ if (owner_id) {
+ BLI_strncpy(mt->owner_id, owner_id, sizeof(mt->owner_id));
+ }
+ }
+
WM_menutype_add(mt);
/* update while blender is running */
@@ -1023,6 +1038,10 @@ static void rna_def_panel(BlenderRNA *brna)
RNA_def_property_string_sdna(prop, NULL, "type->category");
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+ prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->owner_id");
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "type->space_type");
RNA_def_property_enum_items(prop, rna_enum_space_type_items);
@@ -1222,6 +1241,14 @@ static void rna_def_header(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_REGISTER);
RNA_def_property_ui_text(prop, "Space type", "The space where the header is going to be used in");
+ prop = RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "type->region_type");
+ RNA_def_property_enum_default(prop, RGN_TYPE_HEADER);
+ RNA_def_property_enum_items(prop, rna_enum_region_type_items);
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+ RNA_def_property_ui_text(prop, "Region Type", "The region where the header is going to be used in "
+ "(defaults to header region)");
+
RNA_define_verify_sdna(1);
}
@@ -1290,6 +1317,10 @@ static void rna_def_menu(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for NULL */
+ prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->owner_id");
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
RNA_define_verify_sdna(1);
}
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index dd3a2bf6fe2..d980696c3ee 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -268,6 +268,29 @@ static void rna_uiItemM(uiLayout *layout, bContext *C, const char *menuname, con
uiItemM(layout, C, menuname, name, icon);
}
+static void rna_uiItemPopoverPanel(
+ uiLayout *layout, bContext *C,
+ int space_type, int region_type, const char *panel_type,
+ const char *name, const char *text_ctxt,
+ int translate, int icon, int icon_value)
+{
+ /* Get translated name (label). */
+ name = rna_translate_ui_text(name, text_ctxt, NULL, NULL, translate);
+
+ if (icon_value && !icon) {
+ icon = icon_value;
+ }
+
+ uiItemPopoverPanel(layout, C, space_type, region_type, panel_type, name, icon);
+}
+
+static void rna_uiItemPopoverPanelFromGroup(
+ uiLayout *layout, bContext *C,
+ int space_id, int region_id, const char *context, const char *category)
+{
+ uiItemPopoverPanelFromGroup(layout, C, space_id, region_id, context, category);
+}
+
static void rna_uiTemplateAnyID(uiLayout *layout, PointerRNA *ptr, const char *propname, const char *proptypename,
const char *name, const char *text_ctxt, int translate)
{
@@ -670,6 +693,29 @@ void RNA_api_ui_layout(StructRNA *srna)
parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item");
+ func = RNA_def_function(srna, "popover", "rna_uiItemPopoverPanel");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ parm = RNA_def_enum(func, "space_type", rna_enum_space_type_items, 0, "Space Type", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_enum(func, "region_type", rna_enum_region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_string(func, "panel_type", NULL, 0, "", "Identifier of the panel");
+ api_ui_item_common(func);
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_property(func, "icon_value", PROP_INT, PROP_UNSIGNED);
+ RNA_def_property_ui_text(parm, "Icon Value", "Override automatic icon of the item");
+
+ func = RNA_def_function(srna, "popover_group", "rna_uiItemPopoverPanelFromGroup");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ parm = RNA_def_enum(func, "space_type", rna_enum_space_type_items, 0, "Space Type", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_enum(func, "region_type", rna_enum_region_type_items, RGN_TYPE_WINDOW, "Region Type", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_string(func, "context", NULL, 0, "", "panel type context");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_string(func, "category", NULL, 0, "", "panel type category");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
func = RNA_def_function(srna, "separator", "uiItemS");
RNA_def_function_ui_description(func, "Item. Inserts empty space into the layout between items");
@@ -714,7 +760,40 @@ void RNA_api_ui_layout(StructRNA *srna)
"Identifier of property in data giving the type of the ID-blocks to use");
RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
api_ui_item_common_text(func);
-
+
+ func = RNA_def_function(srna, "template_ID_tabs", "uiTemplateIDTabs");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ api_ui_item_rna_common(func);
+ RNA_def_string(func, "new", NULL, 0, "", "Operator identifier to create a new ID block");
+ RNA_def_string(func, "open", NULL, 0, "", "Operator identifier to open a file for creating a new ID block");
+ RNA_def_string(func, "unlink", NULL, 0, "", "Operator identifier to unlink the ID block");
+ RNA_def_enum(func, "filter", id_template_filter_items, UI_TEMPLATE_ID_FILTER_ALL,
+ "", "Optionally limit the items which can be selected");
+
+ func = RNA_def_function(srna, "template_search", "uiTemplateSearch");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ api_ui_item_rna_common(func);
+ parm = RNA_def_pointer(func, "search_data", "AnyType", "", "Data from which to take collection to search in");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ parm = RNA_def_string(func, "search_property", NULL, 0, "", "Identifier of search collection property");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_string(func, "new", NULL, 0, "", "Operator identifier to create a new item for the collection");
+ RNA_def_string(func, "unlink", NULL, 0, "", "Operator identifier to unlink or delete the active "
+ "item from the collection");
+
+ func = RNA_def_function(srna, "template_search_preview", "uiTemplateSearchPreview");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ api_ui_item_rna_common(func);
+ parm = RNA_def_pointer(func, "search_data", "AnyType", "", "Data from which to take collection to search in");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ parm = RNA_def_string(func, "search_property", NULL, 0, "", "Identifier of search collection property");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_string(func, "new", NULL, 0, "", "Operator identifier to create a new item for the collection");
+ RNA_def_string(func, "unlink", NULL, 0, "", "Operator identifier to unlink or delete the active "
+ "item from the collection");
+ RNA_def_int(func, "rows", 0, 0, INT_MAX, "Number of thumbnail preview rows to display", "", 0, INT_MAX);
+ RNA_def_int(func, "cols", 0, 0, INT_MAX, "Number of thumbnail preview columns to display", "", 0, INT_MAX);
+
func = RNA_def_function(srna, "template_path_builder", "rna_uiTemplatePathBuilder");
parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
@@ -899,6 +978,9 @@ void RNA_api_ui_layout(StructRNA *srna)
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
RNA_def_function_ui_description(func, "Inserts common 3DView header UI (selectors for context mode, shading, etc.)");
+ func = RNA_def_function(srna, "template_header_3D_mode", "uiTemplateHeader3D_mode");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ RNA_def_function_ui_description(func, "");
func = RNA_def_function(srna, "template_edit_mode_selection", "uiTemplateEditModeSelection");
RNA_def_function_flag(func, FUNC_USE_CONTEXT);
@@ -931,6 +1013,16 @@ void RNA_api_ui_layout(StructRNA *srna)
parm = RNA_def_pointer(func, "item", "KeyMapItem", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ func = RNA_def_function(srna, "template_override_property", "uiTemplateOverrideProperty");
+ parm = RNA_def_pointer(func, "collection_render_overrides", "AnyType", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ parm = RNA_def_pointer(func, "scene_collection_properties", "AnyType", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in collection_properties");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ api_ui_item_common(func);
+ parm = RNA_def_string(func, "custom_template", NULL, 0, "", "Optional template to use for property");
+
func = RNA_def_function(srna, "template_component_menu", "uiTemplateComponentMenu");
RNA_def_function_ui_description(func, "Item. Display expanded property in a popup menu");
parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
diff --git a/source/blender/makesrna/intern/rna_userdef.c b/source/blender/makesrna/intern/rna_userdef.c
index d813c095589..bcaa5f1fc9a 100644
--- a/source/blender/makesrna/intern/rna_userdef.c
+++ b/source/blender/makesrna/intern/rna_userdef.c
@@ -52,7 +52,6 @@
#include "WM_types.h"
#include "BLT_lang.h"
-#include "GPU_buffers.h"
#ifdef WITH_OPENSUBDIV
static const EnumPropertyItem opensubdiv_compute_type_items[] = {
@@ -68,16 +67,7 @@ static const EnumPropertyItem opensubdiv_compute_type_items[] = {
#endif
static const EnumPropertyItem audio_device_items[] = {
- {0, "NONE", 0, "None", "Null device - there will be no audio output"},
-#ifdef WITH_SDL
- {1, "SDL", 0, "SDL", "SDL device - simple direct media layer, recommended for sequencer usage"},
-#endif
-#ifdef WITH_OPENAL
- {2, "OPENAL", 0, "OpenAL", "OpenAL device - supports 3D audio, recommended for game engine usage"},
-#endif
-#ifdef WITH_JACK
- {3, "JACK", 0, "JACK", "JACK Audio Connection Kit, recommended for pro audio users"},
-#endif
+ {0, "Null", 0, "None", "Null device - there will be no audio output"},
{0, NULL, 0, NULL, NULL}
};
@@ -100,13 +90,14 @@ static const EnumPropertyItem rna_enum_language_default_items[] = {
#include "DNA_screen_types.h"
#include "BKE_blender.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_idprop.h"
#include "BKE_pbvh.h"
#include "BKE_paint.h"
+#include "DEG_depsgraph.h"
+
#include "GPU_draw.h"
#include "GPU_select.h"
@@ -183,10 +174,12 @@ static void rna_userdef_show_manipulator_update(Main *bmain, Scene *scene, Point
for (sl = sa->spacedata.first; sl; sl = sl->next) {
if (sl->spacetype == SPACE_VIEW3D) {
View3D *v3d = (View3D *)sl;
- if (userdef->tw_flag & V3D_USE_MANIPULATOR)
- v3d->twflag |= V3D_USE_MANIPULATOR;
- else
- v3d->twflag &= ~V3D_USE_MANIPULATOR;
+ if (userdef->manipulator_flag & USER_MANIPULATOR_DRAW) {
+ v3d->twflag |= V3D_MANIPULATOR_DRAW;
+ }
+ else {
+ v3d->twflag &= ~V3D_MANIPULATOR_DRAW;
+ }
}
}
}
@@ -210,12 +203,6 @@ static void rna_userdef_load_ui_update(Main *UNUSED(bmain), Scene *UNUSED(scene)
else G.fileflags &= ~G_FILE_NO_UI;
}
-static void rna_userdef_mipmap_update(Main *bmain, Scene *scene, PointerRNA *ptr)
-{
- GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
- rna_userdef_update(bmain, scene, ptr);
-}
-
static void rna_userdef_anisotropic_update(Main *bmain, Scene *scene, PointerRNA *ptr)
{
GPU_set_anisotropic(U.anisotropic_filter);
@@ -371,7 +358,7 @@ static void rna_UserDef_weight_color_update(Main *bmain, Scene *scene, PointerRN
for (ob = bmain->object.first; ob; ob = ob->id.next) {
if (ob->mode & OB_MODE_WEIGHT_PAINT)
- DAG_id_tag_update(&ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&ob->id, OB_RECALC_DATA);
}
rna_userdef_update(bmain, scene, ptr);
@@ -513,7 +500,7 @@ static void rna_userdef_opensubdiv_update(Main *bmain, Scene *UNUSED(scene), Poi
if (object->derivedFinal != NULL &&
object->derivedFinal->type == DM_TYPE_CCGDM)
{
- DAG_id_tag_update(&object->id, OB_RECALC_OB);
+ DEG_id_tag_update(&object->id, OB_RECALC_OB);
}
}
}
@@ -527,7 +514,6 @@ static const EnumPropertyItem *rna_userdef_audio_device_itemf(bContext *UNUSED(C
int totitem = 0;
EnumPropertyItem *item = NULL;
-#ifdef WITH_SYSTEM_AUDASPACE
int i;
char **names = BKE_sound_get_device_names();
@@ -536,31 +522,6 @@ static const EnumPropertyItem *rna_userdef_audio_device_itemf(bContext *UNUSED(C
EnumPropertyItem new_item = {i, names[i], 0, names[i], names[i]};
RNA_enum_item_add(&item, &totitem, &new_item);
}
-#else
- /* NONE */
- RNA_enum_item_add(&item, &totitem, &audio_device_items[index++]);
-
-#ifdef WITH_SDL
-# ifdef WITH_SDL_DYNLOAD
- if (sdlewInit() == SDLEW_SUCCESS)
-# endif
- {
- RNA_enum_item_add(&item, &totitem, &audio_device_items[index]);
- }
- index++;
-#endif
-
-#ifdef WITH_OPENAL
- RNA_enum_item_add(&item, &totitem, &audio_device_items[index++]);
-#endif
-
-#ifdef WITH_JACK
- if (BKE_sound_is_jack_supported()) {
- RNA_enum_item_add(&item, &totitem, &audio_device_items[index]);
- }
- index++;
-#endif
-#endif
/* may be unused */
UNUSED_VARS(index, audio_device_items);
@@ -679,6 +640,19 @@ static StructRNA *rna_AddonPref_refine(PointerRNA *ptr)
return (ptr->type) ? ptr->type : &RNA_AddonPreferences;
}
+static float rna_ThemeUI_roundness_get(PointerRNA *ptr)
+{
+ /* Remap from relative radius to 0..1 range. */
+ uiWidgetColors *tui = (uiWidgetColors *)ptr->data;
+ return tui->roundness * 2.0f;
+}
+
+static void rna_ThemeUI_roundness_set(PointerRNA *ptr, float value)
+{
+ uiWidgetColors *tui = (uiWidgetColors *)ptr->data;
+ tui->roundness = value * 0.5f;
+}
+
#else
/* TODO(sergey): This technically belongs to blenlib, but we don't link
@@ -849,6 +823,11 @@ static void rna_def_userdef_theme_ui_wcol(BlenderRNA *brna)
RNA_def_property_range(prop, -100, 100);
RNA_def_property_ui_text(prop, "Shade Down", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "roundness", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_float_funcs(prop, "rna_ThemeUI_roundness_get", "rna_ThemeUI_roundness_set", NULL);
+ RNA_def_property_ui_text(prop, "Roundness", "Amount of edge rounding");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
}
static void rna_def_userdef_theme_ui_wcol_state(BlenderRNA *brna)
@@ -891,6 +870,16 @@ static void rna_def_userdef_theme_ui_wcol_state(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Driven Selected", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+ prop = RNA_def_property(srna, "inner_overridden", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Overridden", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "inner_overridden_sel", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Overridden Selected", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
prop = RNA_def_property(srna, "blend", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_ui_text(prop, "Blend", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
@@ -973,6 +962,11 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_ui_text(prop, "Tool Widget Colors", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "wcol_toolbar_item", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_ui_text(prop, "Toolbar Item Widget Colors", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "wcol_radio", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
@@ -1059,6 +1053,11 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "State Colors", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+ prop = RNA_def_property(srna, "wcol_tab", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_ui_text(prop, "Tab Colors", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
prop = RNA_def_property(srna, "menu_shadow_fac", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_ui_text(prop, "Menu Shadow Strength", "Blending factor for menu shadows");
RNA_def_property_range(prop, 0.01f, 1.0f);
@@ -1077,6 +1076,10 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
prop = RNA_def_property(srna, "icon_alpha", PROP_FLOAT, PROP_FACTOR);
RNA_def_property_ui_text(prop, "Icon Alpha", "Transparency of icons in the interface, to reduce contrast");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "icon_saturation", PROP_FLOAT, PROP_FACTOR);
+ RNA_def_property_ui_text(prop, "Icon Saturation", "Saturation of icons in the interface");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "widget_emboss", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "widget_emboss");
@@ -1084,6 +1087,12 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Widget Emboss", "Color of the 1px shadow line underlying widgets");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+ prop = RNA_def_property(srna, "editor_outline", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "editor_outline");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Editor Outline", "Color of the outline of the editors and their round corners");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
/* axis */
prop = RNA_def_property(srna, "axis_x", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "xaxis");
@@ -1102,6 +1111,37 @@ static void rna_def_userdef_theme_ui(BlenderRNA *brna)
RNA_def_property_array(prop, 3);
RNA_def_property_ui_text(prop, "Z Axis", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ /* Generic manipulator colors. */
+ prop = RNA_def_property(srna, "manipulator_hi", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "manipulator_hi");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Manipulator Highlight", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "manipulator_primary", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "manipulator_primary");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Manipulator Primary", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "manipulator_secondary", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "manipulator_secondary");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Manipulator Secondary", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "manipulator_a", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "manipulator_a");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Manipulator A", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+
+ prop = RNA_def_property(srna, "manipulator_b", PROP_FLOAT, PROP_COLOR_GAMMA);
+ RNA_def_property_float_sdna(prop, NULL, "manipulator_b");
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_ui_text(prop, "Manipulator B", "");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
}
static void rna_def_userdef_theme_space_common(StructRNA *srna)
@@ -1125,7 +1165,7 @@ static void rna_def_userdef_theme_space_common(StructRNA *srna)
/* header */
prop = RNA_def_property(srna, "header", PROP_FLOAT, PROP_COLOR_GAMMA);
- RNA_def_property_array(prop, 3);
+ RNA_def_property_array(prop, 4);
RNA_def_property_ui_text(prop, "Header", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
@@ -1305,7 +1345,7 @@ static void rna_def_userdef_theme_spaces_vertex(StructRNA *srna)
RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "vertex_size", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 1, 10);
+ RNA_def_property_range(prop, 1, 32);
RNA_def_property_ui_text(prop, "Vertex Size", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
@@ -1527,7 +1567,7 @@ static void rna_def_userdef_theme_spaces_curves(StructRNA *srna, bool incl_nurbs
RNA_def_property_update(prop, 0, "rna_userdef_update");
prop = RNA_def_property(srna, "handle_vertex_size", PROP_INT, PROP_NONE);
- RNA_def_property_range(prop, 0, 255);
+ RNA_def_property_range(prop, 1, 100);
RNA_def_property_ui_text(prop, "Handle Vertex Size", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
}
@@ -1614,18 +1654,6 @@ static void rna_def_userdef_theme_space_view3d(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Active Object", "");
RNA_def_property_update(prop, 0, "rna_userdef_update");
- prop = RNA_def_property(srna, "object_grouped", PROP_FLOAT, PROP_COLOR_GAMMA);
- RNA_def_property_float_sdna(prop, NULL, "group");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Object Grouped", "");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-
- prop = RNA_def_property(srna, "object_grouped_active", PROP_FLOAT, PROP_COLOR_GAMMA);
- RNA_def_property_float_sdna(prop, NULL, "group_active");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Object Grouped Active", "");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-
prop = RNA_def_property(srna, "text_keyframe", PROP_FLOAT, PROP_COLOR_GAMMA);
RNA_def_property_float_sdna(prop, NULL, "time_keyframe");
RNA_def_property_array(prop, 3);
@@ -2273,23 +2301,6 @@ static void rna_def_userdef_theme_space_node(BlenderRNA *brna)
RNA_def_property_update(prop, 0, "rna_userdef_update");
}
-static void rna_def_userdef_theme_space_logic(BlenderRNA *brna)
-{
- StructRNA *srna;
-// PropertyRNA *prop;
-
- /* space_logic */
-
- srna = RNA_def_struct(brna, "ThemeLogicEditor", NULL);
- RNA_def_struct_sdna(srna, "ThemeSpace");
- RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
- RNA_def_struct_ui_text(srna, "Theme Logic Editor", "Theme settings for the Logic Editor");
-
- rna_def_userdef_theme_spaces_main(srna);
-
-}
-
-
static void rna_def_userdef_theme_space_buts(BlenderRNA *brna)
{
StructRNA *srna;
@@ -2306,44 +2317,6 @@ static void rna_def_userdef_theme_space_buts(BlenderRNA *brna)
}
-static void rna_def_userdef_theme_space_time(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- /* space_time */
-
- srna = RNA_def_struct(brna, "ThemeTimeline", NULL);
- RNA_def_struct_sdna(srna, "ThemeSpace");
- RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
- RNA_def_struct_ui_text(srna, "Theme Timeline", "Theme settings for the Timeline");
-
- rna_def_userdef_theme_spaces_main(srna);
-
- prop = RNA_def_property(srna, "grid", PROP_FLOAT, PROP_COLOR_GAMMA);
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Grid", "");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-
- prop = RNA_def_property(srna, "frame_current", PROP_FLOAT, PROP_COLOR_GAMMA);
- RNA_def_property_float_sdna(prop, NULL, "cframe");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Current Frame", "");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-
- prop = RNA_def_property(srna, "time_keyframe", PROP_FLOAT, PROP_COLOR_GAMMA);
- RNA_def_property_float_sdna(prop, NULL, "time_keyframe");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Keyframe", "Base color for keyframe indicator lines");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-
- prop = RNA_def_property(srna, "time_grease_pencil", PROP_FLOAT, PROP_COLOR_GAMMA);
- RNA_def_property_float_sdna(prop, NULL, "time_gp_keyframe");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Grease Pencil", "Color of Grease Pencil keyframes");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-}
-
static void rna_def_userdef_theme_space_image(BlenderRNA *brna)
{
StructRNA *srna;
@@ -2975,6 +2948,20 @@ static void rna_def_userdef_theme_space_clip(BlenderRNA *brna)
rna_def_userdef_theme_spaces_curves(srna, false, false, false, true);
}
+static void rna_def_userdef_theme_space_topbar(BlenderRNA *brna)
+{
+ StructRNA *srna;
+
+ /* space_topbar */
+
+ srna = RNA_def_struct(brna, "ThemeTopBar", NULL);
+ RNA_def_struct_sdna(srna, "ThemeSpace");
+ RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
+ RNA_def_struct_ui_text(srna, "Theme Top Bar", "Theme settings for the Top Bar");
+
+ rna_def_userdef_theme_spaces_main(srna);
+}
+
static void rna_def_userdef_themes(BlenderRNA *brna)
{
StructRNA *srna;
@@ -2985,7 +2972,6 @@ static void rna_def_userdef_themes(BlenderRNA *brna)
{19, "STYLE", ICON_FONTPREVIEW, "Text Style", ""},
{18, "BONE_COLOR_SETS", ICON_COLOR, "Bone Color Sets", ""},
{1, "VIEW_3D", ICON_VIEW3D, "3D View", ""},
- {2, "TIMELINE", ICON_TIME, "Timeline", ""},
{3, "GRAPH_EDITOR", ICON_IPO, "Graph Editor", ""},
{4, "DOPESHEET_EDITOR", ICON_ACTION, "Dope Sheet", ""},
{5, "NLA_EDITOR", ICON_NLA, "NLA Editor", ""},
@@ -2993,7 +2979,6 @@ static void rna_def_userdef_themes(BlenderRNA *brna)
{7, "SEQUENCE_EDITOR", ICON_SEQUENCE, "Video Sequence Editor", ""},
{8, "TEXT_EDITOR", ICON_TEXT, "Text Editor", ""},
{9, "NODE_EDITOR", ICON_NODETREE, "Node Editor", ""},
- {10, "LOGIC_EDITOR", ICON_LOGIC, "Logic Editor", ""},
{11, "PROPERTIES", ICON_BUTS, "Properties", ""},
{12, "OUTLINER", ICON_OOPS, "Outliner", ""},
{14, "USER_PREFERENCES", ICON_PREFERENCES, "User Preferences", ""},
@@ -3001,6 +2986,7 @@ static void rna_def_userdef_themes(BlenderRNA *brna)
{16, "FILE_BROWSER", ICON_FILESEL, "File Browser", ""},
{17, "CONSOLE", ICON_CONSOLE, "Python Console", ""},
{20, "CLIP_EDITOR", ICON_CLIP, "Movie Clip Editor", ""},
+ {21, "TOPBAR", ICON_NONE, "Top Bar", ""},
{0, NULL, 0, NULL, NULL}
};
@@ -3081,24 +3067,12 @@ static void rna_def_userdef_themes(BlenderRNA *brna)
RNA_def_property_struct_type(prop, "ThemeTextEditor");
RNA_def_property_ui_text(prop, "Text Editor", "");
- prop = RNA_def_property(srna, "timeline", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "ttime");
- RNA_def_property_struct_type(prop, "ThemeTimeline");
- RNA_def_property_ui_text(prop, "Timeline", "");
-
prop = RNA_def_property(srna, "node_editor", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "tnode");
RNA_def_property_struct_type(prop, "ThemeNodeEditor");
RNA_def_property_ui_text(prop, "Node Editor", "");
- prop = RNA_def_property(srna, "logic_editor", PROP_POINTER, PROP_NONE);
- RNA_def_property_flag(prop, PROP_NEVER_NULL);
- RNA_def_property_pointer_sdna(prop, NULL, "tlogic");
- RNA_def_property_struct_type(prop, "ThemeLogicEditor");
- RNA_def_property_ui_text(prop, "Logic Editor", "");
-
prop = RNA_def_property(srna, "outliner", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
RNA_def_property_pointer_sdna(prop, NULL, "toops");
@@ -3134,6 +3108,12 @@ static void rna_def_userdef_themes(BlenderRNA *brna)
RNA_def_property_pointer_sdna(prop, NULL, "tclip");
RNA_def_property_struct_type(prop, "ThemeClipEditor");
RNA_def_property_ui_text(prop, "Clip Editor", "");
+
+ prop = RNA_def_property(srna, "topbar", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_pointer_sdna(prop, NULL, "ttopbar");
+ RNA_def_property_struct_type(prop, "ThemeTopBar");
+ RNA_def_property_ui_text(prop, "Top Bar", "");
}
static void rna_def_userdef_addon(BlenderRNA *brna)
@@ -3217,14 +3197,13 @@ static void rna_def_userdef_dothemes(BlenderRNA *brna)
rna_def_userdef_theme_space_seq(brna);
rna_def_userdef_theme_space_buts(brna);
rna_def_userdef_theme_space_text(brna);
- rna_def_userdef_theme_space_time(brna);
rna_def_userdef_theme_space_node(brna);
rna_def_userdef_theme_space_outliner(brna);
rna_def_userdef_theme_space_info(brna);
rna_def_userdef_theme_space_userpref(brna);
rna_def_userdef_theme_space_console(brna);
- rna_def_userdef_theme_space_logic(brna);
rna_def_userdef_theme_space_clip(brna);
+ rna_def_userdef_theme_space_topbar(brna);
rna_def_userdef_theme_colorset(brna);
rna_def_userdef_themes(brna);
}
@@ -3379,11 +3358,6 @@ static void rna_def_userdef_view(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Display Object Info", "Display objects name and frame number in 3D view");
RNA_def_property_update(prop, 0, "rna_userdef_update");
- prop = RNA_def_property(srna, "use_global_scene", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "flag", USER_SCENEGLOBAL);
- RNA_def_property_ui_text(prop, "Global Scene", "Force the current Scene to be displayed in all Screens");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-
prop = RNA_def_property(srna, "show_large_cursors", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "curssize", 0);
RNA_def_property_ui_text(prop, "Large Cursors", "Use large mouse cursors when available");
@@ -3561,30 +3535,30 @@ static void rna_def_userdef_view(BlenderRNA *brna)
/* 3D transform widget */
prop = RNA_def_property(srna, "show_manipulator", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "tw_flag", V3D_USE_MANIPULATOR);
+ RNA_def_property_boolean_sdna(prop, NULL, "manipulator_flag", USER_MANIPULATOR_DRAW);
RNA_def_property_ui_text(prop, "Manipulator", "Use 3D transform manipulator");
RNA_def_property_update(prop, 0, "rna_userdef_show_manipulator_update");
+ prop = RNA_def_property(srna, "show_manipulator_navigate", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "manipulator_flag", USER_MANIPULATOR_DRAW_NAVIGATE);
+ RNA_def_property_ui_text(prop, "Navigate Manipulator", "Use 3D navigation manipulator");
+ RNA_def_property_update(prop, 0, "rna_userdef_show_manipulator_update");
+
+ /* TODO, expose once it's working. */
+#if 0
+ prop = RNA_def_property(srna, "show_manipulator_shaded", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_sdna(prop, NULL, "manipulator_flag", USER_MANIPULATOR_SHADED);
+ RNA_def_property_ui_text(prop, "Manipulator Shaded", "Use 3D transform manipulator");
+ RNA_def_property_update(prop, 0, "rna_userdef_update");
+#endif
+
prop = RNA_def_property(srna, "manipulator_size", PROP_INT, PROP_PIXEL);
- RNA_def_property_int_sdna(prop, NULL, "tw_size");
+ RNA_def_property_int_sdna(prop, NULL, "manipulator_size");
RNA_def_property_range(prop, 10, 200);
RNA_def_property_int_default(prop, 75);
RNA_def_property_ui_text(prop, "Manipulator Size", "Diameter of the manipulator");
RNA_def_property_update(prop, 0, "rna_userdef_update");
- prop = RNA_def_property(srna, "manipulator_handle_size", PROP_INT, PROP_PERCENTAGE);
- RNA_def_property_int_sdna(prop, NULL, "tw_handlesize");
- RNA_def_property_range(prop, 2, 40);
- RNA_def_property_int_default(prop, 25);
- RNA_def_property_ui_text(prop, "Manipulator Handle Size", "Size of manipulator handles as percentage of the radius");
- RNA_def_property_update(prop, 0, "rna_userdef_update");
-
- prop = RNA_def_property(srna, "manipulator_hotspot", PROP_INT, PROP_PIXEL);
- RNA_def_property_int_sdna(prop, NULL, "tw_hotspot");
- RNA_def_property_range(prop, 4, 40);
- RNA_def_property_int_default(prop, 14);
- RNA_def_property_ui_text(prop, "Manipulator Hotspot", "Distance around the handles to accept mouse clicks");
-
prop = RNA_def_property(srna, "object_origin_size", PROP_INT, PROP_PIXEL);
RNA_def_property_int_sdna(prop, NULL, "obcenter_dia");
RNA_def_property_range(prop, 4, 10);
@@ -3926,20 +3900,6 @@ static void rna_def_userdef_system(BlenderRNA *brna)
{0, NULL, 0, NULL, NULL}
};
- static const EnumPropertyItem draw_method_items[] = {
- {USER_DRAW_AUTOMATIC, "AUTOMATIC", 0, "Automatic", "Automatically set based on graphics card and driver"},
- {USER_DRAW_TRIPLE, "TRIPLE_BUFFER", 0, "Triple Buffer",
- "Use a third buffer for minimal redraws at the cost of more memory"},
- {USER_DRAW_OVERLAP, "OVERLAP", 0, "Overlap",
- "Redraw all overlapping regions, minimal memory usage but more redraws"},
- {USER_DRAW_OVERLAP_FLIP, "OVERLAP_FLIP", 0, "Overlap Flip",
- "Redraw all overlapping regions, minimal memory usage but more redraws "
- "(for graphics drivers that do flipping)"},
- {USER_DRAW_FULL, "FULL", 0, "Full",
- "Do a full redraw each time, slow, only use for reference or when everything else fails"},
- {0, NULL, 0, NULL, NULL}
- };
-
static const EnumPropertyItem color_picker_types[] = {
{USER_CP_CIRCLE_HSV, "CIRCLE_HSV", 0, "Circle (HSV)", "A circular Hue/Saturation color wheel, with Value slider"},
{USER_CP_CIRCLE_HSL, "CIRCLE_HSL", 0, "Circle (HSL)", "A circular Hue/Saturation color wheel, with Lightness slider"},
@@ -3985,20 +3945,27 @@ static void rna_def_userdef_system(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "International Fonts", "Use international fonts");
RNA_def_property_update(prop, NC_WINDOW, "rna_userdef_language_update");
+ prop = RNA_def_property(srna, "ui_scale", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_float_sdna(prop, NULL, "dpi_fac");
+ RNA_def_property_ui_text(prop, "UI Scale",
+ "Size multiplier to use when drawing custom user interface elements, so that "
+ "they are scaled correctly on screens with different DPI. This value is based "
+ "on operating system DPI settings and Blender display scale");
+
+ prop = RNA_def_property(srna, "ui_line_width", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_float_sdna(prop, NULL, "pixelsize");
+ RNA_def_property_ui_text(prop, "UI Line Width",
+ "Suggested line thickness and point size in pixels, for add-ons drawing custom "
+ "user interface elements, based on operating system settings and Blender UI scale");
+
prop = RNA_def_property(srna, "dpi", PROP_INT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "DPI",
- "DPI for add-ons to use when drawing custom user interface elements, controlled by "
- "operating system settings and Blender UI scale, with a reference value of 72 DPI "
- "(note that since this value includes a user defined scale, it is not always the "
- "actual monitor DPI)");
prop = RNA_def_property(srna, "pixel_size", PROP_FLOAT, PROP_NONE);
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
RNA_def_property_float_sdna(prop, NULL, "pixelsize");
- RNA_def_property_ui_text(prop, "Pixel Size",
- "Suggested line thickness and point size in pixels, for add-ons drawing custom user "
- "interface elements, controlled by operating system settings and Blender UI scale");
prop = RNA_def_property(srna, "font_path_ui", PROP_STRING, PROP_FILEPATH);
RNA_def_property_string_sdna(prop, NULL, "font_path_ui");
@@ -4112,13 +4079,6 @@ static void rna_def_userdef_system(BlenderRNA *brna)
RNA_def_property_range(prop, 0.0f, 1.0f);
RNA_def_property_ui_text(prop, "Clip Alpha", "Clip alpha below this threshold in the 3D textured view");
RNA_def_property_update(prop, 0, "rna_userdef_update");
-
- prop = RNA_def_property(srna, "use_mipmaps", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_negative_sdna(prop, NULL, "gameflags", USER_DISABLE_MIPMAP);
- RNA_def_property_ui_text(prop, "Mipmaps",
- "Scale textures for the 3D View (looks nicer but uses more memory and slows image "
- "reloading)");
- RNA_def_property_update(prop, 0, "rna_userdef_mipmap_update");
prop = RNA_def_property(srna, "use_16bit_textures", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "use_16bit_textures", 1);
@@ -4164,12 +4124,6 @@ static void rna_def_userdef_system(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Texture Collection Rate",
"Number of seconds between each run of the GL texture garbage collector");
- prop = RNA_def_property(srna, "window_draw_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "wmdrawmethod");
- RNA_def_property_enum_items(prop, draw_method_items);
- RNA_def_property_ui_text(prop, "Window Draw Method", "Drawing method used by the window manager");
- RNA_def_property_update(prop, 0, "rna_userdef_dpi_update");
-
prop = RNA_def_property(srna, "audio_mixing_buffer", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "mixbufsize");
RNA_def_property_enum_items(prop, audio_mixing_samples_items);
@@ -4233,6 +4187,7 @@ static void rna_def_userdef_system(BlenderRNA *brna)
RNA_def_property_enum_items(prop, multi_sample_levels);
RNA_def_property_ui_text(prop, "MultiSample",
"Enable OpenGL multi-sampling, only for systems that support it, requires restart");
+ RNA_def_property_update(prop, 0, "rna_userdef_dpi_update");
prop = RNA_def_property(srna, "use_region_overlap", PROP_BOOLEAN, PROP_NONE);
RNA_def_property_boolean_sdna(prop, NULL, "uiflag2", USER_REGION_OVERLAP);
diff --git a/source/blender/makesrna/intern/rna_vfont.c b/source/blender/makesrna/intern/rna_vfont.c
index c743751649c..78d46d35246 100644
--- a/source/blender/makesrna/intern/rna_vfont.c
+++ b/source/blender/makesrna/intern/rna_vfont.c
@@ -38,9 +38,10 @@
#ifdef RNA_RUNTIME
#include "BKE_font.h"
-#include "BKE_depsgraph.h"
#include "DNA_object_types.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
/* matching fnction in rna_ID.c */
@@ -60,7 +61,7 @@ static void rna_VectorFont_reload_update(Main *UNUSED(bmain), Scene *UNUSED(scen
/* update */
WM_main_add_notifier(NC_GEOM | ND_DATA, NULL);
- DAG_id_tag_update(&vf->id, OB_RECALC_OB | OB_RECALC_DATA);
+ DEG_id_tag_update(&vf->id, OB_RECALC_OB | OB_RECALC_DATA);
}
#else
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index b71eca3d850..0fa7f53da9b 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -36,6 +36,8 @@
#include "BLT_translation.h"
+#include "BKE_workspace.h"
+
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -442,6 +444,11 @@ const EnumPropertyItem rna_enum_operator_return_items[] = {
{0, NULL, 0, NULL, NULL}
};
+const EnumPropertyItem rna_enum_operator_property_tags[] = {
+ {OP_PROP_TAG_ADVANCED, "ADVANCED", 0, "Advanced", "The property is advanced so UI is suggested to hide it"},
+ {0, NULL, 0, NULL, NULL}
+};
+
/* flag/enum */
const EnumPropertyItem rna_enum_wm_report_items[] = {
{RPT_DEBUG, "DEBUG", 0, "Debug", ""},
@@ -462,12 +469,23 @@ const EnumPropertyItem rna_enum_wm_report_items[] = {
#include "WM_api.h"
+#include "DNA_object_types.h"
+#include "DNA_workspace_types.h"
+
+#include "ED_screen.h"
+
#include "UI_interface.h"
+#include "BKE_global.h"
#include "BKE_idprop.h"
#include "MEM_guardedalloc.h"
+#ifdef WITH_PYTHON
+# include "BPY_extern.h"
+#endif
+
+
static wmOperator *rna_OperatorProperties_find_operator(PointerRNA *ptr)
{
wmWindowManager *wm = ptr->id.data;
@@ -611,6 +629,17 @@ static PointerRNA rna_PopupMenu_layout_get(PointerRNA *ptr)
return rptr;
}
+static PointerRNA rna_PopoverMenu_layout_get(PointerRNA *ptr)
+{
+ struct uiPopover *pup = ptr->data;
+ uiLayout *layout = UI_popover_layout(pup);
+
+ PointerRNA rptr;
+ RNA_pointer_create(ptr->id.data, &RNA_UILayout, layout, &rptr);
+
+ return rptr;
+}
+
static PointerRNA rna_PieMenu_layout_get(PointerRNA *ptr)
{
struct uiPieMenu *pie = ptr->data;
@@ -622,42 +651,143 @@ static PointerRNA rna_PieMenu_layout_get(PointerRNA *ptr)
return rptr;
}
-static void rna_Window_screen_set(PointerRNA *ptr, PointerRNA value)
+static void rna_Window_scene_set(PointerRNA *ptr, PointerRNA value)
+{
+ wmWindow *win = ptr->data;
+
+ if (value.data == NULL) {
+ return;
+ }
+
+ win->new_scene = value.data;
+}
+
+static void rna_Window_scene_update(bContext *C, PointerRNA *ptr)
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindow *win = ptr->data;
+
+ /* exception: must use context so notifier gets to the right window */
+ if (win->new_scene) {
+#ifdef WITH_PYTHON
+ BPy_BEGIN_ALLOW_THREADS;
+#endif
+
+ WM_window_change_active_scene(bmain, C, win, win->new_scene);
+
+#ifdef WITH_PYTHON
+ BPy_END_ALLOW_THREADS;
+#endif
+
+ WM_event_add_notifier(C, NC_SCENE | ND_SCENEBROWSE, win->new_scene);
+
+ if (G.debug & G_DEBUG)
+ printf("scene set %p\n", win->new_scene);
+
+ win->new_scene = NULL;
+ }
+}
+
+static PointerRNA rna_Window_workspace_get(PointerRNA *ptr)
+{
+ wmWindow *win = ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_WorkSpace, BKE_workspace_active_get(win->workspace_hook));
+}
+
+static void rna_Window_workspace_set(PointerRNA *ptr, PointerRNA value)
{
wmWindow *win = (wmWindow *)ptr->data;
/* disallow ID-browsing away from temp screens */
- if (win->screen->temp) {
+ if (WM_window_is_temp_screen(win)) {
return;
}
+ if (value.data == NULL) {
+ return;
+ }
+
+ /* exception: can't set workspaces inside of area/region handlers */
+ win->workspace_hook->temp_workspace_store = value.data;
+}
+
+static void rna_Window_workspace_update(bContext *C, PointerRNA *ptr)
+{
+ wmWindow *win = ptr->data;
+ WorkSpace *new_workspace = win->workspace_hook->temp_workspace_store;
+
+ /* exception: can't set screens inside of area/region handlers,
+ * and must use context so notifier gets to the right window */
+ if (new_workspace) {
+ WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_SET, new_workspace);
+ win->workspace_hook->temp_workspace_store = NULL;
+ }
+}
- if (value.data == NULL)
+PointerRNA rna_Window_screen_get(PointerRNA *ptr)
+{
+ wmWindow *win = ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_Screen, BKE_workspace_active_screen_get(win->workspace_hook));
+}
+
+static void rna_Window_screen_set(PointerRNA *ptr, PointerRNA value)
+{
+ wmWindow *win = ptr->data;
+ WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+ WorkSpaceLayout *layout_new;
+ const bScreen *screen = BKE_workspace_active_screen_get(win->workspace_hook);
+
+ /* disallow ID-browsing away from temp screens */
+ if (screen->temp) {
+ return;
+ }
+ if (value.data == NULL) {
return;
+ }
/* exception: can't set screens inside of area/region handlers */
- win->newscreen = value.data;
+ layout_new = BKE_workspace_layout_find(workspace, value.data);
+ win->workspace_hook->temp_layout_store = layout_new;
}
static int rna_Window_screen_assign_poll(PointerRNA *UNUSED(ptr), PointerRNA value)
{
- bScreen *screen = (bScreen *)value.id.data;
-
+ bScreen *screen = value.id.data;
return !screen->temp;
}
-
-static void rna_Window_screen_update(bContext *C, PointerRNA *ptr)
+static void rna_workspace_screen_update(bContext *C, PointerRNA *ptr)
{
- wmWindow *win = (wmWindow *)ptr->data;
+ wmWindow *win = ptr->data;
+ WorkSpaceLayout *layout_new = win->workspace_hook->temp_layout_store;
/* exception: can't set screens inside of area/region handlers,
* and must use context so notifier gets to the right window */
- if (win->newscreen) {
- WM_event_add_notifier(C, NC_SCREEN | ND_SCREENBROWSE, win->newscreen);
- win->newscreen = NULL;
+ if (layout_new) {
+ WM_event_add_notifier(C, NC_SCREEN | ND_LAYOUTBROWSE, layout_new);
+ win->workspace_hook->temp_layout_store = NULL;
}
}
+static PointerRNA rna_Window_view_layer_get(PointerRNA *ptr)
+{
+ wmWindow *win = ptr->data;
+ Scene *scene;
+ ViewLayer *view_layer = WM_window_get_active_view_layer_ex(win, &scene);
+ PointerRNA scene_ptr;
+
+ RNA_id_pointer_create(&scene->id, &scene_ptr);
+ return rna_pointer_inherit_refine(&scene_ptr, &RNA_ViewLayer, view_layer);
+}
+
+static void rna_Window_view_layer_set(PointerRNA *ptr, PointerRNA value)
+{
+ wmWindow *win = ptr->data;
+ Scene *scene = WM_window_get_active_scene(win);
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+
+ BKE_workspace_view_layer_set(workspace, value.data, scene);
+}
+
static PointerRNA rna_KeyMapItem_properties_get(PointerRNA *ptr)
{
wmKeyMapItem *kmi = ptr->data;
@@ -1193,6 +1323,7 @@ static StructRNA *rna_Operator_register(
/* create a new operator type */
dummyot.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummyot.idname, &RNA_Operator);
RNA_def_struct_flag(dummyot.ext.srna, STRUCT_NO_IDPROPERTIES); /* operator properties are registered separately */
+ RNA_def_struct_property_tags(dummyot.ext.srna, rna_enum_operator_property_tags);
RNA_def_struct_translation_context(dummyot.ext.srna, dummyot.translation_context);
dummyot.ext.data = data;
dummyot.ext.call = call;
@@ -1552,6 +1683,7 @@ static void rna_def_operator(BlenderRNA *brna)
RNA_def_struct_ui_text(srna, "Operator Properties", "Input properties of an Operator");
RNA_def_struct_refine_func(srna, "rna_OperatorProperties_refine");
RNA_def_struct_idprops_func(srna, "rna_OperatorProperties_idprops");
+ RNA_def_struct_property_tags(srna, rna_enum_operator_property_tags);
RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES);
}
@@ -1857,6 +1989,11 @@ static void rna_def_popupmenu(BlenderRNA *brna)
rna_def_popup_menu_wrapper(brna, "UIPopupMenu", "uiPopupMenu", "rna_PopupMenu_layout_get");
}
+static void rna_def_popovermenu(BlenderRNA *brna)
+{
+ rna_def_popup_menu_wrapper(brna, "UIPopover", "uiPopover", "rna_PopoverMenu_layout_get");
+}
+
static void rna_def_piemenu(BlenderRNA *brna)
{
rna_def_popup_menu_wrapper(brna, "UIPieMenu", "uiPieMenu", "rna_PieMenu_layout_get");
@@ -1904,14 +2041,35 @@ static void rna_def_window(BlenderRNA *brna)
rna_def_window_stereo3d(brna);
- prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
+ prop = RNA_def_property(srna, "scene", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
+ RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_scene_set", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Scene", "Active scene to be edited in the window");
+ RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_Window_scene_update");
+
+ prop = RNA_def_property(srna, "workspace", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_struct_type(prop, "WorkSpace");
+ RNA_def_property_ui_text(prop, "Workspace", "Active workspace showing in the window");
+ RNA_def_property_pointer_funcs(prop, "rna_Window_workspace_get", "rna_Window_workspace_set", NULL, NULL);
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_Window_workspace_update");
+
+ prop = RNA_def_property(srna, "screen", PROP_POINTER, PROP_NONE);
RNA_def_property_struct_type(prop, "Screen");
- RNA_def_property_ui_text(prop, "Screen", "Active screen showing in the window");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_screen_set", NULL, "rna_Window_screen_assign_poll");
- RNA_def_property_flag(prop, PROP_CONTEXT_UPDATE);
- RNA_def_property_update(prop, 0, "rna_Window_screen_update");
+ RNA_def_property_ui_text(prop, "Screen", "Active workspace screen showing in the window");
+ RNA_def_property_pointer_funcs(prop, "rna_Window_screen_get", "rna_Window_screen_set", NULL,
+ "rna_Window_screen_assign_poll");
+ RNA_def_property_flag(prop, PROP_NEVER_NULL | PROP_EDITABLE | PROP_CONTEXT_UPDATE);
+ RNA_def_property_update(prop, 0, "rna_workspace_screen_update");
+
+ prop = RNA_def_property(srna, "view_layer", PROP_POINTER, PROP_NONE);
+ RNA_def_property_struct_type(prop, "ViewLayer");
+ RNA_def_property_pointer_funcs(prop, "rna_Window_view_layer_get", "rna_Window_view_layer_set", NULL, NULL);
+ RNA_def_property_ui_text(prop, "Active View Layer", "The active workspace view layer showing in the window");
+ RNA_def_property_flag(prop, PROP_EDITABLE | PROP_NEVER_NULL);
+ RNA_def_property_update(prop, NC_SCREEN | ND_LAYER, NULL);
prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
RNA_def_property_int_sdna(prop, NULL, "posx");
@@ -2086,6 +2244,10 @@ static void rna_def_keyconfig(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Name", "Name of the key map");
RNA_def_struct_name_property(srna, prop);
+ prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "owner_id");
+ RNA_def_property_ui_text(prop, "Owner", "Internal owner");
+
prop = RNA_def_property(srna, "space_type", PROP_ENUM, PROP_NONE);
RNA_def_property_enum_sdna(prop, NULL, "spaceid");
RNA_def_property_clear_flag(prop, PROP_EDITABLE);
@@ -2269,6 +2431,7 @@ void RNA_def_wm(BlenderRNA *brna)
rna_def_event(brna);
rna_def_timer(brna);
rna_def_popupmenu(brna);
+ rna_def_popovermenu(brna);
rna_def_piemenu(brna);
rna_def_window(brna);
rna_def_windowmanager(brna);
diff --git a/source/blender/makesrna/intern/rna_wm_api.c b/source/blender/makesrna/intern/rna_wm_api.c
index d2cd72b2f1e..ba955d65ac5 100644
--- a/source/blender/makesrna/intern/rna_wm_api.c
+++ b/source/blender/makesrna/intern/rna_wm_api.c
@@ -71,6 +71,8 @@ const EnumPropertyItem rna_enum_window_cursor_items[] = {
#include "UI_interface.h"
#include "BKE_context.h"
+#include "WM_types.h"
+
static wmKeyMap *rna_keymap_active(wmKeyMap *km, bContext *C)
{
wmWindowManager *wm = CTX_wm_manager(C);
@@ -115,6 +117,37 @@ static void rna_event_timer_remove(struct wmWindowManager *wm, wmTimer *timer)
WM_event_remove_timer(wm, timer->win, timer);
}
+
+static wmManipulatorGroupType *wm_manipulatorgrouptype_find_for_add_remove(ReportList *reports, const char *idname)
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, true);
+ if (wgt == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Manipulator group type '%s' not found!", idname);
+ return NULL;
+ }
+ if (wgt->flag & WM_MANIPULATORGROUPTYPE_PERSISTENT) {
+ BKE_reportf(reports, RPT_ERROR, "Manipulator group '%s' has 'PERSISTENT' option set!", idname);
+ return NULL;
+ }
+ return wgt;
+}
+
+static void rna_manipulator_group_type_add(ReportList *reports, const char *idname)
+{
+ wmManipulatorGroupType *wgt = wm_manipulatorgrouptype_find_for_add_remove(reports, idname);
+ if (wgt != NULL) {
+ WM_manipulator_group_type_add_ptr(wgt);
+ }
+}
+
+static void rna_manipulator_group_type_remove(Main *bmain, ReportList *reports, const char *idname)
+{
+ wmManipulatorGroupType *wgt = wm_manipulatorgrouptype_find_for_add_remove(reports, idname);
+ if (wgt != NULL) {
+ WM_manipulator_group_type_remove_ptr(bmain, wgt);
+ }
+}
+
/* placeholder data for final implementation of a true progressbar */
static struct wmStaticProgress {
float min;
@@ -315,6 +348,24 @@ static void rna_PopMenuEnd(bContext *C, PointerRNA *handle)
UI_popup_menu_end(C, handle->data);
}
+/* popover wrapper */
+static PointerRNA rna_PopoverBegin(bContext *C)
+{
+ PointerRNA r_ptr;
+ void *data;
+
+ data = (void *)UI_popover_begin(C);
+
+ RNA_pointer_create(NULL, &RNA_UIPopover, data, &r_ptr);
+
+ return r_ptr;
+}
+
+static void rna_PopoverEnd(bContext *C, PointerRNA *handle)
+{
+ UI_popover_end(C, handle->data);
+}
+
/* pie menu wrapper */
static PointerRNA rna_PieMenuBegin(bContext *C, const char *title, int icon, PointerRNA *event)
{
@@ -333,6 +384,18 @@ static void rna_PieMenuEnd(bContext *C, PointerRNA *handle)
UI_pie_menu_end(C, handle->data);
}
+static PointerRNA rna_WindoManager_operator_properties_last(const char *idname)
+{
+ wmOperatorType *ot = WM_operatortype_find(idname, true);
+
+ if (ot != NULL) {
+ PointerRNA ptr;
+ WM_operator_last_properties_ensure(ot, &ptr);
+ return ptr;
+ }
+ return PointerRNA_NULL;
+}
+
#else
#define WM_GEN_INVOKE_EVENT (1 << 0)
@@ -426,6 +489,18 @@ void RNA_api_wm(StructRNA *srna)
parm = RNA_def_pointer(func, "timer", "Timer", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ func = RNA_def_function(srna, "manipulator_group_type_add", "rna_manipulator_group_type_add");
+ RNA_def_function_ui_description(func, "Activate an existing widget group (when the persistent option isn't set)");
+ RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_REPORTS);
+ parm = RNA_def_string(func, "identifier", NULL, 0, "", "Manipulator group type name");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "manipulator_group_type_remove", "rna_manipulator_group_type_remove");
+ RNA_def_function_ui_description(func, "De-activate a widget group (when the persistent option isn't set)");
+ RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_MAIN | FUNC_USE_REPORTS);
+ parm = RNA_def_string(func, "identifier", NULL, 0, "", "Manipulator group type name");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
/* Progress bar interface */
func = RNA_def_function(srna, "progress_begin", "rna_progress_begin");
RNA_def_function_ui_description(func, "Start progress report");
@@ -496,6 +571,22 @@ void RNA_api_wm(StructRNA *srna)
parm = RNA_def_pointer(func, "menu", "UIPopupMenu", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
+
+ /* wrap UI_popover_panel_begin */
+ func = RNA_def_function(srna, "popover_begin__internal", "rna_PopoverBegin");
+ RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
+ /* return */
+ parm = RNA_def_pointer(func, "menu", "UIPopover", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
+ RNA_def_function_return(func, parm);
+
+ /* wrap UI_popover_panel_end */
+ func = RNA_def_function(srna, "popover_end__internal", "rna_PopoverEnd");
+ RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
+ parm = RNA_def_pointer(func, "menu", "UIPopover", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
+
+
/* wrap uiPieMenuBegin */
func = RNA_def_function(srna, "piemenu_begin__internal", "rna_PieMenuBegin");
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
@@ -515,6 +606,17 @@ void RNA_api_wm(StructRNA *srna)
RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_USE_CONTEXT);
parm = RNA_def_pointer(func, "menu", "UIPieMenu", "", "");
RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
+
+ /* access last operator options (optionally create). */
+ func = RNA_def_function(srna, "operator_properties_last", "rna_WindoManager_operator_properties_last");
+ RNA_def_function_flag(func, FUNC_NO_SELF);
+ parm = RNA_def_string(func, "operator", NULL, 0, "", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ /* return */
+ parm = RNA_def_pointer(func, "result", "OperatorProperties", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_RNAPTR);
+ RNA_def_function_return(func, parm);
+
}
void RNA_api_operator(StructRNA *srna)
diff --git a/source/blender/makesrna/intern/rna_wm_manipulator.c b/source/blender/makesrna/intern/rna_wm_manipulator.c
new file mode 100644
index 00000000000..bb40a12f5d5
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_wm_manipulator.c
@@ -0,0 +1,1325 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_wm_manipulator.c
+ * \ingroup RNA
+ */
+
+#include <stdlib.h>
+
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+#include "DNA_userdef_types.h"
+#include "DNA_view3d_types.h"
+#include "DNA_windowmanager_types.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_string_utils.h"
+
+#include "BLT_translation.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "rna_internal.h"
+
+#include "WM_types.h"
+
+#ifdef RNA_RUNTIME
+/* enum definitions */
+#endif /* RNA_RUNTIME */
+
+#ifdef RNA_RUNTIME
+
+#include <assert.h>
+
+#include "WM_api.h"
+
+#include "DNA_workspace_types.h"
+
+#include "ED_screen.h"
+
+#include "UI_interface.h"
+
+#include "BKE_global.h"
+#include "BKE_idprop.h"
+#include "BKE_workspace.h"
+
+#include "MEM_guardedalloc.h"
+
+#ifdef WITH_PYTHON
+# include "BPY_extern.h"
+#endif
+
+/* -------------------------------------------------------------------- */
+
+/** \name Manipulator API
+ * \{ */
+
+static void rna_manipulator_draw_cb(
+ const struct bContext *C, struct wmManipulator *mpr)
+{
+ extern FunctionRNA rna_Manipulator_draw_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "draw"); */
+ func = &rna_Manipulator_draw_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+ RNA_parameter_list_free(&list);
+}
+
+static void rna_manipulator_draw_select_cb(
+ const struct bContext *C, struct wmManipulator *mpr, int select_id)
+{
+ extern FunctionRNA rna_Manipulator_draw_select_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "draw_select"); */
+ func = &rna_Manipulator_draw_select_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ RNA_parameter_set_lookup(&list, "select_id", &select_id);
+ mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+ RNA_parameter_list_free(&list);
+}
+
+static int rna_manipulator_test_select_cb(
+ struct bContext *C, struct wmManipulator *mpr, const struct wmEvent *event)
+{
+ extern FunctionRNA rna_Manipulator_test_select_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "test_select"); */
+ func = &rna_Manipulator_test_select_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ RNA_parameter_set_lookup(&list, "event", &event);
+ mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+
+ void *ret;
+ RNA_parameter_get_lookup(&list, "intersect_id", &ret);
+ int intersect_id = *(int *)ret;
+
+ RNA_parameter_list_free(&list);
+ return intersect_id;
+}
+
+static int rna_manipulator_modal_cb(
+ struct bContext *C, struct wmManipulator *mpr, const struct wmEvent *event,
+ eWM_ManipulatorTweak tweak_flag)
+{
+ extern FunctionRNA rna_Manipulator_modal_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ const int tweak_flag_int = tweak_flag;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "modal"); */
+ func = &rna_Manipulator_modal_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ RNA_parameter_set_lookup(&list, "event", &event);
+ RNA_parameter_set_lookup(&list, "tweak", &tweak_flag_int);
+ mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+
+ void *ret;
+ RNA_parameter_get_lookup(&list, "result", &ret);
+ int ret_enum = *(int *)ret;
+
+ RNA_parameter_list_free(&list);
+ return ret_enum;
+}
+
+static void rna_manipulator_setup_cb(
+ struct wmManipulator *mpr)
+{
+ extern FunctionRNA rna_Manipulator_setup_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "setup"); */
+ func = &rna_Manipulator_setup_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ mgroup->type->ext.call((bContext *)NULL, &mpr_ptr, func, &list);
+ RNA_parameter_list_free(&list);
+}
+
+
+static int rna_manipulator_invoke_cb(
+ struct bContext *C, struct wmManipulator *mpr, const struct wmEvent *event)
+{
+ extern FunctionRNA rna_Manipulator_invoke_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "invoke"); */
+ func = &rna_Manipulator_invoke_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ RNA_parameter_set_lookup(&list, "event", &event);
+ mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+
+ void *ret;
+ RNA_parameter_get_lookup(&list, "result", &ret);
+ int ret_enum = *(int *)ret;
+
+ RNA_parameter_list_free(&list);
+ return ret_enum;
+}
+
+static void rna_manipulator_exit_cb(
+ struct bContext *C, struct wmManipulator *mpr, bool cancel)
+{
+ extern FunctionRNA rna_Manipulator_exit_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "exit"); */
+ func = &rna_Manipulator_exit_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ {
+ int cancel_i = cancel;
+ RNA_parameter_set_lookup(&list, "cancel", &cancel_i);
+ }
+ mgroup->type->ext.call((bContext *)C, &mpr_ptr, func, &list);
+ RNA_parameter_list_free(&list);
+}
+
+static void rna_manipulator_select_refresh_cb(
+ struct wmManipulator *mpr)
+{
+ extern FunctionRNA rna_Manipulator_select_refresh_func;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ PointerRNA mpr_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ RNA_pointer_create(NULL, mpr->type->ext.srna, mpr, &mpr_ptr);
+ /* RNA_struct_find_function(&mpr_ptr, "select_refresh"); */
+ func = &rna_Manipulator_select_refresh_func;
+ RNA_parameter_list_create(&list, &mpr_ptr, func);
+ mgroup->type->ext.call((bContext *)NULL, &mpr_ptr, func, &list);
+ RNA_parameter_list_free(&list);
+}
+
+/* just to work around 'const char *' warning and to ensure this is a python op */
+static void rna_Manipulator_bl_idname_set(PointerRNA *ptr, const char *value)
+{
+ wmManipulator *data = ptr->data;
+ char *str = (char *)data->type->idname;
+ if (!str[0]) {
+ BLI_strncpy(str, value, MAX_NAME); /* utf8 already ensured */
+ }
+ else {
+ assert(!"setting the bl_idname on a non-builtin operator");
+ }
+}
+
+static wmManipulator *rna_ManipulatorProperties_find_operator(PointerRNA *ptr)
+{
+#if 0
+ wmWindowManager *wm = ptr->id.data;
+#endif
+
+ /* We could try workaruond this lookup, but not trivial. */
+ for (bScreen *screen = G.main->screen.first; screen; screen = screen->id.next) {
+ IDProperty *properties = ptr->data;
+ for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->manipulator_map) {
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ for (wmManipulatorGroup *mgroup = WM_manipulatormap_group_list(mmap)->first;
+ mgroup;
+ mgroup = mgroup->next)
+ {
+ for (wmManipulator *mpr = mgroup->manipulators.first; mpr; mpr = mpr->next) {
+ if (mpr->properties == properties) {
+ return mpr;
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ return NULL;
+}
+
+static StructRNA *rna_ManipulatorProperties_refine(PointerRNA *ptr)
+{
+ wmManipulator *mpr = rna_ManipulatorProperties_find_operator(ptr);
+
+ if (mpr)
+ return mpr->type->srna;
+ else
+ return ptr->type;
+}
+
+static IDProperty *rna_ManipulatorProperties_idprops(PointerRNA *ptr, bool create)
+{
+ if (create && !ptr->data) {
+ IDPropertyTemplate val = {0};
+ ptr->data = IDP_New(IDP_GROUP, &val, "RNA_ManipulatorProperties group");
+ }
+
+ return ptr->data;
+}
+
+static PointerRNA rna_Manipulator_properties_get(PointerRNA *ptr)
+{
+ wmManipulator *mpr = ptr->data;
+ return rna_pointer_inherit_refine(ptr, mpr->type->srna, mpr->properties);
+}
+
+/* wmManipulator.float */
+#define RNA_MANIPULATOR_GENERIC_FLOAT_RW_DEF(func_id, member_id) \
+static float rna_Manipulator_##func_id##_get(PointerRNA *ptr) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ return mpr->member_id; \
+} \
+static void rna_Manipulator_##func_id##_set(PointerRNA *ptr, float value) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ mpr->member_id = value; \
+}
+#define RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_INDEX_RW_DEF(func_id, member_id, index) \
+static float rna_Manipulator_##func_id##_get(PointerRNA *ptr) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ return mpr->member_id[index]; \
+} \
+static void rna_Manipulator_##func_id##_set(PointerRNA *ptr, float value) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ mpr->member_id[index] = value; \
+}
+/* wmManipulator.float[len] */
+#define RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_RW_DEF(func_id, member_id, len) \
+static void rna_Manipulator_##func_id##_get(PointerRNA *ptr, float value[len]) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ memcpy(value, mpr->member_id, sizeof(float[len])); \
+} \
+static void rna_Manipulator_##func_id##_set(PointerRNA *ptr, const float value[len]) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ memcpy(mpr->member_id, value, sizeof(float[len])); \
+}
+
+/* wmManipulator.flag */
+#define RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(func_id, member_id, flag_value) \
+static int rna_Manipulator_##func_id##_get(PointerRNA *ptr) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ return (mpr->member_id & flag_value) != 0; \
+} \
+static void rna_Manipulator_##func_id##_set(PointerRNA *ptr, int value) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ SET_FLAG_FROM_TEST(mpr->member_id, value, flag_value); \
+}
+
+/* wmManipulator.flag (negative) */
+#define RNA_MANIPULATOR_GENERIC_FLAG_NEG_RW_DEF(func_id, member_id, flag_value) \
+static int rna_Manipulator_##func_id##_get(PointerRNA *ptr) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ return (mpr->member_id & flag_value) == 0; \
+} \
+static void rna_Manipulator_##func_id##_set(PointerRNA *ptr, int value) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ SET_FLAG_FROM_TEST(mpr->member_id, !value, flag_value); \
+}
+
+#define RNA_MANIPULATOR_FLAG_RO_DEF(func_id, member_id, flag_value) \
+static int rna_Manipulator_##func_id##_get(PointerRNA *ptr) \
+{ \
+ wmManipulator *mpr = ptr->data; \
+ return (mpr->member_id & flag_value) != 0; \
+}
+
+RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_RW_DEF(color, color, 3);
+RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_RW_DEF(color_hi, color_hi, 3);
+
+RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_INDEX_RW_DEF(alpha, color, 3);
+RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_INDEX_RW_DEF(alpha_hi, color_hi, 3);
+
+RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_RW_DEF(matrix_space, matrix_space, 16);
+RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_RW_DEF(matrix_basis, matrix_basis, 16);
+RNA_MANIPULATOR_GENERIC_FLOAT_ARRAY_RW_DEF(matrix_offset, matrix_offset, 16);
+
+static void rna_Manipulator_matrix_world_get(PointerRNA *ptr, float value[16])
+{
+ wmManipulator *mpr = ptr->data;
+ WM_manipulator_calc_matrix_final(mpr, (float (*)[4])value);
+}
+
+RNA_MANIPULATOR_GENERIC_FLOAT_RW_DEF(scale_basis, scale_basis);
+RNA_MANIPULATOR_GENERIC_FLOAT_RW_DEF(line_width, line_width);
+
+RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_draw_hover, flag, WM_MANIPULATOR_DRAW_HOVER);
+RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_draw_modal, flag, WM_MANIPULATOR_DRAW_MODAL);
+RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_draw_value, flag, WM_MANIPULATOR_DRAW_VALUE);
+RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_draw_offset_scale, flag, WM_MANIPULATOR_DRAW_OFFSET_SCALE);
+RNA_MANIPULATOR_GENERIC_FLAG_NEG_RW_DEF(flag_use_draw_scale, flag, WM_MANIPULATOR_DRAW_OFFSET_SCALE);
+RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_hide, flag, WM_MANIPULATOR_HIDDEN);
+RNA_MANIPULATOR_GENERIC_FLAG_RW_DEF(flag_use_grab_cursor, flag, WM_MANIPULATOR_GRAB_CURSOR);
+
+/* wmManipulator.state */
+RNA_MANIPULATOR_FLAG_RO_DEF(state_is_highlight, state, WM_MANIPULATOR_STATE_HIGHLIGHT);
+RNA_MANIPULATOR_FLAG_RO_DEF(state_is_modal, state, WM_MANIPULATOR_STATE_MODAL);
+RNA_MANIPULATOR_FLAG_RO_DEF(state_select, state, WM_MANIPULATOR_STATE_SELECT);
+
+static void rna_Manipulator_state_select_set(struct PointerRNA *ptr, int value)
+{
+ wmManipulator *mpr = ptr->data;
+ wmManipulatorGroup *mgroup = mpr->parent_mgroup;
+ WM_manipulator_select_set(mgroup->parent_mmap, mpr, value);
+}
+
+static PointerRNA rna_Manipulator_group_get(PointerRNA *ptr)
+{
+ wmManipulator *mpr = ptr->data;
+ return rna_pointer_inherit_refine(ptr, &RNA_ManipulatorGroup, mpr->parent_mgroup);
+}
+
+#ifdef WITH_PYTHON
+
+static void rna_Manipulator_unregister(struct Main *bmain, StructRNA *type);
+void BPY_RNA_manipulator_wrapper(wmManipulatorType *wgt, void *userdata);
+
+static StructRNA *rna_Manipulator_register(
+ Main *bmain, ReportList *reports, void *data, const char *identifier,
+ StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+{
+ struct {
+ char idname[MAX_NAME];
+ } temp_buffers;
+
+ wmManipulatorType dummywt = {NULL};
+ wmManipulator dummymnp = {NULL};
+ PointerRNA mnp_ptr;
+
+ /* Two sets of functions. */
+ int have_function[8];
+
+ /* setup dummy manipulator & manipulator type to store static properties in */
+ dummymnp.type = &dummywt;
+ dummywt.idname = temp_buffers.idname;
+ RNA_pointer_create(NULL, &RNA_Manipulator, &dummymnp, &mnp_ptr);
+
+ /* Clear so we can detect if it's left unset. */
+ temp_buffers.idname[0] = '\0';
+
+ /* validate the python class */
+ if (validate(&mnp_ptr, data, have_function) != 0)
+ return NULL;
+
+ if (strlen(identifier) >= sizeof(temp_buffers.idname)) {
+ BKE_reportf(reports, RPT_ERROR, "Registering manipulator class: '%s' is too long, maximum length is %d",
+ identifier, (int)sizeof(temp_buffers.idname));
+ return NULL;
+ }
+
+ /* check if we have registered this manipulator type before, and remove it */
+ {
+ const wmManipulatorType *wt = WM_manipulatortype_find(dummywt.idname, true);
+ if (wt && wt->ext.srna) {
+ rna_Manipulator_unregister(bmain, wt->ext.srna);
+ }
+ }
+ if (!RNA_struct_available_or_report(reports, dummywt.idname)) {
+ return NULL;
+ }
+
+ { /* allocate the idname */
+ /* For multiple strings see ManipulatorGroup. */
+ dummywt.idname = BLI_strdup(temp_buffers.idname);
+ }
+
+ /* create a new manipulator type */
+ dummywt.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummywt.idname, &RNA_Manipulator);
+ /* manipulator properties are registered separately */
+ RNA_def_struct_flag(dummywt.ext.srna, STRUCT_NO_IDPROPERTIES);
+ dummywt.ext.data = data;
+ dummywt.ext.call = call;
+ dummywt.ext.free = free;
+
+ {
+ int i = 0;
+ dummywt.draw = (have_function[i++]) ? rna_manipulator_draw_cb : NULL;
+ dummywt.draw_select = (have_function[i++]) ? rna_manipulator_draw_select_cb : NULL;
+ dummywt.test_select = (have_function[i++]) ? rna_manipulator_test_select_cb : NULL;
+ dummywt.modal = (have_function[i++]) ? rna_manipulator_modal_cb : NULL;
+// dummywt.property_update = (have_function[i++]) ? rna_manipulator_property_update : NULL;
+// dummywt.position_get = (have_function[i++]) ? rna_manipulator_position_get : NULL;
+ dummywt.setup = (have_function[i++]) ? rna_manipulator_setup_cb : NULL;
+ dummywt.invoke = (have_function[i++]) ? rna_manipulator_invoke_cb : NULL;
+ dummywt.exit = (have_function[i++]) ? rna_manipulator_exit_cb : NULL;
+ dummywt.select_refresh = (have_function[i++]) ? rna_manipulator_select_refresh_cb : NULL;
+
+ BLI_assert(i == ARRAY_SIZE(have_function));
+ }
+
+ WM_manipulatortype_append_ptr(BPY_RNA_manipulator_wrapper, (void *)&dummywt);
+
+ /* update while blender is running */
+ WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
+
+ return dummywt.ext.srna;
+}
+
+static void rna_Manipulator_unregister(struct Main *bmain, StructRNA *type)
+{
+ wmManipulatorType *wt = RNA_struct_blender_type_get(type);
+
+ if (!wt)
+ return;
+
+ RNA_struct_free_extension(type, &wt->ext);
+ RNA_struct_free(&BLENDER_RNA, type);
+
+ WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
+
+ WM_manipulatortype_remove_ptr(NULL, bmain, wt);
+}
+
+static void **rna_Manipulator_instance(PointerRNA *ptr)
+{
+ wmManipulator *mpr = ptr->data;
+ return &mpr->py_instance;
+}
+
+#endif /* WITH_PYTHON */
+
+
+static StructRNA *rna_Manipulator_refine(PointerRNA *mnp_ptr)
+{
+ wmManipulator *mpr = mnp_ptr->data;
+ return (mpr->type && mpr->type->ext.srna) ? mpr->type->ext.srna : &RNA_Manipulator;
+}
+
+/** \} */
+
+/** \name Manipulator Group API
+ * \{ */
+
+static wmManipulator *rna_ManipulatorGroup_manipulator_new(
+ wmManipulatorGroup *mgroup, ReportList *reports, const char *idname)
+{
+ const wmManipulatorType *wt = WM_manipulatortype_find(idname, true);
+ if (wt == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "ManipulatorType '%s' not known", idname);
+ return NULL;
+ }
+ wmManipulator *mpr = WM_manipulator_new_ptr(wt, mgroup, NULL);
+ return mpr;
+}
+
+static void rna_ManipulatorGroup_manipulator_remove(
+ wmManipulatorGroup *mgroup, bContext *C, wmManipulator *mpr)
+{
+ WM_manipulator_unlink(&mgroup->manipulators, mgroup->parent_mmap, mpr, C);
+}
+
+static void rna_ManipulatorGroup_manipulator_clear(
+ wmManipulatorGroup *mgroup, bContext *C)
+{
+ while (mgroup->manipulators.first) {
+ WM_manipulator_unlink(&mgroup->manipulators, mgroup->parent_mmap, mgroup->manipulators.first, C);
+ }
+}
+
+static void rna_ManipulatorGroup_name_get(PointerRNA *ptr, char *value)
+{
+ wmManipulatorGroup *mgroup = ptr->data;
+ strcpy(value, mgroup->type->name);
+}
+
+static int rna_ManipulatorGroup_name_length(PointerRNA *ptr)
+{
+ wmManipulatorGroup *mgroup = ptr->data;
+ return strlen(mgroup->type->name);
+}
+
+/* just to work around 'const char *' warning and to ensure this is a python op */
+static void rna_ManipulatorGroup_bl_idname_set(PointerRNA *ptr, const char *value)
+{
+ wmManipulatorGroup *data = ptr->data;
+ char *str = (char *)data->type->idname;
+ if (!str[0])
+ BLI_strncpy(str, value, MAX_NAME); /* utf8 already ensured */
+ else
+ assert(!"setting the bl_idname on a non-builtin operator");
+}
+
+static void rna_ManipulatorGroup_bl_label_set(PointerRNA *ptr, const char *value)
+{
+ wmManipulatorGroup *data = ptr->data;
+ char *str = (char *)data->type->name;
+ if (!str[0])
+ BLI_strncpy(str, value, MAX_NAME); /* utf8 already ensured */
+ else
+ assert(!"setting the bl_label on a non-builtin operator");
+}
+
+static int rna_ManipulatorGroup_has_reports_get(PointerRNA *ptr)
+{
+ wmManipulatorGroup *mgroup = ptr->data;
+ return (mgroup->reports && mgroup->reports->list.first);
+}
+
+#ifdef WITH_PYTHON
+
+static bool rna_manipulatorgroup_poll_cb(const bContext *C, wmManipulatorGroupType *wgt)
+{
+
+ extern FunctionRNA rna_ManipulatorGroup_poll_func;
+
+ PointerRNA ptr;
+ ParameterList list;
+ FunctionRNA *func;
+ void *ret;
+ int visible;
+
+ RNA_pointer_create(NULL, wgt->ext.srna, NULL, &ptr); /* dummy */
+ func = &rna_ManipulatorGroup_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
+
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ wgt->ext.call((bContext *)C, &ptr, func, &list);
+
+ RNA_parameter_get_lookup(&list, "visible", &ret);
+ visible = *(int *)ret;
+
+ RNA_parameter_list_free(&list);
+
+ return visible;
+}
+
+static void rna_manipulatorgroup_setup_cb(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ extern FunctionRNA rna_ManipulatorGroup_setup_func;
+
+ PointerRNA mgroup_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+
+ RNA_pointer_create(NULL, mgroup->type->ext.srna, mgroup, &mgroup_ptr);
+ func = &rna_ManipulatorGroup_setup_func; /* RNA_struct_find_function(&wgroupr, "setup"); */
+
+ RNA_parameter_list_create(&list, &mgroup_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ mgroup->type->ext.call((bContext *)C, &mgroup_ptr, func, &list);
+
+ RNA_parameter_list_free(&list);
+}
+
+static wmKeyMap *rna_manipulatorgroup_setup_keymap_cb(const wmManipulatorGroupType *wgt, wmKeyConfig *config)
+{
+ extern FunctionRNA rna_ManipulatorGroup_setup_keymap_func;
+ void *ret;
+
+ PointerRNA ptr;
+ ParameterList list;
+ FunctionRNA *func;
+
+ RNA_pointer_create(NULL, wgt->ext.srna, NULL, &ptr); /* dummy */
+ func = &rna_ManipulatorGroup_setup_keymap_func; /* RNA_struct_find_function(&wgroupr, "setup_keymap"); */
+
+ RNA_parameter_list_create(&list, &ptr, func);
+ RNA_parameter_set_lookup(&list, "keyconfig", &config);
+ wgt->ext.call(NULL, &ptr, func, &list);
+
+ RNA_parameter_get_lookup(&list, "keymap", &ret);
+ wmKeyMap *keymap = *(wmKeyMap **)ret;
+
+ RNA_parameter_list_free(&list);
+
+ return keymap;
+}
+
+static void rna_manipulatorgroup_refresh_cb(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ extern FunctionRNA rna_ManipulatorGroup_refresh_func;
+
+ PointerRNA mgroup_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+
+ RNA_pointer_create(NULL, mgroup->type->ext.srna, mgroup, &mgroup_ptr);
+ func = &rna_ManipulatorGroup_refresh_func; /* RNA_struct_find_function(&wgroupr, "refresh"); */
+
+ RNA_parameter_list_create(&list, &mgroup_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ mgroup->type->ext.call((bContext *)C, &mgroup_ptr, func, &list);
+
+ RNA_parameter_list_free(&list);
+}
+
+static void rna_manipulatorgroup_draw_prepare_cb(const bContext *C, wmManipulatorGroup *mgroup)
+{
+ extern FunctionRNA rna_ManipulatorGroup_draw_prepare_func;
+
+ PointerRNA mgroup_ptr;
+ ParameterList list;
+ FunctionRNA *func;
+
+ RNA_pointer_create(NULL, mgroup->type->ext.srna, mgroup, &mgroup_ptr);
+ func = &rna_ManipulatorGroup_draw_prepare_func; /* RNA_struct_find_function(&wgroupr, "draw_prepare"); */
+
+ RNA_parameter_list_create(&list, &mgroup_ptr, func);
+ RNA_parameter_set_lookup(&list, "context", &C);
+ mgroup->type->ext.call((bContext *)C, &mgroup_ptr, func, &list);
+
+ RNA_parameter_list_free(&list);
+}
+
+void BPY_RNA_manipulatorgroup_wrapper(wmManipulatorGroupType *wgt, void *userdata);
+static void rna_ManipulatorGroup_unregister(struct Main *bmain, StructRNA *type);
+
+static StructRNA *rna_ManipulatorGroup_register(
+ Main *bmain, ReportList *reports, void *data, const char *identifier,
+ StructValidateFunc validate, StructCallbackFunc call, StructFreeFunc free)
+{
+ struct {
+ char name[MAX_NAME];
+ char idname[MAX_NAME];
+ } temp_buffers;
+
+ wmManipulatorGroupType dummywgt = {NULL};
+ wmManipulatorGroup dummywg = {NULL};
+ PointerRNA wgptr;
+
+ /* Two sets of functions. */
+ int have_function[5];
+
+ /* setup dummy manipulatorgroup & manipulatorgroup type to store static properties in */
+ dummywg.type = &dummywgt;
+ dummywgt.name = temp_buffers.name;
+ dummywgt.idname = temp_buffers.idname;
+
+ RNA_pointer_create(NULL, &RNA_ManipulatorGroup, &dummywg, &wgptr);
+
+ /* Clear so we can detect if it's left unset. */
+ temp_buffers.idname[0] = temp_buffers.name[0] = '\0';
+
+ /* validate the python class */
+ if (validate(&wgptr, data, have_function) != 0)
+ return NULL;
+
+ if (strlen(identifier) >= sizeof(temp_buffers.idname)) {
+ BKE_reportf(reports, RPT_ERROR, "Registering manipulatorgroup class: '%s' is too long, maximum length is %d",
+ identifier, (int)sizeof(temp_buffers.idname));
+ return NULL;
+ }
+
+ /* check if the area supports widgets */
+ const struct wmManipulatorMapType_Params wmap_params = {
+ .spaceid = dummywgt.mmap_params.spaceid,
+ .regionid = dummywgt.mmap_params.regionid,
+ };
+
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wmap_params);
+ if (mmap_type == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Area type does not support manipulators");
+ return NULL;
+ }
+
+ /* check if we have registered this manipulatorgroup type before, and remove it */
+ {
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(dummywgt.idname, true);
+ if (wgt && wgt->ext.srna) {
+ rna_ManipulatorGroup_unregister(bmain, wgt->ext.srna);
+ }
+ }
+ if (!RNA_struct_available_or_report(reports, dummywgt.idname)) {
+ return NULL;
+ }
+
+ { /* allocate the idname */
+ const char *strings[] = {
+ temp_buffers.idname,
+ temp_buffers.name,
+ };
+ char *strings_table[ARRAY_SIZE(strings)];
+ BLI_string_join_array_by_sep_char_with_tableN('\0', strings_table, strings, ARRAY_SIZE(strings));
+
+ dummywgt.idname = strings_table[0]; /* allocated string stored here */
+ dummywgt.name = strings_table[1];
+ BLI_assert(ARRAY_SIZE(strings) == 2);
+ }
+
+ /* create a new manipulatorgroup type */
+ dummywgt.ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, dummywgt.idname, &RNA_ManipulatorGroup);
+ RNA_def_struct_flag(dummywgt.ext.srna, STRUCT_NO_IDPROPERTIES); /* manipulatorgroup properties are registered separately */
+ dummywgt.ext.data = data;
+ dummywgt.ext.call = call;
+ dummywgt.ext.free = free;
+
+ /* We used to register widget group types like this, now we do it similar to
+ * operator types. Thus we should be able to do the same as operator types now. */
+ dummywgt.poll = (have_function[0]) ? rna_manipulatorgroup_poll_cb : NULL;
+ dummywgt.setup_keymap = (have_function[1]) ? rna_manipulatorgroup_setup_keymap_cb : NULL;
+ dummywgt.setup = (have_function[2]) ? rna_manipulatorgroup_setup_cb : NULL;
+ dummywgt.refresh = (have_function[3]) ? rna_manipulatorgroup_refresh_cb : NULL;
+ dummywgt.draw_prepare = (have_function[4]) ? rna_manipulatorgroup_draw_prepare_cb : NULL;
+
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_append_ptr(
+ BPY_RNA_manipulatorgroup_wrapper, (void *)&dummywgt);
+
+ {
+ const char *owner_id = RNA_struct_state_owner_get();
+ if (owner_id) {
+ BLI_strncpy(wgt->owner_id, owner_id, sizeof(wgt->owner_id));
+ }
+ }
+
+ if (wgt->flag & WM_MANIPULATORGROUPTYPE_PERSISTENT) {
+ WM_manipulator_group_type_add_ptr_ex(wgt, mmap_type);
+
+ /* update while blender is running */
+ WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
+ }
+
+ return dummywgt.ext.srna;
+}
+
+static void rna_ManipulatorGroup_unregister(struct Main *bmain, StructRNA *type)
+{
+ wmManipulatorGroupType *wgt = RNA_struct_blender_type_get(type);
+
+ if (!wgt)
+ return;
+
+ RNA_struct_free_extension(type, &wgt->ext);
+ RNA_struct_free(&BLENDER_RNA, type);
+
+ WM_main_add_notifier(NC_SCREEN | NA_EDITED, NULL);
+
+ WM_manipulator_group_type_remove_ptr(bmain, wgt);
+}
+
+static void **rna_ManipulatorGroup_instance(PointerRNA *ptr)
+{
+ wmManipulatorGroup *mgroup = ptr->data;
+ return &mgroup->py_instance;
+}
+
+#endif /* WITH_PYTHON */
+
+static StructRNA *rna_ManipulatorGroup_refine(PointerRNA *mgroup_ptr)
+{
+ wmManipulatorGroup *mgroup = mgroup_ptr->data;
+ return (mgroup->type && mgroup->type->ext.srna) ? mgroup->type->ext.srna : &RNA_ManipulatorGroup;
+}
+
+static void rna_ManipulatorGroup_manipulators_begin(CollectionPropertyIterator *iter, PointerRNA *mgroup_ptr)
+{
+ wmManipulatorGroup *mgroup = mgroup_ptr->data;
+ rna_iterator_listbase_begin(iter, &mgroup->manipulators, NULL);
+}
+
+/** \} */
+
+
+#else /* RNA_RUNTIME */
+
+
+/* ManipulatorGroup.manipulators */
+static void rna_def_manipulators(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "Manipulators");
+ srna = RNA_def_struct(brna, "Manipulators", NULL);
+ RNA_def_struct_sdna(srna, "wmManipulatorGroup");
+ RNA_def_struct_ui_text(srna, "Manipulators", "Collection of manipulators");
+
+ func = RNA_def_function(srna, "new", "rna_ManipulatorGroup_manipulator_new");
+ RNA_def_function_ui_description(func, "Add manipulator");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_string(func, "type", "Type", 0, "", "Manipulator identifier"); /* optional */
+ parm = RNA_def_pointer(func, "manipulator", "Manipulator", "", "New manipulator");
+ RNA_def_function_return(func, parm);
+
+ func = RNA_def_function(srna, "remove", "rna_ManipulatorGroup_manipulator_remove");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ RNA_def_function_ui_description(func, "Delete manipulator");
+ parm = RNA_def_pointer(func, "manipulator", "Manipulator", "", "New manipulator");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+
+ func = RNA_def_function(srna, "clear", "rna_ManipulatorGroup_manipulator_clear");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ RNA_def_function_ui_description(func, "Delete all manipulators");
+}
+
+
+static void rna_def_manipulator(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "Manipulator");
+ srna = RNA_def_struct(brna, "Manipulator", NULL);
+ RNA_def_struct_sdna(srna, "wmManipulator");
+ RNA_def_struct_ui_text(srna, "Manipulator", "Collection of manipulators");
+ RNA_def_struct_refine_func(srna, "rna_Manipulator_refine");
+
+#ifdef WITH_PYTHON
+ RNA_def_struct_register_funcs(
+ srna,
+ "rna_Manipulator_register",
+ "rna_Manipulator_unregister",
+ "rna_Manipulator_instance");
+#endif
+ RNA_def_struct_translation_context(srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
+
+ prop = RNA_def_property(srna, "properties", PROP_POINTER, PROP_NONE);
+ RNA_def_property_flag(prop, PROP_NEVER_NULL);
+ RNA_def_property_struct_type(prop, "ManipulatorProperties");
+ RNA_def_property_ui_text(prop, "Properties", "");
+ RNA_def_property_pointer_funcs(prop, "rna_Manipulator_properties_get", NULL, NULL, NULL);
+
+ /* -------------------------------------------------------------------- */
+ /* Registerable Variables */
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+
+ prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->idname");
+ RNA_def_property_string_maxlength(prop, MAX_NAME);
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_Manipulator_bl_idname_set");
+ /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ RNA_def_property_flag(prop, PROP_REGISTER);
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+
+ /* wmManipulator.draw */
+ func = RNA_def_function(srna, "draw", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
+ /* wmManipulator.draw_select */
+ func = RNA_def_function(srna, "draw_select", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_int(func, "select_id", 0, 0, INT_MAX, "", "", 0, INT_MAX);
+
+ /* wmManipulator.test_select */
+ func = RNA_def_function(srna, "test_select", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_pointer(func, "event", "Event", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_int(func, "intersect_id", 0, 0, INT_MAX, "", "", 0, INT_MAX);
+ RNA_def_function_return(func, parm);
+
+ /* wmManipulator.handler */
+ static EnumPropertyItem tweak_actions[] = {
+ {WM_MANIPULATOR_TWEAK_PRECISE, "PRECISE", 0, "Precise", ""},
+ {WM_MANIPULATOR_TWEAK_SNAP, "SNAP", 0, "Snap", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ func = RNA_def_function(srna, "modal", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_pointer(func, "event", "Event", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ /* TODO, shuold be a enum-flag */
+ parm = RNA_def_enum_flag(func, "tweak", tweak_actions, 0, "Tweak", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ parm = RNA_def_enum_flag(func, "result", rna_enum_operator_return_items, OPERATOR_CANCELLED, "result", "");
+ RNA_def_function_return(func, parm);
+ /* wmManipulator.property_update */
+ /* TODO */
+
+ /* wmManipulator.setup */
+ func = RNA_def_function(srna, "setup", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+
+ /* wmManipulator.invoke */
+ func = RNA_def_function(srna, "invoke", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_pointer(func, "event", "Event", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_enum_flag(func, "result", rna_enum_operator_return_items, OPERATOR_CANCELLED, "result", "");
+ RNA_def_function_return(func, parm);
+
+ /* wmManipulator.exit */
+ func = RNA_def_function(srna, "exit", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ parm = RNA_def_boolean(func, "cancel", 0, "Cancel, otherwise confirm", "");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+
+ /* wmManipulator.cursor_get */
+ /* TODO */
+
+ /* wmManipulator.select_refresh */
+ func = RNA_def_function(srna, "select_refresh", NULL);
+ RNA_def_function_ui_description(func, "");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL | FUNC_ALLOW_WRITE);
+
+
+ /* -------------------------------------------------------------------- */
+ /* Instance Variables */
+
+ prop = RNA_def_property(srna, "group", PROP_POINTER, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_struct_type(prop, "ManipulatorGroup");
+ RNA_def_property_pointer_funcs(prop, "rna_Manipulator_group_get", NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "", "Manipulator group this manipulator is a member of");
+
+ /* Color & Alpha */
+ prop = RNA_def_property(srna, "color", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_color_get", "rna_Manipulator_color_set", NULL);
+
+ prop = RNA_def_property(srna, "alpha", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Alpha", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_alpha_get", "rna_Manipulator_alpha_set", NULL);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ /* Color & Alpha (highlight) */
+ prop = RNA_def_property(srna, "color_highlight", PROP_FLOAT, PROP_COLOR);
+ RNA_def_property_array(prop, 3);
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_color_hi_get", "rna_Manipulator_color_hi_set", NULL);
+
+ prop = RNA_def_property(srna, "alpha_highlight", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Alpha", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_alpha_hi_get", "rna_Manipulator_alpha_hi_set", NULL);
+ RNA_def_property_range(prop, 0.0f, 1.0f);
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ prop = RNA_def_property(srna, "matrix_space", PROP_FLOAT, PROP_MATRIX);
+ RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
+ RNA_def_property_ui_text(prop, "Space Matrix", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_matrix_space_get", "rna_Manipulator_matrix_space_set", NULL);
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ prop = RNA_def_property(srna, "matrix_basis", PROP_FLOAT, PROP_MATRIX);
+ RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
+ RNA_def_property_ui_text(prop, "Basis Matrix", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_matrix_basis_get", "rna_Manipulator_matrix_basis_set", NULL);
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ prop = RNA_def_property(srna, "matrix_offset", PROP_FLOAT, PROP_MATRIX);
+ RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
+ RNA_def_property_ui_text(prop, "Offset Matrix", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_matrix_offset_get", "rna_Manipulator_matrix_offset_set", NULL);
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ prop = RNA_def_property(srna, "matrix_world", PROP_FLOAT, PROP_MATRIX);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_multi_array(prop, 2, rna_matrix_dimsize_4x4);
+ RNA_def_property_ui_text(prop, "Final World Matrix", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_matrix_world_get", NULL, NULL);
+
+ prop = RNA_def_property(srna, "scale_basis", PROP_FLOAT, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Scale Basis", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_scale_basis_get", "rna_Manipulator_scale_basis_set", NULL);
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ prop = RNA_def_property(srna, "line_width", PROP_FLOAT, PROP_PIXEL);
+ RNA_def_property_ui_text(prop, "Line Width", "");
+ RNA_def_property_float_funcs(prop, "rna_Manipulator_line_width_get", "rna_Manipulator_line_width_set", NULL);
+ RNA_def_property_range(prop, 0.0f, FLT_MAX);
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ /* wmManipulator.flag */
+ /* WM_MANIPULATOR_HIDDEN */
+ prop = RNA_def_property(srna, "hide", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(
+ prop, "rna_Manipulator_flag_hide_get", "rna_Manipulator_flag_hide_set");
+ RNA_def_property_ui_text(prop, "Hide", "");
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+ /* WM_MANIPULATOR_GRAB_CURSOR */
+ prop = RNA_def_property(srna, "use_grab_cursor", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(
+ prop, "rna_Manipulator_flag_use_grab_cursor_get", "rna_Manipulator_flag_use_grab_cursor_set");
+ RNA_def_property_ui_text(prop, "Grab Cursor", "");
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ /* WM_MANIPULATOR_DRAW_HOVER */
+ prop = RNA_def_property(srna, "use_draw_hover", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(
+ prop, "rna_Manipulator_flag_use_draw_hover_get", "rna_Manipulator_flag_use_draw_hover_set");
+ RNA_def_property_ui_text(prop, "Draw Hover", "");
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+ /* WM_MANIPULATOR_DRAW_MODAL */
+ prop = RNA_def_property(srna, "use_draw_modal", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(
+ prop, "rna_Manipulator_flag_use_draw_modal_get", "rna_Manipulator_flag_use_draw_modal_set");
+ RNA_def_property_ui_text(prop, "Draw Active", "Draw while dragging");
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+ /* WM_MANIPULATOR_DRAW_VALUE */
+ prop = RNA_def_property(srna, "use_draw_value", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(
+ prop, "rna_Manipulator_flag_use_draw_value_get", "rna_Manipulator_flag_use_draw_value_set");
+ RNA_def_property_ui_text(prop, "Draw Value", "Show an indicator for the current value while dragging");
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+ /* WM_MANIPULATOR_DRAW_OFFSET_SCALE */
+ prop = RNA_def_property(srna, "use_draw_offset_scale", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(
+ prop, "rna_Manipulator_flag_use_draw_offset_scale_get", "rna_Manipulator_flag_use_draw_offset_scale_set");
+ RNA_def_property_ui_text(prop, "Scale Offset", "Scale the offset matrix (use to apply screen-space offset)");
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+ /* WM_MANIPULATOR_DRAW_NO_SCALE (negated) */
+ prop = RNA_def_property(srna, "use_draw_scale", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(
+ prop, "rna_Manipulator_flag_use_draw_scale_get", "rna_Manipulator_flag_use_draw_scale_set");
+ RNA_def_property_ui_text(prop, "Scale", "Use scale when calculating the matrix");
+ RNA_def_property_update(prop, NC_SCREEN | NA_EDITED, NULL);
+
+ /* wmManipulator.state (readonly) */
+ /* WM_MANIPULATOR_STATE_HIGHLIGHT */
+ prop = RNA_def_property(srna, "is_highlight", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_Manipulator_state_is_highlight_get", NULL);
+ RNA_def_property_ui_text(prop, "Highlight", "");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ /* WM_MANIPULATOR_STATE_MODAL */
+ prop = RNA_def_property(srna, "is_modal", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_Manipulator_state_is_modal_get", NULL);
+ RNA_def_property_ui_text(prop, "Highlight", "");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ /* WM_MANIPULATOR_STATE_SELECT */
+ /* (note that setting is involved, needs to handle array) */
+ prop = RNA_def_property(srna, "select", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_boolean_funcs(prop, "rna_Manipulator_state_select_get", "rna_Manipulator_state_select_set");
+ RNA_def_property_ui_text(prop, "Select", "");
+
+ RNA_api_manipulator(srna);
+
+ srna = RNA_def_struct(brna, "ManipulatorProperties", NULL);
+ RNA_def_struct_ui_text(srna, "Manipulator Properties", "Input properties of an Manipulator");
+ RNA_def_struct_refine_func(srna, "rna_ManipulatorProperties_refine");
+ RNA_def_struct_idprops_func(srna, "rna_ManipulatorProperties_idprops");
+ RNA_def_struct_flag(srna, STRUCT_NO_DATABLOCK_IDPROPERTIES);
+}
+
+static void rna_def_manipulatorgroup(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ srna = RNA_def_struct(brna, "ManipulatorGroup", NULL);
+ RNA_def_struct_ui_text(srna, "ManipulatorGroup", "Storage of an operator being executed, or registered after execution");
+ RNA_def_struct_sdna(srna, "wmManipulatorGroup");
+ RNA_def_struct_refine_func(srna, "rna_ManipulatorGroup_refine");
+#ifdef WITH_PYTHON
+ RNA_def_struct_register_funcs(
+ srna,
+ "rna_ManipulatorGroup_register",
+ "rna_ManipulatorGroup_unregister",
+ "rna_ManipulatorGroup_instance");
+#endif
+ RNA_def_struct_translation_context(srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
+
+ /* -------------------------------------------------------------------- */
+ /* Registration */
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+
+ prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->idname");
+ RNA_def_property_string_maxlength(prop, MAX_NAME);
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ManipulatorGroup_bl_idname_set");
+ RNA_def_property_flag(prop, PROP_REGISTER);
+ RNA_def_struct_name_property(srna, prop);
+
+ prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->name");
+ RNA_def_property_string_maxlength(prop, MAX_NAME); /* else it uses the pointer size! */
+ RNA_def_property_string_funcs(prop, NULL, NULL, "rna_ManipulatorGroup_bl_label_set");
+ /* RNA_def_property_clear_flag(prop, PROP_EDITABLE); */
+ RNA_def_property_flag(prop, PROP_REGISTER);
+
+ prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "type->mmap_params.spaceid");
+ RNA_def_property_enum_items(prop, rna_enum_space_type_items);
+ RNA_def_property_flag(prop, PROP_REGISTER);
+ RNA_def_property_ui_text(prop, "Space type", "The space where the panel is going to be used in");
+
+ prop = RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "type->mmap_params.regionid");
+ RNA_def_property_enum_items(prop, rna_enum_region_type_items);
+ RNA_def_property_flag(prop, PROP_REGISTER);
+ RNA_def_property_ui_text(prop, "Region Type", "The region where the panel is going to be used in");
+
+ prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "type->owner_id");
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL);
+
+ /* bl_options */
+ static EnumPropertyItem manipulatorgroup_flag_items[] = {
+ {WM_MANIPULATORGROUPTYPE_3D, "3D", 0, "3D",
+ "Use in 3D viewport"},
+ {WM_MANIPULATORGROUPTYPE_SCALE, "SCALE", 0, "Scale",
+ "Scale to respect zoom (otherwise zoom independent draw size)"},
+ {WM_MANIPULATORGROUPTYPE_DEPTH_3D, "DEPTH_3D", 0, "Depth 3D",
+ "Supports culled depth by other objects in the view"},
+ {WM_MANIPULATORGROUPTYPE_SELECT, "SELECT", 0, "Select",
+ "Supports selection"},
+ {WM_MANIPULATORGROUPTYPE_PERSISTENT, "PERSISTENT", 0, "Persistent",
+ ""},
+ {WM_MANIPULATORGROUPTYPE_DRAW_MODAL_ALL, "SHOW_MODAL_ALL", 0, "Show Modal All",
+ "Show all while interacting"},
+ {0, NULL, 0, NULL, NULL}
+ };
+ prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "type->flag");
+ RNA_def_property_enum_items(prop, manipulatorgroup_flag_items);
+ RNA_def_property_flag(prop, PROP_REGISTER_OPTIONAL | PROP_ENUM_FLAG);
+ RNA_def_property_ui_text(prop, "Options", "Options for this operator type");
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+
+
+ /* Functions */
+
+ /* poll */
+ func = RNA_def_function(srna, "poll", NULL);
+ RNA_def_function_ui_description(func, "Test if the manipulator group can be called or not");
+ RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL);
+ RNA_def_function_return(func, RNA_def_boolean(func, "visible", 1, "", ""));
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
+ /* setup_keymap */
+ func = RNA_def_function(srna, "setup_keymap", NULL);
+ RNA_def_function_ui_description(
+ func,
+ "Initialize keymaps for this manipulator group, use fallback keymap when not present");
+ RNA_def_function_flag(func, FUNC_NO_SELF | FUNC_REGISTER_OPTIONAL);
+ parm = RNA_def_pointer(func, "keyconfig", "KeyConfig", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ /* return */
+ parm = RNA_def_pointer(func, "keymap", "KeyMap", "", "");
+ RNA_def_property_flag(parm, PROP_NEVER_NULL);
+ RNA_def_function_return(func, parm);
+
+ /* setup */
+ func = RNA_def_function(srna, "setup", NULL);
+ RNA_def_function_ui_description(func, "Create manipulators function for the manipulator group");
+ RNA_def_function_flag(func, FUNC_REGISTER);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
+ /* refresh */
+ func = RNA_def_function(srna, "refresh", NULL);
+ RNA_def_function_ui_description(func, "Refresh data (called on common state changes such as selection)");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
+ func = RNA_def_function(srna, "draw_prepare", NULL);
+ RNA_def_function_ui_description(func, "Run before each redraw");
+ RNA_def_function_flag(func, FUNC_REGISTER_OPTIONAL);
+ parm = RNA_def_pointer(func, "context", "Context", "", "");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+
+ /* -------------------------------------------------------------------- */
+ /* Instance Variables */
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+ RNA_def_property_string_funcs(prop, "rna_ManipulatorGroup_name_get", "rna_ManipulatorGroup_name_length", NULL);
+ RNA_def_property_ui_text(prop, "Name", "");
+
+ prop = RNA_def_property(srna, "has_reports", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE); /* this is 'virtual' property */
+ RNA_def_property_boolean_funcs(prop, "rna_ManipulatorGroup_has_reports_get", NULL);
+ RNA_def_property_ui_text(prop, "Has Reports",
+ "ManipulatorGroup has a set of reports (warnings and errors) from last execution");
+
+
+ RNA_define_verify_sdna(0); /* not in sdna */
+
+ prop = RNA_def_property(srna, "manipulators", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "manipulators", NULL);
+ RNA_def_property_struct_type(prop, "Manipulator");
+ RNA_def_property_collection_funcs(
+ prop, "rna_ManipulatorGroup_manipulators_begin", "rna_iterator_listbase_next",
+ "rna_iterator_listbase_end", "rna_iterator_listbase_get",
+ NULL, NULL, NULL, NULL);
+
+ RNA_def_property_ui_text(prop, "Manipulators", "List of manipulators in the Manipulator Map");
+ rna_def_manipulator(brna, prop);
+ rna_def_manipulators(brna, prop);
+
+ RNA_define_verify_sdna(1); /* not in sdna */
+
+ RNA_api_manipulatorgroup(srna);
+}
+
+void RNA_def_wm_manipulator(BlenderRNA *brna)
+{
+ rna_def_manipulatorgroup(brna);
+}
+
+#endif /* RNA_RUNTIME */
diff --git a/source/blender/makesrna/intern/rna_wm_manipulator_api.c b/source/blender/makesrna/intern/rna_wm_manipulator_api.c
new file mode 100644
index 00000000000..c948f84e087
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_wm_manipulator_api.c
@@ -0,0 +1,290 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_wm_manipulator_api.c
+ * \ingroup RNA
+ */
+
+
+#include <stdlib.h>
+#include <stdio.h>
+
+#include "BLI_utildefines.h"
+
+#include "BKE_report.h"
+
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "DNA_windowmanager_types.h"
+
+#include "WM_api.h"
+
+#include "rna_internal.h" /* own include */
+
+#ifdef RNA_RUNTIME
+
+#include "UI_interface.h"
+#include "BKE_context.h"
+
+#include "ED_manipulator_library.h"
+
+static void rna_manipulator_draw_preset_box(
+ wmManipulator *mpr, float matrix[16], int select_id)
+{
+ ED_manipulator_draw_preset_box(mpr, (float (*)[4])matrix, select_id);
+}
+
+static void rna_manipulator_draw_preset_arrow(
+ wmManipulator *mpr, float matrix[16], int axis, int select_id)
+{
+ ED_manipulator_draw_preset_arrow(mpr, (float (*)[4])matrix, axis, select_id);
+}
+
+static void rna_manipulator_draw_preset_circle(
+ wmManipulator *mpr, float matrix[16], int axis, int select_id)
+{
+ ED_manipulator_draw_preset_circle(mpr, (float (*)[4])matrix, axis, select_id);
+}
+
+static void rna_manipulator_draw_preset_facemap(
+ wmManipulator *mpr, struct bContext *C, struct Object *ob, int facemap, int select_id)
+{
+ struct Scene *scene = CTX_data_scene(C);
+ ED_manipulator_draw_preset_facemap(C, mpr, scene, ob, facemap, select_id);
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Manipulator Property Define
+ * \{ */
+
+static void rna_manipulator_target_set_prop(
+ wmManipulator *mpr, ReportList *reports, const char *target_propname,
+ PointerRNA *ptr, const char *propname, int index)
+{
+ const wmManipulatorPropertyType *mpr_prop_type =
+ WM_manipulatortype_target_property_find(mpr->type, target_propname);
+ if (mpr_prop_type == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Manipulator target property '%s.%s' not found",
+ mpr->type->idname, target_propname);
+ return;
+ }
+
+ PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
+ if (prop == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Property '%s.%s' not found",
+ RNA_struct_identifier(ptr->type), target_propname);
+ return;
+ }
+
+ if (mpr_prop_type->data_type != RNA_property_type(prop)) {
+ const int manipulator_type_index = RNA_enum_from_value(rna_enum_property_type_items, mpr_prop_type->data_type);
+ const int prop_type_index = RNA_enum_from_value(rna_enum_property_type_items, RNA_property_type(prop));
+ BLI_assert((manipulator_type_index != -1) && (prop_type_index == -1));
+
+ BKE_reportf(reports, RPT_ERROR, "Manipulator target '%s.%s' expects '%s', '%s.%s' is '%s'",
+ mpr->type->idname, target_propname,
+ rna_enum_property_type_items[manipulator_type_index].identifier,
+ RNA_struct_identifier(ptr->type), propname,
+ rna_enum_property_type_items[prop_type_index].identifier);
+ return;
+ }
+
+ if (RNA_property_array_check(prop)) {
+ if (index == -1) {
+ const int prop_array_length = RNA_property_array_length(ptr, prop);
+ if (mpr_prop_type->array_length != prop_array_length) {
+ BKE_reportf(reports, RPT_ERROR,
+ "Manipulator target property '%s.%s' expects an array of length %d, found %d",
+ mpr->type->idname, target_propname,
+ mpr_prop_type->array_length,
+ prop_array_length);
+ return;
+ }
+ }
+ }
+ else {
+ if (mpr_prop_type->array_length != 1) {
+ BKE_reportf(reports, RPT_ERROR,
+ "Manipulator target property '%s.%s' expects an array of length %d",
+ mpr->type->idname, target_propname,
+ mpr_prop_type->array_length);
+ return;
+ }
+ }
+
+ if (index >= mpr_prop_type->array_length) {
+ BKE_reportf(reports, RPT_ERROR, "Manipulator target property '%s.%s', index %d must be below %d",
+ mpr->type->idname, target_propname, index, mpr_prop_type->array_length);
+ return;
+ }
+
+ WM_manipulator_target_property_def_rna_ptr(mpr, mpr_prop_type, ptr, prop, index);
+}
+
+static PointerRNA rna_manipulator_target_set_operator(
+ wmManipulator *mpr, ReportList *reports, const char *opname, int part_index)
+{
+ wmOperatorType *ot;
+
+ ot = WM_operatortype_find(opname, 0); /* print error next */
+ if (!ot || !ot->srna) {
+ BKE_reportf(reports, RPT_ERROR, "%s '%s'", ot ? "unknown operator" : "operator missing srna", opname);
+ return PointerRNA_NULL;
+ }
+
+ /* For the return value to be usable, we need 'PointerRNA.data' to be set. */
+ IDProperty *properties;
+ {
+ IDPropertyTemplate val = {0};
+ properties = IDP_New(IDP_GROUP, &val, "wmManipulatorProperties");
+ }
+
+ return *WM_manipulator_operator_set(mpr, part_index, ot, properties);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Manipulator Property Access
+ * \{ */
+
+static int rna_manipulator_target_is_valid(
+ wmManipulator *mpr, ReportList *reports, const char *target_propname)
+{
+ wmManipulatorProperty *mpr_prop =
+ WM_manipulator_target_property_find(mpr, target_propname);
+ if (mpr_prop == NULL) {
+ BKE_reportf(reports, RPT_ERROR, "Manipulator target property '%s.%s' not found",
+ mpr->type->idname, target_propname);
+ return false;
+ }
+ return WM_manipulator_target_property_is_valid(mpr_prop);
+}
+
+/** \} */
+
+#else
+
+void RNA_api_manipulator(StructRNA *srna)
+{
+ /* Utility draw functions, since we don't expose new OpenGL drawing wrappers via Python yet.
+ * exactly how these should be exposed isn't totally clear.
+ * However it's probably good to have some high level API's for this anyway.
+ * Just note that this could be re-worked once tests are done.
+ */
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ /* -------------------------------------------------------------------- */
+ /* Primitive Shapes */
+
+ /* draw_preset_box */
+ func = RNA_def_function(srna, "draw_preset_box", "rna_manipulator_draw_preset_box");
+ RNA_def_function_ui_description(func, "Draw a box");
+ parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
+ RNA_def_property_ui_text(parm, "", "The matrix to transform");
+ RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX);
+
+ /* draw_preset_box */
+ func = RNA_def_function(srna, "draw_preset_arrow", "rna_manipulator_draw_preset_arrow");
+ RNA_def_function_ui_description(func, "Draw a box");
+ parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
+ RNA_def_property_ui_text(parm, "", "The matrix to transform");
+ RNA_def_enum(func, "axis", rna_enum_object_axis_items, 2, "", "Arrow Orientation");
+ RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX);
+
+ func = RNA_def_function(srna, "draw_preset_circle", "rna_manipulator_draw_preset_circle");
+ RNA_def_function_ui_description(func, "Draw a box");
+ parm = RNA_def_property(func, "matrix", PROP_FLOAT, PROP_MATRIX);
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_property_multi_array(parm, 2, rna_matrix_dimsize_4x4);
+ RNA_def_property_ui_text(parm, "", "The matrix to transform");
+ RNA_def_enum(func, "axis", rna_enum_object_axis_items, 2, "", "Arrow Orientation");
+ RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX);
+
+ /* -------------------------------------------------------------------- */
+ /* Other Shapes */
+
+ /* draw_preset_facemap */
+ func = RNA_def_function(srna, "draw_preset_facemap", "rna_manipulator_draw_preset_facemap");
+ RNA_def_function_ui_description(func, "Draw the face-map of a mesh object");
+ RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+ parm = RNA_def_pointer(func, "object", "Object", "", "Object");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED);
+ RNA_def_int(func, "facemap", 0, 0, INT_MAX, "Face map index", "", 0, INT_MAX);
+ RNA_def_int(func, "select_id", -1, -1, INT_MAX, "Zero when not selecting", "", -1, INT_MAX);
+
+
+ /* -------------------------------------------------------------------- */
+ /* Property API */
+
+ /* Define Properties */
+ /* note, 'target_set_handler' is defined in 'bpy_rna_manipulator.c' */
+ func = RNA_def_function(srna, "target_set_prop", "rna_manipulator_target_set_prop");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(func, "");
+ parm = RNA_def_string(func, "target", NULL, 0, "", "Target property");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ /* similar to UILayout.prop */
+ parm = RNA_def_pointer(func, "data", "AnyType", "", "Data from which to take property");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ parm = RNA_def_string(func, "property", NULL, 0, "", "Identifier of property in data");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_int(func, "index", -1, -1, INT_MAX, "", "", -1, INT_MAX); /* RNA_NO_INDEX == -1 */
+
+ func = RNA_def_function(srna, "target_set_operator", "rna_manipulator_target_set_operator");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(
+ func, "Operator to run when activating the manipulator "
+ "(overrides property targets)");
+ parm = RNA_def_string(func, "operator", NULL, 0, "", "Target operator");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_int(func, "index", 0, 0, 255, "Part index", "", 0, 255);
+
+ /* similar to UILayout.operator */
+ parm = RNA_def_pointer(func, "properties", "OperatorProperties", "", "Operator properties to fill in");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_function_return(func, parm);
+
+ /* Access Properties */
+ /* note, 'target_get', 'target_set' is defined in 'bpy_rna_manipulator.c' */
+ func = RNA_def_function(srna, "target_is_valid", "rna_manipulator_target_is_valid");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ parm = RNA_def_string(func, "property", NULL, 0, "", "Property identifier");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ RNA_def_function_ui_description(func, "");
+ parm = RNA_def_boolean(func, "result", 0, "", "");
+ RNA_def_function_return(func, parm);
+
+}
+
+
+void RNA_api_manipulatorgroup(StructRNA *UNUSED(srna))
+{
+ /* nothing yet */
+}
+
+#endif
diff --git a/source/blender/makesrna/intern/rna_workspace.c b/source/blender/makesrna/intern/rna_workspace.c
new file mode 100644
index 00000000000..b82ca145f5f
--- /dev/null
+++ b/source/blender/makesrna/intern/rna_workspace.c
@@ -0,0 +1,232 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/makesrna/intern/rna_workspace.c
+ * \ingroup RNA
+ */
+
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+#include "RNA_types.h"
+
+#include "BKE_workspace.h"
+
+#include "ED_render.h"
+
+#include "RE_engine.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "rna_internal.h"
+
+/* Allow accessing private members of DNA_workspace_types.h */
+#define DNA_PRIVATE_WORKSPACE_ALLOW
+#include "DNA_workspace_types.h"
+
+#ifdef RNA_RUNTIME
+
+#include "BLI_listbase.h"
+
+#include "BKE_global.h"
+
+#include "DNA_object_types.h"
+#include "DNA_screen_types.h"
+
+#include "RNA_access.h"
+
+static void rna_window_update_all(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *UNUSED(ptr))
+{
+ WM_main_add_notifier(NC_WINDOW, NULL);
+}
+
+void rna_workspace_screens_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
+{
+ WorkSpace *workspace = ptr->id.data;
+ rna_iterator_listbase_begin(iter, BKE_workspace_layouts_get(workspace), NULL);
+}
+
+static PointerRNA rna_workspace_screens_item_get(CollectionPropertyIterator *iter)
+{
+ WorkSpaceLayout *layout = rna_iterator_listbase_get(iter);
+ bScreen *screen = BKE_workspace_layout_screen_get(layout);
+
+ return rna_pointer_inherit_refine(&iter->parent, &RNA_Screen, screen);
+}
+
+/* workspace.owner_ids */
+
+static wmOwnerID *rna_WorkSpace_owner_ids_new(
+ WorkSpace *workspace, const char *name)
+{
+ wmOwnerID *owner_id = MEM_callocN(sizeof(*owner_id), __func__);
+ BLI_addtail(&workspace->owner_ids, owner_id);
+ BLI_strncpy(owner_id->name, name, sizeof(owner_id->name));
+ WM_main_add_notifier(NC_WINDOW, NULL);
+ return owner_id;
+}
+
+static void rna_WorkSpace_owner_ids_remove(
+ WorkSpace *workspace, ReportList *reports, PointerRNA *wstag_ptr)
+{
+ wmOwnerID *owner_id = wstag_ptr->data;
+ if (BLI_remlink_safe(&workspace->owner_ids, owner_id) == false) {
+ BKE_reportf(reports, RPT_ERROR,
+ "wmOwnerID '%s' not in workspace '%s'",
+ owner_id->name, workspace->id.name + 2);
+ return;
+ }
+
+ MEM_freeN(owner_id);
+ RNA_POINTER_INVALIDATE(wstag_ptr);
+
+ WM_main_add_notifier(NC_WINDOW, NULL);
+}
+
+static void rna_WorkSpace_owner_ids_clear(
+ WorkSpace *workspace)
+{
+ BLI_freelistN(&workspace->owner_ids);
+ WM_main_add_notifier(NC_OBJECT | ND_MODIFIER | NA_REMOVED, workspace);
+}
+
+#else /* RNA_RUNTIME */
+
+static void rna_def_workspace_owner(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "wmOwnerID", NULL);
+ RNA_def_struct_sdna(srna, "wmOwnerID");
+ RNA_def_struct_clear_flag(srna, STRUCT_UNDO);
+ RNA_def_struct_ui_text(srna, "Work Space UI Tag", "");
+
+ prop = RNA_def_property(srna, "name", PROP_STRING, PROP_NONE);
+ RNA_def_property_ui_text(prop, "Name", "");
+ RNA_def_struct_name_property(srna, prop);
+}
+
+static void rna_def_workspace_owner_ids(BlenderRNA *brna, PropertyRNA *cprop)
+{
+ StructRNA *srna;
+
+ FunctionRNA *func;
+ PropertyRNA *parm;
+
+ RNA_def_property_srna(cprop, "wmOwnerIDs");
+ srna = RNA_def_struct(brna, "wmOwnerIDs", NULL);
+ RNA_def_struct_sdna(srna, "WorkSpace");
+ RNA_def_struct_ui_text(srna, "WorkSpace UI Tags", "");
+
+ /* add owner_id */
+ func = RNA_def_function(srna, "new", "rna_WorkSpace_owner_ids_new");
+ RNA_def_function_ui_description(func, "Add ui tag");
+ parm = RNA_def_string(func, "name", "Name", 0, "", "New name for the tag");
+ RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
+ /* return type */
+ parm = RNA_def_pointer(func, "owner_id", "wmOwnerID", "", "");
+ RNA_def_function_return(func, parm);
+
+ /* remove owner_id */
+ func = RNA_def_function(srna, "remove", "rna_WorkSpace_owner_ids_remove");
+ RNA_def_function_flag(func, FUNC_USE_REPORTS);
+ RNA_def_function_ui_description(func, "Remove ui tag");
+ /* owner_id to remove */
+ parm = RNA_def_pointer(func, "owner_id", "wmOwnerID", "", "Tag to remove");
+ RNA_def_parameter_flags(parm, PROP_NEVER_NULL, PARM_REQUIRED | PARM_RNAPTR);
+ RNA_def_parameter_clear_flags(parm, PROP_THICK_WRAP, 0);
+
+ /* clear all modifiers */
+ func = RNA_def_function(srna, "clear", "rna_WorkSpace_owner_ids_clear");
+ RNA_def_function_ui_description(func, "Remove all tags");
+}
+
+static void rna_def_workspace(BlenderRNA *brna)
+{
+ StructRNA *srna;
+ PropertyRNA *prop;
+
+ srna = RNA_def_struct(brna, "WorkSpace", "ID");
+ RNA_def_struct_sdna(srna, "WorkSpace");
+ RNA_def_struct_ui_text(srna, "Workspace", "Workspace data-block, defining the working environment for the user");
+ /* TODO: real icon, just to show something */
+ RNA_def_struct_ui_icon(srna, ICON_SPLITSCREEN);
+
+ prop = RNA_def_property(srna, "screens", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_collection_sdna(prop, NULL, "layouts", NULL);
+ RNA_def_property_struct_type(prop, "Screen");
+ RNA_def_property_collection_funcs(prop, "rna_workspace_screens_begin", NULL, NULL,
+ "rna_workspace_screens_item_get", NULL, NULL, NULL, NULL);
+ RNA_def_property_ui_text(prop, "Screens", "Screen layouts of a workspace");
+
+ prop = RNA_def_property(srna, "tool_keymap", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "tool.keymap");
+ RNA_def_property_ui_text(prop, "Active Tool", "Currently active tool keymap");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "tool_manipulator_group", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "tool.manipulator_group");
+ RNA_def_property_ui_text(prop, "Active Tool", "Currently active tool manipulator");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "tool_data_block", PROP_STRING, PROP_NONE);
+ RNA_def_property_string_sdna(prop, NULL, "tool.data_block");
+ RNA_def_property_ui_text(prop, "Active Tool", "Currently active data-block");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "tool_index", PROP_INT, PROP_NONE);
+ RNA_def_property_int_sdna(prop, NULL, "tool.index");
+ RNA_def_property_ui_text(prop, "Active Tool Index", "Tool group index");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "tool_space_type", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_sdna(prop, NULL, "tool.spacetype");
+ RNA_def_property_enum_items(prop, rna_enum_space_type_items);
+ RNA_def_property_ui_text(prop, "Active Tool Space", "Tool space type");
+ RNA_def_property_clear_flag(prop, PROP_EDITABLE);
+
+ prop = RNA_def_property(srna, "owner_ids", PROP_COLLECTION, PROP_NONE);
+ RNA_def_property_struct_type(prop, "wmOwnerID");
+ RNA_def_property_ui_text(prop, "UI Tags", "");
+ rna_def_workspace_owner_ids(brna, prop);
+
+#if 0
+ prop = RNA_def_property(srna, "object_mode", PROP_ENUM, PROP_NONE);
+ RNA_def_property_enum_items(prop, rna_enum_object_mode_items);
+ RNA_def_property_ui_text(prop, "Mode", "Object interaction mode used in this window");
+#endif
+
+ /* Flags */
+ prop = RNA_def_property(srna, "use_filter_by_owner", PROP_BOOLEAN, PROP_NONE);
+ RNA_def_property_clear_flag(prop, PROP_ANIMATABLE);
+ RNA_def_property_boolean_sdna(prop, NULL, "flags", WORKSPACE_USE_FILTER_BY_ORIGIN);
+ RNA_def_property_ui_text(prop, "Use UI Tags",
+ "Filter the UI by tags");
+ RNA_def_property_update(prop, 0, "rna_window_update_all");
+}
+
+void RNA_def_workspace(BlenderRNA *brna)
+{
+ rna_def_workspace_owner(brna);
+ rna_def_workspace(brna);
+}
+
+#endif /* RNA_RUNTIME */
diff --git a/source/blender/makesrna/intern/rna_world.c b/source/blender/makesrna/intern/rna_world.c
index 925bc52d06f..92fbbd61898 100644
--- a/source/blender/makesrna/intern/rna_world.c
+++ b/source/blender/makesrna/intern/rna_world.c
@@ -43,10 +43,12 @@
#include "MEM_guardedalloc.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_main.h"
#include "BKE_texture.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+
#include "ED_node.h"
#include "WM_api.h"
@@ -62,33 +64,11 @@ static PointerRNA rna_World_mist_get(PointerRNA *ptr)
return rna_pointer_inherit_refine(ptr, &RNA_WorldMistSettings, ptr->id.data);
}
-static void rna_World_mtex_begin(CollectionPropertyIterator *iter, PointerRNA *ptr)
-{
- World *wo = (World *)ptr->data;
- rna_iterator_array_begin(iter, (void *)wo->mtex, sizeof(MTex *), MAX_MTEX, 0, NULL);
-}
-
-static PointerRNA rna_World_active_texture_get(PointerRNA *ptr)
-{
- World *wo = (World *)ptr->data;
- Tex *tex;
-
- tex = give_current_world_texture(wo);
- return rna_pointer_inherit_refine(ptr, &RNA_Texture, tex);
-}
-
-static void rna_World_active_texture_set(PointerRNA *ptr, PointerRNA value)
-{
- World *wo = (World *)ptr->data;
-
- set_current_world_texture(wo, value.data);
-}
-
static void rna_World_update(Main *UNUSED(bmain), Scene *UNUSED(scene), PointerRNA *ptr)
{
World *wo = ptr->id.data;
- DAG_id_tag_update(&wo->id, 0);
+ DEG_id_tag_update(&wo->id, 0);
WM_main_add_notifier(NC_WORLD | ND_WORLD, wo);
}
@@ -97,7 +77,7 @@ static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
{
World *wo = ptr->id.data;
- DAG_id_tag_update(&wo->id, 0);
+ DEG_id_tag_update(&wo->id, 0);
WM_main_add_notifier(NC_WORLD | ND_WORLD_DRAW, wo);
}
#endif
@@ -106,7 +86,7 @@ static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
{
World *wo = ptr->id.data;
- DAG_id_tag_update(&wo->id, 0);
+ DEG_id_tag_update(&wo->id, 0);
WM_main_add_notifier(NC_WORLD | ND_WORLD_DRAW, wo);
WM_main_add_notifier(NC_OBJECT | ND_DRAW, NULL);
}
@@ -114,126 +94,24 @@ static void rna_World_draw_update(Main *UNUSED(bmain), Scene *UNUSED(scene), Poi
static void rna_World_use_nodes_update(bContext *C, PointerRNA *ptr)
{
World *wrld = (World *)ptr->data;
+ Main *bmain = CTX_data_main(C);
+ Scene *scene = CTX_data_scene(C);
if (wrld->use_nodes && wrld->nodetree == NULL)
ED_node_shader_default(C, &wrld->id);
-
- rna_World_update(CTX_data_main(C), CTX_data_scene(C), ptr);
+
+ DEG_relations_tag_update(bmain);
+ rna_World_update(bmain, scene, ptr);
+ rna_World_draw_update(bmain, scene, ptr);
}
#else
-static void rna_def_world_mtex(BlenderRNA *brna)
-{
- StructRNA *srna;
- PropertyRNA *prop;
-
- static const EnumPropertyItem texco_items[] = {
- {TEXCO_VIEW, "VIEW", 0, "View", "Use view vector for the texture coordinates"},
- {TEXCO_GLOB, "GLOBAL", 0, "Global", "Use global coordinates for the texture coordinates (interior mist)"},
- {TEXCO_ANGMAP, "ANGMAP", 0, "AngMap", "Use 360 degree angular coordinates, e.g. for spherical light probes"},
- {TEXCO_H_SPHEREMAP, "SPHERE", 0, "Sphere", "For 360 degree panorama sky, spherical mapped, only top half"},
- {TEXCO_EQUIRECTMAP, "EQUIRECT", 0, "Equirectangular", "For 360 degree panorama sky, equirectangular mapping"},
- {TEXCO_H_TUBEMAP, "TUBE", 0, "Tube", "For 360 degree panorama sky, cylindrical mapped, only top half"},
- {TEXCO_OBJECT, "OBJECT", 0, "Object", "Use linked object's coordinates for texture coordinates"},
- {0, NULL, 0, NULL, NULL}
- };
-
- srna = RNA_def_struct(brna, "WorldTextureSlot", "TextureSlot");
- RNA_def_struct_sdna(srna, "MTex");
- RNA_def_struct_ui_text(srna, "World Texture Slot", "Texture slot for textures in a World data-block");
-
- /* map to */
- prop = RNA_def_property(srna, "use_map_blend", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", WOMAP_BLEND);
- RNA_def_property_ui_text(prop, "Blend", "Affect the color progression of the background");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "use_map_horizon", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", WOMAP_HORIZ);
- RNA_def_property_ui_text(prop, "Horizon", "Affect the color of the horizon");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "use_map_zenith_up", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", WOMAP_ZENUP);
- RNA_def_property_ui_text(prop, "Zenith Up", "Affect the color of the zenith above");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "use_map_zenith_down", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mapto", WOMAP_ZENDOWN);
- RNA_def_property_ui_text(prop, "Zenith Down", "Affect the color of the zenith below");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "texture_coords", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "texco");
- RNA_def_property_enum_items(prop, texco_items);
- RNA_def_property_ui_text(prop, "Texture Coordinates",
- "Texture coordinates used to map the texture onto the background");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "object", PROP_POINTER, PROP_NONE);
- RNA_def_property_pointer_sdna(prop, NULL, "object");
- RNA_def_property_struct_type(prop, "Object");
- RNA_def_property_flag(prop, PROP_EDITABLE);
- RNA_def_property_ui_text(prop, "Object", "Object to use for mapping with Object texture coordinates");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "blend_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "blendfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Blend Factor", "Amount texture affects color progression of the background");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "horizon_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "colfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Horizon Factor", "Amount texture affects color of the horizon");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "zenith_up_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "zenupfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Zenith Up Factor", "Amount texture affects color of the zenith above");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "zenith_down_factor", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "zendownfac");
- RNA_def_property_ui_range(prop, 0, 1, 10, 3);
- RNA_def_property_ui_text(prop, "Zenith Down Factor", "Amount texture affects color of the zenith below");
- RNA_def_property_update(prop, 0, "rna_World_update");
-}
-
static void rna_def_lighting(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
- static const EnumPropertyItem blend_mode_items[] = {
- {WO_AOMUL, "MULTIPLY", 0, "Multiply", "Multiply direct lighting with ambient occlusion, darkening the result"},
- {WO_AOADD, "ADD", 0, "Add", "Add light and shadow"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_color_items[] = {
- {WO_AOPLAIN, "PLAIN", 0, "White", "Plain diffuse energy (white.)"},
- {WO_AOSKYCOL, "SKY_COLOR", 0, "Sky Color", "Use horizon and zenith color for diffuse energy"},
- {WO_AOSKYTEX, "SKY_TEXTURE", 0, "Sky Texture", "Does full Sky texture render for diffuse energy"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_sample_method_items[] = {
- {WO_AOSAMP_CONSTANT, "CONSTANT_JITTERED", 0, "Constant Jittered", "Fastest and gives the most noise"},
- {WO_AOSAMP_HALTON, "ADAPTIVE_QMC", 0, "Adaptive QMC", "Fast in high-contrast areas"},
- {WO_AOSAMP_HAMMERSLEY, "CONSTANT_QMC", 0, "Constant QMC", "Best quality"},
- {0, NULL, 0, NULL, NULL}
- };
-
- static const EnumPropertyItem prop_gather_method_items[] = {
- {WO_AOGATHER_RAYTRACE, "RAYTRACE", 0, "Raytrace", "Accurate, but slow when noise-free results are required"},
- {WO_AOGATHER_APPROX, "APPROXIMATE", 0, "Approximate", "Inaccurate, but faster and without noise"},
- {0, NULL, 0, NULL, NULL}
- };
-
srna = RNA_def_struct(brna, "WorldLighting", NULL);
RNA_def_struct_sdna(srna, "World");
RNA_def_struct_nested(brna, srna, "World");
@@ -253,135 +131,12 @@ static void rna_def_lighting(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Factor", "Factor for ambient occlusion blending");
RNA_def_property_update(prop, 0, "rna_World_update");
- prop = RNA_def_property(srna, "ao_blend_type", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "aomix");
- RNA_def_property_enum_items(prop, blend_mode_items);
- RNA_def_property_ui_text(prop, "Blend Mode", "Defines how AO mixes with material shading");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- /* environment lighting */
- prop = RNA_def_property(srna, "use_environment_light", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_ENV_LIGHT);
- RNA_def_property_ui_text(prop, "Use Environment Lighting", "Add light coming from the environment");
- RNA_def_property_update(prop, 0, "rna_World_draw_update");
-
- prop = RNA_def_property(srna, "environment_energy", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ao_env_energy");
- RNA_def_property_ui_range(prop, 0, FLT_MAX, 1, 3);
- RNA_def_property_ui_text(prop, "Environment Color", "Defines the strength of environment light");
- RNA_def_property_update(prop, 0, "rna_World_draw_update");
-
- prop = RNA_def_property(srna, "environment_color", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "aocolor");
- RNA_def_property_enum_items(prop, prop_color_items);
- RNA_def_property_ui_text(prop, "Environment Color", "Defines where the color of the environment light comes from");
- RNA_def_property_update(prop, 0, "rna_World_draw_update");
-
- /* indirect lighting */
- prop = RNA_def_property(srna, "use_indirect_light", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "mode", WO_INDIRECT_LIGHT);
- RNA_def_property_ui_text(prop, "Use Indirect Lighting", "Add indirect light bouncing of surrounding objects");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "indirect_factor", PROP_FLOAT, PROP_FACTOR);
- RNA_def_property_float_sdna(prop, NULL, "ao_indirect_energy");
- RNA_def_property_range(prop, 0, INT_MAX);
- RNA_def_property_ui_range(prop, 0, 1, 0.1, 2);
- RNA_def_property_ui_text(prop, "Indirect Factor", "Factor for how much surrounding objects contribute to light");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "indirect_bounces", PROP_INT, PROP_UNSIGNED);
- RNA_def_property_int_sdna(prop, NULL, "ao_indirect_bounces");
- RNA_def_property_range(prop, 1, SHRT_MAX);
- RNA_def_property_ui_text(prop, "Bounces", "Number of indirect diffuse light bounces");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- /* gathering parameters */
- prop = RNA_def_property(srna, "gather_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "ao_gather_method");
- RNA_def_property_enum_items(prop, prop_gather_method_items);
- RNA_def_property_ui_text(prop, "Gather Method", "");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "passes", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "ao_approx_passes");
- RNA_def_property_range(prop, 0, 10);
- RNA_def_property_ui_text(prop, "Passes", "Number of preprocessing passes to reduce over-occlusion");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
prop = RNA_def_property(srna, "distance", PROP_FLOAT, PROP_DISTANCE);
RNA_def_property_float_sdna(prop, NULL, "aodist");
RNA_def_property_ui_text(prop, "Distance",
"Length of rays, defines how far away other faces give occlusion effect");
RNA_def_property_update(prop, 0, "rna_World_update");
- prop = RNA_def_property(srna, "falloff_strength", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "aodistfac");
- RNA_def_property_ui_text(prop, "Strength",
- "Attenuation falloff strength, the higher, the less influence distant objects have");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "bias", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "aobias");
- RNA_def_property_range(prop, 0, 0.5);
- RNA_def_property_ui_text(prop, "Bias",
- "Bias (in radians) to prevent smoothed faces from showing banding "
- "(for Raytrace Constant Jittered)");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ao_adapt_thresh");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Threshold",
- "Samples below this threshold will be considered fully shadowed/unshadowed and skipped "
- "(for Raytrace Adaptive QMC)");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "adapt_to_speed", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ao_adapt_speed_fac");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_text(prop, "Adapt To Speed",
- "Use the speed vector pass to reduce AO samples in fast moving pixels - "
- "higher values result in more aggressive sample reduction "
- "(requires Vec pass enabled, for Raytrace Adaptive QMC)");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "error_threshold", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ao_approx_error");
- RNA_def_property_range(prop, 0.0001, 10);
- RNA_def_property_ui_text(prop, "Error Tolerance", "Low values are slower and higher quality");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "correction", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "ao_approx_correction");
- RNA_def_property_range(prop, 0, 1);
- RNA_def_property_ui_range(prop, 0, 1, 0.1, 2);
- RNA_def_property_ui_text(prop, "Correction", "Ad-hoc correction for over-occlusion due to the approximation");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "use_falloff", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "aomode", WO_AODIST);
- RNA_def_property_ui_text(prop, "Falloff", "Distance will be used to attenuate shadows");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "use_cache", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "aomode", WO_AOCACHE);
- RNA_def_property_ui_text(prop, "Pixel Cache",
- "Cache AO results in pixels and interpolate over neighboring pixels for speedup");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "samples", PROP_INT, PROP_NONE);
- RNA_def_property_int_sdna(prop, NULL, "aosamp");
- RNA_def_property_range(prop, 1, 128);
- RNA_def_property_ui_text(prop, "Samples",
- "Amount of ray samples. Higher values give smoother results and longer rendering times");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "sample_method", PROP_ENUM, PROP_NONE);
- RNA_def_property_enum_sdna(prop, NULL, "ao_samp_method");
- RNA_def_property_enum_items(prop, prop_sample_method_items);
- RNA_def_property_ui_text(prop, "Sample Method", "Method for generating shadow samples (for Raytrace)");
- RNA_def_property_update(prop, 0, "rna_World_update");
}
static void rna_def_world_mist(BlenderRNA *brna)
@@ -390,9 +145,9 @@ static void rna_def_world_mist(BlenderRNA *brna)
PropertyRNA *prop;
static const EnumPropertyItem falloff_items[] = {
- {0, "QUADRATIC", 0, "Quadratic", "Use quadratic progression"},
- {1, "LINEAR", 0, "Linear", "Use linear progression"},
- {2, "INVERSE_QUADRATIC", 0, "Inverse Quadratic", "Use inverse quadratic progression"},
+ {WO_MIST_QUADRATIC, "QUADRATIC", 0, "Quadratic", "Use quadratic progression"},
+ {WO_MIST_LINEAR, "LINEAR", 0, "Linear", "Use linear progression"},
+ {WO_MIST_INVERSE_QUADRATIC, "INVERSE_QUADRATIC", 0, "Inverse Quadratic", "Use inverse quadratic progression"},
{0, NULL, 0, NULL, NULL}
};
@@ -450,9 +205,6 @@ void RNA_def_world(BlenderRNA *brna)
RNA_def_struct_ui_icon(srna, ICON_WORLD_DATA);
rna_def_animdata_common(srna);
- rna_def_mtex_common(brna, srna, "rna_World_mtex_begin", "rna_World_active_texture_get",
- "rna_World_active_texture_set", NULL, "WorldTextureSlot", "WorldTextureSlots",
- "rna_World_update", "rna_World_update");
/* colors */
prop = RNA_def_property(srna, "horizon_color", PROP_FLOAT, PROP_COLOR);
@@ -463,47 +215,6 @@ void RNA_def_world(BlenderRNA *brna)
/* render-only uses this */
RNA_def_property_update(prop, 0, "rna_World_draw_update");
- prop = RNA_def_property(srna, "zenith_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "zenr");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Zenith Color", "Color at the zenith");
- RNA_def_property_update(prop, 0, "rna_World_draw_update");
-
- prop = RNA_def_property(srna, "ambient_color", PROP_FLOAT, PROP_COLOR);
- RNA_def_property_float_sdna(prop, NULL, "ambr");
- RNA_def_property_array(prop, 3);
- RNA_def_property_ui_text(prop, "Ambient Color", "Ambient color of the world");
- RNA_def_property_update(prop, 0, "rna_World_draw_update");
-
- /* exp, range */
- prop = RNA_def_property(srna, "exposure", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "exp");
- RNA_def_property_range(prop, 0.0, 1.0);
- RNA_def_property_ui_text(prop, "Exposure", "Amount of exponential color correction for light");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- prop = RNA_def_property(srna, "color_range", PROP_FLOAT, PROP_NONE);
- RNA_def_property_float_sdna(prop, NULL, "range");
- RNA_def_property_range(prop, 0.2, 5.0);
- RNA_def_property_ui_text(prop, "Range", "The color range that will be mapped to 0-1");
- RNA_def_property_update(prop, 0, "rna_World_update");
-
- /* sky type */
- prop = RNA_def_property(srna, "use_sky_blend", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "skytype", WO_SKYBLEND);
- RNA_def_property_ui_text(prop, "Blend Sky", "Render background with natural progression from horizon to zenith");
- RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update");
-
- prop = RNA_def_property(srna, "use_sky_paper", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "skytype", WO_SKYPAPER);
- RNA_def_property_ui_text(prop, "Paper Sky", "Flatten blend or texture coordinates");
- RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update");
-
- prop = RNA_def_property(srna, "use_sky_real", PROP_BOOLEAN, PROP_NONE);
- RNA_def_property_boolean_sdna(prop, NULL, "skytype", WO_SKYREAL);
- RNA_def_property_ui_text(prop, "Real Sky", "Render background with a real horizon, relative to the camera angle");
- RNA_def_property_update(prop, NC_WORLD | ND_WORLD_DRAW, "rna_World_update");
-
/* nested structs */
prop = RNA_def_property(srna, "light_settings", PROP_POINTER, PROP_NONE);
RNA_def_property_flag(prop, PROP_NEVER_NULL);
@@ -531,7 +242,6 @@ void RNA_def_world(BlenderRNA *brna)
rna_def_lighting(brna);
rna_def_world_mist(brna);
- rna_def_world_mtex(brna);
}
#endif
diff --git a/source/blender/modifiers/CMakeLists.txt b/source/blender/modifiers/CMakeLists.txt
index a70612447d3..397a3263e22 100644
--- a/source/blender/modifiers/CMakeLists.txt
+++ b/source/blender/modifiers/CMakeLists.txt
@@ -113,10 +113,6 @@ set(SRC
intern/MOD_weightvg_util.h
)
-if(WITH_LEGACY_DEPSGRAPH)
- add_definitions(-DWITH_LEGACY_DEPSGRAPH)
-endif()
-
if(WITH_ALEMBIC)
add_definitions(-DWITH_ALEMBIC)
list(APPEND INC
@@ -151,4 +147,7 @@ if(WITH_OPENSUBDIV)
add_definitions(-DWITH_OPENSUBDIV)
endif()
+# So we can have special tricks in modifier system.
+add_definitions(${GL_DEFINITIONS})
+
blender_add_lib(bf_modifiers "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/modifiers/intern/MOD_armature.c b/source/blender/modifiers/intern/MOD_armature.c
index 579854be725..6644e5383df 100644
--- a/source/blender/modifiers/intern/MOD_armature.c
+++ b/source/blender/modifiers/intern/MOD_armature.c
@@ -42,15 +42,17 @@
#include "BLI_utildefines.h"
#include "BLI_string.h"
-
-#include "BKE_cdderivedmesh.h"
+#include "BKE_editmesh.h"
#include "BKE_lattice.h"
+#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
-#include "MEM_guardedalloc.h"
+#include "bmesh.h"
+#include "bmesh_tools.h"
-#include "depsgraph_private.h"
+#include "MEM_guardedalloc.h"
#include "MOD_util.h"
@@ -99,18 +101,6 @@ static void foreachObjectLink(
walk(userData, ob, &amd->object, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- ArmatureModifierData *amd = (ArmatureModifierData *) md;
-
- if (amd->object) {
- DagNode *curNode = dag_get_node(ctx->forest, amd->object);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Armature Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
ArmatureModifierData *amd = (ArmatureModifierData *)md;
@@ -121,17 +111,16 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Armature Modifier");
}
-static void deformVerts(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
+ Mesh *mesh,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
ArmatureModifierData *amd = (ArmatureModifierData *) md;
modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
- armature_deform_verts(amd->object, ob, derivedData, vertexCos, NULL,
+ armature_deform_verts(amd->object, ctx->object, mesh, vertexCos, NULL,
numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name);
/* free cache */
@@ -142,17 +131,19 @@ static void deformVerts(ModifierData *md, Object *ob,
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *em,
- DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
+ Mesh *mesh, float (*vertexCos)[3], int numVerts)
{
ArmatureModifierData *amd = (ArmatureModifierData *) md;
- DerivedMesh *dm = derivedData;
+ Mesh *mesh_src = mesh;
- if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
+ if (!mesh) {
+ mesh_src = BKE_bmesh_to_mesh(em->bm, &(struct BMeshToMeshParams){0});
+ }
modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
- armature_deform_verts(amd->object, ob, dm, vertexCos, NULL,
+ armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, NULL,
numVerts, amd->deformflag, (float(*)[3])amd->prevCos, amd->defgrp_name);
/* free cache */
@@ -161,37 +152,39 @@ static void deformVertsEM(
amd->prevCos = NULL;
}
- if (!derivedData) dm->release(dm);
+ if (!mesh) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
static void deformMatricesEM(
- ModifierData *md, Object *ob, struct BMEditMesh *em,
- DerivedMesh *derivedData, float (*vertexCos)[3],
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
+ Mesh *mesh, float (*vertexCos)[3],
float (*defMats)[3][3], int numVerts)
{
ArmatureModifierData *amd = (ArmatureModifierData *) md;
- DerivedMesh *dm = derivedData;
+ Mesh *mesh_src = mesh;
- if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
+ if (!mesh) {
+ mesh_src = BKE_bmesh_to_mesh(em->bm, &(struct BMeshToMeshParams){0});
+ }
- armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
+ armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, defMats, numVerts,
amd->deformflag, NULL, amd->defgrp_name);
- if (!derivedData) dm->release(dm);
+ if (!mesh) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
-static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
+static void deformMatrices(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh,
float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
{
ArmatureModifierData *amd = (ArmatureModifierData *) md;
- DerivedMesh *dm = derivedData;
-
- if (!derivedData) dm = CDDM_from_mesh((Mesh *)ob->data);
+ Mesh *mesh_src = mesh ? mesh : ctx->object->data;
- armature_deform_verts(amd->object, ob, dm, vertexCos, defMats, numVerts,
+ armature_deform_verts(amd->object, ctx->object, mesh_src, vertexCos, defMats, numVerts,
amd->deformflag, NULL, amd->defgrp_name);
-
- if (!derivedData) dm->release(dm);
}
ModifierTypeInfo modifierType_Armature = {
@@ -204,17 +197,25 @@ ModifierTypeInfo modifierType_Armature = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ deformVerts,
/* deformMatrices */ deformMatrices,
/* deformVertsEM */ deformVertsEM,
/* deformMatricesEM */ deformMatricesEM,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_array.c b/source/blender/modifiers/intern/MOD_array.c
index 5119f9e9d8e..01414a3dfad 100644
--- a/source/blender/modifiers/intern/MOD_array.c
+++ b/source/blender/modifiers/intern/MOD_array.c
@@ -41,6 +41,7 @@
#include "BLI_utildefines.h"
#include "DNA_curve_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
@@ -55,13 +56,7 @@
#include "MOD_util.h"
-#include "depsgraph_private.h"
-
-/* Due to cyclic dependencies it's possible that curve used for
- * deformation here is not evaluated at the time of evaluating
- * this modifier.
- */
-#define CYCLIC_DEPENDENCY_WORKAROUND
+#include "DEG_depsgraph.h"
static void initData(ModifierData *md)
{
@@ -103,37 +98,6 @@ static void foreachObjectLink(
walk(userData, ob, &amd->offset_ob, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- ArrayModifierData *amd = (ArrayModifierData *) md;
-
- if (amd->start_cap) {
- DagNode *curNode = dag_get_node(ctx->forest, amd->start_cap);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Array Modifier");
- }
- if (amd->end_cap) {
- DagNode *curNode = dag_get_node(ctx->forest, amd->end_cap);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Array Modifier");
- }
- if (amd->curve_ob) {
- DagNode *curNode = dag_get_node(ctx->forest, amd->curve_ob);
- curNode->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Array Modifier");
- }
- if (amd->offset_ob) {
- DagNode *curNode = dag_get_node(ctx->forest, amd->offset_ob);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Array Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
ArrayModifierData *amd = (ArrayModifierData *)md;
@@ -312,8 +276,8 @@ static void dm_mvert_map_doubles(
}
-static void dm_merge_transform(
- DerivedMesh *result, DerivedMesh *cap_dm, float cap_offset[4][4],
+static void mesh_merge_transform(
+ Mesh *result, Mesh *cap_mesh, float cap_offset[4][4],
unsigned int cap_verts_index, unsigned int cap_edges_index, int cap_loops_index, int cap_polys_index,
int cap_nverts, int cap_nedges, int cap_nloops, int cap_npolys, int *remap, int remap_len)
{
@@ -325,18 +289,12 @@ static void dm_merge_transform(
MPoly *mp;
MDeformVert *dvert;
- /* needed for subsurf so arrays are allocated */
- cap_dm->getVertArray(cap_dm);
- cap_dm->getEdgeArray(cap_dm);
- cap_dm->getLoopArray(cap_dm);
- cap_dm->getPolyArray(cap_dm);
-
- DM_copy_vert_data(cap_dm, result, 0, cap_verts_index, cap_nverts);
- DM_copy_edge_data(cap_dm, result, 0, cap_edges_index, cap_nedges);
- DM_copy_loop_data(cap_dm, result, 0, cap_loops_index, cap_nloops);
- DM_copy_poly_data(cap_dm, result, 0, cap_polys_index, cap_npolys);
+ CustomData_copy_data(&cap_mesh->vdata, &result->vdata, 0, cap_verts_index, cap_nverts);
+ CustomData_copy_data(&cap_mesh->edata, &result->edata, 0, cap_edges_index, cap_nedges);
+ CustomData_copy_data(&cap_mesh->ldata, &result->ldata, 0, cap_loops_index, cap_nloops);
+ CustomData_copy_data(&cap_mesh->pdata, &result->pdata, 0, cap_polys_index, cap_npolys);
- mv = CDDM_get_verts(result) + cap_verts_index;
+ mv = result->mvert + cap_verts_index;
for (i = 0; i < cap_nverts; i++, mv++) {
mul_m4_v3(cap_offset, mv->co);
@@ -345,57 +303,55 @@ static void dm_merge_transform(
}
/* remap the vertex groups if necessary */
- dvert = DM_get_vert_data(result, cap_verts_index, CD_MDEFORMVERT);
+ dvert = result->dvert + cap_verts_index;
if (dvert != NULL) {
BKE_object_defgroup_index_map_apply(dvert, cap_nverts, remap, remap_len);
}
/* adjust cap edge vertex indices */
- me = CDDM_get_edges(result) + cap_edges_index;
+ me = result->medge + cap_edges_index;
for (i = 0; i < cap_nedges; i++, me++) {
me->v1 += cap_verts_index;
me->v2 += cap_verts_index;
}
/* adjust cap poly loopstart indices */
- mp = CDDM_get_polys(result) + cap_polys_index;
+ mp = result->mpoly + cap_polys_index;
for (i = 0; i < cap_npolys; i++, mp++) {
mp->loopstart += cap_loops_index;
}
/* adjust cap loop vertex and edge indices */
- ml = CDDM_get_loops(result) + cap_loops_index;
+ ml = result->mloop + cap_loops_index;
for (i = 0; i < cap_nloops; i++, ml++) {
ml->v += cap_verts_index;
ml->e += cap_edges_index;
}
/* set origindex */
- index_orig = result->getVertDataArray(result, CD_ORIGINDEX);
+ index_orig = CustomData_get_layer(&result->vdata, CD_ORIGINDEX);
if (index_orig) {
copy_vn_i(index_orig + cap_verts_index, cap_nverts, ORIGINDEX_NONE);
}
- index_orig = result->getEdgeDataArray(result, CD_ORIGINDEX);
+ index_orig = CustomData_get_layer(&result->edata, CD_ORIGINDEX);
if (index_orig) {
copy_vn_i(index_orig + cap_edges_index, cap_nedges, ORIGINDEX_NONE);
}
- index_orig = result->getPolyDataArray(result, CD_ORIGINDEX);
+ index_orig = CustomData_get_layer(&result->pdata, CD_ORIGINDEX);
if (index_orig) {
copy_vn_i(index_orig + cap_polys_index, cap_npolys, ORIGINDEX_NONE);
}
- index_orig = result->getLoopDataArray(result, CD_ORIGINDEX);
+ index_orig = CustomData_get_layer(&result->ldata, CD_ORIGINDEX);
if (index_orig) {
copy_vn_i(index_orig + cap_loops_index, cap_nloops, ORIGINDEX_NONE);
}
}
-static DerivedMesh *arrayModifier_doArray(
- ArrayModifierData *amd,
- Scene *scene, Object *ob, DerivedMesh *dm,
- ModifierApplyFlag flag)
+static Mesh *arrayModifier_doArray(
+ ArrayModifierData *amd, const ModifierEvalContext *ctx, Mesh *mesh)
{
const float eps = 1e-6f;
const MVert *src_mvert;
@@ -416,7 +372,7 @@ static DerivedMesh *arrayModifier_doArray(
int tot_doubles;
const bool use_merge = (amd->flags & MOD_ARR_MERGE) != 0;
- const bool use_recalc_normals = (dm->dirty & DM_DIRTY_NORMALS) || use_merge;
+ const bool use_recalc_normals = (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) || use_merge;
const bool use_offset_ob = ((amd->offset_type & MOD_ARR_OFF_OBJ) && amd->offset_ob);
int start_cap_nverts = 0, start_cap_nedges = 0, start_cap_npolys = 0, start_cap_nloops = 0;
@@ -425,47 +381,49 @@ static DerivedMesh *arrayModifier_doArray(
int chunk_nverts, chunk_nedges, chunk_nloops, chunk_npolys;
int first_chunk_start, first_chunk_nverts, last_chunk_start, last_chunk_nverts;
- DerivedMesh *result, *start_cap_dm = NULL, *end_cap_dm = NULL;
+ Mesh *result, *start_cap_mesh = NULL, *end_cap_mesh = NULL;
int *vgroup_start_cap_remap = NULL;
int vgroup_start_cap_remap_len = 0;
int *vgroup_end_cap_remap = NULL;
int vgroup_end_cap_remap_len = 0;
- chunk_nverts = dm->getNumVerts(dm);
- chunk_nedges = dm->getNumEdges(dm);
- chunk_nloops = dm->getNumLoops(dm);
- chunk_npolys = dm->getNumPolys(dm);
+ chunk_nverts = mesh->totvert;
+ chunk_nedges = mesh->totedge;
+ chunk_nloops = mesh->totloop;
+ chunk_npolys = mesh->totpoly;
count = amd->count;
- if (amd->start_cap && amd->start_cap != ob && amd->start_cap->type == OB_MESH) {
- vgroup_start_cap_remap = BKE_object_defgroup_index_map_create(amd->start_cap, ob, &vgroup_start_cap_remap_len);
+ if (amd->start_cap && amd->start_cap != ctx->object && amd->start_cap->type == OB_MESH) {
+ vgroup_start_cap_remap = BKE_object_defgroup_index_map_create(
+ amd->start_cap, ctx->object, &vgroup_start_cap_remap_len);
- start_cap_dm = get_dm_for_modifier(amd->start_cap, flag);
- if (start_cap_dm) {
- start_cap_nverts = start_cap_dm->getNumVerts(start_cap_dm);
- start_cap_nedges = start_cap_dm->getNumEdges(start_cap_dm);
- start_cap_nloops = start_cap_dm->getNumLoops(start_cap_dm);
- start_cap_npolys = start_cap_dm->getNumPolys(start_cap_dm);
+ start_cap_mesh = get_mesh_eval_for_modifier(amd->start_cap, ctx->flag);
+ if (start_cap_mesh) {
+ start_cap_nverts = start_cap_mesh->totvert;
+ start_cap_nedges = start_cap_mesh->totedge;
+ start_cap_nloops = start_cap_mesh->totloop;
+ start_cap_npolys = start_cap_mesh->totpoly;
}
}
- if (amd->end_cap && amd->end_cap != ob && amd->end_cap->type == OB_MESH) {
- vgroup_end_cap_remap = BKE_object_defgroup_index_map_create(amd->end_cap, ob, &vgroup_end_cap_remap_len);
+ if (amd->end_cap && amd->end_cap != ctx->object && amd->end_cap->type == OB_MESH) {
+ vgroup_end_cap_remap = BKE_object_defgroup_index_map_create(
+ amd->end_cap, ctx->object, &vgroup_end_cap_remap_len);
- end_cap_dm = get_dm_for_modifier(amd->end_cap, flag);
- if (end_cap_dm) {
- end_cap_nverts = end_cap_dm->getNumVerts(end_cap_dm);
- end_cap_nedges = end_cap_dm->getNumEdges(end_cap_dm);
- end_cap_nloops = end_cap_dm->getNumLoops(end_cap_dm);
- end_cap_npolys = end_cap_dm->getNumPolys(end_cap_dm);
+ end_cap_mesh = get_mesh_eval_for_modifier(amd->end_cap, ctx->flag);
+ if (end_cap_mesh) {
+ end_cap_nverts = end_cap_mesh->totvert;
+ end_cap_nedges = end_cap_mesh->totedge;
+ end_cap_nloops = end_cap_mesh->totloop;
+ end_cap_npolys = end_cap_mesh->totpoly;
}
}
/* Build up offset array, cumulating all settings options */
unit_m4(offset);
- src_mvert = dm->getVertArray(dm);
+ src_mvert = mesh->mvert;
if (amd->offset_type & MOD_ARR_OFF_CONST) {
add_v3_v3(offset[3], amd->offset);
@@ -489,8 +447,8 @@ static DerivedMesh *arrayModifier_doArray(
float obinv[4][4];
float result_mat[4][4];
- if (ob)
- invert_m4_m4(obinv, ob->obmat);
+ if (ctx->object)
+ invert_m4_m4(obinv, ctx->object->obmat);
else
unit_m4(obinv);
@@ -506,12 +464,6 @@ static DerivedMesh *arrayModifier_doArray(
if (amd->fit_type == MOD_ARR_FITCURVE && amd->curve_ob) {
Curve *cu = amd->curve_ob->data;
if (cu) {
-#ifdef CYCLIC_DEPENDENCY_WORKAROUND
- if (amd->curve_ob->curve_cache == NULL) {
- BKE_displist_make_curveTypes(scene, amd->curve_ob, false);
- }
-#endif
-
if (amd->curve_ob->curve_cache && amd->curve_ob->curve_cache->path) {
float scale_fac = mat4_to_scale(amd->curve_ob->obmat);
length = scale_fac * amd->curve_ob->curve_cache->path->totdist;
@@ -545,8 +497,8 @@ static DerivedMesh *arrayModifier_doArray(
result_npolys = chunk_npolys * count + start_cap_npolys + end_cap_npolys;
/* Initialize a result dm */
- result = CDDM_from_template(dm, result_nverts, result_nedges, 0, result_nloops, result_npolys);
- result_dm_verts = CDDM_get_verts(result);
+ result = BKE_mesh_from_template(mesh, result_nverts, result_nedges, 0, result_nloops, result_npolys);
+ result_dm_verts = result->mvert;
if (use_merge) {
/* Will need full_doubles_map for handling merge */
@@ -555,23 +507,22 @@ static DerivedMesh *arrayModifier_doArray(
}
/* copy customdata to original geometry */
- DM_copy_vert_data(dm, result, 0, 0, chunk_nverts);
- DM_copy_edge_data(dm, result, 0, 0, chunk_nedges);
- DM_copy_loop_data(dm, result, 0, 0, chunk_nloops);
- DM_copy_poly_data(dm, result, 0, 0, chunk_npolys);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, chunk_nverts);
+ CustomData_copy_data(&mesh->edata, &result->edata, 0, 0, chunk_nedges);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, 0, 0, chunk_nloops);
+ CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, chunk_npolys);
/* Subsurf for eg wont have mesh data in the custom data arrays.
* now add mvert/medge/mpoly layers. */
-
- if (!CustomData_has_layer(&dm->vertData, CD_MVERT)) {
- dm->copyVertArray(dm, result_dm_verts);
+ if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) {
+ memcpy(result->mvert, mesh->mvert, sizeof(*result->mvert) * mesh->totvert);
}
- if (!CustomData_has_layer(&dm->edgeData, CD_MEDGE)) {
- dm->copyEdgeArray(dm, CDDM_get_edges(result));
+ if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
+ memcpy(result->medge, mesh->medge, sizeof(*result->medge) * mesh->totedge);
}
- if (!CustomData_has_layer(&dm->polyData, CD_MPOLY)) {
- dm->copyLoopArray(dm, CDDM_get_loops(result));
- dm->copyPolyArray(dm, CDDM_get_polys(result));
+ if (!CustomData_has_layer(&mesh->pdata, CD_MPOLY)) {
+ memcpy(result->mloop, mesh->mloop, sizeof(*result->mloop) * mesh->totloop);
+ memcpy(result->mpoly, mesh->mpoly, sizeof(*result->mpoly) * mesh->totpoly);
}
/* Remember first chunk, in case of cap merge */
@@ -581,10 +532,10 @@ static DerivedMesh *arrayModifier_doArray(
unit_m4(current_offset);
for (c = 1; c < count; c++) {
/* copy customdata to new geometry */
- DM_copy_vert_data(result, result, 0, c * chunk_nverts, chunk_nverts);
- DM_copy_edge_data(result, result, 0, c * chunk_nedges, chunk_nedges);
- DM_copy_loop_data(result, result, 0, c * chunk_nloops, chunk_nloops);
- DM_copy_poly_data(result, result, 0, c * chunk_npolys, chunk_npolys);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, 0, c * chunk_nverts, chunk_nverts);
+ CustomData_copy_data(&mesh->edata, &result->edata, 0, c * chunk_nedges, chunk_nedges);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, 0, c * chunk_nloops, chunk_nloops);
+ CustomData_copy_data(&mesh->pdata, &result->pdata, 0, c * chunk_npolys, chunk_npolys);
mv_prev = result_dm_verts;
mv = mv_prev + c * chunk_nverts;
@@ -607,19 +558,19 @@ static DerivedMesh *arrayModifier_doArray(
}
/* adjust edge vertex indices */
- me = CDDM_get_edges(result) + c * chunk_nedges;
+ me = result->medge + c * chunk_nedges;
for (i = 0; i < chunk_nedges; i++, me++) {
me->v1 += c * chunk_nverts;
me->v2 += c * chunk_nverts;
}
- mp = CDDM_get_polys(result) + c * chunk_npolys;
+ mp = result->mpoly + c * chunk_npolys;
for (i = 0; i < chunk_npolys; i++, mp++) {
mp->loopstart += c * chunk_nloops;
}
/* adjust loop vertex and edge indices */
- ml = CDDM_get_loops(result) + c * chunk_nloops;
+ ml = result->mloop + c * chunk_nloops;
for (i = 0; i < chunk_nloops; i++, ml++) {
ml->v += c * chunk_nverts;
ml->e += c * chunk_nedges;
@@ -669,9 +620,9 @@ static DerivedMesh *arrayModifier_doArray(
/* handle UVs */
if (chunk_nloops > 0 && is_zero_v2(amd->uv_offset) == false) {
- const int totuv = CustomData_number_of_layers(&result->loopData, CD_MLOOPUV);
+ const int totuv = CustomData_number_of_layers(&result->ldata, CD_MLOOPUV);
for (i = 0; i < totuv; i++) {
- MLoopUV *dmloopuv = CustomData_get_layer_n(&result->loopData, CD_MLOOPUV, i);
+ MLoopUV *dmloopuv = CustomData_get_layer_n(&result->ldata, CD_MLOOPUV, i);
dmloopuv += chunk_nloops;
for (c = 1; c < count; c++) {
const float uv_offset[2] = {
@@ -705,12 +656,12 @@ static DerivedMesh *arrayModifier_doArray(
}
/* start capping */
- if (start_cap_dm) {
+ if (start_cap_mesh) {
float start_offset[4][4];
int start_cap_start = result_nverts - start_cap_nverts - end_cap_nverts;
invert_m4_m4(start_offset, offset);
- dm_merge_transform(
- result, start_cap_dm, start_offset,
+ mesh_merge_transform(
+ result, start_cap_mesh, start_offset,
result_nverts - start_cap_nverts - end_cap_nverts,
result_nedges - start_cap_nedges - end_cap_nedges,
result_nloops - start_cap_nloops - end_cap_nloops,
@@ -730,12 +681,12 @@ static DerivedMesh *arrayModifier_doArray(
}
}
- if (end_cap_dm) {
+ if (end_cap_mesh) {
float end_offset[4][4];
int end_cap_start = result_nverts - end_cap_nverts;
mul_m4_m4m4(end_offset, current_offset, offset);
- dm_merge_transform(
- result, end_cap_dm, end_offset,
+ mesh_merge_transform(
+ result, end_cap_mesh, end_offset,
result_nverts - end_cap_nverts,
result_nedges - end_cap_nedges,
result_nloops - end_cap_nloops,
@@ -777,16 +728,16 @@ static DerivedMesh *arrayModifier_doArray(
}
}
if (tot_doubles > 0) {
- result = CDDM_merge_verts(result, full_doubles_map, tot_doubles, CDDM_MERGE_VERTS_DUMP_IF_EQUAL);
+ result = BKE_mesh_merge_verts(result, full_doubles_map, tot_doubles, MESH_MERGE_VERTS_DUMP_IF_EQUAL);
}
MEM_freeN(full_doubles_map);
}
- /* In case org dm has dirty normals, or we made some merging, mark normals as dirty in new dm!
+ /* In case org dm has dirty normals, or we made some merging, mark normals as dirty in new mesh!
* TODO: we may need to set other dirty flags as well?
*/
if (use_recalc_normals) {
- result->dirty |= DM_DIRTY_NORMALS;
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
}
if (vgroup_start_cap_remap) {
@@ -800,12 +751,11 @@ static DerivedMesh *arrayModifier_doArray(
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag flag)
+static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ Mesh *mesh)
{
ArrayModifierData *amd = (ArrayModifierData *) md;
- return arrayModifier_doArray(amd, md->scene, ob, dm, flag);
+ return arrayModifier_doArray(amd, ctx, mesh);
}
@@ -821,17 +771,25 @@ ModifierTypeInfo modifierType_Array = {
eModifierTypeFlag_AcceptsCVs,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_bevel.c b/source/blender/modifiers/intern/MOD_bevel.c
index 93dc0203f83..9e5913af6c9 100644
--- a/source/blender/modifiers/intern/MOD_bevel.c
+++ b/source/blender/modifiers/intern/MOD_bevel.c
@@ -33,6 +33,7 @@
*/
#include "DNA_object_types.h"
+#include "DNA_mesh_types.h"
#include "BLI_utildefines.h"
#include "BLI_math.h"
@@ -40,6 +41,7 @@
#include "BKE_cdderivedmesh.h"
#include "BKE_deform.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "MOD_util.h"
@@ -86,11 +88,9 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
/*
* This calls the new bevel code (added since 2.64)
*/
-static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
- DerivedMesh *result;
+ Mesh *result;
BMesh *bm;
BMIter iter;
BMEdge *e;
@@ -103,12 +103,21 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob,
const bool vertex_only = (bmd->flags & MOD_BEVEL_VERT) != 0;
const bool do_clamp = !(bmd->flags & MOD_BEVEL_OVERLAP_OK);
const int offset_type = bmd->val_flags;
- const int mat = CLAMPIS(bmd->mat, -1, ob->totcol - 1);
+ const int mat = CLAMPIS(bmd->mat, -1, ctx->object->totcol - 1);
const bool loop_slide = (bmd->flags & MOD_BEVEL_EVEN_WIDTHS) == 0;
- bm = DM_to_bmesh(dm, true);
+ bm = BKE_mesh_to_bmesh_ex(
+ mesh,
+ &(struct BMeshCreateParams){0},
+ &(struct BMeshFromMeshParams){
+ .calc_face_normal = true,
+ .add_key_index = false,
+ .use_shapekey = true,
+ .active_shapekey = ctx->object->shapenr,
+ });
+
if ((bmd->lim_flags & MOD_BEVEL_VGROUP) && bmd->defgrp_name[0])
- modifier_get_vgroup(ob, dm, bmd->defgrp_name, &dvert, &vgroup);
+ modifier_get_vgroup_mesh(ctx->object, mesh, bmd->defgrp_name, &dvert, &vgroup);
if (vertex_only) {
BM_ITER_MESH (v, &iter, bm, BM_VERTS_OF_MESH) {
@@ -168,14 +177,14 @@ static DerivedMesh *applyModifier(ModifierData *md, struct Object *ob,
vertex_only, bmd->lim_flags & MOD_BEVEL_WEIGHT, do_clamp,
dvert, vgroup, mat, loop_slide);
- result = CDDM_from_bmesh(bm, true);
+ result = BKE_bmesh_to_mesh(bm, &(struct BMeshToMeshParams){0});
BLI_assert(bm->vtoolflagpool == NULL &&
bm->etoolflagpool == NULL &&
bm->ftoolflagpool == NULL); /* make sure we never alloc'd these */
BM_mesh_free(bm);
- result->dirty |= DM_DIRTY_NORMALS;
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
return result;
}
@@ -195,17 +204,25 @@ ModifierTypeInfo modifierType_Bevel = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_boolean.c b/source/blender/modifiers/intern/MOD_boolean.c
index 93c4d83870a..5057f69bf23 100644
--- a/source/blender/modifiers/intern/MOD_boolean.c
+++ b/source/blender/modifiers/intern/MOD_boolean.c
@@ -45,8 +45,6 @@
#include "BKE_library_query.h"
#include "BKE_modifier.h"
-#include "depsgraph_private.h"
-
#include "MOD_util.h"
@@ -97,18 +95,6 @@ static void foreachObjectLink(
walk(userData, ob, &bmd->object, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- BooleanModifierData *bmd = (BooleanModifierData *) md;
-
- if (bmd->object) {
- DagNode *curNode = dag_get_node(ctx->forest, bmd->object);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Boolean Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
BooleanModifierData *bmd = (BooleanModifierData *)md;
@@ -180,9 +166,8 @@ static int bm_face_isect_pair(BMFace *f, void *UNUSED(user_data))
}
static DerivedMesh *applyModifier(
- ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag flag)
+ ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
BooleanModifierData *bmd = (BooleanModifierData *) md;
DerivedMesh *dm_other;
@@ -190,7 +175,7 @@ static DerivedMesh *applyModifier(
if (!bmd->object)
return dm;
- dm_other = get_dm_for_modifier(bmd->object, flag);
+ dm_other = get_dm_for_modifier(bmd->object, ctx->flag);
if (dm_other) {
DerivedMesh *result;
@@ -198,10 +183,10 @@ static DerivedMesh *applyModifier(
/* when one of objects is empty (has got no faces) we could speed up
* calculation a bit returning one of objects' derived meshes (or empty one)
* Returning mesh is depended on modifiers operation (sergey) */
- result = get_quick_derivedMesh(ob, dm, bmd->object, dm_other, bmd->operation);
+ result = get_quick_derivedMesh(ctx->object, dm, bmd->object, dm_other, bmd->operation);
if (result == NULL) {
- const bool is_flip = (is_negative_m4(ob->obmat) != is_negative_m4(bmd->object->obmat));
+ const bool is_flip = (is_negative_m4(ctx->object->obmat) != is_negative_m4(bmd->object->obmat));
BMesh *bm;
const BMAllocTemplate allocsize = BMALLOC_TEMPLATE_FROM_DM(dm, dm_other);
@@ -248,7 +233,7 @@ static DerivedMesh *applyModifier(
float imat[4][4];
float omat[4][4];
- invert_m4_m4(imat, ob->obmat);
+ invert_m4_m4(imat, ctx->object->obmat);
mul_m4_m4m4(omat, imat, bmd->object->obmat);
BMVert *eve;
@@ -274,7 +259,7 @@ static DerivedMesh *applyModifier(
const short ob_src_totcol = bmd->object->totcol;
short *material_remap = BLI_array_alloca(material_remap, ob_src_totcol ? ob_src_totcol : 1);
- BKE_material_remap_object_calc(ob, bmd->object, material_remap);
+ BKE_material_remap_object_calc(ctx->object, bmd->object, material_remap);
BMFace *efa;
i = 0;
@@ -367,17 +352,25 @@ ModifierTypeInfo modifierType_Boolean = {
eModifierTypeFlag_UsesPointCache,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_build.c b/source/blender/modifiers/intern/MOD_build.c
index f71d14efb2b..048e9ce33c0 100644
--- a/source/blender/modifiers/intern/MOD_build.c
+++ b/source/blender/modifiers/intern/MOD_build.c
@@ -41,8 +41,13 @@
#include "BLI_ghash.h"
#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
+#include "DNA_object_types.h"
+
+#include "DEG_depsgraph_query.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_particle.h"
#include "BKE_scene.h"
@@ -75,12 +80,10 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
return true;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ struct Mesh *mesh)
{
- DerivedMesh *dm = derivedData;
- DerivedMesh *result;
+ Mesh *result;
BuildModifierData *bmd = (BuildModifierData *) md;
int i, j, k;
int numFaces_dst, numEdges_dst, numLoops_dst = 0;
@@ -93,16 +96,16 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
GHash *vertHash = BLI_ghash_int_new("build ve apply gh");
/* maps edge indices in new mesh to indices in old mesh */
GHash *edgeHash = BLI_ghash_int_new("build ed apply gh");
+ /* maps edge indices in old mesh to indices in new mesh */
GHash *edgeHash2 = BLI_ghash_int_new("build ed apply gh");
- const int numVert_src = dm->getNumVerts(dm);
- const int numEdge_src = dm->getNumEdges(dm);
- const int numPoly_src = dm->getNumPolys(dm);
- MPoly *mpoly_src = dm->getPolyArray(dm);
- MLoop *mloop_src = dm->getLoopArray(dm);
- MEdge *medge_src = dm->getEdgeArray(dm);
- MVert *mvert_src = dm->getVertArray(dm);
-
+ const int numVert_src = mesh->totvert;
+ const int numEdge_src = mesh->totedge;
+ const int numPoly_src = mesh->totpoly;
+ MPoly *mpoly_src = mesh->mpoly;
+ MLoop *mloop_src = mesh->mloop;
+ MEdge *medge_src = mesh->medge;
+ MVert *mvert_src = mesh->mvert;
vertMap = MEM_malloc_arrayN(numVert_src, sizeof(*vertMap), "build modifier vertMap");
edgeMap = MEM_malloc_arrayN(numEdge_src, sizeof(*edgeMap), "build modifier edgeMap");
@@ -112,13 +115,13 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
range_vn_i(edgeMap, numEdge_src, 0);
range_vn_i(faceMap, numPoly_src, 0);
- frac = (BKE_scene_frame_get(md->scene) - bmd->start) / bmd->length;
+ struct Scene *scene = DEG_get_input_scene(ctx->depsgraph);
+ frac = (BKE_scene_frame_get(scene) - bmd->start) / bmd->length;
CLAMP(frac, 0.0f, 1.0f);
-
if (bmd->flag & MOD_BUILD_FLAG_REVERSE) {
frac = 1.0f - frac;
}
-
+
numFaces_dst = numPoly_src * frac;
numEdges_dst = numEdge_src * frac;
@@ -126,7 +129,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
if (numFaces_dst) {
MPoly *mpoly, *mp;
MLoop *ml, *mloop;
- MEdge *medge;
uintptr_t hash_num, hash_num_alt;
if (bmd->flag & MOD_BUILD_FLAG_RANDOMIZE) {
@@ -159,11 +161,10 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
/* get the set of edges that will be in the new mesh (i.e. all edges
* that have both verts in the new mesh)
*/
- medge = medge_src;
hash_num = 0;
hash_num_alt = 0;
for (i = 0; i < numEdge_src; i++, hash_num_alt++) {
- MEdge *me = medge + i;
+ MEdge *me = medge_src + i;
if (BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v1)) &&
BLI_ghash_haskey(vertHash, SET_INT_IN_POINTER(me->v2)))
@@ -173,6 +174,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
hash_num++;
}
}
+ BLI_assert(hash_num == BLI_ghash_len(edgeHash));
}
else if (numEdges_dst) {
MEdge *medge, *me;
@@ -206,7 +208,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
/* get the set of edges that will be in the new mesh */
for (i = 0; i < numEdges_dst; i++) {
j = BLI_ghash_len(edgeHash);
-
+
BLI_ghash_insert(edgeHash, SET_INT_IN_POINTER(j),
SET_INT_IN_POINTER(edgeMap[i]));
BLI_ghash_insert(edgeHash2, SET_INT_IN_POINTER(edgeMap[i]),
@@ -229,11 +231,9 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
}
}
- /* now we know the number of verts, edges and faces, we can create
- * the mesh
- */
- result = CDDM_from_template(dm, BLI_ghash_len(vertHash),
- BLI_ghash_len(edgeHash), 0, numLoops_dst, numFaces_dst);
+ /* now we know the number of verts, edges and faces, we can create the mesh. */
+ result = BKE_mesh_from_template(mesh, BLI_ghash_len(vertHash), BLI_ghash_len(edgeHash),
+ 0, numLoops_dst, numFaces_dst);
/* copy the vertices across */
GHASH_ITER (gh_iter, vertHash) {
@@ -243,45 +243,44 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
int newIndex = GET_INT_FROM_POINTER(BLI_ghashIterator_getValue(&gh_iter));
source = mvert_src[oldIndex];
- dest = CDDM_get_vert(result, newIndex);
+ dest = &result->mvert[newIndex];
- DM_copy_vert_data(dm, result, oldIndex, newIndex, 1);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, oldIndex, newIndex, 1);
*dest = source;
}
-
+
/* copy the edges across, remapping indices */
for (i = 0; i < BLI_ghash_len(edgeHash); i++) {
MEdge source;
MEdge *dest;
int oldIndex = GET_INT_FROM_POINTER(BLI_ghash_lookup(edgeHash, SET_INT_IN_POINTER(i)));
-
+
source = medge_src[oldIndex];
- dest = CDDM_get_edge(result, i);
-
+ dest = &result->medge[i];
+
source.v1 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v1)));
source.v2 = GET_INT_FROM_POINTER(BLI_ghash_lookup(vertHash, SET_INT_IN_POINTER(source.v2)));
-
- DM_copy_edge_data(dm, result, oldIndex, i, 1);
+
+ CustomData_copy_data(&mesh->edata, &result->edata, oldIndex, i, 1);
*dest = source;
}
- mpoly_dst = CDDM_get_polys(result);
- /* mloop_dst = */ ml_dst = CDDM_get_loops(result);
+ mpoly_dst = result->mpoly;
+ ml_dst = result->mloop;
/* copy the faces across, remapping indices */
k = 0;
for (i = 0; i < numFaces_dst; i++) {
MPoly *source;
MPoly *dest;
-
+
source = mpoly_src + faceMap[i];
dest = mpoly_dst + i;
- DM_copy_poly_data(dm, result, faceMap[i], i, 1);
-
+ CustomData_copy_data(&mesh->pdata, &result->pdata, faceMap[i], i, 1);
+
*dest = *source;
dest->loopstart = k;
-
- DM_copy_loop_data(dm, result, source->loopstart, dest->loopstart, dest->totloop);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, source->loopstart, dest->loopstart, dest->totloop);
ml_src = mloop_src + source->loopstart;
for (j = 0; j < source->totloop; j++, k++, ml_src++, ml_dst++) {
@@ -298,10 +297,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob),
MEM_freeN(edgeMap);
MEM_freeN(faceMap);
- if (dm->dirty & DM_DIRTY_NORMALS) {
- result->dirty |= DM_DIRTY_NORMALS;
+ if (mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) {
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
}
+ /* TODO(sybren): also copy flags & tags? */
return result;
}
@@ -314,17 +314,25 @@ ModifierTypeInfo modifierType_Build = {
/* flags */ eModifierTypeFlag_AcceptsMesh |
eModifierTypeFlag_AcceptsCVs,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_cast.c b/source/blender/modifiers/intern/MOD_cast.c
index 60465df0492..11c8ba4a9cd 100644
--- a/source/blender/modifiers/intern/MOD_cast.c
+++ b/source/blender/modifiers/intern/MOD_cast.c
@@ -45,9 +45,6 @@
#include "BKE_library_query.h"
#include "BKE_modifier.h"
-
-#include "depsgraph_private.h"
-
#include "MOD_util.h"
static void initData(ModifierData *md)
@@ -105,18 +102,6 @@ static void foreachObjectLink(
walk(userData, ob, &cmd->object, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- CastModifierData *cmd = (CastModifierData *) md;
-
- if (cmd->object) {
- DagNode *curNode = dag_get_node(ctx->forest, cmd->object);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_OB_DATA,
- "Cast Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
CastModifierData *cmd = (CastModifierData *)md;
@@ -444,22 +429,21 @@ static void cuboid_do(
}
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
DerivedMesh *dm = NULL;
CastModifierData *cmd = (CastModifierData *)md;
- dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
- cuboid_do(cmd, ob, dm, vertexCos, numVerts);
+ cuboid_do(cmd, ctx->object, dm, vertexCos, numVerts);
}
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
- sphere_do(cmd, ob, dm, vertexCos, numVerts);
+ sphere_do(cmd, ctx->object, dm, vertexCos, numVerts);
}
if (dm != derivedData)
@@ -467,17 +451,18 @@ static void deformVerts(ModifierData *md, Object *ob,
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
+ ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, editData, derivedData, NULL, false, false);
CastModifierData *cmd = (CastModifierData *)md;
if (cmd->type == MOD_CAST_TYPE_CUBOID) {
- cuboid_do(cmd, ob, dm, vertexCos, numVerts);
+ cuboid_do(cmd, ctx->object, dm, vertexCos, numVerts);
}
else { /* MOD_CAST_TYPE_SPHERE or MOD_CAST_TYPE_CYLINDER */
- sphere_do(cmd, ob, dm, vertexCos, numVerts);
+ sphere_do(cmd, ctx->object, dm, vertexCos, numVerts);
}
if (dm != derivedData)
@@ -495,17 +480,25 @@ ModifierTypeInfo modifierType_Cast = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_cloth.c b/source/blender/modifiers/intern/MOD_cloth.c
index 2b181c0fb18..315ea73d086 100644
--- a/source/blender/modifiers/intern/MOD_cloth.c
+++ b/source/blender/modifiers/intern/MOD_cloth.c
@@ -43,7 +43,6 @@
#include "BLI_utildefines.h"
-
#include "BKE_cloth.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_effect.h"
@@ -53,8 +52,6 @@
#include "BKE_modifier.h"
#include "BKE_pointcache.h"
-#include "depsgraph_private.h"
-
#include "MOD_util.h"
static void initData(ModifierData *md)
@@ -72,8 +69,9 @@ static void initData(ModifierData *md)
cloth_init(clmd);
}
-static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData, float (*vertexCos)[3],
- int numVerts, ModifierApplyFlag UNUSED(flag))
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData, float (*vertexCos)[3],
+ int numVerts)
{
DerivedMesh *dm;
ClothModifierData *clmd = (ClothModifierData *) md;
@@ -86,7 +84,7 @@ static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
return;
}
- dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
if (dm == derivedData)
dm = CDDM_copy(dm);
@@ -97,7 +95,7 @@ static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
* Also hopefully new cloth system will arrive soon..
*/
if (derivedData == NULL && clmd->sim_parms->shapekey_rest) {
- KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ob),
+ KeyBlock *kb = BKE_keyblock_from_key(BKE_key_from_object(ctx->object),
clmd->sim_parms->shapekey_rest);
if (kb && kb->data != NULL) {
float (*layerorco)[3];
@@ -112,32 +110,17 @@ static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
CDDM_apply_vert_coords(dm, vertexCos);
- clothModifier_do(clmd, md->scene, ob, dm, vertexCos);
+ clothModifier_do(clmd, ctx->depsgraph, md->scene, ctx->object, dm, vertexCos);
dm->release(dm);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- ClothModifierData *clmd = (ClothModifierData *) md;
-
- if (clmd) {
- /* Actual code uses get_collisionobjects */
-#ifdef WITH_LEGACY_DEPSGRAPH
- dag_add_collision_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, clmd->coll_parms->group, ctx->object->lay|ctx->scene->lay, eModifierType_Collision, NULL, true, "Cloth Collision");
- dag_add_forcefield_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, clmd->sim_parms->effector_weights, true, 0, "Cloth Field");
-#else
- (void)ctx;
-#endif
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
ClothModifierData *clmd = (ClothModifierData *)md;
if (clmd != NULL) {
/* Actual code uses get_collisionobjects */
- DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, clmd->coll_parms->group, ctx->object->lay|ctx->scene->lay, eModifierType_Collision, NULL, true, "Cloth Collision");
+ DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, clmd->coll_parms->group, eModifierType_Collision, NULL, true, "Cloth Collision");
DEG_add_forcefield_relations(ctx->node, ctx->scene, ctx->object, clmd->sim_parms->effector_weights, true, 0, "Cloth Field");
}
@@ -243,17 +226,25 @@ ModifierTypeInfo modifierType_Cloth = {
eModifierTypeFlag_Single,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_collision.c b/source/blender/modifiers/intern/MOD_collision.c
index 0a15799f61a..c8c00e31845 100644
--- a/source/blender/modifiers/intern/MOD_collision.c
+++ b/source/blender/modifiers/intern/MOD_collision.c
@@ -98,15 +98,15 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
return true;
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int UNUSED(numVerts),
- ModifierApplyFlag UNUSED(flag))
+ int UNUSED(numVerts))
{
CollisionModifierData *collmd = (CollisionModifierData *) md;
DerivedMesh *dm = NULL;
MVert *tempVert = NULL;
+ Object *ob = ctx->object;
/* if possible use/create DerivedMesh */
if (derivedData) dm = CDDM_copy(derivedData);
@@ -254,17 +254,25 @@ ModifierTypeInfo modifierType_Collision = {
eModifierTypeFlag_Single,
/* copyData */ NULL,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_correctivesmooth.c b/source/blender/modifiers/intern/MOD_correctivesmooth.c
index 08f4588df87..186f5a7cf89 100644
--- a/source/blender/modifiers/intern/MOD_correctivesmooth.c
+++ b/source/blender/modifiers/intern/MOD_correctivesmooth.c
@@ -713,12 +713,12 @@ error:
static void deformVerts(
- ModifierData *md, Object *ob, DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag))
+ ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
- correctivesmooth_modifier_do(md, ob, dm, vertexCos, (unsigned int)numVerts, NULL);
+ correctivesmooth_modifier_do(md, ctx->object, dm, vertexCos, (unsigned int)numVerts, NULL);
if (dm != derivedData) {
dm->release(dm);
@@ -727,12 +727,12 @@ static void deformVerts(
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, editData, derivedData, NULL, false, false);
- correctivesmooth_modifier_do(md, ob, dm, vertexCos, (unsigned int)numVerts, editData);
+ correctivesmooth_modifier_do(md, ctx->object, dm, vertexCos, (unsigned int)numVerts, editData);
if (dm != derivedData) {
dm->release(dm);
@@ -749,17 +749,25 @@ ModifierTypeInfo modifierType_CorrectiveSmooth = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_curve.c b/source/blender/modifiers/intern/MOD_curve.c
index 7e16bf450fc..7d10d6f687a 100644
--- a/source/blender/modifiers/intern/MOD_curve.c
+++ b/source/blender/modifiers/intern/MOD_curve.c
@@ -39,12 +39,13 @@
#include "BLI_utildefines.h"
+
#include "BKE_cdderivedmesh.h"
#include "BKE_lattice.h"
#include "BKE_library_query.h"
#include "BKE_modifier.h"
-#include "depsgraph_private.h"
+#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
@@ -92,19 +93,6 @@ static void foreachObjectLink(
walk(userData, ob, &cmd->object, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- CurveModifierData *cmd = (CurveModifierData *) md;
-
- if (cmd->object) {
- DagNode *curNode = dag_get_node(ctx->forest, cmd->object);
- curNode->eval_flags |= DAG_EVAL_NEED_CURVE_PATH;
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Curve Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
CurveModifierData *cmd = (CurveModifierData *)md;
@@ -123,29 +111,28 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Curve Modifier");
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
CurveModifierData *cmd = (CurveModifierData *) md;
/* silly that defaxis and curve_deform_verts are off by 1
* but leave for now to save having to call do_versions */
- curve_deform_verts(md->scene, cmd->object, ob, derivedData, vertexCos, numVerts,
+ curve_deform_verts(cmd->object, ctx->object, derivedData, vertexCos, numVerts,
cmd->name, cmd->defaxis - 1);
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *em,
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm = derivedData;
if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
- deformVerts(md, ob, dm, vertexCos, numVerts, 0);
+ deformVerts(md, ctx, dm, vertexCos, numVerts);
if (!derivedData) dm->release(dm);
}
@@ -161,17 +148,25 @@ ModifierTypeInfo modifierType_Curve = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_datatransfer.c b/source/blender/modifiers/intern/MOD_datatransfer.c
index d810978fb0b..863a6a3bb14 100644
--- a/source/blender/modifiers/intern/MOD_datatransfer.c
+++ b/source/blender/modifiers/intern/MOD_datatransfer.c
@@ -50,8 +50,6 @@
#include "MEM_guardedalloc.h"
#include "MOD_util.h"
-#include "depsgraph_private.h"
-
/**************************************
* Modifiers functions. *
**************************************/
@@ -127,19 +125,6 @@ static void foreachObjectLink(
walk(userData, ob, &dtmd->ob_source, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
- DagNode *curNode;
-
- if (dtmd->ob_source) {
- curNode = dag_get_node(ctx->forest, dtmd->ob_source);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "DataTransfer Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
@@ -163,15 +148,14 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
DT_TYPE_SHARP_FACE \
)
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData)
{
DataTransferModifierData *dtmd = (DataTransferModifierData *) md;
DerivedMesh *dm = derivedData;
ReportList reports;
/* Only used to check wehther we are operating on org data or not... */
- Mesh *me = ob->data;
+ Mesh *me = ctx->object->data;
const bool invert_vgroup = (dtmd->flags & MOD_DATATRANSFER_INVERT_VGROUP) != 0;
@@ -181,7 +165,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
SpaceTransform *space_transform = (dtmd->flags & MOD_DATATRANSFER_OBSRC_TRANSFORM) ? &space_transform_data : NULL;
if (space_transform) {
- BLI_SPACE_TRANSFORM_SETUP(space_transform, ob, dtmd->ob_source);
+ BLI_SPACE_TRANSFORM_SETUP(space_transform, ctx->object, dtmd->ob_source);
}
MVert *mvert = dm->getVertArray(dm);
@@ -195,7 +179,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
BKE_reports_init(&reports, RPT_STORE);
/* Note: no islands precision for now here. */
- BKE_object_data_transfer_dm(md->scene, dtmd->ob_source, ob, dm, dtmd->data_types, false,
+ BKE_object_data_transfer_dm(ctx->depsgraph, md->scene, dtmd->ob_source, ctx->object, dm, dtmd->data_types, false,
dtmd->vmap_mode, dtmd->emap_mode, dtmd->lmap_mode, dtmd->pmap_mode,
space_transform, false, max_dist, dtmd->map_ray_radius, 0.0f,
dtmd->layers_select_src, dtmd->layers_select_dst,
@@ -237,17 +221,25 @@ ModifierTypeInfo modifierType_DataTransfer = {
eModifierTypeFlag_UsesPreview,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_decimate.c b/source/blender/modifiers/intern/MOD_decimate.c
index 8b5b0542442..dfa76e53f84 100644
--- a/source/blender/modifiers/intern/MOD_decimate.c
+++ b/source/blender/modifiers/intern/MOD_decimate.c
@@ -86,9 +86,8 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
DecimateModifierData *dmd = (DecimateModifierData *) md;
DerivedMesh *dm = derivedData, *result = NULL;
@@ -136,7 +135,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
MDeformVert *dvert;
int defgrp_index;
- modifier_get_vgroup(ob, dm, dmd->defgrp_name, &dvert, &defgrp_index);
+ modifier_get_vgroup(ctx->object, dm, dmd->defgrp_name, &dvert, &defgrp_index);
if (dvert) {
const unsigned int vert_tot = dm->getNumVerts(dm);
@@ -217,17 +216,25 @@ ModifierTypeInfo modifierType_Decimate = {
/* flags */ eModifierTypeFlag_AcceptsMesh |
eModifierTypeFlag_AcceptsCVs,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_displace.c b/source/blender/modifiers/intern/MOD_displace.c
index 72122fae6b4..7a715c9290c 100644
--- a/source/blender/modifiers/intern/MOD_displace.c
+++ b/source/blender/modifiers/intern/MOD_displace.c
@@ -50,7 +50,6 @@
#include "BKE_deform.h"
#include "BKE_object.h"
-#include "depsgraph_private.h"
#include "MEM_guardedalloc.h"
#include "MOD_util.h"
@@ -147,27 +146,6 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
return ((!dmd->texture && dmd->direction == MOD_DISP_DIR_RGB_XYZ) || dmd->strength == 0.0f);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- DisplaceModifierData *dmd = (DisplaceModifierData *) md;
-
- if (dmd->map_object && dmd->texmapping == MOD_DISP_MAP_OBJECT) {
- DagNode *curNode = dag_get_node(ctx->forest, dmd->map_object);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Displace Modifier");
- }
-
-
- if (dmd->texmapping == MOD_DISP_MAP_GLOBAL ||
- (ELEM(dmd->direction, MOD_DISP_DIR_X, MOD_DISP_DIR_Y, MOD_DISP_DIR_Z, MOD_DISP_DIR_RGB_XYZ) &&
- dmd->space == MOD_DISP_SPACE_GLOBAL))
- {
- dag_add_relation(ctx->forest, ctx->obNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Displace Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
DisplaceModifierData *dmd = (DisplaceModifierData *)md;
@@ -390,15 +368,14 @@ static void displaceModifier_do(
}
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
- DerivedMesh *dm = get_cddm(ob, NULL, derivedData, vertexCos, dependsOnNormals(md));
+ DerivedMesh *dm = get_cddm(ctx->object, NULL, derivedData, vertexCos, dependsOnNormals(md));
- displaceModifier_do((DisplaceModifierData *)md, ob, dm,
+ displaceModifier_do((DisplaceModifierData *)md, ctx->object, dm,
vertexCos, numVerts);
if (dm != derivedData)
@@ -406,12 +383,12 @@ static void deformVerts(ModifierData *md, Object *ob,
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_cddm(ob, editData, derivedData, vertexCos, dependsOnNormals(md));
+ DerivedMesh *dm = get_cddm(ctx->object, editData, derivedData, vertexCos, dependsOnNormals(md));
- displaceModifier_do((DisplaceModifierData *)md, ob, dm,
+ displaceModifier_do((DisplaceModifierData *)md, ctx->object, dm,
vertexCos, numVerts);
if (dm != derivedData)
@@ -428,17 +405,25 @@ ModifierTypeInfo modifierType_Displace = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_dynamicpaint.c b/source/blender/modifiers/intern/MOD_dynamicpaint.c
index faf06f2d128..ea8ebbc52e0 100644
--- a/source/blender/modifiers/intern/MOD_dynamicpaint.c
+++ b/source/blender/modifiers/intern/MOD_dynamicpaint.c
@@ -36,11 +36,13 @@
#include "BKE_cdderivedmesh.h"
#include "BKE_dynamicpaint.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_modifier.h"
-#include "depsgraph_private.h"
+#include "DEG_depsgraph.h"
+
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
@@ -66,9 +68,6 @@ static void copyData(ModifierData *md, ModifierData *target)
id_us_plus((ID *)surface->init_texture);
}
}
- if (tpmd->brush) {
- id_us_plus((ID *)tpmd->brush->mat);
- }
}
static void freeData(ModifierData *md)
@@ -89,7 +88,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
if (surface->format == MOD_DPAINT_SURFACE_F_IMAGESEQ ||
surface->init_color_type == MOD_DPAINT_INITIAL_TEXTURE)
{
- dataMask |= CD_MASK_MLOOPUV | CD_MASK_MTEXPOLY;
+ dataMask |= CD_MASK_MLOOPUV;
}
/* mcol */
if (surface->type == MOD_DPAINT_SURFACE_T_PAINT ||
@@ -103,24 +102,17 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
}
}
}
-
- if (pmd->brush) {
- if (pmd->brush->flags & MOD_DPAINT_USE_MATERIAL) {
- dataMask |= CD_MASK_MLOOPUV | CD_MASK_MTEXPOLY;
- }
- }
return dataMask;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag flag)
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *) md;
/* dont apply dynamic paint on orco dm stack */
- if (!(flag & MOD_APPLY_ORCO)) {
- return dynamicPaint_Modifier_do(pmd, md->scene, ob, dm);
+ if (!(ctx->flag & MOD_APPLY_ORCO)) {
+ return dynamicPaint_Modifier_do(pmd, ctx->depsgraph, md->scene, ctx->object, dm);
}
return dm;
}
@@ -130,27 +122,6 @@ static bool is_brush_cb(Object *UNUSED(ob), ModifierData *pmd)
return ((DynamicPaintModifierData *)pmd)->brush != NULL;
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- DynamicPaintModifierData *pmd = (DynamicPaintModifierData *) md;
-
- /* add relation from canvases to all brush objects */
- if (pmd && pmd->canvas) {
-#ifdef WITH_LEGACY_DEPSGRAPH
- for (DynamicPaintSurface *surface = pmd->canvas->surfaces.first; surface; surface = surface->next) {
- if (surface->effect & MOD_DPAINT_EFFECT_DO_DRIP) {
- dag_add_forcefield_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, surface->effector_weights, true, 0, "Dynamic Paint Field");
- }
-
- /* Actual code uses custom loop over group/scene without layer checks in dynamicPaint_doStep */
- dag_add_collision_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, surface->brush_group, -1, eModifierType_DynamicPaint, is_brush_cb, false, "Dynamic Paint Brush");
- }
-#else
- (void)ctx;
-#endif
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
DynamicPaintModifierData *pmd = (DynamicPaintModifierData *)md;
@@ -162,7 +133,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
/* Actual code uses custom loop over group/scene without layer checks in dynamicPaint_doStep */
- DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, surface->brush_group, -1, eModifierType_DynamicPaint, is_brush_cb, false, "Dynamic Paint Brush");
+ DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, surface->brush_group, eModifierType_DynamicPaint, is_brush_cb, false, "Dynamic Paint Brush");
}
}
}
@@ -188,9 +159,6 @@ static void foreachIDLink(ModifierData *md, Object *ob,
}
}
}
- if (pmd->brush) {
- walk(userData, ob, (ID **)&pmd->brush->mat, IDWALK_CB_USER);
- }
}
static void foreachTexLink(ModifierData *UNUSED(md), Object *UNUSED(ob),
@@ -211,17 +179,25 @@ ModifierTypeInfo modifierType_DynamicPaint = {
eModifierTypeFlag_UsesPreview,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_edgesplit.c b/source/blender/modifiers/intern/MOD_edgesplit.c
index a17870f2bf4..10e26a918be 100644
--- a/source/blender/modifiers/intern/MOD_edgesplit.c
+++ b/source/blender/modifiers/intern/MOD_edgesplit.c
@@ -41,26 +41,37 @@
#include "BLI_math.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_library.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "bmesh.h"
#include "bmesh_tools.h"
+#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "MOD_modifiertypes.h"
-static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd)
+static Mesh *doEdgeSplit(Mesh *mesh, EdgeSplitModifierData *emd, const ModifierEvalContext *ctx)
{
- DerivedMesh *result;
+ Mesh *result;
BMesh *bm;
BMIter iter;
BMEdge *e;
float threshold = cosf(emd->split_angle + 0.000000175f);
const bool calc_face_normals = (emd->flags & MOD_EDGESPLIT_FROMANGLE) != 0;
- bm = DM_to_bmesh(dm, calc_face_normals);
-
+ bm = BKE_mesh_to_bmesh_ex(
+ mesh,
+ &(struct BMeshCreateParams){0},
+ &(struct BMeshFromMeshParams){
+ .calc_face_normal = calc_face_normals,
+ .add_key_index = false,
+ .use_shapekey = true,
+ .active_shapekey = ctx->object->shapenr,
+ });
+
if (emd->flags & MOD_EDGESPLIT_FROMANGLE) {
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
/* check for 1 edge having 2 face users */
@@ -78,7 +89,7 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd)
}
}
}
-
+
if (emd->flags & MOD_EDGESPLIT_FROMFLAG) {
BM_ITER_MESH (e, &iter, bm, BM_EDGES_OF_MESH) {
/* check for 2 or more edge users */
@@ -91,15 +102,16 @@ static DerivedMesh *doEdgeSplit(DerivedMesh *dm, EdgeSplitModifierData *emd)
}
}
}
-
+
BM_mesh_edgesplit(bm, false, true, false);
/* BM_mesh_validate(bm); */ /* for troubleshooting */
- result = CDDM_from_bmesh(bm, true);
+ result = BKE_id_new_nomain(ID_ME, mesh->id.name);
+ BM_mesh_bm_to_me(bm, result, &((struct BMeshToMeshParams){0}));
BM_mesh_free(bm);
- result->dirty |= DM_DIRTY_NORMALS;
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
return result;
}
@@ -121,16 +133,17 @@ static void copyData(ModifierData *md, ModifierData *target)
modifier_copyData_generic(md, target);
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *UNUSED(ob), DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(ModifierData *md,
+ const ModifierEvalContext *ctx,
+ Mesh *mesh)
{
- DerivedMesh *result;
+ Mesh *result;
EdgeSplitModifierData *emd = (EdgeSplitModifierData *) md;
if (!(emd->flags & (MOD_EDGESPLIT_FROMANGLE | MOD_EDGESPLIT_FROMFLAG)))
- return dm;
+ return mesh;
- result = doEdgeSplit(dm, emd);
+ result = doEdgeSplit(mesh, emd, ctx);
return result;
}
@@ -148,17 +161,25 @@ ModifierTypeInfo modifierType_EdgeSplit = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_explode.c b/source/blender/modifiers/intern/MOD_explode.c
index c22901f1947..329d1cc49ef 100644
--- a/source/blender/modifiers/intern/MOD_explode.c
+++ b/source/blender/modifiers/intern/MOD_explode.c
@@ -147,7 +147,7 @@ static void createFacepa(ExplodeModifierData *emd,
/* make tree of emitter locations */
tree = BLI_kdtree_new(totpart);
for (p = 0, pa = psys->particles; p < totpart; p++, pa++) {
- psys_particle_on_emitter(psmd, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, NULL, NULL, NULL, NULL, NULL);
+ psys_particle_on_emitter(psmd, psys->part->from, pa->num, pa->num_dmcache, pa->fuv, pa->foffset, co, NULL, NULL, NULL, NULL);
BLI_kdtree_insert(tree, p, co);
}
BLI_kdtree_balance(tree);
@@ -785,9 +785,10 @@ static DerivedMesh *cutEdges(ExplodeModifierData *emd, DerivedMesh *dm)
return splitdm;
}
-static DerivedMesh *explodeMesh(ExplodeModifierData *emd,
- ParticleSystemModifierData *psmd, Scene *scene, Object *ob,
- DerivedMesh *to_explode)
+static DerivedMesh *explodeMesh(
+ ExplodeModifierData *emd,
+ ParticleSystemModifierData *psmd, const ModifierEvalContext *ctx, Scene *scene,
+ DerivedMesh *to_explode)
{
DerivedMesh *explode, *dm = to_explode;
MFace *mf = NULL, *mface;
@@ -812,8 +813,9 @@ static DerivedMesh *explodeMesh(ExplodeModifierData *emd,
mface = dm->getTessFaceArray(dm);
totpart = psmd->psys->totpart;
+ sim.depsgraph = ctx->depsgraph;
sim.scene = scene;
- sim.ob = ob;
+ sim.ob = ctx->object;
sim.psys = psmd->psys;
sim.psmd = psmd;
@@ -868,7 +870,7 @@ static DerivedMesh *explodeMesh(ExplodeModifierData *emd,
/*dupvert = CDDM_get_verts(explode);*/
/* getting back to object space */
- invert_m4_m4(imat, ob->obmat);
+ invert_m4_m4(imat, ctx->object->obmat);
psmd->psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
@@ -899,7 +901,7 @@ static DerivedMesh *explodeMesh(ExplodeModifierData *emd,
psys_get_particle_state(&sim, ed_v2, &state, 1);
vertco = CDDM_get_vert(explode, v)->co;
- mul_m4_v3(ob->obmat, vertco);
+ mul_m4_v3(ctx->object->obmat, vertco);
sub_v3_v3(vertco, birth.co);
@@ -993,13 +995,12 @@ static ParticleSystemModifierData *findPrecedingParticlesystem(Object *ob, Modif
}
return psmd;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
DerivedMesh *dm = derivedData;
ExplodeModifierData *emd = (ExplodeModifierData *) md;
- ParticleSystemModifierData *psmd = findPrecedingParticlesystem(ob, md);
+ ParticleSystemModifierData *psmd = findPrecedingParticlesystem(ctx->object, md);
if (psmd) {
ParticleSystem *psys = psmd->psys;
@@ -1028,7 +1029,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
if (emd->flag & eExplodeFlag_EdgeCut) {
int *facepa = emd->facepa;
DerivedMesh *splitdm = cutEdges(emd, dm);
- DerivedMesh *explode = explodeMesh(emd, psmd, md->scene, ob, splitdm);
+ DerivedMesh *explode = explodeMesh(emd, psmd, ctx, md->scene, splitdm);
MEM_freeN(emd->facepa);
emd->facepa = facepa;
@@ -1036,7 +1037,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
return explode;
}
else
- return explodeMesh(emd, psmd, md->scene, ob, derivedData);
+ return explodeMesh(emd, psmd, ctx, md->scene, derivedData);
}
return derivedData;
}
@@ -1049,17 +1050,25 @@ ModifierTypeInfo modifierType_Explode = {
/* type */ eModifierTypeType_Constructive,
/* flags */ eModifierTypeFlag_AcceptsMesh,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_fluidsim.c b/source/blender/modifiers/intern/MOD_fluidsim.c
index 37eabdf2425..7014861bc12 100644
--- a/source/blender/modifiers/intern/MOD_fluidsim.c
+++ b/source/blender/modifiers/intern/MOD_fluidsim.c
@@ -41,9 +41,9 @@
#include "BKE_cdderivedmesh.h"
+#include "BKE_layer.h"
#include "BKE_modifier.h"
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MOD_fluidsim_util.h"
@@ -82,9 +82,8 @@ static void copyData(ModifierData *md, ModifierData *target)
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag flag)
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
FluidsimModifierData *fluidmd = (FluidsimModifierData *) md;
DerivedMesh *result = NULL;
@@ -98,43 +97,19 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
}
}
- result = fluidsimModifier_do(fluidmd, md->scene, ob, dm, flag & MOD_APPLY_RENDER, flag & MOD_APPLY_USECACHE);
+ result = fluidsimModifier_do(fluidmd, md->scene, ctx->object, dm,
+ ctx->flag & MOD_APPLY_RENDER, ctx->flag & MOD_APPLY_USECACHE);
return result ? result : dm;
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- FluidsimModifierData *fluidmd = (FluidsimModifierData *) md;
- Base *base;
-
- if (fluidmd && fluidmd->fss) {
- if (fluidmd->fss->type == OB_FLUIDSIM_DOMAIN) {
- for (base = ctx->scene->base.first; base; base = base->next) {
- Object *ob1 = base->object;
- if (ob1 != ctx->object) {
- FluidsimModifierData *fluidmdtmp =
- (FluidsimModifierData *)modifiers_findByType(ob1, eModifierType_Fluidsim);
-
- /* only put dependencies from NON-DOMAIN fluids in here */
- if (fluidmdtmp && fluidmdtmp->fss && (fluidmdtmp->fss->type != OB_FLUIDSIM_DOMAIN)) {
- DagNode *curNode = dag_get_node(ctx->forest, ob1);
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Fluidsim Object");
- }
- }
- }
- }
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
FluidsimModifierData *fluidmd = (FluidsimModifierData *) md;
if (fluidmd && fluidmd->fss) {
if (fluidmd->fss->type == OB_FLUIDSIM_DOMAIN) {
- Base *base;
- for (base = ctx->scene->base.first; base; base = base->next) {
- Object *ob1 = base->object;
+ FOREACH_SCENE_OBJECT_BEGIN(ctx->scene, ob1)
+ {
if (ob1 != ctx->object) {
FluidsimModifierData *fluidmdtmp =
(FluidsimModifierData *)modifiers_findByType(ob1, eModifierType_Fluidsim);
@@ -145,6 +120,7 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
}
}
+ FOREACH_SCENE_OBJECT_END;
}
}
}
@@ -166,17 +142,25 @@ ModifierTypeInfo modifierType_Fluidsim = {
eModifierTypeFlag_Single,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_hook.c b/source/blender/modifiers/intern/MOD_hook.c
index 80c029157f7..7e7d43cdf20 100644
--- a/source/blender/modifiers/intern/MOD_hook.c
+++ b/source/blender/modifiers/intern/MOD_hook.c
@@ -46,8 +46,6 @@
#include "BKE_deform.h"
#include "BKE_colortools.h"
-
-#include "depsgraph_private.h"
#include "MEM_guardedalloc.h"
#include "MOD_util.h"
@@ -118,20 +116,6 @@ static void foreachObjectLink(
walk(userData, ob, &hmd->object, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- HookModifierData *hmd = (HookModifierData *) md;
-
- if (hmd->object) {
- DagNode *curNode = dag_get_node(ctx->forest, hmd->object);
-
- if (hmd->subtarget[0])
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Hook Modifier");
- else
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_OB_DATA, "Hook Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
HookModifierData *hmd = (HookModifierData *)md;
@@ -368,32 +352,31 @@ static void deformVerts_do(HookModifierData *hmd, Object *ob, DerivedMesh *dm,
}
}
-static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts,
- ModifierApplyFlag UNUSED(flag))
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts)
{
HookModifierData *hmd = (HookModifierData *) md;
DerivedMesh *dm = derivedData;
/* We need a valid dm for meshes when a vgroup is set... */
- if (!dm && ob->type == OB_MESH && hmd->name[0] != '\0')
- dm = get_dm(ob, NULL, dm, NULL, false, false);
+ if (!dm && ctx->object->type == OB_MESH && hmd->name[0] != '\0')
+ dm = get_dm(ctx->object, NULL, dm, NULL, false, false);
- deformVerts_do(hmd, ob, dm, vertexCos, numVerts);
+ deformVerts_do(hmd, ctx->object, dm, vertexCos, numVerts);
if (derivedData != dm)
dm->release(dm);
}
-static void deformVertsEM(ModifierData *md, Object *ob, struct BMEditMesh *editData,
+static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
HookModifierData *hmd = (HookModifierData *) md;
DerivedMesh *dm = derivedData;
/* We need a valid dm for meshes when a vgroup is set... */
- if (!dm && ob->type == OB_MESH && hmd->name[0] != '\0')
- dm = get_dm(ob, editData, dm, NULL, false, false);
+ if (!dm && ctx->object->type == OB_MESH && hmd->name[0] != '\0')
+ dm = get_dm(ctx->object, editData, dm, NULL, false, false);
- deformVerts_do(hmd, ob, dm, vertexCos, numVerts);
+ deformVerts_do(hmd, ctx->object, dm, vertexCos, numVerts);
if (derivedData != dm)
dm->release(dm);
@@ -409,17 +392,25 @@ ModifierTypeInfo modifierType_Hook = {
eModifierTypeFlag_AcceptsLattice |
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_laplaciandeform.c b/source/blender/modifiers/intern/MOD_laplaciandeform.c
index 91d41a6badd..ac39f4696ea 100644
--- a/source/blender/modifiers/intern/MOD_laplaciandeform.c
+++ b/source/blender/modifiers/intern/MOD_laplaciandeform.c
@@ -724,23 +724,23 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
-static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag))
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
- LaplacianDeformModifier_do((LaplacianDeformModifierData *)md, ob, dm, vertexCos, numVerts);
+ LaplacianDeformModifier_do((LaplacianDeformModifierData *)md, ctx->object, dm, vertexCos, numVerts);
if (dm != derivedData) {
dm->release(dm);
}
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false);
- LaplacianDeformModifier_do((LaplacianDeformModifierData *)md, ob, dm,
+ DerivedMesh *dm = get_dm(ctx->object, editData, derivedData, NULL, false, false);
+ LaplacianDeformModifier_do((LaplacianDeformModifierData *)md, ctx->object, dm,
vertexCos, numVerts);
if (dm != derivedData) {
dm->release(dm);
@@ -765,17 +765,25 @@ ModifierTypeInfo modifierType_LaplacianDeform = {
/* type */ eModifierTypeType_OnlyDeform,
/* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_laplaciansmooth.c b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
index b3a542f68b7..3b63a3ef5f8 100644
--- a/source/blender/modifiers/intern/MOD_laplaciansmooth.c
+++ b/source/blender/modifiers/intern/MOD_laplaciansmooth.c
@@ -506,17 +506,17 @@ static CustomDataMask required_data_mask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
-static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag))
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm;
if (numVerts == 0)
return;
- dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
- laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ob, dm,
+ laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ctx->object, dm,
vertexCos, numVerts);
if (dm != derivedData)
@@ -524,7 +524,7 @@ static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm;
@@ -532,9 +532,9 @@ static void deformVertsEM(
if (numVerts == 0)
return;
- dm = get_dm(ob, editData, derivedData, NULL, false, false);
+ dm = get_dm(ctx->object, editData, derivedData, NULL, false, false);
- laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ob, dm,
+ laplaciansmoothModifier_do((LaplacianSmoothModifierData *)md, ctx->object, dm,
vertexCos, numVerts);
if (dm != derivedData)
@@ -551,17 +551,25 @@ ModifierTypeInfo modifierType_LaplacianSmooth = {
eModifierTypeFlag_SupportsEditmode,
/* copy_data */ copy_data,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ init_data,
/* requiredDataMask */ required_data_mask,
/* freeData */ NULL,
/* isDisabled */ is_disabled,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_lattice.c b/source/blender/modifiers/intern/MOD_lattice.c
index 0df6329cf04..87933558d86 100644
--- a/source/blender/modifiers/intern/MOD_lattice.c
+++ b/source/blender/modifiers/intern/MOD_lattice.c
@@ -39,12 +39,14 @@
#include "BLI_utildefines.h"
-#include "BKE_cdderivedmesh.h"
+#include "BKE_editmesh.h"
#include "BKE_lattice.h"
+#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
-#include "depsgraph_private.h"
+#include "MEM_guardedalloc.h"
#include "MOD_util.h"
@@ -91,18 +93,6 @@ static void foreachObjectLink(
walk(userData, ob, &lmd->object, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- LatticeModifierData *lmd = (LatticeModifierData *) md;
-
- if (lmd->object) {
- DagNode *latNode = dag_get_node(ctx->forest, lmd->object);
-
- dag_add_relation(ctx->forest, latNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Lattice Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
LatticeModifierData *lmd = (LatticeModifierData *)md;
@@ -113,32 +103,35 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Lattice Modifier");
}
-static void deformVerts(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
+ struct Mesh *mesh,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
LatticeModifierData *lmd = (LatticeModifierData *) md;
modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
-
- lattice_deform_verts(lmd->object, ob, derivedData,
+
+ lattice_deform_verts(lmd->object, ctx->object, mesh,
vertexCos, numVerts, lmd->name, lmd->strength);
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *em,
- DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
+ struct Mesh *mesh, float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = derivedData;
+ struct Mesh *mesh_src = mesh;
- if (!derivedData) dm = CDDM_from_editbmesh(em, false, false);
+ if (!mesh) {
+ mesh_src = BKE_bmesh_to_mesh(em->bm, &(struct BMeshToMeshParams){0});
+ }
- deformVerts(md, ob, dm, vertexCos, numVerts, 0);
+ deformVerts(md, ctx, mesh_src, vertexCos, numVerts);
- if (!derivedData) dm->release(dm);
+ if (!mesh) {
+ BKE_id_free(NULL, mesh_src);
+ }
}
@@ -151,17 +144,25 @@ ModifierTypeInfo modifierType_Lattice = {
eModifierTypeFlag_AcceptsLattice |
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ deformVerts,
/* deformMatrices */ NULL,
/* deformVertsEM */ deformVertsEM,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_mask.c b/source/blender/modifiers/intern/MOD_mask.c
index 351e7116d49..a94f0ecff02 100644
--- a/source/blender/modifiers/intern/MOD_mask.c
+++ b/source/blender/modifiers/intern/MOD_mask.c
@@ -50,7 +50,6 @@
#include "BKE_modifier.h"
#include "BKE_deform.h"
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
@@ -79,20 +78,6 @@ static void foreachObjectLink(
walk(userData, ob, &mmd->ob_arm, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- MaskModifierData *mmd = (MaskModifierData *)md;
-
- if (mmd->ob_arm) {
- bArmature *arm = (bArmature *)mmd->ob_arm->data;
- DagNode *armNode = dag_get_node(ctx->forest, mmd->ob_arm);
-
- /* tag relationship in depsgraph, but also on the armature */
- dag_add_relation(ctx->forest, armNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Mask Modifier");
- arm->flag |= ARM_HAS_VIZ_DEPS;
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
MaskModifierData *mmd = (MaskModifierData *)md;
@@ -105,11 +90,11 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
MaskModifierData *mmd = (MaskModifierData *)md;
+ Object *ob = ctx->object;
const bool found_test = (mmd->flag & MOD_MASK_INV) == 0;
DerivedMesh *result = NULL;
GHash *vertHash = NULL, *edgeHash, *polyHash;
@@ -385,17 +370,25 @@ ModifierTypeInfo modifierType_Mask = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ NULL,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_meshcache.c b/source/blender/modifiers/intern/MOD_meshcache.c
index e026d4da29a..4eb37a4953c 100644
--- a/source/blender/modifiers/intern/MOD_meshcache.c
+++ b/source/blender/modifiers/intern/MOD_meshcache.c
@@ -272,24 +272,23 @@ static void meshcache_do(
}
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
- meshcache_do(mcmd, ob, derivedData, vertexCos, numVerts);
+ meshcache_do(mcmd, ctx->object, derivedData, vertexCos, numVerts);
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *UNUSED(editData),
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *UNUSED(editData),
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
MeshCacheModifierData *mcmd = (MeshCacheModifierData *)md;
- meshcache_do(mcmd, ob, derivedData, vertexCos, numVerts);
+ meshcache_do(mcmd, ctx->object, derivedData, vertexCos, numVerts);
}
@@ -303,17 +302,25 @@ ModifierTypeInfo modifierType_MeshCache = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_meshdeform.c b/source/blender/modifiers/intern/MOD_meshdeform.c
index c125495a234..8b25d192f7f 100644
--- a/source/blender/modifiers/intern/MOD_meshdeform.c
+++ b/source/blender/modifiers/intern/MOD_meshdeform.c
@@ -47,10 +47,10 @@
#include "BKE_deform.h"
#include "BKE_editmesh.h"
-#include "depsgraph_private.h"
-
#include "MEM_guardedalloc.h"
+#include "DEG_depsgraph.h"
+
#include "MOD_util.h"
#ifdef __SSE2__
@@ -122,19 +122,6 @@ static void foreachObjectLink(
walk(userData, ob, &mmd->object, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- MeshDeformModifierData *mmd = (MeshDeformModifierData *) md;
-
- if (mmd->object) {
- DagNode *curNode = dag_get_node(ctx->forest, mmd->object);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA | DAG_RL_DATA_OB | DAG_RL_OB_OB,
- "Mesh Deform Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
MeshDeformModifierData *mmd = (MeshDeformModifierData *)md;
@@ -286,7 +273,7 @@ static void meshdeform_vert_task(
}
static void meshdeformModifier_do(
- ModifierData *md, Object *ob, DerivedMesh *dm,
+ ModifierData *md, struct Depsgraph *depsgraph, Object *ob, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
MeshDeformModifierData *mmd = (MeshDeformModifierData *) md;
@@ -311,9 +298,9 @@ static void meshdeformModifier_do(
*
* We'll support this case once granular dependency graph is landed.
*/
- if (mmd->object == md->scene->obedit) {
+ if (mmd->object->mode & OB_MODE_EDIT) {
BMEditMesh *em = BKE_editmesh_from_object(mmd->object);
- tmpdm = editbmesh_get_derived_cage_and_final(md->scene, mmd->object, em, 0, &cagedm);
+ tmpdm = editbmesh_get_derived_cage_and_final(depsgraph, md->scene, mmd->object, em, 0, &cagedm);
if (tmpdm)
tmpdm->release(tmpdm);
}
@@ -422,31 +409,30 @@ static void meshdeformModifier_do(
cagedm->release(cagedm);
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
- DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
modifier_vgroup_cache(md, vertexCos); /* if next modifier needs original vertices */
- meshdeformModifier_do(md, ob, dm, vertexCos, numVerts);
+ meshdeformModifier_do(md, ctx->depsgraph, ctx->object, dm, vertexCos, numVerts);
if (dm && dm != derivedData)
dm->release(dm);
}
-static void deformVertsEM(ModifierData *md, Object *ob,
+static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx,
struct BMEditMesh *UNUSED(editData),
DerivedMesh *derivedData,
float (*vertexCos)[3],
int numVerts)
{
- DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
- meshdeformModifier_do(md, ob, dm, vertexCos, numVerts);
+ meshdeformModifier_do(md, ctx->depsgraph, ctx->object, dm, vertexCos, numVerts);
if (dm && dm != derivedData)
dm->release(dm);
@@ -525,17 +511,25 @@ ModifierTypeInfo modifierType_MeshDeform = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_meshsequencecache.c b/source/blender/modifiers/intern/MOD_meshsequencecache.c
index 04de6fae336..8ca5873f85c 100644
--- a/source/blender/modifiers/intern/MOD_meshsequencecache.c
+++ b/source/blender/modifiers/intern/MOD_meshsequencecache.c
@@ -37,7 +37,6 @@
#include "BKE_library_query.h"
#include "BKE_scene.h"
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
@@ -91,15 +90,14 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
return (mcmd->cache_file == NULL) || (mcmd->object_path[0] == '\0');
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
#ifdef WITH_ALEMBIC
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;
/* Only used to check whether we are operating on org data or not... */
- Mesh *me = (ob->type == OB_MESH) ? ob->data : NULL;
+ Mesh *me = (ctx->object->type == OB_MESH) ? ctx->object->data : NULL;
DerivedMesh *org_dm = dm;
Scene *scene = md->scene;
@@ -114,7 +112,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
if (!mcmd->reader) {
mcmd->reader = CacheReader_open_alembic_object(cache_file->handle,
NULL,
- ob,
+ ctx->object,
mcmd->object_path);
if (!mcmd->reader) {
modifier_setError(md, "Could not create Alembic reader for file %s", cache_file->filepath);
@@ -133,7 +131,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
}
DerivedMesh *result = ABC_read_mesh(mcmd->reader,
- ob,
+ ctx->object,
dm,
time,
&err_str,
@@ -151,7 +149,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
return result ? result : dm;
#else
return dm;
- UNUSED_VARS(md, ob);
+ UNUSED_VARS(ctx, md);
#endif
}
@@ -170,18 +168,6 @@ static void foreachIDLink(ModifierData *md, Object *ob,
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;
-
- if (mcmd->cache_file != NULL) {
- DagNode *curNode = dag_get_node(ctx->forest, mcmd->cache_file);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Cache File Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
MeshSeqCacheModifierData *mcmd = (MeshSeqCacheModifierData *) md;
@@ -192,28 +178,37 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
ModifierTypeInfo modifierType_MeshSequenceCache = {
- /* name */ "Mesh Sequence Cache",
- /* structName */ "MeshSeqCacheModifierData",
- /* structSize */ sizeof(MeshSeqCacheModifierData),
- /* type */ eModifierTypeType_Constructive,
- /* flags */ eModifierTypeFlag_AcceptsMesh |
- eModifierTypeFlag_AcceptsCVs,
- /* copyData */ copyData,
- /* deformVerts */ NULL,
- /* deformMatrices */ NULL,
- /* deformVertsEM */ NULL,
- /* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
- /* applyModifierEM */ NULL,
- /* initData */ initData,
- /* requiredDataMask */ NULL,
- /* freeData */ freeData,
- /* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
- /* updateDepsgraph */ updateDepsgraph,
- /* dependsOnTime */ dependsOnTime,
- /* dependsOnNormals */ NULL,
- /* foreachObjectLink */ NULL,
- /* foreachIDLink */ foreachIDLink,
- /* foreachTexLink */ NULL,
+ /* name */ "Mesh Sequence Cache",
+ /* structName */ "MeshSeqCacheModifierData",
+ /* structSize */ sizeof(MeshSeqCacheModifierData),
+ /* type */ eModifierTypeType_Constructive,
+ /* flags */ eModifierTypeFlag_AcceptsMesh |
+ eModifierTypeFlag_AcceptsCVs,
+
+ /* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
+ /* deformMatrices */ NULL,
+ /* deformVertsEM */ NULL,
+ /* deformMatricesEM */ NULL,
+ /* applyModifier */ NULL,
+ /* applyModifierEM */ NULL,
+
+ /* initData */ initData,
+ /* requiredDataMask */ NULL,
+ /* freeData */ freeData,
+ /* isDisabled */ isDisabled,
+ /* updateDepsgraph */ updateDepsgraph,
+ /* dependsOnTime */ dependsOnTime,
+ /* dependsOnNormals */ NULL,
+ /* foreachObjectLink */ NULL,
+ /* foreachIDLink */ foreachIDLink,
+ /* foreachTexLink */ NULL,
};
diff --git a/source/blender/modifiers/intern/MOD_mirror.c b/source/blender/modifiers/intern/MOD_mirror.c
index 875a1e8d468..4edfbd43d7a 100644
--- a/source/blender/modifiers/intern/MOD_mirror.c
+++ b/source/blender/modifiers/intern/MOD_mirror.c
@@ -33,19 +33,20 @@
*/
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "BLI_math.h"
-#include "BKE_cdderivedmesh.h"
+#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_mesh.h"
#include "BKE_modifier.h"
#include "BKE_deform.h"
#include "MEM_guardedalloc.h"
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
@@ -77,17 +78,6 @@ static void foreachObjectLink(
walk(userData, ob, &mmd->mirror_ob, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- MirrorModifierData *mmd = (MirrorModifierData *) md;
-
- if (mmd->mirror_ob) {
- DagNode *latNode = dag_get_node(ctx->forest, mmd->mirror_ob);
-
- dag_add_relation(ctx->forest, latNode, ctx->obNode, DAG_RL_OB_DATA, "Mirror Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
MirrorModifierData *mmd = (MirrorModifierData *)md;
@@ -97,20 +87,20 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
DEG_add_object_relation(ctx->node, ctx->object, DEG_OB_COMP_TRANSFORM, "Mirror Modifier");
}
-static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
- Object *ob,
- DerivedMesh *dm,
- int axis)
+static Mesh *doMirrorOnAxis(MirrorModifierData *mmd,
+ Object *ob,
+ const Mesh *mesh,
+ int axis)
{
const float tolerance_sq = mmd->tolerance * mmd->tolerance;
const bool do_vtargetmap = (mmd->flag & MOD_MIR_NO_MERGE) == 0;
int tot_vtargetmap = 0; /* total merge vertices */
- DerivedMesh *result;
- const int maxVerts = dm->getNumVerts(dm);
- const int maxEdges = dm->getNumEdges(dm);
- const int maxLoops = dm->getNumLoops(dm);
- const int maxPolys = dm->getNumPolys(dm);
+ Mesh *result;
+ const int maxVerts = mesh->totvert;
+ const int maxEdges = mesh->totedge;
+ const int maxLoops = mesh->totloop;
+ const int maxPolys = mesh->totpoly;
MVert *mv, *mv_prev;
MEdge *me;
MLoop *ml;
@@ -143,35 +133,33 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
mul_m4_m4m4(mtx, itmp, mtx);
}
- result = CDDM_from_template(dm, maxVerts * 2, maxEdges * 2, 0, maxLoops * 2, maxPolys * 2);
+ result = BKE_mesh_from_template(mesh, maxVerts * 2, maxEdges * 2, 0, maxLoops * 2, maxPolys * 2);
/*copy customdata to original geometry*/
- DM_copy_vert_data(dm, result, 0, 0, maxVerts);
- DM_copy_edge_data(dm, result, 0, 0, maxEdges);
- DM_copy_loop_data(dm, result, 0, 0, maxLoops);
- DM_copy_poly_data(dm, result, 0, 0, maxPolys);
-
+ CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, maxVerts);
+ CustomData_copy_data(&mesh->edata, &result->edata, 0, 0, maxEdges);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, 0, 0, maxLoops);
+ CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, maxPolys);
/* Subsurf for eg wont have mesh data in the custom data arrays.
* now add mvert/medge/mpoly layers. */
-
- if (!CustomData_has_layer(&dm->vertData, CD_MVERT)) {
- dm->copyVertArray(dm, CDDM_get_verts(result));
+ if (!CustomData_has_layer(&mesh->vdata, CD_MVERT)) {
+ memcpy(result->mvert, mesh->mvert, sizeof(*result->mvert) * mesh->totvert);
}
- if (!CustomData_has_layer(&dm->edgeData, CD_MEDGE)) {
- dm->copyEdgeArray(dm, CDDM_get_edges(result));
+ if (!CustomData_has_layer(&mesh->edata, CD_MEDGE)) {
+ memcpy(result->medge, mesh->medge, sizeof(*result->medge) * mesh->totedge);
}
- if (!CustomData_has_layer(&dm->polyData, CD_MPOLY)) {
- dm->copyLoopArray(dm, CDDM_get_loops(result));
- dm->copyPolyArray(dm, CDDM_get_polys(result));
+ if (!CustomData_has_layer(&mesh->pdata, CD_MPOLY)) {
+ memcpy(result->mloop, mesh->mloop, sizeof(*result->mloop) * mesh->totloop);
+ memcpy(result->mpoly, mesh->mpoly, sizeof(*result->mpoly) * mesh->totpoly);
}
/* copy customdata to new geometry,
* copy from its self because this data may have been created in the checks above */
- DM_copy_vert_data(result, result, 0, maxVerts, maxVerts);
- DM_copy_edge_data(result, result, 0, maxEdges, maxEdges);
+ CustomData_copy_data(&result->vdata, &result->vdata, 0, maxVerts, maxVerts);
+ CustomData_copy_data(&result->edata, &result->edata, 0, maxEdges, maxEdges);
/* loops are copied later */
- DM_copy_poly_data(result, result, 0, maxPolys, maxPolys);
+ CustomData_copy_data(&result->pdata, &result->pdata, 0, maxPolys, maxPolys);
if (do_vtargetmap) {
/* second half is filled with -1 */
@@ -182,7 +170,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
}
/* mirror vertex coordinates */
- mv_prev = CDDM_get_verts(result);
+ mv_prev = result->mvert;
mv = mv_prev + maxVerts;
for (i = 0; i < maxVerts; i++, mv++, mv_prev++) {
mul_m4_v3(mtx, mv->co);
@@ -210,33 +198,37 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
}
/* handle shape keys */
- totshape = CustomData_number_of_layers(&result->vertData, CD_SHAPEKEY);
+ totshape = CustomData_number_of_layers(&result->vdata, CD_SHAPEKEY);
for (a = 0; a < totshape; a++) {
- float (*cos)[3] = CustomData_get_layer_n(&result->vertData, CD_SHAPEKEY, a);
- for (i = maxVerts; i < result->numVertData; i++) {
+ float (*cos)[3] = CustomData_get_layer_n(&result->vdata, CD_SHAPEKEY, a);
+ for (i = maxVerts; i < result->totvert; i++) {
mul_m4_v3(mtx, cos[i]);
}
}
/* adjust mirrored edge vertex indices */
- me = CDDM_get_edges(result) + maxEdges;
+ me = result->medge + maxEdges;
for (i = 0; i < maxEdges; i++, me++) {
me->v1 += maxVerts;
me->v2 += maxVerts;
}
/* adjust mirrored poly loopstart indices, and reverse loop order (normals) */
- mp = CDDM_get_polys(result) + maxPolys;
- ml = CDDM_get_loops(result);
+ mp = result->mpoly + maxPolys;
+ ml = result->mloop;
for (i = 0; i < maxPolys; i++, mp++) {
MLoop *ml2;
int j, e;
/* reverse the loop, but we keep the first vertex in the face the same,
* to ensure that quads are split the same way as on the other side */
- DM_copy_loop_data(result, result, mp->loopstart, mp->loopstart + maxLoops, 1);
+ CustomData_copy_data(&result->ldata, &result->ldata, mp->loopstart, mp->loopstart + maxLoops, 1);
+
for (j = 1; j < mp->totloop; j++)
- DM_copy_loop_data(result, result, mp->loopstart + j, mp->loopstart + maxLoops + mp->totloop - j, 1);
+ CustomData_copy_data(&result->ldata, &result->ldata,
+ mp->loopstart + j,
+ mp->loopstart + maxLoops + mp->totloop - j,
+ 1);
ml2 = ml + mp->loopstart + maxLoops;
e = ml2[0].e;
@@ -249,7 +241,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
}
/* adjust mirrored loop vertex and edge indices */
- ml = CDDM_get_loops(result) + maxLoops;
+ ml = result->mloop + maxLoops;
for (i = 0; i < maxLoops; i++, ml++) {
ml->v += maxVerts;
ml->e += maxEdges;
@@ -261,10 +253,10 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
const bool do_mirr_u = (mmd->flag & MOD_MIR_MIRROR_U) != 0;
const bool do_mirr_v = (mmd->flag & MOD_MIR_MIRROR_V) != 0;
- const int totuv = CustomData_number_of_layers(&result->loopData, CD_MLOOPUV);
+ const int totuv = CustomData_number_of_layers(&result->ldata, CD_MLOOPUV);
for (a = 0; a < totuv; a++) {
- MLoopUV *dmloopuv = CustomData_get_layer_n(&result->loopData, CD_MLOOPUV, a);
+ MLoopUV *dmloopuv = CustomData_get_layer_n(&result->ldata, CD_MLOOPUV, a);
int j = maxLoops;
dmloopuv += j; /* second set of loops only */
for (; j-- > 0; dmloopuv++) {
@@ -277,8 +269,8 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
}
/* handle vgroup stuff */
- if ((mmd->flag & MOD_MIR_VGROUP) && CustomData_has_layer(&result->vertData, CD_MDEFORMVERT)) {
- MDeformVert *dvert = (MDeformVert *) CustomData_get_layer(&result->vertData, CD_MDEFORMVERT) + maxVerts;
+ if ((mmd->flag & MOD_MIR_VGROUP) && CustomData_has_layer(&result->vdata, CD_MDEFORMVERT)) {
+ MDeformVert *dvert = (MDeformVert *) CustomData_get_layer(&result->vdata, CD_MDEFORMVERT) + maxVerts;
int *flip_map = NULL, flip_map_len = 0;
flip_map = defgroup_flip_map(ob, &flip_map_len, false);
@@ -300,7 +292,7 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
/* slow - so only call if one or more merge verts are found,
* users may leave this on and not realize there is nothing to merge - campbell */
if (tot_vtargetmap) {
- result = CDDM_merge_verts(result, vtargetmap, tot_vtargetmap, CDDM_MERGE_VERTS_DUMP_IF_MAPPED);
+ result = BKE_mesh_merge_verts(result, vtargetmap, tot_vtargetmap, MESH_MERGE_VERTS_DUMP_IF_MAPPED);
}
MEM_freeN(vtargetmap);
}
@@ -308,41 +300,46 @@ static DerivedMesh *doMirrorOnAxis(MirrorModifierData *mmd,
return result;
}
-static DerivedMesh *mirrorModifier__doMirror(MirrorModifierData *mmd,
- Object *ob, DerivedMesh *dm)
+static Mesh *mirrorModifier__doMirror(MirrorModifierData *mmd,
+ Object *ob, Mesh *mesh)
{
- DerivedMesh *result = dm;
+ Mesh *result = mesh;
/* check which axes have been toggled and mirror accordingly */
if (mmd->flag & MOD_MIR_AXIS_X) {
result = doMirrorOnAxis(mmd, ob, result, 0);
}
if (mmd->flag & MOD_MIR_AXIS_Y) {
- DerivedMesh *tmp = result;
+ Mesh *tmp = result;
result = doMirrorOnAxis(mmd, ob, result, 1);
- if (tmp != dm) tmp->release(tmp); /* free intermediate results */
+ if (tmp != mesh) {
+ /* free intermediate results */
+ BKE_id_free(NULL, tmp);
+ }
}
if (mmd->flag & MOD_MIR_AXIS_Z) {
- DerivedMesh *tmp = result;
+ Mesh *tmp = result;
result = doMirrorOnAxis(mmd, ob, result, 2);
- if (tmp != dm) tmp->release(tmp); /* free intermediate results */
+ if (tmp != mesh) {
+ /* free intermediate results */
+ BKE_id_free(NULL, tmp);
+ }
}
return result;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ Mesh *mesh)
{
- DerivedMesh *result;
+ Mesh *result;
MirrorModifierData *mmd = (MirrorModifierData *) md;
- result = mirrorModifier__doMirror(mmd, ob, derivedData);
+ result = mirrorModifier__doMirror(mmd, ctx->object, mesh);
- if (result != derivedData)
- result->dirty |= DM_DIRTY_NORMALS;
-
+ if (result != mesh) {
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
+ }
return result;
}
@@ -361,17 +358,25 @@ ModifierTypeInfo modifierType_Mirror = {
eModifierTypeFlag_UsesPreview,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_multires.c b/source/blender/modifiers/intern/MOD_multires.c
index f9f17b88fa4..32b15f11116 100644
--- a/source/blender/modifiers/intern/MOD_multires.c
+++ b/source/blender/modifiers/intern/MOD_multires.c
@@ -67,14 +67,14 @@ static void copyData(ModifierData *md, ModifierData *target)
modifier_copyData_generic(md, target);
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
- ModifierApplyFlag flag)
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
MultiresModifierData *mmd = (MultiresModifierData *)md;
DerivedMesh *result;
- Mesh *me = (Mesh *)ob->data;
- const bool useRenderParams = (flag & MOD_APPLY_RENDER) != 0;
- const bool ignore_simplify = (flag & MOD_APPLY_IGNORE_SIMPLIFY) != 0;
+ Mesh *me = (Mesh *)ctx->object->data;
+ const bool useRenderParams = (ctx->flag & MOD_APPLY_RENDER) != 0;
+ const bool ignore_simplify = (ctx->flag & MOD_APPLY_IGNORE_SIMPLIFY) != 0;
MultiresFlags flags = 0;
const bool has_mask = CustomData_has_layer(&me->ldata, CD_GRID_PAINT_MASK);
@@ -94,12 +94,12 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm,
if (ignore_simplify)
flags |= MULTIRES_IGNORE_SIMPLIFY;
- result = multires_make_derived_from_derived(dm, mmd, ob, flags);
+ result = multires_make_derived_from_derived(dm, mmd, ctx->object, flags);
if (result == dm)
return dm;
- if (useRenderParams || !(flag & MOD_APPLY_USECACHE)) {
+ if (useRenderParams || !(ctx->flag & MOD_APPLY_USECACHE)) {
DerivedMesh *cddm;
cddm = CDDM_copy(result);
@@ -153,17 +153,25 @@ ModifierTypeInfo modifierType_Multires = {
eModifierTypeFlag_RequiresOriginalData,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_none.c b/source/blender/modifiers/intern/MOD_none.c
index d9d9ba2966d..b22b1768515 100644
--- a/source/blender/modifiers/intern/MOD_none.c
+++ b/source/blender/modifiers/intern/MOD_none.c
@@ -57,17 +57,25 @@ ModifierTypeInfo modifierType_None = {
eModifierTypeFlag_AcceptsCVs,
/* copyData */ NULL,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ NULL,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_normal_edit.c b/source/blender/modifiers/intern/MOD_normal_edit.c
index 0b703fffda3..7f080a0bd20 100644
--- a/source/blender/modifiers/intern/MOD_normal_edit.c
+++ b/source/blender/modifiers/intern/MOD_normal_edit.c
@@ -38,17 +38,16 @@
#include "BLI_bitmap.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_mesh.h"
#include "BKE_deform.h"
-#include "depsgraph_private.h"
-
#include "MOD_util.h"
static void generate_vert_coordinates(
- DerivedMesh *dm, Object *ob, Object *ob_center, const float offset[3],
+ Mesh *mesh, Object *ob, Object *ob_center, const float offset[3],
const int num_verts, float (*r_cos)[3], float r_size[3])
{
float min_co[3], max_co[3];
@@ -57,30 +56,37 @@ static void generate_vert_coordinates(
INIT_MINMAX(min_co, max_co);
- dm->getVertCos(dm, r_cos);
+ MVert *mv = mesh->mvert;
+ for (int i = 0; i < mesh->totvert; i++, mv++) {
+ copy_v3_v3(r_cos[i], mv->co);
+ if (r_size != NULL && ob_center == NULL) {
+ minmax_v3v3_v3(min_co, max_co, r_cos[i]);
+ }
+ }
/* Get size (i.e. deformation of the spheroid generating normals), either from target object, or own geometry. */
- if (ob_center) {
- /* Not we are not interested in signs here - they are even troublesome actually, due to security clamping! */
- abs_v3_v3(r_size, ob_center->size);
- }
- else {
- minmax_v3v3_v3_array(min_co, max_co, r_cos, num_verts);
- /* Set size. */
- sub_v3_v3v3(r_size, max_co, min_co);
- }
+ if (r_size != NULL) {
+ if (ob_center != NULL) {
+ /* Not we are not interested in signs here - they are even troublesome actually, due to security clamping! */
+ abs_v3_v3(r_size, ob_center->size);
+ }
+ else {
+ /* Set size. */
+ sub_v3_v3v3(r_size, max_co, min_co);
+ }
- /* Error checks - we do not want one or more of our sizes to be null! */
- if (is_zero_v3(r_size)) {
- r_size[0] = r_size[1] = r_size[2] = 1.0f;
- }
- else {
- CLAMP_MIN(r_size[0], FLT_EPSILON);
- CLAMP_MIN(r_size[1], FLT_EPSILON);
- CLAMP_MIN(r_size[2], FLT_EPSILON);
+ /* Error checks - we do not want one or more of our sizes to be null! */
+ if (is_zero_v3(r_size)) {
+ r_size[0] = r_size[1] = r_size[2] = 1.0f;
+ }
+ else {
+ CLAMP_MIN(r_size[0], FLT_EPSILON);
+ CLAMP_MIN(r_size[1], FLT_EPSILON);
+ CLAMP_MIN(r_size[2], FLT_EPSILON);
+ }
}
- if (ob_center) {
+ if (ob_center != NULL) {
float inv_obmat[4][4];
/* Translate our coordinates so that center of ob_center is at (0, 0, 0). */
@@ -92,7 +98,7 @@ static void generate_vert_coordinates(
do_diff = true;
}
- else if (!is_zero_v3(offset)) {
+ else if (offset != NULL && !is_zero_v3(offset)) {
negate_v3_v3(diff, offset);
do_diff = true;
@@ -188,7 +194,7 @@ static bool polygons_check_flip(
}
static void normalEditModifier_do_radial(
- NormalEditModifierData *enmd, Object *ob, DerivedMesh *dm,
+ NormalEditModifierData *enmd, Object *ob, Mesh *mesh,
short (*clnors)[2], float (*loopnors)[3], float (*polynors)[3],
const short mix_mode, const float mix_factor, const float mix_limit,
MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup,
@@ -203,7 +209,7 @@ static void normalEditModifier_do_radial(
BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)num_verts, __func__);
- generate_vert_coordinates(dm, ob, enmd->target, enmd->offset, num_verts, cos, size);
+ generate_vert_coordinates(mesh, ob, enmd->target, enmd->offset, num_verts, cos, size);
/**
* size gives us our spheroid coefficients ``(A, B, C)``.
@@ -272,10 +278,11 @@ static void normalEditModifier_do_radial(
mix_limit, mix_mode, num_verts, mloop, loopnors, nos, num_loops);
}
- if (polygons_check_flip(mloop, nos, dm->getLoopDataLayout(dm), mpoly, polynors, num_polys)) {
- dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
+ if (polygons_check_flip(mloop, nos, &mesh->ldata, mpoly, polynors, num_polys)) {
+ /* XXX TODO is this still needed? */
+ // mesh->dirty |= DM_DIRTY_TESS_CDLAYERS;
/* We need to recompute vertex normals! */
- dm->calcNormals(dm);
+ BKE_mesh_calc_normals(mesh);
}
BKE_mesh_normals_loop_custom_set(mvert, num_verts, medge, num_edges, mloop, nos, num_loops,
@@ -287,7 +294,7 @@ static void normalEditModifier_do_radial(
}
static void normalEditModifier_do_directional(
- NormalEditModifierData *enmd, Object *ob, DerivedMesh *dm,
+ NormalEditModifierData *enmd, Object *ob, Mesh *mesh,
short (*clnors)[2], float (*loopnors)[3], float (*polynors)[3],
const short mix_mode, const float mix_factor, const float mix_limit,
MDeformVert *dvert, const int defgrp_index, const bool use_invert_vgroup,
@@ -296,22 +303,17 @@ static void normalEditModifier_do_directional(
{
const bool use_parallel_normals = (enmd->flag & MOD_NORMALEDIT_USE_DIRECTION_PARALLEL) != 0;
- float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__);
float (*nos)[3] = MEM_malloc_arrayN((size_t)num_loops, sizeof(*nos), __func__);
float target_co[3];
int i;
- dm->getVertCos(dm, cos);
-
/* Get target's center coordinates in ob local coordinates. */
- {
- float mat[4][4];
+ float mat[4][4];
- invert_m4_m4(mat, ob->obmat);
- mul_m4_m4m4(mat, mat, enmd->target->obmat);
- copy_v3_v3(target_co, mat[3]);
- }
+ invert_m4_m4(mat, ob->obmat);
+ mul_m4_m4m4(mat, mat, enmd->target->obmat);
+ copy_v3_v3(target_co, mat[3]);
if (use_parallel_normals) {
float no[3];
@@ -324,6 +326,9 @@ static void normalEditModifier_do_directional(
}
}
else {
+ float (*cos)[3] = MEM_malloc_arrayN((size_t)num_verts, sizeof(*cos), __func__);
+ generate_vert_coordinates(mesh, ob, enmd->target, NULL, num_verts, cos, NULL);
+
BLI_bitmap *done_verts = BLI_BITMAP_NEW((size_t)num_verts, __func__);
MLoop *ml;
float (*no)[3];
@@ -344,6 +349,7 @@ static void normalEditModifier_do_directional(
}
MEM_freeN(done_verts);
+ MEM_freeN(cos);
}
if (loopnors) {
@@ -351,14 +357,13 @@ static void normalEditModifier_do_directional(
mix_limit, mix_mode, num_verts, mloop, loopnors, nos, num_loops);
}
- if (polygons_check_flip(mloop, nos, dm->getLoopDataLayout(dm), mpoly, polynors, num_polys)) {
- dm->dirty |= DM_DIRTY_TESS_CDLAYERS;
+ if (polygons_check_flip(mloop, nos, &mesh->ldata, mpoly, polynors, num_polys)) {
+ mesh->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
}
BKE_mesh_normals_loop_custom_set(mvert, num_verts, medge, num_edges, mloop, nos, num_loops,
mpoly, (const float(*)[3])polynors, num_polys, clnors);
- MEM_freeN(cos);
MEM_freeN(nos);
}
@@ -374,93 +379,105 @@ static bool is_valid_target(NormalEditModifierData *enmd)
return false;
}
-static DerivedMesh *normalEditModifier_do(NormalEditModifierData *enmd, Object *ob, DerivedMesh *dm)
+static Mesh *normalEditModifier_do(NormalEditModifierData *enmd, Object *ob, Mesh *mesh)
{
- Mesh *me = ob->data;
-
- const int num_verts = dm->getNumVerts(dm);
- const int num_edges = dm->getNumEdges(dm);
- const int num_loops = dm->getNumLoops(dm);
- const int num_polys = dm->getNumPolys(dm);
- MVert *mvert;
- MEdge *medge;
- MLoop *mloop;
- MPoly *mpoly;
-
const bool use_invert_vgroup = ((enmd->flag & MOD_NORMALEDIT_INVERT_VGROUP) != 0);
const bool use_current_clnors = !((enmd->mix_mode == MOD_NORMALEDIT_MIX_COPY) &&
(enmd->mix_factor == 1.0f) &&
(enmd->defgrp_name[0] == '\0') &&
(enmd->mix_limit == (float)M_PI));
+ /* Do not run that modifier at all if autosmooth is disabled! */
+ if (!is_valid_target(enmd) || mesh->totloop == 0) {
+ return mesh;
+ }
+
+ /* XXX TODO ARG GRRR XYQWNMPRXTYY
+ * Once we fully switch to Mesh evaluation of modifiers, we can expect to get that flag from the COW copy.
+ * But for now, it is lost in the DM intermediate step, so we need to directly check orig object's data. */
+#if 0
+ if (!(mesh->flag & ME_AUTOSMOOTH)) {
+#else
+ if (!(((Mesh *)ob->data)->flag & ME_AUTOSMOOTH)) {
+#endif
+ modifier_setError((ModifierData *)enmd, "Enable 'Auto Smooth' option in mesh settings");
+ return mesh;
+ }
+
+ Mesh *result;
+ BKE_id_copy_ex(
+ NULL, &mesh->id, (ID **)&result,
+ LIB_ID_CREATE_NO_MAIN |
+ LIB_ID_CREATE_NO_USER_REFCOUNT |
+ LIB_ID_CREATE_NO_DEG_TAG|
+ LIB_ID_COPY_NO_PREVIEW,
+ false);
+
+ const int num_verts = result->totvert;
+ const int num_edges = result->totedge;
+ const int num_loops = result->totloop;
+ const int num_polys = result->totpoly;
+ MVert *mvert = result->mvert;
+ MEdge *medge = result->medge;
+ MLoop *mloop = result->mloop;
+ MPoly *mpoly = result->mpoly;
+
int defgrp_index;
MDeformVert *dvert;
float (*loopnors)[3] = NULL;
- short (*clnors)[2];
+ short (*clnors)[2] = NULL;
float (*polynors)[3];
- bool free_polynors = false;
- /* Do not run that modifier at all if autosmooth is disabled! */
- if (!is_valid_target(enmd) || !num_loops) {
- return dm;
+ CustomData *ldata = &result->ldata;
+ if (CustomData_has_layer(ldata, CD_NORMAL)) {
+ loopnors = CustomData_get_layer(ldata, CD_NORMAL);
}
-
- if (!(me->flag & ME_AUTOSMOOTH)) {
- modifier_setError((ModifierData *)enmd, "Enable 'Auto Smooth' option in mesh settings");
- return dm;
+ else {
+ loopnors = CustomData_add_layer(ldata, CD_NORMAL, CD_CALLOC, NULL, num_loops);
}
- medge = dm->getEdgeArray(dm);
- if (me->medge == medge) {
- /* We need to duplicate data here, otherwise setting custom normals (which may also affect sharp edges) could
- * modify org mesh, see T43671. */
- dm = CDDM_copy(dm);
- medge = dm->getEdgeArray(dm);
+ /* Compute poly (always needed) and vert normals. */
+ CustomData *pdata = &result->pdata;
+ polynors = CustomData_get_layer(pdata, CD_NORMAL);
+ if (!polynors) {
+ polynors = CustomData_add_layer(pdata, CD_NORMAL, CD_CALLOC, NULL, num_polys);
}
- mvert = dm->getVertArray(dm);
- mloop = dm->getLoopArray(dm);
- mpoly = dm->getPolyArray(dm);
+ BKE_mesh_calc_normals_poly(mvert, NULL, num_verts, mloop, mpoly, num_loops, num_polys, polynors,
+ (result->runtime.cd_dirty_vert & CD_MASK_NORMAL) ? false : true);
+
+ result->runtime.cd_dirty_vert &= ~CD_MASK_NORMAL;
if (use_current_clnors) {
- dm->calcLoopNormals(dm, true, me->smoothresh);
- loopnors = dm->getLoopDataArray(dm, CD_NORMAL);
- }
+ clnors = CustomData_get_layer(ldata, CD_CUSTOMLOOPNORMAL);
- clnors = CustomData_duplicate_referenced_layer(&dm->loopData, CD_CUSTOMLOOPNORMAL, num_loops);
- if (!clnors) {
- DM_add_loop_layer(dm, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL);
- clnors = dm->getLoopDataArray(dm, CD_CUSTOMLOOPNORMAL);
+ BKE_mesh_normals_loop_split(mvert, num_verts, medge, num_edges, mloop, loopnors, num_loops,
+ mpoly, (const float (*)[3])polynors, num_polys,
+ true, result->smoothresh,
+ NULL, clnors, NULL);
}
- polynors = dm->getPolyDataArray(dm, CD_NORMAL);
- if (!polynors) {
- polynors = MEM_malloc_arrayN((size_t)num_polys, sizeof(*polynors), __func__);
- BKE_mesh_calc_normals_poly(mvert, NULL, num_verts, mloop, mpoly, num_loops, num_polys, polynors, false);
- free_polynors = true;
+ if (!clnors) {
+ clnors = CustomData_add_layer(ldata, CD_CUSTOMLOOPNORMAL, CD_CALLOC, NULL, num_loops);
}
- modifier_get_vgroup(ob, dm, enmd->defgrp_name, &dvert, &defgrp_index);
+ modifier_get_vgroup_mesh(ob, result, enmd->defgrp_name, &dvert, &defgrp_index);
if (enmd->mode == MOD_NORMALEDIT_MODE_RADIAL) {
normalEditModifier_do_radial(
- enmd, ob, dm, clnors, loopnors, polynors,
+ enmd, ob, result, clnors, loopnors, polynors,
enmd->mix_mode, enmd->mix_factor, enmd->mix_limit, dvert, defgrp_index, use_invert_vgroup,
mvert, num_verts, medge, num_edges, mloop, num_loops, mpoly, num_polys);
}
else if (enmd->mode == MOD_NORMALEDIT_MODE_DIRECTIONAL) {
normalEditModifier_do_directional(
- enmd, ob, dm, clnors, loopnors, polynors,
+ enmd, ob, result, clnors, loopnors, polynors,
enmd->mix_mode, enmd->mix_factor, enmd->mix_limit, dvert, defgrp_index, use_invert_vgroup,
mvert, num_verts, medge, num_edges, mloop, num_loops, mpoly, num_polys);
}
- if (free_polynors) {
- MEM_freeN(polynors);
- }
-
- return dm;
+ return result;
}
static void initData(ModifierData *md)
@@ -511,17 +528,6 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
return !is_valid_target(enmd);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- NormalEditModifierData *enmd = (NormalEditModifierData *) md;
-
- if (enmd->target) {
- DagNode *Node = dag_get_node(ctx->forest, enmd->target);
-
- dag_add_relation(ctx->forest, Node, ctx->obNode, DAG_RL_OB_DATA, "NormalEdit Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
NormalEditModifierData *enmd = (NormalEditModifierData *) md;
@@ -530,9 +536,9 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx, Mesh *mesh)
{
- return normalEditModifier_do((NormalEditModifierData *)md, ob, dm);
+ return normalEditModifier_do((NormalEditModifierData *)md, ctx->object, mesh);
}
ModifierTypeInfo modifierType_NormalEdit = {
@@ -545,17 +551,25 @@ ModifierTypeInfo modifierType_NormalEdit = {
eModifierTypeFlag_SupportsEditmode |
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_ocean.c b/source/blender/modifiers/intern/MOD_ocean.c
index a9c4afcc0af..bff12a55558 100644
--- a/source/blender/modifiers/intern/MOD_ocean.c
+++ b/source/blender/modifiers/intern/MOD_ocean.c
@@ -391,7 +391,6 @@ static DerivedMesh *generate_ocean_geometry(OceanModifierData *omd)
/* add uvs */
if (CustomData_number_of_layers(&result->loopData, CD_MLOOPUV) < MAX_MTFACE) {
gogd.mloopuvs = CustomData_add_layer(&result->loopData, CD_MLOOPUV, CD_CALLOC, NULL, num_polys * 4);
- CustomData_add_layer(&result->polyData, CD_MTEXPOLY, CD_CALLOC, NULL, num_polys);
if (gogd.mloopuvs) { /* unlikely to fail */
gogd.ix = 1.0 / gogd.rx;
@@ -556,13 +555,12 @@ static DerivedMesh *doOcean(ModifierData *md, Object *UNUSED(ob),
}
#endif /* WITH_OCEANSIM */
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
DerivedMesh *result;
- result = doOcean(md, ob, derivedData, 0);
+ result = doOcean(md, ctx->object, derivedData, 0);
if (result != derivedData)
result->dirty |= DM_DIRTY_NORMALS;
@@ -581,17 +579,25 @@ ModifierTypeInfo modifierType_Ocean = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
- /* deformMatrices */ NULL,
+ /* deformMatrices_DM */ NULL,
+
+ /* deformVerts_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
+ /* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_particleinstance.c b/source/blender/modifiers/intern/MOD_particleinstance.c
index f87eb60e336..651a5a96676 100644
--- a/source/blender/modifiers/intern/MOD_particleinstance.c
+++ b/source/blender/modifiers/intern/MOD_particleinstance.c
@@ -52,7 +52,6 @@
#include "BKE_particle.h"
#include "BKE_pointcache.h"
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
static void initData(ModifierData *md)
@@ -131,20 +130,6 @@ static bool isDisabled(ModifierData *md, int useRenderParams)
return false;
}
-
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
-
- if (pimd->ob) {
- DagNode *curNode = dag_get_node(ctx->forest, pimd->ob);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "Particle Instance Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
@@ -217,9 +202,8 @@ static void store_float_in_vcol(MLoopCol *vcol, float float_value)
vcol->a = 1.0f;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
DerivedMesh *dm = derivedData, *result;
ParticleInstanceModifierData *pimd = (ParticleInstanceModifierData *) md;
@@ -232,7 +216,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
int totvert, totpoly, totloop , totedge;
int maxvert, maxpoly, maxloop, maxedge, part_end = 0, part_start;
int k, p, p_skip;
- short track = ob->trackflag % 3, trackneg, axis = pimd->axis;
+ short track = ctx->object->trackflag % 3, trackneg, axis = pimd->axis;
float max_co = 0.0, min_co = 0.0, temp_co[3];
float *size = NULL;
float spacemat[4][4];
@@ -240,9 +224,9 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
const bool use_children = pimd->flag & eParticleInstanceFlag_Children;
bool between;
- trackneg = ((ob->trackflag > 2) ? 1 : 0);
+ trackneg = ((ctx->object->trackflag > 2) ? 1 : 0);
- if (pimd->ob == ob) {
+ if (pimd->ob == ctx->object) {
pimd->ob = NULL;
return derivedData;
}
@@ -267,6 +251,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
if (part_end == 0)
return derivedData;
+ sim.depsgraph = ctx->depsgraph;
sim.scene = md->scene;
sim.ob = pimd->ob;
sim.psys = psys;
@@ -555,17 +540,25 @@ ModifierTypeInfo modifierType_ParticleInstance = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_particlesystem.c b/source/blender/modifiers/intern/MOD_particlesystem.c
index d8cccca415c..9ab3f9ae937 100644
--- a/source/blender/modifiers/intern/MOD_particlesystem.c
+++ b/source/blender/modifiers/intern/MOD_particlesystem.c
@@ -97,11 +97,10 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
}
/* saves the current emitter state for a particle system and calculates particles */
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int UNUSED(numVerts),
- ModifierApplyFlag flag)
+ int UNUSED(numVerts))
{
DerivedMesh *dm = derivedData;
ParticleSystemModifierData *psmd = (ParticleSystemModifierData *) md;
@@ -109,16 +108,16 @@ static void deformVerts(ModifierData *md, Object *ob,
bool needsFree = false;
/* float cfra = BKE_scene_frame_get(md->scene); */ /* UNUSED */
- if (ob->particlesystem.first)
+ if (ctx->object->particlesystem.first)
psys = psmd->psys;
else
return;
- if (!psys_check_enabled(ob, psys, (flag & MOD_APPLY_RENDER) != 0))
+ if (!psys_check_enabled(ctx->object, psys, (ctx->flag & MOD_APPLY_RENDER) != 0))
return;
if (dm == NULL) {
- dm = get_dm(ob, NULL, NULL, vertexCos, false, true);
+ dm = get_dm(ctx->object, NULL, NULL, vertexCos, false, true);
if (!dm)
return;
@@ -163,11 +162,11 @@ static void deformVerts(ModifierData *md, Object *ob,
if (!psmd->dm_final->deformedOnly) {
/* XXX Think we can assume here that if current DM is not only-deformed, ob->deformedOnly has been set.
* This is awfully weak though. :| */
- if (ob->derivedDeform) {
- psmd->dm_deformed = CDDM_copy(ob->derivedDeform);
+ if (ctx->object->derivedDeform) {
+ psmd->dm_deformed = CDDM_copy(ctx->object->derivedDeform);
}
else { /* Can happen in some cases, e.g. when rendering from Edit mode... */
- psmd->dm_deformed = CDDM_from_mesh((Mesh *)ob->data);
+ psmd->dm_deformed = CDDM_from_mesh((Mesh *)ctx->object->data);
}
DM_ensure_tessface(psmd->dm_deformed);
}
@@ -184,9 +183,9 @@ static void deformVerts(ModifierData *md, Object *ob,
psmd->totdmface = psmd->dm_final->getNumTessFaces(psmd->dm_final);
}
- if (!(ob->transflag & OB_NO_PSYS_UPDATE)) {
+ if (!(ctx->object->transflag & OB_NO_PSYS_UPDATE)) {
psmd->flag &= ~eParticleSystemFlag_psys_updated;
- particle_system_update(md->scene, ob, psys, (flag & MOD_APPLY_RENDER) != 0);
+ particle_system_update(ctx->depsgraph, md->scene, ctx->object, psys, (ctx->flag & MOD_APPLY_RENDER) != 0);
psmd->flag |= eParticleSystemFlag_psys_updated;
}
}
@@ -221,17 +220,25 @@ ModifierTypeInfo modifierType_ParticleSystem = {
eModifierTypeFlag_EnableInEditmode */,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
- /* deformVertsEM */ NULL,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_remesh.c b/source/blender/modifiers/intern/MOD_remesh.c
index b85898c07e9..254b82f3968 100644
--- a/source/blender/modifiers/intern/MOD_remesh.c
+++ b/source/blender/modifiers/intern/MOD_remesh.c
@@ -143,9 +143,8 @@ static void dualcon_add_quad(void *output_v, const int vert_indices[4])
}
static DerivedMesh *applyModifier(ModifierData *md,
- Object *UNUSED(ob),
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+ const ModifierEvalContext *UNUSED(ctx),
+ DerivedMesh *dm)
{
RemeshModifierData *rmd;
DualConOutput *output;
@@ -203,9 +202,9 @@ static DerivedMesh *applyModifier(ModifierData *md,
#else /* !WITH_MOD_REMESH */
-static DerivedMesh *applyModifier(ModifierData *UNUSED(md), Object *UNUSED(ob),
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *UNUSED(md),
+ const ModifierEvalContext *UNUSED(ctx),
+ DerivedMesh *derivedData)
{
return derivedData;
}
@@ -221,17 +220,25 @@ ModifierTypeInfo modifierType_Remesh = {
eModifierTypeFlag_AcceptsCVs |
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_screw.c b/source/blender/modifiers/intern/MOD_screw.c
index 047b1d5c47d..6335c453955 100644
--- a/source/blender/modifiers/intern/MOD_screw.c
+++ b/source/blender/modifiers/intern/MOD_screw.c
@@ -46,7 +46,6 @@
#include "BKE_cdderivedmesh.h"
#include "BKE_library_query.h"
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
@@ -185,14 +184,13 @@ static void copyData(ModifierData *md, ModifierData *target)
modifier_copyData_generic(md, target);
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag flag)
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
DerivedMesh *dm = derivedData;
DerivedMesh *result;
ScrewModifierData *ltmd = (ScrewModifierData *) md;
- const bool use_render_params = (flag & MOD_APPLY_RENDER) != 0;
+ const bool use_render_params = (ctx->flag & MOD_APPLY_RENDER) != 0;
int *origindex;
int mpoly_index = 0;
@@ -280,7 +278,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
if (ltmd->ob_axis) {
/* calc the matrix relative to the axis object */
- invert_m4_m4(mtx_tmp_a, ob->obmat);
+ invert_m4_m4(mtx_tmp_a, ctx->object->obmat);
copy_m4_m4(mtx_tx_inv, ltmd->ob_axis->obmat);
mul_m4_m4m4(mtx_tx, mtx_tmp_a, mtx_tx_inv);
@@ -1118,20 +1116,6 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
return result;
}
-
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- ScrewModifierData *ltmd = (ScrewModifierData *) md;
-
- if (ltmd->ob_axis) {
- DagNode *curNode = dag_get_node(ctx->forest, ltmd->ob_axis);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "Screw Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
ScrewModifierData *ltmd = (ScrewModifierData *)md;
@@ -1161,17 +1145,25 @@ ModifierTypeInfo modifierType_Screw = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_shapekey.c b/source/blender/modifiers/intern/MOD_shapekey.c
index 97aae733532..8c4664414d5 100644
--- a/source/blender/modifiers/intern/MOD_shapekey.c
+++ b/source/blender/modifiers/intern/MOD_shapekey.c
@@ -44,28 +44,27 @@
#include "MOD_modifiertypes.h"
-static void deformVerts(ModifierData *UNUSED(md), Object *ob,
+static void deformVerts(ModifierData *UNUSED(md), const ModifierEvalContext *ctx,
DerivedMesh *UNUSED(derivedData),
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
- Key *key = BKE_key_from_object(ob);
+ Key *key = BKE_key_from_object(ctx->object);
if (key && key->block.first) {
int deformedVerts_tot;
BKE_key_evaluate_object_ex(
- ob, &deformedVerts_tot,
+ ctx->object, &deformedVerts_tot,
(float *)vertexCos, sizeof(*vertexCos) * numVerts);
}
}
-static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedData,
+static void deformMatrices(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
float (*vertexCos)[3], float (*defMats)[3][3], int numVerts)
{
- Key *key = BKE_key_from_object(ob);
- KeyBlock *kb = BKE_keyblock_from_object(ob);
+ Key *key = BKE_key_from_object(ctx->object);
+ KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
float scale[3][3];
(void)vertexCos; /* unused */
@@ -73,37 +72,37 @@ static void deformMatrices(ModifierData *md, Object *ob, DerivedMesh *derivedDat
if (kb && kb->totelem == numVerts && kb != key->refkey) {
int a;
- if (ob->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1);
+ if (ctx->object->shapeflag & OB_SHAPE_LOCK) scale_m3_fl(scale, 1);
else scale_m3_fl(scale, kb->curval);
for (a = 0; a < numVerts; a++)
copy_m3_m3(defMats[a], scale);
}
- deformVerts(md, ob, derivedData, vertexCos, numVerts, 0);
+ deformVerts(md, ctx, derivedData, vertexCos, numVerts);
}
-static void deformVertsEM(ModifierData *md, Object *ob,
+static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx,
struct BMEditMesh *UNUSED(editData),
DerivedMesh *derivedData,
float (*vertexCos)[3],
int numVerts)
{
- Key *key = BKE_key_from_object(ob);
+ Key *key = BKE_key_from_object(ctx->object);
if (key && key->type == KEY_RELATIVE)
- deformVerts(md, ob, derivedData, vertexCos, numVerts, 0);
+ deformVerts(md, ctx, derivedData, vertexCos, numVerts);
}
-static void deformMatricesEM(ModifierData *UNUSED(md), Object *ob,
+static void deformMatricesEM(ModifierData *UNUSED(md), const ModifierEvalContext *ctx,
struct BMEditMesh *UNUSED(editData),
DerivedMesh *UNUSED(derivedData),
float (*vertexCos)[3],
float (*defMats)[3][3],
int numVerts)
{
- Key *key = BKE_key_from_object(ob);
- KeyBlock *kb = BKE_keyblock_from_object(ob);
+ Key *key = BKE_key_from_object(ctx->object);
+ KeyBlock *kb = BKE_keyblock_from_object(ctx->object);
float scale[3][3];
(void)vertexCos; /* unused */
@@ -128,17 +127,25 @@ ModifierTypeInfo modifierType_ShapeKey = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ NULL,
- /* deformVerts */ deformVerts,
- /* deformMatrices */ deformMatrices,
- /* deformVertsEM */ deformVertsEM,
- /* deformMatricesEM */ deformMatricesEM,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ deformMatrices,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/deformMatricesEM,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
+ /* deformMatrices */ NULL,
+ /* deformVertsEM */ NULL,
+ /* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ NULL,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_shrinkwrap.c b/source/blender/modifiers/intern/MOD_shrinkwrap.c
index e0f48ae5a2f..1e5f78bdbce 100644
--- a/source/blender/modifiers/intern/MOD_shrinkwrap.c
+++ b/source/blender/modifiers/intern/MOD_shrinkwrap.c
@@ -45,8 +45,6 @@
#include "BKE_modifier.h"
#include "BKE_shrinkwrap.h"
-#include "depsgraph_private.h"
-
#include "MOD_util.h"
static bool dependsOnNormals(ModifierData *md);
@@ -105,57 +103,44 @@ static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk,
walk(userData, ob, &smd->auxTarget, IDWALK_CB_NOP);
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag flag)
+ int numVerts)
{
DerivedMesh *dm = derivedData;
- CustomDataMask dataMask = requiredDataMask(ob, md);
- bool forRender = (flag & MOD_APPLY_RENDER) != 0;
+ CustomDataMask dataMask = requiredDataMask(ctx->object, md);
+ bool forRender = (ctx->flag & MOD_APPLY_RENDER) != 0;
/* ensure we get a CDDM with applied vertex coords */
if (dataMask) {
- dm = get_cddm(ob, NULL, dm, vertexCos, dependsOnNormals(md));
+ dm = get_cddm(ctx->object, NULL, dm, vertexCos, dependsOnNormals(md));
}
- shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ob, dm, vertexCos, numVerts, forRender);
+ shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, dm, vertexCos, numVerts, forRender);
if (dm != derivedData)
dm->release(dm);
}
-static void deformVertsEM(ModifierData *md, Object *ob, struct BMEditMesh *editData, DerivedMesh *derivedData,
+static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData, DerivedMesh *derivedData,
float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm = derivedData;
- CustomDataMask dataMask = requiredDataMask(ob, md);
+ CustomDataMask dataMask = requiredDataMask(ctx->object, md);
/* ensure we get a CDDM with applied vertex coords */
if (dataMask) {
- dm = get_cddm(ob, editData, dm, vertexCos, dependsOnNormals(md));
+ dm = get_cddm(ctx->object, editData, dm, vertexCos, dependsOnNormals(md));
}
- shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ob, dm, vertexCos, numVerts, false);
+ shrinkwrapModifier_deform((ShrinkwrapModifierData *)md, ctx->object, dm, vertexCos, numVerts, false);
if (dm != derivedData)
dm->release(dm);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *) md;
-
- if (smd->target)
- dag_add_relation(ctx->forest, dag_get_node(ctx->forest, smd->target), ctx->obNode,
- DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Shrinkwrap Modifier");
-
- if (smd->auxTarget)
- dag_add_relation(ctx->forest, dag_get_node(ctx->forest, smd->auxTarget), ctx->obNode,
- DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "Shrinkwrap Modifier");
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *)md;
@@ -191,17 +176,25 @@ ModifierTypeInfo modifierType_Shrinkwrap = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_simpledeform.c b/source/blender/modifiers/intern/MOD_simpledeform.c
index 71109922f11..eec1cde3889 100644
--- a/source/blender/modifiers/intern/MOD_simpledeform.c
+++ b/source/blender/modifiers/intern/MOD_simpledeform.c
@@ -32,6 +32,7 @@
* \ingroup modifiers
*/
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
@@ -39,13 +40,11 @@
#include "BLI_utildefines.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_mesh.h"
#include "BKE_library_query.h"
#include "BKE_modifier.h"
#include "BKE_deform.h"
-
-#include "depsgraph_private.h"
-
#include "MOD_util.h"
#define BEND_EPS 0.000001f
@@ -183,11 +182,10 @@ static void simpleDeform_bend(const float factor, const int axis, const float dc
/* simple deform modifier */
-static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct DerivedMesh *dm,
+static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object *ob, struct Mesh *mesh,
float (*vertexCos)[3], int numVerts)
{
const float base_limit[2] = {0.0f, 0.0f};
-
int i;
float smd_limit[2], smd_factor;
SpaceTransform *transf = NULL, tmp_transf;
@@ -284,7 +282,7 @@ static void SimpleDeformModifier_do(SimpleDeformModifierData *smd, struct Object
}
}
- modifier_get_vgroup(ob, dm, smd->vgroup_name, &dvert, &vgroup);
+ modifier_get_vgroup_mesh(ob, mesh, smd->vgroup_name, &dvert, &vgroup);
const bool invert_vgroup = (smd->flag & MOD_SIMPLEDEFORM_FLAG_INVERT_VGROUP) != 0;
const uint *axis_map = axis_map_table[(smd->mode != MOD_SIMPLEDEFORM_MODE_BEND) ? deform_axis : 2];
@@ -378,14 +376,6 @@ static void foreachObjectLink(
walk(userData, ob, &smd->origin, IDWALK_CB_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- SimpleDeformModifierData *smd = (SimpleDeformModifierData *)md;
-
- if (smd->origin)
- dag_add_relation(ctx->forest, dag_get_node(ctx->forest, smd->origin), ctx->obNode, DAG_RL_OB_DATA, "SimpleDeform Modifier");
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
SimpleDeformModifierData *smd = (SimpleDeformModifierData *)md;
@@ -394,44 +384,21 @@ static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphConte
}
}
-static void deformVerts(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
+ struct Mesh *mesh,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
- DerivedMesh *dm = derivedData;
- CustomDataMask dataMask = requiredDataMask(ob, md);
-
- /* we implement requiredDataMask but thats not really useful since
- * mesh_calc_modifiers pass a NULL derivedData */
- if (dataMask)
- dm = get_dm(ob, NULL, dm, NULL, false, false);
-
- SimpleDeformModifier_do((SimpleDeformModifierData *)md, ob, dm, vertexCos, numVerts);
-
- if (dm != derivedData)
- dm->release(dm);
+ SimpleDeformModifier_do((SimpleDeformModifierData *)md, ctx->object, mesh, vertexCos, numVerts);
}
-static void deformVertsEM(ModifierData *md, Object *ob,
- struct BMEditMesh *editData,
- DerivedMesh *derivedData,
+static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *UNUSED(editData),
+ struct Mesh *mesh,
float (*vertexCos)[3],
int numVerts)
{
- DerivedMesh *dm = derivedData;
- CustomDataMask dataMask = requiredDataMask(ob, md);
-
- /* we implement requiredDataMask but thats not really useful since
- * mesh_calc_modifiers pass a NULL derivedData */
- if (dataMask)
- dm = get_dm(ob, editData, dm, NULL, false, false);
-
- SimpleDeformModifier_do((SimpleDeformModifierData *)md, ob, dm, vertexCos, numVerts);
-
- if (dm != derivedData)
- dm->release(dm);
+ SimpleDeformModifier_do((SimpleDeformModifierData *)md, ctx->object, mesh, vertexCos, numVerts);
}
@@ -448,17 +415,25 @@ ModifierTypeInfo modifierType_SimpleDeform = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ deformVerts,
/* deformMatrices */ NULL,
/* deformVertsEM */ deformVertsEM,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_skin.c b/source/blender/modifiers/intern/MOD_skin.c
index dda0c413f57..defb661d9d8 100644
--- a/source/blender/modifiers/intern/MOD_skin.c
+++ b/source/blender/modifiers/intern/MOD_skin.c
@@ -59,6 +59,7 @@
#include "MEM_guardedalloc.h"
+#include "DNA_mesh_types.h"
#include "DNA_meshdata_types.h"
#include "DNA_object_types.h"
#include "DNA_modifier_types.h"
@@ -70,9 +71,8 @@
#include "BLI_stack.h"
#include "BLI_bitmap.h"
-#include "BKE_cdderivedmesh.h"
#include "BKE_deform.h"
-#include "BKE_DerivedMesh.h"
+#include "BKE_library.h"
#include "BKE_mesh.h"
#include "BKE_mesh_mapping.h"
#include "BKE_modifier.h"
@@ -814,11 +814,11 @@ static int calc_edge_subdivisions(const MVert *mvert, const MVertSkin *nodes,
#undef NUM_SUBDIVISIONS_MAX
}
-/* Take a DerivedMesh and subdivide its edges to keep skin nodes
+/* Take a Mesh and subdivide its edges to keep skin nodes
* reasonably close. */
-static DerivedMesh *subdivide_base(DerivedMesh *orig)
+static Mesh *subdivide_base(Mesh *orig)
{
- DerivedMesh *dm;
+ Mesh *result;
MVertSkin *orignode, *outnode;
MVert *origvert, *outvert;
MEdge *origedge, *outedge, *e;
@@ -828,12 +828,12 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig)
int i, j, k, u, v;
float radrat;
- orignode = CustomData_get_layer(&orig->vertData, CD_MVERT_SKIN);
- origvert = orig->getVertArray(orig);
- origedge = orig->getEdgeArray(orig);
- origdvert = orig->getVertDataArray(orig, CD_MDEFORMVERT);
- totorigvert = orig->getNumVerts(orig);
- totorigedge = orig->getNumEdges(orig);
+ orignode = CustomData_get_layer(&orig->vdata, CD_MVERT_SKIN);
+ origvert = orig->mvert;
+ origedge = orig->medge;
+ origdvert = orig->dvert;
+ totorigvert = orig->totvert;
+ totorigedge = orig->totedge;
/* Get degree of all vertices */
degree = MEM_calloc_arrayN(totorigvert, sizeof(int), "degree");
@@ -853,19 +853,19 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig)
MEM_freeN(degree);
/* Allocate output derivedmesh */
- dm = CDDM_from_template(orig,
- totorigvert + totsubd,
- totorigedge + totsubd,
- 0, 0, 0);
+ result = BKE_mesh_from_template(orig,
+ totorigvert + totsubd,
+ totorigedge + totsubd,
+ 0, 0, 0);
- outvert = dm->getVertArray(dm);
- outedge = dm->getEdgeArray(dm);
- outnode = CustomData_get_layer(&dm->vertData, CD_MVERT_SKIN);
- outdvert = CustomData_get_layer(&dm->vertData, CD_MDEFORMVERT);
+ outvert = result->mvert;
+ outedge = result->medge;
+ outnode = CustomData_get_layer(&result->vdata, CD_MVERT_SKIN);
+ outdvert = result->dvert;
/* Copy original vertex data */
- CustomData_copy_data(&orig->vertData,
- &dm->vertData,
+ CustomData_copy_data(&orig->vdata,
+ &result->vdata,
0, 0, totorigvert);
/* Subdivide edges */
@@ -949,7 +949,7 @@ static DerivedMesh *subdivide_base(DerivedMesh *orig)
MEM_freeN(edge_subd);
- return dm;
+ return result;
}
/******************************* Output *******************************/
@@ -1805,12 +1805,12 @@ static BMesh *build_skin(SkinNode *skin_nodes,
return so.bm;
}
-static void skin_set_orig_indices(DerivedMesh *dm)
+static void skin_set_orig_indices(Mesh *mesh)
{
int *orig, totpoly;
- totpoly = dm->getNumPolys(dm);
- orig = CustomData_add_layer(&dm->polyData, CD_ORIGINDEX,
+ totpoly = mesh->totpoly;
+ orig = CustomData_add_layer(&mesh->pdata, CD_ORIGINDEX,
CD_CALLOC, NULL, totpoly);
copy_vn_i(orig, totpoly, ORIGINDEX_NONE);
}
@@ -1821,10 +1821,10 @@ static void skin_set_orig_indices(DerivedMesh *dm)
* 2) Generate node frames
* 3) Output vertices and polygons from frames, connections, and hulls
*/
-static DerivedMesh *base_skin(DerivedMesh *origdm,
- SkinModifierData *smd)
+static Mesh *base_skin(Mesh *origmesh,
+ SkinModifierData *smd)
{
- DerivedMesh *result;
+ Mesh *result;
MVertSkin *nodes;
BMesh *bm;
EMat *emat;
@@ -1837,13 +1837,13 @@ static DerivedMesh *base_skin(DerivedMesh *origdm,
int totvert, totedge;
bool has_valid_root = false;
- nodes = CustomData_get_layer(&origdm->vertData, CD_MVERT_SKIN);
+ nodes = CustomData_get_layer(&origmesh->vdata, CD_MVERT_SKIN);
- mvert = origdm->getVertArray(origdm);
- dvert = origdm->getVertDataArray(origdm, CD_MDEFORMVERT);
- medge = origdm->getEdgeArray(origdm);
- totvert = origdm->getNumVerts(origdm);
- totedge = origdm->getNumEdges(origdm);
+ mvert = origmesh->mvert;
+ dvert = origmesh->dvert;
+ medge = origmesh->medge;
+ totvert = origmesh->totvert;
+ totedge = origmesh->totedge;
BKE_mesh_vert_edge_map_create(&emap, &emapmem, medge, totvert, totedge);
@@ -1864,32 +1864,30 @@ static DerivedMesh *base_skin(DerivedMesh *origdm,
if (!bm)
return NULL;
-
- result = CDDM_from_bmesh(bm, false);
+
+ result = BKE_bmesh_to_mesh(bm, &(struct BMeshToMeshParams){0});
BM_mesh_free(bm);
- result->dirty |= DM_DIRTY_NORMALS;
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
skin_set_orig_indices(result);
return result;
}
-static DerivedMesh *final_skin(SkinModifierData *smd,
- DerivedMesh *origdm)
+static Mesh *final_skin(SkinModifierData *smd, Mesh *mesh)
{
- DerivedMesh *dm;
+ Mesh *result;
/* Skin node layer is required */
- if (!CustomData_get_layer(&origdm->vertData, CD_MVERT_SKIN))
- return origdm;
-
- origdm = subdivide_base(origdm);
- dm = base_skin(origdm, smd);
+ if (!CustomData_get_layer(&mesh->vdata, CD_MVERT_SKIN))
+ return mesh;
- origdm->release(origdm);
+ mesh = subdivide_base(mesh);
+ result = base_skin(mesh, smd);
- return dm;
+ BKE_id_free(NULL, mesh);
+ return result;
}
@@ -1916,15 +1914,14 @@ static void copyData(ModifierData *md, ModifierData *target)
modifier_copyData_generic(md, target);
}
-static DerivedMesh *applyModifier(ModifierData *md,
- Object *UNUSED(ob),
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(ModifierData *md,
+ const ModifierEvalContext *UNUSED(ctx),
+ Mesh *mesh)
{
- DerivedMesh *result;
+ Mesh *result;
- if (!(result = final_skin((SkinModifierData *)md, dm)))
- return dm;
+ if (!(result = final_skin((SkinModifierData *)md, mesh)))
+ return mesh;
return result;
}
@@ -1942,17 +1939,25 @@ ModifierTypeInfo modifierType_Skin = {
/* flags */ eModifierTypeFlag_AcceptsMesh | eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_smoke.c b/source/blender/modifiers/intern/MOD_smoke.c
index 2073e23b7b2..d78d1277374 100644
--- a/source/blender/modifiers/intern/MOD_smoke.c
+++ b/source/blender/modifiers/intern/MOD_smoke.c
@@ -46,13 +46,14 @@
#include "BLI_utildefines.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
#include "BKE_main.h"
#include "BKE_modifier.h"
#include "BKE_smoke.h"
-#include "depsgraph_private.h"
+#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
@@ -101,16 +102,15 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag flag)
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
SmokeModifierData *smd = (SmokeModifierData *) md;
- if (flag & MOD_APPLY_ORCO)
+ if (ctx->flag & MOD_APPLY_ORCO)
return dm;
- return smokeModifier_do(smd, md->scene, ob, dm);
+ return smokeModifier_do(smd, ctx->depsgraph, md->scene, ctx->object, dm);
}
static bool dependsOnTime(ModifierData *UNUSED(md))
@@ -130,30 +130,14 @@ static bool is_coll_cb(Object *UNUSED(ob), ModifierData *md)
return (smd->type & MOD_SMOKE_TYPE_COLL) && smd->coll;
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- SmokeModifierData *smd = (SmokeModifierData *) md;
-
- if (smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
- /* Actual code uses get_collisionobjects */
-#ifdef WITH_LEGACY_DEPSGRAPH
- dag_add_collision_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, smd->domain->fluid_group, ctx->object->lay|ctx->scene->lay, eModifierType_Smoke, is_flow_cb, true, "Smoke Flow");
- dag_add_collision_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, smd->domain->coll_group, ctx->object->lay|ctx->scene->lay, eModifierType_Smoke, is_coll_cb, true, "Smoke Coll");
- dag_add_forcefield_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, smd->domain->effector_weights, true, PFIELD_SMOKEFLOW, "Smoke Force Field");
-#else
- (void)ctx;
-#endif
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
SmokeModifierData *smd = (SmokeModifierData *)md;
if (smd && (smd->type & MOD_SMOKE_TYPE_DOMAIN) && smd->domain) {
/* Actual code uses get_collisionobjects */
- DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, smd->domain->fluid_group, ctx->object->lay|ctx->scene->lay, eModifierType_Smoke, is_flow_cb, true, "Smoke Flow");
- DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, smd->domain->coll_group, ctx->object->lay|ctx->scene->lay, eModifierType_Smoke, is_coll_cb, true, "Smoke Coll");
+ DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, smd->domain->fluid_group, eModifierType_Smoke, is_flow_cb, true, "Smoke Flow");
+ DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, smd->domain->coll_group, eModifierType_Smoke, is_coll_cb, true, "Smoke Coll");
DEG_add_forcefield_relations(ctx->node, ctx->scene, ctx->object, smd->domain->effector_weights, true, PFIELD_SMOKEFLOW, "Smoke Force Field");
}
@@ -189,17 +173,25 @@ ModifierTypeInfo modifierType_Smoke = {
eModifierTypeFlag_Single,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_smooth.c b/source/blender/modifiers/intern/MOD_smooth.c
index 92025512f02..b905e0f8118 100644
--- a/source/blender/modifiers/intern/MOD_smooth.c
+++ b/source/blender/modifiers/intern/MOD_smooth.c
@@ -215,12 +215,12 @@ static void smoothModifier_do(
MEM_freeN(uctmp);
}
-static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag))
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_dm(ob, NULL, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, NULL, derivedData, NULL, false, false);
- smoothModifier_do((SmoothModifierData *)md, ob, dm,
+ smoothModifier_do((SmoothModifierData *)md, ctx->object, dm,
vertexCos, numVerts);
if (dm != derivedData)
@@ -228,12 +228,12 @@ static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
+ ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
- DerivedMesh *dm = get_dm(ob, editData, derivedData, NULL, false, false);
+ DerivedMesh *dm = get_dm(ctx->object, editData, derivedData, NULL, false, false);
- smoothModifier_do((SmoothModifierData *)md, ob, dm,
+ smoothModifier_do((SmoothModifierData *)md, ctx->object, dm,
vertexCos, numVerts);
if (dm != derivedData)
@@ -251,17 +251,25 @@ ModifierTypeInfo modifierType_Smooth = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_softbody.c b/source/blender/modifiers/intern/MOD_softbody.c
index e760ff5ca01..885c355254d 100644
--- a/source/blender/modifiers/intern/MOD_softbody.c
+++ b/source/blender/modifiers/intern/MOD_softbody.c
@@ -40,21 +40,21 @@
#include "BLI_utildefines.h"
#include "BKE_cdderivedmesh.h"
+#include "BKE_layer.h"
#include "BKE_particle.h"
#include "BKE_softbody.h"
-#include "depsgraph_private.h"
+#include "DEG_depsgraph.h"
#include "DEG_depsgraph_build.h"
#include "MOD_modifiertypes.h"
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *UNUSED(derivedData),
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
- sbObjectStep(md->scene, ob, (float)md->scene->r.cfra, vertexCos, numVerts);
+ sbObjectStep(ctx->depsgraph, md->scene, ctx->object, (float)md->scene->r.cfra, vertexCos, numVerts);
}
static bool dependsOnTime(ModifierData *UNUSED(md))
@@ -62,25 +62,11 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
return true;
}
-static void updateDepgraph(ModifierData *UNUSED(md), const ModifierUpdateDepsgraphContext *ctx)
-{
- if (ctx->object->soft) {
-#ifdef WITH_LEGACY_DEPSGRAPH
- /* Actual code uses ccd_build_deflector_hash */
- dag_add_collision_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, ctx->object->soft->collision_group, ctx->object->lay, eModifierType_Collision, NULL, false, "Softbody Collision");
-
- dag_add_forcefield_relations(ctx->forest, ctx->scene, ctx->object, ctx->obNode, ctx->object->soft->effector_weights, true, 0, "Softbody Field");
-#else
- (void)ctx;
-#endif
- }
-}
-
static void updateDepsgraph(ModifierData *UNUSED(md), const ModifierUpdateDepsgraphContext *ctx)
{
if (ctx->object->soft) {
/* Actual code uses ccd_build_deflector_hash */
- DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, ctx->object->soft->collision_group, ctx->object->lay, eModifierType_Collision, NULL, false, "Softbody Collision");
+ DEG_add_collision_relations(ctx->node, ctx->scene, ctx->object, ctx->object->soft->collision_group, eModifierType_Collision, NULL, false, "Softbody Collision");
DEG_add_forcefield_relations(ctx->node, ctx->scene, ctx->object, ctx->object->soft->effector_weights, true, 0, "Softbody Field");
}
@@ -97,17 +83,25 @@ ModifierTypeInfo modifierType_Softbody = {
eModifierTypeFlag_Single,
/* copyData */ NULL,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ NULL,
/* requiredDataMask */ NULL,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_solidify.c b/source/blender/modifiers/intern/MOD_solidify.c
index 280f3c771ed..e37bcccacfd 100644
--- a/source/blender/modifiers/intern/MOD_solidify.c
+++ b/source/blender/modifiers/intern/MOD_solidify.c
@@ -73,7 +73,7 @@ BLI_INLINE bool edgeref_is_init(const EdgeFaceRef *edge_ref)
* \param face_nors Precalculated face normals.
* \param r_vert_nors Return vert normals.
*/
-static void dm_calc_normal(DerivedMesh *dm, float (*face_nors)[3], float (*r_vert_nors)[3])
+static void mesh_calc_hq_normal(Mesh *mesh, float (*face_nors)[3], float (*r_vert_nors)[3])
{
int i, numVerts, numEdges, numFaces;
MPoly *mpoly, *mp;
@@ -81,13 +81,13 @@ static void dm_calc_normal(DerivedMesh *dm, float (*face_nors)[3], float (*r_ver
MEdge *medge, *ed;
MVert *mvert, *mv;
- numVerts = dm->getNumVerts(dm);
- numEdges = dm->getNumEdges(dm);
- numFaces = dm->getNumPolys(dm);
- mpoly = dm->getPolyArray(dm);
- medge = dm->getEdgeArray(dm);
- mvert = dm->getVertArray(dm);
- mloop = dm->getLoopArray(dm);
+ numVerts = mesh->totvert;
+ numEdges = mesh->totedge;
+ numFaces = mesh->totface;
+ mpoly = mesh->mpoly;
+ medge = mesh->medge;
+ mvert = mesh->mvert;
+ mloop = mesh->mloop;
/* we don't want to overwrite any referenced layers */
@@ -204,26 +204,25 @@ BLI_INLINE void madd_v3v3short_fl(float r[3], const short a[3], const float f)
r[2] += (float)a[2] * f;
}
-static DerivedMesh *applyModifier(
- ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(
+ ModifierData *md, const ModifierEvalContext *ctx,
+ Mesh *mesh)
{
- DerivedMesh *result;
+ Mesh *result;
const SolidifyModifierData *smd = (SolidifyModifierData *) md;
MVert *mv, *mvert, *orig_mvert;
MEdge *ed, *medge, *orig_medge;
MLoop *ml, *mloop, *orig_mloop;
MPoly *mp, *mpoly, *orig_mpoly;
- const unsigned int numVerts = (unsigned int)dm->getNumVerts(dm);
- const unsigned int numEdges = (unsigned int)dm->getNumEdges(dm);
- const unsigned int numFaces = (unsigned int)dm->getNumPolys(dm);
- const unsigned int numLoops = (unsigned int)dm->getNumLoops(dm);
+ const unsigned int numVerts = (unsigned int)mesh->totvert;
+ const unsigned int numEdges = (unsigned int)mesh->totedge;
+ const unsigned int numFaces = (unsigned int)mesh->totpoly;
+ const unsigned int numLoops = (unsigned int)mesh->totloop;
unsigned int newLoops = 0, newFaces = 0, newEdges = 0, newVerts = 0, rimVerts = 0;
/* only use material offsets if we have 2 or more materials */
- const short mat_nr_max = ob->totcol > 1 ? ob->totcol - 1 : 0;
+ const short mat_nr_max = ctx->object->totcol > 1 ? ctx->object->totcol - 1 : 0;
const short mat_ofs = mat_nr_max ? smd->mat_ofs : 0;
const short mat_ofs_rim = mat_nr_max ? smd->mat_ofs_rim : 0;
@@ -261,12 +260,12 @@ static DerivedMesh *applyModifier(
/* array size is doubled in case of using a shell */
const unsigned int stride = do_shell ? 2 : 1;
- modifier_get_vgroup(ob, dm, smd->defgrp_name, &dvert, &defgrp_index);
+ modifier_get_vgroup_mesh(ctx->object, mesh, smd->defgrp_name, &dvert, &defgrp_index);
- orig_mvert = dm->getVertArray(dm);
- orig_medge = dm->getEdgeArray(dm);
- orig_mloop = dm->getLoopArray(dm);
- orig_mpoly = dm->getPolyArray(dm);
+ orig_mvert = mesh->mvert;
+ orig_medge = mesh->medge;
+ orig_mloop = mesh->mloop;
+ orig_mpoly = mesh->mpoly;
if (need_face_normals) {
/* calculate only face normals */
@@ -367,49 +366,49 @@ static DerivedMesh *applyModifier(
if (smd->flag & MOD_SOLIDIFY_NORMAL_CALC) {
vert_nors = MEM_calloc_arrayN(numVerts, 3 * sizeof(float), "mod_solid_vno_hq");
- dm_calc_normal(dm, face_nors, vert_nors);
+ mesh_calc_hq_normal(mesh, face_nors, vert_nors);
}
- result = CDDM_from_template(dm,
- (int)((numVerts * stride) + newVerts),
- (int)((numEdges * stride) + newEdges + rimVerts), 0,
- (int)((numLoops * stride) + newLoops),
- (int)((numFaces * stride) + newFaces));
+ result = BKE_mesh_from_template(mesh,
+ (int)((numVerts * stride) + newVerts),
+ (int)((numEdges * stride) + newEdges + rimVerts), 0,
+ (int)((numLoops * stride) + newLoops),
+ (int)((numFaces * stride) + newFaces));
- mpoly = CDDM_get_polys(result);
- mloop = CDDM_get_loops(result);
- medge = CDDM_get_edges(result);
- mvert = CDDM_get_verts(result);
+ mpoly = result->mpoly;
+ mloop = result->mloop;
+ medge = result->medge;
+ mvert = result->mvert;
if (do_shell) {
- DM_copy_vert_data(dm, result, 0, 0, (int)numVerts);
- DM_copy_vert_data(dm, result, 0, (int)numVerts, (int)numVerts);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, (int)numVerts);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, 0, (int)numVerts, (int)numVerts);
- DM_copy_edge_data(dm, result, 0, 0, (int)numEdges);
- DM_copy_edge_data(dm, result, 0, (int)numEdges, (int)numEdges);
+ CustomData_copy_data(&mesh->edata, &result->edata, 0, 0, (int)numEdges);
+ CustomData_copy_data(&mesh->edata, &result->edata, 0, (int)numEdges, (int)numEdges);
- DM_copy_loop_data(dm, result, 0, 0, (int)numLoops);
- DM_copy_loop_data(dm, result, 0, (int)numLoops, (int)numLoops);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, 0, 0, (int)numLoops);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, 0, (int)numLoops, (int)numLoops);
- DM_copy_poly_data(dm, result, 0, 0, (int)numFaces);
- DM_copy_poly_data(dm, result, 0, (int)numFaces, (int)numFaces);
+ CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, (int)numFaces);
+ CustomData_copy_data(&mesh->pdata, &result->pdata, 0, (int)numFaces, (int)numFaces);
}
else {
int i, j;
- DM_copy_vert_data(dm, result, 0, 0, (int)numVerts);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, 0, 0, (int)numVerts);
for (i = 0, j = (int)numVerts; i < numVerts; i++) {
if (old_vert_arr[i] != INVALID_UNUSED) {
- DM_copy_vert_data(dm, result, i, j, 1);
+ CustomData_copy_data(&mesh->vdata, &result->vdata, i, j, 1);
j++;
}
}
- DM_copy_edge_data(dm, result, 0, 0, (int)numEdges);
+ CustomData_copy_data(&mesh->edata, &result->edata, 0, 0, (int)numEdges);
for (i = 0, j = (int)numEdges; i < numEdges; i++) {
if (!ELEM(edge_users[i], INVALID_UNUSED, INVALID_PAIR)) {
MEdge *ed_src, *ed_dst;
- DM_copy_edge_data(dm, result, i, j, 1);
+ CustomData_copy_data(&mesh->edata, &result->edata, i, j, 1);
ed_src = &medge[i];
ed_dst = &medge[j];
@@ -420,8 +419,8 @@ static DerivedMesh *applyModifier(
}
/* will be created later */
- DM_copy_loop_data(dm, result, 0, 0, (int)numLoops);
- DM_copy_poly_data(dm, result, 0, 0, (int)numFaces);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, 0, 0, (int)numLoops);
+ CustomData_copy_data(&mesh->pdata, &result->pdata, 0, 0, (int)numFaces);
}
#undef INVALID_UNUSED
@@ -454,7 +453,7 @@ static DerivedMesh *applyModifier(
unsigned int i;
mp = mpoly + numFaces;
- for (i = 0; i < dm->numPolyData; i++, mp++) {
+ for (i = 0; i < mesh->totpoly; i++, mp++) {
const int loop_end = mp->totloop - 1;
MLoop *ml2;
unsigned int e;
@@ -462,19 +461,19 @@ static DerivedMesh *applyModifier(
/* reverses the loop direction (MLoop.v as well as custom-data)
* MLoop.e also needs to be corrected too, done in a separate loop below. */
- ml2 = mloop + mp->loopstart + dm->numLoopData;
+ ml2 = mloop + mp->loopstart + mesh->totloop;
#if 0
for (j = 0; j < mp->totloop; j++) {
- CustomData_copy_data(&dm->loopData, &result->loopData, mp->loopstart + j,
- mp->loopstart + (loop_end - j) + dm->numLoopData, 1);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, mp->loopstart + j,
+ mp->loopstart + (loop_end - j) + mesh->totloop, 1);
}
#else
/* slightly more involved, keep the first vertex the same for the copy,
* ensures the diagonals in the new face match the original. */
j = 0;
for (int j_prev = loop_end; j < mp->totloop; j_prev = j++) {
- CustomData_copy_data(&dm->loopData, &result->loopData, mp->loopstart + j,
- mp->loopstart + (loop_end - j_prev) + dm->numLoopData, 1);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, mp->loopstart + j,
+ mp->loopstart + (loop_end - j_prev) + mesh->totloop, 1);
}
#endif
@@ -489,7 +488,7 @@ static DerivedMesh *applyModifier(
}
ml2[loop_end].e = e;
- mp->loopstart += dm->numLoopData;
+ mp->loopstart += mesh->totloop;
for (j = 0; j < mp->totloop; j++) {
ml2[j].e += numEdges;
@@ -736,8 +735,8 @@ static DerivedMesh *applyModifier(
MEM_freeN(vert_nors);
/* must recalculate normals with vgroups since they can displace unevenly [#26888] */
- if ((dm->dirty & DM_DIRTY_NORMALS) || (smd->flag & MOD_SOLIDIFY_RIM) || dvert) {
- result->dirty |= DM_DIRTY_NORMALS;
+ if ((mesh->runtime.cd_dirty_vert & CD_MASK_NORMAL) || (smd->flag & MOD_SOLIDIFY_RIM) || dvert) {
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
}
else if (do_shell) {
unsigned int i;
@@ -763,7 +762,9 @@ static DerivedMesh *applyModifier(
#define SOLIDIFY_SIDE_NORMALS
#ifdef SOLIDIFY_SIDE_NORMALS
- const bool do_side_normals = !(result->dirty & DM_DIRTY_NORMALS);
+ /* Note that, due to the code setting cd_dirty_vert a few lines above,
+ * do_side_normals is always false. - Sybren */
+ const bool do_side_normals = !(result->runtime.cd_dirty_vert & CD_MASK_NORMAL);
/* annoying to allocate these since we only need the edge verts, */
float (*edge_vert_nos)[3] = do_side_normals ? MEM_calloc_arrayN(numVerts, 3 * sizeof(float), __func__) : NULL;
float nor[3];
@@ -781,7 +782,8 @@ static DerivedMesh *applyModifier(
}
/* add faces & edges */
- origindex_edge = result->getEdgeDataArray(result, CD_ORIGINDEX);
+ origindex_edge = CustomData_get_layer(&result->edata, CD_ORIGINDEX);
+ BLI_assert(origindex_edge != NULL);
ed = &medge[(numEdges * stride) + newEdges]; /* start after copied edges */
orig_ed = &origindex_edge[(numEdges * stride) + newEdges];
for (i = 0; i < rimVerts; i++, ed++, orig_ed++) {
@@ -817,7 +819,7 @@ static DerivedMesh *applyModifier(
ed = medge + eidx;
/* copy most of the face settings */
- DM_copy_poly_data(dm, result, (int)fidx, (int)((numFaces * stride) + i), 1);
+ CustomData_copy_data(&mesh->pdata, &result->pdata, (int)fidx, (int)((numFaces * stride) + i), 1);
mp->loopstart = (int)(j + (numLoops * stride));
mp->flag = mpoly[fidx].flag;
@@ -829,10 +831,10 @@ static DerivedMesh *applyModifier(
mp->totloop = 4;
- CustomData_copy_data(&dm->loopData, &result->loopData, k2, (int)((numLoops * stride) + j + 0), 1);
- CustomData_copy_data(&dm->loopData, &result->loopData, k1, (int)((numLoops * stride) + j + 1), 1);
- CustomData_copy_data(&dm->loopData, &result->loopData, k1, (int)((numLoops * stride) + j + 2), 1);
- CustomData_copy_data(&dm->loopData, &result->loopData, k2, (int)((numLoops * stride) + j + 3), 1);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, k2, (int)((numLoops * stride) + j + 0), 1);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, k1, (int)((numLoops * stride) + j + 1), 1);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, k1, (int)((numLoops * stride) + j + 2), 1);
+ CustomData_copy_data(&mesh->ldata, &result->ldata, k2, (int)((numLoops * stride) + j + 3), 1);
if (flip == false) {
ml[j].v = ed->v1;
@@ -907,6 +909,7 @@ static DerivedMesh *applyModifier(
int k;
/* note, only the first vertex (lower half of the index) is calculated */
+ BLI_assert(ed->v1 < numVerts);
normalize_v3_v3(nor_cpy, edge_vert_nos[ed_orig->v1]);
for (k = 0; k < 2; k++) { /* loop over both verts of the edge */
@@ -964,17 +967,25 @@ ModifierTypeInfo modifierType_Solidify = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_subsurf.c b/source/blender/modifiers/intern/MOD_subsurf.c
index 8711384e1ee..aea3aee8655 100644
--- a/source/blender/modifiers/intern/MOD_subsurf.c
+++ b/source/blender/modifiers/intern/MOD_subsurf.c
@@ -46,10 +46,12 @@
#include "BKE_cdderivedmesh.h"
-#include "BKE_depsgraph.h"
#include "BKE_scene.h"
#include "BKE_subsurf.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "MOD_modifiertypes.h"
#include "intern/CCGSubSurf.h"
@@ -96,18 +98,17 @@ static bool isDisabled(ModifierData *md, int useRenderParams)
return get_render_subsurf_level(&md->scene->r, levels, useRenderParams != 0) == 0;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag flag)
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
SubsurfModifierData *smd = (SubsurfModifierData *) md;
SubsurfFlags subsurf_flags = 0;
DerivedMesh *result;
- const bool useRenderParams = (flag & MOD_APPLY_RENDER) != 0;
- const bool isFinalCalc = (flag & MOD_APPLY_USECACHE) != 0;
+ const bool useRenderParams = (ctx->flag & MOD_APPLY_RENDER) != 0;
+ const bool isFinalCalc = (ctx->flag & MOD_APPLY_USECACHE) != 0;
#ifdef WITH_OPENSUBDIV
- const bool allow_gpu = (flag & MOD_APPLY_ALLOW_GPU) != 0;
+ const bool allow_gpu = (ctx->flag & MOD_APPLY_ALLOW_GPU) != 0;
#endif
bool do_cddm_convert = useRenderParams || !isFinalCalc;
@@ -115,7 +116,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
subsurf_flags |= SUBSURF_USE_RENDER_PARAMS;
if (isFinalCalc)
subsurf_flags |= SUBSURF_IS_FINAL_CALC;
- if (ob->mode & OB_MODE_EDIT)
+ if (ctx->object->mode & OB_MODE_EDIT)
subsurf_flags |= SUBSURF_IN_EDIT_MODE;
#ifdef WITH_OPENSUBDIV
@@ -130,10 +131,10 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
if (U.opensubdiv_compute_type == USER_OPENSUBDIV_COMPUTE_NONE) {
modifier_setError(md, "OpenSubdiv is disabled in User Preferences");
}
- else if ((ob->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) {
+ else if ((ctx->object->mode & (OB_MODE_VERTEX_PAINT | OB_MODE_WEIGHT_PAINT | OB_MODE_TEXTURE_PAINT)) != 0) {
modifier_setError(md, "OpenSubdiv is not supported in paint modes");
}
- else if ((DAG_get_eval_flags_for_object(md->scene, ob) & DAG_EVAL_NEED_CPU) == 0) {
+ else if ((DEG_get_eval_flags_for_id(ctx->depsgraph, &ctx->object->id) & DAG_EVAL_NEED_CPU) == 0) {
subsurf_flags |= SUBSURF_USE_GPU_BACKEND;
do_cddm_convert = false;
}
@@ -146,26 +147,30 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
result = subsurf_make_derived_from_derived(derivedData, smd, NULL, subsurf_flags);
result->cd_flag = derivedData->cd_flag;
- if (do_cddm_convert) {
+ {
DerivedMesh *cddm = CDDM_copy(result);
result->release(result);
result = cddm;
}
+#ifndef WITH_OPESUBDIV
+ (void) do_cddm_convert;
+#endif
+
return result;
}
-static DerivedMesh *applyModifierEM(ModifierData *md, Object *UNUSED(ob),
- struct BMEditMesh *UNUSED(editData),
- DerivedMesh *derivedData,
- ModifierApplyFlag flag)
+static DerivedMesh *applyModifierEM(
+ ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *UNUSED(editData),
+ DerivedMesh *derivedData)
{
SubsurfModifierData *smd = (SubsurfModifierData *) md;
DerivedMesh *result;
/* 'orco' using editmode flags would cause cache to be used twice in editbmesh_calc_modifiers */
- SubsurfFlags ss_flags = (flag & MOD_APPLY_ORCO) ? 0 : (SUBSURF_FOR_EDIT_MODE | SUBSURF_IN_EDIT_MODE);
+ SubsurfFlags ss_flags = (ctx->flag & MOD_APPLY_ORCO) ? 0 : (SUBSURF_FOR_EDIT_MODE | SUBSURF_IN_EDIT_MODE);
#ifdef WITH_OPENSUBDIV
- const bool allow_gpu = (flag & MOD_APPLY_ALLOW_GPU) != 0;
+ const bool allow_gpu = (ctx->flag & MOD_APPLY_ALLOW_GPU) != 0;
if (md->next == NULL && allow_gpu && smd->use_opensubdiv) {
modifier_setError(md, "OpenSubdiv is not supported in edit mode");
}
@@ -201,17 +206,25 @@ ModifierTypeInfo modifierType_Subsurf = {
eModifierTypeFlag_AcceptsCVs,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */applyModifierEM,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
- /* applyModifierEM */ applyModifierEM,
+ /* applyModifier */ NULL,
+ /* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ freeData,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
diff --git a/source/blender/modifiers/intern/MOD_surface.c b/source/blender/modifiers/intern/MOD_surface.c
index bed8f95fb87..752b81a5f10 100644
--- a/source/blender/modifiers/intern/MOD_surface.c
+++ b/source/blender/modifiers/intern/MOD_surface.c
@@ -85,11 +85,10 @@ static bool dependsOnTime(ModifierData *UNUSED(md))
return true;
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int UNUSED(numVerts),
- ModifierApplyFlag UNUSED(flag))
+ int UNUSED(numVerts))
{
SurfaceModifierData *surmd = (SurfaceModifierData *) md;
@@ -98,9 +97,9 @@ static void deformVerts(ModifierData *md, Object *ob,
/* if possible use/create DerivedMesh */
if (derivedData) surmd->dm = CDDM_copy(derivedData);
- else surmd->dm = get_dm(ob, NULL, NULL, NULL, false, false);
+ else surmd->dm = get_dm(ctx->object, NULL, NULL, NULL, false, false);
- if (!ob->pd) {
+ if (!ctx->object->pd) {
printf("SurfaceModifier deformVerts: Should not happen!\n");
return;
}
@@ -141,7 +140,7 @@ static void deformVerts(ModifierData *md, Object *ob,
/* convert to global coordinates and calculate velocity */
for (i = 0, x = surmd->x, v = surmd->v; i < numverts; i++, x++, v++) {
vec = CDDM_get_vert(surmd->dm, i)->co;
- mul_m4_v3(ob->obmat, vec);
+ mul_m4_v3(ctx->object->obmat, vec);
if (init)
v->co[0] = v->co[1] = v->co[2] = 0.0f;
@@ -176,17 +175,25 @@ ModifierTypeInfo modifierType_Surface = {
eModifierTypeFlag_NoUserAdd,
/* copyData */ NULL,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ freeData,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_surfacedeform.c b/source/blender/modifiers/intern/MOD_surfacedeform.c
index e0c94d456c2..bedce88326e 100644
--- a/source/blender/modifiers/intern/MOD_surfacedeform.c
+++ b/source/blender/modifiers/intern/MOD_surfacedeform.c
@@ -11,7 +11,7 @@
#include "BKE_library_query.h"
#include "BKE_modifier.h"
-#include "depsgraph_private.h"
+#include "DEG_depsgraph.h"
#include "MEM_guardedalloc.h"
@@ -170,17 +170,6 @@ static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk,
walk(userData, ob, &smd->target, IDWALK_NOP);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
-
- if (smd->target) {
- DagNode *curNode = dag_get_node(ctx->forest, smd->target);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA, "Surface Deform Modifier");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
@@ -1106,7 +1095,9 @@ static void deformVert(
}
}
-static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], unsigned int numverts, Object *ob)
+static void surfacedeformModifier_do(
+ ModifierData *md,
+ float (*vertexCos)[3], unsigned int numverts, Object *ob)
{
SurfaceDeformModifierData *smd = (SurfaceDeformModifierData *)md;
DerivedMesh *tdm;
@@ -1119,7 +1110,7 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
}
/* Handle target mesh both in and out of edit mode */
- if (smd->target == md->scene->obedit) {
+ if (smd->target->mode & OB_MODE_EDIT) {
BMEditMesh *em = BKE_editmesh_from_object(smd->target);
tdm = em->derivedFinal;
}
@@ -1189,20 +1180,21 @@ static void surfacedeformModifier_do(ModifierData *md, float (*vertexCos)[3], un
}
}
-static void deformVerts(ModifierData *md, Object *ob,
- DerivedMesh *UNUSED(derivedData),
- float (*vertexCos)[3], int numVerts,
- ModifierApplyFlag UNUSED(flag))
+static void deformVerts(
+ ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *UNUSED(derivedData),
+ float (*vertexCos)[3], int numVerts)
{
- surfacedeformModifier_do(md, vertexCos, numVerts, ob);
+ surfacedeformModifier_do(md, vertexCos, numVerts, ctx->object);
}
-static void deformVertsEM(ModifierData *md, Object *ob,
- struct BMEditMesh *UNUSED(editData),
- DerivedMesh *UNUSED(derivedData),
- float (*vertexCos)[3], int numVerts)
+static void deformVertsEM(
+ ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *UNUSED(editData),
+ DerivedMesh *UNUSED(derivedData),
+ float (*vertexCos)[3], int numVerts)
{
- surfacedeformModifier_do(md, vertexCos, numVerts, ob);
+ surfacedeformModifier_do(md, vertexCos, numVerts, ctx->object);
}
static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
@@ -1221,17 +1213,25 @@ ModifierTypeInfo modifierType_SurfaceDeform = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL,
/* freeData */ freeData,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_triangulate.c b/source/blender/modifiers/intern/MOD_triangulate.c
index b057d6d5a86..349897f2be6 100644
--- a/source/blender/modifiers/intern/MOD_triangulate.c
+++ b/source/blender/modifiers/intern/MOD_triangulate.c
@@ -85,9 +85,8 @@ static void copyData(ModifierData *md, ModifierData *target)
}
static DerivedMesh *applyModifier(ModifierData *md,
- Object *UNUSED(ob),
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+ const ModifierEvalContext *UNUSED(ctx),
+ DerivedMesh *dm)
{
TriangulateModifierData *tmd = (TriangulateModifierData *)md;
DerivedMesh *result;
@@ -110,17 +109,25 @@ ModifierTypeInfo modifierType_Triangulate = {
eModifierTypeFlag_AcceptsCVs,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ NULL, //requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ NULL,
/* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_util.c b/source/blender/modifiers/intern/MOD_util.c
index 5b19bcf4817..e59d7200880 100644
--- a/source/blender/modifiers/intern/MOD_util.c
+++ b/source/blender/modifiers/intern/MOD_util.c
@@ -34,9 +34,11 @@
#include "DNA_image_types.h"
#include "DNA_meshdata_types.h"
+#include "DNA_mesh_types.h"
#include "DNA_modifier_types.h"
#include "DNA_object_types.h"
#include "DNA_scene_types.h"
+#include "DNA_scene_types.h"
#include "BLI_utildefines.h"
#include "BLI_math_vector.h"
@@ -216,6 +218,21 @@ DerivedMesh *get_dm_for_modifier(Object *ob, ModifierApplyFlag flag)
}
}
+/* Get evaluated mesh for other object, which is used as an operand for the modifier,
+ * i.e. second operand for boolean modifier.
+ */
+Mesh *get_mesh_eval_for_modifier(Object *ob, ModifierApplyFlag flag)
+{
+ if (flag & MOD_APPLY_RENDER) {
+ /* TODO(sergey): Use proper derived render in the future. */
+ return ob->mesh_evaluated;
+ }
+ else {
+ return ob->mesh_evaluated;
+ }
+}
+
+
void modifier_get_vgroup(Object *ob, DerivedMesh *dm, const char *name, MDeformVert **dvert, int *defgrp_index)
{
*defgrp_index = defgroup_name_index(ob, name);
@@ -229,6 +246,20 @@ void modifier_get_vgroup(Object *ob, DerivedMesh *dm, const char *name, MDeformV
}
}
+/* TODO(sybren): replace the above function with this one, once we got rid of DerivedMesh for modifiers. */
+void modifier_get_vgroup_mesh(Object *ob, struct Mesh *mesh, const char *name, MDeformVert **dvert, int *defgrp_index)
+{
+ *defgrp_index = defgroup_name_index(ob, name);
+ *dvert = NULL;
+
+ if (*defgrp_index != -1) {
+ if (ob->type == OB_LATTICE)
+ *dvert = BKE_lattice_deform_verts_get(ob);
+ else if (mesh)
+ *dvert = mesh->dvert;
+ }
+}
+
/* only called by BKE_modifier.h/modifier.c */
void modifier_type_init(ModifierTypeInfo *types[])
diff --git a/source/blender/modifiers/intern/MOD_util.h b/source/blender/modifiers/intern/MOD_util.h
index 095d7c278df..b18529abd0c 100644
--- a/source/blender/modifiers/intern/MOD_util.h
+++ b/source/blender/modifiers/intern/MOD_util.h
@@ -35,6 +35,7 @@
struct DerivedMesh;
struct MDeformVert;
+struct Mesh;
struct ModifierData;
struct Object;
struct Scene;
@@ -49,7 +50,11 @@ struct DerivedMesh *get_cddm(struct Object *ob, struct BMEditMesh *em, struct De
struct DerivedMesh *get_dm(struct Object *ob, struct BMEditMesh *em, struct DerivedMesh *dm,
float (*vertexCos)[3], bool use_normals, bool use_orco);
struct DerivedMesh *get_dm_for_modifier(struct Object *ob, ModifierApplyFlag flag);
+struct Mesh *get_mesh_eval_for_modifier(struct Object *ob, ModifierApplyFlag flag);
+
void modifier_get_vgroup(struct Object *ob, struct DerivedMesh *dm,
const char *name, struct MDeformVert **dvert, int *defgrp_index);
+void modifier_get_vgroup_mesh(struct Object *ob, struct Mesh *mesh,
+ const char *name, struct MDeformVert **dvert, int *defgrp_index);
#endif /* __MOD_UTIL_H__ */
diff --git a/source/blender/modifiers/intern/MOD_uvproject.c b/source/blender/modifiers/intern/MOD_uvproject.c
index 1cefb07b50a..620d3c34584 100644
--- a/source/blender/modifiers/intern/MOD_uvproject.c
+++ b/source/blender/modifiers/intern/MOD_uvproject.c
@@ -47,6 +47,7 @@
#include "BKE_camera.h"
#include "BKE_library.h"
#include "BKE_library_query.h"
+#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_DerivedMesh.h"
@@ -54,14 +55,13 @@
#include "MEM_guardedalloc.h"
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
static void initData(ModifierData *md)
{
UVProjectModifierData *umd = (UVProjectModifierData *) md;
- umd->flags = 0;
+
umd->num_projectors = 1;
umd->aspectx = umd->aspecty = 1.0f;
umd->scalex = umd->scaley = 1.0f;
@@ -71,12 +71,10 @@ static void copyData(ModifierData *md, ModifierData *target)
{
#if 0
UVProjectModifierData *umd = (UVProjectModifierData *) md;
-#endif
UVProjectModifierData *tumd = (UVProjectModifierData *) target;
+#endif
modifier_copyData_generic(md, target);
-
- id_us_plus((ID *)tumd->image);
}
static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(md))
@@ -84,7 +82,7 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *UNUSED(
CustomDataMask dataMask = 0;
/* ask for UV coordinates */
- dataMask |= CD_MLOOPUV | CD_MTEXPOLY;
+ dataMask |= CD_MLOOPUV;
return dataMask;
}
@@ -102,28 +100,13 @@ static void foreachObjectLink(ModifierData *md, Object *ob,
static void foreachIDLink(ModifierData *md, Object *ob,
IDWalkFunc walk, void *userData)
{
+#if 0
UVProjectModifierData *umd = (UVProjectModifierData *) md;
-
- walk(userData, ob, (ID **)&umd->image, IDWALK_CB_USER);
+#endif
foreachObjectLink(md, ob, (ObjectWalkFunc)walk, userData);
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- UVProjectModifierData *umd = (UVProjectModifierData *) md;
- int i;
-
- for (i = 0; i < umd->num_projectors; ++i) {
- if (umd->projectors[i]) {
- DagNode *curNode = dag_get_node(ctx->forest, umd->projectors[i]);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode,
- DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "UV Project Modifier");
- }
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
UVProjectModifierData *umd = (UVProjectModifierData *)md;
@@ -147,12 +130,9 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
{
float (*coords)[3], (*co)[3];
MLoopUV *mloop_uv;
- MTexPoly *mtexpoly, *mt = NULL;
int i, numVerts, numPolys, numLoops;
- Image *image = umd->image;
MPoly *mpoly, *mp;
MLoop *mloop;
- const bool override_image = (umd->flags & MOD_UVPROJECT_OVERRIDEIMAGE) != 0;
Projector projectors[MOD_UVPROJECT_MAXPROJECTORS];
int num_projectors = 0;
char uvname[MAX_CUSTOMDATA_LAYER_NAME];
@@ -237,10 +217,6 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
mloop_uv = CustomData_duplicate_referenced_layer_named(&dm->loopData,
CD_MLOOPUV, uvname, numLoops);
- /* can be NULL */
- mt = mtexpoly = CustomData_duplicate_referenced_layer_named(&dm->polyData,
- CD_MTEXPOLY, uvname, numPolys);
-
numVerts = dm->getNumVerts(dm);
coords = MEM_malloc_arrayN(numVerts, sizeof(*coords),
@@ -259,79 +235,72 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
mpoly = dm->getPolyArray(dm);
mloop = dm->getLoopArray(dm);
- /* apply coords as UVs, and apply image if tfaces are new */
- for (i = 0, mp = mpoly; i < numPolys; ++i, ++mp, ++mt) {
- if (override_image || !image || (mtexpoly == NULL || mt->tpage == image)) {
- if (num_projectors == 1) {
- if (projectors[0].uci) {
- unsigned int fidx = mp->totloop - 1;
- do {
- unsigned int lidx = mp->loopstart + fidx;
- unsigned int vidx = mloop[lidx].v;
- BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], projectors[0].uci);
- } while (fidx--);
- }
- else {
- /* apply transformed coords as UVs */
- unsigned int fidx = mp->totloop - 1;
- do {
- unsigned int lidx = mp->loopstart + fidx;
- unsigned int vidx = mloop[lidx].v;
- copy_v2_v2(mloop_uv[lidx].uv, coords[vidx]);
- } while (fidx--);
- }
+ /* apply coords as UVs */
+ for (i = 0, mp = mpoly; i < numPolys; ++i, ++mp) {
+ if (num_projectors == 1) {
+ if (projectors[0].uci) {
+ unsigned int fidx = mp->totloop - 1;
+ do {
+ unsigned int lidx = mp->loopstart + fidx;
+ unsigned int vidx = mloop[lidx].v;
+ BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], projectors[0].uci);
+ } while (fidx--);
}
else {
- /* multiple projectors, select the closest to face normal direction */
- float face_no[3];
- int j;
- Projector *best_projector;
- float best_dot;
-
- /* get the untransformed face normal */
- BKE_mesh_calc_poly_normal_coords(mp, mloop + mp->loopstart, (const float (*)[3])coords, face_no);
-
- /* find the projector which the face points at most directly
- * (projector normal with largest dot product is best)
- */
- best_dot = dot_v3v3(projectors[0].normal, face_no);
- best_projector = &projectors[0];
-
- for (j = 1; j < num_projectors; ++j) {
- float tmp_dot = dot_v3v3(projectors[j].normal,
- face_no);
- if (tmp_dot > best_dot) {
- best_dot = tmp_dot;
- best_projector = &projectors[j];
- }
- }
-
- if (best_projector->uci) {
- unsigned int fidx = mp->totloop - 1;
- do {
- unsigned int lidx = mp->loopstart + fidx;
- unsigned int vidx = mloop[lidx].v;
- BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], best_projector->uci);
- } while (fidx--);
- }
- else {
- unsigned int fidx = mp->totloop - 1;
- do {
- unsigned int lidx = mp->loopstart + fidx;
- unsigned int vidx = mloop[lidx].v;
- mul_v2_project_m4_v3(mloop_uv[lidx].uv, best_projector->projmat, coords[vidx]);
- } while (fidx--);
- }
+ /* apply transformed coords as UVs */
+ unsigned int fidx = mp->totloop - 1;
+ do {
+ unsigned int lidx = mp->loopstart + fidx;
+ unsigned int vidx = mloop[lidx].v;
+ copy_v2_v2(mloop_uv[lidx].uv, coords[vidx]);
+ } while (fidx--);
}
}
+ else {
+ /* multiple projectors, select the closest to face normal direction */
+ float face_no[3];
+ int j;
+ Projector *best_projector;
+ float best_dot;
+
+ /* get the untransformed face normal */
+ BKE_mesh_calc_poly_normal_coords(mp, mloop + mp->loopstart, (const float (*)[3])coords, face_no);
+
+ /* find the projector which the face points at most directly
+ * (projector normal with largest dot product is best)
+ */
+ best_dot = dot_v3v3(projectors[0].normal, face_no);
+ best_projector = &projectors[0];
+
+ for (j = 1; j < num_projectors; ++j) {
+ float tmp_dot = dot_v3v3(projectors[j].normal, face_no);
+ if (tmp_dot > best_dot) {
+ best_dot = tmp_dot;
+ best_projector = &projectors[j];
+ }
+ }
- if (override_image && mtexpoly) {
- mt->tpage = image;
+ if (best_projector->uci) {
+ unsigned int fidx = mp->totloop - 1;
+ do {
+ unsigned int lidx = mp->loopstart + fidx;
+ unsigned int vidx = mloop[lidx].v;
+ BLI_uvproject_from_camera(mloop_uv[lidx].uv, coords[vidx], best_projector->uci);
+ } while (fidx--);
+ }
+ else {
+ unsigned int fidx = mp->totloop - 1;
+ do {
+ unsigned int lidx = mp->loopstart + fidx;
+ unsigned int vidx = mloop[lidx].v;
+ mul_v2_project_m4_v3(mloop_uv[lidx].uv, best_projector->projmat, coords[vidx]);
+ } while (fidx--);
+ }
}
}
MEM_freeN(coords);
-
+
if (free_uci) {
int j;
for (j = 0; j < num_projectors; ++j) {
@@ -347,14 +316,13 @@ static DerivedMesh *uvprojectModifier_do(UVProjectModifierData *umd,
return dm;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
DerivedMesh *result;
UVProjectModifierData *umd = (UVProjectModifierData *) md;
- result = uvprojectModifier_do(umd, ob, derivedData);
+ result = uvprojectModifier_do(umd, ctx->object, derivedData);
return result;
}
@@ -371,17 +339,25 @@ ModifierTypeInfo modifierType_UVProject = {
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_uvwarp.c b/source/blender/modifiers/intern/MOD_uvwarp.c
index 384efc74666..7ea2d6ad3b3 100644
--- a/source/blender/modifiers/intern/MOD_uvwarp.c
+++ b/source/blender/modifiers/intern/MOD_uvwarp.c
@@ -40,8 +40,6 @@
#include "BKE_library_query.h"
#include "BKE_modifier.h"
-#include "depsgraph_private.h"
-
#include "MOD_util.h"
@@ -148,9 +146,8 @@ static void uv_warp_compute(
}
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
- DerivedMesh *dm,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *dm)
{
UVWarpModifierData *umd = (UVWarpModifierData *) md;
int numPolys, numLoops;
@@ -208,7 +205,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob,
mloop = dm->getLoopArray(dm);
/* make sure we are not modifying the original UV map */
mloopuv = CustomData_duplicate_referenced_layer_named(&dm->loopData, CD_MLOOPUV, uvname, numLoops);
- modifier_get_vgroup(ob, dm, umd->vgroup_name, &dvert, &defgrp_index);
+ modifier_get_vgroup(ctx->object, dm, umd->vgroup_name, &dvert, &defgrp_index);
UVWarpData data = {.mpoly = mpoly, .mloop = mloop, .mloopuv = mloopuv,
.dvert = dvert, .defgrp_index = defgrp_index,
@@ -234,27 +231,6 @@ static void foreachObjectLink(ModifierData *md, Object *ob, ObjectWalkFunc walk,
walk(userData, ob, &umd->object_src, IDWALK_CB_NOP);
}
-static void uv_warp_deps_object_bone(DagForest *forest, DagNode *obNode,
- Object *obj, const char *bonename)
-{
- if (obj) {
- DagNode *curNode = dag_get_node(forest, obj);
-
- if (bonename[0])
- dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA | DAG_RL_DATA_DATA, "UVWarp Modifier");
- else
- dag_add_relation(forest, curNode, obNode, DAG_RL_OB_DATA, "UVWarp Modifier");
- }
-}
-
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- UVWarpModifierData *umd = (UVWarpModifierData *) md;
-
- uv_warp_deps_object_bone(ctx->forest, ctx->obNode, umd->object_src, umd->bone_src);
- uv_warp_deps_object_bone(ctx->forest, ctx->obNode, umd->object_dst, umd->bone_dst);
-}
-
static void uv_warp_deps_object_bone_new(struct DepsNodeHandle *node,
Object *object,
const char *bonename)
@@ -284,17 +260,25 @@ ModifierTypeInfo modifierType_UVWarp = {
eModifierTypeFlag_SupportsEditmode |
eModifierTypeFlag_EnableInEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_warp.c b/source/blender/modifiers/intern/MOD_warp.c
index 00d7906a442..f4ec7686a22 100644
--- a/source/blender/modifiers/intern/MOD_warp.c
+++ b/source/blender/modifiers/intern/MOD_warp.c
@@ -42,8 +42,6 @@
#include "BKE_texture.h"
#include "BKE_colortools.h"
-#include "depsgraph_private.h"
-
#include "RE_shader_ext.h"
#include "MOD_util.h"
@@ -139,24 +137,6 @@ static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void
walk(userData, ob, md, "texture");
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- WarpModifierData *wmd = (WarpModifierData *) md;
-
- if (wmd->object_from && wmd->object_to) {
- DagNode *fromNode = dag_get_node(ctx->forest, wmd->object_from);
- DagNode *toNode = dag_get_node(ctx->forest, wmd->object_to);
-
- dag_add_relation(ctx->forest, fromNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Warp Modifier1");
- dag_add_relation(ctx->forest, toNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Warp Modifier2");
- }
-
- if ((wmd->texmapping == MOD_DISP_MAP_OBJECT) && wmd->map_object) {
- DagNode *curNode = dag_get_node(ctx->forest, wmd->map_object);
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA, "Warp Modifier3");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
WarpModifierData *wmd = (WarpModifierData *) md;
@@ -329,24 +309,24 @@ static int warp_needs_dm(WarpModifierData *wmd)
return wmd->texture || wmd->defgrp_name[0];
}
-static void deformVerts(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- float (*vertexCos)[3], int numVerts, ModifierApplyFlag UNUSED(flag))
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx, DerivedMesh *derivedData,
+ float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm = NULL;
int use_dm = warp_needs_dm((WarpModifierData *)md);
if (use_dm) {
- dm = get_cddm(ob, NULL, derivedData, vertexCos, false);
+ dm = get_cddm(ctx->object, NULL, derivedData, vertexCos, false);
}
- warpModifier_do((WarpModifierData *)md, ob, dm, vertexCos, numVerts);
+ warpModifier_do((WarpModifierData *)md, ctx->object, dm, vertexCos, numVerts);
if (use_dm) {
if (dm != derivedData) dm->release(dm);
}
}
-static void deformVertsEM(ModifierData *md, Object *ob, struct BMEditMesh *em,
+static void deformVertsEM(ModifierData *md, const ModifierEvalContext *ctx, struct BMEditMesh *em,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm = derivedData;
@@ -357,7 +337,7 @@ static void deformVertsEM(ModifierData *md, Object *ob, struct BMEditMesh *em,
dm = CDDM_from_editbmesh(em, false, false);
}
- deformVerts(md, ob, dm, vertexCos, numVerts, 0);
+ deformVerts(md, ctx, dm, vertexCos, numVerts);
if (use_dm) {
if (!derivedData) dm->release(dm);
@@ -374,17 +354,25 @@ ModifierTypeInfo modifierType_Warp = {
eModifierTypeFlag_AcceptsLattice |
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_wave.c b/source/blender/modifiers/intern/MOD_wave.c
index 8fe29c78486..c5af7755578 100644
--- a/source/blender/modifiers/intern/MOD_wave.c
+++ b/source/blender/modifiers/intern/MOD_wave.c
@@ -49,14 +49,15 @@
#include "BKE_scene.h"
#include "BKE_texture.h"
-#include "depsgraph_private.h"
-
#include "MEM_guardedalloc.h"
#include "RE_shader_ext.h"
#include "MOD_modifiertypes.h"
#include "MOD_util.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
static void initData(ModifierData *md)
{
WaveModifierData *wmd = (WaveModifierData *) md; // whadya know, moved here from Iraq
@@ -119,25 +120,6 @@ static void foreachTexLink(ModifierData *md, Object *ob,
walk(userData, ob, md, "texture");
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- WaveModifierData *wmd = (WaveModifierData *) md;
-
- if (wmd->objectcenter) {
- DagNode *curNode = dag_get_node(ctx->forest, wmd->objectcenter);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_OB_DATA,
- "Wave Modifier");
- }
-
- if (wmd->map_object) {
- DagNode *curNode = dag_get_node(ctx->forest, wmd->map_object);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_OB_DATA,
- "Wave Modifer");
- }
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
WaveModifierData *wmd = (WaveModifierData *)md;
@@ -166,15 +148,16 @@ static CustomDataMask requiredDataMask(Object *UNUSED(ob), ModifierData *md)
return dataMask;
}
-static void waveModifier_do(WaveModifierData *md,
- Scene *scene, Object *ob, DerivedMesh *dm,
+static void waveModifier_do(WaveModifierData *md,
+ Depsgraph *depsgraph,
+ Object *ob, DerivedMesh *dm,
float (*vertexCos)[3], int numVerts)
{
WaveModifierData *wmd = (WaveModifierData *) md;
MVert *mvert = NULL;
MDeformVert *dvert;
int defgrp_index;
- float ctime = BKE_scene_frame_get(scene);
+ float ctime = DEG_get_ctime(depsgraph);
float minfac = (float)(1.0 / exp(wmd->width * wmd->narrow * wmd->width * wmd->narrow));
float lifefac = wmd->height;
float (*tex_co)[3] = NULL;
@@ -319,39 +302,39 @@ static void waveModifier_do(WaveModifierData *md,
if (wmd->texture) MEM_freeN(tex_co);
}
-static void deformVerts(ModifierData *md, Object *ob,
+static void deformVerts(ModifierData *md, const ModifierEvalContext *ctx,
DerivedMesh *derivedData,
float (*vertexCos)[3],
- int numVerts,
- ModifierApplyFlag UNUSED(flag))
+ int numVerts)
{
DerivedMesh *dm = derivedData;
WaveModifierData *wmd = (WaveModifierData *)md;
if (wmd->flag & MOD_WAVE_NORM)
- dm = get_cddm(ob, NULL, dm, vertexCos, false);
+ dm = get_cddm(ctx->object, NULL, dm, vertexCos, false);
else if (wmd->texture || wmd->defgrp_name[0])
- dm = get_dm(ob, NULL, dm, NULL, false, false);
+ dm = get_dm(ctx->object, NULL, dm, NULL, false, false);
- waveModifier_do(wmd, md->scene, ob, dm, vertexCos, numVerts);
+ waveModifier_do(wmd, ctx->depsgraph, ctx->object, dm, vertexCos, numVerts);
if (dm != derivedData)
dm->release(dm);
}
static void deformVertsEM(
- ModifierData *md, Object *ob, struct BMEditMesh *editData,
+ ModifierData *md, const ModifierEvalContext *ctx,
+ struct BMEditMesh *editData,
DerivedMesh *derivedData, float (*vertexCos)[3], int numVerts)
{
DerivedMesh *dm = derivedData;
WaveModifierData *wmd = (WaveModifierData *)md;
if (wmd->flag & MOD_WAVE_NORM)
- dm = get_cddm(ob, editData, dm, vertexCos, false);
+ dm = get_cddm(ctx->object, editData, dm, vertexCos, false);
else if (wmd->texture || wmd->defgrp_name[0])
- dm = get_dm(ob, editData, dm, NULL, false, false);
+ dm = get_dm(ctx->object, editData, dm, NULL, false, false);
- waveModifier_do(wmd, md->scene, ob, dm, vertexCos, numVerts);
+ waveModifier_do(wmd, ctx->depsgraph, ctx->object, dm, vertexCos, numVerts);
if (dm != derivedData)
dm->release(dm);
@@ -367,17 +350,25 @@ ModifierTypeInfo modifierType_Wave = {
eModifierTypeFlag_AcceptsLattice |
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
- /* deformVerts */ deformVerts,
+
+ /* deformVerts_DM */ deformVerts,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ deformVertsEM,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
+ /* deformVerts */ NULL,
/* deformMatrices */ NULL,
- /* deformVertsEM */ deformVertsEM,
+ /* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_weightvgedit.c b/source/blender/modifiers/intern/MOD_weightvgedit.c
index 8d77747b45d..1a9651909dd 100644
--- a/source/blender/modifiers/intern/MOD_weightvgedit.c
+++ b/source/blender/modifiers/intern/MOD_weightvgedit.c
@@ -46,7 +46,6 @@
#include "BKE_modifier.h"
#include "BKE_texture.h" /* Texture masking. */
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MEM_guardedalloc.h"
@@ -137,23 +136,6 @@ static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void
walk(userData, ob, md, "mask_texture");
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
- DagNode *curNode;
-
- if (wmd->mask_tex_map_obj && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) {
- curNode = dag_get_node(ctx->forest, wmd->mask_tex_map_obj);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "WeightVGEdit Modifier");
- }
-
- if (wmd->mask_tex_mapping == MOD_DISP_MAP_GLOBAL)
- dag_add_relation(ctx->forest, ctx->obNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "WeightVGEdit Modifier");
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *)md;
@@ -172,8 +154,9 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
return (wmd->defgrp_name[0] == '\0');
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md,
+ const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
WeightVGEditModifierData *wmd = (WeightVGEditModifierData *) md;
DerivedMesh *dm = derivedData;
@@ -198,11 +181,11 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
/* Check if we can just return the original mesh.
* Must have verts and therefore verts assigned to vgroups to do anything useful!
*/
- if ((numVerts == 0) || BLI_listbase_is_empty(&ob->defbase))
+ if ((numVerts == 0) || BLI_listbase_is_empty(&ctx->object->defbase))
return dm;
/* Get vgroup idx from its name. */
- defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
+ defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name);
if (defgrp_index == -1)
return dm;
@@ -238,7 +221,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
RNG *rng = NULL;
if (wmd->falloff_type == MOD_WVG_MAPPING_RANDOM)
- rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ob->id.name + 2));
+ rng = BLI_rng_new_srandom(BLI_ghashutil_strhash(ctx->object->id.name + 2));
weightvg_do_map(numVerts, new_w, wmd->falloff_type, wmd->cmap_curve, rng);
@@ -247,7 +230,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
}
/* Do masking. */
- weightvg_do_mask(numVerts, NULL, org_w, new_w, ob, dm, wmd->mask_constant,
+ weightvg_do_mask(numVerts, NULL, org_w, new_w, ctx->object, dm, wmd->mask_constant,
wmd->mask_defgrp_name, wmd->modifier.scene, wmd->mask_texture,
wmd->mask_tex_use_channel, wmd->mask_tex_mapping,
wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name);
@@ -283,17 +266,25 @@ ModifierTypeInfo modifierType_WeightVGEdit = {
eModifierTypeFlag_UsesPreview,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ freeData,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_weightvgmix.c b/source/blender/modifiers/intern/MOD_weightvgmix.c
index bd1f58e7d5e..9f32d5c6e30 100644
--- a/source/blender/modifiers/intern/MOD_weightvgmix.c
+++ b/source/blender/modifiers/intern/MOD_weightvgmix.c
@@ -43,7 +43,6 @@
#include "BKE_modifier.h"
#include "BKE_texture.h" /* Texture masking. */
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MEM_guardedalloc.h"
@@ -182,23 +181,6 @@ static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void
walk(userData, ob, md, "mask_texture");
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- WeightVGMixModifierData *wmd = (WeightVGMixModifierData *) md;
- DagNode *curNode;
-
- if (wmd->mask_tex_map_obj && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) {
- curNode = dag_get_node(ctx->forest, wmd->mask_tex_map_obj);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "WeightVGMix Modifier");
- }
-
- if (wmd->mask_tex_mapping == MOD_DISP_MAP_GLOBAL)
- dag_add_relation(ctx->forest, ctx->obNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "WeightVGMix Modifier");
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *) md;
@@ -219,8 +201,8 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
return (wmd->defgrp_name_a[0] == '\0');
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
WeightVGMixModifierData *wmd = (WeightVGMixModifierData *) md;
DerivedMesh *dm = derivedData;
@@ -244,16 +226,16 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
/* Check if we can just return the original mesh.
* Must have verts and therefore verts assigned to vgroups to do anything useful!
*/
- if ((numVerts == 0) || BLI_listbase_is_empty(&ob->defbase))
+ if ((numVerts == 0) || BLI_listbase_is_empty(&ctx->object->defbase))
return dm;
/* Get vgroup idx from its name. */
- defgrp_index = defgroup_name_index(ob, wmd->defgrp_name_a);
+ defgrp_index = defgroup_name_index(ctx->object, wmd->defgrp_name_a);
if (defgrp_index == -1)
return dm;
/* Get second vgroup idx from its name, if given. */
if (wmd->defgrp_name_b[0] != (char)0) {
- defgrp_index_other = defgroup_name_index(ob, wmd->defgrp_name_b);
+ defgrp_index_other = defgroup_name_index(ctx->object, wmd->defgrp_name_b);
if (defgrp_index_other == -1)
return dm;
}
@@ -370,7 +352,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
}
/* Do masking. */
- weightvg_do_mask(numIdx, indices, org_w, new_w, ob, dm, wmd->mask_constant,
+ weightvg_do_mask(numIdx, indices, org_w, new_w, ctx->object, dm, wmd->mask_constant,
wmd->mask_defgrp_name, wmd->modifier.scene, wmd->mask_texture,
wmd->mask_tex_use_channel, wmd->mask_tex_mapping,
wmd->mask_tex_map_obj, wmd->mask_tex_uvlayer_name);
@@ -411,17 +393,25 @@ ModifierTypeInfo modifierType_WeightVGMix = {
eModifierTypeFlag_UsesPreview,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_weightvgproximity.c b/source/blender/modifiers/intern/MOD_weightvgproximity.c
index 2b17efe7b24..b0416ed9f7a 100644
--- a/source/blender/modifiers/intern/MOD_weightvgproximity.c
+++ b/source/blender/modifiers/intern/MOD_weightvgproximity.c
@@ -47,7 +47,6 @@
#include "BKE_modifier.h"
#include "BKE_texture.h" /* Texture masking. */
-#include "depsgraph_private.h"
#include "DEG_depsgraph_build.h"
#include "MEM_guardedalloc.h"
@@ -343,29 +342,6 @@ static void foreachTexLink(ModifierData *md, Object *ob, TexWalkFunc walk, void
walk(userData, ob, md, "mask_texture");
}
-static void updateDepgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
-{
- WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
- DagNode *curNode;
-
- if (wmd->proximity_ob_target) {
- curNode = dag_get_node(ctx->forest, wmd->proximity_ob_target);
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "WeightVGProximity Modifier");
- }
-
- if (wmd->mask_tex_map_obj && wmd->mask_tex_mapping == MOD_DISP_MAP_OBJECT) {
- curNode = dag_get_node(ctx->forest, wmd->mask_tex_map_obj);
-
- dag_add_relation(ctx->forest, curNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "WeightVGProximity Modifier");
- }
-
- if (wmd->mask_tex_mapping == MOD_DISP_MAP_GLOBAL)
- dag_add_relation(ctx->forest, ctx->obNode, ctx->obNode, DAG_RL_DATA_DATA | DAG_RL_OB_DATA,
- "WeightVGProximity Modifier");
-}
-
static void updateDepsgraph(ModifierData *md, const ModifierUpdateDepsgraphContext *ctx)
{
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *)md;
@@ -392,8 +368,8 @@ static bool isDisabled(ModifierData *md, int UNUSED(useRenderParams))
return (wmd->proximity_ob_target == NULL);
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *derivedData,
- ModifierApplyFlag UNUSED(flag))
+static DerivedMesh *applyModifier(ModifierData *md, const ModifierEvalContext *ctx,
+ DerivedMesh *derivedData)
{
WeightVGProximityModifierData *wmd = (WeightVGProximityModifierData *) md;
DerivedMesh *dm = derivedData;
@@ -401,6 +377,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
MDeformWeight **dw, **tdw;
int numVerts;
float (*v_cos)[3] = NULL; /* The vertices coordinates. */
+ Object *ob = ctx->object;
Object *obr = NULL; /* Our target object. */
int defgrp_index;
float *tw = NULL;
@@ -424,7 +401,7 @@ static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *der
/* Check if we can just return the original mesh.
* Must have verts and therefore verts assigned to vgroups to do anything useful!
*/
- if ((numVerts == 0) || BLI_listbase_is_empty(&ob->defbase))
+ if ((numVerts == 0) || BLI_listbase_is_empty(&ctx->object->defbase))
return dm;
/* Get our target object. */
@@ -600,17 +577,25 @@ ModifierTypeInfo modifierType_WeightVGProximity = {
eModifierTypeFlag_UsesPreview,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ applyModifier,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
- /* applyModifier */ applyModifier,
+ /* applyModifier */ NULL,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ isDisabled,
- /* updateDepgraph */ updateDepgraph,
/* updateDepsgraph */ updateDepsgraph,
/* dependsOnTime */ dependsOnTime,
/* dependsOnNormals */ NULL,
diff --git a/source/blender/modifiers/intern/MOD_wireframe.c b/source/blender/modifiers/intern/MOD_wireframe.c
index 15f8b185a3d..3c6717d3b36 100644
--- a/source/blender/modifiers/intern/MOD_wireframe.c
+++ b/source/blender/modifiers/intern/MOD_wireframe.c
@@ -23,12 +23,14 @@
* \ingroup modifiers
*/
+#include "DNA_mesh_types.h"
#include "DNA_object_types.h"
#include "BLI_utildefines.h"
#include "BKE_cdderivedmesh.h"
#include "BKE_deform.h"
+#include "BKE_mesh.h"
#include "MOD_modifiertypes.h"
@@ -69,14 +71,22 @@ static bool dependsOnNormals(ModifierData *UNUSED(md))
return true;
}
-static DerivedMesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob, DerivedMesh *dm)
+static Mesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob, Mesh *mesh)
{
- DerivedMesh *result;
+ Mesh *result;
BMesh *bm;
const int defgrp_index = defgroup_name_index(ob, wmd->defgrp_name);
- bm = DM_to_bmesh(dm, true);
+ bm = BKE_mesh_to_bmesh_ex(
+ mesh,
+ &(struct BMeshCreateParams){0},
+ &(struct BMeshFromMeshParams){
+ .calc_face_normal = true,
+ .add_key_index = false,
+ .use_shapekey = true,
+ .active_shapekey = ob->shapenr,
+ });
BM_mesh_wireframe(
bm,
@@ -93,18 +103,21 @@ static DerivedMesh *WireframeModifier_do(WireframeModifierData *wmd, Object *ob,
MAX2(ob->totcol - 1, 0),
false);
- result = CDDM_from_bmesh(bm, true);
+ result = BKE_bmesh_to_mesh(bm, &(struct BMeshToMeshParams){0});
BM_mesh_free(bm);
- result->dirty |= DM_DIRTY_NORMALS;
+ result->runtime.cd_dirty_vert |= CD_MASK_NORMAL;
return result;
}
-static DerivedMesh *applyModifier(ModifierData *md, Object *ob, DerivedMesh *dm, ModifierApplyFlag UNUSED(flag))
+static Mesh *applyModifier(
+ ModifierData *md,
+ const struct ModifierEvalContext *ctx,
+ struct Mesh *mesh)
{
- return WireframeModifier_do((WireframeModifierData *)md, ob, dm);
+ return WireframeModifier_do((WireframeModifierData *)md, ctx->object, mesh);
}
@@ -117,18 +130,26 @@ ModifierTypeInfo modifierType_Wireframe = {
eModifierTypeFlag_SupportsEditmode,
/* copyData */ copyData,
+
+ /* deformVerts_DM */ NULL,
+ /* deformMatrices_DM */ NULL,
+ /* deformVertsEM_DM */ NULL,
+ /* deformMatricesEM_DM*/NULL,
+ /* applyModifier_DM */ NULL,
+ /* applyModifierEM_DM */NULL,
+
/* deformVerts */ NULL,
/* deformMatrices */ NULL,
/* deformVertsEM */ NULL,
/* deformMatricesEM */ NULL,
/* applyModifier */ applyModifier,
/* applyModifierEM */ NULL,
+
/* initData */ initData,
/* requiredDataMask */ requiredDataMask,
/* freeData */ NULL,
/* isDisabled */ NULL,
/* updateDepgraph */ NULL,
- /* updateDepsgraph */ NULL,
/* dependsOnTime */ NULL,
/* dependsOnNormals */ dependsOnNormals,
/* foreachObjectLink */ NULL,
diff --git a/source/blender/nodes/CMakeLists.txt b/source/blender/nodes/CMakeLists.txt
index 5247599bdf7..efe7db088f8 100644
--- a/source/blender/nodes/CMakeLists.txt
+++ b/source/blender/nodes/CMakeLists.txt
@@ -32,6 +32,7 @@ set(INC
../blenkernel
../blenlib
../blentranslation
+ ../depsgraph
../gpu
../imbuf
../makesdna
@@ -134,22 +135,17 @@ set(SRC
shader/nodes/node_shader_curves.c
shader/nodes/node_shader_gamma.c
shader/nodes/node_shader_brightness.c
- shader/nodes/node_shader_geom.c
shader/nodes/node_shader_hueSatVal.c
shader/nodes/node_shader_invert.c
- shader/nodes/node_shader_lamp.c
shader/nodes/node_shader_mapping.c
- shader/nodes/node_shader_material.c
shader/nodes/node_shader_math.c
shader/nodes/node_shader_mixRgb.c
shader/nodes/node_shader_normal.c
- shader/nodes/node_shader_output.c
shader/nodes/node_shader_rgb.c
shader/nodes/node_shader_sepcombRGB.c
shader/nodes/node_shader_sepcombHSV.c
shader/nodes/node_shader_sepcombXYZ.c
shader/nodes/node_shader_squeeze.c
- shader/nodes/node_shader_texture.c
shader/nodes/node_shader_valToRgb.c
shader/nodes/node_shader_value.c
shader/nodes/node_shader_wireframe.c
@@ -184,6 +180,7 @@ set(SRC
shader/nodes/node_shader_normal_map.c
shader/nodes/node_shader_object_info.c
shader/nodes/node_shader_hair_info.c
+ shader/nodes/node_shader_eevee_specular.c
shader/nodes/node_shader_output_lamp.c
shader/nodes/node_shader_output_material.c
shader/nodes/node_shader_output_world.c
diff --git a/source/blender/nodes/NOD_composite.h b/source/blender/nodes/NOD_composite.h
index a5c2e604f46..dfcb83b873a 100644
--- a/source/blender/nodes/NOD_composite.h
+++ b/source/blender/nodes/NOD_composite.h
@@ -140,7 +140,7 @@ void register_node_type_cmp_planetrackdeform(void);
void register_node_type_cmp_cornerpin(void);
void node_cmp_rlayers_outputs(struct bNodeTree *ntree, struct bNode *node);
-void node_cmp_rlayers_register_pass(struct bNodeTree *ntree, struct bNode *node, struct Scene *scene, struct SceneRenderLayer *srl, const char *name, int type);
+void node_cmp_rlayers_register_pass(struct bNodeTree *ntree, struct bNode *node, struct Scene *scene, struct ViewLayer *view_layer, const char *name, int type);
const char *node_cmp_rlayers_sock_to_pass(int sock_index);
#endif
diff --git a/source/blender/nodes/NOD_shader.h b/source/blender/nodes/NOD_shader.h
index b00307ed7fb..e411ceb6a23 100644
--- a/source/blender/nodes/NOD_shader.h
+++ b/source/blender/nodes/NOD_shader.h
@@ -44,20 +44,15 @@ void register_node_tree_type_sh(void);
void register_node_type_sh_group(void);
-void register_node_type_sh_output(void);
-void register_node_type_sh_material(void);
void register_node_type_sh_camera(void);
-void register_node_type_sh_lamp(void);
void register_node_type_sh_value(void);
void register_node_type_sh_rgb(void);
void register_node_type_sh_mix_rgb(void);
void register_node_type_sh_valtorgb(void);
void register_node_type_sh_rgbtobw(void);
-void register_node_type_sh_texture(void);
void register_node_type_sh_normal(void);
void register_node_type_sh_gamma(void);
void register_node_type_sh_brightcontrast(void);
-void register_node_type_sh_geom(void);
void register_node_type_sh_mapping(void);
void register_node_type_sh_curve_vec(void);
void register_node_type_sh_curve_rgb(void);
@@ -65,7 +60,6 @@ void register_node_type_sh_math(void);
void register_node_type_sh_vect_math(void);
void register_node_type_sh_squeeze(void);
void register_node_type_sh_dynamic(void);
-void register_node_type_sh_material_ext(void);
void register_node_type_sh_invert(void);
void register_node_type_sh_seprgb(void);
void register_node_type_sh_combrgb(void);
@@ -121,9 +115,12 @@ void register_node_type_sh_mix_shader(void);
void register_node_type_sh_add_shader(void);
void register_node_type_sh_uvmap(void);
void register_node_type_sh_uvalongstroke(void);
+void register_node_type_sh_eevee_metallic(void);
+void register_node_type_sh_eevee_specular(void);
void register_node_type_sh_output_lamp(void);
void register_node_type_sh_output_material(void);
+void register_node_type_sh_output_eevee_material(void);
void register_node_type_sh_output_world(void);
void register_node_type_sh_output_linestyle(void);
diff --git a/source/blender/nodes/NOD_socket.h b/source/blender/nodes/NOD_socket.h
index 5c8875593e7..e311adc45eb 100644
--- a/source/blender/nodes/NOD_socket.h
+++ b/source/blender/nodes/NOD_socket.h
@@ -49,7 +49,7 @@ struct bNodeSocket *node_add_socket_from_template(struct bNodeTree *ntree, struc
void node_verify_socket_templates(struct bNodeTree *ntree, struct bNode *node);
void node_socket_init_default_value(struct bNodeSocket *sock);
-void node_socket_copy_default_value(struct bNodeSocket *to, struct bNodeSocket *from);
+void node_socket_copy_default_value(struct bNodeSocket *to, const struct bNodeSocket *from);
void register_standard_node_socket_types(void);
#endif
diff --git a/source/blender/nodes/NOD_static_types.h b/source/blender/nodes/NOD_static_types.h
index bc90e33ed03..299c3a627ee 100644
--- a/source/blender/nodes/NOD_static_types.h
+++ b/source/blender/nodes/NOD_static_types.h
@@ -40,33 +40,28 @@ DefNode( Node, NODE_GROUP_INPUT, def_group_input, "GROUP
DefNode( Node, NODE_GROUP_OUTPUT, def_group_output, "GROUP_OUTPUT", GroupOutput, "Group Output", "" )
DefNode( Node, NODE_REROUTE, 0, "REROUTE", Reroute, "Reroute", "" )
-DefNode( ShaderNode, SH_NODE_OUTPUT, def_sh_output, "OUTPUT", Output, "Output", "" )
-DefNode( ShaderNode, SH_NODE_MATERIAL, def_sh_material, "MATERIAL", Material, "Material", "" )
DefNode( ShaderNode, SH_NODE_RGB, 0, "RGB", RGB, "RGB", "" )
DefNode( ShaderNode, SH_NODE_VALUE, 0, "VALUE", Value, "Value", "" )
DefNode( ShaderNode, SH_NODE_MIX_RGB, def_mix_rgb, "MIX_RGB", MixRGB, "MixRGB", "" )
DefNode( ShaderNode, SH_NODE_VALTORGB, def_colorramp, "VALTORGB", ValToRGB, "ColorRamp", "" )
DefNode( ShaderNode, SH_NODE_RGBTOBW, 0, "RGBTOBW", RGBToBW, "RGB to BW", "" )
-DefNode( ShaderNode, SH_NODE_TEXTURE, def_texture, "TEXTURE", Texture, "Texture", "" )
DefNode( ShaderNode, SH_NODE_NORMAL, 0, "NORMAL", Normal, "Normal", "" )
DefNode( ShaderNode, SH_NODE_GAMMA, 0, "GAMMA", Gamma, "Gamma", "" )
DefNode( ShaderNode, SH_NODE_BRIGHTCONTRAST, 0, "BRIGHTCONTRAST", BrightContrast, "Bright Contrast", "" )
-DefNode( ShaderNode, SH_NODE_GEOMETRY, def_sh_geometry, "GEOMETRY", Geometry, "Geometry", "" )
DefNode( ShaderNode, SH_NODE_MAPPING, def_sh_mapping, "MAPPING", Mapping, "Mapping", "" )
DefNode( ShaderNode, SH_NODE_CURVE_VEC, def_vector_curve, "CURVE_VEC", VectorCurve, "Vector Curves", "" )
DefNode( ShaderNode, SH_NODE_CURVE_RGB, def_rgb_curve, "CURVE_RGB", RGBCurve, "RGB Curves", "" )
DefNode( ShaderNode, SH_NODE_CAMERA, 0, "CAMERA", CameraData, "Camera Data", "" )
-DefNode( ShaderNode, SH_NODE_LAMP, def_sh_lamp, "LAMP", LampData, "Lamp Data", "" )
DefNode( ShaderNode, SH_NODE_MATH, def_math, "MATH", Math, "Math", "" )
DefNode( ShaderNode, SH_NODE_VECT_MATH, def_vector_math, "VECT_MATH", VectorMath, "Vector Math", "" )
DefNode( ShaderNode, SH_NODE_SQUEEZE, 0, "SQUEEZE", Squeeze, "Squeeze Value", "" )
-DefNode( ShaderNode, SH_NODE_MATERIAL_EXT, def_sh_material, "MATERIAL_EXT", ExtendedMaterial, "Extended Material", "" )
DefNode( ShaderNode, SH_NODE_INVERT, 0, "INVERT", Invert, "Invert", "" )
DefNode( ShaderNode, SH_NODE_SEPRGB, 0, "SEPRGB", SeparateRGB, "Separate RGB", "" )
DefNode( ShaderNode, SH_NODE_COMBRGB, 0, "COMBRGB", CombineRGB, "Combine RGB", "" )
DefNode( ShaderNode, SH_NODE_HUE_SAT, 0, "HUE_SAT", HueSaturation, "Hue/Saturation", "" )
DefNode( ShaderNode, SH_NODE_OUTPUT_MATERIAL, def_sh_output, "OUTPUT_MATERIAL", OutputMaterial, "Material Output", "" )
+DefNode( ShaderNode, SH_NODE_EEVEE_SPECULAR, 0, "EEVEE_SPECULAR", EeveeSpecular, "Specular", "")
DefNode( ShaderNode, SH_NODE_OUTPUT_LAMP, def_sh_output, "OUTPUT_LAMP", OutputLamp, "Lamp Output", "" )
DefNode( ShaderNode, SH_NODE_OUTPUT_WORLD, def_sh_output, "OUTPUT_WORLD", OutputWorld, "World Output", "" )
DefNode( ShaderNode, SH_NODE_OUTPUT_LINESTYLE, def_sh_output_linestyle,"OUTPUT_LINESTYLE", OutputLineStyle, "Line Style Output", "" )
diff --git a/source/blender/nodes/composite/node_composite_tree.c b/source/blender/nodes/composite/node_composite_tree.c
index 36778a18f77..8994a2741f8 100644
--- a/source/blender/nodes/composite/node_composite_tree.c
+++ b/source/blender/nodes/composite/node_composite_tree.c
@@ -261,7 +261,7 @@ void ntreeCompositUpdateRLayers(bNodeTree *ntree)
}
-void ntreeCompositRegisterPass(bNodeTree *ntree, Scene *scene, SceneRenderLayer *srl, const char *name, int type)
+void ntreeCompositRegisterPass(bNodeTree *ntree, Scene *scene, ViewLayer *view_layer, const char *name, int type)
{
bNode *node;
@@ -269,7 +269,7 @@ void ntreeCompositRegisterPass(bNodeTree *ntree, Scene *scene, SceneRenderLayer
for (node = ntree->nodes.first; node; node = node->next) {
if (node->type == CMP_NODE_R_LAYERS)
- node_cmp_rlayers_register_pass(ntree, node, scene, srl, name, type);
+ node_cmp_rlayers_register_pass(ntree, node, scene, view_layer, name, type);
}
}
diff --git a/source/blender/nodes/composite/nodes/node_composite_image.c b/source/blender/nodes/composite/nodes/node_composite_image.c
index 1e240c2f84b..be23c535cba 100644
--- a/source/blender/nodes/composite/nodes/node_composite_image.c
+++ b/source/blender/nodes/composite/nodes/node_composite_image.c
@@ -41,6 +41,7 @@
#include "BKE_context.h"
#include "BKE_global.h"
#include "BKE_main.h"
+#include "BKE_scene.h"
/* **************** IMAGE (and RenderResult, multilayer image) ******************** */
@@ -190,16 +191,16 @@ typedef struct RLayerUpdateData {
int prev_index;
} RLayerUpdateData;
-void node_cmp_rlayers_register_pass(bNodeTree *ntree, bNode *node, Scene *scene, SceneRenderLayer *srl, const char *name, int type)
+void node_cmp_rlayers_register_pass(bNodeTree *ntree, bNode *node, Scene *scene, ViewLayer *view_layer, const char *name, int type)
{
RLayerUpdateData *data = node->storage;
- if (scene == NULL || srl == NULL || data == NULL || node->id != (ID *)scene) {
+ if (scene == NULL || view_layer == NULL || data == NULL || node->id != (ID *)scene) {
return;
}
- SceneRenderLayer *node_srl = BLI_findlink(&scene->r.layers, node->custom1);
- if (node_srl != srl) {
+ ViewLayer *node_view_layer = BLI_findlink(&scene->view_layers, node->custom1);
+ if (node_view_layer != view_layer) {
return;
}
@@ -220,15 +221,15 @@ static void cmp_node_rlayer_create_outputs(bNodeTree *ntree, bNode *node, LinkNo
if (scene) {
RenderEngineType *engine_type = RE_engines_find(scene->r.engine);
if (engine_type && engine_type->update_render_passes) {
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, node->custom1);
- if (srl) {
+ ViewLayer *view_layer = BLI_findlink(&scene->view_layers, node->custom1);
+ if (view_layer) {
RLayerUpdateData *data = MEM_mallocN(sizeof(RLayerUpdateData), "render layer update data");
data->available_sockets = available_sockets;
data->prev_index = -1;
node->storage = data;
RenderEngine *engine = RE_engine_create(engine_type);
- engine_type->update_render_passes(engine, scene, srl);
+ engine_type->update_render_passes(engine, scene, view_layer);
RE_engine_free(engine);
MEM_freeN(data);
diff --git a/source/blender/nodes/intern/node_exec.c b/source/blender/nodes/intern/node_exec.c
index 0cf131adbdc..ac4031f4932 100644
--- a/source/blender/nodes/intern/node_exec.c
+++ b/source/blender/nodes/intern/node_exec.c
@@ -304,8 +304,6 @@ bool ntreeExecThreadNodes(bNodeTreeExec *exec, bNodeThreadStack *nts, void *call
* If the mute func is not set, assume the node should never be muted,
* and hence execute it!
*/
-// if (node->typeinfo->compatibility == NODE_NEW_SHADING)
-// return false;
if (node->typeinfo->execfunc && !(node->flag & NODE_MUTED))
node->typeinfo->execfunc(callerdata, thread, node, &nodeexec->data, nsin, nsout);
}
diff --git a/source/blender/nodes/intern/node_socket.c b/source/blender/nodes/intern/node_socket.c
index 342774facd0..e1d17003ba4 100644
--- a/source/blender/nodes/intern/node_socket.c
+++ b/source/blender/nodes/intern/node_socket.c
@@ -267,7 +267,7 @@ void node_socket_init_default_value(bNodeSocket *sock)
}
}
-void node_socket_copy_default_value(bNodeSocket *to, bNodeSocket *from)
+void node_socket_copy_default_value(bNodeSocket *to, const bNodeSocket *from)
{
/* sanity check */
if (to->type != from->type)
diff --git a/source/blender/nodes/shader/node_shader_tree.c b/source/blender/nodes/shader/node_shader_tree.c
index ce47ecd9a23..bad80450f80 100644
--- a/source/blender/nodes/shader/node_shader_tree.c
+++ b/source/blender/nodes/shader/node_shader_tree.c
@@ -39,6 +39,7 @@
#include "DNA_space_types.h"
#include "DNA_world_types.h"
#include "DNA_linestyle_types.h"
+#include "DNA_workspace_types.h"
#include "BLI_listbase.h"
#include "BLI_threads.h"
@@ -67,11 +68,11 @@
static int shader_tree_poll(const bContext *C, bNodeTreeType *UNUSED(treetype))
{
Scene *scene = CTX_data_scene(C);
+ const char *engine_id = scene->r.engine;
+
/* allow empty engine string too, this is from older versions that didn't have registerable engines yet */
- return (scene->r.engine[0] == '\0' ||
- STREQ(scene->r.engine, RE_engine_id_BLENDER_RENDER) ||
- STREQ(scene->r.engine, RE_engine_id_BLENDER_GAME) ||
- STREQ(scene->r.engine, RE_engine_id_CYCLES) ||
+ return (engine_id[0] == '\0' ||
+ STREQ(engine_id, RE_engine_id_CYCLES) ||
!BKE_scene_use_shading_nodes_custom(scene));
}
@@ -79,11 +80,10 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre
{
SpaceNode *snode = CTX_wm_space_node(C);
Scene *scene = CTX_data_scene(C);
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
- if ((snode->shaderfrom == SNODE_SHADER_OBJECT) ||
- (BKE_scene_use_new_shading_nodes(scene) == false))
- {
+ if (snode->shaderfrom == SNODE_SHADER_OBJECT) {
if (ob) {
*r_from = &ob->id;
if (ob->type == OB_LAMP) {
@@ -101,7 +101,7 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre
}
#ifdef WITH_FREESTYLE
else if (snode->shaderfrom == SNODE_SHADER_LINESTYLE) {
- FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene);
+ FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer);
if (linestyle) {
*r_from = NULL;
*r_id = &linestyle->id;
@@ -118,16 +118,12 @@ static void shader_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tre
}
}
-static void foreach_nodeclass(Scene *scene, void *calldata, bNodeClassCallback func)
+static void foreach_nodeclass(Scene *UNUSED(scene), void *calldata, bNodeClassCallback func)
{
func(calldata, NODE_CLASS_INPUT, N_("Input"));
func(calldata, NODE_CLASS_OUTPUT, N_("Output"));
-
- if (BKE_scene_use_new_shading_nodes(scene)) {
- func(calldata, NODE_CLASS_SHADER, N_("Shader"));
- func(calldata, NODE_CLASS_TEXTURE, N_("Texture"));
- }
-
+ func(calldata, NODE_CLASS_SHADER, N_("Shader"));
+ func(calldata, NODE_CLASS_TEXTURE, N_("Texture"));
func(calldata, NODE_CLASS_OP_COLOR, N_("Color"));
func(calldata, NODE_CLASS_OP_VECTOR, N_("Vector"));
func(calldata, NODE_CLASS_CONVERTOR, N_("Convertor"));
@@ -213,6 +209,9 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree,
* render engines works but it's how the GPU shader compilation works. This we
* can change in the future and make it a generic function, but for now it stays
* private here.
+ *
+ * It also does not yet take into account render engine specific output nodes,
+ * it should give priority to e.g. the Eevee material output node for Eevee.
*/
static bNode *ntree_shader_output_node(bNodeTree *ntree)
{
@@ -430,7 +429,7 @@ static void ntree_shader_link_builtin_normal(bNodeTree *ntree,
static void ntree_shader_relink_displacement(bNodeTree *ntree,
short compatibility)
{
- if (compatibility != NODE_NEW_SHADING) {
+ if ((compatibility & NODE_NEW_SHADING) == 0) {
/* We can only deal with new shading system here. */
return;
}
@@ -491,6 +490,112 @@ static void ntree_shader_relink_displacement(bNodeTree *ntree,
ntreeUpdateTree(G.main, ntree);
}
+static bool ntree_tag_ssr_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed))
+{
+ switch (fromnode->type) {
+ case SH_NODE_BSDF_ANISOTROPIC:
+ case SH_NODE_EEVEE_SPECULAR:
+ case SH_NODE_BSDF_PRINCIPLED:
+ case SH_NODE_BSDF_GLOSSY:
+ case SH_NODE_BSDF_GLASS:
+ fromnode->ssr_id = (*(float *)userdata);
+ (*(float *)userdata) += 1;
+ break;
+ default:
+ /* We could return false here but since we (will)
+ * allow the use of Closure as RGBA, we can have
+ * Bsdf nodes linked to other Bsdf nodes. */
+ break;
+ }
+
+ return true;
+}
+
+/* EEVEE: Scan the ntree to set the Screen Space Reflection
+ * layer id of every specular node.
+ */
+static void ntree_shader_tag_ssr_node(bNodeTree *ntree, short compatibility)
+{
+ if ((compatibility & NODE_NEWER_SHADING) == 0) {
+ /* We can only deal with new shading system here. */
+ return;
+ }
+
+ bNode *output_node = ntree_shader_output_node(ntree);
+ if (output_node == NULL) {
+ return;
+ }
+ /* Make sure sockets links pointers are correct. */
+ ntreeUpdateTree(G.main, ntree);
+
+ float lobe_id = 1;
+ nodeChainIter(ntree, output_node, ntree_tag_ssr_bsdf_cb, &lobe_id, true);
+}
+
+static bool ntree_tag_sss_bsdf_cb(bNode *fromnode, bNode *UNUSED(tonode), void *userdata, const bool UNUSED(reversed))
+{
+ switch (fromnode->type) {
+ case SH_NODE_BSDF_PRINCIPLED:
+ case SH_NODE_SUBSURFACE_SCATTERING:
+ fromnode->sss_id = (*(float *)userdata);
+ (*(float *)userdata) += 1;
+ break;
+ default:
+ break;
+ }
+
+ return true;
+}
+
+/* EEVEE: Scan the ntree to set the Subsurface Scattering id of every SSS node.
+ */
+static void ntree_shader_tag_sss_node(bNodeTree *ntree, short compatibility)
+{
+ if ((compatibility & NODE_NEWER_SHADING) == 0) {
+ /* We can only deal with new shading system here. */
+ return;
+ }
+
+ bNode *output_node = ntree_shader_output_node(ntree);
+ if (output_node == NULL) {
+ return;
+ }
+ /* Make sure sockets links pointers are correct. */
+ ntreeUpdateTree(G.main, ntree);
+
+ float sss_id = 1;
+ nodeChainIter(ntree, output_node, ntree_tag_sss_bsdf_cb, &sss_id, true);
+}
+
+/* EEVEE: Find which material domain are used (volume, surface ...).
+ */
+void ntreeGPUMaterialDomain(bNodeTree *ntree, bool *has_surface_output, bool *has_volume_output)
+{
+ /* localize tree to create links for reroute and mute */
+ bNodeTree *localtree = ntreeLocalize(ntree);
+
+ struct bNode *output = ntree_shader_output_node(localtree);
+
+ *has_surface_output = false;
+ *has_volume_output = false;
+
+ if (output != NULL) {
+ bNodeSocket *surface_sock = ntree_shader_node_find_input(output, "Surface");
+ bNodeSocket *volume_sock = ntree_shader_node_find_input(output, "Volume");
+
+ if (surface_sock != NULL) {
+ *has_surface_output = (nodeCountSocketLinks(localtree, surface_sock) > 0);
+ }
+
+ if (volume_sock != NULL) {
+ *has_volume_output = (nodeCountSocketLinks(localtree, volume_sock) > 0);
+ }
+ }
+
+ ntreeFreeTree(localtree);
+ MEM_freeN(localtree);
+}
+
void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibility)
{
/* localize tree to create links for reroute and mute */
@@ -502,6 +607,9 @@ void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibili
*/
ntree_shader_relink_displacement(localtree, compatibility);
+ ntree_shader_tag_ssr_node(localtree, compatibility);
+ ntree_shader_tag_sss_node(localtree, compatibility);
+
exec = ntreeShaderBeginExecTree(localtree);
ntreeExecGPUNodes(exec, mat, 1, compatibility);
ntreeShaderEndExecTree(exec);
@@ -510,16 +618,6 @@ void ntreeGPUMaterialNodes(bNodeTree *ntree, GPUMaterial *mat, short compatibili
MEM_freeN(localtree);
}
-/* **************** call to switch lamploop for material node ************ */
-
-void (*node_shader_lamp_loop)(struct ShadeInput *, struct ShadeResult *);
-
-void set_node_shader_lamp_loop(void (*lamp_loop_func)(ShadeInput *, ShadeResult *))
-{
- node_shader_lamp_loop = lamp_loop_func;
-}
-
-
bNodeTreeExec *ntreeShaderBeginExecTree_internal(bNodeExecContext *context, bNodeTree *ntree, bNodeInstanceKey parent_key)
{
bNodeTreeExec *exec;
@@ -594,26 +692,14 @@ void ntreeShaderEndExecTree(bNodeTreeExec *exec)
}
}
-/* only for Blender internal */
-bool ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr)
+/* TODO: left over from Blender Internal, could reuse for new texture nodes. */
+bool ntreeShaderExecTree(bNodeTree *ntree, int thread)
{
ShaderCallData scd;
- /**
- * \note: preserve material from ShadeInput for material id, nodetree execs change it
- * fix for bug "[#28012] Mat ID messy with shader nodes"
- */
- Material *mat = shi->mat;
bNodeThreadStack *nts = NULL;
bNodeTreeExec *exec = ntree->execdata;
int compat;
- /* convert caller data to struct */
- scd.shi = shi;
- scd.shr = shr;
-
- /* each material node has own local shaderesult, with optional copying */
- memset(shr, 0, sizeof(ShadeResult));
-
/* ensure execdata is only initialized once */
if (!exec) {
BLI_thread_lock(LOCK_NODES);
@@ -624,18 +710,10 @@ bool ntreeShaderExecTree(bNodeTree *ntree, ShadeInput *shi, ShadeResult *shr)
exec = ntree->execdata;
}
- nts = ntreeGetThreadStack(exec, shi->thread);
- compat = ntreeExecThreadNodes(exec, nts, &scd, shi->thread);
+ nts = ntreeGetThreadStack(exec, thread);
+ compat = ntreeExecThreadNodes(exec, nts, &scd, thread);
ntreeReleaseThreadStack(nts);
- // \note: set material back to preserved material
- shi->mat = mat;
-
- /* better not allow negative for now */
- if (shr->combined[0] < 0.0f) shr->combined[0] = 0.0f;
- if (shr->combined[1] < 0.0f) shr->combined[1] = 0.0f;
- if (shr->combined[2] < 0.0f) shr->combined[2] = 0.0f;
-
/* if compat is zero, it has been using non-compatible nodes */
return compat;
}
diff --git a/source/blender/nodes/shader/node_shader_util.c b/source/blender/nodes/shader/node_shader_util.c
index 5bc97f13b41..69a69c156e3 100644
--- a/source/blender/nodes/shader/node_shader_util.c
+++ b/source/blender/nodes/shader/node_shader_util.c
@@ -91,53 +91,6 @@ void nodestack_get_vec(float *in, short type_in, bNodeStack *ns)
}
-/* go over all used Geometry and Texture nodes, and return a texco flag */
-/* no group inside needed, this function is called for groups too */
-void ntreeShaderGetTexcoMode(bNodeTree *ntree, int r_mode, short *texco, int *mode)
-{
- bNode *node;
- bNodeSocket *sock;
- int a;
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->type == SH_NODE_TEXTURE) {
- if ((r_mode & R_OSA) && node->id) {
- Tex *tex = (Tex *)node->id;
- if (ELEM(tex->type, TEX_IMAGE, TEX_ENVMAP)) {
- *texco |= TEXCO_OSA | NEED_UV;
- }
- }
- /* usability exception... without input we still give the node orcos */
- sock = node->inputs.first;
- if (sock == NULL || sock->link == NULL)
- *texco |= TEXCO_ORCO | NEED_UV;
- }
- else if (node->type == SH_NODE_GEOMETRY) {
- /* note; sockets always exist for the given type! */
- for (a = 0, sock = node->outputs.first; sock; sock = sock->next, a++) {
- if (sock->flag & SOCK_IN_USE) {
- switch (a) {
- case GEOM_OUT_GLOB:
- *texco |= TEXCO_GLOB | NEED_UV; break;
- case GEOM_OUT_VIEW:
- *texco |= TEXCO_VIEW | NEED_UV; break;
- case GEOM_OUT_ORCO:
- *texco |= TEXCO_ORCO | NEED_UV; break;
- case GEOM_OUT_UV:
- *texco |= TEXCO_UV | NEED_UV; break;
- case GEOM_OUT_NORMAL:
- *texco |= TEXCO_NORM | NEED_UV; break;
- case GEOM_OUT_VCOL:
- *texco |= NEED_UV; *mode |= MA_VERTEXCOL; break;
- case GEOM_OUT_VCOL_ALPHA:
- *texco |= NEED_UV; *mode |= MA_VERTEXCOL; break;
- }
- }
- }
- }
- }
-}
-
void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns)
{
memset(gs, 0, sizeof(*gs));
@@ -147,7 +100,6 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns)
zero_v4(gs->vec);
gs->link = NULL;
gs->type = GPU_NONE;
- gs->name = "";
gs->hasinput = false;
gs->hasoutput = false;
gs->sockettype = type;
@@ -163,11 +115,10 @@ void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, bNodeStack *ns)
else if (type == SOCK_RGBA)
gs->type = GPU_VEC4;
else if (type == SOCK_SHADER)
- gs->type = GPU_VEC4;
+ gs->type = GPU_CLOSURE;
else
gs->type = GPU_NONE;
- gs->name = "";
gs->hasinput = ns->hasinput && ns->data;
/* XXX Commented out the ns->data check here, as it seems it's not always set,
* even though there *is* a valid connection/output... But that might need
@@ -193,7 +144,7 @@ static void gpu_stack_from_data_list(GPUNodeStack *gs, ListBase *sockets, bNodeS
for (sock = sockets->first, i = 0; sock; sock = sock->next, i++)
node_gpu_stack_from_data(&gs[i], sock->type, ns[i]);
- gs[i].type = GPU_NONE;
+ gs[i].end = true;
}
static void data_from_gpu_stack_list(ListBase *sockets, bNodeStack **ns, GPUNodeStack *gs)
diff --git a/source/blender/nodes/shader/node_shader_util.h b/source/blender/nodes/shader/node_shader_util.h
index a902ede8aa7..44c1ab7ca95 100644
--- a/source/blender/nodes/shader/node_shader_util.h
+++ b/source/blender/nodes/shader/node_shader_util.h
@@ -78,6 +78,7 @@
#include "RE_shader_ext.h"
#include "GPU_material.h"
+#include "GPU_uniformbuffer.h"
int sh_node_poll_default(struct bNodeType *ntype, struct bNodeTree *ntree);
@@ -87,11 +88,10 @@ void sh_node_type_base(struct bNodeType *ntype, int type, const char *name, shor
/* ********* exec data struct, remains internal *********** */
typedef struct ShaderCallData {
- ShadeInput *shi; /* from render pipe */
- ShadeResult *shr; /* from render pipe */
+ /* Empty for now, may be reused if we convert shader to texture nodes. */
+ int dummy;
} ShaderCallData;
-
void nodestack_get_vec(float *in, short type_in, bNodeStack *ns);
void node_gpu_stack_from_data(struct GPUNodeStack *gs, int type, struct bNodeStack *ns);
diff --git a/source/blender/nodes/shader/nodes/node_shader_add_shader.c b/source/blender/nodes/shader/nodes/node_shader_add_shader.c
index 1edac62438e..d3bb8fccf71 100644
--- a/source/blender/nodes/shader/nodes/node_shader_add_shader.c
+++ b/source/blender/nodes/shader/nodes/node_shader_add_shader.c
@@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_add_shader_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_add_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_add_shader", in, out);
+ return GPU_stack_link(mat, node, "node_add_shader", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c
index 878f8562619..cb4335ca9a7 100644
--- a/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c
+++ b/source/blender/nodes/shader/nodes/node_shader_ambient_occlusion.c
@@ -39,9 +39,9 @@ static bNodeSocketTemplate sh_node_ambient_occlusion_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_ambient_occlusion(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
+ return GPU_stack_link(mat, node, "node_ambient_occlusion", in, out, GPU_builtin(GPU_VIEW_NORMAL));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_attribute.c b/source/blender/nodes/shader/nodes/node_shader_attribute.c
index 0a69593cf07..0ea1348df05 100644
--- a/source/blender/nodes/shader/nodes/node_shader_attribute.c
+++ b/source/blender/nodes/shader/nodes/node_shader_attribute.c
@@ -45,9 +45,29 @@ static void node_shader_init_attribute(bNodeTree *UNUSED(ntree), bNode *node)
static int node_shader_gpu_attribute(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
NodeShaderAttribute *attr = node->storage;
- GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name);
- return GPU_stack_link(mat, "node_attribute", in, out, cd_attr);
+ /* FIXME : if an attribute layer (like vertex color) has one of theses name, it will not work as expected. */
+ if (strcmp(attr->name, "density") == 0) {
+ return GPU_stack_link(mat, node, "node_attribute_volume_density", in, out,
+ GPU_builtin(GPU_VOLUME_DENSITY));
+ }
+ else if (strcmp(attr->name, "color") == 0) {
+ return GPU_stack_link(mat, node, "node_attribute_volume_color", in, out,
+ GPU_builtin(GPU_VOLUME_DENSITY));
+ }
+ else if (strcmp(attr->name, "flame") == 0) {
+ return GPU_stack_link(mat, node, "node_attribute_volume_flame", in, out,
+ GPU_builtin(GPU_VOLUME_FLAME));
+ }
+ else if (strcmp(attr->name, "temperature") == 0) {
+ return GPU_stack_link(mat, node, "node_attribute_volume_temperature", in, out,
+ GPU_builtin(GPU_VOLUME_FLAME),
+ GPU_builtin(GPU_VOLUME_TEMPERATURE));
+ }
+ else {
+ GPUNodeLink *cd_attr = GPU_attribute(CD_AUTO_FROM_NAME, attr->name);
+ return GPU_stack_link(mat, node, "node_attribute", in, out, cd_attr);
+ }
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_background.c b/source/blender/nodes/shader/nodes/node_shader_background.c
index b387529e456..4ea675f9e0c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_background.c
+++ b/source/blender/nodes/shader/nodes/node_shader_background.c
@@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_background_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_background(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_background(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_background", in, out, GPU_builtin(GPU_VIEW_NORMAL));
+ return GPU_stack_link(mat, node, "node_background", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bevel.c b/source/blender/nodes/shader/nodes/node_shader_bevel.c
index e2e4da21ef3..dd9bc91e2d1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bevel.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bevel.c
@@ -45,13 +45,13 @@ static void node_shader_init_bevel(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = 4; /* samples */
}
-static int gpu_shader_bevel(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_bevel(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[1].link) {
GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL), GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[1].link);
}
- return GPU_stack_link(mat, "node_bevel", in, out);
+ return GPU_stack_link(mat, node, "node_bevel", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_blackbody.c b/source/blender/nodes/shader/nodes/node_shader_blackbody.c
index af89a959554..28019651926 100644
--- a/source/blender/nodes/shader/nodes/node_shader_blackbody.c
+++ b/source/blender/nodes/shader/nodes/node_shader_blackbody.c
@@ -38,6 +38,16 @@ static bNodeSocketTemplate sh_node_blackbody_out[] = {
{ -1, 0, "" }
};
+static int node_shader_gpu_blackbody(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+{
+ const int size = 256;
+ float *data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture");
+
+ blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f);
+
+ return GPU_stack_link(mat, node, "node_blackbody", in, out, GPU_texture(size, data));
+}
+
/* node type definition */
void register_node_type_sh_blackbody(void)
{
@@ -49,6 +59,7 @@ void register_node_type_sh_blackbody(void)
node_type_socket_templates(&ntype, sh_node_blackbody_in, sh_node_blackbody_out);
node_type_init(&ntype, NULL);
node_type_storage(&ntype, "", NULL, NULL);
+ node_type_gpu(&ntype, node_shader_gpu_blackbody);
nodeRegisterType(&ntype);
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_brightness.c b/source/blender/nodes/shader/nodes/node_shader_brightness.c
index e992c0773c2..457708405af 100644
--- a/source/blender/nodes/shader/nodes/node_shader_brightness.c
+++ b/source/blender/nodes/shader/nodes/node_shader_brightness.c
@@ -42,9 +42,9 @@ static bNodeSocketTemplate sh_node_brightcontrast_out[] = {
{ -1, 0, "" }
};
-static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_brightcontrast(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "brightness_contrast", in, out);
+ return GPU_stack_link(mat, node, "brightness_contrast", in, out);
}
void register_node_type_sh_brightcontrast(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
index 6410441797a..ee3db99d2ab 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_anisotropic.c
@@ -49,14 +49,12 @@ static void node_shader_init_anisotropic(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_GGX;
}
-static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_anisotropic(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[4].link)
- in[4].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[4].link, GPU_builtin(GPU_VIEW_MATRIX), &in[4].link);
+ GPU_link(mat, "world_normals_get", &in[4].link);
- return GPU_stack_link(mat, "node_bsdf_anisotropic", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_anisotropic", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
index e86d2677a61..be7012712cc 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_diffuse.c
@@ -41,14 +41,12 @@ static bNodeSocketTemplate sh_node_bsdf_diffuse_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_diffuse(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[2].link)
- in[2].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link);
+ GPU_link(mat, "world_normals_get", &in[2].link);
- return GPU_stack_link(mat, "node_bsdf_diffuse", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_diffuse", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
index 5569fe85489..1537e07ca16 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glass.c
@@ -47,14 +47,12 @@ static void node_shader_init_glass(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_BECKMANN;
}
-static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_glass(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[3].link)
- in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
+ GPU_link(mat, "world_normals_get", &in[3].link);
- return GPU_stack_link(mat, "node_bsdf_glass", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_glass", in, out, GPU_uniform(&node->ssr_id));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
index c13fd89d6e5..ad9e7730ad1 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_glossy.c
@@ -46,14 +46,12 @@ static void node_shader_init_glossy(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_GGX;
}
-static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_glossy(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[2].link)
- in[2].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link);
+ GPU_link(mat, "world_normals_get", &in[2].link);
- return GPU_stack_link(mat, "node_bsdf_glossy", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_glossy", in, out, GPU_uniform(&node->ssr_id));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c
index 25be59f091d..b8078ac60ac 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_hair.c
@@ -43,9 +43,9 @@ static bNodeSocketTemplate sh_node_bsdf_hair_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_hair(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_bsdf_hair", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_hair", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
index e3b3f0fc9a6..b4a83c847be 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_principled.c
@@ -64,8 +64,10 @@ static void node_shader_init_principled(bNodeTree *UNUSED(ntree), bNode *node)
node->custom2 = SHD_SUBSURFACE_BURLEY;
}
-static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
+ GPUNodeLink *sss_scale;
+#if 0 /* Old 2.7 glsl viewport */
// normal
if (!in[17].link)
in[17].link = GPU_builtin(GPU_VIEW_NORMAL);
@@ -77,8 +79,46 @@ static int node_shader_gpu_bsdf_principled(GPUMaterial *mat, bNode *UNUSED(node)
in[18].link = GPU_builtin(GPU_VIEW_NORMAL);
else
GPU_link(mat, "direction_transform_m4v3", in[18].link, GPU_builtin(GPU_VIEW_MATRIX), &in[18].link);
+#endif
- return GPU_stack_link(mat, "node_bsdf_principled", in, out, GPU_builtin(GPU_VIEW_POSITION));
+ /* Normals */
+ if (!in[17].link) {
+ GPU_link(mat, "world_normals_get", &in[17].link);
+ }
+
+ /* Clearcoat Normals */
+ if (!in[18].link) {
+ GPU_link(mat, "world_normals_get", &in[18].link);
+ }
+
+ /* Tangents */
+ if (!in[19].link) {
+ GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
+ GPU_link(mat, "tangent_orco_z", orco, &in[19].link);
+ GPU_link(mat, "node_tangent",
+ GPU_builtin(GPU_VIEW_NORMAL), in[19].link, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX),
+ &in[19].link);
+ }
+
+ /* SSS Profile */
+ if (node->sss_id == 1) {
+ static short profile = SHD_SUBSURFACE_BURLEY;
+ bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2);
+ bNodeSocketValueRGBA *socket_data = socket->default_value;
+ /* For some reason it seems that the socket value is in ARGB format. */
+ GPU_material_sss_profile_create(mat, &socket_data->value[1], &profile, NULL);
+ }
+
+ if (in[2].link) {
+ sss_scale = in[2].link;
+ }
+ else {
+ float one[3] = {1.0f, 1.0f, 1.0f};
+ GPU_link(mat, "set_rgb", GPU_uniform((float *)one), &sss_scale);
+ }
+
+ return GPU_stack_link(mat, node, "node_bsdf_principled_clearcoat", in, out, GPU_builtin(GPU_VIEW_POSITION),
+ GPU_uniform(&node->ssr_id), GPU_uniform(&node->sss_id), sss_scale);
}
static void node_shader_update_principled(bNodeTree *UNUSED(ntree), bNode *node)
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c
index c447f5de219..9dbe3361e8b 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_refraction.c
@@ -47,14 +47,12 @@ static void node_shader_init_refraction(bNodeTree *UNUSED(ntree), bNode *node)
node->custom1 = SHD_GLOSSY_BECKMANN;
}
-static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_refraction(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[3].link)
- in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
+ GPU_link(mat, "world_normals_get", &in[3].link);
- return GPU_stack_link(mat, "node_bsdf_refraction", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_refraction", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c
index c3510beb470..28941fbd662 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_toon.c
@@ -42,14 +42,14 @@ static bNodeSocketTemplate sh_node_bsdf_toon_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_toon(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[3].link)
in[3].link = GPU_builtin(GPU_VIEW_NORMAL);
else
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
- return GPU_stack_link(mat, "node_bsdf_toon", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_toon", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c
index 3b88d609cdb..f6f6da524d5 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_translucent.c
@@ -40,14 +40,12 @@ static bNodeSocketTemplate sh_node_bsdf_translucent_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_translucent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[1].link)
- in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
+ GPU_link(mat, "world_normals_get", &in[1].link);
- return GPU_stack_link(mat, "node_bsdf_translucent", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_translucent", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c
index 5cb50b00e1a..76afe935433 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_transparent.c
@@ -39,9 +39,9 @@ static bNodeSocketTemplate sh_node_bsdf_transparent_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_transparent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_bsdf_transparent", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_transparent", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c
index ef3d52ecbce..6d61f3f7473 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bsdf_velvet.c
@@ -41,14 +41,12 @@ static bNodeSocketTemplate sh_node_bsdf_velvet_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_bsdf_velvet(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[2].link)
- in[2].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[2].link, GPU_builtin(GPU_VIEW_MATRIX), &in[2].link);
+ GPU_link(mat, "world_normals_get", &in[2].link);
- return GPU_stack_link(mat, "node_bsdf_velvet", in, out);
+ return GPU_stack_link(mat, node, "node_bsdf_velvet", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_bump.c b/source/blender/nodes/shader/nodes/node_shader_bump.c
index 122f02eda8a..84481a50993 100644
--- a/source/blender/nodes/shader/nodes/node_shader_bump.c
+++ b/source/blender/nodes/shader/nodes/node_shader_bump.c
@@ -52,7 +52,7 @@ static int gpu_shader_bump(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
else
GPU_link(mat, "direction_transform_m4v3", in[3].link, GPU_builtin(GPU_VIEW_MATRIX), &in[3].link);
float invert = node->custom1;
- GPU_stack_link(mat, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&invert));
+ GPU_stack_link(mat, node, "node_bump", in, out, GPU_builtin(GPU_VIEW_POSITION), GPU_uniform(&invert));
/* Other nodes are applying view matrix if the input Normal has a link.
* We don't want normal to have view matrix applied twice, so we cancel it here.
*
diff --git a/source/blender/nodes/shader/nodes/node_shader_camera.c b/source/blender/nodes/shader/nodes/node_shader_camera.c
index 3bdb5c36d69..245360e789f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_camera.c
+++ b/source/blender/nodes/shader/nodes/node_shader_camera.c
@@ -40,29 +40,13 @@ static bNodeSocketTemplate sh_node_camera_out[] = {
{ -1, 0, "" }
};
-
-static void node_shader_exec_camera(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out)
-{
- if (data) {
- ShadeInput *shi = ((ShaderCallData *)data)->shi; /* Data we need for shading. */
-
- copy_v3_v3(out[0]->vec, shi->co); /* get view vector */
- out[1]->vec[0] = fabsf(shi->co[2]); /* get view z-depth */
- out[2]->vec[0] = normalize_v3(out[0]->vec); /* get view distance */
- }
-}
-
-static int gpu_shader_camera(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_camera(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *viewvec;
viewvec = GPU_builtin(GPU_VIEW_POSITION);
-
- /* Blender has negative Z, Cycles positive Z convention */
- if (GPU_material_use_new_shading_nodes(mat))
- GPU_link(mat, "invert_z", viewvec, &viewvec);
-
- return GPU_stack_link(mat, "camera", in, out, viewvec);
+ GPU_link(mat, "invert_z", viewvec, &viewvec);
+ return GPU_stack_link(mat, node, "camera", in, out, viewvec);
}
void register_node_type_sh_camera(void)
@@ -73,7 +57,6 @@ void register_node_type_sh_camera(void)
node_type_compatibility(&ntype, NODE_OLD_SHADING | NODE_NEW_SHADING);
node_type_socket_templates(&ntype, NULL, sh_node_camera_out);
node_type_storage(&ntype, "", NULL, NULL);
- node_type_exec(&ntype, NULL, NULL, node_shader_exec_camera);
node_type_gpu(&ntype, gpu_shader_camera);
nodeRegisterType(&ntype);
diff --git a/source/blender/nodes/shader/nodes/node_shader_curves.c b/source/blender/nodes/shader/nodes/node_shader_curves.c
index 5e067e6c630..ceba8fd1248 100644
--- a/source/blender/nodes/shader/nodes/node_shader_curves.c
+++ b/source/blender/nodes/shader/nodes/node_shader_curves.c
@@ -66,7 +66,7 @@ static int gpu_shader_curve_vec(GPUMaterial *mat, bNode *node, bNodeExecData *UN
int size;
curvemapping_table_RGBA(node->storage, &array, &size);
- return GPU_stack_link(mat, "curves_vec", in, out, GPU_texture(size, array));
+ return GPU_stack_link(mat, node, "curves_vec", in, out, GPU_texture(size, array));
}
void register_node_type_sh_curve_vec(void)
@@ -125,7 +125,7 @@ static int gpu_shader_curve_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UN
curvemapping_initialize(node->storage);
curvemapping_table_RGBA(node->storage, &array, &size);
- return GPU_stack_link(mat, "curves_rgb", in, out, GPU_texture(size, array));
+ return GPU_stack_link(mat, node, "curves_rgb", in, out, GPU_texture(size, array));
}
void register_node_type_sh_curve_rgb(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_displacement.c b/source/blender/nodes/shader/nodes/node_shader_displacement.c
index e259a9e3f6d..c26968e8d14 100644
--- a/source/blender/nodes/shader/nodes/node_shader_displacement.c
+++ b/source/blender/nodes/shader/nodes/node_shader_displacement.c
@@ -61,10 +61,10 @@ static int gpu_shader_displacement(GPUMaterial *mat, bNode *node, bNodeExecData
}
if (node->custom1 == SHD_SPACE_OBJECT) {
- return GPU_stack_link(mat, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
+ return GPU_stack_link(mat, node, "node_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
}
else {
- return GPU_stack_link(mat, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
+ return GPU_stack_link(mat, node, "node_displacement_world", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
}
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c
new file mode 100644
index 00000000000..cd912a4b4cb
--- /dev/null
+++ b/source/blender/nodes/shader/nodes/node_shader_eevee_specular.c
@@ -0,0 +1,87 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2005 Blender Foundation.
+ * All rights reserved.
+ *
+ * The Original Code is: all of this file.
+ *
+ * Contributor(s): Clément Foucault.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#include "../node_shader_util.h"
+
+/* **************** OUTPUT ******************** */
+
+static bNodeSocketTemplate sh_node_eevee_specular_in[] = {
+ { SOCK_RGBA, 1, N_("Base Color"), 0.8f, 0.8f, 0.8f, 1.0f},
+ { SOCK_RGBA, 1, N_("Specular"), 0.03f, 0.03f, 0.03f, 1.0f},
+ { SOCK_FLOAT, 1, N_("Roughness"), 0.2f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+ { SOCK_RGBA, 1, N_("Emissive Color"), 0.0f, 0.0f, 0.0f, 1.0f},
+ { SOCK_FLOAT, 1, N_("Transparency"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+ { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+ { SOCK_FLOAT, 1, N_("Clear Coat"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+ { SOCK_FLOAT, 1, N_("Clear Coat Roughness"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_FACTOR},
+ { SOCK_VECTOR, 1, N_("Clear Coat Normal"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+ { SOCK_FLOAT, 1, N_("Ambient Occlusion"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE},
+ { -1, 0, "" }
+};
+
+static bNodeSocketTemplate sh_node_eevee_specular_out[] = {
+ { SOCK_SHADER, 0, N_("BSDF")},
+ { -1, 0, "" }
+};
+
+static int node_shader_gpu_eevee_specular(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+{
+ static float one = 1.0f;
+
+ /* Normals */
+ if (!in[5].link) {
+ GPU_link(mat, "world_normals_get", &in[5].link);
+ }
+
+ /* Clearcoat Normals */
+ if (!in[8].link) {
+ GPU_link(mat, "world_normals_get", &in[8].link);
+ }
+
+ /* Occlusion */
+ if (!in[9].link) {
+ GPU_link(mat, "set_value", GPU_uniform(&one), &in[9].link);
+ }
+
+ return GPU_stack_link(mat, node, "node_eevee_specular", in, out, GPU_uniform(&node->ssr_id));
+}
+
+
+/* node type definition */
+void register_node_type_sh_eevee_specular(void)
+{
+ static bNodeType ntype;
+
+ sh_node_type_base(&ntype, SH_NODE_EEVEE_SPECULAR, "Specular", NODE_CLASS_SHADER, 0);
+ node_type_compatibility(&ntype, NODE_NEW_SHADING);
+ node_type_socket_templates(&ntype, sh_node_eevee_specular_in, sh_node_eevee_specular_out);
+ node_type_init(&ntype, NULL);
+ node_type_storage(&ntype, "", NULL, NULL);
+ node_type_gpu(&ntype, node_shader_gpu_eevee_specular);
+
+ nodeRegisterType(&ntype);
+}
diff --git a/source/blender/nodes/shader/nodes/node_shader_emission.c b/source/blender/nodes/shader/nodes/node_shader_emission.c
index 51b3d5740a7..0901e8204f8 100644
--- a/source/blender/nodes/shader/nodes/node_shader_emission.c
+++ b/source/blender/nodes/shader/nodes/node_shader_emission.c
@@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_emission_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_emission(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_emission(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL));
+ return GPU_stack_link(mat, node, "node_emission", in, out, GPU_builtin(GPU_VIEW_NORMAL));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_fresnel.c b/source/blender/nodes/shader/nodes/node_shader_fresnel.c
index 8262b70fc44..30bdf0b0f42 100644
--- a/source/blender/nodes/shader/nodes/node_shader_fresnel.c
+++ b/source/blender/nodes/shader/nodes/node_shader_fresnel.c
@@ -39,45 +39,20 @@ static bNodeSocketTemplate sh_node_fresnel_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_fresnel(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[1].link) {
in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
}
- else if (GPU_material_use_world_space_shading(mat)) {
+ else {
GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
}
- return GPU_stack_link(mat, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION));
+ return GPU_stack_link(mat, node, "node_fresnel", in, out, GPU_builtin(GPU_VIEW_POSITION));
}
-static void node_shader_exec_fresnel(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
+static void node_shader_exec_fresnel(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
-
- /* Compute IOR. */
- float eta;
- nodestack_get_vec(&eta, SOCK_FLOAT, in[0]);
- eta = max_ff(eta, 0.00001);
- eta = shi->flippednor ? 1 / eta : eta;
-
- /* Get normal from socket, but only if linked. */
- bNodeSocket *sock_normal = node->inputs.first;
- sock_normal = sock_normal->next;
-
- float n[3];
- if (sock_normal->link) {
- nodestack_get_vec(n, SOCK_VECTOR, in[1]);
- }
- else {
- copy_v3_v3(n, shi->vn);
- }
-
- if (shi->use_world_space_shading) {
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), n);
- }
-
- out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, eta);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_gamma.c b/source/blender/nodes/shader/nodes/node_shader_gamma.c
index 37439569f77..1aebfbe5888 100644
--- a/source/blender/nodes/shader/nodes/node_shader_gamma.c
+++ b/source/blender/nodes/shader/nodes/node_shader_gamma.c
@@ -52,9 +52,9 @@ static void node_shader_exec_gamma(void *UNUSED(data), int UNUSED(thread), bNode
out[0]->vec[2] = col[2] > 0.0f ? powf(col[2], gamma) : col[2];
}
-static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_gamma(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_gamma", in, out);
+ return GPU_stack_link(mat, node, "node_gamma", in, out);
}
void register_node_type_sh_gamma(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_geom.c b/source/blender/nodes/shader/nodes/node_shader_geom.c
deleted file mode 100644
index b289d66efc3..00000000000
--- a/source/blender/nodes/shader/nodes/node_shader_geom.c
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2005 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/nodes/shader/nodes/node_shader_geom.c
- * \ingroup shdnodes
- */
-
-
-#include "node_shader_util.h"
-
-#include "DNA_customdata_types.h"
-
-/* **************** GEOMETRY ******************** */
-
-/* output socket type definition */
-static bNodeSocketTemplate sh_node_geom_out[] = {
- { SOCK_VECTOR, 0, N_("Global")},
- { SOCK_VECTOR, 0, N_("Local")},
- { SOCK_VECTOR, 0, N_("View")},
- { SOCK_VECTOR, 0, N_("Orco")},
- { SOCK_VECTOR, 0, N_("UV")},
- { SOCK_VECTOR, 0, N_("Normal")},
- { SOCK_RGBA, 0, N_("Vertex Color")},
- { SOCK_FLOAT, 0, N_("Vertex Alpha")},
- { SOCK_FLOAT, 0, N_("Front/Back")},
- { -1, 0, "" }
-};
-
-/* node execute callback */
-static void node_shader_exec_geom(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out)
-{
- if (data) {
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
- NodeGeometry *ngeo = (NodeGeometry *)node->storage;
- ShadeInputUV *suv = &shi->uv[shi->actuv];
- static float defaultvcol[4] = {1.0f, 1.0f, 1.0f, 1.0f};
- int i;
-
- if (ngeo->uvname[0]) {
- /* find uv map by name */
- for (i = 0; i < shi->totuv; i++) {
- if (STREQ(shi->uv[i].name, ngeo->uvname)) {
- suv = &shi->uv[i];
- break;
- }
- }
- }
-
- /* out: global, local, view, orco, uv, normal, vertex color */
- copy_v3_v3(out[GEOM_OUT_GLOB]->vec, shi->gl);
- copy_v3_v3(out[GEOM_OUT_LOCAL]->vec, shi->co);
- copy_v3_v3(out[GEOM_OUT_VIEW]->vec, shi->view);
- copy_v3_v3(out[GEOM_OUT_ORCO]->vec, shi->lo);
- copy_v3_v3(out[GEOM_OUT_UV]->vec, suv->uv);
- copy_v3_v3(out[GEOM_OUT_NORMAL]->vec, shi->vno);
-
- if (shi->use_world_space_shading) {
- negate_v3(out[GEOM_OUT_NORMAL]->vec);
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[GEOM_OUT_NORMAL]->vec);
- }
- if (shi->totcol) {
- /* find vertex color layer by name */
- ShadeInputCol *scol = &shi->col[0];
-
- if (ngeo->colname[0]) {
- for (i = 0; i < shi->totcol; i++) {
- if (STREQ(shi->col[i].name, ngeo->colname)) {
- scol = &shi->col[i];
- break;
- }
- }
- }
-
- srgb_to_linearrgb_v3_v3(out[GEOM_OUT_VCOL]->vec, scol->col);
- out[GEOM_OUT_VCOL]->vec[3] = scol->col[3];
- out[GEOM_OUT_VCOL_ALPHA]->vec[0] = scol->col[3];
- }
- else {
- memcpy(out[GEOM_OUT_VCOL]->vec, defaultvcol, sizeof(defaultvcol));
- out[GEOM_OUT_VCOL_ALPHA]->vec[0] = 1.0f;
- }
-
- if (shi->osatex) {
- out[GEOM_OUT_GLOB]->data = shi->dxgl;
- out[GEOM_OUT_GLOB]->datatype = NS_OSA_VECTORS;
- out[GEOM_OUT_LOCAL]->data = shi->dxco;
- out[GEOM_OUT_LOCAL]->datatype = NS_OSA_VECTORS;
- out[GEOM_OUT_VIEW]->data = &shi->dxview;
- out[GEOM_OUT_VIEW]->datatype = NS_OSA_VALUES;
- out[GEOM_OUT_ORCO]->data = shi->dxlo;
- out[GEOM_OUT_ORCO]->datatype = NS_OSA_VECTORS;
- out[GEOM_OUT_UV]->data = suv->dxuv;
- out[GEOM_OUT_UV]->datatype = NS_OSA_VECTORS;
- out[GEOM_OUT_NORMAL]->data = shi->dxno;
- out[GEOM_OUT_NORMAL]->datatype = NS_OSA_VECTORS;
- }
-
- /* front/back, normal flipping was stored */
- out[GEOM_OUT_FRONTBACK]->vec[0] = (shi->flippednor) ? 0.0f : 1.0f;
- }
-}
-
-static void node_shader_init_geometry(bNodeTree *UNUSED(ntree), bNode *node)
-{
- node->storage = MEM_callocN(sizeof(NodeGeometry), "NodeGeometry");
-}
-
-static int gpu_shader_geom(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
-{
- NodeGeometry *ngeo = (NodeGeometry *)node->storage;
- GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
- GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, ngeo->uvname);
- GPUNodeLink *mcol = GPU_attribute(CD_MCOL, ngeo->colname);
-
- bool ret = GPU_stack_link(mat, "geom", in, out,
- GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
- GPU_builtin(GPU_INVERSE_VIEW_MATRIX), orco, mtface, mcol);
- if (GPU_material_use_world_space_shading(mat)) {
- GPU_link(mat, "vec_math_negate", out[5].link, &out[5].link);
- ret &= GPU_link(mat, "direction_transform_m4v3", out[5].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[5].link);
- }
- return ret;
-}
-
-/* node type definition */
-void register_node_type_sh_geom(void)
-{
- static bNodeType ntype;
-
- sh_node_type_base(&ntype, SH_NODE_GEOMETRY, "Geometry", NODE_CLASS_INPUT, 0);
- node_type_compatibility(&ntype, NODE_OLD_SHADING);
- node_type_socket_templates(&ntype, NULL, sh_node_geom_out);
- node_type_init(&ntype, node_shader_init_geometry);
- node_type_storage(&ntype, "NodeGeometry", node_free_standard_storage, node_copy_standard_storage);
- node_type_exec(&ntype, NULL, NULL, node_shader_exec_geom);
- node_type_gpu(&ntype, gpu_shader_geom);
-
- nodeRegisterType(&ntype);
-}
diff --git a/source/blender/nodes/shader/nodes/node_shader_geometry.c b/source/blender/nodes/shader/nodes/node_shader_geometry.c
index 553ea65154f..6647f27e5c9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_geometry.c
+++ b/source/blender/nodes/shader/nodes/node_shader_geometry.c
@@ -41,10 +41,11 @@ static bNodeSocketTemplate sh_node_geometry_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_geometry(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_geometry", in, out,
+ return GPU_stack_link(mat, node, "node_geometry", in, out,
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
+ GPU_attribute(CD_ORCO, ""), GPU_builtin(GPU_OBJECT_MATRIX),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX));
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c
index 6fe6a33010a..9eaa0c9f91c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c
+++ b/source/blender/nodes/shader/nodes/node_shader_hueSatVal.c
@@ -82,9 +82,9 @@ static void node_shader_exec_hue_sat(void *UNUSED(data), int UNUSED(thread), bNo
}
-static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_hue_sat(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "hue_sat", in, out);
+ return GPU_stack_link(mat, node, "hue_sat", in, out);
}
void register_node_type_sh_hue_sat(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_invert.c b/source/blender/nodes/shader/nodes/node_shader_invert.c
index 27450ba0fe6..6a54733006d 100644
--- a/source/blender/nodes/shader/nodes/node_shader_invert.c
+++ b/source/blender/nodes/shader/nodes/node_shader_invert.c
@@ -65,9 +65,9 @@ static void node_shader_exec_invert(void *UNUSED(data), int UNUSED(thread), bNod
copy_v3_v3(out[0]->vec, icol);
}
-static int gpu_shader_invert(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_invert(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "invert", in, out);
+ return GPU_stack_link(mat, node, "invert", in, out);
}
void register_node_type_sh_invert(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_lamp.c b/source/blender/nodes/shader/nodes/node_shader_lamp.c
deleted file mode 100644
index 2c96c91958e..00000000000
--- a/source/blender/nodes/shader/nodes/node_shader_lamp.c
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2013 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/nodes/shader/nodes/node_shader_lamp.c
- * \ingroup shdnodes
- */
-
-
-#include "node_shader_util.h"
-
-/* **************** LAMP INFO ******************** */
-static bNodeSocketTemplate sh_node_lamp_out[] = {
- { SOCK_RGBA, 0, N_("Color")},
- { SOCK_VECTOR, 0, N_("Light Vector")},
- { SOCK_FLOAT, 0, N_("Distance")},
- { SOCK_RGBA, 0, N_("Shadow")},
- { SOCK_FLOAT, 0, N_("Visibility Factor")},
- { -1, 0, "" }
-};
-
-
-static void node_shader_exec_lamp(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out)
-{
- if (data) {
- Object *ob = (Object *)node->id;
-
- if (ob) {
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
-
- shi->nodes = 1; /* temp hack to prevent trashadow recursion */
- out[4]->vec[0] = RE_lamp_get_data(shi, ob, out[0]->vec, out[1]->vec, out[2]->vec, out[3]->vec);
- shi->nodes = 0;
- if (shi->use_world_space_shading)
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[1]->vec);
- }
- }
-}
-
-static int gpu_shader_lamp(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
-{
- if (node->id) {
- GPULamp *lamp = GPU_lamp_from_blender(GPU_material_scene(mat), (Object *)node->id, NULL);
- GPUNodeLink *col, *lv, *dist, *visifac, *shadow, *energy;
-
- visifac = GPU_lamp_get_data(mat, lamp, &col, &lv, &dist, &shadow, &energy);
-
- bool ret = GPU_stack_link(mat, "lamp", in, out, col, energy, lv, dist, shadow, visifac);
- if (GPU_material_use_world_space_shading(mat))
- ret &= GPU_link(mat, "direction_transform_m4v3", out[1].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[1].link);
- return ret;
- }
-
- return false;
-}
-
-void register_node_type_sh_lamp(void)
-{
- static bNodeType ntype;
-
- sh_node_type_base(&ntype, SH_NODE_LAMP, "Lamp Data", NODE_CLASS_INPUT, 0);
- node_type_compatibility(&ntype, NODE_OLD_SHADING);
- node_type_socket_templates(&ntype, NULL, sh_node_lamp_out);
- node_type_exec(&ntype, NULL, NULL, node_shader_exec_lamp);
- node_type_gpu(&ntype, gpu_shader_lamp);
-
- nodeRegisterType(&ntype);
-}
diff --git a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c
index 998e1a5687e..87ed85ffa99 100644
--- a/source/blender/nodes/shader/nodes/node_shader_layer_weight.c
+++ b/source/blender/nodes/shader/nodes/node_shader_layer_weight.c
@@ -41,52 +41,20 @@ static bNodeSocketTemplate sh_node_layer_weight_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_layer_weight(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- if (!in[1].link)
+ if (!in[1].link) {
in[1].link = GPU_builtin(GPU_VIEW_NORMAL);
- else if (GPU_material_use_world_space_shading(mat)) {
+ }
+ else {
GPU_link(mat, "direction_transform_m4v3", in[1].link, GPU_builtin(GPU_VIEW_MATRIX), &in[1].link);
}
- return GPU_stack_link(mat, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION));
+ return GPU_stack_link(mat, node, "node_layer_weight", in, out, GPU_builtin(GPU_VIEW_POSITION));
}
-static void node_shader_exec_layer_weight(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
+static void node_shader_exec_layer_weight(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
-
- /* Compute IOR. */
- float blend;
- nodestack_get_vec(&blend, SOCK_FLOAT, in[0]);
- float eta = max_ff(1 - blend, 0.00001);
- eta = shi->flippednor ? eta : 1 / eta;
-
- /* Get normal from socket, but only if linked. */
- bNodeSocket *sock_normal = node->inputs.first;
- sock_normal = sock_normal->next;
-
- float n[3];
- if (sock_normal->link) {
- nodestack_get_vec(n, SOCK_VECTOR, in[1]);
- }
- else {
- copy_v3_v3(n, shi->vn);
- }
-
-
- if (shi->use_world_space_shading)
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), n);
-
- out[0]->vec[0] = RE_fresnel_dielectric(shi->view, n, eta);
-
- float facing = fabs(dot_v3v3(shi->view, n));
- if (blend != 0.5) {
- CLAMP(blend, 0.0, 0.99999);
- blend = (blend < 0.5) ? 2.0 * blend : 0.5 / (1.0 - blend);
- facing = pow(facing, blend);
- }
- out[1]->vec[0] = 1.0 - facing;
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_light_falloff.c b/source/blender/nodes/shader/nodes/node_shader_light_falloff.c
index 3aad476ea05..a51e4dc720f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_light_falloff.c
+++ b/source/blender/nodes/shader/nodes/node_shader_light_falloff.c
@@ -44,9 +44,9 @@ static bNodeSocketTemplate sh_node_light_falloff_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_light_falloff(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_light_falloff(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_light_falloff", in, out);
+ return GPU_stack_link(mat, node, "node_light_falloff", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_light_path.c b/source/blender/nodes/shader/nodes/node_shader_light_path.c
index 052f2a66ec8..be6db9c8269 100644
--- a/source/blender/nodes/shader/nodes/node_shader_light_path.c
+++ b/source/blender/nodes/shader/nodes/node_shader_light_path.c
@@ -46,9 +46,9 @@ static bNodeSocketTemplate sh_node_light_path_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_light_path(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_light_path(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_light_path", in, out);
+ return GPU_stack_link(mat, node, "node_light_path", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_mapping.c b/source/blender/nodes/shader/nodes/node_shader_mapping.c
index 2044f5390cc..7f25b298cb2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mapping.c
+++ b/source/blender/nodes/shader/nodes/node_shader_mapping.c
@@ -94,7 +94,7 @@ static int gpu_shader_mapping(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
GPUNodeLink *tdomin = GPU_uniform(&domin);
GPUNodeLink *tdomax = GPU_uniform(&domax);
- GPU_stack_link(mat, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
+ GPU_stack_link(mat, node, "mapping", in, out, tmat, tmin, tmax, tdomin, tdomax);
if (texmap->type == TEXMAP_TYPE_NORMAL)
GPU_link(mat, "texco_norm", out[0].link, &out[0].link);
diff --git a/source/blender/nodes/shader/nodes/node_shader_material.c b/source/blender/nodes/shader/nodes/node_shader_material.c
deleted file mode 100644
index 6850cdbf6ea..00000000000
--- a/source/blender/nodes/shader/nodes/node_shader_material.c
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2005 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/nodes/shader/nodes/node_shader_material.c
- * \ingroup shdnodes
- */
-
-#include "node_shader_util.h"
-
-/* **************** MATERIAL ******************** */
-
-static bNodeSocketTemplate sh_node_material_in[] = {
- { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
- { SOCK_RGBA, 1, N_("Spec"), 0.0f, 0.0f, 0.0f, 1.0f},
- { SOCK_FLOAT, 1, N_("DiffuseIntensity"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
- { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION},
- { -1, 0, "" }
-};
-
-static bNodeSocketTemplate sh_node_material_out[] = {
- { SOCK_RGBA, 0, N_("Color")},
- { SOCK_FLOAT, 0, N_("Alpha")},
- { SOCK_VECTOR, 0, N_("Normal")},
- { -1, 0, "" }
-};
-
-/* **************** EXTENDED MATERIAL ******************** */
-
-static bNodeSocketTemplate sh_node_material_ext_in[] = {
- { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
- { SOCK_RGBA, 1, N_("Spec"), 0.0f, 0.0f, 0.0f, 1.0f},
- { SOCK_FLOAT, 1, N_("DiffuseIntensity"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
- { SOCK_VECTOR, 1, N_("Normal"), 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_DIRECTION},
- { SOCK_RGBA, 1, N_("Mirror"), 0.0f, 0.0f, 0.0f, 1.0f},
- { SOCK_FLOAT, 1, N_("Ambient"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
- { SOCK_FLOAT, 1, N_("Emit"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
- { SOCK_FLOAT, 1, N_("SpecTra"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
- { SOCK_FLOAT, 1, N_("Reflectivity"), 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
- { SOCK_FLOAT, 1, N_("Alpha"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_UNSIGNED},
- { SOCK_FLOAT, 1, N_("Translucency"), 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, PROP_NONE},
- { -1, 0, "" }
-};
-
-static bNodeSocketTemplate sh_node_material_ext_out[] = {
- { SOCK_RGBA, 0, N_("Color")},
- { SOCK_FLOAT, 0, N_("Alpha")},
- { SOCK_VECTOR, 0, N_("Normal")},
- { SOCK_RGBA, 0, N_("Diffuse")},
- { SOCK_RGBA, 0, N_("Spec")},
- { SOCK_RGBA, 0, N_("AO")},
- { -1, 0, "" }
-};
-
-static void node_shader_exec_material(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
-{
- if (data && node->id) {
- ShadeResult shrnode;
- ShadeInput *shi;
- ShaderCallData *shcd = data;
- float col[4];
- bNodeSocket *sock;
- char hasinput[NUM_MAT_IN] = {'\0'};
- int i, mode;
-
- /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily
- * the constant input stack values (e.g. in case material node is inside a group).
- * we just want to know if a node input uses external data or the material setting.
- * this is an ugly hack, but so is this node as a whole.
- */
- for (sock = node->inputs.first, i = 0; sock; sock = sock->next, ++i)
- hasinput[i] = (sock->link != NULL);
-
- shi = shcd->shi;
- shi->mat = (Material *)node->id;
-
- /* copy all relevant material vars, note, keep this synced with render_types.h */
- memcpy(&shi->r, &shi->mat->r, 23 * sizeof(float));
- shi->har = shi->mat->har;
-
- /* write values */
- if (hasinput[MAT_IN_COLOR])
- nodestack_get_vec(&shi->r, SOCK_VECTOR, in[MAT_IN_COLOR]);
-
- if (hasinput[MAT_IN_SPEC])
- nodestack_get_vec(&shi->specr, SOCK_VECTOR, in[MAT_IN_SPEC]);
-
- if (hasinput[MAT_IN_REFL])
- nodestack_get_vec(&shi->refl, SOCK_FLOAT, in[MAT_IN_REFL]);
-
- /* retrieve normal */
- if (hasinput[MAT_IN_NORMAL]) {
- nodestack_get_vec(shi->vn, SOCK_VECTOR, in[MAT_IN_NORMAL]);
- if (shi->use_world_space_shading) {
- negate_v3(shi->vn);
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), shi->vn);
- }
- normalize_v3(shi->vn);
- }
- else
- copy_v3_v3(shi->vn, shi->vno);
-
- /* custom option to flip normal */
- if (node->custom1 & SH_NODE_MAT_NEG) {
- negate_v3(shi->vn);
- }
-
- if (node->type == SH_NODE_MATERIAL_EXT) {
- if (hasinput[MAT_IN_MIR])
- nodestack_get_vec(&shi->mirr, SOCK_VECTOR, in[MAT_IN_MIR]);
- if (hasinput[MAT_IN_AMB])
- nodestack_get_vec(&shi->amb, SOCK_FLOAT, in[MAT_IN_AMB]);
- if (hasinput[MAT_IN_EMIT])
- nodestack_get_vec(&shi->emit, SOCK_FLOAT, in[MAT_IN_EMIT]);
- if (hasinput[MAT_IN_SPECTRA])
- nodestack_get_vec(&shi->spectra, SOCK_FLOAT, in[MAT_IN_SPECTRA]);
- if (hasinput[MAT_IN_RAY_MIRROR])
- nodestack_get_vec(&shi->ray_mirror, SOCK_FLOAT, in[MAT_IN_RAY_MIRROR]);
- if (hasinput[MAT_IN_ALPHA])
- nodestack_get_vec(&shi->alpha, SOCK_FLOAT, in[MAT_IN_ALPHA]);
- if (hasinput[MAT_IN_TRANSLUCENCY])
- nodestack_get_vec(&shi->translucency, SOCK_FLOAT, in[MAT_IN_TRANSLUCENCY]);
- }
-
- /* make alpha output give results even if transparency is only enabled on
- * the material linked in this not and not on the parent material */
- mode = shi->mode;
- if (shi->mat->mode & MA_TRANSP)
- shi->mode |= MA_TRANSP;
-
- shi->nodes = 1; /* temp hack to prevent trashadow recursion */
- node_shader_lamp_loop(shi, &shrnode); /* clears shrnode */
- shi->nodes = 0;
-
- shi->mode = mode;
-
- /* write to outputs */
- if (node->custom1 & SH_NODE_MAT_DIFF) {
- copy_v3_v3(col, shrnode.combined);
- if (!(node->custom1 & SH_NODE_MAT_SPEC)) {
- sub_v3_v3(col, shrnode.spec);
- }
- }
- else if (node->custom1 & SH_NODE_MAT_SPEC) {
- copy_v3_v3(col, shrnode.spec);
- }
- else
- col[0] = col[1] = col[2] = 0.0f;
-
- col[3] = shrnode.alpha;
-
- if (shi->do_preview)
- BKE_node_preview_set_pixel(execdata->preview, col, shi->xs, shi->ys, shi->do_manage);
-
- copy_v3_v3(out[MAT_OUT_COLOR]->vec, col);
- out[MAT_OUT_ALPHA]->vec[0] = shrnode.alpha;
-
- if (node->custom1 & SH_NODE_MAT_NEG) {
- shi->vn[0] = -shi->vn[0];
- shi->vn[1] = -shi->vn[1];
- shi->vn[2] = -shi->vn[2];
- }
-
- copy_v3_v3(out[MAT_OUT_NORMAL]->vec, shi->vn);
-
- if (shi->use_world_space_shading) {
- negate_v3(out[MAT_OUT_NORMAL]->vec);
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[MAT_OUT_NORMAL]->vec);
- }
- /* Extended material options */
- if (node->type == SH_NODE_MATERIAL_EXT) {
- /* Shadow, Reflect, Refract, Radiosity, Speed seem to cause problems inside
- * a node tree :( */
- copy_v3_v3(out[MAT_OUT_DIFFUSE]->vec, shrnode.diffshad);
- copy_v3_v3(out[MAT_OUT_SPEC]->vec, shrnode.spec);
- copy_v3_v3(out[MAT_OUT_AO]->vec, shrnode.ao);
- }
-
- /* copy passes, now just active node */
- if (node->flag & NODE_ACTIVE_ID) {
- float combined[4], alpha;
-
- copy_v4_v4(combined, shcd->shr->combined);
- alpha = shcd->shr->alpha;
-
- *(shcd->shr) = shrnode;
-
- copy_v4_v4(shcd->shr->combined, combined);
- shcd->shr->alpha = alpha;
- }
- }
-}
-
-
-static void node_shader_init_material(bNodeTree *UNUSED(ntree), bNode *node)
-{
- node->custom1 = SH_NODE_MAT_DIFF | SH_NODE_MAT_SPEC;
-}
-
-/* XXX this is also done as a local static function in gpu_codegen.c,
- * but we need this to hack around the crappy material node.
- */
-static GPUNodeLink *gpu_get_input_link(GPUMaterial *mat, GPUNodeStack *in)
-{
- if (in->link) {
- return in->link;
- }
- else {
- GPUNodeLink *result = NULL;
-
- /* note GPU_uniform() is only intended to be used as a parameter to
- * GPU_link(), returning it directly results in leaks or double frees */
- if (in->type == GPU_FLOAT)
- GPU_link(mat, "set_value", GPU_uniform(in->vec), &result);
- else if (in->type == GPU_VEC3)
- GPU_link(mat, "set_rgb", GPU_uniform(in->vec), &result);
- else if (in->type == GPU_VEC4)
- GPU_link(mat, "set_rgba", GPU_uniform(in->vec), &result);
- else
- BLI_assert(0);
-
- return result;
- }
-}
-
-static int gpu_shader_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
-{
- if (node->id) {
- GPUShadeInput shi;
- GPUShadeResult shr;
- bNodeSocket *sock;
- char hasinput[NUM_MAT_IN] = {'\0'};
- int i;
-
- /* note: cannot use the in[]->hasinput flags directly, as these are not necessarily
- * the constant input stack values (e.g. in case material node is inside a group).
- * we just want to know if a node input uses external data or the material setting.
- */
- for (sock = node->inputs.first, i = 0; sock; sock = sock->next, ++i)
- hasinput[i] = (sock->link != NULL);
-
- GPU_shadeinput_set(mat, (Material *)node->id, &shi);
-
- /* write values */
- if (hasinput[MAT_IN_COLOR])
- shi.rgb = gpu_get_input_link(mat, &in[MAT_IN_COLOR]);
-
- if (hasinput[MAT_IN_SPEC])
- shi.specrgb = gpu_get_input_link(mat, &in[MAT_IN_SPEC]);
-
- if (hasinput[MAT_IN_REFL])
- shi.refl = gpu_get_input_link(mat, &in[MAT_IN_REFL]);
-
- /* retrieve normal */
- if (hasinput[MAT_IN_NORMAL]) {
- GPUNodeLink *tmp;
- shi.vn = gpu_get_input_link(mat, &in[MAT_IN_NORMAL]);
- if (GPU_material_use_world_space_shading(mat)) {
- GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn);
- GPU_link(mat, "direction_transform_m4v3", shi.vn, GPU_builtin(GPU_VIEW_MATRIX), &shi.vn);
- }
- GPU_link(mat, "vec_math_normalize", shi.vn, &shi.vn, &tmp);
- }
-
- /* custom option to flip normal */
- if (node->custom1 & SH_NODE_MAT_NEG)
- GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn);
-
- if (node->type == SH_NODE_MATERIAL_EXT) {
- if (hasinput[MAT_IN_MIR])
- shi.mir = gpu_get_input_link(mat, &in[MAT_IN_MIR]);
- if (hasinput[MAT_IN_AMB])
- shi.amb = gpu_get_input_link(mat, &in[MAT_IN_AMB]);
- if (hasinput[MAT_IN_EMIT])
- shi.emit = gpu_get_input_link(mat, &in[MAT_IN_EMIT]);
- if (hasinput[MAT_IN_SPECTRA])
- shi.spectra = gpu_get_input_link(mat, &in[MAT_IN_SPECTRA]);
- if (hasinput[MAT_IN_ALPHA])
- shi.alpha = gpu_get_input_link(mat, &in[MAT_IN_ALPHA]);
- }
-
- GPU_shaderesult_set(&shi, &shr); /* clears shr */
-
- /* write to outputs */
- if (node->custom1 & SH_NODE_MAT_DIFF) {
- out[MAT_OUT_COLOR].link = shr.combined;
-
- if (!(node->custom1 & SH_NODE_MAT_SPEC)) {
- GPUNodeLink *link;
- GPU_link(mat, "vec_math_sub", shr.combined, shr.spec, &out[MAT_OUT_COLOR].link, &link);
- }
- }
- else if (node->custom1 & SH_NODE_MAT_SPEC) {
- out[MAT_OUT_COLOR].link = shr.spec;
- }
- else
- GPU_link(mat, "set_rgb_zero", &out[MAT_OUT_COLOR].link);
-
- GPU_link(mat, "mtex_alpha_to_col", out[MAT_OUT_COLOR].link, shr.alpha, &out[MAT_OUT_COLOR].link);
-
- out[MAT_OUT_ALPHA].link = shr.alpha; //
-
- if (node->custom1 & SH_NODE_MAT_NEG)
- GPU_link(mat, "vec_math_negate", shi.vn, &shi.vn);
- out[MAT_OUT_NORMAL].link = shi.vn;
- if (GPU_material_use_world_space_shading(mat)) {
- GPU_link(mat, "vec_math_negate", out[MAT_OUT_NORMAL].link, &out[MAT_OUT_NORMAL].link);
- GPU_link(mat, "direction_transform_m4v3", out[MAT_OUT_NORMAL].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[MAT_OUT_NORMAL].link);
- }
-
- if (node->type == SH_NODE_MATERIAL_EXT) {
- out[MAT_OUT_DIFFUSE].link = shr.diff;
- out[MAT_OUT_SPEC].link = shr.spec;
- GPU_link(mat, "set_rgb_one", &out[MAT_OUT_AO].link);
- }
-
- return 1;
- }
-
- return 0;
-}
-
-void register_node_type_sh_material(void)
-{
- static bNodeType ntype;
-
- sh_node_type_base(&ntype, SH_NODE_MATERIAL, "Material", NODE_CLASS_INPUT, NODE_PREVIEW);
- node_type_compatibility(&ntype, NODE_OLD_SHADING);
- node_type_socket_templates(&ntype, sh_node_material_in, sh_node_material_out);
- node_type_init(&ntype, node_shader_init_material);
- node_type_exec(&ntype, NULL, NULL, node_shader_exec_material);
- node_type_gpu(&ntype, gpu_shader_material);
-
- nodeRegisterType(&ntype);
-}
-
-
-void register_node_type_sh_material_ext(void)
-{
- static bNodeType ntype;
-
- sh_node_type_base(&ntype, SH_NODE_MATERIAL_EXT, "Extended Material", NODE_CLASS_INPUT, NODE_PREVIEW);
- node_type_compatibility(&ntype, NODE_OLD_SHADING);
- node_type_socket_templates(&ntype, sh_node_material_ext_in, sh_node_material_ext_out);
- node_type_init(&ntype, node_shader_init_material);
- node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
- node_type_exec(&ntype, NULL, NULL, node_shader_exec_material);
- node_type_gpu(&ntype, gpu_shader_material);
-
- nodeRegisterType(&ntype);
-}
diff --git a/source/blender/nodes/shader/nodes/node_shader_math.c b/source/blender/nodes/shader/nodes/node_shader_math.c
index 2a1e936570d..6cd58d2fb85 100644
--- a/source/blender/nodes/shader/nodes/node_shader_math.c
+++ b/source/blender/nodes/shader/nodes/node_shader_math.c
@@ -249,7 +249,7 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
case NODE_MATH_LESS:
case NODE_MATH_GREATER:
case NODE_MATH_MOD:
- GPU_stack_link(mat, names[node->custom1], in, out);
+ GPU_stack_link(mat, node, names[node->custom1], in, out);
break;
case NODE_MATH_SIN:
case NODE_MATH_COS:
@@ -264,14 +264,14 @@ static int gpu_shader_math(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
- GPU_stack_link(mat, names[node->custom1], tmp_in, out);
+ GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
else {
/* use only second item and terminator */
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
- GPU_stack_link(mat, names[node->custom1], tmp_in, out);
+ GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
break;
default:
diff --git a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c
index f911fa058dc..cca0a1e0561 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mixRgb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_mixRgb.c
@@ -71,7 +71,8 @@ static int gpu_shader_mix_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUS
"mix_screen", "mix_div", "mix_diff", "mix_dark", "mix_light",
"mix_overlay", "mix_dodge", "mix_burn", "mix_hue", "mix_sat",
"mix_val", "mix_color", "mix_soft", "mix_linear"};
- int ret = GPU_stack_link(mat, names[node->custom1], in, out);
+
+ int ret = GPU_stack_link(mat, node, names[node->custom1], in, out);
if (ret && node->custom2 & SHD_MIXRGB_CLAMP) {
float min[3] = {0.0f, 0.0f, 0.0f};
float max[3] = {1.0f, 1.0f, 1.0f};
diff --git a/source/blender/nodes/shader/nodes/node_shader_mix_shader.c b/source/blender/nodes/shader/nodes/node_shader_mix_shader.c
index 7c5362a8969..5ac576004be 100644
--- a/source/blender/nodes/shader/nodes/node_shader_mix_shader.c
+++ b/source/blender/nodes/shader/nodes/node_shader_mix_shader.c
@@ -41,9 +41,9 @@ static bNodeSocketTemplate sh_node_mix_shader_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_mix_shader(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_mix_shader", in, out);
+ return GPU_stack_link(mat, node, "node_mix_shader", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_normal.c b/source/blender/nodes/shader/nodes/node_shader_normal.c
index 092fc201aa7..7033eeaead0 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal.c
+++ b/source/blender/nodes/shader/nodes/node_shader_normal.c
@@ -58,15 +58,10 @@ static void node_shader_exec_normal(void *UNUSED(data), int UNUSED(thread), bNod
out[1]->vec[0] = -dot_v3v3(vec, out[0]->vec);
}
-static int gpu_shader_normal(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_normal(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *vec = GPU_uniform(out[0].vec);
- if (GPU_material_use_new_shading_nodes(mat)) {
- return GPU_stack_link(mat, "normal_new_shading", in, out, vec);
- }
- else {
- return GPU_stack_link(mat, "normal", in, out, vec);
- }
+ return GPU_stack_link(mat, node, "normal_new_shading", in, out, vec);
}
void register_node_type_sh_normal(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_normal_map.c b/source/blender/nodes/shader/nodes/node_shader_normal_map.c
index 7584b5eba4d..0d58be76030 100644
--- a/source/blender/nodes/shader/nodes/node_shader_normal_map.c
+++ b/source/blender/nodes/shader/nodes/node_shader_normal_map.c
@@ -47,80 +47,9 @@ static void node_shader_init_normal_map(bNodeTree *UNUSED(ntree), bNode *node)
}
static void node_shader_exec_normal_map(
- void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata),
- bNodeStack **in, bNodeStack **out)
+ void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata),
+ bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
- if (data) {
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
-
- NodeShaderNormalMap *nm = node->storage;
-
- float strength, vecIn[3];
- nodestack_get_vec(&strength, SOCK_FLOAT, in[0]);
- nodestack_get_vec(vecIn, SOCK_VECTOR, in[1]);
-
- vecIn[0] = -2 * (vecIn[0] - 0.5f);
- vecIn[1] = 2 * (vecIn[1] - 0.5f);
- vecIn[2] = 2 * (vecIn[2] - 0.5f);
-
- CLAMP_MIN(strength, 0.0f);
-
- float *N = shi->nmapnorm;
- int uv_index = 0;
- switch (nm->space) {
- case SHD_SPACE_TANGENT:
- if (nm->uv_map[0]) {
- /* find uv map by name */
- for (int i = 0; i < shi->totuv; i++) {
- if (STREQ(shi->uv[i].name, nm->uv_map)) {
- uv_index = i;
- break;
- }
- }
- }
- else {
- uv_index = shi->actuv;
- }
-
- float *T = shi->tangents[uv_index];
-
- float B[3];
- cross_v3_v3v3(B, N, T);
- mul_v3_fl(B, T[3]);
-
- for (int j = 0; j < 3; j++)
- out[0]->vec[j] = vecIn[0] * T[j] + vecIn[1] * B[j] + vecIn[2] * N[j];
- interp_v3_v3v3(out[0]->vec, N, out[0]->vec, strength);
- if (shi->use_world_space_shading) {
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), out[0]->vec);
- }
- break;
-
- case SHD_SPACE_OBJECT:
- case SHD_SPACE_BLENDER_OBJECT:
- if (shi->use_world_space_shading) {
- mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB), vecIn);
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), N);
- }
- else
- mul_mat3_m4_v3((float (*)[4])RE_object_instance_get_matrix(shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW), vecIn);
- interp_v3_v3v3(out[0]->vec, N, vecIn, strength);
- break;
-
- case SHD_SPACE_WORLD:
- case SHD_SPACE_BLENDER_WORLD:
- if (shi->use_world_space_shading)
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEWINV_MATRIX), N);
- else
- mul_mat3_m4_v3((float (*)[4])RE_render_current_get_matrix(RE_VIEW_MATRIX), vecIn);
- interp_v3_v3v3(out[0]->vec, N, vecIn, strength);
- break;
- }
- if (shi->use_world_space_shading) {
- negate_v3(out[0]->vec);
- }
- normalize_v3(out[0]->vec);
- }
}
static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
@@ -145,57 +74,29 @@ static int gpu_shader_normal_map(GPUMaterial *mat, bNode *node, bNodeExecData *U
negnorm = GPU_builtin(GPU_VIEW_NORMAL);
GPU_link(mat, "math_max", strength, GPU_uniform(d), &strength);
- if (GPU_material_use_world_space_shading(mat)) {
-
- /* ******* CYCLES or BLENDER INTERNAL with world space shading flag ******* */
-
- const char *color_to_normal_fnc_name = "color_to_normal_new_shading";
- if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD || !GPU_material_use_new_shading_nodes(mat))
- color_to_normal_fnc_name = "color_to_blender_normal_new_shading";
- switch (nm->space) {
- case SHD_SPACE_TANGENT:
- GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm);
- GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm);
- GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link);
- /* for uniform scale this is sufficient to match Cycles */
- GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link);
- GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
- return true;
- case SHD_SPACE_OBJECT:
- case SHD_SPACE_BLENDER_OBJECT:
- GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
- GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm);
- GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm);
- break;
- case SHD_SPACE_WORLD:
- case SHD_SPACE_BLENDER_WORLD:
- GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
- GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm);
- break;
- }
-
- }
- else {
-
- /* ************** BLENDER INTERNAL without world space shading flag ******* */
-
- GPU_link(mat, "color_to_normal", realnorm, &realnorm);
- GPU_link(mat, "mtex_negate_texnormal", realnorm, &realnorm);
- GPU_link(mat, "vec_math_negate", negnorm, &negnorm);
-
- switch (nm->space) {
- case SHD_SPACE_TANGENT:
- GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm);
- break;
- case SHD_SPACE_OBJECT:
- case SHD_SPACE_BLENDER_OBJECT:
- GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_LOC_TO_VIEW_MATRIX), &realnorm);
- break;
- case SHD_SPACE_WORLD:
- case SHD_SPACE_BLENDER_WORLD:
- GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_VIEW_MATRIX), &realnorm);
- break;
- }
+ const char *color_to_normal_fnc_name = "color_to_normal_new_shading";
+ if (nm->space == SHD_SPACE_BLENDER_OBJECT || nm->space == SHD_SPACE_BLENDER_WORLD)
+ color_to_normal_fnc_name = "color_to_blender_normal_new_shading";
+ switch (nm->space) {
+ case SHD_SPACE_TANGENT:
+ GPU_link(mat, "color_to_normal_new_shading", realnorm, &realnorm);
+ GPU_link(mat, "node_normal_map", GPU_attribute(CD_TANGENT, nm->uv_map), negnorm, realnorm, &realnorm);
+ GPU_link(mat, "vec_math_mix", strength, realnorm, GPU_builtin(GPU_VIEW_NORMAL), &out[0].link);
+ /* for uniform scale this is sufficient to match Cycles */
+ GPU_link(mat, "direction_transform_m4v3", out[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &out[0].link);
+ GPU_link(mat, "vect_normalize", out[0].link, &out[0].link);
+ return true;
+ case SHD_SPACE_OBJECT:
+ case SHD_SPACE_BLENDER_OBJECT:
+ GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
+ GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm);
+ GPU_link(mat, "direction_transform_m4v3", realnorm, GPU_builtin(GPU_OBJECT_MATRIX), &realnorm);
+ break;
+ case SHD_SPACE_WORLD:
+ case SHD_SPACE_BLENDER_WORLD:
+ GPU_link(mat, "direction_transform_m4v3", negnorm, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &negnorm);
+ GPU_link(mat, color_to_normal_fnc_name, realnorm, &realnorm);
+ break;
}
GPU_link(mat, "vec_math_mix", strength, realnorm, negnorm, &out[0].link);
diff --git a/source/blender/nodes/shader/nodes/node_shader_object_info.c b/source/blender/nodes/shader/nodes/node_shader_object_info.c
index 63d3bac88a0..25c9bd77250 100644
--- a/source/blender/nodes/shader/nodes/node_shader_object_info.c
+++ b/source/blender/nodes/shader/nodes/node_shader_object_info.c
@@ -37,18 +37,13 @@ static bNodeSocketTemplate sh_node_object_info_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_object_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "node_object_info", in, out, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_OBJECT_INFO));
+ return GPU_stack_link(mat, node, "node_object_info", in, out, GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_OBJECT_INFO));
}
-static void node_shader_exec_object_info(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out)
+static void node_shader_exec_object_info(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
- ShaderCallData *scd = (ShaderCallData *)data;
- copy_v4_v4(out[0]->vec, RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB)[3]);
- out[1]->vec[0] = RE_object_instance_get_object_pass_index(scd->shi->obi);
- out[2]->vec[0] = scd->shi->mat->index;
- out[3]->vec[0] = RE_object_instance_get_random_id(scd->shi->obi) * (1.0f / (float)0xFFFFFFFF);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_output.c b/source/blender/nodes/shader/nodes/node_shader_output.c
deleted file mode 100644
index 789df09d898..00000000000
--- a/source/blender/nodes/shader/nodes/node_shader_output.c
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2005 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/nodes/shader/nodes/node_shader_output.c
- * \ingroup shdnodes
- */
-
-
-#include "node_shader_util.h"
-
-/* **************** OUTPUT ******************** */
-static bNodeSocketTemplate sh_node_output_in[] = {
- { SOCK_RGBA, 1, N_("Color"), 0.0f, 0.0f, 0.0f, 1.0f},
- { SOCK_FLOAT, 1, N_("Alpha"), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, PROP_NONE},
- { -1, 0, "" }
-};
-
-static void node_shader_exec_output(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **UNUSED(out))
-{
- if (data) {
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
- float col[4];
-
- /* stack order input sockets: col, alpha, normal */
- nodestack_get_vec(col, SOCK_VECTOR, in[0]);
- nodestack_get_vec(col + 3, SOCK_FLOAT, in[1]);
-
- if (shi->do_preview) {
- BKE_node_preview_set_pixel(execdata->preview, col, shi->xs, shi->ys, shi->do_manage);
- node->lasty = shi->ys;
- }
-
- if (node->flag & NODE_DO_OUTPUT) {
- ShadeResult *shr = ((ShaderCallData *)data)->shr;
-
- copy_v4_v4(shr->combined, col);
- shr->alpha = col[3];
-
- // copy_v3_v3(shr->nor, in[3]->vec);
- }
- }
-}
-
-static int gpu_shader_output(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
-{
- GPUNodeLink *outlink;
-
-#if 0
- if (in[1].hasinput)
- GPU_material_enable_alpha(mat);
-#endif
-
- GPU_stack_link(mat, "output_node", in, out, &outlink);
- GPU_material_output_link(mat, outlink);
-
- return 1;
-}
-
-void register_node_type_sh_output(void)
-{
- static bNodeType ntype;
-
- sh_node_type_base(&ntype, SH_NODE_OUTPUT, "Output", NODE_CLASS_OUTPUT, NODE_PREVIEW);
- node_type_compatibility(&ntype, NODE_OLD_SHADING);
- node_type_socket_templates(&ntype, sh_node_output_in, NULL);
- node_type_exec(&ntype, NULL, NULL, node_shader_exec_output);
- node_type_gpu(&ntype, gpu_shader_output);
-
- /* Do not allow muting output node. */
- node_type_internal_links(&ntype, NULL);
-
- nodeRegisterType(&ntype);
-}
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_material.c b/source/blender/nodes/shader/nodes/node_shader_output_material.c
index aeb8b546eed..e901e7c4590 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_material.c
+++ b/source/blender/nodes/shader/nodes/node_shader_output_material.c
@@ -27,6 +27,8 @@
#include "../node_shader_util.h"
+#include "BKE_scene.h"
+
/* **************** OUTPUT ******************** */
static bNodeSocketTemplate sh_node_output_material_in[] = {
@@ -36,11 +38,11 @@ static bNodeSocketTemplate sh_node_output_material_in[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_output_material(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *outlink;
- GPU_stack_link(mat, "node_output_material", in, out, &outlink);
+ GPU_stack_link(mat, node, "node_output_material", in, out, &outlink);
GPU_material_output_link(mat, outlink);
return true;
diff --git a/source/blender/nodes/shader/nodes/node_shader_output_world.c b/source/blender/nodes/shader/nodes/node_shader_output_world.c
index f95cc842720..abab4fc351a 100644
--- a/source/blender/nodes/shader/nodes/node_shader_output_world.c
+++ b/source/blender/nodes/shader/nodes/node_shader_output_world.c
@@ -35,11 +35,11 @@ static bNodeSocketTemplate sh_node_output_world_in[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_output_world(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *outlink;
- GPU_stack_link(mat, "node_output_world", in, out, &outlink);
+ GPU_stack_link(mat, node, "node_output_world", in, out, &outlink);
GPU_material_output_link(mat, outlink);
return true;
diff --git a/source/blender/nodes/shader/nodes/node_shader_particle_info.c b/source/blender/nodes/shader/nodes/node_shader_particle_info.c
index 3dbe5c81c57..46cb513a6d9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_particle_info.c
+++ b/source/blender/nodes/shader/nodes/node_shader_particle_info.c
@@ -42,17 +42,14 @@ static bNodeSocketTemplate outputs[] = {
{ SOCK_VECTOR, 0, "Angular Velocity" },
{ -1, 0, "" }
};
-static void node_shader_exec_particle_info(void *data, int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **out)
+static void node_shader_exec_particle_info(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
-
- RE_instance_get_particle_info(shi->obi, out[0]->vec, out[1]->vec, out[2]->vec, out[3]->vec, out[4]->vec, out[5]->vec, out[6]->vec, out[7]->vec);
}
-static int gpu_shader_particle_info(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_particle_info(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "particle_info", in, out,
+ return GPU_stack_link(mat, node, "particle_info", in, out,
GPU_builtin(GPU_PARTICLE_SCALAR_PROPS),
GPU_builtin(GPU_PARTICLE_LOCATION),
GPU_builtin(GPU_PARTICLE_VELOCITY),
diff --git a/source/blender/nodes/shader/nodes/node_shader_rgb.c b/source/blender/nodes/shader/nodes/node_shader_rgb.c
index 4f345bf2067..b9c051c0441 100644
--- a/source/blender/nodes/shader/nodes/node_shader_rgb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_rgb.c
@@ -38,10 +38,10 @@ static bNodeSocketTemplate sh_node_rgb_out[] = {
{ -1, 0, "" }
};
-static int gpu_shader_rgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_rgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- GPUNodeLink *vec = GPU_uniform(out[0].vec);
- return GPU_stack_link(mat, "set_rgba", in, out, vec);
+ GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0);
+ return GPU_stack_link(mat, node, "set_rgba", in, out, link);
}
void register_node_type_sh_rgb(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c
index b5b15397595..d031a2e412f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcombHSV.c
@@ -53,9 +53,9 @@ static void node_shader_exec_sephsv(void *UNUSED(data), int UNUSED(thread), bNod
&out[0]->vec[0], &out[1]->vec[0], &out[2]->vec[0]);
}
-static int gpu_shader_sephsv(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_sephsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "separate_hsv", in, out);
+ return GPU_stack_link(mat, node, "separate_hsv", in, out);
}
void register_node_type_sh_sephsv(void)
@@ -94,9 +94,9 @@ static void node_shader_exec_combhsv(void *UNUSED(data), int UNUSED(thread), bNo
hsv_to_rgb(h, s, v, &out[0]->vec[0], &out[0]->vec[1], &out[0]->vec[2]);
}
-static int gpu_shader_combhsv(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_combhsv(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "combine_hsv", in, out);
+ return GPU_stack_link(mat, node, "combine_hsv", in, out);
}
void register_node_type_sh_combhsv(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c
index 006ba34c3f3..682909edb0e 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcombRGB.c
@@ -54,9 +54,9 @@ static void node_shader_exec_seprgb(void *UNUSED(data), int UNUSED(thread), bNod
out[2]->vec[0] = col[2];
}
-static int gpu_shader_seprgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_seprgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "separate_rgb", in, out);
+ return GPU_stack_link(mat, node, "separate_rgb", in, out);
}
void register_node_type_sh_seprgb(void)
@@ -98,9 +98,9 @@ static void node_shader_exec_combrgb(void *UNUSED(data), int UNUSED(thread), bNo
out[0]->vec[2] = b;
}
-static int gpu_shader_combrgb(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_combrgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "combine_rgb", in, out);
+ return GPU_stack_link(mat, node, "combine_rgb", in, out);
}
void register_node_type_sh_combrgb(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c
index 6375dcc8782..fce62f730b9 100644
--- a/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c
+++ b/source/blender/nodes/shader/nodes/node_shader_sepcombXYZ.c
@@ -44,9 +44,9 @@ static bNodeSocketTemplate sh_node_sepxyz_out[] = {
{ -1, 0, "" }
};
-static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_sepxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "separate_xyz", in, out);
+ return GPU_stack_link(mat, node, "separate_xyz", in, out);
}
void register_node_type_sh_sepxyz(void)
@@ -75,9 +75,9 @@ static bNodeSocketTemplate sh_node_combxyz_out[] = {
{ -1, 0, "" }
};
-static int gpu_shader_combxyz(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_combxyz(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "combine_xyz", in, out);
+ return GPU_stack_link(mat, node, "combine_xyz", in, out);
}
void register_node_type_sh_combxyz(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_squeeze.c b/source/blender/nodes/shader/nodes/node_shader_squeeze.c
index a4c995748d9..2a1fbc2d02d 100644
--- a/source/blender/nodes/shader/nodes/node_shader_squeeze.c
+++ b/source/blender/nodes/shader/nodes/node_shader_squeeze.c
@@ -56,9 +56,9 @@ static void node_shader_exec_squeeze(void *UNUSED(data), int UNUSED(thread), bNo
out[0]->vec[0] = 1.0f / (1.0f + powf(M_E, -((vec[0] - vec[2]) * vec[1])));
}
-static int gpu_shader_squeeze(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_squeeze(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "squeeze", in, out);
+ return GPU_stack_link(mat, node, "squeeze", in, out);
}
void register_node_type_sh_squeeze(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c
index 5051e37310e..4b4f08a8b56 100644
--- a/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c
+++ b/source/blender/nodes/shader/nodes/node_shader_subsurface_scattering.c
@@ -49,14 +49,23 @@ static void node_shader_init_subsurface_scattering(bNodeTree *UNUSED(ntree), bNo
node->custom1 = SHD_SUBSURFACE_BURLEY;
}
-static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_subsurface_scattering(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
if (!in[5].link)
- in[5].link = GPU_builtin(GPU_VIEW_NORMAL);
- else
- GPU_link(mat, "direction_transform_m4v3", in[5].link, GPU_builtin(GPU_VIEW_MATRIX), &in[5].link);
+ GPU_link(mat, "world_normals_get", &in[5].link);
- return GPU_stack_link(mat, "node_subsurface_scattering", in, out);
+ if (node->sss_id == 1) {
+ bNodeSocket *socket = BLI_findlink(&node->original->inputs, 2);
+ bNodeSocketValueRGBA *socket_data = socket->default_value;
+ bNodeSocket *socket_sharp = BLI_findlink(&node->original->inputs, 3);
+ bNodeSocketValueFloat *socket_data_sharp = socket_sharp->default_value;
+ /* For some reason it seems that the socket value is in ARGB format. */
+ GPU_material_sss_profile_create(mat, &socket_data->value[1],
+ &node->original->custom1,
+ &socket_data_sharp->value);
+ }
+
+ return GPU_stack_link(mat, node, "node_subsurface_scattering", in, out, GPU_uniform(&node->sss_id));
}
static void node_shader_update_subsurface_scattering(bNodeTree *UNUSED(ntree), bNode *node)
diff --git a/source/blender/nodes/shader/nodes/node_shader_tangent.c b/source/blender/nodes/shader/nodes/node_shader_tangent.c
index 7aa7fb43221..f2c59ec8fd8 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tangent.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tangent.c
@@ -41,6 +41,28 @@ static void node_shader_init_tangent(bNodeTree *UNUSED(ntree), bNode *node)
node->storage = attr;
}
+static int node_shader_gpu_tangent(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+{
+ NodeShaderTangent *attr = node->storage;
+
+ if (attr->direction_type == SHD_TANGENT_UVMAP) {
+ return GPU_stack_link(mat, node, "node_tangentmap", in, out, GPU_attribute(CD_TANGENT, ""), GPU_builtin(GPU_INVERSE_VIEW_MATRIX));
+ }
+ else {
+ GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
+
+ if (attr->axis == SHD_TANGENT_AXIS_X)
+ GPU_link(mat, "tangent_orco_x", orco, &orco);
+ else if (attr->axis == SHD_TANGENT_AXIS_Y)
+ GPU_link(mat, "tangent_orco_y", orco, &orco);
+ else
+ GPU_link(mat, "tangent_orco_z", orco, &orco);
+
+ return GPU_stack_link(mat, node, "node_tangent", in, out, GPU_builtin(GPU_VIEW_NORMAL), orco,
+ GPU_builtin(GPU_OBJECT_MATRIX), GPU_builtin(GPU_INVERSE_VIEW_MATRIX));
+ }
+}
+
/* node type definition */
void register_node_type_sh_tangent(void)
{
@@ -51,6 +73,7 @@ void register_node_type_sh_tangent(void)
node_type_socket_templates(&ntype, NULL, sh_node_tangent_out);
node_type_size_preset(&ntype, NODE_SIZE_MIDDLE);
node_type_init(&ntype, node_shader_init_tangent);
+ node_type_gpu(&ntype, node_shader_gpu_tangent);
node_type_storage(&ntype, "NodeShaderTangent", node_free_standard_storage, node_copy_standard_storage);
nodeRegisterType(&ntype);
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c
index 1dfebc45d60..20ea162d98f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_brick.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_brick.c
@@ -80,7 +80,7 @@ static int node_shader_gpu_tex_brick(GPUMaterial *mat, bNode *node, bNodeExecDat
NodeTexBrick *tex = (NodeTexBrick *)node->storage;
float offset_freq = tex->offset_freq;
float squash_freq = tex->squash_freq;
- return GPU_stack_link(mat, "node_tex_brick",
+ return GPU_stack_link(mat, node, "node_tex_brick",
in, out,
GPU_uniform(&tex->offset), GPU_uniform(&offset_freq),
GPU_uniform(&tex->squash), GPU_uniform(&squash_freq));
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c
index 77edd0e115e..3dbf98a929c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_checker.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_checker.c
@@ -61,7 +61,7 @@ static int node_shader_gpu_tex_checker(GPUMaterial *mat, bNode *node, bNodeExecD
node_shader_gpu_tex_mapping(mat, node, in, out);
- return GPU_stack_link(mat, "node_tex_checker", in, out);
+ return GPU_stack_link(mat, node, "node_tex_checker", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c
index be393582a42..0cab9379364 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_coord.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_coord.c
@@ -42,20 +42,22 @@ static bNodeSocketTemplate sh_node_tex_coord_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int node_shader_gpu_tex_coord(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
GPUNodeLink *orco = GPU_attribute(CD_ORCO, "");
GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, "");
GPUMatType type = GPU_Material_get_type(mat);
+
+ GPU_link(mat, "generated_from_orco", orco, &orco);
- if (type == GPU_MATERIAL_TYPE_MESH) {
- return GPU_stack_link(mat, "node_tex_coord", in, out,
+ if (type == GPU_MATERIAL_TYPE_WORLD) {
+ return GPU_stack_link(mat, node, "node_tex_coord_background", in, out,
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface);
}
else {
- return GPU_stack_link(mat, "node_tex_coord_background", in, out,
+ return GPU_stack_link(mat, node, "node_tex_coord", in, out,
GPU_builtin(GPU_VIEW_POSITION), GPU_builtin(GPU_VIEW_NORMAL),
GPU_builtin(GPU_INVERSE_VIEW_MATRIX), GPU_builtin(GPU_INVERSE_OBJECT_MATRIX),
GPU_builtin(GPU_CAMERA_TEXCO_FACTORS), orco, mtface);
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
index 508abbf4db1..8a65ee89ffc 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_environment.c
@@ -62,7 +62,7 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
int isdata = tex->color_space == SHD_COLORSPACE_NONE;
if (!ima)
- return GPU_stack_link(mat, "node_tex_environment_empty", in, out);
+ return GPU_stack_link(mat, node, "node_tex_environment_empty", in, out);
if (!in[0].link) {
GPUMatType type = GPU_Material_get_type(mat);
@@ -76,9 +76,9 @@ static int node_shader_gpu_tex_environment(GPUMaterial *mat, bNode *node, bNodeE
node_shader_gpu_tex_mapping(mat, node, in, out);
if (tex->projection == SHD_PROJ_EQUIRECTANGULAR)
- GPU_stack_link(mat, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, node, "node_tex_environment_equirectangular", in, out, GPU_image(ima, iuser, isdata));
else
- GPU_stack_link(mat, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, node, "node_tex_environment_mirror_ball", in, out, GPU_image(ima, iuser, isdata));
ImBuf *ibuf = BKE_image_acquire_ibuf(ima, iuser, NULL);
if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c
index 18a8065fb57..13d3438587c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_gradient.c
@@ -61,7 +61,7 @@ static int node_shader_gpu_tex_gradient(GPUMaterial *mat, bNode *node, bNodeExec
NodeTexGradient *tex = (NodeTexGradient *)node->storage;
float gradient_type = tex->gradient_type;
- return GPU_stack_link(mat, "node_tex_gradient", in, out, GPU_uniform(&gradient_type));
+ return GPU_stack_link(mat, node, "node_tex_gradient", in, out, GPU_uniform(&gradient_type));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_image.c b/source/blender/nodes/shader/nodes/node_shader_tex_image.c
index 5f5cec61513..22f302a9c59 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_image.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_image.c
@@ -66,7 +66,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
float blend = tex->projection_blend;
if (!ima)
- return GPU_stack_link(mat, "node_tex_image_empty", in, out);
+ return GPU_stack_link(mat, node, "node_tex_image_empty", in, out);
if (!in[0].link)
in[0].link = GPU_attribute(CD_MTFACE, "");
@@ -75,7 +75,7 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
switch (tex->projection) {
case SHD_PROJ_FLAT:
- GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, node, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
break;
case SHD_PROJ_BOX:
GPU_link(mat, "direction_transform_m4v3", GPU_builtin(GPU_VIEW_NORMAL),
@@ -94,12 +94,12 @@ static int node_shader_gpu_tex_image(GPUMaterial *mat, bNode *node, bNodeExecDat
case SHD_PROJ_SPHERE:
GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link);
GPU_link(mat, "point_map_to_sphere", in[0].link, &in[0].link);
- GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, node, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
break;
case SHD_PROJ_TUBE:
GPU_link(mat, "point_texco_remap_square", in[0].link, &in[0].link);
GPU_link(mat, "point_map_to_tube", in[0].link, &in[0].link);
- GPU_stack_link(mat, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
+ GPU_stack_link(mat, node, "node_tex_image", in, out, GPU_image(ima, iuser, isdata));
break;
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c
index 8700d7954e7..7cd79067693 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_magic.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_magic.c
@@ -64,7 +64,7 @@ static int node_shader_gpu_tex_magic(GPUMaterial *mat, bNode *node, bNodeExecDat
node_shader_gpu_tex_mapping(mat, node, in, out);
- return GPU_stack_link(mat, "node_tex_magic", in, out, GPU_uniform(&depth));
+ return GPU_stack_link(mat, node, "node_tex_magic", in, out, GPU_uniform(&depth));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c
index 51d6699fadd..e36b2d5b95b 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_musgrave.c
@@ -68,7 +68,7 @@ static int node_shader_gpu_tex_musgrave(GPUMaterial *mat, bNode *node, bNodeExec
NodeTexMusgrave *tex = (NodeTexMusgrave *)node->storage;
float type = tex->musgrave_type;
- return GPU_stack_link(mat, "node_tex_musgrave", in, out, GPU_uniform(&type));
+ return GPU_stack_link(mat, node, "node_tex_musgrave", in, out, GPU_uniform(&type));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c
index 91015b3db25..38b208fc876 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_noise.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_noise.c
@@ -61,7 +61,7 @@ static int node_shader_gpu_tex_noise(GPUMaterial *mat, bNode *node, bNodeExecDat
node_shader_gpu_tex_mapping(mat, node, in, out);
- return GPU_stack_link(mat, "node_tex_noise", in, out);
+ return GPU_stack_link(mat, node, "node_tex_noise", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c b/source/blender/nodes/shader/nodes/node_shader_tex_sky.c
index 495c78ca929..7df6d34b756 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_sky.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_sky.c
@@ -61,7 +61,7 @@ static int node_shader_gpu_tex_sky(GPUMaterial *mat, bNode *node, bNodeExecData
node_shader_gpu_tex_mapping(mat, node, in, out);
- return GPU_stack_link(mat, "node_tex_sky", in, out);
+ return GPU_stack_link(mat, node, "node_tex_sky", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
index c994798e2da..30deb422e58 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_voronoi.c
@@ -63,7 +63,7 @@ static int node_shader_gpu_tex_voronoi(GPUMaterial *mat, bNode *node, bNodeExecD
NodeTexVoronoi *tex = (NodeTexVoronoi *)node->storage;
float coloring = tex->coloring;
- return GPU_stack_link(mat, "node_tex_voronoi", in, out, GPU_uniform(&coloring));
+ return GPU_stack_link(mat, node, "node_tex_voronoi", in, out, GPU_uniform(&coloring));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c
index 1194874e06c..356d2a78139 100644
--- a/source/blender/nodes/shader/nodes/node_shader_tex_wave.c
+++ b/source/blender/nodes/shader/nodes/node_shader_tex_wave.c
@@ -67,7 +67,7 @@ static int node_shader_gpu_tex_wave(GPUMaterial *mat, bNode *node, bNodeExecData
float wave_type = tex->wave_type;
float wave_profile = tex->wave_profile;
- return GPU_stack_link(mat, "node_tex_wave", in, out, GPU_uniform(&wave_type), GPU_uniform(&wave_profile));
+ return GPU_stack_link(mat, node, "node_tex_wave", in, out, GPU_uniform(&wave_type), GPU_uniform(&wave_profile));
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_texture.c b/source/blender/nodes/shader/nodes/node_shader_texture.c
deleted file mode 100644
index b0b25a4878b..00000000000
--- a/source/blender/nodes/shader/nodes/node_shader_texture.c
+++ /dev/null
@@ -1,166 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2005 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/nodes/shader/nodes/node_shader_texture.c
- * \ingroup shdnodes
- */
-
-#include "DNA_texture_types.h"
-
-#include "node_shader_util.h"
-
-#include "GPU_material.h"
-
-/* **************** TEXTURE ******************** */
-static bNodeSocketTemplate sh_node_texture_in[] = {
- { SOCK_VECTOR, 1, "Vector", 0.0f, 0.0f, 0.0f, 1.0f, -1.0f, 1.0f, PROP_NONE, SOCK_HIDE_VALUE}, /* no limit */
- { -1, 0, "" }
-};
-static bNodeSocketTemplate sh_node_texture_out[] = {
- { SOCK_FLOAT, 0, N_("Value"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_NO_INTERNAL_LINK},
- { SOCK_RGBA, 0, N_("Color"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_NO_INTERNAL_LINK},
- { SOCK_VECTOR, 0, N_("Normal"), 0, 0, 0, 0, 0, 0, PROP_NONE, SOCK_NO_INTERNAL_LINK},
- { -1, 0, "" }
-};
-
-static void node_shader_exec_texture(void *data, int UNUSED(thread), bNode *node, bNodeExecData *execdata, bNodeStack **in, bNodeStack **out)
-{
- if (data && node->id) {
- ShadeInput *shi = ((ShaderCallData *)data)->shi;
- TexResult texres;
- bNodeSocket *sock_vector = node->inputs.first;
- float vec[3], nor[3] = {0.0f, 0.0f, 0.0f};
- int retval;
- short which_output = node->custom1;
-
- short thread = shi->thread;
-
- /* out: value, color, normal */
-
- /* we should find out if a normal as output is needed, for now we do all */
- texres.nor = nor;
- texres.tr = texres.tg = texres.tb = 0.0f;
-
- /* don't use in[0]->hasinput, see material node for explanation */
- if (sock_vector->link) {
- nodestack_get_vec(vec, SOCK_VECTOR, in[0]);
-
- if (in[0]->datatype == NS_OSA_VECTORS) {
- float *fp = in[0]->data;
- retval = multitex_nodes((Tex *)node->id, vec, fp, fp + 3, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL);
- }
- else if (in[0]->datatype == NS_OSA_VALUES) {
- const float *fp = in[0]->data;
- float dxt[3], dyt[3];
-
- dxt[0] = fp[0]; dxt[1] = dxt[2] = 0.0f;
- dyt[0] = fp[1]; dyt[1] = dyt[2] = 0.0f;
- retval = multitex_nodes((Tex *)node->id, vec, dxt, dyt, shi->osatex, &texres, thread, which_output, NULL, NULL, NULL);
- }
- else
- retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL);
- }
- else {
- copy_v3_v3(vec, shi->lo);
- retval = multitex_nodes((Tex *)node->id, vec, NULL, NULL, 0, &texres, thread, which_output, NULL, NULL, NULL);
- }
-
- /* stupid exception */
- if ( ((Tex *)node->id)->type == TEX_STUCCI) {
- texres.tin = 0.5f + 0.7f * texres.nor[0];
- CLAMP(texres.tin, 0.0f, 1.0f);
- }
-
- /* intensity and color need some handling */
- if (texres.talpha)
- out[0]->vec[0] = texres.ta;
- else
- out[0]->vec[0] = texres.tin;
-
- if ((retval & TEX_RGB) == 0) {
- copy_v3_fl(out[1]->vec, out[0]->vec[0]);
- out[1]->vec[3] = 1.0f;
- }
- else {
- copy_v3_v3(out[1]->vec, &texres.tr);
- out[1]->vec[3] = 1.0f;
- }
-
- copy_v3_v3(out[2]->vec, nor);
-
- if (shi->do_preview) {
- BKE_node_preview_set_pixel(execdata->preview, out[1]->vec, shi->xs, shi->ys, shi->do_manage);
- }
-
- }
-}
-
-static int gpu_shader_texture(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
-{
- Tex *tex = (Tex *)node->id;
-
- if (tex && tex->ima && (tex->type == TEX_IMAGE || tex->type == TEX_ENVMAP)) {
- if (tex->type == TEX_IMAGE) {
- GPUNodeLink *texlink = GPU_image(tex->ima, &tex->iuser, false);
- GPU_stack_link(mat, "texture_image", in, out, texlink);
- }
- else { /* TEX_ENVMAP */
- if (!in[0].link)
- in[0].link = GPU_uniform(in[0].vec);
- if (!GPU_material_use_world_space_shading(mat))
- GPU_link(mat, "direction_transform_m4v3", in[0].link, GPU_builtin(GPU_INVERSE_VIEW_MATRIX), &in[0].link);
- GPU_link(mat, "mtex_cube_map_refl_from_refldir",
- GPU_cube_map(tex->ima, &tex->iuser, false), in[0].link, &out[0].link, &out[1].link);
- GPU_link(mat, "color_to_normal", out[1].link, &out[2].link);
- }
-
- ImBuf *ibuf = BKE_image_acquire_ibuf(tex->ima, &tex->iuser, NULL);
- if (ibuf && (ibuf->colormanage_flag & IMB_COLORMANAGE_IS_DATA) == 0 &&
- GPU_material_do_color_management(mat))
- {
- GPU_link(mat, "srgb_to_linearrgb", out[1].link, &out[1].link);
- }
- BKE_image_release_ibuf(tex->ima, ibuf, NULL);
-
- return true;
- }
-
- return false;
-}
-
-void register_node_type_sh_texture(void)
-{
- static bNodeType ntype;
-
- sh_node_type_base(&ntype, SH_NODE_TEXTURE, "Texture", NODE_CLASS_INPUT, NODE_PREVIEW);
- node_type_compatibility(&ntype, NODE_OLD_SHADING);
- node_type_socket_templates(&ntype, sh_node_texture_in, sh_node_texture_out);
- node_type_exec(&ntype, NULL, NULL, node_shader_exec_texture);
- node_type_gpu(&ntype, gpu_shader_texture);
-
- nodeRegisterType(&ntype);
-}
diff --git a/source/blender/nodes/shader/nodes/node_shader_uvmap.c b/source/blender/nodes/shader/nodes/node_shader_uvmap.c
index 0f96cb45fe0..c47bb9022b6 100644
--- a/source/blender/nodes/shader/nodes/node_shader_uvmap.c
+++ b/source/blender/nodes/shader/nodes/node_shader_uvmap.c
@@ -47,7 +47,7 @@ static int node_shader_gpu_uvmap(GPUMaterial *mat, bNode *node, bNodeExecData *U
NodeShaderUVMap *attr = node->storage;
GPUNodeLink *mtface = GPU_attribute(CD_MTFACE, attr->uv_map);
- return GPU_stack_link(mat, "node_uvmap", in, out, mtface);
+ return GPU_stack_link(mat, node, "node_uvmap", in, out, mtface);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c
index c960e006a9b..39598eb8675 100644
--- a/source/blender/nodes/shader/nodes/node_shader_valToRgb.c
+++ b/source/blender/nodes/shader/nodes/node_shader_valToRgb.c
@@ -69,7 +69,7 @@ static int gpu_shader_valtorgb(GPUMaterial *mat, bNode *node, bNodeExecData *UNU
int size;
BKE_colorband_evaluate_table_rgba(node->storage, &array, &size);
- return GPU_stack_link(mat, "valtorgb", in, out, GPU_texture(size, array));
+ return GPU_stack_link(mat, node, "valtorgb", in, out, GPU_texture(size, array));
}
void register_node_type_sh_valtorgb(void)
@@ -110,9 +110,9 @@ static void node_shader_exec_rgbtobw(void *UNUSED(data), int UNUSED(thread), bNo
out[0]->vec[0] = IMB_colormanagement_get_luminance(col);
}
-static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_rgbtobw(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return GPU_stack_link(mat, "rgbtobw", in, out);
+ return GPU_stack_link(mat, node, "rgbtobw", in, out);
}
void register_node_type_sh_rgbtobw(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_value.c b/source/blender/nodes/shader/nodes/node_shader_value.c
index 3a9582a6a7c..1e5bd8c5bff 100644
--- a/source/blender/nodes/shader/nodes/node_shader_value.c
+++ b/source/blender/nodes/shader/nodes/node_shader_value.c
@@ -38,10 +38,10 @@ static bNodeSocketTemplate sh_node_value_out[] = {
{ -1, 0, "" }
};
-static int gpu_shader_value(GPUMaterial *mat, bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+static int gpu_shader_value(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- GPUNodeLink *vec = GPU_uniform(out[0].vec);
- return GPU_stack_link(mat, "set_value", in, out, vec);
+ GPUNodeLink *link = GPU_uniformbuffer_link_out(mat, node, out, 0);
+ return GPU_stack_link(mat, node, "set_value", in, out, link);
}
void register_node_type_sh_value(void)
diff --git a/source/blender/nodes/shader/nodes/node_shader_vectMath.c b/source/blender/nodes/shader/nodes/node_shader_vectMath.c
index 26045dfca04..f117adde98c 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vectMath.c
+++ b/source/blender/nodes/shader/nodes/node_shader_vectMath.c
@@ -111,7 +111,7 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN
case 2:
case 3:
case 4:
- GPU_stack_link(mat, names[node->custom1], in, out);
+ GPU_stack_link(mat, node, names[node->custom1], in, out);
break;
case 5:
if (in[0].hasinput || !in[1].hasinput) {
@@ -119,14 +119,14 @@ static int gpu_shader_vect_math(GPUMaterial *mat, bNode *node, bNodeExecData *UN
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[0], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
- GPU_stack_link(mat, names[node->custom1], tmp_in, out);
+ GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
else {
/* use only second item and terminator */
GPUNodeStack tmp_in[2];
memcpy(&tmp_in[0], &in[1], sizeof(GPUNodeStack));
memcpy(&tmp_in[1], &in[2], sizeof(GPUNodeStack));
- GPU_stack_link(mat, names[node->custom1], tmp_in, out);
+ GPU_stack_link(mat, node, names[node->custom1], tmp_in, out);
}
break;
default:
diff --git a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c
index 74e23aed7de..71bb88f892f 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vectTransform.c
+++ b/source/blender/nodes/shader/nodes/node_shader_vectTransform.c
@@ -52,68 +52,8 @@ static void node_shader_init_vect_transform(bNodeTree *UNUSED(ntree), bNode *nod
node->storage = vect;
}
-static const float (* get_matrix_from_to(ShaderCallData *scd, short from, short to))[4]
+static void node_shader_exec_vect_transform(void *UNUSED(data), int UNUSED(thread), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), bNodeStack **UNUSED(in), bNodeStack **UNUSED(out))
{
- switch (from) {
- case SHD_VECT_TRANSFORM_SPACE_OBJECT:
- switch (to) {
- case SHD_VECT_TRANSFORM_SPACE_OBJECT:
- return NULL;
- case SHD_VECT_TRANSFORM_SPACE_WORLD:
- return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OB);
- case SHD_VECT_TRANSFORM_SPACE_CAMERA:
- return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW);
- }
- break;
- case SHD_VECT_TRANSFORM_SPACE_WORLD:
- switch (to) {
- case SHD_VECT_TRANSFORM_SPACE_WORLD:
- return NULL;
- case SHD_VECT_TRANSFORM_SPACE_CAMERA:
- return RE_render_current_get_matrix(RE_VIEW_MATRIX);
- case SHD_VECT_TRANSFORM_SPACE_OBJECT:
- return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_OBINV);
- }
- break;
- case SHD_VECT_TRANSFORM_SPACE_CAMERA:
- switch (to) {
- case SHD_VECT_TRANSFORM_SPACE_CAMERA:
- return NULL;
- case SHD_VECT_TRANSFORM_SPACE_WORLD:
- return RE_render_current_get_matrix(RE_VIEWINV_MATRIX);
- case SHD_VECT_TRANSFORM_SPACE_OBJECT:
- return RE_object_instance_get_matrix(scd->shi->obi, RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEWINV);
- }
- break;
- }
- return NULL;
-}
-
-static void node_shader_exec_vect_transform(void *data, int UNUSED(thread), bNode *node, bNodeExecData *UNUSED(execdata), bNodeStack **in, bNodeStack **out)
-{
- float vec[4];
- const float (*mat)[4];
-
- if (data) {
- NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage;
-
- nodestack_get_vec(vec, SOCK_VECTOR, in[0]);
-
- if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT)
- vec[3] = 1.0f;
- else
- vec[3] = 0.0f;
-
- mat = get_matrix_from_to((ShaderCallData *)data, nodeprop->convert_from, nodeprop->convert_to);
- if (mat) {
- mul_m4_v4((float(*)[4])mat, vec);
- }
-
- if (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_NORMAL)
- normalize_v3(vec);
-
- copy_v4_v4(out[0]->vec, vec);
- }
}
static GPUNodeLink *get_gpulink_matrix_from_to(short from, short to)
@@ -161,8 +101,6 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
const char *ptransform = "point_transform_m4v3";
const char *func_name = 0;
- bool new_shading = GPU_material_use_new_shading_nodes(mat);
-
NodeShaderVectTransform *nodeprop = (NodeShaderVectTransform *)node->storage;
if (in[0].hasinput)
@@ -174,19 +112,14 @@ static int gpu_shader_vect_transform(GPUMaterial *mat, bNode *node, bNodeExecDat
func_name = (nodeprop->type == SHD_VECT_TRANSFORM_TYPE_POINT) ? ptransform : vtransform;
if (fromto) {
- if (new_shading) {
- /* For cycles we have inverted Z */
- /* TODO: pass here the correct matrices */
- if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
- GPU_link(mat, "invert_z", inputlink, &inputlink);
- }
- GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
- if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
- GPU_link(mat, "invert_z", out[0].link, &out[0].link);
- }
+ /* For cycles we have inverted Z */
+ /* TODO: pass here the correct matrices */
+ if (nodeprop->convert_from == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_to != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
+ GPU_link(mat, "invert_z", inputlink, &inputlink);
}
- else {
- GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
+ GPU_link(mat, func_name, inputlink, fromto, &out[0].link);
+ if (nodeprop->convert_to == SHD_VECT_TRANSFORM_SPACE_CAMERA && nodeprop->convert_from != SHD_VECT_TRANSFORM_SPACE_CAMERA) {
+ GPU_link(mat, "invert_z", out[0].link, &out[0].link);
}
}
else
diff --git a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c
index 073bc3110f6..79b41509fcc 100644
--- a/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c
+++ b/source/blender/nodes/shader/nodes/node_shader_vector_displacement.c
@@ -50,6 +50,7 @@ static int gpu_shader_vector_displacement(GPUMaterial *mat, bNode *node, bNodeEx
{
if (node->custom1 == SHD_SPACE_TANGENT) {
return GPU_stack_link(mat,
+ node,
"node_vector_displacement_tangent",
in,
out,
@@ -59,10 +60,10 @@ static int gpu_shader_vector_displacement(GPUMaterial *mat, bNode *node, bNodeEx
GPU_builtin(GPU_VIEW_MATRIX));
}
else if (node->custom1 == SHD_SPACE_OBJECT) {
- return GPU_stack_link(mat, "node_vector_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
+ return GPU_stack_link(mat, node, "node_vector_displacement_object", in, out, GPU_builtin(GPU_OBJECT_MATRIX));
}
else {
- return GPU_stack_link(mat, "node_vector_displacement_world", in, out);
+ return GPU_stack_link(mat, node, "node_vector_displacement_world", in, out);
}
}
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c
index 4861871e8d3..518ab6587b2 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_absorption.c
@@ -40,9 +40,9 @@ static bNodeSocketTemplate sh_node_volume_absorption_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_volume_absorption(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
+static int node_shader_gpu_volume_absorption(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return false;
+ return GPU_stack_link(mat, node, "node_volume_absorption", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c
index e85fec1ec9d..4fbd9af1b58 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_principled.c
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_principled.c
@@ -62,9 +62,89 @@ static void node_shader_init_volume_principled(bNodeTree *UNUSED(ntree), bNode *
}
}
-static int node_shader_gpu_volume_principled(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
+static void node_shader_gpu_volume_attribute(GPUMaterial *mat, const char *name, GPUNodeLink **outcol, GPUNodeLink **outvec, GPUNodeLink **outf)
{
- return false;
+ if (strcmp(name, "density") == 0) {
+ GPU_link(mat, "node_attribute_volume_density",
+ GPU_builtin(GPU_VOLUME_DENSITY),
+ outcol, outvec, outf);
+ }
+ else if (strcmp(name, "color") == 0) {
+ GPU_link(mat, "node_attribute_volume_color",
+ GPU_builtin(GPU_VOLUME_DENSITY),
+ outcol, outvec, outf);
+ }
+ else if (strcmp(name, "flame") == 0) {
+ GPU_link(mat, "node_attribute_volume_flame",
+ GPU_builtin(GPU_VOLUME_FLAME),
+ outcol, outvec, outf);
+ }
+ else if (strcmp(name, "temperature") == 0) {
+ GPU_link(mat, "node_attribute_volume_temperature",
+ GPU_builtin(GPU_VOLUME_FLAME),
+ GPU_builtin(GPU_VOLUME_TEMPERATURE),
+ outcol, outvec, outf);
+ }
+ else {
+ *outcol = *outvec = *outf = NULL;
+ }
+}
+
+static int node_shader_gpu_volume_principled(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
+{
+ /* Test if blackbody intensity is enabled. */
+ bool use_blackbody = (in[8].link || in[8].vec[0] != 0.0f);
+
+ /* Get volume attributes. */
+ GPUNodeLink *density = NULL, *color = NULL, *temperature = NULL;
+
+ for (bNodeSocket *sock = node->inputs.first; sock; sock = sock->next) {
+ if (sock->typeinfo->type != SOCK_STRING) {
+ continue;
+ }
+
+ bNodeSocketValueString *value = sock->default_value;
+ GPUNodeLink *outcol, *outvec, *outf;
+
+ if (STREQ(sock->name, "Density Attribute")) {
+ node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &density);
+ }
+ else if (STREQ(sock->name, "Color Attribute")) {
+ node_shader_gpu_volume_attribute(mat, value->value, &color, &outvec, &outf);
+ }
+ else if (use_blackbody && STREQ(sock->name, "Temperature Attribute")) {
+ node_shader_gpu_volume_attribute(mat, value->value, &outcol, &outvec, &temperature);
+ }
+ }
+
+ /* Default values if attributes not found. */
+ if (!density) {
+ static float one = 1.0f;
+ density = GPU_uniform(&one);
+ }
+ if (!color) {
+ static float white[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ color = GPU_uniform(white);
+ }
+ if (!temperature) {
+ static float one = 1.0f;
+ temperature = GPU_uniform(&one);
+ }
+
+ /* Create blackbody spectrum. */
+ GPUNodeLink *spectrummap;
+ if (use_blackbody) {
+ const int size = 256;
+ float *data = MEM_mallocN(sizeof(float) * size * 4, "blackbody texture");
+ blackbody_temperature_to_rgb_table(data, size, 965.0f, 12000.0f);
+ spectrummap = GPU_texture(size, data);
+ }
+ else {
+ float *data = MEM_callocN(sizeof(float) * 4, "blackbody black");
+ spectrummap = GPU_texture(1, data);
+ }
+
+ return GPU_stack_link(mat, node, "node_volume_principled", in, out, density, color, temperature, spectrummap);
}
/* node type definition */
diff --git a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c
index ed56df257b7..dfd7154e6b8 100644
--- a/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c
+++ b/source/blender/nodes/shader/nodes/node_shader_volume_scatter.c
@@ -41,9 +41,9 @@ static bNodeSocketTemplate sh_node_volume_scatter_out[] = {
{ -1, 0, "" }
};
-static int node_shader_gpu_volume_scatter(GPUMaterial *UNUSED(mat), bNode *UNUSED(node), bNodeExecData *UNUSED(execdata), GPUNodeStack *UNUSED(in), GPUNodeStack *UNUSED(out))
+static int node_shader_gpu_volume_scatter(GPUMaterial *mat, bNode *node, bNodeExecData *UNUSED(execdata), GPUNodeStack *in, GPUNodeStack *out)
{
- return false;
+ return GPU_stack_link(mat, node, "node_volume_scatter", in, out);
}
/* node type definition */
diff --git a/source/blender/nodes/texture/node_texture_tree.c b/source/blender/nodes/texture/node_texture_tree.c
index bc48802a7ca..cd7a3f6d9c2 100644
--- a/source/blender/nodes/texture/node_texture_tree.c
+++ b/source/blender/nodes/texture/node_texture_tree.c
@@ -53,44 +53,22 @@
#include "NOD_texture.h"
#include "node_texture_util.h"
+#include "DEG_depsgraph.h"
+
#include "RNA_access.h"
#include "RE_shader_ext.h"
-
-static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from)
+static void texture_get_from_context(
+ const bContext *C, bNodeTreeType *UNUSED(treetype), bNodeTree **r_ntree, ID **r_id, ID **r_from)
{
SpaceNode *snode = CTX_wm_space_node(C);
Scene *scene = CTX_data_scene(C);
- Object *ob = OBACT;
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ Object *ob = OBACT(view_layer);
Tex *tx = NULL;
- if (snode->texfrom == SNODE_TEX_OBJECT) {
- if (ob) {
- tx = give_current_object_texture(ob);
- if (tx) {
- if (ob->type == OB_LAMP)
- *r_from = (ID *)ob->data;
- else
- *r_from = (ID *)give_current_material(ob, ob->actcol);
-
- /* from is not set fully for material nodes, should be ID + Node then */
- *r_id = &tx->id;
- *r_ntree = tx->nodetree;
- }
- }
- }
- else if (snode->texfrom == SNODE_TEX_WORLD) {
- if (scene->world) {
- *r_from = (ID *)scene->world;
- tx = give_current_world_texture(scene->world);
- if (tx) {
- *r_id = &tx->id;
- *r_ntree = tx->nodetree;
- }
- }
- }
- else if (snode->texfrom == SNODE_TEX_BRUSH) {
+ if (snode->texfrom == SNODE_TEX_BRUSH) {
struct Brush *brush = NULL;
if (ob && (ob->mode & OB_MODE_SCULPT))
@@ -108,7 +86,7 @@ static void texture_get_from_context(const bContext *C, bNodeTreeType *UNUSED(tr
}
}
else if (snode->texfrom == SNODE_TEX_LINESTYLE) {
- FreestyleLineStyle *linestyle = BKE_linestyle_active_from_scene(scene);
+ FreestyleLineStyle *linestyle = BKE_linestyle_active_from_view_layer(view_layer);
if (linestyle) {
*r_from = (ID *)linestyle;
tx = give_current_linestyle_texture(linestyle);
@@ -321,7 +299,6 @@ int ntreeTexExecTree(
short which_output,
int cfra,
int preview,
- ShadeInput *shi,
MTex *mtex)
{
TexCallData data;
@@ -336,12 +313,11 @@ int ntreeTexExecTree(
data.osatex = osatex;
data.target = texres;
data.do_preview = preview;
- data.do_manage = (shi) ? shi->do_manage : true;
+ data.do_manage = true;
data.thread = thread;
data.which_output = which_output;
data.cfra = cfra;
data.mtex = mtex;
- data.shi = shi;
/* ensure execdata is only initialized once */
if (!exec) {
diff --git a/source/blender/nodes/texture/node_texture_util.c b/source/blender/nodes/texture/node_texture_util.c
index 32720364f73..8cb61478c41 100644
--- a/source/blender/nodes/texture/node_texture_util.c
+++ b/source/blender/nodes/texture/node_texture_util.c
@@ -124,7 +124,6 @@ void params_from_cdata(TexParams *out, TexCallData *in)
out->previewco = in->co;
out->osatex = in->osatex;
out->cfra = in->cfra;
- out->shi = in->shi;
out->mtex = in->mtex;
}
diff --git a/source/blender/nodes/texture/node_texture_util.h b/source/blender/nodes/texture/node_texture_util.h
index f6af5b1b6ca..82ba573425a 100644
--- a/source/blender/nodes/texture/node_texture_util.h
+++ b/source/blender/nodes/texture/node_texture_util.h
@@ -87,7 +87,6 @@ typedef struct TexCallData {
short which_output;
int cfra;
- ShadeInput *shi;
MTex *mtex;
} TexCallData;
@@ -100,7 +99,6 @@ typedef struct TexParams {
/* optional. we don't really want these here, but image
* textures need to do mapping & color correction */
- ShadeInput *shi;
MTex *mtex;
} TexParams;
diff --git a/source/blender/nodes/texture/nodes/node_texture_proc.c b/source/blender/nodes/texture/nodes/node_texture_proc.c
index 0be5f875a23..c16d723e1e1 100644
--- a/source/blender/nodes/texture/nodes/node_texture_proc.c
+++ b/source/blender/nodes/texture/nodes/node_texture_proc.c
@@ -69,7 +69,7 @@ static void do_proc(float *result, TexParams *p, const float col1[4], const floa
texres.nor = NULL;
textype = multitex_nodes(tex, p->co, p->dxt, p->dyt, p->osatex,
- &texres, thread, 0, p->shi, p->mtex, NULL);
+ &texres, thread, 0, p->mtex, NULL);
if (is_normal)
return;
diff --git a/source/blender/nodes/texture/nodes/node_texture_texture.c b/source/blender/nodes/texture/nodes/node_texture_texture.c
index 1fd0a55dc63..7e035d522f7 100644
--- a/source/blender/nodes/texture/nodes/node_texture_texture.c
+++ b/source/blender/nodes/texture/nodes/node_texture_texture.c
@@ -78,7 +78,7 @@ static void colorfn(float *out, TexParams *p, bNode *node, bNodeStack **in, shor
texres.nor = nor;
textype = multitex_nodes(nodetex, co, dxt, dyt, p->osatex,
- &texres, thread, 0, p->shi, p->mtex, NULL);
+ &texres, thread, 0, p->mtex, NULL);
if (textype & TEX_RGB) {
copy_v4_v4(out, &texres.tr);
diff --git a/source/blender/physics/BPH_mass_spring.h b/source/blender/physics/BPH_mass_spring.h
index c650d83c927..e89aec1456e 100644
--- a/source/blender/physics/BPH_mass_spring.h
+++ b/source/blender/physics/BPH_mass_spring.h
@@ -58,8 +58,6 @@ void BPH_cloth_solver_free(struct ClothModifierData *clmd);
int BPH_cloth_solve(struct Object *ob, float frame, struct ClothModifierData *clmd, struct ListBase *effectors);
void BKE_cloth_solver_set_positions(struct ClothModifierData *clmd);
-bool BPH_cloth_solver_get_texture_data(struct Object *ob, struct ClothModifierData *clmd, struct VoxelData *vd);
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/physics/intern/BPH_mass_spring.cpp b/source/blender/physics/intern/BPH_mass_spring.cpp
index 5b5639495da..e5724c97bbc 100644
--- a/source/blender/physics/intern/BPH_mass_spring.cpp
+++ b/source/blender/physics/intern/BPH_mass_spring.cpp
@@ -1091,24 +1091,3 @@ int BPH_cloth_solve(Object *ob, float frame, ClothModifierData *clmd, ListBase *
return 1;
}
-
-bool BPH_cloth_solver_get_texture_data(Object *UNUSED(ob), ClothModifierData *clmd, VoxelData *vd)
-{
- Cloth *cloth = clmd->clothObject;
- HairGrid *grid;
- float gmin[3], gmax[3];
-
- if (!clmd->clothObject || !clmd->clothObject->implicit)
- return false;
-
- hair_get_boundbox(clmd, gmin, gmax);
-
- grid = BPH_hair_volume_create_vertex_grid(clmd->sim_parms->voxel_cell_size, gmin, gmax);
- cloth_continuum_fill_grid(grid, cloth);
-
- BPH_hair_volume_get_texture_data(grid, vd);
-
- BPH_hair_volume_free_vertex_grid(grid);
-
- return true;
-}
diff --git a/source/blender/physics/intern/hair_volume.cpp b/source/blender/physics/intern/hair_volume.cpp
index 5cc1231e6cb..05d30657af8 100644
--- a/source/blender/physics/intern/hair_volume.cpp
+++ b/source/blender/physics/intern/hair_volume.cpp
@@ -1099,56 +1099,3 @@ static HairGridVert *hair_volume_create_collision_grid(ClothModifierData *clmd,
return collgrid;
}
#endif
-
-bool BPH_hair_volume_get_texture_data(HairGrid *grid, VoxelData *vd)
-{
- int totres, i;
- int depth;
-
- vd->resol[0] = grid->res[0];
- vd->resol[1] = grid->res[1];
- vd->resol[2] = grid->res[2];
-
- totres = hair_grid_size(grid->res);
-
- if (vd->hair_type == TEX_VD_HAIRVELOCITY) {
- depth = 4;
- vd->data_type = TEX_VD_RGBA_PREMUL;
- }
- else {
- depth = 1;
- vd->data_type = TEX_VD_INTENSITY;
- }
-
- if (totres > 0) {
- vd->dataset = (float *)MEM_mapallocN(sizeof(float) * depth * (totres), "hair volume texture data");
-
- for (i = 0; i < totres; ++i) {
- switch (vd->hair_type) {
- case TEX_VD_HAIRDENSITY:
- vd->dataset[i] = grid->verts[i].density;
- break;
-
- case TEX_VD_HAIRRESTDENSITY:
- vd->dataset[i] = 0.0f; // TODO
- break;
-
- case TEX_VD_HAIRVELOCITY: {
- vd->dataset[i + 0*totres] = grid->verts[i].velocity[0];
- vd->dataset[i + 1*totres] = grid->verts[i].velocity[1];
- vd->dataset[i + 2*totres] = grid->verts[i].velocity[2];
- vd->dataset[i + 3*totres] = len_v3(grid->verts[i].velocity);
- break;
- }
- case TEX_VD_HAIRENERGY:
- vd->dataset[i] = 0.0f; // TODO
- break;
- }
- }
- }
- else {
- vd->dataset = NULL;
- }
-
- return true;
-}
diff --git a/source/blender/physics/intern/implicit.h b/source/blender/physics/intern/implicit.h
index 2f62ab98e12..d6bf5c6b7bf 100644
--- a/source/blender/physics/intern/implicit.h
+++ b/source/blender/physics/intern/implicit.h
@@ -171,8 +171,6 @@ void BPH_hair_volume_vertex_grid_forces(struct HairGrid *grid, const float x[3],
float smoothfac, float pressurefac, float minpressure,
float f[3], float dfdx[3][3], float dfdv[3][3]);
-bool BPH_hair_volume_get_texture_data(struct HairGrid *grid, struct VoxelData *vd);
-
#ifdef __cplusplus
}
#endif
diff --git a/source/blender/python/CMakeLists.txt b/source/blender/python/CMakeLists.txt
index e855f3a3756..8d26fee0abd 100644
--- a/source/blender/python/CMakeLists.txt
+++ b/source/blender/python/CMakeLists.txt
@@ -17,6 +17,7 @@
# ***** END GPL LICENSE BLOCK *****
add_subdirectory(intern)
+add_subdirectory(gawain)
add_subdirectory(generic)
add_subdirectory(mathutils)
add_subdirectory(bmesh)
diff --git a/source/blender/python/bmesh/CMakeLists.txt b/source/blender/python/bmesh/CMakeLists.txt
index c7b86acc8f9..4d3230fa3e9 100644
--- a/source/blender/python/bmesh/CMakeLists.txt
+++ b/source/blender/python/bmesh/CMakeLists.txt
@@ -23,6 +23,7 @@ set(INC
../../bmesh
../../blenkernel
../../blenlib
+ ../../depsgraph
../../makesdna
../../../../intern/guardedalloc
)
diff --git a/source/blender/python/bmesh/bmesh_py_api.c b/source/blender/python/bmesh/bmesh_py_api.c
index d5973baeadb..d6189f7c1eb 100644
--- a/source/blender/python/bmesh/bmesh_py_api.c
+++ b/source/blender/python/bmesh/bmesh_py_api.c
@@ -156,11 +156,6 @@ static PyObject *bpy_bm_update_edit_mesh(PyObject *UNUSED(self), PyObject *args,
{
extern void EDBM_update_generic(BMEditMesh *em, const bool do_tessface, const bool is_destructive);
- BMEditMesh *em = me->edit_btmesh;
- BMesh *bm = em->bm;
-
- /* python won't ensure matching uv/mtex */
- BM_mesh_cd_validate(bm);
EDBM_update_generic(me->edit_btmesh, do_tessface, is_destructive);
}
diff --git a/source/blender/python/bmesh/bmesh_py_types.c b/source/blender/python/bmesh/bmesh_py_types.c
index 2866683b89b..a6ed92d139c 100644
--- a/source/blender/python/bmesh/bmesh_py_types.c
+++ b/source/blender/python/bmesh/bmesh_py_types.c
@@ -34,10 +34,11 @@
#include "DNA_object_types.h"
#include "DNA_material_types.h"
-#include "BKE_depsgraph.h"
#include "BKE_customdata.h"
#include "BKE_DerivedMesh.h"
+#include "DEG_depsgraph.h"
+
#include "bmesh.h"
#include <Python.h>
@@ -901,9 +902,6 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
bm = self->bm;
- /* python won't ensure matching uv/mtex */
- BM_mesh_cd_validate(bm);
-
BM_mesh_bm_to_me(
bm, me,
(&(struct BMeshToMeshParams){
@@ -912,7 +910,7 @@ static PyObject *bpy_bmesh_to_mesh(BPy_BMesh *self, PyObject *args)
/* we could have the user do this but if they forget blender can easy crash
* since the references arrays for the objects derived meshes are now invalid */
- DAG_id_tag_update(&me->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&me->id, OB_RECALC_DATA);
Py_RETURN_NONE;
}
@@ -935,6 +933,8 @@ PyDoc_STRVAR(bpy_bmesh_from_object_doc,
);
static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject *kw)
{
+ /* TODO: This doesn't work currently because of missing depsgraph. */
+#if 0
static const char *kwlist[] = {"object", "scene", "deform", "render", "cage", "face_normals", NULL};
PyObject *py_object;
PyObject *py_scene;
@@ -1027,6 +1027,10 @@ static PyObject *bpy_bmesh_from_object(BPy_BMesh *self, PyObject *args, PyObject
dm->release(dm);
Py_RETURN_NONE;
+#else
+ UNUSED_VARS(self, args, kw);
+#endif
+ return NULL;
}
diff --git a/source/blender/python/bmesh/bmesh_py_types_customdata.c b/source/blender/python/bmesh/bmesh_py_types_customdata.c
index cb95ded4f0d..e2241ade7f0 100644
--- a/source/blender/python/bmesh/bmesh_py_types_customdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_customdata.c
@@ -105,9 +105,6 @@ PyDoc_STRVAR(bpy_bmlayeraccess_collection__bevel_weight_doc,
PyDoc_STRVAR(bpy_bmlayeraccess_collection__crease_doc,
"Edge crease for subsurf - float in [0 - 1].\n\n:type: :class:`BMLayerCollection`"
);
-PyDoc_STRVAR(bpy_bmlayeraccess_collection__tex_doc,
-"Accessor for :class:`BMTexPoly` layer (TODO).\n\ntype: :class:`BMLayerCollection`" // TYPE DOESN'T EXIST YET
-);
PyDoc_STRVAR(bpy_bmlayeraccess_collection__uv_doc,
"Accessor for :class:`BMLoopUV` UV (as a 2D Vector).\n\ntype: :class:`BMLayerCollection`"
);
@@ -120,6 +117,9 @@ PyDoc_STRVAR(bpy_bmlayeraccess_collection__skin_doc,
PyDoc_STRVAR(bpy_bmlayeraccess_collection__paint_mask_doc,
"Accessor for paint mask layer.\n\ntype: :class:`BMLayerCollection`"
);
+PyDoc_STRVAR(bpy_bmlayeraccess_collection__face_map_doc,
+"FaceMap custom-data layer.\n\ntype: :class:`BMLayerCollection`"
+);
#ifdef WITH_FREESTYLE
PyDoc_STRVAR(bpy_bmlayeraccess_collection__freestyle_edge_doc,
"Accessor for Freestyle edge layer.\n\ntype: :class:`BMLayerCollection`"
@@ -222,8 +222,7 @@ static PyGetSetDef bpy_bmlayeraccess_face_getseters[] = {
{(char *)"float", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__float_doc, (void *)CD_PROP_FLT},
{(char *)"int", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__int_doc, (void *)CD_PROP_INT},
{(char *)"string", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__string_doc, (void *)CD_PROP_STR},
-
- {(char *)"tex", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__tex_doc, (void *)CD_MTEXPOLY},
+ {(char *)"face_map", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__face_map_doc, (void *)CD_FACEMAP},
#ifdef WITH_FREESTYLE
{(char *)"freestyle", (getter)bpy_bmlayeraccess_collection_get, (setter)NULL, (char *)bpy_bmlayeraccess_collection__freestyle_face_doc, (void *)CD_FREESTYLE_FACE},
@@ -989,6 +988,7 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
break;
}
case CD_PROP_INT:
+ case CD_FACEMAP:
{
ret = PyLong_FromLong(*(int *)value);
break;
@@ -999,11 +999,6 @@ PyObject *BPy_BMLayerItem_GetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer)
ret = PyBytes_FromStringAndSize(mstring->s, mstring->s_len);
break;
}
- case CD_MTEXPOLY:
- {
- ret = BPy_BMTexPoly_CreatePyObject(value);
- break;
- }
case CD_MLOOPUV:
{
ret = BPy_BMLoopUV_CreatePyObject(value);
@@ -1074,6 +1069,7 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
break;
}
case CD_PROP_INT:
+ case CD_FACEMAP:
{
int tmp_val = PyC_Long_AsI32(py_value);
if (UNLIKELY(tmp_val == -1 && PyErr_Occurred())) {
@@ -1102,11 +1098,6 @@ int BPy_BMLayerItem_SetItem(BPy_BMElem *py_ele, BPy_BMLayerItem *py_layer, PyObj
}
break;
}
- case CD_MTEXPOLY:
- {
- ret = BPy_BMTexPoly_AssignPyObject(value, py_value);
- break;
- }
case CD_MLOOPUV:
{
ret = BPy_BMLoopUV_AssignPyObject(value, py_value);
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.c b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
index 7984f625d96..54b33e7b6b6 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.c
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.c
@@ -48,96 +48,6 @@
#include "../generic/py_capi_utils.h"
#include "../generic/python_utildefines.h"
-
-/* Mesh BMTexPoly
- * ************** */
-
-#define BPy_BMTexPoly_Check(v) (Py_TYPE(v) == &BPy_BMTexPoly_Type)
-
-typedef struct BPy_BMTexPoly {
- PyObject_VAR_HEAD
- MTexPoly *data;
-} BPy_BMTexPoly;
-
-extern PyObject *pyrna_id_CreatePyObject(ID *id);
-extern bool pyrna_id_FromPyObject(PyObject *obj, ID **id);
-
-PyDoc_STRVAR(bpy_bmtexpoly_image_doc,
-"Image or None.\n\n:type: :class:`bpy.types.Image`"
-);
-static PyObject *bpy_bmtexpoly_image_get(BPy_BMTexPoly *self, void *UNUSED(closure))
-{
- return pyrna_id_CreatePyObject((ID *)self->data->tpage);
-}
-
-static int bpy_bmtexpoly_image_set(BPy_BMTexPoly *self, PyObject *value, void *UNUSED(closure))
-{
- ID *id;
-
- if (value == Py_None) {
- id = NULL;
- }
- else if (pyrna_id_FromPyObject(value, &id) && id && GS(id->name) == ID_IM) {
- /* pass */
- }
- else {
- PyErr_Format(PyExc_KeyError, "BMTexPoly.image = x"
- "expected an image or None, not '%.200s'",
- Py_TYPE(value)->tp_name);
- return -1;
- }
-
- id_lib_extern(id);
- self->data->tpage = (struct Image *)id;
-
- return 0;
-}
-
-static PyGetSetDef bpy_bmtexpoly_getseters[] = {
- /* attributes match rna_def_mtpoly */
- {(char *)"image", (getter)bpy_bmtexpoly_image_get, (setter)bpy_bmtexpoly_image_set, (char *)bpy_bmtexpoly_image_doc, NULL},
-
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
-};
-
-static PyTypeObject BPy_BMTexPoly_Type; /* bm.loops.layers.uv.active */
-
-static void bm_init_types_bmtexpoly(void)
-{
- BPy_BMTexPoly_Type.tp_basicsize = sizeof(BPy_BMTexPoly);
-
- BPy_BMTexPoly_Type.tp_name = "BMTexPoly";
-
- BPy_BMTexPoly_Type.tp_doc = NULL; // todo
-
- BPy_BMTexPoly_Type.tp_getset = bpy_bmtexpoly_getseters;
-
- BPy_BMTexPoly_Type.tp_flags = Py_TPFLAGS_DEFAULT;
-
- PyType_Ready(&BPy_BMTexPoly_Type);
-}
-
-int BPy_BMTexPoly_AssignPyObject(struct MTexPoly *mtpoly, PyObject *value)
-{
- if (UNLIKELY(!BPy_BMTexPoly_Check(value))) {
- PyErr_Format(PyExc_TypeError, "expected BMTexPoly, not a %.200s", Py_TYPE(value)->tp_name);
- return -1;
- }
- else {
- *((MTexPoly *)mtpoly) = *(((BPy_BMTexPoly *)value)->data);
- return 0;
- }
-}
-
-PyObject *BPy_BMTexPoly_CreatePyObject(struct MTexPoly *mtpoly)
-{
- BPy_BMTexPoly *self = PyObject_New(BPy_BMTexPoly, &BPy_BMTexPoly_Type);
- self->data = mtpoly;
- return (PyObject *)self;
-}
-
-/* --- End Mesh BMTexPoly --- */
-
/* Mesh Loop UV
* ************ */
@@ -797,7 +707,6 @@ PyObject *BPy_BMDeformVert_CreatePyObject(struct MDeformVert *dvert)
/* call to init all types */
void BPy_BM_init_types_meshdata(void)
{
- bm_init_types_bmtexpoly();
bm_init_types_bmloopuv();
bm_init_types_bmloopcol();
bm_init_types_bmdvert();
diff --git a/source/blender/python/bmesh/bmesh_py_types_meshdata.h b/source/blender/python/bmesh/bmesh_py_types_meshdata.h
index 07d8a46cc65..c8ae2596f99 100644
--- a/source/blender/python/bmesh/bmesh_py_types_meshdata.h
+++ b/source/blender/python/bmesh/bmesh_py_types_meshdata.h
@@ -40,15 +40,11 @@ typedef struct BPy_BMGenericMeshData {
void *data;
} BPy_BMGenericMeshData;
-struct MTexPoly;
struct MLoopUV;
struct MLoopCol;
struct MDeformVert;
struct MVertSkin;
-int BPy_BMTexPoly_AssignPyObject(struct MTexPoly *mloopuv, PyObject *value);
-PyObject *BPy_BMTexPoly_CreatePyObject(struct MTexPoly *mloopuv);
-
int BPy_BMLoopUV_AssignPyObject(struct MLoopUV *data, PyObject *value);
PyObject *BPy_BMLoopUV_CreatePyObject(struct MLoopUV *data);
diff --git a/source/blender/python/gawain/CMakeLists.txt b/source/blender/python/gawain/CMakeLists.txt
new file mode 100644
index 00000000000..9eab323a0fe
--- /dev/null
+++ b/source/blender/python/gawain/CMakeLists.txt
@@ -0,0 +1,47 @@
+# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Contributor(s): Campbell Barton
+#
+# ***** END GPL LICENSE BLOCK *****
+
+set(INC
+ .
+ ../../blenkernel
+ ../../blenlib
+ ../../gpu
+ ../../makesdna
+ ../../../../intern/gawain
+ ../../../../intern/guardedalloc
+ ../../../../intern/glew-mx
+)
+
+set(INC_SYS
+ ${GLEW_INCLUDE_PATH}
+ ${PYTHON_INCLUDE_DIRS}
+)
+
+set(SRC
+ gwn_py_api.c
+ gwn_py_types.c
+
+ gwn_py_api.h
+ gwn_py_types.h
+)
+
+add_definitions(${GL_DEFINITIONS})
+
+blender_add_lib(bf_python_gawain "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/gawain/gwn_py_api.c b/source/blender/python/gawain/gwn_py_api.c
new file mode 100644
index 00000000000..d79ef070649
--- /dev/null
+++ b/source/blender/python/gawain/gwn_py_api.c
@@ -0,0 +1,63 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/gawain/gwn_py_api.c
+ * \ingroup pygawain
+ *
+ * Experimental Python API, not considered public yet (called '_gawain'),
+ * we may re-expose as public later.
+ */
+
+#include <Python.h>
+
+#include "gawain/gwn_batch.h"
+#include "gawain/gwn_vertex_format.h"
+
+#include "gwn_py_api.h"
+#include "gwn_py_types.h"
+
+#include "BLI_utildefines.h"
+
+#include "../generic/python_utildefines.h"
+
+PyDoc_STRVAR(GWN_doc,
+"This module provides access to gawain drawing functions."
+);
+static struct PyModuleDef GWN_module_def = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "_gawain", /* m_name */
+ .m_doc = GWN_doc, /* m_doc */
+};
+
+PyObject *BPyInit_gawain(void)
+{
+ PyObject *sys_modules = PyThreadState_GET()->interp->modules;
+ PyObject *submodule;
+ PyObject *mod;
+
+ mod = PyModule_Create(&GWN_module_def);
+
+ /* _gawain.types */
+ PyModule_AddObject(mod, "types", (submodule = BPyInit_gawain_types()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ Py_INCREF(submodule);
+
+ return mod;
+}
diff --git a/source/blender/python/gawain/gwn_py_api.h b/source/blender/python/gawain/gwn_py_api.h
new file mode 100644
index 00000000000..3ef85e8ae0f
--- /dev/null
+++ b/source/blender/python/gawain/gwn_py_api.h
@@ -0,0 +1,30 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+#ifndef __GWN_PY_API_H__
+#define __GWN_PY_API_H__
+
+/** \file blender/python/gawain/gwn_py_api.h
+ * \ingroup pygawain
+ */
+
+PyObject *BPyInit_gawain(void);
+
+#endif /* __GWN_PY_API_H__ */
diff --git a/source/blender/python/gawain/gwn_py_types.c b/source/blender/python/gawain/gwn_py_types.c
new file mode 100644
index 00000000000..9ddad009a12
--- /dev/null
+++ b/source/blender/python/gawain/gwn_py_types.c
@@ -0,0 +1,847 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/gawain/gwn_py_types.c
+ * \ingroup pygawain
+ *
+ * - Use ``bpygwn_`` for local API.
+ * - Use ``BPyGwn_`` for public API.
+ */
+
+#include <Python.h>
+
+#include "gawain/gwn_batch.h"
+#include "gawain/gwn_vertex_format.h"
+
+#include "BLI_math.h"
+
+#include "GPU_batch.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "../generic/py_capi_utils.h"
+#include "../generic/python_utildefines.h"
+
+#include "gwn_py_types.h" /* own include */
+
+#ifdef __BIG_ENDIAN__
+ /* big endian */
+# define MAKE_ID2(c, d) ((c) << 8 | (d))
+# define MAKE_ID3(a, b, c) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 )
+# define MAKE_ID4(a, b, c, d) ( (int)(a) << 24 | (int)(b) << 16 | (c) << 8 | (d) )
+#else
+ /* little endian */
+# define MAKE_ID2(c, d) ((d) << 8 | (c))
+# define MAKE_ID3(a, b, c) ( (int)(c) << 16 | (b) << 8 | (a) )
+# define MAKE_ID4(a, b, c, d) ( (int)(d) << 24 | (int)(c) << 16 | (b) << 8 | (a) )
+#endif
+
+/* -------------------------------------------------------------------- */
+
+/** \name Enum Conversion
+ *
+ * Use with PyArg_ParseTuple's "O&" formatting.
+ * \{ */
+
+static int bpygwn_ParseVertCompType(PyObject *o, void *p)
+{
+ Py_ssize_t comp_type_id_len;
+ const char *comp_type_id = _PyUnicode_AsStringAndSize(o, &comp_type_id_len);
+ if (comp_type_id == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "expected a string, got %s",
+ Py_TYPE(o)->tp_name);
+ return 0;
+ }
+
+ Gwn_VertCompType comp_type;
+ if (comp_type_id_len == 2) {
+ switch (*((ushort *)comp_type_id)) {
+ case MAKE_ID2('I', '8'): { comp_type = GWN_COMP_I8; goto success; }
+ case MAKE_ID2('U', '8'): { comp_type = GWN_COMP_U8; goto success; }
+ }
+ }
+ else if (comp_type_id_len == 3) {
+ switch (*((uint *)comp_type_id)) {
+ case MAKE_ID3('I', '1', '6'): { comp_type = GWN_COMP_I16; goto success; }
+ case MAKE_ID3('U', '1', '6'): { comp_type = GWN_COMP_U16; goto success; }
+ case MAKE_ID3('I', '3', '2'): { comp_type = GWN_COMP_I32; goto success; }
+ case MAKE_ID3('U', '3', '2'): { comp_type = GWN_COMP_U32; goto success; }
+ case MAKE_ID3('F', '3', '2'): { comp_type = GWN_COMP_F32; goto success; }
+ case MAKE_ID3('I', '1', '0'): { comp_type = GWN_COMP_I10; goto success; }
+ }
+ }
+
+ PyErr_Format(PyExc_ValueError,
+ "unknown type literal: '%s'",
+ comp_type_id);
+ return 0;
+
+success:
+ *((Gwn_VertCompType *)p) = comp_type;
+ return 1;
+}
+
+static int bpygwn_ParseVertFetchMode(PyObject *o, void *p)
+{
+ Py_ssize_t mode_id_len;
+ const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len);
+ if (mode_id == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "expected a string, got %s",
+ Py_TYPE(o)->tp_name);
+ return 0;
+ }
+#define MATCH_ID(id) \
+ if (mode_id_len == strlen(STRINGIFY(id))) { \
+ if (STREQ(mode_id, STRINGIFY(id))) { \
+ mode = GWN_FETCH_##id; \
+ goto success; \
+ } \
+ } ((void)0)
+
+ Gwn_VertFetchMode mode;
+ MATCH_ID(FLOAT);
+ MATCH_ID(INT);
+ MATCH_ID(INT_TO_FLOAT_UNIT);
+ MATCH_ID(INT_TO_FLOAT);
+#undef MATCH_ID
+ PyErr_Format(PyExc_ValueError,
+ "unknown type literal: '%s'",
+ mode_id);
+ return 0;
+
+success:
+ (*(Gwn_VertFetchMode *)p) = mode;
+ return 1;
+}
+
+static int bpygwn_ParsePrimType(PyObject *o, void *p)
+{
+ Py_ssize_t mode_id_len;
+ const char *mode_id = _PyUnicode_AsStringAndSize(o, &mode_id_len);
+ if (mode_id == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "expected a string, got %s",
+ Py_TYPE(o)->tp_name);
+ return 0;
+ }
+#define MATCH_ID(id) \
+ if (mode_id_len == strlen(STRINGIFY(id))) { \
+ if (STREQ(mode_id, STRINGIFY(id))) { \
+ mode = GWN_PRIM_##id; \
+ goto success; \
+ } \
+ } ((void)0)
+
+ Gwn_PrimType mode;
+ MATCH_ID(POINTS);
+ MATCH_ID(LINES);
+ MATCH_ID(TRIS);
+ MATCH_ID(LINE_STRIP);
+ MATCH_ID(LINE_LOOP);
+ MATCH_ID(TRI_STRIP);
+ MATCH_ID(TRI_FAN);
+ MATCH_ID(LINE_STRIP_ADJ);
+
+#undef MATCH_ID
+ PyErr_Format(PyExc_ValueError,
+ "unknown type literal: '%s'",
+ mode_id);
+ return 0;
+
+success:
+ (*(Gwn_PrimType *)p) = mode;
+ return 1;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Utility Functions
+ * \{ */
+
+#define PY_AS_NATIVE_SWITCH(attr) \
+ switch (attr->comp_type) { \
+ case GWN_COMP_I8: { PY_AS_NATIVE(int8_t, PyC_Long_AsI8); break; } \
+ case GWN_COMP_U8: { PY_AS_NATIVE(uint8_t, PyC_Long_AsU8); break; } \
+ case GWN_COMP_I16: { PY_AS_NATIVE(int16_t, PyC_Long_AsI16); break; } \
+ case GWN_COMP_U16: { PY_AS_NATIVE(uint16_t, PyC_Long_AsU16); break; } \
+ case GWN_COMP_I32: { PY_AS_NATIVE(int32_t, PyC_Long_AsI32); break; } \
+ case GWN_COMP_U32: { PY_AS_NATIVE(uint32_t, PyC_Long_AsU32); break; } \
+ case GWN_COMP_F32: { PY_AS_NATIVE(float, PyFloat_AsDouble); break; } \
+ default: \
+ BLI_assert(0); \
+ } ((void)0)
+
+/* No error checking, callers must run PyErr_Occurred */
+static void fill_format_elem(void *data_dst_void, PyObject *py_src, const Gwn_VertAttr *attr)
+{
+#define PY_AS_NATIVE(ty_dst, py_as_native) \
+{ \
+ ty_dst *data_dst = data_dst_void; \
+ *data_dst = py_as_native(py_src); \
+} ((void)0)
+
+ PY_AS_NATIVE_SWITCH(attr);
+
+#undef PY_AS_NATIVE
+}
+
+/* No error checking, callers must run PyErr_Occurred */
+static void fill_format_tuple(void *data_dst_void, PyObject *py_src, const Gwn_VertAttr *attr)
+{
+ const uint len = attr->comp_ct;
+
+/**
+ * Args are constants, so range checks will be optimized out if they're nop's.
+ */
+#define PY_AS_NATIVE(ty_dst, py_as_native) \
+ ty_dst *data_dst = data_dst_void; \
+ for (uint i = 0; i < len; i++) { \
+ data_dst[i] = py_as_native(PyTuple_GET_ITEM(py_src, i)); \
+ } ((void)0)
+
+ PY_AS_NATIVE_SWITCH(attr);
+
+#undef PY_AS_NATIVE
+}
+
+#undef PY_AS_NATIVE_SWITCH
+#undef WARN_TYPE_LIMIT_PUSH
+#undef WARN_TYPE_LIMIT_POP
+
+static bool bpygwn_vertbuf_fill_impl(
+ Gwn_VertBuf *vbo,
+ uint data_id, PyObject *seq)
+{
+ bool ok = true;
+ const Gwn_VertAttr *attr = &vbo->format.attribs[data_id];
+
+ Gwn_VertBufRaw data_step;
+ GWN_vertbuf_attr_get_raw_data(vbo, data_id, &data_step);
+
+ PyObject *seq_fast = PySequence_Fast(seq, "Vertex buffer fill");
+ if (seq_fast == NULL) {
+ goto finally;
+ }
+
+ const uint seq_len = PySequence_Fast_GET_SIZE(seq_fast);
+
+ if (seq_len != vbo->vertex_ct) {
+ PyErr_Format(PyExc_ValueError,
+ "Expected a sequence of size %d, got %d",
+ vbo->vertex_ct, seq_len);
+ }
+
+ PyObject **seq_items = PySequence_Fast_ITEMS(seq_fast);
+
+ if (attr->comp_ct == 1) {
+ for (uint i = 0; i < seq_len; i++) {
+ uchar *data = (uchar *)GWN_vertbuf_raw_step(&data_step);
+ PyObject *item = seq_items[i];
+ fill_format_elem(data, item, attr);
+ }
+ }
+ else {
+ for (uint i = 0; i < seq_len; i++) {
+ uchar *data = (uchar *)GWN_vertbuf_raw_step(&data_step);
+ PyObject *item = seq_items[i];
+ if (!PyTuple_CheckExact(item)) {
+ PyErr_Format(PyExc_ValueError,
+ "expected a tuple, got %s",
+ Py_TYPE(item)->tp_name);
+ ok = false;
+ goto finally;
+ }
+ if (PyTuple_GET_SIZE(item) != attr->comp_ct) {
+ PyErr_Format(PyExc_ValueError,
+ "expected a tuple of size %d, got %d",
+ attr->comp_ct, PyTuple_GET_SIZE(item));
+ ok = false;
+ goto finally;
+ }
+
+ /* May trigger error, check below */
+ fill_format_tuple(data, item, attr);
+ }
+ }
+
+ if (PyErr_Occurred()) {
+ ok = false;
+ }
+
+finally:
+
+ Py_DECREF(seq_fast);
+ return ok;
+}
+
+/* handy, but not used just now */
+#if 0
+static int bpygwn_find_id(const Gwn_VertFormat *fmt, const char *id)
+{
+ for (int i = 0; i < fmt->attrib_ct; i++) {
+ for (uint j = 0; j < fmt->name_ct; j++) {
+ if (STREQ(fmt->attribs[i].name[j], id)) {
+ return i;
+ }
+ }
+ }
+ return -1;
+}
+#endif
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name VertFormat Type
+ * \{ */
+
+static PyObject *bpygwn_VertFormat_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
+{
+ if (PyTuple_GET_SIZE(args) || (kwds && PyDict_Size(kwds))) {
+ PyErr_SetString(PyExc_TypeError,
+ "VertFormat(): takes no arguments");
+ return NULL;
+ }
+
+ BPyGwn_VertFormat *ret = (BPyGwn_VertFormat *)BPyGwn_VertFormat_CreatePyObject(NULL);
+
+ return (PyObject *)ret;
+}
+
+PyDoc_STRVAR(bpygwn_VertFormat_attr_add_doc,
+"TODO"
+);
+static PyObject *bpygwn_VertFormat_attr_add(BPyGwn_VertFormat *self, PyObject *args, PyObject *kwds)
+{
+ static const char *kwlist[] = {"id", "comp_type", "len", "fetch_mode", NULL};
+
+ struct {
+ const char *id;
+ Gwn_VertCompType comp_type;
+ uint len;
+ Gwn_VertFetchMode fetch_mode;
+ } params;
+
+ if (self->fmt.attrib_ct == GWN_VERT_ATTR_MAX_LEN) {
+ PyErr_SetString(PyExc_ValueError, "Maxumum attr reached " STRINGIFY(GWN_VERT_ATTR_MAX_LEN));
+ return NULL;
+ }
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwds, "$sO&IO&:attr_add", (char **)kwlist,
+ &params.id,
+ bpygwn_ParseVertCompType, &params.comp_type,
+ &params.len,
+ bpygwn_ParseVertFetchMode, &params.fetch_mode))
+ {
+ return NULL;
+ }
+
+ uint attr_id = GWN_vertformat_attr_add(&self->fmt, params.id, params.comp_type, params.len, params.fetch_mode);
+ return PyLong_FromLong(attr_id);
+}
+
+static struct PyMethodDef bpygwn_VertFormat_methods[] = {
+ {"attr_add", (PyCFunction)bpygwn_VertFormat_attr_add,
+ METH_VARARGS | METH_KEYWORDS, bpygwn_VertFormat_attr_add_doc},
+ {NULL, NULL, 0, NULL}
+};
+
+
+static void bpygwn_VertFormat_dealloc(BPyGwn_VertFormat *self)
+{
+ Py_TYPE(self)->tp_free(self);
+}
+
+PyTypeObject BPyGwn_VertFormat_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "Gwn_VertFormat",
+ .tp_basicsize = sizeof(BPyGwn_VertFormat),
+ .tp_dealloc = (destructor)bpygwn_VertFormat_dealloc,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_methods = bpygwn_VertFormat_methods,
+ .tp_new = bpygwn_VertFormat_new,
+};
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name VertBuf Type
+ * \{ */
+
+static PyObject *bpygwn_VertBuf_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
+{
+ const char * const keywords[] = {"len", "format", NULL};
+
+ struct {
+ BPyGwn_VertFormat *py_fmt;
+ uint len;
+ } params;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwds,
+ "$IO!:Gwn_VertBuf.__new__", (char **)keywords,
+ &params.len,
+ &BPyGwn_VertFormat_Type, &params.py_fmt))
+ {
+ return NULL;
+ }
+
+ struct Gwn_VertBuf *vbo = GWN_vertbuf_create_with_format(&params.py_fmt->fmt);
+
+ GWN_vertbuf_data_alloc(vbo, params.len);
+
+ return BPyGwn_VertBuf_CreatePyObject(vbo);
+}
+
+PyDoc_STRVAR(bpygwn_VertBuf_fill_doc,
+"TODO"
+);
+static PyObject *bpygwn_VertBuf_fill(BPyGwn_VertBuf *self, PyObject *args, PyObject *kwds)
+{
+ static const char *kwlist[] = {"id", "data", NULL};
+
+ struct {
+ uint id;
+ PyObject *py_seq_data;
+ } params;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwds, "$IO:fill", (char **)kwlist,
+ &params.id,
+ &params.py_seq_data))
+ {
+ return NULL;
+ }
+
+ if (params.id >= self->buf->format.attrib_ct) {
+ PyErr_Format(PyExc_ValueError,
+ "Format id %d out of range",
+ params.id);
+ return NULL;
+ }
+
+ if (self->buf->data == NULL) {
+ PyErr_SetString(PyExc_ValueError,
+ "Can't fill, static buffer already in use");
+ return NULL;
+ }
+
+ if (!bpygwn_vertbuf_fill_impl(self->buf, params.id, params.py_seq_data)) {
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static struct PyMethodDef bpygwn_VertBuf_methods[] = {
+ {"fill", (PyCFunction) bpygwn_VertBuf_fill,
+ METH_VARARGS | METH_KEYWORDS, bpygwn_VertBuf_fill_doc},
+ {NULL, NULL, 0, NULL}
+};
+
+static void bpygwn_VertBuf_dealloc(BPyGwn_VertBuf *self)
+{
+ GWN_vertbuf_discard(self->buf);
+ Py_TYPE(self)->tp_free(self);
+}
+
+PyTypeObject BPyGwn_VertBuf_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "Gwn_VertBuf",
+ .tp_basicsize = sizeof(BPyGwn_VertBuf),
+ .tp_dealloc = (destructor)bpygwn_VertBuf_dealloc,
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_methods = bpygwn_VertBuf_methods,
+ .tp_new = bpygwn_VertBuf_new,
+};
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name VertBatch Type
+ * \{ */
+
+static PyObject *bpygwn_Batch_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
+{
+ const char * const keywords[] = {"type", "buf", NULL};
+
+ struct {
+ Gwn_PrimType type_id;
+ BPyGwn_VertBuf *py_buf;
+ } params;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwds,
+ "$O&O!:Gwn_Batch.__new__", (char **)keywords,
+ bpygwn_ParsePrimType, &params.type_id,
+ &BPyGwn_VertBuf_Type, &params.py_buf))
+ {
+ return NULL;
+ }
+
+ Gwn_Batch *batch = GWN_batch_create(params.type_id, params.py_buf->buf, NULL);
+ BPyGwn_Batch *ret = (BPyGwn_Batch *)BPyGwn_Batch_CreatePyObject(batch);
+
+#ifdef USE_GWN_PY_REFERENCES
+ ret->references = PyList_New(1);
+ PyList_SET_ITEM(ret->references, 0, (PyObject *)params.py_buf);
+ Py_INCREF(params.py_buf);
+ PyObject_GC_Track(ret);
+#endif
+
+ return (PyObject *)ret;
+}
+
+PyDoc_STRVAR(bpygwn_VertBatch_vertbuf_add_doc,
+"TODO"
+);
+static PyObject *bpygwn_VertBatch_vertbuf_add(BPyGwn_Batch *self, BPyGwn_VertBuf *py_buf)
+{
+ if (!BPyGwn_VertBuf_Check(py_buf)) {
+ PyErr_Format(PyExc_TypeError,
+ "Expected a Gwn_VertBuf, got %s",
+ Py_TYPE(py_buf)->tp_name);
+ return NULL;
+ }
+
+ if (self->batch->verts[0]->vertex_ct != py_buf->buf->vertex_ct) {
+ PyErr_Format(PyExc_TypeError,
+ "Expected %d length, got %d",
+ self->batch->verts[0]->vertex_ct, py_buf->buf->vertex_ct);
+ return NULL;
+ }
+
+#ifdef USE_GWN_PY_REFERENCES
+ /* Hold user */
+ PyList_Append(self->references, (PyObject *)py_buf);
+#endif
+
+ GWN_batch_vertbuf_add(self->batch, py_buf->buf);
+ Py_RETURN_NONE;
+}
+
+/* Currently magic number from Py perspective. */
+PyDoc_STRVAR(bpygwn_VertBatch_program_set_builtin_doc,
+"TODO"
+);
+static PyObject *bpygwn_VertBatch_program_set_builtin(BPyGwn_Batch *self, PyObject *args, PyObject *kwds)
+{
+ static const char *kwlist[] = {"id", NULL};
+
+ struct {
+ const char *shader;
+ } params;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kwds, "s:program_set_builtin", (char **)kwlist,
+ &params.shader))
+ {
+ return NULL;
+ }
+
+ GPUBuiltinShader shader;
+
+#define MATCH_ID(id) \
+ if (STREQ(params.shader, STRINGIFY(id))) { \
+ shader = GPU_SHADER_##id; \
+ goto success; \
+ } ((void)0)
+
+ MATCH_ID(2D_FLAT_COLOR);
+ MATCH_ID(2D_SMOOTH_COLOR);
+ MATCH_ID(2D_UNIFORM_COLOR);
+
+ MATCH_ID(3D_FLAT_COLOR);
+ MATCH_ID(3D_SMOOTH_COLOR);
+ MATCH_ID(3D_UNIFORM_COLOR);
+
+#undef MATCH_ID
+
+ PyErr_SetString(PyExc_ValueError,
+ "shader name not known");
+ return NULL;
+
+success:
+ GWN_batch_program_set_builtin(self->batch, shader);
+ Py_RETURN_NONE;
+}
+
+static PyObject *bpygwn_VertBatch_uniform_bool(BPyGwn_Batch *self, PyObject *args)
+{
+ struct {
+ const char *id;
+ bool values[1];
+ } params;
+
+ if (!PyArg_ParseTuple(
+ args, "sO&:uniform_bool",
+ &params.id,
+ PyC_ParseBool, &params.values[0]))
+ {
+ return NULL;
+ }
+
+ GWN_batch_uniform_1b(self->batch, params.id, params.values[0]);
+ Py_RETURN_NONE;
+}
+
+static PyObject *bpygwn_VertBatch_uniform_i32(BPyGwn_Batch *self, PyObject *args)
+{
+ struct {
+ const char *id;
+ int values[1];
+ } params;
+
+ if (!PyArg_ParseTuple(
+ args, "si:uniform_i32",
+ &params.id,
+ &params.values[0]))
+ {
+ return NULL;
+ }
+
+ GWN_batch_uniform_1i(self->batch, params.id, params.values[0]);
+ Py_RETURN_NONE;
+}
+
+static PyObject *bpygwn_VertBatch_uniform_f32(BPyGwn_Batch *self, PyObject *args)
+{
+ struct {
+ const char *id;
+ float values[4];
+ } params;
+
+ if (!PyArg_ParseTuple(
+ args, "sf|fff:uniform_f32",
+ &params.id,
+ &params.values[0], &params.values[1], &params.values[2], &params.values[3]))
+ {
+ return NULL;
+ }
+
+ switch (PyTuple_GET_SIZE(args)) {
+ case 2: GWN_batch_uniform_1f(self->batch, params.id, params.values[0]); break;
+ case 3: GWN_batch_uniform_2f(self->batch, params.id, UNPACK2(params.values)); break;
+ case 4: GWN_batch_uniform_3f(self->batch, params.id, UNPACK3(params.values)); break;
+ case 5: GWN_batch_uniform_4f(self->batch, params.id, UNPACK4(params.values)); break;
+ default:
+ BLI_assert(0);
+ }
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(bpygwn_VertBatch_draw_doc,
+"TODO"
+);
+static PyObject *bpygwn_VertBatch_draw(BPyGwn_Batch *self)
+{
+ if (!glIsProgram(self->batch->program)) {
+ PyErr_SetString(PyExc_ValueError,
+ "batch program has not not set");
+ }
+ GWN_batch_draw(self->batch);
+ Py_RETURN_NONE;
+}
+
+static PyObject *bpygwn_VertBatch_program_use_begin(BPyGwn_Batch *self)
+{
+ if (!glIsProgram(self->batch->program)) {
+ PyErr_SetString(PyExc_ValueError,
+ "batch program has not not set");
+ }
+ GWN_batch_program_use_begin(self->batch);
+ Py_RETURN_NONE;
+}
+
+static PyObject *bpygwn_VertBatch_program_use_end(BPyGwn_Batch *self)
+{
+ if (!glIsProgram(self->batch->program)) {
+ PyErr_SetString(PyExc_ValueError,
+ "batch program has not not set");
+ }
+ GWN_batch_program_use_end(self->batch);
+ Py_RETURN_NONE;
+}
+
+static struct PyMethodDef bpygwn_VertBatch_methods[] = {
+ {"vertbuf_add", (PyCFunction)bpygwn_VertBatch_vertbuf_add,
+ METH_O, bpygwn_VertBatch_vertbuf_add_doc},
+ {"program_set_builtin", (PyCFunction)bpygwn_VertBatch_program_set_builtin,
+ METH_VARARGS | METH_KEYWORDS, bpygwn_VertBatch_program_set_builtin_doc},
+ {"uniform_bool", (PyCFunction)bpygwn_VertBatch_uniform_bool,
+ METH_VARARGS, NULL},
+ {"uniform_i32", (PyCFunction)bpygwn_VertBatch_uniform_i32,
+ METH_VARARGS, NULL},
+ {"uniform_f32", (PyCFunction)bpygwn_VertBatch_uniform_f32,
+ METH_VARARGS, NULL},
+ {"draw", (PyCFunction) bpygwn_VertBatch_draw,
+ METH_NOARGS, bpygwn_VertBatch_draw_doc},
+ {"program_use_begin", (PyCFunction)bpygwn_VertBatch_program_use_begin,
+ METH_NOARGS, ""},
+ {"program_use_end", (PyCFunction)bpygwn_VertBatch_program_use_end,
+ METH_NOARGS, ""},
+ {NULL, NULL, 0, NULL}
+};
+
+#ifdef USE_GWN_PY_REFERENCES
+
+static int bpygwn_Batch_traverse(BPyGwn_Batch *self, visitproc visit, void *arg)
+{
+ Py_VISIT(self->references);
+ return 0;
+}
+
+static int bpygwn_Batch_clear(BPyGwn_Batch *self)
+{
+ Py_CLEAR(self->references);
+ return 0;
+}
+
+#endif
+
+static void bpygwn_Batch_dealloc(BPyGwn_Batch *self)
+{
+ GWN_batch_discard(self->batch);
+
+#ifdef USE_GWN_PY_REFERENCES
+ if (self->references) {
+ PyObject_GC_UnTrack(self);
+ bpygwn_Batch_clear(self);
+ Py_XDECREF(self->references);
+ }
+#endif
+
+ Py_TYPE(self)->tp_free(self);
+}
+
+PyTypeObject BPyGwn_Batch_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "Gwn_Batch",
+ .tp_basicsize = sizeof(BPyGwn_Batch),
+ .tp_dealloc = (destructor)bpygwn_Batch_dealloc,
+#ifdef USE_GWN_PY_REFERENCES
+ .tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
+ .tp_traverse = (traverseproc)bpygwn_Batch_traverse,
+ .tp_clear = (inquiry)bpygwn_Batch_clear,
+#else
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+#endif
+ .tp_methods = bpygwn_VertBatch_methods,
+ .tp_new = bpygwn_Batch_new,
+};
+
+/* -------------------------------------------------------------------- */
+
+
+/** \name Gawain Types Module
+ * \{ */
+
+static struct PyModuleDef BPy_BM_types_module_def = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "_gawain.types",
+};
+
+PyObject *BPyInit_gawain_types(void)
+{
+ PyObject *submodule;
+
+ submodule = PyModule_Create(&BPy_BM_types_module_def);
+
+ if (PyType_Ready(&BPyGwn_VertFormat_Type) < 0)
+ return NULL;
+ if (PyType_Ready(&BPyGwn_VertBuf_Type) < 0)
+ return NULL;
+ if (PyType_Ready(&BPyGwn_Batch_Type) < 0)
+ return NULL;
+
+#define MODULE_TYPE_ADD(s, t) \
+ PyModule_AddObject(s, t.tp_name, (PyObject *)&t); Py_INCREF((PyObject *)&t)
+
+ MODULE_TYPE_ADD(submodule, BPyGwn_VertFormat_Type);
+ MODULE_TYPE_ADD(submodule, BPyGwn_VertBuf_Type);
+ MODULE_TYPE_ADD(submodule, BPyGwn_Batch_Type);
+
+#undef MODULE_TYPE_ADD
+
+ return submodule;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Public API
+ * \{ */
+
+PyObject *BPyGwn_VertFormat_CreatePyObject(Gwn_VertFormat *fmt)
+{
+ BPyGwn_VertFormat *self;
+
+ self = PyObject_New(BPyGwn_VertFormat, &BPyGwn_VertFormat_Type);
+ if (fmt) {
+ self->fmt = *fmt;
+ }
+ else {
+ memset(&self->fmt, 0, sizeof(self->fmt));
+ }
+
+ return (PyObject *)self;
+}
+
+PyObject *BPyGwn_VertBuf_CreatePyObject(Gwn_VertBuf *buf)
+{
+ BPyGwn_VertBuf *self;
+
+ self = PyObject_New(BPyGwn_VertBuf, &BPyGwn_VertBuf_Type);
+ self->buf = buf;
+
+ return (PyObject *)self;
+}
+
+
+PyObject *BPyGwn_Batch_CreatePyObject(Gwn_Batch *batch)
+{
+ BPyGwn_Batch *self;
+
+#ifdef USE_GWN_PY_REFERENCES
+ self = (BPyGwn_Batch *)_PyObject_GC_New(&BPyGwn_Batch_Type);
+ self->references = NULL;
+#else
+ self = PyObject_New(BPyGwn_Batch, &BPyGwn_Batch_Type);
+#endif
+
+ self->batch = batch;
+
+ return (PyObject *)self;
+}
+
+/** \} */
diff --git a/source/blender/python/gawain/gwn_py_types.h b/source/blender/python/gawain/gwn_py_types.h
new file mode 100644
index 00000000000..dde6cf98827
--- /dev/null
+++ b/source/blender/python/gawain/gwn_py_types.h
@@ -0,0 +1,67 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/gawain/gwn_py_types.h
+ * \ingroup pygawain
+ */
+
+#ifndef __GWN_PY_TYPES_H__
+#define __GWN_PY_TYPES_H__
+
+#include "BLI_compiler_attrs.h"
+
+#define USE_GWN_PY_REFERENCES
+
+extern PyTypeObject BPyGwn_VertFormat_Type;
+extern PyTypeObject BPyGwn_VertBuf_Type;
+extern PyTypeObject BPyGwn_Batch_Type;
+
+#define BPyGwn_VertFormat_Check(v) (Py_TYPE(v) == &BPyGwn_VertFormat_Type)
+#define BPyGwn_VertBuf_Check(v) (Py_TYPE(v) == &BPyGwn_VertBuf_Type)
+#define BPyGwn_Batch_Check(v) (Py_TYPE(v) == &BPyGwn_Batch_Type)
+
+typedef struct BPyGwn_VertFormat {
+ PyObject_VAR_HEAD
+ struct Gwn_VertFormat fmt;
+} BPyGwn_VertFormat;
+
+typedef struct BPyGwn_VertBuf {
+ PyObject_VAR_HEAD
+ /* The buf is owned, we may support thin wrapped batches later. */
+ struct Gwn_VertBuf *buf;
+} BPyGwn_VertBuf;
+
+typedef struct BPyGwn_Batch {
+ PyObject_VAR_HEAD
+ /* The batch is owned, we may support thin wrapped batches later. */
+ struct Gwn_Batch *batch;
+#ifdef USE_GWN_PY_REFERENCES
+ /* Just to keep a user to prevent freeing buf's we're using */
+ PyObject *references;
+#endif
+} BPyGwn_Batch;
+
+PyObject *BPyInit_gawain_types(void);
+
+PyObject *BPyGwn_VertFormat_CreatePyObject(struct Gwn_VertFormat *fmt);
+PyObject *BPyGwn_VertBuf_CreatePyObject(struct Gwn_VertBuf *vbo) ATTR_NONNULL(1);
+PyObject *BPyGwn_Batch_CreatePyObject(struct Gwn_Batch *batch) ATTR_NONNULL(1);
+
+#endif /* __GWN_PY_TYPES_H__ */
diff --git a/source/blender/python/generic/bgl.c b/source/blender/python/generic/bgl.c
index 072021c6ac9..1e2837799e3 100644
--- a/source/blender/python/generic/bgl.c
+++ b/source/blender/python/generic/bgl.c
@@ -185,11 +185,13 @@
#define GLbitfield_ref(num) &bgl_var##num
#define GLbitfield_def(num) /* unsigned */ int GLbitfield_var(num)
+#if 0
/* typedef signed char GLbyte; */
#define GLbyte_str "b"
#define GLbyte_var(num) bgl_var##num
#define GLbyte_ref(num) &bgl_var##num
#define GLbyte_def(num) signed char GLbyte_var(num)
+#endif
/* typedef short GLshort; */
#define GLshort_str "h"
@@ -227,11 +229,13 @@
#define GLubyte_ref(num) &bgl_var##num
#define GLubyte_def(num) /* unsigned */ char GLubyte_var(num)
+#if 0
/* typedef unsigned short GLushort; */
#define GLushort_str "H"
#define GLushort_var(num) bgl_var##num
#define GLushort_ref(num) &bgl_var##num
#define GLushort_def(num) /* unsigned */ short GLushort_var(num)
+#endif
/* typedef unsigned int GLuint; */
#define GLuint_str "I"
@@ -1073,358 +1077,71 @@ static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \
ret_ret_##ret; \
}
-#define BGLU_Wrap(funcname, ret, arg_list) \
-static PyObject *Method_##funcname (PyObject *UNUSED(self), PyObject *args) \
-{ \
- arg_def arg_list; \
- ret_def_##ret; \
- if (!PyArg_ParseTuple(args, arg_str arg_list, arg_ref arg_list)) { \
- return NULL; \
- } \
- ret_set_##ret glu##funcname (arg_var arg_list); \
- ret_ret_##ret; \
-}
-
/* GL_VERSION_1_0 */
-BGL_Wrap(Accum, void, (GLenum, GLfloat))
-BGL_Wrap(AlphaFunc, void, (GLenum, GLfloat))
-BGL_Wrap(Begin, void, (GLenum))
-BGL_Wrap(Bitmap, void, (GLsizei, GLsizei, GLfloat, GLfloat, GLfloat, GLfloat, GLubyteP))
BGL_Wrap(BlendFunc, void, (GLenum, GLenum))
-BGL_Wrap(CallList, void, (GLuint))
-BGL_Wrap(CallLists, void, (GLsizei, GLenum, GLvoidP))
BGL_Wrap(Clear, void, (GLbitfield))
-BGL_Wrap(ClearAccum, void, (GLfloat, GLfloat, GLfloat, GLfloat))
BGL_Wrap(ClearColor, void, (GLfloat, GLfloat, GLfloat, GLfloat))
BGL_Wrap(ClearDepth, void, (GLdouble))
-BGL_Wrap(ClearIndex, void, (GLfloat))
BGL_Wrap(ClearStencil, void, (GLint))
-BGL_Wrap(ClipPlane, void, (GLenum, GLdoubleP))
-BGL_Wrap(Color3b, void, (GLbyte, GLbyte, GLbyte))
-BGL_Wrap(Color3bv, void, (GLbyteP))
-BGL_Wrap(Color3d, void, (GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Color3dv, void, (GLdoubleP))
-BGL_Wrap(Color3f, void, (GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Color3fv, void, (GLfloatP))
-BGL_Wrap(Color3i, void, (GLint, GLint, GLint))
-BGL_Wrap(Color3iv, void, (GLintP))
-BGL_Wrap(Color3s, void, (GLshort, GLshort, GLshort))
-BGL_Wrap(Color3sv, void, (GLshortP))
-BGL_Wrap(Color3ub, void, (GLubyte, GLubyte, GLubyte))
-BGL_Wrap(Color3ubv, void, (GLubyteP))
-BGL_Wrap(Color3ui, void, (GLuint, GLuint, GLuint))
-BGL_Wrap(Color3uiv, void, (GLuintP))
-BGL_Wrap(Color3us, void, (GLushort, GLushort, GLushort))
-BGL_Wrap(Color3usv, void, (GLushortP))
-BGL_Wrap(Color4b, void, (GLbyte, GLbyte, GLbyte, GLbyte))
-BGL_Wrap(Color4bv, void, (GLbyteP))
-BGL_Wrap(Color4d, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Color4dv, void, (GLdoubleP))
-BGL_Wrap(Color4f, void, (GLfloat, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Color4fv, void, (GLfloatP))
-BGL_Wrap(Color4i, void, (GLint, GLint, GLint, GLint))
-BGL_Wrap(Color4iv, void, (GLintP))
-BGL_Wrap(Color4s, void, (GLshort, GLshort, GLshort, GLshort))
-BGL_Wrap(Color4sv, void, (GLshortP))
-BGL_Wrap(Color4ub, void, (GLubyte, GLubyte, GLubyte, GLubyte))
-BGL_Wrap(Color4ubv, void, (GLubyteP))
-BGL_Wrap(Color4ui, void, (GLuint, GLuint, GLuint, GLuint))
-BGL_Wrap(Color4uiv, void, (GLuintP))
-BGL_Wrap(Color4us, void, (GLushort, GLushort, GLushort, GLushort))
-BGL_Wrap(Color4usv, void, (GLushortP))
BGL_Wrap(ColorMask, void, (GLboolean, GLboolean, GLboolean, GLboolean))
-BGL_Wrap(ColorMaterial, void, (GLenum, GLenum))
-BGL_Wrap(CopyPixels, void, (GLint, GLint, GLsizei, GLsizei, GLenum))
BGL_Wrap(CullFace, void, (GLenum))
-BGL_Wrap(DeleteLists, void, (GLuint, GLsizei))
BGL_Wrap(DepthFunc, void, (GLenum))
BGL_Wrap(DepthMask, void, (GLboolean))
BGL_Wrap(DepthRange, void, (GLdouble, GLdouble))
BGL_Wrap(Disable, void, (GLenum))
BGL_Wrap(DrawBuffer, void, (GLenum))
-BGL_Wrap(DrawPixels, void, (GLsizei, GLsizei, GLenum, GLenum, GLvoidP))
-BGL_Wrap(EdgeFlag, void, (GLboolean))
-BGL_Wrap(EdgeFlagv, void, (GLbooleanP))
BGL_Wrap(Enable, void, (GLenum))
-BGL_Wrap(End, void, (void))
-BGL_Wrap(EndList, void, (void))
-BGL_Wrap(EvalCoord1d, void, (GLdouble))
-BGL_Wrap(EvalCoord1dv, void, (GLdoubleP))
-BGL_Wrap(EvalCoord1f, void, (GLfloat))
-BGL_Wrap(EvalCoord1fv, void, (GLfloatP))
-BGL_Wrap(EvalCoord2d, void, (GLdouble, GLdouble))
-BGL_Wrap(EvalCoord2dv, void, (GLdoubleP))
-BGL_Wrap(EvalCoord2f, void, (GLfloat, GLfloat))
-BGL_Wrap(EvalCoord2fv, void, (GLfloatP))
-BGL_Wrap(EvalMesh1, void, (GLenum, GLint, GLint))
-BGL_Wrap(EvalMesh2, void, (GLenum, GLint, GLint, GLint, GLint))
-BGL_Wrap(EvalPoint1, void, (GLint))
-BGL_Wrap(EvalPoint2, void, (GLint, GLint))
-BGL_Wrap(FeedbackBuffer, void, (GLsizei, GLenum, GLfloatP))
BGL_Wrap(Finish, void, (void))
BGL_Wrap(Flush, void, (void))
-BGL_Wrap(Fogf, void, (GLenum, GLfloat))
-BGL_Wrap(Fogfv, void, (GLenum, GLfloatP))
-BGL_Wrap(Fogi, void, (GLenum, GLint))
-BGL_Wrap(Fogiv, void, (GLenum, GLintP))
BGL_Wrap(FrontFace, void, (GLenum))
-BGL_Wrap(Frustum, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(GenLists, GLuint, (GLsizei))
BGL_Wrap(GetBooleanv, void, (GLenum, GLbooleanP))
-BGL_Wrap(GetClipPlane, void, (GLenum, GLdoubleP))
BGL_Wrap(GetDoublev, void, (GLenum, GLdoubleP))
BGL_Wrap(GetError, GLenum, (void))
BGL_Wrap(GetFloatv, void, (GLenum, GLfloatP))
BGL_Wrap(GetIntegerv, void, (GLenum, GLintP))
-BGL_Wrap(GetLightfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(GetLightiv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(GetMapdv, void, (GLenum, GLenum, GLdoubleP))
-BGL_Wrap(GetMapfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(GetMapiv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(GetMaterialfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(GetMaterialiv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(GetPixelMapfv, void, (GLenum, GLfloatP))
-BGL_Wrap(GetPixelMapuiv, void, (GLenum, GLuintP))
-BGL_Wrap(GetPixelMapusv, void, (GLenum, GLushortP))
-BGL_Wrap(GetPolygonStipple, void, (GLubyteP))
BGL_Wrap(GetString, GLstring, (GLenum))
-BGL_Wrap(GetTexEnvfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(GetTexEnviv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(GetTexGendv, void, (GLenum, GLenum, GLdoubleP))
-BGL_Wrap(GetTexGenfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(GetTexGeniv, void, (GLenum, GLenum, GLintP))
BGL_Wrap(GetTexImage, void, (GLenum, GLint, GLenum, GLenum, GLvoidP))
BGL_Wrap(GetTexLevelParameterfv, void, (GLenum, GLint, GLenum, GLfloatP))
BGL_Wrap(GetTexLevelParameteriv, void, (GLenum, GLint, GLenum, GLintP))
BGL_Wrap(GetTexParameterfv, void, (GLenum, GLenum, GLfloatP))
BGL_Wrap(GetTexParameteriv, void, (GLenum, GLenum, GLintP))
BGL_Wrap(Hint, void, (GLenum, GLenum))
-BGL_Wrap(IndexMask, void, (GLuint))
-BGL_Wrap(Indexd, void, (GLdouble))
-BGL_Wrap(Indexdv, void, (GLdoubleP))
-BGL_Wrap(Indexf, void, (GLfloat))
-BGL_Wrap(Indexfv, void, (GLfloatP))
-BGL_Wrap(Indexi, void, (GLint))
-BGL_Wrap(Indexiv, void, (GLintP))
-BGL_Wrap(Indexs, void, (GLshort))
-BGL_Wrap(Indexsv, void, (GLshortP))
-BGL_Wrap(InitNames, void, (void))
BGL_Wrap(IsEnabled, GLboolean, (GLenum))
-BGL_Wrap(IsList, GLboolean, (GLuint))
-BGL_Wrap(LightModelf, void, (GLenum, GLfloat))
-BGL_Wrap(LightModelfv, void, (GLenum, GLfloatP))
-BGL_Wrap(LightModeli, void, (GLenum, GLint))
-BGL_Wrap(LightModeliv, void, (GLenum, GLintP))
-BGL_Wrap(Lightf, void, (GLenum, GLenum, GLfloat))
-BGL_Wrap(Lightfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(Lighti, void, (GLenum, GLenum, GLint))
-BGL_Wrap(Lightiv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(LineStipple, void, (GLint, GLushort))
BGL_Wrap(LineWidth, void, (GLfloat))
-BGL_Wrap(ListBase, void, (GLuint))
-BGL_Wrap(LoadIdentity, void, (void))
-BGL_Wrap(LoadMatrixd, void, (GLdoubleP))
-BGL_Wrap(LoadMatrixf, void, (GLfloatP))
-BGL_Wrap(LoadName, void, (GLuint))
BGL_Wrap(LogicOp, void, (GLenum))
-BGL_Wrap(Map1d, void, (GLenum, GLdouble, GLdouble, GLint, GLint, GLdoubleP))
-BGL_Wrap(Map1f, void, (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloatP))
-BGL_Wrap(Map2d, void, (GLenum, GLdouble, GLdouble, GLint, GLint, GLdouble, GLdouble, GLint, GLint, GLdoubleP))
-BGL_Wrap(Map2f, void, (GLenum, GLfloat, GLfloat, GLint, GLint, GLfloat, GLfloat, GLint, GLint, GLfloatP))
-BGL_Wrap(MapGrid1d, void, (GLint, GLdouble, GLdouble))
-BGL_Wrap(MapGrid1f, void, (GLint, GLfloat, GLfloat))
-BGL_Wrap(MapGrid2d, void, (GLint, GLdouble, GLdouble, GLint, GLdouble, GLdouble))
-BGL_Wrap(MapGrid2f, void, (GLint, GLfloat, GLfloat, GLint, GLfloat, GLfloat))
-BGL_Wrap(Materialf, void, (GLenum, GLenum, GLfloat))
-BGL_Wrap(Materialfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(Materiali, void, (GLenum, GLenum, GLint))
-BGL_Wrap(Materialiv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(MatrixMode, void, (GLenum))
-BGL_Wrap(MultMatrixd, void, (GLdoubleP))
-BGL_Wrap(MultMatrixf, void, (GLfloatP))
-BGL_Wrap(NewList, void, (GLuint, GLenum))
-BGL_Wrap(Normal3b, void, (GLbyte, GLbyte, GLbyte))
-BGL_Wrap(Normal3bv, void, (GLbyteP))
-BGL_Wrap(Normal3d, void, (GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Normal3dv, void, (GLdoubleP))
-BGL_Wrap(Normal3f, void, (GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Normal3fv, void, (GLfloatP))
-BGL_Wrap(Normal3i, void, (GLint, GLint, GLint))
-BGL_Wrap(Normal3iv, void, (GLintP))
-BGL_Wrap(Normal3s, void, (GLshort, GLshort, GLshort))
-BGL_Wrap(Normal3sv, void, (GLshortP))
-BGL_Wrap(Ortho, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(PassThrough, void, (GLfloat))
-BGL_Wrap(PixelMapfv, void, (GLenum, GLsizei, GLfloatP))
-BGL_Wrap(PixelMapuiv, void, (GLenum, GLsizei, GLuintP))
-BGL_Wrap(PixelMapusv, void, (GLenum, GLsizei, GLushortP))
BGL_Wrap(PixelStoref, void, (GLenum, GLfloat))
BGL_Wrap(PixelStorei, void, (GLenum, GLint))
-BGL_Wrap(PixelTransferf, void, (GLenum, GLfloat))
-BGL_Wrap(PixelTransferi, void, (GLenum, GLint))
-BGL_Wrap(PixelZoom, void, (GLfloat, GLfloat))
BGL_Wrap(PointSize, void, (GLfloat))
BGL_Wrap(PolygonMode, void, (GLenum, GLenum))
-BGL_Wrap(PolygonStipple, void, (GLubyteP))
-BGL_Wrap(PopAttrib, void, (void))
-BGL_Wrap(PopMatrix, void, (void))
-BGL_Wrap(PopName, void, (void))
-BGL_Wrap(PushAttrib, void, (GLbitfield))
-BGL_Wrap(PushMatrix, void, (void))
-BGL_Wrap(PushName, void, (GLuint))
-BGL_Wrap(RasterPos2d, void, (GLdouble, GLdouble))
-BGL_Wrap(RasterPos2dv, void, (GLdoubleP))
-BGL_Wrap(RasterPos2f, void, (GLfloat, GLfloat))
-BGL_Wrap(RasterPos2fv, void, (GLfloatP))
-BGL_Wrap(RasterPos2i, void, (GLint, GLint))
-BGL_Wrap(RasterPos2iv, void, (GLintP))
-BGL_Wrap(RasterPos2s, void, (GLshort, GLshort))
-BGL_Wrap(RasterPos2sv, void, (GLshortP))
-BGL_Wrap(RasterPos3d, void, (GLdouble, GLdouble, GLdouble))
-BGL_Wrap(RasterPos3dv, void, (GLdoubleP))
-BGL_Wrap(RasterPos3f, void, (GLfloat, GLfloat, GLfloat))
-BGL_Wrap(RasterPos3fv, void, (GLfloatP))
-BGL_Wrap(RasterPos3i, void, (GLint, GLint, GLint))
-BGL_Wrap(RasterPos3iv, void, (GLintP))
-BGL_Wrap(RasterPos3s, void, (GLshort, GLshort, GLshort))
-BGL_Wrap(RasterPos3sv, void, (GLshortP))
-BGL_Wrap(RasterPos4d, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(RasterPos4dv, void, (GLdoubleP))
-BGL_Wrap(RasterPos4f, void, (GLfloat, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(RasterPos4fv, void, (GLfloatP))
-BGL_Wrap(RasterPos4i, void, (GLint, GLint, GLint, GLint))
-BGL_Wrap(RasterPos4iv, void, (GLintP))
-BGL_Wrap(RasterPos4s, void, (GLshort, GLshort, GLshort, GLshort))
-BGL_Wrap(RasterPos4sv, void, (GLshortP))
BGL_Wrap(ReadBuffer, void, (GLenum))
BGL_Wrap(ReadPixels, void, (GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP))
-BGL_Wrap(Rectd, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Rectdv, void, (GLdoubleP, GLdoubleP))
-BGL_Wrap(Rectf, void, (GLfloat, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Rectfv, void, (GLfloatP, GLfloatP))
-BGL_Wrap(Recti, void, (GLint, GLint, GLint, GLint))
-BGL_Wrap(Rectiv, void, (GLintP, GLintP))
-BGL_Wrap(Rects, void, (GLshort, GLshort, GLshort, GLshort))
-BGL_Wrap(Rectsv, void, (GLshortP, GLshortP))
-BGL_Wrap(RenderMode, GLint, (GLenum))
-BGL_Wrap(Rotated, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Rotatef, void, (GLfloat, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Scaled, void, (GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Scalef, void, (GLfloat, GLfloat, GLfloat))
BGL_Wrap(Scissor, void, (GLint, GLint, GLsizei, GLsizei))
-BGL_Wrap(SelectBuffer, void, (GLsizei, GLuintP))
-BGL_Wrap(ShadeModel, void, (GLenum))
BGL_Wrap(StencilFunc, void, (GLenum, GLint, GLuint))
BGL_Wrap(StencilMask, void, (GLuint))
BGL_Wrap(StencilOp, void, (GLenum, GLenum, GLenum))
-BGL_Wrap(TexCoord1d, void, (GLdouble))
-BGL_Wrap(TexCoord1dv, void, (GLdoubleP))
-BGL_Wrap(TexCoord1f, void, (GLfloat))
-BGL_Wrap(TexCoord1fv, void, (GLfloatP))
-BGL_Wrap(TexCoord1i, void, (GLint))
-BGL_Wrap(TexCoord1iv, void, (GLintP))
-BGL_Wrap(TexCoord1s, void, (GLshort))
-BGL_Wrap(TexCoord1sv, void, (GLshortP))
-BGL_Wrap(TexCoord2d, void, (GLdouble, GLdouble))
-BGL_Wrap(TexCoord2dv, void, (GLdoubleP))
-BGL_Wrap(TexCoord2f, void, (GLfloat, GLfloat))
-BGL_Wrap(TexCoord2fv, void, (GLfloatP))
-BGL_Wrap(TexCoord2i, void, (GLint, GLint))
-BGL_Wrap(TexCoord2iv, void, (GLintP))
-BGL_Wrap(TexCoord2s, void, (GLshort, GLshort))
-BGL_Wrap(TexCoord2sv, void, (GLshortP))
-BGL_Wrap(TexCoord3d, void, (GLdouble, GLdouble, GLdouble))
-BGL_Wrap(TexCoord3dv, void, (GLdoubleP))
-BGL_Wrap(TexCoord3f, void, (GLfloat, GLfloat, GLfloat))
-BGL_Wrap(TexCoord3fv, void, (GLfloatP))
-BGL_Wrap(TexCoord3i, void, (GLint, GLint, GLint))
-BGL_Wrap(TexCoord3iv, void, (GLintP))
-BGL_Wrap(TexCoord3s, void, (GLshort, GLshort, GLshort))
-BGL_Wrap(TexCoord3sv, void, (GLshortP))
-BGL_Wrap(TexCoord4d, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(TexCoord4dv, void, (GLdoubleP))
-BGL_Wrap(TexCoord4f, void, (GLfloat, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(TexCoord4fv, void, (GLfloatP))
-BGL_Wrap(TexCoord4i, void, (GLint, GLint, GLint, GLint))
-BGL_Wrap(TexCoord4iv, void, (GLintP))
-BGL_Wrap(TexCoord4s, void, (GLshort, GLshort, GLshort, GLshort))
-BGL_Wrap(TexCoord4sv, void, (GLshortP))
-BGL_Wrap(TexEnvf, void, (GLenum, GLenum, GLfloat))
-BGL_Wrap(TexEnvfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(TexEnvi, void, (GLenum, GLenum, GLint))
-BGL_Wrap(TexEnviv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(TexGend, void, (GLenum, GLenum, GLdouble))
-BGL_Wrap(TexGendv, void, (GLenum, GLenum, GLdoubleP))
-BGL_Wrap(TexGenf, void, (GLenum, GLenum, GLfloat))
-BGL_Wrap(TexGenfv, void, (GLenum, GLenum, GLfloatP))
-BGL_Wrap(TexGeni, void, (GLenum, GLenum, GLint))
-BGL_Wrap(TexGeniv, void, (GLenum, GLenum, GLintP))
BGL_Wrap(TexImage1D, void, (GLenum, GLint, GLint, GLsizei, GLint, GLenum, GLenum, GLvoidP))
BGL_Wrap(TexImage2D, void, (GLenum, GLint, GLint, GLsizei, GLsizei, GLint, GLenum, GLenum, GLvoidP))
BGL_Wrap(TexParameterf, void, (GLenum, GLenum, GLfloat))
BGL_Wrap(TexParameterfv, void, (GLenum, GLenum, GLfloatP))
BGL_Wrap(TexParameteri, void, (GLenum, GLenum, GLint))
BGL_Wrap(TexParameteriv, void, (GLenum, GLenum, GLintP))
-BGL_Wrap(Translated, void, (GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Translatef, void, (GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Vertex2d, void, (GLdouble, GLdouble))
-BGL_Wrap(Vertex2dv, void, (GLdoubleP))
-BGL_Wrap(Vertex2f, void, (GLfloat, GLfloat))
-BGL_Wrap(Vertex2fv, void, (GLfloatP))
-BGL_Wrap(Vertex2i, void, (GLint, GLint))
-BGL_Wrap(Vertex2iv, void, (GLintP))
-BGL_Wrap(Vertex2s, void, (GLshort, GLshort))
-BGL_Wrap(Vertex2sv, void, (GLshortP))
-BGL_Wrap(Vertex3d, void, (GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Vertex3dv, void, (GLdoubleP))
-BGL_Wrap(Vertex3f, void, (GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Vertex3fv, void, (GLfloatP))
-BGL_Wrap(Vertex3i, void, (GLint, GLint, GLint))
-BGL_Wrap(Vertex3iv, void, (GLintP))
-BGL_Wrap(Vertex3s, void, (GLshort, GLshort, GLshort))
-BGL_Wrap(Vertex3sv, void, (GLshortP))
-BGL_Wrap(Vertex4d, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(Vertex4dv, void, (GLdoubleP))
-BGL_Wrap(Vertex4f, void, (GLfloat, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(Vertex4fv, void, (GLfloatP))
-BGL_Wrap(Vertex4i, void, (GLint, GLint, GLint, GLint))
-BGL_Wrap(Vertex4iv, void, (GLintP))
-BGL_Wrap(Vertex4s, void, (GLshort, GLshort, GLshort, GLshort))
-BGL_Wrap(Vertex4sv, void, (GLshortP))
BGL_Wrap(Viewport, void, (GLint, GLint, GLsizei, GLsizei))
/* GL_VERSION_1_1 */
-BGL_Wrap(AreTexturesResident, GLboolean, (GLsizei, GLuintP, GLbooleanP))
-BGL_Wrap(ArrayElement, void, (GLint))
BGL_Wrap(BindTexture, void, (GLenum, GLuint))
-BGL_Wrap(ColorPointer, void, (GLint, GLenum, GLsizei, GLvoidP))
BGL_Wrap(CopyTexImage1D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLint))
BGL_Wrap(CopyTexImage2D, void, (GLenum, GLint, GLenum, GLint, GLint, GLsizei, GLsizei, GLint))
BGL_Wrap(CopyTexSubImage1D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei))
BGL_Wrap(CopyTexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLint, GLint, GLsizei, GLsizei))
BGL_Wrap(DeleteTextures, void, (GLsizei, GLuintP))
-BGL_Wrap(DisableClientState, void, (GLenum))
BGL_Wrap(DrawArrays, void, (GLenum, GLint, GLsizei))
BGL_Wrap(DrawElements, void, (GLenum, GLsizei, GLenum, GLvoidP))
-BGL_Wrap(EdgeFlagPointer, void, (GLsizei, GLvoidP))
-BGL_Wrap(EnableClientState, void, (GLenum))
BGL_Wrap(GenTextures, void, (GLsizei, GLuintP))
-BGL_Wrap(GetPointerv, void, (GLenum, GLvoidP))
-BGL_Wrap(IndexPointer, void, (GLenum, GLsizei, GLvoidP))
-BGL_Wrap(Indexub, void, (GLubyte))
-BGL_Wrap(Indexubv, void, (GLubyteP))
-BGL_Wrap(InterleavedArrays, void, (GLenum, GLsizei, GLvoidP))
BGL_Wrap(IsTexture, GLboolean, (GLuint))
-BGL_Wrap(NormalPointer, void, (GLenum, GLsizei, GLvoidP))
BGL_Wrap(PolygonOffset, void, (GLfloat, GLfloat))
-BGL_Wrap(PopClientAttrib, void, (void))
-BGL_Wrap(PrioritizeTextures, void, (GLsizei, GLuintP, GLfloatP))
-BGL_Wrap(PushClientAttrib, void, (GLbitfield))
-BGL_Wrap(TexCoordPointer, void, (GLint, GLenum, GLsizei, GLvoidP))
BGL_Wrap(TexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, GLenum, GLenum, GLvoidP))
BGL_Wrap(TexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLenum, GLvoidP))
-BGL_Wrap(VertexPointer, void, (GLint, GLenum, GLsizei, GLvoidP))
/* GL_VERSION_1_2 */
@@ -1436,7 +1153,6 @@ BGL_Wrap(TexSubImage3D, void, (GLenum, GLint, GLint, GLint, GLi
/* GL_VERSION_1_3 */
BGL_Wrap(ActiveTexture, void, (GLenum))
-BGL_Wrap(ClientActiveTexture, void, (GLenum))
BGL_Wrap(CompressedTexImage1D, void, (GLenum, GLint, GLenum, GLsizei, GLint, GLsizei, GLvoidP))
BGL_Wrap(CompressedTexImage2D, void, (GLenum, GLint, GLenum, GLsizei, GLsizei, GLint, GLsizei, GLvoidP))
BGL_Wrap(CompressedTexImage3D, void, (GLenum, GLint, GLenum, GLsizei, GLsizei, GLsizei, GLint, GLsizei, GLvoidP))
@@ -1444,42 +1160,6 @@ BGL_Wrap(CompressedTexSubImage1D, void, (GLenum, GLint, GLint, GLsizei, G
BGL_Wrap(CompressedTexSubImage2D, void, (GLenum, GLint, GLint, GLint, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP))
BGL_Wrap(CompressedTexSubImage3D, void, (GLenum, GLint, GLint, GLint, GLint, GLsizei, GLsizei, GLsizei, GLenum, GLsizei, GLvoidP))
BGL_Wrap(GetCompressedTexImage, void, (GLenum, GLint, GLvoidP))
-BGL_Wrap(LoadTransposeMatrixd, void, (GLdoubleP))
-BGL_Wrap(LoadTransposeMatrixf, void, (GLfloatP))
-BGL_Wrap(MultTransposeMatrixd, void, (GLdoubleP))
-BGL_Wrap(MultTransposeMatrixf, void, (GLfloatP))
-BGL_Wrap(MultiTexCoord1d, void, (GLenum, GLdouble))
-BGL_Wrap(MultiTexCoord1dv, void, (GLenum, GLdoubleP))
-BGL_Wrap(MultiTexCoord1f, void, (GLenum, GLfloat))
-BGL_Wrap(MultiTexCoord1fv, void, (GLenum, GLfloatP))
-BGL_Wrap(MultiTexCoord1i, void, (GLenum, GLint))
-BGL_Wrap(MultiTexCoord1iv, void, (GLenum, GLintP))
-BGL_Wrap(MultiTexCoord1s, void, (GLenum, GLshort))
-BGL_Wrap(MultiTexCoord1sv, void, (GLenum, GLshortP))
-BGL_Wrap(MultiTexCoord2d, void, (GLenum, GLdouble, GLdouble))
-BGL_Wrap(MultiTexCoord2dv, void, (GLenum, GLdoubleP))
-BGL_Wrap(MultiTexCoord2f, void, (GLenum, GLfloat, GLfloat))
-BGL_Wrap(MultiTexCoord2fv, void, (GLenum, GLfloatP))
-BGL_Wrap(MultiTexCoord2i, void, (GLenum, GLint, GLint))
-BGL_Wrap(MultiTexCoord2iv, void, (GLenum, GLintP))
-BGL_Wrap(MultiTexCoord2s, void, (GLenum, GLshort, GLshort))
-BGL_Wrap(MultiTexCoord2sv, void, (GLenum, GLshortP))
-BGL_Wrap(MultiTexCoord3d, void, (GLenum, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(MultiTexCoord3dv, void, (GLenum, GLdoubleP))
-BGL_Wrap(MultiTexCoord3f, void, (GLenum, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(MultiTexCoord3fv, void, (GLenum, GLfloatP))
-BGL_Wrap(MultiTexCoord3i, void, (GLenum, GLint, GLint, GLint))
-BGL_Wrap(MultiTexCoord3iv, void, (GLenum, GLintP))
-BGL_Wrap(MultiTexCoord3s, void, (GLenum, GLshort, GLshort, GLshort))
-BGL_Wrap(MultiTexCoord3sv, void, (GLenum, GLshortP))
-BGL_Wrap(MultiTexCoord4d, void, (GLenum, GLdouble, GLdouble, GLdouble, GLdouble))
-BGL_Wrap(MultiTexCoord4dv, void, (GLenum, GLdoubleP))
-BGL_Wrap(MultiTexCoord4f, void, (GLenum, GLfloat, GLfloat, GLfloat, GLfloat))
-BGL_Wrap(MultiTexCoord4fv, void, (GLenum, GLfloatP))
-BGL_Wrap(MultiTexCoord4i, void, (GLenum, GLint, GLint, GLint, GLint))
-BGL_Wrap(MultiTexCoord4iv, void, (GLenum, GLintP))
-BGL_Wrap(MultiTexCoord4s, void, (GLenum, GLshort, GLshort, GLshort, GLshort))
-BGL_Wrap(MultiTexCoord4sv, void, (GLenum, GLshortP))
BGL_Wrap(SampleCoverage, void, (GLfloat, GLboolean))
@@ -1615,10 +1295,20 @@ BGL_Wrap(UniformMatrix4x3fv, void, (GLint, GLsizei, GLboolean, GLflo
/* GL_VERSION_3_0 */
+BGL_Wrap(BindFramebuffer, void, (GLenum, GLuint))
+BGL_Wrap(BindRenderbuffer, void, (GLenum, GLuint))
BGL_Wrap(BindVertexArray, void, (GLuint))
+BGL_Wrap(CheckFramebufferStatus, GLenum, (GLenum))
+BGL_Wrap(DeleteFramebuffers, void, (GLsizei, GLuintP))
+BGL_Wrap(DeleteRenderbuffers, void, (GLsizei, GLuintP))
BGL_Wrap(DeleteVertexArrays, void, (GLsizei, GLuintP))
+BGL_Wrap(FramebufferRenderbuffer, void, (GLenum, GLenum, GLenum, GLuint))
+BGL_Wrap(GenFramebuffers, void, (GLsizei, GLuintP))
+BGL_Wrap(GenRenderbuffers, void, (GLsizei, GLuintP))
BGL_Wrap(GenVertexArrays, void, (GLsizei, GLuintP))
+BGL_Wrap(GetStringi, GLstring, (GLenum, GLuint))
BGL_Wrap(IsVertexArray, GLboolean, (GLuint))
+BGL_Wrap(RenderbufferStorage, void, (GLenum, GLenum, GLsizei, GLsizei))
/* GL_VERSION_3_1 */
@@ -1645,44 +1335,7 @@ BGL_Wrap(TexImage3DMultisample, void, (GLenum, GLsizei, GLenum, GLsizei
/* GL_VERSION_3_3 */
-BGL_Wrap(ColorP3ui, void, (GLenum, GLuint))
-BGL_Wrap(ColorP3uiv, void, (GLenum, GLuintP))
-BGL_Wrap(ColorP4ui, void, (GLenum, GLuint))
-BGL_Wrap(ColorP4uiv, void, (GLenum, GLuintP))
-BGL_Wrap(MultiTexCoordP1ui, void, (GLenum, GLenum, GLuint))
-BGL_Wrap(MultiTexCoordP1uiv, void, (GLenum, GLenum, GLuintP))
-BGL_Wrap(MultiTexCoordP2ui, void, (GLenum, GLenum, GLuint))
-BGL_Wrap(MultiTexCoordP2uiv, void, (GLenum, GLenum, GLuintP))
-BGL_Wrap(MultiTexCoordP3ui, void, (GLenum, GLenum, GLuint))
-BGL_Wrap(MultiTexCoordP3uiv, void, (GLenum, GLenum, GLuintP))
-BGL_Wrap(MultiTexCoordP4ui, void, (GLenum, GLenum, GLuint))
-BGL_Wrap(MultiTexCoordP4uiv, void, (GLenum, GLenum, GLuintP))
-BGL_Wrap(NormalP3ui, void, (GLenum, GLuint))
-BGL_Wrap(NormalP3uiv, void, (GLenum, GLuintP))
-BGL_Wrap(SecondaryColorP3ui, void, (GLenum, GLuint))
-BGL_Wrap(SecondaryColorP3uiv, void, (GLenum, GLuintP))
-BGL_Wrap(TexCoordP1ui, void, (GLenum, GLuint))
-BGL_Wrap(TexCoordP1uiv, void, (GLenum, GLuintP))
-BGL_Wrap(TexCoordP2ui, void, (GLenum, GLuint))
-BGL_Wrap(TexCoordP2uiv, void, (GLenum, GLuintP))
-BGL_Wrap(TexCoordP3ui, void, (GLenum, GLuint))
-BGL_Wrap(TexCoordP3uiv, void, (GLenum, GLuintP))
-BGL_Wrap(TexCoordP4ui, void, (GLenum, GLuint))
-BGL_Wrap(TexCoordP4uiv, void, (GLenum, GLuintP))
-BGL_Wrap(VertexP2ui, void, (GLenum, GLuint))
-BGL_Wrap(VertexP2uiv, void, (GLenum, GLuintP))
-BGL_Wrap(VertexP3ui, void, (GLenum, GLuint))
-BGL_Wrap(VertexP3uiv, void, (GLenum, GLuintP))
-BGL_Wrap(VertexP4ui, void, (GLenum, GLuint))
-BGL_Wrap(VertexP4uiv, void, (GLenum, GLuintP))
-
-
-BGLU_Wrap(Perspective, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGLU_Wrap(LookAt, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble, GLdouble))
-BGLU_Wrap(Ortho2D, void, (GLdouble, GLdouble, GLdouble, GLdouble))
-BGLU_Wrap(PickMatrix, void, (GLdouble, GLdouble, GLdouble, GLdouble, GLintP))
-BGLU_Wrap(Project, GLint, (GLdouble, GLdouble, GLdouble, GLdoubleP, GLdoubleP, GLintP, GLdoubleP, GLdoubleP, GLdoubleP))
-BGLU_Wrap(UnProject, GLint, (GLdouble, GLdouble, GLdouble, GLdoubleP, GLdoubleP, GLintP, GLdoubleP, GLdoubleP, GLdoubleP))
+/* no new functions besides packed immediate mode (not part of core profile) */
/** \} */
@@ -1692,26 +1345,12 @@ BGLU_Wrap(UnProject, GLint, (GLdouble, GLdouble, GLdouble, GLdouble
/** \name Module Definition
* \{ */
-#define MethodDefu(func) {"glu"#func, Method_##func, METH_VARARGS, NULL}
-
-static struct PyMethodDef BGL_methods[] = {
- MethodDefu(Perspective),
- MethodDefu(LookAt),
- MethodDefu(Ortho2D),
- MethodDefu(PickMatrix),
- MethodDefu(Project),
- MethodDefu(UnProject),
- {NULL, NULL, 0, NULL}
-};
-
-#undef MethodDefu
-
static struct PyModuleDef BGL_module_def = {
PyModuleDef_HEAD_INIT,
"bgl", /* m_name */
NULL, /* m_doc */
0, /* m_size */
- BGL_methods, /* m_methods */
+ NULL, /* m_methods */
NULL, /* m_reload */
NULL, /* m_traverse */
NULL, /* m_clear */
@@ -1745,9 +1384,6 @@ static void py_module_dict_add_method(PyObject *submodule, PyObject *dict, PyMet
}
}
-/* TODO, expose to users */
-static bool use_deprecated = true;
-
PyObject *BPyInit_bgl(void)
{
PyObject *submodule, *dict;
@@ -1822,268 +1458,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(TexParameteriv);
PY_MOD_ADD_METHOD(Viewport);
}
- /* adding in GL_VERSION_1_0 removed from core profile */
- if (use_deprecated == true) {
- PY_MOD_ADD_METHOD(Accum);
- PY_MOD_ADD_METHOD(AlphaFunc);
- PY_MOD_ADD_METHOD(Begin);
- PY_MOD_ADD_METHOD(Bitmap);
- PY_MOD_ADD_METHOD(CallList);
- PY_MOD_ADD_METHOD(CallLists);
- PY_MOD_ADD_METHOD(ClearAccum);
- PY_MOD_ADD_METHOD(ClearIndex);
- PY_MOD_ADD_METHOD(ClipPlane);
- PY_MOD_ADD_METHOD(Color3b);
- PY_MOD_ADD_METHOD(Color3bv);
- PY_MOD_ADD_METHOD(Color3d);
- PY_MOD_ADD_METHOD(Color3dv);
- PY_MOD_ADD_METHOD(Color3f);
- PY_MOD_ADD_METHOD(Color3fv);
- PY_MOD_ADD_METHOD(Color3i);
- PY_MOD_ADD_METHOD(Color3iv);
- PY_MOD_ADD_METHOD(Color3s);
- PY_MOD_ADD_METHOD(Color3sv);
- PY_MOD_ADD_METHOD(Color3ub);
- PY_MOD_ADD_METHOD(Color3ubv);
- PY_MOD_ADD_METHOD(Color3ui);
- PY_MOD_ADD_METHOD(Color3uiv);
- PY_MOD_ADD_METHOD(Color3us);
- PY_MOD_ADD_METHOD(Color3usv);
- PY_MOD_ADD_METHOD(Color4b);
- PY_MOD_ADD_METHOD(Color4bv);
- PY_MOD_ADD_METHOD(Color4d);
- PY_MOD_ADD_METHOD(Color4dv);
- PY_MOD_ADD_METHOD(Color4f);
- PY_MOD_ADD_METHOD(Color4fv);
- PY_MOD_ADD_METHOD(Color4i);
- PY_MOD_ADD_METHOD(Color4iv);
- PY_MOD_ADD_METHOD(Color4s);
- PY_MOD_ADD_METHOD(Color4sv);
- PY_MOD_ADD_METHOD(Color4ub);
- PY_MOD_ADD_METHOD(Color4ubv);
- PY_MOD_ADD_METHOD(Color4ui);
- PY_MOD_ADD_METHOD(Color4uiv);
- PY_MOD_ADD_METHOD(Color4us);
- PY_MOD_ADD_METHOD(Color4usv);
- PY_MOD_ADD_METHOD(ColorMaterial);
- PY_MOD_ADD_METHOD(CopyPixels);
- PY_MOD_ADD_METHOD(DeleteLists);
- PY_MOD_ADD_METHOD(DrawPixels);
- PY_MOD_ADD_METHOD(EdgeFlag);
- PY_MOD_ADD_METHOD(EdgeFlagv);
- PY_MOD_ADD_METHOD(End);
- PY_MOD_ADD_METHOD(EndList);
- PY_MOD_ADD_METHOD(EvalCoord1d);
- PY_MOD_ADD_METHOD(EvalCoord1dv);
- PY_MOD_ADD_METHOD(EvalCoord1f);
- PY_MOD_ADD_METHOD(EvalCoord1fv);
- PY_MOD_ADD_METHOD(EvalCoord2d);
- PY_MOD_ADD_METHOD(EvalCoord2dv);
- PY_MOD_ADD_METHOD(EvalCoord2f);
- PY_MOD_ADD_METHOD(EvalCoord2fv);
- PY_MOD_ADD_METHOD(EvalMesh1);
- PY_MOD_ADD_METHOD(EvalMesh2);
- PY_MOD_ADD_METHOD(EvalPoint1);
- PY_MOD_ADD_METHOD(EvalPoint2);
- PY_MOD_ADD_METHOD(FeedbackBuffer);
- PY_MOD_ADD_METHOD(Fogf);
- PY_MOD_ADD_METHOD(Fogfv);
- PY_MOD_ADD_METHOD(Fogi);
- PY_MOD_ADD_METHOD(Fogiv);
- PY_MOD_ADD_METHOD(Frustum);
- PY_MOD_ADD_METHOD(GenLists);
- PY_MOD_ADD_METHOD(GetClipPlane);
- PY_MOD_ADD_METHOD(GetLightfv);
- PY_MOD_ADD_METHOD(GetLightiv);
- PY_MOD_ADD_METHOD(GetMapdv);
- PY_MOD_ADD_METHOD(GetMapfv);
- PY_MOD_ADD_METHOD(GetMapiv);
- PY_MOD_ADD_METHOD(GetMaterialfv);
- PY_MOD_ADD_METHOD(GetMaterialiv);
- PY_MOD_ADD_METHOD(GetPixelMapfv);
- PY_MOD_ADD_METHOD(GetPixelMapuiv);
- PY_MOD_ADD_METHOD(GetPixelMapusv);
- PY_MOD_ADD_METHOD(GetPolygonStipple);
- PY_MOD_ADD_METHOD(GetTexEnvfv);
- PY_MOD_ADD_METHOD(GetTexEnviv);
- PY_MOD_ADD_METHOD(GetTexGendv);
- PY_MOD_ADD_METHOD(GetTexGenfv);
- PY_MOD_ADD_METHOD(GetTexGeniv);
- PY_MOD_ADD_METHOD(IndexMask);
- PY_MOD_ADD_METHOD(Indexd);
- PY_MOD_ADD_METHOD(Indexdv);
- PY_MOD_ADD_METHOD(Indexf);
- PY_MOD_ADD_METHOD(Indexfv);
- PY_MOD_ADD_METHOD(Indexi);
- PY_MOD_ADD_METHOD(Indexiv);
- PY_MOD_ADD_METHOD(Indexs);
- PY_MOD_ADD_METHOD(Indexsv);
- PY_MOD_ADD_METHOD(InitNames);
- PY_MOD_ADD_METHOD(IsList);
- PY_MOD_ADD_METHOD(LightModelf);
- PY_MOD_ADD_METHOD(LightModelfv);
- PY_MOD_ADD_METHOD(LightModeli);
- PY_MOD_ADD_METHOD(LightModeliv);
- PY_MOD_ADD_METHOD(Lightf);
- PY_MOD_ADD_METHOD(Lightfv);
- PY_MOD_ADD_METHOD(Lighti);
- PY_MOD_ADD_METHOD(Lightiv);
- PY_MOD_ADD_METHOD(LineStipple);
- PY_MOD_ADD_METHOD(ListBase);
- PY_MOD_ADD_METHOD(LoadIdentity);
- PY_MOD_ADD_METHOD(LoadMatrixd);
- PY_MOD_ADD_METHOD(LoadMatrixf);
- PY_MOD_ADD_METHOD(LoadName);
- PY_MOD_ADD_METHOD(Map1d);
- PY_MOD_ADD_METHOD(Map1f);
- PY_MOD_ADD_METHOD(Map2d);
- PY_MOD_ADD_METHOD(Map2f);
- PY_MOD_ADD_METHOD(MapGrid1d);
- PY_MOD_ADD_METHOD(MapGrid1f);
- PY_MOD_ADD_METHOD(MapGrid2d);
- PY_MOD_ADD_METHOD(MapGrid2f);
- PY_MOD_ADD_METHOD(Materialf);
- PY_MOD_ADD_METHOD(Materialfv);
- PY_MOD_ADD_METHOD(Materiali);
- PY_MOD_ADD_METHOD(Materialiv);
- PY_MOD_ADD_METHOD(MatrixMode);
- PY_MOD_ADD_METHOD(MultMatrixd);
- PY_MOD_ADD_METHOD(MultMatrixf);
- PY_MOD_ADD_METHOD(NewList);
- PY_MOD_ADD_METHOD(Normal3b);
- PY_MOD_ADD_METHOD(Normal3bv);
- PY_MOD_ADD_METHOD(Normal3d);
- PY_MOD_ADD_METHOD(Normal3dv);
- PY_MOD_ADD_METHOD(Normal3f);
- PY_MOD_ADD_METHOD(Normal3fv);
- PY_MOD_ADD_METHOD(Normal3i);
- PY_MOD_ADD_METHOD(Normal3iv);
- PY_MOD_ADD_METHOD(Normal3s);
- PY_MOD_ADD_METHOD(Normal3sv);
- PY_MOD_ADD_METHOD(Ortho);
- PY_MOD_ADD_METHOD(PassThrough);
- PY_MOD_ADD_METHOD(PixelMapfv);
- PY_MOD_ADD_METHOD(PixelMapuiv);
- PY_MOD_ADD_METHOD(PixelMapusv);
- PY_MOD_ADD_METHOD(PixelTransferf);
- PY_MOD_ADD_METHOD(PixelTransferi);
- PY_MOD_ADD_METHOD(PixelZoom);
- PY_MOD_ADD_METHOD(PolygonStipple);
- PY_MOD_ADD_METHOD(PopAttrib);
- PY_MOD_ADD_METHOD(PopMatrix);
- PY_MOD_ADD_METHOD(PopName);
- PY_MOD_ADD_METHOD(PushAttrib);
- PY_MOD_ADD_METHOD(PushMatrix);
- PY_MOD_ADD_METHOD(PushName);
- PY_MOD_ADD_METHOD(RasterPos2d);
- PY_MOD_ADD_METHOD(RasterPos2dv);
- PY_MOD_ADD_METHOD(RasterPos2f);
- PY_MOD_ADD_METHOD(RasterPos2fv);
- PY_MOD_ADD_METHOD(RasterPos2i);
- PY_MOD_ADD_METHOD(RasterPos2iv);
- PY_MOD_ADD_METHOD(RasterPos2s);
- PY_MOD_ADD_METHOD(RasterPos2sv);
- PY_MOD_ADD_METHOD(RasterPos3d);
- PY_MOD_ADD_METHOD(RasterPos3dv);
- PY_MOD_ADD_METHOD(RasterPos3f);
- PY_MOD_ADD_METHOD(RasterPos3fv);
- PY_MOD_ADD_METHOD(RasterPos3i);
- PY_MOD_ADD_METHOD(RasterPos3iv);
- PY_MOD_ADD_METHOD(RasterPos3s);
- PY_MOD_ADD_METHOD(RasterPos3sv);
- PY_MOD_ADD_METHOD(RasterPos4d);
- PY_MOD_ADD_METHOD(RasterPos4dv);
- PY_MOD_ADD_METHOD(RasterPos4f);
- PY_MOD_ADD_METHOD(RasterPos4fv);
- PY_MOD_ADD_METHOD(RasterPos4i);
- PY_MOD_ADD_METHOD(RasterPos4iv);
- PY_MOD_ADD_METHOD(RasterPos4s);
- PY_MOD_ADD_METHOD(RasterPos4sv);
- PY_MOD_ADD_METHOD(Rectd);
- PY_MOD_ADD_METHOD(Rectdv);
- PY_MOD_ADD_METHOD(Rectf);
- PY_MOD_ADD_METHOD(Rectfv);
- PY_MOD_ADD_METHOD(Recti);
- PY_MOD_ADD_METHOD(Rectiv);
- PY_MOD_ADD_METHOD(Rects);
- PY_MOD_ADD_METHOD(Rectsv);
- PY_MOD_ADD_METHOD(RenderMode);
- PY_MOD_ADD_METHOD(Rotated);
- PY_MOD_ADD_METHOD(Rotatef);
- PY_MOD_ADD_METHOD(Scaled);
- PY_MOD_ADD_METHOD(Scalef);
- PY_MOD_ADD_METHOD(SelectBuffer);
- PY_MOD_ADD_METHOD(ShadeModel);
- PY_MOD_ADD_METHOD(TexCoord1d);
- PY_MOD_ADD_METHOD(TexCoord1dv);
- PY_MOD_ADD_METHOD(TexCoord1f);
- PY_MOD_ADD_METHOD(TexCoord1fv);
- PY_MOD_ADD_METHOD(TexCoord1i);
- PY_MOD_ADD_METHOD(TexCoord1iv);
- PY_MOD_ADD_METHOD(TexCoord1s);
- PY_MOD_ADD_METHOD(TexCoord1sv);
- PY_MOD_ADD_METHOD(TexCoord2d);
- PY_MOD_ADD_METHOD(TexCoord2dv);
- PY_MOD_ADD_METHOD(TexCoord2f);
- PY_MOD_ADD_METHOD(TexCoord2fv);
- PY_MOD_ADD_METHOD(TexCoord2i);
- PY_MOD_ADD_METHOD(TexCoord2iv);
- PY_MOD_ADD_METHOD(TexCoord2s);
- PY_MOD_ADD_METHOD(TexCoord2sv);
- PY_MOD_ADD_METHOD(TexCoord3d);
- PY_MOD_ADD_METHOD(TexCoord3dv);
- PY_MOD_ADD_METHOD(TexCoord3f);
- PY_MOD_ADD_METHOD(TexCoord3fv);
- PY_MOD_ADD_METHOD(TexCoord3i);
- PY_MOD_ADD_METHOD(TexCoord3iv);
- PY_MOD_ADD_METHOD(TexCoord3s);
- PY_MOD_ADD_METHOD(TexCoord3sv);
- PY_MOD_ADD_METHOD(TexCoord4d);
- PY_MOD_ADD_METHOD(TexCoord4dv);
- PY_MOD_ADD_METHOD(TexCoord4f);
- PY_MOD_ADD_METHOD(TexCoord4fv);
- PY_MOD_ADD_METHOD(TexCoord4i);
- PY_MOD_ADD_METHOD(TexCoord4iv);
- PY_MOD_ADD_METHOD(TexCoord4s);
- PY_MOD_ADD_METHOD(TexCoord4sv);
- PY_MOD_ADD_METHOD(TexEnvf);
- PY_MOD_ADD_METHOD(TexEnvfv);
- PY_MOD_ADD_METHOD(TexEnvi);
- PY_MOD_ADD_METHOD(TexEnviv);
- PY_MOD_ADD_METHOD(TexGend);
- PY_MOD_ADD_METHOD(TexGendv);
- PY_MOD_ADD_METHOD(TexGenf);
- PY_MOD_ADD_METHOD(TexGenfv);
- PY_MOD_ADD_METHOD(TexGeni);
- PY_MOD_ADD_METHOD(TexGeniv);
- PY_MOD_ADD_METHOD(Translated);
- PY_MOD_ADD_METHOD(Translatef);
- PY_MOD_ADD_METHOD(Vertex2d);
- PY_MOD_ADD_METHOD(Vertex2dv);
- PY_MOD_ADD_METHOD(Vertex2f);
- PY_MOD_ADD_METHOD(Vertex2fv);
- PY_MOD_ADD_METHOD(Vertex2i);
- PY_MOD_ADD_METHOD(Vertex2iv);
- PY_MOD_ADD_METHOD(Vertex2s);
- PY_MOD_ADD_METHOD(Vertex2sv);
- PY_MOD_ADD_METHOD(Vertex3d);
- PY_MOD_ADD_METHOD(Vertex3dv);
- PY_MOD_ADD_METHOD(Vertex3f);
- PY_MOD_ADD_METHOD(Vertex3fv);
- PY_MOD_ADD_METHOD(Vertex3i);
- PY_MOD_ADD_METHOD(Vertex3iv);
- PY_MOD_ADD_METHOD(Vertex3s);
- PY_MOD_ADD_METHOD(Vertex3sv);
- PY_MOD_ADD_METHOD(Vertex4d);
- PY_MOD_ADD_METHOD(Vertex4dv);
- PY_MOD_ADD_METHOD(Vertex4f);
- PY_MOD_ADD_METHOD(Vertex4fv);
- PY_MOD_ADD_METHOD(Vertex4i);
- PY_MOD_ADD_METHOD(Vertex4iv);
- PY_MOD_ADD_METHOD(Vertex4s);
- PY_MOD_ADD_METHOD(Vertex4sv);
- }
-
/* GL_VERSION_1_1 */
{
@@ -2101,27 +1475,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(TexSubImage1D);
PY_MOD_ADD_METHOD(TexSubImage2D);
}
- /* adding in GL_VERSION_1_1 removed from core profile */
- if (use_deprecated == true) {
- PY_MOD_ADD_METHOD(AreTexturesResident);
- PY_MOD_ADD_METHOD(ArrayElement);
- PY_MOD_ADD_METHOD(ColorPointer);
- PY_MOD_ADD_METHOD(DisableClientState);
- PY_MOD_ADD_METHOD(EdgeFlagPointer);
- PY_MOD_ADD_METHOD(EnableClientState);
- PY_MOD_ADD_METHOD(GetPointerv);
- PY_MOD_ADD_METHOD(IndexPointer);
- PY_MOD_ADD_METHOD(Indexub);
- PY_MOD_ADD_METHOD(Indexubv);
- PY_MOD_ADD_METHOD(InterleavedArrays);
- PY_MOD_ADD_METHOD(NormalPointer);
- PY_MOD_ADD_METHOD(PopClientAttrib);
- PY_MOD_ADD_METHOD(PrioritizeTextures);
- PY_MOD_ADD_METHOD(PushClientAttrib);
- PY_MOD_ADD_METHOD(TexCoordPointer);
- PY_MOD_ADD_METHOD(VertexPointer);
- }
-
/* GL_VERSION_1_2 */
{
@@ -2131,7 +1484,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(TexSubImage3D);
}
-
/* GL_VERSION_1_3 */
{
PY_MOD_ADD_METHOD(ActiveTexture);
@@ -2144,47 +1496,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(GetCompressedTexImage);
PY_MOD_ADD_METHOD(SampleCoverage);
}
- /* adding in GL_VERSION_1_3 removed from core profile */
- if (use_deprecated == true) {
- PY_MOD_ADD_METHOD(ClientActiveTexture);
- PY_MOD_ADD_METHOD(LoadTransposeMatrixd);
- PY_MOD_ADD_METHOD(LoadTransposeMatrixf);
- PY_MOD_ADD_METHOD(MultTransposeMatrixd);
- PY_MOD_ADD_METHOD(MultTransposeMatrixf);
- PY_MOD_ADD_METHOD(MultiTexCoord1d);
- PY_MOD_ADD_METHOD(MultiTexCoord1dv);
- PY_MOD_ADD_METHOD(MultiTexCoord1f);
- PY_MOD_ADD_METHOD(MultiTexCoord1fv);
- PY_MOD_ADD_METHOD(MultiTexCoord1i);
- PY_MOD_ADD_METHOD(MultiTexCoord1iv);
- PY_MOD_ADD_METHOD(MultiTexCoord1s);
- PY_MOD_ADD_METHOD(MultiTexCoord1sv);
- PY_MOD_ADD_METHOD(MultiTexCoord2d);
- PY_MOD_ADD_METHOD(MultiTexCoord2dv);
- PY_MOD_ADD_METHOD(MultiTexCoord2f);
- PY_MOD_ADD_METHOD(MultiTexCoord2fv);
- PY_MOD_ADD_METHOD(MultiTexCoord2i);
- PY_MOD_ADD_METHOD(MultiTexCoord2iv);
- PY_MOD_ADD_METHOD(MultiTexCoord2s);
- PY_MOD_ADD_METHOD(MultiTexCoord2sv);
- PY_MOD_ADD_METHOD(MultiTexCoord3d);
- PY_MOD_ADD_METHOD(MultiTexCoord3dv);
- PY_MOD_ADD_METHOD(MultiTexCoord3f);
- PY_MOD_ADD_METHOD(MultiTexCoord3fv);
- PY_MOD_ADD_METHOD(MultiTexCoord3i);
- PY_MOD_ADD_METHOD(MultiTexCoord3iv);
- PY_MOD_ADD_METHOD(MultiTexCoord3s);
- PY_MOD_ADD_METHOD(MultiTexCoord3sv);
- PY_MOD_ADD_METHOD(MultiTexCoord4d);
- PY_MOD_ADD_METHOD(MultiTexCoord4dv);
- PY_MOD_ADD_METHOD(MultiTexCoord4f);
- PY_MOD_ADD_METHOD(MultiTexCoord4fv);
- PY_MOD_ADD_METHOD(MultiTexCoord4i);
- PY_MOD_ADD_METHOD(MultiTexCoord4iv);
- PY_MOD_ADD_METHOD(MultiTexCoord4s);
- PY_MOD_ADD_METHOD(MultiTexCoord4sv);
- }
-
/* GL_VERSION_1_4 */
{
@@ -2192,7 +1503,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(BlendEquation);
}
-
/* GL_VERSION_1_5 */
{
PY_MOD_ADD_METHOD(BeginQuery);
@@ -2216,7 +1526,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(UnmapBuffer);
}
-
/* GL_VERSION_2_0 */
{
PY_MOD_ADD_METHOD(AttachShader);
@@ -2314,7 +1623,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(VertexAttribPointer);
}
-
/* GL_VERSION_2_1 */
{
PY_MOD_ADD_METHOD(UniformMatrix2x3fv);
@@ -2325,16 +1633,24 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(UniformMatrix4x3fv);
}
-
/* GL_VERSION_3_0 */
{
+ PY_MOD_ADD_METHOD(BindFramebuffer);
+ PY_MOD_ADD_METHOD(BindRenderbuffer);
PY_MOD_ADD_METHOD(BindVertexArray);
+ PY_MOD_ADD_METHOD(CheckFramebufferStatus);
+ PY_MOD_ADD_METHOD(DeleteFramebuffers);
+ PY_MOD_ADD_METHOD(DeleteRenderbuffers);
PY_MOD_ADD_METHOD(DeleteVertexArrays);
+ PY_MOD_ADD_METHOD(FramebufferRenderbuffer);
+ PY_MOD_ADD_METHOD(GenFramebuffers);
+ PY_MOD_ADD_METHOD(GenRenderbuffers);
PY_MOD_ADD_METHOD(GenVertexArrays);
+ PY_MOD_ADD_METHOD(GetStringi);
PY_MOD_ADD_METHOD(IsVertexArray);
+ PY_MOD_ADD_METHOD(RenderbufferStorage);
}
-
/* GL_VERSION_3_1 */
{
PY_MOD_ADD_METHOD(BindBufferBase);
@@ -2349,7 +1665,6 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(UniformBlockBinding);
}
-
/* GL_VERSION_3_2 */
{
PY_MOD_ADD_METHOD(FramebufferTexture);
@@ -2361,39 +1676,8 @@ PyObject *BPyInit_bgl(void)
PY_MOD_ADD_METHOD(TexImage3DMultisample);
}
-
/* GL_VERSION_3_3 */
{
- PY_MOD_ADD_METHOD(ColorP3ui);
- PY_MOD_ADD_METHOD(ColorP3uiv);
- PY_MOD_ADD_METHOD(ColorP4ui);
- PY_MOD_ADD_METHOD(ColorP4uiv);
- PY_MOD_ADD_METHOD(MultiTexCoordP1ui);
- PY_MOD_ADD_METHOD(MultiTexCoordP1uiv);
- PY_MOD_ADD_METHOD(MultiTexCoordP2ui);
- PY_MOD_ADD_METHOD(MultiTexCoordP2uiv);
- PY_MOD_ADD_METHOD(MultiTexCoordP3ui);
- PY_MOD_ADD_METHOD(MultiTexCoordP3uiv);
- PY_MOD_ADD_METHOD(MultiTexCoordP4ui);
- PY_MOD_ADD_METHOD(MultiTexCoordP4uiv);
- PY_MOD_ADD_METHOD(NormalP3ui);
- PY_MOD_ADD_METHOD(NormalP3uiv);
- PY_MOD_ADD_METHOD(SecondaryColorP3ui);
- PY_MOD_ADD_METHOD(SecondaryColorP3uiv);
- PY_MOD_ADD_METHOD(TexCoordP1ui);
- PY_MOD_ADD_METHOD(TexCoordP1uiv);
- PY_MOD_ADD_METHOD(TexCoordP2ui);
- PY_MOD_ADD_METHOD(TexCoordP2uiv);
- PY_MOD_ADD_METHOD(TexCoordP3ui);
- PY_MOD_ADD_METHOD(TexCoordP3uiv);
- PY_MOD_ADD_METHOD(TexCoordP4ui);
- PY_MOD_ADD_METHOD(TexCoordP4uiv);
- PY_MOD_ADD_METHOD(VertexP2ui);
- PY_MOD_ADD_METHOD(VertexP2uiv);
- PY_MOD_ADD_METHOD(VertexP3ui);
- PY_MOD_ADD_METHOD(VertexP3uiv);
- PY_MOD_ADD_METHOD(VertexP4ui);
- PY_MOD_ADD_METHOD(VertexP4uiv);
}
#define PY_DICT_ADD_INT(x) py_module_dict_add_int(dict, #x, x)
@@ -2511,8 +1795,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_POINT);
PY_DICT_ADD_INT(GL_POINTS);
PY_DICT_ADD_INT(GL_POINT_SIZE);
- PY_DICT_ADD_INT(GL_POINT_SIZE_GRANULARITY);
- PY_DICT_ADD_INT(GL_POINT_SIZE_RANGE);
PY_DICT_ADD_INT(GL_POLYGON_MODE);
PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FACTOR);
PY_DICT_ADD_INT(GL_POLYGON_OFFSET_FILL);
@@ -2602,338 +1884,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_XOR);
PY_DICT_ADD_INT(GL_ZERO);
}
- /* adding in GL_VERSION_1_1 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_2D);
- PY_DICT_ADD_INT(GL_2_BYTES);
- PY_DICT_ADD_INT(GL_3D);
- PY_DICT_ADD_INT(GL_3D_COLOR);
- PY_DICT_ADD_INT(GL_3D_COLOR_TEXTURE);
- PY_DICT_ADD_INT(GL_3_BYTES);
- PY_DICT_ADD_INT(GL_4D_COLOR_TEXTURE);
- PY_DICT_ADD_INT(GL_4_BYTES);
- PY_DICT_ADD_INT(GL_ACCUM);
- PY_DICT_ADD_INT(GL_ACCUM_ALPHA_BITS);
- PY_DICT_ADD_INT(GL_ACCUM_BLUE_BITS);
- PY_DICT_ADD_INT(GL_ACCUM_BUFFER_BIT);
- PY_DICT_ADD_INT(GL_ACCUM_CLEAR_VALUE);
- PY_DICT_ADD_INT(GL_ACCUM_GREEN_BITS);
- PY_DICT_ADD_INT(GL_ACCUM_RED_BITS);
- PY_DICT_ADD_INT(GL_ADD);
- PY_DICT_ADD_INT(GL_ALL_ATTRIB_BITS);
- PY_DICT_ADD_INT(GL_ALPHA12);
- PY_DICT_ADD_INT(GL_ALPHA16);
- PY_DICT_ADD_INT(GL_ALPHA4);
- PY_DICT_ADD_INT(GL_ALPHA8);
- PY_DICT_ADD_INT(GL_ALPHA_BIAS);
- PY_DICT_ADD_INT(GL_ALPHA_BITS);
- PY_DICT_ADD_INT(GL_ALPHA_SCALE);
- PY_DICT_ADD_INT(GL_ALPHA_TEST);
- PY_DICT_ADD_INT(GL_ALPHA_TEST_FUNC);
- PY_DICT_ADD_INT(GL_ALPHA_TEST_REF);
- PY_DICT_ADD_INT(GL_AMBIENT);
- PY_DICT_ADD_INT(GL_AMBIENT_AND_DIFFUSE);
- PY_DICT_ADD_INT(GL_ATTRIB_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_AUTO_NORMAL);
- PY_DICT_ADD_INT(GL_AUX0);
- PY_DICT_ADD_INT(GL_AUX1);
- PY_DICT_ADD_INT(GL_AUX2);
- PY_DICT_ADD_INT(GL_AUX3);
- PY_DICT_ADD_INT(GL_AUX_BUFFERS);
- PY_DICT_ADD_INT(GL_BITMAP);
- PY_DICT_ADD_INT(GL_BITMAP_TOKEN);
- PY_DICT_ADD_INT(GL_BLUE_BIAS);
- PY_DICT_ADD_INT(GL_BLUE_BITS);
- PY_DICT_ADD_INT(GL_BLUE_SCALE);
- PY_DICT_ADD_INT(GL_C3F_V3F);
- PY_DICT_ADD_INT(GL_C4F_N3F_V3F);
- PY_DICT_ADD_INT(GL_C4UB_V2F);
- PY_DICT_ADD_INT(GL_C4UB_V3F);
- PY_DICT_ADD_INT(GL_CLAMP);
- PY_DICT_ADD_INT(GL_CLIENT_ALL_ATTRIB_BITS);
- PY_DICT_ADD_INT(GL_CLIENT_ATTRIB_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_CLIENT_PIXEL_STORE_BIT);
- PY_DICT_ADD_INT(GL_CLIENT_VERTEX_ARRAY_BIT);
- PY_DICT_ADD_INT(GL_CLIP_PLANE0);
- PY_DICT_ADD_INT(GL_CLIP_PLANE1);
- PY_DICT_ADD_INT(GL_CLIP_PLANE2);
- PY_DICT_ADD_INT(GL_CLIP_PLANE3);
- PY_DICT_ADD_INT(GL_CLIP_PLANE4);
- PY_DICT_ADD_INT(GL_CLIP_PLANE5);
- PY_DICT_ADD_INT(GL_COEFF);
- PY_DICT_ADD_INT(GL_COLOR_ARRAY);
- PY_DICT_ADD_INT(GL_COLOR_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_COLOR_ARRAY_SIZE);
- PY_DICT_ADD_INT(GL_COLOR_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_COLOR_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_COLOR_INDEX);
- PY_DICT_ADD_INT(GL_COLOR_INDEXES);
- PY_DICT_ADD_INT(GL_COLOR_MATERIAL);
- PY_DICT_ADD_INT(GL_COLOR_MATERIAL_FACE);
- PY_DICT_ADD_INT(GL_COLOR_MATERIAL_PARAMETER);
- PY_DICT_ADD_INT(GL_COMPILE);
- PY_DICT_ADD_INT(GL_COMPILE_AND_EXECUTE);
- PY_DICT_ADD_INT(GL_CONSTANT_ATTENUATION);
- PY_DICT_ADD_INT(GL_COPY_PIXEL_TOKEN);
- PY_DICT_ADD_INT(GL_CURRENT_BIT);
- PY_DICT_ADD_INT(GL_CURRENT_COLOR);
- PY_DICT_ADD_INT(GL_CURRENT_INDEX);
- PY_DICT_ADD_INT(GL_CURRENT_NORMAL);
- PY_DICT_ADD_INT(GL_CURRENT_RASTER_COLOR);
- PY_DICT_ADD_INT(GL_CURRENT_RASTER_DISTANCE);
- PY_DICT_ADD_INT(GL_CURRENT_RASTER_INDEX);
- PY_DICT_ADD_INT(GL_CURRENT_RASTER_POSITION);
- PY_DICT_ADD_INT(GL_CURRENT_RASTER_POSITION_VALID);
- PY_DICT_ADD_INT(GL_CURRENT_RASTER_TEXTURE_COORDS);
- PY_DICT_ADD_INT(GL_CURRENT_TEXTURE_COORDS);
- PY_DICT_ADD_INT(GL_DECAL);
- PY_DICT_ADD_INT(GL_DEPTH_BIAS);
- PY_DICT_ADD_INT(GL_DEPTH_BITS);
- PY_DICT_ADD_INT(GL_DEPTH_SCALE);
- PY_DICT_ADD_INT(GL_DIFFUSE);
- PY_DICT_ADD_INT(GL_DOMAIN);
- PY_DICT_ADD_INT(GL_DRAW_PIXEL_TOKEN);
- PY_DICT_ADD_INT(GL_EDGE_FLAG);
- PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY);
- PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_EMISSION);
- PY_DICT_ADD_INT(GL_ENABLE_BIT);
- PY_DICT_ADD_INT(GL_EVAL_BIT);
- PY_DICT_ADD_INT(GL_EXP);
- PY_DICT_ADD_INT(GL_EXP2);
- PY_DICT_ADD_INT(GL_EYE_LINEAR);
- PY_DICT_ADD_INT(GL_EYE_PLANE);
- PY_DICT_ADD_INT(GL_FEEDBACK);
- PY_DICT_ADD_INT(GL_FEEDBACK_BUFFER_POINTER);
- PY_DICT_ADD_INT(GL_FEEDBACK_BUFFER_SIZE);
- PY_DICT_ADD_INT(GL_FEEDBACK_BUFFER_TYPE);
- PY_DICT_ADD_INT(GL_FLAT);
- PY_DICT_ADD_INT(GL_FOG);
- PY_DICT_ADD_INT(GL_FOG_BIT);
- PY_DICT_ADD_INT(GL_FOG_COLOR);
- PY_DICT_ADD_INT(GL_FOG_DENSITY);
- PY_DICT_ADD_INT(GL_FOG_END);
- PY_DICT_ADD_INT(GL_FOG_HINT);
- PY_DICT_ADD_INT(GL_FOG_INDEX);
- PY_DICT_ADD_INT(GL_FOG_MODE);
- PY_DICT_ADD_INT(GL_FOG_START);
- PY_DICT_ADD_INT(GL_GREEN_BIAS);
- PY_DICT_ADD_INT(GL_GREEN_BITS);
- PY_DICT_ADD_INT(GL_GREEN_SCALE);
- PY_DICT_ADD_INT(GL_HINT_BIT);
- PY_DICT_ADD_INT(GL_INDEX_ARRAY);
- PY_DICT_ADD_INT(GL_INDEX_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_INDEX_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_INDEX_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_INDEX_BITS);
- PY_DICT_ADD_INT(GL_INDEX_CLEAR_VALUE);
- PY_DICT_ADD_INT(GL_INDEX_LOGIC_OP);
- PY_DICT_ADD_INT(GL_INDEX_MODE);
- PY_DICT_ADD_INT(GL_INDEX_OFFSET);
- PY_DICT_ADD_INT(GL_INDEX_SHIFT);
- PY_DICT_ADD_INT(GL_INDEX_WRITEMASK);
- PY_DICT_ADD_INT(GL_INTENSITY);
- PY_DICT_ADD_INT(GL_INTENSITY12);
- PY_DICT_ADD_INT(GL_INTENSITY16);
- PY_DICT_ADD_INT(GL_INTENSITY4);
- PY_DICT_ADD_INT(GL_INTENSITY8);
- PY_DICT_ADD_INT(GL_LIGHT0);
- PY_DICT_ADD_INT(GL_LIGHT1);
- PY_DICT_ADD_INT(GL_LIGHT2);
- PY_DICT_ADD_INT(GL_LIGHT3);
- PY_DICT_ADD_INT(GL_LIGHT4);
- PY_DICT_ADD_INT(GL_LIGHT5);
- PY_DICT_ADD_INT(GL_LIGHT6);
- PY_DICT_ADD_INT(GL_LIGHT7);
- PY_DICT_ADD_INT(GL_LIGHTING);
- PY_DICT_ADD_INT(GL_LIGHTING_BIT);
- PY_DICT_ADD_INT(GL_LIGHT_MODEL_AMBIENT);
- PY_DICT_ADD_INT(GL_LIGHT_MODEL_LOCAL_VIEWER);
- PY_DICT_ADD_INT(GL_LIGHT_MODEL_TWO_SIDE);
- PY_DICT_ADD_INT(GL_LINEAR_ATTENUATION);
- PY_DICT_ADD_INT(GL_LINE_BIT);
- PY_DICT_ADD_INT(GL_LINE_RESET_TOKEN);
- PY_DICT_ADD_INT(GL_LINE_STIPPLE);
- PY_DICT_ADD_INT(GL_LINE_STIPPLE_PATTERN);
- PY_DICT_ADD_INT(GL_LINE_STIPPLE_REPEAT);
- PY_DICT_ADD_INT(GL_LINE_TOKEN);
- PY_DICT_ADD_INT(GL_LIST_BASE);
- PY_DICT_ADD_INT(GL_LIST_BIT);
- PY_DICT_ADD_INT(GL_LIST_INDEX);
- PY_DICT_ADD_INT(GL_LIST_MODE);
- PY_DICT_ADD_INT(GL_LOAD);
- PY_DICT_ADD_INT(GL_LOGIC_OP);
- PY_DICT_ADD_INT(GL_LUMINANCE);
- PY_DICT_ADD_INT(GL_LUMINANCE12);
- PY_DICT_ADD_INT(GL_LUMINANCE12_ALPHA12);
- PY_DICT_ADD_INT(GL_LUMINANCE12_ALPHA4);
- PY_DICT_ADD_INT(GL_LUMINANCE16);
- PY_DICT_ADD_INT(GL_LUMINANCE16_ALPHA16);
- PY_DICT_ADD_INT(GL_LUMINANCE4);
- PY_DICT_ADD_INT(GL_LUMINANCE4_ALPHA4);
- PY_DICT_ADD_INT(GL_LUMINANCE6_ALPHA2);
- PY_DICT_ADD_INT(GL_LUMINANCE8);
- PY_DICT_ADD_INT(GL_LUMINANCE8_ALPHA8);
- PY_DICT_ADD_INT(GL_LUMINANCE_ALPHA);
- PY_DICT_ADD_INT(GL_MAP1_COLOR_4);
- PY_DICT_ADD_INT(GL_MAP1_GRID_DOMAIN);
- PY_DICT_ADD_INT(GL_MAP1_GRID_SEGMENTS);
- PY_DICT_ADD_INT(GL_MAP1_INDEX);
- PY_DICT_ADD_INT(GL_MAP1_NORMAL);
- PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_1);
- PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_2);
- PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_3);
- PY_DICT_ADD_INT(GL_MAP1_TEXTURE_COORD_4);
- PY_DICT_ADD_INT(GL_MAP1_VERTEX_3);
- PY_DICT_ADD_INT(GL_MAP1_VERTEX_4);
- PY_DICT_ADD_INT(GL_MAP2_COLOR_4);
- PY_DICT_ADD_INT(GL_MAP2_GRID_DOMAIN);
- PY_DICT_ADD_INT(GL_MAP2_GRID_SEGMENTS);
- PY_DICT_ADD_INT(GL_MAP2_INDEX);
- PY_DICT_ADD_INT(GL_MAP2_NORMAL);
- PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_1);
- PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_2);
- PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_3);
- PY_DICT_ADD_INT(GL_MAP2_TEXTURE_COORD_4);
- PY_DICT_ADD_INT(GL_MAP2_VERTEX_3);
- PY_DICT_ADD_INT(GL_MAP2_VERTEX_4);
- PY_DICT_ADD_INT(GL_MAP_COLOR);
- PY_DICT_ADD_INT(GL_MAP_STENCIL);
- PY_DICT_ADD_INT(GL_MATRIX_MODE);
- PY_DICT_ADD_INT(GL_MAX_ATTRIB_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_MAX_CLIENT_ATTRIB_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_MAX_CLIP_PLANES);
- PY_DICT_ADD_INT(GL_MAX_EVAL_ORDER);
- PY_DICT_ADD_INT(GL_MAX_LIGHTS);
- PY_DICT_ADD_INT(GL_MAX_LIST_NESTING);
- PY_DICT_ADD_INT(GL_MAX_MODELVIEW_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_MAX_NAME_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_MAX_PIXEL_MAP_TABLE);
- PY_DICT_ADD_INT(GL_MAX_PROJECTION_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_MAX_TEXTURE_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_MODELVIEW);
- PY_DICT_ADD_INT(GL_MODELVIEW_MATRIX);
- PY_DICT_ADD_INT(GL_MODELVIEW_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_MODULATE);
- PY_DICT_ADD_INT(GL_MULT);
- PY_DICT_ADD_INT(GL_N3F_V3F);
- PY_DICT_ADD_INT(GL_NAME_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_NORMALIZE);
- PY_DICT_ADD_INT(GL_NORMAL_ARRAY);
- PY_DICT_ADD_INT(GL_NORMAL_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_NORMAL_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_NORMAL_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_OBJECT_LINEAR);
- PY_DICT_ADD_INT(GL_OBJECT_PLANE);
- PY_DICT_ADD_INT(GL_ORDER);
- PY_DICT_ADD_INT(GL_PASS_THROUGH_TOKEN);
- PY_DICT_ADD_INT(GL_PERSPECTIVE_CORRECTION_HINT);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_A_TO_A);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_A_TO_A_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_B_TO_B);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_B_TO_B_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_G_TO_G);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_G_TO_G_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_A);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_A_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_B);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_B_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_G);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_G_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_I);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_I_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_R);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_I_TO_R_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_R_TO_R);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_R_TO_R_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_S_TO_S);
- PY_DICT_ADD_INT(GL_PIXEL_MAP_S_TO_S_SIZE);
- PY_DICT_ADD_INT(GL_PIXEL_MODE_BIT);
- PY_DICT_ADD_INT(GL_POINT_BIT);
- PY_DICT_ADD_INT(GL_POINT_SMOOTH);
- PY_DICT_ADD_INT(GL_POINT_SMOOTH_HINT);
- PY_DICT_ADD_INT(GL_POINT_TOKEN);
- PY_DICT_ADD_INT(GL_POLYGON);
- PY_DICT_ADD_INT(GL_POLYGON_BIT);
- PY_DICT_ADD_INT(GL_POLYGON_STIPPLE);
- PY_DICT_ADD_INT(GL_POLYGON_STIPPLE_BIT);
- PY_DICT_ADD_INT(GL_POLYGON_TOKEN);
- PY_DICT_ADD_INT(GL_POSITION);
- PY_DICT_ADD_INT(GL_PROJECTION);
- PY_DICT_ADD_INT(GL_PROJECTION_MATRIX);
- PY_DICT_ADD_INT(GL_PROJECTION_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_Q);
- PY_DICT_ADD_INT(GL_QUADRATIC_ATTENUATION);
- PY_DICT_ADD_INT(GL_QUADS);
- PY_DICT_ADD_INT(GL_QUAD_STRIP);
- PY_DICT_ADD_INT(GL_R);
- PY_DICT_ADD_INT(GL_RED_BIAS);
- PY_DICT_ADD_INT(GL_RED_BITS);
- PY_DICT_ADD_INT(GL_RED_SCALE);
- PY_DICT_ADD_INT(GL_RENDER);
- PY_DICT_ADD_INT(GL_RENDER_MODE);
- PY_DICT_ADD_INT(GL_RETURN);
- PY_DICT_ADD_INT(GL_RGBA_MODE);
- PY_DICT_ADD_INT(GL_S);
- PY_DICT_ADD_INT(GL_SCISSOR_BIT);
- PY_DICT_ADD_INT(GL_SELECT);
- PY_DICT_ADD_INT(GL_SELECTION_BUFFER_POINTER);
- PY_DICT_ADD_INT(GL_SELECTION_BUFFER_SIZE);
- PY_DICT_ADD_INT(GL_SHADE_MODEL);
- PY_DICT_ADD_INT(GL_SHININESS);
- PY_DICT_ADD_INT(GL_SMOOTH);
- PY_DICT_ADD_INT(GL_SPECULAR);
- PY_DICT_ADD_INT(GL_SPHERE_MAP);
- PY_DICT_ADD_INT(GL_SPOT_CUTOFF);
- PY_DICT_ADD_INT(GL_SPOT_DIRECTION);
- PY_DICT_ADD_INT(GL_SPOT_EXPONENT);
- PY_DICT_ADD_INT(GL_STACK_OVERFLOW);
- PY_DICT_ADD_INT(GL_STACK_UNDERFLOW);
- PY_DICT_ADD_INT(GL_STENCIL_BITS);
- PY_DICT_ADD_INT(GL_T);
- PY_DICT_ADD_INT(GL_T2F_C3F_V3F);
- PY_DICT_ADD_INT(GL_T2F_C4F_N3F_V3F);
- PY_DICT_ADD_INT(GL_T2F_C4UB_V3F);
- PY_DICT_ADD_INT(GL_T2F_N3F_V3F);
- PY_DICT_ADD_INT(GL_T2F_V3F);
- PY_DICT_ADD_INT(GL_T4F_C4F_N3F_V4F);
- PY_DICT_ADD_INT(GL_T4F_V4F);
- PY_DICT_ADD_INT(GL_TEXTURE_BIT);
- PY_DICT_ADD_INT(GL_TEXTURE_BORDER);
- PY_DICT_ADD_INT(GL_TEXTURE_COMPONENTS);
- PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY);
- PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_SIZE);
- PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_TEXTURE_ENV);
- PY_DICT_ADD_INT(GL_TEXTURE_ENV_COLOR);
- PY_DICT_ADD_INT(GL_TEXTURE_ENV_MODE);
- PY_DICT_ADD_INT(GL_TEXTURE_GEN_MODE);
- PY_DICT_ADD_INT(GL_TEXTURE_GEN_Q);
- PY_DICT_ADD_INT(GL_TEXTURE_GEN_R);
- PY_DICT_ADD_INT(GL_TEXTURE_GEN_S);
- PY_DICT_ADD_INT(GL_TEXTURE_GEN_T);
- PY_DICT_ADD_INT(GL_TEXTURE_INTENSITY_SIZE);
- PY_DICT_ADD_INT(GL_TEXTURE_LUMINANCE_SIZE);
- PY_DICT_ADD_INT(GL_TEXTURE_MATRIX);
- PY_DICT_ADD_INT(GL_TEXTURE_PRIORITY);
- PY_DICT_ADD_INT(GL_TEXTURE_RESIDENT);
- PY_DICT_ADD_INT(GL_TEXTURE_STACK_DEPTH);
- PY_DICT_ADD_INT(GL_TRANSFORM_BIT);
- PY_DICT_ADD_INT(GL_V2F);
- PY_DICT_ADD_INT(GL_V3F);
- PY_DICT_ADD_INT(GL_VERTEX_ARRAY);
- PY_DICT_ADD_INT(GL_VERTEX_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_VERTEX_ARRAY_SIZE);
- PY_DICT_ADD_INT(GL_VERTEX_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_VERTEX_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_VIEWPORT_BIT);
- PY_DICT_ADD_INT(GL_ZOOM_X);
- PY_DICT_ADD_INT(GL_ZOOM_Y);
- }
-
/* GL_VERSION_1_2 */
{
@@ -2974,15 +1924,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5);
PY_DICT_ADD_INT(GL_UNSIGNED_SHORT_5_6_5_REV);
}
- /* adding in GL_VERSION_1_2 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_ALIASED_POINT_SIZE_RANGE);
- PY_DICT_ADD_INT(GL_LIGHT_MODEL_COLOR_CONTROL);
- PY_DICT_ADD_INT(GL_RESCALE_NORMAL);
- PY_DICT_ADD_INT(GL_SEPARATE_SPECULAR_COLOR);
- PY_DICT_ADD_INT(GL_SINGLE_COLOR);
- }
-
/* GL_VERSION_1_3 */
{
@@ -3046,47 +1987,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Y);
PY_DICT_ADD_INT(GL_TEXTURE_CUBE_MAP_POSITIVE_Z);
}
- /* adding in GL_VERSION_1_3 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_ADD_SIGNED);
- PY_DICT_ADD_INT(GL_CLIENT_ACTIVE_TEXTURE);
- PY_DICT_ADD_INT(GL_COMBINE);
- PY_DICT_ADD_INT(GL_COMBINE_ALPHA);
- PY_DICT_ADD_INT(GL_COMBINE_RGB);
- PY_DICT_ADD_INT(GL_COMPRESSED_ALPHA);
- PY_DICT_ADD_INT(GL_COMPRESSED_INTENSITY);
- PY_DICT_ADD_INT(GL_COMPRESSED_LUMINANCE);
- PY_DICT_ADD_INT(GL_COMPRESSED_LUMINANCE_ALPHA);
- PY_DICT_ADD_INT(GL_CONSTANT);
- PY_DICT_ADD_INT(GL_DOT3_RGB);
- PY_DICT_ADD_INT(GL_DOT3_RGBA);
- PY_DICT_ADD_INT(GL_INTERPOLATE);
- PY_DICT_ADD_INT(GL_MAX_TEXTURE_UNITS);
- PY_DICT_ADD_INT(GL_MULTISAMPLE_BIT);
- PY_DICT_ADD_INT(GL_NORMAL_MAP);
- PY_DICT_ADD_INT(GL_OPERAND0_ALPHA);
- PY_DICT_ADD_INT(GL_OPERAND0_RGB);
- PY_DICT_ADD_INT(GL_OPERAND1_ALPHA);
- PY_DICT_ADD_INT(GL_OPERAND1_RGB);
- PY_DICT_ADD_INT(GL_OPERAND2_ALPHA);
- PY_DICT_ADD_INT(GL_OPERAND2_RGB);
- PY_DICT_ADD_INT(GL_PREVIOUS);
- PY_DICT_ADD_INT(GL_PRIMARY_COLOR);
- PY_DICT_ADD_INT(GL_REFLECTION_MAP);
- PY_DICT_ADD_INT(GL_RGB_SCALE);
- PY_DICT_ADD_INT(GL_SOURCE0_ALPHA);
- PY_DICT_ADD_INT(GL_SOURCE0_RGB);
- PY_DICT_ADD_INT(GL_SOURCE1_ALPHA);
- PY_DICT_ADD_INT(GL_SOURCE1_RGB);
- PY_DICT_ADD_INT(GL_SOURCE2_ALPHA);
- PY_DICT_ADD_INT(GL_SOURCE2_RGB);
- PY_DICT_ADD_INT(GL_SUBTRACT);
- PY_DICT_ADD_INT(GL_TRANSPOSE_COLOR_MATRIX);
- PY_DICT_ADD_INT(GL_TRANSPOSE_MODELVIEW_MATRIX);
- PY_DICT_ADD_INT(GL_TRANSPOSE_PROJECTION_MATRIX);
- PY_DICT_ADD_INT(GL_TRANSPOSE_TEXTURE_MATRIX);
- }
-
/* GL_VERSION_1_4 */
{
@@ -3116,33 +2016,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_TEXTURE_DEPTH_SIZE);
PY_DICT_ADD_INT(GL_TEXTURE_LOD_BIAS);
}
- /* adding in GL_VERSION_1_4 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_COLOR_SUM);
- PY_DICT_ADD_INT(GL_COMPARE_R_TO_TEXTURE);
- PY_DICT_ADD_INT(GL_CURRENT_FOG_COORDINATE);
- PY_DICT_ADD_INT(GL_CURRENT_SECONDARY_COLOR);
- PY_DICT_ADD_INT(GL_DEPTH_TEXTURE_MODE);
- PY_DICT_ADD_INT(GL_FOG_COORDINATE);
- PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY);
- PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_FOG_COORDINATE_SOURCE);
- PY_DICT_ADD_INT(GL_FRAGMENT_DEPTH);
- PY_DICT_ADD_INT(GL_GENERATE_MIPMAP);
- PY_DICT_ADD_INT(GL_GENERATE_MIPMAP_HINT);
- PY_DICT_ADD_INT(GL_POINT_DISTANCE_ATTENUATION);
- PY_DICT_ADD_INT(GL_POINT_SIZE_MAX);
- PY_DICT_ADD_INT(GL_POINT_SIZE_MIN);
- PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY);
- PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_SIZE);
- PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_TEXTURE_FILTER_CONTROL);
- }
-
/* GL_VERSION_1_5 */
{
@@ -3165,7 +2038,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_READ_ONLY);
PY_DICT_ADD_INT(GL_READ_WRITE);
PY_DICT_ADD_INT(GL_SAMPLES_PASSED);
- PY_DICT_ADD_INT(GL_SRC1_ALPHA);
PY_DICT_ADD_INT(GL_STATIC_COPY);
PY_DICT_ADD_INT(GL_STATIC_DRAW);
PY_DICT_ADD_INT(GL_STATIC_READ);
@@ -3175,32 +2047,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING);
PY_DICT_ADD_INT(GL_WRITE_ONLY);
}
- /* adding in GL_VERSION_1_5 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_COLOR_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_CURRENT_FOG_COORD);
- PY_DICT_ADD_INT(GL_EDGE_FLAG_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_FOG_COORD);
- PY_DICT_ADD_INT(GL_FOG_COORDINATE_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY);
- PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_POINTER);
- PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_STRIDE);
- PY_DICT_ADD_INT(GL_FOG_COORD_ARRAY_TYPE);
- PY_DICT_ADD_INT(GL_FOG_COORD_SRC);
- PY_DICT_ADD_INT(GL_INDEX_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_NORMAL_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_SECONDARY_COLOR_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_SRC0_ALPHA);
- PY_DICT_ADD_INT(GL_SRC0_RGB);
- PY_DICT_ADD_INT(GL_SRC1_RGB);
- PY_DICT_ADD_INT(GL_SRC2_ALPHA);
- PY_DICT_ADD_INT(GL_SRC2_RGB);
- PY_DICT_ADD_INT(GL_TEXTURE_COORD_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_VERTEX_ARRAY_BUFFER_BINDING);
- PY_DICT_ADD_INT(GL_WEIGHT_ARRAY_BUFFER_BINDING);
- }
-
/* GL_VERSION_2_0 */
{
@@ -3285,14 +2131,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_VERTEX_PROGRAM_POINT_SIZE);
PY_DICT_ADD_INT(GL_VERTEX_SHADER);
}
- /* adding in GL_VERSION_2_0 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_COORD_REPLACE);
- PY_DICT_ADD_INT(GL_MAX_TEXTURE_COORDS);
- PY_DICT_ADD_INT(GL_POINT_SPRITE);
- PY_DICT_ADD_INT(GL_VERTEX_PROGRAM_TWO_SIDE);
- }
-
/* GL_VERSION_2_1 */
{
@@ -3313,16 +2151,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_SRGB8_ALPHA8);
PY_DICT_ADD_INT(GL_SRGB_ALPHA);
}
- /* adding in GL_VERSION_2_1 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_COMPRESSED_SLUMINANCE);
- PY_DICT_ADD_INT(GL_COMPRESSED_SLUMINANCE_ALPHA);
- PY_DICT_ADD_INT(GL_CURRENT_RASTER_SECONDARY_COLOR);
- PY_DICT_ADD_INT(GL_SLUMINANCE);
- PY_DICT_ADD_INT(GL_SLUMINANCE8);
- PY_DICT_ADD_INT(GL_SLUMINANCE8_ALPHA8);
- PY_DICT_ADD_INT(GL_SLUMINANCE_ALPHA);
- }
/* GL_VERSION_3_0 */
{
@@ -3563,14 +2391,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_VERTEX_ARRAY_BINDING);
PY_DICT_ADD_INT(GL_VERTEX_ATTRIB_ARRAY_INTEGER);
}
- /* adding in GL_VERSION_3_0 removed from core profile */
- if (use_deprecated == true) {
- PY_DICT_ADD_INT(GL_ALPHA_INTEGER);
- PY_DICT_ADD_INT(GL_CLAMP_FRAGMENT_COLOR);
- PY_DICT_ADD_INT(GL_CLAMP_VERTEX_COLOR);
- PY_DICT_ADD_INT(GL_TEXTURE_INTENSITY_TYPE);
- PY_DICT_ADD_INT(GL_TEXTURE_LUMINANCE_TYPE);
- }
/* GL_VERSION_3_1 */
{
@@ -3637,7 +2457,6 @@ PyObject *BPyInit_bgl(void)
PY_DICT_ADD_INT(GL_UNSIGNED_INT_SAMPLER_BUFFER);
}
-
/* GL_VERSION_3_2 */
{
PY_DICT_ADD_INT(GL_ALREADY_SIGNALED);
@@ -3743,4 +2562,4 @@ static PyObject *Method_ShaderSource(PyObject *UNUSED(self), PyObject *args)
}
-/** \} */ \ No newline at end of file
+/** \} */
diff --git a/source/blender/python/generic/blf_py_api.c b/source/blender/python/generic/blf_py_api.c
index 69f1e297b43..02bd1fdbe39 100644
--- a/source/blender/python/generic/blf_py_api.c
+++ b/source/blender/python/generic/blf_py_api.c
@@ -114,6 +114,7 @@ static PyObject *py_blf_aspect(PyObject *UNUSED(self), PyObject *args)
}
+#if BLF_BLUR_ENABLE
PyDoc_STRVAR(py_blf_blur_doc,
".. function:: blur(fontid, radius)\n"
"\n"
@@ -135,6 +136,7 @@ static PyObject *py_blf_blur(PyObject *UNUSED(self), PyObject *args)
Py_RETURN_NONE;
}
+#endif
PyDoc_STRVAR(py_blf_draw_doc,
@@ -418,7 +420,9 @@ static PyObject *py_blf_unload(PyObject *UNUSED(self), PyObject *args)
/*----------------------------MODULE INIT-------------------------*/
static PyMethodDef BLF_methods[] = {
{"aspect", (PyCFunction) py_blf_aspect, METH_VARARGS, py_blf_aspect_doc},
+#if BLF_BLUR_ENABLE
{"blur", (PyCFunction) py_blf_blur, METH_VARARGS, py_blf_blur_doc},
+#endif
{"clipping", (PyCFunction) py_blf_clipping, METH_VARARGS, py_blf_clipping_doc},
{"word_wrap", (PyCFunction) py_blf_word_wrap, METH_VARARGS, py_blf_word_wrap_doc},
{"disable", (PyCFunction) py_blf_disable, METH_VARARGS, py_blf_disable_doc},
diff --git a/source/blender/python/generic/bpy_internal_import.c b/source/blender/python/generic/bpy_internal_import.c
index ffac09efdde..750d0c20301 100644
--- a/source/blender/python/generic/bpy_internal_import.c
+++ b/source/blender/python/generic/bpy_internal_import.c
@@ -116,16 +116,6 @@ void bpy_import_main_set(struct Main *maggie)
bpy_import_main = maggie;
}
-void bpy_import_main_extra_add(struct Main *maggie)
-{
- BLI_addhead(&bpy_import_main_list, maggie);
-}
-
-void bpy_import_main_extra_remove(struct Main *maggie)
-{
- BLI_remlink_safe(&bpy_import_main_list, maggie);
-}
-
/* returns a dummy filename for a textblock so we can tell what file a text block comes from */
void bpy_text_filename_get(char *fn, size_t fn_len, Text *text)
{
diff --git a/source/blender/python/generic/bpy_internal_import.h b/source/blender/python/generic/bpy_internal_import.h
index 905e045d657..f11571fb933 100644
--- a/source/blender/python/generic/bpy_internal_import.h
+++ b/source/blender/python/generic/bpy_internal_import.h
@@ -51,12 +51,7 @@ PyObject *bpy_text_reimport(PyObject *module, int *found);
void bpy_text_filename_get(char *fn, size_t fn_len, struct Text *text);
-/* The game engine has its own Main struct, if this is set search this rather than G.main */
struct Main *bpy_import_main_get(void);
void bpy_import_main_set(struct Main *maggie);
-/* This is used for importing text from dynamically loaded libraries in the game engine */
-void bpy_import_main_extra_add(struct Main *maggie);
-void bpy_import_main_extra_remove(struct Main *maggie);
-
#endif /* __BPY_INTERNAL_IMPORT_H__ */
diff --git a/source/blender/python/generic/py_capi_utils.h b/source/blender/python/generic/py_capi_utils.h
index fe7a046d99c..9f3c10bfd67 100644
--- a/source/blender/python/generic/py_capi_utils.h
+++ b/source/blender/python/generic/py_capi_utils.h
@@ -76,7 +76,7 @@ PyObject * PyC_UnicodeFromByteAndSize(const char *str, Py_ssize_t size);
const char * PyC_UnicodeAsByte(PyObject *py_str, PyObject **coerce); /* coerce must be NULL */
const char * PyC_UnicodeAsByteAndSize(PyObject *py_str, Py_ssize_t *size, PyObject **coerce);
-/* name namespace function for bpy & bge */
+/* name namespace function for bpy */
PyObject * PyC_DefaultNameSpace(const char *filename);
void PyC_RunQuicky(const char *filepath, int n, ...);
diff --git a/source/blender/python/intern/CMakeLists.txt b/source/blender/python/intern/CMakeLists.txt
index ae16bd4a145..c6cab3dda65 100644
--- a/source/blender/python/intern/CMakeLists.txt
+++ b/source/blender/python/intern/CMakeLists.txt
@@ -52,6 +52,7 @@ set(SRC
bpy_app_build_options.c
bpy_app_ffmpeg.c
bpy_app_handlers.c
+ bpy_app_icons.c
bpy_app_ocio.c
bpy_app_oiio.c
bpy_app_opensubdiv.c
@@ -65,6 +66,8 @@ set(SRC
bpy_intern_string.c
bpy_library_load.c
bpy_library_write.c
+ bpy_manipulator_wrap.c
+ bpy_msgbus.c
bpy_operator.c
bpy_operator_wrap.c
bpy_path.c
@@ -75,11 +78,14 @@ set(SRC
bpy_rna_callback.c
bpy_rna_driver.c
bpy_rna_id_collection.c
+ bpy_rna_manipulator.c
bpy_traceback.c
bpy_utils_previews.c
bpy_utils_units.c
gpu.c
gpu_offscreen.c
+ gpu_py_matrix.c
+ gpu_py_select.c
stubs.c
bpy.h
@@ -88,6 +94,7 @@ set(SRC
bpy_app_build_options.h
bpy_app_ffmpeg.h
bpy_app_handlers.h
+ bpy_app_icons.h
bpy_app_ocio.h
bpy_app_oiio.h
bpy_app_opensubdiv.h
@@ -98,6 +105,8 @@ set(SRC
bpy_driver.h
bpy_intern_string.h
bpy_library.h
+ bpy_manipulator_wrap.h
+ bpy_msgbus.h
bpy_operator.h
bpy_operator_wrap.h
bpy_path.h
@@ -107,6 +116,7 @@ set(SRC
bpy_rna_callback.h
bpy_rna_driver.h
bpy_rna_id_collection.h
+ bpy_rna_manipulator.h
bpy_traceback.h
bpy_utils_previews.h
bpy_utils_units.h
@@ -172,10 +182,6 @@ if(WITH_FREESTYLE)
add_definitions(-DWITH_FREESTYLE)
endif()
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
if(WITH_IMAGE_CINEON)
add_definitions(-DWITH_CINEON)
endif()
@@ -298,10 +304,6 @@ if(WITH_OPENSUBDIV)
)
endif()
-if(WITH_PLAYER)
- add_definitions(-DWITH_PLAYER)
-endif()
-
add_definitions(${GL_DEFINITIONS})
blender_add_lib(bf_python "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/python/intern/bpy.c b/source/blender/python/intern/bpy.c
index 7150cc65942..e07fa46424c 100644
--- a/source/blender/python/intern/bpy.c
+++ b/source/blender/python/intern/bpy.c
@@ -46,6 +46,7 @@
#include "bpy_rna.h"
#include "bpy_app.h"
#include "bpy_rna_id_collection.h"
+#include "bpy_rna_manipulator.h"
#include "bpy_props.h"
#include "bpy_library.h"
#include "bpy_operator.h"
@@ -57,6 +58,7 @@
/* external util modules */
#include "../generic/idprop_py_api.h"
+#include "bpy_msgbus.h"
#ifdef WITH_FREESTYLE
# include "BPy_Freestyle.h"
@@ -338,6 +340,8 @@ void BPy_init_modules(void)
BPY_rna_id_collection_module(mod);
+ BPY_rna_manipulator_module(mod);
+
bpy_import_test("bpy_types");
PyModule_AddObject(mod, "data", BPY_rna_module()); /* imports bpy_types by running this */
bpy_import_test("bpy_types");
@@ -347,6 +351,7 @@ void BPy_init_modules(void)
PyModule_AddObject(mod, "app", BPY_app_struct());
PyModule_AddObject(mod, "_utils_units", BPY_utils_units());
PyModule_AddObject(mod, "_utils_previews", BPY_utils_previews_module());
+ PyModule_AddObject(mod, "msgbus", BPY_msgbus_module());
/* bpy context */
RNA_pointer_create(NULL, &RNA_Context, (void *)BPy_GetContext(), &ctx_ptr);
@@ -371,6 +376,9 @@ void BPy_init_modules(void)
PyModule_AddObject(mod, meth_bpy_register_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_register_class, NULL));
PyModule_AddObject(mod, meth_bpy_unregister_class.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_unregister_class, NULL));
+ PyModule_AddObject(mod, meth_bpy_owner_id_get.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_owner_id_get, NULL));
+ PyModule_AddObject(mod, meth_bpy_owner_id_set.ml_name, (PyObject *)PyCFunction_New(&meth_bpy_owner_id_set, NULL));
+
/* add our own modules dir, this is a python package */
bpy_package_py = bpy_import_test("bpy");
}
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index 1e2ce372727..f6e89ef38a5 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -47,6 +47,9 @@
#include "bpy_app_handlers.h"
#include "bpy_driver.h"
+/* modules */
+#include "bpy_app_icons.h"
+
#include "BLI_utildefines.h"
#include "BKE_appdir.h"
@@ -117,6 +120,9 @@ static PyStructSequence_Field app_info_fields[] = {
{(char *)"build_options", (char *)"A set containing most important enabled optional build features"},
{(char *)"handlers", (char *)"Application handler callbacks"},
{(char *)"translations", (char *)"Application and addons internationalization API"},
+
+ /* Modules (not struct sequence). */
+ {(char *)"icons", (char *)"Manage custom icons"},
{NULL},
};
@@ -129,6 +135,7 @@ PyDoc_STRVAR(bpy_app_doc,
" :maxdepth: 1\n"
"\n"
" bpy.app.handlers.rst\n"
+" bpy.app.icons.rst\n"
" bpy.app.translations.rst\n"
);
@@ -210,6 +217,9 @@ static PyObject *make_app_info(void)
SetObjItem(BPY_app_handlers_struct());
SetObjItem(BPY_app_translations_struct());
+ /* modules */
+ SetObjItem(BPY_app_icons_module());
+
#undef SetIntItem
#undef SetStrItem
#undef SetBytesItem
diff --git a/source/blender/python/intern/bpy_app_build_options.c b/source/blender/python/intern/bpy_app_build_options.c
index d5c325e4317..6e3f8da31f9 100644
--- a/source/blender/python/intern/bpy_app_build_options.c
+++ b/source/blender/python/intern/bpy_app_build_options.c
@@ -42,7 +42,6 @@ static PyStructSequence_Field app_builtopts_info_fields[] = {
{(char *)"cycles", NULL},
{(char *)"cycles_osl", NULL},
{(char *)"freestyle", NULL},
- {(char *)"gameengine", NULL},
{(char *)"image_cineon", NULL},
{(char *)"image_dds", NULL},
{(char *)"image_frameserver", NULL},
@@ -64,7 +63,6 @@ static PyStructSequence_Field app_builtopts_info_fields[] = {
{(char *)"mod_smoke", NULL},
{(char *)"collada", NULL},
{(char *)"opencolorio", NULL},
- {(char *)"player", NULL},
{(char *)"openmp", NULL},
{(char *)"openvdb", NULL},
{(char *)"alembic", NULL},
@@ -140,12 +138,6 @@ static PyObject *make_builtopts_info(void)
SetObjIncref(Py_False);
#endif
-#ifdef WITH_GAMEENGINE
- SetObjIncref(Py_True);
-#else
- SetObjIncref(Py_False);
-#endif
-
#ifdef WITH_CINEON
SetObjIncref(Py_True);
#else
@@ -272,12 +264,6 @@ static PyObject *make_builtopts_info(void)
SetObjIncref(Py_False);
#endif
-#ifdef WITH_PLAYER
- SetObjIncref(Py_True);
-#else
- SetObjIncref(Py_False);
-#endif
-
#ifdef _OPENMP
SetObjIncref(Py_True);
#else
diff --git a/source/blender/python/intern/bpy_app_handlers.c b/source/blender/python/intern/bpy_app_handlers.c
index 90aa22de5bf..948a78d5794 100644
--- a/source/blender/python/intern/bpy_app_handlers.c
+++ b/source/blender/python/intern/bpy_app_handlers.c
@@ -59,14 +59,6 @@ static PyStructSequence_Field app_cb_info_fields[] = {
{(char *)"load_post", (char *)"on loading a new blend file (after)"},
{(char *)"save_pre", (char *)"on saving a blend file (before)"},
{(char *)"save_post", (char *)"on saving a blend file (after)"},
- {(char *)"scene_update_pre", (char *)"on every scene data update. Does not imply that anything changed in the "
- "scene, just that the dependency graph is about to be reevaluated, and the "
- "scene is about to be updated by Blender's animation system."},
- {(char *)"scene_update_post", (char *)"on every scene data update. Does not imply that anything changed in the "
- "scene, just that the dependency graph was reevaluated, and the scene was "
- "possibly updated by Blender's animation system."},
- {(char *)"game_pre", (char *)"on starting the game engine"},
- {(char *)"game_post", (char *)"on ending the game engine"},
{(char *)"version_update", (char *)"on ending the versioning code"},
/* sets the permanent tag */
diff --git a/source/blender/python/intern/bpy_app_icons.c b/source/blender/python/intern/bpy_app_icons.c
new file mode 100644
index 00000000000..4bd059dd295
--- /dev/null
+++ b/source/blender/python/intern/bpy_app_icons.c
@@ -0,0 +1,183 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_app_icons.c
+ * \ingroup pythonintern
+ *
+ * Runtime defined icons.
+ */
+
+#include <Python.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+
+#include "BKE_icons.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "bpy_app_icons.h"
+
+/* We may want to load direct from file. */
+PyDoc_STRVAR(bpy_app_icons_new_triangles_doc,
+".. function:: new_triangles(range, coords, colors)"
+"\n"
+" Create a new icon from triangle geometry.\n"
+"\n"
+" :arg range: Pair of ints.\n"
+" :type range: tuple.\n"
+" :arg coords: Sequence of bytes (6 floats for one triangle) for (X, Y) coordinates.\n"
+" :type coords: byte sequence.\n"
+" :arg colors: Sequence of ints (12 for one triangles) for RGBA.\n"
+" :type colors: byte sequence.\n"
+" :return: Unique icon value (pass to interface ``icon_value`` argument).\n"
+" :rtype: int\n"
+);
+static PyObject *bpy_app_icons_new_triangles(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ /* bytes */
+ uchar coords_range[2];
+ PyObject *py_coords, *py_colors;
+
+ static const char *_keywords[] = {"range", "coords", "colors", NULL};
+ static _PyArg_Parser _parser = {"(BB)SS:new_triangles", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &coords_range[0], &coords_range[1], &py_coords, &py_colors))
+ {
+ return NULL;
+ }
+
+ const int coords_len = PyBytes_GET_SIZE(py_coords);
+ const int tris_len = coords_len / 6;
+ if (tris_len * 6 != coords_len) {
+ PyErr_SetString(PyExc_ValueError, "coords must be multiple of 6");
+ return NULL;
+ }
+ if (PyBytes_GET_SIZE(py_colors) != 2 * coords_len) {
+ PyErr_SetString(PyExc_ValueError, "colors must be twice size of coords");
+ return NULL;
+ }
+
+ int coords_size = sizeof(uchar[2]) * tris_len * 3;
+ int colors_size = sizeof(uchar[4]) * tris_len * 3;
+ uchar (*coords)[2] = MEM_mallocN(coords_size, __func__);
+ uchar (*colors)[4] = MEM_mallocN(colors_size, __func__);
+
+ memcpy(coords, PyBytes_AS_STRING(py_coords), coords_size);
+ memcpy(colors, PyBytes_AS_STRING(py_colors), colors_size);
+
+ struct Icon_Geom *geom = MEM_mallocN(sizeof(*geom), __func__);
+ geom->coords_len = tris_len;
+ geom->coords_range[0] = coords_range[0];
+ geom->coords_range[1] = coords_range[1];
+ geom->coords = coords;
+ geom->colors = colors;
+ geom->icon_id = 0;
+ int icon_id = BKE_icon_geom_ensure(geom);
+ return PyLong_FromLong(icon_id);
+}
+
+PyDoc_STRVAR(bpy_app_icons_new_triangles_from_file_doc,
+".. function:: new_triangles_from_file(filename)"
+"\n"
+" Create a new icon from triangle geometry.\n"
+"\n"
+" :arg range: File path.\n"
+" :type range: string.\n"
+" :return: Unique icon value (pass to interface ``icon_value`` argument).\n"
+" :rtype: int\n"
+);
+static PyObject *bpy_app_icons_new_triangles_from_file(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ /* bytes */
+ char *filename;
+
+ static const char *_keywords[] = {"filename", NULL};
+ static _PyArg_Parser _parser = {"s:new_triangles_from_file", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &filename))
+ {
+ return NULL;
+ }
+
+ struct Icon_Geom *geom = BKE_icon_geom_from_file(filename);
+ if (geom == NULL) {
+ PyErr_SetString(PyExc_ValueError, "Unable to load from file");
+ return NULL;
+ }
+ int icon_id = BKE_icon_geom_ensure(geom);
+ return PyLong_FromLong(icon_id);
+}
+
+PyDoc_STRVAR(bpy_app_icons_release_doc,
+".. function:: release(icon_id)"
+"\n"
+" Release the icon.\n"
+);
+static PyObject *bpy_app_icons_release(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ int icon_id;
+ static const char *_keywords[] = {"icon_id", NULL};
+ static _PyArg_Parser _parser = {"i:release", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &icon_id))
+ {
+ return NULL;
+ }
+
+ if (!BKE_icon_delete_unmanaged(icon_id)) {
+ PyErr_SetString(PyExc_ValueError, "invalid icon_id");
+ return NULL;
+ }
+ Py_RETURN_NONE;
+}
+
+static struct PyMethodDef M_AppIcons_methods[] = {
+ {"new_triangles", (PyCFunction)bpy_app_icons_new_triangles,
+ METH_VARARGS | METH_KEYWORDS, bpy_app_icons_new_triangles_doc},
+ {"new_triangles_from_file", (PyCFunction)bpy_app_icons_new_triangles_from_file,
+ METH_VARARGS | METH_KEYWORDS, bpy_app_icons_new_triangles_from_file_doc},
+ {"release", (PyCFunction)bpy_app_icons_release,
+ METH_VARARGS | METH_KEYWORDS, bpy_app_icons_release_doc},
+ {NULL, NULL, 0, NULL}
+};
+
+static struct PyModuleDef M_AppIcons_module_def = {
+ PyModuleDef_HEAD_INIT,
+ "bpy.app.icons", /* m_name */
+ NULL, /* m_doc */
+ 0, /* m_size */
+ M_AppIcons_methods, /* m_methods */
+ NULL, /* m_reload */
+ NULL, /* m_traverse */
+ NULL, /* m_clear */
+ NULL, /* m_free */
+};
+
+PyObject *BPY_app_icons_module(void)
+{
+ PyObject *mod = PyModule_Create(&M_AppIcons_module_def);
+
+ return mod;
+}
diff --git a/source/blender/python/intern/bpy_app_icons.h b/source/blender/python/intern/bpy_app_icons.h
new file mode 100644
index 00000000000..309c7ed222f
--- /dev/null
+++ b/source/blender/python/intern/bpy_app_icons.h
@@ -0,0 +1,30 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_app_icons.h
+ * \ingroup pythonintern
+ */
+
+#ifndef __BPY_APP_ICONS_H__
+#define __BPY_APP_ICONS_H__
+
+PyObject *BPY_app_icons_module(void);
+
+#endif /* __BPY_APP_ICONS_H__ */
diff --git a/source/blender/python/intern/bpy_interface.c b/source/blender/python/intern/bpy_interface.c
index 99f87c61c5a..7156bed0c2b 100644
--- a/source/blender/python/intern/bpy_interface.c
+++ b/source/blender/python/intern/bpy_interface.c
@@ -74,6 +74,7 @@
#include "../generic/bgl.h"
#include "../generic/blf_py_api.h"
#include "../generic/idprop_py_api.h"
+#include "../gawain/gwn_py_api.h"
#include "../bmesh/bmesh_py_api.h"
#include "../mathutils/mathutils.h"
@@ -217,6 +218,7 @@ static struct _inittab bpy_internal_modules[] = {
{"mathutils.kdtree", PyInit_mathutils_kdtree},
#endif
{"_bpy_path", BPyInit__bpy_path},
+ {"_gawain", BPyInit_gawain},
{"bgl", BPyInit_bgl},
{"blf", BPyInit_blf},
{"bmesh", BPyInit_bmesh},
@@ -535,7 +537,8 @@ static bool python_script_exec(
if (py_dict) {
#ifdef PYMODULE_CLEAR_WORKAROUND
- PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItemString(PyThreadState_GET()->interp->modules, "__main__");
+ PyModuleObject *mmod = (PyModuleObject *)PyDict_GetItem(
+ PyThreadState_GET()->interp->modules, bpy_intern_str___main__);
PyObject *dict_back = mmod->md_dict;
/* freeing the module will clear the namespace,
* gives problems running classes defined in this namespace being used later. */
diff --git a/source/blender/python/intern/bpy_intern_string.c b/source/blender/python/intern/bpy_intern_string.c
index ac0100fa75d..6911e985e93 100644
--- a/source/blender/python/intern/bpy_intern_string.c
+++ b/source/blender/python/intern/bpy_intern_string.c
@@ -34,21 +34,24 @@
#include "BLI_utildefines.h"
-static PyObject *bpy_intern_str_arr[13];
+static PyObject *bpy_intern_str_arr[16];
-PyObject *bpy_intern_str_register;
-PyObject *bpy_intern_str_unregister;
-PyObject *bpy_intern_str_bl_rna;
+PyObject *bpy_intern_str___doc__;
+PyObject *bpy_intern_str___main__;
+PyObject *bpy_intern_str___module__;
+PyObject *bpy_intern_str___name__;
+PyObject *bpy_intern_str___slots__;
+PyObject *bpy_intern_str_attr;
PyObject *bpy_intern_str_bl_property;
+PyObject *bpy_intern_str_bl_rna;
+PyObject *bpy_intern_str_bl_target_properties;
PyObject *bpy_intern_str_bpy_types;
+PyObject *bpy_intern_str_frame;
PyObject *bpy_intern_str_order;
-PyObject *bpy_intern_str_attr;
+PyObject *bpy_intern_str_properties;
+PyObject *bpy_intern_str_register;
PyObject *bpy_intern_str_self;
-PyObject *bpy_intern_str_frame;
-PyObject *bpy_intern_str___slots__;
-PyObject *bpy_intern_str___name__;
-PyObject *bpy_intern_str___doc__;
-PyObject *bpy_intern_str___module__;
+PyObject *bpy_intern_str_unregister;
void bpy_intern_string_init(void)
{
@@ -57,19 +60,22 @@ void bpy_intern_string_init(void)
#define BPY_INTERN_STR(var, str) \
{ var = bpy_intern_str_arr[i++] = PyUnicode_FromString(str); } (void)0
- BPY_INTERN_STR(bpy_intern_str_register, "register");
- BPY_INTERN_STR(bpy_intern_str_unregister, "unregister");
- BPY_INTERN_STR(bpy_intern_str_bl_rna, "bl_rna");
+ BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__");
+ BPY_INTERN_STR(bpy_intern_str___main__, "__main__");
+ BPY_INTERN_STR(bpy_intern_str___module__, "__module__");
+ BPY_INTERN_STR(bpy_intern_str___name__, "__name__");
+ BPY_INTERN_STR(bpy_intern_str___slots__, "__slots__");
+ BPY_INTERN_STR(bpy_intern_str_attr, "attr");
BPY_INTERN_STR(bpy_intern_str_bl_property, "bl_property");
+ BPY_INTERN_STR(bpy_intern_str_bl_rna, "bl_rna");
+ BPY_INTERN_STR(bpy_intern_str_bl_target_properties, "bl_target_properties");
BPY_INTERN_STR(bpy_intern_str_bpy_types, "bpy.types");
+ BPY_INTERN_STR(bpy_intern_str_frame, "frame");
BPY_INTERN_STR(bpy_intern_str_order, "order");
- BPY_INTERN_STR(bpy_intern_str_attr, "attr");
+ BPY_INTERN_STR(bpy_intern_str_properties, "properties");
+ BPY_INTERN_STR(bpy_intern_str_register, "register");
BPY_INTERN_STR(bpy_intern_str_self, "self");
- BPY_INTERN_STR(bpy_intern_str_frame, "frame");
- BPY_INTERN_STR(bpy_intern_str___slots__, "__slots__");
- BPY_INTERN_STR(bpy_intern_str___name__, "__name__");
- BPY_INTERN_STR(bpy_intern_str___doc__, "__doc__");
- BPY_INTERN_STR(bpy_intern_str___module__, "__module__");
+ BPY_INTERN_STR(bpy_intern_str_unregister, "unregister");
#undef BPY_INTERN_STR
diff --git a/source/blender/python/intern/bpy_intern_string.h b/source/blender/python/intern/bpy_intern_string.h
index 394e84d89bd..998c312c321 100644
--- a/source/blender/python/intern/bpy_intern_string.h
+++ b/source/blender/python/intern/bpy_intern_string.h
@@ -30,18 +30,21 @@
void bpy_intern_string_init(void);
void bpy_intern_string_exit(void);
-extern PyObject *bpy_intern_str_register;
-extern PyObject *bpy_intern_str_unregister;
-extern PyObject *bpy_intern_str_bl_rna;
+extern PyObject *bpy_intern_str___doc__;
+extern PyObject *bpy_intern_str___main__;
+extern PyObject *bpy_intern_str___module__;
+extern PyObject *bpy_intern_str___name__;
+extern PyObject *bpy_intern_str___slots__;
+extern PyObject *bpy_intern_str_attr;
extern PyObject *bpy_intern_str_bl_property;
+extern PyObject *bpy_intern_str_bl_rna;
+extern PyObject *bpy_intern_str_bl_target_properties;
extern PyObject *bpy_intern_str_bpy_types;
+extern PyObject *bpy_intern_str_frame;
extern PyObject *bpy_intern_str_order;
-extern PyObject *bpy_intern_str_attr;
+extern PyObject *bpy_intern_str_properties;
+extern PyObject *bpy_intern_str_register;
extern PyObject *bpy_intern_str_self;
-extern PyObject *bpy_intern_str_frame;
-extern PyObject *bpy_intern_str___slots__;
-extern PyObject *bpy_intern_str___name__;
-extern PyObject *bpy_intern_str___doc__;
-extern PyObject *bpy_intern_str___module__;
+extern PyObject *bpy_intern_str_unregister;
#endif /* __BPY_INTERN_STRING_H__ */
diff --git a/source/blender/python/intern/bpy_library_load.c b/source/blender/python/intern/bpy_library_load.c
index 20226ffe6a3..4cd5e21bc22 100644
--- a/source/blender/python/intern/bpy_library_load.c
+++ b/source/blender/python/intern/bpy_library_load.c
@@ -38,8 +38,6 @@
#include "BLI_linklist.h"
#include "BLI_path_util.h"
-#include "BLO_readfile.h"
-
#include "BKE_main.h"
#include "BKE_library.h"
#include "BKE_idcode.h"
@@ -48,6 +46,8 @@
#include "DNA_space_types.h" /* FILE_LINK, FILE_RELPATH */
+#include "BLO_readfile.h"
+
#include "bpy_capi_utils.h"
#include "bpy_library.h"
@@ -332,6 +332,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
Main *bmain = CTX_data_main(BPy_GetContext());
Main *mainl = NULL;
int err = 0;
+ const bool do_append = ((self->flag & FILE_LINK) == 0);
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, true);
@@ -341,7 +342,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
{
int idcode_step = 0, idcode;
while ((idcode = BKE_idcode_iter_step(&idcode_step))) {
- if (BKE_idcode_is_linkable(idcode)) {
+ if (BKE_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) {
const char *name_plural = BKE_idcode_to_name_plural(idcode);
PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
// printf("lib: %s\n", name_plural);
@@ -414,7 +415,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
BKE_main_lib_objects_recalc_all(bmain);
/* append, rather than linking */
- if ((self->flag & FILE_LINK) == 0) {
+ if (do_append) {
BKE_library_make_local(bmain, lib, old_to_new_ids, true, false);
}
}
@@ -427,7 +428,7 @@ static PyObject *bpy_lib_exit(BPy_Library *self, PyObject *UNUSED(args))
{
int idcode_step = 0, idcode;
while ((idcode = BKE_idcode_iter_step(&idcode_step))) {
- if (BKE_idcode_is_linkable(idcode)) {
+ if (BKE_idcode_is_linkable(idcode) && (idcode != ID_WS || do_append)) {
const char *name_plural = BKE_idcode_to_name_plural(idcode);
PyObject *ls = PyDict_GetItemString(self->dict, name_plural);
if (ls && PyList_Check(ls)) {
diff --git a/source/blender/python/intern/bpy_manipulator_wrap.c b/source/blender/python/intern/bpy_manipulator_wrap.c
new file mode 100644
index 00000000000..9df4e81ec55
--- /dev/null
+++ b/source/blender/python/intern/bpy_manipulator_wrap.c
@@ -0,0 +1,236 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_manipulator_wrap.c
+ * \ingroup pythonintern
+ *
+ * This file is so Python can define widget-group's that C can call into.
+ * The generic callback functions for Python widget-group are defines in
+ * 'rna_wm.c', some calling into functions here to do python specific
+ * functionality.
+ *
+ * \note This follows 'bpy_operator_wrap.c' very closely.
+ * Keep in sync unless there is good reason not to!
+ */
+
+#include <Python.h>
+
+#include "BLI_utildefines.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "bpy_rna.h"
+#include "bpy_intern_string.h"
+#include "bpy_manipulator_wrap.h" /* own include */
+
+/* we may want to add, but not now */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Manipulator
+ * \{ */
+
+
+static bool bpy_manipulatortype_target_property_def(
+ wmManipulatorType *wt, PyObject *item)
+{
+ /* Note: names based on 'rna_rna.c' */
+ PyObject *empty_tuple = PyTuple_New(0);
+
+ struct {
+ char *id;
+ char *type_id; int type;
+ int array_length;
+ } params = {
+ .id = NULL, /* not optional */
+ .type = PROP_FLOAT,
+ .type_id = NULL,
+ .array_length = 1,
+ };
+
+ static const char * const _keywords[] = {"id", "type", "array_length", NULL};
+ static _PyArg_Parser _parser = {"|$ssi:register_class", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ empty_tuple, item,
+ &_parser,
+ &params.id,
+ &params.type_id,
+ &params.array_length))
+ {
+ goto fail;
+ }
+
+ if (params.id == NULL) {
+ PyErr_SetString(PyExc_ValueError, "'id' argument not given");
+ goto fail;
+ }
+
+ if ((params.type_id != NULL) &&
+ pyrna_enum_value_from_id(
+ rna_enum_property_type_items, params.type_id, &params.type, "'type' enum value") == -1)
+ {
+ goto fail;
+ }
+ else {
+ params.type = rna_enum_property_type_items[params.type].value;
+ }
+
+ if ((params.array_length < 1 || params.array_length > RNA_MAX_ARRAY_LENGTH)) {
+ PyErr_SetString(PyExc_ValueError, "'array_length' out of range");
+ goto fail;
+ }
+
+ WM_manipulatortype_target_property_def(wt, params.id, params.type, params.array_length);
+ Py_DECREF(empty_tuple);
+ return true;
+
+fail:
+ Py_DECREF(empty_tuple);
+ return false;
+}
+
+static void manipulator_properties_init(wmManipulatorType *wt)
+{
+ PyTypeObject *py_class = wt->ext.data;
+ RNA_struct_blender_type_set(wt->ext.srna, wt);
+
+ /* only call this so pyrna_deferred_register_class gives a useful error
+ * WM_operatortype_append_ptr will call RNA_def_struct_identifier
+ * later */
+ RNA_def_struct_identifier_no_struct_map(wt->srna, wt->idname);
+
+ if (pyrna_deferred_register_class(wt->srna, py_class) != 0) {
+ PyErr_Print(); /* failed to register operator props */
+ PyErr_Clear();
+ }
+
+ /* Extract target property definitions from 'bl_target_properties' */
+ {
+ /* picky developers will notice that 'bl_targets' won't work with inheritance
+ * get direct from the dict to avoid raising a load of attribute errors (yes this isnt ideal) - campbell */
+ PyObject *py_class_dict = py_class->tp_dict;
+ PyObject *bl_target_properties = PyDict_GetItem(py_class_dict, bpy_intern_str_bl_target_properties);
+
+ /* Some widgets may only exist to activate operators. */
+ if (bl_target_properties != NULL) {
+ PyObject *bl_target_properties_fast;
+ if (!(bl_target_properties_fast = PySequence_Fast(
+ bl_target_properties, "bl_target_properties sequence")))
+ {
+ /* PySequence_Fast sets the error */
+ PyErr_Print();
+ PyErr_Clear();
+ return;
+ }
+
+ const uint items_len = PySequence_Fast_GET_SIZE(bl_target_properties_fast);
+ PyObject **items = PySequence_Fast_ITEMS(bl_target_properties_fast);
+
+ for (uint i = 0; i < items_len; i++) {
+ if (!bpy_manipulatortype_target_property_def(wt, items[i])) {
+ PyErr_Print();
+ PyErr_Clear();
+ break;
+ }
+ }
+
+ Py_DECREF(bl_target_properties_fast);
+ }
+ }
+}
+
+void BPY_RNA_manipulator_wrapper(wmManipulatorType *wt, void *userdata)
+{
+ /* take care not to overwrite anything set in
+ * WM_manipulatormaptype_group_link_ptr before opfunc() is called */
+ StructRNA *srna = wt->srna;
+ *wt = *((wmManipulatorType *)userdata);
+ wt->srna = srna; /* restore */
+
+ /* don't do translations here yet */
+#if 0
+ /* Use i18n context from ext.srna if possible (py manipulatorgroups). */
+ if (wt->ext.srna) {
+ RNA_def_struct_translation_context(wt->srna, RNA_struct_translation_context(wt->ext.srna));
+ }
+#endif
+
+ wt->struct_size = sizeof(wmManipulator);
+
+ manipulator_properties_init(wt);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Manipulator Group
+ * \{ */
+
+static void manipulatorgroup_properties_init(wmManipulatorGroupType *wgt)
+{
+#ifdef USE_SRNA
+ PyTypeObject *py_class = wgt->ext.data;
+#endif
+ RNA_struct_blender_type_set(wgt->ext.srna, wgt);
+
+#ifdef USE_SRNA
+ /* only call this so pyrna_deferred_register_class gives a useful error
+ * WM_operatortype_append_ptr will call RNA_def_struct_identifier
+ * later */
+ RNA_def_struct_identifier(wgt->srna, wgt->idname);
+
+ if (pyrna_deferred_register_class(wgt->srna, py_class) != 0) {
+ PyErr_Print(); /* failed to register operator props */
+ PyErr_Clear();
+ }
+#endif
+}
+
+void BPY_RNA_manipulatorgroup_wrapper(wmManipulatorGroupType *wgt, void *userdata)
+{
+ /* take care not to overwrite anything set in
+ * WM_manipulatormaptype_group_link_ptr before opfunc() is called */
+#ifdef USE_SRNA
+ StructRNA *srna = wgt->srna;
+#endif
+ *wgt = *((wmManipulatorGroupType *)userdata);
+#ifdef USE_SRNA
+ wgt->srna = srna; /* restore */
+#endif
+
+#ifdef USE_SRNA
+ /* Use i18n context from ext.srna if possible (py manipulatorgroups). */
+ if (wgt->ext.srna) {
+ RNA_def_struct_translation_context(wgt->srna, RNA_struct_translation_context(wgt->ext.srna));
+ }
+#endif
+
+ manipulatorgroup_properties_init(wgt);
+}
+
+/** \} */
+
diff --git a/source/blender/python/intern/bpy_manipulator_wrap.h b/source/blender/python/intern/bpy_manipulator_wrap.h
new file mode 100644
index 00000000000..3f739e26059
--- /dev/null
+++ b/source/blender/python/intern/bpy_manipulator_wrap.h
@@ -0,0 +1,36 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_manipulator_wrap.h
+ * \ingroup pythonintern
+ */
+
+#ifndef __BPY_MANIPULATOR_WRAP_H__
+#define __BPY_MANIPULATOR_WRAP_H__
+
+struct wmManipulatorType;
+struct wmManipulatorGroupType;
+
+/* exposed to rna/wm api */
+void BPY_RNA_manipulator_wrapper(struct wmManipulatorType *wt, void *userdata);
+void BPY_RNA_manipulatorgroup_wrapper(struct wmManipulatorGroupType *wgt, void *userdata);
+
+#endif /* __BPY_MANIPULATOR_WRAP_H__ */
+
diff --git a/source/blender/python/intern/bpy_msgbus.c b/source/blender/python/intern/bpy_msgbus.c
new file mode 100644
index 00000000000..941d6b760dc
--- /dev/null
+++ b/source/blender/python/intern/bpy_msgbus.c
@@ -0,0 +1,400 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_msgbus.c
+ * \ingroup pythonintern
+ * This file defines '_bpy_msgbus' module, exposed as 'bpy.msgbus'.
+ */
+
+#include <Python.h>
+
+#include "../generic/python_utildefines.h"
+#include "../generic/py_capi_utils.h"
+#include "../mathutils/mathutils.h"
+
+#include "BLI_utildefines.h"
+
+#include "BKE_context.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "WM_message.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
+
+#include "bpy_capi_utils.h"
+#include "bpy_rna.h"
+#include "bpy_intern_string.h"
+#include "bpy_manipulator_wrap.h" /* own include */
+
+
+#include "bpy_msgbus.h" /* own include */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Internal Utils
+ * \{ */
+
+#define BPY_MSGBUS_RNA_MSGKEY_DOC \
+" :arg key: Represents the type of data being subscribed to\n" \
+"\n" \
+" Arguments include\n" \
+" - :class:`bpy.types.Property` instance.\n" \
+" - :class:`bpy.types.Struct` type.\n" \
+" - (:class:`bpy.types.Struct`, str) type and property name.\n" \
+" :type key: Muliple\n"
+
+/**
+ * There are multiple ways we can get RNA from Python,
+ * it's also possible to register a type instead of an instance.
+ *
+ * This function handles converting Python to RNA subscription information.
+ *
+ * \param py_sub: See #BPY_MSGBUS_RNA_MSGKEY_DOC for description.
+ * \param msg_key_params: Message key with all members zeroed out.
+ * \return -1 on failure, 0 on success.
+ */
+static int py_msgbus_rna_key_from_py(
+ PyObject *py_sub,
+ wmMsgParams_RNA *msg_key_params,
+ const char *error_prefix)
+{
+
+ /* Allow common case, object rotation, location - etc. */
+ if (BaseMathObject_CheckExact(py_sub)) {
+ BaseMathObject *py_sub_math = (BaseMathObject *)py_sub;
+ if (py_sub_math->cb_user == NULL) {
+ PyErr_Format(
+ PyExc_TypeError,
+ "%s: math argument has no owner",
+ error_prefix);
+ return -1;
+ }
+ py_sub = py_sub_math->cb_user;
+ /* Common case will use BPy_PropertyRNA_Check below. */
+ }
+
+ if (BPy_PropertyRNA_Check(py_sub)) {
+ BPy_PropertyRNA *data_prop = (BPy_PropertyRNA *)py_sub;
+ PYRNA_PROP_CHECK_INT(data_prop);
+ msg_key_params->ptr = data_prop->ptr;
+ msg_key_params->prop = data_prop->prop;
+ }
+ else if (BPy_StructRNA_Check(py_sub)) {
+ /* note, this isn't typically used since we don't edit structs directly. */
+ BPy_StructRNA *data_srna = (BPy_StructRNA *)py_sub;
+ PYRNA_STRUCT_CHECK_INT(data_srna);
+ msg_key_params->ptr = data_srna->ptr;
+ }
+ /* TODO - property / type, not instance. */
+ else if (PyType_Check(py_sub)) {
+ StructRNA *data_type = pyrna_struct_as_srna(py_sub, false, error_prefix);
+ if (data_type == NULL) {
+ return -1;
+ }
+ msg_key_params->ptr.type = data_type;
+ }
+ else if (PyTuple_CheckExact(py_sub)) {
+ if (PyTuple_GET_SIZE(py_sub) == 2) {
+ PyObject *data_type_py = PyTuple_GET_ITEM(py_sub, 0);
+ PyObject *data_prop_py = PyTuple_GET_ITEM(py_sub, 1);
+ StructRNA *data_type = pyrna_struct_as_srna(data_type_py, false, error_prefix);
+ if (data_type == NULL) {
+ return -1;
+ }
+ if (!PyUnicode_CheckExact(data_prop_py)) {
+ PyErr_Format(
+ PyExc_TypeError,
+ "%s: expected property to be a string",
+ error_prefix);
+ return -1;
+ }
+ PointerRNA data_type_ptr = { .type = data_type, };
+ const char *data_prop_str = _PyUnicode_AsString(data_prop_py);
+ PropertyRNA *data_prop = RNA_struct_find_property(&data_type_ptr, data_prop_str);
+
+ if (data_prop == NULL) {
+ PyErr_Format(
+ PyExc_TypeError,
+ "%s: struct %.200s does not contain property %.200s",
+ error_prefix,
+ RNA_struct_identifier(data_type),
+ data_prop_str);
+ return -1;
+ }
+
+ msg_key_params->ptr.type = data_type;
+ msg_key_params->prop = data_prop;
+ }
+ else {
+ PyErr_Format(
+ PyExc_ValueError,
+ "%s: Expected a pair (type, property_id)",
+ error_prefix);
+ return -1;
+ }
+ }
+ return 0;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Internal Callbacks
+ * \{ */
+
+#define BPY_MSGBUS_USER_DATA_LEN 2
+
+/* Follow wmMsgNotifyFn spec */
+static void bpy_msgbus_notify(
+ bContext *C, wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val)
+{
+ PyGILState_STATE gilstate;
+ bpy_context_set(C, &gilstate);
+
+ PyObject *user_data = msg_val->user_data;
+ BLI_assert(PyTuple_GET_SIZE(user_data) == BPY_MSGBUS_USER_DATA_LEN);
+
+ PyObject *callback_args = PyTuple_GET_ITEM(user_data, 0);
+ PyObject *callback_notify = PyTuple_GET_ITEM(user_data, 1);
+
+ const bool is_write_ok = pyrna_write_check();
+ if (!is_write_ok) {
+ pyrna_write_set(true);
+ }
+
+ PyObject *ret = PyObject_CallObject(callback_notify, callback_args);
+
+ if (ret == NULL) {
+ PyC_Err_PrintWithFunc(callback_notify);
+ }
+ else {
+ if (ret != Py_None) {
+ PyErr_SetString(PyExc_ValueError, "the return value must be None");
+ PyC_Err_PrintWithFunc(callback_notify);
+ }
+ Py_DECREF(ret);
+ }
+
+ bpy_context_clear(C, &gilstate);
+
+ if (!is_write_ok) {
+ pyrna_write_set(false);
+ }
+}
+
+/* Follow wmMsgSubscribeValueFreeDataFn spec */
+static void bpy_msgbus_subscribe_value_free_data(
+ struct wmMsgSubscribeKey *UNUSED(msg_key), struct wmMsgSubscribeValue *msg_val)
+{
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+ Py_DECREF(msg_val->owner);
+ Py_DECREF(msg_val->user_data);
+ PyGILState_Release(gilstate);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Public Message Bus API
+ * \{ */
+
+PyDoc_STRVAR(bpy_msgbus_subscribe_rna_doc,
+".. function:: subscribe_rna(data, owner, args, notify)\n"
+"\n"
+BPY_MSGBUS_RNA_MSGKEY_DOC
+" :arg owner: Handle for this subscription (compared by identity).\n"
+" :type owner: Any type.\n"
+"\n"
+" Returns a new vector int property definition.\n"
+);
+static PyObject *bpy_msgbus_subscribe_rna(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ const char *error_prefix = "subscribe_rna";
+ PyObject *py_sub = NULL;
+ PyObject *py_owner = NULL;
+ PyObject *callback_args = NULL;
+ PyObject *callback_notify = NULL;
+
+ enum {
+ IS_PERSISTENT = (1 << 0),
+ };
+ PyObject *py_options = NULL;
+ EnumPropertyItem py_options_enum[] = {
+ {IS_PERSISTENT, "PERSISTENT", 0, ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+ int options = 0;
+
+ static const char *_keywords[] = {
+ "key",
+ "owner",
+ "args",
+ "notify",
+ "options",
+ NULL,
+ };
+ static _PyArg_Parser _parser = {"$OOO!OO!:subscribe_rna", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &py_sub, &py_owner,
+ &PyTuple_Type, &callback_args,
+ &callback_notify,
+ &PySet_Type, &py_options))
+ {
+ return NULL;
+ }
+
+ if (py_options &&
+ (pyrna_set_to_enum_bitfield(py_options_enum, py_options, &options, error_prefix)) == -1)
+ {
+ return NULL;
+ }
+
+ /* Note: we may want to have a way to pass this in. */
+ bContext *C = (bContext *)BPy_GetContext();
+ struct wmMsgBus *mbus = CTX_wm_message_bus(C);
+ wmMsgParams_RNA msg_key_params = {{{0}}};
+
+ wmMsgSubscribeValue msg_val_params = {0};
+
+ if (py_msgbus_rna_key_from_py(py_sub, &msg_key_params, error_prefix) == -1) {
+ return NULL;
+ }
+
+ if (!PyFunction_Check(callback_notify)) {
+ PyErr_Format(
+ PyExc_TypeError,
+ "notify expects a function, found %.200s",
+ Py_TYPE(callback_notify)->tp_name);
+ return NULL;
+ }
+
+ if (options != 0) {
+ if (options & IS_PERSISTENT) {
+ msg_val_params.is_persistent = true;
+ }
+ }
+
+ /* owner can be anything. */
+ {
+ msg_val_params.owner = py_owner;
+ Py_INCREF(py_owner);
+ }
+
+ {
+ PyObject *user_data = PyTuple_New(2);
+ PyTuple_SET_ITEMS(
+ user_data,
+ Py_INCREF_RET(callback_args),
+ Py_INCREF_RET(callback_notify));
+ msg_val_params.user_data = user_data;
+ }
+
+ msg_val_params.notify = bpy_msgbus_notify;
+ msg_val_params.free_data = bpy_msgbus_subscribe_value_free_data;
+
+ WM_msg_subscribe_rna_params(mbus, &msg_key_params, &msg_val_params, __func__);
+
+ WM_msg_dump(mbus, __func__);
+
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(bpy_msgbus_publish_rna_doc,
+".. function:: publish_rna(data, owner, args, notify)\n"
+"\n"
+BPY_MSGBUS_RNA_MSGKEY_DOC
+"\n"
+" Notify subscribers of changes to this property\n"
+" (this typically doesn't need to be called explicitly since changes will automatically publish updates).\n"
+" In some cases it may be useful to publish changes explicitly using more general keys.\n"
+);
+static PyObject *bpy_msgbus_publish_rna(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ const char *error_prefix = "publish_rna";
+ PyObject *py_sub = NULL;
+
+ static const char *_keywords[] = {
+ "key",
+ NULL,
+ };
+ static _PyArg_Parser _parser = {"$O:publish_rna", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &py_sub))
+ {
+ return NULL;
+ }
+
+ /* Note: we may want to have a way to pass this in. */
+ bContext *C = (bContext *)BPy_GetContext();
+ struct wmMsgBus *mbus = CTX_wm_message_bus(C);
+ wmMsgParams_RNA msg_key_params = {{{0}}};
+
+ if (py_msgbus_rna_key_from_py(py_sub, &msg_key_params, error_prefix) == -1) {
+ return NULL;
+ }
+
+ WM_msg_publish_rna_params(mbus, &msg_key_params);
+
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(bpy_msgbus_clear_by_owner_doc,
+".. function:: clear_by_owner(owner)\n"
+"\n"
+" Clear all subscribers using this owner.\n"
+);
+static PyObject *bpy_msgbus_clear_by_owner(PyObject *UNUSED(self), PyObject *py_owner)
+{
+ bContext *C = (bContext *)BPy_GetContext();
+ struct wmMsgBus *mbus = CTX_wm_message_bus(C);
+ WM_msgbus_clear_by_owner(mbus, py_owner);
+ Py_RETURN_NONE;
+}
+
+static struct PyMethodDef BPy_msgbus_methods[] = {
+ {"subscribe_rna", (PyCFunction)bpy_msgbus_subscribe_rna, METH_VARARGS | METH_KEYWORDS, bpy_msgbus_subscribe_rna_doc},
+ {"publish_rna", (PyCFunction)bpy_msgbus_publish_rna, METH_VARARGS | METH_KEYWORDS, bpy_msgbus_publish_rna_doc},
+ {"clear_by_owner", (PyCFunction)bpy_msgbus_clear_by_owner, METH_O, bpy_msgbus_clear_by_owner_doc},
+ {NULL, NULL, 0, NULL}
+};
+
+static struct PyModuleDef _bpy_msgbus_def = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "msgbus",
+ .m_methods = BPy_msgbus_methods,
+};
+
+
+PyObject *BPY_msgbus_module(void)
+{
+ PyObject *submodule;
+
+ submodule = PyModule_Create(&_bpy_msgbus_def);
+
+ return submodule;
+}
+
+/** \} */
+
diff --git a/source/blender/python/intern/bpy_msgbus.h b/source/blender/python/intern/bpy_msgbus.h
new file mode 100644
index 00000000000..97b20e9b926
--- /dev/null
+++ b/source/blender/python/intern/bpy_msgbus.h
@@ -0,0 +1,30 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_msgbus.h
+ * \ingroup pythonintern
+ */
+
+#ifndef __BPY_MSGBUS_H__
+#define __BPY_MSGBUS_H__
+
+PyObject *BPY_msgbus_module(void);
+
+#endif /* __BPY_MSGBUS_H__ */
diff --git a/source/blender/python/intern/bpy_props.h b/source/blender/python/intern/bpy_props.h
index 614c1b4b708..fa2594f94d2 100644
--- a/source/blender/python/intern/bpy_props.h
+++ b/source/blender/python/intern/bpy_props.h
@@ -34,6 +34,6 @@ PyObject *BPy_PointerProperty(PyObject *self, PyObject *args, PyObject *kw);
PyObject *BPy_CollectionProperty(PyObject *self, PyObject *args, PyObject *kw);
StructRNA *pointer_type_from_py(PyObject *value, const char *error_prefix);
-#define PYRNA_STACK_ARRAY 32
+#define PYRNA_STACK_ARRAY RNA_STACK_ARRAY
#endif
diff --git a/source/blender/python/intern/bpy_rna.c b/source/blender/python/intern/bpy_rna.c
index 30ab2049b78..aa808118613 100644
--- a/source/blender/python/intern/bpy_rna.c
+++ b/source/blender/python/intern/bpy_rna.c
@@ -315,7 +315,7 @@ static bool rna_id_write_error(PointerRNA *ptr, PyObject *key)
ID *id = ptr->id.data;
if (id) {
const short idcode = GS(id->name);
- if (!ELEM(idcode, ID_WM, ID_SCR)) { /* may need more added here */
+ if (!ELEM(idcode, ID_WM, ID_SCR, ID_WS)) { /* may need more added here */
const char *idtype = BKE_idcode_to_name(idcode);
const char *pyname;
if (key && PyUnicode_Check(key)) pyname = _PyUnicode_AsString(key);
@@ -1849,19 +1849,28 @@ static int pyrna_py_to_prop(
* class mixing if this causes problems in the future it should be removed.
*/
if ((ptr_type == &RNA_AnyType) &&
- (BPy_StructRNA_Check(value)) &&
- (RNA_struct_is_a(((BPy_StructRNA *)value)->ptr.type, &RNA_Operator)))
+ (BPy_StructRNA_Check(value)))
{
- value = PyObject_GetAttrString(value, "properties");
- value_new = value;
+ const StructRNA *base_type =
+ RNA_struct_base_child_of(((const BPy_StructRNA *)value)->ptr.type, NULL);
+ if (ELEM(base_type, &RNA_Operator, &RNA_Manipulator)) {
+ value = PyObject_GetAttr(value, bpy_intern_str_properties);
+ value_new = value;
+ }
}
-
- /* if property is an OperatorProperties pointer and value is a map,
+ /* if property is an OperatorProperties/ManipulatorProperties pointer and value is a map,
* forward back to pyrna_pydict_to_props */
- if (RNA_struct_is_a(ptr_type, &RNA_OperatorProperties) && PyDict_Check(value)) {
- PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
- return pyrna_pydict_to_props(&opptr, value, false, error_prefix);
+ if (PyDict_Check(value)) {
+ const StructRNA *base_type = RNA_struct_base_child_of(ptr_type, NULL);
+ if (base_type == &RNA_OperatorProperties) {
+ PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
+ return pyrna_pydict_to_props(&opptr, value, false, error_prefix);
+ }
+ else if (base_type == &RNA_ManipulatorProperties) {
+ PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
+ return pyrna_pydict_to_props(&opptr, value, false, error_prefix);
+ }
}
/* another exception, allow to pass a collection as an RNA property */
@@ -3500,6 +3509,68 @@ static PyObject *pyrna_struct_is_property_readonly(BPy_StructRNA *self, PyObject
return PyBool_FromLong(!RNA_property_editable(&self->ptr, prop));
}
+
+PyDoc_STRVAR(pyrna_struct_is_property_overridable_static_doc,
+".. method:: is_property_overridable_static(property)\n"
+"\n"
+" Check if a property is statically overridable.\n"
+"\n"
+" :return: True when the property is statically overridable.\n"
+" :rtype: boolean\n"
+);
+static PyObject *pyrna_struct_is_property_overridable_static(BPy_StructRNA *self, PyObject *args)
+{
+ PropertyRNA *prop;
+ const char *name;
+
+ PYRNA_STRUCT_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "s:is_property_overridable_static", &name)) {
+ return NULL;
+ }
+
+ if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s.is_property_overridable_static(\"%.200s\") not found",
+ RNA_struct_identifier(self->ptr.type), name);
+ return NULL;
+ }
+
+ return PyBool_FromLong((long)RNA_property_overridable_get(&self->ptr, prop));
+}
+
+PyDoc_STRVAR(pyrna_struct_property_overridable_static_set_doc,
+".. method:: property_overridable_static_set(property)\n"
+"\n"
+" Define a property as statically overridable or not (only for custom properties!).\n"
+"\n"
+" :return: True when the overridable status of the property was successfully set.\n"
+" :rtype: boolean\n"
+);
+static PyObject *pyrna_struct_property_overridable_static_set(BPy_StructRNA *self, PyObject *args)
+{
+ PropertyRNA *prop;
+ const char *name;
+ int is_overridable;
+
+ PYRNA_STRUCT_CHECK_OBJ(self);
+
+ if (!PyArg_ParseTuple(args, "sp:property_overridable_static_set", &name, &is_overridable)) {
+ return NULL;
+ }
+
+ if ((prop = RNA_struct_find_property(&self->ptr, name)) == NULL) {
+ PyErr_Format(PyExc_TypeError,
+ "%.200s.property_overridable_static_set(\"%.200s\") not found",
+ RNA_struct_identifier(self->ptr.type), name);
+ return NULL;
+ }
+
+ return PyBool_FromLong((long)RNA_property_overridable_static_set(&self->ptr, prop, (bool)is_overridable));
+}
+
+
+
PyDoc_STRVAR(pyrna_struct_path_resolve_doc,
".. method:: path_resolve(path, coerce=True)\n"
"\n"
@@ -5164,6 +5235,8 @@ static struct PyMethodDef pyrna_struct_methods[] = {
{"property_unset", (PyCFunction)pyrna_struct_property_unset, METH_VARARGS, pyrna_struct_property_unset_doc},
{"is_property_hidden", (PyCFunction)pyrna_struct_is_property_hidden, METH_VARARGS, pyrna_struct_is_property_hidden_doc},
{"is_property_readonly", (PyCFunction)pyrna_struct_is_property_readonly, METH_VARARGS, pyrna_struct_is_property_readonly_doc},
+ {"is_property_overridable_static", (PyCFunction)pyrna_struct_is_property_overridable_static, METH_VARARGS, pyrna_struct_is_property_overridable_static_doc},
+ {"property_overridable_static_set", (PyCFunction)pyrna_struct_property_overridable_static_set, METH_VARARGS, pyrna_struct_property_overridable_static_set_doc},
{"path_resolve", (PyCFunction)pyrna_struct_path_resolve, METH_VARARGS, pyrna_struct_path_resolve_doc},
{"path_from_id", (PyCFunction)pyrna_struct_path_from_id, METH_VARARGS, pyrna_struct_path_from_id_doc},
{"type_recast", (PyCFunction)pyrna_struct_type_recast, METH_NOARGS, pyrna_struct_type_recast_doc},
@@ -7645,7 +7718,8 @@ static int bpy_class_call(bContext *C, PointerRNA *ptr, FunctionRNA *func, Param
PyGILState_STATE gilstate;
#ifdef USE_PEDANTIC_WRITE
- const bool is_readonly_init = !RNA_struct_is_a(ptr->type, &RNA_Operator);
+ const bool is_readonly_init = !(RNA_struct_is_a(ptr->type, &RNA_Operator) ||
+ RNA_struct_is_a(ptr->type, &RNA_Manipulator));
// const char *func_id = RNA_function_identifier(func); /* UNUSED */
/* testing, for correctness, not operator and not draw function */
const bool is_readonly = !(RNA_function_flag(func) & FUNC_ALLOW_WRITE);
@@ -8303,6 +8377,43 @@ static PyObject *pyrna_unregister_class(PyObject *UNUSED(self), PyObject *py_cla
Py_RETURN_NONE;
}
+/* Access to 'owner_id' internal global. */
+
+static PyObject *pyrna_bl_owner_id_get(PyObject *UNUSED(self))
+{
+ const char *name = RNA_struct_state_owner_get();
+ if (name) {
+ return PyUnicode_FromString(name);
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject *pyrna_bl_owner_id_set(PyObject *UNUSED(self), PyObject *value)
+{
+ const char *name;
+ if (value == Py_None) {
+ name = NULL;
+ }
+ else if (PyUnicode_Check(value)) {
+ name = _PyUnicode_AsString(value);
+ }
+ else {
+ PyErr_Format(PyExc_ValueError,
+ "owner_set(...): "
+ "expected None or a string, not '%.200s'", Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+ RNA_struct_state_owner_set(name);
+ Py_RETURN_NONE;
+}
+
+PyMethodDef meth_bpy_owner_id_get = {
+ "_bl_owner_id_get", (PyCFunction)pyrna_bl_owner_id_get, METH_NOARGS, NULL,
+};
+PyMethodDef meth_bpy_owner_id_set = {
+ "_bl_owner_id_set", (PyCFunction)pyrna_bl_owner_id_set, METH_O, NULL,
+};
+
/* currently this is fairly limited, we would need to make some way to split up
* pyrna_callback_classmethod_... if we want more than one callback per type */
typedef struct BPyRNA_CallBack {
diff --git a/source/blender/python/intern/bpy_rna.h b/source/blender/python/intern/bpy_rna.h
index f666294666e..32a63acde40 100644
--- a/source/blender/python/intern/bpy_rna.h
+++ b/source/blender/python/intern/bpy_rna.h
@@ -225,4 +225,8 @@ int pyrna_prop_validity_check(BPy_PropertyRNA *self);
extern PyMethodDef meth_bpy_register_class;
extern PyMethodDef meth_bpy_unregister_class;
+/* bpy.utils._bl_owner_(get/set) */
+extern PyMethodDef meth_bpy_owner_id_set;
+extern PyMethodDef meth_bpy_owner_id_get;
+
#endif
diff --git a/source/blender/python/intern/bpy_rna_callback.c b/source/blender/python/intern/bpy_rna_callback.c
index 01a25137a98..6b8684c7acd 100644
--- a/source/blender/python/intern/bpy_rna_callback.c
+++ b/source/blender/python/intern/bpy_rna_callback.c
@@ -168,9 +168,7 @@ static eSpace_Type rna_Space_refine_reverse(StructRNA *srna)
if (srna == &RNA_SpaceTextEditor) return SPACE_TEXT;
if (srna == &RNA_SpaceDopeSheetEditor) return SPACE_ACTION;
if (srna == &RNA_SpaceNLA) return SPACE_NLA;
- if (srna == &RNA_SpaceTimeline) return SPACE_TIME;
if (srna == &RNA_SpaceNodeEditor) return SPACE_NODE;
- if (srna == &RNA_SpaceLogicEditor) return SPACE_LOGIC;
if (srna == &RNA_SpaceConsole) return SPACE_CONSOLE;
if (srna == &RNA_SpaceUserPreferences) return SPACE_USERPREF;
if (srna == &RNA_SpaceClipEditor) return SPACE_CLIP;
diff --git a/source/blender/python/intern/bpy_rna_manipulator.c b/source/blender/python/intern/bpy_rna_manipulator.c
new file mode 100644
index 00000000000..950f7f98be0
--- /dev/null
+++ b/source/blender/python/intern/bpy_rna_manipulator.c
@@ -0,0 +1,565 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_rna_manipulator.c
+ * \ingroup pythonintern
+ *
+ * .
+ */
+
+#include <Python.h>
+#include <stddef.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_alloca.h"
+
+#include "BKE_main.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "bpy_capi_utils.h"
+#include "bpy_rna_manipulator.h"
+
+#include "../generic/py_capi_utils.h"
+#include "../generic/python_utildefines.h"
+
+#include "RNA_access.h"
+#include "RNA_types.h"
+#include "RNA_enum_types.h"
+
+#include "bpy_rna.h"
+
+
+/* -------------------------------------------------------------------- */
+/** \name Manipulator Target Property Define API
+ * \{ */
+
+enum {
+ BPY_MANIPULATOR_FN_SLOT_GET = 0,
+ BPY_MANIPULATOR_FN_SLOT_SET,
+ BPY_MANIPULATOR_FN_SLOT_RANGE_GET,
+};
+#define BPY_MANIPULATOR_FN_SLOT_LEN (BPY_MANIPULATOR_FN_SLOT_RANGE_GET + 1)
+
+struct BPyManipulatorHandlerUserData {
+
+ PyObject *fn_slots[BPY_MANIPULATOR_FN_SLOT_LEN];
+};
+
+static void py_rna_manipulator_handler_get_cb(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+
+ struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data;
+ PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_MANIPULATOR_FN_SLOT_GET], NULL);
+ if (ret == NULL) {
+ goto fail;
+ }
+
+ if (mpr_prop->type->data_type == PROP_FLOAT) {
+ float *value = value_p;
+ if (mpr_prop->type->array_length == 1) {
+ if ((*value = PyFloat_AsDouble(ret)) == -1.0f && PyErr_Occurred()) {
+ goto fail;
+ }
+ }
+ else {
+ if (PyC_AsArray(value, ret, mpr_prop->type->array_length, &PyFloat_Type, false,
+ "Manipulator get callback: ") == -1)
+ {
+ goto fail;
+ }
+ }
+ }
+ else {
+ PyErr_SetString(PyExc_AttributeError, "internal error, unsupported type");
+ goto fail;
+ }
+
+ Py_DECREF(ret);
+
+ PyGILState_Release(gilstate);
+ return;
+
+fail:
+ PyErr_Print();
+ PyErr_Clear();
+
+ PyGILState_Release(gilstate);
+}
+
+static void py_rna_manipulator_handler_set_cb(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ const void *value_p)
+{
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+
+ struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data;
+
+ PyObject *args = PyTuple_New(1);
+
+ if (mpr_prop->type->data_type == PROP_FLOAT) {
+ const float *value = value_p;
+ PyObject *py_value;
+ if (mpr_prop->type->array_length == 1) {
+ py_value = PyFloat_FromDouble(*value);
+ }
+ else {
+ py_value = PyC_Tuple_PackArray_F32(value, mpr_prop->type->array_length);
+ }
+ if (py_value == NULL) {
+ goto fail;
+ }
+ PyTuple_SET_ITEM(args, 0, py_value);
+ }
+ else {
+ PyErr_SetString(PyExc_AttributeError, "internal error, unsupported type");
+ goto fail;
+ }
+
+ PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_MANIPULATOR_FN_SLOT_SET], args);
+ if (ret == NULL) {
+ goto fail;
+ }
+ Py_DECREF(ret);
+
+ PyGILState_Release(gilstate);
+ return;
+
+fail:
+ PyErr_Print();
+ PyErr_Clear();
+
+ Py_DECREF(args);
+
+ PyGILState_Release(gilstate);
+}
+
+static void py_rna_manipulator_handler_range_get_cb(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop,
+ void *value_p)
+{
+ struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data;
+
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+
+ PyObject *ret = PyObject_CallObject(data->fn_slots[BPY_MANIPULATOR_FN_SLOT_RANGE_GET], NULL);
+ if (ret == NULL) {
+ goto fail;
+ }
+
+ if (!PyTuple_Check(ret)) {
+ PyErr_Format(PyExc_TypeError,
+ "Expected a tuple, not %.200s",
+ Py_TYPE(ret)->tp_name);
+ goto fail;
+ }
+
+ if (PyTuple_GET_SIZE(ret) != 2) {
+ PyErr_Format(PyExc_TypeError,
+ "Expected a tuple of size 2, not %d",
+ PyTuple_GET_SIZE(ret));
+ goto fail;
+ }
+
+ if (mpr_prop->type->data_type == PROP_FLOAT) {
+ float range[2];
+ for (int i = 0; i < 2; i++) {
+ if (((range[i] = PyFloat_AsDouble(PyTuple_GET_ITEM(ret, i))) == -1.0f && PyErr_Occurred()) == 0) {
+ /* pass */
+ }
+ else {
+ goto fail;
+ }
+ }
+ memcpy(value_p, range, sizeof(range));
+ }
+ else {
+ PyErr_SetString(PyExc_AttributeError, "internal error, unsupported type");
+ goto fail;
+ }
+
+ Py_DECREF(ret);
+ PyGILState_Release(gilstate);
+ return;
+
+fail:
+ Py_XDECREF(ret);
+
+ PyErr_Print();
+ PyErr_Clear();
+
+ PyGILState_Release(gilstate);
+}
+
+static void py_rna_manipulator_handler_free_cb(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop)
+{
+ struct BPyManipulatorHandlerUserData *data = mpr_prop->custom_func.user_data;
+
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+ for (int i = 0; i < BPY_MANIPULATOR_FN_SLOT_LEN; i++) {
+ Py_XDECREF(data->fn_slots[i]);
+ }
+ PyGILState_Release(gilstate);
+
+ MEM_freeN(data);
+
+}
+
+PyDoc_STRVAR(bpy_manipulator_target_set_handler_doc,
+".. method:: target_set_handler(target, get, set, range=None):\n"
+"\n"
+" Assigns callbacks to a manipulators property.\n"
+"\n"
+" :arg get: Function that returns the value for this property (single value or sequence).\n"
+" :type get: callable\n"
+" :arg set: Function that takes a single value argument and applies it.\n"
+" :type set: callable\n"
+" :arg range: Function that returns a (min, max) tuple for manipulators that use a range.\n"
+" :type range: callable\n"
+);
+static PyObject *bpy_manipulator_target_set_handler(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ PyGILState_STATE gilstate = PyGILState_Ensure();
+
+ struct {
+ PyObject *self;
+ char *target;
+ PyObject *py_fn_slots[BPY_MANIPULATOR_FN_SLOT_LEN];
+ } params = {
+ .self = NULL,
+ .target = NULL,
+ .py_fn_slots = {NULL},
+ };
+
+ /* Note: this is a counter-part to functions:
+ * 'Manipulator.target_set_prop & target_set_operator'
+ * (see: rna_wm_manipulator_api.c). conventions should match. */
+ static const char * const _keywords[] = {"self", "target", "get", "set", "range", NULL};
+ static _PyArg_Parser _parser = {"Os|$OOO:target_set_handler", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &params.self,
+ &params.target,
+ &params.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_GET],
+ &params.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_SET],
+ &params.py_fn_slots[BPY_MANIPULATOR_FN_SLOT_RANGE_GET]))
+ {
+ goto fail;
+ }
+
+ wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data;
+
+ const wmManipulatorPropertyType *mpr_prop_type =
+ WM_manipulatortype_target_property_find(mpr->type, params.target);
+ if (mpr_prop_type == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "Manipulator target property '%s.%s' not found",
+ mpr->type->idname, params.target);
+ goto fail;
+ }
+
+ {
+ const int slots_required = 2;
+ const int slots_start = 2;
+ for (int i = 0; i < BPY_MANIPULATOR_FN_SLOT_LEN; i++) {
+ if (params.py_fn_slots[i] == NULL) {
+ if (i < slots_required) {
+ PyErr_Format(PyExc_ValueError, "Argument '%s' not given", _keywords[slots_start + i]);
+ goto fail;
+ }
+ }
+ else if (!PyCallable_Check(params.py_fn_slots[i])) {
+ PyErr_Format(PyExc_ValueError, "Argument '%s' not callable", _keywords[slots_start + i]);
+ goto fail;
+ }
+ }
+ }
+
+ struct BPyManipulatorHandlerUserData *data = MEM_callocN(sizeof(*data), __func__);
+
+ for (int i = 0; i < BPY_MANIPULATOR_FN_SLOT_LEN; i++) {
+ data->fn_slots[i] = params.py_fn_slots[i];
+ Py_XINCREF(params.py_fn_slots[i]);
+ }
+
+ WM_manipulator_target_property_def_func_ptr(
+ mpr, mpr_prop_type,
+ &(const struct wmManipulatorPropertyFnParams) {
+ .value_get_fn = py_rna_manipulator_handler_get_cb,
+ .value_set_fn = py_rna_manipulator_handler_set_cb,
+ .range_get_fn = py_rna_manipulator_handler_range_get_cb,
+ .free_fn = py_rna_manipulator_handler_free_cb,
+ .user_data = data,
+ });
+
+ PyGILState_Release(gilstate);
+
+ Py_RETURN_NONE;
+
+fail:
+ PyGILState_Release(gilstate);
+ return NULL;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Manipulator Target Property Access API
+ * \{ */
+
+PyDoc_STRVAR(bpy_manipulator_target_get_value_doc,
+".. method:: target_get_value(target):\n"
+"\n"
+" Get the value of this target property.\n"
+"\n"
+" :arg target: Target property name.\n"
+" :type target: string\n"
+" :return: The value of the target property.\n"
+" :rtype: Single value or array based on the target type\n"
+);
+static PyObject *bpy_manipulator_target_get_value(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ struct {
+ PyObject *self;
+ char *target;
+ } params = {
+ .self = NULL,
+ .target = NULL,
+ };
+
+ static const char * const _keywords[] = {"self", "target", NULL};
+ static _PyArg_Parser _parser = {"Os:target_get_value", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &params.self,
+ &params.target))
+ {
+ goto fail;
+ }
+
+ wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data;
+
+ wmManipulatorProperty *mpr_prop =
+ WM_manipulator_target_property_find(mpr, params.target);
+ if (mpr_prop == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "Manipulator target property '%s.%s' not found",
+ mpr->type->idname, params.target);
+ goto fail;
+ }
+
+ const int array_len = WM_manipulator_target_property_array_length(mpr, mpr_prop);
+ switch (mpr_prop->type->data_type) {
+ case PROP_FLOAT:
+ {
+ if (array_len != 0) {
+ float *value = BLI_array_alloca(value, array_len);
+ WM_manipulator_target_property_value_get_array(mpr, mpr_prop, value);
+ return PyC_Tuple_PackArray_F32(value, array_len);
+ }
+ else {
+ float value = WM_manipulator_target_property_value_get(mpr, mpr_prop);
+ return PyFloat_FromDouble(value);
+ }
+ break;
+ }
+ default:
+ {
+ PyErr_SetString(PyExc_RuntimeError, "Not yet supported type");
+ goto fail;
+ }
+ }
+
+fail:
+ return NULL;
+}
+
+PyDoc_STRVAR(bpy_manipulator_target_set_value_doc,
+".. method:: target_set_value(target):\n"
+"\n"
+" Set the value of this target property.\n"
+"\n"
+" :arg target: Target property name.\n"
+" :type target: string\n"
+);
+static PyObject *bpy_manipulator_target_set_value(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ struct {
+ PyObject *self;
+ char *target;
+ PyObject *value;
+ } params = {
+ .self = NULL,
+ .target = NULL,
+ .value = NULL,
+ };
+
+ static const char * const _keywords[] = {"self", "target", "value", NULL};
+ static _PyArg_Parser _parser = {"OsO:target_set_value", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &params.self,
+ &params.target,
+ &params.value))
+ {
+ goto fail;
+ }
+
+ wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data;
+
+ wmManipulatorProperty *mpr_prop =
+ WM_manipulator_target_property_find(mpr, params.target);
+ if (mpr_prop == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "Manipulator target property '%s.%s' not found",
+ mpr->type->idname, params.target);
+ goto fail;
+ }
+
+ const int array_len = WM_manipulator_target_property_array_length(mpr, mpr_prop);
+ switch (mpr_prop->type->data_type) {
+ case PROP_FLOAT:
+ {
+ if (array_len != 0) {
+ float *value = BLI_array_alloca(value, array_len);
+ if (PyC_AsArray(value, params.value, mpr_prop->type->array_length, &PyFloat_Type, false,
+ "Manipulator target property array") == -1)
+ {
+ goto fail;
+ }
+ WM_manipulator_target_property_value_set_array(BPy_GetContext(), mpr, mpr_prop, value);
+ }
+ else {
+ float value;
+ if ((value = PyFloat_AsDouble(params.value)) == -1.0f && PyErr_Occurred()) {
+ goto fail;
+ }
+ WM_manipulator_target_property_value_set(BPy_GetContext(), mpr, mpr_prop, value);
+ }
+ Py_RETURN_NONE;
+ }
+ default:
+ {
+ PyErr_SetString(PyExc_RuntimeError, "Not yet supported type");
+ goto fail;
+ }
+ }
+
+fail:
+ return NULL;
+}
+
+
+PyDoc_STRVAR(bpy_manipulator_target_get_range_doc,
+".. method:: target_get_range(target):\n"
+"\n"
+" Get the range for this target property.\n"
+"\n"
+" :arg target: Target property name.\n"
+" :Get the range for this target property"
+" :return: The range of this property (min, max).\n"
+" :rtype: tuple pair.\n"
+);
+static PyObject *bpy_manipulator_target_get_range(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
+{
+ struct {
+ PyObject *self;
+ char *target;
+ } params = {
+ .self = NULL,
+ .target = NULL,
+ };
+
+ static const char * const _keywords[] = {"self", "target", NULL};
+ static _PyArg_Parser _parser = {"Os:target_get_range", _keywords, 0};
+ if (!_PyArg_ParseTupleAndKeywordsFast(
+ args, kw, &_parser,
+ &params.self,
+ &params.target))
+ {
+ goto fail;
+ }
+
+ wmManipulator *mpr = ((BPy_StructRNA *)params.self)->ptr.data;
+
+ wmManipulatorProperty *mpr_prop =
+ WM_manipulator_target_property_find(mpr, params.target);
+ if (mpr_prop == NULL) {
+ PyErr_Format(PyExc_ValueError,
+ "Manipulator target property '%s.%s' not found",
+ mpr->type->idname, params.target);
+ goto fail;
+ }
+
+ switch (mpr_prop->type->data_type) {
+ case PROP_FLOAT:
+ {
+ float range[2];
+ WM_manipulator_target_property_range_get(mpr, mpr_prop, range);
+ return PyC_Tuple_PackArray_F32(range, 2);
+ }
+ default:
+ {
+ PyErr_SetString(PyExc_RuntimeError, "Not yet supported type");
+ goto fail;
+ }
+ }
+
+fail:
+ return NULL;
+}
+
+/** \} */
+
+int BPY_rna_manipulator_module(PyObject *mod_par)
+{
+ static PyMethodDef method_def_array[] = {
+ /* Manipulator Target Property Define API */
+ {"target_set_handler", (PyCFunction)bpy_manipulator_target_set_handler,
+ METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_set_handler_doc},
+ /* Manipulator Target Property Access API */
+ {"target_get_value", (PyCFunction)bpy_manipulator_target_get_value,
+ METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_get_value_doc},
+ {"target_set_value", (PyCFunction)bpy_manipulator_target_set_value,
+ METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_set_value_doc},
+ {"target_get_range", (PyCFunction)bpy_manipulator_target_get_range,
+ METH_VARARGS | METH_KEYWORDS, bpy_manipulator_target_get_range_doc},
+ /* no sentinel needed. */
+ };
+
+ for (int i = 0; i < ARRAY_SIZE(method_def_array); i++) {
+ PyMethodDef *m = &method_def_array[i];
+ PyObject *func = PyCFunction_New(m, NULL);
+ PyObject *func_inst = PyInstanceMethod_New(func);
+ char name_prefix[128];
+ PyOS_snprintf(name_prefix, sizeof(name_prefix), "_rna_manipulator_%s", m->ml_name);
+ /* TODO, return a type that binds nearly to a method. */
+ PyModule_AddObject(mod_par, name_prefix, func_inst);
+ }
+
+ return 0;
+}
diff --git a/source/blender/python/intern/bpy_rna_manipulator.h b/source/blender/python/intern/bpy_rna_manipulator.h
new file mode 100644
index 00000000000..b6f3a2e651d
--- /dev/null
+++ b/source/blender/python/intern/bpy_rna_manipulator.h
@@ -0,0 +1,32 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): Bastien Montagne
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/bpy_rna_manipulator.h
+ * \ingroup pythonintern
+ */
+
+#ifndef __BPY_RNA_MANIPULATOR_H__
+#define __BPY_RNA_MANIPULATOR_H__
+
+int BPY_rna_manipulator_module(PyObject *);
+
+#endif /* __BPY_RNA_MANIPULATOR_H__ */
diff --git a/source/blender/python/intern/gpu.c b/source/blender/python/intern/gpu.c
index 60ce00c583e..06f3143ec46 100644
--- a/source/blender/python/intern/gpu.c
+++ b/source/blender/python/intern/gpu.c
@@ -55,7 +55,7 @@
#define PY_MODULE_ADD_CONSTANT(module, name) PyModule_AddIntConstant(module, # name, name)
PyDoc_STRVAR(M_gpu_doc,
-"This module provides access to the GLSL shader and Offscreen rendering functionalities."
+"This module provides access to GPU offscreen rendering, matrix stacks and selection."
);
static struct PyModuleDef gpumodule = {
PyModuleDef_HEAD_INIT,
@@ -74,251 +74,10 @@ static PyObject *PyInit_gpu(void)
if (m == NULL)
return NULL;
-
/* Take care to update docs when editing: 'doc/python_api/rst/gpu.rst' */
-
-
- /* -------------------------------------------------------------------- */
- /* GPUDynamicType */
-
- /* device constant groups */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_MISC);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_LAMP);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_OBJECT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_SAMPLER);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_MIST);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_WORLD);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_GROUP_MAT);
-
- /* device constants */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_NONE);
- /* GPU_DYNAMIC_GROUP_OBJECT */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_VIEWMAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_MAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_VIEWIMAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_IMAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_LOCTOVIEWMAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_LOCTOVIEWIMAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_COLOR);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_OBJECT_AUTOBUMPSCALE);
- /* GPU_DYNAMIC_GROUP_LAMP */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNVEC);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNCO);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNIMAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNPERSMAT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNENERGY);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DYNCOL);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_ATT1);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_ATT2);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_DISTANCE);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_SPOTSIZE);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_SPOTBLEND);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_LAMP_SPOTSCALE);
- /* GPU_DYNAMIC_GROUP_SAMPLER */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DBUFFER);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DIMAGE);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_SAMPLER_2DSHADOW);
- /* GPU_DYNAMIC_GROUP_MIST */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_ENABLE);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_START);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_DISTANCE);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_INTENSITY);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_TYPE);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MIST_COLOR);
- /* GPU_DYNAMIC_GROUP_WORLD */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_HORIZON_COLOR);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_AMBIENT_COLOR);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_ZENITH_COLOR);
- /* GPU_DYNAMIC_GROUP_MAT */
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_DIFFRGB);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_REF);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_SPECRGB);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_SPEC);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_HARD);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_EMIT);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_AMB);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_ALPHA);
- PY_MODULE_ADD_CONSTANT(m, GPU_DYNAMIC_MAT_MIR);
-
-
- /* -------------------------------------------------------------------- */
- /* GPUDataType */
-
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_1I);
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_1F);
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_2F);
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_3F);
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_4F);
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_9F);
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_16F);
- PY_MODULE_ADD_CONSTANT(m, GPU_DATA_4UB);
-
-
- /* -------------------------------------------------------------------- */
- /* CustomDataType
- *
- * Intentionally only include the subset used by the GPU API.
- */
- PY_MODULE_ADD_CONSTANT(m, CD_MTFACE);
- PY_MODULE_ADD_CONSTANT(m, CD_ORCO);
- PY_MODULE_ADD_CONSTANT(m, CD_TANGENT);
- PY_MODULE_ADD_CONSTANT(m, CD_MCOL);
return m;
}
-#define PY_DICT_ADD_STRING(d, s, f) \
- val = PyUnicode_FromString(s->f); \
- PyDict_SetItemString(d, # f, val); \
- Py_DECREF(val)
-
-#define PY_DICT_ADD_LONG(d, s, f) \
- val = PyLong_FromLong(s->f); \
- PyDict_SetItemString(d, # f, val); \
- Py_DECREF(val)
-
-#define PY_DICT_ADD_ID(d, s, f) \
- RNA_id_pointer_create((struct ID *)s->f, &tptr); \
- val = pyrna_struct_CreatePyObject(&tptr); \
- PyDict_SetItemString(d, # f, val); \
- Py_DECREF(val)
-
-#if 0 /* UNUSED */
-#define PY_OBJ_ADD_ID(d, s, f) \
- val = PyUnicode_FromString(&s->f->id.name[2]); \
- PyObject_SetAttrString(d, # f, val); \
- Py_DECREF(val)
-
-#define PY_OBJ_ADD_LONG(d, s, f) \
- val = PyLong_FromLong(s->f); \
- PyObject_SetAttrString(d, # f, val); \
- Py_DECREF(val)
-
-#define PY_OBJ_ADD_STRING(d, s, f) \
- val = PyUnicode_FromString(s->f); \
- PyObject_SetAttrString(d, # f, val); \
- Py_DECREF(val)
-#endif
-
-PyDoc_STRVAR(GPU_export_shader_doc,
-"export_shader(scene, material)\n"
-"\n"
-" Returns the GLSL shader that produces the visual effect of material in scene.\n"
-"\n"
-" :return: Dictionary defining the shader, uniforms and attributes.\n"
-" :rtype: Dict"
-);
-static PyObject *GPU_export_shader(PyObject *UNUSED(self), PyObject *args, PyObject *kw)
-{
- PyObject *pyscene;
- PyObject *pymat;
- PyObject *result;
- PyObject *dict;
- PyObject *val;
- PyObject *seq;
-
- int i;
- Scene *scene;
- PointerRNA tptr;
- Material *material;
- GPUShaderExport *shader;
- GPUInputUniform *uniform;
- GPUInputAttribute *attribute;
-
- static const char *_keywords[] = {"scene", "material", NULL};
- static _PyArg_Parser _parser = {"OO:export_shader", _keywords, 0};
- if (!_PyArg_ParseTupleAndKeywordsFast(
- args, kw, &_parser,
- &pyscene, &pymat))
- {
- return NULL;
- }
- scene = (Scene *)PyC_RNA_AsPointer(pyscene, "Scene");
- if (scene == NULL) {
- return NULL;
- }
-
- material = (Material *)PyC_RNA_AsPointer(pymat, "Material");
- if (material == NULL) {
- return NULL;
- }
-
- /* we can call our internal function at last: */
- shader = GPU_shader_export(scene, material);
- if (!shader) {
- PyErr_SetString(PyExc_RuntimeError, "cannot export shader");
- return NULL;
- }
- /* build a dictionary */
- result = PyDict_New();
- if (shader->fragment) {
- PY_DICT_ADD_STRING(result, shader, fragment);
- }
- if (shader->vertex) {
- PY_DICT_ADD_STRING(result, shader, vertex);
- }
- seq = PyList_New(BLI_listbase_count(&shader->uniforms));
- for (i = 0, uniform = shader->uniforms.first; uniform; uniform = uniform->next, i++) {
- dict = PyDict_New();
- PY_DICT_ADD_STRING(dict, uniform, varname);
- PY_DICT_ADD_LONG(dict, uniform, datatype);
- PY_DICT_ADD_LONG(dict, uniform, type);
- if (uniform->lamp) {
- PY_DICT_ADD_ID(dict, uniform, lamp);
- }
- if (uniform->material) {
- PY_DICT_ADD_ID(dict, uniform, material);
- }
- if (uniform->image) {
- PY_DICT_ADD_ID(dict, uniform, image);
- }
- if (uniform->type == GPU_DYNAMIC_SAMPLER_2DBUFFER ||
- uniform->type == GPU_DYNAMIC_SAMPLER_2DIMAGE ||
- uniform->type == GPU_DYNAMIC_SAMPLER_2DSHADOW)
- {
- PY_DICT_ADD_LONG(dict, uniform, texnumber);
- }
- if (uniform->texpixels) {
- val = PyByteArray_FromStringAndSize((const char *)uniform->texpixels, uniform->texsize * 4);
- PyDict_SetItemString(dict, "texpixels", val);
- Py_DECREF(val);
- PY_DICT_ADD_LONG(dict, uniform, texsize);
- }
- PyList_SET_ITEM(seq, i, dict);
- }
- PyDict_SetItemString(result, "uniforms", seq);
- Py_DECREF(seq);
-
- seq = PyList_New(BLI_listbase_count(&shader->attributes));
- for (i = 0, attribute = shader->attributes.first; attribute; attribute = attribute->next, i++) {
- dict = PyDict_New();
- PY_DICT_ADD_STRING(dict, attribute, varname);
- PY_DICT_ADD_LONG(dict, attribute, datatype);
- PY_DICT_ADD_LONG(dict, attribute, type);
- PY_DICT_ADD_LONG(dict, attribute, number);
- if (attribute->name) {
- if (attribute->name[0] != 0) {
- PY_DICT_ADD_STRING(dict, attribute, name);
- }
- else {
- val = PyLong_FromLong(0);
- PyDict_SetItemString(dict, "name", val);
- Py_DECREF(val);
- }
- }
- PyList_SET_ITEM(seq, i, dict);
- }
- PyDict_SetItemString(result, "attributes", seq);
- Py_DECREF(seq);
-
- GPU_free_shader_export(shader);
-
- return result;
-}
-
-static PyMethodDef meth_export_shader[] = {
- {"export_shader", (PyCFunction)GPU_export_shader, METH_VARARGS | METH_KEYWORDS, GPU_export_shader_doc}
-};
-
/* -------------------------------------------------------------------- */
/* Initialize Module */
@@ -330,13 +89,19 @@ PyObject *GPU_initPython(void)
module = PyInit_gpu();
- PyModule_AddObject(module, "export_shader", (PyObject *)PyCFunction_New(meth_export_shader, NULL));
-
/* gpu.offscreen */
PyModule_AddObject(module, "offscreen", (submodule = BPyInit_gpu_offscreen()));
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
Py_INCREF(submodule);
+ PyModule_AddObject(module, "matrix", (submodule = BPyInit_gpu_matrix()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ Py_INCREF(submodule);
+
+ PyModule_AddObject(module, "select", (submodule = BPyInit_gpu_select()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ Py_INCREF(submodule);
+
PyDict_SetItem(PyImport_GetModuleDict(), PyModule_GetNameObject(module), module);
return module;
}
diff --git a/source/blender/python/intern/gpu.h b/source/blender/python/intern/gpu.h
index 0da44a4eb87..92841db9027 100644
--- a/source/blender/python/intern/gpu.h
+++ b/source/blender/python/intern/gpu.h
@@ -37,5 +37,7 @@
PyObject *GPU_initPython(void);
PyObject *BPyInit_gpu_offscreen(void);
+PyObject *BPyInit_gpu_matrix(void);
+PyObject *BPyInit_gpu_select(void);
#endif /* __GPU_H__ */
diff --git a/source/blender/python/intern/gpu_offscreen.c b/source/blender/python/intern/gpu_offscreen.c
index 3c340d14e3f..a8ec828c13f 100644
--- a/source/blender/python/intern/gpu_offscreen.c
+++ b/source/blender/python/intern/gpu_offscreen.c
@@ -37,8 +37,8 @@
#include "ED_screen.h"
-#include "GPU_compositing.h"
#include "GPU_framebuffer.h"
+#include "GPU_texture.h"
#include "../mathutils/mathutils.h"
@@ -89,7 +89,8 @@ PyDoc_STRVAR(pygpu_offscreen_color_texture_doc, "Color texture.\n\n:type: int");
static PyObject *pygpu_offscreen_color_texture_get(BPy_GPUOffScreen *self, void *UNUSED(type))
{
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
- return PyLong_FromLong(GPU_offscreen_color_texture(self->ofs));
+ GPUTexture *texture = GPU_offscreen_color_texture(self->ofs);
+ return PyLong_FromLong(GPU_texture_opengl_bindcode(texture));
}
PyDoc_STRVAR(pygpu_offscreen_bind_doc,
@@ -162,12 +163,15 @@ PyDoc_STRVAR(pygpu_offscreen_draw_view3d_doc,
);
static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *args, PyObject *kwds)
{
- static const char *kwlist[] = {"scene", "view3d", "region", "projection_matrix", "modelview_matrix", NULL};
+ /* TODO: This doesn't work currently because of missing depsgraph. */
+#if 0
+ static const char *kwlist[] = {"scene", "view_layer", "view3d", "region", "projection_matrix", "modelview_matrix", NULL};
MatrixObject *py_mat_modelview, *py_mat_projection;
- PyObject *py_scene, *py_region, *py_view3d;
+ PyObject *py_scene, *py_view_layer, *py_region, *py_view3d;
Scene *scene;
+ ViewLayer *view_layer;
View3D *v3d;
ARegion *ar;
GPUFX *fx;
@@ -177,13 +181,14 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
BPY_GPU_OFFSCREEN_CHECK_OBJ(self);
if (!PyArg_ParseTupleAndKeywords(
- args, kwds, "OOOO&O&:draw_view3d", (char **)(kwlist),
- &py_scene, &py_view3d, &py_region,
+ args, kwds, "OOOOO&O&:draw_view3d", (char **)(kwlist),
+ &py_scene, &py_view_layer, &py_view3d, &py_region,
Matrix_Parse4x4, &py_mat_projection,
Matrix_Parse4x4, &py_mat_modelview) ||
- (!(scene = PyC_RNA_AsPointer(py_scene, "Scene")) ||
- !(v3d = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) ||
- !(ar = PyC_RNA_AsPointer(py_region, "Region"))))
+ (!(scene = PyC_RNA_AsPointer(py_scene, "Scene")) ||
+ !(view_layer = PyC_RNA_AsPointer(py_view_layer, "ViewLayer")) ||
+ !(v3d = PyC_RNA_AsPointer(py_view3d, "SpaceView3D")) ||
+ !(ar = PyC_RNA_AsPointer(py_region, "Region"))))
{
return NULL;
}
@@ -192,14 +197,12 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
fx_settings = v3d->fx_settings; /* full copy */
- ED_view3d_draw_offscreen_init(scene, v3d);
-
rv3d_mats = ED_view3d_mats_rv3d_backup(ar->regiondata);
GPU_offscreen_bind(self->ofs, true); /* bind */
ED_view3d_draw_offscreen(
- scene, v3d, ar, GPU_offscreen_width(self->ofs), GPU_offscreen_height(self->ofs),
+ scene, view_layer, v3d, ar, GPU_offscreen_width(self->ofs), GPU_offscreen_height(self->ofs),
(float(*)[4])py_mat_modelview->matrix, (float(*)[4])py_mat_projection->matrix,
false, true, true, "",
fx, &fx_settings,
@@ -212,6 +215,10 @@ static PyObject *pygpu_offscreen_draw_view3d(BPy_GPUOffScreen *self, PyObject *a
MEM_freeN(rv3d_mats);
Py_RETURN_NONE;
+#else
+ UNUSED_VARS(self, args, kwds);
+#endif
+ return NULL;
}
PyDoc_STRVAR(pygpu_offscreen_free_doc,
@@ -346,7 +353,7 @@ static PyObject *pygpu_offscreen_new(PyObject *UNUSED(self), PyObject *args, PyO
return NULL;
}
- ofs = GPU_offscreen_create(width, height, samples, err_out);
+ ofs = GPU_offscreen_create(width, height, samples, true, false, err_out);
if (ofs == NULL) {
PyErr_Format(PyExc_RuntimeError,
diff --git a/source/blender/python/intern/gpu_py_matrix.c b/source/blender/python/intern/gpu_py_matrix.c
new file mode 100644
index 00000000000..68b08dfb324
--- /dev/null
+++ b/source/blender/python/intern/gpu_py_matrix.c
@@ -0,0 +1,552 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/gpu_py_matrix.c
+ * \ingroup pythonintern
+ *
+ * This file defines the gpu.matrix stack API.
+ *
+ * \warning While these functions attempt to ensure correct stack usage.
+ * Mixing Python and C functions may still crash on invalid use.
+ */
+
+#include <Python.h>
+
+
+#include "BLI_utildefines.h"
+
+#include "../mathutils/mathutils.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "gpu.h"
+
+#define USE_GPU_PY_MATRIX_API
+#include "GPU_matrix.h"
+#undef USE_GPU_PY_MATRIX_API
+
+/* -------------------------------------------------------------------- */
+/** \name Helper Functions
+ * \{ */
+
+static bool pygpu_stack_is_push_model_view_ok_or_error(void)
+{
+ if (GPU_matrix_stack_level_get_model_view() >= GPU_PY_MATRIX_STACK_LEN) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Maximum model-view stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH) " reached");
+ return false;
+ }
+ return true;
+}
+
+static bool pygpu_stack_is_push_projection_ok_or_error(void)
+{
+ if (GPU_matrix_stack_level_get_projection() >= GPU_PY_MATRIX_STACK_LEN) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Maximum projection stack depth " STRINGIFY(GPU_PY_MATRIX_STACK_DEPTH) " reached");
+ return false;
+ }
+ return true;
+}
+
+static bool pygpu_stack_is_pop_model_view_ok_or_error(void)
+{
+ if (GPU_matrix_stack_level_get_model_view() == 0) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Minimum model-view stack depth reached");
+ return false;
+ }
+ return true;
+}
+
+static bool pygpu_stack_is_pop_projection_ok_or_error(void)
+{
+ if (GPU_matrix_stack_level_get_projection() == 0) {
+ PyErr_SetString(PyExc_RuntimeError,
+ "Minimum projection stack depth reached");
+ return false;
+ }
+ return true;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Manage Stack
+ * \{ */
+
+PyDoc_STRVAR(pygpu_matrix_push_doc,
+"push()\n"
+"\n"
+" Add to the model-view matrix stack.\n"
+);
+static PyObject *pygpu_matrix_push(PyObject *UNUSED(self))
+{
+ if (!pygpu_stack_is_push_model_view_ok_or_error()) {
+ return NULL;
+ }
+ gpuPushMatrix();
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_pop_doc,
+"pop()\n"
+"\n"
+" Remove the last model-view matrix from the stack.\n"
+);
+static PyObject *pygpu_matrix_pop(PyObject *UNUSED(self))
+{
+ if (!pygpu_stack_is_pop_model_view_ok_or_error()) {
+ return NULL;
+ }
+ gpuPopMatrix();
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_push_projection_doc,
+"push_projection()\n"
+"\n"
+" Add to the projection matrix stack.\n"
+);
+static PyObject *pygpu_matrix_push_projection(PyObject *UNUSED(self))
+{
+ if (!pygpu_stack_is_push_projection_ok_or_error()) {
+ return NULL;
+ }
+ gpuPushProjectionMatrix();
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_pop_projection_doc,
+"pop_projection()\n"
+"\n"
+" Remove the last projection matrix from the stack.\n"
+);
+static PyObject *pygpu_matrix_pop_projection(PyObject *UNUSED(self))
+{
+ if (!pygpu_stack_is_pop_projection_ok_or_error()) {
+ return NULL;
+ }
+ gpuPopProjectionMatrix();
+ Py_RETURN_NONE;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Stack (Context Manager)
+ *
+ * Safer alternative to ensure balanced push/pop calls.
+ *
+ * \{ */
+
+typedef struct {
+ PyObject_HEAD /* required python macro */
+ int type;
+ int level;
+} BPy_GPU_MatrixStackContext;
+
+enum {
+ PYGPU_MATRIX_TYPE_MODEL_VIEW = 1,
+ PYGPU_MATRIX_TYPE_PROJECTION = 2,
+};
+
+static PyObject *pygpu_matrix_stack_context_enter(BPy_GPU_MatrixStackContext *self);
+static PyObject *pygpu_matrix_stack_context_exit(BPy_GPU_MatrixStackContext *self, PyObject *args);
+
+static PyMethodDef pygpu_matrix_stack_context_methods[] = {
+ {"__enter__", (PyCFunction)pygpu_matrix_stack_context_enter, METH_NOARGS},
+ {"__exit__", (PyCFunction)pygpu_matrix_stack_context_exit, METH_VARARGS},
+ {NULL}
+};
+
+static PyTypeObject pygpu_matrix_stack_context_Type = {
+ PyVarObject_HEAD_INIT(NULL, 0)
+ .tp_name = "GPUMatrixStackContext",
+ .tp_basicsize = sizeof(BPy_GPU_MatrixStackContext),
+ .tp_flags = Py_TPFLAGS_DEFAULT,
+ .tp_methods = pygpu_matrix_stack_context_methods,
+};
+
+static PyObject *pygpu_matrix_stack_context_enter(BPy_GPU_MatrixStackContext *self)
+{
+ /* sanity - should never happen */
+ if (self->level != -1) {
+ PyErr_SetString(PyExc_RuntimeError, "Already in use");
+ return NULL;
+ }
+
+ if (self->type == PYGPU_MATRIX_TYPE_MODEL_VIEW) {
+ if (!pygpu_stack_is_push_model_view_ok_or_error()) {
+ return NULL;
+ }
+ gpuPushMatrix();
+ self->level = GPU_matrix_stack_level_get_model_view();
+ }
+ else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) {
+ if (!pygpu_stack_is_push_projection_ok_or_error()) {
+ return NULL;
+ }
+ gpuPushProjectionMatrix();
+ self->level = GPU_matrix_stack_level_get_projection();
+ }
+ else {
+ BLI_assert(0);
+ }
+ Py_RETURN_NONE;
+}
+
+static PyObject *pygpu_matrix_stack_context_exit(BPy_GPU_MatrixStackContext *self, PyObject *UNUSED(args))
+{
+ /* sanity - should never happen */
+ if (self->level == -1) {
+ fprintf(stderr, "Not yet in use\n");
+ goto finally;
+ }
+
+ if (self->type == PYGPU_MATRIX_TYPE_MODEL_VIEW) {
+ const int level = GPU_matrix_stack_level_get_model_view();
+ if (level != self->level) {
+ fprintf(stderr, "Level push/pop mismatch, expected %d, got %d\n", self->level, level);
+ }
+ if (level != 0) {
+ gpuPopMatrix();
+ }
+ }
+ else if (self->type == PYGPU_MATRIX_TYPE_PROJECTION) {
+ const int level = GPU_matrix_stack_level_get_projection();
+ if (level != self->level) {
+ fprintf(stderr, "Level push/pop mismatch, expected %d, got %d", self->level, level);
+ }
+ if (level != 0) {
+ gpuPopProjectionMatrix();
+ }
+ }
+ else {
+ BLI_assert(0);
+ }
+finally:
+ Py_RETURN_NONE;
+}
+
+static PyObject *pygpu_matrix_push_pop_impl(int type)
+{
+ BPy_GPU_MatrixStackContext *ret = PyObject_New(BPy_GPU_MatrixStackContext, &pygpu_matrix_stack_context_Type);
+ ret->type = type;
+ ret->level = -1;
+ return (PyObject *)ret;
+}
+
+PyDoc_STRVAR(pygpu_matrix_push_pop_doc,
+"push_pop()\n"
+"\n"
+" Context manager to ensure balanced push/pop calls, even in the case of an error.\n"
+);
+static PyObject *pygpu_matrix_push_pop(PyObject *UNUSED(self))
+{
+ return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_MODEL_VIEW);
+}
+
+PyDoc_STRVAR(pygpu_matrix_push_pop_projection_doc,
+"push_pop_projection()\n"
+"\n"
+" Context manager to ensure balanced push/pop calls, even in the case of an error.\n"
+);
+static PyObject *pygpu_matrix_push_pop_projection(PyObject *UNUSED(self))
+{
+ return pygpu_matrix_push_pop_impl(PYGPU_MATRIX_TYPE_PROJECTION);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Manipulate State
+ * \{ */
+
+PyDoc_STRVAR(pygpu_matrix_multiply_matrix_doc,
+"multiply_matrix(matrix)\n"
+"\n"
+" Multiply the current stack matrix.\n"
+"\n"
+" :param matrix: A 4x4 matrix.\n"
+" :type matrix: :class:`mathutils.Matrix`\n"
+);
+static PyObject *pygpu_matrix_multiply_matrix(PyObject *UNUSED(self), PyObject *value)
+{
+ MatrixObject *pymat;
+ if (!Matrix_Parse4x4(value, &pymat)) {
+ return NULL;
+ }
+ gpuMultMatrix(pymat->matrix);
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_scale_doc,
+"scale(scale)\n"
+"\n"
+" Scale the current stack matrix.\n"
+"\n"
+" :param scale: Scale the current stack matrix.\n"
+" :type scale: sequence of 2 or 3 floats\n"
+);
+static PyObject *pygpu_matrix_scale(PyObject *UNUSED(self), PyObject *value)
+{
+ float scale[3];
+ int len;
+ if ((len = mathutils_array_parse(scale, 2, 3, value, "gpu.matrix.scale(): invalid vector arg")) == -1) {
+ return NULL;
+ }
+ if (len == 2) {
+ gpuScale2fv(scale);
+ }
+ else {
+ gpuScale3fv(scale);
+ }
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_scale_uniform_doc,
+"scale_uniform(scale)\n"
+"\n"
+" :param scale: Scale the current stack matrix.\n"
+" :type scale: sequence of 2 or 3 floats\n"
+);
+static PyObject *pygpu_matrix_scale_uniform(PyObject *UNUSED(self), PyObject *value)
+{
+ float scalar;
+ if ((scalar = PyFloat_AsDouble(value)) == -1.0f && PyErr_Occurred()) {
+ PyErr_Format(PyExc_TypeError,
+ "expected a number, not %.200s",
+ Py_TYPE(value)->tp_name);
+ return NULL;
+ }
+ gpuScaleUniform(scalar);
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_translate_doc,
+"translate(offset)\n"
+"\n"
+" Scale the current stack matrix.\n"
+"\n"
+" :param offset: Translate the current stack matrix.\n"
+" :type offset: sequence of 2 or 3 floats\n"
+);
+static PyObject *pygpu_matrix_translate(PyObject *UNUSED(self), PyObject *value)
+{
+ float offset[3];
+ int len;
+ if ((len = mathutils_array_parse(offset, 2, 3, value, "gpu.matrix.translate(): invalid vector arg")) == -1) {
+ return NULL;
+ }
+ if (len == 2) {
+ gpuTranslate2fv(offset);
+ }
+ else {
+ gpuTranslate3fv(offset);
+ }
+ Py_RETURN_NONE;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Write State
+ * \{ */
+
+PyDoc_STRVAR(pygpu_matrix_reset_doc,
+"reset()\n"
+"\n"
+" Empty stack and set to identity.\n"
+);
+static PyObject *pygpu_matrix_reset(PyObject *UNUSED(self))
+{
+ gpuMatrixReset();
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_load_identity_doc,
+"load_identity()\n"
+"\n"
+" Empty stack and set to identity.\n"
+);
+static PyObject *pygpu_matrix_load_identity(PyObject *UNUSED(self))
+{
+ gpuLoadIdentity();
+ Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(pygpu_matrix_load_matrix_doc,
+"load_matrix(matrix)\n"
+"\n"
+" Load a matrix into the stack.\n"
+"\n"
+" :param matrix: A 4x4 matrix.\n"
+" :type matrix: :class:`mathutils.Matrix`\n"
+);
+static PyObject *pygpu_matrix_load_matrix(PyObject *UNUSED(self), PyObject *value)
+{
+ MatrixObject *pymat;
+ if (!Matrix_Parse4x4(value, &pymat)) {
+ return NULL;
+ }
+ gpuLoadMatrix(pymat->matrix);
+ Py_RETURN_NONE;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Read State
+ * \{ */
+
+PyDoc_STRVAR(pygpu_matrix_get_projection_matrix_doc,
+"get_projection_matrix()\n"
+"\n"
+" Return a copy of the projection matrix.\n"
+"\n"
+" :return: A 4x4 projection matrix.\n"
+" :rtype: :class:`mathutils.Matrix`\n"
+);
+static PyObject *pygpu_matrix_get_projection_matrix(PyObject *UNUSED(self))
+{
+ float matrix[4][4];
+ gpuGetModelViewMatrix(matrix);
+ return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL);
+}
+
+
+PyDoc_STRVAR(pygpu_matrix_get_modal_view_matrix_doc,
+"get_view_matrix()\n"
+"\n"
+" Return a copy of the view matrix.\n"
+"\n"
+" :return: A 4x4 view matrix.\n"
+" :rtype: :class:`mathutils.Matrix`\n"
+);
+static PyObject *pygpu_matrix_get_modal_view_matrix(PyObject *UNUSED(self))
+{
+ float matrix[4][4];
+ gpuGetProjectionMatrix(matrix);
+ return Matrix_CreatePyObject(&matrix[0][0], 4, 4, NULL);
+}
+
+PyDoc_STRVAR(pygpu_matrix_get_normal_matrix_doc,
+"get_normal_matrix()\n"
+"\n"
+" Return a copy of the normal matrix.\n"
+"\n"
+" :return: A 3x3 normal matrix.\n"
+" :rtype: :class:`mathutils.Matrix`\n"
+);
+static PyObject *pygpu_matrix_get_normal_matrix(PyObject *UNUSED(self))
+{
+ float matrix[3][3];
+ gpuGetNormalMatrix(matrix);
+ return Matrix_CreatePyObject(&matrix[0][0], 3, 3, NULL);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Module
+ * \{ */
+
+static struct PyMethodDef BPy_GPU_matrix_methods[] = {
+ /* Manage Stack */
+ {"push", (PyCFunction)pygpu_matrix_push,
+ METH_NOARGS, pygpu_matrix_push_doc},
+ {"pop", (PyCFunction)pygpu_matrix_pop,
+ METH_NOARGS, pygpu_matrix_pop_doc},
+
+ {"push_projection", (PyCFunction)pygpu_matrix_push_projection,
+ METH_NOARGS, pygpu_matrix_push_projection_doc},
+ {"pop_projection", (PyCFunction)pygpu_matrix_pop_projection,
+ METH_NOARGS, pygpu_matrix_pop_projection_doc},
+
+ /* Stack (Context Manager) */
+ {"push_pop", (PyCFunction)pygpu_matrix_push_pop,
+ METH_NOARGS, pygpu_matrix_push_pop_doc},
+ {"push_pop_projection", (PyCFunction)pygpu_matrix_push_pop_projection,
+ METH_NOARGS, pygpu_matrix_push_pop_projection_doc},
+
+ /* Manipulate State */
+ {"multiply_matrix", (PyCFunction)pygpu_matrix_multiply_matrix,
+ METH_O, pygpu_matrix_multiply_matrix_doc},
+ {"scale", (PyCFunction)pygpu_matrix_scale,
+ METH_O, pygpu_matrix_scale_doc},
+ {"scale_uniform", (PyCFunction)pygpu_matrix_scale_uniform,
+ METH_O, pygpu_matrix_scale_uniform_doc},
+ {"translate", (PyCFunction)pygpu_matrix_translate,
+ METH_O, pygpu_matrix_translate_doc},
+
+ /* TODO */
+#if 0
+ {"rotate", (PyCFunction)pygpu_matrix_rotate,
+ METH_O, pygpu_matrix_rotate_doc},
+ {"rotate_axis", (PyCFunction)pygpu_matrix_rotate_axis,
+ METH_O, pygpu_matrix_rotate_axis_doc},
+ {"look_at", (PyCFunction)pygpu_matrix_look_at,
+ METH_O, pygpu_matrix_look_at_doc},
+#endif
+
+ /* Write State */
+ {"reset", (PyCFunction)pygpu_matrix_reset,
+ METH_NOARGS, pygpu_matrix_reset_doc},
+ {"load_identity", (PyCFunction)pygpu_matrix_load_identity,
+ METH_NOARGS, pygpu_matrix_load_identity_doc},
+ {"load_matrix", (PyCFunction)pygpu_matrix_load_matrix,
+ METH_O, pygpu_matrix_load_matrix_doc},
+
+ /* Read State */
+ {"get_projection_matrix", (PyCFunction)pygpu_matrix_get_projection_matrix,
+ METH_NOARGS, pygpu_matrix_get_projection_matrix_doc},
+ {"get_model_view_matrix", (PyCFunction)pygpu_matrix_get_modal_view_matrix,
+ METH_NOARGS, pygpu_matrix_get_modal_view_matrix_doc},
+ {"get_normal_matrix", (PyCFunction)pygpu_matrix_get_normal_matrix,
+ METH_NOARGS, pygpu_matrix_get_normal_matrix_doc},
+
+ {NULL, NULL, 0, NULL}
+};
+
+PyDoc_STRVAR(BPy_GPU_matrix_doc,
+"This module provides access to the matrix stack."
+);
+static PyModuleDef BPy_GPU_matrix_module_def = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "gpu.matrix",
+ .m_doc = BPy_GPU_matrix_doc,
+ .m_methods = BPy_GPU_matrix_methods,
+};
+
+PyObject *BPyInit_gpu_matrix(void)
+{
+ PyObject *submodule;
+
+ submodule = PyModule_Create(&BPy_GPU_matrix_module_def);
+
+ if (PyType_Ready(&pygpu_matrix_stack_context_Type) < 0) {
+ return NULL;
+ }
+
+ return submodule;
+}
+
+/** \} */
diff --git a/source/blender/python/intern/gpu_py_select.c b/source/blender/python/intern/gpu_py_select.c
new file mode 100644
index 00000000000..f570c4cdae2
--- /dev/null
+++ b/source/blender/python/intern/gpu_py_select.c
@@ -0,0 +1,92 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/python/intern/gpu_py_select.c
+ * \ingroup pythonintern
+ *
+ * This file defines the gpu.select API.
+ *
+ * \note Currently only used for manipulator selection,
+ * will need to add begin/end and a way to access the hits.
+ */
+
+#include <Python.h>
+
+#include "BLI_utildefines.h"
+
+#include "../generic/py_capi_utils.h"
+
+#include "gpu.h"
+
+#include "GPU_select.h"
+
+/* -------------------------------------------------------------------- */
+/** \name Methods
+ * \{ */
+
+PyDoc_STRVAR(pygpu_select_load_id_doc,
+"load_id(id)\n"
+"\n"
+" Set the selection ID.\n"
+"\n"
+" :param id: Number (32-bit unsigned int).\n"
+" :type select: int\n"
+);
+static PyObject *pygpu_select_load_id(PyObject *UNUSED(self), PyObject *value)
+{
+ uint id;
+ if ((id = PyC_Long_AsU32(value)) == (uint)-1) {
+ return NULL;
+ }
+ GPU_select_load_id(id);
+ Py_RETURN_NONE;
+}
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Module
+ * \{ */
+
+static struct PyMethodDef BPy_GPU_select_methods[] = {
+ /* Manage Stack */
+ {"load_id", (PyCFunction)pygpu_select_load_id, METH_O, pygpu_select_load_id_doc},
+ {NULL, NULL, 0, NULL}
+};
+
+PyDoc_STRVAR(BPy_GPU_select_doc,
+"This module provides access to selection."
+);
+static PyModuleDef BPy_GPU_select_module_def = {
+ PyModuleDef_HEAD_INIT,
+ .m_name = "gpu.select",
+ .m_doc = BPy_GPU_select_doc,
+ .m_methods = BPy_GPU_select_methods,
+};
+
+PyObject *BPyInit_gpu_select(void)
+{
+ PyObject *submodule;
+
+ submodule = PyModule_Create(&BPy_GPU_select_module_def);
+
+ return submodule;
+}
+
+/** \} */
diff --git a/source/blender/python/mathutils/mathutils.h b/source/blender/python/mathutils/mathutils.h
index ec927a9e316..01d2350d7fd 100644
--- a/source/blender/python/mathutils/mathutils.h
+++ b/source/blender/python/mathutils/mathutils.h
@@ -62,7 +62,7 @@ enum {
float *_data; /* array of data (alias), wrapped status depends on wrapped status */ \
PyObject *cb_user; /* if this vector references another object, otherwise NULL, \
* *Note* this owns its reference */ \
- unsigned char cb_type; /* which user funcs do we adhere to, RNA, GameObject, etc */ \
+ unsigned char cb_type; /* which user funcs do we adhere to, RNA, etc */ \
unsigned char cb_subtype; /* subtype: location, rotation... \
* to avoid defining many new functions for every attribute of the same type */ \
unsigned char flag /* wrapped data type? */ \
diff --git a/source/blender/python/mathutils/mathutils_bvhtree.c b/source/blender/python/mathutils/mathutils_bvhtree.c
index c044cc54965..4119917a33f 100644
--- a/source/blender/python/mathutils/mathutils_bvhtree.c
+++ b/source/blender/python/mathutils/mathutils_bvhtree.c
@@ -1049,6 +1049,8 @@ static DerivedMesh *bvh_get_derived_mesh(
const char *funcname, struct Scene *scene, Object *ob,
bool use_deform, bool use_render, bool use_cage)
{
+ /* TODO: This doesn't work currently because of missing depsgraph. */
+#if 0
/* we only need minimum mesh data for topology and vertex locations */
CustomDataMask mask = CD_MASK_BAREMESH;
@@ -1096,6 +1098,11 @@ static DerivedMesh *bvh_get_derived_mesh(
}
}
}
+#else
+ UNUSED_VARS(funcname, scene, ob, use_deform, use_render, use_cage);
+#endif
+
+ return NULL;
}
PyDoc_STRVAR(C_BVHTree_FromObject_doc,
diff --git a/source/blender/python/simple_enum_gen.py b/source/blender/python/simple_enum_gen.py
index 7e54f3dbb41..eef19b6c5f1 100644
--- a/source/blender/python/simple_enum_gen.py
+++ b/source/blender/python/simple_enum_gen.py
@@ -34,7 +34,7 @@ defs = """
SPACE_ACTION,
SPACE_NLA,
SPACE_SCRIPT, #Deprecated
- SPACE_TIME,
+ SPACE_TIME, #Deprecated
SPACE_NODE,
SPACEICONMAX
"""
diff --git a/source/blender/render/CMakeLists.txt b/source/blender/render/CMakeLists.txt
index 27ec6bf8ba6..0f0060c7578 100644
--- a/source/blender/render/CMakeLists.txt
+++ b/source/blender/render/CMakeLists.txt
@@ -36,6 +36,7 @@ set(INC
../makesrna
../nodes
../physics
+ ../draw
../../../intern/atomic
../../../intern/guardedalloc
../../../intern/mikktspace
@@ -47,43 +48,15 @@ set(INC_SYS
)
set(SRC
- intern/raytrace/rayobject.cpp
- intern/raytrace/rayobject_empty.cpp
- intern/raytrace/rayobject_octree.cpp
- intern/raytrace/rayobject_raycounter.cpp
- intern/raytrace/rayobject_svbvh.cpp
- intern/raytrace/rayobject_instance.cpp
- intern/raytrace/rayobject_qbvh.cpp
- intern/raytrace/rayobject_rtbuild.cpp
- intern/raytrace/rayobject_vbvh.cpp
- intern/source/bake.c
intern/source/bake_api.c
- intern/source/convertblender.c
- intern/source/envmap.c
intern/source/external_engine.c
intern/source/imagetexture.c
intern/source/initrender.c
intern/source/multires_bake.c
- intern/source/occlusion.c
intern/source/pipeline.c
- intern/source/pixelblending.c
- intern/source/pixelshading.c
intern/source/pointdensity.c
- intern/source/rayshade.c
- intern/source/rendercore.c
intern/source/render_result.c
intern/source/render_texture.c
- intern/source/renderdatabase.c
- intern/source/shadbuf.c
- intern/source/shadeinput.c
- intern/source/shadeoutput.c
- intern/source/sss.c
- intern/source/strand.c
- intern/source/sunsky.c
- intern/source/texture_ocean.c
- intern/source/volume_precache.c
- intern/source/volumetric.c
- intern/source/voxeldata.c
intern/source/zbuf.c
extern/include/RE_engine.h
@@ -92,38 +65,12 @@ set(SRC
extern/include/RE_pipeline.h
extern/include/RE_render_ext.h
extern/include/RE_shader_ext.h
- intern/include/envmap.h
intern/include/initrender.h
- intern/include/occlusion.h
- intern/include/pixelblending.h
- intern/include/pixelshading.h
- intern/include/pointdensity.h
- intern/include/raycounter.h
- intern/include/rayobject.h
- intern/include/rayintersection.h
intern/include/render_types.h
intern/include/render_result.h
- intern/include/rendercore.h
- intern/include/renderdatabase.h
intern/include/renderpipeline.h
- intern/include/shadbuf.h
- intern/include/shading.h
- intern/include/sss.h
- intern/include/strand.h
- intern/include/sunsky.h
intern/include/texture.h
- intern/include/texture_ocean.h
- intern/include/volume_precache.h
- intern/include/volumetric.h
- intern/include/voxeldata.h
intern/include/zbuf.h
- intern/raytrace/bvh.h
- intern/raytrace/rayobject_hint.h
- intern/raytrace/rayobject_internal.h
- intern/raytrace/rayobject_rtbuild.h
- intern/raytrace/reorganize.h
- intern/raytrace/svbvh.h
- intern/raytrace/vbvh.h
)
if(WITH_PYTHON)
@@ -148,10 +95,6 @@ if(WITH_FREESTYLE)
add_definitions(-DWITH_FREESTYLE)
endif()
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
if(WITH_INTERNATIONAL)
add_definitions(-DWITH_INTERNATIONAL)
endif()
diff --git a/source/blender/render/extern/include/RE_bake.h b/source/blender/render/extern/include/RE_bake.h
index 090e0e6c28d..76228d93e66 100644
--- a/source/blender/render/extern/include/RE_bake.h
+++ b/source/blender/render/extern/include/RE_bake.h
@@ -35,6 +35,7 @@
struct ImBuf;
struct Render;
struct Mesh;
+struct ViewLayer;
typedef struct BakeImage {
struct Image *image;
@@ -71,14 +72,11 @@ typedef struct BakeHighPolyData {
bool RE_bake_has_engine(struct Render *re);
bool RE_bake_engine(
- struct Render *re, struct Object *object, const int object_id, const BakePixel pixel_array[],
+ struct Render *re, struct ViewLayer *view_layer, struct Object *object, const int object_id, const BakePixel pixel_array[],
const size_t num_pixels, const int depth, const eScenePassType pass_type, const int pass_filter, float result[]);
/* bake.c */
int RE_pass_depth(const eScenePassType pass_type);
-bool RE_bake_internal(
- struct Render *re, struct Object *object, const BakePixel pixel_array[],
- const size_t num_pixels, const int depth, const eScenePassType pass_type, float result[]);
bool RE_bake_pixels_populate_from_objects(
struct Mesh *me_low, BakePixel pixel_array_from[], BakePixel pixel_array_to[],
diff --git a/source/blender/render/extern/include/RE_engine.h b/source/blender/render/extern/include/RE_engine.h
index 321eda0175f..e857d508424 100644
--- a/source/blender/render/extern/include/RE_engine.h
+++ b/source/blender/render/extern/include/RE_engine.h
@@ -39,6 +39,12 @@
struct bNode;
struct bNodeTree;
+struct BakePixel;
+struct Depsgraph;
+struct Depsgraph;
+struct Depsgraph;
+struct IDProperty;
+struct Main;
struct Object;
struct Render;
struct RenderData;
@@ -48,13 +54,13 @@ struct RenderLayer;
struct RenderResult;
struct ReportList;
struct Scene;
-struct BakePixel;
+struct ViewLayer;
/* External Engine */
/* RenderEngineType.flag */
#define RE_INTERNAL 1
-#define RE_GAME 2
+/* #define RE_FLAG_DEPRECATED 2 */
#define RE_USE_PREVIEW 4
#define RE_USE_POSTPROCESS 8
#define RE_USE_SHADING_NODES 16
@@ -89,14 +95,22 @@ typedef struct RenderEngineType {
int flag;
void (*update)(struct RenderEngine *engine, struct Main *bmain, struct Scene *scene);
- void (*render)(struct RenderEngine *engine, struct Scene *scene);
- void (*bake)(struct RenderEngine *engine, struct Scene *scene, struct Object *object, const int pass_type, const int pass_filter, const int object_id, const struct BakePixel *pixel_array, const int num_pixels, const int depth, void *result);
+ void (*render_to_image)(struct RenderEngine *engine, struct Depsgraph *depsgraph);
+ void (*bake)(struct RenderEngine *engine, struct Depsgraph *depsgraph,
+ struct Scene *scene, struct Object *object, const int pass_type,
+ const int pass_filter, const int object_id, const struct BakePixel *pixel_array, const int num_pixels,
+ const int depth, void *result);
void (*view_update)(struct RenderEngine *engine, const struct bContext *context);
- void (*view_draw)(struct RenderEngine *engine, const struct bContext *context);
+ void (*render_to_view)(struct RenderEngine *engine, const struct bContext *context);
void (*update_script_node)(struct RenderEngine *engine, struct bNodeTree *ntree, struct bNode *node);
- void (*update_render_passes)(struct RenderEngine *engine, struct Scene *scene, struct SceneRenderLayer *srl);
+ void (*update_render_passes)(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer);
+
+ void (*collection_settings_create)(struct RenderEngine *engine, struct IDProperty *props);
+ void (*render_settings_create)(struct RenderEngine *engine, struct IDProperty *props);
+
+ struct DrawEngineType *draw_engine;
/* RNA integration */
ExtensionRNA ext;
@@ -121,6 +135,9 @@ typedef struct RenderEngine {
struct ReportList *reports;
+ /* Depsgraph */
+ struct Depsgraph *depsgraph;
+
/* for blender internal only */
int update_flag;
int job_update_flag;
@@ -163,19 +180,23 @@ bool RE_engine_is_external(struct Render *re);
void RE_engine_frame_set(struct RenderEngine *engine, int frame, float subframe);
-void RE_engine_register_pass(struct RenderEngine *engine, struct Scene *scene, struct SceneRenderLayer *srl,
+void RE_engine_register_pass(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer,
const char *name, int channels, const char *chanid, int type);
/* Engine Types */
void RE_engines_init(void);
void RE_engines_exit(void);
+void RE_engines_register(struct Main *bmain, RenderEngineType *render_type);
+
+bool RE_engine_is_opengl(RenderEngineType *render_type);
RenderEngineType *RE_engines_find(const char *idname);
rcti* RE_engine_get_current_tiles(struct Render *re, int *r_total_tiles, bool *r_needs_free);
struct RenderData *RE_engine_get_render_data(struct Render *re);
-void RE_bake_engine_set_engine_parameters(struct Render *re, struct Main *bmain, struct Scene *scene);
+void RE_bake_engine_set_engine_parameters(
+ struct Render *re, struct Main *bmain, struct Scene *scene);
#endif /* __RE_ENGINE_H__ */
diff --git a/source/blender/render/extern/include/RE_multires_bake.h b/source/blender/render/extern/include/RE_multires_bake.h
index c1c5fc4a04d..901c1c1d05d 100644
--- a/source/blender/render/extern/include/RE_multires_bake.h
+++ b/source/blender/render/extern/include/RE_multires_bake.h
@@ -43,6 +43,12 @@ typedef struct MultiresBakeRender {
short mode;
bool use_lores_mesh; /* Use low-resolution mesh when baking displacement maps */
+ /* material aligned image array (for per-face bake image) */
+ struct {
+ Image **array;
+ int len;
+ } ob_image;
+
int number_of_rays; /* Number of rays to be cast when doing AO baking */
float bias; /* Bias between object and start ray point when doing AO baking */
diff --git a/source/blender/render/extern/include/RE_pipeline.h b/source/blender/render/extern/include/RE_pipeline.h
index 8065de831ba..056e236f60e 100644
--- a/source/blender/render/extern/include/RE_pipeline.h
+++ b/source/blender/render/extern/include/RE_pipeline.h
@@ -34,9 +34,11 @@
#include "DNA_listBase.h"
#include "DNA_vec_types.h"
+#include "DEG_depsgraph.h"
struct bMovieHandle;
struct bNodeTree;
+struct Depsgraph;
struct Image;
struct ImageFormatData;
struct Main;
@@ -46,8 +48,7 @@ struct RenderData;
struct RenderResult;
struct ReportList;
struct Scene;
-struct SceneRenderLayer;
-struct EnvMap;
+struct ViewLayer;
struct StampData;
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
@@ -105,12 +106,8 @@ typedef struct RenderLayer {
/* copy of RenderData */
char name[RE_MAXNAME];
- unsigned int lay, lay_zmask, lay_exclude;
int layflag, passflag, pass_xor;
- struct Material *mat_override;
- struct Group *light_override;
-
/* MULTIVIEW_TODO: acolrect and scolrect are not supported by multiview at the moment.
* If they are really required they should be in RenderView instead */
@@ -122,7 +119,7 @@ typedef struct RenderLayer {
/* optional saved endresult on disk */
void *exrhandle;
-
+
ListBase passes;
} RenderLayer;
@@ -243,7 +240,7 @@ struct RenderPass *RE_create_gp_pass(struct RenderResult *rr, const char *layern
/* obligatory initialize call, disprect is optional */
void RE_InitState(struct Render *re, struct Render *source, struct RenderData *rd,
- struct SceneRenderLayer *srl,
+ struct ListBase *render_layers, struct ViewLayer *single_layer,
int winx, int winy, rcti *disprect);
void RE_ChangeResolution(struct Render *re, int winx, int winy, rcti *disprect);
void RE_ChangeModeFlag(struct Render *re, int flag, bool clear);
@@ -252,10 +249,8 @@ void RE_ChangeModeFlag(struct Render *re, int flag, bool clear);
struct Object *RE_GetCamera(struct Render *re); /* return camera override if set */
void RE_SetOverrideCamera(struct Render *re, struct Object *camera);
void RE_SetCamera(struct Render *re, struct Object *camera);
-void RE_SetEnvmapCamera(struct Render *re, struct Object *cam_ob, float viewscale, float clipsta, float clipend);
void RE_SetWindow(struct Render *re, const rctf *viewplane, float clipsta, float clipend);
void RE_SetOrtho(struct Render *re, const rctf *viewplane, float clipsta, float clipend);
-void RE_SetPixelSize(struct Render *re, float pixsize);
/* option to set viewmatrix before making dbase */
void RE_SetView(struct Render *re, float mat[4][4]);
@@ -265,23 +260,13 @@ void RE_GetView(struct Render *re, float mat[4][4]);
void RE_GetViewPlane(struct Render *re, rctf *r_viewplane, rcti *r_disprect);
/* make or free the dbase */
-void RE_Database_FromScene(
+void RE_Database_CameraOnly(
struct Render *re, struct Main *bmain, struct Scene *scene,
unsigned int lay, int use_camera_view);
-void RE_Database_Preprocess(struct Render *re);
-void RE_Database_Free(struct Render *re);
-
-/* project dbase again, when viewplane/perspective changed */
-void RE_DataBase_ApplyWindow(struct Render *re);
-/* rotate scene again, for incremental render */
-void RE_DataBase_IncrementalView(struct Render *re, float viewmat[4][4], int restore);
/* set the render threads based on the commandline and autothreads setting */
void RE_init_threadcount(Render *re);
-/* the main processor, assumes all was set OK! */
-void RE_TileProcessor(struct Render *re);
-
bool RE_WriteRenderViewsImage(
struct ReportList *reports, struct RenderResult *rr, struct Scene *scene, const bool stamp, char *name);
bool RE_WriteRenderViewsMovie(
@@ -291,7 +276,7 @@ bool RE_WriteRenderViewsMovie(
/* only RE_NewRender() needed, main Blender render calls */
void RE_BlenderFrame(struct Render *re, struct Main *bmain, struct Scene *scene,
- struct SceneRenderLayer *srl, struct Object *camera_override,
+ struct ViewLayer *single_layer, struct Object *camera_override,
unsigned int lay_override, int frame, const bool write_still);
void RE_BlenderAnim(struct Render *re, struct Main *bmain, struct Scene *scene, struct Object *camera_override,
unsigned int lay_override, int sfra, int efra, int tfra);
@@ -316,14 +301,6 @@ bool RE_WriteRenderResult(
struct RenderResult *RE_MultilayerConvert(
void *exrhandle, const char *colorspace, bool predivide, int rectx, int recty);
-extern const float default_envmap_layout[];
-bool RE_WriteEnvmapResult(
- struct ReportList *reports, struct Scene *scene, struct EnvMap *env,
- const char *relpath, const char imtype, float layout[12]);
-
-/* do a full sample buffer compo */
-void RE_MergeFullSample(struct Render *re, struct Main *bmain, struct Scene *sce, struct bNodeTree *ntree);
-
/* display and event callbacks */
void RE_display_init_cb (struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr));
void RE_display_clear_cb(struct Render *re, void *handle, void (*f)(void *handle, RenderResult *rr));
@@ -346,43 +323,18 @@ struct RenderPass *RE_pass_find_by_name(volatile struct RenderLayer *rl, const c
struct RenderPass *RE_pass_find_by_type(volatile struct RenderLayer *rl, int passtype, const char *viewname);
/* shaded view or baking options */
-#define RE_BAKE_LIGHT 0 /* not listed in rna_scene.c -> can't be enabled! */
-#define RE_BAKE_ALL 1
+#define RE_BAKE_NORMALS 0
+#define RE_BAKE_DISPLACEMENT 1
#define RE_BAKE_AO 2
-#define RE_BAKE_NORMALS 3
-#define RE_BAKE_TEXTURE 4
-#define RE_BAKE_DISPLACEMENT 5
-#define RE_BAKE_SHADOW 6
-#define RE_BAKE_SPEC_COLOR 7
-#define RE_BAKE_SPEC_INTENSITY 8
-#define RE_BAKE_MIRROR_COLOR 9
-#define RE_BAKE_MIRROR_INTENSITY 10
-#define RE_BAKE_ALPHA 11
-#define RE_BAKE_EMIT 12
-#define RE_BAKE_DERIVATIVE 13
-#define RE_BAKE_VERTEX_COLORS 14
-
-void RE_Database_Baking(
- struct Render *re, struct Main *bmain, struct Scene *scene,
- unsigned int lay, const int type, struct Object *actob);
-void RE_DataBase_GetView(struct Render *re, float mat[4][4]);
void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[4][4]);
void RE_GetCameraModelMatrix(struct Render *re, struct Object *camera, float r_mat[4][4]);
struct Scene *RE_GetScene(struct Render *re);
-bool RE_force_single_renderlayer(struct Scene *scene);
-bool RE_is_rendering_allowed(struct Scene *scene, struct Object *camera_override, struct ReportList *reports);
+bool RE_is_rendering_allowed(struct Scene *scene, struct ViewLayer *single_layer, struct Object *camera_override, struct ReportList *reports);
bool RE_allow_render_generic_object(struct Object *ob);
-/* RE_updateRenderInstances flag */
-enum {
- RE_OBJECT_INSTANCES_UPDATE_VIEW = (1 << 0),
- RE_OBJECT_INSTANCES_UPDATE_OBMAT = (1 << 1)
-};
-void RE_updateRenderInstances(Render *re, int flag);
-
/******* defined in render_result.c *********/
bool RE_HasCombinedLayer(RenderResult *res);
diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h
index 971be381f97..3b4b9262465 100644
--- a/source/blender/render/extern/include/RE_render_ext.h
+++ b/source/blender/render/extern/include/RE_render_ext.h
@@ -38,9 +38,12 @@
/* called by meshtools */
struct DerivedMesh;
+struct Depsgraph;
struct ImagePool;
struct MTex;
struct Scene;
+struct ViewLayer;
+struct Render;
/* render_texture.c */
/* used by particle.c, effect.c, editmesh_modes.c and brush.c, returns 1 if rgb, 0 otherwise */
@@ -53,12 +56,6 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen
void RE_texture_rng_init(void);
void RE_texture_rng_exit(void);
-struct Material *RE_sample_material_init(struct Material *orig_mat, struct Scene *scene);
-void RE_sample_material_free(struct Material *mat);
-void RE_sample_material_color(
- struct Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3],
- int tri_index, struct DerivedMesh *orcoDm, struct Object *ob);
-
/* imagetexture.c */
void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float result[4]);
@@ -66,23 +63,22 @@ void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, flo
struct PointDensity;
void RE_point_density_cache(
- struct Scene *scene,
- struct PointDensity *pd,
- const bool use_render_params);
+ struct Depsgraph *depsgraph,
+ struct PointDensity *pd);
void RE_point_density_minmax(
- struct Scene *scene,
+ struct Depsgraph *depsgraph,
struct PointDensity *pd,
- const bool use_render_params,
float r_min[3], float r_max[3]);
void RE_point_density_sample(
- struct Scene *scene,
+ struct Depsgraph *depsgraph,
struct PointDensity *pd,
const int resolution,
- const bool use_render_params,
float *values);
void RE_point_density_free(struct PointDensity *pd);
+void RE_point_density_fix_linking(void);
+
#endif /* __RE_RENDER_EXT_H__ */
diff --git a/source/blender/render/extern/include/RE_shader_ext.h b/source/blender/render/extern/include/RE_shader_ext.h
index e1cb922f6a5..0d354c27e3a 100644
--- a/source/blender/render/extern/include/RE_shader_ext.h
+++ b/source/blender/render/extern/include/RE_shader_ext.h
@@ -33,7 +33,7 @@
#define __RE_SHADER_EXT_H__
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* this include is for shading and texture exports */
+/* this include is for texture exports */
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
/* localized texture result data */
@@ -44,150 +44,6 @@ typedef struct TexResult {
float *nor;
} TexResult;
-/* localized shade result data */
-typedef struct ShadeResult {
- float combined[4];
- float col[4];
- float alpha, mist, z;
- float emit[3];
- float diff[3]; /* diffuse with no ramps, shadow, etc */
- float diffshad[3]; /* diffuse with shadow */
- float spec[3]; /* specular with shadow */
- float shad[4]; /* shad[3] is shadow intensity */
- float ao[3];
- float env[3];
- float indirect[3];
- float refl[3];
- float refr[3];
- float nor[3];
- float winspeed[4];
- float rayhits[4];
-} ShadeResult;
-
-/* only here for quick copy */
-struct ShadeInputCopy {
-
- struct Material *mat;
- struct VlakRen *vlr;
- struct StrandRen *strand;
- struct ObjectInstanceRen *obi;
- struct ObjectRen *obr;
- int facenr;
- float facenor[3]; /* copy from face */
- short flippednor; /* is facenor flipped? */
- struct VertRen *v1, *v2, *v3; /* vertices can be in any order for quads... */
- short i1, i2, i3; /* original vertex indices */
- short puno;
- short osatex;
- float vn[3], vno[3]; /* actual render normal, and a copy to restore it */
- float n1[3], n2[3], n3[3]; /* vertex normals, corrected */
- int mode, mode2; /* base material mode (OR-ed result of entire node tree) */
-};
-
-typedef struct ShadeInputUV {
- float dxuv[3], dyuv[3], uv[3];
- const char *name;
-} ShadeInputUV;
-
-typedef struct ShadeInputCol {
- float col[4];
- const char *name;
-} ShadeInputCol;
-
-/* localized renderloop data */
-typedef struct ShadeInput {
- /* copy from face, also to extract tria from quad */
- /* note it mirrors a struct above for quick copy */
-
- struct Material *mat;
- struct VlakRen *vlr;
- struct StrandRen *strand;
- struct ObjectInstanceRen *obi;
- struct ObjectRen *obr;
- int facenr;
- float facenor[3]; /* copy from face */
- short flippednor; /* is facenor flipped? */
- struct VertRen *v1, *v2, *v3; /* vertices can be in any order for quads... */
- short i1, i2, i3; /* original vertex indices */
- short puno;
- short osatex;
- float vn[3], vno[3]; /* actual render normal, and a copy to restore it */
- float n1[3], n2[3], n3[3]; /* vertex normals, corrected */
- int mode, mode2; /* base material mode (OR-ed result of entire node tree) */
-
- /* internal face coordinates */
- float u, v, dx_u, dx_v, dy_u, dy_v;
- float co[3], view[3], camera_co[3];
-
- /* copy from material, keep synced so we can do memcopy */
- /* current size: 23*4 */
- float r, g, b;
- float specr, specg, specb;
- float mirr, mirg, mirb;
- float ambr, ambb, ambg;
-
- float amb, emit, ang, spectra, ray_mirror;
- float alpha, refl, spec, zoffs, add;
- float translucency;
- /* end direct copy from material */
-
- /* individual copies: */
- int har; /* hardness */
-
- /* texture coordinates */
- float lo[3], gl[3], ref[3], orn[3], winco[3], vcol[4];
- float refcol[4], displace[3];
- float strandco, tang[3], nmapnorm[3], nmaptang[4], stress, winspeed[4];
- float duplilo[3], dupliuv[3];
- float tangents[8][4]; /* 8 = MAX_MTFACE */
-
- ShadeInputUV uv[8]; /* 8 = MAX_MTFACE */
- ShadeInputCol col[8]; /* 8 = MAX_MCOL */
- int totuv, totcol, actuv, actcol;
-
- /* dx/dy OSA coordinates */
- float dxco[3], dyco[3];
- float dxlo[3], dylo[3], dxgl[3], dygl[3];
- float dxref[3], dyref[3], dxorn[3], dyorn[3];
- float dxno[3], dyno[3], dxview, dyview;
- float dxlv[3], dylv[3];
- float dxwin[3], dywin[3];
- float dxrefract[3], dyrefract[3];
- float dxstrand, dystrand;
-
- /* AO is a pre-process now */
- float ao[3], indirect[3], env[3];
-
- int xs, ys; /* pixel to be rendered */
- int mask; /* subsample mask */
- float scanco[3]; /* original scanline coordinate without jitter */
-
- int samplenr; /* sample counter, to detect if we should do shadow again */
- int depth; /* 1 or larger on raytrace shading */
- int volume_depth; /* number of intersections through volumes */
-
- /* for strand shading, normal at the surface */
- float surfnor[3], surfdist;
-
- /* from initialize, part or renderlayer */
- bool do_preview; /* for nodes, in previewrender */
- bool do_manage; /* color management flag */
- bool use_world_space_shading;
- short thread, sample; /* sample: ShadeSample array index */
- short nodes; /* indicate node shading, temp hack to prevent recursion */
-
- unsigned int lay;
- int layflag, passflag, combinedflag;
- short object_pass_index;
- struct Group *light_override;
- struct Material *mat_override;
-
-#ifdef RE_RAYCOUNTER
- RayCounter raycounter;
-#endif
-
-} ShadeInput;
-
typedef struct BakeImBufuserData {
float *displacement_buffer;
char *mask_buffer;
@@ -214,46 +70,6 @@ int multitex_ext(struct Tex *tex,
int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres, struct ImagePool *pool, bool scene_color_manage, const bool skip_load_image);
/* only for internal node usage */
int multitex_nodes(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres,
- const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex,
- struct ImagePool *pool);
-float RE_lamp_get_data(struct ShadeInput *shi, struct Object *lamp_obj, float col[4], float lv[3], float *dist, float shadow[4]);
-void RE_instance_get_particle_info(struct ObjectInstanceRen *obi, float *index, float *random, float *age, float *lifetime, float co[3], float *size, float vel[3], float angvel[3]);
-
-float RE_fresnel_dielectric(float incoming[3], float normal[3], float eta);
-
-/* shaded view and bake */
-struct Render;
-struct Image;
-
-int RE_bake_shade_all_selected(struct Render *re, int type, struct Object *actob, short *do_update, float *progress);
-struct Image *RE_bake_shade_get_image(void);
-void RE_bake_ibuf_filter(struct ImBuf *ibuf, char *mask, const int filter);
-void RE_bake_ibuf_normalize_displacement(struct ImBuf *ibuf, float *displacement, char *mask, float displacement_min, float displacement_max);
-float RE_bake_make_derivative(struct ImBuf *ibuf, float *heights_buffer, const char *mask,
- const float height_min, const float height_max,
- const float fmult);
-
-enum {
- RE_OBJECT_INSTANCE_MATRIX_OB,
- RE_OBJECT_INSTANCE_MATRIX_OBINV,
- RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW,
- RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEWINV,
-};
-
-const float (*RE_object_instance_get_matrix(struct ObjectInstanceRen *obi, int matrix_id))[4];
-
-float RE_object_instance_get_object_pass_index(struct ObjectInstanceRen *obi);
-float RE_object_instance_get_random_id(struct ObjectInstanceRen *obi);
-
-enum {
- RE_VIEW_MATRIX,
- RE_VIEWINV_MATRIX,
-};
-
-const float (*RE_render_current_get_matrix(int matrix_id))[4];
-
-#define BAKE_RESULT_OK 0
-#define BAKE_RESULT_NO_OBJECTS 1
-#define BAKE_RESULT_FEEDBACK_LOOP 2
+ const short thread, short which_output, struct MTex *mtex, struct ImagePool *pool);
#endif /* __RE_SHADER_EXT_H__ */
diff --git a/source/blender/render/intern/include/envmap.h b/source/blender/render/intern/include/envmap.h
deleted file mode 100644
index 627e6c0e1e6..00000000000
--- a/source/blender/render/intern/include/envmap.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * envmap_ext.h
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/envmap.h
- * \ingroup render
- */
-
-
-#ifndef __ENVMAP_H__
-#define __ENVMAP_H__
-
-/**
- * Make environment maps for all objects in the scene that have an
- * environment map as texture.
- * (initrender.c)
- */
-
-struct Render;
-struct TexResult;
-struct ImagePool;
-
-void make_envmaps(struct Render *re);
-int envmaptex(struct Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, struct ImagePool *pool, const bool skip_image_load);
-void env_rotate_scene(struct Render *re, float mat[4][4], int do_rotate);
-
-#endif /* __ENVMAP_H__ */
-
diff --git a/source/blender/render/intern/include/initrender.h b/source/blender/render/intern/include/initrender.h
index 87e2d2519d5..e7ff3c7097c 100644
--- a/source/blender/render/intern/include/initrender.h
+++ b/source/blender/render/intern/include/initrender.h
@@ -33,16 +33,11 @@
#ifndef __INITRENDER_H__
#define __INITRENDER_H__
-
/* Functions */
-void free_sample_tables(Render *re);
-void make_sample_tables(Render *re);
-
-void RE_parts_init(Render *re, bool do_crop);
+void RE_parts_init(Render *re);
void RE_parts_free(Render *re);
void RE_parts_clamp(Render *re);
-
#endif /* __INITRENDER_H__ */
diff --git a/source/blender/render/intern/include/occlusion.h b/source/blender/render/intern/include/occlusion.h
deleted file mode 100644
index 4a70d691436..00000000000
--- a/source/blender/render/intern/include/occlusion.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Brecht Van Lommel.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/occlusion.h
- * \ingroup render
- */
-
-
-#ifndef __OCCLUSION_H__
-#define __OCCLUSION_H__
-
-struct Render;
-struct ShadeInput;
-struct RenderPart;
-struct ShadeSample;
-
-void make_occ_tree(struct Render *re);
-void free_occ(struct Render *re);
-void sample_occ(struct Render *re, struct ShadeInput *shi);
-
-void cache_occ_samples(struct Render *re, struct RenderPart *pa, struct ShadeSample *ssamp);
-void free_occ_samples(struct Render *re, struct RenderPart *pa);
-
-#endif
-
diff --git a/source/blender/render/intern/include/pixelblending.h b/source/blender/render/intern/include/pixelblending.h
deleted file mode 100644
index 17a872a0676..00000000000
--- a/source/blender/render/intern/include/pixelblending.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): 2004-2006 Blender Foundation, full recode
- *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/pixelblending.h
- * \ingroup render
- */
-
-
-#ifndef __PIXELBLENDING_H__
-#define __PIXELBLENDING_H__
-
-
-/**
- * add 1 pixel to into filtered three lines
- * (float vecs to float vec)
- */
-void add_filt_fmask(unsigned int mask, const float col[4], float *rowbuf, int row_w);
-void add_filt_fmask_pixsize(unsigned int mask, float *in, float *rowbuf, int row_w, int pixsize);
-void add_filt_fmask_coord(float filt[3][3], const float col[4], float *rowbuf, int row_stride, int x, int y, rcti *mask);
-void mask_array(unsigned int mask, float filt[3][3]);
-
-/**
- * Alpha-over blending for floats.
- */
-void addAlphaOverFloat(float dest[4], const float source[4]);
-
-/**
- * Alpha-under blending for floats.
- */
-void addAlphaUnderFloat(float dest[4], const float source[4]);
-
-
-/**
- * Same for floats
- */
-void addalphaAddfacFloat(float dest[4], const float source[4], char addfac);
-
-/**
- * dest = dest + source
- */
-void addalphaAddFloat(float dest[4], const float source[4]);
-
-#endif /* __PIXELBLENDING_H__ */
diff --git a/source/blender/render/intern/include/pixelshading.h b/source/blender/render/intern/include/pixelshading.h
deleted file mode 100644
index 8f23455564f..00000000000
--- a/source/blender/render/intern/include/pixelshading.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): 2004-2006, Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/pixelshading.h
- * \ingroup render
- *
- * These functions determine what actual color a pixel will have.
- */
-
-#ifndef __PIXELSHADING_H__
-#define __PIXELSHADING_H__
-
-
-/**
- * Render the pixel at (x,y) for object ap. Apply the jitter mask.
- * Output is given in float collector[4]. The type vector:
- * t[0] - min. distance
- * t[1] - face/halo index
- * t[2] - jitter mask
- * t[3] - type ZB_POLY or ZB_HALO
- * t[4] - max. distance
- * mask is pixel coverage in bits
- * \return pointer to the object
- */
-int shadeHaloFloat(HaloRen *har,
- float *col, int zz,
- float dist, float xn,
- float yn, short flarec);
-
-/**
- * Render the sky at pixel (x, y).
- */
-void shadeSkyPixel(float collector[4], float fx, float fy, short thread);
-void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const float dxyview[2], short thread);
-void shadeAtmPixel(struct SunSky *sunsky, float *collector, float fx, float fy, float distance);
-void shadeSunView(float col_r[3], const float view[3]);
-/* ------------------------------------------------------------------------- */
-
-#endif
-
diff --git a/source/blender/render/intern/include/pointdensity.h b/source/blender/render/intern/include/pointdensity.h
deleted file mode 100644
index 1d1e808e8d3..00000000000
--- a/source/blender/render/intern/include/pointdensity.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Matt Ebb
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/pointdensity.h
- * \ingroup render
- */
-
-
-#ifndef __POINTDENSITY_H__
-#define __POINTDENSITY_H__
-
-/**
- * Make point density kd-trees for all point density textures in the scene
- */
-
-struct PointDensity;
-struct Render;
-struct TexResult;
-
-void free_pointdensity(struct PointDensity *pd);
-void cache_pointdensity(struct Render *re, struct PointDensity *pd);
-void make_pointdensities(struct Render *re);
-void free_pointdensities(struct Render *re);
-int pointdensitytex(struct Tex *tex, const float texvec[3], struct TexResult *texres);
-
-#endif /* __POINTDENSITY_H__ */
-
diff --git a/source/blender/render/intern/include/raycounter.h b/source/blender/render/intern/include/raycounter.h
deleted file mode 100644
index 1694273df0e..00000000000
--- a/source/blender/render/intern/include/raycounter.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/raycounter.h
- * \ingroup render
- */
-
-
-#ifndef __RAYCOUNTER_H__
-#define __RAYCOUNTER_H__
-
-//#define RE_RAYCOUNTER /* enable counters per ray, useful for measuring raytrace structures performance */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#ifdef RE_RAYCOUNTER
-
-/* ray counter functions */
-
-typedef struct RayCounter {
- struct {
- unsigned long long test, hit;
- } faces, bb, simd_bb, raycast, raytrace_hint, rayshadow_last_hit;
-} RayCounter;
-
-#define RE_RC_INIT(isec, shi) (isec).raycounter = &((shi).shading.raycounter)
-void RE_RC_INFO(RayCounter *rc);
-void RE_RC_MERGE(RayCounter *rc, RayCounter *tmp);
-#define RE_RC_COUNT(var) (var)++
-
-extern RayCounter re_rc_counter[];
-
-#else
-
-/* ray counter stubs */
-
-#define RE_RC_INIT(isec,shi)
-#define RE_RC_INFO(rc)
-#define RE_RC_MERGE(dest,src)
-#define RE_RC_COUNT(var)
-
-#endif
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/source/blender/render/intern/include/rayintersection.h b/source/blender/render/intern/include/rayintersection.h
deleted file mode 100644
index 1935e4ef59c..00000000000
--- a/source/blender/render/intern/include/rayintersection.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2007 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- * RE_raytrace.h: ray tracing api, can be used independently from the renderer.
- */
-
-/** \file blender/render/intern/include/rayintersection.h
- * \ingroup render
- */
-
-
-#ifndef __RAYINTERSECTION_H__
-#define __RAYINTERSECTION_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "BLI_math_geom.h"
-
-struct RayObject;
-
-/* Ray Hints */
-
-#define RE_RAY_LCTS_MAX_SIZE 256
-#define RT_USE_LAST_HIT /* last shadow hit is reused before raycasting on whole tree */
-//#define RT_USE_HINT /* last hit object is reused before raycasting on whole tree */
-
-typedef struct LCTSHint {
- int size;
- struct RayObject *stack[RE_RAY_LCTS_MAX_SIZE];
-} LCTSHint;
-
-typedef struct RayHint {
- union { LCTSHint lcts; } data;
-} RayHint;
-
-/* Ray Intersection */
-
-typedef struct Isect {
- /* ray start, direction (normalized vector), and max distance. on hit,
- * the distance is modified to be the distance to the hit point. */
- float start[3];
- float dir[3];
- float dist;
-
- /* for envmap and incremental view update renders */
- float origstart[3];
- float origdir[3];
-
- /* precomputed values to accelerate bounding box intersection */
- int bv_index[6];
- float idot_axis[3];
-
- /* intersection options */
- int mode; /* RE_RAY_SHADOW, RE_RAY_MIRROR, RE_RAY_SHADOW_TRA */
- int lay; /* -1 default, set for layer lamps */
- int skip; /* skip flags */
- int check; /* check flags */
- void *userdata; /* used by bake check */
-
- /* hit information */
- float u, v;
- int isect; /* which half of quad */
-
- struct {
- void *ob;
- void *face;
- } hit, orig;
-
- /* last hit optimization */
- struct RayObject *last_hit;
-
- /* hints */
-#ifdef RT_USE_HINT
- RayTraceHint *hint, *hit_hint;
-#endif
- RayHint *hint;
-
- /* ray counter */
-#ifdef RE_RAYCOUNTER
- RayCounter *raycounter;
-#endif
-
- /* Precalculated coefficients for watertight intersection check. */
- struct IsectRayPrecalc isect_precalc;
-} Isect;
-
-/* ray types */
-#define RE_RAY_SHADOW 0
-#define RE_RAY_MIRROR 1
-#define RE_RAY_SHADOW_TRA 2
-
-/* skip options */
-#define RE_SKIP_CULLFACE (1 << 0)
-/* if using this flag then *face should be a pointer to a VlakRen */
-#define RE_SKIP_VLR_NEIGHBOUR (1 << 1)
-
-/* check options */
-#define RE_CHECK_VLR_NONE 0
-#define RE_CHECK_VLR_RENDER 1
-#define RE_CHECK_VLR_NON_SOLID_MATERIAL 2
-#define RE_CHECK_VLR_BAKE 3
-
-/* arbitrary, but can't use e.g. FLT_MAX because of precision issues */
-#define RE_RAYTRACE_MAXDIST 1e15f
-#define RE_RAYTRACE_EPSILON 0.0f
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __RAYINTERSECTION_H__ */
-
diff --git a/source/blender/render/intern/include/rayobject.h b/source/blender/render/intern/include/rayobject.h
deleted file mode 100644
index 63135d01c23..00000000000
--- a/source/blender/render/intern/include/rayobject.h
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/rayobject.h
- * \ingroup render
- */
-
-
-#ifndef __RAYOBJECT_H__
-#define __RAYOBJECT_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct Isect;
-struct ObjectInstanceRen;
-struct RayHint;
-struct VlakRen;
-
-/* RayObject
- * Can be a face/triangle, bvh tree, object instance, etc. This is the
- * public API used by the renderer, see rayobject_internal.h for the
- * internal implementation details.
- * */
-typedef struct RayObject RayObject;
-
-/* Intersection, see rayintersection.h */
-
-int RE_rayobject_raycast(RayObject *r, struct Isect *i);
-
-/* Acceleration Structures */
-
-RayObject *RE_rayobject_octree_create(int ocres, int size);
-RayObject *RE_rayobject_instance_create(RayObject *target, float transform[4][4], void *ob, void *target_ob);
-RayObject *RE_rayobject_empty_create(void);
-
-RayObject *RE_rayobject_vbvh_create(int size); /* raytrace/rayobject_vbvh.c */
-RayObject *RE_rayobject_svbvh_create(int size); /* raytrace/rayobject_svbvh.c */
-RayObject *RE_rayobject_qbvh_create(int size); /* raytrace/rayobject_qbvh.c */
-
-/* Building */
-
-void RE_rayobject_add(RayObject *r, RayObject *);
-void RE_rayobject_done(RayObject *r);
-void RE_rayobject_free(RayObject *r);
-
-void RE_rayobject_set_control(RayObject *r, void *data, int (*test_break)(void *data));
-
-/* RayObject representing faces, all data is locally available instead
- * of referring to some external data structure, for possibly faster
- * intersection tests. */
-
-typedef struct RayFace {
- float v1[4], v2[4], v3[4], v4[3];
- int quad;
- void *ob;
- void *face;
-} RayFace;
-
-#define RE_rayface_isQuad(a) ((a)->quad)
-
-RayObject *RE_rayface_from_vlak(RayFace *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr);
-
-RayObject *RE_rayface_from_coords(RayFace *rayface, void *ob, void *face, float *v1, float *v2, float *v3, float *v4);
-
-/* RayObject representing faces directly from a given VlakRen structure. Thus
- * allowing to save memory, but making code triangle intersection dependent on
- * render structures. */
-
-typedef struct VlakPrimitive {
- struct ObjectInstanceRen *ob;
- struct VlakRen *face;
-} VlakPrimitive;
-
-RayObject *RE_vlakprimitive_from_vlak(VlakPrimitive *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr);
-
-/* Bounding Box */
-
-/* extend min/max coords so that the rayobject is inside them */
-void RE_rayobject_merge_bb(RayObject *ob, float *min, float *max);
-
-/* initializes an hint for optimizing raycast where it is know that a ray will pass by the given BB often the origin point */
-void RE_rayobject_hint_bb(RayObject *r, struct RayHint *hint, float min[3], float max[3]);
-
-/* initializes an hint for optimizing raycast where it is know that a ray will be contained inside the given cone*/
-/* void RE_rayobject_hint_cone(RayObject *r, struct RayHint *hint, float *); */
-
-/* Internals */
-
-#include "../raytrace/rayobject_internal.h"
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif
diff --git a/source/blender/render/intern/include/render_result.h b/source/blender/render/intern/include/render_result.h
index 8d293c938c7..9a1b1b5abe8 100644
--- a/source/blender/render/intern/include/render_result.h
+++ b/source/blender/render/intern/include/render_result.h
@@ -55,8 +55,6 @@ struct ColorManagedViewSettings;
struct RenderResult *render_result_new(struct Render *re,
struct rcti *partrct, int crop, int savebuffers, const char *layername, const char *viewname);
-struct RenderResult *render_result_new_full_sample(struct Render *re,
- struct ListBase *lb, struct rcti *partrct, int crop, int savebuffers, const char *viewname);
struct RenderResult *render_result_new_from_exr(void *exrhandle, const char *colorspace, bool predivide, int rectx, int recty);
@@ -117,5 +115,28 @@ void render_result_views_shallowcopy(struct RenderResult *dst, struct RenderResu
void render_result_views_shallowdelete(struct RenderResult *rr);
bool render_result_has_views(struct RenderResult *rr);
+#define FOREACH_VIEW_LAYER_TO_RENDER_BEGIN(re_, iter_) \
+{ \
+ int nr_; \
+ ViewLayer *iter_; \
+ for (nr_ = 0, iter_ = (re_)->view_layers.first; \
+ iter_ != NULL; \
+ iter_ = iter_->next, nr_++) \
+ { \
+ if ((re_)->r.scemode & R_SINGLE_LAYER) { \
+ if (nr_ != re->active_view_layer) { \
+ continue; \
+ } \
+ } \
+ else { \
+ if ((iter_->flag & VIEW_LAYER_RENDER) == 0) { \
+ continue; \
+ } \
+ }
+
+#define FOREACH_VIEW_LAYER_TO_RENDER_END \
+ } \
+} ((void)0)
+
#endif /* __RENDER_RESULT_H__ */
diff --git a/source/blender/render/intern/include/render_types.h b/source/blender/render/intern/include/render_types.h
index 45206f21ae4..8308b5e76e4 100644
--- a/source/blender/render/intern/include/render_types.h
+++ b/source/blender/render/intern/include/render_types.h
@@ -35,58 +35,19 @@
/* exposed internal in render module only! */
/* ------------------------------------------------------------------------- */
-#include "DNA_color_types.h"
-#include "DNA_customdata_types.h"
#include "DNA_scene_types.h"
-#include "DNA_world_types.h"
#include "DNA_object_types.h"
-#include "DNA_vec_types.h"
#include "BLI_threads.h"
#include "BKE_main.h"
#include "RE_pipeline.h"
-#include "RE_shader_ext.h" /* TexResult, ShadeResult, ShadeInput */
-#include "sunsky.h"
-#include "BLI_sys_types.h" // for intptr_t support
-
-struct EvaluationContext;
struct Object;
-struct MemArena;
-struct VertTableNode;
-struct VlakTableNode;
-struct GHash;
-struct ObjectInstanceRen;
-struct RayObject;
-struct RayFace;
struct RenderEngine;
struct ReportList;
struct Main;
-struct ImagePool;
-
-#define TABLEINITSIZE 1024
-
-typedef struct SampleTables {
- float centLut[16];
- float *fmask1[9], *fmask2[9];
- char cmask[256], *centmask;
-
-} SampleTables;
-
-typedef struct QMCSampler {
- struct QMCSampler *next, *prev;
- int type;
- int tot;
- int used;
- double *samp2d;
- double offs[BLENDER_MAX_THREADS][2];
-} QMCSampler;
-
-// #define SAMP_TYPE_JITTERED 0 // UNUSED
-#define SAMP_TYPE_HALTON 1
-#define SAMP_TYPE_HAMMERSLEY 2
/* this is handed over to threaded hiding/passes/shading engine */
typedef struct RenderPart {
@@ -95,24 +56,10 @@ typedef struct RenderPart {
RenderResult *result; /* result of part rendering */
ListBase fullresult; /* optional full sample buffers */
- int *recto; /* object table for objects */
- int *rectp; /* polygon index table */
- int *rectz; /* zbuffer */
- int *rectmask; /* negative zmask */
- intptr_t *rectdaps; /* delta acum buffer for pixel structs */
- int *rectbacko; /* object table for backside sss */
- int *rectbackp; /* polygon index table for backside sss */
- int *rectbackz; /* zbuffer for backside sss */
- intptr_t *rectall; /* buffer for all faces for sss */
-
rcti disprect; /* part coordinates within total picture */
int rectx, recty; /* the size */
int nr; /* nr is partnr */
- short crop, status; /* crop is amount of pixels we crop, for filter */
- short sample; /* sample can be used by zbuffers */
- short thread; /* thread id */
-
- char *clipflag; /* clipflags for part zbuffering */
+ short status;
} RenderPart;
enum {
@@ -129,10 +76,7 @@ struct Render {
int slot;
/* state settings */
- short flag, osa, ok, result_ok;
-
- /* due to performance issues, getting initialized from color management settings once on Render initialization */
- bool scene_color_manage;
+ short flag, ok, result_ok;
/* result of rendering */
RenderResult *result;
@@ -150,8 +94,6 @@ struct Render {
* without border & crop. convert to long before multiplying together to avoid overflow. */
rcti disprect; /* part within winx winy */
rctf viewplane; /* mapped on winx winy */
- float viewdx, viewdy; /* size of 1 pixel */
- float clipcrop; /* 2 pixel boundary to prevent clip when filter used */
/* final picture width and height (within disprect) */
int rectx, recty;
@@ -160,14 +102,7 @@ struct Render {
* partx*xparts can be larger than rectx, in that case last part is smaller */
int partx, party;
- /* values for viewing */
- float ycor; /* (scene->xasp / scene->yasp), multiplied with 'winy' */
-
- float panophi, panosi, panoco, panodxp, panodxv;
-
- /* Matrices */
- float grvec[3]; /* for world */
- float imat[3][3]; /* copy of viewinv */
+ /* Camera transform, only used by Freestyle. */
float viewmat[4][4], viewinv[4][4];
float viewmat_orig[4][4]; /* for incremental render */
float winmat[4][4];
@@ -176,21 +111,12 @@ struct Render {
float clipsta;
float clipend;
- /* samples */
- SampleTables *samples;
- float jit[32][2];
- float mblur_jit[32][2];
- ListBase *qmcsamplers;
- int num_qmc_samplers;
-
- /* shadow counter, detect shadow-reuse for shaders */
- int shadowsamplenr[BLENDER_MAX_THREADS];
-
/* main, scene, and its full copy of renderdata and world */
struct Main *main;
Scene *scene;
RenderData r;
- World wrld;
+ ListBase view_layers;
+ int active_view_layer;
struct Object *camera_override;
unsigned int lay, layer_override;
@@ -200,56 +126,11 @@ struct Render {
/* render engine */
struct RenderEngine *engine;
- /* octree tables and variables for raytrace */
- struct RayObject *raytree;
- struct RayFace *rayfaces;
- struct VlakPrimitive *rayprimitives;
- float maxdist; /* needed for keeping an incorrect behavior of SUN and HEMI lights (avoid breaking old scenes) */
-
- /* occlusion tree */
- void *occlusiontree;
- ListBase strandsurface;
-
- /* use this instead of R.r.cfra */
- float mblur_offs, field_offs;
-
- /* render database */
- int totvlak, totvert, tothalo, totstrand, totlamp;
- struct HaloRen **sortedhalos;
-
- ListBase lights; /* GroupObject pointers */
- ListBase lampren; /* storage, for free */
-
- ListBase objecttable;
-
- struct ObjectInstanceRen *objectinstance;
- ListBase instancetable;
- int totinstance;
-
- struct Image *bakebuf;
-
- struct GHash *orco_hash;
-
- struct GHash *sss_hash;
- ListBase *sss_points;
- struct Material *sss_mat;
-
- ListBase customdata_names;
-
- struct Object *excludeob;
- ListBase render_volumes_inside;
- ListBase volumes;
-
#ifdef WITH_FREESTYLE
struct Main *freestyle_bmain;
ListBase freestyle_renders;
#endif
- /* arena for allocating data for use during render, for
- * example dynamic TFaces to go in the VlakRen structure.
- */
- struct MemArena *memArena;
-
/* callbacks */
void (*display_init)(void *handle, RenderResult *rr);
void *dih;
@@ -274,415 +155,14 @@ struct Render {
struct ReportList *reports;
- struct ImagePool *pool;
- struct EvaluationContext *eval_ctx;
-
void **movie_ctx_arr;
char viewname[MAX_NAME];
};
-/* ------------------------------------------------------------------------- */
-
-struct ISBData;
-
-typedef struct DeepSample {
- int z;
- float v;
-} DeepSample;
-
-typedef struct ShadSampleBuf {
- struct ShadSampleBuf *next, *prev;
- intptr_t *zbuf;
- char *cbuf;
- DeepSample **deepbuf;
- int *totbuf;
-} ShadSampleBuf;
-
-typedef struct ShadBuf {
- /* regular shadowbuffer */
- short samp, shadhalostep, totbuf;
- float persmat[4][4];
- float viewmat[4][4];
- float winmat[4][4];
- float *jit, *weight;
- float d, clipend, pixsize, soft, compressthresh;
- int co[3];
- int size, bias;
- ListBase buffers;
-
- /* irregular shadowbufer, result stored per thread */
- struct ISBData *isb_result[BLENDER_MAX_THREADS];
-} ShadBuf;
-
-/* ------------------------------------------------------------------------- */
-
-typedef struct ObjectRen {
- struct ObjectRen *next, *prev;
- struct Object *ob, *par;
- struct Scene *sce;
- int index, psysindex, flag, lay;
-
- float boundbox[2][3];
-
- int totvert, totvlak, totstrand, tothalo;
- int vertnodeslen, vlaknodeslen, strandnodeslen, blohalen;
- struct VertTableNode *vertnodes;
- struct VlakTableNode *vlaknodes;
- struct StrandTableNode *strandnodes;
- struct HaloRen **bloha;
- struct StrandBuffer *strandbuf;
-
- char (*mtface)[MAX_CUSTOMDATA_LAYER_NAME];
- char (*mcol)[MAX_CUSTOMDATA_LAYER_NAME];
- int actmtface, actmcol, bakemtface;
-
- short tangent_mask; /* which tangent layer should be calculated */
-
- float obmat[4][4]; /* only used in convertblender.c, for instancing */
-
- /* used on makeraytree */
- struct RayObject *raytree;
- struct RayFace *rayfaces;
- struct VlakPrimitive *rayprimitives;
- struct ObjectInstanceRen *rayobi;
-
-} ObjectRen;
-
-typedef struct ObjectInstanceRen {
- struct ObjectInstanceRen *next, *prev;
-
- ObjectRen *obr;
- Object *ob, *par;
- int index, psysindex, lay;
-
- float mat[4][4], imat[4][4];
- float nmat[3][3]; /* nmat is inverse mat tranposed */
-
- float obmat[4][4], obinvmat[4][4];
- float localtoviewmat[4][4], localtoviewinvmat[4][4];
-
- short flag;
-
- float dupliorco[3], dupliuv[2];
- float (*duplitexmat)[4];
-
- struct VolumePrecache *volume_precache;
-
- float *vectors; /* (RE_WINSPEED_ELEMS * VertRen.index) */
- int totvector;
-
- /* used on makeraytree */
- struct RayObject *raytree;
- int transform_primitives;
-
- /* Particle info */
- float part_index;
- float part_age;
- float part_lifetime;
- float part_size;
- float part_co[3];
- float part_vel[3];
- float part_avel[3];
-
- unsigned int random_id;
-} ObjectInstanceRen;
-
-/* ------------------------------------------------------------------------- */
-
-typedef struct VertRen {
- float co[3];
- float n[3];
- float *orco;
- unsigned int flag; /* in use for clipping zbuffer parts, temp setting stuff in convertblender.c
- * only an 'int' because of alignment, could be a char too */
- float accum; /* accum for radio weighting, and for strand texco static particles */
- int index; /* index allows extending vertren with any property */
-} VertRen;
-
-/* ------------------------------------------------------------------------- */
-
-struct halosort {
- struct HaloRen *har;
- int z;
-};
-
-/* ------------------------------------------------------------------------- */
-struct Material;
-struct ImagePool;
-
-typedef struct RadFace {
- float unshot[3], totrad[3];
- float norm[3], cent[3], area;
- int flag;
-} RadFace;
-
-typedef struct VlakRen {
- struct VertRen *v1, *v2, *v3, *v4; /* keep in order for ** addressing */
- float n[3];
- struct Material *mat;
- char puno;
- char flag, ec;
-#ifdef WITH_FREESTYLE
- char freestyle_edge_mark;
- char freestyle_face_mark;
-#endif
- int index;
-} VlakRen;
-
-typedef struct HaloRen {
- short miny, maxy;
- float alfa, xs, ys, rad, radsq, sin, cos, co[3], no[3];
- float hard, b, g, r;
- int zs, zd;
- int zBufDist; /* depth in the z-buffer coordinate system */
- char starpoints, type, add, tex;
- char linec, ringc, seed;
- short flarec; /* used to be a char. why ?*/
- float hasize;
- int pixels;
- unsigned int lay;
- struct Material *mat;
- struct ImagePool *pool;
- bool skip_load_image, texnode_preview;
-} HaloRen;
-
-/* ------------------------------------------------------------------------- */
-
-typedef struct StrandVert {
- float co[3];
- float strandco;
-} StrandVert;
-
-typedef struct StrandSurface {
- struct StrandSurface *next, *prev;
- ObjectRen obr;
- int (*face)[4];
- float (*co)[3];
- /* for occlusion caching */
- float (*ao)[3];
- float (*env)[3];
- float (*indirect)[3];
- /* for speedvectors */
- float (*prevco)[3], (*nextco)[3];
- int totvert, totface;
-} StrandSurface;
-
-typedef struct StrandBound {
- int start, end;
- float boundbox[2][3];
-} StrandBound;
-
-typedef struct StrandBuffer {
- struct StrandBuffer *next, *prev;
- struct StrandVert *vert;
- struct StrandBound *bound;
- int totvert, totbound;
-
- struct ObjectRen *obr;
- struct Material *ma;
- struct StrandSurface *surface;
- unsigned int lay;
- int overrideuv;
- int flag, maxdepth;
- float adaptcos, minwidth, widthfade;
-
- float maxwidth; /* for cliptest of strands in blender unit */
-
- float winmat[4][4];
- int winx, winy;
-} StrandBuffer;
-
-typedef struct StrandRen {
- StrandVert *vert;
- StrandBuffer *buffer;
- int totvert, flag;
- int clip, index;
- float orco[3];
-} StrandRen;
-
-/* ------------------------------------------------------------------------- */
-
-typedef struct VolumeOb {
- struct VolumeOb *next, *prev;
- struct Material *ma;
- struct ObjectRen *obr;
-} VolumeOb;
-
-typedef struct MatInside {
- struct MatInside *next, *prev;
- struct Material *ma;
- struct ObjectInstanceRen *obi;
-} MatInside;
-
-typedef struct VolPrecachePart {
- struct VolPrecachePart *next, *prev;
- struct RayObject *tree;
- struct ShadeInput *shi;
- struct ObjectInstanceRen *obi;
- float viewmat[4][4];
- int num;
- int minx, maxx;
- int miny, maxy;
- int minz, maxz;
- int res[3];
- float bbmin[3];
- float voxel[3];
- struct Render *re;
-} VolPrecachePart;
-
-typedef struct VolumePrecache {
- int res[3];
- float *bbmin, *bbmax;
- float *data_r;
- float *data_g;
- float *data_b;
-} VolumePrecache;
-
-/* ------------------------------------------------------------------------- */
-
-struct LampRen;
-struct MTex;
-
-/**
- * For each lamp in a scene, a LampRen is created. It determines the
- * properties of a lightsource.
- */
-
-typedef struct LampShadowSubSample {
- int samplenr;
- float shadfac[4]; /* rgba shadow */
-} LampShadowSubSample;
-
-typedef struct LampShadowSample {
- LampShadowSubSample s[16]; /* MAX OSA */
-} LampShadowSample;
-
-typedef struct LampRen {
- struct LampRen *next, *prev;
-
- float xs, ys, dist;
- float co[3];
- short type;
- int mode;
- float r, g, b, k;
- float shdwr, shdwg, shdwb;
- float energy, haint;
- int lay;
- float spotsi, spotbl;
- float vec[3];
- float xsp, ysp, distkw, inpr;
- float halokw, halo;
-
- short falloff_type;
- float ld1, ld2;
- float coeff_const, coeff_lin, coeff_quad;
- struct CurveMapping *curfalloff;
-
- /* copied from Lamp, to decouple more rendering stuff */
- /** Size of the shadowbuffer */
- short bufsize;
- /** Number of samples for the shadows */
- short samp;
- /** Softness factor for shadow */
- float soft;
- /** amount of subsample buffers and type of filter for sampling */
- short buffers, filtertype;
- /** shadow buffer type (regular, irregular) */
- short buftype;
- /** autoclip */
- short bufflag;
- /** shadow plus halo: detail level */
- short shadhalostep;
- /** Near clip of the lamp */
- float clipsta;
- /** Far clip of the lamp */
- float clipend;
- /** A small depth offset to prevent self-shadowing. */
- float bias;
- /* Compression threshold for deep shadow maps */
- float compressthresh;
-
- short ray_samp, ray_sampy, ray_sampz, ray_samp_method, ray_samp_type, area_shape, ray_totsamp;
- short xold[BLENDER_MAX_THREADS], yold[BLENDER_MAX_THREADS]; /* last jitter table for area lights */
- float area_size, area_sizey, area_sizez;
- float adapt_thresh;
-
- /* sun/sky */
- struct SunSky *sunsky;
-
- struct ShadBuf *shb;
- float *jitter;
-
- float imat[3][3];
- float spottexfac;
- float sh_invcampos[3], sh_zfac; /* sh_= spothalo */
-
- float lampmat[4][4]; /* worls space lamp matrix, used for scene rotation */
-
- float mat[3][3]; /* 3x3 part from lampmat x viewmat */
- float area[8][3], areasize;
-
- /* passes & node shader support: all shadow info for a pixel */
- LampShadowSample *shadsamp;
-
- /* ray optim */
- struct RayObject *last_hit[BLENDER_MAX_THREADS];
-
- struct MTex *mtex[MAX_MTEX];
-
- /* threading */
- int thread_assigned;
- int thread_ready;
-} LampRen;
-
/* **************** defines ********************* */
-/* R.r.mode flag is same as for renderdata */
-
/* R.flag */
-#define R_ZTRA 1
-#define R_HALO 2
-#define R_SEC_FIELD 4
-#define R_LAMPHALO 8
-#define R_NEED_TANGENT 16
-#define R_BAKE_TRACE 32
-#define R_BAKING 64
-#define R_ANIMATION 128
-#define R_NEED_VCOL 256
-
-/* vlakren->flag (vlak = face in dutch) char!!! */
-#define R_SMOOTH 1
-#define R_HIDDEN 2
-/* strand flag, means special handling */
-#define R_STRAND 4
-#define R_FULL_OSA 8
-#define R_FACE_SPLIT 16
-/* Tells render to divide face other way. */
-#define R_DIVIDE_24 32
-/* vertex normals are tangent or view-corrected vector, for hair strands */
-#define R_TANGENT 64
-#define R_TRACEBLE 128
-
-/* vlakren->freestyle_edge_mark */
-#ifdef WITH_FREESTYLE
-# define R_EDGE_V1V2 1
-# define R_EDGE_V2V3 2
-# define R_EDGE_V3V4 4
-# define R_EDGE_V3V1 4
-# define R_EDGE_V4V1 8
-#endif
-
-/* strandbuffer->flag */
-#define R_STRAND_BSPLINE 1
-#define R_STRAND_B_UNITS 2
-
-/* objectren->flag */
-#define R_INSTANCEABLE 1
-
-/* objectinstance->flag */
-#define R_DUPLI_TRANSFORMED 1
-#define R_ENV_TRANSFORMED 2
-#define R_TRANSFORMED (1|2)
+#define R_ANIMATION 1
#endif /* __RENDER_TYPES_H__ */
diff --git a/source/blender/render/intern/include/rendercore.h b/source/blender/render/intern/include/rendercore.h
deleted file mode 100644
index f4c4a50ac27..00000000000
--- a/source/blender/render/intern/include/rendercore.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __RENDERCORE_H__
-#define __RENDERCORE_H__
-
-/** \file blender/render/intern/include/rendercore.h
- * \ingroup render
- */
-
-#include "render_types.h"
-
-#include "RE_engine.h"
-
-#include "DNA_node_types.h"
-
-#include "NOD_composite.h"
-
-struct ShadeInput;
-struct ShadeResult;
-struct World;
-struct RenderPart;
-struct RenderLayer;
-struct RayObject;
-
-/* ------------------------------------------------------------------------- */
-
-typedef struct PixStr {
- struct PixStr *next;
- int obi, facenr, z, maskz;
- unsigned short mask;
- short shadfac;
-} PixStr;
-
-typedef struct PixStrMain {
- struct PixStrMain *next, *prev;
- struct PixStr *ps;
- int counter;
-} PixStrMain;
-
-/* ------------------------------------------------------------------------- */
-
-
-void calc_view_vector(float view[3], float x, float y);
-float mistfactor(float zcor, const float co[3]); /* dist and height, return alpha */
-
-void renderspothalo(struct ShadeInput *shi, float col[4], float alpha);
-void add_halo_flare(Render *re);
-
-void calc_renderco_zbuf(float co[3], const float view[3], int z);
-void calc_renderco_ortho(float co[3], float x, float y, int z);
-
-int count_mask(unsigned short mask);
-
-void zbufshade_tile(struct RenderPart *pa);
-void zbufshadeDA_tile(struct RenderPart *pa);
-
-void zbufshade_sss_tile(struct RenderPart *pa);
-
-int get_sample_layers(struct RenderPart *pa, struct RenderLayer *rl, struct RenderLayer **rlpp);
-
-void render_internal_update_passes(struct RenderEngine *engine, struct Scene *scene, struct SceneRenderLayer *srl);
-
-
-/* -------- ray.c ------- */
-
-struct RayObject *RE_rayobject_create(int type, int size, int octree_resolution);
-
-extern void freeraytree(Render *re);
-extern void makeraytree(Render *re);
-struct RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi);
-
-extern void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4]);
-extern void ray_trace(ShadeInput *shi, ShadeResult *);
-extern void ray_ao(ShadeInput *shi, float ao[3], float env[3]);
-extern void init_jitter_plane(LampRen *lar);
-extern void init_ao_sphere(Render *re, struct World *wrld);
-extern void init_render_qmcsampler(Render *re);
-extern void free_render_qmcsampler(Render *re);
-
-#endif /* __RENDERCORE_H__ */
diff --git a/source/blender/render/intern/include/renderdatabase.h b/source/blender/render/intern/include/renderdatabase.h
deleted file mode 100644
index b576d69d806..00000000000
--- a/source/blender/render/intern/include/renderdatabase.h
+++ /dev/null
@@ -1,174 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2006 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/renderdatabase.h
- * \ingroup render
- */
-
-
-#ifndef __RENDERDATABASE_H__
-#define __RENDERDATABASE_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-struct Object;
-struct VlakRen;
-struct VertRen;
-struct HaloRen;
-struct Main;
-struct Material;
-struct Render;
-struct MCol;
-struct MTFace;
-struct CustomData;
-struct StrandBuffer;
-struct StrandRen;
-struct ObjectInstanceRen;
-struct RadFace;
-struct Isect;
-
-#define RE_QUAD_MASK 0x7FFFFFF
-#define RE_QUAD_OFFS 0x8000000
-
-/* render allocates totvert/256 of these nodes, for lookup and quick alloc */
-typedef struct VertTableNode {
- struct VertRen *vert;
- float *rad;
- float *strand;
- float *tangent;
- float *stress;
- float *winspeed;
- /* Index of vertex in source mesh (before modifiers). */
- int *origindex;
-} VertTableNode;
-
-typedef struct VlakTableNode {
- struct VlakRen *vlak;
- struct MTFace *mtface;
- struct MCol *mcol;
- /* Index of mpoly in source mesh (before tessellation). */
- int *origindex;
- int totmtface, totmcol;
- float *surfnor;
- float *tangent_arrays[MAX_MTFACE];
- struct RadFace **radface;
-} VlakTableNode;
-
-typedef struct StrandTableNode {
- struct StrandRen *strand;
- float *winspeed;
- float *surfnor;
- float *simplify;
- int *face;
- struct MCol *mcol;
- float *uv;
- int totuv, totmcol;
-} StrandTableNode;
-
-/* renderdatabase.c */
-void free_renderdata_tables(struct Render *re);
-void free_renderdata_vertnodes(struct VertTableNode *vertnodes);
-void free_renderdata_vlaknodes(struct VlakTableNode *vlaknodes);
-
-void project_renderdata(struct Render *re, void (*projectfunc)(const float *, float mat[4][4], float *), bool do_pano, float xoffs, bool do_buckets);
-int clip_render_object(float boundbox[2][3], float bounds[4], float mat[4][4]);
-
-/* functions are not exported... so wrong names */
-
-struct VlakRen *RE_findOrAddVlak(struct ObjectRen *obr, int nr);
-struct VertRen *RE_findOrAddVert(struct ObjectRen *obr, int nr);
-struct StrandRen *RE_findOrAddStrand(struct ObjectRen *obr, int nr);
-struct HaloRen *RE_findOrAddHalo(struct ObjectRen *obr, int nr);
-struct HaloRen *RE_inithalo(struct Render *re, struct ObjectRen *obr, struct Material *ma,
- const float vec[3], const float vec1[3],
- const float *orco, float hasize, float vectsize, int seed);
-struct HaloRen *RE_inithalo_particle(struct Render *re, struct ObjectRen *obr, struct DerivedMesh *dm, struct Material *ma,
- const float vec[3], const float vec1[3],
- const float *orco, const float *uvco, float hasize, float vectsize, int seed,
- const float pa_co[3]);
-struct StrandBuffer *RE_addStrandBuffer(struct ObjectRen *obr, int totvert);
-
-struct ObjectRen *RE_addRenderObject(struct Render *re, struct Object *ob, struct Object *par, int index, int psysindex, int lay);
-struct ObjectInstanceRen *RE_addRenderInstance(
- struct Render *re, struct ObjectRen *obr, struct Object *ob, struct Object *par,
- int index, int psysindex, float mat[4][4], int lay, const struct DupliObject *dob);
-void RE_makeRenderInstances(struct Render *re);
-void RE_updateRenderInstance(Render *re, ObjectInstanceRen *obi, int flag);
-
-void RE_instance_rotate_ray_start(struct ObjectInstanceRen *obi, struct Isect *is);
-void RE_instance_rotate_ray_dir(struct ObjectInstanceRen *obi, struct Isect *is);
-void RE_instance_rotate_ray(struct ObjectInstanceRen *obi, struct Isect *is);
-void RE_instance_rotate_ray_restore(struct ObjectInstanceRen *obi, struct Isect *is);
-
-float *RE_vertren_get_stress(struct ObjectRen *obr, struct VertRen *ver, int verify);
-float *RE_vertren_get_rad(struct ObjectRen *obr, struct VertRen *ver, int verify);
-float *RE_vertren_get_strand(struct ObjectRen *obr, struct VertRen *ver, int verify);
-float *RE_vertren_get_tangent(struct ObjectRen *obr, struct VertRen *ver, int verify);
-float *RE_vertren_get_winspeed(struct ObjectInstanceRen *obi, struct VertRen *ver, int verify);
-int *RE_vertren_get_origindex(struct ObjectRen *obr, VertRen *ver, int verify);
-
-struct MTFace *RE_vlakren_get_tface(struct ObjectRen *obr, VlakRen *ren, int n, char **name, int verify);
-struct MCol *RE_vlakren_get_mcol(struct ObjectRen *obr, VlakRen *ren, int n, char **name, int verify);
-int *RE_vlakren_get_origindex(struct ObjectRen *obr, VlakRen *vlak, int verify);
-float *RE_vlakren_get_surfnor(struct ObjectRen *obr, VlakRen *ren, int verify);
-float *RE_vlakren_get_nmap_tangent(ObjectRen *obr, VlakRen *vlak, int index, bool verify);
-RadFace **RE_vlakren_get_radface(struct ObjectRen *obr, VlakRen *ren, int verify);
-void RE_vlakren_get_normal(struct Render *re, struct ObjectInstanceRen *obi, struct VlakRen *vlr, float *nor);
-
-float *RE_strandren_get_surfnor(struct ObjectRen *obr, struct StrandRen *strand, int verify);
-float *RE_strandren_get_uv(struct ObjectRen *obr, struct StrandRen *strand, int n, char **name, int verify);
-struct MCol *RE_strandren_get_mcol(struct ObjectRen *obr, struct StrandRen *strand, int n, char **name, int verify);
-float *RE_strandren_get_simplify(struct ObjectRen *obr, struct StrandRen *strand, int verify);
-int *RE_strandren_get_face(struct ObjectRen *obr, struct StrandRen *strand, int verify);
-float *RE_strandren_get_winspeed(struct ObjectInstanceRen *obi, struct StrandRen *strand, int verify);
-
-struct VertRen *RE_vertren_copy(struct ObjectRen *obr, struct VertRen *ver);
-struct VlakRen *RE_vlakren_copy(struct ObjectRen *obr, struct VlakRen *vlr);
-
-void RE_set_customdata_names(struct ObjectRen *obr, struct CustomData *data);
-
-void area_lamp_vectors(struct LampRen *lar);
-
-
-/* haloren->type: flags */
-#define HA_ONLYSKY 1
-#define HA_VECT 2
-#define HA_XALPHA 4
-#define HA_FLARECIRC 8
-
-/* convertblender.c */
-void init_render_world(Render *re);
-void RE_Database_FromScene_Vectors(Render *re, struct Main *bmain, struct Scene *sce, unsigned int lay);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __RENDERDATABASE_H__ */
-
diff --git a/source/blender/render/intern/include/renderpipeline.h b/source/blender/render/intern/include/renderpipeline.h
index c5d6e3b44b1..68fbc01b914 100644
--- a/source/blender/render/intern/include/renderpipeline.h
+++ b/source/blender/render/intern/include/renderpipeline.h
@@ -33,14 +33,14 @@
#ifndef __RENDERPIPELINE_H__
#define __RENDERPIPELINE_H__
+struct ListBase;
struct Render;
struct RenderData;
struct RenderLayer;
struct RenderResult;
struct RenderLayer *render_get_active_layer(struct Render *re, struct RenderResult *rr);
-float panorama_pixel_rot(struct Render *re);
-void render_update_anim_renderdata(struct Render *re, struct RenderData *rd);
+void render_update_anim_renderdata(struct Render *re, struct RenderData *rd, struct ListBase *render_layers);
void render_copy_renderdata(struct RenderData *to, struct RenderData *from);
#endif /* __RENDERPIPELINE_H__ */
diff --git a/source/blender/render/intern/include/shadbuf.h b/source/blender/render/intern/include/shadbuf.h
deleted file mode 100644
index ddf5de8d974..00000000000
--- a/source/blender/render/intern/include/shadbuf.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __SHADBUF_H__
-#define __SHADBUF_H__
-
-/** \file blender/render/intern/include/shadbuf.h
- * \ingroup render
- */
-
-#include "render_types.h"
-
-
-/**
- * Calculates shadowbuffers for a vector of shadow-giving lamps
- * \param lar The vector of lamps
- */
-void makeshadowbuf(struct Render *re, LampRen *lar);
-void freeshadowbuf(struct LampRen *lar);
-
-void threaded_makeshadowbufs(struct Render *re);
-
-/**
- * Determines the shadow factor for a face and lamp. There is some
- * communication with global variables here.
- * \return The shadow factors: 1.0 for no shadow, 0.0 for complete
- * shadow.
- * \param shb The shadowbuffer to find the shadow factor in.
- * \param inp The inproduct between viewvector and ?
- *
- */
-float testshadowbuf(struct Render *re, struct ShadBuf *shb, const float rco[3], const float dxco[3], const float dyco[3], float inp, float mat_bias);
-
-/**
- * Determines the shadow factor for lamp \a lar, between \a p1 and \a p2. (Which CS?)
- */
-float shadow_halo(LampRen *lar, const float p1[3], const float p2[3]);
-
-/**
- * Irregular shadowbuffer
- */
-
-struct MemArena;
-struct APixstr;
-
-void ISB_create(RenderPart *pa, struct APixstr *apixbuf);
-void ISB_free(RenderPart *pa);
-float ISB_getshadow(ShadeInput *shi, ShadBuf *shb);
-
-/* data structures have to be accessible both in camview(x, y) as in lampview(x, y) */
-/* since they're created per tile rendered, speed goes over memory requirements */
-
-
-/* buffer samples, allocated in camera buffer and pointed to in lampbuffer nodes */
-typedef struct ISBSample {
- float zco[3]; /* coordinate in lampview projection */
- short *shadfac; /* initialized zero = full lighted */
- int obi; /* object for face lookup */
- int facenr; /* index in faces list */
-} ISBSample;
-
-/* transparent version of buffer sample */
-typedef struct ISBSampleA {
- float zco[3]; /* coordinate in lampview projection */
- short *shadfac; /* NULL = full lighted */
- int obi; /* object for face lookup */
- int facenr; /* index in faces list */
- struct ISBSampleA *next; /* in end, we want the first items to align with ISBSample */
-} ISBSampleA;
-
-/* used for transparent storage only */
-typedef struct ISBShadfacA {
- struct ISBShadfacA *next;
- int obi;
- int facenr;
- float shadfac;
-} ISBShadfacA;
-
-/* What needs to be stored to evaluate shadow, for each thread in ShadBuf */
-typedef struct ISBData {
- short *shadfacs; /* simple storage for solid only */
- ISBShadfacA **shadfaca;
- struct MemArena *memarena;
- int minx, miny, rectx, recty; /* copy from part disprect */
-} ISBData;
-
-#endif /* __SHADBUF_H__ */
-
diff --git a/source/blender/render/intern/include/shading.h b/source/blender/render/intern/include/shading.h
deleted file mode 100644
index 3ef6e9d7476..00000000000
--- a/source/blender/render/intern/include/shading.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2006 Blender Foundation
- * All rights reserved.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/shading.h
- * \ingroup render
- */
-
-
-struct ShadeInput;
-struct ShadeResult;
-struct RenderPart;
-struct RenderLayer;
-struct PixStr;
-struct LampRen;
-struct VlakRen;
-struct StrandPoint;
-struct ObjectInstanceRen;
-struct Isect;
-
-/* shadeinput.c */
-
-#define RE_MAX_OSA 16
-
-/* needed to calculate shadow and AO for an entire pixel */
-typedef struct ShadeSample {
- int tot; /* amount of shi in use, can be 1 for not FULL_OSA */
-
- RenderLayer *rlpp[RE_MAX_OSA]; /* fast lookup from sample to renderlayer (fullsample buf) */
-
- /* could be malloced once */
- ShadeInput shi[RE_MAX_OSA];
- ShadeResult shr[RE_MAX_OSA];
-} ShadeSample;
-
-
- /* also the node shader callback */
-void shade_material_loop(struct ShadeInput *shi, struct ShadeResult *shr);
-
-void shade_input_set_triangle_i(struct ShadeInput *shi, struct ObjectInstanceRen *obi, struct VlakRen *vlr, short i1, short i2, short i3);
-void shade_input_set_triangle(struct ShadeInput *shi, int obi, int facenr, int normal_flip);
-void shade_input_copy_triangle(struct ShadeInput *shi, struct ShadeInput *from);
-void shade_input_calc_viewco(struct ShadeInput *shi, float x, float y, float z, float view[3], float dxyview[2], float co[3], float dxco[3], float dyco[3]);
-void shade_input_set_viewco(struct ShadeInput *shi, float x, float y, float sx, float sy, float z);
-void shade_input_set_uv(struct ShadeInput *shi);
-void shade_input_set_normals(struct ShadeInput *shi);
-void shade_input_set_vertex_normals(struct ShadeInput *shi);
-void shade_input_flip_normals(struct ShadeInput *shi);
-void shade_input_set_shade_texco(struct ShadeInput *shi);
-void shade_input_set_strand(struct ShadeInput *shi, struct StrandRen *strand, struct StrandPoint *spoint);
-void shade_input_set_strand_texco(struct ShadeInput *shi, struct StrandRen *strand, struct StrandVert *svert, struct StrandPoint *spoint);
-void shade_input_do_shade(struct ShadeInput *shi, struct ShadeResult *shr);
-
-void shade_input_init_material(struct ShadeInput *shi);
-void shade_input_initialize(struct ShadeInput *shi, struct RenderPart *pa, struct RenderLayer *rl, int sample);
-
-void shade_sample_initialize(struct ShadeSample *ssamp, struct RenderPart *pa, struct RenderLayer *rl);
-void shade_samples_do_AO(struct ShadeSample *ssamp);
-void shade_samples_fill_with_ps(struct ShadeSample *ssamp, struct PixStr *ps, int x, int y);
-int shade_samples(struct ShadeSample *ssamp, struct PixStr *ps, int x, int y);
-
-void vlr_set_uv_indices(struct VlakRen *vlr, int *i1, int *i2, int *i3);
-
-void calc_R_ref(struct ShadeInput *shi);
-
-void barycentric_differentials_from_position(
- const float co[3], const float v1[3], const float v2[3], const float v3[3],
- const float dxco[3], const float dyco[3], const float facenor[3], const bool differentials,
- float *u, float *v, float *dx_u, float *dx_v, float *dy_u, float *dy_v);
-
-/* shadeoutput. */
-void shade_lamp_loop(struct ShadeInput *shi, struct ShadeResult *shr);
-
-void shade_color(struct ShadeInput *shi, ShadeResult *shr);
-
-void ambient_occlusion(struct ShadeInput *shi);
-void environment_lighting_apply(struct ShadeInput *shi, struct ShadeResult *shr);
-
-ListBase *get_lights(struct ShadeInput *shi);
-float lamp_get_visibility(struct LampRen *lar, const float co[3], float lv[3], float *dist);
-void lamp_get_shadow(struct LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], int do_real);
-
-float fresnel_fac(const float view[3], const float vn[3], float fresnel, float fac);
-
-/* rayshade.c */
-extern void shade_ray(struct Isect *is, struct ShadeInput *shi, struct ShadeResult *shr);
diff --git a/source/blender/render/intern/include/sss.h b/source/blender/render/intern/include/sss.h
deleted file mode 100644
index 0952c6bff65..00000000000
--- a/source/blender/render/intern/include/sss.h
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2007 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/sss.h
- * \ingroup render
- */
-
-
-#ifndef __SSS_H__
-#define __SSS_H__
-
-/* Generic multiple scattering API */
-
-struct ScatterSettings;
-typedef struct ScatterSettings ScatterSettings;
-
-struct ScatterTree;
-typedef struct ScatterTree ScatterTree;
-
-ScatterSettings *scatter_settings_new(float refl, float radius, float ior,
- float reflfac, float frontweight, float backweight);
-void scatter_settings_free(ScatterSettings *ss);
-
-ScatterTree *scatter_tree_new(ScatterSettings *ss[3], float scale, float error,
- float (*co)[3], float (*color)[3], float *area, int totpoint);
-void scatter_tree_build(ScatterTree *tree);
-void scatter_tree_sample(ScatterTree *tree, const float co[3], float color[3]);
-void scatter_tree_free(ScatterTree *tree);
-
-/* Internal renderer API */
-
-struct Render;
-struct Material;
-
-void make_sss_tree(struct Render *re);
-void sss_add_points(Render *re, float (*co)[3], float (*color)[3], float *area, int totpoint);
-void free_sss(struct Render *re);
-
-int sample_sss(struct Render *re, struct Material *mat, const float co[3], float color[3]);
-int sss_pass_done(struct Render *re, struct Material *mat);
-
-#endif /*__SSS_H__*/
-
diff --git a/source/blender/render/intern/include/strand.h b/source/blender/render/intern/include/strand.h
deleted file mode 100644
index 5687ef3c837..00000000000
--- a/source/blender/render/intern/include/strand.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Brecht Van Lommel.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/strand.h
- * \ingroup render
- */
-
-
-#ifndef __STRAND_H__
-#define __STRAND_H__
-
-struct StrandVert;
-struct StrandRen;
-struct StrandBuffer;
-struct ShadeSample;
-struct StrandPart;
-struct Render;
-struct ZSpan;
-struct ObjectInstanceRen;
-struct StrandSurface;
-struct DerivedMesh;
-struct ObjectRen;
-
-typedef struct StrandPoint {
- /* position within segment */
- float t;
-
- /* camera space */
- float co[3];
- float nor[3];
- float tan[3];
- float strandco;
- float width;
-
- /* derivatives */
- float dtco[3], dsco[3];
- float dtstrandco;
-
- /* outer points */
- float co1[3], co2[3];
- float hoco1[4], hoco2[4];
- float zco1[3], zco2[3];
- int clip1, clip2;
-
- /* screen space */
- float hoco[4];
- float x, y;
-
- /* simplification */
- float alpha;
-} StrandPoint;
-
-typedef struct StrandSegment {
- struct StrandVert *v[4];
- struct StrandRen *strand;
- struct StrandBuffer *buffer;
- struct ObjectInstanceRen *obi;
- float sqadaptcos;
-
- StrandPoint point1, point2;
- int shaded;
-} StrandSegment;
-
-struct StrandShadeCache;
-typedef struct StrandShadeCache StrandShadeCache;
-
-void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint);
-void render_strand_segment(struct Render *re, float winmat[4][4], struct StrandPart *spart, struct ZSpan *zspan, int totzspan, StrandSegment *sseg);
-void strand_minmax(struct StrandRen *strand, float min[3], float max[3], const float width);
-
-struct StrandSurface *cache_strand_surface(struct Render *re, struct ObjectRen *obr, struct DerivedMesh *dm, float mat[4][4], int timeoffset);
-void free_strand_surface(struct Render *re);
-
-struct StrandShadeCache *strand_shade_cache_create(void);
-void strand_shade_cache_free(struct StrandShadeCache *cache);
-void strand_shade_segment(struct Render *re, struct StrandShadeCache *cache, struct StrandSegment *sseg, struct ShadeSample *ssamp, float t, float s, int addpassflag);
-void strand_shade_unref(struct StrandShadeCache *cache, struct ObjectInstanceRen *obi, struct StrandVert *svert);
-
-#endif
-
diff --git a/source/blender/render/intern/include/sunsky.h b/source/blender/render/intern/include/sunsky.h
deleted file mode 100644
index 60fa8aa51ba..00000000000
--- a/source/blender/render/intern/include/sunsky.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): zaghaghi
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/sunsky.h
- * \ingroup render
- */
-
-#ifndef __SUNSKY_H__
-#define __SUNSKY_H__
-
-// #define SPECTRUM_MAX_COMPONENTS 100
-
-typedef struct SunSky {
- short effect_type, skyblendtype, sky_colorspace;
- float turbidity;
- float theta, phi;
-
- float toSun[3];
-
- /*float sunSpectralRaddata[SPECTRUM_MAX_COMPONENTS];*/
- float sunSolidAngle;
-
- float zenith_Y, zenith_x, zenith_y;
-
- float perez_Y[5], perez_x[5], perez_y[5];
-
- /* suggested by glome in patch [#8063] */
- float horizon_brightness;
- float spread;
- float sun_brightness;
- float sun_size;
- float backscattered_light;
- float skyblendfac;
- float sky_exposure;
-
- float atm_HGg;
-
- float atm_SunIntensity;
- float atm_InscatteringMultiplier;
- float atm_ExtinctionMultiplier;
- float atm_BetaRayMultiplier;
- float atm_BetaMieMultiplier;
- float atm_DistanceMultiplier;
-
- float atm_BetaRay[3];
- float atm_BetaDashRay[3];
- float atm_BetaMie[3];
- float atm_BetaDashMie[3];
- float atm_BetaRM[3];
-} SunSky;
-
-void InitSunSky(struct SunSky *sunsky, float turb, const float toSun[3], float horizon_brightness,
- float spread, float sun_brightness, float sun_size, float back_scatter,
- float skyblendfac, short skyblendtype, float sky_exposure, float sky_colorspace);
-
-void GetSkyXYZRadiance(struct SunSky *sunsky, float theta, float phi, float color_out[3]);
-void GetSkyXYZRadiancef(struct SunSky *sunsky, const float varg[3], float color_out[3]);
-void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float rayf, float inscattf, float extincf, float disf);
-void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float rgb[3]);
-void ClipColor(float c[3]);
-
-#endif /*__SUNSKY_H__*/
diff --git a/source/blender/render/intern/include/texture.h b/source/blender/render/intern/include/texture.h
index dfb491f46b0..71000e38960 100644
--- a/source/blender/render/intern/include/texture.h
+++ b/source/blender/render/intern/include/texture.h
@@ -63,29 +63,12 @@
} \
} \
-struct HaloRen;
-struct ShadeInput;
struct TexResult;
struct Tex;
struct Image;
struct ImBuf;
struct ImagePool;
-/* texture.h */
-
-void do_halo_tex(struct HaloRen *har, float xn, float yn, float col_r[4]);
-void do_sky_tex(
- const float rco[3], const float view[3], const float lo[3], const float dxyview[2],
- float hor[3], float zen[3], float *blend, int skyflag, short thread);
-void do_material_tex(struct ShadeInput *shi, struct Render *re);
-void do_lamp_tex(LampRen *la, const float lavec[3], struct ShadeInput *shi, float col_r[3], int effect);
-void do_volume_tex(struct ShadeInput *shi, const float xyz[3], int mapto_flag, float col_r[3], float *val, struct Render *re);
-
-void init_render_textures(Render *re);
-void end_render_textures(Render *re);
-
-void render_realtime_texture(struct ShadeInput *shi, struct Image *ima);
-
/* imagetexture.h */
int imagewraposa(struct Tex *tex, struct Image *ima, struct ImBuf *ibuf, const float texvec[3], const float dxt[2], const float dyt[2], struct TexResult *texres, struct ImagePool *pool, const bool skip_load_image);
diff --git a/source/blender/render/intern/include/texture_ocean.h b/source/blender/render/intern/include/texture_ocean.h
deleted file mode 100644
index 4a71aff930a..00000000000
--- a/source/blender/render/intern/include/texture_ocean.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributors: Matt Ebb
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __TEXTURE_OCEAN_H__
-#define __TEXTURE_OCEAN_H__
-
-/** \file blender/render/intern/include/texture_ocean.h
- * \ingroup render
- */
-
-int ocean_texture(struct Tex *tex, const float texvec[2], struct TexResult *texres);
-
-#endif /* __TEXTURE_OCEAN_H__ */
diff --git a/source/blender/render/intern/include/volume_precache.h b/source/blender/render/intern/include/volume_precache.h
deleted file mode 100644
index 9aa280d8276..00000000000
--- a/source/blender/render/intern/include/volume_precache.h
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Matt Ebb.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/volume_precache.h
- * \ingroup render
- */
-
-
-void global_bounds_obi(Render *re, ObjectInstanceRen *obi, float bbmin[3], float bbmax[3]);
-int point_inside_volume_objectinstance(Render *re, ObjectInstanceRen *obi, const float co[3]);
-
-void volume_precache(Render *re);
-void free_volume_precache(Render *re);
-
-#define VOL_MS_TIMESTEP 0.1f
diff --git a/source/blender/render/intern/include/volumetric.h b/source/blender/render/intern/include/volumetric.h
deleted file mode 100644
index 3805478fed0..00000000000
--- a/source/blender/render/intern/include/volumetric.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Matt Ebb.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/volumetric.h
- * \ingroup render
- */
-
-
-struct Isect;
-struct ShadeInput;
-struct ShadeResult;
-
-float vol_get_density(struct ShadeInput *shi, const float co[3]);
-void vol_get_scattering(ShadeInput *shi, float scatter_col[3], const float co[3], const float view[3]);
-
-void shade_volume_outside(ShadeInput *shi, ShadeResult *shr);
-void shade_volume_inside(ShadeInput *shi, ShadeResult *shr);
-void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct Isect *last_is);
-
-#define VOL_IS_BACKFACE 1
-#define VOL_IS_SAMEMATERIAL 2
-
-#define VOL_BOUNDS_DEPTH 0
-#define VOL_BOUNDS_SS 1
-
-#define VOL_SHADE_OUTSIDE 0
-#define VOL_SHADE_INSIDE 1
diff --git a/source/blender/render/intern/include/voxeldata.h b/source/blender/render/intern/include/voxeldata.h
deleted file mode 100644
index dd2262e0357..00000000000
--- a/source/blender/render/intern/include/voxeldata.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Raul Fernandez Hernandez (Farsthary), Matt Ebb.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/include/voxeldata.h
- * \ingroup render
- */
-
-#ifndef __VOXELDATA_H__
-#define __VOXELDATA_H__
-
-struct Render;
-struct TexResult;
-
-typedef struct VoxelDataHeader {
- int resolX, resolY, resolZ;
- int frames;
-} VoxelDataHeader;
-
-void cache_voxeldata(Tex *tex, int scene_frame);
-void make_voxeldata(struct Render *re);
-int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texres);
-
-#endif /* __VOXELDATA_H__ */
diff --git a/source/blender/render/intern/include/zbuf.h b/source/blender/render/intern/include/zbuf.h
index 6fc1a4c2656..1a93fc6c3b2 100644
--- a/source/blender/render/intern/include/zbuf.h
+++ b/source/blender/render/intern/include/zbuf.h
@@ -33,57 +33,6 @@
#ifndef __ZBUF_H__
#define __ZBUF_H__
-struct RenderPart;
-struct RenderLayer;
-struct LampRen;
-struct ListBase;
-struct ZSpan;
-struct APixstrand;
-struct APixstr;
-struct StrandShadeCache;
-
-void fillrect(int *rect, int x, int y, int val);
-
-/**
- * Converts a world coordinate into a homogeneous coordinate in view
- * coordinates.
- */
-void projectvert(const float v1[3], float winmat[4][4], float adr[4]);
-void projectverto(const float v1[3], float winmat[4][4], float adr[4]);
-int testclip(const float v[3]);
-
-void zbuffer_shadow(struct Render *re, float winmat[4][4], struct LampRen *lar, int *rectz, int size, float jitx, float jity);
-void zbuffer_abuf_shadow(struct Render *re, struct LampRen *lar, float winmat[4][4], struct APixstr *APixbuf, struct APixstrand *apixbuf, struct ListBase *apsmbase, int size, int samples, float (*jit)[2]);
-void zbuffer_solid(struct RenderPart *pa, struct RenderLayer *rl, void (*fillfunc)(struct RenderPart *, struct ZSpan *, int, void *), void *data);
-
-unsigned short *zbuffer_transp_shade(struct RenderPart *pa, struct RenderLayer *rl, float *pass, struct ListBase *psmlist);
-void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(void *, int, int, int, int, int));
-int zbuffer_strands_abuf(struct Render *re, struct RenderPart *pa, struct APixstrand *apixbuf, struct ListBase *apsmbase, unsigned int lay, int negzmask, float winmat[4][4], int winx, int winy, int sample, float (*jit)[2], float clipcrop, int shadow, struct StrandShadeCache *cache);
-
-typedef struct APixstr {
- unsigned short mask[4]; /* jitter mask */
- int z[4]; /* distance */
- int p[4]; /* index */
- int obi[4]; /* object instance */
- short shadfac[4]; /* optimize storage for irregular shadow */
- struct APixstr *next;
-} APixstr;
-
-typedef struct APixstrand {
- unsigned short mask[4]; /* jitter mask */
- int z[4]; /* distance */
- int p[4]; /* index */
- int obi[4]; /* object instance */
- int seg[4]; /* for strands, segment number */
- float u[4], v[4]; /* for strands, u,v coordinate in segment */
- struct APixstrand *next;
-} APixstrand;
-
-typedef struct APixstrMain {
- struct APixstrMain *next, *prev;
- void *ps;
-} APixstrMain;
-
/* span fill in method, is also used to localize data for zbuffering */
typedef struct ZSpan {
int rectx, recty; /* range for clipping */
@@ -91,61 +40,13 @@ typedef struct ZSpan {
int miny1, maxy1, miny2, maxy2; /* actual filled in range */
const float *minp1, *maxp1, *minp2, *maxp2; /* vertex pointers detect min/max range in */
float *span1, *span2;
-
- float zmulx, zmuly, zofsx, zofsy; /* transform from hoco to zbuf co */
-
- int *rectz, *arectz; /* zbuffers, arectz is for transparent */
- int *rectz1; /* secondary z buffer for shadowbuffer (2nd closest z) */
- int *rectp; /* polygon index buffer */
- int *recto; /* object buffer */
- int *rectmask; /* negative zmask buffer */
- APixstr *apixbuf, *curpstr; /* apixbuf for transparent */
- APixstrand *curpstrand; /* same for strands */
- struct ListBase *apsmbase;
-
- int polygon_offset; /* offset in Z */
- float shad_alpha; /* copy from material, used by irregular shadbuf */
- int mask, apsmcounter; /* in use by apixbuf */
- int apstrandmcounter;
-
- float clipcrop; /* for shadow, was in R global before */
-
- void *sss_handle; /* used by sss */
- void (*sss_func)(void *, int, int, int, int, int);
-
- void (*zbuffunc)(struct ZSpan *, int, int, const float *, const float *, const float *, const float *);
- void (*zbuflinefunc)(struct ZSpan *, int, int, const float *, const float *);
-
} ZSpan;
-/* exported to shadbuf.c */
-void zbufclip4(struct ZSpan *zspan, int obi, int zvlnr,
- const float f1[4], const float f2[4], const float f3[4], const float f4[4],
- const int c1, const int c2, const int c3, const int c4);
+void zbuf_alloc_span(struct ZSpan *zspan, int rectx, int recty);
void zbuf_free_span(struct ZSpan *zspan);
-void freepsA(struct ListBase *lb);
-/* to rendercore.c */
void zspan_scanconvert(struct ZSpan *zpan, void *handle, float *v1, float *v2, float *v3,
void (*func)(void *, int, int, float, float) );
-/* exported to edge render... */
-void zbufclip(struct ZSpan *zspan, int obi, int zvlnr,
- const float f1[4], const float f2[4], const float f3[4],
- const int c1, const int c2, const int c3);
-void zbuf_alloc_span(struct ZSpan *zspan, int rectx, int recty, float clipcrop);
-void zbufclipwire(struct ZSpan *zspan, int obi, int zvlnr, int ec,
- const float ho1[4], const float ho2[4], const float ho3[4], const float ho4[4],
- const int c1, const int c2, const int c3, const int c4);
-
-/* exported to shadeinput.c */
-void zbuf_make_winmat(Render *re, float winmat[4][4]);
-void zbuf_render_project(float winmat[4][4], const float co[3], float ho[4]);
-
-/* should not really be exposed, bad! */
-void hoco_to_zco(ZSpan *zspan, float zco[3], const float hoco[4]);
-void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, float *v3, void (*func)(void *, int, int, float, float, float) );
-void zbufsinglewire(ZSpan *zspan, int obi, int zvlnr, const float ho1[4], const float ho2[4]);
-
#endif
diff --git a/source/blender/render/intern/raytrace/bvh.h b/source/blender/render/intern/raytrace/bvh.h
deleted file mode 100644
index 25fdb41bb3a..00000000000
--- a/source/blender/render/intern/raytrace/bvh.h
+++ /dev/null
@@ -1,407 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/bvh.h
- * \ingroup render
- */
-
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-
-#include "raycounter.h"
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "rayobject_hint.h"
-#include "rayobject_rtbuild.h"
-
-#include <assert.h>
-
-#ifdef __SSE__
-#include <xmmintrin.h>
-#endif
-
-#ifndef __BVH_H__
-#define __BVH_H__
-
-#ifdef __SSE__
-inline int test_bb_group4(__m128 *bb_group, const Isect *isec)
-{
- const __m128 tmin0 = _mm_setzero_ps();
- const __m128 tmax0 = _mm_set_ps1(isec->dist);
-
- float start[3], idot_axis[3];
- copy_v3_v3(start, isec->start);
- copy_v3_v3(idot_axis, isec->idot_axis);
-
- const __m128 tmin1 = _mm_max_ps(tmin0, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[0]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) );
- const __m128 tmax1 = _mm_min_ps(tmax0, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[1]], _mm_set_ps1(start[0]) ), _mm_set_ps1(idot_axis[0])) );
- const __m128 tmin2 = _mm_max_ps(tmin1, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[2]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) );
- const __m128 tmax2 = _mm_min_ps(tmax1, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[3]], _mm_set_ps1(start[1]) ), _mm_set_ps1(idot_axis[1])) );
- const __m128 tmin3 = _mm_max_ps(tmin2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[4]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) );
- const __m128 tmax3 = _mm_min_ps(tmax2, _mm_mul_ps(_mm_sub_ps(bb_group[isec->bv_index[5]], _mm_set_ps1(start[2]) ), _mm_set_ps1(idot_axis[2])) );
-
- return _mm_movemask_ps(_mm_cmpge_ps(tmax3, tmin3));
-}
-#endif
-
-/*
- * Determines the distance that the ray must travel to hit the bounding volume of the given node
- * Based on Tactical Optimization of Ray/Box Intersection, by Graham Fyffe
- * [http://tog.acm.org/resources/RTNews/html/rtnv21n1.html#art9]
- */
-static inline int rayobject_bb_intersect_test(const Isect *isec, const float *_bb)
-{
- const float *bb = _bb;
-
- float t1x = (bb[isec->bv_index[0]] - isec->start[0]) * isec->idot_axis[0];
- float t2x = (bb[isec->bv_index[1]] - isec->start[0]) * isec->idot_axis[0];
- float t1y = (bb[isec->bv_index[2]] - isec->start[1]) * isec->idot_axis[1];
- float t2y = (bb[isec->bv_index[3]] - isec->start[1]) * isec->idot_axis[1];
- float t1z = (bb[isec->bv_index[4]] - isec->start[2]) * isec->idot_axis[2];
- float t2z = (bb[isec->bv_index[5]] - isec->start[2]) * isec->idot_axis[2];
-
- RE_RC_COUNT(isec->raycounter->bb.test);
-
- if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0;
- if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return 0;
- if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0;
- RE_RC_COUNT(isec->raycounter->bb.hit);
-
- return 1;
-}
-
-/* bvh tree generics */
-template<class Tree> static void bvh_add(Tree *obj, RayObject *ob)
-{
- rtbuild_add(obj->builder, ob);
-}
-
-template<class Node>
-inline bool is_leaf(Node *node)
-{
- return !RE_rayobject_isAligned(node);
-}
-
-template<class Tree> static void bvh_done(Tree *obj);
-
-template<class Tree>
-static void bvh_free(Tree *obj)
-{
- if (obj->builder)
- rtbuild_free(obj->builder);
-
- if (obj->node_arena)
- BLI_memarena_free(obj->node_arena);
-
- MEM_freeN(obj);
-}
-
-template<class Tree>
-static void bvh_bb(Tree *obj, float *min, float *max)
-{
- if (obj->root)
- bvh_node_merge_bb(obj->root, min, max);
-}
-
-
-template<class Tree>
-static float bvh_cost(Tree *obj)
-{
- assert(obj->cost >= 0.0f);
- return obj->cost;
-}
-
-
-
-/* bvh tree nodes generics */
-template<class Node> static inline int bvh_node_hit_test(Node *node, Isect *isec)
-{
- return rayobject_bb_intersect_test(isec, (const float *)node->bb);
-}
-
-
-template<class Node>
-static inline void bvh_node_merge_bb(Node *node, float min[3], float max[3])
-{
- if (is_leaf(node)) {
- RE_rayobject_merge_bb((RayObject *)node, min, max);
- }
- else {
- DO_MIN(node->bb, min);
- DO_MAX(node->bb + 3, max);
- }
-}
-
-
-
-/*
- * recursively transverse a BVH looking for a rayhit using a local stack
- */
-template<class Node> static inline void bvh_node_push_childs(Node *node, Isect *isec, Node **stack, int &stack_pos);
-
-template<class Node, int MAX_STACK_SIZE, bool TEST_ROOT, bool SHADOW>
-static int bvh_node_stack_raycast(Node *root, Isect *isec)
-{
- Node *stack[MAX_STACK_SIZE];
- int hit = 0, stack_pos = 0;
-
- if (!TEST_ROOT && !is_leaf(root))
- bvh_node_push_childs(root, isec, stack, stack_pos);
- else
- stack[stack_pos++] = root;
-
- while (stack_pos) {
- Node *node = stack[--stack_pos];
- if (!is_leaf(node)) {
- if (bvh_node_hit_test(node, isec)) {
- bvh_node_push_childs(node, isec, stack, stack_pos);
- assert(stack_pos <= MAX_STACK_SIZE);
- }
- }
- else {
- hit |= RE_rayobject_intersect( (RayObject *)node, isec);
- if (SHADOW && hit) return hit;
- }
- }
- return hit;
-}
-
-
-#ifdef __SSE__
-/*
- * Generic SIMD bvh recursion
- * this was created to be able to use any simd (with the cost of some memmoves)
- * it can take advantage of any SIMD width and doens't needs any special tree care
- */
-template<class Node, int MAX_STACK_SIZE, bool TEST_ROOT>
-static int bvh_node_stack_raycast_simd(Node *root, Isect *isec)
-{
- Node *stack[MAX_STACK_SIZE];
-
- int hit = 0, stack_pos = 0;
-
- if (!TEST_ROOT) {
- if (!is_leaf(root)) {
- if (!is_leaf(root->child))
- bvh_node_push_childs(root, isec, stack, stack_pos);
- else
- return RE_rayobject_intersect( (RayObject *)root->child, isec);
- }
- else
- return RE_rayobject_intersect( (RayObject *)root, isec);
- }
- else {
- if (!is_leaf(root))
- stack[stack_pos++] = root;
- else
- return RE_rayobject_intersect( (RayObject *)root, isec);
- }
-
- while (true) {
- //Use SIMD 4
- if (stack_pos >= 4) {
- __m128 t_bb[6];
- Node *t_node[4];
-
- stack_pos -= 4;
-
- /* prepare the 4BB for SIMD */
- t_node[0] = stack[stack_pos + 0]->child;
- t_node[1] = stack[stack_pos + 1]->child;
- t_node[2] = stack[stack_pos + 2]->child;
- t_node[3] = stack[stack_pos + 3]->child;
-
- const float *bb0 = stack[stack_pos + 0]->bb;
- const float *bb1 = stack[stack_pos + 1]->bb;
- const float *bb2 = stack[stack_pos + 2]->bb;
- const float *bb3 = stack[stack_pos + 3]->bb;
-
- const __m128 x0y0x1y1 = _mm_shuffle_ps(_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(1, 0, 1, 0) );
- const __m128 x2y2x3y3 = _mm_shuffle_ps(_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(1, 0, 1, 0) );
- t_bb[0] = _mm_shuffle_ps(x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(2, 0, 2, 0) );
- t_bb[1] = _mm_shuffle_ps(x0y0x1y1, x2y2x3y3, _MM_SHUFFLE(3, 1, 3, 1) );
-
- const __m128 z0X0z1X1 = _mm_shuffle_ps(_mm_load_ps(bb0), _mm_load_ps(bb1), _MM_SHUFFLE(3, 2, 3, 2) );
- const __m128 z2X2z3X3 = _mm_shuffle_ps(_mm_load_ps(bb2), _mm_load_ps(bb3), _MM_SHUFFLE(3, 2, 3, 2) );
- t_bb[2] = _mm_shuffle_ps(z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(2, 0, 2, 0) );
- t_bb[3] = _mm_shuffle_ps(z0X0z1X1, z2X2z3X3, _MM_SHUFFLE(3, 1, 3, 1) );
-
- const __m128 Y0Z0Y1Z1 = _mm_shuffle_ps(_mm_load_ps(bb0 + 4), _mm_load_ps(bb1 + 4), _MM_SHUFFLE(1, 0, 1, 0) );
- const __m128 Y2Z2Y3Z3 = _mm_shuffle_ps(_mm_load_ps(bb2 + 4), _mm_load_ps(bb3 + 4), _MM_SHUFFLE(1, 0, 1, 0) );
- t_bb[4] = _mm_shuffle_ps(Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(2, 0, 2, 0) );
- t_bb[5] = _mm_shuffle_ps(Y0Z0Y1Z1, Y2Z2Y3Z3, _MM_SHUFFLE(3, 1, 3, 1) );
-#if 0
- for (int i = 0; i < 4; i++)
- {
- Node *t = stack[stack_pos + i];
- assert(!is_leaf(t));
-
- float *bb = ((float *)t_bb) + i;
- bb[4 * 0] = t->bb[0];
- bb[4 * 1] = t->bb[1];
- bb[4 * 2] = t->bb[2];
- bb[4 * 3] = t->bb[3];
- bb[4 * 4] = t->bb[4];
- bb[4 * 5] = t->bb[5];
- t_node[i] = t->child;
- }
-#endif
- RE_RC_COUNT(isec->raycounter->simd_bb.test);
- int res = test_bb_group4(t_bb, isec);
-
- for (int i = 0; i < 4; i++)
- if (res & (1 << i)) {
- RE_RC_COUNT(isec->raycounter->simd_bb.hit);
- if (!is_leaf(t_node[i])) {
- for (Node *t = t_node[i]; t; t = t->sibling) {
- assert(stack_pos < MAX_STACK_SIZE);
- stack[stack_pos++] = t;
- }
- }
- else {
- hit |= RE_rayobject_intersect( (RayObject *)t_node[i], isec);
- if (hit && isec->mode == RE_RAY_SHADOW) return hit;
- }
- }
- }
- else if (stack_pos > 0) {
- Node *node = stack[--stack_pos];
- assert(!is_leaf(node));
-
- if (bvh_node_hit_test(node, isec)) {
- if (!is_leaf(node->child)) {
- bvh_node_push_childs(node, isec, stack, stack_pos);
- assert(stack_pos <= MAX_STACK_SIZE);
- }
- else {
- hit |= RE_rayobject_intersect( (RayObject *)node->child, isec);
- if (hit && isec->mode == RE_RAY_SHADOW) return hit;
- }
- }
- }
- else break;
- }
- return hit;
-}
-#endif
-
-/*
- * recursively transverse a BVH looking for a rayhit using system stack
- */
-#if 0
-template<class Node>
-static int bvh_node_raycast(Node *node, Isect *isec)
-{
- int hit = 0;
- if (bvh_test_node(node, isec))
- {
- if (isec->idot_axis[node->split_axis] > 0.0f)
- {
- int i;
- for (i = 0; i < BVH_NCHILDS; i++)
- if (!is_leaf(node->child[i]))
- {
- if (node->child[i] == 0) break;
-
- hit |= bvh_node_raycast(node->child[i], isec);
- if (hit && isec->mode == RE_RAY_SHADOW) return hit;
- }
- else {
- hit |= RE_rayobject_intersect( (RayObject *)node->child[i], isec);
- if (hit && isec->mode == RE_RAY_SHADOW) return hit;
- }
- }
- else {
- int i;
- for (i = BVH_NCHILDS - 1; i >= 0; i--)
- if (!is_leaf(node->child[i]))
- {
- if (node->child[i])
- {
- hit |= dfs_raycast(node->child[i], isec);
- if (hit && isec->mode == RE_RAY_SHADOW) return hit;
- }
- }
- else {
- hit |= RE_rayobject_intersect( (RayObject *)node->child[i], isec);
- if (hit && isec->mode == RE_RAY_SHADOW) return hit;
- }
- }
- }
- return hit;
-}
-#endif
-
-template<class Node, class HintObject>
-static void bvh_dfs_make_hint(Node *node, LCTSHint *hint, int reserve_space, HintObject *hintObject)
-{
- assert(hint->size + reserve_space + 1 <= RE_RAY_LCTS_MAX_SIZE);
-
- if (is_leaf(node)) {
- hint->stack[hint->size++] = (RayObject *)node;
- }
- else {
- int childs = count_childs(node);
- if (hint->size + reserve_space + childs <= RE_RAY_LCTS_MAX_SIZE) {
- int result = hint_test_bb(hintObject, node->bb, node->bb + 3);
- if (result == HINT_RECURSE) {
- /* We are 100% sure the ray will be pass inside this node */
- bvh_dfs_make_hint_push_siblings(node->child, hint, reserve_space, hintObject);
- }
- else if (result == HINT_ACCEPT) {
- hint->stack[hint->size++] = (RayObject *)node;
- }
- }
- else {
- hint->stack[hint->size++] = (RayObject *)node;
- }
- }
-}
-
-
-template<class Tree>
-static RayObjectAPI *bvh_get_api(int maxstacksize);
-
-
-template<class Tree, int DFS_STACK_SIZE>
-static inline RayObject *bvh_create_tree(int size)
-{
- Tree *obj = (Tree *)MEM_callocN(sizeof(Tree), "BVHTree");
- assert(RE_rayobject_isAligned(obj)); /* RayObject API assumes real data to be 4-byte aligned */
-
- obj->rayobj.api = bvh_get_api<Tree>(DFS_STACK_SIZE);
- obj->root = NULL;
-
- obj->node_arena = NULL;
- obj->builder = rtbuild_create(size);
-
- return RE_rayobject_unalignRayAPI((RayObject *) obj);
-}
-
-#endif
diff --git a/source/blender/render/intern/raytrace/rayobject.cpp b/source/blender/render/intern/raytrace/rayobject.cpp
deleted file mode 100644
index c16ef5500df..00000000000
--- a/source/blender/render/intern/raytrace/rayobject.cpp
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject.cpp
- * \ingroup render
- */
-
-
-#include <assert.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "DNA_material_types.h"
-
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "raycounter.h"
-#include "render_types.h"
-#include "renderdatabase.h"
-
-/* RayFace
- *
- * note we force always inline here, because compiler refuses to otherwise
- * because function is too long. Since this is code that is called billions
- * of times we really do want to inline. */
-
-MALWAYS_INLINE RayObject *rayface_from_coords(RayFace *rayface, void *ob, void *face,
- float *v1, float *v2, float *v3, float *v4)
-{
- rayface->ob = ob;
- rayface->face = face;
-
- copy_v3_v3(rayface->v1, v1);
- copy_v3_v3(rayface->v2, v2);
- copy_v3_v3(rayface->v3, v3);
-
- if (v4) {
- copy_v3_v3(rayface->v4, v4);
- rayface->quad = 1;
- }
- else {
- rayface->quad = 0;
- }
-
- return RE_rayobject_unalignRayFace(rayface);
-}
-
-MALWAYS_INLINE void rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, VlakRen *vlr)
-{
- rayface_from_coords(rayface, obi, vlr, vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->v4 ? vlr->v4->co : NULL);
-
- if (obi->transform_primitives) {
- mul_m4_v3(obi->mat, rayface->v1);
- mul_m4_v3(obi->mat, rayface->v2);
- mul_m4_v3(obi->mat, rayface->v3);
-
- if (RE_rayface_isQuad(rayface))
- mul_m4_v3(obi->mat, rayface->v4);
- }
-}
-
-RayObject *RE_rayface_from_vlak(RayFace *rayface, ObjectInstanceRen *obi, VlakRen *vlr)
-{
- return rayface_from_coords(rayface, obi, vlr, vlr->v1->co, vlr->v2->co, vlr->v3->co, vlr->v4 ? vlr->v4->co : NULL);
-}
-
-RayObject *RE_rayface_from_coords(RayFace *rayface, void *ob, void *face, float *v1, float *v2, float *v3, float *v4)
-{
- return rayface_from_coords(rayface, ob, face, v1, v2, v3, v4);
-}
-
-/* VlakPrimitive */
-
-RayObject *RE_vlakprimitive_from_vlak(VlakPrimitive *face, struct ObjectInstanceRen *obi, struct VlakRen *vlr)
-{
- face->ob = obi;
- face->face = vlr;
-
- return RE_rayobject_unalignVlakPrimitive(face);
-}
-
-/* Checks for ignoring faces or materials */
-
-MALWAYS_INLINE int vlr_check_intersect(Isect *is, ObjectInstanceRen *obi, VlakRen *vlr)
-{
- /* for baking selected to active non-traceable materials might still
- * be in the raytree */
- if (!(vlr->flag & R_TRACEBLE))
- return 0;
-
- /* I know... cpu cycle waste, might do smarter once */
- if (is->mode == RE_RAY_MIRROR)
- return !(vlr->mat->mode & MA_ONLYCAST);
- else
- return (vlr->mat->mode2 & MA_CASTSHADOW) && (is->lay & obi->lay);
-}
-
-MALWAYS_INLINE int vlr_check_intersect_solid(Isect *UNUSED(is), ObjectInstanceRen *UNUSED(obi), VlakRen *vlr)
-{
- /* solid material types only */
- if (vlr->mat->material_type == MA_TYPE_SURFACE)
- return 1;
- else
- return 0;
-}
-
-MALWAYS_INLINE int vlr_check_bake(Isect *is, ObjectInstanceRen *obi, VlakRen *UNUSED(vlr))
-{
- return (obi->obr->ob != is->userdata) && (obi->obr->ob->flag & SELECT);
-}
-
-/* Ray Triangle/Quad Intersection */
-
-static bool isect_ray_tri_watertight_no_sign_check_v3(
- const float ray_origin[3], const struct IsectRayPrecalc *isect_precalc,
- const float v0[3], const float v1[3], const float v2[3],
- float *r_lambda, float r_uv[2])
-{
- const int kx = isect_precalc->kx;
- const int ky = isect_precalc->ky;
- const int kz = isect_precalc->kz;
- const float sx = isect_precalc->sx;
- const float sy = isect_precalc->sy;
- const float sz = isect_precalc->sz;
-
- /* Calculate vertices relative to ray origin. */
- const float a[3] = {v0[0] - ray_origin[0], v0[1] - ray_origin[1], v0[2] - ray_origin[2]};
- const float b[3] = {v1[0] - ray_origin[0], v1[1] - ray_origin[1], v1[2] - ray_origin[2]};
- const float c[3] = {v2[0] - ray_origin[0], v2[1] - ray_origin[1], v2[2] - ray_origin[2]};
-
- const float a_kx = a[kx], a_ky = a[ky], a_kz = a[kz];
- const float b_kx = b[kx], b_ky = b[ky], b_kz = b[kz];
- const float c_kx = c[kx], c_ky = c[ky], c_kz = c[kz];
-
- /* Perform shear and scale of vertices. */
- const float ax = a_kx - sx * a_kz;
- const float ay = a_ky - sy * a_kz;
- const float bx = b_kx - sx * b_kz;
- const float by = b_ky - sy * b_kz;
- const float cx = c_kx - sx * c_kz;
- const float cy = c_ky - sy * c_kz;
-
- /* Calculate scaled barycentric coordinates. */
- const float u = cx * by - cy * bx;
- const float v = ax * cy - ay * cx;
- const float w = bx * ay - by * ax;
- float det;
-
- if ((u < 0.0f || v < 0.0f || w < 0.0f) &&
- (u > 0.0f || v > 0.0f || w > 0.0f))
- {
- return false;
- }
-
- /* Calculate determinant. */
- det = u + v + w;
- if (UNLIKELY(det == 0.0f)) {
- return false;
- }
- else {
- /* Calculate scaled z-coordinates of vertices and use them to calculate
- * the hit distance.
- */
- const float t = (u * a_kz + v * b_kz + w * c_kz) * sz;
- /* Normalize u, v and t. */
- const float inv_det = 1.0f / det;
- if (r_uv) {
- r_uv[0] = u * inv_det;
- r_uv[1] = v * inv_det;
- }
- *r_lambda = t * inv_det;
- return true;
- }
-}
-
-MALWAYS_INLINE int isec_tri_quad(const float start[3],
- const struct IsectRayPrecalc *isect_precalc,
- const RayFace *face,
- float r_uv[2], float *r_lambda)
-{
- float uv[2], l;
-
- if (isect_ray_tri_watertight_v3(start, isect_precalc, face->v1, face->v2, face->v3, &l, uv)) {
- /* check if intersection is within ray length */
- if (l > -RE_RAYTRACE_EPSILON && l < *r_lambda) {
- r_uv[0] = -uv[0];
- r_uv[1] = -uv[1];
- *r_lambda = l;
- return 1;
- }
- }
-
- /* intersect second triangle in quad */
- if (RE_rayface_isQuad(face)) {
- if (isect_ray_tri_watertight_v3(start, isect_precalc, face->v1, face->v3, face->v4, &l, uv)) {
- /* check if intersection is within ray length */
- if (l > -RE_RAYTRACE_EPSILON && l < *r_lambda) {
- r_uv[0] = -uv[0];
- r_uv[1] = -uv[1];
- *r_lambda = l;
- return 2;
- }
- }
- }
-
- return 0;
-}
-
-/* Simpler yes/no Ray Triangle/Quad Intersection */
-
-MALWAYS_INLINE int isec_tri_quad_neighbour(const float start[3],
- const float dir[3],
- const RayFace *face)
-{
- float r[3];
- struct IsectRayPrecalc isect_precalc;
- float uv[2], l;
-
- negate_v3_v3(r, dir); /* note, different than above function */
-
- isect_ray_tri_watertight_v3_precalc(&isect_precalc, r);
-
- if (isect_ray_tri_watertight_no_sign_check_v3(start, &isect_precalc, face->v1, face->v2, face->v3, &l, uv)) {
- return 1;
- }
-
- /* intersect second triangle in quad */
- if (RE_rayface_isQuad(face)) {
- if (isect_ray_tri_watertight_no_sign_check_v3(start, &isect_precalc, face->v1, face->v3, face->v4, &l, uv)) {
- return 2;
- }
- }
-
- return 0;
-}
-
-/* RayFace intersection with checks and neighbor verifaction included,
- * Isect is modified if the face is hit. */
-
-MALWAYS_INLINE int intersect_rayface(RayObject *hit_obj, RayFace *face, Isect *is)
-{
- float dist, uv[2];
- int ok = 0;
-
- /* avoid self-intersection */
- if (is->orig.ob == face->ob && is->orig.face == face->face)
- return 0;
-
- /* check if we should intersect this face */
- if (is->check == RE_CHECK_VLR_RENDER) {
- if (vlr_check_intersect(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0)
- return 0;
- }
- else if (is->check == RE_CHECK_VLR_NON_SOLID_MATERIAL) {
- if (vlr_check_intersect(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0)
- return 0;
- if (vlr_check_intersect_solid(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0)
- return 0;
- }
- else if (is->check == RE_CHECK_VLR_BAKE) {
- if (vlr_check_bake(is, (ObjectInstanceRen *)face->ob, (VlakRen *)face->face) == 0)
- return 0;
- }
-
- /* ray counter */
- RE_RC_COUNT(is->raycounter->faces.test);
-
- dist = is->dist;
- ok = isec_tri_quad(is->start, &is->isect_precalc, face, uv, &dist);
-
- if (ok) {
-
- /* when a shadow ray leaves a face, it can be little outside the edges
- * of it, causing intersection to be detected in its neighbor face */
- if (is->skip & RE_SKIP_VLR_NEIGHBOUR) {
- if (dist < 0.1f && is->orig.ob == face->ob) {
- VlakRen *a = (VlakRen *)is->orig.face;
- VlakRen *b = (VlakRen *)face->face;
- ObjectRen *obr = ((ObjectInstanceRen *)face->ob)->obr;
-
- VertRen **va, **vb;
- int *org_idx_a, *org_idx_b;
- int i, j;
- bool is_neighbor = false;
-
- /* "same" vertex means either the actual same VertRen, or the same 'final org index', if available
- * (autosmooth only, currently). */
- for (i = 0, va = &a->v1; !is_neighbor && i < 4 && *va; ++i, ++va) {
- org_idx_a = RE_vertren_get_origindex(obr, *va, false);
- for (j = 0, vb = &b->v1; !is_neighbor && j < 4 && *vb; ++j, ++vb) {
- if (*va == *vb) {
- is_neighbor = true;
- }
- else if (org_idx_a) {
- org_idx_b = RE_vertren_get_origindex(obr, *vb, 0);
- if (org_idx_b && *org_idx_a == *org_idx_b) {
- is_neighbor = true;
- }
- }
- }
- }
-
- /* So there's a shared edge or vertex, let's intersect ray with self, if that's true
- * we can safely return 1, otherwise we assume the intersection is invalid, 0 */
- if (is_neighbor) {
- /* create RayFace from original face, transformed if necessary */
- RayFace origface;
- ObjectInstanceRen *ob = (ObjectInstanceRen *)is->orig.ob;
- rayface_from_vlak(&origface, ob, (VlakRen *)is->orig.face);
-
- if (!isec_tri_quad_neighbour(is->start, is->dir, &origface)) {
- return 0;
- }
- }
- }
- }
-
- RE_RC_COUNT(is->raycounter->faces.hit);
-
- is->isect = ok; // which half of the quad
- is->dist = dist;
- is->u = uv[0]; is->v = uv[1];
-
- is->hit.ob = face->ob;
- is->hit.face = face->face;
-#ifdef RT_USE_LAST_HIT
- is->last_hit = hit_obj;
-#endif
- return 1;
- }
-
- return 0;
-}
-
-/* Intersection */
-
-int RE_rayobject_raycast(RayObject *r, Isect *isec)
-{
- int i;
-
- /* Pre-calculate orientation for watertight intersection checks. */
- isect_ray_tri_watertight_v3_precalc(&isec->isect_precalc, isec->dir);
-
- RE_RC_COUNT(isec->raycounter->raycast.test);
-
- /* setup vars used on raycast */
- for (i = 0; i < 3; i++) {
- isec->idot_axis[i] = 1.0f / isec->dir[i];
-
- isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0;
- isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i];
-
- isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i];
- isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1];
- }
-
-#ifdef RT_USE_LAST_HIT
- /* last hit heuristic */
- if (isec->mode == RE_RAY_SHADOW && isec->last_hit) {
- RE_RC_COUNT(isec->raycounter->rayshadow_last_hit.test);
-
- if (RE_rayobject_intersect(isec->last_hit, isec)) {
- RE_RC_COUNT(isec->raycounter->raycast.hit);
- RE_RC_COUNT(isec->raycounter->rayshadow_last_hit.hit);
- return 1;
- }
- }
-#endif
-
-#ifdef RT_USE_HINT
- isec->hit_hint = 0;
-#endif
-
- if (RE_rayobject_intersect(r, isec)) {
- RE_RC_COUNT(isec->raycounter->raycast.hit);
-
-#ifdef RT_USE_HINT
- isec->hint = isec->hit_hint;
-#endif
- return 1;
- }
-
- return 0;
-}
-
-int RE_rayobject_intersect(RayObject *r, Isect *i)
-{
- if (RE_rayobject_isRayFace(r)) {
- return intersect_rayface(r, (RayFace *) RE_rayobject_align(r), i);
- }
- else if (RE_rayobject_isVlakPrimitive(r)) {
- //TODO optimize (useless copy to RayFace to avoid duplicate code)
- VlakPrimitive *face = (VlakPrimitive *) RE_rayobject_align(r);
- RayFace nface;
- rayface_from_vlak(&nface, face->ob, face->face);
-
- return intersect_rayface(r, &nface, i);
- }
- else if (RE_rayobject_isRayAPI(r)) {
- r = RE_rayobject_align(r);
- return r->api->raycast(r, i);
- }
- else {
- assert(0);
- return 0;
- }
-}
-
-/* Building */
-
-void RE_rayobject_add(RayObject *r, RayObject *o)
-{
- r = RE_rayobject_align(r);
- return r->api->add(r, o);
-}
-
-void RE_rayobject_done(RayObject *r)
-{
- r = RE_rayobject_align(r);
- r->api->done(r);
-}
-
-void RE_rayobject_free(RayObject *r)
-{
- r = RE_rayobject_align(r);
- r->api->free(r);
-}
-
-float RE_rayobject_cost(RayObject *r)
-{
- if (RE_rayobject_isRayFace(r) || RE_rayobject_isVlakPrimitive(r)) {
- return 1.0f;
- }
- else if (RE_rayobject_isRayAPI(r)) {
- r = RE_rayobject_align(r);
- return r->api->cost(r);
- }
- else {
- assert(0);
- return 1.0f;
- }
-}
-
-/* Bounding Boxes */
-
-void RE_rayobject_merge_bb(RayObject *r, float min[3], float max[3])
-{
- if (RE_rayobject_isRayFace(r)) {
- RayFace *face = (RayFace *) RE_rayobject_align(r);
-
- DO_MINMAX(face->v1, min, max);
- DO_MINMAX(face->v2, min, max);
- DO_MINMAX(face->v3, min, max);
- if (RE_rayface_isQuad(face)) DO_MINMAX(face->v4, min, max);
- }
- else if (RE_rayobject_isVlakPrimitive(r)) {
- VlakPrimitive *face = (VlakPrimitive *) RE_rayobject_align(r);
- RayFace nface;
- rayface_from_vlak(&nface, face->ob, face->face);
-
- DO_MINMAX(nface.v1, min, max);
- DO_MINMAX(nface.v2, min, max);
- DO_MINMAX(nface.v3, min, max);
- if (RE_rayface_isQuad(&nface)) DO_MINMAX(nface.v4, min, max);
- }
- else if (RE_rayobject_isRayAPI(r)) {
- r = RE_rayobject_align(r);
- r->api->bb(r, min, max);
- }
- else
- assert(0);
-}
-
-/* Hints */
-
-void RE_rayobject_hint_bb(RayObject *r, RayHint *hint, float *min, float *max)
-{
- if (RE_rayobject_isRayFace(r) || RE_rayobject_isVlakPrimitive(r)) {
- return;
- }
- else if (RE_rayobject_isRayAPI(r)) {
- r = RE_rayobject_align(r);
- return r->api->hint_bb(r, hint, min, max);
- }
- else
- assert(0);
-}
-
-/* RayObjectControl */
-
-int RE_rayobjectcontrol_test_break(RayObjectControl *control)
-{
- if (control->test_break)
- return control->test_break(control->data);
-
- return 0;
-}
-
-void RE_rayobject_set_control(RayObject *r, void *data, RE_rayobjectcontrol_test_break_callback test_break)
-{
- if (RE_rayobject_isRayAPI(r)) {
- r = RE_rayobject_align(r);
- r->control.data = data;
- r->control.test_break = test_break;
- }
-}
-
diff --git a/source/blender/render/intern/raytrace/rayobject_empty.cpp b/source/blender/render/intern/raytrace/rayobject_empty.cpp
deleted file mode 100644
index eacec0b7eb9..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_empty.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 1990-1998 NeoGeo BV.
- * All rights reserved.
- *
- * Contributors: 2004/2005 Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_empty.cpp
- * \ingroup render
- */
-
-
-#include "MEM_guardedalloc.h"
-
-#include "rayobject.h"
-
-#include "BLI_utildefines.h"
-
-/*
- * Empty raytree
- */
-
-static int RE_rayobject_empty_intersect(RayObject *UNUSED(o), Isect *UNUSED(is))
-{
- return 0;
-}
-
-static void RE_rayobject_empty_free(RayObject *UNUSED(o))
-{
-}
-
-static void RE_rayobject_empty_bb(RayObject *UNUSED(o), float *UNUSED(min), float *UNUSED(max))
-{
- return;
-}
-
-static float RE_rayobject_empty_cost(RayObject *UNUSED(o))
-{
- return 0.0;
-}
-
-static void RE_rayobject_empty_hint_bb(RayObject *UNUSED(o), RayHint *UNUSED(hint),
- float *UNUSED(min), float *UNUSED(max))
-{}
-
-static RayObjectAPI empty_api =
-{
- RE_rayobject_empty_intersect,
- NULL, //static void RE_rayobject_instance_add(RayObject *o, RayObject *ob);
- NULL, //static void RE_rayobject_instance_done(RayObject *o);
- RE_rayobject_empty_free,
- RE_rayobject_empty_bb,
- RE_rayobject_empty_cost,
- RE_rayobject_empty_hint_bb
-};
-
-static RayObject empty_raytree = { &empty_api, {NULL, NULL} };
-
-RayObject *RE_rayobject_empty_create()
-{
- return RE_rayobject_unalignRayAPI( &empty_raytree );
-}
-
diff --git a/source/blender/render/intern/raytrace/rayobject_hint.h b/source/blender/render/intern/raytrace/rayobject_hint.h
deleted file mode 100644
index 6eb3c035935..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_hint.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_hint.h
- * \ingroup render
- */
-
-
-#ifndef __RAYOBJECT_HINT_H__
-#define __RAYOBJECT_HINT_H__
-
-#define HINT_RECURSE 1
-#define HINT_ACCEPT 0
-#define HINT_DISCARD -1
-
-struct HintBB {
- float bb[6];
-};
-
-inline int hint_test_bb(HintBB *obj, float *Nmin, float *Nmax)
-{
- if (bb_fits_inside(Nmin, Nmax, obj->bb, obj->bb + 3) )
- return HINT_RECURSE;
- else
- return HINT_ACCEPT;
-}
-#if 0
-struct HintFrustum {
- float co[3];
- float no[4][3];
-};
-
-inline int hint_test_bb(HintFrustum &obj, float *Nmin, float *Nmax)
-{
- //if frustum inside BB
- {
- return HINT_RECURSE;
- }
- //if BB outside frustum
- {
- return HINT_DISCARD;
- }
-
- return HINT_ACCEPT;
-}
-#endif
-
-#endif /* __RAYOBJECT_HINT_H__ */
diff --git a/source/blender/render/intern/raytrace/rayobject_instance.cpp b/source/blender/render/intern/raytrace/rayobject_instance.cpp
deleted file mode 100644
index 349f0fc6844..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_instance.cpp
+++ /dev/null
@@ -1,211 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_instance.cpp
- * \ingroup render
- */
-
-
-#include <assert.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "rayintersection.h"
-#include "rayobject.h"
-
-#define RE_COST_INSTANCE (1.0f)
-
-static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec);
-static void RE_rayobject_instance_free(RayObject *o);
-static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max);
-static float RE_rayobject_instance_cost(RayObject *o);
-
-static void RE_rayobject_instance_hint_bb(RayObject *UNUSED(o), RayHint *UNUSED(hint),
- float *UNUSED(min), float *UNUSED(max))
-{}
-
-static RayObjectAPI instance_api =
-{
- RE_rayobject_instance_intersect,
- NULL, //static void RE_rayobject_instance_add(RayObject *o, RayObject *ob);
- NULL, //static void RE_rayobject_instance_done(RayObject *o);
- RE_rayobject_instance_free,
- RE_rayobject_instance_bb,
- RE_rayobject_instance_cost,
- RE_rayobject_instance_hint_bb
-};
-
-typedef struct InstanceRayObject {
- RayObject rayobj;
- RayObject *target;
-
- void *ob; //Object represented by this instance
- void *target_ob; //Object represented by the inner RayObject, needed to handle self-intersection
-
- float global2target[4][4];
- float target2global[4][4];
-
-} InstanceRayObject;
-
-
-RayObject *RE_rayobject_instance_create(RayObject *target, float transform[4][4], void *ob, void *target_ob)
-{
- InstanceRayObject *obj = (InstanceRayObject *)MEM_callocN(sizeof(InstanceRayObject), "InstanceRayObject");
- assert(RE_rayobject_isAligned(obj) ); /* RayObject API assumes real data to be 4-byte aligned */
-
- obj->rayobj.api = &instance_api;
- obj->target = target;
- obj->ob = ob;
- obj->target_ob = target_ob;
-
- copy_m4_m4(obj->target2global, transform);
- invert_m4_m4(obj->global2target, obj->target2global);
-
- return RE_rayobject_unalignRayAPI((RayObject *) obj);
-}
-
-static int RE_rayobject_instance_intersect(RayObject *o, Isect *isec)
-{
- InstanceRayObject *obj = (InstanceRayObject *)o;
- float start[3], dir[3], idot_axis[3], dist;
- int changed = 0, i, res;
-
- // TODO - this is disabling self intersection on instances
- if (isec->orig.ob == obj->ob && obj->ob) {
- changed = 1;
- isec->orig.ob = obj->target_ob;
- }
-
- // backup old values
- copy_v3_v3(start, isec->start);
- copy_v3_v3(dir, isec->dir);
- copy_v3_v3(idot_axis, isec->idot_axis);
- dist = isec->dist;
-
- // transform to target coordinates system
- mul_m4_v3(obj->global2target, isec->start);
- mul_mat3_m4_v3(obj->global2target, isec->dir);
- isec->dist *= normalize_v3(isec->dir);
-
- // update idot_axis and bv_index
- for (i = 0; i < 3; i++) {
- isec->idot_axis[i] = 1.0f / isec->dir[i];
-
- isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0;
- isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i];
-
- isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i];
- isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1];
- }
-
- // Pre-calculate orientation for watertight intersection checks.
- isect_ray_tri_watertight_v3_precalc(&isec->isect_precalc, isec->dir);
-
- // raycast
- res = RE_rayobject_intersect(obj->target, isec);
-
- // map dist into original coordinate space
- if (res == 0) {
- isec->dist = dist;
- }
- else {
- // note we don't just multiply dist, because of possible
- // non-uniform scaling in the transform matrix
- float vec[3];
-
- mul_v3_v3fl(vec, isec->dir, isec->dist);
- mul_mat3_m4_v3(obj->target2global, vec);
-
- isec->dist = len_v3(vec);
- isec->hit.ob = obj->ob;
-
-#ifdef RT_USE_LAST_HIT
- // TODO support for last hit optimization in instances that can jump
- // directly to the last hit face.
- // For now it jumps directly to the last-hit instance root node.
- isec->last_hit = RE_rayobject_unalignRayAPI((RayObject *) obj);
-#endif
- }
-
- // restore values
- copy_v3_v3(isec->start, start);
- copy_v3_v3(isec->dir, dir);
- copy_v3_v3(isec->idot_axis, idot_axis);
-
- if (changed)
- isec->orig.ob = obj->ob;
-
- // restore bv_index
- for (i = 0; i < 3; i++) {
- isec->bv_index[2 * i] = isec->idot_axis[i] < 0.0f ? 1 : 0;
- isec->bv_index[2 * i + 1] = 1 - isec->bv_index[2 * i];
-
- isec->bv_index[2 * i] = i + 3 * isec->bv_index[2 * i];
- isec->bv_index[2 * i + 1] = i + 3 * isec->bv_index[2 * i + 1];
- }
-
- // Pre-calculate orientation for watertight intersection checks.
- isect_ray_tri_watertight_v3_precalc(&isec->isect_precalc, isec->dir);
-
- return res;
-}
-
-static void RE_rayobject_instance_free(RayObject *o)
-{
- InstanceRayObject *obj = (InstanceRayObject *)o;
- MEM_freeN(obj);
-}
-
-static float RE_rayobject_instance_cost(RayObject *o)
-{
- InstanceRayObject *obj = (InstanceRayObject *)o;
- return RE_rayobject_cost(obj->target) + RE_COST_INSTANCE;
-}
-
-static void RE_rayobject_instance_bb(RayObject *o, float *min, float *max)
-{
- //TODO:
- // *better bb.. calculated without rotations of bb
- // *maybe cache that better-fitted-BB at the InstanceRayObject
- InstanceRayObject *obj = (InstanceRayObject *)o;
-
- float m[3], M[3], t[3];
- int i, j;
- INIT_MINMAX(m, M);
- RE_rayobject_merge_bb(obj->target, m, M);
-
- //There must be a faster way than rotating all the 8 vertexs of the BB
- for (i = 0; i < 8; i++) {
- for (j = 0; j < 3; j++) t[j] = (i & (1 << j)) ? M[j] : m[j];
- mul_m4_v3(obj->target2global, t);
- DO_MINMAX(t, min, max);
- }
-}
-
diff --git a/source/blender/render/intern/raytrace/rayobject_internal.h b/source/blender/render/intern/raytrace/rayobject_internal.h
deleted file mode 100644
index 5b8a43eab03..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_internal.h
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __RAYOBJECT_INTERNAL_H__
-#define __RAYOBJECT_INTERNAL_H__
-
-/** \file blender/render/intern/raytrace/rayobject_internal.h
- * \ingroup render
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* RayObjectControl
- *
- * This class is intended as a place holder for control, configuration of the
- * rayobject like:
- * - stop building (TODO maybe when porting build to threads this could be
- * implemented with some thread_cancel function)
- * - max number of threads and threads callback to use during build
- * ...
- */
-
-typedef int (*RE_rayobjectcontrol_test_break_callback)(void *data);
-
-typedef struct RayObjectControl {
- void *data;
- RE_rayobjectcontrol_test_break_callback test_break;
-} RayObjectControl;
-
-/* Returns true if for some reason a heavy processing function should stop
- * (eg.: user asked to stop during a tree a build)
- */
-
-int RE_rayobjectcontrol_test_break(RayObjectControl *c);
-
-/* RayObject
- *
- * A ray object is everything where we can cast rays like:
- * * a face/triangle
- * * an octree
- * * a bvh tree
- * * an octree of bvh's
- * * a bvh of bvh's
- *
- *
- * All types of RayObjects can be created by implementing the
- * callbacks of the RayObject.
- *
- * Due to high computing time evolved with casting on faces
- * there is a special type of RayObject (named RayFace)
- * which won't use callbacks like other generic nodes.
- *
- * In order to allow a mixture of RayFace+RayObjects,
- * all RayObjects must be 4byte aligned, allowing us to use the
- * 2 least significant bits (with the mask 0x03) to define the
- * type of RayObject.
- *
- * This leads to 4 possible types of RayObject:
- *
- * addr&3 - type of object
- * 0 Self (reserved for each structure)
- * 1 RayFace (tri/quad primitive)
- * 2 RayObject (generic with API callbacks)
- * 3 VlakPrimitive
- * (vlak primitive - to be used when we have a vlak describing the data
- * eg.: on render code)
- *
- * 0 means it's reserved and has it own meaning inside each ray acceleration structure
- * (this way each structure can use the align offset to determine if a node represents a
- * RayObject primitive, which can be used to save memory)
- */
-
-/* used to test the type of ray object */
-#define RE_rayobject_isAligned(o) ((((intptr_t)o)&3) == 0)
-#define RE_rayobject_isRayFace(o) ((((intptr_t)o)&3) == 1)
-#define RE_rayobject_isRayAPI(o) ((((intptr_t)o)&3) == 2)
-#define RE_rayobject_isVlakPrimitive(o) ((((intptr_t)o)&3) == 3)
-
-/* used to align a given ray object */
-#define RE_rayobject_align(o) ((RayObject *)(((intptr_t)o)&(~3)))
-
-/* used to unalign a given ray object */
-#define RE_rayobject_unalignRayFace(o) ((RayObject *)(((intptr_t)o)|1))
-#define RE_rayobject_unalignRayAPI(o) ((RayObject *)(((intptr_t)o)|2))
-#define RE_rayobject_unalignVlakPrimitive(o) ((RayObject *)(((intptr_t)o)|3))
-
-/*
- * This rayobject represents a generic object. With it's own callbacks for raytrace operations.
- * It's suitable to implement things like LOD.
- */
-
-struct RayObject {
- struct RayObjectAPI *api;
- struct RayObjectControl control;
-};
-
-typedef int (*RE_rayobject_raycast_callback)(RayObject *, struct Isect *);
-typedef void (*RE_rayobject_add_callback)(RayObject *raytree, RayObject *rayobject);
-typedef void (*RE_rayobject_done_callback)(RayObject *);
-typedef void (*RE_rayobject_free_callback)(RayObject *);
-typedef void (*RE_rayobject_merge_bb_callback)(RayObject *, float min[3], float max[3]);
-typedef float (*RE_rayobject_cost_callback)(RayObject *);
-typedef void (*RE_rayobject_hint_bb_callback)(RayObject *, struct RayHint *, float min[3], float max[3]);
-
-typedef struct RayObjectAPI {
- RE_rayobject_raycast_callback raycast;
- RE_rayobject_add_callback add;
- RE_rayobject_done_callback done;
- RE_rayobject_free_callback free;
- RE_rayobject_merge_bb_callback bb;
- RE_rayobject_cost_callback cost;
- RE_rayobject_hint_bb_callback hint_bb;
-} RayObjectAPI;
-
-/*
- * Returns the expected cost of raycast on this node, primitives have a cost of 1
- */
-float RE_rayobject_cost(RayObject *r);
-
-/*
- * This function differs from RE_rayobject_raycast
- * RE_rayobject_intersect does NOT perform last-hit optimization
- * So this is probably a function to call inside raytrace structures
- */
-int RE_rayobject_intersect(RayObject *r, struct Isect *i);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __RAYOBJECT_INTERNAL_H__ */
diff --git a/source/blender/render/intern/raytrace/rayobject_octree.cpp b/source/blender/render/intern/raytrace/rayobject_octree.cpp
deleted file mode 100644
index b21197e728d..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_octree.cpp
+++ /dev/null
@@ -1,1101 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 1990-1998 NeoGeo BV.
- * All rights reserved.
- *
- * Contributors: 2004/2005 Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_octree.cpp
- * \ingroup render
- */
-
-
-/* IMPORTANT NOTE: this code must be independent of any other render code
- * to use it outside the renderer! */
-
-#include <math.h>
-#include <string.h>
-#include <stdlib.h>
-#include <float.h>
-#include <assert.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_material_types.h"
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "rayintersection.h"
-#include "rayobject.h"
-
-/* ********** structs *************** */
-#define BRANCH_ARRAY 1024
-#define NODE_ARRAY 4096
-
-typedef struct Branch {
- struct Branch *b[8];
-} Branch;
-
-typedef struct OcVal {
- short ocx, ocy, ocz;
-} OcVal;
-
-typedef struct Node {
- struct RayFace *v[8];
- struct OcVal ov[8];
- struct Node *next;
-} Node;
-
-typedef struct Octree {
- RayObject rayobj;
-
- struct Branch **adrbranch;
- struct Node **adrnode;
- float ocsize; /* ocsize: mult factor, max size octree */
- float ocfacx, ocfacy, ocfacz;
- float min[3], max[3];
- int ocres;
- int branchcount, nodecount;
-
- /* during building only */
- char *ocface;
-
- RayFace **ro_nodes;
- int ro_nodes_size, ro_nodes_used;
-
-} Octree;
-
-static int RE_rayobject_octree_intersect(RayObject *o, Isect *isec);
-static void RE_rayobject_octree_add(RayObject *o, RayObject *ob);
-static void RE_rayobject_octree_done(RayObject *o);
-static void RE_rayobject_octree_free(RayObject *o);
-static void RE_rayobject_octree_bb(RayObject *o, float *min, float *max);
-
-/*
- * This function is not expected to be called by current code state.
- */
-static float RE_rayobject_octree_cost(RayObject *UNUSED(o))
-{
- return 1.0;
-}
-
-static void RE_rayobject_octree_hint_bb(RayObject *UNUSED(o), RayHint *UNUSED(hint),
- float *UNUSED(min), float *UNUSED(max))
-{
- return;
-}
-
-static RayObjectAPI octree_api =
-{
- RE_rayobject_octree_intersect,
- RE_rayobject_octree_add,
- RE_rayobject_octree_done,
- RE_rayobject_octree_free,
- RE_rayobject_octree_bb,
- RE_rayobject_octree_cost,
- RE_rayobject_octree_hint_bb
-};
-
-/* **************** ocval method ******************* */
-/* within one octree node, a set of 3x15 bits defines a 'boundbox' to OR with */
-
-#define OCVALRES 15
-#define BROW16(min, max) \
- (((max) >= OCVALRES ? 0xFFFF : (1 << ((max) + 1)) - 1) - (((min) > 0) ? ((1 << (min)) - 1) : 0))
-
-static void calc_ocval_face(float *v1, float *v2, float *v3, float *v4, short x, short y, short z, OcVal *ov)
-{
- float min[3], max[3];
- int ocmin, ocmax;
-
- copy_v3_v3(min, v1);
- copy_v3_v3(max, v1);
- DO_MINMAX(v2, min, max);
- DO_MINMAX(v3, min, max);
- if (v4) {
- DO_MINMAX(v4, min, max);
- }
-
- ocmin = OCVALRES * (min[0] - x);
- ocmax = OCVALRES * (max[0] - x);
- ov->ocx = BROW16(ocmin, ocmax);
-
- ocmin = OCVALRES * (min[1] - y);
- ocmax = OCVALRES * (max[1] - y);
- ov->ocy = BROW16(ocmin, ocmax);
-
- ocmin = OCVALRES * (min[2] - z);
- ocmax = OCVALRES * (max[2] - z);
- ov->ocz = BROW16(ocmin, ocmax);
-
-}
-
-static void calc_ocval_ray(OcVal *ov, float xo, float yo, float zo, float *vec1, float *vec2)
-{
- int ocmin, ocmax;
-
- if (vec1[0] < vec2[0]) {
- ocmin = OCVALRES * (vec1[0] - xo);
- ocmax = OCVALRES * (vec2[0] - xo);
- }
- else {
- ocmin = OCVALRES * (vec2[0] - xo);
- ocmax = OCVALRES * (vec1[0] - xo);
- }
- ov->ocx = BROW16(ocmin, ocmax);
-
- if (vec1[1] < vec2[1]) {
- ocmin = OCVALRES * (vec1[1] - yo);
- ocmax = OCVALRES * (vec2[1] - yo);
- }
- else {
- ocmin = OCVALRES * (vec2[1] - yo);
- ocmax = OCVALRES * (vec1[1] - yo);
- }
- ov->ocy = BROW16(ocmin, ocmax);
-
- if (vec1[2] < vec2[2]) {
- ocmin = OCVALRES * (vec1[2] - zo);
- ocmax = OCVALRES * (vec2[2] - zo);
- }
- else {
- ocmin = OCVALRES * (vec2[2] - zo);
- ocmax = OCVALRES * (vec1[2] - zo);
- }
- ov->ocz = BROW16(ocmin, ocmax);
-}
-
-/* ************* octree ************** */
-
-static Branch *addbranch(Octree *oc, Branch *br, short ocb)
-{
- int index;
-
- if (br->b[ocb]) return br->b[ocb];
-
- oc->branchcount++;
- index = oc->branchcount >> 12;
-
- if (oc->adrbranch[index] == NULL)
- oc->adrbranch[index] = (Branch *)MEM_callocN(4096 * sizeof(Branch), "new oc branch");
-
- if (oc->branchcount >= BRANCH_ARRAY * 4096) {
- printf("error; octree branches full\n");
- oc->branchcount = 0;
- }
-
- return br->b[ocb] = oc->adrbranch[index] + (oc->branchcount & 4095);
-}
-
-static Node *addnode(Octree *oc)
-{
- int index;
-
- oc->nodecount++;
- index = oc->nodecount >> 12;
-
- if (oc->adrnode[index] == NULL)
- oc->adrnode[index] = (Node *)MEM_callocN(4096 * sizeof(Node), "addnode");
-
- if (oc->nodecount > NODE_ARRAY * NODE_ARRAY) {
- printf("error; octree nodes full\n");
- oc->nodecount = 0;
- }
-
- return oc->adrnode[index] + (oc->nodecount & 4095);
-}
-
-static bool face_in_node(RayFace *face, short x, short y, short z, float rtf[4][3])
-{
- static float nor[3], d;
- float fx, fy, fz;
-
- // init static vars
- if (face) {
- normal_tri_v3(nor, rtf[0], rtf[1], rtf[2]);
- d = -nor[0] * rtf[0][0] - nor[1] * rtf[0][1] - nor[2] * rtf[0][2];
- return 0;
- }
-
- fx = x;
- fy = y;
- fz = z;
-
- if ((fx) * nor[0] + (fy) * nor[1] + (fz) * nor[2] + d > 0.0f) {
- if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz ) * nor[2] + d < 0.0f) return 1;
- if ((fx ) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d < 0.0f) return 1;
- if ((fx + 1) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d < 0.0f) return 1;
-
- if ((fx ) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d < 0.0f) return 1;
- if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d < 0.0f) return 1;
- if ((fx ) * nor[0] + (fy + 1) * nor[1] + (fz + 1) * nor[2] + d < 0.0f) return 1;
- if ((fx + 1) * nor[0] + (fy + 1) * nor[1] + (fz + 1) * nor[2] + d < 0.0f) return 1;
- }
- else {
- if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz ) * nor[2] + d > 0.0f) return 1;
- if ((fx ) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d > 0.0f) return 1;
- if ((fx + 1) * nor[0] + (fy + 1) * nor[1] + (fz ) * nor[2] + d > 0.0f) return 1;
-
- if ((fx ) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1;
- if ((fx + 1) * nor[0] + (fy ) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1;
- if ((fx ) * nor[0] + (fy + 1) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1;
- if ((fx + 1) * nor[0] + (fy + 1) * nor[1] + (fz + 1) * nor[2] + d > 0.0f) return 1;
- }
-
- return 0;
-}
-
-static void ocwrite(Octree *oc, RayFace *face, int quad, short x, short y, short z, float rtf[4][3])
-{
- Branch *br;
- Node *no;
- short a, oc0, oc1, oc2, oc3, oc4, oc5;
-
- x <<= 2;
- y <<= 1;
-
- br = oc->adrbranch[0];
-
- if (oc->ocres == 512) {
- oc0 = ((x & 1024) + (y & 512) + (z & 256)) >> 8;
- br = addbranch(oc, br, oc0);
- }
- if (oc->ocres >= 256) {
- oc0 = ((x & 512) + (y & 256) + (z & 128)) >> 7;
- br = addbranch(oc, br, oc0);
- }
- if (oc->ocres >= 128) {
- oc0 = ((x & 256) + (y & 128) + (z & 64)) >> 6;
- br = addbranch(oc, br, oc0);
- }
-
- oc0 = ((x & 128) + (y & 64) + (z & 32)) >> 5;
- oc1 = ((x & 64) + (y & 32) + (z & 16)) >> 4;
- oc2 = ((x & 32) + (y & 16) + (z & 8)) >> 3;
- oc3 = ((x & 16) + (y & 8) + (z & 4)) >> 2;
- oc4 = ((x & 8) + (y & 4) + (z & 2)) >> 1;
- oc5 = ((x & 4) + (y & 2) + (z & 1));
-
- br = addbranch(oc, br, oc0);
- br = addbranch(oc, br, oc1);
- br = addbranch(oc, br, oc2);
- br = addbranch(oc, br, oc3);
- br = addbranch(oc, br, oc4);
- no = (Node *)br->b[oc5];
- if (no == NULL) br->b[oc5] = (Branch *)(no = addnode(oc));
-
- while (no->next) no = no->next;
-
- a = 0;
- if (no->v[7]) { /* node full */
- no->next = addnode(oc);
- no = no->next;
- }
- else {
- while (no->v[a] != NULL) a++;
- }
-
- no->v[a] = (RayFace *) RE_rayobject_align(face);
-
- if (quad)
- calc_ocval_face(rtf[0], rtf[1], rtf[2], rtf[3], x >> 2, y >> 1, z, &no->ov[a]);
- else
- calc_ocval_face(rtf[0], rtf[1], rtf[2], NULL, x >> 2, y >> 1, z, &no->ov[a]);
-}
-
-static void d2dda(Octree *oc, short b1, short b2, short c1, short c2, char *ocface, short rts[4][3], float rtf[4][3])
-{
- int ocx1, ocx2, ocy1, ocy2;
- int x, y, dx = 0, dy = 0;
- float ox1, ox2, oy1, oy2;
- float lambda, lambda_o, lambda_x, lambda_y, ldx, ldy;
-
- ocx1 = rts[b1][c1];
- ocy1 = rts[b1][c2];
- ocx2 = rts[b2][c1];
- ocy2 = rts[b2][c2];
-
- if (ocx1 == ocx2 && ocy1 == ocy2) {
- ocface[oc->ocres * ocx1 + ocy1] = 1;
- return;
- }
-
- ox1 = rtf[b1][c1];
- oy1 = rtf[b1][c2];
- ox2 = rtf[b2][c1];
- oy2 = rtf[b2][c2];
-
- if (ox1 != ox2) {
- if (ox2 - ox1 > 0.0f) {
- lambda_x = (ox1 - ocx1 - 1.0f) / (ox1 - ox2);
- ldx = -1.0f / (ox1 - ox2);
- dx = 1;
- }
- else {
- lambda_x = (ox1 - ocx1) / (ox1 - ox2);
- ldx = 1.0f / (ox1 - ox2);
- dx = -1;
- }
- }
- else {
- lambda_x = 1.0f;
- ldx = 0;
- }
-
- if (oy1 != oy2) {
- if (oy2 - oy1 > 0.0f) {
- lambda_y = (oy1 - ocy1 - 1.0f) / (oy1 - oy2);
- ldy = -1.0f / (oy1 - oy2);
- dy = 1;
- }
- else {
- lambda_y = (oy1 - ocy1) / (oy1 - oy2);
- ldy = 1.0f / (oy1 - oy2);
- dy = -1;
- }
- }
- else {
- lambda_y = 1.0f;
- ldy = 0;
- }
-
- x = ocx1; y = ocy1;
- lambda = MIN2(lambda_x, lambda_y);
-
- while (true) {
-
- if (x < 0 || y < 0 || x >= oc->ocres || y >= oc->ocres) {
- /* pass*/
- }
- else {
- ocface[oc->ocres * x + y] = 1;
- }
-
- lambda_o = lambda;
- if (lambda_x == lambda_y) {
- lambda_x += ldx;
- x += dx;
- lambda_y += ldy;
- y += dy;
- }
- else {
- if (lambda_x < lambda_y) {
- lambda_x += ldx;
- x += dx;
- }
- else {
- lambda_y += ldy;
- y += dy;
- }
- }
- lambda = MIN2(lambda_x, lambda_y);
- if (lambda == lambda_o) break;
- if (lambda >= 1.0f) break;
- }
- ocface[oc->ocres * ocx2 + ocy2] = 1;
-}
-
-static void filltriangle(Octree *oc, short c1, short c2, char *ocface, short *ocmin, short *ocmax)
-{
- int a, x, y, y1, y2;
-
- for (x = ocmin[c1]; x <= ocmax[c1]; x++) {
- a = oc->ocres * x;
- for (y = ocmin[c2]; y <= ocmax[c2]; y++) {
- if (ocface[a + y]) {
- y++;
- while (ocface[a + y] && y != ocmax[c2]) y++;
- for (y1 = ocmax[c2]; y1 > y; y1--) {
- if (ocface[a + y1]) {
- for (y2 = y; y2 <= y1; y2++) ocface[a + y2] = 1;
- y1 = 0;
- }
- }
- y = ocmax[c2];
- }
- }
- }
-}
-
-static void RE_rayobject_octree_free(RayObject *tree)
-{
- Octree *oc = (Octree *)tree;
-
-#if 0
- printf("branches %d nodes %d\n", oc->branchcount, oc->nodecount);
- printf("raycount %d\n", raycount);
- printf("ray coherent %d\n", coherent_ray);
- printf("accepted %d rejected %d\n", accepted, rejected);
-#endif
- if (oc->ocface)
- MEM_freeN(oc->ocface);
-
- if (oc->adrbranch) {
- int a = 0;
- while (oc->adrbranch[a]) {
- MEM_freeN(oc->adrbranch[a]);
- oc->adrbranch[a] = NULL;
- a++;
- }
- MEM_freeN(oc->adrbranch);
- oc->adrbranch = NULL;
- }
- oc->branchcount = 0;
-
- if (oc->adrnode) {
- int a = 0;
- while (oc->adrnode[a]) {
- MEM_freeN(oc->adrnode[a]);
- oc->adrnode[a] = NULL;
- a++;
- }
- MEM_freeN(oc->adrnode);
- oc->adrnode = NULL;
- }
- oc->nodecount = 0;
-
- MEM_freeN(oc);
-}
-
-
-RayObject *RE_rayobject_octree_create(int ocres, int size)
-{
- Octree *oc = (Octree *)MEM_callocN(sizeof(Octree), "Octree");
- assert(RE_rayobject_isAligned(oc) ); /* RayObject API assumes real data to be 4-byte aligned */
-
- oc->rayobj.api = &octree_api;
-
- oc->ocres = ocres;
-
- oc->ro_nodes = (RayFace **)MEM_callocN(sizeof(RayFace *) * size, "octree rayobject nodes");
- oc->ro_nodes_size = size;
- oc->ro_nodes_used = 0;
-
-
- return RE_rayobject_unalignRayAPI((RayObject *) oc);
-}
-
-
-static void RE_rayobject_octree_add(RayObject *tree, RayObject *node)
-{
- Octree *oc = (Octree *)tree;
-
- assert(RE_rayobject_isRayFace(node) );
- assert(oc->ro_nodes_used < oc->ro_nodes_size);
- oc->ro_nodes[oc->ro_nodes_used++] = (RayFace *)RE_rayobject_align(node);
-}
-
-static void octree_fill_rayface(Octree *oc, RayFace *face)
-{
- float ocfac[3], rtf[4][3];
- float co1[3], co2[3], co3[3], co4[3];
- short rts[4][3];
- short ocmin[3], ocmax[3];
- char *ocface = oc->ocface; // front, top, size view of face, to fill in
- int a, b, c, oc1, oc2, oc3, oc4, x, y, z, ocres2;
-
- ocfac[0] = oc->ocfacx;
- ocfac[1] = oc->ocfacy;
- ocfac[2] = oc->ocfacz;
-
- ocres2 = oc->ocres * oc->ocres;
-
- copy_v3_v3(co1, face->v1);
- copy_v3_v3(co2, face->v2);
- copy_v3_v3(co3, face->v3);
- if (RE_rayface_isQuad(face))
- copy_v3_v3(co4, face->v4);
-
- for (c = 0; c < 3; c++) {
- rtf[0][c] = (co1[c] - oc->min[c]) * ocfac[c];
- rts[0][c] = (short)rtf[0][c];
- rtf[1][c] = (co2[c] - oc->min[c]) * ocfac[c];
- rts[1][c] = (short)rtf[1][c];
- rtf[2][c] = (co3[c] - oc->min[c]) * ocfac[c];
- rts[2][c] = (short)rtf[2][c];
- if (RE_rayface_isQuad(face)) {
- rtf[3][c] = (co4[c] - oc->min[c]) * ocfac[c];
- rts[3][c] = (short)rtf[3][c];
- }
- }
-
- for (c = 0; c < 3; c++) {
- oc1 = rts[0][c];
- oc2 = rts[1][c];
- oc3 = rts[2][c];
- if (!RE_rayface_isQuad(face)) {
- ocmin[c] = min_iii(oc1, oc2, oc3);
- ocmax[c] = max_iii(oc1, oc2, oc3);
- }
- else {
- oc4 = rts[3][c];
- ocmin[c] = min_iiii(oc1, oc2, oc3, oc4);
- ocmax[c] = max_iiii(oc1, oc2, oc3, oc4);
- }
- if (ocmax[c] > oc->ocres - 1) ocmax[c] = oc->ocres - 1;
- if (ocmin[c] < 0) ocmin[c] = 0;
- }
-
- if (ocmin[0] == ocmax[0] && ocmin[1] == ocmax[1] && ocmin[2] == ocmax[2]) {
- ocwrite(oc, face, RE_rayface_isQuad(face), ocmin[0], ocmin[1], ocmin[2], rtf);
- }
- else {
-
- d2dda(oc, 0, 1, 0, 1, ocface + ocres2, rts, rtf);
- d2dda(oc, 0, 1, 0, 2, ocface, rts, rtf);
- d2dda(oc, 0, 1, 1, 2, ocface + 2 * ocres2, rts, rtf);
- d2dda(oc, 1, 2, 0, 1, ocface + ocres2, rts, rtf);
- d2dda(oc, 1, 2, 0, 2, ocface, rts, rtf);
- d2dda(oc, 1, 2, 1, 2, ocface + 2 * ocres2, rts, rtf);
- if (!RE_rayface_isQuad(face)) {
- d2dda(oc, 2, 0, 0, 1, ocface + ocres2, rts, rtf);
- d2dda(oc, 2, 0, 0, 2, ocface, rts, rtf);
- d2dda(oc, 2, 0, 1, 2, ocface + 2 * ocres2, rts, rtf);
- }
- else {
- d2dda(oc, 2, 3, 0, 1, ocface + ocres2, rts, rtf);
- d2dda(oc, 2, 3, 0, 2, ocface, rts, rtf);
- d2dda(oc, 2, 3, 1, 2, ocface + 2 * ocres2, rts, rtf);
- d2dda(oc, 3, 0, 0, 1, ocface + ocres2, rts, rtf);
- d2dda(oc, 3, 0, 0, 2, ocface, rts, rtf);
- d2dda(oc, 3, 0, 1, 2, ocface + 2 * ocres2, rts, rtf);
- }
- /* nothing todo with triangle..., just fills :) */
- filltriangle(oc, 0, 1, ocface + ocres2, ocmin, ocmax);
- filltriangle(oc, 0, 2, ocface, ocmin, ocmax);
- filltriangle(oc, 1, 2, ocface + 2 * ocres2, ocmin, ocmax);
-
- /* init static vars here */
- face_in_node(face, 0, 0, 0, rtf);
-
- for (x = ocmin[0]; x <= ocmax[0]; x++) {
- a = oc->ocres * x;
- for (y = ocmin[1]; y <= ocmax[1]; y++) {
- if (ocface[a + y + ocres2]) {
- b = oc->ocres * y + 2 * ocres2;
- for (z = ocmin[2]; z <= ocmax[2]; z++) {
- if (ocface[b + z] && ocface[a + z]) {
- if (face_in_node(NULL, x, y, z, rtf))
- ocwrite(oc, face, RE_rayface_isQuad(face), x, y, z, rtf);
- }
- }
- }
- }
- }
-
- /* same loops to clear octree, doubt it can be done smarter */
- for (x = ocmin[0]; x <= ocmax[0]; x++) {
- a = oc->ocres * x;
- for (y = ocmin[1]; y <= ocmax[1]; y++) {
- /* x-y */
- ocface[a + y + ocres2] = 0;
-
- b = oc->ocres * y + 2 * ocres2;
- for (z = ocmin[2]; z <= ocmax[2]; z++) {
- /* y-z */
- ocface[b + z] = 0;
- /* x-z */
- ocface[a + z] = 0;
- }
- }
- }
- }
-}
-
-static void RE_rayobject_octree_done(RayObject *tree)
-{
- Octree *oc = (Octree *)tree;
- int c;
- float t00, t01, t02;
- int ocres2 = oc->ocres * oc->ocres;
-
- INIT_MINMAX(oc->min, oc->max);
-
- /* Calculate Bounding Box */
- for (c = 0; c < oc->ro_nodes_used; c++)
- RE_rayobject_merge_bb(RE_rayobject_unalignRayFace(oc->ro_nodes[c]), oc->min, oc->max);
-
- /* Alloc memory */
- oc->adrbranch = (Branch **)MEM_callocN(sizeof(void *) * BRANCH_ARRAY, "octree branches");
- oc->adrnode = (Node **)MEM_callocN(sizeof(void *) * NODE_ARRAY, "octree nodes");
-
- oc->adrbranch[0] = (Branch *)MEM_callocN(4096 * sizeof(Branch), "makeoctree");
-
- /* the lookup table, per face, for which nodes to fill in */
- oc->ocface = (char *)MEM_callocN(3 * ocres2 + 8, "ocface");
- memset(oc->ocface, 0, 3 * ocres2);
-
- for (c = 0; c < 3; c++) { /* octree enlarge, still needed? */
- oc->min[c] -= 0.01f;
- oc->max[c] += 0.01f;
- }
-
- t00 = oc->max[0] - oc->min[0];
- t01 = oc->max[1] - oc->min[1];
- t02 = oc->max[2] - oc->min[2];
-
- /* this minus 0.1 is old safety... seems to be needed? */
- oc->ocfacx = (oc->ocres - 0.1f) / t00;
- oc->ocfacy = (oc->ocres - 0.1f) / t01;
- oc->ocfacz = (oc->ocres - 0.1f) / t02;
-
- oc->ocsize = sqrtf(t00 * t00 + t01 * t01 + t02 * t02); /* global, max size octree */
-
- for (c = 0; c < oc->ro_nodes_used; c++) {
- octree_fill_rayface(oc, oc->ro_nodes[c]);
- }
-
- MEM_freeN(oc->ocface);
- oc->ocface = NULL;
- MEM_freeN(oc->ro_nodes);
- oc->ro_nodes = NULL;
-
-#if 0
- printf("%f %f - %f\n", oc->min[0], oc->max[0], oc->ocfacx);
- printf("%f %f - %f\n", oc->min[1], oc->max[1], oc->ocfacy);
- printf("%f %f - %f\n", oc->min[2], oc->max[2], oc->ocfacz);
-#endif
-}
-
-static void RE_rayobject_octree_bb(RayObject *tree, float *min, float *max)
-{
- Octree *oc = (Octree *)tree;
- DO_MINMAX(oc->min, min, max);
- DO_MINMAX(oc->max, min, max);
-}
-
-/* check all faces in this node */
-static int testnode(Octree *UNUSED(oc), Isect *is, Node *no, OcVal ocval)
-{
- short nr = 0;
-
- /* return on any first hit */
- if (is->mode == RE_RAY_SHADOW) {
-
- for (; no; no = no->next) {
- for (nr = 0; nr < 8; nr++) {
- RayFace *face = no->v[nr];
- OcVal *ov = no->ov + nr;
-
- if (!face) break;
-
- if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) {
- if (RE_rayobject_intersect(RE_rayobject_unalignRayFace(face), is) )
- return 1;
- }
- }
- }
- }
- else {
- /* else mirror or glass or shadowtra, return closest face */
- int found = 0;
-
- for (; no; no = no->next) {
- for (nr = 0; nr < 8; nr++) {
- RayFace *face = no->v[nr];
- OcVal *ov = no->ov + nr;
-
- if (!face) break;
-
- if ( (ov->ocx & ocval.ocx) && (ov->ocy & ocval.ocy) && (ov->ocz & ocval.ocz) ) {
- if (RE_rayobject_intersect(RE_rayobject_unalignRayFace(face), is) ) {
- found = 1;
- }
- }
- }
- }
-
- return found;
- }
-
- return 0;
-}
-
-/* find the Node for the octree coord x y z */
-static Node *ocread(Octree *oc, int x, int y, int z)
-{
- Branch *br;
- int oc1;
-
- x <<= 2;
- y <<= 1;
-
- br = oc->adrbranch[0];
-
- if (oc->ocres == 512) {
- oc1 = ((x & 1024) + (y & 512) + (z & 256)) >> 8;
- br = br->b[oc1];
- if (br == NULL) {
- return NULL;
- }
- }
- if (oc->ocres >= 256) {
- oc1 = ((x & 512) + (y & 256) + (z & 128)) >> 7;
- br = br->b[oc1];
- if (br == NULL) {
- return NULL;
- }
- }
- if (oc->ocres >= 128) {
- oc1 = ((x & 256) + (y & 128) + (z & 64)) >> 6;
- br = br->b[oc1];
- if (br == NULL) {
- return NULL;
- }
- }
-
- oc1 = ((x & 128) + (y & 64) + (z & 32)) >> 5;
- br = br->b[oc1];
- if (br) {
- oc1 = ((x & 64) + (y & 32) + (z & 16)) >> 4;
- br = br->b[oc1];
- if (br) {
- oc1 = ((x & 32) + (y & 16) + (z & 8)) >> 3;
- br = br->b[oc1];
- if (br) {
- oc1 = ((x & 16) + (y & 8) + (z & 4)) >> 2;
- br = br->b[oc1];
- if (br) {
- oc1 = ((x & 8) + (y & 4) + (z & 2)) >> 1;
- br = br->b[oc1];
- if (br) {
- oc1 = ((x & 4) + (y & 2) + (z & 1));
- return (Node *)br->b[oc1];
- }
- }
- }
- }
- }
-
- return NULL;
-}
-
-static int cliptest(float p, float q, float *u1, float *u2)
-{
- float r;
-
- if (p < 0.0f) {
- if (q < p) return 0;
- else if (q < 0.0f) {
- r = q / p;
- if (r > *u2) return 0;
- else if (r > *u1) *u1 = r;
- }
- }
- else {
- if (p > 0.0f) {
- if (q < 0.0f) return 0;
- else if (q < p) {
- r = q / p;
- if (r < *u1) return 0;
- else if (r < *u2) *u2 = r;
- }
- }
- else if (q < 0.0f) return 0;
- }
- return 1;
-}
-
-/* extensive coherence checks/storage cancels out the benefit of it, and gives errors... we
- * need better methods, sample code commented out below (ton) */
-
-#if 0
-
-in top : static int coh_nodes[16 * 16 * 16][6];
-in makeoctree : memset(coh_nodes, 0, sizeof(coh_nodes));
-
-static void add_coherence_test(int ocx1, int ocx2, int ocy1, int ocy2, int ocz1, int ocz2)
-{
- short *sp;
-
- sp = coh_nodes[(ocx2 & 15) + 16 * (ocy2 & 15) + 256 * (ocz2 & 15)];
- sp[0] = ocx1; sp[1] = ocy1; sp[2] = ocz1;
- sp[3] = ocx2; sp[4] = ocy2; sp[5] = ocz2;
-
-}
-
-static int do_coherence_test(int ocx1, int ocx2, int ocy1, int ocy2, int ocz1, int ocz2)
-{
- short *sp;
-
- sp = coh_nodes[(ocx2 & 15) + 16 * (ocy2 & 15) + 256 * (ocz2 & 15)];
- if (sp[0] == ocx1 && sp[1] == ocy1 && sp[2] == ocz1 &&
- sp[3] == ocx2 && sp[4] == ocy2 && sp[5] == ocz2) return 1;
- return 0;
-}
-
-#endif
-
-/* return 1: found valid intersection */
-/* starts with is->orig.face */
-static int RE_rayobject_octree_intersect(RayObject *tree, Isect *is)
-{
- Octree *oc = (Octree *)tree;
- Node *no;
- OcVal ocval;
- float vec1[3], vec2[3], start[3], end[3];
- float u1, u2, ox1, ox2, oy1, oy2, oz1, oz2;
- float lambda_o, lambda_x, ldx, lambda_y, ldy, lambda_z, ldz, dda_lambda;
- float o_lambda = 0;
- int dx, dy, dz;
- int xo, yo, zo, c1 = 0;
- int ocx1, ocx2, ocy1, ocy2, ocz1, ocz2;
-
- /* clip with octree */
- if (oc->branchcount == 0) return 0;
-
- /* do this before intersect calls */
-#if 0
- is->facecontr = NULL; /* to check shared edge */
- is->obcontr = 0;
- is->faceisect = is->isect = 0; /* shared edge, quad half flag */
- is->userdata = oc->userdata;
-#endif
-
- copy_v3_v3(start, is->start);
- madd_v3_v3v3fl(end, is->start, is->dir, is->dist);
- ldx = is->dir[0] * is->dist;
- o_lambda = is->dist;
- u1 = 0.0f;
- u2 = 1.0f;
-
- /* clip with octree cube */
- if (cliptest(-ldx, start[0] - oc->min[0], &u1, &u2)) {
- if (cliptest(ldx, oc->max[0] - start[0], &u1, &u2)) {
- ldy = is->dir[1] * is->dist;
- if (cliptest(-ldy, start[1] - oc->min[1], &u1, &u2)) {
- if (cliptest(ldy, oc->max[1] - start[1], &u1, &u2)) {
- ldz = is->dir[2] * is->dist;
- if (cliptest(-ldz, start[2] - oc->min[2], &u1, &u2)) {
- if (cliptest(ldz, oc->max[2] - start[2], &u1, &u2)) {
- c1 = 1;
- if (u2 < 1.0f) {
- end[0] = start[0] + u2 * ldx;
- end[1] = start[1] + u2 * ldy;
- end[2] = start[2] + u2 * ldz;
- }
-
- if (u1 > 0.0f) {
- start[0] += u1 * ldx;
- start[1] += u1 * ldy;
- start[2] += u1 * ldz;
- }
- }
- }
- }
- }
- }
- }
-
- if (c1 == 0) return 0;
-
- /* reset static variables in ocread */
- //ocread(oc, oc->ocres, 0, 0);
-
- /* setup 3dda to traverse octree */
- ox1 = (start[0] - oc->min[0]) * oc->ocfacx;
- oy1 = (start[1] - oc->min[1]) * oc->ocfacy;
- oz1 = (start[2] - oc->min[2]) * oc->ocfacz;
- ox2 = (end[0] - oc->min[0]) * oc->ocfacx;
- oy2 = (end[1] - oc->min[1]) * oc->ocfacy;
- oz2 = (end[2] - oc->min[2]) * oc->ocfacz;
-
- ocx1 = (int)ox1;
- ocy1 = (int)oy1;
- ocz1 = (int)oz1;
- ocx2 = (int)ox2;
- ocy2 = (int)oy2;
- ocz2 = (int)oz2;
-
- if (ocx1 == ocx2 && ocy1 == ocy2 && ocz1 == ocz2) {
- no = ocread(oc, ocx1, ocy1, ocz1);
- if (no) {
- /* exact intersection with node */
- vec1[0] = ox1; vec1[1] = oy1; vec1[2] = oz1;
- vec2[0] = ox2; vec2[1] = oy2; vec2[2] = oz2;
- calc_ocval_ray(&ocval, (float)ocx1, (float)ocy1, (float)ocz1, vec1, vec2);
- if (testnode(oc, is, no, ocval) ) return 1;
- }
- }
- else {
- int found = 0;
- //static int coh_ocx1, coh_ocx2, coh_ocy1, coh_ocy2, coh_ocz1, coh_ocz2;
- float dox, doy, doz;
- int eqval;
-
- /* calc lambda en ld */
- dox = ox1 - ox2;
- doy = oy1 - oy2;
- doz = oz1 - oz2;
-
- if (dox < -FLT_EPSILON) {
- ldx = -1.0f / dox;
- lambda_x = (ocx1 - ox1 + 1.0f) * ldx;
- dx = 1;
- }
- else if (dox > FLT_EPSILON) {
- ldx = 1.0f / dox;
- lambda_x = (ox1 - ocx1) * ldx;
- dx = -1;
- }
- else {
- lambda_x = 1.0f;
- ldx = 0;
- dx = 0;
- }
-
- if (doy < -FLT_EPSILON) {
- ldy = -1.0f / doy;
- lambda_y = (ocy1 - oy1 + 1.0f) * ldy;
- dy = 1;
- }
- else if (doy > FLT_EPSILON) {
- ldy = 1.0f / doy;
- lambda_y = (oy1 - ocy1) * ldy;
- dy = -1;
- }
- else {
- lambda_y = 1.0f;
- ldy = 0;
- dy = 0;
- }
-
- if (doz < -FLT_EPSILON) {
- ldz = -1.0f / doz;
- lambda_z = (ocz1 - oz1 + 1.0f) * ldz;
- dz = 1;
- }
- else if (doz > FLT_EPSILON) {
- ldz = 1.0f / doz;
- lambda_z = (oz1 - ocz1) * ldz;
- dz = -1;
- }
- else {
- lambda_z = 1.0f;
- ldz = 0;
- dz = 0;
- }
-
- xo = ocx1; yo = ocy1; zo = ocz1;
- dda_lambda = min_fff(lambda_x, lambda_y, lambda_z);
-
- vec2[0] = ox1;
- vec2[1] = oy1;
- vec2[2] = oz1;
-
- /* this loop has been constructed to make sure the first and last node of ray
- * are always included, even when dda_lambda==1.0f or larger */
-
- while (true) {
-
- no = ocread(oc, xo, yo, zo);
- if (no) {
-
- /* calculate ray intersection with octree node */
- copy_v3_v3(vec1, vec2);
- // dox, y, z is negative
- vec2[0] = ox1 - dda_lambda * dox;
- vec2[1] = oy1 - dda_lambda * doy;
- vec2[2] = oz1 - dda_lambda * doz;
- calc_ocval_ray(&ocval, (float)xo, (float)yo, (float)zo, vec1, vec2);
-
- //is->dist = (u1 + dda_lambda * (u2 - u1)) * o_lambda;
- if (testnode(oc, is, no, ocval) )
- found = 1;
-
- if (is->dist < (u1 + dda_lambda * (u2 - u1)) * o_lambda)
- return found;
- }
-
-
- lambda_o = dda_lambda;
-
- /* traversing octree nodes need careful detection of smallest values, with proper
- * exceptions for equal lambdas */
- eqval = (lambda_x == lambda_y);
- if (lambda_y == lambda_z) eqval += 2;
- if (lambda_x == lambda_z) eqval += 4;
-
- if (eqval) { // only 4 cases exist!
- if (eqval == 7) { // x=y=z
- xo += dx; lambda_x += ldx;
- yo += dy; lambda_y += ldy;
- zo += dz; lambda_z += ldz;
- }
- else if (eqval == 1) { // x=y
- if (lambda_y < lambda_z) {
- xo += dx; lambda_x += ldx;
- yo += dy; lambda_y += ldy;
- }
- else {
- zo += dz; lambda_z += ldz;
- }
- }
- else if (eqval == 2) { // y=z
- if (lambda_x < lambda_y) {
- xo += dx; lambda_x += ldx;
- }
- else {
- yo += dy; lambda_y += ldy;
- zo += dz; lambda_z += ldz;
- }
- }
- else { // x=z
- if (lambda_y < lambda_x) {
- yo += dy; lambda_y += ldy;
- }
- else {
- xo += dx; lambda_x += ldx;
- zo += dz; lambda_z += ldz;
- }
- }
- }
- else { // all three different, just three cases exist
- eqval = (lambda_x < lambda_y);
- if (lambda_y < lambda_z) eqval += 2;
- if (lambda_x < lambda_z) eqval += 4;
-
- if (eqval == 7 || eqval == 5) { // x smallest
- xo += dx; lambda_x += ldx;
- }
- else if (eqval == 2 || eqval == 6) { // y smallest
- yo += dy; lambda_y += ldy;
- }
- else { // z smallest
- zo += dz; lambda_z += ldz;
- }
-
- }
-
- dda_lambda = min_fff(lambda_x, lambda_y, lambda_z);
- if (dda_lambda == lambda_o) break;
- /* to make sure the last node is always checked */
- if (lambda_o >= 1.0f) break;
- }
- }
-
- /* reached end, no intersections found */
- return 0;
-}
-
-
-
diff --git a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp b/source/blender/render/intern/raytrace/rayobject_qbvh.cpp
deleted file mode 100644
index 5b90ae77732..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_qbvh.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_qbvh.cpp
- * \ingroup render
- */
-
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-
-#include "vbvh.h"
-#include "svbvh.h"
-#include "reorganize.h"
-
-#ifdef __SSE__
-
-#define DFS_STACK_SIZE 256
-
-struct QBVHTree {
- RayObject rayobj;
-
- SVBVHNode *root;
- MemArena *node_arena;
-
- float cost;
- RTBuilder *builder;
-};
-
-
-template<>
-void bvh_done<QBVHTree>(QBVHTree *obj)
-{
- rtbuild_done(obj->builder, &obj->rayobj.control);
-
- //TODO find a away to exactly calculate the needed memory
- MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "qbvh arena");
- BLI_memarena_use_malloc(arena1);
-
- MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "qbvh arena 2");
- BLI_memarena_use_malloc(arena2);
- BLI_memarena_use_align(arena2, 16);
-
- //Build and optimize the tree
- //TODO do this in 1 pass (half memory usage during building)
- VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1, &obj->rayobj.control).transform(obj->builder);
-
- if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) {
- BLI_memarena_free(arena1);
- BLI_memarena_free(arena2);
- return;
- }
-
- if (root) {
- pushup_simd<VBVHNode, 4>(root);
- obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
- }
- else
- obj->root = NULL;
-
- //Free data
- BLI_memarena_free(arena1);
-
- obj->node_arena = arena2;
- obj->cost = 1.0;
-
- rtbuild_free(obj->builder);
- obj->builder = NULL;
-}
-
-template<int StackSize>
-static int intersect(QBVHTree *obj, Isect *isec)
-{
- //TODO renable hint support
- if (RE_rayobject_isAligned(obj->root)) {
- if (isec->mode == RE_RAY_SHADOW)
- return svbvh_node_stack_raycast<StackSize, true>(obj->root, isec);
- else
- return svbvh_node_stack_raycast<StackSize, false>(obj->root, isec);
- }
- else
- return RE_rayobject_intersect((RayObject *)obj->root, isec);
-}
-
-template<class Tree>
-static void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(max))
-{
- //TODO renable hint support
- {
- hint->size = 0;
- hint->stack[hint->size++] = (RayObject *)tree->root;
- }
-}
-/* the cast to pointer function is needed to workarround gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11407 */
-template<class Tree, int STACK_SIZE>
-static RayObjectAPI make_api()
-{
- static RayObjectAPI api =
- {
- (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect<STACK_SIZE>),
- (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add<Tree>),
- (RE_rayobject_done_callback) ((void (*)(Tree *)) & bvh_done<Tree>),
- (RE_rayobject_free_callback) ((void (*)(Tree *)) & bvh_free<Tree>),
- (RE_rayobject_merge_bb_callback)((void (*)(Tree *, float *, float *)) & bvh_bb<Tree>),
- (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost<Tree>),
- (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb<Tree>)
- };
-
- return api;
-}
-
-template<class Tree>
-RayObjectAPI *bvh_get_api(int maxstacksize)
-{
- static RayObjectAPI bvh_api256 = make_api<Tree, 1024>();
-
- if (maxstacksize <= 1024) return &bvh_api256;
- assert(maxstacksize <= 256);
- return NULL;
-}
-
-RayObject *RE_rayobject_qbvh_create(int size)
-{
- return bvh_create_tree<QBVHTree, DFS_STACK_SIZE>(size);
-}
-
-#else
-
-RayObject *RE_rayobject_qbvh_create(int UNUSED(size))
-{
- puts("WARNING: SSE disabled at compile time\n");
- return NULL;
-}
-
-#endif
diff --git a/source/blender/render/intern/raytrace/rayobject_raycounter.cpp b/source/blender/render/intern/raytrace/rayobject_raycounter.cpp
deleted file mode 100644
index 5335bf50cbc..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_raycounter.cpp
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_raycounter.cpp
- * \ingroup render
- */
-
-
-#include "rayobject.h"
-#include "raycounter.h"
-
-#ifdef RE_RAYCOUNTER
-
-void RE_RC_INFO(RayCounter *info)
-{
- printf("----------- Raycast counter --------\n");
- printf("Rays total: %llu\n", info->raycast.test );
- printf("Rays hit: %llu\n", info->raycast.hit );
- printf("\n");
- printf("BB tests: %llu\n", info->bb.test );
- printf("BB hits: %llu\n", info->bb.hit );
- printf("\n");
- printf("SIMD BB tests: %llu\n", info->simd_bb.test );
- printf("SIMD BB hits: %llu\n", info->simd_bb.hit );
- printf("\n");
- printf("Primitives tests: %llu\n", info->faces.test );
- printf("Primitives hits: %llu\n", info->faces.hit );
- printf("------------------------------------\n");
- printf("Shadow last-hit tests per ray: %f\n", info->rayshadow_last_hit.test / ((float)info->raycast.test) );
- printf("Shadow last-hit hits per ray: %f\n", info->rayshadow_last_hit.hit / ((float)info->raycast.test) );
- printf("\n");
- printf("Hint tests per ray: %f\n", info->raytrace_hint.test / ((float)info->raycast.test) );
- printf("Hint hits per ray: %f\n", info->raytrace_hint.hit / ((float)info->raycast.test) );
- printf("\n");
- printf("BB tests per ray: %f\n", info->bb.test / ((float)info->raycast.test) );
- printf("BB hits per ray: %f\n", info->bb.hit / ((float)info->raycast.test) );
- printf("\n");
- printf("SIMD tests per ray: %f\n", info->simd_bb.test / ((float)info->raycast.test) );
- printf("SIMD hits per ray: %f\n", info->simd_bb.hit / ((float)info->raycast.test) );
- printf("\n");
- printf("Primitives tests per ray: %f\n", info->faces.test / ((float)info->raycast.test) );
- printf("Primitives hits per ray: %f\n", info->faces.hit / ((float)info->raycast.test) );
- printf("------------------------------------\n");
-}
-
-void RE_RC_MERGE(RayCounter *dest, RayCounter *tmp)
-{
- dest->faces.test += tmp->faces.test;
- dest->faces.hit += tmp->faces.hit;
-
- dest->bb.test += tmp->bb.test;
- dest->bb.hit += tmp->bb.hit;
-
- dest->simd_bb.test += tmp->simd_bb.test;
- dest->simd_bb.hit += tmp->simd_bb.hit;
-
- dest->raycast.test += tmp->raycast.test;
- dest->raycast.hit += tmp->raycast.hit;
-
- dest->rayshadow_last_hit.test += tmp->rayshadow_last_hit.test;
- dest->rayshadow_last_hit.hit += tmp->rayshadow_last_hit.hit;
-
- dest->raytrace_hint.test += tmp->raytrace_hint.test;
- dest->raytrace_hint.hit += tmp->raytrace_hint.hit;
-}
-
-#endif
diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp b/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp
deleted file mode 100644
index 103fa3e6034..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_rtbuild.cpp
+++ /dev/null
@@ -1,531 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_rtbuild.cpp
- * \ingroup render
- */
-
-
-#include <assert.h>
-#include <stdlib.h>
-#include <algorithm>
-
-#if __cplusplus >= 201103L
-#include <cmath>
-using std::isfinite;
-#else
-#include <math.h>
-#endif
-
-#include "rayobject_rtbuild.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-static bool selected_node(RTBuilder::Object *node)
-{
- return node->selected;
-}
-
-static void rtbuild_init(RTBuilder *b)
-{
- b->split_axis = -1;
- b->primitives.begin = NULL;
- b->primitives.end = NULL;
- b->primitives.maxsize = 0;
- b->depth = 0;
-
- for (int i = 0; i < RTBUILD_MAX_CHILDS; i++)
- b->child_offset[i] = 0;
-
- for (int i = 0; i < 3; i++)
- b->sorted_begin[i] = b->sorted_end[i] = NULL;
-
- INIT_MINMAX(b->bb, b->bb + 3);
-}
-
-RTBuilder *rtbuild_create(int size)
-{
- RTBuilder *builder = (RTBuilder *) MEM_mallocN(sizeof(RTBuilder), "RTBuilder");
- RTBuilder::Object *memblock = (RTBuilder::Object *)MEM_mallocN(sizeof(RTBuilder::Object) * size, "RTBuilder.objects");
-
-
- rtbuild_init(builder);
-
- builder->primitives.begin = builder->primitives.end = memblock;
- builder->primitives.maxsize = size;
-
- for (int i = 0; i < 3; i++) {
- builder->sorted_begin[i] = (RTBuilder::Object **)MEM_mallocN(sizeof(RTBuilder::Object *) * size, "RTBuilder.sorted_objects");
- builder->sorted_end[i] = builder->sorted_begin[i];
- }
-
-
- return builder;
-}
-
-void rtbuild_free(RTBuilder *b)
-{
- if (b->primitives.begin) MEM_freeN(b->primitives.begin);
-
- for (int i = 0; i < 3; i++)
- if (b->sorted_begin[i])
- MEM_freeN(b->sorted_begin[i]);
-
- MEM_freeN(b);
-}
-
-void rtbuild_add(RTBuilder *b, RayObject *o)
-{
- float bb[6];
-
- assert(b->primitives.begin + b->primitives.maxsize != b->primitives.end);
-
- INIT_MINMAX(bb, bb + 3);
- RE_rayobject_merge_bb(o, bb, bb + 3);
-
- /* skip objects with invalid bounding boxes, nan causes DO_MINMAX
- * to do nothing, so we get these invalid values. this shouldn't
- * happen usually, but bugs earlier in the pipeline can cause it. */
- if (bb[0] > bb[3] || bb[1] > bb[4] || bb[2] > bb[5])
- return;
- /* skip objects with inf bounding boxes */
- if (!isfinite(bb[0]) || !isfinite(bb[1]) || !isfinite(bb[2]))
- return;
- if (!isfinite(bb[3]) || !isfinite(bb[4]) || !isfinite(bb[5]))
- return;
- /* skip objects with zero bounding box, they are of no use, and
- * will give problems in rtbuild_heuristic_object_split later */
- if (bb[0] == bb[3] && bb[1] == bb[4] && bb[2] == bb[5])
- return;
-
- copy_v3_v3(b->primitives.end->bb, bb);
- copy_v3_v3(b->primitives.end->bb + 3, bb + 3);
- b->primitives.end->obj = o;
- b->primitives.end->cost = RE_rayobject_cost(o);
-
- for (int i = 0; i < 3; i++) {
- *(b->sorted_end[i]) = b->primitives.end;
- b->sorted_end[i]++;
- }
- b->primitives.end++;
-}
-
-int rtbuild_size(RTBuilder *b)
-{
- return b->sorted_end[0] - b->sorted_begin[0];
-}
-
-
-template<class Obj, int Axis>
-static bool obj_bb_compare(const Obj &a, const Obj &b)
-{
- if (a->bb[Axis] != b->bb[Axis])
- return a->bb[Axis] < b->bb[Axis];
- return a->obj < b->obj;
-}
-
-template<class Item>
-static void object_sort(Item *begin, Item *end, int axis)
-{
- if (axis == 0) return std::sort(begin, end, obj_bb_compare<Item, 0> );
- if (axis == 1) return std::sort(begin, end, obj_bb_compare<Item, 1> );
- if (axis == 2) return std::sort(begin, end, obj_bb_compare<Item, 2> );
- assert(false);
-}
-
-void rtbuild_done(RTBuilder *b, RayObjectControl *ctrl)
-{
- for (int i = 0; i < 3; i++) {
- if (b->sorted_begin[i]) {
- if (RE_rayobjectcontrol_test_break(ctrl)) break;
- object_sort(b->sorted_begin[i], b->sorted_end[i], i);
- }
- }
-}
-
-RayObject *rtbuild_get_primitive(RTBuilder *b, int index)
-{
- return b->sorted_begin[0][index]->obj;
-}
-
-RTBuilder *rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp)
-{
- rtbuild_init(tmp);
-
- tmp->depth = b->depth + 1;
-
- for (int i = 0; i < 3; i++)
- if (b->sorted_begin[i]) {
- tmp->sorted_begin[i] = b->sorted_begin[i] + b->child_offset[child];
- tmp->sorted_end[i] = b->sorted_begin[i] + b->child_offset[child + 1];
- }
- else {
- tmp->sorted_begin[i] = NULL;
- tmp->sorted_end[i] = NULL;
- }
-
- return tmp;
-}
-
-static void rtbuild_calc_bb(RTBuilder *b)
-{
- if (b->bb[0] == 1.0e30f) {
- for (RTBuilder::Object **index = b->sorted_begin[0]; index != b->sorted_end[0]; index++)
- RE_rayobject_merge_bb( (*index)->obj, b->bb, b->bb + 3);
- }
-}
-
-void rtbuild_merge_bb(RTBuilder *b, float min[3], float max[3])
-{
- rtbuild_calc_bb(b);
- DO_MIN(b->bb, min);
- DO_MAX(b->bb + 3, max);
-}
-
-#if 0
-int rtbuild_get_largest_axis(RTBuilder *b)
-{
- rtbuild_calc_bb(b);
- return bb_largest_axis(b->bb, b->bb + 3);
-}
-
-//Left balanced tree
-int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis)
-{
- int i;
- int mleafs_per_child, Mleafs_per_child;
- int tot_leafs = rtbuild_size(b);
- int missing_leafs;
-
- long long s;
-
- assert(nchilds <= RTBUILD_MAX_CHILDS);
-
- //TODO optimize calc of leafs_per_child
- for (s = nchilds; s < tot_leafs; s *= nchilds) ;
- Mleafs_per_child = s / nchilds;
- mleafs_per_child = Mleafs_per_child / nchilds;
-
- //split min leafs per child
- b->child_offset[0] = 0;
- for (i = 1; i <= nchilds; i++)
- b->child_offset[i] = mleafs_per_child;
-
- //split remaining leafs
- missing_leafs = tot_leafs - mleafs_per_child * nchilds;
- for (i = 1; i <= nchilds; i++)
- {
- if (missing_leafs > Mleafs_per_child - mleafs_per_child)
- {
- b->child_offset[i] += Mleafs_per_child - mleafs_per_child;
- missing_leafs -= Mleafs_per_child - mleafs_per_child;
- }
- else {
- b->child_offset[i] += missing_leafs;
- missing_leafs = 0;
- break;
- }
- }
-
- //adjust for accumulative offsets
- for (i = 1; i <= nchilds; i++)
- b->child_offset[i] += b->child_offset[i - 1];
-
- //Count created childs
- for (i = nchilds; b->child_offset[i] == b->child_offset[i - 1]; i--) ;
- split_leafs(b, b->child_offset, i, axis);
-
- assert(b->child_offset[0] == 0 && b->child_offset[i] == tot_leafs);
- return i;
-}
-
-
-int rtbuild_mean_split_largest_axis(RTBuilder *b, int nchilds)
-{
- int axis = rtbuild_get_largest_axis(b);
- return rtbuild_mean_split(b, nchilds, axis);
-}
-#endif
-
-/*
- * "separators" is an array of dim NCHILDS-1
- * and indicates where to cut the childs
- */
-#if 0
-int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis)
-{
- int size = rtbuild_size(b);
-
- assert(nchilds <= RTBUILD_MAX_CHILDS);
- if (size <= nchilds)
- {
- return rtbuild_mean_split(b, nchilds, axis);
- }
- else {
- int i;
-
- b->split_axis = axis;
-
- //Calculate child offsets
- b->child_offset[0] = 0;
- for (i = 0; i < nchilds - 1; i++)
- b->child_offset[i + 1] = split_leafs_by_plane(b, b->child_offset[i], size, separators[i]);
- b->child_offset[nchilds] = size;
-
- for (i = 0; i < nchilds; i++)
- if (b->child_offset[i + 1] - b->child_offset[i] == size)
- return rtbuild_mean_split(b, nchilds, axis);
-
- return nchilds;
- }
-}
-
-int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds)
-{
- int la, i;
- float separators[RTBUILD_MAX_CHILDS];
-
- rtbuild_calc_bb(b);
-
- la = bb_largest_axis(b->bb, b->bb + 3);
- for (i = 1; i < nchilds; i++)
- separators[i - 1] = (b->bb[la + 3] - b->bb[la]) * i / nchilds;
-
- return rtbuild_median_split(b, separators, nchilds, la);
-}
-#endif
-
-//Heuristics Object Splitter
-
-
-struct SweepCost {
- float bb[6];
- float cost;
-};
-
-/* Object Surface Area Heuristic splitter */
-int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds)
-{
- int size = rtbuild_size(b);
- assert(nchilds == 2);
- assert(size > 1);
- int baxis = -1, boffset = 0;
-
- if (size > nchilds) {
- if (b->depth > RTBUILD_MAX_SAH_DEPTH) {
- // for degenerate cases we avoid running out of stack space
- // by simply splitting the children in the middle
- b->child_offset[0] = 0;
- b->child_offset[1] = (size+1)/2;
- b->child_offset[2] = size;
- return 2;
- }
-
- float bcost = FLT_MAX;
- baxis = -1;
- boffset = size / 2;
-
- SweepCost *sweep = (SweepCost *)MEM_mallocN(sizeof(SweepCost) * size, "RTBuilder.HeuristicSweep");
-
- for (int axis = 0; axis < 3; axis++) {
- SweepCost sweep_left;
-
- RTBuilder::Object **obj = b->sorted_begin[axis];
-
-// float right_cost = 0;
- for (int i = size - 1; i >= 0; i--) {
- if (i == size - 1) {
- copy_v3_v3(sweep[i].bb, obj[i]->bb);
- copy_v3_v3(sweep[i].bb + 3, obj[i]->bb + 3);
- sweep[i].cost = obj[i]->cost;
- }
- else {
- sweep[i].bb[0] = min_ff(obj[i]->bb[0], sweep[i + 1].bb[0]);
- sweep[i].bb[1] = min_ff(obj[i]->bb[1], sweep[i + 1].bb[1]);
- sweep[i].bb[2] = min_ff(obj[i]->bb[2], sweep[i + 1].bb[2]);
- sweep[i].bb[3] = max_ff(obj[i]->bb[3], sweep[i + 1].bb[3]);
- sweep[i].bb[4] = max_ff(obj[i]->bb[4], sweep[i + 1].bb[4]);
- sweep[i].bb[5] = max_ff(obj[i]->bb[5], sweep[i + 1].bb[5]);
- sweep[i].cost = obj[i]->cost + sweep[i + 1].cost;
- }
-// right_cost += obj[i]->cost;
- }
-
- sweep_left.bb[0] = obj[0]->bb[0];
- sweep_left.bb[1] = obj[0]->bb[1];
- sweep_left.bb[2] = obj[0]->bb[2];
- sweep_left.bb[3] = obj[0]->bb[3];
- sweep_left.bb[4] = obj[0]->bb[4];
- sweep_left.bb[5] = obj[0]->bb[5];
- sweep_left.cost = obj[0]->cost;
-
-// right_cost -= obj[0]->cost; if (right_cost < 0) right_cost = 0;
-
- for (int i = 1; i < size; i++) {
- //Worst case heuristic (cost of each child is linear)
- float hcost, left_side, right_side;
-
- // not using log seems to have no impact on raytracing perf, but
- // makes tree construction quicker, left out for now to test (brecht)
- // left_side = bb_area(sweep_left.bb, sweep_left.bb + 3) * (sweep_left.cost + logf((float)i));
- // right_side = bb_area(sweep[i].bb, sweep[i].bb + 3) * (sweep[i].cost + logf((float)size - i));
- left_side = bb_area(sweep_left.bb, sweep_left.bb + 3) * (sweep_left.cost);
- right_side = bb_area(sweep[i].bb, sweep[i].bb + 3) * (sweep[i].cost);
- hcost = left_side + right_side;
-
- assert(left_side >= 0);
- assert(right_side >= 0);
-
- if (left_side > bcost) break; //No way we can find a better heuristic in this axis
-
- assert(hcost >= 0);
- // this makes sure the tree built is the same whatever is the order of the sorting axis
- if (hcost < bcost || (hcost == bcost && axis < baxis)) {
- bcost = hcost;
- baxis = axis;
- boffset = i;
- }
- DO_MIN(obj[i]->bb, sweep_left.bb);
- DO_MAX(obj[i]->bb + 3, sweep_left.bb + 3);
-
- sweep_left.cost += obj[i]->cost;
-// right_cost -= obj[i]->cost; if (right_cost < 0) right_cost = 0;
- }
-
- //assert(baxis >= 0 && baxis < 3);
- if (!(baxis >= 0 && baxis < 3))
- baxis = 0;
- }
-
-
- MEM_freeN(sweep);
- }
- else if (size == 2) {
- baxis = 0;
- boffset = 1;
- }
- else if (size == 1) {
- b->child_offset[0] = 0;
- b->child_offset[1] = 1;
- return 1;
- }
-
- b->child_offset[0] = 0;
- b->child_offset[1] = boffset;
- b->child_offset[2] = size;
-
-
- /* Adjust sorted arrays for childs */
- for (int i = 0; i < boffset; i++) b->sorted_begin[baxis][i]->selected = true;
- for (int i = boffset; i < size; i++) b->sorted_begin[baxis][i]->selected = false;
- for (int i = 0; i < 3; i++)
- std::stable_partition(b->sorted_begin[i], b->sorted_end[i], selected_node);
-
- return nchilds;
-}
-
-/*
- * Helper code
- * PARTITION code / used on mean-split
- * basically this a std::nth_element (like on C++ STL algorithm)
- */
-#if 0
-static void split_leafs(RTBuilder *b, int *nth, int partitions, int split_axis)
-{
- int i;
- b->split_axis = split_axis;
-
- for (i = 0; i < partitions - 1; i++)
- {
- assert(nth[i] < nth[i + 1] && nth[i + 1] < nth[partitions]);
-
- if (split_axis == 0) std::nth_element(b, nth[i], nth[i + 1], nth[partitions], obj_bb_compare<RTBuilder::Object, 0>);
- if (split_axis == 1) std::nth_element(b, nth[i], nth[i + 1], nth[partitions], obj_bb_compare<RTBuilder::Object, 1>);
- if (split_axis == 2) std::nth_element(b, nth[i], nth[i + 1], nth[partitions], obj_bb_compare<RTBuilder::Object, 2>);
- }
-}
-#endif
-
-/*
- * Bounding Box utils
- */
-float bb_volume(const float min[3], const float max[3])
-{
- return (max[0] - min[0]) * (max[1] - min[1]) * (max[2] - min[2]);
-}
-
-float bb_area(const float min[3], const float max[3])
-{
- float sub[3], a;
- sub[0] = max[0] - min[0];
- sub[1] = max[1] - min[1];
- sub[2] = max[2] - min[2];
-
- a = (sub[0] * sub[1] + sub[0] * sub[2] + sub[1] * sub[2]) * 2.0f;
- /* used to have an assert() here on negative results
- * however, in this case its likely some overflow or ffast math error.
- * so just return 0.0f instead. */
- return a < 0.0f ? 0.0f : a;
-}
-
-int bb_largest_axis(const float min[3], const float max[3])
-{
- float sub[3];
-
- sub[0] = max[0] - min[0];
- sub[1] = max[1] - min[1];
- sub[2] = max[2] - min[2];
- if (sub[0] > sub[1]) {
- if (sub[0] > sub[2])
- return 0;
- else
- return 2;
- }
- else {
- if (sub[1] > sub[2])
- return 1;
- else
- return 2;
- }
-}
-
-/* only returns 0 if merging inner and outerbox would create a box larger than outer box */
-int bb_fits_inside(const float outer_min[3], const float outer_max[3],
- const float inner_min[3], const float inner_max[3])
-{
- int i;
- for (i = 0; i < 3; i++)
- if (outer_min[i] > inner_min[i]) return 0;
-
- for (i = 0; i < 3; i++)
- if (outer_max[i] < inner_max[i]) return 0;
-
- return 1;
-}
diff --git a/source/blender/render/intern/raytrace/rayobject_rtbuild.h b/source/blender/render/intern/raytrace/rayobject_rtbuild.h
deleted file mode 100644
index 061d76e3a3e..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_rtbuild.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_rtbuild.h
- * \ingroup render
- */
-
-#ifndef __RAYOBJECT_RTBUILD_H__
-#define __RAYOBJECT_RTBUILD_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include "rayobject.h"
-
-
-/*
- * Ray Tree Builder
- * this structs helps building any type of tree
- * it contains several methods to organize/split nodes
- * allowing to create a given tree on the fly.
- *
- * Idea is that other trees BVH, BIH can use this code to
- * generate with simple calls, and then convert to the theirs
- * specific structure on the fly.
- */
-#define RTBUILD_MAX_CHILDS 32
-#define RTBUILD_MAX_SAH_DEPTH 256
-
-
-typedef struct RTBuilder {
- struct Object {
- RayObject *obj;
- float cost;
- float bb[6];
- int selected;
- };
-
- /* list to all primitives added in this tree */
- struct {
- Object *begin, *end;
- int maxsize;
- } primitives;
-
- /* sorted list of rayobjects */
- struct Object **sorted_begin[3], **sorted_end[3];
-
- /* axis used (if any) on the split method */
- int split_axis;
-
- /* child partitions calculated during splitting */
- int child_offset[RTBUILD_MAX_CHILDS + 1];
-
-// int child_sorted_axis; /* -1 if not sorted */
-
- float bb[6];
-
- /* current depth */
- int depth;
-} RTBuilder;
-
-/* used during creation */
-RTBuilder *rtbuild_create(int size);
-void rtbuild_free(RTBuilder *b);
-void rtbuild_add(RTBuilder *b, RayObject *o);
-void rtbuild_done(RTBuilder *b, RayObjectControl *c);
-void rtbuild_merge_bb(RTBuilder *b, float min[3], float max[3]);
-int rtbuild_size(RTBuilder *b);
-
-RayObject *rtbuild_get_primitive(RTBuilder *b, int offset);
-
-/* used during tree reorganization */
-RTBuilder *rtbuild_get_child(RTBuilder *b, int child, RTBuilder *tmp);
-
-/* Calculates child partitions and returns number of efectively needed partitions */
-int rtbuild_get_largest_axis(RTBuilder *b);
-
-//Object partition
-int rtbuild_mean_split(RTBuilder *b, int nchilds, int axis);
-int rtbuild_mean_split_largest_axis(RTBuilder *b, int nchilds);
-
-int rtbuild_heuristic_object_split(RTBuilder *b, int nchilds);
-
-//Space partition
-int rtbuild_median_split(RTBuilder *b, float *separators, int nchilds, int axis);
-int rtbuild_median_split_largest_axis(RTBuilder *b, int nchilds);
-
-
-/* bb utils */
-float bb_area(const float min[3], const float max[3]);
-float bb_volume(const float min[3], const float max[3]);
-int bb_largest_axis(const float min[3], const float max[3]);
-int bb_fits_inside(const float outer_min[3], const float outer_max[3],
- const float inner_min[3], const float inner_max[3]);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __RAYOBJECT_RTBUILD_H__ */
diff --git a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp b/source/blender/render/intern/raytrace/rayobject_svbvh.cpp
deleted file mode 100644
index eb7dddac06e..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_svbvh.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_svbvh.cpp
- * \ingroup render
- */
-
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_utildefines.h"
-
-#include "vbvh.h"
-#include "svbvh.h"
-#include "reorganize.h"
-
-#ifdef __SSE__
-
-#define DFS_STACK_SIZE 256
-
-struct SVBVHTree {
- RayObject rayobj;
-
- SVBVHNode *root;
- MemArena *node_arena;
-
- float cost;
- RTBuilder *builder;
-};
-
-/*
- * Cost to test N childs
- */
-struct PackCost {
- float operator()(int n)
- {
- return (n / 4) + ((n % 4) > 2 ? 1 : n % 4);
- }
-};
-
-
-template<>
-void bvh_done<SVBVHTree>(SVBVHTree *obj)
-{
- rtbuild_done(obj->builder, &obj->rayobj.control);
-
- //TODO find a away to exactly calculate the needed memory
- MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "svbvh arena");
- BLI_memarena_use_malloc(arena1);
-
- MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "svbvh arena2");
- BLI_memarena_use_malloc(arena2);
- BLI_memarena_use_align(arena2, 16);
-
- //Build and optimize the tree
- if (0) {
- VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1, &obj->rayobj.control).transform(obj->builder);
-
- if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) {
- BLI_memarena_free(arena1);
- BLI_memarena_free(arena2);
- return;
- }
-
- reorganize(root);
- remove_useless(root, &root);
- bvh_refit(root);
-
- pushup(root);
- pushdown(root);
- pushup_simd<VBVHNode, 4>(root);
-
- obj->root = Reorganize_SVBVH<VBVHNode>(arena2).transform(root);
- }
- else {
- //Finds the optimal packing of this tree using a given cost model
- //TODO this uses quite a lot of memory, find ways to reduce memory usage during building
- OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena1, &obj->rayobj.control).transform(obj->builder);
-
- if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) {
- BLI_memarena_free(arena1);
- BLI_memarena_free(arena2);
- return;
- }
-
- if (root) {
- VBVH_optimalPackSIMD<OVBVHNode, PackCost>(PackCost()).transform(root);
- obj->root = Reorganize_SVBVH<OVBVHNode>(arena2).transform(root);
- }
- else
- obj->root = NULL;
- }
-
- //Free data
- BLI_memarena_free(arena1);
-
- obj->node_arena = arena2;
- obj->cost = 1.0;
-
- rtbuild_free(obj->builder);
- obj->builder = NULL;
-}
-
-template<int StackSize>
-static int intersect(SVBVHTree *obj, Isect *isec)
-{
- //TODO renable hint support
- if (RE_rayobject_isAligned(obj->root)) {
- if (isec->mode == RE_RAY_SHADOW)
- return svbvh_node_stack_raycast<StackSize, true>(obj->root, isec);
- else
- return svbvh_node_stack_raycast<StackSize, false>(obj->root, isec);
- }
- else
- return RE_rayobject_intersect( (RayObject *) obj->root, isec);
-}
-
-template<class Tree>
-static void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(max))
-{
- //TODO renable hint support
- {
- hint->size = 0;
- hint->stack[hint->size++] = (RayObject *)tree->root;
- }
-}
-/* the cast to pointer function is needed to workarround gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11407 */
-template<class Tree, int STACK_SIZE>
-static RayObjectAPI make_api()
-{
- static RayObjectAPI api =
- {
- (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect<STACK_SIZE>),
- (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add<Tree>),
- (RE_rayobject_done_callback) ((void (*)(Tree *)) & bvh_done<Tree>),
- (RE_rayobject_free_callback) ((void (*)(Tree *)) & bvh_free<Tree>),
- (RE_rayobject_merge_bb_callback)((void (*)(Tree *, float *, float *)) & bvh_bb<Tree>),
- (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost<Tree>),
- (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb<Tree>)
- };
-
- return api;
-}
-
-template<class Tree>
-static RayObjectAPI *bvh_get_api(int maxstacksize)
-{
- static RayObjectAPI bvh_api256 = make_api<Tree, 1024>();
-
- if (maxstacksize <= 1024) return &bvh_api256;
- assert(maxstacksize <= 256);
- return NULL;
-}
-
-RayObject *RE_rayobject_svbvh_create(int size)
-{
- return bvh_create_tree<SVBVHTree, DFS_STACK_SIZE>(size);
-}
-
-#else
-
-RayObject *RE_rayobject_svbvh_create(int UNUSED(size))
-{
- puts("WARNING: SSE disabled at compile time\n");
- return NULL;
-}
-
-#endif
diff --git a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp b/source/blender/render/intern/raytrace/rayobject_vbvh.cpp
deleted file mode 100644
index dfa5a69b335..00000000000
--- a/source/blender/render/intern/raytrace/rayobject_vbvh.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/rayobject_vbvh.cpp
- * \ingroup render
- */
-
-
-int tot_pushup = 0;
-int tot_pushdown = 0;
-int tot_hints = 0;
-
-#include <assert.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_memarena.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_global.h"
-
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "rayobject_rtbuild.h"
-
-#include "reorganize.h"
-#include "bvh.h"
-#include "vbvh.h"
-
-#include <queue>
-#include <algorithm>
-
-#define DFS_STACK_SIZE 256
-
-struct VBVHTree {
- RayObject rayobj;
- VBVHNode *root;
- MemArena *node_arena;
- float cost;
- RTBuilder *builder;
-};
-
-/*
- * Cost to test N childs
- */
-struct PackCost {
- float operator()(int n)
- {
- return n;
- }
-};
-
-template<>
-void bvh_done<VBVHTree>(VBVHTree *obj)
-{
- rtbuild_done(obj->builder, &obj->rayobj.control);
-
- //TODO find a away to exactly calculate the needed memory
- MemArena *arena1 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena");
- BLI_memarena_use_malloc(arena1);
-
- //Build and optimize the tree
- if (1) {
- VBVHNode *root = BuildBinaryVBVH<VBVHNode>(arena1, &obj->rayobj.control).transform(obj->builder);
- if (RE_rayobjectcontrol_test_break(&obj->rayobj.control)) {
- BLI_memarena_free(arena1);
- return;
- }
-
- if (root) {
- reorganize(root);
- remove_useless(root, &root);
- bvh_refit(root);
-
- pushup(root);
- pushdown(root);
- obj->root = root;
- }
- else
- obj->root = NULL;
- }
- else {
- /* TODO */
-#if 0
- MemArena *arena2 = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vbvh arena2");
- BLI_memarena_use_malloc(arena2);
-
- //Finds the optimal packing of this tree using a given cost model
- //TODO this uses quite a lot of memory, find ways to reduce memory usage during building
- OVBVHNode *root = BuildBinaryVBVH<OVBVHNode>(arena2).transform(obj->builder);
- VBVH_optimalPackSIMD<OVBVHNode, PackCost>(PackCost()).transform(root);
- obj->root = Reorganize_VBVH<OVBVHNode>(arena1).transform(root);
-
- BLI_memarena_free(arena2);
-#endif
- }
-
- //Cleanup
- rtbuild_free(obj->builder);
- obj->builder = NULL;
-
- obj->node_arena = arena1;
- obj->cost = 1.0;
-}
-
-template<int StackSize>
-static int intersect(VBVHTree *obj, Isect *isec)
-{
- //TODO renable hint support
- if (RE_rayobject_isAligned(obj->root)) {
- if (isec->mode == RE_RAY_SHADOW)
- return bvh_node_stack_raycast<VBVHNode, StackSize, false, true>(obj->root, isec);
- else
- return bvh_node_stack_raycast<VBVHNode, StackSize, false, false>(obj->root, isec);
- }
- else
- return RE_rayobject_intersect( (RayObject *) obj->root, isec);
-}
-
-template<class Tree>
-static void bvh_hint_bb(Tree *tree, LCTSHint *hint, float *UNUSED(min), float *UNUSED(max))
-{
- //TODO renable hint support
- {
- hint->size = 0;
- hint->stack[hint->size++] = (RayObject *)tree->root;
- }
-}
-
-#if 0 /* UNUSED */
-static void bfree(VBVHTree *tree)
-{
- if (tot_pushup + tot_pushdown + tot_hints + tot_moves) {
- if (G.debug & G_DEBUG) {
- printf("tot pushups: %d\n", tot_pushup);
- printf("tot pushdowns: %d\n", tot_pushdown);
- printf("tot moves: %d\n", tot_moves);
- printf("tot hints created: %d\n", tot_hints);
- }
-
- tot_pushup = 0;
- tot_pushdown = 0;
- tot_hints = 0;
- tot_moves = 0;
- }
- bvh_free(tree);
-}
-#endif
-
-/* the cast to pointer function is needed to workarround gcc bug: http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11407 */
-template<class Tree, int STACK_SIZE>
-static RayObjectAPI make_api()
-{
- static RayObjectAPI api =
- {
- (RE_rayobject_raycast_callback) ((int (*)(Tree *, Isect *)) & intersect<STACK_SIZE>),
- (RE_rayobject_add_callback) ((void (*)(Tree *, RayObject *)) & bvh_add<Tree>),
- (RE_rayobject_done_callback) ((void (*)(Tree *)) & bvh_done<Tree>),
- (RE_rayobject_free_callback) ((void (*)(Tree *)) & bvh_free<Tree>),
- (RE_rayobject_merge_bb_callback)((void (*)(Tree *, float *, float *)) & bvh_bb<Tree>),
- (RE_rayobject_cost_callback) ((float (*)(Tree *)) & bvh_cost<Tree>),
- (RE_rayobject_hint_bb_callback) ((void (*)(Tree *, LCTSHint *, float *, float *)) & bvh_hint_bb<Tree>)
- };
-
- return api;
-}
-
-template<class Tree>
-RayObjectAPI *bvh_get_api(int maxstacksize)
-{
- static RayObjectAPI bvh_api256 = make_api<Tree, 1024>();
-
- if (maxstacksize <= 1024) return &bvh_api256;
- assert(maxstacksize <= 256);
- return 0;
-}
-
-RayObject *RE_rayobject_vbvh_create(int size)
-{
- return bvh_create_tree<VBVHTree, DFS_STACK_SIZE>(size);
-}
diff --git a/source/blender/render/intern/raytrace/reorganize.h b/source/blender/render/intern/raytrace/reorganize.h
deleted file mode 100644
index 84d04a8851f..00000000000
--- a/source/blender/render/intern/raytrace/reorganize.h
+++ /dev/null
@@ -1,513 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/reorganize.h
- * \ingroup render
- */
-
-
-#include <float.h>
-#include <math.h>
-#include <stdio.h>
-
-#include <algorithm>
-#include <queue>
-#include <vector>
-
-#include "BKE_global.h"
-
-#ifdef _WIN32
-# ifdef INFINITY
-# undef INFINITY
-# endif
-# define INFINITY FLT_MAX // in mingw math.h: (1.0F/0.0F). This generates compile error, though.
-#endif
-
-extern int tot_pushup;
-extern int tot_pushdown;
-
-#if !defined(INFINITY) && defined(HUGE_VAL)
-#define INFINITY HUGE_VAL
-#endif
-
-template<class Node>
-static bool node_fits_inside(Node *a, Node *b)
-{
- return bb_fits_inside(b->bb, b->bb + 3, a->bb, a->bb + 3);
-}
-
-template<class Node>
-static void reorganize_find_fittest_parent(Node *tree, Node *node, std::pair<float, Node *> &cost)
-{
- std::queue<Node *> q;
- q.push(tree);
-
- while (!q.empty()) {
- Node *parent = q.front();
- q.pop();
-
- if (parent == node) continue;
- if (node_fits_inside(node, parent) && RE_rayobject_isAligned(parent->child) ) {
- float pcost = bb_area(parent->bb, parent->bb + 3);
- cost = std::min(cost, std::make_pair(pcost, parent) );
- for (Node *child = parent->child; child; child = child->sibling)
- q.push(child);
- }
- }
-}
-
-template<class Node>
-static void reorganize(Node *root)
-{
- std::queue<Node *> q;
-
- q.push(root);
- while (!q.empty()) {
- Node *node = q.front();
- q.pop();
-
- if (RE_rayobject_isAligned(node->child)) {
- for (Node **prev = &node->child; *prev; ) {
- assert(RE_rayobject_isAligned(*prev));
- q.push(*prev);
-
- std::pair<float, Node *> best(FLT_MAX, root);
- reorganize_find_fittest_parent(root, *prev, best);
-
- if (best.second == node) {
- //Already inside the fitnest BB
- prev = &(*prev)->sibling;
- }
- else {
- Node *tmp = *prev;
- *prev = (*prev)->sibling;
-
- tmp->sibling = best.second->child;
- best.second->child = tmp;
- }
-
-
- }
- }
- if (node != root) {
- }
- }
-}
-
-/*
- * Prunes useless nodes from trees:
- * erases nodes with total amount of primitives = 0
- * prunes nodes with only one child (except if that child is a primitive)
- */
-template<class Node>
-static void remove_useless(Node *node, Node **new_node)
-{
- if (RE_rayobject_isAligned(node->child) ) {
-
- for (Node **prev = &node->child; *prev; ) {
- Node *next = (*prev)->sibling;
- remove_useless(*prev, prev);
- if (*prev == NULL)
- *prev = next;
- else {
- (*prev)->sibling = next;
- prev = &((*prev)->sibling);
- }
- }
- }
- if (node->child) {
- if (RE_rayobject_isAligned(node->child) && node->child->sibling == 0)
- *new_node = node->child;
- }
- else if (node->child == NULL) {
- *new_node = NULL;
- }
-}
-
-/*
- * Minimizes expected number of BBtest by colapsing nodes
- * it uses surface area heuristic for determining whether a node should be colapsed
- */
-template<class Node>
-static void pushup(Node *parent)
-{
- if (is_leaf(parent)) return;
-
- float p_area = bb_area(parent->bb, parent->bb + 3);
- Node **prev = &parent->child;
- for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) {
- const float c_area = bb_area(child->bb, child->bb + 3);
- const int nchilds = count_childs(child);
- float original_cost = ((p_area != 0.0f) ? (c_area / p_area) * nchilds : 1.0f) + 1;
- float flatten_cost = nchilds;
- if (flatten_cost < original_cost && nchilds >= 2) {
- append_sibling(child, child->child);
- child = child->sibling;
- *prev = child;
-
-// *prev = child->child;
-// append_sibling( *prev, child->sibling );
-// child = *prev;
- tot_pushup++;
- }
- else {
- *prev = child;
- prev = &(*prev)->sibling;
- child = *prev;
- }
- }
-
- for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling)
- pushup(child);
-}
-
-/*
- * try to optimize number of childs to be a multiple of SSize
- */
-template<class Node, int SSize>
-static void pushup_simd(Node *parent)
-{
- if (is_leaf(parent)) return;
-
- int n = count_childs(parent);
-
- Node **prev = &parent->child;
- for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; ) {
- int cn = count_childs(child);
- if (cn - 1 <= (SSize - (n % SSize) ) % SSize && RE_rayobject_isAligned(child->child) ) {
- n += (cn - 1);
- append_sibling(child, child->child);
- child = child->sibling;
- *prev = child;
- }
- else {
- *prev = child;
- prev = &(*prev)->sibling;
- child = *prev;
- }
- }
-
- for (Node *child = parent->child; RE_rayobject_isAligned(child) && child; child = child->sibling)
- pushup_simd<Node, SSize>(child);
-}
-
-
-/*
- * Pushdown
- * makes sure no child fits inside any of its sibling
- */
-template<class Node>
-static void pushdown(Node *parent)
-{
- Node **s_child = &parent->child;
- Node *child = parent->child;
-
- while (child && RE_rayobject_isAligned(child)) {
- Node *next = child->sibling;
- Node **next_s_child = &child->sibling;
-
- //assert(bb_fits_inside(parent->bb, parent->bb+3, child->bb, child->bb+3));
-
- for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling)
- if (child != i && bb_fits_inside(i->bb, i->bb + 3, child->bb, child->bb + 3) && RE_rayobject_isAligned(i->child)) {
-// todo optimize (should the one with the smallest area?)
-// float ia = bb_area(i->bb, i->bb+3)
-// if (child->i)
- *s_child = child->sibling;
- child->sibling = i->child;
- i->child = child;
- next_s_child = s_child;
-
- tot_pushdown++;
- break;
- }
- child = next;
- s_child = next_s_child;
- }
-
- for (Node *i = parent->child; RE_rayobject_isAligned(i) && i; i = i->sibling) {
- pushdown(i);
- }
-}
-
-
-/*
- * BVH refit
- * readjust nodes BB (useful if nodes childs where modified)
- */
-template<class Node>
-static float bvh_refit(Node *node)
-{
- if (is_leaf(node)) return 0;
- if (is_leaf(node->child)) return 0;
-
- float total = 0;
-
- for (Node *child = node->child; child; child = child->sibling)
- total += bvh_refit(child);
-
- float old_area = bb_area(node->bb, node->bb + 3);
- INIT_MINMAX(node->bb, node->bb + 3);
- for (Node *child = node->child; child; child = child->sibling) {
- DO_MIN(child->bb, node->bb);
- DO_MAX(child->bb + 3, node->bb + 3);
- }
- total += old_area - bb_area(node->bb, node->bb + 3);
- return total;
-}
-
-
-/*
- * this finds the best way to packing a tree according to a given test cost function
- * with the purpose to reduce the expected cost (eg.: number of BB tests).
- */
-#include <vector>
-#define MAX_CUT_SIZE 4 /* svbvh assumes max 4 children! */
-#define MAX_OPTIMIZE_CHILDS MAX_CUT_SIZE
-
-#define CUT_SIZE_IS_VALID(cut_size) ((cut_size) < MAX_CUT_SIZE && (cut_size) >= 0)
-#define CUT_SIZE_INVALID -1
-
-
-struct OVBVHNode {
- float bb[6];
-
- OVBVHNode *child;
- OVBVHNode *sibling;
-
- /*
- * Returns min cost to represent the subtree starting at the given node,
- * allowing it to have a given cutsize
- */
- float cut_cost[MAX_CUT_SIZE];
- float get_cost(int cutsize)
- {
- assert(CUT_SIZE_IS_VALID(cutsize - 1));
- return cut_cost[cutsize - 1];
- }
-
- /*
- * This saves the cut size of this child, when parent is reaching
- * its minimum cut with the given cut size
- */
- int cut_size[MAX_CUT_SIZE];
- int get_cut_size(int parent_cut_size)
- {
- assert(CUT_SIZE_IS_VALID(parent_cut_size - 1));
- return cut_size[parent_cut_size - 1];
- }
-
- /*
- * Reorganize the node based on calculated cut costs
- */
- int best_cutsize;
- void set_cut(int cutsize, OVBVHNode ***cut)
- {
- if (cutsize == 1) {
- **cut = this;
- *cut = &(**cut)->sibling;
- }
- else {
- if (cutsize > MAX_CUT_SIZE) {
- for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
- child->set_cut(1, cut);
- cutsize--;
- }
- assert(cutsize == 0);
- }
- else {
- for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
- child->set_cut(child->get_cut_size(cutsize), cut);
- }
- }
- }
- }
-
- void optimize()
- {
- if (RE_rayobject_isAligned(this->child)) {
- //Calc new childs
- if (this->best_cutsize != CUT_SIZE_INVALID) {
- OVBVHNode **cut = &(this->child);
- set_cut(this->best_cutsize, &cut);
- *cut = NULL;
- }
-
- //Optimize new childs
- for (OVBVHNode *child = this->child; child && RE_rayobject_isAligned(child); child = child->sibling)
- child->optimize();
- }
- }
-};
-
-/*
- * Calculates an optimal SIMD packing
- *
- */
-template<class Node, class TestCost>
-struct VBVH_optimalPackSIMD {
- TestCost testcost;
-
- VBVH_optimalPackSIMD(TestCost testcost)
- {
- this->testcost = testcost;
- }
-
- /*
- * calc best cut on a node
- */
- struct calc_best {
- Node *child[MAX_OPTIMIZE_CHILDS];
- float child_hit_prob[MAX_OPTIMIZE_CHILDS];
-
- calc_best(Node *node)
- {
- int nchilds = 0;
- //Fetch childs and needed data
- {
- float parent_area = bb_area(node->bb, node->bb + 3);
- for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
- this->child[nchilds] = child;
- this->child_hit_prob[nchilds] = (parent_area != 0.0f) ? bb_area(child->bb, child->bb + 3) / parent_area : 1.0f;
- nchilds++;
- }
-
- assert(nchilds >= 2 && nchilds <= MAX_OPTIMIZE_CHILDS);
- }
-
-
- //Build DP table to find minimum cost to represent this node with a given cutsize
- int bt[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //backtrace table
- float cost[MAX_OPTIMIZE_CHILDS + 1][MAX_CUT_SIZE + 1]; //cost table (can be reduced to float[2][MAX_CUT_COST])
-
- for (int i = 0; i <= nchilds; i++) {
- for (int j = 0; j <= MAX_CUT_SIZE; j++) {
- cost[i][j] = INFINITY;
- }
- }
-
- cost[0][0] = 0;
-
- for (int i = 1; i <= nchilds; i++) {
- for (int size = i - 1; size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; size++) {
- for (int cut = 1; cut + size /*+(nchilds-i)*/ <= MAX_CUT_SIZE; cut++) {
- float new_cost = cost[i - 1][size] + child_hit_prob[i - 1] * child[i - 1]->get_cost(cut);
- if (new_cost < cost[i][size + cut]) {
- cost[i][size + cut] = new_cost;
- bt[i][size + cut] = cut;
- }
- }
- }
- }
-
- /* Save the ways to archive the minimum cost with a given cutsize */
- for (int i = nchilds; i <= MAX_CUT_SIZE; i++) {
- node->cut_cost[i - 1] = cost[nchilds][i];
- if (cost[nchilds][i] < INFINITY) {
- int current_size = i;
- for (int j = nchilds; j > 0; j--) {
- child[j - 1]->cut_size[i - 1] = bt[j][current_size];
- current_size -= bt[j][current_size];
- }
- }
- }
- }
- };
-
- void calc_costs(Node *node)
- {
-
- if (RE_rayobject_isAligned(node->child) ) {
- int nchilds = 0;
- for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
- calc_costs(child);
- nchilds++;
- }
-
- for (int i = 0; i < MAX_CUT_SIZE; i++)
- node->cut_cost[i] = INFINITY;
-
- //We are not allowed to look on nodes with with so many childs
- if (nchilds > MAX_CUT_SIZE) {
- float cost = 0;
-
- float parent_area = bb_area(node->bb, node->bb + 3);
- for (Node *child = node->child; child && RE_rayobject_isAligned(child); child = child->sibling) {
- cost += ((parent_area != 0.0f) ? (bb_area(child->bb, child->bb + 3) / parent_area) : 1.0f) * child->get_cost(1);
- }
-
- cost += testcost(nchilds);
- node->cut_cost[0] = cost;
- node->best_cutsize = nchilds;
- }
- else {
- calc_best calc(node);
-
- //calc expected cost if we optimaly pack this node
- for (int cutsize = nchilds; cutsize <= MAX_CUT_SIZE; cutsize++) {
- float m = node->get_cost(cutsize) + testcost(cutsize);
- if (m < node->cut_cost[0]) {
- node->cut_cost[0] = m;
- node->best_cutsize = cutsize;
- }
- }
- }
-
- if (node->cut_cost[0] == INFINITY) {
- node->best_cutsize = CUT_SIZE_INVALID;
- }
- }
- else {
- node->cut_cost[0] = 1.0f;
- for (int i = 1; i < MAX_CUT_SIZE; i++)
- node->cut_cost[i] = INFINITY;
-
- /* node->best_cutsize can remain unset here */
- }
- }
-
- Node *transform(Node *node)
- {
- if (RE_rayobject_isAligned(node->child)) {
-#ifdef DEBUG
- static int num = 0;
- bool first = false;
- if (num == 0) { num++; first = true; }
-#endif
-
- calc_costs(node);
-
-#ifdef DEBUG
- if (first && G.debug) {
- printf("expected cost = %f (%d)\n", node->cut_cost[0], node->best_cutsize);
- }
-#endif
- node->optimize();
- }
- return node;
- }
-};
diff --git a/source/blender/render/intern/raytrace/svbvh.h b/source/blender/render/intern/raytrace/svbvh.h
deleted file mode 100644
index 292b93c445f..00000000000
--- a/source/blender/render/intern/raytrace/svbvh.h
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/svbvh.h
- * \ingroup render
- */
-
-#ifndef __SVBVH_H__
-#define __SVBVH_H__
-
-#ifdef __SSE__
-
-#include "bvh.h"
-#include "BLI_memarena.h"
-#include <algorithm>
-
-struct SVBVHNode {
- float child_bb[24];
- SVBVHNode *child[4];
- int nchilds;
-};
-
-static int svbvh_bb_intersect_test_simd4(const Isect *isec, const __m128 *bb_group)
-{
- const __m128 tmin0 = _mm_setzero_ps();
- const __m128 tmax0 = _mm_set_ps1(isec->dist);
-
- const __m128 start0 = _mm_set_ps1(isec->start[0]);
- const __m128 start1 = _mm_set_ps1(isec->start[1]);
- const __m128 start2 = _mm_set_ps1(isec->start[2]);
- const __m128 sub0 = _mm_sub_ps(bb_group[isec->bv_index[0]], start0);
- const __m128 sub1 = _mm_sub_ps(bb_group[isec->bv_index[1]], start0);
- const __m128 sub2 = _mm_sub_ps(bb_group[isec->bv_index[2]], start1);
- const __m128 sub3 = _mm_sub_ps(bb_group[isec->bv_index[3]], start1);
- const __m128 sub4 = _mm_sub_ps(bb_group[isec->bv_index[4]], start2);
- const __m128 sub5 = _mm_sub_ps(bb_group[isec->bv_index[5]], start2);
- const __m128 idot_axis0 = _mm_set_ps1(isec->idot_axis[0]);
- const __m128 idot_axis1 = _mm_set_ps1(isec->idot_axis[1]);
- const __m128 idot_axis2 = _mm_set_ps1(isec->idot_axis[2]);
- const __m128 mul0 = _mm_mul_ps(sub0, idot_axis0);
- const __m128 mul1 = _mm_mul_ps(sub1, idot_axis0);
- const __m128 mul2 = _mm_mul_ps(sub2, idot_axis1);
- const __m128 mul3 = _mm_mul_ps(sub3, idot_axis1);
- const __m128 mul4 = _mm_mul_ps(sub4, idot_axis2);
- const __m128 mul5 = _mm_mul_ps(sub5, idot_axis2);
- const __m128 tmin1 = _mm_max_ps(tmin0, mul0);
- const __m128 tmax1 = _mm_min_ps(tmax0, mul1);
- const __m128 tmin2 = _mm_max_ps(tmin1, mul2);
- const __m128 tmax2 = _mm_min_ps(tmax1, mul3);
- const __m128 tmin3 = _mm_max_ps(tmin2, mul4);
- const __m128 tmax3 = _mm_min_ps(tmax2, mul5);
-
- return _mm_movemask_ps(_mm_cmpge_ps(tmax3, tmin3));
-}
-
-static int svbvh_bb_intersect_test(const Isect *isec, const float *_bb)
-{
- const float *bb = _bb;
-
- float t1x = (bb[isec->bv_index[0]] - isec->start[0]) * isec->idot_axis[0];
- float t2x = (bb[isec->bv_index[1]] - isec->start[0]) * isec->idot_axis[0];
- float t1y = (bb[isec->bv_index[2]] - isec->start[1]) * isec->idot_axis[1];
- float t2y = (bb[isec->bv_index[3]] - isec->start[1]) * isec->idot_axis[1];
- float t1z = (bb[isec->bv_index[4]] - isec->start[2]) * isec->idot_axis[2];
- float t2z = (bb[isec->bv_index[5]] - isec->start[2]) * isec->idot_axis[2];
-
- RE_RC_COUNT(isec->raycounter->bb.test);
-
- if (t1x > t2y || t2x < t1y || t1x > t2z || t2x < t1z || t1y > t2z || t2y < t1z) return 0;
- if (t2x < 0.0f || t2y < 0.0f || t2z < 0.0f) return 0;
- if (t1x > isec->dist || t1y > isec->dist || t1z > isec->dist) return 0;
-
- RE_RC_COUNT(isec->raycounter->bb.hit);
-
- return 1;
-}
-
-static bool svbvh_node_is_leaf(const SVBVHNode *node)
-{
- return !RE_rayobject_isAligned(node);
-}
-
-template<int MAX_STACK_SIZE, bool SHADOW>
-static int svbvh_node_stack_raycast(SVBVHNode *root, Isect *isec)
-{
- SVBVHNode *stack[MAX_STACK_SIZE], *node;
- int hit = 0, stack_pos = 0;
-
- stack[stack_pos++] = root;
-
- while (stack_pos) {
- node = stack[--stack_pos];
-
- if (!svbvh_node_is_leaf(node)) {
- int nchilds = node->nchilds;
-
- if (nchilds == 4) {
- float *child_bb = node->child_bb;
- int res = svbvh_bb_intersect_test_simd4(isec, ((__m128 *) (child_bb)));
- SVBVHNode **child = node->child;
-
- RE_RC_COUNT(isec->raycounter->simd_bb.test);
-
- if (res & 1) { stack[stack_pos++] = child[0]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
- if (res & 2) { stack[stack_pos++] = child[1]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
- if (res & 4) { stack[stack_pos++] = child[2]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
- if (res & 8) { stack[stack_pos++] = child[3]; RE_RC_COUNT(isec->raycounter->simd_bb.hit); }
- }
- else {
- float *child_bb = node->child_bb;
- SVBVHNode **child = node->child;
- int i;
-
- for (i = 0; i < nchilds; i++) {
- if (svbvh_bb_intersect_test(isec, (float *)child_bb + 6 * i)) {
- stack[stack_pos++] = child[i];
- }
- }
- }
- }
- else {
- hit |= RE_rayobject_intersect((RayObject *)node, isec);
- if (SHADOW && hit) break;
- }
- }
-
- return hit;
-}
-
-
-template<>
-inline void bvh_node_merge_bb<SVBVHNode>(SVBVHNode *node, float min[3], float max[3])
-{
- if (is_leaf(node)) {
- RE_rayobject_merge_bb((RayObject *)node, min, max);
- }
- else {
- int i;
- for (i = 0; i + 4 <= node->nchilds; i += 4) {
- float *res = node->child_bb + 6 * i;
- for (int j = 0; j < 3; j++) {
- min[j] = min_ff(min[j],
- min_ffff(res[4 * j + 0],
- res[4 * j + 1],
- res[4 * j + 2],
- res[4 * j + 3]));
- }
- for (int j = 0; j < 3; j++) {
- max[j] = max_ff(max[j],
- max_ffff(res[4 * (j + 3) + 0],
- res[4 * (j + 3) + 1],
- res[4 * (j + 3) + 2],
- res[4 * (j + 3) + 3]));
- }
- }
-
- for (; i < node->nchilds; i++) {
- DO_MIN(node->child_bb + 6 * i, min);
- DO_MAX(node->child_bb + 3 + 6 * i, max);
- }
- }
-}
-
-
-
-/*
- * Builds a SVBVH tree form a VBVHTree
- */
-template<class OldNode>
-struct Reorganize_SVBVH {
- MemArena *arena;
-
- float childs_per_node;
- int nodes_with_childs[16];
- int useless_bb;
- int nodes;
-
- Reorganize_SVBVH(MemArena *a)
- {
- arena = a;
- nodes = 0;
- childs_per_node = 0;
- useless_bb = 0;
-
- for (int i = 0; i < 16; i++) {
- nodes_with_childs[i] = 0;
- }
- }
-
- ~Reorganize_SVBVH()
- {
-#if 0
- {
- printf("%f childs per node\n", childs_per_node / nodes);
- printf("%d childs BB are useless\n", useless_bb);
- for (int i = 0; i < 16; i++) {
- printf("%i childs per node: %d/%d = %f\n", i, nodes_with_childs[i], nodes, nodes_with_childs[i] / float(nodes));
- }
- }
-#endif
- }
-
- SVBVHNode *create_node(int nchilds)
- {
- SVBVHNode *node = (SVBVHNode *)BLI_memarena_alloc(arena, sizeof(SVBVHNode));
- node->nchilds = nchilds;
-
- return node;
- }
-
- void copy_bb(float bb[6], const float old_bb[6])
- {
- std::copy(old_bb, old_bb + 6, bb);
- }
-
- void prepare_for_simd(SVBVHNode *node)
- {
- int i = 0;
- while (i + 4 <= node->nchilds) {
- float vec_tmp[4 * 6];
- float *res = node->child_bb + 6 * i;
- std::copy(res, res + 6 * 4, vec_tmp);
-
- for (int j = 0; j < 6; j++) {
- res[4 * j + 0] = vec_tmp[6 * 0 + j];
- res[4 * j + 1] = vec_tmp[6 * 1 + j];
- res[4 * j + 2] = vec_tmp[6 * 2 + j];
- res[4 * j + 3] = vec_tmp[6 * 3 + j];
- }
-
- i += 4;
- }
- }
-
- /* amt must be power of two */
- inline int padup(int num, int amt)
- {
- return ((num + (amt - 1)) & ~(amt - 1));
- }
-
- SVBVHNode *transform(OldNode *old)
- {
- if (is_leaf(old))
- return (SVBVHNode *)old;
- if (is_leaf(old->child))
- return (SVBVHNode *)old->child;
-
- int nchilds = count_childs(old);
- int alloc_childs = nchilds;
- if (nchilds % 4 > 2)
- alloc_childs = padup(nchilds, 4);
-
- SVBVHNode *node = create_node(alloc_childs);
-
- childs_per_node += nchilds;
- nodes++;
- if (nchilds < 16)
- nodes_with_childs[nchilds]++;
-
- useless_bb += alloc_childs - nchilds;
- while (alloc_childs > nchilds) {
- const static float def_bb[6] = {FLT_MAX, FLT_MAX, FLT_MAX, -FLT_MAX, -FLT_MAX, -FLT_MAX};
- alloc_childs--;
- node->child[alloc_childs] = NULL;
- copy_bb(node->child_bb + alloc_childs * 6, def_bb);
- }
-
- int i = nchilds;
- for (OldNode *o_child = old->child; o_child; o_child = o_child->sibling) {
- i--;
- node->child[i] = transform(o_child);
- if (is_leaf(o_child)) {
- float bb[6];
- INIT_MINMAX(bb, bb + 3);
- RE_rayobject_merge_bb((RayObject *)o_child, bb, bb + 3);
- copy_bb(node->child_bb + i * 6, bb);
- break;
- }
- else {
- copy_bb(node->child_bb + i * 6, o_child->bb);
- }
- }
- assert(i == 0);
-
- prepare_for_simd(node);
-
- return node;
- }
-};
-
-#endif /* __SSE__ */
-
-#endif /* __SVBVH_H__ */
diff --git a/source/blender/render/intern/raytrace/vbvh.h b/source/blender/render/intern/raytrace/vbvh.h
deleted file mode 100644
index abccab5fc13..00000000000
--- a/source/blender/render/intern/raytrace/vbvh.h
+++ /dev/null
@@ -1,238 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2009 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): André Pinto.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/raytrace/vbvh.h
- * \ingroup render
- */
-
-
-#include <assert.h>
-#include <algorithm>
-
-#include "BLI_memarena.h"
-
-#include "rayobject_rtbuild.h"
-
-/*
- * VBVHNode represents a BVHNode with support for a variable number of childrens
- */
-struct VBVHNode {
- float bb[6];
-
- VBVHNode *child;
- VBVHNode *sibling;
-};
-
-
-/*
- * Push nodes (used on dfs)
- */
-template<class Node>
-inline static void bvh_node_push_childs(Node *node, Isect *UNUSED(isec), Node **stack, int &stack_pos)
-{
- Node *child = node->child;
-
- if (is_leaf(child)) {
- stack[stack_pos++] = child;
- }
- else {
- while (child) {
- /* Skips BB tests on primitives */
-#if 0
- if (is_leaf(child->child)) {
- stack[stack_pos++] = child->child;
- }
- else
-#endif
- {
- stack[stack_pos++] = child;
- }
-
- child = child->sibling;
- }
- }
-}
-
-
-template<class Node>
-static int count_childs(Node *parent)
-{
- int n = 0;
- for (Node *i = parent->child; i; i = i->sibling) {
- n++;
- if (is_leaf(i))
- break;
- }
-
- return n;
-}
-
-
-template<class Node>
-static void append_sibling(Node *node, Node *sibling)
-{
- while (node->sibling)
- node = node->sibling;
-
- node->sibling = sibling;
-}
-
-
-/*
- * Builds a binary VBVH from a rtbuild
- */
-template<class Node>
-struct BuildBinaryVBVH {
- MemArena *arena;
- RayObjectControl *control;
-
- void test_break()
- {
- if (RE_rayobjectcontrol_test_break(control))
- throw "Stop";
- }
-
- BuildBinaryVBVH(MemArena *a, RayObjectControl *c)
- {
- arena = a;
- control = c;
- }
-
- Node *create_node()
- {
- Node *node = (Node *)BLI_memarena_alloc(arena, sizeof(Node) );
- assert(RE_rayobject_isAligned(node));
-
- node->sibling = NULL;
- node->child = NULL;
-
- return node;
- }
-
- int rtbuild_split(RTBuilder *builder)
- {
- return ::rtbuild_heuristic_object_split(builder, 2);
- }
-
- Node *transform(RTBuilder *builder)
- {
- try
- {
- return _transform(builder);
-
- } catch (...)
- {
- }
- return NULL;
- }
-
- Node *_transform(RTBuilder *builder)
- {
- int size = rtbuild_size(builder);
-
- if (size == 0) {
- return NULL;
- }
- else if (size == 1) {
- Node *node = create_node();
- INIT_MINMAX(node->bb, node->bb + 3);
- rtbuild_merge_bb(builder, node->bb, node->bb + 3);
- node->child = (Node *) rtbuild_get_primitive(builder, 0);
- return node;
- }
- else {
- test_break();
-
- Node *node = create_node();
-
- Node **child = &node->child;
-
- int nc = rtbuild_split(builder);
- INIT_MINMAX(node->bb, node->bb + 3);
-
- assert(nc == 2);
- for (int i = 0; i < nc; i++) {
- RTBuilder tmp;
- rtbuild_get_child(builder, i, &tmp);
-
- *child = _transform(&tmp);
- DO_MIN((*child)->bb, node->bb);
- DO_MAX((*child)->bb + 3, node->bb + 3);
- child = &((*child)->sibling);
- }
-
- *child = NULL;
- return node;
- }
- }
-};
-
-#if 0
-template<class Tree, class OldNode>
-struct Reorganize_VBVH {
- Tree *tree;
-
- Reorganize_VBVH(Tree *t)
- {
- tree = t;
- }
-
- VBVHNode *create_node()
- {
- VBVHNode *node = (VBVHNode *)BLI_memarena_alloc(tree->node_arena, sizeof(VBVHNode));
- return node;
- }
-
- void copy_bb(VBVHNode *node, OldNode *old)
- {
- std::copy(old->bb, old->bb + 6, node->bb);
- }
-
- VBVHNode *transform(OldNode *old)
- {
- if (is_leaf(old))
- return (VBVHNode *)old;
-
- VBVHNode *node = create_node();
- VBVHNode **child_ptr = &node->child;
- node->sibling = 0;
-
- copy_bb(node, old);
-
- for (OldNode *o_child = old->child; o_child; o_child = o_child->sibling)
- {
- VBVHNode *n_child = transform(o_child);
- *child_ptr = n_child;
- if (is_leaf(n_child)) return node;
- child_ptr = &n_child->sibling;
- }
- *child_ptr = 0;
-
- return node;
- }
-};
-#endif
diff --git a/source/blender/render/intern/source/bake.c b/source/blender/render/intern/source/bake.c
deleted file mode 100644
index 12be60d5171..00000000000
--- a/source/blender/render/intern/source/bake.c
+++ /dev/null
@@ -1,1342 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors: 2004/2005/2006 Blender Foundation, full recode
- * Contributors: Vertex color baking, Copyright 2011 AutoCRC
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/bake.c
- * \ingroup render
- */
-
-
-/* system includes */
-#include <stdio.h>
-#include <string.h>
-
-/* External modules: */
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_rand.h"
-#include "BLI_threads.h"
-#include "BLI_utildefines.h"
-
-#include "DNA_image_types.h"
-#include "DNA_material_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-#include "BKE_customdata.h"
-#include "BKE_global.h"
-#include "BKE_image.h"
-#include "BKE_main.h"
-#include "BKE_node.h"
-#include "BKE_scene.h"
-#include "BKE_library.h"
-
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-#include "IMB_colormanagement.h"
-
-/* local include */
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "render_types.h"
-#include "renderdatabase.h"
-#include "shading.h"
-#include "zbuf.h"
-
-#include "PIL_time.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-
-/* ************************* bake ************************ */
-
-
-typedef struct BakeShade {
- int thread;
-
- ShadeSample ssamp;
- ObjectInstanceRen *obi;
- VlakRen *vlr;
-
- ZSpan *zspan;
- Image *ima;
- ImBuf *ibuf;
-
- int rectx, recty, quad, type, vdone;
- bool ready;
-
- float dir[3];
- Object *actob;
-
- /* Output: vertex color or image data. If vcol is not NULL, rect and
- * rect_float should be NULL. */
- MPoly *mpoly;
- MLoop *mloop;
- MLoopCol *vcol;
-
- unsigned int *rect;
- float *rect_float;
-
- /* displacement buffer used for normalization with unknown maximal distance */
- bool use_displacement_buffer;
- float *displacement_buffer;
- float displacement_min, displacement_max;
-
- bool use_mask;
- char *rect_mask; /* bake pixel mask */
-
- float dxco[3], dyco[3];
-
- short *do_update;
-
- struct ColorSpace *rect_colorspace;
-} BakeShade;
-
-static void bake_set_shade_input(ObjectInstanceRen *obi, VlakRen *vlr, ShadeInput *shi, int quad, int UNUSED(isect), int x, int y, float u, float v)
-{
- if (quad)
- shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3);
- else
- shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2);
-
- /* cache for shadow */
- shi->samplenr = R.shadowsamplenr[shi->thread]++;
-
- shi->mask = 0xFFFF; /* all samples */
-
- shi->u = -u;
- shi->v = -v;
- shi->xs = x;
- shi->ys = y;
-
- shade_input_set_uv(shi);
- shade_input_set_normals(shi);
-
- /* no normal flip */
- if (shi->flippednor)
- shade_input_flip_normals(shi);
-
- /* set up view vector to look right at the surface (note that the normal
- * is negated in the renderer so it does not need to be done here) */
- shi->view[0] = shi->vn[0];
- shi->view[1] = shi->vn[1];
- shi->view[2] = shi->vn[2];
-}
-
-static void bake_shade(void *handle, Object *ob, ShadeInput *shi, int UNUSED(quad), int x, int y, float UNUSED(u), float UNUSED(v), float *tvn, float *ttang)
-{
- BakeShade *bs = handle;
- ShadeSample *ssamp = &bs->ssamp;
- ShadeResult shr;
- VlakRen *vlr = shi->vlr;
-
- shade_input_init_material(shi);
-
- if (bs->type == RE_BAKE_AO) {
- ambient_occlusion(shi);
-
- if (R.r.bake_flag & R_BAKE_NORMALIZE) {
- copy_v3_v3(shr.combined, shi->ao);
- }
- else {
- zero_v3(shr.combined);
- environment_lighting_apply(shi, &shr);
- }
- }
- else {
- if (bs->type == RE_BAKE_SHADOW) /* Why do shadows set the color anyhow?, ignore material color for baking */
- shi->r = shi->g = shi->b = 1.0f;
-
- shade_input_set_shade_texco(shi);
-
- /* only do AO for a full bake (and obviously AO bakes)
- * AO for light bakes is a leftover and might not be needed */
- if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_AO, RE_BAKE_LIGHT))
- shade_samples_do_AO(ssamp);
-
- if (shi->mat->nodetree && shi->mat->use_nodes) {
- ntreeShaderExecTree(shi->mat->nodetree, shi, &shr);
- shi->mat = vlr->mat; /* shi->mat is being set in nodetree */
- }
- else
- shade_material_loop(shi, &shr);
-
- if (bs->type == RE_BAKE_NORMALS) {
- float nor[3];
-
- copy_v3_v3(nor, shi->vn);
-
- if (R.r.bake_normal_space == R_BAKE_SPACE_CAMERA) {
- /* pass */
- }
- else if (R.r.bake_normal_space == R_BAKE_SPACE_TANGENT) {
- float mat[3][3], imat[3][3];
-
- /* bitangent */
- if (tvn && ttang) {
- copy_v3_v3(mat[0], ttang);
- cross_v3_v3v3(mat[1], tvn, ttang);
- mul_v3_fl(mat[1], ttang[3]);
- copy_v3_v3(mat[2], tvn);
- }
- else {
- copy_v3_v3(mat[0], shi->nmaptang);
- cross_v3_v3v3(mat[1], shi->nmapnorm, shi->nmaptang);
- mul_v3_fl(mat[1], shi->nmaptang[3]);
- copy_v3_v3(mat[2], shi->nmapnorm);
- }
-
- invert_m3_m3(imat, mat);
- mul_m3_v3(imat, nor);
- }
- else if (R.r.bake_normal_space == R_BAKE_SPACE_OBJECT)
- mul_mat3_m4_v3(ob->imat_ren, nor); /* ob->imat_ren includes viewinv! */
- else if (R.r.bake_normal_space == R_BAKE_SPACE_WORLD)
- mul_mat3_m4_v3(R.viewinv, nor);
-
- normalize_v3(nor); /* in case object has scaling */
-
- /* The invert of the red channel is to make
- * the normal map compliant with the outside world.
- * It needs to be done because in Blender
- * the normal used in the renderer points inward. It is generated
- * this way in calc_vertexnormals(). Should this ever change
- * this negate must be removed.
- *
- * there is also a small 1e-5f bias for precision issues. otherwise
- * we randomly get 127 or 128 for neutral colors. we choose 128
- * because it is the convention flat color. * */
- shr.combined[0] = (-nor[0]) / 2.0f + 0.5f + 1e-5f;
- shr.combined[1] = nor[1] / 2.0f + 0.5f + 1e-5f;
- shr.combined[2] = nor[2] / 2.0f + 0.5f + 1e-5f;
- }
- else if (bs->type == RE_BAKE_TEXTURE) {
- copy_v3_v3(shr.combined, &shi->r);
- shr.alpha = shi->alpha;
- }
- else if (bs->type == RE_BAKE_SHADOW) {
- copy_v3_v3(shr.combined, shr.shad);
- shr.alpha = shi->alpha;
- }
- else if (bs->type == RE_BAKE_SPEC_COLOR) {
- copy_v3_v3(shr.combined, &shi->specr);
- shr.alpha = 1.0f;
- }
- else if (bs->type == RE_BAKE_SPEC_INTENSITY) {
- copy_v3_fl(shr.combined, shi->spec);
- shr.alpha = 1.0f;
- }
- else if (bs->type == RE_BAKE_MIRROR_COLOR) {
- copy_v3_v3(shr.combined, &shi->mirr);
- shr.alpha = 1.0f;
- }
- else if (bs->type == RE_BAKE_MIRROR_INTENSITY) {
- copy_v3_fl(shr.combined, shi->ray_mirror);
- shr.alpha = 1.0f;
- }
- else if (bs->type == RE_BAKE_ALPHA) {
- copy_v3_fl(shr.combined, shi->alpha);
- shr.alpha = 1.0f;
- }
- else if (bs->type == RE_BAKE_EMIT) {
- copy_v3_fl(shr.combined, shi->emit);
- shr.alpha = 1.0f;
- }
- else if (bs->type == RE_BAKE_VERTEX_COLORS) {
- copy_v3_v3(shr.combined, shi->vcol);
- shr.alpha = shi->vcol[3];
- }
- }
-
- if (bs->rect_float && !bs->vcol) {
- float *col = bs->rect_float + 4 * (bs->rectx * y + x);
- copy_v3_v3(col, shr.combined);
- if (bs->type == RE_BAKE_ALL || bs->type == RE_BAKE_TEXTURE || bs->type == RE_BAKE_VERTEX_COLORS) {
- col[3] = shr.alpha;
- }
- else {
- col[3] = 1.0;
- }
- }
- else {
- /* Target is char (LDR). */
- unsigned char col[4];
-
- if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) {
- float rgb[3];
-
- copy_v3_v3(rgb, shr.combined);
- if (R.scene_color_manage) {
- /* Vertex colors have no way to specify color space, so they
- * default to sRGB. */
- if (!bs->vcol)
- IMB_colormanagement_scene_linear_to_colorspace_v3(rgb, bs->rect_colorspace);
- else
- linearrgb_to_srgb_v3_v3(rgb, rgb);
- }
- rgb_float_to_uchar(col, rgb);
- }
- else {
- rgb_float_to_uchar(col, shr.combined);
- }
-
- if (ELEM(bs->type, RE_BAKE_ALL, RE_BAKE_TEXTURE, RE_BAKE_VERTEX_COLORS)) {
- col[3] = unit_float_to_uchar_clamp(shr.alpha);
- }
- else {
- col[3] = 255;
- }
-
- if (bs->vcol) {
- /* Vertex color baking. Vcol has no useful alpha channel (it exists
- * but is used only for vertex painting). */
- bs->vcol->r = col[0];
- bs->vcol->g = col[1];
- bs->vcol->b = col[2];
- }
- else {
- unsigned char *imcol = (unsigned char *)(bs->rect + bs->rectx * y + x);
- copy_v4_v4_uchar(imcol, col);
- }
-
- }
-
- if (bs->rect_mask) {
- bs->rect_mask[bs->rectx * y + x] = FILTER_MASK_USED;
- }
-
- if (bs->do_update) {
- *bs->do_update = true;
- }
-}
-
-static void bake_displacement(void *handle, ShadeInput *UNUSED(shi), float dist, int x, int y)
-{
- BakeShade *bs = handle;
- float disp;
-
- if (R.r.bake_flag & R_BAKE_NORMALIZE) {
- if (R.r.bake_maxdist)
- disp = (dist + R.r.bake_maxdist) / (R.r.bake_maxdist * 2); /* alter the range from [-bake_maxdist, bake_maxdist] to [0, 1]*/
- else
- disp = dist;
- }
- else {
- disp = 0.5f + dist; /* alter the range from [-0.5,0.5] to [0,1]*/
- }
-
- if (bs->displacement_buffer) {
- float *displacement = bs->displacement_buffer + (bs->rectx * y + x);
- *displacement = disp;
- bs->displacement_min = min_ff(bs->displacement_min, disp);
- bs->displacement_max = max_ff(bs->displacement_max, disp);
- }
-
- if (bs->rect_float && !bs->vcol) {
- float *col = bs->rect_float + 4 * (bs->rectx * y + x);
- col[0] = col[1] = col[2] = disp;
- col[3] = 1.0f;
- }
- else {
- /* Target is char (LDR). */
- unsigned char col[4];
- col[0] = col[1] = col[2] = unit_float_to_uchar_clamp(disp);
- col[3] = 255;
-
- if (bs->vcol) {
- /* Vertex color baking. Vcol has no useful alpha channel (it exists
- * but is used only for vertex painting). */
- bs->vcol->r = col[0];
- bs->vcol->g = col[1];
- bs->vcol->b = col[2];
- }
- else {
- unsigned char *imcol = (unsigned char *)(bs->rect + bs->rectx * y + x);
- copy_v4_v4_uchar(imcol, col);
- }
- }
- if (bs->rect_mask) {
- bs->rect_mask[bs->rectx * y + x] = FILTER_MASK_USED;
- }
-}
-
-static int bake_intersect_tree(RayObject *raytree, Isect *isect, float *start, float *dir, float sign, float *hitco, float *dist)
-{
- float maxdist;
- int hit;
-
- /* might be useful to make a user setting for maxsize*/
- if (R.r.bake_maxdist > 0.0f)
- maxdist = R.r.bake_maxdist;
- else
- maxdist = RE_RAYTRACE_MAXDIST + R.r.bake_biasdist;
-
- /* 'dir' is always normalized */
- madd_v3_v3v3fl(isect->start, start, dir, -R.r.bake_biasdist);
-
- mul_v3_v3fl(isect->dir, dir, sign);
-
- isect->dist = maxdist;
-
- hit = RE_rayobject_raycast(raytree, isect);
- if (hit) {
- madd_v3_v3v3fl(hitco, isect->start, isect->dir, isect->dist);
-
- *dist = isect->dist;
- }
-
- return hit;
-}
-
-static void bake_set_vlr_dxyco(BakeShade *bs, float *uv1, float *uv2, float *uv3)
-{
- VlakRen *vlr = bs->vlr;
- float A, d1, d2, d3, *v1, *v2, *v3;
-
- if (bs->quad) {
- v1 = vlr->v1->co;
- v2 = vlr->v3->co;
- v3 = vlr->v4->co;
- }
- else {
- v1 = vlr->v1->co;
- v2 = vlr->v2->co;
- v3 = vlr->v3->co;
- }
-
- /* formula derived from barycentric coordinates:
- * (uvArea1*v1 + uvArea2*v2 + uvArea3*v3)/uvArea
- * then taking u and v partial derivatives to get dxco and dyco */
- A = (uv2[0] - uv1[0]) * (uv3[1] - uv1[1]) - (uv3[0] - uv1[0]) * (uv2[1] - uv1[1]);
-
- if (fabsf(A) > FLT_EPSILON) {
- A = 0.5f / A;
-
- d1 = uv2[1] - uv3[1];
- d2 = uv3[1] - uv1[1];
- d3 = uv1[1] - uv2[1];
- bs->dxco[0] = (v1[0] * d1 + v2[0] * d2 + v3[0] * d3) * A;
- bs->dxco[1] = (v1[1] * d1 + v2[1] * d2 + v3[1] * d3) * A;
- bs->dxco[2] = (v1[2] * d1 + v2[2] * d2 + v3[2] * d3) * A;
-
- d1 = uv3[0] - uv2[0];
- d2 = uv1[0] - uv3[0];
- d3 = uv2[0] - uv1[0];
- bs->dyco[0] = (v1[0] * d1 + v2[0] * d2 + v3[0] * d3) * A;
- bs->dyco[1] = (v1[1] * d1 + v2[1] * d2 + v3[1] * d3) * A;
- bs->dyco[2] = (v1[2] * d1 + v2[2] * d2 + v3[2] * d3) * A;
- }
- else {
- bs->dxco[0] = bs->dxco[1] = bs->dxco[2] = 0.0f;
- bs->dyco[0] = bs->dyco[1] = bs->dyco[2] = 0.0f;
- }
-
- if (bs->obi->flag & R_TRANSFORMED) {
- mul_m3_v3(bs->obi->nmat, bs->dxco);
- mul_m3_v3(bs->obi->nmat, bs->dyco);
- }
-}
-
-static void do_bake_shade(void *handle, int x, int y, float u, float v)
-{
- BakeShade *bs = handle;
- VlakRen *vlr = bs->vlr;
- ObjectInstanceRen *obi = bs->obi;
- Object *ob = obi->obr->ob;
- float l, *v1, *v2, *v3, tvn[3], ttang[4];
- int quad;
- ShadeSample *ssamp = &bs->ssamp;
- ShadeInput *shi = ssamp->shi;
-
- /* fast threadsafe break test */
- if (R.test_break(R.tbh))
- return;
-
- /* setup render coordinates */
- if (bs->quad) {
- v1 = vlr->v1->co;
- v2 = vlr->v3->co;
- v3 = vlr->v4->co;
- }
- else {
- v1 = vlr->v1->co;
- v2 = vlr->v2->co;
- v3 = vlr->v3->co;
- }
-
- l = 1.0f - u - v;
-
- /* shrink barycentric coordinates inwards slightly to avoid some issues
- * where baking selected to active might just miss the other face at the
- * near the edge of a face */
- if (bs->actob) {
- const float eps = 1.0f - 1e-4f;
- float invsum;
-
- u = (u - 0.5f) * eps + 0.5f;
- v = (v - 0.5f) * eps + 0.5f;
- l = (l - 0.5f) * eps + 0.5f;
-
- invsum = 1.0f / (u + v + l);
-
- u *= invsum;
- v *= invsum;
- l *= invsum;
- }
-
- /* renderco */
- shi->co[0] = l * v3[0] + u * v1[0] + v * v2[0];
- shi->co[1] = l * v3[1] + u * v1[1] + v * v2[1];
- shi->co[2] = l * v3[2] + u * v1[2] + v * v2[2];
-
- /* avoid self shadow with vertex bake from adjacent faces [#33729] */
- if ((bs->vcol != NULL) && (bs->actob == NULL)) {
- madd_v3_v3fl(shi->co, vlr->n, 0.0001f);
- }
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_v3(obi->mat, shi->co);
-
- copy_v3_v3(shi->dxco, bs->dxco);
- copy_v3_v3(shi->dyco, bs->dyco);
-
- quad = bs->quad;
- bake_set_shade_input(obi, vlr, shi, quad, 0, x, y, u, v);
-
- if (bs->type == RE_BAKE_NORMALS && R.r.bake_normal_space == R_BAKE_SPACE_TANGENT) {
- shade_input_set_shade_texco(shi);
- copy_v3_v3(tvn, shi->nmapnorm);
- copy_v4_v4(ttang, shi->nmaptang);
- }
-
- /* if we are doing selected to active baking, find point on other face */
- if (bs->actob) {
- Isect isec, minisec;
- float co[3], minco[3], dist, mindist = 0.0f;
- int hit, sign, dir = 1;
-
- /* intersect with ray going forward and backward*/
- hit = 0;
- memset(&minisec, 0, sizeof(minisec));
- minco[0] = minco[1] = minco[2] = 0.0f;
-
- copy_v3_v3(bs->dir, shi->vn);
-
- for (sign = -1; sign <= 1; sign += 2) {
- memset(&isec, 0, sizeof(isec));
- isec.mode = RE_RAY_MIRROR;
-
- isec.orig.ob = obi;
- isec.orig.face = vlr;
- isec.userdata = bs->actob;
- isec.check = RE_CHECK_VLR_BAKE;
- isec.skip = RE_SKIP_VLR_NEIGHBOUR;
-
- if (bake_intersect_tree(R.raytree, &isec, shi->co, shi->vn, sign, co, &dist)) {
- if (!hit || len_squared_v3v3(shi->co, co) < len_squared_v3v3(shi->co, minco)) {
- minisec = isec;
- mindist = dist;
- copy_v3_v3(minco, co);
- hit = 1;
- dir = sign;
- }
- }
- }
-
- if (ELEM(bs->type, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) {
- if (hit)
- bake_displacement(handle, shi, (dir == -1) ? mindist : -mindist, x, y);
- else
- bake_displacement(handle, shi, 0.0f, x, y);
- return;
- }
-
- /* if hit, we shade from the new point, otherwise from point one starting face */
- if (hit) {
- obi = (ObjectInstanceRen *)minisec.hit.ob;
- vlr = (VlakRen *)minisec.hit.face;
- quad = (minisec.isect == 2);
- copy_v3_v3(shi->co, minco);
-
- u = -minisec.u;
- v = -minisec.v;
- bake_set_shade_input(obi, vlr, shi, quad, 1, x, y, u, v);
- }
- }
-
- if (bs->type == RE_BAKE_NORMALS && R.r.bake_normal_space == R_BAKE_SPACE_TANGENT)
- bake_shade(handle, ob, shi, quad, x, y, u, v, tvn, ttang);
- else
- bake_shade(handle, ob, shi, quad, x, y, u, v, NULL, NULL);
-}
-
-static int get_next_bake_face(BakeShade *bs)
-{
- ObjectRen *obr;
- VlakRen *vlr;
- MTFace *tface;
- static int v = 0, vdone = false;
- static ObjectInstanceRen *obi = NULL;
-
- if (bs == NULL) {
- vlr = NULL;
- v = vdone = false;
- obi = R.instancetable.first;
- return 0;
- }
-
- BLI_thread_lock(LOCK_CUSTOM1);
-
- for (; obi; obi = obi->next, v = 0) {
- obr = obi->obr;
-
- /* only allow non instances here */
- if (obr->flag & R_INSTANCEABLE)
- continue;
-
- for (; v < obr->totvlak; v++) {
- vlr = RE_findOrAddVlak(obr, v);
-
- if ((bs->actob && bs->actob == obr->ob) || (!bs->actob && (obr->ob->flag & SELECT))) {
- if (R.r.bake_flag & R_BAKE_VCOL) {
- /* Gather face data for vertex color bake */
- Mesh *me;
- int *origindex, vcollayer;
- CustomDataLayer *cdl;
-
- if (obr->ob->type != OB_MESH)
- continue;
- me = obr->ob->data;
-
- origindex = RE_vlakren_get_origindex(obr, vlr, 0);
- if (origindex == NULL)
- continue;
- if (*origindex >= me->totpoly) {
- /* Small hack for Array modifier, which gives false
- * original indices - z0r */
- continue;
- }
-#if 0
- /* Only shade selected faces. */
- if ((me->mface[*origindex].flag & ME_FACE_SEL) == 0)
- continue;
-#endif
-
- vcollayer = CustomData_get_render_layer_index(&me->ldata, CD_MLOOPCOL);
- if (vcollayer == -1)
- continue;
-
- cdl = &me->ldata.layers[vcollayer];
- bs->mpoly = me->mpoly + *origindex;
- bs->vcol = ((MLoopCol *)cdl->data) + bs->mpoly->loopstart;
- bs->mloop = me->mloop + bs->mpoly->loopstart;
-
- /* Tag mesh for reevaluation. */
- me->id.tag |= LIB_TAG_DOIT;
- }
- else {
- Image *ima = NULL;
- ImBuf *ibuf = NULL;
- const float vec_alpha[4] = {0.0f, 0.0f, 0.0f, 0.0f};
- const float vec_solid[4] = {0.0f, 0.0f, 0.0f, 1.0f};
- const float nor_alpha[4] = {0.5f, 0.5f, 1.0f, 0.0f};
- const float nor_solid[4] = {0.5f, 0.5f, 1.0f, 1.0f};
- const float disp_alpha[4] = {0.5f, 0.5f, 0.5f, 0.0f};
- const float disp_solid[4] = {0.5f, 0.5f, 0.5f, 1.0f};
-
- tface = RE_vlakren_get_tface(obr, vlr, obr->bakemtface, NULL, 0);
-
- if (!tface || !tface->tpage)
- continue;
-
- ima = tface->tpage;
- ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
-
- if (ibuf == NULL)
- continue;
-
- if (ibuf->rect == NULL && ibuf->rect_float == NULL) {
- BKE_image_release_ibuf(ima, ibuf, NULL);
- continue;
- }
-
- if (ibuf->rect_float && !(ibuf->channels == 0 || ibuf->channels == 4)) {
- BKE_image_release_ibuf(ima, ibuf, NULL);
- continue;
- }
-
- if (ima->flag & IMA_USED_FOR_RENDER) {
- ima->id.tag &= ~LIB_TAG_DOIT;
- BKE_image_release_ibuf(ima, ibuf, NULL);
- continue;
- }
-
- /* find the image for the first time? */
- if (ima->id.tag & LIB_TAG_DOIT) {
- ima->id.tag &= ~LIB_TAG_DOIT;
-
- /* we either fill in float or char, this ensures things go fine */
- if (ibuf->rect_float)
- imb_freerectImBuf(ibuf);
- /* clear image */
- if (R.r.bake_flag & R_BAKE_CLEAR) {
- if (R.r.bake_mode == RE_BAKE_NORMALS && R.r.bake_normal_space == R_BAKE_SPACE_TANGENT)
- IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? nor_alpha : nor_solid);
- else if (ELEM(R.r.bake_mode, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE))
- IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? disp_alpha : disp_solid);
- else
- IMB_rectfill(ibuf, (ibuf->planes == R_IMF_PLANES_RGBA) ? vec_alpha : vec_solid);
- }
- /* might be read by UI to set active image for display */
- R.bakebuf = ima;
- }
-
- /* Tag image for redraw. */
- ibuf->userflags |= IB_DISPLAY_BUFFER_INVALID;
- BKE_image_release_ibuf(ima, ibuf, NULL);
- }
-
- bs->obi = obi;
- bs->vlr = vlr;
- bs->vdone++; /* only for error message if nothing was rendered */
- v++;
- BLI_thread_unlock(LOCK_CUSTOM1);
- return 1;
- }
- }
- }
-
- BLI_thread_unlock(LOCK_CUSTOM1);
- return 0;
-}
-
-static void bake_single_vertex(BakeShade *bs, VertRen *vert, float u, float v)
-{
- int *origindex, i;
- MLoopCol *basevcol;
- MLoop *mloop;
-
- /* per vertex fixed seed */
- BLI_thread_srandom(bs->thread, vert->index);
-
- origindex = RE_vertren_get_origindex(bs->obi->obr, vert, 0);
- if (!origindex || *origindex == ORIGINDEX_NONE)
- return;
-
- /* Search for matching vertex index and apply shading. */
- for (i = 0; i < bs->mpoly->totloop; i++) {
- mloop = bs->mloop + i;
- if (mloop->v != *origindex)
- continue;
- basevcol = bs->vcol;
- bs->vcol = basevcol + i;
- do_bake_shade(bs, 0, 0, u, v);
- bs->vcol = basevcol;
- break;
- }
-}
-
-/* Bake all vertices of a face. Actually, this still works on a face-by-face
- * basis, and each vertex on each face is shaded. Vertex colors are a property
- * of loops, not vertices. */
-static void shade_verts(BakeShade *bs)
-{
- VlakRen *vlr = bs->vlr;
-
- /* Disable baking to image; write to vcol instead. vcol pointer is set in
- * bake_single_vertex. */
- bs->ima = NULL;
- bs->rect = NULL;
- bs->rect_float = NULL;
- bs->displacement_buffer = NULL;
- bs->displacement_min = FLT_MAX;
- bs->displacement_max = -FLT_MAX;
-
- bs->quad = 0;
-
- /* No anti-aliasing for vertices. */
- zero_v3(bs->dxco);
- zero_v3(bs->dyco);
-
- /* Shade each vertex of the face. u and v are barycentric coordinates; since
- * we're only interested in vertices, these will be 0 or 1. */
- if ((vlr->flag & R_FACE_SPLIT) == 0) {
- /* Processing triangle face, whole quad, or first half of split quad. */
-
- bake_single_vertex(bs, bs->vlr->v1, 1.0f, 0.0f);
- bake_single_vertex(bs, bs->vlr->v2, 0.0f, 1.0f);
- bake_single_vertex(bs, bs->vlr->v3, 0.0f, 0.0f);
-
- if (vlr->v4) {
- bs->quad = 1;
- bake_single_vertex(bs, bs->vlr->v4, 0.0f, 0.0f);
- }
- }
- else {
- /* Processing second half of split quad. Only one vertex to go. */
- if (vlr->flag & R_DIVIDE_24) {
- bake_single_vertex(bs, bs->vlr->v2, 0.0f, 1.0f);
- }
- else {
- bake_single_vertex(bs, bs->vlr->v3, 0.0f, 0.0f);
- }
- }
-}
-
-/* already have tested for tface and ima and zspan */
-static void shade_tface(BakeShade *bs)
-{
- VlakRen *vlr = bs->vlr;
- ObjectInstanceRen *obi = bs->obi;
- ObjectRen *obr = obi->obr;
- MTFace *tface = RE_vlakren_get_tface(obr, vlr, obr->bakemtface, NULL, 0);
- Image *ima = tface->tpage;
- float vec[4][2];
- int a, i1, i2, i3;
-
- /* per face fixed seed */
- BLI_thread_srandom(bs->thread, vlr->index);
-
- /* check valid zspan */
- if (ima != bs->ima) {
- BKE_image_release_ibuf(bs->ima, bs->ibuf, NULL);
-
- bs->ima = ima;
- bs->ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- /* note, these calls only free/fill contents of zspan struct, not zspan itself */
- zbuf_free_span(bs->zspan);
- zbuf_alloc_span(bs->zspan, bs->ibuf->x, bs->ibuf->y, R.clipcrop);
- }
-
- bs->rectx = bs->ibuf->x;
- bs->recty = bs->ibuf->y;
- bs->rect = bs->ibuf->rect;
- bs->rect_colorspace = bs->ibuf->rect_colorspace;
- bs->rect_float = bs->ibuf->rect_float;
- bs->vcol = NULL;
- bs->quad = 0;
- bs->rect_mask = NULL;
- bs->displacement_buffer = NULL;
-
- if (bs->use_mask || bs->use_displacement_buffer) {
- BakeImBufuserData *userdata = bs->ibuf->userdata;
- if (userdata == NULL) {
- BLI_thread_lock(LOCK_CUSTOM1);
- userdata = bs->ibuf->userdata;
- if (userdata == NULL) /* since the thread was locked, its possible another thread alloced the value */
- userdata = MEM_callocN(sizeof(BakeImBufuserData), "BakeImBufuserData");
-
- if (bs->use_mask) {
- if (userdata->mask_buffer == NULL) {
- userdata->mask_buffer = MEM_callocN(sizeof(char) * bs->rectx * bs->recty, "BakeMask");
- }
- }
-
- if (bs->use_displacement_buffer) {
- if (userdata->displacement_buffer == NULL) {
- userdata->displacement_buffer = MEM_callocN(sizeof(float) * bs->rectx * bs->recty, "BakeDisp");
- }
- }
-
- bs->ibuf->userdata = userdata;
-
- BLI_thread_unlock(LOCK_CUSTOM1);
- }
-
- bs->rect_mask = userdata->mask_buffer;
- bs->displacement_buffer = userdata->displacement_buffer;
- }
-
- /* get pixel level vertex coordinates */
- for (a = 0; a < 4; a++) {
- /* Note, workaround for pixel aligned UVs which are common and can screw up our intersection tests
- * where a pixel gets in between 2 faces or the middle of a quad,
- * camera aligned quads also have this problem but they are less common.
- * Add a small offset to the UVs, fixes bug #18685 - Campbell */
- vec[a][0] = tface->uv[a][0] * (float)bs->rectx - (0.5f + 0.001f);
- vec[a][1] = tface->uv[a][1] * (float)bs->recty - (0.5f + 0.002f);
- }
-
- /* UV indices have to be corrected for possible quad->tria splits */
- i1 = 0; i2 = 1; i3 = 2;
- vlr_set_uv_indices(vlr, &i1, &i2, &i3);
- bake_set_vlr_dxyco(bs, vec[i1], vec[i2], vec[i3]);
- zspan_scanconvert(bs->zspan, bs, vec[i1], vec[i2], vec[i3], do_bake_shade);
-
- if (vlr->v4) {
- bs->quad = 1;
- bake_set_vlr_dxyco(bs, vec[0], vec[2], vec[3]);
- zspan_scanconvert(bs->zspan, bs, vec[0], vec[2], vec[3], do_bake_shade);
- }
-}
-
-static void *do_bake_thread(void *bs_v)
-{
- BakeShade *bs = bs_v;
-
- while (get_next_bake_face(bs)) {
- if (R.r.bake_flag & R_BAKE_VCOL) {
- shade_verts(bs);
- }
- else {
- shade_tface(bs);
- }
-
- /* fast threadsafe break test */
- if (R.test_break(R.tbh))
- break;
-
- /* access is not threadsafe but since its just true/false probably ok
- * only used for interactive baking */
- if (bs->do_update) {
- *bs->do_update = true;
- }
- }
- bs->ready = true;
-
- BKE_image_release_ibuf(bs->ima, bs->ibuf, NULL);
-
- return NULL;
-}
-
-void RE_bake_ibuf_filter(ImBuf *ibuf, char *mask, const int filter)
-{
- /* must check before filtering */
- const bool is_new_alpha = (ibuf->planes != R_IMF_PLANES_RGBA) && BKE_imbuf_alpha_test(ibuf);
-
- /* Margin */
- if (filter) {
- IMB_filter_extend(ibuf, mask, filter);
- }
-
- /* if the bake results in new alpha then change the image setting */
- if (is_new_alpha) {
- ibuf->planes = R_IMF_PLANES_RGBA;
- }
- else {
- if (filter && ibuf->planes != R_IMF_PLANES_RGBA) {
- /* clear alpha added by filtering */
- IMB_rectfill_alpha(ibuf, 1.0f);
- }
- }
-}
-
-void RE_bake_ibuf_normalize_displacement(ImBuf *ibuf, float *displacement, char *mask, float displacement_min, float displacement_max)
-{
- int i;
- const float *current_displacement = displacement;
- const char *current_mask = mask;
- float max_distance;
-
- max_distance = max_ff(fabsf(displacement_min), fabsf(displacement_max));
-
- for (i = 0; i < ibuf->x * ibuf->y; i++) {
- if (*current_mask == FILTER_MASK_USED) {
- float normalized_displacement;
-
- if (max_distance > 1e-5f)
- normalized_displacement = (*current_displacement + max_distance) / (max_distance * 2);
- else
- normalized_displacement = 0.5f;
-
- if (ibuf->rect_float) {
- /* currently baking happens to RGBA only */
- float *fp = ibuf->rect_float + i * 4;
- fp[0] = fp[1] = fp[2] = normalized_displacement;
- fp[3] = 1.0f;
- }
-
- if (ibuf->rect) {
- unsigned char *cp = (unsigned char *) (ibuf->rect + i);
- cp[0] = cp[1] = cp[2] = unit_float_to_uchar_clamp(normalized_displacement);
- cp[3] = 255;
- }
- }
-
- current_displacement++;
- current_mask++;
- }
-}
-
-/* using object selection tags, the faces with UV maps get baked */
-/* render should have been setup */
-/* returns 0 if nothing was handled */
-int RE_bake_shade_all_selected(Render *re, int type, Object *actob, short *do_update, float *progress)
-{
- BakeShade *handles;
- ListBase threads;
- Image *ima;
- int a, vdone = false, result = BAKE_RESULT_OK;
- bool use_mask = false;
- bool use_displacement_buffer = false;
- bool do_manage = false;
-
- if (ELEM(type, RE_BAKE_ALL, RE_BAKE_TEXTURE)) {
- do_manage = BKE_scene_check_color_management_enabled(re->scene);
- }
-
- re->scene_color_manage = BKE_scene_check_color_management_enabled(re->scene);
-
- /* initialize render global */
- R = *re;
- R.bakebuf = NULL;
-
- /* initialize static vars */
- get_next_bake_face(NULL);
-
- /* do we need a mask? */
- if (re->r.bake_filter)
- use_mask = true;
-
- /* do we need buffer to store displacements */
- if (ELEM(type, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE)) {
- if (((R.r.bake_flag & R_BAKE_NORMALIZE) && R.r.bake_maxdist == 0.0f) ||
- (type == RE_BAKE_DERIVATIVE))
- {
- use_displacement_buffer = true;
- use_mask = true;
- }
- }
-
- /* baker uses this flag to detect if image was initialized */
- if ((R.r.bake_flag & R_BAKE_VCOL) == 0) {
- for (ima = G.main->image.first; ima; ima = ima->id.next) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- ima->id.tag |= LIB_TAG_DOIT;
- ima->flag &= ~IMA_USED_FOR_RENDER;
- if (ibuf) {
- ibuf->userdata = NULL; /* use for masking if needed */
- }
- BKE_image_release_ibuf(ima, ibuf, NULL);
- }
- }
-
- if (R.r.bake_flag & R_BAKE_VCOL) {
- /* untag all meshes */
- BKE_main_id_tag_listbase(&G.main->mesh, LIB_TAG_DOIT, false);
- }
-
- BLI_threadpool_init(&threads, do_bake_thread, re->r.threads);
-
- handles = MEM_callocN(sizeof(BakeShade) * re->r.threads, "BakeShade");
-
- /* get the threads running */
- for (a = 0; a < re->r.threads; a++) {
- handles[a].thread = a;
-
- /* set defaults in handles */
- handles[a].ssamp.shi[0].lay = re->lay;
-
- if (type == RE_BAKE_SHADOW) {
- handles[a].ssamp.shi[0].passflag = SCE_PASS_SHADOW;
- }
- else {
- handles[a].ssamp.shi[0].passflag = SCE_PASS_COMBINED;
- }
- handles[a].ssamp.shi[0].combinedflag = ~(SCE_PASS_SPEC);
- handles[a].ssamp.shi[0].thread = a;
- handles[a].ssamp.shi[0].do_manage = do_manage;
- handles[a].ssamp.tot = 1;
-
- handles[a].type = type;
- handles[a].actob = actob;
- if (R.r.bake_flag & R_BAKE_VCOL)
- handles[a].zspan = NULL;
- else
- handles[a].zspan = MEM_callocN(sizeof(ZSpan), "zspan for bake");
-
- handles[a].use_mask = use_mask;
- handles[a].use_displacement_buffer = use_displacement_buffer;
-
- handles[a].do_update = do_update; /* use to tell the view to update */
-
- handles[a].displacement_min = FLT_MAX;
- handles[a].displacement_max = -FLT_MAX;
-
- BLI_threadpool_insert(&threads, &handles[a]);
- }
-
- /* wait for everything to be done */
- a = 0;
- while (a != re->r.threads) {
- PIL_sleep_ms(50);
-
- /* calculate progress */
- for (vdone = false, a = 0; a < re->r.threads; a++)
- vdone += handles[a].vdone;
- if (progress)
- *progress = (float)(vdone / (float)re->totvlak);
-
- for (a = 0; a < re->r.threads; a++) {
- if (handles[a].ready == false) {
- break;
- }
- }
- }
-
- /* filter and refresh images */
- if ((R.r.bake_flag & R_BAKE_VCOL) == 0) {
- float displacement_min = FLT_MAX, displacement_max = -FLT_MAX;
-
- if (use_displacement_buffer) {
- for (a = 0; a < re->r.threads; a++) {
- displacement_min = min_ff(displacement_min, handles[a].displacement_min);
- displacement_max = max_ff(displacement_max, handles[a].displacement_max);
- }
- }
-
- for (ima = G.main->image.first; ima; ima = ima->id.next) {
- if ((ima->id.tag & LIB_TAG_DOIT) == 0) {
- ImBuf *ibuf = BKE_image_acquire_ibuf(ima, NULL, NULL);
- BakeImBufuserData *userdata;
-
- if (ima->flag & IMA_USED_FOR_RENDER)
- result = BAKE_RESULT_FEEDBACK_LOOP;
-
- if (!ibuf)
- continue;
-
- userdata = (BakeImBufuserData *)ibuf->userdata;
- if (userdata) {
- if (use_displacement_buffer) {
- if (type == RE_BAKE_DERIVATIVE) {
- float user_scale = (R.r.bake_flag & R_BAKE_USERSCALE) ? R.r.bake_user_scale : -1.0f;
- RE_bake_make_derivative(ibuf, userdata->displacement_buffer, userdata->mask_buffer,
- displacement_min, displacement_max, user_scale);
- }
- else {
- RE_bake_ibuf_normalize_displacement(ibuf, userdata->displacement_buffer, userdata->mask_buffer,
- displacement_min, displacement_max);
- }
- }
-
- RE_bake_ibuf_filter(ibuf, userdata->mask_buffer, re->r.bake_filter);
- }
-
- ibuf->userflags |= IB_BITMAPDIRTY;
- BKE_image_release_ibuf(ima, ibuf, NULL);
- }
- }
-
- /* calculate return value */
- for (a = 0; a < re->r.threads; a++) {
- zbuf_free_span(handles[a].zspan);
- MEM_freeN(handles[a].zspan);
- }
- }
-
- MEM_freeN(handles);
-
- BLI_threadpool_end(&threads);
-
- if (vdone == 0) {
- result = BAKE_RESULT_NO_OBJECTS;
- }
-
- return result;
-}
-
-struct Image *RE_bake_shade_get_image(void)
-{
- return R.bakebuf;
-}
-
-/* **************** Derivative Maps Baker **************** */
-
-static void add_single_heights_margin(const ImBuf *ibuf, const char *mask, float *heights_buffer)
-{
- int x, y;
-
- for (y = 0; y < ibuf->y; y++) {
- for (x = 0; x < ibuf->x; x++) {
- int index = ibuf->x * y + x;
-
- /* If unassigned pixel, look for neighbors. */
- if (mask[index] != FILTER_MASK_USED) {
- float height_acc = 0;
- int denom = 0;
- int i, j;
-
- for (j = -1; j <= 1; j++)
- for (i = -1; i <= 1; i++) {
- int w = (i == 0 ? 1 : 0) + (j == 0 ? 1 : 0) + 1;
-
- if (i != 0 || j != 0) {
- int index2 = 0;
- int x0 = x + i;
- int y0 = y + j;
-
- CLAMP(x0, 0, ibuf->x - 1);
- CLAMP(y0, 0, ibuf->y - 1);
-
- index2 = ibuf->x * y0 + x0;
-
- if (mask[index2] == FILTER_MASK_USED) {
- height_acc += w * heights_buffer[index2];
- denom += w;
- }
- }
- }
-
- /* Insert final value. */
- if (denom > 0) {
- heights_buffer[index] = height_acc / denom;
- }
- }
- }
- }
-}
-
-/* returns user-scale */
-float RE_bake_make_derivative(ImBuf *ibuf, float *heights_buffer, const char *mask,
- const float height_min, const float height_max,
- const float fmult)
-{
- const float delta_height = height_max - height_min;
- const float denom = delta_height > 0.0f ? (8 * delta_height) : 1.0f;
- bool auto_range_fit = fmult <= 0.0f;
- float max_num_deriv = -1.0f;
- int x, y, index;
-
- /* Need a single margin to calculate good derivatives. */
- add_single_heights_margin(ibuf, mask, heights_buffer);
-
- if (auto_range_fit) {
- /* If automatic range fitting is enabled. */
- for (y = 0; y < ibuf->y; y++) {
- const int Yu = y == (ibuf->y - 1) ? (ibuf->y - 1) : (y + 1);
- const int Yc = y;
- const int Yd = y == 0 ? 0 : (y - 1);
-
- for (x = 0; x < ibuf->x; x++) {
- const int Xl = x == 0 ? 0 : (x - 1);
- const int Xc = x;
- const int Xr = x == (ibuf->x - 1) ? (ibuf->x - 1) : (x + 1);
-
- const float Hcy = heights_buffer[Yc * ibuf->x + Xr] - heights_buffer[Yc * ibuf->x + Xl];
- const float Hu = heights_buffer[Yu * ibuf->x + Xr] - heights_buffer[Yu * ibuf->x + Xl];
- const float Hd = heights_buffer[Yd * ibuf->x + Xr] - heights_buffer[Yd * ibuf->x + Xl];
-
- const float Hl = heights_buffer[Yu * ibuf->x + Xl] - heights_buffer[Yd * ibuf->x + Xl];
- const float Hcx = heights_buffer[Yu * ibuf->x + Xc] - heights_buffer[Yd * ibuf->x + Xc];
- const float Hr = heights_buffer[Yu * ibuf->x + Xr] - heights_buffer[Yd * ibuf->x + Xr];
-
- /* This corresponds to using the sobel kernel on the heights buffer
- * to obtain the derivative multiplied by 8.
- */
- const float deriv_x = Hu + 2 * Hcy + Hd;
- const float deriv_y = Hr + 2 * Hcx + Hl;
-
- /* early out */
- index = ibuf->x * y + x;
- if (mask[index] != FILTER_MASK_USED) {
- continue;
- }
-
- /* Widen bound. */
- if (fabsf(deriv_x) > max_num_deriv) {
- max_num_deriv = fabsf(deriv_x);
- }
-
- if (fabsf(deriv_y) > max_num_deriv) {
- max_num_deriv = fabsf(deriv_y);
- }
- }
- }
- }
-
- /* Output derivatives. */
- auto_range_fit &= (max_num_deriv > 0);
- for (y = 0; y < ibuf->y; y++) {
- const int Yu = y == (ibuf->y - 1) ? (ibuf->y - 1) : (y + 1);
- const int Yc = y;
- const int Yd = y == 0 ? 0 : (y - 1);
-
- for (x = 0; x < ibuf->x; x++) {
- const int Xl = x == 0 ? 0 : (x - 1);
- const int Xc = x;
- const int Xr = x == (ibuf->x - 1) ? (ibuf->x - 1) : (x + 1);
-
- const float Hcy = heights_buffer[Yc * ibuf->x + Xr] - heights_buffer[Yc * ibuf->x + Xl];
- const float Hu = heights_buffer[Yu * ibuf->x + Xr] - heights_buffer[Yu * ibuf->x + Xl];
- const float Hd = heights_buffer[Yd * ibuf->x + Xr] - heights_buffer[Yd * ibuf->x + Xl];
-
- const float Hl = heights_buffer[Yu * ibuf->x + Xl] - heights_buffer[Yd * ibuf->x + Xl];
- const float Hcx = heights_buffer[Yu * ibuf->x + Xc] - heights_buffer[Yd * ibuf->x + Xc];
- const float Hr = heights_buffer[Yu * ibuf->x + Xr] - heights_buffer[Yd * ibuf->x + Xr];
-
- /* This corresponds to using the sobel kernel on the heights buffer
- * to obtain the derivative multiplied by 8.
- */
- float deriv_x = Hu + 2 * Hcy + Hd;
- float deriv_y = Hr + 2 * Hcx + Hl;
-
- /* Early out. */
- index = ibuf->x * y + x;
- if (mask[index] != FILTER_MASK_USED) {
- continue;
- }
-
- if (auto_range_fit) {
- deriv_x /= max_num_deriv;
- deriv_y /= max_num_deriv;
- }
- else {
- deriv_x *= (fmult / denom);
- deriv_y *= (fmult / denom);
- }
-
- deriv_x = deriv_x * 0.5f + 0.5f;
- deriv_y = deriv_y * 0.5f + 0.5f;
-
- /* Clamp. */
- CLAMP(deriv_x, 0.0f, 1.0f);
- CLAMP(deriv_y, 0.0f, 1.0f);
-
- /* Write out derivatives. */
- if (ibuf->rect_float) {
- float *rrgbf = ibuf->rect_float + index * 4;
-
- rrgbf[0] = deriv_x;
- rrgbf[1] = deriv_y;
- rrgbf[2] = 0.0f;
- rrgbf[3] = 1.0f;
- }
- else {
- char *rrgb = (char *)ibuf->rect + index * 4;
-
- rrgb[0] = unit_float_to_uchar_clamp(deriv_x);
- rrgb[1] = unit_float_to_uchar_clamp(deriv_y);
- rrgb[2] = 0;
- rrgb[3] = 255;
- }
- }
- }
-
- /* Eeturn user-scale (for rendering). */
- return auto_range_fit ? (max_num_deriv / denom) : (fmult > 0.0f ? (1.0f / fmult) : 0.0f);
-}
diff --git a/source/blender/render/intern/source/bake_api.c b/source/blender/render/intern/source/bake_api.c
index 8b25c1fe962..57846bc7443 100644
--- a/source/blender/render/intern/source/bake_api.c
+++ b/source/blender/render/intern/source/bake_api.c
@@ -84,19 +84,11 @@
/* local include */
#include "render_types.h"
-#include "shading.h"
#include "zbuf.h"
/* Remove when Cycles moves from MFace to MLoopTri */
#define USE_MFACE_WORKAROUND
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-
typedef struct BakeDataZSpan {
BakePixel *pixel_array;
int primitive_id;
@@ -263,6 +255,36 @@ static void calc_point_from_barycentric_extrusion(
copy_v3_v3(r_dir, dir);
}
+static void barycentric_differentials_from_position(
+ const float co[3], const float v1[3], const float v2[3], const float v3[3],
+ const float dxco[3], const float dyco[3], const float facenor[3], const bool differentials,
+ float *u, float *v, float *dx_u, float *dx_v, float *dy_u, float *dy_v)
+{
+ /* find most stable axis to project */
+ int axis1, axis2;
+ axis_dominant_v3(&axis1, &axis2, facenor);
+
+ /* compute u,v and derivatives */
+ float t00 = v3[axis1] - v1[axis1];
+ float t01 = v3[axis2] - v1[axis2];
+ float t10 = v3[axis1] - v2[axis1];
+ float t11 = v3[axis2] - v2[axis2];
+
+ float detsh = (t00 * t11 - t10 * t01);
+ detsh = (detsh != 0.0f) ? 1.0f / detsh : 0.0f;
+ t00 *= detsh; t01 *= detsh;
+ t10 *= detsh; t11 *= detsh;
+
+ *u = (v3[axis1] - co[axis1]) * t11 - (v3[axis2] - co[axis2]) * t10;
+ *v = (v3[axis2] - co[axis2]) * t00 - (v3[axis1] - co[axis1]) * t01;
+ if (differentials) {
+ *dx_u = dxco[axis1] * t11 - dxco[axis2] * t10;
+ *dx_v = dxco[axis2] * t00 - dxco[axis1] * t01;
+ *dy_u = dyco[axis1] * t11 - dyco[axis2] * t10;
+ *dy_v = dyco[axis2] * t00 - dyco[axis1] * t01;
+ }
+}
+
/**
* This function populates pixel_array and returns TRUE if things are correct
*/
@@ -665,7 +687,7 @@ void RE_bake_pixels_populate(
}
for (i = 0; i < bake_images->size; i++) {
- zbuf_alloc_span(&bd.zspan[i], bake_images->data[i].width, bake_images->data[i].height, R.clipcrop);
+ zbuf_alloc_span(&bd.zspan[i], bake_images->data[i].width, bake_images->data[i].height);
}
looptri = MEM_mallocN(sizeof(*looptri) * tottri, __func__);
@@ -958,36 +980,6 @@ void RE_bake_ibuf_clear(Image *image, const bool is_tangent)
/* ************************************************************* */
-/**
- * not the real UV, but the internal per-face UV instead
- * I'm using it to test if everything is correct */
-static bool bake_uv(const BakePixel pixel_array[], const size_t num_pixels, const int depth, float result[])
-{
- size_t i;
-
- for (i=0; i < num_pixels; i++) {
- size_t offset = i * depth;
- copy_v2_v2(&result[offset], pixel_array[i].uv);
- }
-
- return true;
-}
-
-bool RE_bake_internal(
- Render *UNUSED(re), Object *UNUSED(object), const BakePixel pixel_array[],
- const size_t num_pixels, const int depth, const eScenePassType pass_type, float result[])
-{
- switch (pass_type) {
- case SCE_PASS_UV:
- {
- return bake_uv(pixel_array, num_pixels, depth, result);
- }
- default:
- break;
- }
- return false;
-}
-
int RE_pass_depth(const eScenePassType pass_type)
{
/* IMB_buffer_byte_from_float assumes 4 channels
diff --git a/source/blender/render/intern/source/convertblender.c b/source/blender/render/intern/source/convertblender.c
deleted file mode 100644
index 52cd5c3449e..00000000000
--- a/source/blender/render/intern/source/convertblender.c
+++ /dev/null
@@ -1,6014 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributors: 2004/2005/2006 Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/convertblender.c
- * \ingroup render
- */
-
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <limits.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-#include "BLI_rand.h"
-#include "BLI_memarena.h"
-#ifdef WITH_FREESTYLE
-# include "BLI_edgehash.h"
-#endif
-
-#include "BLT_translation.h"
-
-#include "DNA_material_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_group_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_image_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_node_types.h"
-#include "DNA_object_types.h"
-#include "DNA_object_fluidsim_types.h"
-#include "DNA_particle_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_texture_types.h"
-
-#include "BKE_anim.h"
-#include "BKE_curve.h"
-#include "BKE_customdata.h"
-#include "BKE_colortools.h"
-#include "BKE_displist.h"
-#include "BKE_depsgraph.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_global.h"
-#include "BKE_key.h"
-#include "BKE_image.h"
-#include "BKE_lattice.h"
-#include "BKE_material.h"
-#include "BKE_main.h"
-#include "BKE_mball.h"
-#include "BKE_mesh.h"
-#include "BKE_modifier.h"
-#include "BKE_node.h"
-#include "BKE_object.h"
-#include "BKE_particle.h"
-#include "BKE_scene.h"
-
-#include "PIL_time.h"
-
-#include "envmap.h"
-#include "occlusion.h"
-#include "pointdensity.h"
-#include "voxeldata.h"
-#include "render_types.h"
-#include "rendercore.h"
-#include "renderdatabase.h"
-#include "renderpipeline.h"
-#include "shadbuf.h"
-#include "shading.h"
-#include "strand.h"
-#include "texture.h"
-#include "volume_precache.h"
-#include "sss.h"
-#include "zbuf.h"
-#include "sunsky.h"
-
-/* 10 times larger than normal epsilon, test it on default nurbs sphere with ray_transp (for quad detection) */
-/* or for checking vertex normal flips */
-#define FLT_EPSILON10 1.19209290e-06F
-
-/* could enable at some point but for now there are far too many conversions */
-#ifdef __GNUC__
-# pragma GCC diagnostic ignored "-Wdouble-promotion"
-#endif
-
-/* ------------------------------------------------------------------------- */
-/* tool functions/defines for ad hoc simplification and possible future
- * cleanup */
-/* ------------------------------------------------------------------------- */
-
-#define UVTOINDEX(u, v) (startvlak + (u) * sizev + (v))
-/*
- *
- * NOTE THAT U/V COORDINATES ARE SOMETIMES SWAPPED !!
- *
- * ^ ()----p4----p3----()
- * | | | | |
- * u | | F1 | F2 |
- * | | | |
- * ()----p1----p2----()
- * v ->
- */
-
-/* ------------------------------------------------------------------------- */
-
-#define CD_MASK_RENDER_INTERNAL \
- (CD_MASK_BAREMESH | CD_MASK_MFACE | CD_MASK_MTFACE | CD_MASK_MCOL)
-
-static void split_v_renderfaces(ObjectRen *obr, int startvlak, int UNUSED(startvert), int UNUSED(usize), int vsize, int uIndex, int UNUSED(cyclu), int cyclv)
-{
- int vLen = vsize-1+(!!cyclv);
- int v;
-
- for (v=0; v<vLen; v++) {
- VlakRen *vlr = RE_findOrAddVlak(obr, startvlak + vLen*uIndex + v);
- VlakRen *vlr_other;
- VertRen *vert = RE_vertren_copy(obr, vlr->v2);
-
- if (cyclv) {
- vlr->v2 = vert;
-
- if (v == vLen - 1) {
- vlr_other = RE_findOrAddVlak(obr, startvlak + vLen*uIndex + 0);
- vlr_other->v1 = vert;
- }
- else {
- vlr_other = RE_findOrAddVlak(obr, startvlak + vLen*uIndex + v+1);
- vlr_other->v1 = vert;
- }
- }
- else {
- vlr->v2 = vert;
-
- if (v < vLen - 1) {
- vlr_other = RE_findOrAddVlak(obr, startvlak + vLen*uIndex + v+1);
- vlr_other->v1 = vert;
- }
-
- if (v == 0) {
- vlr->v1 = RE_vertren_copy(obr, vlr->v1);
- }
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* Stress, tangents and normals */
-/* ------------------------------------------------------------------------- */
-
-static void calc_edge_stress_add(float *accum, VertRen *v1, VertRen *v2)
-{
- float len= len_v3v3(v1->co, v2->co)/len_v3v3(v1->orco, v2->orco);
- float *acc;
-
- acc= accum + 2*v1->index;
- acc[0]+= len;
- acc[1]+= 1.0f;
-
- acc= accum + 2*v2->index;
- acc[0]+= len;
- acc[1]+= 1.0f;
-}
-
-static void calc_edge_stress(Render *UNUSED(re), ObjectRen *obr, Mesh *me)
-{
- float loc[3], size[3], *accum, *acc, *accumoffs, *stress;
- int a;
-
- if (obr->totvert==0) return;
-
- BKE_mesh_texspace_get(me, loc, NULL, size);
-
- accum= MEM_callocN(2*sizeof(float)*obr->totvert, "temp accum for stress");
-
- /* de-normalize orco */
- for (a=0; a<obr->totvert; a++) {
- VertRen *ver= RE_findOrAddVert(obr, a);
- if (ver->orco) {
- ver->orco[0]= ver->orco[0]*size[0] +loc[0];
- ver->orco[1]= ver->orco[1]*size[1] +loc[1];
- ver->orco[2]= ver->orco[2]*size[2] +loc[2];
- }
- }
-
- /* add stress values */
- accumoffs= accum; /* so we can use vertex index */
- for (a=0; a<obr->totvlak; a++) {
- VlakRen *vlr= RE_findOrAddVlak(obr, a);
-
- if (vlr->v1->orco && vlr->v4) {
- calc_edge_stress_add(accumoffs, vlr->v1, vlr->v2);
- calc_edge_stress_add(accumoffs, vlr->v2, vlr->v3);
- calc_edge_stress_add(accumoffs, vlr->v3, vlr->v1);
- if (vlr->v4) {
- calc_edge_stress_add(accumoffs, vlr->v3, vlr->v4);
- calc_edge_stress_add(accumoffs, vlr->v4, vlr->v1);
- calc_edge_stress_add(accumoffs, vlr->v2, vlr->v4);
- }
- }
- }
-
- for (a=0; a<obr->totvert; a++) {
- VertRen *ver= RE_findOrAddVert(obr, a);
- if (ver->orco) {
- /* find stress value */
- acc= accumoffs + 2*ver->index;
- if (acc[1]!=0.0f)
- acc[0]/= acc[1];
- stress= RE_vertren_get_stress(obr, ver, 1);
- *stress= *acc;
-
- /* restore orcos */
- ver->orco[0] = (ver->orco[0]-loc[0])/size[0];
- ver->orco[1] = (ver->orco[1]-loc[1])/size[1];
- ver->orco[2] = (ver->orco[2]-loc[2])/size[2];
- }
- }
-
- MEM_freeN(accum);
-}
-
-/* gets tangent from tface or orco */
-static void calc_tangent_vector(ObjectRen *obr, VlakRen *vlr, int do_tangent)
-{
- MTFace *tface= RE_vlakren_get_tface(obr, vlr, obr->actmtface, NULL, 0);
- VertRen *v1=vlr->v1, *v2=vlr->v2, *v3=vlr->v3, *v4=vlr->v4;
- float tang[3], *tav;
- float *uv1, *uv2, *uv3, *uv4;
- float uv[4][2];
-
- if (tface) {
- uv1= tface->uv[0];
- uv2= tface->uv[1];
- uv3= tface->uv[2];
- uv4= tface->uv[3];
- }
- else if (v1->orco) {
- uv1= uv[0]; uv2= uv[1]; uv3= uv[2]; uv4= uv[3];
- map_to_sphere(&uv[0][0], &uv[0][1], v1->orco[0], v1->orco[1], v1->orco[2]);
- map_to_sphere(&uv[1][0], &uv[1][1], v2->orco[0], v2->orco[1], v2->orco[2]);
- map_to_sphere(&uv[2][0], &uv[2][1], v3->orco[0], v3->orco[1], v3->orco[2]);
- if (v4)
- map_to_sphere(&uv[3][0], &uv[3][1], v4->orco[0], v4->orco[1], v4->orco[2]);
- }
- else return;
-
- tangent_from_uv_v3(uv1, uv2, uv3, v1->co, v2->co, v3->co, vlr->n, tang);
-
- if (do_tangent) {
- tav= RE_vertren_get_tangent(obr, v1, 1);
- add_v3_v3(tav, tang);
- tav= RE_vertren_get_tangent(obr, v2, 1);
- add_v3_v3(tav, tang);
- tav= RE_vertren_get_tangent(obr, v3, 1);
- add_v3_v3(tav, tang);
- }
-
- if (v4) {
- tangent_from_uv_v3(uv1, uv3, uv4, v1->co, v3->co, v4->co, vlr->n, tang);
-
- if (do_tangent) {
- tav= RE_vertren_get_tangent(obr, v1, 1);
- add_v3_v3(tav, tang);
- tav= RE_vertren_get_tangent(obr, v3, 1);
- add_v3_v3(tav, tang);
- tav= RE_vertren_get_tangent(obr, v4, 1);
- add_v3_v3(tav, tang);
- }
- }
-}
-
-
-
-/****************************************************************
- ************ tangent space generation interface ****************
- ****************************************************************/
-
-typedef struct {
- ObjectRen *obr;
- int mtface_index;
-} SRenderMeshToTangent;
-
-/* interface */
-#include "mikktspace.h"
-
-static int GetNumFaces(const SMikkTSpaceContext *pContext)
-{
- SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
- return pMesh->obr->totvlak;
-}
-
-static int GetNumVertsOfFace(const SMikkTSpaceContext *pContext, const int face_num)
-{
- SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
- VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num);
- return vlr->v4!=NULL ? 4 : 3;
-}
-
-static void GetPosition(const SMikkTSpaceContext *pContext, float r_co[3], const int face_num, const int vert_index)
-{
- //assert(vert_index>=0 && vert_index<4);
- SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
- VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num);
- const float *co = (&vlr->v1)[vert_index]->co;
- copy_v3_v3(r_co, co);
-}
-
-static void GetTextureCoordinate(const SMikkTSpaceContext *pContext, float r_uv[2], const int face_num, const int vert_index)
-{
- //assert(vert_index>=0 && vert_index<4);
- SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
- VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num);
- MTFace *tface= RE_vlakren_get_tface(pMesh->obr, vlr, pMesh->mtface_index, NULL, 0);
- const float *coord;
-
- if (tface != NULL) {
- coord= tface->uv[vert_index];
- copy_v2_v2(r_uv, coord);
- }
- else if ((coord = (&vlr->v1)[vert_index]->orco)) {
- map_to_sphere(&r_uv[0], &r_uv[1], coord[0], coord[1], coord[2]);
- }
- else { /* else we get un-initialized value, 0.0 ok default? */
- zero_v2(r_uv);
- }
-}
-
-static void GetNormal(const SMikkTSpaceContext *pContext, float r_no[3], const int face_num, const int vert_index)
-{
- //assert(vert_index>=0 && vert_index<4);
- SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
- VlakRen *vlr= RE_findOrAddVlak(pMesh->obr, face_num);
-
- if (vlr->flag & ME_SMOOTH) {
- const float *n = (&vlr->v1)[vert_index]->n;
- copy_v3_v3(r_no, n);
- }
- else {
- negate_v3_v3(r_no, vlr->n);
- }
-}
-static void SetTSpace(const SMikkTSpaceContext *pContext, const float fvTangent[3], const float fSign, const int face_num, const int iVert)
-{
- //assert(vert_index>=0 && vert_index<4);
- SRenderMeshToTangent *pMesh = (SRenderMeshToTangent *) pContext->m_pUserData;
- VlakRen *vlr = RE_findOrAddVlak(pMesh->obr, face_num);
- float *ftang = RE_vlakren_get_nmap_tangent(pMesh->obr, vlr, pMesh->mtface_index, true);
- if (ftang!=NULL) {
- copy_v3_v3(&ftang[iVert*4+0], fvTangent);
- ftang[iVert*4+3]=fSign;
- }
-}
-
-static void calc_vertexnormals(Render *UNUSED(re), ObjectRen *obr, bool do_vertex_normal, bool do_tangent, bool do_nmap_tangent)
-{
- int a;
-
- /* clear all vertex normals */
- if (do_vertex_normal) {
- for (a=0; a<obr->totvert; a++) {
- VertRen *ver= RE_findOrAddVert(obr, a);
- ver->n[0]=ver->n[1]=ver->n[2]= 0.0f;
- }
- }
-
- /* calculate cos of angles and point-masses, use as weight factor to
- * add face normal to vertex */
- for (a=0; a<obr->totvlak; a++) {
- VlakRen *vlr= RE_findOrAddVlak(obr, a);
- if (do_vertex_normal && vlr->flag & ME_SMOOTH) {
- float *n4= (vlr->v4)? vlr->v4->n: NULL;
- const float *c4= (vlr->v4)? vlr->v4->co: NULL;
-
- accumulate_vertex_normals_v3(vlr->v1->n, vlr->v2->n, vlr->v3->n, n4,
- vlr->n, vlr->v1->co, vlr->v2->co, vlr->v3->co, c4);
- }
- if (do_tangent) {
- /* tangents still need to be calculated for flat faces too */
- /* weighting removed, they are not vertexnormals */
- calc_tangent_vector(obr, vlr, do_tangent);
- }
- }
-
- /* do solid faces */
- for (a=0; a<obr->totvlak; a++) {
- VlakRen *vlr= RE_findOrAddVlak(obr, a);
-
- if (do_vertex_normal && (vlr->flag & ME_SMOOTH)==0) {
- if (is_zero_v3(vlr->v1->n)) copy_v3_v3(vlr->v1->n, vlr->n);
- if (is_zero_v3(vlr->v2->n)) copy_v3_v3(vlr->v2->n, vlr->n);
- if (is_zero_v3(vlr->v3->n)) copy_v3_v3(vlr->v3->n, vlr->n);
- if (vlr->v4 && is_zero_v3(vlr->v4->n)) copy_v3_v3(vlr->v4->n, vlr->n);
- }
- }
-
- /* normalize vertex normals */
- for (a=0; a<obr->totvert; a++) {
- VertRen *ver= RE_findOrAddVert(obr, a);
- normalize_v3(ver->n);
- if (do_tangent) {
- float *tav= RE_vertren_get_tangent(obr, ver, 0);
- if (tav) {
- /* orthonorm. */
- const float tdn = dot_v3v3(tav, ver->n);
- tav[0] -= ver->n[0]*tdn;
- tav[1] -= ver->n[1]*tdn;
- tav[2] -= ver->n[2]*tdn;
- normalize_v3(tav);
- }
- }
- }
-
- /* normal mapping tangent with mikktspace */
- if (do_nmap_tangent != false) {
- SRenderMeshToTangent mesh2tangent;
- SMikkTSpaceContext sContext;
- SMikkTSpaceInterface sInterface;
- memset(&mesh2tangent, 0, sizeof(SRenderMeshToTangent));
- memset(&sContext, 0, sizeof(SMikkTSpaceContext));
- memset(&sInterface, 0, sizeof(SMikkTSpaceInterface));
-
- mesh2tangent.obr = obr;
-
- sContext.m_pUserData = &mesh2tangent;
- sContext.m_pInterface = &sInterface;
- sInterface.m_getNumFaces = GetNumFaces;
- sInterface.m_getNumVerticesOfFace = GetNumVertsOfFace;
- sInterface.m_getPosition = GetPosition;
- sInterface.m_getTexCoord = GetTextureCoordinate;
- sInterface.m_getNormal = GetNormal;
- sInterface.m_setTSpaceBasic = SetTSpace;
-
- for (a = 0; a < MAX_MTFACE; a++) {
- if (obr->tangent_mask & 1 << a) {
- mesh2tangent.mtface_index = a;
- genTangSpaceDefault(&sContext);
- }
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* Autosmoothing: */
-/* ------------------------------------------------------------------------- */
-
-typedef struct ASvert {
- int totface;
- ListBase faces;
-} ASvert;
-
-typedef struct ASface {
- struct ASface *next, *prev;
- VlakRen *vlr[4];
- VertRen *nver[4];
-} ASface;
-
-static int as_addvert(ASvert *asv, VertRen *v1, VlakRen *vlr)
-{
- ASface *asf;
- int a = -1;
-
- if (v1 == NULL)
- return a;
-
- asf = asv->faces.last;
- if (asf) {
- for (a = 0; a < 4 && asf->vlr[a]; a++) {
- }
- }
- else {
- a = 4;
- }
-
- /* new face struct */
- if (a == 4) {
- a = 0;
- asf = MEM_callocN(sizeof(ASface), "asface");
- BLI_addtail(&asv->faces, asf);
- }
-
- asf->vlr[a] = vlr;
- asv->totface++;
-
- return a;
-}
-
-static VertRen *as_findvertex_lnor(VlakRen *vlr, VertRen *ver, ASvert *asv, const float lnor[3])
-{
- /* return when new vertex already was made, or existing one is OK */
- ASface *asf;
- int a;
-
- /* First face, we can use existing vert and assign it current lnor! */
- if (asv->totface == 1) {
- copy_v3_v3(ver->n, lnor);
- return ver;
- }
-
- /* In case existing ver has same normal as current lnor, we can simply use it! */
- if (equals_v3v3(lnor, ver->n)) {
- return ver;
- }
-
- asf = asv->faces.first;
- while (asf) {
- for (a = 0; a < 4; a++) {
- if (asf->vlr[a] && asf->vlr[a] != vlr) {
- /* this face already made a copy for this vertex! */
- if (asf->nver[a]) {
- if (equals_v3v3(lnor, asf->nver[a]->n)) {
- return asf->nver[a];
- }
- }
- }
- }
- asf = asf->next;
- }
-
- return NULL;
-}
-
-static void as_addvert_lnor(ObjectRen *obr, ASvert *asv, VertRen *ver, VlakRen *vlr, const short _lnor[3])
-{
- VertRen *v1;
- ASface *asf;
- int asf_idx;
- float lnor[3];
-
- normal_short_to_float_v3(lnor, _lnor);
-
- asf_idx = as_addvert(asv, ver, vlr);
- if (asf_idx < 0) {
- return;
- }
- asf = asv->faces.last;
-
- /* already made a new vertex within threshold? */
- v1 = as_findvertex_lnor(vlr, ver, asv, lnor);
- if (v1 == NULL) {
- /* make a new vertex */
- v1 = RE_vertren_copy(obr, ver);
- copy_v3_v3(v1->n, lnor);
- }
- if (v1 != ver) {
- asf->nver[asf_idx] = v1;
- if (vlr->v1 == ver) vlr->v1 = v1;
- if (vlr->v2 == ver) vlr->v2 = v1;
- if (vlr->v3 == ver) vlr->v3 = v1;
- if (vlr->v4 == ver) vlr->v4 = v1;
- }
-}
-
-/* note; autosmooth happens in object space still, after applying autosmooth we rotate */
-/* note2; actually, when original mesh and displist are equal sized, face normals are from original mesh */
-static void autosmooth(Render *UNUSED(re), ObjectRen *obr, float mat[4][4], short (*lnors)[4][3])
-{
- ASvert *asverts;
- VertRen *ver;
- VlakRen *vlr;
- int a, totvert;
-
- float rot[3][3];
-
- /* Note: For normals, we only want rotation, not scaling component.
- * Negative scales (aka mirroring) give wrong results, see T44102. */
- if (lnors) {
- float mat3[3][3], size[3];
-
- copy_m3_m4(mat3, mat);
- mat3_to_rot_size(rot, size, mat3);
- }
-
- if (obr->totvert == 0)
- return;
-
- totvert = obr->totvert;
- asverts = MEM_callocN(sizeof(ASvert) * totvert, "all smooth verts");
-
- if (lnors) {
- /* We construct listbase of all vertices and pointers to faces, and add new verts when needed
- * (i.e. when existing ones do not share the same (loop)normal).
- */
- for (a = 0; a < obr->totvlak; a++, lnors++) {
- vlr = RE_findOrAddVlak(obr, a);
- /* skip wire faces */
- if (vlr->v2 != vlr->v3) {
- as_addvert_lnor(obr, asverts+vlr->v1->index, vlr->v1, vlr, (const short*)lnors[0][0]);
- as_addvert_lnor(obr, asverts+vlr->v2->index, vlr->v2, vlr, (const short*)lnors[0][1]);
- as_addvert_lnor(obr, asverts+vlr->v3->index, vlr->v3, vlr, (const short*)lnors[0][2]);
- if (vlr->v4)
- as_addvert_lnor(obr, asverts+vlr->v4->index, vlr->v4, vlr, (const short*)lnors[0][3]);
- }
- }
- }
-
- /* free */
- for (a = 0; a < totvert; a++) {
- BLI_freelistN(&asverts[a].faces);
- }
- MEM_freeN(asverts);
-
- /* rotate vertices and calculate normal of faces */
- for (a = 0; a < obr->totvert; a++) {
- ver = RE_findOrAddVert(obr, a);
- mul_m4_v3(mat, ver->co);
- if (lnors) {
- mul_m3_v3(rot, ver->n);
- negate_v3(ver->n);
- }
- }
- for (a = 0; a < obr->totvlak; a++) {
- vlr = RE_findOrAddVlak(obr, a);
-
- /* skip wire faces */
- if (vlr->v2 != vlr->v3) {
- if (vlr->v4)
- normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- else
- normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* Orco hash and Materials */
-/* ------------------------------------------------------------------------- */
-
-static float *get_object_orco(Render *re, void *ob)
-{
- if (!re->orco_hash) {
- return NULL;
- }
-
- return BLI_ghash_lookup(re->orco_hash, ob);
-}
-
-static void set_object_orco(Render *re, void *ob, float *orco)
-{
- if (!re->orco_hash)
- re->orco_hash = BLI_ghash_ptr_new("set_object_orco gh");
-
- BLI_ghash_insert(re->orco_hash, ob, orco);
-}
-
-static void free_mesh_orco_hash(Render *re)
-{
- if (re->orco_hash) {
- BLI_ghash_free(re->orco_hash, NULL, MEM_freeN);
- re->orco_hash = NULL;
- }
-}
-
-static void check_material_mapto(Material *ma)
-{
- int a;
- ma->mapto_textured = 0;
-
- /* cache which inputs are actually textured.
- * this can avoid a bit of time spent iterating through all the texture slots, map inputs and map tos
- * every time a property which may or may not be textured is accessed */
-
- for (a=0; a<MAX_MTEX; a++) {
- if (ma->mtex[a] && ma->mtex[a]->tex) {
- /* currently used only in volume render, so we'll check for those flags */
- if (ma->mtex[a]->mapto & MAP_DENSITY) ma->mapto_textured |= MAP_DENSITY;
- if (ma->mtex[a]->mapto & MAP_EMISSION) ma->mapto_textured |= MAP_EMISSION;
- if (ma->mtex[a]->mapto & MAP_EMISSION_COL) ma->mapto_textured |= MAP_EMISSION_COL;
- if (ma->mtex[a]->mapto & MAP_SCATTERING) ma->mapto_textured |= MAP_SCATTERING;
- if (ma->mtex[a]->mapto & MAP_TRANSMISSION_COL) ma->mapto_textured |= MAP_TRANSMISSION_COL;
- if (ma->mtex[a]->mapto & MAP_REFLECTION) ma->mapto_textured |= MAP_REFLECTION;
- if (ma->mtex[a]->mapto & MAP_REFLECTION_COL) ma->mapto_textured |= MAP_REFLECTION_COL;
- }
- }
-}
-static void flag_render_node_material(Render *re, bNodeTree *ntree)
-{
- bNode *node;
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->id) {
- if (GS(node->id->name)==ID_MA) {
- Material *ma= (Material *)node->id;
-
- if ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP))
- re->flag |= R_ZTRA;
-
- ma->flag |= MA_IS_USED;
- }
- else if (node->type==NODE_GROUP)
- flag_render_node_material(re, (bNodeTree *)node->id);
- }
- }
-}
-
-static Material *give_render_material(Render *re, Object *ob, short nr)
-{
- extern Material defmaterial; /* material.c */
- Material *ma;
-
- ma= give_current_material(ob, nr);
- if (ma==NULL)
- ma= &defmaterial;
-
- if (re->r.mode & R_SPEED) ma->texco |= NEED_UV;
-
- if (ma->material_type == MA_TYPE_VOLUME) {
- ma->mode |= MA_TRANSP;
- ma->mode &= ~MA_SHADBUF;
- }
- if ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP))
- re->flag |= R_ZTRA;
-
- /* for light groups and SSS */
- ma->flag |= MA_IS_USED;
-
- if (ma->nodetree && ma->use_nodes)
- flag_render_node_material(re, ma->nodetree);
-
- check_material_mapto(ma);
-
- return ma;
-}
-
-/* ------------------------------------------------------------------------- */
-/* Particles */
-/* ------------------------------------------------------------------------- */
-typedef struct ParticleStrandData {
- struct MCol *mcol;
- float *orco, *uvco, *surfnor;
- float time, adapt_angle, adapt_pix, size;
- int totuv, totcol;
- int first, line, adapt, override_uv;
-}
-ParticleStrandData;
-/* future thread problem... */
-static void static_particle_strand(Render *re, ObjectRen *obr, Material *ma, ParticleStrandData *sd, const float vec[3], const float vec1[3])
-{
- static VertRen *v1= NULL, *v2= NULL;
- VlakRen *vlr= NULL;
- float nor[3], cross[3], crosslen, w, dx, dy, width;
- static float anor[3], avec[3];
- int flag, i;
- static int second=0;
-
- sub_v3_v3v3(nor, vec, vec1);
- normalize_v3(nor); /* nor needed as tangent */
- cross_v3_v3v3(cross, vec, nor);
-
- /* turn cross in pixelsize */
- w= vec[2]*re->winmat[2][3] + re->winmat[3][3];
- dx= re->winx*cross[0]*re->winmat[0][0];
- dy= re->winy*cross[1]*re->winmat[1][1];
- w = sqrtf(dx * dx + dy * dy) / w;
-
- if (w!=0.0f) {
- float fac;
- if (ma->strand_ease!=0.0f) {
- if (ma->strand_ease<0.0f)
- fac= pow(sd->time, 1.0f+ma->strand_ease);
- else
- fac= pow(sd->time, 1.0f/(1.0f-ma->strand_ease));
- }
- else fac= sd->time;
-
- width= ((1.0f-fac)*ma->strand_sta + (fac)*ma->strand_end);
-
- /* use actual Blender units for strand width and fall back to minimum width */
- if (ma->mode & MA_STR_B_UNITS) {
- crosslen= len_v3(cross);
- w= 2.0f*crosslen*ma->strand_min/w;
-
- if (width < w)
- width= w;
-
- /*cross is the radius of the strand so we want it to be half of full width */
- mul_v3_fl(cross, 0.5f/crosslen);
- }
- else
- width/=w;
-
- mul_v3_fl(cross, width);
- }
-
- if (ma->mode & MA_TANGENT_STR)
- flag= R_SMOOTH|R_TANGENT;
- else
- flag= R_SMOOTH;
-
- /* only 1 pixel wide strands filled in as quads now, otherwise zbuf errors */
- if (ma->strand_sta==1.0f)
- flag |= R_STRAND;
-
- /* single face line */
- if (sd->line) {
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->flag= flag;
- vlr->v1= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v2= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v3= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v4= RE_findOrAddVert(obr, obr->totvert++);
-
- copy_v3_v3(vlr->v1->co, vec);
- add_v3_v3(vlr->v1->co, cross);
- copy_v3_v3(vlr->v1->n, nor);
- vlr->v1->orco= sd->orco;
- vlr->v1->accum = -1.0f; /* accum abuse for strand texco */
-
- copy_v3_v3(vlr->v2->co, vec);
- sub_v3_v3v3(vlr->v2->co, vlr->v2->co, cross);
- copy_v3_v3(vlr->v2->n, nor);
- vlr->v2->orco= sd->orco;
- vlr->v2->accum= vlr->v1->accum;
-
- copy_v3_v3(vlr->v4->co, vec1);
- add_v3_v3(vlr->v4->co, cross);
- copy_v3_v3(vlr->v4->n, nor);
- vlr->v4->orco= sd->orco;
- vlr->v4->accum = 1.0f; /* accum abuse for strand texco */
-
- copy_v3_v3(vlr->v3->co, vec1);
- sub_v3_v3v3(vlr->v3->co, vlr->v3->co, cross);
- copy_v3_v3(vlr->v3->n, nor);
- vlr->v3->orco= sd->orco;
- vlr->v3->accum= vlr->v4->accum;
-
- normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
-
- vlr->mat= ma;
- vlr->ec= ME_V2V3;
-
- if (sd->surfnor) {
- float *snor= RE_vlakren_get_surfnor(obr, vlr, 1);
- copy_v3_v3(snor, sd->surfnor);
- }
-
- if (sd->uvco) {
- for (i=0; i<sd->totuv; i++) {
- MTFace *mtf;
- mtf=RE_vlakren_get_tface(obr, vlr, i, NULL, 1);
- mtf->uv[0][0]=mtf->uv[1][0]=
- mtf->uv[2][0]=mtf->uv[3][0]=(sd->uvco+2*i)[0];
- mtf->uv[0][1]=mtf->uv[1][1]=
- mtf->uv[2][1]=mtf->uv[3][1]=(sd->uvco+2*i)[1];
- }
- if (sd->override_uv>=0) {
- MTFace *mtf;
- mtf=RE_vlakren_get_tface(obr, vlr, sd->override_uv, NULL, 0);
-
- mtf->uv[0][0]=mtf->uv[3][0]=0.0f;
- mtf->uv[1][0]=mtf->uv[2][0]=1.0f;
-
- mtf->uv[0][1]=mtf->uv[1][1]=0.0f;
- mtf->uv[2][1]=mtf->uv[3][1]=1.0f;
- }
- }
- if (sd->mcol) {
- for (i=0; i<sd->totcol; i++) {
- MCol *mc;
- mc=RE_vlakren_get_mcol(obr, vlr, i, NULL, 1);
- mc[0]=mc[1]=mc[2]=mc[3]=sd->mcol[i];
- mc[0]=mc[1]=mc[2]=mc[3]=sd->mcol[i];
- }
- }
- }
- /* first two vertices of a strand */
- else if (sd->first) {
- if (sd->adapt) {
- copy_v3_v3(anor, nor);
- copy_v3_v3(avec, vec);
- second=1;
- }
-
- v1= RE_findOrAddVert(obr, obr->totvert++);
- v2= RE_findOrAddVert(obr, obr->totvert++);
-
- copy_v3_v3(v1->co, vec);
- add_v3_v3(v1->co, cross);
- copy_v3_v3(v1->n, nor);
- v1->orco= sd->orco;
- v1->accum = -1.0f; /* accum abuse for strand texco */
-
- copy_v3_v3(v2->co, vec);
- sub_v3_v3v3(v2->co, v2->co, cross);
- copy_v3_v3(v2->n, nor);
- v2->orco= sd->orco;
- v2->accum= v1->accum;
- }
- /* more vertices & faces to strand */
- else {
- if (sd->adapt==0 || second) {
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->flag= flag;
- vlr->v1= v1;
- vlr->v2= v2;
- vlr->v3= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v4= RE_findOrAddVert(obr, obr->totvert++);
-
- v1= vlr->v4; /* cycle */
- v2= vlr->v3; /* cycle */
-
-
- if (sd->adapt) {
- second=0;
- copy_v3_v3(anor, nor);
- copy_v3_v3(avec, vec);
- }
-
- }
- else if (sd->adapt) {
- float dvec[3], pvec[3];
- sub_v3_v3v3(dvec, avec, vec);
- project_v3_v3v3(pvec, dvec, vec);
- sub_v3_v3v3(dvec, dvec, pvec);
-
- w= vec[2]*re->winmat[2][3] + re->winmat[3][3];
- dx= re->winx*dvec[0]*re->winmat[0][0]/w;
- dy= re->winy*dvec[1]*re->winmat[1][1]/w;
- w = sqrtf(dx * dx + dy * dy);
- if (dot_v3v3(anor, nor)<sd->adapt_angle && w>sd->adapt_pix) {
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->flag= flag;
- vlr->v1= v1;
- vlr->v2= v2;
- vlr->v3= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v4= RE_findOrAddVert(obr, obr->totvert++);
-
- v1= vlr->v4; /* cycle */
- v2= vlr->v3; /* cycle */
-
- copy_v3_v3(anor, nor);
- copy_v3_v3(avec, vec);
- }
- else {
- vlr= RE_findOrAddVlak(obr, obr->totvlak-1);
- }
- }
-
- copy_v3_v3(vlr->v4->co, vec);
- add_v3_v3(vlr->v4->co, cross);
- copy_v3_v3(vlr->v4->n, nor);
- vlr->v4->orco= sd->orco;
- vlr->v4->accum= -1.0f + 2.0f * sd->time; /* accum abuse for strand texco */
-
- copy_v3_v3(vlr->v3->co, vec);
- sub_v3_v3v3(vlr->v3->co, vlr->v3->co, cross);
- copy_v3_v3(vlr->v3->n, nor);
- vlr->v3->orco= sd->orco;
- vlr->v3->accum= vlr->v4->accum;
-
- normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
-
- vlr->mat= ma;
- vlr->ec= ME_V2V3;
-
- if (sd->surfnor) {
- float *snor= RE_vlakren_get_surfnor(obr, vlr, 1);
- copy_v3_v3(snor, sd->surfnor);
- }
-
- if (sd->uvco) {
- for (i=0; i<sd->totuv; i++) {
- MTFace *mtf;
- mtf=RE_vlakren_get_tface(obr, vlr, i, NULL, 1);
- mtf->uv[0][0]=mtf->uv[1][0]=
- mtf->uv[2][0]=mtf->uv[3][0]=(sd->uvco+2*i)[0];
- mtf->uv[0][1]=mtf->uv[1][1]=
- mtf->uv[2][1]=mtf->uv[3][1]=(sd->uvco+2*i)[1];
- }
- if (sd->override_uv>=0) {
- MTFace *mtf;
- mtf=RE_vlakren_get_tface(obr, vlr, sd->override_uv, NULL, 0);
-
- mtf->uv[0][0]=mtf->uv[3][0]=0.0f;
- mtf->uv[1][0]=mtf->uv[2][0]=1.0f;
-
- mtf->uv[0][1]=mtf->uv[1][1]=(vlr->v1->accum+1.0f)/2.0f;
- mtf->uv[2][1]=mtf->uv[3][1]=(vlr->v3->accum+1.0f)/2.0f;
- }
- }
- if (sd->mcol) {
- for (i=0; i<sd->totcol; i++) {
- MCol *mc;
- mc=RE_vlakren_get_mcol(obr, vlr, i, NULL, 1);
- mc[0]=mc[1]=mc[2]=mc[3]=sd->mcol[i];
- mc[0]=mc[1]=mc[2]=mc[3]=sd->mcol[i];
- }
- }
- }
-}
-
-static void static_particle_wire(ObjectRen *obr, Material *ma, const float vec[3], const float vec1[3], int first, int line)
-{
- VlakRen *vlr;
- static VertRen *v1;
-
- if (line) {
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v2= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v3= vlr->v2;
- vlr->v4= NULL;
-
- copy_v3_v3(vlr->v1->co, vec);
- copy_v3_v3(vlr->v2->co, vec1);
-
- sub_v3_v3v3(vlr->n, vec, vec1);
- normalize_v3(vlr->n);
- copy_v3_v3(vlr->v1->n, vlr->n);
- copy_v3_v3(vlr->v2->n, vlr->n);
-
- vlr->mat= ma;
- vlr->ec= ME_V1V2;
-
- }
- else if (first) {
- v1= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(v1->co, vec);
- }
- else {
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= v1;
- vlr->v2= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v3= vlr->v2;
- vlr->v4= NULL;
-
- v1= vlr->v2; /* cycle */
- copy_v3_v3(v1->co, vec);
-
- sub_v3_v3v3(vlr->n, vec, vec1);
- normalize_v3(vlr->n);
- copy_v3_v3(v1->n, vlr->n);
-
- vlr->mat= ma;
- vlr->ec= ME_V1V2;
- }
-
-}
-
-static void particle_curve(Render *re, ObjectRen *obr, DerivedMesh *dm, Material *ma, ParticleStrandData *sd,
- const float loc[3], const float loc1[3], int seed, float *pa_co)
-{
- HaloRen *har = NULL;
-
- if (ma->material_type == MA_TYPE_WIRE)
- static_particle_wire(obr, ma, loc, loc1, sd->first, sd->line);
- else if (ma->material_type == MA_TYPE_HALO) {
- har= RE_inithalo_particle(re, obr, dm, ma, loc, loc1, sd->orco, sd->uvco, sd->size, 1.0, seed, pa_co);
- if (har) har->lay= obr->ob->lay;
- }
- else
- static_particle_strand(re, obr, ma, sd, loc, loc1);
-}
-static void particle_billboard(Render *re, ObjectRen *obr, Material *ma, ParticleBillboardData *bb)
-{
- VlakRen *vlr;
- MTFace *mtf;
- float xvec[3], yvec[3], zvec[3], bb_center[3];
- /* Number of tiles */
- int totsplit = bb->uv_split * bb->uv_split;
- int tile, x, y;
- /* Tile offsets */
- float uvx = 0.0f, uvy = 0.0f, uvdx = 1.0f, uvdy = 1.0f, time = 0.0f;
-
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v2= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v3= RE_findOrAddVert(obr, obr->totvert++);
- vlr->v4= RE_findOrAddVert(obr, obr->totvert++);
-
- psys_make_billboard(bb, xvec, yvec, zvec, bb_center);
-
- add_v3_v3v3(vlr->v1->co, bb_center, xvec);
- add_v3_v3(vlr->v1->co, yvec);
- mul_m4_v3(re->viewmat, vlr->v1->co);
-
- sub_v3_v3v3(vlr->v2->co, bb_center, xvec);
- add_v3_v3(vlr->v2->co, yvec);
- mul_m4_v3(re->viewmat, vlr->v2->co);
-
- sub_v3_v3v3(vlr->v3->co, bb_center, xvec);
- sub_v3_v3v3(vlr->v3->co, vlr->v3->co, yvec);
- mul_m4_v3(re->viewmat, vlr->v3->co);
-
- add_v3_v3v3(vlr->v4->co, bb_center, xvec);
- sub_v3_v3(vlr->v4->co, yvec);
- mul_m4_v3(re->viewmat, vlr->v4->co);
-
- normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- copy_v3_v3(vlr->v1->n, vlr->n);
- copy_v3_v3(vlr->v2->n, vlr->n);
- copy_v3_v3(vlr->v3->n, vlr->n);
- copy_v3_v3(vlr->v4->n, vlr->n);
-
- vlr->mat= ma;
- vlr->ec= ME_V2V3;
-
- if (bb->uv_split > 1) {
- uvdx = uvdy = 1.0f / (float)bb->uv_split;
-
- if (ELEM(bb->anim, PART_BB_ANIM_AGE, PART_BB_ANIM_FRAME)) {
- if (bb->anim == PART_BB_ANIM_FRAME)
- time = ((int)(bb->time * bb->lifetime) % totsplit)/(float)totsplit;
- else
- time = bb->time;
- }
- else if (bb->anim == PART_BB_ANIM_ANGLE) {
- if (bb->align == PART_BB_VIEW) {
- time = (float)fmod((bb->tilt + 1.0f) / 2.0f, 1.0);
- }
- else {
- float axis1[3] = {0.0f, 0.0f, 0.0f};
- float axis2[3] = {0.0f, 0.0f, 0.0f};
-
- axis1[(bb->align + 1) % 3] = 1.0f;
- axis2[(bb->align + 2) % 3] = 1.0f;
-
- if (bb->lock == 0) {
- zvec[bb->align] = 0.0f;
- normalize_v3(zvec);
- }
-
- time = saacos(dot_v3v3(zvec, axis1)) / (float)M_PI;
-
- if (dot_v3v3(zvec, axis2) < 0.0f)
- time = 1.0f - time / 2.0f;
- else
- time /= 2.0f;
- }
- }
-
- if (bb->split_offset == PART_BB_OFF_LINEAR)
- time = (float)fmod(time + (float)bb->num / (float)totsplit, 1.0f);
- else if (bb->split_offset==PART_BB_OFF_RANDOM)
- time = (float)fmod(time + bb->random, 1.0f);
-
- /* Find the coordinates in tile space (integer), then convert to UV
- * space (float). Note that Y is flipped. */
- tile = (int)((time + FLT_EPSILON10) * totsplit);
- x = tile % bb->uv_split;
- y = tile / bb->uv_split;
- y = (bb->uv_split - 1) - y;
- uvx = uvdx * x;
- uvy = uvdy * y;
- }
-
- /* normal UVs */
- if (bb->uv[0] >= 0) {
- mtf = RE_vlakren_get_tface(obr, vlr, bb->uv[0], NULL, 1);
- mtf->uv[0][0] = 1.0f;
- mtf->uv[0][1] = 1.0f;
- mtf->uv[1][0] = 0.0f;
- mtf->uv[1][1] = 1.0f;
- mtf->uv[2][0] = 0.0f;
- mtf->uv[2][1] = 0.0f;
- mtf->uv[3][0] = 1.0f;
- mtf->uv[3][1] = 0.0f;
- }
-
- /* time-index UVs */
- if (bb->uv[1] >= 0) {
- mtf = RE_vlakren_get_tface(obr, vlr, bb->uv[1], NULL, 1);
- mtf->uv[0][0] = mtf->uv[1][0] = mtf->uv[2][0] = mtf->uv[3][0] = bb->time;
- mtf->uv[0][1] = mtf->uv[1][1] = mtf->uv[2][1] = mtf->uv[3][1] = (float)bb->num/(float)bb->totnum;
- }
-
- /* split UVs */
- if (bb->uv_split > 1 && bb->uv[2] >= 0) {
- mtf = RE_vlakren_get_tface(obr, vlr, bb->uv[2], NULL, 1);
- mtf->uv[0][0] = uvx + uvdx;
- mtf->uv[0][1] = uvy + uvdy;
- mtf->uv[1][0] = uvx;
- mtf->uv[1][1] = uvy + uvdy;
- mtf->uv[2][0] = uvx;
- mtf->uv[2][1] = uvy;
- mtf->uv[3][0] = uvx + uvdx;
- mtf->uv[3][1] = uvy;
- }
-}
-static void particle_normal_ren(short ren_as, ParticleSettings *part, Render *re, ObjectRen *obr, DerivedMesh *dm, Material *ma, ParticleStrandData *sd, ParticleBillboardData *bb, ParticleKey *state, int seed, float hasize, float *pa_co)
-{
- float loc[3], loc0[3], loc1[3], vel[3];
-
- copy_v3_v3(loc, state->co);
-
- if (ren_as != PART_DRAW_BB)
- mul_m4_v3(re->viewmat, loc);
-
- switch (ren_as) {
- case PART_DRAW_LINE:
- sd->line = 1;
- sd->time = 0.0f;
- sd->size = hasize;
-
- mul_v3_mat3_m4v3(vel, re->viewmat, state->vel);
- normalize_v3(vel);
-
- if (part->draw & PART_DRAW_VEL_LENGTH)
- mul_v3_fl(vel, len_v3(state->vel));
-
- madd_v3_v3v3fl(loc0, loc, vel, -part->draw_line[0]);
- madd_v3_v3v3fl(loc1, loc, vel, part->draw_line[1]);
-
- particle_curve(re, obr, dm, ma, sd, loc0, loc1, seed, pa_co);
-
- break;
-
- case PART_DRAW_BB:
-
- copy_v3_v3(bb->vec, loc);
- copy_v3_v3(bb->vel, state->vel);
-
- particle_billboard(re, obr, ma, bb);
-
- break;
-
- default:
- {
- HaloRen *har = NULL;
-
- har = RE_inithalo_particle(re, obr, dm, ma, loc, NULL, sd->orco, sd->uvco, hasize, 0.0, seed, pa_co);
-
- if (har) har->lay= obr->ob->lay;
-
- break;
- }
- }
-}
-static void get_particle_uvco_mcol(short from, DerivedMesh *dm, float *fuv, int num, ParticleStrandData *sd)
-{
- int i;
-
- /* get uvco */
- if (sd->uvco && ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) {
- for (i=0; i<sd->totuv; i++) {
- if (!ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) {
- MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE);
- MTFace *mtface = (MTFace*)CustomData_get_layer_n(&dm->faceData, CD_MTFACE, i);
- mtface += num;
-
- psys_interpolate_uvs(mtface, mface->v4, fuv, sd->uvco + 2 * i);
- }
- else {
- sd->uvco[2*i] = 0.0f;
- sd->uvco[2*i + 1] = 0.0f;
- }
- }
- }
-
- /* get mcol */
- if (sd->mcol && ELEM(from, PART_FROM_FACE, PART_FROM_VOLUME)) {
- for (i=0; i<sd->totcol; i++) {
- if (!ELEM(num, DMCACHE_NOTFOUND, DMCACHE_ISCHILD)) {
- MFace *mface = dm->getTessFaceData(dm, num, CD_MFACE);
- MCol *mc = (MCol*)CustomData_get_layer_n(&dm->faceData, CD_MCOL, i);
- mc += num * 4;
-
- psys_interpolate_mcol(mc, mface->v4, fuv, sd->mcol + i);
- }
- else
- memset(&sd->mcol[i], 0, sizeof(MCol));
- }
- }
-}
-static int render_new_particle_system(Render *re, ObjectRen *obr, ParticleSystem *psys, int timeoffset)
-{
- Object *ob= obr->ob;
-// Object *tob=0;
- Material *ma = NULL;
- ParticleSystemModifierData *psmd;
- ParticleSystem *tpsys = NULL;
- ParticleSettings *part, *tpart = NULL;
- ParticleData *pars, *pa = NULL, *tpa = NULL;
- ParticleKey *states = NULL;
- ParticleKey state;
- ParticleCacheKey *cache = NULL;
- ParticleBillboardData bb;
- ParticleSimulationData sim = {NULL};
- ParticleStrandData sd;
- StrandBuffer *strandbuf = NULL;
- StrandVert *svert = NULL;
- StrandBound *sbound = NULL;
- StrandRen *strand = NULL;
- RNG *rng = NULL;
- float loc[3], loc1[3], loc0[3], mat[4][4], nmat[3][3], co[3], nor[3], duplimat[4][4];
- float strandlen=0.0f, curlen=0.0f;
- float hasize, pa_size, r_tilt, r_length;
- float pa_time, pa_birthtime, pa_dietime;
- float random, simplify[2], pa_co[3];
- const float cfra= BKE_scene_frame_get(re->scene);
- int i, a, k, max_k=0, totpart;
- bool do_simplify = false, do_surfacecache = false, use_duplimat = false;
- int totchild=0, step_nbr;
- int seed, path_nbr=0, orco1=0, num;
- int totface;
-
- const int *index_mf_to_mpoly = NULL;
- const int *index_mp_to_orig = NULL;
-
-/* 1. check that everything is ok & updated */
- if (psys==NULL)
- return 0;
-
- part=psys->part;
- pars=psys->particles;
-
- if (part==NULL || pars==NULL || !psys_check_enabled(ob, psys, G.is_rendering))
- return 0;
-
- if (part->ren_as==PART_DRAW_OB || part->ren_as==PART_DRAW_GR || part->ren_as==PART_DRAW_NOT)
- return 1;
-
- if ((re->r.scemode & R_VIEWPORT_PREVIEW) && (ob->mode & OB_MODE_PARTICLE_EDIT))
- return 0;
-
- if (part->ren_as == PART_DRAW_BB && part->bb_ob == NULL && RE_GetCamera(re) == NULL)
- return 0;
-
-/* 2. start initializing things */
-
- /* last possibility to bail out! */
- psmd = psys_get_modifier(ob, psys);
- if (!(psmd->modifier.mode & eModifierMode_Render))
- return 0;
-
- sim.scene= re->scene;
- sim.ob= ob;
- sim.psys= psys;
- sim.psmd= psmd;
-
- if (part->phystype==PART_PHYS_KEYED)
- psys_count_keyed_targets(&sim);
-
- totchild=psys->totchild;
-
- /* can happen for disconnected/global hair */
- if (part->type==PART_HAIR && !psys->childcache)
- totchild= 0;
-
- if (re->r.scemode & R_VIEWPORT_PREVIEW) { /* preview render */
- totchild = (int)((float)totchild * (float)part->disp / 100.0f);
- step_nbr = 1 << part->draw_step;
- }
- else {
- step_nbr = 1 << part->ren_step;
- }
- if (ELEM(part->kink, PART_KINK_SPIRAL))
- step_nbr += part->kink_extra_steps;
-
- psys->flag |= PSYS_DRAWING;
-
- rng= BLI_rng_new(psys->seed);
-
- totpart=psys->totpart;
-
- memset(&sd, 0, sizeof(ParticleStrandData));
- sd.override_uv = -1;
-
-/* 2.1 setup material stff */
- ma= give_render_material(re, ob, part->omat);
-
-#if 0 /* XXX old animation system */
- if (ma->ipo) {
- calc_ipo(ma->ipo, cfra);
- execute_ipo((ID *)ma, ma->ipo);
- }
-#endif /* XXX old animation system */
-
- hasize = ma->hasize;
- seed = ma->seed1;
-
- re->flag |= R_HALO;
-
- RE_set_customdata_names(obr, &psmd->dm_final->faceData);
- sd.totuv = CustomData_number_of_layers(&psmd->dm_final->faceData, CD_MTFACE);
- sd.totcol = CustomData_number_of_layers(&psmd->dm_final->faceData, CD_MCOL);
-
- if (ma->texco & TEXCO_UV && sd.totuv) {
- sd.uvco = MEM_callocN(sd.totuv * 2 * sizeof(float), "particle_uvs");
-
- if (ma->strand_uvname[0]) {
- sd.override_uv = CustomData_get_named_layer_index(&psmd->dm_final->faceData, CD_MTFACE, ma->strand_uvname);
- sd.override_uv -= CustomData_get_layer_index(&psmd->dm_final->faceData, CD_MTFACE);
- }
- }
- else
- sd.uvco = NULL;
-
- if (sd.totcol)
- sd.mcol = MEM_callocN(sd.totcol * sizeof(MCol), "particle_mcols");
-
-/* 2.2 setup billboards */
- if (part->ren_as == PART_DRAW_BB) {
- int first_uv = CustomData_get_layer_index(&psmd->dm_final->faceData, CD_MTFACE);
-
- bb.uv[0] = CustomData_get_named_layer_index(&psmd->dm_final->faceData, CD_MTFACE, psys->bb_uvname[0]);
- if (bb.uv[0] < 0)
- bb.uv[0] = CustomData_get_active_layer_index(&psmd->dm_final->faceData, CD_MTFACE);
-
- bb.uv[1] = CustomData_get_named_layer_index(&psmd->dm_final->faceData, CD_MTFACE, psys->bb_uvname[1]);
-
- bb.uv[2] = CustomData_get_named_layer_index(&psmd->dm_final->faceData, CD_MTFACE, psys->bb_uvname[2]);
-
- if (first_uv >= 0) {
- bb.uv[0] -= first_uv;
- bb.uv[1] -= first_uv;
- bb.uv[2] -= first_uv;
- }
-
- bb.align = part->bb_align;
- bb.anim = part->bb_anim;
- bb.lock = part->draw & PART_DRAW_BB_LOCK;
- bb.ob = (part->bb_ob ? part->bb_ob : RE_GetCamera(re));
- bb.split_offset = part->bb_split_offset;
- bb.totnum = totpart+totchild;
- bb.uv_split = part->bb_uv_split;
- }
-
-/* 2.5 setup matrices */
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat, mat); /* need to be that way, for imat texture */
- transpose_m3_m4(nmat, ob->imat);
-
- if (psys->flag & PSYS_USE_IMAT) {
- /* psys->imat is the original emitter's inverse matrix, ob->obmat is the duplicated object's matrix */
- mul_m4_m4m4(duplimat, ob->obmat, psys->imat);
- use_duplimat = true;
- }
-
-/* 2.6 setup strand rendering */
- if (part->ren_as == PART_DRAW_PATH && psys->pathcache) {
- path_nbr = step_nbr;
-
- if (path_nbr) {
- if (!ELEM(ma->material_type, MA_TYPE_HALO, MA_TYPE_WIRE)) {
- sd.orco = get_object_orco(re, psys);
- if (!sd.orco) {
- sd.orco = MEM_mallocN(3*sizeof(float)*(totpart+totchild), "particle orcos");
- set_object_orco(re, psys, sd.orco);
- }
- }
- }
-
- if (part->draw & PART_DRAW_REN_ADAPT) {
- sd.adapt = 1;
- sd.adapt_pix = (float)part->adapt_pix;
- sd.adapt_angle = cosf(DEG2RADF((float)part->adapt_angle));
- }
-
- if (part->draw & PART_DRAW_REN_STRAND) {
- strandbuf= RE_addStrandBuffer(obr, (totpart+totchild)*(path_nbr+1));
- strandbuf->ma= ma;
- strandbuf->lay= ob->lay;
- copy_m4_m4(strandbuf->winmat, re->winmat);
- strandbuf->winx= re->winx;
- strandbuf->winy= re->winy;
- strandbuf->maxdepth= 2;
- strandbuf->adaptcos= cosf(DEG2RADF((float)part->adapt_angle));
- strandbuf->overrideuv= sd.override_uv;
- strandbuf->minwidth= ma->strand_min;
-
- if (ma->strand_widthfade == 0.0f)
- strandbuf->widthfade= -1.0f;
- else if (ma->strand_widthfade >= 1.0f)
- strandbuf->widthfade= 2.0f - ma->strand_widthfade;
- else
- strandbuf->widthfade= 1.0f/MAX2(ma->strand_widthfade, 1e-5f);
-
- if (part->flag & PART_HAIR_BSPLINE)
- strandbuf->flag |= R_STRAND_BSPLINE;
- if (ma->mode & MA_STR_B_UNITS)
- strandbuf->flag |= R_STRAND_B_UNITS;
-
- svert= strandbuf->vert;
-
- if (re->r.mode & R_SPEED)
- do_surfacecache = true;
- else if ((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && (re->wrld.ao_gather_method == WO_AOGATHER_APPROX))
- if (ma->amb != 0.0f)
- do_surfacecache = true;
-
- totface= psmd->dm_final->getNumTessFaces(psmd->dm_final);
- index_mf_to_mpoly = psmd->dm_final->getTessFaceDataArray(psmd->dm_final, CD_ORIGINDEX);
- index_mp_to_orig = psmd->dm_final->getPolyDataArray(psmd->dm_final, CD_ORIGINDEX);
- if (index_mf_to_mpoly == NULL) {
- index_mp_to_orig = NULL;
- }
- for (a=0; a<totface; a++)
- strandbuf->totbound = max_ii(strandbuf->totbound, (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a): a);
-
- strandbuf->totbound++;
- strandbuf->bound= MEM_callocN(sizeof(StrandBound)*strandbuf->totbound, "StrandBound");
- sbound= strandbuf->bound;
- sbound->start= sbound->end= 0;
- }
- }
-
- if (sd.orco == NULL) {
- sd.orco = MEM_mallocN(3 * sizeof(float), "particle orco");
- orco1 = 1;
- }
-
- if (path_nbr == 0)
- psys->lattice_deform_data = psys_create_lattice_deform_data(&sim);
-
-/* 3. start creating renderable things */
- for (a=0, pa=pars; a<totpart+totchild; a++, pa++, seed++) {
- random = BLI_rng_get_float(rng);
- /* setup per particle individual stuff */
- if (a<totpart) {
- if (pa->flag & PARS_UNEXIST) continue;
-
- pa_time=(cfra-pa->time)/pa->lifetime;
- pa_birthtime = pa->time;
- pa_dietime = pa->dietime;
-
- hasize = ma->hasize;
-
- /* XXX 'tpsys' is alwyas NULL, this code won't run! */
- /* get orco */
- if (tpsys && part->phystype == PART_PHYS_NO) {
- tpa = tpsys->particles + pa->num;
- psys_particle_on_emitter(
- psmd,
- tpart->from, tpa->num, pa->num_dmcache, tpa->fuv,
- tpa->foffset, co, nor, NULL, NULL, sd.orco, NULL);
- }
- else {
- psys_particle_on_emitter(
- psmd,
- part->from, pa->num, pa->num_dmcache,
- pa->fuv, pa->foffset, co, nor, NULL, NULL, sd.orco, NULL);
- }
-
- /* get uvco & mcol */
- num= pa->num_dmcache;
-
- if (num == DMCACHE_NOTFOUND)
- if (pa->num < psmd->dm_final->getNumTessFaces(psmd->dm_final))
- num= pa->num;
-
- get_particle_uvco_mcol(part->from, psmd->dm_final, pa->fuv, num, &sd);
-
- pa_size = pa->size;
-
- r_tilt = 2.0f*(psys_frand(psys, a) - 0.5f);
- r_length = psys_frand(psys, a+1);
-
- if (path_nbr) {
- cache = psys->pathcache[a];
- max_k = (int)cache->segments;
- }
-
- if (totchild && (part->draw&PART_DRAW_PARENT)==0) continue;
- }
- else {
- ChildParticle *cpa= psys->child+a-totpart;
-
- if (path_nbr) {
- cache = psys->childcache[a-totpart];
-
- if (cache->segments < 0)
- continue;
-
- max_k = (int)cache->segments;
- }
-
- pa_time = psys_get_child_time(psys, cpa, cfra, &pa_birthtime, &pa_dietime);
- pa_size = psys_get_child_size(psys, cpa, cfra, &pa_time);
-
- r_tilt = 2.0f*(psys_frand(psys, a + 21) - 0.5f);
- r_length = psys_frand(psys, a + 22);
-
- num = cpa->num;
-
- /* get orco */
- if (part->childtype == PART_CHILD_FACES) {
- psys_particle_on_emitter(
- psmd,
- PART_FROM_FACE, cpa->num, DMCACHE_ISCHILD,
- cpa->fuv, cpa->foffset, co, nor, NULL, NULL, sd.orco, NULL);
- }
- else {
- ParticleData *par = psys->particles + cpa->parent;
- psys_particle_on_emitter(
- psmd,
- part->from, par->num, DMCACHE_ISCHILD, par->fuv,
- par->foffset, co, nor, NULL, NULL, sd.orco, NULL);
- }
-
- /* get uvco & mcol */
- if (part->childtype==PART_CHILD_FACES) {
- get_particle_uvco_mcol(PART_FROM_FACE, psmd->dm_final, cpa->fuv, cpa->num, &sd);
- }
- else {
- ParticleData *parent = psys->particles + cpa->parent;
- num = parent->num_dmcache;
-
- if (num == DMCACHE_NOTFOUND)
- if (parent->num < psmd->dm_final->getNumTessFaces(psmd->dm_final))
- num = parent->num;
-
- get_particle_uvco_mcol(part->from, psmd->dm_final, parent->fuv, num, &sd);
- }
-
- do_simplify = psys_render_simplify_params(psys, cpa, simplify);
-
- if (strandbuf) {
- int orignum = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, cpa->num) : cpa->num;
-
- if ((orignum > sbound - strandbuf->bound) &&
- (orignum < strandbuf->totbound))
- {
- sbound = &strandbuf->bound[orignum];
- sbound->start = sbound->end = obr->totstrand;
- }
- }
- }
-
- /* TEXCO_PARTICLE */
- pa_co[0] = pa_time;
- pa_co[1] = 0.f;
- pa_co[2] = 0.f;
-
- /* surface normal shading setup */
- if (ma->mode_l & MA_STR_SURFDIFF) {
- mul_m3_v3(nmat, nor);
- sd.surfnor= nor;
- }
- else
- sd.surfnor= NULL;
-
- /* strand render setup */
- if (strandbuf) {
- strand= RE_findOrAddStrand(obr, obr->totstrand++);
- strand->buffer= strandbuf;
- strand->vert= svert;
- copy_v3_v3(strand->orco, sd.orco);
-
- if (do_simplify) {
- float *ssimplify= RE_strandren_get_simplify(obr, strand, 1);
- ssimplify[0]= simplify[0];
- ssimplify[1]= simplify[1];
- }
-
- if (sd.surfnor) {
- float *snor= RE_strandren_get_surfnor(obr, strand, 1);
- copy_v3_v3(snor, sd.surfnor);
- }
-
- if (do_surfacecache && num >= 0) {
- int *facenum= RE_strandren_get_face(obr, strand, 1);
- *facenum= num;
- }
-
- if (sd.uvco) {
- for (i=0; i<sd.totuv; i++) {
- if (i != sd.override_uv) {
- float *uv= RE_strandren_get_uv(obr, strand, i, NULL, 1);
-
- uv[0]= sd.uvco[2*i];
- uv[1]= sd.uvco[2*i+1];
- }
- }
- }
- if (sd.mcol) {
- for (i=0; i<sd.totcol; i++) {
- MCol *mc= RE_strandren_get_mcol(obr, strand, i, NULL, 1);
- *mc = sd.mcol[i];
- }
- }
-
- sbound->end++;
- }
-
- /* strandco computation setup */
- if (path_nbr) {
- strandlen= 0.0f;
- curlen= 0.0f;
- for (k=1; k<=path_nbr; k++)
- if (k<=max_k)
- strandlen += len_v3v3((cache+k-1)->co, (cache+k)->co);
- }
-
- if (path_nbr) {
- /* render strands */
- for (k=0; k<=path_nbr; k++) {
- float time;
-
- if (k<=max_k) {
- copy_v3_v3(state.co, (cache+k)->co);
- copy_v3_v3(state.vel, (cache+k)->vel);
- }
- else
- continue;
-
- if (k > 0)
- curlen += len_v3v3((cache+k-1)->co, (cache+k)->co);
- time= curlen/strandlen;
-
- copy_v3_v3(loc, state.co);
- mul_m4_v3(re->viewmat, loc);
-
- if (strandbuf) {
- copy_v3_v3(svert->co, loc);
- svert->strandco= -1.0f + 2.0f*time;
- svert++;
- strand->totvert++;
- }
- else {
- sd.size = hasize;
-
- if (k==1) {
- sd.first = 1;
- sd.time = 0.0f;
- sub_v3_v3v3(loc0, loc1, loc);
- add_v3_v3v3(loc0, loc1, loc0);
-
- particle_curve(re, obr, psmd->dm_final, ma, &sd, loc1, loc0, seed, pa_co);
- }
-
- sd.first = 0;
- sd.time = time;
-
- if (k)
- particle_curve(re, obr, psmd->dm_final, ma, &sd, loc, loc1, seed, pa_co);
-
- copy_v3_v3(loc1, loc);
- }
- }
-
- }
- else {
- /* render normal particles */
- if (part->trail_count > 1) {
- float length = part->path_end * (1.0f - part->randlength * r_length);
- int trail_count = part->trail_count * (1.0f - part->randlength * r_length);
- float ct = (part->draw & PART_ABS_PATH_TIME) ? cfra : pa_time;
- float dt = length / (trail_count ? (float)trail_count : 1.0f);
-
- /* make sure we have pointcache in memory before getting particle on path */
- psys_make_temp_pointcache(ob, psys);
-
- for (i=0; i < trail_count; i++, ct -= dt) {
- if (part->draw & PART_ABS_PATH_TIME) {
- if (ct < pa_birthtime || ct > pa_dietime)
- continue;
- }
- else if (ct < 0.0f || ct > 1.0f)
- continue;
-
- state.time = (part->draw & PART_ABS_PATH_TIME) ? -ct : ct;
- psys_get_particle_on_path(&sim, a, &state, 1);
-
- if (psys->parent)
- mul_m4_v3(psys->parent->obmat, state.co);
-
- if (use_duplimat)
- mul_m4_v4(duplimat, state.co);
-
- if (part->ren_as == PART_DRAW_BB) {
- bb.random = random;
- bb.offset[0] = part->bb_offset[0];
- bb.offset[1] = part->bb_offset[1];
- bb.size[0] = part->bb_size[0] * pa_size;
- if (part->bb_align==PART_BB_VEL) {
- float pa_vel = len_v3(state.vel);
- float head = part->bb_vel_head*pa_vel;
- float tail = part->bb_vel_tail*pa_vel;
- bb.size[1] = part->bb_size[1]*pa_size + head + tail;
- /* use offset to adjust the particle center. this is relative to size, so need to divide! */
- if (bb.size[1] > 0.0f)
- bb.offset[1] += (head-tail) / bb.size[1];
- }
- else
- bb.size[1] = part->bb_size[1] * pa_size;
- bb.tilt = part->bb_tilt * (1.0f - part->bb_rand_tilt * r_tilt);
- bb.time = ct;
- bb.num = a;
- }
-
- pa_co[0] = (part->draw & PART_ABS_PATH_TIME) ? (ct-pa_birthtime)/(pa_dietime-pa_birthtime) : ct;
- pa_co[1] = (float)i/(float)(trail_count-1);
-
- particle_normal_ren(part->ren_as, part, re, obr, psmd->dm_final, ma, &sd, &bb, &state, seed, hasize, pa_co);
- }
- }
- else {
- state.time=cfra;
- if (psys_get_particle_state(&sim, a, &state, 0)==0)
- continue;
-
- if (psys->parent)
- mul_m4_v3(psys->parent->obmat, state.co);
-
- if (use_duplimat)
- mul_m4_v3(duplimat, state.co);
-
- if (part->ren_as == PART_DRAW_BB) {
- bb.random = random;
- bb.offset[0] = part->bb_offset[0];
- bb.offset[1] = part->bb_offset[1];
- bb.size[0] = part->bb_size[0] * pa_size;
- if (part->bb_align==PART_BB_VEL) {
- float pa_vel = len_v3(state.vel);
- float head = part->bb_vel_head*pa_vel;
- float tail = part->bb_vel_tail*pa_vel;
- bb.size[1] = part->bb_size[1]*pa_size + head + tail;
- /* use offset to adjust the particle center. this is relative to size, so need to divide! */
- if (bb.size[1] > 0.0f)
- bb.offset[1] += (head-tail) / bb.size[1];
- }
- else
- bb.size[1] = part->bb_size[1] * pa_size;
- bb.tilt = part->bb_tilt * (1.0f - part->bb_rand_tilt * r_tilt);
- bb.time = pa_time;
- bb.num = a;
- bb.lifetime = pa_dietime-pa_birthtime;
- }
-
- particle_normal_ren(part->ren_as, part, re, obr, psmd->dm_final, ma, &sd, &bb, &state, seed, hasize, pa_co);
- }
- }
-
- if (orco1==0)
- sd.orco+=3;
-
- if (re->test_break(re->tbh))
- break;
- }
-
- if (do_surfacecache)
- strandbuf->surface= cache_strand_surface(re, obr, psmd->dm_final, mat, timeoffset);
-
-/* 4. clean up */
-#if 0 /* XXX old animation system */
- if (ma) do_mat_ipo(re->scene, ma);
-#endif /* XXX old animation system */
-
- if (orco1)
- MEM_freeN(sd.orco);
-
- if (sd.uvco)
- MEM_freeN(sd.uvco);
-
- if (sd.mcol)
- MEM_freeN(sd.mcol);
-
- if (states)
- MEM_freeN(states);
-
- BLI_rng_free(rng);
-
- psys->flag &= ~PSYS_DRAWING;
-
- if (psys->lattice_deform_data) {
- end_latt_deform(psys->lattice_deform_data);
- psys->lattice_deform_data = NULL;
- }
-
- if (path_nbr && (ma->mode_l & MA_TANGENT_STR)==0)
- calc_vertexnormals(re, obr, 1, 0, 0);
-
- return 1;
-}
-
-/* ------------------------------------------------------------------------- */
-/* Halo's */
-/* ------------------------------------------------------------------------- */
-
-static void make_render_halos(Render *re, ObjectRen *obr, Mesh *UNUSED(me), int totvert, MVert *mvert, Material *ma, float *orco)
-{
- Object *ob= obr->ob;
- HaloRen *har;
- float xn, yn, zn, nor[3], view[3];
- float vec[3], hasize, mat[4][4], imat[3][3];
- int a, ok, seed= ma->seed1;
-
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- copy_m3_m4(imat, ob->imat);
-
- re->flag |= R_HALO;
-
- for (a=0; a<totvert; a++, mvert++) {
- ok= 1;
-
- if (ok) {
- hasize= ma->hasize;
-
- copy_v3_v3(vec, mvert->co);
- mul_m4_v3(mat, vec);
-
- if (ma->mode & MA_HALOPUNO) {
- xn= mvert->no[0];
- yn= mvert->no[1];
- zn= mvert->no[2];
-
- /* transpose ! */
- nor[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn;
- nor[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn;
- nor[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn;
- normalize_v3(nor);
-
- copy_v3_v3(view, vec);
- normalize_v3(view);
-
- zn = dot_v3v3(nor, view);
- if (zn>=0.0f) hasize= 0.0f;
- else hasize*= zn*zn*zn*zn;
- }
-
- if (orco) har= RE_inithalo(re, obr, ma, vec, NULL, orco, hasize, 0.0, seed);
- else har= RE_inithalo(re, obr, ma, vec, NULL, mvert->co, hasize, 0.0, seed);
- if (har) har->lay= ob->lay;
- }
- if (orco) orco+= 3;
- seed++;
- }
-}
-
-static int verghalo(const void *a1, const void *a2)
-{
- const HaloRen *har1= *(const HaloRen**)a1;
- const HaloRen *har2= *(const HaloRen**)a2;
-
- if (har1->zs < har2->zs) return 1;
- else if (har1->zs > har2->zs) return -1;
- return 0;
-}
-
-static void sort_halos(Render *re, int totsort)
-{
- ObjectRen *obr;
- HaloRen *har= NULL, **haso;
- int a;
-
- if (re->tothalo==0) return;
-
- re->sortedhalos= MEM_callocN(sizeof(HaloRen*)*re->tothalo, "sorthalos");
- haso= re->sortedhalos;
-
- for (obr=re->objecttable.first; obr; obr=obr->next) {
- for (a=0; a<obr->tothalo; a++) {
- if ((a & 255)==0) har= obr->bloha[a>>8];
- else har++;
-
- *(haso++)= har;
- }
- }
-
- qsort(re->sortedhalos, totsort, sizeof(HaloRen*), verghalo);
-}
-
-/* ------------------------------------------------------------------------- */
-/* Displacement Mapping */
-/* ------------------------------------------------------------------------- */
-
-static short test_for_displace(Render *re, Object *ob)
-{
- /* return 1 when this object uses displacement textures. */
- Material *ma;
- int i;
-
- for (i=1; i<=ob->totcol; i++) {
- ma=give_render_material(re, ob, i);
- /* ma->mapto is ORed total of all mapto channels */
- if (ma && (ma->mapto & MAP_DISPLACE)) return 1;
- }
- return 0;
-}
-
-static void displace_render_vert(Render *re, ObjectRen *obr, ShadeInput *shi, VertRen *vr, int vindex, float *scale)
-{
- MTFace *tface;
- short texco= shi->mat->texco;
- float sample=0, displace[3];
- char *name;
- int i;
-
- /* shi->co is current render coord, just make sure at least some vector is here */
- copy_v3_v3(shi->co, vr->co);
- /* vertex normal is used for textures type 'col' and 'var' */
- copy_v3_v3(shi->vn, vr->n);
-
- if (texco & TEXCO_UV) {
- shi->totuv= 0;
- shi->actuv= obr->actmtface;
-
- for (i=0; (tface=RE_vlakren_get_tface(obr, shi->vlr, i, &name, 0)); i++) {
- ShadeInputUV *suv= &shi->uv[i];
-
- /* shi.uv needs scale correction from tface uv */
- suv->uv[0]= 2*tface->uv[vindex][0]-1.0f;
- suv->uv[1]= 2*tface->uv[vindex][1]-1.0f;
- suv->uv[2]= 0.0f;
- suv->name= name;
- shi->totuv++;
- }
- }
-
- /* set all rendercoords, 'texco' is an ORed value for all textures needed */
- if ((texco & TEXCO_ORCO) && (vr->orco)) {
- copy_v3_v3(shi->lo, vr->orco);
- }
- if (texco & TEXCO_GLOB) {
- copy_v3_v3(shi->gl, shi->co);
- mul_m4_v3(re->viewinv, shi->gl);
- }
- if (texco & TEXCO_NORM) {
- copy_v3_v3(shi->orn, shi->vn);
- }
- if (texco & TEXCO_REFL) {
- /* not (yet?) */
- }
- if (texco & TEXCO_STRESS) {
- const float *s= RE_vertren_get_stress(obr, vr, 0);
-
- if (s) {
- shi->stress= *s;
- if (shi->stress<1.0f) shi->stress-= 1.0f;
- else shi->stress= (shi->stress-1.0f)/shi->stress;
- }
- else
- shi->stress= 0.0f;
- }
-
- shi->displace[0]= shi->displace[1]= shi->displace[2]= 0.0;
-
- do_material_tex(shi, re);
-
- //printf("no=%f, %f, %f\nbefore co=%f, %f, %f\n", vr->n[0], vr->n[1], vr->n[2],
- //vr->co[0], vr->co[1], vr->co[2]);
-
- displace[0]= shi->displace[0] * scale[0];
- displace[1]= shi->displace[1] * scale[1];
- displace[2]= shi->displace[2] * scale[2];
-
- /* 0.5 could become button once? */
- vr->co[0] += displace[0];
- vr->co[1] += displace[1];
- vr->co[2] += displace[2];
-
- //printf("after co=%f, %f, %f\n", vr->co[0], vr->co[1], vr->co[2]);
-
- /* we just don't do this vertex again, bad luck for other face using same vertex with
- * different material... */
- vr->flag |= 1;
-
- /* Pass sample back so displace_face can decide which way to split the quad */
- sample = shi->displace[0]*shi->displace[0];
- sample += shi->displace[1]*shi->displace[1];
- sample += shi->displace[2]*shi->displace[2];
-
- vr->accum=sample;
- /* Should be sqrt(sample), but I'm only looking for "bigger". Save the cycles. */
- return;
-}
-
-static void displace_render_face(Render *re, ObjectRen *obr, VlakRen *vlr, float *scale)
-{
- ShadeInput shi;
-
- /* Warning, This is not that nice, and possibly a bit slow,
- * however some variables were not initialized properly in, unless using shade_input_initialize(...), we need to do a memset */
- memset(&shi, 0, sizeof(ShadeInput));
- /* end warning! - Campbell */
-
- /* set up shadeinput struct for multitex() */
-
- /* memset above means we don't need this */
- /*shi.osatex= 0;*/ /* signal not to use dx[] and dy[] texture AA vectors */
-
- shi.obr= obr;
- shi.vlr= vlr; /* current render face */
- shi.mat= vlr->mat; /* current input material */
- shi.thread= 0;
-
- /* TODO, assign these, displacement with new bumpmap is skipped without - campbell */
-#if 0
- /* order is not known ? */
- shi.v1= vlr->v1;
- shi.v2= vlr->v2;
- shi.v3= vlr->v3;
-#endif
-
- /* Displace the verts, flag is set when done */
- if (!vlr->v1->flag)
- displace_render_vert(re, obr, &shi, vlr->v1, 0, scale);
-
- if (!vlr->v2->flag)
- displace_render_vert(re, obr, &shi, vlr->v2, 1, scale);
-
- if (!vlr->v3->flag)
- displace_render_vert(re, obr, &shi, vlr->v3, 2, scale);
-
- if (vlr->v4) {
- if (!vlr->v4->flag)
- displace_render_vert(re, obr, &shi, vlr->v4, 3, scale);
-
- /* closest in displace value. This will help smooth edges. */
- if (fabsf(vlr->v1->accum - vlr->v3->accum) > fabsf(vlr->v2->accum - vlr->v4->accum)) vlr->flag |= R_DIVIDE_24;
- else vlr->flag &= ~R_DIVIDE_24;
- }
-
- /* Recalculate the face normal - if flipped before, flip now */
- if (vlr->v4) {
- normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- }
- else {
- normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- }
-}
-
-static void displace(Render *re, ObjectRen *obr)
-{
- VertRen *vr;
- VlakRen *vlr;
-// float min[3]={1e30, 1e30, 1e30}, max[3]={-1e30, -1e30, -1e30};
- float scale[3]={1.0f, 1.0f, 1.0f}, temp[3];//, xn
- int i; //, texflag=0;
- Object *obt;
-
- /* Object Size with parenting */
- obt=obr->ob;
- while (obt) {
- mul_v3_v3v3(temp, obt->size, obt->dscale);
- scale[0]*=temp[0]; scale[1]*=temp[1]; scale[2]*=temp[2];
- obt=obt->parent;
- }
-
- /* Clear all flags */
- for (i=0; i<obr->totvert; i++) {
- vr= RE_findOrAddVert(obr, i);
- vr->flag= 0;
- }
-
- for (i=0; i<obr->totvlak; i++) {
- vlr=RE_findOrAddVlak(obr, i);
- displace_render_face(re, obr, vlr, scale);
- }
-
- /* Recalc vertex normals */
- calc_vertexnormals(re, obr, 1, 0, 0);
-}
-
-/* ------------------------------------------------------------------------- */
-/* Metaball */
-/* ------------------------------------------------------------------------- */
-
-static void init_render_mball(Render *re, ObjectRen *obr)
-{
- Object *ob= obr->ob;
- DispList *dl;
- VertRen *ver;
- VlakRen *vlr, *vlr1;
- Material *ma;
- float *data, *nors, *orco=NULL, mat[4][4], imat[3][3], xn, yn, zn;
- int a, need_orco, vlakindex, *index, negative_scale;
- ListBase dispbase= {NULL, NULL};
-
- if (ob!=BKE_mball_basis_find(re->scene, ob))
- return;
-
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat, mat);
- copy_m3_m4(imat, ob->imat);
- negative_scale = is_negative_m4(mat);
-
- ma= give_render_material(re, ob, 1);
-
- need_orco= 0;
- if (ma->texco & TEXCO_ORCO) {
- need_orco= 1;
- }
-
- BKE_displist_make_mball_forRender(re->eval_ctx, re->scene, ob, &dispbase);
- dl= dispbase.first;
- if (dl == NULL) return;
-
- data= dl->verts;
- nors= dl->nors;
- if (need_orco) {
- orco= get_object_orco(re, ob);
-
- if (!orco) {
- /* orco hasn't been found in cache - create new one and add to cache */
- orco= BKE_mball_make_orco(ob, &dispbase);
- set_object_orco(re, ob, orco);
- }
- }
-
- for (a=0; a<dl->nr; a++, data+=3, nors+=3) {
-
- ver= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, data);
- mul_m4_v3(mat, ver->co);
-
- /* render normals are inverted */
- xn= -nors[0];
- yn= -nors[1];
- zn= -nors[2];
-
- /* transpose ! */
- ver->n[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn;
- ver->n[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn;
- ver->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn;
- normalize_v3(ver->n);
- //if (ob->transflag & OB_NEG_SCALE) negate_v3(ver->n);
-
- if (need_orco) {
- ver->orco= orco;
- orco+=3;
- }
- }
-
- index= dl->index;
- for (a=0; a<dl->parts; a++, index+=4) {
-
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= RE_findOrAddVert(obr, index[0]);
- vlr->v2= RE_findOrAddVert(obr, index[1]);
- vlr->v3= RE_findOrAddVert(obr, index[2]);
- vlr->v4 = NULL;
-
- if (negative_scale)
- normal_tri_v3(vlr->n, vlr->v1->co, vlr->v2->co, vlr->v3->co);
- else
- normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co);
-
- vlr->mat= ma;
- vlr->flag= ME_SMOOTH;
- vlr->ec= 0;
-
- /* mball -too bad- always has triangles, because quads can be non-planar */
- if (index[3] && index[3]!=index[2]) {
- vlr1= RE_findOrAddVlak(obr, obr->totvlak++);
- vlakindex= vlr1->index;
- *vlr1= *vlr;
- vlr1->index= vlakindex;
- vlr1->v2= vlr1->v3;
- vlr1->v3= RE_findOrAddVert(obr, index[3]);
- if (negative_scale)
- normal_tri_v3(vlr1->n, vlr1->v1->co, vlr1->v2->co, vlr1->v3->co);
- else
- normal_tri_v3(vlr1->n, vlr1->v3->co, vlr1->v2->co, vlr1->v1->co);
- }
- }
-
- /* enforce display lists remade */
- BKE_displist_free(&dispbase);
-}
-
-/* ------------------------------------------------------------------------- */
-/* Surfaces and Curves */
-/* ------------------------------------------------------------------------- */
-
-/* returns amount of vertices added for orco */
-static int dl_surf_to_renderdata(ObjectRen *obr, DispList *dl, Material **matar, float *orco, float mat[4][4])
-{
- VertRen *v1, *v2, *v3, *v4, *ver;
- VlakRen *vlr, *vlr1, *vlr2, *vlr3;
- float *data, n1[3];
- int u, v, orcoret= 0;
- int p1, p2, p3, p4, a;
- int sizeu, nsizeu, sizev, nsizev;
- int startvert, startvlak;
-
- startvert= obr->totvert;
- nsizeu = sizeu = dl->parts; nsizev = sizev = dl->nr;
-
- data= dl->verts;
- for (u = 0; u < sizeu; u++) {
- v1 = RE_findOrAddVert(obr, obr->totvert++); /* save this for possible V wrapping */
- copy_v3_v3(v1->co, data); data += 3;
- if (orco) {
- v1->orco= orco; orco+= 3; orcoret++;
- }
- mul_m4_v3(mat, v1->co);
-
- for (v = 1; v < sizev; v++) {
- ver= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, data); data += 3;
- if (orco) {
- ver->orco= orco; orco+= 3; orcoret++;
- }
- mul_m4_v3(mat, ver->co);
- }
- /* if V-cyclic, add extra vertices at end of the row */
- if (dl->flag & DL_CYCL_U) {
- ver= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, v1->co);
- if (orco) {
- ver->orco= orco; orco+=3; orcoret++; //orcobase + 3*(u*sizev + 0);
- }
- }
- }
-
- /* Done before next loop to get corner vert */
- if (dl->flag & DL_CYCL_U) nsizev++;
- if (dl->flag & DL_CYCL_V) nsizeu++;
-
- /* if U cyclic, add extra row at end of column */
- if (dl->flag & DL_CYCL_V) {
- for (v = 0; v < nsizev; v++) {
- v1= RE_findOrAddVert(obr, startvert + v);
- ver= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, v1->co);
- if (orco) {
- ver->orco= orco; orco+=3; orcoret++; //ver->orco= orcobase + 3*(0*sizev + v);
- }
- }
- }
-
- sizeu = nsizeu;
- sizev = nsizev;
-
- startvlak= obr->totvlak;
-
- for (u = 0; u < sizeu - 1; u++) {
- p1 = startvert + u * sizev; /* walk through face list */
- p2 = p1 + 1;
- p3 = p2 + sizev;
- p4 = p3 - 1;
-
- for (v = 0; v < sizev - 1; v++) {
- v1= RE_findOrAddVert(obr, p1);
- v2= RE_findOrAddVert(obr, p2);
- v3= RE_findOrAddVert(obr, p3);
- v4= RE_findOrAddVert(obr, p4);
-
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= v1; vlr->v2= v2; vlr->v3= v3; vlr->v4= v4;
-
- normal_quad_v3(n1, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
-
- copy_v3_v3(vlr->n, n1);
-
- vlr->mat= matar[ dl->col];
- vlr->ec= ME_V1V2+ME_V2V3;
- vlr->flag= dl->rt;
-
- add_v3_v3(v1->n, n1);
- add_v3_v3(v2->n, n1);
- add_v3_v3(v3->n, n1);
- add_v3_v3(v4->n, n1);
-
- p1++; p2++; p3++; p4++;
- }
- }
- /* fix normals for U resp. V cyclic faces */
- sizeu--; sizev--; /* dec size for face array */
- if (dl->flag & DL_CYCL_V) {
-
- for (v = 0; v < sizev; v++) {
- /* optimize! :*/
- vlr= RE_findOrAddVlak(obr, UVTOINDEX(sizeu - 1, v));
- vlr1= RE_findOrAddVlak(obr, UVTOINDEX(0, v));
- add_v3_v3(vlr1->v1->n, vlr->n);
- add_v3_v3(vlr1->v2->n, vlr->n);
- add_v3_v3(vlr->v3->n, vlr1->n);
- add_v3_v3(vlr->v4->n, vlr1->n);
- }
- }
- if (dl->flag & DL_CYCL_U) {
-
- for (u = 0; u < sizeu; u++) {
- /* optimize! :*/
- vlr= RE_findOrAddVlak(obr, UVTOINDEX(u, 0));
- vlr1= RE_findOrAddVlak(obr, UVTOINDEX(u, sizev-1));
- add_v3_v3(vlr1->v2->n, vlr->n);
- add_v3_v3(vlr1->v3->n, vlr->n);
- add_v3_v3(vlr->v1->n, vlr1->n);
- add_v3_v3(vlr->v4->n, vlr1->n);
- }
- }
-
- /* last vertex is an extra case:
- *
- * ^ ()----()----()----()
- * | | | || |
- * u | |(0,n)||(0,0)|
- * | | || |
- * ()====()====[]====()
- * | | || |
- * | |(m,n)||(m,0)|
- * | | || |
- * ()----()----()----()
- * v ->
- *
- * vertex [] is no longer shared, therefore distribute
- * normals of the surrounding faces to all of the duplicates of []
- */
-
- if ((dl->flag & DL_CYCL_V) && (dl->flag & DL_CYCL_U)) {
- vlr= RE_findOrAddVlak(obr, UVTOINDEX(sizeu - 1, sizev - 1)); /* (m, n) */
- vlr1= RE_findOrAddVlak(obr, UVTOINDEX(0, 0)); /* (0, 0) */
- add_v3_v3v3(n1, vlr->n, vlr1->n);
- vlr2= RE_findOrAddVlak(obr, UVTOINDEX(0, sizev-1)); /* (0, n) */
- add_v3_v3(n1, vlr2->n);
- vlr3= RE_findOrAddVlak(obr, UVTOINDEX(sizeu-1, 0)); /* (m, 0) */
- add_v3_v3(n1, vlr3->n);
- copy_v3_v3(vlr->v3->n, n1);
- copy_v3_v3(vlr1->v1->n, n1);
- copy_v3_v3(vlr2->v2->n, n1);
- copy_v3_v3(vlr3->v4->n, n1);
- }
- for (a = startvert; a < obr->totvert; a++) {
- ver= RE_findOrAddVert(obr, a);
- normalize_v3(ver->n);
- }
-
-
- return orcoret;
-}
-
-static void init_render_dm(DerivedMesh *dm, Render *re, ObjectRen *obr,
- int timeoffset, float *orco, float mat[4][4])
-{
- Object *ob= obr->ob;
- int a, end, totvert, vertofs;
- short mat_iter;
- VertRen *ver;
- VlakRen *vlr;
- MVert *mvert = NULL;
- MFace *mface;
- Material *ma;
-#ifdef WITH_FREESTYLE
- const int *index_mf_to_mpoly = NULL;
- const int *index_mp_to_orig = NULL;
- FreestyleFace *ffa = NULL;
-#endif
- /* Curve *cu= ELEM(ob->type, OB_FONT, OB_CURVE) ? ob->data : NULL; */
-
- mvert= dm->getVertArray(dm);
- totvert= dm->getNumVerts(dm);
-
- for (a=0; a<totvert; a++, mvert++) {
- ver= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, mvert->co);
- mul_m4_v3(mat, ver->co);
-
- if (orco) {
- ver->orco= orco;
- orco+=3;
- }
- }
-
- if (!timeoffset) {
- /* store customdata names, because DerivedMesh is freed */
- RE_set_customdata_names(obr, &dm->faceData);
-
- /* still to do for keys: the correct local texture coordinate */
-
- /* faces in order of color blocks */
- vertofs= obr->totvert - totvert;
- for (mat_iter= 0; (mat_iter < ob->totcol || (mat_iter==0 && ob->totcol==0)); mat_iter++) {
-
- ma= give_render_material(re, ob, mat_iter+1);
- end= dm->getNumTessFaces(dm);
- mface= dm->getTessFaceArray(dm);
-
-#ifdef WITH_FREESTYLE
- if (ob->type == OB_MESH) {
- Mesh *me= ob->data;
- index_mf_to_mpoly= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
- index_mp_to_orig= dm->getPolyDataArray(dm, CD_ORIGINDEX);
- ffa= CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE);
- }
-#endif
-
- for (a=0; a<end; a++, mface++) {
- int v1, v2, v3, v4, flag;
-
- if (mface->mat_nr == mat_iter) {
- float len;
-
- v1= mface->v1;
- v2= mface->v2;
- v3= mface->v3;
- v4= mface->v4;
- flag= mface->flag & ME_SMOOTH;
-
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= RE_findOrAddVert(obr, vertofs+v1);
- vlr->v2= RE_findOrAddVert(obr, vertofs+v2);
- vlr->v3= RE_findOrAddVert(obr, vertofs+v3);
- if (v4) vlr->v4= RE_findOrAddVert(obr, vertofs+v4);
- else vlr->v4 = NULL;
-
- /* render normals are inverted in render */
- if (vlr->v4)
- len= normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- else
- len= normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co);
-
- vlr->mat= ma;
- vlr->flag= flag;
- vlr->ec= 0; /* mesh edges rendered separately */
-#ifdef WITH_FREESTYLE
- if (ffa) {
- int index = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a) : a;
- vlr->freestyle_face_mark= (ffa[index].flag & FREESTYLE_FACE_MARK) ? 1 : 0;
- }
- else {
- vlr->freestyle_face_mark= 0;
- }
-#endif
-
- if (len==0) obr->totvlak--;
- else {
- CustomDataLayer *layer;
- MTFace *mtface, *mtf;
- MCol *mcol, *mc;
- int index, mtfn= 0, mcn= 0;
- char *name;
-
- for (index=0; index<dm->faceData.totlayer; index++) {
- layer= &dm->faceData.layers[index];
- name= layer->name;
-
- if (layer->type == CD_MTFACE && mtfn < MAX_MTFACE) {
- mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1);
- mtface= (MTFace*)layer->data;
- *mtf= mtface[a];
- }
- else if (layer->type == CD_MCOL && mcn < MAX_MCOL) {
- mc= RE_vlakren_get_mcol(obr, vlr, mcn++, &name, 1);
- mcol= (MCol*)layer->data;
- memcpy(mc, &mcol[a*4], sizeof(MCol)*4);
- }
- }
- }
- }
- }
- }
-
- /* Normals */
- calc_vertexnormals(re, obr, 1, 0, 0);
- }
-
-}
-
-static void init_render_surf(Render *re, ObjectRen *obr, int timeoffset)
-{
- Object *ob= obr->ob;
- Nurb *nu = NULL;
- Curve *cu;
- ListBase displist= {NULL, NULL};
- DispList *dl;
- Material **matar;
- float *orco=NULL, mat[4][4];
- int a, totmat;
- bool need_orco = false;
- DerivedMesh *dm= NULL;
-
- cu= ob->data;
- nu= cu->nurb.first;
- if (nu == NULL) return;
-
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat, mat);
-
- /* material array */
- totmat= ob->totcol+1;
- matar= MEM_callocN(sizeof(Material*)*totmat, "init_render_surf matar");
-
- for (a=0; a<totmat; a++) {
- matar[a]= give_render_material(re, ob, a+1);
-
- if (matar[a] && matar[a]->texco & TEXCO_ORCO)
- need_orco= 1;
- }
-
- if (ob->parent && (ob->parent->type==OB_LATTICE)) need_orco= 1;
-
- BKE_displist_make_surf(re->scene, ob, &displist, &dm, 1, 0, 1);
-
- if (dm) {
- if (need_orco) {
- orco = get_object_orco(re, ob);
- if (!orco) {
- orco= BKE_displist_make_orco(re->scene, ob, dm, true, true);
- if (orco) {
- set_object_orco(re, ob, orco);
- }
- }
- }
-
- init_render_dm(dm, re, obr, timeoffset, orco, mat);
- dm->release(dm);
- }
- else {
- if (need_orco) {
- orco = get_object_orco(re, ob);
- if (!orco) {
- orco = BKE_curve_surf_make_orco(ob);
- set_object_orco(re, ob, orco);
- }
- }
-
- /* walk along displaylist and create rendervertices/-faces */
- for (dl=displist.first; dl; dl=dl->next) {
- /* watch out: u ^= y, v ^= x !! */
- if (dl->type==DL_SURF)
- orco+= 3*dl_surf_to_renderdata(obr, dl, matar, orco, mat);
- }
- }
-
- BKE_displist_free(&displist);
-
- MEM_freeN(matar);
-}
-
-static void init_render_curve(Render *re, ObjectRen *obr, int timeoffset)
-{
- Object *ob= obr->ob;
- Curve *cu;
- VertRen *ver;
- VlakRen *vlr;
- DispList *dl;
- DerivedMesh *dm = NULL;
- ListBase disp={NULL, NULL};
- Material **matar;
- float *data, *fp, *orco=NULL;
- float n[3], mat[4][4], nmat[4][4];
- int nr, startvert, a, b, negative_scale;
- bool need_orco = false;
- int totmat;
-
- cu= ob->data;
- if (ob->type==OB_FONT && cu->str==NULL) return;
- else if (ob->type==OB_CURVE && cu->nurb.first==NULL) return;
-
- BKE_displist_make_curveTypes_forRender(re->scene, ob, &disp, &dm, false, true);
- dl= disp.first;
- if (dl==NULL) return;
-
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat, mat);
- negative_scale = is_negative_m4(mat);
-
- /* local object -> world space transform for normals */
- transpose_m4_m4(nmat, mat);
- invert_m4(nmat);
-
- /* material array */
- totmat= ob->totcol+1;
- matar= MEM_callocN(sizeof(Material*)*totmat, "init_render_surf matar");
-
- for (a=0; a<totmat; a++) {
- matar[a]= give_render_material(re, ob, a+1);
-
- if (matar[a] && matar[a]->texco & TEXCO_ORCO)
- need_orco= 1;
- }
-
- if (dm) {
- if (need_orco) {
- orco = get_object_orco(re, ob);
- if (!orco) {
- orco = BKE_displist_make_orco(re->scene, ob, dm, true, true);
- if (orco) {
- set_object_orco(re, ob, orco);
- }
- }
- }
-
- init_render_dm(dm, re, obr, timeoffset, orco, mat);
- dm->release(dm);
- }
- else {
- if (need_orco) {
- orco = get_object_orco(re, ob);
- if (!orco) {
- orco = BKE_curve_make_orco(re->scene, ob, NULL);
- set_object_orco(re, ob, orco);
- }
- }
-
- while (dl) {
- if (dl->col > ob->totcol) {
- /* pass */
- }
- else if (dl->type==DL_INDEX3) {
- const int *index;
-
- startvert= obr->totvert;
- data= dl->verts;
-
- for (a=0; a<dl->nr; a++, data+=3) {
- ver= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, data);
-
- mul_m4_v3(mat, ver->co);
-
- if (orco) {
- ver->orco = orco;
- orco += 3;
- }
- }
-
- if (timeoffset==0) {
- float tmp[3];
- const int startvlak= obr->totvlak;
-
- zero_v3(n);
- index= dl->index;
- for (a=0; a<dl->parts; a++, index+=3) {
- int v1 = index[0], v2 = index[2], v3 = index[1];
- float *co1 = &dl->verts[v1 * 3],
- *co2 = &dl->verts[v2 * 3],
- *co3 = &dl->verts[v3 * 3];
-
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= RE_findOrAddVert(obr, startvert + v1);
- vlr->v2= RE_findOrAddVert(obr, startvert + v2);
- vlr->v3= RE_findOrAddVert(obr, startvert + v3);
- vlr->v4= NULL;
-
- /* to prevent float accuracy issues, we calculate normal in local object space (not world) */
- if (normal_tri_v3(tmp, co1, co2, co3) > FLT_EPSILON) {
- if (negative_scale == false) {
- add_v3_v3(n, tmp);
- }
- else {
- sub_v3_v3(n, tmp);
- }
- }
-
- vlr->mat= matar[ dl->col ];
- vlr->flag= 0;
- vlr->ec= 0;
- }
-
- /* transform normal to world space */
- mul_m4_v3(nmat, n);
- normalize_v3(n);
-
- /* vertex normals */
- for (a= startvlak; a<obr->totvlak; a++) {
- vlr= RE_findOrAddVlak(obr, a);
-
- copy_v3_v3(vlr->n, n);
- add_v3_v3(vlr->v1->n, vlr->n);
- add_v3_v3(vlr->v3->n, vlr->n);
- add_v3_v3(vlr->v2->n, vlr->n);
- }
- for (a=startvert; a<obr->totvert; a++) {
- ver= RE_findOrAddVert(obr, a);
- normalize_v3(ver->n);
- }
- }
- }
- else if (dl->type==DL_SURF) {
-
- /* cyclic U means an extruded full circular curve, we skip bevel splitting then */
- if (dl->flag & DL_CYCL_U) {
- orco+= 3*dl_surf_to_renderdata(obr, dl, matar, orco, mat);
- }
- else {
- int p1, p2, p3, p4;
-
- fp= dl->verts;
- startvert= obr->totvert;
- nr= dl->nr*dl->parts;
-
- while (nr--) {
- ver= RE_findOrAddVert(obr, obr->totvert++);
-
- copy_v3_v3(ver->co, fp);
- mul_m4_v3(mat, ver->co);
- fp+= 3;
-
- if (orco) {
- ver->orco = orco;
- orco += 3;
- }
- }
-
- if (dl->flag & DL_CYCL_V && orco) {
- fp = dl->verts;
- nr = dl->nr;
- while (nr--) {
- ver = RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, fp);
- mul_m4_v3(mat, ver->co);
- ver->orco = orco;
- fp += 3;
- orco += 3;
- }
- }
-
- if (dl->bevel_split || timeoffset == 0) {
- const int startvlak= obr->totvlak;
-
- for (a=0; a<dl->parts; a++) {
-
- if (BKE_displist_surfindex_get(dl, a, &b, &p1, &p2, &p3, &p4)==0)
- break;
-
- p1+= startvert;
- p2+= startvert;
- p3+= startvert;
- p4+= startvert;
-
- if (dl->flag & DL_CYCL_V && orco && a == dl->parts - 1) {
- p3 = p1 + dl->nr;
- p4 = p2 + dl->nr;
- }
-
- for (; b<dl->nr; b++) {
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- /* important 1 offset in order is kept [#24913] */
- vlr->v1= RE_findOrAddVert(obr, p2);
- vlr->v2= RE_findOrAddVert(obr, p1);
- vlr->v3= RE_findOrAddVert(obr, p3);
- vlr->v4= RE_findOrAddVert(obr, p4);
- vlr->ec= ME_V2V3+ME_V3V4;
- if (a==0) vlr->ec+= ME_V1V2;
-
- vlr->flag= dl->rt;
-
- normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- vlr->mat= matar[ dl->col ];
-
- p4= p3;
- p3++;
- p2= p1;
- p1++;
- }
- }
-
- if (dl->bevel_split) {
- for (a = 0; a < dl->parts - 1 + !!(dl->flag & DL_CYCL_V); a++) {
- if (BLI_BITMAP_TEST(dl->bevel_split, a)) {
- split_v_renderfaces(
- obr, startvlak, startvert, dl->parts, dl->nr, a,
- /* intentionally swap (v, u) --> (u, v) */
- dl->flag & DL_CYCL_V, dl->flag & DL_CYCL_U);
- }
- }
- }
-
- /* vertex normals */
- for (a= startvlak; a<obr->totvlak; a++) {
- vlr= RE_findOrAddVlak(obr, a);
-
- add_v3_v3(vlr->v1->n, vlr->n);
- add_v3_v3(vlr->v3->n, vlr->n);
- add_v3_v3(vlr->v2->n, vlr->n);
- add_v3_v3(vlr->v4->n, vlr->n);
- }
- for (a=startvert; a<obr->totvert; a++) {
- ver= RE_findOrAddVert(obr, a);
- normalize_v3(ver->n);
- }
- }
- }
- }
-
- dl= dl->next;
- }
- }
-
- BKE_displist_free(&disp);
-
- MEM_freeN(matar);
-}
-
-/* ------------------------------------------------------------------------- */
-/* Mesh */
-/* ------------------------------------------------------------------------- */
-
-struct edgesort {
- unsigned int v1, v2;
- int f;
- unsigned int i1, i2;
-};
-
-/* edges have to be added with lowest index first for sorting */
-static void to_edgesort(struct edgesort *ed,
- unsigned int i1, unsigned int i2,
- unsigned int v1, unsigned int v2, int f)
-{
- if (v1 > v2) {
- SWAP(unsigned int, v1, v2);
- SWAP(unsigned int, i1, i2);
- }
-
- ed->v1= v1;
- ed->v2= v2;
- ed->i1= i1;
- ed->i2= i2;
- ed->f = f;
-}
-
-static int vergedgesort(const void *v1, const void *v2)
-{
- const struct edgesort *x1=v1, *x2=v2;
-
- if ( x1->v1 > x2->v1) return 1;
- else if ( x1->v1 < x2->v1) return -1;
- else if ( x1->v2 > x2->v2) return 1;
- else if ( x1->v2 < x2->v2) return -1;
-
- return 0;
-}
-
-static struct edgesort *make_mesh_edge_lookup(DerivedMesh *dm, int *totedgesort)
-{
- MFace *mf, *mface;
- MTFace *tface=NULL;
- struct edgesort *edsort, *ed;
- unsigned int *mcol=NULL;
- int a, totedge=0, totface;
-
- mface= dm->getTessFaceArray(dm);
- totface= dm->getNumTessFaces(dm);
- tface= dm->getTessFaceDataArray(dm, CD_MTFACE);
- mcol= dm->getTessFaceDataArray(dm, CD_MCOL);
-
- if (mcol==NULL && tface==NULL) return NULL;
-
- /* make sorted table with edges and face indices in it */
- for (a= totface, mf= mface; a>0; a--, mf++) {
- totedge += mf->v4 ? 4 : 3;
- }
-
- if (totedge==0)
- return NULL;
-
- ed= edsort= MEM_callocN(totedge*sizeof(struct edgesort), "edgesort");
-
- for (a=0, mf=mface; a<totface; a++, mf++) {
- to_edgesort(ed++, 0, 1, mf->v1, mf->v2, a);
- to_edgesort(ed++, 1, 2, mf->v2, mf->v3, a);
- if (mf->v4) {
- to_edgesort(ed++, 2, 3, mf->v3, mf->v4, a);
- to_edgesort(ed++, 3, 0, mf->v4, mf->v1, a);
- }
- else {
- to_edgesort(ed++, 2, 3, mf->v3, mf->v1, a);
- }
- }
-
- qsort(edsort, totedge, sizeof(struct edgesort), vergedgesort);
-
- *totedgesort= totedge;
-
- return edsort;
-}
-
-static void use_mesh_edge_lookup(ObjectRen *obr, DerivedMesh *dm, MEdge *medge, VlakRen *vlr, struct edgesort *edgetable, int totedge)
-{
- struct edgesort ed, *edp;
- CustomDataLayer *layer;
- MTFace *mtface, *mtf;
- MCol *mcol, *mc;
- int index, mtfn, mcn;
- char *name;
-
- if (medge->v1 < medge->v2) {
- ed.v1= medge->v1;
- ed.v2= medge->v2;
- }
- else {
- ed.v1= medge->v2;
- ed.v2= medge->v1;
- }
-
- edp= bsearch(&ed, edgetable, totedge, sizeof(struct edgesort), vergedgesort);
-
- /* since edges have different index ordering, we have to duplicate mcol and tface */
- if (edp) {
- mtfn= mcn= 0;
-
- for (index=0; index<dm->faceData.totlayer; index++) {
- layer= &dm->faceData.layers[index];
- name= layer->name;
-
- if (layer->type == CD_MTFACE && mtfn < MAX_MTFACE) {
- mtface= &((MTFace*)layer->data)[edp->f];
- mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1);
-
- *mtf= *mtface;
-
- memcpy(mtf->uv[0], mtface->uv[edp->i1], sizeof(float)*2);
- memcpy(mtf->uv[1], mtface->uv[edp->i2], sizeof(float)*2);
- memcpy(mtf->uv[2], mtface->uv[1], sizeof(float)*2);
- memcpy(mtf->uv[3], mtface->uv[1], sizeof(float)*2);
- }
- else if (layer->type == CD_MCOL && mcn < MAX_MCOL) {
- mcol= &((MCol*)layer->data)[edp->f*4];
- mc= RE_vlakren_get_mcol(obr, vlr, mcn++, &name, 1);
-
- mc[0]= mcol[edp->i1];
- mc[1]= mc[2]= mc[3]= mcol[edp->i2];
- }
- }
- }
-}
-
-static void free_camera_inside_volumes(Render *re)
-{
- BLI_freelistN(&re->render_volumes_inside);
-}
-
-static void init_camera_inside_volumes(Render *re)
-{
- ObjectInstanceRen *obi;
- VolumeOb *vo;
- /* coordinates are all in camera space, so camera coordinate is zero. we also
- * add an offset for the clip start, however note that with clip start it's
- * actually impossible to do a single 'inside' test, since there will not be
- * a single point where all camera rays start from, though for small clip start
- * they will be close together. */
- float co[3] = {0.f, 0.f, -re->clipsta};
-
- for (vo= re->volumes.first; vo; vo= vo->next) {
- for (obi= re->instancetable.first; obi; obi= obi->next) {
- if (obi->obr == vo->obr) {
- if (point_inside_volume_objectinstance(re, obi, co)) {
- MatInside *mi;
-
- mi = MEM_mallocN(sizeof(MatInside), "camera inside material");
- mi->ma = vo->ma;
- mi->obi = obi;
-
- BLI_addtail(&(re->render_volumes_inside), mi);
- }
- }
- }
- }
-
-
-#if 0 /* debug */
- {
- MatInside *m;
- for (m = re->render_volumes_inside.first; m; m = m->next) {
- printf("matinside: ma: %s\n", m->ma->id.name + 2);
- }
- }
-#endif
-}
-
-static void add_volume(Render *re, ObjectRen *obr, Material *ma)
-{
- struct VolumeOb *vo;
-
- vo = MEM_mallocN(sizeof(VolumeOb), "volume object");
-
- vo->ma = ma;
- vo->obr = obr;
-
- BLI_addtail(&re->volumes, vo);
-}
-
-#ifdef WITH_FREESTYLE
-static EdgeHash *make_freestyle_edge_mark_hash(DerivedMesh *dm)
-{
- EdgeHash *edge_hash= NULL;
- FreestyleEdge *fed;
- MEdge *medge;
- int totedge, a;
-
- medge = dm->getEdgeArray(dm);
- totedge = dm->getNumEdges(dm);
- fed = dm->getEdgeDataArray(dm, CD_FREESTYLE_EDGE);
- if (fed) {
- edge_hash = BLI_edgehash_new(__func__);
- for (a = 0; a < totedge; a++) {
- if (fed[a].flag & FREESTYLE_EDGE_MARK)
- BLI_edgehash_insert(edge_hash, medge[a].v1, medge[a].v2, medge+a);
- }
- }
- return edge_hash;
-}
-
-static bool has_freestyle_edge_mark(EdgeHash *edge_hash, int v1, int v2)
-{
- MEdge *medge= BLI_edgehash_lookup(edge_hash, v1, v2);
- return (!medge) ? 0 : 1;
-}
-#endif
-
-static void init_render_mesh(Render *re, ObjectRen *obr, int timeoffset)
-{
- Object *ob= obr->ob;
- Mesh *me;
- MVert *mvert = NULL;
- MFace *mface;
- VlakRen *vlr; //, *vlr1;
- VertRen *ver;
- Material *ma;
- DerivedMesh *dm;
- CustomDataMask mask;
- float xn, yn, zn, imat[3][3], mat[4][4]; //nor[3],
- float *orco = NULL;
- short (*loop_nors)[4][3] = NULL;
- bool need_orco = false, need_stress = false, need_tangent = false, need_origindex = false;
- bool need_nmap_tangent_concrete = false;
- int a, a1, ok, vertofs;
- int end, totvert = 0;
- bool do_autosmooth = false, do_displace = false;
- bool use_original_normals = false;
- int recalc_normals = 0; /* false by default */
- int negative_scale;
-#ifdef WITH_FREESTYLE
- FreestyleFace *ffa;
-#endif
-
- me= ob->data;
-
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat, mat);
- copy_m3_m4(imat, ob->imat);
- negative_scale= is_negative_m4(mat);
-
- need_orco= 0;
- for (a=1; a<=ob->totcol; a++) {
- ma= give_render_material(re, ob, a);
- if (ma) {
- if (ma->texco & (TEXCO_ORCO|TEXCO_STRESS))
- need_orco= 1;
- if (ma->texco & TEXCO_STRESS)
- need_stress= 1;
- /* normalmaps, test if tangents needed, separated from shading */
- if (ma->mode_l & MA_TANGENT_V) {
- need_tangent= 1;
- if (me->mtpoly==NULL)
- need_orco= 1;
- }
- if (ma->mode_l & MA_NORMAP_TANG) {
- if (me->mtpoly==NULL) {
- need_orco= 1;
- }
- need_tangent= 1;
- }
- if (ma->mode2_l & MA_TANGENT_CONCRETE) {
- need_nmap_tangent_concrete = true;
- }
- }
- }
-
- if (re->flag & R_NEED_TANGENT) {
- /* exception for tangent space baking */
- if (me->mtpoly==NULL) {
- need_orco= 1;
- }
- need_tangent= 1;
- }
-
- /* check autosmooth and displacement, we then have to skip only-verts optimize
- * Note: not sure what we want to give higher priority, currently do_displace
- * takes precedence over do_autosmooth.
- */
- do_displace = test_for_displace(re, ob);
- do_autosmooth = ((me->flag & ME_AUTOSMOOTH) != 0) && !do_displace;
- if (do_autosmooth || do_displace)
- timeoffset = 0;
-
- /* origindex currently used when using autosmooth, or baking to vertex colors. */
- need_origindex = (do_autosmooth || ((re->flag & R_BAKING) && (re->r.bake_flag & R_BAKE_VCOL)));
-
- mask = CD_MASK_RENDER_INTERNAL;
- if (!timeoffset)
- if (need_orco)
- mask |= CD_MASK_ORCO;
-
-#ifdef WITH_FREESTYLE
- mask |= CD_MASK_ORIGINDEX | CD_MASK_FREESTYLE_EDGE | CD_MASK_FREESTYLE_FACE;
-#endif
-
- if (re->r.scemode & R_VIEWPORT_PREVIEW)
- dm= mesh_create_derived_view(re->scene, ob, mask);
- else
- dm= mesh_create_derived_render(re->scene, ob, mask);
- if (dm==NULL) return; /* in case duplicated object fails? */
-
- mvert= dm->getVertArray(dm);
- totvert= dm->getNumVerts(dm);
-
- if (totvert == 0) {
- dm->release(dm);
- return;
- }
-
- if (mask & CD_MASK_ORCO) {
- orco = get_object_orco(re, ob);
- if (!orco) {
- orco= dm->getVertDataArray(dm, CD_ORCO);
- if (orco) {
- orco= MEM_dupallocN(orco);
- set_object_orco(re, ob, orco);
- }
- }
- }
-
- /* attempt to autsmooth on original mesh, only without subsurf */
- if (do_autosmooth && me->totvert==totvert && me->totface==dm->getNumTessFaces(dm))
- use_original_normals= true;
-
- ma= give_render_material(re, ob, 1);
-
-
- if (ma->material_type == MA_TYPE_HALO) {
- make_render_halos(re, obr, me, totvert, mvert, ma, orco);
- }
- else {
- const int *index_vert_orig = NULL;
- const int *index_mf_to_mpoly = NULL;
- const int *index_mp_to_orig = NULL;
- if (need_origindex) {
- index_vert_orig = dm->getVertDataArray(dm, CD_ORIGINDEX);
- /* double lookup for faces -> polys */
-#ifdef WITH_FREESTYLE
- index_mf_to_mpoly = dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
- index_mp_to_orig = dm->getPolyDataArray(dm, CD_ORIGINDEX);
-#endif
- }
-
- for (a=0; a<totvert; a++, mvert++) {
- ver= RE_findOrAddVert(obr, obr->totvert++);
- copy_v3_v3(ver->co, mvert->co);
- if (do_autosmooth == false) { /* autosmooth on original unrotated data to prevent differences between frames */
- normal_short_to_float_v3(ver->n, mvert->no);
- mul_m4_v3(mat, ver->co);
- mul_transposed_m3_v3(imat, ver->n);
- normalize_v3(ver->n);
- negate_v3(ver->n);
- }
-
- if (orco) {
- ver->orco= orco;
- orco+=3;
- }
-
- if (need_origindex) {
- int *origindex;
- origindex = RE_vertren_get_origindex(obr, ver, 1);
-
- /* Use orig index array if it's available (e.g. in the presence
- * of modifiers). */
- if (index_vert_orig)
- *origindex = index_vert_orig[a];
- else
- *origindex = a;
- }
- }
-
- if (!timeoffset) {
- short (*lnp)[4][3] = NULL;
-#ifdef WITH_FREESTYLE
- EdgeHash *edge_hash;
-
- /* create a hash table of Freestyle edge marks */
- edge_hash = make_freestyle_edge_mark_hash(dm);
-#endif
-
- /* store customdata names, because DerivedMesh is freed */
- RE_set_customdata_names(obr, &dm->faceData);
-
- /* add tangent layers if we need */
- if ((ma->nmap_tangent_names_count && need_nmap_tangent_concrete) || need_tangent) {
- dm->calcLoopTangents(
- dm, need_tangent,
- (const char (*)[MAX_NAME])ma->nmap_tangent_names, ma->nmap_tangent_names_count);
- obr->tangent_mask = dm->tangent_mask;
- DM_generate_tangent_tessface_data(dm, need_nmap_tangent_concrete || need_tangent);
- }
-
- /* still to do for keys: the correct local texture coordinate */
-
- /* faces in order of color blocks */
- vertofs= obr->totvert - totvert;
- for (a1=0; (a1<ob->totcol || (a1==0 && ob->totcol==0)); a1++) {
-
- ma= give_render_material(re, ob, a1+1);
-
- /* test for 100% transparent */
- ok = 1;
- if ((ma->alpha == 0.0f) &&
- (ma->spectra == 0.0f) &&
- /* No need to test filter here, it's only active with MA_RAYTRANSP and we check against it below. */
- /* (ma->filter == 0.0f) && */
- (ma->mode & MA_TRANSP) &&
- (ma->mode & (MA_RAYTRANSP | MA_RAYMIRROR)) == 0)
- {
- ok = 0;
- /* texture on transparency? */
- for (a=0; a<MAX_MTEX; a++) {
- if (ma->mtex[a] && ma->mtex[a]->tex) {
- if (ma->mtex[a]->mapto & MAP_ALPHA) ok= 1;
- }
- }
- }
-
- /* if wire material, and we got edges, don't do the faces */
- if (ma->material_type == MA_TYPE_WIRE) {
- end= dm->getNumEdges(dm);
- if (end) ok= 0;
- }
-
- if (ok) {
- end= dm->getNumTessFaces(dm);
- mface= dm->getTessFaceArray(dm);
- if (!loop_nors && do_autosmooth &&
- (dm->getTessFaceDataArray(dm, CD_TESSLOOPNORMAL) != NULL))
- {
- lnp = loop_nors = MEM_mallocN(sizeof(*loop_nors) * end, __func__);
- }
-#ifdef WITH_FREESTYLE
- index_mf_to_mpoly= dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
- index_mp_to_orig= dm->getPolyDataArray(dm, CD_ORIGINDEX);
- ffa= CustomData_get_layer(&me->pdata, CD_FREESTYLE_FACE);
-#endif
-
- for (a=0; a<end; a++, mface++) {
- int v1, v2, v3, v4, flag;
-
- if ( mface->mat_nr==a1 ) {
- float len;
- bool reverse_verts = (negative_scale != 0 && do_autosmooth == false);
- int rev_tab[] = {reverse_verts==0 ? 0 : 2, 1, reverse_verts==0 ? 2 : 0, 3};
- v1= reverse_verts==0 ? mface->v1 : mface->v3;
- v2= mface->v2;
- v3= reverse_verts==0 ? mface->v3 : mface->v1;
- v4= mface->v4;
- flag = do_autosmooth ? ME_SMOOTH : mface->flag & ME_SMOOTH;
-
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= RE_findOrAddVert(obr, vertofs+v1);
- vlr->v2= RE_findOrAddVert(obr, vertofs+v2);
- vlr->v3= RE_findOrAddVert(obr, vertofs+v3);
- if (v4) vlr->v4 = RE_findOrAddVert(obr, vertofs+v4);
- else vlr->v4 = NULL;
-
-#ifdef WITH_FREESTYLE
- /* Freestyle edge/face marks */
- if (edge_hash) {
- int edge_mark = 0;
-
- if (has_freestyle_edge_mark(edge_hash, v1, v2)) edge_mark |= R_EDGE_V1V2;
- if (has_freestyle_edge_mark(edge_hash, v2, v3)) edge_mark |= R_EDGE_V2V3;
- if (!v4) {
- if (has_freestyle_edge_mark(edge_hash, v3, v1)) edge_mark |= R_EDGE_V3V1;
- }
- else {
- if (has_freestyle_edge_mark(edge_hash, v3, v4)) edge_mark |= R_EDGE_V3V4;
- if (has_freestyle_edge_mark(edge_hash, v4, v1)) edge_mark |= R_EDGE_V4V1;
- }
- vlr->freestyle_edge_mark= edge_mark;
- }
- if (ffa) {
- int index = (index_mf_to_mpoly) ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a) : a;
- vlr->freestyle_face_mark= (ffa[index].flag & FREESTYLE_FACE_MARK) ? 1 : 0;
- }
- else {
- vlr->freestyle_face_mark= 0;
- }
-#endif
-
- /* render normals are inverted in render */
- if (use_original_normals) {
- MFace *mf= me->mface+a;
- MVert *mv= me->mvert;
-
- if (vlr->v4)
- len= normal_quad_v3(vlr->n, mv[mf->v4].co, mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co);
- else
- len= normal_tri_v3(vlr->n, mv[mf->v3].co, mv[mf->v2].co, mv[mf->v1].co);
- }
- else {
- if (vlr->v4)
- len= normal_quad_v3(vlr->n, vlr->v4->co, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- else
- len= normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- }
-
- vlr->mat= ma;
- vlr->flag= flag;
- vlr->ec= 0; /* mesh edges rendered separately */
-
- if (len==0) obr->totvlak--;
- else {
- CustomDataLayer *layer;
- MTFace *mtface, *mtf;
- MCol *mcol, *mc;
- int index, mtfn= 0, mcn= 0, mln = 0, vindex;
- char *name;
- int nr_verts = v4!=0 ? 4 : 3;
-
- for (index=0; index<dm->faceData.totlayer; index++) {
- layer= &dm->faceData.layers[index];
- name= layer->name;
-
- if (layer->type == CD_MTFACE && mtfn < MAX_MTFACE) {
- int t;
- mtf= RE_vlakren_get_tface(obr, vlr, mtfn++, &name, 1);
- mtface= (MTFace*)layer->data;
- *mtf = mtface[a]; /* copy face info */
- for (vindex=0; vindex<nr_verts; vindex++)
- for (t=0; t<2; t++)
- mtf->uv[vindex][t]=mtface[a].uv[rev_tab[vindex]][t];
- }
- else if (layer->type == CD_MCOL && mcn < MAX_MCOL) {
- mc= RE_vlakren_get_mcol(obr, vlr, mcn++, &name, 1);
- mcol= (MCol*)layer->data;
- for (vindex=0; vindex<nr_verts; vindex++)
- mc[vindex]=mcol[a*4+rev_tab[vindex]];
- }
- else if (layer->type == CD_TANGENT) {
- if (need_nmap_tangent_concrete || need_tangent) {
- int uv_start = CustomData_get_layer_index(&dm->faceData, CD_MTFACE);
- int uv_index = CustomData_get_named_layer_index(&dm->faceData, CD_MTFACE, layer->name);
-
- /* if there are no UVs, orco tangents are in first slot */
- int n = (uv_start >= 0 && uv_index >= 0) ? uv_index - uv_start : 0;
-
- const float *tangent = (const float *) layer->data;
- float *ftang = RE_vlakren_get_nmap_tangent(obr, vlr, n, true);
-
- for (vindex=0; vindex<nr_verts; vindex++) {
- copy_v4_v4(ftang+vindex*4, tangent+a*16+rev_tab[vindex]*4);
- mul_mat3_m4_v3(mat, ftang+vindex*4);
- normalize_v3(ftang+vindex*4);
- }
- }
- }
- else if (layer->type == CD_TESSLOOPNORMAL && mln < 1) {
- if (loop_nors) {
- const short (*lnors)[4][3] = (const short (*)[4][3])layer->data;
- for (vindex = 0; vindex < 4; vindex++) {
- //print_v3("lnors[a][rev_tab[vindex]]", lnors[a][rev_tab[vindex]]);
- copy_v3_v3_short((short *)lnp[0][vindex], lnors[a][rev_tab[vindex]]);
- /* If we copy loop normals, we are doing autosmooth, so we are still
- * in object space, no need to multiply with mat!
- */
- }
- lnp++;
- }
- mln++;
- }
- }
-
- if (need_origindex) {
- /* Find original index of mpoly for this tessface. Options:
- * - Modified mesh; two-step look up from tessface -> modified mpoly -> original mpoly
- * - OR Tesselated mesh; look up from tessface -> mpoly
- * - OR Failsafe; tessface == mpoly. Could probably assert(false) in this case? */
- int *origindex;
- origindex = RE_vlakren_get_origindex(obr, vlr, 1);
- if (index_mf_to_mpoly && index_mp_to_orig)
- *origindex = DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, a);
- else if (index_mf_to_mpoly)
- *origindex = index_mf_to_mpoly[a];
- else
- *origindex = a;
- }
- }
- }
- }
- }
- }
-
-#ifdef WITH_FREESTYLE
- /* release the hash table of Freestyle edge marks */
- if (edge_hash)
- BLI_edgehash_free(edge_hash, NULL);
-#endif
-
- /* exception... we do edges for wire mode. potential conflict when faces exist... */
- end= dm->getNumEdges(dm);
- mvert= dm->getVertArray(dm);
- ma= give_render_material(re, ob, 1);
- if (end && (ma->material_type == MA_TYPE_WIRE)) {
- MEdge *medge;
- struct edgesort *edgetable;
- int totedge= 0;
- recalc_normals= 1;
-
- medge= dm->getEdgeArray(dm);
-
- /* we want edges to have UV and vcol too... */
- edgetable= make_mesh_edge_lookup(dm, &totedge);
-
- for (a1=0; a1<end; a1++, medge++) {
- if (medge->flag&ME_EDGERENDER) {
- MVert *v0 = &mvert[medge->v1];
- MVert *v1 = &mvert[medge->v2];
-
- vlr= RE_findOrAddVlak(obr, obr->totvlak++);
- vlr->v1= RE_findOrAddVert(obr, vertofs+medge->v1);
- vlr->v2= RE_findOrAddVert(obr, vertofs+medge->v2);
- vlr->v3= vlr->v2;
- vlr->v4= NULL;
-
- if (edgetable)
- use_mesh_edge_lookup(obr, dm, medge, vlr, edgetable, totedge);
-
- xn= -(v0->no[0]+v1->no[0]);
- yn= -(v0->no[1]+v1->no[1]);
- zn= -(v0->no[2]+v1->no[2]);
- /* transpose ! */
- vlr->n[0]= imat[0][0]*xn+imat[0][1]*yn+imat[0][2]*zn;
- vlr->n[1]= imat[1][0]*xn+imat[1][1]*yn+imat[1][2]*zn;
- vlr->n[2]= imat[2][0]*xn+imat[2][1]*yn+imat[2][2]*zn;
- normalize_v3(vlr->n);
-
- vlr->mat= ma;
- vlr->flag= 0;
- vlr->ec= ME_V1V2;
- }
- }
- if (edgetable)
- MEM_freeN(edgetable);
- }
- }
- }
-
- if (!timeoffset) {
- if (need_stress)
- calc_edge_stress(re, obr, me);
-
- if (do_displace) {
- calc_vertexnormals(re, obr, 1, 0, 0);
- displace(re, obr);
- recalc_normals = 0; /* Already computed by displace! */
- }
- else if (do_autosmooth) {
- recalc_normals = (loop_nors == NULL); /* Should never happen, but better be safe than sorry. */
- autosmooth(re, obr, mat, loop_nors);
- }
-
- if (recalc_normals!=0 || need_tangent!=0)
- calc_vertexnormals(re, obr, recalc_normals, need_tangent, need_nmap_tangent_concrete);
- }
-
- MEM_SAFE_FREE(loop_nors);
-
- dm->release(dm);
-}
-
-/* ------------------------------------------------------------------------- */
-/* Lamps and Shadowbuffers */
-/* ------------------------------------------------------------------------- */
-
-static void initshadowbuf(Render *re, LampRen *lar, float mat[4][4])
-{
- struct ShadBuf *shb;
- float viewinv[4][4];
-
- /* if (la->spsi<16) return; */
-
- /* memory alloc */
- shb= (struct ShadBuf *)MEM_callocN(sizeof(struct ShadBuf), "initshadbuf");
- lar->shb= shb;
-
- if (shb==NULL) return;
-
- VECCOPY(shb->co, lar->co); /* int copy */
-
- /* percentage render: keep track of min and max */
- shb->size= (lar->bufsize*re->r.size)/100;
-
- if (shb->size<512) shb->size= 512;
- else if (shb->size > lar->bufsize) shb->size= lar->bufsize;
-
- shb->size &= ~15; /* make sure its multiples of 16 */
-
- shb->samp= lar->samp;
- shb->soft= lar->soft;
- shb->shadhalostep= lar->shadhalostep;
-
- normalize_m4(mat);
- invert_m4_m4(shb->winmat, mat); /* winmat is temp */
-
- /* matrix: combination of inverse view and lampmat */
- /* calculate again: the ortho-render has no correct viewinv */
- invert_m4_m4(viewinv, re->viewmat);
- mul_m4_m4m4(shb->viewmat, shb->winmat, viewinv);
-
- /* projection */
- shb->d= lar->clipsta;
- shb->clipend= lar->clipend;
-
- /* bias is percentage, made 2x larger because of correction for angle of incidence */
- /* when a ray is closer to parallel of a face, bias value is increased during render */
- shb->bias= (0.02f*lar->bias)*0x7FFFFFFF;
-
- /* halfway method (average of first and 2nd z) reduces bias issues */
- if (ELEM(lar->buftype, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP))
- shb->bias= 0.1f*shb->bias;
-
- shb->compressthresh= lar->compressthresh;
-}
-
-void area_lamp_vectors(LampRen *lar)
-{
- float xsize= 0.5f*lar->area_size, ysize= 0.5f*lar->area_sizey, multifac;
-
- /* make it smaller, so area light can be multisampled */
- multifac= 1.0f/sqrtf((float)lar->ray_totsamp);
- xsize *= multifac;
- ysize *= multifac;
-
- /* corner vectors */
- lar->area[0][0]= lar->co[0] - xsize*lar->mat[0][0] - ysize*lar->mat[1][0];
- lar->area[0][1]= lar->co[1] - xsize*lar->mat[0][1] - ysize*lar->mat[1][1];
- lar->area[0][2]= lar->co[2] - xsize*lar->mat[0][2] - ysize*lar->mat[1][2];
-
- /* corner vectors */
- lar->area[1][0]= lar->co[0] - xsize*lar->mat[0][0] + ysize*lar->mat[1][0];
- lar->area[1][1]= lar->co[1] - xsize*lar->mat[0][1] + ysize*lar->mat[1][1];
- lar->area[1][2]= lar->co[2] - xsize*lar->mat[0][2] + ysize*lar->mat[1][2];
-
- /* corner vectors */
- lar->area[2][0]= lar->co[0] + xsize*lar->mat[0][0] + ysize*lar->mat[1][0];
- lar->area[2][1]= lar->co[1] + xsize*lar->mat[0][1] + ysize*lar->mat[1][1];
- lar->area[2][2]= lar->co[2] + xsize*lar->mat[0][2] + ysize*lar->mat[1][2];
-
- /* corner vectors */
- lar->area[3][0]= lar->co[0] + xsize*lar->mat[0][0] - ysize*lar->mat[1][0];
- lar->area[3][1]= lar->co[1] + xsize*lar->mat[0][1] - ysize*lar->mat[1][1];
- lar->area[3][2]= lar->co[2] + xsize*lar->mat[0][2] - ysize*lar->mat[1][2];
- /* only for correction button size, matrix size works on energy */
- lar->areasize= lar->dist*lar->dist/(4.0f*xsize*ysize);
-}
-
-/* If lar takes more lamp data, the decoupling will be better. */
-static GroupObject *add_render_lamp(Render *re, Object *ob)
-{
- Lamp *la= ob->data;
- LampRen *lar;
- GroupObject *go;
- float mat[4][4], angle, xn, yn;
- float vec[3];
- int c;
-
- /* previewrender sets this to zero... prevent accidents */
- if (la==NULL) return NULL;
-
- /* prevent only shadow from rendering light */
- if (la->mode & LA_ONLYSHADOW)
- if ((re->r.mode & R_SHADOW)==0)
- return NULL;
-
- re->totlamp++;
-
- /* groups is used to unify support for lightgroups, this is the global lightgroup */
- go= MEM_callocN(sizeof(GroupObject), "groupobject");
- BLI_addtail(&re->lights, go);
- go->ob= ob;
- /* lamprens are in own list, for freeing */
- lar= (LampRen *)MEM_callocN(sizeof(LampRen), "lampren");
- BLI_addtail(&re->lampren, lar);
- go->lampren= lar;
-
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat, mat);
-
- copy_m4_m4(lar->lampmat, ob->obmat);
- copy_m3_m4(lar->mat, mat);
- copy_m3_m4(lar->imat, ob->imat);
-
- lar->bufsize = la->bufsize;
- lar->samp = la->samp;
- lar->buffers= la->buffers;
- if (lar->buffers==0) lar->buffers= 1;
- lar->buftype= la->buftype;
- lar->filtertype= la->filtertype;
- lar->soft = la->soft;
- lar->shadhalostep = la->shadhalostep;
- lar->clipsta = la->clipsta;
- lar->clipend = la->clipend;
-
- lar->bias = la->bias;
- lar->compressthresh = la->compressthresh;
-
- lar->type= la->type;
- lar->mode= la->mode;
-
- lar->energy= la->energy;
- if (la->mode & LA_NEG) lar->energy= -lar->energy;
-
- lar->vec[0]= -mat[2][0];
- lar->vec[1]= -mat[2][1];
- lar->vec[2]= -mat[2][2];
- normalize_v3(lar->vec);
- lar->co[0]= mat[3][0];
- lar->co[1]= mat[3][1];
- lar->co[2]= mat[3][2];
- lar->dist= la->dist;
- lar->haint= la->haint;
- lar->distkw= lar->dist*lar->dist;
- lar->r= lar->energy*la->r;
- lar->g= lar->energy*la->g;
- lar->b= lar->energy*la->b;
- lar->shdwr= la->shdwr;
- lar->shdwg= la->shdwg;
- lar->shdwb= la->shdwb;
- lar->k= la->k;
-
- /* area */
- lar->ray_samp= la->ray_samp;
- lar->ray_sampy= la->ray_sampy;
- lar->ray_sampz= la->ray_sampz;
-
- lar->area_size= la->area_size;
- lar->area_sizey= la->area_sizey;
- lar->area_sizez= la->area_sizez;
-
- lar->area_shape= la->area_shape;
-
- /* Annoying, lamp UI does this, but the UI might not have been used? - add here too.
- * make sure this matches buttons_shading.c's logic */
- if (ELEM(la->type, LA_AREA, LA_SPOT, LA_SUN, LA_LOCAL) && (la->mode & LA_SHAD_RAY))
- if (ELEM(la->type, LA_SPOT, LA_SUN, LA_LOCAL))
- if (la->ray_samp_method == LA_SAMP_CONSTANT) la->ray_samp_method = LA_SAMP_HALTON;
-
- lar->ray_samp_method= la->ray_samp_method;
- lar->ray_samp_type= la->ray_samp_type;
-
- lar->adapt_thresh= la->adapt_thresh;
- lar->sunsky = NULL;
-
- if ( ELEM(lar->type, LA_SPOT, LA_LOCAL)) {
- lar->ray_totsamp= lar->ray_samp*lar->ray_samp;
- lar->area_shape = LA_AREA_SQUARE;
- lar->area_sizey= lar->area_size;
- }
- else if (lar->type==LA_AREA) {
- switch (lar->area_shape) {
- case LA_AREA_SQUARE:
- lar->ray_totsamp= lar->ray_samp*lar->ray_samp;
- lar->ray_sampy= lar->ray_samp;
- lar->area_sizey= lar->area_size;
- break;
- case LA_AREA_RECT:
- lar->ray_totsamp= lar->ray_samp*lar->ray_sampy;
- break;
- case LA_AREA_CUBE:
- lar->ray_totsamp= lar->ray_samp*lar->ray_samp*lar->ray_samp;
- lar->ray_sampy= lar->ray_samp;
- lar->ray_sampz= lar->ray_samp;
- lar->area_sizey= lar->area_size;
- lar->area_sizez= lar->area_size;
- break;
- case LA_AREA_BOX:
- lar->ray_totsamp= lar->ray_samp*lar->ray_sampy*lar->ray_sampz;
- break;
- }
-
- area_lamp_vectors(lar);
- init_jitter_plane(lar); /* subsamples */
- }
- else if (lar->type==LA_SUN) {
- lar->ray_totsamp= lar->ray_samp*lar->ray_samp;
- lar->area_shape = LA_AREA_SQUARE;
- lar->area_sizey= lar->area_size;
-
- if ((la->sun_effect_type & LA_SUN_EFFECT_SKY) ||
- (la->sun_effect_type & LA_SUN_EFFECT_AP))
- {
- lar->sunsky = (struct SunSky*)MEM_callocN(sizeof(struct SunSky), "sunskyren");
- lar->sunsky->effect_type = la->sun_effect_type;
-
- copy_v3_v3(vec, ob->obmat[2]);
- normalize_v3(vec);
-
- InitSunSky(
- lar->sunsky, la->atm_turbidity, vec, la->horizon_brightness,
- la->spread, la->sun_brightness, la->sun_size, la->backscattered_light,
- la->skyblendfac, la->skyblendtype, la->sky_exposure, la->sky_colorspace);
- InitAtmosphere(
- lar->sunsky, la->sun_intensity, 1.0, 1.0, la->atm_inscattering_factor, la->atm_extinction_factor,
- la->atm_distance_factor);
- }
- }
- else lar->ray_totsamp= 0;
-
- lar->spotsi= la->spotsize;
- if (lar->mode & LA_HALO) {
- if (lar->spotsi > DEG2RADF(170.0f)) lar->spotsi = DEG2RADF(170.0f);
- }
- lar->spotsi= cosf(lar->spotsi * 0.5f);
- lar->spotbl= (1.0f-lar->spotsi)*la->spotblend;
-
- memcpy(lar->mtex, la->mtex, MAX_MTEX*sizeof(void *));
-
- lar->lay = ob->lay & 0xFFFFFF; /* higher 8 bits are localview layers */
-
- lar->falloff_type = la->falloff_type;
- lar->ld1= la->att1;
- lar->ld2= la->att2;
- lar->coeff_const= la->coeff_const;
- lar->coeff_lin= la->coeff_lin;
- lar->coeff_quad= la->coeff_quad;
- lar->curfalloff = curvemapping_copy(la->curfalloff);
-
- if (lar->curfalloff) {
- /* so threads don't conflict on init */
- curvemapping_initialize(lar->curfalloff);
- }
-
- if (lar->type==LA_SPOT) {
-
- normalize_v3(lar->imat[0]);
- normalize_v3(lar->imat[1]);
- normalize_v3(lar->imat[2]);
-
- xn = saacos(lar->spotsi);
- xn = sinf(xn) / cosf(xn);
- lar->spottexfac= 1.0f/(xn);
-
- if (lar->mode & LA_ONLYSHADOW) {
- if ((lar->mode & (LA_SHAD_BUF|LA_SHAD_RAY))==0) lar->mode -= LA_ONLYSHADOW;
- }
-
- }
-
- /* set flag for spothalo en initvars */
- if ((la->type == LA_SPOT) && (la->mode & LA_HALO) &&
- (!(la->mode & LA_SHAD_BUF) || la->buftype != LA_SHADBUF_DEEP))
- {
- if (la->haint>0.0f) {
- re->flag |= R_LAMPHALO;
-
- /* camera position (0, 0, 0) rotate around lamp */
- lar->sh_invcampos[0]= -lar->co[0];
- lar->sh_invcampos[1]= -lar->co[1];
- lar->sh_invcampos[2]= -lar->co[2];
- mul_m3_v3(lar->imat, lar->sh_invcampos);
-
- /* z factor, for a normalized volume */
- angle= saacos(lar->spotsi);
- xn= lar->spotsi;
- yn = sinf(angle);
- lar->sh_zfac= yn/xn;
- /* pre-scale */
- lar->sh_invcampos[2]*= lar->sh_zfac;
-
- /* halfway shadow buffer doesn't work for volumetric effects */
- if (ELEM(lar->buftype, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP))
- lar->buftype = LA_SHADBUF_REGULAR;
-
- }
- }
- else if (la->type==LA_HEMI) {
- lar->mode &= ~(LA_SHAD_RAY|LA_SHAD_BUF);
- }
-
- for (c=0; c<MAX_MTEX; c++) {
- if (la->mtex[c] && la->mtex[c]->tex) {
- if (la->mtex[c]->mapto & LAMAP_COL)
- lar->mode |= LA_TEXTURE;
- if (la->mtex[c]->mapto & LAMAP_SHAD)
- lar->mode |= LA_SHAD_TEX;
-
- if (G.is_rendering) {
- if (re->osa) {
- if (la->mtex[c]->tex->type==TEX_IMAGE) lar->mode |= LA_OSATEX;
- }
- }
- }
- }
-
- /* old code checked for internal render (aka not yafray) */
- {
- /* to make sure we can check ray shadow easily in the render code */
- if (lar->mode & LA_SHAD_RAY) {
- if ( (re->r.mode & R_RAYTRACE)==0)
- lar->mode &= ~LA_SHAD_RAY;
- }
-
-
- if (re->r.mode & R_SHADOW) {
-
- if (la->type==LA_AREA && (lar->mode & LA_SHAD_RAY) && (lar->ray_samp_method == LA_SAMP_CONSTANT)) {
- init_jitter_plane(lar);
- }
- else if (la->type==LA_SPOT && (lar->mode & LA_SHAD_BUF) ) {
- /* Per lamp, one shadow buffer is made. */
- lar->bufflag= la->bufflag;
- copy_m4_m4(mat, ob->obmat);
- initshadowbuf(re, lar, mat); /* mat is altered */
- }
-
-
- /* this is the way used all over to check for shadow */
- if (lar->shb || (lar->mode & LA_SHAD_RAY)) {
- LampShadowSample *ls;
- LampShadowSubSample *lss;
- int a, b;
-
- memset(re->shadowsamplenr, 0, sizeof(re->shadowsamplenr));
-
- lar->shadsamp= MEM_mallocN(re->r.threads*sizeof(LampShadowSample), "lamp shadow sample");
- ls= lar->shadsamp;
-
- /* shadfacs actually mean light, let's put them to 1 to prevent unitialized accidents */
- for (a=0; a<re->r.threads; a++, ls++) {
- lss= ls->s;
- for (b=0; b<re->r.osa; b++, lss++) {
- lss->samplenr= -1; /* used to detect whether we store or read */
- lss->shadfac[0]= 1.0f;
- lss->shadfac[1]= 1.0f;
- lss->shadfac[2]= 1.0f;
- lss->shadfac[3]= 1.0f;
- }
- }
- }
- }
- }
-
- return go;
-}
-
-static bool is_object_restricted(Render *re, Object *ob)
-{
- if (re->r.scemode & R_VIEWPORT_PREVIEW)
- return (ob->restrictflag & OB_RESTRICT_VIEW) != 0;
- else
- return (ob->restrictflag & OB_RESTRICT_RENDER) != 0;
-}
-
-static bool is_object_hidden(Render *re, Object *ob)
-{
- if (is_object_restricted(re, ob))
- return true;
-
- if (re->r.scemode & R_VIEWPORT_PREVIEW) {
- /* Mesh deform cages and so on mess up the preview. To avoid the problem,
- * viewport doesn't show mesh object if its draw type is bounding box or wireframe.
- * Unless it's an active smoke domain!
- */
- ModifierData *md = NULL;
-
- if ((md = modifiers_findByType(ob, eModifierType_Smoke)) &&
- (modifier_isEnabled(re->scene, md, eModifierMode_Realtime)))
- {
- return false;
- }
- return ELEM(ob->dt, OB_BOUNDBOX, OB_WIRE);
- }
- else {
- return false;
- }
-}
-
-/* layflag: allows material group to ignore layerflag */
-static void add_lightgroup(Render *re, Group *group, int exclusive)
-{
- GroupObject *go, *gol;
-
- group->id.tag &= ~LIB_TAG_DOIT;
-
- /* it's a bit too many loops in loops... but will survive */
- /* note that 'exclusive' will remove it from the global list */
- for (go= group->gobject.first; go; go= go->next) {
- go->lampren= NULL;
-
- if (is_object_hidden(re, go->ob))
- continue;
-
- if (go->ob->lay & re->lay) {
- if (go->ob && go->ob->type==OB_LAMP) {
- for (gol= re->lights.first; gol; gol= gol->next) {
- if (gol->ob==go->ob) {
- go->lampren= gol->lampren;
- break;
- }
- }
- if (go->lampren==NULL)
- gol= add_render_lamp(re, go->ob);
- if (gol && exclusive) {
- BLI_remlink(&re->lights, gol);
- MEM_freeN(gol);
- }
- }
- }
- }
-}
-
-static void set_material_lightgroups(Render *re)
-{
- Group *group;
- Material *ma;
-
- /* not for preview render */
- if (re->scene->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))
- return;
-
- for (group= re->main->group.first; group; group=group->id.next)
- group->id.tag |= LIB_TAG_DOIT;
-
- /* it's a bit too many loops in loops... but will survive */
- /* hola! materials not in use...? */
- for (ma= re->main->mat.first; ma; ma=ma->id.next) {
- if (ma->group && (ma->group->id.tag & LIB_TAG_DOIT))
- add_lightgroup(re, ma->group, ma->mode & MA_GROUP_NOLAY);
- }
-}
-
-static void set_renderlayer_lightgroups(Render *re, Scene *sce)
-{
- SceneRenderLayer *srl;
-
- for (srl= sce->r.layers.first; srl; srl= srl->next) {
- if (srl->light_override)
- add_lightgroup(re, srl->light_override, 0);
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* World */
-/* ------------------------------------------------------------------------- */
-
-void init_render_world(Render *re)
-{
- void *wrld_prev[2] = {
- re->wrld.aotables,
- re->wrld.aosphere,
- };
-
- int a;
-
- if (re->scene && re->scene->world) {
- re->wrld = *(re->scene->world);
-
- copy_v3_v3(re->grvec, re->viewmat[2]);
- normalize_v3(re->grvec);
- copy_m3_m4(re->imat, re->viewinv);
-
- for (a=0; a<MAX_MTEX; a++)
- if (re->wrld.mtex[a] && re->wrld.mtex[a]->tex) re->wrld.skytype |= WO_SKYTEX;
-
- /* AO samples should be OSA minimum */
- if (re->osa)
- while (re->wrld.aosamp*re->wrld.aosamp < re->osa)
- re->wrld.aosamp++;
- if (!(re->r.mode & R_RAYTRACE) && (re->wrld.ao_gather_method == WO_AOGATHER_RAYTRACE))
- re->wrld.mode &= ~(WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT);
- }
- else {
- memset(&re->wrld, 0, sizeof(World));
- re->wrld.exp= 0.0f;
- re->wrld.range= 1.0f;
-
- /* for mist pass */
- re->wrld.miststa= re->clipsta;
- re->wrld.mistdist= re->clipend-re->clipsta;
- re->wrld.misi= 1.0f;
- }
-
- re->wrld.linfac= 1.0f + powf((2.0f*re->wrld.exp + 0.5f), -10);
- re->wrld.logfac= logf((re->wrld.linfac-1.0f)/re->wrld.linfac) / re->wrld.range;
-
- /* restore runtime vars, needed for viewport rendering [#36005] */
- re->wrld.aotables = wrld_prev[0];
- re->wrld.aosphere = wrld_prev[1];
-}
-
-
-
-/* ------------------------------------------------------------------------- */
-/* Object Finalization */
-/* ------------------------------------------------------------------------- */
-
-/* prevent phong interpolation for giving ray shadow errors (terminator problem) */
-static void set_phong_threshold(ObjectRen *obr)
-{
-// VertRen *ver;
- VlakRen *vlr;
- float thresh= 0.0, dot;
- int tot=0, i;
-
- /* Added check for 'pointy' situations, only dotproducts of 0.9 and larger
- * are taken into account. This threshold is meant to work on smooth geometry, not
- * for extreme cases (ton) */
-
- for (i=0; i<obr->totvlak; i++) {
- vlr= RE_findOrAddVlak(obr, i);
- if ((vlr->flag & R_SMOOTH) && (vlr->flag & R_STRAND)==0) {
- dot= dot_v3v3(vlr->n, vlr->v1->n);
- dot= ABS(dot);
- if (dot>0.9f) {
- thresh+= dot; tot++;
- }
- dot= dot_v3v3(vlr->n, vlr->v2->n);
- dot= ABS(dot);
- if (dot>0.9f) {
- thresh+= dot; tot++;
- }
-
- dot= dot_v3v3(vlr->n, vlr->v3->n);
- dot= ABS(dot);
- if (dot>0.9f) {
- thresh+= dot; tot++;
- }
-
- if (vlr->v4) {
- dot= dot_v3v3(vlr->n, vlr->v4->n);
- dot= ABS(dot);
- if (dot>0.9f) {
- thresh+= dot; tot++;
- }
- }
- }
- }
-
- if (tot) {
- thresh/= (float)tot;
- obr->ob->smoothresh= cosf(0.5f*(float)M_PI-saacos(thresh));
- }
-}
-
-/* per face check if all samples should be taken.
- * if raytrace or multisample, do always for raytraced material, or when material full_osa set */
-static void set_fullsample_trace_flag(Render *re, ObjectRen *obr)
-{
- VlakRen *vlr;
- int a, trace, mode, osa;
-
- osa= re->osa;
- trace= re->r.mode & R_RAYTRACE;
-
- for (a=obr->totvlak-1; a>=0; a--) {
- vlr= RE_findOrAddVlak(obr, a);
- mode= vlr->mat->mode;
-
- if (trace && (mode & MA_TRACEBLE))
- vlr->flag |= R_TRACEBLE;
-
- if (osa) {
- if (mode & MA_FULL_OSA) {
- vlr->flag |= R_FULL_OSA;
- }
- else if (trace) {
- if (mode & MA_SHLESS) {
- /* pass */
- }
- else if (vlr->mat->material_type == MA_TYPE_VOLUME) {
- /* pass */
- }
- else if ((mode & MA_RAYMIRROR) || ((mode & MA_TRANSP) && (mode & MA_RAYTRANSP))) {
- /* for blurry reflect/refract, better to take more samples
- * inside the raytrace than as OSA samples */
- if ((vlr->mat->gloss_mir == 1.0f) && (vlr->mat->gloss_tra == 1.0f))
- vlr->flag |= R_FULL_OSA;
- }
- }
- }
- }
-}
-
-/* split quads for predictable baking
- * dir 1 == (0, 1, 2) (0, 2, 3), 2 == (1, 3, 0) (1, 2, 3)
- */
-static void split_quads(ObjectRen *obr, int dir)
-{
- VlakRen *vlr, *vlr1;
- int a;
-
- for (a=obr->totvlak-1; a>=0; a--) {
- vlr= RE_findOrAddVlak(obr, a);
-
- /* test if rendering as a quad or triangle, skip wire */
- if ((vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) {
-
- if (vlr->v4) {
-
- vlr1= RE_vlakren_copy(obr, vlr);
- vlr1->flag |= R_FACE_SPLIT;
-
- if ( dir==2 ) vlr->flag |= R_DIVIDE_24;
- else vlr->flag &= ~R_DIVIDE_24;
-
- /* new vertex pointers */
- if (vlr->flag & R_DIVIDE_24) {
- vlr1->v1= vlr->v2;
- vlr1->v2= vlr->v3;
- vlr1->v3= vlr->v4;
-
- vlr->v3 = vlr->v4;
-
- vlr1->flag |= R_DIVIDE_24;
- }
- else {
- vlr1->v1= vlr->v1;
- vlr1->v2= vlr->v3;
- vlr1->v3= vlr->v4;
-
- vlr1->flag &= ~R_DIVIDE_24;
- }
- vlr->v4 = vlr1->v4 = NULL;
-
-#ifdef WITH_FREESTYLE
- /* Freestyle edge marks */
- if (vlr->flag & R_DIVIDE_24) {
- vlr1->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V2V3) ? R_EDGE_V1V2 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V3V4) ? R_EDGE_V2V3 : 0);
- vlr->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V1V2) ? R_EDGE_V1V2 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V4V1) ? R_EDGE_V3V1 : 0);
- }
- else {
- vlr1->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V3V4) ? R_EDGE_V2V3 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V4V1) ? R_EDGE_V3V1 : 0);
- vlr->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V1V2) ? R_EDGE_V1V2 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V2V3) ? R_EDGE_V2V3 : 0);
- }
-#endif
-
- /* new normals */
- normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- normal_tri_v3(vlr1->n, vlr1->v3->co, vlr1->v2->co, vlr1->v1->co);
- }
- /* clear the flag when not divided */
- else vlr->flag &= ~R_DIVIDE_24;
- }
- }
-}
-
-static void check_non_flat_quads(ObjectRen *obr)
-{
- VlakRen *vlr, *vlr1;
- VertRen *v1, *v2, *v3, *v4;
- float nor[3], xn, flen;
- int a;
-
- for (a=obr->totvlak-1; a>=0; a--) {
- vlr= RE_findOrAddVlak(obr, a);
-
- /* test if rendering as a quad or triangle, skip wire */
- if (vlr->v4 && (vlr->flag & R_STRAND)==0 && (vlr->mat->material_type != MA_TYPE_WIRE)) {
-
- /* check if quad is actually triangle */
- v1= vlr->v1;
- v2= vlr->v2;
- v3= vlr->v3;
- v4= vlr->v4;
- sub_v3_v3v3(nor, v1->co, v2->co);
- if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) {
- vlr->v1= v2;
- vlr->v2= v3;
- vlr->v3= v4;
- vlr->v4= NULL;
- vlr->flag |= (R_DIVIDE_24 | R_FACE_SPLIT);
- }
- else {
- sub_v3_v3v3(nor, v2->co, v3->co);
- if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) {
- vlr->v2= v3;
- vlr->v3= v4;
- vlr->v4= NULL;
- vlr->flag |= R_FACE_SPLIT;
- }
- else {
- sub_v3_v3v3(nor, v3->co, v4->co);
- if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) {
- vlr->v4= NULL;
- }
- else {
- sub_v3_v3v3(nor, v4->co, v1->co);
- if ( ABS(nor[0])<FLT_EPSILON10 && ABS(nor[1])<FLT_EPSILON10 && ABS(nor[2])<FLT_EPSILON10 ) {
- vlr->v4= NULL;
- }
- }
- }
- }
-
- if (vlr->v4) {
-
- /* Face is divided along edge with the least gradient */
- /* Flagged with R_DIVIDE_24 if divide is from vert 2 to 4 */
- /* 4---3 4---3 */
- /* |\ 1| or |1 /| */
- /* |0\ | |/ 0| */
- /* 1---2 1---2 0 = orig face, 1 = new face */
-
- /* render normals are inverted in render! we calculate normal of single tria here */
- flen= normal_tri_v3(nor, vlr->v4->co, vlr->v3->co, vlr->v1->co);
- if (flen==0.0f) normal_tri_v3(nor, vlr->v4->co, vlr->v2->co, vlr->v1->co);
-
- xn = dot_v3v3(nor, vlr->n);
-
- if (ABS(xn) < 0.999995f ) { /* checked on noisy fractal grid */
-
- float d1, d2;
-
- vlr1= RE_vlakren_copy(obr, vlr);
- vlr1->flag |= R_FACE_SPLIT;
-
- /* split direction based on vnorms */
- normal_tri_v3(nor, vlr->v1->co, vlr->v2->co, vlr->v3->co);
- d1 = dot_v3v3(nor, vlr->v1->n);
-
- normal_tri_v3(nor, vlr->v2->co, vlr->v3->co, vlr->v4->co);
- d2 = dot_v3v3(nor, vlr->v2->n);
-
- if (fabsf(d1) < fabsf(d2) ) vlr->flag |= R_DIVIDE_24;
- else vlr->flag &= ~R_DIVIDE_24;
-
- /* new vertex pointers */
- if (vlr->flag & R_DIVIDE_24) {
- vlr1->v1= vlr->v2;
- vlr1->v2= vlr->v3;
- vlr1->v3= vlr->v4;
-
- vlr->v3 = vlr->v4;
-
- vlr1->flag |= R_DIVIDE_24;
- }
- else {
- vlr1->v1= vlr->v1;
- vlr1->v2= vlr->v3;
- vlr1->v3= vlr->v4;
-
- vlr1->flag &= ~R_DIVIDE_24;
- }
- vlr->v4 = vlr1->v4 = NULL;
-
- /* new normals */
- normal_tri_v3(vlr->n, vlr->v3->co, vlr->v2->co, vlr->v1->co);
- normal_tri_v3(vlr1->n, vlr1->v3->co, vlr1->v2->co, vlr1->v1->co);
-
-#ifdef WITH_FREESTYLE
- /* Freestyle edge marks */
- if (vlr->flag & R_DIVIDE_24) {
- vlr1->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V2V3) ? R_EDGE_V1V2 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V3V4) ? R_EDGE_V2V3 : 0);
- vlr->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V1V2) ? R_EDGE_V1V2 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V4V1) ? R_EDGE_V3V1 : 0);
- }
- else {
- vlr1->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V3V4) ? R_EDGE_V2V3 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V4V1) ? R_EDGE_V3V1 : 0);
- vlr->freestyle_edge_mark=
- ((vlr->freestyle_edge_mark & R_EDGE_V1V2) ? R_EDGE_V1V2 : 0) |
- ((vlr->freestyle_edge_mark & R_EDGE_V2V3) ? R_EDGE_V2V3 : 0);
- }
-#endif
- }
- /* clear the flag when not divided */
- else vlr->flag &= ~R_DIVIDE_24;
- }
- }
- }
-}
-
-static void finalize_render_object(Render *re, ObjectRen *obr, int timeoffset)
-{
- Object *ob= obr->ob;
- VertRen *ver= NULL;
- StrandRen *strand= NULL;
- StrandBound *sbound= NULL;
- float min[3], max[3], smin[3], smax[3];
- int a, b;
-
- if (obr->totvert || obr->totvlak || obr->tothalo || obr->totstrand) {
- /* the exception below is because displace code now is in init_render_mesh call,
- * I will look at means to have autosmooth enabled for all object types
- * and have it as general postprocess, like displace */
- if (ob->type!=OB_MESH && test_for_displace(re, ob))
- displace(re, obr);
-
- if (!timeoffset) {
- /* phong normal interpolation can cause error in tracing
- * (terminator problem) */
- ob->smoothresh= 0.0;
- if ((re->r.mode & R_RAYTRACE) && (re->r.mode & R_SHADOW))
- set_phong_threshold(obr);
-
- if (re->flag & R_BAKING && re->r.bake_quad_split != 0) {
- /* Baking lets us define a quad split order */
- split_quads(obr, re->r.bake_quad_split);
- }
- else if (BKE_object_is_animated(re->scene, ob))
- split_quads(obr, 1);
- else {
- if ((re->r.mode & R_SIMPLIFY && re->r.simplify_flag & R_SIMPLE_NO_TRIANGULATE) == 0)
- check_non_flat_quads(obr);
- }
-
- set_fullsample_trace_flag(re, obr);
-
- /* compute bounding boxes for clipping */
- INIT_MINMAX(min, max);
- for (a=0; a<obr->totvert; a++) {
- if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert;
- else ver++;
-
- minmax_v3v3_v3(min, max, ver->co);
- }
-
- if (obr->strandbuf) {
- float width;
-
- /* compute average bounding box of strandpoint itself (width) */
- if (obr->strandbuf->flag & R_STRAND_B_UNITS)
- obr->strandbuf->maxwidth = max_ff(obr->strandbuf->ma->strand_sta, obr->strandbuf->ma->strand_end);
- else
- obr->strandbuf->maxwidth= 0.0f;
-
- width= obr->strandbuf->maxwidth;
- sbound= obr->strandbuf->bound;
- for (b=0; b<obr->strandbuf->totbound; b++, sbound++) {
-
- INIT_MINMAX(smin, smax);
-
- for (a=sbound->start; a<sbound->end; a++) {
- strand= RE_findOrAddStrand(obr, a);
- strand_minmax(strand, smin, smax, width);
- }
-
- copy_v3_v3(sbound->boundbox[0], smin);
- copy_v3_v3(sbound->boundbox[1], smax);
-
- minmax_v3v3_v3(min, max, smin);
- minmax_v3v3_v3(min, max, smax);
- }
- }
-
- copy_v3_v3(obr->boundbox[0], min);
- copy_v3_v3(obr->boundbox[1], max);
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* Database */
-/* ------------------------------------------------------------------------- */
-
-static int render_object_type(short type)
-{
- return OB_TYPE_SUPPORT_MATERIAL(type);
-}
-
-static void find_dupli_instances(Render *re, ObjectRen *obr, DupliObject *dob)
-{
- ObjectInstanceRen *obi;
- float imat[4][4], obmat[4][4], obimat[4][4], nmat[3][3];
- int first = 1;
-
- mul_m4_m4m4(obmat, re->viewmat, obr->obmat);
- invert_m4_m4(imat, obmat);
-
- /* for objects instanced by dupliverts/faces/particles, we go over the
- * list of instances to find ones that instance obr, and setup their
- * matrices and obr pointer */
- for (obi=re->instancetable.last; obi; obi=obi->prev) {
- if (!obi->obr && obi->ob == obr->ob && obi->psysindex == obr->psysindex) {
- obi->obr= obr;
-
- /* compute difference between object matrix and
- * object matrix with dupli transform, in viewspace */
- copy_m4_m4(obimat, obi->mat);
- mul_m4_m4m4(obi->mat, obimat, imat);
-
- copy_m3_m4(nmat, obi->mat);
- invert_m3_m3(obi->nmat, nmat);
- transpose_m3(obi->nmat);
-
- if (dob) {
- copy_v3_v3(obi->dupliorco, dob->orco);
- obi->dupliuv[0]= dob->uv[0];
- obi->dupliuv[1]= dob->uv[1];
- }
-
- if (!first) {
- re->totvert += obr->totvert;
- re->totvlak += obr->totvlak;
- re->tothalo += obr->tothalo;
- re->totstrand += obr->totstrand;
- }
- else
- first= 0;
- }
- }
-}
-
-static void assign_dupligroup_dupli(Render *re, ObjectInstanceRen *obi, ObjectRen *obr, DupliObject *dob)
-{
- float imat[4][4], obmat[4][4], obimat[4][4], nmat[3][3];
-
- mul_m4_m4m4(obmat, re->viewmat, obr->obmat);
- invert_m4_m4(imat, obmat);
-
- obi->obr= obr;
-
- /* compute difference between object matrix and
- * object matrix with dupli transform, in viewspace */
- copy_m4_m4(obimat, obi->mat);
- mul_m4_m4m4(obi->mat, obimat, imat);
-
- copy_m3_m4(nmat, obi->mat);
- invert_m3_m3(obi->nmat, nmat);
- transpose_m3(obi->nmat);
-
- if (dob) {
- copy_v3_v3(obi->dupliorco, dob->orco);
- obi->dupliuv[0]= dob->uv[0];
- obi->dupliuv[1]= dob->uv[1];
- }
-
- re->totvert += obr->totvert;
- re->totvlak += obr->totvlak;
- re->tothalo += obr->tothalo;
- re->totstrand += obr->totstrand;
-}
-
-static ObjectRen *find_dupligroup_dupli(Render *re, Object *ob, int psysindex)
-{
- ObjectRen *obr;
-
- /* if the object is itself instanced, we don't want to create an instance
- * for it */
- if (ob->transflag & OB_RENDER_DUPLI)
- return NULL;
-
- /* try to find an object that was already created so we can reuse it
- * and save memory */
- for (obr=re->objecttable.first; obr; obr=obr->next)
- if (obr->ob == ob && obr->psysindex == psysindex && (obr->flag & R_INSTANCEABLE))
- return obr;
-
- return NULL;
-}
-
-static void set_dupli_tex_mat(Render *re, ObjectInstanceRen *obi, DupliObject *dob, float omat[4][4])
-{
- /* For duplis we need to have a matrix that transform the coordinate back
- * to it's original position, without the dupli transforms. We also check
- * the matrix is actually needed, to save memory on lots of dupliverts for
- * example */
- static Object *lastob= NULL;
- static int needtexmat= 0;
-
- /* init */
- if (!re) {
- lastob= NULL;
- needtexmat= 0;
- return;
- }
-
- /* check if we actually need it */
- if (lastob != dob->ob) {
- Material ***material;
- short a, *totmaterial;
-
- lastob= dob->ob;
- needtexmat= 0;
-
- totmaterial= give_totcolp(dob->ob);
- material= give_matarar(dob->ob);
-
- if (totmaterial && material)
- for (a= 0; a<*totmaterial; a++)
- if ((*material)[a] && (*material)[a]->texco & TEXCO_OBJECT)
- needtexmat= 1;
- }
-
- if (needtexmat) {
- float imat[4][4];
-
- obi->duplitexmat= BLI_memarena_alloc(re->memArena, sizeof(float)*4*4);
- invert_m4_m4(imat, dob->mat);
- mul_m4_series(obi->duplitexmat, re->viewmat, omat, imat, re->viewinv);
- }
-
- copy_v3_v3(obi->dupliorco, dob->orco);
- copy_v2_v2(obi->dupliuv, dob->uv);
-}
-
-static void init_render_object_data(Render *re, ObjectRen *obr, int timeoffset)
-{
- Object *ob= obr->ob;
- ParticleSystem *psys;
- int i;
-
- if (obr->psysindex) {
- if ((!obr->prev || obr->prev->ob != ob || (obr->prev->flag & R_INSTANCEABLE)==0) && ob->type==OB_MESH) {
- /* the emitter mesh wasn't rendered so the modifier stack wasn't
- * evaluated with render settings */
- DerivedMesh *dm;
- const CustomDataMask mask = CD_MASK_RENDER_INTERNAL;
-
- if (re->r.scemode & R_VIEWPORT_PREVIEW)
- dm = mesh_create_derived_view(re->scene, ob, mask);
- else
- dm = mesh_create_derived_render(re->scene, ob, mask);
- dm->release(dm);
- }
-
- for (psys=ob->particlesystem.first, i=0; i<obr->psysindex-1; i++)
- psys= psys->next;
-
- render_new_particle_system(re, obr, psys, timeoffset);
- }
- else {
- if (ELEM(ob->type, OB_FONT, OB_CURVE))
- init_render_curve(re, obr, timeoffset);
- else if (ob->type==OB_SURF)
- init_render_surf(re, obr, timeoffset);
- else if (ob->type==OB_MESH)
- init_render_mesh(re, obr, timeoffset);
- else if (ob->type==OB_MBALL)
- init_render_mball(re, obr);
- }
-
- finalize_render_object(re, obr, timeoffset);
-
- re->totvert += obr->totvert;
- re->totvlak += obr->totvlak;
- re->tothalo += obr->tothalo;
- re->totstrand += obr->totstrand;
-}
-
-static void add_render_object(Render *re, Object *ob, Object *par, DupliObject *dob, float omat[4][4], int timeoffset)
-{
- ObjectRen *obr;
- ObjectInstanceRen *obi;
- ParticleSystem *psys;
- int show_emitter, allow_render= 1, index, psysindex, i;
-
- index= (dob)? dob->persistent_id[0]: 0;
-
- /* It seems that we may generate psys->renderdata recursively in some nasty intricated cases of
- * several levels of bupliobject (see T51524).
- * For now, basic rule is, do not restore psys if it was already in 'render state'.
- * Another, more robust solution could be to add some reference counting to that renderdata... */
- bool psys_has_renderdata = false;
-
- /* the emitter has to be processed first (render levels of modifiers) */
- /* so here we only check if the emitter should be rendered */
- if (ob->particlesystem.first) {
- show_emitter= 0;
- for (psys=ob->particlesystem.first; psys; psys=psys->next) {
- show_emitter += psys->part->draw & PART_DRAW_EMITTER;
- if (!(re->r.scemode & R_VIEWPORT_PREVIEW)) {
- psys_has_renderdata |= (psys->renderdata != NULL);
- psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, timeoffset);
- }
- }
-
- /* if no psys has "show emitter" selected don't render emitter */
- if (show_emitter == 0)
- allow_render= 0;
- }
-
- /* one render object for the data itself */
- if (allow_render) {
- obr= RE_addRenderObject(re, ob, par, index, 0, ob->lay);
- if ((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) {
- obr->flag |= R_INSTANCEABLE;
- copy_m4_m4(obr->obmat, ob->obmat);
- }
- init_render_object_data(re, obr, timeoffset);
-
- /* only add instance for objects that have not been used for dupli */
- if (!(ob->transflag & OB_RENDER_DUPLI)) {
- obi = RE_addRenderInstance(re, obr, ob, par, index, 0, NULL, ob->lay, dob);
- if (dob) set_dupli_tex_mat(re, obi, dob, omat);
- }
- else
- find_dupli_instances(re, obr, dob);
-
- for (i=1; i<=ob->totcol; i++) {
- Material* ma = give_render_material(re, ob, i);
- if (ma && ma->material_type == MA_TYPE_VOLUME)
- add_volume(re, obr, ma);
- }
- }
-
- /* and one render object per particle system */
- if (ob->particlesystem.first) {
- psysindex= 1;
- for (psys=ob->particlesystem.first; psys; psys=psys->next, psysindex++) {
- if (!psys_check_enabled(ob, psys, G.is_rendering))
- continue;
-
- obr= RE_addRenderObject(re, ob, par, index, psysindex, ob->lay);
- if ((dob && !dob->animated) || (ob->transflag & OB_RENDER_DUPLI)) {
- obr->flag |= R_INSTANCEABLE;
- copy_m4_m4(obr->obmat, ob->obmat);
- }
- if (dob)
- psys->flag |= PSYS_USE_IMAT;
- init_render_object_data(re, obr, timeoffset);
- if (!(re->r.scemode & R_VIEWPORT_PREVIEW) && !psys_has_renderdata) {
- psys_render_restore(ob, psys);
- }
- psys->flag &= ~PSYS_USE_IMAT;
-
- /* only add instance for objects that have not been used for dupli */
- if (!(ob->transflag & OB_RENDER_DUPLI)) {
- obi = RE_addRenderInstance(re, obr, ob, par, index, psysindex, NULL, ob->lay, dob);
- if (dob) set_dupli_tex_mat(re, obi, dob, omat);
- }
- else
- find_dupli_instances(re, obr, dob);
- }
- }
-}
-
-/* par = pointer to duplicator parent, needed for object lookup table */
-/* index = when duplicater copies same object (particle), the counter */
-static void init_render_object(Render *re, Object *ob, Object *par, DupliObject *dob, float omat[4][4], int timeoffset)
-{
- static double lasttime= 0.0;
- double time;
- float mat[4][4];
-
- if (ob->type==OB_LAMP)
- add_render_lamp(re, ob);
- else if (render_object_type(ob->type))
- add_render_object(re, ob, par, dob, omat, timeoffset);
- else {
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat, mat);
- }
-
- time= PIL_check_seconds_timer();
- if (time - lasttime > 1.0) {
- lasttime= time;
- /* clumsy copying still */
- re->i.totvert= re->totvert;
- re->i.totface= re->totvlak;
- re->i.totstrand= re->totstrand;
- re->i.tothalo= re->tothalo;
- re->i.totlamp= re->totlamp;
- re->stats_draw(re->sdh, &re->i);
- }
-
- ob->flag |= OB_DONE;
-}
-
-void RE_Database_Free(Render *re)
-{
- LampRen *lar;
-
- /* will crash if we try to free empty database */
- if (!re->i.convertdone)
- return;
-
- /* statistics for debugging render memory usage */
- if ((G.debug & G_DEBUG) && (G.is_rendering)) {
- if ((re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0) {
- BKE_image_print_memlist();
- MEM_printmemlist_stats();
- }
- }
-
- /* FREE */
-
- for (lar= re->lampren.first; lar; lar= lar->next) {
- freeshadowbuf(lar);
- if (lar->jitter) MEM_freeN(lar->jitter);
- if (lar->shadsamp) MEM_freeN(lar->shadsamp);
- if (lar->sunsky) MEM_freeN(lar->sunsky);
- curvemapping_free(lar->curfalloff);
- }
-
- free_volume_precache(re);
-
- BLI_freelistN(&re->lampren);
- BLI_freelistN(&re->lights);
-
- free_renderdata_tables(re);
-
- /* free orco */
- free_mesh_orco_hash(re);
-
- if (re->main) {
- end_render_materials(re->main);
- end_render_textures(re);
- free_pointdensities(re);
- }
-
- free_camera_inside_volumes(re);
-
- if (re->wrld.aosphere) {
- MEM_freeN(re->wrld.aosphere);
- re->wrld.aosphere= NULL;
- if (re->scene && re->scene->world)
- re->scene->world->aosphere= NULL;
- }
- if (re->wrld.aotables) {
- MEM_freeN(re->wrld.aotables);
- re->wrld.aotables= NULL;
- if (re->scene && re->scene->world)
- re->scene->world->aotables= NULL;
- }
- if (re->r.mode & R_RAYTRACE)
- free_render_qmcsampler(re);
-
- if (re->r.mode & R_RAYTRACE) freeraytree(re);
-
- free_sss(re);
- free_occ(re);
- free_strand_surface(re);
-
- re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
- re->i.convertdone = false;
-
- re->bakebuf= NULL;
-
- if (re->scene)
- if (re->scene->r.scemode & R_FREE_IMAGE)
- if ((re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0)
- BKE_image_free_all_textures();
-
- if (re->memArena) {
- BLI_memarena_free(re->memArena);
- re->memArena = NULL;
- }
-}
-
-static int allow_render_object(Render *re, Object *ob, int nolamps, int onlyselected, Object *actob)
-{
- if (is_object_hidden(re, ob))
- return 0;
-
- /* Only handle dupli-hiding here if there is no particle systems. Else, let those handle show/noshow. */
- if (!ob->particlesystem.first) {
- if ((ob->transflag & OB_DUPLI) && !(ob->transflag & OB_DUPLIFRAMES)) {
- return 0;
- }
- }
-
- /* don't add non-basic meta objects, ends up having renderobjects with no geometry */
- if (ob->type == OB_MBALL && ob!=BKE_mball_basis_find(re->scene, ob))
- return 0;
-
- if (nolamps && (ob->type==OB_LAMP))
- return 0;
-
- if (onlyselected && (ob!=actob && !(ob->flag & SELECT)))
- return 0;
-
- return 1;
-}
-
-static int allow_render_dupli_instance(Render *UNUSED(re), DupliObject *dob, Object *obd)
-{
- ParticleSystem *psys;
- Material *ma;
- short a, *totmaterial;
-
- /* don't allow objects with halos. we need to have
- * all halo's to sort them globally in advance */
- totmaterial= give_totcolp(obd);
-
- if (totmaterial) {
- for (a= 0; a<*totmaterial; a++) {
- ma= give_current_material(obd, a + 1);
- if (ma && (ma->material_type == MA_TYPE_HALO))
- return 0;
- }
- }
-
- for (psys=obd->particlesystem.first; psys; psys=psys->next)
- if (!ELEM(psys->part->ren_as, PART_DRAW_BB, PART_DRAW_LINE, PART_DRAW_PATH, PART_DRAW_OB, PART_DRAW_GR))
- return 0;
-
- /* don't allow lamp, animated duplis, or radio render */
- return (render_object_type(obd->type) &&
- (!(dob->type == OB_DUPLIGROUP) || !dob->animated));
-}
-
-static void dupli_render_particle_set(Render *re, Object *ob, int timeoffset, int level, int enable)
-{
- /* ugly function, but we need to set particle systems to their render
- * settings before calling object_duplilist, to get render level duplis */
- Group *group;
- GroupObject *go;
- ParticleSystem *psys;
- DerivedMesh *dm;
-
- if (re->r.scemode & R_VIEWPORT_PREVIEW)
- return;
-
- if (level >= MAX_DUPLI_RECUR)
- return;
-
- if (ob->transflag & OB_DUPLIPARTS) {
- for (psys=ob->particlesystem.first; psys; psys=psys->next) {
- if (ELEM(psys->part->ren_as, PART_DRAW_OB, PART_DRAW_GR)) {
- if (enable)
- psys_render_set(ob, psys, re->viewmat, re->winmat, re->winx, re->winy, timeoffset);
- else
- psys_render_restore(ob, psys);
- }
- }
-
- if (enable) {
- /* this is to make sure we get render level duplis in groups:
- * the derivedmesh must be created before init_render_mesh,
- * since object_duplilist does dupliparticles before that */
- dm = mesh_create_derived_render(re->scene, ob, CD_MASK_RENDER_INTERNAL);
- dm->release(dm);
-
- for (psys=ob->particlesystem.first; psys; psys=psys->next)
- psys_get_modifier(ob, psys)->flag &= ~eParticleSystemFlag_psys_updated;
- }
- }
-
- if (ob->dup_group==NULL) return;
- group= ob->dup_group;
-
- for (go= group->gobject.first; go; go= go->next)
- dupli_render_particle_set(re, go->ob, timeoffset, level+1, enable);
-}
-
-static int get_vector_renderlayers(Scene *sce)
-{
- SceneRenderLayer *srl;
- unsigned int lay= 0;
-
- for (srl= sce->r.layers.first; srl; srl= srl->next)
- if (srl->passflag & SCE_PASS_VECTOR)
- lay |= srl->lay;
-
- return lay;
-}
-
-static void add_group_render_dupli_obs(Render *re, Group *group, int nolamps, int onlyselected, Object *actob, int timeoffset, int level)
-{
- GroupObject *go;
- Object *ob;
-
- /* simple preventing of too deep nested groups */
- if (level>MAX_DUPLI_RECUR) return;
-
- /* recursively go into dupligroups to find objects with OB_RENDER_DUPLI
- * that were not created yet */
- for (go= group->gobject.first; go; go= go->next) {
- ob= go->ob;
-
- if (ob->flag & OB_DONE) {
- if (ob->transflag & OB_RENDER_DUPLI) {
- if (allow_render_object(re, ob, nolamps, onlyselected, actob)) {
- init_render_object(re, ob, NULL, NULL, NULL, timeoffset);
- ob->transflag &= ~OB_RENDER_DUPLI;
-
- if (ob->dup_group)
- add_group_render_dupli_obs(re, ob->dup_group, nolamps, onlyselected, actob, timeoffset, level+1);
- }
- }
- }
- }
-}
-
-static void database_init_objects(Render *re, unsigned int renderlay, int nolamps, int onlyselected, Object *actob, int timeoffset)
-{
- Base *base;
- Object *ob;
- Group *group;
- ObjectInstanceRen *obi;
- Scene *sce_iter;
- int lay, vectorlay;
-
- /* for duplis we need the Object texture mapping to work as if
- * untransformed, set_dupli_tex_mat sets the matrix to allow that
- * NULL is just for init */
- set_dupli_tex_mat(NULL, NULL, NULL, NULL);
-
- /* loop over all objects rather then using SETLOOPER because we may
- * reference an mtex-mapped object which isn't rendered or is an
- * empty in a dupli group. We could scan all render material/lamp/world
- * mtex's for mapto objects but its easier just to set the
- * 'imat' / 'imat_ren' on all and unlikely to be a performance hit
- * See bug: [#28744] - campbell */
- for (ob= re->main->object.first; ob; ob= ob->id.next) {
- float mat[4][4];
-
- /* imat objects has to be done here, since displace can have texture using Object map-input */
- mul_m4_m4m4(mat, re->viewmat, ob->obmat);
- invert_m4_m4(ob->imat_ren, mat);
- copy_m4_m4(ob->imat, ob->imat_ren);
- /* each object should only be rendered once */
- ob->flag &= ~OB_DONE;
- ob->transflag &= ~OB_RENDER_DUPLI;
- }
-
- for (SETLOOPER(re->scene, sce_iter, base)) {
- ob= base->object;
-
- /* in the prev/next pass for making speed vectors, avoid creating
- * objects that are not on a renderlayer with a vector pass, can
- * save a lot of time in complex scenes */
- vectorlay= get_vector_renderlayers(re->scene);
- lay= (timeoffset)? renderlay & vectorlay: renderlay;
-
- /* if the object has been restricted from rendering in the outliner, ignore it */
- if (is_object_restricted(re, ob)) continue;
-
- /* OB_DONE means the object itself got duplicated, so was already converted */
- if (ob->flag & OB_DONE) {
- /* OB_RENDER_DUPLI means instances for it were already created, now
- * it still needs to create the ObjectRen containing the data */
- if (ob->transflag & OB_RENDER_DUPLI) {
- if (allow_render_object(re, ob, nolamps, onlyselected, actob)) {
- init_render_object(re, ob, NULL, NULL, NULL, timeoffset);
- ob->transflag &= ~OB_RENDER_DUPLI;
- }
- }
- }
- else if ((base->lay & lay) || (ob->type==OB_LAMP && (base->lay & re->lay)) ) {
- if ((ob->transflag & OB_DUPLI) && (ob->type!=OB_MBALL)) {
- DupliObject *dob;
- ListBase *duplilist;
- DupliApplyData *duplilist_apply_data = NULL;
- int i;
-
- /* create list of duplis generated by this object, particle
- * system need to have render settings set for dupli particles */
- dupli_render_particle_set(re, ob, timeoffset, 0, 1);
- duplilist = object_duplilist(re->eval_ctx, re->scene, ob);
- duplilist_apply_data = duplilist_apply(ob, NULL, duplilist);
- /* postpone 'dupli_render_particle_set', since RE_addRenderInstance reads
- * index values from 'dob->persistent_id[0]', referencing 'psys->child' which
- * may be smaller once the particle system is restored, see: T45563. */
-
- for (dob= duplilist->first, i = 0; dob; dob= dob->next, ++i) {
- DupliExtraData *dob_extra = &duplilist_apply_data->extra[i];
- Object *obd= dob->ob;
-
- copy_m4_m4(obd->obmat, dob->mat);
-
- /* group duplis need to set ob matrices correct, for deform. so no_draw is part handled */
- if (!(obd->transflag & OB_RENDER_DUPLI) && dob->no_draw)
- continue;
-
- if (is_object_hidden(re, obd))
- continue;
-
- if (obd->type==OB_MBALL)
- continue;
-
- if (!allow_render_object(re, obd, nolamps, onlyselected, actob))
- continue;
-
- if (allow_render_dupli_instance(re, dob, obd)) {
- ParticleSystem *psys;
- ObjectRen *obr = NULL;
- int psysindex;
- float mat[4][4];
-
- obi=NULL;
-
- /* instances instead of the actual object are added in two cases, either
- * this is a duplivert/face/particle, or it is a non-animated object in
- * a dupligroup that has already been created before */
- if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, 0))) {
- mul_m4_m4m4(mat, re->viewmat, dob->mat);
- /* ob = particle system, use that layer */
- obi = RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], 0, mat, ob->lay, dob);
-
- /* fill in instance variables for texturing */
- set_dupli_tex_mat(re, obi, dob, dob_extra->obmat);
- if (dob->type != OB_DUPLIGROUP) {
- copy_v3_v3(obi->dupliorco, dob->orco);
- obi->dupliuv[0]= dob->uv[0];
- obi->dupliuv[1]= dob->uv[1];
- }
- else {
- /* for the second case, setup instance to point to the already
- * created object, and possibly setup instances if this object
- * itself was duplicated. for the first case find_dupli_instances
- * will be called later. */
- assign_dupligroup_dupli(re, obi, obr, dob);
- if (obd->transflag & OB_RENDER_DUPLI)
- find_dupli_instances(re, obr, dob);
- }
- }
-
- /* same logic for particles, each particle system has it's own object, so
- * need to go over them separately */
- psysindex= 1;
- for (psys=obd->particlesystem.first; psys; psys=psys->next) {
- if (dob->type != OB_DUPLIGROUP || (obr=find_dupligroup_dupli(re, obd, psysindex))) {
- if (obi == NULL)
- mul_m4_m4m4(mat, re->viewmat, dob->mat);
- obi = RE_addRenderInstance(re, NULL, obd, ob, dob->persistent_id[0], psysindex++, mat, obd->lay, dob);
-
- set_dupli_tex_mat(re, obi, dob, dob_extra->obmat);
- if (dob->type != OB_DUPLIGROUP) {
- copy_v3_v3(obi->dupliorco, dob->orco);
- obi->dupliuv[0]= dob->uv[0];
- obi->dupliuv[1]= dob->uv[1];
- }
- else {
- assign_dupligroup_dupli(re, obi, obr, dob);
- if (obd->transflag & OB_RENDER_DUPLI)
- find_dupli_instances(re, obr, dob);
- }
- }
- }
-
- if (obi==NULL)
- /* can't instance, just create the object */
- init_render_object(re, obd, ob, dob, dob_extra->obmat, timeoffset);
-
- if (dob->type != OB_DUPLIGROUP) {
- obd->flag |= OB_DONE;
- obd->transflag |= OB_RENDER_DUPLI;
- }
- }
- else
- init_render_object(re, obd, ob, dob, dob_extra->obmat, timeoffset);
-
- if (re->test_break(re->tbh)) break;
- }
-
- /* restore particle system */
- dupli_render_particle_set(re, ob, timeoffset, 0, false);
-
- if (duplilist_apply_data) {
- duplilist_restore(duplilist, duplilist_apply_data);
- duplilist_free_apply_data(duplilist_apply_data);
- }
- free_object_duplilist(duplilist);
-
- if (allow_render_object(re, ob, nolamps, onlyselected, actob))
- init_render_object(re, ob, NULL, NULL, NULL, timeoffset);
- }
- else if (allow_render_object(re, ob, nolamps, onlyselected, actob))
- init_render_object(re, ob, NULL, NULL, NULL, timeoffset);
- }
-
- if (re->test_break(re->tbh)) break;
- }
-
- /* objects in groups with OB_RENDER_DUPLI set still need to be created,
- * since they may not be part of the scene */
- for (group= re->main->group.first; group; group=group->id.next)
- add_group_render_dupli_obs(re, group, nolamps, onlyselected, actob, timeoffset, 0);
-
- if (!re->test_break(re->tbh))
- RE_makeRenderInstances(re);
-}
-
-/* used to be 'rotate scene' */
-void RE_Database_FromScene(Render *re, Main *bmain, Scene *scene, unsigned int lay, int use_camera_view)
-{
- Scene *sce;
- Object *camera;
- float mat[4][4];
- float amb[3];
-
- re->main= bmain;
- re->scene= scene;
- re->lay= lay;
-
- if (re->r.scemode & R_VIEWPORT_PREVIEW)
- re->scene_color_manage = BKE_scene_check_color_management_enabled(scene);
-
- /* scene needs to be set to get camera */
- camera= RE_GetCamera(re);
-
- /* per second, per object, stats print this */
- re->i.infostr= "Preparing Scene data";
- re->i.cfra= scene->r.cfra;
- BLI_strncpy(re->i.scene_name, scene->id.name + 2, sizeof(re->i.scene_name));
-
- /* XXX add test if dbase was filled already? */
-
- re->memArena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "render db arena");
- re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
- re->lights.first= re->lights.last= NULL;
- re->lampren.first= re->lampren.last= NULL;
-
- re->i.partsdone = false; /* signal now in use for previewrender */
-
- /* in localview, lamps are using normal layers, objects only local bits */
- if (re->lay & 0xFF000000)
- lay &= 0xFF000000;
-
- /* applies changes fully */
- if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0) {
- BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, lay);
- render_update_anim_renderdata(re, &re->scene->r);
- }
-
- /* if no camera, viewmat should have been set! */
- if (use_camera_view && camera) {
- /* called before but need to call again in case of lens animation from the
- * above call to BKE_scene_update_for_newframe, fixes bug. [#22702].
- * following calls don't depend on 'RE_SetCamera' */
- RE_SetCamera(re, camera);
- RE_GetCameraModelMatrix(re, camera, mat);
- invert_m4(mat);
- RE_SetView(re, mat);
-
- /* force correct matrix for scaled cameras */
- DAG_id_tag_update_ex(re->main, &camera->id, OB_RECALC_OB);
- }
-
- /* store for incremental render, viewmat rotates dbase */
- copy_m4_m4(re->viewmat_orig, re->viewmat);
-
- init_render_world(re); /* do first, because of ambient. also requires re->osa set correct */
- if (re->r.mode & R_RAYTRACE) {
- init_render_qmcsampler(re);
-
- if (re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT))
- if (re->wrld.ao_samp_method == WO_AOSAMP_CONSTANT)
- init_ao_sphere(re, &re->wrld);
- }
-
- /* still bad... doing all */
- init_render_textures(re);
- copy_v3_v3(amb, &re->wrld.ambr);
- init_render_materials(re->main, re->r.mode, amb, (re->r.scemode & R_BUTS_PREVIEW) == 0);
- set_node_shader_lamp_loop(shade_material_loop);
-
- /* MAKE RENDER DATA */
- database_init_objects(re, lay, 0, 0, NULL, 0);
-
- if (!re->test_break(re->tbh)) {
- set_material_lightgroups(re);
- for (sce= re->scene; sce; sce= sce->set)
- set_renderlayer_lightgroups(re, sce);
-
- /* for now some clumsy copying still */
- re->i.totvert= re->totvert;
- re->i.totface= re->totvlak;
- re->i.totstrand= re->totstrand;
- re->i.tothalo= re->tothalo;
- re->i.totlamp= re->totlamp;
- re->stats_draw(re->sdh, &re->i);
- }
-}
-
-void RE_Database_Preprocess(Render *re)
-{
- if (!re->test_break(re->tbh)) {
- int tothalo;
-
- tothalo= re->tothalo;
- sort_halos(re, tothalo);
-
- init_camera_inside_volumes(re);
-
- re->i.infostr = IFACE_("Creating Shadowbuffers");
- re->stats_draw(re->sdh, &re->i);
-
- /* SHADOW BUFFER */
- threaded_makeshadowbufs(re);
-
- /* old code checked for internal render (aka not yafray) */
- {
- /* raytree */
- if (!re->test_break(re->tbh)) {
- if (re->r.mode & R_RAYTRACE) {
- makeraytree(re);
- }
- }
- /* ENVIRONMENT MAPS */
- if (!re->test_break(re->tbh))
- make_envmaps(re);
-
- /* point density texture */
- if (!re->test_break(re->tbh))
- make_pointdensities(re);
- /* voxel data texture */
- if (!re->test_break(re->tbh))
- make_voxeldata(re);
- }
-
- if (!re->test_break(re->tbh))
- project_renderdata(re, projectverto, (re->r.mode & R_PANORAMA) != 0, 0, 1);
-
- /* Occlusion */
- if ((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh))
- if (re->wrld.ao_gather_method == WO_AOGATHER_APPROX)
- if (re->r.mode & R_SHADOW)
- make_occ_tree(re);
-
- /* SSS */
- if ((re->r.mode & R_SSS) && !re->test_break(re->tbh))
- make_sss_tree(re);
-
- if (!re->test_break(re->tbh))
- if (re->r.mode & R_RAYTRACE)
- volume_precache(re);
- }
-
- re->i.convertdone = true;
-
- if (re->test_break(re->tbh))
- RE_Database_Free(re);
-
- re->i.infostr = NULL;
- re->stats_draw(re->sdh, &re->i);
-}
-
-/* exported call to recalculate hoco for vertices, when winmat changed */
-void RE_DataBase_ApplyWindow(Render *re)
-{
- project_renderdata(re, projectverto, 0, 0, 0);
-}
-
-/* exported call to rotate render data again, when viewmat changed */
-void RE_DataBase_IncrementalView(Render *re, float viewmat[4][4], int restore)
-{
- float oldviewinv[4][4], tmat[4][4];
-
- invert_m4_m4(oldviewinv, re->viewmat_orig);
-
- /* we have to correct for the already rotated vertexcoords */
- mul_m4_m4m4(tmat, viewmat, oldviewinv);
-
- copy_m4_m4(re->viewmat, viewmat);
- invert_m4_m4(re->viewinv, re->viewmat);
-
- init_camera_inside_volumes(re);
-
- env_rotate_scene(re, tmat, !restore);
-
- /* SSS points distribution depends on view */
- if ((re->r.mode & R_SSS) && !re->test_break(re->tbh))
- make_sss_tree(re);
-}
-
-
-void RE_DataBase_GetView(Render *re, float mat[4][4])
-{
- copy_m4_m4(mat, re->viewmat);
-}
-
-/* ------------------------------------------------------------------------- */
-/* Speed Vectors */
-/* ------------------------------------------------------------------------- */
-
-static void database_fromscene_vectors(Render *re, Scene *scene, unsigned int lay, int timeoffset)
-{
- Object *camera= RE_GetCamera(re);
- float mat[4][4];
-
- re->scene= scene;
- re->lay= lay;
-
- /* XXX add test if dbase was filled already? */
-
- re->memArena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "vector render db arena");
- re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
- re->i.totface=re->i.totvert=re->i.totstrand=re->i.totlamp=re->i.tothalo= 0;
- re->lights.first= re->lights.last= NULL;
-
- /* in localview, lamps are using normal layers, objects only local bits */
- if (re->lay & 0xFF000000)
- lay &= 0xFF000000;
-
- /* applies changes fully */
- scene->r.cfra += timeoffset;
- BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, lay);
-
- /* if no camera, viewmat should have been set! */
- if (camera) {
- RE_GetCameraModelMatrix(re, camera, mat);
- normalize_m4(mat);
- invert_m4(mat);
- RE_SetView(re, mat);
- }
-
- /* MAKE RENDER DATA */
- database_init_objects(re, lay, 0, 0, NULL, timeoffset);
-
- if (!re->test_break(re->tbh))
- project_renderdata(re, projectverto, (re->r.mode & R_PANORAMA) != 0, 0, 1);
-
- /* do this in end, particles for example need cfra */
- scene->r.cfra -= timeoffset;
-}
-
-/* choose to use static, to prevent giving too many args to this call */
-static void speedvector_project(Render *re, float zco[2], const float co[3], const float ho[4])
-{
- static float pixelphix=0.0f, pixelphiy=0.0f, zmulx=0.0f, zmuly=0.0f;
- static int pano= 0;
- float div;
-
- /* initialize */
- if (re) {
- pano= re->r.mode & R_PANORAMA;
-
- /* precalculate amount of radians 1 pixel rotates */
- if (pano) {
- /* size of 1 pixel mapped to viewplane coords */
- float psize;
-
- psize = BLI_rctf_size_x(&re->viewplane) / (float)re->winx;
- /* x angle of a pixel */
- pixelphix = atan(psize / re->clipsta);
-
- psize = BLI_rctf_size_y(&re->viewplane) / (float)re->winy;
- /* y angle of a pixel */
- pixelphiy = atan(psize / re->clipsta);
- }
- zmulx= re->winx/2;
- zmuly= re->winy/2;
-
- return;
- }
-
- /* now map hocos to screenspace, uses very primitive clip still */
- if (ho[3]<0.1f) div= 10.0f;
- else div= 1.0f/ho[3];
-
- /* use cylinder projection */
- if (pano) {
- float vec[3], ang;
- /* angle between (0, 0, -1) and (co) */
- copy_v3_v3(vec, co);
-
- ang= saacos(-vec[2]/sqrtf(vec[0]*vec[0] + vec[2]*vec[2]));
- if (vec[0]<0.0f) ang= -ang;
- zco[0]= ang/pixelphix + zmulx;
-
- ang= 0.5f*(float)M_PI - saacos(vec[1] / len_v3(vec));
- zco[1]= ang/pixelphiy + zmuly;
-
- }
- else {
- zco[0]= zmulx*(1.0f+ho[0]*div);
- zco[1]= zmuly*(1.0f+ho[1]*div);
- }
-}
-
-static void calculate_speedvector(const float vectors[2], int step, float winsq, float winroot, const float co[3], const float ho[4], float speed[4])
-{
- float zco[2], len;
-
- speedvector_project(NULL, zco, co, ho);
-
- zco[0]= vectors[0] - zco[0];
- zco[1]= vectors[1] - zco[1];
-
- /* enable nice masks for hardly moving stuff or float inaccuracy */
- if (zco[0]<0.1f && zco[0]>-0.1f && zco[1]<0.1f && zco[1]>-0.1f ) {
- zco[0]= 0.0f;
- zco[1]= 0.0f;
- }
-
- /* maximize speed for image width, otherwise it never looks good */
- len= zco[0]*zco[0] + zco[1]*zco[1];
- if (len > winsq) {
- len= winroot/sqrtf(len);
- zco[0]*= len;
- zco[1]*= len;
- }
-
- /* note; in main vecblur loop speedvec is negated again */
- if (step) {
- speed[2]= -zco[0];
- speed[3]= -zco[1];
- }
- else {
- speed[0]= zco[0];
- speed[1]= zco[1];
- }
-}
-
-static float *calculate_strandsurface_speedvectors(Render *re, ObjectInstanceRen *obi, StrandSurface *mesh)
-{
- if (mesh->co && mesh->prevco && mesh->nextco) {
- float winsq= (float)re->winx*(float)re->winy; /* int's can wrap on large images */
- float winroot= sqrtf(winsq);
- float (*winspeed)[4];
- float ho[4], prevho[4], nextho[4], winmat[4][4], vec[2];
- int a;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(winmat, re->winmat, obi->mat);
- else
- copy_m4_m4(winmat, re->winmat);
-
- winspeed= MEM_callocN(sizeof(float)*4*mesh->totvert, "StrandSurfWin");
-
- for (a=0; a<mesh->totvert; a++) {
- projectvert(mesh->co[a], winmat, ho);
-
- projectvert(mesh->prevco[a], winmat, prevho);
- speedvector_project(NULL, vec, mesh->prevco[a], prevho);
- calculate_speedvector(vec, 0, winsq, winroot, mesh->co[a], ho, winspeed[a]);
-
- projectvert(mesh->nextco[a], winmat, nextho);
- speedvector_project(NULL, vec, mesh->nextco[a], nextho);
- calculate_speedvector(vec, 1, winsq, winroot, mesh->co[a], ho, winspeed[a]);
- }
-
- return (float *)winspeed;
- }
-
- return NULL;
-}
-
-static void calculate_speedvectors(Render *re, ObjectInstanceRen *obi, float *vectors, int step)
-{
- ObjectRen *obr= obi->obr;
- VertRen *ver= NULL;
- StrandRen *strand= NULL;
- StrandBuffer *strandbuf;
- StrandSurface *mesh= NULL;
- float *speed, (*winspeed)[4]=NULL, ho[4], winmat[4][4];
- float *co1, *co2, *co3, *co4, w[4];
- float winsq = (float)re->winx * (float)re->winy, winroot = sqrtf(winsq); /* int's can wrap on large images */
- int a, *face, *index;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(winmat, re->winmat, obi->mat);
- else
- copy_m4_m4(winmat, re->winmat);
-
- if (obr->vertnodes) {
- for (a=0; a<obr->totvert; a++, vectors+=2) {
- if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert;
- else ver++;
-
- speed= RE_vertren_get_winspeed(obi, ver, 1);
- projectvert(ver->co, winmat, ho);
- calculate_speedvector(vectors, step, winsq, winroot, ver->co, ho, speed);
- }
- }
-
- if (obr->strandnodes) {
- strandbuf= obr->strandbuf;
- mesh= (strandbuf)? strandbuf->surface: NULL;
-
- /* compute speed vectors at surface vertices */
- if (mesh)
- winspeed= (float(*)[4])calculate_strandsurface_speedvectors(re, obi, mesh);
-
- if (winspeed) {
- for (a=0; a<obr->totstrand; a++, vectors+=2) {
- if ((a & 255)==0) strand= obr->strandnodes[a>>8].strand;
- else strand++;
-
- index= RE_strandren_get_face(obr, strand, 0);
- if (index && *index < mesh->totface) {
- speed= RE_strandren_get_winspeed(obi, strand, 1);
-
- /* interpolate speed vectors from strand surface */
- face= mesh->face[*index];
-
- co1 = mesh->co[face[0]];
- co2 = mesh->co[face[1]];
- co3 = mesh->co[face[2]];
-
- if (face[3]) {
- co4 = mesh->co[face[3]];
- interp_weights_quad_v3(w, co1, co2, co3, co4, strand->vert->co);
- }
- else {
- interp_weights_tri_v3(w, co1, co2, co3, strand->vert->co);
- }
-
- zero_v4(speed);
- madd_v4_v4fl(speed, winspeed[face[0]], w[0]);
- madd_v4_v4fl(speed, winspeed[face[1]], w[1]);
- madd_v4_v4fl(speed, winspeed[face[2]], w[2]);
- if (face[3])
- madd_v4_v4fl(speed, winspeed[face[3]], w[3]);
- }
- }
-
- MEM_freeN(winspeed);
- }
- }
-}
-
-static int load_fluidsimspeedvectors(Render *re, ObjectInstanceRen *obi, float *vectors, int step)
-{
- ObjectRen *obr= obi->obr;
- Object *fsob= obr->ob;
- VertRen *ver= NULL;
- float *speed, div, zco[2], avgvel[4] = {0.0, 0.0, 0.0, 0.0};
- float zmulx= re->winx/2, zmuly= re->winy/2, len;
- float winsq = (float)re->winx * (float)re->winy, winroot= sqrtf(winsq); /* int's can wrap on large images */
- int a, j;
- float hoco[4], ho[4], fsvec[4], camco[4];
- float mat[4][4], winmat[4][4];
- float imat[4][4];
- FluidsimModifierData *fluidmd = (FluidsimModifierData *)modifiers_findByType(fsob, eModifierType_Fluidsim);
- FluidsimSettings *fss;
- FluidVertexVelocity *velarray = NULL;
-
- /* only one step needed */
- if (step) return 1;
-
- if (fluidmd)
- fss = fluidmd->fss;
- else
- return 0;
-
- copy_m4_m4(mat, re->viewmat);
- invert_m4_m4(imat, mat);
-
- /* set first vertex OK */
- if (!fss->meshVelocities) return 0;
-
- if ( obr->totvert != fss->totvert) {
- //fprintf(stderr, "load_fluidsimspeedvectors - modified fluidsim mesh, not using speed vectors (%d,%d)...\n", obr->totvert, fsob->fluidsimSettings->meshSurface->totvert); // DEBUG
- return 0;
- }
-
- velarray = fss->meshVelocities;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(winmat, re->winmat, obi->mat);
- else
- copy_m4_m4(winmat, re->winmat);
-
- /* (bad) HACK calculate average velocity */
- /* better solution would be fixing getVelocityAt() in intern/elbeem/intern/solver_util.cpp
- * so that also small drops/little water volumes return a velocity != 0.
- * But I had no luck in fixing that function - DG */
- for (a=0; a<obr->totvert; a++) {
- for (j=0;j<3;j++) avgvel[j] += velarray[a].vel[j];
-
- }
- for (j=0;j<3;j++) avgvel[j] /= (float)(obr->totvert);
-
-
- for (a=0; a<obr->totvert; a++, vectors+=2) {
- if ((a & 255)==0)
- ver= obr->vertnodes[a>>8].vert;
- else
- ver++;
-
- /* get fluid velocity */
- fsvec[3] = 0.0f;
- //fsvec[0] = fsvec[1] = fsvec[2] = fsvec[3] = 0.0; fsvec[2] = 2.0f; // NT fixed test
- for (j=0;j<3;j++) fsvec[j] = velarray[a].vel[j];
-
- /* (bad) HACK insert average velocity if none is there (see previous comment) */
- if ((fsvec[0] == 0.0f) && (fsvec[1] == 0.0f) && (fsvec[2] == 0.0f)) {
- fsvec[0] = avgvel[0];
- fsvec[1] = avgvel[1];
- fsvec[2] = avgvel[2];
- }
-
- /* transform (=rotate) to cam space */
- camco[0] = dot_v3v3(imat[0], fsvec);
- camco[1] = dot_v3v3(imat[1], fsvec);
- camco[2] = dot_v3v3(imat[2], fsvec);
-
- /* get homogeneous coordinates */
- projectvert(camco, winmat, hoco);
- projectvert(ver->co, winmat, ho);
-
- /* now map hocos to screenspace, uses very primitive clip still */
- /* use ho[3] of original vertex, xy component of vel. direction */
- if (ho[3]<0.1f) div= 10.0f;
- else div= 1.0f/ho[3];
- zco[0]= zmulx*hoco[0]*div;
- zco[1]= zmuly*hoco[1]*div;
-
- /* maximize speed as usual */
- len= zco[0]*zco[0] + zco[1]*zco[1];
- if (len > winsq) {
- len= winroot/sqrtf(len);
- zco[0]*= len; zco[1]*= len;
- }
-
- speed= RE_vertren_get_winspeed(obi, ver, 1);
- /* set both to the same value */
- speed[0]= speed[2]= zco[0];
- speed[1]= speed[3]= zco[1];
- //if (a < 20) fprintf(stderr,"speed %d %f,%f | camco %f,%f,%f | hoco %f,%f,%f,%f\n", a, speed[0], speed[1], camco[0],camco[1], camco[2], hoco[0],hoco[1], hoco[2],hoco[3]); // NT DEBUG
- }
-
- return 1;
-}
-
-/* makes copy per object of all vectors */
-/* result should be that we can free entire database */
-static void copy_dbase_object_vectors(Render *re, ListBase *lb)
-{
- ObjectInstanceRen *obi, *obilb;
- ObjectRen *obr;
- VertRen *ver= NULL;
- float *vec, ho[4], winmat[4][4];
- int a, totvector;
-
- for (obi= re->instancetable.first; obi; obi= obi->next) {
- obr= obi->obr;
-
- obilb= MEM_mallocN(sizeof(ObjectInstanceRen), "ObInstanceVector");
- memcpy(obilb, obi, sizeof(ObjectInstanceRen));
- BLI_addtail(lb, obilb);
-
- obilb->totvector= totvector= obr->totvert;
-
- if (totvector > 0) {
- vec= obilb->vectors= MEM_mallocN(2*sizeof(float)*totvector, "vector array");
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(winmat, re->winmat, obi->mat);
- else
- copy_m4_m4(winmat, re->winmat);
-
- for (a=0; a<obr->totvert; a++, vec+=2) {
- if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert;
- else ver++;
-
- projectvert(ver->co, winmat, ho);
- speedvector_project(NULL, vec, ver->co, ho);
- }
- }
- }
-}
-
-static void free_dbase_object_vectors(ListBase *lb)
-{
- ObjectInstanceRen *obi;
-
- for (obi= lb->first; obi; obi= obi->next)
- if (obi->vectors)
- MEM_freeN(obi->vectors);
- BLI_freelistN(lb);
-}
-
-void RE_Database_FromScene_Vectors(Render *re, Main *bmain, Scene *sce, unsigned int lay)
-{
- ObjectInstanceRen *obi, *oldobi;
- StrandSurface *mesh;
- ListBase *table;
- ListBase oldtable= {NULL, NULL}, newtable= {NULL, NULL};
- ListBase strandsurface;
- int step;
-
- re->i.infostr = IFACE_("Calculating previous frame vectors");
- re->r.mode |= R_SPEED;
-
- speedvector_project(re, NULL, NULL, NULL); /* initializes projection code */
-
- /* creates entire dbase */
- database_fromscene_vectors(re, sce, lay, -1);
-
- /* copy away vertex info */
- copy_dbase_object_vectors(re, &oldtable);
-
- /* free dbase and make the future one */
- strandsurface= re->strandsurface;
- memset(&re->strandsurface, 0, sizeof(ListBase));
- re->i.convertdone = true;
- RE_Database_Free(re);
- re->strandsurface= strandsurface;
-
- if (!re->test_break(re->tbh)) {
- /* creates entire dbase */
- re->i.infostr = IFACE_("Calculating next frame vectors");
-
- database_fromscene_vectors(re, sce, lay, +1);
- }
- /* copy away vertex info */
- copy_dbase_object_vectors(re, &newtable);
-
- /* free dbase and make the real one */
- strandsurface= re->strandsurface;
- memset(&re->strandsurface, 0, sizeof(ListBase));
- re->i.convertdone = true;
- RE_Database_Free(re);
- re->strandsurface= strandsurface;
-
- if (!re->test_break(re->tbh)) {
- RE_Database_FromScene(re, bmain, sce, lay, 1);
- RE_Database_Preprocess(re);
- }
-
- if (!re->test_break(re->tbh)) {
- int vectorlay= get_vector_renderlayers(re->scene);
-
- for (step= 0; step<2; step++) {
-
- if (step)
- table= &newtable;
- else
- table= &oldtable;
-
- oldobi= table->first;
- for (obi= re->instancetable.first; obi && oldobi; obi= obi->next) {
- int ok= 1;
- FluidsimModifierData *fluidmd;
-
- if (!(obi->lay & vectorlay))
- continue;
-
- obi->totvector= obi->obr->totvert;
-
- /* find matching object in old table */
- if (oldobi->ob!=obi->ob || oldobi->par!=obi->par || oldobi->index!=obi->index || oldobi->psysindex!=obi->psysindex) {
- ok= 0;
- for (oldobi= table->first; oldobi; oldobi= oldobi->next)
- if (oldobi->ob==obi->ob && oldobi->par==obi->par && oldobi->index==obi->index && oldobi->psysindex==obi->psysindex)
- break;
- if (oldobi==NULL)
- oldobi= table->first;
- else
- ok= 1;
- }
- if (ok==0) {
- printf("speed table: missing object %s\n", obi->ob->id.name + 2);
- continue;
- }
-
- /* NT check for fluidsim special treatment */
- fluidmd = (FluidsimModifierData *)modifiers_findByType(obi->ob, eModifierType_Fluidsim);
- if (fluidmd && fluidmd->fss && (fluidmd->fss->type & OB_FLUIDSIM_DOMAIN)) {
- /* use preloaded per vertex simulation data, only does calculation for step=1 */
- /* NOTE/FIXME - velocities and meshes loaded unnecessarily often during the database_fromscene_vectors calls... */
- load_fluidsimspeedvectors(re, obi, oldobi->vectors, step);
- }
- else {
- /* check if both have same amounts of vertices */
- if (obi->totvector==oldobi->totvector)
- calculate_speedvectors(re, obi, oldobi->vectors, step);
- else
- printf("Warning: object %s has different amount of vertices or strands on other frame\n", obi->ob->id.name + 2);
- } /* not fluidsim */
-
- oldobi= oldobi->next;
- }
- }
- }
-
- free_dbase_object_vectors(&oldtable);
- free_dbase_object_vectors(&newtable);
-
- for (mesh=re->strandsurface.first; mesh; mesh=mesh->next) {
- if (mesh->prevco) {
- MEM_freeN(mesh->prevco);
- mesh->prevco= NULL;
- }
- if (mesh->nextco) {
- MEM_freeN(mesh->nextco);
- mesh->nextco= NULL;
- }
- }
-
- re->i.infostr = NULL;
- re->stats_draw(re->sdh, &re->i);
-}
-
-
-/* ------------------------------------------------------------------------- */
-/* Baking */
-/* ------------------------------------------------------------------------- */
-
-/* setup for shaded view or bake, so only lamps and materials are initialized */
-/* type:
- * RE_BAKE_LIGHT: for shaded view, only add lamps
- * RE_BAKE_ALL: for baking, all lamps and objects
- * RE_BAKE_NORMALS:for baking, no lamps and only selected objects
- * RE_BAKE_AO: for baking, no lamps, but all objects
- * RE_BAKE_TEXTURE:for baking, no lamps, only selected objects
- * RE_BAKE_VERTEX_COLORS:for baking, no lamps, only selected objects
- * RE_BAKE_DISPLACEMENT:for baking, no lamps, only selected objects
- * RE_BAKE_DERIVATIVE:for baking, no lamps, only selected objects
- * RE_BAKE_SHADOW: for baking, only shadows, but all objects
- */
-void RE_Database_Baking(Render *re, Main *bmain, Scene *scene, unsigned int lay, const int type, Object *actob)
-{
- Object *camera;
- float mat[4][4];
- float amb[3];
- const short onlyselected= !ELEM(type, RE_BAKE_LIGHT, RE_BAKE_ALL, RE_BAKE_SHADOW, RE_BAKE_AO, RE_BAKE_VERTEX_COLORS);
- const short nolamps= ELEM(type, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS);
-
- re->main= bmain;
- re->scene= scene;
- re->lay= lay;
-
- /* renderdata setup and exceptions */
- render_copy_renderdata(&re->r, &scene->r);
-
- RE_init_threadcount(re);
-
- re->flag |= R_BAKING;
- re->excludeob= actob;
- if (actob)
- re->flag |= R_BAKE_TRACE;
-
- if (type==RE_BAKE_NORMALS && re->r.bake_normal_space==R_BAKE_SPACE_TANGENT)
- re->flag |= R_NEED_TANGENT;
-
- if (type==RE_BAKE_VERTEX_COLORS)
- re->flag |= R_NEED_VCOL;
-
- if (!actob && ELEM(type, RE_BAKE_LIGHT, RE_BAKE_NORMALS, RE_BAKE_TEXTURE, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE, RE_BAKE_VERTEX_COLORS)) {
- re->r.mode &= ~R_SHADOW;
- re->r.mode &= ~R_RAYTRACE;
- }
-
- if (!actob && (type==RE_BAKE_SHADOW)) {
- re->r.mode |= R_SHADOW;
- }
-
- /* setup render stuff */
- re->memArena = BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "bake db arena");
-
- re->totvlak=re->totvert=re->totstrand=re->totlamp=re->tothalo= 0;
- re->lights.first= re->lights.last= NULL;
- re->lampren.first= re->lampren.last= NULL;
-
- /* in localview, lamps are using normal layers, objects only local bits */
- if (re->lay & 0xFF000000)
- lay &= 0xFF000000;
-
- camera= RE_GetCamera(re);
-
- /* if no camera, set unit */
- if (camera) {
- normalize_m4_m4(mat, camera->obmat);
- invert_m4(mat);
- RE_SetView(re, mat);
- }
- else {
- unit_m4(mat);
- RE_SetView(re, mat);
- }
- copy_m3_m4(re->imat, re->viewinv);
-
- /* TODO: deep shadow maps + baking + strands */
- /* strands use the window matrix and view size, there is to correct
- * window matrix but at least avoids malloc and crash loop [#27807] */
- unit_m4(re->winmat);
- re->winx= re->winy= 256;
- /* done setting dummy values */
-
- init_render_world(re); /* do first, because of ambient. also requires re->osa set correct */
- if (re->r.mode & R_RAYTRACE) {
- init_render_qmcsampler(re);
-
- if (re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT))
- if (re->wrld.ao_samp_method == WO_AOSAMP_CONSTANT)
- init_ao_sphere(re, &re->wrld);
- }
-
- /* still bad... doing all */
- init_render_textures(re);
-
- copy_v3_v3(amb, &re->wrld.ambr);
- init_render_materials(re->main, re->r.mode, amb, true);
-
- set_node_shader_lamp_loop(shade_material_loop);
-
- /* MAKE RENDER DATA */
- database_init_objects(re, lay, nolamps, onlyselected, actob, 0);
-
- set_material_lightgroups(re);
-
- /* SHADOW BUFFER */
- if (type!=RE_BAKE_LIGHT)
- if (re->r.mode & R_SHADOW)
- threaded_makeshadowbufs(re);
-
- /* raytree */
- if (!re->test_break(re->tbh))
- if (re->r.mode & R_RAYTRACE)
- makeraytree(re);
-
- /* point density texture */
- if (!re->test_break(re->tbh))
- make_pointdensities(re);
-
- /* voxel data texture */
- if (!re->test_break(re->tbh))
- make_voxeldata(re);
-
- /* occlusion */
- if ((re->wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && !re->test_break(re->tbh))
- if (re->wrld.ao_gather_method == WO_AOGATHER_APPROX)
- if (re->r.mode & R_SHADOW)
- make_occ_tree(re);
-
- re->i.convertdone = true;
-}
diff --git a/source/blender/render/intern/source/envmap.c b/source/blender/render/intern/source/envmap.c
deleted file mode 100644
index 40b249192f9..00000000000
--- a/source/blender/render/intern/source/envmap.c
+++ /dev/null
@@ -1,822 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributors: 2004/2005/2006 Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/envmap.c
- * \ingroup render
- */
-
-#include <math.h>
-#include <string.h>
-
-/* external modules: */
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_threads.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h" /* for rectcpy */
-
-#include "DNA_group_types.h"
-#include "DNA_image_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_texture_types.h"
-
-#include "BKE_main.h"
-#include "BKE_image.h" /* BKE_imbuf_write */
-#include "BKE_texture.h"
-#include "BKE_scene.h"
-
-/* this module */
-#include "render_types.h"
-#include "envmap.h"
-#include "renderdatabase.h"
-#include "renderpipeline.h"
-#include "texture.h"
-#include "zbuf.h"
-#include "render_result.h"
-
-/* ------------------------------------------------------------------------- */
-
-static void envmap_split_ima(EnvMap *env, ImBuf *ibuf)
-{
- int dx, part;
-
- /* after lock we test cube[1], if set the other thread has done it fine */
- BLI_thread_lock(LOCK_IMAGE);
- if (env->cube[1] == NULL) {
-
- BKE_texture_envmap_free_data(env);
-
- dx = ibuf->y;
- dx /= 2;
- if (3 * dx == ibuf->x) {
- env->type = ENV_CUBE;
- env->ok = ENV_OSA;
- }
- else if (ibuf->x == ibuf->y) {
- env->type = ENV_PLANE;
- env->ok = ENV_OSA;
- }
- else {
- printf("Incorrect envmap size\n");
- env->ok = 0;
- env->ima->ok = 0;
- }
-
- if (env->ok) {
- if (env->type == ENV_CUBE) {
- for (part = 0; part < 6; part++) {
- env->cube[part] = IMB_allocImBuf(dx, dx, 24, IB_rect | IB_rectfloat);
- }
- IMB_float_from_rect(ibuf);
-
- IMB_rectcpy(env->cube[0], ibuf,
- 0, 0, 0, 0, dx, dx);
- IMB_rectcpy(env->cube[1], ibuf,
- 0, 0, dx, 0, dx, dx);
- IMB_rectcpy(env->cube[2], ibuf,
- 0, 0, 2 * dx, 0, dx, dx);
- IMB_rectcpy(env->cube[3], ibuf,
- 0, 0, 0, dx, dx, dx);
- IMB_rectcpy(env->cube[4], ibuf,
- 0, 0, dx, dx, dx, dx);
- IMB_rectcpy(env->cube[5], ibuf,
- 0, 0, 2 * dx, dx, dx, dx);
-
- }
- else { /* ENV_PLANE */
- env->cube[1] = IMB_dupImBuf(ibuf);
- IMB_float_from_rect(env->cube[1]);
- }
- }
- }
- BLI_thread_unlock(LOCK_IMAGE);
-}
-
-/* ------------------------------------------------------------------------- */
-/* ****************** RENDER ********************** */
-
-/* copy current render */
-static Render *envmap_render_copy(Render *re, EnvMap *env)
-{
- Render *envre;
- float viewscale;
- int cuberes;
-
- envre = RE_NewRender("Envmap");
-
- env->lastsize = re->r.size;
- cuberes = (env->cuberes * re->r.size) / 100;
- cuberes &= 0xFFFC;
-
- /* this flag has R_ZTRA in it for example */
- envre->flag = re->flag;
-
- /* set up renderdata */
- render_copy_renderdata(&envre->r, &re->r);
- envre->r.mode &= ~(R_BORDER | R_PANORAMA | R_ORTHO | R_MBLUR);
- BLI_freelistN(&envre->r.layers);
- BLI_freelistN(&envre->r.views);
- envre->r.filtertype = 0;
- envre->r.tilex = envre->r.xsch / 2;
- envre->r.tiley = envre->r.ysch / 2;
- envre->r.size = 100;
- envre->r.yasp = envre->r.xasp = 1;
-
- RE_InitState(envre, NULL, &envre->r, NULL, cuberes, cuberes, NULL);
- envre->main = re->main;
- envre->scene = re->scene; /* unsure about this... */
- envre->scene_color_manage = re->scene_color_manage;
- envre->lay = re->lay;
-
- /* view stuff in env render */
- viewscale = (env->type == ENV_PLANE) ? env->viewscale : 1.0f;
- RE_SetEnvmapCamera(envre, env->object, viewscale, env->clipsta, env->clipend);
- copy_m4_m4(envre->viewmat_orig, re->viewmat_orig);
-
- /* callbacks */
- envre->display_update = re->display_update;
- envre->duh = re->duh;
- envre->test_break = re->test_break;
- envre->tbh = re->tbh;
- envre->current_scene_update = re->current_scene_update;
- envre->suh = re->suh;
-
- /* and for the evil stuff; copy the database... */
- envre->totvlak = re->totvlak;
- envre->totvert = re->totvert;
- envre->tothalo = re->tothalo;
- envre->totstrand = re->totstrand;
- envre->totlamp = re->totlamp;
- envre->sortedhalos = re->sortedhalos;
- envre->lights = re->lights;
- envre->objecttable = re->objecttable;
- envre->customdata_names = re->customdata_names;
- envre->raytree = re->raytree;
- envre->totinstance = re->totinstance;
- envre->instancetable = re->instancetable;
- envre->objectinstance = re->objectinstance;
- envre->qmcsamplers = re->qmcsamplers;
-
- return envre;
-}
-
-static void envmap_free_render_copy(Render *envre)
-{
-
- envre->totvlak = 0;
- envre->totvert = 0;
- envre->tothalo = 0;
- envre->totstrand = 0;
- envre->totlamp = 0;
- envre->totinstance = 0;
- envre->sortedhalos = NULL;
- BLI_listbase_clear(&envre->lights);
- BLI_listbase_clear(&envre->objecttable);
- BLI_listbase_clear(&envre->customdata_names);
- envre->raytree = NULL;
- BLI_listbase_clear(&envre->instancetable);
- envre->objectinstance = NULL;
- envre->qmcsamplers = NULL;
-
- RE_FreeRender(envre);
-}
-
-/* ------------------------------------------------------------------------- */
-
-static void envmap_transmatrix(float mat[4][4], int part)
-{
- float tmat[4][4], eul[3], rotmat[4][4];
-
- eul[0] = eul[1] = eul[2] = 0.0;
-
- if (part == 0) { /* neg z */
- /* pass */
- }
- else if (part == 1) { /* pos z */
- eul[0] = M_PI;
- }
- else if (part == 2) { /* pos y */
- eul[0] = M_PI / 2.0;
- }
- else if (part == 3) { /* neg x */
- eul[0] = M_PI / 2.0;
- eul[2] = M_PI / 2.0;
- }
- else if (part == 4) { /* neg y */
- eul[0] = M_PI / 2.0;
- eul[2] = M_PI;
- }
- else { /* pos x */
- eul[0] = M_PI / 2.0;
- eul[2] = -M_PI / 2.0;
- }
-
- copy_m4_m4(tmat, mat);
- eul_to_mat4(rotmat, eul);
- mul_m4_m4m4(mat, tmat, rotmat);
-}
-/* ------------------------------------------------------------------------- */
-
-static void env_set_imats(Render *re)
-{
- Base *base;
- float mat[4][4];
-
- base = re->scene->base.first;
- while (base) {
- mul_m4_m4m4(mat, re->viewmat, base->object->obmat);
- invert_m4_m4(base->object->imat, mat);
-
- base = base->next;
- }
-
-}
-
-/* ------------------------------------------------------------------------- */
-
-void env_rotate_scene(Render *re, float mat[4][4], int do_rotate)
-{
- ObjectRen *obr;
- ObjectInstanceRen *obi;
- LampRen *lar = NULL;
- HaloRen *har = NULL;
- float imat[3][3], mat_inverse[4][4], smat[4][4], tmat[4][4], cmat[3][3], tmpmat[4][4];
- int a;
-
- if (do_rotate == 0) {
- invert_m4_m4(tmat, mat);
- copy_m3_m4(imat, tmat);
-
- copy_m4_m4(mat_inverse, mat);
- }
- else {
- copy_m4_m4(tmat, mat);
- copy_m3_m4(imat, mat);
-
- invert_m4_m4(mat_inverse, tmat);
- }
-
- for (obi = re->instancetable.first; obi; obi = obi->next) {
- /* append or set matrix depending on dupli */
- if (obi->flag & R_DUPLI_TRANSFORMED) {
- copy_m4_m4(tmpmat, obi->mat);
- mul_m4_m4m4(obi->mat, tmat, tmpmat);
- }
- else if (do_rotate == 1)
- copy_m4_m4(obi->mat, tmat);
- else
- unit_m4(obi->mat);
-
- copy_m3_m4(cmat, obi->mat);
- invert_m3_m3(obi->nmat, cmat);
- transpose_m3(obi->nmat);
-
- /* indicate the renderer has to use transform matrices */
- if (do_rotate == 0)
- obi->flag &= ~R_ENV_TRANSFORMED;
- else {
- obi->flag |= R_ENV_TRANSFORMED;
- copy_m4_m4(obi->imat, mat_inverse);
- }
- }
-
-
- for (obr = re->objecttable.first; obr; obr = obr->next) {
- for (a = 0; a < obr->tothalo; a++) {
- if ((a & 255) == 0) har = obr->bloha[a >> 8];
- else har++;
-
- mul_m4_v3(tmat, har->co);
- }
-
- /* imat_ren is needed for correct texture coordinates */
- mul_m4_m4m4(obr->ob->imat_ren, re->viewmat, obr->ob->obmat);
- invert_m4(obr->ob->imat_ren);
- }
-
- for (lar = re->lampren.first; lar; lar = lar->next) {
- float lamp_imat[4][4];
-
- /* copy from add_render_lamp */
- if (do_rotate == 1)
- mul_m4_m4m4(tmpmat, re->viewmat, lar->lampmat);
- else
- mul_m4_m4m4(tmpmat, re->viewmat_orig, lar->lampmat);
-
- invert_m4_m4(lamp_imat, tmpmat);
- copy_m3_m4(lar->mat, tmpmat);
- copy_m3_m4(lar->imat, lamp_imat);
-
- lar->vec[0]= -tmpmat[2][0];
- lar->vec[1]= -tmpmat[2][1];
- lar->vec[2]= -tmpmat[2][2];
- normalize_v3(lar->vec);
- lar->co[0]= tmpmat[3][0];
- lar->co[1]= tmpmat[3][1];
- lar->co[2]= tmpmat[3][2];
-
- if (lar->type == LA_AREA) {
- area_lamp_vectors(lar);
- }
- else if (lar->type == LA_SPOT) {
- normalize_v3(lar->imat[0]);
- normalize_v3(lar->imat[1]);
- normalize_v3(lar->imat[2]);
-
- lar->sh_invcampos[0] = -lar->co[0];
- lar->sh_invcampos[1] = -lar->co[1];
- lar->sh_invcampos[2] = -lar->co[2];
- mul_m3_v3(lar->imat, lar->sh_invcampos);
- lar->sh_invcampos[2] *= lar->sh_zfac;
-
- if (lar->shb) {
- if (do_rotate == 1) {
- mul_m4_m4m4(smat, lar->shb->viewmat, mat_inverse);
- mul_m4_m4m4(lar->shb->persmat, lar->shb->winmat, smat);
- }
- else mul_m4_m4m4(lar->shb->persmat, lar->shb->winmat, lar->shb->viewmat);
- }
- }
- }
-
- if (do_rotate) {
- init_render_world(re);
- env_set_imats(re);
- }
-}
-
-/* ------------------------------------------------------------------------- */
-
-static void env_layerflags(Render *re, unsigned int notlay)
-{
- ObjectRen *obr;
- VlakRen *vlr = NULL;
- int a;
-
- /* invert notlay, so if face is in multiple layers it will still be visible,
- * unless all 'notlay' bits match the face bits.
- * face: 0110
- * not: 0100
- * ~not: 1011
- * now (face & ~not) is true
- */
-
- notlay = ~notlay;
-
- for (obr = re->objecttable.first; obr; obr = obr->next) {
- if ((obr->lay & notlay) == 0) {
- for (a = 0; a < obr->totvlak; a++) {
- if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak;
- else vlr++;
-
- vlr->flag |= R_HIDDEN;
- }
- }
- }
-}
-
-static void env_hideobject(Render *re, Object *ob)
-{
- ObjectRen *obr;
- VlakRen *vlr = NULL;
- int a;
-
- for (obr = re->objecttable.first; obr; obr = obr->next) {
- for (a = 0; a < obr->totvlak; a++) {
- if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak;
- else vlr++;
-
- if (obr->ob == ob)
- vlr->flag |= R_HIDDEN;
- }
- }
-}
-
-static void env_showobjects(Render *re)
-{
- ObjectRen *obr;
- VlakRen *vlr = NULL;
- int a;
-
- for (obr = re->objecttable.first; obr; obr = obr->next) {
- for (a = 0; a < obr->totvlak; a++) {
- if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak;
- else vlr++;
-
- vlr->flag &= ~R_HIDDEN;
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-
-static void render_envmap(Render *re, EnvMap *env)
-{
- /* only the cubemap and planar map is implemented */
- Render *envre;
- ImBuf *ibuf;
- float orthmat[4][4];
- float oldviewinv[4][4], mat[4][4], tmat[4][4];
- short part;
-
- /* need a recalc: ortho-render has no correct viewinv */
- invert_m4_m4(oldviewinv, re->viewmat);
-
- envre = envmap_render_copy(re, env);
-
- /* precalc orthmat for object */
- copy_m4_m4(orthmat, env->object->obmat);
- normalize_m4(orthmat);
-
- /* need imat later for texture imat */
- mul_m4_m4m4(mat, re->viewmat, orthmat);
- invert_m4_m4(tmat, mat);
- copy_m3_m4(env->obimat, tmat);
-
- for (part = 0; part < 6; part++) {
- if (env->type == ENV_PLANE && part != 1)
- continue;
-
- re->display_clear(re->dch, envre->result);
-
- copy_m4_m4(tmat, orthmat);
- envmap_transmatrix(tmat, part);
- invert_m4_m4(mat, tmat);
- /* mat now is the camera 'viewmat' */
-
- copy_m4_m4(envre->viewmat, mat);
- copy_m4_m4(envre->viewinv, tmat);
-
- /* we have to correct for the already rotated vertexcoords */
- mul_m4_m4m4(tmat, envre->viewmat, oldviewinv);
- invert_m4_m4(env->imat, tmat);
-
- env_rotate_scene(envre, tmat, 1);
- project_renderdata(envre, projectverto, 0, 0, 1);
- env_layerflags(envre, env->notlay);
- env_hideobject(envre, env->object);
-
- if (re->test_break(re->tbh) == 0) {
- RE_TileProcessor(envre);
- }
-
- /* rotate back */
- env_showobjects(envre);
- env_rotate_scene(envre, tmat, 0);
-
- if (re->test_break(re->tbh) == 0) {
- int y;
- float *alpha;
- float *rect;
-
- if (envre->result->do_exr_tile) {
- BLI_rw_mutex_lock(&envre->resultmutex, THREAD_LOCK_WRITE);
- render_result_exr_file_end(envre);
- BLI_rw_mutex_unlock(&envre->resultmutex);
- }
-
- RenderLayer *rl = envre->result->layers.first;
-
- /* envmap is rendered independently of multiview */
- rect = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, "");
- ibuf = IMB_allocImBuf(envre->rectx, envre->recty, 24, IB_rect | IB_rectfloat);
- memcpy(ibuf->rect_float, rect, ibuf->channels * ibuf->x * ibuf->y * sizeof(float));
-
- /* envmap renders without alpha */
- alpha = ibuf->rect_float + 3;
- for (y = ibuf->x * ibuf->y - 1; y >= 0; y--, alpha += 4)
- *alpha = 1.0;
-
- env->cube[part] = ibuf;
- }
-
- if (re->test_break(re->tbh)) break;
-
- }
-
- if (re->test_break(re->tbh)) BKE_texture_envmap_free_data(env);
- else {
- if (envre->r.mode & R_OSA) env->ok = ENV_OSA;
- else env->ok = ENV_NORMAL;
- env->lastframe = re->scene->r.cfra;
- }
-
- /* restore */
- envmap_free_render_copy(envre);
- env_set_imats(re);
-
-}
-
-/* ------------------------------------------------------------------------- */
-
-void make_envmaps(Render *re)
-{
- Tex *tex;
- bool do_init = false;
- int depth = 0, trace;
-
- if (!(re->r.mode & R_ENVMAP)) return;
-
- /* we don't raytrace, disabling the flag will cause ray_transp render solid */
- trace = (re->r.mode & R_RAYTRACE);
- re->r.mode &= ~R_RAYTRACE;
-
- re->i.infostr = IFACE_("Creating Environment maps");
- re->stats_draw(re->sdh, &re->i);
-
- /* 5 = hardcoded max recursion level */
- while (depth < 5) {
- tex = re->main->tex.first;
- while (tex) {
- if (tex->id.us && tex->type == TEX_ENVMAP) {
- if (tex->env && tex->env->object) {
- EnvMap *env = tex->env;
-
- if (env->object->lay & re->lay) {
- if (env->stype == ENV_LOAD) {
- float orthmat[4][4], mat[4][4], tmat[4][4];
-
- /* precalc orthmat for object */
- copy_m4_m4(orthmat, env->object->obmat);
- normalize_m4(orthmat);
-
- /* need imat later for texture imat */
- mul_m4_m4m4(mat, re->viewmat, orthmat);
- invert_m4_m4(tmat, mat);
- copy_m3_m4(env->obimat, tmat);
- }
- else {
-
- /* decide if to render an envmap (again) */
- if (env->depth >= depth) {
-
- /* set 'recalc' to make sure it does an entire loop of recalcs */
-
- if (env->ok) {
- /* free when OSA, and old one isn't OSA */
- if ((re->r.mode & R_OSA) && env->ok == ENV_NORMAL)
- BKE_texture_envmap_free_data(env);
- /* free when size larger */
- else if (env->lastsize < re->r.size)
- BKE_texture_envmap_free_data(env);
- /* free when env is in recalcmode */
- else if (env->recalc)
- BKE_texture_envmap_free_data(env);
- }
-
- if (env->ok == 0 && depth == 0) env->recalc = 1;
-
- if (env->ok == 0) {
- do_init = true;
- render_envmap(re, env);
-
- if (depth == env->depth) env->recalc = 0;
- }
- }
- }
- }
- }
- }
- tex = tex->id.next;
- }
- depth++;
- }
-
- if (do_init) {
- re->display_init(re->dih, re->result);
- re->display_clear(re->dch, re->result);
- // re->flag |= R_REDRAW_PRV;
- }
- /* restore */
- re->r.mode |= trace;
-
-}
-
-/* ------------------------------------------------------------------------- */
-
-static int envcube_isect(EnvMap *env, const float vec[3], float answ[2])
-{
- float lambda;
- int face;
-
- if (env->type == ENV_PLANE) {
- face = 1;
-
- lambda = 1.0f / vec[2];
- answ[0] = env->viewscale * lambda * vec[0];
- answ[1] = -env->viewscale * lambda * vec[1];
- }
- else {
- /* which face */
- if (vec[2] <= -fabsf(vec[0]) && vec[2] <= -fabsf(vec[1]) ) {
- face = 0;
- lambda = -1.0f / vec[2];
- answ[0] = lambda * vec[0];
- answ[1] = lambda * vec[1];
- }
- else if (vec[2] >= fabsf(vec[0]) && vec[2] >= fabsf(vec[1])) {
- face = 1;
- lambda = 1.0f / vec[2];
- answ[0] = lambda * vec[0];
- answ[1] = -lambda * vec[1];
- }
- else if (vec[1] >= fabsf(vec[0])) {
- face = 2;
- lambda = 1.0f / vec[1];
- answ[0] = lambda * vec[0];
- answ[1] = lambda * vec[2];
- }
- else if (vec[0] <= -fabsf(vec[1])) {
- face = 3;
- lambda = -1.0f / vec[0];
- answ[0] = lambda * vec[1];
- answ[1] = lambda * vec[2];
- }
- else if (vec[1] <= -fabsf(vec[0])) {
- face = 4;
- lambda = -1.0f / vec[1];
- answ[0] = -lambda * vec[0];
- answ[1] = lambda * vec[2];
- }
- else {
- face = 5;
- lambda = 1.0f / vec[0];
- answ[0] = -lambda * vec[1];
- answ[1] = lambda * vec[2];
- }
- }
-
- answ[0] = 0.5f + 0.5f * answ[0];
- answ[1] = 0.5f + 0.5f * answ[1];
- return face;
-}
-
-/* ------------------------------------------------------------------------- */
-
-static void set_dxtdyt(float r_dxt[3], float r_dyt[3], const float dxt[3], const float dyt[3], int face)
-{
- if (face == 2 || face == 4) {
- r_dxt[0] = dxt[0];
- r_dyt[0] = dyt[0];
- r_dxt[1] = dxt[2];
- r_dyt[1] = dyt[2];
- }
- else if (face == 3 || face == 5) {
- r_dxt[0] = dxt[1];
- r_dxt[1] = dxt[2];
- r_dyt[0] = dyt[1];
- r_dyt[1] = dyt[2];
- }
- else {
- r_dxt[0] = dxt[0];
- r_dyt[0] = dyt[0];
- r_dxt[1] = dxt[1];
- r_dyt[1] = dyt[1];
- }
-}
-
-/* ------------------------------------------------------------------------- */
-
-int envmaptex(Tex *tex, const float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres, struct ImagePool *pool, const bool skip_load_image)
-{
- extern Render R; /* only in this call */
- /* texvec should be the already reflected normal */
- EnvMap *env;
- ImBuf *ibuf;
- float fac, vec[3], sco[3], dxts[3], dyts[3];
- int face, face1;
-
- env = tex->env;
- if (env == NULL || (env->stype != ENV_LOAD && env->object == NULL)) {
- texres->tin = 0.0;
- return 0;
- }
-
- if (env->stype == ENV_LOAD) {
- env->ima = tex->ima;
- if (env->ima && env->ima->ok) {
- if (env->cube[1] == NULL) {
- ImBuf *ibuf_ima = BKE_image_pool_acquire_ibuf(env->ima, NULL, pool);
- if (ibuf_ima)
- envmap_split_ima(env, ibuf_ima);
- else
- env->ok = 0;
-
- if (env->type == ENV_PLANE)
- tex->extend = TEX_EXTEND;
-
- BKE_image_pool_release_ibuf(env->ima, ibuf_ima, pool);
- }
- }
- }
-
- if (env->ok == 0) {
- texres->tin = 0.0;
- return 0;
- }
-
- /* rotate to envmap space, if object is set */
- copy_v3_v3(vec, texvec);
- if (env->object) {
- mul_m3_v3(env->obimat, vec);
- if (osatex) {
- mul_m3_v3(env->obimat, dxt);
- mul_m3_v3(env->obimat, dyt);
- }
- }
- else {
- if (!BKE_scene_use_world_space_shading(R.scene)) {
- // texvec is in view space
- mul_mat3_m4_v3(R.viewinv, vec);
- if (osatex) {
- mul_mat3_m4_v3(R.viewinv, dxt);
- mul_mat3_m4_v3(R.viewinv, dyt);
- }
- }
- }
-
- face = envcube_isect(env, vec, sco);
- ibuf = env->cube[face];
-
- if (osatex) {
- set_dxtdyt(dxts, dyts, dxt, dyt, face);
- imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, texres, pool, skip_load_image);
-
- /* edges? */
-
- if (texres->ta < 1.0f) {
- TexResult texr1, texr2;
-
- texr1.nor = texr2.nor = NULL;
- texr1.talpha = texr2.talpha = texres->talpha; /* boxclip expects this initialized */
-
- add_v3_v3(vec, dxt);
- face1 = envcube_isect(env, vec, sco);
- sub_v3_v3(vec, dxt);
-
- if (face != face1) {
- ibuf = env->cube[face1];
- set_dxtdyt(dxts, dyts, dxt, dyt, face1);
- imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr1, pool, skip_load_image);
- }
- else texr1.tr = texr1.tg = texr1.tb = texr1.ta = 0.0;
-
- /* here was the nasty bug! results were not zero-ed. FPE! */
-
- add_v3_v3(vec, dyt);
- face1 = envcube_isect(env, vec, sco);
- sub_v3_v3(vec, dyt);
-
- if (face != face1) {
- ibuf = env->cube[face1];
- set_dxtdyt(dxts, dyts, dxt, dyt, face1);
- imagewraposa(tex, NULL, ibuf, sco, dxts, dyts, &texr2, pool, skip_load_image);
- }
- else texr2.tr = texr2.tg = texr2.tb = texr2.ta = 0.0;
-
- fac = (texres->ta + texr1.ta + texr2.ta);
- if (fac != 0.0f) {
- fac = 1.0f / fac;
-
- texres->tr = fac * (texres->ta * texres->tr + texr1.ta * texr1.tr + texr2.ta * texr2.tr);
- texres->tg = fac * (texres->ta * texres->tg + texr1.ta * texr1.tg + texr2.ta * texr2.tg);
- texres->tb = fac * (texres->ta * texres->tb + texr1.ta * texr1.tb + texr2.ta * texr2.tb);
- }
- texres->ta = 1.0;
- }
- }
- else {
- imagewrap(tex, NULL, ibuf, sco, texres, pool, skip_load_image);
- }
-
- return 1;
-}
diff --git a/source/blender/render/intern/source/external_engine.c b/source/blender/render/intern/source/external_engine.c
index fdf914102b0..1cdf4d3495b 100644
--- a/source/blender/render/intern/source/external_engine.c
+++ b/source/blender/render/intern/source/external_engine.c
@@ -41,12 +41,20 @@
#include "BLI_string.h"
#include "BLI_utildefines.h"
+#include "DNA_object_types.h"
+
#include "BKE_camera.h"
#include "BKE_global.h"
#include "BKE_colortools.h"
+#include "BKE_layer.h"
+#include "BKE_node.h"
#include "BKE_report.h"
#include "BKE_scene.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_debug.h"
+#include "DEG_depsgraph_query.h"
+
#include "RNA_access.h"
#ifdef WITH_PYTHON
@@ -57,46 +65,31 @@
#include "RE_pipeline.h"
#include "RE_bake.h"
+#include "DRW_engine.h"
+
#include "initrender.h"
#include "renderpipeline.h"
#include "render_types.h"
#include "render_result.h"
-#include "rendercore.h"
/* Render Engine Types */
-static RenderEngineType internal_render_type = {
- NULL, NULL,
- "BLENDER_RENDER", N_("Blender Render"), RE_INTERNAL,
- NULL, NULL, NULL, NULL, NULL, NULL, render_internal_update_passes,
- {NULL, NULL, NULL}
-};
-
-#ifdef WITH_GAMEENGINE
-
-static RenderEngineType internal_game_type = {
- NULL, NULL,
- "BLENDER_GAME", N_("Blender Game"), RE_INTERNAL | RE_GAME,
- NULL, NULL, NULL, NULL, NULL, NULL, NULL,
- {NULL, NULL, NULL}
-};
-
-#endif
-
ListBase R_engines = {NULL, NULL};
void RE_engines_init(void)
{
- BLI_addtail(&R_engines, &internal_render_type);
-#ifdef WITH_GAMEENGINE
- BLI_addtail(&R_engines, &internal_game_type);
-#endif
+ DRW_engines_register();
}
void RE_engines_exit(void)
{
RenderEngineType *type, *next;
+ DRW_engines_free();
+
+ BKE_layer_collection_engine_settings_callback_free();
+ BKE_view_layer_engine_settings_callback_free();
+
for (type = R_engines.first; type; type = next) {
next = type->next;
@@ -111,21 +104,43 @@ void RE_engines_exit(void)
}
}
+void RE_engines_register(Main *bmain, RenderEngineType *render_type)
+{
+ if (render_type->draw_engine) {
+ DRW_engine_register(render_type->draw_engine);
+ }
+ if (render_type->collection_settings_create) {
+ BKE_layer_collection_engine_settings_callback_register(
+ bmain, render_type->idname, render_type->collection_settings_create);
+ }
+ if (render_type->render_settings_create) {
+ BKE_view_layer_engine_settings_callback_register(
+ bmain, render_type->idname, render_type->render_settings_create);
+ }
+ BLI_addtail(&R_engines, render_type);
+}
+
RenderEngineType *RE_engines_find(const char *idname)
{
RenderEngineType *type;
type = BLI_findstring(&R_engines, idname, offsetof(RenderEngineType, idname));
if (!type)
- type = &internal_render_type;
+ type = BLI_findstring(&R_engines, "BLENDER_EEVEE", offsetof(RenderEngineType, idname));
return type;
}
bool RE_engine_is_external(Render *re)
{
- RenderEngineType *type = RE_engines_find(re->r.engine);
- return (type && type->render);
+ return (re->engine && re->engine->type && re->engine->type->render_to_image);
+}
+
+bool RE_engine_is_opengl(RenderEngineType *render_type)
+{
+ /* TODO refine? Can we have ogl render engine without ogl render pipeline? */
+ return (render_type->draw_engine != NULL) &&
+ DRW_engine_render_support(render_type->draw_engine);
}
/* Create, Free */
@@ -183,7 +198,8 @@ static RenderPart *get_part_from_result(Render *re, RenderResult *result)
return NULL;
}
-RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h, const char *layername, const char *viewname)
+RenderResult *RE_engine_begin_result(
+ RenderEngine *engine, int x, int y, int w, int h, const char *layername, const char *viewname)
{
Render *re = engine->re;
RenderResult *result;
@@ -413,7 +429,8 @@ float RE_engine_get_camera_shift_x(RenderEngine *engine, Object *camera, int use
return BKE_camera_multiview_shift_x(re ? &re->r : NULL, camera, re->viewname);
}
-void RE_engine_get_camera_model_matrix(RenderEngine *engine, Object *camera, int use_spherical_stereo, float *r_modelmat)
+void RE_engine_get_camera_model_matrix(
+ RenderEngine *engine, Object *camera, int use_spherical_stereo, float *r_modelmat)
{
Render *re = engine->re;
@@ -469,13 +486,6 @@ rcti* RE_engine_get_current_tiles(Render *re, int *r_total_tiles, bool *r_needs_
}
tiles[total_tiles] = pa->disprect;
- if (pa->crop) {
- tiles[total_tiles].xmin += pa->crop;
- tiles[total_tiles].ymin += pa->crop;
- tiles[total_tiles].xmax -= pa->crop;
- tiles[total_tiles].ymax -= pa->crop;
- }
-
total_tiles++;
}
}
@@ -489,6 +499,49 @@ RenderData *RE_engine_get_render_data(Render *re)
return &re->r;
}
+/* Depsgraph */
+static void engine_depsgraph_init(RenderEngine *engine, ViewLayer *view_layer)
+{
+ Main *bmain = engine->re->main;
+ Scene *scene = engine->re->scene;
+
+ engine->depsgraph = DEG_graph_new(scene, view_layer, DAG_EVAL_RENDER);
+ DEG_debug_name_set(engine->depsgraph, "RENDER");
+
+ BKE_scene_graph_update_tagged(engine->depsgraph, bmain);
+}
+
+static void engine_depsgraph_free(RenderEngine *engine)
+{
+ DEG_graph_free(engine->depsgraph);
+
+ engine->depsgraph = NULL;
+}
+
+void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
+{
+ if(!engine->depsgraph) {
+ return;
+ }
+
+ Render *re = engine->re;
+ double cfra = (double)frame + (double)subframe;
+
+ CLAMP(cfra, MINAFRAME, MAXFRAME);
+ BKE_scene_frame_set(re->scene, cfra);
+ BKE_scene_graph_update_for_newframe(engine->depsgraph, re->main);
+
+#ifdef WITH_PYTHON
+ BPy_BEGIN_ALLOW_THREADS;
+#endif
+
+#ifdef WITH_PYTHON
+ BPy_END_ALLOW_THREADS;
+#endif
+
+ BKE_scene_camera_switch_update(re->scene);
+}
+
/* Bake */
void RE_bake_engine_set_engine_parameters(Render *re, Main *bmain, Scene *scene)
{
@@ -504,7 +557,7 @@ bool RE_bake_has_engine(Render *re)
}
bool RE_bake_engine(
- Render *re, Object *object,
+ Render *re, ViewLayer *view_layer, Object *object,
const int object_id, const BakePixel pixel_array[],
const size_t num_pixels, const int depth,
const eScenePassType pass_type, const int pass_filter,
@@ -535,7 +588,7 @@ bool RE_bake_engine(
engine->resolution_x = re->winx;
engine->resolution_y = re->winy;
- RE_parts_init(re, false);
+ RE_parts_init(re);
engine->tile_x = re->r.tilex;
engine->tile_y = re->r.tiley;
@@ -543,8 +596,23 @@ bool RE_bake_engine(
if (type->update)
type->update(engine, re->main, re->scene);
- if (type->bake)
- type->bake(engine, re->scene, object, pass_type, pass_filter, object_id, pixel_array, num_pixels, depth, result);
+ if (type->bake) {
+ engine_depsgraph_init(engine, view_layer);
+
+ type->bake(engine,
+ engine->depsgraph,
+ re->scene,
+ object,
+ pass_type,
+ pass_filter,
+ object_id,
+ pixel_array,
+ num_pixels,
+ depth,
+ result);
+
+ engine_depsgraph_free(engine);
+ }
engine->tile_x = 0;
engine->tile_y = 0;
@@ -567,42 +635,8 @@ bool RE_bake_engine(
return true;
}
-void RE_engine_frame_set(RenderEngine *engine, int frame, float subframe)
-{
- Render *re = engine->re;
- Scene *scene = re->scene;
- double cfra = (double)frame + (double)subframe;
-
- CLAMP(cfra, MINAFRAME, MAXFRAME);
- BKE_scene_frame_set(scene, cfra);
-
-#ifdef WITH_PYTHON
- BPy_BEGIN_ALLOW_THREADS;
-#endif
-
- /* It's possible that here we're including layers which were never visible before. */
- BKE_scene_update_for_newframe_ex(re->eval_ctx, re->main, scene, (1 << 20) - 1, true);
-
-#ifdef WITH_PYTHON
- BPy_END_ALLOW_THREADS;
-#endif
-
- BKE_scene_camera_switch_update(scene);
-}
-
/* Render */
-static bool render_layer_exclude_animated(Scene *scene, SceneRenderLayer *srl)
-{
- PointerRNA ptr;
- PropertyRNA *prop;
-
- RNA_pointer_create(&scene->id, &RNA_SceneRenderLayer, srl, &ptr);
- prop = RNA_struct_find_property(&ptr, "layers_exclude");
-
- return RNA_property_animated(&ptr, prop);
-}
-
int RE_engine_render(Render *re, int do_all)
{
RenderEngineType *type = RE_engines_find(re->r.engine);
@@ -610,7 +644,7 @@ int RE_engine_render(Render *re, int do_all)
bool persistent_data = (re->r.mode & R_PERSISTENT_DATA) != 0;
/* verify if we can render */
- if (!type->render)
+ if (!type->render_to_image)
return 0;
if ((re->r.scemode & R_BUTS_PREVIEW) && !(type->flag & RE_USE_PREVIEW))
return 0;
@@ -627,41 +661,7 @@ int RE_engine_render(Render *re, int do_all)
/* update animation here so any render layer animation is applied before
* creating the render result */
if ((re->r.scemode & (R_NO_FRAME_UPDATE | R_BUTS_PREVIEW)) == 0) {
- unsigned int lay = re->lay;
-
- /* don't update layers excluded on all render layers */
- if (type->flag & RE_USE_EXCLUDE_LAYERS) {
- SceneRenderLayer *srl;
- unsigned int non_excluded_lay = 0;
-
- if (re->r.scemode & R_SINGLE_LAYER) {
- srl = BLI_findlink(&re->r.layers, re->r.actlay);
- if (srl) {
- non_excluded_lay |= ~(srl->lay_exclude & ~srl->lay_zmask);
-
- /* in this case we must update all because animation for
- * the scene has not been updated yet, and so may not be
- * up to date until after BKE_scene_update_for_newframe */
- if (render_layer_exclude_animated(re->scene, srl))
- non_excluded_lay |= ~0;
- }
- }
- else {
- for (srl = re->r.layers.first; srl; srl = srl->next) {
- if (!(srl->layflag & SCE_LAY_DISABLE)) {
- non_excluded_lay |= ~(srl->lay_exclude & ~srl->lay_zmask);
-
- if (render_layer_exclude_animated(re->scene, srl))
- non_excluded_lay |= ~0;
- }
- }
- }
-
- lay &= non_excluded_lay;
- }
-
- BKE_scene_update_for_newframe_ex(re->eval_ctx, re->main, re->scene, lay, true);
- render_update_anim_renderdata(re, &re->scene->r);
+ render_update_anim_renderdata(re, &re->scene->r, &re->scene->view_layers);
}
/* create render result */
@@ -719,23 +719,34 @@ int RE_engine_render(Render *re, int do_all)
engine->resolution_x = re->winx;
engine->resolution_y = re->winy;
- RE_parts_init(re, false);
+ RE_parts_init(re);
engine->tile_x = re->partx;
engine->tile_y = re->party;
if (re->result->do_exr_tile)
render_result_exr_file_begin(re);
- if (type->update)
+ if (type->update) {
type->update(engine, re->main, re->scene);
+ }
/* Clear UI drawing locks. */
if (re->draw_lock) {
re->draw_lock(re->dlh, 0);
}
- if (type->render)
- type->render(engine, re->scene);
+ if (type->render_to_image) {
+ FOREACH_VIEW_LAYER_TO_RENDER_BEGIN(re, view_layer_iter)
+ {
+ ViewLayer *view_layer = BLI_findstring(&re->scene->view_layers, view_layer_iter->name, offsetof(ViewLayer, name));
+ engine_depsgraph_init(engine, view_layer);
+
+ type->render_to_image(engine, engine->depsgraph);
+
+ engine_depsgraph_free(engine);
+ }
+ FOREACH_VIEW_LAYER_TO_RENDER_END;
+ }
engine->tile_x = 0;
engine->tile_y = 0;
@@ -778,12 +789,12 @@ int RE_engine_render(Render *re, int do_all)
return 1;
}
-void RE_engine_register_pass(struct RenderEngine *engine, struct Scene *scene, struct SceneRenderLayer *srl,
+void RE_engine_register_pass(struct RenderEngine *engine, struct Scene *scene, struct ViewLayer *view_layer,
const char *name, int UNUSED(channels), const char *UNUSED(chanid), int type)
{
/* The channel information is currently not used, but is part of the API in case it's needed in the future. */
- if (!(scene && srl && engine)) {
+ if (!(scene && view_layer && engine)) {
return;
}
@@ -793,7 +804,7 @@ void RE_engine_register_pass(struct RenderEngine *engine, struct Scene *scene, s
Scene *sce;
for (sce = G.main->scene.first; sce; sce = sce->id.next) {
if (sce->nodetree) {
- ntreeCompositRegisterPass(sce->nodetree, scene, srl, name, type);
+ ntreeCompositRegisterPass(sce->nodetree, scene, view_layer, name, type);
}
}
}
diff --git a/source/blender/render/intern/source/imagetexture.c b/source/blender/render/intern/source/imagetexture.c
index 6e5d10fcc84..db28a5db531 100644
--- a/source/blender/render/intern/source/imagetexture.c
+++ b/source/blender/render/intern/source/imagetexture.c
@@ -53,16 +53,11 @@
#include "BKE_image.h"
#include "RE_render_ext.h"
+#include "RE_shader_ext.h"
#include "render_types.h"
#include "texture.h"
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
static void boxsample(ImBuf *ibuf, float minx, float miny, float maxx, float maxy, TexResult *texres, const short imaprepeat, const short imapextend);
/* *********** IMAGEWRAPPING ****************** */
@@ -211,11 +206,6 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul
}
}
- /* warning, no return before setting back! */
- if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
- ibuf->rect+= (ibuf->x*ibuf->y);
- }
-
/* keep this before interpolation [#29761] */
if (ima) {
if ((tex->imaflag & TEX_USEALPHA) && (ima->flag & IMA_IGNORE_ALPHA) == 0) {
@@ -243,10 +233,6 @@ int imagewrap(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], TexResul
ibuf_get_color(&texres->tr, ibuf, x, y);
}
- if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
- ibuf->rect-= (ibuf->x*ibuf->y);
- }
-
if (texres->nor) {
if (tex->imaflag & TEX_NORMALMAP) {
/* qdn: normal from color
@@ -979,17 +965,6 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex
fy = texvec[1];
}
- if (ibuf->flags & IB_fields) {
- if (R.r.mode & R_FIELDS) { /* field render */
- if (R.flag & R_SEC_FIELD) { /* correction for 2nd field */
- /* fac1= 0.5/( (float)ibuf->y ); */
- /* fy-= fac1; */
- }
- else /* first field */
- fy += 0.5f/( (float)ibuf->y );
- }
- }
-
/* pixel coordinates */
minx = min_fff(dxt[0], dyt[0], dxt[0] + dyt[0]);
maxx = max_fff(dxt[0], dyt[0], dxt[0] + dyt[0]);
@@ -1129,10 +1104,6 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex
intpol = tex->imaflag & TEX_INTERPOL;
- /* warning no return! */
- if ((R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields))
- ibuf->rect += ibuf->x*ibuf->y;
-
/* struct common data */
copy_v2_v2(AFD.dxt, dxt);
copy_v2_v2(AFD.dyt, dyt);
@@ -1311,9 +1282,6 @@ static int imagewraposa_aniso(Tex *tex, Image *ima, ImBuf *ibuf, const float tex
texres->tin = texres->ta;
if (tex->flag & TEX_NEGALPHA) texres->ta = 1.f - texres->ta;
- if ((R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields))
- ibuf->rect -= ibuf->x*ibuf->y;
-
if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) { /* normal from color */
/* The invert of the red channel is to make
* the normal map compliant with the outside world.
@@ -1411,18 +1379,6 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const
fy= texvec[1];
}
- if (ibuf->flags & IB_fields) {
- if (R.r.mode & R_FIELDS) { /* field render */
- if (R.flag & R_SEC_FIELD) { /* correction for 2nd field */
- /* fac1= 0.5/( (float)ibuf->y ); */
- /* fy-= fac1; */
- }
- else { /* first field */
- fy+= 0.5f/( (float)ibuf->y );
- }
- }
- }
-
/* pixel coordinates */
minx = min_fff(dxt[0], dyt[0], dxt[0] + dyt[0]);
@@ -1580,11 +1536,6 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const
}
}
- /* warning no return! */
- if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
- ibuf->rect+= (ibuf->x*ibuf->y);
- }
-
/* choice: */
if (tex->imaflag & TEX_MIPMAP) {
ImBuf *previbuf, *curibuf;
@@ -1731,10 +1682,6 @@ int imagewraposa(Tex *tex, Image *ima, ImBuf *ibuf, const float texvec[3], const
if (tex->flag & TEX_NEGALPHA) texres->ta= 1.0f-texres->ta;
- if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) ) {
- ibuf->rect-= (ibuf->x*ibuf->y);
- }
-
if (texres->nor && (tex->imaflag & TEX_NORMALMAP)) {
/* qdn: normal from color
* The invert of the red channel is to make
@@ -1772,16 +1719,10 @@ void image_sample(Image *ima, float fx, float fy, float dx, float dy, float resu
return;
}
- if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
- ibuf->rect+= (ibuf->x*ibuf->y);
-
texres.talpha = true; /* boxsample expects to be initialized */
boxsample(ibuf, fx, fy, fx + dx, fy + dy, &texres, 0, 1);
copy_v4_v4(result, &texres.tr);
- if ( (R.flag & R_SEC_FIELD) && (ibuf->flags & IB_fields) )
- ibuf->rect-= (ibuf->x*ibuf->y);
-
ima->flag|= IMA_USED_FOR_RENDER;
BKE_image_pool_release_ibuf(ima, ibuf, pool);
diff --git a/source/blender/render/intern/source/initrender.c b/source/blender/render/intern/source/initrender.c
index ce3331e9a92..4274d641674 100644
--- a/source/blender/render/intern/source/initrender.c
+++ b/source/blender/render/intern/source/initrender.c
@@ -38,13 +38,9 @@
#include "BLI_math.h"
#include "BLI_blenlib.h"
-#include "BLI_jitter_2d.h"
#include "BLI_utildefines.h"
#include "DNA_camera_types.h"
-#include "DNA_image_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
#include "BKE_camera.h"
@@ -56,31 +52,6 @@
#include "initrender.h"
-/* ********************** */
-
-static void init_render_jit(Render *re)
-{
- static float jit[32][2]; /* simple caching */
- static float mblur_jit[32][2]; /* simple caching */
- static int lastjit = 0;
- static int last_mblur_jit = 0;
-
- if (lastjit != re->r.osa || last_mblur_jit != re->r.mblur_samples) {
- memset(jit, 0, sizeof(jit));
- BLI_jitter_init(jit, re->r.osa);
-
- memset(mblur_jit, 0, sizeof(mblur_jit));
- BLI_jitter_init(mblur_jit, re->r.mblur_samples);
- }
-
- lastjit = re->r.osa;
- memcpy(re->jit, jit, sizeof(jit));
-
- last_mblur_jit = re->r.mblur_samples;
- memcpy(re->mblur_jit, mblur_jit, sizeof(mblur_jit));
-}
-
-
/* ****************** MASKS and LUTS **************** */
static float filt_quadratic(float x)
@@ -171,256 +142,6 @@ float RE_filter_value(int type, float x)
return 0.0f;
}
-static float calc_weight(Render *re, float *weight, int i, int j)
-{
- float x, y, dist, totw = 0.0;
- int a;
-
- for (a = 0; a < re->osa; a++) {
- x = re->jit[a][0] + i;
- y = re->jit[a][1] + j;
- dist = sqrtf(x * x + y * y);
-
- weight[a] = 0.0;
-
- /* Weighting choices */
- switch (re->r.filtertype) {
- case R_FILTER_BOX:
- if (i == 0 && j == 0) weight[a] = 1.0;
- break;
-
- case R_FILTER_TENT:
- if (dist < re->r.gauss)
- weight[a] = re->r.gauss - dist;
- break;
-
- case R_FILTER_GAUSS:
- x = dist * re->r.gauss;
- weight[a] = (1.0f / expf(x * x) - 1.0f / expf(re->r.gauss * re->r.gauss * 2.25f));
- break;
-
- case R_FILTER_MITCH:
- weight[a] = filt_mitchell(dist * re->r.gauss);
- break;
-
- case R_FILTER_QUAD:
- weight[a] = filt_quadratic(dist * re->r.gauss);
- break;
-
- case R_FILTER_CUBIC:
- weight[a] = filt_cubic(dist * re->r.gauss);
- break;
-
- case R_FILTER_CATROM:
- weight[a] = filt_catrom(dist * re->r.gauss);
- break;
-
- }
-
- totw += weight[a];
-
- }
- return totw;
-}
-
-void free_sample_tables(Render *re)
-{
- int a;
-
- if (re->samples) {
- for (a = 0; a < 9; a++) {
- MEM_freeN(re->samples->fmask1[a]);
- MEM_freeN(re->samples->fmask2[a]);
- }
-
- MEM_freeN(re->samples->centmask);
- MEM_freeN(re->samples);
- re->samples = NULL;
- }
-}
-
-/* based on settings in render, it makes the lookup tables */
-void make_sample_tables(Render *re)
-{
- static int firsttime = 1;
- SampleTables *st;
- float flweight[32];
- float weight[32], totw, val, *fpx1, *fpx2, *fpy1, *fpy2, *m3, *m4;
- int i, j, a, centmasksize;
-
- /* optimization tables, only once */
- if (firsttime) {
- firsttime = 0;
- }
-
- free_sample_tables(re);
-
- init_render_jit(re); /* needed for mblur too */
-
- if (re->osa == 0) {
- /* just prevents cpu cycles for larger render and copying */
- re->r.filtertype = 0;
- return;
- }
-
- st = re->samples = MEM_callocN(sizeof(SampleTables), "sample tables");
-
- for (a = 0; a < 9; a++) {
- st->fmask1[a] = MEM_callocN(256 * sizeof(float), "initfilt");
- st->fmask2[a] = MEM_callocN(256 * sizeof(float), "initfilt");
- }
- for (a = 0; a < 256; a++) {
- st->cmask[a] = 0;
- if (a & 1) st->cmask[a]++;
- if (a & 2) st->cmask[a]++;
- if (a & 4) st->cmask[a]++;
- if (a & 8) st->cmask[a]++;
- if (a & 16) st->cmask[a]++;
- if (a & 32) st->cmask[a]++;
- if (a & 64) st->cmask[a]++;
- if (a & 128) st->cmask[a]++;
- }
-
- centmasksize = (1 << re->osa);
- st->centmask = MEM_mallocN(centmasksize, "Initfilt3");
-
- for (a = 0; a < 16; a++) {
- st->centLut[a] = -0.45f + ((float)a) / 16.0f;
- }
-
- /* calculate totw */
- totw = 0.0;
- for (j = -1; j < 2; j++) {
- for (i = -1; i < 2; i++) {
- totw += calc_weight(re, weight, i, j);
- }
- }
-
- for (j = -1; j < 2; j++) {
- for (i = -1; i < 2; i++) {
- /* calculate using jit, with offset the weights */
-
- memset(weight, 0, sizeof(weight));
- calc_weight(re, weight, i, j);
-
- for (a = 0; a < 16; a++) flweight[a] = weight[a] * (1.0f / totw);
-
- m3 = st->fmask1[3 * (j + 1) + i + 1];
- m4 = st->fmask2[3 * (j + 1) + i + 1];
-
- for (a = 0; a < 256; a++) {
- if (a & 1) {
- m3[a] += flweight[0];
- m4[a] += flweight[8];
- }
- if (a & 2) {
- m3[a] += flweight[1];
- m4[a] += flweight[9];
- }
- if (a & 4) {
- m3[a] += flweight[2];
- m4[a] += flweight[10];
- }
- if (a & 8) {
- m3[a] += flweight[3];
- m4[a] += flweight[11];
- }
- if (a & 16) {
- m3[a] += flweight[4];
- m4[a] += flweight[12];
- }
- if (a & 32) {
- m3[a] += flweight[5];
- m4[a] += flweight[13];
- }
- if (a & 64) {
- m3[a] += flweight[6];
- m4[a] += flweight[14];
- }
- if (a & 128) {
- m3[a] += flweight[7];
- m4[a] += flweight[15];
- }
- }
- }
- }
-
- /* centmask: the correct subpixel offset per mask */
-
- fpx1 = MEM_mallocN(256 * sizeof(float), "initgauss4");
- fpx2 = MEM_mallocN(256 * sizeof(float), "initgauss4");
- fpy1 = MEM_mallocN(256 * sizeof(float), "initgauss4");
- fpy2 = MEM_mallocN(256 * sizeof(float), "initgauss4");
- for (a = 0; a < 256; a++) {
- fpx1[a] = fpx2[a] = 0.0;
- fpy1[a] = fpy2[a] = 0.0;
- if (a & 1) {
- fpx1[a] += re->jit[0][0];
- fpy1[a] += re->jit[0][1];
- fpx2[a] += re->jit[8][0];
- fpy2[a] += re->jit[8][1];
- }
- if (a & 2) {
- fpx1[a] += re->jit[1][0];
- fpy1[a] += re->jit[1][1];
- fpx2[a] += re->jit[9][0];
- fpy2[a] += re->jit[9][1];
- }
- if (a & 4) {
- fpx1[a] += re->jit[2][0];
- fpy1[a] += re->jit[2][1];
- fpx2[a] += re->jit[10][0];
- fpy2[a] += re->jit[10][1];
- }
- if (a & 8) {
- fpx1[a] += re->jit[3][0];
- fpy1[a] += re->jit[3][1];
- fpx2[a] += re->jit[11][0];
- fpy2[a] += re->jit[11][1];
- }
- if (a & 16) {
- fpx1[a] += re->jit[4][0];
- fpy1[a] += re->jit[4][1];
- fpx2[a] += re->jit[12][0];
- fpy2[a] += re->jit[12][1];
- }
- if (a & 32) {
- fpx1[a] += re->jit[5][0];
- fpy1[a] += re->jit[5][1];
- fpx2[a] += re->jit[13][0];
- fpy2[a] += re->jit[13][1];
- }
- if (a & 64) {
- fpx1[a] += re->jit[6][0];
- fpy1[a] += re->jit[6][1];
- fpx2[a] += re->jit[14][0];
- fpy2[a] += re->jit[14][1];
- }
- if (a & 128) {
- fpx1[a] += re->jit[7][0];
- fpy1[a] += re->jit[7][1];
- fpx2[a] += re->jit[15][0];
- fpy2[a] += re->jit[15][1];
- }
- }
-
- for (a = centmasksize - 1; a > 0; a--) {
- val = st->cmask[a & 255] + st->cmask[a >> 8];
- i = 8 + (15.9f * (fpy1[a & 255] + fpy2[a >> 8]) / val);
- CLAMP(i, 0, 15);
- j = 8 + (15.9f * (fpx1[a & 255] + fpx2[a >> 8]) / val);
- CLAMP(j, 0, 15);
- i = j + (i << 4);
- st->centmask[a] = i;
- }
-
- MEM_freeN(fpx1);
- MEM_freeN(fpx2);
- MEM_freeN(fpy1);
- MEM_freeN(fpy2);
-}
-
-
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
struct Object *RE_GetCamera(Render *re)
{
@@ -435,37 +156,11 @@ static void re_camera_params_get(Render *re, CameraParams *params, Object *cam_o
re->clipsta = params->clipsta;
re->clipend = params->clipend;
- re->ycor = params->ycor;
- re->viewdx = params->viewdx;
- re->viewdy = params->viewdy;
re->viewplane = params->viewplane;
BKE_camera_object_mode(&re->r, cam_ob);
}
-void RE_SetEnvmapCamera(Render *re, Object *cam_ob, float viewscale, float clipsta, float clipend)
-{
- CameraParams params;
-
- /* setup parameters */
- BKE_camera_params_init(&params);
- BKE_camera_params_from_object(&params, cam_ob);
-
- params.lens = 16.0f * viewscale;
- params.sensor_x = 32.0f;
- params.sensor_y = 32.0f;
- params.sensor_fit = CAMERA_SENSOR_FIT_AUTO;
- params.clipsta = clipsta;
- params.clipend = clipend;
-
- /* compute matrix, viewplane, .. */
- BKE_camera_params_compute_viewplane(&params, re->winx, re->winy, 1.0f, 1.0f);
- BKE_camera_params_compute_matrix(&params);
-
- /* extract results */
- re_camera_params_get(re, &params, cam_ob);
-}
-
void RE_SetOverrideCamera(Render *re, Object *camera)
{
re->camera_override = camera;
@@ -487,10 +182,6 @@ void RE_SetCamera(Render *re, Object *cam_ob)
BKE_camera_params_from_object(&params, cam_ob);
re_camera_params_stereo3d(re, &params, cam_ob);
- params.use_fields = (re->r.mode & R_FIELDS);
- params.field_second = (re->flag & R_SEC_FIELD);
- params.field_odd = (re->r.mode & R_ODDFIELD);
-
/* compute matrix, viewplane, .. */
BKE_camera_params_compute_viewplane(&params, re->winx, re->winy, re->r.xasp, re->r.yasp);
BKE_camera_params_compute_matrix(&params);
@@ -499,12 +190,6 @@ void RE_SetCamera(Render *re, Object *cam_ob)
re_camera_params_get(re, &params, cam_ob);
}
-void RE_SetPixelSize(Render *re, float pixsize)
-{
- re->viewdx = pixsize;
- re->viewdy = re->ycor * pixsize;
-}
-
void RE_GetCameraWindow(struct Render *re, struct Object *camera, int frame, float mat[4][4])
{
re->r.cfra = frame;
@@ -522,13 +207,6 @@ void RE_GetCameraModelMatrix(Render *re, struct Object *camera, float r_mat[4][4
void RE_parts_free(Render *re)
{
- RenderPart *part = re->parts.first;
-
- while (part) {
- if (part->rectp) MEM_freeN(part->rectp);
- if (part->rectz) MEM_freeN(part->rectz);
- part = part->next;
- }
BLI_freelistN(&re->parts);
}
@@ -539,7 +217,7 @@ void RE_parts_clamp(Render *re)
re->party = max_ii(1, min_ii(re->r.tiley, re->recty));
}
-void RE_parts_init(Render *re, bool do_crop)
+void RE_parts_init(Render *re)
{
int nr, xd, yd, partx, party, xparts, yparts;
int xminb, xmaxb, yminb, ymaxb;
@@ -565,10 +243,6 @@ void RE_parts_init(Render *re, bool do_crop)
xparts = (re->rectx + partx - 1) / partx;
yparts = (re->recty + party - 1) / party;
- /* calculate rotation factor of 1 pixel */
- if (re->r.mode & R_PANORAMA)
- re->panophi = panorama_pixel_rot(re);
-
for (nr = 0; nr < xparts * yparts; nr++) {
rcti disprect;
int rectx, recty;
@@ -601,16 +275,6 @@ void RE_parts_init(Render *re, bool do_crop)
if (rectx > 0 && recty > 0) {
RenderPart *pa = MEM_callocN(sizeof(RenderPart), "new part");
- /* Non-box filters need 2 pixels extra to work */
- if (do_crop && (re->r.filtertype || (re->r.mode & R_EDGE))) {
- pa->crop = 2;
- disprect.xmin -= pa->crop;
- disprect.ymin -= pa->crop;
- disprect.xmax += pa->crop;
- disprect.ymax += pa->crop;
- rectx += 2 * pa->crop;
- recty += 2 * pa->crop;
- }
pa->disprect = disprect;
pa->rectx = rectx;
pa->recty = recty;
diff --git a/source/blender/render/intern/source/multires_bake.c b/source/blender/render/intern/source/multires_bake.c
index d85cc87dfe3..d506028e306 100644
--- a/source/blender/render/intern/source/multires_bake.c
+++ b/source/blender/render/intern/source/multires_bake.c
@@ -36,20 +36,23 @@
#include "DNA_object_types.h"
#include "DNA_mesh_types.h"
+#include "DNA_scene_types.h"
#include "BLI_math.h"
#include "BLI_listbase.h"
#include "BLI_threads.h"
#include "BKE_ccg.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
+#include "BKE_material.h"
#include "BKE_mesh.h"
#include "BKE_multires.h"
#include "BKE_modifier.h"
#include "BKE_subsurf.h"
+#include "DEG_depsgraph.h"
+
#include "RE_multires_bake.h"
#include "RE_pipeline.h"
#include "RE_shader_ext.h"
@@ -57,10 +60,6 @@
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "rendercore.h"
-
typedef void (*MPassKnownData)(DerivedMesh *lores_dm, DerivedMesh *hires_dm, void *thread_data,
void *bake_data, ImBuf *ibuf, const int face_index, const int lvl,
const float st[2], float tangmat[3][3], const int x, const int y);
@@ -78,7 +77,6 @@ typedef struct {
MLoop *mloop;
MLoopUV *mloopuv;
const MLoopTri *mlooptri;
- MTexPoly *mtpoly;
float *pvtangent;
const float *precomputed_normals;
int w, h;
@@ -89,6 +87,8 @@ typedef struct {
void *bake_data;
ImBuf *ibuf;
MPassKnownData pass_data;
+ /* material aligned UV array */
+ Image **image_array;
} MResolvePixelData;
typedef void (*MFlushPixel)(const MResolvePixelData *data, const int x, const int y);
@@ -112,19 +112,6 @@ typedef struct {
const int *orig_index_mp_to_orig;
} MNormalBakeData;
-typedef struct {
- int number_of_rays;
- float bias;
-
- unsigned short *permutation_table_1;
- unsigned short *permutation_table_2;
-
- RayObject *raytree;
- RayFace *rayfaces;
-
- const int *orig_index_mp_to_orig;
-} MAOBakeData;
-
static void multiresbake_get_normal(const MResolvePixelData *data, float norm[],const int tri_num, const int vert_index)
{
const int poly_index = data->mlooptri[tri_num].poly;
@@ -373,13 +360,15 @@ static void *do_multires_bake_thread(void *data_v)
while ((tri_index = multires_bake_queue_next_tri(handle->queue)) >= 0) {
const MLoopTri *lt = &data->mlooptri[tri_index];
- MTexPoly *mtpoly = &data->mtpoly[lt->poly];
- MLoopUV *mloopuv = data->mloopuv;
+ const MPoly *mp = &data->mpoly[lt->poly];
+ const short mat_nr = mp->mat_nr;
+ const MLoopUV *mloopuv = data->mloopuv;
if (multiresbake_test_break(bkr))
break;
- if (mtpoly->tpage != handle->image)
+ Image *tri_image = mat_nr < bkr->ob_image.len ? bkr->ob_image.array[mat_nr] : NULL;
+ if (tri_image != handle->image)
continue;
data->tri_index = tri_index;
@@ -445,7 +434,6 @@ static void do_multires_bake(MultiresBakeRender *bkr, Image *ima, bool require_t
MPoly *mpoly = dm->getPolyArray(dm);
MLoop *mloop = dm->getLoopArray(dm);
MLoopUV *mloopuv = dm->getLoopDataArray(dm, CD_MLOOPUV);
- MTexPoly *mtpoly = dm->getPolyDataArray(dm, CD_MTEXPOLY);
const float *precomputed_normals = dm->getPolyDataArray(dm, CD_NORMAL);
float *pvtangent = NULL;
@@ -489,7 +477,6 @@ static void do_multires_bake(MultiresBakeRender *bkr, Image *ima, bool require_t
handle->data.mvert = mvert;
handle->data.mloopuv = mloopuv;
handle->data.mlooptri = mlooptri;
- handle->data.mtpoly = mtpoly;
handle->data.mloop = mloop;
handle->data.pvtangent = pvtangent;
handle->data.precomputed_normals = precomputed_normals; /* don't strictly need this */
@@ -881,6 +868,8 @@ static void apply_tangmat_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm,
}
}
+/* TODO: restore ambient occlusion baking support, using BLI BVH? */
+#if 0
/* **************** Ambient Occlusion Baker **************** */
// must be a power of two
@@ -1173,35 +1162,101 @@ static void apply_ao_callback(DerivedMesh *lores_dm, DerivedMesh *hires_dm, void
rrgb[3] = 255;
}
}
+#endif
+
+/* ******$***************** Post processing ************************* */
+
+static void bake_ibuf_filter(ImBuf *ibuf, char *mask, const int filter)
+{
+ /* must check before filtering */
+ const bool is_new_alpha = (ibuf->planes != R_IMF_PLANES_RGBA) && BKE_imbuf_alpha_test(ibuf);
+
+ /* Margin */
+ if (filter) {
+ IMB_filter_extend(ibuf, mask, filter);
+ }
+
+ /* if the bake results in new alpha then change the image setting */
+ if (is_new_alpha) {
+ ibuf->planes = R_IMF_PLANES_RGBA;
+ }
+ else {
+ if (filter && ibuf->planes != R_IMF_PLANES_RGBA) {
+ /* clear alpha added by filtering */
+ IMB_rectfill_alpha(ibuf, 1.0f);
+ }
+ }
+}
+
+static void bake_ibuf_normalize_displacement(ImBuf *ibuf, float *displacement, char *mask, float displacement_min, float displacement_max)
+{
+ int i;
+ const float *current_displacement = displacement;
+ const char *current_mask = mask;
+ float max_distance;
+
+ max_distance = max_ff(fabsf(displacement_min), fabsf(displacement_max));
+
+ for (i = 0; i < ibuf->x * ibuf->y; i++) {
+ if (*current_mask == FILTER_MASK_USED) {
+ float normalized_displacement;
+
+ if (max_distance > 1e-5f)
+ normalized_displacement = (*current_displacement + max_distance) / (max_distance * 2);
+ else
+ normalized_displacement = 0.5f;
+
+ if (ibuf->rect_float) {
+ /* currently baking happens to RGBA only */
+ float *fp = ibuf->rect_float + i * 4;
+ fp[0] = fp[1] = fp[2] = normalized_displacement;
+ fp[3] = 1.0f;
+ }
+
+ if (ibuf->rect) {
+ unsigned char *cp = (unsigned char *) (ibuf->rect + i);
+ cp[0] = cp[1] = cp[2] = unit_float_to_uchar_clamp(normalized_displacement);
+ cp[3] = 255;
+ }
+ }
+
+ current_displacement++;
+ current_mask++;
+ }
+}
/* **************** Common functions public API relates on **************** */
static void count_images(MultiresBakeRender *bkr)
{
- int a, totpoly;
- DerivedMesh *dm = bkr->lores_dm;
- MTexPoly *mtexpoly = CustomData_get_layer(&dm->polyData, CD_MTEXPOLY);
-
BLI_listbase_clear(&bkr->image);
bkr->tot_image = 0;
- totpoly = dm->getNumPolys(dm);
-
- for (a = 0; a < totpoly; a++)
- mtexpoly[a].tpage->id.tag &= ~LIB_TAG_DOIT;
+ for (int i = 0; i < bkr->ob_image.len; i++) {
+ Image *ima = bkr->ob_image.array[i];
+ if (ima) {
+ ima->id.tag &= ~LIB_TAG_DOIT;
+ }
+ }
- for (a = 0; a < totpoly; a++) {
- Image *ima = mtexpoly[a].tpage;
- if ((ima->id.tag & LIB_TAG_DOIT) == 0) {
- LinkData *data = BLI_genericNodeN(ima);
- BLI_addtail(&bkr->image, data);
- bkr->tot_image++;
- ima->id.tag |= LIB_TAG_DOIT;
+ for (int i = 0; i < bkr->ob_image.len; i++) {
+ Image *ima = bkr->ob_image.array[i];
+ if (ima) {
+ if ((ima->id.tag & LIB_TAG_DOIT) == 0) {
+ LinkData *data = BLI_genericNodeN(ima);
+ BLI_addtail(&bkr->image, data);
+ bkr->tot_image++;
+ ima->id.tag |= LIB_TAG_DOIT;
+ }
}
}
- for (a = 0; a < totpoly; a++)
- mtexpoly[a].tpage->id.tag &= ~LIB_TAG_DOIT;
+ for (int i = 0; i < bkr->ob_image.len; i++) {
+ Image *ima = bkr->ob_image.array[i];
+ if (ima) {
+ ima->id.tag &= ~LIB_TAG_DOIT;
+ }
+ }
}
static void bake_images(MultiresBakeRender *bkr, MultiresBakeResult *result)
@@ -1222,12 +1277,14 @@ static void bake_images(MultiresBakeRender *bkr, MultiresBakeResult *result)
do_multires_bake(bkr, ima, true, apply_tangmat_callback, init_normal_data, free_normal_data, result);
break;
case RE_BAKE_DISPLACEMENT:
- case RE_BAKE_DERIVATIVE:
do_multires_bake(bkr, ima, false, apply_heights_callback, init_heights_data, free_heights_data, result);
break;
+/* TODO: restore ambient occlusion baking support. */
+#if 0
case RE_BAKE_AO:
do_multires_bake(bkr, ima, false, apply_ao_callback, init_ao_data, free_ao_data, result);
break;
+#endif
}
}
@@ -1240,7 +1297,7 @@ static void bake_images(MultiresBakeRender *bkr, MultiresBakeResult *result)
static void finish_images(MultiresBakeRender *bkr, MultiresBakeResult *result)
{
LinkData *link;
- bool use_displacement_buffer = ELEM(bkr->mode, RE_BAKE_DISPLACEMENT, RE_BAKE_DERIVATIVE);
+ bool use_displacement_buffer = bkr->mode == RE_BAKE_DISPLACEMENT;
for (link = bkr->image.first; link; link = link->next) {
Image *ima = (Image *)link->data;
@@ -1251,17 +1308,11 @@ static void finish_images(MultiresBakeRender *bkr, MultiresBakeResult *result)
continue;
if (use_displacement_buffer) {
- if (bkr->mode == RE_BAKE_DERIVATIVE) {
- RE_bake_make_derivative(ibuf, userdata->displacement_buffer, userdata->mask_buffer,
- result->height_min, result->height_max, bkr->user_scale);
- }
- else {
- RE_bake_ibuf_normalize_displacement(ibuf, userdata->displacement_buffer, userdata->mask_buffer,
- result->height_min, result->height_max);
- }
+ bake_ibuf_normalize_displacement(ibuf, userdata->displacement_buffer, userdata->mask_buffer,
+ result->height_min, result->height_max);
}
- RE_bake_ibuf_filter(ibuf, userdata->mask_buffer, bkr->bake_filter);
+ bake_ibuf_filter(ibuf, userdata->mask_buffer, bkr->bake_filter);
ibuf->userflags |= IB_BITMAPDIRTY | IB_DISPLAY_BUFFER_INVALID;
@@ -1283,7 +1334,7 @@ static void finish_images(MultiresBakeRender *bkr, MultiresBakeResult *result)
}
BKE_image_release_ibuf(ima, ibuf, NULL);
- DAG_id_tag_update(&ima->id, 0);
+ DEG_id_tag_update(&ima->id, 0);
}
}
diff --git a/source/blender/render/intern/source/occlusion.c b/source/blender/render/intern/source/occlusion.c
deleted file mode 100644
index 42200a8278c..00000000000
--- a/source/blender/render/intern/source/occlusion.c
+++ /dev/null
@@ -1,1533 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2008 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Brecht Van Lommel.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/occlusion.c
- * \ingroup render
- */
-
-#include <math.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_material_types.h"
-
-#include "BLI_math.h"
-#include "BLI_memarena.h"
-#include "BLI_threads.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "BKE_node.h"
-#include "BKE_scene.h"
-
-
-#include "RE_shader_ext.h"
-
-/* local includes */
-#include "occlusion.h"
-#include "render_types.h"
-#include "rendercore.h"
-#include "renderdatabase.h"
-#include "shading.h"
-
-/* ------------------------- Declarations --------------------------- */
-
-#define INVPI ((float)M_1_PI)
-#define TOTCHILD 8
-#define CACHE_STEP 3
-
-typedef struct OcclusionCacheSample {
- float co[3], n[3], ao[3], env[3], indirect[3], intensity, dist2;
- int x, y, filled;
-} OcclusionCacheSample;
-
-typedef struct OcclusionCache {
- OcclusionCacheSample *sample;
- int x, y, w, h, step;
-} OcclusionCache;
-
-typedef struct OccFace {
- int obi;
- int facenr;
-} OccFace;
-
-typedef struct OccNode {
- float co[3], area;
- float sh[9], dco;
- float occlusion, rad[3];
- int childflag;
- union {
- //OccFace face;
- int face;
- struct OccNode *node;
- } child[TOTCHILD];
-} OccNode;
-
-typedef struct OcclusionTree {
- MemArena *arena;
-
- float (*co)[3]; /* temporary during build */
-
- OccFace *face; /* instance and face indices */
- float *occlusion; /* occlusion for faces */
- float (*rad)[3]; /* radiance for faces */
-
- OccNode *root;
-
- OccNode **stack[BLENDER_MAX_THREADS];
- int maxdepth;
-
- int totface;
-
- float error;
- float distfac;
-
- int dothreadedbuild;
- int totbuildthread;
- int doindirect;
-
- OcclusionCache *cache;
-
- int num_threads;
-} OcclusionTree;
-
-typedef struct OcclusionThread {
- Render *re;
- StrandSurface *mesh;
- float (*faceao)[3];
- float (*faceenv)[3];
- float (*faceindirect)[3];
- int begin, end;
- int thread;
-} OcclusionThread;
-
-typedef struct OcclusionBuildThread {
- OcclusionTree *tree;
- int begin, end, depth;
- OccNode *node;
-} OcclusionBuildThread;
-
-/* ------------------------- Shading --------------------------- */
-
-extern Render R; /* meh */
-
-static void occ_shade(ShadeSample *ssamp, ObjectInstanceRen *obi, VlakRen *vlr, float *rad)
-{
- ShadeInput *shi = ssamp->shi;
- ShadeResult *shr = ssamp->shr;
- float l, u, v, *v1, *v2, *v3;
-
- /* init */
- if (vlr->v4) {
- shi->u = u = 0.5f;
- shi->v = v = 0.5f;
- }
- else {
- shi->u = u = 1.0f / 3.0f;
- shi->v = v = 1.0f / 3.0f;
- }
-
- /* setup render coordinates */
- v1 = vlr->v1->co;
- v2 = vlr->v2->co;
- v3 = vlr->v3->co;
-
- /* renderco */
- l = 1.0f - u - v;
-
- shi->co[0] = l * v3[0] + u * v1[0] + v * v2[0];
- shi->co[1] = l * v3[1] + u * v1[1] + v * v2[1];
- shi->co[2] = l * v3[2] + u * v1[2] + v * v2[2];
-
- shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2);
-
- /* set up view vector */
- copy_v3_v3(shi->view, shi->co);
- normalize_v3(shi->view);
-
- /* cache for shadow */
- shi->samplenr++;
-
- shi->xs = 0; /* TODO */
- shi->ys = 0;
-
- shade_input_set_normals(shi);
-
- /* no normal flip */
- if (shi->flippednor)
- shade_input_flip_normals(shi);
-
- madd_v3_v3fl(shi->co, shi->facenor, -0.0001f); /* ugly.. */
-
- /* not a pretty solution, but fixes common cases */
- if (shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) {
- negate_v3(shi->vn);
- negate_v3(shi->vno);
- negate_v3(shi->nmapnorm);
- }
-
- /* init material vars */
- shade_input_init_material(shi);
-
- /* render */
- shade_input_set_shade_texco(shi);
-
- if (shi->mat->nodetree && shi->mat->use_nodes) {
- ntreeShaderExecTree(shi->mat->nodetree, shi, shr);
- shi->mat = vlr->mat; /* shi->mat is being set in nodetree */
- }
- else {
- shade_material_loop(shi, shr);
- }
-
- copy_v3_v3(rad, shr->combined);
-}
-
-static void occ_build_shade(Render *re, OcclusionTree *tree)
-{
- ShadeSample ssamp;
- ObjectInstanceRen *obi;
- VlakRen *vlr;
- int a;
-
- R = *re;
-
- /* setup shade sample with correct passes */
- memset(&ssamp, 0, sizeof(ShadeSample));
- ssamp.shi[0].lay = re->lay;
- ssamp.shi[0].passflag = SCE_PASS_DIFFUSE | SCE_PASS_RGBA;
- ssamp.shi[0].combinedflag = ~(SCE_PASS_SPEC);
- ssamp.tot = 1;
-
- for (a = 0; a < tree->totface; a++) {
- obi = &R.objectinstance[tree->face[a].obi];
- vlr = RE_findOrAddVlak(obi->obr, tree->face[a].facenr);
-
- occ_shade(&ssamp, obi, vlr, tree->rad[a]);
-
- if (re->test_break(re->tbh))
- break;
- }
-}
-
-/* ------------------------- Spherical Harmonics --------------------------- */
-
-/* Use 2nd order SH => 9 coefficients, stored in this order:
- * 0 = (0,0),
- * 1 = (1,-1), 2 = (1,0), 3 = (1,1),
- * 4 = (2,-2), 5 = (2,-1), 6 = (2,0), 7 = (2,1), 8 = (2,2) */
-
-static void sh_copy(float *shresult, float *sh)
-{
- memcpy(shresult, sh, sizeof(float) * 9);
-}
-
-static void sh_mul(float *sh, float f)
-{
- int i;
-
- for (i = 0; i < 9; i++)
- sh[i] *= f;
-}
-
-static void sh_add(float *shresult, float *sh1, float *sh2)
-{
- int i;
-
- for (i = 0; i < 9; i++)
- shresult[i] = sh1[i] + sh2[i];
-}
-
-static void sh_from_disc(float *n, float area, float *shresult)
-{
- /* See formula (3) in:
- * "An Efficient Representation for Irradiance Environment Maps" */
- float sh[9], x, y, z;
-
- x = n[0];
- y = n[1];
- z = n[2];
-
- sh[0] = 0.282095f;
-
- sh[1] = 0.488603f * y;
- sh[2] = 0.488603f * z;
- sh[3] = 0.488603f * x;
-
- sh[4] = 1.092548f * x * y;
- sh[5] = 1.092548f * y * z;
- sh[6] = 0.315392f * (3.0f * z * z - 1.0f);
- sh[7] = 1.092548f * x * z;
- sh[8] = 0.546274f * (x * x - y * y);
-
- sh_mul(sh, area);
- sh_copy(shresult, sh);
-}
-
-static float sh_eval(float *sh, float *v)
-{
- /* See formula (13) in:
- * "An Efficient Representation for Irradiance Environment Maps" */
- static const float c1 = 0.429043f, c2 = 0.511664f, c3 = 0.743125f;
- static const float c4 = 0.886227f, c5 = 0.247708f;
- float x, y, z, sum;
-
- x = v[0];
- y = v[1];
- z = v[2];
-
- sum = c1 * sh[8] * (x * x - y * y);
- sum += c3 * sh[6] * z * z;
- sum += c4 * sh[0];
- sum += -c5 * sh[6];
- sum += 2.0f * c1 * (sh[4] * x * y + sh[7] * x * z + sh[5] * y * z);
- sum += 2.0f * c2 * (sh[3] * x + sh[1] * y + sh[2] * z);
-
- return sum;
-}
-
-/* ------------------------------ Building --------------------------------- */
-
-static void occ_face(const OccFace *face, float co[3], float normal[3], float *area)
-{
- ObjectInstanceRen *obi;
- VlakRen *vlr;
- float v1[3], v2[3], v3[3], v4[3];
-
- obi = &R.objectinstance[face->obi];
- vlr = RE_findOrAddVlak(obi->obr, face->facenr);
-
- if (co) {
- if (vlr->v4)
- mid_v3_v3v3(co, vlr->v1->co, vlr->v3->co);
- else
- mid_v3_v3v3v3(co, vlr->v1->co, vlr->v2->co, vlr->v3->co);
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_v3(obi->mat, co);
- }
-
- if (normal) {
- normal[0] = -vlr->n[0];
- normal[1] = -vlr->n[1];
- normal[2] = -vlr->n[2];
-
- if (obi->flag & R_TRANSFORMED)
- mul_m3_v3(obi->nmat, normal);
- }
-
- if (area) {
- copy_v3_v3(v1, vlr->v1->co);
- copy_v3_v3(v2, vlr->v2->co);
- copy_v3_v3(v3, vlr->v3->co);
- if (vlr->v4) copy_v3_v3(v4, vlr->v4->co);
-
- if (obi->flag & R_TRANSFORMED) {
- mul_m4_v3(obi->mat, v1);
- mul_m4_v3(obi->mat, v2);
- mul_m4_v3(obi->mat, v3);
- if (vlr->v4) mul_m4_v3(obi->mat, v4);
- }
-
- /* todo: correct area for instances */
- if (vlr->v4)
- *area = area_quad_v3(v1, v2, v3, v4);
- else
- *area = area_tri_v3(v1, v2, v3);
- }
-}
-
-static void occ_sum_occlusion(OcclusionTree *tree, OccNode *node)
-{
- OccNode *child;
- float occ, area, totarea, rad[3];
- int a, b, indirect = tree->doindirect;
-
- occ = 0.0f;
- totarea = 0.0f;
- if (indirect) zero_v3(rad);
-
- for (b = 0; b < TOTCHILD; b++) {
- if (node->childflag & (1 << b)) {
- a = node->child[b].face;
- occ_face(&tree->face[a], NULL, NULL, &area);
- occ += area * tree->occlusion[a];
- if (indirect) madd_v3_v3fl(rad, tree->rad[a], area);
- totarea += area;
- }
- else if (node->child[b].node) {
- child = node->child[b].node;
- occ_sum_occlusion(tree, child);
-
- occ += child->area * child->occlusion;
- if (indirect) madd_v3_v3fl(rad, child->rad, child->area);
- totarea += child->area;
- }
- }
-
- if (totarea != 0.0f) {
- occ /= totarea;
- if (indirect) mul_v3_fl(rad, 1.0f / totarea);
- }
-
- node->occlusion = occ;
- if (indirect) copy_v3_v3(node->rad, rad);
-}
-
-static int occ_find_bbox_axis(OcclusionTree *tree, int begin, int end, float *min, float *max)
-{
- float len, maxlen = -1.0f;
- int a, axis = 0;
-
- INIT_MINMAX(min, max);
-
- for (a = begin; a < end; a++) {
- minmax_v3v3_v3(min, max, tree->co[a]);
- }
-
- for (a = 0; a < 3; a++) {
- len = max[a] - min[a];
-
- if (len > maxlen) {
- maxlen = len;
- axis = a;
- }
- }
-
- return axis;
-}
-
-static void occ_node_from_face(OccFace *face, OccNode *node)
-{
- float n[3];
-
- occ_face(face, node->co, n, &node->area);
- node->dco = 0.0f;
- sh_from_disc(n, node->area, node->sh);
-}
-
-static void occ_build_dco(OcclusionTree *tree, OccNode *node, const float co[3], float *dco)
-{
- int b;
- for (b = 0; b < TOTCHILD; b++) {
- float dist, d[3], nco[3];
-
- if (node->childflag & (1 << b)) {
- occ_face(tree->face + node->child[b].face, nco, NULL, NULL);
- }
- else if (node->child[b].node) {
- OccNode *child = node->child[b].node;
- occ_build_dco(tree, child, co, dco);
- copy_v3_v3(nco, child->co);
- }
- else {
- continue;
- }
-
- sub_v3_v3v3(d, nco, co);
- dist = dot_v3v3(d, d);
- if (dist > *dco)
- *dco = dist;
- }
-}
-
-static void occ_build_split(OcclusionTree *tree, int begin, int end, int *split)
-{
- float min[3], max[3], mid;
- int axis, a, enda;
-
- /* split in middle of boundbox. this seems faster than median split
- * on complex scenes, possibly since it avoids two distant faces to
- * be in the same node better? */
- axis = occ_find_bbox_axis(tree, begin, end, min, max);
- mid = 0.5f * (min[axis] + max[axis]);
-
- a = begin;
- enda = end;
- while (a < enda) {
- if (tree->co[a][axis] > mid) {
- enda--;
- SWAP(OccFace, tree->face[a], tree->face[enda]);
- swap_v3_v3(tree->co[a], tree->co[enda]);
- }
- else
- a++;
- }
-
- *split = enda;
-}
-
-static void occ_build_8_split(OcclusionTree *tree, int begin, int end, int *offset, int *count)
-{
- /* split faces into eight groups */
- int b, splitx, splity[2], splitz[4];
-
- occ_build_split(tree, begin, end, &splitx);
-
- /* force split if none found, to deal with degenerate geometry */
- if (splitx == begin || splitx == end)
- splitx = (begin + end) / 2;
-
- occ_build_split(tree, begin, splitx, &splity[0]);
- occ_build_split(tree, splitx, end, &splity[1]);
-
- occ_build_split(tree, begin, splity[0], &splitz[0]);
- occ_build_split(tree, splity[0], splitx, &splitz[1]);
- occ_build_split(tree, splitx, splity[1], &splitz[2]);
- occ_build_split(tree, splity[1], end, &splitz[3]);
-
- offset[0] = begin;
- offset[1] = splitz[0];
- offset[2] = splity[0];
- offset[3] = splitz[1];
- offset[4] = splitx;
- offset[5] = splitz[2];
- offset[6] = splity[1];
- offset[7] = splitz[3];
-
- for (b = 0; b < 7; b++)
- count[b] = offset[b + 1] - offset[b];
- count[7] = end - offset[7];
-}
-
-static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, int end, int depth);
-
-static void *exec_occ_build(void *data)
-{
- OcclusionBuildThread *othread = (OcclusionBuildThread *)data;
-
- occ_build_recursive(othread->tree, othread->node, othread->begin, othread->end, othread->depth);
-
- return NULL;
-}
-
-static void occ_build_recursive(OcclusionTree *tree, OccNode *node, int begin, int end, int depth)
-{
- ListBase threads;
- OcclusionBuildThread othreads[BLENDER_MAX_THREADS];
- OccNode *child, tmpnode;
- /* OccFace *face; */
- int a, b, totthread = 0, offset[TOTCHILD], count[TOTCHILD];
-
- /* add a new node */
- node->occlusion = 1.0f;
-
- /* leaf node with only children */
- if (end - begin <= TOTCHILD) {
- for (a = begin, b = 0; a < end; a++, b++) {
- /* face= &tree->face[a]; */
- node->child[b].face = a;
- node->childflag |= (1 << b);
- }
- }
- else {
- /* order faces */
- occ_build_8_split(tree, begin, end, offset, count);
-
- if (depth == 1 && tree->dothreadedbuild)
- BLI_threadpool_init(&threads, exec_occ_build, tree->totbuildthread);
-
- for (b = 0; b < TOTCHILD; b++) {
- if (count[b] == 0) {
- node->child[b].node = NULL;
- }
- else if (count[b] == 1) {
- /* face= &tree->face[offset[b]]; */
- node->child[b].face = offset[b];
- node->childflag |= (1 << b);
- }
- else {
- if (tree->dothreadedbuild)
- BLI_thread_lock(LOCK_CUSTOM1);
-
- child = BLI_memarena_alloc(tree->arena, sizeof(OccNode));
- node->child[b].node = child;
-
- /* keep track of maximum depth for stack */
- if (depth >= tree->maxdepth)
- tree->maxdepth = depth + 1;
-
- if (tree->dothreadedbuild)
- BLI_thread_unlock(LOCK_CUSTOM1);
-
- if (depth == 1 && tree->dothreadedbuild) {
- othreads[totthread].tree = tree;
- othreads[totthread].node = child;
- othreads[totthread].begin = offset[b];
- othreads[totthread].end = offset[b] + count[b];
- othreads[totthread].depth = depth + 1;
- BLI_threadpool_insert(&threads, &othreads[totthread]);
- totthread++;
- }
- else
- occ_build_recursive(tree, child, offset[b], offset[b] + count[b], depth + 1);
- }
- }
-
- if (depth == 1 && tree->dothreadedbuild)
- BLI_threadpool_end(&threads);
- }
-
- /* combine area, position and sh */
- for (b = 0; b < TOTCHILD; b++) {
- if (node->childflag & (1 << b)) {
- child = &tmpnode;
- occ_node_from_face(tree->face + node->child[b].face, &tmpnode);
- }
- else {
- child = node->child[b].node;
- }
-
- if (child) {
- node->area += child->area;
- sh_add(node->sh, node->sh, child->sh);
- madd_v3_v3fl(node->co, child->co, child->area);
- }
- }
-
- if (node->area != 0.0f)
- mul_v3_fl(node->co, 1.0f / node->area);
-
- /* compute maximum distance from center */
- node->dco = 0.0f;
- if (node->area > 0.0f)
- occ_build_dco(tree, node, node->co, &node->dco);
-}
-
-static void occ_build_sh_normalize(OccNode *node)
-{
- /* normalize spherical harmonics to not include area, so
- * we can clamp the dot product and then multiply by area */
- int b;
-
- if (node->area != 0.0f)
- sh_mul(node->sh, 1.0f / node->area);
-
- for (b = 0; b < TOTCHILD; b++) {
- if (node->childflag & (1 << b)) {
- /* pass */
- }
- else if (node->child[b].node) {
- occ_build_sh_normalize(node->child[b].node);
- }
- }
-}
-
-static OcclusionTree *occ_tree_build(Render *re)
-{
- const int num_threads = re->r.threads;
- OcclusionTree *tree;
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- Material *ma;
- VlakRen *vlr = NULL;
- int a, b, c, totface;
-
- /* count */
- totface = 0;
- for (obi = re->instancetable.first; obi; obi = obi->next) {
- obr = obi->obr;
- for (a = 0; a < obr->totvlak; a++) {
- if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak;
- else vlr++;
-
- ma = vlr->mat;
-
- if ((ma->shade_flag & MA_APPROX_OCCLUSION) && (ma->material_type == MA_TYPE_SURFACE))
- totface++;
- }
- }
-
- if (totface == 0)
- return NULL;
-
- tree = MEM_callocN(sizeof(OcclusionTree), "OcclusionTree");
- tree->totface = totface;
-
- /* parameters */
- tree->error = get_render_aosss_error(&re->r, re->wrld.ao_approx_error);
- tree->distfac = (re->wrld.aomode & WO_AODIST) ? re->wrld.aodistfac : 0.0f;
- tree->doindirect = (re->wrld.ao_indirect_energy > 0.0f && re->wrld.ao_indirect_bounces > 0);
-
- /* allocation */
- tree->arena = BLI_memarena_new(0x8000 * sizeof(OccNode), "occ tree arena");
- BLI_memarena_use_calloc(tree->arena);
-
- if (re->wrld.aomode & WO_AOCACHE)
- tree->cache = MEM_callocN(sizeof(OcclusionCache) * num_threads, "OcclusionCache");
-
- tree->face = MEM_callocN(sizeof(OccFace) * totface, "OcclusionFace");
- tree->co = MEM_callocN(sizeof(float) * 3 * totface, "OcclusionCo");
- tree->occlusion = MEM_callocN(sizeof(float) * totface, "OcclusionOcclusion");
-
- if (tree->doindirect)
- tree->rad = MEM_callocN(sizeof(float) * 3 * totface, "OcclusionRad");
-
- /* make array of face pointers */
- for (b = 0, c = 0, obi = re->instancetable.first; obi; obi = obi->next, c++) {
- obr = obi->obr;
- for (a = 0; a < obr->totvlak; a++) {
- if ((a & 255) == 0) vlr = obr->vlaknodes[a >> 8].vlak;
- else vlr++;
-
- ma = vlr->mat;
-
- if ((ma->shade_flag & MA_APPROX_OCCLUSION) && (ma->material_type == MA_TYPE_SURFACE)) {
- tree->face[b].obi = c;
- tree->face[b].facenr = a;
- tree->occlusion[b] = 1.0f;
- occ_face(&tree->face[b], tree->co[b], NULL, NULL);
- b++;
- }
- }
- }
-
- /* threads */
- tree->totbuildthread = (re->r.threads > 1 && totface > 10000) ? 8 : 1;
- tree->dothreadedbuild = (tree->totbuildthread > 1);
-
- /* recurse */
- tree->root = BLI_memarena_alloc(tree->arena, sizeof(OccNode));
- tree->maxdepth = 1;
- occ_build_recursive(tree, tree->root, 0, totface, 1);
-
- if (tree->doindirect) {
- if (!(re->test_break(re->tbh)))
- occ_build_shade(re, tree);
-
- if (!(re->test_break(re->tbh)))
- occ_sum_occlusion(tree, tree->root);
- }
-
- MEM_freeN(tree->co);
- tree->co = NULL;
-
- if (!(re->test_break(re->tbh)))
- occ_build_sh_normalize(tree->root);
-
- for (a = 0; a < num_threads; a++)
- tree->stack[a] = MEM_callocN(sizeof(OccNode) * TOTCHILD * (tree->maxdepth + 1), "OccStack");
-
- tree->num_threads = num_threads;
-
- return tree;
-}
-
-static void occ_free_tree(OcclusionTree *tree)
-{
- int a;
-
- if (tree) {
- if (tree->arena) BLI_memarena_free(tree->arena);
- for (a = 0; a < tree->num_threads; a++)
- if (tree->stack[a])
- MEM_freeN(tree->stack[a]);
- if (tree->occlusion) MEM_freeN(tree->occlusion);
- if (tree->cache) MEM_freeN(tree->cache);
- if (tree->face) MEM_freeN(tree->face);
- if (tree->rad) MEM_freeN(tree->rad);
- MEM_freeN(tree);
- }
-}
-
-/* ------------------------- Traversal --------------------------- */
-
-static float occ_solid_angle(OccNode *node, const float v[3], float d2, float invd2, const float receivenormal[3])
-{
- float dotreceive, dotemit;
- float ev[3];
-
- ev[0] = -v[0] * invd2;
- ev[1] = -v[1] * invd2;
- ev[2] = -v[2] * invd2;
- dotemit = sh_eval(node->sh, ev);
- dotreceive = dot_v3v3(receivenormal, v) * invd2;
-
- CLAMP(dotemit, 0.0f, 1.0f);
- CLAMP(dotreceive, 0.0f, 1.0f);
-
- return ((node->area * dotemit * dotreceive) / (d2 + node->area * INVPI)) * INVPI;
-}
-
-static float occ_form_factor(OccFace *face, float *p, float *n)
-{
- ObjectInstanceRen *obi;
- VlakRen *vlr;
- float v1[3], v2[3], v3[3], v4[3], q0[3], q1[3], q2[3], q3[3], contrib = 0.0f;
-
- obi = &R.objectinstance[face->obi];
- vlr = RE_findOrAddVlak(obi->obr, face->facenr);
-
- copy_v3_v3(v1, vlr->v1->co);
- copy_v3_v3(v2, vlr->v2->co);
- copy_v3_v3(v3, vlr->v3->co);
-
- if (obi->flag & R_TRANSFORMED) {
- mul_m4_v3(obi->mat, v1);
- mul_m4_v3(obi->mat, v2);
- mul_m4_v3(obi->mat, v3);
- }
-
- if (form_factor_visible_quad(p, n, v1, v2, v3, q0, q1, q2, q3))
- contrib += form_factor_quad(p, n, q0, q1, q2, q3);
-
- if (vlr->v4) {
- copy_v3_v3(v4, vlr->v4->co);
- if (obi->flag & R_TRANSFORMED)
- mul_m4_v3(obi->mat, v4);
-
- if (form_factor_visible_quad(p, n, v1, v3, v4, q0, q1, q2, q3))
- contrib += form_factor_quad(p, n, q0, q1, q2, q3);
- }
-
- return contrib;
-}
-
-static void occ_lookup(OcclusionTree *tree, int thread, OccFace *exclude,
- const float pp[3], const float pn[3], float *occ, float rad[3], float bentn[3])
-{
- OccNode *node, **stack;
- OccFace *face;
- float resultocc, resultrad[3], v[3], p[3], n[3], co[3], invd2;
- float distfac, fac, error, d2, weight, emitarea;
- int b, f, totstack;
-
- /* init variables */
- copy_v3_v3(p, pp);
- copy_v3_v3(n, pn);
- madd_v3_v3fl(p, n, 1e-4f);
-
- if (bentn)
- copy_v3_v3(bentn, n);
-
- error = tree->error;
- distfac = tree->distfac;
-
- resultocc = 0.0f;
- zero_v3(resultrad);
-
- /* init stack */
- stack = tree->stack[thread];
- stack[0] = tree->root;
- totstack = 1;
-
- while (totstack) {
- /* pop point off the stack */
- node = stack[--totstack];
-
- sub_v3_v3v3(v, node->co, p);
- d2 = dot_v3v3(v, v) + 1e-16f;
- emitarea = MAX2(node->area, node->dco);
-
- if (d2 * error > emitarea) {
- if (distfac != 0.0f) {
- fac = 1.0f / (1.0f + distfac * d2);
- if (fac < 0.01f)
- continue;
- }
- else
- fac = 1.0f;
-
- /* accumulate occlusion from spherical harmonics */
- invd2 = 1.0f / sqrtf(d2);
- weight = occ_solid_angle(node, v, d2, invd2, n);
-
- if (rad)
- madd_v3_v3fl(resultrad, node->rad, weight * fac);
-
- weight *= node->occlusion;
-
- if (bentn) {
- bentn[0] -= weight * invd2 * v[0];
- bentn[1] -= weight * invd2 * v[1];
- bentn[2] -= weight * invd2 * v[2];
- }
-
- resultocc += weight * fac;
- }
- else {
- /* traverse into children */
- for (b = 0; b < TOTCHILD; b++) {
- if (node->childflag & (1 << b)) {
- f = node->child[b].face;
- face = &tree->face[f];
-
- /* accumulate occlusion with face form factor */
- if (!exclude || !(face->obi == exclude->obi && face->facenr == exclude->facenr)) {
- if (bentn || distfac != 0.0f) {
- occ_face(face, co, NULL, NULL);
- sub_v3_v3v3(v, co, p);
- d2 = dot_v3v3(v, v) + 1e-16f;
-
- fac = (distfac == 0.0f) ? 1.0f : 1.0f / (1.0f + distfac * d2);
- if (fac < 0.01f)
- continue;
- }
- else
- fac = 1.0f;
-
- weight = occ_form_factor(face, p, n);
-
- if (rad)
- madd_v3_v3fl(resultrad, tree->rad[f], weight * fac);
-
- weight *= tree->occlusion[f];
-
- if (bentn) {
- invd2 = 1.0f / sqrtf(d2);
- bentn[0] -= weight * invd2 * v[0];
- bentn[1] -= weight * invd2 * v[1];
- bentn[2] -= weight * invd2 * v[2];
- }
-
- resultocc += weight * fac;
- }
- }
- else if (node->child[b].node) {
- /* push child on the stack */
- stack[totstack++] = node->child[b].node;
- }
- }
- }
- }
-
- if (occ) *occ = resultocc;
- if (rad) copy_v3_v3(rad, resultrad);
-#if 0
- if (rad && exclude) {
- int a;
- for (a = 0; a < tree->totface; a++)
- if ((tree->face[a].obi == exclude->obi && tree->face[a].facenr == exclude->facenr))
- copy_v3_v3(rad, tree->rad[a]);
- }
-#endif
- if (bentn) normalize_v3(bentn);
-}
-
-static void occ_compute_bounces(Render *re, OcclusionTree *tree, int totbounce)
-{
- float (*rad)[3], (*sum)[3], (*tmp)[3], co[3], n[3], occ;
- int bounce, i;
-
- rad = MEM_callocN(sizeof(float) * 3 * tree->totface, "OcclusionBounceRad");
- sum = MEM_dupallocN(tree->rad);
-
- for (bounce = 1; bounce < totbounce; bounce++) {
- for (i = 0; i < tree->totface; i++) {
- occ_face(&tree->face[i], co, n, NULL);
- madd_v3_v3fl(co, n, 1e-8f);
-
- occ_lookup(tree, 0, &tree->face[i], co, n, &occ, rad[i], NULL);
- rad[i][0] = MAX2(rad[i][0], 0.0f);
- rad[i][1] = MAX2(rad[i][1], 0.0f);
- rad[i][2] = MAX2(rad[i][2], 0.0f);
- add_v3_v3(sum[i], rad[i]);
-
- if (re->test_break(re->tbh))
- break;
- }
-
- if (re->test_break(re->tbh))
- break;
-
- tmp = tree->rad;
- tree->rad = rad;
- rad = tmp;
-
- occ_sum_occlusion(tree, tree->root);
- }
-
- MEM_freeN(rad);
- MEM_freeN(tree->rad);
- tree->rad = sum;
-
- if (!re->test_break(re->tbh))
- occ_sum_occlusion(tree, tree->root);
-}
-
-static void occ_compute_passes(Render *re, OcclusionTree *tree, int totpass)
-{
- float *occ, co[3], n[3];
- int pass, i;
-
- occ = MEM_callocN(sizeof(float) * tree->totface, "OcclusionPassOcc");
-
- for (pass = 0; pass < totpass; pass++) {
- for (i = 0; i < tree->totface; i++) {
- occ_face(&tree->face[i], co, n, NULL);
- negate_v3(n);
- madd_v3_v3fl(co, n, 1e-8f);
-
- occ_lookup(tree, 0, &tree->face[i], co, n, &occ[i], NULL, NULL);
- if (re->test_break(re->tbh))
- break;
- }
-
- if (re->test_break(re->tbh))
- break;
-
- for (i = 0; i < tree->totface; i++) {
- tree->occlusion[i] -= occ[i]; //MAX2(1.0f-occ[i], 0.0f);
- if (tree->occlusion[i] < 0.0f)
- tree->occlusion[i] = 0.0f;
- }
-
- occ_sum_occlusion(tree, tree->root);
- }
-
- MEM_freeN(occ);
-}
-
-static void sample_occ_tree(Render *re, OcclusionTree *tree, OccFace *exclude,
- const float co[3], const float n[3], int thread, int onlyshadow,
- float *ao, float *env, float *indirect)
-{
- float nn[3], bn[3], fac, occ, occlusion, correction, rad[3];
- int envcolor;
-
- envcolor = re->wrld.aocolor;
- if (onlyshadow)
- envcolor = WO_AOPLAIN;
-
- negate_v3_v3(nn, n);
-
- occ_lookup(tree, thread, exclude, co, nn, &occ, (tree->doindirect) ? rad : NULL, (env && envcolor) ? bn : NULL);
-
- correction = re->wrld.ao_approx_correction;
-
- occlusion = (1.0f - correction) * (1.0f - occ);
- CLAMP(occlusion, 0.0f, 1.0f);
- if (correction != 0.0f)
- occlusion += correction * expf(-occ);
-
- if (env) {
- /* sky shading using bent normal */
- if (ELEM(envcolor, WO_AOSKYCOL, WO_AOSKYTEX)) {
- fac = 0.5f * (1.0f + dot_v3v3(bn, re->grvec));
- env[0] = (1.0f - fac) * re->wrld.horr + fac * re->wrld.zenr;
- env[1] = (1.0f - fac) * re->wrld.horg + fac * re->wrld.zeng;
- env[2] = (1.0f - fac) * re->wrld.horb + fac * re->wrld.zenb;
-
- mul_v3_fl(env, occlusion);
- }
- else {
- env[0] = occlusion;
- env[1] = occlusion;
- env[2] = occlusion;
- }
-#if 0
- else { /* WO_AOSKYTEX */
- float dxyview[3];
- bn[0] = -bn[0];
- bn[1] = -bn[1];
- bn[2] = -bn[2];
- dxyview[0] = 1.0f;
- dxyview[1] = 1.0f;
- dxyview[2] = 0.0f;
- shadeSkyView(ao, co, bn, dxyview);
- }
-#endif
- }
-
- if (ao) {
- ao[0] = occlusion;
- ao[1] = occlusion;
- ao[2] = occlusion;
- }
-
- if (tree->doindirect) copy_v3_v3(indirect, rad);
- else zero_v3(indirect);
-}
-
-/* ---------------------------- Caching ------------------------------- */
-
-static OcclusionCacheSample *find_occ_sample(OcclusionCache *cache, int x, int y)
-{
- x -= cache->x;
- y -= cache->y;
-
- x /= cache->step;
- y /= cache->step;
- x *= cache->step;
- y *= cache->step;
-
- if (x < 0 || x >= cache->w || y < 0 || y >= cache->h)
- return NULL;
- else
- return &cache->sample[y * cache->w + x];
-}
-
-static int sample_occ_cache(OcclusionTree *tree, float *co, float *n, int x, int y, int thread, float *ao, float *env, float *indirect)
-{
- OcclusionCache *cache;
- OcclusionCacheSample *samples[4], *sample;
- float wn[4], wz[4], wb[4], tx, ty, w, totw, mino, maxo;
- float d[3], dist2;
- int i, x1, y1, x2, y2;
-
- if (!tree->cache)
- return 0;
-
- /* first try to find a sample in the same pixel */
- cache = &tree->cache[thread];
-
- if (cache->sample && cache->step) {
- sample = &cache->sample[(y - cache->y) * cache->w + (x - cache->x)];
- if (sample->filled) {
- sub_v3_v3v3(d, sample->co, co);
- dist2 = dot_v3v3(d, d);
- if (dist2 < 0.5f * sample->dist2 && dot_v3v3(sample->n, n) > 0.98f) {
- copy_v3_v3(ao, sample->ao);
- copy_v3_v3(env, sample->env);
- copy_v3_v3(indirect, sample->indirect);
- return 1;
- }
- }
- }
- else
- return 0;
-
- /* try to interpolate between 4 neighboring pixels */
- samples[0] = find_occ_sample(cache, x, y);
- samples[1] = find_occ_sample(cache, x + cache->step, y);
- samples[2] = find_occ_sample(cache, x, y + cache->step);
- samples[3] = find_occ_sample(cache, x + cache->step, y + cache->step);
-
- for (i = 0; i < 4; i++)
- if (!samples[i] || !samples[i]->filled)
- return 0;
-
- /* require intensities not being too different */
- mino = min_ffff(samples[0]->intensity, samples[1]->intensity, samples[2]->intensity, samples[3]->intensity);
- maxo = max_ffff(samples[0]->intensity, samples[1]->intensity, samples[2]->intensity, samples[3]->intensity);
-
- if (maxo - mino > 0.05f)
- return 0;
-
- /* compute weighted interpolation between samples */
- zero_v3(ao);
- zero_v3(env);
- zero_v3(indirect);
- totw = 0.0f;
-
- x1 = samples[0]->x;
- y1 = samples[0]->y;
- x2 = samples[3]->x;
- y2 = samples[3]->y;
-
- tx = (float)(x2 - x) / (float)(x2 - x1);
- ty = (float)(y2 - y) / (float)(y2 - y1);
-
- wb[3] = (1.0f - tx) * (1.0f - ty);
- wb[2] = (tx) * (1.0f - ty);
- wb[1] = (1.0f - tx) * (ty);
- wb[0] = tx * ty;
-
- for (i = 0; i < 4; i++) {
- sub_v3_v3v3(d, samples[i]->co, co);
- //dist2 = dot_v3v3(d, d);
-
- wz[i] = 1.0f; //(samples[i]->dist2/(1e-4f + dist2));
- wn[i] = pow(dot_v3v3(samples[i]->n, n), 32.0f);
-
- w = wb[i] * wn[i] * wz[i];
-
- totw += w;
- madd_v3_v3fl(ao, samples[i]->ao, w);
- madd_v3_v3fl(env, samples[i]->env, w);
- madd_v3_v3fl(indirect, samples[i]->indirect, w);
- }
-
- if (totw >= 0.9f) {
- totw = 1.0f / totw;
- mul_v3_fl(ao, totw);
- mul_v3_fl(env, totw);
- mul_v3_fl(indirect, totw);
- return 1;
- }
-
- return 0;
-}
-
-static void sample_occ_surface(ShadeInput *shi)
-{
- StrandRen *strand = shi->strand;
- StrandSurface *mesh = strand->buffer->surface;
- const int *face, *index = RE_strandren_get_face(shi->obr, strand, 0);
- float w[4], *co1, *co2, *co3, *co4;
-
- if (mesh && mesh->face && mesh->co && mesh->ao && index) {
- face = mesh->face[*index];
-
- co1 = mesh->co[face[0]];
- co2 = mesh->co[face[1]];
- co3 = mesh->co[face[2]];
-
- if (face[3]) {
- co4 = mesh->co[face[3]];
- interp_weights_quad_v3(w, co1, co2, co3, co4, strand->vert->co);
- }
- else {
- interp_weights_tri_v3(w, co1, co2, co3, strand->vert->co);
- }
-
- zero_v3(shi->ao);
- zero_v3(shi->env);
- zero_v3(shi->indirect);
-
- madd_v3_v3fl(shi->ao, mesh->ao[face[0]], w[0]);
- madd_v3_v3fl(shi->env, mesh->env[face[0]], w[0]);
- madd_v3_v3fl(shi->indirect, mesh->indirect[face[0]], w[0]);
- madd_v3_v3fl(shi->ao, mesh->ao[face[1]], w[1]);
- madd_v3_v3fl(shi->env, mesh->env[face[1]], w[1]);
- madd_v3_v3fl(shi->indirect, mesh->indirect[face[1]], w[1]);
- madd_v3_v3fl(shi->ao, mesh->ao[face[2]], w[2]);
- madd_v3_v3fl(shi->env, mesh->env[face[2]], w[2]);
- madd_v3_v3fl(shi->indirect, mesh->indirect[face[2]], w[2]);
- if (face[3]) {
- madd_v3_v3fl(shi->ao, mesh->ao[face[3]], w[3]);
- madd_v3_v3fl(shi->env, mesh->env[face[3]], w[3]);
- madd_v3_v3fl(shi->indirect, mesh->indirect[face[3]], w[3]);
- }
- }
- else {
- shi->ao[0] = 1.0f;
- shi->ao[1] = 1.0f;
- shi->ao[2] = 1.0f;
- zero_v3(shi->env);
- zero_v3(shi->indirect);
- }
-}
-
-/* ------------------------- External Functions --------------------------- */
-
-static void *exec_strandsurface_sample(void *data)
-{
- OcclusionThread *othread = (OcclusionThread *)data;
- Render *re = othread->re;
- StrandSurface *mesh = othread->mesh;
- float ao[3], env[3], indirect[3], co[3], n[3], *co1, *co2, *co3, *co4;
- int a, *face;
-
- for (a = othread->begin; a < othread->end; a++) {
- face = mesh->face[a];
- co1 = mesh->co[face[0]];
- co2 = mesh->co[face[1]];
- co3 = mesh->co[face[2]];
-
- if (face[3]) {
- co4 = mesh->co[face[3]];
-
- mid_v3_v3v3(co, co1, co3);
- normal_quad_v3(n, co1, co2, co3, co4);
- }
- else {
- mid_v3_v3v3v3(co, co1, co2, co3);
- normal_tri_v3(n, co1, co2, co3);
- }
- negate_v3(n);
-
- sample_occ_tree(re, re->occlusiontree, NULL, co, n, othread->thread, 0, ao, env, indirect);
- copy_v3_v3(othread->faceao[a], ao);
- copy_v3_v3(othread->faceenv[a], env);
- copy_v3_v3(othread->faceindirect[a], indirect);
- }
-
- return NULL;
-}
-
-void make_occ_tree(Render *re)
-{
- OcclusionThread othreads[BLENDER_MAX_THREADS];
- OcclusionTree *tree;
- StrandSurface *mesh;
- ListBase threads;
- float ao[3], env[3], indirect[3], (*faceao)[3], (*faceenv)[3], (*faceindirect)[3];
- int a, totface, totthread, *face, *count;
-
- /* ugly, needed for occ_face */
- R = *re;
-
- re->i.infostr = IFACE_("Occlusion preprocessing");
- re->stats_draw(re->sdh, &re->i);
-
- re->occlusiontree = tree = occ_tree_build(re);
-
- if (tree && !re->test_break(re->tbh)) {
- if (re->wrld.ao_approx_passes > 0)
- occ_compute_passes(re, tree, re->wrld.ao_approx_passes);
- if (tree->doindirect && (re->wrld.mode & WO_INDIRECT_LIGHT))
- occ_compute_bounces(re, tree, re->wrld.ao_indirect_bounces);
-
- for (mesh = re->strandsurface.first; mesh; mesh = mesh->next) {
- if (!mesh->face || !mesh->co || !mesh->ao)
- continue;
-
- count = MEM_callocN(sizeof(int) * mesh->totvert, "OcclusionCount");
- faceao = MEM_callocN(sizeof(float) * 3 * mesh->totface, "StrandSurfFaceAO");
- faceenv = MEM_callocN(sizeof(float) * 3 * mesh->totface, "StrandSurfFaceEnv");
- faceindirect = MEM_callocN(sizeof(float) * 3 * mesh->totface, "StrandSurfFaceIndirect");
-
- totthread = (mesh->totface > 10000) ? re->r.threads : 1;
- totface = mesh->totface / totthread;
- for (a = 0; a < totthread; a++) {
- othreads[a].re = re;
- othreads[a].faceao = faceao;
- othreads[a].faceenv = faceenv;
- othreads[a].faceindirect = faceindirect;
- othreads[a].thread = a;
- othreads[a].mesh = mesh;
- othreads[a].begin = a * totface;
- othreads[a].end = (a == totthread - 1) ? mesh->totface : (a + 1) * totface;
- }
-
- if (totthread == 1) {
- exec_strandsurface_sample(&othreads[0]);
- }
- else {
- BLI_threadpool_init(&threads, exec_strandsurface_sample, totthread);
-
- for (a = 0; a < totthread; a++)
- BLI_threadpool_insert(&threads, &othreads[a]);
-
- BLI_threadpool_end(&threads);
- }
-
- for (a = 0; a < mesh->totface; a++) {
- face = mesh->face[a];
-
- copy_v3_v3(ao, faceao[a]);
- copy_v3_v3(env, faceenv[a]);
- copy_v3_v3(indirect, faceindirect[a]);
-
- add_v3_v3(mesh->ao[face[0]], ao);
- add_v3_v3(mesh->env[face[0]], env);
- add_v3_v3(mesh->indirect[face[0]], indirect);
- count[face[0]]++;
- add_v3_v3(mesh->ao[face[1]], ao);
- add_v3_v3(mesh->env[face[1]], env);
- add_v3_v3(mesh->indirect[face[1]], indirect);
- count[face[1]]++;
- add_v3_v3(mesh->ao[face[2]], ao);
- add_v3_v3(mesh->env[face[2]], env);
- add_v3_v3(mesh->indirect[face[2]], indirect);
- count[face[2]]++;
-
- if (face[3]) {
- add_v3_v3(mesh->ao[face[3]], ao);
- add_v3_v3(mesh->env[face[3]], env);
- add_v3_v3(mesh->indirect[face[3]], indirect);
- count[face[3]]++;
- }
- }
-
- for (a = 0; a < mesh->totvert; a++) {
- if (count[a]) {
- mul_v3_fl(mesh->ao[a], 1.0f / count[a]);
- mul_v3_fl(mesh->env[a], 1.0f / count[a]);
- mul_v3_fl(mesh->indirect[a], 1.0f / count[a]);
- }
- }
-
- MEM_freeN(count);
- MEM_freeN(faceao);
- MEM_freeN(faceenv);
- MEM_freeN(faceindirect);
- }
- }
-}
-
-void free_occ(Render *re)
-{
- if (re->occlusiontree) {
- occ_free_tree(re->occlusiontree);
- re->occlusiontree = NULL;
- }
-}
-
-void sample_occ(Render *re, ShadeInput *shi)
-{
- OcclusionTree *tree = re->occlusiontree;
- OcclusionCache *cache;
- OcclusionCacheSample *sample;
- OccFace exclude;
- int onlyshadow;
-
- if (tree) {
- if (shi->strand) {
- sample_occ_surface(shi);
- }
- /* try to get result from the cache if possible */
- else if (shi->depth != 0 || !sample_occ_cache(tree, shi->co, shi->vno, shi->xs, shi->ys, shi->thread, shi->ao, shi->env, shi->indirect)) {
- /* no luck, let's sample the occlusion */
- exclude.obi = shi->obi - re->objectinstance;
- exclude.facenr = shi->vlr->index;
- onlyshadow = (shi->mat->mode & MA_ONLYSHADOW);
- sample_occ_tree(re, tree, &exclude, shi->co, shi->vno, shi->thread, onlyshadow, shi->ao, shi->env, shi->indirect);
-
- /* fill result into sample, each time */
- if (tree->cache) {
- cache = &tree->cache[shi->thread];
-
- if (cache->sample && cache->step) {
- sample = &cache->sample[(shi->ys - cache->y) * cache->w + (shi->xs - cache->x)];
- copy_v3_v3(sample->co, shi->co);
- copy_v3_v3(sample->n, shi->vno);
- copy_v3_v3(sample->ao, shi->ao);
- copy_v3_v3(sample->env, shi->env);
- copy_v3_v3(sample->indirect, shi->indirect);
- sample->intensity = max_fff(sample->ao[0], sample->ao[1], sample->ao[2]);
- sample->intensity = max_ff(sample->intensity, max_fff(sample->env[0], sample->env[1], sample->env[2]));
- sample->intensity = max_ff(sample->intensity, max_fff(sample->indirect[0], sample->indirect[1], sample->indirect[2]));
- sample->dist2 = dot_v3v3(shi->dxco, shi->dxco) + dot_v3v3(shi->dyco, shi->dyco);
- sample->filled = 1;
- }
- }
- }
- }
- else {
- shi->ao[0] = 1.0f;
- shi->ao[1] = 1.0f;
- shi->ao[2] = 1.0f;
-
- shi->env[0] = 0.0f;
- shi->env[1] = 0.0f;
- shi->env[2] = 0.0f;
-
- shi->indirect[0] = 0.0f;
- shi->indirect[1] = 0.0f;
- shi->indirect[2] = 0.0f;
- }
-}
-
-void cache_occ_samples(Render *re, RenderPart *pa, ShadeSample *ssamp)
-{
- OcclusionTree *tree = re->occlusiontree;
- PixStr ps;
- OcclusionCache *cache;
- OcclusionCacheSample *sample;
- OccFace exclude;
- ShadeInput *shi;
- intptr_t *rd = NULL;
- int *ro = NULL, *rp = NULL, *rz = NULL, onlyshadow;
- int x, y, step = CACHE_STEP;
-
- if (!tree->cache)
- return;
-
- cache = &tree->cache[pa->thread];
- cache->w = pa->rectx;
- cache->h = pa->recty;
- cache->x = pa->disprect.xmin;
- cache->y = pa->disprect.ymin;
- cache->step = step;
- cache->sample = MEM_callocN(sizeof(OcclusionCacheSample) * cache->w * cache->h, "OcclusionCacheSample");
- sample = cache->sample;
-
- if (re->osa) {
- rd = pa->rectdaps;
- }
- else {
- /* fake pixel struct for non-osa */
- ps.next = NULL;
- ps.mask = 0xFFFF;
-
- ro = pa->recto;
- rp = pa->rectp;
- rz = pa->rectz;
- }
-
- /* compute a sample at every step pixels */
- for (y = pa->disprect.ymin; y < pa->disprect.ymax; y++) {
- for (x = pa->disprect.xmin; x < pa->disprect.xmax; x++, sample++, rd++, ro++, rp++, rz++) {
- if (!(((x - pa->disprect.xmin + step) % step) == 0 || x == pa->disprect.xmax - 1))
- continue;
- if (!(((y - pa->disprect.ymin + step) % step) == 0 || y == pa->disprect.ymax - 1))
- continue;
-
- if (re->osa) {
- if (!*rd) continue;
-
- shade_samples_fill_with_ps(ssamp, (PixStr *)(*rd), x, y);
- }
- else {
- if (!*rp) continue;
-
- ps.obi = *ro;
- ps.facenr = *rp;
- ps.z = *rz;
- shade_samples_fill_with_ps(ssamp, &ps, x, y);
- }
-
- shi = ssamp->shi;
- if (shi->vlr) {
- onlyshadow = (shi->mat->mode & MA_ONLYSHADOW);
- exclude.obi = shi->obi - re->objectinstance;
- exclude.facenr = shi->vlr->index;
- sample_occ_tree(re, tree, &exclude, shi->co, shi->vno, shi->thread, onlyshadow, shi->ao, shi->env, shi->indirect);
-
- copy_v3_v3(sample->co, shi->co);
- copy_v3_v3(sample->n, shi->vno);
- copy_v3_v3(sample->ao, shi->ao);
- copy_v3_v3(sample->env, shi->env);
- copy_v3_v3(sample->indirect, shi->indirect);
- sample->intensity = max_fff(sample->ao[0], sample->ao[1], sample->ao[2]);
- sample->intensity = max_ff(sample->intensity, max_fff(sample->env[0], sample->env[1], sample->env[2]));
- sample->intensity = max_ff(sample->intensity, max_fff(sample->indirect[0], sample->indirect[1], sample->indirect[2]));
- sample->dist2 = dot_v3v3(shi->dxco, shi->dxco) + dot_v3v3(shi->dyco, shi->dyco);
- sample->x = shi->xs;
- sample->y = shi->ys;
- sample->filled = 1;
- }
-
- if (re->test_break(re->tbh))
- break;
- }
- }
-}
-
-void free_occ_samples(Render *re, RenderPart *pa)
-{
- OcclusionTree *tree = re->occlusiontree;
- OcclusionCache *cache;
-
- if (tree->cache) {
- cache = &tree->cache[pa->thread];
-
- if (cache->sample)
- MEM_freeN(cache->sample);
-
- cache->w = 0;
- cache->h = 0;
- cache->step = 0;
- }
-}
-
diff --git a/source/blender/render/intern/source/pipeline.c b/source/blender/render/intern/source/pipeline.c
index d1de985e4d6..df356bee295 100644
--- a/source/blender/render/intern/source/pipeline.c
+++ b/source/blender/render/intern/source/pipeline.c
@@ -64,9 +64,9 @@
#include "BKE_animsys.h" /* <------ should this be here?, needed for sequencer update */
#include "BKE_camera.h"
#include "BKE_colortools.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_image.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
#include "BKE_main.h"
@@ -80,6 +80,10 @@
#include "BKE_writeavi.h" /* <------ should be replaced once with generic movie module */
#include "BKE_object.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_query.h"
+
#include "PIL_time.h"
#include "IMB_colormanagement.h"
#include "IMB_imbuf.h"
@@ -88,6 +92,7 @@
#include "RE_engine.h"
#include "RE_pipeline.h"
+#include "RE_render_ext.h"
#ifdef WITH_FREESTYLE
# include "FRS_freestyle.h"
@@ -96,14 +101,10 @@
#include "DEG_depsgraph.h"
/* internal */
+#include "initrender.h"
+#include "renderpipeline.h"
#include "render_result.h"
#include "render_types.h"
-#include "renderpipeline.h"
-#include "renderdatabase.h"
-#include "rendercore.h"
-#include "initrender.h"
-#include "pixelblending.h"
-#include "zbuf.h"
/* render flow
*
@@ -138,19 +139,10 @@ static struct {
ListBase renderlist;
} RenderGlobal = {{NULL, NULL}};
-/* hardcopy of current render, used while rendering for speed */
-Render R;
-
/* ********* alloc and free ******** */
static int do_write_image_or_movie(Render *re, Main *bmain, Scene *scene, bMovieHandle *mh, const int totvideos, const char *name_override);
-static volatile int g_break = 0;
-static int thread_break(void *UNUSED(arg))
-{
- return g_break;
-}
-
/* default callbacks, set in each new render */
static void result_nothing(void *UNUSED(arg), RenderResult *UNUSED(rr)) {}
static void result_rcti_nothing(void *UNUSED(arg), RenderResult *UNUSED(rr), volatile struct rcti *UNUSED(rect)) {}
@@ -270,11 +262,11 @@ RenderResult *RE_MultilayerConvert(void *exrhandle, const char *colorspace, bool
RenderLayer *render_get_active_layer(Render *re, RenderResult *rr)
{
- SceneRenderLayer *srl = BLI_findlink(&re->r.layers, re->r.actlay);
+ ViewLayer *view_layer = BLI_findlink(&re->view_layers, re->active_view_layer);
- if (srl) {
+ if (view_layer) {
RenderLayer *rl = BLI_findstring(&rr->layers,
- srl->name,
+ view_layer->name,
offsetof(RenderLayer, name));
if (rl) {
@@ -285,23 +277,15 @@ RenderLayer *render_get_active_layer(Render *re, RenderResult *rr)
return rr->layers.first;
}
-static int render_scene_needs_vector(Render *re)
+static bool render_scene_has_layers_to_render(Scene *scene, ViewLayer *single_layer)
{
- SceneRenderLayer *srl;
-
- for (srl = re->r.layers.first; srl; srl = srl->next)
- if (!(srl->layflag & SCE_LAY_DISABLE))
- if (srl->passflag & SCE_PASS_VECTOR)
- return 1;
-
- return 0;
-}
+ if (single_layer) {
+ return true;
+ }
-static bool render_scene_has_layers_to_render(Scene *scene)
-{
- SceneRenderLayer *srl;
- for (srl = scene->r.layers.first; srl; srl = srl->next) {
- if (!(srl->layflag & SCE_LAY_DISABLE)) {
+ ViewLayer *view_layer;
+ for (view_layer = scene->view_layers.first; view_layer; view_layer = view_layer->next) {
+ if (view_layer->flag & VIEW_LAYER_RENDER) {
return true;
}
}
@@ -517,14 +501,10 @@ Render *RE_NewRender(const char *name)
BLI_strncpy(re->name, name, RE_MAXNAME);
BLI_rw_mutex_init(&re->resultmutex);
BLI_rw_mutex_init(&re->partsmutex);
- re->eval_ctx = DEG_evaluation_context_new(DAG_EVAL_RENDER);
}
RE_InitRenderCB(re);
- /* init some variables */
- re->ycor = 1.0f;
-
return re;
}
@@ -586,7 +566,7 @@ void RE_FreeRender(Render *re)
BLI_rw_mutex_end(&re->resultmutex);
BLI_rw_mutex_end(&re->partsmutex);
- BLI_freelistN(&re->r.layers);
+ BLI_freelistN(&re->view_layers);
BLI_freelistN(&re->r.views);
curvemapping_free_data(&re->r.mblur_shutter_curve);
@@ -595,14 +575,10 @@ void RE_FreeRender(Render *re)
re->main = NULL;
re->scene = NULL;
- RE_Database_Free(re); /* view render can still have full database */
- free_sample_tables(re);
-
render_result_free(re->result);
render_result_free(re->pushedresult);
BLI_remlink(&RenderGlobal.renderlist, re);
- MEM_freeN(re->eval_ctx);
MEM_freeN(re);
}
@@ -667,14 +643,8 @@ static int check_mode_full_sample(RenderData *rd)
{
int scemode = rd->scemode;
- if (!STREQ(rd->engine, RE_engine_id_BLENDER_RENDER) &&
- !STREQ(rd->engine, RE_engine_id_BLENDER_GAME))
- {
- scemode &= ~R_FULL_SAMPLE;
- }
-
- if ((rd->mode & R_OSA) == 0)
- scemode &= ~R_FULL_SAMPLE;
+ /* not supported by any current renderer */
+ scemode &= ~R_FULL_SAMPLE;
#ifdef WITH_OPENEXR
if (scemode & R_FULL_SAMPLE)
@@ -694,7 +664,7 @@ static void re_init_resolution(Render *re, Render *source,
re->winy = winy;
if (source && (source->r.mode & R_BORDER)) {
/* eeh, doesn't seem original bordered disprect is storing anywhere
- * after insertion on black happening in do_render_fields_blur_3d(),
+ * after insertion on black happening in do_render(),
* so for now simply re-calculate disprect using border from source
* renderer (sergey)
*/
@@ -723,20 +693,15 @@ static void re_init_resolution(Render *re, Render *source,
re->rectx = winx;
re->recty = winy;
}
-
- /* we clip faces with a minimum of 2 pixel boundary outside of image border. see zbuf.c */
- re->clipcrop = 1.0f + 2.0f / (float)(re->winx > re->winy ? re->winy : re->winx);
}
void render_copy_renderdata(RenderData *to, RenderData *from)
{
- BLI_freelistN(&to->layers);
BLI_freelistN(&to->views);
curvemapping_free_data(&to->mblur_shutter_curve);
*to = *from;
- BLI_duplicatelist(&to->layers, &from->layers);
BLI_duplicatelist(&to->views, &from->views);
curvemapping_copy_data(&to->mblur_shutter_curve, &from->mblur_shutter_curve);
}
@@ -744,7 +709,7 @@ void render_copy_renderdata(RenderData *to, RenderData *from)
/* what doesn't change during entire render sequence */
/* disprect is optional, if NULL it assumes full window render */
void RE_InitState(Render *re, Render *source, RenderData *rd,
- SceneRenderLayer *srl,
+ ListBase *render_layers, ViewLayer *single_layer,
int winx, int winy, rcti *disprect)
{
bool had_freestyle = (re->r.mode & R_EDGE_FRS) != 0;
@@ -755,6 +720,9 @@ void RE_InitState(Render *re, Render *source, RenderData *rd,
/* copy render data and render layers for thread safety */
render_copy_renderdata(&re->r, rd);
+ BLI_freelistN(&re->view_layers);
+ BLI_duplicatelist(&re->view_layers, render_layers);
+ re->active_view_layer = 0;
if (source) {
/* reuse border flags from source renderer */
@@ -786,34 +754,14 @@ void RE_InitState(Render *re, Render *source, RenderData *rd,
re->r.scemode = check_mode_full_sample(&re->r);
- /* fullsample wants uniform osa levels */
- if (source && (re->r.scemode & R_FULL_SAMPLE)) {
- /* but, if source has no full sample we disable it */
- if ((source->r.scemode & R_FULL_SAMPLE) == 0)
- re->r.scemode &= ~R_FULL_SAMPLE;
- else
- re->r.osa = re->osa = source->osa;
- }
- else {
- /* check state variables, osa? */
- if (re->r.mode & (R_OSA)) {
- re->osa = re->r.osa;
- if (re->osa > 16) re->osa = 16;
- }
- else re->osa = 0;
- }
-
- if (srl) {
- int index = BLI_findindex(&rd->layers, srl);
+ if (single_layer) {
+ int index = BLI_findindex(render_layers, single_layer);
if (index != -1) {
- re->r.actlay = index;
+ re->active_view_layer = index;
re->r.scemode |= R_SINGLE_LAYER;
}
}
- /* always call, checks for gamma, gamma tables and jitter too */
- make_sample_tables(re);
-
/* if preview render, we try to keep old result */
BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
@@ -824,12 +772,12 @@ void RE_InitState(Render *re, Render *source, RenderData *rd,
re->result = NULL;
}
else if (re->result) {
- SceneRenderLayer *actsrl = BLI_findlink(&re->r.layers, re->r.actlay);
+ ViewLayer *active_render_layer = BLI_findlink(&re->view_layers, re->active_view_layer);
RenderLayer *rl;
bool have_layer = false;
for (rl = re->result->layers.first; rl; rl = rl->next)
- if (STREQ(rl->name, actsrl->name))
+ if (STREQ(rl->name, active_render_layer->name))
have_layer = true;
if (re->result->rectx == re->rectx && re->result->recty == re->recty &&
@@ -854,20 +802,19 @@ void RE_InitState(Render *re, Render *source, RenderData *rd,
re->result->recty = re->recty;
render_result_view_new(re->result, "");
}
-
- if (re->r.scemode & R_VIEWPORT_PREVIEW)
- re->eval_ctx->mode = DAG_EVAL_PREVIEW;
- else
- re->eval_ctx->mode = DAG_EVAL_RENDER;
-
+
+ eEvaluationMode mode = (re->r.scemode & R_VIEWPORT_PREVIEW) ? DAG_EVAL_PREVIEW : DAG_EVAL_RENDER;
+ /* This mode should have been set in the Depsgraph immediately when it was created. */
+ (void)mode;
+
/* ensure renderdatabase can use part settings correct */
RE_parts_clamp(re);
BLI_rw_mutex_unlock(&re->resultmutex);
- re->mblur_offs = re->field_offs = 0.f;
-
RE_init_threadcount(re);
+
+ RE_point_density_fix_linking();
}
/* This function is only called by view3d rendering, which doesn't support
@@ -954,13 +901,12 @@ void RE_ChangeModeFlag(Render *re, int flag, bool clear)
/* update some variables that can be animated, and otherwise wouldn't be due to
* RenderData getting copied once at the start of animation render */
-void render_update_anim_renderdata(Render *re, RenderData *rd)
+void render_update_anim_renderdata(Render *re, RenderData *rd, ListBase *render_layers)
{
/* filter */
re->r.gauss = rd->gauss;
/* motion blur */
- re->r.mblur_samples = rd->mblur_samples;
re->r.blurfac = rd->blurfac;
/* freestyle */
@@ -968,8 +914,8 @@ void render_update_anim_renderdata(Render *re, RenderData *rd)
re->r.unit_line_thickness = rd->unit_line_thickness;
/* render layers */
- BLI_freelistN(&re->r.layers);
- BLI_duplicatelist(&re->r.layers, &rd->layers);
+ BLI_freelistN(&re->view_layers);
+ BLI_duplicatelist(&re->view_layers, render_layers);
/* render views */
BLI_freelistN(&re->r.views);
@@ -1088,783 +1034,19 @@ void RE_AddObject(Render *UNUSED(re), Object *UNUSED(ob))
/* *************************************** */
-static int render_display_update_enabled(Render *re)
-{
- /* don't show preprocess for previewrender sss */
- if (re->sss_points)
- return !(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW));
- else
- return 1;
-}
-
-/* the main thread call, renders an entire part */
-static void *do_part_thread(void *pa_v)
-{
- RenderPart *pa = pa_v;
-
- pa->status = PART_STATUS_IN_PROGRESS;
-
- /* need to return nicely all parts on esc */
- if (R.test_break(R.tbh) == 0) {
-
- if (!R.sss_points && (R.r.scemode & R_FULL_SAMPLE))
- pa->result = render_result_new_full_sample(&R, &pa->fullresult, &pa->disprect, pa->crop, RR_USE_MEM, R.viewname);
- else
- pa->result = render_result_new(&R, &pa->disprect, pa->crop, RR_USE_MEM, RR_ALL_LAYERS, R.viewname);
-
- /* Copy EXR tile settings, so pipeline knows whether this is a result
- * for Save Buffers enabled rendering.
- *
- * TODO(sergey): This actually duplicates logic with external engine, so
- * worth looking into more generic solution.
- */
- pa->result->do_exr_tile = R.result->do_exr_tile;
-
- if (R.sss_points)
- zbufshade_sss_tile(pa);
- else if (R.osa)
- zbufshadeDA_tile(pa);
- else
- zbufshade_tile(pa);
-
- /* we do actually write pixels, but don't allocate/deallocate anything,
- * so it is safe with other threads reading at the same time */
- BLI_rw_mutex_lock(&R.resultmutex, THREAD_LOCK_READ);
-
- /* merge too on break! */
- if (R.result->do_exr_tile) {
- render_result_exr_file_merge(R.result, pa->result, R.viewname);
- }
- else if (render_display_update_enabled(&R)) {
- /* on break, don't merge in result for preview renders, looks nicer */
- if (R.test_break(R.tbh) && (R.r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))) {
- /* pass */
- }
- else {
- render_result_merge(R.result, pa->result);
- }
- }
-
- BLI_rw_mutex_unlock(&R.resultmutex);
- }
-
- pa->status = PART_STATUS_MERGED;
-
- return NULL;
-}
-
-/* calculus for how much 1 pixel rendered should rotate the 3d geometry */
-/* is not that simple, needs to be corrected for errors of larger viewplane sizes */
-/* called in initrender.c, RE_parts_init() and convertblender.c, for speedvectors */
-float panorama_pixel_rot(Render *re)
-{
- float psize, phi, xfac;
- float borderfac = (float)BLI_rcti_size_x(&re->disprect) / (float)re->winx;
- int xparts = (re->rectx + re->partx - 1) / re->partx;
-
- /* size of 1 pixel mapped to viewplane coords */
- psize = BLI_rctf_size_x(&re->viewplane) / (float)re->winx;
- /* angle of a pixel */
- phi = atan(psize / re->clipsta);
-
- /* correction factor for viewplane shifting, first calculate how much the viewplane angle is */
- xfac = borderfac * BLI_rctf_size_x(&re->viewplane) / (float)xparts;
- xfac = atan(0.5f * xfac / re->clipsta);
- /* and how much the same viewplane angle is wrapped */
- psize = 0.5f * phi * ((float)re->partx);
-
- /* the ratio applied to final per-pixel angle */
- phi *= xfac / psize;
-
- return phi;
-}
-
-/* for panorama, we render per Y slice, and update
- * camera parameters when we go the next slice */
-static bool find_next_pano_slice(Render *re, int *slice, int *minx, rctf *viewplane)
-{
- RenderPart *pa, *best = NULL;
- bool found = false;
-
- *minx = re->winx;
-
- if (!(re->r.mode & R_PANORAMA)) {
- /* for regular render, just one 'slice' */
- found = (*slice == 0);
- (*slice)++;
- return found;
- }
-
- /* most left part of the non-rendering parts */
- for (pa = re->parts.first; pa; pa = pa->next) {
- if (pa->status == PART_STATUS_NONE && pa->nr == 0) {
- if (pa->disprect.xmin < *minx) {
- found = true;
- best = pa;
- *minx = pa->disprect.xmin;
- }
- }
- }
-
- if (best) {
- float phi = panorama_pixel_rot(re);
-
- R.panodxp = (re->winx - (best->disprect.xmin + best->disprect.xmax) ) / 2;
- R.panodxv = (BLI_rctf_size_x(viewplane) * R.panodxp) / (float)(re->winx);
-
- /* shift viewplane */
- R.viewplane.xmin = viewplane->xmin + R.panodxv;
- R.viewplane.xmax = viewplane->xmax + R.panodxv;
- RE_SetWindow(re, &R.viewplane, R.clipsta, R.clipend);
- copy_m4_m4(R.winmat, re->winmat);
-
- /* rotate database according to part coordinates */
- project_renderdata(re, projectverto, 1, -R.panodxp * phi, 1);
- R.panosi = sinf(R.panodxp * phi);
- R.panoco = cosf(R.panodxp * phi);
- }
-
- (*slice)++;
-
- return found;
-}
-
-typedef struct SortRenderPart {
- RenderPart *pa;
- long long int dist;
-} SortRenderPart;
-
-static int sort_render_part(const void *pa1, const void *pa2) {
- const SortRenderPart *rpa1 = pa1;
- const SortRenderPart *rpa2 = pa2;
-
- if (rpa1->dist > rpa2->dist) return 1;
- else if (rpa1->dist < rpa2->dist) return -1;
-
- return 0;
-}
-
-static int sort_and_queue_parts(Render *re, int minx, ThreadQueue *workqueue)
-{
- RenderPart *pa;
-
- /* long long int's needed because of overflow [#24414] */
- long long int centx = re->winx / 2, centy = re->winy / 2, tot = 1;
- int totsort = 0;
-
- /* find center of rendered parts, image center counts for 1 too */
- for (pa = re->parts.first; pa; pa = pa->next) {
- if (pa->status >= PART_STATUS_RENDERED) {
- centx += BLI_rcti_cent_x(&pa->disprect);
- centy += BLI_rcti_cent_y(&pa->disprect);
- tot++;
- }
- else if (pa->status == PART_STATUS_NONE && pa->nr == 0) {
- if (!(re->r.mode & R_PANORAMA) || pa->disprect.xmin == minx) {
- totsort++;
- }
- }
- }
- centx /= tot;
- centy /= tot;
-
- if (totsort > 0) {
- SortRenderPart *sortlist = MEM_mallocN(sizeof(*sortlist) * totsort, "renderpartsort");
- long int i = 0;
-
- /* prepare the list */
- for (pa = re->parts.first; pa; pa = pa->next) {
- if (pa->status == PART_STATUS_NONE && pa->nr == 0) {
- if (!(re->r.mode & R_PANORAMA) || pa->disprect.xmin == minx) {
- long long int distx = centx - BLI_rcti_cent_x(&pa->disprect);
- long long int disty = centy - BLI_rcti_cent_y(&pa->disprect);
- sortlist[i].dist = (long long int)sqrt(distx * distx + disty * disty);
- sortlist[i].pa = pa;
- i++;
- }
- }
- }
-
- /* Now sort it */
- qsort(sortlist, totsort, sizeof(*sortlist), sort_render_part);
-
- /* Finally flush it to the workqueue */
- for (i = 0; i < totsort; i++) {
- pa = sortlist[i].pa;
- pa->nr = i + 1; /* for nicest part, and for stats */
- BLI_thread_queue_push(workqueue, pa);
- }
-
- MEM_freeN(sortlist);
-
- return totsort;
- }
-
- return 0;
-}
-
-static void print_part_stats(Render *re, RenderPart *pa)
-{
- char str[64];
-
- BLI_snprintf(str, sizeof(str), IFACE_("%s, Part %d-%d"), re->scene->id.name + 2, pa->nr, re->i.totpart);
- re->i.infostr = str;
- re->stats_draw(re->sdh, &re->i);
- re->i.infostr = NULL;
-}
-
-typedef struct RenderThread {
- ThreadQueue *workqueue;
- ThreadQueue *donequeue;
-
- int number;
-
- void (*display_update)(void *handle, RenderResult *rr, volatile rcti *rect);
- void *duh;
-} RenderThread;
-
-static void *do_render_thread(void *thread_v)
-{
- RenderThread *thread = thread_v;
- RenderPart *pa;
-
- while ((pa = BLI_thread_queue_pop(thread->workqueue))) {
- pa->thread = thread->number;
- do_part_thread(pa);
-
- if (thread->display_update) {
- thread->display_update(thread->duh, pa->result, NULL);
- }
-
- BLI_thread_queue_push(thread->donequeue, pa);
-
- if (R.test_break(R.tbh))
- break;
- }
-
- return NULL;
-}
-
-static void main_render_result_end(Render *re)
-{
- if (re->result->do_exr_tile) {
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- render_result_exr_file_end(re);
- BLI_rw_mutex_unlock(&re->resultmutex);
- }
-
- if (re->r.scemode & R_EXR_CACHE_FILE) {
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- render_result_exr_file_cache_write(re);
- BLI_rw_mutex_unlock(&re->resultmutex);
- }
-}
-
-static void main_render_result_new(Render *re)
-{
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
-
- /* first step; free the entire render result, make new, and/or prepare exr buffer saving */
- if (re->result == NULL || !(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))) {
- render_result_free(re->result);
-
- if (re->sss_points && render_display_update_enabled(re))
- re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS, RR_ALL_VIEWS);
- else if (re->r.scemode & R_FULL_SAMPLE)
- re->result = render_result_new_full_sample(re, &re->fullresult, &re->disprect, 0, RR_USE_EXR, RR_ALL_VIEWS);
- else
- re->result = render_result_new(re, &re->disprect, 0,
- (re->r.scemode & R_EXR_TILE_FILE) ? RR_USE_EXR : RR_USE_MEM, RR_ALL_LAYERS, RR_ALL_VIEWS);
- }
-
- BLI_rw_mutex_unlock(&re->resultmutex);
-
- if (re->result) {
- if (re->result->do_exr_tile) {
- render_result_exr_file_begin(re);
- }
- }
-}
-
-static void threaded_tile_processor(Render *re)
-{
- RenderThread thread[BLENDER_MAX_THREADS];
- ThreadQueue *workqueue, *donequeue;
- ListBase threads;
- RenderPart *pa;
- rctf viewplane = re->viewplane;
- double lastdraw, elapsed, redrawtime = 1.0f;
- int totpart = 0, minx = 0, slice = 0, a, wait;
-
- if (re->result == NULL)
- return;
-
- /* warning; no return here without closing exr file */
- RE_parts_init(re, true);
-
- /* assuming no new data gets added to dbase... */
- R = *re;
-
- /* set threadsafe break */
- R.test_break = thread_break;
-
- /* create and fill work queue */
- workqueue = BLI_thread_queue_init();
- donequeue = BLI_thread_queue_init();
-
- /* for panorama we loop over slices */
- while (find_next_pano_slice(re, &slice, &minx, &viewplane)) {
- /* gather parts into queue */
- totpart = sort_and_queue_parts(re, minx, workqueue);
-
- BLI_thread_queue_nowait(workqueue);
-
- /* start all threads */
- BLI_threadpool_init(&threads, do_render_thread, re->r.threads);
-
- for (a = 0; a < re->r.threads; a++) {
- thread[a].workqueue = workqueue;
- thread[a].donequeue = donequeue;
- thread[a].number = a;
-
- if (render_display_update_enabled(re)) {
- thread[a].display_update = re->display_update;
- thread[a].duh = re->duh;
- }
- else {
- thread[a].display_update = NULL;
- thread[a].duh = NULL;
- }
-
- BLI_threadpool_insert(&threads, &thread[a]);
- }
-
- /* wait for results to come back */
- lastdraw = PIL_check_seconds_timer();
-
- while (1) {
- elapsed = PIL_check_seconds_timer() - lastdraw;
- wait = (redrawtime - elapsed)*1000;
-
- /* handle finished part */
- if ((pa=BLI_thread_queue_pop_timeout(donequeue, wait))) {
- if (pa->result) {
- print_part_stats(re, pa);
-
- render_result_free_list(&pa->fullresult, pa->result);
- pa->result = NULL;
- re->i.partsdone++;
- re->progress(re->prh, re->i.partsdone / (float)re->i.totpart);
- }
-
- totpart--;
- }
-
- /* check for render cancel */
- if ((g_break=re->test_break(re->tbh)))
- break;
-
- /* or done with parts */
- if (totpart == 0)
- break;
-
- /* redraw in progress parts */
- elapsed = PIL_check_seconds_timer() - lastdraw;
- if (elapsed > redrawtime) {
- if (render_display_update_enabled(re))
- for (pa = re->parts.first; pa; pa = pa->next)
- if ((pa->status == PART_STATUS_IN_PROGRESS) && pa->nr && pa->result)
- re->display_update(re->duh, pa->result, &pa->result->renrect);
-
- lastdraw = PIL_check_seconds_timer();
- }
- }
-
- BLI_threadpool_end(&threads);
-
- if ((g_break=re->test_break(re->tbh)))
- break;
- }
-
- if (g_break) {
- /* review the done queue and handle all the render parts,
- * so no unfreed render result are lurking around
- */
- BLI_thread_queue_nowait(donequeue);
- while ((pa = BLI_thread_queue_pop(donequeue))) {
- if (pa->result) {
- render_result_free_list(&pa->fullresult, pa->result);
- pa->result = NULL;
- }
- }
- }
-
- BLI_thread_queue_free(donequeue);
- BLI_thread_queue_free(workqueue);
-
- if (re->result->do_exr_tile) {
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- render_result_save_empty_result_tiles(re);
- BLI_rw_mutex_unlock(&re->resultmutex);
- }
-
- /* unset threadsafety */
- g_break = 0;
- BLI_rw_mutex_lock(&re->partsmutex, THREAD_LOCK_WRITE);
- RE_parts_free(re);
- BLI_rw_mutex_unlock(&re->partsmutex);
- re->viewplane = viewplane; /* restore viewplane, modified by pano render */
-}
-
#ifdef WITH_FREESTYLE
static void init_freestyle(Render *re);
static void add_freestyle(Render *re, int render);
static void free_all_freestyle_renders(void);
#endif
-/* currently only called by preview renders and envmap */
-void RE_TileProcessor(Render *re)
-{
- main_render_result_new(re);
- threaded_tile_processor(re);
-
- re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime;
- re->stats_draw(re->sdh, &re->i);
-
-#ifdef WITH_FREESTYLE
- /* Freestyle */
- if (re->r.mode & R_EDGE_FRS) {
- if (!re->test_break(re->tbh)) {
- init_freestyle(re);
- add_freestyle(re, 1);
- free_all_freestyle_renders();
-
- re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime;
- re->stats_draw(re->sdh, &re->i);
- }
- }
-#endif
-
-}
/* ************ This part uses API, for rendering Blender scenes ********** */
static void do_render_3d(Render *re)
{
- RenderView *rv;
-
re->current_scene_update(re->suh, re->scene);
-
- /* try external */
- if (RE_engine_render(re, 0))
- return;
-
- /* internal */
- RE_parts_clamp(re);
-
- /* add motion blur and fields offset to frames */
- const int cfra_backup = re->scene->r.cfra;
- const float subframe_backup = re->scene->r.subframe;
-
- BKE_scene_frame_set(
- re->scene, (double)re->scene->r.cfra + (double)re->scene->r.subframe +
- (double)re->mblur_offs + (double)re->field_offs);
-
- /* init main render result */
- main_render_result_new(re);
- if (re->result == NULL) {
- BKE_report(re->reports, RPT_ERROR, "Failed allocate render result, out of memory");
- G.is_break = true;
- return;
- }
-
-#ifdef WITH_FREESTYLE
- if (re->r.mode & R_EDGE_FRS) {
- init_freestyle(re);
- }
-#endif
-
- /* we need a new database for each view */
- for (rv = re->result->views.first; rv; rv = rv->next) {
- RE_SetActiveRenderView(re, rv->name);
-
- /* lock drawing in UI during data phase */
- if (re->draw_lock)
- re->draw_lock(re->dlh, 1);
-
- /* make render verts/faces/halos/lamps */
- if (render_scene_needs_vector(re))
- RE_Database_FromScene_Vectors(re, re->main, re->scene, re->lay);
- else {
- RE_Database_FromScene(re, re->main, re->scene, re->lay, 1);
- RE_Database_Preprocess(re);
- }
-
- /* clear UI drawing locks */
- if (re->draw_lock)
- re->draw_lock(re->dlh, 0);
-
- threaded_tile_processor(re);
-
-#ifdef WITH_FREESTYLE
- /* Freestyle */
- if (re->r.mode & R_EDGE_FRS)
- if (!re->test_break(re->tbh))
- add_freestyle(re, 1);
-#endif
-
- /* do left-over 3d post effects (flares) */
- if (re->flag & R_HALO)
- if (!re->test_break(re->tbh))
- add_halo_flare(re);
-
- /* free all render verts etc */
- RE_Database_Free(re);
- }
-
- main_render_result_end(re);
-
- re->scene->r.cfra = cfra_backup;
- re->scene->r.subframe = subframe_backup;
-}
-
-/* called by blur loop, accumulate RGBA key alpha */
-static void addblur_rect_key(RenderResult *rr, float *rectf, float *rectf1, float blurfac)
-{
- float mfac = 1.0f - blurfac;
- int a, b, stride = 4 * rr->rectx;
- int len = stride * sizeof(float);
-
- for (a = 0; a < rr->recty; a++) {
- if (blurfac == 1.0f) {
- memcpy(rectf, rectf1, len);
- }
- else {
- float *rf = rectf, *rf1 = rectf1;
-
- for (b = rr->rectx; b > 0; b--, rf += 4, rf1 += 4) {
- if (rf1[3] < 0.01f)
- rf[3] = mfac * rf[3];
- else if (rf[3] < 0.01f) {
- rf[0] = rf1[0];
- rf[1] = rf1[1];
- rf[2] = rf1[2];
- rf[3] = blurfac * rf1[3];
- }
- else {
- rf[0] = mfac * rf[0] + blurfac * rf1[0];
- rf[1] = mfac * rf[1] + blurfac * rf1[1];
- rf[2] = mfac * rf[2] + blurfac * rf1[2];
- rf[3] = mfac * rf[3] + blurfac * rf1[3];
- }
- }
- }
- rectf += stride;
- rectf1 += stride;
- }
-}
-
-/* called by blur loop, accumulate renderlayers */
-static void addblur_rect(RenderResult *rr, float *rectf, float *rectf1, float blurfac, int channels)
-{
- float mfac = 1.0f - blurfac;
- int a, b, stride = channels * rr->rectx;
- int len = stride * sizeof(float);
-
- for (a = 0; a < rr->recty; a++) {
- if (blurfac == 1.0f) {
- memcpy(rectf, rectf1, len);
- }
- else {
- float *rf = rectf, *rf1 = rectf1;
-
- for (b = rr->rectx * channels; b > 0; b--, rf++, rf1++) {
- rf[0] = mfac * rf[0] + blurfac * rf1[0];
- }
- }
- rectf += stride;
- rectf1 += stride;
- }
-}
-
-
-/* called by blur loop, accumulate renderlayers */
-static void merge_renderresult_blur(RenderResult *rr, RenderResult *brr, float blurfac, bool key_alpha)
-{
- RenderLayer *rl, *rl1;
- RenderPass *rpass, *rpass1;
-
- rl1 = brr->layers.first;
- for (rl = rr->layers.first; rl && rl1; rl = rl->next, rl1 = rl1->next) {
- /* passes are allocated in sync */
- rpass1 = rl1->passes.first;
- for (rpass = rl->passes.first; rpass && rpass1; rpass = rpass->next, rpass1 = rpass1->next) {
- if (STREQ(rpass->name, RE_PASSNAME_COMBINED) && key_alpha)
- addblur_rect_key(rr, rpass->rect, rpass1->rect, blurfac);
- else
- addblur_rect(rr, rpass->rect, rpass1->rect, blurfac, rpass->channels);
- }
- }
-}
-
-/* main blur loop, can be called by fields too */
-static void do_render_blur_3d(Render *re)
-{
- RenderResult *rres;
- float blurfac;
- int blur = re->r.mblur_samples;
-
- /* create accumulation render result */
- rres = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS, RR_ALL_VIEWS);
-
- /* do the blur steps */
- while (blur--) {
- re->mblur_offs = re->r.blurfac * ((float)(re->r.mblur_samples - blur)) / (float)re->r.mblur_samples;
-
- re->i.curblur = re->r.mblur_samples - blur; /* stats */
-
- do_render_3d(re);
-
- blurfac = 1.0f / (float)(re->r.mblur_samples - blur);
-
- merge_renderresult_blur(rres, re->result, blurfac, false);
- if (re->test_break(re->tbh)) break;
- }
-
- /* swap results */
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- render_result_free(re->result);
- re->result = rres;
- BLI_rw_mutex_unlock(&re->resultmutex);
-
- re->mblur_offs = 0.0f;
- re->i.curblur = 0; /* stats */
-
- /* make sure motion blur changes get reset to current frame */
- if ((re->r.scemode & (R_NO_FRAME_UPDATE|R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))==0) {
- BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, re->lay);
- }
-
- /* weak... the display callback wants an active renderlayer pointer... */
- re->result->renlay = render_get_active_layer(re, re->result);
- re->display_update(re->duh, re->result, NULL);
-}
-
-
-/* function assumes rectf1 and rectf2 to be half size of rectf */
-static void interleave_rect(RenderResult *rr, float *rectf, float *rectf1, float *rectf2, int channels)
-{
- int a, stride = channels * rr->rectx;
- int len = stride * sizeof(float);
-
- for (a = 0; a < rr->recty; a += 2) {
- memcpy(rectf, rectf1, len);
- rectf += stride;
- rectf1 += stride;
- memcpy(rectf, rectf2, len);
- rectf += stride;
- rectf2 += stride;
- }
-}
-
-/* merge render results of 2 fields */
-static void merge_renderresult_fields(RenderResult *rr, RenderResult *rr1, RenderResult *rr2)
-{
- RenderLayer *rl, *rl1, *rl2;
- RenderPass *rpass, *rpass1, *rpass2;
-
- rl1 = rr1->layers.first;
- rl2 = rr2->layers.first;
- for (rl = rr->layers.first; rl && rl1 && rl2; rl = rl->next, rl1 = rl1->next, rl2 = rl2->next) {
-
- /* passes are allocated in sync */
- rpass1 = rl1->passes.first;
- rpass2 = rl2->passes.first;
- for (rpass = rl->passes.first;
- rpass && rpass1 && rpass2;
- rpass = rpass->next, rpass1 = rpass1->next, rpass2 = rpass2->next)
- {
- interleave_rect(rr, rpass->rect, rpass1->rect, rpass2->rect, rpass->channels);
- }
- }
-}
-
-
-/* interleaves 2 frames */
-static void do_render_fields_3d(Render *re)
-{
- Object *camera = RE_GetCamera(re);
- RenderResult *rr1, *rr2 = NULL;
-
- /* no render result was created, we can safely halve render y */
- re->winy /= 2;
- re->recty /= 2;
- re->disprect.ymin /= 2;
- re->disprect.ymax /= 2;
-
- re->i.curfield = 1; /* stats */
-
- /* first field, we have to call camera routine for correct aspect and subpixel offset */
- RE_SetCamera(re, camera);
- if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0)
- do_render_blur_3d(re);
- else
- do_render_3d(re);
-
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- rr1 = re->result;
- re->result = NULL;
- BLI_rw_mutex_unlock(&re->resultmutex);
-
- /* second field */
- if (!re->test_break(re->tbh)) {
-
- re->i.curfield = 2; /* stats */
-
- re->flag |= R_SEC_FIELD;
- if ((re->r.mode & R_FIELDSTILL) == 0) {
- re->field_offs = 0.5f;
- }
- RE_SetCamera(re, camera);
- if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0)
- do_render_blur_3d(re);
- else
- do_render_3d(re);
- re->flag &= ~R_SEC_FIELD;
-
- re->field_offs = 0.0f;
-
- rr2 = re->result;
- }
-
- /* allocate original height new buffers */
- re->winy *= 2;
- re->recty *= 2;
- re->disprect.ymin *= 2;
- re->disprect.ymax *= 2;
-
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- re->result = render_result_new(re, &re->disprect, 0, RR_USE_MEM, RR_ALL_LAYERS, RR_ALL_VIEWS);
-
- if (rr2) {
- if (re->r.mode & R_ODDFIELD)
- merge_renderresult_fields(re->result, rr2, rr1);
- else
- merge_renderresult_fields(re->result, rr1, rr2);
-
- render_result_free(rr2);
- }
-
- render_result_free(rr1);
-
- re->i.curfield = 0; /* stats */
-
- /* weak... the display callback wants an active renderlayer pointer... */
- re->result->renlay = render_get_active_layer(re, re->result);
-
- BLI_rw_mutex_unlock(&re->resultmutex);
-
- re->display_update(re->duh, re->result, NULL);
+ RE_engine_render(re, 0);
}
/* make sure disprect is not affected by the render border */
@@ -1927,7 +1109,7 @@ static void render_result_uncrop(Render *re)
}
/* main render routine, no compositing */
-static void do_render_fields_blur_3d(Render *re)
+static void do_render(Render *re)
{
Object *camera = RE_GetCamera(re);
/* also check for camera here */
@@ -1940,12 +1122,7 @@ static void do_render_fields_blur_3d(Render *re)
/* now use renderdata and camera to set viewplane */
RE_SetCamera(re, camera);
- if (re->r.mode & R_FIELDS)
- do_render_fields_3d(re);
- else if (re->r.mode & R_MBLUR && (re->r.scemode & R_FULL_SAMPLE) == 0)
- do_render_blur_3d(re);
- else
- do_render_3d(re);
+ do_render_3d(re);
/* when border render, check if we have to insert it in black */
render_result_uncrop(re);
@@ -1971,7 +1148,7 @@ static void render_scene(Render *re, Scene *sce, int cfra)
}
/* initial setup */
- RE_InitState(resc, re, &sce->r, NULL, winx, winy, &re->disprect);
+ RE_InitState(resc, re, &sce->r, &sce->view_layers, NULL, winx, winy, &re->disprect);
/* We still want to use 'rendercache' setting from org (main) scene... */
resc->r.scemode = (resc->r.scemode & ~R_EXR_CACHE_FILE) | (re->r.scemode & R_EXR_CACHE_FILE);
@@ -1980,7 +1157,6 @@ static void render_scene(Render *re, Scene *sce, int cfra)
resc->main = re->main;
resc->scene = sce;
resc->lay = sce->lay;
- resc->scene_color_manage = BKE_scene_check_color_management_enabled(sce);
/* ensure scene has depsgraph, base flags etc OK */
BKE_scene_set_background(re->main, sce);
@@ -1995,7 +1171,7 @@ static void render_scene(Render *re, Scene *sce, int cfra)
resc->current_scene_update = re->current_scene_update;
resc->suh = re->suh;
- do_render_fields_blur_3d(resc);
+ do_render(resc);
}
/* helper call to detect if this scene needs a render, or if there's a any render layer to render */
@@ -2081,7 +1257,7 @@ static void tag_dependend_object_for_render(Scene *scene, Object *object)
VirtualModifierData virtualModifierData;
if (object->particlesystem.first) {
- DAG_id_tag_update(&object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&object->id, OB_RECALC_DATA);
}
for (md = modifiers_getVirtualModifierList(object, &virtualModifierData);
@@ -2095,22 +1271,22 @@ static void tag_dependend_object_for_render(Scene *scene, Object *object)
if (md->type == eModifierType_Boolean) {
BooleanModifierData *bmd = (BooleanModifierData *)md;
if (bmd->object && bmd->object->type == OB_MESH) {
- DAG_id_tag_update(&bmd->object->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&bmd->object->id, OB_RECALC_DATA);
}
}
else if (md->type == eModifierType_Array) {
ArrayModifierData *amd = (ArrayModifierData *)md;
if (amd->start_cap && amd->start_cap->type == OB_MESH) {
- DAG_id_tag_update(&amd->start_cap->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&amd->start_cap->id, OB_RECALC_DATA);
}
if (amd->end_cap && amd->end_cap->type == OB_MESH) {
- DAG_id_tag_update(&amd->end_cap->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&amd->end_cap->id, OB_RECALC_DATA);
}
}
else if (md->type == eModifierType_Shrinkwrap) {
ShrinkwrapModifierData *smd = (ShrinkwrapModifierData *)md;
if (smd->target && smd->target->type == OB_MESH) {
- DAG_id_tag_update(&smd->target->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&smd->target->id, OB_RECALC_DATA);
}
}
else if (md->type == eModifierType_ParticleSystem) {
@@ -2120,7 +1296,7 @@ static void tag_dependend_object_for_render(Scene *scene, Object *object)
switch (part->ren_as) {
case PART_DRAW_OB:
if (part->dup_ob != NULL) {
- DAG_id_tag_update(&part->dup_ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&part->dup_ob->id, OB_RECALC_DATA);
}
break;
case PART_DRAW_GR:
@@ -2129,7 +1305,7 @@ static void tag_dependend_object_for_render(Scene *scene, Object *object)
go != NULL;
go = go->next)
{
- DAG_id_tag_update(&go->ob->id, OB_RECALC_DATA);
+ DEG_id_tag_update(&go->ob->id, OB_RECALC_DATA);
}
}
break;
@@ -2143,18 +1319,14 @@ static void tag_dependend_object_for_render(Scene *scene, Object *object)
}
}
-static void tag_dependend_objects_for_render(Main *bmain, Scene *scene, int renderlay)
+static void tag_dependend_objects_for_render(Main *bmain, Scene *scene)
{
- Scene *sce_iter;
- Base *base;
BKE_main_id_tag_idcode(bmain, ID_GR, LIB_TAG_DOIT, false);
- for (SETLOOPER(scene, sce_iter, base)) {
- Object *object = base->object;
- if ((base->lay & renderlay) == 0) {
- continue;
- }
+ FOREACH_OBJECT_RENDERABLE_BEGIN(scene, object)
+ {
tag_dependend_object_for_render(scene, object);
}
+ FOREACH_OBJECT_RENDERABLE_END;
}
#endif
@@ -2162,14 +1334,11 @@ static void tag_scenes_for_render(Render *re)
{
bNode *node;
Scene *sce;
-#ifdef DEPSGRAPH_WORKAROUND_HACK
- int renderlay = re->lay;
-#endif
for (sce = re->main->scene.first; sce; sce = sce->id.next) {
sce->id.tag &= ~LIB_TAG_DOIT;
#ifdef DEPSGRAPH_WORKAROUND_HACK
- tag_dependend_objects_for_render(re->main, sce, renderlay);
+ tag_dependend_objects_for_render(re->main, sce);
#endif
}
@@ -2178,7 +1347,7 @@ static void tag_scenes_for_render(Render *re)
for (sce = re->freestyle_bmain->scene.first; sce; sce = sce->id.next) {
sce->id.tag &= ~LIB_TAG_DOIT;
#ifdef DEPSGRAPH_WORKAROUND_HACK
- tag_dependend_objects_for_render(re->freestyle_bmain, sce, renderlay);
+ tag_dependend_objects_for_render(re->freestyle_bmain, sce);
#endif
}
}
@@ -2187,7 +1356,7 @@ static void tag_scenes_for_render(Render *re)
if (RE_GetCamera(re) && composite_needs_render(re->scene, 1)) {
re->scene->id.tag |= LIB_TAG_DOIT;
#ifdef DEPSGRAPH_WORKAROUND_HACK
- tag_dependend_objects_for_render(re->main, re->scene, renderlay);
+ tag_dependend_objects_for_render(re->main, re->scene);
#endif
}
@@ -2216,11 +1385,11 @@ static void tag_scenes_for_render(Render *re)
if (node->id != (ID *)re->scene) {
if ((node->id->tag & LIB_TAG_DOIT) == 0) {
Scene *scene = (Scene *) node->id;
- if (render_scene_has_layers_to_render(scene)) {
+ if (render_scene_has_layers_to_render(scene, NULL)) {
node->flag |= NODE_TEST;
node->id->tag |= LIB_TAG_DOIT;
#ifdef DEPSGRAPH_WORKAROUND_HACK
- tag_dependend_objects_for_render(re->main, scene, renderlay);
+ tag_dependend_objects_for_render(re->main, scene);
#endif
}
}
@@ -2241,6 +1410,10 @@ static void ntree_render_scenes(Render *re)
if (re->scene->nodetree == NULL) return;
tag_scenes_for_render(re);
+
+#ifdef DEPSGRAPH_WORKAROUND_GROUP_HACK
+ tag_groups_for_render(re);
+#endif
/* now foreach render-result node tagged we do a full render */
/* results are stored in a way compisitor will find it */
@@ -2266,12 +1439,14 @@ static void ntree_render_scenes(Render *re)
}
/* bad call... need to think over proper method still */
-static void render_composit_stats(void *UNUSED(arg), const char *str)
+static void render_composit_stats(void *arg, const char *str)
{
+ Render *re = (Render*)arg;
+
RenderStats i;
- memcpy(&i, &R.i, sizeof(i));
+ memcpy(&i, &re->i, sizeof(i));
i.infostr = str;
- R.stats_draw(R.sdh, &i);
+ re->stats_draw(re->sdh, &i);
}
#ifdef WITH_FREESTYLE
@@ -2295,66 +1470,27 @@ static void init_freestyle(Render *re)
/* invokes Freestyle stroke rendering */
static void add_freestyle(Render *re, int render)
{
- SceneRenderLayer *srl, *actsrl;
+ ViewLayer *view_layer, *active_view_layer;
LinkData *link;
Render *r;
- const bool do_link = (re->r.mode & R_MBLUR) == 0 || re->i.curblur == re->r.mblur_samples;
- actsrl = BLI_findlink(&re->r.layers, re->r.actlay);
+ active_view_layer = BLI_findlink(&re->view_layers, re->active_view_layer);
FRS_begin_stroke_rendering(re);
- for (srl = (SceneRenderLayer *)re->r.layers.first; srl; srl = srl->next) {
- if (do_link) {
- link = (LinkData *)MEM_callocN(sizeof(LinkData), "LinkData to Freestyle render");
- BLI_addtail(&re->freestyle_renders, link);
- }
- if ((re->r.scemode & R_SINGLE_LAYER) && srl != actsrl)
+ for (view_layer = (ViewLayer *)re->view_layers.first; view_layer; view_layer = view_layer->next) {
+ link = (LinkData *)MEM_callocN(sizeof(LinkData), "LinkData to Freestyle render");
+ BLI_addtail(&re->freestyle_renders, link);
+
+ if ((re->r.scemode & R_SINGLE_LAYER) && view_layer != active_view_layer)
continue;
- if (FRS_is_freestyle_enabled(srl)) {
- r = FRS_do_stroke_rendering(re, srl, render);
- if (do_link)
- link->data = (void *)r;
+ if (FRS_is_freestyle_enabled(view_layer)) {
+ r = FRS_do_stroke_rendering(re, view_layer, render);
+ link->data = (void *)r;
}
}
FRS_end_stroke_rendering(re);
-
- /* restore the global R value (invalidated by nested execution of the internal renderer) */
- R = *re;
-}
-
-/* merges the results of Freestyle stroke rendering into a given render result */
-static void composite_freestyle_renders(Render *re, int sample)
-{
- Render *freestyle_render;
- RenderView *rv;
- SceneRenderLayer *srl, *actsrl;
- LinkData *link;
-
- actsrl = BLI_findlink(&re->r.layers, re->r.actlay);
-
- link = (LinkData *)re->freestyle_renders.first;
-
- for (rv = re->result->views.first; rv; rv = rv->next) {
- for (srl = (SceneRenderLayer *)re->r.layers.first; srl; srl = srl->next) {
- if ((re->r.scemode & R_SINGLE_LAYER) && srl != actsrl)
- continue;
-
- if (FRS_is_freestyle_enabled(srl)) {
- freestyle_render = (Render *)link->data;
-
- /* may be NULL in case of empty render layer */
- if (freestyle_render) {
- render_result_exr_file_read_sample(freestyle_render, sample);
- FRS_composite_result(re, srl, freestyle_render);
- RE_FreeRenderResult(freestyle_render->result);
- freestyle_render->result = NULL;
- }
- }
- link = link->next;
- }
- }
}
/* releases temporary scenes and renders for Freestyle stroke rendering */
@@ -2390,229 +1526,8 @@ static void free_all_freestyle_renders(void)
}
#endif
-/* reads all buffers, calls optional composite, merges in first result->views rectf */
-static void do_merge_fullsample(Render *re, bNodeTree *ntree)
-{
- ListBase *rectfs;
- RenderView *rv;
- rcti filter_mask = re->disprect;
- float *rectf, filt[3][3];
- int x, y, sample;
- int nr, numviews;
-
- /* interaction callbacks */
- if (ntree) {
- ntree->stats_draw = render_composit_stats;
- ntree->test_break = re->test_break;
- ntree->progress = re->progress;
- ntree->sdh = re->sdh;
- ntree->tbh = re->tbh;
- ntree->prh = re->prh;
- }
-
- /* filtmask needs it */
- R = *re;
-
- /* temporary storage of the acccumulation buffers */
- rectfs = MEM_callocN(sizeof(ListBase), "fullsample accumulation buffers");
-
- numviews = BLI_listbase_count(&re->result->views);
- for (nr = 0; nr < numviews; nr++) {
- rv = MEM_callocN(sizeof(RenderView), "fullsample renderview");
-
- /* we accumulate in here */
- rv->rectf = MEM_mapallocN(re->result->rectx * re->result->recty * sizeof(float) * 4, "fullsample rgba");
- BLI_addtail(rectfs, rv);
- }
-
- for (sample = 0; sample < re->r.osa; sample++) {
- Scene *sce;
- Render *re1;
- RenderResult rres;
- int mask;
-
- /* enable full sample print */
- R.i.curfsa = sample + 1;
-
- /* set all involved renders on the samplebuffers (first was done by render itself, but needs tagged) */
- /* also function below assumes this */
-
- tag_scenes_for_render(re);
- for (sce = re->main->scene.first; sce; sce = sce->id.next) {
- if (sce->id.tag & LIB_TAG_DOIT) {
- re1 = RE_GetSceneRender(sce);
-
- if (re1 && (re1->r.scemode & R_FULL_SAMPLE)) {
- if (sample) {
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- render_result_exr_file_read_sample(re1, sample);
-#ifdef WITH_FREESTYLE
- if (re1->r.mode & R_EDGE_FRS)
- composite_freestyle_renders(re1, sample);
-#endif
- BLI_rw_mutex_unlock(&re->resultmutex);
- render_result_uncrop(re1);
- }
- ntreeCompositTagRender(re1->scene); /* ensure node gets exec to put buffers on stack */
- }
- }
- }
-
- /* composite */
- if (ntree) {
- ntreeCompositTagRender(re->scene);
- ntreeCompositTagAnimated(ntree);
-
- for (rv = re->result->views.first; rv; rv = rv->next) {
- ntreeCompositExecTree(re->scene, ntree, &re->r, true, G.background == 0, &re->scene->view_settings, &re->scene->display_settings, rv->name);
- }
- }
-
- for (nr = 0, rv = rectfs->first; rv; rv = rv->next, nr++) {
- rectf = rv->rectf;
-
- /* ensure we get either composited result or the active layer */
- RE_AcquireResultImage(re, &rres, nr);
-
- /* accumulate with filter, and clip */
- mask = (1 << sample);
- mask_array(mask, filt);
-
- for (y = 0; y < re->result->recty; y++) {
- float *rf = rectf + 4 * y * re->result->rectx;
- float *col = rres.rectf + 4 * y * re->result->rectx;
-
- for (x = 0; x < re->result->rectx; x++, rf += 4, col += 4) {
- /* clamping to 1.0 is needed for correct AA */
- CLAMP(col[0], 0.0f, 1.0f);
- CLAMP(col[1], 0.0f, 1.0f);
- CLAMP(col[2], 0.0f, 1.0f);
-
- add_filt_fmask_coord(filt, col, rf, re->result->rectx, x, y, &filter_mask);
- }
- }
-
- RE_ReleaseResultImage(re);
-
- /* show stuff */
- if (sample != re->osa - 1) {
- /* weak... the display callback wants an active renderlayer pointer... */
- re->result->renlay = render_get_active_layer(re, re->result);
- RE_SetActiveRenderView(re, rv->name);
- re->display_update(re->duh, re->result, NULL);
- }
- }
- }
-
- for (nr = 0; nr < numviews; nr++) {
- rectf = ((RenderView *)BLI_findlink(rectfs, nr))->rectf;
-
- /* clamp alpha and RGB to 0..1 and 0..inf, can go outside due to filter */
- for (y = 0; y < re->result->recty; y++) {
- float *rf = rectf + 4 * y * re->result->rectx;
-
- for (x = 0; x < re->result->rectx; x++, rf += 4) {
- rf[0] = MAX2(rf[0], 0.0f);
- rf[1] = MAX2(rf[1], 0.0f);
- rf[2] = MAX2(rf[2], 0.0f);
- CLAMP(rf[3], 0.0f, 1.0f);
- }
- }
-
- /* store the final result */
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- rv = RE_RenderViewGetById(re->result, nr);
- if (rv->rectf)
- MEM_freeN(rv->rectf);
- rv->rectf = rectf;
- BLI_rw_mutex_unlock(&re->resultmutex);
- }
-
- /* clear interaction callbacks */
- if (ntree) {
- ntree->stats_draw = NULL;
- ntree->test_break = NULL;
- ntree->progress = NULL;
- ntree->tbh = ntree->sdh = ntree->prh = NULL;
- }
-
- /* disable full sample print */
- R.i.curfsa = 0;
-
- /* garbage collection */
- while (rectfs->first) {
- rv = rectfs->first;
- BLI_remlink(rectfs, rv);
- MEM_freeN(rv);
- }
- MEM_freeN(rectfs);
-}
-
-/* called externally, via compositor */
-void RE_MergeFullSample(Render *re, Main *bmain, Scene *sce, bNodeTree *ntree)
-{
- Scene *scene;
- bNode *node;
-
- /* default start situation */
- G.is_break = false;
-
- re->main = bmain;
- re->scene = sce;
- re->scene_color_manage = BKE_scene_check_color_management_enabled(sce);
-
- /* first call RE_ReadRenderResult on every renderlayer scene. this creates Render structs */
-
- /* tag scenes unread */
- for (scene = re->main->scene.first; scene; scene = scene->id.next)
- scene->id.tag |= LIB_TAG_DOIT;
-
-#ifdef WITH_FREESTYLE
- if (re->freestyle_bmain) {
- for (scene = re->freestyle_bmain->scene.first; scene; scene = scene->id.next)
- scene->id.tag &= ~LIB_TAG_DOIT;
- }
-#endif
-
- for (node = ntree->nodes.first; node; node = node->next) {
- if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) {
- Scene *nodescene = (Scene *)node->id;
-
- if (nodescene == NULL) nodescene = sce;
- if (nodescene->id.tag & LIB_TAG_DOIT) {
- nodescene->r.mode |= R_OSA; /* render struct needs tables */
- RE_ReadRenderResult(sce, nodescene);
- nodescene->id.tag &= ~LIB_TAG_DOIT;
- }
- }
- }
-
- /* own render result should be read/allocated */
- if (re->scene->id.tag & LIB_TAG_DOIT) {
- RE_ReadRenderResult(re->scene, re->scene);
- re->scene->id.tag &= ~LIB_TAG_DOIT;
- }
-
- /* and now we can draw (result is there) */
- re->display_init(re->dih, re->result);
- re->display_clear(re->dch, re->result);
-
-#ifdef WITH_FREESTYLE
- if (re->r.mode & R_EDGE_FRS) {
- init_freestyle(re);
- add_freestyle(re, 0);
- }
-#endif
-
- do_merge_fullsample(re, ntree);
-
-#ifdef WITH_FREESTYLE
- free_all_freestyle_renders();
-#endif
-}
-
/* returns fully composited render-result on given time step (in RenderData) */
-static void do_render_composite_fields_blur_3d(Render *re)
+static void do_render_composite(Render *re)
{
bNodeTree *ntree = re->scene->nodetree;
int update_newframe = 0;
@@ -2628,7 +1543,7 @@ static void do_render_composite_fields_blur_3d(Render *re)
* it could be optimized to render only the needed view
* but what if a scene has a different number of views
* than the main scene? */
- do_render_fields_blur_3d(re);
+ do_render(re);
}
else {
re->i.cfra = re->r.cfra;
@@ -2671,26 +1586,17 @@ static void do_render_composite_fields_blur_3d(Render *re)
ntree->stats_draw = render_composit_stats;
ntree->test_break = re->test_break;
ntree->progress = re->progress;
- ntree->sdh = re->sdh;
+ ntree->sdh = re;
ntree->tbh = re->tbh;
ntree->prh = re->prh;
- /* in case it was never initialized */
- R.sdh = re->sdh;
- R.stats_draw = re->stats_draw;
- R.i.starttime = re->i.starttime;
- R.i.cfra = re->i.cfra;
-
- if (update_newframe)
- BKE_scene_update_for_newframe(re->eval_ctx, re->main, re->scene, re->lay);
+ if (update_newframe) {
+ /* If we have consistent depsgraph now would be a time to update them. */
+ }
- if (re->r.scemode & R_FULL_SAMPLE)
- do_merge_fullsample(re, ntree);
- else {
- RenderView *rv;
- for (rv = re->result->views.first; rv; rv = rv->next) {
- ntreeCompositExecTree(re->scene, ntree, &re->r, true, G.background == 0, &re->scene->view_settings, &re->scene->display_settings, rv->name);
- }
+ RenderView *rv;
+ for (rv = re->result->views.first; rv; rv = rv->next) {
+ ntreeCompositExecTree(re->scene, ntree, &re->r, true, G.background == 0, &re->scene->view_settings, &re->scene->display_settings, rv->name);
}
ntree->stats_draw = NULL;
@@ -2699,14 +1605,17 @@ static void do_render_composite_fields_blur_3d(Render *re)
ntree->tbh = ntree->sdh = ntree->prh = NULL;
}
}
- else if (re->r.scemode & R_FULL_SAMPLE)
- do_merge_fullsample(re, NULL);
}
#ifdef WITH_FREESTYLE
free_all_freestyle_renders();
#endif
+#ifdef DEPSGRAPH_WORKAROUND_GROUP_HACK
+ /* Restore their visibility based on the viewport visibility flags. */
+ tag_groups_for_render(re);
+#endif
+
/* weak... the display callback wants an active renderlayer pointer... */
if (re->result != NULL) {
re->result->renlay = render_get_active_layer(re, re->result);
@@ -2789,8 +1698,8 @@ static void do_render_seq(Render *re)
ibuf_arr = MEM_mallocN(sizeof(ImBuf *) * tot_views, "Sequencer Views ImBufs");
BKE_sequencer_new_render_data(
- re->eval_ctx, re->main, re->scene,
- re_x, re_y, 100,
+ re->main, re->scene,
+ re_x, re_y, 100, true,
&context);
/* the renderresult gets destroyed during the rendering, so we first collect all ibufs
@@ -2866,7 +1775,7 @@ static void do_render_seq(Render *re)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* main loop: doing sequence + fields + blur + 3d render + compositing */
+/* main loop: doing sequence + 3d render + compositing */
static void do_render_all_options(Render *re)
{
Object *camera;
@@ -2896,12 +1805,7 @@ static void do_render_all_options(Render *re)
re->display_update(re->duh, re->result, NULL);
}
else {
- re->pool = BKE_image_pool_new();
-
- do_render_composite_fields_blur_3d(re);
-
- BKE_image_pool_free(re->pool);
- re->pool = NULL;
+ do_render_composite(re);
}
re->i.lastframetime = PIL_check_seconds_timer() - re->i.starttime;
@@ -2923,20 +1827,6 @@ static void do_render_all_options(Render *re)
}
}
-bool RE_force_single_renderlayer(Scene *scene)
-{
- int scemode = check_mode_full_sample(&scene->r);
- if (scemode & R_SINGLE_LAYER) {
- SceneRenderLayer *srl = BLI_findlink(&scene->r.layers, scene->r.actlay);
- /* force layer to be enabled */
- if (srl->layflag & SCE_LAY_DISABLE) {
- srl->layflag &= ~SCE_LAY_DISABLE;
- return true;
- }
- }
- return false;
-}
-
static bool check_valid_compositing_camera(Scene *scene, Object *camera_override)
{
if (scene->r.scemode & R_DOCOMP && scene->use_nodes) {
@@ -2946,7 +1836,7 @@ static bool check_valid_compositing_camera(Scene *scene, Object *camera_override
if (node->type == CMP_NODE_R_LAYERS && (node->flag & NODE_MUTED) == 0) {
Scene *sce = node->id ? (Scene *)node->id : scene;
if (sce->camera == NULL) {
- sce->camera = BKE_scene_camera_find(sce);
+ sce->camera = BKE_view_layer_camera_find(BKE_view_layer_default_render(sce));
}
if (sce->camera == NULL) {
/* all render layers nodes need camera */
@@ -3004,7 +1894,7 @@ static int check_valid_camera(Scene *scene, Object *camera_override, ReportList
const char *err_msg = "No camera found in scene \"%s\"";
if (camera_override == NULL && scene->camera == NULL)
- scene->camera = BKE_scene_camera_find(scene);
+ scene->camera = BKE_view_layer_camera_find(BKE_view_layer_default_render(scene));
if (!check_valid_camera_multiview(scene, scene->camera, reports))
return false;
@@ -3019,7 +1909,9 @@ static int check_valid_camera(Scene *scene, Object *camera_override, ReportList
(seq->scene != NULL))
{
if (!seq->scene_camera) {
- if (!seq->scene->camera && !BKE_scene_camera_find(seq->scene)) {
+ if (!seq->scene->camera &&
+ !BKE_view_layer_camera_find(BKE_view_layer_default_render(seq->scene)))
+ {
/* camera could be unneeded due to composite nodes */
Object *override = (seq->scene == scene) ? camera_override : NULL;
@@ -3070,7 +1962,7 @@ static int check_composite_output(Scene *scene)
return node_tree_has_composite_output(scene->nodetree);
}
-bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *reports)
+bool RE_is_rendering_allowed(Scene *scene, ViewLayer *single_layer, Object *camera_override, ReportList *reports)
{
int scemode = check_mode_full_sample(&scene->r);
@@ -3092,13 +1984,6 @@ bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *
BKE_report(reports, RPT_ERROR, "Cannot save render buffers, check the temp default path");
return 0;
}
-
- /* no fullsample and edge */
- if ((scemode & R_FULL_SAMPLE) && (scene->r.mode & R_EDGE)) {
- BKE_report(reports, RPT_ERROR, "Full sample does not support edge enhance");
- return 0;
- }
-
}
if (scemode & R_DOCOMP) {
@@ -3145,15 +2030,6 @@ bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *
#endif
}
-#ifdef WITH_FREESTYLE
- if (scene->r.mode & R_EDGE_FRS) {
- if (scene->r.mode & R_FIELDS) {
- BKE_report(reports, RPT_ERROR, "Fields not supported in Freestyle");
- return false;
- }
- }
-#endif
-
if (RE_seq_render_active(scene, &scene->r)) {
if (scene->r.mode & R_BORDER) {
BKE_report(reports, RPT_ERROR, "Border rendering is not supported by sequencer");
@@ -3162,7 +2038,7 @@ bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *
}
/* layer flag tests */
- if (!render_scene_has_layers_to_render(scene)) {
+ if (!render_scene_has_layers_to_render(scene, single_layer)) {
BKE_report(reports, RPT_ERROR, "All render layers are disabled");
return 0;
}
@@ -3172,26 +2048,21 @@ bool RE_is_rendering_allowed(Scene *scene, Object *camera_override, ReportList *
static void validate_render_settings(Render *re)
{
- if (re->r.scemode & (R_EXR_TILE_FILE | R_FULL_SAMPLE)) {
- /* no osa + fullsample won't work... */
- if (re->r.osa == 0)
- re->r.scemode &= ~R_FULL_SAMPLE;
- }
-
if (RE_engine_is_external(re)) {
/* not supported yet */
re->r.scemode &= ~(R_FULL_SAMPLE);
- re->r.mode &= ~(R_FIELDS | R_MBLUR);
}
}
-static void update_physics_cache(Render *re, Scene *scene, int UNUSED(anim_init))
+static void update_physics_cache(Render *re, Scene *scene, ViewLayer *view_layer, int UNUSED(anim_init))
{
PTCacheBaker baker;
memset(&baker, 0, sizeof(baker));
baker.main = re->main;
baker.scene = scene;
+ baker.view_layer = view_layer;
+ baker.depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
baker.bake = 0;
baker.render = 1;
baker.anim_init = 1;
@@ -3211,8 +2082,9 @@ const char *RE_GetActiveRenderView(Render *re)
}
/* evaluating scene options for general Blender render */
-static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, Scene *scene, SceneRenderLayer *srl,
- Object *camera_override, unsigned int lay_override, int anim, int anim_init)
+static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain, Scene *scene,
+ ViewLayer *single_layer, Object *camera_override, unsigned int lay_override,
+ int anim, int anim_init)
{
int winx, winy;
rcti disprect;
@@ -3240,7 +2112,6 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain,
re->main = bmain;
re->scene = scene;
- re->scene_color_manage = BKE_scene_check_color_management_enabled(scene);
re->camera_override = camera_override;
re->lay = lay_override ? lay_override : scene->lay;
re->layer_override = lay_override;
@@ -3249,7 +2120,7 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain,
/* not too nice, but it survives anim-border render */
if (anim) {
- render_update_anim_renderdata(re, &scene->r);
+ render_update_anim_renderdata(re, &scene->r, &scene->view_layers);
re->disprect = disprect;
return 1;
}
@@ -3257,6 +2128,11 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain,
/* check all scenes involved */
tag_scenes_for_render(re);
+#ifdef DEPSGRAPH_WORKAROUND_GROUP_HACK
+ /* Update group collections visibility. */
+ tag_groups_for_render(re);
+#endif
+
/*
* Disabled completely for now,
* can be later set as render profile option
@@ -3264,16 +2140,17 @@ static int render_initialize_from_main(Render *re, RenderData *rd, Main *bmain,
*/
if (0) {
/* make sure dynamics are up to date */
- update_physics_cache(re, scene, anim_init);
+ ViewLayer *view_layer = BKE_view_layer_context_active_PLACEHOLDER(scene);
+ update_physics_cache(re, scene, view_layer, anim_init);
}
- if (srl || scene->r.scemode & R_SINGLE_LAYER) {
+ if (single_layer || scene->r.scemode & R_SINGLE_LAYER) {
BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
render_result_single_layer_begin(re);
BLI_rw_mutex_unlock(&re->resultmutex);
}
- RE_InitState(re, NULL, &scene->r, srl, winx, winy, &disprect);
+ RE_InitState(re, NULL, &scene->r, &scene->view_layers, single_layer, winx, winy, &disprect);
if (!re->ok) /* if an error was printed, abort */
return 0;
@@ -3294,7 +2171,7 @@ void RE_SetReports(Render *re, ReportList *reports)
}
/* general Blender frame render call */
-void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *srl, Object *camera_override,
+void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, ViewLayer *single_layer, Object *camera_override,
unsigned int lay_override, int frame, const bool write_still)
{
BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_INIT);
@@ -3304,7 +2181,9 @@ void RE_BlenderFrame(Render *re, Main *bmain, Scene *scene, SceneRenderLayer *sr
scene->r.cfra = frame;
- if (render_initialize_from_main(re, &scene->r, bmain, scene, srl, camera_override, lay_override, 0, 0)) {
+ if (render_initialize_from_main(re, &scene->r, bmain, scene, single_layer,
+ camera_override, lay_override, 0, 0))
+ {
MEM_reset_peak_memory();
BLI_callback_exec(re->main, (ID *)scene, BLI_CB_EVT_RENDER_PRE);
@@ -3345,7 +2224,7 @@ void RE_RenderFreestyleStrokes(Render *re, Main *bmain, Scene *scene, int render
re->result_ok= 0;
if (render_initialize_from_main(re, &scene->r, bmain, scene, NULL, NULL, scene->lay, 0, 0)) {
if (render)
- do_render_fields_blur_3d(re);
+ do_render_3d(re);
}
re->result_ok = 1;
}
@@ -3359,10 +2238,29 @@ void RE_RenderFreestyleExternal(Render *re)
for (rv = re->result->views.first; rv; rv = rv->next) {
RE_SetActiveRenderView(re, rv->name);
- RE_Database_FromScene(re, re->main, re->scene, re->lay, 1);
- RE_Database_Preprocess(re);
+
+ /* scene needs to be set to get camera */
+ Object *camera = RE_GetCamera(re);
+
+ /* if no camera, viewmat should have been set! */
+ if (camera) {
+ /* called before but need to call again in case of lens animation from the
+ * above call to BKE_scene_graph_update_for_newframe, fixes bug. [#22702].
+ * following calls don't depend on 'RE_SetCamera' */
+ float mat[4][4];
+
+ RE_SetCamera(re, camera);
+ RE_GetCameraModelMatrix(re, camera, mat);
+ invert_m4(mat);
+ RE_SetView(re, mat);
+
+ /* force correct matrix for scaled cameras */
+ DEG_id_tag_update_ex(re->main, &camera->id, OB_RECALC_OB);
+ }
+
+ printf("add freestyle\n");
+
add_freestyle(re, 1);
- RE_Database_Free(re);
}
}
}
@@ -3729,22 +2627,11 @@ void RE_BlenderAnim(Render *re, Main *bmain, Scene *scene, Object *camera_overri
}
/* only border now, todo: camera lens. (ton) */
- render_initialize_from_main(re, &rd, bmain, scene, NULL, camera_override, lay_override, 1, 0);
+ render_initialize_from_main(re, &rd, bmain, scene,
+ NULL, camera_override, lay_override, 1, 0);
if (nfra != scene->r.cfra) {
- /*
- * Skip this frame, but update for physics and particles system.
- * From convertblender.c:
- * in localview, lamps are using normal layers, objects only local bits.
- */
- unsigned int updatelay;
-
- if (re->lay & 0xFF000000)
- updatelay = re->lay & 0xFF000000;
- else
- updatelay = re->lay;
-
- BKE_scene_update_for_newframe(re->eval_ctx, bmain, scene, updatelay);
+ /* Skip this frame, but could update for physics and particles system. */
continue;
}
else
@@ -3898,22 +2785,16 @@ void RE_PreviewRender(Render *re, Main *bmain, Scene *sce)
winx = (sce->r.size * sce->r.xsch) / 100;
winy = (sce->r.size * sce->r.ysch) / 100;
- RE_InitState(re, NULL, &sce->r, NULL, winx, winy, NULL);
-
- re->pool = BKE_image_pool_new();
+ RE_InitState(re, NULL, &sce->r, &sce->view_layers, NULL, winx, winy, NULL);
re->main = bmain;
re->scene = sce;
- re->scene_color_manage = BKE_scene_check_color_management_enabled(sce);
re->lay = sce->lay;
camera = RE_GetCamera(re);
RE_SetCamera(re, camera);
do_render_3d(re);
-
- BKE_image_pool_free(re->pool);
- re->pool = NULL;
}
/* note; repeated win/disprect calc... solve that nicer, also in compo */
@@ -3951,9 +2832,8 @@ bool RE_ReadRenderResult(Scene *scene, Scene *scenode)
re = RE_GetSceneRender(scene);
if (re == NULL)
re = RE_NewSceneRender(scene);
- RE_InitState(re, NULL, &scene->r, NULL, winx, winy, &disprect);
+ RE_InitState(re, NULL, &scene->r, &scene->view_layers, NULL, winx, winy, &disprect);
re->scene = scene;
- re->scene_color_manage = BKE_scene_check_color_management_enabled(scene);
BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
success = render_result_exr_file_cache_read(re);
@@ -4030,67 +2910,6 @@ void RE_result_load_from_file(RenderResult *result, ReportList *reports, const c
}
}
-const float default_envmap_layout[] = { 0, 0, 1, 0, 2, 0, 0, 1, 1, 1, 2, 1 };
-
-bool RE_WriteEnvmapResult(struct ReportList *reports, Scene *scene, EnvMap *env, const char *relpath, const char imtype, float layout[12])
-{
- ImageFormatData imf;
- ImBuf *ibuf = NULL;
- int ok;
- int dx;
- int maxX = 0, maxY = 0, i = 0;
- char filepath[FILE_MAX];
-
- if (env->cube[1] == NULL) {
- BKE_report(reports, RPT_ERROR, "There is no generated environment map available to save");
- return 0;
- }
-
- imf = scene->r.im_format;
- imf.imtype = imtype;
-
- dx = env->cube[1]->x;
-
- if (env->type == ENV_CUBE) {
- for (i = 0; i < 12; i += 2) {
- maxX = max_ii(maxX, (int)layout[i] + 1);
- maxY = max_ii(maxY, (int)layout[i + 1] + 1);
- }
-
- ibuf = IMB_allocImBuf(maxX * dx, maxY * dx, 24, IB_rectfloat);
-
- for (i = 0; i < 12; i += 2)
- if (layout[i] > -1 && layout[i + 1] > -1)
- IMB_rectcpy(ibuf, env->cube[i / 2], layout[i] * dx, layout[i + 1] * dx, 0, 0, dx, dx);
- }
- else if (env->type == ENV_PLANE) {
- ibuf = IMB_allocImBuf(dx, dx, 24, IB_rectfloat);
- IMB_rectcpy(ibuf, env->cube[1], 0, 0, 0, 0, dx, dx);
- }
- else {
- BKE_report(reports, RPT_ERROR, "Invalid environment map type");
- return 0;
- }
-
- IMB_colormanagement_imbuf_for_write(ibuf, true, false, &scene->view_settings, &scene->display_settings, &imf);
-
- /* to save, we first get absolute path */
- BLI_strncpy(filepath, relpath, sizeof(filepath));
- BLI_path_abs(filepath, G.main->name);
-
- ok = BKE_imbuf_write(ibuf, filepath, &imf);
-
- IMB_freeImBuf(ibuf);
-
- if (ok) {
- return true;
- }
- else {
- BKE_report(reports, RPT_ERROR, "Error writing environment map");
- return false;
- }
-}
-
/* Used in the interface to decide whether to show layers or passes. */
bool RE_layers_have_name(struct RenderResult *rr)
{
@@ -4184,7 +3003,6 @@ RenderPass *RE_create_gp_pass(RenderResult *rr, const char *layername, const cha
rl = MEM_callocN(sizeof(RenderLayer), layername);
BLI_addtail(&rr->layers, rl);
BLI_strncpy(rl->name, layername, sizeof(rl->name));
- rl->lay = 0;
rl->layflag = SCE_LAY_SOLID;
rl->passflag = SCE_PASS_COMBINED;
rl->rectx = rr->rectx;
diff --git a/source/blender/render/intern/source/pixelblending.c b/source/blender/render/intern/source/pixelblending.c
deleted file mode 100644
index fc79786e5c7..00000000000
--- a/source/blender/render/intern/source/pixelblending.c
+++ /dev/null
@@ -1,400 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): Full recode, 2004-2006 Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/pixelblending.c
- * \ingroup render
- *
- * Functions to blend pixels with or without alpha, in various formats
- * nzc - June 2000
- */
-
-
-#include <math.h>
-#include <string.h>
-
-/* global includes */
-
-/* own includes */
-#include "render_types.h"
-#include "pixelblending.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-
-/* ------------------------------------------------------------------------- */
-/* Debug/behavior defines */
-/* if defined: alpha blending with floats clips color, as with shorts */
-/* #define RE_FLOAT_COLOR_CLIPPING */
-/* if defined: alpha values are clipped */
-/* For now, we just keep alpha clipping. We run into thresholding and */
-/* blending difficulties otherwise. Be careful here. */
-#define RE_ALPHA_CLIPPING
-
-
-
-/* Threshold for a 'full' pixel: pixels with alpha above this level are */
-/* considered opaque This is the decimal value for 0xFFF0 / 0xFFFF */
-#define RE_FULL_COLOR_FLOAT 0.9998f
-/* Threshold for an 'empty' pixel: pixels with alpha above this level are */
-/* considered completely transparent. This is the decimal value */
-/* for 0x000F / 0xFFFF */
-#define RE_EMPTY_COLOR_FLOAT 0.0002f
-
-
-/* ------------------------------------------------------------------------- */
-
-void addAlphaOverFloat(float dest[4], const float source[4])
-{
- /* d = s + (1-alpha_s)d*/
- float mul;
-
- mul = 1.0f - source[3];
-
- dest[0] = (mul * dest[0]) + source[0];
- dest[1] = (mul * dest[1]) + source[1];
- dest[2] = (mul * dest[2]) + source[2];
- dest[3] = (mul * dest[3]) + source[3];
-
-}
-
-
-/* ------------------------------------------------------------------------- */
-
-void addAlphaUnderFloat(float dest[4], const float source[4])
-{
- float mul;
-
- mul = 1.0f - dest[3];
-
- dest[0] += (mul * source[0]);
- dest[1] += (mul * source[1]);
- dest[2] += (mul * source[2]);
- dest[3] += (mul * source[3]);
-}
-
-
-/* ------------------------------------------------------------------------- */
-void addalphaAddfacFloat(float dest[4], const float source[4], char addfac)
-{
- float m; /* weiging factor of destination */
- float c; /* intermediate color */
-
- /* Addfac is a number between 0 and 1: rescale */
- /* final target is to diminish the influence of dest when addfac rises */
- m = 1.0f - (source[3] * ((255 - addfac) / 255.0f));
-
- /* blend colors*/
- c = (m * dest[0]) + source[0];
-#ifdef RE_FLOAT_COLOR_CLIPPING
- if (c >= RE_FULL_COLOR_FLOAT) dest[0] = RE_FULL_COLOR_FLOAT;
- else
-#endif
- dest[0] = c;
-
- c = (m * dest[1]) + source[1];
-#ifdef RE_FLOAT_COLOR_CLIPPING
- if (c >= RE_FULL_COLOR_FLOAT) dest[1] = RE_FULL_COLOR_FLOAT;
- else
-#endif
- dest[1] = c;
-
- c = (m * dest[2]) + source[2];
-#ifdef RE_FLOAT_COLOR_CLIPPING
- if (c >= RE_FULL_COLOR_FLOAT) dest[2] = RE_FULL_COLOR_FLOAT;
- else
-#endif
- dest[2] = c;
-
- c = (m * dest[3]) + source[3];
-#ifdef RE_ALPHA_CLIPPING
- if (c >= RE_FULL_COLOR_FLOAT) dest[3] = RE_FULL_COLOR_FLOAT;
- else
-#endif
- dest[3] = c;
-
-}
-
-
-/* ------------------------------------------------------------------------- */
-
-/* filtered adding to scanlines */
-void add_filt_fmask(unsigned int mask, const float col[4], float *rowbuf, int row_w)
-{
- /* calc the value of mask */
- float **fmask1 = R.samples->fmask1, **fmask2 = R.samples->fmask2;
- float *rb1, *rb2, *rb3;
- float val, r, g, b, al;
- unsigned int a, maskand, maskshift;
- int j;
-
- r = col[0];
- g = col[1];
- b = col[2];
- al = col[3];
-
- rb2 = rowbuf - 4;
- rb3 = rb2 - 4 * row_w;
- rb1 = rb2 + 4 * row_w;
-
- maskand = (mask & 255);
- maskshift = (mask >> 8);
-
- for (j = 2; j >= 0; j--) {
-
- a = j;
-
- val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
- if (val != 0.0f) {
- rb1[0] += val * r;
- rb1[1] += val * g;
- rb1[2] += val * b;
- rb1[3] += val * al;
- }
- a += 3;
-
- val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
- if (val != 0.0f) {
- rb2[0] += val * r;
- rb2[1] += val * g;
- rb2[2] += val * b;
- rb2[3] += val * al;
- }
- a += 3;
-
- val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
- if (val != 0.0f) {
- rb3[0] += val * r;
- rb3[1] += val * g;
- rb3[2] += val * b;
- rb3[3] += val * al;
- }
-
- rb1 += 4;
- rb2 += 4;
- rb3 += 4;
- }
-}
-
-
-void mask_array(unsigned int mask, float filt[3][3])
-{
- float **fmask1 = R.samples->fmask1, **fmask2 = R.samples->fmask2;
- unsigned int maskand = (mask & 255);
- unsigned int maskshift = (mask >> 8);
- int a, j;
-
- for (j = 2; j >= 0; j--) {
-
- a = j;
-
- filt[2][2 - j] = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
-
- a += 3;
-
- filt[1][2 - j] = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
-
- a += 3;
-
- filt[0][2 - j] = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
- }
-}
-
-
-/**
- * Index ordering, scanline based:
- *
- * <pre>
- * --- --- ---
- * | 2,0 | 2,1 | 2,2 |
- * --- --- ---
- * | 1,0 | 1,1 | 1,2 |
- * --- --- ---
- * | 0,0 | 0,1 | 0,2 |
- * --- --- ---
- * </pre>
- */
-
-void add_filt_fmask_coord(float filt[3][3], const float col[4], float *rowbuf, int row_stride, int x, int y, rcti *mask)
-{
- float *fpoin[3][3];
- float val, r, g, b, al, lfilt[3][3];
-
- r = col[0];
- g = col[1];
- b = col[2];
- al = col[3];
-
- memcpy(lfilt, filt, sizeof(lfilt));
-
- fpoin[0][1] = rowbuf - 4 * row_stride;
- fpoin[1][1] = rowbuf;
- fpoin[2][1] = rowbuf + 4 * row_stride;
-
- fpoin[0][0] = fpoin[0][1] - 4;
- fpoin[1][0] = fpoin[1][1] - 4;
- fpoin[2][0] = fpoin[2][1] - 4;
-
- fpoin[0][2] = fpoin[0][1] + 4;
- fpoin[1][2] = fpoin[1][1] + 4;
- fpoin[2][2] = fpoin[2][1] + 4;
-
- /* limit filtering to withing a mask for border rendering, so pixels don't
- * leak outside of the border */
- if (y <= mask->ymin) {
- fpoin[0][0] = fpoin[1][0];
- fpoin[0][1] = fpoin[1][1];
- fpoin[0][2] = fpoin[1][2];
- /* filter needs the opposite value yes! */
- lfilt[0][0] = filt[2][0];
- lfilt[0][1] = filt[2][1];
- lfilt[0][2] = filt[2][2];
- }
- else if (y >= mask->ymax - 1) {
- fpoin[2][0] = fpoin[1][0];
- fpoin[2][1] = fpoin[1][1];
- fpoin[2][2] = fpoin[1][2];
-
- lfilt[2][0] = filt[0][0];
- lfilt[2][1] = filt[0][1];
- lfilt[2][2] = filt[0][2];
- }
-
- if (x <= mask->xmin) {
- fpoin[2][0] = fpoin[2][1];
- fpoin[1][0] = fpoin[1][1];
- fpoin[0][0] = fpoin[0][1];
-
- lfilt[2][0] = filt[2][2];
- lfilt[1][0] = filt[1][2];
- lfilt[0][0] = filt[0][2];
- }
- else if (x >= mask->xmax - 1) {
- fpoin[2][2] = fpoin[2][1];
- fpoin[1][2] = fpoin[1][1];
- fpoin[0][2] = fpoin[0][1];
-
- lfilt[2][2] = filt[2][0];
- lfilt[1][2] = filt[1][0];
- lfilt[0][2] = filt[0][0];
- }
-
-
- /* loop unroll */
-#define MASKFILT(i, j) \
- val = lfilt[i][j]; \
- if (val != 0.0f) { \
- float *fp = fpoin[i][j]; \
- fp[0] += val * r; \
- fp[1] += val * g; \
- fp[2] += val * b; \
- fp[3] += val * al; \
- } (void)0
-
- MASKFILT(0, 0);
- MASKFILT(0, 1);
- MASKFILT(0, 2);
- MASKFILT(1, 0);
- MASKFILT(1, 1);
- MASKFILT(1, 2);
- MASKFILT(2, 0);
- MASKFILT(2, 1);
- MASKFILT(2, 2);
-
-#undef MASKFILT
-}
-
-void add_filt_fmask_pixsize(unsigned int mask, float *in, float *rowbuf, int row_w, int pixsize)
-{
- /* calc the value of mask */
- float **fmask1 = R.samples->fmask1, **fmask2 = R.samples->fmask2;
- float *rb1, *rb2, *rb3;
- float val;
- unsigned int a, maskand, maskshift;
- int i, j;
-
- rb2 = rowbuf - pixsize;
- rb3 = rb2 - pixsize * row_w;
- rb1 = rb2 + pixsize * row_w;
-
- maskand = (mask & 255);
- maskshift = (mask >> 8);
-
- for (j = 2; j >= 0; j--) {
-
- a = j;
-
- val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
- if (val != 0.0f) {
- for (i = 0; i < pixsize; i++)
- rb1[i] += val * in[i];
- }
- a += 3;
-
- val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
- if (val != 0.0f) {
- for (i = 0; i < pixsize; i++)
- rb2[i] += val * in[i];
- }
- a += 3;
-
- val = *(fmask1[a] + maskand) + *(fmask2[a] + maskshift);
- if (val != 0.0f) {
- for (i = 0; i < pixsize; i++)
- rb3[i] += val * in[i];
- }
-
- rb1 += pixsize;
- rb2 += pixsize;
- rb3 += pixsize;
- }
-}
-
-/* ------------------------------------------------------------------------- */
-void addalphaAddFloat(float dest[4], const float source[4])
-{
-
- /* Makes me wonder whether this is required... */
- if (dest[3] < RE_EMPTY_COLOR_FLOAT) {
- dest[0] = source[0];
- dest[1] = source[1];
- dest[2] = source[2];
- dest[3] = source[3];
- return;
- }
-
- /* no clipping! */
- dest[0] = dest[0] + source[0];
- dest[1] = dest[1] + source[1];
- dest[2] = dest[2] + source[2];
- dest[3] = dest[3] + source[3];
-
-}
-
-
-/* ---------------------------------------------------------------------------- */
diff --git a/source/blender/render/intern/source/pixelshading.c b/source/blender/render/intern/source/pixelshading.c
deleted file mode 100644
index ddbdb35bf51..00000000000
--- a/source/blender/render/intern/source/pixelshading.c
+++ /dev/null
@@ -1,650 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): 2004-2006, Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/pixelshading.c
- * \ingroup render
- */
-
-
-#include <float.h>
-#include <math.h>
-#include <string.h>
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-/* External modules: */
-
-#include "DNA_group_types.h"
-#include "DNA_material_types.h"
-#include "DNA_object_types.h"
-#include "DNA_image_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_lamp_types.h"
-
-#include "BKE_material.h"
-
-
-/* own module */
-#include "render_types.h"
-#include "renderdatabase.h"
-#include "texture.h"
-#include "rendercore.h"
-#include "shadbuf.h"
-#include "pixelshading.h"
-#include "sunsky.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-
-extern const float hashvectf[];
-
-static void render_lighting_halo(HaloRen *har, float col_r[3])
-{
- GroupObject *go;
- LampRen *lar;
- float i, inp, inpr, rco[3], dco[3], lv[3], lampdist, ld, t, *vn;
- float ir, ig, ib, shadfac, soft, lacol[3];
-
- ir= ig= ib= 0.0;
-
- copy_v3_v3(rco, har->co);
- dco[0]=dco[1]=dco[2]= 1.0f/har->rad;
-
- vn= har->no;
-
- for (go=R.lights.first; go; go= go->next) {
- lar= go->lampren;
-
- /* test for lamplayer */
- if (lar->mode & LA_LAYER) if ((lar->lay & har->lay)==0) continue;
-
- /* lampdist cacluation */
- if (lar->type==LA_SUN || lar->type==LA_HEMI) {
- copy_v3_v3(lv, lar->vec);
- lampdist= 1.0;
- }
- else {
- lv[0]= rco[0]-lar->co[0];
- lv[1]= rco[1]-lar->co[1];
- lv[2]= rco[2]-lar->co[2];
- ld = len_v3(lv);
- lv[0]/= ld;
- lv[1]/= ld;
- lv[2]/= ld;
-
- /* ld is re-used further on (texco's) */
-
- if (lar->mode & LA_QUAD) {
- t= 1.0;
- if (lar->ld1>0.0f)
- t= lar->dist/(lar->dist+lar->ld1*ld);
- if (lar->ld2>0.0f)
- t*= lar->distkw/(lar->distkw+lar->ld2*ld*ld);
-
- lampdist= t;
- }
- else {
- lampdist= (lar->dist/(lar->dist+ld));
- }
-
- if (lar->mode & LA_SPHERE) {
- t= lar->dist - ld;
- if (t<0.0f) continue;
-
- t/= lar->dist;
- lampdist*= (t);
- }
-
- }
-
- lacol[0]= lar->r;
- lacol[1]= lar->g;
- lacol[2]= lar->b;
-
- if (lar->mode & LA_TEXTURE) {
- ShadeInput shi;
-
- /* Warning, This is not that nice, and possibly a bit slow,
- * however some variables were not initialized properly in, unless using shade_input_initialize(...),
- * we need to do a memset */
- memset(&shi, 0, sizeof(ShadeInput));
- /* end warning! - Campbell */
-
- copy_v3_v3(shi.co, rco);
- shi.osatex= 0;
- do_lamp_tex(lar, lv, &shi, lacol, LA_TEXTURE);
- }
-
- if (lar->type==LA_SPOT) {
-
- if (lar->mode & LA_SQUARE) {
- if (lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2]>0.0f) {
- float x, lvrot[3];
-
- /* rotate view to lampspace */
- copy_v3_v3(lvrot, lv);
- mul_m3_v3(lar->imat, lvrot);
-
- x = max_ff(fabsf(lvrot[0]/lvrot[2]), fabsf(lvrot[1]/lvrot[2]));
- /* 1.0/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */
-
- inpr = 1.0f / (sqrtf(1.0f + x * x));
- }
- else inpr= 0.0;
- }
- else {
- inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2];
- }
-
- t= lar->spotsi;
- if (inpr<t) continue;
- else {
- t= inpr-t;
- soft= 1.0;
- if (t<lar->spotbl && lar->spotbl!=0.0f) {
- /* soft area */
- i= t/lar->spotbl;
- t= i*i;
- soft= (3.0f*t-2.0f*t*i);
- inpr*= soft;
- }
- if (lar->mode & LA_ONLYSHADOW) {
- /* if (ma->mode & MA_SHADOW) { */
- /* dot product positive: front side face! */
- inp= vn[0]*lv[0] + vn[1]*lv[1] + vn[2]*lv[2];
- if (inp>0.0f) {
- /* testshadowbuf==0.0 : 100% shadow */
- shadfac = testshadowbuf(&R, lar->shb, rco, dco, dco, inp, 0.0f);
- if ( shadfac>0.0f ) {
- shadfac*= inp*soft*lar->energy;
- ir -= shadfac;
- ig -= shadfac;
- ib -= shadfac;
-
- continue;
- }
- }
- /* } */
- }
- lampdist*=inpr;
- }
- if (lar->mode & LA_ONLYSHADOW) continue;
-
- }
-
- /* dot product and reflectivity*/
-
- inp = 1.0f - fabsf(dot_v3v3(vn, lv));
-
- /* inp= cos(0.5*M_PI-acos(inp)); */
-
- i= inp;
-
- if (lar->type==LA_HEMI) {
- i= 0.5f*i+0.5f;
- }
- if (i>0.0f) {
- i*= lampdist;
- }
-
- /* shadow */
- if (i> -0.41f) { /* heuristic valua! */
- if (lar->shb) {
- shadfac = testshadowbuf(&R, lar->shb, rco, dco, dco, inp, 0.0f);
- if (shadfac==0.0f) continue;
- i*= shadfac;
- }
- }
-
- if (i>0.0f) {
- ir+= i*lacol[0];
- ig+= i*lacol[1];
- ib+= i*lacol[2];
- }
- }
-
- if (ir<0.0f) ir= 0.0f;
- if (ig<0.0f) ig= 0.0f;
- if (ib<0.0f) ib= 0.0f;
-
- col_r[0]*= ir;
- col_r[1]*= ig;
- col_r[2]*= ib;
-
-}
-
-
-/**
- * Converts a halo z-buffer value to distance from the camera's near plane
- * \param z The z-buffer value to convert
- * \return a distance from the camera's near plane in blender units
- */
-static float haloZtoDist(int z)
-{
- float zco = 0;
-
- if (z >= 0x7FFFFF)
- return 10e10;
- else {
- zco = (float)z/(float)0x7FFFFF;
- if (R.r.mode & R_ORTHO)
- return (R.winmat[3][2] - zco*R.winmat[3][3])/(R.winmat[2][2]);
- else
- return (R.winmat[3][2])/(R.winmat[2][2] - R.winmat[2][3]*zco);
- }
-}
-
-/**
- * \param col (float[4]) Store the rgb color here (with alpha)
- * The alpha is used to blend the color to the background
- * color_new = (1-alpha)*color_background + color
- * \param zz The current zbuffer value at the place of this pixel
- * \param dist Distance of the pixel from the center of the halo squared. Given in pixels
- * \param xn The x coordinate of the pixel relaticve to the center of the halo. given in pixels
- * \param yn The y coordinate of the pixel relaticve to the center of the halo. given in pixels
- */
-int shadeHaloFloat(HaloRen *har, float col[4], int zz,
- float dist, float xn, float yn, short flarec)
-{
- /* fill in col */
- float t, zn, radist, ringf=0.0f, linef=0.0f, alpha, si, co;
- int a;
-
- if (R.wrld.mode & WO_MIST) {
- if (har->type & HA_ONLYSKY) {
- alpha= har->alfa;
- }
- else {
- /* a bit patchy... */
- alpha= mistfactor(-har->co[2], har->co)*har->alfa;
- }
- }
- else alpha= har->alfa;
-
- if (alpha==0.0f)
- return 0;
-
- /* soften the halo if it intersects geometry */
- if (har->mat && har->mat->mode & MA_HALO_SOFT) {
- float segment_length, halo_depth, distance_from_z /* , visible_depth */ /* UNUSED */, soften;
-
- /* calculate halo depth */
- segment_length= har->hasize*sasqrt(1.0f - dist/(har->rad*har->rad));
- halo_depth= 2.0f*segment_length;
-
- if (halo_depth < FLT_EPSILON)
- return 0;
-
- /* calculate how much of this depth is visible */
- distance_from_z = haloZtoDist(zz) - haloZtoDist(har->zs);
- /* visible_depth = halo_depth; */ /* UNUSED */
- if (distance_from_z < segment_length) {
- soften= (segment_length + distance_from_z)/halo_depth;
-
- /* apply softening to alpha */
- if (soften < 1.0f)
- alpha *= soften;
- if (alpha <= 0.0f)
- return 0;
- }
- }
- else {
- /* not a soft halo. use the old softening code */
- /* halo being intersected? */
- if (har->zs> zz-har->zd) {
- t= ((float)(zz-har->zs))/(float)har->zd;
- alpha*= sqrtf(sqrtf(t));
- }
- }
-
- radist = sqrtf(dist);
-
- /* watch it: not used nicely: flarec is set at zero in pixstruct */
- if (flarec) har->pixels+= (int)(har->rad-radist);
-
- if (har->ringc) {
- const float *rc;
- float fac;
- int ofs;
-
- /* per ring an antialised circle */
- ofs= har->seed;
-
- for (a= har->ringc; a>0; a--, ofs+=2) {
-
- rc= hashvectf + (ofs % 768);
-
- fac = fabsf(rc[1] * (har->rad * fabsf(rc[0]) - radist));
-
- if (fac< 1.0f) {
- ringf+= (1.0f-fac);
- }
- }
- }
-
- if (har->type & HA_VECT) {
- dist= fabsf(har->cos * (yn) - har->sin * (xn)) / har->rad;
- if (dist>1.0f) dist= 1.0f;
- if (har->tex) {
- zn= har->sin*xn - har->cos*yn;
- yn= har->cos*xn + har->sin*yn;
- xn= zn;
- }
- }
- else dist= dist/har->radsq;
-
- if (har->type & HA_FLARECIRC) {
- dist = 0.5f + fabsf(dist - 0.5f);
- }
-
- if (har->hard>=30) {
- dist = sqrtf(dist);
- if (har->hard>=40) {
- dist = sinf(dist*(float)M_PI_2);
- if (har->hard>=50) {
- dist = sqrtf(dist);
- }
- }
- }
- else if (har->hard<20) dist*=dist;
-
- if (dist < 1.0f)
- dist= (1.0f-dist);
- else
- dist= 0.0f;
-
- if (har->linec) {
- const float *rc;
- float fac;
- int ofs;
-
- /* per starpoint an antialiased line */
- ofs= har->seed;
-
- for (a= har->linec; a>0; a--, ofs+=3) {
-
- rc= hashvectf + (ofs % 768);
-
- fac = fabsf((xn) * rc[0] + (yn) * rc[1]);
-
- if (fac< 1.0f )
- linef+= (1.0f-fac);
- }
-
- linef*= dist;
- }
-
- if (har->starpoints) {
- float ster, angle;
- /* rotation */
- angle = atan2f(yn, xn);
- angle *= (1.0f+0.25f*har->starpoints);
-
- co= cosf(angle);
- si= sinf(angle);
-
- angle= (co*xn+si*yn)*(co*yn-si*xn);
-
- ster = fabsf(angle);
- if (ster>1.0f) {
- ster= (har->rad)/(ster);
-
- if (ster<1.0f) dist*= sqrtf(ster);
- }
- }
-
- /* disputable optimize... (ton) */
- if (dist<=0.00001f)
- return 0;
-
- dist*= alpha;
- ringf*= dist;
- linef*= alpha;
-
- /* The color is either the rgb spec-ed by the user, or extracted from */
- /* the texture */
- if (har->tex) {
- col[0]= har->r;
- col[1]= har->g;
- col[2]= har->b;
- col[3]= dist;
-
- do_halo_tex(har, xn, yn, col);
-
- col[0]*= col[3];
- col[1]*= col[3];
- col[2]*= col[3];
-
- }
- else {
- col[0]= dist*har->r;
- col[1]= dist*har->g;
- col[2]= dist*har->b;
- if (har->type & HA_XALPHA) col[3]= dist*dist;
- else col[3]= dist;
- }
-
- if (har->mat) {
- if (har->mat->mode & MA_HALO_SHADE) {
- /* we test for lights because of preview... */
- if (R.lights.first) render_lighting_halo(har, col);
- }
-
- /* Next, we do the line and ring factor modifications. */
- if (linef!=0.0f) {
- Material *ma= har->mat;
-
- col[0]+= linef * ma->specr;
- col[1]+= linef * ma->specg;
- col[2]+= linef * ma->specb;
-
- if (har->type & HA_XALPHA) col[3]+= linef*linef;
- else col[3]+= linef;
- }
- if (ringf!=0.0f) {
- Material *ma= har->mat;
-
- col[0]+= ringf * ma->mirr;
- col[1]+= ringf * ma->mirg;
- col[2]+= ringf * ma->mirb;
-
- if (har->type & HA_XALPHA) col[3]+= ringf*ringf;
- else col[3]+= ringf;
- }
- }
-
- /* alpha requires clip, gives black dots */
- if (col[3] > 1.0f)
- col[3]= 1.0f;
-
- return 1;
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* Only view vector is important here. Result goes to col_r[3] */
-void shadeSkyView(float col_r[3], const float rco[3], const float view[3], const float dxyview[2], short thread)
-{
- float zen[3], hor[3], blend, blendm;
- int skyflag;
-
- /* flag indicating if we render the top hemisphere */
- skyflag = WO_ZENUP;
-
- /* Some view vector stuff. */
- if (R.wrld.skytype & WO_SKYREAL) {
-
- blend = dot_v3v3(view, R.grvec);
-
- if (blend<0.0f) skyflag= 0;
-
- blend = fabsf(blend);
- }
- else if (R.wrld.skytype & WO_SKYPAPER) {
- blend= 0.5f + 0.5f * view[1];
- }
- else {
- /* the fraction of how far we are above the bottom of the screen */
- blend = fabsf(0.5f + view[1]);
- }
-
- copy_v3_v3(hor, &R.wrld.horr);
- copy_v3_v3(zen, &R.wrld.zenr);
-
- /* Careful: SKYTEX and SKYBLEND are NOT mutually exclusive! If */
- /* SKYBLEND is active, the texture and color blend are added. */
- if (R.wrld.skytype & WO_SKYTEX) {
- float lo[3];
- copy_v3_v3(lo, view);
- if (R.wrld.skytype & WO_SKYREAL) {
-
- mul_m3_v3(R.imat, lo);
-
- SWAP(float, lo[1], lo[2]);
-
- }
- do_sky_tex(rco, view, lo, dxyview, hor, zen, &blend, skyflag, thread);
- }
-
- if (blend>1.0f) blend= 1.0f;
- blendm= 1.0f-blend;
-
- /* No clipping, no conversion! */
- if (R.wrld.skytype & WO_SKYBLEND) {
- col_r[0] = (blendm*hor[0] + blend*zen[0]);
- col_r[1] = (blendm*hor[1] + blend*zen[1]);
- col_r[2] = (blendm*hor[2] + blend*zen[2]);
- }
- else {
- /* Done when a texture was grabbed. */
- col_r[0]= hor[0];
- col_r[1]= hor[1];
- col_r[2]= hor[2];
- }
-}
-
-/* shade sky according to sun lamps, all parameters are like shadeSkyView except sunsky*/
-void shadeSunView(float col_r[3], const float view[3])
-{
- GroupObject *go;
- LampRen *lar;
- float sview[3];
- bool do_init = true;
-
- for (go=R.lights.first; go; go= go->next) {
- lar= go->lampren;
- if (lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_SKY)) {
- float sun_collector[3];
- float colorxyz[3];
-
- if (do_init) {
-
- normalize_v3_v3(sview, view);
- mul_m3_v3(R.imat, sview);
- if (sview[2] < 0.0f)
- sview[2] = 0.0f;
- normalize_v3(sview);
- do_init = false;
- }
-
- GetSkyXYZRadiancef(lar->sunsky, sview, colorxyz);
- xyz_to_rgb(colorxyz[0], colorxyz[1], colorxyz[2], &sun_collector[0], &sun_collector[1], &sun_collector[2],
- lar->sunsky->sky_colorspace);
-
- ramp_blend(lar->sunsky->skyblendtype, col_r, lar->sunsky->skyblendfac, sun_collector);
- }
- }
-}
-
-
-/*
- * Stuff the sky color into the collector.
- */
-void shadeSkyPixel(float collector[4], float fx, float fy, short thread)
-{
- float view[3], dxyview[2];
-
- /*
- * The rules for sky:
- * 1. Draw an image, if a background image was provided. Stop
- * 2. get texture and color blend, and combine these.
- */
-
- float fac;
-
- if ((R.wrld.skytype & (WO_SKYBLEND+WO_SKYTEX))==0) {
- /* 1. solid color */
- copy_v3_v3(collector, &R.wrld.horr);
-
- collector[3] = 0.0f;
- }
- else {
- /* 2. */
-
- /* This one true because of the context of this routine */
- if (R.wrld.skytype & WO_SKYPAPER) {
- view[0]= -1.0f + 2.0f*(fx/(float)R.winx);
- view[1]= -1.0f + 2.0f*(fy/(float)R.winy);
- view[2]= 0.0;
-
- dxyview[0]= 1.0f/(float)R.winx;
- dxyview[1]= 1.0f/(float)R.winy;
- }
- else {
- calc_view_vector(view, fx, fy);
- fac= normalize_v3(view);
-
- if (R.wrld.skytype & WO_SKYTEX) {
- dxyview[0]= -R.viewdx/fac;
- dxyview[1]= -R.viewdy/fac;
- }
- }
-
- /* get sky color in the collector */
- shadeSkyView(collector, NULL, view, dxyview, thread);
- collector[3] = 0.0f;
- }
-
- calc_view_vector(view, fx, fy);
- shadeSunView(collector, view);
-}
-
-/* aerial perspective */
-void shadeAtmPixel(struct SunSky *sunsky, float collector[3], float fx, float fy, float distance)
-{
- float view[3];
-
- calc_view_vector(view, fx, fy);
- normalize_v3(view);
- /*mul_m3_v3(R.imat, view);*/
- AtmospherePixleShader(sunsky, view, distance, collector);
-}
-
-/* eof */
diff --git a/source/blender/render/intern/source/pointdensity.c b/source/blender/render/intern/source/pointdensity.c
index b75d996ff27..a6350e3c448 100644
--- a/source/blender/render/intern/source/pointdensity.c
+++ b/source/blender/render/intern/source/pointdensity.c
@@ -58,17 +58,14 @@
#include "BKE_scene.h"
#include "BKE_colortools.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_query.h"
+
#include "render_types.h"
#include "texture.h"
-#include "pointdensity.h"
#include "RE_render_ext.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+#include "RE_shader_ext.h"
static ThreadMutex sample_mutex = PTHREAD_MUTEX_INITIALIZER;
@@ -77,15 +74,13 @@ static int point_data_used(PointDensity *pd)
int pd_bitflag = 0;
if (pd->source == TEX_PD_PSYS) {
- if ((pd->noise_influence == TEX_PD_NOISE_VEL) ||
- (pd->falloff_type == TEX_PD_FALLOFF_PARTICLE_VEL) ||
+ if ((pd->falloff_type == TEX_PD_FALLOFF_PARTICLE_VEL) ||
(pd->color_source == TEX_PD_COLOR_PARTVEL) ||
(pd->color_source == TEX_PD_COLOR_PARTSPEED))
{
pd_bitflag |= POINT_DATA_VEL;
}
- if ((pd->noise_influence == TEX_PD_NOISE_AGE) ||
- (pd->color_source == TEX_PD_COLOR_PARTAGE) ||
+ if ((pd->color_source == TEX_PD_COLOR_PARTAGE) ||
(pd->falloff_type == TEX_PD_FALLOFF_PARTICLE_AGE))
{
pd_bitflag |= POINT_DATA_LIFE;
@@ -167,13 +162,10 @@ static void alloc_point_data(PointDensity *pd)
}
}
-static void pointdensity_cache_psys(Scene *scene,
+static void pointdensity_cache_psys(Depsgraph *depsgraph, Scene *scene,
PointDensity *pd,
Object *ob,
ParticleSystem *psys,
- float viewmat[4][4],
- float winmat[4][4],
- int winx, int winy,
const bool use_render_params)
{
DerivedMesh *dm;
@@ -195,27 +187,22 @@ static void pointdensity_cache_psys(Scene *scene,
data_used = point_data_used(pd);
- /* Just to create a valid rendering context for particles */
- if (use_render_params) {
- psys_render_set(ob, psys, viewmat, winmat, winx, winy, 0);
- }
-
if (use_render_params) {
- dm = mesh_create_derived_render(scene,
+ dm = mesh_create_derived_render(depsgraph, scene,
ob,
CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL);
}
else {
- dm = mesh_get_derived_final(scene,
+ dm = mesh_get_derived_final(depsgraph, scene,
ob,
CD_MASK_BAREMESH | CD_MASK_MTFACE | CD_MASK_MCOL);
}
if (!psys_check_enabled(ob, psys, use_render_params)) {
- psys_render_restore(ob, psys);
return;
}
+ sim.depsgraph = depsgraph;
sim.scene = scene;
sim.ob = ob;
sim.psys = psys;
@@ -304,10 +291,6 @@ static void pointdensity_cache_psys(Scene *scene,
end_latt_deform(psys->lattice_deform_data);
psys->lattice_deform_data = NULL;
}
-
- if (use_render_params) {
- psys_render_restore(ob, psys);
- }
}
@@ -400,7 +383,7 @@ static void pointdensity_cache_vertex_normal(PointDensity *pd, Object *UNUSED(ob
}
}
-static void pointdensity_cache_object(Scene *scene,
+static void pointdensity_cache_object(Depsgraph *depsgraph, Scene *scene,
PointDensity *pd,
Object *ob,
const bool use_render_params)
@@ -421,10 +404,10 @@ static void pointdensity_cache_object(Scene *scene,
}
if (use_render_params) {
- dm = mesh_create_derived_render(scene, ob, mask);
+ dm = mesh_create_derived_render(depsgraph, scene, ob, mask);
}
else {
- dm = mesh_get_derived_final(scene, ob, mask);
+ dm = mesh_get_derived_final(depsgraph, scene, ob, mask);
}
mvert = dm->getVertArray(dm); /* local object space */
@@ -475,12 +458,10 @@ static void pointdensity_cache_object(Scene *scene,
}
-static void cache_pointdensity_ex(Scene *scene,
- PointDensity *pd,
- float viewmat[4][4],
- float winmat[4][4],
- int winx, int winy,
- const bool use_render_params)
+static void cache_pointdensity(Depsgraph *depsgraph,
+ Scene *scene,
+ PointDensity *pd,
+ const bool use_render_params)
{
if (pd == NULL) {
return;
@@ -504,31 +485,21 @@ static void cache_pointdensity_ex(Scene *scene,
return;
}
- pointdensity_cache_psys(scene,
+ pointdensity_cache_psys(depsgraph,
+ scene,
pd,
ob,
psys,
- viewmat, winmat,
- winx, winy,
use_render_params);
}
else if (pd->source == TEX_PD_OBJECT) {
Object *ob = pd->object;
if (ob && ob->type == OB_MESH)
- pointdensity_cache_object(scene, pd, ob, use_render_params);
+ pointdensity_cache_object(depsgraph, scene, pd, ob, use_render_params);
}
}
-void cache_pointdensity(Render *re, PointDensity *pd)
-{
- cache_pointdensity_ex(re->scene,
- pd,
- re->viewmat, re->winmat,
- re->winx, re->winy,
- true);
-}
-
-void free_pointdensity(PointDensity *pd)
+static void free_pointdensity(PointDensity *pd)
{
if (pd == NULL) {
return;
@@ -546,41 +517,6 @@ void free_pointdensity(PointDensity *pd)
pd->totpoints = 0;
}
-void make_pointdensities(Render *re)
-{
- Tex *tex;
-
- if (re->scene->r.scemode & R_BUTS_PREVIEW) {
- return;
- }
-
- re->i.infostr = IFACE_("Caching Point Densities");
- re->stats_draw(re->sdh, &re->i);
-
- for (tex = re->main->tex.first; tex != NULL; tex = tex->id.next) {
- if (tex->id.us && tex->type == TEX_POINTDENSITY) {
- cache_pointdensity(re, tex->pd);
- }
- }
-
- re->i.infostr = NULL;
- re->stats_draw(re->sdh, &re->i);
-}
-
-void free_pointdensities(Render *re)
-{
- Tex *tex;
-
- if (re->scene->r.scemode & R_BUTS_PREVIEW)
- return;
-
- for (tex = re->main->tex.first; tex != NULL; tex = tex->id.next) {
- if (tex->id.us && tex->type == TEX_POINTDENSITY) {
- free_pointdensity(tex->pd);
- }
- }
-}
-
typedef struct PointDensityRangeData {
float *density;
float squared_radius;
@@ -691,7 +627,7 @@ static int pointdensity(PointDensity *pd,
{
int retval = TEX_INT;
PointDensityRangeData pdr;
- float density = 0.0f, age = 0.0f, time = 0.0f;
+ float density = 0.0f, age = 0.0f;
float vec[3] = {0.0f, 0.0f, 0.0f}, col[3] = {0.0f, 0.0f, 0.0f}, co[3];
float turb, noise_fac;
int num = 0;
@@ -725,21 +661,8 @@ static int pointdensity(PointDensity *pd,
}
if (pd->flag & TEX_PD_TURBULENCE) {
-
- if (pd->noise_influence == TEX_PD_NOISE_AGE) {
- turb = BLI_gTurbulence(pd->noise_size, texvec[0] + age, texvec[1] + age, texvec[2] + age,
- pd->noise_depth, 0, pd->noise_basis);
- }
- else if (pd->noise_influence == TEX_PD_NOISE_TIME) {
- time = R.r.cfra / (float)R.r.efra;
- turb = BLI_gTurbulence(pd->noise_size, texvec[0] + time, texvec[1] + time, texvec[2] + time,
- pd->noise_depth, 0, pd->noise_basis);
- //turb = BLI_turbulence(pd->noise_size, texvec[0]+time, texvec[1]+time, texvec[2]+time, pd->noise_depth);
- }
- else {
- turb = BLI_gTurbulence(pd->noise_size, texvec[0] + vec[0], texvec[1] + vec[1], texvec[2] + vec[2],
- pd->noise_depth, 0, pd->noise_basis);
- }
+ turb = BLI_gTurbulence(pd->noise_size, texvec[0] + vec[0], texvec[1] + vec[1], texvec[2] + vec[2],
+ pd->noise_depth, 0, pd->noise_basis);
turb -= 0.5f; /* re-center 0.0-1.0 range around 0 to prevent offsetting result */
@@ -851,36 +774,16 @@ static int pointdensity_color(PointDensity *pd, TexResult *texres, float age, co
return retval;
}
-int pointdensitytex(Tex *tex, const float texvec[3], TexResult *texres)
-{
- PointDensity *pd = tex->pd;
- float age = 0.0f;
- float vec[3] = {0.0f, 0.0f, 0.0f};
- float col[3] = {0.0f, 0.0f, 0.0f};
- int retval = pointdensity(pd, texvec, texres, vec, &age, col);
-
- retval |= pointdensity_color(pd, texres, age, vec, col);
- BRICONTRGB;
-
- return retval;
-
-#if 0
- if (texres->nor!=NULL) {
- texres->nor[0] = texres->nor[1] = texres->nor[2] = 0.0f;
- }
-#endif
-}
-
static void sample_dummy_point_density(int resolution, float *values)
{
memset(values, 0, sizeof(float) * 4 * resolution * resolution * resolution);
}
-static void particle_system_minmax(Scene *scene,
+static void particle_system_minmax(Depsgraph *depsgraph,
+ Scene *scene,
Object *object,
ParticleSystem *psys,
float radius,
- const bool use_render_params,
float min[3], float max[3])
{
const float size[3] = {radius, radius, radius};
@@ -899,10 +802,8 @@ static void particle_system_minmax(Scene *scene,
}
unit_m4(mat);
- if (use_render_params) {
- psys_render_set(object, psys, mat, mat, 1, 1, 0);
- }
+ sim.depsgraph = depsgraph;
sim.scene = scene;
sim.ob = object;
sim.psys = psys;
@@ -930,31 +831,28 @@ static void particle_system_minmax(Scene *scene,
end_latt_deform(psys->lattice_deform_data);
psys->lattice_deform_data = NULL;
}
-
- if (use_render_params) {
- psys_render_restore(object, psys);
- }
}
void RE_point_density_cache(
- Scene *scene,
- PointDensity *pd,
- const bool use_render_params)
+ struct Depsgraph *depsgraph,
+ PointDensity *pd)
{
- float mat[4][4];
+ const bool use_render_params = (DEG_get_mode(depsgraph) == DAG_EVAL_RENDER);
+
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
+
/* Same matricies/resolution as dupli_render_particle_set(). */
- unit_m4(mat);
BLI_mutex_lock(&sample_mutex);
- cache_pointdensity_ex(scene, pd, mat, mat, 1, 1, use_render_params);
+ cache_pointdensity(depsgraph, scene, pd, use_render_params);
BLI_mutex_unlock(&sample_mutex);
}
void RE_point_density_minmax(
- struct Scene *scene,
+ struct Depsgraph *depsgraph,
struct PointDensity *pd,
- const bool use_render_params,
float r_min[3], float r_max[3])
{
+ Scene *scene = DEG_get_evaluated_scene(depsgraph);
Object *object = pd->object;
if (object == NULL) {
zero_v3(r_min);
@@ -963,6 +861,7 @@ void RE_point_density_minmax(
}
if (pd->source == TEX_PD_PSYS) {
ParticleSystem *psys;
+
if (pd->psys == 0) {
zero_v3(r_min);
zero_v3(r_max);
@@ -974,11 +873,12 @@ void RE_point_density_minmax(
zero_v3(r_max);
return;
}
- particle_system_minmax(scene,
+
+ particle_system_minmax(depsgraph,
+ scene,
object,
psys,
pd->radius,
- use_render_params,
r_min, r_max);
}
else {
@@ -1046,10 +946,9 @@ static void point_density_sample_func(
* NOTE 2: Frees point density structure after sampling.
*/
void RE_point_density_sample(
- Scene *scene,
+ Depsgraph *depsgraph,
PointDensity *pd,
const int resolution,
- const bool use_render_params,
float *values)
{
Object *object = pd->object;
@@ -1065,9 +964,8 @@ void RE_point_density_sample(
}
BLI_mutex_lock(&sample_mutex);
- RE_point_density_minmax(scene,
+ RE_point_density_minmax(depsgraph,
pd,
- use_render_params,
min,
max);
BLI_mutex_unlock(&sample_mutex);
@@ -1099,3 +997,8 @@ void RE_point_density_free(struct PointDensity *pd)
{
free_pointdensity(pd);
}
+
+void RE_point_density_fix_linking(void)
+{
+}
+
diff --git a/source/blender/render/intern/source/rayshade.c b/source/blender/render/intern/source/rayshade.c
deleted file mode 100644
index 26a0b0c71b4..00000000000
--- a/source/blender/render/intern/source/rayshade.c
+++ /dev/null
@@ -1,2503 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 1990-1998 NeoGeo BV.
- * All rights reserved.
- *
- * Contributors: 2004/2005 Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/rayshade.c
- * \ingroup render
- */
-
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-#include <stdlib.h>
-#include <float.h>
-#include <assert.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_material_types.h"
-#include "DNA_lamp_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_system.h"
-#include "BLI_math.h"
-#include "BLI_rand.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "BKE_node.h"
-
-#include "render_result.h"
-#include "render_types.h"
-#include "rendercore.h"
-#include "renderdatabase.h"
-#include "pixelshading.h"
-#include "shading.h"
-#include "volumetric.h"
-
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "raycounter.h"
-
-#define RAY_TRA 1
-#define RAY_INSIDE 2
-
-#define DEPTH_SHADOW_TRA 10
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-static int test_break(void *data)
-{
- Render *re = (Render *)data;
- return re->test_break(re->tbh);
-}
-
-static void RE_rayobject_config_control(RayObject *r, Render *re)
-{
- if (RE_rayobject_isRayAPI(r)) {
- r = RE_rayobject_align(r);
- r->control.data = re;
- r->control.test_break = test_break;
- }
-}
-
-RayObject *RE_rayobject_create(int type, int size, int octree_resolution)
-{
- RayObject * res = NULL;
-
- if (type == R_RAYSTRUCTURE_AUTO) {
- /* TODO */
- //if (detect_simd())
-#ifdef __SSE__
- type = BLI_cpu_support_sse2()? R_RAYSTRUCTURE_SIMD_SVBVH: R_RAYSTRUCTURE_VBVH;
-#else
- type = R_RAYSTRUCTURE_VBVH;
-#endif
- }
-
-#ifndef __SSE__
- if (type == R_RAYSTRUCTURE_SIMD_SVBVH || type == R_RAYSTRUCTURE_SIMD_QBVH) {
- puts("Warning: Using VBVH (SSE was disabled at compile time)");
- type = R_RAYSTRUCTURE_VBVH;
- }
-#endif
-
-
- if (type == R_RAYSTRUCTURE_OCTREE) //TODO dynamic ocres
- res = RE_rayobject_octree_create(octree_resolution, size);
- else if (type == R_RAYSTRUCTURE_VBVH)
- res = RE_rayobject_vbvh_create(size);
- else if (type == R_RAYSTRUCTURE_SIMD_SVBVH)
- res = RE_rayobject_svbvh_create(size);
- else if (type == R_RAYSTRUCTURE_SIMD_QBVH)
- res = RE_rayobject_qbvh_create(size);
- else
- res = RE_rayobject_vbvh_create(size); //Fallback
-
- return res;
-}
-
-static RayObject* rayobject_create(Render *re, int type, int size)
-{
- RayObject * res = NULL;
-
- res = RE_rayobject_create(type, size, re->r.ocres);
-
- if (res)
- RE_rayobject_config_control(res, re);
-
- return res;
-}
-
-#ifdef RE_RAYCOUNTER
-RayCounter re_rc_counter[BLENDER_MAX_THREADS];
-#endif
-
-
-void freeraytree(Render *re)
-{
- ObjectInstanceRen *obi;
-
- if (re->raytree) {
- RE_rayobject_free(re->raytree);
- re->raytree = NULL;
- }
- if (re->rayfaces) {
- MEM_freeN(re->rayfaces);
- re->rayfaces = NULL;
- }
- if (re->rayprimitives) {
- MEM_freeN(re->rayprimitives);
- re->rayprimitives = NULL;
- }
-
- for (obi=re->instancetable.first; obi; obi=obi->next) {
- ObjectRen *obr = obi->obr;
- if (obr->raytree) {
- RE_rayobject_free(obr->raytree);
- obr->raytree = NULL;
- }
- if (obr->rayfaces) {
- MEM_freeN(obr->rayfaces);
- obr->rayfaces = NULL;
- }
- if (obi->raytree) {
- RE_rayobject_free(obi->raytree);
- obi->raytree = NULL;
- }
- }
-
-#ifdef RE_RAYCOUNTER
- {
- const int num_threads = re->r.threads;
- RayCounter sum;
- memset(&sum, 0, sizeof(sum));
- int i;
- for (i=0; i<num_threads; i++)
- RE_RC_MERGE(&sum, re_rc_counter+i);
- RE_RC_INFO(&sum);
- }
-#endif
-}
-
-static bool is_raytraceable_vlr(Render *re, VlakRen *vlr)
-{
- /* note: volumetric must be tracable, wire must not */
- if ((re->flag & R_BAKE_TRACE) || (vlr->flag & R_TRACEBLE) || (vlr->mat->material_type == MA_TYPE_VOLUME))
- if (vlr->mat->material_type != MA_TYPE_WIRE)
- return 1;
- return 0;
-}
-
-static bool is_raytraceable(Render *re, ObjectInstanceRen *obi)
-{
- int v;
- ObjectRen *obr = obi->obr;
-
- if (re->excludeob && obr->ob == re->excludeob)
- return 0;
-
- for (v=0;v<obr->totvlak;v++) {
- VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
-
- if (is_raytraceable_vlr(re, vlr))
- return 1;
- }
-
- return 0;
-}
-
-
-RayObject* makeraytree_object(Render *re, ObjectInstanceRen *obi)
-{
- /*TODO
- * out-of-memory safeproof
- * break render
- * update render stats */
- ObjectRen *obr = obi->obr;
-
- if (obr->raytree == NULL) {
- RayObject *raytree;
- RayFace *face = NULL;
- VlakPrimitive *vlakprimitive = NULL;
- int v;
-
- //Count faces
- int faces = 0;
- for (v=0;v<obr->totvlak;v++) {
- VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
- if (is_raytraceable_vlr(re, vlr))
- faces++;
- }
-
- if (faces == 0)
- return NULL;
-
- //Create Ray cast accelaration structure
- raytree = rayobject_create( re, re->r.raytrace_structure, faces );
- if ( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) )
- vlakprimitive = obr->rayprimitives = (VlakPrimitive *)MEM_callocN(faces * sizeof(VlakPrimitive), "ObjectRen primitives");
- else
- face = obr->rayfaces = (RayFace *)MEM_callocN(faces * sizeof(RayFace), "ObjectRen faces");
-
- obr->rayobi = obi;
-
- for (v=0;v<obr->totvlak;v++) {
- VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
- if (is_raytraceable_vlr(re, vlr)) {
- if ((re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS)) {
- RE_rayobject_add(raytree, RE_vlakprimitive_from_vlak(vlakprimitive, obi, vlr));
- vlakprimitive++;
- }
- else {
- RE_rayface_from_vlak(face, obi, vlr);
- RE_rayobject_add(raytree, RE_rayobject_unalignRayFace(face));
- face++;
- }
- }
- }
- RE_rayobject_done(raytree);
-
- /* in case of cancel during build, raytree is not usable */
- if (test_break(re))
- RE_rayobject_free(raytree);
- else
- obr->raytree= raytree;
- }
-
- if (obr->raytree) {
- if ((obi->flag & R_TRANSFORMED) && obi->raytree == NULL) {
- obi->transform_primitives = 0;
- obi->raytree = RE_rayobject_instance_create( obr->raytree, obi->mat, obi, obi->obr->rayobi );
- }
- }
-
- if (obi->raytree) return obi->raytree;
- return obi->obr->raytree;
-}
-
-static bool has_special_rayobject(Render *re, ObjectInstanceRen *obi)
-{
- if ( (obi->flag & R_TRANSFORMED) && (re->r.raytrace_options & R_RAYTRACE_USE_INSTANCES) ) {
- ObjectRen *obr = obi->obr;
- int v, faces = 0;
-
- for (v=0;v<obr->totvlak;v++) {
- VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
- if (is_raytraceable_vlr(re, vlr)) {
- faces++;
- if (faces > 4)
- return 1;
- }
- }
- }
- return 0;
-}
-/*
- * create a single raytrace structure with all faces
- */
-static void makeraytree_single(Render *re)
-{
- ObjectInstanceRen *obi;
- RayObject *raytree;
- RayFace *face = NULL;
- VlakPrimitive *vlakprimitive = NULL;
- int faces = 0, special = 0;
-
- for (obi = re->instancetable.first; obi; obi = obi->next) {
- if (is_raytraceable(re, obi)) {
- ObjectRen *obr = obi->obr;
-
- if (has_special_rayobject(re, obi)) {
- special++;
- }
- else {
- int v;
- for (v = 0;v < obr->totvlak; v++) {
- VlakRen *vlr = obr->vlaknodes[v >> 8].vlak + (v&255);
- if (is_raytraceable_vlr(re, vlr)) {
- faces++;
- }
- }
- }
- }
- }
-
- if (faces + special == 0) {
- re->raytree = RE_rayobject_empty_create();
- return;
- }
-
- //Create raytree
- raytree = re->raytree = rayobject_create( re, re->r.raytrace_structure, faces+special );
-
- if ( (re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS) ) {
- vlakprimitive = re->rayprimitives = (VlakPrimitive *)MEM_callocN(faces * sizeof(VlakPrimitive), "Raytrace vlak-primitives");
- }
- else {
- face = re->rayfaces = (RayFace *)MEM_callocN(faces * sizeof(RayFace), "Render ray faces");
- }
-
- for (obi=re->instancetable.first; obi; obi=obi->next)
- if (is_raytraceable(re, obi)) {
- if (test_break(re))
- break;
-
- if (has_special_rayobject(re, obi)) {
- RayObject *obj = makeraytree_object(re, obi);
-
- if (test_break(re))
- break;
-
- if (obj)
- RE_rayobject_add(re->raytree, obj);
- }
- else {
- int v;
- ObjectRen *obr = obi->obr;
-
- if (obi->flag & R_TRANSFORMED) {
- obi->transform_primitives = 1;
- }
-
- for (v=0;v<obr->totvlak;v++) {
- VlakRen *vlr = obr->vlaknodes[v>>8].vlak + (v&255);
- if (is_raytraceable_vlr(re, vlr)) {
- if ((re->r.raytrace_options & R_RAYTRACE_USE_LOCAL_COORDS)) {
- RayObject *obj = RE_vlakprimitive_from_vlak( vlakprimitive, obi, vlr );
- RE_rayobject_add(raytree, obj);
- vlakprimitive++;
- }
- else {
- RE_rayface_from_vlak(face, obi, vlr);
- if ((obi->flag & R_TRANSFORMED)) {
- mul_m4_v3(obi->mat, face->v1);
- mul_m4_v3(obi->mat, face->v2);
- mul_m4_v3(obi->mat, face->v3);
- if (RE_rayface_isQuad(face))
- mul_m4_v3(obi->mat, face->v4);
- }
-
- RE_rayobject_add(raytree, RE_rayobject_unalignRayFace(face));
- face++;
- }
- }
- }
- }
- }
-
- if (!test_break(re)) {
- re->i.infostr = IFACE_("Raytree.. building");
- re->stats_draw(re->sdh, &re->i);
-
- RE_rayobject_done(raytree);
- }
-}
-
-void makeraytree(Render *re)
-{
- float min[3], max[3], sub[3];
- int i;
-
- re->i.infostr = IFACE_("Raytree.. preparing");
- re->stats_draw(re->sdh, &re->i);
-
- /* disable options not yet supported by octree,
- * they might actually never be supported (unless people really need it) */
- if (re->r.raytrace_structure == R_RAYSTRUCTURE_OCTREE)
- re->r.raytrace_options &= ~( R_RAYTRACE_USE_INSTANCES | R_RAYTRACE_USE_LOCAL_COORDS);
-
- makeraytree_single(re);
-
- if (test_break(re)) {
- freeraytree(re);
-
- re->i.infostr = IFACE_("Raytree building canceled");
- re->stats_draw(re->sdh, &re->i);
- }
- else {
- /* Calculate raytree max_size
- * This is ONLY needed to kept a bogus behavior of SUN and HEMI lights */
- INIT_MINMAX(min, max);
- RE_rayobject_merge_bb(re->raytree, min, max);
- if (min[0] > max[0]) { /* empty raytree */
- zero_v3(min);
- zero_v3(max);
- }
- for (i=0; i<3; i++) {
- /* TODO: explain why add top both min and max??? */
- min[i] += 0.01f;
- max[i] += 0.01f;
- sub[i] = max[i]-min[i];
- }
-
- re->maxdist = len_v3(sub);
-
- re->i.infostr = IFACE_("Raytree finished");
- re->stats_draw(re->sdh, &re->i);
- }
-
-#ifdef RE_RAYCOUNTER
- memset(re_rc_counter, 0, sizeof(re_rc_counter));
-#endif
-}
-
-/* if (shi->osatex) */
-static void shade_ray_set_derivative(ShadeInput *shi)
-{
- float detsh, t00, t10, t01, t11;
- int axis1, axis2;
-
- /* find most stable axis to project */
- axis_dominant_v3(&axis1, &axis2, shi->facenor);
-
- /* compute u,v and derivatives */
- if (shi->obi->flag & R_TRANSFORMED) {
- float v1[3], v2[3], v3[3];
-
- mul_v3_m3v3(v1, shi->obi->nmat, shi->v1->co);
- mul_v3_m3v3(v2, shi->obi->nmat, shi->v2->co);
- mul_v3_m3v3(v3, shi->obi->nmat, shi->v3->co);
-
- /* same as below */
- t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
- t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2];
- }
- else {
- const float *v1= shi->v1->co;
- const float *v2= shi->v2->co;
- const float *v3= shi->v3->co;
-
- /* same as above */
- t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
- t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2];
- }
-
- detsh= 1.0f/(t00*t11-t10*t01);
- t00*= detsh; t01*=detsh;
- t10*=detsh; t11*=detsh;
-
- shi->dx_u= shi->dxco[axis1]*t11- shi->dxco[axis2]*t10;
- shi->dx_v= shi->dxco[axis2]*t00- shi->dxco[axis1]*t01;
- shi->dy_u= shi->dyco[axis1]*t11- shi->dyco[axis2]*t10;
- shi->dy_v= shi->dyco[axis2]*t00- shi->dyco[axis1]*t01;
-
-}
-
-/* main ray shader */
-void shade_ray(Isect *is, ShadeInput *shi, ShadeResult *shr)
-{
- ObjectInstanceRen *obi = (ObjectInstanceRen *)is->hit.ob;
- VlakRen *vlr = (VlakRen *)is->hit.face;
-
- /* set up view vector */
- copy_v3_v3(shi->view, is->dir);
-
- /* render co */
- shi->co[0]= is->start[0]+is->dist*(shi->view[0]);
- shi->co[1]= is->start[1]+is->dist*(shi->view[1]);
- shi->co[2]= is->start[2]+is->dist*(shi->view[2]);
-
- normalize_v3(shi->view);
-
- shi->obi= obi;
- shi->obr= obi->obr;
- shi->vlr= vlr;
- shi->mat= vlr->mat;
- shade_input_init_material(shi);
-
- if (is->isect==2)
- shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3);
- else
- shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2);
-
- shi->u= is->u;
- shi->v= is->v;
- shi->dx_u= shi->dx_v= shi->dy_u= shi->dy_v= 0.0f;
-
- if (shi->osatex)
- shade_ray_set_derivative(shi);
- shade_input_set_normals(shi);
-
- shade_input_set_shade_texco(shi);
- if (shi->mat->material_type == MA_TYPE_VOLUME) {
- if (ELEM(is->mode, RE_RAY_SHADOW, RE_RAY_SHADOW_TRA)) {
- shade_volume_shadow(shi, shr, is);
- }
- else {
- shade_volume_outside(shi, shr);
- }
- }
- else if (is->mode==RE_RAY_SHADOW_TRA) {
- /* temp hack to prevent recursion */
- if (shi->nodes==0 && shi->mat->nodetree && shi->mat->use_nodes) {
- ntreeShaderExecTree(shi->mat->nodetree, shi, shr);
- shi->mat= vlr->mat; /* shi->mat is being set in nodetree */
- }
- else
- shade_color(shi, shr);
- }
- else {
- if (shi->mat->nodetree && shi->mat->use_nodes) {
- ntreeShaderExecTree(shi->mat->nodetree, shi, shr);
- shi->mat= vlr->mat; /* shi->mat is being set in nodetree */
- }
- else {
- shade_material_loop(shi, shr);
- }
-
- /* raytrace likes to separate the spec color */
- sub_v3_v3v3(shr->diff, shr->combined, shr->spec);
- copy_v3_v3(shr->diffshad, shr->diff);
- }
-
-}
-
-static int refraction(float refract[3], const float n[3], const float view[3], float index)
-{
- float dot, fac;
-
- copy_v3_v3(refract, view);
-
- dot = dot_v3v3(view, n);
-
- if (dot>0.0f) {
- index = 1.0f/index;
- fac= 1.0f - (1.0f - dot*dot)*index*index;
- if (fac <= 0.0f) return 0;
- fac= -dot*index + sqrtf(fac);
- }
- else {
- fac= 1.0f - (1.0f - dot*dot)*index*index;
- if (fac <= 0.0f) return 0;
- fac= -dot*index - sqrtf(fac);
- }
-
- refract[0]= index*view[0] + fac*n[0];
- refract[1]= index*view[1] + fac*n[1];
- refract[2]= index*view[2] + fac*n[2];
-
- return 1;
-}
-
-static void reflection_simple(float ref[3], float n[3], const float view[3])
-{
- const float f1= -2.0f * dot_v3v3(n, view);
- madd_v3_v3v3fl(ref, view, n, f1);
-}
-
-/* orn = original face normal */
-static void reflection(float ref[3], float n[3], const float view[3], const float orn[3])
-{
- float f1;
-
- reflection_simple(ref, n, view);
-
- /* test phong normals, then we should prevent vector going to the back */
- f1= dot_v3v3(ref, orn);
- if (f1>0.0f) {
- f1+= 0.01f;
- ref[0]-= f1*orn[0];
- ref[1]-= f1*orn[1];
- ref[2]-= f1*orn[2];
- }
-}
-
-#if 0
-static void color_combine(float *result, float fac1, float fac2, float col1[3], float col2[3])
-{
- float col1t[3], col2t[3];
-
- col1t[0]= sqrt(col1[0]);
- col1t[1]= sqrt(col1[1]);
- col1t[2]= sqrt(col1[2]);
- col2t[0]= sqrt(col2[0]);
- col2t[1]= sqrt(col2[1]);
- col2t[2]= sqrt(col2[2]);
-
- result[0]= (fac1*col1t[0] + fac2*col2t[0]);
- result[0]*= result[0];
- result[1]= (fac1*col1t[1] + fac2*col2t[1]);
- result[1]*= result[1];
- result[2]= (fac1*col1t[2] + fac2*col2t[2]);
- result[2]*= result[2];
-}
-#endif
-
-static float shade_by_transmission(Isect *is, ShadeInput *shi, ShadeResult *shr)
-{
- float d;
- if (0 == (shi->mat->mode & MA_TRANSP))
- return -1;
-
- if (shi->mat->tx_limit <= 0.0f) {
- d= 1.0f;
- }
- else {
- float p;
-
- /* shi.co[] calculated by shade_ray() */
- const float dx= shi->co[0] - is->start[0];
- const float dy= shi->co[1] - is->start[1];
- const float dz= shi->co[2] - is->start[2];
- d = sqrtf(dx * dx + dy * dy + dz * dz);
- if (d > shi->mat->tx_limit)
- d= shi->mat->tx_limit;
-
- p = shi->mat->tx_falloff;
- if (p < 0.0f) p= 0.0f;
- else if (p > 10.0f) p= 10.0f;
-
- shr->alpha *= powf(d, p);
- if (shr->alpha > 1.0f)
- shr->alpha= 1.0f;
- }
-
- return d;
-}
-
-static void ray_fadeout_endcolor(float col[3], ShadeInput *origshi, ShadeInput *shi, ShadeResult *shr, Isect *isec, const float vec[3])
-{
- /* un-intersected rays get either rendered material color or sky color */
- if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOMAT) {
- copy_v3_v3(col, shr->combined);
- }
- else if (origshi->mat->fadeto_mir == MA_RAYMIR_FADETOSKY) {
- copy_v3_v3(shi->view, vec);
- normalize_v3(shi->view);
-
- shadeSkyView(col, isec->start, shi->view, NULL, shi->thread);
- shadeSunView(col, shi->view);
- }
-}
-
-static void ray_fadeout(Isect *is, ShadeInput *shi, float col[3], const float blendcol[3], float dist_mir)
-{
- /* if fading out, linear blend against fade color */
- float blendfac;
-
- blendfac = 1.0f - len_v3v3(shi->co, is->start)/dist_mir;
-
- col[0] = col[0]*blendfac + (1.0f - blendfac)*blendcol[0];
- col[1] = col[1]*blendfac + (1.0f - blendfac)*blendcol[1];
- col[2] = col[2]*blendfac + (1.0f - blendfac)*blendcol[2];
-}
-
-/* the main recursive tracer itself
- * note: 'col' must be initialized */
-static void traceray(ShadeInput *origshi, ShadeResult *origshr, short depth, const float start[3], const float dir[3], float col[4], ObjectInstanceRen *obi, VlakRen *vlr, int traflag)
-{
- ShadeInput shi = {NULL};
- Isect isec;
- float dist_mir = origshi->mat->dist_mir;
-
- /* with high depth the number of rays can explode due to the path splitting
- * in two each time, giving 2^depth rays. we need to be able to cancel such
- * a render to avoid hanging, a better solution would be random picking
- * between directions and russian roulette termination */
- if (R.test_break(R.tbh)) {
- zero_v4(col);
- return;
- }
-
- copy_v3_v3(isec.start, start);
- copy_v3_v3(isec.dir, dir);
- isec.dist = dist_mir > 0 ? dist_mir : RE_RAYTRACE_MAXDIST;
- isec.mode= RE_RAY_MIRROR;
- isec.check = RE_CHECK_VLR_RENDER;
- isec.skip = RE_SKIP_VLR_NEIGHBOUR;
- isec.hint = NULL;
-
- isec.orig.ob = obi;
- isec.orig.face = vlr;
- RE_RC_INIT(isec, shi);
-
- /* database is in original view, obi->imat transforms current position back to original */
- RE_instance_rotate_ray(origshi->obi, &isec);
-
- if (RE_rayobject_raycast(R.raytree, &isec)) {
- ShadeResult shr= {{0}};
- float d= 1.0f;
-
- RE_instance_rotate_ray_restore(origshi->obi, &isec);
-
- /* for as long we don't have proper dx/dy transform for rays we copy over original */
- copy_v3_v3(shi.dxco, origshi->dxco);
- copy_v3_v3(shi.dyco, origshi->dyco);
-
- shi.mask= origshi->mask;
- shi.osatex= origshi->osatex;
- shi.depth= origshi->depth + 1; /* only used to indicate tracing */
- shi.thread= origshi->thread;
- //shi.sample= 0; // memset above, so don't need this
- shi.xs= origshi->xs;
- shi.ys= origshi->ys;
- shi.do_manage= origshi->do_manage;
- shi.lay= origshi->lay;
- shi.passflag= SCE_PASS_COMBINED; /* result of tracing needs no pass info */
- shi.combinedflag= 0xFFFFFF; /* ray trace does all options */
- //shi.do_preview = false; // memset above, so don't need this
- shi.light_override= origshi->light_override;
- shi.mat_override= origshi->mat_override;
-
- shade_ray(&isec, &shi, &shr);
- /* ray has traveled inside the material, so shade by transmission */
- if (traflag & RAY_INSIDE)
- d= shade_by_transmission(&isec, &shi, &shr);
-
- if (depth>0) {
- float fr, fg, fb, f1;
-
- if ((shi.mat->mode_l & MA_TRANSP) && shr.alpha < 1.0f && (shi.mat->mode_l & (MA_ZTRANSP | MA_RAYTRANSP))) {
- float nf, f, refract[3], tracol[4];
-
- tracol[0]= shi.r;
- tracol[1]= shi.g;
- tracol[2]= shi.b;
- tracol[3]= col[3]; /* we pass on and accumulate alpha */
-
- if ((shi.mat->mode & MA_TRANSP) && (shi.mat->mode & MA_RAYTRANSP)) {
- /* don't overwrite traflag, it's value is used in mirror reflection */
- int new_traflag = traflag;
-
- if (new_traflag & RAY_INSIDE) {
- /* inside the material, so use inverse normal */
- float norm[3];
- norm[0]= - shi.vn[0];
- norm[1]= - shi.vn[1];
- norm[2]= - shi.vn[2];
-
- if (refraction(refract, norm, shi.view, shi.ang)) {
- /* ray comes out from the material into air */
- new_traflag &= ~RAY_INSIDE;
- }
- else {
- /* total internal reflection (ray stays inside the material) */
- reflection(refract, norm, shi.view, shi.vn);
- }
- }
- else {
- if (refraction(refract, shi.vn, shi.view, shi.ang)) {
- /* ray goes in to the material from air */
- new_traflag |= RAY_INSIDE;
- }
- else {
- /* total external reflection (ray doesn't enter the material) */
- reflection(refract, shi.vn, shi.view, shi.vn);
- }
- }
- traceray(origshi, origshr, depth-1, shi.co, refract, tracol, shi.obi, shi.vlr, new_traflag);
- }
- else
- traceray(origshi, origshr, depth-1, shi.co, shi.view, tracol, shi.obi, shi.vlr, 0);
-
- f= shr.alpha; f1= 1.0f-f;
- nf= (shi.mat->mode & MA_RAYTRANSP) ? d * shi.mat->filter : 0.0f;
- fr= 1.0f+ nf*(shi.r-1.0f);
- fg= 1.0f+ nf*(shi.g-1.0f);
- fb= 1.0f+ nf*(shi.b-1.0f);
- shr.diff[0]= f*shr.diff[0] + f1*fr*tracol[0];
- shr.diff[1]= f*shr.diff[1] + f1*fg*tracol[1];
- shr.diff[2]= f*shr.diff[2] + f1*fb*tracol[2];
-
- shr.spec[0] *=f;
- shr.spec[1] *=f;
- shr.spec[2] *=f;
-
- col[3]= f1*tracol[3] + f;
- }
- else {
- col[3]= 1.0f;
- }
-
- float f;
- if (shi.mat->mode_l & MA_RAYMIRROR) {
- f= shi.ray_mirror;
- if (f!=0.0f) f*= fresnel_fac(shi.view, shi.vn, shi.mat->fresnel_mir_i, shi.mat->fresnel_mir);
- }
- else f= 0.0f;
-
- if (f!=0.0f) {
- float mircol[4];
- float ref[3];
-
- reflection_simple(ref, shi.vn, shi.view);
- traceray(origshi, origshr, depth-1, shi.co, ref, mircol, shi.obi, shi.vlr, traflag);
-
- f1= 1.0f-f;
-
- /* combine */
- //color_combine(col, f*fr*(1.0f-shr.spec[0]), f1, col, shr.diff);
- //col[0]+= shr.spec[0];
- //col[1]+= shr.spec[1];
- //col[2]+= shr.spec[2];
-
- fr= shi.mirr;
- fg= shi.mirg;
- fb= shi.mirb;
-
- col[0]= f*fr*(1.0f-shr.spec[0])*mircol[0] + f1*shr.diff[0] + shr.spec[0];
- col[1]= f*fg*(1.0f-shr.spec[1])*mircol[1] + f1*shr.diff[1] + shr.spec[1];
- col[2]= f*fb*(1.0f-shr.spec[2])*mircol[2] + f1*shr.diff[2] + shr.spec[2];
- }
- else {
- col[0]= shr.diff[0] + shr.spec[0];
- col[1]= shr.diff[1] + shr.spec[1];
- col[2]= shr.diff[2] + shr.spec[2];
- }
-
- if (dist_mir > 0.0f) {
- float blendcol[3];
-
- /* max ray distance set, but found an intersection, so fade this color
- * out towards the sky/material color for a smooth transition */
- ray_fadeout_endcolor(blendcol, origshi, &shi, origshr, &isec, dir);
- ray_fadeout(&isec, &shi, col, blendcol, dist_mir);
- }
- }
- else {
- col[0]= shr.diff[0] + shr.spec[0];
- col[1]= shr.diff[1] + shr.spec[1];
- col[2]= shr.diff[2] + shr.spec[2];
- }
-
- }
- else {
- ray_fadeout_endcolor(col, origshi, &shi, origshr, &isec, dir);
- }
- RE_RC_MERGE(&origshi->raycounter, &shi.raycounter);
-}
-
-/* **************** jitter blocks ********** */
-
-/* calc distributed planar energy */
-
-static void DP_energy(float *table, float vec[2], int tot, float xsize, float ysize)
-{
- int x, y, a;
- float *fp, force[3], result[3];
- float dx, dy, dist, min;
-
- min= MIN2(xsize, ysize);
- min*= min;
- result[0]= result[1]= 0.0f;
-
- for (y= -1; y<2; y++) {
- dy= ysize*y;
- for (x= -1; x<2; x++) {
- dx= xsize*x;
- fp= table;
- for (a=0; a<tot; a++, fp+= 2) {
- force[0]= vec[0] - fp[0]-dx;
- force[1]= vec[1] - fp[1]-dy;
- dist= force[0]*force[0] + force[1]*force[1];
- if (dist < min && dist>0.0f) {
- result[0]+= force[0]/dist;
- result[1]+= force[1]/dist;
- }
- }
- }
- }
- vec[0] += 0.1f*min*result[0]/(float)tot;
- vec[1] += 0.1f*min*result[1]/(float)tot;
- /* cyclic clamping */
- vec[0]= vec[0] - xsize*floorf(vec[0]/xsize + 0.5f);
- vec[1]= vec[1] - ysize*floorf(vec[1]/ysize + 0.5f);
-}
-
-/* random offset of 1 in 2 */
-static void jitter_plane_offset(float *jitter1, float *jitter2, int tot, float sizex, float sizey, float ofsx, float ofsy)
-{
- float dsizex= sizex*ofsx;
- float dsizey= sizey*ofsy;
- float hsizex= 0.5f*sizex, hsizey= 0.5f*sizey;
- int x;
-
- for (x=tot; x>0; x--, jitter1+=2, jitter2+=2) {
- jitter2[0]= jitter1[0] + dsizex;
- jitter2[1]= jitter1[1] + dsizey;
- if (jitter2[0] > hsizex) jitter2[0]-= sizex;
- if (jitter2[1] > hsizey) jitter2[1]-= sizey;
- }
-}
-
-/* called from convertBlenderScene.c */
-/* we do this in advance to get consistent random, not alter the render seed, and be threadsafe */
-void init_jitter_plane(LampRen *lar)
-{
- float *fp;
- int x, tot= lar->ray_totsamp;
-
- /* test if already initialized */
- if (lar->jitter) return;
-
- /* at least 4, or max threads+1 tables */
- if (BLENDER_MAX_THREADS < 4) x= 4;
- else x= BLENDER_MAX_THREADS+1;
- fp= lar->jitter= MEM_callocN(x*tot*2*sizeof(float), "lamp jitter tab");
-
- /* if 1 sample, we leave table to be zero's */
- if (tot>1) {
- /* set per-lamp fixed seed */
- RNG *rng = BLI_rng_new_srandom(tot);
- int iter=12;
-
- /* fill table with random locations, area_size large */
- for (x=0; x<tot; x++, fp+=2) {
- fp[0]= (BLI_rng_get_float(rng)-0.5f)*lar->area_size;
- fp[1]= (BLI_rng_get_float(rng)-0.5f)*lar->area_sizey;
- }
-
- while (iter--) {
- fp= lar->jitter;
- for (x=tot; x>0; x--, fp+=2) {
- DP_energy(lar->jitter, fp, tot, lar->area_size, lar->area_sizey);
- }
- }
-
- BLI_rng_free(rng);
- }
- /* create the dithered tables (could just check lamp type!) */
- jitter_plane_offset(lar->jitter, lar->jitter+2*tot, tot, lar->area_size, lar->area_sizey, 0.5f, 0.0f);
- jitter_plane_offset(lar->jitter, lar->jitter+4*tot, tot, lar->area_size, lar->area_sizey, 0.5f, 0.5f);
- jitter_plane_offset(lar->jitter, lar->jitter+6*tot, tot, lar->area_size, lar->area_sizey, 0.0f, 0.5f);
-}
-
-/* table around origin, -0.5*size to 0.5*size */
-static float *give_jitter_plane(LampRen *lar, int thread, int xs, int ys)
-{
- int tot;
-
- tot= lar->ray_totsamp;
-
- if (lar->ray_samp_type & LA_SAMP_JITTER) {
- /* made it threadsafe */
-
- if (lar->xold[thread]!=xs || lar->yold[thread]!=ys) {
- jitter_plane_offset(lar->jitter, lar->jitter+2*(thread+1)*tot, tot, lar->area_size, lar->area_sizey, BLI_thread_frand(thread), BLI_thread_frand(thread));
- lar->xold[thread]= xs;
- lar->yold[thread]= ys;
- }
- return lar->jitter+2*(thread+1)*tot;
- }
- if (lar->ray_samp_type & LA_SAMP_DITHER) {
- return lar->jitter + 2*tot*((xs & 1)+2*(ys & 1));
- }
-
- return lar->jitter;
-}
-
-
-/* **************** QMC sampling *************** */
-
-static void halton_sample(double *ht_invprimes, double *ht_nums, double *v)
-{
- /* incremental halton sequence generator, from:
- * "Instant Radiosity", Keller A. */
- unsigned int i;
-
- for (i = 0; i < 2; i++) {
- double r = fabs((1.0 - ht_nums[i]) - 1e-10);
-
- if (ht_invprimes[i] >= r) {
- double lasth;
- double h = ht_invprimes[i];
-
- do {
- lasth = h;
- h *= ht_invprimes[i];
- } while (h >= r);
-
- ht_nums[i] += ((lasth + h) - 1.0);
- }
- else
- ht_nums[i] += ht_invprimes[i];
-
- v[i] = (float)ht_nums[i];
- }
-}
-
-/* Generate Hammersley points in [0,1)^2
- * From Lucille renderer */
-static void hammersley_create(double *out, int n)
-{
- double p, t;
- int k, kk;
-
- for (k = 0; k < n; k++) {
- t = 0;
- for (p = 0.5, kk = k; kk; p *= 0.5, kk >>= 1) {
- if (kk & 1) { /* kk mod 2 = 1 */
- t += p;
- }
- }
-
- out[2 * k + 0] = (double)k / (double)n;
- out[2 * k + 1] = t;
- }
-}
-
-static struct QMCSampler *QMC_initSampler(int type, int tot)
-{
- QMCSampler *qsa = MEM_callocN(sizeof(QMCSampler), "qmc sampler");
- qsa->samp2d = MEM_callocN(2*sizeof(double)*tot, "qmc sample table");
-
- qsa->tot = tot;
- qsa->type = type;
-
- if (qsa->type==SAMP_TYPE_HAMMERSLEY)
- hammersley_create(qsa->samp2d, qsa->tot);
-
- return qsa;
-}
-
-static void QMC_initPixel(QMCSampler *qsa, int thread)
-{
- if (qsa->type==SAMP_TYPE_HAMMERSLEY) {
- /* hammersley sequence is fixed, already created in QMCSampler init.
- * per pixel, gets a random offset. We create separate offsets per thread, for write-safety */
- qsa->offs[thread][0] = 0.5f * BLI_thread_frand(thread);
- qsa->offs[thread][1] = 0.5f * BLI_thread_frand(thread);
- }
- else { /* SAMP_TYPE_HALTON */
-
- /* generate a new randomized halton sequence per pixel
- * to alleviate qmc artifacts and make it reproducible
- * between threads/frames */
- double ht_invprimes[2], ht_nums[2];
- double r[2];
- int i;
-
- ht_nums[0] = BLI_thread_frand(thread);
- ht_nums[1] = BLI_thread_frand(thread);
- ht_invprimes[0] = 0.5;
- ht_invprimes[1] = 1.0/3.0;
-
- for (i=0; i< qsa->tot; i++) {
- halton_sample(ht_invprimes, ht_nums, r);
- qsa->samp2d[2*i+0] = r[0];
- qsa->samp2d[2*i+1] = r[1];
- }
- }
-}
-
-static void QMC_freeSampler(QMCSampler *qsa)
-{
- MEM_freeN(qsa->samp2d);
- MEM_freeN(qsa);
-}
-
-static void QMC_getSample(double *s, QMCSampler *qsa, int thread, int num)
-{
- if (qsa->type == SAMP_TYPE_HAMMERSLEY) {
- s[0] = fmod(qsa->samp2d[2*num+0] + qsa->offs[thread][0], 1.0f);
- s[1] = fmod(qsa->samp2d[2*num+1] + qsa->offs[thread][1], 1.0f);
- }
- else { /* SAMP_TYPE_HALTON */
- s[0] = qsa->samp2d[2*num+0];
- s[1] = qsa->samp2d[2*num+1];
- }
-}
-
-/* phong weighted disc using 'blur' for exponent, centred on 0,0 */
-static void QMC_samplePhong(float vec[3], QMCSampler *qsa, int thread, int num, float blur)
-{
- double s[2];
- float phi, pz, sqr;
-
- QMC_getSample(s, qsa, thread, num);
-
- phi = s[0]*2*M_PI;
- pz = pow(s[1], blur);
- sqr = sqrtf(1.0f - pz * pz);
-
- vec[0] = (float)(cosf(phi)*sqr);
- vec[1] = (float)(sinf(phi)*sqr);
- vec[2] = 0.0f;
-}
-
-/* rect of edge lengths sizex, sizey, centred on 0.0,0.0 i.e. ranging from -sizex/2 to +sizey/2 */
-static void QMC_sampleRect(float vec[3], QMCSampler *qsa, int thread, int num, float sizex, float sizey)
-{
- double s[2];
-
- QMC_getSample(s, qsa, thread, num);
-
- vec[0] = (float)(s[0] - 0.5) * sizex;
- vec[1] = (float)(s[1] - 0.5) * sizey;
- vec[2] = 0.0f;
-}
-
-/* disc of radius 'radius', centred on 0,0 */
-static void QMC_sampleDisc(float vec[3], QMCSampler *qsa, int thread, int num, float radius)
-{
- double s[2];
- float phi, sqr;
-
- QMC_getSample(s, qsa, thread, num);
-
- phi = s[0]*2*M_PI;
- sqr = sqrt(s[1]);
-
- vec[0] = cosf(phi)*sqr* radius/2.0f;
- vec[1] = sinf(phi)*sqr* radius/2.0f;
- vec[2] = 0.0f;
-}
-
-/* uniform hemisphere sampling */
-static void QMC_sampleHemi(float vec[3], QMCSampler *qsa, int thread, int num)
-{
- double s[2];
- float phi, sqr;
-
- QMC_getSample(s, qsa, thread, num);
-
- phi = s[0]*2.0*M_PI;
- sqr = sqrt(s[1]);
-
- vec[0] = cosf(phi)*sqr;
- vec[1] = sinf(phi)*sqr;
- vec[2] = (float)(1.0 - s[1]*s[1]);
-}
-
-#if 0 /* currently not used */
-/* cosine weighted hemisphere sampling */
-static void QMC_sampleHemiCosine(float vec[3], QMCSampler *qsa, int thread, int num)
-{
- double s[2];
- float phi, sqr;
-
- QMC_getSample(s, qsa, thread, num);
-
- phi = s[0]*2.f*M_PI;
- sqr = s[1]*sqrt(2-s[1]*s[1]);
-
- vec[0] = cos(phi)*sqr;
- vec[1] = sin(phi)*sqr;
- vec[2] = 1.f - s[1]*s[1];
-
-}
-#endif
-
-/* called from convertBlenderScene.c */
-void init_render_qmcsampler(Render *re)
-{
- const int num_threads = re->r.threads;
- re->qmcsamplers= MEM_callocN(sizeof(ListBase)*num_threads, "QMCListBase");
- re->num_qmc_samplers = num_threads;
-}
-
-static QMCSampler *get_thread_qmcsampler(Render *re, int thread, int type, int tot)
-{
- QMCSampler *qsa;
-
- /* create qmc samplers as needed, since recursion makes it hard to
- * predict how many are needed */
-
- for (qsa=re->qmcsamplers[thread].first; qsa; qsa=qsa->next) {
- if (qsa->type == type && qsa->tot == tot && !qsa->used) {
- qsa->used = true;
- return qsa;
- }
- }
-
- qsa= QMC_initSampler(type, tot);
- qsa->used = true;
- BLI_addtail(&re->qmcsamplers[thread], qsa);
-
- return qsa;
-}
-
-static void release_thread_qmcsampler(Render *UNUSED(re), int UNUSED(thread), QMCSampler *qsa)
-{
- qsa->used= 0;
-}
-
-void free_render_qmcsampler(Render *re)
-{
- if (re->qmcsamplers) {
- QMCSampler *qsa, *next;
- int a;
- for (a = 0; a < re->num_qmc_samplers; a++) {
- for (qsa=re->qmcsamplers[a].first; qsa; qsa=next) {
- next= qsa->next;
- QMC_freeSampler(qsa);
- }
-
- re->qmcsamplers[a].first= re->qmcsamplers[a].last= NULL;
- }
-
- MEM_freeN(re->qmcsamplers);
- re->qmcsamplers= NULL;
- }
-}
-
-static int adaptive_sample_variance(int samples, const float col[3], const float colsq[3], float thresh)
-{
- float var[3], mean[3];
-
- /* scale threshold just to give a bit more precision in input rather than dealing with
- * tiny tiny numbers in the UI */
- thresh /= 2;
-
- mean[0] = col[0] / (float)samples;
- mean[1] = col[1] / (float)samples;
- mean[2] = col[2] / (float)samples;
-
- var[0] = (colsq[0] / (float)samples) - (mean[0]*mean[0]);
- var[1] = (colsq[1] / (float)samples) - (mean[1]*mean[1]);
- var[2] = (colsq[2] / (float)samples) - (mean[2]*mean[2]);
-
- if ((var[0] * 0.4f < thresh) && (var[1] * 0.3f < thresh) && (var[2] * 0.6f < thresh))
- return 1;
- else
- return 0;
-}
-
-static int adaptive_sample_contrast_val(int samples, float prev, float val, float thresh)
-{
- /* if the last sample's contribution to the total value was below a small threshold
- * (i.e. the samples taken are very similar), then taking more samples that are probably
- * going to be the same is wasting effort */
- if (fabsf(prev / (float)(samples - 1) - val / (float)samples ) < thresh) {
- return 1;
- }
- else
- return 0;
-}
-
-static float get_avg_speed(ShadeInput *shi)
-{
- float pre_x, pre_y, post_x, post_y, speedavg;
-
- pre_x = (shi->winspeed[0] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[0];
- pre_y = (shi->winspeed[1] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[1];
- post_x = (shi->winspeed[2] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[2];
- post_y = (shi->winspeed[3] == PASS_VECTOR_MAX)?0.0f:shi->winspeed[3];
-
- speedavg = (sqrtf(pre_x * pre_x + pre_y * pre_y) + sqrtf(post_x * post_x + post_y * post_y)) / 2.0f;
-
- return speedavg;
-}
-
-/* ***************** main calls ************** */
-
-
-static void trace_refract(float col[4], ShadeInput *shi, ShadeResult *shr)
-{
- QMCSampler *qsa=NULL;
- int samp_type;
- int traflag=0;
-
- float samp3d[3], orthx[3], orthy[3];
- float v_refract[3], v_refract_new[3];
- float sampcol[4], colsq[4];
-
- float blur = pow3f(1.0f - shi->mat->gloss_tra);
- short max_samples = shi->mat->samp_gloss_tra;
- float adapt_thresh = shi->mat->adapt_thresh_tra;
-
- int samples=0;
-
- colsq[0] = colsq[1] = colsq[2] = 0.0;
- col[0] = col[1] = col[2] = 0.0;
- col[3]= shr->alpha;
-
- if (blur > 0.0f) {
- if (adapt_thresh != 0.0f) samp_type = SAMP_TYPE_HALTON;
- else samp_type = SAMP_TYPE_HAMMERSLEY;
-
- /* all samples are generated per pixel */
- qsa = get_thread_qmcsampler(&R, shi->thread, samp_type, max_samples);
- QMC_initPixel(qsa, shi->thread);
- }
- else
- max_samples = 1;
-
-
- while (samples < max_samples) {
- if (refraction(v_refract, shi->vn, shi->view, shi->ang)) {
- traflag |= RAY_INSIDE;
- }
- else {
- /* total external reflection can happen for materials with IOR < 1.0 */
- if ((shi->vlr->flag & R_SMOOTH))
- reflection(v_refract, shi->vn, shi->view, shi->facenor);
- else
- reflection_simple(v_refract, shi->vn, shi->view);
-
- /* can't blur total external reflection */
- max_samples = 1;
- }
-
- if (max_samples > 1) {
- /* get a quasi-random vector from a phong-weighted disc */
- QMC_samplePhong(samp3d, qsa, shi->thread, samples, blur);
-
- ortho_basis_v3v3_v3(orthx, orthy, v_refract);
- mul_v3_fl(orthx, samp3d[0]);
- mul_v3_fl(orthy, samp3d[1]);
-
- /* and perturb the refraction vector in it */
- add_v3_v3v3(v_refract_new, v_refract, orthx);
- add_v3_v3(v_refract_new, orthy);
-
- normalize_v3(v_refract_new);
- }
- else {
- /* no blurriness, use the original normal */
- copy_v3_v3(v_refract_new, v_refract);
- }
-
- sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f;
-
- traceray(shi, shr, shi->mat->ray_depth_tra, shi->co, v_refract_new, sampcol, shi->obi, shi->vlr, traflag);
-
- col[0] += sampcol[0];
- col[1] += sampcol[1];
- col[2] += sampcol[2];
- col[3] += sampcol[3];
-
- /* for variance calc */
- colsq[0] += sampcol[0]*sampcol[0];
- colsq[1] += sampcol[1]*sampcol[1];
- colsq[2] += sampcol[2]*sampcol[2];
-
- samples++;
-
- /* adaptive sampling */
- if (adapt_thresh < 1.0f && samples > max_samples/2) {
- if (adaptive_sample_variance(samples, col, colsq, adapt_thresh))
- break;
-
- /* if the pixel so far is very dark, we can get away with less samples */
- if ( (col[0] + col[1] + col[2])/3.0f/(float)samples < 0.01f )
- max_samples--;
- }
- }
-
- col[0] /= (float)samples;
- col[1] /= (float)samples;
- col[2] /= (float)samples;
- col[3] /= (float)samples;
-
- if (qsa)
- release_thread_qmcsampler(&R, shi->thread, qsa);
-}
-
-static void trace_reflect(float col[3], ShadeInput *shi, ShadeResult *shr, float fresnelfac)
-{
- QMCSampler *qsa=NULL;
- int samp_type;
-
- float samp3d[3], orthx[3], orthy[3];
- float v_nor_new[3], v_reflect[3];
- float sampcol[4], colsq[4];
-
- float blur = pow3f(1.0f - shi->mat->gloss_mir);
- short max_samples = shi->mat->samp_gloss_mir;
- float adapt_thresh = shi->mat->adapt_thresh_mir;
- float aniso = 1.0f - shi->mat->aniso_gloss_mir;
-
- int samples=0;
-
- col[0] = col[1] = col[2] = 0.0;
- colsq[0] = colsq[1] = colsq[2] = 0.0;
-
- if (blur > 0.0f) {
- if (adapt_thresh != 0.0f) samp_type = SAMP_TYPE_HALTON;
- else samp_type = SAMP_TYPE_HAMMERSLEY;
-
- /* all samples are generated per pixel */
- qsa = get_thread_qmcsampler(&R, shi->thread, samp_type, max_samples);
- QMC_initPixel(qsa, shi->thread);
- }
- else
- max_samples = 1;
-
- while (samples < max_samples) {
-
- if (max_samples > 1) {
- /* get a quasi-random vector from a phong-weighted disc */
- QMC_samplePhong(samp3d, qsa, shi->thread, samples, blur);
-
- /* find the normal's perpendicular plane, blurring along tangents
- * if tangent shading enabled */
- if (shi->mat->mode & (MA_TANGENT_V)) {
- cross_v3_v3v3(orthx, shi->vn, shi->tang); // bitangent
- copy_v3_v3(orthy, shi->tang);
- mul_v3_fl(orthx, samp3d[0]);
- mul_v3_fl(orthy, samp3d[1]*aniso);
- }
- else {
- ortho_basis_v3v3_v3(orthx, orthy, shi->vn);
- mul_v3_fl(orthx, samp3d[0]);
- mul_v3_fl(orthy, samp3d[1]);
- }
-
- /* and perturb the normal in it */
- add_v3_v3v3(v_nor_new, shi->vn, orthx);
- add_v3_v3(v_nor_new, orthy);
- normalize_v3(v_nor_new);
- }
- else {
- /* no blurriness, use the original normal */
- copy_v3_v3(v_nor_new, shi->vn);
- }
-
- if ((shi->vlr->flag & R_SMOOTH))
- reflection(v_reflect, v_nor_new, shi->view, shi->facenor);
- else
- reflection_simple(v_reflect, v_nor_new, shi->view);
-
- sampcol[0]= sampcol[1]= sampcol[2]= sampcol[3]= 0.0f;
-
- traceray(shi, shr, shi->mat->ray_depth, shi->co, v_reflect, sampcol, shi->obi, shi->vlr, 0);
-
-
- col[0] += sampcol[0];
- col[1] += sampcol[1];
- col[2] += sampcol[2];
-
- /* for variance calc */
- colsq[0] += sampcol[0]*sampcol[0];
- colsq[1] += sampcol[1]*sampcol[1];
- colsq[2] += sampcol[2]*sampcol[2];
-
- samples++;
-
- /* adaptive sampling */
- if (adapt_thresh > 0.0f && samples > max_samples/3) {
- if (adaptive_sample_variance(samples, col, colsq, adapt_thresh))
- break;
-
- /* if the pixel so far is very dark, we can get away with less samples */
- if ( (col[0] + col[1] + col[2])/3.0f/(float)samples < 0.01f )
- max_samples--;
-
- /* reduce samples when reflection is dim due to low ray mirror blend value or fresnel factor
- * and when reflection is blurry */
- if (fresnelfac < 0.1f * (blur+1)) {
- max_samples--;
-
- /* even more for very dim */
- if (fresnelfac < 0.05f * (blur+1))
- max_samples--;
- }
- }
- }
-
- col[0] /= (float)samples;
- col[1] /= (float)samples;
- col[2] /= (float)samples;
-
- if (qsa)
- release_thread_qmcsampler(&R, shi->thread, qsa);
-}
-
-/* extern call from render loop */
-void ray_trace(ShadeInput *shi, ShadeResult *shr)
-{
- float f1, fr, fg, fb;
- float mircol[4], tracol[4];
- float diff[3];
- int do_tra, do_mir;
-
- do_tra = ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha != 1.0f && (shi->depth <= shi->mat->ray_depth_tra));
- do_mir = ((shi->mat->mode & MA_RAYMIRROR) && shi->ray_mirror != 0.0f && (shi->depth <= shi->mat->ray_depth));
-
- /* raytrace mirror and refract like to separate the spec color */
- if (shi->combinedflag & SCE_PASS_SPEC)
- sub_v3_v3v3(diff, shr->combined, shr->spec);
- else
- copy_v3_v3(diff, shr->combined);
-
- if (do_tra) {
- float olddiff[3], f;
-
- trace_refract(tracol, shi, shr);
-
- f= shr->alpha; f1= 1.0f-f;
- fr= 1.0f+ shi->mat->filter*(shi->r-1.0f);
- fg= 1.0f+ shi->mat->filter*(shi->g-1.0f);
- fb= 1.0f+ shi->mat->filter*(shi->b-1.0f);
-
- /* for refract pass */
- copy_v3_v3(olddiff, diff);
-
- diff[0]= f*diff[0] + f1*fr*tracol[0];
- diff[1]= f*diff[1] + f1*fg*tracol[1];
- diff[2]= f*diff[2] + f1*fb*tracol[2];
-
- if (shi->passflag & SCE_PASS_REFRACT)
- sub_v3_v3v3(shr->refr, diff, olddiff);
-
- if (!(shi->combinedflag & SCE_PASS_REFRACT))
- sub_v3_v3v3(diff, diff, shr->refr);
-
- shr->alpha = min_ff(1.0f, tracol[3]);
- }
-
- if (do_mir) {
- const float i= shi->ray_mirror*fresnel_fac(shi->view, shi->vn, shi->mat->fresnel_mir_i, shi->mat->fresnel_mir);
- if (i!=0.0f) {
-
- trace_reflect(mircol, shi, shr, i);
-
- fr= i*shi->mirr;
- fg= i*shi->mirg;
- fb= i*shi->mirb;
-
- if (shi->passflag & SCE_PASS_REFLECT) {
- /* mirror pass is not blocked out with spec */
- shr->refl[0]= fr*mircol[0] - fr*diff[0];
- shr->refl[1]= fg*mircol[1] - fg*diff[1];
- shr->refl[2]= fb*mircol[2] - fb*diff[2];
- }
-
- if (shi->combinedflag & SCE_PASS_REFLECT) {
- /* values in shr->spec can be greater than 1.0.
- * In this case the mircol uses a zero blending factor, so ignoring it is ok.
- * Fixes bug #18837 - when the spec is higher then 1.0,
- * diff can become a negative color - Campbell */
-
- f1= 1.0f-i;
-
- diff[0] *= f1;
- diff[1] *= f1;
- diff[2] *= f1;
-
- if (shr->spec[0]<1.0f) diff[0] += mircol[0] * (fr*(1.0f-shr->spec[0]));
- if (shr->spec[1]<1.0f) diff[1] += mircol[1] * (fg*(1.0f-shr->spec[1]));
- if (shr->spec[2]<1.0f) diff[2] += mircol[2] * (fb*(1.0f-shr->spec[2]));
- }
- }
- }
- /* put back together */
- if (shi->combinedflag & SCE_PASS_SPEC)
- add_v3_v3v3(shr->combined, diff, shr->spec);
- else
- copy_v3_v3(shr->combined, diff);
-}
-
-/* color 'shadfac' passes through 'col' with alpha and filter */
-/* filter is only applied on alpha defined transparent part */
-static void addAlphaLight(float shadfac[4], const float col[3], float alpha, float filter)
-{
- float fr, fg, fb;
-
- fr= 1.0f+ filter*(col[0]-1.0f);
- fg= 1.0f+ filter*(col[1]-1.0f);
- fb= 1.0f+ filter*(col[2]-1.0f);
-
- shadfac[0]= alpha*col[0] + fr*(1.0f-alpha)*shadfac[0];
- shadfac[1]= alpha*col[1] + fg*(1.0f-alpha)*shadfac[1];
- shadfac[2]= alpha*col[2] + fb*(1.0f-alpha)*shadfac[2];
-
- shadfac[3]= (1.0f-alpha)*shadfac[3];
-}
-
-static void ray_trace_shadow_tra(Isect *is, ShadeInput *origshi, int depth, int traflag, float col[4])
-{
- /* ray to lamp, find first face that intersects, check alpha properties,
- * if it has col[3]>0.0f continue. so exit when alpha is full */
- const float initial_dist = is->dist;
-
- if (RE_rayobject_raycast(R.raytree, is)) {
- /* Warning regarding initializing to zero's, This is not that nice,
- * and possibly a bit slow for every ray, however some variables were
- * not initialized properly in, unless using
- * shade_input_initialize(...), we need to zero them. */
- ShadeInput shi= {NULL};
- /* end warning! - Campbell */
-
- ShadeResult shr;
-
- /* we got a face */
-
- shi.depth= origshi->depth + 1; /* only used to indicate tracing */
- shi.mask= origshi->mask;
- shi.thread= origshi->thread;
- shi.passflag= SCE_PASS_COMBINED;
- shi.combinedflag= 0xFFFFFF; /* ray trace does all options */
-
- shi.xs= origshi->xs;
- shi.ys= origshi->ys;
- shi.do_manage= origshi->do_manage;
- shi.lay= origshi->lay;
- shi.nodes= origshi->nodes;
-
- RE_instance_rotate_ray_restore(origshi->obi, is);
-
- shade_ray(is, &shi, &shr);
- if (shi.mat->material_type == MA_TYPE_SURFACE) {
- const float d = (shi.mat->mode & MA_RAYTRANSP) ?
- ((traflag & RAY_TRA) ? shade_by_transmission(is, &shi, &shr) : 1.0f) :
- 0.0f;
- /* mix colors based on shadfac (rgb + amount of light factor) */
- addAlphaLight(col, shr.diff, shr.alpha, d*shi.mat->filter);
- }
- else if (shi.mat->material_type == MA_TYPE_VOLUME) {
- const float a = col[3];
-
- col[0] = a*col[0] + shr.alpha*shr.combined[0];
- col[1] = a*col[1] + shr.alpha*shr.combined[1];
- col[2] = a*col[2] + shr.alpha*shr.combined[2];
-
- col[3] = (1.0f - shr.alpha)*a;
- }
-
- if (depth>0 && col[3]>0.0f) {
-
- /* adapt isect struct */
- copy_v3_v3(is->start, shi.co);
- is->dist = initial_dist-is->dist;
- is->orig.ob = shi.obi;
- is->orig.face = shi.vlr;
-
- ray_trace_shadow_tra(is, origshi, depth-1, traflag | RAY_TRA, col);
- }
-
- RE_RC_MERGE(&origshi->raycounter, &shi.raycounter);
- }
-}
-
-
-/* aolight: function to create random unit sphere vectors for total random sampling */
-
-/* calc distributed spherical energy */
-static void DS_energy(float *sphere, int tot, float vec[3])
-{
- float *fp, fac, force[3], res[3];
- int a;
-
- res[0]= res[1]= res[2]= 0.0f;
-
- for (a=0, fp=sphere; a<tot; a++, fp+=3) {
- sub_v3_v3v3(force, vec, fp);
- fac = dot_v3v3(force, force);
- if (fac!=0.0f) {
- fac= 1.0f/fac;
- res[0]+= fac*force[0];
- res[1]+= fac*force[1];
- res[2]+= fac*force[2];
- }
- }
-
- mul_v3_fl(res, 0.5);
- add_v3_v3(vec, res);
- normalize_v3(vec);
-
-}
-
-/* called from convertBlenderScene.c */
-/* creates an equally distributed spherical sample pattern */
-/* and allocates threadsafe memory */
-void init_ao_sphere(Render *re, World *wrld)
-{
- /* fixed random */
- const int num_threads = re->r.threads;
- RNG *rng;
- float *fp;
- int a, tot, iter= 16;
-
- /* we make twice the amount of samples, because only a hemisphere is used */
- tot= 2*wrld->aosamp*wrld->aosamp;
-
- wrld->aosphere= MEM_mallocN(3*tot*sizeof(float), "AO sphere");
- rng = BLI_rng_new_srandom(tot);
-
- /* init */
- fp= wrld->aosphere;
- for (a=0; a<tot; a++, fp+= 3) {
- BLI_rng_get_float_unit_v3(rng, fp);
- }
-
- while (iter--) {
- for (a=0, fp= wrld->aosphere; a<tot; a++, fp+= 3) {
- DS_energy(wrld->aosphere, tot, fp);
- }
- }
-
- /* tables */
- wrld->aotables= MEM_mallocN(num_threads*3*tot*sizeof(float), "AO tables");
-
- BLI_rng_free(rng);
-}
-
-/* give per thread a table, we have to compare xs ys because of way OSA works... */
-static float *threadsafe_table_sphere(int test, int thread, int xs, int ys, int tot)
-{
- static int xso[BLENDER_MAX_THREADS], yso[BLENDER_MAX_THREADS];
- static int firsttime= 1;
-
- if (firsttime) {
- memset(xso, 255, sizeof(xso));
- memset(yso, 255, sizeof(yso));
- firsttime= 0;
- }
-
- if (xs==xso[thread] && ys==yso[thread]) return R.wrld.aotables+ thread*tot*3;
- if (test) return NULL;
- xso[thread]= xs; yso[thread]= ys;
- return R.wrld.aotables+ thread*tot*3;
-}
-
-static float *sphere_sampler(int type, int resol, int thread, int xs, int ys, int reset)
-{
- int tot;
- float *vec;
-
- tot= 2*resol*resol;
-
- if (type & WO_AORNDSMP) {
- /* total random sampling. NOT THREADSAFE! (should be removed, is not useful) */
- RNG *rng = BLI_rng_new(BLI_thread_rand(thread));
- float *sphere;
- int a;
-
- /* always returns table */
- sphere= threadsafe_table_sphere(0, thread, xs, ys, tot);
-
- vec= sphere;
- for (a=0; a<tot; a++, vec+=3) {
- BLI_rng_get_float_unit_v3(rng, vec);
- }
-
- BLI_rng_free(rng);
-
- return sphere;
- }
- else {
- float *sphere;
- float *vec1;
-
- /* returns table if xs and ys were equal to last call, and not resetting */
- sphere= (reset)? NULL: threadsafe_table_sphere(1, thread, xs, ys, tot);
- if (sphere==NULL) {
- float cosfi, sinfi, cost, sint;
- float ang;
- int a;
-
- sphere= threadsafe_table_sphere(0, thread, xs, ys, tot);
-
- /* random rotation */
- ang = BLI_thread_frand(thread);
- sinfi = sinf(ang); cosfi = cosf(ang);
- ang = BLI_thread_frand(thread);
- sint = sinf(ang); cost = cosf(ang);
-
- vec= R.wrld.aosphere;
- vec1= sphere;
- for (a=0; a<tot; a++, vec+=3, vec1+=3) {
- vec1[0]= cost*cosfi*vec[0] - sinfi*vec[1] + sint*cosfi*vec[2];
- vec1[1]= cost*sinfi*vec[0] + cosfi*vec[1] + sint*sinfi*vec[2];
- vec1[2]= -sint*vec[0] + cost*vec[2];
- }
- }
- return sphere;
- }
-}
-
-static void ray_ao_qmc(ShadeInput *shi, float ao[3], float env[3])
-{
- Isect isec;
- RayHint point_hint;
- QMCSampler *qsa=NULL;
- float samp3d[3];
- float up[3], side[3], dir[3], nrm[3];
-
- float maxdist = R.wrld.aodist;
- float fac=0.0f, prev=0.0f;
- float adapt_thresh = R.wrld.ao_adapt_thresh;
- float adapt_speed_fac = R.wrld.ao_adapt_speed_fac;
-
- int samples=0;
- int max_samples = R.wrld.aosamp*R.wrld.aosamp;
-
- float dxyview[3], skyadded=0;
- int envcolor;
-
- RE_RC_INIT(isec, *shi);
- isec.orig.ob = shi->obi;
- isec.orig.face = shi->vlr;
- isec.check = RE_CHECK_VLR_NON_SOLID_MATERIAL;
- isec.skip = RE_SKIP_VLR_NEIGHBOUR;
- isec.hint = NULL;
-
- isec.hit.ob = NULL;
- isec.hit.face = NULL;
-
- isec.last_hit = NULL;
-
- isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW;
- isec.lay= -1;
-
- copy_v3_v3(isec.start, shi->co);
-
- RE_instance_rotate_ray_start(shi->obi, &isec);
-
- RE_rayobject_hint_bb(R.raytree, &point_hint, isec.start, isec.start);
- isec.hint = &point_hint;
-
- zero_v3(ao);
- zero_v3(env);
-
- /* prevent sky colors to be added for only shadow (shadow becomes alpha) */
- envcolor= R.wrld.aocolor;
- if (shi->mat->mode & MA_ONLYSHADOW)
- envcolor= WO_AOPLAIN;
-
- if (envcolor == WO_AOSKYTEX) {
- dxyview[0]= 1.0f/(float)R.wrld.aosamp;
- dxyview[1]= 1.0f/(float)R.wrld.aosamp;
- dxyview[2]= 0.0f;
- }
-
- if (shi->vlr->flag & R_SMOOTH) {
- copy_v3_v3(nrm, shi->vn);
- }
- else {
- copy_v3_v3(nrm, shi->facenor);
- }
-
- ortho_basis_v3v3_v3(up, side, nrm);
-
- /* sampling init */
- if (R.wrld.ao_samp_method==WO_AOSAMP_HALTON) {
- float speedfac;
-
- speedfac = get_avg_speed(shi) * adapt_speed_fac;
- CLAMP(speedfac, 1.0f, 1000.0f);
- max_samples /= speedfac;
- if (max_samples < 5) max_samples = 5;
-
- qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HALTON, max_samples);
- }
- else if (R.wrld.ao_samp_method==WO_AOSAMP_HAMMERSLEY)
- qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples);
-
- QMC_initPixel(qsa, shi->thread);
-
- while (samples < max_samples) {
-
- /* sampling, returns quasi-random vector in unit hemisphere */
- QMC_sampleHemi(samp3d, qsa, shi->thread, samples);
-
- dir[0] = (samp3d[0]*up[0] + samp3d[1]*side[0] + samp3d[2]*nrm[0]);
- dir[1] = (samp3d[0]*up[1] + samp3d[1]*side[1] + samp3d[2]*nrm[1]);
- dir[2] = (samp3d[0]*up[2] + samp3d[1]*side[2] + samp3d[2]*nrm[2]);
-
- normalize_v3(dir);
-
- isec.dir[0] = -dir[0];
- isec.dir[1] = -dir[1];
- isec.dir[2] = -dir[2];
- isec.dist = maxdist;
-
- RE_instance_rotate_ray_dir(shi->obi, &isec);
-
- prev = fac;
-
- if (RE_rayobject_raycast(R.raytree, &isec)) {
- if (R.wrld.aomode & WO_AODIST) fac+= expf(-isec.dist*R.wrld.aodistfac);
- else fac+= 1.0f;
- }
- else if (envcolor!=WO_AOPLAIN) {
- float skycol[4];
- float view[3];
-
- view[0]= -dir[0];
- view[1]= -dir[1];
- view[2]= -dir[2];
- normalize_v3(view);
-
- if (envcolor==WO_AOSKYCOL) {
- const float skyfac= 0.5f * (1.0f + dot_v3v3(view, R.grvec));
- env[0]+= (1.0f-skyfac)*R.wrld.horr + skyfac*R.wrld.zenr;
- env[1]+= (1.0f-skyfac)*R.wrld.horg + skyfac*R.wrld.zeng;
- env[2]+= (1.0f-skyfac)*R.wrld.horb + skyfac*R.wrld.zenb;
- }
- else { /* WO_AOSKYTEX */
- shadeSkyView(skycol, isec.start, view, dxyview, shi->thread);
- shadeSunView(skycol, shi->view);
- env[0]+= skycol[0];
- env[1]+= skycol[1];
- env[2]+= skycol[2];
- }
- skyadded++;
- }
-
- samples++;
-
- if (qsa && qsa->type == SAMP_TYPE_HALTON) {
- /* adaptive sampling - consider samples below threshold as in shadow (or vice versa) and exit early */
- if (adapt_thresh > 0.0f && (samples > max_samples/2) ) {
-
- if (adaptive_sample_contrast_val(samples, prev, fac, adapt_thresh)) {
- break;
- }
- }
- }
- }
-
- /* average color times distances/hits formula */
- ao[0]= ao[1]= ao[2]= 1.0f - fac/(float)samples;
-
- if (envcolor!=WO_AOPLAIN && skyadded)
- mul_v3_fl(env, (1.0f - fac/(float)samples)/((float)skyadded));
- else
- copy_v3_v3(env, ao);
-
- if (qsa)
- release_thread_qmcsampler(&R, shi->thread, qsa);
-}
-
-/* extern call from shade_lamp_loop, ambient occlusion calculus */
-static void ray_ao_spheresamp(ShadeInput *shi, float ao[3], float env[3])
-{
- Isect isec;
- RayHint point_hint;
- float *vec, *nrm, bias, sh=0.0f;
- float maxdist = R.wrld.aodist;
- float dxyview[3];
- int j= -1, tot, actual=0, skyadded=0, envcolor, resol= R.wrld.aosamp;
-
- RE_RC_INIT(isec, *shi);
- isec.orig.ob = shi->obi;
- isec.orig.face = shi->vlr;
- isec.check = RE_CHECK_VLR_RENDER;
- isec.skip = RE_SKIP_VLR_NEIGHBOUR;
- isec.hint = NULL;
-
- isec.hit.ob = NULL;
- isec.hit.face = NULL;
-
- isec.last_hit = NULL;
-
- isec.mode= (R.wrld.aomode & WO_AODIST)?RE_RAY_SHADOW_TRA:RE_RAY_SHADOW;
- isec.lay= -1;
-
- copy_v3_v3(isec.start, shi->co);
- RE_instance_rotate_ray_start(shi->obi, &isec);
-
- RE_rayobject_hint_bb(R.raytree, &point_hint, isec.start, isec.start);
- isec.hint = &point_hint;
-
- zero_v3(ao);
- zero_v3(env);
-
- /* bias prevents smoothed faces to appear flat */
- if (shi->vlr->flag & R_SMOOTH) {
- bias= R.wrld.aobias;
- nrm= shi->vn;
- }
- else {
- bias= 0.0f;
- nrm= shi->facenor;
- }
-
- /* prevent sky colors to be added for only shadow (shadow becomes alpha) */
- envcolor= R.wrld.aocolor;
- if (shi->mat->mode & MA_ONLYSHADOW)
- envcolor= WO_AOPLAIN;
-
- if (resol>32) resol= 32;
-
- /* get sphere samples. for faces we get the same samples for sample x/y values,
- * for strand render we always require a new sampler because x/y are not set */
- vec= sphere_sampler(R.wrld.aomode, resol, shi->thread, shi->xs, shi->ys, shi->strand != NULL);
-
- /* warning: since we use full sphere now, and dotproduct is below, we do twice as much */
- tot= 2*resol*resol;
-
- if (envcolor == WO_AOSKYTEX) {
- dxyview[0]= 1.0f/(float)resol;
- dxyview[1]= 1.0f/(float)resol;
- dxyview[2]= 0.0f;
- }
-
- while (tot--) {
-
- if (dot_v3v3(vec, nrm) > bias) {
- /* only ao samples for mask */
- if (R.r.mode & R_OSA) {
- j++;
- if (j==R.osa) j= 0;
- if (!(shi->mask & (1<<j))) {
- vec+=3;
- continue;
- }
- }
-
- actual++;
-
- /* always set start/vec/dist */
- isec.dir[0] = -vec[0];
- isec.dir[1] = -vec[1];
- isec.dir[2] = -vec[2];
- isec.dist = maxdist;
-
- RE_instance_rotate_ray_dir(shi->obi, &isec);
-
- /* do the trace */
- if (RE_rayobject_raycast(R.raytree, &isec)) {
- if (R.wrld.aomode & WO_AODIST) sh+= expf(-isec.dist*R.wrld.aodistfac);
- else sh+= 1.0f;
- }
- else if (envcolor!=WO_AOPLAIN) {
- float skycol[4];
- float view[3];
-
- view[0]= -vec[0];
- view[1]= -vec[1];
- view[2]= -vec[2];
- normalize_v3(view);
-
- if (envcolor==WO_AOSKYCOL) {
- const float fac = 0.5f * (1.0f + dot_v3v3(view, R.grvec));
- env[0]+= (1.0f-fac)*R.wrld.horr + fac*R.wrld.zenr;
- env[1]+= (1.0f-fac)*R.wrld.horg + fac*R.wrld.zeng;
- env[2]+= (1.0f-fac)*R.wrld.horb + fac*R.wrld.zenb;
- }
- else { /* WO_AOSKYTEX */
- shadeSkyView(skycol, isec.start, view, dxyview, shi->thread);
- shadeSunView(skycol, shi->view);
- env[0]+= skycol[0];
- env[1]+= skycol[1];
- env[2]+= skycol[2];
- }
- skyadded++;
- }
- }
- /* samples */
- vec+= 3;
- }
-
- if (actual==0) sh= 1.0f;
- else sh = 1.0f - sh/((float)actual);
-
- /* average color times distances/hits formula */
- ao[0]= ao[1]= ao[2]= sh;
-
- if (envcolor!=WO_AOPLAIN && skyadded)
- mul_v3_fl(env, sh/((float)skyadded));
- else
- copy_v3_v3(env, ao);
-}
-
-void ray_ao(ShadeInput *shi, float ao[3], float env[3])
-{
- /* Unfortunately, the unusual way that the sphere sampler calculates roughly twice as many
- * samples as are actually traced, and skips them based on bias and OSA settings makes it very difficult
- * to reuse code between these two functions. This is the easiest way I can think of to do it
- * --broken */
- if (ELEM(R.wrld.ao_samp_method, WO_AOSAMP_HAMMERSLEY, WO_AOSAMP_HALTON))
- ray_ao_qmc(shi, ao, env);
- else if (R.wrld.ao_samp_method == WO_AOSAMP_CONSTANT)
- ray_ao_spheresamp(shi, ao, env);
-}
-
-static void ray_shadow_jittered_coords(ShadeInput *shi, int max, float jitco[RE_MAX_OSA][3], int *totjitco)
-{
- /* magic numbers for reordering sample positions to give better
- * results with adaptive sample, when it usually only takes 4 samples */
- int order8[8] = {0, 1, 5, 6, 2, 3, 4, 7};
- int order11[11] = {1, 3, 8, 10, 0, 2, 4, 5, 6, 7, 9};
- int order16[16] = {1, 3, 9, 12, 0, 6, 7, 8, 13, 2, 4, 5, 10, 11, 14, 15};
- int count = count_mask(shi->mask);
-
- /* for better antialising shadow samples are distributed over the subpixel
- * sample coordinates, this only works for raytracing depth 0 though */
- if (!shi->strand && shi->depth == 0 && count > 1 && count <= max) {
- float xs, ys, zs, view[3];
- int samp, ordsamp, tot= 0;
-
- for (samp=0; samp<R.osa; samp++) {
- if (R.osa == 8) ordsamp = order8[samp];
- else if (R.osa == 11) ordsamp = order11[samp];
- else if (R.osa == 16) ordsamp = order16[samp];
- else ordsamp = samp;
-
- if (shi->mask & (1<<ordsamp)) {
- /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */
- xs= (float)shi->scanco[0] + R.jit[ordsamp][0] + 0.5f;
- ys= (float)shi->scanco[1] + R.jit[ordsamp][1] + 0.5f;
- zs= shi->scanco[2];
-
- shade_input_calc_viewco(shi, xs, ys, zs, view, NULL, jitco[tot], NULL, NULL);
- tot++;
- }
- }
-
- *totjitco= tot;
- }
- else {
- copy_v3_v3(jitco[0], shi->co);
- *totjitco= 1;
- }
-}
-
-static void ray_shadow_qmc(ShadeInput *shi, LampRen *lar, const float lampco[3], float shadfac[4], Isect *isec)
-{
- QMCSampler *qsa=NULL;
- int samples=0;
- float samp3d[3];
-
- float fac=0.0f, vec[3], end[3];
- float colsq[4];
- float adapt_thresh = lar->adapt_thresh;
- int min_adapt_samples=4, max_samples = lar->ray_totsamp;
- float start[3];
- bool do_soft = true, full_osa = false;
- int i;
-
- float min[3], max[3];
- RayHint bb_hint;
-
- float jitco[RE_MAX_OSA][3];
- int totjitco;
-
- colsq[0] = colsq[1] = colsq[2] = 0.0;
- if (isec->mode==RE_RAY_SHADOW_TRA) {
- shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 0.0f;
- }
- else
- shadfac[3]= 1.0f;
-
- if (lar->ray_totsamp < 2) do_soft = false;
- if ((R.r.mode & R_OSA) && (R.osa > 0) && (shi->vlr->flag & R_FULL_OSA)) full_osa = true;
-
- if (full_osa) {
- if (do_soft) max_samples = max_samples/R.osa + 1;
- else max_samples = 1;
- }
- else {
- if (do_soft) max_samples = lar->ray_totsamp;
- else if (shi->depth == 0) max_samples = (R.osa > 4)?R.osa:5;
- else max_samples = 1;
- }
-
- ray_shadow_jittered_coords(shi, max_samples, jitco, &totjitco);
-
- /* sampling init */
- if (lar->ray_samp_method==LA_SAMP_HALTON)
- qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HALTON, max_samples);
- else if (lar->ray_samp_method==LA_SAMP_HAMMERSLEY)
- qsa = get_thread_qmcsampler(&R, shi->thread, SAMP_TYPE_HAMMERSLEY, max_samples);
-
- QMC_initPixel(qsa, shi->thread);
-
- INIT_MINMAX(min, max);
- for (i = 0; i < totjitco; i++) {
- minmax_v3v3_v3(min, max, jitco[i]);
- }
- if (shi->obi->flag & R_ENV_TRANSFORMED) {
- mul_m4_v3(shi->obi->imat, min);
- mul_m4_v3(shi->obi->imat, max);
- }
- RE_rayobject_hint_bb(R.raytree, &bb_hint, min, max);
-
- isec->hint = &bb_hint;
- isec->check = RE_CHECK_VLR_RENDER;
- isec->skip = RE_SKIP_VLR_NEIGHBOUR;
- copy_v3_v3(vec, lampco);
-
- while (samples < max_samples) {
-
- isec->orig.ob = shi->obi;
- isec->orig.face = shi->vlr;
-
- /* manually jitter the start shading co-ord per sample
- * based on the pre-generated OSA texture sampling offsets,
- * for anti-aliasing sharp shadow edges. */
- copy_v3_v3(start, jitco[samples % totjitco]);
-
- if (do_soft) {
- /* sphere shadow source */
- if (lar->type == LA_LOCAL) {
- float ru[3], rv[3], v[3], s[3];
-
- /* calc tangent plane vectors */
- sub_v3_v3v3(v, start, lampco);
- normalize_v3(v);
- ortho_basis_v3v3_v3(ru, rv, v);
-
- /* sampling, returns quasi-random vector in area_size disc */
- QMC_sampleDisc(samp3d, qsa, shi->thread, samples, lar->area_size);
-
- /* distribute disc samples across the tangent plane */
- s[0] = samp3d[0]*ru[0] + samp3d[1]*rv[0];
- s[1] = samp3d[0]*ru[1] + samp3d[1]*rv[1];
- s[2] = samp3d[0]*ru[2] + samp3d[1]*rv[2];
-
- copy_v3_v3(samp3d, s);
- }
- else {
- /* sampling, returns quasi-random vector in [sizex,sizey]^2 plane */
- QMC_sampleRect(samp3d, qsa, shi->thread, samples, lar->area_size, lar->area_sizey);
-
- /* align samples to lamp vector */
- mul_m3_v3(lar->mat, samp3d);
- }
- end[0] = vec[0]+samp3d[0];
- end[1] = vec[1]+samp3d[1];
- end[2] = vec[2]+samp3d[2];
- }
- else {
- copy_v3_v3(end, vec);
- }
-
- if (shi->strand) {
- /* bias away somewhat to avoid self intersection */
- float jitbias= 0.5f*(len_v3(shi->dxco) + len_v3(shi->dyco));
- float v[3];
-
- sub_v3_v3v3(v, start, end);
- normalize_v3(v);
-
- start[0] -= jitbias*v[0];
- start[1] -= jitbias*v[1];
- start[2] -= jitbias*v[2];
- }
-
- copy_v3_v3(isec->start, start);
- sub_v3_v3v3(isec->dir, end, start);
- isec->dist = normalize_v3(isec->dir);
-
- RE_instance_rotate_ray(shi->obi, isec);
-
- /* trace the ray */
- if (isec->mode==RE_RAY_SHADOW_TRA) {
- float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-
- ray_trace_shadow_tra(isec, shi, DEPTH_SHADOW_TRA, 0, col);
- shadfac[0] += col[0];
- shadfac[1] += col[1];
- shadfac[2] += col[2];
- shadfac[3] += col[3];
-
- /* for variance calc */
- colsq[0] += col[0]*col[0];
- colsq[1] += col[1]*col[1];
- colsq[2] += col[2]*col[2];
- }
- else {
- if ( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f;
- }
-
- samples++;
-
- if (lar->ray_samp_method == LA_SAMP_HALTON) {
-
- /* adaptive sampling - consider samples below threshold as in shadow (or vice versa) and exit early */
- if ((max_samples > min_adapt_samples) && (adapt_thresh > 0.0f) && (samples > max_samples / 3)) {
- if (isec->mode==RE_RAY_SHADOW_TRA) {
- if ((shadfac[3] / samples > (1.0f-adapt_thresh)) || (shadfac[3] / samples < adapt_thresh))
- break;
- else if (adaptive_sample_variance(samples, shadfac, colsq, adapt_thresh))
- break;
- }
- else {
- if ((fac / samples > (1.0f-adapt_thresh)) || (fac / samples < adapt_thresh))
- break;
- }
- }
- }
- }
-
- if (isec->mode==RE_RAY_SHADOW_TRA) {
- shadfac[0] /= samples;
- shadfac[1] /= samples;
- shadfac[2] /= samples;
- shadfac[3] /= samples;
- }
- else
- shadfac[3]= 1.0f-fac/samples;
-
- if (qsa)
- release_thread_qmcsampler(&R, shi->thread, qsa);
-}
-
-static void ray_shadow_jitter(ShadeInput *shi, LampRen *lar, const float lampco[3], float shadfac[4], Isect *isec)
-{
- /* area soft shadow */
- const float *jitlamp;
- float fac=0.0f, div=0.0f, vec[3];
- int a, j= -1, mask;
- RayHint point_hint;
-
- if (isec->mode==RE_RAY_SHADOW_TRA) {
- shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 0.0f;
- }
- else shadfac[3]= 1.0f;
-
- fac= 0.0f;
- jitlamp= give_jitter_plane(lar, shi->thread, shi->xs, shi->ys);
-
- a= lar->ray_totsamp;
-
- /* this correction to make sure we always take at least 1 sample */
- mask= shi->mask;
- if (a==4) mask |= (mask>>4)|(mask>>8);
- else if (a==9) mask |= (mask>>9);
-
- copy_v3_v3(isec->start, shi->co);
- RE_instance_rotate_ray_start(shi->obi, isec);
-
- isec->orig.ob = shi->obi;
- isec->orig.face = shi->vlr;
- RE_rayobject_hint_bb(R.raytree, &point_hint, isec->start, isec->start);
- isec->hint = &point_hint;
-
- while (a--) {
-
- if (R.r.mode & R_OSA) {
- j++;
- if (j>=R.osa) j= 0;
- if (!(mask & (1<<j))) {
- jitlamp+= 2;
- continue;
- }
- }
-
- vec[0]= jitlamp[0];
- vec[1]= jitlamp[1];
- vec[2]= 0.0f;
- mul_m3_v3(lar->mat, vec);
-
- /* set start and vec */
- isec->dir[0] = vec[0]+lampco[0]-shi->co[0];
- isec->dir[1] = vec[1]+lampco[1]-shi->co[1];
- isec->dir[2] = vec[2]+lampco[2]-shi->co[2];
-
- RE_instance_rotate_ray_dir(shi->obi, isec);
-
- isec->dist = 1.0f;
- isec->check = RE_CHECK_VLR_RENDER;
- isec->skip = RE_SKIP_VLR_NEIGHBOUR;
-
- if (isec->mode==RE_RAY_SHADOW_TRA) {
- /* isec.col is like shadfac, so defines amount of light (0.0 is full shadow) */
- float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-
- ray_trace_shadow_tra(isec, shi, DEPTH_SHADOW_TRA, 0, col);
- shadfac[0] += col[0];
- shadfac[1] += col[1];
- shadfac[2] += col[2];
- shadfac[3] += col[3];
- }
- else if ( RE_rayobject_raycast(R.raytree, isec) ) fac+= 1.0f;
-
- div+= 1.0f;
- jitlamp+= 2;
- }
-
- if (isec->mode==RE_RAY_SHADOW_TRA) {
- shadfac[0] /= div;
- shadfac[1] /= div;
- shadfac[2] /= div;
- shadfac[3] /= div;
- }
- else {
- /* sqrt makes nice umbra effect */
- if (lar->ray_samp_type & LA_SAMP_UMBRA)
- shadfac[3] = sqrtf(1.0f - fac / div);
- else
- shadfac[3] = 1.0f - fac / div;
- }
-}
-/* extern call from shade_lamp_loop */
-void ray_shadow(ShadeInput *shi, LampRen *lar, float shadfac[4])
-{
- Isect isec;
- float lampco[3];
-
- /* setup isec */
- RE_RC_INIT(isec, *shi);
- if (shi->mat->mode & MA_SHADOW_TRA) isec.mode= RE_RAY_SHADOW_TRA;
- else isec.mode= RE_RAY_SHADOW;
- isec.hint = NULL;
-
- if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW))
- isec.lay= lar->lay;
- else
- isec.lay= -1;
-
- /* only when not mir tracing, first hit optimm */
- if (shi->depth==0) {
- isec.last_hit = lar->last_hit[shi->thread];
- }
- else {
- isec.last_hit = NULL;
- }
-
- if (lar->type==LA_SUN || lar->type==LA_HEMI) {
- /* jitter and QMC sampling add a displace vector to the lamp position
- * that's incorrect because a SUN lamp does not has an exact position
- * and the displace should be done at the ray vector instead of the
- * lamp position.
- * This is easily verified by noticing that shadows of SUN lights change
- * with the scene BB.
- *
- * This was detected during SoC 2009 - Raytrace Optimization, but to keep
- * consistency with older render code it wasn't removed.
- *
- * If the render code goes through some recode/serious bug-fix then this
- * is something to consider!
- */
- lampco[0]= shi->co[0] - R.maxdist*lar->vec[0];
- lampco[1]= shi->co[1] - R.maxdist*lar->vec[1];
- lampco[2]= shi->co[2] - R.maxdist*lar->vec[2];
- }
- else {
- copy_v3_v3(lampco, lar->co);
- }
-
- if (ELEM(lar->ray_samp_method, LA_SAMP_HALTON, LA_SAMP_HAMMERSLEY)) {
-
- ray_shadow_qmc(shi, lar, lampco, shadfac, &isec);
-
- }
- else {
- if (lar->ray_totsamp<2) {
-
- isec.orig.ob = shi->obi;
- isec.orig.face = shi->vlr;
-
- shadfac[3]= 1.0f; /* 1.0=full light */
-
- /* set up isec.dir */
- copy_v3_v3(isec.start, shi->co);
- sub_v3_v3v3(isec.dir, lampco, isec.start);
- isec.dist = normalize_v3(isec.dir);
-
- RE_instance_rotate_ray(shi->obi, &isec);
-
- if (isec.mode==RE_RAY_SHADOW_TRA) {
- /* isec.col is like shadfac, so defines amount of light (0.0 is full shadow) */
- float col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
-
- ray_trace_shadow_tra(&isec, shi, DEPTH_SHADOW_TRA, 0, col);
- copy_v4_v4(shadfac, col);
- }
- else if (RE_rayobject_raycast(R.raytree, &isec))
- shadfac[3]= 0.0f;
- }
- else {
- ray_shadow_jitter(shi, lar, lampco, shadfac, &isec);
- }
- }
-
- /* for first hit optim, set last interesected shadow face */
- if (shi->depth==0) {
- lar->last_hit[shi->thread] = isec.last_hit;
- }
-
-}
-
diff --git a/source/blender/render/intern/source/render_result.c b/source/blender/render/intern/source/render_result.c
index 25377fb4f7e..ba12eac3efa 100644
--- a/source/blender/render/intern/source/render_result.c
+++ b/source/blender/render/intern/source/render_result.c
@@ -266,9 +266,7 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
RenderResult *rr;
RenderLayer *rl;
RenderView *rv;
- SceneRenderLayer *srl;
int rectx, recty;
- int nr;
rectx = BLI_rcti_size_x(partrct);
recty = BLI_rcti_size_y(partrct);
@@ -296,33 +294,21 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
render_result_views_new(rr, &re->r);
/* check renderdata for amount of layers */
- for (nr = 0, srl = re->r.layers.first; srl; srl = srl->next, nr++) {
-
- if (layername && layername[0])
- if (!STREQ(srl->name, layername))
- continue;
-
- if (re->r.scemode & R_SINGLE_LAYER) {
- if (nr != re->r.actlay)
- continue;
- }
- else {
- if (srl->layflag & SCE_LAY_DISABLE)
+ FOREACH_VIEW_LAYER_TO_RENDER_BEGIN(re, view_layer)
+ {
+ if (layername && layername[0]) {
+ if (!STREQ(view_layer->name, layername)) {
continue;
+ }
}
-
+
rl = MEM_callocN(sizeof(RenderLayer), "new render layer");
BLI_addtail(&rr->layers, rl);
- BLI_strncpy(rl->name, srl->name, sizeof(rl->name));
- rl->lay = srl->lay;
- rl->lay_zmask = srl->lay_zmask;
- rl->lay_exclude = srl->lay_exclude;
- rl->layflag = srl->layflag;
- rl->passflag = srl->passflag; /* for debugging: srl->passflag | SCE_PASS_RAYHITS; */
- rl->pass_xor = srl->pass_xor;
- rl->light_override = srl->light_override;
- rl->mat_override = srl->mat_override;
+ BLI_strncpy(rl->name, view_layer->name, sizeof(rl->name));
+ rl->layflag = view_layer->layflag;
+ rl->passflag = view_layer->passflag; /* for debugging: view_layer->passflag | SCE_PASS_RAYHITS; */
+ rl->pass_xor = view_layer->pass_xor;
rl->rectx = rectx;
rl->recty = recty;
@@ -357,70 +343,72 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
/* a renderlayer should always have a Combined pass*/
render_layer_add_pass(rr, rl, 4, "Combined", view, "RGBA");
- if (srl->passflag & SCE_PASS_Z)
+ if (view_layer->passflag & SCE_PASS_Z)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_Z, view, "Z");
- if (srl->passflag & SCE_PASS_VECTOR)
+ if (view_layer->passflag & SCE_PASS_VECTOR)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_VECTOR, view, "XYZW");
- if (srl->passflag & SCE_PASS_NORMAL)
+ if (view_layer->passflag & SCE_PASS_NORMAL)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_NORMAL, view, "XYZ");
- if (srl->passflag & SCE_PASS_UV)
+ if (view_layer->passflag & SCE_PASS_UV)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_UV, view, "UVA");
- if (srl->passflag & SCE_PASS_RGBA)
+ if (view_layer->passflag & SCE_PASS_RGBA)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_RGBA, view, "RGBA");
- if (srl->passflag & SCE_PASS_EMIT)
+ if (view_layer->passflag & SCE_PASS_EMIT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_EMIT, view, "RGB");
- if (srl->passflag & SCE_PASS_DIFFUSE)
+ if (view_layer->passflag & SCE_PASS_DIFFUSE)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE, view, "RGB");
- if (srl->passflag & SCE_PASS_SPEC)
+ if (view_layer->passflag & SCE_PASS_SPEC)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SPEC, view, "RGB");
- if (srl->passflag & SCE_PASS_AO)
+ if (view_layer->passflag & SCE_PASS_AO)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_AO, view, "RGB");
- if (srl->passflag & SCE_PASS_ENVIRONMENT)
+ if (view_layer->passflag & SCE_PASS_ENVIRONMENT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_ENVIRONMENT, view, "RGB");
- if (srl->passflag & SCE_PASS_INDIRECT)
+ if (view_layer->passflag & SCE_PASS_INDIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_INDIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_SHADOW)
+ if (view_layer->passflag & SCE_PASS_SHADOW)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SHADOW, view, "RGB");
- if (srl->passflag & SCE_PASS_REFLECT)
+ if (view_layer->passflag & SCE_PASS_REFLECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_REFLECT, view, "RGB");
- if (srl->passflag & SCE_PASS_REFRACT)
+ if (view_layer->passflag & SCE_PASS_REFRACT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_REFRACT, view, "RGB");
- if (srl->passflag & SCE_PASS_INDEXOB)
+ if (view_layer->passflag & SCE_PASS_INDEXOB)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_INDEXOB, view, "X");
- if (srl->passflag & SCE_PASS_INDEXMA)
+ if (view_layer->passflag & SCE_PASS_INDEXMA)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_INDEXMA, view, "X");
- if (srl->passflag & SCE_PASS_MIST)
+ if (view_layer->passflag & SCE_PASS_MIST)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 1, RE_PASSNAME_MIST, view, "Z");
if (rl->passflag & SCE_PASS_RAYHITS)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 4, RE_PASSNAME_RAYHITS, view, "RGB");
- if (srl->passflag & SCE_PASS_DIFFUSE_DIRECT)
+ if (view_layer->passflag & SCE_PASS_DIFFUSE_DIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_DIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_DIFFUSE_INDIRECT)
+ if (view_layer->passflag & SCE_PASS_DIFFUSE_INDIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_INDIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_DIFFUSE_COLOR)
+ if (view_layer->passflag & SCE_PASS_DIFFUSE_COLOR)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_DIFFUSE_COLOR, view, "RGB");
- if (srl->passflag & SCE_PASS_GLOSSY_DIRECT)
+ if (view_layer->passflag & SCE_PASS_GLOSSY_DIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_DIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_GLOSSY_INDIRECT)
+ if (view_layer->passflag & SCE_PASS_GLOSSY_INDIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_INDIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_GLOSSY_COLOR)
+ if (view_layer->passflag & SCE_PASS_GLOSSY_COLOR)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_GLOSSY_COLOR, view, "RGB");
- if (srl->passflag & SCE_PASS_TRANSM_DIRECT)
+ if (view_layer->passflag & SCE_PASS_TRANSM_DIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_DIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_TRANSM_INDIRECT)
+ if (view_layer->passflag & SCE_PASS_TRANSM_INDIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_INDIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_TRANSM_COLOR)
+ if (view_layer->passflag & SCE_PASS_TRANSM_COLOR)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_TRANSM_COLOR, view, "RGB");
- if (srl->passflag & SCE_PASS_SUBSURFACE_DIRECT)
+ if (view_layer->passflag & SCE_PASS_SUBSURFACE_DIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_DIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_SUBSURFACE_INDIRECT)
+ if (view_layer->passflag & SCE_PASS_SUBSURFACE_INDIRECT)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_INDIRECT, view, "RGB");
- if (srl->passflag & SCE_PASS_SUBSURFACE_COLOR)
+ if (view_layer->passflag & SCE_PASS_SUBSURFACE_COLOR)
RENDER_LAYER_ADD_PASS_SAFE(rr, rl, 3, RE_PASSNAME_SUBSURFACE_COLOR, view, "RGB");
#undef RENDER_LAYER_ADD_PASS_SAFE
}
}
- /* sss, previewrender and envmap don't do layers, so we make a default one */
+ FOREACH_VIEW_LAYER_TO_RENDER_END;
+
+ /* previewrender doesn't do layers, so we make a default one */
if (BLI_listbase_is_empty(&rr->layers) && !(layername && layername[0])) {
rl = MEM_callocN(sizeof(RenderLayer), "new render layer");
BLI_addtail(&rr->layers, rl);
@@ -449,11 +437,10 @@ RenderResult *render_result_new(Render *re, rcti *partrct, int crop, int savebuf
}
/* note, this has to be in sync with scene.c */
- rl->lay = (1 << 20) - 1;
rl->layflag = 0x7FFF; /* solid ztra halo strand */
rl->passflag = SCE_PASS_COMBINED;
- re->r.actlay = 0;
+ re->active_view_layer = 0;
}
/* border render; calculate offset for use in compositor. compo is centralized coords */
@@ -518,23 +505,6 @@ void render_result_add_pass(RenderResult *rr, const char *name, int channels, co
}
}
-/* allocate osa new results for samples */
-RenderResult *render_result_new_full_sample(Render *re, ListBase *lb, rcti *partrct, int crop, int savebuffers, const char *viewname)
-{
- int a;
-
- if (re->osa == 0)
- return render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS, viewname);
-
- for (a = 0; a < re->osa; a++) {
- RenderResult *rr = render_result_new(re, partrct, crop, savebuffers, RR_ALL_LAYERS, viewname);
- BLI_addtail(lb, rr);
- rr->sample_nr = a;
- }
-
- return lb->first;
-}
-
static int passtype_from_name(const char *name)
{
const char delim[] = {'.', '\0'};
@@ -994,7 +964,7 @@ void render_result_single_layer_begin(Render *re)
/* if scemode is R_SINGLE_LAYER, at end of rendering, merge the both render results */
void render_result_single_layer_end(Render *re)
{
- SceneRenderLayer *srl;
+ ViewLayer *view_layer;
RenderLayer *rlpush;
RenderLayer *rl;
int nr;
@@ -1015,12 +985,12 @@ void render_result_single_layer_end(Render *re)
BLI_remlink(&re->result->layers, rl);
/* reconstruct render result layers */
- for (nr = 0, srl = re->r.layers.first; srl; srl = srl->next, nr++) {
- if (nr == re->r.actlay) {
+ for (nr = 0, view_layer = re->view_layers.first; view_layer; view_layer = view_layer->next, nr++) {
+ if (nr == re->active_view_layer) {
BLI_addtail(&re->result->layers, rl);
}
else {
- rlpush = RE_GetRenderLayer(re->pushedresult, srl->name);
+ rlpush = RE_GetRenderLayer(re->pushedresult, view_layer->name);
if (rlpush) {
BLI_remlink(&re->pushedresult->layers, rlpush);
BLI_addtail(&re->result->layers, rlpush);
@@ -1103,8 +1073,8 @@ void render_result_save_empty_result_tiles(Render *re)
for (rl = rr->layers.first; rl; rl = rl->next) {
for (pa = re->parts.first; pa; pa = pa->next) {
if (pa->status != PART_STATUS_MERGED) {
- int party = pa->disprect.ymin - re->disprect.ymin + pa->crop;
- int partx = pa->disprect.xmin - re->disprect.xmin + pa->crop;
+ int party = pa->disprect.ymin - re->disprect.ymin;
+ int partx = pa->disprect.xmin - re->disprect.xmin;
IMB_exrtile_write_channels(rl->exrhandle, partx, party, 0, re->viewname, true);
}
}
diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c
index e66dd86a75a..79d13ecab5b 100644
--- a/source/blender/render/intern/source/render_texture.c
+++ b/source/blender/render/intern/source/render_texture.c
@@ -65,23 +65,11 @@
#include "MEM_guardedalloc.h"
-#include "envmap.h"
-#include "pointdensity.h"
-#include "voxeldata.h"
#include "render_types.h"
-#include "shading.h"
#include "texture.h"
-#include "texture_ocean.h"
-
-#include "renderdatabase.h" /* needed for UV */
#include "RE_render_ext.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
+#include "RE_shader_ext.h"
static RNG_THREAD_ARRAY *random_tex_array;
@@ -97,63 +85,6 @@ void RE_texture_rng_exit(void)
}
-static void init_render_texture(Render *re, Tex *tex)
-{
- /* imap test */
- if (tex->ima && BKE_image_is_animated(tex->ima)) {
- BKE_image_user_frame_calc(&tex->iuser, re ? re->r.cfra : 0, re ? re->flag & R_SEC_FIELD:0);
- }
-
- else if (tex->type==TEX_ENVMAP) {
- /* just in case */
- tex->imaflag |= TEX_INTERPOL | TEX_MIPMAP;
- tex->extend= TEX_CLIP;
-
- if (tex->env) {
- if (tex->env->type==ENV_PLANE)
- tex->extend= TEX_EXTEND;
-
- /* only free envmap when rendermode was set to render envmaps, for previewrender */
- if (G.is_rendering && re) {
- if (re->r.mode & R_ENVMAP)
- if (tex->env->stype==ENV_ANIM)
- BKE_texture_envmap_free_data(tex->env);
- }
- }
- }
-
- if (tex->nodetree && tex->use_nodes) {
- ntreeTexBeginExecTree(tex->nodetree); /* has internal flag to detect it only does it once */
- }
-}
-
-/* ------------------------------------------------------------------------- */
-
-void init_render_textures(Render *re)
-{
- Tex *tex;
-
- tex= re->main->tex.first;
- while (tex) {
- if (tex->id.us) init_render_texture(re, tex);
- tex= tex->id.next;
- }
-}
-
-static void end_render_texture(Tex *tex)
-{
- if (tex && tex->use_nodes && tex->nodetree && tex->nodetree->execdata)
- ntreeTexEndExecTree(tex->nodetree->execdata);
-}
-
-void end_render_textures(Render *re)
-{
- Tex *tex;
- for (tex= re->main->tex.first; tex; tex= tex->id.next)
- if (tex->id.us)
- end_render_texture(tex);
-}
-
/* ------------------------------------------------------------------------- */
@@ -755,7 +686,6 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1
else {
copy_v3_v3(nor, n);
}
- mul_mat3_m4_v3(R.viewinv, nor);
x1 = fabsf(nor[0]);
y1 = fabsf(nor[1]);
@@ -781,115 +711,20 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1
/* ------------------------------------------------------------------------- */
-/* mtex argument only for projection switches */
-static int cubemap(
- const MTex *mtex, VlakRen *vlr, const float n[3], float x, float y, float z, float *adr1, float *adr2)
-{
- int proj[4]={0, ME_PROJXY, ME_PROJXZ, ME_PROJYZ}, ret= 0;
-
- if (vlr) {
- int index;
-
- /* Mesh vertices have such flags, for others we calculate it once based on orco */
- if ((vlr->puno & (ME_PROJXY|ME_PROJXZ|ME_PROJYZ))==0) {
- /* test for v1, vlr can be faked for baking */
- if (vlr->v1 && vlr->v1->orco) {
- float nor[3];
- normal_tri_v3(nor, vlr->v1->orco, vlr->v2->orco, vlr->v3->orco);
-
- if (fabsf(nor[0]) < fabsf(nor[2]) && fabsf(nor[1]) < fabsf(nor[2])) vlr->puno |= ME_PROJXY;
- else if (fabsf(nor[0]) < fabsf(nor[1]) && fabsf(nor[2]) < fabsf(nor[1])) vlr->puno |= ME_PROJXZ;
- else vlr->puno |= ME_PROJYZ;
- }
- else return cubemap_glob(n, x, y, z, adr1, adr2);
- }
-
- if (mtex) {
- /* the mtex->proj{xyz} have type char. maybe this should be wider? */
- /* casting to int ensures that the index type is right. */
- index = (int) mtex->projx;
- proj[index]= ME_PROJXY;
-
- index = (int) mtex->projy;
- proj[index]= ME_PROJXZ;
-
- index = (int) mtex->projz;
- proj[index]= ME_PROJYZ;
- }
-
- if (vlr->puno & proj[1]) {
- *adr1 = (x + 1.0f) / 2.0f;
- *adr2 = (y + 1.0f) / 2.0f;
- }
- else if (vlr->puno & proj[2]) {
- *adr1 = (x + 1.0f) / 2.0f;
- *adr2 = (z + 1.0f) / 2.0f;
- ret= 1;
- }
- else {
- *adr1 = (y + 1.0f) / 2.0f;
- *adr2 = (z + 1.0f) / 2.0f;
- ret= 2;
- }
- }
- else {
- return cubemap_glob(n, x, y, z, adr1, adr2);
- }
-
- return ret;
-}
-
-/* ------------------------------------------------------------------------- */
-
-static int cubemap_ob(Object *ob, const float n[3], float x, float y, float z, float *adr1, float *adr2)
-{
- float x1, y1, z1, nor[3];
- int ret;
-
- if (n==NULL) return 0;
-
- copy_v3_v3(nor, n);
- if (ob) mul_mat3_m4_v3(ob->imat, nor);
-
- x1 = fabsf(nor[0]);
- y1 = fabsf(nor[1]);
- z1 = fabsf(nor[2]);
-
- if (z1>=x1 && z1>=y1) {
- *adr1 = (x + 1.0f) / 2.0f;
- *adr2 = (y + 1.0f) / 2.0f;
- ret= 0;
- }
- else if (y1>=x1 && y1>=z1) {
- *adr1 = (x + 1.0f) / 2.0f;
- *adr2 = (z + 1.0f) / 2.0f;
- ret= 1;
- }
- else {
- *adr1 = (y + 1.0f) / 2.0f;
- *adr2 = (z + 1.0f) / 2.0f;
- ret= 2;
- }
- return ret;
-}
-
/* ------------------------------------------------------------------------- */
static void do_2d_mapping(
- const MTex *mtex, float texvec[3], VlakRen *vlr, const float n[3], float dxt[3], float dyt[3])
+ const MTex *mtex, float texvec[3], const float n[3], float dxt[3], float dyt[3])
{
Tex *tex;
- Object *ob= NULL;
float fx, fy, fac1, area[8];
- int ok, proj, areaflag= 0, wrap, texco;
+ int ok, proj, areaflag= 0, wrap;
/* mtex variables localized, only cubemap doesn't cooperate yet... */
wrap= mtex->mapping;
tex= mtex->tex;
- ob= mtex->object;
- texco= mtex->texco;
- if (R.osa==0) {
+ if (!(dxt && dyt)) {
if (wrap==MTEX_FLAT) {
fx = (texvec[0] + 1.0f) / 2.0f;
@@ -898,9 +733,7 @@ static void do_2d_mapping(
else if (wrap == MTEX_TUBE) map_to_tube( &fx, &fy, texvec[0], texvec[1], texvec[2]);
else if (wrap == MTEX_SPHERE) map_to_sphere(&fx, &fy, texvec[0], texvec[1], texvec[2]);
else {
- if (texco == TEXCO_OBJECT) cubemap_ob(ob, n, texvec[0], texvec[1], texvec[2], &fx, &fy);
- else if (texco == TEXCO_GLOB) cubemap_glob(n, texvec[0], texvec[1], texvec[2], &fx, &fy);
- else cubemap(mtex, vlr, n, texvec[0], texvec[1], texvec[2], &fx, &fy);
+ cubemap_glob(n, texvec[0], texvec[1], texvec[2], &fx, &fy);
}
/* repeat */
@@ -996,9 +829,7 @@ static void do_2d_mapping(
}
else {
- if (texco==TEXCO_OBJECT) proj = cubemap_ob(ob, n, texvec[0], texvec[1], texvec[2], &fx, &fy);
- else if (texco==TEXCO_GLOB) proj = cubemap_glob(n, texvec[0], texvec[1], texvec[2], &fx, &fy);
- else proj = cubemap(mtex, vlr, n, texvec[0], texvec[1], texvec[2], &fx, &fy);
+ proj = cubemap_glob(n, texvec[0], texvec[1], texvec[2], &fx, &fy);
if (proj==1) {
SWAP(float, dxt[1], dxt[2]);
@@ -1124,8 +955,9 @@ static int multitex(Tex *tex,
texres->talpha = false; /* is set when image texture returns alpha (considered premul) */
if (use_nodes && tex->use_nodes && tex->nodetree) {
+ const float cfra = 1.0f; /* This was only set for Blender Internal render before. */
retval = ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, osatex, thread,
- tex, which_output, R.r.cfra, texnode_preview, NULL, NULL);
+ tex, which_output, cfra, texnode_preview, NULL);
}
else {
switch (tex->type) {
@@ -1160,9 +992,6 @@ static int multitex(Tex *tex,
BKE_image_tag_time(tex->ima);
}
break;
- case TEX_ENVMAP:
- retval = envmaptex(tex, texvec, dxt, dyt, osatex, texres, pool, skip_load_image);
- break;
case TEX_MUSGRAVE:
/* newnoise: musgrave types */
@@ -1205,15 +1034,6 @@ static int multitex(Tex *tex,
retval = mg_distNoiseTex(tex, tmpvec, texres);
break;
- case TEX_POINTDENSITY:
- retval = pointdensitytex(tex, texvec, texres);
- break;
- case TEX_VOXELDATA:
- retval = voxeldatatex(tex, texvec, texres);
- break;
- case TEX_OCEAN:
- retval = ocean_texture(tex, texvec, texres);
- break;
}
}
@@ -1238,7 +1058,6 @@ static int multitex_nodes_intern(Tex *tex,
TexResult *texres,
const short thread,
short which_output,
- ShadeInput *shi,
MTex *mtex, struct
ImagePool *pool,
const bool scene_color_manage,
@@ -1259,7 +1078,7 @@ static int multitex_nodes_intern(Tex *tex,
if (mtex) {
/* we have mtex, use it for 2d mapping images only */
- do_2d_mapping(mtex, texvec, shi->vlr, shi->facenor, dxt, dyt);
+ do_2d_mapping(mtex, texvec, NULL, dxt, dyt);
rgbnor = multitex(tex,
texvec,
dxt, dyt,
@@ -1272,7 +1091,7 @@ static int multitex_nodes_intern(Tex *tex,
texnode_preview,
use_nodes);
- if (mtex->mapto & (MAP_COL+MAP_COLSPEC+MAP_COLMIR)) {
+ if (mtex->mapto & (MAP_COL)) {
ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool);
/* don't linearize float buffers, assumed to be linear */
@@ -1307,7 +1126,7 @@ static int multitex_nodes_intern(Tex *tex,
zero_v3(dyt_l);
}
- do_2d_mapping(&localmtex, texvec_l, NULL, NULL, dxt_l, dyt_l);
+ do_2d_mapping(&localmtex, texvec_l, NULL, dxt_l, dyt_l);
rgbnor = multitex(tex,
texvec_l,
dxt_l, dyt_l,
@@ -1357,41 +1176,15 @@ static int multitex_nodes_intern(Tex *tex,
* Use it from render pipeline only!
*/
int multitex_nodes(Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, TexResult *texres,
- const short thread, short which_output, ShadeInput *shi, MTex *mtex, struct ImagePool *pool)
+ const short thread, short which_output, MTex *mtex, struct ImagePool *pool)
{
return multitex_nodes_intern(tex, texvec, dxt, dyt, osatex, texres,
- thread, which_output, shi, mtex, pool, R.scene_color_manage,
- (R.r.scemode & R_NO_IMAGE_LOAD) != 0,
- (R.r.scemode & R_TEXNODE_PREVIEW) != 0,
+ thread, which_output, mtex, pool, true,
+ false,
+ false,
true);
}
-/* this is called for surface shading */
-static int multitex_mtex(ShadeInput *shi, MTex *mtex, float texvec[3], float dxt[3], float dyt[3], TexResult *texres, struct ImagePool *pool, const bool skip_load_image)
-{
- Tex *tex = mtex->tex;
- /* TODO(sergey): Texture preview should become an argument? */
- if (tex->use_nodes && tex->nodetree) {
- /* stupid exception here .. but we have to pass shi and mtex to
- * textures nodes for 2d mapping and color management for images */
- return ntreeTexExecTree(tex->nodetree, texres, texvec, dxt, dyt, shi->osatex, shi->thread,
- tex, mtex->which_output, R.r.cfra, (R.r.scemode & R_TEXNODE_PREVIEW) != 0, shi, mtex);
- }
- else {
- return multitex(mtex->tex,
- texvec,
- dxt, dyt,
- shi->osatex,
- texres,
- shi->thread,
- mtex->which_output,
- pool,
- skip_load_image,
- (R.r.scemode & R_TEXNODE_PREVIEW) != 0,
- true);
- }
-}
-
/* Warning, if the texres's values are not declared zero, check the return value to be sure
* the color values are set before using the r/g/b values, otherwise you may use uninitialized values - Campbell
*
@@ -1414,7 +1207,7 @@ int multitex_ext(Tex *tex,
texres,
thread,
0,
- NULL, NULL,
+ NULL,
pool,
scene_color_manage,
skip_load_image,
@@ -1435,7 +1228,7 @@ int multitex_ext_safe(Tex *tex, float texvec[3], TexResult *texres, struct Image
texres,
0,
0,
- NULL, NULL,
+ NULL,
pool,
scene_color_manage,
skip_load_image,
@@ -1652,1949 +1445,6 @@ float texture_value_blend(float tex, float out, float fact, float facg, int blen
return in;
}
-static void texco_mapping(ShadeInput *shi, Tex *tex, MTex *mtex,
- const float co[3], const float dx[3], const float dy[3], float texvec[3], float dxt[3], float dyt[3])
-{
- /* new: first swap coords, then map, then trans/scale */
- if (tex->type == TEX_IMAGE) {
- /* placement */
- texvec[0] = mtex->projx ? co[mtex->projx - 1] : 0.f;
- texvec[1] = mtex->projy ? co[mtex->projy - 1] : 0.f;
- texvec[2] = mtex->projz ? co[mtex->projz - 1] : 0.f;
-
- if (shi->osatex) {
- if (mtex->projx) {
- dxt[0] = dx[mtex->projx - 1];
- dyt[0] = dy[mtex->projx - 1];
- }
- else dxt[0] = dyt[0] = 0.f;
- if (mtex->projy) {
- dxt[1] = dx[mtex->projy - 1];
- dyt[1] = dy[mtex->projy - 1];
- }
- else dxt[1] = dyt[1] = 0.f;
- if (mtex->projz) {
- dxt[2] = dx[mtex->projz - 1];
- dyt[2] = dy[mtex->projz - 1];
- }
- else dxt[2] = dyt[2] = 0.f;
- }
- do_2d_mapping(mtex, texvec, shi->vlr, shi->facenor, dxt, dyt);
-
- /* translate and scale */
- texvec[0] = mtex->size[0]*(texvec[0] - 0.5f) + mtex->ofs[0] + 0.5f;
- texvec[1] = mtex->size[1]*(texvec[1] - 0.5f) + mtex->ofs[1] + 0.5f;
- if (shi->osatex) {
- dxt[0] = mtex->size[0] * dxt[0];
- dxt[1] = mtex->size[1] * dxt[1];
- dyt[0] = mtex->size[0] * dyt[0];
- dyt[1] = mtex->size[1] * dyt[1];
- }
-
- /* problem: repeat-mirror is not a 'repeat' but 'extend' in imagetexture.c */
- /* TXF: bug was here, only modify texvec when repeat mode set, old code affected other modes too.
- * New texfilters solve mirroring differently so that it also works correctly when
- * textures are scaled (sizeXYZ) as well as repeated. See also modification in do_2d_mapping().
- * (since currently only done in osa mode, results will look incorrect without osa TODO) */
- if (tex->extend == TEX_REPEAT && (tex->flag & TEX_REPEAT_XMIR)) {
- if (tex->texfilter == TXF_BOX)
- texvec[0] -= floorf(texvec[0]); /* this line equivalent to old code, same below */
- else if (texvec[0] < 0.f || texvec[0] > 1.f) {
- const float tx = 0.5f*texvec[0];
- texvec[0] = 2.f*(tx - floorf(tx));
- if (texvec[0] > 1.f) texvec[0] = 2.f - texvec[0];
- }
- }
- if (tex->extend == TEX_REPEAT && (tex->flag & TEX_REPEAT_YMIR)) {
- if (tex->texfilter == TXF_BOX)
- texvec[1] -= floorf(texvec[1]);
- else if (texvec[1] < 0.f || texvec[1] > 1.f) {
- const float ty = 0.5f*texvec[1];
- texvec[1] = 2.f*(ty - floorf(ty));
- if (texvec[1] > 1.f) texvec[1] = 2.f - texvec[1];
- }
- }
-
- }
- else { /* procedural */
- /* placement */
- texvec[0] = mtex->size[0]*(mtex->projx ? (co[mtex->projx - 1] + mtex->ofs[0]) : mtex->ofs[0]);
- texvec[1] = mtex->size[1]*(mtex->projy ? (co[mtex->projy - 1] + mtex->ofs[1]) : mtex->ofs[1]);
- texvec[2] = mtex->size[2]*(mtex->projz ? (co[mtex->projz - 1] + mtex->ofs[2]) : mtex->ofs[2]);
-
- if (shi->osatex) {
- if (mtex->projx) {
- dxt[0] = mtex->size[0]*dx[mtex->projx - 1];
- dyt[0] = mtex->size[0]*dy[mtex->projx - 1];
- }
- else dxt[0] = dyt[0] = 0.f;
- if (mtex->projy) {
- dxt[1] = mtex->size[1]*dx[mtex->projy - 1];
- dyt[1] = mtex->size[1]*dy[mtex->projy - 1];
- }
- else dxt[1] = dyt[1] = 0.f;
- if (mtex->projz) {
- dxt[2] = mtex->size[2]*dx[mtex->projz - 1];
- dyt[2] = mtex->size[2]*dy[mtex->projz - 1];
- }
- else dxt[2]= dyt[2] = 0.f;
- }
-
- if (mtex->tex->type == TEX_ENVMAP) {
- EnvMap *env = tex->env;
- if (!env->object) {
- // env->object is a view point for envmap rendering
- // if it's not set, return the result depending on the world_space_shading flag
- if (BKE_scene_use_world_space_shading(R.scene)) {
- mul_mat3_m4_v3(R.viewinv, texvec);
- if (shi->osatex) {
- mul_mat3_m4_v3(R.viewinv, dxt);
- mul_mat3_m4_v3(R.viewinv, dyt);
- }
- }
- }
- }
- }
-}
-
-/* Bump code from 2.5 development cycle, has a number of bugs, but here for compatibility */
-
-typedef struct CompatibleBump {
- float nu[3], nv[3], nn[3];
- float dudnu, dudnv, dvdnu, dvdnv;
- bool nunvdone;
-} CompatibleBump;
-
-static void compatible_bump_init(CompatibleBump *compat_bump)
-{
- memset(compat_bump, 0, sizeof(*compat_bump));
-
- compat_bump->dudnu = 1.0f;
- compat_bump->dvdnv = 1.0f;
-}
-
-static void compatible_bump_uv_derivs(CompatibleBump *compat_bump, ShadeInput *shi, MTex *mtex, int i)
-{
- /* uvmapping only, calculation of normal tangent u/v partial derivatives
- * (should not be here, dudnu, dudnv, dvdnu & dvdnv should probably be part of ShadeInputUV struct,
- * nu/nv in ShadeInput and this calculation should then move to shadeinput.c,
- * shade_input_set_shade_texco() func.) */
-
- /* NOTE: test for shi->obr->ob here,
- * since vlr/obr/obi can be 'fake' when called from fastshade(), another reason to move it.. */
-
- /* NOTE: shi->v1 is NULL when called from displace_render_vert,
- * assigning verts in this case is not trivial because the shi quad face side is not know. */
- if ((mtex->texflag & MTEX_COMPAT_BUMP) && shi->obr && shi->obr->ob && shi->v1) {
- if (mtex->mapto & (MAP_NORM|MAP_WARP) && !((mtex->tex->type==TEX_IMAGE) && (mtex->tex->imaflag & TEX_NORMALMAP))) {
- MTFace* tf = RE_vlakren_get_tface(shi->obr, shi->vlr, i, NULL, 0);
- int j1 = shi->i1, j2 = shi->i2, j3 = shi->i3;
-
- vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3);
-
- /* compute ortho basis around normal */
- if (!compat_bump->nunvdone) {
- /* render normal is negated */
- compat_bump->nn[0] = -shi->vn[0];
- compat_bump->nn[1] = -shi->vn[1];
- compat_bump->nn[2] = -shi->vn[2];
- ortho_basis_v3v3_v3(compat_bump->nu, compat_bump->nv, compat_bump->nn);
- compat_bump->nunvdone = true;
- }
-
- if (tf) {
- const float *uv1 = tf->uv[j1], *uv2 = tf->uv[j2], *uv3 = tf->uv[j3];
- const float an[3] = {fabsf(compat_bump->nn[0]), fabsf(compat_bump->nn[1]), fabsf(compat_bump->nn[2])};
- const int a1 = (an[0] > an[1] && an[0] > an[2]) ? 1 : 0;
- const int a2 = (an[2] > an[0] && an[2] > an[1]) ? 1 : 2;
- const float dp1_a1 = shi->v1->co[a1] - shi->v3->co[a1];
- const float dp1_a2 = shi->v1->co[a2] - shi->v3->co[a2];
- const float dp2_a1 = shi->v2->co[a1] - shi->v3->co[a1];
- const float dp2_a2 = shi->v2->co[a2] - shi->v3->co[a2];
- const float du1 = uv1[0] - uv3[0], du2 = uv2[0] - uv3[0];
- const float dv1 = uv1[1] - uv3[1], dv2 = uv2[1] - uv3[1];
- const float dpdu_a1 = dv2*dp1_a1 - dv1*dp2_a1;
- const float dpdu_a2 = dv2*dp1_a2 - dv1*dp2_a2;
- const float dpdv_a1 = du1*dp2_a1 - du2*dp1_a1;
- const float dpdv_a2 = du1*dp2_a2 - du2*dp1_a2;
- float d = dpdu_a1*dpdv_a2 - dpdv_a1*dpdu_a2;
- float uvd = du1*dv2 - dv1*du2;
-
- if (uvd == 0.f) uvd = 1e-5f;
- if (d == 0.f) d = 1e-5f;
- d = uvd / d;
-
- compat_bump->dudnu = (dpdv_a2*compat_bump->nu[a1] - dpdv_a1*compat_bump->nu[a2])*d;
- compat_bump->dvdnu = (dpdu_a1*compat_bump->nu[a2] - dpdu_a2*compat_bump->nu[a1])*d;
- compat_bump->dudnv = (dpdv_a2*compat_bump->nv[a1] - dpdv_a1*compat_bump->nv[a2])*d;
- compat_bump->dvdnv = (dpdu_a1*compat_bump->nv[a2] - dpdu_a2*compat_bump->nv[a1])*d;
- }
- }
- }
-}
-
-static int compatible_bump_compute(CompatibleBump *compat_bump, ShadeInput *shi, MTex *mtex, Tex *tex, TexResult *texres,
- float Tnor, const float co[3], const float dx[3], const float dy[3], float texvec[3], float dxt[3], float dyt[3],
- struct ImagePool *pool, const bool skip_load_image)
-{
- TexResult ttexr = {0, 0, 0, 0, 0, texres->talpha, NULL}; /* temp TexResult */
- float tco[3], texv[3], cd, ud, vd, du, dv, idu, idv;
- const int fromrgb = ((tex->type == TEX_IMAGE) || ((tex->flag & TEX_COLORBAND)!=0));
- const float bf = -0.04f*Tnor*mtex->norfac;
- int rgbnor;
- /* disable internal bump eval */
- float *nvec = texres->nor;
- texres->nor = NULL;
- /* du & dv estimates, constant value defaults */
- du = dv = 0.01f;
-
- /* compute ortho basis around normal */
- if (!compat_bump->nunvdone) {
- /* render normal is negated */
- negate_v3_v3(compat_bump->nn, shi->vn);
- ortho_basis_v3v3_v3(compat_bump->nu, compat_bump->nv, compat_bump->nn);
- compat_bump->nunvdone = true;
- }
-
- /* two methods, either constant based on main image resolution,
- * (which also works without osa, though of course not always good (or even very bad) results),
- * or based on tex derivative max values (osa only). Not sure which is best... */
-
- if (!shi->osatex && (tex->type == TEX_IMAGE) && tex->ima) {
- /* in case we have no proper derivatives, fall back to
- * computing du/dv it based on image size */
- ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool);
- if (ibuf) {
- du = 1.f/(float)ibuf->x;
- dv = 1.f/(float)ibuf->y;
- }
- BKE_image_pool_release_ibuf(tex->ima, ibuf, pool);
- }
- else if (shi->osatex) {
- /* we have derivatives, can compute proper du/dv */
- if (tex->type == TEX_IMAGE) { /* 2d image, use u & v max. of dx/dy 2d vecs */
- const float adx[2] = {fabsf(dx[0]), fabsf(dx[1])};
- const float ady[2] = {fabsf(dy[0]), fabsf(dy[1])};
- du = MAX2(adx[0], ady[0]);
- dv = MAX2(adx[1], ady[1]);
- }
- else { /* 3d procedural, estimate from all dx/dy elems */
- const float adx[3] = {fabsf(dx[0]), fabsf(dx[1]), fabsf(dx[2])};
- const float ady[3] = {fabsf(dy[0]), fabsf(dy[1]), fabsf(dy[2])};
- du = max_fff(adx[0], adx[1], adx[2]);
- dv = max_fff(ady[0], ady[1], ady[2]);
- }
- }
-
- /* center, main return value */
- texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
- rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, texres, pool, skip_load_image);
- cd = fromrgb ? (texres->tr + texres->tg + texres->tb) / 3.0f : texres->tin;
-
- if (mtex->texco == TEXCO_UV) {
- /* for the uv case, use the same value for both du/dv,
- * since individually scaling the normal derivatives makes them useless... */
- du = min_ff(du, dv);
- idu = (du < 1e-5f) ? bf : (bf/du);
-
- /* +u val */
- tco[0] = co[0] + compat_bump->dudnu*du;
- tco[1] = co[1] + compat_bump->dvdnu*du;
- tco[2] = 0.f;
- texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool, skip_load_image);
- ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
-
- /* +v val */
- tco[0] = co[0] + compat_bump->dudnv*du;
- tco[1] = co[1] + compat_bump->dvdnv*du;
- tco[2] = 0.f;
- texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool, skip_load_image);
- vd = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
- }
- else {
- float tu[3], tv[3];
-
- copy_v3_v3(tu, compat_bump->nu);
- copy_v3_v3(tv, compat_bump->nv);
-
- idu = (du < 1e-5f) ? bf : (bf/du);
- idv = (dv < 1e-5f) ? bf : (bf/dv);
-
- if ((mtex->texco == TEXCO_ORCO) && shi->obr && shi->obr->ob) {
- mul_mat3_m4_v3(shi->obr->ob->imat_ren, tu);
- mul_mat3_m4_v3(shi->obr->ob->imat_ren, tv);
- normalize_v3(tu);
- normalize_v3(tv);
- }
- else if (mtex->texco == TEXCO_GLOB) {
- mul_mat3_m4_v3(R.viewinv, tu);
- mul_mat3_m4_v3(R.viewinv, tv);
- }
- else if (mtex->texco == TEXCO_OBJECT && mtex->object) {
- mul_mat3_m4_v3(mtex->object->imat_ren, tu);
- mul_mat3_m4_v3(mtex->object->imat_ren, tv);
- normalize_v3(tu);
- normalize_v3(tv);
- }
-
- /* +u val */
- tco[0] = co[0] + tu[0]*du;
- tco[1] = co[1] + tu[1]*du;
- tco[2] = co[2] + tu[2]*du;
- texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool, skip_load_image);
- ud = idu*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
-
- /* +v val */
- tco[0] = co[0] + tv[0]*dv;
- tco[1] = co[1] + tv[1]*dv;
- tco[2] = co[2] + tv[2]*dv;
- texco_mapping(shi, tex, mtex, tco, dx, dy, texv, dxt, dyt);
- multitex_mtex(shi, mtex, texv, dxt, dyt, &ttexr, pool, skip_load_image);
- vd = idv*(cd - (fromrgb ? (ttexr.tr + ttexr.tg + ttexr.tb) / 3.0f : ttexr.tin));
- }
-
- /* bumped normal */
- compat_bump->nu[0] += ud*compat_bump->nn[0];
- compat_bump->nu[1] += ud*compat_bump->nn[1];
- compat_bump->nu[2] += ud*compat_bump->nn[2];
- compat_bump->nv[0] += vd*compat_bump->nn[0];
- compat_bump->nv[1] += vd*compat_bump->nn[1];
- compat_bump->nv[2] += vd*compat_bump->nn[2];
- cross_v3_v3v3(nvec, compat_bump->nu, compat_bump->nv);
-
- nvec[0] = -nvec[0];
- nvec[1] = -nvec[1];
- nvec[2] = -nvec[2];
- texres->nor = nvec;
-
- rgbnor |= TEX_NOR;
- return rgbnor;
-}
-
-/* Improved bump code from later in 2.5 development cycle */
-
-typedef struct NTapBump {
- int init_done;
- int iPrevBumpSpace; /* 0: uninitialized, 1: objectspace, 2: texturespace, 4: viewspace */
- /* bumpmapping */
- float vNorg[3]; /* backup copy of shi->vn */
- float vNacc[3]; /* original surface normal minus the surface gradient of every bump map which is encountered */
- float vR1[3], vR2[3]; /* cross products (sigma_y, original_normal), (original_normal, sigma_x) */
- float sgn_det; /* sign of the determinant of the matrix {sigma_x, sigma_y, original_normal} */
- float fPrevMagnitude; /* copy of previous magnitude, used for multiple bumps in different spaces */
-} NTapBump;
-
-static void ntap_bump_init(NTapBump *ntap_bump)
-{
- memset(ntap_bump, 0, sizeof(*ntap_bump));
-}
-
-static int ntap_bump_compute(NTapBump *ntap_bump, ShadeInput *shi, MTex *mtex, Tex *tex, TexResult *texres,
- float Tnor, const float co[3], const float dx[3], const float dy[3],
- float texvec[3], float dxt[3], float dyt[3], struct ImagePool *pool,
- const bool skip_load_image)
-{
- TexResult ttexr = {0, 0, 0, 0, 0, texres->talpha, NULL}; /* temp TexResult */
-
- const int fromrgb = ((tex->type == TEX_IMAGE) || ((tex->flag & TEX_COLORBAND)!=0));
-
- /* The negate on Hscale is done because the
- * normal in the renderer points inward which corresponds
- * to inverting the bump map. The normals are generated
- * this way in calc_vertexnormals(). Should this ever change
- * this negate must be removed. */
- float Hscale = -Tnor*mtex->norfac;
-
- int dimx=512, dimy=512;
- const int imag_tspace_dimension_x = 1024; /* only used for texture space variant */
- float aspect = 1.0f;
-
- /* 2 channels for 2D texture and 3 for 3D textures. */
- const int nr_channels = (mtex->texco == TEXCO_UV)? 2 : 3;
- int c, rgbnor, iBumpSpace;
- float dHdx, dHdy;
- int found_deriv_map = (tex->type==TEX_IMAGE) && (tex->imaflag & TEX_DERIVATIVEMAP);
-
- /* disable internal bump eval in sampler, save pointer */
- float *nvec = texres->nor;
- texres->nor = NULL;
-
- if (found_deriv_map==0) {
- if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
- if (tex->ima)
- Hscale *= 13.0f; /* appears to be a sensible default value */
- }
- else
- Hscale *= 0.1f; /* factor 0.1 proved to look like the previous bump code */
- }
-
- if ( !ntap_bump->init_done ) {
- copy_v3_v3(ntap_bump->vNacc, shi->vn);
- copy_v3_v3(ntap_bump->vNorg, shi->vn);
- ntap_bump->fPrevMagnitude = 1.0f;
- ntap_bump->iPrevBumpSpace = 0;
-
- ntap_bump->init_done = true;
- }
-
- /* resolve image dimensions */
- if (found_deriv_map || (mtex->texflag&MTEX_BUMP_TEXTURESPACE)!=0) {
- ImBuf *ibuf = BKE_image_pool_acquire_ibuf(tex->ima, &tex->iuser, pool);
- if (ibuf) {
- dimx = ibuf->x;
- dimy = ibuf->y;
- aspect = ((float) dimy) / dimx;
- }
- BKE_image_pool_release_ibuf(tex->ima, ibuf, pool);
- }
-
- if (found_deriv_map) {
- float dBdu, dBdv, auto_bump = 1.0f;
- float s = 1; /* negate this if flipped texture coordinate */
- texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
- rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, texres, pool, skip_load_image);
-
- if (shi->obr->ob->derivedFinal) {
- auto_bump = shi->obr->ob->derivedFinal->auto_bump_scale;
- }
-
- {
- float fVirtDim = sqrtf(fabsf((float) (dimx*dimy)*mtex->size[0]*mtex->size[1]));
- auto_bump /= MAX2(fVirtDim, FLT_EPSILON);
- }
-
- /* this variant using a derivative map is described here
- * http://mmikkelsen3d.blogspot.com/2011/07/derivative-maps.html */
- dBdu = auto_bump*Hscale*dimx*(2*texres->tr-1);
- dBdv = auto_bump*Hscale*dimy*(2*texres->tg-1);
-
- dHdx = dBdu*dxt[0] + s * dBdv*dxt[1];
- dHdy = dBdu*dyt[0] + s * dBdv*dyt[1];
- }
- else if (!(mtex->texflag & MTEX_5TAP_BUMP)) {
- /* compute height derivatives with respect to output image pixel coordinates x and y */
- float STll[3], STlr[3], STul[3];
- float Hll, Hlr, Hul;
-
- texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
-
- for (c=0; c<nr_channels; c++) {
- /* dx contains the derivatives (du/dx, dv/dx)
- * dy contains the derivatives (du/dy, dv/dy) */
- STll[c] = texvec[c];
- STlr[c] = texvec[c]+dxt[c];
- STul[c] = texvec[c]+dyt[c];
- }
-
- /* clear unused derivatives */
- for (c=nr_channels; c<3; c++) {
- STll[c] = 0.0f;
- STlr[c] = 0.0f;
- STul[c] = 0.0f;
- }
-
- /* use texres for the center sample, set rgbnor */
- rgbnor = multitex_mtex(shi, mtex, STll, dxt, dyt, texres, pool, skip_load_image);
- Hll = (fromrgb) ? IMB_colormanagement_get_luminance(&texres->tr) : texres->tin;
-
- /* use ttexr for the other 2 taps */
- multitex_mtex(shi, mtex, STlr, dxt, dyt, &ttexr, pool, skip_load_image);
- Hlr = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
-
- multitex_mtex(shi, mtex, STul, dxt, dyt, &ttexr, pool, skip_load_image);
- Hul = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
-
- dHdx = Hscale*(Hlr - Hll);
- dHdy = Hscale*(Hul - Hll);
- }
- else {
- /* same as above, but doing 5 taps, increasing quality at cost of speed */
- float STc[3], STl[3], STr[3], STd[3], STu[3];
- float /* Hc, */ /* UNUSED */ Hl, Hr, Hd, Hu;
-
- texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
-
- for (c=0; c<nr_channels; c++) {
- STc[c] = texvec[c];
- STl[c] = texvec[c] - 0.5f*dxt[c];
- STr[c] = texvec[c] + 0.5f*dxt[c];
- STd[c] = texvec[c] - 0.5f*dyt[c];
- STu[c] = texvec[c] + 0.5f*dyt[c];
- }
-
- /* clear unused derivatives */
- for (c=nr_channels; c<3; c++) {
- STc[c] = 0.0f;
- STl[c] = 0.0f;
- STr[c] = 0.0f;
- STd[c] = 0.0f;
- STu[c] = 0.0f;
- }
-
- /* use texres for the center sample, set rgbnor */
- rgbnor = multitex_mtex(shi, mtex, STc, dxt, dyt, texres, pool, skip_load_image);
- /* Hc = (fromrgb) ? IMB_colormanagement_get_luminance(&texres->tr) : texres->tin; */ /* UNUSED */
-
- /* use ttexr for the other taps */
- multitex_mtex(shi, mtex, STl, dxt, dyt, &ttexr, pool, skip_load_image);
- Hl = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
- multitex_mtex(shi, mtex, STr, dxt, dyt, &ttexr, pool, skip_load_image);
- Hr = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
- multitex_mtex(shi, mtex, STd, dxt, dyt, &ttexr, pool, skip_load_image);
- Hd = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
- multitex_mtex(shi, mtex, STu, dxt, dyt, &ttexr, pool, skip_load_image);
- Hu = (fromrgb) ? IMB_colormanagement_get_luminance(&ttexr.tr) : ttexr.tin;
-
- dHdx = Hscale*(Hr - Hl);
- dHdy = Hscale*(Hu - Hd);
- }
-
- /* restore pointer */
- texres->nor = nvec;
-
- /* replaced newbump with code based on listing 1 and 2 of
- * [Mik10] Mikkelsen M. S.: Bump Mapping Unparameterized Surfaces on the GPU.
- * -> http://jbit.net/~sparky/sfgrad_bump/mm_sfgrad_bump.pdf */
-
- if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE )
- iBumpSpace = 1;
- else if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE )
- iBumpSpace = 2;
- else
- iBumpSpace = 4; /* ViewSpace */
-
- if ( ntap_bump->iPrevBumpSpace != iBumpSpace ) {
-
- /* initialize normal perturbation vectors */
- int xyz;
- float fDet, abs_fDet, fMagnitude;
- /* object2view and inverted matrix */
- float obj2view[3][3], view2obj[3][3], tmp[4][4];
- /* local copies of derivatives and normal */
- float dPdx[3], dPdy[3], vN[3];
- copy_v3_v3(dPdx, shi->dxco);
- copy_v3_v3(dPdy, shi->dyco);
- copy_v3_v3(vN, ntap_bump->vNorg);
-
- if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) {
- /* TODO: these calculations happen for every pixel!
- * -> move to shi->obi */
- mul_m4_m4m4(tmp, R.viewmat, shi->obr->ob->obmat);
- copy_m3_m4(obj2view, tmp); /* use only upper left 3x3 matrix */
- invert_m3_m3(view2obj, obj2view);
-
- /* generate the surface derivatives in object space */
- mul_m3_v3(view2obj, dPdx);
- mul_m3_v3(view2obj, dPdy);
- /* generate the unit normal in object space */
- mul_transposed_m3_v3(obj2view, vN);
- normalize_v3(vN);
- }
-
- cross_v3_v3v3(ntap_bump->vR1, dPdy, vN);
- cross_v3_v3v3(ntap_bump->vR2, vN, dPdx);
- fDet = dot_v3v3(dPdx, ntap_bump->vR1);
- ntap_bump->sgn_det = (fDet < 0)? -1.0f: 1.0f;
- abs_fDet = ntap_bump->sgn_det * fDet;
-
- if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
- if (tex->ima) {
- /* crazy hack solution that gives results similar to normal mapping - part 1 */
- normalize_v3(ntap_bump->vR1);
- normalize_v3(ntap_bump->vR2);
- abs_fDet = 1.0f;
- }
- }
-
- fMagnitude = abs_fDet;
- if ( mtex->texflag & MTEX_BUMP_OBJECTSPACE ) {
- /* pre do transform of texres->nor by the inverse transposed of obj2view */
- mul_transposed_m3_v3(view2obj, vN);
- mul_transposed_m3_v3(view2obj, ntap_bump->vR1);
- mul_transposed_m3_v3(view2obj, ntap_bump->vR2);
-
- fMagnitude *= len_v3(vN);
- }
-
- if (ntap_bump->fPrevMagnitude > 0.0f)
- for (xyz=0; xyz<3; xyz++)
- ntap_bump->vNacc[xyz] *= fMagnitude / ntap_bump->fPrevMagnitude;
-
- ntap_bump->fPrevMagnitude = fMagnitude;
- ntap_bump->iPrevBumpSpace = iBumpSpace;
- }
-
- if ( mtex->texflag & MTEX_BUMP_TEXTURESPACE ) {
- if (tex->ima) {
- /* crazy hack solution that gives results similar to normal mapping - part 2 */
- float vec[2];
- const float imag_tspace_dimension_y = aspect*imag_tspace_dimension_x;
-
- vec[0] = imag_tspace_dimension_x*dxt[0];
- vec[1] = imag_tspace_dimension_y*dxt[1];
- dHdx *= 1.0f/len_v2(vec);
- vec[0] = imag_tspace_dimension_x*dyt[0];
- vec[1] = imag_tspace_dimension_y*dyt[1];
- dHdy *= 1.0f/len_v2(vec);
- }
- }
-
- /* subtract the surface gradient from vNacc */
- for (c=0; c<3; c++) {
- float vSurfGrad_compi = ntap_bump->sgn_det * (dHdx * ntap_bump->vR1[c] + dHdy * ntap_bump->vR2[c]);
- ntap_bump->vNacc[c] -= vSurfGrad_compi;
- texres->nor[c] = ntap_bump->vNacc[c]; /* copy */
- }
-
- rgbnor |= TEX_NOR;
- return rgbnor;
-}
-
-void do_material_tex(ShadeInput *shi, Render *re)
-{
- const bool skip_load_image = (R.r.scemode & R_NO_IMAGE_LOAD) != 0;
- CompatibleBump compat_bump;
- NTapBump ntap_bump;
- MTex *mtex;
- Tex *tex;
- TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
- float *co = NULL, *dx = NULL, *dy = NULL;
- float fact, facm, factt, facmm, stencilTin=1.0;
- float texvec[3], dxt[3], dyt[3], tempvec[3], norvec[3], warpvec[3]={0.0f, 0.0f, 0.0f}, Tnor=1.0;
- int tex_nr, rgbnor= 0;
- bool warp_done = false, use_compat_bump = false, use_ntap_bump = false;
- bool found_nmapping = false, found_deriv_map = false;
- bool iFirstTimeNMap = true;
-
- compatible_bump_init(&compat_bump);
- ntap_bump_init(&ntap_bump);
-
- if (re->r.scemode & R_NO_TEX) return;
- /* here: test flag if there's a tex (todo) */
-
- for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
-
- /* separate tex switching */
- if (shi->mat->septex & (1<<tex_nr)) continue;
-
- if (shi->mat->mtex[tex_nr]) {
- mtex= shi->mat->mtex[tex_nr];
-
- tex= mtex->tex;
- if (tex == NULL) continue;
-
- found_deriv_map = (tex->type==TEX_IMAGE) && (tex->imaflag & TEX_DERIVATIVEMAP);
- use_compat_bump= (mtex->texflag & MTEX_COMPAT_BUMP) != 0;
- use_ntap_bump = ((mtex->texflag & (MTEX_3TAP_BUMP|MTEX_5TAP_BUMP|MTEX_BICUBIC_BUMP))!=0 || found_deriv_map!=0) ? true : false;
-
- /* XXX texture node trees don't work for this yet */
- if (tex->nodetree && tex->use_nodes) {
- use_compat_bump = false;
- use_ntap_bump = false;
- }
-
- /* case displacement mapping */
- if (shi->osatex == 0 && use_ntap_bump) {
- use_ntap_bump = false;
- use_compat_bump = true;
- }
-
- /* case ocean */
- if (tex->type == TEX_OCEAN) {
- use_ntap_bump = false;
- use_compat_bump = false;
- }
-
- /* which coords */
- if (mtex->texco==TEXCO_ORCO) {
- if (mtex->texflag & MTEX_DUPLI_MAPTO) {
- co= shi->duplilo; dx= dxt; dy= dyt;
- dxt[0]= dxt[1]= dxt[2]= 0.0f;
- dyt[0]= dyt[1]= dyt[2]= 0.0f;
- }
- else {
- co= shi->lo; dx= shi->dxlo; dy= shi->dylo;
- }
- }
- else if (mtex->texco==TEXCO_OBJECT) {
- Object *ob= mtex->object;
- if (ob) {
- co= tempvec;
- dx= dxt;
- dy= dyt;
- copy_v3_v3(tempvec, shi->co);
- if (mtex->texflag & MTEX_OB_DUPLI_ORIG)
- if (shi->obi && shi->obi->duplitexmat)
- mul_m4_v3(shi->obi->duplitexmat, tempvec);
- mul_m4_v3(ob->imat_ren, tempvec);
- if (shi->osatex) {
- copy_v3_v3(dxt, shi->dxco);
- copy_v3_v3(dyt, shi->dyco);
- mul_mat3_m4_v3(ob->imat_ren, dxt);
- mul_mat3_m4_v3(ob->imat_ren, dyt);
- }
- }
- else {
- /* if object doesn't exist, do not use orcos (not initialized) */
- co= shi->co;
- dx= shi->dxco; dy= shi->dyco;
- }
- }
- else if (mtex->texco==TEXCO_REFL) {
- calc_R_ref(shi);
- co= shi->ref; dx= shi->dxref; dy= shi->dyref;
- }
- else if (mtex->texco==TEXCO_NORM) {
- co= shi->orn; dx= shi->dxno; dy= shi->dyno;
- }
- else if (mtex->texco==TEXCO_TANGENT) {
- co= shi->tang; dx= shi->dxno; dy= shi->dyno;
- }
- else if (mtex->texco==TEXCO_GLOB) {
- co= shi->gl; dx= shi->dxgl; dy= shi->dygl;
- }
- else if (mtex->texco==TEXCO_UV) {
- if (mtex->texflag & MTEX_DUPLI_MAPTO) {
- co= shi->dupliuv; dx= dxt; dy= dyt;
- dxt[0]= dxt[1]= dxt[2]= 0.0f;
- dyt[0]= dyt[1]= dyt[2]= 0.0f;
- }
- else {
- ShadeInputUV *suv= &shi->uv[shi->actuv];
- int i = shi->actuv;
-
- if (mtex->uvname[0] != 0) {
- for (i = 0; i < shi->totuv; i++) {
- if (STREQ(shi->uv[i].name, mtex->uvname)) {
- suv= &shi->uv[i];
- break;
- }
- }
- }
-
- co= suv->uv;
- dx= suv->dxuv;
- dy= suv->dyuv;
-
- compatible_bump_uv_derivs(&compat_bump, shi, mtex, i);
- }
- }
- else if (mtex->texco==TEXCO_WINDOW) {
- co= shi->winco; dx= shi->dxwin; dy= shi->dywin;
- }
- else if (mtex->texco==TEXCO_STRAND) {
- co= tempvec; dx= dxt; dy= dyt;
- co[0]= shi->strandco;
- co[1]= co[2]= 0.0f;
- dx[0]= shi->dxstrand;
- dx[1]= dx[2]= 0.0f;
- dy[0]= shi->dystrand;
- dy[1]= dy[2]= 0.0f;
- }
- else if (mtex->texco==TEXCO_STRESS) {
- co= tempvec; dx= dxt; dy= dyt;
- co[0]= shi->stress;
- co[1]= co[2]= 0.0f;
- dx[0]= 0.0f;
- dx[1]= dx[2]= 0.0f;
- dy[0]= 0.0f;
- dy[1]= dy[2]= 0.0f;
- }
- else {
- continue; /* can happen when texco defines disappear and it renders old files */
- }
-
- /* the pointer defines if bumping happens */
- if (mtex->mapto & (MAP_NORM|MAP_WARP)) {
- texres.nor= norvec;
- norvec[0]= norvec[1]= norvec[2]= 0.0;
- }
- else texres.nor= NULL;
-
- if (warp_done) {
- add_v3_v3v3(tempvec, co, warpvec);
- co= tempvec;
- }
-
- /* XXX texture node trees don't work for this yet */
- if (texres.nor && !((tex->type==TEX_IMAGE) && (tex->imaflag & TEX_NORMALMAP))) {
- if (use_compat_bump) {
- rgbnor = compatible_bump_compute(&compat_bump, shi, mtex, tex,
- &texres, Tnor*stencilTin, co, dx, dy, texvec, dxt, dyt,
- re->pool, skip_load_image);
- }
- else if (use_ntap_bump) {
- rgbnor = ntap_bump_compute(&ntap_bump, shi, mtex, tex,
- &texres, Tnor*stencilTin, co, dx, dy, texvec, dxt, dyt,
- re->pool, skip_load_image);
- }
- else {
- texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
- rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, &texres, re->pool, skip_load_image);
- }
- }
- else {
- texco_mapping(shi, tex, mtex, co, dx, dy, texvec, dxt, dyt);
- rgbnor = multitex_mtex(shi, mtex, texvec, dxt, dyt, &texres, re->pool, skip_load_image);
- }
-
- /* texture output */
-
- if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
- texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- rgbnor -= TEX_RGB;
- }
- if (mtex->texflag & MTEX_NEGATIVE) {
- if (rgbnor & TEX_RGB) {
- texres.tr= 1.0f-texres.tr;
- texres.tg= 1.0f-texres.tg;
- texres.tb= 1.0f-texres.tb;
- }
- texres.tin= 1.0f-texres.tin;
- }
- if (mtex->texflag & MTEX_STENCIL) {
- if (rgbnor & TEX_RGB) {
- fact= texres.ta;
- texres.ta*= stencilTin;
- stencilTin*= fact;
- }
- else {
- fact= texres.tin;
- texres.tin*= stencilTin;
- stencilTin*= fact;
- }
- }
- else {
- Tnor*= stencilTin;
- }
-
- if (texres.nor) {
- if ((rgbnor & TEX_NOR)==0) {
- /* make our own normal */
- if (rgbnor & TEX_RGB) {
- copy_v3_v3(texres.nor, &texres.tr);
- }
- else {
- float co_nor= 0.5f * cosf(texres.tin - 0.5f);
- float si = 0.5f * sinf(texres.tin - 0.5f);
- float f1, f2;
-
- f1= shi->vn[0];
- f2= shi->vn[1];
- texres.nor[0]= f1*co_nor+f2*si;
- f1= shi->vn[1];
- f2= shi->vn[2];
- texres.nor[1]= f1*co_nor+f2*si;
- texres.nor[2]= f2*co_nor-f1*si;
- }
- }
- /* warping, local space */
- if (mtex->mapto & MAP_WARP) {
- float *warpnor= texres.nor, warpnor_[3];
-
- if (use_ntap_bump) {
- copy_v3_v3(warpnor_, texres.nor);
- warpnor= warpnor_;
- normalize_v3(warpnor_);
- }
- warpvec[0]= mtex->warpfac*warpnor[0];
- warpvec[1]= mtex->warpfac*warpnor[1];
- warpvec[2]= mtex->warpfac*warpnor[2];
- warp_done = true;
- }
-#if 0
- if (mtex->texflag & MTEX_VIEWSPACE) {
- /* rotate to global coords */
- if (mtex->texco==TEXCO_ORCO || mtex->texco==TEXCO_UV) {
- if (shi->vlr && shi->obr && shi->obr->ob) {
- float len= normalize_v3(texres.nor);
- /* can be optimized... (ton) */
- mul_mat3_m4_v3(shi->obr->ob->obmat, texres.nor);
- mul_mat3_m4_v3(re->viewmat, texres.nor);
- normalize_v3_length(texres.nor, len);
- }
- }
- }
-#endif
- }
-
- /* mapping */
- if (mtex->mapto & (MAP_COL | MAP_COLSPEC | MAP_COLMIR)) {
- float tcol[3];
-
- /* stencil maps on the texture control slider, not texture intensity value */
- copy_v3_v3(tcol, &texres.tr);
-
- if ((rgbnor & TEX_RGB) == 0) {
- copy_v3_v3(tcol, &mtex->r);
- }
- else if (mtex->mapto & MAP_ALPHA) {
- texres.tin = stencilTin;
- }
- else {
- texres.tin = texres.ta;
- }
-
- /* inverse gamma correction */
- if (tex->type==TEX_IMAGE) {
- Image *ima = tex->ima;
- ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, re->pool);
-
- /* don't linearize float buffers, assumed to be linear */
- if (ibuf != NULL &&
- ibuf->rect_float == NULL &&
- (rgbnor & TEX_RGB) &&
- R.scene_color_manage)
- {
- IMB_colormanagement_colorspace_to_scene_linear_v3(tcol, ibuf->rect_colorspace);
- }
-
- BKE_image_pool_release_ibuf(ima, ibuf, re->pool);
- }
-
- if (mtex->mapto & MAP_COL) {
- float colfac= mtex->colfac*stencilTin;
- texture_rgb_blend(&shi->r, tcol, &shi->r, texres.tin, colfac, mtex->blendtype);
- }
- if (mtex->mapto & MAP_COLSPEC) {
- float colspecfac= mtex->colspecfac*stencilTin;
- texture_rgb_blend(&shi->specr, tcol, &shi->specr, texres.tin, colspecfac, mtex->blendtype);
- }
- if (mtex->mapto & MAP_COLMIR) {
- float mirrfac= mtex->mirrfac*stencilTin;
-
- /* exception for envmap only */
- if (tex->type==TEX_ENVMAP && mtex->blendtype==MTEX_BLEND) {
- fact= texres.tin*mirrfac;
- facm= 1.0f- fact;
- shi->refcol[0]= fact + facm*shi->refcol[0];
- shi->refcol[1]= fact*tcol[0] + facm*shi->refcol[1];
- shi->refcol[2]= fact*tcol[1] + facm*shi->refcol[2];
- shi->refcol[3]= fact*tcol[2] + facm*shi->refcol[3];
- }
- else {
- texture_rgb_blend(&shi->mirr, tcol, &shi->mirr, texres.tin, mirrfac, mtex->blendtype);
- }
- }
- }
- if ( (mtex->mapto & MAP_NORM) ) {
- if (texres.nor) {
- float norfac= mtex->norfac;
-
- /* we need to code blending modes for normals too once.. now 1 exception hardcoded */
-
- if ((tex->type==TEX_IMAGE) && (tex->imaflag & TEX_NORMALMAP)) {
-
- found_nmapping = 1;
-
- /* qdn: for normalmaps, to invert the normalmap vector,
- * it is better to negate x & y instead of subtracting the vector as was done before */
- if (norfac < 0.0f) {
- texres.nor[0] = -texres.nor[0];
- texres.nor[1] = -texres.nor[1];
- }
- fact = Tnor*fabsf(norfac);
- if (fact>1.f) fact = 1.f;
- facm = 1.f-fact;
- if (mtex->normapspace == MTEX_NSPACE_TANGENT) {
- /* qdn: tangent space */
- float B[3], tv[3];
- const float *no = iFirstTimeNMap ? shi->nmapnorm : shi->vn;
- iFirstTimeNMap = false;
- cross_v3_v3v3(B, no, shi->nmaptang); /* bitangent */
- mul_v3_fl(B, shi->nmaptang[3]);
- /* transform norvec from tangent space to object surface in camera space */
- tv[0] = texres.nor[0]*shi->nmaptang[0] + texres.nor[1]*B[0] + texres.nor[2]*no[0];
- tv[1] = texres.nor[0]*shi->nmaptang[1] + texres.nor[1]*B[1] + texres.nor[2]*no[1];
- tv[2] = texres.nor[0]*shi->nmaptang[2] + texres.nor[1]*B[2] + texres.nor[2]*no[2];
- shi->vn[0]= facm*no[0] + fact*tv[0];
- shi->vn[1]= facm*no[1] + fact*tv[1];
- shi->vn[2]= facm*no[2] + fact*tv[2];
- }
- else {
- float nor[3];
-
- copy_v3_v3(nor, texres.nor);
-
- if (mtex->normapspace == MTEX_NSPACE_CAMERA) {
- /* pass */
- }
- else if (mtex->normapspace == MTEX_NSPACE_WORLD) {
- mul_mat3_m4_v3(re->viewmat, nor);
- }
- else if (mtex->normapspace == MTEX_NSPACE_OBJECT) {
- if (shi->obr && shi->obr->ob)
- mul_mat3_m4_v3(shi->obr->ob->obmat, nor);
- mul_mat3_m4_v3(re->viewmat, nor);
- }
-
- normalize_v3(nor);
-
- /* qdn: worldspace */
- shi->vn[0]= facm*shi->vn[0] + fact*nor[0];
- shi->vn[1]= facm*shi->vn[1] + fact*nor[1];
- shi->vn[2]= facm*shi->vn[2] + fact*nor[2];
- }
- }
- else {
- /* XXX texture node trees don't work for this yet */
- if (use_compat_bump || use_ntap_bump) {
- shi->vn[0] = texres.nor[0];
- shi->vn[1] = texres.nor[1];
- shi->vn[2] = texres.nor[2];
- }
- else {
- float nor[3], dot;
-
- if (shi->mat->mode & MA_TANGENT_V) {
- shi->tang[0]+= Tnor*norfac*texres.nor[0];
- shi->tang[1]+= Tnor*norfac*texres.nor[1];
- shi->tang[2]+= Tnor*norfac*texres.nor[2];
- }
-
- /* prevent bump to become negative normal */
- nor[0]= Tnor*norfac*texres.nor[0];
- nor[1]= Tnor*norfac*texres.nor[1];
- nor[2]= Tnor*norfac*texres.nor[2];
-
- dot= 0.5f + 0.5f * dot_v3v3(nor, shi->vn);
-
- shi->vn[0]+= dot*nor[0];
- shi->vn[1]+= dot*nor[1];
- shi->vn[2]+= dot*nor[2];
- }
- }
- normalize_v3(shi->vn);
-
- /* this makes sure the bump is passed on to the next texture */
- shi->orn[0]= -shi->vn[0];
- shi->orn[1]= -shi->vn[1];
- shi->orn[2]= -shi->vn[2];
- }
- }
-
- if ( mtex->mapto & MAP_DISPLACE ) {
- /* Now that most textures offer both Nor and Intensity, allow */
- /* both to work, and let user select with slider. */
- if (texres.nor) {
- float norfac= mtex->norfac;
-
- shi->displace[0]+= 0.2f*Tnor*norfac*texres.nor[0];
- shi->displace[1]+= 0.2f*Tnor*norfac*texres.nor[1];
- shi->displace[2]+= 0.2f*Tnor*norfac*texres.nor[2];
- }
-
- if (rgbnor & TEX_RGB) {
- texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- }
-
- factt= (0.5f-texres.tin)*mtex->dispfac*stencilTin; facmm= 1.0f-factt;
-
- if (mtex->blendtype==MTEX_BLEND) {
- shi->displace[0]= factt*shi->vn[0] + facmm*shi->displace[0];
- shi->displace[1]= factt*shi->vn[1] + facmm*shi->displace[1];
- shi->displace[2]= factt*shi->vn[2] + facmm*shi->displace[2];
- }
- else if (mtex->blendtype==MTEX_MUL) {
- shi->displace[0]*= factt*shi->vn[0];
- shi->displace[1]*= factt*shi->vn[1];
- shi->displace[2]*= factt*shi->vn[2];
- }
- else { /* add or sub */
- if (mtex->blendtype==MTEX_SUB) factt= -factt;
- shi->displace[0]+= factt*shi->vn[0];
- shi->displace[1]+= factt*shi->vn[1];
- shi->displace[2]+= factt*shi->vn[2];
- }
- }
-
- if (mtex->mapto & MAP_VARS) {
- /* stencil maps on the texture control slider, not texture intensity value */
-
- if (rgbnor & TEX_RGB) {
- if (texres.talpha) texres.tin = texres.ta;
- else texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- }
-
- if (mtex->mapto & MAP_REF) {
- float difffac= mtex->difffac*stencilTin;
-
- shi->refl= texture_value_blend(mtex->def_var, shi->refl, texres.tin, difffac, mtex->blendtype);
- if (shi->refl<0.0f) shi->refl= 0.0f;
- }
- if (mtex->mapto & MAP_SPEC) {
- float specfac= mtex->specfac*stencilTin;
-
- shi->spec= texture_value_blend(mtex->def_var, shi->spec, texres.tin, specfac, mtex->blendtype);
- if (shi->spec<0.0f) shi->spec= 0.0f;
- }
- if (mtex->mapto & MAP_EMIT) {
- float emitfac= mtex->emitfac*stencilTin;
-
- shi->emit= texture_value_blend(mtex->def_var, shi->emit, texres.tin, emitfac, mtex->blendtype);
- if (shi->emit<0.0f) shi->emit= 0.0f;
- }
- if (mtex->mapto & MAP_ALPHA) {
- float alphafac= mtex->alphafac*stencilTin;
-
- shi->alpha= texture_value_blend(mtex->def_var, shi->alpha, texres.tin, alphafac, mtex->blendtype);
- if (shi->alpha<0.0f) shi->alpha= 0.0f;
- else if (shi->alpha>1.0f) shi->alpha= 1.0f;
- }
- if (mtex->mapto & MAP_HAR) {
- float har; /* have to map to 0-1 */
- float hardfac= mtex->hardfac*stencilTin;
-
- har= ((float)shi->har)/128.0f;
- har= 128.0f*texture_value_blend(mtex->def_var, har, texres.tin, hardfac, mtex->blendtype);
-
- if (har<1.0f) shi->har= 1;
- else if (har>511) shi->har= 511;
- else shi->har= (int)har;
- }
- if (mtex->mapto & MAP_RAYMIRR) {
- float raymirrfac= mtex->raymirrfac*stencilTin;
-
- shi->ray_mirror= texture_value_blend(mtex->def_var, shi->ray_mirror, texres.tin, raymirrfac, mtex->blendtype);
- if (shi->ray_mirror<0.0f) shi->ray_mirror= 0.0f;
- else if (shi->ray_mirror>1.0f) shi->ray_mirror= 1.0f;
- }
- if (mtex->mapto & MAP_TRANSLU) {
- float translfac= mtex->translfac*stencilTin;
-
- shi->translucency= texture_value_blend(mtex->def_var, shi->translucency, texres.tin, translfac, mtex->blendtype);
- if (shi->translucency<0.0f) shi->translucency= 0.0f;
- else if (shi->translucency>1.0f) shi->translucency= 1.0f;
- }
- if (mtex->mapto & MAP_AMB) {
- float ambfac= mtex->ambfac*stencilTin;
-
- shi->amb= texture_value_blend(mtex->def_var, shi->amb, texres.tin, ambfac, mtex->blendtype);
- if (shi->amb<0.0f) shi->amb= 0.0f;
- else if (shi->amb>1.0f) shi->amb= 1.0f;
-
- shi->ambr= shi->amb*re->wrld.ambr;
- shi->ambg= shi->amb*re->wrld.ambg;
- shi->ambb= shi->amb*re->wrld.ambb;
- }
- }
- }
- }
- if ((use_compat_bump || use_ntap_bump || found_nmapping) && (shi->mat->mode & MA_TANGENT_V) != 0) {
- const float fnegdot = -dot_v3v3(shi->vn, shi->tang);
- /* apply Gram-Schmidt projection */
- madd_v3_v3fl(shi->tang, shi->vn, fnegdot);
- normalize_v3(shi->tang);
- }
-}
-
-
-void do_volume_tex(ShadeInput *shi, const float *xyz, int mapto_flag, float col_r[3], float *val, Render *re)
-{
- const bool skip_load_image = (re->r.scemode & R_NO_IMAGE_LOAD) != 0;
- const bool texnode_preview = (re->r.scemode & R_TEXNODE_PREVIEW) != 0;
- MTex *mtex;
- Tex *tex;
- TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
- int tex_nr, rgbnor= 0;
- float co[3], texvec[3];
- float fact, stencilTin=1.0;
-
- if (re->r.scemode & R_NO_TEX) return;
- /* here: test flag if there's a tex (todo) */
-
- for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
- /* separate tex switching */
- if (shi->mat->septex & (1<<tex_nr)) continue;
-
- if (shi->mat->mtex[tex_nr]) {
- mtex= shi->mat->mtex[tex_nr];
- tex= mtex->tex;
- if (tex == NULL) continue;
-
- /* only process if this texture is mapped
- * to one that we're interested in */
- if (!(mtex->mapto & mapto_flag)) continue;
-
- /* which coords */
- if (mtex->texco==TEXCO_OBJECT) {
- Object *ob= mtex->object;
- if (ob) {
- copy_v3_v3(co, xyz);
- if (mtex->texflag & MTEX_OB_DUPLI_ORIG) {
- if (shi->obi && shi->obi->duplitexmat)
- mul_m4_v3(shi->obi->duplitexmat, co);
- }
- mul_m4_v3(ob->imat_ren, co);
-
- if (mtex->texflag & MTEX_MAPTO_BOUNDS && ob->bb) {
- /* use bb vec[0] as min and bb vec[6] as max */
- co[0] = (co[0] - ob->bb->vec[0][0]) / (ob->bb->vec[6][0]-ob->bb->vec[0][0]) * 2.0f - 1.0f;
- co[1] = (co[1] - ob->bb->vec[0][1]) / (ob->bb->vec[6][1]-ob->bb->vec[0][1]) * 2.0f - 1.0f;
- co[2] = (co[2] - ob->bb->vec[0][2]) / (ob->bb->vec[6][2]-ob->bb->vec[0][2]) * 2.0f - 1.0f;
- }
- }
- }
- /* not really orco, but 'local' */
- else if (mtex->texco==TEXCO_ORCO) {
-
- if (mtex->texflag & MTEX_DUPLI_MAPTO) {
- copy_v3_v3(co, shi->duplilo);
- }
- else {
- Object *ob= shi->obi->ob;
- copy_v3_v3(co, xyz);
- mul_m4_v3(ob->imat_ren, co);
-
- if (mtex->texflag & MTEX_MAPTO_BOUNDS && ob->bb) {
- /* use bb vec[0] as min and bb vec[6] as max */
- co[0] = (co[0] - ob->bb->vec[0][0]) / (ob->bb->vec[6][0]-ob->bb->vec[0][0]) * 2.0f - 1.0f;
- co[1] = (co[1] - ob->bb->vec[0][1]) / (ob->bb->vec[6][1]-ob->bb->vec[0][1]) * 2.0f - 1.0f;
- co[2] = (co[2] - ob->bb->vec[0][2]) / (ob->bb->vec[6][2]-ob->bb->vec[0][2]) * 2.0f - 1.0f;
- }
- }
- }
- else if (mtex->texco==TEXCO_GLOB) {
- copy_v3_v3(co, xyz);
- mul_m4_v3(re->viewinv, co);
- }
- else {
- continue; /* can happen when texco defines disappear and it renders old files */
- }
-
- texres.nor= NULL;
-
- if (tex->type == TEX_IMAGE) {
- continue; /* not supported yet */
- //do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt);
- }
- else {
- /* placement */
- if (mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]);
- else texvec[0]= mtex->size[0]*(mtex->ofs[0]);
-
- if (mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]);
- else texvec[1]= mtex->size[1]*(mtex->ofs[1]);
-
- if (mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]);
- else texvec[2]= mtex->size[2]*(mtex->ofs[2]);
- }
-
- rgbnor = multitex(tex,
- texvec,
- NULL, NULL,
- 0,
- &texres,
- shi->thread,
- mtex->which_output,
- re->pool,
- skip_load_image,
- texnode_preview,
- true); /* NULL = dxt/dyt, 0 = shi->osatex - not supported */
-
- /* texture output */
-
- if ((rgbnor & TEX_RGB) && (mtex->texflag & MTEX_RGBTOINT)) {
- texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- rgbnor -= TEX_RGB;
- }
- if (mtex->texflag & MTEX_NEGATIVE) {
- if (rgbnor & TEX_RGB) {
- texres.tr= 1.0f-texres.tr;
- texres.tg= 1.0f-texres.tg;
- texres.tb= 1.0f-texres.tb;
- }
- texres.tin= 1.0f-texres.tin;
- }
- if (mtex->texflag & MTEX_STENCIL) {
- if (rgbnor & TEX_RGB) {
- fact= texres.ta;
- texres.ta*= stencilTin;
- stencilTin*= fact;
- }
- else {
- fact= texres.tin;
- texres.tin*= stencilTin;
- stencilTin*= fact;
- }
- }
-
-
- if ((mapto_flag & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL)) && (mtex->mapto & (MAP_EMISSION_COL+MAP_TRANSMISSION_COL+MAP_REFLECTION_COL))) {
- float tcol[3];
-
- /* stencil maps on the texture control slider, not texture intensity value */
-
- if ((rgbnor & TEX_RGB) == 0) {
- copy_v3_v3(tcol, &mtex->r);
- }
- else if (mtex->mapto & MAP_DENSITY) {
- copy_v3_v3(tcol, &texres.tr);
- if (texres.talpha) {
- texres.tin = stencilTin;
- }
- }
- else {
- copy_v3_v3(tcol, &texres.tr);
- if (texres.talpha) {
- texres.tin= texres.ta;
- }
- }
-
- /* used for emit */
- if ((mapto_flag & MAP_EMISSION_COL) && (mtex->mapto & MAP_EMISSION_COL)) {
- float colemitfac= mtex->colemitfac*stencilTin;
- texture_rgb_blend(col_r, tcol, col_r, texres.tin, colemitfac, mtex->blendtype);
- }
-
- if ((mapto_flag & MAP_REFLECTION_COL) && (mtex->mapto & MAP_REFLECTION_COL)) {
- float colreflfac= mtex->colreflfac*stencilTin;
- texture_rgb_blend(col_r, tcol, col_r, texres.tin, colreflfac, mtex->blendtype);
- }
-
- if ((mapto_flag & MAP_TRANSMISSION_COL) && (mtex->mapto & MAP_TRANSMISSION_COL)) {
- float coltransfac= mtex->coltransfac*stencilTin;
- texture_rgb_blend(col_r, tcol, col_r, texres.tin, coltransfac, mtex->blendtype);
- }
- }
-
- if ((mapto_flag & MAP_VARS) && (mtex->mapto & MAP_VARS)) {
- /* stencil maps on the texture control slider, not texture intensity value */
-
- /* convert RGB to intensity if intensity info isn't provided */
- if (rgbnor & TEX_RGB) {
- if (texres.talpha) texres.tin = texres.ta;
- else texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- }
-
- if ((mapto_flag & MAP_EMISSION) && (mtex->mapto & MAP_EMISSION)) {
- float emitfac= mtex->emitfac*stencilTin;
-
- *val = texture_value_blend(mtex->def_var, *val, texres.tin, emitfac, mtex->blendtype);
- if (*val<0.0f) *val= 0.0f;
- }
- if ((mapto_flag & MAP_DENSITY) && (mtex->mapto & MAP_DENSITY)) {
- float densfac= mtex->densfac*stencilTin;
-
- *val = texture_value_blend(mtex->def_var, *val, texres.tin, densfac, mtex->blendtype);
- CLAMP(*val, 0.0f, 1.0f);
- }
- if ((mapto_flag & MAP_SCATTERING) && (mtex->mapto & MAP_SCATTERING)) {
- float scatterfac= mtex->scatterfac*stencilTin;
-
- *val = texture_value_blend(mtex->def_var, *val, texres.tin, scatterfac, mtex->blendtype);
- CLAMP(*val, 0.0f, 1.0f);
- }
- if ((mapto_flag & MAP_REFLECTION) && (mtex->mapto & MAP_REFLECTION)) {
- float reflfac= mtex->reflfac*stencilTin;
-
- *val = texture_value_blend(mtex->def_var, *val, texres.tin, reflfac, mtex->blendtype);
- CLAMP(*val, 0.0f, 1.0f);
- }
- }
- }
- }
-}
-
-
-/* ------------------------------------------------------------------------- */
-
-void do_halo_tex(HaloRen *har, float xn, float yn, float col_r[4])
-{
- const bool skip_load_image = har->skip_load_image;
- const bool texnode_preview = har->texnode_preview;
- MTex *mtex;
- TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
- float texvec[3], dxt[3], dyt[3], fact, facm, dx;
- int rgb, osatex;
-
- if (R.r.scemode & R_NO_TEX) return;
-
- mtex= har->mat->mtex[0];
- if (har->mat->septex & (1<<0)) return;
- if (mtex->tex==NULL) return;
-
- /* no normal mapping */
- texres.nor= NULL;
-
- texvec[0]= xn/har->rad;
- texvec[1]= yn/har->rad;
- texvec[2]= 0.0;
-
- osatex= (har->mat->texco & TEXCO_OSA);
-
- /* placement */
- if (mtex->projx) texvec[0]= mtex->size[0]*(texvec[mtex->projx-1]+mtex->ofs[0]);
- else texvec[0]= mtex->size[0]*(mtex->ofs[0]);
-
- if (mtex->projy) texvec[1]= mtex->size[1]*(texvec[mtex->projy-1]+mtex->ofs[1]);
- else texvec[1]= mtex->size[1]*(mtex->ofs[1]);
-
- if (mtex->projz) texvec[2]= mtex->size[2]*(texvec[mtex->projz-1]+mtex->ofs[2]);
- else texvec[2]= mtex->size[2]*(mtex->ofs[2]);
-
- if (osatex) {
-
- dx= 1.0f/har->rad;
-
- if (mtex->projx) {
- dxt[0]= mtex->size[0]*dx;
- dyt[0]= mtex->size[0]*dx;
- }
- else dxt[0]= dyt[0]= 0.0;
-
- if (mtex->projy) {
- dxt[1]= mtex->size[1]*dx;
- dyt[1]= mtex->size[1]*dx;
- }
- else dxt[1]= dyt[1]= 0.0;
-
- if (mtex->projz) {
- dxt[2]= 0.0;
- dyt[2]= 0.0;
- }
- else dxt[2]= dyt[2]= 0.0;
-
- }
-
- if (mtex->tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt);
-
- rgb = multitex(mtex->tex,
- texvec,
- dxt, dyt,
- osatex,
- &texres,
- 0,
- mtex->which_output,
- har->pool,
- skip_load_image,
- texnode_preview,
- true);
-
- /* texture output */
- if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
- texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- rgb= 0;
- }
- if (mtex->texflag & MTEX_NEGATIVE) {
- if (rgb) {
- texres.tr= 1.0f-texres.tr;
- texres.tg= 1.0f-texres.tg;
- texres.tb= 1.0f-texres.tb;
- }
- else texres.tin= 1.0f-texres.tin;
- }
-
- /* mapping */
- if (mtex->mapto & MAP_COL) {
-
- if (rgb==0) {
- texres.tr= mtex->r;
- texres.tg= mtex->g;
- texres.tb= mtex->b;
- }
- else if (mtex->mapto & MAP_ALPHA) {
- texres.tin= 1.0;
- }
- else texres.tin= texres.ta;
-
- /* inverse gamma correction */
- if (mtex->tex->type==TEX_IMAGE) {
- Image *ima = mtex->tex->ima;
- ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &mtex->tex->iuser, har->pool);
-
- /* don't linearize float buffers, assumed to be linear */
- if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
- IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace);
-
- BKE_image_pool_release_ibuf(ima, ibuf, har->pool);
- }
-
- fact= texres.tin*mtex->colfac;
- facm= 1.0f-fact;
-
- if (mtex->blendtype==MTEX_MUL) {
- facm= 1.0f-mtex->colfac;
- }
-
- if (mtex->blendtype==MTEX_SUB) fact= -fact;
-
- if (mtex->blendtype==MTEX_BLEND) {
- col_r[0]= (fact*texres.tr + facm*har->r);
- col_r[1]= (fact*texres.tg + facm*har->g);
- col_r[2]= (fact*texres.tb + facm*har->b);
- }
- else if (mtex->blendtype==MTEX_MUL) {
- col_r[0]= (facm+fact*texres.tr)*har->r;
- col_r[1]= (facm+fact*texres.tg)*har->g;
- col_r[2]= (facm+fact*texres.tb)*har->b;
- }
- else {
- col_r[0]= (fact*texres.tr + har->r);
- col_r[1]= (fact*texres.tg + har->g);
- col_r[2]= (fact*texres.tb + har->b);
-
- CLAMP(col_r[0], 0.0f, 1.0f);
- CLAMP(col_r[1], 0.0f, 1.0f);
- CLAMP(col_r[2], 0.0f, 1.0f);
- }
- }
- if (mtex->mapto & MAP_ALPHA) {
- if (rgb) {
- if (texres.talpha) {
- texres.tin = texres.ta;
- }
- else {
- texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- }
- }
-
- col_r[3]*= texres.tin;
- }
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* hor and zen are RGB vectors, blend is 1 float, should all be initialized */
-void do_sky_tex(
- const float rco[3], const float view[3], const float lo[3], const float dxyview[2],
- float hor[3], float zen[3], float *blend, int skyflag, short thread)
-{
- const bool skip_load_image = (R.r.scemode & R_NO_IMAGE_LOAD) != 0;
- const bool texnode_preview = (R.r.scemode & R_TEXNODE_PREVIEW) != 0;
- MTex *mtex;
- Tex *tex;
- TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
- float fact, stencilTin=1.0;
- float tempvec[3], texvec[3], dxt[3], dyt[3];
- int tex_nr, rgb= 0;
-
- if (R.r.scemode & R_NO_TEX) return;
- /* todo: add flag to test if there's a tex */
- texres.nor= NULL;
-
- for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
- if (R.wrld.mtex[tex_nr]) {
- const float *co;
-
- mtex= R.wrld.mtex[tex_nr];
-
- tex= mtex->tex;
- if (tex == NULL) continue;
- /* if (mtex->mapto==0) continue; */
-
- /* which coords */
- co= lo;
-
- /* dxt dyt just from 1 value */
- if (dxyview) {
- dxt[0]= dxt[1]= dxt[2]= dxyview[0];
- dyt[0]= dyt[1]= dyt[2]= dxyview[1];
- }
- else {
- dxt[0]= dxt[1]= dxt[2]= 0.0;
- dyt[0]= dyt[1]= dyt[2]= 0.0;
- }
-
- /* Grab the mapping settings for this texture */
- switch (mtex->texco) {
- case TEXCO_ANGMAP:
- /* only works with texture being "real" */
- /* use saacos(), fixes bug [#22398], float precision caused lo[2] to be slightly less than -1.0 */
- if (lo[0] || lo[1]) { /* check for zero case [#24807] */
- fact= (1.0f/(float)M_PI)*saacos(lo[2])/(sqrtf(lo[0]*lo[0] + lo[1]*lo[1]));
- tempvec[0]= lo[0]*fact;
- tempvec[1]= lo[1]*fact;
- tempvec[2]= 0.0;
- }
- else {
- /* this value has no angle, the vector is directly along the view.
- * avoid divide by zero and use a dummy value. */
- tempvec[0]= 1.0f;
- tempvec[1]= 0.0;
- tempvec[2]= 0.0;
- }
- co= tempvec;
- break;
-
- case TEXCO_H_SPHEREMAP:
- case TEXCO_H_TUBEMAP:
- if (skyflag & WO_ZENUP) {
- if (mtex->texco==TEXCO_H_TUBEMAP) map_to_tube( tempvec, tempvec+1, lo[0], lo[2], lo[1]);
- else map_to_sphere(tempvec, tempvec+1, lo[0], lo[2], lo[1]);
- /* tube/spheremap maps for outside view, not inside */
- tempvec[0]= 1.0f-tempvec[0];
- /* only top half */
- tempvec[1]= 2.0f*tempvec[1]-1.0f;
- tempvec[2]= 0.0;
- /* and correction for do_2d_mapping */
- tempvec[0]= 2.0f*tempvec[0]-1.0f;
- tempvec[1]= 2.0f*tempvec[1]-1.0f;
- co= tempvec;
- }
- else {
- /* potentially dangerous... check with multitex! */
- continue;
- }
- break;
- case TEXCO_EQUIRECTMAP:
- tempvec[0]= -atan2f(lo[2], lo[0]) / (float)M_PI;
- tempvec[1]= atan2f(lo[1], hypot(lo[0], lo[2])) / (float)M_PI_2;
- tempvec[2]= 0.0f;
- co= tempvec;
- break;
- case TEXCO_OBJECT:
- if (mtex->object) {
- copy_v3_v3(tempvec, lo);
- mul_m4_v3(mtex->object->imat_ren, tempvec);
- co= tempvec;
- }
- break;
-
- case TEXCO_GLOB:
- if (rco) {
- copy_v3_v3(tempvec, rco);
- mul_m4_v3(R.viewinv, tempvec);
- co= tempvec;
- }
- else
- co= lo;
-
-// copy_v3_v3(shi->dxgl, shi->dxco);
-// mul_m3_v3(R.imat, shi->dxco);
-// copy_v3_v3(shi->dygl, shi->dyco);
-// mul_m3_v3(R.imat, shi->dyco);
- break;
- case TEXCO_VIEW:
- co = view;
- break;
- }
-
- /* placement */
- if (mtex->projx) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]);
- else texvec[0]= mtex->size[0]*(mtex->ofs[0]);
-
- if (mtex->projy) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]);
- else texvec[1]= mtex->size[1]*(mtex->ofs[1]);
-
- if (mtex->projz) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]);
- else texvec[2]= mtex->size[2]*(mtex->ofs[2]);
-
- /* texture */
- if (tex->type==TEX_IMAGE) do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt);
-
- rgb = multitex(mtex->tex,
- texvec,
- dxt, dyt,
- R.osa,
- &texres,
- thread,
- mtex->which_output,
- R.pool,
- skip_load_image,
- texnode_preview,
- true);
-
- /* texture output */
- if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
- texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- rgb= 0;
- }
- if (mtex->texflag & MTEX_NEGATIVE) {
- if (rgb) {
- texres.tr= 1.0f-texres.tr;
- texres.tg= 1.0f-texres.tg;
- texres.tb= 1.0f-texres.tb;
- }
- else texres.tin= 1.0f-texres.tin;
- }
- if (mtex->texflag & MTEX_STENCIL) {
- if (rgb) {
- fact= texres.ta;
- texres.ta*= stencilTin;
- stencilTin*= fact;
- }
- else {
- fact= texres.tin;
- texres.tin*= stencilTin;
- stencilTin*= fact;
- }
- }
- else {
- if (rgb) texres.ta *= stencilTin;
- else texres.tin*= stencilTin;
- }
-
- /* color mapping */
- if (mtex->mapto & (WOMAP_HORIZ+WOMAP_ZENUP+WOMAP_ZENDOWN)) {
- float tcol[3];
-
- if (rgb==0) {
- texres.tr= mtex->r;
- texres.tg= mtex->g;
- texres.tb= mtex->b;
- }
- else texres.tin= texres.ta;
-
- tcol[0]= texres.tr; tcol[1]= texres.tg; tcol[2]= texres.tb;
-
- /* inverse gamma correction */
- if (tex->type==TEX_IMAGE) {
- Image *ima = tex->ima;
- ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, R.pool);
-
- /* don't linearize float buffers, assumed to be linear */
- if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
- IMB_colormanagement_colorspace_to_scene_linear_v3(tcol, ibuf->rect_colorspace);
-
- BKE_image_pool_release_ibuf(ima, ibuf, R.pool);
- }
-
- if (mtex->mapto & WOMAP_HORIZ) {
- texture_rgb_blend(hor, tcol, hor, texres.tin, mtex->colfac, mtex->blendtype);
- }
- if (mtex->mapto & (WOMAP_ZENUP+WOMAP_ZENDOWN)) {
- float zenfac = 0.0f;
-
- if (R.wrld.skytype & WO_SKYREAL) {
- if ((skyflag & WO_ZENUP)) {
- if (mtex->mapto & WOMAP_ZENUP) zenfac= mtex->zenupfac;
- }
- else if (mtex->mapto & WOMAP_ZENDOWN) zenfac= mtex->zendownfac;
- }
- else {
- if (mtex->mapto & WOMAP_ZENUP) zenfac= mtex->zenupfac;
- else if (mtex->mapto & WOMAP_ZENDOWN) zenfac= mtex->zendownfac;
- }
-
- if (zenfac != 0.0f)
- texture_rgb_blend(zen, tcol, zen, texres.tin, zenfac, mtex->blendtype);
- }
- }
- if (mtex->mapto & WOMAP_BLEND) {
- if (rgb) texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
-
- *blend= texture_value_blend(mtex->def_var, *blend, texres.tin, mtex->blendfac, mtex->blendtype);
- }
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-/* col_r supposed to be initialized with la->r,g,b */
-
-void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r[3], int effect)
-{
- const bool skip_load_image = (R.r.scemode & R_NO_IMAGE_LOAD) != 0;
- const bool texnode_preview = (R.r.scemode & R_TEXNODE_PREVIEW) != 0;
- Object *ob;
- MTex *mtex;
- Tex *tex;
- TexResult texres= {0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0, NULL};
- float *co = NULL, *dx = NULL, *dy = NULL, fact, stencilTin=1.0;
- float texvec[3], dxt[3], dyt[3], tempvec[3];
- int i, tex_nr, rgb= 0;
-
- if (R.r.scemode & R_NO_TEX) return;
- tex_nr= 0;
-
- for (; tex_nr<MAX_MTEX; tex_nr++) {
-
- if (la->mtex[tex_nr]) {
- mtex= la->mtex[tex_nr];
-
- tex= mtex->tex;
- if (tex==NULL) continue;
- texres.nor= NULL;
-
- /* which coords */
- if (mtex->texco==TEXCO_OBJECT) {
- ob= mtex->object;
- if (ob) {
- co= tempvec;
- dx= dxt;
- dy= dyt;
- copy_v3_v3(tempvec, shi->co);
- mul_m4_v3(ob->imat_ren, tempvec);
- if (shi->osatex) {
- copy_v3_v3(dxt, shi->dxco);
- copy_v3_v3(dyt, shi->dyco);
- mul_mat3_m4_v3(ob->imat_ren, dxt);
- mul_mat3_m4_v3(ob->imat_ren, dyt);
- }
- }
- else {
- co= shi->co;
- dx= shi->dxco; dy= shi->dyco;
- }
- }
- else if (mtex->texco==TEXCO_GLOB) {
- co= shi->gl; dx= shi->dxco; dy= shi->dyco;
- copy_v3_v3(shi->gl, shi->co);
- mul_m4_v3(R.viewinv, shi->gl);
- }
- else if (mtex->texco==TEXCO_VIEW) {
-
- copy_v3_v3(tempvec, lavec);
- mul_m3_v3(la->imat, tempvec);
-
- if (la->type==LA_SPOT) {
- tempvec[0]*= la->spottexfac;
- tempvec[1]*= la->spottexfac;
- /* project from 3d to 2d */
- tempvec[0] /= -tempvec[2];
- tempvec[1] /= -tempvec[2];
- }
- co= tempvec;
-
- dx= dxt; dy= dyt;
- if (shi->osatex) {
- copy_v3_v3(dxt, shi->dxlv);
- copy_v3_v3(dyt, shi->dylv);
- /* need some matrix conversion here? la->imat is a [3][3] matrix!!! **/
- mul_m3_v3(la->imat, dxt);
- mul_m3_v3(la->imat, dyt);
-
- mul_v3_fl(dxt, la->spottexfac);
- mul_v3_fl(dyt, la->spottexfac);
- }
- }
-
-
- /* placement */
- if (mtex->projx && co) texvec[0]= mtex->size[0]*(co[mtex->projx-1]+mtex->ofs[0]);
- else texvec[0]= mtex->size[0]*(mtex->ofs[0]);
-
- if (mtex->projy && co) texvec[1]= mtex->size[1]*(co[mtex->projy-1]+mtex->ofs[1]);
- else texvec[1]= mtex->size[1]*(mtex->ofs[1]);
-
- if (mtex->projz && co) texvec[2]= mtex->size[2]*(co[mtex->projz-1]+mtex->ofs[2]);
- else texvec[2]= mtex->size[2]*(mtex->ofs[2]);
-
- if (shi->osatex) {
- if (!dx) {
- for (i=0;i<2;i++) {
- dxt[i] = dyt[i] = 0.0;
- }
- }
- else {
- if (mtex->projx) {
- dxt[0]= mtex->size[0]*dx[mtex->projx-1];
- dyt[0]= mtex->size[0]*dy[mtex->projx-1];
- }
- else {
- dxt[0]= 0.0;
- dyt[0]= 0.0;
- }
- if (mtex->projy) {
- dxt[1]= mtex->size[1]*dx[mtex->projy-1];
- dyt[1]= mtex->size[1]*dy[mtex->projy-1];
- }
- else {
- dxt[1]= 0.0;
- dyt[1]= 0.0;
- }
- if (mtex->projz) {
- dxt[2]= mtex->size[2]*dx[mtex->projz-1];
- dyt[2]= mtex->size[2]*dy[mtex->projz-1];
- }
- else {
- dxt[2]= 0.0;
- dyt[2]= 0.0;
- }
- }
- }
-
- /* texture */
- if (tex->type==TEX_IMAGE) {
- do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt);
- }
-
- rgb = multitex(tex,
- texvec,
- dxt, dyt,
- shi->osatex,
- &texres,
- shi->thread,
- mtex->which_output,
- R.pool,
- skip_load_image,
- texnode_preview,
- true);
-
- /* texture output */
- if (rgb && (mtex->texflag & MTEX_RGBTOINT)) {
- texres.tin = IMB_colormanagement_get_luminance(&texres.tr);
- rgb= 0;
- }
- if (mtex->texflag & MTEX_NEGATIVE) {
- if (rgb) {
- texres.tr= 1.0f-texres.tr;
- texres.tg= 1.0f-texres.tg;
- texres.tb= 1.0f-texres.tb;
- }
- else texres.tin= 1.0f-texres.tin;
- }
- if (mtex->texflag & MTEX_STENCIL) {
- if (rgb) {
- fact= texres.ta;
- texres.ta*= stencilTin;
- stencilTin*= fact;
- }
- else {
- fact= texres.tin;
- texres.tin*= stencilTin;
- stencilTin*= fact;
- }
- }
- else {
- if (rgb) texres.ta*= stencilTin;
- else texres.tin*= stencilTin;
- }
-
- /* mapping */
- if (((mtex->mapto & LAMAP_COL) && (effect & LA_TEXTURE))||((mtex->mapto & LAMAP_SHAD) && (effect & LA_SHAD_TEX))) {
- float col[3];
-
- if (rgb==0) {
- texres.tr= mtex->r;
- texres.tg= mtex->g;
- texres.tb= mtex->b;
- }
- else if (mtex->mapto & MAP_ALPHA) {
- texres.tin= stencilTin;
- }
- else texres.tin= texres.ta;
-
- /* inverse gamma correction */
- if (tex->type==TEX_IMAGE) {
- Image *ima = tex->ima;
- ImBuf *ibuf = BKE_image_pool_acquire_ibuf(ima, &tex->iuser, R.pool);
-
- /* don't linearize float buffers, assumed to be linear */
- if (ibuf && !(ibuf->rect_float) && R.scene_color_manage)
- IMB_colormanagement_colorspace_to_scene_linear_v3(&texres.tr, ibuf->rect_colorspace);
-
- BKE_image_pool_release_ibuf(ima, ibuf, R.pool);
- }
-
- /* lamp colors were premultiplied with this */
- col[0]= texres.tr*la->energy;
- col[1]= texres.tg*la->energy;
- col[2]= texres.tb*la->energy;
-
- if (effect & LA_SHAD_TEX)
- texture_rgb_blend(col_r, col, col_r, texres.tin, mtex->shadowfac, mtex->blendtype);
- else
- texture_rgb_blend(col_r, col, col_r, texres.tin, mtex->colfac, mtex->blendtype);
- }
- }
- }
-}
-
/* ------------------------------------------------------------------------- */
int externtex(const MTex *mtex,
@@ -3626,7 +1476,7 @@ int externtex(const MTex *mtex,
/* texture */
if (tex->type==TEX_IMAGE) {
- do_2d_mapping(mtex, texvec, NULL, NULL, dxt, dyt);
+ do_2d_mapping(mtex, texvec, NULL, dxt, dyt);
}
rgb = multitex(tex,
@@ -3658,327 +1508,3 @@ int externtex(const MTex *mtex,
return (rgb != 0);
}
-
-/* ------------------------------------------------------------------------- */
-
-void render_realtime_texture(ShadeInput *shi, Image *ima)
-{
- const bool skip_load_image = (R.r.scemode & R_NO_IMAGE_LOAD) != 0;
- TexResult texr;
- static Tex imatex[BLENDER_MAX_THREADS]; /* threadsafe */
- static int firsttime= 1;
- Tex *tex;
- float texvec[3], dx[2], dy[2];
- ShadeInputUV *suv= &shi->uv[shi->actuv];
- int a;
-
- if (R.r.scemode & R_NO_TEX) return;
-
- if (firsttime) {
- BLI_thread_lock(LOCK_IMAGE);
- if (firsttime) {
- const int num_threads = BLI_system_thread_count();
- for (a = 0; a < num_threads; a++) {
- memset(&imatex[a], 0, sizeof(Tex));
- BKE_texture_default(&imatex[a]);
- imatex[a].type= TEX_IMAGE;
- }
-
- firsttime= 0;
- }
- BLI_thread_unlock(LOCK_IMAGE);
- }
-
- tex= &imatex[shi->thread];
- tex->iuser.ok= ima->ok;
- tex->ima = ima;
-
- texvec[0]= 0.5f+0.5f*suv->uv[0];
- texvec[1]= 0.5f+0.5f*suv->uv[1];
- texvec[2] = 0.0f; /* initalize it because imagewrap looks at it. */
- if (shi->osatex) {
- dx[0]= 0.5f*suv->dxuv[0];
- dx[1]= 0.5f*suv->dxuv[1];
- dy[0]= 0.5f*suv->dyuv[0];
- dy[1]= 0.5f*suv->dyuv[1];
- }
-
- texr.nor= NULL;
-
- if (shi->osatex) imagewraposa(tex, ima, NULL, texvec, dx, dy, &texr, R.pool, skip_load_image);
- else imagewrap(tex, ima, NULL, texvec, &texr, R.pool, skip_load_image);
-
- shi->vcol[0]*= texr.tr;
- shi->vcol[1]*= texr.tg;
- shi->vcol[2]*= texr.tb;
- shi->vcol[3]*= texr.ta;
-}
-
-/* A modified part of shadeinput.c -> shade_input_set_uv()
- * Used for sampling UV mapped texture color */
-static void textured_face_generate_uv(
- const float normal[3], const float hit[3],
- const float v1[3], const float v2[3], const float v3[3],
- float r_uv[2])
-{
-
- float detsh, t00, t10, t01, t11;
- int axis1, axis2;
-
- /* find most stable axis to project */
- axis_dominant_v3(&axis1, &axis2, normal);
-
- /* compute u,v and derivatives */
- t00= v3[axis1]-v1[axis1]; t01= v3[axis2]-v1[axis2];
- t10= v3[axis1]-v2[axis1]; t11= v3[axis2]-v2[axis2];
-
- detsh= 1.0f/(t00*t11-t10*t01);
- t00*= detsh; t01*=detsh;
- t10*=detsh; t11*=detsh;
-
- r_uv[0] = (hit[axis1] - v3[axis1]) * t11 - (hit[axis2] - v3[axis2]) * t10;
- r_uv[1] = (hit[axis2] - v3[axis2]) * t00 - (hit[axis1] - v3[axis1]) * t01;
-
- /* u and v are in range -1 to 0, we allow a little bit extra but not too much, screws up speedvectors */
- CLAMP(r_uv[0], -2.0f, 1.0f);
- CLAMP(r_uv[1], -2.0f, 1.0f);
-}
-
-/* Generate an updated copy of material to use for color sampling. */
-Material *RE_sample_material_init(Material *orig_mat, Scene *scene)
-{
- Tex *tex = NULL;
- Material *mat;
- int tex_nr;
-
- if (!orig_mat) return NULL;
-
- /* copy material */
- mat = BKE_material_localize(orig_mat);
-
- /* update material anims */
- BKE_animsys_evaluate_animdata(scene, &mat->id, mat->adt, BKE_scene_frame_get(scene), ADT_RECALC_ANIM);
-
- /* strip material copy from unsupported flags */
- for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
-
- if (mat->mtex[tex_nr]) {
- MTex *mtex = mat->mtex[tex_nr];
-
- /* just in case make all non-used mtexes empty*/
- Tex *cur_tex = mtex->tex;
- mtex->tex = NULL;
-
- if (mat->septex & (1<<tex_nr) || !cur_tex) continue;
-
- /* only keep compatible texflags */
- mtex->texflag = mtex->texflag & (MTEX_RGBTOINT | MTEX_STENCIL | MTEX_NEGATIVE | MTEX_ALPHAMIX);
-
- /* depending of material type, strip non-compatible mapping modes */
- if (mat->material_type == MA_TYPE_SURFACE) {
- if (!ELEM(mtex->texco, TEXCO_ORCO, TEXCO_OBJECT, TEXCO_GLOB, TEXCO_UV)) {
- /* ignore this texture */
- mtex->texco = 0;
- continue;
- }
- /* strip all mapto flags except color and alpha */
- mtex->mapto = (mtex->mapto & MAP_COL) | (mtex->mapto & MAP_ALPHA);
- }
- else if (mat->material_type == MA_TYPE_VOLUME) {
- if (!ELEM(mtex->texco, TEXCO_OBJECT, TEXCO_ORCO, TEXCO_GLOB)) {
- /* ignore */
- mtex->texco = 0;
- continue;
- }
- /* strip all mapto flags except color and alpha */
- mtex->mapto = mtex->mapto & (MAP_TRANSMISSION_COL | MAP_REFLECTION_COL | MAP_DENSITY);
- }
-
- /* if mapped to an object, calculate inverse matrices */
- if (mtex->texco==TEXCO_OBJECT) {
- Object *ob= mtex->object;
- if (ob) {
- invert_m4_m4(ob->imat, ob->obmat);
- copy_m4_m4(ob->imat_ren, ob->imat);
- }
- }
-
- /* copy texture */
- tex= mtex->tex = BKE_texture_localize(cur_tex);
-
- /* update texture anims */
- BKE_animsys_evaluate_animdata(scene, &tex->id, tex->adt, BKE_scene_frame_get(scene), ADT_RECALC_ANIM);
-
- /* update texture cache if required */
- if (tex->type==TEX_VOXELDATA) {
- cache_voxeldata(tex, (int)scene->r.cfra);
- }
- if (tex->type==TEX_POINTDENSITY) {
- /* set dummy values for render and do cache */
- Render dummy_re = {NULL};
- dummy_re.scene = scene;
- unit_m4(dummy_re.viewinv);
- unit_m4(dummy_re.viewmat);
- unit_m4(dummy_re.winmat);
- dummy_re.winx = dummy_re.winy = 128;
- cache_pointdensity(&dummy_re, tex->pd);
- }
-
- /* update image sequences and movies */
- if (tex->ima && BKE_image_is_animated(tex->ima)) {
- BKE_image_user_check_frame_calc(&tex->iuser, (int)scene->r.cfra, 0);
- }
- }
- }
- return mat;
-}
-
-/* free all duplicate data allocated by RE_sample_material_init() */
-void RE_sample_material_free(Material *mat)
-{
- int tex_nr;
-
- /* free textures */
- for (tex_nr=0; tex_nr<MAX_MTEX; tex_nr++) {
- if (mat->septex & (1<<tex_nr)) continue;
- if (mat->mtex[tex_nr]) {
- MTex *mtex= mat->mtex[tex_nr];
-
- if (mtex->tex) {
- /* don't update user counts as we are freeing a duplicate */
- BKE_texture_free(mtex->tex);
- MEM_freeN(mtex->tex);
- mtex->tex = NULL;
- }
- }
- }
-
- /* don't update user counts as we are freeing a duplicate */
- BKE_material_free(mat);
- MEM_freeN(mat);
-}
-
-/*
- * Get material diffuse color and alpha (including linked textures) in given coordinates
- *
- * color,alpha : input/output color values
- * volume_co : sample coordinate in global space. used by volumetric materials
- * surface_co : sample surface coordinate in global space. used by "surface" materials
- * tri_index : surface tri index
- * orcoDm : orco state derived mesh
- */
-void RE_sample_material_color(
- Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3],
- int tri_index, DerivedMesh *orcoDm, Object *ob)
-{
- int v1, v2, v3;
- MVert *mvert;
- MLoop *mloop;
- const MLoopTri *mlooptri;
- float normal[3];
- ShadeInput shi = {NULL};
- Render re = {NULL};
-
- /* Get face data */
- mvert = orcoDm->getVertArray(orcoDm);
- mloop = orcoDm->getLoopArray(orcoDm);
- mlooptri = orcoDm->getLoopTriArray(orcoDm);
-
- if (!mvert || !mlooptri || !mat) {
- return;
- }
-
- v1 = mloop[mlooptri[tri_index].tri[0]].v;
- v2 = mloop[mlooptri[tri_index].tri[1]].v;
- v3 = mloop[mlooptri[tri_index].tri[2]].v;
- normal_tri_v3(normal, mvert[v1].co, mvert[v2].co, mvert[v3].co);
-
- /* generate shadeinput with data required */
- shi.mat = mat;
-
- /* fill shadeinput data depending on material type */
- if (mat->material_type == MA_TYPE_SURFACE) {
- /* global coordinates */
- copy_v3_v3(shi.gl, surface_co);
- /* object space coordinates */
- copy_v3_v3(shi.co, surface_co);
- mul_m4_v3(ob->imat, shi.co);
- /* orco coordinates */
- {
- float uv[2];
- float l;
- /* Get generated UV */
- textured_face_generate_uv(normal, shi.co, mvert[v1].co, mvert[v2].co, mvert[v3].co, uv);
- l= 1.0f+uv[0]+uv[1];
-
- /* calculate generated coordinate */
- shi.lo[0]= l*mvert[v3].co[0]-uv[0]*mvert[v1].co[0]-uv[1]*mvert[v2].co[0];
- shi.lo[1]= l*mvert[v3].co[1]-uv[0]*mvert[v1].co[1]-uv[1]*mvert[v2].co[1];
- shi.lo[2]= l*mvert[v3].co[2]-uv[0]*mvert[v1].co[2]-uv[1]*mvert[v2].co[2];
- }
- /* uv coordinates */
- {
- const int layers = CustomData_number_of_layers(&orcoDm->loopData, CD_MLOOPUV);
- const int layer_index = CustomData_get_layer_index(&orcoDm->loopData, CD_MLOOPUV);
- int i;
-
- /* for every uv map set coords and name */
- for (i=0; i<layers; i++) {
- if (layer_index >= 0) {
- const float *uv1, *uv2, *uv3;
- const CustomData *data = &orcoDm->loopData;
- const MLoopUV *mloopuv = data->layers[layer_index + i].data;
- float uv[2];
- float l;
-
- /* point layer name from actual layer data */
- shi.uv[i].name = data->layers[i].name;
- /* Get generated coordinates to calculate UV from */
- textured_face_generate_uv(normal, shi.co, mvert[v1].co, mvert[v2].co, mvert[v3].co, uv);
- /* Get UV mapping coordinate */
- l= 1.0f+uv[0]+uv[1];
-
- uv1 = mloopuv[mlooptri[tri_index].tri[0]].uv;
- uv2 = mloopuv[mlooptri[tri_index].tri[1]].uv;
- uv3 = mloopuv[mlooptri[tri_index].tri[2]].uv;
-
- shi.uv[i].uv[0]= -1.0f + 2.0f*(l*uv3[0]-uv[0]*uv1[0]-uv[1]*uv2[0]);
- shi.uv[i].uv[1]= -1.0f + 2.0f*(l*uv3[1]-uv[0]*uv1[1]-uv[1]*uv2[1]);
- shi.uv[i].uv[2]= 0.0f; /* texture.c assumes there are 3 coords */
- }
- }
- /* active uv map */
- shi.actuv = CustomData_get_active_layer_index(&orcoDm->loopData, CD_MLOOPUV) - layer_index;
- shi.totuv = layers;
- }
-
- /* apply initial values from material */
- shi.r = mat->r;
- shi.g = mat->g;
- shi.b = mat->b;
- shi.alpha = mat->alpha;
-
- /* do texture */
- do_material_tex(&shi, &re);
-
- /* apply result */
- color[0] = shi.r;
- color[1] = shi.g;
- color[2] = shi.b;
- *alpha = shi.alpha;
- }
- else if (mat->material_type == MA_TYPE_VOLUME) {
- ObjectInstanceRen obi = {NULL};
- obi.ob = ob;
- shi.obi = &obi;
- unit_m4(re.viewinv);
- copy_v3_v3(color, mat->vol.reflection_col);
- *alpha = mat->vol.density;
-
- /* do texture */
- do_volume_tex(&shi, volume_co, (MAP_TRANSMISSION_COL | MAP_REFLECTION_COL | MAP_DENSITY),
- color, alpha, &re);
- }
-}
-
-/* eof */
diff --git a/source/blender/render/intern/source/rendercore.c b/source/blender/render/intern/source/rendercore.c
deleted file mode 100644
index 77f399d08d1..00000000000
--- a/source/blender/render/intern/source/rendercore.c
+++ /dev/null
@@ -1,2030 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributors: Hos, Robert Wenzlaff.
- * Contributors: 2004/2005/2006 Blender Foundation, full recode
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/rendercore.c
- * \ingroup render
- */
-
-
-/* system includes */
-#include <stdio.h>
-#include <math.h>
-#include <float.h>
-#include <string.h>
-#include <assert.h>
-
-/* External modules: */
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_rand.h"
-#include "BLI_threads.h"
-#include "BLI_utildefines.h"
-
-#include "DNA_image_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_material_types.h"
-#include "DNA_group_types.h"
-
-/* local include */
-#include "renderpipeline.h"
-#include "render_result.h"
-#include "render_types.h"
-#include "renderdatabase.h"
-#include "occlusion.h"
-#include "pixelblending.h"
-#include "pixelshading.h"
-#include "shadbuf.h"
-#include "shading.h"
-#include "sss.h"
-#include "zbuf.h"
-
-/* own include */
-#include "rendercore.h"
-
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-/* x and y are current pixels in rect to be rendered */
-/* do not normalize! */
-void calc_view_vector(float view[3], float x, float y)
-{
-
- view[2]= -ABS(R.clipsta);
-
- if (R.r.mode & R_ORTHO) {
- view[0]= view[1]= 0.0f;
- }
- else {
-
- if (R.r.mode & R_PANORAMA) {
- x-= R.panodxp;
- }
-
- /* move x and y to real viewplane coords */
- x = (x / (float)R.winx);
- view[0] = R.viewplane.xmin + x * BLI_rctf_size_x(&R.viewplane);
-
- y = (y / (float)R.winy);
- view[1] = R.viewplane.ymin + y * BLI_rctf_size_y(&R.viewplane);
-
-// if (R.flag & R_SEC_FIELD) {
-// if (R.r.mode & R_ODDFIELD) view[1]= (y+R.ystart)*R.ycor;
-// else view[1]= (y+R.ystart+1.0)*R.ycor;
-// }
-// else view[1]= (y+R.ystart+R.bluroffsy+0.5)*R.ycor;
-
- if (R.r.mode & R_PANORAMA) {
- float u= view[0] + R.panodxv; float v= view[2];
- view[0]= R.panoco*u + R.panosi*v;
- view[2]= -R.panosi*u + R.panoco*v;
- }
- }
-}
-
-void calc_renderco_ortho(float co[3], float x, float y, int z)
-{
- /* x and y 3d coordinate can be derived from pixel coord and winmat */
- float fx= 2.0f/(R.winx*R.winmat[0][0]);
- float fy= 2.0f/(R.winy*R.winmat[1][1]);
- float zco;
-
- co[0]= (x - 0.5f*R.winx)*fx - R.winmat[3][0]/R.winmat[0][0];
- co[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1];
-
- zco= ((float)z)/2147483647.0f;
- co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] );
-}
-
-void calc_renderco_zbuf(float co[3], const float view[3], int z)
-{
- float fac, zco;
-
- /* inverse of zbuf calc: zbuf = MAXZ*hoco_z/hoco_w */
- zco= ((float)z)/2147483647.0f;
- co[2]= R.winmat[3][2]/( R.winmat[2][3]*zco - R.winmat[2][2] );
-
- fac= co[2]/view[2];
- co[0]= fac*view[0];
- co[1]= fac*view[1];
-}
-
-/* also used in zbuf.c and shadbuf.c */
-int count_mask(unsigned short mask)
-{
- if (R.samples)
- return (R.samples->cmask[mask & 255]+R.samples->cmask[mask>>8]);
- return 0;
-}
-
-static int calchalo_z(HaloRen *har, int zz)
-{
-
- if (har->type & HA_ONLYSKY) {
- if (zz < 0x7FFFFFF0) zz= - 0x7FFFFF; /* edge render messes zvalues */
- }
- else {
- zz= (zz>>8);
- }
- return zz;
-}
-
-
-
-static void halo_pixelstruct(HaloRen *har, RenderLayer **rlpp, int totsample, int od, float dist, float xn, float yn, PixStr *ps)
-{
- float col[4], accol[4], fac;
- int amount, amountm, zz, flarec, sample, fullsample, mask=0;
-
- fullsample= (totsample > 1);
- amount= 0;
- accol[0] = accol[1] = accol[2] = accol[3]= 0.0f;
- col[0] = col[1] = col[2] = col[3]= 0.0f;
- flarec= har->flarec;
-
- while (ps) {
- amountm= count_mask(ps->mask);
- amount+= amountm;
-
- zz= calchalo_z(har, ps->z);
- if ((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) {
- if (shadeHaloFloat(har, col, zz, dist, xn, yn, flarec)) {
- flarec= 0;
-
- if (fullsample) {
- for (sample=0; sample<totsample; sample++) {
- if (ps->mask & (1 << sample)) {
- float *pass = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- addalphaAddfacFloat(pass + od*4, col, har->add);
- }
- }
- }
- else {
- fac= ((float)amountm)/(float)R.osa;
- accol[0]+= fac*col[0];
- accol[1]+= fac*col[1];
- accol[2]+= fac*col[2];
- accol[3]+= fac*col[3];
- }
- }
- }
-
- mask |= ps->mask;
- ps= ps->next;
- }
-
- /* now do the sky sub-pixels */
- amount= R.osa-amount;
- if (amount) {
- if (shadeHaloFloat(har, col, 0x7FFFFF, dist, xn, yn, flarec)) {
- if (!fullsample) {
- fac= ((float)amount)/(float)R.osa;
- accol[0]+= fac*col[0];
- accol[1]+= fac*col[1];
- accol[2]+= fac*col[2];
- accol[3]+= fac*col[3];
- }
- }
- }
-
- if (fullsample) {
- for (sample=0; sample<totsample; sample++) {
- if (!(mask & (1 << sample))) {
- float *pass = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- addalphaAddfacFloat(pass + od*4, col, har->add);
- }
- }
- }
- else {
- col[0]= accol[0];
- col[1]= accol[1];
- col[2]= accol[2];
- col[3]= accol[3];
-
- for (sample=0; sample<totsample; sample++) {
- float *pass = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- addalphaAddfacFloat(pass + od*4, col, har->add);
- }
- }
-}
-
-static void halo_tile(RenderPart *pa, RenderLayer *rl)
-{
- RenderLayer *rlpp[RE_MAX_OSA];
- HaloRen *har;
- rcti disprect= pa->disprect, testrect= pa->disprect;
- float dist, xsq, ysq, xn, yn;
- float col[4];
- intptr_t *rd= NULL;
- int a, *rz, zz, y, sample, totsample, od;
- short minx, maxx, miny, maxy, x;
- unsigned int lay= rl->lay;
-
- /* we don't render halos in the cropped area, gives errors in flare counter */
- if (pa->crop) {
- testrect.xmin+= pa->crop;
- testrect.xmax-= pa->crop;
- testrect.ymin+= pa->crop;
- testrect.ymax-= pa->crop;
- }
-
- totsample= get_sample_layers(pa, rl, rlpp);
-
- for (a=0; a<R.tothalo; a++) {
- har= R.sortedhalos[a];
-
- /* layer test, clip halo with y */
- if ((har->lay & lay) == 0) {
- /* pass */
- }
- else if (testrect.ymin > har->maxy) {
- /* pass */
- }
- else if (testrect.ymax < har->miny) {
- /* pass */
- }
- else {
-
- minx= floor(har->xs-har->rad);
- maxx= ceil(har->xs+har->rad);
-
- if (testrect.xmin > maxx) {
- /* pass */
- }
- else if (testrect.xmax < minx) {
- /* pass */
- }
- else {
-
- minx = max_ii(minx, testrect.xmin);
- maxx = min_ii(maxx, testrect.xmax);
-
- miny = max_ii(har->miny, testrect.ymin);
- maxy = min_ii(har->maxy, testrect.ymax);
-
- for (y=miny; y<maxy; y++) {
- int rectofs= (y-disprect.ymin)*pa->rectx + (minx - disprect.xmin);
- rz= pa->rectz + rectofs;
- od= rectofs;
-
- if (pa->rectdaps)
- rd= pa->rectdaps + rectofs;
-
- yn= (y-har->ys)*R.ycor;
- ysq= yn*yn;
-
- for (x=minx; x<maxx; x++, rz++, od++) {
- xn= x- har->xs;
- xsq= xn*xn;
- dist= xsq+ysq;
- if (dist<har->radsq) {
- if (rd && *rd) {
- halo_pixelstruct(har, rlpp, totsample, od, dist, xn, yn, (PixStr *)*rd);
- }
- else {
- zz= calchalo_z(har, *rz);
- if ((zz> har->zs) || (har->mat && (har->mat->mode & MA_HALO_SOFT))) {
- if (shadeHaloFloat(har, col, zz, dist, xn, yn, har->flarec)) {
- for (sample=0; sample<totsample; sample++) {
- float * rect= RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- addalphaAddfacFloat(rect + od*4, col, har->add);
- }
- }
- }
- }
- }
- if (rd) rd++;
- }
- }
- }
- }
- if (R.test_break(R.tbh) ) break;
- }
-}
-
-static void lamphalo_tile(RenderPart *pa, RenderLayer *rl)
-{
- RenderLayer *rlpp[RE_MAX_OSA];
- ShadeInput shi;
- float *pass;
- float fac, col[4];
- intptr_t *rd= pa->rectdaps;
- const int *rz= pa->rectz;
- int x, y, sample, totsample, fullsample, od;
-
- totsample= get_sample_layers(pa, rl, rlpp);
- fullsample= (totsample > 1);
-
- shade_input_initialize(&shi, pa, rl, 0); /* this zero's ShadeInput for us */
-
- for (od=0, y=pa->disprect.ymin; y<pa->disprect.ymax; y++) {
- for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, rz++, od++) {
-
- calc_view_vector(shi.view, x, y);
-
- if (rd && *rd) {
- PixStr *ps= (PixStr *)*rd;
- int count, totsamp= 0, mask= 0;
-
- while (ps) {
- if (R.r.mode & R_ORTHO)
- calc_renderco_ortho(shi.co, (float)x, (float)y, ps->z);
- else
- calc_renderco_zbuf(shi.co, shi.view, ps->z);
-
- totsamp+= count= count_mask(ps->mask);
- mask |= ps->mask;
-
- col[0]= col[1]= col[2]= col[3]= 0.0f;
- renderspothalo(&shi, col, 1.0f);
-
- if (fullsample) {
- for (sample=0; sample<totsample; sample++) {
- if (ps->mask & (1 << sample)) {
- pass = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- pass += od * 4;
- pass[0]+= col[0];
- pass[1]+= col[1];
- pass[2]+= col[2];
- pass[3]+= col[3];
- if (pass[3]>1.0f) pass[3]= 1.0f;
- }
- }
- }
- else {
- fac= ((float)count)/(float)R.osa;
- pass = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, R.viewname);
- pass += od * 4;
- pass[0]+= fac*col[0];
- pass[1]+= fac*col[1];
- pass[2]+= fac*col[2];
- pass[3]+= fac*col[3];
- if (pass[3]>1.0f) pass[3]= 1.0f;
- }
-
- ps= ps->next;
- }
-
- if (totsamp<R.osa) {
- shi.co[2]= 0.0f;
-
- col[0]= col[1]= col[2]= col[3]= 0.0f;
- renderspothalo(&shi, col, 1.0f);
-
- if (fullsample) {
- for (sample=0; sample<totsample; sample++) {
- if (!(mask & (1 << sample))) {
-
- pass = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- pass += od * 4;
- pass[0]+= col[0];
- pass[1]+= col[1];
- pass[2]+= col[2];
- pass[3]+= col[3];
- if (pass[3]>1.0f) pass[3]= 1.0f;
- }
- }
- }
- else {
- fac= ((float)R.osa-totsamp)/(float)R.osa;
- pass = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, R.viewname);
- pass += od * 4;
- pass[0]+= fac*col[0];
- pass[1]+= fac*col[1];
- pass[2]+= fac*col[2];
- pass[3]+= fac*col[3];
- if (pass[3]>1.0f) pass[3]= 1.0f;
- }
- }
- }
- else {
- if (R.r.mode & R_ORTHO)
- calc_renderco_ortho(shi.co, (float)x, (float)y, *rz);
- else
- calc_renderco_zbuf(shi.co, shi.view, *rz);
-
- col[0]= col[1]= col[2]= col[3]= 0.0f;
- renderspothalo(&shi, col, 1.0f);
-
- for (sample=0; sample<totsample; sample++) {
- pass = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- pass += od * 4;
- pass[0]+= col[0];
- pass[1]+= col[1];
- pass[2]+= col[2];
- pass[3]+= col[3];
- if (pass[3]>1.0f) pass[3]= 1.0f;
- }
- }
-
- if (rd) rd++;
- }
- if (y&1)
- if (R.test_break(R.tbh)) break;
- }
-}
-
-
-/* ********************* MAINLOOPS ******************** */
-
-/* osa version */
-static void add_filt_passes(RenderLayer *rl, int curmask, int rectx, int offset, ShadeInput *shi, ShadeResult *shr)
-{
- RenderPass *rpass;
-
- for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
- float *fp, *col= NULL;
- int pixsize= 3;
-
- if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) {
- add_filt_fmask(curmask, shr->combined, rpass->rect + 4*offset, rectx);
- }
- else if (STREQ(rpass->name, RE_PASSNAME_Z)) {
- fp = rpass->rect + offset;
- *fp = shr->z;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_RGBA)) {
- col = shr->col;
- pixsize = 4;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_EMIT)) {
- col = shr->emit;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE)) {
- col = shr->diff;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SPEC)) {
- col = shr->spec;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SHADOW)) {
- col = shr->shad;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_AO)) {
- col = shr->ao;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_ENVIRONMENT)) {
- col = shr->env;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDIRECT)) {
- col = shr->indirect;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFLECT)) {
- col = shr->refl;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFRACT)) {
- col = shr->refr;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_NORMAL)) {
- col = shr->nor;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_UV)) {
- /* box filter only, gauss will screwup UV too much */
- if (shi->totuv) {
- float mult = (float)count_mask(curmask)/(float)R.osa;
- fp = rpass->rect + 3*offset;
- fp[0]+= mult*(0.5f + 0.5f*shi->uv[shi->actuv].uv[0]);
- fp[1]+= mult*(0.5f + 0.5f*shi->uv[shi->actuv].uv[1]);
- fp[2]+= mult;
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDEXOB)) {
- /* no filter */
- if (shi->vlr) {
- fp = rpass->rect + offset;
- if (*fp==0.0f)
- *fp = (float)shi->obr->ob->index;
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDEXMA)) {
- /* no filter */
- if (shi->vlr) {
- fp = rpass->rect + offset;
- if (*fp==0.0f)
- *fp = (float)shi->mat->index;
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_MIST)) {
- /* */
- col = &shr->mist;
- pixsize = 1;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) {
- /* add minimum speed in pixel, no filter */
- fp = rpass->rect + 4*offset;
- if ( (ABS(shr->winspeed[0]) + ABS(shr->winspeed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) {
- fp[0] = shr->winspeed[0];
- fp[1] = shr->winspeed[1];
- }
- if ( (ABS(shr->winspeed[2]) + ABS(shr->winspeed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) {
- fp[2] = shr->winspeed[2];
- fp[3] = shr->winspeed[3];
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_RAYHITS)) {
- /* */
- col = shr->rayhits;
- pixsize= 4;
- }
-
- if (col) {
- fp= rpass->rect + pixsize*offset;
- add_filt_fmask_pixsize(curmask, col, fp, rectx, pixsize);
- }
- }
-}
-
-/* non-osa version */
-static void add_passes(RenderLayer *rl, int offset, ShadeInput *shi, ShadeResult *shr)
-{
- RenderPass *rpass;
- float *fp;
-
- for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
- float *col= NULL, uvcol[3];
- int a, pixsize= 3;
-
- if (STREQ(rpass->name, RE_PASSNAME_COMBINED)) {
- /* copy combined to use for preview */
- copy_v4_v4(rpass->rect + 4*offset, shr->combined);
- }
- else if (STREQ(rpass->name, RE_PASSNAME_Z)) {
- fp = rpass->rect + offset;
- *fp = shr->z;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_RGBA)) {
- col = shr->col;
- pixsize = 4;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_EMIT)) {
- col = shr->emit;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE)) {
- col = shr->diff;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SPEC)) {
- col = shr->spec;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SHADOW)) {
- col = shr->shad;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_AO)) {
- col = shr->ao;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_ENVIRONMENT)) {
- col = shr->env;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDIRECT)) {
- col = shr->indirect;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFLECT)) {
- col = shr->refl;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFRACT)) {
- col = shr->refr;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_NORMAL)) {
- col = shr->nor;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_UV)) {
- if (shi->totuv) {
- uvcol[0] = 0.5f + 0.5f*shi->uv[shi->actuv].uv[0];
- uvcol[1] = 0.5f + 0.5f*shi->uv[shi->actuv].uv[1];
- uvcol[2] = 1.0f;
- col = uvcol;
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) {
- col = shr->winspeed;
- pixsize = 4;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDEXOB)) {
- if (shi->vlr) {
- fp = rpass->rect + offset;
- *fp = (float)shi->obr->ob->index;
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDEXMA)) {
- if (shi->vlr) {
- fp = rpass->rect + offset;
- *fp = (float)shi->mat->index;
- }
- }
- else if (STREQ(rpass->name, RE_PASSNAME_MIST)) {
- fp = rpass->rect + offset;
- *fp = shr->mist;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_RAYHITS)) {
- col = shr->rayhits;
- pixsize = 4;
- }
-
- if (col) {
- fp = rpass->rect + pixsize*offset;
- for (a=0; a<pixsize; a++)
- fp[a] = col[a];
- }
- }
-}
-
-int get_sample_layers(RenderPart *pa, RenderLayer *rl, RenderLayer **rlpp)
-{
-
- if (pa->fullresult.first) {
- int sample, nr= BLI_findindex(&pa->result->layers, rl);
-
- for (sample=0; sample<R.osa; sample++) {
- RenderResult *rr= BLI_findlink(&pa->fullresult, sample);
-
- rlpp[sample]= BLI_findlink(&rr->layers, nr);
- }
- return R.osa;
- }
- else {
- rlpp[0]= rl;
- return 1;
- }
-}
-
-
-/* only do sky, is default in the solid layer (shade_tile) btw */
-static void sky_tile(RenderPart *pa, RenderLayer *rl)
-{
- RenderLayer *rlpp[RE_MAX_OSA];
- int x, y, od=0, totsample;
-
- if (R.r.alphamode!=R_ADDSKY)
- return;
-
- totsample= get_sample_layers(pa, rl, rlpp);
-
- for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++) {
- for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, od+=4) {
- float col[4];
- int sample;
- bool done = false;
-
- for (sample= 0; sample<totsample; sample++) {
- float *pass = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
- pass += od;
-
- if (pass[3]<1.0f) {
-
- if (done==0) {
- shadeSkyPixel(col, x, y, pa->thread);
- done = true;
- }
-
- if (pass[3]==0.0f) {
- copy_v4_v4(pass, col);
- pass[3] = 1.0f;
- }
- else {
- addAlphaUnderFloat(pass, col);
- pass[3] = 1.0f;
- }
- }
- }
- }
-
- if (y&1)
- if (R.test_break(R.tbh)) break;
- }
-}
-
-static void atm_tile(RenderPart *pa, RenderLayer *rl)
-{
- RenderPass *zpass;
- GroupObject *go;
- LampRen *lar;
- RenderLayer *rlpp[RE_MAX_OSA];
- int totsample;
- int x, y, od= 0;
-
- totsample= get_sample_layers(pa, rl, rlpp);
-
- /* check that z pass is enabled */
- if (pa->rectz==NULL) return;
- for (zpass= rl->passes.first; zpass; zpass= zpass->next)
- if (STREQ(zpass->name, RE_PASSNAME_Z))
- break;
-
- if (zpass==NULL) return;
-
- /* check for at least one sun lamp that its atmosphere flag is enabled */
- for (go=R.lights.first; go; go= go->next) {
- lar= go->lampren;
- if (lar->type==LA_SUN && lar->sunsky && (lar->sunsky->effect_type & LA_SUN_EFFECT_AP))
- break;
- }
- /* do nothign and return if there is no sun lamp */
- if (go==NULL)
- return;
-
- /* for each x,y and each sample, and each sun lamp*/
- for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++) {
- for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, od++) {
- int sample;
-
- for (sample=0; sample<totsample; sample++) {
- const float *zrect = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_Z, R.viewname) + od;
- float *rgbrect = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname) + 4*od;
- float rgb[3] = {0};
- bool done = false;
-
- for (go=R.lights.first; go; go= go->next) {
-
-
- lar= go->lampren;
- if (lar->type==LA_SUN && lar->sunsky) {
-
- /* if it's sky continue and don't apply atmosphere effect on it */
- if (*zrect >= 9.9e10f || rgbrect[3]==0.0f) {
- continue;
- }
-
- if ((lar->sunsky->effect_type & LA_SUN_EFFECT_AP)) {
- float tmp_rgb[3];
-
- /* skip if worldspace lamp vector is below horizon */
- if (go->ob->obmat[2][2] < 0.f) {
- continue;
- }
-
- copy_v3_v3(tmp_rgb, rgbrect);
- if (rgbrect[3]!=1.0f) { /* de-premul */
- mul_v3_fl(tmp_rgb, 1.0f/rgbrect[3]);
- }
- shadeAtmPixel(lar->sunsky, tmp_rgb, x, y, *zrect);
- if (rgbrect[3]!=1.0f) { /* premul */
- mul_v3_fl(tmp_rgb, rgbrect[3]);
- }
-
- if (done==0) {
- copy_v3_v3(rgb, tmp_rgb);
- done = true;
- }
- else {
- rgb[0] = 0.5f*rgb[0] + 0.5f*tmp_rgb[0];
- rgb[1] = 0.5f*rgb[1] + 0.5f*tmp_rgb[1];
- rgb[2] = 0.5f*rgb[2] + 0.5f*tmp_rgb[2];
- }
- }
- }
- }
-
- /* if at least for one sun lamp aerial perspective was applied*/
- if (done) {
- copy_v3_v3(rgbrect, rgb);
- }
- }
- }
- }
-}
-
-static void shadeDA_tile(RenderPart *pa, RenderLayer *rl)
-{
- RenderResult *rr= pa->result;
- ShadeSample ssamp;
- intptr_t *rd, *rectdaps= pa->rectdaps;
- int samp;
- int x, y, seed, crop=0, offs=0, od;
-
- if (R.test_break(R.tbh)) return;
-
- /* irregular shadowb buffer creation */
- if (R.r.mode & R_SHADOW)
- ISB_create(pa, NULL);
-
- /* we set per pixel a fixed seed, for random AO and shadow samples */
- seed= pa->rectx*pa->disprect.ymin;
-
- /* general shader info, passes */
- shade_sample_initialize(&ssamp, pa, rl);
-
- /* occlusion caching */
- if (R.occlusiontree)
- cache_occ_samples(&R, pa, &ssamp);
-
- /* filtered render, for now we assume only 1 filter size */
- if (pa->crop) {
- crop= 1;
- rectdaps+= pa->rectx + 1;
- offs= pa->rectx + 1;
- }
-
- /* scanline updates have to be 2 lines behind */
- rr->renrect.ymin = 0;
- rr->renrect.ymax = -2*crop;
- rr->renlay= rl;
-
- for (y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) {
- rd= rectdaps;
- od= offs;
-
- for (x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, rd++, od++) {
- BLI_thread_srandom(pa->thread, seed++);
-
- if (*rd) {
- if (shade_samples(&ssamp, (PixStr *)(*rd), x, y)) {
-
- /* multisample buffers or filtered mask filling? */
- if (pa->fullresult.first) {
- int a;
- for (samp=0; samp<ssamp.tot; samp++) {
- int smask= ssamp.shi[samp].mask;
- for (a=0; a<R.osa; a++) {
- int mask= 1<<a;
- if (smask & mask)
- add_passes(ssamp.rlpp[a], od, &ssamp.shi[samp], &ssamp.shr[samp]);
- }
- }
- }
- else {
- for (samp=0; samp<ssamp.tot; samp++)
- add_filt_passes(rl, ssamp.shi[samp].mask, pa->rectx, od, &ssamp.shi[samp], &ssamp.shr[samp]);
- }
- }
- }
- }
-
- rectdaps+= pa->rectx;
- offs+= pa->rectx;
-
- if (y&1) if (R.test_break(R.tbh)) break;
- }
-
- /* disable scanline updating */
- rr->renlay= NULL;
-
- if (R.r.mode & R_SHADOW)
- ISB_free(pa);
-
- if (R.occlusiontree)
- free_occ_samples(&R, pa);
-}
-
-/* ************* pixel struct ******** */
-
-
-static PixStrMain *addpsmain(ListBase *lb)
-{
- PixStrMain *psm;
-
- psm= (PixStrMain *)MEM_mallocN(sizeof(PixStrMain), "pixstrMain");
- BLI_addtail(lb, psm);
-
- psm->ps= (PixStr *)MEM_mallocN(4096*sizeof(PixStr), "pixstr");
- psm->counter= 0;
-
- return psm;
-}
-
-static void freeps(ListBase *lb)
-{
- PixStrMain *psm, *psmnext;
-
- for (psm= lb->first; psm; psm= psmnext) {
- psmnext= psm->next;
- if (psm->ps)
- MEM_freeN(psm->ps);
- MEM_freeN(psm);
- }
- BLI_listbase_clear(lb);
-}
-
-static void addps(ListBase *lb, intptr_t *rd, int obi, int facenr, int z, int maskz, unsigned short mask)
-{
- PixStrMain *psm;
- PixStr *ps, *last= NULL;
-
- if (*rd) {
- ps= (PixStr *)(*rd);
-
- while (ps) {
- if ( ps->obi == obi && ps->facenr == facenr ) {
- ps->mask |= mask;
- return;
- }
- last= ps;
- ps= ps->next;
- }
- }
-
- /* make new PS (pixel struct) */
- psm= lb->last;
-
- if (psm->counter==4095)
- psm= addpsmain(lb);
-
- ps= psm->ps + psm->counter++;
-
- if (last) last->next= ps;
- else *rd= (intptr_t)ps;
-
- ps->next= NULL;
- ps->obi= obi;
- ps->facenr= facenr;
- ps->z= z;
- ps->maskz= maskz;
- ps->mask = mask;
- ps->shadfac= 0;
-}
-
-static void edge_enhance_add(RenderPart *pa, float *rectf, float *arect)
-{
- float addcol[4];
- int pix;
-
- if (arect==NULL)
- return;
-
- for (pix= pa->rectx*pa->recty; pix>0; pix--, arect++, rectf+=4) {
- if (*arect != 0.0f) {
- addcol[0]= *arect * R.r.edgeR;
- addcol[1]= *arect * R.r.edgeG;
- addcol[2]= *arect * R.r.edgeB;
- addcol[3]= *arect;
- addAlphaOverFloat(rectf, addcol);
- }
- }
-}
-
-/* clamp alpha and RGB to 0..1 and 0..inf, can go outside due to filter */
-static void clamp_alpha_rgb_range(RenderPart *pa, RenderLayer *rl)
-{
- RenderLayer *rlpp[RE_MAX_OSA];
- int y, sample, totsample;
-
- totsample= get_sample_layers(pa, rl, rlpp);
-
- /* not for full sample, there we clamp after compositing */
- if (totsample > 1)
- return;
-
- for (sample= 0; sample<totsample; sample++) {
- float *rectf = RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_COMBINED, R.viewname);
-
- for (y= pa->rectx*pa->recty; y>0; y--, rectf+=4) {
- rectf[0] = MAX2(rectf[0], 0.0f);
- rectf[1] = MAX2(rectf[1], 0.0f);
- rectf[2] = MAX2(rectf[2], 0.0f);
- CLAMP(rectf[3], 0.0f, 1.0f);
- }
- }
-}
-
-/* adds only alpha values */
-static void edge_enhance_tile(RenderPart *pa, float *rectf, int *rectz)
-{
- /* use zbuffer to define edges, add it to the image */
- int y, x, col, *rz, *rz1, *rz2, *rz3;
- int zval1, zval2, zval3;
- float *rf;
-
- /* shift values in zbuffer 4 to the right (anti overflows), for filter we need multiplying with 12 max */
- rz= rectz;
- if (rz==NULL) return;
-
- for (y=0; y<pa->recty; y++)
- for (x=0; x<pa->rectx; x++, rz++) (*rz)>>= 4;
-
- rz1= rectz;
- rz2= rz1+pa->rectx;
- rz3= rz2+pa->rectx;
-
- rf= rectf+pa->rectx+1;
-
- for (y=0; y<pa->recty-2; y++) {
- for (x=0; x<pa->rectx-2; x++, rz1++, rz2++, rz3++, rf++) {
-
- /* prevent overflow with sky z values */
- zval1= rz1[0] + 2*rz1[1] + rz1[2];
- zval2= 2*rz2[0] + 2*rz2[2];
- zval3= rz3[0] + 2*rz3[1] + rz3[2];
-
- col= ( 4*rz2[1] - (zval1 + zval2 + zval3)/3 );
- if (col<0) col= -col;
-
- col >>= 5;
- if (col > (1<<16)) col= (1<<16);
- else col= (R.r.edgeint*col)>>8;
-
- if (col>0) {
- float fcol;
-
- if (col>255) fcol= 1.0f;
- else fcol= (float)col/255.0f;
-
- if (R.osa)
- *rf+= fcol/(float)R.osa;
- else
- *rf= fcol;
- }
- }
- rz1+= 2;
- rz2+= 2;
- rz3+= 2;
- rf+= 2;
- }
-
- /* shift back zbuf values, we might need it still */
- rz= rectz;
- for (y=0; y<pa->recty; y++)
- for (x=0; x<pa->rectx; x++, rz++) (*rz)<<= 4;
-
-}
-
-static void reset_sky_speed(RenderPart *pa, RenderLayer *rl)
-{
- /* for all pixels with max speed, set to zero */
- RenderLayer *rlpp[RE_MAX_OSA];
- float *fp;
- int a, sample, totsample;
-
- totsample= get_sample_layers(pa, rl, rlpp);
-
- for (sample= 0; sample<totsample; sample++) {
- fp= RE_RenderLayerGetPass(rlpp[sample], RE_PASSNAME_VECTOR, R.viewname);
- if (fp==NULL) break;
-
- for (a= 4*pa->rectx*pa->recty - 1; a>=0; a--)
- if (fp[a] == PASS_VECTOR_MAX) fp[a]= 0.0f;
- }
-}
-
-static unsigned short *make_solid_mask(RenderPart *pa)
-{
- intptr_t *rd= pa->rectdaps;
- unsigned short *solidmask, *sp;
- int x;
-
- if (rd==NULL) return NULL;
-
- sp=solidmask= MEM_mallocN(sizeof(short)*pa->rectx*pa->recty, "solidmask");
-
- for (x=pa->rectx*pa->recty; x>0; x--, rd++, sp++) {
- if (*rd) {
- PixStr *ps= (PixStr *)*rd;
-
- *sp= ps->mask;
- for (ps= ps->next; ps; ps= ps->next)
- *sp |= ps->mask;
- }
- else
- *sp= 0;
- }
-
- return solidmask;
-}
-
-static void addAlphaOverFloatMask(float *dest, float *source, unsigned short dmask, unsigned short smask)
-{
- unsigned short shared= dmask & smask;
- float mul= 1.0f - source[3];
-
- if (shared) { /* overlapping masks */
-
- /* masks differ, we make a mixture of 'add' and 'over' */
- if (shared!=dmask) {
- float shared_bits= (float)count_mask(shared); /* alpha over */
- float tot_bits= (float)count_mask(smask|dmask); /* alpha add */
-
- float add= (tot_bits - shared_bits)/tot_bits; /* add level */
- mul= add + (1.0f-add)*mul;
- }
- }
- else if (dmask && smask) {
- /* works for premul only, of course */
- dest[0]+= source[0];
- dest[1]+= source[1];
- dest[2]+= source[2];
- dest[3]+= source[3];
-
- return;
- }
-
- dest[0]= (mul*dest[0]) + source[0];
- dest[1]= (mul*dest[1]) + source[1];
- dest[2]= (mul*dest[2]) + source[2];
- dest[3]= (mul*dest[3]) + source[3];
-}
-
-typedef struct ZbufSolidData {
- RenderLayer *rl;
- ListBase *psmlist;
- float *edgerect;
-} ZbufSolidData;
-
-static void make_pixelstructs(RenderPart *pa, ZSpan *zspan, int sample, void *data)
-{
- ZbufSolidData *sdata = (ZbufSolidData *)data;
- ListBase *lb= sdata->psmlist;
- intptr_t *rd= pa->rectdaps;
- const int *ro= zspan->recto;
- const int *rp= zspan->rectp;
- const int *rz= zspan->rectz;
- const int *rm= zspan->rectmask;
- int x, y;
- int mask= 1<<sample;
-
- for (y=0; y<pa->recty; y++) {
- for (x=0; x<pa->rectx; x++, rd++, rp++, ro++, rz++, rm++) {
- if (*rp) {
- addps(lb, rd, *ro, *rp, *rz, (zspan->rectmask)? *rm: 0, mask);
- }
- }
- }
-
- if (sdata->rl->layflag & SCE_LAY_EDGE)
- if (R.r.mode & R_EDGE)
- edge_enhance_tile(pa, sdata->edgerect, zspan->rectz);
-}
-
-/* main call for shading Delta Accum, for OSA */
-/* supposed to be fully threadable! */
-void zbufshadeDA_tile(RenderPart *pa)
-{
- RenderResult *rr= pa->result;
- RenderLayer *rl;
- ListBase psmlist= {NULL, NULL};
- float *edgerect= NULL;
-
- /* allocate the necessary buffers */
- /* zbuffer inits these rects */
- pa->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto");
- pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
- pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
- for (rl= rr->layers.first; rl; rl= rl->next) {
- float *rect = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, R.viewname);
-
- if ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK))
- pa->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectmask");
-
- /* initialize pixelstructs and edge buffer */
- addpsmain(&psmlist);
- pa->rectdaps= MEM_callocN(sizeof(intptr_t)*pa->rectx*pa->recty+4, "zbufDArectd");
-
- if (rl->layflag & SCE_LAY_EDGE)
- if (R.r.mode & R_EDGE)
- edgerect= MEM_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge");
-
- /* always fill visibility */
- for (pa->sample=0; pa->sample<R.osa; pa->sample+=4) {
- ZbufSolidData sdata;
-
- sdata.rl= rl;
- sdata.psmlist= &psmlist;
- sdata.edgerect= edgerect;
- zbuffer_solid(pa, rl, make_pixelstructs, &sdata);
- if (R.test_break(R.tbh)) break;
- }
-
- /* shades solid */
- if (rl->layflag & SCE_LAY_SOLID)
- shadeDA_tile(pa, rl);
-
- /* lamphalo after solid, before ztra, looks nicest because ztra does own halo */
- if (R.flag & R_LAMPHALO)
- if (rl->layflag & SCE_LAY_HALO)
- lamphalo_tile(pa, rl);
-
- /* halo before ztra, because ztra fills in zbuffer now */
- if (R.flag & R_HALO)
- if (rl->layflag & SCE_LAY_HALO)
- halo_tile(pa, rl);
-
- /* transp layer */
- if (R.flag & R_ZTRA || R.totstrand) {
- if (rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) {
- if (pa->fullresult.first) {
- zbuffer_transp_shade(pa, rl, rect, &psmlist);
- }
- else {
- unsigned short *ztramask, *solidmask= NULL; /* 16 bits, MAX_OSA */
-
- /* allocate, but not free here, for asynchronous display of this rect in main thread */
- rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
-
- /* swap for live updates, and it is used in zbuf.c!!! */
- SWAP(float *, rl->acolrect, rect);
- ztramask = zbuffer_transp_shade(pa, rl, rect, &psmlist);
- SWAP(float *, rl->acolrect, rect);
-
- /* zbuffer transp only returns ztramask if there's solid rendered */
- if (ztramask)
- solidmask= make_solid_mask(pa);
-
- if (ztramask && solidmask) {
- unsigned short *sps= solidmask, *spz= ztramask;
- unsigned short fullmask= (1<<R.osa)-1;
- float *fcol= rect;
- float *acol= rl->acolrect;
- int x;
-
- for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4, sps++, spz++) {
- if (*sps == fullmask)
- addAlphaOverFloat(fcol, acol);
- else
- addAlphaOverFloatMask(fcol, acol, *sps, *spz);
- }
- }
- else {
- float *fcol= rect;
- float *acol= rl->acolrect;
- int x;
- for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) {
- addAlphaOverFloat(fcol, acol);
- }
- }
- if (solidmask) MEM_freeN(solidmask);
- if (ztramask) MEM_freeN(ztramask);
- }
- }
- }
-
- /* sun/sky */
- if (rl->layflag & SCE_LAY_SKY)
- atm_tile(pa, rl);
-
- /* sky before edge */
- if (rl->layflag & SCE_LAY_SKY)
- sky_tile(pa, rl);
-
- /* extra layers */
- if (rl->layflag & SCE_LAY_EDGE)
- if (R.r.mode & R_EDGE)
- edge_enhance_add(pa, rect, edgerect);
-
- if (rl->passflag & SCE_PASS_VECTOR)
- reset_sky_speed(pa, rl);
-
- /* clamp alpha to 0..1 range, can go outside due to filter */
- clamp_alpha_rgb_range(pa, rl);
-
- /* free stuff within loop! */
- MEM_freeN(pa->rectdaps); pa->rectdaps= NULL;
- freeps(&psmlist);
-
- if (edgerect) MEM_freeN(edgerect);
- edgerect= NULL;
-
- if (pa->rectmask) {
- MEM_freeN(pa->rectmask);
- pa->rectmask= NULL;
- }
- }
-
- /* free all */
- MEM_freeN(pa->recto); pa->recto= NULL;
- MEM_freeN(pa->rectp); pa->rectp= NULL;
- MEM_freeN(pa->rectz); pa->rectz= NULL;
-
- /* display active layer */
- rr->renrect.ymin=rr->renrect.ymax = 0;
- rr->renlay= render_get_active_layer(&R, rr);
-}
-
-
-/* ------------------------------------------------------------------------ */
-
-/* non OSA case, full tile render */
-/* supposed to be fully threadable! */
-void zbufshade_tile(RenderPart *pa)
-{
- ShadeSample ssamp;
- RenderResult *rr= pa->result;
- RenderLayer *rl;
- PixStr ps;
- float *edgerect= NULL;
-
- /* fake pixel struct, to comply to osa render */
- ps.next= NULL;
- ps.mask= 0xFFFF;
-
- /* zbuffer code clears/inits rects */
- pa->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto");
- pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
- pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
-
- for (rl= rr->layers.first; rl; rl= rl->next) {
- float *rect= RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, R.viewname);
- if ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK))
- pa->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectmask");
-
- /* general shader info, passes */
- shade_sample_initialize(&ssamp, pa, rl);
-
- zbuffer_solid(pa, rl, NULL, NULL);
-
- if (!R.test_break(R.tbh)) { /* NOTE: this if () is not consistent */
-
- /* edges only for solid part, ztransp doesn't support it yet anti-aliased */
- if (rl->layflag & SCE_LAY_EDGE) {
- if (R.r.mode & R_EDGE) {
- edgerect= MEM_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge");
- edge_enhance_tile(pa, edgerect, pa->rectz);
- }
- }
-
- /* initialize scanline updates for main thread */
- rr->renrect.ymin = 0;
- rr->renlay= rl;
-
- if (rl->layflag & SCE_LAY_SOLID) {
- const float *fcol = rect;
- const int *ro= pa->recto, *rp= pa->rectp, *rz= pa->rectz;
- int x, y, offs=0, seed;
-
- /* we set per pixel a fixed seed, for random AO and shadow samples */
- seed= pa->rectx*pa->disprect.ymin;
-
- /* irregular shadowb buffer creation */
- if (R.r.mode & R_SHADOW)
- ISB_create(pa, NULL);
-
- if (R.occlusiontree)
- cache_occ_samples(&R, pa, &ssamp);
-
- for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) {
- for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, ro++, rz++, rp++, fcol+=4, offs++) {
- /* per pixel fixed seed */
- BLI_thread_srandom(pa->thread, seed++);
-
- if (*rp) {
- ps.obi= *ro;
- ps.facenr= *rp;
- ps.z= *rz;
- if (shade_samples(&ssamp, &ps, x, y)) {
- /* combined and passes */
- add_passes(rl, offs, ssamp.shi, ssamp.shr);
- }
- }
- }
- if (y&1)
- if (R.test_break(R.tbh)) break;
- }
-
- if (R.occlusiontree)
- free_occ_samples(&R, pa);
-
- if (R.r.mode & R_SHADOW)
- ISB_free(pa);
- }
-
- /* disable scanline updating */
- rr->renlay= NULL;
- }
-
- /* lamphalo after solid, before ztra, looks nicest because ztra does own halo */
- if (R.flag & R_LAMPHALO)
- if (rl->layflag & SCE_LAY_HALO)
- lamphalo_tile(pa, rl);
-
- /* halo before ztra, because ztra fills in zbuffer now */
- if (R.flag & R_HALO)
- if (rl->layflag & SCE_LAY_HALO)
- halo_tile(pa, rl);
-
- if (R.flag & R_ZTRA || R.totstrand) {
- if (rl->layflag & (SCE_LAY_ZTRA|SCE_LAY_STRAND)) {
- float *fcol, *acol;
- int x;
-
- /* allocate, but not free here, for asynchronous display of this rect in main thread */
- rl->acolrect= MEM_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
-
- /* swap for live updates */
- SWAP(float *, rl->acolrect, rect);
- zbuffer_transp_shade(pa, rl, rect, NULL);
- SWAP(float *, rl->acolrect, rect);
-
- fcol= rect; acol= rl->acolrect;
- for (x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) {
- addAlphaOverFloat(fcol, acol);
- }
- }
- }
-
- /* sun/sky */
- if (rl->layflag & SCE_LAY_SKY)
- atm_tile(pa, rl);
-
- /* sky before edge */
- if (rl->layflag & SCE_LAY_SKY)
- sky_tile(pa, rl);
-
- if (!R.test_break(R.tbh)) {
- if (rl->layflag & SCE_LAY_EDGE)
- if (R.r.mode & R_EDGE)
- edge_enhance_add(pa, rect, edgerect);
- }
-
- if (rl->passflag & SCE_PASS_VECTOR)
- reset_sky_speed(pa, rl);
-
- if (edgerect) MEM_freeN(edgerect);
- edgerect= NULL;
-
- if (pa->rectmask) {
- MEM_freeN(pa->rectmask);
- pa->rectmask= NULL;
- }
- }
-
- /* display active layer */
- rr->renrect.ymin=rr->renrect.ymax = 0;
- rr->renlay= render_get_active_layer(&R, rr);
-
- MEM_freeN(pa->recto); pa->recto= NULL;
- MEM_freeN(pa->rectp); pa->rectp= NULL;
- MEM_freeN(pa->rectz); pa->rectz= NULL;
-}
-
-/* SSS preprocess tile render, fully threadable */
-typedef struct ZBufSSSHandle {
- RenderPart *pa;
- ListBase psmlist;
- int totps;
-} ZBufSSSHandle;
-
-static void addps_sss(void *cb_handle, int obi, int facenr, int x, int y, int z)
-{
- ZBufSSSHandle *handle = cb_handle;
- RenderPart *pa= handle->pa;
-
- /* extra border for filter gives double samples on part edges,
- * don't use those */
- if (x<pa->crop || x>=pa->rectx-pa->crop)
- return;
- if (y<pa->crop || y>=pa->recty-pa->crop)
- return;
-
- if (pa->rectall) {
- intptr_t *rs= pa->rectall + pa->rectx*y + x;
-
- addps(&handle->psmlist, rs, obi, facenr, z, 0, 0);
- handle->totps++;
- }
- if (pa->rectz) {
- int *rz= pa->rectz + pa->rectx*y + x;
- int *rp= pa->rectp + pa->rectx*y + x;
- int *ro= pa->recto + pa->rectx*y + x;
-
- if (z < *rz) {
- if (*rp == 0)
- handle->totps++;
- *rz= z;
- *rp= facenr;
- *ro= obi;
- }
- }
- if (pa->rectbackz) {
- int *rz= pa->rectbackz + pa->rectx*y + x;
- int *rp= pa->rectbackp + pa->rectx*y + x;
- int *ro= pa->rectbacko + pa->rectx*y + x;
-
- if (z >= *rz) {
- if (*rp == 0)
- handle->totps++;
- *rz= z;
- *rp= facenr;
- *ro= obi;
- }
- }
-}
-
-static void shade_sample_sss(ShadeSample *ssamp, Material *mat, ObjectInstanceRen *obi, VlakRen *vlr, int quad, float x, float y, float z, float *co, float color[3], float *area)
-{
- ShadeInput *shi= ssamp->shi;
- ShadeResult shr;
- float /* texfac,*/ /* UNUSED */ orthoarea, nor[3], alpha, sx, sy;
-
- /* cache for shadow */
- shi->samplenr= R.shadowsamplenr[shi->thread]++;
-
- if (quad)
- shade_input_set_triangle_i(shi, obi, vlr, 0, 2, 3);
- else
- shade_input_set_triangle_i(shi, obi, vlr, 0, 1, 2);
-
- /* center pixel */
- sx = x + 0.5f;
- sy = y + 0.5f;
-
- /* we estimate the area here using shi->dxco and shi->dyco. we need to
- * enabled shi->osatex these are filled. we compute two areas, one with
- * the normal pointed at the camera and one with the original normal, and
- * then clamp to avoid a too large contribution from a single pixel */
- shi->osatex= 1;
-
- copy_v3_v3(nor, shi->facenor);
- calc_view_vector(shi->facenor, sx, sy);
- normalize_v3(shi->facenor);
- shade_input_set_viewco(shi, x, y, sx, sy, z);
- orthoarea= len_v3(shi->dxco)*len_v3(shi->dyco);
-
- copy_v3_v3(shi->facenor, nor);
- shade_input_set_viewco(shi, x, y, sx, sy, z);
- *area = min_ff(len_v3(shi->dxco) * len_v3(shi->dyco), 2.0f * orthoarea);
-
- shade_input_set_uv(shi);
- shade_input_set_normals(shi);
-
- /* we don't want flipped normals, they screw up back scattering */
- if (shi->flippednor)
- shade_input_flip_normals(shi);
-
- /* not a pretty solution, but fixes common cases */
- if (shi->obr->ob && shi->obr->ob->transflag & OB_NEG_SCALE) {
- negate_v3(shi->vn);
- negate_v3(shi->vno);
- negate_v3(shi->nmapnorm);
- }
-
- /* if nodetree, use the material that we are currently preprocessing
- * instead of the node material */
- if (shi->mat->nodetree && shi->mat->use_nodes)
- shi->mat= mat;
-
- /* init material vars */
- shade_input_init_material(shi);
-
- /* render */
- shade_input_set_shade_texco(shi);
-
- shade_samples_do_AO(ssamp);
- shade_material_loop(shi, &shr);
-
- copy_v3_v3(co, shi->co);
- copy_v3_v3(color, shr.combined);
-
- /* texture blending */
- /* texfac= shi->mat->sss_texfac; */ /* UNUSED */
-
- alpha= shr.combined[3];
- *area *= alpha;
-}
-
-static void zbufshade_sss_free(RenderPart *pa)
-{
-#if 0
- MEM_freeN(pa->rectall); pa->rectall= NULL;
- freeps(&handle.psmlist);
-#else
- MEM_freeN(pa->rectz); pa->rectz= NULL;
- MEM_freeN(pa->rectp); pa->rectp= NULL;
- MEM_freeN(pa->recto); pa->recto= NULL;
- MEM_freeN(pa->rectbackz); pa->rectbackz= NULL;
- MEM_freeN(pa->rectbackp); pa->rectbackp= NULL;
- MEM_freeN(pa->rectbacko); pa->rectbacko= NULL;
-#endif
-}
-
-void zbufshade_sss_tile(RenderPart *pa)
-{
- Render *re= &R;
- ShadeSample ssamp;
- ZBufSSSHandle handle;
- RenderResult *rr= pa->result;
- RenderLayer *rl;
- VlakRen *vlr;
- Material *mat= re->sss_mat;
- float (*co)[3], (*color)[3], *area, *fcol;
- int x, y, seed, quad, totpoint;
- const bool display = (re->r.scemode & (R_BUTS_PREVIEW | R_VIEWPORT_PREVIEW)) == 0;
- int *ro, *rz, *rp, *rbo, *rbz, *rbp, lay;
-#if 0
- PixStr *ps;
- intptr_t *rs;
- int z;
-#endif
-
- /* setup pixelstr list and buffer for zbuffering */
- handle.pa= pa;
- handle.totps= 0;
-
-#if 0
- handle.psmlist.first= handle.psmlist.last= NULL;
- addpsmain(&handle.psmlist);
-
- pa->rectall= MEM_callocN(sizeof(intptr_t)*pa->rectx*pa->recty+4, "rectall");
-#else
- pa->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto");
- pa->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
- pa->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
- pa->rectbacko= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectbacko");
- pa->rectbackp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectbackp");
- pa->rectbackz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectbackz");
-#endif
-
- /* setup shade sample with correct passes */
- memset(&ssamp, 0, sizeof(ssamp));
- shade_sample_initialize(&ssamp, pa, rr->layers.first);
- ssamp.tot= 1;
-
- for (rl=rr->layers.first; rl; rl=rl->next) {
- ssamp.shi[0].lay |= rl->lay;
- ssamp.shi[0].layflag |= rl->layflag;
- ssamp.shi[0].passflag |= rl->passflag;
- ssamp.shi[0].combinedflag |= ~rl->pass_xor;
- }
-
- rl= rr->layers.first;
- ssamp.shi[0].passflag |= SCE_PASS_RGBA|SCE_PASS_COMBINED;
- ssamp.shi[0].combinedflag &= ~(SCE_PASS_SPEC);
- ssamp.shi[0].mat_override= NULL;
- ssamp.shi[0].light_override= NULL;
- lay= ssamp.shi[0].lay;
-
- /* create the pixelstrs to be used later */
- zbuffer_sss(pa, lay, &handle, addps_sss);
-
- if (handle.totps==0) {
- zbufshade_sss_free(pa);
- return;
- }
-
- fcol= RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, R.viewname);
-
- co= MEM_mallocN(sizeof(float)*3*handle.totps, "SSSCo");
- color= MEM_mallocN(sizeof(float)*3*handle.totps, "SSSColor");
- area= MEM_mallocN(sizeof(float)*handle.totps, "SSSArea");
-
-#if 0
- /* create ISB (does not work currently!) */
- if (re->r.mode & R_SHADOW)
- ISB_create(pa, NULL);
-#endif
-
- if (display) {
- /* initialize scanline updates for main thread */
- rr->renrect.ymin = 0;
- rr->renlay= rl;
- }
-
- seed= pa->rectx*pa->disprect.ymin;
-#if 0
- rs= pa->rectall;
-#else
- rz= pa->rectz;
- rp= pa->rectp;
- ro= pa->recto;
- rbz= pa->rectbackz;
- rbp= pa->rectbackp;
- rbo= pa->rectbacko;
-#endif
- totpoint= 0;
-
- for (y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) {
- for (x=pa->disprect.xmin; x<pa->disprect.xmax; x++, fcol+=4) {
- /* per pixel fixed seed */
- BLI_thread_srandom(pa->thread, seed++);
-
-#if 0
- if (rs) {
- /* for each sample in this pixel, shade it */
- for (ps = (PixStr *)(*rs); ps; ps=ps->next) {
- ObjectInstanceRen *obi= &re->objectinstance[ps->obi];
- ObjectRen *obr= obi->obr;
- vlr= RE_findOrAddVlak(obr, (ps->facenr-1) & RE_QUAD_MASK);
- quad= (ps->facenr & RE_QUAD_OFFS);
- z= ps->z;
-
- shade_sample_sss(&ssamp, mat, obi, vlr, quad, x, y, z,
- co[totpoint], color[totpoint], &area[totpoint]);
-
- totpoint++;
-
- add_v3_v3(fcol, color);
- fcol[3]= 1.0f;
- }
-
- rs++;
- }
-#else
- if (rp) {
- if (*rp != 0) {
- ObjectInstanceRen *obi= &re->objectinstance[*ro];
- ObjectRen *obr= obi->obr;
-
- /* shade front */
- vlr= RE_findOrAddVlak(obr, (*rp-1) & RE_QUAD_MASK);
- quad= ((*rp) & RE_QUAD_OFFS);
-
- shade_sample_sss(&ssamp, mat, obi, vlr, quad, x, y, *rz,
- co[totpoint], color[totpoint], &area[totpoint]);
-
- add_v3_v3(fcol, color[totpoint]);
- fcol[3]= 1.0f;
- totpoint++;
- }
-
- rp++; rz++; ro++;
- }
-
- if (rbp) {
- if (*rbp != 0 && !(*rbp == *(rp-1) && *rbo == *(ro-1))) {
- ObjectInstanceRen *obi= &re->objectinstance[*rbo];
- ObjectRen *obr= obi->obr;
-
- /* shade back */
- vlr= RE_findOrAddVlak(obr, (*rbp-1) & RE_QUAD_MASK);
- quad= ((*rbp) & RE_QUAD_OFFS);
-
- shade_sample_sss(&ssamp, mat, obi, vlr, quad, x, y, *rbz,
- co[totpoint], color[totpoint], &area[totpoint]);
-
- /* to indicate this is a back sample */
- area[totpoint]= -area[totpoint];
-
- add_v3_v3(fcol, color[totpoint]);
- fcol[3]= 1.0f;
- totpoint++;
- }
-
- rbz++; rbp++; rbo++;
- }
-#endif
- }
-
- if (y&1)
- if (re->test_break(re->tbh)) break;
- }
-
- /* note: after adding we do not free these arrays, sss keeps them */
- if (totpoint > 0) {
- sss_add_points(re, co, color, area, totpoint);
- }
- else {
- MEM_freeN(co);
- MEM_freeN(color);
- MEM_freeN(area);
- }
-
-#if 0
- if (re->r.mode & R_SHADOW)
- ISB_free(pa);
-#endif
-
- if (display) {
- /* display active layer */
- rr->renrect.ymin=rr->renrect.ymax = 0;
- rr->renlay= render_get_active_layer(&R, rr);
- }
-
- zbufshade_sss_free(pa);
-}
-
-/* ------------------------------------------------------------------------ */
-
-static void renderhalo_post(RenderResult *rr, float *rectf, HaloRen *har) /* postprocess version */
-{
- float dist, xsq, ysq, xn, yn, colf[4], *rectft, *rtf;
- float haloxs, haloys;
- int minx, maxx, miny, maxy, x, y;
-
- /* calculate the disprect mapped coordinate for halo. note: rectx is disprect corrected */
- haloxs= har->xs - R.disprect.xmin;
- haloys= har->ys - R.disprect.ymin;
-
- har->miny= miny= haloys - har->rad/R.ycor;
- har->maxy= maxy= haloys + har->rad/R.ycor;
-
- if (maxy < 0) {
- /* pass */
- }
- else if (rr->recty < miny) {
- /* pass */
- }
- else {
- minx = floor(haloxs - har->rad);
- maxx = ceil(haloxs + har->rad);
-
- if (maxx < 0) {
- /* pass */
- }
- else if (rr->rectx < minx) {
- /* pass */
- }
- else {
- if (minx<0) minx= 0;
- if (maxx>=rr->rectx) maxx= rr->rectx-1;
- if (miny<0) miny= 0;
- if (maxy>rr->recty) maxy= rr->recty;
-
- rectft= rectf+ 4*rr->rectx*miny;
-
- for (y=miny; y<maxy; y++) {
-
- rtf= rectft+4*minx;
-
- yn= (y - haloys)*R.ycor;
- ysq= yn*yn;
-
- for (x=minx; x<=maxx; x++) {
- xn= x - haloxs;
- xsq= xn*xn;
- dist= xsq+ysq;
- if (dist<har->radsq) {
-
- if (shadeHaloFloat(har, colf, 0x7FFFFF, dist, xn, yn, har->flarec))
- addalphaAddfacFloat(rtf, colf, har->add);
- }
- rtf+=4;
- }
-
- rectft+= 4*rr->rectx;
-
- if (R.test_break(R.tbh)) break;
- }
- }
- }
-}
-/* ------------------------------------------------------------------------ */
-
-static void renderflare(RenderResult *rr, float *rectf, HaloRen *har)
-{
- extern const float hashvectf[];
- HaloRen fla;
- Material *ma;
- const float *rc;
- float rad, alfa, visifac, vec[3];
- int b, type;
-
- fla= *har;
- fla.linec= fla.ringc= fla.flarec= 0;
-
- rad= har->rad;
- alfa= har->alfa;
-
- visifac= R.ycor*(har->pixels);
- /* all radials added / r^3 == 1.0f! */
- visifac /= (har->rad*har->rad*har->rad);
- visifac*= visifac;
-
- ma= har->mat;
-
- /* first halo: just do */
-
- har->rad= rad*ma->flaresize*visifac;
- har->radsq= har->rad*har->rad;
- har->zs= fla.zs= 0;
-
- har->alfa= alfa*visifac;
-
- renderhalo_post(rr, rectf, har);
-
- /* next halo's: the flares */
- rc= hashvectf + ma->seed2;
-
- for (b=1; b<har->flarec; b++) {
-
- fla.r = fabsf(rc[0]);
- fla.g = fabsf(rc[1]);
- fla.b = fabsf(rc[2]);
- fla.alfa= ma->flareboost*fabsf(alfa*visifac*rc[3]);
- fla.hard= 20.0f + fabsf(70.0f*rc[7]);
- fla.tex= 0;
-
- type= (int)(fabsf(3.9f*rc[6]));
-
- fla.rad = ma->subsize * sqrtf(fabsf(2.0f * har->rad * rc[4]));
-
- if (type==3) {
- fla.rad*= 3.0f;
- fla.rad+= R.rectx/10;
- }
-
- fla.radsq= fla.rad*fla.rad;
-
- vec[0]= 1.4f*rc[5]*(har->xs-R.winx/2);
- vec[1]= 1.4f*rc[5]*(har->ys-R.winy/2);
- vec[2]= 32.0f*sqrtf(vec[0]*vec[0] + vec[1]*vec[1] + 1.0f);
-
- fla.xs= R.winx/2 + vec[0] + (1.2f+rc[8])*R.rectx*vec[0]/vec[2];
- fla.ys= R.winy/2 + vec[1] + (1.2f+rc[8])*R.rectx*vec[1]/vec[2];
-
- if (R.flag & R_SEC_FIELD) {
- if (R.r.mode & R_ODDFIELD) fla.ys += 0.5f;
- else fla.ys -= 0.5f;
- }
- if (type & 1) fla.type= HA_FLARECIRC;
- else fla.type= 0;
- renderhalo_post(rr, rectf, &fla);
-
- fla.alfa*= 0.5f;
- if (type & 2) fla.type= HA_FLARECIRC;
- else fla.type= 0;
- renderhalo_post(rr, rectf, &fla);
-
- rc+= 7;
- }
-}
-
-/* needs recode... integrate this better! */
-void add_halo_flare(Render *re)
-{
- RenderResult *rr= re->result;
- RenderLayer *rl;
- HaloRen *har;
- int a, mode;
- float *rect;
-
- /* for now, we get the first renderlayer in list with halos set */
- for (rl= rr->layers.first; rl; rl= rl->next) {
- bool do_draw = false;
-
- if ((rl->layflag & SCE_LAY_HALO) == 0)
- continue;
-
- rect = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, re->viewname);
-
- if (rect==NULL)
- continue;
-
- mode= R.r.mode;
- R.r.mode &= ~R_PANORAMA;
-
- project_renderdata(&R, projectverto, 0, 0, 0);
-
- for (a=0; a<R.tothalo; a++) {
- har= R.sortedhalos[a];
-
- if (har->flarec && (har->lay & rl->lay)) {
- do_draw = true;
- renderflare(rr, rect, har);
- }
- }
-
- if (do_draw) {
- /* weak... the display callback wants an active renderlayer pointer... */
- rr->renlay= rl;
- re->display_update(re->duh, rr, NULL);
- }
-
- R.r.mode= mode;
- }
-}
-
-void render_internal_update_passes(RenderEngine *engine, Scene *scene, SceneRenderLayer *srl)
-{
- int type;
-
- RE_engine_register_pass(engine, scene, srl, RE_PASSNAME_COMBINED, 4, "RGBA", SOCK_RGBA);
-
-#define CHECK_PASS(name, channels, chanid) \
- if (srl->passflag & (SCE_PASS_ ## name)) { \
- if (channels == 4) type = SOCK_RGBA; \
- else if (channels == 3) type = SOCK_VECTOR; \
- else type = SOCK_FLOAT; \
- RE_engine_register_pass(engine, scene, srl, RE_PASSNAME_ ## name, channels, chanid, type); \
- }
-
- CHECK_PASS(Z, 1, "Z");
- CHECK_PASS(VECTOR, 4, "XYZW");
- CHECK_PASS(NORMAL, 3, "XYZ");
- CHECK_PASS(UV, 3, "UVA");
- CHECK_PASS(RGBA, 4, "RGBA");
- CHECK_PASS(EMIT, 3, "RGB");
- CHECK_PASS(DIFFUSE, 3, "RGB");
- CHECK_PASS(SPEC, 3, "RGB");
- CHECK_PASS(AO, 3, "RGB");
- CHECK_PASS(ENVIRONMENT, 3, "RGB");
- CHECK_PASS(INDIRECT, 3, "RGB");
- CHECK_PASS(SHADOW, 3, "RGB");
- CHECK_PASS(REFLECT, 3, "RGB");
- CHECK_PASS(REFRACT, 3, "RGB");
- CHECK_PASS(INDEXOB, 1, "X");
- CHECK_PASS(INDEXMA, 1, "X");
- CHECK_PASS(MIST, 1, "Z");
-
-#undef CHECK_PASS
-}
diff --git a/source/blender/render/intern/source/renderdatabase.c b/source/blender/render/intern/source/renderdatabase.c
deleted file mode 100644
index 2fbfcc64c8f..00000000000
--- a/source/blender/render/intern/source/renderdatabase.c
+++ /dev/null
@@ -1,1603 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): 2004-2006, Blender Foundation, full recode
- *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/renderdatabase.c
- * \ingroup render
- */
-
-
-/*
- * Storage, retrieval and query of render specific data.
- *
- * All data from a Blender scene is converted by the renderconverter/
- * into a special format that is used by the render module to make
- * images out of. These functions interface to the render-specific
- * database.
- *
- * The blo{ha/ve/vl} arrays store pointers to blocks of 256 data
- * entries each.
- *
- * The index of an entry is >>8 (the highest 24 * bits), to find an
- * offset in a 256-entry block.
- *
- * - If the 256-entry block entry has an entry in the
- * vertnodes/vlaknodes/bloha array of the current block, the i-th entry in
- * that block is allocated to this entry.
- *
- * - If the entry has no block allocated for it yet, memory is
- * allocated.
- *
- * The pointer to the correct entry is returned. Memory is guaranteed
- * to exist (as long as the malloc does not break). Since guarded
- * allocation is used, memory _must_ be available. Otherwise, an
- * exit(0) would occur.
- *
- */
-
-#include <limits.h>
-#include <math.h>
-#include <string.h>
-
-#include "MEM_guardedalloc.h"
-
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-#include "BLI_hash.h"
-
-#include "DNA_material_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_listBase.h"
-#include "DNA_particle_types.h"
-
-#include "BKE_customdata.h"
-#include "BKE_DerivedMesh.h"
-
-#include "RE_render_ext.h" /* externtex */
-
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "render_types.h"
-#include "renderdatabase.h"
-#include "zbuf.h"
-
-/* ------------------------------------------------------------------------- */
-
-/* More dynamic allocation of options for render vertices and faces, so we don't
- * have to reserve this space inside vertices.
- * Important; vertices and faces, should have been created already (to get tables
- * checked) that's a reason why the calls demand VertRen/VlakRen * as arg, not
- * the index */
-
-/* NOTE! the hardcoded table size 256 is used still in code for going quickly over vertices/faces */
-#define RE_STRESS_ELEMS 1
-#define RE_RAD_ELEMS 4
-#define RE_STRAND_ELEMS 1
-#define RE_TANGENT_ELEMS 3
-#define RE_WINSPEED_ELEMS 4
-#define RE_MTFACE_ELEMS 1
-#define RE_MCOL_ELEMS 4
-#define RE_UV_ELEMS 2
-#define RE_VLAK_ORIGINDEX_ELEMS 1
-#define RE_VERT_ORIGINDEX_ELEMS 1
-#define RE_SURFNOR_ELEMS 3
-#define RE_RADFACE_ELEMS 1
-#define RE_SIMPLIFY_ELEMS 2
-#define RE_FACE_ELEMS 1
-#define RE_NMAP_TANGENT_ELEMS 16
-
-float *RE_vertren_get_stress(ObjectRen *obr, VertRen *ver, int verify)
-{
- float *stress;
- int nr= ver->index>>8;
-
- stress= obr->vertnodes[nr].stress;
- if (stress==NULL) {
- if (verify)
- stress= obr->vertnodes[nr].stress= MEM_mallocN(256*RE_STRESS_ELEMS*sizeof(float), "stress table");
- else
- return NULL;
- }
- return stress + (ver->index & 255)*RE_STRESS_ELEMS;
-}
-
-/* this one callocs! */
-float *RE_vertren_get_rad(ObjectRen *obr, VertRen *ver, int verify)
-{
- float *rad;
- int nr= ver->index>>8;
-
- rad= obr->vertnodes[nr].rad;
- if (rad==NULL) {
- if (verify)
- rad= obr->vertnodes[nr].rad= MEM_callocN(256*RE_RAD_ELEMS*sizeof(float), "rad table");
- else
- return NULL;
- }
- return rad + (ver->index & 255)*RE_RAD_ELEMS;
-}
-
-float *RE_vertren_get_strand(ObjectRen *obr, VertRen *ver, int verify)
-{
- float *strand;
- int nr= ver->index>>8;
-
- strand= obr->vertnodes[nr].strand;
- if (strand==NULL) {
- if (verify)
- strand= obr->vertnodes[nr].strand= MEM_mallocN(256*RE_STRAND_ELEMS*sizeof(float), "strand table");
- else
- return NULL;
- }
- return strand + (ver->index & 255)*RE_STRAND_ELEMS;
-}
-
-/* needs calloc */
-float *RE_vertren_get_tangent(ObjectRen *obr, VertRen *ver, int verify)
-{
- float *tangent;
- int nr= ver->index>>8;
-
- tangent= obr->vertnodes[nr].tangent;
- if (tangent==NULL) {
- if (verify)
- tangent= obr->vertnodes[nr].tangent= MEM_callocN(256*RE_TANGENT_ELEMS*sizeof(float), "tangent table");
- else
- return NULL;
- }
- return tangent + (ver->index & 255)*RE_TANGENT_ELEMS;
-}
-
-/* needs calloc! not all renderverts have them */
-/* also winspeed is exception, it is stored per instance */
-float *RE_vertren_get_winspeed(ObjectInstanceRen *obi, VertRen *ver, int verify)
-{
- float *winspeed;
- int totvector;
-
- winspeed= obi->vectors;
- if (winspeed==NULL) {
- if (verify) {
- totvector= obi->obr->totvert + obi->obr->totstrand;
- winspeed= obi->vectors= MEM_callocN(totvector*RE_WINSPEED_ELEMS*sizeof(float), "winspeed table");
- }
- else
- return NULL;
- }
- return winspeed + ver->index*RE_WINSPEED_ELEMS;
-}
-
-int *RE_vertren_get_origindex(ObjectRen *obr, VertRen *ver, int verify)
-{
- int *origindex;
- int nr= ver->index>>8;
-
- origindex= obr->vertnodes[nr].origindex;
- if (origindex==NULL) {
- if (verify)
- origindex= obr->vertnodes[nr].origindex= MEM_mallocN(256*RE_VERT_ORIGINDEX_ELEMS*sizeof(int), "origindex table");
- else
- return NULL;
- }
- return origindex + (ver->index & 255)*RE_VERT_ORIGINDEX_ELEMS;
-}
-
-VertRen *RE_vertren_copy(ObjectRen *obr, VertRen *ver)
-{
- VertRen *v1= RE_findOrAddVert(obr, obr->totvert++);
- float *fp1, *fp2;
- int *int1, *int2;
- int index= v1->index;
-
- *v1= *ver;
- v1->index= index;
-
- fp1= RE_vertren_get_stress(obr, ver, 0);
- if (fp1) {
- fp2= RE_vertren_get_stress(obr, v1, 1);
- memcpy(fp2, fp1, RE_STRESS_ELEMS*sizeof(float));
- }
- fp1= RE_vertren_get_rad(obr, ver, 0);
- if (fp1) {
- fp2= RE_vertren_get_rad(obr, v1, 1);
- memcpy(fp2, fp1, RE_RAD_ELEMS*sizeof(float));
- }
- fp1= RE_vertren_get_strand(obr, ver, 0);
- if (fp1) {
- fp2= RE_vertren_get_strand(obr, v1, 1);
- memcpy(fp2, fp1, RE_STRAND_ELEMS*sizeof(float));
- }
- fp1= RE_vertren_get_tangent(obr, ver, 0);
- if (fp1) {
- fp2= RE_vertren_get_tangent(obr, v1, 1);
- memcpy(fp2, fp1, RE_TANGENT_ELEMS*sizeof(float));
- }
- int1= RE_vertren_get_origindex(obr, ver, 0);
- if (int1) {
- int2= RE_vertren_get_origindex(obr, v1, 1);
- memcpy(int2, int1, RE_VERT_ORIGINDEX_ELEMS*sizeof(int));
- }
- return v1;
-}
-
-VertRen *RE_findOrAddVert(ObjectRen *obr, int nr)
-{
- VertTableNode *temp;
- VertRen *v;
- int a;
-
- if (nr<0) {
- printf("error in findOrAddVert: %d\n", nr);
- return NULL;
- }
- a= nr>>8;
-
- if (a>=obr->vertnodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */
- temp= obr->vertnodes;
-
- obr->vertnodes= MEM_mallocN(sizeof(VertTableNode)*(obr->vertnodeslen+TABLEINITSIZE), "vertnodes");
- if (temp) memcpy(obr->vertnodes, temp, obr->vertnodeslen*sizeof(VertTableNode));
- memset(obr->vertnodes+obr->vertnodeslen, 0, TABLEINITSIZE*sizeof(VertTableNode));
-
- obr->vertnodeslen+=TABLEINITSIZE;
- if (temp) MEM_freeN(temp);
- }
-
- v= obr->vertnodes[a].vert;
- if (v==NULL) {
- int i;
-
- v= (VertRen *)MEM_callocN(256*sizeof(VertRen), "findOrAddVert");
- obr->vertnodes[a].vert= v;
-
- for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++) {
- v[a].index= i;
- }
- }
- v+= (nr & 255);
- return v;
-}
-
-/* ------------------------------------------------------------------------ */
-
-MTFace *RE_vlakren_get_tface(ObjectRen *obr, VlakRen *vlr, int n, char **name, int verify)
-{
- VlakTableNode *node;
- int nr= vlr->index>>8, vlakindex= (vlr->index&255);
- int index= (n<<8) + vlakindex;
-
- node= &obr->vlaknodes[nr];
-
- if (verify) {
- if (n>=node->totmtface) {
- MTFace *mtface= node->mtface;
- int size= (n+1)*256;
-
- node->mtface= MEM_callocN(size*sizeof(MTFace), "Vlak mtface");
-
- if (mtface) {
- size= node->totmtface*256;
- memcpy(node->mtface, mtface, size*sizeof(MTFace));
- MEM_freeN(mtface);
- }
-
- node->totmtface= n+1;
- }
- }
- else {
- if (n>=node->totmtface)
- return NULL;
-
- if (name) *name= obr->mtface[n];
- }
-
- return node->mtface + index;
-}
-
-MCol *RE_vlakren_get_mcol(ObjectRen *obr, VlakRen *vlr, int n, char **name, int verify)
-{
- VlakTableNode *node;
- int nr= vlr->index>>8, vlakindex= (vlr->index&255);
- int index= (n<<8) + vlakindex;
-
- node= &obr->vlaknodes[nr];
-
- if (verify) {
- if (n>=node->totmcol) {
- MCol *mcol= node->mcol;
- int size= (n+1)*256;
-
- node->mcol= MEM_callocN(size*sizeof(MCol)*RE_MCOL_ELEMS, "Vlak mcol");
-
- if (mcol) {
- size= node->totmcol*256;
- memcpy(node->mcol, mcol, size*sizeof(MCol)*RE_MCOL_ELEMS);
- MEM_freeN(mcol);
- }
-
- node->totmcol= n+1;
- }
- }
- else {
- if (n>=node->totmcol)
- return NULL;
-
- if (name) *name= obr->mcol[n];
- }
-
- return node->mcol + index*RE_MCOL_ELEMS;
-}
-
-int *RE_vlakren_get_origindex(ObjectRen *obr, VlakRen *vlak, int verify)
-{
- int *origindex;
- int nr= vlak->index>>8;
-
- origindex= obr->vlaknodes[nr].origindex;
- if (origindex==NULL) {
- if (verify)
- origindex= obr->vlaknodes[nr].origindex= MEM_callocN(256*RE_VLAK_ORIGINDEX_ELEMS*sizeof(int), "origindex table");
- else
- return NULL;
- }
- return origindex + (vlak->index & 255)*RE_VLAK_ORIGINDEX_ELEMS;
-}
-
-float *RE_vlakren_get_surfnor(ObjectRen *obr, VlakRen *vlak, int verify)
-{
- float *surfnor;
- int nr= vlak->index>>8;
-
- surfnor= obr->vlaknodes[nr].surfnor;
- if (surfnor==NULL) {
- if (verify)
- surfnor= obr->vlaknodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor table");
- else
- return NULL;
- }
- return surfnor + (vlak->index & 255)*RE_SURFNOR_ELEMS;
-}
-
-float *RE_vlakren_get_nmap_tangent(ObjectRen *obr, VlakRen *vlak, int index, bool verify)
-{
- float **tangents;
- int nr= vlak->index>>8;
-
- tangents = obr->vlaknodes[nr].tangent_arrays;
-
- if (index + 1 > 8) {
- return NULL;
- }
-
- index = index < 0 ? 0: index;
-
- if (tangents[index] == NULL) {
- if (verify) {
- tangents[index] = MEM_callocN(256*RE_NMAP_TANGENT_ELEMS*sizeof(float), "tangent table");
- }
- else
- return NULL;
- }
-
- return tangents[index] + (vlak->index & 255)*RE_NMAP_TANGENT_ELEMS;
-}
-
-RadFace **RE_vlakren_get_radface(ObjectRen *obr, VlakRen *vlak, int verify)
-{
- RadFace **radface;
- int nr= vlak->index>>8;
-
- radface= obr->vlaknodes[nr].radface;
- if (radface==NULL) {
- if (verify)
- radface = obr->vlaknodes[nr].radface= MEM_callocN(256 * RE_RADFACE_ELEMS * sizeof(void *), "radface table");
- else
- return NULL;
- }
- return radface + (vlak->index & 255)*RE_RADFACE_ELEMS;
-}
-
-VlakRen *RE_vlakren_copy(ObjectRen *obr, VlakRen *vlr)
-{
- VlakRen *vlr1 = RE_findOrAddVlak(obr, obr->totvlak++);
- MTFace *mtface, *mtface1;
- MCol *mcol, *mcol1;
- float *surfnor, *surfnor1;
- float *tangent, *tangent1;
- int *origindex, *origindex1;
- RadFace **radface, **radface1;
- int i, index = vlr1->index;
- char *name;
-
- *vlr1= *vlr;
- vlr1->index= index;
-
- for (i=0; (mtface=RE_vlakren_get_tface(obr, vlr, i, &name, 0)) != NULL; i++) {
- mtface1= RE_vlakren_get_tface(obr, vlr1, i, &name, 1);
- memcpy(mtface1, mtface, sizeof(MTFace)*RE_MTFACE_ELEMS);
- }
-
- for (i=0; (mcol=RE_vlakren_get_mcol(obr, vlr, i, &name, 0)) != NULL; i++) {
- mcol1= RE_vlakren_get_mcol(obr, vlr1, i, &name, 1);
- memcpy(mcol1, mcol, sizeof(MCol)*RE_MCOL_ELEMS);
- }
-
- origindex= RE_vlakren_get_origindex(obr, vlr, 0);
- if (origindex) {
- origindex1= RE_vlakren_get_origindex(obr, vlr1, 1);
- /* Just an int, but memcpy for consistency. */
- memcpy(origindex1, origindex, sizeof(int)*RE_VLAK_ORIGINDEX_ELEMS);
- }
-
- surfnor= RE_vlakren_get_surfnor(obr, vlr, 0);
- if (surfnor) {
- surfnor1= RE_vlakren_get_surfnor(obr, vlr1, 1);
- copy_v3_v3(surfnor1, surfnor);
- }
-
- for (i=0; i < MAX_MTFACE; i++) {
- tangent = RE_vlakren_get_nmap_tangent(obr, vlr, i, false);
- if (!tangent)
- continue;
- tangent1 = RE_vlakren_get_nmap_tangent(obr, vlr1, i, true);
- memcpy(tangent1, tangent, sizeof(float)*RE_NMAP_TANGENT_ELEMS);
- }
-
- radface= RE_vlakren_get_radface(obr, vlr, 0);
- if (radface) {
- radface1= RE_vlakren_get_radface(obr, vlr1, 1);
- *radface1= *radface;
- }
-
- return vlr1;
-}
-
-void RE_vlakren_get_normal(Render *UNUSED(re), ObjectInstanceRen *obi, VlakRen *vlr, float r_nor[3])
-{
- float (*nmat)[3]= obi->nmat;
-
- if (obi->flag & R_TRANSFORMED) {
- mul_v3_m3v3(r_nor, nmat, vlr->n);
- normalize_v3(r_nor);
- }
- else {
- copy_v3_v3(r_nor, vlr->n);
- }
-}
-
-void RE_set_customdata_names(ObjectRen *obr, CustomData *data)
-{
- /* CustomData layer names are stored per object here, because the
- * DerivedMesh which stores the layers is freed */
-
- CustomDataLayer *layer;
- int numtf = 0, numcol = 0, i, mtfn, mcn;
-
- if (CustomData_has_layer(data, CD_MTFACE)) {
- numtf= CustomData_number_of_layers(data, CD_MTFACE);
- obr->mtface= MEM_callocN(sizeof(*obr->mtface)*numtf, "mtfacenames");
- }
-
- if (CustomData_has_layer(data, CD_MCOL)) {
- numcol= CustomData_number_of_layers(data, CD_MCOL);
- obr->mcol= MEM_callocN(sizeof(*obr->mcol)*numcol, "mcolnames");
- }
-
- for (i=0, mtfn=0, mcn=0; i < data->totlayer; i++) {
- layer= &data->layers[i];
-
- if (layer->type == CD_MTFACE) {
- BLI_strncpy(obr->mtface[mtfn++], layer->name, sizeof(layer->name));
- obr->actmtface= CLAMPIS(layer->active_rnd, 0, numtf);
- obr->bakemtface= layer->active;
- }
- else if (layer->type == CD_MCOL) {
- BLI_strncpy(obr->mcol[mcn++], layer->name, sizeof(layer->name));
- obr->actmcol= CLAMPIS(layer->active_rnd, 0, numcol);
- }
- }
-}
-
-VlakRen *RE_findOrAddVlak(ObjectRen *obr, int nr)
-{
- VlakTableNode *temp;
- VlakRen *v;
- int a;
-
- if (nr<0) {
- printf("error in findOrAddVlak: %d\n", nr);
- return obr->vlaknodes[0].vlak;
- }
- a= nr>>8;
-
- if (a>=obr->vlaknodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */
- temp= obr->vlaknodes;
-
- obr->vlaknodes= MEM_mallocN(sizeof(VlakTableNode)*(obr->vlaknodeslen+TABLEINITSIZE), "vlaknodes");
- if (temp) memcpy(obr->vlaknodes, temp, obr->vlaknodeslen*sizeof(VlakTableNode));
- memset(obr->vlaknodes+obr->vlaknodeslen, 0, TABLEINITSIZE*sizeof(VlakTableNode));
-
- obr->vlaknodeslen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/
- if (temp) MEM_freeN(temp);
- }
-
- v= obr->vlaknodes[a].vlak;
-
- if (v==NULL) {
- int i;
-
- v= (VlakRen *)MEM_callocN(256*sizeof(VlakRen), "findOrAddVlak");
- obr->vlaknodes[a].vlak= v;
-
- for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++)
- v[a].index= i;
- }
- v+= (nr & 255);
- return v;
-}
-
-/* ------------------------------------------------------------------------ */
-
-float *RE_strandren_get_surfnor(ObjectRen *obr, StrandRen *strand, int verify)
-{
- float *surfnor;
- int nr= strand->index>>8;
-
- surfnor= obr->strandnodes[nr].surfnor;
- if (surfnor==NULL) {
- if (verify)
- surfnor= obr->strandnodes[nr].surfnor= MEM_callocN(256*RE_SURFNOR_ELEMS*sizeof(float), "surfnor strand table");
- else
- return NULL;
- }
- return surfnor + (strand->index & 255)*RE_SURFNOR_ELEMS;
-}
-
-float *RE_strandren_get_uv(ObjectRen *obr, StrandRen *strand, int n, char **name, int verify)
-{
- StrandTableNode *node;
- int nr= strand->index>>8, strandindex= (strand->index&255);
- int index= (n<<8) + strandindex;
-
- node= &obr->strandnodes[nr];
-
- if (verify) {
- if (n>=node->totuv) {
- float *uv= node->uv;
- int size= (n+1)*256;
-
- node->uv= MEM_callocN(size*sizeof(float)*RE_UV_ELEMS, "strand uv table");
-
- if (uv) {
- size= node->totuv*256;
- memcpy(node->uv, uv, size*sizeof(float)*RE_UV_ELEMS);
- MEM_freeN(uv);
- }
-
- node->totuv= n+1;
- }
- }
- else {
- if (n>=node->totuv)
- return NULL;
-
- if (name) *name= obr->mtface[n];
- }
-
- return node->uv + index*RE_UV_ELEMS;
-}
-
-MCol *RE_strandren_get_mcol(ObjectRen *obr, StrandRen *strand, int n, char **name, int verify)
-{
- StrandTableNode *node;
- int nr= strand->index>>8, strandindex= (strand->index&255);
- int index= (n<<8) + strandindex;
-
- node= &obr->strandnodes[nr];
-
- if (verify) {
- if (n>=node->totmcol) {
- MCol *mcol= node->mcol;
- int size= (n+1)*256;
-
- node->mcol= MEM_callocN(size*sizeof(MCol)*RE_MCOL_ELEMS, "strand mcol table");
-
- if (mcol) {
- size= node->totmcol*256;
- memcpy(node->mcol, mcol, size*sizeof(MCol)*RE_MCOL_ELEMS);
- MEM_freeN(mcol);
- }
-
- node->totmcol= n+1;
- }
- }
- else {
- if (n>=node->totmcol)
- return NULL;
-
- if (name) *name= obr->mcol[n];
- }
-
- return node->mcol + index*RE_MCOL_ELEMS;
-}
-
-float *RE_strandren_get_simplify(struct ObjectRen *obr, struct StrandRen *strand, int verify)
-{
- float *simplify;
- int nr= strand->index>>8;
-
- simplify= obr->strandnodes[nr].simplify;
- if (simplify==NULL) {
- if (verify)
- simplify= obr->strandnodes[nr].simplify= MEM_callocN(256*RE_SIMPLIFY_ELEMS*sizeof(float), "simplify strand table");
- else
- return NULL;
- }
- return simplify + (strand->index & 255)*RE_SIMPLIFY_ELEMS;
-}
-
-int *RE_strandren_get_face(ObjectRen *obr, StrandRen *strand, int verify)
-{
- int *face;
- int nr= strand->index>>8;
-
- face= obr->strandnodes[nr].face;
- if (face==NULL) {
- if (verify)
- face= obr->strandnodes[nr].face= MEM_callocN(256*RE_FACE_ELEMS*sizeof(int), "face strand table");
- else
- return NULL;
- }
- return face + (strand->index & 255)*RE_FACE_ELEMS;
-}
-
-/* winspeed is exception, it is stored per instance */
-float *RE_strandren_get_winspeed(ObjectInstanceRen *obi, StrandRen *strand, int verify)
-{
- float *winspeed;
- int totvector;
-
- winspeed= obi->vectors;
- if (winspeed==NULL) {
- if (verify) {
- totvector= obi->obr->totvert + obi->obr->totstrand;
- winspeed= obi->vectors= MEM_callocN(totvector*RE_WINSPEED_ELEMS*sizeof(float), "winspeed strand table");
- }
- else
- return NULL;
- }
- return winspeed + (obi->obr->totvert + strand->index)*RE_WINSPEED_ELEMS;
-}
-
-StrandRen *RE_findOrAddStrand(ObjectRen *obr, int nr)
-{
- StrandTableNode *temp;
- StrandRen *v;
- int a;
-
- if (nr<0) {
- printf("error in findOrAddStrand: %d\n", nr);
- return obr->strandnodes[0].strand;
- }
- a= nr>>8;
-
- if (a>=obr->strandnodeslen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */
- temp= obr->strandnodes;
-
- obr->strandnodes= MEM_mallocN(sizeof(StrandTableNode)*(obr->strandnodeslen+TABLEINITSIZE), "strandnodes");
- if (temp) memcpy(obr->strandnodes, temp, obr->strandnodeslen*sizeof(StrandTableNode));
- memset(obr->strandnodes+obr->strandnodeslen, 0, TABLEINITSIZE*sizeof(StrandTableNode));
-
- obr->strandnodeslen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/
- if (temp) MEM_freeN(temp);
- }
-
- v= obr->strandnodes[a].strand;
-
- if (v==NULL) {
- int i;
-
- v= (StrandRen *)MEM_callocN(256*sizeof(StrandRen), "findOrAddStrand");
- obr->strandnodes[a].strand= v;
-
- for (i= (nr & 0xFFFFFF00), a=0; a<256; a++, i++)
- v[a].index= i;
- }
- v+= (nr & 255);
- return v;
-}
-
-StrandBuffer *RE_addStrandBuffer(ObjectRen *obr, int totvert)
-{
- StrandBuffer *strandbuf;
-
- strandbuf= MEM_callocN(sizeof(StrandBuffer), "StrandBuffer");
- strandbuf->vert= MEM_callocN(sizeof(StrandVert)*totvert, "StrandVert");
- strandbuf->totvert= totvert;
- strandbuf->obr= obr;
-
- obr->strandbuf= strandbuf;
-
- return strandbuf;
-}
-
-/* ------------------------------------------------------------------------ */
-
-ObjectRen *RE_addRenderObject(Render *re, Object *ob, Object *par, int index, int psysindex, int lay)
-{
- ObjectRen *obr= MEM_callocN(sizeof(ObjectRen), "object render struct");
-
- BLI_addtail(&re->objecttable, obr);
- obr->ob= ob;
- obr->par= par;
- obr->index= index;
- obr->psysindex= psysindex;
- obr->lay= lay;
-
- return obr;
-}
-
-void free_renderdata_vertnodes(VertTableNode *vertnodes)
-{
- int a;
-
- if (vertnodes==NULL) return;
-
- for (a=0; vertnodes[a].vert; a++) {
- MEM_freeN(vertnodes[a].vert);
-
- if (vertnodes[a].rad)
- MEM_freeN(vertnodes[a].rad);
- if (vertnodes[a].strand)
- MEM_freeN(vertnodes[a].strand);
- if (vertnodes[a].tangent)
- MEM_freeN(vertnodes[a].tangent);
- if (vertnodes[a].stress)
- MEM_freeN(vertnodes[a].stress);
- if (vertnodes[a].winspeed)
- MEM_freeN(vertnodes[a].winspeed);
- if (vertnodes[a].origindex)
- MEM_freeN(vertnodes[a].origindex);
- }
-
- MEM_freeN(vertnodes);
-}
-
-void free_renderdata_vlaknodes(VlakTableNode *vlaknodes)
-{
- int a;
-
- if (vlaknodes==NULL) return;
-
- for (a=0; vlaknodes[a].vlak; a++) {
- MEM_freeN(vlaknodes[a].vlak);
-
- if (vlaknodes[a].mtface)
- MEM_freeN(vlaknodes[a].mtface);
- if (vlaknodes[a].mcol)
- MEM_freeN(vlaknodes[a].mcol);
- if (vlaknodes[a].origindex)
- MEM_freeN(vlaknodes[a].origindex);
- if (vlaknodes[a].surfnor)
- MEM_freeN(vlaknodes[a].surfnor);
- for (int b = 0; b < MAX_MTFACE; b++) {
- if (vlaknodes[a].tangent_arrays[b])
- MEM_freeN(vlaknodes[a].tangent_arrays[b]);
- }
- if (vlaknodes[a].radface)
- MEM_freeN(vlaknodes[a].radface);
- }
-
- MEM_freeN(vlaknodes);
-}
-
-static void free_renderdata_strandnodes(StrandTableNode *strandnodes)
-{
- int a;
-
- if (strandnodes==NULL) return;
-
- for (a=0; strandnodes[a].strand; a++) {
- MEM_freeN(strandnodes[a].strand);
-
- if (strandnodes[a].uv)
- MEM_freeN(strandnodes[a].uv);
- if (strandnodes[a].mcol)
- MEM_freeN(strandnodes[a].mcol);
- if (strandnodes[a].winspeed)
- MEM_freeN(strandnodes[a].winspeed);
- if (strandnodes[a].surfnor)
- MEM_freeN(strandnodes[a].surfnor);
- if (strandnodes[a].simplify)
- MEM_freeN(strandnodes[a].simplify);
- if (strandnodes[a].face)
- MEM_freeN(strandnodes[a].face);
- }
-
- MEM_freeN(strandnodes);
-}
-
-void free_renderdata_tables(Render *re)
-{
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- StrandBuffer *strandbuf;
- int a=0;
-
- for (obr=re->objecttable.first; obr; obr=obr->next) {
- if (obr->vertnodes) {
- free_renderdata_vertnodes(obr->vertnodes);
- obr->vertnodes= NULL;
- obr->vertnodeslen= 0;
- }
-
- if (obr->vlaknodes) {
- free_renderdata_vlaknodes(obr->vlaknodes);
- obr->vlaknodes= NULL;
- obr->vlaknodeslen= 0;
- obr->totvlak= 0;
- }
-
- if (obr->bloha) {
- for (a=0; obr->bloha[a]; a++)
- MEM_freeN(obr->bloha[a]);
-
- MEM_freeN(obr->bloha);
- obr->bloha= NULL;
- obr->blohalen= 0;
- }
-
- if (obr->strandnodes) {
- free_renderdata_strandnodes(obr->strandnodes);
- obr->strandnodes= NULL;
- obr->strandnodeslen= 0;
- }
-
- strandbuf= obr->strandbuf;
- if (strandbuf) {
- if (strandbuf->vert) MEM_freeN(strandbuf->vert);
- if (strandbuf->bound) MEM_freeN(strandbuf->bound);
- MEM_freeN(strandbuf);
- }
-
- if (obr->mtface)
- MEM_freeN(obr->mtface);
-
- if (obr->mcol)
- MEM_freeN(obr->mcol);
-
- if (obr->rayfaces) {
- MEM_freeN(obr->rayfaces);
- obr->rayfaces = NULL;
- }
-
- if (obr->rayprimitives) {
- MEM_freeN(obr->rayprimitives);
- obr->rayprimitives = NULL;
- }
-
- if (obr->raytree) {
- RE_rayobject_free(obr->raytree);
- obr->raytree = NULL;
- }
- }
-
- if (re->objectinstance) {
- for (obi=re->instancetable.first; obi; obi=obi->next) {
- if (obi->vectors)
- MEM_freeN(obi->vectors);
-
- if (obi->raytree)
- RE_rayobject_free(obi->raytree);
- }
-
- MEM_freeN(re->objectinstance);
- re->objectinstance= NULL;
- re->totinstance= 0;
- re->instancetable.first= re->instancetable.last= NULL;
- }
-
- if (re->sortedhalos) {
- MEM_freeN(re->sortedhalos);
- re->sortedhalos= NULL;
- }
-
- BLI_freelistN(&re->customdata_names);
- BLI_freelistN(&re->objecttable);
- BLI_freelistN(&re->instancetable);
-}
-
-/* ------------------------------------------------------------------------ */
-
-HaloRen *RE_findOrAddHalo(ObjectRen *obr, int nr)
-{
- HaloRen *h, **temp;
- int a;
-
- if (nr<0) {
- printf("error in findOrAddHalo: %d\n", nr);
- return NULL;
- }
- a= nr>>8;
-
- if (a>=obr->blohalen-1) { /* Need to allocate more columns..., and keep last element NULL for free loop */
- //printf("Allocating %i more halo groups. %i total.\n",
- // TABLEINITSIZE, obr->blohalen+TABLEINITSIZE );
- temp=obr->bloha;
-
- obr->bloha = (HaloRen **)MEM_callocN(sizeof(void *) * (obr->blohalen + TABLEINITSIZE), "Bloha");
- if (temp) memcpy(obr->bloha, temp, obr->blohalen*sizeof(void *));
- memset(&(obr->bloha[obr->blohalen]), 0, TABLEINITSIZE * sizeof(void *));
- obr->blohalen+=TABLEINITSIZE; /*Does this really need to be power of 2?*/
- if (temp) MEM_freeN(temp);
- }
-
- h= obr->bloha[a];
- if (h==NULL) {
- h= (HaloRen *)MEM_callocN(256*sizeof(HaloRen), "findOrAdHalo");
- obr->bloha[a]= h;
- }
- h+= (nr & 255);
- return h;
-}
-
-/* ------------------------------------------------------------------------- */
-
-HaloRen *RE_inithalo(Render *re, ObjectRen *obr, Material *ma,
- const float vec[3], const float vec1[3],
- const float *orco, float hasize, float vectsize, int seed)
-{
- const bool skip_load_image = (re->r.scemode & R_NO_IMAGE_LOAD) != 0;
- const bool texnode_preview = (re->r.scemode & R_TEXNODE_PREVIEW) != 0;
- HaloRen *har;
- MTex *mtex;
- float tin, tr, tg, tb, ta;
- float xn, yn, zn, texvec[3], hoco[4], hoco1[4];
-
- if (hasize==0.0f) return NULL;
-
- projectverto(vec, re->winmat, hoco);
- if (hoco[3]==0.0f) return NULL;
- if (vec1) {
- projectverto(vec1, re->winmat, hoco1);
- if (hoco1[3]==0.0f) return NULL;
- }
-
- har= RE_findOrAddHalo(obr, obr->tothalo++);
- copy_v3_v3(har->co, vec);
- har->hasize= hasize;
-
- /* actual projectvert is done in function project_renderdata() because of parts/border/pano */
- /* we do it here for sorting of halos */
- zn= hoco[3];
- har->xs= 0.5f*re->winx*(hoco[0]/zn);
- har->ys= 0.5f*re->winy*(hoco[1]/zn);
- har->zs= 0x7FFFFF*(hoco[2]/zn);
-
- har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn);
-
- /* halovect */
- if (vec1) {
-
- har->type |= HA_VECT;
-
- xn= har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]);
- yn= har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]);
- if (yn == 0.0f && xn >= 0.0f) zn = 0.0f;
- else zn = atan2f(yn, xn);
-
- har->sin = sinf(zn);
- har->cos = cosf(zn);
- zn= len_v3v3(vec1, vec);
-
- har->hasize= vectsize*zn + (1.0f-vectsize)*hasize;
-
- sub_v3_v3v3(har->no, vec, vec1);
- normalize_v3(har->no);
- }
-
- if (ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA;
-
- har->alfa= ma->alpha;
- har->r= ma->r;
- har->g= ma->g;
- har->b= ma->b;
- har->add= (255.0f*ma->add);
- har->mat= ma;
- har->hard= ma->har;
- har->seed= seed % 256;
-
- if (ma->mode & MA_STAR) har->starpoints= ma->starc;
- if (ma->mode & MA_HALO_LINES) har->linec= ma->linec;
- if (ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc;
- if (ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec;
-
-
- if (ma->mtex[0]) {
-
- if (ma->mode & MA_HALOTEX) {
- har->tex = 1;
- }
- else if (har->mat->septex & (1 << 0)) {
- /* only 1 level textures */
- }
- else {
- mtex= ma->mtex[0];
- copy_v3_v3(texvec, vec);
-
- if (mtex->texco & TEXCO_NORM) {
- ;
- }
- else if (mtex->texco & TEXCO_OBJECT) {
- /* texvec[0]+= imatbase->ivec[0]; */
- /* texvec[1]+= imatbase->ivec[1]; */
- /* texvec[2]+= imatbase->ivec[2]; */
- /* mul_m3_v3(imatbase->imat, texvec); */
- }
- else {
- if (orco) {
- copy_v3_v3(texvec, orco);
- }
- }
-
- externtex(mtex,
- texvec,
- &tin, &tr, &tg, &tb, &ta,
- 0,
- re->pool,
- skip_load_image,
- texnode_preview);
-
- yn= tin*mtex->colfac;
- //zn= tin*mtex->alphafac;
-
- if (mtex->mapto & MAP_COL) {
- zn= 1.0f-yn;
- har->r= (yn*tr+ zn*ma->r);
- har->g= (yn*tg+ zn*ma->g);
- har->b= (yn*tb+ zn*ma->b);
- }
- if (mtex->texco & TEXCO_UV) {
- har->alfa= tin;
- }
- if (mtex->mapto & MAP_ALPHA)
- har->alfa= tin;
- }
- }
-
- har->pool = re->pool;
- har->skip_load_image = skip_load_image;
- har->texnode_preview = texnode_preview;
-
- return har;
-}
-
-HaloRen *RE_inithalo_particle(Render *re, ObjectRen *obr, DerivedMesh *dm, Material *ma,
- const float vec[3], const float vec1[3],
- const float *orco, const float *uvco, float hasize, float vectsize, int seed, const float pa_co[3])
-{
- const bool skip_load_image = (re->r.scemode & R_NO_IMAGE_LOAD) != 0;
- const bool texnode_preview = (re->r.scemode & R_TEXNODE_PREVIEW) != 0;
- HaloRen *har;
- MTex *mtex;
- float tin, tr, tg, tb, ta;
- float xn, yn, zn, texvec[3], hoco[4], hoco1[4], in[3], tex[3], out[3];
- int i, hasrgb;
-
- if (hasize==0.0f) return NULL;
-
- projectverto(vec, re->winmat, hoco);
- if (hoco[3]==0.0f) return NULL;
- if (vec1) {
- projectverto(vec1, re->winmat, hoco1);
- if (hoco1[3]==0.0f) return NULL;
- }
-
- har= RE_findOrAddHalo(obr, obr->tothalo++);
- copy_v3_v3(har->co, vec);
- har->hasize= hasize;
-
- /* actual projectvert is done in function project_renderdata() because of parts/border/pano */
- /* we do it here for sorting of halos */
- zn= hoco[3];
- har->xs= 0.5f*re->winx*(hoco[0]/zn);
- har->ys= 0.5f*re->winy*(hoco[1]/zn);
- har->zs= 0x7FFFFF*(hoco[2]/zn);
-
- har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn);
-
- /* halovect */
- if (vec1) {
-
- har->type |= HA_VECT;
-
- xn= har->xs - 0.5f*re->winx*(hoco1[0]/hoco1[3]);
- yn= har->ys - 0.5f*re->winy*(hoco1[1]/hoco1[3]);
- if (yn == 0.0f && xn >= 0.0f) zn = 0.0f;
- else zn = atan2f(yn, xn);
-
- har->sin = sinf(zn);
- har->cos = cosf(zn);
- zn= len_v3v3(vec1, vec)*0.5f;
-
- har->hasize= vectsize*zn + (1.0f-vectsize)*hasize;
-
- sub_v3_v3v3(har->no, vec, vec1);
- normalize_v3(har->no);
- }
-
- if (ma->mode & MA_HALO_XALPHA) har->type |= HA_XALPHA;
-
- har->alfa= ma->alpha;
- har->r= ma->r;
- har->g= ma->g;
- har->b= ma->b;
- har->add= (255.0f*ma->add);
- har->mat= ma;
- har->hard= ma->har;
- har->seed= seed % 256;
-
- if (ma->mode & MA_STAR) har->starpoints= ma->starc;
- if (ma->mode & MA_HALO_LINES) har->linec= ma->linec;
- if (ma->mode & MA_HALO_RINGS) har->ringc= ma->ringc;
- if (ma->mode & MA_HALO_FLARE) har->flarec= ma->flarec;
-
- if ((ma->mode & MA_HALOTEX) && ma->mtex[0])
- har->tex= 1;
-
- for (i=0; i<MAX_MTEX; i++)
- if (ma->mtex[i] && (ma->septex & (1<<i))==0) {
- mtex= ma->mtex[i];
- copy_v3_v3(texvec, vec);
-
- if (mtex->texco & TEXCO_NORM) {
- ;
- }
- else if (mtex->texco & TEXCO_OBJECT) {
- if (mtex->object)
- mul_m4_v3(mtex->object->imat_ren, texvec);
- }
- else if (mtex->texco & TEXCO_GLOB) {
- copy_v3_v3(texvec, vec);
- }
- else if (mtex->texco & TEXCO_UV && uvco) {
- int uv_index=CustomData_get_named_layer_index(&dm->faceData, CD_MTFACE, mtex->uvname);
- if (uv_index<0)
- uv_index=CustomData_get_active_layer_index(&dm->faceData, CD_MTFACE);
-
- uv_index-=CustomData_get_layer_index(&dm->faceData, CD_MTFACE);
-
- texvec[0]=2.0f*uvco[2*uv_index]-1.0f;
- texvec[1]=2.0f*uvco[2*uv_index+1]-1.0f;
- texvec[2]=0.0f;
- }
- else if (mtex->texco & TEXCO_PARTICLE) {
- /* particle coordinates in range [0, 1] */
- texvec[0] = 2.f * pa_co[0] - 1.f;
- texvec[1] = 2.f * pa_co[1] - 1.f;
- texvec[2] = pa_co[2];
- }
- else if (orco) {
- copy_v3_v3(texvec, orco);
- }
-
- hasrgb = externtex(mtex,
- texvec,
- &tin, &tr, &tg, &tb, &ta,
- 0,
- re->pool,
- skip_load_image,
- texnode_preview);
-
- //yn= tin*mtex->colfac;
- //zn= tin*mtex->alphafac;
- if (mtex->mapto & MAP_COL) {
- tex[0]=tr;
- tex[1]=tg;
- tex[2]=tb;
- out[0]=har->r;
- out[1]=har->g;
- out[2]=har->b;
-
- texture_rgb_blend(in, tex, out, tin, mtex->colfac, mtex->blendtype);
- // zn= 1.0-yn;
- //har->r= (yn*tr+ zn*ma->r);
- //har->g= (yn*tg+ zn*ma->g);
- //har->b= (yn*tb+ zn*ma->b);
- har->r= in[0];
- har->g= in[1];
- har->b= in[2];
- }
-
- /* alpha returned, so let's use it instead of intensity */
- if (hasrgb)
- tin = ta;
-
- if (mtex->mapto & MAP_ALPHA)
- har->alfa = texture_value_blend(mtex->def_var, har->alfa, tin, mtex->alphafac, mtex->blendtype);
- if (mtex->mapto & MAP_HAR)
- har->hard = 1.0f+126.0f*texture_value_blend(mtex->def_var, ((float)har->hard)/127.0f, tin, mtex->hardfac, mtex->blendtype);
- if (mtex->mapto & MAP_RAYMIRR)
- har->hasize = 100.0f*texture_value_blend(mtex->def_var, har->hasize/100.0f, tin, mtex->raymirrfac, mtex->blendtype);
- if (mtex->mapto & MAP_TRANSLU) {
- float add = texture_value_blend(mtex->def_var, (float)har->add/255.0f, tin, mtex->translfac, mtex->blendtype);
- CLAMP(add, 0.f, 1.f);
- har->add = 255.0f*add;
- }
- /* now what on earth is this good for?? */
- //if (mtex->texco & 16) {
- // har->alfa= tin;
- //}
- }
-
- har->pool = re->pool;
- har->skip_load_image = (re->r.scemode & R_NO_IMAGE_LOAD) != 0;
- har->texnode_preview = (re->r.scemode & R_TEXNODE_PREVIEW) != 0;
-
- return har;
-}
-
-/* -------------------------- operations on entire database ----------------------- */
-
-/* ugly function for halos in panorama */
-static int panotestclip(Render *re, bool do_pano, float v[4])
-{
- /* part size (ensure we run RE_parts_clamp first) */
- BLI_assert(re->partx == min_ii(re->r.tilex, re->rectx));
- BLI_assert(re->party == min_ii(re->r.tiley, re->recty));
-
- if (do_pano == false) {
- return testclip(v);
- }
- else {
- /* to be used for halos en infos */
- float abs4;
- short c = 0;
-
- int xparts = (re->rectx + re->partx - 1) / re->partx;
-
- abs4= fabsf(v[3]);
-
- if (v[2]< -abs4) c=16; /* this used to be " if (v[2]<0) ", see clippz() */
- else if (v[2]> abs4) c+= 32;
-
- if ( v[1]>abs4) c+=4;
- else if ( v[1]< -abs4) c+=8;
-
- abs4*= xparts;
- if ( v[0]>abs4) c+=2;
- else if ( v[0]< -abs4) c+=1;
-
- return c;
- }
-}
-
-/**
- * This adds the hcs coordinates to vertices. It iterates over all
- * vertices, halos and faces. After the conversion, we clip in hcs.
- *
- * Elsewhere, all primites are converted to vertices.
- * Called in
- * - envmapping (envmap.c)
- * - shadow buffering (shadbuf.c)
- */
-
-void project_renderdata(Render *re,
- void (*projectfunc)(const float *, float mat[4][4], float *),
- bool do_pano, float xoffs, bool UNUSED(do_buckets))
-{
- ObjectRen *obr;
- HaloRen *har = NULL;
- float zn, vec[3], hoco[4];
- int a;
-
- if (do_pano) {
- float panophi= xoffs;
-
- re->panosi = sinf(panophi);
- re->panoco = cosf(panophi);
- }
-
- for (obr=re->objecttable.first; obr; obr=obr->next) {
- /* calculate view coordinates (and zbuffer value) */
- for (a=0; a<obr->tothalo; a++) {
- if ((a & 255)==0) har= obr->bloha[a>>8];
- else har++;
-
- if (do_pano) {
- vec[0]= re->panoco*har->co[0] + re->panosi*har->co[2];
- vec[1]= har->co[1];
- vec[2]= -re->panosi*har->co[0] + re->panoco*har->co[2];
- }
- else {
- copy_v3_v3(vec, har->co);
- }
-
- projectfunc(vec, re->winmat, hoco);
-
- /* we clip halos less critical, but not for the Z */
- hoco[0]*= 0.5f;
- hoco[1]*= 0.5f;
-
- if ( panotestclip(re, do_pano, hoco) ) {
- har->miny= har->maxy= -10000; /* that way render clips it */
- }
- else if (hoco[3]<0.0f) {
- har->miny= har->maxy= -10000; /* render clips it */
- }
- else { /* do the projection...*/
- /* bring back hocos */
- hoco[0]*= 2.0f;
- hoco[1]*= 2.0f;
-
- zn= hoco[3];
- har->xs= 0.5f*re->winx*(1.0f+hoco[0]/zn); /* the 0.5 negates the previous 2...*/
- har->ys= 0.5f*re->winy*(1.0f+hoco[1]/zn);
-
- /* this should be the zbuffer coordinate */
- har->zs= 0x7FFFFF*(hoco[2]/zn);
- /* taking this from the face clip functions? seems ok... */
- har->zBufDist = 0x7FFFFFFF*(hoco[2]/zn);
-
- vec[0]+= har->hasize;
- projectfunc(vec, re->winmat, hoco);
- vec[0]-= har->hasize;
- zn= hoco[3];
- har->rad= fabsf(har->xs- 0.5f*re->winx*(1.0f+hoco[0]/zn));
-
- /* this clip is not really OK, to prevent stars to become too large */
- if (har->type & HA_ONLYSKY) {
- if (har->rad>3.0f) har->rad= 3.0f;
- }
-
- har->radsq= har->rad*har->rad;
-
- har->miny= har->ys - har->rad/re->ycor;
- har->maxy= har->ys + har->rad/re->ycor;
-
- /* the Zd value is still not really correct for pano */
-
- vec[2] -= har->hasize; /* z negative, otherwise it's clipped */
- projectfunc(vec, re->winmat, hoco);
- zn = hoco[3];
- zn = fabsf((float)har->zs - 0x7FFFFF * (hoco[2] / zn));
- har->zd = CLAMPIS(zn, 0, INT_MAX);
-
- }
-
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-
-void RE_updateRenderInstance(Render *re, ObjectInstanceRen *obi, int flag)
-{
- /* flag specifies what things have changed. */
- if (flag & RE_OBJECT_INSTANCES_UPDATE_OBMAT) {
- copy_m4_m4(obi->obmat, obi->ob->obmat);
- invert_m4_m4(obi->obinvmat, obi->obmat);
- }
- if (flag & RE_OBJECT_INSTANCES_UPDATE_VIEW) {
- mul_m4_m4m4(obi->localtoviewmat, re->viewmat, obi->obmat);
- mul_m4_m4m4(obi->localtoviewinvmat, obi->obinvmat, re->viewinv);
- }
-}
-
-void RE_updateRenderInstances(Render *re, int flag)
-{
- int i = 0;
- for (i = 0; i < re->totinstance; i++)
- RE_updateRenderInstance(re, &re->objectinstance[i], flag);
-}
-
-ObjectInstanceRen *RE_addRenderInstance(
- Render *re, ObjectRen *obr, Object *ob, Object *par,
- int index, int psysindex, float mat[4][4], int lay, const DupliObject *dob)
-{
- ObjectInstanceRen *obi;
- float mat3[3][3];
-
- obi= MEM_callocN(sizeof(ObjectInstanceRen), "ObjectInstanceRen");
- obi->obr= obr;
- obi->ob= ob;
- obi->par= par;
- obi->index= index;
- obi->psysindex= psysindex;
- obi->lay= lay;
-
- /* Fill particle info */
- if (par && dob) {
- const ParticleSystem *psys = dob->particle_system;
- if (psys) {
- int part_index;
- if (obi->index < psys->totpart) {
- part_index = obi->index;
- }
- else if (psys->child) {
- part_index = psys->child[obi->index - psys->totpart].parent;
- }
- else {
- part_index = -1;
- }
-
- if (part_index >= 0) {
- const ParticleData *p = &psys->particles[part_index];
- obi->part_index = part_index;
- obi->part_size = p->size;
- obi->part_age = RE_GetStats(re)->cfra - p->time;
- obi->part_lifetime = p->lifetime;
-
- copy_v3_v3(obi->part_co, p->state.co);
- copy_v3_v3(obi->part_vel, p->state.vel);
- copy_v3_v3(obi->part_avel, p->state.ave);
- }
- }
- }
-
- /* Fill object info */
- if (dob) {
- obi->random_id = dob->random_id;
- }
- else {
- obi->random_id = BLI_hash_int_2d(BLI_hash_string(obi->ob->id.name + 2), 0);
- }
-
- RE_updateRenderInstance(re, obi, RE_OBJECT_INSTANCES_UPDATE_OBMAT | RE_OBJECT_INSTANCES_UPDATE_VIEW);
-
- if (mat) {
- copy_m4_m4(obi->mat, mat);
- copy_m3_m4(mat3, mat);
- invert_m3_m3(obi->nmat, mat3);
- transpose_m3(obi->nmat);
- obi->flag |= R_DUPLI_TRANSFORMED;
- }
-
- BLI_addtail(&re->instancetable, obi);
-
- return obi;
-}
-
-void RE_instance_get_particle_info(struct ObjectInstanceRen *obi, float *index, float *random, float *age, float *lifetime, float co[3], float *size, float vel[3], float angvel[3])
-{
- *index = obi->part_index;
- *random = BLI_hash_int_01(obi->part_index);
- *age = obi->part_age;
- *lifetime = obi->part_lifetime;
- copy_v3_v3(co, obi->part_co);
- *size = obi->part_size;
- copy_v3_v3(vel, obi->part_vel);
- copy_v3_v3(angvel, obi->part_avel);
-}
-
-
-void RE_makeRenderInstances(Render *re)
-{
- ObjectInstanceRen *obi, *oldobi;
- ListBase newlist;
- int tot;
-
- /* convert list of object instances to an array for index based lookup */
- tot= BLI_listbase_count(&re->instancetable);
- re->objectinstance= MEM_callocN(sizeof(ObjectInstanceRen)*tot, "ObjectInstance");
- re->totinstance= tot;
- newlist.first= newlist.last= NULL;
-
- obi= re->objectinstance;
- for (oldobi=re->instancetable.first; oldobi; oldobi=oldobi->next) {
- *obi= *oldobi;
-
- if (obi->obr) {
- obi->prev= obi->next= NULL;
- BLI_addtail(&newlist, obi);
- obi++;
- }
- else
- re->totinstance--;
- }
-
- BLI_freelistN(&re->instancetable);
- re->instancetable= newlist;
-}
-
-/* four functions to facilitate envmap rotation for raytrace */
-void RE_instance_rotate_ray_start(ObjectInstanceRen *obi, Isect *is)
-{
- if (obi && (obi->flag & R_ENV_TRANSFORMED)) {
- copy_v3_v3(is->origstart, is->start);
- mul_m4_v3(obi->imat, is->start);
- }
-}
-
-void RE_instance_rotate_ray_dir(ObjectInstanceRen *obi, Isect *is)
-{
- if (obi && (obi->flag & R_ENV_TRANSFORMED)) {
- float end[3];
-
- copy_v3_v3(is->origdir, is->dir);
- add_v3_v3v3(end, is->origstart, is->dir);
-
- mul_m4_v3(obi->imat, end);
- sub_v3_v3v3(is->dir, end, is->start);
- }
-}
-
-void RE_instance_rotate_ray(ObjectInstanceRen *obi, Isect *is)
-{
- RE_instance_rotate_ray_start(obi, is);
- RE_instance_rotate_ray_dir(obi, is);
-}
-
-void RE_instance_rotate_ray_restore(ObjectInstanceRen *obi, Isect *is)
-{
- if (obi && (obi->flag & R_ENV_TRANSFORMED)) {
- copy_v3_v3(is->start, is->origstart);
- copy_v3_v3(is->dir, is->origdir);
- }
-}
-
-int clip_render_object(float boundbox[2][3], float bounds[4], float winmat[4][4])
-{
- float mat[4][4], vec[4];
- int a, fl, flag = -1;
-
- copy_m4_m4(mat, winmat);
-
- for (a=0; a < 8; a++) {
- vec[0]= (a & 1)? boundbox[0][0]: boundbox[1][0];
- vec[1]= (a & 2)? boundbox[0][1]: boundbox[1][1];
- vec[2]= (a & 4)? boundbox[0][2]: boundbox[1][2];
- vec[3]= 1.0;
- mul_m4_v4(mat, vec);
-
- fl = 0;
- if (bounds) {
- if (vec[0] < bounds[0] * vec[3]) fl |= 1;
- else if (vec[0] > bounds[1] * vec[3]) fl |= 2;
-
- if (vec[1] > bounds[3] * vec[3]) fl |= 4;
- else if (vec[1] < bounds[2] * vec[3]) fl |= 8;
- }
- else {
- if (vec[0] < -vec[3]) fl |= 1;
- else if (vec[0] > vec[3]) fl |= 2;
-
- if (vec[1] > vec[3]) fl |= 4;
- else if (vec[1] < -vec[3]) fl |= 8;
- }
- if (vec[2] < -vec[3]) fl |= 16;
- else if (vec[2] > vec[3]) fl |= 32;
-
- flag &= fl;
- if (flag == 0) {
- return 0;
- }
- }
-
- return flag;
-}
-
diff --git a/source/blender/render/intern/source/shadbuf.c b/source/blender/render/intern/source/shadbuf.c
deleted file mode 100644
index fb441662829..00000000000
--- a/source/blender/render/intern/source/shadbuf.c
+++ /dev/null
@@ -1,2647 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributor(s): 2004-2006, Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/shadbuf.c
- * \ingroup render
- */
-
-
-#include <math.h>
-#include <string.h>
-
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_group_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_material_types.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_jitter_2d.h"
-#include "BLI_memarena.h"
-#include "BLI_rand.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_global.h"
-#include "BKE_scene.h"
-
-#include "PIL_time.h"
-
-#include "render_types.h"
-#include "renderdatabase.h"
-#include "rendercore.h"
-#include "shadbuf.h"
-#include "shading.h"
-#include "zbuf.h"
-
-/* XXX, could be better implemented... this is for endian issues */
-#ifdef __BIG_ENDIAN__
-//# define RCOMP 3
-# define GCOMP 2
-# define BCOMP 1
-# define ACOMP 0
-#else
-//# define RCOMP 0
-# define GCOMP 1
-# define BCOMP 2
-# define ACOMP 3
-#endif
-
-#define RCT_SIZE_X(rct) ((rct)->xmax - (rct)->xmin)
-#define RCT_SIZE_Y(rct) ((rct)->ymax - (rct)->ymin)
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-/* ------------------------------------------------------------------------- */
-
-/* initshadowbuf() in convertBlenderScene.c */
-
-/* ------------------------------------------------------------------------- */
-
-static void copy_to_ztile(int *rectz, int size, int x1, int y1, int tile, char *r1)
-{
- int len4, *rz;
- int x2, y2;
-
- x2= x1+tile;
- y2= y1+tile;
- if (x2>=size) x2= size-1;
- if (y2>=size) y2= size-1;
-
- if (x1>=x2 || y1>=y2) return;
-
- len4= 4*(x2- x1);
- rz= rectz + size*y1 + x1;
- for (; y1<y2; y1++) {
- memcpy(r1, rz, len4);
- rz+= size;
- r1+= len4;
- }
-}
-
-#if 0
-static int sizeoflampbuf(ShadBuf *shb)
-{
- int num, count=0;
- char *cp;
-
- cp= shb->cbuf;
- num= (shb->size*shb->size)/256;
-
- while (num--) count+= *(cp++);
-
- return 256*count;
-}
-#endif
-
-/* not threadsafe... */
-static float *give_jitter_tab(int samp)
-{
- /* these are all possible jitter tables, takes up some
- * 12k, not really bad!
- * For soft shadows, it saves memory and render time
- */
- static int tab[17]={1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256};
- static float jit[1496][2];
- static char ctab[17]= {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
- int a, offset=0;
-
- if (samp<2) samp= 2;
- else if (samp>16) samp= 16;
-
- for (a=0; a<samp-1; a++) offset+= tab[a];
-
- if (ctab[samp]==0) {
- ctab[samp]= 1;
- BLI_jitter_init((float (*)[2])jit[offset], samp*samp);
- }
-
- return jit[offset];
-
-}
-
-static void make_jitter_weight_tab(Render *re, ShadBuf *shb, short filtertype)
-{
- float *jit, totw= 0.0f;
- int samp= get_render_shadow_samples(&re->r, shb->samp);
- int a, tot=samp*samp;
-
- shb->weight= MEM_mallocN(sizeof(float)*tot, "weight tab lamp");
-
- for (jit= shb->jit, a=0; a<tot; a++, jit+=2) {
- if (filtertype==LA_SHADBUF_TENT)
- shb->weight[a] = 0.71f - sqrtf(jit[0] * jit[0] + jit[1] * jit[1]);
- else if (filtertype==LA_SHADBUF_GAUSS)
- shb->weight[a] = RE_filter_value(R_FILTER_GAUSS, 1.8f * sqrtf(jit[0] * jit[0] + jit[1] * jit[1]));
- else
- shb->weight[a]= 1.0f;
-
- totw+= shb->weight[a];
- }
-
- totw= 1.0f/totw;
- for (a=0; a<tot; a++) {
- shb->weight[a]*= totw;
- }
-}
-
-static int verg_deepsample(const void *poin1, const void *poin2)
-{
- const DeepSample *ds1= (const DeepSample*)poin1;
- const DeepSample *ds2= (const DeepSample*)poin2;
-
- if (ds1->z < ds2->z) return -1;
- else if (ds1->z == ds2->z) return 0;
- else return 1;
-}
-
-static int compress_deepsamples(DeepSample *dsample, int tot, float epsilon)
-{
- /* uses doubles to avoid overflows and other numerical issues,
- * could be improved */
- DeepSample *ds, *newds;
- float v;
- double slope, slopemin, slopemax, min, max, div, newmin, newmax;
- int a, first, z, newtot= 0;
-
-#if 0
- if (print) {
- for (a=0, ds=dsample; a<tot; a++, ds++)
- printf("%lf, %f ", ds->z/(double)0x7FFFFFFF, ds->v);
- printf("\n");
- }
-#endif
-
- /* read from and write into same array */
- ds= dsample;
- newds= dsample;
- a= 0;
-
- /* as long as we are not at the end of the array */
- for (a++, ds++; a<tot; a++, ds++) {
- slopemin= 0.0f;
- slopemax= 0.0f;
- first= 1;
-
- for (; a<tot; a++, ds++) {
- //dz= ds->z - newds->z;
- if (ds->z == newds->z) {
- /* still in same z position, simply check
- * visibility difference against epsilon */
- if (!(fabsf(newds->v - ds->v) <= epsilon)) {
- break;
- }
- }
- else {
- /* compute slopes */
- div= (double)0x7FFFFFFF / ((double)ds->z - (double)newds->z);
- min= (double)((ds->v - epsilon) - newds->v) * div;
- max= (double)((ds->v + epsilon) - newds->v) * div;
-
- /* adapt existing slopes */
- if (first) {
- newmin= min;
- newmax= max;
- first= 0;
- }
- else {
- newmin= MAX2(slopemin, min);
- newmax= MIN2(slopemax, max);
-
- /* verify if there is still space between the slopes */
- if (newmin > newmax) {
- ds--;
- a--;
- break;
- }
- }
-
- slopemin= newmin;
- slopemax= newmax;
- }
- }
-
- if (a == tot) {
- ds--;
- a--;
- }
-
- /* always previous z */
- z= ds->z;
-
- if (first || a==tot-1) {
- /* if slopes were not initialized, use last visibility */
- v= ds->v;
- }
- else {
- /* compute visibility at center between slopes at z */
- slope = (slopemin + slopemax) * 0.5;
- v = (double)newds->v + slope * ((double)(z - newds->z) / (double)0x7FFFFFFF);
- }
-
- newds++;
- newtot++;
-
- newds->z= z;
- newds->v= v;
- }
-
- if (newtot == 0 || (newds->v != (newds-1)->v))
- newtot++;
-
-#if 0
- if (print) {
- for (a=0, ds=dsample; a<newtot; a++, ds++)
- printf("%lf, %f ", ds->z/(double)0x7FFFFFFF, ds->v);
- printf("\n");
- }
-#endif
-
- return newtot;
-}
-
-static float deep_alpha(Render *re, int obinr, int facenr, bool use_strand)
-{
- ObjectInstanceRen *obi= &re->objectinstance[obinr];
- Material *ma;
-
- if (use_strand) {
- StrandRen *strand= RE_findOrAddStrand(obi->obr, facenr-1);
- ma= strand->buffer->ma;
- }
- else {
- VlakRen *vlr= RE_findOrAddVlak(obi->obr, (facenr-1) & RE_QUAD_MASK);
- ma= vlr->mat;
- }
-
- return ma->shad_alpha;
-}
-
-static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, APixstrand *apixbufstrand)
-{
- ShadSampleBuf *shsample;
- DeepSample *ds[RE_MAX_OSA], *sampleds[RE_MAX_OSA], *dsb, *newbuf;
- APixstr *ap, *apn;
- APixstrand *aps, *apns;
- float visibility;
-
- const int totbuf= shb->totbuf;
- const float totbuf_f= (float)shb->totbuf;
- const float totbuf_f_inv= 1.0f/totbuf_f;
- const int size= shb->size;
-
- int a, b, c, tot, minz, found, prevtot, newtot;
- int sampletot[RE_MAX_OSA], totsample = 0, totsamplec = 0;
-
- shsample= MEM_callocN(sizeof(ShadSampleBuf), "shad sample buf");
- BLI_addtail(&shb->buffers, shsample);
-
- shsample->totbuf = MEM_callocN(sizeof(int) * size * size, "deeptotbuf");
- shsample->deepbuf = MEM_callocN(sizeof(DeepSample *) * size * size, "deepbuf");
-
- ap= apixbuf;
- aps= apixbufstrand;
- for (a=0; a<size*size; a++, ap++, aps++) {
- /* count number of samples */
- for (c=0; c<totbuf; c++)
- sampletot[c]= 0;
-
- tot= 0;
- for (apn=ap; apn; apn=apn->next)
- for (b=0; b<4; b++)
- if (apn->p[b])
- for (c=0; c<totbuf; c++)
- if (apn->mask[b] & (1<<c))
- sampletot[c]++;
-
- if (apixbufstrand) {
- for (apns=aps; apns; apns=apns->next)
- for (b=0; b<4; b++)
- if (apns->p[b])
- for (c=0; c<totbuf; c++)
- if (apns->mask[b] & (1<<c))
- sampletot[c]++;
- }
-
- for (c=0; c<totbuf; c++)
- tot += sampletot[c];
-
- if (tot == 0) {
- shsample->deepbuf[a]= NULL;
- shsample->totbuf[a]= 0;
- continue;
- }
-
- /* fill samples */
- ds[0]= sampleds[0]= MEM_callocN(sizeof(DeepSample)*tot*2, "deepsample");
- for (c=1; c<totbuf; c++)
- ds[c]= sampleds[c]= sampleds[c-1] + sampletot[c-1]*2;
-
- for (apn=ap; apn; apn=apn->next) {
- for (b=0; b<4; b++) {
- if (apn->p[b]) {
- for (c=0; c<totbuf; c++) {
- if (apn->mask[b] & (1<<c)) {
- /* two entries to create step profile */
- ds[c]->z= apn->z[b];
- ds[c]->v= 1.0f; /* not used */
- ds[c]++;
- ds[c]->z= apn->z[b];
- ds[c]->v= deep_alpha(re, apn->obi[b], apn->p[b], 0);
- ds[c]++;
- }
- }
- }
- }
- }
-
- if (apixbufstrand) {
- for (apns=aps; apns; apns=apns->next) {
- for (b=0; b<4; b++) {
- if (apns->p[b]) {
- for (c=0; c<totbuf; c++) {
- if (apns->mask[b] & (1<<c)) {
- /* two entries to create step profile */
- ds[c]->z= apns->z[b];
- ds[c]->v= 1.0f; /* not used */
- ds[c]++;
- ds[c]->z= apns->z[b];
- ds[c]->v= deep_alpha(re, apns->obi[b], apns->p[b], 1);
- ds[c]++;
- }
- }
- }
- }
- }
- }
-
- for (c=0; c<totbuf; c++) {
- /* sort by increasing z */
- qsort(sampleds[c], sampletot[c], sizeof(DeepSample)*2, verg_deepsample);
-
- /* sum visibility, replacing alpha values */
- visibility= 1.0f;
- ds[c]= sampleds[c];
-
- for (b=0; b<sampletot[c]; b++) {
- /* two entries creating step profile */
- ds[c]->v= visibility;
- ds[c]++;
-
- visibility *= 1.0f-ds[c]->v;
- ds[c]->v= visibility;
- ds[c]++;
- }
-
- /* halfway trick, probably won't work well for volumes? */
- ds[c]= sampleds[c];
- for (b=0; b<sampletot[c]; b++) {
- if (b+1 < sampletot[c]) {
- ds[c]->z= (ds[c]->z>>1) + ((ds[c]+2)->z>>1);
- ds[c]++;
- ds[c]->z= (ds[c]->z>>1) + ((ds[c]+2)->z>>1);
- ds[c]++;
- }
- else {
- ds[c]->z= (ds[c]->z>>1) + (0x7FFFFFFF>>1);
- ds[c]++;
- ds[c]->z= (ds[c]->z>>1) + (0x7FFFFFFF>>1);
- ds[c]++;
- }
- }
-
- /* init for merge loop */
- ds[c]= sampleds[c];
- sampletot[c] *= 2;
- }
-
- shsample->deepbuf[a]= MEM_callocN(sizeof(DeepSample)*tot*2, "deepsample");
- shsample->totbuf[a]= 0;
-
- /* merge buffers */
- dsb= shsample->deepbuf[a];
- while (1) {
- minz= 0;
- found= 0;
-
- for (c=0; c<totbuf; c++) {
- if (sampletot[c] && (!found || ds[c]->z < minz)) {
- minz= ds[c]->z;
- found= 1;
- }
- }
-
- if (!found)
- break;
-
- dsb->z= minz;
- dsb->v= 0.0f;
-
- visibility= 0.0f;
- for (c=0; c<totbuf; c++) {
- if (sampletot[c] && ds[c]->z == minz) {
- ds[c]++;
- sampletot[c]--;
- }
-
- if (sampleds[c] == ds[c])
- visibility += totbuf_f_inv;
- else
- visibility += (ds[c]-1)->v / totbuf_f;
- }
-
- dsb->v= visibility;
- dsb++;
- shsample->totbuf[a]++;
- }
-
- prevtot= shsample->totbuf[a];
- totsample += prevtot;
-
- newtot= compress_deepsamples(shsample->deepbuf[a], prevtot, shb->compressthresh);
- shsample->totbuf[a]= newtot;
- totsamplec += newtot;
-
- if (newtot < prevtot) {
- newbuf= MEM_mallocN(sizeof(DeepSample)*newtot, "cdeepsample");
- memcpy(newbuf, shsample->deepbuf[a], sizeof(DeepSample)*newtot);
- MEM_freeN(shsample->deepbuf[a]);
- shsample->deepbuf[a]= newbuf;
- }
-
- MEM_freeN(sampleds[0]);
- }
-
- //printf("%d -> %d, ratio %f\n", totsample, totsamplec, (float)totsamplec/(float)totsample);
-}
-
-/* create Z tiles (for compression): this system is 24 bits!!! */
-static void compress_shadowbuf(ShadBuf *shb, int *rectz, int square)
-{
- ShadSampleBuf *shsample;
- float dist;
- uintptr_t *ztile;
- int *rz, *rz1, verg, verg1, size= shb->size;
- int a, x, y, minx, miny, byt1, byt2;
- char *rc, *rcline, *ctile, *zt;
-
- shsample= MEM_callocN(sizeof(ShadSampleBuf), "shad sample buf");
- BLI_addtail(&shb->buffers, shsample);
-
- shsample->zbuf= MEM_mallocN(sizeof(uintptr_t)*(size*size)/256, "initshadbuf2");
- shsample->cbuf= MEM_callocN((size*size)/256, "initshadbuf3");
-
- ztile= (uintptr_t *)shsample->zbuf;
- ctile= shsample->cbuf;
-
- /* help buffer */
- rcline= MEM_mallocN(256*4+sizeof(int), "makeshadbuf2");
-
- for (y=0; y<size; y+=16) {
- if (y< size/2) miny= y+15-size/2;
- else miny= y-size/2;
-
- for (x=0; x<size; x+=16) {
-
- /* is tile within spotbundle? */
- a= size/2;
- if (x< a) minx= x+15-a;
- else minx= x-a;
-
- dist = sqrtf((float)(minx * minx + miny * miny));
-
- if (square==0 && dist>(float)(a+12)) { /* 12, tested with a onlyshadow lamp */
- a= 256; verg= 0; /* 0x80000000; */ /* 0x7FFFFFFF; */
- rz1= (&verg)+1;
- }
- else {
- copy_to_ztile(rectz, size, x, y, 16, rcline);
- rz1= (int *)rcline;
-
- verg= (*rz1 & 0xFFFFFF00);
-
- for (a=0;a<256;a++, rz1++) {
- if ( (*rz1 & 0xFFFFFF00) !=verg) break;
- }
- }
- if (a==256) { /* complete empty tile */
- *ctile= 0;
- *ztile= *(rz1-1);
- }
- else {
-
- /* ACOMP etc. are defined to work L/B endian */
-
- rc= rcline;
- rz1= (int *)rcline;
- verg= rc[ACOMP];
- verg1= rc[BCOMP];
- rc+= 4;
- byt1= 1; byt2= 1;
- for (a=1;a<256;a++, rc+=4) {
- byt1 &= (verg==rc[ACOMP]);
- byt2 &= (verg1==rc[BCOMP]);
-
- if (byt1==0) break;
- }
- if (byt1 && byt2) { /* only store byte */
- *ctile= 1;
- *ztile= (uintptr_t)MEM_mallocN(256+4, "tile1");
- rz= (int *)*ztile;
- *rz= *rz1;
-
- zt= (char *)(rz+1);
- rc= rcline;
- for (a=0; a<256; a++, zt++, rc+=4) *zt= rc[GCOMP];
- }
- else if (byt1) { /* only store short */
- *ctile= 2;
- *ztile= (uintptr_t)MEM_mallocN(2*256+4, "Tile2");
- rz= (int *)*ztile;
- *rz= *rz1;
-
- zt= (char *)(rz+1);
- rc= rcline;
- for (a=0; a<256; a++, zt+=2, rc+=4) {
- zt[0]= rc[BCOMP];
- zt[1]= rc[GCOMP];
- }
- }
- else { /* store triple */
- *ctile= 3;
- *ztile= (uintptr_t)MEM_mallocN(3*256, "Tile3");
-
- zt= (char *)*ztile;
- rc= rcline;
- for (a=0; a<256; a++, zt+=3, rc+=4) {
- zt[0]= rc[ACOMP];
- zt[1]= rc[BCOMP];
- zt[2]= rc[GCOMP];
- }
- }
- }
- ztile++;
- ctile++;
- }
- }
-
- MEM_freeN(rcline);
-}
-
-/* sets start/end clipping. lar->shb should be initialized */
-static void shadowbuf_autoclip(Render *re, LampRen *lar)
-{
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- VlakRen *vlr= NULL;
- VertRen *ver= NULL;
- Material *ma= NULL;
- float minz, maxz, vec[3], viewmat[4][4], obviewmat[4][4];
- unsigned int lay = -1;
- int i, a, maxtotvert, ok= 1;
- char *clipflag;
-
- minz= 1.0e30f; maxz= -1.0e30f;
- copy_m4_m4(viewmat, lar->shb->viewmat);
-
- if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay;
-
- maxtotvert= 0;
- for (obr=re->objecttable.first; obr; obr=obr->next)
- maxtotvert = max_ii(obr->totvert, maxtotvert);
-
- clipflag= MEM_callocN(sizeof(char)*maxtotvert, "autoclipflag");
-
- /* set clip in vertices when face visible */
- for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
- obr= obi->obr;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(obviewmat, viewmat, obi->mat);
- else
- copy_m4_m4(obviewmat, viewmat);
-
- memset(clipflag, 0, sizeof(char)*obr->totvert);
-
- /* clear clip, is being set if face is visible (clip is calculated for real later) */
- for (a=0; a<obr->totvlak; a++) {
- if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
- else vlr++;
-
- /* note; these conditions are copied from zbuffer_shadow() */
- if (vlr->mat!= ma) {
- ma= vlr->mat;
- ok= 1;
- if ((ma->mode2 & MA_CASTSHADOW)==0 || (ma->mode & MA_SHADBUF)==0) ok= 0;
- }
-
- if (ok && (obi->lay & lay)) {
- clipflag[vlr->v1->index]= 1;
- clipflag[vlr->v2->index]= 1;
- clipflag[vlr->v3->index]= 1;
- if (vlr->v4) clipflag[vlr->v4->index]= 1;
- }
- }
-
- /* calculate min and max */
- for (a=0; a< obr->totvert;a++) {
- if ((a & 255)==0) ver= RE_findOrAddVert(obr, a);
- else ver++;
-
- if (clipflag[a]) {
- copy_v3_v3(vec, ver->co);
- mul_m4_v3(obviewmat, vec);
- /* Z on visible side of lamp space */
- if (vec[2] < 0.0f) {
- float inpr, z= -vec[2];
-
- /* since vec is rotated in lampspace, this is how to get the cosine of angle */
- /* precision is set 20% larger */
- vec[2]*= 1.2f;
- normalize_v3(vec);
- inpr= - vec[2];
-
- if (inpr>=lar->spotsi) {
- if (z<minz) minz= z;
- if (z>maxz) maxz= z;
- }
- }
- }
- }
- }
-
- MEM_freeN(clipflag);
-
- /* set clipping min and max */
- if (minz < maxz) {
- float delta= (maxz - minz); /* threshold to prevent precision issues */
-
- //printf("minz %f maxz %f delta %f\n", minz, maxz, delta);
- if (lar->bufflag & LA_SHADBUF_AUTO_START)
- lar->shb->d= minz - delta*0.02f; /* 0.02 is arbitrary... needs more thinking! */
- if (lar->bufflag & LA_SHADBUF_AUTO_END)
- lar->shb->clipend= maxz + delta*0.1f;
-
- /* bias was calculated as percentage, we scale it to prevent animation issues */
- delta= (lar->clipend-lar->clipsta)/(lar->shb->clipend-lar->shb->d);
- //printf("bias delta %f\n", delta);
- lar->shb->bias= (int) (delta*(float)lar->shb->bias);
- }
-}
-
-static void makeflatshadowbuf(Render *re, LampRen *lar, float *jitbuf)
-{
- ShadBuf *shb= lar->shb;
- int *rectz, samples;
-
- /* zbuffering */
- rectz= MEM_mapallocN(sizeof(int)*shb->size*shb->size, "makeshadbuf");
-
- for (samples=0; samples<shb->totbuf; samples++) {
- zbuffer_shadow(re, shb->persmat, lar, rectz, shb->size, jitbuf[2*samples], jitbuf[2*samples+1]);
- /* create Z tiles (for compression): this system is 24 bits!!! */
- compress_shadowbuf(shb, rectz, lar->mode & LA_SQUARE);
-
- if (re->test_break(re->tbh))
- break;
- }
-
- MEM_freeN(rectz);
-}
-
-static void makedeepshadowbuf(Render *re, LampRen *lar, float *jitbuf)
-{
- ShadBuf *shb= lar->shb;
- APixstr *apixbuf;
- APixstrand *apixbufstrand= NULL;
- ListBase apsmbase= {NULL, NULL};
-
- /* zbuffering */
- apixbuf= MEM_callocN(sizeof(APixstr)*shb->size*shb->size, "APixbuf");
- if (re->totstrand)
- apixbufstrand= MEM_callocN(sizeof(APixstrand)*shb->size*shb->size, "APixbufstrand");
-
- zbuffer_abuf_shadow(re, lar, shb->persmat, apixbuf, apixbufstrand, &apsmbase, shb->size,
- shb->totbuf, (float(*)[2])jitbuf);
-
- /* create Z tiles (for compression): this system is 24 bits!!! */
- compress_deepshadowbuf(re, shb, apixbuf, apixbufstrand);
-
- MEM_freeN(apixbuf);
- if (apixbufstrand)
- MEM_freeN(apixbufstrand);
- freepsA(&apsmbase);
-}
-
-void makeshadowbuf(Render *re, LampRen *lar)
-{
- ShadBuf *shb= lar->shb;
- float wsize, *jitbuf, twozero[2]= {0.0f, 0.0f}, angle, temp;
-
- if (lar->bufflag & (LA_SHADBUF_AUTO_START|LA_SHADBUF_AUTO_END))
- shadowbuf_autoclip(re, lar);
-
- /* just to enforce identical behavior of all irregular buffers */
- if (lar->buftype==LA_SHADBUF_IRREGULAR)
- shb->size= 1024;
-
- /* matrices and window: in winmat the transformation is being put,
- * transforming from observer view to lamp view, including lamp window matrix */
-
- angle= saacos(lar->spotsi);
- temp = 0.5f * shb->size * cosf(angle) / sinf(angle);
- shb->pixsize= (shb->d)/temp;
- wsize= shb->pixsize*(shb->size/2.0f);
-
- perspective_m4(shb->winmat, -wsize, wsize, -wsize, wsize, shb->d, shb->clipend);
- mul_m4_m4m4(shb->persmat, shb->winmat, shb->viewmat);
-
- if (ELEM(lar->buftype, LA_SHADBUF_REGULAR, LA_SHADBUF_HALFWAY, LA_SHADBUF_DEEP)) {
- shb->totbuf= lar->buffers;
-
- /* jitter, weights - not threadsafe! */
- BLI_thread_lock(LOCK_CUSTOM1);
- shb->jit= give_jitter_tab(get_render_shadow_samples(&re->r, shb->samp));
- make_jitter_weight_tab(re, shb, lar->filtertype);
- BLI_thread_unlock(LOCK_CUSTOM1);
-
- if (shb->totbuf==4) jitbuf= give_jitter_tab(2);
- else if (shb->totbuf==9) jitbuf= give_jitter_tab(3);
- else jitbuf= twozero;
-
- /* zbuffering */
- if (lar->buftype == LA_SHADBUF_DEEP) {
- makedeepshadowbuf(re, lar, jitbuf);
- shb->totbuf= 1;
- }
- else
- makeflatshadowbuf(re, lar, jitbuf);
-
- /* printf("lampbuf %d\n", sizeoflampbuf(shb)); */
- }
-}
-
-static void *do_shadow_thread(void *re_v)
-{
- Render *re = (Render *)re_v;
- LampRen *lar;
-
- do {
- BLI_thread_lock(LOCK_CUSTOM1);
- for (lar=re->lampren.first; lar; lar=lar->next) {
- if (lar->shb && !lar->thread_assigned) {
- lar->thread_assigned= 1;
- break;
- }
- }
- BLI_thread_unlock(LOCK_CUSTOM1);
-
- /* if type is irregular, this only sets the perspective matrix and autoclips */
- if (lar) {
- makeshadowbuf(re, lar);
- BLI_thread_lock(LOCK_CUSTOM1);
- lar->thread_ready= 1;
- BLI_thread_unlock(LOCK_CUSTOM1);
- }
- } while (lar && !re->test_break(re->tbh));
-
- return NULL;
-}
-
-static volatile int g_break= 0;
-static int thread_break(void *UNUSED(arg))
-{
- return g_break;
-}
-
-void threaded_makeshadowbufs(Render *re)
-{
- ListBase threads;
- LampRen *lar;
- int a, totthread= 0;
- int (*test_break)(void *);
-
- /* count number of threads to use */
- if (G.is_rendering) {
- for (lar=re->lampren.first; lar; lar= lar->next)
- if (lar->shb)
- totthread++;
-
- totthread = min_ii(totthread, re->r.threads);
- }
- else
- totthread = 1; /* preview render */
-
- if (totthread <= 1) {
- for (lar=re->lampren.first; lar; lar= lar->next) {
- if (re->test_break(re->tbh)) break;
- if (lar->shb) {
- /* if type is irregular, this only sets the perspective matrix and autoclips */
- makeshadowbuf(re, lar);
- }
- }
- }
- else {
- /* swap test break function */
- test_break= re->test_break;
- re->test_break= thread_break;
-
- for (lar=re->lampren.first; lar; lar= lar->next) {
- lar->thread_assigned= 0;
- lar->thread_ready= 0;
- }
-
- BLI_threadpool_init(&threads, do_shadow_thread, totthread);
-
- for (a=0; a<totthread; a++)
- BLI_threadpool_insert(&threads, re);
-
- /* keep rendering as long as there are shadow buffers not ready */
- do {
- if ((g_break=test_break(re->tbh)))
- break;
-
- PIL_sleep_ms(50);
-
- BLI_thread_lock(LOCK_CUSTOM1);
- for (lar=re->lampren.first; lar; lar= lar->next)
- if (lar->shb && !lar->thread_ready)
- break;
- BLI_thread_unlock(LOCK_CUSTOM1);
- } while (lar);
-
- BLI_threadpool_end(&threads);
-
- /* unset threadsafety */
- re->test_break= test_break;
- g_break= 0;
- }
-}
-
-void freeshadowbuf(LampRen *lar)
-{
- if (lar->shb) {
- ShadBuf *shb= lar->shb;
- ShadSampleBuf *shsample;
- int b, v;
-
- for (shsample= shb->buffers.first; shsample; shsample= shsample->next) {
- if (shsample->deepbuf) {
- v= shb->size*shb->size;
- for (b=0; b<v; b++)
- if (shsample->deepbuf[b])
- MEM_freeN(shsample->deepbuf[b]);
-
- MEM_freeN(shsample->deepbuf);
- MEM_freeN(shsample->totbuf);
- }
- else {
- intptr_t *ztile= shsample->zbuf;
- const char *ctile= shsample->cbuf;
-
- v= (shb->size*shb->size)/256;
- for (b=0; b<v; b++, ztile++, ctile++)
- if (*ctile) MEM_freeN((void *) *ztile);
-
- MEM_freeN(shsample->zbuf);
- MEM_freeN(shsample->cbuf);
- }
- }
- BLI_freelistN(&shb->buffers);
-
- if (shb->weight) MEM_freeN(shb->weight);
- MEM_freeN(lar->shb);
-
- lar->shb= NULL;
- }
-}
-
-
-static int firstreadshadbuf(ShadBuf *shb, ShadSampleBuf *shsample, int **rz, int xs, int ys, int nr)
-{
- /* return a 1 if fully compressed shadbuf-tile && z==const */
- int ofs;
- const char *ct;
-
- if (shsample->deepbuf)
- return 0;
-
- /* always test borders of shadowbuffer */
- if (xs<0) xs= 0; else if (xs>=shb->size) xs= shb->size-1;
- if (ys<0) ys= 0; else if (ys>=shb->size) ys= shb->size-1;
-
- /* calc z */
- ofs= (ys>>4)*(shb->size>>4) + (xs>>4);
- ct= shsample->cbuf+ofs;
- if (*ct==0) {
- if (nr==0) {
- *rz= *( (int **)(shsample->zbuf+ofs) );
- return 1;
- }
- else if (*rz!= *( (int **)(shsample->zbuf+ofs) )) return 0;
-
- return 1;
- }
-
- return 0;
-}
-
-static float readdeepvisibility(DeepSample *dsample, int tot, int z, int bias, float *biast)
-{
- DeepSample *ds, *prevds;
- float t;
- int a;
-
- /* tricky stuff here; we use ints which can overflow easily with bias values */
-
- ds= dsample;
- for (a=0; a<tot && (z-bias > ds->z); a++, ds++) {}
-
- if (a == tot) {
- if (biast)
- *biast= 0.0f;
- return (ds-1)->v; /* completely behind all samples */
- }
-
- /* check if this read needs bias blending */
- if (biast) {
- if (z > ds->z)
- *biast= (float)(z - ds->z)/(float)bias;
- else
- *biast= 0.0f;
- }
-
- if (a == 0)
- return 1.0f; /* completely in front of all samples */
-
- /* converting to float early here because ds->z - prevds->z can overflow */
- prevds= ds-1;
- t= ((float)(z-bias) - (float)prevds->z)/((float)ds->z - (float)prevds->z);
- return t*ds->v + (1.0f-t)*prevds->v;
-}
-
-static float readdeepshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int xs, int ys, int zs)
-{
- float v, biasv, biast;
- int ofs, tot;
-
- if (zs < - 0x7FFFFE00 + bias)
- return 1.0; /* extreme close to clipstart */
-
- /* calc z */
- ofs= ys*shb->size + xs;
- tot= shsample->totbuf[ofs];
- if (tot == 0)
- return 1.0f;
-
- v= readdeepvisibility(shsample->deepbuf[ofs], tot, zs, bias, &biast);
-
- if (biast != 0.0f) {
- /* in soft bias area */
- biasv = readdeepvisibility(shsample->deepbuf[ofs], tot, zs, 0, NULL);
-
- biast= biast*biast;
- return (1.0f-biast)*v + biast*biasv;
- }
-
- return v;
-}
-
-/* return 1.0 : fully in light */
-static float readshadowbuf(ShadBuf *shb, ShadSampleBuf *shsample, int bias, int xs, int ys, int zs)
-{
- float temp;
- int *rz, ofs;
- int zsamp=0;
- char *ct, *cz;
-
- /* simpleclip */
- /* if (xs<0 || ys<0) return 1.0; */
- /* if (xs>=shb->size || ys>=shb->size) return 1.0; */
-
- /* always test borders of shadowbuffer */
- if (xs<0) xs= 0; else if (xs>=shb->size) xs= shb->size-1;
- if (ys<0) ys= 0; else if (ys>=shb->size) ys= shb->size-1;
-
- if (shsample->deepbuf)
- return readdeepshadowbuf(shb, shsample, bias, xs, ys, zs);
-
- /* calc z */
- ofs= (ys>>4)*(shb->size>>4) + (xs>>4);
- ct= shsample->cbuf+ofs;
- rz= *( (int **)(shsample->zbuf+ofs) );
-
- if (*ct==3) {
- ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15);
- cz= (char *)&zsamp;
- cz[ACOMP]= ct[0];
- cz[BCOMP]= ct[1];
- cz[GCOMP]= ct[2];
- }
- else if (*ct==2) {
- ct= ((char *)rz);
- ct+= 4+2*16*(ys & 15)+2*(xs & 15);
- zsamp= *rz;
-
- cz= (char *)&zsamp;
- cz[BCOMP]= ct[0];
- cz[GCOMP]= ct[1];
- }
- else if (*ct==1) {
- ct= ((char *)rz);
- ct+= 4+16*(ys & 15)+(xs & 15);
- zsamp= *rz;
-
- cz= (char *)&zsamp;
- cz[GCOMP]= ct[0];
-
- }
- else {
- /* got warning on this for 64 bits.... */
- /* but it's working code! in this case rz is not a pointer but zvalue (ton) */
- zsamp= GET_INT_FROM_POINTER(rz);
- }
-
- /* tricky stuff here; we use ints which can overflow easily with bias values */
-
- if (zsamp > zs) return 1.0; /* absolute no shadow */
- else if (zs < - 0x7FFFFE00 + bias) return 1.0; /* extreme close to clipstart */
- else if (zsamp < zs-bias) return 0.0; /* absolute in shadow */
- else { /* soft area */
-
- temp= ( (float)(zs- zsamp) )/(float)bias;
- return 1.0f - temp*temp;
-
- }
-}
-
-static void shadowbuf_project_co(float *x, float *y, float *z, ShadBuf *shb, const float co[3])
-{
- float hco[4], size= 0.5f*(float)shb->size;
-
- copy_v3_v3(hco, co);
- hco[3]= 1.0f;
-
- mul_m4_v4(shb->persmat, hco);
-
- *x= size*(1.0f+hco[0]/hco[3]);
- *y= size*(1.0f+hco[1]/hco[3]);
- if (z) *z= (hco[2]/hco[3]);
-}
-
-/* the externally called shadow testing (reading) function */
-/* return 1.0: no shadow at all */
-float testshadowbuf(Render *re, ShadBuf *shb, const float co[3], const float dxco[3], const float dyco[3], float inp, float mat_bias)
-{
- ShadSampleBuf *shsample;
- float fac, dco[3], dx[3], dy[3], shadfac=0.0f;
- float xs1, ys1, zs1, *jit, *weight, xres, yres, biasf;
- int xs, ys, zs, bias, *rz;
- short a, num;
-
- /* crash preventer */
- if (shb->buffers.first==NULL)
- return 1.0f;
-
- /* when facing away, assume fully in shadow */
- if (inp <= 0.0f)
- return 0.0f;
-
- /* project coordinate to pixel space */
- shadowbuf_project_co(&xs1, &ys1, &zs1, shb, co);
-
- /* clip z coordinate, z is projected so that (-1.0, 1.0) matches
- * (clipstart, clipend), so we can do this simple test */
- if (zs1>=1.0f)
- return 0.0f;
- else if (zs1<= -1.0f)
- return 1.0f;
-
- zs= ((float)0x7FFFFFFF)*zs1;
-
- /* take num*num samples, increase area with fac */
- num= get_render_shadow_samples(&re->r, shb->samp);
- num= num*num;
- fac= shb->soft;
-
- /* compute z bias */
- if (mat_bias!=0.0f) biasf= shb->bias*mat_bias;
- else biasf= shb->bias;
- /* with inp==1.0, bias is half the size. correction value was 1.1, giving errors
- * on cube edges, with one side being almost frontal lighted (ton) */
- bias= (1.5f-inp*inp)*biasf;
-
- /* in case of no filtering we can do things simpler */
- if (num==1) {
- for (shsample= shb->buffers.first; shsample; shsample= shsample->next)
- shadfac += readshadowbuf(shb, shsample, bias, (int)xs1, (int)ys1, zs);
-
- return shadfac/(float)shb->totbuf;
- }
-
- /* calculate filter size */
- add_v3_v3v3(dco, co, dxco);
- shadowbuf_project_co(&dx[0], &dx[1], NULL, shb, dco);
- dx[0]= xs1 - dx[0];
- dx[1]= ys1 - dx[1];
-
- add_v3_v3v3(dco, co, dyco);
- shadowbuf_project_co(&dy[0], &dy[1], NULL, shb, dco);
- dy[0]= xs1 - dy[0];
- dy[1]= ys1 - dy[1];
-
- xres = fac * (fabsf(dx[0]) + fabsf(dy[0]));
- yres = fac * (fabsf(dx[1]) + fabsf(dy[1]));
- if (xres<1.0f) xres= 1.0f;
- if (yres<1.0f) yres= 1.0f;
-
- /* make xs1/xs1 corner of sample area */
- xs1 -= xres*0.5f;
- ys1 -= yres*0.5f;
-
- /* in case we have a constant value in a tile, we can do quicker lookup */
- if (xres<16.0f && yres<16.0f) {
- shsample= shb->buffers.first;
- if (firstreadshadbuf(shb, shsample, &rz, (int)xs1, (int)ys1, 0)) {
- if (firstreadshadbuf(shb, shsample, &rz, (int)(xs1+xres), (int)ys1, 1)) {
- if (firstreadshadbuf(shb, shsample, &rz, (int)xs1, (int)(ys1+yres), 1)) {
- if (firstreadshadbuf(shb, shsample, &rz, (int)(xs1+xres), (int)(ys1+yres), 1)) {
- return readshadowbuf(shb, shsample, bias, (int)xs1, (int)ys1, zs);
- }
- }
- }
- }
- }
-
- /* full jittered shadow buffer lookup */
- for (shsample= shb->buffers.first; shsample; shsample= shsample->next) {
- jit= shb->jit;
- weight= shb->weight;
-
- for (a=num; a>0; a--, jit+=2, weight++) {
- /* instead of jit i tried random: ugly! */
- /* note: the plus 0.5 gives best sampling results, jit goes from -0.5 to 0.5 */
- /* xs1 and ys1 are already corrected to be corner of sample area */
- xs= xs1 + xres*(jit[0] + 0.5f);
- ys= ys1 + yres*(jit[1] + 0.5f);
-
- shadfac+= *weight * readshadowbuf(shb, shsample, bias, xs, ys, zs);
- }
- }
-
- /* Renormalizes for the sample number: */
- return shadfac/(float)shb->totbuf;
-}
-
-/* different function... sampling behind clipend can be LIGHT, bias is negative! */
-/* return: light */
-static float readshadowbuf_halo(ShadBuf *shb, ShadSampleBuf *shsample, int xs, int ys, int zs)
-{
- float temp;
- int *rz, ofs;
- int bias, zbias, zsamp;
- char *ct, *cz;
-
- /* negative! The other side is more important */
- bias= -shb->bias;
-
- /* simpleclip */
- if (xs<0 || ys<0) return 0.0;
- if (xs>=shb->size || ys>=shb->size) return 0.0;
-
- /* calc z */
- ofs= (ys>>4)*(shb->size>>4) + (xs>>4);
- ct= shsample->cbuf+ofs;
- rz= *( (int **)(shsample->zbuf+ofs) );
-
- if (*ct==3) {
- ct= ((char *)rz)+3*16*(ys & 15)+3*(xs & 15);
- cz= (char *)&zsamp;
- zsamp= 0;
- cz[ACOMP]= ct[0];
- cz[BCOMP]= ct[1];
- cz[GCOMP]= ct[2];
- }
- else if (*ct==2) {
- ct= ((char *)rz);
- ct+= 4+2*16*(ys & 15)+2*(xs & 15);
- zsamp= *rz;
-
- cz= (char *)&zsamp;
- cz[BCOMP]= ct[0];
- cz[GCOMP]= ct[1];
- }
- else if (*ct==1) {
- ct= ((char *)rz);
- ct+= 4+16*(ys & 15)+(xs & 15);
- zsamp= *rz;
-
- cz= (char *)&zsamp;
- cz[GCOMP]= ct[0];
-
- }
- else {
- /* same as before */
- /* still working code! (ton) */
- zsamp= GET_INT_FROM_POINTER(rz);
- }
-
- /* NO schadow when sampled at 'eternal' distance */
-
- if (zsamp >= 0x7FFFFE00) return 1.0;
-
- if (zsamp > zs) return 1.0; /* absolute no shadww */
- else {
- /* bias is negative, so the (zs-bias) can be beyond 0x7fffffff */
- zbias= 0x7fffffff - zs;
- if (zbias > -bias) {
- if ( zsamp < zs-bias) return 0.0; /* absolute in shadow */
- }
- else return 0.0; /* absolute shadow */
- }
-
- /* soft area */
-
- temp= ( (float)(zs- zsamp) )/(float)bias;
- return 1.0f - temp*temp;
-}
-
-
-float shadow_halo(LampRen *lar, const float p1[3], const float p2[3])
-{
- /* p1 p2 already are rotated in spot-space */
- ShadBuf *shb= lar->shb;
- ShadSampleBuf *shsample;
- float co[4], siz;
- float lambda, lambda_o, lambda_x, lambda_y, ldx, ldy;
- float zf, xf1, yf1, zf1, xf2, yf2, zf2;
- float count, lightcount;
- int x, y, z, xs1, ys1;
- int dx = 0, dy = 0;
-
- siz= 0.5f*(float)shb->size;
-
- co[0]= p1[0];
- co[1]= p1[1];
- co[2]= p1[2]/lar->sh_zfac;
- co[3]= 1.0;
- mul_m4_v4(shb->winmat, co); /* rational hom co */
- xf1= siz*(1.0f+co[0]/co[3]);
- yf1= siz*(1.0f+co[1]/co[3]);
- zf1= (co[2]/co[3]);
-
-
- co[0]= p2[0];
- co[1]= p2[1];
- co[2]= p2[2]/lar->sh_zfac;
- co[3]= 1.0;
- mul_m4_v4(shb->winmat, co); /* rational hom co */
- xf2= siz*(1.0f+co[0]/co[3]);
- yf2= siz*(1.0f+co[1]/co[3]);
- zf2= (co[2]/co[3]);
-
- /* the 2dda (a pixel line formula) */
-
- xs1= (int)xf1;
- ys1= (int)yf1;
-
- if (xf1 != xf2) {
- if (xf2-xf1 > 0.0f) {
- lambda_x= (xf1-xs1-1.0f)/(xf1-xf2);
- ldx= -shb->shadhalostep/(xf1-xf2);
- dx= shb->shadhalostep;
- }
- else {
- lambda_x= (xf1-xs1)/(xf1-xf2);
- ldx= shb->shadhalostep/(xf1-xf2);
- dx= -shb->shadhalostep;
- }
- }
- else {
- lambda_x= 1.0;
- ldx= 0.0;
- }
-
- if (yf1 != yf2) {
- if (yf2-yf1 > 0.0f) {
- lambda_y= (yf1-ys1-1.0f)/(yf1-yf2);
- ldy= -shb->shadhalostep/(yf1-yf2);
- dy= shb->shadhalostep;
- }
- else {
- lambda_y= (yf1-ys1)/(yf1-yf2);
- ldy= shb->shadhalostep/(yf1-yf2);
- dy= -shb->shadhalostep;
- }
- }
- else {
- lambda_y= 1.0;
- ldy= 0.0;
- }
-
- x= xs1;
- y= ys1;
- lambda= count= lightcount= 0.0;
-
-/* printf("start %x %x \n", (int)(0x7FFFFFFF*zf1), (int)(0x7FFFFFFF*zf2)); */
-
- do {
- lambda_o= lambda;
-
- if (lambda_x==lambda_y) {
- lambda_x+= ldx;
- x+= dx;
- lambda_y+= ldy;
- y+= dy;
- }
- else {
- if (lambda_x<lambda_y) {
- lambda_x+= ldx;
- x+= dx;
- }
- else {
- lambda_y+= ldy;
- y+= dy;
- }
- }
-
- lambda = min_ff(lambda_x, lambda_y);
-
- /* not making any progress? */
- if (lambda==lambda_o) break;
-
- /* clip to end of volume */
- lambda = min_ff(lambda, 1.0f);
-
- zf= zf1 + lambda*(zf2-zf1);
- count+= (float)shb->totbuf;
-
- if (zf<= -1.0f) lightcount += 1.0f; /* close to the spot */
- else {
-
- /* make sure, behind the clipend we extend halolines. */
- if (zf>=1.0f) z= 0x7FFFF000;
- else z= (int)(0x7FFFF000*zf);
-
- for (shsample= shb->buffers.first; shsample; shsample= shsample->next)
- lightcount+= readshadowbuf_halo(shb, shsample, x, y, z);
-
- }
- }
- while (lambda < 1.0f);
-
- if (count!=0.0f) return (lightcount/count);
- return 0.0f;
-
-}
-
-
-/* ********************* Irregular Shadow Buffer (ISB) ************* */
-/* ********** storage of all view samples in a raster of lists ***** */
-
-/* based on several articles describing this method, like:
- * The Irregular Z-Buffer and its Application to Shadow Mapping
- * Gregory S. Johnson - William R. Mark - Christopher A. Burns
- * and
- * Alias-Free Shadow Maps
- * Timo Aila and Samuli Laine
- */
-
-/* bsp structure (actually kd tree) */
-
-#define BSPMAX_SAMPLE 128
-#define BSPMAX_DEPTH 32
-
-/* aligned with struct rctf */
-typedef struct Boxf {
- float xmin, xmax;
- float ymin, ymax;
- float zmin, zmax;
-} Boxf;
-
-typedef struct ISBBranch {
- struct ISBBranch *left, *right;
- float divider[2];
- Boxf box;
- short totsamp, index, full, unused;
- ISBSample **samples;
-} ISBBranch;
-
-typedef struct BSPFace {
- Boxf box;
- const float *v1, *v2, *v3, *v4;
- int obi; /* object for face lookup */
- int facenr; /* index to retrieve VlakRen */
- int type; /* only for strand now */
- short shad_alpha, is_full;
-
- /* strand caching data, optimize for point_behind_strand() */
- float radline, radline_end, len;
- float vec1[3], vec2[3], rc[3];
-} BSPFace;
-
-/* boxes are in lamp projection */
-static void init_box(Boxf *box)
-{
- box->xmin = 1000000.0f;
- box->xmax = 0;
- box->ymin = 1000000.0f;
- box->ymax = 0;
- box->zmin= 0x7FFFFFFF;
- box->zmax= - 0x7FFFFFFF;
-}
-
-/* use v1 to calculate boundbox */
-static void bound_boxf(Boxf *box, const float v1[3])
-{
- if (v1[0] < box->xmin) box->xmin = v1[0];
- if (v1[0] > box->xmax) box->xmax = v1[0];
- if (v1[1] < box->ymin) box->ymin = v1[1];
- if (v1[1] > box->ymax) box->ymax = v1[1];
- if (v1[2] < box->zmin) box->zmin= v1[2];
- if (v1[2] > box->zmax) box->zmax= v1[2];
-}
-
-/* use v1 to calculate boundbox */
-static void bound_rectf(rctf *box, const float v1[2])
-{
- if (v1[0] < box->xmin) box->xmin = v1[0];
- if (v1[0] > box->xmax) box->xmax = v1[0];
- if (v1[1] < box->ymin) box->ymin = v1[1];
- if (v1[1] > box->ymax) box->ymax = v1[1];
-}
-
-
-/* halfway splitting, for initializing a more regular tree */
-static void isb_bsp_split_init(ISBBranch *root, MemArena *mem, int level)
-{
-
- /* if level > 0 we create new branches and go deeper */
- if (level > 0) {
- ISBBranch *left, *right;
- int i;
-
- /* splitpoint */
- root->divider[0]= 0.5f*(root->box.xmin+root->box.xmax);
- root->divider[1]= 0.5f*(root->box.ymin+root->box.ymax);
-
- /* find best splitpoint */
- if (RCT_SIZE_X(&root->box) > RCT_SIZE_Y(&root->box))
- i = root->index = 0;
- else
- i = root->index = 1;
-
- left= root->left= BLI_memarena_alloc(mem, sizeof(ISBBranch));
- right= root->right= BLI_memarena_alloc(mem, sizeof(ISBBranch));
-
- /* box info */
- left->box= root->box;
- right->box= root->box;
- if (i==0) {
- left->box.xmax = root->divider[0];
- right->box.xmin = root->divider[0];
- }
- else {
- left->box.ymax = root->divider[1];
- right->box.ymin = root->divider[1];
- }
- isb_bsp_split_init(left, mem, level-1);
- isb_bsp_split_init(right, mem, level-1);
- }
- else {
- /* we add sample array */
- root->samples= BLI_memarena_alloc(mem, BSPMAX_SAMPLE*sizeof(void *));
- }
-}
-
-/* note; if all samples on same location we just spread them over 2 new branches */
-static void isb_bsp_split(ISBBranch *root, MemArena *mem)
-{
- ISBBranch *left, *right;
- ISBSample *samples[BSPMAX_SAMPLE];
- int a, i;
-
- /* splitpoint */
- root->divider[0]= root->divider[1]= 0.0f;
- for (a=BSPMAX_SAMPLE-1; a>=0; a--) {
- root->divider[0]+= root->samples[a]->zco[0];
- root->divider[1]+= root->samples[a]->zco[1];
- }
- root->divider[0]/= BSPMAX_SAMPLE;
- root->divider[1]/= BSPMAX_SAMPLE;
-
- /* find best splitpoint */
- if (RCT_SIZE_X(&root->box) > RCT_SIZE_Y(&root->box))
- i = root->index = 0;
- else
- i = root->index = 1;
-
- /* new branches */
- left= root->left= BLI_memarena_alloc(mem, sizeof(ISBBranch));
- right= root->right= BLI_memarena_alloc(mem, sizeof(ISBBranch));
-
- /* new sample array */
- left->samples = BLI_memarena_alloc(mem, BSPMAX_SAMPLE*sizeof(void *));
- right->samples = samples; /* tmp */
-
- /* split samples */
- for (a=BSPMAX_SAMPLE-1; a>=0; a--) {
- int comp= 0;
- /* this prevents adding samples all to 1 branch when divider is equal to samples */
- if (root->samples[a]->zco[i] == root->divider[i])
- comp= a & 1;
- else if (root->samples[a]->zco[i] < root->divider[i])
- comp= 1;
-
- if (comp==1) {
- left->samples[left->totsamp]= root->samples[a];
- left->totsamp++;
- }
- else {
- right->samples[right->totsamp]= root->samples[a];
- right->totsamp++;
- }
- }
-
- /* copy samples from tmp */
- memcpy(root->samples, samples, right->totsamp*(sizeof(void *)));
- right->samples= root->samples;
- root->samples= NULL;
-
- /* box info */
- left->box= root->box;
- right->box= root->box;
- if (i==0) {
- left->box.xmax = root->divider[0];
- right->box.xmin = root->divider[0];
- }
- else {
- left->box.ymax = root->divider[1];
- right->box.ymin = root->divider[1];
- }
-}
-
-/* inserts sample in main tree, also splits on threshold */
-/* returns 1 if error */
-static int isb_bsp_insert(ISBBranch *root, MemArena *memarena, ISBSample *sample)
-{
- ISBBranch *bspn= root;
- const float *zco= sample->zco;
- int i= 0;
-
- /* debug counter, also used to check if something was filled in ever */
- root->totsamp++;
-
- /* going over branches until last one found */
- while (bspn->left) {
- if (zco[bspn->index] <= bspn->divider[bspn->index])
- bspn= bspn->left;
- else
- bspn= bspn->right;
- i++;
- }
- /* bspn now is the last branch */
-
- if (bspn->totsamp==BSPMAX_SAMPLE) {
- printf("error in bsp branch\n"); /* only for debug, cannot happen */
- return 1;
- }
-
- /* insert */
- bspn->samples[bspn->totsamp]= sample;
- bspn->totsamp++;
-
- /* split if allowed and needed */
- if (bspn->totsamp==BSPMAX_SAMPLE) {
- if (i==BSPMAX_DEPTH) {
- bspn->totsamp--; /* stop filling in... will give errors */
- return 1;
- }
- isb_bsp_split(bspn, memarena);
- }
- return 0;
-}
-
-/* initialize vars in face, for optimal point-in-face test */
-static void bspface_init_strand(BSPFace *face)
-{
-
- face->radline= 0.5f* len_v2v2(face->v1, face->v2);
-
- mid_v3_v3v3(face->vec1, face->v1, face->v2);
- if (face->v4)
- mid_v3_v3v3(face->vec2, face->v3, face->v4);
- else
- copy_v3_v3(face->vec2, face->v3);
-
- face->rc[0]= face->vec2[0]-face->vec1[0];
- face->rc[1]= face->vec2[1]-face->vec1[1];
- face->rc[2]= face->vec2[2]-face->vec1[2];
-
- face->len= face->rc[0]*face->rc[0]+ face->rc[1]*face->rc[1];
-
- if (face->len != 0.0f) {
- face->radline_end = face->radline / sqrtf(face->len);
- face->len = 1.0f / face->len;
- }
-}
-
-/* brought back to a simple 2d case */
-static int point_behind_strand(const float p[3], BSPFace *face)
-{
- /* v1 - v2 is radius, v1 - v3 length */
- float dist, rc[2], pt[2];
-
- /* using code from dist_to_line_segment_v2(), distance vec to line-piece */
-
- if (face->len==0.0f) {
- rc[0]= p[0]-face->vec1[0];
- rc[1]= p[1]-face->vec1[1];
- dist = len_v2(rc);
-
- if (dist < face->radline)
- return 1;
- }
- else {
- float lambda= ( face->rc[0]*(p[0]-face->vec1[0]) + face->rc[1]*(p[1]-face->vec1[1]) )*face->len;
-
- if (lambda > -face->radline_end && lambda < 1.0f+face->radline_end) {
- /* hesse for dist: */
- //dist= (float)(fabs( (p[0]-vec2[0])*rc[1] + (p[1]-vec2[1])*rc[0])/len);
-
- pt[0]= lambda*face->rc[0]+face->vec1[0];
- pt[1]= lambda*face->rc[1]+face->vec1[1];
-
- rc[0]= pt[0]-p[0];
- rc[1]= pt[1]-p[1];
- dist = len_v2(rc);
-
- if (dist < face->radline) {
- float zval= face->vec1[2] + lambda*face->rc[2];
- if (p[2] > zval)
- return 1;
- }
- }
- }
- return 0;
-}
-
-
-/* return 1 if inside. code derived from src/parametrizer.c */
-static int point_behind_tria2d(const float p[3], const float v1[3], const float v2[3], const float v3[3])
-{
- float a[2], c[2], h[2], div;
- float u, v;
-
- a[0] = v2[0] - v1[0];
- a[1] = v2[1] - v1[1];
- c[0] = v3[0] - v1[0];
- c[1] = v3[1] - v1[1];
-
- div = a[0]*c[1] - a[1]*c[0];
- if (div==0.0f)
- return 0;
-
- h[0] = p[0] - v1[0];
- h[1] = p[1] - v1[1];
-
- div = 1.0f/div;
-
- u = (h[0]*c[1] - h[1]*c[0])*div;
- if (u >= 0.0f) {
- v = (a[0]*h[1] - a[1]*h[0])*div;
- if (v >= 0.0f) {
- if ( u + v <= 1.0f) {
- /* inside, now check if point p is behind */
- float z= (1.0f-u-v)*v1[2] + u*v2[2] + v*v3[2];
- if (z <= p[2])
- return 1;
- }
- }
- }
-
- return 0;
-}
-
-#if 0
-/* tested these calls, but it gives inaccuracy, 'side' cannot be found reliably using v3 */
-
-/* check if line v1-v2 has all rect points on other side of point v3 */
-static int rect_outside_line(rctf *rect, const float v1[3], const float v2[3], const float v3[3])
-{
- float a, b, c;
- int side;
-
- /* line formula for v1-v2 */
- a= v2[1]-v1[1];
- b= v1[0]-v2[0];
- c= -a*v1[0] - b*v1[1];
- side= a*v3[0] + b*v3[1] + c < 0.0f;
-
- /* the four quad points */
- if ( side==(rect->xmin*a + rect->ymin*b + c >= 0.0f) )
- if ( side==(rect->xmax*a + rect->ymin*b + c >= 0.0f) )
- if ( side==(rect->xmax*a + rect->ymax*b + c >= 0.0f) )
- if ( side==(rect->xmin*a + rect->ymax*b + c >= 0.0f) )
- return 1;
- return 0;
-}
-
-/* check if one of the triangle edges separates all rect points on 1 side */
-static int rect_isect_tria(rctf *rect, const float v1[3], const float v2[3], const float v3[3])
-{
- if (rect_outside_line(rect, v1, v2, v3))
- return 0;
- if (rect_outside_line(rect, v2, v3, v1))
- return 0;
- if (rect_outside_line(rect, v3, v1, v2))
- return 0;
- return 1;
-}
-#endif
-
-/* if face overlaps a branch, it executes func. recursive */
-static void isb_bsp_face_inside(ISBBranch *bspn, BSPFace *face)
-{
-
- /* are we descending? */
- if (bspn->left) {
- /* hrmf, the box struct cannot be addressed with index */
- if (bspn->index==0) {
- if (face->box.xmin <= bspn->divider[0])
- isb_bsp_face_inside(bspn->left, face);
- if (face->box.xmax > bspn->divider[0])
- isb_bsp_face_inside(bspn->right, face);
- }
- else {
- if (face->box.ymin <= bspn->divider[1])
- isb_bsp_face_inside(bspn->left, face);
- if (face->box.ymax > bspn->divider[1])
- isb_bsp_face_inside(bspn->right, face);
- }
- }
- else {
- /* else: end branch reached */
- int a;
-
- if (bspn->totsamp==0) return;
-
- /* check for nodes entirely in shadow, can be skipped */
- if (bspn->totsamp==bspn->full)
- return;
-
- /* if bsp node is entirely in front of face, give up */
- if (bspn->box.zmax < face->box.zmin)
- return;
-
- /* if face boundbox is outside of branch rect, give up */
- if (0==BLI_rctf_isect((rctf *)&face->box, (rctf *)&bspn->box, NULL))
- return;
-
- /* test all points inside branch */
- for (a=bspn->totsamp-1; a>=0; a--) {
- ISBSample *samp= bspn->samples[a];
-
- if ((samp->facenr!=face->facenr || samp->obi!=face->obi) && samp->shadfac) {
- if (face->box.zmin < samp->zco[2]) {
- if (BLI_rctf_isect_pt_v((rctf *)&face->box, samp->zco)) {
- int inshadow= 0;
-
- if (face->type) {
- if (point_behind_strand(samp->zco, face))
- inshadow= 1;
- }
- else if ( point_behind_tria2d(samp->zco, face->v1, face->v2, face->v3))
- inshadow= 1;
- else if (face->v4 && point_behind_tria2d(samp->zco, face->v1, face->v3, face->v4))
- inshadow= 1;
-
- if (inshadow) {
- *(samp->shadfac) += face->shad_alpha;
- /* optimize; is_full means shad_alpha==4096 */
- if (*(samp->shadfac) >= 4096 || face->is_full) {
- bspn->full++;
- samp->shadfac= NULL;
- }
- }
- }
- }
- }
- }
- }
-}
-
-/* based on available samples, recalculate the bounding box for bsp nodes, recursive */
-static void isb_bsp_recalc_box(ISBBranch *root)
-{
- if (root->left) {
- isb_bsp_recalc_box(root->left);
- isb_bsp_recalc_box(root->right);
- }
- else if (root->totsamp) {
- int a;
-
- init_box(&root->box);
- for (a=root->totsamp-1; a>=0; a--)
- bound_boxf(&root->box, root->samples[a]->zco);
- }
-}
-
-/* callback function for zbuf clip */
-static void isb_bsp_test_strand(ZSpan *zspan, int obi, int zvlnr,
- const float *v1, const float *v2, const float *v3, const float *v4)
-{
- BSPFace face;
-
- face.v1= v1;
- face.v2= v2;
- face.v3= v3;
- face.v4= v4;
- face.obi= obi;
- face.facenr= zvlnr & ~RE_QUAD_OFFS;
- face.type= R_STRAND;
- if (R.osa)
- face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha/(float)R.osa);
- else
- face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha);
-
- face.is_full= (zspan->shad_alpha==1.0f);
-
- /* setup boundbox */
- init_box(&face.box);
- bound_boxf(&face.box, v1);
- bound_boxf(&face.box, v2);
- bound_boxf(&face.box, v3);
- if (v4)
- bound_boxf(&face.box, v4);
-
- /* optimize values */
- bspface_init_strand(&face);
-
- isb_bsp_face_inside((ISBBranch *)zspan->rectz, &face);
-
-}
-
-/* callback function for zbuf clip */
-static void isb_bsp_test_face(ZSpan *zspan, int obi, int zvlnr,
- const float *v1, const float *v2, const float *v3, const float *v4)
-{
- BSPFace face;
-
- face.v1= v1;
- face.v2= v2;
- face.v3= v3;
- face.v4= v4;
- face.obi= obi;
- face.facenr= zvlnr & ~RE_QUAD_OFFS;
- face.type= 0;
- if (R.osa)
- face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha/(float)R.osa);
- else
- face.shad_alpha= (short)ceil(4096.0f*zspan->shad_alpha);
-
- face.is_full= (zspan->shad_alpha==1.0f);
-
- /* setup boundbox */
- init_box(&face.box);
- bound_boxf(&face.box, v1);
- bound_boxf(&face.box, v2);
- bound_boxf(&face.box, v3);
- if (v4)
- bound_boxf(&face.box, v4);
-
- isb_bsp_face_inside((ISBBranch *)zspan->rectz, &face);
-}
-
-static int testclip_minmax(const float ho[4], const float minmax[4])
-{
- float wco= ho[3];
- int flag= 0;
-
- if ( ho[0] > minmax[1]*wco) flag = 1;
- else if ( ho[0]< minmax[0]*wco) flag = 2;
-
- if ( ho[1] > minmax[3]*wco) flag |= 4;
- else if ( ho[1]< minmax[2]*wco) flag |= 8;
-
- return flag;
-}
-
-/* main loop going over all faces and check in bsp overlaps, fill in shadfac values */
-static void isb_bsp_fillfaces(Render *re, LampRen *lar, ISBBranch *root)
-{
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- ShadBuf *shb= lar->shb;
- ZSpan zspan, zspanstrand;
- VlakRen *vlr= NULL;
- Material *ma= NULL;
- float minmaxf[4], winmat[4][4];
- int size= shb->size;
- int i, a, ok=1, lay= -1;
-
- /* further optimize, also sets minz maxz */
- isb_bsp_recalc_box(root);
-
- /* extra clipping for minmax */
- minmaxf[0]= (2.0f*root->box.xmin - size-2.0f)/size;
- minmaxf[1]= (2.0f*root->box.xmax - size+2.0f)/size;
- minmaxf[2]= (2.0f*root->box.ymin - size-2.0f)/size;
- minmaxf[3]= (2.0f*root->box.ymax - size+2.0f)/size;
-
- if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay;
-
- /* (ab)use zspan, since we use zbuffer clipping code */
- zbuf_alloc_span(&zspan, size, size, re->clipcrop);
-
- zspan.zmulx= ((float)size)/2.0f;
- zspan.zmuly= ((float)size)/2.0f;
- zspan.zofsx= -0.5f;
- zspan.zofsy= -0.5f;
-
- /* pass on bsp root to zspan */
- zspan.rectz= (int *)root;
-
- /* filling methods */
- zspanstrand= zspan;
- // zspan.zbuflinefunc= zbufline_onlyZ;
- zspan.zbuffunc= isb_bsp_test_face;
- zspanstrand.zbuffunc= isb_bsp_test_strand;
-
- for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
- obr= obi->obr;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(winmat, shb->persmat, obi->mat);
- else
- copy_m4_m4(winmat, shb->persmat);
-
- for (a=0; a<obr->totvlak; a++) {
-
- if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
- else vlr++;
-
- /* note, these conditions are copied in shadowbuf_autoclip() */
- if (vlr->mat!= ma) {
- ma= vlr->mat;
- ok= 1;
- if ((ma->mode2 & MA_CASTSHADOW)==0 || (ma->mode & MA_SHADBUF)==0) ok= 0;
- if (ma->material_type == MA_TYPE_WIRE) ok= 0;
- zspanstrand.shad_alpha= zspan.shad_alpha= ma->shad_alpha;
- }
-
- if (ok && (obi->lay & lay)) {
- float hoco[4][4];
- int c1, c2, c3, c4=0;
- int d1, d2, d3, d4=0;
- int partclip;
-
- /* create hocos per face, it is while render */
- projectvert(vlr->v1->co, winmat, hoco[0]); d1= testclip_minmax(hoco[0], minmaxf);
- projectvert(vlr->v2->co, winmat, hoco[1]); d2= testclip_minmax(hoco[1], minmaxf);
- projectvert(vlr->v3->co, winmat, hoco[2]); d3= testclip_minmax(hoco[2], minmaxf);
- if (vlr->v4) {
- projectvert(vlr->v4->co, winmat, hoco[3]); d4= testclip_minmax(hoco[3], minmaxf);
- }
-
- /* minmax clipping */
- if (vlr->v4) partclip= d1 & d2 & d3 & d4;
- else partclip= d1 & d2 & d3;
-
- if (partclip==0) {
-
- /* window clipping */
- c1= testclip(hoco[0]);
- c2= testclip(hoco[1]);
- c3= testclip(hoco[2]);
- if (vlr->v4)
- c4= testclip(hoco[3]);
-
- /* ***** NO WIRE YET */
- if (ma->material_type == MA_TYPE_WIRE) {
- if (vlr->v4)
- zbufclipwire(&zspan, i, a+1, vlr->ec, hoco[0], hoco[1], hoco[2], hoco[3], c1, c2, c3, c4);
- else
- zbufclipwire(&zspan, i, a+1, vlr->ec, hoco[0], hoco[1], hoco[2], NULL, c1, c2, c3, 0);
- }
- else if (vlr->v4) {
- if (vlr->flag & R_STRAND)
- zbufclip4(&zspanstrand, i, a+1, hoco[0], hoco[1], hoco[2], hoco[3], c1, c2, c3, c4);
- else
- zbufclip4(&zspan, i, a+1, hoco[0], hoco[1], hoco[2], hoco[3], c1, c2, c3, c4);
- }
- else
- zbufclip(&zspan, i, a+1, hoco[0], hoco[1], hoco[2], c1, c2, c3);
-
- }
- }
- }
- }
-
- zbuf_free_span(&zspan);
-}
-
-/* returns 1 when the viewpixel is visible in lampbuffer */
-static int viewpixel_to_lampbuf(ShadBuf *shb, ObjectInstanceRen *obi, VlakRen *vlr, float x, float y, float co_r[3])
-{
- float hoco[4], v1[3], nor[3];
- float dface, fac, siz;
-
- RE_vlakren_get_normal(&R, obi, vlr, nor);
- copy_v3_v3(v1, vlr->v1->co);
- if (obi->flag & R_TRANSFORMED)
- mul_m4_v3(obi->mat, v1);
-
- /* from shadepixel() */
- dface = dot_v3v3(v1, nor);
- hoco[3]= 1.0f;
-
- /* ortho viewplane cannot intersect using view vector originating in (0, 0, 0) */
- if (R.r.mode & R_ORTHO) {
- /* x and y 3d coordinate can be derived from pixel coord and winmat */
- float fx= 2.0f/(R.winx*R.winmat[0][0]);
- float fy= 2.0f/(R.winy*R.winmat[1][1]);
-
- hoco[0]= (x - 0.5f*R.winx)*fx - R.winmat[3][0]/R.winmat[0][0];
- hoco[1]= (y - 0.5f*R.winy)*fy - R.winmat[3][1]/R.winmat[1][1];
-
- /* using a*x + b*y + c*z = d equation, (a b c) is normal */
- if (nor[2]!=0.0f)
- hoco[2]= (dface - nor[0]*hoco[0] - nor[1]*hoco[1])/nor[2];
- else
- hoco[2]= 0.0f;
- }
- else {
- float div, view[3];
-
- calc_view_vector(view, x, y);
-
- div = dot_v3v3(nor, view);
- if (div==0.0f)
- return 0;
-
- fac= dface/div;
-
- hoco[0]= fac*view[0];
- hoco[1]= fac*view[1];
- hoco[2]= fac*view[2];
- }
-
- /* move 3d vector to lampbuf */
- mul_m4_v4(shb->persmat, hoco); /* rational hom co */
-
- /* clip We can test for -1.0/1.0 because of the properties of the
- * coordinate transformations. */
- fac = fabsf(hoco[3]);
- if (hoco[0]<-fac || hoco[0]>fac)
- return 0;
- if (hoco[1]<-fac || hoco[1]>fac)
- return 0;
- if (hoco[2]<-fac || hoco[2]>fac)
- return 0;
-
- siz= 0.5f*(float)shb->size;
- co_r[0]= siz*(1.0f+hoco[0]/hoco[3]) -0.5f;
- co_r[1]= siz*(1.0f+hoco[1]/hoco[3]) -0.5f;
- co_r[2]= ((float)0x7FFFFFFF)*(hoco[2]/hoco[3]);
-
- /* XXXX bias, much less than normal shadbuf, or do we need a constant? */
- co_r[2] -= 0.05f*shb->bias;
-
- return 1;
-}
-
-/* storage of shadow results, solid osa and transp case */
-static void isb_add_shadfac(ISBShadfacA **isbsapp, MemArena *mem, int obi, int facenr, short shadfac, short samples)
-{
- ISBShadfacA *new;
- float shadfacf;
-
- /* in osa case, the samples were filled in with factor 1.0/R.osa. if fewer samples we have to correct */
- if (R.osa)
- shadfacf= ((float)shadfac*R.osa)/(4096.0f*samples);
- else
- shadfacf= ((float)shadfac)/(4096.0f);
-
- new= BLI_memarena_alloc(mem, sizeof(ISBShadfacA));
- new->obi= obi;
- new->facenr= facenr & ~RE_QUAD_OFFS;
- new->shadfac= shadfacf;
- if (*isbsapp)
- new->next= (*isbsapp);
- else
- new->next= NULL;
-
- *isbsapp= new;
-}
-
-/* adding samples, solid case */
-static int isb_add_samples(RenderPart *pa, ISBBranch *root, MemArena *memarena, ISBSample **samplebuf)
-{
- int xi, yi, *xcos, *ycos;
- int sample, bsp_err= 0;
-
- /* bsp split doesn't like to handle regular sequences */
- xcos= MEM_mallocN(pa->rectx*sizeof(int), "xcos");
- ycos= MEM_mallocN(pa->recty*sizeof(int), "ycos");
- for (xi=0; xi<pa->rectx; xi++)
- xcos[xi]= xi;
- for (yi=0; yi<pa->recty; yi++)
- ycos[yi]= yi;
- BLI_array_randomize(xcos, sizeof(int), pa->rectx, 12345);
- BLI_array_randomize(ycos, sizeof(int), pa->recty, 54321);
-
- for (sample=0; sample<(R.osa?R.osa:1); sample++) {
- ISBSample *samp= samplebuf[sample], *samp1;
-
- for (yi=0; yi<pa->recty; yi++) {
- int y= ycos[yi];
- for (xi=0; xi<pa->rectx; xi++) {
- int x= xcos[xi];
- samp1= samp + y*pa->rectx + x;
- if (samp1->facenr)
- bsp_err |= isb_bsp_insert(root, memarena, samp1);
- }
- if (bsp_err) break;
- }
- }
-
- MEM_freeN(xcos);
- MEM_freeN(ycos);
-
- return bsp_err;
-}
-
-/* solid version */
-/* lar->shb, pa->rectz and pa->rectp should exist */
-static void isb_make_buffer(RenderPart *pa, LampRen *lar)
-{
- ShadBuf *shb= lar->shb;
- ISBData *isbdata;
- ISBSample *samp, *samplebuf[16]; /* should be RE_MAX_OSA */
- ISBBranch root;
- MemArena *memarena;
- intptr_t *rd;
- int *recto, *rectp, x, y, sindex, sample, bsp_err=0;
-
- /* storage for shadow, per thread */
- isbdata= shb->isb_result[pa->thread];
-
- /* to map the shi->xs and ys coordinate */
- isbdata->minx= pa->disprect.xmin;
- isbdata->miny= pa->disprect.ymin;
- isbdata->rectx= pa->rectx;
- isbdata->recty= pa->recty;
-
- /* branches are added using memarena (32k branches) */
- memarena = BLI_memarena_new(0x8000 * sizeof(ISBBranch), "isb arena");
- BLI_memarena_use_calloc(memarena);
-
- /* samplebuf is in camera view space (pixels) */
- for (sample=0; sample<(R.osa?R.osa:1); sample++)
- samplebuf[sample]= MEM_callocN(sizeof(ISBSample)*pa->rectx*pa->recty, "isb samplebuf");
-
- /* for end result, ISBSamples point to this in non OSA case, otherwise to pixstruct->shadfac */
- if (R.osa==0)
- isbdata->shadfacs= MEM_callocN(pa->rectx*pa->recty*sizeof(short), "isb shadfacs");
-
- /* setup bsp root */
- memset(&root, 0, sizeof(ISBBranch));
- root.box.xmin = (float)shb->size;
- root.box.ymin = (float)shb->size;
-
- /* create the sample buffers */
- for (sindex=0, y=0; y<pa->recty; y++) {
- for (x=0; x<pa->rectx; x++, sindex++) {
-
- /* this makes it a long function, but splitting it out would mean 10+ arguments */
- /* first check OSA case */
- if (R.osa) {
- rd= pa->rectdaps + sindex;
- if (*rd) {
- float xs= (float)(x + pa->disprect.xmin);
- float ys= (float)(y + pa->disprect.ymin);
-
- for (sample=0; sample<R.osa; sample++) {
- PixStr *ps= (PixStr *)(*rd);
- int mask= (1<<sample);
-
- while (ps) {
- if (ps->mask & mask)
- break;
- ps= ps->next;
- }
- if (ps && ps->facenr>0) {
- ObjectInstanceRen *obi= &R.objectinstance[ps->obi];
- ObjectRen *obr= obi->obr;
- VlakRen *vlr= RE_findOrAddVlak(obr, (ps->facenr-1) & RE_QUAD_MASK);
-
- samp= samplebuf[sample] + sindex;
- /* convert image plane pixel location to lamp buffer space */
- if (viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], samp->zco)) {
- samp->obi= ps->obi;
- samp->facenr= ps->facenr & ~RE_QUAD_OFFS;
- ps->shadfac= 0;
- samp->shadfac= &ps->shadfac;
- bound_rectf((rctf *)&root.box, samp->zco);
- }
- }
- }
- }
- }
- else {
- rectp= pa->rectp + sindex;
- recto= pa->recto + sindex;
- if (*rectp>0) {
- ObjectInstanceRen *obi= &R.objectinstance[*recto];
- ObjectRen *obr= obi->obr;
- VlakRen *vlr= RE_findOrAddVlak(obr, (*rectp-1) & RE_QUAD_MASK);
- float xs= (float)(x + pa->disprect.xmin);
- float ys= (float)(y + pa->disprect.ymin);
-
- samp= samplebuf[0] + sindex;
- /* convert image plane pixel location to lamp buffer space */
- if (viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, samp->zco)) {
- samp->obi= *recto;
- samp->facenr= *rectp & ~RE_QUAD_OFFS;
- samp->shadfac= isbdata->shadfacs + sindex;
- bound_rectf((rctf *)&root.box, samp->zco);
- }
- }
- }
- }
- }
-
- /* simple method to see if we have samples */
- if (root.box.xmin != (float)shb->size) {
- /* now create a regular split, root.box has the initial bounding box of all pixels */
- /* split bsp 8 levels deep, in regular grid (16 x 16) */
- isb_bsp_split_init(&root, memarena, 8);
-
- /* insert all samples in BSP now */
- bsp_err= isb_add_samples(pa, &root, memarena, samplebuf);
-
- if (bsp_err==0) {
- /* go over all faces and fill in shadow values */
-
- isb_bsp_fillfaces(&R, lar, &root); /* shb->persmat should have been calculated */
-
- /* copy shadow samples to persistent buffer, reduce memory overhead */
- if (R.osa) {
- ISBShadfacA **isbsa= isbdata->shadfaca= MEM_callocN(pa->rectx*pa->recty*sizeof(void *), "isb shadfacs");
-
- isbdata->memarena = BLI_memarena_new(0x8000 * sizeof(ISBSampleA), "isb arena");
- BLI_memarena_use_calloc(isbdata->memarena);
-
- for (rd= pa->rectdaps, x=pa->rectx*pa->recty; x>0; x--, rd++, isbsa++) {
-
- if (*rd) {
- PixStr *ps= (PixStr *)(*rd);
- while (ps) {
- if (ps->shadfac)
- isb_add_shadfac(isbsa, isbdata->memarena, ps->obi, ps->facenr, ps->shadfac, count_mask(ps->mask));
- ps= ps->next;
- }
- }
- }
- }
- }
- }
- else {
- if (isbdata->shadfacs) {
- MEM_freeN(isbdata->shadfacs);
- isbdata->shadfacs= NULL;
- }
- }
-
- /* free BSP */
- BLI_memarena_free(memarena);
-
- /* free samples */
- for (x=0; x<(R.osa?R.osa:1); x++)
- MEM_freeN(samplebuf[x]);
-
- if (bsp_err) printf("error in filling bsp\n");
-}
-
-/* add sample to buffer, isbsa is the root sample in a buffer */
-static ISBSampleA *isb_alloc_sample_transp(ISBSampleA **isbsa, MemArena *mem)
-{
- ISBSampleA *new;
-
- new= BLI_memarena_alloc(mem, sizeof(ISBSampleA));
- if (*isbsa)
- new->next= (*isbsa);
- else
- new->next= NULL;
-
- *isbsa= new;
- return new;
-}
-
-/* adding samples in BSP, transparent case */
-static int isb_add_samples_transp(RenderPart *pa, ISBBranch *root, MemArena *memarena, ISBSampleA ***samplebuf)
-{
- int xi, yi, *xcos, *ycos;
- int sample, bsp_err= 0;
-
- /* bsp split doesn't like to handle regular sequences */
- xcos= MEM_mallocN(pa->rectx*sizeof(int), "xcos");
- ycos= MEM_mallocN(pa->recty*sizeof(int), "ycos");
- for (xi=0; xi<pa->rectx; xi++)
- xcos[xi]= xi;
- for (yi=0; yi<pa->recty; yi++)
- ycos[yi]= yi;
- BLI_array_randomize(xcos, sizeof(int), pa->rectx, 12345);
- BLI_array_randomize(ycos, sizeof(int), pa->recty, 54321);
-
- for (sample=0; sample<(R.osa?R.osa:1); sample++) {
- ISBSampleA **samp= samplebuf[sample], *samp1;
-
- for (yi=0; yi<pa->recty; yi++) {
- int y= ycos[yi];
- for (xi=0; xi<pa->rectx; xi++) {
- int x= xcos[xi];
-
- samp1= *(samp + y*pa->rectx + x);
- while (samp1) {
- bsp_err |= isb_bsp_insert(root, memarena, (ISBSample *)samp1);
- samp1= samp1->next;
- }
- }
- if (bsp_err) break;
- }
- }
-
- MEM_freeN(xcos);
- MEM_freeN(ycos);
-
- return bsp_err;
-}
-
-
-/* Ztransp version */
-/* lar->shb, pa->rectz and pa->rectp should exist */
-static void isb_make_buffer_transp(RenderPart *pa, APixstr *apixbuf, LampRen *lar)
-{
- ShadBuf *shb= lar->shb;
- ISBData *isbdata;
- ISBSampleA *samp, **samplebuf[16]; /* MAX_OSA */
- ISBBranch root;
- MemArena *memarena;
- APixstr *ap;
- int x, y, sindex, sample, bsp_err=0;
-
- /* storage for shadow, per thread */
- isbdata= shb->isb_result[pa->thread];
-
- /* to map the shi->xs and ys coordinate */
- isbdata->minx= pa->disprect.xmin;
- isbdata->miny= pa->disprect.ymin;
- isbdata->rectx= pa->rectx;
- isbdata->recty= pa->recty;
-
- /* branches are added using memarena (32k branches) */
- memarena = BLI_memarena_new(0x8000 * sizeof(ISBBranch), "isb arena");
- BLI_memarena_use_calloc(memarena);
-
- /* samplebuf is in camera view space (pixels) */
- for (sample=0; sample<(R.osa?R.osa:1); sample++)
- samplebuf[sample]= MEM_callocN(sizeof(void *)*pa->rectx*pa->recty, "isb alpha samplebuf");
-
- /* setup bsp root */
- memset(&root, 0, sizeof(ISBBranch));
- root.box.xmin = (float)shb->size;
- root.box.ymin = (float)shb->size;
-
- /* create the sample buffers */
- for (ap= apixbuf, sindex=0, y=0; y<pa->recty; y++) {
- for (x=0; x<pa->rectx; x++, sindex++, ap++) {
-
- if (ap->p[0]) {
- APixstr *apn;
- float xs= (float)(x + pa->disprect.xmin);
- float ys= (float)(y + pa->disprect.ymin);
-
- for (apn=ap; apn; apn= apn->next) {
- int a;
- for (a=0; a<4; a++) {
- if (apn->p[a]) {
- ObjectInstanceRen *obi= &R.objectinstance[apn->obi[a]];
- ObjectRen *obr= obi->obr;
- VlakRen *vlr= RE_findOrAddVlak(obr, (apn->p[a]-1) & RE_QUAD_MASK);
- float zco[3];
-
- /* here we store shadfac, easier to create the end storage buffer. needs zero'ed, multiple shadowbufs use it */
- apn->shadfac[a]= 0;
-
- if (R.osa) {
- for (sample=0; sample<R.osa; sample++) {
- int mask= (1<<sample);
-
- if (apn->mask[a] & mask) {
-
- /* convert image plane pixel location to lamp buffer space */
- if (viewpixel_to_lampbuf(shb, obi, vlr, xs + R.jit[sample][0], ys + R.jit[sample][1], zco)) {
- samp= isb_alloc_sample_transp(samplebuf[sample] + sindex, memarena);
- samp->obi= apn->obi[a];
- samp->facenr= apn->p[a] & ~RE_QUAD_OFFS;
- samp->shadfac= &apn->shadfac[a];
-
- copy_v3_v3(samp->zco, zco);
- bound_rectf((rctf *)&root.box, samp->zco);
- }
- }
- }
- }
- else {
-
- /* convert image plane pixel location to lamp buffer space */
- if (viewpixel_to_lampbuf(shb, obi, vlr, xs, ys, zco)) {
-
- samp= isb_alloc_sample_transp(samplebuf[0] + sindex, memarena);
- samp->obi= apn->obi[a];
- samp->facenr= apn->p[a] & ~RE_QUAD_OFFS;
- samp->shadfac= &apn->shadfac[a];
-
- copy_v3_v3(samp->zco, zco);
- bound_rectf((rctf *)&root.box, samp->zco);
- }
- }
- }
- }
- }
- }
- }
- }
-
- /* simple method to see if we have samples */
- if (root.box.xmin != (float)shb->size) {
- /* now create a regular split, root.box has the initial bounding box of all pixels */
- /* split bsp 8 levels deep, in regular grid (16 x 16) */
- isb_bsp_split_init(&root, memarena, 8);
-
- /* insert all samples in BSP now */
- bsp_err= isb_add_samples_transp(pa, &root, memarena, samplebuf);
-
- if (bsp_err==0) {
- ISBShadfacA **isbsa;
-
- /* go over all faces and fill in shadow values */
- isb_bsp_fillfaces(&R, lar, &root); /* shb->persmat should have been calculated */
-
- /* copy shadow samples to persistent buffer, reduce memory overhead */
- isbsa= isbdata->shadfaca= MEM_callocN(pa->rectx*pa->recty*sizeof(void *), "isb shadfacs");
-
- isbdata->memarena = BLI_memarena_new(0x8000 * sizeof(ISBSampleA), "isb arena");
-
- for (ap= apixbuf, x=pa->rectx*pa->recty; x>0; x--, ap++, isbsa++) {
-
- if (ap->p[0]) {
- APixstr *apn;
- for (apn=ap; apn; apn= apn->next) {
- int a;
- for (a=0; a<4; a++) {
- if (apn->p[a] && apn->shadfac[a]) {
- if (R.osa)
- isb_add_shadfac(isbsa, isbdata->memarena, apn->obi[a], apn->p[a], apn->shadfac[a], count_mask(apn->mask[a]));
- else
- isb_add_shadfac(isbsa, isbdata->memarena, apn->obi[a], apn->p[a], apn->shadfac[a], 0);
- }
- }
- }
- }
- }
- }
- }
-
- /* free BSP */
- BLI_memarena_free(memarena);
-
- /* free samples */
- for (x=0; x<(R.osa?R.osa:1); x++)
- MEM_freeN(samplebuf[x]);
-
- if (bsp_err) printf("error in filling bsp\n");
-}
-
-
-
-/* exported */
-
-/* returns amount of light (1.0 = no shadow) */
-/* note, shadepixel() rounds the coordinate, not the real sample info */
-float ISB_getshadow(ShadeInput *shi, ShadBuf *shb)
-{
- /* if raytracing, we can't accept irregular shadow */
- if (shi->depth==0) {
- ISBData *isbdata= shb->isb_result[shi->thread];
-
- if (isbdata) {
- if (isbdata->shadfacs || isbdata->shadfaca) {
- int x= shi->xs - isbdata->minx;
-
- if (x >= 0 && x < isbdata->rectx) {
- int y= shi->ys - isbdata->miny;
-
- if (y >= 0 && y < isbdata->recty) {
- if (isbdata->shadfacs) {
- const short *sp= isbdata->shadfacs + y*isbdata->rectx + x;
- return *sp>=4096?0.0f:1.0f - ((float)*sp)/4096.0f;
- }
- else {
- int sindex= y*isbdata->rectx + x;
- int obi= shi->obi - R.objectinstance;
- ISBShadfacA *isbsa= *(isbdata->shadfaca + sindex);
-
- while (isbsa) {
- if (isbsa->facenr==shi->facenr+1 && isbsa->obi==obi)
- return isbsa->shadfac>=1.0f?0.0f:1.0f - isbsa->shadfac;
- isbsa= isbsa->next;
- }
- }
- }
- }
- }
- }
- }
- return 1.0f;
-}
-
-/* part is supposed to be solid zbuffered (apixbuf==NULL) or transparent zbuffered */
-void ISB_create(RenderPart *pa, APixstr *apixbuf)
-{
- GroupObject *go;
-
- /* go over all lamps, and make the irregular buffers */
- for (go=R.lights.first; go; go= go->next) {
- LampRen *lar= go->lampren;
-
- if (lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) {
-
- /* create storage for shadow, per thread */
- lar->shb->isb_result[pa->thread]= MEM_callocN(sizeof(ISBData), "isb data");
-
- if (apixbuf)
- isb_make_buffer_transp(pa, apixbuf, lar);
- else
- isb_make_buffer(pa, lar);
- }
- }
-}
-
-
-/* end of part rendering, free stored shadow data for this thread from all lamps */
-void ISB_free(RenderPart *pa)
-{
- GroupObject *go;
-
- /* go over all lamps, and free the irregular buffers */
- for (go=R.lights.first; go; go= go->next) {
- LampRen *lar= go->lampren;
-
- if (lar->type==LA_SPOT && lar->shb && lar->buftype==LA_SHADBUF_IRREGULAR) {
- ISBData *isbdata= lar->shb->isb_result[pa->thread];
-
- if (isbdata) {
- if (isbdata->shadfacs)
- MEM_freeN(isbdata->shadfacs);
- if (isbdata->shadfaca)
- MEM_freeN(isbdata->shadfaca);
-
- if (isbdata->memarena)
- BLI_memarena_free(isbdata->memarena);
-
- MEM_freeN(isbdata);
- lar->shb->isb_result[pa->thread]= NULL;
- }
- }
- }
-}
diff --git a/source/blender/render/intern/source/shadeinput.c b/source/blender/render/intern/source/shadeinput.c
deleted file mode 100644
index b4ff5f52fcf..00000000000
--- a/source/blender/render/intern/source/shadeinput.c
+++ /dev/null
@@ -1,1490 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2006 Blender Foundation
- * All rights reserved.
- *
- * Contributors: Hos, Robert Wenzlaff.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/shadeinput.c
- * \ingroup render
- */
-
-
-#include <stdio.h>
-#include <math.h>
-#include <string.h>
-
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "DNA_lamp_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_material_types.h"
-#include "DNA_particle_types.h"
-
-#include "BKE_scene.h"
-
-#include "BKE_node.h"
-
-/* local include */
-#include "raycounter.h"
-#include "render_types.h"
-#include "renderdatabase.h"
-#include "rendercore.h"
-#include "shading.h"
-#include "strand.h"
-#include "texture.h"
-#include "volumetric.h"
-#include "zbuf.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-/* Shade Sample order:
- *
- * - shade_samples_fill_with_ps()
- * - for each sample
- * - shade_input_set_triangle() <- if prev sample-face is same, use shade_input_copy_triangle()
- * - if vlr
- * - shade_input_set_viewco() <- not for ray or bake
- * - shade_input_set_uv() <- not for ray or bake
- * - shade_input_set_normals()
- * - shade_samples()
- * - if AO
- * - shade_samples_do_AO()
- * - if shading happens
- * - for each sample
- * - shade_input_set_shade_texco()
- * - shade_samples_do_shade()
- * - OSA: distribute sample result with filter masking
- *
- */
-
-/* initialize material variables in shadeinput,
- * doing inverse gamma correction where applicable */
-void shade_input_init_material(ShadeInput *shi)
-{
- /* note, keep this synced with render_types.h */
- memcpy(&shi->r, &shi->mat->r, 23 * sizeof(float));
- shi->har = shi->mat->har;
-}
-
-/* also used as callback for nodes */
-/* delivers a fully filled in ShadeResult, for all passes */
-void shade_material_loop(ShadeInput *shi, ShadeResult *shr)
-{
-
- shade_lamp_loop(shi, shr); /* clears shr */
-
- if (shi->translucency != 0.0f) {
- ShadeResult shr_t;
- float fac = shi->translucency;
-
- shade_input_init_material(shi);
- negate_v3_v3(shi->vn, shi->vno);
- negate_v3(shi->facenor);
- shi->depth++; /* hack to get real shadow now */
- shade_lamp_loop(shi, &shr_t);
- shi->depth--;
-
- /* a couple of passes */
- madd_v3_v3fl(shr->combined, shr_t.combined, fac);
- if (shi->passflag & SCE_PASS_SPEC)
- madd_v3_v3fl(shr->spec, shr_t.spec, fac);
- if (shi->passflag & SCE_PASS_DIFFUSE) {
- madd_v3_v3fl(shr->diff, shr_t.diff, fac);
- madd_v3_v3fl(shr->diffshad, shr_t.diffshad, fac);
- }
- if (shi->passflag & SCE_PASS_SHADOW)
- madd_v3_v3fl(shr->shad, shr_t.shad, fac);
-
- negate_v3(shi->vn);
- negate_v3(shi->facenor);
- }
-
- /* depth >= 1 when ray-shading */
- if (shi->depth == 0 || shi->volume_depth > 0) {
- if (R.r.mode & R_RAYTRACE) {
- if (shi->ray_mirror != 0.0f || ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP) && shr->alpha != 1.0f)) {
- /* ray trace works on combined, but gives pass info */
- ray_trace(shi, shr);
- }
- }
- /* disable adding of sky for raytransp */
- if ((shi->mode & MA_TRANSP) && (shi->mode & MA_RAYTRANSP))
- if ((shi->layflag & SCE_LAY_SKY) && (R.r.alphamode == R_ADDSKY))
- shr->alpha = 1.0f;
- }
-
- if (R.r.mode & R_RAYTRACE) {
- if (R.render_volumes_inside.first)
- shade_volume_inside(shi, shr);
- }
-}
-
-
-/* do a shade, finish up some passes, apply mist */
-void shade_input_do_shade(ShadeInput *shi, ShadeResult *shr)
-{
- bool compat = false;
- float alpha;
-
- /* ------ main shading loop -------- */
-#ifdef RE_RAYCOUNTER
- memset(&shi->raycounter, 0, sizeof(shi->raycounter));
-#endif
-
- if (shi->mat->nodetree && shi->mat->use_nodes) {
- compat = ntreeShaderExecTree(shi->mat->nodetree, shi, shr);
- }
-
- /* also run this when node shaders fail, due to incompatible shader nodes */
- if (compat == false) {
- /* copy all relevant material vars, note, keep this synced with render_types.h */
- shade_input_init_material(shi);
-
- if (shi->mat->material_type == MA_TYPE_VOLUME) {
- if (R.r.mode & R_RAYTRACE) {
- shade_volume_outside(shi, shr);
- }
- }
- else { /* MA_TYPE_SURFACE, MA_TYPE_WIRE */
- shade_material_loop(shi, shr);
- }
- }
-
- /* copy additional passes */
- if (shi->passflag & (SCE_PASS_VECTOR | SCE_PASS_NORMAL)) {
- copy_v4_v4(shr->winspeed, shi->winspeed);
- copy_v3_v3(shr->nor, shi->vn);
- }
-
- /* MIST */
- if ((shi->passflag & SCE_PASS_MIST) || ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST) == 0)) {
- if (R.r.mode & R_ORTHO)
- shr->mist = mistfactor(-shi->co[2], shi->co);
- else
- shr->mist = mistfactor(len_v3(shi->co), shi->co);
- }
- else shr->mist = 0.0f;
-
- if ((R.wrld.mode & WO_MIST) && (shi->mat->mode & MA_NOMIST) == 0) {
- alpha = shr->mist;
- }
- else alpha = 1.0f;
-
- /* add mist and premul color */
- if (shr->alpha != 1.0f || alpha != 1.0f) {
- float fac = alpha * (shr->alpha);
- shr->combined[3] = fac;
-
- if (shi->mat->material_type != MA_TYPE_VOLUME)
- mul_v3_fl(shr->combined, fac);
- }
- else
- shr->combined[3] = 1.0f;
-
- /* add z */
- shr->z = -shi->co[2];
-
- /* RAYHITS */
-#if 0
- if (1 || shi->passflag & SCE_PASS_RAYHITS) {
- shr->rayhits[0] = (float)shi->raycounter.faces.test;
- shr->rayhits[1] = (float)shi->raycounter.bb.hit;
- shr->rayhits[2] = 0.0;
- shr->rayhits[3] = 1.0;
- }
-#endif
-
- RE_RC_MERGE(&re_rc_counter[shi->thread], &shi->raycounter);
-}
-
-/* **************************************************************************** */
-/* ShadeInput */
-/* **************************************************************************** */
-
-
-void vlr_set_uv_indices(VlakRen *vlr, int *i1, int *i2, int *i3)
-{
- /* to prevent storing new tfaces or vcols, we check a split runtime */
- /* 4---3 4---3 */
- /* |\ 1| or |1 /| */
- /* |0\ | |/ 0| */
- /* 1---2 1---2 0 = orig face, 1 = new face */
-
- /* Update vert nums to point to correct verts of original face */
- if (vlr->flag & R_DIVIDE_24) {
- if (vlr->flag & R_FACE_SPLIT) {
- (*i1)++; (*i2)++; (*i3)++;
- }
- else {
- (*i3)++;
- }
- }
- else if (vlr->flag & R_FACE_SPLIT) {
- (*i2)++; (*i3)++;
- }
-}
-
-/* copy data from face to ShadeInput, general case */
-/* indices 0 1 2 3 only */
-void shade_input_set_triangle_i(ShadeInput *shi, ObjectInstanceRen *obi, VlakRen *vlr, short i1, short i2, short i3)
-{
- VertRen **vpp = &vlr->v1;
-
- shi->vlr = vlr;
- shi->obi = obi;
- shi->obr = obi->obr;
-
- shi->v1 = vpp[i1];
- shi->v2 = vpp[i2];
- shi->v3 = vpp[i3];
-
- shi->i1 = i1;
- shi->i2 = i2;
- shi->i3 = i3;
-
- /* note, shi->mat is set in node shaders */
- shi->mat = shi->mat_override ? shi->mat_override : vlr->mat;
-
- shi->osatex = (shi->mat->texco & TEXCO_OSA);
- shi->mode = shi->mat->mode_l; /* or-ed result for all nodes */
- shi->mode2 = shi->mat->mode2_l;
-
- /* facenormal copy, can get flipped */
- shi->flippednor = 0;
- RE_vlakren_get_normal(&R, obi, vlr, shi->facenor);
-
- /* calculate vertexnormals */
- if (vlr->flag & R_SMOOTH) {
- copy_v3_v3(shi->n1, shi->v1->n);
- copy_v3_v3(shi->n2, shi->v2->n);
- copy_v3_v3(shi->n3, shi->v3->n);
-
- if (obi->flag & R_TRANSFORMED) {
- mul_m3_v3(obi->nmat, shi->n1); normalize_v3(shi->n1);
- mul_m3_v3(obi->nmat, shi->n2); normalize_v3(shi->n2);
- mul_m3_v3(obi->nmat, shi->n3); normalize_v3(shi->n3);
- }
- }
-}
-
-/* copy data from face to ShadeInput, scanline case */
-void shade_input_set_triangle(ShadeInput *shi, int obi, int facenr, int UNUSED(normal_flip))
-{
- if (facenr > 0) {
- shi->obi = &R.objectinstance[obi];
- shi->obr = shi->obi->obr;
- shi->facenr = (facenr - 1) & RE_QUAD_MASK;
- if (shi->facenr < shi->obr->totvlak) {
- VlakRen *vlr = RE_findOrAddVlak(shi->obr, shi->facenr);
-
- if (facenr & RE_QUAD_OFFS)
- shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 2, 3);
- else
- shade_input_set_triangle_i(shi, shi->obi, vlr, 0, 1, 2);
- }
- else
- shi->vlr = NULL; /* general signal we got sky */
- }
- else
- shi->vlr = NULL; /* general signal we got sky */
-}
-
-/* full osa case: copy static info */
-void shade_input_copy_triangle(ShadeInput *shi, ShadeInput *from)
-{
- /* not so nice, but works... warning is in RE_shader_ext.h */
- memcpy(shi, from, sizeof(struct ShadeInputCopy));
-}
-
-/* copy data from strand to shadeinput */
-void shade_input_set_strand(ShadeInput *shi, StrandRen *strand, StrandPoint *spoint)
-{
- /* note, shi->mat is set in node shaders */
- shi->mat = shi->mat_override ? shi->mat_override : strand->buffer->ma;
-
- shi->osatex = (shi->mat->texco & TEXCO_OSA);
- shi->mode = shi->mat->mode_l; /* or-ed result for all nodes */
-
- /* shade_input_set_viewco equivalent */
- copy_v3_v3(shi->co, spoint->co);
- copy_v3_v3(shi->view, shi->co);
- normalize_v3(shi->view);
-
- shi->xs = (int)spoint->x;
- shi->ys = (int)spoint->y;
-
- if (shi->osatex || (R.r.mode & R_SHADOW)) {
- copy_v3_v3(shi->dxco, spoint->dtco);
- copy_v3_v3(shi->dyco, spoint->dsco);
- }
-
- /* dxview, dyview, not supported */
-
- /* facenormal, simply viewco flipped */
- copy_v3_v3(shi->facenor, spoint->nor);
-
- /* shade_input_set_normals equivalent */
- if (shi->mat->mode & MA_TANGENT_STR) {
- copy_v3_v3(shi->vn, spoint->tan);
- }
- else {
- float cross[3];
-
- cross_v3_v3v3(cross, spoint->co, spoint->tan);
- cross_v3_v3v3(shi->vn, cross, spoint->tan);
- normalize_v3(shi->vn);
-
- if (dot_v3v3(shi->vn, shi->view) < 0.0f)
- negate_v3(shi->vn);
- }
-
- copy_v3_v3(shi->vno, shi->vn);
-}
-
-void shade_input_set_strand_texco(ShadeInput *shi, StrandRen *strand, StrandVert *svert, StrandPoint *spoint)
-{
- StrandBuffer *strandbuf = strand->buffer;
- ObjectRen *obr = strandbuf->obr;
- StrandVert *sv;
- int mode = shi->mode; /* or-ed result for all nodes */
- short texco = shi->mat->texco;
-
- if ((shi->mat->texco & TEXCO_REFL)) {
- /* shi->dxview, shi->dyview, not supported */
- }
-
- if (shi->osatex && (texco & (TEXCO_NORM | TEXCO_REFL))) {
- /* not supported */
- }
-
- if (mode & (MA_TANGENT_V | MA_NORMAP_TANG)) {
- copy_v3_v3(shi->tang, spoint->tan);
- copy_v3_v3(shi->nmaptang, spoint->tan);
- }
-
- if (mode & MA_STR_SURFDIFF) {
- const float *surfnor = RE_strandren_get_surfnor(obr, strand, 0);
-
- if (surfnor)
- copy_v3_v3(shi->surfnor, surfnor);
- else
- copy_v3_v3(shi->surfnor, shi->vn);
-
- if (shi->mat->strand_surfnor > 0.0f) {
- shi->surfdist = 0.0f;
- for (sv = strand->vert; sv != svert; sv++)
- shi->surfdist += len_v3v3(sv->co, (sv + 1)->co);
- shi->surfdist += spoint->t * len_v3v3(sv->co, (sv + 1)->co);
- }
- }
-
- if (R.r.mode & R_SPEED) {
- const float *speed;
-
- speed = RE_strandren_get_winspeed(shi->obi, strand, 0);
- if (speed)
- copy_v4_v4(shi->winspeed, speed);
- else
- shi->winspeed[0] = shi->winspeed[1] = shi->winspeed[2] = shi->winspeed[3] = 0.0f;
- }
-
- /* shade_input_set_shade_texco equivalent */
- if (texco & NEED_UV) {
- if (texco & TEXCO_ORCO) {
- copy_v3_v3(shi->lo, strand->orco);
- /* no shi->osatex, orco derivatives are zero */
- }
-
- if (texco & TEXCO_GLOB) {
- mul_v3_m4v3(shi->gl, R.viewinv, shi->co);
-
- if (shi->osatex) {
- mul_v3_mat3_m4v3(shi->dxgl, R.viewinv, shi->dxco);
- mul_v3_mat3_m4v3(shi->dygl, R.viewinv, shi->dyco);
- }
- }
-
- if (texco & TEXCO_STRAND) {
- shi->strandco = spoint->strandco;
-
- if (shi->osatex) {
- shi->dxstrand = spoint->dtstrandco;
- shi->dystrand = 0.0f;
- }
- }
-
- if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE))) {
- MCol *mcol;
- const float *uv;
- char *name;
- int i;
-
- shi->totuv = 0;
- shi->totcol = 0;
- shi->actuv = obr->actmtface;
- shi->actcol = obr->actmcol;
-
- if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) {
- for (i = 0; (mcol = RE_strandren_get_mcol(obr, strand, i, &name, 0)); i++) {
- ShadeInputCol *scol = &shi->col[i];
- const char *cp = (char *)mcol;
-
- shi->totcol++;
- scol->name = name;
-
- scol->col[0] = cp[3] / 255.0f;
- scol->col[1] = cp[2] / 255.0f;
- scol->col[2] = cp[1] / 255.0f;
- scol->col[3] = cp[0] / 255.0f;
- }
-
- if (shi->totcol) {
- shi->vcol[0] = shi->col[shi->actcol].col[0];
- shi->vcol[1] = shi->col[shi->actcol].col[1];
- shi->vcol[2] = shi->col[shi->actcol].col[2];
- shi->vcol[3] = shi->col[shi->actcol].col[3];
- }
- else {
- shi->vcol[0] = 0.0f;
- shi->vcol[1] = 0.0f;
- shi->vcol[2] = 0.0f;
- shi->vcol[3] = 0.0f;
- }
- }
-
- for (i = 0; (uv = RE_strandren_get_uv(obr, strand, i, &name, 0)); i++) {
- ShadeInputUV *suv = &shi->uv[i];
-
- shi->totuv++;
- suv->name = name;
-
- if (strandbuf->overrideuv == i) {
- suv->uv[0] = -1.0f;
- suv->uv[1] = spoint->strandco;
- suv->uv[2] = 0.0f;
- }
- else {
- suv->uv[0] = -1.0f + 2.0f * uv[0];
- suv->uv[1] = -1.0f + 2.0f * uv[1];
- suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */
- }
-
- if (shi->osatex) {
- suv->dxuv[0] = 0.0f;
- suv->dxuv[1] = 0.0f;
- suv->dyuv[0] = 0.0f;
- suv->dyuv[1] = 0.0f;
- }
-
- if ((mode & MA_FACETEXTURE) && i == obr->actmtface) {
- if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) {
- shi->vcol[0] = 1.0f;
- shi->vcol[1] = 1.0f;
- shi->vcol[2] = 1.0f;
- shi->vcol[3] = 1.0f;
- }
- }
- }
-
- if (shi->totuv == 0) {
- ShadeInputUV *suv = &shi->uv[0];
-
- suv->uv[0] = 0.0f;
- suv->uv[1] = spoint->strandco;
- suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */
-
- if (mode & MA_FACETEXTURE) {
- /* no tface? set at 1.0f */
- shi->vcol[0] = 1.0f;
- shi->vcol[1] = 1.0f;
- shi->vcol[2] = 1.0f;
- shi->vcol[3] = 1.0f;
- }
- }
-
- }
-
- if (texco & TEXCO_NORM) {
- shi->orn[0] = -shi->vn[0];
- shi->orn[1] = -shi->vn[1];
- shi->orn[2] = -shi->vn[2];
- }
-
- if (texco & TEXCO_STRESS) {
- /* not supported */
- }
-
- if (texco & TEXCO_TANGENT) {
- if ((mode & MA_TANGENT_V) == 0) {
- /* just prevent surprises */
- shi->tang[0] = shi->tang[1] = shi->tang[2] = 0.0f;
- shi->nmaptang[0] = shi->nmaptang[1] = shi->nmaptang[2] = 0.0f;
- }
- }
- }
-
- /* this only avalailable for scanline renders */
- if (shi->depth == 0) {
- if (texco & TEXCO_WINDOW) {
- shi->winco[0] = -1.0f + 2.0f * spoint->x / (float)R.winx;
- shi->winco[1] = -1.0f + 2.0f * spoint->y / (float)R.winy;
- shi->winco[2] = 0.0f;
-
- /* not supported */
- if (shi->osatex) {
- shi->dxwin[0] = 0.0f;
- shi->dywin[1] = 0.0f;
- shi->dxwin[0] = 0.0f;
- shi->dywin[1] = 0.0f;
- }
- }
- }
-
- if (shi->do_manage) {
- if (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) {
- srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol);
- }
- }
-
-}
-
-/* from scanline pixel coordinates to 3d coordinates, requires set_triangle */
-void shade_input_calc_viewco(ShadeInput *shi, float x, float y, float z, float view[3], float dxyview[2], float co[3], float dxco[3], float dyco[3])
-{
- /* returns not normalized, so is in viewplane coords */
- calc_view_vector(view, x, y);
-
- if (shi->mat->material_type == MA_TYPE_WIRE) {
- /* wire cannot use normal for calculating shi->co, so
- * we reconstruct the coordinate less accurate */
- if (R.r.mode & R_ORTHO)
- calc_renderco_ortho(co, x, y, z);
- else
- calc_renderco_zbuf(co, view, z);
- }
- else {
- /* for non-wire, intersect with the triangle to get the exact coord */
- float fac, dface, v1[3];
-
- copy_v3_v3(v1, shi->v1->co);
- if (shi->obi->flag & R_TRANSFORMED)
- mul_m4_v3(shi->obi->mat, v1);
-
- dface = dot_v3v3(v1, shi->facenor);
-
- /* ortho viewplane cannot intersect using view vector originating in (0,0,0) */
- if (R.r.mode & R_ORTHO) {
- /* x and y 3d coordinate can be derived from pixel coord and winmat */
- float fx = 2.0f / (R.winx * R.winmat[0][0]);
- float fy = 2.0f / (R.winy * R.winmat[1][1]);
-
- co[0] = (x - 0.5f * R.winx) * fx - R.winmat[3][0] / R.winmat[0][0];
- co[1] = (y - 0.5f * R.winy) * fy - R.winmat[3][1] / R.winmat[1][1];
-
- /* using a*x + b*y + c*z = d equation, (a b c) is normal */
- if (shi->facenor[2] != 0.0f)
- co[2] = (dface - shi->facenor[0] * co[0] - shi->facenor[1] * co[1]) / shi->facenor[2];
- else
- co[2] = 0.0f;
-
- if (dxco && dyco) {
- dxco[0] = fx;
- dxco[1] = 0.0f;
- if (shi->facenor[2] != 0.0f)
- dxco[2] = -(shi->facenor[0] * fx) / shi->facenor[2];
- else
- dxco[2] = 0.0f;
-
- dyco[0] = 0.0f;
- dyco[1] = fy;
- if (shi->facenor[2] != 0.0f)
- dyco[2] = -(shi->facenor[1] * fy) / shi->facenor[2];
- else
- dyco[2] = 0.0f;
-
- if (dxyview) {
- fac = (co[2] != 0.0f) ? (1.0f / co[2]) : 0.0f;
- dxyview[0] = -R.viewdx * fac;
- dxyview[1] = -R.viewdy * fac;
- }
- }
- }
- else {
- float div;
-
- div = dot_v3v3(shi->facenor, view);
- if (div != 0.0f) fac = dface / div;
- else fac = 0.0f;
-
- co[0] = fac * view[0];
- co[1] = fac * view[1];
- co[2] = fac * view[2];
-
- /* pixel dx/dy for render coord */
- if (dxco && dyco) {
- float u = dface / (div - R.viewdx * shi->facenor[0]);
- float v = dface / (div - R.viewdy * shi->facenor[1]);
-
- dxco[0] = co[0] - (view[0] - R.viewdx) * u;
- dxco[1] = co[1] - (view[1]) * u;
- dxco[2] = co[2] - (view[2]) * u;
-
- dyco[0] = co[0] - (view[0]) * v;
- dyco[1] = co[1] - (view[1] - R.viewdy) * v;
- dyco[2] = co[2] - (view[2]) * v;
-
- if (dxyview) {
- if (fac != 0.0f) fac = 1.0f / fac;
- dxyview[0] = -R.viewdx * fac;
- dxyview[1] = -R.viewdy * fac;
- }
- }
- }
- }
-
- /* set camera coords - for scanline, it's always 0.0,0.0,0.0 (render is in camera space)
- * however for raytrace it can be different - the position of the last intersection */
- shi->camera_co[0] = shi->camera_co[1] = shi->camera_co[2] = 0.0f;
-
- /* cannot normalize earlier, code above needs it at viewplane level */
- normalize_v3(view);
-}
-
-/* from scanline pixel coordinates to 3d coordinates, requires set_triangle */
-void shade_input_set_viewco(ShadeInput *shi, float x, float y, float xs, float ys, float z)
-{
- float *dxyview = NULL, *dxco = NULL, *dyco = NULL;
-
- /* currently in use for dithering (soft shadow), node preview, irregular shad */
- shi->xs = (int)xs;
- shi->ys = (int)ys;
-
- /* original scanline coordinate without jitter */
- shi->scanco[0] = x;
- shi->scanco[1] = y;
- shi->scanco[2] = z;
-
- /* check if we need derivatives */
- if (shi->osatex || (R.r.mode & R_SHADOW)) {
- dxco = shi->dxco;
- dyco = shi->dyco;
-
- if ((shi->mat->texco & TEXCO_REFL))
- dxyview = &shi->dxview;
- }
-
- shade_input_calc_viewco(shi, xs, ys, z, shi->view, dxyview, shi->co, dxco, dyco);
-}
-
-void barycentric_differentials_from_position(
- const float co[3], const float v1[3], const float v2[3], const float v3[3],
- const float dxco[3], const float dyco[3], const float facenor[3], const bool differentials,
- float *u, float *v, float *dx_u, float *dx_v, float *dy_u, float *dy_v)
-{
- /* find most stable axis to project */
- int axis1, axis2;
- axis_dominant_v3(&axis1, &axis2, facenor);
-
- /* compute u,v and derivatives */
- float t00 = v3[axis1] - v1[axis1];
- float t01 = v3[axis2] - v1[axis2];
- float t10 = v3[axis1] - v2[axis1];
- float t11 = v3[axis2] - v2[axis2];
-
- float detsh = (t00 * t11 - t10 * t01);
- detsh = (detsh != 0.0f) ? 1.0f / detsh : 0.0f;
- t00 *= detsh; t01 *= detsh;
- t10 *= detsh; t11 *= detsh;
-
- *u = (v3[axis1] - co[axis1]) * t11 - (v3[axis2] - co[axis2]) * t10;
- *v = (v3[axis2] - co[axis2]) * t00 - (v3[axis1] - co[axis1]) * t01;
- if (differentials) {
- *dx_u = dxco[axis1] * t11 - dxco[axis2] * t10;
- *dx_v = dxco[axis2] * t00 - dxco[axis1] * t01;
- *dy_u = dyco[axis1] * t11 - dyco[axis2] * t10;
- *dy_v = dyco[axis2] * t00 - dyco[axis1] * t01;
- }
-}
-/* calculate U and V, for scanline (silly render face u and v are in range -1 to 0) */
-void shade_input_set_uv(ShadeInput *shi)
-{
- VlakRen *vlr = shi->vlr;
-
- if ((vlr->flag & R_SMOOTH) || (shi->mat->texco & NEED_UV) || (shi->passflag & SCE_PASS_UV)) {
- float v1[3], v2[3], v3[3];
-
- copy_v3_v3(v1, shi->v1->co);
- copy_v3_v3(v2, shi->v2->co);
- copy_v3_v3(v3, shi->v3->co);
-
- if (shi->obi->flag & R_TRANSFORMED) {
- mul_m4_v3(shi->obi->mat, v1);
- mul_m4_v3(shi->obi->mat, v2);
- mul_m4_v3(shi->obi->mat, v3);
- }
-
- /* exception case for wire render of edge */
- if (vlr->v2 == vlr->v3) {
- float lend, lenc;
-
- lend = len_v3v3(v2, v1);
- lenc = len_v3v3(shi->co, v1);
-
- if (lend == 0.0f) {
- shi->u = shi->v = 0.0f;
- }
- else {
- shi->u = -(1.0f - lenc / lend);
- shi->v = 0.0f;
- }
-
- if (shi->osatex) {
- shi->dx_u = 0.0f;
- shi->dx_v = 0.0f;
- shi->dy_u = 0.0f;
- shi->dy_v = 0.0f;
- }
- }
- else {
- barycentric_differentials_from_position(
- shi->co, v1, v2, v3, shi->dxco, shi->dyco, shi->facenor, shi->osatex,
- &shi->u, &shi->v, &shi->dx_u, &shi->dx_v, &shi->dy_u, &shi->dy_v);
-
- shi->u = -shi->u;
- shi->v = -shi->v;
-
- /* u and v are in range -1 to 0, we allow a little bit extra but not too much, screws up speedvectors */
- CLAMP(shi->u, -2.0f, 1.0f);
- CLAMP(shi->v, -2.0f, 1.0f);
- }
- }
-}
-
-void shade_input_set_normals(ShadeInput *shi)
-{
- float u = shi->u, v = shi->v;
- float l = 1.0f + u + v;
-
- shi->flippednor = 0;
-
- /* test flip normals to viewing direction */
- if (!(shi->vlr->flag & R_TANGENT)) {
- if (dot_v3v3(shi->facenor, shi->view) < 0.0f) {
- negate_v3(shi->facenor);
- shi->flippednor = 1;
- }
- }
-
- /* calculate vertexnormals */
- if (shi->vlr->flag & R_SMOOTH) {
- float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3;
-
- if (shi->flippednor) {
- negate_v3(n1);
- negate_v3(n2);
- negate_v3(n3);
- }
-
- shi->vn[0] = l * n3[0] - u * n1[0] - v * n2[0];
- shi->vn[1] = l * n3[1] - u * n1[1] - v * n2[1];
- shi->vn[2] = l * n3[2] - u * n1[2] - v * n2[2];
-
- /* use unnormalized normal (closer to games) */
- copy_v3_v3(shi->nmapnorm, shi->vn);
-
- normalize_v3(shi->vn);
- }
- else {
- copy_v3_v3(shi->vn, shi->facenor);
- copy_v3_v3(shi->nmapnorm, shi->vn);
- }
-
- /* used in nodes */
- copy_v3_v3(shi->vno, shi->vn);
-
- /* flip normals to viewing direction */
- if (!(shi->vlr->flag & R_TANGENT))
- if (dot_v3v3(shi->facenor, shi->view) < 0.0f)
- shade_input_flip_normals(shi);
-}
-
-/* XXX shi->flippednor messes up otherwise */
-void shade_input_set_vertex_normals(ShadeInput *shi)
-{
- float u = shi->u, v = shi->v;
- float l = 1.0f + u + v;
-
- /* calculate vertexnormals */
- if (shi->vlr->flag & R_SMOOTH) {
- const float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3;
-
- shi->vn[0] = l * n3[0] - u * n1[0] - v * n2[0];
- shi->vn[1] = l * n3[1] - u * n1[1] - v * n2[1];
- shi->vn[2] = l * n3[2] - u * n1[2] - v * n2[2];
-
- /* use unnormalized normal (closer to games) */
- copy_v3_v3(shi->nmapnorm, shi->vn);
-
- normalize_v3(shi->vn);
- }
- else {
- copy_v3_v3(shi->vn, shi->facenor);
- copy_v3_v3(shi->nmapnorm, shi->vn);
- }
-
- /* used in nodes */
- copy_v3_v3(shi->vno, shi->vn);
-}
-
-
-/* use by raytrace, sss, bake to flip into the right direction */
-void shade_input_flip_normals(ShadeInput *shi)
-{
- negate_v3(shi->facenor);
- negate_v3(shi->vn);
- negate_v3(shi->vno);
- negate_v3(shi->nmapnorm);
- shi->flippednor = !shi->flippednor;
-}
-
-void shade_input_set_shade_texco(ShadeInput *shi)
-{
- ObjectInstanceRen *obi = shi->obi;
- ObjectRen *obr = shi->obr;
- VertRen *v1 = shi->v1, *v2 = shi->v2, *v3 = shi->v3;
- float u = shi->u, v = shi->v;
- float l = 1.0f + u + v, dl;
- int mode = shi->mode; /* or-ed result for all nodes */
- int mode2 = shi->mode2;
- short texco = shi->mat->texco;
- const bool need_mikk_tangent = (mode & MA_NORMAP_TANG || R.flag & R_NEED_TANGENT);
- const bool need_mikk_tangent_concrete = (mode2 & MA_TANGENT_CONCRETE) != 0;
-
- /* calculate dxno */
- if (shi->vlr->flag & R_SMOOTH) {
-
- if (shi->osatex && (texco & (TEXCO_NORM | TEXCO_REFL)) ) {
- const float *n1 = shi->n1, *n2 = shi->n2, *n3 = shi->n3;
-
- dl = shi->dx_u + shi->dx_v;
- shi->dxno[0] = dl * n3[0] - shi->dx_u * n1[0] - shi->dx_v * n2[0];
- shi->dxno[1] = dl * n3[1] - shi->dx_u * n1[1] - shi->dx_v * n2[1];
- shi->dxno[2] = dl * n3[2] - shi->dx_u * n1[2] - shi->dx_v * n2[2];
- dl = shi->dy_u + shi->dy_v;
- shi->dyno[0] = dl * n3[0] - shi->dy_u * n1[0] - shi->dy_v * n2[0];
- shi->dyno[1] = dl * n3[1] - shi->dy_u * n1[1] - shi->dy_v * n2[1];
- shi->dyno[2] = dl * n3[2] - shi->dy_u * n1[2] - shi->dy_v * n2[2];
-
- }
- }
-
- /* calc tangents */
- if (mode & (MA_TANGENT_V | MA_NORMAP_TANG) || mode2 & MA_TANGENT_CONCRETE || R.flag & R_NEED_TANGENT) {
- const float *s1, *s2, *s3;
- float tl, tu, tv;
-
- if (shi->vlr->flag & R_SMOOTH) {
- tl = l;
- tu = u;
- tv = v;
- }
- else {
- /* qdn: flat faces have tangents too,
- * could pick either one, using average here */
- tl = 1.0f / 3.0f;
- tu = -1.0f / 3.0f;
- tv = -1.0f / 3.0f;
- }
-
- shi->tang[0] = shi->tang[1] = shi->tang[2] = 0.0f;
- shi->nmaptang[0] = shi->nmaptang[1] = shi->nmaptang[2] = 0.0f;
-
- if (mode & MA_TANGENT_V) {
- s1 = RE_vertren_get_tangent(obr, v1, 0);
- s2 = RE_vertren_get_tangent(obr, v2, 0);
- s3 = RE_vertren_get_tangent(obr, v3, 0);
-
- if (s1 && s2 && s3) {
- shi->tang[0] = (tl * s3[0] - tu * s1[0] - tv * s2[0]);
- shi->tang[1] = (tl * s3[1] - tu * s1[1] - tv * s2[1]);
- shi->tang[2] = (tl * s3[2] - tu * s1[2] - tv * s2[2]);
-
- if (obi->flag & R_TRANSFORMED)
- mul_m3_v3(obi->nmat, shi->tang);
-
- normalize_v3(shi->tang);
- copy_v3_v3(shi->nmaptang, shi->tang);
- }
- }
-
- if (need_mikk_tangent || need_mikk_tangent_concrete) {
- int j1 = shi->i1, j2 = shi->i2, j3 = shi->i3;
- float c0[3], c1[3], c2[3];
- int acttang = obr->actmtface;
-
- vlr_set_uv_indices(shi->vlr, &j1, &j2, &j3);
-
- /* cycle through all tangent in vlakren */
- for (int i = 0; i < MAX_MTFACE; i++) {
- const float *tangent = RE_vlakren_get_nmap_tangent(obr, shi->vlr, i, false);
- if (!tangent)
- continue;
-
- copy_v3_v3(c0, &tangent[j1 * 4]);
- copy_v3_v3(c1, &tangent[j2 * 4]);
- copy_v3_v3(c2, &tangent[j3 * 4]);
-
- /* keeping tangents normalized at vertex level
- * corresponds better to how it's done in game engines */
- if (obi->flag & R_TRANSFORMED) {
- mul_mat3_m4_v3(obi->mat, c0); normalize_v3(c0);
- mul_mat3_m4_v3(obi->mat, c1); normalize_v3(c1);
- mul_mat3_m4_v3(obi->mat, c2); normalize_v3(c2);
- }
-
- /* we don't normalize the interpolated TBN tangent
- * corresponds better to how it's done in game engines */
- shi->tangents[i][0] = (tl * c2[0] - tu * c0[0] - tv * c1[0]);
- shi->tangents[i][1] = (tl * c2[1] - tu * c0[1] - tv * c1[1]);
- shi->tangents[i][2] = (tl * c2[2] - tu * c0[2] - tv * c1[2]);
-
- /* the sign is the same for all 3 vertices of any
- * non degenerate triangle. */
- shi->tangents[i][3] = tangent[j1 * 4 + 3];
-
- if (acttang == i && need_mikk_tangent) {
- for (int m = 0; m < 4; m++) {
- shi->nmaptang[m] = shi->tangents[i][m];
- }
- }
- }
- }
- }
-
- if (mode & MA_STR_SURFDIFF) {
- const float *surfnor = RE_vlakren_get_surfnor(obr, shi->vlr, 0);
-
- if (surfnor) {
- copy_v3_v3(shi->surfnor, surfnor);
- if (obi->flag & R_TRANSFORMED)
- mul_m3_v3(obi->nmat, shi->surfnor);
- }
- else
- copy_v3_v3(shi->surfnor, shi->vn);
-
- shi->surfdist = 0.0f;
- }
-
- if (R.r.mode & R_SPEED) {
- const float *s1, *s2, *s3;
-
- s1 = RE_vertren_get_winspeed(obi, v1, 0);
- s2 = RE_vertren_get_winspeed(obi, v2, 0);
- s3 = RE_vertren_get_winspeed(obi, v3, 0);
- if (s1 && s2 && s3) {
- shi->winspeed[0] = (l * s3[0] - u * s1[0] - v * s2[0]);
- shi->winspeed[1] = (l * s3[1] - u * s1[1] - v * s2[1]);
- shi->winspeed[2] = (l * s3[2] - u * s1[2] - v * s2[2]);
- shi->winspeed[3] = (l * s3[3] - u * s1[3] - v * s2[3]);
- }
- else {
- shi->winspeed[0] = shi->winspeed[1] = shi->winspeed[2] = shi->winspeed[3] = 0.0f;
- }
- }
-
- /* pass option forces UV calc */
- if ((shi->passflag & SCE_PASS_UV) || (R.flag & R_NEED_VCOL))
- texco |= (NEED_UV | TEXCO_UV);
-
- /* texture coordinates. shi->dxuv shi->dyuv have been set */
- if (texco & NEED_UV) {
-
- if (texco & TEXCO_ORCO) {
- if (v1->orco) {
- const float *o1, *o2, *o3;
-
- o1 = v1->orco;
- o2 = v2->orco;
- o3 = v3->orco;
-
- shi->lo[0] = l * o3[0] - u * o1[0] - v * o2[0];
- shi->lo[1] = l * o3[1] - u * o1[1] - v * o2[1];
- shi->lo[2] = l * o3[2] - u * o1[2] - v * o2[2];
-
- if (shi->osatex) {
- dl = shi->dx_u + shi->dx_v;
- shi->dxlo[0] = dl * o3[0] - shi->dx_u * o1[0] - shi->dx_v * o2[0];
- shi->dxlo[1] = dl * o3[1] - shi->dx_u * o1[1] - shi->dx_v * o2[1];
- shi->dxlo[2] = dl * o3[2] - shi->dx_u * o1[2] - shi->dx_v * o2[2];
- dl = shi->dy_u + shi->dy_v;
- shi->dylo[0] = dl * o3[0] - shi->dy_u * o1[0] - shi->dy_v * o2[0];
- shi->dylo[1] = dl * o3[1] - shi->dy_u * o1[1] - shi->dy_v * o2[1];
- shi->dylo[2] = dl * o3[2] - shi->dy_u * o1[2] - shi->dy_v * o2[2];
- }
- }
-
- copy_v3_v3(shi->duplilo, obi->dupliorco);
- }
-
- if (texco & TEXCO_GLOB) {
- copy_v3_v3(shi->gl, shi->co);
- mul_m4_v3(R.viewinv, shi->gl);
- if (shi->osatex) {
- copy_v3_v3(shi->dxgl, shi->dxco);
- mul_mat3_m4_v3(R.viewinv, shi->dxgl);
- copy_v3_v3(shi->dygl, shi->dyco);
- mul_mat3_m4_v3(R.viewinv, shi->dygl);
- }
- }
-
- if (texco & TEXCO_STRAND) {
- shi->strandco = (l * v3->accum - u * v1->accum - v * v2->accum);
- if (shi->osatex) {
- dl = shi->dx_u + shi->dx_v;
- shi->dxstrand = dl * v3->accum - shi->dx_u * v1->accum - shi->dx_v * v2->accum;
- dl = shi->dy_u + shi->dy_v;
- shi->dystrand = dl * v3->accum - shi->dy_u * v1->accum - shi->dy_v * v2->accum;
- }
- }
-
- if ((texco & TEXCO_UV) || (mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) || (R.flag & R_NEED_VCOL)) {
- VlakRen *vlr = shi->vlr;
- MTFace *tface;
- MCol *mcol;
- char *name;
- int i, j1 = shi->i1, j2 = shi->i2, j3 = shi->i3;
-
- /* uv and vcols are not copied on split, so set them according vlr divide flag */
- vlr_set_uv_indices(vlr, &j1, &j2, &j3);
-
- shi->totuv = 0;
- shi->totcol = 0;
- shi->actuv = obr->actmtface;
- shi->actcol = obr->actmcol;
-
- if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) || (R.flag & R_NEED_VCOL)) {
- for (i = 0; (mcol = RE_vlakren_get_mcol(obr, vlr, i, &name, 0)); i++) {
- ShadeInputCol *scol = &shi->col[i];
- const char *cp1, *cp2, *cp3;
- float a[3];
-
- shi->totcol++;
- scol->name = name;
-
- cp1 = (char *)(mcol + j1);
- cp2 = (char *)(mcol + j2);
- cp3 = (char *)(mcol + j3);
-
- /* alpha values */
- a[0] = ((float)cp1[0]) / 255.f;
- a[1] = ((float)cp2[0]) / 255.f;
- a[2] = ((float)cp3[0]) / 255.f;
- scol->col[3] = l * a[2] - u * a[0] - v * a[1];
-
- /* sample premultiplied color value */
- scol->col[0] = (l * ((float)cp3[3]) * a[2] - u * ((float)cp1[3]) * a[0] - v * ((float)cp2[3]) * a[1]) / 255.f;
- scol->col[1] = (l * ((float)cp3[2]) * a[2] - u * ((float)cp1[2]) * a[0] - v * ((float)cp2[2]) * a[1]) / 255.f;
- scol->col[2] = (l * ((float)cp3[1]) * a[2] - u * ((float)cp1[1]) * a[0] - v * ((float)cp2[1]) * a[1]) / 255.f;
-
- /* if not zero alpha, restore non-multiplied color */
- if (scol->col[3]) {
- mul_v3_fl(scol->col, 1.0f / scol->col[3]);
- }
- }
-
- if (shi->totcol) {
- shi->vcol[0] = shi->col[shi->actcol].col[0];
- shi->vcol[1] = shi->col[shi->actcol].col[1];
- shi->vcol[2] = shi->col[shi->actcol].col[2];
- shi->vcol[3] = shi->col[shi->actcol].col[3];
- }
- else {
- shi->vcol[0] = 0.0f;
- shi->vcol[1] = 0.0f;
- shi->vcol[2] = 0.0f;
- shi->vcol[3] = 1.0f;
- }
- }
-
- for (i = 0; (tface = RE_vlakren_get_tface(obr, vlr, i, &name, 0)); i++) {
- ShadeInputUV *suv = &shi->uv[i];
- const float *uv1 = tface->uv[j1];
- const float *uv2 = tface->uv[j2];
- const float *uv3 = tface->uv[j3];
-
- shi->totuv++;
- suv->name = name;
-
- if ((shi->mat->mapflag & MA_MAPFLAG_UVPROJECT) && (shi->depth == 0)) {
- float x = shi->xs;
- float y = shi->ys;
-
- float s1[2] = {-1.0f + 2.0f * uv1[0], -1.0f + 2.0f * uv1[1]};
- float s2[2] = {-1.0f + 2.0f * uv2[0], -1.0f + 2.0f * uv2[1]};
- float s3[2] = {-1.0f + 2.0f * uv3[0], -1.0f + 2.0f * uv3[1]};
-
-
- float obwinmat[4][4], winmat[4][4], ho1[4], ho2[4], ho3[4];
- float Zmulx, Zmuly;
- float hox, hoy, l_proj, dl_proj, u_proj, v_proj;
- float s00, s01, s10, s11, detsh;
-
- /* old globals, localized now */
- Zmulx = ((float)R.winx) / 2.0f;
- Zmuly = ((float)R.winy) / 2.0f;
-
- zbuf_make_winmat(&R, winmat);
- if (shi->obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(obwinmat, winmat, obi->mat);
- else
- copy_m4_m4(obwinmat, winmat);
-
- zbuf_render_project(obwinmat, v1->co, ho1);
- zbuf_render_project(obwinmat, v2->co, ho2);
- zbuf_render_project(obwinmat, v3->co, ho3);
-
- s00 = ho3[0] / ho3[3] - ho1[0] / ho1[3];
- s01 = ho3[1] / ho3[3] - ho1[1] / ho1[3];
- s10 = ho3[0] / ho3[3] - ho2[0] / ho2[3];
- s11 = ho3[1] / ho3[3] - ho2[1] / ho2[3];
-
- detsh = s00 * s11 - s10 * s01;
- detsh = (detsh != 0.0f) ? 1.0f / detsh : 0.0f;
- s00 *= detsh; s01 *= detsh;
- s10 *= detsh; s11 *= detsh;
-
- /* recalc u and v again */
- hox = x / Zmulx - 1.0f;
- hoy = y / Zmuly - 1.0f;
- u_proj = (hox - ho3[0] / ho3[3]) * s11 - (hoy - ho3[1] / ho3[3]) * s10;
- v_proj = (hoy - ho3[1] / ho3[3]) * s00 - (hox - ho3[0] / ho3[3]) * s01;
- l_proj = 1.0f + u_proj + v_proj;
-
- suv->uv[0] = l_proj * s3[0] - u_proj * s1[0] - v_proj * s2[0];
- suv->uv[1] = l_proj * s3[1] - u_proj * s1[1] - v_proj * s2[1];
- suv->uv[2] = 0.0f;
-
- if (shi->osatex) {
- float dxuv[2], dyuv[2];
- dxuv[0] = s11 / Zmulx;
- dxuv[1] = -s01 / Zmulx;
- dyuv[0] = -s10 / Zmuly;
- dyuv[1] = s00 / Zmuly;
-
- dl_proj = dxuv[0] + dxuv[1];
- suv->dxuv[0] = dl_proj * s3[0] - dxuv[0] * s1[0] - dxuv[1] * s2[0];
- suv->dxuv[1] = dl_proj * s3[1] - dxuv[0] * s1[1] - dxuv[1] * s2[1];
- dl_proj = dyuv[0] + dyuv[1];
- suv->dyuv[0] = dl_proj * s3[0] - dyuv[0] * s1[0] - dyuv[1] * s2[0];
- suv->dyuv[1] = dl_proj * s3[1] - dyuv[0] * s1[1] - dyuv[1] * s2[1];
- }
- }
- else {
-
- suv->uv[0] = -1.0f + 2.0f * (l * uv3[0] - u * uv1[0] - v * uv2[0]);
- suv->uv[1] = -1.0f + 2.0f * (l * uv3[1] - u * uv1[1] - v * uv2[1]);
- suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */
-
- if (shi->osatex) {
- float duv[2];
-
- dl = shi->dx_u + shi->dx_v;
- duv[0] = shi->dx_u;
- duv[1] = shi->dx_v;
-
- suv->dxuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]);
- suv->dxuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]);
-
- dl = shi->dy_u + shi->dy_v;
- duv[0] = shi->dy_u;
- duv[1] = shi->dy_v;
-
- suv->dyuv[0] = 2.0f * (dl * uv3[0] - duv[0] * uv1[0] - duv[1] * uv2[0]);
- suv->dyuv[1] = 2.0f * (dl * uv3[1] - duv[0] * uv1[1] - duv[1] * uv2[1]);
- }
-
- if ((mode & MA_FACETEXTURE) && i == obr->actmtface) {
- if (((mode & (MA_VERTEXCOL | MA_VERTEXCOLP)) == 0) && ((R.flag & R_NEED_VCOL) == 0)) {
- shi->vcol[0] = 1.0f;
- shi->vcol[1] = 1.0f;
- shi->vcol[2] = 1.0f;
- shi->vcol[3] = 1.0f;
- }
- if (tface->tpage) {
- render_realtime_texture(shi, tface->tpage);
- }
- }
- }
- }
-
- shi->dupliuv[0] = -1.0f + 2.0f * obi->dupliuv[0];
- shi->dupliuv[1] = -1.0f + 2.0f * obi->dupliuv[1];
- shi->dupliuv[2] = 0.0f;
-
- if (shi->totuv == 0) {
- ShadeInputUV *suv = &shi->uv[0];
-
- suv->uv[0] = 2.0f * (u + .5f);
- suv->uv[1] = 2.0f * (v + .5f);
- suv->uv[2] = 0.0f; /* texture.c assumes there are 3 coords */
-
- if (mode & MA_FACETEXTURE) {
- /* no tface? set at 1.0f */
- shi->vcol[0] = 1.0f;
- shi->vcol[1] = 1.0f;
- shi->vcol[2] = 1.0f;
- shi->vcol[3] = 1.0f;
- }
- }
- }
-
- if (texco & TEXCO_NORM) {
- shi->orn[0] = -shi->vn[0];
- shi->orn[1] = -shi->vn[1];
- shi->orn[2] = -shi->vn[2];
- }
-
- if (texco & TEXCO_STRESS) {
- const float *s1, *s2, *s3;
-
- s1 = RE_vertren_get_stress(obr, v1, 0);
- s2 = RE_vertren_get_stress(obr, v2, 0);
- s3 = RE_vertren_get_stress(obr, v3, 0);
- if (s1 && s2 && s3) {
- shi->stress = l * s3[0] - u * s1[0] - v * s2[0];
- if (shi->stress < 1.0f) shi->stress -= 1.0f;
- else shi->stress = (shi->stress - 1.0f) / shi->stress;
- }
- else shi->stress = 0.0f;
- }
-
- if (texco & TEXCO_TANGENT) {
- if ((mode & MA_TANGENT_V) == 0) {
- /* just prevent surprises */
- shi->tang[0] = shi->tang[1] = shi->tang[2] = 0.0f;
- shi->nmaptang[0] = shi->nmaptang[1] = shi->nmaptang[2] = 0.0f;
- }
- }
- }
-
- /* this only avalailable for scanline renders */
- if (shi->depth == 0) {
- float x = shi->xs;
- float y = shi->ys;
-
- if (texco & TEXCO_WINDOW) {
- shi->winco[0] = -1.0f + 2.0f * x / (float)R.winx;
- shi->winco[1] = -1.0f + 2.0f * y / (float)R.winy;
- shi->winco[2] = 0.0f;
- if (shi->osatex) {
- shi->dxwin[0] = 2.0f / (float)R.winx;
- shi->dywin[1] = 2.0f / (float)R.winy;
- shi->dxwin[1] = shi->dxwin[2] = 0.0f;
- shi->dywin[0] = shi->dywin[2] = 0.0f;
- }
- }
- }
- /* else {
- * Note! For raytracing winco is not set,
- * important because thus means all shader input's need to have their variables set to zero
- * else un-initialized values are used
- */
- if (shi->do_manage) {
- if ((mode & (MA_VERTEXCOL | MA_VERTEXCOLP | MA_FACETEXTURE)) || (R.flag & R_NEED_VCOL)) {
- srgb_to_linearrgb_v3_v3(shi->vcol, shi->vcol);
- }
- }
-
-}
-
-/* ****************** ShadeSample ************************************** */
-
-/* initialize per part, not per pixel! */
-void shade_input_initialize(ShadeInput *shi, RenderPart *pa, RenderLayer *rl, int sample)
-{
-
- memset(shi, 0, sizeof(ShadeInput));
-
- shi->sample = sample;
- shi->thread = pa->thread;
- shi->do_preview = (R.r.scemode & R_MATNODE_PREVIEW) != 0;
-
- shi->do_manage = BKE_scene_check_color_management_enabled(R.scene);
- shi->use_world_space_shading = BKE_scene_use_world_space_shading(R.scene);
-
- shi->lay = rl->lay;
- shi->layflag = rl->layflag;
- shi->passflag = rl->passflag;
- shi->combinedflag = ~rl->pass_xor;
- shi->mat_override = rl->mat_override;
- shi->light_override = rl->light_override;
-// shi->rl= rl;
- /* note shi.depth==0 means first hit, not raytracing */
-
-}
-
-/* initialize per part, not per pixel! */
-void shade_sample_initialize(ShadeSample *ssamp, RenderPart *pa, RenderLayer *rl)
-{
- int a, tot;
-
- tot = R.osa == 0 ? 1 : R.osa;
-
- for (a = 0; a < tot; a++) {
- shade_input_initialize(&ssamp->shi[a], pa, rl, a);
- memset(&ssamp->shr[a], 0, sizeof(ShadeResult));
- }
-
- get_sample_layers(pa, rl, ssamp->rlpp);
-}
-
-/* Do AO or (future) GI */
-void shade_samples_do_AO(ShadeSample *ssamp)
-{
- if (!(R.r.mode & R_SHADOW))
- return;
- if (!(R.r.mode & R_RAYTRACE) && !(R.wrld.ao_gather_method == WO_AOGATHER_APPROX))
- return;
-
- if (R.wrld.mode & (WO_AMB_OCC | WO_ENV_LIGHT | WO_INDIRECT_LIGHT)) {
- ShadeInput *shi = &ssamp->shi[0];
- int sample;
-
- if (((shi->passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO | SCE_PASS_ENVIRONMENT | SCE_PASS_INDIRECT))) ||
- (shi->passflag & (SCE_PASS_AO | SCE_PASS_ENVIRONMENT | SCE_PASS_INDIRECT)))
- {
- for (sample = 0; sample < ssamp->tot; shi++, sample++)
- if (!(shi->mode & MA_SHLESS))
- ambient_occlusion(shi); /* stores in shi->ao[] */
- }
- }
-}
-
-
-void shade_samples_fill_with_ps(ShadeSample *ssamp, PixStr *ps, int x, int y)
-{
- ShadeInput *shi;
- float xs, ys;
-
- ssamp->tot = 0;
-
- for (shi = ssamp->shi; ps; ps = ps->next) {
- shade_input_set_triangle(shi, ps->obi, ps->facenr, 1);
-
- if (shi->vlr) { /* NULL happens for env material or for 'all z' */
- unsigned short curmask = ps->mask;
-
- /* full osa is only set for OSA renders */
- if (shi->vlr->flag & R_FULL_OSA) {
- short shi_cp = 0, samp;
-
- for (samp = 0; samp < R.osa; samp++) {
- if (curmask & (1 << samp)) {
- /* zbuffer has this inverse corrected, ensures xs,ys are inside pixel */
- xs = (float)x + R.jit[samp][0] + 0.5f;
- ys = (float)y + R.jit[samp][1] + 0.5f;
-
- if (shi_cp)
- shade_input_copy_triangle(shi, shi - 1);
-
- shi->mask = (1 << samp);
-// shi->rl= ssamp->rlpp[samp];
- shi->samplenr = R.shadowsamplenr[shi->thread]++; /* this counter is not being reset per pixel */
- shade_input_set_viewco(shi, x, y, xs, ys, (float)ps->z);
- shade_input_set_uv(shi);
- if (shi_cp == 0)
- shade_input_set_normals(shi);
- else /* XXX shi->flippednor messes up otherwise */
- shade_input_set_vertex_normals(shi);
-
- shi_cp = 1;
- shi++;
- }
- }
- }
- else {
- if (R.osa) {
- short b = R.samples->centmask[curmask];
- xs = (float)x + R.samples->centLut[b & 15] + 0.5f;
- ys = (float)y + R.samples->centLut[b >> 4] + 0.5f;
- }
- else if (R.i.curblur) {
- xs= (float)x + R.mblur_jit[R.i.curblur-1][0] + 0.5f;
- ys= (float)y + R.mblur_jit[R.i.curblur-1][1] + 0.5f;
- }
- else {
- xs = (float)x + 0.5f;
- ys = (float)y + 0.5f;
- }
-
- shi->mask = curmask;
- shi->samplenr = R.shadowsamplenr[shi->thread]++;
- shade_input_set_viewco(shi, x, y, xs, ys, (float)ps->z);
- shade_input_set_uv(shi);
- shade_input_set_normals(shi);
- shi++;
- }
-
- /* total sample amount, shi->sample is static set in initialize */
- if (shi != ssamp->shi)
- ssamp->tot = (shi - 1)->sample + 1;
- }
- }
-}
-
-/* shades samples, returns true if anything happened */
-int shade_samples(ShadeSample *ssamp, PixStr *ps, int x, int y)
-{
- shade_samples_fill_with_ps(ssamp, ps, x, y);
-
- if (ssamp->tot) {
- ShadeInput *shi = ssamp->shi;
- ShadeResult *shr = ssamp->shr;
- int samp;
-
- /* if shadow or AO? */
- shade_samples_do_AO(ssamp);
-
- /* if shade (all shadepinputs have same passflag) */
- if (ssamp->shi[0].passflag & ~(SCE_PASS_Z | SCE_PASS_INDEXOB | SCE_PASS_INDEXMA)) {
-
- for (samp = 0; samp < ssamp->tot; samp++, shi++, shr++) {
- shade_input_set_shade_texco(shi);
- shade_input_do_shade(shi, shr);
- }
- }
- else if (shi->passflag & SCE_PASS_Z) {
- for (samp = 0; samp < ssamp->tot; samp++, shi++, shr++)
- shr->z = -shi->co[2];
- }
-
- return 1;
- }
- return 0;
-}
-
diff --git a/source/blender/render/intern/source/shadeoutput.c b/source/blender/render/intern/source/shadeoutput.c
deleted file mode 100644
index 83827067775..00000000000
--- a/source/blender/render/intern/source/shadeoutput.c
+++ /dev/null
@@ -1,2182 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2006 Blender Foundation
- * All rights reserved.
- *
- * Contributors: Hos, Robert Wenzlaff.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/shadeoutput.c
- * \ingroup render
- */
-
-#include <stdio.h>
-#include <float.h>
-#include <math.h>
-#include <string.h>
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "BKE_colorband.h"
-#include "BKE_colortools.h"
-#include "BKE_material.h"
-
-#include "DNA_group_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_material_types.h"
-
-/* local include */
-#include "occlusion.h"
-#include "render_types.h"
-#include "rendercore.h"
-#include "shadbuf.h"
-#include "sss.h"
-#include "texture.h"
-
-#include "shading.h" /* own include */
-
-#include "IMB_colormanagement.h"
-
-/* could enable at some point but for now there are far too many conversions */
-#ifdef __GNUC__
-# pragma GCC diagnostic ignored "-Wdouble-promotion"
-#endif
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-ListBase *get_lights(ShadeInput *shi)
-{
-
- if (R.r.scemode & R_BUTS_PREVIEW)
- return &R.lights;
- if (shi->light_override)
- return &shi->light_override->gobject;
- if (shi->mat && shi->mat->group)
- return &shi->mat->group->gobject;
-
- return &R.lights;
-}
-
-#if 0
-static void fogcolor(const float colf[3], float *rco, float *view)
-{
- float alpha, stepsize, startdist, dist, hor[4], zen[3], vec[3], dview[3];
- float div=0.0f, distfac;
-
- hor[0]= R.wrld.horr; hor[1]= R.wrld.horg; hor[2]= R.wrld.horb;
- zen[0]= R.wrld.zenr; zen[1]= R.wrld.zeng; zen[2]= R.wrld.zenb;
-
- copy_v3_v3(vec, rco);
-
- /* we loop from cur coord to mist start in steps */
- stepsize= 1.0f;
-
- div= ABS(view[2]);
- dview[0]= view[0]/(stepsize*div);
- dview[1]= view[1]/(stepsize*div);
- dview[2]= -stepsize;
-
- startdist= -rco[2] + BLI_frand();
- for (dist= startdist; dist>R.wrld.miststa; dist-= stepsize) {
-
- hor[0]= R.wrld.horr; hor[1]= R.wrld.horg; hor[2]= R.wrld.horb;
- alpha= 1.0f;
- do_sky_tex(vec, vec, NULL, hor, zen, &alpha);
-
- distfac= (dist-R.wrld.miststa)/R.wrld.mistdist;
-
- hor[3]= hor[0]*distfac*distfac;
-
- /* premul! */
- alpha= hor[3];
- hor[0]= hor[0]*alpha;
- hor[1]= hor[1]*alpha;
- hor[2]= hor[2]*alpha;
- addAlphaOverFloat(colf, hor);
-
- sub_v3_v3(vec, dview);
- }
-}
-#endif
-
-/* zcor is distance, co the 3d coordinate in eye space, return alpha */
-float mistfactor(float zcor, float const co[3])
-{
- float fac, hi;
-
- fac = zcor - R.wrld.miststa; /* zcor is calculated per pixel */
-
- /* fac= -co[2]-R.wrld.miststa; */
-
- if (fac > 0.0f) {
- if (fac < R.wrld.mistdist) {
-
- fac = (fac / R.wrld.mistdist);
-
- if (R.wrld.mistype == 0) {
- fac *= fac;
- }
- else if (R.wrld.mistype == 1) {
- /* pass */
- }
- else {
- fac = sqrtf(fac);
- }
- }
- else {
- fac = 1.0f;
- }
- }
- else {
- fac = 0.0f;
- }
-
- /* height switched off mist */
- if (R.wrld.misthi!=0.0f && fac!=0.0f) {
- /* at height misthi the mist is completely gone */
-
- hi = R.viewinv[0][2] * co[0] +
- R.viewinv[1][2] * co[1] +
- R.viewinv[2][2] * co[2] +
- R.viewinv[3][2];
-
- if (hi > R.wrld.misthi) {
- fac = 0.0f;
- }
- else if (hi>0.0f) {
- hi= (R.wrld.misthi-hi)/R.wrld.misthi;
- fac*= hi*hi;
- }
- }
-
- return (1.0f-fac)* (1.0f-R.wrld.misi);
-}
-
-static void spothalo(struct LampRen *lar, ShadeInput *shi, float *intens)
-{
- double a, b, c, disc, nray[3], npos[3];
- double t0, t1 = 0.0f, t2= 0.0f, t3;
- float p1[3], p2[3], ladist, maxz = 0.0f, maxy = 0.0f, haint;
- int cuts;
- bool do_clip = true, use_yco = false;
-
- *intens= 0.0f;
- haint= lar->haint;
-
- if (R.r.mode & R_ORTHO) {
- /* camera pos (view vector) cannot be used... */
- /* camera position (cox,coy,0) rotate around lamp */
- p1[0]= shi->co[0]-lar->co[0];
- p1[1]= shi->co[1]-lar->co[1];
- p1[2]= -lar->co[2];
- mul_m3_v3(lar->imat, p1);
- copy_v3db_v3fl(npos, p1); /* npos is double! */
-
- /* pre-scale */
- npos[2] *= (double)lar->sh_zfac;
- }
- else {
- copy_v3db_v3fl(npos, lar->sh_invcampos); /* in initlamp calculated */
- }
-
- /* rotate view */
- copy_v3db_v3fl(nray, shi->view);
- mul_m3_v3_double(lar->imat, nray);
-
- if (R.wrld.mode & WO_MIST) {
- /* patchy... */
- haint *= mistfactor(-lar->co[2], lar->co);
- if (haint==0.0f) {
- return;
- }
- }
-
-
- /* rotate maxz */
- if (shi->co[2]==0.0f) {
- do_clip = false; /* for when halo at sky */
- }
- else {
- p1[0]= shi->co[0]-lar->co[0];
- p1[1]= shi->co[1]-lar->co[1];
- p1[2]= shi->co[2]-lar->co[2];
-
- maxz= lar->imat[0][2]*p1[0]+lar->imat[1][2]*p1[1]+lar->imat[2][2]*p1[2];
- maxz*= lar->sh_zfac;
- maxy= lar->imat[0][1]*p1[0]+lar->imat[1][1]*p1[1]+lar->imat[2][1]*p1[2];
-
- if (fabs(nray[2]) < FLT_EPSILON) {
- use_yco = true;
- }
- }
-
- /* scale z to make sure volume is normalized */
- nray[2] *= (double)lar->sh_zfac;
- /* nray does not need normalization */
-
- ladist= lar->sh_zfac*lar->dist;
-
- /* solve */
- a = nray[0] * nray[0] + nray[1] * nray[1] - nray[2]*nray[2];
- b = nray[0] * npos[0] + nray[1] * npos[1] - nray[2]*npos[2];
- c = npos[0] * npos[0] + npos[1] * npos[1] - npos[2]*npos[2];
-
- cuts= 0;
- if (fabs(a) < DBL_EPSILON) {
- /*
- * Only one intersection point...
- */
- return;
- }
- else {
- disc = b*b - a*c;
-
- if (disc==0.0) {
- t1=t2= (-b)/ a;
- cuts= 2;
- }
- else if (disc > 0.0) {
- disc = sqrt(disc);
- t1 = (-b + disc) / a;
- t2 = (-b - disc) / a;
- cuts= 2;
- }
- }
- if (cuts==2) {
- int ok1=0, ok2=0;
-
- /* sort */
- if (t1>t2) {
- a= t1; t1= t2; t2= a;
- }
-
- /* z of intersection points with diabolo */
- p1[2]= npos[2] + t1*nray[2];
- p2[2]= npos[2] + t2*nray[2];
-
- /* evaluate both points */
- if (p1[2]<=0.0f) ok1= 1;
- if (p2[2]<=0.0f && t1!=t2) ok2= 1;
-
- /* at least 1 point with negative z */
- if (ok1==0 && ok2==0) return;
-
- /* intersction point with -ladist, the bottom of the cone */
- if (use_yco == false) {
- t3= ((double)(-ladist)-npos[2])/nray[2];
-
- /* de we have to replace one of the intersection points? */
- if (ok1) {
- if (p1[2]<-ladist) t1= t3;
- }
- else {
- t1= t3;
- }
- if (ok2) {
- if (p2[2]<-ladist) t2= t3;
- }
- else {
- t2= t3;
- }
- }
- else if (ok1==0 || ok2==0) return;
-
- /* at least 1 visible interesction point */
- if (t1<0.0 && t2<0.0) return;
-
- if (t1<0.0) t1= 0.0;
- if (t2<0.0) t2= 0.0;
-
- if (t1==t2) return;
-
- /* sort again to be sure */
- if (t1>t2) {
- a= t1; t1= t2; t2= a;
- }
-
- /* calculate t0: is the maximum visible z (when halo is intersected by face) */
- if (do_clip) {
- if (use_yco == false) t0 = ((double)maxz - npos[2]) / nray[2];
- else t0 = ((double)maxy - npos[1]) / nray[1];
-
- if (t0 < t1) return;
- if (t0 < t2) t2= t0;
- }
-
- /* calc points */
- p1[0]= npos[0] + t1*nray[0];
- p1[1]= npos[1] + t1*nray[1];
- p1[2]= npos[2] + t1*nray[2];
- p2[0]= npos[0] + t2*nray[0];
- p2[1]= npos[1] + t2*nray[1];
- p2[2]= npos[2] + t2*nray[2];
-
-
- /* now we have 2 points, make three lengths with it */
-
- a = len_v3(p1);
- b = len_v3(p2);
- c = len_v3v3(p1, p2);
-
- a/= ladist;
- a= sqrt(a);
- b/= ladist;
- b= sqrt(b);
- c/= ladist;
-
- *intens= c*( (1.0-a)+(1.0-b) );
-
- /* WATCH IT: do not clip a,b en c at 1.0, this gives nasty little overflows
- * at the edges (especially with narrow halos) */
- if (*intens<=0.0f) return;
-
- /* soft area */
- /* not needed because t0 has been used for p1/p2 as well */
- /* if (doclip && t0<t2) { */
- /* *intens *= (t0-t1)/(t2-t1); */
- /* } */
-
- *intens *= haint;
-
- if (lar->shb && lar->shb->shadhalostep) {
- *intens *= shadow_halo(lar, p1, p2);
- }
-
- }
-}
-
-void renderspothalo(ShadeInput *shi, float col[4], float alpha)
-{
- ListBase *lights;
- GroupObject *go;
- LampRen *lar;
- float i;
-
- if (alpha==0.0f) return;
-
- lights= get_lights(shi);
- for (go=lights->first; go; go= go->next) {
- lar= go->lampren;
- if (lar==NULL) continue;
-
- if (lar->type==LA_SPOT && (lar->mode & LA_HALO) && (lar->buftype != LA_SHADBUF_DEEP) && lar->haint>0) {
-
- if (lar->mode & LA_LAYER)
- if (shi->vlr && (lar->lay & shi->obi->lay)==0)
- continue;
- if ((lar->lay & shi->lay)==0)
- continue;
-
- spothalo(lar, shi, &i);
- if (i > 0.0f) {
- const float i_alpha = i * alpha;
- col[0] += i_alpha * lar->r;
- col[1] += i_alpha * lar->g;
- col[2] += i_alpha * lar->b;
- col[3] += i_alpha; /* all premul */
- }
- }
- }
- /* clip alpha, is needed for unified 'alpha threshold' (vanillaRenderPipe.c) */
- if (col[3]>1.0f) col[3]= 1.0f;
-}
-
-
-
-/* ---------------- shaders ----------------------- */
-
-static double Normalize_d(double *n)
-{
- double d;
-
- d= n[0]*n[0]+n[1]*n[1]+n[2]*n[2];
-
- if (d>0.00000000000000001) {
- d= sqrt(d);
-
- n[0]/=d;
- n[1]/=d;
- n[2]/=d;
- }
- else {
- n[0]=n[1]=n[2]= 0.0;
- d= 0.0;
- }
- return d;
-}
-
-/* mix of 'real' fresnel and allowing control. grad defines blending gradient */
-float fresnel_fac(const float view[3], const float vn[3], float grad, float fac)
-{
- float t1, t2;
-
- if (fac==0.0f) return 1.0f;
-
- t1 = dot_v3v3(view, vn);
- if (t1>0.0f) t2= 1.0f+t1;
- else t2= 1.0f-t1;
-
- t2= grad + (1.0f-grad)*powf(t2, fac);
-
- if (t2<0.0f) return 0.0f;
- else if (t2>1.0f) return 1.0f;
- return t2;
-}
-
-static double saacos_d(double fac)
-{
- if (fac<= -1.0) return M_PI;
- else if (fac>=1.0) return 0.0;
- else return acos(fac);
-}
-
-/* Stoke's form factor. Need doubles here for extreme small area sizes */
-static float area_lamp_energy(float (*area)[3], const float co[3], const float vn[3])
-{
- double fac;
- double vec[4][3]; /* vectors of rendered co to vertices lamp */
- double cross[4][3]; /* cross products of this */
- double rad[4]; /* angles between vecs */
-
- VECSUB(vec[0], co, area[0]);
- VECSUB(vec[1], co, area[1]);
- VECSUB(vec[2], co, area[2]);
- VECSUB(vec[3], co, area[3]);
-
- Normalize_d(vec[0]);
- Normalize_d(vec[1]);
- Normalize_d(vec[2]);
- Normalize_d(vec[3]);
-
- /* cross product */
-#define CROSS(dest, a, b) \
- { \
- dest[0]= a[1] * b[2] - a[2] * b[1]; \
- dest[1]= a[2] * b[0] - a[0] * b[2]; \
- dest[2]= a[0] * b[1] - a[1] * b[0]; \
- } (void)0
-
- CROSS(cross[0], vec[0], vec[1]);
- CROSS(cross[1], vec[1], vec[2]);
- CROSS(cross[2], vec[2], vec[3]);
- CROSS(cross[3], vec[3], vec[0]);
-
-#undef CROSS
-
- Normalize_d(cross[0]);
- Normalize_d(cross[1]);
- Normalize_d(cross[2]);
- Normalize_d(cross[3]);
-
- /* angles */
- rad[0]= vec[0][0]*vec[1][0]+ vec[0][1]*vec[1][1]+ vec[0][2]*vec[1][2];
- rad[1]= vec[1][0]*vec[2][0]+ vec[1][1]*vec[2][1]+ vec[1][2]*vec[2][2];
- rad[2]= vec[2][0]*vec[3][0]+ vec[2][1]*vec[3][1]+ vec[2][2]*vec[3][2];
- rad[3]= vec[3][0]*vec[0][0]+ vec[3][1]*vec[0][1]+ vec[3][2]*vec[0][2];
-
- rad[0]= saacos_d(rad[0]);
- rad[1]= saacos_d(rad[1]);
- rad[2]= saacos_d(rad[2]);
- rad[3]= saacos_d(rad[3]);
-
- /* Stoke formula */
- fac= rad[0]*(vn[0]*cross[0][0]+ vn[1]*cross[0][1]+ vn[2]*cross[0][2]);
- fac+= rad[1]*(vn[0]*cross[1][0]+ vn[1]*cross[1][1]+ vn[2]*cross[1][2]);
- fac+= rad[2]*(vn[0]*cross[2][0]+ vn[1]*cross[2][1]+ vn[2]*cross[2][2]);
- fac+= rad[3]*(vn[0]*cross[3][0]+ vn[1]*cross[3][1]+ vn[2]*cross[3][2]);
-
- if (fac<=0.0) return 0.0;
- return fac;
-}
-
-static float area_lamp_energy_multisample(LampRen *lar, const float co[3], float *vn)
-{
- /* corner vectors are moved around according lamp jitter */
- float *jitlamp= lar->jitter, vec[3];
- float area[4][3], intens= 0.0f;
- int a= lar->ray_totsamp;
-
- /* test if co is behind lamp */
- sub_v3_v3v3(vec, co, lar->co);
- if (dot_v3v3(vec, lar->vec) < 0.0f)
- return 0.0f;
-
- while (a--) {
- vec[0]= jitlamp[0];
- vec[1]= jitlamp[1];
- vec[2]= 0.0f;
- mul_m3_v3(lar->mat, vec);
-
- add_v3_v3v3(area[0], lar->area[0], vec);
- add_v3_v3v3(area[1], lar->area[1], vec);
- add_v3_v3v3(area[2], lar->area[2], vec);
- add_v3_v3v3(area[3], lar->area[3], vec);
-
- intens+= area_lamp_energy(area, co, vn);
-
- jitlamp+= 2;
- }
- intens /= (float)lar->ray_totsamp;
-
- return pow(intens * lar->areasize, lar->k); /* corrected for buttons size and lar->dist^2 */
-}
-
-static float spec(float inp, int hard)
-{
- float b1;
-
- if (inp>=1.0f) return 1.0f;
- else if (inp<=0.0f) return 0.0f;
-
- b1= inp*inp;
- /* avoid FPE */
- if (b1<0.01f) b1= 0.01f;
-
- if ((hard & 1)==0) inp= 1.0f;
- if (hard & 2) inp*= b1;
- b1*= b1;
- if (hard & 4) inp*= b1;
- b1*= b1;
- if (hard & 8) inp*= b1;
- b1*= b1;
- if (hard & 16) inp*= b1;
- b1*= b1;
-
- /* avoid FPE */
- if (b1<0.001f) b1= 0.0f;
-
- if (hard & 32) inp*= b1;
- b1*= b1;
- if (hard & 64) inp*=b1;
- b1*= b1;
- if (hard & 128) inp*=b1;
-
- if (b1<0.001f) b1= 0.0f;
-
- if (hard & 256) {
- b1*= b1;
- inp*=b1;
- }
-
- return inp;
-}
-
-static float Phong_Spec(const float n[3], const float l[3], const float v[3], int hard, int tangent )
-{
- float h[3];
- float rslt;
-
- h[0] = l[0] + v[0];
- h[1] = l[1] + v[1];
- h[2] = l[2] + v[2];
- normalize_v3(h);
-
- rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2];
- if (tangent) rslt= sasqrt(1.0f - rslt*rslt);
-
- if ( rslt > 0.0f ) rslt= spec(rslt, hard);
- else rslt = 0.0f;
-
- return rslt;
-}
-
-
-/* reduced cook torrance spec (for off-specular peak) */
-static float CookTorr_Spec(const float n[3], const float l[3], const float v[3], int hard, int tangent)
-{
- float i, nh, nv, h[3];
-
- h[0]= v[0]+l[0];
- h[1]= v[1]+l[1];
- h[2]= v[2]+l[2];
- normalize_v3(h);
-
- nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2];
- if (tangent) nh= sasqrt(1.0f - nh*nh);
- else if (nh<0.0f) return 0.0f;
-
- nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2];
- if (tangent) nv= sasqrt(1.0f - nv*nv);
- else if (nv<0.0f) nv= 0.0f;
-
- i= spec(nh, hard);
-
- i= i/(0.1f+nv);
- return i;
-}
-
-/* Blinn spec */
-static float Blinn_Spec(const float n[3], const float l[3], const float v[3], float refrac, float spec_power, int tangent)
-{
- float i, nh, nv, nl, vh, h[3];
- float a, b, c, g=0.0f, p, f, ang;
-
- if (refrac < 1.0f) return 0.0f;
- if (spec_power == 0.0f) return 0.0f;
-
- /* conversion from 'hardness' (1-255) to 'spec_power' (50 maps at 0.1) */
- if (spec_power<100.0f)
- spec_power = sqrtf(1.0f / spec_power);
- else spec_power= 10.0f/spec_power;
-
- h[0]= v[0]+l[0];
- h[1]= v[1]+l[1];
- h[2]= v[2]+l[2];
- normalize_v3(h);
-
- nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */
- if (tangent) nh= sasqrt(1.0f - nh*nh);
- else if (nh<0.0f) return 0.0f;
-
- nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */
- if (tangent) nv= sasqrt(1.0f - nv*nv);
- if (nv<=0.01f) nv= 0.01f; /* hrms... */
-
- nl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */
- if (tangent) nl= sasqrt(1.0f - nl*nl);
- if (nl<=0.01f) {
- return 0.0f;
- }
-
- vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; /* Dot product between view vector and half-way vector */
- if (vh<=0.0f) vh= 0.01f;
-
- a = 1.0f;
- b = (2.0f*nh*nv)/vh;
- c = (2.0f*nh*nl)/vh;
-
- if ( a < b && a < c ) g = a;
- else if ( b < a && b < c ) g = b;
- else if ( c < a && c < b ) g = c;
-
- p = sqrt((double)((refrac * refrac)+(vh * vh) - 1.0f));
- f = (((p-vh)*(p-vh))/((p+vh)*(p+vh)))*(1+((((vh*(p+vh))-1.0f)*((vh*(p+vh))-1.0f))/(((vh*(p-vh))+1.0f)*((vh*(p-vh))+1.0f))));
- ang = saacos(nh);
-
- i= f * g * exp((double)(-(ang*ang) / (2.0f*spec_power*spec_power)));
- if (i<0.0f) i= 0.0f;
-
- return i;
-}
-
-/* cartoon render spec */
-static float Toon_Spec(const float n[3], const float l[3], const float v[3], float size, float smooth, int tangent)
-{
- float h[3];
- float ang;
- float rslt;
-
- h[0] = l[0] + v[0];
- h[1] = l[1] + v[1];
- h[2] = l[2] + v[2];
- normalize_v3(h);
-
- rslt = h[0]*n[0] + h[1]*n[1] + h[2]*n[2];
- if (tangent) rslt = sasqrt(1.0f - rslt*rslt);
-
- ang = saacos( rslt );
-
- if ( ang < size ) rslt = 1.0f;
- else if ( ang >= (size + smooth) || smooth == 0.0f ) rslt = 0.0f;
- else rslt = 1.0f - ((ang - size) / smooth);
-
- return rslt;
-}
-
-/* Ward isotropic gaussian spec */
-static float WardIso_Spec(const float n[3], const float l[3], const float v[3], float rms, int tangent)
-{
- float i, nh, nv, nl, h[3], angle, alpha;
-
-
- /* half-way vector */
- h[0] = l[0] + v[0];
- h[1] = l[1] + v[1];
- h[2] = l[2] + v[2];
- normalize_v3(h);
-
- nh = n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; /* Dot product between surface normal and half-way vector */
- if (tangent) nh = sasqrt(1.0f - nh*nh);
- if (nh<=0.0f) nh = 0.001f;
-
- nv = n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */
- if (tangent) nv = sasqrt(1.0f - nv*nv);
- if (nv<=0.0f) nv = 0.001f;
-
- nl = n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */
- if (tangent) nl = sasqrt(1.0f - nl*nl);
- if (nl<=0.0f) nl = 0.001f;
-
- angle = tanf(saacos(nh));
- alpha = MAX2(rms, 0.001f);
-
- i= nl * (1.0f/(4.0f*(float)M_PI*alpha*alpha)) * (expf( -(angle*angle)/(alpha*alpha))/(sqrtf(nv*nl)));
-
- return i;
-}
-
-/* cartoon render diffuse */
-static float Toon_Diff(const float n[3], const float l[3], const float UNUSED(v[3]), float size, float smooth)
-{
- float rslt, ang;
-
- rslt = n[0]*l[0] + n[1]*l[1] + n[2]*l[2];
-
- ang = saacos(rslt);
-
- if ( ang < size ) rslt = 1.0f;
- else if ( ang >= (size + smooth) || smooth == 0.0f ) rslt = 0.0f;
- else rslt = 1.0f - ((ang - size) / smooth);
-
- return rslt;
-}
-
-/* Oren Nayar diffuse */
-
-/* 'nl' is either dot product, or return value of area light */
-/* in latter case, only last multiplication uses 'nl' */
-static float OrenNayar_Diff(float nl, const float n[3], const float l[3], const float v[3], float rough )
-{
- float i/*, nh*/, nv /*, vh */, realnl, h[3];
- float a, b, t, A, B;
- float Lit_A, View_A, Lit_B[3], View_B[3];
-
- h[0]= v[0]+l[0];
- h[1]= v[1]+l[1];
- h[2]= v[2]+l[2];
- normalize_v3(h);
-
- /* nh= n[0]*h[0]+n[1]*h[1]+n[2]*h[2]; */ /* Dot product between surface normal and half-way vector */
- /* if (nh<0.0f) nh = 0.0f; */
-
- nv= n[0]*v[0]+n[1]*v[1]+n[2]*v[2]; /* Dot product between surface normal and view vector */
- if (nv<=0.0f) nv= 0.0f;
-
- realnl= n[0]*l[0]+n[1]*l[1]+n[2]*l[2]; /* Dot product between surface normal and light vector */
- if (realnl<=0.0f) return 0.0f;
- if (nl<0.0f) return 0.0f; /* value from area light */
-
- /* vh= v[0]*h[0]+v[1]*h[1]+v[2]*h[2]; */ /* Dot product between view vector and halfway vector */
- /* if (vh<=0.0f) vh= 0.0f; */
-
- Lit_A = saacos(realnl);
- View_A = saacos( nv );
-
- Lit_B[0] = l[0] - (realnl * n[0]);
- Lit_B[1] = l[1] - (realnl * n[1]);
- Lit_B[2] = l[2] - (realnl * n[2]);
- normalize_v3(Lit_B);
-
- View_B[0] = v[0] - (nv * n[0]);
- View_B[1] = v[1] - (nv * n[1]);
- View_B[2] = v[2] - (nv * n[2]);
- normalize_v3(View_B);
-
- t = Lit_B[0]*View_B[0] + Lit_B[1]*View_B[1] + Lit_B[2]*View_B[2];
- if ( t < 0 ) t = 0;
-
- if ( Lit_A > View_A ) {
- a = Lit_A;
- b = View_A;
- }
- else {
- a = View_A;
- b = Lit_A;
- }
-
- A = 1.0f - (0.5f * ((rough * rough) / ((rough * rough) + 0.33f)));
- B = 0.45f * ((rough * rough) / ((rough * rough) + 0.09f));
-
- b*= 0.95f; /* prevent tangens from shooting to inf, 'nl' can be not a dot product here. */
- /* overflow only happens with extreme size area light, and higher roughness */
- i = nl * ( A + ( B * t * sinf(a) * tanf(b) ) );
-
- return i;
-}
-
-/* Minnaert diffuse */
-static float Minnaert_Diff(float nl, const float n[3], const float v[3], float darkness)
-{
- float i, nv;
-
- /* nl = dot product between surface normal and light vector */
- if (nl <= 0.0f)
- return 0.0f;
-
- /* nv = dot product between surface normal and view vector */
- nv = dot_v3v3(n, v);
- if (nv < 0.0f)
- nv = 0.0f;
-
- if (darkness <= 1.0f)
- i = nl * pow(max_ff(nv * nl, 0.1f), (darkness - 1.0f) ); /*The Real model*/
- else
- i = nl * pow( (1.001f - nv), (darkness - 1.0f) ); /*Nvidia model*/
-
- return i;
-}
-
-static float Fresnel_Diff(float *vn, float *lv, float *UNUSED(view), float fac_i, float fac)
-{
- return fresnel_fac(lv, vn, fac_i, fac);
-}
-
-/* --------------------------------------------- */
-/* also called from texture.c */
-void calc_R_ref(ShadeInput *shi)
-{
- float i;
-
- /* shi->vn dot shi->view */
- i= -2*(shi->vn[0]*shi->view[0]+shi->vn[1]*shi->view[1]+shi->vn[2]*shi->view[2]);
-
- shi->ref[0]= (shi->view[0]+i*shi->vn[0]);
- shi->ref[1]= (shi->view[1]+i*shi->vn[1]);
- shi->ref[2]= (shi->view[2]+i*shi->vn[2]);
- if (shi->osatex) {
- if (shi->vlr->flag & R_SMOOTH) {
- i= -2*( (shi->vn[0]+shi->dxno[0])*(shi->view[0]+shi->dxview) +
- (shi->vn[1]+shi->dxno[1])*shi->view[1]+ (shi->vn[2]+shi->dxno[2])*shi->view[2] );
-
- shi->dxref[0]= shi->ref[0]- ( shi->view[0]+shi->dxview+i*(shi->vn[0]+shi->dxno[0]));
- shi->dxref[1]= shi->ref[1]- (shi->view[1]+ i*(shi->vn[1]+shi->dxno[1]));
- shi->dxref[2]= shi->ref[2]- (shi->view[2]+ i*(shi->vn[2]+shi->dxno[2]));
-
- i= -2*( (shi->vn[0]+shi->dyno[0])*shi->view[0]+
- (shi->vn[1]+shi->dyno[1])*(shi->view[1]+shi->dyview)+ (shi->vn[2]+shi->dyno[2])*shi->view[2] );
-
- shi->dyref[0]= shi->ref[0]- (shi->view[0]+ i*(shi->vn[0]+shi->dyno[0]));
- shi->dyref[1]= shi->ref[1]- (shi->view[1]+shi->dyview+i*(shi->vn[1]+shi->dyno[1]));
- shi->dyref[2]= shi->ref[2]- (shi->view[2]+ i*(shi->vn[2]+shi->dyno[2]));
-
- }
- else {
-
- i= -2*( shi->vn[0]*(shi->view[0]+shi->dxview) +
- shi->vn[1]*shi->view[1]+ shi->vn[2]*shi->view[2] );
-
- shi->dxref[0]= shi->ref[0]- (shi->view[0]+shi->dxview+i*shi->vn[0]);
- shi->dxref[1]= shi->ref[1]- (shi->view[1]+ i*shi->vn[1]);
- shi->dxref[2]= shi->ref[2]- (shi->view[2]+ i*shi->vn[2]);
-
- i= -2*( shi->vn[0]*shi->view[0]+
- shi->vn[1]*(shi->view[1]+shi->dyview)+ shi->vn[2]*shi->view[2] );
-
- shi->dyref[0]= shi->ref[0]- (shi->view[0]+ i*shi->vn[0]);
- shi->dyref[1]= shi->ref[1]- (shi->view[1]+shi->dyview+i*shi->vn[1]);
- shi->dyref[2]= shi->ref[2]- (shi->view[2]+ i*shi->vn[2]);
- }
- }
-
-}
-
-/* called from rayshade.c */
-void shade_color(ShadeInput *shi, ShadeResult *shr)
-{
- Material *ma= shi->mat;
-
- if (ma->mode & (MA_FACETEXTURE)) {
- shi->r= shi->vcol[0];
- shi->g= shi->vcol[1];
- shi->b= shi->vcol[2];
- if (ma->mode & (MA_FACETEXTURE_ALPHA))
- shi->alpha= shi->vcol[3];
- }
- else if (ma->mode & (MA_VERTEXCOLP)) {
- float neg_alpha = 1.0f - shi->vcol[3];
- shi->r= shi->r*neg_alpha + shi->vcol[0]*shi->vcol[3];
- shi->g= shi->g*neg_alpha + shi->vcol[1]*shi->vcol[3];
- shi->b= shi->b*neg_alpha + shi->vcol[2]*shi->vcol[3];
- }
-
- if (ma->texco)
- do_material_tex(shi, &R);
-
- if (ma->fresnel_tra!=0.0f)
- shi->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra_i, ma->fresnel_tra);
-
- if (!(shi->mode & MA_TRANSP)) shi->alpha= 1.0f;
-
- shr->diff[0]= shi->r;
- shr->diff[1]= shi->g;
- shr->diff[2]= shi->b;
- shr->alpha= shi->alpha;
-
- /* modulate by the object color */
- if ((ma->shade_flag & MA_OBCOLOR) && shi->obr->ob) {
- float obcol[4];
-
- copy_v4_v4(obcol, shi->obr->ob->col);
- CLAMP(obcol[3], 0.0f, 1.0f);
-
- shr->diff[0] *= obcol[0];
- shr->diff[1] *= obcol[1];
- shr->diff[2] *= obcol[2];
- if (shi->mode & MA_TRANSP) shr->alpha *= obcol[3];
- }
-
- copy_v3_v3(shr->diffshad, shr->diff);
-}
-
-/* ramp for at end of shade */
-static void ramp_diffuse_result(float *diff, ShadeInput *shi)
-{
- Material *ma= shi->mat;
- float col[4];
-
- if (ma->ramp_col) {
- if (ma->rampin_col==MA_RAMP_IN_RESULT) {
- float fac = IMB_colormanagement_get_luminance(diff);
- BKE_colorband_evaluate(ma->ramp_col, fac, col);
-
- /* blending method */
- fac= col[3]*ma->rampfac_col;
-
- ramp_blend(ma->rampblend_col, diff, fac, col);
- }
- }
-}
-
-/* r,g,b denote energy, ramp is used with different values to make new material color */
-static void add_to_diffuse(float diff[3], const ShadeInput *shi, const float is, const float rgb[3])
-{
- Material *ma= shi->mat;
-
- if (ma->ramp_col && (ma->mode & MA_RAMP_COL)) {
-
- /* MA_RAMP_IN_RESULT is exceptional */
- if (ma->rampin_col==MA_RAMP_IN_RESULT) {
- /* normal add */
- diff[0] += rgb[0] * shi->r;
- diff[1] += rgb[1] * shi->g;
- diff[2] += rgb[2] * shi->b;
- }
- else {
- float colt[3], col[4];
- float fac;
-
- /* input */
- switch (ma->rampin_col) {
- case MA_RAMP_IN_ENERGY:
- fac = IMB_colormanagement_get_luminance(rgb);
- break;
- case MA_RAMP_IN_SHADER:
- fac = is;
- break;
- case MA_RAMP_IN_NOR:
- fac = dot_v3v3(shi->view, shi->vn);
- break;
- default:
- fac = 0.0f;
- break;
- }
-
- BKE_colorband_evaluate(ma->ramp_col, fac, col);
-
- /* blending method */
- fac = col[3] * ma->rampfac_col;
- copy_v3_v3(colt, &shi->r);
-
- ramp_blend(ma->rampblend_col, colt, fac, col);
-
- /* output to */
- diff[0] += rgb[0] * colt[0];
- diff[1] += rgb[1] * colt[1];
- diff[2] += rgb[2] * colt[2];
- }
- }
- else {
- diff[0] += rgb[0] * shi->r;
- diff[1] += rgb[1] * shi->g;
- diff[2] += rgb[2] * shi->b;
- }
-}
-
-static void ramp_spec_result(float spec_col[3], ShadeInput *shi)
-{
- Material *ma= shi->mat;
-
- if (ma->ramp_spec && (ma->rampin_spec==MA_RAMP_IN_RESULT)) {
- float col[4];
- float fac = IMB_colormanagement_get_luminance(spec_col);
-
- BKE_colorband_evaluate(ma->ramp_spec, fac, col);
-
- /* blending method */
- fac= col[3]*ma->rampfac_spec;
-
- ramp_blend(ma->rampblend_spec, spec_col, fac, col);
-
- }
-}
-
-/* is = dot product shade, t = spec energy */
-static void do_specular_ramp(ShadeInput *shi, float is, float t, float spec[3])
-{
- Material *ma= shi->mat;
-
- spec[0]= shi->specr;
- spec[1]= shi->specg;
- spec[2]= shi->specb;
-
- /* MA_RAMP_IN_RESULT is exception */
- if (ma->ramp_spec && (ma->rampin_spec!=MA_RAMP_IN_RESULT)) {
- float fac;
- float col[4];
-
- /* input */
- switch (ma->rampin_spec) {
- case MA_RAMP_IN_ENERGY:
- fac= t;
- break;
- case MA_RAMP_IN_SHADER:
- fac= is;
- break;
- case MA_RAMP_IN_NOR:
- fac= shi->view[0]*shi->vn[0] + shi->view[1]*shi->vn[1] + shi->view[2]*shi->vn[2];
- break;
- default:
- fac= 0.0f;
- break;
- }
-
- BKE_colorband_evaluate(ma->ramp_spec, fac, col);
-
- /* blending method */
- fac= col[3]*ma->rampfac_spec;
-
- ramp_blend(ma->rampblend_spec, spec, fac, col);
- }
-}
-
-/* pure AO, check for raytrace and world should have been done */
-/* preprocess, textures were not done, don't use shi->amb for that reason */
-void ambient_occlusion(ShadeInput *shi)
-{
- if ((R.wrld.ao_gather_method == WO_AOGATHER_APPROX) && shi->mat->amb!=0.0f) {
- sample_occ(&R, shi);
- }
- else if ((R.r.mode & R_RAYTRACE) && shi->mat->amb!=0.0f) {
- ray_ao(shi, shi->ao, shi->env);
- }
- else {
- shi->ao[0]= shi->ao[1]= shi->ao[2]= 1.0f;
- zero_v3(shi->env);
- zero_v3(shi->indirect);
- }
-}
-
-
-/* wrld mode was checked for */
-static void ambient_occlusion_apply(ShadeInput *shi, ShadeResult *shr)
-{
- float f= R.wrld.aoenergy;
- float tmp[3], tmpspec[3];
-
- if (!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX))
- return;
- if (f == 0.0f)
- return;
-
- if (R.wrld.aomix==WO_AOADD) {
- shr->combined[0] += shi->ao[0]*shi->r*shi->refl*f;
- shr->combined[1] += shi->ao[1]*shi->g*shi->refl*f;
- shr->combined[2] += shi->ao[2]*shi->b*shi->refl*f;
- }
- else if (R.wrld.aomix==WO_AOMUL) {
- mul_v3_v3v3(tmp, shr->combined, shi->ao);
- mul_v3_v3v3(tmpspec, shr->spec, shi->ao);
-
- if (f == 1.0f) {
- copy_v3_v3(shr->combined, tmp);
- copy_v3_v3(shr->spec, tmpspec);
- }
- else {
- interp_v3_v3v3(shr->combined, shr->combined, tmp, f);
- interp_v3_v3v3(shr->spec, shr->spec, tmpspec, f);
- }
- }
-}
-
-void environment_lighting_apply(ShadeInput *shi, ShadeResult *shr)
-{
- float f= R.wrld.ao_env_energy*shi->amb;
-
- if (!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX))
- return;
- if (f == 0.0f)
- return;
-
- shr->combined[0] += shi->env[0]*shi->r*shi->refl*f;
- shr->combined[1] += shi->env[1]*shi->g*shi->refl*f;
- shr->combined[2] += shi->env[2]*shi->b*shi->refl*f;
-}
-
-static void indirect_lighting_apply(ShadeInput *shi, ShadeResult *shr)
-{
- float f= R.wrld.ao_indirect_energy;
-
- if (!((R.r.mode & R_RAYTRACE) || R.wrld.ao_gather_method == WO_AOGATHER_APPROX))
- return;
- if (f == 0.0f)
- return;
-
- shr->combined[0] += shi->indirect[0]*shi->r*shi->refl*f;
- shr->combined[1] += shi->indirect[1]*shi->g*shi->refl*f;
- shr->combined[2] += shi->indirect[2]*shi->b*shi->refl*f;
-}
-
-/* result written in shadfac */
-void lamp_get_shadow(LampRen *lar, ShadeInput *shi, float inp, float shadfac[4], int do_real)
-{
- LampShadowSubSample *lss= &(lar->shadsamp[shi->thread].s[shi->sample]);
-
- if (do_real || lss->samplenr!=shi->samplenr) {
-
- shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f;
-
- if (lar->shb) {
- if (lar->buftype==LA_SHADBUF_IRREGULAR)
- shadfac[3]= ISB_getshadow(shi, lar->shb);
- else
- shadfac[3] = testshadowbuf(&R, lar->shb, shi->co, shi->dxco, shi->dyco, inp, shi->mat->lbias);
- }
- else if (lar->mode & LA_SHAD_RAY) {
- ray_shadow(shi, lar, shadfac);
- }
-
- if (shi->depth==0) {
- copy_v4_v4(lss->shadfac, shadfac);
- lss->samplenr= shi->samplenr;
- }
- }
- else {
- copy_v4_v4(shadfac, lss->shadfac);
- }
-}
-
-/* lampdistance and spot angle, writes in lv and dist */
-float lamp_get_visibility(LampRen *lar, const float co[3], float lv[3], float *dist)
-{
- if (lar->type==LA_SUN || lar->type==LA_HEMI) {
- *dist= 1.0f;
- copy_v3_v3(lv, lar->vec);
- return 1.0f;
- }
- else {
- float visifac= 1.0f, visifac_r;
-
- sub_v3_v3v3(lv, co, lar->co);
- mul_v3_fl(lv, 1.0f / (*dist = len_v3(lv)));
-
- /* area type has no quad or sphere option */
- if (lar->type==LA_AREA) {
- /* area is single sided */
- //if (dot_v3v3(lv, lar->vec) > 0.0f)
- // visifac= 1.0f;
- //else
- // visifac= 0.0f;
- }
- else {
- switch (lar->falloff_type) {
- case LA_FALLOFF_CONSTANT:
- visifac = 1.0f;
- break;
- case LA_FALLOFF_INVLINEAR:
- visifac = lar->dist/(lar->dist + dist[0]);
- break;
- case LA_FALLOFF_INVSQUARE:
- /* NOTE: This seems to be a hack since commit r12045 says this
- * option is similar to old Quad, but with slight changes.
- * Correct inv square would be (which would be old Quad):
- * visifac = lar->distkw / (lar->distkw + dist[0]*dist[0]);
- */
- visifac = lar->dist / (lar->dist + dist[0]*dist[0]);
- break;
- case LA_FALLOFF_SLIDERS:
- if (lar->ld1>0.0f)
- visifac= lar->dist/(lar->dist+lar->ld1*dist[0]);
- if (lar->ld2>0.0f)
- visifac*= lar->distkw/(lar->distkw+lar->ld2*dist[0]*dist[0]);
- break;
- case LA_FALLOFF_INVCOEFFICIENTS:
- visifac_r = lar->coeff_const +
- lar->coeff_lin * dist[0] +
- lar->coeff_quad * dist[0] * dist[0];
- if (visifac_r > 0.0)
- visifac = 1.0 / visifac_r;
- else
- visifac = 0.0;
- break;
- case LA_FALLOFF_CURVE:
- /* curvemapping_initialize is called from #add_render_lamp */
- visifac = curvemapping_evaluateF(lar->curfalloff, 0, dist[0]/lar->dist);
- break;
- }
-
- if (lar->mode & LA_SPHERE) {
- float t= lar->dist - dist[0];
- if (t<=0.0f)
- visifac= 0.0f;
- else
- visifac*= t/lar->dist;
- }
-
- if (visifac > 0.0f) {
- if (lar->type==LA_SPOT) {
- float inpr, t;
-
- if (lar->mode & LA_SQUARE) {
- if (dot_v3v3(lv, lar->vec) > 0.0f) {
- float lvrot[3], x;
-
- /* rotate view to lampspace */
- copy_v3_v3(lvrot, lv);
- mul_m3_v3(lar->imat, lvrot);
-
- x = max_ff(fabsf(lvrot[0]/lvrot[2]), fabsf(lvrot[1]/lvrot[2]));
- /* 1.0f/(sqrt(1+x*x)) is equivalent to cos(atan(x)) */
-
- inpr = 1.0f / (sqrtf(1.0f + x * x));
- }
- else inpr= 0.0f;
- }
- else {
- inpr= lv[0]*lar->vec[0]+lv[1]*lar->vec[1]+lv[2]*lar->vec[2];
- }
-
- t= lar->spotsi;
- if (inpr<=t)
- visifac= 0.0f;
- else {
- t= inpr-t;
- if (t<lar->spotbl && lar->spotbl!=0.0f) {
- /* soft area */
- float i= t/lar->spotbl;
- t= i*i;
- inpr*= (3.0f*t-2.0f*t*i);
- }
- visifac*= inpr;
- }
- }
- }
- }
- if (visifac <= 0.001f) visifac = 0.0f;
- return visifac;
- }
-}
-
-/* function returns raw diff, spec and full shadowed diff in the 'shad' pass */
-static void shade_one_light(LampRen *lar, ShadeInput *shi, ShadeResult *shr, int passflag)
-{
- Material *ma= shi->mat;
- VlakRen *vlr= shi->vlr;
- float lv[3], lampdist, lacol[3], shadfac[4], lashdw[3];
- float i, is, i_noshad, inp, *vn, *view, vnor[3], phongcorr=1.0f;
- float visifac;
-
- vn= shi->vn;
- view= shi->view;
-
-
- if (lar->energy == 0.0f) return;
- /* only shadow lamps shouldn't affect shadow-less materials at all */
- if ((lar->mode & LA_ONLYSHADOW) && (!(ma->mode & MA_SHADOW) || !(R.r.mode & R_SHADOW)))
- return;
- /* optimization, don't render fully black lamps */
- if (!(lar->mode & LA_TEXTURE) && (lar->r + lar->g + lar->b == 0.0f))
- return;
-
- /* lampdist, spot angle, area side, ... */
- visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist);
- if (visifac==0.0f)
- return;
-
- if (lar->type==LA_SPOT) {
- if (lar->mode & LA_OSATEX) {
- shi->osatex= 1; /* signal for multitex() */
-
- shi->dxlv[0]= lv[0] - (shi->co[0]-lar->co[0]+shi->dxco[0])/lampdist;
- shi->dxlv[1]= lv[1] - (shi->co[1]-lar->co[1]+shi->dxco[1])/lampdist;
- shi->dxlv[2]= lv[2] - (shi->co[2]-lar->co[2]+shi->dxco[2])/lampdist;
-
- shi->dylv[0]= lv[0] - (shi->co[0]-lar->co[0]+shi->dyco[0])/lampdist;
- shi->dylv[1]= lv[1] - (shi->co[1]-lar->co[1]+shi->dyco[1])/lampdist;
- shi->dylv[2]= lv[2] - (shi->co[2]-lar->co[2]+shi->dyco[2])/lampdist;
- }
- }
-
- /* lamp color texture */
- lacol[0]= lar->r;
- lacol[1]= lar->g;
- lacol[2]= lar->b;
-
- lashdw[0]= lar->shdwr;
- lashdw[1]= lar->shdwg;
- lashdw[2]= lar->shdwb;
-
- if (lar->mode & LA_TEXTURE) do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE);
- if (lar->mode & LA_SHAD_TEX) do_lamp_tex(lar, lv, shi, lashdw, LA_SHAD_TEX);
-
- /* tangent case; calculate fake face normal, aligned with lampvector */
- /* note, vnor==vn is used as tangent trigger for buffer shadow */
- if (vlr->flag & R_TANGENT) {
- float cross[3], nstrand[3], blend;
-
- if (ma->mode & MA_STR_SURFDIFF) {
- cross_v3_v3v3(cross, shi->surfnor, vn);
- cross_v3_v3v3(nstrand, vn, cross);
-
- blend= dot_v3v3(nstrand, shi->surfnor);
- blend= 1.0f - blend;
- CLAMP(blend, 0.0f, 1.0f);
-
- interp_v3_v3v3(vnor, nstrand, shi->surfnor, blend);
- normalize_v3(vnor);
- }
- else {
- cross_v3_v3v3(cross, lv, vn);
- cross_v3_v3v3(vnor, cross, vn);
- normalize_v3(vnor);
- }
-
- if (ma->strand_surfnor > 0.0f) {
- if (ma->strand_surfnor > shi->surfdist) {
- blend= (ma->strand_surfnor - shi->surfdist)/ma->strand_surfnor;
- interp_v3_v3v3(vnor, vnor, shi->surfnor, blend);
- normalize_v3(vnor);
- }
- }
-
- vnor[0]= -vnor[0];vnor[1]= -vnor[1];vnor[2]= -vnor[2];
- vn= vnor;
- }
- else if (ma->mode & MA_TANGENT_V) {
- float cross[3];
- cross_v3_v3v3(cross, lv, shi->tang);
- cross_v3_v3v3(vnor, cross, shi->tang);
- normalize_v3(vnor);
- vnor[0]= -vnor[0];vnor[1]= -vnor[1];vnor[2]= -vnor[2];
- vn= vnor;
- }
-
- /* dot product and reflectivity */
- /* inp = dotproduct, is = shader result, i = lamp energy (with shadow), i_noshad = i without shadow */
- inp= dot_v3v3(vn, lv);
-
- /* phong threshold to prevent backfacing faces having artifacts on ray shadow (terminator problem) */
- /* this complex construction screams for a nicer implementation! (ton) */
- if (R.r.mode & R_SHADOW) {
- if (ma->mode & MA_SHADOW) {
- if (lar->type == LA_HEMI || lar->type == LA_AREA) {
- /* pass */
- }
- else if ((ma->mode & MA_RAYBIAS) && (lar->mode & LA_SHAD_RAY) && (vlr->flag & R_SMOOTH)) {
- float thresh= shi->obr->ob->smoothresh;
- if (inp>thresh)
- phongcorr= (inp-thresh)/(inp*(1.0f-thresh));
- else
- phongcorr= 0.0f;
- }
- else if (ma->sbias!=0.0f && ((lar->mode & LA_SHAD_RAY) || lar->shb)) {
- if (inp>ma->sbias)
- phongcorr= (inp-ma->sbias)/(inp*(1.0f-ma->sbias));
- else
- phongcorr= 0.0f;
- }
- }
- }
-
- /* diffuse shaders */
- if (lar->mode & LA_NO_DIFF) {
- is = 0.0f; /* skip shaders */
- }
- else if (lar->type==LA_HEMI) {
- is = 0.5f * inp + 0.5f;
- }
- else {
-
- if (lar->type==LA_AREA)
- inp= area_lamp_energy_multisample(lar, shi->co, vn);
-
- /* diffuse shaders (oren nayer gets inp from area light) */
- if (ma->diff_shader==MA_DIFF_ORENNAYAR) is= OrenNayar_Diff(inp, vn, lv, view, ma->roughness);
- else if (ma->diff_shader==MA_DIFF_TOON) is= Toon_Diff(vn, lv, view, ma->param[0], ma->param[1]);
- else if (ma->diff_shader==MA_DIFF_MINNAERT) is= Minnaert_Diff(inp, vn, view, ma->darkness);
- else if (ma->diff_shader==MA_DIFF_FRESNEL) is= Fresnel_Diff(vn, lv, view, ma->param[0], ma->param[1]);
- else is= inp; /* Lambert */
- }
-
- /* 'is' is diffuse */
- if ((ma->shade_flag & MA_CUBIC) && is > 0.0f && is < 1.0f) {
- is= 3.0f * is * is - 2.0f * is * is * is; /* nicer termination of shades */
- }
-
- i= is*phongcorr;
-
- if (i>0.0f) {
- i*= visifac*shi->refl;
- }
- i_noshad= i;
-
- vn = shi->vn; /* bring back original vector, we use special specular shaders for tangent */
- if (ma->mode & MA_TANGENT_V)
- vn= shi->tang;
-
- /* init transp shadow */
- shadfac[0]= shadfac[1]= shadfac[2]= shadfac[3]= 1.0f;
-
- /* shadow and spec, (visifac==0 outside spot) */
- if (visifac> 0.0f) {
-
- if ((R.r.mode & R_SHADOW)) {
- if (ma->mode & MA_SHADOW) {
- if (lar->shb || (lar->mode & LA_SHAD_RAY)) {
-
- if (vn==vnor) /* tangent trigger */
- lamp_get_shadow(lar, shi, dot_v3v3(shi->vn, lv), shadfac, shi->depth);
- else
- lamp_get_shadow(lar, shi, inp, shadfac, shi->depth);
-
- /* warning, here it skips the loop */
- if ((lar->mode & LA_ONLYSHADOW) && i>0.0f) {
-
- shadfac[3]= i*lar->energy*(1.0f-shadfac[3]);
- shr->shad[0] -= shadfac[3]*shi->r*(1.0f-lashdw[0]);
- shr->shad[1] -= shadfac[3]*shi->g*(1.0f-lashdw[1]);
- shr->shad[2] -= shadfac[3]*shi->b*(1.0f-lashdw[2]);
-
- if (!(lar->mode & LA_NO_SPEC)) {
- shr->spec[0] -= shadfac[3]*shi->specr*(1.0f-lashdw[0]);
- shr->spec[1] -= shadfac[3]*shi->specg*(1.0f-lashdw[1]);
- shr->spec[2] -= shadfac[3]*shi->specb*(1.0f-lashdw[2]);
- }
-
- return;
- }
-
- i*= shadfac[3];
- shr->shad[3] = shadfac[3]; /* store this for possible check in troublesome cases */
- }
- else {
- shr->shad[3] = 1.0f; /* No shadow at all! */
- }
- }
- }
-
- /* in case 'no diffuse' we still do most calculus, spec can be in shadow.*/
- if (!(lar->mode & LA_NO_DIFF)) {
- if (i>0.0f) {
- if (ma->mode & MA_SHADOW_TRA) {
- const float tcol[3] = {
- i * shadfac[0] * lacol[0],
- i * shadfac[1] * lacol[1],
- i * shadfac[2] * lacol[2],
- };
- add_to_diffuse(shr->shad, shi, is, tcol);
- }
- else {
- const float tcol[3] = {
- i * lacol[0],
- i * lacol[1],
- i * lacol[2],
- };
- add_to_diffuse(shr->shad, shi, is, tcol);
- }
- }
- /* add light for colored shadow */
- if (i_noshad>i && !(lashdw[0]==0 && lashdw[1]==0 && lashdw[2]==0)) {
- const float tcol[3] = {
- lashdw[0] * (i_noshad - i) * lacol[0],
- lashdw[1] * (i_noshad - i) * lacol[1],
- lashdw[2] * (i_noshad - i) * lacol[2],
- };
- add_to_diffuse(shr->shad, shi, is, tcol);
- }
- if (i_noshad>0.0f) {
- if (passflag & (SCE_PASS_DIFFUSE|SCE_PASS_SHADOW) ||
- ((passflag & SCE_PASS_COMBINED) && !(shi->combinedflag & SCE_PASS_SHADOW)))
- {
- const float tcol[3] = {
- i_noshad * lacol[0],
- i_noshad * lacol[1],
- i_noshad * lacol[2]
- };
- add_to_diffuse(shr->diff, shi, is, tcol);
- }
- else {
- copy_v3_v3(shr->diff, shr->shad);
- }
- }
- }
-
- /* specularity */
- shadfac[3]*= phongcorr; /* note, shadfac not allowed to be stored nonlocal */
-
- if (shadfac[3]>0.0f && shi->spec!=0.0f && !(lar->mode & LA_NO_SPEC) && !(lar->mode & LA_ONLYSHADOW)) {
-
- if (!(passflag & (SCE_PASS_COMBINED | SCE_PASS_SPEC))) {
- /* pass */
- }
- else if (lar->type == LA_HEMI) {
- float t;
- /* hemi uses no spec shaders (yet) */
-
- lv[0]+= view[0];
- lv[1]+= view[1];
- lv[2]+= view[2];
-
- normalize_v3(lv);
-
- t= vn[0]*lv[0]+vn[1]*lv[1]+vn[2]*lv[2];
-
- if (lar->type==LA_HEMI) {
- t= 0.5f*t+0.5f;
- }
-
- t= shadfac[3]*shi->spec*spec(t, shi->har);
-
- shr->spec[0]+= t*(lacol[0] * shi->specr);
- shr->spec[1]+= t*(lacol[1] * shi->specg);
- shr->spec[2]+= t*(lacol[2] * shi->specb);
- }
- else {
- /* specular shaders */
- float specfac, t;
-
- if (ma->spec_shader==MA_SPEC_PHONG)
- specfac= Phong_Spec(vn, lv, view, shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V));
- else if (ma->spec_shader==MA_SPEC_COOKTORR)
- specfac= CookTorr_Spec(vn, lv, view, shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V));
- else if (ma->spec_shader==MA_SPEC_BLINN)
- specfac= Blinn_Spec(vn, lv, view, ma->refrac, (float)shi->har, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V));
- else if (ma->spec_shader==MA_SPEC_WARDISO)
- specfac= WardIso_Spec( vn, lv, view, ma->rms, (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V));
- else
- specfac= Toon_Spec(vn, lv, view, ma->param[2], ma->param[3], (vlr->flag & R_TANGENT) || (ma->mode & MA_TANGENT_V));
-
- /* area lamp correction */
- if (lar->type==LA_AREA) specfac*= inp;
-
- t= shadfac[3]*shi->spec*visifac*specfac;
-
- if (ma->mode & MA_RAMP_SPEC) {
- float spec[3];
- do_specular_ramp(shi, specfac, t, spec);
- shr->spec[0]+= t*(lacol[0] * spec[0]);
- shr->spec[1]+= t*(lacol[1] * spec[1]);
- shr->spec[2]+= t*(lacol[2] * spec[2]);
- }
- else {
- shr->spec[0]+= t*(lacol[0] * shi->specr);
- shr->spec[1]+= t*(lacol[1] * shi->specg);
- shr->spec[2]+= t*(lacol[2] * shi->specb);
- }
- }
- }
- }
-}
-
-static void shade_lamp_loop_only_shadow(ShadeInput *shi, ShadeResult *shr)
-{
-
- if (R.r.mode & R_SHADOW) {
- ListBase *lights;
- LampRen *lar;
- GroupObject *go;
- float inpr, lv[3];
- float /* *view, */ shadfac[4];
- float ir, accum, visifac, lampdist;
- float shaded = 0.0f, lightness = 0.0f;
-
-
- /* view= shi->view; */ /* UNUSED */
- accum= ir= 0.0f;
-
- lights= get_lights(shi);
- for (go=lights->first; go; go= go->next) {
- lar= go->lampren;
- if (lar==NULL) continue;
-
- if (lar->mode & LA_LAYER) if ((lar->lay & shi->obi->lay)==0) continue;
- if ((lar->lay & shi->lay)==0) continue;
-
- if (lar->shb || (lar->mode & LA_SHAD_RAY)) {
- visifac= lamp_get_visibility(lar, shi->co, lv, &lampdist);
- ir+= 1.0f;
-
- if (visifac <= 0.0f) {
- if (shi->mat->shadowonly_flag == MA_SO_OLD)
- accum+= 1.0f;
-
- continue;
- }
- inpr= dot_v3v3(shi->vn, lv);
- if (inpr <= 0.0f) {
- if (shi->mat->shadowonly_flag == MA_SO_OLD)
- accum+= 1.0f;
-
- continue;
- }
-
- lamp_get_shadow(lar, shi, inpr, shadfac, shi->depth);
-
- if (shi->mat->shadowonly_flag == MA_SO_OLD) {
- /* Old "Shadows Only" */
- accum+= (1.0f-visifac) + (visifac)*IMB_colormanagement_get_luminance(shadfac)*shadfac[3];
- }
- else {
- shaded += IMB_colormanagement_get_luminance(shadfac)*shadfac[3] * visifac * lar->energy;
-
- if (shi->mat->shadowonly_flag == MA_SO_SHADOW) {
- lightness += visifac * lar->energy;
- }
- }
- }
- }
-
- /* Apply shadows as alpha */
- if (ir>0.0f) {
- if (shi->mat->shadowonly_flag == MA_SO_OLD) {
- accum = 1.0f - accum/ir;
- }
- else {
- if (shi->mat->shadowonly_flag == MA_SO_SHADOW) {
- if (lightness > 0.0f) {
- /* Get shadow value from between 0.0f and non-shadowed lightness */
- accum = (lightness - shaded) / (lightness);
- }
- else {
- accum = 0.0f;
- }
- }
- else { /* shadowonly_flag == MA_SO_SHADED */
- /* Use shaded value */
- accum = 1.0f - shaded;
- }
- }
-
- shr->alpha= (shi->alpha)*(accum);
- if (shr->alpha<0.0f) shr->alpha=0.0f;
- }
- else {
- /* If "fully shaded", use full alpha even on areas that have no lights */
- if (shi->mat->shadowonly_flag == MA_SO_SHADED) shr->alpha=shi->alpha;
- else shr->alpha= 0.f;
- }
- }
-
- /* quite disputable this... also note it doesn't mirror-raytrace */
- if ((R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT)) && shi->amb!=0.0f) {
- float f;
-
- if (R.wrld.mode & WO_AMB_OCC) {
- f= R.wrld.aoenergy*shi->amb;
-
- if (R.wrld.aomix==WO_AOADD) {
- if (shi->mat->shadowonly_flag == MA_SO_OLD) {
- f= f*(1.0f - IMB_colormanagement_get_luminance(shi->ao));
- shr->alpha= (shr->alpha + f)*f;
- }
- else {
- shr->alpha -= f*IMB_colormanagement_get_luminance(shi->ao);
- if (shr->alpha<0.0f) shr->alpha=0.0f;
- }
- }
- else /* AO Multiply */
- shr->alpha= (1.0f - f)*shr->alpha + f*(1.0f - (1.0f - shr->alpha)*IMB_colormanagement_get_luminance(shi->ao));
- }
-
- if (R.wrld.mode & WO_ENV_LIGHT) {
- if (shi->mat->shadowonly_flag == MA_SO_OLD) {
- f= R.wrld.ao_env_energy*shi->amb*(1.0f - IMB_colormanagement_get_luminance(shi->env));
- shr->alpha= (shr->alpha + f)*f;
- }
- else {
- f= R.wrld.ao_env_energy*shi->amb;
- shr->alpha -= f*IMB_colormanagement_get_luminance(shi->env);
- if (shr->alpha<0.0f) shr->alpha=0.0f;
- }
- }
- }
-}
-
-/* let's map negative light as if it mirrors positive light, otherwise negative values disappear */
-static void wrld_exposure_correct(float diff[3])
-{
-
- diff[0]= R.wrld.linfac*(1.0f-expf( diff[0]*R.wrld.logfac) );
- diff[1]= R.wrld.linfac*(1.0f-expf( diff[1]*R.wrld.logfac) );
- diff[2]= R.wrld.linfac*(1.0f-expf( diff[2]*R.wrld.logfac) );
-}
-
-void shade_lamp_loop(ShadeInput *shi, ShadeResult *shr)
-{
- /* Passes which might need to know material color.
- *
- * It seems to be faster to just calculate material color
- * even if the pass doesn't really need it than trying to
- * figure out whether color is really needed or not.
- */
- const int color_passes =
- SCE_PASS_COMBINED | SCE_PASS_RGBA | SCE_PASS_DIFFUSE | SCE_PASS_SPEC |
- SCE_PASS_REFLECT | SCE_PASS_NORMAL | SCE_PASS_REFRACT | SCE_PASS_EMIT | SCE_PASS_SHADOW;
-
- Material *ma= shi->mat;
- int passflag= shi->passflag;
-
- memset(shr, 0, sizeof(ShadeResult));
-
- if (!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f;
-
- /* separate loop */
- if (ma->mode & MA_ONLYSHADOW) {
- shade_lamp_loop_only_shadow(shi, shr);
- return;
- }
-
- /* envmap hack, always reset */
- shi->refcol[0]= shi->refcol[1]= shi->refcol[2]= shi->refcol[3]= 0.0f;
-
- /* material color itself */
- if (passflag & color_passes) {
- if (ma->mode & (MA_FACETEXTURE)) {
- shi->r= shi->vcol[0];
- shi->g= shi->vcol[1];
- shi->b= shi->vcol[2];
- if (ma->mode & (MA_FACETEXTURE_ALPHA))
- shi->alpha= shi->vcol[3];
- }
-#ifdef WITH_FREESTYLE
- else if (ma->vcol_alpha) {
- shi->r= shi->vcol[0];
- shi->g= shi->vcol[1];
- shi->b= shi->vcol[2];
- shi->alpha= shi->vcol[3];
- }
-#endif
- else if (ma->mode & (MA_VERTEXCOLP)) {
- float neg_alpha = 1.0f - shi->vcol[3];
- shi->r= shi->r*neg_alpha + shi->vcol[0]*shi->vcol[3];
- shi->g= shi->g*neg_alpha + shi->vcol[1]*shi->vcol[3];
- shi->b= shi->b*neg_alpha + shi->vcol[2]*shi->vcol[3];
- }
- if (ma->texco) {
- do_material_tex(shi, &R);
- if (!(shi->mode & MA_TRANSP)) shi->alpha = 1.0f;
- }
-
- shr->col[0]= shi->r*shi->alpha;
- shr->col[1]= shi->g*shi->alpha;
- shr->col[2]= shi->b*shi->alpha;
- shr->col[3]= shi->alpha;
-
- if ((ma->sss_flag & MA_DIFF_SSS) && !sss_pass_done(&R, ma)) {
- if (ma->sss_texfac == 0.0f) {
- shi->r= shi->g= shi->b= shi->alpha= 1.0f;
- shr->col[0]= shr->col[1]= shr->col[2]= shr->col[3]= 1.0f;
- }
- else {
- shi->r= pow(max_ff(shi->r, 0.0f), ma->sss_texfac);
- shi->g= pow(max_ff(shi->g, 0.0f), ma->sss_texfac);
- shi->b= pow(max_ff(shi->b, 0.0f), ma->sss_texfac);
- shi->alpha= pow(max_ff(shi->alpha, 0.0f), ma->sss_texfac);
-
- shr->col[0]= pow(max_ff(shr->col[0], 0.0f), ma->sss_texfac);
- shr->col[1]= pow(max_ff(shr->col[1], 0.0f), ma->sss_texfac);
- shr->col[2]= pow(max_ff(shr->col[2], 0.0f), ma->sss_texfac);
- shr->col[3]= pow(max_ff(shr->col[3], 0.0f), ma->sss_texfac);
- }
- }
- }
-
- if (ma->mode & MA_SHLESS) {
- shr->combined[0]= shi->r;
- shr->combined[1]= shi->g;
- shr->combined[2]= shi->b;
- shr->alpha= shi->alpha;
- goto finally_shadeless;
- }
-
- if ( (ma->mode & (MA_VERTEXCOL|MA_VERTEXCOLP))== MA_VERTEXCOL ) { /* vertexcolor light */
- shr->emit[0]= shi->r*(shi->emit+shi->vcol[0]*shi->vcol[3]);
- shr->emit[1]= shi->g*(shi->emit+shi->vcol[1]*shi->vcol[3]);
- shr->emit[2]= shi->b*(shi->emit+shi->vcol[2]*shi->vcol[3]);
- }
- else {
- shr->emit[0]= shi->r*shi->emit;
- shr->emit[1]= shi->g*shi->emit;
- shr->emit[2]= shi->b*shi->emit;
- }
-
- /* AO pass */
- if (((passflag & SCE_PASS_COMBINED) && (shi->combinedflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) ||
- (passflag & (SCE_PASS_AO|SCE_PASS_ENVIRONMENT|SCE_PASS_INDIRECT))) {
- if ((R.wrld.mode & (WO_AMB_OCC|WO_ENV_LIGHT|WO_INDIRECT_LIGHT)) && (R.r.mode & R_SHADOW)) {
- /* AO was calculated for scanline already */
- if (shi->depth || shi->volume_depth)
- ambient_occlusion(shi);
- copy_v3_v3(shr->ao, shi->ao);
- copy_v3_v3(shr->env, shi->env); /* XXX multiply */
- copy_v3_v3(shr->indirect, shi->indirect); /* XXX multiply */
- }
- else {
- shr->ao[0]= shr->ao[1]= shr->ao[2]= 1.0f;
- zero_v3(shr->env);
- zero_v3(shr->indirect);
- }
- }
-
- /* lighting pass */
- if (passflag & (SCE_PASS_COMBINED|SCE_PASS_DIFFUSE|SCE_PASS_SPEC|SCE_PASS_SHADOW)) {
- GroupObject *go;
- ListBase *lights;
- LampRen *lar;
-
- lights= get_lights(shi);
- for (go=lights->first; go; go= go->next) {
- lar= go->lampren;
- if (lar==NULL) continue;
-
- /* test for lamp layer */
- if (lar->mode & LA_LAYER) if ((lar->lay & shi->obi->lay)==0) continue;
- if ((lar->lay & shi->lay)==0) continue;
-
- /* accumulates in shr->diff and shr->spec and shr->shad (diffuse with shadow!) */
- shade_one_light(lar, shi, shr, passflag);
- }
-
- /* this check is to prevent only shadow lamps from producing negative
- * colors.*/
- if (shr->spec[0] < 0) shr->spec[0] = 0;
- if (shr->spec[1] < 0) shr->spec[1] = 0;
- if (shr->spec[2] < 0) shr->spec[2] = 0;
-
- if (shr->shad[0] < 0) shr->shad[0] = 0;
- if (shr->shad[1] < 0) shr->shad[1] = 0;
- if (shr->shad[2] < 0) shr->shad[2] = 0;
-
- if (ma->sss_flag & MA_DIFF_SSS) {
- float sss[3], col[3], invalpha, texfac= ma->sss_texfac;
-
- /* this will return false in the preprocess stage */
- if (sample_sss(&R, ma, shi->co, sss)) {
- invalpha= (shr->col[3] > FLT_EPSILON)? 1.0f/shr->col[3]: 1.0f;
-
- if (texfac==0.0f) {
- copy_v3_v3(col, shr->col);
- mul_v3_fl(col, invalpha);
- }
- else if (texfac==1.0f) {
- col[0]= col[1]= col[2]= 1.0f;
- mul_v3_fl(col, invalpha);
- }
- else {
- copy_v3_v3(col, shr->col);
- mul_v3_fl(col, invalpha);
- col[0]= pow(max_ff(col[0], 0.0f), 1.0f-texfac);
- col[1]= pow(max_ff(col[1], 0.0f), 1.0f-texfac);
- col[2]= pow(max_ff(col[2], 0.0f), 1.0f-texfac);
- }
-
- shr->diff[0]= sss[0]*col[0];
- shr->diff[1]= sss[1]*col[1];
- shr->diff[2]= sss[2]*col[2];
-
- if (shi->combinedflag & SCE_PASS_SHADOW) {
- shr->shad[0]= shr->diff[0];
- shr->shad[1]= shr->diff[1];
- shr->shad[2]= shr->diff[2];
- }
- }
- }
-
- if (shi->combinedflag & SCE_PASS_SHADOW)
- copy_v3_v3(shr->diffshad, shr->shad);
- else
- copy_v3_v3(shr->diffshad, shr->diff);
-
- copy_v3_v3(shr->combined, shr->diffshad);
-
- /* calculate shadow pass, we use a multiplication mask */
- /* Even if diff = 0,0,0, it does matter what the shadow pass is, since we may want it 'for itself'! */
- if (passflag & SCE_PASS_SHADOW) {
- if (shr->diff[0]!=0.0f) shr->shad[0]= shr->shad[0]/shr->diff[0];
- /* can't determine proper shadow from shad/diff (0/0), so use shadow intensity */
- else if (shr->shad[0]==0.0f) shr->shad[0]= shr->shad[3];
-
- if (shr->diff[1]!=0.0f) shr->shad[1]= shr->shad[1]/shr->diff[1];
- else if (shr->shad[1]==0.0f) shr->shad[1]= shr->shad[3];
-
- if (shr->diff[2]!=0.0f) shr->shad[2]= shr->shad[2]/shr->diff[2];
- else if (shr->shad[2]==0.0f) shr->shad[2]= shr->shad[3];
- }
-
- /* exposure correction */
- if ((R.wrld.exp!=0.0f || R.wrld.range!=1.0f) && !R.sss_points) {
- wrld_exposure_correct(shr->combined); /* has no spec! */
- wrld_exposure_correct(shr->spec);
- }
- }
-
- /* alpha in end, spec can influence it */
- if (passflag & (SCE_PASS_COMBINED)) {
- if ((ma->fresnel_tra!=0.0f) && (shi->mode & MA_TRANSP))
- shi->alpha*= fresnel_fac(shi->view, shi->vn, ma->fresnel_tra_i, ma->fresnel_tra);
-
- /* note: shi->mode! */
- if (shi->mode & MA_TRANSP && (shi->mode & (MA_ZTRANSP|MA_RAYTRANSP))) {
- if (shi->spectra!=0.0f) {
- float t = max_fff(shr->spec[0], shr->spec[1], shr->spec[2]);
- t *= shi->spectra;
- if (t>1.0f) t= 1.0f;
- shi->alpha= (1.0f-t)*shi->alpha+t;
- }
- }
- }
- shr->alpha= shi->alpha;
-
- /* from now stuff everything in shr->combined: ambient, AO, ramps, exposure */
- if (!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) {
- if (R.r.mode & R_SHADOW) {
- /* add AO in combined? */
- if (R.wrld.mode & WO_AMB_OCC)
- if (shi->combinedflag & SCE_PASS_AO)
- ambient_occlusion_apply(shi, shr);
-
- if (R.wrld.mode & WO_ENV_LIGHT)
- if (shi->combinedflag & SCE_PASS_ENVIRONMENT)
- environment_lighting_apply(shi, shr);
-
- if (R.wrld.mode & WO_INDIRECT_LIGHT)
- if (shi->combinedflag & SCE_PASS_INDIRECT)
- indirect_lighting_apply(shi, shr);
- }
-
- shr->combined[0]+= shi->ambr;
- shr->combined[1]+= shi->ambg;
- shr->combined[2]+= shi->ambb;
-
- if (ma->mode & MA_RAMP_COL) ramp_diffuse_result(shr->combined, shi);
- }
-
- if (ma->mode & MA_RAMP_SPEC) ramp_spec_result(shr->spec, shi);
-
- /* refcol is for envmap only */
- if (shi->refcol[0]!=0.0f) {
- float result[3];
-
- result[0]= shi->mirr*shi->refcol[1] + (1.0f - shi->mirr*shi->refcol[0])*shr->combined[0];
- result[1]= shi->mirg*shi->refcol[2] + (1.0f - shi->mirg*shi->refcol[0])*shr->combined[1];
- result[2]= shi->mirb*shi->refcol[3] + (1.0f - shi->mirb*shi->refcol[0])*shr->combined[2];
-
- if (passflag & SCE_PASS_REFLECT)
- sub_v3_v3v3(shr->refl, result, shr->combined);
-
- if (shi->combinedflag & SCE_PASS_REFLECT)
- copy_v3_v3(shr->combined, result);
-
- }
-
- /* and add emit and spec */
- if (shi->combinedflag & SCE_PASS_EMIT)
- add_v3_v3(shr->combined, shr->emit);
- if (shi->combinedflag & SCE_PASS_SPEC)
- add_v3_v3(shr->combined, shr->spec);
-
-
- /* Last section of this function applies to shadeless colors too */
-finally_shadeless:
-
- /* modulate by the object color */
- if ((ma->shade_flag & MA_OBCOLOR) && shi->obr->ob) {
- if (!(ma->sss_flag & MA_DIFF_SSS) || !sss_pass_done(&R, ma)) {
- float obcol[4];
-
- copy_v4_v4(obcol, shi->obr->ob->col);
- CLAMP(obcol[3], 0.0f, 1.0f);
-
- shr->combined[0] *= obcol[0];
- shr->combined[1] *= obcol[1];
- shr->combined[2] *= obcol[2];
- if (shi->mode & MA_TRANSP) shr->alpha *= obcol[3];
- }
- }
-
- shr->combined[3]= shr->alpha;
-}
-
-/* used for "Lamp Data" shader node */
-static float lamp_get_data_internal(ShadeInput *shi, GroupObject *go, float col[4], float lv[3], float *dist, float shadow[4])
-{
- LampRen *lar = go->lampren;
- float visifac, inp;
-
- if (!lar
- || ((lar->mode & LA_LAYER) && (lar->lay & shi->obi->lay) == 0)
- || (lar->lay & shi->lay) == 0)
- return 0.0f;
-
- if (lar->mode & LA_TEXTURE)
- do_lamp_tex(lar, lv, shi, col, LA_TEXTURE);
-
- visifac = lamp_get_visibility(lar, shi->co, lv, dist);
-
- if (visifac == 0.0f
- || lar->type == LA_HEMI
- || (lar->type != LA_SPOT && !(lar->mode & LA_SHAD_RAY))
- || (R.r.scemode & R_BUTS_PREVIEW))
- return visifac;
-
- inp = dot_v3v3(shi->vn, lv);
-
- if (inp > 0.0f) {
- float shadfac[4];
-
- shadow[0] = lar->shdwr;
- shadow[1] = lar->shdwg;
- shadow[2] = lar->shdwb;
-
- if (lar->mode & LA_SHAD_TEX)
- do_lamp_tex(lar, lv, shi, shadow, LA_SHAD_TEX);
-
- if (R.r.mode & R_SHADOW) {
- lamp_get_shadow(lar, shi, inp, shadfac, shi->depth);
-
- shadow[0] = 1.0f - ((1.0f - shadfac[0] * shadfac[3]) * (1.0f - shadow[0]));
- shadow[1] = 1.0f - ((1.0f - shadfac[1] * shadfac[3]) * (1.0f - shadow[1]));
- shadow[2] = 1.0f - ((1.0f - shadfac[2] * shadfac[3]) * (1.0f - shadow[2]));
- }
- }
-
- return visifac;
-}
-
-float RE_lamp_get_data(ShadeInput *shi, Object *lamp_obj, float col[4], float lv[3], float *dist, float shadow[4])
-{
- col[0] = col[1] = col[2] = 0.0f;
- col[3] = 1.0f;
- copy_v3_v3(lv, shi->vn);
- *dist = 1.0f;
- shadow[0] = shadow[1] = shadow[2] = shadow[3] = 1.0f;
-
- if (lamp_obj->type == OB_LAMP) {
- GroupObject *go;
- Lamp *lamp = (Lamp *)lamp_obj->data;
-
- col[0] = lamp->r * lamp->energy;
- col[1] = lamp->g * lamp->energy;
- col[2] = lamp->b * lamp->energy;
-
- if (R.r.scemode & R_BUTS_PREVIEW) {
- for (go = R.lights.first; go; go = go->next) {
- /* "Lamp.002" is main key light of material preview */
- if (STREQ(go->ob->id.name + 2, "Lamp.002"))
- return lamp_get_data_internal(shi, go, col, lv, dist, shadow);
- }
- return 0.0f;
- }
-
- if (shi->light_override) {
- for (go = shi->light_override->gobject.first; go; go = go->next) {
- if (go->ob == lamp_obj)
- return lamp_get_data_internal(shi, go, col, lv, dist, shadow);
- }
- }
-
- if (shi->mat && shi->mat->group) {
- for (go = shi->mat->group->gobject.first; go; go = go->next) {
- if (go->ob == lamp_obj)
- return lamp_get_data_internal(shi, go, col, lv, dist, shadow);
- }
- }
-
- for (go = R.lights.first; go; go = go->next) {
- if (go->ob == lamp_obj)
- return lamp_get_data_internal(shi, go, col, lv, dist, shadow);
- }
- }
-
- return 0.0f;
-}
-
-const float (*RE_object_instance_get_matrix(struct ObjectInstanceRen *obi, int matrix_id))[4]
-{
- if (obi) {
- switch (matrix_id) {
- case RE_OBJECT_INSTANCE_MATRIX_OB:
- return (const float(*)[4])obi->obmat;
- case RE_OBJECT_INSTANCE_MATRIX_OBINV:
- return (const float(*)[4])obi->obinvmat;
- case RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEW:
- return (const float(*)[4])obi->localtoviewmat;
- case RE_OBJECT_INSTANCE_MATRIX_LOCALTOVIEWINV:
- return (const float(*)[4])obi->localtoviewinvmat;
- }
- }
- return NULL;
-}
-
-float RE_object_instance_get_object_pass_index(struct ObjectInstanceRen *obi)
-{
- return obi->ob->index;
-}
-
-float RE_object_instance_get_random_id(struct ObjectInstanceRen *obi)
-{
- return obi->random_id;
-}
-
-const float (*RE_render_current_get_matrix(int matrix_id))[4]
-{
- switch (matrix_id) {
- case RE_VIEW_MATRIX:
- return (const float(*)[4])R.viewmat;
- case RE_VIEWINV_MATRIX:
- return (const float(*)[4])R.viewinv;
- }
- return NULL;
-}
-
-float RE_fresnel_dielectric(float incoming[3], float normal[3], float eta)
-{
- /* compute fresnel reflectance without explicitly computing
- * the refracted direction */
- float c = fabs(dot_v3v3(incoming, normal));
- float g = eta * eta - 1.0 + c * c;
- float result;
-
- if (g > 0.0) {
- g = sqrtf(g);
- float A = (g - c) / (g + c);
- float B = (c * (g + c) - 1.0) / (c * (g - c) + 1.0);
- result = 0.5 * A * A * (1.0 + B * B);
- }
- else {
- result = 1.0; /* TIR (no refracted component) */
- }
-
- return result;
-}
diff --git a/source/blender/render/intern/source/sss.c b/source/blender/render/intern/source/sss.c
deleted file mode 100644
index c29da9b17c6..00000000000
--- a/source/blender/render/intern/source/sss.c
+++ /dev/null
@@ -1,1074 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2007 Blender Foundation.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/sss.c
- * \ingroup render
- */
-
-/* Possible Improvements:
- * - add fresnel terms
- * - adapt Rd table to scale, now with small scale there are a lot of misses?
- * - possible interesting method: perform sss on all samples in the tree,
- * and then use those values interpolated somehow later. can also do this
- * filtering on demand for speed. since we are doing things in screen
- * space now there is an exact correspondence
- * - avoid duplicate shading (filtering points in advance, irradiance cache
- * like lookup?)
- * - lower resolution samples
- */
-
-#include <math.h>
-#include <string.h>
-#include <stdio.h>
-#include <string.h>
-
-/* external modules: */
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BLI_memarena.h"
-
-#include "BLT_translation.h"
-
-
-#include "DNA_material_types.h"
-
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_scene.h"
-
-
-/* this module */
-#include "render_types.h"
-#include "sss.h"
-
-/* Generic Multiple Scattering API */
-
-/* Relevant papers:
- * [1] A Practical Model for Subsurface Light Transport
- * [2] A Rapid Hierarchical Rendering Technique for Translucent Materials
- * [3] Efficient Rendering of Local Subsurface Scattering
- * [4] Implementing a skin BSSRDF (or several...)
- */
-
-/* Defines */
-
-#define RD_TABLE_RANGE 100.0f
-#define RD_TABLE_RANGE_2 10000.0f
-#define RD_TABLE_SIZE 10000
-
-#define MAX_OCTREE_NODE_POINTS 8
-#define MAX_OCTREE_DEPTH 15
-
-/* Struct Definitions */
-
-struct ScatterSettings {
- float eta; /* index of refraction */
- float sigma_a; /* absorption coefficient */
- float sigma_s_; /* reduced scattering coefficient */
- float sigma_t_; /* reduced extinction coefficient */
- float sigma; /* effective extinction coefficient */
- float Fdr; /* diffuse fresnel reflectance */
- float D; /* diffusion constant */
- float A;
- float alpha_; /* reduced albedo */
- float zr; /* distance of virtual lightsource above surface */
- float zv; /* distance of virtual lightsource below surface */
- float ld; /* mean free path */
- float ro; /* diffuse reflectance */
- float color;
- float invsigma_t_;
- float frontweight;
- float backweight;
-
- float *tableRd; /* lookup table to avoid computing Rd */
- float *tableRd2; /* lookup table to avoid computing Rd for bigger values */
-};
-
-typedef struct ScatterPoint {
- float co[3];
- float rad[3];
- float area;
- int back;
-} ScatterPoint;
-
-typedef struct ScatterNode {
- float co[3];
- float rad[3];
- float backrad[3];
- float area, backarea;
-
- int totpoint;
- ScatterPoint *points;
-
- float split[3];
- struct ScatterNode *child[8];
-} ScatterNode;
-
-struct ScatterTree {
- MemArena *arena;
-
- ScatterSettings *ss[3];
- float error, scale;
-
- ScatterNode *root;
- ScatterPoint *points;
- ScatterPoint **refpoints;
- ScatterPoint **tmppoints;
- int totpoint;
- float min[3], max[3];
-};
-
-typedef struct ScatterResult {
- float rad[3];
- float backrad[3];
- float rdsum[3];
- float backrdsum[3];
-} ScatterResult;
-
-/* Functions for BSSRDF reparametrization in to more intuitive parameters,
- * see [2] section 4 for more info. */
-
-static float f_Rd(float alpha_, float A, float ro)
-{
- float sq;
-
- sq = sqrtf(3.0f * (1.0f - alpha_));
- return (alpha_/2.0f)*(1.0f + expf((-4.0f/3.0f)*A*sq))*expf(-sq) - ro;
-}
-
-static float compute_reduced_albedo(ScatterSettings *ss)
-{
- const float tolerance= 1e-8;
- const int max_iteration_count= 20;
- float d, fsub, xn_1= 0.0f, xn= 1.0f, fxn, fxn_1;
- int i;
-
- /* use secant method to compute reduced albedo using Rd function inverse
- * with a given reflectance */
- fxn= f_Rd(xn, ss->A, ss->ro);
- fxn_1= f_Rd(xn_1, ss->A, ss->ro);
-
- for (i= 0; i < max_iteration_count; i++) {
- fsub= (fxn - fxn_1);
- if (fabsf(fsub) < tolerance)
- break;
- d= ((xn - xn_1)/fsub)*fxn;
- if (fabsf(d) < tolerance)
- break;
-
- xn_1= xn;
- fxn_1= fxn;
- xn= xn - d;
-
- if (xn > 1.0f) xn= 1.0f;
- if (xn_1 > 1.0f) xn_1= 1.0f;
-
- fxn= f_Rd(xn, ss->A, ss->ro);
- }
-
- /* avoid division by zero later */
- if (xn <= 0.0f)
- xn= 0.00001f;
-
- return xn;
-}
-
-/* Exponential falloff functions */
-
-static float Rd_rsquare(ScatterSettings *ss, float rr)
-{
- float sr, sv, Rdr, Rdv;
-
- sr = sqrtf(rr + ss->zr * ss->zr);
- sv = sqrtf(rr + ss->zv * ss->zv);
-
- Rdr= ss->zr*(1.0f + ss->sigma*sr)*expf(-ss->sigma*sr)/(sr*sr*sr);
- Rdv= ss->zv*(1.0f + ss->sigma*sv)*expf(-ss->sigma*sv)/(sv*sv*sv);
-
- return /*ss->alpha_*/(1.0f/(4.0f*(float)M_PI))*(Rdr + Rdv);
-}
-
-static float Rd(ScatterSettings *ss, float r)
-{
- return Rd_rsquare(ss, r*r);
-}
-
-/* table lookups for Rd. this avoids expensive exp calls. we use two
- * separate tables as well for lower and higher numbers to improve
- * precision, since the number are poorly distributed because we do
- * a lookup with the squared distance for smaller distances, saving
- * another sqrt. */
-
-static void approximate_Rd_rgb(ScatterSettings **ss, float rr, float *rd)
-{
- float indexf, t, idxf;
- int index;
-
- if (rr > (RD_TABLE_RANGE_2 * RD_TABLE_RANGE_2)) {
- /* pass */
- }
- else if (rr > RD_TABLE_RANGE) {
- rr = sqrtf(rr);
- indexf= rr*(RD_TABLE_SIZE/RD_TABLE_RANGE_2);
- index= (int)indexf;
- idxf= (float)index;
- t= indexf - idxf;
-
- if (index >= 0 && index < RD_TABLE_SIZE) {
- rd[0]= (ss[0]->tableRd2[index]*(1-t) + ss[0]->tableRd2[index+1]*t);
- rd[1]= (ss[1]->tableRd2[index]*(1-t) + ss[1]->tableRd2[index+1]*t);
- rd[2]= (ss[2]->tableRd2[index]*(1-t) + ss[2]->tableRd2[index+1]*t);
- return;
- }
- }
- else {
- indexf= rr*(RD_TABLE_SIZE/RD_TABLE_RANGE);
- index= (int)indexf;
- idxf= (float)index;
- t= indexf - idxf;
-
- if (index >= 0 && index < RD_TABLE_SIZE) {
- rd[0]= (ss[0]->tableRd[index]*(1-t) + ss[0]->tableRd[index+1]*t);
- rd[1]= (ss[1]->tableRd[index]*(1-t) + ss[1]->tableRd[index+1]*t);
- rd[2]= (ss[2]->tableRd[index]*(1-t) + ss[2]->tableRd[index+1]*t);
- return;
- }
- }
-
- /* fallback to slow Rd computation */
- rd[0]= Rd_rsquare(ss[0], rr);
- rd[1]= Rd_rsquare(ss[1], rr);
- rd[2]= Rd_rsquare(ss[2], rr);
-}
-
-static void build_Rd_table(ScatterSettings *ss)
-{
- float r;
- int i, size = RD_TABLE_SIZE+1;
-
- ss->tableRd= MEM_mallocN(sizeof(float)*size, "scatterTableRd");
- ss->tableRd2= MEM_mallocN(sizeof(float)*size, "scatterTableRd");
-
- for (i= 0; i < size; i++) {
- r= i*(RD_TABLE_RANGE/RD_TABLE_SIZE);
-#if 0
- if (r < ss->invsigma_t_*ss->invsigma_t_) {
- r= ss->invsigma_t_*ss->invsigma_t_;
- }
-#endif
- ss->tableRd[i]= Rd(ss, sqrtf(r));
-
- r= i*(RD_TABLE_RANGE_2/RD_TABLE_SIZE);
-#if 0
- if (r < ss->invsigma_t_) {
- r= ss->invsigma_t_;
- }
-#endif
- ss->tableRd2[i]= Rd(ss, r);
- }
-}
-
-ScatterSettings *scatter_settings_new(float refl, float radius, float ior, float reflfac, float frontweight, float backweight)
-{
- ScatterSettings *ss;
-
- ss= MEM_callocN(sizeof(ScatterSettings), "ScatterSettings");
-
- /* see [1] and [3] for these formulas */
- ss->eta= ior;
- ss->Fdr= -1.440f/ior*ior + 0.710f/ior + 0.668f + 0.0636f*ior;
- ss->A= (1.0f + ss->Fdr)/(1.0f - ss->Fdr);
- ss->ld= radius;
- ss->ro= min_ff(refl, 0.99f);
- ss->color= ss->ro*reflfac + (1.0f-reflfac);
-
- ss->alpha_= compute_reduced_albedo(ss);
-
- ss->sigma= 1.0f/ss->ld;
- ss->sigma_t_= ss->sigma/sqrtf(3.0f*(1.0f - ss->alpha_));
- ss->sigma_s_= ss->alpha_*ss->sigma_t_;
- ss->sigma_a= ss->sigma_t_ - ss->sigma_s_;
-
- ss->D= 1.0f/(3.0f*ss->sigma_t_);
-
- ss->zr= 1.0f/ss->sigma_t_;
- ss->zv= ss->zr + 4.0f*ss->A*ss->D;
-
- ss->invsigma_t_= 1.0f/ss->sigma_t_;
-
- ss->frontweight= frontweight;
- ss->backweight= backweight;
-
- /* precompute a table of Rd values for quick lookup */
- build_Rd_table(ss);
-
- return ss;
-}
-
-void scatter_settings_free(ScatterSettings *ss)
-{
- MEM_freeN(ss->tableRd);
- MEM_freeN(ss->tableRd2);
- MEM_freeN(ss);
-}
-
-/* Hierarchical method as in [2]. */
-
-/* traversal */
-
-#define SUBNODE_INDEX(co, split) \
- ((co[0]>=split[0]) + (co[1]>=split[1])*2 + (co[2]>=split[2])*4)
-
-static void add_radiance(ScatterTree *tree, float *frontrad, float *backrad, float area, float backarea, float rr, ScatterResult *result)
-{
- float rd[3], frontrd[3], backrd[3];
-
- approximate_Rd_rgb(tree->ss, rr, rd);
-
- if (frontrad && area) {
- frontrd[0] = rd[0]*area;
- frontrd[1] = rd[1]*area;
- frontrd[2] = rd[2]*area;
-
- result->rad[0] += frontrad[0]*frontrd[0];
- result->rad[1] += frontrad[1]*frontrd[1];
- result->rad[2] += frontrad[2]*frontrd[2];
-
- result->rdsum[0] += frontrd[0];
- result->rdsum[1] += frontrd[1];
- result->rdsum[2] += frontrd[2];
- }
- if (backrad && backarea) {
- backrd[0] = rd[0]*backarea;
- backrd[1] = rd[1]*backarea;
- backrd[2] = rd[2]*backarea;
-
- result->backrad[0] += backrad[0]*backrd[0];
- result->backrad[1] += backrad[1]*backrd[1];
- result->backrad[2] += backrad[2]*backrd[2];
-
- result->backrdsum[0] += backrd[0];
- result->backrdsum[1] += backrd[1];
- result->backrdsum[2] += backrd[2];
- }
-}
-
-static void traverse_octree(ScatterTree *tree, ScatterNode *node, const float co[3], int self, ScatterResult *result)
-{
- float sub[3], dist;
- int i, index = 0;
-
- if (node->totpoint > 0) {
- /* leaf - add radiance from all samples */
- for (i=0; i<node->totpoint; i++) {
- ScatterPoint *p= &node->points[i];
-
- sub_v3_v3v3(sub, co, p->co);
- dist= dot_v3v3(sub, sub);
-
- if (p->back)
- add_radiance(tree, NULL, p->rad, 0.0f, p->area, dist, result);
- else
- add_radiance(tree, p->rad, NULL, p->area, 0.0f, dist, result);
- }
- }
- else {
- /* branch */
- if (self)
- index = SUBNODE_INDEX(co, node->split);
-
- for (i=0; i<8; i++) {
- if (node->child[i]) {
- ScatterNode *subnode= node->child[i];
-
- if (self && index == i) {
- /* always traverse node containing the point */
- traverse_octree(tree, subnode, co, 1, result);
- }
- else {
- /* decide subnode traversal based on maximum solid angle */
- sub_v3_v3v3(sub, co, subnode->co);
- dist= dot_v3v3(sub, sub);
-
- /* actually area/dist > error, but this avoids division */
- if (subnode->area+subnode->backarea>tree->error*dist) {
- traverse_octree(tree, subnode, co, 0, result);
- }
- else {
- add_radiance(tree, subnode->rad, subnode->backrad,
- subnode->area, subnode->backarea, dist, result);
- }
- }
- }
- }
- }
-}
-
-static void compute_radiance(ScatterTree *tree, const float co[3], float *rad)
-{
- ScatterResult result;
- float rdsum[3], backrad[3], backrdsum[3];
-
- memset(&result, 0, sizeof(result));
-
- traverse_octree(tree, tree->root, co, 1, &result);
-
- /* the original paper doesn't do this, but we normalize over the
- * sampled area and multiply with the reflectance. this is because
- * our point samples are incomplete, there are no samples on parts
- * of the mesh not visible from the camera. this can not only make
- * it darker, but also lead to ugly color shifts */
-
- mul_v3_fl(result.rad, tree->ss[0]->frontweight);
- mul_v3_fl(result.backrad, tree->ss[0]->backweight);
-
- copy_v3_v3(rad, result.rad);
- add_v3_v3v3(backrad, result.rad, result.backrad);
-
- copy_v3_v3(rdsum, result.rdsum);
- add_v3_v3v3(backrdsum, result.rdsum, result.backrdsum);
-
- if (rdsum[0] > 1e-16f) rad[0]= tree->ss[0]->color*rad[0]/rdsum[0];
- if (rdsum[1] > 1e-16f) rad[1]= tree->ss[1]->color*rad[1]/rdsum[1];
- if (rdsum[2] > 1e-16f) rad[2]= tree->ss[2]->color*rad[2]/rdsum[2];
-
- if (backrdsum[0] > 1e-16f) backrad[0]= tree->ss[0]->color*backrad[0]/backrdsum[0];
- if (backrdsum[1] > 1e-16f) backrad[1]= tree->ss[1]->color*backrad[1]/backrdsum[1];
- if (backrdsum[2] > 1e-16f) backrad[2]= tree->ss[2]->color*backrad[2]/backrdsum[2];
-
- rad[0]= MAX2(rad[0], backrad[0]);
- rad[1]= MAX2(rad[1], backrad[1]);
- rad[2]= MAX2(rad[2], backrad[2]);
-}
-
-/* building */
-
-static void sum_leaf_radiance(ScatterTree *UNUSED(tree), ScatterNode *node)
-{
- ScatterPoint *p;
- float rad, totrad= 0.0f, inv;
- int i;
-
- node->co[0]= node->co[1]= node->co[2]= 0.0;
- node->rad[0]= node->rad[1]= node->rad[2]= 0.0;
- node->backrad[0]= node->backrad[1]= node->backrad[2]= 0.0;
-
- /* compute total rad, rad weighted average position,
- * and total area */
- for (i=0; i<node->totpoint; i++) {
- p= &node->points[i];
-
- rad= p->area*fabsf(p->rad[0] + p->rad[1] + p->rad[2]);
- totrad += rad;
-
- node->co[0] += rad*p->co[0];
- node->co[1] += rad*p->co[1];
- node->co[2] += rad*p->co[2];
-
- if (p->back) {
- node->backrad[0] += p->rad[0]*p->area;
- node->backrad[1] += p->rad[1]*p->area;
- node->backrad[2] += p->rad[2]*p->area;
-
- node->backarea += p->area;
- }
- else {
- node->rad[0] += p->rad[0]*p->area;
- node->rad[1] += p->rad[1]*p->area;
- node->rad[2] += p->rad[2]*p->area;
-
- node->area += p->area;
- }
- }
-
- if (node->area > 1e-16f) {
- inv= 1.0f/node->area;
- node->rad[0] *= inv;
- node->rad[1] *= inv;
- node->rad[2] *= inv;
- }
- if (node->backarea > 1e-16f) {
- inv= 1.0f/node->backarea;
- node->backrad[0] *= inv;
- node->backrad[1] *= inv;
- node->backrad[2] *= inv;
- }
-
- if (totrad > 1e-16f) {
- inv= 1.0f/totrad;
- node->co[0] *= inv;
- node->co[1] *= inv;
- node->co[2] *= inv;
- }
- else {
- /* make sure that if radiance is 0.0f, we still have these points in
- * the tree at a good position, they count for rdsum too */
- for (i=0; i<node->totpoint; i++) {
- p= &node->points[i];
-
- node->co[0] += p->co[0];
- node->co[1] += p->co[1];
- node->co[2] += p->co[2];
- }
-
- node->co[0] /= node->totpoint;
- node->co[1] /= node->totpoint;
- node->co[2] /= node->totpoint;
- }
-}
-
-static void sum_branch_radiance(ScatterTree *UNUSED(tree), ScatterNode *node)
-{
- ScatterNode *subnode;
- float rad, totrad= 0.0f, inv;
- int i, totnode;
-
- node->co[0]= node->co[1]= node->co[2]= 0.0;
- node->rad[0]= node->rad[1]= node->rad[2]= 0.0;
- node->backrad[0]= node->backrad[1]= node->backrad[2]= 0.0;
-
- /* compute total rad, rad weighted average position,
- * and total area */
- for (i=0; i<8; i++) {
- if (node->child[i] == NULL)
- continue;
-
- subnode= node->child[i];
-
- rad= subnode->area*fabsf(subnode->rad[0] + subnode->rad[1] + subnode->rad[2]);
- rad += subnode->backarea*fabsf(subnode->backrad[0] + subnode->backrad[1] + subnode->backrad[2]);
- totrad += rad;
-
- node->co[0] += rad*subnode->co[0];
- node->co[1] += rad*subnode->co[1];
- node->co[2] += rad*subnode->co[2];
-
- node->rad[0] += subnode->rad[0]*subnode->area;
- node->rad[1] += subnode->rad[1]*subnode->area;
- node->rad[2] += subnode->rad[2]*subnode->area;
-
- node->backrad[0] += subnode->backrad[0]*subnode->backarea;
- node->backrad[1] += subnode->backrad[1]*subnode->backarea;
- node->backrad[2] += subnode->backrad[2]*subnode->backarea;
-
- node->area += subnode->area;
- node->backarea += subnode->backarea;
- }
-
- if (node->area > 1e-16f) {
- inv= 1.0f/node->area;
- node->rad[0] *= inv;
- node->rad[1] *= inv;
- node->rad[2] *= inv;
- }
- if (node->backarea > 1e-16f) {
- inv= 1.0f/node->backarea;
- node->backrad[0] *= inv;
- node->backrad[1] *= inv;
- node->backrad[2] *= inv;
- }
-
- if (totrad > 1e-16f) {
- inv= 1.0f/totrad;
- node->co[0] *= inv;
- node->co[1] *= inv;
- node->co[2] *= inv;
- }
- else {
- /* make sure that if radiance is 0.0f, we still have these points in
- * the tree at a good position, they count for rdsum too */
- totnode= 0;
-
- for (i=0; i<8; i++) {
- if (node->child[i]) {
- subnode= node->child[i];
-
- node->co[0] += subnode->co[0];
- node->co[1] += subnode->co[1];
- node->co[2] += subnode->co[2];
-
- totnode++;
- }
- }
-
- node->co[0] /= totnode;
- node->co[1] /= totnode;
- node->co[2] /= totnode;
- }
-}
-
-static void sum_radiance(ScatterTree *tree, ScatterNode *node)
-{
- if (node->totpoint > 0) {
- sum_leaf_radiance(tree, node);
- }
- else {
- int i;
-
- for (i=0; i<8; i++)
- if (node->child[i])
- sum_radiance(tree, node->child[i]);
-
- sum_branch_radiance(tree, node);
- }
-}
-
-static void subnode_middle(int i, float *mid, float *subsize, float *submid)
-{
- int x= i & 1, y= i & 2, z= i & 4;
-
- submid[0]= mid[0] + ((x)? subsize[0]: -subsize[0]);
- submid[1]= mid[1] + ((y)? subsize[1]: -subsize[1]);
- submid[2]= mid[2] + ((z)? subsize[2]: -subsize[2]);
-}
-
-static void create_octree_node(ScatterTree *tree, ScatterNode *node, float *mid, float *size, ScatterPoint **refpoints, int depth)
-{
- ScatterNode *subnode;
- ScatterPoint **subrefpoints, **tmppoints= tree->tmppoints;
- int index, nsize[8], noffset[8], i, subco, used_nodes, usedi;
- float submid[3], subsize[3];
-
- /* stopping condition */
- if (node->totpoint <= MAX_OCTREE_NODE_POINTS || depth == MAX_OCTREE_DEPTH) {
- for (i=0; i<node->totpoint; i++)
- node->points[i]= *(refpoints[i]);
-
- return;
- }
-
- subsize[0]= size[0]*0.5f;
- subsize[1]= size[1]*0.5f;
- subsize[2]= size[2]*0.5f;
-
- node->split[0]= mid[0];
- node->split[1]= mid[1];
- node->split[2]= mid[2];
-
- memset(nsize, 0, sizeof(nsize));
- memset(noffset, 0, sizeof(noffset));
-
- /* count points in subnodes */
- for (i=0; i<node->totpoint; i++) {
- index= SUBNODE_INDEX(refpoints[i]->co, node->split);
- tmppoints[i]= refpoints[i];
- nsize[index]++;
- }
-
- /* here we check if only one subnode is used. if this is the case, we don't
- * create a new node, but rather call this function again, with different
- * size and middle position for the same node. */
- for (usedi=0, used_nodes=0, i=0; i<8; i++) {
- if (nsize[i]) {
- used_nodes++;
- usedi = i;
- }
- if (i != 0)
- noffset[i]= noffset[i-1]+nsize[i-1];
- }
-
- if (used_nodes <= 1) {
- subnode_middle(usedi, mid, subsize, submid);
- create_octree_node(tree, node, submid, subsize, refpoints, depth+1);
- return;
- }
-
- /* reorder refpoints by subnode */
- for (i=0; i<node->totpoint; i++) {
- index= SUBNODE_INDEX(tmppoints[i]->co, node->split);
- refpoints[noffset[index]]= tmppoints[i];
- noffset[index]++;
- }
-
- /* create subnodes */
- for (subco=0, i=0; i<8; subco+=nsize[i], i++) {
- if (nsize[i] > 0) {
- subnode= BLI_memarena_alloc(tree->arena, sizeof(ScatterNode));
- node->child[i]= subnode;
- subnode->points= node->points + subco;
- subnode->totpoint= nsize[i];
- subrefpoints= refpoints + subco;
-
- subnode_middle(i, mid, subsize, submid);
-
- create_octree_node(tree, subnode, submid, subsize, subrefpoints,
- depth+1);
- }
- else
- node->child[i]= NULL;
- }
-
- node->points= NULL;
- node->totpoint= 0;
-}
-
-/* public functions */
-
-ScatterTree *scatter_tree_new(ScatterSettings *ss[3], float scale, float error,
- float (*co)[3], float (*color)[3], float *area, int totpoint)
-{
- ScatterTree *tree;
- ScatterPoint *points, **refpoints;
- int i;
-
- /* allocate tree */
- tree= MEM_callocN(sizeof(ScatterTree), "ScatterTree");
- tree->scale= scale;
- tree->error= error;
- tree->totpoint= totpoint;
-
- tree->ss[0]= ss[0];
- tree->ss[1]= ss[1];
- tree->ss[2]= ss[2];
-
- points = MEM_callocN(sizeof(ScatterPoint) * totpoint, "ScatterPoints");
- refpoints = MEM_callocN(sizeof(ScatterPoint *) * totpoint, "ScatterRefPoints");
-
- tree->points= points;
- tree->refpoints= refpoints;
-
- /* build points */
- INIT_MINMAX(tree->min, tree->max);
-
- for (i=0; i<totpoint; i++) {
- copy_v3_v3(points[i].co, co[i]);
- copy_v3_v3(points[i].rad, color[i]);
- points[i].area= fabsf(area[i])/(tree->scale*tree->scale);
- points[i].back= (area[i] < 0.0f);
-
- mul_v3_fl(points[i].co, 1.0f / tree->scale);
- minmax_v3v3_v3(tree->min, tree->max, points[i].co);
-
- refpoints[i]= points + i;
- }
-
- return tree;
-}
-
-void scatter_tree_build(ScatterTree *tree)
-{
- ScatterPoint *newpoints, **tmppoints;
- float mid[3], size[3];
- int totpoint= tree->totpoint;
-
- newpoints = MEM_callocN(sizeof(ScatterPoint) * totpoint, "ScatterPoints");
- tmppoints = MEM_callocN(sizeof(ScatterPoint *) * totpoint, "ScatterTmpPoints");
- tree->tmppoints= tmppoints;
-
- tree->arena= BLI_memarena_new(0x8000 * sizeof(ScatterNode), "sss tree arena");
- BLI_memarena_use_calloc(tree->arena);
-
- /* build tree */
- tree->root= BLI_memarena_alloc(tree->arena, sizeof(ScatterNode));
- tree->root->points= newpoints;
- tree->root->totpoint= totpoint;
-
- mid[0]= (tree->min[0]+tree->max[0])*0.5f;
- mid[1]= (tree->min[1]+tree->max[1])*0.5f;
- mid[2]= (tree->min[2]+tree->max[2])*0.5f;
-
- size[0]= (tree->max[0]-tree->min[0])*0.5f;
- size[1]= (tree->max[1]-tree->min[1])*0.5f;
- size[2]= (tree->max[2]-tree->min[2])*0.5f;
-
- create_octree_node(tree, tree->root, mid, size, tree->refpoints, 0);
-
- MEM_freeN(tree->points);
- MEM_freeN(tree->refpoints);
- MEM_freeN(tree->tmppoints);
- tree->refpoints= NULL;
- tree->tmppoints= NULL;
- tree->points= newpoints;
-
- /* sum radiance at nodes */
- sum_radiance(tree, tree->root);
-}
-
-void scatter_tree_sample(ScatterTree *tree, const float co[3], float color[3])
-{
- float sco[3];
-
- copy_v3_v3(sco, co);
- mul_v3_fl(sco, 1.0f / tree->scale);
-
- compute_radiance(tree, sco, color);
-}
-
-void scatter_tree_free(ScatterTree *tree)
-{
- if (tree->arena) BLI_memarena_free(tree->arena);
- if (tree->points) MEM_freeN(tree->points);
- if (tree->refpoints) MEM_freeN(tree->refpoints);
-
- MEM_freeN(tree);
-}
-
-/* Internal Renderer API */
-
-/* sss tree building */
-
-typedef struct SSSData {
- ScatterTree *tree;
- ScatterSettings *ss[3];
-} SSSData;
-
-typedef struct SSSPoints {
- struct SSSPoints *next, *prev;
-
- float (*co)[3];
- float (*color)[3];
- float *area;
- int totpoint;
-} SSSPoints;
-
-static void sss_create_tree_mat(Render *re, Material *mat)
-{
- SSSPoints *p;
- RenderResult *rr;
- ListBase points;
- float (*co)[3] = NULL, (*color)[3] = NULL, *area = NULL;
- int totpoint = 0, osa, osaflag, frsflag, partsdone;
-
- if (re->test_break(re->tbh))
- return;
-
- points.first= points.last= NULL;
-
- /* TODO: this is getting a bit ugly, copying all those variables and
- * setting them back, maybe we need to create our own Render? */
-
- /* do SSS preprocessing render */
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- rr= re->result;
- osa= re->osa;
- osaflag= re->r.mode & R_OSA;
- frsflag= re->r.mode & R_EDGE_FRS;
- partsdone= re->i.partsdone;
-
- re->osa= 0;
- re->r.mode &= ~(R_OSA | R_EDGE_FRS);
- re->sss_points= &points;
- re->sss_mat= mat;
- re->i.partsdone = 0;
-
- if (!(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW)))
- re->result= NULL;
- BLI_rw_mutex_unlock(&re->resultmutex);
-
- RE_TileProcessor(re);
-
- BLI_rw_mutex_lock(&re->resultmutex, THREAD_LOCK_WRITE);
- if (!(re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW))) {
- RE_FreeRenderResult(re->result);
- re->result= rr;
- }
- BLI_rw_mutex_unlock(&re->resultmutex);
-
- re->i.partsdone= partsdone;
- re->sss_mat= NULL;
- re->sss_points= NULL;
- re->osa= osa;
- if (osaflag) re->r.mode |= R_OSA;
- if (frsflag) re->r.mode |= R_EDGE_FRS;
-
- /* no points? no tree */
- if (!points.first)
- return;
-
- /* merge points together into a single buffer */
- if (!re->test_break(re->tbh)) {
- for (totpoint=0, p=points.first; p; p=p->next)
- totpoint += p->totpoint;
-
- co= MEM_mallocN(sizeof(*co)*totpoint, "SSSCo");
- color= MEM_mallocN(sizeof(*color)*totpoint, "SSSColor");
- area= MEM_mallocN(sizeof(*area)*totpoint, "SSSArea");
-
- for (totpoint=0, p=points.first; p; p=p->next) {
- memcpy(co+totpoint, p->co, sizeof(*co)*p->totpoint);
- memcpy(color+totpoint, p->color, sizeof(*color)*p->totpoint);
- memcpy(area+totpoint, p->area, sizeof(*area)*p->totpoint);
- totpoint += p->totpoint;
- }
- }
-
- /* free points */
- for (p=points.first; p; p=p->next) {
- MEM_freeN(p->co);
- MEM_freeN(p->color);
- MEM_freeN(p->area);
- }
- BLI_freelistN(&points);
-
- /* build tree */
- if (!re->test_break(re->tbh)) {
- SSSData *sss= MEM_callocN(sizeof(*sss), "SSSData");
- float ior= mat->sss_ior, cfac= mat->sss_colfac;
- const float *radius = mat->sss_radius;
- float fw= mat->sss_front, bw= mat->sss_back;
- float error = mat->sss_error;
-
- error= get_render_aosss_error(&re->r, error);
- if ((re->r.scemode & (R_BUTS_PREVIEW|R_VIEWPORT_PREVIEW)) && error < 0.5f)
- error= 0.5f;
-
- sss->ss[0]= scatter_settings_new(mat->sss_col[0], radius[0], ior, cfac, fw, bw);
- sss->ss[1]= scatter_settings_new(mat->sss_col[1], radius[1], ior, cfac, fw, bw);
- sss->ss[2]= scatter_settings_new(mat->sss_col[2], radius[2], ior, cfac, fw, bw);
- sss->tree= scatter_tree_new(sss->ss, mat->sss_scale, error,
- co, color, area, totpoint);
-
- MEM_freeN(co);
- MEM_freeN(color);
- MEM_freeN(area);
-
- scatter_tree_build(sss->tree);
-
- BLI_ghash_insert(re->sss_hash, mat, sss);
- }
- else {
- if (co) MEM_freeN(co);
- if (color) MEM_freeN(color);
- if (area) MEM_freeN(area);
- }
-}
-
-void sss_add_points(Render *re, float (*co)[3], float (*color)[3], float *area, int totpoint)
-{
- SSSPoints *p;
-
- if (totpoint > 0) {
- p= MEM_callocN(sizeof(SSSPoints), "SSSPoints");
-
- p->co= co;
- p->color= color;
- p->area= area;
- p->totpoint= totpoint;
-
- BLI_thread_lock(LOCK_CUSTOM1);
- BLI_addtail(re->sss_points, p);
- BLI_thread_unlock(LOCK_CUSTOM1);
- }
-}
-
-static void sss_free_tree(SSSData *sss)
-{
- scatter_tree_free(sss->tree);
- scatter_settings_free(sss->ss[0]);
- scatter_settings_free(sss->ss[1]);
- scatter_settings_free(sss->ss[2]);
- MEM_freeN(sss);
-}
-
-/* public functions */
-
-void make_sss_tree(Render *re)
-{
- Material *mat;
- bool infostr_set = false;
- const char *prevstr = NULL;
-
- free_sss(re);
-
- re->sss_hash= BLI_ghash_ptr_new("make_sss_tree gh");
-
- re->stats_draw(re->sdh, &re->i);
-
- for (mat= re->main->mat.first; mat; mat= mat->id.next) {
- if (mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS)) {
- if (!infostr_set) {
- prevstr = re->i.infostr;
- re->i.infostr = IFACE_("SSS preprocessing");
- infostr_set = true;
- }
-
- sss_create_tree_mat(re, mat);
- }
- }
-
- /* XXX preview exception */
- /* localizing preview render data is not fun for node trees :( */
- if (re->main!=G.main) {
- for (mat= G.main->mat.first; mat; mat= mat->id.next) {
- if (mat->id.us && (mat->flag & MA_IS_USED) && (mat->sss_flag & MA_DIFF_SSS)) {
- if (!infostr_set) {
- prevstr = re->i.infostr;
- re->i.infostr = IFACE_("SSS preprocessing");
- infostr_set = true;
- }
-
- sss_create_tree_mat(re, mat);
- }
- }
- }
-
- if (infostr_set)
- re->i.infostr = prevstr;
-}
-
-void free_sss(Render *re)
-{
- if (re->sss_hash) {
- GHashIterator gh_iter;
-
- GHASH_ITER (gh_iter, re->sss_hash) {
- sss_free_tree(BLI_ghashIterator_getValue(&gh_iter));
- }
-
- BLI_ghash_free(re->sss_hash, NULL, NULL);
- re->sss_hash= NULL;
- }
-}
-
-int sample_sss(Render *re, Material *mat, const float co[3], float color[3])
-{
- if (re->sss_hash) {
- SSSData *sss= BLI_ghash_lookup(re->sss_hash, mat);
-
- if (sss) {
- scatter_tree_sample(sss->tree, co, color);
- return 1;
- }
- else {
- color[0]= 0.0f;
- color[1]= 0.0f;
- color[2]= 0.0f;
- }
- }
-
- return 0;
-}
-
-int sss_pass_done(struct Render *re, struct Material *mat)
-{
- return ((re->flag & R_BAKING) || !(re->r.mode & R_SSS) || (re->sss_hash && BLI_ghash_lookup(re->sss_hash, mat)));
-}
-
diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c
deleted file mode 100644
index 6b52d4aa419..00000000000
--- a/source/blender/render/intern/source/strand.c
+++ /dev/null
@@ -1,1069 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributors: Brecht Van Lommel.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/strand.c
- * \ingroup render
- */
-
-
-#include <math.h>
-#include <string.h>
-#include <stdlib.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "DNA_key_types.h"
-#include "DNA_material_types.h"
-#include "DNA_meshdata_types.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BLI_memarena.h"
-#include "BLI_rand.h"
-
-#include "BKE_DerivedMesh.h"
-#include "BKE_key.h"
-
-
-#include "render_types.h"
-#include "rendercore.h"
-#include "renderdatabase.h"
-#include "shading.h"
-#include "strand.h"
-#include "zbuf.h"
-
-/* *************** */
-
-static float strand_eval_width(Material *ma, float strandco)
-{
- float fac;
-
- strandco= 0.5f*(strandco + 1.0f);
-
- if (ma->strand_ease!=0.0f) {
- if (ma->strand_ease<0.0f)
- fac= pow(strandco, 1.0f+ma->strand_ease);
- else
- fac= pow(strandco, 1.0f/(1.0f-ma->strand_ease));
- }
- else fac= strandco;
-
- return ((1.0f-fac)*ma->strand_sta + (fac)*ma->strand_end);
-}
-
-void strand_eval_point(StrandSegment *sseg, StrandPoint *spoint)
-{
- Material *ma;
- StrandBuffer *strandbuf;
- const float *simplify;
- float p[4][3], data[4], cross[3], w, dx, dy, t;
- int type;
-
- strandbuf= sseg->buffer;
- ma= sseg->buffer->ma;
- t= spoint->t;
- type= (strandbuf->flag & R_STRAND_BSPLINE)? KEY_BSPLINE: KEY_CARDINAL;
-
- copy_v3_v3(p[0], sseg->v[0]->co);
- copy_v3_v3(p[1], sseg->v[1]->co);
- copy_v3_v3(p[2], sseg->v[2]->co);
- copy_v3_v3(p[3], sseg->v[3]->co);
-
- if (sseg->obi->flag & R_TRANSFORMED) {
- mul_m4_v3(sseg->obi->mat, p[0]);
- mul_m4_v3(sseg->obi->mat, p[1]);
- mul_m4_v3(sseg->obi->mat, p[2]);
- mul_m4_v3(sseg->obi->mat, p[3]);
- }
-
- if (t == 0.0f) {
- copy_v3_v3(spoint->co, p[1]);
- spoint->strandco= sseg->v[1]->strandco;
-
- spoint->dtstrandco= (sseg->v[2]->strandco - sseg->v[0]->strandco);
- if (sseg->v[0] != sseg->v[1])
- spoint->dtstrandco *= 0.5f;
- }
- else if (t == 1.0f) {
- copy_v3_v3(spoint->co, p[2]);
- spoint->strandco= sseg->v[2]->strandco;
-
- spoint->dtstrandco= (sseg->v[3]->strandco - sseg->v[1]->strandco);
- if (sseg->v[3] != sseg->v[2])
- spoint->dtstrandco *= 0.5f;
- }
- else {
- key_curve_position_weights(t, data, type);
- spoint->co[0]= data[0]*p[0][0] + data[1]*p[1][0] + data[2]*p[2][0] + data[3]*p[3][0];
- spoint->co[1]= data[0]*p[0][1] + data[1]*p[1][1] + data[2]*p[2][1] + data[3]*p[3][1];
- spoint->co[2]= data[0]*p[0][2] + data[1]*p[1][2] + data[2]*p[2][2] + data[3]*p[3][2];
- spoint->strandco= (1.0f-t)*sseg->v[1]->strandco + t*sseg->v[2]->strandco;
- }
-
- key_curve_tangent_weights(t, data, type);
- spoint->dtco[0]= data[0]*p[0][0] + data[1]*p[1][0] + data[2]*p[2][0] + data[3]*p[3][0];
- spoint->dtco[1]= data[0]*p[0][1] + data[1]*p[1][1] + data[2]*p[2][1] + data[3]*p[3][1];
- spoint->dtco[2]= data[0]*p[0][2] + data[1]*p[1][2] + data[2]*p[2][2] + data[3]*p[3][2];
-
- normalize_v3_v3(spoint->tan, spoint->dtco);
- normalize_v3_v3(spoint->nor, spoint->co);
- negate_v3(spoint->nor);
-
- spoint->width= strand_eval_width(ma, spoint->strandco);
-
- /* simplification */
- simplify= RE_strandren_get_simplify(strandbuf->obr, sseg->strand, 0);
- spoint->alpha= (simplify)? simplify[1]: 1.0f;
-
- /* outer points */
- cross_v3_v3v3(cross, spoint->co, spoint->tan);
-
- w= spoint->co[2]*strandbuf->winmat[2][3] + strandbuf->winmat[3][3];
- dx= strandbuf->winx*cross[0]*strandbuf->winmat[0][0]/w;
- dy= strandbuf->winy*cross[1]*strandbuf->winmat[1][1]/w;
- w = sqrtf(dx * dx + dy * dy);
-
- if (w > 0.0f) {
- if (strandbuf->flag & R_STRAND_B_UNITS) {
- const float crosslen= len_v3(cross);
- w= 2.0f*crosslen*strandbuf->minwidth/w;
-
- if (spoint->width < w) {
- spoint->alpha= spoint->width/w;
- spoint->width= w;
- }
-
- if (simplify)
- /* squared because we only change width, not length */
- spoint->width *= simplify[0]*simplify[0];
-
- mul_v3_fl(cross, spoint->width*0.5f/crosslen);
- }
- else
- mul_v3_fl(cross, spoint->width/w);
- }
-
- sub_v3_v3v3(spoint->co1, spoint->co, cross);
- add_v3_v3v3(spoint->co2, spoint->co, cross);
-
- copy_v3_v3(spoint->dsco, cross);
-}
-
-/* *************** */
-
-static void interpolate_vec1(float *v1, float *v2, float t, float negt, float *v)
-{
- v[0]= negt*v1[0] + t*v2[0];
-}
-
-static void interpolate_vec3(float *v1, float *v2, float t, float negt, float *v)
-{
- v[0]= negt*v1[0] + t*v2[0];
- v[1]= negt*v1[1] + t*v2[1];
- v[2]= negt*v1[2] + t*v2[2];
-}
-
-static void interpolate_vec4(float *v1, float *v2, float t, float negt, float *v)
-{
- v[0]= negt*v1[0] + t*v2[0];
- v[1]= negt*v1[1] + t*v2[1];
- v[2]= negt*v1[2] + t*v2[2];
- v[3]= negt*v1[3] + t*v2[3];
-}
-
-static void interpolate_shade_result(ShadeResult *shr1, ShadeResult *shr2, float t, ShadeResult *shr, int addpassflag)
-{
- float negt= 1.0f - t;
-
- interpolate_vec4(shr1->combined, shr2->combined, t, negt, shr->combined);
-
- if (addpassflag & SCE_PASS_VECTOR) {
- interpolate_vec4(shr1->winspeed, shr2->winspeed, t, negt, shr->winspeed);
- }
- /* optim... */
- if (addpassflag & ~(SCE_PASS_VECTOR)) {
- if (addpassflag & SCE_PASS_Z)
- interpolate_vec1(&shr1->z, &shr2->z, t, negt, &shr->z);
- if (addpassflag & SCE_PASS_RGBA)
- interpolate_vec4(shr1->col, shr2->col, t, negt, shr->col);
- if (addpassflag & SCE_PASS_NORMAL) {
- interpolate_vec3(shr1->nor, shr2->nor, t, negt, shr->nor);
- normalize_v3(shr->nor);
- }
- if (addpassflag & SCE_PASS_EMIT)
- interpolate_vec3(shr1->emit, shr2->emit, t, negt, shr->emit);
- if (addpassflag & SCE_PASS_DIFFUSE) {
- interpolate_vec3(shr1->diff, shr2->diff, t, negt, shr->diff);
- interpolate_vec3(shr1->diffshad, shr2->diffshad, t, negt, shr->diffshad);
- }
- if (addpassflag & SCE_PASS_SPEC)
- interpolate_vec3(shr1->spec, shr2->spec, t, negt, shr->spec);
- if (addpassflag & SCE_PASS_SHADOW)
- interpolate_vec3(shr1->shad, shr2->shad, t, negt, shr->shad);
- if (addpassflag & SCE_PASS_AO)
- interpolate_vec3(shr1->ao, shr2->ao, t, negt, shr->ao);
- if (addpassflag & SCE_PASS_ENVIRONMENT)
- interpolate_vec3(shr1->env, shr2->env, t, negt, shr->env);
- if (addpassflag & SCE_PASS_INDIRECT)
- interpolate_vec3(shr1->indirect, shr2->indirect, t, negt, shr->indirect);
- if (addpassflag & SCE_PASS_REFLECT)
- interpolate_vec3(shr1->refl, shr2->refl, t, negt, shr->refl);
- if (addpassflag & SCE_PASS_REFRACT)
- interpolate_vec3(shr1->refr, shr2->refr, t, negt, shr->refr);
- if (addpassflag & SCE_PASS_MIST)
- interpolate_vec1(&shr1->mist, &shr2->mist, t, negt, &shr->mist);
- }
-}
-
-static void strand_apply_shaderesult_alpha(ShadeResult *shr, float alpha)
-{
- if (alpha < 1.0f) {
- shr->combined[0] *= alpha;
- shr->combined[1] *= alpha;
- shr->combined[2] *= alpha;
- shr->combined[3] *= alpha;
-
- shr->col[0] *= alpha;
- shr->col[1] *= alpha;
- shr->col[2] *= alpha;
- shr->col[3] *= alpha;
-
- shr->alpha *= alpha;
- }
-}
-
-static void strand_shade_point(Render *re, ShadeSample *ssamp, StrandSegment *sseg, StrandVert *svert, StrandPoint *spoint)
-{
- ShadeInput *shi= ssamp->shi;
- ShadeResult *shr= ssamp->shr;
- VlakRen vlr;
- int seed;
-
- memset(&vlr, 0, sizeof(vlr));
- vlr.flag= R_SMOOTH;
- if (sseg->buffer->ma->mode & MA_TANGENT_STR)
- vlr.flag |= R_TANGENT;
-
- shi->vlr= &vlr;
- shi->v1= NULL;
- shi->v2= NULL;
- shi->v3= NULL;
- shi->strand= sseg->strand;
- shi->obi= sseg->obi;
- shi->obr= sseg->obi->obr;
-
- /* cache for shadow */
- shi->samplenr= re->shadowsamplenr[shi->thread]++;
-
- /* all samples */
- shi->mask= 0xFFFF;
-
- /* seed RNG for consistent results across tiles */
- seed = shi->strand->index + (svert - shi->strand->vert);
- BLI_thread_srandom(shi->thread, seed);
-
- shade_input_set_strand(shi, sseg->strand, spoint);
- shade_input_set_strand_texco(shi, sseg->strand, sseg->v[1], spoint);
-
- /* init material vars */
- shade_input_init_material(shi);
-
- /* shade */
- shade_samples_do_AO(ssamp);
- shade_input_do_shade(shi, shr);
-
- /* apply simplification */
- strand_apply_shaderesult_alpha(shr, spoint->alpha);
-
- /* include lamphalos for strand, since halo layer was added already */
- if (re->flag & R_LAMPHALO)
- if (shi->layflag & SCE_LAY_HALO)
- renderspothalo(shi, shr->combined, shr->combined[3]);
-
- shi->strand= NULL;
-}
-
-/* *************** */
-
-struct StrandShadeCache {
- GHash *resulthash;
- GHash *refcounthash;
- MemArena *memarena;
-};
-
-typedef struct StrandCacheEntry {
- GHashPair pair;
- ShadeResult shr;
-} StrandCacheEntry;
-
-StrandShadeCache *strand_shade_cache_create(void)
-{
- StrandShadeCache *cache;
-
- cache= MEM_callocN(sizeof(StrandShadeCache), "StrandShadeCache");
- cache->resulthash= BLI_ghash_pair_new("strand_shade_cache_create1 gh");
- cache->refcounthash= BLI_ghash_pair_new("strand_shade_cache_create2 gh");
- cache->memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "strand shade cache arena");
-
- return cache;
-}
-
-void strand_shade_cache_free(StrandShadeCache *cache)
-{
- BLI_ghash_free(cache->refcounthash, NULL, NULL);
- BLI_ghash_free(cache->resulthash, MEM_freeN, NULL);
- BLI_memarena_free(cache->memarena);
- MEM_freeN(cache);
-}
-
-static GHashPair strand_shade_hash_pair(ObjectInstanceRen *obi, StrandVert *svert)
-{
- GHashPair pair = {obi, svert};
- return pair;
-}
-
-static void strand_shade_get(Render *re, StrandShadeCache *cache, ShadeSample *ssamp, StrandSegment *sseg, StrandVert *svert)
-{
- StrandCacheEntry *entry;
- StrandPoint p;
- int *refcount;
- GHashPair pair = strand_shade_hash_pair(sseg->obi, svert);
-
- entry= BLI_ghash_lookup(cache->resulthash, &pair);
- refcount= BLI_ghash_lookup(cache->refcounthash, &pair);
-
- if (!entry) {
- /* not shaded yet, shade and insert into hash */
- p.t= (sseg->v[1] == svert)? 0.0f: 1.0f;
- strand_eval_point(sseg, &p);
- strand_shade_point(re, ssamp, sseg, svert, &p);
-
- entry= MEM_callocN(sizeof(StrandCacheEntry), "StrandCacheEntry");
- entry->pair = pair;
- entry->shr = ssamp->shr[0];
- BLI_ghash_insert(cache->resulthash, entry, entry);
- }
- else
- /* already shaded, just copy previous result from hash */
- ssamp->shr[0]= entry->shr;
-
- /* lower reference count and remove if not needed anymore by any samples */
- (*refcount)--;
- if (*refcount == 0) {
- BLI_ghash_remove(cache->resulthash, &pair, MEM_freeN, NULL);
- BLI_ghash_remove(cache->refcounthash, &pair, NULL, NULL);
- }
-}
-
-void strand_shade_segment(Render *re, StrandShadeCache *cache, StrandSegment *sseg, ShadeSample *ssamp, float t, float s, int addpassflag)
-{
- ShadeResult shr1, shr2;
-
- /* get shading for two endpoints and interpolate */
- strand_shade_get(re, cache, ssamp, sseg, sseg->v[1]);
- shr1= ssamp->shr[0];
- strand_shade_get(re, cache, ssamp, sseg, sseg->v[2]);
- shr2= ssamp->shr[0];
-
- interpolate_shade_result(&shr1, &shr2, t, ssamp->shr, addpassflag);
-
- /* apply alpha along width */
- if (sseg->buffer->widthfade != -1.0f) {
- s = 1.0f - powf(fabsf(s), sseg->buffer->widthfade);
-
- strand_apply_shaderesult_alpha(ssamp->shr, s);
- }
-}
-
-void strand_shade_unref(StrandShadeCache *cache, ObjectInstanceRen *obi, StrandVert *svert)
-{
- GHashPair pair = strand_shade_hash_pair(obi, svert);
- int *refcount;
-
- /* lower reference count and remove if not needed anymore by any samples */
- refcount= BLI_ghash_lookup(cache->refcounthash, &pair);
-
- (*refcount)--;
- if (*refcount == 0) {
- BLI_ghash_remove(cache->resulthash, &pair, MEM_freeN, NULL);
- BLI_ghash_remove(cache->refcounthash, &pair, NULL, NULL);
- }
-}
-
-static void strand_shade_refcount(StrandShadeCache *cache, StrandSegment *sseg, StrandVert *svert)
-{
- GHashPair pair = strand_shade_hash_pair(sseg->obi, svert);
- GHashPair *key;
- int *refcount= BLI_ghash_lookup(cache->refcounthash, &pair);
-
- if (!refcount) {
- key= BLI_memarena_alloc(cache->memarena, sizeof(GHashPair));
- *key = pair;
- refcount= BLI_memarena_alloc(cache->memarena, sizeof(int));
- *refcount= 1;
- BLI_ghash_insert(cache->refcounthash, key, refcount);
- }
- else
- (*refcount)++;
-}
-
-/* *************** */
-
-typedef struct StrandPart {
- Render *re;
- ZSpan *zspan;
-
- APixstrand *apixbuf;
- int *totapixbuf;
- int *rectz;
- int *rectmask;
- intptr_t *rectdaps;
- int rectx, recty;
- int sample;
- int shadow;
- float (*jit)[2];
- int samples;
-
- StrandSegment *segment;
- float t[3], s[3];
-
- StrandShadeCache *cache;
-} StrandPart;
-
-typedef struct StrandSortSegment {
- struct StrandSortSegment *next;
- int obi, strand, segment;
- float z;
-} StrandSortSegment;
-
-static int compare_strand_segment(const void *poin1, const void *poin2)
-{
- const StrandSortSegment *seg1= (const StrandSortSegment*)poin1;
- const StrandSortSegment *seg2= (const StrandSortSegment*)poin2;
-
- if (seg1->z < seg2->z)
- return -1;
- else if (seg1->z == seg2->z)
- return 0;
- else
- return 1;
-}
-
-static void do_strand_point_project(float winmat[4][4], ZSpan *zspan, float *co, float *hoco, float *zco)
-{
- projectvert(co, winmat, hoco);
- hoco_to_zco(zspan, zco, hoco);
-}
-
-static void strand_project_point(float winmat[4][4], float winx, float winy, StrandPoint *spoint)
-{
- float div;
-
- projectvert(spoint->co, winmat, spoint->hoco);
-
- div= 1.0f/spoint->hoco[3];
- spoint->x= spoint->hoco[0]*div*winx*0.5f;
- spoint->y= spoint->hoco[1]*div*winy*0.5f;
-}
-
-static APixstrand *addpsmainAstrand(ListBase *lb)
-{
- APixstrMain *psm;
-
- psm= MEM_mallocN(sizeof(APixstrMain), "addpsmainA");
- BLI_addtail(lb, psm);
- psm->ps = MEM_callocN(4096 * sizeof(APixstrand), "pixstr");
-
- return psm->ps;
-}
-
-static APixstrand *addpsAstrand(ZSpan *zspan)
-{
- /* make new PS */
- if (zspan->apstrandmcounter==0) {
- zspan->curpstrand= addpsmainAstrand(zspan->apsmbase);
- zspan->apstrandmcounter= 4095;
- }
- else {
- zspan->curpstrand++;
- zspan->apstrandmcounter--;
- }
- return zspan->curpstrand;
-}
-
-#define MAX_ZROW 2000
-
-static void do_strand_fillac(void *handle, int x, int y, float u, float v, float z)
-{
- StrandPart *spart= (StrandPart *)handle;
- StrandShadeCache *cache= spart->cache;
- StrandSegment *sseg= spart->segment;
- APixstrand *apn, *apnew;
- float t, s;
- int offset, mask, obi, strnr, seg, zverg, bufferz, maskz=0;
-
- offset = y*spart->rectx + x;
- obi= sseg->obi - spart->re->objectinstance;
- strnr= sseg->strand->index + 1;
- seg= sseg->v[1] - sseg->strand->vert;
- mask= (1<<spart->sample);
-
- /* check against solid z-buffer */
- zverg= (int)z;
-
- if (spart->rectdaps) {
- /* find the z of the sample */
- PixStr *ps;
- intptr_t *rd= spart->rectdaps + offset;
-
- bufferz= 0x7FFFFFFF;
- if (spart->rectmask) maskz= 0x7FFFFFFF;
-
- if (*rd) {
- for (ps= (PixStr *)(*rd); ps; ps= ps->next) {
- if (mask & ps->mask) {
- bufferz= ps->z;
- if (spart->rectmask)
- maskz= ps->maskz;
- break;
- }
- }
- }
- }
- else {
- bufferz= (spart->rectz)? spart->rectz[offset]: 0x7FFFFFFF;
- if (spart->rectmask)
- maskz= spart->rectmask[offset];
- }
-
-#define CHECK_ADD(n) \
- if (apn->p[n]==strnr && apn->obi[n]==obi && apn->seg[n]==seg) \
- { if (!(apn->mask[n] & mask)) { apn->mask[n] |= mask; apn->v[n] += t; apn->u[n] += s; } break; } (void)0
-#define CHECK_ASSIGN(n) \
- if (apn->p[n]==0) \
- {apn->obi[n]= obi; apn->p[n]= strnr; apn->z[n]= zverg; apn->mask[n]= mask; apn->v[n]= t; apn->u[n]= s; apn->seg[n]= seg; break; } (void)0
-
- /* add to pixel list */
- if (zverg < bufferz && (spart->totapixbuf[offset] < MAX_ZROW)) {
- if (!spart->rectmask || zverg > maskz) {
- t = u * spart->t[0] + v * spart->t[1] + (1.0f - u - v) * spart->t[2];
- s = fabsf(u * spart->s[0] + v * spart->s[1] + (1.0f - u - v) * spart->s[2]);
-
- apn= spart->apixbuf + offset;
- while (apn) {
- CHECK_ADD(0);
- CHECK_ADD(1);
- CHECK_ADD(2);
- CHECK_ADD(3);
- CHECK_ASSIGN(0);
- CHECK_ASSIGN(1);
- CHECK_ASSIGN(2);
- CHECK_ASSIGN(3);
-
- apnew= addpsAstrand(spart->zspan);
- SWAP(APixstrand, *apnew, *apn);
- apn->next= apnew;
- CHECK_ASSIGN(0);
- }
-
- if (cache) {
- strand_shade_refcount(cache, sseg, sseg->v[1]);
- strand_shade_refcount(cache, sseg, sseg->v[2]);
- }
- spart->totapixbuf[offset]++;
- }
- }
-}
-
-/* width is calculated in hoco space, to ensure strands are visible */
-static int strand_test_clip(float winmat[4][4], ZSpan *UNUSED(zspan), float *bounds, float *co, float *zcomp, float widthx, float widthy)
-{
- float hoco[4];
- int clipflag= 0;
-
- projectvert(co, winmat, hoco);
-
- /* we compare z without perspective division for segment sorting */
- *zcomp= hoco[2];
-
- if (hoco[0]+widthx < bounds[0]*hoco[3]) clipflag |= 1;
- else if (hoco[0]-widthx > bounds[1]*hoco[3]) clipflag |= 2;
-
- if (hoco[1]-widthy > bounds[3]*hoco[3]) clipflag |= 4;
- else if (hoco[1]+widthy < bounds[2]*hoco[3]) clipflag |= 8;
-
- clipflag |= testclip(hoco);
-
- return clipflag;
-}
-
-static void do_scanconvert_strand(Render *UNUSED(re), StrandPart *spart, ZSpan *zspan, float t, float dt, float *co1, float *co2, float *co3, float *co4, int sample)
-{
- float jco1[3], jco2[3], jco3[3], jco4[3], jx, jy;
-
- copy_v3_v3(jco1, co1);
- copy_v3_v3(jco2, co2);
- copy_v3_v3(jco3, co3);
- copy_v3_v3(jco4, co4);
-
- if (spart->jit) {
- jx= -spart->jit[sample][0];
- jy= -spart->jit[sample][1];
-
- jco1[0] += jx; jco1[1] += jy;
- jco2[0] += jx; jco2[1] += jy;
- jco3[0] += jx; jco3[1] += jy;
- jco4[0] += jx; jco4[1] += jy;
-
- /* XXX mblur? */
- }
-
- spart->sample= sample;
-
- spart->t[0]= t-dt;
- spart->s[0]= -1.0f;
- spart->t[1]= t-dt;
- spart->s[1]= 1.0f;
- spart->t[2]= t;
- spart->s[2]= 1.0f;
- zspan_scanconvert_strand(zspan, spart, jco1, jco2, jco3, do_strand_fillac);
- spart->t[0]= t-dt;
- spart->s[0]= -1.0f;
- spart->t[1]= t;
- spart->s[1]= 1.0f;
- spart->t[2]= t;
- spart->s[2]= -1.0f;
- zspan_scanconvert_strand(zspan, spart, jco1, jco3, jco4, do_strand_fillac);
-}
-
-static void strand_render(Render *re, StrandSegment *sseg, float winmat[4][4], StrandPart *spart, ZSpan *zspan, int totzspan, StrandPoint *p1, StrandPoint *p2)
-{
- if (spart) {
- float t= p2->t;
- float dt= p2->t - p1->t;
- int a;
-
- for (a=0; a<spart->samples; a++)
- do_scanconvert_strand(re, spart, zspan, t, dt, p1->zco2, p1->zco1, p2->zco1, p2->zco2, a);
- }
- else {
- float hoco1[4], hoco2[4];
- int a, obi, index;
-
- obi= sseg->obi - re->objectinstance;
- index= sseg->strand->index;
-
- projectvert(p1->co, winmat, hoco1);
- projectvert(p2->co, winmat, hoco2);
-
-
- for (a=0; a<totzspan; a++) {
-#if 0
- /* render both strand and single pixel wire to counter aliasing */
- zbufclip4(re, &zspan[a], obi, index, p1->hoco2, p1->hoco1, p2->hoco1, p2->hoco2, p1->clip2, p1->clip1, p2->clip1, p2->clip2);
-#endif
- /* only render a line for now, which makes the shadow map more
- * similar across frames, and so reduces flicker */
- zbufsinglewire(&zspan[a], obi, index, hoco1, hoco2);
- }
- }
-}
-
-static int strand_segment_recursive(Render *re, float winmat[4][4], StrandPart *spart, ZSpan *zspan, int totzspan, StrandSegment *sseg, StrandPoint *p1, StrandPoint *p2, int depth)
-{
- StrandPoint p;
- StrandBuffer *buffer= sseg->buffer;
- float dot, d1[2], d2[2], len1, len2;
-
- if (depth == buffer->maxdepth)
- return 0;
-
- p.t= (p1->t + p2->t)*0.5f;
- strand_eval_point(sseg, &p);
- strand_project_point(buffer->winmat, buffer->winx, buffer->winy, &p);
-
- d1[0]= (p.x - p1->x);
- d1[1]= (p.y - p1->y);
- len1= d1[0]*d1[0] + d1[1]*d1[1];
-
- d2[0]= (p2->x - p.x);
- d2[1]= (p2->y - p.y);
- len2= d2[0]*d2[0] + d2[1]*d2[1];
-
- if (len1 == 0.0f || len2 == 0.0f)
- return 0;
-
- dot= d1[0]*d2[0] + d1[1]*d2[1];
- if (dot*dot > sseg->sqadaptcos*len1*len2)
- return 0;
-
- if (spart) {
- do_strand_point_project(winmat, zspan, p.co1, p.hoco1, p.zco1);
- do_strand_point_project(winmat, zspan, p.co2, p.hoco2, p.zco2);
- }
- else {
-#if 0
- projectvert(p.co1, winmat, p.hoco1);
- projectvert(p.co2, winmat, p.hoco2);
- p.clip1= testclip(p.hoco1);
- p.clip2= testclip(p.hoco2);
-#endif
- }
-
- if (!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, p1, &p, depth+1))
- strand_render(re, sseg, winmat, spart, zspan, totzspan, p1, &p);
- if (!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, &p, p2, depth+1))
- strand_render(re, sseg, winmat, spart, zspan, totzspan, &p, p2);
-
- return 1;
-}
-
-void render_strand_segment(Render *re, float winmat[4][4], StrandPart *spart, ZSpan *zspan, int totzspan, StrandSegment *sseg)
-{
- StrandBuffer *buffer= sseg->buffer;
- StrandPoint *p1= &sseg->point1;
- StrandPoint *p2= &sseg->point2;
-
- p1->t= 0.0f;
- p2->t= 1.0f;
-
- strand_eval_point(sseg, p1);
- strand_project_point(buffer->winmat, buffer->winx, buffer->winy, p1);
- strand_eval_point(sseg, p2);
- strand_project_point(buffer->winmat, buffer->winx, buffer->winy, p2);
-
- if (spart) {
- do_strand_point_project(winmat, zspan, p1->co1, p1->hoco1, p1->zco1);
- do_strand_point_project(winmat, zspan, p1->co2, p1->hoco2, p1->zco2);
- do_strand_point_project(winmat, zspan, p2->co1, p2->hoco1, p2->zco1);
- do_strand_point_project(winmat, zspan, p2->co2, p2->hoco2, p2->zco2);
- }
- else {
-#if 0
- projectvert(p1->co1, winmat, p1->hoco1);
- projectvert(p1->co2, winmat, p1->hoco2);
- projectvert(p2->co1, winmat, p2->hoco1);
- projectvert(p2->co2, winmat, p2->hoco2);
- p1->clip1= testclip(p1->hoco1);
- p1->clip2= testclip(p1->hoco2);
- p2->clip1= testclip(p2->hoco1);
- p2->clip2= testclip(p2->hoco2);
-#endif
- }
-
- if (!strand_segment_recursive(re, winmat, spart, zspan, totzspan, sseg, p1, p2, 0))
- strand_render(re, sseg, winmat, spart, zspan, totzspan, p1, p2);
-}
-
-/* render call to fill in strands */
-int zbuffer_strands_abuf(Render *re, RenderPart *pa, APixstrand *apixbuf, ListBase *apsmbase, unsigned int lay, int UNUSED(negzmask), float winmat[4][4], int winx, int winy, int samples, float (*jit)[2], float clipcrop, int shadow, StrandShadeCache *cache)
-{
- ObjectRen *obr;
- ObjectInstanceRen *obi;
- ZSpan zspan;
- StrandRen *strand = NULL;
- StrandVert *svert;
- StrandBound *sbound;
- StrandPart spart;
- StrandSegment sseg;
- StrandSortSegment *sortsegments = NULL, *sortseg, *firstseg;
- MemArena *memarena;
- float z[4], bounds[4], obwinmat[4][4];
- int a, b, c, i, totsegment, clip[4];
-
- if (re->test_break(re->tbh))
- return 0;
- if (re->totstrand == 0)
- return 0;
-
- /* setup StrandPart */
- memset(&spart, 0, sizeof(spart));
-
- spart.re= re;
- spart.rectx= pa->rectx;
- spart.recty= pa->recty;
- spart.apixbuf= apixbuf;
- spart.zspan= &zspan;
- spart.rectdaps= pa->rectdaps;
- spart.rectz= pa->rectz;
- spart.rectmask= pa->rectmask;
- spart.cache= cache;
- spart.shadow= shadow;
- spart.jit= jit;
- spart.samples= samples;
-
- zbuf_alloc_span(&zspan, pa->rectx, pa->recty, clipcrop);
-
- /* needed for transform from hoco to zbuffer co */
- zspan.zmulx= ((float)winx)/2.0f;
- zspan.zmuly= ((float)winy)/2.0f;
-
- zspan.zofsx= -pa->disprect.xmin;
- zspan.zofsy= -pa->disprect.ymin;
-
- /* to center the sample position */
- if (!shadow) {
- zspan.zofsx -= 0.5f;
- zspan.zofsy -= 0.5f;
- }
-
- zspan.apsmbase= apsmbase;
-
- /* clipping setup */
- bounds[0]= (2*pa->disprect.xmin - winx-1)/(float)winx;
- bounds[1]= (2*pa->disprect.xmax - winx+1)/(float)winx;
- bounds[2]= (2*pa->disprect.ymin - winy-1)/(float)winy;
- bounds[3]= (2*pa->disprect.ymax - winy+1)/(float)winy;
-
- memarena= BLI_memarena_new(BLI_MEMARENA_STD_BUFSIZE, "strand sort arena");
- firstseg= NULL;
- totsegment= 0;
-
- /* for all object instances */
- for (obi=re->instancetable.first, i=0; obi; obi=obi->next, i++) {
- Material *ma;
- float widthx, widthy;
-
- obr= obi->obr;
-
- if (!obr->strandbuf || !(obr->strandbuf->lay & lay))
- continue;
-
- /* compute matrix and try clipping whole object */
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(obwinmat, winmat, obi->mat);
- else
- copy_m4_m4(obwinmat, winmat);
-
- /* test if we should skip it */
- ma = obr->strandbuf->ma;
-
- if (shadow && (!(ma->mode2 & MA_CASTSHADOW) || !(ma->mode & MA_SHADBUF)))
- continue;
- else if (!shadow && (ma->mode & MA_ONLYCAST))
- continue;
-
- if (clip_render_object(obi->obr->boundbox, bounds, obwinmat))
- continue;
-
- widthx= obr->strandbuf->maxwidth*obwinmat[0][0];
- widthy= obr->strandbuf->maxwidth*obwinmat[1][1];
-
- /* for each bounding box containing a number of strands */
- sbound= obr->strandbuf->bound;
- for (c=0; c<obr->strandbuf->totbound; c++, sbound++) {
- if (clip_render_object(sbound->boundbox, bounds, obwinmat))
- continue;
-
- /* for each strand in this bounding box */
- for (a=sbound->start; a<sbound->end; a++) {
- strand= RE_findOrAddStrand(obr, a);
- svert= strand->vert;
-
- /* keep clipping and z depth for 4 control points */
- clip[1]= strand_test_clip(obwinmat, &zspan, bounds, svert->co, &z[1], widthx, widthy);
- clip[2]= strand_test_clip(obwinmat, &zspan, bounds, (svert+1)->co, &z[2], widthx, widthy);
- clip[0]= clip[1]; z[0]= z[1];
-
- for (b=0; b<strand->totvert-1; b++, svert++) {
- /* compute 4th point clipping and z depth */
- if (b < strand->totvert-2) {
- clip[3]= strand_test_clip(obwinmat, &zspan, bounds, (svert+2)->co, &z[3], widthx, widthy);
- }
- else {
- clip[3]= clip[2]; z[3]= z[2];
- }
-
- /* check clipping and add to sortsegments buffer */
- if (!(clip[0] & clip[1] & clip[2] & clip[3])) {
- sortseg= BLI_memarena_alloc(memarena, sizeof(StrandSortSegment));
- sortseg->obi= i;
- sortseg->strand= strand->index;
- sortseg->segment= b;
-
- sortseg->z= 0.5f*(z[1] + z[2]);
-
- sortseg->next= firstseg;
- firstseg= sortseg;
- totsegment++;
- }
-
- /* shift clipping and z depth */
- clip[0]= clip[1]; z[0]= z[1];
- clip[1]= clip[2]; z[1]= z[2];
- clip[2]= clip[3]; z[2]= z[3];
- }
- }
- }
- }
-
- if (!re->test_break(re->tbh)) {
- /* convert list to array and sort */
- sortsegments= MEM_mallocN(sizeof(StrandSortSegment)*totsegment, "StrandSortSegment");
- for (a=0, sortseg=firstseg; a<totsegment; a++, sortseg=sortseg->next)
- sortsegments[a]= *sortseg;
- qsort(sortsegments, totsegment, sizeof(StrandSortSegment), compare_strand_segment);
- }
-
- BLI_memarena_free(memarena);
-
- spart.totapixbuf= MEM_callocN(sizeof(int)*pa->rectx*pa->recty, "totapixbuf");
-
- if (!re->test_break(re->tbh)) {
- /* render segments in sorted order */
- sortseg= sortsegments;
- for (a=0; a<totsegment; a++, sortseg++) {
- if (re->test_break(re->tbh))
- break;
-
- obi= &re->objectinstance[sortseg->obi];
- obr= obi->obr;
-
- sseg.obi= obi;
- sseg.strand= RE_findOrAddStrand(obr, sortseg->strand);
- sseg.buffer= sseg.strand->buffer;
- sseg.sqadaptcos= sseg.buffer->adaptcos;
- sseg.sqadaptcos *= sseg.sqadaptcos;
-
- svert= sseg.strand->vert + sortseg->segment;
- sseg.v[0]= (sortseg->segment > 0)? (svert-1): svert;
- sseg.v[1]= svert;
- sseg.v[2]= svert+1;
- sseg.v[3]= (sortseg->segment < sseg.strand->totvert-2)? svert+2: svert+1;
- sseg.shaded= 0;
-
- spart.segment= &sseg;
-
- render_strand_segment(re, winmat, &spart, &zspan, 1, &sseg);
- }
- }
-
- if (sortsegments)
- MEM_freeN(sortsegments);
- MEM_freeN(spart.totapixbuf);
-
- zbuf_free_span(&zspan);
-
- return totsegment;
-}
-
-/* *************** */
-
-StrandSurface *cache_strand_surface(Render *re, ObjectRen *obr, DerivedMesh *dm, float mat[4][4], int timeoffset)
-{
- StrandSurface *mesh;
- MFace *mface;
- MVert *mvert;
- float (*co)[3];
- int a, totvert, totface;
-
- totvert= dm->getNumVerts(dm);
- totface= dm->getNumTessFaces(dm);
-
- for (mesh = re->strandsurface.first; mesh; mesh = mesh->next) {
- if ((mesh->obr.ob == obr->ob) &&
- (mesh->obr.par == obr->par) &&
- (mesh->obr.index == obr->index) &&
- (mesh->totvert == totvert) &&
- (mesh->totface == totface))
- {
- break;
- }
- }
-
- if (!mesh) {
- mesh= MEM_callocN(sizeof(StrandSurface), "StrandSurface");
- mesh->obr= *obr;
- mesh->totvert= totvert;
- mesh->totface= totface;
- mesh->face= MEM_callocN(sizeof(int)*4*mesh->totface, "StrandSurfFaces");
- mesh->ao= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfAO");
- mesh->env= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfEnv");
- mesh->indirect= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfIndirect");
- BLI_addtail(&re->strandsurface, mesh);
- }
-
- if (timeoffset == -1 && !mesh->prevco)
- mesh->prevco= co= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfCo");
- else if (timeoffset == 0 && !mesh->co)
- mesh->co= co= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfCo");
- else if (timeoffset == 1 && !mesh->nextco)
- mesh->nextco= co= MEM_callocN(sizeof(float)*3*mesh->totvert, "StrandSurfCo");
- else
- return mesh;
-
- mvert= dm->getVertArray(dm);
- for (a=0; a<mesh->totvert; a++, mvert++) {
- copy_v3_v3(co[a], mvert->co);
- mul_m4_v3(mat, co[a]);
- }
-
- mface= dm->getTessFaceArray(dm);
- for (a=0; a<mesh->totface; a++, mface++) {
- mesh->face[a][0]= mface->v1;
- mesh->face[a][1]= mface->v2;
- mesh->face[a][2]= mface->v3;
- mesh->face[a][3]= mface->v4;
- }
-
- return mesh;
-}
-
-void free_strand_surface(Render *re)
-{
- StrandSurface *mesh;
-
- for (mesh=re->strandsurface.first; mesh; mesh=mesh->next) {
- if (mesh->co) MEM_freeN(mesh->co);
- if (mesh->prevco) MEM_freeN(mesh->prevco);
- if (mesh->nextco) MEM_freeN(mesh->nextco);
- if (mesh->ao) MEM_freeN(mesh->ao);
- if (mesh->env) MEM_freeN(mesh->env);
- if (mesh->indirect) MEM_freeN(mesh->indirect);
- if (mesh->face) MEM_freeN(mesh->face);
- }
-
- BLI_freelistN(&re->strandsurface);
-}
-
-void strand_minmax(StrandRen *strand, float min[3], float max[3], const float width)
-{
- StrandVert *svert;
- const float width2 = width * 2.0f;
- float vec[3];
- int a;
-
- for (a=0, svert=strand->vert; a<strand->totvert; a++, svert++) {
- copy_v3_v3(vec, svert->co);
- minmax_v3v3_v3(min, max, vec);
-
- if (width!=0.0f) {
- add_v3_fl(vec, width);
- minmax_v3v3_v3(min, max, vec);
- add_v3_fl(vec, -width2);
- minmax_v3v3_v3(min, max, vec);
- }
- }
-}
-
diff --git a/source/blender/render/intern/source/sunsky.c b/source/blender/render/intern/source/sunsky.c
deleted file mode 100644
index f0cf29e98ca..00000000000
--- a/source/blender/render/intern/source/sunsky.c
+++ /dev/null
@@ -1,506 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/sunsky.c
- * \ingroup render
- *
- * This feature comes from Preetham paper on "A Practical Analytic Model for Daylight"
- * and example code from Brian Smits, another author of that paper in
- * http://www.cs.utah.edu/vissim/papers/sunsky/code/
- */
-
-#include "sunsky.h"
-#include "BLI_math.h"
-
-/**
- * These macros are defined for vector operations
- * */
-
-/**
- * compute v1 = v2 op v3
- * v1, v2 and v3 are vectors contains 3 float
- * */
-#define VEC3OPV(v1, v2, op, v3) \
- { \
- v1[0] = (v2[0] op v3[0]); \
- v1[1] = (v2[1] op v3[1]); \
- v1[2] = (v2[2] op v3[2]); \
- } (void)0
-
-/**
- * compute v1 = v2 op f1
- * v1, v2 are vectors contains 3 float
- * and f1 is a float
- * */
-#define VEC3OPF(v1, v2, op, f1) \
- { \
- v1[0] = (v2[0] op(f1)); \
- v1[1] = (v2[1] op(f1)); \
- v1[2] = (v2[2] op(f1)); \
- } (void)0
-
-/**
- * compute v1 = f1 op v2
- * v1, v2 are vectors contains 3 float
- * and f1 is a float
- * */
-#define FOPVEC3(v1, f1, op, v2) \
- { \
- v1[0] = ((f1) op v2[0]); \
- v1[1] = ((f1) op v2[1]); \
- v1[2] = ((f1) op v2[2]); \
- } (void)0
-
-/**
- * ClipColor:
- * clip a color to range [0, 1];
- * */
-void ClipColor(float c[3])
-{
- if (c[0] > 1.0f) c[0] = 1.0f;
- if (c[0] < 0.0f) c[0] = 0.0f;
- if (c[1] > 1.0f) c[1] = 1.0f;
- if (c[1] < 0.0f) c[1] = 0.0f;
- if (c[2] > 1.0f) c[2] = 1.0f;
- if (c[2] < 0.0f) c[2] = 0.0f;
-}
-
-/**
- * AngleBetween:
- * compute angle between to direction
- * all angles are in radians
- * */
-static float AngleBetween(float thetav, float phiv, float theta, float phi)
-{
- float cospsi = sinf(thetav) * sinf(theta) * cosf(phi - phiv) + cosf(thetav) * cosf(theta);
-
- if (cospsi > 1.0f)
- return 0;
- if (cospsi < -1.0f)
- return M_PI;
-
- return acosf(cospsi);
-}
-
-/**
- * DirectionToThetaPhi:
- * this function convert a direction to it's theta and phi value
- * parameters:
- * toSun: contains direction information
- * theta, phi, are return values from this conversion
- * */
-static void DirectionToThetaPhi(float *toSun, float *theta, float *phi)
-{
- *theta = acosf(toSun[2]);
- if (fabsf(*theta) < 1e-5f)
- *phi = 0;
- else
- *phi = atan2f(toSun[1], toSun[0]);
-}
-
-/**
- * PerezFunction:
- * compute perez function value based on input parameters
- */
-static float PerezFunction(struct SunSky *sunsky, const float *lam, float theta, float gamma, float lvz)
-{
- float den, num;
-
- den = ((1 + lam[0] * expf(lam[1])) *
- (1 + lam[2] * expf(lam[3] * sunsky->theta) + lam[4] * cosf(sunsky->theta) * cosf(sunsky->theta)));
-
- num = ((1 + lam[0] * expf(lam[1] / cosf(theta))) *
- (1 + lam[2] * expf(lam[3] * gamma) + lam[4] * cosf(gamma) * cosf(gamma)));
-
- return(lvz * num / den);
-}
-
-/**
- * InitSunSky:
- * this function compute some sun,sky parameters according to input parameters and also initiate some other sun, sky parameters
- * parameters:
- * sunSky, is a structure that contains information about sun, sky and atmosphere, in this function, most of its values initiated
- * turb, is atmosphere turbidity
- * toSun, contains sun direction
- * horizon_brighness, controls the brightness of the horizon colors
- * spread, controls colors spreed at horizon
- * sun_brightness, controls sun's brightness
- * sun_size, controls sun's size
- * back_scatter, controls back scatter light
- * */
-void InitSunSky(struct SunSky *sunsky, float turb, const float toSun[3], float horizon_brightness,
- float spread, float sun_brightness, float sun_size, float back_scatter,
- float skyblendfac, short skyblendtype, float sky_exposure, float sky_colorspace)
-{
- float theta2;
- float theta3;
- float T;
- float T2;
- float chi;
-
- sunsky->turbidity = turb;
-
- sunsky->horizon_brightness = horizon_brightness;
- sunsky->spread = spread;
- sunsky->sun_brightness = sun_brightness;
- sunsky->sun_size = sun_size;
- sunsky->backscattered_light = back_scatter;
- sunsky->skyblendfac = skyblendfac;
- sunsky->skyblendtype = skyblendtype;
- sunsky->sky_exposure = -sky_exposure;
- sunsky->sky_colorspace = sky_colorspace;
-
- sunsky->toSun[0] = toSun[0];
- sunsky->toSun[1] = toSun[1];
- sunsky->toSun[2] = toSun[2];
-
- DirectionToThetaPhi(sunsky->toSun, &sunsky->theta, &sunsky->phi);
-
- sunsky->sunSolidAngle = 0.25 * M_PI * 1.39 * 1.39 / (150 * 150); /* = 6.7443e-05 */
-
- theta2 = sunsky->theta * sunsky->theta;
- theta3 = theta2 * sunsky->theta;
- T = turb;
- T2 = turb * turb;
-
- chi = (4.0f / 9.0f - T / 120.0f) * ((float)M_PI - 2.0f * sunsky->theta);
- sunsky->zenith_Y = (4.0453f * T - 4.9710f) * tanf(chi) - 0.2155f * T + 2.4192f;
- sunsky->zenith_Y *= 1000; /* conversion from kcd/m^2 to cd/m^2 */
-
- if (sunsky->zenith_Y <= 0)
- sunsky->zenith_Y = 1e-6;
-
- sunsky->zenith_x =
- (+0.00165f * theta3 - 0.00374f * theta2 + 0.00208f * sunsky->theta + 0.0f) * T2 +
- (-0.02902f * theta3 + 0.06377f * theta2 - 0.03202f * sunsky->theta + 0.00394f) * T +
- (+0.11693f * theta3 - 0.21196f * theta2 + 0.06052f * sunsky->theta + 0.25885f);
-
- sunsky->zenith_y =
- (+0.00275f * theta3 - 0.00610f * theta2 + 0.00316f * sunsky->theta + 0.0f) * T2 +
- (-0.04214f * theta3 + 0.08970f * theta2 - 0.04153f * sunsky->theta + 0.00515f) * T +
- (+0.15346f * theta3 - 0.26756f * theta2 + 0.06669f * sunsky->theta + 0.26688f);
-
-
- sunsky->perez_Y[0] = 0.17872f * T - 1.46303f;
- sunsky->perez_Y[1] = -0.35540f * T + 0.42749f;
- sunsky->perez_Y[2] = -0.02266f * T + 5.32505f;
- sunsky->perez_Y[3] = 0.12064f * T - 2.57705f;
- sunsky->perez_Y[4] = -0.06696f * T + 0.37027f;
-
- sunsky->perez_x[0] = -0.01925f * T - 0.25922f;
- sunsky->perez_x[1] = -0.06651f * T + 0.00081f;
- sunsky->perez_x[2] = -0.00041f * T + 0.21247f;
- sunsky->perez_x[3] = -0.06409f * T - 0.89887f;
- sunsky->perez_x[4] = -0.00325f * T + 0.04517f;
-
- sunsky->perez_y[0] = -0.01669f * T - 0.26078f;
- sunsky->perez_y[1] = -0.09495f * T + 0.00921f;
- sunsky->perez_y[2] = -0.00792f * T + 0.21023f;
- sunsky->perez_y[3] = -0.04405f * T - 1.65369f;
- sunsky->perez_y[4] = -0.01092f * T + 0.05291f;
-
- /* suggested by glome in patch [#8063] */
- sunsky->perez_Y[0] *= sunsky->horizon_brightness;
- sunsky->perez_x[0] *= sunsky->horizon_brightness;
- sunsky->perez_y[0] *= sunsky->horizon_brightness;
-
- sunsky->perez_Y[1] *= sunsky->spread;
- sunsky->perez_x[1] *= sunsky->spread;
- sunsky->perez_y[1] *= sunsky->spread;
-
- sunsky->perez_Y[2] *= sunsky->sun_brightness;
- sunsky->perez_x[2] *= sunsky->sun_brightness;
- sunsky->perez_y[2] *= sunsky->sun_brightness;
-
- sunsky->perez_Y[3] *= sunsky->sun_size;
- sunsky->perez_x[3] *= sunsky->sun_size;
- sunsky->perez_y[3] *= sunsky->sun_size;
-
- sunsky->perez_Y[4] *= sunsky->backscattered_light;
- sunsky->perez_x[4] *= sunsky->backscattered_light;
- sunsky->perez_y[4] *= sunsky->backscattered_light;
-}
-
-/**
- * GetSkyXYZRadiance:
- * this function compute sky radiance according to a view parameters `theta' and `phi'and sunSky values
- * parameters:
- * sunSky, sontains sun and sky parameters
- * theta, is sun's theta
- * phi, is sun's phi
- * color_out, is computed color that shows sky radiance in XYZ color format
- * */
-void GetSkyXYZRadiance(struct SunSky *sunsky, float theta, float phi, float color_out[3])
-{
- float gamma;
- float x, y, Y, X, Z;
- float hfade = 1, nfade = 1;
-
-
- if (theta > (float)M_PI_2) {
- hfade = 1.0f - (theta * (float)M_1_PI - 0.5f) * 2.0f;
- hfade = hfade * hfade * (3.0f - 2.0f * hfade);
- theta = M_PI_2;
- }
-
- if (sunsky->theta > (float)M_PI_2) {
- if (theta <= (float)M_PI_2) {
- nfade = 1.0f - (0.5f - theta * (float)M_1_PI) * 2.0f;
- nfade *= 1.0f - (sunsky->theta * (float)M_1_PI - 0.5f) * 2.0f;
- nfade = nfade * nfade * (3.0f - 2.0f * nfade);
- }
- }
-
- gamma = AngleBetween(theta, phi, sunsky->theta, sunsky->phi);
-
- /* Compute xyY values */
- x = PerezFunction(sunsky, sunsky->perez_x, theta, gamma, sunsky->zenith_x);
- y = PerezFunction(sunsky, sunsky->perez_y, theta, gamma, sunsky->zenith_y);
- Y = 6.666666667e-5f * nfade * hfade * PerezFunction(sunsky, sunsky->perez_Y, theta, gamma, sunsky->zenith_Y);
-
- if (sunsky->sky_exposure != 0.0f)
- Y = 1.0 - exp(Y * sunsky->sky_exposure);
-
- X = (x / y) * Y;
- Z = ((1 - x - y) / y) * Y;
-
- color_out[0] = X;
- color_out[1] = Y;
- color_out[2] = Z;
-}
-
-/**
- * GetSkyXYZRadiancef:
- * this function compute sky radiance according to a view direction `varg' and sunSky values
- * parameters:
- * sunSky, sontains sun and sky parameters
- * varg, shows direction
- * color_out, is computed color that shows sky radiance in XYZ color format
- * */
-void GetSkyXYZRadiancef(struct SunSky *sunsky, const float varg[3], float color_out[3])
-{
- float theta, phi;
- float v[3];
-
- normalize_v3_v3(v, varg);
-
- if (v[2] < 0.001f) {
- v[2] = 0.001f;
- normalize_v3(v);
- }
-
- DirectionToThetaPhi(v, &theta, &phi);
- GetSkyXYZRadiance(sunsky, theta, phi, color_out);
-}
-
-/**
- * ComputeAttenuatedSunlight:
- * this function compute attenuated sun light based on sun's theta and atmosphere turbidity
- * parameters:
- * theta, is sun's theta
- * turbidity: is atmosphere turbidity
- * fTau: contains computed attenuated sun light
- * */
-static void ComputeAttenuatedSunlight(float theta, int turbidity, float fTau[3])
-{
- float fBeta;
- float fTauR, fTauA;
- float m;
- float fAlpha;
-
- int i;
- float fLambda[3];
- fLambda[0] = 0.65f;
- fLambda[1] = 0.57f;
- fLambda[2] = 0.475f;
-
- fAlpha = 1.3f;
- fBeta = 0.04608365822050f * turbidity - 0.04586025928522f;
-
- m = 1.0f / (cosf(theta) + 0.15f * powf(93.885f - theta / (float)M_PI * 180.0f, -1.253f));
-
- for (i = 0; i < 3; i++) {
- /* Rayleigh Scattering */
- fTauR = expf(-m * 0.008735f * powf(fLambda[i], (float)(-4.08f)));
-
- /* Aerosal (water + dust) attenuation */
- fTauA = exp(-m * fBeta * powf(fLambda[i], -fAlpha));
-
- fTau[i] = fTauR * fTauA;
- }
-}
-
-/**
- * InitAtmosphere:
- * this function initiate sunSky structure with user input parameters.
- * parameters:
- * sunSky, contains information about sun, and in this function some atmosphere parameters will initiated
- * sun_intens, shows sun intensity value
- * mief, Mie scattering factor this factor currently call with 1.0
- * rayf, Rayleigh scattering factor, this factor currently call with 1.0
- * inscattf, inscatter light factor that range from 0.0 to 1.0, 0.0 means no inscatter light and 1.0 means full inscatter light
- * extincf, extinction light factor that range from 0.0 to 1.0, 0.0 means no extinction and 1.0 means full extinction
- * disf, is distance factor, multiplied to pixle's z value to compute each pixle's distance to camera,
- * */
-void InitAtmosphere(struct SunSky *sunSky, float sun_intens, float mief, float rayf,
- float inscattf, float extincf, float disf)
-{
- const float pi = M_PI;
- const float n = 1.003f; /* refractive index */
- const float N = 2.545e25;
- const float pn = 0.035f;
- const float T = 2.0f;
- float fTemp, fTemp2, fTemp3, fBeta, fBetaDash;
- float c = (6.544f * T - 6.51f) * 1e-17f;
- float K[3] = {0.685f, 0.679f, 0.670f};
- float vBetaMieTemp[3];
-
- float fLambda[3], fLambda2[3], fLambda4[3];
- float vLambda2[3];
- float vLambda4[3];
-
- int i;
-
- sunSky->atm_SunIntensity = sun_intens;
- sunSky->atm_BetaMieMultiplier = mief;
- sunSky->atm_BetaRayMultiplier = rayf;
- sunSky->atm_InscatteringMultiplier = inscattf;
- sunSky->atm_ExtinctionMultiplier = extincf;
- sunSky->atm_DistanceMultiplier = disf;
-
- sunSky->atm_HGg = 0.8;
-
- fLambda[0] = 1 / 650e-9f;
- fLambda[1] = 1 / 570e-9f;
- fLambda[2] = 1 / 475e-9f;
- for (i = 0; i < 3; i++) {
- fLambda2[i] = fLambda[i] * fLambda[i];
- fLambda4[i] = fLambda2[i] * fLambda2[i];
- }
-
- vLambda2[0] = fLambda2[0];
- vLambda2[1] = fLambda2[1];
- vLambda2[2] = fLambda2[2];
-
- vLambda4[0] = fLambda4[0];
- vLambda4[1] = fLambda4[1];
- vLambda4[2] = fLambda4[2];
-
- /* Rayleigh scattering constants. */
- fTemp = pi * pi * (n * n - 1) * (n * n - 1) * (6 + 3 * pn) / (6 - 7 * pn) / N;
- fBeta = 8 * fTemp * pi / 3;
-
- VEC3OPF(sunSky->atm_BetaRay, vLambda4, *, fBeta);
- fBetaDash = fTemp / 2;
- VEC3OPF(sunSky->atm_BetaDashRay, vLambda4, *, fBetaDash);
-
-
- /* Mie scattering constants. */
- fTemp2 = 0.434f * c * (2 * pi) * (2 * pi) * 0.5f;
- VEC3OPF(sunSky->atm_BetaDashMie, vLambda2, *, fTemp2);
-
- fTemp3 = 0.434f * c * pi * (2 * pi) * (2 * pi);
-
- VEC3OPV(vBetaMieTemp, K, *, fLambda);
- VEC3OPF(sunSky->atm_BetaMie, vBetaMieTemp, *, fTemp3);
-
-}
-
-/**
- * AtmospherePixleShader:
- * this function apply atmosphere effect on a pixle color `rgb' at distance `s'
- * parameters:
- * sunSky, contains information about sun parameters and user values
- * view, is camera view vector
- * s, is distance
- * rgb, contains rendered color value for a pixle
- * */
-void AtmospherePixleShader(struct SunSky *sunSky, float view[3], float s, float rgb[3])
-{
- float costheta;
- float Phase_1;
- float Phase_2;
- float sunColor[3];
-
- float E[3];
- float E1[3];
-
-
- float I[3];
- float fTemp;
- float vTemp1[3], vTemp2[3];
-
- float sunDirection[3];
-
- s *= sunSky->atm_DistanceMultiplier;
-
- sunDirection[0] = sunSky->toSun[0];
- sunDirection[1] = sunSky->toSun[1];
- sunDirection[2] = sunSky->toSun[2];
-
- costheta = dot_v3v3(view, sunDirection); /* cos(theta) */
- Phase_1 = 1 + (costheta * costheta); /* Phase_1 */
-
- VEC3OPF(sunSky->atm_BetaRay, sunSky->atm_BetaRay, *, sunSky->atm_BetaRayMultiplier);
- VEC3OPF(sunSky->atm_BetaMie, sunSky->atm_BetaMie, *, sunSky->atm_BetaMieMultiplier);
- VEC3OPV(sunSky->atm_BetaRM, sunSky->atm_BetaRay, +, sunSky->atm_BetaMie);
-
- /* e^(-(beta_1 + beta_2) * s) = E1 */
- VEC3OPF(E1, sunSky->atm_BetaRM, *, -s / (float)M_LN2);
- E1[0] = exp(E1[0]);
- E1[1] = exp(E1[1]);
- E1[2] = exp(E1[2]);
-
- copy_v3_v3(E, E1);
-
- /* Phase2(theta) = (1-g^2)/(1+g-2g*cos(theta))^(3/2) */
- fTemp = 1 + sunSky->atm_HGg - 2 * sunSky->atm_HGg * costheta;
- fTemp = fTemp * sqrtf(fTemp);
- Phase_2 = (1 - sunSky->atm_HGg * sunSky->atm_HGg) / fTemp;
-
- VEC3OPF(vTemp1, sunSky->atm_BetaDashRay, *, Phase_1);
- VEC3OPF(vTemp2, sunSky->atm_BetaDashMie, *, Phase_2);
-
- VEC3OPV(vTemp1, vTemp1, +, vTemp2);
- FOPVEC3(vTemp2, 1.0f, -, E1);
- VEC3OPV(vTemp1, vTemp1, *, vTemp2);
-
- FOPVEC3(vTemp2, 1.0f, /, sunSky->atm_BetaRM);
-
- VEC3OPV(I, vTemp1, *, vTemp2);
-
- VEC3OPF(I, I, *, sunSky->atm_InscatteringMultiplier);
- VEC3OPF(E, E, *, sunSky->atm_ExtinctionMultiplier);
-
- /* scale to color sun */
- ComputeAttenuatedSunlight(sunSky->theta, sunSky->turbidity, sunColor);
- VEC3OPV(E, E, *, sunColor);
-
- VEC3OPF(I, I, *, sunSky->atm_SunIntensity);
-
- VEC3OPV(rgb, rgb, *, E);
- VEC3OPV(rgb, rgb, +, I);
-}
-
-#undef VEC3OPV
-#undef VEC3OPF
-#undef FOPVEC3
-
-/* EOF */
diff --git a/source/blender/render/intern/source/texture_ocean.c b/source/blender/render/intern/source/texture_ocean.c
deleted file mode 100644
index a932123243d..00000000000
--- a/source/blender/render/intern/source/texture_ocean.c
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * Contributors: Matt Ebb
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/texture_ocean.c
- * \ingroup bke
- */
-
-#include <stddef.h>
-
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-
-#include "DNA_modifier_types.h"
-#include "DNA_object_types.h"
-#include "DNA_texture_types.h"
-
-#include "BKE_global.h" /* XXX */
-
-#include "BKE_modifier.h"
-#include "BKE_ocean.h"
-
-#include "render_types.h"
-#include "RE_shader_ext.h"
-
-#include "texture.h"
-
-#include "texture_ocean.h" /* own include */
-
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-
-/* ***** actual texture sampling ***** */
-int ocean_texture(Tex *tex, const float texvec[2], TexResult *texres)
-{
- OceanTex *ot = tex->ot;
- ModifierData *md;
- OceanModifierData *omd;
-
- texres->tin = 0.0f;
-
- if ( !(ot) ||
- !(ot->object) ||
- !(md = (ModifierData *)modifiers_findByType(ot->object, eModifierType_Ocean)) ||
- !(omd = (OceanModifierData *)md)->ocean)
- {
- return 0;
- }
- else {
- const bool do_normals = (omd->flag & MOD_OCEAN_GENERATE_NORMALS) != 0;
- int cfra = R.r.cfra;
- int retval = TEX_INT;
-
- OceanResult ocr;
- const float u = 0.5f + 0.5f * texvec[0];
- const float v = 0.5f + 0.5f * texvec[1];
-
- if (omd->oceancache && omd->cached == true) {
-
- CLAMP(cfra, omd->bakestart, omd->bakeend);
- cfra -= omd->bakestart; /* shift to 0 based */
-
- BKE_ocean_cache_eval_uv(omd->oceancache, &ocr, cfra, u, v);
-
- }
- else { /* non-cached */
-
- if (G.is_rendering)
- BKE_ocean_eval_uv_catrom(omd->ocean, &ocr, u, v);
- else
- BKE_ocean_eval_uv(omd->ocean, &ocr, u, v);
-
- ocr.foam = BKE_ocean_jminus_to_foam(ocr.Jminus, omd->foam_coverage);
- }
-
- switch (ot->output) {
- case TEX_OCN_DISPLACEMENT:
- /* XYZ displacement */
- texres->tr = 0.5f + 0.5f * ocr.disp[0];
- texres->tg = 0.5f + 0.5f * ocr.disp[2];
- texres->tb = 0.5f + 0.5f * ocr.disp[1];
-
- texres->tr = MAX2(0.0f, texres->tr);
- texres->tg = MAX2(0.0f, texres->tg);
- texres->tb = MAX2(0.0f, texres->tb);
-
- BRICONTRGB;
-
- retval = TEX_RGB;
- break;
-
- case TEX_OCN_EMINUS:
- /* -ve eigenvectors ? */
- texres->tr = ocr.Eminus[0];
- texres->tg = ocr.Eminus[2];
- texres->tb = ocr.Eminus[1];
- retval = TEX_RGB;
- break;
-
- case TEX_OCN_EPLUS:
- /* -ve eigenvectors ? */
- texres->tr = ocr.Eplus[0];
- texres->tg = ocr.Eplus[2];
- texres->tb = ocr.Eplus[1];
- retval = TEX_RGB;
- break;
-
- case TEX_OCN_JPLUS:
- texres->tin = ocr.Jplus;
- retval = TEX_INT;
- break;
-
- case TEX_OCN_FOAM:
-
- texres->tin = ocr.foam;
-
- BRICONT;
-
- retval = TEX_INT;
- break;
- }
-
- /* if normals needed */
-
- if (texres->nor && do_normals) {
- normalize_v3_v3(texres->nor, ocr.normal);
- retval |= TEX_NOR;
- }
-
- texres->ta = 1.0f;
-
- return retval;
- }
-}
diff --git a/source/blender/render/intern/source/volume_precache.c b/source/blender/render/intern/source/volume_precache.c
deleted file mode 100644
index 752a9df0b79..00000000000
--- a/source/blender/render/intern/source/volume_precache.c
+++ /dev/null
@@ -1,855 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Matt Ebb, Ra˙l Fern·ndez Hern·ndez (Farsthary).
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/volume_precache.c
- * \ingroup render
- */
-
-
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-#include <float.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_task.h"
-#include "BLI_threads.h"
-#include "BLI_voxel.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "PIL_time.h"
-
-#include "RE_shader_ext.h"
-
-#include "DNA_material_types.h"
-
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "render_types.h"
-#include "rendercore.h"
-#include "renderdatabase.h"
-#include "volumetric.h"
-#include "volume_precache.h"
-
-#include "atomic_ops.h"
-
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-/* *** utility code to set up an individual raytree for objectinstance, for checking inside/outside *** */
-
-/* Recursive test for intersections, from a point inside the mesh, to outside
- * Number of intersections (depth) determine if a point is inside or outside the mesh */
-static int intersect_outside_volume(RayObject *tree, Isect *isect, float *offset, int limit, int depth)
-{
- if (limit == 0) return depth;
-
- if (RE_rayobject_raycast(tree, isect)) {
-
- isect->start[0] = isect->start[0] + isect->dist*isect->dir[0];
- isect->start[1] = isect->start[1] + isect->dist*isect->dir[1];
- isect->start[2] = isect->start[2] + isect->dist*isect->dir[2];
-
- isect->dist = FLT_MAX;
- isect->skip = RE_SKIP_VLR_NEIGHBOUR;
- isect->orig.face= isect->hit.face;
- isect->orig.ob= isect->hit.ob;
-
- return intersect_outside_volume(tree, isect, offset, limit-1, depth+1);
- }
- else {
- return depth;
- }
-}
-
-/* Uses ray tracing to check if a point is inside or outside an ObjectInstanceRen */
-static int point_inside_obi(RayObject *tree, ObjectInstanceRen *obi, const float co[3])
-{
- Isect isect= {{0}};
- float dir[3] = {0.0f, 0.0f, 1.0f};
- int final_depth=0, depth=0, limit=20;
-
- /* set up the isect */
- copy_v3_v3(isect.start, co);
- copy_v3_v3(isect.dir, dir);
- isect.mode= RE_RAY_MIRROR;
- isect.last_hit= NULL;
- isect.lay= -1;
-
- isect.dist = FLT_MAX;
- isect.orig.face= NULL;
- isect.orig.ob = NULL;
-
- RE_instance_rotate_ray(obi, &isect);
- final_depth = intersect_outside_volume(tree, &isect, dir, limit, depth);
- RE_instance_rotate_ray_restore(obi, &isect);
-
- /* even number of intersections: point is outside
- * odd number: point is inside */
- if (final_depth % 2 == 0) return 0;
- else return 1;
-}
-
-/* find the bounding box of an objectinstance in global space */
-void global_bounds_obi(Render *re, ObjectInstanceRen *obi, float bbmin[3], float bbmax[3])
-{
- ObjectRen *obr = obi->obr;
- VolumePrecache *vp = obi->volume_precache;
- VertRen *ver= NULL;
- float co[3];
- int a;
-
- if (vp->bbmin != NULL && vp->bbmax != NULL) {
- copy_v3_v3(bbmin, vp->bbmin);
- copy_v3_v3(bbmax, vp->bbmax);
- return;
- }
-
- vp->bbmin = MEM_callocN(sizeof(float)*3, "volume precache min boundbox corner");
- vp->bbmax = MEM_callocN(sizeof(float)*3, "volume precache max boundbox corner");
-
- INIT_MINMAX(bbmin, bbmax);
-
- for (a=0; a<obr->totvert; a++) {
- if ((a & 255)==0) ver= obr->vertnodes[a>>8].vert;
- else ver++;
-
- copy_v3_v3(co, ver->co);
-
- /* transformed object instance in camera space */
- if (obi->flag & R_TRANSFORMED)
- mul_m4_v3(obi->mat, co);
-
- /* convert to global space */
- mul_m4_v3(re->viewinv, co);
-
- minmax_v3v3_v3(vp->bbmin, vp->bbmax, co);
- }
-
- copy_v3_v3(bbmin, vp->bbmin);
- copy_v3_v3(bbmax, vp->bbmax);
-
-}
-
-/* *** light cache filtering *** */
-
-static float get_avg_surrounds(float *cache, int *res, int xx, int yy, int zz)
-{
- int x, y, z, x_, y_, z_;
- int added=0;
- float tot=0.0f;
-
- for (z=-1; z <= 1; z++) {
- z_ = zz+z;
- if (z_ >= 0 && z_ <= res[2]-1) {
-
- for (y=-1; y <= 1; y++) {
- y_ = yy+y;
- if (y_ >= 0 && y_ <= res[1]-1) {
-
- for (x=-1; x <= 1; x++) {
- x_ = xx+x;
- if (x_ >= 0 && x_ <= res[0]-1) {
- const int64_t i = BLI_VOXEL_INDEX(x_, y_, z_, res);
-
- if (cache[i] > 0.0f) {
- tot += cache[i];
- added++;
- }
-
- }
- }
- }
- }
- }
- }
-
- if (added > 0) tot /= added;
-
- return tot;
-}
-
-/* function to filter the edges of the light cache, where there was no volume originally.
- * For each voxel which was originally external to the mesh, it finds the average values of
- * the surrounding internal voxels and sets the original external voxel to that average amount.
- * Works almost a bit like a 'dilate' filter */
-static void lightcache_filter(VolumePrecache *vp)
-{
- int x, y, z;
-
- for (z=0; z < vp->res[2]; z++) {
- for (y=0; y < vp->res[1]; y++) {
- for (x=0; x < vp->res[0]; x++) {
- /* trigger for outside mesh */
- const int64_t i = BLI_VOXEL_INDEX(x, y, z, vp->res);
-
- if (vp->data_r[i] < -0.f)
- vp->data_r[i] = get_avg_surrounds(vp->data_r, vp->res, x, y, z);
- if (vp->data_g[i] < -0.f)
- vp->data_g[i] = get_avg_surrounds(vp->data_g, vp->res, x, y, z);
- if (vp->data_b[i] < -0.f)
- vp->data_b[i] = get_avg_surrounds(vp->data_b, vp->res, x, y, z);
- }
- }
- }
-}
-
-#if 0
-static void lightcache_filter2(VolumePrecache *vp)
-{
- int x, y, z;
- float *new_r, *new_g, *new_b;
- int field_size = vp->res[0]*vp->res[1]*vp->res[2]*sizeof(float);
-
- new_r = MEM_mallocN(field_size, "temp buffer for light cache filter r channel");
- new_g = MEM_mallocN(field_size, "temp buffer for light cache filter g channel");
- new_b = MEM_mallocN(field_size, "temp buffer for light cache filter b channel");
-
- memcpy(new_r, vp->data_r, field_size);
- memcpy(new_g, vp->data_g, field_size);
- memcpy(new_b, vp->data_b, field_size);
-
- for (z=0; z < vp->res[2]; z++) {
- for (y=0; y < vp->res[1]; y++) {
- for (x=0; x < vp->res[0]; x++) {
- /* trigger for outside mesh */
- const int64_t i = BLI_VOXEL_INDEX(x, y, z, vp->res);
- if (vp->data_r[i] < -0.f)
- new_r[i] = get_avg_surrounds(vp->data_r, vp->res, x, y, z);
- if (vp->data_g[i] < -0.f)
- new_g[i] = get_avg_surrounds(vp->data_g, vp->res, x, y, z);
- if (vp->data_b[i] < -0.f)
- new_b[i] = get_avg_surrounds(vp->data_b, vp->res, x, y, z);
- }
- }
- }
-
- SWAP(float *, vp->data_r, new_r);
- SWAP(float *, vp->data_g, new_g);
- SWAP(float *, vp->data_b, new_b);
-
- if (new_r) { MEM_freeN(new_r); new_r=NULL; }
- if (new_g) { MEM_freeN(new_g); new_g=NULL; }
- if (new_b) { MEM_freeN(new_b); new_b=NULL; }
-}
-#endif
-
-/* has a pad of 1 voxel surrounding the core for boundary simulation */
-BLI_INLINE int64_t ms_I(int x, int y, int z, const int *n)
-{
- /* different ordering to light cache */
- return ((int64_t)x * (int64_t)(n[1] + 2) * (int64_t)(n[2] + 2) +
- (int64_t)y * (int64_t)(n[2] + 2) +
- (int64_t)z);
-}
-
-/* has a pad of 1 voxel surrounding the core for boundary simulation */
-BLI_INLINE int64_t v_I_pad(int x, int y, int z, const int *n)
-{
- /* same ordering to light cache, with padding */
- return ((int64_t)z * (int64_t)(n[1] + 2) * (int64_t)(n[0] + 2) +
- (int64_t)y * (int64_t)(n[0] + 2) +
- (int64_t)x);
-}
-
-BLI_INLINE int64_t lc_to_ms_I(int x, int y, int z, const int *n)
-{
- /* converting light cache index to multiple scattering index */
- return ((int64_t)(x - 1) * ((int64_t)n[1] * (int64_t)n[2]) +
- (int64_t)(y - 1) * ((int64_t)n[2]) +
- (int64_t)(z - 1));
-}
-
-/* *** multiple scattering approximation *** */
-
-/* get the total amount of light energy in the light cache. used to normalize after multiple scattering */
-static float total_ss_energy(Render *re, int do_test_break, VolumePrecache *vp)
-{
- int x, y, z;
- const int *res = vp->res;
- float energy=0.f;
-
- for (z=0; z < res[2]; z++) {
- for (y=0; y < res[1]; y++) {
- for (x=0; x < res[0]; x++) {
- const int64_t i = BLI_VOXEL_INDEX(x, y, z, res);
-
- if (vp->data_r[i] > 0.f) energy += vp->data_r[i];
- if (vp->data_g[i] > 0.f) energy += vp->data_g[i];
- if (vp->data_b[i] > 0.f) energy += vp->data_b[i];
- }
- }
-
- if (do_test_break && re->test_break(re->tbh)) break;
- }
-
- return energy;
-}
-
-static float total_ms_energy(Render *re, int do_test_break, float *sr, float *sg, float *sb, const int res[3])
-{
- int x, y, z;
- float energy=0.f;
-
- for (z=1;z<=res[2];z++) {
- for (y=1;y<=res[1];y++) {
- for (x=1;x<=res[0];x++) {
- const int64_t i = ms_I(x, y, z, res);
-
- if (sr[i] > 0.f) energy += sr[i];
- if (sg[i] > 0.f) energy += sg[i];
- if (sb[i] > 0.f) energy += sb[i];
- }
- }
-
- if (do_test_break && re->test_break(re->tbh)) break;
- }
-
- return energy;
-}
-
-/**
- * \param n: the unpadded resolution
- */
-static void ms_diffuse(Render *re, int do_test_break, const float *x0, float *x, float diff, const int n[3])
-{
- int i, j, k, l;
- const float dt = VOL_MS_TIMESTEP;
- int64_t size = (int64_t)n[0] * (int64_t)n[1] * (int64_t)n[2];
- const float a = dt * diff * size;
-
- for (l=0; l<20; l++) {
- for (k=1; k<=n[2]; k++) {
- for (j=1; j<=n[1]; j++) {
- for (i=1; i<=n[0]; i++) {
- x[v_I_pad(i, j, k, n)] =
- ((x0[v_I_pad(i, j, k, n)]) + (
- (x0[v_I_pad(i - 1, j, k, n)] +
- x0[v_I_pad(i + 1, j, k, n)] +
- x0[v_I_pad(i, j - 1, k, n)] +
- x0[v_I_pad(i, j + 1, k, n)] +
- x0[v_I_pad(i, j, k - 1, n)] +
- x0[v_I_pad(i, j, k + 1, n)]) * a) / (1 + 6 * a));
- }
- }
-
- if (do_test_break && re->test_break(re->tbh)) break;
- }
-
- if (re->test_break(re->tbh)) break;
- }
-}
-
-static void multiple_scattering_diffusion(Render *re, VolumePrecache *vp, Material *ma)
-{
- const float diff = ma->vol.ms_diff * 0.001f; /* compensate for scaling for a nicer UI range */
- const int simframes = (int)(ma->vol.ms_spread * (float)max_iii(vp->res[0], vp->res[1], vp->res[2]));
- const int shade_type = ma->vol.shade_type;
- float fac = ma->vol.ms_intensity;
-
- int x, y, z, m;
- const int *n = vp->res;
- const int size = (n[0]+2)*(n[1]+2)*(n[2]+2);
- const int do_test_break = (size > 100000);
- double time, lasttime= PIL_check_seconds_timer();
- float total;
- float c=1.0f;
- float origf; /* factor for blending in original light cache */
- float energy_ss, energy_ms;
-
- float *sr0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
- float *sr=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
- float *sg0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
- float *sg=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
- float *sb0=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
- float *sb=(float *)MEM_callocN(size*sizeof(float), "temporary multiple scattering buffer");
-
- total = (float)(n[0]*n[1]*n[2]*simframes);
-
- energy_ss = total_ss_energy(re, do_test_break, vp);
-
- /* Scattering as diffusion pass */
- for (m=0; m<simframes; m++) {
- /* add sources */
- for (z=1; z<=n[2]; z++) {
- for (y=1; y<=n[1]; y++) {
- for (x=1; x<=n[0]; x++) {
- const int64_t i = lc_to_ms_I(x, y, z, n); //lc index
- const int64_t j = ms_I(x, y, z, n); //ms index
-
- time= PIL_check_seconds_timer();
- c++;
- if (vp->data_r[i] > 0.0f)
- sr[j] += vp->data_r[i];
- if (vp->data_g[i] > 0.0f)
- sg[j] += vp->data_g[i];
- if (vp->data_b[i] > 0.0f)
- sb[j] += vp->data_b[i];
-
- /* Displays progress every second */
- if (time-lasttime>1.0) {
- char str[64];
- BLI_snprintf(str, sizeof(str), IFACE_("Simulating multiple scattering: %d%%"),
- (int)(100.0f * (c / total)));
- re->i.infostr = str;
- re->stats_draw(re->sdh, &re->i);
- re->i.infostr = NULL;
- lasttime= time;
- }
- }
- }
-
- if (do_test_break && re->test_break(re->tbh)) break;
- }
-
- if (re->test_break(re->tbh)) break;
-
- SWAP(float *, sr, sr0);
- SWAP(float *, sg, sg0);
- SWAP(float *, sb, sb0);
-
- /* main diffusion simulation */
- ms_diffuse(re, do_test_break, sr0, sr, diff, n);
- ms_diffuse(re, do_test_break, sg0, sg, diff, n);
- ms_diffuse(re, do_test_break, sb0, sb, diff, n);
-
- if (re->test_break(re->tbh)) break;
- }
-
- /* normalization factor to conserve energy */
- energy_ms = total_ms_energy(re, do_test_break, sr, sg, sb, n);
- fac *= (energy_ss / energy_ms);
-
- /* blend multiple scattering back in the light cache */
- if (shade_type == MA_VOL_SHADE_SHADEDPLUSMULTIPLE) {
- /* conserve energy - half single, half multiple */
- origf = 0.5f;
- fac *= 0.5f;
- }
- else {
- origf = 0.0f;
- }
-
- for (z=1;z<=n[2];z++) {
- for (y=1;y<=n[1];y++) {
- for (x=1;x<=n[0];x++) {
- const int64_t i = lc_to_ms_I(x, y, z, n); //lc index
- const int64_t j = ms_I(x, y, z, n); //ms index
-
- vp->data_r[i] = origf * vp->data_r[i] + fac * sr[j];
- vp->data_g[i] = origf * vp->data_g[i] + fac * sg[j];
- vp->data_b[i] = origf * vp->data_b[i] + fac * sb[j];
- }
- }
-
- if (do_test_break && re->test_break(re->tbh)) break;
- }
-
- MEM_freeN(sr0);
- MEM_freeN(sr);
- MEM_freeN(sg0);
- MEM_freeN(sg);
- MEM_freeN(sb0);
- MEM_freeN(sb);
-}
-
-
-
-#if 0 /* debug stuff */
-static void *vol_precache_part_test(void *data)
-{
- VolPrecachePart *pa = data;
-
- printf("part number: %d\n", pa->num);
- printf("done: %d\n", pa->done);
- printf("x min: %d x max: %d\n", pa->minx, pa->maxx);
- printf("y min: %d y max: %d\n", pa->miny, pa->maxy);
- printf("z min: %d z max: %d\n", pa->minz, pa->maxz);
-
- return NULL;
-}
-#endif
-
-/* Iterate over the 3d voxel grid, and fill the voxels with scattering information
- *
- * It's stored in memory as 3 big float grids next to each other, one for each RGB channel.
- * I'm guessing the memory alignment may work out better this way for the purposes
- * of doing linear interpolation, but I haven't actually tested this theory! :)
- */
-typedef struct VolPrecacheState {
- double lasttime;
- unsigned int doneparts;
- unsigned int totparts;
-} VolPrecacheState;
-
-static void vol_precache_part(TaskPool * __restrict pool, void *taskdata, int UNUSED(threadid))
-{
- VolPrecacheState *state = (VolPrecacheState *)BLI_task_pool_userdata(pool);
- VolPrecachePart *pa = (VolPrecachePart *)taskdata;
- Render *re = pa->re;
-
- ObjectInstanceRen *obi = pa->obi;
- RayObject *tree = pa->tree;
- ShadeInput *shi = pa->shi;
- float scatter_col[3] = {0.f, 0.f, 0.f};
- float co[3], cco[3], view[3];
- int x, y, z;
- int res[3];
- double time;
-
- if (re->test_break && re->test_break(re->tbh))
- return;
-
- //printf("thread id %d\n", threadid);
-
- res[0]= pa->res[0];
- res[1]= pa->res[1];
- res[2]= pa->res[2];
-
- for (z= pa->minz; z < pa->maxz; z++) {
- co[2] = pa->bbmin[2] + (pa->voxel[2] * (z + 0.5f));
-
- for (y= pa->miny; y < pa->maxy; y++) {
- co[1] = pa->bbmin[1] + (pa->voxel[1] * (y + 0.5f));
-
- for (x=pa->minx; x < pa->maxx; x++) {
- int64_t i;
- co[0] = pa->bbmin[0] + (pa->voxel[0] * (x + 0.5f));
-
- if (re->test_break && re->test_break(re->tbh))
- break;
-
- /* convert from world->camera space for shading */
- mul_v3_m4v3(cco, pa->viewmat, co);
-
- i = BLI_VOXEL_INDEX(x, y, z, res);
-
- /* don't bother if the point is not inside the volume mesh */
- if (!point_inside_obi(tree, obi, cco)) {
- obi->volume_precache->data_r[i] = -1.0f;
- obi->volume_precache->data_g[i] = -1.0f;
- obi->volume_precache->data_b[i] = -1.0f;
- continue;
- }
-
- copy_v3_v3(view, cco);
- normalize_v3(view);
- vol_get_scattering(shi, scatter_col, cco, view);
-
- obi->volume_precache->data_r[i] = scatter_col[0];
- obi->volume_precache->data_g[i] = scatter_col[1];
- obi->volume_precache->data_b[i] = scatter_col[2];
-
- }
- }
- }
-
- unsigned int doneparts = atomic_add_and_fetch_u(&state->doneparts, 1);
-
- time = PIL_check_seconds_timer();
- if (time - state->lasttime > 1.0) {
- ThreadMutex *mutex = BLI_task_pool_user_mutex(pool);
-
- if (BLI_mutex_trylock(mutex)) {
- char str[64];
- float ratio = (float)doneparts/(float)state->totparts;
- BLI_snprintf(str, sizeof(str), IFACE_("Precaching volume: %d%%"), (int)(100.0f * ratio));
- re->i.infostr = str;
- re->stats_draw(re->sdh, &re->i);
- re->i.infostr = NULL;
- state->lasttime = time;
-
- BLI_mutex_unlock(mutex);
- }
- }
-}
-
-static void precache_setup_shadeinput(Render *re, ObjectInstanceRen *obi, Material *ma, ShadeInput *shi)
-{
- memset(shi, 0, sizeof(ShadeInput));
- shi->depth= 1;
- shi->mask= 1;
- shi->mat = ma;
- shi->vlr = NULL;
- memcpy(&shi->r, &shi->mat->r, 23*sizeof(float)); /* note, keep this synced with render_types.h */
- shi->har= shi->mat->har;
- shi->obi= obi;
- shi->obr= obi->obr;
- shi->lay = re->lay;
-}
-
-static void precache_launch_parts(Render *re, RayObject *tree, ShadeInput *shi, ObjectInstanceRen *obi)
-{
- TaskScheduler *task_scheduler;
- TaskPool *task_pool;
- VolumePrecache *vp = obi->volume_precache;
- VolPrecacheState state;
- int i=0, x, y, z;
- float voxel[3];
- int sizex, sizey, sizez;
- float bbmin[3], bbmax[3];
- const int *res;
- int minx, maxx;
- int miny, maxy;
- int minz, maxz;
- int totthread = re->r.threads;
- int parts[3];
-
- if (!vp) return;
-
- /* currently we just subdivide the box, number of threads per side */
- parts[0] = parts[1] = parts[2] = totthread;
- res = vp->res;
-
- /* setup task scheduler */
- memset(&state, 0, sizeof(state));
- state.doneparts = 0;
- state.totparts = parts[0]*parts[1]*parts[2];
- state.lasttime = PIL_check_seconds_timer();
-
- task_scheduler = BLI_task_scheduler_create(totthread);
- task_pool = BLI_task_pool_create(task_scheduler, &state);
-
- /* using boundbox in worldspace */
- global_bounds_obi(re, obi, bbmin, bbmax);
- sub_v3_v3v3(voxel, bbmax, bbmin);
-
- voxel[0] /= (float)res[0];
- voxel[1] /= (float)res[1];
- voxel[2] /= (float)res[2];
-
- for (x=0; x < parts[0]; x++) {
- sizex = ceil(res[0] / (float)parts[0]);
- minx = x * sizex;
- maxx = minx + sizex;
- maxx = (maxx>res[0])?res[0]:maxx;
-
- for (y=0; y < parts[1]; y++) {
- sizey = ceil(res[1] / (float)parts[1]);
- miny = y * sizey;
- maxy = miny + sizey;
- maxy = (maxy>res[1])?res[1]:maxy;
-
- for (z=0; z < parts[2]; z++) {
- VolPrecachePart *pa= MEM_callocN(sizeof(VolPrecachePart), "new precache part");
-
- sizez = ceil(res[2] / (float)parts[2]);
- minz = z * sizez;
- maxz = minz + sizez;
- maxz = (maxz>res[2])?res[2]:maxz;
-
- pa->re = re;
- pa->num = i;
- pa->tree = tree;
- pa->shi = shi;
- pa->obi = obi;
- copy_m4_m4(pa->viewmat, re->viewmat);
-
- copy_v3_v3(pa->bbmin, bbmin);
- copy_v3_v3(pa->voxel, voxel);
- copy_v3_v3_int(pa->res, res);
-
- pa->minx = minx; pa->maxx = maxx;
- pa->miny = miny; pa->maxy = maxy;
- pa->minz = minz; pa->maxz = maxz;
-
- BLI_task_pool_push(task_pool, vol_precache_part, pa, true, TASK_PRIORITY_HIGH);
-
- i++;
- }
- }
- }
-
- /* work and wait until tasks are done */
- BLI_task_pool_work_and_wait(task_pool);
-
- /* free */
- BLI_task_pool_free(task_pool);
- BLI_task_scheduler_free(task_scheduler);
-}
-
-/* calculate resolution from bounding box in world space */
-static int precache_resolution(Render *re, VolumePrecache *vp, ObjectInstanceRen *obi, int res)
-{
- float dim[3], div;
- float bbmin[3], bbmax[3];
-
- /* bound box in global space */
- global_bounds_obi(re, obi, bbmin, bbmax);
- sub_v3_v3v3(dim, bbmax, bbmin);
-
- div = max_fff(dim[0], dim[1], dim[2]);
- dim[0] /= div;
- dim[1] /= div;
- dim[2] /= div;
-
- vp->res[0] = ceil(dim[0] * res);
- vp->res[1] = ceil(dim[1] * res);
- vp->res[2] = ceil(dim[2] * res);
-
- if ((vp->res[0] < 1) || (vp->res[1] < 1) || (vp->res[2] < 1))
- return 0;
-
- return 1;
-}
-
-/* Precache a volume into a 3D voxel grid.
- * The voxel grid is stored in the ObjectInstanceRen,
- * in camera space, aligned with the ObjectRen's bounding box.
- * Resolution is defined by the user.
- */
-static void vol_precache_objectinstance_threads(Render *re, ObjectInstanceRen *obi, Material *ma)
-{
- VolumePrecache *vp;
- RayObject *tree;
- ShadeInput shi;
-
- R = *re;
-
- /* create a raytree with just the faces of the instanced ObjectRen,
- * used for checking if the cached point is inside or outside. */
- tree = makeraytree_object(&R, obi);
- if (!tree) return;
-
- vp = MEM_callocN(sizeof(VolumePrecache), "volume light cache");
- obi->volume_precache = vp;
-
- if (!precache_resolution(re, vp, obi, ma->vol.precache_resolution)) {
- MEM_freeN(vp);
- vp = NULL;
- return;
- }
-
- vp->data_r = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data red channel");
- vp->data_g = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data green channel");
- vp->data_b = MEM_callocN(sizeof(float)*vp->res[0]*vp->res[1]*vp->res[2], "volume light cache data blue channel");
- if (vp->data_r==NULL || vp->data_g==NULL || vp->data_b==NULL) {
- MEM_freeN(vp);
- return;
- }
-
- /* Need a shadeinput to calculate scattering */
- precache_setup_shadeinput(re, obi, ma, &shi);
-
- precache_launch_parts(re, tree, &shi, obi);
-
- if (tree) {
- /* TODO: makeraytree_object creates a tree and saves it on OBI,
- * if we free this tree we should also clear other pointers to it */
- //RE_rayobject_free(tree);
- //tree= NULL;
- }
-
- if (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)) {
- /* this should be before the filtering */
- multiple_scattering_diffusion(re, obi->volume_precache, ma);
- }
-
- lightcache_filter(obi->volume_precache);
-}
-
-static int using_lightcache(Material *ma)
-{
- return (((ma->vol.shadeflag & MA_VOL_PRECACHESHADING) && (ma->vol.shade_type == MA_VOL_SHADE_SHADED)) ||
- (ELEM(ma->vol.shade_type, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)));
-}
-
-/* loop through all objects (and their associated materials)
- * marked for pre-caching in convertblender.c, and pre-cache them */
-void volume_precache(Render *re)
-{
- ObjectInstanceRen *obi;
- VolumeOb *vo;
-
- re->i.infostr = IFACE_("Volume preprocessing");
- re->stats_draw(re->sdh, &re->i);
-
- for (vo= re->volumes.first; vo; vo= vo->next) {
- if (using_lightcache(vo->ma)) {
- for (obi= re->instancetable.first; obi; obi= obi->next) {
- if (obi->obr == vo->obr) {
- vol_precache_objectinstance_threads(re, obi, vo->ma);
-
- if (re->test_break && re->test_break(re->tbh))
- break;
- }
- }
-
- if (re->test_break && re->test_break(re->tbh))
- break;
- }
- }
-
- re->i.infostr = NULL;
- re->stats_draw(re->sdh, &re->i);
-}
-
-void free_volume_precache(Render *re)
-{
- ObjectInstanceRen *obi;
-
- for (obi= re->instancetable.first; obi; obi= obi->next) {
- if (obi->volume_precache != NULL) {
- MEM_freeN(obi->volume_precache->data_r);
- MEM_freeN(obi->volume_precache->data_g);
- MEM_freeN(obi->volume_precache->data_b);
- MEM_freeN(obi->volume_precache->bbmin);
- MEM_freeN(obi->volume_precache->bbmax);
- MEM_freeN(obi->volume_precache);
- obi->volume_precache = NULL;
- }
- }
-
- BLI_freelistN(&re->volumes);
-}
-
-int point_inside_volume_objectinstance(Render *re, ObjectInstanceRen *obi, const float co[3])
-{
- RayObject *tree;
- int inside=0;
-
- tree = makeraytree_object(re, obi);
- if (!tree) return 0;
-
- inside = point_inside_obi(tree, obi, co);
-
- //TODO: makeraytree_object creates a tree and saves it on OBI, if we free this tree we should also clear other pointers to it
- //RE_rayobject_free(tree);
- //tree= NULL;
-
- return inside;
-}
-
diff --git a/source/blender/render/intern/source/volumetric.c b/source/blender/render/intern/source/volumetric.c
deleted file mode 100644
index 7fe52328781..00000000000
--- a/source/blender/render/intern/source/volumetric.c
+++ /dev/null
@@ -1,836 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Matt Ebb, Raul Fernandez Hernandez (Farsthary)
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/volumetric.c
- * \ingroup render
- */
-
-#include <math.h>
-#include <stdlib.h>
-#include <string.h>
-#include <float.h>
-
-#include "BLI_math.h"
-#include "BLI_rand.h"
-#include "BLI_voxel.h"
-#include "BLI_utildefines.h"
-
-#include "RE_shader_ext.h"
-
-#include "IMB_colormanagement.h"
-
-#include "DNA_material_types.h"
-#include "DNA_group_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_meta_types.h"
-
-
-#include "render_types.h"
-#include "pixelshading.h"
-#include "rayintersection.h"
-#include "rayobject.h"
-#include "renderdatabase.h"
-#include "shading.h"
-#include "shadbuf.h"
-#include "texture.h"
-#include "volumetric.h"
-#include "volume_precache.h"
-
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-/* tracing */
-static float vol_get_shadow(ShadeInput *shi, LampRen *lar, const float co[3])
-{
- float visibility = 1.f;
-
- if (lar->shb) {
- float dxco[3] = {0.f, 0.f, 0.f}, dyco[3] = {0.f, 0.f, 0.f};
-
- visibility = testshadowbuf(&R, lar->shb, co, dxco, dyco, 1.0, 0.0);
- }
- else if (lar->mode & LA_SHAD_RAY) {
- /* trace shadow manually, no good lamp api atm */
- Isect is;
-
- copy_v3_v3(is.start, co);
- if (lar->type == LA_SUN || lar->type == LA_HEMI) {
- is.dir[0] = -lar->vec[0];
- is.dir[1] = -lar->vec[1];
- is.dir[2] = -lar->vec[2];
- is.dist = R.maxdist;
- }
- else {
- sub_v3_v3v3(is.dir, lar->co, is.start);
- is.dist = normalize_v3(is.dir);
- }
-
- is.mode = RE_RAY_MIRROR;
- is.check = RE_CHECK_VLR_NON_SOLID_MATERIAL;
- is.skip = 0;
-
- if (lar->mode & (LA_LAYER | LA_LAYER_SHADOW))
- is.lay = lar->lay;
- else
- is.lay = -1;
-
- is.orig.ob = NULL;
- is.orig.face = NULL;
- is.last_hit = lar->last_hit[shi->thread];
-
- RE_instance_rotate_ray(shi->obi, &is);
-
- if (RE_rayobject_raycast(R.raytree, &is)) {
- RE_instance_rotate_ray_restore(shi->obi, &is);
-
- visibility = 0.f;
- }
-
- lar->last_hit[shi->thread] = is.last_hit;
- }
- return visibility;
-}
-
-static int vol_get_bounds(ShadeInput *shi, const float co[3], const float vec[3], float hitco[3], Isect *isect, int intersect_type)
-{
-
- copy_v3_v3(isect->start, co);
- copy_v3_v3(isect->dir, vec);
- isect->dist = FLT_MAX;
- isect->mode = RE_RAY_MIRROR;
- isect->last_hit = NULL;
- isect->lay = -1;
- isect->check = RE_CHECK_VLR_NONE;
-
- if (intersect_type == VOL_BOUNDS_DEPTH) {
- isect->skip = RE_SKIP_VLR_NEIGHBOUR;
- isect->orig.face = (void *)shi->vlr;
- isect->orig.ob = (void *)shi->obi;
- }
- else { // if (intersect_type == VOL_BOUNDS_SS) {
- isect->skip = 0;
- isect->orig.face = NULL;
- isect->orig.ob = NULL;
- }
-
- RE_instance_rotate_ray(shi->obi, isect);
-
- if (RE_rayobject_raycast(R.raytree, isect)) {
- RE_instance_rotate_ray_restore(shi->obi, isect);
-
- hitco[0] = isect->start[0] + isect->dist * isect->dir[0];
- hitco[1] = isect->start[1] + isect->dist * isect->dir[1];
- hitco[2] = isect->start[2] + isect->dist * isect->dir[2];
- return 1;
- }
- else {
- return 0;
- }
-}
-
-static void shade_intersection(ShadeInput *shi, float col_r[4], Isect *is)
-{
- ShadeInput shi_new;
- ShadeResult shr_new;
-
- memset(&shi_new, 0, sizeof(ShadeInput));
-
- shi_new.mask = shi->mask;
- shi_new.osatex = shi->osatex;
- shi_new.thread = shi->thread;
- shi_new.depth = shi->depth + 1;
- shi_new.volume_depth = shi->volume_depth + 1;
- shi_new.xs = shi->xs;
- shi_new.ys = shi->ys;
- shi_new.lay = shi->lay;
- shi_new.passflag = SCE_PASS_COMBINED; /* result of tracing needs no pass info */
- shi_new.combinedflag = 0xFFFFFF; /* ray trace does all options */
- shi_new.light_override = shi->light_override;
- shi_new.mat_override = shi->mat_override;
-
- copy_v3_v3(shi_new.camera_co, is->start);
-
- memset(&shr_new, 0, sizeof(ShadeResult));
-
- /* hardcoded limit of 100 for now - prevents problems in weird geometry */
- if (shi->volume_depth < 100) {
- shade_ray(is, &shi_new, &shr_new);
- }
-
- copy_v3_v3(col_r, shr_new.combined);
- col_r[3] = shr_new.alpha;
-}
-
-static void vol_trace_behind(ShadeInput *shi, VlakRen *vlr, const float co[3], float col_r[4])
-{
- Isect isect;
-
- copy_v3_v3(isect.start, co);
- copy_v3_v3(isect.dir, shi->view);
- isect.dist = FLT_MAX;
-
- isect.mode = RE_RAY_MIRROR;
- isect.check = RE_CHECK_VLR_NONE;
- isect.skip = RE_SKIP_VLR_NEIGHBOUR;
- isect.orig.ob = (void *) shi->obi;
- isect.orig.face = (void *)vlr;
- isect.last_hit = NULL;
- isect.lay = -1;
-
- /* check to see if there's anything behind the volume, otherwise shade the sky */
- RE_instance_rotate_ray(shi->obi, &isect);
-
- if (RE_rayobject_raycast(R.raytree, &isect)) {
- RE_instance_rotate_ray_restore(shi->obi, &isect);
-
- shade_intersection(shi, col_r, &isect);
- }
- else {
- shadeSkyView(col_r, co, shi->view, NULL, shi->thread);
- shadeSunView(col_r, shi->view);
- }
-}
-
-
-/* trilinear interpolation */
-static void vol_get_precached_scattering(Render *re, ShadeInput *shi, float scatter_col[3], const float co[3])
-{
- VolumePrecache *vp = shi->obi->volume_precache;
- float bbmin[3], bbmax[3], dim[3];
- float world_co[3], sample_co[3];
-
- if (!vp) return;
-
- /* find sample point in global space bounding box 0.0-1.0 */
- global_bounds_obi(re, shi->obi, bbmin, bbmax);
- sub_v3_v3v3(dim, bbmax, bbmin);
- mul_v3_m4v3(world_co, re->viewinv, co);
-
- /* sample_co in 0.0-1.0 */
- sample_co[0] = (world_co[0] - bbmin[0]) / dim[0];
- sample_co[1] = (world_co[1] - bbmin[1]) / dim[1];
- sample_co[2] = (world_co[2] - bbmin[2]) / dim[2];
-
- scatter_col[0] = BLI_voxel_sample_triquadratic(vp->data_r, vp->res, sample_co);
- scatter_col[1] = BLI_voxel_sample_triquadratic(vp->data_g, vp->res, sample_co);
- scatter_col[2] = BLI_voxel_sample_triquadratic(vp->data_b, vp->res, sample_co);
-}
-
-/* Meta object density, brute force for now
- * (might be good enough anyway, don't need huge number of metaobs to model volumetric objects */
-static float metadensity(Object *ob, const float co[3])
-{
- float mat[4][4], imat[4][4], dens = 0.f;
- MetaBall *mb = (MetaBall *)ob->data;
- MetaElem *ml;
-
- /* transform co to meta-element */
- float tco[3] = {co[0], co[1], co[2]};
- mul_m4_m4m4(mat, R.viewmat, ob->obmat);
- invert_m4_m4(imat, mat);
- mul_m4_v3(imat, tco);
-
- for (ml = mb->elems.first; ml; ml = ml->next) {
- float bmat[3][3], dist2;
-
- /* element rotation transform */
- float tp[3] = {ml->x - tco[0], ml->y - tco[1], ml->z - tco[2]};
- quat_to_mat3(bmat, ml->quat);
- transpose_m3(bmat); /* rot.only, so inverse == transpose */
- mul_m3_v3(bmat, tp);
-
- /* MB_BALL default */
- switch (ml->type) {
- case MB_ELIPSOID:
- tp[0] /= ml->expx;
- tp[1] /= ml->expy;
- tp[2] /= ml->expz;
- break;
- case MB_CUBE:
- tp[2] = (tp[2] > ml->expz) ? (tp[2] - ml->expz) : ((tp[2] < -ml->expz) ? (tp[2] + ml->expz) : 0.f);
- /* no break, xy as plane */
- ATTR_FALLTHROUGH;
- case MB_PLANE:
- tp[1] = (tp[1] > ml->expy) ? (tp[1] - ml->expy) : ((tp[1] < -ml->expy) ? (tp[1] + ml->expy) : 0.f);
- /* no break, x as tube */
- ATTR_FALLTHROUGH;
- case MB_TUBE:
- tp[0] = (tp[0] > ml->expx) ? (tp[0] - ml->expx) : ((tp[0] < -ml->expx) ? (tp[0] + ml->expx) : 0.f);
- }
-
- /* ml->rad2 is not set */
- dist2 = 1.0f - (dot_v3v3(tp, tp) / (ml->rad * ml->rad));
- if (dist2 > 0.f)
- dens += (ml->flag & MB_NEGATIVE) ? -ml->s * dist2 * dist2 * dist2 : ml->s * dist2 * dist2 * dist2;
- }
-
- dens -= mb->thresh;
- return (dens < 0.f) ? 0.f : dens;
-}
-
-float vol_get_density(struct ShadeInput *shi, const float co[3])
-{
- float density = shi->mat->vol.density;
- float density_scale = shi->mat->vol.density_scale;
-
- if (shi->mat->mapto_textured & MAP_DENSITY)
- do_volume_tex(shi, co, MAP_DENSITY, NULL, &density, &R);
-
- /* if meta-object, modulate by metadensity without increasing it */
- if (shi->obi->obr->ob->type == OB_MBALL) {
- const float md = metadensity(shi->obi->obr->ob, co);
- if (md < 1.f) density *= md;
- }
-
- return density * density_scale;
-}
-
-
-/* Color of light that gets scattered out by the volume */
-/* Uses same physically based scattering parameter as in transmission calculations,
- * along with artificial reflection scale/reflection color tint */
-static void vol_get_reflection_color(ShadeInput *shi, float ref_col[3], const float co[3])
-{
- float scatter = shi->mat->vol.scattering;
- float reflection = shi->mat->vol.reflection;
- copy_v3_v3(ref_col, shi->mat->vol.reflection_col);
-
- if (shi->mat->mapto_textured & (MAP_SCATTERING + MAP_REFLECTION_COL))
- do_volume_tex(shi, co, MAP_SCATTERING + MAP_REFLECTION_COL, ref_col, &scatter, &R);
-
- /* only one single float parameter at a time... :s */
- if (shi->mat->mapto_textured & (MAP_REFLECTION))
- do_volume_tex(shi, co, MAP_REFLECTION, NULL, &reflection, &R);
-
- ref_col[0] = reflection * ref_col[0] * scatter;
- ref_col[1] = reflection * ref_col[1] * scatter;
- ref_col[2] = reflection * ref_col[2] * scatter;
-}
-
-/* compute emission component, amount of radiance to add per segment
- * can be textured with 'emit' */
-static void vol_get_emission(ShadeInput *shi, float emission_col[3], const float co[3])
-{
- float emission = shi->mat->vol.emission;
- copy_v3_v3(emission_col, shi->mat->vol.emission_col);
-
- if (shi->mat->mapto_textured & (MAP_EMISSION + MAP_EMISSION_COL))
- do_volume_tex(shi, co, MAP_EMISSION + MAP_EMISSION_COL, emission_col, &emission, &R);
-
- emission_col[0] = emission_col[0] * emission;
- emission_col[1] = emission_col[1] * emission;
- emission_col[2] = emission_col[2] * emission;
-}
-
-
-/* A combination of scattering and absorption -> known as sigma T.
- * This can possibly use a specific scattering color,
- * and absorption multiplier factor too, but these parameters are left out for simplicity.
- * It's easy enough to get a good wide range of results with just these two parameters. */
-static void vol_get_sigma_t(ShadeInput *shi, float sigma_t[3], const float co[3])
-{
- /* technically absorption, but named transmission color
- * since it describes the effect of the coloring *after* absorption */
- float transmission_col[3] = {shi->mat->vol.transmission_col[0], shi->mat->vol.transmission_col[1], shi->mat->vol.transmission_col[2]};
- float scattering = shi->mat->vol.scattering;
-
- if (shi->mat->mapto_textured & (MAP_SCATTERING + MAP_TRANSMISSION_COL))
- do_volume_tex(shi, co, MAP_SCATTERING + MAP_TRANSMISSION_COL, transmission_col, &scattering, &R);
-
- sigma_t[0] = (1.0f - transmission_col[0]) + scattering;
- sigma_t[1] = (1.0f - transmission_col[1]) + scattering;
- sigma_t[2] = (1.0f - transmission_col[2]) + scattering;
-}
-
-/* phase function - determines in which directions the light
- * is scattered in the volume relative to incoming direction
- * and view direction */
-static float vol_get_phasefunc(ShadeInput *UNUSED(shi), float g, const float w[3], const float wp[3])
-{
- const float normalize = 0.25f; // = 1.f/4.f = M_PI/(4.f*M_PI)
-
- /* normalization constant is 1/4 rather than 1/4pi, since
- * Blender's shading system doesn't normalize for
- * energy conservation - eg. multiplying by pdf ( 1/pi for a lambert brdf ).
- * This means that lambert surfaces in Blender are pi times brighter than they 'should be'
- * and therefore, with correct energy conservation, volumes will darker than other solid objects,
- * for the same lighting intensity.
- * To correct this, scale up the phase function values by pi
- * until Blender's shading system supports this better. --matt
- */
-
- if (g == 0.f) { /* isotropic */
- return normalize * 1.f;
- }
- else { /* schlick */
- const float k = 1.55f * g - 0.55f * g * g * g;
- const float kcostheta = k * dot_v3v3(w, wp);
- return normalize * (1.f - k * k) / ((1.f - kcostheta) * (1.f - kcostheta));
- }
-
- /* not used, but here for reference: */
-#if 0
- switch (phasefunc_type) {
- case MA_VOL_PH_MIEHAZY:
- return normalize * (0.5f + 4.5f * powf(0.5 * (1.f + costheta), 8.f));
- case MA_VOL_PH_MIEMURKY:
- return normalize * (0.5f + 16.5f * powf(0.5 * (1.f + costheta), 32.f));
- case MA_VOL_PH_RAYLEIGH:
- return normalize * 3.f / 4.f * (1 + costheta * costheta);
- case MA_VOL_PH_HG:
- return normalize * (1.f - g * g) / powf(1.f + g * g - 2.f * g * costheta, 1.5f);
- case MA_VOL_PH_SCHLICK:
- {
- const float k = 1.55f * g - 0.55f * g * g * g;
- const float kcostheta = k * costheta;
- return normalize * (1.f - k * k) / ((1.f - kcostheta) * (1.f - kcostheta));
- }
- case MA_VOL_PH_ISOTROPIC:
- default:
- return normalize * 1.f;
- }
-#endif
-}
-
-/* Compute transmittance = e^(-attenuation) */
-static void vol_get_transmittance_seg(ShadeInput *shi, float tr[3], float stepsize, const float co[3], float density)
-{
- /* input density = density at co */
- float tau[3] = {0.f, 0.f, 0.f};
- const float stepd = density * stepsize;
- float sigma_t[3];
-
- vol_get_sigma_t(shi, sigma_t, co);
-
- /* homogeneous volume within the sampled distance */
- tau[0] += stepd * sigma_t[0];
- tau[1] += stepd * sigma_t[1];
- tau[2] += stepd * sigma_t[2];
-
- tr[0] *= expf(-tau[0]);
- tr[1] *= expf(-tau[1]);
- tr[2] *= expf(-tau[2]);
-}
-
-/* Compute transmittance = e^(-attenuation) */
-static void vol_get_transmittance(ShadeInput *shi, float tr[3], const float co[3], const float endco[3])
-{
- float p[3] = {co[0], co[1], co[2]};
- float step_vec[3] = {endco[0] - co[0], endco[1] - co[1], endco[2] - co[2]};
- float tau[3] = {0.f, 0.f, 0.f};
-
- float t0 = 0.f;
- float t1 = normalize_v3(step_vec);
- float pt0 = t0;
-
- t0 += shi->mat->vol.stepsize * ((shi->mat->vol.stepsize_type == MA_VOL_STEP_CONSTANT) ? 0.5f : BLI_thread_frand(shi->thread));
- p[0] += t0 * step_vec[0];
- p[1] += t0 * step_vec[1];
- p[2] += t0 * step_vec[2];
- mul_v3_fl(step_vec, shi->mat->vol.stepsize);
-
- for (; t0 < t1; pt0 = t0, t0 += shi->mat->vol.stepsize) {
- const float d = vol_get_density(shi, p);
- const float stepd = (t0 - pt0) * d;
- float sigma_t[3];
-
- vol_get_sigma_t(shi, sigma_t, p);
-
- tau[0] += stepd * sigma_t[0];
- tau[1] += stepd * sigma_t[1];
- tau[2] += stepd * sigma_t[2];
-
- add_v3_v3(p, step_vec);
- }
-
- /* return transmittance */
- tr[0] = expf(-tau[0]);
- tr[1] = expf(-tau[1]);
- tr[2] = expf(-tau[2]);
-}
-
-static void vol_shade_one_lamp(struct ShadeInput *shi, const float co[3], const float view[3], LampRen *lar, float lacol[3])
-{
- float visifac, lv[3], lampdist;
- float tr[3] = {1.0, 1.0, 1.0};
- float hitco[3], *atten_co;
- float p, ref_col[3];
-
- if (lar->mode & LA_LAYER) if ((lar->lay & shi->obi->lay) == 0) return;
- if ((lar->lay & shi->lay) == 0) return;
- if (lar->energy == 0.0f) return;
-
- if ((visifac = lamp_get_visibility(lar, co, lv, &lampdist)) == 0.f) return;
-
- copy_v3_v3(lacol, &lar->r);
-
- if (lar->mode & LA_TEXTURE) {
- shi->osatex = 0;
- do_lamp_tex(lar, lv, shi, lacol, LA_TEXTURE);
- }
-
- mul_v3_fl(lacol, visifac);
-
- if (ELEM(lar->type, LA_SUN, LA_HEMI))
- copy_v3_v3(lv, lar->vec);
- negate_v3(lv);
-
- if (shi->mat->vol.shade_type == MA_VOL_SHADE_SHADOWED) {
- mul_v3_fl(lacol, vol_get_shadow(shi, lar, co));
- }
- else if (ELEM(shi->mat->vol.shade_type, MA_VOL_SHADE_SHADED, MA_VOL_SHADE_MULTIPLE, MA_VOL_SHADE_SHADEDPLUSMULTIPLE)) {
- Isect is;
-
- if (shi->mat->vol.shadeflag & MA_VOL_RECV_EXT_SHADOW) {
- mul_v3_fl(lacol, vol_get_shadow(shi, lar, co));
- if (IMB_colormanagement_get_luminance(lacol) < 0.001f) return;
- }
-
- /* find minimum of volume bounds, or lamp coord */
- if (vol_get_bounds(shi, co, lv, hitco, &is, VOL_BOUNDS_SS)) {
- float dist = len_v3v3(co, hitco);
- VlakRen *vlr = (VlakRen *)is.hit.face;
-
- /* simple internal shadowing */
- if (vlr->mat->material_type == MA_TYPE_SURFACE) {
- lacol[0] = lacol[1] = lacol[2] = 0.0f;
- return;
- }
-
- if (ELEM(lar->type, LA_SUN, LA_HEMI))
- /* infinite lights, can never be inside volume */
- atten_co = hitco;
- else if (lampdist < dist) {
- atten_co = lar->co;
- }
- else
- atten_co = hitco;
-
- vol_get_transmittance(shi, tr, co, atten_co);
-
- mul_v3_v3v3(lacol, lacol, tr);
- }
- else {
- /* Point is on the outside edge of the volume,
- * therefore no attenuation, full transmission.
- * Radiance from lamp remains unchanged */
- }
- }
-
- if (IMB_colormanagement_get_luminance(lacol) < 0.001f) return;
-
- normalize_v3(lv);
- p = vol_get_phasefunc(shi, shi->mat->vol.asymmetry, view, lv);
-
- /* physically based scattering with non-physically based RGB gain */
- vol_get_reflection_color(shi, ref_col, co);
-
- lacol[0] *= p * ref_col[0];
- lacol[1] *= p * ref_col[1];
- lacol[2] *= p * ref_col[2];
-}
-
-/* single scattering only for now */
-void vol_get_scattering(ShadeInput *shi, float scatter_col[3], const float co[3], const float view[3])
-{
- ListBase *lights;
- GroupObject *go;
- LampRen *lar;
-
- zero_v3(scatter_col);
-
- lights = get_lights(shi);
- for (go = lights->first; go; go = go->next) {
- float lacol[3] = {0.f, 0.f, 0.f};
- lar = go->lampren;
-
- if (lar) {
- vol_shade_one_lamp(shi, co, view, lar, lacol);
- add_v3_v3(scatter_col, lacol);
- }
- }
-}
-
-
-/*
- * The main volumetric integrator, using an emission/absorption/scattering model.
- *
- * Incoming radiance =
- *
- * outgoing radiance from behind surface * beam transmittance/attenuation
- * + added radiance from all points along the ray due to participating media
- * --> radiance for each segment =
- * (radiance added by scattering + radiance added by emission) * beam transmittance/attenuation
- */
-
-/* For ease of use, I've also introduced a 'reflection' and 'reflection color' parameter, which isn't
- * physically correct. This works as an RGB tint/gain on out-scattered light, but doesn't affect the light
- * that is transmitted through the volume. While having wavelength dependent absorption/scattering is more correct,
- * it also makes it harder to control the overall look of the volume since coloring the outscattered light results
- * in the inverse color being transmitted through the rest of the volume.
- */
-static void volumeintegrate(struct ShadeInput *shi, float col[4], const float co[3], const float endco[3])
-{
- float radiance[3] = {0.f, 0.f, 0.f};
- float tr[3] = {1.f, 1.f, 1.f};
- float p[3] = {co[0], co[1], co[2]};
- float step_vec[3] = {endco[0] - co[0], endco[1] - co[1], endco[2] - co[2]};
- const float stepsize = shi->mat->vol.stepsize;
-
- float t0 = 0.f;
- float pt0 = t0;
- float t1 = normalize_v3(step_vec); /* returns vector length */
-
- t0 += stepsize * ((shi->mat->vol.stepsize_type == MA_VOL_STEP_CONSTANT) ? 0.5f : BLI_thread_frand(shi->thread));
- p[0] += t0 * step_vec[0];
- p[1] += t0 * step_vec[1];
- p[2] += t0 * step_vec[2];
- mul_v3_fl(step_vec, stepsize);
-
- for (; t0 < t1; pt0 = t0, t0 += stepsize) {
- const float density = vol_get_density(shi, p);
-
- if (density > 0.00001f) {
- float scatter_col[3] = {0.f, 0.f, 0.f}, emit_col[3];
- const float stepd = (t0 - pt0) * density;
-
- /* transmittance component (alpha) */
- vol_get_transmittance_seg(shi, tr, stepsize, co, density);
-
- if (t0 > t1 * 0.25f) {
- /* only use depth cutoff after we've traced a little way into the volume */
- if (IMB_colormanagement_get_luminance(tr) < shi->mat->vol.depth_cutoff) break;
- }
-
- vol_get_emission(shi, emit_col, p);
-
- if (shi->obi->volume_precache) {
- float p2[3];
-
- p2[0] = p[0] + (step_vec[0] * 0.5f);
- p2[1] = p[1] + (step_vec[1] * 0.5f);
- p2[2] = p[2] + (step_vec[2] * 0.5f);
-
- vol_get_precached_scattering(&R, shi, scatter_col, p2);
- }
- else
- vol_get_scattering(shi, scatter_col, p, shi->view);
-
- radiance[0] += stepd * tr[0] * (emit_col[0] + scatter_col[0]);
- radiance[1] += stepd * tr[1] * (emit_col[1] + scatter_col[1]);
- radiance[2] += stepd * tr[2] * (emit_col[2] + scatter_col[2]);
- }
- add_v3_v3(p, step_vec);
- }
-
- /* multiply original color (from behind volume) with transmittance over entire distance */
- mul_v3_v3v3(col, tr, col);
- add_v3_v3(col, radiance);
-
- /* alpha <-- transmission luminance */
- col[3] = 1.0f - IMB_colormanagement_get_luminance(tr);
-}
-
-/* the main entry point for volume shading */
-static void volume_trace(struct ShadeInput *shi, struct ShadeResult *shr, int inside_volume)
-{
- float hitco[3], col[4] = {0.f, 0.f, 0.f, 0.f};
- const float *startco, *endco;
- int trace_behind = 1;
- const int ztransp = ((shi->depth == 0) && (shi->mat->mode & MA_TRANSP) && (shi->mat->mode & MA_ZTRANSP));
- Isect is;
-
- /* check for shading an internal face a volume object directly */
- if (inside_volume == VOL_SHADE_INSIDE)
- trace_behind = 0;
- else if (inside_volume == VOL_SHADE_OUTSIDE) {
- if (shi->flippednor)
- inside_volume = VOL_SHADE_INSIDE;
- }
-
- if (ztransp && inside_volume == VOL_SHADE_INSIDE) {
- MatInside *mi;
- int render_this = 0;
-
- /* don't render the backfaces of ztransp volume materials.
- *
- * volume shading renders the internal volume from between the
- * ' view intersection of the solid volume to the
- * intersection on the other side, as part of the shading of
- * the front face.
- *
- * Because ztransp renders both front and back faces independently
- * this will double up, so here we prevent rendering the backface as well,
- * which would otherwise render the volume in between the camera and the backface
- * --matt */
-
- for (mi = R.render_volumes_inside.first; mi; mi = mi->next) {
- /* weak... */
- if (mi->ma == shi->mat) render_this = 1;
- }
- if (!render_this) return;
- }
-
-
- if (inside_volume == VOL_SHADE_INSIDE) {
- startco = shi->camera_co;
- endco = shi->co;
-
- if (trace_behind) {
- if (!ztransp)
- /* trace behind the volume object */
- vol_trace_behind(shi, shi->vlr, endco, col);
- }
- else {
- /* we're tracing through the volume between the camera
- * and a solid surface, so use that pre-shaded radiance */
- copy_v4_v4(col, shr->combined);
- }
-
- /* shade volume from 'camera' to 1st hit point */
- volumeintegrate(shi, col, startco, endco);
- }
- /* trace to find a backface, the other side bounds of the volume */
- /* (ray intersect ignores front faces here) */
- else if (vol_get_bounds(shi, shi->co, shi->view, hitco, &is, VOL_BOUNDS_DEPTH)) {
- VlakRen *vlr = (VlakRen *)is.hit.face;
-
- startco = shi->co;
- endco = hitco;
-
- if (!ztransp) {
- /* if it's another face in the same material */
- if (vlr->mat == shi->mat) {
- /* trace behind the 2nd (raytrace) hit point */
- vol_trace_behind(shi, (VlakRen *)is.hit.face, endco, col);
- }
- else {
- shade_intersection(shi, col, &is);
- }
- }
-
- /* shade volume from 1st hit point to 2nd hit point */
- volumeintegrate(shi, col, startco, endco);
- }
-
- if (ztransp)
- col[3] = col[3] > 1.f ? 1.f : col[3];
- else
- col[3] = 1.f;
-
- copy_v3_v3(shr->combined, col);
- shr->alpha = col[3];
-
- copy_v3_v3(shr->diff, shr->combined);
- copy_v3_v3(shr->diffshad, shr->diff);
-}
-
-/* Traces a shadow through the object,
- * pretty much gets the transmission over a ray path */
-void shade_volume_shadow(struct ShadeInput *shi, struct ShadeResult *shr, struct Isect *last_is)
-{
- float hitco[3];
- float tr[3] = {1.0, 1.0, 1.0};
- Isect is = {{0}};
- const float *startco, *endco;
-
- memset(shr, 0, sizeof(ShadeResult));
-
- /* if 1st hit normal is facing away from the camera,
- * then we're inside the volume already. */
- if (shi->flippednor) {
- startco = last_is->start;
- endco = shi->co;
- }
-
- /* trace to find a backface, the other side bounds of the volume */
- /* (ray intersect ignores front faces here) */
- else if (vol_get_bounds(shi, shi->co, shi->view, hitco, &is, VOL_BOUNDS_DEPTH)) {
- startco = shi->co;
- endco = hitco;
- }
- else {
- shr->combined[0] = shr->combined[1] = shr->combined[2] = 0.f;
- shr->alpha = shr->combined[3] = 1.f;
- return;
- }
-
- vol_get_transmittance(shi, tr, startco, endco);
-
-
- /* if we hit another face in the same volume bounds */
- /* shift raytrace coordinates to the hit point, to avoid shading volume twice */
- /* due to idiosyncracy in ray_trace_shadow_tra() */
- if (is.hit.ob == shi->obi) {
- copy_v3_v3(shi->co, hitco);
- last_is->dist += is.dist;
- shi->vlr = (VlakRen *)is.hit.face;
- }
-
-
- copy_v3_v3(shr->combined, tr);
- shr->combined[3] = 1.0f - IMB_colormanagement_get_luminance(tr);
- shr->alpha = shr->combined[3];
-}
-
-
-/* delivers a fully filled in ShadeResult, for all passes */
-void shade_volume_outside(ShadeInput *shi, ShadeResult *shr)
-{
- memset(shr, 0, sizeof(ShadeResult));
- volume_trace(shi, shr, VOL_SHADE_OUTSIDE);
-}
-
-
-void shade_volume_inside(ShadeInput *shi, ShadeResult *shr)
-{
- MatInside *m;
- Material *mat_backup;
- ObjectInstanceRen *obi_backup;
- float prev_alpha = shr->alpha;
-
- /* XXX: extend to multiple volumes perhaps later */
- mat_backup = shi->mat;
- obi_backup = shi->obi;
-
- m = R.render_volumes_inside.first;
- shi->mat = m->ma;
- shi->obi = m->obi;
- shi->obr = m->obi->obr;
-
- volume_trace(shi, shr, VOL_SHADE_INSIDE);
-
- shr->alpha = shr->alpha + prev_alpha;
- CLAMP(shr->alpha, 0.0f, 1.0f);
-
- shi->mat = mat_backup;
- shi->obi = obi_backup;
- shi->obr = obi_backup->obr;
-}
diff --git a/source/blender/render/intern/source/voxeldata.c b/source/blender/render/intern/source/voxeldata.c
deleted file mode 100644
index c45bde300e7..00000000000
--- a/source/blender/render/intern/source/voxeldata.c
+++ /dev/null
@@ -1,571 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Raul Fernandez Hernandez (Farsthary), Matt Ebb.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/render/intern/source/voxeldata.c
- * \ingroup render
- */
-
-
-#include <math.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_threads.h"
-#include "BLI_voxel.h"
-#include "BLI_utildefines.h"
-
-#include "BLT_translation.h"
-
-#include "IMB_imbuf.h"
-#include "IMB_imbuf_types.h"
-
-#include "BKE_cloth.h"
-#include "BKE_global.h"
-#include "BKE_image.h"
-#include "BKE_main.h"
-#include "BKE_modifier.h"
-
-#include "smoke_API.h"
-#include "BPH_mass_spring.h"
-
-#include "DNA_texture_types.h"
-#include "DNA_object_force_types.h"
-#include "DNA_object_types.h"
-#include "DNA_particle_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_smoke_types.h"
-
-
-#include "render_types.h"
-#include "texture.h"
-#include "voxeldata.h"
-
-static bool is_vd_res_ok(VoxelData *vd)
-{
- /* arbitrary large value so corrupt headers don't break */
- const int min = 1, max = 100000;
- return (vd->resol[0] >= min && vd->resol[0] <= max) &&
- (vd->resol[1] >= min && vd->resol[1] <= max) &&
- (vd->resol[2] >= min && vd->resol[2] <= max);
-}
-
-/* use size_t because the result may exceed INT_MAX */
-static size_t vd_resol_size(VoxelData *vd)
-{
- return (size_t)vd->resol[0] * (size_t)vd->resol[1] * (size_t)vd->resol[2];
-}
-
-static int load_frame_blendervoxel(VoxelData *vd, FILE *fp, int frame)
-{
- const size_t size = vd_resol_size(vd);
- size_t offset = sizeof(VoxelDataHeader);
-
- if (is_vd_res_ok(vd) == false)
- return 0;
-
- vd->dataset = MEM_mapallocN(sizeof(float) * size, "voxel dataset");
- if (vd->dataset == NULL) return 0;
-
- if (fseek(fp, frame * size * sizeof(float) + offset, 0) == -1)
- return 0;
- if (fread(vd->dataset, sizeof(float), size, fp) != size)
- return 0;
-
- vd->cachedframe = frame;
- vd->ok = 1;
- return 1;
-}
-
-static int load_frame_raw8(VoxelData *vd, FILE *fp, int frame)
-{
- const size_t size = vd_resol_size(vd);
- size_t i;
- char *data_c;
-
- if (is_vd_res_ok(vd) == false)
- return 0;
-
- vd->dataset = MEM_mapallocN(sizeof(float) * size, "voxel dataset");
- if (vd->dataset == NULL) return 0;
- data_c = (char *)MEM_mallocN(sizeof(char) * size, "temporary voxel file reading storage");
- if (data_c == NULL) {
- MEM_freeN(vd->dataset);
- vd->dataset = NULL;
- return 0;
- }
-
- if (fseek(fp, (frame - 1) * size * sizeof(char), 0) == -1) {
- MEM_freeN(data_c);
- MEM_freeN(vd->dataset);
- vd->dataset = NULL;
- return 0;
- }
- if (fread(data_c, sizeof(char), size, fp) != size) {
- MEM_freeN(data_c);
- MEM_freeN(vd->dataset);
- vd->dataset = NULL;
- return 0;
- }
-
- for (i = 0; i < size; i++) {
- vd->dataset[i] = (float)data_c[i] / 255.f;
- }
- MEM_freeN(data_c);
-
- vd->cachedframe = frame;
- vd->ok = 1;
- return 1;
-}
-
-static void load_frame_image_sequence(VoxelData *vd, Tex *tex)
-{
- ImBuf *ibuf;
- Image *ima = tex->ima;
- ImageUser *tiuser = &tex->iuser;
- ImageUser iuser = *(tiuser);
- int x = 0, y = 0, z = 0;
- const float *rf;
-
- if (!ima) return;
- if (iuser.frames == 0) return;
-
- ima->source = IMA_SRC_SEQUENCE;
- iuser.framenr = 1 + iuser.offset;
-
- /* find the first valid ibuf and use it to initialize the resolution of the data set */
- /* need to do this in advance so we know how much memory to allocate */
- ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
- while (!ibuf && (iuser.framenr < iuser.frames)) {
- iuser.framenr++;
- ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
- }
- if (!ibuf) return;
- if (!ibuf->rect_float) IMB_float_from_rect(ibuf);
-
- vd->flag |= TEX_VD_STILL;
- vd->resol[0] = ibuf->x;
- vd->resol[1] = ibuf->y;
- vd->resol[2] = iuser.frames;
- vd->dataset = MEM_mapallocN(sizeof(float) * vd_resol_size(vd), "voxel dataset");
-
- for (z = 0; z < iuser.frames; z++) {
- /* get a new ibuf for each frame */
- if (z > 0) {
- iuser.framenr++;
- BKE_image_release_ibuf(ima, ibuf, NULL);
- ibuf = BKE_image_acquire_ibuf(ima, &iuser, NULL);
- if (!ibuf) break;
- if (!ibuf->rect_float) IMB_float_from_rect(ibuf);
- }
- rf = ibuf->rect_float;
-
- for (y = 0; y < ibuf->y; y++) {
- for (x = 0; x < ibuf->x; x++) {
- /* currently averaged to monchrome */
- vd->dataset[BLI_VOXEL_INDEX(x, y, z, vd->resol)] = (rf[0] + rf[1] + rf[2]) / 3.0f;
- rf += 4;
- }
- }
-
- BKE_image_free_anim_ibufs(ima, iuser.framenr);
- }
-
- BKE_image_release_ibuf(ima, ibuf, NULL);
-
- vd->ok = 1;
- return;
-}
-
-static int read_voxeldata_header(FILE *fp, struct VoxelData *vd)
-{
- VoxelDataHeader *h = (VoxelDataHeader *)MEM_mallocN(sizeof(VoxelDataHeader), "voxel data header");
-
- rewind(fp);
- if (fread(h, sizeof(VoxelDataHeader), 1, fp) != 1) {
- MEM_freeN(h);
- return 0;
- }
-
- vd->resol[0] = h->resolX;
- vd->resol[1] = h->resolY;
- vd->resol[2] = h->resolZ;
-
- MEM_freeN(h);
- return 1;
-}
-
-static void init_frame_smoke(VoxelData *vd, int cfra)
-{
-#ifdef WITH_SMOKE
- Object *ob;
- ModifierData *md;
-
- vd->dataset = NULL;
- if (vd->object == NULL) return;
- ob = vd->object;
-
- /* draw code for smoke */
- if ((md = (ModifierData *)modifiers_findByType(ob, eModifierType_Smoke))) {
- SmokeModifierData *smd = (SmokeModifierData *)md;
- SmokeDomainSettings *sds = smd->domain;
-
- if (sds && sds->fluid) {
- BLI_rw_mutex_lock(sds->fluid_mutex, THREAD_LOCK_READ);
-
- if (!sds->fluid) {
- BLI_rw_mutex_unlock(sds->fluid_mutex);
- return;
- }
-
- if (cfra < sds->point_cache[0]->startframe)
- ; /* don't show smoke before simulation starts, this could be made an option in the future */
- else if (vd->smoked_type == TEX_VD_SMOKEHEAT) {
- size_t totRes;
- size_t i;
- float *heat;
-
- if (!smoke_has_heat(sds->fluid)) {
- BLI_rw_mutex_unlock(sds->fluid_mutex);
- return;
- }
-
- copy_v3_v3_int(vd->resol, sds->res);
- totRes = vd_resol_size(vd);
- vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data");
- /* get heat data */
- heat = smoke_get_heat(sds->fluid);
-
- /* scale heat values from -2.0-2.0 to 0.0-1.0 */
- for (i = 0; i < totRes; i++) {
- vd->dataset[i] = (heat[i] + 2.0f) / 4.0f;
- }
- }
- else if (vd->smoked_type == TEX_VD_SMOKEVEL) {
- size_t totRes;
- size_t i;
- float *xvel, *yvel, *zvel;
-
- copy_v3_v3_int(vd->resol, sds->res);
- totRes = vd_resol_size(vd);
- vd->dataset = MEM_mapallocN(sizeof(float) * (totRes), "smoke data");
- /* get velocity data */
- xvel = smoke_get_velocity_x(sds->fluid);
- yvel = smoke_get_velocity_y(sds->fluid);
- zvel = smoke_get_velocity_z(sds->fluid);
-
- /* map velocities between 0 and 0.3f */
- for (i = 0; i < totRes; i++) {
- vd->dataset[i] = sqrtf(xvel[i] * xvel[i] + yvel[i] * yvel[i] + zvel[i] * zvel[i]) * 3.0f;
- }
-
- }
- else if (vd->smoked_type == TEX_VD_SMOKEFLAME) {
- size_t totRes;
- float *flame;
-
- if (sds->flags & MOD_SMOKE_HIGHRES) {
- if (!smoke_turbulence_has_fuel(sds->wt)) {
- BLI_rw_mutex_unlock(sds->fluid_mutex);
- return;
- }
- smoke_turbulence_get_res(sds->wt, vd->resol);
- flame = smoke_turbulence_get_flame(sds->wt);
- }
- else {
- if (!smoke_has_fuel(sds->fluid)) {
- BLI_rw_mutex_unlock(sds->fluid_mutex);
- return;
- }
- copy_v3_v3_int(vd->resol, sds->res);
- flame = smoke_get_flame(sds->fluid);
- }
-
- /* always store copy, as smoke internal data can change */
- totRes = vd_resol_size(vd);
- vd->dataset = MEM_mapallocN(sizeof(float)*(totRes), "smoke data");
- memcpy(vd->dataset, flame, sizeof(float)*totRes);
- }
- else {
- size_t totCells;
- int depth = 4;
- vd->data_type = TEX_VD_RGBA_PREMUL;
-
- /* data resolution */
- if (sds->flags & MOD_SMOKE_HIGHRES) {
- smoke_turbulence_get_res(sds->wt, vd->resol);
- }
- else {
- copy_v3_v3_int(vd->resol, sds->res);
- }
-
- /* TODO: is_vd_res_ok(rvd) doesnt check this resolution */
- totCells = vd_resol_size(vd) * depth;
- /* always store copy, as smoke internal data can change */
- vd->dataset = MEM_mapallocN(sizeof(float) * totCells, "smoke data");
-
- if (sds->flags & MOD_SMOKE_HIGHRES) {
- if (smoke_turbulence_has_colors(sds->wt)) {
- smoke_turbulence_get_rgba(sds->wt, vd->dataset, 1);
- }
- else {
- smoke_turbulence_get_rgba_from_density(sds->wt, sds->active_color, vd->dataset, 1);
- }
- }
- else {
- if (smoke_has_colors(sds->fluid)) {
- smoke_get_rgba(sds->fluid, vd->dataset, 1);
- }
- else {
- smoke_get_rgba_from_density(sds->fluid, sds->active_color, vd->dataset, 1);
- }
- }
- } /* end of fluid condition */
-
- BLI_rw_mutex_unlock(sds->fluid_mutex);
- }
- }
-
- vd->ok = 1;
-
-#else // WITH_SMOKE
- (void)vd;
- (void)cfra;
-
- vd->dataset = NULL;
-#endif
-}
-
-static void init_frame_hair(VoxelData *vd, int UNUSED(cfra))
-{
- Object *ob;
- ModifierData *md;
-
- vd->dataset = NULL;
- if (vd->object == NULL) return;
- ob = vd->object;
-
- if ((md = (ModifierData *)modifiers_findByType(ob, eModifierType_ParticleSystem))) {
- ParticleSystemModifierData *pmd = (ParticleSystemModifierData *)md;
-
- if (pmd->psys && pmd->psys->clmd) {
- vd->ok |= BPH_cloth_solver_get_texture_data(ob, pmd->psys->clmd, vd);
- }
- }
-}
-
-void cache_voxeldata(Tex *tex, int scene_frame)
-{
- VoxelData *vd = tex->vd;
- FILE *fp;
- int curframe;
- char path[sizeof(vd->source_path)];
-
- /* only re-cache if dataset needs updating */
- if ((vd->flag & TEX_VD_STILL) || (vd->cachedframe == scene_frame))
- if (vd->ok) return;
-
- /* clear out old cache, ready for new */
- if (vd->dataset) {
- MEM_freeN(vd->dataset);
- vd->dataset = NULL;
- }
- /* reset data_type */
- vd->data_type = TEX_VD_INTENSITY;
-
- if (vd->flag & TEX_VD_STILL)
- curframe = vd->still_frame;
- else
- curframe = scene_frame;
-
- BLI_strncpy(path, vd->source_path, sizeof(path));
-
- /* each type is responsible for setting to true */
- vd->ok = false;
-
- switch (vd->file_format) {
- case TEX_VD_IMAGE_SEQUENCE:
- load_frame_image_sequence(vd, tex);
- return;
- case TEX_VD_SMOKE:
- init_frame_smoke(vd, scene_frame);
- return;
- case TEX_VD_HAIR:
- init_frame_hair(vd, scene_frame);
- return;
- case TEX_VD_BLENDERVOXEL:
- BLI_path_abs(path, G.main->name);
- fp = BLI_fopen(path, "rb");
- if (!fp) return;
-
- if (read_voxeldata_header(fp, vd))
- load_frame_blendervoxel(vd, fp, curframe - 1);
-
- fclose(fp);
- return;
- case TEX_VD_RAW_8BIT:
- BLI_path_abs(path, G.main->name);
- fp = BLI_fopen(path, "rb");
- if (!fp) return;
-
- load_frame_raw8(vd, fp, curframe);
- fclose(fp);
- return;
- }
-}
-
-void make_voxeldata(struct Render *re)
-{
- Tex *tex;
-
- re->i.infostr = IFACE_("Loading voxel datasets");
- re->stats_draw(re->sdh, &re->i);
-
- /* XXX: should be doing only textures used in this render */
- for (tex = re->main->tex.first; tex; tex = tex->id.next) {
- if (tex->id.us && tex->type == TEX_VOXELDATA) {
- cache_voxeldata(tex, re->r.cfra);
- }
- }
-
- re->i.infostr = NULL;
- re->stats_draw(re->sdh, &re->i);
-
-}
-
-int voxeldatatex(struct Tex *tex, const float texvec[3], struct TexResult *texres)
-{
- VoxelData *vd = tex->vd;
- float co[3], offset[3] = {0.5, 0.5, 0.5}, a;
- int retval = (vd->data_type == TEX_VD_RGBA_PREMUL) ? TEX_RGB : TEX_INT;
- int depth = (vd->data_type == TEX_VD_RGBA_PREMUL) ? 4 : 1;
- int ch;
-
- if (vd->dataset == NULL) {
- texres->tin = 0.0f;
- return 0;
- }
-
- /* scale lookup from 0.0-1.0 (original location) to -1.0, 1.0, consistent with image texture tex coords */
- /* in implementation this works backwards, bringing sample locations from -1.0, 1.0
- * to the range 0.0, 1.0, before looking up in the voxel structure. */
- copy_v3_v3(co, texvec);
- mul_v3_fl(co, 0.5f);
- add_v3_v3(co, offset);
-
- /* co is now in the range 0.0, 1.0 */
- switch (vd->extend) {
- case TEX_CLIP:
- {
- if ((co[0] < 0.f || co[0] > 1.f) || (co[1] < 0.f || co[1] > 1.f) || (co[2] < 0.f || co[2] > 1.f)) {
- texres->tin = 0.f;
- return retval;
- }
- break;
- }
- case TEX_REPEAT:
- {
- co[0] = co[0] - floorf(co[0]);
- co[1] = co[1] - floorf(co[1]);
- co[2] = co[2] - floorf(co[2]);
- break;
- }
- case TEX_EXTEND:
- {
- CLAMP(co[0], 0.f, 1.f);
- CLAMP(co[1], 0.f, 1.f);
- CLAMP(co[2], 0.f, 1.f);
- break;
- }
- }
-
- for (ch = 0; ch < depth; ch++) {
- float *dataset = vd->dataset + ch*vd->resol[0]*vd->resol[1]*vd->resol[2];
- float *result = &texres->tin;
-
- if (vd->data_type == TEX_VD_RGBA_PREMUL) {
- switch (ch) {
- case 0:
- result = &texres->tr;
- break;
- case 1:
- result = &texres->tg;
- break;
- case 2:
- result = &texres->tb;
- break;
- }
- }
-
- switch (vd->interp_type) {
- case TEX_VD_NEARESTNEIGHBOR:
- *result = BLI_voxel_sample_nearest(dataset, vd->resol, co);
- break;
- case TEX_VD_LINEAR:
- *result = BLI_voxel_sample_trilinear(dataset, vd->resol, co);
- break;
- case TEX_VD_QUADRATIC:
- *result = BLI_voxel_sample_triquadratic(dataset, vd->resol, co);
- break;
- case TEX_VD_TRICUBIC_CATROM:
- case TEX_VD_TRICUBIC_BSPLINE:
- *result = BLI_voxel_sample_tricubic(dataset, vd->resol, co, (vd->interp_type == TEX_VD_TRICUBIC_BSPLINE));
- break;
- }
- }
-
- a = texres->tin;
- texres->tin *= vd->int_multiplier;
- BRICONT;
-
- if (vd->data_type == TEX_VD_RGBA_PREMUL) {
- /* unmultiply */
- if (a>0.001f) {
- texres->tr /= a;
- texres->tg /= a;
- texres->tb /= a;
- }
- texres->talpha = 1;
- }
- else {
- texres->tr = texres->tin;
- texres->tg = texres->tin;
- texres->tb = texres->tin;
- }
-
- texres->ta = texres->tin;
- BRICONTRGB;
-
- return retval;
-}
diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c
index aa073ad9a83..3837383c4c7 100644
--- a/source/blender/render/intern/source/zbuf.c
+++ b/source/blender/render/intern/source/zbuf.c
@@ -34,40 +34,11 @@
/* Common includes */
/*---------------------------------------------------------------------------*/
-#include <math.h>
-#include <float.h>
-#include <stdlib.h>
-#include <limits.h>
#include <string.h>
-#include "BLI_math.h"
-#include "BLI_blenlib.h"
-#include "BLI_jitter_2d.h"
-#include "BLI_threads.h"
-#include "BLI_utildefines.h"
-
#include "MEM_guardedalloc.h"
-#include "DNA_lamp_types.h"
-#include "DNA_node_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_material_types.h"
-
-#include "BKE_global.h"
-#include "BKE_material.h"
-
-
-#include "RE_render_ext.h"
-
-/* local includes */
-#include "pixelblending.h"
-#include "render_result.h"
-#include "render_types.h"
-#include "renderdatabase.h"
-#include "rendercore.h"
-#include "shadbuf.h"
-#include "shading.h"
-#include "strand.h"
+#include "BLI_math_base.h"
/* own includes */
#include "zbuf.h"
@@ -77,17 +48,10 @@
# pragma GCC diagnostic ignored "-Wdouble-promotion"
#endif
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-/* defined in pipeline.c, is hardcopy of active dynamic allocated Render */
-/* only to be used here in this file, it's for speed */
-extern struct Render R;
-/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
-
-
/* ****************** Spans ******************************* */
/* each zbuffer has coordinates transformed to local rect coordinates, so we can simply clip */
-void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty, float clipcrop)
+void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty)
{
memset(zspan, 0, sizeof(ZSpan));
@@ -96,8 +60,6 @@ void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty, float clipcrop)
zspan->span1= MEM_mallocN(recty*sizeof(float), "zspan");
zspan->span2= MEM_mallocN(recty*sizeof(float), "zspan");
-
- zspan->clipcrop= clipcrop;
}
void zbuf_free_span(ZSpan *zspan)
@@ -200,1312 +162,6 @@ static void zbuf_add_to_span(ZSpan *zspan, const float v1[2], const float v2[2])
/* Functions */
/*-----------------------------------------------------------*/
-void fillrect(int *rect, int x, int y, int val)
-{
- int len, *drect;
-
- len= x*y;
- drect= rect;
- while (len>0) {
- len--;
- *drect= val;
- drect++;
- }
-}
-
-/* based on Liang&Barsky, for clipping of pyramidical volume */
-static short cliptestf(float a, float b, float c, float d, float *u1, float *u2)
-{
- float p= a + b, q= c + d, r;
-
- if (p<0.0f) {
- if (q<p) return 0;
- else if (q<0.0f) {
- r= q/p;
- if (r>*u2) return 0;
- else if (r>*u1) *u1=r;
- }
- }
- else {
- if (p>0.0f) {
- if (q<0.0f) return 0;
- else if (q<p) {
- r= q/p;
- if (r<*u1) return 0;
- else if (r<*u2) *u2=r;
- }
- }
- else if (q<0.0f) return 0;
- }
- return 1;
-}
-
-int testclip(const float v[4])
-{
- float abs4; /* WATCH IT: this function should do the same as cliptestf, otherwise troubles in zbufclip()*/
- short c=0;
-
- /* if we set clip flags, the clipping should be at least larger than epsilon.
- * prevents issues with vertices lying exact on borders */
- abs4= fabsf(v[3]) + FLT_EPSILON;
-
- if ( v[0] < -abs4) c+=1;
- else if ( v[0] > abs4) c+=2;
-
- if ( v[1] > abs4) c+=4;
- else if ( v[1] < -abs4) c+=8;
-
- if (v[2] < -abs4) c+=16; /* this used to be " if (v[2]<0) ", see clippz() */
- else if (v[2]> abs4) c+= 32;
-
- return c;
-}
-
-
-
-/* ************* ACCUMULATION ZBUF ************ */
-
-
-static APixstr *addpsmainA(ListBase *lb)
-{
- APixstrMain *psm;
-
- psm= MEM_mallocN(sizeof(APixstrMain), "addpsmainA");
- BLI_addtail(lb, psm);
- psm->ps= MEM_callocN(4096*sizeof(APixstr), "pixstr");
-
- return psm->ps;
-}
-
-void freepsA(ListBase *lb)
-{
- APixstrMain *psm, *psmnext;
-
- for (psm= lb->first; psm; psm= psmnext) {
- psmnext= psm->next;
- if (psm->ps)
- MEM_freeN(psm->ps);
- MEM_freeN(psm);
- }
-}
-
-static APixstr *addpsA(ZSpan *zspan)
-{
- /* make new PS */
- if (zspan->apsmcounter==0) {
- zspan->curpstr= addpsmainA(zspan->apsmbase);
- zspan->apsmcounter= 4095;
- }
- else {
- zspan->curpstr++;
- zspan->apsmcounter--;
- }
- return zspan->curpstr;
-}
-
-static void zbuffillAc4(ZSpan *zspan, int obi, int zvlnr,
- const float *v1, const float *v2, const float *v3, const float *v4)
-{
- APixstr *ap, *apofs, *apn;
- double zxd, zyd, zy0, zverg;
- float x0, y0, z0;
- float x1, y1, z1, x2, y2, z2, xx1;
- const float *span1, *span2;
- int *rz, *rm, x, y;
- int sn1, sn2, rectx, *rectzofs, *rectmaskofs, my0, my2, mask;
-
- /* init */
- zbuf_init_span(zspan);
-
- /* set spans */
- zbuf_add_to_span(zspan, v1, v2);
- zbuf_add_to_span(zspan, v2, v3);
- if (v4) {
- zbuf_add_to_span(zspan, v3, v4);
- zbuf_add_to_span(zspan, v4, v1);
- }
- else
- zbuf_add_to_span(zspan, v3, v1);
-
- /* clipped */
- if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
-
- my0 = max_ii(zspan->miny1, zspan->miny2);
- my2 = min_ii(zspan->maxy1, zspan->maxy2);
-
- if (my2<my0) return;
-
- /* ZBUF DX DY, in floats still */
- x1= v1[0]- v2[0];
- x2= v2[0]- v3[0];
- y1= v1[1]- v2[1];
- y2= v2[1]- v3[1];
- z1= v1[2]- v2[2];
- z2= v2[2]- v3[2];
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
- z0= x1*y2-y1*x2;
-
- if (z0==0.0f) return;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
-
- zxd= -(double)x0/(double)z0;
- zyd= -(double)y0/(double)z0;
- zy0= ((double)my2)*zyd + (double)xx1;
-
- /* start-offset in rect */
- rectx= zspan->rectx;
- rectzofs= (int *)(zspan->arectz+rectx*(my2));
- rectmaskofs= (int *)(zspan->rectmask+rectx*(my2));
- apofs= (zspan->apixbuf+ rectx*(my2));
- mask= zspan->mask;
-
- /* correct span */
- sn1= (my0 + my2)/2;
- if (zspan->span1[sn1] < zspan->span2[sn1]) {
- span1= zspan->span1+my2;
- span2= zspan->span2+my2;
- }
- else {
- span1= zspan->span2+my2;
- span2= zspan->span1+my2;
- }
-
- for (y=my2; y>=my0; y--, span1--, span2--) {
-
- sn1= floor(*span1);
- sn2= floor(*span2);
- sn1++;
-
- if (sn2>=rectx) sn2= rectx-1;
- if (sn1<0) sn1= 0;
-
- if (sn2>=sn1) {
- int intzverg;
-
- zverg= (double)sn1*zxd + zy0;
- rz= rectzofs+sn1;
- rm= rectmaskofs+sn1;
- ap= apofs+sn1;
- x= sn2-sn1;
-
- zverg-= zspan->polygon_offset;
-
- while (x>=0) {
- intzverg = round_db_to_int_clamp(zverg);
-
- if ( intzverg < *rz) {
- if (!zspan->rectmask || intzverg > *rm) {
-
- apn= ap;
- while (apn) {
- if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= intzverg; apn->mask[0]= mask; break; }
- if (apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; }
- if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= intzverg; apn->mask[1]= mask; break; }
- if (apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; }
- if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= intzverg; apn->mask[2]= mask; break; }
- if (apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; }
- if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= intzverg; apn->mask[3]= mask; break; }
- if (apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; }
- if (apn->next==NULL) apn->next= addpsA(zspan);
- apn= apn->next;
- }
- }
- }
- zverg+= zxd;
- rz++;
- rm++;
- ap++;
- x--;
- }
- }
-
- zy0-=zyd;
- rectzofs-= rectx;
- rectmaskofs-= rectx;
- apofs-= rectx;
- }
-}
-
-
-
-static void zbuflineAc(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], const float vec2[3])
-{
- APixstr *ap, *apn;
- const int *rectz, *rectmask;
- int start, end, x, y, oldx, oldy, ofs;
- int dz, vergz, mask, maxtest=0;
- float dx, dy;
- float v1[3], v2[3];
-
- dx= vec2[0]-vec1[0];
- dy= vec2[1]-vec1[1];
-
- mask= zspan->mask;
-
- if (fabsf(dx) > fabsf(dy)) {
-
- /* all lines from left to right */
- if (vec1[0]<vec2[0]) {
- copy_v3_v3(v1, vec1);
- copy_v3_v3(v2, vec2);
- }
- else {
- copy_v3_v3(v2, vec1);
- copy_v3_v3(v1, vec2);
- dx= -dx; dy= -dy;
- }
-
- start= floor(v1[0]);
- end= start+floor(dx);
- if (end>=zspan->rectx) end= zspan->rectx-1;
-
- oldy= floor(v1[1]);
- dy/= dx;
-
- vergz= v1[2];
- vergz-= zspan->polygon_offset;
- dz= (v2[2]-v1[2])/dx;
- if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */
-
- rectz= (int *)(zspan->arectz+zspan->rectx*(oldy) +start);
- rectmask= (int *)(zspan->rectmask+zspan->rectx*(oldy) +start);
- ap= (zspan->apixbuf+ zspan->rectx*(oldy) +start);
-
- if (dy<0) ofs= -zspan->rectx;
- else ofs= zspan->rectx;
-
- for (x= start; x<=end; x++, rectz++, rectmask++, ap++) {
-
- y= floor(v1[1]);
- if (y!=oldy) {
- oldy= y;
- rectz+= ofs;
- rectmask+= ofs;
- ap+= ofs;
- }
-
- if (x>=0 && y>=0 && y<zspan->recty) {
- if (vergz<*rectz) {
- if (!zspan->rectmask || vergz>*rectmask) {
-
- apn= ap;
- while (apn) { /* loop unrolled */
- if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
- if (apn->p[0]==zvlnr && apn->obi[0]==obi) {apn->mask[0]|= mask; break; }
- if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
- if (apn->p[1]==zvlnr && apn->obi[1]==obi) {apn->mask[1]|= mask; break; }
- if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
- if (apn->p[2]==zvlnr && apn->obi[2]==obi) {apn->mask[2]|= mask; break; }
- if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
- if (apn->p[3]==zvlnr && apn->obi[3]==obi) {apn->mask[3]|= mask; break; }
- if (apn->next == NULL) apn->next = addpsA(zspan);
- apn= apn->next;
- }
- }
- }
- }
-
- v1[1]+= dy;
- if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
- else vergz+= dz;
- }
- }
- else {
-
- /* all lines from top to bottom */
- if (vec1[1]<vec2[1]) {
- copy_v3_v3(v1, vec1);
- copy_v3_v3(v2, vec2);
- }
- else {
- copy_v3_v3(v2, vec1);
- copy_v3_v3(v1, vec2);
- dx= -dx; dy= -dy;
- }
-
- start= floor(v1[1]);
- end= start+floor(dy);
-
- if (start>=zspan->recty || end<0) return;
-
- if (end>=zspan->recty) end= zspan->recty-1;
-
- oldx= floor(v1[0]);
- dx/= dy;
-
- vergz= v1[2];
- vergz-= zspan->polygon_offset;
- dz= (v2[2]-v1[2])/dy;
- if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */
-
- rectz= (int *)( zspan->arectz+ (start)*zspan->rectx+ oldx );
- rectmask= (int *)( zspan->rectmask+ (start)*zspan->rectx+ oldx );
- ap= (zspan->apixbuf+ zspan->rectx*(start) +oldx);
-
- if (dx<0) ofs= -1;
- else ofs= 1;
-
- for (y= start; y<=end; y++, rectz+=zspan->rectx, rectmask+=zspan->rectx, ap+=zspan->rectx) {
-
- x= floor(v1[0]);
- if (x!=oldx) {
- oldx= x;
- rectz+= ofs;
- rectmask+= ofs;
- ap+= ofs;
- }
-
- if (x>=0 && y>=0 && x<zspan->rectx) {
- if (vergz<*rectz) {
- if (!zspan->rectmask || vergz>*rectmask) {
-
- apn= ap;
- while (apn) { /* loop unrolled */
- if (apn->p[0]==0) {apn->obi[0]= obi; apn->p[0]= zvlnr; apn->z[0]= vergz; apn->mask[0]= mask; break; }
- if (apn->p[0]==zvlnr) {apn->mask[0]|= mask; break; }
- if (apn->p[1]==0) {apn->obi[1]= obi; apn->p[1]= zvlnr; apn->z[1]= vergz; apn->mask[1]= mask; break; }
- if (apn->p[1]==zvlnr) {apn->mask[1]|= mask; break; }
- if (apn->p[2]==0) {apn->obi[2]= obi; apn->p[2]= zvlnr; apn->z[2]= vergz; apn->mask[2]= mask; break; }
- if (apn->p[2]==zvlnr) {apn->mask[2]|= mask; break; }
- if (apn->p[3]==0) {apn->obi[3]= obi; apn->p[3]= zvlnr; apn->z[3]= vergz; apn->mask[3]= mask; break; }
- if (apn->p[3]==zvlnr) {apn->mask[3]|= mask; break; }
- if (apn->next == NULL) apn->next = addpsA(zspan);
- apn= apn->next;
- }
- }
- }
- }
-
- v1[0]+= dx;
- if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
- else vergz+= dz;
- }
- }
-}
-
-/* ************* NORMAL ZBUFFER ************ */
-
-static void zbufline(ZSpan *zspan, int obi, int zvlnr, const float vec1[3], const float vec2[3])
-{
- int *rectz, *rectp, *recto, *rectmask;
- int start, end, x, y, oldx, oldy, ofs;
- int dz, vergz, maxtest= 0;
- float dx, dy;
- float v1[3], v2[3];
-
- dx= vec2[0]-vec1[0];
- dy= vec2[1]-vec1[1];
-
- if (fabsf(dx) > fabsf(dy)) {
-
- /* all lines from left to right */
- if (vec1[0]<vec2[0]) {
- copy_v3_v3(v1, vec1);
- copy_v3_v3(v2, vec2);
- }
- else {
- copy_v3_v3(v2, vec1);
- copy_v3_v3(v1, vec2);
- dx= -dx; dy= -dy;
- }
-
- start= floor(v1[0]);
- end= start+floor(dx);
- if (end>=zspan->rectx) end= zspan->rectx-1;
-
- oldy= floor(v1[1]);
- dy/= dx;
-
- vergz= floor(v1[2]);
- dz= floor((v2[2]-v1[2])/dx);
- if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */
-
- rectz= zspan->rectz + oldy*zspan->rectx+ start;
- rectp= zspan->rectp + oldy*zspan->rectx+ start;
- recto= zspan->recto + oldy*zspan->rectx+ start;
- rectmask= zspan->rectmask + oldy*zspan->rectx+ start;
-
- if (dy<0) ofs= -zspan->rectx;
- else ofs= zspan->rectx;
-
- for (x= start; x<=end; x++, rectz++, rectp++, recto++, rectmask++) {
-
- y= floor(v1[1]);
- if (y!=oldy) {
- oldy= y;
- rectz+= ofs;
- rectp+= ofs;
- recto+= ofs;
- rectmask+= ofs;
- }
-
- if (x>=0 && y>=0 && y<zspan->recty) {
- if (vergz<*rectz) {
- if (!zspan->rectmask || vergz>*rectmask) {
- *recto= obi;
- *rectz= vergz;
- *rectp= zvlnr;
- }
- }
- }
-
- v1[1]+= dy;
-
- if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
- else vergz+= dz;
- }
- }
- else {
- /* all lines from top to bottom */
- if (vec1[1]<vec2[1]) {
- copy_v3_v3(v1, vec1);
- copy_v3_v3(v2, vec2);
- }
- else {
- copy_v3_v3(v2, vec1);
- copy_v3_v3(v1, vec2);
- dx= -dx; dy= -dy;
- }
-
- start= floor(v1[1]);
- end= start+floor(dy);
-
- if (end>=zspan->recty) end= zspan->recty-1;
-
- oldx= floor(v1[0]);
- dx/= dy;
-
- vergz= floor(v1[2]);
- dz= floor((v2[2]-v1[2])/dy);
- if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */
-
- rectz= zspan->rectz + start*zspan->rectx+ oldx;
- rectp= zspan->rectp + start*zspan->rectx+ oldx;
- recto= zspan->recto + start*zspan->rectx+ oldx;
- rectmask= zspan->rectmask + start*zspan->rectx+ oldx;
-
- if (dx<0) ofs= -1;
- else ofs= 1;
-
- for (y= start; y<=end; y++, rectz+=zspan->rectx, rectp+=zspan->rectx, recto+=zspan->rectx, rectmask+=zspan->rectx) {
-
- x= floor(v1[0]);
- if (x!=oldx) {
- oldx= x;
- rectz+= ofs;
- rectp+= ofs;
- recto+= ofs;
- rectmask+= ofs;
- }
-
- if (x>=0 && y>=0 && x<zspan->rectx) {
- if (vergz<*rectz) {
- if (!zspan->rectmask || vergz>*rectmask) {
- *rectz= vergz;
- *rectp= zvlnr;
- *recto= obi;
- }
- }
- }
-
- v1[0]+= dx;
- if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
- else vergz+= dz;
- }
- }
-}
-
-static void zbufline_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr), const float vec1[3], const float vec2[3])
-{
- int *rectz, *rectz1= NULL;
- int start, end, x, y, oldx, oldy, ofs;
- int dz, vergz, maxtest= 0;
- float dx, dy;
- float v1[3], v2[3];
-
- dx= vec2[0]-vec1[0];
- dy= vec2[1]-vec1[1];
-
- if (fabsf(dx) > fabsf(dy)) {
-
- /* all lines from left to right */
- if (vec1[0]<vec2[0]) {
- copy_v3_v3(v1, vec1);
- copy_v3_v3(v2, vec2);
- }
- else {
- copy_v3_v3(v2, vec1);
- copy_v3_v3(v1, vec2);
- dx= -dx; dy= -dy;
- }
-
- start= floor(v1[0]);
- end= start+floor(dx);
- if (end>=zspan->rectx) end= zspan->rectx-1;
-
- oldy= floor(v1[1]);
- dy/= dx;
-
- vergz= floor(v1[2]);
- dz= floor((v2[2]-v1[2])/dx);
- if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */
-
- rectz= zspan->rectz + oldy*zspan->rectx+ start;
- if (zspan->rectz1)
- rectz1= zspan->rectz1 + oldy*zspan->rectx+ start;
-
- if (dy<0) ofs= -zspan->rectx;
- else ofs= zspan->rectx;
-
- for (x= start; x<=end; x++, rectz++) {
-
- y= floor(v1[1]);
- if (y!=oldy) {
- oldy= y;
- rectz+= ofs;
- if (rectz1) rectz1+= ofs;
- }
-
- if (x>=0 && y>=0 && y<zspan->recty) {
- if (vergz < *rectz) {
- if (rectz1) *rectz1= *rectz;
- *rectz= vergz;
- }
- else if (rectz1 && vergz < *rectz1)
- *rectz1= vergz;
- }
-
- v1[1]+= dy;
-
- if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
- else vergz+= dz;
-
- if (rectz1) rectz1++;
- }
- }
- else {
- /* all lines from top to bottom */
- if (vec1[1]<vec2[1]) {
- copy_v3_v3(v1, vec1);
- copy_v3_v3(v2, vec2);
- }
- else {
- copy_v3_v3(v2, vec1);
- copy_v3_v3(v1, vec2);
- dx= -dx; dy= -dy;
- }
-
- start= floor(v1[1]);
- end= start+floor(dy);
-
- if (end>=zspan->recty) end= zspan->recty-1;
-
- oldx= floor(v1[0]);
- dx/= dy;
-
- vergz= floor(v1[2]);
- dz= floor((v2[2]-v1[2])/dy);
- if (vergz>0x50000000 && dz>0) maxtest= 1; /* prevent overflow */
-
- rectz= zspan->rectz + start*zspan->rectx+ oldx;
- if (zspan->rectz1)
- rectz1= zspan->rectz1 + start*zspan->rectx+ oldx;
-
- if (dx<0) ofs= -1;
- else ofs= 1;
-
- for (y= start; y<=end; y++, rectz+=zspan->rectx) {
-
- x= floor(v1[0]);
- if (x!=oldx) {
- oldx= x;
- rectz+= ofs;
- if (rectz1) rectz1+= ofs;
- }
-
- if (x>=0 && y>=0 && x<zspan->rectx) {
- if (vergz < *rectz) {
- if (rectz1) *rectz1= *rectz;
- *rectz= vergz;
- }
- else if (rectz1 && vergz < *rectz1)
- *rectz1= vergz;
- }
-
- v1[0]+= dx;
- if (maxtest && (vergz > 0x7FFFFFF0 - dz)) vergz= 0x7FFFFFF0;
- else vergz+= dz;
-
- if (rectz1)
- rectz1+=zspan->rectx;
- }
- }
-}
-
-
-static int clipline(float v1[4], float v2[4]) /* return 0: do not draw */
-{
- float dz, dw, u1=0.0, u2=1.0;
- float dx, dy, v13;
-
- dz= v2[2]-v1[2];
- dw= v2[3]-v1[3];
-
- /* this 1.01 is for clipping x and y just a tinsy larger. that way it is
- * filled in with zbufwire correctly when rendering in parts. otherwise
- * you see line endings at edges... */
-
- if (cliptestf(-dz, -dw, v1[3], v1[2], &u1, &u2)) {
- if (cliptestf(dz, -dw, v1[3], -v1[2], &u1, &u2)) {
-
- dx= v2[0]-v1[0];
- dz= 1.01f*(v2[3]-v1[3]);
- v13= 1.01f*v1[3];
-
- if (cliptestf(-dx, -dz, v1[0], v13, &u1, &u2)) {
- if (cliptestf(dx, -dz, v13, -v1[0], &u1, &u2)) {
-
- dy= v2[1]-v1[1];
-
- if (cliptestf(-dy, -dz, v1[1], v13, &u1, &u2)) {
- if (cliptestf(dy, -dz, v13, -v1[1], &u1, &u2)) {
-
- if (u2<1.0f) {
- v2[0]= v1[0]+u2*dx;
- v2[1]= v1[1]+u2*dy;
- v2[2]= v1[2]+u2*dz;
- v2[3]= v1[3]+u2*dw;
- }
- if (u1>0.0f) {
- v1[0]= v1[0]+u1*dx;
- v1[1]= v1[1]+u1*dy;
- v1[2]= v1[2]+u1*dz;
- v1[3]= v1[3]+u1*dw;
- }
- return 1;
- }
- }
- }
- }
- }
- }
-
- return 0;
-}
-
-void hoco_to_zco(ZSpan *zspan, float zco[3], const float hoco[4])
-{
- float div;
-
- div= 1.0f/hoco[3];
- zco[0]= zspan->zmulx*(1.0f+hoco[0]*div) + zspan->zofsx;
- zco[1]= zspan->zmuly*(1.0f+hoco[1]*div) + zspan->zofsy;
- zco[2]= 0x7FFFFFFF *(hoco[2]*div);
-}
-
-void zbufclipwire(ZSpan *zspan, int obi, int zvlnr, int ec,
- const float ho1[4], const float ho2[4], const float ho3[4], const float ho4[4],
- const int c1, const int c2, const int c3, const int c4)
-{
- float vez[20];
- int and, or;
-
- /* edgecode: 1= draw */
- if (ec==0) return;
-
- if (ho4) {
- and= (c1 & c2 & c3 & c4);
- or= (c1 | c2 | c3 | c4);
- }
- else {
- and= (c1 & c2 & c3);
- or= (c1 | c2 | c3);
- }
-
- if (or) { /* not in the middle */
- if (and) { /* out completely */
- return;
- }
- else { /* clipping */
-
- if (ec & ME_V1V2) {
- copy_v4_v4(vez, ho1);
- copy_v4_v4(vez+4, ho2);
- if ( clipline(vez, vez+4)) {
- hoco_to_zco(zspan, vez, vez);
- hoco_to_zco(zspan, vez+4, vez+4);
- zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
- }
- }
- if (ec & ME_V2V3) {
- copy_v4_v4(vez, ho2);
- copy_v4_v4(vez+4, ho3);
- if ( clipline(vez, vez+4)) {
- hoco_to_zco(zspan, vez, vez);
- hoco_to_zco(zspan, vez+4, vez+4);
- zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
- }
- }
- if (ho4) {
- if (ec & ME_V3V4) {
- copy_v4_v4(vez, ho3);
- copy_v4_v4(vez+4, ho4);
- if ( clipline(vez, vez+4)) {
- hoco_to_zco(zspan, vez, vez);
- hoco_to_zco(zspan, vez+4, vez+4);
- zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
- }
- }
- if (ec & ME_V4V1) {
- copy_v4_v4(vez, ho4);
- copy_v4_v4(vez+4, ho1);
- if ( clipline(vez, vez+4)) {
- hoco_to_zco(zspan, vez, vez);
- hoco_to_zco(zspan, vez+4, vez+4);
- zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
- }
- }
- }
- else {
- if (ec & ME_V3V1) {
- copy_v4_v4(vez, ho3);
- copy_v4_v4(vez+4, ho1);
- if ( clipline(vez, vez+4)) {
- hoco_to_zco(zspan, vez, vez);
- hoco_to_zco(zspan, vez+4, vez+4);
- zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
- }
- }
- }
-
- return;
- }
- }
-
- hoco_to_zco(zspan, vez, ho1);
- hoco_to_zco(zspan, vez+4, ho2);
- hoco_to_zco(zspan, vez+8, ho3);
- if (ho4) {
- hoco_to_zco(zspan, vez+12, ho4);
-
- if (ec & ME_V3V4) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez+12);
- if (ec & ME_V4V1) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+12, vez);
- }
- else {
- if (ec & ME_V3V1) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+8, vez);
- }
-
- if (ec & ME_V1V2) zspan->zbuflinefunc(zspan, obi, zvlnr, vez, vez+4);
- if (ec & ME_V2V3) zspan->zbuflinefunc(zspan, obi, zvlnr, vez+4, vez+8);
-
-}
-
-void zbufsinglewire(ZSpan *zspan, int obi, int zvlnr, const float ho1[4], const float ho2[4])
-{
- float f1[4], f2[4];
- int c1, c2;
-
- c1= testclip(ho1);
- c2= testclip(ho2);
-
- if (c1 | c2) { /* not in the middle */
- if (!(c1 & c2)) { /* not out completely */
- copy_v4_v4(f1, ho1);
- copy_v4_v4(f2, ho2);
-
- if (clipline(f1, f2)) {
- hoco_to_zco(zspan, f1, f1);
- hoco_to_zco(zspan, f2, f2);
- zspan->zbuflinefunc(zspan, obi, zvlnr, f1, f2);
- }
- }
- }
- else {
- hoco_to_zco(zspan, f1, ho1);
- hoco_to_zco(zspan, f2, ho2);
-
- zspan->zbuflinefunc(zspan, obi, zvlnr, f1, f2);
- }
-}
-
-/**
- * Fill the z buffer, but invert z order, and add the face index to
- * the corresponding face buffer.
- *
- * This is one of the z buffer fill functions called in zbufclip() and
- * zbufwireclip().
- *
- * \param v1 [4 floats, world coordinates] first vertex
- * \param v2 [4 floats, world coordinates] second vertex
- * \param v3 [4 floats, world coordinates] third vertex
- */
-
-/* WATCH IT: zbuffillGLinv4 and zbuffillGL4 are identical except for a 2 lines,
- * commented below */
-static void zbuffillGLinv4(ZSpan *zspan, int obi, int zvlnr,
- const float *v1, const float *v2, const float *v3, const float *v4)
-{
- double zxd, zyd, zy0, zverg;
- float x0, y0, z0;
- float x1, y1, z1, x2, y2, z2, xx1;
- const float *span1, *span2;
- int *rectoofs, *ro;
- int *rectpofs, *rp;
- const int *rectmaskofs, *rm;
- int *rz, x, y;
- int sn1, sn2, rectx, *rectzofs, my0, my2;
-
- /* init */
- zbuf_init_span(zspan);
-
- /* set spans */
- zbuf_add_to_span(zspan, v1, v2);
- zbuf_add_to_span(zspan, v2, v3);
- if (v4) {
- zbuf_add_to_span(zspan, v3, v4);
- zbuf_add_to_span(zspan, v4, v1);
- }
- else
- zbuf_add_to_span(zspan, v3, v1);
-
- /* clipped */
- if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
-
- my0 = max_ii(zspan->miny1, zspan->miny2);
- my2 = min_ii(zspan->maxy1, zspan->maxy2);
-
- // printf("my %d %d\n", my0, my2);
- if (my2<my0) return;
-
-
- /* ZBUF DX DY, in floats still */
- x1= v1[0]- v2[0];
- x2= v2[0]- v3[0];
- y1= v1[1]- v2[1];
- y2= v2[1]- v3[1];
- z1= v1[2]- v2[2];
- z2= v2[2]- v3[2];
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
- z0= x1*y2-y1*x2;
-
- if (z0==0.0f) return;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
-
- zxd= -(double)x0/(double)z0;
- zyd= -(double)y0/(double)z0;
- zy0= ((double)my2)*zyd + (double)xx1;
-
- /* start-offset in rect */
- rectx= zspan->rectx;
- rectzofs= (zspan->rectz+rectx*my2);
- rectpofs= (zspan->rectp+rectx*my2);
- rectoofs= (zspan->recto+rectx*my2);
- rectmaskofs= (zspan->rectmask+rectx*my2);
-
- /* correct span */
- sn1= (my0 + my2)/2;
- if (zspan->span1[sn1] < zspan->span2[sn1]) {
- span1= zspan->span1+my2;
- span2= zspan->span2+my2;
- }
- else {
- span1= zspan->span2+my2;
- span2= zspan->span1+my2;
- }
-
- for (y=my2; y>=my0; y--, span1--, span2--) {
-
- sn1= floor(*span1);
- sn2= floor(*span2);
- sn1++;
-
- if (sn2>=rectx) sn2= rectx-1;
- if (sn1<0) sn1= 0;
-
- if (sn2>=sn1) {
- int intzverg;
-
- zverg= (double)sn1*zxd + zy0;
- rz= rectzofs+sn1;
- rp= rectpofs+sn1;
- ro= rectoofs+sn1;
- rm= rectmaskofs+sn1;
- x= sn2-sn1;
-
- while (x>=0) {
- intzverg = round_db_to_int_clamp(zverg);
-
- if ( intzverg > *rz || *rz==0x7FFFFFFF) { /* UNIQUE LINE: see comment above */
- if (!zspan->rectmask || intzverg > *rm) {
- *ro= obi; /* UNIQUE LINE: see comment above (order differs) */
- *rz= intzverg;
- *rp= zvlnr;
- }
- }
- zverg+= zxd;
- rz++;
- rp++;
- ro++;
- rm++;
- x--;
- }
- }
-
- zy0-=zyd;
- rectzofs-= rectx;
- rectpofs-= rectx;
- rectoofs-= rectx;
- rectmaskofs-= rectx;
- }
-}
-
-/* uses spanbuffers */
-
-/* WATCH IT: zbuffillGLinv4 and zbuffillGL4 are identical except for a 2 lines,
- * commented below */
-static void zbuffillGL4(ZSpan *zspan, int obi, int zvlnr,
- const float *v1, const float *v2, const float *v3, const float *v4)
-{
- double zxd, zyd, zy0, zverg;
- float x0, y0, z0;
- float x1, y1, z1, x2, y2, z2, xx1;
- const float *span1, *span2;
- int *rectoofs, *ro;
- int *rectpofs, *rp;
- const int *rectmaskofs, *rm;
- int *rz, x, y;
- int sn1, sn2, rectx, *rectzofs, my0, my2;
-
- /* init */
- zbuf_init_span(zspan);
-
- /* set spans */
- zbuf_add_to_span(zspan, v1, v2);
- zbuf_add_to_span(zspan, v2, v3);
- if (v4) {
- zbuf_add_to_span(zspan, v3, v4);
- zbuf_add_to_span(zspan, v4, v1);
- }
- else
- zbuf_add_to_span(zspan, v3, v1);
-
- /* clipped */
- if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
-
- my0 = max_ii(zspan->miny1, zspan->miny2);
- my2 = min_ii(zspan->maxy1, zspan->maxy2);
-
- // printf("my %d %d\n", my0, my2);
- if (my2<my0) return;
-
-
- /* ZBUF DX DY, in floats still */
- x1= v1[0]- v2[0];
- x2= v2[0]- v3[0];
- y1= v1[1]- v2[1];
- y2= v2[1]- v3[1];
- z1= v1[2]- v2[2];
- z2= v2[2]- v3[2];
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
- z0= x1*y2-y1*x2;
-
- if (z0==0.0f) return;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
-
- zxd= -(double)x0/(double)z0;
- zyd= -(double)y0/(double)z0;
- zy0= ((double)my2)*zyd + (double)xx1;
-
- /* start-offset in rect */
- rectx= zspan->rectx;
- rectzofs= (zspan->rectz+rectx*my2);
- rectpofs= (zspan->rectp+rectx*my2);
- rectoofs= (zspan->recto+rectx*my2);
- rectmaskofs= (zspan->rectmask+rectx*my2);
-
- /* correct span */
- sn1= (my0 + my2)/2;
- if (zspan->span1[sn1] < zspan->span2[sn1]) {
- span1= zspan->span1+my2;
- span2= zspan->span2+my2;
- }
- else {
- span1= zspan->span2+my2;
- span2= zspan->span1+my2;
- }
-
- for (y=my2; y>=my0; y--, span1--, span2--) {
-
- sn1= floor(*span1);
- sn2= floor(*span2);
- sn1++;
-
- if (sn2>=rectx) sn2= rectx-1;
- if (sn1<0) sn1= 0;
-
- if (sn2>=sn1) {
- int intzverg;
-
- zverg= (double)sn1*zxd + zy0;
- rz= rectzofs+sn1;
- rp= rectpofs+sn1;
- ro= rectoofs+sn1;
- rm= rectmaskofs+sn1;
- x= sn2-sn1;
-
- while (x>=0) {
- intzverg = round_db_to_int_clamp(zverg);
-
- if (intzverg < *rz) { /* ONLY UNIQUE LINE: see comment above */
- if (!zspan->rectmask || intzverg > *rm) {
- *rz= intzverg;
- *rp= zvlnr;
- *ro= obi; /* UNIQUE LINE: see comment above (order differs) */
- }
- }
- zverg+= zxd;
- rz++;
- rp++;
- ro++;
- rm++;
- x--;
- }
- }
-
- zy0-=zyd;
- rectzofs-= rectx;
- rectpofs-= rectx;
- rectoofs-= rectx;
- rectmaskofs-= rectx;
- }
-}
-
-/**
- * Fill the z buffer. The face buffer is not operated on!
- *
- * This is one of the z buffer fill functions called in zbufclip() and
- * zbufwireclip().
- *
- * \param v1 [4 floats, world coordinates] first vertex
- * \param v2 [4 floats, world coordinates] second vertex
- * \param v3 [4 floats, world coordinates] third vertex
- */
-
-/* now: filling two Z values, the closest and 2nd closest */
-static void zbuffillGL_onlyZ(ZSpan *zspan, int UNUSED(obi), int UNUSED(zvlnr),
- const float *v1, const float *v2, const float *v3, const float *v4)
-{
- double zxd, zyd, zy0, zverg;
- float x0, y0, z0;
- float x1, y1, z1, x2, y2, z2, xx1;
- const float *span1, *span2;
- int *rz, *rz1, x, y;
- int sn1, sn2, rectx, *rectzofs, *rectzofs1= NULL, my0, my2;
-
- /* init */
- zbuf_init_span(zspan);
-
- /* set spans */
- zbuf_add_to_span(zspan, v1, v2);
- zbuf_add_to_span(zspan, v2, v3);
- if (v4) {
- zbuf_add_to_span(zspan, v3, v4);
- zbuf_add_to_span(zspan, v4, v1);
- }
- else
- zbuf_add_to_span(zspan, v3, v1);
-
- /* clipped */
- if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
-
- my0 = max_ii(zspan->miny1, zspan->miny2);
- my2 = min_ii(zspan->maxy1, zspan->maxy2);
-
- // printf("my %d %d\n", my0, my2);
- if (my2<my0) return;
-
-
- /* ZBUF DX DY, in floats still */
- x1= v1[0]- v2[0];
- x2= v2[0]- v3[0];
- y1= v1[1]- v2[1];
- y2= v2[1]- v3[1];
- z1= v1[2]- v2[2];
- z2= v2[2]- v3[2];
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
- z0= x1*y2-y1*x2;
-
- if (z0==0.0f) return;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
-
- zxd= -(double)x0/(double)z0;
- zyd= -(double)y0/(double)z0;
- zy0= ((double)my2)*zyd + (double)xx1;
-
- /* start-offset in rect */
- rectx= zspan->rectx;
- rectzofs= (zspan->rectz+rectx*my2);
- if (zspan->rectz1)
- rectzofs1= (zspan->rectz1+rectx*my2);
-
- /* correct span */
- sn1= (my0 + my2)/2;
- if (zspan->span1[sn1] < zspan->span2[sn1]) {
- span1= zspan->span1+my2;
- span2= zspan->span2+my2;
- }
- else {
- span1= zspan->span2+my2;
- span2= zspan->span1+my2;
- }
-
- for (y=my2; y>=my0; y--, span1--, span2--) {
-
- sn1= floor(*span1);
- sn2= floor(*span2);
- sn1++;
-
- if (sn2>=rectx) sn2= rectx-1;
- if (sn1<0) sn1= 0;
-
- if (sn2>=sn1) {
- zverg= (double)sn1*zxd + zy0;
- rz= rectzofs+sn1;
- rz1= rectzofs1+sn1;
- x= sn2-sn1;
-
- while (x>=0) {
- int zvergi = round_db_to_int_clamp(zverg);
-
- /* option: maintain two depth values, closest and 2nd closest */
- if (zvergi < *rz) {
- if (rectzofs1) *rz1= *rz;
- *rz= zvergi;
- }
- else if (rectzofs1 && zvergi < *rz1)
- *rz1= zvergi;
-
- zverg+= zxd;
-
- rz++;
- rz1++;
- x--;
- }
- }
-
- zy0-=zyd;
- rectzofs-= rectx;
- if (rectzofs1) rectzofs1-= rectx;
- }
-}
-
-/* 2d scanconvert for tria, calls func for each x, y coordinate and gives UV barycentrics */
-void zspan_scanconvert_strand(ZSpan *zspan, void *handle, float *v1, float *v2, float *v3, void (*func)(void *, int, int, float, float, float) )
-{
- float x0, y0, x1, y1, x2, y2, z0, z1, z2, z;
- float u, v, uxd, uyd, vxd, vyd, uy0, vy0, zxd, zyd, zy0, xx1;
- const float *span1, *span2;
- int x, y, sn1, sn2, rectx= zspan->rectx, my0, my2;
-
- /* init */
- zbuf_init_span(zspan);
-
- /* set spans */
- zbuf_add_to_span(zspan, v1, v2);
- zbuf_add_to_span(zspan, v2, v3);
- zbuf_add_to_span(zspan, v3, v1);
-
- /* clipped */
- if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
-
- my0 = max_ii(zspan->miny1, zspan->miny2);
- my2 = min_ii(zspan->maxy1, zspan->maxy2);
-
- // printf("my %d %d\n", my0, my2);
- if (my2<my0) return;
-
- /* ZBUF DX DY, in floats still */
- x1= v1[0]- v2[0];
- x2= v2[0]- v3[0];
- y1= v1[1]- v2[1];
- y2= v2[1]- v3[1];
- z1= v1[2]- v2[2];
- z2= v2[2]- v3[2];
-
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
- z0= x1*y2-y1*x2;
-
- if (z0==0.0f) return;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
- zxd= -(double)x0/(double)z0;
- zyd= -(double)y0/(double)z0;
- zy0= ((double)my2)*zyd + (double)xx1;
-
- z1= 1.0f; /* (u1 - u2) */
- z2= 0.0f; /* (u2 - u3) */
-
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0 + 1.0f;
- uxd= -(double)x0/(double)z0;
- uyd= -(double)y0/(double)z0;
- uy0= ((double)my2)*uyd + (double)xx1;
-
- z1= -1.0f; /* (v1 - v2) */
- z2= 1.0f; /* (v2 - v3) */
-
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0;
- vxd= -(double)x0/(double)z0;
- vyd= -(double)y0/(double)z0;
- vy0= ((double)my2)*vyd + (double)xx1;
-
- /* correct span */
- sn1= (my0 + my2)/2;
- if (zspan->span1[sn1] < zspan->span2[sn1]) {
- span1= zspan->span1+my2;
- span2= zspan->span2+my2;
- }
- else {
- span1= zspan->span2+my2;
- span2= zspan->span1+my2;
- }
-
- for (y=my2; y>=my0; y--, span1--, span2--) {
-
- sn1= floor(*span1);
- sn2= floor(*span2);
- sn1++;
-
- if (sn2>=rectx) sn2= rectx-1;
- if (sn1<0) sn1= 0;
-
- u= (double)sn1*uxd + uy0;
- v= (double)sn1*vxd + vy0;
- z= (double)sn1*zxd + zy0;
-
- for (x= sn1; x<=sn2; x++, u+=uxd, v+=vxd, z+=zxd)
- func(handle, x, y, u, v, z);
-
- uy0 -= uyd;
- vy0 -= vyd;
- zy0 -= zyd;
- }
-}
-
/* scanconvert for strand triangles, calls func for each x, y coordinate and gives UV barycentrics and z */
void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float *v3, void (*func)(void *, int, int, float, float) )
@@ -1585,2154 +241,4 @@ void zspan_scanconvert(ZSpan *zspan, void *handle, float *v1, float *v2, float *
}
}
-
-
-/**
- * (clip pyramid)
- * Sets lambda: flag, and parametrize the clipping of vertices in
- * viewspace coordinates. lambda = -1 means no clipping, lambda in [0, 1] means a clipping.
- * Note: uses globals.
- * \param v1 start coordinate s
- * \param v2 target coordinate t
- * \param b2
- * \param b3
- * \param a index for coordinate (x, y, or z)
- */
-
-static void clippyra(float *lambda, float *v1, float *v2, int *b2, int *b3, int a, float clipcrop)
-{
- float da, dw, u1=0.0, u2=1.0;
- float v13;
-
- lambda[0]= -1.0;
- lambda[1]= -1.0;
-
- da= v2[a]-v1[a];
- /* prob; we clip slightly larger, osa renders add 2 pixels on edges, should become variable? */
- /* or better; increase r.winx/y size, but thats quite a complex one. do it later */
- if (a==2) {
- dw= (v2[3]-v1[3]);
- v13= v1[3];
- }
- else {
- dw= clipcrop*(v2[3]-v1[3]);
- v13= clipcrop*v1[3];
- }
- /* according the original article by Liang&Barsky, for clipping of
- * homogeneous coordinates with viewplane, the value of "0" is used instead of "-w" .
- * This differs from the other clipping cases (like left or top) and I considered
- * it to be not so 'homogenic'. But later it has proven to be an error,
- * who would have thought that of L&B!
- */
-
- if (cliptestf(-da, -dw, v13, v1[a], &u1, &u2)) {
- if (cliptestf(da, -dw, v13, -v1[a], &u1, &u2)) {
- *b3=1;
- if (u2<1.0f) {
- lambda[1]= u2;
- *b2=1;
- }
- else lambda[1]=1.0; /* u2 */
- if (u1>0.0f) {
- lambda[0] = u1;
- *b2 = 1;
- }
- else {
- lambda[0] = 0.0;
- }
- }
- }
-}
-
-/**
- * (make vertex pyramide clip)
- * Checks lambda and uses this to make decision about clipping the line
- * segment from v1 to v2. lambda is the factor by which the vector is
- * cut. ( calculate s + l * ( t - s )). The result is appended to the
- * vertex list of this face.
- *
- *
- * \param v1 start coordinate s
- * \param v2 target coordinate t
- * \param b1
- * \param b2
- * \param clve vertex vector.
- */
-
-static void makevertpyra(float *vez, float *lambda, float **trias, float *v1, float *v2, int *b1, int *clve)
-{
- float l1, l2, *adr;
-
- l1= lambda[0];
- l2= lambda[1];
-
- if (l1!= -1.0f) {
- if (l1!= 0.0f) {
- adr= vez+4*(*clve);
- trias[*b1]=adr;
- (*clve)++;
- adr[0]= v1[0]+l1*(v2[0]-v1[0]);
- adr[1]= v1[1]+l1*(v2[1]-v1[1]);
- adr[2]= v1[2]+l1*(v2[2]-v1[2]);
- adr[3]= v1[3]+l1*(v2[3]-v1[3]);
- }
- else trias[*b1]= v1;
-
- (*b1)++;
- }
- if (l2!= -1.0f) {
- if (l2!= 1.0f) {
- adr= vez+4*(*clve);
- trias[*b1]=adr;
- (*clve)++;
- adr[0]= v1[0]+l2*(v2[0]-v1[0]);
- adr[1]= v1[1]+l2*(v2[1]-v1[1]);
- adr[2]= v1[2]+l2*(v2[2]-v1[2]);
- adr[3]= v1[3]+l2*(v2[3]-v1[3]);
- (*b1)++;
- }
- }
-}
-
-/* ------------------------------------------------------------------------- */
-
-void projectverto(const float v1[3], float winmat[4][4], float adr[4])
-{
- /* calcs homogenic coord of vertex v1 */
- float x, y, z;
-
- x = v1[0];
- y = v1[1];
- z = v1[2];
- adr[0] = x * winmat[0][0] + z * winmat[2][0] + winmat[3][0];
- adr[1] = y * winmat[1][1] + z * winmat[2][1] + winmat[3][1];
- adr[2] = z * winmat[2][2] + winmat[3][2];
- adr[3] = z * winmat[2][3] + winmat[3][3];
-
- //printf("hoco %f %f %f %f\n", adr[0], adr[1], adr[2], adr[3]);
-}
-
-/* ------------------------------------------------------------------------- */
-
-void projectvert(const float v1[3], float winmat[4][4], float adr[4])
-{
- /* calcs homogenic coord of vertex v1 */
- float x, y, z;
-
- x = v1[0];
- y = v1[1];
- z = v1[2];
- adr[0] = x * winmat[0][0] + y * winmat[1][0] + z * winmat[2][0] + winmat[3][0];
- adr[1] = x * winmat[0][1] + y * winmat[1][1] + z * winmat[2][1] + winmat[3][1];
- adr[2] = x * winmat[0][2] + y * winmat[1][2] + z * winmat[2][2] + winmat[3][2];
- adr[3] = x * winmat[0][3] + y * winmat[1][3] + z * winmat[2][3] + winmat[3][3];
-}
-
-/* ------------------------------------------------------------------------- */
-
-#define ZBUF_PROJECT_CACHE_SIZE 256
-
-typedef struct ZbufProjectCache {
- int index, clip;
- float ho[4];
-} ZbufProjectCache;
-
-static void zbuf_project_cache_clear(ZbufProjectCache *cache, int size)
-{
- int i;
-
- if (size > ZBUF_PROJECT_CACHE_SIZE)
- size= ZBUF_PROJECT_CACHE_SIZE;
-
- memset(cache, 0, sizeof(ZbufProjectCache)*size);
- for (i=0; i<size; i++)
- cache[i].index= -1;
-}
-
-static int zbuf_shadow_project(ZbufProjectCache *cache, int index, float winmat[4][4], float *co, float *ho)
-{
- int cindex= index & 255;
-
- if (cache[cindex].index == index) {
- copy_v4_v4(ho, cache[cindex].ho);
- return cache[cindex].clip;
- }
- else {
- int clipflag;
- projectvert(co, winmat, ho);
- clipflag= testclip(ho);
-
- copy_v4_v4(cache[cindex].ho, ho);
- cache[cindex].clip= clipflag;
- cache[cindex].index= index;
-
- return clipflag;
- }
-}
-
-static void zbuffer_part_bounds(int winx, int winy, RenderPart *pa, float *bounds)
-{
- bounds[0]= (2*pa->disprect.xmin - winx-1)/(float)winx;
- bounds[1]= (2*pa->disprect.xmax - winx+1)/(float)winx;
- bounds[2]= (2*pa->disprect.ymin - winy-1)/(float)winy;
- bounds[3]= (2*pa->disprect.ymax - winy+1)/(float)winy;
-}
-
-static int zbuf_part_project(ZbufProjectCache *cache, int index, float winmat[4][4], float *bounds, float *co, float *ho)
-{
- float vec[3];
- int cindex= index & 255;
-
- if (cache[cindex].index == index) {
- copy_v4_v4(ho, cache[cindex].ho);
- return cache[cindex].clip;
- }
- else {
- float wco;
- int clipflag= 0;
- copy_v3_v3(vec, co);
- projectvert(co, winmat, ho);
-
- wco= ho[3];
- if (ho[0] < bounds[0]*wco) clipflag |= 1;
- else if (ho[0] > bounds[1]*wco) clipflag |= 2;
- if (ho[1] > bounds[3]*wco) clipflag |= 4;
- else if (ho[1] < bounds[2]*wco) clipflag |= 8;
-
- copy_v4_v4(cache[cindex].ho, ho);
- cache[cindex].clip= clipflag;
- cache[cindex].index= index;
-
- return clipflag;
- }
-}
-
-void zbuf_render_project(float winmat[4][4], const float co[3], float ho[4])
-{
- float vec[3];
-
- copy_v3_v3(vec, co);
- projectvert(vec, winmat, ho);
-}
-
-void zbuf_make_winmat(Render *re, float winmat[4][4])
-{
- if (re->r.mode & R_PANORAMA) {
- float panomat[4][4];
-
- unit_m4(panomat);
-
- panomat[0][0]= re->panoco;
- panomat[0][2]= re->panosi;
- panomat[2][0]= -re->panosi;
- panomat[2][2]= re->panoco;
-
- mul_m4_m4m4(winmat, re->winmat, panomat);
- }
- else
- copy_m4_m4(winmat, re->winmat);
-}
-
-/* do zbuffering and clip, f1 f2 f3 are hocos, c1 c2 c3 are clipping flags */
-
-void zbufclip(ZSpan *zspan, int obi, int zvlnr,
- const float f1[4], const float f2[4], const float f3[4],
- const int c1, const int c2, const int c3)
-{
- float *vlzp[32][3], lambda[3][2];
- float vez[400], *trias[40];
-
- if (c1 | c2 | c3) { /* not in middle */
- if (c1 & c2 & c3) { /* completely out */
- return;
- }
- else { /* clipping */
- int arg, v, b, clipflag[3], b1, b2, b3, c4, clve=3, clvlo, clvl=1;
- float *fp;
-
- vez[0]= f1[0]; vez[1]= f1[1]; vez[2]= f1[2]; vez[3]= f1[3];
- vez[4]= f2[0]; vez[5]= f2[1]; vez[6]= f2[2]; vez[7]= f2[3];
- vez[8]= f3[0]; vez[9]= f3[1]; vez[10]= f3[2];vez[11]= f3[3];
-
- vlzp[0][0]= vez;
- vlzp[0][1]= vez+4;
- vlzp[0][2]= vez+8;
-
- clipflag[0]= ( (c1 & 48) | (c2 & 48) | (c3 & 48) );
- if (clipflag[0]==0) { /* othwerwise it needs to be calculated again, after the first (z) clip */
- clipflag[1]= ( (c1 & 3) | (c2 & 3) | (c3 & 3) );
- clipflag[2]= ( (c1 & 12) | (c2 & 12) | (c3 & 12) );
- }
- else clipflag[1]=clipflag[2]= 0;
-
- for (b=0;b<3;b++) {
-
- if (clipflag[b]) {
-
- clvlo= clvl;
-
- for (v=0; v<clvlo; v++) {
-
- if (vlzp[v][0]!=NULL) { /* face is still there */
- b2= b3 =0; /* clip flags */
-
- if (b==0) arg= 2;
- else if (b==1) arg= 0;
- else arg= 1;
-
- clippyra(lambda[0], vlzp[v][0], vlzp[v][1], &b2, &b3, arg, zspan->clipcrop);
- clippyra(lambda[1], vlzp[v][1], vlzp[v][2], &b2, &b3, arg, zspan->clipcrop);
- clippyra(lambda[2], vlzp[v][2], vlzp[v][0], &b2, &b3, arg, zspan->clipcrop);
-
- if (b2==0 && b3==1) {
- /* completely 'in', but we copy because of last for () loop in this section */;
- vlzp[clvl][0]= vlzp[v][0];
- vlzp[clvl][1]= vlzp[v][1];
- vlzp[clvl][2]= vlzp[v][2];
- vlzp[v][0]= NULL;
- clvl++;
- }
- else if (b3==0) {
- vlzp[v][0]= NULL;
- /* completely 'out' */;
- }
- else {
- b1=0;
- makevertpyra(vez, lambda[0], trias, vlzp[v][0], vlzp[v][1], &b1, &clve);
- makevertpyra(vez, lambda[1], trias, vlzp[v][1], vlzp[v][2], &b1, &clve);
- makevertpyra(vez, lambda[2], trias, vlzp[v][2], vlzp[v][0], &b1, &clve);
-
- /* after front clip done: now set clip flags */
- if (b==0) {
- clipflag[1]= clipflag[2]= 0;
- f1= vez;
- for (b3=0; b3<clve; b3++) {
- c4= testclip(f1);
- clipflag[1] |= (c4 & 3);
- clipflag[2] |= (c4 & 12);
- f1+= 4;
- }
- }
-
- vlzp[v][0]= NULL;
- if (b1>2) {
- for (b3=3; b3<=b1; b3++) {
- vlzp[clvl][0]= trias[0];
- vlzp[clvl][1]= trias[b3-2];
- vlzp[clvl][2]= trias[b3-1];
- clvl++;
- }
- }
- }
- }
- }
- }
- }
-
- /* warning, clip overflow, this should never happen! */
- BLI_assert(!(clve > 38 || clvl > 31));
-
- /* perspective division */
- fp = vez;
- for (b = 0; b < clve; b++) {
- hoco_to_zco(zspan, fp, fp);
- fp += 4;
- }
- for (b = 1; b < clvl; b++) {
- if (vlzp[b][0]) {
- zspan->zbuffunc(zspan, obi, zvlnr, vlzp[b][0], vlzp[b][1], vlzp[b][2], NULL);
- }
- }
- return;
- }
- }
-
- /* perspective division: HCS to ZCS */
- hoco_to_zco(zspan, vez, f1);
- hoco_to_zco(zspan, vez+4, f2);
- hoco_to_zco(zspan, vez+8, f3);
- zspan->zbuffunc(zspan, obi, zvlnr, vez, vez+4, vez+8, NULL);
-}
-
-void zbufclip4(ZSpan *zspan, int obi, int zvlnr,
- const float f1[4], const float f2[4], const float f3[4], const float f4[4],
- const int c1, const int c2, const int c3, const int c4)
-{
- float vez[16];
-
- if (c1 | c2 | c3 | c4) { /* not in middle */
- if (c1 & c2 & c3 & c4) { /* completely out */
- return;
- }
- else { /* clipping */
- zbufclip(zspan, obi, zvlnr, f1, f2, f3, c1, c2, c3);
- zbufclip(zspan, obi, zvlnr, f1, f3, f4, c1, c3, c4);
- }
- return;
- }
-
- /* perspective division: HCS to ZCS */
- hoco_to_zco(zspan, vez, f1);
- hoco_to_zco(zspan, vez+4, f2);
- hoco_to_zco(zspan, vez+8, f3);
- hoco_to_zco(zspan, vez+12, f4);
-
- zspan->zbuffunc(zspan, obi, zvlnr, vez, vez+4, vez+8, vez+12);
-}
-
-/* ************** ZMASK ******************************** */
-
-#define EXTEND_PIXEL(a) if (temprectp[a]) { z += rectz[a]; tot++; } (void)0
-
-/* changes the zbuffer to be ready for z-masking: applies an extend-filter, and then clears */
-static void zmask_rect(int *rectz, int *rectp, int xs, int ys, int neg)
-{
- int len=0, x, y;
- int *temprectp;
- int row1, row2, row3, *curp, *curz;
-
- temprectp= MEM_dupallocN(rectp);
-
- /* extend: if pixel is not filled in, we check surrounding pixels and average z value */
-
- for (y=1; y<=ys; y++) {
- /* setup row indices */
- row1= (y-2)*xs;
- row2= row1 + xs;
- row3= row2 + xs;
- if (y==1)
- row1= row2;
- else if (y==ys)
- row3= row2;
-
- curp= rectp + (y-1)*xs;
- curz= rectz + (y-1)*xs;
-
- for (x=0; x<xs; x++, curp++, curz++) {
- if (curp[0]==0) {
- int tot= 0;
- float z= 0.0f;
-
- EXTEND_PIXEL(row1);
- EXTEND_PIXEL(row2);
- EXTEND_PIXEL(row3);
- EXTEND_PIXEL(row1 + 1);
- EXTEND_PIXEL(row3 + 1);
- if (x!=xs-1) {
- EXTEND_PIXEL(row1 + 2);
- EXTEND_PIXEL(row2 + 2);
- EXTEND_PIXEL(row3 + 2);
- }
- if (tot) {
- len++;
- curz[0]= (int)(z/(float)tot);
- curp[0]= -1; /* env */
- }
- }
-
- if (x!=0) {
- row1++; row2++; row3++;
- }
- }
- }
-
- MEM_freeN(temprectp);
-
- if (neg) {
- /* z values for negative are already correct */
- }
- else {
- /* clear not filled z values */
- for (len= xs*ys -1; len>=0; len--) {
- if (rectp[len]==0) {
- rectz[len] = -0x7FFFFFFF;
- rectp[len]= -1; /* env code */
- }
- }
- }
-}
-
-
-/* ***************** ZBUFFER MAIN ROUTINES **************** */
-
-void zbuffer_solid(RenderPart *pa, RenderLayer *rl, void(*fillfunc)(RenderPart *, ZSpan *, int, void *), void *data)
-{
- ZbufProjectCache cache[ZBUF_PROJECT_CACHE_SIZE];
- ZSpan zspans[16], *zspan; /* 16 = RE_MAX_OSA */
- VlakRen *vlr= NULL;
- VertRen *v1, *v2, *v3, *v4;
- Material *ma = NULL;
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- float obwinmat[4][4], winmat[4][4], bounds[4];
- float ho1[4], ho2[4], ho3[4], ho4[4]={0};
- unsigned int lay= rl->lay, lay_zmask= rl->lay_zmask;
- int i, v, zvlnr, zsample, samples, c1, c2, c3, c4=0;
- short nofill=0, env=0, wire=0, zmaskpass=0;
- const bool all_z = (rl->layflag & SCE_LAY_ALL_Z) && !(rl->layflag & SCE_LAY_ZMASK);
- const bool neg_zmask = (rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK);
-
- zbuf_make_winmat(&R, winmat);
-
- samples= (R.osa? R.osa: 1);
- samples= MIN2(4, samples-pa->sample);
-
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
-
- zbuffer_part_bounds(R.winx, R.winy, pa, bounds);
- zbuf_alloc_span(zspan, pa->rectx, pa->recty, R.clipcrop);
-
- /* needed for transform from hoco to zbuffer co */
- zspan->zmulx= ((float)R.winx)/2.0f;
- zspan->zmuly= ((float)R.winy)/2.0f;
-
- if (R.osa) {
- zspan->zofsx= -pa->disprect.xmin - R.jit[pa->sample+zsample][0];
- zspan->zofsy= -pa->disprect.ymin - R.jit[pa->sample+zsample][1];
- }
- else if (R.i.curblur) {
- zspan->zofsx= -pa->disprect.xmin - R.mblur_jit[R.i.curblur-1][0];
- zspan->zofsy= -pa->disprect.ymin - R.mblur_jit[R.i.curblur-1][1];
- }
- else {
- zspan->zofsx= -pa->disprect.xmin;
- zspan->zofsy= -pa->disprect.ymin;
- }
- /* to center the sample position */
- zspan->zofsx -= 0.5f;
- zspan->zofsy -= 0.5f;
-
- /* the buffers */
- if (zsample == samples-1) {
- zspan->rectp= pa->rectp;
- zspan->recto= pa->recto;
-
- if (neg_zmask)
- zspan->rectz= pa->rectmask;
- else
- zspan->rectz= pa->rectz;
- }
- else {
- zspan->recto= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "recto");
- zspan->rectp= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
- zspan->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
- }
-
- fillrect(zspan->rectz, pa->rectx, pa->recty, 0x7FFFFFFF);
- fillrect(zspan->rectp, pa->rectx, pa->recty, 0);
- fillrect(zspan->recto, pa->rectx, pa->recty, 0);
- }
-
- /* in case zmask we fill Z for objects in lay_zmask first, then clear Z, and then do normal zbuffering */
- if (rl->layflag & SCE_LAY_ZMASK)
- zmaskpass= 1;
-
- for (; zmaskpass >=0; zmaskpass--) {
- ma= NULL;
-
- /* filling methods */
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
-
- if (zmaskpass && neg_zmask)
- zspan->zbuffunc= zbuffillGLinv4;
- else
- zspan->zbuffunc= zbuffillGL4;
- zspan->zbuflinefunc= zbufline;
- }
-
- /* regular zbuffering loop, does all sample buffers */
- for (i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) {
- obr= obi->obr;
-
- /* continue happens in 2 different ways... zmaskpass only does lay_zmask stuff */
- if (zmaskpass) {
- if ((obi->lay & lay_zmask)==0)
- continue;
- }
- else if (!all_z && !(obi->lay & (lay|lay_zmask)))
- continue;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(obwinmat, winmat, obi->mat);
- else
- copy_m4_m4(obwinmat, winmat);
-
- if (clip_render_object(obi->obr->boundbox, bounds, obwinmat))
- continue;
-
- zbuf_project_cache_clear(cache, obr->totvert);
-
- for (v=0; v<obr->totvlak; v++) {
- if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak;
- else vlr++;
-
- /* the cases: visible for render, only z values, zmask, nothing */
- if (obi->lay & lay) {
- if (vlr->mat!=ma) {
- ma= vlr->mat;
- nofill= (ma->mode & MA_ONLYCAST) || ((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP));
- env= (ma->mode & MA_ENV);
- wire= (ma->material_type == MA_TYPE_WIRE);
-
- for (zsample=0; zsample<samples; zsample++) {
- if (ma->mode & MA_ZINV || (zmaskpass && neg_zmask))
- zspans[zsample].zbuffunc= zbuffillGLinv4;
- else
- zspans[zsample].zbuffunc= zbuffillGL4;
- }
- }
- }
- else if (all_z || (obi->lay & lay_zmask)) {
- env= 1;
- nofill= 0;
- ma= NULL;
- }
- else {
- nofill= 1;
- ma= NULL; /* otherwise nofill can hang */
- }
-
- if (!(vlr->flag & R_HIDDEN) && nofill==0) {
- unsigned short partclip;
-
- v1= vlr->v1;
- v2= vlr->v2;
- v3= vlr->v3;
- v4= vlr->v4;
-
- c1= zbuf_part_project(cache, v1->index, obwinmat, bounds, v1->co, ho1);
- c2= zbuf_part_project(cache, v2->index, obwinmat, bounds, v2->co, ho2);
- c3= zbuf_part_project(cache, v3->index, obwinmat, bounds, v3->co, ho3);
-
- /* partclipping doesn't need viewplane clipping */
- partclip= c1 & c2 & c3;
- if (v4) {
- c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4);
- partclip &= c4;
- }
-
- if (partclip==0) {
-
- if (env) zvlnr= -1;
- else zvlnr= v+1;
-
- c1= testclip(ho1);
- c2= testclip(ho2);
- c3= testclip(ho3);
- if (v4)
- c4= testclip(ho4);
-
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
-
- if (wire) {
- if (v4)
- zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
- else
- zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, NULL, c1, c2, c3, 0);
- }
- else {
- /* strands allow to be filled in as quad */
- if (v4 && (vlr->flag & R_STRAND)) {
- zbufclip4(zspan, i, zvlnr, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
- }
- else {
- zbufclip(zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3);
- if (v4)
- zbufclip(zspan, i, (env)? zvlnr: zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4);
- }
- }
- }
- }
- }
- }
- }
-
- /* clear all z to close value, so it works as mask for next passes (ztra+strand) */
- if (zmaskpass) {
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
-
- if (neg_zmask) {
- zspan->rectmask= zspan->rectz;
- if (zsample == samples-1)
- zspan->rectz= pa->rectz;
- else
- zspan->rectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
- fillrect(zspan->rectz, pa->rectx, pa->recty, 0x7FFFFFFF);
-
- zmask_rect(zspan->rectmask, zspan->rectp, pa->rectx, pa->recty, 1);
- }
- else
- zmask_rect(zspan->rectz, zspan->rectp, pa->rectx, pa->recty, 0);
- }
- }
- }
-
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
-
- if (fillfunc)
- fillfunc(pa, zspan, pa->sample+zsample, data);
-
- if (zsample != samples-1) {
- MEM_freeN(zspan->rectz);
- MEM_freeN(zspan->rectp);
- MEM_freeN(zspan->recto);
- if (zspan->rectmask)
- MEM_freeN(zspan->rectmask);
- }
-
- zbuf_free_span(zspan);
- }
-}
-
-void zbuffer_shadow(Render *re, float winmat[4][4], LampRen *lar, int *rectz, int size, float jitx, float jity)
-{
- ZbufProjectCache cache[ZBUF_PROJECT_CACHE_SIZE];
- ZSpan zspan;
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- VlakRen *vlr= NULL;
- Material *ma= NULL;
- StrandSegment sseg;
- StrandRen *strand= NULL;
- StrandVert *svert;
- StrandBound *sbound;
- float obwinmat[4][4], ho1[4], ho2[4], ho3[4], ho4[4];
- int a, b, c, i, c1, c2, c3, c4, ok=1, lay= -1;
-
- if (lar->mode & (LA_LAYER|LA_LAYER_SHADOW)) lay= lar->lay;
-
- /* 1.0f for clipping in clippyra()... bad stuff actually */
- zbuf_alloc_span(&zspan, size, size, 1.0f);
- zspan.zmulx= ((float)size)/2.0f;
- zspan.zmuly= ((float)size)/2.0f;
- /* -0.5f to center the sample position */
- zspan.zofsx= jitx - 0.5f;
- zspan.zofsy= jity - 0.5f;
-
- /* the buffers */
- zspan.rectz= rectz;
- fillrect(rectz, size, size, 0x7FFFFFFE);
- if (lar->buftype==LA_SHADBUF_HALFWAY) {
- zspan.rectz1= MEM_mallocN(size*size*sizeof(int), "seconday z buffer");
- fillrect(zspan.rectz1, size, size, 0x7FFFFFFE);
- }
-
- /* filling methods */
- zspan.zbuflinefunc= zbufline_onlyZ;
- zspan.zbuffunc= zbuffillGL_onlyZ;
-
- for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
- obr= obi->obr;
-
- if (obr->ob==re->excludeob)
- continue;
- else if (!(obi->lay & lay))
- continue;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(obwinmat, winmat, obi->mat);
- else
- copy_m4_m4(obwinmat, winmat);
-
- if (clip_render_object(obi->obr->boundbox, NULL, obwinmat))
- continue;
-
- zbuf_project_cache_clear(cache, obr->totvert);
-
- /* faces */
- for (a=0; a<obr->totvlak; a++) {
-
- if ((a & 255)==0) vlr= obr->vlaknodes[a>>8].vlak;
- else vlr++;
-
- /* note, these conditions are copied in shadowbuf_autoclip() */
- if (vlr->mat!= ma) {
- ma= vlr->mat;
- ok= 1;
- if ((ma->mode2 & MA_CASTSHADOW)==0 || (ma->mode & MA_SHADBUF)==0) ok= 0;
- }
-
- if (ok && (obi->lay & lay) && !(vlr->flag & R_HIDDEN)) {
- c1= zbuf_shadow_project(cache, vlr->v1->index, obwinmat, vlr->v1->co, ho1);
- c2= zbuf_shadow_project(cache, vlr->v2->index, obwinmat, vlr->v2->co, ho2);
- c3= zbuf_shadow_project(cache, vlr->v3->index, obwinmat, vlr->v3->co, ho3);
-
- if ((ma->material_type == MA_TYPE_WIRE) || (vlr->flag & R_STRAND)) {
- if (vlr->v4) {
- c4= zbuf_shadow_project(cache, vlr->v4->index, obwinmat, vlr->v4->co, ho4);
- zbufclipwire(&zspan, 0, a+1, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
- }
- else
- zbufclipwire(&zspan, 0, a+1, vlr->ec, ho1, ho2, ho3, NULL, c1, c2, c3, 0);
- }
- else {
- if (vlr->v4) {
- c4= zbuf_shadow_project(cache, vlr->v4->index, obwinmat, vlr->v4->co, ho4);
- zbufclip4(&zspan, 0, 0, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
- }
- else
- zbufclip(&zspan, 0, 0, ho1, ho2, ho3, c1, c2, c3);
- }
- }
-
- if ((a & 255)==255 && re->test_break(re->tbh))
- break;
- }
-
- /* strands */
- if (obr->strandbuf) {
- /* for each bounding box containing a number of strands */
- sbound= obr->strandbuf->bound;
- for (c=0; c<obr->strandbuf->totbound; c++, sbound++) {
- if (clip_render_object(sbound->boundbox, NULL, obwinmat))
- continue;
-
- /* for each strand in this bounding box */
- for (a=sbound->start; a<sbound->end; a++) {
- strand= RE_findOrAddStrand(obr, a);
-
- sseg.obi= obi;
- sseg.buffer= strand->buffer;
- sseg.sqadaptcos= sseg.buffer->adaptcos;
- sseg.sqadaptcos *= sseg.sqadaptcos;
- sseg.strand= strand;
- svert= strand->vert;
-
- /* note, these conditions are copied in shadowbuf_autoclip() */
- if (sseg.buffer->ma!= ma) {
- ma= sseg.buffer->ma;
- ok= 1;
- if ((ma->mode2 & MA_CASTSHADOW)==0 || (ma->mode & MA_SHADBUF)==0) ok= 0;
- }
-
- if (ok && (sseg.buffer->lay & lay)) {
- zbuf_project_cache_clear(cache, strand->totvert);
-
- for (b=0; b<strand->totvert-1; b++, svert++) {
- sseg.v[0]= (b > 0)? (svert-1): svert;
- sseg.v[1]= svert;
- sseg.v[2]= svert+1;
- sseg.v[3]= (b < strand->totvert-2)? svert+2: svert+1;
-
- c1= zbuf_shadow_project(cache, sseg.v[0]-strand->vert, obwinmat, sseg.v[0]->co, ho1);
- c2= zbuf_shadow_project(cache, sseg.v[1]-strand->vert, obwinmat, sseg.v[1]->co, ho2);
- c3= zbuf_shadow_project(cache, sseg.v[2]-strand->vert, obwinmat, sseg.v[2]->co, ho3);
- c4= zbuf_shadow_project(cache, sseg.v[3]-strand->vert, obwinmat, sseg.v[3]->co, ho4);
-
- if (!(c1 & c2 & c3 & c4))
- render_strand_segment(re, winmat, NULL, &zspan, 1, &sseg);
- }
- }
-
- if ((a & 255)==255 && re->test_break(re->tbh))
- break;
- }
- }
- }
-
- if (re->test_break(re->tbh))
- break;
- }
-
- /* merge buffers */
- if (lar->buftype==LA_SHADBUF_HALFWAY) {
- for (a=size*size -1; a>=0; a--)
- rectz[a]= (rectz[a]>>1) + (zspan.rectz1[a]>>1);
-
- MEM_freeN(zspan.rectz1);
- }
-
- zbuf_free_span(&zspan);
-}
-
-static void zbuffill_sss(ZSpan *zspan, int obi, int zvlnr,
- const float *v1, const float *v2, const float *v3, const float *v4)
-{
- double zxd, zyd, zy0, z;
- float x0, y0, x1, y1, x2, y2, z0, z1, z2, xx1, *span1, *span2;
- int x, y, sn1, sn2, rectx= zspan->rectx, my0, my2;
- /* init */
- zbuf_init_span(zspan);
-
- /* set spans */
- zbuf_add_to_span(zspan, v1, v2);
- zbuf_add_to_span(zspan, v2, v3);
- if (v4) {
- zbuf_add_to_span(zspan, v3, v4);
- zbuf_add_to_span(zspan, v4, v1);
- }
- else
- zbuf_add_to_span(zspan, v3, v1);
-
- /* clipped */
- if (zspan->minp2==NULL || zspan->maxp2==NULL) return;
-
- my0 = max_ii(zspan->miny1, zspan->miny2);
- my2 = min_ii(zspan->maxy1, zspan->maxy2);
-
- if (my2<my0) return;
-
- /* ZBUF DX DY, in floats still */
- x1= v1[0]- v2[0];
- x2= v2[0]- v3[0];
- y1= v1[1]- v2[1];
- y2= v2[1]- v3[1];
- z1= v1[2]- v2[2];
- z2= v2[2]- v3[2];
-
- x0= y1*z2-z1*y2;
- y0= z1*x2-x1*z2;
- z0= x1*y2-y1*x2;
-
- if (z0==0.0f) return;
-
- xx1= (x0*v1[0] + y0*v1[1])/z0 + v1[2];
- zxd= -(double)x0/(double)z0;
- zyd= -(double)y0/(double)z0;
- zy0= ((double)my2)*zyd + (double)xx1;
-
- /* correct span */
- sn1= (my0 + my2)/2;
- if (zspan->span1[sn1] < zspan->span2[sn1]) {
- span1= zspan->span1+my2;
- span2= zspan->span2+my2;
- }
- else {
- span1= zspan->span2+my2;
- span2= zspan->span1+my2;
- }
-
- for (y=my2; y>=my0; y--, span1--, span2--) {
- sn1= floor(*span1);
- sn2= floor(*span2);
- sn1++;
-
- if (sn2>=rectx) sn2= rectx-1;
- if (sn1<0) sn1= 0;
-
- z= (double)sn1*zxd + zy0;
-
- for (x= sn1; x<=sn2; x++, z+=zxd)
- zspan->sss_func(zspan->sss_handle, obi, zvlnr, x, y, z);
-
- zy0 -= zyd;
- }
-}
-
-void zbuffer_sss(RenderPart *pa, unsigned int lay, void *handle, void (*func)(void *, int, int, int, int, int))
-{
- ZbufProjectCache cache[ZBUF_PROJECT_CACHE_SIZE];
- ZSpan zspan;
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- VlakRen *vlr= NULL;
- VertRen *v1, *v2, *v3, *v4;
- Material *ma = NULL, *sss_ma = R.sss_mat;
- float obwinmat[4][4], winmat[4][4], bounds[4];
- float ho1[4], ho2[4], ho3[4], ho4[4]={0};
- int i, v, zvlnr, c1, c2, c3, c4=0;
- short nofill=0, env=0, wire=0;
-
- zbuf_make_winmat(&R, winmat);
- zbuffer_part_bounds(R.winx, R.winy, pa, bounds);
- zbuf_alloc_span(&zspan, pa->rectx, pa->recty, R.clipcrop);
-
- zspan.sss_handle= handle;
- zspan.sss_func= func;
-
- /* needed for transform from hoco to zbuffer co */
- zspan.zmulx= ((float)R.winx)/2.0f;
- zspan.zmuly= ((float)R.winy)/2.0f;
-
- /* -0.5f to center the sample position */
- zspan.zofsx= -pa->disprect.xmin - 0.5f;
- zspan.zofsy= -pa->disprect.ymin - 0.5f;
-
- /* filling methods */
- zspan.zbuffunc= zbuffill_sss;
-
- /* fill front and back zbuffer */
- if (pa->rectz) {
- fillrect(pa->recto, pa->rectx, pa->recty, 0);
- fillrect(pa->rectp, pa->rectx, pa->recty, 0);
- fillrect(pa->rectz, pa->rectx, pa->recty, 0x7FFFFFFF);
- }
- if (pa->rectbackz) {
- fillrect(pa->rectbacko, pa->rectx, pa->recty, 0);
- fillrect(pa->rectbackp, pa->rectx, pa->recty, 0);
- fillrect(pa->rectbackz, pa->rectx, pa->recty, -0x7FFFFFFF);
- }
-
- for (i=0, obi=R.instancetable.first; obi; i++, obi=obi->next) {
- obr= obi->obr;
-
- if (!(obi->lay & lay))
- continue;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(obwinmat, winmat, obi->mat);
- else
- copy_m4_m4(obwinmat, winmat);
-
- if (clip_render_object(obi->obr->boundbox, bounds, obwinmat))
- continue;
-
- zbuf_project_cache_clear(cache, obr->totvert);
-
- for (v=0; v<obr->totvlak; v++) {
- if ((v & 255)==0) vlr= obr->vlaknodes[v>>8].vlak;
- else vlr++;
-
- if (material_in_material(vlr->mat, sss_ma)) {
- /* three cases, visible for render, only z values and nothing */
- if (obi->lay & lay) {
- if (vlr->mat!=ma) {
- ma= vlr->mat;
- nofill= ma->mode & MA_ONLYCAST;
- env= (ma->mode & MA_ENV);
- wire= (ma->material_type == MA_TYPE_WIRE);
- }
- }
- else {
- nofill= 1;
- ma= NULL; /* otherwise nofill can hang */
- }
-
- if (nofill==0 && wire==0 && env==0) {
- unsigned short partclip;
-
- v1= vlr->v1;
- v2= vlr->v2;
- v3= vlr->v3;
- v4= vlr->v4;
-
- c1= zbuf_part_project(cache, v1->index, obwinmat, bounds, v1->co, ho1);
- c2= zbuf_part_project(cache, v2->index, obwinmat, bounds, v2->co, ho2);
- c3= zbuf_part_project(cache, v3->index, obwinmat, bounds, v3->co, ho3);
-
- /* partclipping doesn't need viewplane clipping */
- partclip= c1 & c2 & c3;
- if (v4) {
- c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4);
- partclip &= c4;
- }
-
- if (partclip==0) {
- c1= testclip(ho1);
- c2= testclip(ho2);
- c3= testclip(ho3);
-
- zvlnr= v+1;
- zbufclip(&zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3);
- if (v4) {
- c4= testclip(ho4);
- zbufclip(&zspan, i, zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4);
- }
- }
- }
- }
- }
- }
-
- zbuf_free_span(&zspan);
-}
-
-/* ******************** ABUF ************************* */
-
-/**
- * Copy results from the solid face z buffering to the transparent
- * buffer.
- */
-static void copyto_abufz(RenderPart *pa, int *arectz, int *rectmask, int sample)
-{
- PixStr *ps;
- int x, y, *rza, *rma;
- intptr_t *rd;
-
- if (R.osa==0) {
- if (!pa->rectz)
- fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE);
- else
- memcpy(arectz, pa->rectz, sizeof(int)*pa->rectx*pa->recty);
-
- if (rectmask && pa->rectmask)
- memcpy(rectmask, pa->rectmask, sizeof(int)*pa->rectx*pa->recty);
-
- return;
- }
- else if (!pa->rectdaps) {
- fillrect(arectz, pa->rectx, pa->recty, 0x7FFFFFFE);
- return;
- }
-
- rza= arectz;
- rma= rectmask;
- rd= pa->rectdaps;
-
- sample= (1<<sample);
-
- for (y=0; y<pa->recty; y++) {
- for (x=0; x<pa->rectx; x++) {
-
- *rza= 0x7FFFFFFF;
- if (rectmask) *rma= 0x7FFFFFFF;
- if (*rd) {
- /* when there's a sky pixstruct, fill in sky-Z, otherwise solid Z */
- for (ps= (PixStr *)(*rd); ps; ps= ps->next) {
- if (sample & ps->mask) {
- *rza= ps->z;
- if (rectmask) *rma= ps->maskz;
- break;
- }
- }
- }
-
- rza++;
- rma++;
- rd++;
- }
- }
-}
-
-
-/* ------------------------------------------------------------------------ */
-
-/**
- * Do accumulation z buffering.
- */
-
-static int zbuffer_abuf(Render *re, RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, unsigned int lay, int negzmask, float winmat[4][4], int winx, int winy, int samples, float (*jit)[2], float UNUSED(clipcrop), int shadow)
-{
- ZbufProjectCache cache[ZBUF_PROJECT_CACHE_SIZE];
- ZSpan zspans[16], *zspan; /* MAX_OSA */
- Material *ma=NULL;
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- VlakRen *vlr=NULL;
- VertRen *v1, *v2, *v3, *v4;
- float vec[3], hoco[4], mul, zval, fval;
- float obwinmat[4][4], bounds[4], ho1[4], ho2[4], ho3[4], ho4[4]={0};
- int i, v, zvlnr, c1, c2, c3, c4=0, dofill= 0;
- int zsample, polygon_offset;
-
- zbuffer_part_bounds(winx, winy, pa, bounds);
-
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
-
- zbuf_alloc_span(zspan, pa->rectx, pa->recty, re->clipcrop);
-
- /* needed for transform from hoco to zbuffer co */
- zspan->zmulx= ((float)winx)/2.0f;
- zspan->zmuly= ((float)winy)/2.0f;
-
- /* the buffers */
- zspan->arectz= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectz");
- zspan->apixbuf= APixbuf;
- zspan->apsmbase= apsmbase;
-
- if (negzmask)
- zspan->rectmask= MEM_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectmask");
-
- /* filling methods */
- zspan->zbuffunc= zbuffillAc4;
- zspan->zbuflinefunc= zbuflineAc;
-
- copyto_abufz(pa, zspan->arectz, zspan->rectmask, zsample); /* init zbuffer */
- zspan->mask= 1<<zsample;
-
- if (jit) {
- zspan->zofsx= -pa->disprect.xmin - jit[zsample][0];
- zspan->zofsy= -pa->disprect.ymin - jit[zsample][1];
- }
- else {
- zspan->zofsx= -pa->disprect.xmin;
- zspan->zofsy= -pa->disprect.ymin;
- }
-
- /* to center the sample position */
- zspan->zofsx -= 0.5f;
- zspan->zofsy -= 0.5f;
- }
-
- /* we use this to test if nothing was filled in */
- zvlnr= 0;
-
- for (i=0, obi=re->instancetable.first; obi; i++, obi=obi->next) {
- obr= obi->obr;
-
- if (!(obi->lay & lay))
- continue;
-
- if (obi->flag & R_TRANSFORMED)
- mul_m4_m4m4(obwinmat, winmat, obi->mat);
- else
- copy_m4_m4(obwinmat, winmat);
-
- if (clip_render_object(obi->obr->boundbox, bounds, obwinmat))
- continue;
-
- zbuf_project_cache_clear(cache, obr->totvert);
-
- for (v=0; v<obr->totvlak; v++) {
- if ((v & 255)==0)
- vlr= obr->vlaknodes[v>>8].vlak;
- else vlr++;
-
- if (vlr->mat!=ma) {
- ma= vlr->mat;
- if (shadow)
- dofill= (ma->mode2 & MA_CASTSHADOW) && (ma->mode & MA_SHADBUF);
- else
- dofill= (((ma->mode & MA_TRANSP) && (ma->mode & MA_ZTRANSP)) && !(ma->mode & MA_ONLYCAST));
- }
-
- if (dofill) {
- if (!(vlr->flag & R_HIDDEN) && (obi->lay & lay)) {
- unsigned short partclip;
-
- v1= vlr->v1;
- v2= vlr->v2;
- v3= vlr->v3;
- v4= vlr->v4;
-
- c1= zbuf_part_project(cache, v1->index, obwinmat, bounds, v1->co, ho1);
- c2= zbuf_part_project(cache, v2->index, obwinmat, bounds, v2->co, ho2);
- c3= zbuf_part_project(cache, v3->index, obwinmat, bounds, v3->co, ho3);
-
- /* partclipping doesn't need viewplane clipping */
- partclip= c1 & c2 & c3;
- if (v4) {
- c4= zbuf_part_project(cache, v4->index, obwinmat, bounds, v4->co, ho4);
- partclip &= c4;
- }
-
- if (partclip==0) {
- /* a little advantage for transp rendering (a z offset) */
- if (!shadow && ma->zoffs != 0.0f) {
- mul= 0x7FFFFFFF;
- zval= mul*(1.0f+ho1[2]/ho1[3]);
-
- copy_v3_v3(vec, v1->co);
- /* z is negative, otherwise its being clipped */
- vec[2]-= ma->zoffs;
- projectverto(vec, obwinmat, hoco);
- fval= mul*(1.0f+hoco[2]/hoco[3]);
-
- polygon_offset= (int)fabsf(zval - fval);
- }
- else polygon_offset= 0;
-
- zvlnr= v+1;
-
- c1= testclip(ho1);
- c2= testclip(ho2);
- c3= testclip(ho3);
- if (v4)
- c4= testclip(ho4);
-
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
- zspan->polygon_offset= polygon_offset;
-
- if (ma->material_type == MA_TYPE_WIRE) {
- if (v4)
- zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
- else
- zbufclipwire(zspan, i, zvlnr, vlr->ec, ho1, ho2, ho3, NULL, c1, c2, c3, 0);
- }
- else {
- if (v4 && (vlr->flag & R_STRAND)) {
- zbufclip4(zspan, i, zvlnr, ho1, ho2, ho3, ho4, c1, c2, c3, c4);
- }
- else {
- zbufclip(zspan, i, zvlnr, ho1, ho2, ho3, c1, c2, c3);
- if (v4)
- zbufclip(zspan, i, zvlnr+RE_QUAD_OFFS, ho1, ho3, ho4, c1, c3, c4);
- }
- }
- }
- }
- if ((v & 255)==255)
- if (re->test_break(re->tbh))
- break;
- }
- }
- }
-
- if (re->test_break(re->tbh)) break;
- }
-
- for (zsample=0; zsample<samples; zsample++) {
- zspan= &zspans[zsample];
- MEM_freeN(zspan->arectz);
- if (zspan->rectmask)
- MEM_freeN(zspan->rectmask);
- zbuf_free_span(zspan);
- }
-
- return zvlnr;
-}
-
-static int zbuffer_abuf_render(RenderPart *pa, APixstr *APixbuf, APixstrand *APixbufstrand, ListBase *apsmbase, RenderLayer *rl, StrandShadeCache *sscache)
-{
- float winmat[4][4], (*jit)[2];
- int samples, negzmask, doztra= 0;
-
- samples= (R.osa)? R.osa: 1;
- negzmask= ((rl->layflag & SCE_LAY_ZMASK) && (rl->layflag & SCE_LAY_NEG_ZMASK));
-
- if (R.osa)
- jit= R.jit;
- else if (R.i.curblur)
- jit= &R.mblur_jit[R.i.curblur-1];
- else
- jit= NULL;
-
- zbuf_make_winmat(&R, winmat);
-
- if (rl->layflag & SCE_LAY_ZTRA)
- doztra+= zbuffer_abuf(&R, pa, APixbuf, apsmbase, rl->lay, negzmask, winmat, R.winx, R.winy, samples, jit, R.clipcrop, 0);
- if ((rl->layflag & SCE_LAY_STRAND) && APixbufstrand)
- doztra+= zbuffer_strands_abuf(&R, pa, APixbufstrand, apsmbase, rl->lay, negzmask, winmat, R.winx, R.winy, samples, jit, R.clipcrop, 0, sscache);
-
- return doztra;
-}
-
-void zbuffer_abuf_shadow(Render *re, LampRen *lar, float winmat[4][4], APixstr *APixbuf, APixstrand *APixbufstrand, ListBase *apsmbase, int size, int samples, float (*jit)[2])
-{
- RenderPart pa;
- int lay= -1;
-
- if (lar->mode & LA_LAYER) lay= lar->lay;
-
- memset(&pa, 0, sizeof(RenderPart));
- pa.rectx= size;
- pa.recty= size;
- pa.disprect.xmin = 0;
- pa.disprect.ymin = 0;
- pa.disprect.xmax = size;
- pa.disprect.ymax = size;
-
- zbuffer_abuf(re, &pa, APixbuf, apsmbase, lay, 0, winmat, size, size, samples, jit, 1.0f, 1);
- if (APixbufstrand)
- zbuffer_strands_abuf(re, &pa, APixbufstrand, apsmbase, lay, 0, winmat, size, size, samples, jit, 1.0f, 1, NULL);
-}
-
-/* different rules for speed in transparent pass... */
-/* speed pointer NULL = sky, we clear */
-/* else if either alpha is full or no solid was filled in: copy speed */
-/* else fill in minimum speed */
-static void add_transp_speed(RenderLayer *rl, int offset, float speed[4], float alpha, intptr_t *rdrect)
-{
- RenderPass *rpass;
-
- for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
- if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) {
- float *fp= rpass->rect + 4*offset;
-
- if (speed==NULL) {
- /* clear */
- if (fp[0]==PASS_VECTOR_MAX) fp[0]= 0.0f;
- if (fp[1]==PASS_VECTOR_MAX) fp[1]= 0.0f;
- if (fp[2]==PASS_VECTOR_MAX) fp[2]= 0.0f;
- if (fp[3]==PASS_VECTOR_MAX) fp[3]= 0.0f;
- }
- else if (rdrect==NULL || rdrect[offset]==0 || alpha>0.95f) {
- copy_v4_v4(fp, speed);
- }
- else {
- /* add minimum speed in pixel */
- if ( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) {
- fp[0]= speed[0];
- fp[1]= speed[1];
- }
- if ( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) {
- fp[2]= speed[2];
- fp[3]= speed[3];
- }
- }
- break;
- }
- }
-}
-
-static void add_transp_obindex(RenderLayer *rl, int offset, Object *ob)
-{
- RenderPass *rpass;
-
- for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
- if (STREQ(rpass->name, RE_PASSNAME_INDEXOB)) {
- float *fp= rpass->rect + offset;
- *fp= (float)ob->index;
- break;
- }
- }
-}
-
-static void add_transp_material_index(RenderLayer *rl, int offset, Material *mat)
-{
- RenderPass *rpass;
-
- for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
- if (STREQ(rpass->name, RE_PASSNAME_INDEXMA)) {
- float *fp= rpass->rect + offset;
- *fp= (float)mat->index;
- break;
- }
- }
-}
-
-/* ONLY OSA! merge all shaderesult samples to one */
-/* target should have been cleared */
-static void merge_transp_passes(RenderLayer *rl, ShadeResult *shr)
-{
- RenderPass *rpass;
- float weight= 1.0f/((float)R.osa);
- int delta= sizeof(ShadeResult)/4;
-
- for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
- float *col = NULL;
- int pixsize = 3;
-
- if (STREQ(rpass->name, RE_PASSNAME_RGBA)) {
- col = shr->col;
- pixsize = 4;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_EMIT)) {
- col = shr->emit;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE)) {
- col = shr->diff;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SPEC)) {
- col = shr->spec;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SHADOW)) {
- col = shr->shad;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_AO)) {
- col = shr->ao;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_ENVIRONMENT)) {
- col = shr->env;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDIRECT)) {
- col = shr->indirect;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFLECT)) {
- col = shr->refl;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFRACT)) {
- col = shr->refr;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_NORMAL)) {
- col = shr->nor;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_MIST)) {
- col = &shr->mist;
- pixsize = 1;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_Z)) {
- col = &shr->z;
- pixsize = 1;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_VECTOR)) {
- ShadeResult *shr_t = shr+1;
- float *fp = shr->winspeed; /* was initialized */
- int samp;
-
- /* add minimum speed in pixel */
- for (samp = 1; samp<R.osa; samp++, shr_t++) {
-
- if (shr_t->combined[3] > 0.0f) {
- const float *speed = shr_t->winspeed;
-
- if ( (ABS(speed[0]) + ABS(speed[1]))< (ABS(fp[0]) + ABS(fp[1])) ) {
- fp[0] = speed[0];
- fp[1] = speed[1];
- }
- if ( (ABS(speed[2]) + ABS(speed[3]))< (ABS(fp[2]) + ABS(fp[3])) ) {
- fp[2] = speed[2];
- fp[3] = speed[3];
- }
- }
- }
- }
-
- if (col) {
- const float *fp= col+delta;
- int samp;
-
- for (samp= 1; samp<R.osa; samp++, fp+=delta) {
- col[0]+= fp[0];
- if (pixsize>1) {
- col[1]+= fp[1];
- col[2]+= fp[2];
- if (pixsize==4) col[3]+= fp[3];
- }
- }
- col[0]*= weight;
- if (pixsize>1) {
- col[1]*= weight;
- col[2]*= weight;
- if (pixsize==4) col[3]*= weight;
- }
- }
- }
-
-}
-
-static void add_transp_passes(RenderLayer *rl, int offset, ShadeResult *shr, float alpha)
-{
- RenderPass *rpass;
-
- for (rpass= rl->passes.first; rpass; rpass= rpass->next) {
- float *fp, *col= NULL;
- int pixsize= 3;
-
- if (STREQ(rpass->name, RE_PASSNAME_Z)) {
- fp = rpass->rect + offset;
- if (shr->z < *fp)
- *fp = shr->z;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_RGBA)) {
- fp = rpass->rect + 4*offset;
- addAlphaOverFloat(fp, shr->col);
- }
- else if (STREQ(rpass->name, RE_PASSNAME_EMIT)) {
- col = shr->emit;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_DIFFUSE)) {
- col = shr->diff;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SPEC)) {
- col = shr->spec;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_SHADOW)) {
- col = shr->shad;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_AO)) {
- col = shr->ao;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_ENVIRONMENT)) {
- col = shr->env;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_INDIRECT)) {
- col = shr->indirect;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFLECT)) {
- col = shr->refl;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_REFRACT)) {
- col = shr->refr;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_NORMAL)) {
- col = shr->nor;
- }
- else if (STREQ(rpass->name, RE_PASSNAME_MIST)) {
- col = &shr->mist;
- pixsize = 1;
- }
-
- if (col) {
- fp= rpass->rect + pixsize*offset;
- fp[0]= col[0] + (1.0f-alpha)*fp[0];
- if (pixsize==3) {
- fp[1]= col[1] + (1.0f-alpha)*fp[1];
- fp[2]= col[2] + (1.0f-alpha)*fp[2];
- }
- }
- }
-}
-
-typedef struct ZTranspRow {
- int obi;
- int z;
- int p;
- int mask;
- int segment;
- float u, v;
-} ZTranspRow;
-
-static int vergzvlak(const void *a1, const void *a2)
-{
- const ZTranspRow *r1 = a1, *r2 = a2;
-
- if (r1->z < r2->z) return 1;
- else if (r1->z > r2->z) return -1;
- return 0;
-}
-
-static void shade_strand_samples(StrandShadeCache *cache, ShadeSample *ssamp, int UNUSED(x), int UNUSED(y), ZTranspRow *row, int addpassflag)
-{
- StrandSegment sseg;
- StrandVert *svert;
- ObjectInstanceRen *obi;
- ObjectRen *obr;
-
- obi= R.objectinstance + row->obi;
- obr= obi->obr;
-
- sseg.obi= obi;
- sseg.strand= RE_findOrAddStrand(obr, row->p-1);
- sseg.buffer= sseg.strand->buffer;
-
- svert= sseg.strand->vert + row->segment;
- sseg.v[0]= (row->segment > 0)? (svert-1): svert;
- sseg.v[1]= svert;
- sseg.v[2]= svert+1;
- sseg.v[3]= (row->segment < sseg.strand->totvert-2)? svert+2: svert+1;
-
- ssamp->tot= 1;
- strand_shade_segment(&R, cache, &sseg, ssamp, row->v, row->u, addpassflag);
- ssamp->shi[0].mask= row->mask;
-}
-
-static void unref_strand_samples(StrandShadeCache *cache, ZTranspRow *row, int totface)
-{
- StrandVert *svert;
- ObjectInstanceRen *obi;
- ObjectRen *obr;
- StrandRen *strand;
-
- /* remove references to samples that are not being rendered, but we still
- * need to remove them so that the reference count of strand vertex shade
- * samples correctly drops to zero */
- while (totface > 0) {
- totface--;
-
- if (row[totface].segment != -1) {
- obi= R.objectinstance + row[totface].obi;
- obr= obi->obr;
- strand= RE_findOrAddStrand(obr, row[totface].p-1);
- svert= strand->vert + row[totface].segment;
-
- strand_shade_unref(cache, obi, svert);
- strand_shade_unref(cache, obi, svert+1);
- }
- }
-}
-
-static void shade_tra_samples_fill(ShadeSample *ssamp, int x, int y, int z, int obi, int facenr, int curmask)
-{
- ShadeInput *shi= ssamp->shi;
- float xs, ys;
-
- ssamp->tot= 0;
-
- shade_input_set_triangle(shi, obi, facenr, 1);
-
- /* officially should always be true... we have no sky info */
- if (shi->vlr) {
-
- /* full osa is only set for OSA renders */
- if (shi->vlr->flag & R_FULL_OSA) {
- short shi_inc= 0, samp;
-
- for (samp=0; samp<R.osa; samp++) {
- if (curmask & (1<<samp)) {
- xs= (float)x + R.jit[samp][0] + 0.5f; /* zbuffer has this inverse corrected, ensures (xs, ys) are inside pixel */
- ys= (float)y + R.jit[samp][1] + 0.5f;
-
- if (shi_inc) {
- shade_input_copy_triangle(shi+1, shi);
- shi++;
- }
- shi->mask= (1<<samp);
- shi->samplenr= R.shadowsamplenr[shi->thread]++;
- shade_input_set_viewco(shi, x, y, xs, ys, (float)z);
- shade_input_set_uv(shi);
- if (shi_inc==0)
- shade_input_set_normals(shi);
- else /* XXX shi->flippednor messes up otherwise */
- shade_input_set_vertex_normals(shi);
-
- shi_inc= 1;
- }
- }
- }
- else {
- if (R.osa) {
- short b= R.samples->centmask[curmask];
- xs= (float)x + R.samples->centLut[b & 15] + 0.5f;
- ys= (float)y + R.samples->centLut[b>>4] + 0.5f;
- }
- else if (R.i.curblur) {
- xs= (float)x + R.mblur_jit[R.i.curblur-1][0] + 0.5f;
- ys= (float)y + R.mblur_jit[R.i.curblur-1][1] + 0.5f;
- }
- else {
- xs= (float)x + 0.5f;
- ys= (float)y + 0.5f;
- }
- shi->mask= curmask;
- shi->samplenr= R.shadowsamplenr[shi->thread]++;
- shade_input_set_viewco(shi, x, y, xs, ys, (float)z);
- shade_input_set_uv(shi);
- shade_input_set_normals(shi);
- }
-
- /* total sample amount, shi->sample is static set in initialize */
- ssamp->tot= shi->sample+1;
- }
-}
-
-static int shade_tra_samples(ShadeSample *ssamp, StrandShadeCache *cache, int x, int y, ZTranspRow *row, int addpassflag)
-{
- if (row->segment != -1) {
- shade_strand_samples(cache, ssamp, x, y, row, addpassflag);
- return 1;
- }
-
- shade_tra_samples_fill(ssamp, x, y, row->z, row->obi, row->p, row->mask);
-
- if (ssamp->tot) {
- ShadeInput *shi= ssamp->shi;
- ShadeResult *shr= ssamp->shr;
- int samp;
-
- /* if AO? */
- shade_samples_do_AO(ssamp);
-
- /* if shade (all shadepinputs have same passflag) */
- if (shi->passflag & ~(SCE_PASS_Z|SCE_PASS_INDEXOB|SCE_PASS_INDEXMA)) {
- for (samp=0; samp<ssamp->tot; samp++, shi++, shr++) {
- shade_input_set_shade_texco(shi);
- shade_input_do_shade(shi, shr);
-
- /* include lamphalos for ztra, since halo layer was added already */
- if (R.flag & R_LAMPHALO)
- if (shi->layflag & SCE_LAY_HALO)
- renderspothalo(shi, shr->combined, shr->combined[3]);
- }
- }
- else if (shi->passflag & SCE_PASS_Z) {
- for (samp=0; samp<ssamp->tot; samp++, shi++, shr++)
- shr->z= -shi->co[2];
- }
-
- return 1;
- }
- return 0;
-}
-
-static int addtosamp_shr(ShadeResult *samp_shr, ShadeSample *ssamp, int addpassflag)
-{
- int a, sample, osa = (R.osa? R.osa: 1), retval = osa;
-
- for (a=0; a < osa; a++, samp_shr++) {
- ShadeInput *shi= ssamp->shi;
- ShadeResult *shr= ssamp->shr;
-
- for (sample=0; sample<ssamp->tot; sample++, shi++, shr++) {
-
- if (shi->mask & (1<<a)) {
- float fac= (1.0f - samp_shr->combined[3])*shr->combined[3];
-
- addAlphaUnderFloat(samp_shr->combined, shr->combined);
-
- samp_shr->z = min_ff(samp_shr->z, shr->z);
-
- if (addpassflag & SCE_PASS_VECTOR) {
- copy_v4_v4(samp_shr->winspeed, shr->winspeed);
- }
- /* optim... */
- if (addpassflag & ~(SCE_PASS_VECTOR)) {
-
- if (addpassflag & SCE_PASS_RGBA)
- addAlphaUnderFloat(samp_shr->col, shr->col);
-
- if (addpassflag & SCE_PASS_NORMAL)
- madd_v3_v3fl(samp_shr->nor, shr->nor, fac);
-
- if (addpassflag & SCE_PASS_EMIT)
- madd_v3_v3fl(samp_shr->emit, shr->emit, fac);
-
- if (addpassflag & SCE_PASS_DIFFUSE)
- madd_v3_v3fl(samp_shr->diff, shr->diff, fac);
-
- if (addpassflag & SCE_PASS_SPEC)
- madd_v3_v3fl(samp_shr->spec, shr->spec, fac);
-
- if (addpassflag & SCE_PASS_SHADOW)
- madd_v3_v3fl(samp_shr->shad, shr->shad, fac);
-
- if (addpassflag & SCE_PASS_AO)
- madd_v3_v3fl(samp_shr->ao, shr->ao, fac);
-
- if (addpassflag & SCE_PASS_ENVIRONMENT)
- madd_v3_v3fl(samp_shr->env, shr->env, fac);
-
- if (addpassflag & SCE_PASS_INDIRECT)
- madd_v3_v3fl(samp_shr->indirect, shr->indirect, fac);
-
- if (addpassflag & SCE_PASS_REFLECT)
- madd_v3_v3fl(samp_shr->refl, shr->refl, fac);
-
- if (addpassflag & SCE_PASS_REFRACT)
- madd_v3_v3fl(samp_shr->refr, shr->refr, fac);
-
- if (addpassflag & SCE_PASS_MIST)
- samp_shr->mist= samp_shr->mist+fac*shr->mist;
-
- }
- }
- }
-
- if (samp_shr->combined[3]>0.999f) retval--;
- }
- return retval;
-}
-
-static void reset_sky_speedvectors(RenderPart *pa, RenderLayer *rl, float *rectf)
-{
- /* speed vector exception... if solid render was done, sky pixels are set to zero already */
- /* for all pixels with alpha zero, we re-initialize speed again then */
- float *fp, *col;
- int a;
-
- fp = RE_RenderLayerGetPass(rl, RE_PASSNAME_VECTOR, R.viewname);
- if (fp==NULL) return;
- col= rectf+3;
-
- for (a= 4*pa->rectx*pa->recty -4; a>=0; a-=4) {
- if (col[a]==0.0f) {
- fp[a]= PASS_VECTOR_MAX;
- fp[a+1]= PASS_VECTOR_MAX;
- fp[a+2]= PASS_VECTOR_MAX;
- fp[a+3]= PASS_VECTOR_MAX;
- }
- }
-}
-
-#define MAX_ZROW 2000
-
-/* main render call to do the z-transparent layer */
-/* returns a mask, only if a) transp rendered and b) solid was rendered */
-unsigned short *zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass, ListBase *UNUSED(psmlist))
-{
- RenderResult *rr= pa->result;
- ShadeSample ssamp;
- APixstr *APixbuf; /* Zbuffer: linked list of face samples */
- APixstrand *APixbufstrand = NULL;
- APixstr *ap, *aprect, *apn;
- APixstrand *apstrand, *aprectstrand, *apnstrand;
- ListBase apsmbase={NULL, NULL};
- ShadeResult samp_shr[16]; /* MAX_OSA */
- ZTranspRow zrow[MAX_ZROW];
- StrandShadeCache *sscache= NULL;
- RenderLayer *rlpp[RE_MAX_OSA];
- float sampalpha, alpha, *passrect= pass;
- intptr_t *rdrect;
- int x, y, crop=0, a, b, totface, totfullsample, totsample, doztra;
- int addpassflag, offs= 0, od, osa = (R.osa? R.osa: 1);
- unsigned short *ztramask= NULL, filled;
-
- /* looks nicer for calling code */
- if (R.test_break(R.tbh))
- return NULL;
-
- if (R.osa > 16) { /* MAX_OSA */
- printf("zbuffer_transp_shade: osa too large\n");
- G.is_break = true;
- return NULL;
- }
-
- APixbuf= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf");
- if (R.totstrand && (rl->layflag & SCE_LAY_STRAND)) {
- APixbufstrand= MEM_callocN(pa->rectx*pa->recty*sizeof(APixstrand), "APixbufstrand");
- sscache= strand_shade_cache_create();
- }
-
- /* general shader info, passes */
- shade_sample_initialize(&ssamp, pa, rl);
- addpassflag= rl->passflag & ~(SCE_PASS_COMBINED);
-
- if (R.osa)
- sampalpha= 1.0f/(float)R.osa;
- else
- sampalpha= 1.0f;
-
- /* fill the Apixbuf */
- doztra= zbuffer_abuf_render(pa, APixbuf, APixbufstrand, &apsmbase, rl, sscache);
-
- if (doztra == 0) {
- /* nothing filled in */
- MEM_freeN(APixbuf);
- if (APixbufstrand)
- MEM_freeN(APixbufstrand);
- if (sscache)
- strand_shade_cache_free(sscache);
- freepsA(&apsmbase);
- return NULL;
- }
-
- aprect= APixbuf;
- aprectstrand= APixbufstrand;
- rdrect= pa->rectdaps;
-
- /* needed for correct zbuf/index pass */
- totfullsample= get_sample_layers(pa, rl, rlpp);
-
- /* irregular shadowb buffer creation */
- if (R.r.mode & R_SHADOW)
- ISB_create(pa, APixbuf);
-
- /* masks, to have correct alpha combine */
- if (R.osa && (rl->layflag & SCE_LAY_SOLID) && pa->fullresult.first==NULL)
- ztramask= MEM_callocN(pa->rectx*pa->recty*sizeof(short), "ztramask");
-
- /* zero alpha pixels get speed vector max again */
- if (addpassflag & SCE_PASS_VECTOR)
- if (rl->layflag & SCE_LAY_SOLID) {
- float *rect = RE_RenderLayerGetPass(rl, RE_PASSNAME_COMBINED, R.viewname);
- reset_sky_speedvectors(pa, rl, rl->acolrect ? rl->acolrect : rect); /* if acolrect is set we use it */
- }
- /* filtered render, for now we assume only 1 filter size */
- if (pa->crop) {
- crop= 1;
- offs= pa->rectx + 1;
- passrect+= 4*offs;
- aprect+= offs;
- aprectstrand+= offs;
- }
-
- /* init scanline updates */
- rr->renrect.ymin = 0;
- rr->renrect.ymax = -pa->crop;
- rr->renlay= rl;
-
- /* render the tile */
- for (y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) {
- pass= passrect;
- ap= aprect;
- apstrand= aprectstrand;
- od= offs;
-
- if (R.test_break(R.tbh))
- break;
-
- for (x=pa->disprect.xmin+crop; x<pa->disprect.xmax-crop; x++, ap++, apstrand++, pass+=4, od++) {
-
- if (ap->p[0]==0 && (!APixbufstrand || apstrand->p[0]==0)) {
- if (addpassflag & SCE_PASS_VECTOR)
- add_transp_speed(rl, od, NULL, 0.0f, rdrect);
- }
- else {
- /* sort in z */
- totface= 0;
- apn= ap;
- while (apn) {
- for (a=0; a<4; a++) {
- if (apn->p[a]) {
- zrow[totface].obi= apn->obi[a];
- zrow[totface].z= apn->z[a];
- zrow[totface].p= apn->p[a];
- zrow[totface].mask= apn->mask[a];
- zrow[totface].segment= -1;
- totface++;
- if (totface>=MAX_ZROW) totface= MAX_ZROW-1;
- }
- else break;
- }
- apn= apn->next;
- }
-
- apnstrand= (APixbufstrand)? apstrand: NULL;
- while (apnstrand) {
- for (a=0; a<4; a++) {
- if (apnstrand->p[a]) {
- zrow[totface].obi= apnstrand->obi[a];
- zrow[totface].z= apnstrand->z[a];
- zrow[totface].p= apnstrand->p[a];
- zrow[totface].mask= apnstrand->mask[a];
- zrow[totface].segment= apnstrand->seg[a];
-
- if (R.osa) {
- totsample= 0;
- for (b=0; b<R.osa; b++)
- if (zrow[totface].mask & (1<<b))
- totsample++;
- }
- else
- totsample= 1;
-
- zrow[totface].u= apnstrand->u[a]/totsample;
- zrow[totface].v= apnstrand->v[a]/totsample;
- totface++;
- if (totface>=MAX_ZROW) totface= MAX_ZROW-1;
- }
- }
- apnstrand= apnstrand->next;
- }
-
- if (totface==2) {
- if (zrow[0].z < zrow[1].z) {
- SWAP(ZTranspRow, zrow[0], zrow[1]);
- }
-
- }
- else if (totface>2) {
- qsort(zrow, totface, sizeof(ZTranspRow), vergzvlak);
- }
-
- /* front face does index pass for transparent, no AA or filters, but yes FSA */
- if (addpassflag & SCE_PASS_INDEXOB) {
- ObjectRen *obr= R.objectinstance[zrow[totface-1].obi].obr;
- if (obr->ob) {
- for (a= 0; a<totfullsample; a++)
- add_transp_obindex(rlpp[a], od, obr->ob);
- }
- }
- if (addpassflag & SCE_PASS_INDEXMA) {
- ObjectRen *obr = R.objectinstance[zrow[totface-1].obi].obr;
- int p = zrow[totface-1].p;
- Material *mat = NULL;
-
- if (zrow[totface-1].segment == -1) {
- int facenr = (p - 1) & RE_QUAD_MASK;
- VlakRen *vlr = NULL;
-
- if (facenr >= 0 && facenr < obr->totvlak)
- vlr = RE_findOrAddVlak(obr, facenr);
-
- if (vlr)
- mat = vlr->mat;
- }
- else {
- StrandRen *strand = RE_findOrAddStrand(obr, p - 1);
-
- if (strand)
- mat = strand->buffer->ma;
- }
-
- if (mat) {
- for (a= 0; a<totfullsample; a++)
- add_transp_material_index(rlpp[a], od, mat);
- }
- }
-
- /* for each mask-sample we alpha-under colors. then in end it's added using filter */
- memset(samp_shr, 0, sizeof(ShadeResult)*osa);
- for (a=0; a<osa; a++) {
- samp_shr[a].z= 10e10f;
- if (addpassflag & SCE_PASS_VECTOR) {
- samp_shr[a].winspeed[0]= PASS_VECTOR_MAX;
- samp_shr[a].winspeed[1]= PASS_VECTOR_MAX;
- samp_shr[a].winspeed[2]= PASS_VECTOR_MAX;
- samp_shr[a].winspeed[3]= PASS_VECTOR_MAX;
- }
- }
-
- if (R.osa==0) {
- while (totface>0) {
- totface--;
-
- if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) {
- filled= addtosamp_shr(samp_shr, &ssamp, addpassflag);
- addAlphaUnderFloat(pass, ssamp.shr[0].combined);
-
- if (filled == 0) {
- if (sscache)
- unref_strand_samples(sscache, zrow, totface);
- break;
- }
- }
- }
-
- alpha= samp_shr->combined[3];
- if (alpha!=0.0f) {
- add_transp_passes(rl, od, samp_shr, alpha);
- if (addpassflag & SCE_PASS_VECTOR)
- add_transp_speed(rl, od, samp_shr->winspeed, alpha, rdrect);
- }
- }
- else {
- short *sp= (short *)(ztramask+od);
-
- while (totface>0) {
- totface--;
-
- if (shade_tra_samples(&ssamp, sscache, x, y, &zrow[totface], addpassflag)) {
- filled= addtosamp_shr(samp_shr, &ssamp, addpassflag);
-
- if (ztramask)
- *sp |= zrow[totface].mask;
- if (filled==0) {
- if (sscache)
- unref_strand_samples(sscache, zrow, totface);
- break;
- }
- }
- }
-
- /* multisample buffers or filtered mask filling? */
- if (pa->fullresult.first) {
- for (a=0; a<R.osa; a++) {
- alpha= samp_shr[a].combined[3];
- if (alpha != 0.0f) {
- RenderLayer *rl_other = ssamp.rlpp[a];
-
- float *rect = RE_RenderLayerGetPass(rl_other , RE_PASSNAME_COMBINED, R.viewname);
- addAlphaOverFloat(rect + 4 * od, samp_shr[a].combined);
-
- add_transp_passes(rl_other , od, &samp_shr[a], alpha);
- if (addpassflag & SCE_PASS_VECTOR)
- add_transp_speed(rl_other , od, samp_shr[a].winspeed, alpha, rdrect);
- }
- }
- }
- else {
- alpha= 0.0f;
-
- /* note; cannot use pass[3] for alpha due to filtermask */
- for (a=0; a<R.osa; a++) {
- add_filt_fmask(1<<a, samp_shr[a].combined, pass, rr->rectx);
- alpha+= samp_shr[a].combined[3];
- }
-
- if (addpassflag) {
- alpha*= sampalpha;
-
- /* merge all in one, and then add */
- merge_transp_passes(rl, samp_shr);
- add_transp_passes(rl, od, samp_shr, alpha);
-
- if (addpassflag & SCE_PASS_VECTOR)
- add_transp_speed(rl, od, samp_shr[0].winspeed, alpha, rdrect);
- }
- }
- }
- }
- }
-
- aprect+= pa->rectx;
- aprectstrand+= pa->rectx;
- passrect+= 4*pa->rectx;
- offs+= pa->rectx;
- }
-
- /* disable scanline updating */
- rr->renlay= NULL;
-
- MEM_freeN(APixbuf);
- if (APixbufstrand)
- MEM_freeN(APixbufstrand);
- if (sscache)
- strand_shade_cache_free(sscache);
- freepsA(&apsmbase);
-
- if (R.r.mode & R_SHADOW)
- ISB_free(pa);
-
- return ztramask;
-}
-
-
/* end of zbuf.c */
diff --git a/source/blender/windowmanager/CMakeLists.txt b/source/blender/windowmanager/CMakeLists.txt
index 50f99251489..d74cf15d78b 100644
--- a/source/blender/windowmanager/CMakeLists.txt
+++ b/source/blender/windowmanager/CMakeLists.txt
@@ -25,20 +25,23 @@
set(INC
.
+ manipulators
+ manipulators/intern
../blenfont
../blenkernel
../blenlib
../blenloader
../blentranslation
../compositor
+ ../depsgraph
../editors/include
+ ../draw
../gpu
../imbuf
../makesdna
../makesrna
../nodes
../render/extern/include
- ../../gameengine/BlenderRoutines
../../../intern/clog
../../../intern/ghost
../../../intern/guardedalloc
@@ -68,9 +71,19 @@ set(SRC
intern/wm_operator_props.c
intern/wm_operators.c
intern/wm_subwindow.c
- intern/wm_tooltip.c
intern/wm_window.c
intern/wm_stereo.c
+ intern/wm_toolsystem.c
+ intern/wm_tooltip.c
+ manipulators/intern/wm_manipulator.c
+ manipulators/intern/wm_manipulator_group.c
+ manipulators/intern/wm_manipulator_group_type.c
+ manipulators/intern/wm_manipulator_map.c
+ manipulators/intern/wm_manipulator_target_props.c
+ manipulators/intern/wm_manipulator_type.c
+ message_bus/intern/wm_message_bus.c
+ message_bus/intern/wm_message_bus_rna.c
+ message_bus/intern/wm_message_bus_static.c
WM_api.h
WM_keymap.h
@@ -81,12 +94,18 @@ set(SRC
wm_event_system.h
wm_event_types.h
wm_files.h
- wm_subwindow.h
wm_window.h
+ manipulators/WM_manipulator_api.h
+ manipulators/WM_manipulator_types.h
+ manipulators/wm_manipulator_fn.h
+ manipulators/wm_manipulator_wmapi.h
+ manipulators/intern/wm_manipulator_intern.h
+ message_bus/intern/wm_message_bus_intern.h
+ message_bus/wm_message_bus.h
)
if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
+ add_definitions(-DWITH_AUDASPACE)
list(APPEND INC_SYS
${AUDASPACE_C_INCLUDE_DIRS}
@@ -123,10 +142,6 @@ if(WITH_PYTHON)
add_definitions(-DWITH_PYTHON)
endif()
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
if(WITH_BUILDINFO)
add_definitions(-DWITH_BUILDINFO)
endif()
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index bf26d512589..31c30388560 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -64,12 +64,20 @@ struct wmDrag;
struct ImBuf;
struct ImageFormatData;
struct ARegion;
+struct ScrArea;
+struct Main;
+struct bToolDef;
+struct ViewLayer;
+struct GPUViewport;
#ifdef WITH_INPUT_NDOF
struct wmNDOFMotionData;
#endif
typedef struct wmJob wmJob;
+typedef struct wmManipulator wmManipulator;
+typedef struct wmManipulatorMap wmManipulatorMap;
+typedef struct wmManipulatorMapType wmManipulatorMapType;
/* general API */
void WM_init_state_size_set (int stax, int stay, int sizx, int sizy);
@@ -84,15 +92,42 @@ void WM_exit (struct bContext *C) ATTR_NORETURN;
void WM_main (struct bContext *C) ATTR_NORETURN;
-bool WM_init_game (struct bContext *C);
void WM_init_splash (struct bContext *C);
+void WM_init_opengl (void);
void WM_check (struct bContext *C);
-int WM_window_pixels_x (struct wmWindow *win);
-int WM_window_pixels_y (struct wmWindow *win);
-bool WM_window_is_fullscreen (struct wmWindow *win);
+int WM_window_pixels_x(const struct wmWindow *win);
+int WM_window_pixels_y(const struct wmWindow *win);
+int WM_window_screen_pixels_x(const struct wmWindow *win);
+int WM_window_screen_pixels_y(const struct wmWindow *win);
+bool WM_window_is_fullscreen(struct wmWindow *win);
+
+void WM_windows_scene_data_sync(const ListBase *win_lb, struct Scene *scene) ATTR_NONNULL();
+struct Scene *WM_windows_scene_get_from_screen(const struct wmWindowManager *wm, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+struct WorkSpace *WM_windows_workspace_get_from_screen(const wmWindowManager *wm, const struct bScreen *screen) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+
+struct Scene *WM_window_get_active_scene(const struct wmWindow *win) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void WM_window_change_active_scene(struct Main *bmain, struct bContext *C, struct wmWindow *win,
+ struct Scene *scene_new) ATTR_NONNULL();
+struct WorkSpace *WM_window_get_active_workspace(const struct wmWindow *win) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void WM_window_set_active_workspace(struct wmWindow *win, struct WorkSpace *workspace) ATTR_NONNULL(1);
+struct WorkSpaceLayout *WM_window_get_active_layout(const struct wmWindow *win) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void WM_window_set_active_layout(
+ struct wmWindow *win, struct WorkSpace *workspace, struct WorkSpaceLayout *layout) ATTR_NONNULL(1);
+struct bScreen *WM_window_get_active_screen(const struct wmWindow *win) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void WM_window_set_active_screen(struct wmWindow *win, struct WorkSpace *workspace, struct bScreen *screen) ATTR_NONNULL(1);
+
+struct ViewLayer *WM_window_get_active_view_layer_ex(const struct wmWindow *win, struct Scene **r_scene) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
+struct ViewLayer *WM_window_get_active_view_layer(const struct wmWindow *win) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT;
+
+bool WM_window_is_temp_screen(const struct wmWindow *win) ATTR_WARN_UNUSED_RESULT;
+
+void *WM_opengl_context_create(void);
+void WM_opengl_context_dispose(void *context);
+void WM_opengl_context_activate(void *context);
+void WM_opengl_context_release(void *context);
/* defines for 'type' WM_window_open_temp */
enum {
@@ -105,9 +140,6 @@ struct wmWindow *WM_window_open(struct bContext *C, const struct rcti *rect);
struct wmWindow *WM_window_open_temp(struct bContext *C, int x, int y, int sizex, int sizey, int type);
void WM_window_set_dpi(wmWindow *win);
- /* returns true if draw method is triple buffer */
-bool WM_is_draw_triple(struct wmWindow *win);
-
bool WM_stereo3d_enabled(struct wmWindow *win, bool only_fullscreen_test);
@@ -143,6 +175,7 @@ float WM_cursor_pressure (const struct wmWindow *win);
/* event map */
int WM_userdef_event_map(int kmitype);
+int WM_userdef_event_type_from_keymap_type(int kmitype);
/* handlers */
@@ -172,6 +205,9 @@ void WM_event_free_ui_handler_all(
wmUIHandlerFunc ui_handle, wmUIHandlerRemoveFunc ui_remove);
struct wmEventHandler *WM_event_add_modal_handler(struct bContext *C, struct wmOperator *op);
+void WM_event_modal_handler_area_replace(wmWindow *win, const struct ScrArea *old_area, struct ScrArea *new_area);
+void WM_event_modal_handler_region_replace(wmWindow *win, const struct ARegion *old_region, struct ARegion *new_region);
+
void WM_event_remove_handlers(struct bContext *C, ListBase *handlers);
/* handler flag */
@@ -230,6 +266,7 @@ int WM_operator_smooth_viewtx_get(const struct wmOperator *op);
int WM_menu_invoke_ex(struct bContext *C, struct wmOperator *op, int opcontext);
int WM_menu_invoke (struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
void WM_menu_name_call(struct bContext *C, const char *menu_name, short context);
+int WM_enum_search_invoke_previews(struct bContext *C, struct wmOperator *op, short prv_cols, short prv_rows);
int WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
/* invoke callback, confirm menu + exec */
int WM_operator_confirm (struct bContext *C, struct wmOperator *op, const struct wmEvent *event);
@@ -267,6 +304,14 @@ void WM_operatortype_append_macro_ptr(void (*opfunc)(struct wmOperatorType *, v
void WM_operatortype_remove_ptr(struct wmOperatorType *ot);
bool WM_operatortype_remove(const char *idname);
void WM_operatortype_last_properties_clear_all(void);
+void WM_operatortype_props_advanced_begin(struct wmOperatorType *ot);
+void WM_operatortype_props_advanced_end(struct wmOperatorType *ot);
+
+#define WM_operatortype_prop_tag(property, tags) \
+ { \
+ CHECK_TYPE(tags, eOperatorPropTags); \
+ RNA_def_property_tags(prop, tags); \
+ } (void)0
struct wmOperatorType *WM_operatortype_append_macro(const char *idname, const char *name, const char *description, int flag);
struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *ot, const char *idname);
@@ -293,7 +338,11 @@ void WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperato
void WM_operator_properties_clear(struct PointerRNA *ptr);
void WM_operator_properties_free(struct PointerRNA *ptr);
+bool WM_operator_check_ui_empty(struct wmOperatorType *ot);
bool WM_operator_check_ui_enabled(const struct bContext *C, const char *idname);
+
+IDProperty *WM_operator_last_properties_ensure_idprops(struct wmOperatorType *ot);
+void WM_operator_last_properties_ensure(struct wmOperatorType *ot, struct PointerRNA *ptr);
wmOperator *WM_operator_last_redo(const struct bContext *C);
ID *WM_operator_drop_load_path(struct bContext *C, struct wmOperator *op, const short idcode);
@@ -420,17 +469,17 @@ struct wmDropBox *WM_dropbox_add(ListBase *lb, const char *idname, int (*poll)(s
void (*copy)(struct wmDrag *, struct wmDropBox *));
ListBase *WM_dropboxmap_find(const char *idname, int spaceid, int regionid);
- /* Set a subwindow active in pixelspace view, with optional scissor subset */
-void wmSubWindowSet (struct wmWindow *win, int swinid);
-void wmSubWindowScissorSet (struct wmWindow *win, int swinid, const struct rcti *srct, bool srct_pad);
+ /* Set OpenGL viewport and scissor */
+void wmViewport(const struct rcti *rect);
+void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct);
+void wmWindowViewport(struct wmWindow *win);
- /* OpenGL utilities with safety check + working in modelview matrix mode */
-void wmFrustum (float x1, float x2, float y1, float y2, float n, float f);
-void wmOrtho (float x1, float x2, float y1, float y2, float n, float f);
+ /* OpenGL utilities with safety check */
void wmOrtho2 (float x1, float x2, float y1, float y2);
/* use for conventions (avoid hard-coded offsets all over) */
void wmOrtho2_region_pixelspace(const struct ARegion *ar);
void wmOrtho2_pixelspace(const float x, const float y);
+void wmGetProjectionMatrix(float mat[4][4], const struct rcti *winrct);
/* threaded Jobs Manager */
enum {
@@ -461,6 +510,7 @@ enum {
WM_JOB_TYPE_POINTCACHE,
WM_JOB_TYPE_DPAINT_BAKE,
WM_JOB_TYPE_ALEMBIC,
+ WM_JOB_TYPE_SHADER_COMPILATION,
/* add as needed, screencast, seq proxy build
* if having hard coded values is a problem */
};
@@ -509,11 +559,16 @@ void WM_progress_clear(struct wmWindow *win);
/* Draw (for screenshot) */
void *WM_draw_cb_activate(
struct wmWindow *win,
- void(*draw)(const struct wmWindow *, void *),
+ void (*draw)(const struct wmWindow *, void *),
void *customdata);
void WM_draw_cb_exit(struct wmWindow *win, void *handle);
void WM_redraw_windows(struct bContext *C);
+ /* Region drawing */
+void WM_draw_region_free(struct ARegion *ar);
+struct GPUViewport *WM_draw_region_get_viewport(struct ARegion *ar, int view);
+struct GPUViewport *WM_draw_region_get_bound_viewport(struct ARegion *ar);
+
void WM_main_playanim(int argc, const char **argv);
/* debugging only, convenience function to write on crash */
@@ -537,6 +592,15 @@ bool WM_event_is_tablet(const struct wmEvent *event);
bool WM_event_is_ime_switch(const struct wmEvent *event);
#endif
+/* wm_toolsystem.c */
+void WM_toolsystem_unlink(struct bContext *C, struct WorkSpace *workspace);
+void WM_toolsystem_link(struct bContext *C, struct WorkSpace *workspace);
+
+void WM_toolsystem_set(struct bContext *C, const struct bToolDef *tool);
+void WM_toolsystem_init(struct bContext *C);
+
+bool WM_toolsystem_active_tool_is_brush(const struct bContext *C);
+
/* wm_tooltip.c */
typedef struct ARegion *(*wmTooltipInitFn)(struct bContext *, struct ARegion *, bool *);
diff --git a/source/blender/windowmanager/WM_message.h b/source/blender/windowmanager/WM_message.h
new file mode 100644
index 00000000000..48197ae99cd
--- /dev/null
+++ b/source/blender/windowmanager/WM_message.h
@@ -0,0 +1,30 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/WM_message.h
+ * \ingroup wm
+ */
+
+#ifndef __WM_MESSAGE_H__
+#define __WM_MESSAGE_H__
+
+#include "message_bus/wm_message_bus.h"
+
+#endif /* __WM_MESSAGE_H__ */
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index 8c94c2ff043..bbd12ddfb0a 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -109,16 +109,22 @@ extern "C" {
struct bContext;
struct wmEvent;
struct wmWindowManager;
+struct wmMsgBus;
struct wmOperator;
struct ImBuf;
#include "RNA_types.h"
#include "DNA_listBase.h"
+#include "DNA_vec_types.h"
#include "BLI_compiler_attrs.h"
/* exported types for WM */
#include "wm_cursors.h"
#include "wm_event_types.h"
+#include "manipulators/WM_manipulator_types.h"
+
+/* Include external manipulator API's */
+#include "manipulators/WM_manipulator_api.h"
/* ************** wmOperatorType ************************ */
@@ -160,6 +166,12 @@ enum {
WM_OP_EXEC_SCREEN
};
+/* property tags for RNA_OperatorProperties */
+typedef enum eOperatorPropTags {
+ OP_PROP_TAG_ADVANCED = (1 << 0),
+} eOperatorPropTags;
+#define OP_PROP_TAG_ADVANCED ((eOperatorPropTags)OP_PROP_TAG_ADVANCED)
+
/* ************** wmKeyMap ************************ */
/* modifier */
@@ -203,7 +215,6 @@ typedef struct wmNotifier {
struct wmWindowManager *wm;
struct wmWindow *window;
- int swinid; /* can't rely on this, notifiers can be added without context, swinid of 0 */
unsigned int category, data, subtype, action;
void *reference;
@@ -223,7 +234,7 @@ typedef struct wmNotifier {
#define NOTE_CATEGORY 0xFF000000
#define NC_WM (1<<24)
#define NC_WINDOW (2<<24)
-#define NC_SCREEN (3<<24)
+#define NC_SCREEN (3<<24)
#define NC_SCENE (4<<24)
#define NC_OBJECT (5<<24)
#define NC_MATERIAL (6<<24)
@@ -257,15 +268,17 @@ typedef struct wmNotifier {
#define ND_JOB (5<<16)
#define ND_UNDO (6<<16)
- /* NC_SCREEN screen */
-#define ND_SCREENBROWSE (1<<16)
-#define ND_SCREENDELETE (2<<16)
+ /* NC_SCREEN */
+#define ND_LAYOUTBROWSE (1<<16)
+#define ND_LAYOUTDELETE (2<<16)
#define ND_SCREENCAST (3<<16)
#define ND_ANIMPLAY (4<<16)
#define ND_GPENCIL (5<<16)
#define ND_EDITOR_CHANGED (6<<16) /*sent to new editors after switching to them*/
-#define ND_SCREENSET (7<<16)
+#define ND_LAYOUTSET (7<<16)
#define ND_SKETCH (8<<16)
+#define ND_WORKSPACE_SET (9<<16)
+#define ND_WORKSPACE_DELETE (10<<16)
/* NC_SCENE Scene */
#define ND_SCENEBROWSE (1<<16)
@@ -410,7 +423,7 @@ typedef struct wmGesture {
struct wmGesture *next, *prev;
int event_type; /* event->type */
int type; /* gesture type define */
- int swinid; /* initial subwindow id where it started */
+ rcti winrct; /* bounds of region to draw gesture within */
int points; /* optional, amount of points stored */
int points_alloc; /* optional, maximum amount of points stored */
int modal_state;
@@ -726,6 +739,7 @@ extern struct CLG_LogRef *WM_LOG_OPERATORS;
extern struct CLG_LogRef *WM_LOG_HANDLERS;
extern struct CLG_LogRef *WM_LOG_EVENTS;
extern struct CLG_LogRef *WM_LOG_KEYMAPS;
+extern struct CLG_LogRef *WM_LOG_TOOLS;
#ifdef __cplusplus
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 8be7555b34a..a0ad3950e6b 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -52,9 +52,11 @@
#include "BKE_screen.h"
#include "BKE_report.h"
#include "BKE_global.h"
+#include "BKE_workspace.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "wm_window.h"
#include "wm_event_system.h"
#include "wm_draw.h"
@@ -163,6 +165,9 @@ void wm_operator_register(bContext *C, wmOperator *op)
wmWindowManager *wm = CTX_wm_manager(C);
int tot = 0;
+ op->execution_area = CTX_wm_area(C);
+ op->execution_region = CTX_wm_region(C);
+
BLI_addtail(&wm->operators, op);
/* only count registered operators */
@@ -340,6 +345,14 @@ void WM_menutype_free(void)
bool WM_menutype_poll(bContext *C, MenuType *mt)
{
+ /* If we're tagged, only use compatible. */
+ if (mt->owner_id[0] != '\0') {
+ const WorkSpace *workspace = CTX_wm_workspace(C);
+ if (BKE_workspace_owner_id_check(workspace, mt->owner_id) == false) {
+ return false;
+ }
+ }
+
if (mt->poll != NULL) {
return mt->poll(C, mt);
}
@@ -362,7 +375,7 @@ void WM_keymap_init(bContext *C)
/* initialize only after python init is done, for keymaps that
* use python operators */
- if (CTX_py_init_get(C) && (wm->initialized & WM_INIT_KEYMAP) == 0) {
+ if (CTX_py_init_get(C) && (wm->initialized & WM_KEYMAP_IS_INITIALIZED) == 0) {
/* create default key config, only initialize once,
* it's persistent across sessions */
if (!(wm->defaultconf->flag & KEYCONF_INIT_DEFAULT)) {
@@ -375,7 +388,7 @@ void WM_keymap_init(bContext *C)
WM_keyconfig_update_tag(NULL, NULL);
WM_keyconfig_update(wm);
- wm->initialized |= WM_INIT_KEYMAP;
+ wm->initialized |= WM_KEYMAP_IS_INITIALIZED;
}
}
@@ -395,7 +408,7 @@ void WM_check(bContext *C)
if (!G.background) {
/* case: fileread */
- if ((wm->initialized & WM_INIT_WINDOW) == 0) {
+ if ((wm->initialized & WM_WINDOW_IS_INITIALIZED) == 0) {
WM_keymap_init(C);
WM_autosave_init(wm);
}
@@ -404,11 +417,15 @@ void WM_check(bContext *C)
wm_window_ghostwindows_ensure(wm);
}
+ if (wm->message_bus == NULL) {
+ wm->message_bus = WM_msgbus_create();
+ }
+
/* case: fileread */
/* note: this runs in bg mode to set the screen context cb */
- if ((wm->initialized & WM_INIT_WINDOW) == 0) {
+ if ((wm->initialized & WM_WINDOW_IS_INITIALIZED) == 0) {
ED_screens_initialize(wm);
- wm->initialized |= WM_INIT_WINDOW;
+ wm->initialized |= WM_WINDOW_IS_INITIALIZED;
}
}
@@ -437,21 +454,24 @@ void wm_clear_default_size(bContext *C)
}
/* on startup, it adds all data, for matching */
-void wm_add_default(bContext *C)
+void wm_add_default(Main *bmain, bContext *C)
{
- wmWindowManager *wm = BKE_libblock_alloc(CTX_data_main(C), ID_WM, "WinMan", 0);
+ wmWindowManager *wm = BKE_libblock_alloc(bmain, ID_WM, "WinMan", 0);
wmWindow *win;
bScreen *screen = CTX_wm_screen(C); /* XXX from file read hrmf */
-
+ WorkSpace *workspace;
+ WorkSpaceLayout *layout = BKE_workspace_layout_find_global(bmain, screen, &workspace);
+
CTX_wm_manager_set(C, wm);
win = wm_window_new(C);
- win->screen = screen;
+ win->scene = CTX_data_scene(C);
+ WM_window_set_active_workspace(win, workspace);
+ WM_window_set_active_layout(win, workspace, layout);
screen->winid = win->winid;
- BLI_strncpy(win->screenname, screen->id.name + 2, sizeof(win->screenname));
-
+
wm->winactive = win;
wm->file_saved = 1;
- wm_window_make_drawable(wm, win);
+ wm_window_make_drawable(wm, win);
}
@@ -466,8 +486,7 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
wm_autosave_timer_ended(wm);
while ((win = BLI_pophead(&wm->windows))) {
- win->screen = NULL; /* prevent draw clear to use screen */
- wm_draw_window_clear(win);
+ WM_window_set_active_workspace(win, NULL); /* prevent draw clear to use screen */
wm_window_free(C, wm, win);
}
@@ -480,7 +499,11 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
}
BLI_freelistN(&wm->queue);
-
+
+ if (wm->message_bus != NULL) {
+ WM_msgbus_destroy(wm->message_bus);
+ }
+
BLI_freelistN(&wm->paintcursors);
WM_drag_free_list(&wm->drags);
diff --git a/source/blender/windowmanager/intern/wm_dragdrop.c b/source/blender/windowmanager/intern/wm_dragdrop.c
index dd01efdb4c4..05d9689565c 100644
--- a/source/blender/windowmanager/intern/wm_dragdrop.c
+++ b/source/blender/windowmanager/intern/wm_dragdrop.c
@@ -46,6 +46,8 @@
#include "BKE_context.h"
+#include "GPU_shader.h"
+
#include "IMB_imbuf_types.h"
#include "UI_interface.h"
@@ -268,10 +270,10 @@ void wm_drags_check_ops(bContext *C, const wmEvent *event)
static void wm_drop_operator_draw(const char *name, int x, int y)
{
const uiFontStyle *fstyle = UI_FSTYLE_WIDGET;
- const unsigned char fg[4] = {255, 255, 255, 255};
- const unsigned char bg[4] = {0, 0, 0, 50};
+ const float col_fg[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+ const float col_bg[4] = {0.0f, 0.0f, 0.0f, 0.2f};
- UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, fg, bg);
+ UI_fontstyle_draw_simple_backdrop(fstyle, x, y, name, col_fg, col_bg);
}
static const char *wm_drag_name(wmDrag *drag)
@@ -332,8 +334,10 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
if (rect)
drag_rect_minmax(rect, x, y, x + drag->sx, y + drag->sy);
else {
- glColor4f(1.0, 1.0, 1.0, 0.65); /* this blends texture */
- glaDrawPixelsTexScaled(x, y, drag->imb->x, drag->imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST, drag->imb->rect, drag->scale, drag->scale);
+ float col[4] = {1.0f, 1.0f, 1.0f, 0.65f}; /* this blends texture */
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
+ immDrawPixelsTexScaled(&state, x, y, drag->imb->x, drag->imb->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
+ drag->imb->rect, drag->scale, drag->scale, 1.0f, 1.0f, col);
}
}
else {
@@ -361,8 +365,8 @@ void wm_drags_draw(bContext *C, wmWindow *win, rcti *rect)
drag_rect_minmax(rect, x, y, x + w, y + iconsize);
}
else {
- glColor4ub(255, 255, 255, 255);
- UI_fontstyle_draw_simple(fstyle, x, y, wm_drag_name(drag));
+ const unsigned char col[] = {255, 255, 255, 255};
+ UI_fontstyle_draw_simple(fstyle, x, y, wm_drag_name(drag), col);
}
/* operator name with roundbox */
diff --git a/source/blender/windowmanager/intern/wm_draw.c b/source/blender/windowmanager/intern/wm_draw.c
index e1f21699057..55e7ce4a1d8 100644
--- a/source/blender/windowmanager/intern/wm_draw.c
+++ b/source/blender/windowmanager/intern/wm_draw.c
@@ -34,6 +34,8 @@
#include <string.h>
#include "DNA_listBase.h"
+#include "DNA_object_types.h"
+#include "DNA_camera_types.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
#include "DNA_userdef_types.h"
@@ -48,6 +50,9 @@
#include "BKE_context.h"
#include "BKE_image.h"
+#include "BKE_screen.h"
+#include "BKE_scene.h"
+#include "BKE_workspace.h"
#include "GHOST_C-api.h"
@@ -57,8 +62,11 @@
#include "GPU_draw.h"
#include "GPU_extensions.h"
-#include "GPU_glew.h"
-#include "GPU_basic_shader.h"
+#include "GPU_framebuffer.h"
+#include "GPU_immediate.h"
+#include "GPU_matrix.h"
+#include "GPU_texture.h"
+#include "GPU_viewport.h"
#include "RE_engine.h"
@@ -73,87 +81,131 @@
# include "BKE_subsurf.h"
#endif
-/* swap */
-#define WIN_NONE_OK 0
-#define WIN_BACK_OK 1
-#define WIN_FRONT_OK 2
-#define WIN_BOTH_OK 3
-
-/* ******************* drawing, overlays *************** */
+/* ******************* paint cursor *************** */
static void wm_paintcursor_draw(bContext *C, ARegion *ar)
{
wmWindowManager *wm = CTX_wm_manager(C);
-
- if (wm->paintcursors.first) {
- wmWindow *win = CTX_wm_window(C);
- bScreen *screen = win->screen;
- wmPaintCursor *pc;
-
- if (ar->swinid && screen->subwinactive == ar->swinid) {
- for (pc = wm->paintcursors.first; pc; pc = pc->next) {
- if (pc->poll == NULL || pc->poll(C)) {
- ARegion *ar_other = CTX_wm_region(C);
- if (ELEM(win->grabcursor, GHOST_kGrabWrap, GHOST_kGrabHide)) {
- int x = 0, y = 0;
- wm_get_cursor_position(win, &x, &y);
- pc->draw(C,
- x - ar_other->winrct.xmin,
- y - ar_other->winrct.ymin,
- pc->customdata);
- }
- else {
- pc->draw(C,
- win->eventstate->x - ar_other->winrct.xmin,
- win->eventstate->y - ar_other->winrct.ymin,
- pc->customdata);
- }
+ wmWindow *win = CTX_wm_window(C);
+ bScreen *screen = WM_window_get_active_screen(win);
+ wmPaintCursor *pc;
+
+ if (ar->visible && ar == screen->active_region) {
+ for (pc = wm->paintcursors.first; pc; pc = pc->next) {
+ if (pc->poll == NULL || pc->poll(C)) {
+ /* Prevent drawing outside region. */
+ GLint scissor[4];
+ glGetIntegerv(GL_SCISSOR_BOX, scissor);
+ glScissor(ar->winrct.xmin,
+ ar->winrct.ymin,
+ BLI_rcti_size_x(&ar->winrct) + 1,
+ BLI_rcti_size_y(&ar->winrct) + 1);
+
+ if (ELEM(win->grabcursor, GHOST_kGrabWrap, GHOST_kGrabHide)) {
+ int x = 0, y = 0;
+ wm_get_cursor_position(win, &x, &y);
+ pc->draw(C, x, y, pc->customdata);
}
+ else {
+ pc->draw(C, win->eventstate->x, win->eventstate->y, pc->customdata);
+ }
+
+ glScissor(scissor[0], scissor[1], scissor[2], scissor[3]);
}
}
}
}
-/* ********************* drawing, swap ****************** */
-static void wm_area_mark_invalid_backbuf(ScrArea *sa)
+static bool wm_draw_region_stereo_set(ScrArea *sa, ARegion *ar, eStereoViews sview)
{
- if (sa->spacetype == SPACE_VIEW3D)
- ((View3D *)sa->spacedata.first)->flag |= V3D_INVALID_BACKBUF;
+ /* We could detect better when stereo is actually needed, by inspecting the
+ * image in the image editor and sequencer. */
+ if (ar->regiontype != RGN_TYPE_WINDOW) {
+ return false;
+ }
+
+ switch (sa->spacetype) {
+ case SPACE_IMAGE:
+ {
+ SpaceImage *sima = sa->spacedata.first;
+ sima->iuser.multiview_eye = sview;
+ return true;
+ }
+ case SPACE_VIEW3D:
+ {
+ View3D *v3d = sa->spacedata.first;
+ if (v3d->camera && v3d->camera->type == OB_CAMERA) {
+ Camera *cam = v3d->camera->data;
+ CameraBGImage *bgpic = cam->bg_images.first;
+ v3d->multiview_eye = sview;
+ if (bgpic) bgpic->iuser.multiview_eye = sview;
+ return true;
+ }
+ return false;
+ }
+ case SPACE_NODE:
+ {
+ SpaceNode *snode = sa->spacedata.first;
+ if ((snode->flag & SNODE_BACKDRAW) && ED_node_is_compositor(snode)) {
+ Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
+ ima->eye = sview;
+ return true;
+ }
+ return false;
+ }
+ case SPACE_SEQ:
+ {
+ SpaceSeq *sseq = sa->spacedata.first;
+ sseq->multiview_eye = sview;
+ return true;
+ }
+ }
+
+ return false;
}
-static bool wm_area_test_invalid_backbuf(ScrArea *sa)
+/* ********************* drawing ****************** */
+
+static void wm_area_mark_invalid_backbuf(ScrArea *sa)
{
if (sa->spacetype == SPACE_VIEW3D)
- return (((View3D *)sa->spacedata.first)->flag & V3D_INVALID_BACKBUF) != 0;
- else
- return true;
+ ((View3D *)sa->spacedata.first)->flag |= V3D_INVALID_BACKBUF;
}
-static void wm_region_test_render_do_draw(const bScreen *screen, ScrArea *sa, ARegion *ar)
+static void wm_region_test_render_do_draw(const Scene *scene, struct Depsgraph *depsgraph,
+ ScrArea *sa, ARegion *ar)
{
/* tag region for redraw from render engine preview running inside of it */
- if (sa->spacetype == SPACE_VIEW3D) {
+ if (sa->spacetype == SPACE_VIEW3D && ar->regiontype == RGN_TYPE_WINDOW) {
RegionView3D *rv3d = ar->regiondata;
- RenderEngine *engine = (rv3d) ? rv3d->render_engine : NULL;
+ RenderEngine *engine = rv3d->render_engine;
+ GPUViewport *viewport = WM_draw_region_get_viewport(ar, 0);
if (engine && (engine->flag & RE_ENGINE_DO_DRAW)) {
- Scene *scene = screen->scene;
View3D *v3d = sa->spacedata.first;
rcti border_rect;
/* do partial redraw when possible */
- if (ED_view3d_calc_render_border(scene, v3d, ar, &border_rect))
+ if (ED_view3d_calc_render_border(scene, depsgraph, v3d, ar, &border_rect))
ED_region_tag_redraw_partial(ar, &border_rect);
else
ED_region_tag_redraw(ar);
engine->flag &= ~RE_ENGINE_DO_DRAW;
}
+ else if (viewport && GPU_viewport_do_update(viewport)) {
+ ED_region_tag_redraw(ar);
+ }
}
}
+static bool wm_region_use_viewport(ScrArea *sa, ARegion *ar)
+{
+ return (sa->spacetype == SPACE_VIEW3D && ar->regiontype == RGN_TYPE_WINDOW);
+}
+
/********************** draw all **************************/
/* - reference method, draw all each time */
@@ -197,612 +249,368 @@ static void wm_draw_callbacks(wmWindow *win)
}
}
-static void wm_method_draw_full(bContext *C, wmWindow *win)
-{
- bScreen *screen = win->screen;
- ScrArea *sa;
- ARegion *ar;
- /* draw area regions */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- CTX_wm_area_set(C, sa);
+/************************* Region drawing. ********************************
+ *
+ * Each region draws into its own framebuffer, which is then blit on the
+ * window draw buffer. This helps with fast redrawing if only some regions
+ * change. It also means we can share a single context for multiple windows,
+ * so that for example VAOs can be shared between windows. */
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid) {
- CTX_wm_region_set(C, ar);
- ED_region_do_draw(C, ar);
- ar->do_draw = false;
- wm_paintcursor_draw(C, ar);
- CTX_wm_region_set(C, NULL);
+static void wm_draw_region_buffer_free(ARegion *ar)
+{
+ if (ar->draw_buffer) {
+ for (int view = 0; view < 2; view++) {
+ if (ar->draw_buffer->offscreen[view]) {
+ GPU_offscreen_free(ar->draw_buffer->offscreen[view]);
+ }
+ if (ar->draw_buffer->viewport[view]) {
+ GPU_viewport_free(ar->draw_buffer->viewport[view]);
}
}
-
- wm_area_mark_invalid_backbuf(sa);
- CTX_wm_area_set(C, NULL);
- }
- ED_screen_draw_edges(win);
- screen->do_draw = false;
- wm_draw_callbacks(win);
-
- /* draw overlapping regions */
- for (ar = screen->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid) {
- CTX_wm_menu_set(C, ar);
- ED_region_do_draw(C, ar);
- ar->do_draw = false;
- CTX_wm_menu_set(C, NULL);
- }
+ MEM_freeN(ar->draw_buffer);
+ ar->draw_buffer = NULL;
}
-
- if (screen->do_draw_gesture)
- wm_gesture_draw(win);
}
-/****************** draw overlap all **********************/
-/* - redraw marked areas, and anything that overlaps it */
-/* - it also handles swap exchange optionally, assuming */
-/* that on swap no clearing happens and we get back the */
-/* same buffer as we swapped to the front */
-
-/* mark area-regions to redraw if overlapped with rect */
-static void wm_flush_regions_down(bScreen *screen, rcti *dirty)
+static void wm_draw_offscreen_texture_parameters(GPUOffScreen *offscreen)
{
- ScrArea *sa;
- ARegion *ar;
+ /* Setup offscreen color texture for drawing. */
+ GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (BLI_rcti_isect(dirty, &ar->winrct, NULL)) {
- ar->do_draw = RGN_DRAW;
- memset(&ar->drawrct, 0, sizeof(ar->drawrct));
- ar->swap = WIN_NONE_OK;
- }
- }
- }
+ /* We don't support multisample textures here. */
+ BLI_assert(GPU_texture_target(texture) == GL_TEXTURE_2D);
+
+ glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(texture));
+
+ /* No mipmaps or filtering. */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
+ /* GL_TEXTURE_BASE_LEVEL = 0 by default */
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
+
+ glBindTexture(GL_TEXTURE_2D, 0);
}
-/* mark menu-regions to redraw if overlapped with rect */
-static void wm_flush_regions_up(bScreen *screen, rcti *dirty)
+static void wm_draw_region_buffer_create(ARegion *ar, bool stereo, bool use_viewport)
{
- ARegion *ar;
-
- for (ar = screen->regionbase.first; ar; ar = ar->next) {
- if (BLI_rcti_isect(dirty, &ar->winrct, NULL)) {
- ar->do_draw = RGN_DRAW;
- memset(&ar->drawrct, 0, sizeof(ar->drawrct));
- ar->swap = WIN_NONE_OK;
+ if (ar->draw_buffer) {
+ if (ar->draw_buffer->stereo != stereo) {
+ /* Free draw buffer on stereo changes. */
+ wm_draw_region_buffer_free(ar);
+ }
+ else {
+ /* Free offscreen buffer on size changes. Viewport auto resizes. */
+ GPUOffScreen *offscreen = ar->draw_buffer->offscreen[0];
+ if (offscreen && (GPU_offscreen_width(offscreen) != ar->winx ||
+ GPU_offscreen_height(offscreen) != ar->winy))
+ {
+ wm_draw_region_buffer_free(ar);
+ }
}
}
-}
-
-static void wm_method_draw_overlap_all(bContext *C, wmWindow *win, int exchange)
-{
- wmWindowManager *wm = CTX_wm_manager(C);
- bScreen *screen = win->screen;
- ScrArea *sa;
- ARegion *ar;
- static rcti rect = {0, 0, 0, 0};
- /* after backbuffer selection draw, we need to redraw */
- for (sa = screen->areabase.first; sa; sa = sa->next)
- for (ar = sa->regionbase.first; ar; ar = ar->next)
- if (ar->swinid && !wm_area_test_invalid_backbuf(sa))
- ED_region_tag_redraw(ar);
-
- /* flush overlapping regions */
- if (screen->regionbase.first) {
- /* flush redraws of area regions up to overlapping regions */
- for (sa = screen->areabase.first; sa; sa = sa->next)
- for (ar = sa->regionbase.first; ar; ar = ar->next)
- if (ar->swinid && ar->do_draw)
- wm_flush_regions_up(screen, &ar->winrct);
-
- /* flush between overlapping regions */
- for (ar = screen->regionbase.last; ar; ar = ar->prev)
- if (ar->swinid && ar->do_draw)
- wm_flush_regions_up(screen, &ar->winrct);
-
- /* flush redraws of overlapping regions down to area regions */
- for (ar = screen->regionbase.last; ar; ar = ar->prev)
- if (ar->swinid && ar->do_draw)
- wm_flush_regions_down(screen, &ar->winrct);
- }
+ if (!ar->draw_buffer) {
+ if (use_viewport) {
+ /* Allocate viewport which includes an offscreen buffer with depth
+ * multisample, etc. */
+ ar->draw_buffer = MEM_callocN(sizeof(wmDrawBuffer), "wmDrawBuffer");
+ ar->draw_buffer->viewport[0] = GPU_viewport_create();
+ ar->draw_buffer->viewport[1] = (stereo) ? GPU_viewport_create() : NULL;
+ }
+ else {
+ /* Allocate offscreen buffer if it does not exist. This one has no
+ * depth or multisample buffers. 3D view creates own buffers with
+ * the data it needs. */
+ GPUOffScreen *offscreen = GPU_offscreen_create(ar->winx, ar->winy, 0, false, false, NULL);
+ if (!offscreen) {
+ return;
+ }
- /* flush drag item */
- if (rect.xmin != rect.xmax) {
- wm_flush_regions_down(screen, &rect);
- rect.xmin = rect.xmax = 0;
- }
- if (wm->drags.first) {
- /* doesnt draw, fills rect with boundbox */
- wm_drags_draw(C, win, &rect);
- }
-
- /* draw marked area regions */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- CTX_wm_area_set(C, sa);
+ wm_draw_offscreen_texture_parameters(offscreen);
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid) {
- if (ar->do_draw) {
- CTX_wm_region_set(C, ar);
- ED_region_do_draw(C, ar);
- ar->do_draw = false;
- wm_paintcursor_draw(C, ar);
- CTX_wm_region_set(C, NULL);
+ GPUOffScreen *offscreen_right = NULL;
+ if (stereo) {
+ offscreen_right = GPU_offscreen_create(ar->winx, ar->winy, 0, false, false, NULL);
- if (exchange)
- ar->swap = WIN_FRONT_OK;
+ if (!offscreen_right) {
+ GPU_offscreen_free(offscreen);
+ return;
}
- else if (exchange) {
- if (ar->swap == WIN_FRONT_OK) {
- CTX_wm_region_set(C, ar);
- ED_region_do_draw(C, ar);
- ar->do_draw = false;
- wm_paintcursor_draw(C, ar);
- CTX_wm_region_set(C, NULL);
- ar->swap = WIN_BOTH_OK;
- }
- else if (ar->swap == WIN_BACK_OK)
- ar->swap = WIN_FRONT_OK;
- else if (ar->swap == WIN_BOTH_OK)
- ar->swap = WIN_BOTH_OK;
- }
+ wm_draw_offscreen_texture_parameters(offscreen_right);
}
- }
-
- wm_area_mark_invalid_backbuf(sa);
- CTX_wm_area_set(C, NULL);
- }
- /* after area regions so we can do area 'overlay' drawing */
- if (screen->do_draw) {
- ED_screen_draw_edges(win);
- screen->do_draw = false;
- wm_draw_callbacks(win);
-
- if (exchange)
- screen->swap = WIN_FRONT_OK;
- }
- else if (exchange) {
- if (screen->swap == WIN_FRONT_OK) {
- ED_screen_draw_edges(win);
- screen->do_draw = false;
- screen->swap = WIN_BOTH_OK;
- wm_draw_callbacks(win);
+ ar->draw_buffer = MEM_callocN(sizeof(wmDrawBuffer), "wmDrawBuffer");
+ ar->draw_buffer->offscreen[0] = offscreen;
+ ar->draw_buffer->offscreen[1] = offscreen_right;
}
- else if (screen->swap == WIN_BACK_OK)
- screen->swap = WIN_FRONT_OK;
- else if (screen->swap == WIN_BOTH_OK)
- screen->swap = WIN_BOTH_OK;
- }
- /* draw marked overlapping regions */
- for (ar = screen->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid && ar->do_draw) {
- CTX_wm_menu_set(C, ar);
- ED_region_do_draw(C, ar);
- ar->do_draw = false;
- CTX_wm_menu_set(C, NULL);
- }
- }
-
- if (screen->do_draw_gesture)
- wm_gesture_draw(win);
-
- /* needs pixel coords in screen */
- if (wm->drags.first) {
- wm_drags_draw(C, win, NULL);
+ ar->draw_buffer->bound_view = -1;
+ ar->draw_buffer->stereo = stereo;
}
}
-/****************** draw triple buffer ********************/
-/* - area regions are written into a texture, without any */
-/* of the overlapping menus, brushes, gestures. these */
-/* are redrawn each time. */
-
-static void wm_draw_triple_free(wmDrawTriple *triple)
+static void wm_draw_region_bind(ARegion *ar, int view)
{
- if (triple) {
- glDeleteTextures(1, &triple->bind);
- MEM_freeN(triple);
+ if (!ar->draw_buffer) {
+ return;
}
-}
-static void wm_draw_triple_fail(bContext *C, wmWindow *win)
-{
- wm_draw_window_clear(win);
+ if (ar->draw_buffer->viewport[view]) {
+ GPU_viewport_bind(ar->draw_buffer->viewport[view], &ar->winrct);
+ }
+ else {
+ GPU_offscreen_bind(ar->draw_buffer->offscreen[view], false);
+
+ /* For now scissor is expected by region drawing, we could disable it
+ * and do the enable/disable in the specific cases that setup scissor. */
+ glEnable(GL_SCISSOR_TEST);
+ glScissor(0, 0, ar->winx, ar->winy);
+ }
- win->drawfail = 1;
- wm_method_draw_overlap_all(C, win, 0);
+ ar->draw_buffer->bound_view = view;
}
-static int wm_triple_gen_textures(wmWindow *win, wmDrawTriple *triple)
+static void wm_draw_region_unbind(ARegion *ar, int view)
{
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
+ if (!ar->draw_buffer) {
+ return;
+ }
- GLint maxsize;
+ ar->draw_buffer->bound_view = -1;
- /* compute texture sizes */
- if (GLEW_ARB_texture_rectangle || GLEW_NV_texture_rectangle || GLEW_EXT_texture_rectangle) {
- triple->target = GL_TEXTURE_RECTANGLE_ARB;
+ if (ar->draw_buffer->viewport[view]) {
+ GPU_viewport_unbind(ar->draw_buffer->viewport[view]);
}
else {
- triple->target = GL_TEXTURE_2D;
+ glDisable(GL_SCISSOR_TEST);
+ GPU_offscreen_unbind(ar->draw_buffer->offscreen[view], false);
}
+}
- triple->x = winsize_x;
- triple->y = winsize_y;
-
- /* generate texture names */
- glGenTextures(1, &triple->bind);
-
- if (!triple->bind) {
- /* not the typical failure case but we handle it anyway */
- printf("WM: failed to allocate texture for triple buffer drawing (glGenTextures).\n");
- return 0;
+static void wm_draw_region_blit(ARegion *ar, int view)
+{
+ if (!ar->draw_buffer) {
+ return;
}
- /* proxy texture is only guaranteed to test for the cases that
- * there is only one texture in use, which may not be the case */
- maxsize = GPU_max_texture_size();
-
- if (triple->x > maxsize || triple->y > maxsize) {
- glBindTexture(triple->target, 0);
- printf("WM: failed to allocate texture for triple buffer drawing "
- "(texture too large for graphics card).\n");
- return 0;
+ if (ar->draw_buffer->viewport[view]) {
+ GPU_viewport_draw_to_screen(ar->draw_buffer->viewport[view], &ar->winrct);
}
-
- /* setup actual texture */
- glBindTexture(triple->target, triple->bind);
- glTexImage2D(triple->target, 0, GL_RGB8, triple->x, triple->y, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
- glTexParameteri(triple->target, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(triple->target, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glBindTexture(triple->target, 0);
-
- /* not sure if this works everywhere .. */
- if (glGetError() == GL_OUT_OF_MEMORY) {
- printf("WM: failed to allocate texture for triple buffer drawing (out of memory).\n");
- return 0;
+ else {
+ GPU_offscreen_draw_to_screen(ar->draw_buffer->offscreen[view], ar->winrct.xmin, ar->winrct.ymin);
}
-
- return 1;
}
-void wm_triple_draw_textures(wmWindow *win, wmDrawTriple *triple, float alpha, bool is_interlace)
+GPUTexture *wm_draw_region_texture(ARegion *ar, int view)
{
- const int sizex = WM_window_pixels_x(win);
- const int sizey = WM_window_pixels_y(win);
-
- float halfx, halfy, ratiox, ratioy;
-
- /* wmOrtho for the screen has this same offset */
- ratiox = sizex;
- ratioy = sizey;
- halfx = GLA_PIXEL_OFS;
- halfy = GLA_PIXEL_OFS;
-
- /* texture rectangle has unnormalized coordinates */
- if (triple->target == GL_TEXTURE_2D) {
- ratiox /= triple->x;
- ratioy /= triple->y;
- halfx /= triple->x;
- halfy /= triple->y;
+ if (!ar->draw_buffer) {
+ return NULL;
}
- /* interlace stereo buffer bind the shader before calling wm_triple_draw_textures */
- if (is_interlace) {
- glEnable(triple->target);
+ if (ar->draw_buffer->viewport[view]) {
+ return GPU_viewport_color_texture(ar->draw_buffer->viewport[view]);
}
else {
- GPU_basic_shader_bind((triple->target == GL_TEXTURE_2D) ? GPU_SHADER_TEXTURE_2D : GPU_SHADER_TEXTURE_RECT);
+ return GPU_offscreen_color_texture(ar->draw_buffer->offscreen[view]);
}
+}
- glBindTexture(triple->target, triple->bind);
-
- glColor4f(1.0f, 1.0f, 1.0f, alpha);
- glBegin(GL_QUADS);
- glTexCoord2f(halfx, halfy);
- glVertex2f(0, 0);
+void wm_draw_region_blend(ARegion *ar, int view, bool blend)
+{
+ if (!ar->draw_buffer) {
+ return;
+ }
- glTexCoord2f(ratiox + halfx, halfy);
- glVertex2f(sizex, 0);
+ /* Alpha is always 1, except when blend timer is running. */
+ float alpha = ED_region_blend_alpha(ar);
+ if (alpha <= 0.0f) {
+ return;
+ }
- glTexCoord2f(ratiox + halfx, ratioy + halfy);
- glVertex2f(sizex, sizey);
+ if (!blend) {
+ alpha = 1.0f;
+ }
- glTexCoord2f(halfx, ratioy + halfy);
- glVertex2f(0, sizey);
- glEnd();
+ /* setup actual texture */
+ GPUTexture *texture = wm_draw_region_texture(ar, view);
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(texture));
- glBindTexture(triple->target, 0);
+ /* wmOrtho for the screen has this same offset */
+ const float halfx = GLA_PIXEL_OFS / (BLI_rcti_size_x(&ar->winrct) + 1);
+ const float halfy = GLA_PIXEL_OFS / (BLI_rcti_size_y(&ar->winrct) + 1);
- if (is_interlace) {
- glDisable(triple->target);
- }
- else {
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ if (blend) {
+ /* GL_ONE because regions drawn offscreen have premultiplied alpha. */
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
}
-}
-static void wm_triple_copy_textures(wmWindow *win, wmDrawTriple *triple)
-{
- const int sizex = WM_window_pixels_x(win);
- const int sizey = WM_window_pixels_y(win);
+ GPUShader *shader = GPU_shader_get_builtin_shader(GPU_SHADER_2D_IMAGE_RECT_COLOR);
+ GPU_shader_bind(shader);
- glBindTexture(triple->target, triple->bind);
- glCopyTexSubImage2D(triple->target, 0, 0, 0, 0, 0, sizex, sizey);
+ glUniform1i(GPU_shader_get_uniform(shader, "image"), 0);
+ glUniform4f(GPU_shader_get_uniform(shader, "rect_icon"), halfx, halfy, 1.0f + halfx, 1.0f + halfy);
+ glUniform4f(GPU_shader_get_uniform(shader, "rect_geom"), ar->winrct.xmin, ar->winrct.ymin, ar->winrct.xmax + 1, ar->winrct.ymax + 1);
+ glUniform4f(GPU_shader_get_builtin_uniform(shader, GWN_UNIFORM_COLOR), alpha, alpha, alpha, alpha);
- glBindTexture(triple->target, 0);
-}
+ GWN_draw_primitive(GWN_PRIM_TRI_STRIP, 4);
-static void wm_draw_region_blend(wmWindow *win, ARegion *ar, wmDrawTriple *triple)
-{
- float fac = ED_region_blend_factor(ar);
-
- /* region blend always is 1, except when blend timer is running */
- if (fac < 1.0f) {
- wmSubWindowScissorSet(win, win->screen->mainwin, &ar->winrct, true);
+ glBindTexture(GL_TEXTURE_2D, 0);
- glEnable(GL_BLEND);
- wm_triple_draw_textures(win, triple, 1.0f - fac, false);
+ if (blend) {
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glDisable(GL_BLEND);
}
}
-static void wm_method_draw_triple(bContext *C, wmWindow *win)
+GPUViewport *WM_draw_region_get_viewport(ARegion *ar, int view)
{
- wmWindowManager *wm = CTX_wm_manager(C);
- wmDrawData *dd, *dd_next, *drawdata = win->drawdata.first;
- bScreen *screen = win->screen;
- ScrArea *sa;
- ARegion *ar;
- int copytex = false;
-
- if (drawdata && drawdata->triple) {
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- wmSubWindowSet(win, screen->mainwin);
-
- wm_triple_draw_textures(win, drawdata->triple, 1.0f, false);
+ if (!ar->draw_buffer) {
+ return NULL;
}
- else {
- /* we run it when we start OR when we turn stereo on */
- if (drawdata == NULL) {
- drawdata = MEM_callocN(sizeof(wmDrawData), "wmDrawData");
- BLI_addhead(&win->drawdata, drawdata);
- }
- drawdata->triple = MEM_callocN(sizeof(wmDrawTriple), "wmDrawTriple");
+ return ar->draw_buffer->viewport[view];
+}
- if (!wm_triple_gen_textures(win, drawdata->triple)) {
- wm_draw_triple_fail(C, win);
- return;
- }
+GPUViewport *WM_draw_region_get_bound_viewport(ARegion *ar)
+{
+ if (!ar->draw_buffer || ar->draw_buffer->bound_view == -1) {
+ return NULL;
}
- /* it means stereo was just turned off */
- /* note: we are removing all drawdatas that are not the first */
- for (dd = drawdata->next; dd; dd = dd_next) {
- dd_next = dd->next;
-
- BLI_remlink(&win->drawdata, dd);
- wm_draw_triple_free(dd->triple);
- MEM_freeN(dd);
- }
+ int view = ar->draw_buffer->bound_view;
+ return ar->draw_buffer->viewport[view];
+}
- wmDrawTriple *triple = drawdata->triple;
+static void wm_draw_window_offscreen(bContext *C, wmWindow *win, bool stereo)
+{
+ wmWindowManager *wm = CTX_wm_manager(C);
+ bScreen *screen = WM_window_get_active_screen(win);
- /* draw marked area regions */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
+ /* Draw screen areas into own frame buffer. */
+ ED_screen_areas_iter(win, screen, sa) {
CTX_wm_area_set(C, sa);
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid && ar->do_draw) {
- if (ar->overlap == false) {
- CTX_wm_region_set(C, ar);
- ED_region_do_draw(C, ar);
- ar->do_draw = false;
- CTX_wm_region_set(C, NULL);
- copytex = true;
- }
+ /* Compute UI layouts for dynamically size regions. */
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->visible && ar->do_draw && ar->type && ar->type->layout) {
+ CTX_wm_region_set(C, ar);
+ ED_region_do_layout(C, ar);
+ CTX_wm_region_set(C, NULL);
}
}
- wm_area_mark_invalid_backbuf(sa);
- CTX_wm_area_set(C, NULL);
- }
+ ED_area_update_region_sizes(wm, win, sa);
- if (copytex) {
- wmSubWindowSet(win, screen->mainwin);
-
- wm_triple_copy_textures(win, triple);
- }
-
- if (wm->paintcursors.first) {
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid && ar->swinid == screen->subwinactive) {
- CTX_wm_area_set(C, sa);
- CTX_wm_region_set(C, ar);
-
- /* make region ready for draw, scissor, pixelspace */
- ED_region_set(C, ar);
- wm_paintcursor_draw(C, ar);
-
- CTX_wm_region_set(C, NULL);
- CTX_wm_area_set(C, NULL);
+ /* Then do actual drawing of regions. */
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->visible && ar->do_draw) {
+ CTX_wm_region_set(C, ar);
+ bool use_viewport = wm_region_use_viewport(sa, ar);
+
+ if (stereo && wm_draw_region_stereo_set(sa, ar, STEREO_LEFT_ID)) {
+ wm_draw_region_buffer_create(ar, true, use_viewport);
+
+ for (int view = 0; view < 2; view++) {
+ eStereoViews sview;
+ if (view == 0) {
+ sview = STEREO_LEFT_ID;
+ }
+ else {
+ sview = STEREO_RIGHT_ID;
+ wm_draw_region_stereo_set(sa, ar, sview);
+ }
+
+ wm_draw_region_bind(ar, view);
+ ED_region_do_draw(C, ar);
+ wm_draw_region_unbind(ar, view);
+ }
+ }
+ else {
+ wm_draw_region_buffer_create(ar, false, use_viewport);
+ wm_draw_region_bind(ar, 0);
+ ED_region_do_draw(C, ar);
+ wm_draw_region_unbind(ar, 0);
}
- }
- }
-
- wmSubWindowSet(win, screen->mainwin);
- }
-
- /* draw overlapping area regions (always like popups) */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- CTX_wm_area_set(C, sa);
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid && ar->overlap) {
- CTX_wm_region_set(C, ar);
- ED_region_do_draw(C, ar);
ar->do_draw = false;
CTX_wm_region_set(C, NULL);
-
- wm_draw_region_blend(win, ar, triple);
}
}
+ wm_area_mark_invalid_backbuf(sa);
CTX_wm_area_set(C, NULL);
}
- /* after area regions so we can do area 'overlay' drawing */
- ED_screen_draw_edges(win);
- win->screen->do_draw = false;
- wm_draw_callbacks(win);
-
- /* draw floating regions (menus) */
- for (ar = screen->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid) {
+ /* Draw menus into their own framebuffer. */
+ for (ARegion *ar = screen->regionbase.first; ar; ar = ar->next) {
+ if (ar->visible) {
CTX_wm_menu_set(C, ar);
+
+ if (ar->type && ar->type->layout) {
+ /* UI code reads the OpenGL state, but we have to refesh
+ * the UI layout beforehand in case the menu size changes. */
+ wmViewport(&ar->winrct);
+ ar->type->layout(C, ar);
+ }
+
+ wm_draw_region_buffer_create(ar, false, false);
+ wm_draw_region_bind(ar, 0);
+ glClearColor(0, 0, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT);
ED_region_do_draw(C, ar);
+ wm_draw_region_unbind(ar, 0);
+
ar->do_draw = false;
CTX_wm_menu_set(C, NULL);
}
}
-
- /* always draw, not only when screen tagged */
- if (win->gesture.first)
- wm_gesture_draw(win);
-
- /* needs pixel coords in screen */
- if (wm->drags.first) {
- wm_drags_draw(C, win, NULL);
- }
}
-static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoViews sview)
+static void wm_draw_window_onscreen(bContext *C, wmWindow *win, int view)
{
wmWindowManager *wm = CTX_wm_manager(C);
- wmDrawData *drawdata;
- wmDrawTriple *triple_data, *triple_all;
- bScreen *screen = win->screen;
- ScrArea *sa;
- ARegion *ar;
- int copytex = false;
- int id;
-
- /* we store the triple_data in sequence to triple_all */
- for (id = 0; id < 2; id++) {
- drawdata = BLI_findlink(&win->drawdata, (sview * 2) + id);
-
- if (drawdata && drawdata->triple) {
- if (id == 0) {
- glClearColor(0, 0, 0, 0);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- wmSubWindowSet(win, screen->mainwin);
-
- wm_triple_draw_textures(win, drawdata->triple, 1.0f, false);
- }
- }
- else {
- /* we run it when we start OR when we turn stereo on */
- if (drawdata == NULL) {
- drawdata = MEM_callocN(sizeof(wmDrawData), "wmDrawData");
- BLI_addtail(&win->drawdata, drawdata);
- }
-
- drawdata->triple = MEM_callocN(sizeof(wmDrawTriple), "wmDrawTriple");
-
- if (!wm_triple_gen_textures(win, drawdata->triple)) {
- wm_draw_triple_fail(C, win);
- return;
- }
- }
- }
-
- triple_data = ((wmDrawData *) BLI_findlink(&win->drawdata, sview * 2))->triple;
- triple_all = ((wmDrawData *) BLI_findlink(&win->drawdata, (sview * 2) + 1))->triple;
-
- /* draw marked area regions */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- CTX_wm_area_set(C, sa);
-
- switch (sa->spacetype) {
- case SPACE_IMAGE:
- {
- SpaceImage *sima = sa->spacedata.first;
- sima->iuser.multiview_eye = sview;
- break;
- }
- case SPACE_VIEW3D:
- {
- View3D *v3d = sa->spacedata.first;
- BGpic *bgpic = v3d->bgpicbase.first;
- v3d->multiview_eye = sview;
- if (bgpic) bgpic->iuser.multiview_eye = sview;
- break;
- }
- case SPACE_NODE:
- {
- SpaceNode *snode = sa->spacedata.first;
- if ((snode->flag & SNODE_BACKDRAW) && ED_node_is_compositor(snode)) {
- Image *ima = BKE_image_verify_viewer(IMA_TYPE_COMPOSITE, "Viewer Node");
- ima->eye = sview;
+ bScreen *screen = WM_window_get_active_screen(win);
+
+ /* Draw into the window framebuffer, in full window coordinates. */
+ wmWindowViewport(win);
+ glClearColor(0, 0, 0, 0);
+ glClear(GL_COLOR_BUFFER_BIT);
+
+ /* Blit non-overlapping area regions. */
+ ED_screen_areas_iter(win, screen, sa) {
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->visible && ar->overlap == false) {
+ if (view == -1 && ar->draw_buffer && ar->draw_buffer->stereo) {
+ /* Stereo drawing from textures. */
+ if (win->stereo3d_format->display_mode == S3D_DISPLAY_ANAGLYPH) {
+ wm_stereo3d_draw_anaglyph(win, ar);
+ }
+ else {
+ wm_stereo3d_draw_interlace(win, ar);
+ }
}
- break;
- }
- case SPACE_SEQ:
- {
- SpaceSeq *sseq = sa->spacedata.first;
- sseq->multiview_eye = sview;
- break;
- }
- }
-
- /* draw marked area regions */
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid && ar->do_draw) {
-
- if (ar->overlap == false) {
- CTX_wm_region_set(C, ar);
- ED_region_do_draw(C, ar);
-
- if (sview == STEREO_RIGHT_ID)
- ar->do_draw = false;
-
- CTX_wm_region_set(C, NULL);
- copytex = true;
+ else {
+ /* Blit from offscreen buffer. */
+ wm_draw_region_blit(ar, 0);
}
}
}
-
- wm_area_mark_invalid_backbuf(sa);
- CTX_wm_area_set(C, NULL);
- }
-
- if (copytex) {
- wmSubWindowSet(win, screen->mainwin);
-
- wm_triple_copy_textures(win, triple_data);
}
+ /* Draw paint cursors. */
if (wm->paintcursors.first) {
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid && ar->swinid == screen->subwinactive) {
+ ED_screen_areas_iter(win, screen, sa) {
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->visible && ar == screen->active_region) {
CTX_wm_area_set(C, sa);
CTX_wm_region_set(C, ar);
/* make region ready for draw, scissor, pixelspace */
- ED_region_set(C, ar);
wm_paintcursor_draw(C, ar);
CTX_wm_region_set(C, NULL);
@@ -811,42 +619,26 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
}
}
- wmSubWindowSet(win, screen->mainwin);
+ wmWindowViewport(win);
}
- /* draw overlapping area regions (always like popups) */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
- CTX_wm_area_set(C, sa);
-
- for (ar = sa->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid && ar->overlap) {
- CTX_wm_region_set(C, ar);
- ED_region_do_draw(C, ar);
- if (sview == STEREO_RIGHT_ID)
- ar->do_draw = false;
- CTX_wm_region_set(C, NULL);
-
- wm_draw_region_blend(win, ar, triple_data);
+ /* Blend in overlapping area regions */
+ ED_screen_areas_iter(win, screen, sa) {
+ for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+ if (ar->visible && ar->overlap) {
+ wm_draw_region_blend(ar, 0, true);
}
}
-
- CTX_wm_area_set(C, NULL);
}
- /* after area regions so we can do area 'overlay' drawing */
+ /* After area regions so we can do area 'overlay' drawing. */
ED_screen_draw_edges(win);
- if (sview == STEREO_RIGHT_ID)
- win->screen->do_draw = false;
wm_draw_callbacks(win);
- /* draw floating regions (menus) */
- for (ar = screen->regionbase.first; ar; ar = ar->next) {
- if (ar->swinid) {
- CTX_wm_menu_set(C, ar);
- ED_region_do_draw(C, ar);
- if (sview == STEREO_RIGHT_ID)
- ar->do_draw = false;
- CTX_wm_menu_set(C, NULL);
+ /* Blend in floating regions (menus). */
+ for (ARegion *ar = screen->regionbase.first; ar; ar = ar->next) {
+ if (ar->visible) {
+ wm_draw_region_blend(ar, 0, true);
}
}
@@ -858,10 +650,76 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
if (wm->drags.first) {
wm_drags_draw(C, win, NULL);
}
+}
- /* copy the ui + overlays */
- wmSubWindowSet(win, screen->mainwin);
- wm_triple_copy_textures(win, triple_all);
+static void wm_draw_window(bContext *C, wmWindow *win)
+{
+ bScreen *screen = WM_window_get_active_screen(win);
+ bool stereo = WM_stereo3d_enabled(win, false);
+
+ /* Draw area regions into their own framebuffer. This way we can redraw
+ * the areas that need it, and blit the rest from existing framebuffers. */
+ wm_draw_window_offscreen(C, win, stereo);
+
+ /* Now we draw into the window framebuffer, in full window coordinates. */
+ if (!stereo) {
+ /* Regular mono drawing. */
+ wm_draw_window_onscreen(C, win, -1);
+ }
+ else if (win->stereo3d_format->display_mode == S3D_DISPLAY_PAGEFLIP) {
+ /* For pageflip we simply draw to both back buffers. */
+ glDrawBuffer(GL_BACK_LEFT);
+ wm_draw_window_onscreen(C, win, 0);
+ glDrawBuffer(GL_BACK_RIGHT);
+ wm_draw_window_onscreen(C, win, 1);
+ glDrawBuffer(GL_BACK);
+ }
+ else if (ELEM(win->stereo3d_format->display_mode, S3D_DISPLAY_ANAGLYPH, S3D_DISPLAY_INTERLACE)) {
+ /* For anaglyph and interlace, we draw individual regions with
+ * stereo framebuffers using different shaders. */
+ wm_draw_window_onscreen(C, win, -1);
+ }
+ else {
+ /* For side-by-side and top-bottom, we need to render each view to an
+ * an offscreen texture and then draw it. This used to happen for all
+ * stereo methods, but it's less efficient than drawing directly. */
+ const int width = WM_window_pixels_x(win);
+ const int height = WM_window_pixels_y(win);
+ GPUOffScreen *offscreen = GPU_offscreen_create(width, height, 0, false, false, NULL);
+
+ if (offscreen) {
+ GPUTexture *texture = GPU_offscreen_color_texture(offscreen);
+ wm_draw_offscreen_texture_parameters(offscreen);
+
+ for (int view = 0; view < 2; view++) {
+ /* Draw view into offscreen buffer. */
+ GPU_offscreen_bind(offscreen, false);
+ wm_draw_window_onscreen(C, win, view);
+ GPU_offscreen_unbind(offscreen, false);
+
+ /* Draw offscreen buffer to screen. */
+ glActiveTexture(GL_TEXTURE0);
+ glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(texture));
+
+ if (win->stereo3d_format->display_mode == S3D_DISPLAY_SIDEBYSIDE) {
+ wm_stereo3d_draw_sidebyside(win, view);
+ }
+ else {
+ wm_stereo3d_draw_topbottom(win, view);
+ }
+
+ glBindTexture(GL_TEXTURE_2D, 0);
+ }
+
+ GPU_offscreen_free(offscreen);
+ }
+ else {
+ /* Still draw something in case of allocation failure. */
+ wm_draw_window_onscreen(C, win, 0);
+ }
+ }
+
+ screen->do_draw = false;
}
/****************** main update call **********************/
@@ -869,25 +727,28 @@ static void wm_method_draw_triple_multiview(bContext *C, wmWindow *win, eStereoV
/* quick test to prevent changing window drawable */
static bool wm_draw_update_test_window(wmWindow *win)
{
- const bScreen *screen = win->screen;
- ScrArea *sa;
+ struct WorkSpace *workspace = WM_window_get_active_workspace(win);
+ Scene *scene = WM_window_get_active_scene(win);
+ ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
+ struct Depsgraph *depsgraph = BKE_scene_get_depsgraph(scene, view_layer, true);
+ bScreen *screen = WM_window_get_active_screen(win);
ARegion *ar;
bool do_draw = false;
for (ar = screen->regionbase.first; ar; ar = ar->next) {
if (ar->do_draw_overlay) {
- wm_tag_redraw_overlay(win, ar);
+ screen->do_draw_paintcursor = true;
ar->do_draw_overlay = false;
}
- if (ar->swinid && ar->do_draw)
+ if (ar->visible && ar->do_draw)
do_draw = true;
}
- for (sa = screen->areabase.first; sa; sa = sa->next) {
+ ED_screen_areas_iter(win, screen, sa) {
for (ar = sa->regionbase.first; ar; ar = ar->next) {
- wm_region_test_render_do_draw(screen, sa, ar);
+ wm_region_test_render_do_draw(scene, depsgraph, sa, ar);
- if (ar->swinid && ar->do_draw)
+ if (ar->visible && ar->do_draw)
do_draw = true;
}
}
@@ -909,41 +770,14 @@ static bool wm_draw_update_test_window(wmWindow *win)
return false;
}
-static int wm_automatic_draw_method(wmWindow *win)
+void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *UNUSED(ar))
{
- /* We assume all supported GPUs now support triple buffer well. */
- if (win->drawmethod == USER_DRAW_AUTOMATIC) {
- return USER_DRAW_TRIPLE;
- }
- else {
- return win->drawmethod;
- }
-}
-
-bool WM_is_draw_triple(wmWindow *win)
-{
- /* function can get called before this variable is set in drawing code below */
- if (win->drawmethod != U.wmdrawmethod)
- win->drawmethod = U.wmdrawmethod;
- return (USER_DRAW_TRIPLE == wm_automatic_draw_method(win));
-}
-
-void wm_tag_redraw_overlay(wmWindow *win, ARegion *ar)
-{
- /* for draw triple gestures, paint cursors don't need region redraw */
- if (ar && win) {
- if (wm_automatic_draw_method(win) != USER_DRAW_TRIPLE)
- ED_region_tag_redraw(ar);
- win->screen->do_draw_paintcursor = true;
+ if (win) {
+ bScreen *screen = WM_window_get_active_screen(win);
+ screen->do_draw_paintcursor = true;
}
}
-void WM_paint_cursor_tag_redraw(wmWindow *win, ARegion *ar)
-{
- win->screen->do_draw_paintcursor = true;
- wm_tag_redraw_overlay(win, ar);
-}
-
void wm_draw_update(bContext *C)
{
wmWindowManager *wm = CTX_wm_manager(C);
@@ -967,13 +801,9 @@ void wm_draw_update(bContext *C)
continue;
}
#endif
- if (win->drawmethod != U.wmdrawmethod) {
- wm_draw_window_clear(win);
- win->drawmethod = U.wmdrawmethod;
- }
if (wm_draw_update_test_window(win)) {
- bScreen *screen = win->screen;
+ bScreen *screen = WM_window_get_active_screen(win);
CTX_wm_window_set(C, win);
@@ -981,29 +811,10 @@ void wm_draw_update(bContext *C)
wm_window_make_drawable(wm, win);
/* notifiers for screen redraw */
- if (screen->do_refresh)
- ED_screen_refresh(wm, win);
-
- int drawmethod = wm_automatic_draw_method(win);
-
- if (win->drawfail)
- wm_method_draw_overlap_all(C, win, 0);
- else if (drawmethod == USER_DRAW_FULL)
- wm_method_draw_full(C, win);
- else if (drawmethod == USER_DRAW_OVERLAP)
- wm_method_draw_overlap_all(C, win, 0);
- else if (drawmethod == USER_DRAW_OVERLAP_FLIP)
- wm_method_draw_overlap_all(C, win, 1);
- else { /* USER_DRAW_TRIPLE */
- if ((WM_stereo3d_enabled(win, false)) == false) {
- wm_method_draw_triple(C, win);
- }
- else {
- wm_method_draw_triple_multiview(C, win, STEREO_LEFT_ID);
- wm_method_draw_triple_multiview(C, win, STEREO_RIGHT_ID);
- wm_method_draw_stereo3d(C, win);
- }
- }
+ ED_screen_set_active_region(C, &win->eventstate->x);
+ ED_screen_ensure_updated(wm, win, screen);
+
+ wm_draw_window(C, win);
screen->do_draw_gesture = false;
screen->do_draw_paintcursor = false;
@@ -1016,42 +827,16 @@ void wm_draw_update(bContext *C)
}
}
-void wm_draw_data_free(wmWindow *win)
+void wm_draw_region_clear(wmWindow *win, ARegion *UNUSED(ar))
{
- wmDrawData *dd;
-
- for (dd = win->drawdata.first; dd; dd = dd->next) {
- wm_draw_triple_free(dd->triple);
- }
- BLI_freelistN(&win->drawdata);
+ bScreen *screen = WM_window_get_active_screen(win);
+ screen->do_draw = true;
}
-void wm_draw_window_clear(wmWindow *win)
+void WM_draw_region_free(ARegion *ar)
{
- bScreen *screen = win->screen;
- ScrArea *sa;
- ARegion *ar;
-
- wm_draw_data_free(win);
-
- /* clear screen swap flags */
- if (screen) {
- for (sa = screen->areabase.first; sa; sa = sa->next)
- for (ar = sa->regionbase.first; ar; ar = ar->next)
- ar->swap = WIN_NONE_OK;
-
- screen->swap = WIN_NONE_OK;
- }
-}
-
-void wm_draw_region_clear(wmWindow *win, ARegion *ar)
-{
- int drawmethod = wm_automatic_draw_method(win);
-
- if (ELEM(drawmethod, USER_DRAW_OVERLAP, USER_DRAW_OVERLAP_FLIP))
- wm_flush_regions_down(win->screen, &ar->winrct);
-
- win->screen->do_draw = true;
+ wm_draw_region_buffer_free(ar);
+ ar->visible = 0;
}
void WM_redraw_windows(bContext *C)
diff --git a/source/blender/windowmanager/intern/wm_event_system.c b/source/blender/windowmanager/intern/wm_event_system.c
index a6c98686f5a..f0bd033f033 100644
--- a/source/blender/windowmanager/intern/wm_event_system.c
+++ b/source/blender/windowmanager/intern/wm_event_system.c
@@ -55,10 +55,12 @@
#include "BKE_context.h"
#include "BKE_idprop.h"
#include "BKE_global.h"
+#include "BKE_layer.h"
#include "BKE_main.h"
#include "BKE_report.h"
#include "BKE_scene.h"
#include "BKE_screen.h"
+#include "BKE_workspace.h"
#include "BKE_sound.h"
@@ -71,14 +73,13 @@
#include "RNA_access.h"
-#include "GPU_debug.h"
-
#include "UI_interface.h"
#include "PIL_time.h"
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "wm.h"
#include "wm_window.h"
#include "wm_event_system.h"
@@ -86,6 +87,8 @@
#include "RNA_enum_types.h"
+#include "DEG_depsgraph.h"
+
/* Motion in pixels allowed before we don't consider single/double click. */
#define WM_EVENT_CLICK_WIGGLE_ROOM 2
@@ -182,7 +185,6 @@ static bool wm_test_duplicate_notifier(wmWindowManager *wm, unsigned int type, v
/* XXX: in future, which notifiers to send to other windows? */
void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference)
{
- ARegion *ar;
wmWindowManager *wm = CTX_wm_manager(C);
wmNotifier *note;
@@ -196,10 +198,6 @@ void WM_event_add_notifier(const bContext *C, unsigned int type, void *reference
note->window = CTX_wm_window(C);
- ar = CTX_wm_region(C);
- if (ar)
- note->swinid = ar->swinid;
-
note->category = type & NOTE_CATEGORY;
note->data = type & NOTE_DATA;
note->subtype = type & NOTE_SUBTYPE;
@@ -250,6 +248,14 @@ void WM_main_remove_notifier_reference(const void *reference)
wm_notifier_clear(note);
}
}
+
+ /* Remap instead. */
+#if 0
+ if (wm->message_bus) {
+ WM_msg_id_remove(wm->message_bus, reference);
+ }
+#endif
+
}
}
@@ -269,6 +275,17 @@ void WM_main_remap_editor_id_reference(ID *old_id, ID *new_id)
}
}
}
+
+ wmWindowManager *wm = bmain->wm.first;
+ if (wm && wm->message_bus) {
+ struct wmMsgBus *mbus = wm->message_bus;
+ if (new_id != NULL) {
+ WM_msg_id_update(mbus, old_id, new_id);
+ }
+ else {
+ WM_msg_id_remove(mbus, old_id);
+ }
+ }
}
static void wm_notifier_clear(wmNotifier *note)
@@ -288,15 +305,20 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
/* combine datamasks so 1 win doesn't disable UV's in another [#26448] */
for (wmWindow *win = wm->windows.first; win; win = win->next) {
- win_combine_v3d_datamask |= ED_view3d_screen_datamask(win->screen);
+ const Scene *scene = WM_window_get_active_scene(win);
+ const bScreen *screen = WM_window_get_active_screen(win);
+
+ win_combine_v3d_datamask |= ED_view3d_screen_datamask(scene, screen);
}
/* cached: editor refresh callbacks now, they get context */
for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ const bScreen *screen = WM_window_get_active_screen(win);
+ Scene *scene = WM_window_get_active_scene(win);
ScrArea *sa;
CTX_wm_window_set(C, win);
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+ for (sa = screen->areabase.first; sa; sa = sa->next) {
if (sa->do_refresh) {
CTX_wm_area_set(C, sa);
ED_area_do_refresh(C, sa);
@@ -309,12 +331,14 @@ void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
Main *bmain = CTX_data_main(C);
/* copied to set's in scene_update_tagged_recursive() */
- win->screen->scene->customdata_mask = win_combine_v3d_datamask;
+ scene->customdata_mask = win_combine_v3d_datamask;
/* XXX, hack so operators can enforce datamasks [#26482], gl render */
- win->screen->scene->customdata_mask |= win->screen->scene->customdata_mask_modal;
+ scene->customdata_mask |= scene->customdata_mask_modal;
- BKE_scene_update_tagged(bmain->eval_ctx, bmain, win->screen->scene);
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+
+ BKE_workspace_update_tagged(bmain, workspace, scene);
}
}
@@ -330,9 +354,12 @@ void wm_event_do_notifiers(bContext *C)
if (wm == NULL)
return;
-
+
+ /* disable? - keep for now since its used for window level notifiers. */
+#if 1
/* cache & catch WM level notifiers, such as frame change, scene/screen set */
for (win = wm->windows.first; win; win = win->next) {
+ Scene *scene = WM_window_get_active_scene(win);
bool do_anim = false;
CTX_wm_window_set(C, win);
@@ -350,23 +377,46 @@ void wm_event_do_notifiers(bContext *C)
}
if (note->window == win) {
if (note->category == NC_SCREEN) {
- if (note->data == ND_SCREENBROWSE) {
+ if (note->data == ND_WORKSPACE_SET) {
+ WorkSpace *ref_ws = note->reference;
+
+ UI_popup_handlers_remove_all(C, &win->modalhandlers);
+
+ ED_workspace_change(ref_ws, C, wm, win);
+ if (G.debug & G_DEBUG_EVENTS)
+ printf("%s: Workspace set %p\n", __func__, note->reference);
+ }
+ else if (note->data == ND_WORKSPACE_DELETE) {
+ WorkSpace *workspace = note->reference;
+
+ ED_workspace_delete(workspace, CTX_data_main(C), C, wm); // XXX hrms, think this over!
+ if (G.debug & G_DEBUG_EVENTS)
+ printf("%s: Workspace delete %p\n", __func__, workspace);
+ }
+ else if (note->data == ND_LAYOUTBROWSE) {
+ bScreen *ref_screen = BKE_workspace_layout_screen_get(note->reference);
+
/* free popup handlers only [#35434] */
UI_popup_handlers_remove_all(C, &win->modalhandlers);
- ED_screen_set(C, note->reference); // XXX hrms, think this over!
- CLOG_INFO(WM_LOG_EVENTS, 1, "screen set %p", note->reference);
+ ED_screen_change(C, ref_screen); /* XXX hrms, think this over! */
+ if (G.debug & G_DEBUG_EVENTS)
+ printf("%s: screen set %p\n", __func__, note->reference);
}
- else if (note->data == ND_SCREENDELETE) {
- ED_screen_delete(C, note->reference); // XXX hrms, think this over!
- CLOG_INFO(WM_LOG_EVENTS, 1, "screen delete %p", note->reference);
+ else if (note->data == ND_LAYOUTDELETE) {
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ WorkSpaceLayout *layout = note->reference;
+
+ ED_workspace_layout_delete(workspace, layout, C); // XXX hrms, think this over!
+ if (G.debug & G_DEBUG_EVENTS)
+ printf("%s: screen delete %p\n", __func__, note->reference);
}
}
}
if (note->window == win ||
- (note->window == NULL && (note->reference == NULL || note->reference == win->screen->scene)))
+ (note->window == NULL && (note->reference == NULL || note->reference == scene)))
{
if (note->category == NC_SCENE) {
if (note->data == ND_FRAME)
@@ -374,19 +424,20 @@ void wm_event_do_notifiers(bContext *C)
}
}
if (ELEM(note->category, NC_SCENE, NC_OBJECT, NC_GEOM, NC_WM)) {
- ED_info_stats_clear(win->screen->scene);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
+ ED_info_stats_clear(view_layer);
WM_event_add_notifier(C, NC_SPACE | ND_SPACE_INFO, NULL);
}
}
if (do_anim) {
/* XXX, quick frame changes can cause a crash if framechange and rendering
- * collide (happens on slow scenes), BKE_scene_update_for_newframe can be called
+ * collide (happens on slow scenes), BKE_scene_graph_update_for_newframe can be called
* twice which can depgraph update the same object at once */
if (G.is_rendering == false) {
-
/* depsgraph gets called, might send more notifiers */
- ED_update_for_newframe(CTX_data_main(C), win->screen->scene, 1);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ED_update_for_newframe(CTX_data_main(C), depsgraph);
}
}
}
@@ -394,16 +445,23 @@ void wm_event_do_notifiers(bContext *C)
/* the notifiers are sent without context, to keep it clean */
while ((note = BLI_pophead(&wm->queue))) {
for (win = wm->windows.first; win; win = win->next) {
-
+ Scene *scene = WM_window_get_active_scene(win);
+ bScreen *screen = WM_window_get_active_screen(win);
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+
/* filter out notifiers */
- if (note->category == NC_SCREEN && note->reference && note->reference != win->screen) {
+ if (note->category == NC_SCREEN &&
+ note->reference &&
+ note->reference != screen &&
+ note->reference != workspace &&
+ note->reference != WM_window_get_active_layout(win))
+ {
/* pass */
}
- else if (note->category == NC_SCENE && note->reference && note->reference != win->screen->scene) {
+ else if (note->category == NC_SCENE && note->reference && note->reference != scene) {
/* pass */
}
else {
- ScrArea *sa;
ARegion *ar;
/* XXX context in notifiers? */
@@ -412,14 +470,14 @@ void wm_event_do_notifiers(bContext *C)
/* printf("notifier win %d screen %s cat %x\n", win->winid, win->screen->id.name + 2, note->category); */
ED_screen_do_listen(C, note);
- for (ar = win->screen->regionbase.first; ar; ar = ar->next) {
- ED_region_do_listen(win->screen, NULL, ar, note);
+ for (ar = screen->regionbase.first; ar; ar = ar->next) {
+ ED_region_do_listen(screen, NULL, ar, note, scene);
}
-
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
- ED_area_do_listen(win->screen, sa, note);
+
+ ED_screen_areas_iter(win, screen, sa) {
+ ED_area_do_listen(screen, sa, note, scene, workspace);
for (ar = sa->regionbase.first; ar; ar = ar->next) {
- ED_region_do_listen(win->screen, sa, ar, note);
+ ED_region_do_listen(screen, sa, ar, note, scene);
}
}
}
@@ -427,7 +485,17 @@ void wm_event_do_notifiers(bContext *C)
MEM_freeN(note);
}
-
+#endif /* if 1 (postpone disabling for in favor of message-bus), eventually. */
+
+ /* Handle message bus. */
+ {
+ for (win = wm->windows.first; win; win = win->next) {
+ CTX_wm_window_set(C, win);
+ WM_msgbus_handle(wm->message_bus, C);
+ }
+ CTX_wm_window_set(C, NULL);
+ }
+
wm_event_do_refresh_wm_and_depsgraph(C);
}
@@ -546,6 +614,39 @@ int WM_operator_poll_context(bContext *C, wmOperatorType *ot, short context)
return wm_operator_call_internal(C, ot, NULL, NULL, context, true);
}
+bool WM_operator_check_ui_empty(wmOperatorType *ot)
+{
+ if (ot->macro.first != NULL) {
+ /* for macros, check all have exec() we can call */
+ wmOperatorTypeMacro *otmacro;
+ for (otmacro = ot->macro.first; otmacro; otmacro = otmacro->next) {
+ wmOperatorType *otm = WM_operatortype_find(otmacro->idname, 0);
+ if (otm && !WM_operator_check_ui_empty(otm)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /* Assume a ui callback will draw something. */
+ if (ot->ui) {
+ return false;
+ }
+
+ PointerRNA ptr;
+ WM_operator_properties_create_ptr(&ptr, ot);
+ RNA_STRUCT_BEGIN (&ptr, prop)
+ {
+ int flag = RNA_property_flag(prop);
+ if (flag & PROP_HIDDEN) {
+ continue;
+ }
+ return false;
+ }
+ RNA_STRUCT_END;
+ return true;
+}
+
/**
* Sets the active region for this space from the context.
*
@@ -704,7 +805,7 @@ static void wm_operator_reports(bContext *C, wmOperator *op, int retval, bool ca
CTX_wm_region_set(C, ar_prev);
}
}
-
+
if (retval & OPERATOR_FINISHED) {
CLOG_STR_INFO_N(WM_LOG_OPERATORS, 1, WM_operator_pystring(C, op, false, true));
@@ -876,7 +977,14 @@ int WM_operator_call_notest(bContext *C, wmOperator *op)
*/
int WM_operator_repeat(bContext *C, wmOperator *op)
{
- return wm_operator_exec(C, op, true, true);
+ const OperatorRepeatContextHandle *context_info;
+ int retval;
+
+ context_info = ED_operator_repeat_prepare_context(C, op);
+ retval = wm_operator_exec(C, op, true, true);
+ ED_operator_repeat_reset_context(C, context_info);
+
+ return retval;
}
/**
* \return true if #WM_operator_repeat can run
@@ -1139,8 +1247,8 @@ static int wm_operator_invoke(
if ((event == NULL) || (event->type != MOUSEMOVE)) {
CLOG_INFO(WM_LOG_HANDLERS, 2,
- "handle evt %d win %d op %s",
- event ? event->type : 0, CTX_wm_screen(C)->subwinactive, ot->idname);
+ "handle evt %d win %p op %s",
+ event ? event->type : 0, CTX_wm_screen(C)->active_region, ot->idname);
}
if (op->type->invoke && event) {
@@ -1477,17 +1585,22 @@ void wm_event_free_handler(wmEventHandler *handler)
/* only set context when area/region is part of screen */
static void wm_handler_op_context(bContext *C, wmEventHandler *handler, const wmEvent *event)
{
+ wmWindow *win = CTX_wm_window(C);
bScreen *screen = CTX_wm_screen(C);
if (screen && handler->op) {
if (handler->op_area == NULL)
CTX_wm_area_set(C, NULL);
else {
- ScrArea *sa;
-
- for (sa = screen->areabase.first; sa; sa = sa->next)
- if (sa == handler->op_area)
+ ScrArea *sa = NULL;
+
+ ED_screen_areas_iter(win, screen, sa_iter) {
+ if (sa_iter == handler->op_area) {
+ sa = sa_iter;
break;
+ }
+ }
+
if (sa == NULL) {
/* when changing screen layouts with running modal handlers (like render display), this
* is not an error to print */
@@ -1598,6 +1711,36 @@ int WM_userdef_event_map(int kmitype)
return kmitype;
}
+/**
+ * Use so we can check if 'wmEvent.type' is released in modal operators.
+ *
+ * An alternative would be to add a 'wmEvent.type_nokeymap'... or similar.
+ */
+int WM_userdef_event_type_from_keymap_type(int kmitype)
+{
+ switch (kmitype) {
+ case SELECTMOUSE:
+ return (U.flag & USER_LMOUSESELECT) ? LEFTMOUSE : RIGHTMOUSE;
+ case ACTIONMOUSE:
+ return (U.flag & USER_LMOUSESELECT) ? RIGHTMOUSE : LEFTMOUSE;
+ case EVT_TWEAK_S:
+ return (U.flag & USER_LMOUSESELECT) ? LEFTMOUSE : RIGHTMOUSE;
+ case EVT_TWEAK_A:
+ return (U.flag & USER_LMOUSESELECT) ? RIGHTMOUSE : LEFTMOUSE;
+ case EVT_TWEAK_L:
+ return LEFTMOUSE;
+ case EVT_TWEAK_M:
+ return MIDDLEMOUSE;
+ case EVT_TWEAK_R:
+ return RIGHTMOUSE;
+ case WHEELOUTMOUSE:
+ return (U.uiflag & USER_WHEELZOOMDIR) ? WHEELUPMOUSE : WHEELDOWNMOUSE;
+ case WHEELINMOUSE:
+ return (U.uiflag & USER_WHEELZOOMDIR) ? WHEELDOWNMOUSE : WHEELUPMOUSE;
+ }
+
+ return kmitype;
+}
static int wm_eventmatch(const wmEvent *winevent, wmKeyMapItem *kmi)
{
@@ -1746,7 +1889,7 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
wm_handler_op_context(C, handler, event);
wm_region_mouse_co(C, event);
wm_event_modalkeymap(C, op, event, &dbl_click_disabled);
-
+
if (ot->flag & OPTYPE_UNDO)
wm->op_undo_depth++;
@@ -1795,9 +1938,15 @@ static int wm_handler_operator_call(bContext *C, ListBase *handlers, wmEventHand
CTX_wm_region_set(C, NULL);
}
+ /* update manipulators during modal handlers */
+ wm_manipulatormaps_handled_modal_update(C, event, handler);
+
/* remove modal handler, operator itself should have been canceled and freed */
if (retval & (OPERATOR_CANCELLED | OPERATOR_FINISHED)) {
- WM_cursor_grab_disable(CTX_wm_window(C), NULL);
+ /* set cursor back to the default for the region */
+ wmWindow *win = CTX_wm_window(C);
+ WM_cursor_grab_disable(win, NULL);
+ ED_region_cursor_set(win, CTX_wm_area(C), CTX_wm_region(C));
BLI_remlink(handlers, handler);
wm_event_free_handler(handler);
@@ -1844,13 +1993,14 @@ static int wm_handler_fileselect_do(bContext *C, ListBase *handlers, wmEventHand
int action = WM_HANDLER_CONTINUE;
switch (val) {
- case EVT_FILESELECT_FULL_OPEN:
+ case EVT_FILESELECT_FULL_OPEN:
{
ScrArea *sa;
-
- /* sa can be null when window A is active, but mouse is over window B */
- /* in this case, open file select in original window A */
- if (handler->op_area == NULL) {
+
+ /* sa can be null when window A is active, but mouse is over window B
+ * in this case, open file select in original window A. Also don't
+ * use global areas. */
+ if (handler->op_area == NULL || ED_area_is_global(handler->op_area)) {
bScreen *screen = CTX_wm_screen(C);
sa = (ScrArea *)screen->areabase.first;
}
@@ -2162,6 +2312,139 @@ static int wm_handlers_do_intern(bContext *C, wmEvent *event, ListBase *handlers
}
}
}
+ else if (handler->manipulator_map) {
+ ScrArea *area = CTX_wm_area(C);
+ ARegion *region = CTX_wm_region(C);
+ wmManipulatorMap *mmap = handler->manipulator_map;
+ wmManipulator *mpr = wm_manipulatormap_highlight_get(mmap);
+
+ if (region->manipulator_map != handler->manipulator_map) {
+ WM_manipulatormap_tag_refresh(handler->manipulator_map);
+ }
+
+ wm_manipulatormap_handler_context(C, handler);
+ wm_region_mouse_co(C, event);
+
+ /* handle manipulator highlighting */
+ if (event->type == MOUSEMOVE && !wm_manipulatormap_modal_get(mmap)) {
+ int part;
+ mpr = wm_manipulatormap_highlight_find(mmap, C, event, &part);
+ wm_manipulatormap_highlight_set(mmap, C, mpr, part);
+ if (mpr != NULL) {
+ WM_tooltip_timer_init(C, CTX_wm_window(C), region, WM_manipulatormap_tooltip_init);
+ }
+ }
+ else {
+ /* Either we operate on a single highlighted item
+ * or groups attached to the selected manipulators.
+ * To simplify things both cases loop over an array of items. */
+ wmManipulatorGroup *mgroup_first;
+ bool is_mgroup_single;
+
+ if (ISMOUSE(event->type)) {
+ /* Keep mpr set as-is, just fake single selection. */
+ if (mpr) {
+ mgroup_first = mpr->parent_mgroup;
+ }
+ else {
+ mgroup_first = NULL;
+ }
+ is_mgroup_single = true;
+ }
+ else {
+ if (WM_manipulatormap_is_any_selected(mmap)) {
+ const ListBase *groups = WM_manipulatormap_group_list(mmap);
+ mgroup_first = groups->first;
+ }
+ else {
+ mgroup_first = NULL;
+ }
+ is_mgroup_single = false;
+ }
+
+ /* Don't use from now on. */
+ mpr = NULL;
+
+ for (wmManipulatorGroup *mgroup = mgroup_first; mgroup; mgroup = mgroup->next) {
+ /* get user customized keymap from default one */
+
+ if ((is_mgroup_single == false) &&
+ /* We might want to change the logic here and use some kind of manipulator edit-mode.
+ * For now just use keymap when a selection exists. */
+ wm_manipulatorgroup_is_any_selected(mgroup) == false)
+ {
+ continue;
+ }
+
+ const wmKeyMap *keymap = WM_keymap_active(wm, mgroup->type->keymap);
+ wmKeyMapItem *kmi;
+
+ PRINT("%s: checking '%s' ...", __func__, keymap->idname);
+
+ if (!keymap->poll || keymap->poll(C)) {
+ PRINT("pass\n");
+ for (kmi = keymap->items.first; kmi; kmi = kmi->next) {
+ if (wm_eventmatch(event, kmi)) {
+ wmOperator *op = handler->op;
+
+ PRINT("%s: item matched '%s'\n", __func__, kmi->idname);
+
+ /* weak, but allows interactive callback to not use rawkey */
+ event->keymap_idname = kmi->idname;
+
+ CTX_wm_manipulator_group_set(C, mgroup);
+
+ /* handler->op is called later, we want keymap op to be triggered here */
+ handler->op = NULL;
+ action |= wm_handler_operator_call(C, handlers, handler, event, kmi->ptr);
+ handler->op = op;
+
+ CTX_wm_manipulator_group_set(C, NULL);
+
+ if (action & WM_HANDLER_BREAK) {
+ if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) {
+ printf("%s: handled - and pass on! '%s'\n",
+ __func__, kmi->idname);
+ }
+ break;
+ }
+ else {
+ if (action & WM_HANDLER_HANDLED) {
+ if (G.debug & (G_DEBUG_EVENTS | G_DEBUG_HANDLERS)) {
+ printf("%s: handled - and pass on! '%s'\n",
+ __func__, kmi->idname);
+ }
+ }
+ else {
+ PRINT("%s: un-handled '%s'\n",
+ __func__, kmi->idname);
+ }
+ }
+ }
+ }
+ }
+ else {
+ PRINT("fail\n");
+ }
+
+ if (action & WM_HANDLER_BREAK) {
+ break;
+ }
+
+ if (is_mgroup_single) {
+ break;
+ }
+ }
+ }
+
+ /* restore the area */
+ CTX_wm_area_set(C, area);
+ CTX_wm_region_set(C, region);
+
+ if (handler->op) {
+ action |= wm_handler_operator_call(C, handlers, handler, event, NULL);
+ }
+ }
else {
/* modal, swallows all */
action |= wm_handler_operator_call(C, handlers, handler, event, NULL);
@@ -2276,13 +2559,15 @@ static int wm_event_inside_i(wmEvent *event, rcti *rect)
static ScrArea *area_event_inside(bContext *C, const int xy[2])
{
+ wmWindow *win = CTX_wm_window(C);
bScreen *screen = CTX_wm_screen(C);
- ScrArea *sa;
- if (screen)
- for (sa = screen->areabase.first; sa; sa = sa->next)
+ if (screen) {
+ ED_screen_areas_iter(win, screen, sa) {
if (BLI_rcti_isect_pt_v(&sa->totrct, xy))
return sa;
+ }
+ }
return NULL;
}
@@ -2340,17 +2625,19 @@ static void wm_paintcursor_test(bContext *C, const wmEvent *event)
static void wm_event_drag_test(wmWindowManager *wm, wmWindow *win, wmEvent *event)
{
+ bScreen *screen = WM_window_get_active_screen(win);
+
if (BLI_listbase_is_empty(&wm->drags)) {
return;
}
if (event->type == MOUSEMOVE || ISKEYMODIFIER(event->type)) {
- win->screen->do_draw_drag = true;
+ screen->do_draw_drag = true;
}
else if (event->type == ESCKEY) {
WM_drag_free_list(&wm->drags);
- win->screen->do_draw_drag = true;
+ screen->do_draw_drag = true;
}
else if (event->type == LEFTMOUSE && event->val == KM_RELEASE) {
event->type = EVT_DROP;
@@ -2366,17 +2653,11 @@ static void wm_event_drag_test(wmWindowManager *wm, wmWindow *win, wmEvent *even
event->customdatafree = 1;
/* clear drop icon */
- win->screen->do_draw_drag = true;
+ screen->do_draw_drag = true;
/* restore cursor (disabled, see wm_dragdrop.c) */
// WM_cursor_modal_restore(win);
}
-
- /* overlap fails otherwise */
- if (win->screen->do_draw_drag)
- if (win->drawmethod == USER_DRAW_OVERLAP)
- win->screen->do_draw = true;
-
}
/* filter out all events of the pie that spawned the last pie unless it's a release event */
@@ -2405,22 +2686,28 @@ void wm_event_do_handlers(bContext *C)
/* update key configuration before handling events */
WM_keyconfig_update(wm);
+ WM_manipulatorconfig_update(CTX_data_main(C));
for (win = wm->windows.first; win; win = win->next) {
+ bScreen *screen = WM_window_get_active_screen(win);
wmEvent *event;
-
- if (win->screen == NULL)
+
+ /* some safty checks - these should always be set! */
+ BLI_assert(WM_window_get_active_scene(win));
+ BLI_assert(WM_window_get_active_screen(win));
+ BLI_assert(WM_window_get_active_workspace(win));
+
+ if (screen == NULL)
wm_event_free_all(win);
else {
- Scene *scene = win->screen->scene;
-
+ Scene *scene = WM_window_get_active_scene(win);
+
if (scene) {
- int is_playing_sound = BKE_sound_scene_playing(win->screen->scene);
+ int is_playing_sound = BKE_sound_scene_playing(scene);
if (is_playing_sound != -1) {
bool is_playing_screen;
CTX_wm_window_set(C, win);
- CTX_wm_screen_set(C, win->screen);
CTX_data_scene_set(C, scene);
is_playing_screen = (ED_screen_animation_playing(wm) != NULL);
@@ -2437,7 +2724,8 @@ void wm_event_do_handlers(bContext *C)
int ncfra = time * (float)FPS + 0.5f;
if (ncfra != scene->r.cfra) {
scene->r.cfra = ncfra;
- ED_update_for_newframe(CTX_data_main(C), scene, 1);
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+ ED_update_for_newframe(CTX_data_main(C), depsgraph);
WM_event_add_notifier(C, NC_WINDOW, NULL);
}
}
@@ -2453,9 +2741,11 @@ void wm_event_do_handlers(bContext *C)
while ( (event = win->queue.first) ) {
int action = WM_HANDLER_CONTINUE;
+ /* active screen might change during handlers, update pointer */
+ screen = WM_window_get_active_screen(win);
+
if (G.debug & (G_DEBUG_HANDLERS | G_DEBUG_EVENTS) && !ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
printf("\n%s: Handling event\n", __func__);
-
WM_event_print(event);
}
@@ -2472,7 +2762,7 @@ void wm_event_do_handlers(bContext *C)
CTX_wm_window_set(C, win);
/* Clear tool-tip on mouse move. */
- if (win->screen->tool_tip && win->screen->tool_tip->exit_on_event) {
+ if (screen->tool_tip && screen->tool_tip->exit_on_event) {
if (ISMOUSE(event->type)) {
WM_tooltip_clear(C, win);
}
@@ -2496,8 +2786,7 @@ void wm_event_do_handlers(bContext *C)
return;
/* check for a tooltip */
- {
- bScreen *screen = CTX_wm_window(C)->screen;
+ if (screen == WM_window_get_active_screen(win)) {
if (screen->tool_tip && screen->tool_tip->timer) {
if ((event->type == TIMER) && (event->customdata == screen->tool_tip->timer)) {
WM_tooltip_init(C, win);
@@ -2512,13 +2801,12 @@ void wm_event_do_handlers(bContext *C)
wm_tweakevent_test(C, event, action);
if ((action & WM_HANDLER_BREAK) == 0) {
- ScrArea *sa;
ARegion *ar;
/* Note: setting subwin active should be done here, after modal handlers have been done */
if (event->type == MOUSEMOVE) {
/* state variables in screen, cursors. Also used in wm_draw.c, fails for modal handlers though */
- ED_screen_set_subwinactive(C, event);
+ ED_screen_set_active_region(C, &event->x);
/* for regions having custom cursors */
wm_paintcursor_test(C, event);
}
@@ -2528,12 +2816,12 @@ void wm_event_do_handlers(bContext *C)
}
#endif
- for (sa = win->screen->areabase.first; sa; sa = sa->next) {
+ ED_screen_areas_iter(win, screen, sa) {
/* after restoring a screen from SCREENMAXIMIZED we have to wait
* with the screen handling till the region coordinates are updated */
- if (win->screen->skip_handling == true) {
+ if (screen->skip_handling == true) {
/* restore for the next iteration of wm_event_do_handlers */
- win->screen->skip_handling = false;
+ screen->skip_handling = false;
break;
}
@@ -2560,9 +2848,48 @@ void wm_event_do_handlers(bContext *C)
wm_drags_check_ops(C, event);
}
}
-
+
+#ifdef USE_WORKSPACE_TOOL
+ /* How to solve properly?
+ *
+ * Handlers are stored in each region,
+ * however the tool-system swaps keymaps often and isn't stored
+ * per region.
+ *
+ * Need to investigate how this could be done better.
+ * We might need to add a more dynamic handler type that uses a callback
+ * to fetch its current keymap.
+ */
+ wmEventHandler sneaky_handler = {NULL};
+ if (ar->regiontype == RGN_TYPE_WINDOW) {
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ if (workspace->tool.keymap[0] &&
+ workspace->tool.spacetype == sa->spacetype)
+ {
+ wmKeyMap *km = WM_keymap_find_all(
+ C, workspace->tool.keymap, sa->spacetype, RGN_TYPE_WINDOW);
+ if (km != NULL) {
+ sneaky_handler.keymap = km;
+ /* Handle widgets first. */
+ wmEventHandler *handler_last = ar->handlers.last;
+ while (handler_last && handler_last->manipulator_map == NULL) {
+ handler_last = handler_last->prev;
+ }
+ /* Head of list or after last manipulator. */
+ BLI_insertlinkafter(&ar->handlers, handler_last, &sneaky_handler);
+ }
+ }
+ }
+#endif /* USE_WORKSPACE_TOOL */
+
action |= wm_handlers_do(C, event, &ar->handlers);
+#ifdef USE_WORKSPACE_TOOL
+ if (sneaky_handler.keymap) {
+ BLI_remlink(&ar->handlers, &sneaky_handler);
+ }
+#endif /* USE_WORKSPACE_TOOL */
+
/* fileread case (python), [#29489] */
if (CTX_wm_window(C) == NULL)
return;
@@ -2627,8 +2954,7 @@ void wm_event_do_handlers(bContext *C)
/* update key configuration after handling events */
WM_keyconfig_update(wm);
-
- GPU_ASSERT_NO_GL_ERRORS("wm_event_do_handlers");
+ WM_manipulatorconfig_update(CTX_data_main(C));
}
/* ********** filesector handling ************ */
@@ -2670,24 +2996,26 @@ void WM_event_add_fileselect(bContext *C, wmOperator *op)
if (handler->type == WM_HANDLER_FILESELECT) {
bScreen *screen = CTX_wm_screen(C);
- ScrArea *sa;
+ bool cancel_handler = true;
/* find the area with the file selector for this handler */
- for (sa = screen->areabase.first; sa; sa = sa->next) {
+ ED_screen_areas_iter(win, screen, sa) {
if (sa->spacetype == SPACE_FILE) {
SpaceFile *sfile = sa->spacedata.first;
if (sfile->op == handler->op) {
CTX_wm_area_set(C, sa);
wm_handler_fileselect_do(C, &win->modalhandlers, handler, EVT_FILESELECT_CANCEL);
+ cancel_handler = false;
break;
}
}
}
/* if not found we stop the handler without changing the screen */
- if (!sa)
+ if (cancel_handler) {
wm_handler_fileselect_do(C, &win->modalhandlers, handler, EVT_FILESELECT_EXTERNAL_CANCEL);
+ }
}
}
@@ -2741,6 +3069,34 @@ wmEventHandler *WM_event_add_modal_handler(bContext *C, wmOperator *op)
return handler;
}
+/**
+ * Modal handlers store a pointer to an area which might be freed while the handler runs.
+ * Use this function to NULL all handler pointers to \a old_area.
+ */
+void WM_event_modal_handler_area_replace(wmWindow *win, const ScrArea *old_area, ScrArea *new_area)
+{
+ for (wmEventHandler *handler = win->modalhandlers.first; handler; handler = handler->next) {
+ /* fileselect handler is quite special... it needs to keep old area stored in handler, so don't change it */
+ if ((handler->op_area == old_area) && (handler->type != WM_HANDLER_FILESELECT)) {
+ handler->op_area = new_area;
+ }
+ }
+}
+
+/**
+ * Modal handlers store a pointer to a region which might be freed while the handler runs.
+ * Use this function to NULL all handler pointers to \a old_region.
+ */
+void WM_event_modal_handler_region_replace(wmWindow *win, const ARegion *old_region, ARegion *new_region)
+{
+ for (wmEventHandler *handler = win->modalhandlers.first; handler; handler = handler->next) {
+ if (handler->op_region == old_region) {
+ handler->op_region = new_region;
+ handler->op_region_type = new_region ? new_region->regiontype : RGN_TYPE_WINDOW;
+ }
+ }
+}
+
wmEventHandler *WM_event_add_keymap_handler(ListBase *handlers, wmKeyMap *keymap)
{
wmEventHandler *handler;
diff --git a/source/blender/windowmanager/intern/wm_files.c b/source/blender/windowmanager/intern/wm_files.c
index da5ebd7abcd..efb3d0e7461 100644
--- a/source/blender/windowmanager/intern/wm_files.c
+++ b/source/blender/windowmanager/intern/wm_files.c
@@ -71,6 +71,7 @@
#include "DNA_scene_types.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "BKE_appdir.h"
#include "BKE_autoexec.h"
@@ -78,7 +79,6 @@
#include "BKE_blendfile.h"
#include "BKE_blender_undo.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_global.h"
#include "BKE_library.h"
#include "BKE_main.h"
@@ -88,6 +88,7 @@
#include "BKE_scene.h"
#include "BKE_screen.h"
#include "BKE_undo_system.h"
+#include "BKE_workspace.h"
#include "BLO_readfile.h"
#include "BLO_writefile.h"
@@ -123,8 +124,11 @@
#include "BPY_extern.h"
#endif
+#include "DEG_depsgraph.h"
+
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "wm.h"
#include "wm_files.h"
#include "wm_window.h"
@@ -163,7 +167,7 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist)
CTX_wm_window_set(C, win); /* needed by operator close callbacks */
WM_event_remove_handlers(C, &win->handlers);
WM_event_remove_handlers(C, &win->modalhandlers);
- ED_screen_exit(C, win, win->screen);
+ ED_screen_exit(C, win, WM_window_get_active_screen(win));
}
}
@@ -178,27 +182,12 @@ static void wm_window_match_init(bContext *C, ListBase *wmlist)
CTX_wm_menu_set(C, NULL);
ED_editors_exit(C);
-
- /* just had return; here from r12991, this code could just get removed?*/
-#if 0
- if (wm == NULL) return;
- if (G.fileflags & G_FILE_NO_UI) return;
-
- /* we take apart the used screens from non-active window */
- for (win = wm->windows.first; win; win = win->next) {
- BLI_strncpy(win->screenname, win->screen->id.name, MAX_ID_NAME);
- if (win != wm->winactive) {
- BLI_remlink(&G.main->screen, win->screen);
- //BLI_addtail(screenbase, win->screen);
- }
- }
-#endif
}
static void wm_window_substitute_old(wmWindowManager *wm, wmWindow *oldwin, wmWindow *win)
{
win->ghostwin = oldwin->ghostwin;
- win->multisamples = oldwin->multisamples;
+ win->gwnctx = oldwin->gwnctx;
win->active = oldwin->active;
if (win->active)
wm->winactive = win;
@@ -207,7 +196,7 @@ static void wm_window_substitute_old(wmWindowManager *wm, wmWindow *oldwin, wmWi
GHOST_SetWindowUserData(win->ghostwin, win); /* pointer back */
oldwin->ghostwin = NULL;
- oldwin->multisamples = 0;
+ oldwin->gwnctx = NULL;
win->eventstate = oldwin->eventstate;
oldwin->eventstate = NULL;
@@ -219,102 +208,127 @@ static void wm_window_substitute_old(wmWindowManager *wm, wmWindow *oldwin, wmWi
win->posy = oldwin->posy;
}
-/* match old WM with new, 4 cases:
- * 1- no current wm, no read wm: make new default
- * 2- no current wm, but read wm: that's OK, do nothing
- * 3- current wm, but not in file: try match screen names
- * 4- current wm, and wm in file: try match ghostwin
- */
-
-static void wm_window_match_do(bContext *C, ListBase *oldwmlist)
+static void wm_window_match_keep_current_wm(
+ const bContext *C, ListBase *current_wm_list,
+ const bool load_ui,
+ ListBase *r_new_wm_list)
{
- wmWindowManager *oldwm, *wm;
- wmWindow *oldwin, *win;
-
- /* cases 1 and 2 */
- if (BLI_listbase_is_empty(oldwmlist)) {
- if (G.main->wm.first) {
- /* nothing todo */
- }
- else {
- wm_add_default(C);
- }
- }
- else {
- /* cases 3 and 4 */
-
- /* we've read file without wm..., keep current one entirely alive */
- if (BLI_listbase_is_empty(&G.main->wm)) {
- bScreen *screen = NULL;
-
- /* when loading without UI, no matching needed */
- if (!(G.fileflags & G_FILE_NO_UI) && (screen = CTX_wm_screen(C))) {
-
- /* match oldwm to new dbase, only old files */
- for (wm = oldwmlist->first; wm; wm = wm->id.next) {
-
- for (win = wm->windows.first; win; win = win->next) {
- /* all windows get active screen from file */
- if (screen->winid == 0)
- win->screen = screen;
- else
- win->screen = ED_screen_duplicate(win, screen);
-
- BLI_strncpy(win->screenname, win->screen->id.name + 2, sizeof(win->screenname));
- win->screen->winid = win->winid;
- }
- }
+ wmWindowManager *wm = current_wm_list->first;
+ bScreen *screen = NULL;
+
+ /* match oldwm to new dbase, only old files */
+ wm->initialized &= ~WM_WINDOW_IS_INITIALIZED;
+
+ /* when loading without UI, no matching needed */
+ if (load_ui && (screen = CTX_wm_screen(C))) {
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ WorkSpace *workspace;
+
+ BKE_workspace_layout_find_global(G.main, screen, &workspace);
+ BKE_workspace_active_set(win->workspace_hook, workspace);
+ win->scene = CTX_data_scene(C);
+
+ /* all windows get active screen from file */
+ if (screen->winid == 0) {
+ WM_window_set_active_screen(win, workspace, screen);
+ }
+ else {
+ WorkSpaceLayout *layout_old = WM_window_get_active_layout(win);
+ WorkSpaceLayout *layout_new = ED_workspace_layout_duplicate(workspace, layout_old, win);
+
+ WM_window_set_active_layout(win, workspace, layout_new);
}
-
- G.main->wm = *oldwmlist;
-
- /* screens were read from file! */
- ED_screens_initialize(G.main->wm.first);
- }
- else {
- bool has_match = false;
- /* what if old was 3, and loaded 1? */
- /* this code could move to setup_appdata */
- oldwm = oldwmlist->first;
- wm = G.main->wm.first;
+ bScreen *win_screen = WM_window_get_active_screen(win);
+ win_screen->winid = win->winid;
+ }
+ }
- /* preserve key configurations in new wm, to preserve their keymaps */
- wm->keyconfigs = oldwm->keyconfigs;
- wm->addonconf = oldwm->addonconf;
- wm->defaultconf = oldwm->defaultconf;
- wm->userconf = oldwm->userconf;
+ *r_new_wm_list = *current_wm_list;
+}
- BLI_listbase_clear(&oldwm->keyconfigs);
- oldwm->addonconf = NULL;
- oldwm->defaultconf = NULL;
- oldwm->userconf = NULL;
+static void wm_window_match_replace_by_file_wm(
+ bContext *C, ListBase *current_wm_list, ListBase *readfile_wm_list,
+ ListBase *r_new_wm_list)
+{
+ wmWindowManager *oldwm = current_wm_list->first;
+ wmWindowManager *wm = readfile_wm_list->first; /* will become our new WM */
+ bool has_match = false;
- /* ensure making new keymaps and set space types */
- wm->initialized = 0;
- wm->winactive = NULL;
+ /* this code could move to setup_appdata */
- /* only first wm in list has ghostwins */
- for (win = wm->windows.first; win; win = win->next) {
- for (oldwin = oldwm->windows.first; oldwin; oldwin = oldwin->next) {
+ /* preserve key configurations in new wm, to preserve their keymaps */
+ wm->keyconfigs = oldwm->keyconfigs;
+ wm->addonconf = oldwm->addonconf;
+ wm->defaultconf = oldwm->defaultconf;
+ wm->userconf = oldwm->userconf;
- if (oldwin->winid == win->winid) {
- has_match = true;
+ BLI_listbase_clear(&oldwm->keyconfigs);
+ oldwm->addonconf = NULL;
+ oldwm->defaultconf = NULL;
+ oldwm->userconf = NULL;
- wm_window_substitute_old(wm, oldwin, win);
- }
- }
- }
+ /* ensure making new keymaps and set space types */
+ wm->initialized = 0;
+ wm->winactive = NULL;
- /* make sure at least one window is kept open so we don't lose the context, check T42303 */
- if (!has_match) {
- oldwin = oldwm->windows.first;
- win = wm->windows.first;
+ /* only first wm in list has ghostwins */
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ for (wmWindow *oldwin = oldwm->windows.first; oldwin; oldwin = oldwin->next) {
+ if (oldwin->winid == win->winid) {
+ has_match = true;
wm_window_substitute_old(wm, oldwin, win);
}
+ }
+ }
+ /* make sure at least one window is kept open so we don't lose the context, check T42303 */
+ if (!has_match) {
+ wm_window_substitute_old(wm, oldwm->windows.first, wm->windows.first);
+ }
+
+ wm_close_and_free_all(C, current_wm_list);
+
+ *r_new_wm_list = *readfile_wm_list;
+}
- wm_close_and_free_all(C, oldwmlist);
+/**
+ * Match old WM with new, 4 cases:
+ * 1) No current WM, no WM in file: Make new default.
+ * 2) No current WM, but WM in file: Keep current WM, do nothing else.
+ * 3) Current WM, but not in file: Keep current WM, update windows with screens from file.
+ * 4) Current WM, and WM in file: Try to keep current GHOST windows, use WM from file.
+ *
+ * \param r_new_wm_list: Return argument for the wm list to be used from now on.
+ */
+static void wm_window_match_do(
+ bContext *C,
+ ListBase *current_wm_list, ListBase *readfile_wm_list,
+ ListBase *r_new_wm_list)
+{
+ if (BLI_listbase_is_empty(current_wm_list)) {
+ /* case 1 */
+ if (BLI_listbase_is_empty(readfile_wm_list)) {
+ Main *bmain = CTX_data_main(C);
+ /* Neither current, no newly read file have a WM -> add the default one. */
+ wm_add_default(bmain, C);
+ *r_new_wm_list = bmain->wm;
+ }
+ /* case 2 */
+ else {
+ *r_new_wm_list = *readfile_wm_list;
+ }
+ }
+ else {
+ /* case 3 */
+ if (BLI_listbase_is_empty(readfile_wm_list)) {
+ /* We've read file without wm, keep current one entirely alive.
+ * Happens when reading pre 2.5 files (no WM back then) */
+ wm_window_match_keep_current_wm(C, current_wm_list, (G.fileflags & G_FILE_NO_UI) == 0, r_new_wm_list);
+ }
+ /* case 4 */
+ else {
+ wm_window_match_replace_by_file_wm(C, current_wm_list, readfile_wm_list, r_new_wm_list);
}
}
}
@@ -466,7 +480,7 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo
CTX_wm_window_set(C, wm->windows.first);
ED_editors_init(C);
- DAG_on_visible_update(CTX_data_main(C), true);
+ DEG_on_visible_update(CTX_data_main(C), true);
#ifdef WITH_PYTHON
if (is_startup_file) {
@@ -499,17 +513,11 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo
BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_VERSION_UPDATE);
BLI_callback_exec(CTX_data_main(C), NULL, BLI_CB_EVT_LOAD_POST);
- /* Would otherwise be handled by event loop.
- *
- * Disabled for startup file, since it causes problems when PyDrivers are used in the startup file.
- * While its possible state of startup file may be wrong,
- * in this case users nearly always load a file to replace the startup file. */
- if (G.background && (is_startup_file == false)) {
- Main *bmain = CTX_data_main(C);
- BKE_scene_update_tagged(bmain->eval_ctx, bmain, CTX_data_scene(C));
- }
-
+#if 1
WM_event_add_notifier(C, NC_WM | ND_FILEREAD, NULL);
+#else
+ WM_msg_publish_static(CTX_wm_message_bus(C), WM_MSG_STATICTYPE_FILE_READ);
+#endif
/* report any errors.
* currently disabled if addons aren't yet loaded */
@@ -522,6 +530,9 @@ static void wm_file_read_post(bContext *C, const bool is_startup_file, const boo
* a blend file and do anything since the screen
* won't be set to a valid value again */
CTX_wm_window_set(C, NULL); /* exits queues */
+
+ /* Ensure tools are registered. */
+ WM_toolsystem_init(C);
}
if (!G.background) {
@@ -563,7 +574,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
/* put aside screens to match with persistent windows later */
/* also exit screens and editors */
- wm_window_match_init(C, &wmbase);
+ wm_window_match_init(C, &wmbase);
/* confusing this global... */
G.relbase_valid = 1;
@@ -585,7 +596,7 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
}
/* match the read WM with current WM */
- wm_window_match_do(C, &wmbase);
+ wm_window_match_do(C, &wmbase, &G.main->wm, &G.main->wm);
WM_check(C); /* opens window(s), checks keymaps */
if (retval == BKE_BLENDFILE_READ_OK_USERPREFS) {
@@ -603,6 +614,10 @@ bool WM_file_read(bContext *C, const char *filepath, ReportList *reports)
success = true;
}
+#if 0
+ else if (retval == BKE_READ_EXOTIC_OK_OTHER)
+ BKE_undo_write(C, "Import file");
+#endif
else if (retval == BKE_READ_EXOTIC_FAIL_OPEN) {
BKE_reportf(reports, RPT_ERROR, "Cannot read file '%s': %s", filepath,
errno ? strerror(errno) : TIP_("unable to open the file"));
@@ -844,29 +859,20 @@ int wm_homefile_read(
/* prevent buggy files that had G_FILE_RELATIVE_REMAP written out by mistake. Screws up autosaves otherwise
* can remove this eventually, only in a 2.53 and older, now its not written */
G.fileflags &= ~G_FILE_RELATIVE_REMAP;
-
- if (use_userdef) {
+
+ if (use_userdef) {
/* check userdef before open window, keymaps etc */
wm_init_userdef(CTX_data_main(C), read_userdef_from_memory);
}
/* match the read WM with current WM */
- wm_window_match_do(C, &wmbase);
+ wm_window_match_do(C, &wmbase, &G.main->wm, &G.main->wm);
WM_check(C); /* opens window(s), checks keymaps */
G.main->name[0] = '\0';
- if (use_userdef) {
- /* When loading factory settings, the reset solid OpenGL lights need to be applied. */
- if (!G.background) {
- GPU_default_lights();
- }
- }
-
/* start with save preference untitled.blend */
G.save_over = 0;
- /* disable auto-play in startup.blend... */
- G.fileflags &= ~G_FILE_AUTOPLAY;
wm_file_read_post(C, true, use_userdef);
@@ -997,7 +1003,7 @@ static void wm_history_file_update(void)
/* screen can be NULL */
-static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **thumb_pt)
+static ImBuf *blend_file_thumb(const bContext *C, Scene *scene, bScreen *screen, BlendThumbnail **thumb_pt)
{
/* will be scaled down, but gives some nice oversampling */
ImBuf *ibuf;
@@ -1032,19 +1038,21 @@ static ImBuf *blend_file_thumb(Scene *scene, bScreen *screen, BlendThumbnail **t
}
/* gets scaled to BLEN_THUMB_SIZE */
+ Depsgraph *depsgraph = CTX_data_depsgraph(C);
+
if (scene->camera) {
ibuf = ED_view3d_draw_offscreen_imbuf_simple(
- scene, scene->camera,
+ depsgraph, scene, OB_SOLID, scene->camera,
BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
- IB_rect, V3D_OFSDRAW_NONE, OB_SOLID, R_ALPHAPREMUL, 0, NULL,
- NULL, NULL, err_out);
+ IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL,
+ NULL, err_out);
}
else {
ibuf = ED_view3d_draw_offscreen_imbuf(
- scene, v3d, ar,
+ depsgraph, scene, OB_SOLID, v3d, ar,
BLEN_THUMB_SIZE * 2, BLEN_THUMB_SIZE * 2,
IB_rect, V3D_OFSDRAW_NONE, R_ALPHAPREMUL, 0, NULL,
- NULL, NULL, err_out);
+ NULL, err_out);
}
if (ibuf) {
@@ -1137,7 +1145,7 @@ static int wm_file_write(bContext *C, const char *filepath, int fileflags, Repor
/* Main now can store a .blend thumbnail, usefull for background mode or thumbnail customization. */
main_thumb = thumb = CTX_data_main(C)->blen_thumb;
if ((U.flag & USER_SAVE_PREVIEWS) && BLI_thread_is_main()) {
- ibuf_thumb = blend_file_thumb(CTX_data_scene(C), CTX_wm_screen(C), &thumb);
+ ibuf_thumb = blend_file_thumb(C, CTX_data_scene(C), CTX_wm_screen(C), &thumb);
}
/* operator now handles overwrite checks */
@@ -1173,7 +1181,6 @@ static int wm_file_write(bContext *C, const char *filepath, int fileflags, Repor
}
SET_FLAG_FROM_TEST(G.fileflags, fileflags & G_FILE_COMPRESS, G_FILE_COMPRESS);
- SET_FLAG_FROM_TEST(G.fileflags, fileflags & G_FILE_AUTOPLAY, G_FILE_AUTOPLAY);
/* prevent background mode scripts from clobbering history */
if (do_history) {
@@ -1281,7 +1288,7 @@ void wm_autosave_timer(const bContext *C, wmWindowManager *wm, wmTimer *UNUSED(w
}
else {
/* save as regular blend file */
- int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_HISTORY);
+ int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
ED_editors_flush_edits(C, false);
@@ -1395,7 +1402,7 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
BLI_callback_exec(G.main, NULL, BLI_CB_EVT_SAVE_PRE);
/* check current window and close it if temp */
- if (win && win->screen->temp)
+ if (win && WM_window_is_temp_screen(win))
wm_window_close(C, wm, win);
/* update keymaps in user preferences */
@@ -1408,7 +1415,7 @@ static int wm_homefile_write_exec(bContext *C, wmOperator *op)
ED_editors_flush_edits(C, false);
/* force save as regular blend file */
- fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_HISTORY);
+ fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
if (BLO_write_file(CTX_data_main(C), filepath, fileflags | G_FILE_USERPREFS, op->reports, NULL) == 0) {
printf("fail\n");
@@ -1542,6 +1549,42 @@ void WM_OT_save_userpref(wmOperatorType *ot)
ot->exec = wm_userpref_write_exec;
}
+static int wm_workspace_configuration_file_write_exec(bContext *C, wmOperator *op)
+{
+ Main *bmain = CTX_data_main(C);
+ char filepath[FILE_MAX];
+
+ const char *app_template = U.app_template[0] ? U.app_template : NULL;
+ const char * const cfgdir = BKE_appdir_folder_id_create(BLENDER_USER_CONFIG, app_template);
+ if (cfgdir == NULL) {
+ BKE_report(op->reports, RPT_ERROR, "Unable to create workspace configuration file path");
+ return OPERATOR_CANCELLED;
+ }
+
+ BLI_path_join(filepath, sizeof(filepath), cfgdir, BLENDER_WORKSPACES_FILE, NULL);
+ printf("trying to save workspace configuration file at %s ", filepath);
+
+ if (BKE_blendfile_workspace_config_write(bmain, filepath, op->reports) != 0) {
+ printf("ok\n");
+ return OPERATOR_FINISHED;
+ }
+ else {
+ printf("fail\n");
+ }
+
+ return OPERATOR_CANCELLED;
+}
+
+void WM_OT_save_workspace_file(wmOperatorType *ot)
+{
+ ot->name = "Save Workspace Configuration";
+ ot->idname = "WM_OT_save_workspace_file";
+ ot->description = "Save workspaces of the current file as part of the user configuration";
+
+ ot->invoke = WM_operator_confirm;
+ ot->exec = wm_workspace_configuration_file_write_exec;
+}
+
static int wm_history_file_read_exec(bContext *UNUSED(C), wmOperator *UNUSED(op))
{
ED_file_read_bookmarks();
@@ -2085,9 +2128,11 @@ static int wm_save_as_mainfile_exec(bContext *C, wmOperator *op)
WM_event_add_notifier(C, NC_WM | ND_FILESAVE, NULL);
+#if 0 /* XXX: Remove? This is not currently defined as a valid property */
if (RNA_boolean_get(op->ptr, "exit")) {
wm_exit_schedule_delayed(C);
}
+#endif
return OPERATOR_FINISHED;
}
diff --git a/source/blender/windowmanager/intern/wm_files_link.c b/source/blender/windowmanager/intern/wm_files_link.c
index fb611290aa5..97f738f37da 100644
--- a/source/blender/windowmanager/intern/wm_files_link.c
+++ b/source/blender/windowmanager/intern/wm_files_link.c
@@ -59,7 +59,7 @@
#include "BLO_readfile.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
+#include "BKE_layer.h"
#include "BKE_library.h"
#include "BKE_library_remap.h"
#include "BKE_global.h"
@@ -69,13 +69,13 @@
#include "BKE_idcode.h"
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
#include "IMB_colormanagement.h"
#include "ED_screen.h"
-#include "GPU_material.h"
-
#include "RNA_access.h"
#include "RNA_define.h"
@@ -131,8 +131,8 @@ static short wm_link_append_flag(wmOperator *op)
if (RNA_boolean_get(op->ptr, "autoselect"))
flag |= FILE_AUTOSELECT;
- if (RNA_boolean_get(op->ptr, "active_layer"))
- flag |= FILE_ACTIVELAY;
+ if (RNA_boolean_get(op->ptr, "active_collection"))
+ flag |= FILE_ACTIVE_COLLECTION;
if ((prop = RNA_struct_find_property(op->ptr, "relative_path")) && RNA_property_boolean_get(op->ptr, prop))
flag |= FILE_RELPATH;
if (RNA_boolean_get(op->ptr, "link"))
@@ -211,7 +211,8 @@ static WMLinkAppendDataItem *wm_link_append_data_item_add(
return item;
}
-static void wm_link_do(WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, Scene *scene, View3D *v3d)
+static void wm_link_do(
+ WMLinkAppendData *lapp_data, ReportList *reports, Main *bmain, Scene *scene, ViewLayer *view_layer)
{
Main *mainl;
BlendHandle *bh;
@@ -258,7 +259,7 @@ static void wm_link_do(WMLinkAppendData *lapp_data, ReportList *reports, Main *b
continue;
}
- new_id = BLO_library_link_named_part_ex(mainl, &bh, item->idcode, item->name, flag, scene, v3d);
+ new_id = BLO_library_link_named_part_ex(mainl, &bh, item->idcode, item->name, flag, scene, view_layer);
if (new_id) {
/* If the link is successful, clear item's libs 'todo' flags.
@@ -268,15 +269,50 @@ static void wm_link_do(WMLinkAppendData *lapp_data, ReportList *reports, Main *b
}
}
- BLO_library_link_end(mainl, &bh, flag, scene, v3d);
+ BLO_library_link_end(mainl, &bh, flag, scene, view_layer);
BLO_blendhandle_close(bh);
}
}
+/**
+ * Check if an item defined by \a name and \a group can be appended/linked.
+ *
+ * \param reports: Optionally report an error when an item can't be appended/linked.
+ */
+static bool wm_link_append_item_poll(
+ ReportList *reports, const char *path, const char *group, const char *name, const bool do_append)
+{
+ short idcode;
+
+ if (!group || !name) {
+ printf("skipping %s\n", path);
+ return false;
+ }
+
+ idcode = BKE_idcode_from_name(group);
+
+ /* XXX For now, we do a nasty exception for workspace, forbid linking them.
+ * Not nice, ultimately should be solved! */
+ if (!BKE_idcode_is_linkable(idcode) && (do_append || idcode != ID_WS)) {
+ if (reports) {
+ if (do_append) {
+ BKE_reportf(reports, RPT_ERROR_INVALID_INPUT, "Can't append data-block '%s' of type '%s'", name, group);
+ }
+ else {
+ BKE_reportf(reports, RPT_ERROR_INVALID_INPUT, "Can't link data-block '%s' of type '%s'", name, group);
+ }
+ }
+ return false;
+ }
+
+ return true;
+}
+
static int wm_link_append_exec(bContext *C, wmOperator *op)
{
Main *bmain = CTX_data_main(C);
Scene *scene = CTX_data_scene(C);
+ ViewLayer *view_layer = CTX_data_view_layer(C);
PropertyRNA *prop;
WMLinkAppendData *lapp_data;
char path[FILE_MAX_LIBEXTRA], root[FILE_MAXDIR], libname[FILE_MAX_LIBEXTRA], relname[FILE_MAX];
@@ -319,6 +355,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
}
short flag = wm_link_append_flag(op);
+ const bool do_append = (flag & FILE_LINK) == 0;
/* sanity checks for flag */
if (scene && scene->id.lib) {
@@ -332,8 +369,8 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
/* from here down, no error returns */
- if (scene && RNA_boolean_get(op->ptr, "autoselect")) {
- BKE_scene_base_deselect_all(scene);
+ if (view_layer && RNA_boolean_get(op->ptr, "autoselect")) {
+ BKE_view_layer_base_deselect_all(view_layer);
}
/* tag everything, all untagged data can be made local
@@ -356,7 +393,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
BLI_join_dirfile(path, sizeof(path), root, relname);
if (BLO_library_path_explode(path, libname, &group, &name)) {
- if (!group || !name) {
+ if (!wm_link_append_item_poll(NULL, path, group, name, do_append)) {
continue;
}
@@ -377,8 +414,8 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
if (BLO_library_path_explode(path, libname, &group, &name)) {
WMLinkAppendDataItem *item;
- if (!group || !name) {
- printf("skipping %s\n", path);
+
+ if (!wm_link_append_item_poll(op->reports, path, group, name, do_append)) {
continue;
}
@@ -409,7 +446,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
/* XXX We'd need re-entrant locking on Main for this to work... */
/* BKE_main_lock(bmain); */
- wm_link_do(lapp_data, op->reports, bmain, scene, CTX_wm_view3d(C));
+ wm_link_do(lapp_data, op->reports, bmain, scene, view_layer);
/* BKE_main_unlock(bmain); */
@@ -418,7 +455,7 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
IMB_colormanagement_check_file_config(bmain);
/* append, rather than linking */
- if ((flag & FILE_LINK) == 0) {
+ if (do_append) {
const bool set_fake = RNA_boolean_get(op->ptr, "set_fake");
const bool use_recursive = RNA_boolean_get(op->ptr, "use_recursive");
@@ -449,13 +486,17 @@ static int wm_link_append_exec(bContext *C, wmOperator *op)
* link into other scenes from this blend file */
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
+ /* TODO(sergey): Use proper flag for tagging here. */
+
+ /* TODO (dalai): Temporary solution!
+ * Ideally we only need to tag the new objects themselves, not the scene. This way we'll avoid flush of
+ * collection properties to all objects and limit update to the particular object only.
+ * But afraid first we need to change collection evaluation in DEG according to depsgraph manifesto.
+ */
+ DEG_id_tag_update(&scene->id, 0);
+
/* recreate dependency graph to include new objects */
- if (scene) {
- DAG_scene_relations_rebuild(bmain, scene);
- }
-
- /* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */
- GPU_materials_free();
+ DEG_relations_tag_update(bmain);
/* XXX TODO: align G.lib with other directory storage (like last opened image etc...) */
BLI_strncpy(G.lib, root, FILE_MAX);
@@ -477,8 +518,8 @@ static void wm_link_append_properties_common(wmOperatorType *ot, bool is_link)
prop = RNA_def_boolean(ot->srna, "autoselect", true,
"Select", "Select new objects");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
- prop = RNA_def_boolean(ot->srna, "active_layer", true,
- "Active Layer", "Put new objects on the active layer");
+ prop = RNA_def_boolean(ot->srna, "active_collection", true,
+ "Active Collection", "Put new objects on the active collection");
RNA_def_property_flag(prop, PROP_SKIP_SAVE);
prop = RNA_def_boolean(ot->srna, "instance_groups", is_link,
"Instance Groups", "Create Dupli-Group instances for each group");
@@ -558,7 +599,7 @@ static int wm_lib_relocate_invoke(bContext *C, wmOperator *op, const wmEvent *UN
}
static void lib_relocate_do(
- Main *bmain, Scene *scene,
+ Main *bmain,
Library *library, WMLinkAppendData *lapp_data, ReportList *reports, const bool do_reload)
{
ListBase *lbarray[MAX_LIBARRAY];
@@ -748,10 +789,7 @@ static void lib_relocate_do(
BKE_main_id_tag_all(bmain, LIB_TAG_PRE_EXISTING, false);
/* recreate dependency graph to include new objects */
- DAG_scene_relations_rebuild(bmain, scene);
-
- /* free gpu materials, some materials depend on existing objects, such as lamps so freeing correctly refreshes */
- GPU_materials_free();
+ DEG_relations_tag_update(bmain);
}
void WM_lib_reload(Library *lib, bContext *C, ReportList *reports)
@@ -771,7 +809,7 @@ void WM_lib_reload(Library *lib, bContext *C, ReportList *reports)
wm_link_append_data_library_add(lapp_data, lib->filepath);
- lib_relocate_do(CTX_data_main(C), CTX_data_scene(C), lib, lapp_data, reports, true);
+ lib_relocate_do(CTX_data_main(C), lib, lapp_data, reports, true);
wm_link_append_data_free(lapp_data);
@@ -788,7 +826,6 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
if (lib) {
Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
PropertyRNA *prop;
WMLinkAppendData *lapp_data;
@@ -882,7 +919,7 @@ static int wm_lib_relocate_exec_do(bContext *C, wmOperator *op, bool do_reload)
lapp_data->flag |= BLO_LIBLINK_USE_PLACEHOLDERS | BLO_LIBLINK_FORCE_INDIRECT;
}
- lib_relocate_do(bmain, scene, lib, lapp_data, op->reports, do_reload);
+ lib_relocate_do(bmain, lib, lapp_data, op->reports, do_reload);
wm_link_append_data_free(lapp_data);
diff --git a/source/blender/windowmanager/intern/wm_gesture.c b/source/blender/windowmanager/intern/wm_gesture.c
index 1a4381a1275..2c3583a9f02 100644
--- a/source/blender/windowmanager/intern/wm_gesture.c
+++ b/source/blender/windowmanager/intern/wm_gesture.c
@@ -45,15 +45,14 @@
#include "BKE_context.h"
-
#include "WM_api.h"
#include "WM_types.h"
#include "wm.h"
-#include "wm_subwindow.h"
#include "wm_draw.h"
-#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
#include "BIF_glutil.h"
@@ -64,40 +63,37 @@ wmGesture *WM_gesture_new(bContext *C, const wmEvent *event, int type)
wmGesture *gesture = MEM_callocN(sizeof(wmGesture), "new gesture");
wmWindow *window = CTX_wm_window(C);
ARegion *ar = CTX_wm_region(C);
- int sx, sy;
BLI_addtail(&window->gesture, gesture);
gesture->type = type;
gesture->event_type = event->type;
- gesture->swinid = ar->swinid; /* means only in area-region context! */
+ gesture->winrct = ar->winrct;
gesture->userdata_free = true; /* Free if userdata is set. */
gesture->modal_state = GESTURE_MODAL_NOP;
- wm_subwindow_origin_get(window, gesture->swinid, &sx, &sy);
-
if (ELEM(type, WM_GESTURE_RECT, WM_GESTURE_CROSS_RECT, WM_GESTURE_TWEAK,
WM_GESTURE_CIRCLE, WM_GESTURE_STRAIGHTLINE))
{
rcti *rect = MEM_callocN(sizeof(rcti), "gesture rect new");
gesture->customdata = rect;
- rect->xmin = event->x - sx;
- rect->ymin = event->y - sy;
+ rect->xmin = event->x - gesture->winrct.xmin;
+ rect->ymin = event->y - gesture->winrct.ymin;
if (type == WM_GESTURE_CIRCLE) {
/* caller is responsible for initializing 'xmax' to radius. */
}
else {
- rect->xmax = event->x - sx;
- rect->ymax = event->y - sy;
+ rect->xmax = event->x - gesture->winrct.xmin;
+ rect->ymax = event->y - gesture->winrct.ymin;
}
}
else if (ELEM(type, WM_GESTURE_LINES, WM_GESTURE_LASSO)) {
short *lasso;
gesture->points_alloc = 1024;
gesture->customdata = lasso = MEM_mallocN(sizeof(short[2]) * gesture->points_alloc, "lasso points");
- lasso[0] = event->x - sx;
- lasso[1] = event->y - sy;
+ lasso[0] = event->x - gesture->winrct.xmin;
+ lasso[1] = event->y - gesture->winrct.ymin;
gesture->points = 1;
}
@@ -166,69 +162,99 @@ int wm_gesture_evaluate(wmGesture *gesture)
/* ******************* gesture draw ******************* */
-static void wm_gesture_draw_rect(wmGesture *gt)
+static void wm_gesture_draw_line(wmGesture *gt)
{
rcti *rect = (rcti *)gt->customdata;
-
- glEnable(GL_BLEND);
- glColor4f(1.0, 1.0, 1.0, 0.05);
- glBegin(GL_QUADS);
- glVertex2s(rect->xmax, rect->ymin);
- glVertex2s(rect->xmax, rect->ymax);
- glVertex2s(rect->xmin, rect->ymax);
- glVertex2s(rect->xmin, rect->ymin);
- glEnd();
- glDisable(GL_BLEND);
-
- GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- glColor3ub(96, 96, 96);
- GPU_basic_shader_line_stipple(1, 0xCCCC);
- sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
- glColor3ub(255, 255, 255);
- GPU_basic_shader_line_stipple(1, 0x3333);
- sdrawbox(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+
+ uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 8.0f);
+
+ float xmin = (float)rect->xmin;
+ float ymin = (float)rect->ymin;
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(shdr_pos, xmin, ymin);
+ immVertex2f(shdr_pos, (float)rect->xmax, (float)rect->ymax);
+ immEnd();
+
+ immUnbindProgram();
}
-static void wm_gesture_draw_line(wmGesture *gt)
+static void wm_gesture_draw_rect(wmGesture *gt)
{
rcti *rect = (rcti *)gt->customdata;
-
- GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE);
- glColor3ub(96, 96, 96);
- GPU_basic_shader_line_stipple(1, 0xAAAA);
- sdrawline(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
- glColor3ub(255, 255, 255);
- GPU_basic_shader_line_stipple(1, 0x5555);
- sdrawline(rect->xmin, rect->ymin, rect->xmax, rect->ymax);
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
+
+ uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_I32, 2, GWN_FETCH_INT_TO_FLOAT);
+
+ glEnable(GL_BLEND);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.05f);
+
+ immRecti(shdr_pos, rect->xmin, rect->ymin, rect->xmax, rect->ymax);
+
+ immUnbindProgram();
+
+ glDisable(GL_BLEND);
+
+ shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 8.0f);
+
+ imm_draw_box_wire_2d(shdr_pos, (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, (float)rect->ymax);
+
+ immUnbindProgram();
+
+ // wm_gesture_draw_line(gt); // draws a diagonal line in the lined box to test wm_gesture_draw_line
}
static void wm_gesture_draw_circle(wmGesture *gt)
{
rcti *rect = (rcti *)gt->customdata;
- glTranslatef((float)rect->xmin, (float)rect->ymin, 0.0f);
-
glEnable(GL_BLEND);
- glColor4f(1.0, 1.0, 1.0, 0.05);
- glutil_draw_filled_arc(0.0, M_PI * 2.0, rect->xmax, 40);
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+
+ immUniformColor4f(1.0f, 1.0f, 1.0f, 0.05f);
+ imm_draw_circle_fill_2d(shdr_pos, (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, 40);
+
+ immUnbindProgram();
+
glDisable(GL_BLEND);
-
- // for USE_GLSL works bad because of no relation between lines
- GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- glColor3ub(96, 96, 96);
- GPU_basic_shader_line_stipple(1, 0xAAAA);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, rect->xmax, 40);
- glColor3ub(255, 255, 255);
- GPU_basic_shader_line_stipple(1, 0x5555);
- glutil_draw_lined_arc(0.0, M_PI * 2.0, rect->xmax, 40);
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
- glTranslatef(-rect->xmin, -rect->ymin, 0.0f);
-
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 4.0f);
+
+ imm_draw_circle_wire_2d(shdr_pos, (float)rect->xmin, (float)rect->ymin, (float)rect->xmax, 40);
+
+ immUnbindProgram();
}
struct LassoFillData {
@@ -243,14 +269,14 @@ static void draw_filled_lasso_px_cb(int x, int x_end, int y, void *user_data)
memset(col, 0x10, x_end - x);
}
-static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
+static void draw_filled_lasso(wmGesture *gt)
{
const short *lasso = (short *)gt->customdata;
const int tot = gt->points;
int (*moves)[2] = MEM_mallocN(sizeof(*moves) * (tot + 1), __func__);
int i;
rcti rect;
- rcti rect_win;
+ float red[4] = {1.0f, 0.0f, 0.0f, 0.0f};
for (i = 0; i < tot; i++, lasso += 2) {
moves[i][0] = lasso[0];
@@ -259,10 +285,9 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
BLI_lasso_boundbox(&rect, (const int (*)[2])moves, tot);
- wm_subwindow_rect_get(win, gt->swinid, &rect_win);
- BLI_rcti_translate(&rect, rect_win.xmin, rect_win.ymin);
- BLI_rcti_isect(&rect_win, &rect, &rect);
- BLI_rcti_translate(&rect, -rect_win.xmin, -rect_win.ymin);
+ BLI_rcti_translate(&rect, gt->winrct.xmin, gt->winrct.ymin);
+ BLI_rcti_isect(&gt->winrct, &rect, &rect);
+ BLI_rcti_translate(&rect, -gt->winrct.xmin, -gt->winrct.ymin);
/* highly unlikely this will fail, but could crash if (tot == 0) */
if (BLI_rcti_is_empty(&rect) == false) {
@@ -276,66 +301,72 @@ static void draw_filled_lasso(wmWindow *win, wmGesture *gt)
(const int (*)[2])moves, tot,
draw_filled_lasso_px_cb, &lasso_fill_data);
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
+ /* Additive Blending */
+ glEnable(GL_BLEND);
+ glBlendFunc(GL_ONE, GL_ONE);
- glColor4f(1, 1, 1, 1);
- glPixelTransferf(GL_RED_BIAS, 1);
- glPixelTransferf(GL_GREEN_BIAS, 1);
- glPixelTransferf(GL_BLUE_BIAS, 1);
+ GLint unpack_alignment;
+ glGetIntegerv(GL_UNPACK_ALIGNMENT, &unpack_alignment);
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
- glEnable(GL_BLEND);
- glaDrawPixelsTex(rect.xmin, rect.ymin, w, h, GL_ALPHA, GL_UNSIGNED_BYTE, GL_NEAREST, pixel_buf);
- glDisable(GL_BLEND);
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_SHUFFLE_COLOR);
+ GPU_shader_bind(state.shader);
+ GPU_shader_uniform_vector(state.shader, GPU_shader_get_uniform(state.shader, "shuffle"), 4, 1, red);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ immDrawPixelsTex(&state, rect.xmin, rect.ymin, w, h, GL_RED, GL_UNSIGNED_BYTE, GL_NEAREST, pixel_buf, 1.0f, 1.0f, NULL);
- glPixelTransferf(GL_RED_BIAS, 0);
- glPixelTransferf(GL_GREEN_BIAS, 0);
- glPixelTransferf(GL_BLUE_BIAS, 0);
+ GPU_shader_unbind();
- glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
+ glPixelStorei(GL_UNPACK_ALIGNMENT, unpack_alignment);
MEM_freeN(pixel_buf);
+
+ glDisable(GL_BLEND);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
}
MEM_freeN(moves);
}
-static void wm_gesture_draw_lasso(wmWindow *win, wmGesture *gt, bool filled)
+static void wm_gesture_draw_lasso(wmGesture *gt, bool filled)
{
const short *lasso = (short *)gt->customdata;
int i;
if (filled) {
- draw_filled_lasso(win, gt);
+ draw_filled_lasso(gt);
}
- // for USE_GLSL can't check this yet
- GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- glColor3ub(96, 96, 96);
- GPU_basic_shader_line_stipple(1, 0xAAAA);
- glBegin(GL_LINE_STRIP);
- for (i = 0; i < gt->points; i++, lasso += 2)
- glVertex2sv(lasso);
- if (gt->type == WM_GESTURE_LASSO)
- glVertex2sv((short *)gt->customdata);
- glEnd();
-
- glColor3ub(255, 255, 255);
- GPU_basic_shader_line_stipple(1, 0x5555);
- glBegin(GL_LINE_STRIP);
- lasso = (short *)gt->customdata;
- for (i = 0; i < gt->points; i++, lasso += 2)
- glVertex2sv(lasso);
- if (gt->type == WM_GESTURE_LASSO)
- glVertex2sv((short *)gt->customdata);
- glEnd();
-
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
-
+ const int numverts = gt->points;
+
+ /* Nothing to draw, do early output. */
+ if (numverts < 2) {
+ return;
+ }
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 2.0f);
+
+ immBegin((gt->type == WM_GESTURE_LASSO) ? GWN_PRIM_LINE_LOOP : GWN_PRIM_LINE_STRIP, numverts);
+
+ for (i = 0; i < gt->points; i++, lasso += 2) {
+ immVertex2f(shdr_pos, (float)lasso[0], (float)lasso[1]);
+ }
+
+ immEnd();
+
+ immUnbindProgram();
}
static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt)
@@ -344,28 +375,52 @@ static void wm_gesture_draw_cross(wmWindow *win, wmGesture *gt)
const int winsize_x = WM_window_pixels_x(win);
const int winsize_y = WM_window_pixels_y(win);
- GPU_basic_shader_bind(GPU_SHADER_LINE | GPU_SHADER_STIPPLE | GPU_SHADER_USE_COLOR);
- glColor3ub(96, 96, 96);
- GPU_basic_shader_line_stipple(1, 0xCCCC);
- sdrawline(rect->xmin - winsize_x, rect->ymin, rect->xmin + winsize_x, rect->ymin);
- sdrawline(rect->xmin, rect->ymin - winsize_y, rect->xmin, rect->ymin + winsize_y);
-
- glColor3ub(255, 255, 255);
- GPU_basic_shader_line_stipple(1, 0x3333);
- sdrawline(rect->xmin - winsize_x, rect->ymin, rect->xmin + winsize_x, rect->ymin);
- sdrawline(rect->xmin, rect->ymin - winsize_y, rect->xmin, rect->ymin + winsize_y);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ float x1, x2, y1, y2;
+
+ const uint shdr_pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_LINE_DASHED_UNIFORM_COLOR);
+
+ float viewport_size[4];
+ glGetFloatv(GL_VIEWPORT, viewport_size);
+ immUniform2f("viewport_size", viewport_size[2], viewport_size[3]);
+
+ immUniform1i("num_colors", 2); /* "advanced" mode */
+ immUniformArray4fv("colors", (float *)(float[][4]){{0.4f, 0.4f, 0.4f, 1.0f}, {1.0f, 1.0f, 1.0f, 1.0f}}, 2);
+ immUniform1f("dash_width", 8.0f);
+
+ immBegin(GWN_PRIM_LINES, 4);
+
+ x1 = (float)(rect->xmin - winsize_x);
+ y1 = (float)rect->ymin;
+ x2 = (float)(rect->xmin + winsize_x);
+ y2 = y1;
+
+ immVertex2f(shdr_pos, x1, y1);
+ immVertex2f(shdr_pos, x2, y2);
+
+ x1 = (float)rect->xmin;
+ y1 = (float)(rect->ymin - winsize_y);
+ x2 = x1;
+ y2 = (float)(rect->ymin + winsize_y);
+
+ immVertex2f(shdr_pos, x1, y1);
+ immVertex2f(shdr_pos, x2, y2);
+
+ immEnd();
+
+ immUnbindProgram();
}
/* called in wm_draw.c */
void wm_gesture_draw(wmWindow *win)
{
wmGesture *gt = (wmGesture *)win->gesture.first;
-
- GPU_basic_shader_line_width(1);
+
+ glLineWidth(1.0f);
for (; gt; gt = gt->next) {
/* all in subwindow space */
- wmSubWindowSet(win, gt->swinid);
+ wmViewport(&gt->winrct);
if (gt->type == WM_GESTURE_RECT)
wm_gesture_draw_rect(gt);
@@ -382,9 +437,9 @@ void wm_gesture_draw(wmWindow *win)
}
}
else if (gt->type == WM_GESTURE_LINES)
- wm_gesture_draw_lasso(win, gt, false);
+ wm_gesture_draw_lasso(gt, false);
else if (gt->type == WM_GESTURE_LASSO)
- wm_gesture_draw_lasso(win, gt, true);
+ wm_gesture_draw_lasso(gt, true);
else if (gt->type == WM_GESTURE_STRAIGHTLINE)
wm_gesture_draw_line(gt);
}
@@ -392,12 +447,8 @@ void wm_gesture_draw(wmWindow *win)
void wm_gesture_tag_redraw(bContext *C)
{
- wmWindow *win = CTX_wm_window(C);
bScreen *screen = CTX_wm_screen(C);
- ARegion *ar = CTX_wm_region(C);
if (screen)
screen->do_draw_gesture = true;
-
- wm_tag_redraw_overlay(win, ar);
}
diff --git a/source/blender/windowmanager/intern/wm_gesture_ops.c b/source/blender/windowmanager/intern/wm_gesture_ops.c
index a554727cacd..01184f47920 100644
--- a/source/blender/windowmanager/intern/wm_gesture_ops.c
+++ b/source/blender/windowmanager/intern/wm_gesture_ops.c
@@ -47,7 +47,6 @@
#include "wm.h"
#include "wm_event_types.h"
#include "wm_event_system.h"
-#include "wm_subwindow.h"
#include "ED_screen.h"
@@ -198,18 +197,15 @@ int WM_gesture_border_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmGesture *gesture = op->customdata;
rcti *rect = gesture->customdata;
- int sx, sy;
if (event->type == MOUSEMOVE) {
- wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
-
if (gesture->type == WM_GESTURE_CROSS_RECT && gesture->is_active == false) {
- rect->xmin = rect->xmax = event->x - sx;
- rect->ymin = rect->ymax = event->y - sy;
+ rect->xmin = rect->xmax = event->x - gesture->winrct.xmin;
+ rect->ymin = rect->ymax = event->y - gesture->winrct.ymin;
}
else {
- rect->xmax = event->x - sx;
- rect->ymax = event->y - sy;
+ rect->xmax = event->x - gesture->winrct.xmin;
+ rect->ymax = event->y - gesture->winrct.ymin;
}
gesture_border_apply_rect(op);
@@ -333,13 +329,11 @@ int WM_gesture_circle_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmGesture *gesture = op->customdata;
rcti *rect = gesture->customdata;
- int sx, sy;
if (event->type == MOUSEMOVE) {
- wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
- rect->xmin = event->x - sx;
- rect->ymin = event->y - sy;
+ rect->xmin = event->x - gesture->winrct.xmin;
+ rect->ymin = event->y - gesture->winrct.ymin;
wm_gesture_tag_redraw(C);
@@ -464,24 +458,22 @@ static void gesture_tweak_modal(bContext *C, const wmEvent *event)
wmWindow *window = CTX_wm_window(C);
wmGesture *gesture = window->tweak;
rcti *rect = gesture->customdata;
- int sx, sy, val;
+ int val;
switch (event->type) {
case MOUSEMOVE:
case INBETWEEN_MOUSEMOVE:
- wm_subwindow_origin_get(window, gesture->swinid, &sx, &sy);
-
- rect->xmax = event->x - sx;
- rect->ymax = event->y - sy;
+ rect->xmax = event->x - gesture->winrct.xmin;
+ rect->ymax = event->y - gesture->winrct.ymin;
if ((val = wm_gesture_evaluate(gesture))) {
wmEvent tevent;
wm_event_init_from_window(window, &tevent);
/* We want to get coord from start of drag, not from point where it becomes a tweak event, see T40549 */
- tevent.x = rect->xmin + sx;
- tevent.y = rect->ymin + sy;
+ tevent.x = rect->xmin + gesture->winrct.xmin;
+ tevent.y = rect->ymin + gesture->winrct.ymin;
if (gesture->event_type == LEFTMOUSE)
tevent.type = EVT_TWEAK_L;
else if (gesture->event_type == RIGHTMOUSE)
@@ -617,7 +609,6 @@ static void gesture_lasso_apply(bContext *C, wmOperator *op)
int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
{
wmGesture *gesture = op->customdata;
- int sx, sy;
switch (event->type) {
case MOUSEMOVE:
@@ -625,8 +616,6 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
wm_gesture_tag_redraw(C);
- wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
-
if (gesture->points == gesture->points_alloc) {
gesture->points_alloc *= 2;
gesture->customdata = MEM_reallocN(gesture->customdata, sizeof(short[2]) * gesture->points_alloc);
@@ -637,15 +626,15 @@ int WM_gesture_lasso_modal(bContext *C, wmOperator *op, const wmEvent *event)
short *lasso = gesture->customdata;
lasso += (2 * gesture->points - 2);
- x = (event->x - sx - lasso[0]);
- y = (event->y - sy - lasso[1]);
+ x = (event->x - gesture->winrct.xmin - lasso[0]);
+ y = (event->y - gesture->winrct.ymin - lasso[1]);
/* make a simple distance check to get a smoother lasso
* add only when at least 2 pixels between this and previous location */
if ((x * x + y * y) > 4) {
lasso += 2;
- lasso[0] = event->x - sx;
- lasso[1] = event->y - sy;
+ lasso[0] = event->x - gesture->winrct.xmin;
+ lasso[1] = event->y - gesture->winrct.ymin;
gesture->points++;
}
}
@@ -813,18 +802,15 @@ int WM_gesture_straightline_modal(bContext *C, wmOperator *op, const wmEvent *ev
{
wmGesture *gesture = op->customdata;
rcti *rect = gesture->customdata;
- int sx, sy;
if (event->type == MOUSEMOVE) {
- wm_subwindow_origin_get(CTX_wm_window(C), gesture->swinid, &sx, &sy);
-
if (gesture->is_active == false) {
- rect->xmin = rect->xmax = event->x - sx;
- rect->ymin = rect->ymax = event->y - sy;
+ rect->xmin = rect->xmax = event->x - gesture->winrct.xmin;
+ rect->ymin = rect->ymax = event->y - gesture->winrct.ymin;
}
else {
- rect->xmax = event->x - sx;
- rect->ymax = event->y - sy;
+ rect->xmax = event->x - gesture->winrct.xmin;
+ rect->ymax = event->y - gesture->winrct.ymin;
gesture_straightline_apply(C, op);
}
diff --git a/source/blender/windowmanager/intern/wm_init_exit.c b/source/blender/windowmanager/intern/wm_init_exit.c
index 52682523212..1f17efa0845 100644
--- a/source/blender/windowmanager/intern/wm_init_exit.c
+++ b/source/blender/windowmanager/intern/wm_init_exit.c
@@ -86,9 +86,6 @@
#include "BPY_extern.h"
#endif
-#ifdef WITH_GAMEENGINE
-# include "BL_System.h"
-#endif
#include "GHOST_Path-api.h"
#include "GHOST_C-api.h"
@@ -96,6 +93,7 @@
#include "WM_api.h"
#include "WM_types.h"
+#include "WM_message.h"
#include "wm_cursors.h"
#include "wm_event_system.h"
@@ -119,14 +117,17 @@
#include "BLF_api.h"
#include "BLT_lang.h"
-#include "GPU_buffers.h"
+#include "GPU_material.h"
#include "GPU_draw.h"
#include "GPU_init_exit.h"
-#include "BKE_depsgraph.h"
#include "BKE_sound.h"
#include "COM_compositor.h"
+#include "DEG_depsgraph.h"
+
+#include "DRW_engine.h"
+
#ifdef WITH_OPENSUBDIV
# include "BKE_subsurf.h"
#endif
@@ -135,6 +136,7 @@ CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_OPERATORS, "wm.operator");
CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_HANDLERS, "wm.handler");
CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_EVENTS, "wm.event");
CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_KEYMAPS, "wm.keymap");
+CLG_LOGREF_DECLARE_GLOBAL(WM_LOG_TOOLS, "wm.tool");
static void wm_init_reports(bContext *C)
{
@@ -153,6 +155,40 @@ static void wm_free_reports(bContext *C)
bool wm_start_with_console = false; /* used in creator.c */
+/**
+ * Since we cannot know in advance if we will require the draw manager
+ * context when starting blender in background mode (specially true with
+ * scripts) we deferre the ghost initialization the most as possible
+ * so that it does not break anything that can run in headless mode (as in
+ * without display server attached).
+ **/
+static bool opengl_is_init = false;
+
+void WM_init_opengl(void)
+{
+ /* must be called only once */
+ BLI_assert(opengl_is_init == false);
+
+ if (G.background) {
+ /* Ghost is still not init elsewhere in background mode. */
+ wm_ghost_init(NULL);
+ }
+
+ /* Needs to be first to have an ogl context bound. */
+ DRW_opengl_context_create();
+
+ GPU_init();
+ GPU_set_mipmap(true);
+ GPU_set_linear_mipmap(true);
+ GPU_set_anisotropic(U.anisotropic_filter);
+ GPU_set_gpu_mipmapping(U.use_gpu_mipmap);
+
+#ifdef WITH_OPENSUBDIV
+ BKE_subsurf_osd_init();
+#endif
+ opengl_is_init = true;
+}
+
/* only called once, for startup */
void WM_init(bContext *C, int argc, const char **argv)
{
@@ -161,6 +197,7 @@ void WM_init(bContext *C, int argc, const char **argv)
wm_ghost_init(C); /* note: it assigns C to ghost! */
wm_init_cursor_data();
}
+
GHOST_CreateSystemPaths();
BKE_addon_pref_type_init();
@@ -168,33 +205,37 @@ void WM_init(bContext *C, int argc, const char **argv)
wm_operatortype_init();
WM_menutype_init();
WM_uilisttype_init();
+ wm_manipulatortype_init();
+ wm_manipulatorgrouptype_init();
ED_undosys_type_init();
BKE_library_callback_free_window_manager_set(wm_close_and_free); /* library.c */
BKE_library_callback_free_notifier_reference_set(WM_main_remove_notifier_reference); /* library.c */
+ BKE_region_callback_free_manipulatormap_set(wm_manipulatormap_remove); /* screen.c */
+ BKE_region_callback_refresh_tag_manipulatormap_set(WM_manipulatormap_tag_refresh);
BKE_library_callback_remap_editor_id_reference_set(WM_main_remap_editor_id_reference); /* library.c */
BKE_blender_callback_test_break_set(wm_window_testbreak); /* blender.c */
BKE_spacedata_callback_id_remap_set(ED_spacedata_id_remap); /* screen.c */
- DAG_editors_update_cb(ED_render_id_flush_update,
- ED_render_scene_update,
- ED_render_scene_update_pre); /* depsgraph.c */
+ DEG_editors_set_update_cb(ED_render_id_flush_update,
+ ED_render_scene_update);
ED_spacetypes_init(); /* editors/space_api/spacetype.c */
ED_file_init(); /* for fsmenu */
ED_node_init_butfuncs();
- BLF_init(); /* Please update source/gamengine/GamePlayer/GPG_ghost.cpp if you change this */
+ BLF_init();
BLT_lang_init();
/* reports cant be initialized before the wm,
* but keep before file reading, since that may report errors */
wm_init_reports(C);
+ WM_msgbus_types_init();
+
/* get the default database, plus a wm */
wm_homefile_read(C, NULL, G.factory_startup, false, true, NULL, NULL);
-
BLT_lang_set(NULL);
@@ -204,17 +245,7 @@ void WM_init(bContext *C, int argc, const char **argv)
/* sets 3D mouse deadzone */
WM_ndof_deadzone_set(U.ndof_deadzone);
#endif
-
- GPU_init();
-
- GPU_set_mipmap(!(U.gameflags & USER_DISABLE_MIPMAP));
- GPU_set_linear_mipmap(true);
- GPU_set_anisotropic(U.anisotropic_filter);
- GPU_set_gpu_mipmapping(U.use_gpu_mipmap);
-
-#ifdef WITH_OPENSUBDIV
- BKE_subsurf_osd_init();
-#endif
+ WM_init_opengl();
UI_init();
}
@@ -253,7 +284,7 @@ void WM_init(bContext *C, int argc, const char **argv)
clear_matcopybuf();
ED_render_clear_mtex_copybuf();
- // glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ // glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
wm_history_file_read();
@@ -313,96 +344,6 @@ void WM_init_splash(bContext *C)
}
}
-bool WM_init_game(bContext *C)
-{
- wmWindowManager *wm = CTX_wm_manager(C);
- wmWindow *win;
-
- ScrArea *sa;
- ARegion *ar = NULL;
-
- Scene *scene = CTX_data_scene(C);
-
- if (!scene) {
- /* XXX, this should not be needed. */
- Main *bmain = CTX_data_main(C);
- scene = bmain->scene.first;
- }
-
- win = wm->windows.first;
-
- /* first to get a valid window */
- if (win)
- CTX_wm_window_set(C, win);
-
- sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_VIEW3D, 0);
- ar = BKE_area_find_region_type(sa, RGN_TYPE_WINDOW);
-
- /* if we have a valid 3D view */
- if (sa && ar) {
- ARegion *arhide;
-
- CTX_wm_area_set(C, sa);
- CTX_wm_region_set(C, ar);
-
- /* disable quad view */
- if (ar->alignment == RGN_ALIGN_QSPLIT)
- WM_operator_name_call(C, "SCREEN_OT_region_quadview", WM_OP_EXEC_DEFAULT, NULL);
-
- /* toolbox, properties panel and header are hidden */
- for (arhide = sa->regionbase.first; arhide; arhide = arhide->next) {
- if (arhide->regiontype != RGN_TYPE_WINDOW) {
- if (!(arhide->flag & RGN_FLAG_HIDDEN)) {
- ED_region_toggle_hidden(C, arhide);
- }
- }
- }
-
- /* full screen the area */
- if (!sa->full) {
- ED_screen_state_toggle(C, win, sa, SCREENMAXIMIZED);
- }
-
- /* Fullscreen */
- if ((scene->gm.playerflag & GAME_PLAYER_FULLSCREEN)) {
- WM_operator_name_call(C, "WM_OT_window_fullscreen_toggle", WM_OP_EXEC_DEFAULT, NULL);
- wm_get_screensize(&ar->winrct.xmax, &ar->winrct.ymax);
- ar->winx = ar->winrct.xmax + 1;
- ar->winy = ar->winrct.ymax + 1;
- }
- else {
- GHOST_RectangleHandle rect = GHOST_GetClientBounds(win->ghostwin);
- ar->winrct.ymax = GHOST_GetHeightRectangle(rect);
- ar->winrct.xmax = GHOST_GetWidthRectangle(rect);
- ar->winx = ar->winrct.xmax + 1;
- ar->winy = ar->winrct.ymax + 1;
- GHOST_DisposeRectangle(rect);
- }
-
- WM_operator_name_call(C, "VIEW3D_OT_game_start", WM_OP_EXEC_DEFAULT, NULL);
-
- BKE_sound_exit();
-
- return true;
- }
- else {
- ReportTimerInfo *rti;
-
- BKE_report(&wm->reports, RPT_ERROR, "No valid 3D View found, game auto start is not possible");
-
- /* After adding the report to the global list, reset the report timer. */
- WM_event_remove_timer(wm, NULL, wm->reports.reporttimer);
-
- /* Records time since last report was added */
- wm->reports.reporttimer = WM_event_add_timer(wm, CTX_wm_window(C), TIMER, 0.02);
-
- rti = MEM_callocN(sizeof(ReportTimerInfo), "ReportTimerInfo");
- wm->reports.reporttimer->customdata = rti;
-
- return false;
- }
-}
-
/* free strings of open recent files */
static void free_openrecent(void)
{
@@ -480,7 +421,7 @@ void WM_exit_ext(bContext *C, const bool do_python)
/* save the undo state as quit.blend */
char filename[FILE_MAX];
bool has_edited;
- int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_AUTOPLAY | G_FILE_HISTORY);
+ int fileflags = G.fileflags & ~(G_FILE_COMPRESS | G_FILE_HISTORY);
BLI_make_file_string("/", filename, BKE_tempdir_base(), BLENDER_QUIT_FILE);
@@ -501,7 +442,7 @@ void WM_exit_ext(bContext *C, const bool do_python)
CTX_wm_window_set(C, win); /* needed by operator close callbacks */
WM_event_remove_handlers(C, &win->handlers);
WM_event_remove_handlers(C, &win->modalhandlers);
- ED_screen_exit(C, win, win->screen);
+ ED_screen_exit(C, win, WM_window_get_active_screen(win));
}
}
@@ -517,11 +458,6 @@ void WM_exit_ext(bContext *C, const bool do_python)
ED_undosys_type_free();
-// XXX
-// BIF_GlobalReebFree();
-// BIF_freeRetarget();
- BIF_freeTemplates(C);
-
free_openrecent();
BKE_mball_cubeTable_free();
@@ -543,6 +479,16 @@ void WM_exit_ext(bContext *C, const bool do_python)
#ifdef WITH_COMPOSITOR
COM_deinitialize();
#endif
+
+ if (opengl_is_init) {
+#ifdef WITH_OPENSUBDIV
+ BKE_subsurf_osd_cleanup();
+#endif
+
+ GPU_free_unused_buffers();
+
+ GPU_exit();
+ }
BKE_blender_free(); /* blender.c, does entire library and spacetypes */
// free_matcopybuf();
@@ -554,8 +500,18 @@ void WM_exit_ext(bContext *C, const bool do_python)
ED_gpencil_strokes_copybuf_free();
BKE_node_clipboard_clear();
+ /* free manipulator-maps after freeing blender, so no deleted data get accessed during cleaning up of areas */
+ wm_manipulatormaptypes_free();
+ wm_manipulatorgrouptype_free();
+ wm_manipulatortype_free();
+
BLF_exit();
+ if (opengl_is_init) {
+ GPU_pass_cache_free();
+ DRW_opengl_context_destroy();
+ }
+
#ifdef WITH_INTERNATIONAL
BLF_free_unifont();
BLF_free_unifont_mono();
@@ -583,17 +539,6 @@ void WM_exit_ext(bContext *C, const bool do_python)
(void)do_python;
#endif
- if (!G.background) {
-#ifdef WITH_OPENSUBDIV
- BKE_subsurf_osd_cleanup();
-#endif
-
- GPU_global_buffer_pool_free();
- GPU_free_unused_buffers();
-
- GPU_exit();
- }
-
ED_file_exit(); /* for fsmenu */
UI_exit();
@@ -604,9 +549,6 @@ void WM_exit_ext(bContext *C, const bool do_python)
wm_ghost_exit();
CTX_free(C);
-#ifdef WITH_GAMEENGINE
- SYS_DeleteSystem(SYS_GetSystem());
-#endif
GHOST_DisposeSystemPaths();
diff --git a/source/blender/windowmanager/intern/wm_keymap.c b/source/blender/windowmanager/intern/wm_keymap.c
index 39dd26339eb..27b9710cb45 100644
--- a/source/blender/windowmanager/intern/wm_keymap.c
+++ b/source/blender/windowmanager/intern/wm_keymap.c
@@ -38,6 +38,7 @@
#include "DNA_space_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "MEM_guardedalloc.h"
#include "CLG_log.h"
@@ -51,6 +52,7 @@
#include "BKE_global.h"
#include "BKE_main.h"
#include "BKE_screen.h"
+#include "BKE_workspace.h"
#include "BLT_translation.h"
@@ -343,6 +345,12 @@ static wmKeyMap *wm_keymap_new(const char *idname, int spaceid, int regionid)
km->spaceid = spaceid;
km->regionid = regionid;
+ {
+ const char *owner_id = RNA_struct_state_owner_get();
+ if (owner_id) {
+ BLI_strncpy(km->owner_id, owner_id, sizeof(km->owner_id));
+ }
+ }
return km;
}
@@ -403,6 +411,14 @@ bool WM_keymap_remove(wmKeyConfig *keyconf, wmKeyMap *keymap)
bool WM_keymap_poll(bContext *C, wmKeyMap *keymap)
{
+ /* If we're tagged, only use compatible. */
+ if (keymap->owner_id[0] != '\0') {
+ const WorkSpace *workspace = CTX_wm_workspace(C);
+ if (BKE_workspace_owner_id_check(workspace, keymap->owner_id) == false) {
+ return false;
+ }
+ }
+
if (keymap->poll != NULL) {
return keymap->poll(C);
}
@@ -1801,10 +1817,6 @@ wmKeyMap *WM_keymap_guess_opname(const bContext *C, const char *opname)
break;
}
}
- /* Timeline */
- else if (STRPREFIX(opname, "TIME_OT")) {
- km = WM_keymap_find_all(C, "Timeline", sl->spacetype, 0);
- }
/* Image Editor */
else if (STRPREFIX(opname, "IMAGE_OT")) {
km = WM_keymap_find_all(C, "Image", sl->spacetype, 0);
diff --git a/source/blender/windowmanager/intern/wm_operators.c b/source/blender/windowmanager/intern/wm_operators.c
index f46358f83cf..4e21607d847 100644
--- a/source/blender/windowmanager/intern/wm_operators.c
+++ b/source/blender/windowmanager/intern/wm_operators.c
@@ -54,6 +54,7 @@
#include "DNA_scene_types.h"
#include "DNA_userdef_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "BLT_translation.h"
@@ -72,7 +73,6 @@
#include "BKE_blender_version.h"
#include "BKE_brush.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h"
#include "BKE_icons.h"
#include "BKE_idprop.h"
#include "BKE_image.h"
@@ -88,9 +88,12 @@
#include "BKE_idcode.h"
-#include "BIF_glutil.h" /* for paint cursor */
#include "BLF_api.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+#include "GPU_matrix.h"
+
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
@@ -99,8 +102,6 @@
#include "ED_undo.h"
#include "ED_view3d.h"
-#include "GPU_basic_shader.h"
-
#include "RNA_access.h"
#include "RNA_define.h"
#include "RNA_enum_types.h"
@@ -120,6 +121,8 @@
#include "wm_window.h"
static GHash *global_ops_hash = NULL;
+/** Counter for operator-properties that should not be tagged with #OP_PROP_TAG_ADVANCED. */
+static int ot_prop_basic_count = -1;
#define UNDOCUMENTED_OPERATOR_TIP N_("(undocumented operator)")
@@ -159,22 +162,32 @@ void WM_operatortype_iter(GHashIterator *ghi)
BLI_ghashIterator_init(ghi, global_ops_hash);
}
-/* all ops in 1 list (for time being... needs evaluation later) */
-void WM_operatortype_append(void (*opfunc)(wmOperatorType *))
+/** \name Operator Type Append
+ * \{ */
+
+static wmOperatorType *wm_operatortype_append__begin(void)
{
- wmOperatorType *ot;
-
- ot = MEM_callocN(sizeof(wmOperatorType), "operatortype");
+ wmOperatorType *ot = MEM_callocN(sizeof(wmOperatorType), "operatortype");
+
+ BLI_assert(ot_prop_basic_count == -1);
+
ot->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_OperatorProperties);
+ RNA_def_struct_property_tags(ot->srna, rna_enum_operator_property_tags);
/* Set the default i18n context now, so that opfunc can redefine it if needed! */
RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
- opfunc(ot);
+ return ot;
+}
+static void wm_operatortype_append__end(wmOperatorType *ot)
+{
if (ot->name == NULL) {
CLOG_ERROR(WM_LOG_OPERATORS, "Operator '%s' has no name property", ot->idname);
}
+ /* Allow calling _begin without _end in operatortype creation. */
+ WM_operatortype_props_advanced_end(ot);
+
/* XXX All ops should have a description but for now allow them not to. */
RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP);
RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname);
@@ -182,22 +195,23 @@ void WM_operatortype_append(void (*opfunc)(wmOperatorType *))
BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
}
-void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType *, void *), void *userdata)
+/* all ops in 1 list (for time being... needs evaluation later) */
+void WM_operatortype_append(void (*opfunc)(wmOperatorType *))
{
- wmOperatorType *ot;
+ wmOperatorType *ot = wm_operatortype_append__begin();
+ opfunc(ot);
+ wm_operatortype_append__end(ot);
+}
- ot = MEM_callocN(sizeof(wmOperatorType), "operatortype");
- ot->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_OperatorProperties);
- /* Set the default i18n context now, so that opfunc can redefine it if needed! */
- RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
- ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
+void WM_operatortype_append_ptr(void (*opfunc)(wmOperatorType *, void *), void *userdata)
+{
+ wmOperatorType *ot = wm_operatortype_append__begin();
opfunc(ot, userdata);
- RNA_def_struct_ui_text(ot->srna, ot->name, ot->description ? ot->description : UNDOCUMENTED_OPERATOR_TIP);
- RNA_def_struct_identifier(&BLENDER_RNA, ot->srna, ot->idname);
-
- BLI_ghash_insert(global_ops_hash, (void *)ot->idname, ot);
+ wm_operatortype_append__end(ot);
}
+/** \} */
+
/* ********************* macro operator ******************** */
typedef struct {
@@ -529,6 +543,55 @@ void WM_operatortype_last_properties_clear_all(void)
}
}
+/**
+ * Tag all operator-properties of \a ot defined after calling this, until
+ * the next #WM_operatortype_props_advanced_end call (if available), with
+ * #OP_PROP_TAG_ADVANCED. Previously defined ones properties not touched.
+ *
+ * Calling this multiple times without a call to #WM_operatortype_props_advanced_end,
+ * all calls after the first one are ignored. Meaning all propereties defined after the
+ * first call are tagged as advanced.
+ *
+ * This doesn't do the actual tagging, #WM_operatortype_props_advanced_end does which is
+ * called for all operators during registration (see #wm_operatortype_append__end).
+ */
+void WM_operatortype_props_advanced_begin(wmOperatorType *ot)
+{
+ if (ot_prop_basic_count == -1) { /* Don't do anything if _begin was called before, but not _end */
+ ot_prop_basic_count = RNA_struct_count_properties(ot->srna);
+ }
+}
+
+/**
+ * Tags all operator-properties of \ot defined since the first #WM_operatortype_props_advanced_begin
+ * call, or the last #WM_operatortype_props_advanced_end call, with #OP_PROP_TAG_ADVANCED.
+ * Note that this is called for all operators during registration (see #wm_operatortype_append__end).
+ * So it does not need to be explicitly called in operator-type definition.
+ */
+void WM_operatortype_props_advanced_end(wmOperatorType *ot)
+{
+ PointerRNA struct_ptr;
+ int counter = 0;
+
+ if (ot_prop_basic_count == -1) {
+ /* WM_operatortype_props_advanced_begin was not called. Don't do anything. */
+ return;
+ }
+
+ RNA_pointer_create(NULL, ot->srna, NULL, &struct_ptr);
+
+ RNA_STRUCT_BEGIN (&struct_ptr, prop)
+ {
+ counter++;
+ if (counter > ot_prop_basic_count) {
+ WM_operatortype_prop_tag(prop, OP_PROP_TAG_ADVANCED);
+ }
+ }
+ RNA_STRUCT_END;
+
+ ot_prop_basic_count = -1;
+}
+
/* SOME_OT_op -> some.op */
void WM_operator_py_idname(char *to, const char *from)
{
@@ -1169,46 +1232,70 @@ int WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
return WM_menu_invoke_ex(C, op, WM_OP_INVOKE_REGION_WIN);
}
+struct EnumSearchMenu {
+ wmOperator *op; /* the operator that will be executed when selecting an item */
+
+ bool use_previews;
+ short prv_cols, prv_rows;
+};
/* generic enum search invoke popup */
-static uiBlock *wm_enum_search_menu(bContext *C, ARegion *ar, void *arg_op)
+static uiBlock *wm_enum_search_menu(bContext *C, ARegion *ar, void *arg)
{
- static char search[256] = "";
- wmEvent event;
+ struct EnumSearchMenu *search_menu = arg;
wmWindow *win = CTX_wm_window(C);
+ wmOperator *op = search_menu->op;
+ /* template_ID uses 4 * widget_unit for width, we use a bit more, some items may have a suffix to show */
+ const int width = search_menu->use_previews ? 5 * U.widget_unit * search_menu->prv_cols : UI_searchbox_size_x();
+ const int height = search_menu->use_previews ? 5 * U.widget_unit * search_menu->prv_rows : UI_searchbox_size_y();
+ static char search[256] = "";
uiBlock *block;
uiBut *but;
- wmOperator *op = (wmOperator *)arg_op;
block = UI_block_begin(C, ar, "_popup", UI_EMBOSS);
UI_block_flag_enable(block, UI_BLOCK_LOOP | UI_BLOCK_MOVEMOUSE_QUIT | UI_BLOCK_SEARCH_MENU);
search[0] = '\0';
+ BLI_assert(search_menu->use_previews || (search_menu->prv_cols == 0 && search_menu->prv_rows == 0));
#if 0 /* ok, this isn't so easy... */
uiDefBut(block, UI_BTYPE_LABEL, 0, RNA_struct_ui_name(op->type->srna), 10, 10, UI_searchbox_size_x(), UI_UNIT_Y, NULL, 0.0, 0.0, 0, 0, "");
#endif
but = uiDefSearchButO_ptr(block, op->type, op->ptr->data, search, 0, ICON_VIEWZOOM, sizeof(search),
- 10, 10, UI_searchbox_size_x(), UI_UNIT_Y, 0, 0, "");
+ 10, 10, width, UI_UNIT_Y, search_menu->prv_rows, search_menu->prv_cols, "");
/* fake button, it holds space for search items */
- uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - UI_searchbox_size_y(), UI_searchbox_size_x(), UI_searchbox_size_y(), NULL, 0, 0, 0, 0, NULL);
+ uiDefBut(block, UI_BTYPE_LABEL, 0, "", 10, 10 - UI_searchbox_size_y(), width, height, NULL, 0, 0, 0, 0, NULL);
UI_block_bounds_set_popup(block, 6, 0, -UI_UNIT_Y); /* move it downwards, mouse over button */
-
- wm_event_init_from_window(win, &event);
- event.type = EVT_BUT_OPEN;
- event.val = KM_PRESS;
- event.customdata = but;
- event.customdatafree = false;
- wm_event_add(win, &event);
+ UI_but_focus_on_enter_event(win, but);
return block;
}
+/**
+ * Similar to #WM_enum_search_invoke, but draws previews. Also, this can't
+ * be used as invoke callback directly since it needs additional info.
+ */
+int WM_enum_search_invoke_previews(
+ bContext *C, wmOperator *op, short prv_cols, short prv_rows)
+{
+ static struct EnumSearchMenu search_menu;
+
+ search_menu.op = op;
+ search_menu.use_previews = true;
+ search_menu.prv_cols = prv_cols;
+ search_menu.prv_rows = prv_rows;
+
+ UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu);
+
+ return OPERATOR_INTERFACE;
+}
int WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
{
- UI_popup_block_invoke(C, wm_enum_search_menu, op);
+ static struct EnumSearchMenu search_menu;
+ search_menu.op = op;
+ UI_popup_block_invoke(C, wm_enum_search_menu, &search_menu);
return OPERATOR_INTERFACE;
}
@@ -1301,6 +1388,21 @@ wmOperator *WM_operator_last_redo(const bContext *C)
return op;
}
+IDProperty *WM_operator_last_properties_ensure_idprops(wmOperatorType *ot)
+{
+ if (ot->last_properties == NULL) {
+ IDPropertyTemplate val = {0};
+ ot->last_properties = IDP_New(IDP_GROUP, &val, "wmOperatorProperties");
+ }
+ return ot->last_properties;
+}
+
+void WM_operator_last_properties_ensure(wmOperatorType *ot, PointerRNA *ptr)
+{
+ IDProperty *props = WM_operator_last_properties_ensure_idprops(ot);
+ RNA_pointer_create(NULL, ot->srna, props, ptr);
+}
+
/**
* Use for drag & drop a path or name with operators invoke() function.
*/
@@ -1411,13 +1513,15 @@ static uiBlock *wm_block_create_redo(bContext *C, ARegion *ar, void *arg_op)
if (op->type->flag & OPTYPE_MACRO) {
for (op = op->macro.first; op; op = op->next) {
- uiTemplateOperatorPropertyButs(C, layout, op, NULL, 'H', UI_TEMPLATE_OP_PROPS_SHOW_TITLE);
+ uiTemplateOperatorPropertyButs(C, layout, op, NULL, UI_BUT_LABEL_ALIGN_SPLIT_COLUMN,
+ UI_TEMPLATE_OP_PROPS_SHOW_TITLE);
if (op->next)
uiItemS(layout);
}
}
else {
- uiTemplateOperatorPropertyButs(C, layout, op, NULL, 'H', UI_TEMPLATE_OP_PROPS_SHOW_TITLE);
+ uiTemplateOperatorPropertyButs(C, layout, op, NULL, UI_BUT_LABEL_ALIGN_SPLIT_COLUMN,
+ UI_TEMPLATE_OP_PROPS_SHOW_TITLE);
}
UI_block_bounds_set_popup(block, 4, 0, 0);
@@ -1486,7 +1590,8 @@ static uiBlock *wm_block_dialog_create(bContext *C, ARegion *ar, void *userData)
layout = UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, 0, style);
- uiTemplateOperatorPropertyButs(C, layout, op, NULL, 'H', UI_TEMPLATE_OP_PROPS_SHOW_TITLE);
+ uiTemplateOperatorPropertyButs(C, layout, op, NULL, UI_BUT_LABEL_ALIGN_SPLIT_COLUMN,
+ UI_TEMPLATE_OP_PROPS_SHOW_TITLE);
/* clear so the OK button is left alone */
UI_block_func_set(block, NULL, NULL, NULL);
@@ -1525,7 +1630,7 @@ static uiBlock *wm_operator_ui_create(bContext *C, ARegion *ar, void *userData)
layout = UI_block_layout(block, UI_LAYOUT_VERTICAL, UI_LAYOUT_PANEL, 0, 0, data->width, data->height, 0, style);
/* since ui is defined the auto-layout args are not used */
- uiTemplateOperatorPropertyButs(C, layout, op, NULL, 'V', 0);
+ uiTemplateOperatorPropertyButs(C, layout, op, NULL, UI_BUT_LABEL_ALIGN_COLUMN, 0);
UI_block_func_set(block, NULL, NULL, NULL);
@@ -1721,6 +1826,50 @@ static void WM_OT_operator_defaults(wmOperatorType *ot)
ot->flag = OPTYPE_INTERNAL;
}
+#ifdef USE_WORKSPACE_TOOL
+/* ***************** Set Active Tool ************************* */
+
+/* Developers note: in it's current form this doesn't need to be an operator,
+ * keep this as-is for now since it may end up setting an active key-map.
+ */
+
+static int wm_operator_tool_set_exec(bContext *C, wmOperator *op)
+{
+ ScrArea *sa = CTX_wm_area(C);
+
+ bToolDef tool_def = {{0}};
+
+ tool_def.index = RNA_int_get(op->ptr, "index");
+ tool_def.spacetype = sa->spacetype;
+ RNA_string_get(op->ptr, "keymap", tool_def.keymap);
+ RNA_string_get(op->ptr, "manipulator_group", tool_def.manipulator_group);
+ RNA_string_get(op->ptr, "data_block", tool_def.data_block);
+
+ WM_toolsystem_set(C, &tool_def);
+
+ /* For some reason redraw fails with menus (even though 'ar' isn't the menu's region). */
+ ED_area_tag_redraw(sa);
+
+ return OPERATOR_FINISHED;
+}
+
+static void WM_OT_tool_set(wmOperatorType *ot)
+{
+ ot->name = "Set Active Tool";
+ ot->idname = "WM_OT_tool_set";
+ ot->description = "Set the active tool";
+
+ ot->exec = wm_operator_tool_set_exec;
+
+ ot->flag = OPTYPE_INTERNAL;
+
+ RNA_def_string(ot->srna, "keymap", NULL, KMAP_MAX_NAME, "Key Map", "");
+ RNA_def_string(ot->srna, "manipulator_group", NULL, MAX_NAME, "Manipulator Group", "");
+ RNA_def_string(ot->srna, "data_block", NULL, MAX_NAME, "Data Block", "");
+ RNA_def_int(ot->srna, "index", 0, INT_MIN, INT_MAX, "Index", "", INT_MIN, INT_MAX);
+}
+#endif /* USE_WORKSPACE_TOOL */
+
/* ***************** Splash Screen ************************* */
static void wm_block_splash_close(bContext *C, void *arg_block, void *UNUSED(arg))
@@ -1826,7 +1975,7 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
ibuf_template = IMB_loadiffname(splash_filepath, IB_rect, NULL);
if (ibuf_template) {
const int x_expect = ibuf->x;
- const int y_expect = 230 * (int)U.pixelsize;
+ const int y_expect = 282 * (int)U.pixelsize;
/* don't cover the header text */
if (ibuf_template->x == x_expect && ibuf_template->y == y_expect) {
memcpy(ibuf->rect, ibuf_template->rect, ibuf_template->x * ibuf_template->y * sizeof(char[4]));
@@ -1865,8 +2014,8 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
if (version_suffix != NULL && version_suffix[0]) {
/* placed after the version number in the image,
* placing y is tricky to match baseline */
- int x = 260 * U.pixelsize - (2 * UI_DPI_FAC);
- int y = 242 * U.pixelsize + (4 * UI_DPI_FAC);
+ int x = 236 * U.pixelsize - (2 * UI_DPI_FAC);
+ int y = 231 * U.pixelsize + (4 * UI_DPI_FAC);
int w = 240 * U.pixelsize;
/* hack to have text draw 'text_sel' */
@@ -1879,17 +2028,32 @@ static uiBlock *wm_block_create_splash(bContext *C, ARegion *ar, void *UNUSED(ar
#ifdef WITH_BUILDINFO
if (build_commit_timestamp != 0) {
- uiDefBut(block, UI_BTYPE_LABEL, 0, date_buf, U.pixelsize * 494 - date_width, U.pixelsize * 270, date_width, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+ but = uiDefBut(
+ block, UI_BTYPE_LABEL, 0, date_buf,
+ U.pixelsize * 502 - date_width, U.pixelsize * 267,
+ date_width, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+ /* XXX, set internal flag - UI_SELECT */
+ UI_but_flag_enable(but, 1);
label_delta = 12;
}
- uiDefBut(block, UI_BTYPE_LABEL, 0, hash_buf, U.pixelsize * 494 - hash_width, U.pixelsize * (270 - label_delta), hash_width, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+ but = uiDefBut(
+ block, UI_BTYPE_LABEL, 0, hash_buf,
+ U.pixelsize * 502 - hash_width, U.pixelsize * (267 - label_delta),
+ hash_width, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+ /* XXX, set internal flag - UI_SELECT */
+ UI_but_flag_enable(but, 1);
if (!STREQ(build_branch, "master")) {
char branch_buf[128] = "\0";
int branch_width;
BLI_snprintf(branch_buf, sizeof(branch_buf), "Branch: %s", build_branch);
branch_width = (int)BLF_width(style->widgetlabel.uifont_id, branch_buf, sizeof(branch_buf)) + U.widget_unit;
- uiDefBut(block, UI_BTYPE_LABEL, 0, branch_buf, U.pixelsize * 494 - branch_width, U.pixelsize * (258 - label_delta), branch_width, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+ but = uiDefBut(
+ block, UI_BTYPE_LABEL, 0, branch_buf,
+ U.pixelsize * 502 - branch_width, U.pixelsize * (255 - label_delta),
+ branch_width, UI_UNIT_Y, NULL, 0, 0, 0, 0, NULL);
+ /* XXX, set internal flag - UI_SELECT */
+ UI_but_flag_enable(but, 1);
}
#endif /* WITH_BUILDINFO */
@@ -2128,8 +2292,11 @@ static void WM_OT_call_menu_pie(wmOperatorType *ot)
static int wm_operator_winactive_normal(bContext *C)
{
wmWindow *win = CTX_wm_window(C);
+ bScreen *screen;
- if (win == NULL || win->screen == NULL || win->screen->state != SCREENNORMAL)
+ if (win == NULL)
+ return 0;
+ if (!((screen = WM_window_get_active_screen(win)) && (screen->state == SCREENNORMAL)))
return 0;
return 1;
@@ -2146,14 +2313,22 @@ static void WM_OT_window_close(wmOperatorType *ot)
ot->poll = WM_operator_winactive;
}
-static void WM_OT_window_duplicate(wmOperatorType *ot)
+static void WM_OT_window_new(wmOperatorType *ot)
{
- ot->name = "Duplicate Window";
- ot->idname = "WM_OT_window_duplicate";
- ot->description = "Duplicate the current Blender window";
-
- ot->exec = wm_window_duplicate_exec;
+ PropertyRNA *prop;
+
+ ot->name = "New Window";
+ ot->idname = "WM_OT_window_new";
+ ot->description = "Create a new Blender window";
+
+ ot->exec = wm_window_new_exec;
+ ot->invoke = wm_window_new_invoke;
ot->poll = wm_operator_winactive_normal;
+
+ prop = RNA_def_enum(ot->srna, "screen", DummyRNA_NULL_items, 0, "Screen", "");
+ RNA_def_enum_funcs(prop, wm_window_new_screen_itemf);
+ RNA_def_property_flag(prop, PROP_ENUM_NO_TRANSLATE);
+ ot->prop = prop;
}
static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
@@ -2364,8 +2539,9 @@ static void radial_control_set_tex(RadialControl *rc)
if ((ibuf = BKE_brush_gen_radial_control_imbuf(rc->image_id_ptr.data, rc->use_secondary_tex))) {
glGenTextures(1, &rc->gltex);
glBindTexture(GL_TEXTURE_2D, rc->gltex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_ALPHA8, ibuf->x, ibuf->y, 0,
- GL_ALPHA, GL_FLOAT, ibuf->rect_float);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, ibuf->x, ibuf->y, 0,
+ GL_RED, GL_FLOAT, ibuf->rect_float);
+ glBindTexture(GL_TEXTURE_2D, 0);
MEM_freeN(ibuf->rect_float);
MEM_freeN(ibuf);
}
@@ -2398,49 +2574,69 @@ static void radial_control_paint_tex(RadialControl *rc, float radius, float alph
RNA_property_float_get_array(fill_ptr, fill_prop, col);
}
- glColor4f(col[0], col[1], col[2], alpha);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
if (rc->gltex) {
+
+ unsigned int texCoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, rc->gltex);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+
+ GLint swizzleMask[] = {GL_ZERO, GL_ZERO, GL_ZERO, GL_RED};
+ glTexParameteriv(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_RGBA, swizzleMask);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_MASK_UNIFORM_COLOR);
+
+ immUniformColor3fvAlpha(col, alpha);
+ immUniform1i("image", 0);
/* set up rotation if available */
if (rc->rot_prop) {
rot = RNA_property_float_get(&rc->rot_ptr, rc->rot_prop);
- glPushMatrix();
- glRotatef(RAD2DEGF(rot), 0, 0, 1);
+ gpuPushMatrix();
+ gpuRotate2D(RAD2DEGF(rot));
}
/* draw textured quad */
- GPU_basic_shader_bind(GPU_SHADER_TEXTURE_2D | GPU_SHADER_USE_COLOR);
- glBegin(GL_QUADS);
- glTexCoord2f(0, 0);
- glVertex2f(-radius, -radius);
- glTexCoord2f(1, 0);
- glVertex2f(radius, -radius);
- glTexCoord2f(1, 1);
- glVertex2f(radius, radius);
- glTexCoord2f(0, 1);
- glVertex2f(-radius, radius);
- glEnd();
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ immBegin(GWN_PRIM_TRI_FAN, 4);
+
+ immAttrib2f(texCoord, 0, 0);
+ immVertex2f(pos, -radius, -radius);
+
+ immAttrib2f(texCoord, 1, 0);
+ immVertex2f(pos, radius, -radius);
+
+ immAttrib2f(texCoord, 1, 1);
+ immVertex2f(pos, radius, radius);
+
+ immAttrib2f(texCoord, 0, 1);
+ immVertex2f(pos, -radius, radius);
+
+ immEnd();
/* undo rotation */
if (rc->rot_prop)
- glPopMatrix();
+ gpuPopMatrix();
}
else {
/* flat color if no texture available */
- glutil_draw_filled_arc(0, M_PI * 2, radius, 40);
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fvAlpha(col, alpha);
+ imm_draw_circle_fill_2d(pos, 0.0f, 0.0f, radius, 40);
}
+
+ immUnbindProgram();
}
-static void radial_control_paint_cursor(bContext *C, int x, int y, void *customdata)
+static void radial_control_paint_cursor(bContext *UNUSED(C), int x, int y, void *customdata)
{
RadialControl *rc = customdata;
- ARegion *ar = CTX_wm_region(C);
uiStyle *style = UI_style_get();
const uiFontStyle *fstyle = &style->widget;
const int fontid = fstyle->uifont_id;
@@ -2491,9 +2687,9 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
}
/* Keep cursor in the original place */
- x = rc->initial_mouse[0] - ar->winrct.xmin;
- y = rc->initial_mouse[1] - ar->winrct.ymin;
- glTranslatef((float)x, (float)y, 0.0f);
+ x = rc->initial_mouse[0];
+ y = rc->initial_mouse[1];
+ gpuTranslate2f((float)x, (float)y);
glEnable(GL_BLEND);
glEnable(GL_LINE_SMOOTH);
@@ -2501,7 +2697,7 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
/* apply zoom if available */
if (rc->zoom_prop) {
RNA_property_float_get_array(&rc->zoom_ptr, rc->zoom_prop, zoom);
- glScalef(zoom[0], zoom[1], 1);
+ gpuScale2fv(zoom);
}
/* draw rotated texture */
@@ -2510,24 +2706,39 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
/* set line color */
if (rc->col_prop)
RNA_property_float_get_array(&rc->col_ptr, rc->col_prop, col);
- glColor4f(col[0], col[1], col[2], 0.5);
+
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3fvAlpha(col, 0.5f);
if (rc->subtype == PROP_ANGLE) {
- glPushMatrix();
+ gpuPushMatrix();
+
/* draw original angle line */
- glRotatef(RAD2DEGF(rc->initial_value), 0, 0, 1);
- fdrawline((float)WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE, 0.0f, (float)WM_RADIAL_CONTROL_DISPLAY_SIZE, 0.0f);
+ gpuRotate2D(RAD2DEGF(rc->initial_value));
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, (float)WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE, 0.0f);
+ immVertex2f(pos, (float)WM_RADIAL_CONTROL_DISPLAY_SIZE, 0.0f);
+ immEnd();
+
/* draw new angle line */
- glRotatef(RAD2DEGF(rc->current_value - rc->initial_value), 0, 0, 1);
- fdrawline((float)WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE, 0.0f, (float)WM_RADIAL_CONTROL_DISPLAY_SIZE, 0.0f);
- glPopMatrix();
+ gpuRotate2D(RAD2DEGF(rc->current_value - rc->initial_value));
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, (float)WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE, 0.0f);
+ immVertex2f(pos, (float)WM_RADIAL_CONTROL_DISPLAY_SIZE, 0.0f);
+ immEnd();
+
+ gpuPopMatrix();
}
/* draw circles on top */
- glutil_draw_lined_arc(0.0, (float)(M_PI * 2.0), r1, 40);
- glutil_draw_lined_arc(0.0, (float)(M_PI * 2.0), r2, 40);
+ imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, r1, 40);
+ imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, r2, 40);
if (rmin > 0.0f)
- glutil_draw_lined_arc(0.0, (float)(M_PI * 2.0), rmin, 40);
+ imm_draw_circle_wire_2d(pos, 0.0, 0.0f, rmin, 40);
+ immUnbindProgram();
BLF_size(fontid, 1.5 * fstyle_points * U.pixelsize, U.dpi);
BLF_enable(fontid, BLF_SHADOW);
@@ -2543,6 +2754,7 @@ static void radial_control_paint_cursor(bContext *C, int x, int y, void *customd
glDisable(GL_BLEND);
glDisable(GL_LINE_SMOOTH);
+
}
typedef enum {
@@ -3115,6 +3327,7 @@ static const EnumPropertyItem redraw_timer_type_items[] = {
static void redraw_timer_step(
bContext *C, Main *bmain, Scene *scene,
+ struct Depsgraph *depsgraph,
wmWindow *win, ScrArea *sa, ARegion *ar,
const int type, const int cfra)
{
@@ -3133,16 +3346,17 @@ static void redraw_timer_step(
CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
}
else if (type == eRTDrawWindow) {
+ bScreen *screen = WM_window_get_active_screen(win);
ScrArea *sa_iter;
CTX_wm_menu_set(C, NULL);
- for (sa_iter = win->screen->areabase.first; sa_iter; sa_iter = sa_iter->next) {
+ for (sa_iter = screen->areabase.first; sa_iter; sa_iter = sa_iter->next) {
ARegion *ar_iter;
CTX_wm_area_set(C, sa_iter);
for (ar_iter = sa_iter->regionbase.first; ar_iter; ar_iter = ar_iter->next) {
- if (ar_iter->swinid) {
+ if (ar_iter->visible) {
CTX_wm_region_set(C, ar_iter);
ED_region_do_draw(C, ar_iter);
ar_iter->do_draw = false;
@@ -3160,7 +3374,7 @@ static void redraw_timer_step(
}
else if (type == eRTAnimationStep) {
scene->r.cfra += (cfra == scene->r.cfra) ? 1 : -1;
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
}
else if (type == eRTAnimationPlay) {
/* play anim, return on same frame as started with */
@@ -3172,7 +3386,7 @@ static void redraw_timer_step(
if (scene->r.cfra > scene->r.efra)
scene->r.cfra = scene->r.sfra;
- BKE_scene_update_for_newframe(bmain->eval_ctx, bmain, scene, scene->lay);
+ BKE_scene_graph_update_for_newframe(depsgraph, bmain);
redraw_timer_window_swap(C);
}
}
@@ -3196,13 +3410,14 @@ static int redraw_timer_exec(bContext *C, wmOperator *op)
const int cfra = scene->r.cfra;
int a, iter_steps = 0;
const char *infostr = "";
+ struct Depsgraph *depsgraph = CTX_data_depsgraph(C);
WM_cursor_wait(1);
time_start = PIL_check_seconds_timer();
for (a = 0; a < iter; a++) {
- redraw_timer_step(C, bmain, scene, win, sa, ar, type, cfra);
+ redraw_timer_step(C, bmain, scene, depsgraph, win, sa, ar, type, cfra);
iter_steps += 1;
if (time_limit != 0.0) {
@@ -3260,28 +3475,6 @@ static void WM_OT_memory_statistics(wmOperatorType *ot)
ot->exec = memory_statistics_exec;
}
-/* ************************** memory statistics for testing ***************** */
-
-static int dependency_relations_exec(bContext *C, wmOperator *UNUSED(op))
-{
- Main *bmain = CTX_data_main(C);
- Scene *scene = CTX_data_scene(C);
- Object *ob = CTX_data_active_object(C);
-
- DAG_print_dependencies(bmain, scene, ob);
-
- return OPERATOR_FINISHED;
-}
-
-static void WM_OT_dependency_relations(wmOperatorType *ot)
-{
- ot->name = "Dependency Relations";
- ot->idname = "WM_OT_dependency_relations";
- ot->description = "Print dependency graph relations to the console";
-
- ot->exec = dependency_relations_exec;
-}
-
/* *************************** Mat/tex/etc. previews generation ************* */
typedef struct PreviewsIDEnsureData {
@@ -3528,12 +3721,13 @@ void wm_operatortype_init(void)
global_ops_hash = BLI_ghash_str_new_ex("wm_operatortype_init gh", 2048);
WM_operatortype_append(WM_OT_window_close);
- WM_operatortype_append(WM_OT_window_duplicate);
+ WM_operatortype_append(WM_OT_window_new);
WM_operatortype_append(WM_OT_read_history);
WM_operatortype_append(WM_OT_read_homefile);
WM_operatortype_append(WM_OT_read_factory_settings);
WM_operatortype_append(WM_OT_save_homefile);
WM_operatortype_append(WM_OT_save_userpref);
+ WM_operatortype_append(WM_OT_save_workspace_file);
WM_operatortype_append(WM_OT_userpref_autoexec_path_add);
WM_operatortype_append(WM_OT_userpref_autoexec_path_remove);
WM_operatortype_append(WM_OT_window_fullscreen_toggle);
@@ -3550,9 +3744,11 @@ void wm_operatortype_init(void)
WM_operatortype_append(WM_OT_save_mainfile);
WM_operatortype_append(WM_OT_redraw_timer);
WM_operatortype_append(WM_OT_memory_statistics);
- WM_operatortype_append(WM_OT_dependency_relations);
WM_operatortype_append(WM_OT_debug_menu);
WM_operatortype_append(WM_OT_operator_defaults);
+#ifdef USE_WORKSPACE_TOOL
+ WM_operatortype_append(WM_OT_tool_set);
+#endif
WM_operatortype_append(WM_OT_splash);
WM_operatortype_append(WM_OT_search_menu);
WM_operatortype_append(WM_OT_call_menu);
@@ -3565,6 +3761,10 @@ void wm_operatortype_init(void)
WM_operatortype_append(WM_OT_previews_ensure);
WM_operatortype_append(WM_OT_previews_clear);
WM_operatortype_append(WM_OT_doc_view_manual_ui_context);
+
+ /* manipulators */
+ WM_operatortype_append(MANIPULATORGROUP_OT_manipulator_select);
+ WM_operatortype_append(MANIPULATORGROUP_OT_manipulator_tweak);
}
/* circleselect-like modal operators */
@@ -3767,7 +3967,7 @@ void wm_window_keymap(wmKeyConfig *keyconf)
wmKeyMapItem *kmi;
/* note, this doesn't replace existing keymap items */
- WM_keymap_verify_item(keymap, "WM_OT_window_duplicate", WKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
+ WM_keymap_verify_item(keymap, "WM_OT_window_new", WKEY, KM_PRESS, KM_CTRL | KM_ALT, 0);
#ifdef __APPLE__
WM_keymap_add_item(keymap, "WM_OT_read_homefile", NKEY, KM_PRESS, KM_OSKEY, 0);
WM_keymap_add_menu(keymap, "INFO_MT_file_open_recent", OKEY, KM_PRESS, KM_SHIFT | KM_OSKEY, 0);
@@ -3807,10 +4007,6 @@ void wm_window_keymap(wmKeyConfig *keyconf)
#endif
/* Space switching */
- kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F2KEY, KM_PRESS, KM_SHIFT, 0); /* new in 2.5x, was DXF export */
- RNA_string_set(kmi->ptr, "data_path", "area.type");
- RNA_string_set(kmi->ptr, "value", "LOGIC_EDITOR");
-
kmi = WM_keymap_add_item(keymap, "WM_OT_context_set_enum", F3KEY, KM_PRESS, KM_SHIFT, 0);
RNA_string_set(kmi->ptr, "data_path", "area.type");
RNA_string_set(kmi->ptr, "value", "NODE_EDITOR");
@@ -3871,6 +4067,7 @@ void wm_window_keymap(wmKeyConfig *keyconf)
RNA_float_set(kmi->ptr, "value", 1.0f / 1.5f);
#endif /* WITH_INPUT_NDOF */
+ wm_manipulators_keymap(keyconf);
gesture_circle_modal_keymap(keyconf);
gesture_border_modal_keymap(keyconf);
gesture_zoom_border_modal_keymap(keyconf);
diff --git a/source/blender/windowmanager/intern/wm_playanim.c b/source/blender/windowmanager/intern/wm_playanim.c
index 77378cf8e0c..d6a1eb81981 100644
--- a/source/blender/windowmanager/intern/wm_playanim.c
+++ b/source/blender/windowmanager/intern/wm_playanim.c
@@ -58,24 +58,29 @@
#include "IMB_imbuf_types.h"
#include "IMB_imbuf.h"
-#include "BKE_depsgraph.h"
#include "BKE_image.h"
#include "BIF_gl.h"
#include "BIF_glutil.h"
+#include "GPU_matrix.h"
+#include "GPU_immediate.h"
+#include "GPU_immediate_util.h"
+
#include "DNA_scene_types.h"
#include "ED_datafiles.h" /* for fonts */
#include "GHOST_C-api.h"
#include "BLF_api.h"
+#include "DEG_depsgraph.h"
+
#include "WM_api.h" /* only for WM_main_playanim */
#ifdef WITH_AUDASPACE
-# include AUD_DEVICE_H
-# include AUD_HANDLE_H
-# include AUD_SOUND_H
-# include AUD_SPECIAL_H
+# include <AUD_Device.h>
+# include <AUD_Handle.h>
+# include <AUD_Sound.h>
+# include <AUD_Special.h>
static AUD_Sound *source = NULL;
static AUD_Handle *playback_handle = NULL;
@@ -190,10 +195,7 @@ static void playanim_window_get_size(int *r_width, int *r_height)
static void playanim_gl_matrix(void)
{
/* unified matrix, note it affects offset for drawing */
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(0.0f, 1.0f, 0.0f, 1.0f, -1.0f, 1.0f);
- glMatrixMode(GL_MODELVIEW);
+ gpuOrtho2D(0.0f, 1.0f, 0.0f, 1.0f);
}
/* implementation */
@@ -308,42 +310,45 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
CLAMP(offs_x, 0.0f, 1.0f);
CLAMP(offs_y, 0.0f, 1.0f);
- glRasterPos2f(offs_x, offs_y);
glClearColor(0.1, 0.1, 0.1, 0.0);
glClear(GL_COLOR_BUFFER_BIT);
-
+
/* checkerboard for case alpha */
if (ibuf->planes == 32) {
glEnable(GL_BLEND);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
- fdrawcheckerboard(offs_x, offs_y, offs_x + span_x, offs_y + span_y);
+ imm_draw_box_checker_2d(offs_x, offs_y, offs_x + span_x, offs_y + span_y);
}
- glRasterPos2f(offs_x + (ps->draw_flip[0] ? span_x : 0.0f),
- offs_y + (ps->draw_flip[1] ? span_y : 0.0f));
-
- glPixelZoom(ps->zoom * (ps->draw_flip[0] ? -1.0f : 1.0f),
- ps->zoom * (ps->draw_flip[1] ? -1.0f : 1.0f));
+ IMMDrawPixelsTexState state = immDrawPixelsTexSetup(GPU_SHADER_2D_IMAGE_COLOR);
- glDrawPixels(ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect);
+ immDrawPixelsTex(
+ &state,
+ offs_x + (ps->draw_flip[0] ? span_x : 0.0f),
+ offs_y + (ps->draw_flip[1] ? span_y : 0.0f),
+ ibuf->x, ibuf->y, GL_RGBA, GL_UNSIGNED_BYTE, GL_NEAREST,
+ ibuf->rect,
+ ((ps->draw_flip[0] ? -1.0f : 1.0f)) * (ps->zoom / (float)ps->win_x),
+ ((ps->draw_flip[1] ? -1.0f : 1.0f)) * (ps->zoom / (float)ps->win_y),
+ NULL);
glDisable(GL_BLEND);
-
+
pupdate_time();
if (picture && (g_WS.qual & (WS_QUAL_SHIFT | WS_QUAL_LMOUSE)) && (fontid != -1)) {
int sizex, sizey;
float fsizex_inv, fsizey_inv;
char str[32 + FILE_MAX];
- cpack(-1);
BLI_snprintf(str, sizeof(str), "%s | %.2f frames/s", picture->name, fstep / swaptime);
playanim_window_get_size(&sizex, &sizey);
fsizex_inv = 1.0f / sizex;
fsizey_inv = 1.0f / sizey;
+ BLF_color4f(fontid, 1.0, 1.0, 1.0, 1.0);
BLF_enable(fontid, BLF_ASPECT);
BLF_aspect(fontid, fsizex_inv, fsizey_inv, 1.0f);
BLF_position(fontid, 10.0f * fsizex_inv, 10.0f * fsizey_inv, 0.0f);
@@ -354,24 +359,25 @@ static void playanim_toscreen(PlayState *ps, PlayAnimPict *picture, struct ImBuf
float fac = ps->picture->frame / (double)(((PlayAnimPict *)picsbase.last)->frame - ((PlayAnimPict *)picsbase.first)->frame);
fac = 2.0f * fac - 1.0f;
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
-
- glBegin(GL_LINES);
- glVertex2f(fac, -1.0f);
- glVertex2f(fac, 1.0f);
- glEnd();
-
- glPopMatrix();
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
+ gpuPushProjectionMatrix();
+ gpuLoadIdentityProjectionMatrix();
+ gpuPushMatrix();
+ gpuLoadIdentity();
+
+ unsigned int pos = GWN_vertformat_attr_add(immVertexFormat(), "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_UNIFORM_COLOR);
+ immUniformColor3ub(0, 255, 0);
+
+ immBegin(GWN_PRIM_LINES, 2);
+ immVertex2f(pos, fac, -1.0f);
+ immVertex2f(pos, fac, 1.0f);
+ immEnd();
+
+ immUnbindProgram();
+
+ gpuPopMatrix();
+ gpuPopProjectionMatrix();
}
GHOST_SwapWindowBuffers(g_WS.ghost_window);
@@ -1255,6 +1261,9 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
//GHOST_ActivateWindowDrawingContext(g_WS.ghost_window);
+ /* initialize OpenGL immediate mode */
+ immInit();
+
/* initialize the font */
BLF_init();
ps.fontid = BLF_load_mem("monospace", (unsigned char *)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
@@ -1524,7 +1533,11 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
#endif
/* we still miss freeing a lot!,
* but many areas could skip initialization too for anim play */
-
+
+ GPU_shader_free_builtin_shaders();
+
+ immDestroy();
+
BLF_exit();
GHOST_DisposeWindow(g_WS.ghost_system, g_WS.ghost_window);
@@ -1537,7 +1550,7 @@ static char *wm_main_playanim_intern(int argc, const char **argv)
IMB_exit();
BKE_images_exit();
- DAG_exit();
+ DEG_free_node_types();
totblock = MEM_get_memory_blocks_in_use();
if (totblock != 0) {
diff --git a/source/blender/windowmanager/intern/wm_stereo.c b/source/blender/windowmanager/intern/wm_stereo.c
index 55fe2ec846c..4450d18a5df 100644
--- a/source/blender/windowmanager/intern/wm_stereo.c
+++ b/source/blender/windowmanager/intern/wm_stereo.c
@@ -52,90 +52,86 @@
#include "ED_screen.h"
-#include "GPU_glew.h"
-#include "GPU_basic_shader.h"
+#include "GPU_immediate.h"
+#include "GPU_framebuffer.h"
+#include "GPU_texture.h"
#include "WM_api.h"
#include "WM_types.h"
#include "wm.h"
-#include "wm_draw.h" /* wmDrawTriple */
+#include "wm_draw.h"
#include "wm_window.h"
#include "UI_interface.h"
#include "UI_resources.h"
-static void wm_method_draw_stereo3d_pageflip(wmWindow *win)
+static GPUInterlaceShader interlace_gpu_id_from_type(eStereo3dInterlaceType interlace_type)
{
- wmDrawData *drawdata;
- int view;
+ switch (interlace_type) {
+ case S3D_INTERLACE_ROW:
+ return GPU_SHADER_INTERLACE_ROW;
+ case S3D_INTERLACE_COLUMN:
+ return GPU_SHADER_INTERLACE_COLUMN;
+ case S3D_INTERLACE_CHECKERBOARD:
+ default:
+ return GPU_SHADER_INTERLACE_CHECKER;
+ }
+}
+
+void wm_stereo3d_draw_interlace(wmWindow *win, ARegion *ar)
+{
+ bool swap = (win->stereo3d_format->flag & S3D_INTERLACE_SWAP) != 0;
+ enum eStereo3dInterlaceType interlace_type = win->stereo3d_format->interlace_type;
- for (view = 0; view < 2; view ++) {
- drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1);
+ /* wmOrtho for the screen has this same offset */
+ float halfx = GLA_PIXEL_OFS / ar->winx;
+ float halfy = GLA_PIXEL_OFS / ar->winy;
- if (view == STEREO_LEFT_ID)
- glDrawBuffer(GL_BACK_LEFT);
- else //STEREO_RIGHT_ID
- glDrawBuffer(GL_BACK_RIGHT);
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- wm_triple_draw_textures(win, drawdata->triple, 1.0f, false);
+ /* leave GL_TEXTURE0 as the latest active texture */
+ for (int view = 1; view >= 0; view--) {
+ GPUTexture *texture = wm_draw_region_texture(ar, view);
+ glActiveTexture(GL_TEXTURE0 + view);
+ glBindTexture(GL_TEXTURE_2D, GPU_texture_opengl_bindcode(texture));
}
- glDrawBuffer(GL_BACK);
-}
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE_INTERLACE);
+ immUniform1i("image_a", (swap) ? 1 : 0);
+ immUniform1i("image_b", (swap) ? 0 : 1);
-static enum eStereo3dInterlaceType interlace_prev_type = -1;
-static char interlace_prev_swap = -1;
+ immUniform1i("interlace_id", interlace_gpu_id_from_type(interlace_type));
-static void wm_method_draw_stereo3d_interlace(wmWindow *win)
-{
- wmDrawData *drawdata;
- int view;
- bool flag;
- bool swap = (win->stereo3d_format->flag & S3D_INTERLACE_SWAP) != 0;
- enum eStereo3dInterlaceType interlace_type = win->stereo3d_format->interlace_type;
+ immBegin(GWN_PRIM_TRI_FAN, 4);
- for (view = 0; view < 2; view ++) {
- flag = swap ? !view : view;
- drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1);
- GPU_basic_shader_bind(GPU_SHADER_STIPPLE);
- switch (interlace_type) {
- case S3D_INTERLACE_ROW:
- if (flag)
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW_SWAP);
- else
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_ROW);
- break;
- case S3D_INTERLACE_COLUMN:
- if (flag)
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN_SWAP);
- else
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_COLUMN);
- break;
- case S3D_INTERLACE_CHECKERBOARD:
- default:
- if (flag)
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER_SWAP);
- else
- GPU_basic_shader_stipple(GPU_SHADER_STIPPLE_S3D_INTERLACE_CHECKER);
- break;
- }
+ immAttrib2f(texcoord, halfx, halfy);
+ immVertex2f(pos, ar->winrct.xmin, ar->winrct.ymin);
- wm_triple_draw_textures(win, drawdata->triple, 1.0f, true);
- GPU_basic_shader_bind(GPU_SHADER_USE_COLOR);
+ immAttrib2f(texcoord, 1.0f + halfx, halfy);
+ immVertex2f(pos, ar->winrct.xmax + 1, ar->winrct.ymin);
+
+ immAttrib2f(texcoord, 1.0f + halfx, 1.0f + halfy);
+ immVertex2f(pos, ar->winrct.xmax + 1, ar->winrct.ymax + 1);
+
+ immAttrib2f(texcoord, halfx, 1.0f + halfy);
+ immVertex2f(pos, ar->winrct.xmin, ar->winrct.ymax + 1);
+
+ immEnd();
+ immUnbindProgram();
+
+ for (int view = 1; view >= 0; view--) {
+ glActiveTexture(GL_TEXTURE0 + view);
+ glBindTexture(GL_TEXTURE_2D, 0);
}
- interlace_prev_type = interlace_type;
- interlace_prev_swap = swap;
}
-static void wm_method_draw_stereo3d_anaglyph(wmWindow *win)
+void wm_stereo3d_draw_anaglyph(wmWindow *win, ARegion *ar)
{
- wmDrawData *drawdata;
- int view, bit;
+ for (int view = 0; view < 2; view ++) {
+ int bit = view + 1;
- for (view = 0; view < 2; view ++) {
- drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1);
-
- bit = view + 1;
switch (win->stereo3d_format->anaglyph_type) {
case S3D_ANAGLYPH_REDCYAN:
glColorMask((1&bit) ? GL_TRUE : GL_FALSE,
@@ -157,162 +153,110 @@ static void wm_method_draw_stereo3d_anaglyph(wmWindow *win)
break;
}
- wm_triple_draw_textures(win, drawdata->triple, 1.0f, false);
-
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
+ wm_draw_region_blend(ar, view, false);
}
+
+ glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
}
-static void wm_method_draw_stereo3d_sidebyside(wmWindow *win)
+void wm_stereo3d_draw_sidebyside(wmWindow *win, int view)
{
- wmDrawData *drawdata;
- wmDrawTriple *triple;
- float halfx, halfy, ratiox, ratioy;
- int view;
- int soffx;
bool cross_eyed = (win->stereo3d_format->flag & S3D_SIDEBYSIDE_CROSSEYED) != 0;
- for (view = 0; view < 2; view ++) {
- drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1);
- triple = drawdata->triple;
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
- soffx = WM_window_pixels_x(win) * 0.5f;
- if (view == STEREO_LEFT_ID) {
- if (!cross_eyed)
- soffx = 0;
- }
- else { //RIGHT_LEFT_ID
- if (cross_eyed)
- soffx = 0;
- }
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE);
- const int sizex = triple->x;
- const int sizey = triple->y;
-
- /* wmOrtho for the screen has this same offset */
- ratiox = sizex;
- ratioy = sizey;
- halfx = GLA_PIXEL_OFS;
- halfy = GLA_PIXEL_OFS;
-
- /* texture rectangle has unnormalized coordinates */
- if (triple->target == GL_TEXTURE_2D) {
- ratiox /= triple->x;
- ratioy /= triple->y;
- halfx /= triple->x;
- halfy /= triple->y;
- }
+ int soffx = WM_window_pixels_x(win) * 0.5f;
+ if (view == STEREO_LEFT_ID) {
+ if (!cross_eyed)
+ soffx = 0;
+ }
+ else { //RIGHT_LEFT_ID
+ if (cross_eyed)
+ soffx = 0;
+ }
- glEnable(triple->target);
- glBindTexture(triple->target, triple->bind);
+ const int sizex = WM_window_pixels_x(win);
+ const int sizey = WM_window_pixels_y(win);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBegin(GL_QUADS);
- glTexCoord2f(halfx, halfy);
- glVertex2f(soffx, 0);
+ /* wmOrtho for the screen has this same offset */
+ const float halfx = GLA_PIXEL_OFS / sizex;
+ const float halfy = GLA_PIXEL_OFS / sizex;
- glTexCoord2f(ratiox + halfx, halfy);
- glVertex2f(soffx + (sizex * 0.5f), 0);
+ immUniform1i("image", 0); /* texture is already bound to GL_TEXTURE0 unit */
- glTexCoord2f(ratiox + halfx, ratioy + halfy);
- glVertex2f(soffx + (sizex * 0.5f), sizey);
+ immBegin(GWN_PRIM_TRI_FAN, 4);
- glTexCoord2f(halfx, ratioy + halfy);
- glVertex2f(soffx, sizey);
- glEnd();
+ immAttrib2f(texcoord, halfx, halfy);
+ immVertex2f(pos, soffx, 0.0f);
- glBindTexture(triple->target, 0);
- glDisable(triple->target);
- }
+ immAttrib2f(texcoord, 1.0f + halfx, halfy);
+ immVertex2f(pos, soffx + (sizex * 0.5f), 0.0f);
+
+ immAttrib2f(texcoord, 1.0f + halfx, 1.0f + halfy);
+ immVertex2f(pos, soffx + (sizex * 0.5f), sizey);
+
+ immAttrib2f(texcoord, halfx, 1.0f + halfy);
+ immVertex2f(pos, soffx, sizey);
+
+ immEnd();
+
+ immUnbindProgram();
}
-static void wm_method_draw_stereo3d_topbottom(wmWindow *win)
+void wm_stereo3d_draw_topbottom(wmWindow *win, int view)
{
- wmDrawData *drawdata;
- wmDrawTriple *triple;
- float halfx, halfy, ratiox, ratioy;
- int view;
+ Gwn_VertFormat *format = immVertexFormat();
+ unsigned int texcoord = GWN_vertformat_attr_add(format, "texCoord", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+ unsigned int pos = GWN_vertformat_attr_add(format, "pos", GWN_COMP_F32, 2, GWN_FETCH_FLOAT);
+
+ immBindBuiltinProgram(GPU_SHADER_2D_IMAGE);
+
int soffy;
+ if (view == STEREO_LEFT_ID) {
+ soffy = WM_window_pixels_y(win) * 0.5f;
+ }
+ else { /* STEREO_RIGHT_ID */
+ soffy = 0;
+ }
- for (view = 0; view < 2; view ++) {
- drawdata = BLI_findlink(&win->drawdata, (view * 2) + 1);
- triple = drawdata->triple;
+ const int sizex = WM_window_pixels_x(win);
+ const int sizey = WM_window_pixels_y(win);
- if (view == STEREO_LEFT_ID) {
- soffy = WM_window_pixels_y(win) * 0.5f;
- }
- else { /* STEREO_RIGHT_ID */
- soffy = 0;
- }
+ /* wmOrtho for the screen has this same offset */
+ const float halfx = GLA_PIXEL_OFS / sizex;
+ const float halfy = GLA_PIXEL_OFS / sizex;
- const int sizex = triple->x;
- const int sizey = triple->y;
-
- /* wmOrtho for the screen has this same offset */
- ratiox = sizex;
- ratioy = sizey;
- halfx = GLA_PIXEL_OFS;
- halfy = GLA_PIXEL_OFS;
-
- /* texture rectangle has unnormalized coordinates */
- if (triple->target == GL_TEXTURE_2D) {
- ratiox /= triple->x;
- ratioy /= triple->y;
- halfx /= triple->x;
- halfy /= triple->y;
- }
+ immUniform1i("image", 0); /* texture is already bound to GL_TEXTURE0 unit */
- glEnable(triple->target);
- glBindTexture(triple->target, triple->bind);
+ immBegin(GWN_PRIM_TRI_FAN, 4);
- glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
- glBegin(GL_QUADS);
- glTexCoord2f(halfx, halfy);
- glVertex2f(0, soffy);
+ immAttrib2f(texcoord, halfx, halfy);
+ immVertex2f(pos, 0.0f, soffy);
- glTexCoord2f(ratiox + halfx, halfy);
- glVertex2f(sizex, soffy);
+ immAttrib2f(texcoord, 1.0f + halfx, halfy);
+ immVertex2f(pos, sizex, soffy);
- glTexCoord2f(ratiox + halfx, ratioy + halfy);
- glVertex2f(sizex, soffy + (sizey * 0.5f));
+ immAttrib2f(texcoord, 1.0f + halfx, 1.0f + halfy);
+ immVertex2f(pos, sizex, soffy + (sizey * 0.5f));
- glTexCoord2f(halfx, ratioy + halfy);
- glVertex2f(0, soffy + (sizey * 0.5f));
- glEnd();
+ immAttrib2f(texcoord, halfx, 1.0f + halfy);
+ immVertex2f(pos, 0.0f, soffy + (sizey * 0.5f));
- glBindTexture(triple->target, 0);
- glDisable(triple->target);
- }
-}
+ immEnd();
-void wm_method_draw_stereo3d(const bContext *UNUSED(C), wmWindow *win)
-{
- switch (win->stereo3d_format->display_mode) {
- case S3D_DISPLAY_ANAGLYPH:
- wm_method_draw_stereo3d_anaglyph(win);
- break;
- case S3D_DISPLAY_INTERLACE:
- wm_method_draw_stereo3d_interlace(win);
- break;
- case S3D_DISPLAY_PAGEFLIP:
- wm_method_draw_stereo3d_pageflip(win);
- break;
- case S3D_DISPLAY_SIDEBYSIDE:
- wm_method_draw_stereo3d_sidebyside(win);
- break;
- case S3D_DISPLAY_TOPBOTTOM:
- wm_method_draw_stereo3d_topbottom(win);
- break;
- default:
- break;
- }
+ immUnbindProgram();
}
+
static bool wm_stereo3d_quadbuffer_supported(void)
{
- int gl_stereo = 0;
- glGetBooleanv(GL_STEREO, (GLboolean *)&gl_stereo);
- return gl_stereo != 0;
+ GLboolean stereo = GL_FALSE;
+ glGetBooleanv(GL_STEREO, &stereo);
+ return stereo == GL_TRUE;
}
static bool wm_stereo3d_is_fullscreen_required(eStereoDisplayMode stereo_display)
@@ -324,7 +268,8 @@ static bool wm_stereo3d_is_fullscreen_required(eStereoDisplayMode stereo_display
bool WM_stereo3d_enabled(wmWindow *win, bool skip_stereo3d_check)
{
- bScreen *screen = win->screen;
+ const bScreen *screen = WM_window_get_active_screen(win);
+ const Scene *scene = WM_window_get_active_scene(win);
/* some 3d methods change the window arrangement, thus they shouldn't
* toggle on/off just because there is no 3d elements being drawn */
@@ -332,7 +277,7 @@ bool WM_stereo3d_enabled(wmWindow *win, bool skip_stereo3d_check)
return GHOST_GetWindowState(win->ghostwin) == GHOST_kWindowStateFullScreen;
}
- if ((skip_stereo3d_check == false) && (ED_screen_stereo3d_required(screen) == false)) {
+ if ((skip_stereo3d_check == false) && (ED_screen_stereo3d_required(screen, scene) == false)) {
return false;
}
@@ -459,7 +404,7 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op)
prev_display_mode != win_src->stereo3d_format->display_mode)
{
/* in case the hardward supports pageflip but not the display */
- if ((win_dst = wm_window_copy_test(C, win_src))) {
+ if ((win_dst = wm_window_copy_test(C, win_src, false))) {
/* pass */
}
else {
@@ -469,14 +414,16 @@ int wm_stereo3d_set_exec(bContext *C, wmOperator *op)
}
}
else if (win_src->stereo3d_format->display_mode == S3D_DISPLAY_PAGEFLIP) {
- /* ED_screen_duplicate() can't handle other cases yet T44688 */
- if (win_src->screen->state != SCREENNORMAL) {
+ const bScreen *screen = WM_window_get_active_screen(win_src);
+
+ /* ED_workspace_layout_duplicate() can't handle other cases yet T44688 */
+ if (screen->state != SCREENNORMAL) {
BKE_report(op->reports, RPT_ERROR,
"Failed to switch to Time Sequential mode when in fullscreen");
ok = false;
}
/* pageflip requires a new window to be created with the proper OS flags */
- else if ((win_dst = wm_window_copy_test(C, win_src))) {
+ else if ((win_dst = wm_window_copy_test(C, win_src, false))) {
if (wm_stereo3d_quadbuffer_supported()) {
BKE_report(op->reports, RPT_INFO, "Quad-buffer window successfully created");
}
diff --git a/source/blender/windowmanager/intern/wm_subwindow.c b/source/blender/windowmanager/intern/wm_subwindow.c
index 458ac4a121a..89a12206a66 100644
--- a/source/blender/windowmanager/intern/wm_subwindow.c
+++ b/source/blender/windowmanager/intern/wm_subwindow.c
@@ -21,334 +21,87 @@
* Contributor(s): 2007 Blender Foundation (refactor)
*
* ***** END GPL LICENSE BLOCK *****
- *
- *
- * Subwindow opengl handling.
- * BTW: subwindows open/close in X11 are way too slow, tried it, and choose for my own system... (ton)
- *
*/
/** \file blender/windowmanager/intern/wm_subwindow.c
* \ingroup wm
*
- * Internal subwindows used for OpenGL state, used for regions and screens.
+ * OpenGL utilities for setting up 2D viewport for window and regions.
*/
-#include <string.h>
-
-#include "MEM_guardedalloc.h"
+#include "BLI_math.h"
+#include "BLI_rect.h"
-#include "DNA_windowmanager_types.h"
#include "DNA_screen_types.h"
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
+#include "DNA_windowmanager_types.h"
#include "BIF_gl.h"
-#include "GPU_extensions.h"
-#include "GPU_basic_shader.h"
+#include "GPU_matrix.h"
#include "WM_api.h"
-#include "wm_subwindow.h"
-
-/**
- * \note #wmSubWindow stored in #wmWindow but not exposed outside this C file,
- * it seems a bit redundant (area regions can store it too, but we keep it
- * because we can store all kind of future opengl fanciness here.
- *
- * We use indices and array because:
- * - index has safety, no pointers from this C file hanging around
- * - fast lookups of indices with array, list would give overhead
- * - old code used it this way...
- * - keep option open to have 2 screens using same window
- */
-
-typedef struct wmSubWindow {
- struct wmSubWindow *next, *prev;
-
- rcti winrct;
- int swinid;
-} wmSubWindow;
-
-/* ******************* open, free, set, get data ******************** */
-
-/* not subwindow itself */
-static void wm_subwindow_free(wmSubWindow *UNUSED(swin))
-{
- /* future fancy stuff */
-}
-
-void wm_subwindows_free(wmWindow *win)
-{
- wmSubWindow *swin;
-
- for (swin = win->subwindows.first; swin; swin = swin->next)
- wm_subwindow_free(swin);
-
- BLI_freelistN(&win->subwindows);
-}
-
-
-int wm_subwindow_get_id(wmWindow *win)
-{
- if (win->curswin)
- return win->curswin->swinid;
- return 0;
-}
-
-static wmSubWindow *swin_from_swinid(wmWindow *win, int swinid)
+void wmViewport(const rcti *winrct)
{
- wmSubWindow *swin;
-
- for (swin = win->subwindows.first; swin; swin = swin->next)
- if (swin->swinid == swinid)
- break;
- return swin;
-}
+ int width = BLI_rcti_size_x(winrct) + 1;
+ int height = BLI_rcti_size_y(winrct) + 1;
+ glViewport(winrct->xmin, winrct->ymin, width, height);
+ glScissor(winrct->xmin, winrct->ymin, width, height);
-static void wm_swin_size_get(wmSubWindow *swin, int *x, int *y)
-{
- *x = BLI_rcti_size_x(&swin->winrct) + 1;
- *y = BLI_rcti_size_y(&swin->winrct) + 1;
-}
-void wm_subwindow_size_get(wmWindow *win, int swinid, int *x, int *y)
-{
- wmSubWindow *swin = swin_from_swinid(win, swinid);
-
- if (swin) {
- wm_swin_size_get(swin, x, y);
- }
-}
-
-
-static void wm_swin_origin_get(wmSubWindow *swin, int *x, int *y)
-{
- *x = swin->winrct.xmin;
- *y = swin->winrct.ymin;
-}
-void wm_subwindow_origin_get(wmWindow *win, int swinid, int *x, int *y)
-{
- wmSubWindow *swin = swin_from_swinid(win, swinid);
-
- if (swin) {
- wm_swin_origin_get(swin, x, y);
- }
-}
-
-
-static void wm_swin_matrix_get(wmWindow *win, wmSubWindow *swin, float mat[4][4])
-{
- /* used by UI, should find a better way to get the matrix there */
- if (swin->swinid == win->screen->mainwin) {
- int width, height;
-
- wm_swin_size_get(swin, &width, &height);
- orthographic_m4(mat, -GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS, -100, 100);
- }
- else {
- glGetFloatv(GL_PROJECTION_MATRIX, (float *)mat);
- }
-}
-void wm_subwindow_matrix_get(wmWindow *win, int swinid, float mat[4][4])
-{
- wmSubWindow *swin = swin_from_swinid(win, swinid);
-
- if (swin) {
- wm_swin_matrix_get(win, swin, mat);
- }
-}
-
-
-static void wm_swin_rect_get(wmSubWindow *swin, rcti *r_rect)
-{
- *r_rect = swin->winrct;
-}
-void wm_subwindow_rect_get(wmWindow *win, int swinid, rcti *r_rect)
-{
- wmSubWindow *swin = swin_from_swinid(win, swinid);
-
- if (swin) {
- wm_swin_rect_get(swin, r_rect);
- }
-}
-
-
-static void wm_swin_rect_set(wmSubWindow *swin, const rcti *rect)
-{
- swin->winrct = *rect;
-}
-void wm_subwindow_rect_set(wmWindow *win, int swinid, const rcti *rect)
-{
- wmSubWindow *swin = swin_from_swinid(win, swinid);
-
- if (swin) {
- wm_swin_rect_set(swin, rect);
- }
-}
-
-
-/* always sets pixel-precise 2D window/view matrices */
-/* coords is in whole pixels. xmin = 15, xmax = 16: means window is 2 pix big */
-int wm_subwindow_open(wmWindow *win, const rcti *winrct, bool activate)
-{
- wmSubWindow *swin;
- int width, height;
- int freewinid = 1;
-
- for (swin = win->subwindows.first; swin; swin = swin->next)
- if (freewinid <= swin->swinid)
- freewinid = swin->swinid + 1;
-
- win->curswin = swin = MEM_callocN(sizeof(wmSubWindow), "swinopen");
- BLI_addtail(&win->subwindows, swin);
-
- swin->swinid = freewinid;
- swin->winrct = *winrct;
-
- if (activate) {
- /* and we appy it all right away */
- wmSubWindowSet(win, swin->swinid);
-
- /* extra service */
- wm_swin_size_get(swin, &width, &height);
- wmOrtho2_pixelspace(width, height);
- glLoadIdentity();
- }
-
- return swin->swinid;
-}
-
-void wm_subwindow_close(wmWindow *win, int swinid)
-{
- wmSubWindow *swin = swin_from_swinid(win, swinid);
-
- if (swin) {
- if (swin == win->curswin)
- win->curswin = NULL;
- wm_subwindow_free(swin);
- BLI_remlink(&win->subwindows, swin);
- MEM_freeN(swin);
- }
- else {
- printf("%s: Internal error, bad winid: %d\n", __func__, swinid);
- }
+ wmOrtho2_pixelspace(width, height);
+ gpuLoadIdentity();
}
-/* pixels go from 0-99 for a 100 pixel window */
-void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct, bool activate)
+void wmPartialViewport(rcti *drawrct, const rcti *winrct, const rcti *partialrct)
{
- wmSubWindow *swin = swin_from_swinid(win, swinid);
-
- if (swin) {
- const int winsize_x = WM_window_pixels_x(win);
- const int winsize_y = WM_window_pixels_y(win);
+ /* Setup part of the viewport for partial redraw. */
+ bool scissor_pad;
- int width, height;
-
- swin->winrct = *winrct;
-
- /* CRITICAL, this clamping ensures that
- * the viewport never goes outside the screen
- * edges (assuming the x, y coords aren't
- * outside). This caused a hardware lock
- * on Matrox cards if it happens.
- *
- * Really Blender should never _ever_ try
- * to do such a thing, but just to be safe
- * clamp it anyway (or fix the bScreen
- * scaling routine, and be damn sure you
- * fixed it). - zr (2001!)
- */
-
- if (swin->winrct.xmax > winsize_x)
- swin->winrct.xmax = winsize_x;
- if (swin->winrct.ymax > winsize_y)
- swin->winrct.ymax = winsize_y;
-
- if (activate) {
- /* extra service */
- wmSubWindowSet(win, swinid);
- wm_swin_size_get(swin, &width, &height);
- wmOrtho2_pixelspace(width, height);
- }
+ if (partialrct->xmin == partialrct->xmax) {
+ /* Full region. */
+ *drawrct = *winrct;
+ scissor_pad = true;
}
else {
- printf("%s: Internal error, bad winid: %d\n", __func__, swinid);
+ /* Partial redraw, clipped to region. */
+ BLI_rcti_isect(winrct, partialrct, drawrct);
+ scissor_pad = false;
}
-}
-/* ---------------- WM versions of OpenGL style API calls ------------------------ */
-/* ----------------- exported in WM_api.h ------------------------------------------------------ */
+ int x = drawrct->xmin - winrct->xmin;
+ int y = drawrct->ymin - winrct->ymin;
+ int width = BLI_rcti_size_x(winrct) + 1;
+ int height = BLI_rcti_size_y(winrct) + 1;
-/* internal state, no threaded opengl! XXX */
-static wmWindow *_curwindow = NULL;
-static wmSubWindow *_curswin = NULL;
+ int scissor_width = BLI_rcti_size_x(drawrct);
+ int scissor_height = BLI_rcti_size_y(drawrct);
-void wmSubWindowScissorSet(wmWindow *win, int swinid, const rcti *srct, bool srct_pad)
-{
- int width, height;
- _curswin = swin_from_swinid(win, swinid);
-
- if (_curswin == NULL) {
- printf("%s %d: doesn't exist\n", __func__, swinid);
- return;
+ /* Partial redraw rect uses different convention than region rect,
+ * so compensate for that here. One pixel offset is noticeable with
+ * viewport border render. */
+ if (scissor_pad) {
+ scissor_width += 1;
+ scissor_height += 1;
}
-
- win->curswin = _curswin;
- _curwindow = win;
-
- width = BLI_rcti_size_x(&_curswin->winrct) + 1;
- height = BLI_rcti_size_y(&_curswin->winrct) + 1;
- glViewport(_curswin->winrct.xmin, _curswin->winrct.ymin, width, height);
-
- if (srct) {
- int scissor_width = BLI_rcti_size_x(srct);
- int scissor_height = BLI_rcti_size_y(srct);
- /* typically a single pixel doesn't matter,
- * but one pixel offset is noticeable with viewport border render */
- if (srct_pad) {
- scissor_width += 1;
- scissor_height += 1;
- }
+ glViewport(0, 0, width, height);
+ glScissor(x, y, scissor_width, scissor_height);
- glScissor(srct->xmin, srct->ymin, scissor_width, scissor_height);
- }
- else
- glScissor(_curswin->winrct.xmin, _curswin->winrct.ymin, width, height);
-
wmOrtho2_pixelspace(width, height);
- glLoadIdentity();
-
- glFlush();
-}
-
-/* enable the WM versions of opengl calls */
-void wmSubWindowSet(wmWindow *win, int swinid)
-{
- wmSubWindowScissorSet(win, swinid, NULL, true);
-}
-
-void wmFrustum(float x1, float x2, float y1, float y2, float n, float f)
-{
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(x1, x2, y1, y2, n, f);
- glMatrixMode(GL_MODELVIEW);
+ gpuLoadIdentity();
}
-void wmOrtho(float x1, float x2, float y1, float y2, float n, float f)
+void wmWindowViewport(wmWindow *win)
{
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
+ int width = WM_window_pixels_x(win);
+ int height = WM_window_pixels_y(win);
- glOrtho(x1, x2, y1, y2, n, f);
+ glViewport(0, 0, width, height);
+ glScissor(0, 0, width, height);
- glMatrixMode(GL_MODELVIEW);
+ wmOrtho2_pixelspace(width, height);
+ gpuLoadIdentity();
}
void wmOrtho2(float x1, float x2, float y1, float y2)
@@ -357,7 +110,7 @@ void wmOrtho2(float x1, float x2, float y1, float y2)
if (x1 == x2) x2 += 1.0f;
if (y1 == y2) y2 += 1.0f;
- wmOrtho(x1, x2, y1, y2, -100, 100);
+ gpuOrtho(x1, x2, y1, y2, -100, 100);
}
static void wmOrtho2_offset(const float x, const float y, const float ofs)
@@ -365,9 +118,7 @@ static void wmOrtho2_offset(const float x, const float y, const float ofs)
wmOrtho2(ofs, x + ofs, ofs, y + ofs);
}
-/**
- * default pixel alignment.
- */
+/* Default pixel alignment for regions. */
void wmOrtho2_region_pixelspace(const ARegion *ar)
{
wmOrtho2_offset(ar->winx, ar->winy, -0.01f);
@@ -378,5 +129,9 @@ void wmOrtho2_pixelspace(const float x, const float y)
wmOrtho2_offset(x, y, -GLA_PIXEL_OFS);
}
-/* ********** END MY WINDOW ************** */
-
+void wmGetProjectionMatrix(float mat[4][4], const rcti *winrct)
+{
+ int width = BLI_rcti_size_x(winrct) + 1;
+ int height = BLI_rcti_size_y(winrct) + 1;
+ orthographic_m4(mat, -GLA_PIXEL_OFS, (float)width - GLA_PIXEL_OFS, -GLA_PIXEL_OFS, (float)height - GLA_PIXEL_OFS, -100, 100);
+}
diff --git a/source/blender/windowmanager/intern/wm_toolsystem.c b/source/blender/windowmanager/intern/wm_toolsystem.c
new file mode 100644
index 00000000000..e449695e3cf
--- /dev/null
+++ b/source/blender/windowmanager/intern/wm_toolsystem.c
@@ -0,0 +1,161 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/intern/wm_toolsystem.c
+ * \ingroup wm
+ *
+ * Experimental tool-system>
+ */
+
+#include <string.h>
+
+#include "CLG_log.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_string.h"
+
+#include "DNA_ID.h"
+#include "DNA_scene_types.h"
+#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
+
+#include "BKE_context.h"
+#include "BKE_library.h"
+#include "BKE_main.h"
+#include "BKE_paint.h"
+#include "BKE_workspace.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "WM_message.h"
+
+void WM_toolsystem_unlink(bContext *C, WorkSpace *workspace)
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindowManager *wm = bmain->wm.first;
+
+ if (workspace->tool.manipulator_group[0]) {
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(workspace->tool.manipulator_group, false);
+ if (wgt != NULL) {
+ bool found = false;
+
+ /* Check another workspace isn't using this tool. */
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ const WorkSpace *workspace_iter = WM_window_get_active_workspace(win);
+ if (workspace != workspace_iter) {
+ if (STREQ(workspace->tool.manipulator_group, workspace_iter->tool.manipulator_group)) {
+ found = true;
+ break;
+ }
+ }
+ }
+
+ if (!found) {
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params);
+ WM_manipulatormaptype_group_unlink(C, bmain, mmap_type, wgt);
+ }
+ }
+ }
+}
+
+void WM_toolsystem_link(bContext *C, WorkSpace *workspace)
+{
+ if (workspace->tool.manipulator_group[0]) {
+ const char *idname = workspace->tool.manipulator_group;
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, false);
+ if (wgt != NULL) {
+ WM_manipulator_group_type_ensure_ptr(wgt);
+ }
+ else {
+ CLOG_WARN(WM_LOG_TOOLS, "'%s' widget not found", idname);
+ }
+ }
+
+ if (workspace->tool.data_block[0]) {
+ Main *bmain = CTX_data_main(C);
+
+ /* Currently only brush data-blocks supported. */
+ struct Brush *brush = (struct Brush *)BKE_libblock_find_name(ID_BR, workspace->tool.data_block);
+
+ if (brush) {
+ wmWindowManager *wm = bmain->wm.first;
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ if (workspace == WM_window_get_active_workspace(win)) {
+ Scene *scene = win->scene;
+ ViewLayer *view_layer = BKE_workspace_view_layer_get(workspace, scene);
+ Paint *paint = BKE_paint_get_active(scene, view_layer);
+ if (paint) {
+ if (brush) {
+ BKE_paint_brush_set(paint, brush);
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void WM_toolsystem_set(bContext *C, const bToolDef *tool)
+{
+ WorkSpace *workspace = CTX_wm_workspace(C);
+
+ WM_toolsystem_unlink(C, workspace);
+
+ workspace->tool.index = tool->index;
+ workspace->tool.spacetype = tool->spacetype;
+
+ if (&workspace->tool != tool) {
+ STRNCPY(workspace->tool.keymap, tool->keymap);
+ STRNCPY(workspace->tool.manipulator_group, tool->manipulator_group);
+ STRNCPY(workspace->tool.data_block, tool->data_block);
+ workspace->tool.spacetype = tool->spacetype;
+ }
+
+ WM_toolsystem_link(C, workspace);
+
+ {
+ struct wmMsgBus *mbus = CTX_wm_message_bus(C);
+ WM_msg_publish_rna_prop(
+ mbus, &workspace->id, workspace, WorkSpace, tool_keymap);
+ }
+}
+
+void WM_toolsystem_init(bContext *C)
+{
+ Main *bmain = CTX_data_main(C);
+ wmWindowManager *wm = bmain->wm.first;
+
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ WM_toolsystem_link(C, workspace);
+ }
+}
+
+/**
+ * For paint modes to support non-brush tools.
+ */
+bool WM_toolsystem_active_tool_is_brush(const bContext *C)
+{
+ WorkSpace *workspace = CTX_wm_workspace(C);
+ /* Will need to become more comprehensive, for now check tool data-block. */
+ return workspace->tool.data_block[0] != '\0';
+}
diff --git a/source/blender/windowmanager/intern/wm_tooltip.c b/source/blender/windowmanager/intern/wm_tooltip.c
index 86ca95ef377..83d620d1522 100644
--- a/source/blender/windowmanager/intern/wm_tooltip.c
+++ b/source/blender/windowmanager/intern/wm_tooltip.c
@@ -41,7 +41,7 @@ void WM_tooltip_timer_init(
bContext *C, wmWindow *win, ARegion *ar,
wmTooltipInitFn init)
{
- bScreen *screen = win->screen;
+ bScreen *screen = WM_window_get_active_screen(win);
wmWindowManager *wm = CTX_wm_manager(C);
if (screen->tool_tip == NULL) {
screen->tool_tip = MEM_callocN(sizeof(*screen->tool_tip), __func__);
@@ -54,7 +54,7 @@ void WM_tooltip_timer_init(
void WM_tooltip_timer_clear(bContext *C, wmWindow *win)
{
wmWindowManager *wm = CTX_wm_manager(C);
- bScreen *screen = win->screen;
+ bScreen *screen = WM_window_get_active_screen(win);
if (screen->tool_tip != NULL) {
if (screen->tool_tip->timer != NULL) {
WM_event_remove_timer(wm, win, screen->tool_tip->timer);
@@ -66,7 +66,7 @@ void WM_tooltip_timer_clear(bContext *C, wmWindow *win)
void WM_tooltip_clear(bContext *C, wmWindow *win)
{
WM_tooltip_timer_clear(C, win);
- bScreen *screen = win->screen;
+ bScreen *screen = WM_window_get_active_screen(win);
if (screen->tool_tip != NULL) {
if (screen->tool_tip->region) {
UI_tooltip_free(C, screen, screen->tool_tip->region);
@@ -80,7 +80,7 @@ void WM_tooltip_clear(bContext *C, wmWindow *win)
void WM_tooltip_init(bContext *C, wmWindow *win)
{
WM_tooltip_timer_clear(C, win);
- bScreen *screen = win->screen;
+ bScreen *screen = WM_window_get_active_screen(win);
if (screen->tool_tip->region) {
UI_tooltip_free(C, screen, screen->tool_tip->region);
screen->tool_tip->region = NULL;
@@ -95,7 +95,7 @@ void WM_tooltip_init(bContext *C, wmWindow *win)
void WM_tooltip_refresh(bContext *C, wmWindow *win)
{
WM_tooltip_timer_clear(C, win);
- bScreen *screen = win->screen;
+ bScreen *screen = WM_window_get_active_screen(win);
if (screen->tool_tip != NULL) {
if (screen->tool_tip->region) {
UI_tooltip_free(C, screen, screen->tool_tip->region);
diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c
index 06bd60e8692..2d94cc1dae7 100644
--- a/source/blender/windowmanager/intern/wm_window.c
+++ b/source/blender/windowmanager/intern/wm_window.c
@@ -38,6 +38,7 @@
#include "DNA_listBase.h"
#include "DNA_screen_types.h"
#include "DNA_windowmanager_types.h"
+#include "DNA_workspace_types.h"
#include "MEM_guardedalloc.h"
@@ -51,35 +52,45 @@
#include "BKE_blender.h"
#include "BKE_context.h"
+#include "BKE_icons.h"
#include "BKE_library.h"
#include "BKE_global.h"
#include "BKE_main.h"
-
+#include "BKE_screen.h"
+#include "BKE_workspace.h"
#include "RNA_access.h"
+#include "RNA_define.h"
+#include "RNA_enum_types.h"
#include "WM_api.h"
#include "WM_types.h"
#include "wm.h"
#include "wm_draw.h"
#include "wm_window.h"
-#include "wm_subwindow.h"
#include "wm_event_system.h"
+#include "ED_scene.h"
#include "ED_screen.h"
#include "ED_fileselect.h"
#include "UI_interface.h"
-#include "UI_resources.h"
+#include "UI_interface_icons.h"
#include "PIL_time.h"
+#include "GPU_batch.h"
#include "GPU_draw.h"
#include "GPU_extensions.h"
+#include "GPU_framebuffer.h"
#include "GPU_init_exit.h"
-#include "GPU_glew.h"
+#include "GPU_immediate.h"
#include "BLF_api.h"
+#include "UI_resources.h"
+
+#include "../../../intern/gawain/gawain/gwn_context.h"
+
/* for assert */
#ifndef NDEBUG
# include "BLI_threads.h"
@@ -162,12 +173,23 @@ static void wm_window_check_position(rcti *rect)
}
-static void wm_ghostwindow_destroy(wmWindow *win)
+static void wm_ghostwindow_destroy(wmWindowManager *wm, wmWindow *win)
{
if (win->ghostwin) {
+ /* We need this window's opengl context active to discard it. */
+ GHOST_ActivateWindowDrawingContext(win->ghostwin);
+ GWN_context_active_set(win->gwnctx);
+
+ /* Delete local gawain objects. */
+ GWN_context_discard(win->gwnctx);
+
GHOST_DisposeWindow(g_system, win->ghostwin);
win->ghostwin = NULL;
- win->multisamples = 0;
+ win->gwnctx = NULL;
+
+ /* prevents non-drawable state of main windows (bugs #22967 and #25071, possibly #22477 too) */
+ wm->windrawable = NULL;
+ wm->winactive = NULL;
}
}
@@ -186,10 +208,7 @@ void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
CTX_wm_window_set(C, NULL);
}
- /* always set drawable and active to NULL,
- * prevents non-drawable state of main windows (bugs #22967 and #25071, possibly #22477 too) */
- wm->windrawable = NULL;
- wm->winactive = NULL;
+ BKE_screen_area_map_free(&win->global_areas);
/* end running jobs, a job end also removes its timer */
for (wt = wm->timers.first; wt; wt = wtnext) {
@@ -208,12 +227,10 @@ void wm_window_free(bContext *C, wmWindowManager *wm, wmWindow *win)
if (win->eventstate) MEM_freeN(win->eventstate);
wm_event_free_all(win);
- wm_subwindows_free(win);
-
- wm_draw_data_free(win);
- wm_ghostwindow_destroy(win);
+ wm_ghostwindow_destroy(wm, win);
+ BKE_workspace_instance_hook_free(G.main, win->workspace_hook);
MEM_freeN(win->stereo3d_format);
MEM_freeN(win);
@@ -234,39 +251,57 @@ static int find_free_winid(wmWindowManager *wm)
/* don't change context itself */
wmWindow *wm_window_new(bContext *C)
{
+ Main *bmain = CTX_data_main(C);
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win = MEM_callocN(sizeof(wmWindow), "window");
-
+
BLI_addtail(&wm->windows, win);
win->winid = find_free_winid(wm);
win->stereo3d_format = MEM_callocN(sizeof(Stereo3dFormat), "Stereo 3D Format (window)");
+ win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
return win;
}
+/**
+ * A higher level version of copy that tests the new window can be added.
+ */
+static wmWindow *wm_window_new_test(bContext *C)
+{
+ wmWindow *win = wm_window_new(C);
+
+ WM_check(C);
+
+ if (win->ghostwin) {
+ WM_event_add_notifier(C, NC_WINDOW | NA_ADDED, NULL);
+ return win;
+ }
+ else {
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wm_window_close(C, wm, win);
+ return NULL;
+ }
+}
/* part of wm_window.c api */
-wmWindow *wm_window_copy(bContext *C, wmWindow *win_src)
+wmWindow *wm_window_copy(bContext *C, wmWindow *win_src, const bool duplicate_layout)
{
wmWindow *win_dst = wm_window_new(C);
-
+ WorkSpace *workspace = WM_window_get_active_workspace(win_src);
+ WorkSpaceLayout *layout_old = WM_window_get_active_layout(win_src);
+ Scene *scene = WM_window_get_active_scene(win_src);
+ WorkSpaceLayout *layout_new;
+
win_dst->posx = win_src->posx + 10;
win_dst->posy = win_src->posy;
win_dst->sizex = win_src->sizex;
win_dst->sizey = win_src->sizey;
-
- /* duplicate assigns to window */
- win_dst->screen = ED_screen_duplicate(win_dst, win_src->screen);
- BLI_strncpy(win_dst->screenname, win_dst->screen->id.name + 2, sizeof(win_dst->screenname));
- win_dst->screen->winid = win_dst->winid;
-
- win_dst->screen->do_refresh = true;
- win_dst->screen->do_draw = true;
-
- win_dst->drawmethod = U.wmdrawmethod;
- BLI_listbase_clear(&win_dst->drawdata);
+ win_dst->scene = scene;
+ WM_window_set_active_workspace(win_dst, workspace);
+ layout_new = duplicate_layout ? ED_workspace_layout_duplicate(workspace, layout_old, win_dst) : layout_old;
+ WM_window_set_active_layout(win_dst, workspace, layout_new);
*win_dst->stereo3d_format = *win_src->stereo3d_format;
@@ -277,12 +312,12 @@ wmWindow *wm_window_copy(bContext *C, wmWindow *win_src)
* A higher level version of copy that tests the new window can be added.
* (called from the operator directly)
*/
-wmWindow *wm_window_copy_test(bContext *C, wmWindow *win_src)
+wmWindow *wm_window_copy_test(bContext *C, wmWindow *win_src, const bool duplicate_layout)
{
wmWindowManager *wm = CTX_wm_manager(C);
wmWindow *win_dst;
- win_dst = wm_window_copy(C, win_src);
+ win_dst = wm_window_copy(C, win_src, duplicate_layout);
WM_check(C);
@@ -453,7 +488,7 @@ void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
for (tmpwin = wm->windows.first; tmpwin; tmpwin = tmpwin->next) {
if (tmpwin == win)
continue;
- if (tmpwin->screen->temp == 0)
+ if (WM_window_is_temp_screen(tmpwin) == false)
break;
}
@@ -461,36 +496,50 @@ void wm_window_close(bContext *C, wmWindowManager *wm, wmWindow *win)
wm_quit_with_optional_confirmation_prompt(C, win);
}
else {
- /* We're just closing a window */
- bScreen *screen = win->screen;
-
+ bScreen *screen = WM_window_get_active_screen(win);
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ WorkSpaceLayout *layout = BKE_workspace_active_layout_get(win->workspace_hook);
+
BLI_remlink(&wm->windows, win);
- wm_draw_window_clear(win);
-
CTX_wm_window_set(C, win); /* needed by handlers */
WM_event_remove_handlers(C, &win->handlers);
WM_event_remove_handlers(C, &win->modalhandlers);
/* for regular use this will _never_ be NULL,
* however we may be freeing an improperly initialized window. */
- if (win->screen) {
- ED_screen_exit(C, win, win->screen);
+ if (screen) {
+ ED_screen_exit(C, win, screen);
}
-
+
+ if (tmpwin) {
+ BLF_batch_reset();
+ gpu_batch_presets_reset();
+ immDeactivate();
+ }
+
wm_window_free(C, wm, win);
-
+
+ /* keep imediatemode active before the next `wm_window_make_drawable` call */
+ if (tmpwin) {
+ GHOST_ActivateWindowDrawingContext(tmpwin->ghostwin);
+ GWN_context_active_set(tmpwin->gwnctx);
+ immActivate();
+ }
+
/* if temp screen, delete it after window free (it stops jobs that can access it) */
if (screen && screen->temp) {
Main *bmain = CTX_data_main(C);
- BKE_libblock_free(bmain, screen);
+
+ BLI_assert(BKE_workspace_layout_screen_get(layout) == screen);
+ BKE_workspace_layout_remove(bmain, workspace, layout);
}
- }
+ }
}
void wm_window_title(wmWindowManager *wm, wmWindow *win)
{
- if (win->screen && win->screen->temp) {
+ if (WM_window_is_temp_screen(win)) {
/* nothing to do for 'temp' windows,
* because WM_window_open_temp always sets window title */
}
@@ -553,6 +602,7 @@ void WM_window_set_dpi(wmWindow *win)
U.dpi = dpi / pixelsize;
U.virtual_pixel = (pixelsize == 1) ? VIRTUAL_PIXEL_NATIVE : VIRTUAL_PIXEL_DOUBLE;
U.widget_unit = (U.pixelsize * U.dpi * 20 + 36) / 72;
+ U.dpi_fac = ((U.pixelsize * (float)U.dpi) / 72.0f);
/* update font drawing */
BLF_default_dpi(U.pixelsize * U.dpi);
@@ -563,16 +613,8 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wm
{
GHOST_WindowHandle ghostwin;
GHOST_GLSettings glSettings = {0};
- static int multisamples = -1;
int scr_w, scr_h, posy;
- /* force setting multisamples only once, it requires restart - and you cannot
- * mix it, either all windows have it, or none (tested in OSX opengl) */
- if (multisamples == -1)
- multisamples = U.ogl_multisamples;
-
- glSettings.numOfAASamples = multisamples;
-
/* a new window is created when pageflip mode is required for a window */
if (win->stereo3d_format->display_mode == S3D_DISPLAY_PAGEFLIP)
glSettings.flags |= GHOST_glStereoVisual;
@@ -589,9 +631,16 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wm
(GHOST_TWindowState)win->windowstate,
GHOST_kDrawingContextTypeOpenGL,
glSettings);
-
+
if (ghostwin) {
GHOST_RectangleHandle bounds;
+
+ /* XXX Fix crash when a new window is created.
+ * However this should be move somewhere else. (fclem) */
+ BLF_batch_reset();
+ gpu_batch_presets_reset();
+
+ win->gwnctx = GWN_context_create();
/* the new window has already been made drawable upon creation */
wm->windrawable = win;
@@ -605,9 +654,6 @@ static void wm_window_ghostwindow_add(wmWindowManager *wm, const char *title, wm
if (win->eventstate == NULL)
win->eventstate = MEM_callocN(sizeof(wmEvent), "window event state");
- /* store multisamples window was created with, in case user prefs change */
- win->multisamples = multisamples;
-
/* store actual window size in blender window */
bounds = GHOST_GetClientBounds(win->ghostwin);
@@ -731,6 +777,11 @@ void wm_window_ghostwindows_ensure(wmWindowManager *wm)
WM_event_add_dropbox_handler(&win->handlers, lb);
}
wm_window_title(wm, win);
+
+ /* add topbar */
+ if (BLI_listbase_is_empty(&win->global_areas.areabase)) {
+ ED_screen_global_areas_create(win);
+ }
}
}
@@ -768,8 +819,6 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect)
win->sizex = BLI_rcti_size_x(rect);
win->sizey = BLI_rcti_size_y(rect);
- win->drawmethod = U.wmdrawmethod;
-
WM_check(C);
if (win->ghostwin) {
@@ -791,8 +840,10 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect)
*/
wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, int type)
{
+ Main *bmain = CTX_data_main(C);
wmWindow *win_prev = CTX_wm_window(C);
wmWindow *win;
+ bScreen *screen;
ScrArea *sa;
Scene *scene = CTX_data_scene(C);
const char *title;
@@ -816,7 +867,7 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
/* test if we have a temp screen already */
for (win = CTX_wm_manager(C)->windows.first; win; win = win->next)
- if (win->screen->temp)
+ if (WM_window_is_temp_screen(win))
break;
/* add new window? */
@@ -827,6 +878,8 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
win->posy = rect.ymin;
}
+ screen = WM_window_get_active_screen(win);
+
win->sizex = BLI_rcti_size_x(&rect);
win->sizey = BLI_rcti_size_y(&rect);
@@ -834,19 +887,31 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
wm_window_set_size(win, win->sizex, win->sizey);
wm_window_raise(win);
}
-
- if (win->screen == NULL) {
- /* add new screen */
- win->screen = ED_screen_add(win, scene, "temp");
+
+ if (WM_window_get_active_workspace(win) == NULL) {
+ WorkSpace *workspace = WM_window_get_active_workspace(win_prev);
+ WM_window_set_active_workspace(win, workspace);
}
- else {
- /* switch scene for rendering */
- if (win->screen->scene != scene)
- ED_screen_set_scene(C, win->screen, scene);
+
+ if (screen == NULL) {
+ /* add new screen layout */
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ WorkSpaceLayout *layout = ED_workspace_layout_add(workspace, win, "temp");
+
+ screen = BKE_workspace_layout_screen_get(layout);
+ WM_window_set_active_layout(win, workspace, layout);
}
- win->screen->temp = 1;
-
+ if (win->scene == NULL) {
+ win->scene = scene;
+ }
+ /* In case we reuse an already existing temp window (see win lookup above). */
+ else if (WM_window_get_active_scene(win) != scene) {
+ WM_window_change_active_scene(bmain, C, win, scene);
+ }
+
+ screen->temp = 1;
+
/* make window active, and validate/resize */
CTX_wm_window_set(C, win);
WM_check(C);
@@ -858,7 +923,7 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
*/
/* ensure it shows the right spacetype editor */
- sa = win->screen->areabase.first;
+ sa = screen->areabase.first;
CTX_wm_area_set(C, sa);
if (type == WM_WINDOW_RENDER) {
@@ -868,7 +933,7 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
ED_area_newspace(C, sa, SPACE_USERPREF, false);
}
- ED_screen_set(C, win->screen);
+ ED_screen_change(C, screen);
ED_screen_refresh(CTX_wm_manager(C), win); /* test scale */
if (sa->spacetype == SPACE_IMAGE)
@@ -904,17 +969,108 @@ int wm_window_close_exec(bContext *C, wmOperator *UNUSED(op))
return OPERATOR_FINISHED;
}
-/* operator callback */
-int wm_window_duplicate_exec(bContext *C, wmOperator *UNUSED(op))
+static WorkSpaceLayout *wm_window_new_find_layout(wmOperator *op, WorkSpace *workspace)
+{
+ ListBase *listbase = BKE_workspace_layouts_get(workspace);
+ const int layout_id = RNA_enum_get(op->ptr, "screen");
+ int i = 0;
+
+ for (WorkSpaceLayout *layout = listbase->first; layout; layout = layout->next) {
+ if (i++ == layout_id) {
+ return layout;
+ }
+ }
+
+ BLI_assert(0);
+ return NULL;
+}
+
+/* new window operator callback */
+int wm_window_new_exec(bContext *C, wmOperator *op)
{
wmWindow *win_src = CTX_wm_window(C);
- bool ok;
+ WorkSpace *workspace = WM_window_get_active_workspace(win_src);
+ WorkSpaceLayout *layout_new = wm_window_new_find_layout(op, workspace);
+ bScreen *screen_new = BKE_workspace_layout_screen_get(layout_new);
+ wmWindow *win_dst;
- ok = (wm_window_copy_test(C, win_src) != NULL);
+ if ((win_dst = wm_window_new_test(C))) {
+ if (screen_new->winid) {
+ /* layout/screen is already used, duplicate it */
+ layout_new = ED_workspace_layout_duplicate(workspace, layout_new, win_dst);
+ screen_new = BKE_workspace_layout_screen_get(layout_new);
+ }
+ /* New window with a different screen but same workspace */
+ WM_window_set_active_workspace(win_dst, workspace);
+ WM_window_set_active_screen(win_dst, workspace, screen_new);
+ win_dst->scene = win_src->scene;
+ screen_new->winid = win_dst->winid;
+ CTX_wm_window_set(C, win_dst);
+
+ ED_screen_refresh(CTX_wm_manager(C), win_dst);
+ }
- return ok ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
+ return (win_dst != NULL) ? OPERATOR_FINISHED : OPERATOR_CANCELLED;
}
+int wm_window_new_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ wmWindow *win = CTX_wm_window(C);
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ ListBase *listbase = BKE_workspace_layouts_get(workspace);
+
+ if (BLI_listbase_count_at_most(listbase, 2) == 1) {
+ RNA_enum_set(op->ptr, "screen", 0);
+ return wm_window_new_exec(C, op);
+ }
+ else {
+ return WM_enum_search_invoke_previews(C, op, 6, 2);
+ }
+}
+
+const EnumPropertyItem *wm_window_new_screen_itemf(
+ bContext *C, struct PointerRNA *UNUSED(ptr), struct PropertyRNA *UNUSED(prop), bool *r_free)
+{
+ if (C == NULL) {
+ return DummyRNA_NULL_items;
+ }
+ wmWindow *win = CTX_wm_window(C);
+ WorkSpace *workspace = WM_window_get_active_workspace(win);
+ ListBase *listbase = BKE_workspace_layouts_get(workspace);
+ EnumPropertyItem *item = NULL;
+ EnumPropertyItem tmp = {0, "", 0, "", ""};
+ int value = 0, totitem = 0;
+ int count_act_screens = 0;
+ /* XXX setting max number of windows to 20. We'd need support
+ * for dynamic strings in EnumPropertyItem.name to avoid this. */
+ static char active_screens[20][MAX_NAME + 12];
+
+ for (WorkSpaceLayout *layout = listbase->first; layout; layout = layout->next) {
+ bScreen *screen = BKE_workspace_layout_screen_get(layout);
+ const char *layout_name = BKE_workspace_layout_name_get(layout);
+
+ if (screen->winid) {
+ BLI_snprintf(active_screens[count_act_screens], sizeof(*active_screens), "%s (Duplicate)", layout_name);
+ tmp.name = active_screens[count_act_screens++];
+ }
+ else {
+ tmp.name = layout_name;
+ }
+
+ tmp.value = value;
+ tmp.identifier = layout_name;
+ UI_id_icon_render(C, CTX_data_scene(C), &screen->id, true, false);
+ tmp.icon = BKE_icon_id_ensure(&screen->id);
+
+ RNA_enum_item_add(&item, &totitem, &tmp);
+ value++;
+ }
+
+ RNA_enum_item_end(&item, &totitem);
+ *r_free = true;
+
+ return item;
+}
/* fullscreen operator callback */
int wm_window_fullscreen_toggle_exec(bContext *C, wmOperator *UNUSED(op))
@@ -1007,20 +1163,50 @@ static int query_qual(modifierKeyType qual)
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
{
+ BLI_assert(GPU_framebuffer_current_get() == 0);
+
if (win != wm->windrawable && win->ghostwin) {
// win->lmbut = 0; /* keeps hanging when mousepressed while other window opened */
-
+
wm->windrawable = win;
if (G.debug & G_DEBUG_EVENTS) {
printf("%s: set drawable %d\n", __func__, win->winid);
}
+
+ BLF_batch_reset();
+ gpu_batch_presets_reset();
+ immDeactivate();
GHOST_ActivateWindowDrawingContext(win->ghostwin);
-
+ GWN_context_active_set(win->gwnctx);
+ immActivate();
+
/* this can change per window */
WM_window_set_dpi(win);
}
}
+/* Reset active the current window opengl drawing context. */
+void wm_window_reset_drawable(void)
+{
+ BLI_assert(BLI_thread_is_main());
+ BLI_assert(GPU_framebuffer_current_get() == 0);
+ wmWindowManager *wm = G.main->wm.first;
+
+ if (wm == NULL)
+ return;
+
+ wmWindow *win = wm->windrawable;
+
+ if (win && win->ghostwin) {
+ BLF_batch_reset();
+ gpu_batch_presets_reset();
+ immDeactivate();
+ GHOST_ActivateWindowDrawingContext(win->ghostwin);
+ GWN_context_active_set(win->gwnctx);
+ immActivate();
+ }
+}
+
/* called by ghost, here we handle events for windows themselves or send to event system */
/* mouse coordinate converversion happens here */
static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr)
@@ -1040,7 +1226,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
/* Ghost now can call this function for life resizes, but it should return if WM didn't initialize yet.
* Can happen on file read (especially full size window) */
- if ((wm->initialized & WM_INIT_WINDOW) == 0) {
+ if ((wm->initialized & WM_WINDOW_IS_INITIALIZED) == 0) {
return 1;
}
if (!ghostwin) {
@@ -1214,7 +1400,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
/* stop screencast if resize */
if (type == GHOST_kEventWindowSize) {
- WM_jobs_stop(wm, win->screen, NULL);
+ WM_jobs_stop(wm, WM_window_get_active_screen(win), NULL);
}
WM_window_set_dpi(win);
@@ -1249,6 +1435,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
win->posx != posx ||
win->posy != posy)
{
+ const bScreen *screen = WM_window_get_active_screen(win);
+
win->sizex = sizex;
win->sizey = sizey;
win->posx = posx;
@@ -1284,7 +1472,7 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
}
wm_window_make_drawable(wm, win);
- wm_draw_window_clear(win);
+ BKE_icon_changed(screen->id.icon_id);
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
@@ -1396,6 +1584,8 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
WM_window_set_dpi(win);
if (U.pixelsize != prev_pixelsize) {
+ BKE_icon_changed(WM_window_get_active_screen(win)->id.icon_id);
+
// close all popups since they are positioned with the pixel
// size baked in and it's difficult to correct them
wmWindow *oldWindow = CTX_wm_window(C);
@@ -1404,7 +1594,6 @@ static int ghost_event_proc(GHOST_EventHandle evt, GHOST_TUserDataPtr C_void_ptr
CTX_wm_window_set(C, oldWindow);
wm_window_make_drawable(wm, win);
- wm_draw_window_clear(win);
WM_event_add_notifier(C, NC_SCREEN | NA_EDITED, NULL);
WM_event_add_notifier(C, NC_WINDOW | NA_EDITED, NULL);
@@ -1535,13 +1724,22 @@ void wm_window_testbreak(void)
/* **************** init ********************** */
+/* bContext can be null in background mode because we don't
+ * need to event handling. */
void wm_ghost_init(bContext *C)
{
if (!g_system) {
- GHOST_EventConsumerHandle consumer = GHOST_CreateEventConsumer(ghost_event_proc, C);
+ GHOST_EventConsumerHandle consumer;
+
+ if (C != NULL) {
+ consumer = GHOST_CreateEventConsumer(ghost_event_proc, C);
+ }
g_system = GHOST_CreateSystem();
- GHOST_AddEventConsumer(g_system, consumer);
+
+ if (C != NULL) {
+ GHOST_AddEventConsumer(g_system, consumer);
+ }
if (wm_init_state.native_pixels) {
GHOST_UseNativePixels();
@@ -1785,7 +1983,6 @@ void wm_window_raise(wmWindow *win)
void wm_window_swap_buffers(wmWindow *win)
{
-
#ifdef WIN32
glDisable(GL_SCISSOR_TEST);
GHOST_SwapWindowBuffers(win->ghostwin);
@@ -1883,19 +2080,37 @@ float WM_cursor_pressure(const struct wmWindow *win)
/* support for native pixel size */
/* mac retina opens window in size X, but it has up to 2 x more pixels */
-int WM_window_pixels_x(wmWindow *win)
+int WM_window_pixels_x(const wmWindow *win)
{
float f = GHOST_GetNativePixelSize(win->ghostwin);
return (int)(f * (float)win->sizex);
}
-
-int WM_window_pixels_y(wmWindow *win)
+int WM_window_pixels_y(const wmWindow *win)
{
float f = GHOST_GetNativePixelSize(win->ghostwin);
return (int)(f * (float)win->sizey);
-
+}
+
+/**
+ * Get the total pixels that are usable by the screen-layouts, excluding global areas.
+ */
+int WM_window_screen_pixels_x(const wmWindow *win)
+{
+ return WM_window_pixels_x(win);
+}
+int WM_window_screen_pixels_y(const wmWindow *win)
+{
+ short screen_size_y = WM_window_pixels_y(win);
+
+ for (ScrArea *sa = win->global_areas.areabase.first; sa; sa = sa->next) {
+ if ((sa->global->flag & GLOBAL_AREA_IS_HIDDEN) == 0) {
+ screen_size_y -= ED_area_global_size_y(sa);
+ }
+ }
+
+ return screen_size_y;
}
bool WM_window_is_fullscreen(wmWindow *win)
@@ -1903,6 +2118,115 @@ bool WM_window_is_fullscreen(wmWindow *win)
return win->windowstate == GHOST_kWindowStateFullScreen;
}
+/**
+ * Some editor data may need to be synced with scene data (3D View camera and layers).
+ * This function ensures data is synced for editors in visible workspaces and their visible layouts.
+ */
+void WM_windows_scene_data_sync(const ListBase *win_lb, Scene *scene)
+{
+ for (wmWindow *win = win_lb->first; win; win = win->next) {
+ if (WM_window_get_active_scene(win) == scene) {
+ ED_workspace_scene_data_sync(win->workspace_hook, scene);
+ }
+ }
+}
+
+Scene *WM_windows_scene_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
+{
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ if (WM_window_get_active_screen(win) == screen) {
+ return WM_window_get_active_scene(win);
+ }
+ }
+
+ return NULL;
+}
+
+WorkSpace *WM_windows_workspace_get_from_screen(const wmWindowManager *wm, const bScreen *screen)
+{
+ for (wmWindow *win = wm->windows.first; win; win = win->next) {
+ if (WM_window_get_active_screen(win) == screen) {
+ return WM_window_get_active_workspace(win);
+ }
+ }
+ return NULL;
+}
+
+Scene *WM_window_get_active_scene(const wmWindow *win)
+{
+ return win->scene;
+}
+
+/**
+ * \warning Only call outside of area/region loops
+ */
+void WM_window_change_active_scene(Main *bmain, bContext *C, wmWindow *win, Scene *scene_new)
+{
+ const bScreen *screen = WM_window_get_active_screen(win);
+ Scene *scene_old = win->scene;
+
+ ED_scene_change_update(bmain, C, win, screen, scene_old, scene_new);
+}
+
+WorkSpace *WM_window_get_active_workspace(const wmWindow *win)
+{
+ return BKE_workspace_active_get(win->workspace_hook);
+}
+void WM_window_set_active_workspace(wmWindow *win, WorkSpace *workspace)
+{
+ BKE_workspace_active_set(win->workspace_hook, workspace);
+}
+
+WorkSpaceLayout *WM_window_get_active_layout(const wmWindow *win)
+{
+ const WorkSpace *workspace = WM_window_get_active_workspace(win);
+ return (LIKELY(workspace != NULL) ? BKE_workspace_active_layout_get(win->workspace_hook) : NULL);
+}
+void WM_window_set_active_layout(wmWindow *win, WorkSpace *workspace, WorkSpaceLayout *layout)
+{
+ BKE_workspace_hook_layout_for_workspace_set(win->workspace_hook, workspace, layout);
+}
+
+/**
+ * Get the active screen of the active workspace in \a win.
+ */
+bScreen *WM_window_get_active_screen(const wmWindow *win)
+{
+ const WorkSpace *workspace = WM_window_get_active_workspace(win);
+ /* May be NULL in rare cases like closing Blender */
+ return (LIKELY(workspace != NULL) ? BKE_workspace_active_screen_get(win->workspace_hook) : NULL);
+}
+void WM_window_set_active_screen(wmWindow *win, WorkSpace *workspace, bScreen *screen)
+{
+ BKE_workspace_active_screen_set(win->workspace_hook, workspace, screen);
+}
+
+struct ViewLayer *WM_window_get_active_view_layer_ex(const wmWindow *win, Scene **r_scene)
+{
+ const WorkSpace *workspace = WM_window_get_active_workspace(win);
+ Scene *scene = WM_window_get_active_scene(win);
+ /* May be NULL in rare cases like closing Blender */
+ bScreen *screen = (LIKELY(workspace != NULL) ? BKE_workspace_active_screen_get(win->workspace_hook) : NULL);
+ if (screen != NULL) {
+ if (r_scene) {
+ *r_scene = scene;
+ }
+ return BKE_workspace_view_layer_get(workspace, scene);
+ }
+ return NULL;
+}
+
+struct ViewLayer *WM_window_get_active_view_layer(const wmWindow *win)
+{
+ return WM_window_get_active_view_layer_ex(win, NULL);
+}
+
+bool WM_window_is_temp_screen(const wmWindow *win)
+{
+ const bScreen *screen = WM_window_get_active_screen(win);
+ return (screen && screen->temp != 0);
+}
+
#ifdef WITH_INPUT_IME
/* note: keep in mind wm_window_IME_begin is also used to reposition the IME window */
@@ -1921,3 +2245,34 @@ void wm_window_IME_end(wmWindow *win)
win->ime_data = NULL;
}
#endif /* WITH_INPUT_IME */
+
+/* ****** direct opengl context management ****** */
+
+void *WM_opengl_context_create(void)
+{
+ /* On Windows there is a problem creating contexts that share lists
+ * from one context that is current in another thread.
+ * So we should call this function only on the main thread.
+ */
+ BLI_assert(BLI_thread_is_main());
+ BLI_assert(GPU_framebuffer_current_get() == 0);
+ return GHOST_CreateOpenGLContext(g_system);
+}
+
+void WM_opengl_context_dispose(void *context)
+{
+ BLI_assert(GPU_framebuffer_current_get() == 0);
+ GHOST_DisposeOpenGLContext(g_system, (GHOST_ContextHandle)context);
+}
+
+void WM_opengl_context_activate(void *context)
+{
+ BLI_assert(GPU_framebuffer_current_get() == 0);
+ GHOST_ActivateOpenGLContext((GHOST_ContextHandle)context);
+}
+
+void WM_opengl_context_release(void *context)
+{
+ BLI_assert(GPU_framebuffer_current_get() == 0);
+ GHOST_ReleaseOpenGLContext((GHOST_ContextHandle)context);
+}
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_api.h b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
new file mode 100644
index 00000000000..97fcb4513be
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_api.h
@@ -0,0 +1,336 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/WM_manipulator_api.h
+ * \ingroup wm
+ *
+ * \name Manipulator API
+ * \brief API for external use of wmManipulator types.
+ *
+ * Only included in WM_api.h
+ */
+
+
+#ifndef __WM_MANIPULATOR_API_H__
+#define __WM_MANIPULATOR_API_H__
+
+struct ARegion;
+struct GHashIterator;
+struct IDProperty;
+struct Main;
+struct PropertyRNA;
+struct wmKeyConfig;
+struct wmManipulator;
+struct wmManipulatorProperty;
+struct wmManipulatorPropertyType;
+struct wmManipulatorType;
+struct wmManipulatorGroup;
+struct wmManipulatorGroupType;
+struct wmManipulatorMap;
+struct wmManipulatorMapType;
+struct wmManipulatorMapType_Params;
+struct wmMsgSubscribeKey;
+struct wmMsgSubscribeValue;
+
+#include "wm_manipulator_fn.h"
+
+/* -------------------------------------------------------------------- */
+/* wmManipulator */
+
+struct wmManipulator *WM_manipulator_new_ptr(
+ const struct wmManipulatorType *wt, struct wmManipulatorGroup *mgroup,
+ struct PointerRNA *properties);
+struct wmManipulator *WM_manipulator_new(
+ const char *idname, struct wmManipulatorGroup *mgroup,
+ struct PointerRNA *properties);
+void WM_manipulator_free(struct wmManipulator *mpr);
+void WM_manipulator_unlink(
+ ListBase *manipulatorlist, struct wmManipulatorMap *mmap, struct wmManipulator *mpr,
+ struct bContext *C);
+
+void WM_manipulator_name_set(struct wmManipulatorGroup *mgroup, struct wmManipulator *mpr, const char *name);
+
+bool WM_manipulator_select_unlink(struct wmManipulatorMap *mmap, struct wmManipulator *mpr);
+bool WM_manipulator_select_set(struct wmManipulatorMap *mmap, struct wmManipulator *mpr, bool select);
+void WM_manipulator_highlight_set(struct wmManipulatorMap *mmap, struct wmManipulator *mpr);
+
+struct wmManipulatorOpElem *WM_manipulator_operator_get(
+ struct wmManipulator *mpr, int part_index);
+struct PointerRNA *WM_manipulator_operator_set(
+ struct wmManipulator *mpr, int part_index,
+ struct wmOperatorType *ot, struct IDProperty *properties);
+
+/* callbacks */
+void WM_manipulator_set_fn_custom_modal(struct wmManipulator *mpr, wmManipulatorFnModal fn);
+
+void WM_manipulator_set_matrix_location(
+ struct wmManipulator *mpr, const float origin[3]);
+void WM_manipulator_set_matrix_rotation_from_z_axis(
+ struct wmManipulator *mpr, const float z_axis[3]);
+void WM_manipulator_set_matrix_rotation_from_yz_axis(
+ struct wmManipulator *mpr, const float y_axis[3], const float z_axis[3]);
+
+void WM_manipulator_set_matrix_offset_location(
+ struct wmManipulator *mpr, const float origin[3]);
+void WM_manipulator_set_matrix_offset_rotation_from_z_axis(
+ struct wmManipulator *mpr, const float z_axis[3]);
+void WM_manipulator_set_matrix_offset_rotation_from_yz_axis(
+ struct wmManipulator *mpr, const float y_axis[3], const float z_axis[3]);
+
+void WM_manipulator_set_flag(struct wmManipulator *mpr, const int flag, const bool enable);
+void WM_manipulator_set_scale(struct wmManipulator *mpr, float scale);
+void WM_manipulator_set_line_width(struct wmManipulator *mpr, const float line_width);
+
+void WM_manipulator_get_color(const struct wmManipulator *mpr, float color[4]);
+void WM_manipulator_set_color(struct wmManipulator *mpr, const float color[4]);
+void WM_manipulator_get_color_highlight(const struct wmManipulator *mpr, float color_hi[4]);
+void WM_manipulator_set_color_highlight(struct wmManipulator *mpr, const float color[4]);
+
+/**
+ * Leaving values NULL use values from #wmManipulator.
+ */
+struct WM_ManipulatorMatrixParams {
+ const float(*matrix_space)[4];
+ const float(*matrix_basis)[4];
+ const float(*matrix_offset)[4];
+ const float *scale_final;
+};
+
+void WM_manipulator_calc_matrix_final_params(
+ const struct wmManipulator *mpr, const struct WM_ManipulatorMatrixParams *params,
+ float r_mat[4][4]);
+
+void WM_manipulator_calc_matrix_final(const struct wmManipulator *mpr, float r_mat[4][4]);
+
+/* properties */
+void WM_manipulator_properties_create_ptr(struct PointerRNA *ptr, struct wmManipulatorType *wt);
+void WM_manipulator_properties_create(struct PointerRNA *ptr, const char *opstring);
+void WM_manipulator_properties_alloc(struct PointerRNA **ptr, struct IDProperty **properties, const char *wtstring);
+void WM_manipulator_properties_sanitize(struct PointerRNA *ptr, const bool no_context);
+bool WM_manipulator_properties_default(struct PointerRNA *ptr, const bool do_update);
+void WM_manipulator_properties_reset(struct wmManipulator *op);
+void WM_manipulator_properties_clear(struct PointerRNA *ptr);
+void WM_manipulator_properties_free(struct PointerRNA *ptr);
+
+
+/* wm_manipulator_type.c */
+const struct wmManipulatorType *WM_manipulatortype_find(const char *idname, bool quiet);
+void WM_manipulatortype_append(void (*wtfunc)(struct wmManipulatorType *));
+void WM_manipulatortype_append_ptr(void (*mnpfunc)(struct wmManipulatorType *, void *), void *userdata);
+bool WM_manipulatortype_remove(struct bContext *C, struct Main *bmain, const char *idname);
+void WM_manipulatortype_remove_ptr(struct bContext *C, struct Main *bmain, struct wmManipulatorType *wt);
+void WM_manipulatortype_iter(struct GHashIterator *ghi);
+
+/* wm_manipulator_group_type.c */
+struct wmManipulatorGroupType *WM_manipulatorgrouptype_find(const char *idname, bool quiet);
+struct wmManipulatorGroupType *WM_manipulatorgrouptype_append(void (*wtfunc)(struct wmManipulatorGroupType *));
+struct wmManipulatorGroupType *WM_manipulatorgrouptype_append_ptr(void (*mnpfunc)(struct wmManipulatorGroupType *, void *), void *userdata);
+bool WM_manipulatorgrouptype_free(const char *idname);
+void WM_manipulatorgrouptype_free_ptr(struct wmManipulatorGroupType *wt);
+void WM_manipulatorgrouptype_iter(struct GHashIterator *ghi);
+
+struct wmManipulatorGroupTypeRef *WM_manipulatorgrouptype_append_and_link(
+ struct wmManipulatorMapType *mmap_type,
+ void (*wtfunc)(struct wmManipulatorGroupType *));
+
+/* wm_manipulator_map.c */
+
+/* Dynamic Updates (for RNA runtime registration) */
+void WM_manipulatorconfig_update_tag_init(struct wmManipulatorMapType *mmap_type, struct wmManipulatorGroupType *wgt);
+void WM_manipulatorconfig_update_tag_remove(struct wmManipulatorMapType *mmap_type, struct wmManipulatorGroupType *wgt);
+void WM_manipulatorconfig_update(struct Main *bmain);
+
+
+/* wm_maniulator_target_props.c */
+struct wmManipulatorProperty *WM_manipulator_target_property_array(struct wmManipulator *mpr);
+struct wmManipulatorProperty *WM_manipulator_target_property_at_index(
+ struct wmManipulator *mpr, int index);
+struct wmManipulatorProperty *WM_manipulator_target_property_find(
+ struct wmManipulator *mpr, const char *idname);
+
+void WM_manipulator_target_property_def_rna_ptr(
+ struct wmManipulator *mpr, const struct wmManipulatorPropertyType *mpr_prop_type,
+ struct PointerRNA *ptr, struct PropertyRNA *prop, int index);
+void WM_manipulator_target_property_def_rna(
+ struct wmManipulator *mpr, const char *idname,
+ struct PointerRNA *ptr, const char *propname, int index);
+
+void WM_manipulator_target_property_def_func_ptr(
+ struct wmManipulator *mpr, const struct wmManipulatorPropertyType *mpr_prop_type,
+ const struct wmManipulatorPropertyFnParams *params);
+void WM_manipulator_target_property_def_func(
+ struct wmManipulator *mpr, const char *idname,
+ const struct wmManipulatorPropertyFnParams *params);
+
+void WM_manipulator_target_property_clear_rna_ptr(
+ struct wmManipulator *mpr, const struct wmManipulatorPropertyType *mpr_prop_type);
+void WM_manipulator_target_property_clear_rna(
+ struct wmManipulator *mpr, const char *idname);
+
+bool WM_manipulator_target_property_is_valid_any(struct wmManipulator *mpr);
+bool WM_manipulator_target_property_is_valid(
+ const struct wmManipulatorProperty *mpr_prop);
+float WM_manipulator_target_property_value_get(
+ const struct wmManipulator *mpr, struct wmManipulatorProperty *mpr_prop);
+void WM_manipulator_target_property_value_set(
+ struct bContext *C, const struct wmManipulator *mpr, struct wmManipulatorProperty *mpr_prop,
+ const float value);
+
+void WM_manipulator_target_property_value_get_array(
+ const struct wmManipulator *mpr, struct wmManipulatorProperty *mpr_prop,
+ float *value);
+void WM_manipulator_target_property_value_set_array(
+ struct bContext *C, const struct wmManipulator *mpr, struct wmManipulatorProperty *mpr_prop,
+ const float *value);
+
+bool WM_manipulator_target_property_range_get(
+ const struct wmManipulator *mpr, struct wmManipulatorProperty *mpr_prop,
+ float range[2]);
+
+int WM_manipulator_target_property_array_length(
+ const struct wmManipulator *mpr, struct wmManipulatorProperty *mpr_prop);
+
+/* definitions */
+const struct wmManipulatorPropertyType *WM_manipulatortype_target_property_find(
+ const struct wmManipulatorType *wt, const char *idname);
+void WM_manipulatortype_target_property_def(
+ struct wmManipulatorType *wt, const char *idname, int data_type, int array_length);
+
+/* utilities */
+void WM_manipulator_do_msg_notify_tag_refresh(
+ struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val);
+void WM_manipulator_target_property_subscribe_all(
+ struct wmManipulator *mpr, struct wmMsgBus *mbus, struct ARegion *ar);
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorGroup */
+
+/* Callbacks for 'wmManipulatorGroupType.setup_keymap' */
+struct wmKeyMap *WM_manipulatorgroup_keymap_common(
+ const struct wmManipulatorGroupType *wgt, struct wmKeyConfig *config);
+struct wmKeyMap *WM_manipulatorgroup_keymap_common_select(
+ const struct wmManipulatorGroupType *wgt, struct wmKeyConfig *config);
+
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorMap */
+
+struct wmManipulatorMap *WM_manipulatormap_new_from_type(
+ const struct wmManipulatorMapType_Params *mmap_params);
+const struct ListBase *WM_manipulatormap_group_list(struct wmManipulatorMap *mmap);
+struct wmManipulatorGroup *WM_manipulatormap_group_find(
+ struct wmManipulatorMap *mmap,
+ const char *idname);
+struct wmManipulatorGroup *WM_manipulatormap_group_find_ptr(
+ struct wmManipulatorMap *mmap,
+ const struct wmManipulatorGroupType *wgt);
+void WM_manipulatormap_tag_refresh(struct wmManipulatorMap *mmap);
+void WM_manipulatormap_draw(
+ struct wmManipulatorMap *mmap, const struct bContext *C, const eWM_ManipulatorMapDrawStep drawstep);
+void WM_manipulatormap_add_handlers(struct ARegion *ar, struct wmManipulatorMap *mmap);
+bool WM_manipulatormap_select_all(struct bContext *C, struct wmManipulatorMap *mmap, const int action);
+bool WM_manipulatormap_cursor_set(const struct wmManipulatorMap *mmap, struct wmWindow *win);
+void WM_manipulatormap_message_subscribe(
+ struct bContext *C, struct wmManipulatorMap *mmap, struct ARegion *ar, struct wmMsgBus *mbus);
+bool WM_manipulatormap_is_any_selected(const struct wmManipulatorMap *mmap);
+bool WM_manipulatormap_minmax(
+ const struct wmManipulatorMap *mmap, bool use_hidden, bool use_select,
+ float r_min[3], float r_max[3]);
+
+struct ARegion *WM_manipulatormap_tooltip_init(
+ struct bContext *C, struct ARegion *ar, bool *r_exit_on_event);
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorMapType */
+
+struct wmManipulatorMapType *WM_manipulatormaptype_find(
+ const struct wmManipulatorMapType_Params *mmap_params);
+struct wmManipulatorMapType *WM_manipulatormaptype_ensure(
+ const struct wmManipulatorMapType_Params *mmap_params);
+
+struct wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_find(
+ struct wmManipulatorMapType *mmap_type,
+ const char *idname);
+struct wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_find_ptr(
+ struct wmManipulatorMapType *mmap_type,
+ const struct wmManipulatorGroupType *wgt);
+struct wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_link(
+ struct wmManipulatorMapType *mmap_type,
+ const char *idname);
+struct wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_link_ptr(
+ struct wmManipulatorMapType *mmap_type,
+ struct wmManipulatorGroupType *wgt);
+
+void WM_manipulatormaptype_group_init_runtime_keymap(
+ const struct Main *bmain,
+ struct wmManipulatorGroupType *wgt);
+void WM_manipulatormaptype_group_init_runtime(
+ const struct Main *bmain, struct wmManipulatorMapType *mmap_type,
+ struct wmManipulatorGroupType *wgt);
+void WM_manipulatormaptype_group_unlink(
+ struct bContext *C, struct Main *bmain, struct wmManipulatorMapType *mmap_type,
+ const struct wmManipulatorGroupType *wgt);
+
+void WM_manipulatormaptype_group_free(struct wmManipulatorGroupTypeRef *wgt);
+
+/* -------------------------------------------------------------------- */
+/* ManipulatorGroup */
+
+/* Add/Ensure/Remove (High level API) */
+
+void WM_manipulator_group_type_add_ptr_ex(
+ struct wmManipulatorGroupType *wgt,
+ struct wmManipulatorMapType *mmap_type);
+void WM_manipulator_group_type_add_ptr(
+ struct wmManipulatorGroupType *wgt);
+void WM_manipulator_group_type_add(const char *idname);
+
+void WM_manipulator_group_type_ensure_ptr_ex(
+ struct wmManipulatorGroupType *wgt,
+ struct wmManipulatorMapType *mmap_type);
+void WM_manipulator_group_type_ensure_ptr(
+ struct wmManipulatorGroupType *wgt);
+void WM_manipulator_group_type_ensure(const char *idname);
+
+void WM_manipulator_group_type_remove_ptr_ex(
+ struct Main *bmain, struct wmManipulatorGroupType *wgt,
+ struct wmManipulatorMapType *mmap_type);
+void WM_manipulator_group_type_remove_ptr(
+ struct Main *bmain, struct wmManipulatorGroupType *wgt);
+void WM_manipulator_group_type_remove(struct Main *bmain, const char *idname);
+
+void WM_manipulator_group_type_unlink_delayed_ptr_ex(
+ struct wmManipulatorGroupType *wgt,
+ struct wmManipulatorMapType *mmap_type);
+void WM_manipulator_group_type_unlink_delayed_ptr(
+ struct wmManipulatorGroupType *wgt);
+void WM_manipulator_group_type_unlink_delayed(const char *idname);
+
+/* Utilities */
+bool WM_manipulator_context_check_drawstep(const struct bContext *C, eWM_ManipulatorMapDrawStep step);
+
+bool WM_manipulator_group_type_poll(const struct bContext *C, const struct wmManipulatorGroupType *wgt);
+
+#endif /* __WM_MANIPULATOR_API_H__ */
diff --git a/source/blender/windowmanager/manipulators/WM_manipulator_types.h b/source/blender/windowmanager/manipulators/WM_manipulator_types.h
new file mode 100644
index 00000000000..e4482e797e3
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/WM_manipulator_types.h
@@ -0,0 +1,420 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/WM_manipulator_types.h
+ * \ingroup wm
+ *
+ * \name Manipulator Types
+ * \brief Manipulator defines for external use.
+ *
+ * Only included in WM_types.h and lower level files.
+ */
+
+
+#ifndef __WM_MANIPULATOR_TYPES_H__
+#define __WM_MANIPULATOR_TYPES_H__
+
+#include "BLI_compiler_attrs.h"
+
+struct wmManipulatorMapType;
+struct wmManipulatorGroupType;
+struct wmManipulatorGroup;
+struct wmManipulator;
+struct wmManipulatorProperty;
+struct wmKeyConfig;
+
+#include "DNA_listBase.h"
+
+
+/* -------------------------------------------------------------------- */
+/* Enum Typedef's */
+
+
+/**
+ * #wmManipulator.state
+ */
+typedef enum eWM_ManipulatorState {
+ WM_MANIPULATOR_STATE_HIGHLIGHT = (1 << 0), /* while hovered */
+ WM_MANIPULATOR_STATE_MODAL = (1 << 1), /* while dragging */
+ WM_MANIPULATOR_STATE_SELECT = (1 << 2),
+} eWM_ManipulatorState;
+
+
+/**
+ * #wmManipulator.flag
+ * Flags for individual manipulators.
+ */
+typedef enum eWM_ManipulatorFlag {
+ WM_MANIPULATOR_DRAW_HOVER = (1 << 0), /* draw *only* while hovering */
+ WM_MANIPULATOR_DRAW_MODAL = (1 << 1), /* draw while dragging */
+ WM_MANIPULATOR_DRAW_VALUE = (1 << 2), /* draw an indicator for the current value while dragging */
+ WM_MANIPULATOR_HIDDEN = (1 << 3),
+ /**
+ * When set 'scale_final' value also scales the offset.
+ * Use when offset is to avoid screen-space overlap instead of absolute positioning. */
+ WM_MANIPULATOR_DRAW_OFFSET_SCALE = (1 << 4),
+ /**
+ * User should still use 'scale_final' for any handles and UI elements.
+ * This simply skips scale when calculating the final matrix.
+ * Needed when the manipulator needs to align with the interface underneath it. */
+ WM_MANIPULATOR_DRAW_NO_SCALE = (1 << 5),
+ /**
+ * Hide the cursor and lock it's position while interacting with this manipulator.
+ */
+ WM_MANIPULATOR_GRAB_CURSOR = (1 << 6),
+} eWM_ManipulatorFlag;
+
+/**
+ * #wmManipulatorGroupType.flag
+ * Flags that influence the behavior of all manipulators in the group.
+ */
+typedef enum eWM_ManipulatorGroupTypeFlag {
+ /* Mark manipulator-group as being 3D */
+ WM_MANIPULATORGROUPTYPE_3D = (1 << 0),
+ /* Scale manipulators as 3D object that respects zoom (otherwise zoom independent draw size).
+ * note: currently only for 3D views, 2D support needs adding. */
+ WM_MANIPULATORGROUPTYPE_SCALE = (1 << 1),
+ /* Manipulators can be depth culled with scene objects (covered by other geometry - TODO) */
+ WM_MANIPULATORGROUPTYPE_DEPTH_3D = (1 << 2),
+ /* Manipulators can be selected */
+ WM_MANIPULATORGROUPTYPE_SELECT = (1 << 3),
+ /* The manipulator group is to be kept (not removed on loading a new file for eg). */
+ WM_MANIPULATORGROUPTYPE_PERSISTENT = (1 << 4),
+ /* Show all other manipulators when interacting. */
+ WM_MANIPULATORGROUPTYPE_DRAW_MODAL_ALL = (1 << 5),
+} eWM_ManipulatorGroupTypeFlag;
+
+
+/**
+ * #wmManipulatorGroup.init_flag
+ */
+typedef enum eWM_ManipulatorGroupInitFlag {
+ /* mgroup has been initialized */
+ WM_MANIPULATORGROUP_INIT_SETUP = (1 << 0),
+ WM_MANIPULATORGROUP_INIT_REFRESH = (1 << 1),
+} eWM_ManipulatorGroupInitFlag;
+
+/**
+ * #wmManipulatorMapType.type_update_flag
+ * Manipulator-map type update flag
+ */
+typedef enum eWM_ManipulatorMapTypeUpdateFlag {
+ /* A new type has been added, needs to be initialized for all views. */
+ WM_MANIPULATORMAPTYPE_UPDATE_INIT = (1 << 0),
+ WM_MANIPULATORMAPTYPE_UPDATE_REMOVE = (1 << 1),
+
+ /* Needed because keymap may be registered before and after window initialization.
+ * So we need to keep track of keymap initialization separately. */
+ WM_MANIPULATORMAPTYPE_KEYMAP_INIT = (1 << 2),
+} eWM_ManipulatorMapTypeUpdateFlag;
+
+/* -------------------------------------------------------------------- */
+/* wmManipulator */
+
+/**
+ * \brief Manipulator tweak flag.
+ * Bitflag passed to manipulator while tweaking.
+ *
+ * \note Manipulators are responsible for handling this #wmManipulator.modal callback!.
+ */
+typedef enum {
+ /* Drag with extra precision (Shift). */
+ WM_MANIPULATOR_TWEAK_PRECISE = (1 << 0),
+ /* Drag with snap enabled (Ctrl). */
+ WM_MANIPULATOR_TWEAK_SNAP = (1 << 1),
+} eWM_ManipulatorTweak;
+
+#include "wm_manipulator_fn.h"
+
+typedef struct wmManipulatorOpElem {
+ struct wmOperatorType *type;
+ /* operator properties if manipulator spawns and controls an operator,
+ * or owner pointer if manipulator spawns and controls a property */
+ PointerRNA ptr;
+
+ bool is_redo;
+} wmManipulatorOpElem;
+
+/* manipulators are set per region by registering them on manipulator-maps */
+struct wmManipulator {
+ struct wmManipulator *next, *prev;
+
+ /* While we don't have a real type, use this to put type-like vars. */
+ const struct wmManipulatorType *type;
+
+ /* Overrides 'type->modal' when set.
+ * Note that this is a workaround, remove if we can. */
+ wmManipulatorFnModal custom_modal;
+
+ /* pointer back to group this manipulator is in (just for quick access) */
+ struct wmManipulatorGroup *parent_mgroup;
+
+ void *py_instance;
+
+ /* rna pointer to access properties */
+ struct PointerRNA *ptr;
+
+ /* flags that influence the behavior or how the manipulators are drawn */
+ eWM_ManipulatorFlag flag;
+ /* state flags (active, highlighted, selected) */
+ eWM_ManipulatorState state;
+
+ /* Optional ID for highlighting different parts of this manipulator.
+ * -1 when unset, otherwise a valid index. (Used as index to 'op_data'). */
+ int highlight_part;
+ /* For single click button manipulators, use a different part as a fallback, -1 when unused. */
+ int drag_part;
+
+ /* Transformation of the manipulator in 2d or 3d space.
+ * - Matrix axis are expected to be unit length (scale is applied after).
+ * - Behavior when axis aren't orthogonal depends on each manipulator.
+ * - Typically the +Z is the primary axis for manipulators to use.
+ * - 'matrix[3]' must be used for location,
+ * besides this it's up to the manipulators internal code how the
+ * rotation components are used for drawing and interaction.
+ */
+
+ /* The space this manipulator is being modified in. */
+ float matrix_space[4][4];
+ /* Transformation of this manipulator. */
+ float matrix_basis[4][4];
+ /* custom offset from origin */
+ float matrix_offset[4][4];
+ /* runtime property, set the scale while drawing on the viewport */
+ float scale_final;
+ /* user defined scale, in addition to the original one */
+ float scale_basis;
+ /* user defined width for line drawing */
+ float line_width;
+ /* manipulator colors (uses default fallbacks if not defined) */
+ float color[4], color_hi[4];
+
+ /* data used during interaction */
+ void *interaction_data;
+
+ /* Operator to spawn when activating the manipulator (overrides property editing),
+ * an array of items (aligned with #wmManipulator.highlight_part). */
+ wmManipulatorOpElem *op_data;
+ int op_data_len;
+
+ struct IDProperty *properties;
+
+ /* over alloc target_properties after 'wmManipulatorType.struct_size' */
+};
+
+/* Similar to PropertyElemRNA, but has an identifier. */
+typedef struct wmManipulatorProperty {
+ const struct wmManipulatorPropertyType *type;
+
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ int index;
+
+
+ /* Optional functions for converting to/from RNA */
+ struct {
+ wmManipulatorPropertyFnGet value_get_fn;
+ wmManipulatorPropertyFnSet value_set_fn;
+ wmManipulatorPropertyFnRangeGet range_get_fn;
+ wmManipulatorPropertyFnFree free_fn;
+ void *user_data;
+ } custom_func;
+} wmManipulatorProperty;
+
+typedef struct wmManipulatorPropertyType {
+ struct wmManipulatorPropertyType *next, *prev;
+ /* PropertyType, typically 'PROP_FLOAT' */
+ int data_type;
+ int array_length;
+
+ /* index within 'wmManipulatorType' */
+ int index_in_type;
+
+ /* over alloc */
+ char idname[0];
+} wmManipulatorPropertyType;
+
+
+/**
+ * Simple utility wrapper for storing a single manipulator as wmManipulatorGroup.customdata (which gets freed).
+ */
+typedef struct wmManipulatorWrapper {
+ struct wmManipulator *manipulator;
+} wmManipulatorWrapper;
+
+struct wmManipulatorMapType_Params {
+ short spaceid;
+ short regionid;
+};
+
+typedef struct wmManipulatorType {
+
+ const char *idname; /* MAX_NAME */
+
+ /* Set to 'sizeof(wmManipulator)' or larger for instances of this type,
+ * use so we can cant to other types without the hassle of a custom-data pointer. */
+ uint struct_size;
+
+ /* Initialize struct (calloc'd 'struct_size' region). */
+ wmManipulatorFnSetup setup;
+
+ /* draw manipulator */
+ wmManipulatorFnDraw draw;
+
+ /* determines 3d intersection by rendering the manipulator in a selection routine. */
+ wmManipulatorFnDrawSelect draw_select;
+
+ /* Determine if the mouse intersects with the manipulator.
+ * The calculation should be done in the callback itself, -1 for no seleciton. */
+ wmManipulatorFnTestSelect test_select;
+
+ /* handler used by the manipulator. Usually handles interaction tied to a manipulator type */
+ wmManipulatorFnModal modal;
+
+ /* manipulator-specific handler to update manipulator attributes based on the property value */
+ wmManipulatorFnPropertyUpdate property_update;
+
+ /* Returns the final transformation which may be different from the 'matrix',
+ * depending on the manipulator.
+ * Notes:
+ * - Scale isn't applied (wmManipulator.scale/user_scale).
+ * - Offset isn't applied (wmManipulator.matrix_offset).
+ */
+ wmManipulatorFnMatrixBasisGet matrix_basis_get;
+
+ /* activate a manipulator state when the user clicks on it */
+ wmManipulatorFnInvoke invoke;
+
+ /* called when manipulator tweaking is done - used to free data and reset property when cancelling */
+ wmManipulatorFnExit exit;
+
+ wmManipulatorFnCursorGet cursor_get;
+
+ /* called when manipulator selection state changes */
+ wmManipulatorFnSelectRefresh select_refresh;
+
+ /* Free data (not the manipulator it's self), use when the manipulator allocates it's own members. */
+ wmManipulatorFnFree free;
+
+ /* RNA for properties */
+ struct StructRNA *srna;
+
+ /* RNA integration */
+ ExtensionRNA ext;
+
+ ListBase target_property_defs;
+ int target_property_defs_len;
+
+} wmManipulatorType;
+
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorGroup */
+
+/* factory class for a manipulator-group type, gets called every time a new area is spawned */
+typedef struct wmManipulatorGroupTypeRef {
+ struct wmManipulatorGroupTypeRef *next, *prev;
+ struct wmManipulatorGroupType *type;
+} wmManipulatorGroupTypeRef;
+
+/* factory class for a manipulator-group type, gets called every time a new area is spawned */
+typedef struct wmManipulatorGroupType {
+ const char *idname; /* MAX_NAME */
+ const char *name; /* manipulator-group name - displayed in UI (keymap editor) */
+ char owner_id[64]; /* MAX_NAME */
+
+ /* poll if manipulator-map should be visible */
+ wmManipulatorGroupFnPoll poll;
+ /* initially create manipulators and set permanent data - stuff you only need to do once */
+ wmManipulatorGroupFnInit setup;
+ /* refresh data, only called if recreate flag is set (WM_manipulatormap_tag_refresh) */
+ wmManipulatorGroupFnRefresh refresh;
+ /* refresh data for drawing, called before each redraw */
+ wmManipulatorGroupFnDrawPrepare draw_prepare;
+
+ /* Keymap init callback for this manipulator-group (optional),
+ * will fall back to default tweak keymap when left NULL. */
+ wmManipulatorGroupFnSetupKeymap setup_keymap;
+
+ /* Optionally subscribe to wmMsgBus events,
+ * these are calculated automatically from RNA properties,
+ * only needed if manipulators depend indirectly on properties. */
+ wmManipulatorGroupFnMsgBusSubscribe message_subscribe;
+
+ /* keymap created with callback from above */
+ struct wmKeyMap *keymap;
+ /* Only for convenient removal. */
+ struct wmKeyConfig *keyconf;
+
+ /* Disable for now, maybe some day we want properties. */
+#if 0
+ /* rna for properties */
+ struct StructRNA *srna;
+#endif
+
+ /* RNA integration */
+ ExtensionRNA ext;
+
+ eWM_ManipulatorGroupTypeFlag flag;
+
+ /* So we know which group type to update. */
+ eWM_ManipulatorMapTypeUpdateFlag type_update_flag;
+
+ /* same as manipulator-maps, so registering/unregistering goes to the correct region */
+ struct wmManipulatorMapType_Params mmap_params;
+
+} wmManipulatorGroupType;
+
+typedef struct wmManipulatorGroup {
+ struct wmManipulatorGroup *next, *prev;
+
+ struct wmManipulatorGroupType *type;
+ ListBase manipulators;
+
+ struct wmManipulatorMap *parent_mmap;
+
+ void *py_instance; /* python stores the class instance here */
+ struct ReportList *reports; /* errors and warnings storage */
+
+ void *customdata;
+ void (*customdata_free)(void *); /* for freeing customdata from above */
+ eWM_ManipulatorGroupInitFlag init_flag;
+} wmManipulatorGroup;
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorMap */
+
+/**
+ * Pass a value of this enum to #WM_manipulatormap_draw to tell it what to draw.
+ */
+typedef enum eWM_ManipulatorMapDrawStep {
+ /** Draw 2D manipulator-groups (#WM_MANIPULATORGROUPTYPE_3D not set). */
+ WM_MANIPULATORMAP_DRAWSTEP_2D = 0,
+ /** Draw 3D manipulator-groups (#WM_MANIPULATORGROUPTYPE_3D set). */
+ WM_MANIPULATORMAP_DRAWSTEP_3D,
+} eWM_ManipulatorMapDrawStep;
+#define WM_MANIPULATORMAP_DRAWSTEP_MAX 2
+
+#endif /* __WM_MANIPULATOR_TYPES_H__ */
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
new file mode 100644
index 00000000000..856b92096dd
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator.c
@@ -0,0 +1,764 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator.c
+ * \ingroup wm
+ */
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_context.h"
+
+#include "GPU_batch.h"
+#include "GPU_glew.h"
+#include "GPU_immediate.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "BKE_global.h"
+#include "BKE_main.h"
+#include "BKE_idprop.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "UI_interface.h"
+
+#ifdef WITH_PYTHON
+#include "BPY_extern.h"
+#endif
+
+/* only for own init/exit calls (wm_manipulatortype_init/wm_manipulatortype_free) */
+#include "wm.h"
+
+/* own includes */
+#include "wm_manipulator_wmapi.h"
+#include "wm_manipulator_intern.h"
+
+static void wm_manipulator_register(
+ wmManipulatorGroup *mgroup, wmManipulator *mpr);
+
+/**
+ * \note Follow #wm_operator_create convention.
+ */
+static wmManipulator *wm_manipulator_create(
+ const wmManipulatorType *wt,
+ PointerRNA *properties)
+{
+ BLI_assert(wt != NULL);
+ BLI_assert(wt->struct_size >= sizeof(wmManipulator));
+
+ wmManipulator *mpr = MEM_callocN(
+ wt->struct_size + (sizeof(wmManipulatorProperty) * wt->target_property_defs_len), __func__);
+ mpr->type = wt;
+
+ /* initialize properties, either copy or create */
+ mpr->ptr = MEM_callocN(sizeof(PointerRNA), "wmManipulatorPtrRNA");
+ if (properties && properties->data) {
+ mpr->properties = IDP_CopyProperty(properties->data);
+ }
+ else {
+ IDPropertyTemplate val = {0};
+ mpr->properties = IDP_New(IDP_GROUP, &val, "wmManipulatorProperties");
+ }
+ RNA_pointer_create(G.main->wm.first, wt->srna, mpr->properties, mpr->ptr);
+
+ WM_manipulator_properties_sanitize(mpr->ptr, 0);
+
+ unit_m4(mpr->matrix_space);
+ unit_m4(mpr->matrix_basis);
+ unit_m4(mpr->matrix_offset);
+
+ mpr->drag_part = -1;
+
+ return mpr;
+}
+
+wmManipulator *WM_manipulator_new_ptr(
+ const wmManipulatorType *wt, wmManipulatorGroup *mgroup,
+ PointerRNA *properties)
+{
+ wmManipulator *mpr = wm_manipulator_create(wt, properties);
+
+ wm_manipulator_register(mgroup, mpr);
+
+ if (mpr->type->setup != NULL) {
+ mpr->type->setup(mpr);
+ }
+
+ return mpr;
+}
+
+/**
+ * \param wt: Must be valid,
+ * if you need to check it exists use #WM_manipulator_new_ptr
+ * because callers of this function don't NULL check the return value.
+ */
+wmManipulator *WM_manipulator_new(
+ const char *idname, wmManipulatorGroup *mgroup,
+ PointerRNA *properties)
+{
+ const wmManipulatorType *wt = WM_manipulatortype_find(idname, false);
+ return WM_manipulator_new_ptr(wt, mgroup, properties);
+}
+
+/**
+ * Initialize default values and allocate needed memory for members.
+ */
+static void manipulator_init(wmManipulator *mpr)
+{
+ const float color_default[4] = {1.0f, 1.0f, 1.0f, 1.0f};
+
+ mpr->scale_basis = 1.0f;
+ mpr->line_width = 1.0f;
+
+ /* defaults */
+ copy_v4_v4(mpr->color, color_default);
+ copy_v4_v4(mpr->color_hi, color_default);
+}
+
+/**
+ * Register \a manipulator.
+ *
+ * \param name: name used to create a unique idname for \a manipulator in \a mgroup
+ *
+ * \note Not to be confused with type registration from RNA.
+ */
+static void wm_manipulator_register(wmManipulatorGroup *mgroup, wmManipulator *mpr)
+{
+ manipulator_init(mpr);
+ wm_manipulatorgroup_manipulator_register(mgroup, mpr);
+}
+
+/**
+ * \warning this doesn't check #wmManipulatorMap (highlight, selection etc).
+ * Typical use is when freeing the windowing data,
+ * where caller can manage clearing selection, highlight... etc.
+ */
+void WM_manipulator_free(wmManipulator *mpr)
+{
+ if (mpr->type->free != NULL) {
+ mpr->type->free(mpr);
+ }
+
+#ifdef WITH_PYTHON
+ if (mpr->py_instance) {
+ /* do this first in case there are any __del__ functions or
+ * similar that use properties */
+ BPY_DECREF_RNA_INVALIDATE(mpr->py_instance);
+ }
+#endif
+
+ if (mpr->op_data) {
+ for (int i = 0; i < mpr->op_data_len; i++) {
+ WM_operator_properties_free(&mpr->op_data[i].ptr);
+ }
+ MEM_freeN(mpr->op_data);
+ }
+
+ if (mpr->ptr != NULL) {
+ WM_manipulator_properties_free(mpr->ptr);
+ MEM_freeN(mpr->ptr);
+ }
+
+ if (mpr->type->target_property_defs_len != 0) {
+ wmManipulatorProperty *mpr_prop_array = WM_manipulator_target_property_array(mpr);
+ for (int i = 0; i < mpr->type->target_property_defs_len; i++) {
+ wmManipulatorProperty *mpr_prop = &mpr_prop_array[i];
+ if (mpr_prop->custom_func.free_fn) {
+ mpr_prop->custom_func.free_fn(mpr, mpr_prop);
+ }
+ }
+ }
+
+ MEM_freeN(mpr);
+}
+
+/**
+ * Free \a manipulator and unlink from \a manipulatorlist.
+ * \a manipulatorlist is allowed to be NULL.
+ */
+void WM_manipulator_unlink(ListBase *manipulatorlist, wmManipulatorMap *mmap, wmManipulator *mpr, bContext *C)
+{
+ if (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) {
+ wm_manipulatormap_highlight_set(mmap, C, NULL, 0);
+ }
+ if (mpr->state & WM_MANIPULATOR_STATE_MODAL) {
+ wm_manipulatormap_modal_set(mmap, C, mpr, NULL, false);
+ }
+ /* Unlink instead of setting so we don't run callbacks. */
+ if (mpr->state & WM_MANIPULATOR_STATE_SELECT) {
+ WM_manipulator_select_unlink(mmap, mpr);
+ }
+
+ if (manipulatorlist) {
+ BLI_remlink(manipulatorlist, mpr);
+ }
+
+ BLI_assert(mmap->mmap_context.highlight != mpr);
+ BLI_assert(mmap->mmap_context.modal != mpr);
+
+ WM_manipulator_free(mpr);
+}
+
+/* -------------------------------------------------------------------- */
+/** \name Manipulator Creation API
+ *
+ * API for defining data on manipulator creation.
+ *
+ * \{ */
+
+struct wmManipulatorOpElem *WM_manipulator_operator_get(
+ wmManipulator *mpr, int part_index)
+{
+ if (mpr->op_data && ((part_index >= 0) && (part_index < mpr->op_data_len))) {
+ return &mpr->op_data[part_index];
+ }
+ return NULL;
+}
+
+PointerRNA *WM_manipulator_operator_set(
+ wmManipulator *mpr, int part_index,
+ wmOperatorType *ot, IDProperty *properties)
+{
+ BLI_assert(part_index < 255);
+ /* We could pre-allocate these but using multiple is such a rare thing. */
+ if (part_index >= mpr->op_data_len) {
+ mpr->op_data_len = part_index + 1;
+ mpr->op_data = MEM_recallocN(mpr->op_data, sizeof(*mpr->op_data) * mpr->op_data_len);
+ }
+ wmManipulatorOpElem *mpop = &mpr->op_data[part_index];
+ mpop->type = ot;
+
+ if (mpop->ptr.data) {
+ WM_operator_properties_free(&mpop->ptr);
+ }
+ WM_operator_properties_create_ptr(&mpop->ptr, ot);
+
+ if (properties) {
+ mpop->ptr.data = properties;
+ }
+
+ return &mpop->ptr;
+}
+
+static void wm_manipulator_set_matrix_rotation_from_z_axis__internal(
+ float matrix[4][4], const float z_axis[3])
+{
+ /* old code, seems we can use simpler method */
+#if 0
+ const float z_global[3] = {0.0f, 0.0f, 1.0f};
+ float rot[3][3];
+
+ rotation_between_vecs_to_mat3(rot, z_global, z_axis);
+ copy_v3_v3(matrix[0], rot[0]);
+ copy_v3_v3(matrix[1], rot[1]);
+ copy_v3_v3(matrix[2], rot[2]);
+#else
+ normalize_v3_v3(matrix[2], z_axis);
+ ortho_basis_v3v3_v3(matrix[0], matrix[1], matrix[2]);
+#endif
+
+}
+
+static void wm_manipulator_set_matrix_rotation_from_yz_axis__internal(
+ float matrix[4][4], const float y_axis[3], const float z_axis[3])
+{
+ normalize_v3_v3(matrix[1], y_axis);
+ normalize_v3_v3(matrix[2], z_axis);
+ cross_v3_v3v3(matrix[0], matrix[1], matrix[2]);
+ normalize_v3(matrix[0]);
+}
+
+/**
+ * wmManipulator.matrix utils.
+ */
+void WM_manipulator_set_matrix_rotation_from_z_axis(
+ wmManipulator *mpr, const float z_axis[3])
+{
+ wm_manipulator_set_matrix_rotation_from_z_axis__internal(mpr->matrix_basis, z_axis);
+}
+void WM_manipulator_set_matrix_rotation_from_yz_axis(
+ wmManipulator *mpr, const float y_axis[3], const float z_axis[3])
+{
+ wm_manipulator_set_matrix_rotation_from_yz_axis__internal(mpr->matrix_basis, y_axis, z_axis);
+}
+void WM_manipulator_set_matrix_location(wmManipulator *mpr, const float origin[3])
+{
+ copy_v3_v3(mpr->matrix_basis[3], origin);
+}
+
+/**
+ * wmManipulator.matrix_offset utils.
+ */
+void WM_manipulator_set_matrix_offset_rotation_from_z_axis(
+ wmManipulator *mpr, const float z_axis[3])
+{
+ wm_manipulator_set_matrix_rotation_from_z_axis__internal(mpr->matrix_offset, z_axis);
+}
+void WM_manipulator_set_matrix_offset_rotation_from_yz_axis(
+ wmManipulator *mpr, const float y_axis[3], const float z_axis[3])
+{
+ wm_manipulator_set_matrix_rotation_from_yz_axis__internal(mpr->matrix_offset, y_axis, z_axis);
+}
+void WM_manipulator_set_matrix_offset_location(wmManipulator *mpr, const float offset[3])
+{
+ copy_v3_v3(mpr->matrix_offset[3], offset);
+}
+
+void WM_manipulator_set_flag(wmManipulator *mpr, const int flag, const bool enable)
+{
+ if (enable) {
+ mpr->flag |= flag;
+ }
+ else {
+ mpr->flag &= ~flag;
+ }
+}
+
+void WM_manipulator_set_scale(wmManipulator *mpr, const float scale)
+{
+ mpr->scale_basis = scale;
+}
+
+void WM_manipulator_set_line_width(wmManipulator *mpr, const float line_width)
+{
+ mpr->line_width = line_width;
+}
+
+/**
+ * Set manipulator rgba colors.
+ *
+ * \param col Normal state color.
+ * \param col_hi Highlighted state color.
+ */
+void WM_manipulator_get_color(const wmManipulator *mpr, float color[4])
+{
+ copy_v4_v4(color, mpr->color);
+}
+void WM_manipulator_set_color(wmManipulator *mpr, const float color[4])
+{
+ copy_v4_v4(mpr->color, color);
+}
+
+void WM_manipulator_get_color_highlight(const wmManipulator *mpr, float color_hi[4])
+{
+ copy_v4_v4(color_hi, mpr->color_hi);
+}
+void WM_manipulator_set_color_highlight(wmManipulator *mpr, const float color_hi[4])
+{
+ copy_v4_v4(mpr->color_hi, color_hi);
+}
+
+
+/** \} */ // Manipulator Creation API
+
+
+/* -------------------------------------------------------------------- */
+/** \name Manipulator Callback Assignment
+ *
+ * \{ */
+
+void WM_manipulator_set_fn_custom_modal(struct wmManipulator *mpr, wmManipulatorFnModal fn)
+{
+ mpr->custom_modal = fn;
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/**
+ * Add/Remove \a manipulator to selection.
+ * Reallocates memory for selected manipulators so better not call for selecting multiple ones.
+ *
+ * \return if the selection has changed.
+ */
+bool wm_manipulator_select_set_ex(
+ wmManipulatorMap *mmap, wmManipulator *mpr, bool select,
+ bool use_array, bool use_callback)
+{
+ bool changed = false;
+
+ if (select) {
+ if ((mpr->state & WM_MANIPULATOR_STATE_SELECT) == 0) {
+ if (use_array) {
+ wm_manipulatormap_select_array_push_back(mmap, mpr);
+ }
+ mpr->state |= WM_MANIPULATOR_STATE_SELECT;
+ changed = true;
+ }
+ }
+ else {
+ if (mpr->state & WM_MANIPULATOR_STATE_SELECT) {
+ if (use_array) {
+ wm_manipulatormap_select_array_remove(mmap, mpr);
+ }
+ mpr->state &= ~WM_MANIPULATOR_STATE_SELECT;
+ changed = true;
+ }
+ }
+
+ /* In the case of unlinking we only want to remove from the array
+ * and not write to the external state */
+ if (use_callback && changed) {
+ if (mpr->type->select_refresh) {
+ mpr->type->select_refresh(mpr);
+ }
+ }
+
+ return changed;
+}
+
+/* Remove from selection array without running callbacks. */
+bool WM_manipulator_select_unlink(wmManipulatorMap *mmap, wmManipulator *mpr)
+{
+ return wm_manipulator_select_set_ex(mmap, mpr, false, true, false);
+}
+
+bool WM_manipulator_select_set(wmManipulatorMap *mmap, wmManipulator *mpr, bool select)
+{
+ return wm_manipulator_select_set_ex(mmap, mpr, select, true, true);
+}
+
+void WM_manipulator_highlight_set(wmManipulatorMap *mmap, wmManipulator *mpr)
+{
+ wm_manipulatormap_highlight_set(mmap, NULL, mpr, mpr ? mpr->highlight_part : 0);
+}
+
+bool wm_manipulator_select_and_highlight(bContext *C, wmManipulatorMap *mmap, wmManipulator *mpr)
+{
+ if (WM_manipulator_select_set(mmap, mpr, true)) {
+ wm_manipulatormap_highlight_set(mmap, C, mpr, mpr->highlight_part);
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+void wm_manipulator_calculate_scale(wmManipulator *mpr, const bContext *C)
+{
+ const RegionView3D *rv3d = CTX_wm_region_view3d(C);
+ float scale = UI_DPI_FAC;
+
+ if ((mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_SCALE) == 0) {
+ scale *= U.manipulator_size;
+ if (rv3d) {
+ /* 'ED_view3d_pixel_size' includes 'U.pixelsize', remove it. */
+ float matrix_world[4][4];
+ if (mpr->type->matrix_basis_get) {
+ float matrix_basis[4][4];
+ mpr->type->matrix_basis_get(mpr, matrix_basis);
+ mul_m4_m4m4(matrix_world, mpr->matrix_space, matrix_basis);
+ }
+ else {
+ mul_m4_m4m4(matrix_world, mpr->matrix_space, mpr->matrix_basis);
+ }
+
+ /* Exclude matrix_offset from scale. */
+ scale *= ED_view3d_pixel_size(rv3d, matrix_world[3]) / U.pixelsize;
+ }
+ else {
+ scale *= 0.02f;
+ }
+ }
+
+ mpr->scale_final = mpr->scale_basis * scale;
+}
+
+static void manipulator_update_prop_data(wmManipulator *mpr)
+{
+ /* manipulator property might have been changed, so update manipulator */
+ if (mpr->type->property_update) {
+ wmManipulatorProperty *mpr_prop_array = WM_manipulator_target_property_array(mpr);
+ for (int i = 0; i < mpr->type->target_property_defs_len; i++) {
+ wmManipulatorProperty *mpr_prop = &mpr_prop_array[i];
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ mpr->type->property_update(mpr, mpr_prop);
+ }
+ }
+ }
+}
+
+void wm_manipulator_update(wmManipulator *mpr, const bContext *C, const bool refresh_map)
+{
+ if (refresh_map) {
+ manipulator_update_prop_data(mpr);
+ }
+ wm_manipulator_calculate_scale(mpr, C);
+}
+
+int wm_manipulator_is_visible(wmManipulator *mpr)
+{
+ if (mpr->flag & WM_MANIPULATOR_HIDDEN) {
+ return 0;
+ }
+ if ((mpr->state & WM_MANIPULATOR_STATE_MODAL) &&
+ !(mpr->flag & (WM_MANIPULATOR_DRAW_MODAL | WM_MANIPULATOR_DRAW_VALUE)))
+ {
+ /* don't draw while modal (dragging) */
+ return 0;
+ }
+ if ((mpr->flag & WM_MANIPULATOR_DRAW_HOVER) &&
+ !(mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT) &&
+ !(mpr->state & WM_MANIPULATOR_STATE_SELECT)) /* still draw selected manipulators */
+ {
+ /* update but don't draw */
+ return WM_MANIPULATOR_IS_VISIBLE_UPDATE;
+ }
+
+ return WM_MANIPULATOR_IS_VISIBLE_UPDATE | WM_MANIPULATOR_IS_VISIBLE_DRAW;
+}
+
+void WM_manipulator_calc_matrix_final_params(
+ const wmManipulator *mpr,
+ const struct WM_ManipulatorMatrixParams *params,
+ float r_mat[4][4])
+{
+ const float (* const matrix_space)[4] = params->matrix_space ? params->matrix_space : mpr->matrix_space;
+ const float (* const matrix_basis)[4] = params->matrix_basis ? params->matrix_basis : mpr->matrix_basis;
+ const float (* const matrix_offset)[4] = params->matrix_offset ? params->matrix_offset : mpr->matrix_offset;
+ const float *scale_final = params->scale_final ? params->scale_final : &mpr->scale_final;
+
+ float final_matrix[4][4];
+ if (params->matrix_basis == NULL && mpr->type->matrix_basis_get) {
+ mpr->type->matrix_basis_get(mpr, final_matrix);
+ }
+ else {
+ copy_m4_m4(final_matrix, matrix_basis);
+ }
+
+ if (mpr->flag & WM_MANIPULATOR_DRAW_NO_SCALE) {
+ mul_m4_m4m4(final_matrix, final_matrix, matrix_offset);
+ }
+ else {
+ if (mpr->flag & WM_MANIPULATOR_DRAW_OFFSET_SCALE) {
+ mul_mat3_m4_fl(final_matrix, *scale_final);
+ mul_m4_m4m4(final_matrix, final_matrix, matrix_offset);
+ }
+ else {
+ mul_m4_m4m4(final_matrix, final_matrix, matrix_offset);
+ mul_mat3_m4_fl(final_matrix, *scale_final);
+ }
+ }
+
+ mul_m4_m4m4(r_mat, matrix_space, final_matrix);
+}
+
+void WM_manipulator_calc_matrix_final(const wmManipulator *mpr, float r_mat[4][4])
+{
+ WM_manipulator_calc_matrix_final_params(
+ mpr,
+ &((struct WM_ManipulatorMatrixParams) {
+ .matrix_space = NULL,
+ .matrix_basis = NULL,
+ .matrix_offset = NULL,
+ .scale_final = NULL,
+ }), r_mat
+ );
+}
+
+/** \name Manipulator Propery Access
+ *
+ * Matches `WM_operator_properties` conventions.
+ *
+ * \{ */
+
+
+void WM_manipulator_properties_create_ptr(PointerRNA *ptr, wmManipulatorType *wt)
+{
+ RNA_pointer_create(NULL, wt->srna, NULL, ptr);
+}
+
+void WM_manipulator_properties_create(PointerRNA *ptr, const char *wtstring)
+{
+ const wmManipulatorType *wt = WM_manipulatortype_find(wtstring, false);
+
+ if (wt)
+ WM_manipulator_properties_create_ptr(ptr, (wmManipulatorType *)wt);
+ else
+ RNA_pointer_create(NULL, &RNA_ManipulatorProperties, NULL, ptr);
+}
+
+/* similar to the function above except its uses ID properties
+ * used for keymaps and macros */
+void WM_manipulator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *wtstring)
+{
+ if (*properties == NULL) {
+ IDPropertyTemplate val = {0};
+ *properties = IDP_New(IDP_GROUP, &val, "wmOpItemProp");
+ }
+
+ if (*ptr == NULL) {
+ *ptr = MEM_callocN(sizeof(PointerRNA), "wmOpItemPtr");
+ WM_manipulator_properties_create(*ptr, wtstring);
+ }
+
+ (*ptr)->data = *properties;
+
+}
+
+void WM_manipulator_properties_sanitize(PointerRNA *ptr, const bool no_context)
+{
+ RNA_STRUCT_BEGIN (ptr, prop)
+ {
+ switch (RNA_property_type(prop)) {
+ case PROP_ENUM:
+ if (no_context)
+ RNA_def_property_flag(prop, PROP_ENUM_NO_CONTEXT);
+ else
+ RNA_def_property_clear_flag(prop, PROP_ENUM_NO_CONTEXT);
+ break;
+ case PROP_POINTER:
+ {
+ StructRNA *ptype = RNA_property_pointer_type(ptr, prop);
+
+ /* recurse into manipulator properties */
+ if (RNA_struct_is_a(ptype, &RNA_ManipulatorProperties)) {
+ PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
+ WM_manipulator_properties_sanitize(&opptr, no_context);
+ }
+ break;
+ }
+ default:
+ break;
+ }
+ }
+ RNA_STRUCT_END;
+}
+
+
+/** set all props to their default,
+ * \param do_update Only update un-initialized props.
+ *
+ * \note, theres nothing specific to manipulators here.
+ * this could be made a general function.
+ */
+bool WM_manipulator_properties_default(PointerRNA *ptr, const bool do_update)
+{
+ bool changed = false;
+ RNA_STRUCT_BEGIN (ptr, prop)
+ {
+ switch (RNA_property_type(prop)) {
+ case PROP_POINTER:
+ {
+ StructRNA *ptype = RNA_property_pointer_type(ptr, prop);
+ if (ptype != &RNA_Struct) {
+ PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
+ changed |= WM_manipulator_properties_default(&opptr, do_update);
+ }
+ break;
+ }
+ default:
+ if ((do_update == false) || (RNA_property_is_set(ptr, prop) == false)) {
+ if (RNA_property_reset(ptr, prop, -1)) {
+ changed = true;
+ }
+ }
+ break;
+ }
+ }
+ RNA_STRUCT_END;
+
+ return changed;
+}
+
+/* remove all props without PROP_SKIP_SAVE */
+void WM_manipulator_properties_reset(wmManipulator *mpr)
+{
+ if (mpr->ptr->data) {
+ PropertyRNA *iterprop;
+ iterprop = RNA_struct_iterator_property(mpr->type->srna);
+
+ RNA_PROP_BEGIN (mpr->ptr, itemptr, iterprop)
+ {
+ PropertyRNA *prop = itemptr.data;
+
+ if ((RNA_property_flag(prop) & PROP_SKIP_SAVE) == 0) {
+ const char *identifier = RNA_property_identifier(prop);
+ RNA_struct_idprops_unset(mpr->ptr, identifier);
+ }
+ }
+ RNA_PROP_END;
+ }
+}
+
+void WM_manipulator_properties_clear(PointerRNA *ptr)
+{
+ IDProperty *properties = ptr->data;
+
+ if (properties) {
+ IDP_ClearProperty(properties);
+ }
+}
+
+void WM_manipulator_properties_free(PointerRNA *ptr)
+{
+ IDProperty *properties = ptr->data;
+
+ if (properties) {
+ IDP_FreeProperty(properties);
+ MEM_freeN(properties);
+ ptr->data = NULL; /* just in case */
+ }
+}
+
+/** \} */
+
+/** \name General Utilities
+ *
+ * \{ */
+
+bool WM_manipulator_context_check_drawstep(const struct bContext *C, eWM_ManipulatorMapDrawStep step)
+{
+ switch (step) {
+ case WM_MANIPULATORMAP_DRAWSTEP_2D:
+ {
+ break;
+ }
+ case WM_MANIPULATORMAP_DRAWSTEP_3D:
+ {
+ wmWindowManager *wm = CTX_wm_manager(C);
+ if (ED_screen_animation_playing(wm)) {
+ return false;
+ }
+ break;
+ }
+ }
+ return true;
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c
new file mode 100644
index 00000000000..3d7403dc0e1
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_group.c
@@ -0,0 +1,949 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator_group.c
+ * \ingroup wm
+ *
+ * \name Manipulator-Group
+ *
+ * Manipulator-groups store and manage groups of manipulators. They can be
+ * attached to modal handlers and have own keymaps.
+ */
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "MEM_guardedalloc.h"
+
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_math.h"
+
+#include "BKE_context.h"
+#include "BKE_main.h"
+#include "BKE_report.h"
+#include "BKE_workspace.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "wm_event_system.h"
+
+#include "ED_screen.h"
+#include "ED_undo.h"
+
+/* own includes */
+#include "wm_manipulator_wmapi.h"
+#include "wm_manipulator_intern.h"
+
+#ifdef WITH_PYTHON
+# include "BPY_extern.h"
+#endif
+
+/* Allow manipulator part's to be single click only,
+ * dragging falls back to activating their 'drag_part' action. */
+#define USE_DRAG_DETECT
+
+/* -------------------------------------------------------------------- */
+/** \name wmManipulatorGroup
+ *
+ * \{ */
+
+/**
+ * Create a new manipulator-group from \a wgt.
+ */
+wmManipulatorGroup *wm_manipulatorgroup_new_from_type(
+ wmManipulatorMap *mmap, wmManipulatorGroupType *wgt)
+{
+ wmManipulatorGroup *mgroup = MEM_callocN(sizeof(*mgroup), "manipulator-group");
+ mgroup->type = wgt;
+
+ /* keep back-link */
+ mgroup->parent_mmap = mmap;
+
+ BLI_addtail(&mmap->groups, mgroup);
+
+ return mgroup;
+}
+
+void wm_manipulatorgroup_free(bContext *C, wmManipulatorGroup *mgroup)
+{
+ wmManipulatorMap *mmap = mgroup->parent_mmap;
+
+ /* Similar to WM_manipulator_unlink, but only to keep mmap state correct,
+ * we don't want to run callbacks. */
+ if (mmap->mmap_context.highlight && mmap->mmap_context.highlight->parent_mgroup == mgroup) {
+ wm_manipulatormap_highlight_set(mmap, C, NULL, 0);
+ }
+ if (mmap->mmap_context.modal && mmap->mmap_context.modal->parent_mgroup == mgroup) {
+ wm_manipulatormap_modal_set(mmap, C, mmap->mmap_context.modal, NULL, false);
+ }
+
+ for (wmManipulator *mpr = mgroup->manipulators.first, *mpr_next; mpr; mpr = mpr_next) {
+ mpr_next = mpr->next;
+ if (mmap->mmap_context.select.len) {
+ WM_manipulator_select_unlink(mmap, mpr);
+ }
+ WM_manipulator_free(mpr);
+ }
+ BLI_listbase_clear(&mgroup->manipulators);
+
+#ifdef WITH_PYTHON
+ if (mgroup->py_instance) {
+ /* do this first in case there are any __del__ functions or
+ * similar that use properties */
+ BPY_DECREF_RNA_INVALIDATE(mgroup->py_instance);
+ }
+#endif
+
+ if (mgroup->reports && (mgroup->reports->flag & RPT_FREE)) {
+ BKE_reports_clear(mgroup->reports);
+ MEM_freeN(mgroup->reports);
+ }
+
+ if (mgroup->customdata_free) {
+ mgroup->customdata_free(mgroup->customdata);
+ }
+ else {
+ MEM_SAFE_FREE(mgroup->customdata);
+ }
+
+ BLI_remlink(&mmap->groups, mgroup);
+
+ MEM_freeN(mgroup);
+}
+
+/**
+ * Add \a manipulator to \a mgroup and make sure its name is unique within the group.
+ */
+void wm_manipulatorgroup_manipulator_register(wmManipulatorGroup *mgroup, wmManipulator *mpr)
+{
+ BLI_assert(BLI_findindex(&mgroup->manipulators, mpr) == -1);
+ BLI_addtail(&mgroup->manipulators, mpr);
+ mpr->parent_mgroup = mgroup;
+}
+
+wmManipulator *wm_manipulatorgroup_find_intersected_manipulator(
+ const wmManipulatorGroup *mgroup, bContext *C, const wmEvent *event,
+ int *r_part)
+{
+ for (wmManipulator *mpr = mgroup->manipulators.first; mpr; mpr = mpr->next) {
+ if (mpr->type->test_select && (mpr->flag & WM_MANIPULATOR_HIDDEN) == 0) {
+ if ((*r_part = mpr->type->test_select(C, mpr, event)) != -1) {
+ return mpr;
+ }
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * Adds all manipulators of \a mgroup that can be selected to the head of \a listbase. Added items need freeing!
+ */
+void wm_manipulatorgroup_intersectable_manipulators_to_list(const wmManipulatorGroup *mgroup, ListBase *listbase)
+{
+ for (wmManipulator *mpr = mgroup->manipulators.first; mpr; mpr = mpr->next) {
+ if ((mpr->flag & WM_MANIPULATOR_HIDDEN) == 0) {
+ if (((mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) && mpr->type->draw_select) ||
+ ((mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) == 0 && mpr->type->test_select))
+ {
+ BLI_addhead(listbase, BLI_genericNodeN(mpr));
+ }
+ }
+ }
+}
+
+void wm_manipulatorgroup_ensure_initialized(wmManipulatorGroup *mgroup, const bContext *C)
+{
+ /* prepare for first draw */
+ if (UNLIKELY((mgroup->init_flag & WM_MANIPULATORGROUP_INIT_SETUP) == 0)) {
+ mgroup->type->setup(C, mgroup);
+
+ /* Not ideal, initialize keymap here, needed for RNA runtime generated manipulators. */
+ wmManipulatorGroupType *wgt = mgroup->type;
+ if (wgt->keymap == NULL) {
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wm_manipulatorgrouptype_setup_keymap(wgt, wm->defaultconf);
+ BLI_assert(wgt->keymap != NULL);
+ }
+ mgroup->init_flag |= WM_MANIPULATORGROUP_INIT_SETUP;
+ }
+
+ /* refresh may be called multiple times, this just ensures its called at least once before we draw. */
+ if (UNLIKELY((mgroup->init_flag & WM_MANIPULATORGROUP_INIT_REFRESH) == 0)) {
+ if (mgroup->type->refresh) {
+ mgroup->type->refresh(C, mgroup);
+ }
+ mgroup->init_flag |= WM_MANIPULATORGROUP_INIT_REFRESH;
+ }
+}
+
+bool WM_manipulator_group_type_poll(const bContext *C, const struct wmManipulatorGroupType *wgt)
+{
+ /* If we're tagged, only use compatible. */
+ if (wgt->owner_id[0] != '\0') {
+ const WorkSpace *workspace = CTX_wm_workspace(C);
+ if (BKE_workspace_owner_id_check(workspace, wgt->owner_id) == false) {
+ return false;
+ }
+ }
+ /* Check for poll function, if manipulator-group belongs to an operator, also check if the operator is running. */
+ return (!wgt->poll || wgt->poll(C, (wmManipulatorGroupType *)wgt));
+}
+
+bool wm_manipulatorgroup_is_visible_in_drawstep(
+ const wmManipulatorGroup *mgroup, const eWM_ManipulatorMapDrawStep drawstep)
+{
+ switch (drawstep) {
+ case WM_MANIPULATORMAP_DRAWSTEP_2D:
+ return (mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) == 0;
+ case WM_MANIPULATORMAP_DRAWSTEP_3D:
+ return (mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D);
+ default:
+ BLI_assert(0);
+ return false;
+ }
+}
+
+bool wm_manipulatorgroup_is_any_selected(const wmManipulatorGroup *mgroup)
+{
+ if (mgroup->type->flag & WM_MANIPULATORGROUPTYPE_SELECT) {
+ for (const wmManipulator *mpr = mgroup->manipulators.first; mpr; mpr = mpr->next) {
+ if (mpr->state & WM_MANIPULATOR_STATE_SELECT) {
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+/** \} */
+
+/** \name Manipulator operators
+ *
+ * Basic operators for manipulator interaction with user configurable keymaps.
+ *
+ * \{ */
+
+static int manipulator_select_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
+{
+ ARegion *ar = CTX_wm_region(C);
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+ wmManipulator *highlight = mmap->mmap_context.highlight;
+
+ bool extend = RNA_boolean_get(op->ptr, "extend");
+ bool deselect = RNA_boolean_get(op->ptr, "deselect");
+ bool toggle = RNA_boolean_get(op->ptr, "toggle");
+
+ /* deselect all first */
+ if (extend == false && deselect == false && toggle == false) {
+ wm_manipulatormap_deselect_all(mmap);
+ BLI_assert(msel->items == NULL && msel->len == 0);
+ UNUSED_VARS_NDEBUG(msel);
+ }
+
+ if (highlight) {
+ const bool is_selected = (highlight->state & WM_MANIPULATOR_STATE_SELECT);
+ bool redraw = false;
+
+ if (toggle) {
+ /* toggle: deselect if already selected, else select */
+ deselect = is_selected;
+ }
+
+ if (deselect) {
+ if (is_selected && WM_manipulator_select_set(mmap, highlight, false)) {
+ redraw = true;
+ }
+ }
+ else if (wm_manipulator_select_and_highlight(C, mmap, highlight)) {
+ redraw = true;
+ }
+
+ if (redraw) {
+ ED_region_tag_redraw(ar);
+ }
+
+ return OPERATOR_FINISHED;
+ }
+ else {
+ BLI_assert(0);
+ return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
+ }
+
+ return OPERATOR_PASS_THROUGH;
+}
+
+void MANIPULATORGROUP_OT_manipulator_select(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Manipulator Select";
+ ot->description = "Select the currently highlighted manipulator";
+ ot->idname = "MANIPULATORGROUP_OT_manipulator_select";
+
+ /* api callbacks */
+ ot->invoke = manipulator_select_invoke;
+
+ ot->flag = OPTYPE_UNDO;
+
+ WM_operator_properties_mouse_select(ot);
+}
+
+typedef struct ManipulatorTweakData {
+ wmManipulatorMap *mmap;
+ wmManipulatorGroup *mgroup;
+ wmManipulator *mpr_modal;
+
+ int init_event; /* initial event type */
+ int flag; /* tweak flags */
+
+#ifdef USE_DRAG_DETECT
+ /* True until the mouse is moved (only use when the operator has no modal).
+ * this allows some manipulators to be click-only. */
+ enum {
+ /* Don't detect dragging. */
+ DRAG_NOP = 0,
+ /* Detect dragging (wait until a drag or click is detected). */
+ DRAG_DETECT,
+ /* Drag has started, idle until there is no active modal operator.
+ * This is needed because finishing the modal operator also exits
+ * the modal manipulator state (un-grabbs the cursor).
+ * Ideally this workaround could be removed later. */
+ DRAG_IDLE,
+ } drag_state;
+#endif
+
+} ManipulatorTweakData;
+
+static bool manipulator_tweak_start(
+ bContext *C, wmManipulatorMap *mmap, wmManipulator *mpr, const wmEvent *event)
+{
+ /* activate highlighted manipulator */
+ wm_manipulatormap_modal_set(mmap, C, mpr, event, true);
+
+ return (mpr->state & WM_MANIPULATOR_STATE_MODAL);
+}
+
+static bool manipulator_tweak_start_and_finish(
+ bContext *C, wmManipulatorMap *mmap, wmManipulator *mpr, const wmEvent *event, bool *r_is_modal)
+{
+ wmManipulatorOpElem *mpop = WM_manipulator_operator_get(mpr, mpr->highlight_part);
+ if (r_is_modal) {
+ *r_is_modal = false;
+ }
+ if (mpop && mpop->type) {
+
+ /* Undo/Redo */
+ if (mpop->is_redo) {
+ wmWindowManager *wm = CTX_wm_manager(C);
+ wmOperator *op = WM_operator_last_redo(C);
+
+ /* We may want to enable this, for now the manipulator can manage it's own properties. */
+#if 0
+ IDP_MergeGroup(mpop->ptr.data, op->properties, false);
+#endif
+
+ WM_operator_free_all_after(wm, op);
+ ED_undo_pop_op(C, op);
+ }
+
+ /* XXX temporary workaround for modal manipulator operator
+ * conflicting with modal operator attached to manipulator */
+ if (mpop->type->modal) {
+ /* activate highlighted manipulator */
+ wm_manipulatormap_modal_set(mmap, C, mpr, event, true);
+ if (r_is_modal) {
+ *r_is_modal = true;
+ }
+ }
+ else {
+ /* Allow for 'button' manipulators, single click to run an action. */
+ WM_operator_name_call_ptr(C, mpop->type, WM_OP_INVOKE_DEFAULT, &mpop->ptr);
+ }
+ return true;
+ }
+ else {
+ return false;
+ }
+}
+
+static void manipulator_tweak_finish(bContext *C, wmOperator *op, const bool cancel, bool clear_modal)
+{
+ ManipulatorTweakData *mtweak = op->customdata;
+ if (mtweak->mpr_modal->type->exit) {
+ mtweak->mpr_modal->type->exit(C, mtweak->mpr_modal, cancel);
+ }
+ if (clear_modal) {
+ /* The manipulator may have been removed. */
+ if ((BLI_findindex(&mtweak->mmap->groups, mtweak->mgroup) != -1) &&
+ (BLI_findindex(&mtweak->mgroup->manipulators, mtweak->mpr_modal) != -1))
+ {
+ wm_manipulatormap_modal_set(mtweak->mmap, C, mtweak->mpr_modal, NULL, false);
+ }
+ }
+ MEM_freeN(mtweak);
+}
+
+static int manipulator_tweak_modal(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ ManipulatorTweakData *mtweak = op->customdata;
+ wmManipulator *mpr = mtweak->mpr_modal;
+ int retval = OPERATOR_PASS_THROUGH;
+ bool clear_modal = true;
+
+ if (mpr == NULL) {
+ BLI_assert(0);
+ return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
+ }
+
+#ifdef USE_DRAG_DETECT
+ wmManipulatorMap *mmap = mtweak->mmap;
+ if (mtweak->drag_state == DRAG_DETECT) {
+ if (ELEM(event->type, MOUSEMOVE, INBETWEEN_MOUSEMOVE)) {
+ if (len_manhattan_v2v2_int(&event->x, mmap->mmap_context.event_xy) > 2) {
+ mtweak->drag_state = DRAG_IDLE;
+ mpr->highlight_part = mpr->drag_part;
+ }
+ }
+ else if (event->type == mtweak->init_event && event->val == KM_RELEASE) {
+ mtweak->drag_state = DRAG_NOP;
+ retval = OPERATOR_FINISHED;
+ }
+
+ if (mtweak->drag_state != DRAG_DETECT) {
+ /* Follow logic in 'manipulator_tweak_invoke' */
+ bool is_modal = false;
+ if (manipulator_tweak_start_and_finish(C, mmap, mpr, event, &is_modal)) {
+ if (is_modal) {
+ clear_modal = false;
+ }
+ }
+ else {
+ if (!manipulator_tweak_start(C, mmap, mpr, event)) {
+ retval = OPERATOR_FINISHED;
+ }
+ }
+ }
+ }
+ if (mtweak->drag_state == DRAG_IDLE) {
+ if (mmap->mmap_context.modal != NULL) {
+ return OPERATOR_PASS_THROUGH;
+ }
+ else {
+ manipulator_tweak_finish(C, op, false, false);
+ return OPERATOR_FINISHED;
+ }
+ }
+#endif /* USE_DRAG_DETECT */
+
+ if (retval == OPERATOR_FINISHED) {
+ /* pass */
+ }
+ else if (event->type == mtweak->init_event && event->val == KM_RELEASE) {
+ retval = OPERATOR_FINISHED;
+ }
+ else if (event->type == EVT_MODAL_MAP) {
+ switch (event->val) {
+ case TWEAK_MODAL_CANCEL:
+ retval = OPERATOR_CANCELLED;
+ break;
+ case TWEAK_MODAL_CONFIRM:
+ retval = OPERATOR_FINISHED;
+ break;
+ case TWEAK_MODAL_PRECISION_ON:
+ mtweak->flag |= WM_MANIPULATOR_TWEAK_PRECISE;
+ break;
+ case TWEAK_MODAL_PRECISION_OFF:
+ mtweak->flag &= ~WM_MANIPULATOR_TWEAK_PRECISE;
+ break;
+
+ case TWEAK_MODAL_SNAP_ON:
+ mtweak->flag |= WM_MANIPULATOR_TWEAK_SNAP;
+ break;
+ case TWEAK_MODAL_SNAP_OFF:
+ mtweak->flag &= ~WM_MANIPULATOR_TWEAK_SNAP;
+ break;
+ }
+ }
+
+ if (retval != OPERATOR_PASS_THROUGH) {
+ manipulator_tweak_finish(C, op, retval != OPERATOR_FINISHED, clear_modal);
+ return retval;
+ }
+
+ /* handle manipulator */
+ wmManipulatorFnModal modal_fn = mpr->custom_modal ? mpr->custom_modal : mpr->type->modal;
+ if (modal_fn) {
+ int modal_retval = modal_fn(C, mpr, event, mtweak->flag);
+
+ if ((modal_retval & OPERATOR_RUNNING_MODAL) == 0) {
+ manipulator_tweak_finish(C, op, (modal_retval & OPERATOR_CANCELLED) != 0, true);
+ return OPERATOR_FINISHED;
+ }
+
+ /* Ugly hack to send manipulator events */
+ ((wmEvent *)event)->type = EVT_MANIPULATOR_UPDATE;
+ }
+
+ /* always return PASS_THROUGH so modal handlers
+ * with manipulators attached can update */
+ BLI_assert(retval == OPERATOR_PASS_THROUGH);
+ return OPERATOR_PASS_THROUGH;
+}
+
+static int manipulator_tweak_invoke(bContext *C, wmOperator *op, const wmEvent *event)
+{
+ ARegion *ar = CTX_wm_region(C);
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ wmManipulator *mpr = mmap->mmap_context.highlight;
+
+ /* Needed for single click actions which don't enter modal state. */
+ WM_tooltip_clear(C, CTX_wm_window(C));
+
+ if (!mpr) {
+ /* wm_handlers_do_intern shouldn't let this happen */
+ BLI_assert(0);
+ return (OPERATOR_CANCELLED | OPERATOR_PASS_THROUGH);
+ }
+
+ bool use_drag_fallback = false;
+
+#ifdef USE_DRAG_DETECT
+ use_drag_fallback = !ELEM(mpr->drag_part, -1, mpr->highlight_part);
+#endif
+
+ if (use_drag_fallback == false) {
+ if (manipulator_tweak_start_and_finish(C, mmap, mpr, event, NULL)) {
+ return OPERATOR_FINISHED;
+ }
+ }
+
+ bool use_drag_detect = false;
+#ifdef USE_DRAG_DETECT
+ if (use_drag_fallback) {
+ wmManipulatorOpElem *mpop = WM_manipulator_operator_get(mpr, mpr->highlight_part);
+ if (mpop && mpop->type) {
+ if (mpop->type->modal == NULL) {
+ use_drag_detect = true;
+ }
+ }
+ }
+#endif
+
+ if (use_drag_detect == false) {
+ if (!manipulator_tweak_start(C, mmap, mpr, event)) {
+ /* failed to start */
+ return OPERATOR_PASS_THROUGH;
+ }
+ }
+
+ ManipulatorTweakData *mtweak = MEM_mallocN(sizeof(ManipulatorTweakData), __func__);
+
+ mtweak->init_event = WM_userdef_event_type_from_keymap_type(event->type);
+ mtweak->mpr_modal = mmap->mmap_context.highlight;
+ mtweak->mgroup = mtweak->mpr_modal->parent_mgroup;
+ mtweak->mmap = mmap;
+ mtweak->flag = 0;
+
+#ifdef USE_DRAG_DETECT
+ mtweak->drag_state = use_drag_detect ? DRAG_DETECT : DRAG_NOP;
+#endif
+
+ op->customdata = mtweak;
+
+ WM_event_add_modal_handler(C, op);
+
+ return OPERATOR_RUNNING_MODAL;
+}
+
+void MANIPULATORGROUP_OT_manipulator_tweak(wmOperatorType *ot)
+{
+ /* identifiers */
+ ot->name = "Manipulator Tweak";
+ ot->description = "Tweak the active manipulator";
+ ot->idname = "MANIPULATORGROUP_OT_manipulator_tweak";
+
+ /* api callbacks */
+ ot->invoke = manipulator_tweak_invoke;
+ ot->modal = manipulator_tweak_modal;
+
+ /* TODO(campbell) This causes problems tweaking settings for operators,
+ * need to find a way to support this. */
+#if 0
+ ot->flag = OPTYPE_UNDO;
+#endif
+}
+
+/** \} */ // Manipulator operators
+
+
+static wmKeyMap *manipulatorgroup_tweak_modal_keymap(wmKeyConfig *keyconf, const char *mgroupname)
+{
+ wmKeyMap *keymap;
+ char name[KMAP_MAX_NAME];
+
+ static EnumPropertyItem modal_items[] = {
+ {TWEAK_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
+ {TWEAK_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
+ {TWEAK_MODAL_PRECISION_ON, "PRECISION_ON", 0, "Enable Precision", ""},
+ {TWEAK_MODAL_PRECISION_OFF, "PRECISION_OFF", 0, "Disable Precision", ""},
+ {TWEAK_MODAL_SNAP_ON, "SNAP_ON", 0, "Enable Snap", ""},
+ {TWEAK_MODAL_SNAP_OFF, "SNAP_OFF", 0, "Disable Snap", ""},
+ {0, NULL, 0, NULL, NULL}
+ };
+
+
+ BLI_snprintf(name, sizeof(name), "%s Tweak Modal Map", mgroupname);
+ keymap = WM_modalkeymap_get(keyconf, name);
+
+ /* this function is called for each spacetype, only needs to add map once */
+ if (keymap && keymap->modal_items)
+ return NULL;
+
+ keymap = WM_modalkeymap_add(keyconf, name, modal_items);
+
+
+ /* items for modal map */
+ WM_modalkeymap_add_item(keymap, ESCKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL);
+ WM_modalkeymap_add_item(keymap, RIGHTMOUSE, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CANCEL);
+
+ WM_modalkeymap_add_item(keymap, RETKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM);
+ WM_modalkeymap_add_item(keymap, PADENTER, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_CONFIRM);
+
+ WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON);
+ WM_modalkeymap_add_item(keymap, RIGHTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF);
+ WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_PRECISION_ON);
+ WM_modalkeymap_add_item(keymap, LEFTSHIFTKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_PRECISION_OFF);
+
+ WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON);
+ WM_modalkeymap_add_item(keymap, RIGHTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF);
+ WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_PRESS, KM_ANY, 0, TWEAK_MODAL_SNAP_ON);
+ WM_modalkeymap_add_item(keymap, LEFTCTRLKEY, KM_RELEASE, KM_ANY, 0, TWEAK_MODAL_SNAP_OFF);
+
+ WM_modalkeymap_assign(keymap, "MANIPULATORGROUP_OT_manipulator_tweak");
+
+ return keymap;
+}
+
+/**
+ * Common default keymap for manipulator groups
+ */
+wmKeyMap *WM_manipulatorgroup_keymap_common(
+ const wmManipulatorGroupType *wgt, wmKeyConfig *config)
+{
+ /* Use area and region id since we might have multiple manipulators with the same name in different areas/regions */
+ wmKeyMap *km = WM_keymap_find(config, wgt->name, wgt->mmap_params.spaceid, wgt->mmap_params.regionid);
+
+ WM_keymap_add_item(km, "MANIPULATORGROUP_OT_manipulator_tweak", LEFTMOUSE, KM_PRESS, KM_ANY, 0);
+ manipulatorgroup_tweak_modal_keymap(config, wgt->name);
+
+ return km;
+}
+
+/**
+ * Variation of #WM_manipulatorgroup_keymap_common but with keymap items for selection
+ */
+wmKeyMap *WM_manipulatorgroup_keymap_common_select(
+ const wmManipulatorGroupType *wgt, wmKeyConfig *config)
+{
+ /* Use area and region id since we might have multiple manipulators with the same name in different areas/regions */
+ wmKeyMap *km = WM_keymap_find(config, wgt->name, wgt->mmap_params.spaceid, wgt->mmap_params.regionid);
+
+ WM_keymap_add_item(km, "MANIPULATORGROUP_OT_manipulator_tweak", ACTIONMOUSE, KM_PRESS, KM_ANY, 0);
+ WM_keymap_add_item(km, "MANIPULATORGROUP_OT_manipulator_tweak", EVT_TWEAK_S, KM_ANY, 0, 0);
+ manipulatorgroup_tweak_modal_keymap(config, wgt->name);
+
+ wmKeyMapItem *kmi = WM_keymap_add_item(km, "MANIPULATORGROUP_OT_manipulator_select", SELECTMOUSE, KM_PRESS, 0, 0);
+ RNA_boolean_set(kmi->ptr, "extend", false);
+ RNA_boolean_set(kmi->ptr, "deselect", false);
+ RNA_boolean_set(kmi->ptr, "toggle", false);
+ kmi = WM_keymap_add_item(km, "MANIPULATORGROUP_OT_manipulator_select", SELECTMOUSE, KM_PRESS, KM_SHIFT, 0);
+ RNA_boolean_set(kmi->ptr, "extend", false);
+ RNA_boolean_set(kmi->ptr, "deselect", false);
+ RNA_boolean_set(kmi->ptr, "toggle", true);
+
+ return km;
+}
+
+/** \} */ /* wmManipulatorGroup */
+
+/* -------------------------------------------------------------------- */
+/** \name wmManipulatorGroupType
+ *
+ * \{ */
+
+struct wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_find_ptr(
+ struct wmManipulatorMapType *mmap_type,
+ const wmManipulatorGroupType *wgt)
+{
+ /* could use hash lookups as operator types do, for now simple search. */
+ for (wmManipulatorGroupTypeRef *wgt_ref = mmap_type->grouptype_refs.first;
+ wgt_ref;
+ wgt_ref = wgt_ref->next)
+ {
+ if (wgt_ref->type == wgt) {
+ return wgt_ref;
+ }
+ }
+ return NULL;
+}
+
+struct wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_find(
+ struct wmManipulatorMapType *mmap_type,
+ const char *idname)
+{
+ /* could use hash lookups as operator types do, for now simple search. */
+ for (wmManipulatorGroupTypeRef *wgt_ref = mmap_type->grouptype_refs.first;
+ wgt_ref;
+ wgt_ref = wgt_ref->next)
+ {
+ if (STREQ(idname, wgt_ref->type->idname)) {
+ return wgt_ref;
+ }
+ }
+ return NULL;
+}
+
+/**
+ * Use this for registering manipulators on startup. For runtime, use #WM_manipulatormaptype_group_link_runtime.
+ */
+wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_link(
+ wmManipulatorMapType *mmap_type, const char *idname)
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, false);
+ BLI_assert(wgt != NULL);
+ return WM_manipulatormaptype_group_link_ptr(mmap_type, wgt);
+}
+
+wmManipulatorGroupTypeRef *WM_manipulatormaptype_group_link_ptr(
+ wmManipulatorMapType *mmap_type, wmManipulatorGroupType *wgt)
+{
+ wmManipulatorGroupTypeRef *wgt_ref = MEM_callocN(sizeof(wmManipulatorGroupTypeRef), "manipulator-group-ref");
+ wgt_ref->type = wgt;
+ BLI_addtail(&mmap_type->grouptype_refs, wgt_ref);
+ return wgt_ref;
+}
+
+void WM_manipulatormaptype_group_init_runtime_keymap(
+ const Main *bmain,
+ wmManipulatorGroupType *wgt)
+{
+ /* init keymap - on startup there's an extra call to init keymaps for 'permanent' manipulator-groups */
+ wm_manipulatorgrouptype_setup_keymap(wgt, ((wmWindowManager *)bmain->wm.first)->defaultconf);
+}
+
+void WM_manipulatormaptype_group_init_runtime(
+ const Main *bmain, wmManipulatorMapType *mmap_type,
+ wmManipulatorGroupType *wgt)
+{
+ /* now create a manipulator for all existing areas */
+ for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
+ for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+ ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
+ for (ARegion *ar = lb->first; ar; ar = ar->next) {
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ if (mmap && mmap->type == mmap_type) {
+ wm_manipulatorgroup_new_from_type(mmap, wgt);
+
+ /* just add here, drawing will occur on next update */
+ wm_manipulatormap_highlight_set(mmap, NULL, NULL, 0);
+ ED_region_tag_redraw(ar);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+/**
+ * Unlike #WM_manipulatormaptype_group_unlink this doesn't maintain correct state, simply free.
+ */
+void WM_manipulatormaptype_group_free(wmManipulatorGroupTypeRef *wgt_ref)
+{
+ MEM_freeN(wgt_ref);
+}
+
+void WM_manipulatormaptype_group_unlink(
+ bContext *C, Main *bmain, wmManipulatorMapType *mmap_type,
+ const wmManipulatorGroupType *wgt)
+{
+ /* Free instances. */
+ for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
+ for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+ ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
+ for (ARegion *ar = lb->first; ar; ar = ar->next) {
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ if (mmap && mmap->type == mmap_type) {
+ wmManipulatorGroup *mgroup, *mgroup_next;
+ for (mgroup = mmap->groups.first; mgroup; mgroup = mgroup_next) {
+ mgroup_next = mgroup->next;
+ if (mgroup->type == wgt) {
+ BLI_assert(mgroup->parent_mmap == mmap);
+ wm_manipulatorgroup_free(C, mgroup);
+ ED_region_tag_redraw(ar);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+
+ /* Free types. */
+ wmManipulatorGroupTypeRef *wgt_ref = WM_manipulatormaptype_group_find_ptr(mmap_type, wgt);
+ if (wgt_ref) {
+ BLI_remlink(&mmap_type->grouptype_refs, wgt_ref);
+ WM_manipulatormaptype_group_free(wgt_ref);
+ }
+
+ /* Note, we may want to keep this keymap for editing */
+ WM_keymap_remove(wgt->keyconf, wgt->keymap);
+
+ BLI_assert(WM_manipulatormaptype_group_find_ptr(mmap_type, wgt) == NULL);
+}
+
+void wm_manipulatorgrouptype_setup_keymap(
+ wmManipulatorGroupType *wgt, wmKeyConfig *keyconf)
+{
+ /* Use flag since setup_keymap may return NULL,
+ * in that case we better not keep calling it. */
+ if (wgt->type_update_flag & WM_MANIPULATORMAPTYPE_KEYMAP_INIT) {
+ wgt->keymap = wgt->setup_keymap(wgt, keyconf);
+ wgt->keyconf = keyconf;
+ wgt->type_update_flag &= ~WM_MANIPULATORMAPTYPE_KEYMAP_INIT;
+ }
+}
+
+/** \} */ /* wmManipulatorGroupType */
+
+/* -------------------------------------------------------------------- */
+/** \name High Level Add/Remove API
+ *
+ * For use directly from operators & RNA registration.
+ *
+ * \note In context of manipulator API these names are a bit misleading,
+ * but for general use terms its OK.
+ * `WM_manipulator_group_type_add` would be more correctly called:
+ * `WM_manipulatormaptype_grouptype_reference_link`
+ * but for general purpose API this is too detailed & annoying.
+ *
+ * \note We may want to return a value if there is nothing to remove.
+ *
+ * \{ */
+
+void WM_manipulator_group_type_add_ptr_ex(
+ wmManipulatorGroupType *wgt,
+ wmManipulatorMapType *mmap_type)
+{
+ WM_manipulatormaptype_group_link_ptr(mmap_type, wgt);
+
+ WM_manipulatorconfig_update_tag_init(mmap_type, wgt);
+}
+void WM_manipulator_group_type_add_ptr(
+ wmManipulatorGroupType *wgt)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params);
+ WM_manipulator_group_type_add_ptr_ex(wgt, mmap_type);
+}
+void WM_manipulator_group_type_add(const char *idname)
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, false);
+ BLI_assert(wgt != NULL);
+ WM_manipulator_group_type_add_ptr(wgt);
+}
+
+void WM_manipulator_group_type_ensure_ptr_ex(
+ wmManipulatorGroupType *wgt,
+ wmManipulatorMapType *mmap_type)
+{
+ wmManipulatorGroupTypeRef *wgt_ref = WM_manipulatormaptype_group_find_ptr(mmap_type, wgt);
+ if (wgt_ref == NULL) {
+ WM_manipulator_group_type_add_ptr_ex(wgt, mmap_type);
+ }
+}
+void WM_manipulator_group_type_ensure_ptr(
+ wmManipulatorGroupType *wgt)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params);
+ WM_manipulator_group_type_ensure_ptr_ex(wgt, mmap_type);
+}
+void WM_manipulator_group_type_ensure(const char *idname)
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, false);
+ BLI_assert(wgt != NULL);
+ WM_manipulator_group_type_ensure_ptr(wgt);
+}
+
+void WM_manipulator_group_type_remove_ptr_ex(
+ struct Main *bmain, wmManipulatorGroupType *wgt,
+ wmManipulatorMapType *mmap_type)
+{
+ WM_manipulatormaptype_group_unlink(NULL, bmain, mmap_type, wgt);
+ WM_manipulatorgrouptype_free_ptr(wgt);
+}
+void WM_manipulator_group_type_remove_ptr(
+ struct Main *bmain, wmManipulatorGroupType *wgt)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params);
+ WM_manipulator_group_type_remove_ptr_ex(bmain, wgt, mmap_type);
+}
+void WM_manipulator_group_type_remove(struct Main *bmain, const char *idname)
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, false);
+ BLI_assert(wgt != NULL);
+ WM_manipulator_group_type_remove_ptr(bmain, wgt);
+}
+
+/* delayed versions */
+
+void WM_manipulator_group_type_unlink_delayed_ptr_ex(
+ wmManipulatorGroupType *wgt,
+ wmManipulatorMapType *mmap_type)
+{
+ WM_manipulatorconfig_update_tag_remove(mmap_type, wgt);
+}
+
+void WM_manipulator_group_type_unlink_delayed_ptr(
+ wmManipulatorGroupType *wgt)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(&wgt->mmap_params);
+ WM_manipulator_group_type_unlink_delayed_ptr_ex(wgt, mmap_type);
+}
+
+void WM_manipulator_group_type_unlink_delayed(const char *idname)
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, false);
+ BLI_assert(wgt != NULL);
+ WM_manipulator_group_type_unlink_delayed_ptr(wgt);
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_group_type.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_group_type.c
new file mode 100644
index 00000000000..1b5225a2f04
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_group_type.c
@@ -0,0 +1,198 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator_group_type.c
+ * \ingroup wm
+ */
+
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_context.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+/* only for own init/exit calls (wm_manipulatorgrouptype_init/wm_manipulatorgrouptype_free) */
+#include "wm.h"
+
+/* own includes */
+#include "wm_manipulator_wmapi.h"
+#include "wm_manipulator_intern.h"
+
+
+/** \name ManipulatorGroup Type Append
+ *
+ * \note This follows conventions from #WM_operatortype_find #WM_operatortype_append & friends.
+ * \{ */
+
+static GHash *global_manipulatorgrouptype_hash = NULL;
+
+wmManipulatorGroupType *WM_manipulatorgrouptype_find(const char *idname, bool quiet)
+{
+ if (idname[0]) {
+ wmManipulatorGroupType *wgt;
+
+ wgt = BLI_ghash_lookup(global_manipulatorgrouptype_hash, idname);
+ if (wgt) {
+ return wgt;
+ }
+
+ if (!quiet) {
+ printf("search for unknown manipulator group '%s'\n", idname);
+ }
+ }
+ else {
+ if (!quiet) {
+ printf("search for empty manipulator group\n");
+ }
+ }
+
+ return NULL;
+}
+
+/* caller must free */
+void WM_manipulatorgrouptype_iter(GHashIterator *ghi)
+{
+ BLI_ghashIterator_init(ghi, global_manipulatorgrouptype_hash);
+}
+
+static wmManipulatorGroupType *wm_manipulatorgrouptype_append__begin(void)
+{
+ wmManipulatorGroupType *wgt = MEM_callocN(sizeof(wmManipulatorGroupType), "manipulatorgrouptype");
+
+ return wgt;
+}
+static void wm_manipulatorgrouptype_append__end(wmManipulatorGroupType *wgt)
+{
+ BLI_assert(wgt->name != NULL);
+ BLI_assert(wgt->idname != NULL);
+
+ wgt->type_update_flag |= WM_MANIPULATORMAPTYPE_KEYMAP_INIT;
+
+ /* if not set, use default */
+ if (wgt->setup_keymap == NULL) {
+ if (wgt->flag & WM_MANIPULATORGROUPTYPE_SELECT) {
+ wgt->setup_keymap = WM_manipulatorgroup_keymap_common_select;
+ }
+ else {
+ wgt->setup_keymap = WM_manipulatorgroup_keymap_common;
+ }
+ }
+
+ BLI_ghash_insert(global_manipulatorgrouptype_hash, (void *)wgt->idname, wgt);
+}
+
+wmManipulatorGroupType *WM_manipulatorgrouptype_append(
+ void (*wtfunc)(struct wmManipulatorGroupType *))
+{
+ wmManipulatorGroupType *wgt = wm_manipulatorgrouptype_append__begin();
+ wtfunc(wgt);
+ wm_manipulatorgrouptype_append__end(wgt);
+ return wgt;
+}
+
+wmManipulatorGroupType *WM_manipulatorgrouptype_append_ptr(
+ void (*wtfunc)(struct wmManipulatorGroupType *, void *), void *userdata)
+{
+ wmManipulatorGroupType *wgt = wm_manipulatorgrouptype_append__begin();
+ wtfunc(wgt, userdata);
+ wm_manipulatorgrouptype_append__end(wgt);
+ return wgt;
+}
+
+/**
+ * Append and insert into a manipulator typemap.
+ * This is most common for C manipulators which are enabled by default.
+ */
+wmManipulatorGroupTypeRef *WM_manipulatorgrouptype_append_and_link(
+ wmManipulatorMapType *mmap_type,
+ void (*wtfunc)(struct wmManipulatorGroupType *))
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_append(wtfunc);
+
+ wgt->mmap_params.spaceid = mmap_type->spaceid;
+ wgt->mmap_params.regionid = mmap_type->regionid;
+
+ return WM_manipulatormaptype_group_link_ptr(mmap_type, wgt);
+}
+
+/**
+ * Free but don't remove from ghash.
+ */
+static void manipulatorgrouptype_free(wmManipulatorGroupType *wgt)
+{
+ if (wgt->ext.srna) { /* python manipulator group, allocs own string */
+ MEM_freeN((void *)wgt->idname);
+ }
+
+ MEM_freeN(wgt);
+}
+
+void WM_manipulatorgrouptype_free_ptr(wmManipulatorGroupType *wgt)
+{
+ BLI_assert(wgt == WM_manipulatorgrouptype_find(wgt->idname, false));
+
+ BLI_ghash_remove(global_manipulatorgrouptype_hash, wgt->idname, NULL, NULL);
+
+ manipulatorgrouptype_free(wgt);
+
+ /* XXX, TODO, update the world! */
+}
+
+bool WM_manipulatorgrouptype_free(const char *idname)
+{
+ wmManipulatorGroupType *wgt = BLI_ghash_lookup(global_manipulatorgrouptype_hash, idname);
+
+ if (wgt == NULL) {
+ return false;
+ }
+
+ WM_manipulatorgrouptype_free_ptr(wgt);
+
+ return true;
+}
+
+static void wm_manipulatorgrouptype_ghash_free_cb(wmManipulatorGroupType *wgt)
+{
+ manipulatorgrouptype_free(wgt);
+}
+
+void wm_manipulatorgrouptype_free(void)
+{
+ BLI_ghash_free(global_manipulatorgrouptype_hash, NULL, (GHashValFreeFP)wm_manipulatorgrouptype_ghash_free_cb);
+ global_manipulatorgrouptype_hash = NULL;
+}
+
+/* called on initialize WM_init() */
+void wm_manipulatorgrouptype_init(void)
+{
+ /* reserve size is set based on blender default setup */
+ global_manipulatorgrouptype_hash = BLI_ghash_str_new_ex("wm_manipulatorgrouptype_init gh", 128);
+}
+
+/** \} */
+
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h b/source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h
new file mode 100644
index 00000000000..a131c6c5069
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_intern.h
@@ -0,0 +1,142 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator_intern.h
+ * \ingroup wm
+ */
+
+
+#ifndef __WM_MANIPULATOR_INTERN_H__
+#define __WM_MANIPULATOR_INTERN_H__
+
+struct wmKeyConfig;
+struct wmManipulatorMap;
+struct ManipulatorGeomInfo;
+struct GHashIterator;
+
+#include "wm_manipulator_fn.h"
+
+/* -------------------------------------------------------------------- */
+/* wmManipulator */
+
+
+bool wm_manipulator_select_set_ex(
+ struct wmManipulatorMap *mmap, struct wmManipulator *mpr, bool select,
+ bool use_array, bool use_callback);
+bool wm_manipulator_select_and_highlight(bContext *C, struct wmManipulatorMap *mmap, struct wmManipulator *mpr);
+
+void wm_manipulator_calculate_scale(struct wmManipulator *mpr, const bContext *C);
+void wm_manipulator_update(struct wmManipulator *mpr, const bContext *C, const bool refresh_map);
+
+int wm_manipulator_is_visible(struct wmManipulator *mpr);
+enum {
+ WM_MANIPULATOR_IS_VISIBLE_UPDATE = (1 << 0),
+ WM_MANIPULATOR_IS_VISIBLE_DRAW = (1 << 1),
+};
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorGroup */
+
+enum {
+ TWEAK_MODAL_CANCEL = 1,
+ TWEAK_MODAL_CONFIRM,
+ TWEAK_MODAL_PRECISION_ON,
+ TWEAK_MODAL_PRECISION_OFF,
+ TWEAK_MODAL_SNAP_ON,
+ TWEAK_MODAL_SNAP_OFF,
+};
+
+struct wmManipulatorGroup *wm_manipulatorgroup_new_from_type(
+ struct wmManipulatorMap *mmap, struct wmManipulatorGroupType *wgt);
+void wm_manipulatorgroup_free(bContext *C, struct wmManipulatorGroup *mgroup);
+void wm_manipulatorgroup_manipulator_register(struct wmManipulatorGroup *mgroup, struct wmManipulator *mpr);
+struct wmManipulator *wm_manipulatorgroup_find_intersected_manipulator(
+ const struct wmManipulatorGroup *mgroup, struct bContext *C, const struct wmEvent *event,
+ int *r_part);
+void wm_manipulatorgroup_intersectable_manipulators_to_list(
+ const struct wmManipulatorGroup *mgroup, struct ListBase *listbase);
+void wm_manipulatorgroup_ensure_initialized(struct wmManipulatorGroup *mgroup, const struct bContext *C);
+bool wm_manipulatorgroup_is_visible_in_drawstep(
+ const struct wmManipulatorGroup *mgroup, const eWM_ManipulatorMapDrawStep drawstep);
+
+void wm_manipulatorgrouptype_setup_keymap(
+ struct wmManipulatorGroupType *wgt, struct wmKeyConfig *keyconf);
+
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorMap */
+
+typedef struct wmManipulatorMapSelectState {
+ struct wmManipulator **items;
+ int len, len_alloc;
+} wmManipulatorMapSelectState;
+
+struct wmManipulatorMap {
+
+ struct wmManipulatorMapType *type;
+ ListBase groups; /* wmManipulatorGroup */
+
+ /* private, update tagging (enum defined in C source). */
+ char update_flag[WM_MANIPULATORMAP_DRAWSTEP_MAX];
+
+ /**
+ * \brief Manipulator map runtime context
+ *
+ * Contains information about this manipulator-map. Currently
+ * highlighted manipulator, currently selected manipulators, ...
+ */
+ struct {
+ /* we redraw the manipulator-map when this changes */
+ struct wmManipulator *highlight;
+ /* User has clicked this manipulator and it gets all input. */
+ struct wmManipulator *modal;
+ /* array for all selected manipulators */
+ struct wmManipulatorMapSelectState select;
+ /* cursor location at point of entering modal (see: WM_MANIPULATOR_GRAB_CURSOR) */
+ int event_xy[2];
+ short event_grabcursor;
+ } mmap_context;
+};
+
+/**
+ * This is a container for all manipulator types that can be instantiated in a region.
+ * (similar to dropboxes).
+ *
+ * \note There is only ever one of these for every (area, region) combination.
+ */
+struct wmManipulatorMapType {
+ struct wmManipulatorMapType *next, *prev;
+ short spaceid, regionid;
+ /* types of manipulator-groups for this manipulator-map type */
+ ListBase grouptype_refs;
+
+ /* eManipulatorMapTypeUpdateFlags */
+ eWM_ManipulatorMapTypeUpdateFlag type_update_flag;
+};
+
+void wm_manipulatormap_select_array_clear(struct wmManipulatorMap *mmap);
+bool wm_manipulatormap_deselect_all(struct wmManipulatorMap *mmap);
+void wm_manipulatormap_select_array_shrink(struct wmManipulatorMap *mmap, int len_subtract);
+void wm_manipulatormap_select_array_push_back(struct wmManipulatorMap *mmap, wmManipulator *mpr);
+void wm_manipulatormap_select_array_remove(struct wmManipulatorMap *mmap, wmManipulator *mpr);
+
+#endif
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
new file mode 100644
index 00000000000..1bb479774c2
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_map.c
@@ -0,0 +1,1191 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2014 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): Blender Foundation
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator_map.c
+ * \ingroup wm
+ */
+
+#include <string.h>
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_rect.h"
+#include "BLI_string.h"
+#include "BLI_ghash.h"
+
+#include "BKE_context.h"
+#include "BKE_global.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+#include "GPU_glew.h"
+#include "GPU_matrix.h"
+#include "GPU_select.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "wm_event_system.h"
+
+/* for tool-tips */
+#include "UI_interface.h"
+
+#include "DEG_depsgraph.h"
+
+/* own includes */
+#include "wm_manipulator_wmapi.h"
+#include "wm_manipulator_intern.h"
+
+/**
+ * Store all manipulator-maps here. Anyone who wants to register a manipulator for a certain
+ * area type can query the manipulator-map to do so.
+ */
+static ListBase manipulatormaptypes = {NULL, NULL};
+
+/**
+ * Update when manipulator-map types change.
+ */
+/* so operator removal can trigger update */
+typedef enum eWM_ManipulatorGroupTypeGlobalFlag {
+ WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_INIT = (1 << 0),
+ WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_REMOVE = (1 << 1),
+} eWM_ManipulatorGroupTypeGlobalFlag;
+
+static eWM_ManipulatorGroupTypeGlobalFlag wm_mmap_type_update_flag = 0;
+
+/**
+ * Manipulator-map update tagging.
+ */
+enum {
+ /** #manipulatormap_prepare_drawing has run */
+ MANIPULATORMAP_IS_PREPARE_DRAW = (1 << 0),
+ MANIPULATORMAP_IS_REFRESH_CALLBACK = (1 << 1),
+};
+
+
+/* -------------------------------------------------------------------- */
+/** \name wmManipulatorMap Selection Array API
+ *
+ * Just handle ``wm_manipulatormap_select_array_*``, not flags or callbacks.
+ *
+ * \{ */
+
+static void wm_manipulatormap_select_array_ensure_len_alloc(wmManipulatorMap *mmap, int len)
+{
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+ if (len <= msel->len_alloc) {
+ return;
+ }
+ msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * len);
+ msel->len_alloc = len;
+}
+
+void wm_manipulatormap_select_array_clear(wmManipulatorMap *mmap)
+{
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+ MEM_SAFE_FREE(msel->items);
+ msel->len = 0;
+ msel->len_alloc = 0;
+}
+
+void wm_manipulatormap_select_array_shrink(wmManipulatorMap *mmap, int len_subtract)
+{
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+ msel->len -= len_subtract;
+ if (msel->len <= 0) {
+ wm_manipulatormap_select_array_clear(mmap);
+ }
+ else {
+ if (msel->len < msel->len_alloc / 2) {
+ msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * msel->len);
+ msel->len_alloc = msel->len;
+ }
+ }
+}
+
+void wm_manipulatormap_select_array_push_back(wmManipulatorMap *mmap, wmManipulator *mpr)
+{
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+ BLI_assert(msel->len <= msel->len_alloc);
+ if (msel->len == msel->len_alloc) {
+ msel->len_alloc = (msel->len + 1) * 2;
+ msel->items = MEM_reallocN(msel->items, sizeof(*msel->items) * msel->len_alloc);
+ }
+ msel->items[msel->len++] = mpr;
+}
+
+void wm_manipulatormap_select_array_remove(wmManipulatorMap *mmap, wmManipulator *mpr)
+{
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+ /* remove manipulator from selected_manipulators array */
+ for (int i = 0; i < msel->len; i++) {
+ if (msel->items[i] == mpr) {
+ for (int j = i; j < (msel->len - 1); j++) {
+ msel->items[j] = msel->items[j + 1];
+ }
+ wm_manipulatormap_select_array_shrink(mmap, 1);
+ break;
+ }
+ }
+
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+/** \name wmManipulatorMap
+ *
+ * \{ */
+
+/**
+ * Creates a manipulator-map with all registered manipulators for that type
+ */
+wmManipulatorMap *WM_manipulatormap_new_from_type(
+ const struct wmManipulatorMapType_Params *mmap_params)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_ensure(mmap_params);
+ wmManipulatorMap *mmap;
+
+ mmap = MEM_callocN(sizeof(wmManipulatorMap), "ManipulatorMap");
+ mmap->type = mmap_type;
+ WM_manipulatormap_tag_refresh(mmap);
+
+ /* create all manipulator-groups for this manipulator-map. We may create an empty one
+ * too in anticipation of manipulators from operators etc */
+ for (wmManipulatorGroupTypeRef *wgt_ref = mmap_type->grouptype_refs.first; wgt_ref; wgt_ref = wgt_ref->next) {
+ wm_manipulatorgroup_new_from_type(mmap, wgt_ref->type);
+ }
+
+ return mmap;
+}
+
+void wm_manipulatormap_remove(wmManipulatorMap *mmap)
+{
+ /* Clear first so further calls don't waste time trying to maintain correct array state. */
+ wm_manipulatormap_select_array_clear(mmap);
+
+ for (wmManipulatorGroup *mgroup = mmap->groups.first, *mgroup_next; mgroup; mgroup = mgroup_next) {
+ mgroup_next = mgroup->next;
+ BLI_assert(mgroup->parent_mmap == mmap);
+ wm_manipulatorgroup_free(NULL, mgroup);
+ }
+ BLI_assert(BLI_listbase_is_empty(&mmap->groups));
+
+ MEM_freeN(mmap);
+}
+
+
+wmManipulatorGroup *WM_manipulatormap_group_find(
+ struct wmManipulatorMap *mmap,
+ const char *idname)
+{
+ wmManipulatorGroupType *wgt = WM_manipulatorgrouptype_find(idname, false);
+ if (wgt) {
+ return WM_manipulatormap_group_find_ptr(mmap, wgt);
+ }
+ return NULL;
+}
+
+wmManipulatorGroup *WM_manipulatormap_group_find_ptr(
+ struct wmManipulatorMap *mmap,
+ const struct wmManipulatorGroupType *wgt)
+{
+ for (wmManipulatorGroup *mgroup = mmap->groups.first; mgroup; mgroup = mgroup->next) {
+ if (mgroup->type == wgt) {
+ return mgroup;
+ }
+ }
+ return NULL;
+}
+
+const ListBase *WM_manipulatormap_group_list(wmManipulatorMap *mmap)
+{
+ return &mmap->groups;
+}
+
+bool WM_manipulatormap_is_any_selected(const wmManipulatorMap *mmap)
+{
+ return mmap->mmap_context.select.len != 0;
+}
+
+/**
+ * \note We could use a callback to define bounds, for now just use matrix location.
+ */
+bool WM_manipulatormap_minmax(
+ const wmManipulatorMap *mmap, bool UNUSED(use_hidden), bool use_select,
+ float r_min[3], float r_max[3])
+{
+ if (use_select) {
+ int i;
+ for (i = 0; i < mmap->mmap_context.select.len; i++) {
+ minmax_v3v3_v3(r_min, r_max, mmap->mmap_context.select.items[i]->matrix_basis[3]);
+ }
+ return i != 0;
+ }
+ else {
+ bool ok = false;
+ BLI_assert(!"TODO");
+ return ok;
+ }
+}
+
+/**
+ * Creates and returns idname hash table for (visible) manipulators in \a mmap
+ *
+ * \param poll Polling function for excluding manipulators.
+ * \param data Custom data passed to \a poll
+ *
+ * TODO(campbell): this uses unreliable order,
+ * best we use an iterator function instead of a hash.
+ */
+static GHash *WM_manipulatormap_manipulator_hash_new(
+ const bContext *C, wmManipulatorMap *mmap,
+ bool (*poll)(const wmManipulator *, void *),
+ void *data, const bool include_hidden)
+{
+ GHash *hash = BLI_ghash_ptr_new(__func__);
+
+ /* collect manipulators */
+ for (wmManipulatorGroup *mgroup = mmap->groups.first; mgroup; mgroup = mgroup->next) {
+ if (WM_manipulator_group_type_poll(C, mgroup->type)) {
+ for (wmManipulator *mpr = mgroup->manipulators.first; mpr; mpr = mpr->next) {
+ if ((include_hidden || (mpr->flag & WM_MANIPULATOR_HIDDEN) == 0) &&
+ (!poll || poll(mpr, data)))
+ {
+ BLI_ghash_insert(hash, mpr, mpr);
+ }
+ }
+ }
+ }
+
+ return hash;
+}
+
+void WM_manipulatormap_tag_refresh(wmManipulatorMap *mmap)
+{
+ if (mmap) {
+ /* We might want only to refresh some, for tag all steps. */
+ for (int i = 0; i < WM_MANIPULATORMAP_DRAWSTEP_MAX; i++) {
+ mmap->update_flag[i] |= (
+ MANIPULATORMAP_IS_PREPARE_DRAW |
+ MANIPULATORMAP_IS_REFRESH_CALLBACK);
+ }
+ }
+}
+
+static bool manipulator_prepare_drawing(
+ wmManipulatorMap *mmap, wmManipulator *mpr,
+ const bContext *C, ListBase *draw_manipulators,
+ const eWM_ManipulatorMapDrawStep drawstep)
+{
+ int do_draw = wm_manipulator_is_visible(mpr);
+ if (do_draw == 0) {
+ /* skip */
+ }
+ else {
+ /* Ensure we get RNA updates */
+ if (do_draw & WM_MANIPULATOR_IS_VISIBLE_UPDATE) {
+ /* hover manipulators need updating, even if we don't draw them */
+ wm_manipulator_update(mpr, C, (mmap->update_flag[drawstep] & MANIPULATORMAP_IS_PREPARE_DRAW) != 0);
+ }
+ if (do_draw & WM_MANIPULATOR_IS_VISIBLE_DRAW) {
+ BLI_addhead(draw_manipulators, BLI_genericNodeN(mpr));
+ }
+ return true;
+ }
+
+ return false;
+}
+
+/**
+ * Update manipulators of \a mmap to prepare for drawing. Adds all manipulators that
+ * should be drawn to list \a draw_manipulators, note that added items need freeing.
+ */
+static void manipulatormap_prepare_drawing(
+ wmManipulatorMap *mmap, const bContext *C, ListBase *draw_manipulators,
+ const eWM_ManipulatorMapDrawStep drawstep)
+{
+ if (!mmap || BLI_listbase_is_empty(&mmap->groups))
+ return;
+ wmManipulator *mpr_modal = mmap->mmap_context.modal;
+
+ /* only active manipulator needs updating */
+ if (mpr_modal) {
+ if ((mpr_modal->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_DRAW_MODAL_ALL) == 0) {
+ if (wm_manipulatorgroup_is_visible_in_drawstep(mpr_modal->parent_mgroup, drawstep)) {
+ if (manipulator_prepare_drawing(mmap, mpr_modal, C, draw_manipulators, drawstep)) {
+ mmap->update_flag[drawstep] &= ~MANIPULATORMAP_IS_PREPARE_DRAW;
+ }
+ }
+ /* don't draw any other manipulators */
+ return;
+ }
+ }
+
+ for (wmManipulatorGroup *mgroup = mmap->groups.first; mgroup; mgroup = mgroup->next) {
+ /* check group visibility - drawstep first to avoid unnecessary call of group poll callback */
+ if (!wm_manipulatorgroup_is_visible_in_drawstep(mgroup, drawstep) ||
+ !WM_manipulator_group_type_poll(C, mgroup->type))
+ {
+ continue;
+ }
+
+ /* needs to be initialized on first draw */
+ /* XXX weak: Manipulator-group may skip refreshing if it's invisible (map gets untagged nevertheless) */
+ if (mmap->update_flag[drawstep] & MANIPULATORMAP_IS_REFRESH_CALLBACK) {
+ /* force refresh again. */
+ mgroup->init_flag &= ~WM_MANIPULATORGROUP_INIT_REFRESH;
+ }
+ /* Calls `setup`, `setup_keymap` and `refresh` if they're defined. */
+ wm_manipulatorgroup_ensure_initialized(mgroup, C);
+
+ /* prepare drawing */
+ if (mgroup->type->draw_prepare) {
+ mgroup->type->draw_prepare(C, mgroup);
+ }
+
+ for (wmManipulator *mpr = mgroup->manipulators.first; mpr; mpr = mpr->next) {
+ manipulator_prepare_drawing(mmap, mpr, C, draw_manipulators, drawstep);
+ }
+ }
+
+ mmap->update_flag[drawstep] &=
+ ~(MANIPULATORMAP_IS_REFRESH_CALLBACK |
+ MANIPULATORMAP_IS_PREPARE_DRAW);
+}
+
+/**
+ * Draw all visible manipulators in \a mmap.
+ * Uses global draw_manipulators listbase.
+ */
+static void manipulators_draw_list(const wmManipulatorMap *mmap, const bContext *C, ListBase *draw_manipulators)
+{
+ /* Can be empty if we're dynamically added and removed. */
+ if ((mmap == NULL) || BLI_listbase_is_empty(&mmap->groups)) {
+ return;
+ }
+
+ /* TODO this will need it own shader probably? don't think it can be handled from that point though. */
+/* const bool use_lighting = (U.manipulator_flag & V3D_MANIPULATOR_SHADED) != 0; */
+
+ bool is_depth_prev = false;
+
+ /* draw_manipulators contains all visible manipulators - draw them */
+ for (LinkData *link = draw_manipulators->first, *link_next; link; link = link_next) {
+ wmManipulator *mpr = link->data;
+ link_next = link->next;
+
+ bool is_depth = (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_DEPTH_3D) != 0;
+
+ /* Weak! since we don't 100% support depth yet (select ignores depth) always show highlighted */
+ if (is_depth && (mpr->state & WM_MANIPULATOR_STATE_HIGHLIGHT)) {
+ is_depth = false;
+ }
+
+ if (is_depth == is_depth_prev) {
+ /* pass */
+ }
+ else {
+ if (is_depth) {
+ glEnable(GL_DEPTH_TEST);
+ }
+ else {
+ glDisable(GL_DEPTH_TEST);
+ }
+ is_depth_prev = is_depth;
+ }
+
+ /* XXX force AntiAlias Manipulators. */
+ glEnable(GL_LINE_SMOOTH);
+ glEnable(GL_POLYGON_SMOOTH);
+
+ mpr->type->draw(C, mpr);
+
+ glDisable(GL_LINE_SMOOTH);
+ glDisable(GL_POLYGON_SMOOTH);
+
+ /* free/remove manipulator link after drawing */
+ BLI_freelinkN(draw_manipulators, link);
+ }
+
+ if (is_depth_prev) {
+ glDisable(GL_DEPTH_TEST);
+ }
+}
+
+void WM_manipulatormap_draw(
+ wmManipulatorMap *mmap, const bContext *C,
+ const eWM_ManipulatorMapDrawStep drawstep)
+{
+ if (!WM_manipulator_context_check_drawstep(C, drawstep)) {
+ return;
+ }
+
+ ListBase draw_manipulators = {NULL};
+
+ manipulatormap_prepare_drawing(mmap, C, &draw_manipulators, drawstep);
+ manipulators_draw_list(mmap, C, &draw_manipulators);
+ BLI_assert(BLI_listbase_is_empty(&draw_manipulators));
+}
+
+static void manipulator_draw_select_3D_loop(const bContext *C, ListBase *visible_manipulators)
+{
+ int select_id = 0;
+ wmManipulator *mpr;
+
+ /* TODO(campbell): this depends on depth buffer being written to, currently broken for the 3D view. */
+ bool is_depth_prev = false;
+
+ for (LinkData *link = visible_manipulators->first; link; link = link->next) {
+ mpr = link->data;
+
+ bool is_depth = (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_DEPTH_3D) != 0;
+ if (is_depth == is_depth_prev) {
+ /* pass */
+ }
+ else {
+ if (is_depth) {
+ glEnable(GL_DEPTH_TEST);
+ }
+ else {
+ glDisable(GL_DEPTH_TEST);
+ }
+ is_depth_prev = is_depth;
+ }
+
+ /* pass the selection id shifted by 8 bits. Last 8 bits are used for selected manipulator part id */
+
+ mpr->type->draw_select(C, mpr, select_id << 8);
+
+
+ select_id++;
+ }
+
+ if (is_depth_prev) {
+ glDisable(GL_DEPTH_TEST);
+ }
+}
+
+static int manipulator_find_intersected_3d_intern(
+ ListBase *visible_manipulators, const bContext *C, const int co[2],
+ const int hotspot)
+{
+ ScrArea *sa = CTX_wm_area(C);
+ ARegion *ar = CTX_wm_region(C);
+ View3D *v3d = sa->spacedata.first;
+ rcti rect;
+ /* Almost certainly overkill, but allow for many custom manipulators. */
+ GLuint buffer[MAXPICKBUF];
+ short hits;
+ const bool do_passes = GPU_select_query_check_active();
+
+ BLI_rcti_init_pt_radius(&rect, co, hotspot);
+
+ ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, &rect);
+
+ if (do_passes)
+ GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_NEAREST_FIRST_PASS, 0);
+ else
+ GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_ALL, 0);
+ /* do the drawing */
+ manipulator_draw_select_3D_loop(C, visible_manipulators);
+
+ hits = GPU_select_end();
+
+ if (do_passes && (hits > 0)) {
+ GPU_select_begin(buffer, ARRAY_SIZE(buffer), &rect, GPU_SELECT_NEAREST_SECOND_PASS, hits);
+ manipulator_draw_select_3D_loop(C, visible_manipulators);
+ GPU_select_end();
+ }
+
+ ED_view3d_draw_setup_view(CTX_wm_window(C), CTX_data_depsgraph(C), CTX_data_scene(C), ar, v3d, NULL, NULL, NULL);
+
+ const GLuint *hit_near = GPU_select_buffer_near(buffer, hits);
+
+ return hit_near ? hit_near[3] : -1;
+}
+
+/**
+ * Try to find a 3D manipulator at screen-space coordinate \a co. Uses OpenGL picking.
+ */
+static wmManipulator *manipulator_find_intersected_3d(
+ bContext *C, const int co[2], ListBase *visible_manipulators,
+ int *r_part)
+{
+ wmManipulator *result = NULL;
+ int hit = -1;
+
+ int hotspot_radii[] = {
+ 3 * U.pixelsize,
+#if 0 /* We may want to enable when selection doesn't run on mousemove! */
+ 7 * U.pixelsize,
+#endif
+ };
+
+ *r_part = 0;
+
+ /* set up view matrices */
+ view3d_operator_needs_opengl(C);
+
+ hit = -1;
+
+ for (int i = 0; i < ARRAY_SIZE(hotspot_radii); i++) {
+ hit = manipulator_find_intersected_3d_intern(visible_manipulators, C, co, hotspot_radii[i]);
+ if (hit != -1) {
+ break;
+ }
+ }
+
+ if (hit != -1) {
+ LinkData *link = BLI_findlink(visible_manipulators, hit >> 8);
+ if (link != NULL) {
+ *r_part = hit & 255;
+ result = link->data;
+ }
+ else {
+ /* All manipulators should use selection ID they're given as part of the callback,
+ * if they don't it will attempt tp lookup non-existing index. */
+ BLI_assert(0);
+ }
+ }
+
+ return result;
+}
+
+/**
+ * Try to find a manipulator under the mouse position. 2D intersections have priority over
+ * 3D ones (could check for smallest screen-space distance but not needed right now).
+ */
+wmManipulator *wm_manipulatormap_highlight_find(
+ wmManipulatorMap *mmap, bContext *C, const wmEvent *event,
+ int *r_part)
+{
+ wmManipulator *mpr = NULL;
+ ListBase visible_3d_manipulators = {NULL};
+ bool do_step[WM_MANIPULATORMAP_DRAWSTEP_MAX];
+
+ for (int i = 0; i < ARRAY_SIZE(do_step); i++) {
+ do_step[i] = WM_manipulator_context_check_drawstep(C, i);
+ }
+
+ for (wmManipulatorGroup *mgroup = mmap->groups.first; mgroup; mgroup = mgroup->next) {
+
+ /* If it were important we could initialize here,
+ * but this only happens when events are handled before drawing,
+ * just skip to keep code-path for initializing manipulators simple. */
+ if ((mgroup->init_flag & WM_MANIPULATORGROUP_INIT_SETUP) == 0) {
+ continue;
+ }
+
+ if (WM_manipulator_group_type_poll(C, mgroup->type)) {
+ eWM_ManipulatorMapDrawStep step;
+ if (mgroup->type->flag & WM_MANIPULATORGROUPTYPE_3D) {
+ step = WM_MANIPULATORMAP_DRAWSTEP_3D;
+ }
+ else {
+ step = WM_MANIPULATORMAP_DRAWSTEP_2D;
+ }
+
+ if (do_step[step]) {
+ if ((mmap->update_flag[step] & MANIPULATORMAP_IS_REFRESH_CALLBACK) &&
+ (mgroup->type->refresh != NULL))
+ {
+ mgroup->type->refresh(C, mgroup);
+ /* cleared below */
+ }
+ if (step == WM_MANIPULATORMAP_DRAWSTEP_3D) {
+ wm_manipulatorgroup_intersectable_manipulators_to_list(mgroup, &visible_3d_manipulators);
+ }
+ else if (step == WM_MANIPULATORMAP_DRAWSTEP_2D) {
+ if ((mpr = wm_manipulatorgroup_find_intersected_manipulator(mgroup, C, event, r_part))) {
+ break;
+ }
+ }
+ }
+ }
+ }
+
+ if (!BLI_listbase_is_empty(&visible_3d_manipulators)) {
+ /* 2D manipulators get priority. */
+ if (mpr == NULL) {
+ mpr = manipulator_find_intersected_3d(C, event->mval, &visible_3d_manipulators, r_part);
+ }
+ BLI_freelistN(&visible_3d_manipulators);
+ }
+
+ mmap->update_flag[WM_MANIPULATORMAP_DRAWSTEP_3D] &= ~MANIPULATORMAP_IS_REFRESH_CALLBACK;
+ mmap->update_flag[WM_MANIPULATORMAP_DRAWSTEP_2D] &= ~MANIPULATORMAP_IS_REFRESH_CALLBACK;
+
+ return mpr;
+}
+
+void WM_manipulatormap_add_handlers(ARegion *ar, wmManipulatorMap *mmap)
+{
+ wmEventHandler *handler;
+
+ for (handler = ar->handlers.first; handler; handler = handler->next) {
+ if (handler->manipulator_map == mmap) {
+ return;
+ }
+ }
+
+ handler = MEM_callocN(sizeof(wmEventHandler), "manipulator handler");
+
+ BLI_assert(mmap == ar->manipulator_map);
+ handler->manipulator_map = mmap;
+ BLI_addtail(&ar->handlers, handler);
+}
+
+void wm_manipulatormaps_handled_modal_update(
+ bContext *C, wmEvent *event, wmEventHandler *handler)
+{
+ const bool modal_running = (handler->op != NULL);
+
+ /* happens on render or when joining areas */
+ if (!handler->op_region || !handler->op_region->manipulator_map) {
+ return;
+ }
+
+ wmManipulatorMap *mmap = handler->op_region->manipulator_map;
+ wmManipulator *mpr = wm_manipulatormap_modal_get(mmap);
+ ScrArea *area = CTX_wm_area(C);
+ ARegion *region = CTX_wm_region(C);
+
+ wm_manipulatormap_handler_context(C, handler);
+
+ /* regular update for running operator */
+ if (modal_running) {
+ wmManipulatorOpElem *mpop = mpr ? WM_manipulator_operator_get(mpr, mpr->highlight_part) : NULL;
+ if (mpr && mpop && (mpop->type != NULL) && (mpop->type == handler->op->type)) {
+ wmManipulatorFnModal modal_fn = mpr->custom_modal ? mpr->custom_modal : mpr->type->modal;
+ if (modal_fn != NULL) {
+ int retval = modal_fn(C, mpr, event, 0);
+ /* The manipulator is tried to the operator, we can't choose when to exit. */
+ BLI_assert(retval & OPERATOR_RUNNING_MODAL);
+ UNUSED_VARS_NDEBUG(retval);
+ }
+ }
+ }
+ /* operator not running anymore */
+ else {
+ wm_manipulatormap_highlight_set(mmap, C, NULL, 0);
+ if (mpr) {
+ /* This isn't defined if it ends because of success of cancel, we may want to change. */
+ bool cancel = true;
+ if (mpr->type->exit) {
+ mpr->type->exit(C, mpr, cancel);
+ }
+ wm_manipulatormap_modal_set(mmap, C, mpr, NULL, false);
+ }
+ }
+
+ /* restore the area */
+ CTX_wm_area_set(C, area);
+ CTX_wm_region_set(C, region);
+}
+
+/**
+ * Deselect all selected manipulators in \a mmap.
+ * \return if selection has changed.
+ */
+bool wm_manipulatormap_deselect_all(wmManipulatorMap *mmap)
+{
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+
+ if (msel->items == NULL || msel->len == 0) {
+ return false;
+ }
+
+ for (int i = 0; i < msel->len; i++) {
+ wm_manipulator_select_set_ex(mmap, msel->items[i], false, false, true);
+ }
+
+ wm_manipulatormap_select_array_clear(mmap);
+
+ /* always return true, we already checked
+ * if there's anything to deselect */
+ return true;
+}
+
+BLI_INLINE bool manipulator_selectable_poll(const wmManipulator *mpr, void *UNUSED(data))
+{
+ return (mpr->parent_mgroup->type->flag & WM_MANIPULATORGROUPTYPE_SELECT);
+}
+
+/**
+ * Select all selectable manipulators in \a mmap.
+ * \return if selection has changed.
+ */
+static bool wm_manipulatormap_select_all_intern(
+ bContext *C, wmManipulatorMap *mmap)
+{
+ wmManipulatorMapSelectState *msel = &mmap->mmap_context.select;
+ /* GHash is used here to avoid having to loop over all manipulators twice (once to
+ * get tot_sel for allocating, once for actually selecting). Instead we collect
+ * selectable manipulators in hash table and use this to get tot_sel and do selection */
+
+ GHash *hash = WM_manipulatormap_manipulator_hash_new(C, mmap, manipulator_selectable_poll, NULL, true);
+ GHashIterator gh_iter;
+ int i;
+ bool changed = false;
+
+ wm_manipulatormap_select_array_ensure_len_alloc(mmap, BLI_ghash_len(hash));
+
+ GHASH_ITER_INDEX (gh_iter, hash, i) {
+ wmManipulator *mpr_iter = BLI_ghashIterator_getValue(&gh_iter);
+ WM_manipulator_select_set(mmap, mpr_iter, true);
+ }
+ /* highlight first manipulator */
+ wm_manipulatormap_highlight_set(mmap, C, msel->items[0], msel->items[0]->highlight_part);
+
+ BLI_assert(BLI_ghash_len(hash) == msel->len);
+
+ BLI_ghash_free(hash, NULL, NULL);
+ return changed;
+}
+
+/**
+ * Select/Deselect all selectable manipulators in \a mmap.
+ * \return if selection has changed.
+ *
+ * TODO select all by type
+ */
+bool WM_manipulatormap_select_all(bContext *C, wmManipulatorMap *mmap, const int action)
+{
+ bool changed = false;
+
+ switch (action) {
+ case SEL_SELECT:
+ changed = wm_manipulatormap_select_all_intern(C, mmap);
+ break;
+ case SEL_DESELECT:
+ changed = wm_manipulatormap_deselect_all(mmap);
+ break;
+ default:
+ BLI_assert(0);
+ break;
+ }
+
+ if (changed)
+ WM_event_add_mousemove(C);
+
+ return changed;
+}
+
+/**
+ * Prepare context for manipulator handling (but only if area/region is
+ * part of screen). Version of #wm_handler_op_context for manipulators.
+ */
+void wm_manipulatormap_handler_context(bContext *C, wmEventHandler *handler)
+{
+ bScreen *screen = CTX_wm_screen(C);
+
+ if (screen) {
+ if (handler->op_area == NULL) {
+ /* do nothing in this context */
+ }
+ else {
+ ScrArea *sa;
+
+ for (sa = screen->areabase.first; sa; sa = sa->next)
+ if (sa == handler->op_area)
+ break;
+ if (sa == NULL) {
+ /* when changing screen layouts with running modal handlers (like render display), this
+ * is not an error to print */
+ if (handler->manipulator_map == NULL)
+ printf("internal error: modal manipulator-map handler has invalid area\n");
+ }
+ else {
+ ARegion *ar;
+ CTX_wm_area_set(C, sa);
+ for (ar = sa->regionbase.first; ar; ar = ar->next)
+ if (ar == handler->op_region)
+ break;
+ /* XXX no warning print here, after full-area and back regions are remade */
+ if (ar)
+ CTX_wm_region_set(C, ar);
+ }
+ }
+ }
+}
+
+bool WM_manipulatormap_cursor_set(const wmManipulatorMap *mmap, wmWindow *win)
+{
+ wmManipulator *mpr = mmap->mmap_context.highlight;
+ if (mpr && mpr->type->cursor_get) {
+ WM_cursor_set(win, mpr->type->cursor_get(mpr));
+ return true;
+ }
+
+ return false;
+}
+
+void wm_manipulatormap_highlight_set(
+ wmManipulatorMap *mmap, const bContext *C, wmManipulator *mpr, int part)
+{
+ if ((mpr != mmap->mmap_context.highlight) ||
+ (mpr && part != mpr->highlight_part))
+ {
+ if (mmap->mmap_context.highlight) {
+ mmap->mmap_context.highlight->state &= ~WM_MANIPULATOR_STATE_HIGHLIGHT;
+ mmap->mmap_context.highlight->highlight_part = -1;
+ }
+
+ mmap->mmap_context.highlight = mpr;
+
+ if (mpr) {
+ mpr->state |= WM_MANIPULATOR_STATE_HIGHLIGHT;
+ mpr->highlight_part = part;
+
+ if (C && mpr->type->cursor_get) {
+ wmWindow *win = CTX_wm_window(C);
+ WM_cursor_set(win, mpr->type->cursor_get(mpr));
+ }
+ }
+ else {
+ if (C) {
+ wmWindow *win = CTX_wm_window(C);
+ WM_cursor_set(win, CURSOR_STD);
+ }
+ }
+
+ /* tag the region for redraw */
+ if (C) {
+ ARegion *ar = CTX_wm_region(C);
+ ED_region_tag_redraw(ar);
+ }
+ }
+}
+
+wmManipulator *wm_manipulatormap_highlight_get(wmManipulatorMap *mmap)
+{
+ return mmap->mmap_context.highlight;
+}
+
+/**
+ * Caller should call exit when (enable == False).
+ */
+void wm_manipulatormap_modal_set(
+ wmManipulatorMap *mmap, bContext *C, wmManipulator *mpr, const wmEvent *event, bool enable)
+{
+ if (enable) {
+ BLI_assert(mmap->mmap_context.modal == NULL);
+ wmWindow *win = CTX_wm_window(C);
+
+ WM_tooltip_clear(C, win);
+
+ if (mpr->type->invoke &&
+ (mpr->type->modal || mpr->custom_modal))
+ {
+ const int retval = mpr->type->invoke(C, mpr, event);
+ if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
+ return;
+ }
+ }
+
+ mpr->state |= WM_MANIPULATOR_STATE_MODAL;
+ mmap->mmap_context.modal = mpr;
+
+ if ((mpr->flag & WM_MANIPULATOR_GRAB_CURSOR) &&
+ (event->is_motion_absolute == false))
+ {
+ WM_cursor_grab_enable(win, true, true, NULL);
+ copy_v2_v2_int(mmap->mmap_context.event_xy, &event->x);
+ mmap->mmap_context.event_grabcursor = win->grabcursor;
+ }
+ else {
+ mmap->mmap_context.event_xy[0] = INT_MAX;
+ }
+
+ struct wmManipulatorOpElem *mpop = WM_manipulator_operator_get(mpr, mpr->highlight_part);
+ if (mpop && mpop->type) {
+ const int retval = WM_operator_name_call_ptr(C, mpop->type, WM_OP_INVOKE_DEFAULT, &mpop->ptr);
+ if ((retval & OPERATOR_RUNNING_MODAL) == 0) {
+ wm_manipulatormap_modal_set(mmap, C, mpr, event, false);
+ }
+
+ /* we failed to hook the manipulator to the operator handler or operator was cancelled, return */
+ if (!mmap->mmap_context.modal) {
+ mpr->state &= ~WM_MANIPULATOR_STATE_MODAL;
+ MEM_SAFE_FREE(mpr->interaction_data);
+ }
+ return;
+ }
+ }
+ else {
+ BLI_assert(ELEM(mmap->mmap_context.modal, NULL, mpr));
+
+ /* deactivate, manipulator but first take care of some stuff */
+ if (mpr) {
+ mpr->state &= ~WM_MANIPULATOR_STATE_MODAL;
+ MEM_SAFE_FREE(mpr->interaction_data);
+ }
+ mmap->mmap_context.modal = NULL;
+
+ if (C) {
+ wmWindow *win = CTX_wm_window(C);
+ if (mmap->mmap_context.event_xy[0] != INT_MAX) {
+ /* Check if some other part of Blender (typically operators)
+ * have adjusted the grab mode since it was set.
+ * If so: warp, so we have a predictable outcome. */
+ if (mmap->mmap_context.event_grabcursor == win->grabcursor) {
+ WM_cursor_grab_disable(win, mmap->mmap_context.event_xy);
+ }
+ else {
+ WM_cursor_warp(win, UNPACK2(mmap->mmap_context.event_xy));
+ }
+ }
+ ED_region_tag_redraw(CTX_wm_region(C));
+ WM_event_add_mousemove(C);
+ }
+
+ mmap->mmap_context.event_xy[0] = INT_MAX;
+ }
+}
+
+wmManipulator *wm_manipulatormap_modal_get(wmManipulatorMap *mmap)
+{
+ return mmap->mmap_context.modal;
+}
+
+wmManipulator **wm_manipulatormap_selected_get(wmManipulatorMap *mmap, int *r_selected_len)
+{
+ *r_selected_len = mmap->mmap_context.select.len;
+ return mmap->mmap_context.select.items;
+}
+
+ListBase *wm_manipulatormap_groups_get(wmManipulatorMap *mmap)
+{
+ return &mmap->groups;
+}
+
+void WM_manipulatormap_message_subscribe(
+ bContext *C, wmManipulatorMap *mmap, ARegion *ar, struct wmMsgBus *mbus)
+{
+ for (wmManipulatorGroup *mgroup = mmap->groups.first; mgroup; mgroup = mgroup->next) {
+ if (!WM_manipulator_group_type_poll(C, mgroup->type)) {
+ continue;
+ }
+ for (wmManipulator *mpr = mgroup->manipulators.first; mpr; mpr = mpr->next) {
+ if (mpr->flag & WM_MANIPULATOR_HIDDEN) {
+ continue;
+ }
+ WM_manipulator_target_property_subscribe_all(mpr, mbus, ar);
+ }
+ if (mgroup->type->message_subscribe != NULL) {
+ mgroup->type->message_subscribe(C, mgroup, mbus);
+ }
+ }
+}
+
+/** \} */ /* wmManipulatorMap */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Tooltip Handling
+ *
+ * \{ */
+
+struct ARegion *WM_manipulatormap_tooltip_init(
+ struct bContext *C, struct ARegion *ar, bool *r_exit_on_event)
+{
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ *r_exit_on_event = true;
+ if (mmap) {
+ wmManipulator *mpr = mmap->mmap_context.highlight;
+ if (mpr) {
+ return UI_tooltip_create_from_manipulator(C, mpr);
+ }
+ }
+ return NULL;
+}
+
+/** \} */ /* wmManipulatorMapType */
+
+/* -------------------------------------------------------------------- */
+/** \name wmManipulatorMapType
+ *
+ * \{ */
+
+wmManipulatorMapType *WM_manipulatormaptype_find(
+ const struct wmManipulatorMapType_Params *mmap_params)
+{
+ for (wmManipulatorMapType *mmap_type = manipulatormaptypes.first; mmap_type; mmap_type = mmap_type->next) {
+ if (mmap_type->spaceid == mmap_params->spaceid &&
+ mmap_type->regionid == mmap_params->regionid)
+ {
+ return mmap_type;
+ }
+ }
+
+ return NULL;
+}
+
+wmManipulatorMapType *WM_manipulatormaptype_ensure(
+ const struct wmManipulatorMapType_Params *mmap_params)
+{
+ wmManipulatorMapType *mmap_type = WM_manipulatormaptype_find(mmap_params);
+
+ if (mmap_type) {
+ return mmap_type;
+ }
+
+ mmap_type = MEM_callocN(sizeof(wmManipulatorMapType), "manipulatortype list");
+ mmap_type->spaceid = mmap_params->spaceid;
+ mmap_type->regionid = mmap_params->regionid;
+ BLI_addhead(&manipulatormaptypes, mmap_type);
+
+ return mmap_type;
+}
+
+void wm_manipulatormaptypes_free(void)
+{
+ for (wmManipulatorMapType *mmap_type = manipulatormaptypes.first, *mmap_type_next;
+ mmap_type;
+ mmap_type = mmap_type_next)
+ {
+ mmap_type_next = mmap_type->next;
+ for (wmManipulatorGroupTypeRef *wgt_ref = mmap_type->grouptype_refs.first, *wgt_next;
+ wgt_ref;
+ wgt_ref = wgt_next)
+ {
+ wgt_next = wgt_ref->next;
+ WM_manipulatormaptype_group_free(wgt_ref);
+ }
+ MEM_freeN(mmap_type);
+ }
+}
+
+/**
+ * Initialize keymaps for all existing manipulator-groups
+ */
+void wm_manipulators_keymap(wmKeyConfig *keyconf)
+{
+ /* we add this item-less keymap once and use it to group manipulator-group keymaps into it */
+ WM_keymap_find(keyconf, "Manipulators", 0, 0);
+
+ for (wmManipulatorMapType *mmap_type = manipulatormaptypes.first; mmap_type; mmap_type = mmap_type->next) {
+ for (wmManipulatorGroupTypeRef *wgt_ref = mmap_type->grouptype_refs.first; wgt_ref; wgt_ref = wgt_ref->next) {
+ wm_manipulatorgrouptype_setup_keymap(wgt_ref->type, keyconf);
+ }
+ }
+}
+
+/** \} */ /* wmManipulatorMapType */
+
+/* -------------------------------------------------------------------- */
+/** \name Updates for Dynamic Type Registraion
+ *
+ * \{ */
+
+
+void WM_manipulatorconfig_update_tag_init(
+ wmManipulatorMapType *mmap_type, wmManipulatorGroupType *wgt)
+{
+ /* tag for update on next use */
+ mmap_type->type_update_flag |= (WM_MANIPULATORMAPTYPE_UPDATE_INIT | WM_MANIPULATORMAPTYPE_KEYMAP_INIT);
+ wgt->type_update_flag |= (WM_MANIPULATORMAPTYPE_UPDATE_INIT | WM_MANIPULATORMAPTYPE_KEYMAP_INIT);
+
+ wm_mmap_type_update_flag |= WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_INIT;
+}
+
+void WM_manipulatorconfig_update_tag_remove(
+ wmManipulatorMapType *mmap_type, wmManipulatorGroupType *wgt)
+{
+ /* tag for update on next use */
+ mmap_type->type_update_flag |= WM_MANIPULATORMAPTYPE_UPDATE_REMOVE;
+ wgt->type_update_flag |= WM_MANIPULATORMAPTYPE_UPDATE_REMOVE;
+
+ wm_mmap_type_update_flag |= WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_REMOVE;
+}
+
+/**
+ * Run incase new types have been added (runs often, early exit where possible).
+ * Follows #WM_keyconfig_update concentions.
+ */
+void WM_manipulatorconfig_update(struct Main *bmain)
+{
+ if (G.background)
+ return;
+
+ if (wm_mmap_type_update_flag == 0)
+ return;
+
+ if (wm_mmap_type_update_flag & WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_REMOVE) {
+ for (wmManipulatorMapType *mmap_type = manipulatormaptypes.first;
+ mmap_type;
+ mmap_type = mmap_type->next)
+ {
+ if (mmap_type->type_update_flag & WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_REMOVE) {
+ mmap_type->type_update_flag &= ~WM_MANIPULATORMAPTYPE_UPDATE_REMOVE;
+ for (wmManipulatorGroupTypeRef *wgt_ref = mmap_type->grouptype_refs.first, *wgt_ref_next;
+ wgt_ref;
+ wgt_ref = wgt_ref_next)
+ {
+ wgt_ref_next = wgt_ref->next;
+ if (wgt_ref->type->type_update_flag & WM_MANIPULATORMAPTYPE_UPDATE_REMOVE) {
+ WM_manipulatormaptype_group_unlink(NULL, bmain, mmap_type, wgt_ref->type);
+ }
+ }
+ }
+ }
+
+ wm_mmap_type_update_flag &= ~WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_REMOVE;
+ }
+
+ if (wm_mmap_type_update_flag & WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_INIT) {
+ for (wmManipulatorMapType *mmap_type = manipulatormaptypes.first;
+ mmap_type;
+ mmap_type = mmap_type->next)
+ {
+ const uchar type_update_all = WM_MANIPULATORMAPTYPE_UPDATE_INIT | WM_MANIPULATORMAPTYPE_KEYMAP_INIT;
+ if (mmap_type->type_update_flag & type_update_all) {
+ mmap_type->type_update_flag &= ~type_update_all;
+ for (wmManipulatorGroupTypeRef *wgt_ref = mmap_type->grouptype_refs.first;
+ wgt_ref;
+ wgt_ref = wgt_ref->next)
+ {
+ if (wgt_ref->type->type_update_flag & WM_MANIPULATORMAPTYPE_KEYMAP_INIT) {
+ WM_manipulatormaptype_group_init_runtime_keymap(bmain, wgt_ref->type);
+ wgt_ref->type->type_update_flag &= ~WM_MANIPULATORMAPTYPE_KEYMAP_INIT;
+ }
+
+ if (wgt_ref->type->type_update_flag & WM_MANIPULATORMAPTYPE_UPDATE_INIT) {
+ WM_manipulatormaptype_group_init_runtime(bmain, mmap_type, wgt_ref->type);
+ wgt_ref->type->type_update_flag &= ~WM_MANIPULATORMAPTYPE_UPDATE_INIT;
+ }
+ }
+ }
+ }
+
+ wm_mmap_type_update_flag &= ~WM_MANIPULATORMAPTYPE_GLOBAL_UPDATE_INIT;
+ }
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c
new file mode 100644
index 00000000000..137e8f5639d
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c
@@ -0,0 +1,364 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator_target_props.c
+ * \ingroup wm
+ */
+
+#include "BLI_listbase.h"
+#include "BLI_math.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_context.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+#include "WM_message.h"
+
+#include "wm.h"
+
+#include "ED_screen.h"
+#include "ED_view3d.h"
+
+/* own includes */
+#include "wm_manipulator_wmapi.h"
+#include "wm_manipulator_intern.h"
+
+/* -------------------------------------------------------------------- */
+
+/** \name Property Definition
+ * \{ */
+
+BLI_INLINE wmManipulatorProperty *wm_manipulator_target_property_array(wmManipulator *mpr)
+{
+ return (wmManipulatorProperty *)(POINTER_OFFSET(mpr, mpr->type->struct_size));
+}
+
+wmManipulatorProperty *WM_manipulator_target_property_array(wmManipulator *mpr)
+{
+ return wm_manipulator_target_property_array(mpr);
+}
+
+wmManipulatorProperty *WM_manipulator_target_property_at_index(wmManipulator *mpr, int index)
+{
+ BLI_assert(index < mpr->type->target_property_defs_len);
+ BLI_assert(index != -1);
+ wmManipulatorProperty *mpr_prop_array = wm_manipulator_target_property_array(mpr);
+ return &mpr_prop_array[index];
+}
+
+wmManipulatorProperty *WM_manipulator_target_property_find(wmManipulator *mpr, const char *idname)
+{
+ int index = BLI_findstringindex(
+ &mpr->type->target_property_defs, idname, offsetof(wmManipulatorPropertyType, idname));
+ if (index != -1) {
+ return WM_manipulator_target_property_at_index(mpr, index);
+ }
+ else {
+ return NULL;
+ }
+}
+
+void WM_manipulator_target_property_def_rna_ptr(
+ wmManipulator *mpr, const wmManipulatorPropertyType *mpr_prop_type,
+ PointerRNA *ptr, PropertyRNA *prop, int index)
+{
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_at_index(mpr, mpr_prop_type->index_in_type);
+
+ /* if manipulator evokes an operator we cannot use it for property manipulation */
+ BLI_assert(mpr->op_data == NULL);
+
+ mpr_prop->type = mpr_prop_type;
+
+ mpr_prop->ptr = *ptr;
+ mpr_prop->prop = prop;
+ mpr_prop->index = index;
+
+ if (mpr->type->property_update) {
+ mpr->type->property_update(mpr, mpr_prop);
+ }
+}
+
+void WM_manipulator_target_property_def_rna(
+ wmManipulator *mpr, const char *idname,
+ PointerRNA *ptr, const char *propname, int index)
+{
+ const wmManipulatorPropertyType *mpr_prop_type = WM_manipulatortype_target_property_find(mpr->type, idname);
+ PropertyRNA *prop = RNA_struct_find_property(ptr, propname);
+ WM_manipulator_target_property_def_rna_ptr(mpr, mpr_prop_type, ptr, prop, index);
+}
+
+void WM_manipulator_target_property_def_func_ptr(
+ wmManipulator *mpr, const wmManipulatorPropertyType *mpr_prop_type,
+ const wmManipulatorPropertyFnParams *params)
+{
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_at_index(mpr, mpr_prop_type->index_in_type);
+
+ /* if manipulator evokes an operator we cannot use it for property manipulation */
+ BLI_assert(mpr->op_data == NULL);
+
+ mpr_prop->type = mpr_prop_type;
+
+ mpr_prop->custom_func.value_get_fn = params->value_get_fn;
+ mpr_prop->custom_func.value_set_fn = params->value_set_fn;
+ mpr_prop->custom_func.range_get_fn = params->range_get_fn;
+ mpr_prop->custom_func.free_fn = params->free_fn;
+ mpr_prop->custom_func.user_data = params->user_data;
+
+ if (mpr->type->property_update) {
+ mpr->type->property_update(mpr, mpr_prop);
+ }
+}
+
+void WM_manipulator_target_property_def_func(
+ wmManipulator *mpr, const char *idname,
+ const wmManipulatorPropertyFnParams *params)
+{
+ const wmManipulatorPropertyType *mpr_prop_type = WM_manipulatortype_target_property_find(mpr->type, idname);
+ WM_manipulator_target_property_def_func_ptr(mpr, mpr_prop_type, params);
+}
+
+void WM_manipulator_target_property_clear_rna_ptr(
+ wmManipulator *mpr, const wmManipulatorPropertyType *mpr_prop_type)
+{
+ wmManipulatorProperty *mpr_prop = WM_manipulator_target_property_at_index(mpr, mpr_prop_type->index_in_type);
+
+ /* if manipulator evokes an operator we cannot use it for property manipulation */
+ BLI_assert(mpr->op_data == NULL);
+
+ mpr_prop->type = NULL;
+
+ mpr_prop->ptr = PointerRNA_NULL;
+ mpr_prop->prop = NULL;
+ mpr_prop->index = -1;
+}
+
+void WM_manipulator_target_property_clear_rna(
+ wmManipulator *mpr, const char *idname)
+{
+ const wmManipulatorPropertyType *mpr_prop_type = WM_manipulatortype_target_property_find(mpr->type, idname);
+ WM_manipulator_target_property_clear_rna_ptr(mpr, mpr_prop_type);
+}
+
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Property Access
+ * \{ */
+
+bool WM_manipulator_target_property_is_valid_any(wmManipulator *mpr)
+{
+ wmManipulatorProperty *mpr_prop_array = wm_manipulator_target_property_array(mpr);
+ for (int i = 0; i < mpr->type->target_property_defs_len; i++) {
+ wmManipulatorProperty *mpr_prop = &mpr_prop_array[i];
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ return true;
+ }
+ }
+ return false;
+}
+
+bool WM_manipulator_target_property_is_valid(const wmManipulatorProperty *mpr_prop)
+{
+ return ((mpr_prop->prop != NULL) ||
+ (mpr_prop->custom_func.value_get_fn && mpr_prop->custom_func.value_set_fn));
+}
+
+float WM_manipulator_target_property_value_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop)
+{
+ if (mpr_prop->custom_func.value_get_fn) {
+ float value = 0.0f;
+ BLI_assert(mpr_prop->type->array_length == 1);
+ mpr_prop->custom_func.value_get_fn(mpr, mpr_prop, &value);
+ return value;
+ }
+
+ if (mpr_prop->index == -1) {
+ return RNA_property_float_get(&mpr_prop->ptr, mpr_prop->prop);
+ }
+ else {
+ return RNA_property_float_get_index(&mpr_prop->ptr, mpr_prop->prop, mpr_prop->index);
+ }
+}
+
+void WM_manipulator_target_property_value_set(
+ bContext *C, const wmManipulator *mpr,
+ wmManipulatorProperty *mpr_prop, const float value)
+{
+ if (mpr_prop->custom_func.value_set_fn) {
+ BLI_assert(mpr_prop->type->array_length == 1);
+ mpr_prop->custom_func.value_set_fn(mpr, mpr_prop, &value);
+ return;
+ }
+
+ /* reset property */
+ if (mpr_prop->index == -1) {
+ RNA_property_float_set(&mpr_prop->ptr, mpr_prop->prop, value);
+ }
+ else {
+ RNA_property_float_set_index(&mpr_prop->ptr, mpr_prop->prop, mpr_prop->index, value);
+ }
+ RNA_property_update(C, &mpr_prop->ptr, mpr_prop->prop);
+}
+
+void WM_manipulator_target_property_value_get_array(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ float *value)
+{
+ if (mpr_prop->custom_func.value_get_fn) {
+ mpr_prop->custom_func.value_get_fn(mpr, mpr_prop, value);
+ return;
+ }
+ RNA_property_float_get_array(&mpr_prop->ptr, mpr_prop->prop, value);
+}
+
+void WM_manipulator_target_property_value_set_array(
+ bContext *C, const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ const float *value)
+{
+ if (mpr_prop->custom_func.value_set_fn) {
+ mpr_prop->custom_func.value_set_fn(mpr, mpr_prop, value);
+ return;
+ }
+ RNA_property_float_set_array(&mpr_prop->ptr, mpr_prop->prop, value);
+
+ RNA_property_update(C, &mpr_prop->ptr, mpr_prop->prop);
+}
+
+bool WM_manipulator_target_property_range_get(
+ const wmManipulator *mpr, wmManipulatorProperty *mpr_prop,
+ float range[2])
+{
+ if (mpr_prop->custom_func.value_get_fn) {
+ if (mpr_prop->custom_func.range_get_fn) {
+ mpr_prop->custom_func.range_get_fn(mpr, mpr_prop, range);
+ return true;
+ }
+ else {
+ return false;
+
+ }
+ }
+
+ float step, precision;
+ RNA_property_float_ui_range(&mpr_prop->ptr, mpr_prop->prop, &range[0], &range[1], &step, &precision);
+ return true;
+}
+
+int WM_manipulator_target_property_array_length(
+ const wmManipulator *UNUSED(mpr), wmManipulatorProperty *mpr_prop)
+{
+ if (mpr_prop->custom_func.value_get_fn) {
+ return mpr_prop->type->array_length;
+ }
+ return RNA_property_array_length(&mpr_prop->ptr, mpr_prop->prop);
+}
+
+/** \} */
+
+
+/* -------------------------------------------------------------------- */
+
+/** \name Property Define
+ * \{ */
+
+const wmManipulatorPropertyType *WM_manipulatortype_target_property_find(
+ const wmManipulatorType *wt, const char *idname)
+{
+ return BLI_findstring(&wt->target_property_defs, idname, offsetof(wmManipulatorPropertyType, idname));
+}
+
+void WM_manipulatortype_target_property_def(
+ wmManipulatorType *wt, const char *idname, int data_type, int array_length)
+{
+ wmManipulatorPropertyType *mpt;
+
+ BLI_assert(WM_manipulatortype_target_property_find(wt, idname) == NULL);
+
+ const uint idname_size = strlen(idname) + 1;
+ mpt = MEM_callocN(sizeof(wmManipulatorPropertyType) + idname_size, __func__);
+ memcpy(mpt->idname, idname, idname_size);
+ mpt->data_type = data_type;
+ mpt->array_length = array_length;
+ mpt->index_in_type = wt->target_property_defs_len;
+ wt->target_property_defs_len += 1;
+ BLI_addtail(&wt->target_property_defs, mpt);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+
+/** \name Property Utilities
+ * \{ */
+
+void WM_manipulator_do_msg_notify_tag_refresh(
+ bContext *UNUSED(C), wmMsgSubscribeKey *UNUSED(msg_key), wmMsgSubscribeValue *msg_val)
+{
+ ARegion *ar = msg_val->owner;
+ wmManipulatorMap *mmap = msg_val->user_data;
+
+ ED_region_tag_redraw(ar);
+ WM_manipulatormap_tag_refresh(mmap);
+}
+
+/**
+ * Runs on the "prepare draw" pass,
+ * drawing the region clears.
+ */
+void WM_manipulator_target_property_subscribe_all(
+ wmManipulator *mpr, struct wmMsgBus *mbus, ARegion *ar)
+{
+ if (mpr->type->target_property_defs_len) {
+ wmManipulatorProperty *mpr_prop_array = WM_manipulator_target_property_array(mpr);
+ for (int i = 0; i < mpr->type->target_property_defs_len; i++) {
+ wmManipulatorProperty *mpr_prop = &mpr_prop_array[i];
+ if (WM_manipulator_target_property_is_valid(mpr_prop)) {
+ if (mpr_prop->prop) {
+ WM_msg_subscribe_rna(
+ mbus, &mpr_prop->ptr, mpr_prop->prop,
+ &(const wmMsgSubscribeValue){
+ .owner = ar,
+ .user_data = ar,
+ .notify = ED_region_do_msg_notify_tag_redraw,
+ }, __func__);
+ WM_msg_subscribe_rna(
+ mbus, &mpr_prop->ptr, mpr_prop->prop,
+ &(const wmMsgSubscribeValue){
+ .owner = ar,
+ .user_data = mpr->parent_mgroup->parent_mmap,
+ .notify = WM_manipulator_do_msg_notify_tag_refresh,
+ }, __func__);
+ }
+ }
+ }
+ }
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c b/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
new file mode 100644
index 00000000000..fd7f31db903
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/intern/wm_manipulator_type.c
@@ -0,0 +1,212 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/intern/wm_manipulator_type.c
+ * \ingroup wm
+ */
+
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+#include "BLI_string.h"
+#include "BLI_string_utils.h"
+
+#include "BKE_context.h"
+#include "BKE_main.h"
+
+#include "DNA_screen_types.h"
+#include "DNA_space_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "RNA_access.h"
+#include "RNA_define.h"
+
+#include "WM_api.h"
+#include "WM_types.h"
+
+#include "ED_screen.h"
+
+/* only for own init/exit calls (wm_manipulatortype_init/wm_manipulatortype_free) */
+#include "wm.h"
+
+/* own includes */
+#include "wm_manipulator_wmapi.h"
+#include "wm_manipulator_intern.h"
+
+
+/** \name Manipulator Type Append
+ *
+ * \note This follows conventions from #WM_operatortype_find #WM_operatortype_append & friends.
+ * \{ */
+
+static GHash *global_manipulatortype_hash = NULL;
+
+const wmManipulatorType *WM_manipulatortype_find(const char *idname, bool quiet)
+{
+ if (idname[0]) {
+ wmManipulatorType *wt;
+
+ wt = BLI_ghash_lookup(global_manipulatortype_hash, idname);
+ if (wt) {
+ return wt;
+ }
+
+ if (!quiet) {
+ printf("search for unknown manipulator '%s'\n", idname);
+ }
+ }
+ else {
+ if (!quiet) {
+ printf("search for empty manipulator\n");
+ }
+ }
+
+ return NULL;
+}
+
+/* caller must free */
+void WM_manipulatortype_iter(GHashIterator *ghi)
+{
+ BLI_ghashIterator_init(ghi, global_manipulatortype_hash);
+}
+
+static wmManipulatorType *wm_manipulatortype_append__begin(void)
+{
+ wmManipulatorType *wt = MEM_callocN(sizeof(wmManipulatorType), "manipulatortype");
+ wt->srna = RNA_def_struct_ptr(&BLENDER_RNA, "", &RNA_ManipulatorProperties);
+#if 0
+ /* Set the default i18n context now, so that opfunc can redefine it if needed! */
+ RNA_def_struct_translation_context(ot->srna, BLT_I18NCONTEXT_OPERATOR_DEFAULT);
+ ot->translation_context = BLT_I18NCONTEXT_OPERATOR_DEFAULT;
+#endif
+ return wt;
+}
+static void wm_manipulatortype_append__end(wmManipulatorType *wt)
+{
+ BLI_assert(wt->struct_size >= sizeof(wmManipulator));
+
+ RNA_def_struct_identifier(&BLENDER_RNA, wt->srna, wt->idname);
+
+ BLI_ghash_insert(global_manipulatortype_hash, (void *)wt->idname, wt);
+}
+
+void WM_manipulatortype_append(void (*wtfunc)(struct wmManipulatorType *))
+{
+ wmManipulatorType *wt = wm_manipulatortype_append__begin();
+ wtfunc(wt);
+ wm_manipulatortype_append__end(wt);
+}
+
+void WM_manipulatortype_append_ptr(void (*wtfunc)(struct wmManipulatorType *, void *), void *userdata)
+{
+ wmManipulatorType *mt = wm_manipulatortype_append__begin();
+ wtfunc(mt, userdata);
+ wm_manipulatortype_append__end(mt);
+}
+
+/**
+ * Free but don't remove from ghash.
+ */
+static void manipulatortype_free(wmManipulatorType *wt)
+{
+ if (wt->ext.srna) { /* python manipulator, allocs own string */
+ MEM_freeN((void *)wt->idname);
+ }
+
+ BLI_freelistN(&wt->target_property_defs);
+ MEM_freeN(wt);
+}
+
+/**
+ * \param C: May be NULL.
+ */
+static void manipulatortype_unlink(
+ bContext *C, Main *bmain, wmManipulatorType *wt)
+{
+ /* Free instances. */
+ for (bScreen *sc = bmain->screen.first; sc; sc = sc->id.next) {
+ for (ScrArea *sa = sc->areabase.first; sa; sa = sa->next) {
+ for (SpaceLink *sl = sa->spacedata.first; sl; sl = sl->next) {
+ ListBase *lb = (sl == sa->spacedata.first) ? &sa->regionbase : &sl->regionbase;
+ for (ARegion *ar = lb->first; ar; ar = ar->next) {
+ wmManipulatorMap *mmap = ar->manipulator_map;
+ if (mmap) {
+ wmManipulatorGroup *mgroup;
+ for (mgroup = mmap->groups.first; mgroup; mgroup = mgroup->next) {
+ for (wmManipulator *mpr = mgroup->manipulators.first, *mpr_next; mpr; mpr = mpr_next) {
+ mpr_next = mpr->next;
+ BLI_assert(mgroup->parent_mmap == mmap);
+ if (mpr->type == wt) {
+ WM_manipulator_unlink(&mgroup->manipulators, mgroup->parent_mmap, mpr, C);
+ ED_region_tag_redraw(ar);
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+ }
+}
+
+void WM_manipulatortype_remove_ptr(bContext *C, Main *bmain, wmManipulatorType *wt)
+{
+ BLI_assert(wt == WM_manipulatortype_find(wt->idname, false));
+
+ BLI_ghash_remove(global_manipulatortype_hash, wt->idname, NULL, NULL);
+
+ manipulatortype_unlink(C, bmain, wt);
+
+ manipulatortype_free(wt);
+}
+
+bool WM_manipulatortype_remove(bContext *C, Main *bmain, const char *idname)
+{
+ wmManipulatorType *wt = BLI_ghash_lookup(global_manipulatortype_hash, idname);
+
+ if (wt == NULL) {
+ return false;
+ }
+
+ WM_manipulatortype_remove_ptr(C, bmain, wt);
+
+ return true;
+}
+
+static void wm_manipulatortype_ghash_free_cb(wmManipulatorType *mt)
+{
+ manipulatortype_free(mt);
+}
+
+void wm_manipulatortype_free(void)
+{
+ BLI_ghash_free(global_manipulatortype_hash, NULL, (GHashValFreeFP)wm_manipulatortype_ghash_free_cb);
+ global_manipulatortype_hash = NULL;
+}
+
+/* called on initialize WM_init() */
+void wm_manipulatortype_init(void)
+{
+ /* reserve size is set based on blender default setup */
+ global_manipulatortype_hash = BLI_ghash_str_new_ex("wm_manipulatortype_init gh", 128);
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_fn.h b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
new file mode 100644
index 00000000000..305d04eab68
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/wm_manipulator_fn.h
@@ -0,0 +1,88 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/wm_manipulator_fn.h
+ * \ingroup wm
+ *
+ * Callback function definitions, needed for both Types & API headers.
+ */
+
+#ifndef __WM_MANIPULATOR_FN_H__
+#define __WM_MANIPULATOR_FN_H__
+
+#include "BLI_compiler_attrs.h"
+
+/* wmManipulatorGroup */
+typedef bool (*wmManipulatorGroupFnPoll)(
+ const struct bContext *, struct wmManipulatorGroupType *)
+ ATTR_WARN_UNUSED_RESULT;
+typedef void (*wmManipulatorGroupFnInit)(
+ const struct bContext *, struct wmManipulatorGroup *);
+typedef void (*wmManipulatorGroupFnRefresh)(
+ const struct bContext *, struct wmManipulatorGroup *);
+typedef void (*wmManipulatorGroupFnDrawPrepare)(
+ const struct bContext *, struct wmManipulatorGroup *);
+typedef struct wmKeyMap *(*wmManipulatorGroupFnSetupKeymap)(
+ const struct wmManipulatorGroupType *, struct wmKeyConfig *)
+ ATTR_WARN_UNUSED_RESULT;
+typedef void (*wmManipulatorGroupFnMsgBusSubscribe)(
+ const struct bContext *, struct wmManipulatorGroup *, struct wmMsgBus *);
+
+/* wmManipulator */
+/* See: wmManipulatorType for docs on each type. */
+
+typedef void (*wmManipulatorFnSetup)(struct wmManipulator *);
+typedef void (*wmManipulatorFnDraw)(const struct bContext *, struct wmManipulator *);
+typedef void (*wmManipulatorFnDrawSelect)(const struct bContext *, struct wmManipulator *, int);
+typedef int (*wmManipulatorFnTestSelect)(struct bContext *, struct wmManipulator *, const struct wmEvent *);
+typedef int (*wmManipulatorFnModal)(struct bContext *, struct wmManipulator *, const struct wmEvent *, eWM_ManipulatorTweak);
+typedef void (*wmManipulatorFnPropertyUpdate)(struct wmManipulator *, struct wmManipulatorProperty *);
+typedef void (*wmManipulatorFnMatrixBasisGet)(const struct wmManipulator *, float[4][4]);
+typedef int (*wmManipulatorFnInvoke)(struct bContext *, struct wmManipulator *, const struct wmEvent *);
+typedef void (*wmManipulatorFnExit)(struct bContext *, struct wmManipulator *, const bool);
+typedef int (*wmManipulatorFnCursorGet)(struct wmManipulator *);
+typedef void (*wmManipulatorFnSelectRefresh)(struct wmManipulator *);
+typedef void (*wmManipulatorFnFree)(struct wmManipulator *);
+
+/* wmManipulatorProperty ('value' type defined by 'wmManipulatorProperty.data_type') */
+typedef void (*wmManipulatorPropertyFnGet)(
+ const struct wmManipulator *, struct wmManipulatorProperty *,
+ /* typically 'float *' */
+ void *value);
+typedef void (*wmManipulatorPropertyFnSet)(
+ const struct wmManipulator *, struct wmManipulatorProperty *,
+ /* typically 'const float *' */
+ const void *value);
+typedef void (*wmManipulatorPropertyFnRangeGet)(
+ const struct wmManipulator *, struct wmManipulatorProperty *,
+ /* typically 'float[2]' */
+ void *range);
+typedef void (*wmManipulatorPropertyFnFree)(
+ const struct wmManipulator *, struct wmManipulatorProperty *);
+
+typedef struct wmManipulatorPropertyFnParams {
+ wmManipulatorPropertyFnGet value_get_fn;
+ wmManipulatorPropertyFnSet value_set_fn;
+ wmManipulatorPropertyFnRangeGet range_get_fn;
+ wmManipulatorPropertyFnFree free_fn;
+ void *user_data;
+} wmManipulatorPropertyFnParams;
+
+#endif /* __WM_MANIPULATOR_FN_H__ */
diff --git a/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h b/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h
new file mode 100644
index 00000000000..87cf711a60b
--- /dev/null
+++ b/source/blender/windowmanager/manipulators/wm_manipulator_wmapi.h
@@ -0,0 +1,98 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/manipulators/wm_manipulator_wmapi.h
+ * \ingroup wm
+ *
+ * \name Manipulators Window Manager API
+ * API for usage in window manager code only. It should contain all functionality
+ * needed to hook up the manipulator system with Blender's window manager. It's
+ * mostly the event system that needs to communicate with manipulator code.
+ *
+ * Only included in wm.h and lower level files.
+ */
+
+
+#ifndef __WM_MANIPULATOR_WMAPI_H__
+#define __WM_MANIPULATOR_WMAPI_H__
+
+struct wmEventHandler;
+struct wmManipulatorMap;
+struct wmOperatorType;
+struct wmOperator;
+
+
+/* -------------------------------------------------------------------- */
+/* wmManipulator */
+
+/* wm_manipulator_type.c, for init/exit */
+void wm_manipulatortype_free(void);
+void wm_manipulatortype_init(void);
+
+/* wm_manipulatorgroup_type.c, for init/exit */
+void wm_manipulatorgrouptype_free(void);
+void wm_manipulatorgrouptype_init(void);
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorGroup */
+
+void MANIPULATORGROUP_OT_manipulator_select(struct wmOperatorType *ot);
+void MANIPULATORGROUP_OT_manipulator_tweak(struct wmOperatorType *ot);
+
+bool wm_manipulatorgroup_is_any_selected(const struct wmManipulatorGroup *mgroup);
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorMap */
+
+void wm_manipulatormap_remove(struct wmManipulatorMap *mmap);
+
+void wm_manipulators_keymap(struct wmKeyConfig *keyconf);
+
+void wm_manipulatormaps_handled_modal_update(
+ bContext *C, struct wmEvent *event, struct wmEventHandler *handler);
+void wm_manipulatormap_handler_context(bContext *C, struct wmEventHandler *handler);
+
+struct wmManipulator *wm_manipulatormap_highlight_find(
+ struct wmManipulatorMap *mmap, bContext *C, const struct wmEvent *event,
+ int *r_part);
+void wm_manipulatormap_highlight_set(
+ struct wmManipulatorMap *mmap, const bContext *C,
+ struct wmManipulator *mpr, int part);
+struct wmManipulator *wm_manipulatormap_highlight_get(struct wmManipulatorMap *mmap);
+void wm_manipulatormap_modal_set(
+ struct wmManipulatorMap *mmap, bContext *C, struct wmManipulator *mpr,
+ const struct wmEvent *event, bool enable);
+
+struct wmManipulator *wm_manipulatormap_modal_get(struct wmManipulatorMap *mmap);
+struct wmManipulator **wm_manipulatormap_selected_get(wmManipulatorMap *mmap, int *r_selected_len);
+struct ListBase *wm_manipulatormap_groups_get(wmManipulatorMap *mmap);
+
+/* -------------------------------------------------------------------- */
+/* wmManipulatorMapType */
+
+void wm_manipulatormaptypes_free(void);
+
+#endif /* __WM_MANIPULATOR_WMAPI_H__ */
+
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus.c b/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
new file mode 100644
index 00000000000..06a9c2de69b
--- /dev/null
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus.c
@@ -0,0 +1,250 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/message_bus/intern/wm_message_bus.c
+ * \ingroup wm
+ */
+
+#include <string.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_listbase.h"
+
+#include "BLI_ghash.h"
+
+#include "WM_types.h"
+
+#include "MEM_guardedalloc.h"
+
+#include "message_bus/wm_message_bus.h"
+#include "message_bus/intern/wm_message_bus_intern.h"
+
+/* -------------------------------------------------------------------------- */
+/** \name Public API
+ * \{ */
+
+static wmMsgTypeInfo wm_msg_types[WM_MSG_TYPE_NUM] = {{{NULL}}};
+
+typedef void (*wmMsgTypeInitFn)(wmMsgTypeInfo *);
+
+static wmMsgTypeInitFn wm_msg_init_fn[WM_MSG_TYPE_NUM] = {
+ WM_msgtypeinfo_init_rna,
+ WM_msgtypeinfo_init_static,
+};
+
+void WM_msgbus_types_init(void)
+{
+ for (uint i = 0; i < WM_MSG_TYPE_NUM; i++) {
+ wm_msg_init_fn[i](&wm_msg_types[i]);
+ }
+}
+
+struct wmMsgBus *WM_msgbus_create(void)
+{
+ struct wmMsgBus *mbus = MEM_callocN(sizeof(*mbus), __func__);
+ const uint gset_reserve = 512;
+ for (uint i = 0; i < WM_MSG_TYPE_NUM; i++) {
+ wmMsgTypeInfo *info = &wm_msg_types[i];
+ mbus->messages_gset[i] = BLI_gset_new_ex(info->gset.hash_fn, info->gset.cmp_fn, __func__, gset_reserve);
+ }
+ return mbus;
+}
+
+void WM_msgbus_destroy(struct wmMsgBus *mbus)
+{
+ for (uint i = 0; i < WM_MSG_TYPE_NUM; i++) {
+ wmMsgTypeInfo *info = &wm_msg_types[i];
+ BLI_gset_free(mbus->messages_gset[i], info->gset.key_free_fn);
+ }
+ MEM_freeN(mbus);
+}
+
+void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner)
+{
+ wmMsgSubscribeKey *msg_key, *msg_key_next;
+ for (msg_key = mbus->messages.first; msg_key; msg_key = msg_key_next) {
+ msg_key_next = msg_key->next;
+
+ wmMsgSubscribeValueLink *msg_lnk_next;
+ for (wmMsgSubscribeValueLink *msg_lnk = msg_key->values.first; msg_lnk; msg_lnk = msg_lnk_next) {
+ msg_lnk_next = msg_lnk->next;
+ if (msg_lnk->params.owner == owner) {
+ if (msg_lnk->params.tag) {
+ mbus->messages_tag_count -= 1;
+ }
+ if (msg_lnk->params.free_data) {
+ msg_lnk->params.free_data(msg_key, &msg_lnk->params);
+ }
+ BLI_remlink(&msg_key->values, msg_lnk);
+ MEM_freeN(msg_lnk);
+ }
+ }
+
+ if (BLI_listbase_is_empty(&msg_key->values)) {
+ const wmMsg *msg = wm_msg_subscribe_value_msg_cast(msg_key);
+ wmMsgTypeInfo *info = &wm_msg_types[msg->type];
+ BLI_remlink(&mbus->messages, msg_key);
+ bool ok = BLI_gset_remove(mbus->messages_gset[msg->type], msg_key, info->gset.key_free_fn);
+ BLI_assert(ok);
+ UNUSED_VARS_NDEBUG(ok);
+ }
+ }
+}
+
+void WM_msg_dump(struct wmMsgBus *mbus, const char *info_str)
+{
+ printf(">>>> %s\n", info_str);
+ for (wmMsgSubscribeKey *key = mbus->messages.first; key; key = key->next) {
+ const wmMsg *msg = wm_msg_subscribe_value_msg_cast(key);
+ const wmMsgTypeInfo *info = &wm_msg_types[msg->type];
+ info->repr(stdout, key);
+ }
+ printf("<<<< %s\n", info_str);
+}
+
+void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C)
+{
+ if (mbus->messages_tag_count == 0) {
+ // printf("msgbus: skipping\n");
+ return;
+ }
+
+ if (false) {
+ WM_msg_dump(mbus, __func__);
+ }
+
+ // uint a = 0, b = 0;
+ for (wmMsgSubscribeKey *key = mbus->messages.first; key; key = key->next) {
+ for (wmMsgSubscribeValueLink *msg_lnk = key->values.first; msg_lnk; msg_lnk = msg_lnk->next) {
+ if (msg_lnk->params.tag) {
+ msg_lnk->params.notify(C, key, &msg_lnk->params);
+ msg_lnk->params.tag = false;
+ mbus->messages_tag_count -= 1;
+ }
+ // b++;
+ }
+ // a++;
+ }
+ BLI_assert(mbus->messages_tag_count == 0);
+ mbus->messages_tag_count = 0;
+ // printf("msgbus: keys=%u values=%u\n", a, b);
+}
+
+/**
+ * \param msg_key_test: Needs following #wmMsgSubscribeKey fields filled in:
+ * - msg.params
+ * - msg.head.type
+ * - msg.head.id
+ * .. other values should be zeroed.
+ *
+ * \return The key for this subscription.
+ * note that this is only needed in rare cases when the key needs further manipulation.
+ */
+wmMsgSubscribeKey *WM_msg_subscribe_with_key(
+ struct wmMsgBus *mbus,
+ const wmMsgSubscribeKey *msg_key_test,
+ const wmMsgSubscribeValue *msg_val_params)
+{
+ const uint type = wm_msg_subscribe_value_msg_cast(msg_key_test)->type;
+ const wmMsgTypeInfo *info = &wm_msg_types[type];
+ wmMsgSubscribeKey *key;
+
+ BLI_assert(wm_msg_subscribe_value_msg_cast(msg_key_test)->id != NULL);
+
+ void **r_key;
+ if (!BLI_gset_ensure_p_ex(mbus->messages_gset[type], msg_key_test, &r_key)) {
+ key = *r_key = MEM_mallocN(info->msg_key_size, __func__);
+ memcpy(key, msg_key_test, info->msg_key_size);
+ BLI_addtail(&mbus->messages, key);
+ }
+ else {
+ key = *r_key;
+ for (wmMsgSubscribeValueLink *msg_lnk = key->values.first; msg_lnk; msg_lnk = msg_lnk->next) {
+ if ((msg_lnk->params.notify == msg_val_params->notify) &&
+ (msg_lnk->params.owner == msg_val_params->owner) &&
+ (msg_lnk->params.user_data == msg_val_params->user_data))
+ {
+ return key;
+ }
+ }
+ }
+
+ wmMsgSubscribeValueLink *msg_lnk = MEM_mallocN(sizeof(wmMsgSubscribeValueLink), __func__);
+ msg_lnk->params = *msg_val_params;
+ BLI_addtail(&key->values, msg_lnk);
+ return key;
+}
+
+void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key)
+{
+ for (wmMsgSubscribeValueLink *msg_lnk = msg_key->values.first; msg_lnk; msg_lnk = msg_lnk->next) {
+ if (false) { /* make an option? */
+ msg_lnk->params.notify(NULL, msg_key, &msg_lnk->params);
+ }
+ else {
+ if (msg_lnk->params.tag == false) {
+ msg_lnk->params.tag = true;
+ mbus->messages_tag_count += 1;
+ }
+ }
+ }
+}
+
+void WM_msg_id_update(
+ struct wmMsgBus *mbus,
+ struct ID *id_src, struct ID *id_dst)
+{
+ for (uint i = 0; i < WM_MSG_TYPE_NUM; i++) {
+ wmMsgTypeInfo *info = &wm_msg_types[i];
+ if (info->update_by_id != NULL) {
+ info->update_by_id(mbus, id_src, id_dst);
+ }
+ }
+}
+
+void WM_msg_id_remove(struct wmMsgBus *mbus, const struct ID *id)
+{
+ for (uint i = 0; i < WM_MSG_TYPE_NUM; i++) {
+ wmMsgTypeInfo *info = &wm_msg_types[i];
+ if (info->remove_by_id != NULL) {
+ info->remove_by_id(mbus, id);
+ }
+ }
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------------- */
+/** \name Internal API
+ *
+ * \note While we could have a separate type for ID's, use RNA since there is enough overlap.
+ * \{ */
+
+void wm_msg_subscribe_value_free(
+ wmMsgSubscribeKey *msg_key, wmMsgSubscribeValueLink *msg_lnk)
+{
+ if (msg_lnk->params.free_data) {
+ msg_lnk->params.free_data(msg_key, &msg_lnk->params);
+ }
+ BLI_remlink(&msg_key->values, msg_lnk);
+ MEM_freeN(msg_lnk);
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h
new file mode 100644
index 00000000000..db8b481a3c2
--- /dev/null
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_intern.h
@@ -0,0 +1,55 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/message_bus/intern/wm_message_bus_intern.h
+ * \ingroup wm
+ */
+
+#ifndef __WM_MESSAGE_BUS_INTERN_H__
+#define __WM_MESSAGE_BUS_INTERN_H__
+
+/* wm_message_bus.h must be included first */
+
+struct wmMsgBus {
+ struct GSet *messages_gset[WM_MSG_TYPE_NUM];
+ /** Messages in order of being added. */
+ ListBase messages;
+ /** Avoid checking messages when no tags exist. */
+ uint messages_tag_count;
+};
+
+void wm_msg_subscribe_value_free(
+ struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValueLink *msg_lnk);
+
+typedef struct wmMsgSubscribeKey_Generic {
+ wmMsgSubscribeKey head;
+ wmMsg msg;
+} wmMsgSubscribeKey_Generic;
+
+BLI_INLINE const wmMsg *wm_msg_subscribe_value_msg_cast(const wmMsgSubscribeKey *key)
+{
+ return &((wmMsgSubscribeKey_Generic *)key)->msg;
+}
+BLI_INLINE wmMsg *wm_msg_subscribe_value_msg_cast_mut(wmMsgSubscribeKey *key)
+{
+ return &((wmMsgSubscribeKey_Generic *)key)->msg;
+}
+
+#endif /* __WM_MESSAGE_BUS_INTERN_H__ */
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c b/source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c
new file mode 100644
index 00000000000..67b96f3d8b3
--- /dev/null
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_rna.c
@@ -0,0 +1,316 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/message_bus/intern/wm_message_bus_rna.c
+ * \ingroup wm
+ */
+
+
+#include <stdio.h>
+#include "DNA_ID.h"
+
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+
+#include "WM_types.h"
+#include "WM_message.h"
+#include "message_bus/intern/wm_message_bus_intern.h"
+
+#include "RNA_access.h"
+
+#include "MEM_guardedalloc.h"
+
+/* -------------------------------------------------------------------------- */
+
+BLI_INLINE uint void_hash_uint(const void *key)
+{
+ size_t y = (size_t)key >> (sizeof(void *));
+ return (unsigned int)y;
+}
+
+static uint wm_msg_rna_gset_hash(const void *key_p)
+{
+ const wmMsgSubscribeKey_RNA *key = key_p;
+ const wmMsgParams_RNA *params = &key->msg.params;
+// printf("%s\n", RNA_struct_identifier(params->ptr.type));
+ uint k = void_hash_uint(params->ptr.type);
+ k ^= void_hash_uint(params->ptr.data);
+ k ^= void_hash_uint(params->ptr.id.data);
+ k ^= void_hash_uint(params->prop);
+ return k;
+}
+static bool wm_msg_rna_gset_cmp(const void *key_a_p, const void *key_b_p)
+{
+ const wmMsgParams_RNA *params_a = &((const wmMsgSubscribeKey_RNA *)key_a_p)->msg.params;
+ const wmMsgParams_RNA *params_b = &((const wmMsgSubscribeKey_RNA *)key_b_p)->msg.params;
+ return !(
+ (params_a->ptr.type ==
+ params_b->ptr.type) &&
+ (params_a->ptr.id.data ==
+ params_b->ptr.id.data) &&
+ (params_a->ptr.data ==
+ params_b->ptr.data) &&
+ (params_a->prop ==
+ params_b->prop)
+ );
+}
+static void wm_msg_rna_gset_key_free(void *key_p)
+{
+ wmMsgSubscribeKey_RNA *key = key_p;
+ wmMsgSubscribeValueLink *msg_lnk_next;
+ for (wmMsgSubscribeValueLink *msg_lnk = key->head.values.first; msg_lnk; msg_lnk = msg_lnk_next) {
+ msg_lnk_next = msg_lnk->next;
+ wm_msg_subscribe_value_free(&key->head, msg_lnk);
+ }
+ if (key->msg.params.data_path != NULL) {
+ MEM_freeN(key->msg.params.data_path);
+ }
+ MEM_freeN(key);
+}
+
+static void wm_msg_rna_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
+{
+ const wmMsgSubscribeKey_RNA *m = (wmMsgSubscribeKey_RNA *)msg_key;
+ const char *none = "<none>";
+ fprintf(stream,
+ "<wmMsg_RNA %p, "
+ "id='%s', "
+ "%s.%s values_len=%d\n",
+ m, m->msg.head.id,
+ m->msg.params.ptr.type ? RNA_struct_identifier(m->msg.params.ptr.type) : none,
+ m->msg.params.prop ? RNA_property_identifier((PropertyRNA *)m->msg.params.prop) : none,
+ BLI_listbase_count(&m->head.values));
+}
+
+static void wm_msg_rna_update_by_id(
+ struct wmMsgBus *mbus,
+ ID *id_src, ID *id_dst)
+{
+ GSet *gs = mbus->messages_gset[WM_MSG_TYPE_RNA];
+ GSetIterator gs_iter;
+ BLI_gsetIterator_init(&gs_iter, gs);
+ while (BLI_gsetIterator_done(&gs_iter) == false) {
+ wmMsgSubscribeKey_RNA *key = BLI_gsetIterator_getKey(&gs_iter);
+ BLI_gsetIterator_step(&gs_iter);
+ if (key->msg.params.ptr.id.data == id_src) {
+
+ /* GSet always needs updating since the key changes. */
+ BLI_gset_remove(gs, key, NULL);
+
+ /* Remove any non-persistent values, so a single persistent
+ * value doesn't modify behavior for the rest. */
+ wmMsgSubscribeValueLink *msg_lnk_next;
+ for (wmMsgSubscribeValueLink *msg_lnk = key->head.values.first; msg_lnk; msg_lnk = msg_lnk_next) {
+ msg_lnk_next = msg_lnk->next;
+ if (msg_lnk->params.is_persistent == false) {
+ wm_msg_subscribe_value_free(&key->head, msg_lnk);
+ }
+ }
+
+ bool remove = true;
+
+ if (BLI_listbase_is_empty(&key->head.values)) {
+ /* Remove, no reason to keep. */
+ }
+ else if (key->msg.params.ptr.data == key->msg.params.ptr.id.data) {
+ /* Simple, just update the ID. */
+ key->msg.params.ptr.data = id_dst;
+ key->msg.params.ptr.id.data = id_dst;
+ remove = false;
+ }
+ else {
+ /* we need to resolve this from the */
+ PointerRNA idptr;
+ RNA_id_pointer_create(id_dst, &idptr);
+ PointerRNA ptr;
+ PropertyRNA *prop;
+ if (!RNA_path_resolve(&idptr, key->msg.params.data_path, &ptr, &prop)) {
+ key->msg.params.ptr = ptr;
+ key->msg.params.prop = prop;
+ remove = false;
+ }
+ }
+
+ if (remove) {
+ /* Failed to persist, remove the key. */
+ BLI_remlink(&mbus->messages, key);
+ wm_msg_rna_gset_key_free(key);
+ }
+ else {
+ /* note that it's not impossible this key exists, however it is very unlikely
+ * since a subscriber would need to register in the middle of an undo for eg. so assert for now. */
+ BLI_assert(!BLI_gset_haskey(gs, key));
+ BLI_gset_add(gs, key);
+ }
+ }
+ }
+}
+
+static void wm_msg_rna_remove_by_id(struct wmMsgBus *mbus, const ID *id)
+{
+ GSet *gs = mbus->messages_gset[WM_MSG_TYPE_RNA];
+ GSetIterator gs_iter;
+ BLI_gsetIterator_init(&gs_iter, gs);
+ while (BLI_gsetIterator_done(&gs_iter) == false) {
+ wmMsgSubscribeKey_RNA *key = BLI_gsetIterator_getKey(&gs_iter);
+ BLI_gsetIterator_step(&gs_iter);
+ if (key->msg.params.ptr.id.data == id) {
+ BLI_remlink(&mbus->messages, key);
+ BLI_gset_remove(gs, key, NULL);
+ wm_msg_rna_gset_key_free(key);
+ }
+ }
+}
+
+void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msgtype_info)
+{
+ msgtype_info->gset.hash_fn = wm_msg_rna_gset_hash;
+ msgtype_info->gset.cmp_fn = wm_msg_rna_gset_cmp;
+ msgtype_info->gset.key_free_fn = wm_msg_rna_gset_key_free;
+
+ msgtype_info->repr = wm_msg_rna_repr;
+ msgtype_info->update_by_id = wm_msg_rna_update_by_id;
+ msgtype_info->remove_by_id = wm_msg_rna_remove_by_id;
+
+ msgtype_info->msg_key_size = sizeof(wmMsgSubscribeKey_RNA);
+}
+
+/* -------------------------------------------------------------------------- */
+
+
+wmMsgSubscribeKey_RNA *WM_msg_lookup_rna(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
+{
+ wmMsgSubscribeKey_RNA key_test;
+ key_test.msg.params = *msg_key_params;
+ return BLI_gset_lookup(mbus->messages_gset[WM_MSG_TYPE_RNA], &key_test);
+}
+
+void WM_msg_publish_rna_params(struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params)
+{
+ wmMsgSubscribeKey_RNA *key;
+
+ if ((key = WM_msg_lookup_rna(mbus, msg_key_params))) {
+ WM_msg_publish_with_key(mbus, &key->head);
+ }
+
+ /* Support anonymous subscribers, this may be some extra overhead
+ * but we want to be able to be more ambiguous. */
+ if (msg_key_params->ptr.id.data || msg_key_params->ptr.data) {
+ wmMsgParams_RNA msg_key_params_anon = *msg_key_params;
+
+ /* We might want to enable this later? */
+ if (msg_key_params_anon.prop != NULL) {
+ /* All properties for this type. */
+ msg_key_params_anon.prop = NULL;
+ if ((key = WM_msg_lookup_rna(mbus, &msg_key_params_anon))) {
+ WM_msg_publish_with_key(mbus, &key->head);
+ }
+ msg_key_params_anon.prop = msg_key_params->prop;
+ }
+
+ msg_key_params_anon.ptr.id.data = NULL;
+ msg_key_params_anon.ptr.data = NULL;
+ if ((key = WM_msg_lookup_rna(mbus, &msg_key_params_anon))) {
+ WM_msg_publish_with_key(mbus, &key->head);
+ }
+
+ /* Support subscribers to a type. */
+ if (msg_key_params->prop) {
+ msg_key_params_anon.prop = NULL;
+ if ((key = WM_msg_lookup_rna(mbus, &msg_key_params_anon))) {
+ WM_msg_publish_with_key(mbus, &key->head);
+ }
+ }
+ }
+}
+
+void WM_msg_publish_rna(struct wmMsgBus *mbus, PointerRNA *ptr, PropertyRNA *prop)
+{
+ WM_msg_publish_rna_params(mbus, &(wmMsgParams_RNA){ .ptr = *ptr, .prop = prop, });
+}
+
+void WM_msg_subscribe_rna_params(
+ struct wmMsgBus *mbus,
+ const wmMsgParams_RNA *msg_key_params,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr)
+{
+ wmMsgSubscribeKey_RNA msg_key_test = {{NULL}};
+
+ /* use when added */
+ msg_key_test.msg.head.id = id_repr;
+ msg_key_test.msg.head.type = WM_MSG_TYPE_RNA;
+ /* for lookup */
+ msg_key_test.msg.params = *msg_key_params;
+
+ wmMsgSubscribeKey_RNA *msg_key = (wmMsgSubscribeKey_RNA *)WM_msg_subscribe_with_key(
+ mbus, &msg_key_test.head, msg_val_params);
+
+ if (msg_val_params->is_persistent) {
+ if (msg_key->msg.params.data_path == NULL) {
+ if (msg_key->msg.params.ptr.data != msg_key->msg.params.ptr.id.data) {
+ /* We assume prop type can't change. */
+ msg_key->msg.params.data_path = RNA_path_from_ID_to_struct(&msg_key->msg.params.ptr);
+ }
+ }
+ }
+}
+
+void WM_msg_subscribe_rna(
+ struct wmMsgBus *mbus,
+ PointerRNA *ptr, const PropertyRNA *prop,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr)
+{
+ WM_msg_subscribe_rna_params(
+ mbus,
+ &(const wmMsgParams_RNA){
+ .ptr = *ptr,
+ .prop = prop,
+ },
+ msg_val_params, id_repr);
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------------- */
+/** \name ID variants of RNA API
+ *
+ * \note While we could have a separate type for ID's, use RNA since there is enough overlap.
+ * \{ */
+
+void WM_msg_subscribe_ID(
+ struct wmMsgBus *mbus, ID *id, const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr)
+{
+ wmMsgParams_RNA msg_key_params = {{{NULL}}};
+ RNA_id_pointer_create(id, &msg_key_params.ptr);
+ WM_msg_subscribe_rna_params(mbus, &msg_key_params, msg_val_params, id_repr);
+}
+
+void WM_msg_publish_ID(struct wmMsgBus *mbus, ID *id)
+{
+ wmMsgParams_RNA msg_key_params = {{{NULL}}};
+ RNA_id_pointer_create(id, &msg_key_params.ptr);
+ WM_msg_publish_rna_params(mbus, &msg_key_params);
+}
+
+/** \} */
diff --git a/source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c b/source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c
new file mode 100644
index 00000000000..da98cb75162
--- /dev/null
+++ b/source/blender/windowmanager/message_bus/intern/wm_message_bus_static.c
@@ -0,0 +1,136 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/message_bus/intern/wm_message_bus_static.c
+ * \ingroup wm
+ */
+
+#include <stdio.h>
+
+#include "BLI_utildefines.h"
+#include "BLI_ghash.h"
+#include "BLI_listbase.h"
+
+#include "WM_types.h"
+#include "WM_message.h"
+#include "message_bus/intern/wm_message_bus_intern.h"
+
+#include "MEM_guardedalloc.h"
+
+/* -------------------------------------------------------------------------- */
+
+static uint wm_msg_static_gset_hash(const void *key_p)
+{
+ const wmMsgSubscribeKey_Static *key = key_p;
+ const wmMsgParams_Static *params = &key->msg.params;
+ uint k = params->event;
+ return k;
+}
+static bool wm_msg_static_gset_cmp(const void *key_a_p, const void *key_b_p)
+{
+ const wmMsgParams_Static *params_a = &((const wmMsgSubscribeKey_Static *)key_a_p)->msg.params;
+ const wmMsgParams_Static *params_b = &((const wmMsgSubscribeKey_Static *)key_b_p)->msg.params;
+ return !(
+ (params_a->event ==
+ params_b->event)
+ );
+}
+static void wm_msg_static_gset_key_free(void *key_p)
+{
+ wmMsgSubscribeKey *key = key_p;
+ wmMsgSubscribeValueLink *msg_lnk_next;
+ for (wmMsgSubscribeValueLink *msg_lnk = key->values.first; msg_lnk; msg_lnk = msg_lnk_next) {
+ msg_lnk_next = msg_lnk->next;
+ BLI_remlink(&key->values, msg_lnk);
+ MEM_freeN(msg_lnk);
+ }
+ MEM_freeN(key);
+}
+
+static void wm_msg_static_repr(FILE *stream, const wmMsgSubscribeKey *msg_key)
+{
+ const wmMsgSubscribeKey_Static *m = (wmMsgSubscribeKey_Static *)msg_key;
+ fprintf(stream,
+ "<wmMsg_Static %p, "
+ "id='%s', "
+ "values_len=%d\n",
+ m, m->msg.head.id,
+ BLI_listbase_count(&m->head.values));
+}
+
+
+void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msgtype_info)
+{
+ msgtype_info->gset.hash_fn = wm_msg_static_gset_hash;
+ msgtype_info->gset.cmp_fn = wm_msg_static_gset_cmp;
+ msgtype_info->gset.key_free_fn = wm_msg_static_gset_key_free;
+ msgtype_info->repr = wm_msg_static_repr;
+
+ msgtype_info->msg_key_size = sizeof(wmMsgSubscribeKey_Static);
+}
+
+/* -------------------------------------------------------------------------- */
+
+
+wmMsgSubscribeKey_Static *WM_msg_lookup_static(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
+{
+ wmMsgSubscribeKey_Static key_test;
+ key_test.msg.params = *msg_key_params;
+ return BLI_gset_lookup(mbus->messages_gset[WM_MSG_TYPE_STATIC], &key_test);
+}
+
+void WM_msg_publish_static_params(struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params)
+{
+ wmMsgSubscribeKey_Static *key = WM_msg_lookup_static(mbus, msg_key_params);
+ if (key) {
+ WM_msg_publish_with_key(mbus, &key->head);
+ }
+}
+
+void WM_msg_publish_static(struct wmMsgBus *mbus, int event)
+{
+ WM_msg_publish_static_params(mbus, &(wmMsgParams_Static){ .event = event, });
+}
+
+void WM_msg_subscribe_static_params(
+ struct wmMsgBus *mbus,
+ const wmMsgParams_Static *msg_key_params,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr)
+{
+ wmMsgSubscribeKey_Static msg_key_test = {{NULL}};
+
+ /* use when added */
+ msg_key_test.msg.head.id = id_repr;
+ msg_key_test.msg.head.type = WM_MSG_TYPE_STATIC;
+ /* for lookup */
+ msg_key_test.msg.params = *msg_key_params;
+
+ WM_msg_subscribe_with_key(mbus, &msg_key_test.head, msg_val_params);
+}
+
+void WM_msg_subscribe_static(
+ struct wmMsgBus *mbus,
+ int event,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr)
+{
+ WM_msg_subscribe_static_params(mbus, &(const wmMsgParams_Static){ .event = event, }, msg_val_params, id_repr);
+}
diff --git a/source/blender/windowmanager/message_bus/wm_message_bus.h b/source/blender/windowmanager/message_bus/wm_message_bus.h
new file mode 100644
index 00000000000..a31137d353f
--- /dev/null
+++ b/source/blender/windowmanager/message_bus/wm_message_bus.h
@@ -0,0 +1,273 @@
+/*
+ * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/windowmanager/message_bus/wm_message_bus.h
+ * \ingroup wm
+ */
+
+#ifndef __WM_MESSAGE_BUS_H__
+#define __WM_MESSAGE_BUS_H__
+
+#include <stdio.h>
+
+struct GSet;
+struct ID;
+struct bContext;
+struct wmMsg;
+
+/* opaque (don't expose outside wm_message_bus.c) */
+struct wmMsgBus;
+struct wmMsgSubscribeKey;
+struct wmMsgSubscribeValue;
+struct wmMsgSubscribeValueLink;
+
+typedef void (*wmMsgNotifyFn)(
+ struct bContext *C, struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val);
+typedef void (*wmMsgSubscribeValueFreeDataFn)(
+ struct wmMsgSubscribeKey *msg_key, struct wmMsgSubscribeValue *msg_val);
+
+/* Exactly what arguments here is not obvious. */
+typedef void (*wmMsgSubscribeValueUpdateIdFn)(
+ struct bContext *C,
+ struct wmMsgBus *mbus,
+ struct ID *id_src, struct ID *id_dst,
+ struct wmMsgSubscribeValue *msg_val);
+enum {
+ WM_MSG_TYPE_RNA = 0,
+ WM_MSG_TYPE_STATIC = 1,
+};
+#define WM_MSG_TYPE_NUM 2
+
+typedef struct wmMsgTypeInfo {
+ struct {
+ unsigned int (*hash_fn)(const void *msg);
+ bool (*cmp_fn)(const void *a, const void *b);
+ void (*key_free_fn)(void *key);
+ } gset;
+
+ void (*update_by_id)(struct wmMsgBus *mbus, struct ID *id_src, struct ID *id_dst);
+ void (*remove_by_id)(struct wmMsgBus *mbus, const struct ID *id);
+ void (*repr)(FILE *stream, const struct wmMsgSubscribeKey *msg_key);
+
+ /* sizeof(wmMsgSubscribeKey_*) */
+ uint msg_key_size;
+} wmMsgTypeInfo;
+
+typedef struct wmMsg {
+ unsigned int type;
+// #ifdef DEBUG
+ /* For debugging: '__func__:__LINE__'. */
+ const char *id;
+// #endif
+} wmMsg;
+
+typedef struct wmMsgSubscribeKey {
+ /** Linked list for predicable ordering, otherwise we would depend on ghash bucketing. */
+ struct wmMsgSubscribeKey *next, *prev;
+ ListBase values;
+ /* over-alloc, eg: wmMsgSubscribeKey_RNA */
+ /* Last member will be 'wmMsg_*' */
+} wmMsgSubscribeKey;
+
+/** One of many in #wmMsgSubscribeKey.values */
+typedef struct wmMsgSubscribeValue {
+ struct wmMsgSubscribe *next, *prev;
+
+ /** Handle, used to iterate and clear. */
+ void *owner;
+ /** User data, can be whatever we like, free using the 'free_data' callback if it's owned. */
+ void *user_data;
+
+ /** Callbacks */
+ wmMsgNotifyFn notify;
+ wmMsgSubscribeValueUpdateIdFn update_id;
+ wmMsgSubscribeValueFreeDataFn free_data;
+
+ /** Keep this subscriber if possible. */
+ uint is_persistent : 1;
+ /* tag to run when handling events,
+ * we may want option for immediate execution. */
+ uint tag : 1;
+} wmMsgSubscribeValue;
+
+/** One of many in #wmMsgSubscribeKey.values */
+typedef struct wmMsgSubscribeValueLink {
+ struct wmMsgSubscribeValueLink *next, *prev;
+ wmMsgSubscribeValue params;
+} wmMsgSubscribeValueLink;
+
+void WM_msgbus_types_init(void);
+
+struct wmMsgBus *WM_msgbus_create(void);
+void WM_msgbus_destroy(struct wmMsgBus *mbus);
+
+void WM_msgbus_clear_by_owner(struct wmMsgBus *mbus, void *owner);
+
+void WM_msg_dump(struct wmMsgBus *mbus, const char *info);
+void WM_msgbus_handle(struct wmMsgBus *mbus, struct bContext *C);
+
+void WM_msg_publish_with_key(struct wmMsgBus *mbus, wmMsgSubscribeKey *msg_key);
+wmMsgSubscribeKey *WM_msg_subscribe_with_key(
+ struct wmMsgBus *mbus,
+ const wmMsgSubscribeKey *msg_key_test,
+ const wmMsgSubscribeValue *msg_val_params);
+
+void WM_msg_id_update(
+ struct wmMsgBus *mbus,
+ struct ID *id_src, struct ID *id_dst);
+void WM_msg_id_remove(struct wmMsgBus *mbus, const struct ID *id);
+
+/* -------------------------------------------------------------------------- */
+/* wm_message_bus_static.c */
+
+enum {
+ /* generic window redraw */
+ WM_MSG_STATICTYPE_WINDOW_DRAW = 0,
+ WM_MSG_STATICTYPE_SCREEN_EDIT = 1,
+ WM_MSG_STATICTYPE_FILE_READ = 2,
+};
+
+typedef struct wmMsgParams_Static {
+ int event;
+} wmMsgParams_Static;
+
+typedef struct wmMsg_Static {
+ wmMsg head; /* keep first */
+ wmMsgParams_Static params;
+} wmMsg_Static;
+
+typedef struct wmMsgSubscribeKey_Static {
+ wmMsgSubscribeKey head;
+ wmMsg_Static msg;
+} wmMsgSubscribeKey_Static;
+
+void WM_msgtypeinfo_init_static(wmMsgTypeInfo *msg_type);
+
+wmMsgSubscribeKey_Static *WM_msg_lookup_static(
+ struct wmMsgBus *mbus, const wmMsgParams_Static *msg_key_params);
+void WM_msg_publish_static_params(
+ struct wmMsgBus *mbus,
+ const wmMsgParams_Static *msg_key_params);
+void WM_msg_publish_static(
+ struct wmMsgBus *mbus,
+ /* wmMsgParams_Static (expanded) */
+ int event);
+void WM_msg_subscribe_static_params(
+ struct wmMsgBus *mbus,
+ const wmMsgParams_Static *msg_key_params,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr);
+void WM_msg_subscribe_static(
+ struct wmMsgBus *mbus,
+ int event,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr);
+
+/* -------------------------------------------------------------------------- */
+/* wm_message_bus_rna.c */
+
+typedef struct wmMsgParams_RNA {
+ /** when #PointerRNA.data & id.data are NULL. match against all. */
+ PointerRNA ptr;
+ /** when NULL, match against any property. */
+ const PropertyRNA *prop;
+
+ /**
+ * Optional RNA data path for persistent RNA properties, ignore if NULL.
+ * otherwise it's allocated.
+ */
+ char *data_path;
+} wmMsgParams_RNA;
+
+typedef struct wmMsg_RNA {
+ wmMsg head; /* keep first */
+ wmMsgParams_RNA params;
+} wmMsg_RNA;
+
+typedef struct wmMsgSubscribeKey_RNA {
+ wmMsgSubscribeKey head;
+ wmMsg_RNA msg;
+} wmMsgSubscribeKey_RNA;
+
+void WM_msgtypeinfo_init_rna(wmMsgTypeInfo *msg_type);
+
+wmMsgSubscribeKey_RNA *WM_msg_lookup_rna(
+ struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params);
+void WM_msg_publish_rna_params(
+ struct wmMsgBus *mbus, const wmMsgParams_RNA *msg_key_params);
+void WM_msg_publish_rna(
+ struct wmMsgBus *mbus,
+ /* wmMsgParams_RNA (expanded) */
+ PointerRNA *ptr, PropertyRNA *prop);
+void WM_msg_subscribe_rna_params(
+ struct wmMsgBus *mbus,
+ const wmMsgParams_RNA *msg_key_params,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr);
+void WM_msg_subscribe_rna(
+ struct wmMsgBus *mbus,
+ PointerRNA *ptr, const PropertyRNA *prop,
+ const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr);
+
+/* ID variants */
+void WM_msg_subscribe_ID(
+ struct wmMsgBus *mbus, struct ID *id, const wmMsgSubscribeValue *msg_val_params,
+ const char *id_repr);
+void WM_msg_publish_ID(
+ struct wmMsgBus *mbus, struct ID *id);
+
+#define WM_msg_publish_rna_prop(mbus, id_, data_, type_, prop_) { \
+ wmMsgParams_RNA msg_key_params_ = {{{0}}}; \
+ extern PropertyRNA rna_##type_##_##prop_; \
+ RNA_pointer_create(id_, &RNA_##type_, data_, &msg_key_params_.ptr); \
+ msg_key_params_.prop = &rna_##type_##_##prop_; \
+ WM_msg_publish_rna_params(mbus, &msg_key_params_); \
+} ((void)0)
+#define WM_msg_subscribe_rna_prop(mbus, id_, data_, type_, prop_, value) { \
+ wmMsgParams_RNA msg_key_params_ = {{{0}}}; \
+ extern PropertyRNA rna_##type_##_##prop_; \
+ RNA_pointer_create(id_, &RNA_##type_, data_, &msg_key_params_.ptr); \
+ msg_key_params_.prop = &rna_##type_##_##prop_; \
+ WM_msg_subscribe_rna_params(mbus, &msg_key_params_, value, __func__); \
+} ((void)0)
+
+/* Anonymous variants (for convenience) */
+#define WM_msg_subscribe_rna_anon_type(mbus, type_, value) { \
+ WM_msg_subscribe_rna_params( \
+ mbus, \
+ &(const wmMsgParams_RNA){ \
+ .ptr = (PointerRNA){.type = &RNA_##type_}, \
+ .prop = NULL, \
+ }, \
+ value, __func__); \
+} ((void)0)
+#define WM_msg_subscribe_rna_anon_prop(mbus, type_, prop_, value) { \
+ extern PropertyRNA rna_##type_##_##prop_; \
+ WM_msg_subscribe_rna_params( \
+ mbus, \
+ &(const wmMsgParams_RNA){ \
+ .ptr = (PointerRNA){.type = &RNA_##type_}, \
+ .prop = &rna_##type_##_##prop_, \
+ }, \
+ value, __func__); \
+} ((void)0)
+
+#endif /* __WM_MESSAGE_BUS_H__ */
diff --git a/source/blender/windowmanager/wm.h b/source/blender/windowmanager/wm.h
index 5ced36a104f..073adef177c 100644
--- a/source/blender/windowmanager/wm.h
+++ b/source/blender/windowmanager/wm.h
@@ -31,9 +31,12 @@
#ifndef __WM_H__
#define __WM_H__
+struct ARegion;
struct wmWindow;
struct ReportList;
+#include "manipulators/wm_manipulator_wmapi.h"
+
typedef struct wmPaintCursor {
struct wmPaintCursor *next, *prev;
@@ -49,7 +52,7 @@ void wm_exit_schedule_delayed(const bContext *C);
extern void wm_close_and_free(bContext *C, wmWindowManager *);
extern void wm_close_and_free_all(bContext *C, ListBase *);
-extern void wm_add_default(bContext *C);
+extern void wm_add_default(struct Main *bmain, bContext *C);
extern void wm_clear_default_size(bContext *C);
/* register to windowmanager for redo or macro */
@@ -80,7 +83,11 @@ void wm_autosave_read(bContext *C, struct ReportList *reports);
void wm_autosave_location(char *filepath);
/* wm_stereo.c */
-void wm_method_draw_stereo3d(const bContext *C, wmWindow *win);
+void wm_stereo3d_draw_interlace(wmWindow *win, struct ARegion *ar);
+void wm_stereo3d_draw_anaglyph(wmWindow *win, struct ARegion *ar);
+void wm_stereo3d_draw_sidebyside(wmWindow *win, int view);
+void wm_stereo3d_draw_topbottom(wmWindow *win, int view);
+
void wm_stereo3d_mouse_offset_apply(wmWindow *win, int *r_mouse_xy);
int wm_stereo3d_set_exec(bContext *C, wmOperator *op);
int wm_stereo3d_set_invoke(bContext *C, wmOperator *op, const wmEvent *event);
diff --git a/source/blender/windowmanager/wm_draw.h b/source/blender/windowmanager/wm_draw.h
index 5257bba45ff..096d241eb64 100644
--- a/source/blender/windowmanager/wm_draw.h
+++ b/source/blender/windowmanager/wm_draw.h
@@ -34,31 +34,27 @@
#include "GPU_glew.h"
-typedef struct wmDrawTriple {
- GLuint bind;
- int x, y;
- GLenum target;
-} wmDrawTriple;
+struct GPUOffScreen;
+struct GPUViewport;
+struct GPUTexture;
-typedef struct wmDrawData {
- struct wmDrawData *next, *prev;
- wmDrawTriple *triple;
-} wmDrawData;
+typedef struct wmDrawBuffer {
+ struct GPUOffScreen *offscreen[2];
+ struct GPUViewport *viewport[2];
+ bool stereo;
+ int bound_view;
+} wmDrawBuffer;
struct bContext;
struct wmWindow;
struct ARegion;
/* wm_draw.c */
-void wm_draw_update (struct bContext *C);
-void wm_draw_window_clear (struct wmWindow *win);
-void wm_draw_region_clear (struct wmWindow *win, struct ARegion *ar);
+void wm_draw_update(struct bContext *C);
+void wm_draw_region_clear(struct wmWindow *win, struct ARegion *ar);
+void wm_draw_region_blend(struct ARegion *ar, int view, bool blend);
-void wm_tag_redraw_overlay (struct wmWindow *win, struct ARegion *ar);
-
-void wm_triple_draw_textures (struct wmWindow *win, struct wmDrawTriple *triple, float alpha, bool is_interlace);
-
-void wm_draw_data_free (struct wmWindow *win);
+struct GPUTexture *wm_draw_region_texture(struct ARegion *ar, int view);
#endif /* __WM_DRAW_H__ */
diff --git a/source/blender/windowmanager/wm_event_system.h b/source/blender/windowmanager/wm_event_system.h
index 9977e73f2fd..c14517f1662 100644
--- a/source/blender/windowmanager/wm_event_system.h
+++ b/source/blender/windowmanager/wm_event_system.h
@@ -68,7 +68,8 @@ typedef struct wmEventHandler {
/* drop box handler */
ListBase *dropboxes;
-
+ /* manipulator handler */
+ struct wmManipulatorMap *manipulator_map;
} wmEventHandler;
/* custom types for handlers, for signaling, freeing */
diff --git a/source/blender/windowmanager/wm_event_types.h b/source/blender/windowmanager/wm_event_types.h
index 090c8c90280..e327bd81d81 100644
--- a/source/blender/windowmanager/wm_event_types.h
+++ b/source/blender/windowmanager/wm_event_types.h
@@ -339,6 +339,8 @@ enum {
EVT_DROP = 0x5023,
EVT_BUT_CANCEL = 0x5024,
+ /* could become manipulator callback */
+ EVT_MANIPULATOR_UPDATE = 0x5025,
/* ********** End of Blender internal events. ********** */
};
diff --git a/source/blender/windowmanager/wm_files.h b/source/blender/windowmanager/wm_files.h
index b102b6c7cc7..6f63e55e8ab 100644
--- a/source/blender/windowmanager/wm_files.h
+++ b/source/blender/windowmanager/wm_files.h
@@ -45,6 +45,7 @@ void WM_OT_save_homefile(struct wmOperatorType *ot);
void WM_OT_userpref_autoexec_path_add(struct wmOperatorType *ot);
void WM_OT_userpref_autoexec_path_remove(struct wmOperatorType *ot);
void WM_OT_save_userpref(struct wmOperatorType *ot);
+void WM_OT_save_workspace_file(struct wmOperatorType *ot);
void WM_OT_read_history(struct wmOperatorType *ot);
void WM_OT_read_homefile(struct wmOperatorType *ot);
void WM_OT_read_factory_settings(struct wmOperatorType *ot);
diff --git a/source/blender/windowmanager/wm_subwindow.h b/source/blender/windowmanager/wm_subwindow.h
deleted file mode 100644
index cc9abf87514..00000000000
--- a/source/blender/windowmanager/wm_subwindow.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2007 Blender Foundation.
- * All rights reserved.
- *
- *
- * Contributor(s): Blender Foundation
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file blender/windowmanager/wm_subwindow.h
- * \ingroup wm
- */
-
-
-#ifndef __WM_SUBWINDOW_H__
-#define __WM_SUBWINDOW_H__
-
-
-/* *************** internal api ************** */
-void wm_subwindows_free(wmWindow *win);
-
-int wm_subwindow_open(wmWindow *win, const rcti *winrct, bool activate);
-void wm_subwindow_close(wmWindow *win, int swinid);
-int wm_subwindow_get_id(wmWindow *win); /* returns id */
-
-void wm_subwindow_position(wmWindow *win, int swinid, const rcti *winrct, bool activate);
-
-void wm_subwindow_size_get(wmWindow *win, int swinid, int *x, int *y);
-void wm_subwindow_origin_get(wmWindow *win, int swinid, int *x, int *y);
-void wm_subwindow_matrix_get(wmWindow *win, int swinid, float mat[4][4]);
-void wm_subwindow_rect_get(wmWindow *win, int swinid, struct rcti *r_rect);
-void wm_subwindow_rect_set(wmWindow *win, int swinid, const rcti *rect);
-
-#endif /* __WM_SUBWINDOW_H__ */
-
diff --git a/source/blender/windowmanager/wm_window.h b/source/blender/windowmanager/wm_window.h
index 5209af87960..b0c7021c496 100644
--- a/source/blender/windowmanager/wm_window.h
+++ b/source/blender/windowmanager/wm_window.h
@@ -32,7 +32,11 @@
#ifndef __WM_WINDOW_H__
#define __WM_WINDOW_H__
+struct EnumPropertyItem;
+struct wmEvent;
struct wmOperator;
+struct PointerRNA;
+struct PropertyRNA;
/* *************** internal api ************** */
void wm_ghost_init (bContext *C);
@@ -42,8 +46,8 @@ void wm_get_screensize(int *r_width, int *r_height);
void wm_get_desktopsize(int *r_width, int *r_height);
wmWindow *wm_window_new (bContext *C);
-wmWindow *wm_window_copy (bContext *C, wmWindow *win_src);
-wmWindow *wm_window_copy_test (bContext *C, wmWindow *win_src);
+wmWindow *wm_window_copy (bContext *C, wmWindow *win_src, const bool duplicate_layout);
+wmWindow *wm_window_copy_test (bContext *C, wmWindow *win_src, const bool duplicate_layout);
void wm_window_free (bContext *C, wmWindowManager *wm, wmWindow *win);
void wm_window_close (bContext *C, wmWindowManager *wm, wmWindow *win);
@@ -54,6 +58,7 @@ void wm_window_process_events (const bContext *C);
void wm_window_process_events_nosleep(void);
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win);
+void wm_window_reset_drawable(void);
void wm_window_raise (wmWindow *win);
void wm_window_lower (wmWindow *win);
@@ -76,10 +81,14 @@ void wm_window_IME_end (wmWindow *win);
/* *************** window operators ************** */
int wm_window_close_exec(bContext *C, struct wmOperator *op);
-int wm_window_duplicate_exec(bContext *C, struct wmOperator *op);
int wm_window_fullscreen_toggle_exec(bContext *C, struct wmOperator *op);
void wm_quit_with_optional_confirmation_prompt(bContext *C, wmWindow *win) ATTR_NONNULL();
+const struct EnumPropertyItem *wm_window_new_screen_itemf(
+ bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop, bool *r_free);
+int wm_window_new_exec(bContext *C, struct wmOperator *op);
+int wm_window_new_invoke(bContext *C, struct wmOperator *op, const struct wmEvent *event);
+
/* Initial (unmaximized) size to start with for
* systems that can't find it for themselves (X11).
* Clamped by real desktop limits */
diff --git a/source/blenderplayer/CMakeLists.txt b/source/blenderplayer/CMakeLists.txt
deleted file mode 100644
index cec936f215d..00000000000
--- a/source/blenderplayer/CMakeLists.txt
+++ /dev/null
@@ -1,265 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-# message(STATUS "Configuring blenderplayer")
-
-setup_libdirs()
-
-if(WIN32 AND NOT UNIX)
- string(SUBSTRING ${BLENDER_VERSION} 0 1 bver1)
- string(SUBSTRING ${BLENDER_VERSION} 2 1 bver2)
- string(SUBSTRING ${BLENDER_VERSION} 3 1 bver3)
- add_definitions(
- -DBLEN_VER_RC_STR=${BLENDER_VERSION}
- -DBLEN_VER_RC_1=${bver1}
- -DBLEN_VER_RC_2=${bver2}
- -DBLEN_VER_RC_3=${bver3}
- -DBLEN_VER_RC_4=0
- )
-
- add_executable(
- blenderplayer ${EXETYPE}
- bad_level_call_stubs/stubs.c
- ${CMAKE_SOURCE_DIR}/release/windows/icons/winblender.rc)
- WINDOWS_SIGN_TARGET(blenderplayer)
- install(TARGETS blenderplayer
- COMPONENT Blenderplayer
- DESTINATION ".")
-
-add_cc_flags_custom_test(blenderplayer)
-
-elseif(APPLE)
- add_executable(blenderplayer ${EXETYPE} bad_level_call_stubs/stubs.c)
- # setup Info.plist
- execute_process(COMMAND date "+%Y-%m-%d" OUTPUT_VARIABLE BLENDER_DATE OUTPUT_STRIP_TRAILING_WHITESPACE)
- set(PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blenderplayer.app)
- set(PLAYER_SOURCEINFO ${PLAYER_SOURCEDIR}/Contents/Info.plist)
- set_target_properties(blenderplayer PROPERTIES
- MACOSX_BUNDLE_INFO_PLIST ${PLAYER_SOURCEINFO}
- MACOSX_BUNDLE_SHORT_VERSION_STRING "${BLENDER_VERSION}${BLENDER_VERSION_CHAR}"
- MACOSX_BUNDLE_LONG_VERSION_STRING "${BLENDER_VERSION}${BLENDER_VERSION_CHAR} ${BLENDER_DATE}")
-
-else()
- add_executable(blenderplayer bad_level_call_stubs/stubs.c)
-
- if(NOT WITH_INSTALL_PORTABLE)
- install(
- TARGETS blenderplayer
- DESTINATION bin
- )
- else()
- install(
- TARGETS blenderplayer
- DESTINATION "."
- )
- endif()
-endif()
-
-add_dependencies(blenderplayer makesdna)
-
-get_property(BLENDER_LINK_LIBS GLOBAL PROPERTY BLENDER_LINK_LIBS)
-
-list(APPEND BLENDER_LINK_LIBS
- ge_player_common
- ge_player_ghost
- blenkernel_blc
-)
-
-if(CMAKE_SYSTEM_NAME MATCHES "Linux")
- list(APPEND BLENDER_LINK_LIBS extern_binreloc)
-endif()
-
-# if(UNIX)
- # Sort libraries
- set(BLENDER_SORTED_LIBS
- ge_player_ghost
- ge_player_common
- bf_intern_string
- bf_intern_ghost
- bf_rna
- bf_blenkernel
- bf_depsgraph
- bf_physics
- bf_intern_rigidbody
- bf_blenloader
- ge_blen_routines
- bf_editor_datafiles
- ge_converter
- ge_logic_ketsji
- ge_phys_bullet
- ge_phys_dummy
- ge_logic
- ge_rasterizer
- ge_oglrasterizer
- ge_logic_expressions
- ge_scenegraph
- bf_ikplugin
- bf_intern_itasc
- bf_intern_iksolver
- bf_intern_smoke
- bf_modifiers
- bf_intern_moto
- bf_nodes
- bf_gpu
- bf_imbuf
- bf_avi
- ge_logic_network
- ge_logic_ngnetwork
- ge_logic_loopbacknetwork
- extern_bullet
- bf_intern_guardedalloc
- bf_intern_memutil
- bf_python_ext
- bf_python_mathutils
- bf_python_bmesh
- bf_intern_utfconv
- bf_imbuf_cineon
- bf_imbuf_openexr
- bf_imbuf_openimageio
- extern_openjpeg
- bf_imbuf_dds
- bf_dna
- ge_videotex
- bf_blenfont
- bf_blentranslation
- bf_intern_audaspace
- blenkernel_blc
- bf_bmesh
- bf_blenlib
- bf_intern_utfconv
- extern_binreloc
- extern_minilzo
- bf_intern_ghost # duplicate for linking
- bf_blenkernel # duplicate for linking
- bf_intern_mikktspace
- extern_recastnavigation
- bf_intern_opencolorio
- bf_intern_glew_mx
- bf_intern_eigen
- extern_rangetree
- extern_wcwidth
- bf_intern_libmv
- extern_sdlew
- )
-
- if(NOT WITH_SYSTEM_GLOG)
- list(APPEND BLENDER_SORTED_LIBS extern_glog)
- endif()
-
- if(NOT WITH_SYSTEM_GFLAGS)
- list(APPEND BLENDER_SORTED_LIBS extern_gflags)
- endif()
-
- if(WITH_MOD_CLOTH_ELTOPO)
- list(APPEND BLENDER_SORTED_LIBS extern_eltopo)
- endif()
-
- if(NOT WITH_SYSTEM_GLEW)
- list(APPEND BLENDER_SORTED_LIBS ${BLENDER_GLEW_LIBRARIES})
- endif()
-
- if(WITH_LZMA)
- list(APPEND BLENDER_SORTED_LIBS extern_lzma)
- endif()
-
- if(WITH_LIBMV)
- list(APPEND BLENDER_SORTED_LIBS extern_ceres)
- endif()
-
- if(WITH_GHOST_XDND)
- list(APPEND BLENDER_SORTED_LIBS extern_xdnd)
- endif()
-
- if(WITH_CXX_GUARDEDALLOC)
- list(APPEND BLENDER_SORTED_LIBS bf_intern_guardedalloc_cpp)
- endif()
-
- if(WITH_INTERNATIONAL)
- list(APPEND BLENDER_SORTED_LIBS bf_intern_locale)
- endif()
-
- if(WITH_GAMEENGINE_DECKLINK)
- list(APPEND BLENDER_SORTED_LIBS bf_intern_decklink)
- endif()
-
- if(WIN32)
- list(APPEND BLENDER_SORTED_LIBS bf_intern_gpudirect)
- endif()
-
- if(WITH_OPENSUBDIV)
- list(APPEND BLENDER_SORTED_LIBS bf_intern_opensubdiv)
- endif()
-
- if(WITH_OPENVDB)
- list(APPEND BLENDER_SORTED_LIBS bf_intern_openvdb)
- endif()
-
- if(WITH_ALEMBIC)
- list(APPEND BLENDER_SORTED_LIBS bf_alembic)
- endif()
-
- foreach(SORTLIB ${BLENDER_SORTED_LIBS})
- set(REMLIB ${SORTLIB})
- foreach(SEARCHLIB ${BLENDER_LINK_LIBS})
- if(${SEARCHLIB} STREQUAL ${SORTLIB})
- set(REMLIB "")
- endif()
- endforeach()
- if(REMLIB)
- # message(STATUS "Removing library ${REMLIB} from blenderplayer linking because: not configured")
- list(APPEND REM_MSG ${REMLIB})
- list(REMOVE_ITEM BLENDER_SORTED_LIBS ${REMLIB})
- endif()
- endforeach()
- if(REM_MSG)
- list(SORT REM_MSG)
- message(STATUS "Player Skipping: (${REM_MSG})")
- endif()
- target_link_libraries(blenderplayer ${BLENDER_SORTED_LIBS})
-
- unset(SEARCHLIB)
- unset(SORTLIB)
- unset(REMLIB)
- unset(REM_MSG)
-
-# else()
-# target_link_libraries(blenderplayer ${BLENDER_LINK_LIBS})
-# endif()
-
-if(WITH_PLAYER)
- add_subdirectory(bad_level_call_stubs)
-endif()
-
-setup_liblinks(blenderplayer)
-
-# We put CLEW and CUEW here because OPENSUBDIV_LIBRARIES dpeends on them..
-if(WITH_CYCLES OR WITH_COMPOSITOR OR WITH_OPENSUBDIV)
- target_link_libraries(blenderplayer "extern_clew")
- if(WITH_CUDA_DYNLOAD)
- target_link_libraries(blenderplayer "extern_cuew")
- else()
- target_link_libraries(${target} ${CUDA_CUDA_LIBRARY})
- endif()
-endif()
diff --git a/source/blenderplayer/bad_level_call_stubs/CMakeLists.txt b/source/blenderplayer/bad_level_call_stubs/CMakeLists.txt
deleted file mode 100644
index 0e570e19258..00000000000
--- a/source/blenderplayer/bad_level_call_stubs/CMakeLists.txt
+++ /dev/null
@@ -1,77 +0,0 @@
-
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-# this warning on generated files gets annoying
-remove_strict_flags()
-
-set(INC
- .
- ..
- ../../blender/blenlib
- ../../blender/blenkernel
- ../../blender/blenloader
- ../../blender/makesdna
- ../../blender/makesrna
- ../../../intern/guardedalloc
-)
-
-set(INC_SYS
-
-)
-
-set(SRC
- stubs.c
-)
-
-if(WITH_BUILDINFO)
- list(APPEND SRC
- ../../creator/buildinfo.c
- )
- add_definitions(-DBUILD_DATE="\"\""
- -DBUILD_TIME="\"\""
- -DBUILD_COMMIT_TIMESTAMP=0
- -DBUILD_COMMIT_DATE="\"\""
- -DBUILD_COMMIT_TIME="\"\""
- -DBUILD_HASH="\"\""
- -DBUILD_PLATFORM="\"\""
- -DBUILD_BRANCH="\"\""
- -DBUILD_TYPE="\"\""
- )
-endif()
-
-if(WITH_GAMEENGINE)
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
-if(WITH_FREESTYLE)
- add_definitions(-DWITH_FREESTYLE)
-endif()
-
-if(WITH_INPUT_NDOF)
- add_definitions(-DWITH_INPUT_NDOF)
-endif()
-
-blender_add_lib_nolist(blenkernel_blc "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blenderplayer/bad_level_call_stubs/stubs.c b/source/blenderplayer/bad_level_call_stubs/stubs.c
deleted file mode 100644
index 054ca1385f0..00000000000
--- a/source/blenderplayer/bad_level_call_stubs/stubs.c
+++ /dev/null
@@ -1,765 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * BKE_bad_level_calls function stubs
- */
-
-/** \file blenderplayer/bad_level_call_stubs/stubs.c
- * \ingroup blc
- */
-
-#ifdef WITH_GAMEENGINE
-
-#define ASSERT_STUBS 0
-#if ASSERT_STUBS
-# include <assert.h>
-# define STUB_ASSERT(x) (assert(x))
-#else
-# define STUB_ASSERT(x)
-#endif
-
-
-struct ARegion;
-struct ARegionType;
-struct BMEditMesh;
-struct Base;
-struct bContext;
-struct BoundBox;
-struct Brush;
-struct CSG_FaceIteratorDescriptor;
-struct CSG_VertexIteratorDescriptor;
-struct ChannelDriver;
-struct ColorBand;
-struct Context;
-struct Curve;
-struct CurveMapping;
-struct DerivedMesh;
-struct EditBone;
-struct EnvMap;
-struct FCurve;
-struct Heap;
-struct HeapNode;
-struct ID;
-struct ImBuf;
-struct Image;
-struct ImageUser;
-struct KeyingSet;
-struct KeyingSetInfo;
-struct MCol;
-struct MTex;
-struct Main;
-struct Mask;
-struct Material;
-struct MenuType;
-struct Mesh;
-struct MetaBall;
-struct Lattice;
-struct ModifierData;
-struct MovieClip;
-struct MultiresModifierData;
-struct HookModifierData;
-struct NodeBlurData;
-struct Nurb;
-struct Object;
-struct PBVHNode;
-struct PyObject;
-struct Render;
-struct RenderEngine;
-struct RenderEngineType;
-struct RenderLayer;
-struct RenderResult;
-struct Scene;
-struct Scene;
-struct ScrArea;
-struct SculptSession;
-struct ShadeInput;
-struct ShadeResult;
-struct SpaceButs;
-struct SpaceClip;
-struct SpaceImage;
-struct SpaceNode;
-struct Tex;
-struct TexResult;
-struct Text;
-struct ToolSettings;
-struct View2D;
-struct View3D;
-struct bAction;
-struct bArmature;
-struct bConstraint;
-struct bConstraintOb;
-struct bConstraintTarget;
-struct bContextDataResult;
-struct bGPDlayer;
-struct bNode;
-struct bNodeType;
-struct bNodeSocket;
-struct bNodeSocketType;
-struct bNodeTree;
-struct bNodeTreeType;
-struct bPoseChannel;
-struct bPythonConstraint;
-struct bTheme;
-struct uiLayout;
-struct wmEvent;
-struct wmKeyConfig;
-struct wmKeyMap;
-struct wmOperator;
-struct wmOperatorType;
-struct wmWindow;
-struct wmWindowManager;
-
-
-/* -------------------------------------------------------------------- */
-/* Declarations */
-
-/* may cause troubles... enable for now so args match for certain */
-#if 1
-#if defined(__GNUC__)
-# pragma GCC diagnostic error "-Wmissing-prototypes"
-# pragma GCC diagnostic ignored "-Wunused-parameter"
-#endif
-
-#include "../../intern/dualcon/dualcon.h"
-#include "../../intern/elbeem/extern/elbeem.h"
-#include "../blender/blenkernel/BKE_modifier.h"
-#include "../blender/blenkernel/BKE_paint.h"
-#include "../blender/compositor/COM_compositor.h"
-#include "../blender/editors/include/ED_armature.h"
-#include "../blender/editors/include/ED_anim_api.h"
-#include "../blender/editors/include/ED_buttons.h"
-#include "../blender/editors/include/ED_clip.h"
-#include "../blender/editors/include/ED_curve.h"
-#include "../blender/editors/include/ED_fileselect.h"
-#include "../blender/editors/include/ED_gpencil.h"
-#include "../blender/editors/include/ED_image.h"
-#include "../blender/editors/include/ED_info.h"
-#include "../blender/editors/include/ED_keyframes_edit.h"
-#include "../blender/editors/include/ED_keyframing.h"
-#include "../blender/editors/include/ED_lattice.h"
-#include "../blender/editors/include/ED_mball.h"
-#include "../blender/editors/include/ED_mesh.h"
-#include "../blender/editors/include/ED_node.h"
-#include "../blender/editors/include/ED_object.h"
-#include "../blender/editors/include/ED_particle.h"
-#include "../blender/editors/include/ED_render.h"
-#include "../blender/editors/include/ED_screen.h"
-#include "../blender/editors/include/ED_space_api.h"
-#include "../blender/editors/include/ED_text.h"
-#include "../blender/editors/include/ED_transform.h"
-#include "../blender/editors/include/ED_transform_snap_object_context.h"
-#include "../blender/editors/include/ED_uvedit.h"
-#include "../blender/editors/include/ED_view3d.h"
-#include "../blender/editors/include/UI_interface.h"
-#include "../blender/editors/include/UI_interface_icons.h"
-#include "../blender/editors/include/UI_resources.h"
-#include "../blender/editors/include/UI_view2d.h"
-#include "../blender/freestyle/FRS_freestyle.h"
-#include "../blender/python/BPY_extern.h"
-#include "../blender/render/extern/include/RE_engine.h"
-#include "../blender/render/extern/include/RE_pipeline.h"
-#include "../blender/render/extern/include/RE_render_ext.h"
-#include "../blender/render/extern/include/RE_shader_ext.h"
-#include "../blender/windowmanager/WM_api.h"
-
-
-/* -------------------------------------------------------------------- */
-/* Externs
- * (ideally we wouldn't have _any_ but we can't include all directly)
- */
-
-/* bpy_operator_wrap.h */
-extern void macro_wrapper(struct wmOperatorType *ot, void *userdata);
-extern void operator_wrapper(struct wmOperatorType *ot, void *userdata);
-/* bpy_rna.h */
-extern bool pyrna_id_FromPyObject(struct PyObject *obj, struct ID **id);
-extern const char *BPY_app_translations_py_pgettext(const char *msgctxt, const char *msgid);
-extern const char *BPY_app_translations_py_pgettext(const char *msgctxt, const char *msgid);
-extern struct PyObject *pyrna_id_CreatePyObject(struct ID *id);
-extern bool pyrna_id_CheckPyObject(struct PyObject *obj);
-/* bpy_interface.c */
-bool BPY_string_is_keyword(const char *str) { return false; }
-
-#endif
-/* end declarations */
-
-
-/* -------------------------------------------------------------------- */
-/* Return Macro's */
-
-#include <string.h> /* memset */
-#define RET_NULL {STUB_ASSERT(0); return (void *) NULL;}
-#define RET_ZERO {STUB_ASSERT(0); return 0;}
-#define RET_MINUSONE {STUB_ASSERT(0); return -1;}
-#define RET_STRUCT(t) {struct t v; STUB_ASSERT(0); memset(&v, 0, sizeof(v)); return v;}
-#define RET_ARG(arg) {STUB_ASSERT(0); return arg; }
-#define RET_NONE {STUB_ASSERT(0);}
-
-
-/* -------------------------------------------------------------------- */
-/* Stubs */
-
-/*new render funcs */
-void EDBM_selectmode_set(struct BMEditMesh *em) RET_NONE
-void EDBM_mesh_load(struct Object *ob) RET_NONE
-void EDBM_mesh_make(struct Object *ob, const int select_mode, const bool use_key_index) RET_NONE
-void EDBM_mesh_normals_update(struct BMEditMesh *em) RET_NONE
-void *g_system;
-bool EDBM_uv_check(struct BMEditMesh *em) RET_ZERO
-
-float *RE_RenderLayerGetPass(volatile struct RenderLayer *rl, const char *name, const char *viewname) RET_NULL
-float RE_filter_value(int type, float x) RET_ZERO
-struct RenderLayer *RE_GetRenderLayer(struct RenderResult *rr, const char *name) RET_NULL
-void RE_texture_rng_init() RET_NONE
-void RE_texture_rng_exit() RET_NONE
-
-bool RE_layers_have_name(struct RenderResult *result) RET_ZERO
-const char *RE_engine_active_view_get(struct RenderEngine *engine) RET_NULL
-void RE_engine_active_view_set(struct RenderEngine *engine, const char *viewname) RET_NONE
-void RE_engine_get_camera_model_matrix(struct RenderEngine *engine, struct Object *camera, int use_spherical_stereo, float *r_modelmat) RET_NONE
-float RE_engine_get_camera_shift_x(struct RenderEngine *engine, struct Object *camera, int use_spherical_stereo) RET_ZERO
-int RE_engine_get_spherical_stereo(struct RenderEngine *engine, struct Object *camera) RET_ZERO
-void RE_SetActiveRenderView(struct Render *re, const char *viewname) RET_NONE
-
-struct RenderPass *RE_pass_find_by_name(volatile struct RenderLayer *rl, const char *name, const char *viewname) RET_NULL
-struct RenderPass *RE_pass_find_by_type(volatile struct RenderLayer *rl, int passtype, const char *viewname) RET_NULL
-bool RE_HasCombinedLayer(RenderResult *res) RET_ZERO
-
-/* imagetexture.c stub */
-void ibuf_sample(struct ImBuf *ibuf, float fx, float fy, float dx, float dy, float *result) RET_NONE
-
-/* Freestyle */
-bool ED_texture_context_check_linestyle(const struct bContext *C) RET_ZERO
-void FRS_free_view_map_cache(void) RET_NONE
-
-/* texture.c */
-int multitex_ext(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, short thread, struct ImagePool *pool, bool scene_color_manage, const bool skip_load_image) RET_ZERO
-int multitex_ext_safe(struct Tex *tex, float texvec[3], struct TexResult *texres, struct ImagePool *pool, bool scene_color_manage, const bool skip_load_image) RET_ZERO
-int multitex_nodes(struct Tex *tex, float texvec[3], float dxt[3], float dyt[3], int osatex, struct TexResult *texres, const short thread, short which_output, struct ShadeInput *shi, struct MTex *mtex, struct ImagePool *pool) RET_ZERO
-
-struct Material *RE_sample_material_init(struct Material *orig_mat, struct Scene *scene) RET_NULL
-void RE_sample_material_free(struct Material *mat) RET_NONE
-void RE_sample_material_color(
- struct Material *mat, float color[3], float *alpha, const float volume_co[3], const float surface_co[3],
- int tri_index, struct DerivedMesh *orcoDm, struct Object *ob) RET_NONE
-/* nodes */
-struct Render *RE_GetRender(const char *name) RET_NULL
-struct Render *RE_GetSceneRender(const struct Scene *scene) RET_NULL
-struct Object *RE_GetCamera(struct Render *re) RET_NULL
-float RE_lamp_get_data(struct ShadeInput *shi, struct Object *lamp_obj, float col[4], float lv[3], float *dist, float shadow[4]) RET_ZERO
-const float (*RE_object_instance_get_matrix(struct ObjectInstanceRen *obi, int matrix_id))[4] RET_NULL
-const float (*RE_render_current_get_matrix(int matrix_id))[4] RET_NULL
-float RE_object_instance_get_object_pass_index(struct ObjectInstanceRen *obi) RET_ZERO
-float RE_object_instance_get_random_id(struct ObjectInstanceRen *obi) RET_ZERO
-
-/* blenkernel */
-bool BKE_paint_proj_mesh_data_check(struct Scene *scene, struct Object *ob, bool *uvs, bool *mat, bool *tex, bool *stencil) RET_ZERO
-
-/* render */
-void RE_FreeRenderResult(struct RenderResult *res) RET_NONE
-void RE_FreeAllRenderResults(void) RET_NONE
-struct RenderResult *RE_MultilayerConvert(void *exrhandle, const char *colorspace, bool predivide, int rectx, int recty) RET_NULL
-struct Scene *RE_GetScene(struct Render *re) RET_NULL
-void RE_Database_Free(struct Render *re) RET_NONE
-void RE_FreeRender(struct Render *re) RET_NONE
-void RE_DataBase_GetView(struct Render *re, float mat[4][4]) RET_NONE
-int externtex(
- const struct MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, float *tb, float *ta,
- const int thread, struct ImagePool *pool, const bool skip_load_image, const bool texnode_preview) RET_ZERO
-float texture_value_blend(float tex, float out, float fact, float facg, int blendtype) RET_ZERO
-void texture_rgb_blend(float in[3], const float tex[3], const float out[3], float fact, float facg, int blendtype) RET_NONE
-double elbeemEstimateMemreq(int res, float sx, float sy, float sz, int refine, char *retstr) RET_ZERO
-struct Render *RE_NewRender(const char *name) RET_NULL
-struct Render *RE_NewSceneRender(const struct Scene *scene) RET_NULL
-void RE_SwapResult(struct Render *re, struct RenderResult **rr) RET_NONE
-void RE_BlenderFrame(struct Render *re, struct Main *bmain, struct Scene *scene, struct SceneRenderLayer *srl, struct Object *camera_override, unsigned int lay_override, int frame, const bool write_still) RET_NONE
-bool RE_WriteEnvmapResult(struct ReportList *reports, struct Scene *scene, struct EnvMap *env, const char *relpath, const char imtype, float layout[12]) RET_ZERO
-
-/* rna */
-float *ED_view3d_cursor3d_get(struct Scene *scene, struct View3D *v3d) RET_NULL
-void WM_menutype_free(void) RET_NONE
-void WM_menutype_freelink(struct MenuType *mt) RET_NONE
-bool WM_menutype_add(struct MenuType *mt) RET_ZERO
-int WM_operator_props_dialog_popup(struct bContext *C, struct wmOperator *op, int width, int height) RET_ZERO
-int WM_operator_confirm(struct bContext *C, struct wmOperator *op, const struct wmEvent *event) RET_ZERO
-struct MenuType *WM_menutype_find(const char *idname, bool quiet) RET_NULL
-void WM_operator_stack_clear(struct wmWindowManager *wm) RET_NONE
-void WM_operator_handlers_clear(wmWindowManager *wm, struct wmOperatorType *ot) RET_NONE
-bool WM_operator_is_repeat(const struct bContext *C, const struct wmOperator *op) RET_ZERO;
-
-void WM_autosave_init(wmWindowManager *wm) RET_NONE
-void WM_jobs_kill_all_except(struct wmWindowManager *wm, void *owner) RET_NONE
-
-void WM_lib_reload(struct Library *lib, struct bContext *C, struct ReportList *reports) RET_NONE
-
-char *WM_clipboard_text_get(bool selection, int *r_len) RET_NULL
-char *WM_clipboard_text_get_firstline(bool selection, int *r_len) RET_NULL
-void WM_clipboard_text_set(const char *buf, bool selection) RET_NONE
-
-void WM_cursor_set(struct wmWindow *win, int curor) RET_NONE
-void WM_cursor_modal_set(struct wmWindow *win, int curor) RET_NONE
-void WM_cursor_modal_restore(struct wmWindow *win) RET_NONE
-void WM_cursor_time(struct wmWindow *win, int nr) RET_NONE
-void WM_cursor_warp(struct wmWindow *win, int x, int y) RET_NONE
-
-struct wmJob *WM_jobs_get(struct wmWindowManager *wm, struct wmWindow *win, void *owner, const char *name, int flag, int job_type) RET_NULL
-void WM_jobs_customdata_set(struct wmJob *job, void *customdata, void (*free)(void *)) RET_NONE
-void WM_jobs_timer(struct wmJob *job, double timestep, unsigned int note, unsigned int endnote) RET_NONE
-
-void WM_jobs_callbacks(struct wmJob *job,
- void (*startjob)(void *, short *, short *, float *),
- void (*initjob)(void *),
- void (*update)(void *),
- void (*endjob)(void *)) RET_NONE
-
-void WM_jobs_start(struct wmWindowManager *wm, struct wmJob *job) RET_NONE
-void WM_report(ReportType type, const char *message) RET_NONE
-
-#ifdef WITH_INPUT_NDOF
- void WM_ndof_deadzone_set(float deadzone) RET_NONE
-#endif
-
-void WM_uilisttype_init(void) RET_NONE
-struct uiListType *WM_uilisttype_find(const char *idname, bool quiet) RET_NULL
-bool WM_uilisttype_add(struct uiListType *ult) RET_ZERO
-void WM_uilisttype_freelink(struct uiListType *ult) RET_NONE
-void WM_uilisttype_free(void) RET_NONE
-
-struct wmKeyMapItem *WM_keymap_item_find_id(struct wmKeyMap *keymap, int id) RET_NULL
-int WM_enum_search_invoke(struct bContext *C, struct wmOperator *op, const struct wmEvent *event) RET_ZERO
-void WM_event_add_notifier(const struct bContext *C, unsigned int type, void *reference) RET_NONE
-void WM_main_add_notifier(unsigned int type, void *reference) RET_NONE
-void ED_armature_bone_rename(struct bArmature *arm, const char *oldnamep, const char *newnamep) RET_NONE
-void ED_armature_transform(struct bArmature *arm, float mat[4][4], const bool do_props) RET_NONE
-struct wmEventHandler *WM_event_add_modal_handler(struct bContext *C, struct wmOperator *op) RET_NULL
-struct wmTimer *WM_event_add_timer(struct wmWindowManager *wm, struct wmWindow *win, int event_type, double timestep) RET_NULL
-void WM_event_remove_timer(struct wmWindowManager *wm, struct wmWindow *win, struct wmTimer *timer) RET_NONE
-float WM_event_tablet_data(const struct wmEvent *event, int *pen_flip, float tilt[2]) RET_ZERO
-bool WM_event_is_tablet(const struct wmEvent *event) RET_ZERO
-void ED_armature_ebone_remove(struct bArmature *arm, struct EditBone *exBone) RET_NONE
-void object_test_constraints(struct Object *owner) RET_NONE
-void ED_armature_ebone_to_mat4(struct EditBone *ebone, float mat[4][4]) RET_NONE
-void ED_armature_ebone_from_mat4(EditBone *ebone, float mat[4][4]) RET_NONE
-void ED_object_parent(struct Object *ob, struct Object *par, int type, const char *substr) RET_NONE
-void ED_object_constraint_set_active(struct Object *ob, struct bConstraint *con) RET_NONE
-void ED_node_composit_default(const struct bContext *C, struct Scene *scene) RET_NONE
-void *ED_region_draw_cb_activate(struct ARegionType *art, void(*draw)(const struct bContext *, struct ARegion *, void *), void *custumdata, int type) RET_ZERO /* XXX this one looks weird */
-void *ED_region_draw_cb_customdata(void *handle) RET_ZERO /* XXX This one looks wrong also */
-void ED_region_draw_cb_exit(struct ARegionType *art, void *handle) RET_NONE
-void ED_area_headerprint(struct ScrArea *sa, const char *str) RET_NONE
-void ED_gpencil_parent_location(struct bGPDlayer *gpl, float diff_mat[4][4]) RET_NONE
-void UI_view2d_region_to_view(struct View2D *v2d, float x, float y, float *viewx, float *viewy) RET_NONE
-bool UI_view2d_view_to_region_clip(struct View2D *v2d, float x, float y, int *regionx, int *regiony) RET_ZERO
-void UI_view2d_view_to_region(struct View2D *v2d, float x, float y, int *regionx, int *region_y) RET_NONE
-void UI_view2d_sync(struct bScreen *screen, struct ScrArea *sa, struct View2D *v2dcur, int flag) RET_NONE
-
-struct EditBone *ED_armature_ebone_get_mirrored(const struct ListBase *edbo, EditBone *ebo) RET_NULL
-struct EditBone *ED_armature_ebone_add(struct bArmature *arm, const char *name) RET_NULL
-struct ListBase *get_active_constraints (struct Object *ob) RET_NULL
-struct ListBase *get_constraint_lb(struct Object *ob, struct bConstraint *con, struct bPoseChannel **r_pchan) RET_NULL
-
-bool ED_space_image_show_uvedit(struct SpaceImage *sima, struct Object *obedit) RET_ZERO
-bool ED_space_image_show_render(struct SpaceImage *sima) RET_ZERO
-bool ED_space_image_show_paint(struct SpaceImage *sima) RET_ZERO
-void ED_space_image_paint_update(struct wmWindowManager *wm, struct Scene *scene) RET_NONE
-void ED_space_image_set(struct SpaceImage *sima, struct Scene *scene, struct Object *obedit, struct Image *ima) RET_NONE
-void ED_space_image_uv_sculpt_update(struct wmWindowManager *wm, struct Scene *scene) RET_NONE
-void ED_space_image_scopes_update(const struct bContext *C, struct SpaceImage *sima, struct ImBuf *ibuf, bool use_view_settings) RET_NONE
-
-void ED_uvedit_get_aspect(struct Scene *scene, struct Object *ob, struct BMesh *em, float *aspx, float *aspy) RET_NONE
-
-void ED_screen_set_scene(struct bContext *C, struct bScreen *screen, struct Scene *scene) RET_NONE
-struct MovieClip *ED_space_clip_get_clip(struct SpaceClip *sc) RET_NULL
-void ED_space_clip_set_clip(struct bContext *C, struct bScreen *screen, struct SpaceClip *sc, struct MovieClip *clip) RET_NONE
-void ED_space_clip_set_mask(struct bContext *C, struct SpaceClip *sc, struct Mask *mask) RET_NONE
-void ED_space_image_set_mask(struct bContext *C, struct SpaceImage *sima, struct Mask *mask) RET_NONE
-
-void ED_area_tag_redraw_regiontype(struct ScrArea *sa, int regiontype) RET_NONE
-void ED_render_engine_changed(struct Main *bmain) RET_NONE
-
-void ED_file_read_bookmarks(void) RET_NONE
-void ED_file_change_dir(struct bContext *C) RET_NONE
-void ED_preview_kill_jobs(struct wmWindowManager *wm, struct Main *bmain) RET_NONE
-struct FSMenu *ED_fsmenu_get(void) RET_NULL
-struct FSMenuEntry *ED_fsmenu_get_category(struct FSMenu *fsmenu, FSMenuCategory category) RET_NULL
-int ED_fsmenu_get_nentries(struct FSMenu *fsmenu, FSMenuCategory category) RET_ZERO
-struct FSMenuEntry *ED_fsmenu_get_entry(struct FSMenu *fsmenu, FSMenuCategory category, int index) RET_NULL
-char *ED_fsmenu_entry_get_path(struct FSMenuEntry *fsentry) RET_NULL
-void ED_fsmenu_entry_set_path(struct FSMenuEntry *fsentry, const char *name) RET_NONE
-char *ED_fsmenu_entry_get_name(struct FSMenuEntry *fsentry) RET_NULL
-void ED_fsmenu_entry_set_name(struct FSMenuEntry *fsentry, const char *name) RET_NONE
-
-struct PTCacheEdit *PE_get_current(struct Scene *scene, struct Object *ob) RET_NULL
-void PE_current_changed(struct Scene *scene, struct Object *ob) RET_NONE
-
-/* rna keymap */
-struct wmKeyMap *WM_keymap_active(struct wmWindowManager *wm, struct wmKeyMap *keymap) RET_NULL
-struct wmKeyMap *WM_keymap_find(struct wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid) RET_NULL
-struct wmKeyMapItem *WM_keymap_add_item(struct wmKeyMap *keymap, const char *idname, int type, int val, int modifier, int keymodifier) RET_NULL
-struct wmKeyMap *WM_keymap_list_find(ListBase *lb, const char *idname, int spaceid, int regionid) RET_NULL
-struct wmKeyConfig *WM_keyconfig_new(struct wmWindowManager *wm, const char *idname) RET_NULL
-struct wmKeyConfig *WM_keyconfig_new_user(struct wmWindowManager *wm, const char *idname) RET_NULL
-bool WM_keyconfig_remove(struct wmWindowManager *wm, struct wmKeyConfig *keyconf) RET_ZERO
-bool WM_keymap_remove(struct wmKeyConfig *keyconfig, struct wmKeyMap *keymap) RET_ZERO
-void WM_keyconfig_set_active(struct wmWindowManager *wm, const char *idname) RET_NONE
-bool WM_keymap_remove_item(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi) RET_ZERO
-void WM_keymap_restore_to_default(struct wmKeyMap *keymap, struct bContext *C) RET_NONE
-void WM_keymap_restore_item_to_default(struct bContext *C, struct wmKeyMap *keymap, struct wmKeyMapItem *kmi) RET_NONE
-void WM_keymap_properties_reset(struct wmKeyMapItem *kmi, struct IDProperty *properties) RET_NONE
-void WM_keyconfig_update_tag(struct wmKeyMap *keymap, struct wmKeyMapItem *kmi) RET_NONE
-int WM_keymap_item_compare(struct wmKeyMapItem *k1, struct wmKeyMapItem *k2) RET_ZERO
-int WM_keymap_map_type_get(struct wmKeyMapItem *kmi) RET_ZERO
-
-
-/* rna editors */
-
-struct FCurve *verify_fcurve(struct bAction *act, const char group[], struct PointerRNA *ptr, const char rna_path[], const int array_index, short add) RET_NULL
-int insert_vert_fcurve(struct FCurve *fcu, float x, float y, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag) RET_ZERO
-void delete_fcurve_key(struct FCurve *fcu, int index, bool do_recalc) RET_NONE
-struct KeyingSetInfo *ANIM_keyingset_info_find_name (const char name[]) RET_NULL
-struct KeyingSet *ANIM_scene_get_active_keyingset (struct Scene *scene) RET_NULL
-int ANIM_scene_get_keyingset_index(struct Scene *scene, struct KeyingSet *ks) RET_ZERO
-void ANIM_id_update(struct Scene *scene, struct ID *id) RET_NONE
-struct ListBase builtin_keyingsets;
-void ANIM_keyingset_info_register(struct KeyingSetInfo *ksi) RET_NONE
-void ANIM_keyingset_info_unregister(struct Main *bmain, KeyingSetInfo *ksi) RET_NONE
-short ANIM_validate_keyingset(struct bContext *C, struct ListBase *dsources, struct KeyingSet *ks) RET_ZERO
-int ANIM_add_driver(struct ReportList *reports, struct ID *id, const char rna_path[], int array_index, short flag, int type) RET_ZERO
-bool ANIM_remove_driver(struct ReportList *reports, struct ID *id, const char rna_path[], int array_index, short flag) RET_ZERO
-void ED_space_image_release_buffer(struct SpaceImage *sima, struct ImBuf *ibuf, void *lock) RET_NONE
-struct ImBuf *ED_space_image_acquire_buffer(struct SpaceImage *sima, void **r_lock) RET_NULL
-void ED_space_image_get_zoom(struct SpaceImage *sima, struct ARegion *ar, float *zoomx, float *zoomy) RET_NONE
-const char *ED_info_stats_string(struct Scene *scene) RET_NULL
-void ED_area_tag_redraw(struct ScrArea *sa) RET_NONE
-void ED_area_tag_refresh(struct ScrArea *sa) RET_NONE
-void ED_area_newspace(struct bContext *C, struct ScrArea *sa, int type, const bool skip_ar_exit) RET_NONE
-void ED_region_tag_redraw(struct ARegion *ar) RET_NONE
-void WM_event_add_fileselect(struct bContext *C, struct wmOperator *op) RET_NONE
-void WM_cursor_wait(bool val) RET_NONE
-void ED_node_texture_default(const struct bContext *C, struct Tex *tex) RET_NONE
-void ED_node_tag_update_id(struct ID *id) RET_NONE
-void ED_node_tag_update_nodetree(struct Main *bmain, struct bNodeTree *ntree, struct bNode *node) RET_NONE
-void ED_node_tree_update(const struct bContext *C) RET_NONE
-void ED_node_set_tree_type(struct SpaceNode *snode, struct bNodeTreeType *typeinfo) RET_NONE
-void ED_init_custom_node_type(struct bNodeType *ntype) RET_NONE
-void ED_init_custom_node_socket_type(struct bNodeSocketType *stype) RET_NONE
-void ED_init_standard_node_socket_type(struct bNodeSocketType *stype) RET_NONE
-void ED_init_node_socket_type_virtual(struct bNodeSocketType *stype) RET_NONE
-int ED_node_tree_path_length(struct SpaceNode *snode) RET_ZERO
-void ED_node_tree_path_get(struct SpaceNode *snode, char *value) RET_NONE
-void ED_node_tree_path_get_fixedbuf(struct SpaceNode *snode, char *value, int max_length) RET_NONE
-void ED_node_tree_start(struct SpaceNode *snode, struct bNodeTree *ntree, struct ID *id, struct ID *from) RET_NONE
-void ED_node_tree_push(struct SpaceNode *snode, struct bNodeTree *ntree, struct bNode *gnode) RET_NONE
-void ED_node_tree_pop(struct SpaceNode *snode) RET_NONE
-int ED_view3d_scene_layer_set(int lay, const int *values, int *active) RET_ZERO
-void ED_view3d_quadview_update(struct ScrArea *sa, struct ARegion *ar, bool do_clip) RET_NONE
-void ED_view3d_from_m4(float mat[4][4], float ofs[3], float quat[4], float *dist) RET_NONE
-struct BGpic *ED_view3d_background_image_new(struct View3D *v3d) RET_NULL
-void ED_view3d_background_image_remove(struct View3D *v3d, struct BGpic *bgpic) RET_NONE
-void ED_view3d_background_image_clear(struct View3D *v3d) RET_NONE
-void ED_view3d_update_viewmat(struct Scene *scene, struct View3D *v3d, struct ARegion *ar, float viewmat[4][4], float winmat[4][4], const struct rcti *rect) RET_NONE
-float ED_view3d_grid_scale(struct Scene *scene, struct View3D *v3d, const char **grid_unit) RET_ZERO
-void ED_view3d_shade_update(struct Main *bmain, struct View3D *v3d, struct ScrArea *sa) RET_NONE
-void ED_node_shader_default(const struct bContext *C, struct ID *id) RET_NONE
-void ED_screen_animation_timer_update(struct bScreen *screen, int redraws, int refresh) RET_NONE
-struct bScreen *ED_screen_animation_playing(const struct wmWindowManager *wm) RET_NULL
-void ED_base_object_select(struct Base *base, short mode) RET_NONE
-bool ED_object_modifier_remove(struct ReportList *reports, struct Main *bmain, struct Object *ob, struct ModifierData *md) RET_ZERO
-struct ModifierData *ED_object_modifier_add(struct ReportList *reports, struct Main *bmain, struct Scene *scene, struct Object *ob, const char *name, int type) RET_ZERO
-void ED_object_modifier_clear(struct Main *bmain, struct Object *ob) RET_NONE
-void ED_object_editmode_enter(struct bContext *C, int flag) RET_NONE
-void ED_object_editmode_exit(struct bContext *C, int flag) RET_NONE
-bool ED_object_editmode_load(struct Object *obedit) RET_ZERO
-void ED_object_check_force_modifiers(struct Main *bmain, struct Scene *scene, struct Object *object) RET_NONE
-bool uiLayoutGetActive(struct uiLayout *layout) RET_ZERO
-int uiLayoutGetOperatorContext(struct uiLayout *layout) RET_ZERO
-int uiLayoutGetAlignment(struct uiLayout *layout) RET_ZERO
-bool uiLayoutGetEnabled(struct uiLayout *layout) RET_ZERO
-float uiLayoutGetScaleX(struct uiLayout *layout) RET_ZERO
-float uiLayoutGetScaleY(struct uiLayout *layout) RET_ZERO
-void uiLayoutSetActive(struct uiLayout *layout, bool active) RET_NONE
-void uiLayoutSetOperatorContext(struct uiLayout *layout, int opcontext) RET_NONE
-void uiLayoutSetEnabled(uiLayout *layout, bool enabled) RET_NONE
-void uiLayoutSetAlignment(uiLayout *layout, char alignment) RET_NONE
-void uiLayoutSetScaleX(struct uiLayout *layout, float scale) RET_NONE
-void uiLayoutSetScaleY(struct uiLayout *layout, float scale) RET_NONE
-void uiTemplateIconView(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname, int show_labels, float icon_scale) RET_NONE
-void ED_base_object_free_and_unlink(struct Main *bmain, struct Scene *scene, struct Base *base) RET_NONE
-void ED_mesh_update(struct Mesh *mesh, struct bContext *C, int calc_edges, int calc_tessface) RET_NONE
-void ED_mesh_vertices_add(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-void ED_mesh_edges_add(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-void ED_mesh_tessfaces_add(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-void ED_mesh_loops_add(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-void ED_mesh_polys_add(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-void ED_mesh_vertices_remove(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-void ED_mesh_edges_remove(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-void ED_mesh_faces_remove(struct Mesh *mesh, struct ReportList *reports, int count) RET_NONE
-int ED_mesh_color_add(struct Mesh *me, const char *name, const bool active_set) RET_MINUSONE
-int ED_mesh_uv_texture_add(struct Mesh *me, const char *name, const bool active_set) RET_MINUSONE
-bool ED_mesh_color_remove_named(struct Mesh *me, const char *name) RET_ZERO
-bool ED_mesh_uv_texture_remove_named(struct Mesh *me, const char *name) RET_ZERO
-void ED_object_constraint_dependency_update(struct Main *bmain, struct Object *ob) RET_NONE
-void ED_object_constraint_dependency_tag_update(struct Main *bmain, struct Object *ob, struct bConstraint *con) RET_NONE
-void ED_object_constraint_update(struct Object *ob) RET_NONE
-void ED_object_constraint_tag_update(struct Object *ob, struct bConstraint *con) RET_NONE
-void ED_vgroup_vert_add(struct Object *ob, struct bDeformGroup *dg, int vertnum, float weight, int assignmode) RET_NONE
-void ED_vgroup_vert_remove(struct Object *ob, struct bDeformGroup *dg, int vertnum) RET_NONE
-float ED_vgroup_vert_weight(struct Object *ob, struct bDeformGroup *dg, int vertnum) RET_ZERO
-int ED_mesh_mirror_topo_table(struct Object *ob, struct DerivedMesh *dm, char mode) RET_ZERO
-int ED_mesh_mirror_spatial_table(struct Object *ob, struct BMEditMesh *em, struct DerivedMesh *dm, const float co[3], char mode) RET_ZERO
-
-float ED_armature_ebone_roll_to_vector(const EditBone *bone, const float new_up_axis[3], const bool axis_only) RET_ZERO
-void ED_space_image_get_size(struct SpaceImage *sima, int *width, int *height) RET_NONE
-bool ED_space_image_check_show_maskedit(struct Scene *scene, struct SpaceImage *sima) RET_ZERO
-
-bool ED_texture_context_check_world(const struct bContext *C) RET_ZERO
-bool ED_texture_context_check_material(const struct bContext *C) RET_ZERO
-bool ED_texture_context_check_lamp(const struct bContext *C) RET_ZERO
-bool ED_texture_context_check_particles(const struct bContext *C) RET_ZERO
-bool ED_texture_context_check_others(const struct bContext *C) RET_ZERO
-
-bool ED_text_region_location_from_cursor(SpaceText *st, ARegion *ar, const int cursor_co[2], int r_pixel_co[2]) RET_ZERO
-
-SnapObjectContext *ED_transform_snap_object_context_create(
- struct Main *bmain, struct Scene *scene, int flag) RET_NULL
-SnapObjectContext *ED_transform_snap_object_context_create_view3d(
- struct Main *bmain, struct Scene *scene, int flag,
- const struct ARegion *ar, const struct View3D *v3d) RET_NULL
-void ED_transform_snap_object_context_destroy(SnapObjectContext *sctx) RET_NONE
-bool ED_transform_snap_object_project_ray_ex(
- struct SnapObjectContext *sctx,
- const struct SnapObjectParams *params,
- const float ray_start[3], const float ray_normal[3], float *ray_depth,
- /* return args */
- float r_loc[3], float r_no[3], int *r_index,
- struct Object **r_ob, float r_obmat[4][4]) RET_ZERO
-
-void ED_curve_editnurb_load(struct Object *obedit) RET_NONE
-void ED_curve_editnurb_make(struct Object *obedit) RET_NONE
-
-void uiItemR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int flag, const char *name, int icon) RET_NONE
-
-void uiItemFullO(uiLayout *layout, const char *idname, const char *name, int icon, struct IDProperty *properties, int context, int flag, struct PointerRNA *r_opptr) RET_NONE
-void uiItemFullO_ptr(struct uiLayout *layout, struct wmOperatorType *ot, const char *name, int icon, struct IDProperty *properties, int context, int flag, struct PointerRNA *r_opptr) RET_NONE
-void uiItemFullOMenuHold_ptr( uiLayout *layout, struct wmOperatorType *ot, const char *name, int icon, struct IDProperty *properties, int context, int flag, const char *menu_id, /* extra menu arg. */ PointerRNA *r_opptr) RET_NONE
-struct uiLayout *uiLayoutRow(uiLayout *layout, int align) RET_NULL
-struct uiLayout *uiLayoutColumn(uiLayout *layout, int align) RET_NULL
-struct uiLayout *uiLayoutColumnFlow(uiLayout *layout, int number, int align) RET_NULL
-struct uiLayout *uiLayoutBox(struct uiLayout *layout) RET_NULL
-struct uiLayout *uiLayoutSplit(uiLayout *layout, float percentage, int align) RET_NULL
-bool uiLayoutGetRedAlert(struct uiLayout *layout) RET_ZERO
-void uiLayoutSetRedAlert(uiLayout *layout, bool redalert) RET_NONE
-void uiItemsEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname) RET_NONE
-void uiItemMenuEnumR_prop(uiLayout *layout, struct PointerRNA *ptr, PropertyRNA *prop, const char *name, int icon) RET_NONE
-void uiItemMenuEnumR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name, int icon) RET_NONE
-void uiItemEnumR_string(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *value, const char *name, int icon) RET_NONE
-void uiItemPointerR(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *searchptr, const char *searchpropname, const char *name, int icon) RET_NONE
-void uiItemsEnumO(uiLayout *layout, const char *opname, const char *propname) RET_NONE
-void uiItemEnumO_string(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, const char *value) RET_NONE
-void uiItemMenuEnumO(uiLayout *layout, struct bContext *C, const char *opname, const char *propname, const char *name, int icon) RET_NONE
-void uiItemMenuEnumO_ptr(uiLayout *layout, struct bContext *C, struct wmOperatorType *ot, const char *propname, const char *name, int icon) RET_NONE
-void uiItemBooleanO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, int value) RET_NONE
-void uiItemIntO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, int value) RET_NONE
-void uiItemFloatO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, float value) RET_NONE
-void uiItemStringO(uiLayout *layout, const char *name, int icon, const char *opname, const char *propname, const char *value) RET_NONE
-void uiItemL(struct uiLayout *layout, const char *name, int icon) RET_NONE
-void uiItemM(uiLayout *layout, struct bContext *C, const char *menuname, const char *name, int icon) RET_NONE
-void uiItemS(struct uiLayout *layout) RET_NONE
-void uiItemFullR(uiLayout *layout, struct PointerRNA *ptr, struct PropertyRNA *prop, int index, int value, int flag, const char *name, int icon) RET_NONE
-void uiLayoutSetContextPointer(uiLayout *layout, const char *name, struct PointerRNA *ptr) RET_NONE
-const char *uiLayoutIntrospect(uiLayout *layout) RET_NULL
-void UI_reinit_font(void) RET_NONE
-int UI_rnaptr_icon_get(struct bContext *C, struct PointerRNA *ptr, int rnaicon, const bool big) RET_ZERO
-struct bTheme *UI_GetTheme(void) RET_NULL
-
-/* rna template */
-void uiTemplateAnyID(uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *proptypename, const char *text) RET_NONE
-void uiTemplatePathBuilder(uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *root_ptr, const char *text) RET_NONE
-void uiTemplateHeader(struct uiLayout *layout, struct bContext *C) RET_NONE
-void uiTemplateID(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int filter) RET_NONE
-struct uiLayout *uiTemplateModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr) RET_NULL
-struct uiLayout *uiTemplateConstraint(struct uiLayout *layout, struct PointerRNA *ptr) RET_NULL
-void uiTemplatePreview(struct uiLayout *layout, struct bContext *C, struct ID *id, int show_buttons, struct ID *parent,
- struct MTex *slot, const char *preview_id) RET_NONE
-void uiTemplateIDPreview(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, const char *newop, const char *openop, const char *unlinkop, int rows, int cols, int filter) RET_NONE
-void uiTemplateCurveMapping(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int type, int levels, int brush, int neg_slope) RET_NONE
-void uiTemplateColorRamp(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int expand) RET_NONE
-void uiTemplateLayers(uiLayout *layout, struct PointerRNA *ptr, const char *propname, PointerRNA *used_ptr, const char *used_propname, int active_layer) RET_NONE
-void uiTemplateImageLayers(struct uiLayout *layout, struct bContext *C, struct Image *ima, struct ImageUser *iuser) RET_NONE
-void uiTemplateList(struct uiLayout *layout, struct bContext *C, const char *listtype_name, const char *list_id,
- PointerRNA *dataptr, const char *propname, PointerRNA *active_dataptr, const char *active_propname,
- const char *item_dyntip_propname, int rows, int maxrows, int layout_type, int columns) RET_NONE
-void uiTemplateRunningJobs(struct uiLayout *layout, struct bContext *C) RET_NONE
-void uiTemplateOperatorSearch(struct uiLayout *layout) RET_NONE
-void uiTemplateHeader3D(struct uiLayout *layout, struct bContext *C) RET_NONE
-void uiTemplateEditModeSelection(struct uiLayout *layout, struct bContext *C) RET_NONE
-void uiTemplateImage(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, struct PointerRNA *userptr, int compact, int multiview) RET_NONE
-void uiTemplateColorPicker(uiLayout *layout, struct PointerRNA *ptr, const char *propname, int value_slider, int lock, int lock_luminosity, int cubic) RET_NONE
-void uiTemplateHistogram(uiLayout *layout, struct PointerRNA *ptr, const char *propname) RET_NONE
-void uiTemplateReportsBanner(uiLayout *layout, struct bContext *C) RET_NONE
-void uiTemplateWaveform(uiLayout *layout, struct PointerRNA *ptr, const char *propname) RET_NONE
-void uiTemplateVectorscope(uiLayout *layout, struct PointerRNA *ptr, const char *propname) RET_NONE
-void uiTemplateNodeLink(struct uiLayout *layout, struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *input) RET_NONE
-void uiTemplateNodeView(struct uiLayout *layout, struct bContext *C, struct bNodeTree *ntree, struct bNode *node, struct bNodeSocket *input) RET_NONE
-void uiTemplateTextureUser(struct uiLayout *layout, struct bContext *C) RET_NONE
-void uiTemplateTextureShow(struct uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, struct PropertyRNA *prop) RET_NONE
-void uiTemplateKeymapItemProperties(struct uiLayout *layout, struct PointerRNA *ptr) RET_NONE
-void uiTemplateMovieClip(struct uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname, int compact) RET_NONE
-void uiTemplateMovieclipInformation(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname, struct PointerRNA *userptr) RET_NONE
-void uiTemplateTrack(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname) RET_NONE
-void uiTemplateMarker(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname, PointerRNA *userptr, PointerRNA *trackptr, int compact) RET_NONE
-void uiTemplateImageSettings(uiLayout *layout, struct PointerRNA *imfptr, int color_management) RET_NONE
-void uiTemplateColorspaceSettings(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname) RET_NONE
-void uiTemplateColormanagedViewSettings(struct uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname) RET_NONE
-void uiTemplateComponentMenu(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname, const char *name) RET_NONE
-void uiTemplateNodeSocket(struct uiLayout *layout, struct bContext *C, float *color) RET_NONE
-void uiTemplatePalette(struct uiLayout *layout, struct PointerRNA *ptr, const char *propname, int color) RET_NONE
-void uiTemplateImageStereo3d(struct uiLayout *layout, struct PointerRNA *stereo3d_format_ptr) RET_NONE
-void uiTemplateCacheFile(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr, const char *propname) RET_NONE
-
-/* rna render */
-struct RenderResult *RE_engine_begin_result(RenderEngine *engine, int x, int y, int w, int h, const char *layername, const char *viewname) RET_NULL
-struct RenderResult *RE_AcquireResultRead(struct Render *re) RET_NULL
-struct RenderResult *RE_AcquireResultWrite(struct Render *re) RET_NULL
-struct RenderResult *RE_engine_get_result(struct RenderEngine *re) RET_NULL
-struct RenderStats *RE_GetStats(struct Render *re) RET_NULL
-struct RenderData *RE_engine_get_render_data(struct Render *re) RET_NULL
-void RE_engine_update_result(struct RenderEngine *engine, struct RenderResult *result) RET_NONE
-void RE_engine_update_progress(struct RenderEngine *engine, float progress) RET_NONE
-void RE_engine_set_error_message(RenderEngine *engine, const char *msg) RET_NONE
-void RE_engine_add_pass(RenderEngine *engine, const char *name, int channels, const char *chan_id, const char *layername) RET_NONE
-void RE_engine_end_result(RenderEngine *engine, struct RenderResult *result, int cancel, int highlight, int merge_results) RET_NONE
-void RE_engine_update_stats(RenderEngine *engine, const char *stats, const char *info) RET_NONE
-void RE_layer_load_from_file(struct RenderLayer *layer, struct ReportList *reports, const char *filename, int x, int y) RET_NONE
-void RE_result_load_from_file(struct RenderResult *result, struct ReportList *reports, const char *filename) RET_NONE
-void RE_AcquireResultImage(struct Render *re, struct RenderResult *rr, const int view_id) RET_NONE
-void RE_ReleaseResult(struct Render *re) RET_NONE
-void RE_ReleaseResultImage(struct Render *re) RET_NONE
-int RE_engine_test_break(struct RenderEngine *engine) RET_ZERO
-void RE_engines_init() RET_NONE
-void RE_engines_exit() RET_NONE
-void RE_engine_report(struct RenderEngine *engine, int type, const char *msg) RET_NONE
-ListBase R_engines = {NULL, NULL};
-void RE_engine_free(struct RenderEngine *engine) RET_NONE
-struct RenderEngineType *RE_engines_find(const char *idname) RET_NULL
-void RE_engine_update_memory_stats(struct RenderEngine *engine, float mem_used, float mem_peak) RET_NONE
-struct RenderEngine *RE_engine_create(struct RenderEngineType *type) RET_NULL
-void RE_engine_frame_set(struct RenderEngine *engine, int frame, float subframe) RET_NONE
-void RE_FreePersistentData(void) RET_NONE
-void RE_point_density_cache(struct Scene *scene, struct PointDensity *pd, const bool use_render_params) RET_NONE
-void RE_point_density_minmax(struct Scene *scene, struct PointDensity *pd, const bool use_render_params, float r_min[3], float r_max[3]) RET_NONE
-void RE_point_density_sample(struct Scene *scene, struct PointDensity *pd, int resolution, const bool use_render_params, float *values) RET_NONE
-void RE_point_density_free(struct PointDensity *pd) RET_NONE
-void RE_instance_get_particle_info(struct ObjectInstanceRen *obi, float *index, float *random, float *age, float *lifetime, float co[3], float *size, float vel[3], float angvel[3]) RET_NONE
-void RE_FreeAllPersistentData(void) RET_NONE
-float RE_fresnel_dielectric(float incoming[3], float normal[3], float eta) RET_ZERO
-void RE_engine_register_pass(struct RenderEngine *engine, struct Scene *scene, struct SceneRenderLayer *srl, const char *name, int channels, const char *chanid, int type) RET_NONE
-
-/* python */
-struct wmOperatorType *WM_operatortype_find(const char *idname, bool quiet) RET_NULL
-void WM_operatortype_iter(struct GHashIterator *ghi) RET_NONE
-struct wmOperatorTypeMacro *WM_operatortype_macro_define(struct wmOperatorType *ot, const char *idname) RET_NULL
-int WM_operator_call_py(struct bContext *C, struct wmOperatorType *ot, short context, struct PointerRNA *properties, struct ReportList *reports, const bool is_undo) RET_ZERO
-void WM_operatortype_remove_ptr(struct wmOperatorType *ot) RET_NONE
-bool WM_operatortype_remove(const char *idname) RET_ZERO
-int WM_operator_poll(struct bContext *C, struct wmOperatorType *ot) RET_ZERO
-int WM_operator_poll_context(struct bContext *C, struct wmOperatorType *ot, short context) RET_ZERO
-int WM_operator_props_popup(struct bContext *C, struct wmOperator *op, const struct wmEvent *event) RET_ZERO
-void WM_operator_properties_free(struct PointerRNA *ptr) RET_NONE
-void WM_operator_properties_create(struct PointerRNA *ptr, const char *opstring) RET_NONE
-void WM_operator_properties_create_ptr(struct PointerRNA *ptr, struct wmOperatorType *ot) RET_NONE
-void WM_operator_properties_sanitize(struct PointerRNA *ptr, const bool no_context) RET_NONE
-void WM_operatortype_append_ptr(void (*opfunc)(struct wmOperatorType *, void *), void *userdata) RET_NONE
-void WM_operatortype_append_macro_ptr(void (*opfunc)(struct wmOperatorType *, void *), void *userdata) RET_NONE
-void WM_operator_bl_idname(char *to, const char *from) RET_NONE
-void WM_operator_py_idname(char *to, const char *from) RET_NONE
-bool WM_operator_py_idname_ok_or_report(struct ReportList *reports, const char *classname, const char *idname) RET_ZERO
-int WM_operator_ui_popup(struct bContext *C, struct wmOperator *op, int width, int height) RET_ZERO
-void update_autoflags_fcurve(struct FCurve *fcu, struct bContext *C, struct ReportList *reports, struct PointerRNA *ptr) RET_NONE
-short insert_keyframe(struct ReportList *reports, struct ID *id, struct bAction *act, const char group[], const char rna_path[], int array_index, float cfra, eBezTriple_KeyframeType keytype, eInsertKeyFlags flag) RET_ZERO
-short delete_keyframe(struct ReportList *reports, struct ID *id, struct bAction *act, const char group[], const char rna_path[], int array_index, float cfra, eInsertKeyFlags flag) RET_ZERO
-struct bAction *verify_adt_action(struct ID *id, short add) RET_NULL
-char *WM_operator_pystring_ex(struct bContext *C, struct wmOperator *op, const bool all_args, const bool macro_args, struct wmOperatorType *ot, struct PointerRNA *opptr) RET_NULL
-char *WM_operator_pystring(struct bContext *C, struct wmOperator *op, const bool all_args, const bool macro_args) RET_NULL
-struct wmKeyMapItem *WM_modalkeymap_add_item(struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, int value) RET_NULL
-struct wmKeyMapItem *WM_modalkeymap_add_item_str(struct wmKeyMap *km, int type, int val, int modifier, int keymodifier, const char *value) RET_NULL
-struct wmKeyMap *WM_modalkeymap_add(struct wmKeyConfig *keyconf, const char *idname, const struct EnumPropertyItem *items) RET_NULL
-struct uiPopupMenu *UI_popup_menu_begin(struct bContext *C, const char *title, int icon) RET_NULL
-void UI_popup_menu_end(struct bContext *C, struct uiPopupMenu *head) RET_NONE
-struct uiLayout *UI_popup_menu_layout(struct uiPopupMenu *head) RET_NULL
-struct uiLayout *UI_pie_menu_layout(struct uiPieMenu *pie) RET_NULL
-int UI_pie_menu_invoke(struct bContext *C, const char *idname, const struct wmEvent *event) RET_ZERO
-struct uiPieMenu *UI_pie_menu_begin(struct bContext *C, const char *title, int icon, const struct wmEvent *event) RET_NULL
-void UI_pie_menu_end(struct bContext *C, uiPieMenu *pie) RET_NONE
-struct uiLayout *uiLayoutRadial(struct uiLayout *layout) RET_NULL
-int UI_pie_menu_invoke_from_operator_enum(struct bContext *C, const char *title, const char *opname,
- const char *propname, const struct wmEvent *event) RET_ZERO
-
-void ED_mesh_calc_tessface(struct Mesh *mesh, bool free_mpoly) RET_NONE
-
-/* bpy/python internal api */
-extern void BPY_RNA_operator_wrapper(struct wmOperatorType *ot, void *userdata);
-extern void BPY_RNA_operator_macro_wrapper(struct wmOperatorType *ot, void *userdata);
-void BPY_RNA_operator_wrapper(struct wmOperatorType *ot, void *userdata) RET_NONE
-void BPY_RNA_operator_macro_wrapper(struct wmOperatorType *ot, void *userdata) RET_NONE
-void BPY_text_free_code(struct Text *text) RET_NONE
-void BPY_id_release(struct ID *id) RET_NONE
-int BPY_context_member_get(struct bContext *C, const char *member, struct bContextDataResult *result) RET_ZERO
-void BPY_pyconstraint_target(struct bPythonConstraint *con, struct bConstraintTarget *ct) RET_NONE
-float BPY_driver_exec(PathResolvedRNA *anim_rna, struct ChannelDriver *driver, const float evaltime) RET_ZERO /* might need this one! */
-void BPY_DECREF(void *pyob_ptr) RET_NONE
-void BPY_DECREF_RNA_INVALIDATE(void *pyob_ptr) RET_NONE;
-void BPY_pyconstraint_exec(struct bPythonConstraint *con, struct bConstraintOb *cob, struct ListBase *targets) RET_NONE
-bool pyrna_id_FromPyObject(struct PyObject *obj, struct ID **id) RET_ZERO
-struct PyObject *pyrna_id_CreatePyObject(struct ID *id) RET_NULL
-bool pyrna_id_CheckPyObject(struct PyObject *obj) RET_ZERO
-void BPY_context_update(struct bContext *C) RET_NONE
-const char *BPY_app_translations_py_pgettext(const char *msgctxt, const char *msgid) RET_ARG(msgid)
-
-/* intern/dualcon */
-
-void *dualcon(const DualConInput *input_mesh,
- /* callbacks for output */
- DualConAllocOutput alloc_output,
- DualConAddVert add_vert,
- DualConAddQuad add_quad,
-
- DualConFlags flags,
- DualConMode mode,
- float threshold,
- float hermite_num,
- float scale,
- int depth) RET_ZERO
-
-/* compositor */
-void COM_execute(RenderData *rd, Scene *scene, bNodeTree *editingtree, int rendering,
- const ColorManagedViewSettings *viewSettings, const ColorManagedDisplaySettings *displaySettings,
- const char *viewName) RET_NONE
-
-/*multiview*/
-bool RE_RenderResult_is_stereo(RenderResult *res) RET_ZERO
-void uiTemplateImageViews(uiLayout *layout, struct PointerRNA *imfptr) RET_NONE
-
-#endif // WITH_GAMEENGINE
diff --git a/source/creator/CMakeLists.txt b/source/creator/CMakeLists.txt
index a71c1bb1984..585a2f58204 100644
--- a/source/creator/CMakeLists.txt
+++ b/source/creator/CMakeLists.txt
@@ -76,12 +76,6 @@ if(WITH_HEADLESS)
add_definitions(-DWITH_HEADLESS)
endif()
-if(WITH_GAMEENGINE)
- blender_include_dirs(../gameengine/BlenderRoutines)
-
- add_definitions(-DWITH_GAMEENGINE)
-endif()
-
if(WITH_SDL)
if(WITH_SDL_DYNLOAD)
add_definitions(-DWITH_SDL_DYNLOAD)
@@ -413,6 +407,12 @@ if(WITH_OPENCOLORIO)
)
endif()
+# Add default workspaces.blend to build (under [version]/datafiles
+install(
+ FILES ${CMAKE_SOURCE_DIR}/release/datafiles/workspaces.blend
+ DESTINATION ${TARGETDIR_VER}/datafiles
+)
+
# helpful tip when using make
if("${CMAKE_GENERATOR}" MATCHES ".*Makefiles.*")
# message after building.
@@ -924,53 +924,6 @@ elseif(APPLE)
)
unset(_py_inc_suffix)
endif()
-
- # install blenderplayer bundle - copy of blender.app above. re-using macros et al
- # note we are using OSX Bundle as base and copying Blender dummy bundle on top of it
- if(WITH_GAMEENGINE AND WITH_PLAYER)
- set(OSX_APP_PLAYER_SOURCEDIR ${CMAKE_SOURCE_DIR}/release/darwin/blenderplayer.app)
- set(PLAYER_SOURCEINFO ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Info.plist)
- set(PLAYER_TARGETDIR_VER blenderplayer.app/Contents/Resources/${BLENDER_VERSION})
-
-
- # important to make a clean install each time else old scripts get loaded.
- install(
- CODE
- "file(REMOVE_RECURSE ${PLAYER_TARGETDIR_VER})"
- )
-
- # Give the bundle actual creation/modification date
- execute_process(COMMAND SetFile -d ${SETFILE_DATE} -m ${SETFILE_DATE}
- ${EXECUTABLE_OUTPUT_PATH}/blenderplayer.app)
-
- install(
- FILES ${OSX_APP_PLAYER_SOURCEDIR}/Contents/PkgInfo
- DESTINATION blenderplayer.app/Contents
- )
-
- install_dir(
- ${OSX_APP_PLAYER_SOURCEDIR}/Contents/Resources
- blenderplayer.app/Contents/
- )
-
- if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
- install(
- FILES ${LIBDIR}/openmp/lib/libiomp5.dylib
- DESTINATION blenderplayer.app/Contents/Resources/lib/
- )
- endif()
-
-
- # python
- if(WITH_PYTHON AND NOT WITH_PYTHON_FRAMEWORK)
- # Copy the python libs into the install directory
- install_dir(
- ${PYTHON_LIBPATH}
- ${PLAYER_TARGETDIR_VER}/python/lib
- )
- endif()
-
- endif()
endif()
@@ -1007,6 +960,27 @@ unset(BLENDER_TEXT_FILES_DESTINATION)
# -----------------------------------------------------------------------------
+# Geometry Icons
+
+# Geometry icons.
+get_property(_icon_names GLOBAL PROPERTY ICON_GEOM_NAMES)
+set(_icon_files)
+foreach(_f ${_icon_names})
+ list(APPEND _icon_files
+ "${CMAKE_SOURCE_DIR}/release/datafiles/icons/${_f}.dat"
+ )
+endforeach()
+install(
+ FILES ${_icon_files}
+ DESTINATION ${TARGETDIR_VER}/datafiles/icons
+)
+
+unset(_icon_names)
+unset(_icon_files)
+unset(_f)
+
+
+# -----------------------------------------------------------------------------
# Setup link libs
add_dependencies(blender makesdna)
diff --git a/source/creator/creator.c b/source/creator/creator.c
index 962d6720760..d3fecad2e03 100644
--- a/source/creator/creator.c
+++ b/source/creator/creator.c
@@ -59,7 +59,6 @@
#include "BKE_brush.h"
#include "BKE_cachefile.h"
#include "BKE_context.h"
-#include "BKE_depsgraph.h" /* for DAG_init */
#include "BKE_font.h"
#include "BKE_global.h"
#include "BKE_material.h"
@@ -69,6 +68,7 @@
#include "BKE_image.h"
#include "BKE_particle.h"
+#include "DEG_depsgraph.h"
#include "IMB_imbuf.h" /* for IMB_init */
@@ -85,13 +85,6 @@
# include "FRS_freestyle.h"
#endif
-/* for passing information between creator and gameengine */
-#ifdef WITH_GAMEENGINE
-# include "BL_System.h"
-#else /* dummy */
-# define SYS_SystemHandle int
-#endif
-
#include <signal.h>
#ifdef __FreeBSD__
@@ -226,7 +219,6 @@ int main(
)
{
bContext *C;
- SYS_SystemHandle syshandle;
#ifndef WITH_PYTHON_MODULE
bArgs *ba;
@@ -373,7 +365,7 @@ int main(
BKE_cachefiles_init();
BKE_images_init();
BKE_modifier_init();
- DAG_init();
+ DEG_register_node_types();
BKE_brush_system_init();
RE_texture_rng_init();
@@ -381,12 +373,6 @@ int main(
BLI_callback_global_init();
-#ifdef WITH_GAMEENGINE
- syshandle = SYS_GetSystem();
-#else
- syshandle = 0;
-#endif
-
/* first test for background */
#ifndef WITH_PYTHON_MODULE
ba = BLI_argsInit(argc, (const char **)argv); /* skip binary path */
@@ -394,7 +380,7 @@ int main(
/* ensure we free on early exit */
app_init_data.ba = ba;
- main_args_setup(C, ba, &syshandle);
+ main_args_setup(C, ba);
BLI_argsParse(ba, 1, NULL, NULL);
@@ -402,7 +388,6 @@ int main(
#else
G.factory_startup = true; /* using preferences or user startup makes no sense for py-as-module */
- (void)syshandle;
#endif
#ifdef WITH_FFMPEG
@@ -517,20 +502,6 @@ int main(
WM_exit(C);
}
else {
- if (G.fileflags & G_FILE_AUTOPLAY) {
- if (G.f & G_SCRIPT_AUTOEXEC) {
- if (WM_init_game(C)) {
- return 0;
- }
- }
- else {
- if (!(G.f & G_SCRIPT_AUTOEXEC_FAIL_QUIET)) {
- G.f |= G_SCRIPT_AUTOEXEC_FAIL;
- BLI_snprintf(G.autoexec_fail, sizeof(G.autoexec_fail), "Game AutoStart");
- }
- }
- }
-
if (!G.file_loaded) {
WM_init_splash(C);
}
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 675f2621942..5d49c954522 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -59,8 +59,6 @@
#include "BKE_sound.h"
#include "BKE_image.h"
-#include "DEG_depsgraph.h"
-
#ifdef WITH_FFMPEG
#include "IMB_imbuf.h"
#endif
@@ -76,16 +74,7 @@
#include "WM_api.h"
-#include "GPU_basic_shader.h"
#include "GPU_draw.h"
-#include "GPU_extensions.h"
-
-/* for passing information between creator and gameengine */
-#ifdef WITH_GAMEENGINE
-# include "BL_System.h"
-#else /* dummy */
-# define SYS_SystemHandle int
-#endif
#ifdef WITH_LIBMV
# include "libmv-capi.h"
@@ -95,6 +84,10 @@
# include "CCL_api.h"
#endif
+#include "DEG_depsgraph.h"
+#include "DEG_depsgraph_build.h"
+#include "DEG_depsgraph_debug.h"
+
#include "creator_intern.h" /* own include */
@@ -430,7 +423,6 @@ static void arg_py_context_restore(
/** \} */
-
/* -------------------------------------------------------------------- */
/** \name Handle Argument Callbacks
@@ -512,11 +504,6 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
BLI_argsPrintArgDoc(ba, "--start-console");
BLI_argsPrintArgDoc(ba, "--no-native-pixels");
-
- printf("\n");
- printf("Game Engine Specific Options:\n");
- BLI_argsPrintArgDoc(ba, "-g");
-
printf("\n");
printf("Python Options:\n");
BLI_argsPrintArgDoc(ba, "--enable-autoexec");
@@ -565,6 +552,7 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
BLI_argsPrintArgDoc(ba, "--debug-depsgraph-no-threads");
BLI_argsPrintArgDoc(ba, "--debug-gpumem");
+ BLI_argsPrintArgDoc(ba, "--debug-gpu-shaders");
BLI_argsPrintArgDoc(ba, "--debug-wm");
BLI_argsPrintArgDoc(ba, "--debug-all");
BLI_argsPrintArgDoc(ba, "--debug-io");
@@ -581,8 +569,6 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
BLI_argsPrintArgDoc(ba, "--env-system-scripts");
BLI_argsPrintArgDoc(ba, "--env-system-python");
printf("\n");
- BLI_argsPrintArgDoc(ba, "-nojoystick");
- BLI_argsPrintArgDoc(ba, "-noglsl");
BLI_argsPrintArgDoc(ba, "-noaudio");
BLI_argsPrintArgDoc(ba, "-setaudio");
@@ -600,8 +586,7 @@ static int arg_handle_print_help(int UNUSED(argc), const char **UNUSED(argv), vo
printf("\n");
printf("Experimental Features:\n");
- BLI_argsPrintArgDoc(ba, "--enable-new-depsgraph");
- BLI_argsPrintArgDoc(ba, "--enable-new-basic-shader-glsl");
+ BLI_argsPrintArgDoc(ba, "--enable-copy-on-write");
/* Other options _must_ be last (anything not handled will show here) */
printf("\n");
@@ -861,7 +846,7 @@ static const char arg_handle_debug_mode_generic_set_doc_events[] =
static const char arg_handle_debug_mode_generic_set_doc_handlers[] =
"\n\tEnable debug messages for event handling.";
static const char arg_handle_debug_mode_generic_set_doc_wm[] =
-"\n\tEnable debug messages for the window manager, also prints every operator call.";
+"\n\tEnable debug messages for the window manager, shows all operators in search, shows keymap errors.";
static const char arg_handle_debug_mode_generic_set_doc_jobs[] =
"\n\tEnable time profiling for background jobs.";
static const char arg_handle_debug_mode_generic_set_doc_gpu[] =
@@ -1130,36 +1115,6 @@ static int arg_handle_register_extension(int UNUSED(argc), const char **UNUSED(a
return 0;
}
-static const char arg_handle_joystick_disable_doc[] =
-"\n\tDisable joystick support."
-;
-static int arg_handle_joystick_disable(int UNUSED(argc), const char **UNUSED(argv), void *data)
-{
-#ifndef WITH_GAMEENGINE
- (void)data;
-#else
- SYS_SystemHandle *syshandle = data;
-
- /**
- * don't initialize joysticks if user doesn't want to use joysticks
- * failed joystick initialization delays over 5 seconds, before game engine start
- */
- SYS_WriteCommandLineInt(*syshandle, "nojoystick", 1);
- if (G.debug & G_DEBUG) printf("disabling nojoystick\n");
-#endif
-
- return 0;
-}
-
-static const char arg_handle_glsl_disable_doc[] =
-"\n\tDisable GLSL shading."
-;
-static int arg_handle_glsl_disable(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
-{
- GPU_extensions_disable();
- return 0;
-}
-
static const char arg_handle_audio_disable_doc[] =
"\n\tForce sound system to None."
;
@@ -1237,10 +1192,8 @@ static int arg_handle_engine_set(int argc, const char **argv, void *data)
else {
Scene *scene = CTX_data_scene(C);
if (scene) {
- RenderData *rd = &scene->r;
-
if (BLI_findstring(&R_engines, argv[1], offsetof(RenderEngineType, idname))) {
- BLI_strncpy_utf8(rd->engine, argv[1], sizeof(rd->engine));
+ BLI_strncpy_utf8(scene->r.engine, argv[1], sizeof(scene->r.engine));
}
else {
printf("\nError: engine not found '%s'\n", argv[1]);
@@ -1323,23 +1276,13 @@ static int arg_handle_threads_set(int argc, const char **argv, void *UNUSED(data
}
}
-static const char arg_handle_depsgraph_use_new_doc[] =
-"\n\tUse new dependency graph."
-;
-static int arg_handle_depsgraph_use_new(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
-{
- printf("Using new dependency graph.\n");
- DEG_depsgraph_switch_to_new();
- return 0;
-}
-
-static const char arg_handle_basic_shader_glsl_use_new_doc[] =
-"\n\tUse new GLSL basic shader."
+static const char arg_handle_use_copy_on_write_doc[] =
+"\n\tUse new dependency graph"
;
-static int arg_handle_basic_shader_glsl_use_new(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
+static int arg_handle_use_copy_on_write(int UNUSED(argc), const char **UNUSED(argv), void *UNUSED(data))
{
- printf("Using new GLSL basic shader.\n");
- GPU_basic_shader_use_glsl_set(true);
+ printf("Using copy on write. This is highly EXPERIMENTAL!\n");
+ DEG_depsgraph_enable_copy_on_write();
return 0;
}
@@ -1405,76 +1348,6 @@ static int arg_handle_extension_set(int argc, const char **argv, void *data)
}
}
-static const char arg_handle_ge_parameters_set_doc[] =
-"Game Engine specific options\n"
-"\n"
-"\t'fixedtime'\n"
-"\t\tRun on 50 hertz without dropping frames.\n"
-"\t'vertexarrays'\n"
-"\t\tUse Vertex Arrays for rendering (usually faster).\n"
-"\t'nomipmap'\n"
-"\t\tNo Texture Mipmapping.\n"
-"\t'linearmipmap'\n"
-"\t\tLinear Texture Mipmapping instead of Nearest (default)."
-;
-static int arg_handle_ge_parameters_set(int argc, const char **argv, void *data)
-{
- int a = 0;
-#ifdef WITH_GAMEENGINE
- SYS_SystemHandle syshandle = *(SYS_SystemHandle *)data;
-#else
- (void)data;
-#endif
-
- /**
- * gameengine parameters are automatically put into system
- * -g [paramname = value]
- * -g [boolparamname]
- * example:
- * -g novertexarrays
- * -g maxvertexarraysize = 512
- */
-
- if (argc >= 1) {
- const char *paramname = argv[a];
- /* check for single value versus assignment */
- if (a + 1 < argc && (*(argv[a + 1]) == '=')) {
- a++;
- if (a + 1 < argc) {
- a++;
- /* assignment */
-#ifdef WITH_GAMEENGINE
- SYS_WriteCommandLineString(syshandle, paramname, argv[a]);
-#endif
- }
- else {
- printf("Error: argument assignment (%s) without value.\n", paramname);
- return 0;
- }
- /* name arg eaten */
-
- }
- else {
-#ifdef WITH_GAMEENGINE
- SYS_WriteCommandLineInt(syshandle, argv[a], 1);
-#endif
- /* doMipMap */
- if (STREQ(argv[a], "nomipmap")) {
- GPU_set_mipmap(0); //doMipMap = 0;
- }
- /* linearMipMap */
- if (STREQ(argv[a], "linearmipmap")) {
- GPU_set_mipmap(1);
- GPU_set_linear_mipmap(1); //linearMipMap = 1;
- }
-
-
- } /* if (*(argv[a + 1]) == '=') */
- }
-
- return a;
-}
-
static const char arg_handle_render_frame_doc[] =
"<frame>\n"
"\tRender frame <frame> and save it.\n"
@@ -1508,7 +1381,6 @@ static int arg_handle_render_frame(int argc, const char **argv, void *data)
re = RE_NewSceneRender(scene);
BLI_threaded_malloc_begin();
BKE_reports_init(&reports, RPT_STORE);
-
RE_SetReports(re, &reports);
for (int i = 0; i < frames_range_len; i++) {
/* We could pass in frame ranges,
@@ -1917,7 +1789,7 @@ static int arg_handle_load_file(int UNUSED(argc), const char **argv, void *data)
}
-void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
+void main_args_setup(bContext *C, bArgs *ba)
{
#define CB(a) a##_doc, a
@@ -2007,9 +1879,10 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
CB_EX(arg_handle_debug_mode_generic_set, depsgraph_pretty), (void *)G_DEBUG_DEPSGRAPH_PRETTY);
BLI_argsAdd(ba, 1, NULL, "--debug-gpumem",
CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_MEM);
+ BLI_argsAdd(ba, 1, NULL, "--debug-gpu-shaders",
+ CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_SHADERS);
- BLI_argsAdd(ba, 1, NULL, "--enable-new-depsgraph", CB(arg_handle_depsgraph_use_new), NULL);
- BLI_argsAdd(ba, 1, NULL, "--enable-new-basic-shader-glsl", CB(arg_handle_basic_shader_glsl_use_new), NULL);
+ BLI_argsAdd(ba, 1, NULL, "--enable-copy-on-write", CB(arg_handle_use_copy_on_write), NULL);
BLI_argsAdd(ba, 1, NULL, "--verbose", CB(arg_handle_verbosity_set), NULL);
@@ -2030,13 +1903,10 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
BLI_argsAdd(ba, 2, NULL, "--no-native-pixels", CB(arg_handle_native_pixels_set), ba);
/* third pass: disabling things and forcing settings */
- BLI_argsAddCase(ba, 3, "-nojoystick", 1, NULL, 0, CB(arg_handle_joystick_disable), syshandle);
- BLI_argsAddCase(ba, 3, "-noglsl", 1, NULL, 0, CB(arg_handle_glsl_disable), NULL);
BLI_argsAddCase(ba, 3, "-noaudio", 1, NULL, 0, CB(arg_handle_audio_disable), NULL);
BLI_argsAddCase(ba, 3, "-setaudio", 1, NULL, 0, CB(arg_handle_audio_set), NULL);
/* fourth pass: processing arguments */
- BLI_argsAdd(ba, 4, "-g", NULL, CB(arg_handle_ge_parameters_set), syshandle);
BLI_argsAdd(ba, 4, "-f", "--render-frame", CB(arg_handle_render_frame), C);
BLI_argsAdd(ba, 4, "-a", "--render-anim", CB(arg_handle_render_animation), C);
BLI_argsAdd(ba, 4, "-S", "--scene", CB(arg_handle_scene_set), C);
diff --git a/source/creator/creator_intern.h b/source/creator/creator_intern.h
index a972a926677..311c8b74006 100644
--- a/source/creator/creator_intern.h
+++ b/source/creator/creator_intern.h
@@ -33,7 +33,7 @@ struct bContext;
#ifndef WITH_PYTHON_MODULE
/* creator_args.c */
-void main_args_setup(struct bContext *C, struct bArgs *ba, SYS_SystemHandle *syshandle);
+void main_args_setup(struct bContext *C, struct bArgs *ba);
void main_args_setup_post(struct bContext *C, struct bArgs *ba);
diff --git a/source/creator/creator_signals.c b/source/creator/creator_signals.c
index feb108da289..55f9777f55a 100644
--- a/source/creator/creator_signals.c
+++ b/source/creator/creator_signals.c
@@ -65,13 +65,6 @@
#include "BKE_report.h"
-/* for passing information between creator and gameengine */
-#ifdef WITH_GAMEENGINE
-# include "BL_System.h"
-#else /* dummy */
-# define SYS_SystemHandle int
-#endif
-
#include <signal.h>
#include "creator_intern.h" /* own include */
diff --git a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp b/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
deleted file mode 100644
index 6e698166fd9..00000000000
--- a/source/gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
+++ /dev/null
@@ -1,683 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Blender's Ketsji startpoint
- */
-
-/** \file gameengine/BlenderRoutines/BL_KetsjiEmbedStart.cpp
- * \ingroup blroutines
- */
-
-
-#include <signal.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#ifdef _MSC_VER
- /* don't show stl-warnings */
-# pragma warning (disable:4786)
-#endif
-
-#include "GPU_glew.h"
-
-#include "KX_BlenderCanvas.h"
-#include "KX_BlenderKeyboardDevice.h"
-#include "KX_BlenderMouseDevice.h"
-#include "KX_BlenderSystem.h"
-#include "BL_Material.h"
-
-#include "KX_KetsjiEngine.h"
-#include "KX_BlenderSceneConverter.h"
-#include "KX_PythonInit.h"
-#include "KX_PyConstraintBinding.h"
-#include "KX_PythonMain.h"
-
-#include "RAS_OpenGLRasterizer.h"
-#include "RAS_ListRasterizer.h"
-
-#include "NG_LoopBackNetworkDeviceInterface.h"
-
-#include "BL_System.h"
-
-#include "GPU_extensions.h"
-#include "EXP_Value.h"
-
-
-extern "C" {
- #include "DNA_object_types.h"
- #include "DNA_view3d_types.h"
- #include "DNA_screen_types.h"
- #include "DNA_userdef_types.h"
- #include "DNA_scene_types.h"
- #include "DNA_windowmanager_types.h"
-
- #include "BKE_global.h"
- #include "BKE_report.h"
- #include "BKE_ipo.h"
- #include "BKE_main.h"
- #include "BKE_context.h"
- #include "BKE_sound.h"
-
- /* avoid c++ conflict with 'new' */
- #define new _new
- #include "BKE_screen.h"
- #undef new
-
- #include "MEM_guardedalloc.h"
-
- #include "BLI_blenlib.h"
- #include "BLO_readfile.h"
-
- #include "../../blender/windowmanager/WM_types.h"
- #include "../../blender/windowmanager/wm_window.h"
-
-/* avoid more includes (not used by BGE) */
-typedef void * wmUIHandlerFunc;
-typedef void * wmUIHandlerRemoveFunc;
-
- #include "../../blender/windowmanager/wm_event_system.h"
-}
-
-#ifdef WITH_AUDASPACE
-# include AUD_DEVICE_H
-#endif
-
-static BlendFileData *load_game_data(const char *filename)
-{
- ReportList reports;
- BlendFileData *bfd;
-
- BKE_reports_init(&reports, RPT_STORE);
- bfd= BLO_read_from_file(filename, &reports, BLO_READ_SKIP_USERDEF);
-
- if (!bfd) {
- printf("Loading %s failed: ", filename);
- BKE_reports_print(&reports, RPT_ERROR);
- }
-
- BKE_reports_clear(&reports);
-
- return bfd;
-}
-
-static int BL_KetsjiNextFrame(KX_KetsjiEngine *ketsjiengine, bContext *C, wmWindow *win, Scene *scene, ARegion *ar,
- KX_BlenderKeyboardDevice* keyboarddevice, KX_BlenderMouseDevice* mousedevice, int draw_letterbox)
-{
- int exitrequested;
-
- // first check if we want to exit
- exitrequested = ketsjiengine->GetExitCode();
-
- // kick the engine
- bool render = ketsjiengine->NextFrame();
-
- if (render) {
- if (draw_letterbox) {
- // Clear screen to border color
- // We do this here since we set the canvas to be within the frames. This means the engine
- // itself is unaware of the extra space, so we clear the whole region for it.
- glClearColor(scene->gm.framing.col[0], scene->gm.framing.col[1], scene->gm.framing.col[2], 1.0f);
- glViewport(ar->winrct.xmin, ar->winrct.ymin,
- BLI_rcti_size_x(&ar->winrct), BLI_rcti_size_y(&ar->winrct));
- glClear(GL_COLOR_BUFFER_BIT);
- }
-
- // render the frame
- ketsjiengine->Render();
- }
-
- wm_window_process_events_nosleep();
-
- // test for the ESC key
- //XXX while (qtest())
- while (wmEvent *event= (wmEvent *)win->queue.first) {
- short val = 0;
- //unsigned short event = 0; //XXX extern_qread(&val);
- unsigned int unicode = event->utf8_buf[0] ? BLI_str_utf8_as_unicode(event->utf8_buf) : event->ascii;
-
- if (keyboarddevice->ConvertBlenderEvent(event->type, event->val, unicode))
- exitrequested = KX_EXIT_REQUEST_BLENDER_ESC;
-
- /* Coordinate conversion... where
- * should this really be?
- */
- if (event->type == MOUSEMOVE) {
- /* Note, not nice! XXX 2.5 event hack */
- val = event->x - ar->winrct.xmin;
- mousedevice->ConvertBlenderEvent(MOUSEX, val, 0);
-
- val = ar->winy - (event->y - ar->winrct.ymin) - 1;
- mousedevice->ConvertBlenderEvent(MOUSEY, val, 0);
- }
- else {
- mousedevice->ConvertBlenderEvent(event->type, event->val, 0);
- }
-
- BLI_remlink(&win->queue, event);
- wm_event_free(event);
- }
-
- if (win != CTX_wm_window(C)) {
- exitrequested= KX_EXIT_REQUEST_OUTSIDE; /* window closed while bge runs */
- }
- return exitrequested;
-}
-
-
-#ifdef WITH_PYTHON
-static struct BL_KetsjiNextFrameState {
- class KX_KetsjiEngine* ketsjiengine;
- struct bContext *C;
- struct wmWindow* win;
- struct Scene* scene;
- struct ARegion *ar;
- KX_BlenderKeyboardDevice* keyboarddevice;
- KX_BlenderMouseDevice* mousedevice;
- int draw_letterbox;
-} ketsjinextframestate;
-
-static int BL_KetsjiPyNextFrame(void *state0)
-{
- BL_KetsjiNextFrameState *state = (BL_KetsjiNextFrameState *) state0;
- return BL_KetsjiNextFrame(
- state->ketsjiengine,
- state->C,
- state->win,
- state->scene,
- state->ar,
- state->keyboarddevice,
- state->mousedevice,
- state->draw_letterbox);
-}
-#endif
-
-
-extern "C" void StartKetsjiShell(struct bContext *C, struct ARegion *ar, rcti *cam_frame, int always_use_expand_framing)
-{
- /* context values */
- struct wmWindowManager *wm= CTX_wm_manager(C);
- struct wmWindow *win= CTX_wm_window(C);
- struct Scene *startscene= CTX_data_scene(C);
- struct Main* maggie1= CTX_data_main(C);
-
-
- RAS_Rect area_rect;
- area_rect.SetLeft(cam_frame->xmin);
- area_rect.SetBottom(cam_frame->ymin);
- area_rect.SetRight(cam_frame->xmax);
- area_rect.SetTop(cam_frame->ymax);
-
- int exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
- Main* blenderdata = maggie1;
-
- char* startscenename = startscene->id.name+2;
- char pathname[FILE_MAXDIR+FILE_MAXFILE], oldsce[FILE_MAXDIR+FILE_MAXFILE];
- STR_String exitstring = "";
- BlendFileData *bfd= NULL;
-
- BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
- BLI_strncpy(oldsce, G.main->name, sizeof(oldsce));
-#ifdef WITH_PYTHON
- resetGamePythonPath(); // need this so running a second time wont use an old blendfiles path
- setGamePythonPath(G.main->name);
-
- // Acquire Python's GIL (global interpreter lock)
- // so we can safely run Python code and API calls
- PyGILState_STATE gilstate = PyGILState_Ensure();
-
- PyObject *pyGlobalDict = PyDict_New(); /* python utility storage, spans blend file loading */
-#endif
-
- // Globals to be carried on over blender files
- GlobalSettings gs;
- gs.matmode= startscene->gm.matmode;
- gs.glslflag= startscene->gm.flag;
-
- do
- {
- View3D *v3d= CTX_wm_view3d(C);
- RegionView3D *rv3d= CTX_wm_region_view3d(C);
-
- // get some preferences
- SYS_SystemHandle syshandle = SYS_GetSystem();
- bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
- bool usefixed = (SYS_GetCommandLineInt(syshandle, "fixedtime", 0) != 0);
- bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
- bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
- bool animation_record = (SYS_GetCommandLineInt(syshandle, "animation_record", 0) != 0);
- bool displaylists = (SYS_GetCommandLineInt(syshandle, "displaylists", 0) != 0) && GPU_display_list_support();
-#ifdef WITH_PYTHON
- bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 0) != 0);
-#endif
- // bool novertexarrays = (SYS_GetCommandLineInt(syshandle, "novertexarrays", 0) != 0);
- bool mouse_state = (startscene->gm.flag & GAME_SHOW_MOUSE) != 0;
- bool restrictAnimFPS = (startscene->gm.flag & GAME_RESTRICT_ANIM_UPDATES) != 0;
-
- short drawtype = v3d->drawtype;
-
- /* we do not support material mode in game engine, force change to texture mode */
- if (drawtype == OB_MATERIAL) drawtype = OB_TEXTURE;
- if (animation_record) usefixed= false; /* override since you don't want to run full-speed for sim recording */
-
- // create the canvas and rasterizer
- RAS_ICanvas* canvas = new KX_BlenderCanvas(wm, win, area_rect, ar);
-
- // default mouse state set on render panel
- if (mouse_state)
- canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
- else
- canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
-
- // Setup vsync
- int previous_vsync = 0;
- canvas->GetSwapInterval(previous_vsync);
- if (startscene->gm.vsync == VSYNC_ADAPTIVE)
- canvas->SetSwapInterval(-1);
- else
- canvas->SetSwapInterval((startscene->gm.vsync == VSYNC_ON) ? 1 : 0);
-
- RAS_IRasterizer* rasterizer = NULL;
- RAS_STORAGE_TYPE raster_storage = RAS_AUTO_STORAGE;
-
- if (startscene->gm.raster_storage == RAS_STORE_VBO) {
- raster_storage = RAS_VBO;
- }
- else if (startscene->gm.raster_storage == RAS_STORE_VA) {
- raster_storage = RAS_VA;
- }
- //Don't use displaylists with VBOs
- //If auto starts using VBOs, make sure to check for that here
- if (displaylists && raster_storage != RAS_VBO)
- rasterizer = new RAS_ListRasterizer(canvas, true, raster_storage);
- else
- rasterizer = new RAS_OpenGLRasterizer(canvas, raster_storage);
-
- RAS_IRasterizer::MipmapOption mipmapval = rasterizer->GetMipmapping();
-
-
- // create the inputdevices
- KX_BlenderKeyboardDevice* keyboarddevice = new KX_BlenderKeyboardDevice();
- KX_BlenderMouseDevice* mousedevice = new KX_BlenderMouseDevice();
-
- // create a networkdevice
- NG_NetworkDeviceInterface* networkdevice = new
- NG_LoopBackNetworkDeviceInterface();
-
- //
- // create a ketsji/blendersystem (only needed for timing and stuff)
- KX_BlenderSystem* kxsystem = new KX_BlenderSystem();
-
- // create the ketsjiengine
- KX_KetsjiEngine* ketsjiengine = new KX_KetsjiEngine(kxsystem);
-
- // set the devices
- ketsjiengine->SetKeyboardDevice(keyboarddevice);
- ketsjiengine->SetMouseDevice(mousedevice);
- ketsjiengine->SetNetworkDevice(networkdevice);
- ketsjiengine->SetCanvas(canvas);
- ketsjiengine->SetRasterizer(rasterizer);
- ketsjiengine->SetUseFixedTime(usefixed);
- ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
- ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
- ketsjiengine->SetRender(true);
- KX_KetsjiEngine::SetExitKey(ConvertKeyCode(startscene->gm.exitkey));
-
- //set the global settings (carried over if restart/load new files)
- ketsjiengine->SetGlobalSettings(&gs);
-
-#ifdef WITH_PYTHON
- CValue::SetDeprecationWarnings(nodepwarnings);
-#endif
-
- //lock frame and camera enabled - storing global values
- int tmp_lay= startscene->lay;
- Object *tmp_camera = startscene->camera;
-
- if (v3d->scenelock==0) {
- startscene->lay= v3d->lay;
- startscene->camera= v3d->camera;
- }
-
- // some blender stuff
- float camzoom = 1.0f;
- int draw_letterbox = 0;
-
- if (rv3d->persp==RV3D_CAMOB) {
- if (startscene->gm.framing.type == SCE_GAMEFRAMING_BARS) { /* Letterbox */
- draw_letterbox = 1;
- }
- else {
- camzoom = 1.0f / BKE_screen_view3d_zoom_to_fac(rv3d->camzoom);
- }
- }
-
- rasterizer->SetDrawingMode(drawtype);
- ketsjiengine->SetCameraZoom(camzoom);
- ketsjiengine->SetCameraOverrideZoom(2.0f);
-
- // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
- if (exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME || exitrequested == KX_EXIT_REQUEST_RESTART_GAME)
- {
- exitrequested = KX_EXIT_REQUEST_NO_REQUEST;
- if (bfd) BLO_blendfiledata_free(bfd);
-
- char basedpath[FILE_MAX];
- // base the actuator filename with respect
- // to the original file working directory
-
- if (exitstring != "")
- BLI_strncpy(basedpath, exitstring.ReadPtr(), sizeof(basedpath));
-
- // load relative to the last loaded file, this used to be relative
- // to the first file but that makes no sense, relative paths in
- // blend files should be relative to that file, not some other file
- // that happened to be loaded first
- BLI_path_abs(basedpath, pathname);
- bfd = load_game_data(basedpath);
-
- // if it wasn't loaded, try it forced relative
- if (!bfd)
- {
- // just add "//" in front of it
- char temppath[FILE_MAX] = "//";
- BLI_strncpy(temppath + 2, basedpath, FILE_MAX - 2);
-
- BLI_path_abs(temppath, pathname);
- bfd = load_game_data(temppath);
- }
-
- // if we got a loaded blendfile, proceed
- if (bfd)
- {
- blenderdata = bfd->main;
- startscenename = bfd->curscene->id.name + 2;
-
- if (blenderdata) {
- BLI_strncpy(G.main->name, blenderdata->name, sizeof(G.main->name));
- BLI_strncpy(pathname, blenderdata->name, sizeof(pathname));
-#ifdef WITH_PYTHON
- setGamePythonPath(G.main->name);
-#endif
- }
- }
- // else forget it, we can't find it
- else
- {
- exitrequested = KX_EXIT_REQUEST_QUIT_GAME;
- }
- }
-
- Scene *scene= bfd ? bfd->curscene : (Scene *)BLI_findstring(&blenderdata->scene, startscenename, offsetof(ID, name) + 2);
-
- if (scene)
- {
- int startFrame = scene->r.cfra;
- ketsjiengine->SetAnimRecordMode(animation_record, startFrame);
-
- // Quad buffered needs a special window.
- if (scene->gm.stereoflag == STEREO_ENABLED) {
- if (scene->gm.stereomode != RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
- rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) scene->gm.stereomode);
-
- rasterizer->SetEyeSeparation(scene->gm.eyeseparation);
- }
-
- rasterizer->SetBackColor(scene->gm.framing.col);
- }
-
- if (exitrequested != KX_EXIT_REQUEST_QUIT_GAME)
- {
- if (rv3d->persp != RV3D_CAMOB)
- {
- ketsjiengine->EnableCameraOverride(startscenename);
- ketsjiengine->SetCameraOverrideUseOrtho((rv3d->persp == RV3D_ORTHO));
- ketsjiengine->SetCameraOverrideProjectionMatrix(MT_CmMatrix4x4(rv3d->winmat));
- ketsjiengine->SetCameraOverrideViewMatrix(MT_CmMatrix4x4(rv3d->viewmat));
- ketsjiengine->SetCameraOverrideClipping(v3d->near, v3d->far);
- ketsjiengine->SetCameraOverrideLens(v3d->lens);
- }
-
- // create a scene converter, create and convert the startingscene
- KX_ISceneConverter* sceneconverter = new KX_BlenderSceneConverter(blenderdata, ketsjiengine);
- ketsjiengine->SetSceneConverter(sceneconverter);
- if (always_use_expand_framing)
- sceneconverter->SetAlwaysUseExpandFraming(true);
-
- sceneconverter->SetMaterials(true);
-
- if (gs.matmode == GAME_MAT_GLSL)
- sceneconverter->SetGLSLMaterials(true);
- if (scene->gm.flag & GAME_NO_MATERIAL_CACHING)
- sceneconverter->SetCacheMaterials(false);
-
- KX_Scene* startscene = new KX_Scene(keyboarddevice,
- mousedevice,
- networkdevice,
- startscenename,
- scene,
- canvas);
-
-#ifdef WITH_PYTHON
- // some python things
- PyObject *gameLogic, *gameLogic_keys;
- setupGamePython(ketsjiengine, startscene, blenderdata, pyGlobalDict, &gameLogic, &gameLogic_keys, 0, NULL);
-#endif // WITH_PYTHON
-
- //initialize Dome Settings
- if (scene->gm.stereoflag == STEREO_DOME)
- ketsjiengine->InitDome(scene->gm.dome.res, scene->gm.dome.mode, scene->gm.dome.angle, scene->gm.dome.resbuf, scene->gm.dome.tilt, scene->gm.dome.warptext);
-
- // initialize 3D Audio Settings
- AUD_Device* device = BKE_sound_get_device();
- AUD_Device_setSpeedOfSound(device, scene->audio.speed_of_sound);
- AUD_Device_setDopplerFactor(device, scene->audio.doppler_factor);
- AUD_Device_setDistanceModel(device, AUD_DistanceModel(scene->audio.distance_model));
-
- // from see blender.c:
- // FIXME: this version patching should really be part of the file-reading code,
- // but we still get too many unrelated data-corruption crashes otherwise...
- if (blenderdata->versionfile < 250)
- do_versions_ipos_to_animato(blenderdata);
-
- if (sceneconverter)
- {
- // convert and add scene
- sceneconverter->ConvertScene(
- startscene,
- rasterizer,
- canvas);
- ketsjiengine->AddScene(startscene);
-
- // init the rasterizer
- rasterizer->Init();
-
- // start the engine
- ketsjiengine->StartEngine(true);
-
-
- // Set the animation playback rate for ipo's and actions
- // the framerate below should patch with FPS macro defined in blendef.h
- // Could be in StartEngine set the framerate, we need the scene to do this
- ketsjiengine->SetAnimFrameRate(FPS);
-
-#ifdef WITH_PYTHON
- char *python_main = NULL;
- pynextframestate.state = NULL;
- pynextframestate.func = NULL;
- python_main = KX_GetPythonMain(scene);
-
- // the mainloop
- printf("\nBlender Game Engine Started\n");
- if (python_main) {
- char *python_code = KX_GetPythonCode(blenderdata, python_main);
- if (python_code) {
- // Set python environement variable.
- KX_SetActiveScene(startscene);
- PHY_SetActiveEnvironment(startscene->GetPhysicsEnvironment());
-
- ketsjinextframestate.ketsjiengine = ketsjiengine;
- ketsjinextframestate.C = C;
- ketsjinextframestate.win = win;
- ketsjinextframestate.scene = scene;
- ketsjinextframestate.ar = ar;
- ketsjinextframestate.keyboarddevice = keyboarddevice;
- ketsjinextframestate.mousedevice = mousedevice;
- ketsjinextframestate.draw_letterbox = draw_letterbox;
-
- pynextframestate.state = &ketsjinextframestate;
- pynextframestate.func = &BL_KetsjiPyNextFrame;
- printf("Yielding control to Python script '%s'...\n", python_main);
- PyRun_SimpleString(python_code);
- printf("Exit Python script '%s'\n", python_main);
- MEM_freeN(python_code);
- }
- }
- else
-#endif /* WITH_PYTHON */
- {
- while (!exitrequested)
- {
- exitrequested = BL_KetsjiNextFrame(ketsjiengine, C, win, scene, ar, keyboarddevice, mousedevice, draw_letterbox);
- }
- }
- printf("Blender Game Engine Finished\n");
- exitstring = ketsjiengine->GetExitString();
-#ifdef WITH_PYTHON
- if (python_main) MEM_freeN(python_main);
-#endif /* WITH_PYTHON */
-
- gs = *(ketsjiengine->GetGlobalSettings());
-
- // when exiting the mainloop
-#ifdef WITH_PYTHON
- // Clears the dictionary by hand:
- // This prevents, extra references to global variables
- // inside the GameLogic dictionary when the python interpreter is finalized.
- // which allows the scene to safely delete them :)
- // see: (space.c)->start_game
-
- //PyDict_Clear(PyModule_GetDict(gameLogic));
-
- // Keep original items, means python plugins will autocomplete members
- PyObject *gameLogic_keys_new = PyDict_Keys(PyModule_GetDict(gameLogic));
- const Py_ssize_t numitems= PyList_GET_SIZE(gameLogic_keys_new);
- Py_ssize_t listIndex;
- for (listIndex=0; listIndex < numitems; listIndex++) {
- PyObject *item = PyList_GET_ITEM(gameLogic_keys_new, listIndex);
- if (!PySequence_Contains(gameLogic_keys, item)) {
- PyDict_DelItem( PyModule_GetDict(gameLogic), item);
- }
- }
- Py_DECREF(gameLogic_keys_new);
- gameLogic_keys_new = NULL;
-#endif
- ketsjiengine->StopEngine();
-#ifdef WITH_PYTHON
- exitGamePythonScripting();
-#endif
- networkdevice->Disconnect();
- }
- if (sceneconverter)
- {
- delete sceneconverter;
- sceneconverter = NULL;
- }
-
-#ifdef WITH_PYTHON
- Py_DECREF(gameLogic_keys);
- gameLogic_keys = NULL;
-#endif
- }
- //lock frame and camera enabled - restoring global values
- if (v3d->scenelock==0) {
- startscene->lay= tmp_lay;
- startscene->camera= tmp_camera;
- }
-
- if (exitrequested != KX_EXIT_REQUEST_OUTSIDE)
- {
- // set the cursor back to normal
- canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
-
- // set mipmap setting back to its original value
- rasterizer->SetMipmapping(mipmapval);
- }
-
- // clean up some stuff
- if (ketsjiengine)
- {
- delete ketsjiengine;
- ketsjiengine = NULL;
- }
- if (kxsystem)
- {
- delete kxsystem;
- kxsystem = NULL;
- }
- if (networkdevice)
- {
- delete networkdevice;
- networkdevice = NULL;
- }
- if (keyboarddevice)
- {
- delete keyboarddevice;
- keyboarddevice = NULL;
- }
- if (mousedevice)
- {
- delete mousedevice;
- mousedevice = NULL;
- }
- if (rasterizer)
- {
- delete rasterizer;
- rasterizer = NULL;
- }
- if (canvas)
- {
- canvas->SetSwapInterval(previous_vsync); // Set the swap interval back
- delete canvas;
- canvas = NULL;
- }
-
- // stop all remaining playing sounds
- AUD_Device_stopAll(BKE_sound_get_device());
-
- } while (exitrequested == KX_EXIT_REQUEST_RESTART_GAME || exitrequested == KX_EXIT_REQUEST_START_OTHER_GAME);
-
- if (bfd) BLO_blendfiledata_free(bfd);
-
- BLI_strncpy(G.main->name, oldsce, sizeof(G.main->name));
-
-#ifdef WITH_PYTHON
- PyDict_Clear(pyGlobalDict);
- Py_DECREF(pyGlobalDict);
-
- // Release Python's GIL
- PyGILState_Release(gilstate);
-#endif
-
-}
diff --git a/source/gameengine/BlenderRoutines/BL_System.cpp b/source/gameengine/BlenderRoutines/BL_System.cpp
deleted file mode 100644
index 251182a07aa..00000000000
--- a/source/gameengine/BlenderRoutines/BL_System.cpp
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Interface to the commandline arguments
- */
-
-/** \file gameengine/BlenderRoutines/BL_System.cpp
- * \ingroup blroutines
- */
-
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "BL_System.h"
-
-struct SingletonSystem {
- CTR_Map<STR_HashedString,int> int_params;
- CTR_Map<STR_HashedString,float> float_params;
- CTR_Map<STR_HashedString,STR_String> string_params;
-};
-
-static SingletonSystem *_system_instance = NULL;
-
-SYS_SystemHandle SYS_GetSystem()
-{
- if (!_system_instance)
- _system_instance = new SingletonSystem();
-
- return (SYS_SystemHandle)_system_instance;
-}
-
-void SYS_DeleteSystem(SYS_SystemHandle sys)
-{
- if (_system_instance) {
- delete _system_instance;
- _system_instance = NULL;
- }
-}
-
-int SYS_GetCommandLineInt(SYS_SystemHandle sys, const char *paramname, int defaultvalue)
-{
- int *result = ((SingletonSystem *)sys)->int_params[paramname];
- if (result)
- return *result;
-
- return defaultvalue;
-}
-
-float SYS_GetCommandLineFloat(SYS_SystemHandle sys, const char *paramname, float defaultvalue)
-{
- float *result = ((SingletonSystem *)sys)->float_params[paramname];
- if (result)
- return *result;
-
- return defaultvalue;
-}
-
-const char *SYS_GetCommandLineString(SYS_SystemHandle sys, const char *paramname, const char *defaultvalue)
-{
- STR_String *result = ((SingletonSystem *)sys)->string_params[paramname];
- if (result)
- return *result;
-
- return defaultvalue;
-}
-
-void SYS_WriteCommandLineInt(SYS_SystemHandle sys, const char *paramname, int value)
-{
- ((SingletonSystem *)sys)->int_params.insert(paramname, value);
-}
-
-void SYS_WriteCommandLineFloat(SYS_SystemHandle sys, const char *paramname, float value)
-{
- ((SingletonSystem *)sys)->float_params.insert(paramname, value);
-}
-
-void SYS_WriteCommandLineString(SYS_SystemHandle sys, const char *paramname, const char *value)
-{
- ((SingletonSystem *)sys)->string_params.insert(paramname, value);
-}
-
diff --git a/source/gameengine/BlenderRoutines/BL_System.h b/source/gameengine/BlenderRoutines/BL_System.h
deleted file mode 100644
index b9f51393f44..00000000000
--- a/source/gameengine/BlenderRoutines/BL_System.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * System specific information / access.
- * Interface to the commandline arguments
- */
-
-/** \file gameengine/BlenderRoutines/BL_System.h
- * \ingroup blroutines
- */
-
-#ifndef __BL_SYSTEM_H__
-#define __BL_SYSTEM_H__
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-/* Game Engine command line parameters */
-
-typedef void* SYS_SystemHandle;
-
-extern SYS_SystemHandle SYS_GetSystem(void);
-extern void SYS_DeleteSystem(SYS_SystemHandle sys);
-
-extern int SYS_GetCommandLineInt(SYS_SystemHandle sys, const char *paramname, int defaultvalue);
-extern float SYS_GetCommandLineFloat(SYS_SystemHandle sys, const char *paramname, float defaultvalue);
-extern const char *SYS_GetCommandLineString(SYS_SystemHandle sys, const char *paramname, const char *defaultvalue);
-
-extern void SYS_WriteCommandLineInt(SYS_SystemHandle sys, const char *paramname, int value);
-extern void SYS_WriteCommandLineFloat(SYS_SystemHandle sys, const char *paramname, float value);
-extern void SYS_WriteCommandLineString(SYS_SystemHandle sys, const char *paramname, const char *value);
-
-/* Start game engine */
-
-struct bContext;
-struct ARegion;
-struct rcti;
-
-extern void StartKetsjiShell(struct bContext *C, struct ARegion *ar,
- struct rcti *cam_frame, int always_use_expand_framing);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __BL_SYSTEM_H__ */
-
diff --git a/source/gameengine/BlenderRoutines/CMakeLists.txt b/source/gameengine/BlenderRoutines/CMakeLists.txt
deleted file mode 100644
index aaeb2e10462..00000000000
--- a/source/gameengine/BlenderRoutines/CMakeLists.txt
+++ /dev/null
@@ -1,78 +0,0 @@
-
-set(INC
- .
- ../Converter
- ../Expressions
- ../GameLogic
- ../Ketsji
- ../Network
- ../Network/LoopBackNetwork
- ../Physics/Bullet
- ../Physics/common
- ../Rasterizer
- ../Rasterizer/RAS_OpenGLRasterizer
- ../SceneGraph
- ../../blender
- ../../blender/blenfont
- ../../blender/blenkernel
- ../../blender/blenlib
- ../../blender/blenloader
- ../../blender/editors/include
- ../../blender/gpu
- ../../blender/imbuf
- ../../blender/makesdna
- ../../blender/makesrna
- ../../blender/windowmanager
- ../../../intern/container
- ../../../intern/glew-mx
- ../../../intern/guardedalloc
- ../../../intern/string
-)
-
-set(INC_SYS
- ../../../intern/moto/include
- ${PTHREADS_INCLUDE_DIRS}
- ${GLEW_INCLUDE_PATH}
- ${BOOST_INCLUDE_DIR}
-)
-
-set(SRC
- BL_KetsjiEmbedStart.cpp
- BL_System.cpp
- KX_BlenderCanvas.cpp
- KX_BlenderInputDevice.cpp
- KX_BlenderKeyboardDevice.cpp
- KX_BlenderMouseDevice.cpp
- KX_BlenderSystem.cpp
-
- BL_System.h
- KX_BlenderCanvas.h
- KX_BlenderInputDevice.h
- KX_BlenderKeyboardDevice.h
- KX_BlenderMouseDevice.h
- KX_BlenderSystem.h
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
-
- list(APPEND INC_SYS
- ${AUDASPACE_C_INCLUDE_DIRS}
- )
-endif()
-
-if(WITH_CODEC_FFMPEG)
- add_definitions(-DWITH_FFMPEG)
-endif()
-
-if(WITH_BULLET)
- list(APPEND INC_SYS
- ${BULLET_INCLUDE_DIRS}
- )
- add_definitions(-DWITH_BULLET)
-endif()
-
-
-blender_add_lib(ge_blen_routines "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
deleted file mode 100644
index a6b2340d7b4..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
+++ /dev/null
@@ -1,353 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/BlenderRoutines/KX_BlenderCanvas.cpp
- * \ingroup blroutines
- */
-
-#include "GPU_glew.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "KX_BlenderCanvas.h"
-
-#include "DNA_screen_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_windowmanager_types.h"
-
-#include "BKE_image.h"
-
-#include <assert.h>
-#include <iostream>
-
-extern "C" {
-#include "WM_api.h"
-#include "wm_cursors.h"
-#include "wm_window.h"
-}
-
-KX_BlenderCanvas::KX_BlenderCanvas(wmWindowManager *wm, wmWindow *win, RAS_Rect &rect, struct ARegion *ar) :
-m_wm(wm),
-m_win(win),
-m_frame_rect(rect)
-{
- // initialize area so that it's available for game logic on frame 1 (ImageViewport)
- m_area_rect = rect;
- // area boundaries needed for mouse coordinates in Letterbox framing mode
- m_area_left = ar->winrct.xmin;
- m_area_top = ar->winrct.ymax;
- m_frame = 1;
-
- glGetIntegerv(GL_VIEWPORT, (GLint *)m_viewport);
-}
-
-KX_BlenderCanvas::~KX_BlenderCanvas()
-{
-}
-
-void KX_BlenderCanvas::Init()
-{
- glDepthFunc(GL_LEQUAL);
-}
-
-
-void KX_BlenderCanvas::SwapBuffers()
-{
- wm_window_swap_buffers(m_win);
-}
-
-void KX_BlenderCanvas::SetSwapInterval(int interval)
-{
- wm_window_set_swap_interval(m_win, interval);
-}
-
-bool KX_BlenderCanvas::GetSwapInterval(int &intervalOut)
-{
- return wm_window_get_swap_interval(m_win, &intervalOut);
-}
-
-void KX_BlenderCanvas::GetDisplayDimensions(int &width, int &height)
-{
- wm_get_screensize(&width, &height);
-}
-
-void KX_BlenderCanvas::ResizeWindow(int width, int height)
-{
- // Not implemented for the embedded player
-}
-
-void KX_BlenderCanvas::SetFullScreen(bool enable)
-{
- // Not implemented for the embedded player
-}
-
-bool KX_BlenderCanvas::GetFullScreen()
-{
- // Not implemented for the embedded player
- return false;
-}
-
-bool KX_BlenderCanvas::BeginDraw()
-{
- // in case of multi-window we need to ensure we are drawing to the correct
- // window always, because it may change in window event handling
- wm_window_make_drawable(m_wm, m_win);
- return true;
-}
-
-
-void KX_BlenderCanvas::EndDraw()
-{
- // nothing needs to be done here
-}
-
-void KX_BlenderCanvas::BeginFrame()
-{
- glEnable(GL_DEPTH_TEST);
- glDepthFunc(GL_LEQUAL);
-}
-
-
-void KX_BlenderCanvas::EndFrame()
-{
- glDisable(GL_FOG);
-}
-
-
-
-void KX_BlenderCanvas::ClearColor(float r,float g,float b,float a)
-{
- glClearColor(r,g,b,a);
-}
-
-
-
-void KX_BlenderCanvas::ClearBuffer(int type)
-{
- int ogltype = 0;
-
- if (type & RAS_ICanvas::COLOR_BUFFER )
- ogltype |= GL_COLOR_BUFFER_BIT;
-
- if (type & RAS_ICanvas::DEPTH_BUFFER )
- ogltype |= GL_DEPTH_BUFFER_BIT;
- glClear(ogltype);
-}
-
-int KX_BlenderCanvas::GetWidth(
-) const {
- return m_frame_rect.GetWidth();
-}
-
-int KX_BlenderCanvas::GetHeight(
-) const {
- return m_frame_rect.GetHeight();
-}
-
-int KX_BlenderCanvas::GetMouseX(int x)
-{
- int left = GetWindowArea().GetLeft();
- return x - (left - m_area_left);
-}
-
-int KX_BlenderCanvas::GetMouseY(int y)
-{
- int top = GetWindowArea().GetTop();
- return y - (m_area_top - top);
-}
-
-float KX_BlenderCanvas::GetMouseNormalizedX(int x)
-{
- int can_x = GetMouseX(x);
- return float(can_x)/this->GetWidth();
-}
-
-float KX_BlenderCanvas::GetMouseNormalizedY(int y)
-{
- int can_y = GetMouseY(y);
- return float(can_y)/this->GetHeight();
-}
-
-RAS_Rect &
-KX_BlenderCanvas::
-GetWindowArea(
-) {
- return m_area_rect;
-}
-
- void
-KX_BlenderCanvas::
-SetViewPort(
- int x1, int y1,
- int x2, int y2
-) {
- /* x1 and y1 are the min pixel coordinate (e.g. 0)
- * x2 and y2 are the max pixel coordinate
- * the width,height is calculated including both pixels
- * therefore: max - min + 1
- */
- int vp_width = (x2 - x1) + 1;
- int vp_height = (y2 - y1) + 1;
- int minx = m_frame_rect.GetLeft();
- int miny = m_frame_rect.GetBottom();
-
- m_area_rect.SetLeft(minx + x1);
- m_area_rect.SetBottom(miny + y1);
- m_area_rect.SetRight(minx + x2);
- m_area_rect.SetTop(miny + y2);
-
- m_viewport[0] = minx+x1;
- m_viewport[1] = miny+y1;
- m_viewport[2] = vp_width;
- m_viewport[3] = vp_height;
-
- glViewport(minx + x1, miny + y1, vp_width, vp_height);
- glScissor(minx + x1, miny + y1, vp_width, vp_height);
-}
-
- void
-KX_BlenderCanvas::
-UpdateViewPort(
- int x1, int y1,
- int x2, int y2
-) {
- m_viewport[0] = x1;
- m_viewport[1] = y1;
- m_viewport[2] = x2;
- m_viewport[3] = y2;
-}
-
- const int*
-KX_BlenderCanvas::
-GetViewPort() {
-#ifdef DEBUG
- // If we're in a debug build, we might as well make sure our values don't differ
- // from what the gpu thinks we have. This could lead to nasty, hard to find bugs.
- int viewport[4];
- glGetIntegerv(GL_VIEWPORT, viewport);
- assert(viewport[0] == m_viewport[0]);
- assert(viewport[1] == m_viewport[1]);
- assert(viewport[2] == m_viewport[2]);
- assert(viewport[3] == m_viewport[3]);
-#endif
-
- return m_viewport;
-}
-
-void KX_BlenderCanvas::SetMouseState(RAS_MouseState mousestate)
-{
- m_mousestate = mousestate;
-
- switch (mousestate)
- {
- case MOUSE_INVISIBLE:
- {
- WM_cursor_set(m_win, CURSOR_NONE);
- break;
- }
- case MOUSE_WAIT:
- {
- WM_cursor_set(m_win, CURSOR_WAIT);
- break;
- }
- case MOUSE_NORMAL:
- {
- WM_cursor_set(m_win, CURSOR_STD);
- break;
- }
- default:
- {
- }
- }
-}
-
-
-
-// (0,0) is top left, (width,height) is bottom right
-void KX_BlenderCanvas::SetMousePosition(int x,int y)
-{
- int winX = m_frame_rect.GetLeft();
- int winY = m_frame_rect.GetBottom();
- int winH = m_frame_rect.GetHeight();
-
- WM_cursor_warp(m_win, winX + x, winY + (winH-y));
-}
-
-
-/* get shot from frontbuffer sort of a copy from screendump.c */
-static unsigned int *screenshot(ScrArea *curarea, int *dumpsx, int *dumpsy)
-{
- int x=0, y=0;
- unsigned int *dumprect= NULL;
-
- x= curarea->totrct.xmin;
- y= curarea->totrct.ymin;
- *dumpsx= curarea->totrct.xmax-x;
- *dumpsy= curarea->totrct.ymax-y;
-
- if (*dumpsx && *dumpsy) {
-
- dumprect= (unsigned int *)MEM_mallocN(sizeof(int) * (*dumpsx) * (*dumpsy), "dumprect");
- glReadBuffer(GL_FRONT);
- glReadPixels(x, y, *dumpsx, *dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, dumprect);
- glFinish();
- glReadBuffer(GL_BACK);
- }
-
- return dumprect;
-}
-
-void KX_BlenderCanvas::MakeScreenShot(const char *filename)
-{
- ScrArea area_dummy= {0};
- bScreen *screen = m_win->screen;
- unsigned int *dumprect;
- int dumpsx, dumpsy;
-
- area_dummy.totrct.xmin = m_frame_rect.GetLeft();
- area_dummy.totrct.xmax = m_frame_rect.GetRight();
- area_dummy.totrct.ymin = m_frame_rect.GetBottom();
- area_dummy.totrct.ymax = m_frame_rect.GetTop();
-
- dumprect = screenshot(&area_dummy, &dumpsx, &dumpsy);
- if (!dumprect) {
- std::cerr << "KX_BlenderCanvas: Unable to take screenshot!" << std::endl;
- return;
- }
-
- /* initialize image file format data */
- Scene *scene = (screen)? screen->scene: NULL;
- ImageFormatData *im_format = (ImageFormatData *)MEM_mallocN(sizeof(ImageFormatData), "im_format");
-
- if (scene)
- *im_format = scene->r.im_format;
- else
- BKE_imformat_defaults(im_format);
-
- /* save_screenshot() frees dumprect and im_format */
- save_screenshot(filename, dumpsx, dumpsy, dumprect, im_format);
-}
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h b/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
deleted file mode 100644
index 6f408f86551..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderCanvas.h
+++ /dev/null
@@ -1,222 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderCanvas.h
- * \ingroup blroutines
- */
-
-#ifndef __KX_BLENDERCANVAS_H__
-#define __KX_BLENDERCANVAS_H__
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#include "RAS_ICanvas.h"
-#include "RAS_Rect.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-struct ARegion;
-struct wmWindow;
-struct wmWindowManager;
-
-/**
- * 2D Blender device context abstraction.
- * The connection from 3d rendercontext to 2d Blender surface embedding.
- */
-
-class KX_BlenderCanvas : public RAS_ICanvas
-{
-private:
- /**
- * Rect that defines the area used for rendering,
- * relative to the context */
- RAS_Rect m_displayarea;
- int m_viewport[4];
-
-public:
- /* Construct a new canvas.
- *
- * \param area The Blender ARegion to run the game within.
- */
- KX_BlenderCanvas(struct wmWindowManager *wm, struct wmWindow* win, RAS_Rect &rect, struct ARegion* ar);
- ~KX_BlenderCanvas();
-
- void
- Init(
- );
-
- void
- SwapBuffers(
- );
-
- void
- SetSwapInterval(
- int interval
- );
-
- bool
- GetSwapInterval(
- int &intervalOut
- );
-
- void GetDisplayDimensions(int &width, int &height);
-
- void
- ResizeWindow(
- int width,
- int height
- );
-
- void
- SetFullScreen(
- bool enable
- );
-
- bool
- GetFullScreen();
-
- void
- BeginFrame(
- );
-
- void
- EndFrame(
- );
-
- void
- ClearColor(
- float r,
- float g,
- float b,
- float a
- );
-
- void
- ClearBuffer(
- int type
- );
-
- int
- GetWidth(
- ) const;
-
- int
- GetHeight(
- ) const;
-
- int
- GetMouseX(int x
- );
-
- int
- GetMouseY(int y
- );
-
- float
- GetMouseNormalizedX(int x
- );
-
- float
- GetMouseNormalizedY(int y
- );
-
- const
- RAS_Rect &
- GetDisplayArea(
- ) const {
- return m_displayarea;
- };
-
- void
- SetDisplayArea(RAS_Rect *rect
- ) {
- m_displayarea= *rect;
- };
-
- RAS_Rect &
- GetWindowArea(
- );
-
- void
- SetViewPort(
- int x1, int y1,
- int x2, int y2
- );
-
- void
- UpdateViewPort(
- int x1, int y1,
- int x2, int y2
- );
-
- const int*
- GetViewPort();
-
- void
- SetMouseState(
- RAS_MouseState mousestate
- );
-
- void
- SetMousePosition(
- int x,
- int y
- );
-
- void
- MakeScreenShot(
- const char* filename
- );
-
- bool
- BeginDraw(
- );
-
- void
- EndDraw(
- );
-
-private:
- /** Blender area the game engine is running within */
- struct wmWindowManager *m_wm;
- struct wmWindow* m_win;
- RAS_Rect m_frame_rect;
- RAS_Rect m_area_rect;
- int m_area_left;
- int m_area_top;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderCanvas")
-#endif
-};
-
-#endif /* __KX_BLENDERCANVAS_H__ */
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp
deleted file mode 100644
index 8d224051df4..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/BlenderRoutines/KX_BlenderInputDevice.cpp
- * \ingroup blroutines
- */
-
-#include "KX_BlenderInputDevice.h"
-
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h
deleted file mode 100644
index a936f328545..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderInputDevice.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderInputDevice.h
- * \ingroup blroutines
- */
-
-#ifndef __KX_BLENDERINPUTDEVICE_H__
-#define __KX_BLENDERINPUTDEVICE_H__
-
-#ifdef _MSC_VER
-# pragma warning(disable:4786) // shut off 255 char limit debug template warning
-#endif
-
-#include <map>
-
-#include "wm_event_types.h"
-#include "WM_types.h"
-#include "SCA_IInputDevice.h"
-#include "BL_BlenderDataConversion.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/**
- * Base Class for Blender specific inputdevices.
- * Blender specific inputdevices are used when the gameengine is running in embedded mode instead of standalone mode.
- */
-class BL_BlenderInputDevice : public SCA_IInputDevice
-{
-public:
- BL_BlenderInputDevice()
- {
- }
-
- virtual ~BL_BlenderInputDevice()
- {
-
- }
-
- KX_EnumInputs ToNative(unsigned short incode) {
- return ConvertKeyCode(incode);
- }
-
- virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
- // virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
- virtual bool ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode)=0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_BlenderInputDevice")
-#endif
-};
-
-#endif /* __KX_BLENDERINPUTDEVICE_H__ */
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
deleted file mode 100644
index ea78d2d389e..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
+++ /dev/null
@@ -1,169 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.cpp
- * \ingroup blroutines
- */
-
-
-#ifdef _MSC_VER
- /* annoying warnings about truncated STL debug info */
-# pragma warning (disable:4786)
-#endif
-
-#include "KX_BlenderKeyboardDevice.h"
-#include "KX_KetsjiEngine.h"
-
-KX_BlenderKeyboardDevice::KX_BlenderKeyboardDevice()
- : m_hookesc(false)
-{
-
-}
-KX_BlenderKeyboardDevice::~KX_BlenderKeyboardDevice()
-{
-
-}
-
-/**
- * IsPressed gives boolean information about keyboard status, true if pressed, false if not
- */
-
-bool KX_BlenderKeyboardDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
- const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode];
- bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- inevent.m_status == SCA_InputEvent::KX_ACTIVE);
- return pressed;
-}
-/*const SCA_InputEvent& KX_BlenderKeyboardDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
- return m_eventStatusTables[m_currentTable][inputcode];
-}
-*/
-/**
- * NextFrame toggles currentTable with previousTable,
- * and copy relevant event information from previous to current
- * (pressed keys need to be remembered)
- */
-void KX_BlenderKeyboardDevice::NextFrame()
-{
- SCA_IInputDevice::NextFrame();
-
- // now convert justpressed keyevents into regular (active) keyevents
- int previousTable = 1-m_currentTable;
- for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++)
- {
- SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent];
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- oldevent.m_status == SCA_InputEvent::KX_ACTIVE )
- {
- m_eventStatusTables[m_currentTable][keyevent] = oldevent;
- m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_ACTIVE;
- }
- }
-}
-
-/**
- * ConvertBlenderEvent translates blender keyboard events into ketsji kbd events
- * extra event information is stored, like ramp-mode (just released/pressed)
-*/
-bool KX_BlenderKeyboardDevice::ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode)
-{
- bool result = false;
-
- // convert event
- KX_EnumInputs kxevent = this->ToNative(incode);
-
- // only process it, if it's a key
- if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY)
- {
- int previousTable = 1-m_currentTable;
-
- if (val == KM_PRESS || val == KM_DBL_CLICK)
- {
- if (kxevent == KX_KetsjiEngine::GetExitKey() && val != 0 && !m_hookesc)
- result = true;
- if (kxevent == KX_PAUSEKEY && val && (IsPressed(KX_LEFTCTRLKEY) || IsPressed(KX_RIGHTCTRLKEY)))
- result = true;
-
- // todo: convert val ??
- m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
- m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode;
-
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
- break;
- }
- case SCA_InputEvent::KX_ACTIVE:
-
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
- break;
- }
- case SCA_InputEvent::KX_NO_INPUTSTATUS:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- }
- }
-
- } else if (val == KM_RELEASE)
- {
- // blender eventval == 0
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
- break;
- }
- case SCA_InputEvent::KX_ACTIVE:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
- }
- }
- }
- }
- return result;
-}
-
-void KX_BlenderKeyboardDevice::HookEscape()
-{
- m_hookesc = true;
-}
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
deleted file mode 100644
index 10a5b00937d..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderKeyboardDevice.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderKeyboardDevice.h
- * \ingroup blroutines
- */
-
-#ifndef __KX_BLENDERKEYBOARDDEVICE_H__
-#define __KX_BLENDERKEYBOARDDEVICE_H__
-
-#include "KX_BlenderInputDevice.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class KX_BlenderKeyboardDevice : public BL_BlenderInputDevice
-{
- bool m_hookesc;
-public:
- KX_BlenderKeyboardDevice();
- virtual ~KX_BlenderKeyboardDevice();
-
- virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode);
-// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode);
- virtual bool ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode);
- virtual void NextFrame();
- virtual void HookEscape();
-private:
- /* short m_exit_key; */ /* UNUSED */
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderKeyboardDevice")
-#endif
-};
-
-#endif /* __KX_BLENDERKEYBOARDDEVICE_H__ */
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
deleted file mode 100644
index 9df06e83b92..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
+++ /dev/null
@@ -1,192 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/BlenderRoutines/KX_BlenderMouseDevice.cpp
- * \ingroup blroutines
- */
-
-#ifdef _MSC_VER
- /* annoying warnings about truncated STL debug info */
-# pragma warning (disable:4786)
-#endif
-
-#include "KX_BlenderMouseDevice.h"
-
-KX_BlenderMouseDevice::KX_BlenderMouseDevice()
-{
-
-}
-KX_BlenderMouseDevice::~KX_BlenderMouseDevice()
-{
-
-}
-
-/**
- * IsPressed gives boolean information about mouse status, true if pressed, false if not
- */
-
-bool KX_BlenderMouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
- const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode];
- bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- inevent.m_status == SCA_InputEvent::KX_ACTIVE);
- return pressed;
-}
-/*const SCA_InputEvent& KX_BlenderMouseDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
- return m_eventStatusTables[m_currentTable][inputcode];
-}
-*/
-
-/**
- * NextFrame toggles currentTable with previousTable,
- * and copy relevant event information from previous to current
- * (pressed keys need to be remembered)
- */
-void KX_BlenderMouseDevice::NextFrame()
-{
- SCA_IInputDevice::NextFrame();
-
- // now convert justpressed keyevents into regular (active) keyevents
- int previousTable = 1-m_currentTable;
- for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS;mouseevent++)
- {
- SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent];
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- oldevent.m_status == SCA_InputEvent::KX_ACTIVE )
- {
- m_eventStatusTables[m_currentTable][mouseevent] = oldevent;
- m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE;
- }
- }
- for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE;mousemove++)
- {
- SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove];
- m_eventStatusTables[m_currentTable][mousemove] = oldevent;
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- oldevent.m_status == SCA_InputEvent::KX_ACTIVE )
- {
-
- m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED;
- } else
- {
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED)
- {
-
- m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
- }
- }
- }
-}
-
-
-/**
- * ConvertBlenderEvent translates blender mouse events into ketsji kbd events
- * extra event information is stored, like ramp-mode (just released/pressed)
- */
-bool KX_BlenderMouseDevice::ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode)
-{
- bool result = false;
-
- // convert event
- KX_EnumInputs kxevent = this->ToNative(incode);
- int previousTable = 1-m_currentTable;
-
- // only process it, if it's a key
- if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSEBUTTONS)
- {
- if (val == KM_PRESS || val == KM_DBL_CLICK)
- {
- m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
-
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
-
- case SCA_InputEvent::KX_ACTIVE:
- case SCA_InputEvent::KX_JUSTACTIVATED:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
- break;
- }
- case SCA_InputEvent::KX_JUSTRELEASED:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- }
- }
-
- } else if (val == KM_RELEASE)
- {
- // blender eventval == 0
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- case SCA_InputEvent::KX_ACTIVE:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
- }
- }
- }
- }
-
- if (kxevent > KX_ENDMOUSEBUTTONS && kxevent < KX_ENDMOUSE)
- {
- m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //remember mouse position
-
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
-
- case SCA_InputEvent::KX_ACTIVE:
- case SCA_InputEvent::KX_JUSTACTIVATED:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
- break;
- }
- case SCA_InputEvent::KX_JUSTRELEASED:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- }
- }
- }
-
-
- return result;
-}
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h b/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h
deleted file mode 100644
index 04b78aff05c..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderMouseDevice.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderMouseDevice.h
- * \ingroup blroutines
- */
-
-#ifndef __KX_BLENDERMOUSEDEVICE_H__
-#define __KX_BLENDERMOUSEDEVICE_H__
-
-#include "KX_BlenderInputDevice.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class KX_BlenderMouseDevice : public BL_BlenderInputDevice
-{
-public:
- KX_BlenderMouseDevice();
- virtual ~KX_BlenderMouseDevice();
-
- virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode);
-// virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode);
- virtual bool ConvertBlenderEvent(unsigned short incode, short val, unsigned int unicode);
- virtual void NextFrame();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderMouseDevice")
-#endif
-};
-
-#endif /* __KX_BLENDERMOUSEDEVICE_H__ */
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderSystem.cpp b/source/gameengine/BlenderRoutines/KX_BlenderSystem.cpp
deleted file mode 100644
index 0582e79d269..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderSystem.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/BlenderRoutines/KX_BlenderSystem.cpp
- * \ingroup blroutines
- */
-
-
-#include "KX_ISystem.h"
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#ifdef WIN32
-#include <windows.h>
-#endif
-
-#include <iostream>
-#include <stdio.h>
-#include "KX_BlenderInputDevice.h"
-#include "KX_BlenderSystem.h"
-
-#include "PIL_time.h"
-
-KX_BlenderSystem::KX_BlenderSystem()
-: KX_ISystem()
-{
- m_starttime = PIL_check_seconds_timer();
-}
-
-double KX_BlenderSystem::GetTimeInSeconds()
-{
- return PIL_check_seconds_timer() - m_starttime;
-}
diff --git a/source/gameengine/BlenderRoutines/KX_BlenderSystem.h b/source/gameengine/BlenderRoutines/KX_BlenderSystem.h
deleted file mode 100644
index 0867ef2421f..00000000000
--- a/source/gameengine/BlenderRoutines/KX_BlenderSystem.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderSystem.h
- * \ingroup blroutines
- * \brief Blender System embedding. Needed when gameengine runs embedded within Blender.
- */
-
-#ifndef __KX_BLENDERSYSTEM_H__
-#define __KX_BLENDERSYSTEM_H__
-
-#include "KX_ISystem.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class KX_BlenderSystem : public KX_ISystem
-{
- double m_starttime;
-
-public:
- KX_BlenderSystem();
- virtual ~KX_BlenderSystem() {}
- virtual double GetTimeInSeconds();
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderSystem")
-#endif
-};
-
-#endif /* __KX_BLENDERSYSTEM_H__ */
diff --git a/source/gameengine/CMakeLists.txt b/source/gameengine/CMakeLists.txt
deleted file mode 100644
index 62523175f46..00000000000
--- a/source/gameengine/CMakeLists.txt
+++ /dev/null
@@ -1,57 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-remove_extra_strict_flags()
-
-# there are too many inter-includes so best define here
-if(WITH_PYTHON)
- blender_include_dirs_sys("${PYTHON_INCLUDE_DIRS}")
- add_definitions(-DWITH_PYTHON)
-endif()
-
-add_subdirectory(BlenderRoutines)
-add_subdirectory(Converter)
-add_subdirectory(Expressions)
-add_subdirectory(GameLogic)
-add_subdirectory(Ketsji)
-add_subdirectory(Ketsji/KXNetwork)
-add_subdirectory(Network)
-add_subdirectory(Network/LoopBackNetwork)
-add_subdirectory(Physics/Dummy)
-add_subdirectory(Rasterizer)
-add_subdirectory(Rasterizer/RAS_OpenGLRasterizer)
-add_subdirectory(SceneGraph)
-
-if(WITH_BULLET)
- add_subdirectory(Physics/Bullet)
-endif()
-
-if(WITH_PYTHON)
- add_subdirectory(VideoTexture)
-endif()
-
-if(WITH_PLAYER)
- add_subdirectory(GamePlayer)
-endif()
diff --git a/source/gameengine/Converter/BL_ActionActuator.cpp b/source/gameengine/Converter/BL_ActionActuator.cpp
deleted file mode 100644
index d28cdb84275..00000000000
--- a/source/gameengine/Converter/BL_ActionActuator.cpp
+++ /dev/null
@@ -1,664 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ActionActuator.cpp
- * \ingroup bgeconv
- */
-
-
-#include "SCA_LogicManager.h"
-#include "BL_ActionActuator.h"
-#include "BL_ArmatureObject.h"
-#include "BL_SkinDeformer.h"
-#include "BL_Action.h"
-#include "BL_ActionManager.h"
-#include "KX_GameObject.h"
-#include "STR_HashedString.h"
-#include "MEM_guardedalloc.h"
-#include "DNA_nla_types.h"
-#include "DNA_action_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_scene_types.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "MT_Matrix4x4.h"
-
-#include "BKE_action.h"
-#include "EXP_FloatValue.h"
-#include "EXP_PyObjectPlus.h"
-#include "KX_PyMath.h"
-
-extern "C" {
-#include "BKE_animsys.h"
-#include "BKE_action.h"
-#include "RNA_access.h"
-#include "RNA_define.h"
-}
-
-BL_ActionActuator::BL_ActionActuator(SCA_IObject *gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blend_mode,
- short blendin,
- short priority,
- short layer,
- float layer_weight,
- short ipo_flags,
- short end_reset,
- float stride)
- : SCA_IActuator(gameobj, KX_ACT_ACTION),
-
- m_lastpos(0, 0, 0),
- m_blendframe(0),
- m_flag(0),
- m_startframe (starttime),
- m_endframe(endtime) ,
- m_starttime(0),
- m_localtime(starttime),
- m_lastUpdate(-1),
- m_blendin(blendin),
- m_blendstart(0),
- m_stridelength(stride),
- m_layer_weight(layer_weight),
- m_playtype(playtype),
- m_blendmode(blend_mode),
- m_priority(priority),
- m_layer(layer),
- m_ipo_flags(ipo_flags),
- m_action(action),
- m_propname(propname),
- m_framepropname(framepropname)
-{
- if (!end_reset)
- m_flag |= ACT_FLAG_CONTINUE;
-};
-
-BL_ActionActuator::~BL_ActionActuator()
-{
-}
-
-void BL_ActionActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
-
- m_localtime=m_startframe;
- m_lastUpdate=-1;
-
-}
-
-void BL_ActionActuator::SetBlendTime(float newtime)
-{
- m_blendframe = newtime;
-}
-
-void BL_ActionActuator::SetLocalTime(float curtime)
-{
- float dt = (curtime-m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
-
- if (m_endframe < m_startframe)
- dt = -dt;
-
- m_localtime = m_startframe + dt;
-
- // Handle wrap around
- if (m_localtime < min(m_startframe, m_endframe) || m_localtime > max(m_startframe, m_endframe))
- {
- switch (m_playtype) {
- case ACT_ACTION_PLAY:
- // Clamp
- m_localtime = m_endframe;
- break;
- case ACT_ACTION_LOOP_END:
- // Put the time back to the beginning
- m_localtime = m_startframe;
- m_starttime = curtime;
- break;
- case ACT_ACTION_PINGPONG:
- // Swap the start and end frames
- float temp = m_startframe;
- m_startframe = m_endframe;
- m_endframe = temp;
-
- m_starttime = curtime;
-
- m_flag ^= ACT_FLAG_REVERSE;
-
- break;
- }
- }
-}
-
-void BL_ActionActuator::ResetStartTime(float curtime)
-{
- float dt = m_localtime - m_startframe;
-
- m_starttime = curtime - dt / (KX_KetsjiEngine::GetAnimFrameRate());
- //SetLocalTime(curtime);
-}
-
-CValue* BL_ActionActuator::GetReplica()
-{
- BL_ActionActuator* replica = new BL_ActionActuator(*this);//m_float,GetName());
- replica->ProcessReplica();
- return replica;
-}
-
-bool BL_ActionActuator::Update(double curtime, bool frame)
-{
- bool bNegativeEvent = false;
- bool bPositiveEvent = false;
- bool bUseContinue = false;
- KX_GameObject *obj = (KX_GameObject*)GetParent();
- short playtype = BL_Action::ACT_MODE_PLAY;
- short blendmode = (m_blendmode == ACT_ACTION_ADD) ? BL_Action::ACT_BLEND_ADD : BL_Action::ACT_BLEND_BLEND;
- float start = m_startframe;
- float end = m_endframe;
-
- // If we don't have an action, we can't do anything
- if (!m_action)
- return false;
-
- // Convert our playtype to one that BL_Action likes
- switch (m_playtype) {
- case ACT_ACTION_LOOP_END:
- case ACT_ACTION_LOOP_STOP:
- playtype = BL_Action::ACT_MODE_LOOP;
- break;
-
- case ACT_ACTION_PINGPONG:
- // We handle ping pong ourselves to increase compabitility
- // with files made prior to animation changes from GSoC 2011.
- playtype = BL_Action::ACT_MODE_PLAY;
-
- if (m_flag & ACT_FLAG_REVERSE)
- {
- start = m_endframe;
- end = m_startframe;
- }
-
- break;
- case ACT_ACTION_FROM_PROP:
- CValue* prop = GetParent()->GetProperty(m_propname);
-
- // If we don't have a property, we can't do anything, so just bail
- if (!prop) return false;
-
- playtype = BL_Action::ACT_MODE_PLAY;
- start = end = prop->GetNumber();
-
- break;
- }
-
- if (m_flag & ACT_FLAG_CONTINUE)
- bUseContinue = true;
-
-
- // Handle events
- if (frame)
- {
- bNegativeEvent = m_negevent;
- bPositiveEvent = m_posevent;
- RemoveAllEvents();
- }
-
- // "Active" actions need to keep updating their current frame
- if (bUseContinue && (m_flag & ACT_FLAG_ACTIVE))
- m_localtime = obj->GetActionFrame(m_layer);
-
- if (m_flag & ACT_FLAG_ATTEMPT_PLAY)
- SetLocalTime(curtime);
- else
- ResetStartTime(curtime);
-
- // Handle a frame property if it's defined
- if ((m_flag & ACT_FLAG_ACTIVE) && m_framepropname[0] != 0)
- {
- CValue* oldprop = obj->GetProperty(m_framepropname);
- CValue* newval = new CFloatValue(obj->GetActionFrame(m_layer));
- if (oldprop)
- oldprop->SetValue(newval);
- else
- obj->SetProperty(m_framepropname, newval);
-
- newval->Release();
- }
-
- // Handle a finished animation
- if ((m_flag & ACT_FLAG_PLAY_END) && (m_flag & ACT_FLAG_ACTIVE) && obj->IsActionDone(m_layer))
- {
- m_flag &= ~ACT_FLAG_ACTIVE;
-
- if (m_playtype == ACT_ACTION_PINGPONG) {
- m_flag ^= ACT_FLAG_REVERSE;
- }
- else {
- m_flag &= ~ACT_FLAG_ATTEMPT_PLAY;
- return false;
- }
- }
-
- // If a different action is playing, we've been overruled and are no longer active
- if (obj->GetCurrentAction(m_layer) != m_action && !obj->IsActionDone(m_layer))
- m_flag &= ~ACT_FLAG_ACTIVE;
-
- if (bPositiveEvent || (m_flag & ACT_FLAG_ATTEMPT_PLAY && !(m_flag & ACT_FLAG_ACTIVE)))
- {
- if (bPositiveEvent && m_playtype == ACT_ACTION_PLAY)
- {
- if (obj->IsActionDone(m_layer))
- m_localtime = start;
- ResetStartTime(curtime);
- }
-
- if (obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, m_blendin, playtype, m_layer_weight, m_ipo_flags, 1.f, blendmode))
- {
- m_flag |= ACT_FLAG_ACTIVE;
- if (bUseContinue)
- obj->SetActionFrame(m_layer, m_localtime);
-
- if (m_playtype == ACT_ACTION_PLAY || m_playtype == ACT_ACTION_PINGPONG)
- m_flag |= ACT_FLAG_PLAY_END;
- else
- m_flag &= ~ACT_FLAG_PLAY_END;
- }
- m_flag |= ACT_FLAG_ATTEMPT_PLAY;
- }
- else if ((m_flag & ACT_FLAG_ACTIVE) && bNegativeEvent)
- {
- m_flag &= ~ACT_FLAG_ATTEMPT_PLAY;
- m_localtime = obj->GetActionFrame(m_layer);
- bAction *curr_action = obj->GetCurrentAction(m_layer);
- if (curr_action && curr_action != m_action)
- {
- // Someone changed the action on us, so we wont mess with it
- // Hopefully there wont be too many problems with two actuators using
- // the same action...
- m_flag &= ~ACT_FLAG_ACTIVE;
- return false;
- }
-
- switch (m_playtype) {
- case ACT_ACTION_FROM_PROP:
- case ACT_ACTION_LOOP_STOP:
- obj->StopAction(m_layer); // Stop the action after getting the frame
-
- // We're done
- m_flag &= ~ACT_FLAG_ACTIVE;
- return false;
- case ACT_ACTION_LOOP_END:
- // Convert into a play and let it finish
- obj->SetPlayMode(m_layer, BL_Action::ACT_MODE_PLAY);
-
- m_flag |= ACT_FLAG_PLAY_END;
- break;
-
- case ACT_ACTION_FLIPPER:
- // Convert into a play action and play back to the beginning
- float temp = end;
- end = start;
- start = curr_action ? obj->GetActionFrame(m_layer) : temp;
- obj->PlayAction(m_action->id.name+2, start, end, m_layer, m_priority, 0, BL_Action::ACT_MODE_PLAY, m_layer_weight, m_ipo_flags, 1.f, blendmode);
-
- m_flag |= ACT_FLAG_PLAY_END;
- break;
- }
- }
-
- return m_flag & ACT_FLAG_ACTIVE;
-}
-
-void BL_ActionActuator::DecLink()
-{
- SCA_IActuator::DecLink();
- /* In this case no controllers use this action actuator,
- and it should stop its action. */
- if (m_links == 0) {
- KX_GameObject *obj = (KX_GameObject *)GetParent();
- obj->StopAction(m_layer);
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-PyObject *BL_ActionActuator::PyGetChannel(PyObject *value)
-{
- PyErr_SetString(PyExc_NotImplementedError, "BL_ActionActuator.getChannel() no longer works, please use BL_ArmatureObject.channels instead");
- return NULL;
-#if 0 // XXX To be removed in a later version (first removed in 2.64)
- const char *string= _PyUnicode_AsString(value);
-
- if (GetParent()->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE)
- {
- PyErr_SetString(PyExc_NotImplementedError, "actuator.getChannel(): Only armatures support channels");
- return NULL;
- }
-
- if (!string) {
- PyErr_SetString(PyExc_TypeError, "expected a single string");
- return NULL;
- }
-
- bPoseChannel *pchan;
-
- if (m_userpose==NULL && m_pose==NULL) {
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
- obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
- }
-
- // BKE_pose_channel_find_name accounts for NULL pose, run on both in case one exists but
- // the channel doesnt
- if ( !(pchan=BKE_pose_channel_find_name(m_userpose, string)) &&
- !(pchan=BKE_pose_channel_find_name(m_pose, string)) )
- {
- PyErr_SetString(PyExc_ValueError, "channel doesnt exist");
- return NULL;
- }
-
- PyObject *ret = PyTuple_New(3);
-
- PyObject *list = PyList_New(3);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->loc[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->loc[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->loc[2]));
- PyTuple_SET_ITEM(ret, 0, list);
-
- list = PyList_New(3);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->size[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->size[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->size[2]));
- PyTuple_SET_ITEM(ret, 1, list);
-
- list = PyList_New(4);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(pchan->quat[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(pchan->quat[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(pchan->quat[2]));
- PyList_SET_ITEM(list, 3, PyFloat_FromDouble(pchan->quat[3]));
- PyTuple_SET_ITEM(ret, 2, list);
-
- return ret;
-#if 0
- return Py_BuildValue("([fff][fff][ffff])",
- pchan->loc[0], pchan->loc[1], pchan->loc[2],
- pchan->size[0], pchan->size[1], pchan->size[2],
- pchan->quat[0], pchan->quat[1], pchan->quat[2], pchan->quat[3] );
-#endif
-#endif
-}
-
-/* setChannel */
-KX_PYMETHODDEF_DOC(BL_ActionActuator, setChannel,
-"setChannel(channel, matrix)\n"
-"\t - channel : A string specifying the name of the bone channel.\n"
-"\t - matrix : A 4x4 matrix specifying the overriding transformation\n"
-"\t as an offset from the bone's rest position.\n")
-{
- PyErr_SetString(PyExc_NotImplementedError, "BL_ActionActuator.setChannel() no longer works, please use BL_ArmatureObject.channels instead");
- return NULL;
-
-#if 0 // XXX To be removed in a later version (first removed in 2.64)
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
- char *string;
- PyObject *pymat= NULL;
- PyObject *pyloc= NULL, *pysize= NULL, *pyquat= NULL;
- bPoseChannel *pchan;
-
- if (GetParent()->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE)
- {
- PyErr_SetString(PyExc_NotImplementedError, "actuator.setChannel(): Only armatures support channels");
- return NULL;
- }
-
- if (PyTuple_Size(args)==2) {
- if (!PyArg_ParseTuple(args,"sO:setChannel", &string, &pymat)) // matrix
- return NULL;
- }
- else if (PyTuple_Size(args)==4) {
- if (!PyArg_ParseTuple(args,"sOOO:setChannel", &string, &pyloc, &pysize, &pyquat)) // loc/size/quat
- return NULL;
- }
- else {
- PyErr_SetString(PyExc_ValueError, "Expected a string and a 4x4 matrix (2 args) or a string and loc/size/quat sequences (4 args)");
- return NULL;
- }
-
- if (pymat) {
- float matrix[4][4];
- MT_Matrix4x4 mat;
-
- if (!PyMatTo(pymat, mat))
- return NULL;
-
- mat.getValue((float*)matrix);
-
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
-
- if (!m_userpose) {
- if (!m_pose)
- obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
- game_copy_pose(&m_userpose, m_pose, 0);
- }
- // pchan= BKE_pose_channel_verify(m_userpose, string); // adds the channel if its not there.
- pchan= BKE_pose_channel_find_name(m_userpose, string); // adds the channel if its not there.
-
- if (pchan) {
- copy_v3_v3(pchan->loc, matrix[3]);
- mat4_to_size(pchan->size, matrix);
- mat4_to_quat(pchan->quat, matrix);
- }
- }
- else {
- MT_Vector3 loc;
- MT_Vector3 size;
- MT_Quaternion quat;
-
- if (!PyVecTo(pyloc, loc) || !PyVecTo(pysize, size) || !PyQuatTo(pyquat, quat))
- return NULL;
-
- // same as above
- if (!m_userpose) {
- if (!m_pose)
- obj->GetPose(&m_pose); /* Get the underlying pose from the armature */
- game_copy_pose(&m_userpose, m_pose, 0);
- }
- // pchan= BKE_pose_channel_verify(m_userpose, string);
- pchan= BKE_pose_channel_find_name(m_userpose, string); // adds the channel if its not there.
-
- // for some reason loc.setValue(pchan->loc) fails
- if (pchan) {
- pchan->loc[0] = loc[0]; pchan->loc[1] = loc[1]; pchan->loc[2] = loc[2];
- pchan->size[0] = size[0]; pchan->size[1] = size[1]; pchan->size[2] = size[2];
- pchan->quat[0] = quat[3]; pchan->quat[1] = quat[0]; pchan->quat[2] = quat[1]; pchan->quat[3] = quat[2]; /* notice xyzw -> wxyz is intentional */
- }
- }
-
- if (pchan==NULL) {
- PyErr_SetString(PyExc_ValueError, "Channel could not be found, use the 'channelNames' attribute to get a list of valid channels");
- return NULL;
- }
-
- Py_RETURN_NONE;
-#endif
-}
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject BL_ActionActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ActionActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef BL_ActionActuator::Methods[] = {
- {"getChannel", (PyCFunction) BL_ActionActuator::sPyGetChannel, METH_O},
- KX_PYMETHODTABLE(BL_ActionActuator, setChannel),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ActionActuator::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ActionActuator, m_startframe),
- KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ActionActuator, m_endframe),
- KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ActionActuator, m_blendin),
- KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ActionActuator, pyattr_get_action, pyattr_set_action),
- KX_PYATTRIBUTE_RO_FUNCTION("channelNames", BL_ActionActuator, pyattr_get_channel_names),
- KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ActionActuator, m_priority),
- KX_PYATTRIBUTE_SHORT_RW("layer", 0, MAX_ACTION_LAYERS-1, true, BL_ActionActuator, m_layer),
- KX_PYATTRIBUTE_FLOAT_RW("layerWeight", 0, 1.0, BL_ActionActuator, m_layer_weight),
- KX_PYATTRIBUTE_RW_FUNCTION("frame", BL_ActionActuator, pyattr_get_frame, pyattr_set_frame),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ActionActuator, m_propname),
- KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ActionActuator, m_framepropname),
- KX_PYATTRIBUTE_RW_FUNCTION("useContinue", BL_ActionActuator, pyattr_get_use_continue, pyattr_set_use_continue),
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ActionActuator, m_blendframe, CheckBlendTime),
- KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ActionActuator,m_playtype,CheckType),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
-}
-
-int BL_ActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
-
- if (!PyUnicode_Check(value))
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, expected the string name of the action");
- return PY_SET_ATTR_FAIL;
- }
-
- bAction *action= NULL;
- STR_String val = _PyUnicode_AsString(value);
-
- if (val != "")
- {
- action= (bAction*)self->GetLogicManager()->GetActionByName(val);
- if (!action)
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Action Actuator, action not found!");
- return PY_SET_ATTR_FAIL;
- }
- }
-
- self->SetAction(action);
- return PY_SET_ATTR_SUCCESS;
-
-}
-
-PyObject *BL_ActionActuator::pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- PyErr_SetString(PyExc_NotImplementedError, "BL_ActionActuator.channelNames no longer works, please use BL_ArmatureObject.channels instead");
- return NULL;
-
-#if 0 // XXX To be removed in a later version (first removed in 2.64)
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- PyObject *ret= PyList_New(0);
- PyObject *item;
-
- if (self->GetParent()->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE)
- {
- PyErr_SetString(PyExc_NotImplementedError, "actuator.channelNames: Only armatures support channels");
- return NULL;
- }
-
- bPose *pose= ((BL_ArmatureObject*)self->GetParent())->GetOrigPose();
-
- if (pose) {
- bPoseChannel *pchan;
- for (pchan= (bPoseChannel *)pose->chanbase.first; pchan; pchan= (bPoseChannel *)pchan->next) {
- item= PyUnicode_FromString(pchan->name);
- PyList_Append(ret, item);
- Py_DECREF(item);
- }
- }
-
- return ret;
-#endif
-}
-
-PyObject *BL_ActionActuator::pyattr_get_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- return PyBool_FromLong(self->m_flag & ACT_FLAG_CONTINUE);
-}
-
-int BL_ActionActuator::pyattr_set_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
-
- if (PyObject_IsTrue(value))
- self->m_flag |= ACT_FLAG_CONTINUE;
- else
- self->m_flag &= ~ACT_FLAG_CONTINUE;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *BL_ActionActuator::pyattr_get_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
- return PyFloat_FromDouble(((KX_GameObject*)self->m_gameobj)->GetActionFrame(self->m_layer));
-}
-
-int BL_ActionActuator::pyattr_set_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ActionActuator* self = static_cast<BL_ActionActuator*>(self_v);
-
- ((KX_GameObject*)self->m_gameobj)->SetActionFrame(self->m_layer, PyFloat_AsDouble(value));
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ActionActuator.h b/source/gameengine/Converter/BL_ActionActuator.h
deleted file mode 100644
index a43cf0f0a7b..00000000000
--- a/source/gameengine/Converter/BL_ActionActuator.h
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ActionActuator.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ACTIONACTUATOR_H__
-#define __BL_ACTIONACTUATOR_H__
-
-#include "CTR_HashedPtr.h"
-#include "SCA_IActuator.h"
-#include "DNA_actuator_types.h"
-#include "MT_Point3.h"
-
-class BL_ActionActuator : public SCA_IActuator
-{
-public:
- Py_Header
- BL_ActionActuator(SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blend_mode,
- short blendin,
- short priority,
- short layer,
- float layer_weight,
- short ipo_flags,
- short end_reset,
- float stride);
-
- virtual ~BL_ActionActuator();
- virtual bool Update(double curtime, bool frame);
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
-
- void SetBlendTime(float newtime);
- void SetLocalTime(float curtime);
- void ResetStartTime(float curtime);
-
- bAction* GetAction() { return m_action; }
- void SetAction(bAction* act) { m_action= act; }
-
- virtual void DecLink();
-
-#ifdef WITH_PYTHON
-
- KX_PYMETHOD_O(BL_ActionActuator,GetChannel)
- KX_PYMETHOD_DOC(BL_ActionActuator,setChannel)
-
- static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_channel_names(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_use_continue(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_frame(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static int CheckBlendTime(void *self, const PyAttributeDef*)
- {
- BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self);
-
- if (act->m_blendframe > act->m_blendin)
- act->m_blendframe = act->m_blendin;
-
- return 0;
- }
-
- static int CheckType(void *self, const PyAttributeDef*)
- {
- BL_ActionActuator* act = reinterpret_cast<BL_ActionActuator*>(self);
-
- switch (act->m_playtype) {
- case ACT_ACTION_PLAY:
- case ACT_ACTION_PINGPONG:
- case ACT_ACTION_FLIPPER:
- case ACT_ACTION_LOOP_STOP:
- case ACT_ACTION_LOOP_END:
- case ACT_ACTION_FROM_PROP:
- return 0;
- default:
- PyErr_SetString(PyExc_ValueError, "Action Actuator, invalid play type supplied");
- return 1;
- }
- }
-#endif /* WITH_PYTHON */
-
-protected:
- MT_Point3 m_lastpos;
- float m_blendframe;
- int m_flag;
- /** The frame this action starts */
- float m_startframe;
- /** The frame this action ends */
- float m_endframe;
- /** The time this action started */
- float m_starttime;
- /** The current time of the action */
- float m_localtime;
-
- float m_lastUpdate;
- float m_blendin;
- float m_blendstart;
- float m_stridelength;
- float m_layer_weight;
- short m_playtype;
- short m_blendmode;
- short m_priority;
- short m_layer;
- short m_ipo_flags;
- struct bAction *m_action;
- STR_String m_propname;
- STR_String m_framepropname;
-};
-
-// Not all of these values are used in BL_ActionActuator anymore,
-// but BL_ShapeActionActuator still uses them, so we keep them around
-// for now.
-enum {
- ACT_FLAG_REVERSE = 1<<0,
- ACT_FLAG_LOCKINPUT = 1<<1,
- ACT_FLAG_KEYUP = 1<<2,
- ACT_FLAG_ACTIVE = 1<<3,
- ACT_FLAG_CONTINUE = 1<<4,
- ACT_FLAG_PLAY_END = 1<<5,
- ACT_FLAG_ATTEMPT_PLAY = 1<<6,
-};
-
-#endif
-
diff --git a/source/gameengine/Converter/BL_ArmatureActuator.cpp b/source/gameengine/Converter/BL_ArmatureActuator.cpp
deleted file mode 100644
index 67cc7d2c291..00000000000
--- a/source/gameengine/Converter/BL_ArmatureActuator.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureActuator.cpp
- * \ingroup bgeconv
- */
-
-
-#include "DNA_action_types.h"
-#include "DNA_constraint_types.h"
-#include "DNA_actuator_types.h"
-#include "BKE_constraint.h"
-#include "BL_ArmatureActuator.h"
-#include "BL_ArmatureObject.h"
-#include "BLI_math.h"
-
-/**
- * This class is the conversion of the Pose channel constraint.
- * It makes a link between the pose constraint and the KX scene.
- * The main purpose is to give access to the constraint target
- * to link it to a game object.
- * It also allows to activate/deactivate constraints during the game.
- * Later it will also be possible to create constraint on the fly
- */
-
-BL_ArmatureActuator::BL_ArmatureActuator(SCA_IObject* obj,
- int type,
- const char *posechannel,
- const char *constraintname,
- KX_GameObject* targetobj,
- KX_GameObject* subtargetobj,
- float weight,
- float influence) :
- SCA_IActuator(obj, KX_ACT_ARMATURE),
- m_constraint(NULL),
- m_gametarget(targetobj),
- m_gamesubtarget(subtargetobj),
- m_posechannel(posechannel),
- m_constraintname(constraintname),
- m_weight(weight),
- m_influence(influence),
- m_type(type)
-{
- if (m_gametarget)
- m_gametarget->RegisterActuator(this);
- if (m_gamesubtarget)
- m_gamesubtarget->RegisterActuator(this);
- FindConstraint();
-}
-
-BL_ArmatureActuator::~BL_ArmatureActuator()
-{
- if (m_gametarget)
- m_gametarget->UnregisterActuator(this);
- if (m_gamesubtarget)
- m_gamesubtarget->UnregisterActuator(this);
-}
-
-void BL_ArmatureActuator::ProcessReplica()
-{
- // the replica is tracking the same object => register it (this may be changed in Relnk())
- if (m_gametarget)
- m_gametarget->RegisterActuator(this);
- if (m_gamesubtarget)
- m_gamesubtarget->UnregisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-void BL_ArmatureActuator::ReParent(SCA_IObject* parent)
-{
- SCA_IActuator::ReParent(parent);
- // must remap the constraint
- FindConstraint();
-}
-
-bool BL_ArmatureActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- bool res=false;
- if (clientobj == m_gametarget)
- {
- // this object is being deleted, we cannot continue to track it.
- m_gametarget = NULL;
- res = true;
- }
- if (clientobj == m_gamesubtarget)
- {
- // this object is being deleted, we cannot continue to track it.
- m_gamesubtarget = NULL;
- res = true;
- }
- return res;
-}
-
-void BL_ArmatureActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_gametarget];
- if (h_obj) {
- if (m_gametarget)
- m_gametarget->UnregisterActuator(this);
- m_gametarget = (KX_GameObject*)(*h_obj);
- m_gametarget->RegisterActuator(this);
- }
- h_obj = (*obj_map)[m_gamesubtarget];
- if (h_obj) {
- if (m_gamesubtarget)
- m_gamesubtarget->UnregisterActuator(this);
- m_gamesubtarget = (KX_GameObject*)(*h_obj);
- m_gamesubtarget->RegisterActuator(this);
- }
-}
-
-void BL_ArmatureActuator::FindConstraint()
-{
- m_constraint = NULL;
-
- if (m_gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) {
- BL_ArmatureObject* armobj = (BL_ArmatureObject*)m_gameobj;
- m_constraint = armobj->GetConstraint(m_posechannel, m_constraintname);
- }
-}
-
-bool BL_ArmatureActuator::Update(double curtime, bool frame)
-{
- // the only role of this actuator is to ensure that the armature pose will be evaluated
- bool result = false;
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (!bNegativeEvent) {
- BL_ArmatureObject *obj = (BL_ArmatureObject*)GetParent();
- switch (m_type) {
- case ACT_ARM_RUN:
- result = true;
- obj->UpdateTimestep(curtime);
- break;
- case ACT_ARM_ENABLE:
- if (m_constraint)
- m_constraint->ClrConstraintFlag(CONSTRAINT_OFF);
- break;
- case ACT_ARM_DISABLE:
- if (m_constraint)
- m_constraint->SetConstraintFlag(CONSTRAINT_OFF);
- break;
- case ACT_ARM_SETTARGET:
- if (m_constraint) {
- m_constraint->SetTarget(m_gametarget);
- m_constraint->SetSubtarget(m_gamesubtarget);
- }
- break;
- case ACT_ARM_SETWEIGHT:
- if (m_constraint)
- m_constraint->SetWeight(m_weight);
- break;
- case ACT_ARM_SETINFLUENCE:
- if (m_constraint)
- m_constraint->SetInfluence(m_influence);
- break;
- }
- }
- return result;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject BL_ArmatureActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-
-PyMethodDef BL_ArmatureActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ArmatureActuator::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("constraint", BL_ArmatureActuator, pyattr_get_constraint),
- KX_PYATTRIBUTE_RW_FUNCTION("target", BL_ArmatureActuator, pyattr_get_object, pyattr_set_object),
- KX_PYATTRIBUTE_RW_FUNCTION("subtarget", BL_ArmatureActuator, pyattr_get_object, pyattr_set_object),
- KX_PYATTRIBUTE_FLOAT_RW("weight",0.0f,1.0f,BL_ArmatureActuator,m_weight),
- KX_PYATTRIBUTE_FLOAT_RW("influence",0.0f,1.0f,BL_ArmatureActuator,m_influence),
- KX_PYATTRIBUTE_INT_RW("type",0,ACT_ARM_MAXTYPE,false,BL_ArmatureActuator,m_type),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ArmatureActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self);
- KX_GameObject *target = (!strcmp(attrdef->m_name, "target")) ? actuator->m_gametarget : actuator->m_gamesubtarget;
- if (!target)
- Py_RETURN_NONE;
- else
- return target->GetProxy();
-}
-
-int BL_ArmatureActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self);
- KX_GameObject* &target = (!strcmp(attrdef->m_name, "target")) ? actuator->m_gametarget : actuator->m_gamesubtarget;
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: BL_ArmatureActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (target != NULL)
- target->UnregisterActuator(actuator);
-
- target = gameobj;
-
- if (target)
- target->RegisterActuator(actuator);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *BL_ArmatureActuator::pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureActuator* actuator = static_cast<BL_ArmatureActuator*>(self);
- BL_ArmatureConstraint* constraint = actuator->m_constraint;
- if (!constraint)
- Py_RETURN_NONE;
- else
- return constraint->GetProxy();
-}
-
-#endif // WITH_PYTHON
-
diff --git a/source/gameengine/Converter/BL_ArmatureActuator.h b/source/gameengine/Converter/BL_ArmatureActuator.h
deleted file mode 100644
index ba02c5aa362..00000000000
--- a/source/gameengine/Converter/BL_ArmatureActuator.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureActuator.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATUREACTUATOR_H__
-#define __BL_ARMATUREACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "BL_ArmatureConstraint.h"
-
-/**
- * This class is the conversion of the Pose channel constraint.
- * It makes a link between the pose constraint and the KX scene.
- * The main purpose is to give access to the constraint target
- * to link it to a game object.
- * It also allows to activate/deactivate constraints during the game.
- * Later it will also be possible to create constraint on the fly
- */
-
-class BL_ArmatureActuator : public SCA_IActuator
-{
- Py_Header
-public:
- BL_ArmatureActuator(SCA_IObject* gameobj,
- int type,
- const char *posechannel,
- const char *constraintname,
- KX_GameObject* targetobj,
- KX_GameObject* subtargetobj,
- float weight,
- float influence);
-
- virtual ~BL_ArmatureActuator();
-
- virtual CValue* GetReplica() {
- BL_ArmatureActuator* replica = new BL_ArmatureActuator(*this);
- replica->ProcessReplica();
- return replica;
- };
- virtual void ProcessReplica();
- virtual bool UnlinkObject(SCA_IObject* clientobj);
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual bool Update(double curtime, bool frame);
- virtual void ReParent(SCA_IObject* parent);
-
-#ifdef WITH_PYTHON
-
- /* These are used to get and set m_target */
- static PyObject *pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
-#endif /* WITH_PYTHON */
-
-private:
- // identify the constraint that this actuator controls
- void FindConstraint();
-
- BL_ArmatureConstraint* m_constraint;
- KX_GameObject* m_gametarget;
- KX_GameObject* m_gamesubtarget;
- STR_String m_posechannel;
- STR_String m_constraintname;
- float m_weight;
- float m_influence;
- int m_type;
-};
-
-#endif /* __BL_ARMATUREACTUATOR_H__ */
diff --git a/source/gameengine/Converter/BL_ArmatureChannel.cpp b/source/gameengine/Converter/BL_ArmatureChannel.cpp
deleted file mode 100644
index 2b8dfd8f8d1..00000000000
--- a/source/gameengine/Converter/BL_ArmatureChannel.cpp
+++ /dev/null
@@ -1,469 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureChannel.cpp
- * \ingroup bgeconv
- */
-
-
-#include "DNA_armature_types.h"
-#include "BL_ArmatureChannel.h"
-#include "BL_ArmatureObject.h"
-#include "BL_ArmatureConstraint.h"
-#include "BLI_math.h"
-#include "BLI_string.h"
-#include <stddef.h>
-
-#ifdef WITH_PYTHON
-
-PyTypeObject BL_ArmatureChannel::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureChannel",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyObject *BL_ArmatureChannel::py_repr(void)
-{
- return PyUnicode_FromString(m_posechannel->name);
-}
-
-PyObject *BL_ArmatureChannel::GetProxy()
-{
- return GetProxyPlus_Ext(this, &Type, m_posechannel);
-}
-
-PyObject *BL_ArmatureChannel::NewProxy(bool py_owns)
-{
- return NewProxyPlus_Ext(this, &Type, m_posechannel, py_owns);
-}
-
-#endif // WITH_PYTHON
-
-BL_ArmatureChannel::BL_ArmatureChannel(
- BL_ArmatureObject *armature,
- bPoseChannel *posechannel)
- : PyObjectPlus(), m_posechannel(posechannel), m_armature(armature)
-{
-}
-
-BL_ArmatureChannel::~BL_ArmatureChannel()
-{
-}
-
-#ifdef WITH_PYTHON
-
-// PYTHON
-
-PyMethodDef BL_ArmatureChannel::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-// order of definition of attributes, must match Attributes[] array
-#define BCA_BONE 0
-#define BCA_PARENT 1
-
-PyAttributeDef BL_ArmatureChannel::Attributes[] = {
- // Keep these attributes in order of BCA_ defines!!! used by py_attr_getattr and py_attr_setattr
- KX_PYATTRIBUTE_RO_FUNCTION("bone",BL_ArmatureChannel,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("parent",BL_ArmatureChannel,py_attr_getattr),
-
- { NULL } //Sentinel
-};
-
-/* attributes directly taken from bPoseChannel */
-PyAttributeDef BL_ArmatureChannel::AttributesPtr[] = {
- KX_PYATTRIBUTE_CHAR_RO("name",bPoseChannel,name),
- KX_PYATTRIBUTE_FLAG_RO("has_ik",bPoseChannel,flag, POSE_CHAIN),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("ik_dof_x",bPoseChannel,ikflag, BONE_IK_NO_XDOF),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("ik_dof_y",bPoseChannel,ikflag, BONE_IK_NO_YDOF),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("ik_dof_z",bPoseChannel,ikflag, BONE_IK_NO_ZDOF),
- KX_PYATTRIBUTE_FLAG_RO("ik_limit_x",bPoseChannel,ikflag, BONE_IK_XLIMIT),
- KX_PYATTRIBUTE_FLAG_RO("ik_limit_y",bPoseChannel,ikflag, BONE_IK_YLIMIT),
- KX_PYATTRIBUTE_FLAG_RO("ik_limit_z",bPoseChannel,ikflag, BONE_IK_ZLIMIT),
- KX_PYATTRIBUTE_FLAG_RO("ik_rot_control",bPoseChannel,ikflag, BONE_IK_ROTCTL),
- KX_PYATTRIBUTE_FLAG_RO("ik_lin_control",bPoseChannel,ikflag, BONE_IK_LINCTL),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("location",-FLT_MAX,FLT_MAX,bPoseChannel,loc,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("scale",-FLT_MAX,FLT_MAX,bPoseChannel,size,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("rotation_quaternion",-1.0f,1.0f,bPoseChannel,quat,4),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RW("rotation_euler",-10.f,10.f,bPoseChannel,eul,3),
- KX_PYATTRIBUTE_SHORT_RW("rotation_mode",ROT_MODE_MIN,ROT_MODE_MAX,false,bPoseChannel,rotmode),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("channel_matrix",bPoseChannel,chan_mat,4),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("pose_matrix",bPoseChannel,pose_mat,4),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("pose_head",bPoseChannel,pose_head,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("pose_tail",bPoseChannel,pose_tail,3),
- KX_PYATTRIBUTE_FLOAT_RO("ik_min_x",bPoseChannel,limitmin[0]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_max_x",bPoseChannel,limitmax[0]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_min_y",bPoseChannel,limitmin[1]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_max_y",bPoseChannel,limitmax[1]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_min_z",bPoseChannel,limitmin[2]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_max_z",bPoseChannel,limitmax[2]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stiffness_x",bPoseChannel,stiffness[0]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stiffness_y",bPoseChannel,stiffness[1]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stiffness_z",bPoseChannel,stiffness[2]),
- KX_PYATTRIBUTE_FLOAT_RO("ik_stretch",bPoseChannel,ikstretch),
- KX_PYATTRIBUTE_FLOAT_RW("ik_rot_weight",0,1.0f,bPoseChannel,ikrotweight),
- KX_PYATTRIBUTE_FLOAT_RW("ik_lin_weight",0,1.0f,bPoseChannel,iklinweight),
- KX_PYATTRIBUTE_RW_FUNCTION("joint_rotation",BL_ArmatureChannel,py_attr_get_joint_rotation,py_attr_set_joint_rotation),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ArmatureChannel::py_attr_getattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureChannel* self = static_cast<BL_ArmatureChannel*>(self_v);
- bPoseChannel* channel = self->m_posechannel;
- int attr_order = attrdef-Attributes;
-
- if (!channel) {
- PyErr_SetString(PyExc_AttributeError, "channel is NULL");
- return NULL;
- }
-
- switch (attr_order) {
- case BCA_BONE:
- // bones are standalone proxy
- return NewProxyPlus_Ext(NULL,&BL_ArmatureBone::Type,channel->bone,false);
- case BCA_PARENT:
- {
- BL_ArmatureChannel* parent = self->m_armature->GetChannel(channel->parent);
- if (parent)
- return parent->GetProxy();
- else
- Py_RETURN_NONE;
- }
- }
- PyErr_SetString(PyExc_AttributeError, "channel unknown attribute");
- return NULL;
-}
-
-int BL_ArmatureChannel::py_attr_setattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureChannel* self = static_cast<BL_ArmatureChannel*>(self_v);
- bPoseChannel* channel = self->m_posechannel;
- int attr_order = attrdef-Attributes;
-
-// int ival;
-// double dval;
-// char* sval;
-// KX_GameObject *oval;
-
- if (!channel) {
- PyErr_SetString(PyExc_AttributeError, "channel is NULL");
- return PY_SET_ATTR_FAIL;
- }
-
- switch (attr_order) {
- default:
- break;
- }
-
- PyErr_SetString(PyExc_AttributeError, "channel unknown attribute");
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *BL_ArmatureChannel::py_attr_get_joint_rotation(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- bPoseChannel* pchan = static_cast<bPoseChannel*>(self_v);
- // decompose the pose matrix in euler rotation
- float rest_mat[3][3];
- float pose_mat[3][3];
- float joint_mat[3][3];
- float joints[3];
- float norm;
- double sa, ca;
- // get rotation in armature space
- copy_m3_m4(pose_mat, pchan->pose_mat);
- normalize_m3(pose_mat);
- if (pchan->parent) {
- // bone has a parent, compute the rest pose of the bone taking actual pose of parent
- mul_m3_m3m4(rest_mat, pchan->parent->pose_mat, pchan->bone->bone_mat);
- normalize_m3(rest_mat);
- } else {
- // otherwise, the bone matrix in armature space is the rest pose
- copy_m3_m4(rest_mat, pchan->bone->arm_mat);
- }
- // remove the rest pose to get the joint movement
- transpose_m3(rest_mat);
- mul_m3_m3m3(joint_mat, rest_mat, pose_mat);
- joints[0] = joints[1] = joints[2] = 0.f;
- // returns a 3 element list that gives corresponding joint
- int flag = 0;
- if (!(pchan->ikflag & BONE_IK_NO_XDOF))
- flag |= 1;
- if (!(pchan->ikflag & BONE_IK_NO_YDOF))
- flag |= 2;
- if (!(pchan->ikflag & BONE_IK_NO_ZDOF))
- flag |= 4;
- switch (flag) {
- case 0: // fixed joint
- break;
- case 1: // X only
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[1] = joints[2] = 0.f;
- break;
- case 2: // Y only
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[0] = joints[2] = 0.f;
- break;
- case 3: // X+Y
- mat3_to_eulO( joints, EULER_ORDER_ZYX,joint_mat);
- joints[2] = 0.f;
- break;
- case 4: // Z only
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[0] = joints[1] = 0.f;
- break;
- case 5: // X+Z
- // decompose this as an equivalent rotation vector in X/Z plane
- joints[0] = joint_mat[1][2];
- joints[2] = -joint_mat[1][0];
- norm = normalize_v3(joints);
- if (norm < FLT_EPSILON) {
- norm = (joint_mat[1][1] < 0.0f) ? (float)M_PI : 0.0f;
- } else {
- norm = acos(joint_mat[1][1]);
- }
- mul_v3_fl(joints, norm);
- break;
- case 6: // Y+Z
- mat3_to_eulO( joints, EULER_ORDER_XYZ,joint_mat);
- joints[0] = 0.f;
- break;
- case 7: // X+Y+Z
- // equivalent axis
- joints[0] = (joint_mat[1][2]-joint_mat[2][1])*0.5f;
- joints[1] = (joint_mat[2][0]-joint_mat[0][2])*0.5f;
- joints[2] = (joint_mat[0][1]-joint_mat[1][0])*0.5f;
- sa = len_v3(joints);
- ca = (joint_mat[0][0]+joint_mat[1][1]+joint_mat[1][1]-1.0f)*0.5f;
- if (sa > (double)FLT_EPSILON) {
- norm = atan2(sa,ca)/sa;
- } else {
- if (ca < 0.0) {
- norm = M_PI;
- mul_v3_fl(joints,0.f);
- if (joint_mat[0][0] > 0.f) {
- joints[0] = 1.0f;
- } else if (joint_mat[1][1] > 0.f) {
- joints[1] = 1.0f;
- } else {
- joints[2] = 1.0f;
- }
- } else {
- norm = 0.0;
- }
- }
- mul_v3_fl(joints,norm);
- break;
- }
- return Vector_CreatePyObject(joints, 3, NULL);
-}
-
-int BL_ArmatureChannel::py_attr_set_joint_rotation(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureChannel* self = static_cast<BL_ArmatureChannel*>(self_v);
- bPoseChannel* pchan = self->m_posechannel;
- PyObject *item;
- float joints[3];
- float quat[4];
-
- if (!PySequence_Check(value) || PySequence_Size(value) != 3) {
- PyErr_SetString(PyExc_AttributeError, "expected a sequence of 3 floats");
- return PY_SET_ATTR_FAIL;
- }
- for (int i=0; i<3; i++) {
- item = PySequence_GetItem(value, i); /* new ref */
- joints[i] = PyFloat_AsDouble(item);
- Py_DECREF(item);
- if (joints[i] == -1.0f && PyErr_Occurred()) {
- PyErr_SetString(PyExc_AttributeError, "expected a sequence of 3 floats");
- return PY_SET_ATTR_FAIL;
- }
- }
-
- int flag = 0;
- if (!(pchan->ikflag & BONE_IK_NO_XDOF))
- flag |= 1;
- if (!(pchan->ikflag & BONE_IK_NO_YDOF))
- flag |= 2;
- if (!(pchan->ikflag & BONE_IK_NO_ZDOF))
- flag |= 4;
- unit_qt(quat);
- switch (flag) {
- case 0: // fixed joint
- break;
- case 1: // X only
- joints[1] = joints[2] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 2: // Y only
- joints[0] = joints[2] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 3: // X+Y
- joints[2] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_ZYX);
- break;
- case 4: // Z only
- joints[0] = joints[1] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 5: // X+Z
- // X and Z are components of an equivalent rotation axis
- joints[1] = 0;
- axis_angle_to_quat( quat,joints, len_v3(joints));
- break;
- case 6: // Y+Z
- joints[0] = 0.f;
- eulO_to_quat( quat,joints, EULER_ORDER_XYZ);
- break;
- case 7: // X+Y+Z
- // equivalent axis
- axis_angle_to_quat( quat,joints, len_v3(joints));
- break;
- }
- if (pchan->rotmode > 0) {
- quat_to_eulO( joints, pchan->rotmode,quat);
- copy_v3_v3(pchan->eul, joints);
- } else
- copy_qt_qt(pchan->quat, quat);
- return PY_SET_ATTR_SUCCESS;
-}
-
-// *************************
-// BL_ArmatureBone
-//
-// Access to Bone structure
-PyTypeObject BL_ArmatureBone::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureBone",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_bone_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-// not used since this class is never instantiated
-PyObject *BL_ArmatureBone::GetProxy()
-{
- return NULL;
-}
-PyObject *BL_ArmatureBone::NewProxy(bool py_owns)
-{
- return NULL;
-}
-
-PyObject *BL_ArmatureBone::py_bone_repr(PyObject *self)
-{
- Bone* bone = static_cast<Bone*>BGE_PROXY_PTR(self);
- return PyUnicode_FromString(bone->name);
-}
-
-PyMethodDef BL_ArmatureBone::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-/* no attributes on C++ class since it is never instantiated */
-PyAttributeDef BL_ArmatureBone::Attributes[] = {
- { NULL } //Sentinel
-};
-
-// attributes that work on proxy ptr (points to a Bone structure)
-PyAttributeDef BL_ArmatureBone::AttributesPtr[] = {
- KX_PYATTRIBUTE_CHAR_RO("name",Bone,name),
- KX_PYATTRIBUTE_FLAG_RO("connected",Bone,flag, BONE_CONNECTED),
- KX_PYATTRIBUTE_FLAG_RO("hinge",Bone,flag, BONE_HINGE),
- KX_PYATTRIBUTE_FLAG_NEGATIVE_RO("inherit_scale",Bone,flag, BONE_NO_SCALE),
- KX_PYATTRIBUTE_SHORT_RO("bbone_segments",Bone,segments),
- KX_PYATTRIBUTE_FLOAT_RO("roll",Bone,roll),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("head",Bone,head,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("tail",Bone,tail,3),
- KX_PYATTRIBUTE_FLOAT_RO("length",Bone,length),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("arm_head",Bone,arm_head,3),
- KX_PYATTRIBUTE_FLOAT_VECTOR_RO("arm_tail",Bone,arm_tail,3),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("arm_mat",Bone,arm_mat,4),
- KX_PYATTRIBUTE_FLOAT_MATRIX_RO("bone_mat",Bone,bone_mat,3),
- KX_PYATTRIBUTE_RO_FUNCTION("parent",BL_ArmatureBone,py_bone_get_parent),
- KX_PYATTRIBUTE_RO_FUNCTION("children",BL_ArmatureBone,py_bone_get_children),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ArmatureBone::py_bone_get_parent(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- Bone* bone = reinterpret_cast<Bone*>(self);
- if (bone->parent) {
- // create a proxy unconnected to any GE object
- return NewProxyPlus_Ext(NULL,&Type,bone->parent,false);
- }
- Py_RETURN_NONE;
-}
-
-PyObject *BL_ArmatureBone::py_bone_get_children(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- Bone* bone = reinterpret_cast<Bone*>(self);
- Bone* child;
- int count = 0;
- for (child = (Bone *)bone->childbase.first; child; child = child->next)
- count++;
-
- PyObject *childrenlist = PyList_New(count);
-
- for (count = 0, child = (Bone *)bone->childbase.first; child; child = child->next, ++count)
- PyList_SET_ITEM(childrenlist,count,NewProxyPlus_Ext(NULL,&Type,child,false));
-
- return childrenlist;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ArmatureChannel.h b/source/gameengine/Converter/BL_ArmatureChannel.h
deleted file mode 100644
index a07097f8178..00000000000
--- a/source/gameengine/Converter/BL_ArmatureChannel.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureChannel.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATURECHANNEL_H__
-#define __BL_ARMATURECHANNEL_H__
-
-#include "DNA_action_types.h"
-#include "CTR_HashedPtr.h"
-#include "CTR_Map.h"
-#include "EXP_PyObjectPlus.h"
-
-class SCA_IObject;
-class KX_GameObject;
-class BL_ArmatureObject;
-struct bConstraint;
-struct bPoseChannel;
-struct Object;
-struct bPose;
-
-class BL_ArmatureChannel : public PyObjectPlus
-{
- // use Py_HeaderPtr since we use generic pointer in proxy
- Py_HeaderPtr;
-
-private:
- friend class BL_ArmatureObject;
- struct bPoseChannel* m_posechannel;
- BL_ArmatureObject* m_armature;
-
-public:
- BL_ArmatureChannel(class BL_ArmatureObject *armature,
- struct bPoseChannel *posechannel);
- virtual ~BL_ArmatureChannel();
-
- inline const char *GetName()
- {
- return m_posechannel->name;
- }
-
-#ifdef WITH_PYTHON
- // Python access
- virtual PyObject *py_repr(void);
-
- static PyObject *py_attr_getattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int py_attr_setattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *py_attr_get_joint_rotation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int py_attr_set_joint_rotation(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif /* WITH_PYTHON */
-};
-
-/* this is a factory class to access bBone data field in the GE.
- * It's not supposed to be instantiated, we only need it for the Attributes and Method array.
- * The actual proxy object will be manually created using NewProxyPtr */
-class BL_ArmatureBone : public PyObjectPlus
-{
- // use Py_HeaderPtr since we use generic pointer in proxy
- Py_HeaderPtr;
-private:
- // make constructor private to make sure no one tries to instantiate this class
- BL_ArmatureBone() {}
- virtual ~BL_ArmatureBone() {}
-
-public:
-
-#ifdef WITH_PYTHON
- static PyObject *py_bone_repr(PyObject *self);
- static PyObject *py_bone_get_parent(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *py_bone_get_children(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-
-};
-
-#endif /* __BL_ARMATURECHANNEL_H__ */
diff --git a/source/gameengine/Converter/BL_ArmatureConstraint.cpp b/source/gameengine/Converter/BL_ArmatureConstraint.cpp
deleted file mode 100644
index d0c7e061fb7..00000000000
--- a/source/gameengine/Converter/BL_ArmatureConstraint.cpp
+++ /dev/null
@@ -1,456 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureConstraint.cpp
- * \ingroup bgeconv
- */
-
-
-#include "DNA_constraint_types.h"
-#include "DNA_action_types.h"
-#include "BL_ArmatureConstraint.h"
-#include "BL_ArmatureObject.h"
-#include "BLI_math.h"
-#include "BLI_string.h"
-#include "KX_PythonInit.h"
-
-#ifdef WITH_PYTHON
-
-PyTypeObject BL_ArmatureConstraint::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureConstraint",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyObject *BL_ArmatureConstraint::py_repr(void)
-{
- return PyUnicode_FromString(m_name);
-}
-
-#endif // WITH_PYTHON
-
-BL_ArmatureConstraint::BL_ArmatureConstraint(
- BL_ArmatureObject *armature,
- bPoseChannel *posechannel,
- bConstraint *constraint,
- KX_GameObject* target,
- KX_GameObject* subtarget)
- : PyObjectPlus(), m_constraint(constraint), m_posechannel(posechannel), m_armature(armature)
-{
- m_target = target;
- m_blendtarget = (target) ? target->GetBlenderObject() : NULL;
- m_subtarget = subtarget;
- m_blendsubtarget = (subtarget) ? subtarget->GetBlenderObject() : NULL;
- m_pose = m_subpose = NULL;
- if (m_blendtarget) {
- copy_m4_m4(m_blendmat, m_blendtarget->obmat);
- if (m_blendtarget->type == OB_ARMATURE)
- m_pose = m_blendtarget->pose;
- }
- if (m_blendsubtarget) {
- copy_m4_m4(m_blendsubmat, m_blendsubtarget->obmat);
- if (m_blendsubtarget->type == OB_ARMATURE)
- m_subpose = m_blendsubtarget->pose;
- }
- if (m_target)
- m_target->RegisterObject(m_armature);
- if (m_subtarget)
- m_subtarget->RegisterObject(m_armature);
- BLI_snprintf(m_name, sizeof(m_name), "%s:%s", m_posechannel->name, m_constraint->name);
-}
-
-BL_ArmatureConstraint::~BL_ArmatureConstraint()
-{
- if (m_target)
- m_target->UnregisterObject(m_armature);
- if (m_subtarget)
- m_subtarget->UnregisterObject(m_armature);
-}
-
-BL_ArmatureConstraint* BL_ArmatureConstraint::GetReplica() const
-{
- BL_ArmatureConstraint* replica = new BL_ArmatureConstraint(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void BL_ArmatureConstraint::ReParent(BL_ArmatureObject* armature)
-{
- m_armature = armature;
- if (m_target)
- m_target->RegisterObject(armature);
- if (m_subtarget)
- m_subtarget->RegisterObject(armature);
- // find the corresponding constraint in the new armature object
- if (m_constraint) {
- bPose* newpose = armature->GetOrigPose();
- char* constraint = m_constraint->name;
- char* posechannel = m_posechannel->name;
- bPoseChannel* pchan;
- bConstraint* pcon;
- m_constraint = NULL;
- m_posechannel = NULL;
- // and locate the constraint
- for (pchan = (bPoseChannel*)newpose->chanbase.first; pchan; pchan = (bPoseChannel*)pchan->next) {
- if (!strcmp(pchan->name, posechannel)) {
- // now locate the constraint
- for (pcon = (bConstraint *)pchan->constraints.first; pcon; pcon = (bConstraint *)pcon->next) {
- if (!strcmp(pcon->name, constraint)) {
- m_constraint = pcon;
- m_posechannel = pchan;
- break;
- }
- }
- break;
- }
- }
- }
-}
-
-void BL_ArmatureConstraint::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_target];
- if (h_obj) {
- m_target->UnregisterObject(m_armature);
- m_target = (KX_GameObject*)(*h_obj);
- m_target->RegisterObject(m_armature);
- }
- h_obj = (*obj_map)[m_subtarget];
- if (h_obj) {
- m_subtarget->UnregisterObject(m_armature);
- m_subtarget = (KX_GameObject*)(*h_obj);
- m_subtarget->RegisterObject(m_armature);
- }
-}
-
-bool BL_ArmatureConstraint::UnlinkObject(SCA_IObject* clientobj)
-{
- bool res=false;
- if (clientobj == m_target) {
- m_target = NULL;
- res = true;
- }
- if (clientobj == m_subtarget) {
- m_subtarget = NULL;
- res = true;
- }
- return res;
-}
-
-void BL_ArmatureConstraint::UpdateTarget()
-{
- if (m_constraint && !(m_constraint->flag&CONSTRAINT_OFF) && (!m_blendtarget || m_target)) {
- if (m_blendtarget) {
- // external target, must be updated
- m_target->UpdateBlenderObjectMatrix(m_blendtarget);
- if (m_pose && m_target->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- // update the pose in case a bone is specified in the constraint target
- m_blendtarget->pose = ((BL_ArmatureObject*)m_target)->GetOrigPose();
- }
- if (m_blendsubtarget && m_subtarget) {
- m_subtarget->UpdateBlenderObjectMatrix(m_blendsubtarget);
- if (m_subpose && m_subtarget->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- m_blendsubtarget->pose = ((BL_ArmatureObject*)m_subtarget)->GetOrigPose();
- }
- }
-}
-
-void BL_ArmatureConstraint::RestoreTarget()
-{
- if (m_constraint && !(m_constraint->flag&CONSTRAINT_OFF) && (!m_blendtarget || m_target)) {
- if (m_blendtarget) {
- copy_m4_m4(m_blendtarget->obmat, m_blendmat);
- if (m_pose)
- m_blendtarget->pose = m_pose;
- }
- if (m_blendsubtarget && m_subtarget) {
- copy_m4_m4(m_blendsubtarget->obmat, m_blendsubmat);
- if (m_subpose)
- m_blendsubtarget->pose = m_subpose;
- }
- }
-}
-
-bool BL_ArmatureConstraint::Match(const char* posechannel, const char* constraint)
-{
- return (!strcmp(m_posechannel->name, posechannel) && !strcmp(m_constraint->name, constraint));
-}
-
-void BL_ArmatureConstraint::SetTarget(KX_GameObject* target)
-{
- if (m_blendtarget) {
- if (target != m_target) {
- m_target->UnregisterObject(m_armature);
- m_target = target;
- if (m_target)
- m_target->RegisterObject(m_armature);
- }
- }
-
-}
-
-void BL_ArmatureConstraint::SetSubtarget(KX_GameObject* subtarget)
-{
- if (m_blendsubtarget) {
- if (subtarget != m_subtarget) {
- m_subtarget->UnregisterObject(m_armature);
- m_subtarget = subtarget;
- if (m_subtarget)
- m_subtarget->RegisterObject(m_armature);
- }
- }
-
-}
-
-#ifdef WITH_PYTHON
-
-// PYTHON
-
-PyMethodDef BL_ArmatureConstraint::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-// order of definition of attributes, must match Attributes[] array
-#define BCA_TYPE 0
-#define BCA_NAME 1
-#define BCA_ENFORCE 2
-#define BCA_HEADTAIL 3
-#define BCA_LINERROR 4
-#define BCA_ROTERROR 5
-#define BCA_TARGET 6
-#define BCA_SUBTARGET 7
-#define BCA_ACTIVE 8
-#define BCA_IKWEIGHT 9
-#define BCA_IKTYPE 10
-#define BCA_IKFLAG 11
-#define BCA_IKDIST 12
-#define BCA_IKMODE 13
-
-PyAttributeDef BL_ArmatureConstraint::Attributes[] = {
- // Keep these attributes in order of BCA_ defines!!! used by py_attr_getattr and py_attr_setattr
- KX_PYATTRIBUTE_RO_FUNCTION("type",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("name",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RW_FUNCTION("enforce",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("headtail",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RO_FUNCTION("lin_error",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("rot_error",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RW_FUNCTION("target",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("subtarget",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("active",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("ik_weight",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RO_FUNCTION("ik_type",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RO_FUNCTION("ik_flag",BL_ArmatureConstraint,py_attr_getattr),
- KX_PYATTRIBUTE_RW_FUNCTION("ik_dist",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
- KX_PYATTRIBUTE_RW_FUNCTION("ik_mode",BL_ArmatureConstraint,py_attr_getattr,py_attr_setattr),
-
- { NULL } //Sentinel
-};
-
-
-PyObject *BL_ArmatureConstraint::py_attr_getattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureConstraint* self = static_cast<BL_ArmatureConstraint*>(self_v);
- bConstraint* constraint = self->m_constraint;
- bKinematicConstraint* ikconstraint = (constraint && constraint->type == CONSTRAINT_TYPE_KINEMATIC) ? (bKinematicConstraint*)constraint->data : NULL;
- int attr_order = attrdef-Attributes;
-
- if (!constraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is NULL");
- return NULL;
- }
-
- switch (attr_order) {
- case BCA_TYPE:
- return PyLong_FromLong(constraint->type);
- case BCA_NAME:
- return PyUnicode_FromString(constraint->name);
- case BCA_ENFORCE:
- return PyFloat_FromDouble(constraint->enforce);
- case BCA_HEADTAIL:
- return PyFloat_FromDouble(constraint->headtail);
- case BCA_LINERROR:
- return PyFloat_FromDouble(constraint->lin_error);
- case BCA_ROTERROR:
- return PyFloat_FromDouble(constraint->rot_error);
- case BCA_TARGET:
- if (!self->m_target)
- Py_RETURN_NONE;
- else
- return self->m_target->GetProxy();
- case BCA_SUBTARGET:
- if (!self->m_subtarget)
- Py_RETURN_NONE;
- else
- return self->m_subtarget->GetProxy();
- case BCA_ACTIVE:
- return PyBool_FromLong((constraint->flag & CONSTRAINT_OFF) == 0);
- case BCA_IKWEIGHT:
- case BCA_IKTYPE:
- case BCA_IKFLAG:
- case BCA_IKDIST:
- case BCA_IKMODE:
- if (!ikconstraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is not of IK type");
- return NULL;
- }
- switch (attr_order) {
- case BCA_IKWEIGHT:
- return PyFloat_FromDouble(ikconstraint->weight);
- case BCA_IKTYPE:
- return PyLong_FromLong(ikconstraint->type);
- case BCA_IKFLAG:
- return PyLong_FromLong(ikconstraint->flag);
- case BCA_IKDIST:
- return PyFloat_FromDouble(ikconstraint->dist);
- case BCA_IKMODE:
- return PyLong_FromLong(ikconstraint->mode);
- }
- // should not come here
- break;
- }
- PyErr_SetString(PyExc_AttributeError, "constraint unknown attribute");
- return NULL;
-}
-
-int BL_ArmatureConstraint::py_attr_setattr(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ArmatureConstraint* self = static_cast<BL_ArmatureConstraint*>(self_v);
- bConstraint* constraint = self->m_constraint;
- bKinematicConstraint* ikconstraint = (constraint && constraint->type == CONSTRAINT_TYPE_KINEMATIC) ? (bKinematicConstraint*)constraint->data : NULL;
- int attr_order = attrdef-Attributes;
- int ival;
- double dval;
-// char* sval;
- SCA_LogicManager *logicmgr = KX_GetActiveScene()->GetLogicManager();
- KX_GameObject *oval;
-
- if (!constraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is NULL");
- return PY_SET_ATTR_FAIL;
- }
-
- switch (attr_order) {
- case BCA_ENFORCE:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0 || dval > 1.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.enforce = float: BL_ArmatureConstraint, expected a float between 0 and 1");
- return PY_SET_ATTR_FAIL;
- }
- constraint->enforce = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_HEADTAIL:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0 || dval > 1.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.headtail = float: BL_ArmatureConstraint, expected a float between 0 and 1");
- return PY_SET_ATTR_FAIL;
- }
- constraint->headtail = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_TARGET:
- if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.target = value: BL_ArmatureConstraint"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
- self->SetTarget(oval);
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_SUBTARGET:
- if (!ConvertPythonToGameObject(logicmgr, value, &oval, true, "constraint.subtarget = value: BL_ArmatureConstraint"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
- self->SetSubtarget(oval);
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_ACTIVE:
- ival = PyObject_IsTrue( value );
- if (ival == -1) {
- PyErr_SetString(PyExc_AttributeError, "constraint.active = bool: BL_ArmatureConstraint, expected True or False");
- return PY_SET_ATTR_FAIL;
- }
- self->m_constraint->flag = (self->m_constraint->flag & ~CONSTRAINT_OFF) | ((ival)?0:CONSTRAINT_OFF);
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_IKWEIGHT:
- case BCA_IKDIST:
- case BCA_IKMODE:
- if (!ikconstraint) {
- PyErr_SetString(PyExc_AttributeError, "constraint is not of IK type");
- return PY_SET_ATTR_FAIL;
- }
- switch (attr_order) {
- case BCA_IKWEIGHT:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0 || dval > 1.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.weight = float: BL_ArmatureConstraint, expected a float between 0 and 1");
- return PY_SET_ATTR_FAIL;
- }
- ikconstraint->weight = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_IKDIST:
- dval = PyFloat_AsDouble(value);
- if (dval < 0.0) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "constraint.ik_dist = float: BL_ArmatureConstraint, expected a positive float");
- return PY_SET_ATTR_FAIL;
- }
- ikconstraint->dist = dval;
- return PY_SET_ATTR_SUCCESS;
-
- case BCA_IKMODE:
- ival = PyLong_AsLong(value);
- if (ival < 0) {
- PyErr_SetString(PyExc_AttributeError, "constraint.ik_mode = integer: BL_ArmatureConstraint, expected a positive integer");
- return PY_SET_ATTR_FAIL;
- }
- ikconstraint->mode = ival;
- return PY_SET_ATTR_SUCCESS;
- }
- // should not come here
- break;
-
- }
-
- PyErr_SetString(PyExc_AttributeError, "constraint unknown attribute");
- return PY_SET_ATTR_FAIL;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ArmatureConstraint.h b/source/gameengine/Converter/BL_ArmatureConstraint.h
deleted file mode 100644
index 1d9f7f0d548..00000000000
--- a/source/gameengine/Converter/BL_ArmatureConstraint.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureConstraint.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATURECONSTRAINT_H__
-#define __BL_ARMATURECONSTRAINT_H__
-
-#include "DNA_constraint_types.h"
-#include "CTR_HashedPtr.h"
-#include "CTR_Map.h"
-#include "EXP_PyObjectPlus.h"
-
-class SCA_IObject;
-class KX_GameObject;
-class BL_ArmatureObject;
-struct bConstraint;
-struct bPoseChannel;
-struct Object;
-struct bPose;
-
-/**
- * SG_DList : element of controlled constraint list
- * head = BL_ArmatureObject::m_controlledConstraints
- * SG_QList : not used
- */
-class BL_ArmatureConstraint : public PyObjectPlus
-{
- Py_Header
-
-private:
- struct bConstraint* m_constraint;
- struct bPoseChannel* m_posechannel;
- class BL_ArmatureObject* m_armature;
- char m_name[64];
- KX_GameObject* m_target;
- KX_GameObject* m_subtarget;
- struct Object* m_blendtarget;
- struct Object* m_blendsubtarget;
- float m_blendmat[4][4];
- float m_blendsubmat[4][4];
- struct bPose* m_pose;
- struct bPose* m_subpose;
-
-public:
- BL_ArmatureConstraint(class BL_ArmatureObject *armature,
- struct bPoseChannel *posechannel,
- struct bConstraint *constraint,
- KX_GameObject* target,
- KX_GameObject* subtarget);
- virtual ~BL_ArmatureConstraint();
-
- BL_ArmatureConstraint* GetReplica() const;
- void ReParent(BL_ArmatureObject* armature);
- void Relink(CTR_Map<CTR_HashedPtr, void*> *map);
- bool UnlinkObject(SCA_IObject* clientobj);
-
- void UpdateTarget();
- void RestoreTarget();
-
- bool Match(const char* posechannel, const char* constraint);
- const char* GetName() { return m_name; }
-
- void SetConstraintFlag(int flag)
- {
- if (m_constraint)
- m_constraint->flag |= flag;
- }
- void ClrConstraintFlag(int flag)
- {
- if (m_constraint)
- m_constraint->flag &= ~flag;
- }
- void SetWeight(float weight)
- {
- if (m_constraint && m_constraint->type == CONSTRAINT_TYPE_KINEMATIC && m_constraint->data) {
- bKinematicConstraint* con = (bKinematicConstraint*)m_constraint->data;
- con->weight = weight;
- }
- }
- void SetInfluence(float influence)
- {
- if (m_constraint)
- m_constraint->enforce = influence;
- }
- void SetTarget(KX_GameObject* target);
- void SetSubtarget(KX_GameObject* subtarget);
-
-#ifdef WITH_PYTHON
-
- // Python access
- virtual PyObject *py_repr(void);
-
- static PyObject *py_attr_getattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int py_attr_setattr(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif /* WITH_PYTHON */
-};
-
-#endif /* __BL_ARMATURECONSTRAINT_H__ */
diff --git a/source/gameengine/Converter/BL_ArmatureObject.cpp b/source/gameengine/Converter/BL_ArmatureObject.cpp
deleted file mode 100644
index a5af525e13a..00000000000
--- a/source/gameengine/Converter/BL_ArmatureObject.cpp
+++ /dev/null
@@ -1,687 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ArmatureObject.cpp
- * \ingroup bgeconv
- */
-
-
-#include "BL_ArmatureObject.h"
-#include "BL_ActionActuator.h"
-#include "BL_Action.h"
-#include "KX_BlenderSceneConverter.h"
-#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_utildefines.h"
-#include "BLI_ghash.h"
-#include "BIK_api.h"
-#include "BKE_action.h"
-#include "BKE_armature.h"
-#include "BKE_object.h"
-#include "BKE_library.h"
-#include "BKE_global.h"
-
-extern "C" {
-#include "BKE_animsys.h"
-}
-
-#include "BKE_constraint.h"
-#include "CTR_Map.h"
-#include "CTR_HashedPtr.h"
-#include "MEM_guardedalloc.h"
-#include "DNA_action_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_constraint_types.h"
-#include "RNA_access.h"
-#include "KX_PythonInit.h"
-#include "KX_KetsjiEngine.h"
-
-#include "EXP_ListWrapper.h"
-
-#include "MT_Matrix4x4.h"
-
-/**
- * Move here pose function for game engine so that we can mix with GE objects
- * Principle is as follow:
- * Use Blender structures so that BKE_pose_where_is can be used unchanged
- * Copy the constraint so that they can be enabled/disabled/added/removed at runtime
- * Don't copy the constraints for the pose used by the Action actuator, it does not need them.
- * Scan the constraint structures so that the KX equivalent of target objects are identified and
- * stored in separate list.
- * When it is about to evaluate the pose, set the KX object position in the obmat of the corresponding
- * Blender objects and restore after the evaluation.
- */
-static void game_copy_pose(bPose **dst, bPose *src, int copy_constraint)
-{
- bPose *out;
- bPoseChannel *pchan, *outpchan;
- GHash *ghash;
-
- /* the game engine copies the current armature pose and then swaps
- * the object pose pointer. this makes it possible to change poses
- * without affecting the original blender data. */
-
- if (!src) {
- *dst=NULL;
- return;
- }
- else if (*dst==src) {
- printf("game_copy_pose source and target are the same\n");
- *dst=NULL;
- return;
- }
-
- out= (bPose*)MEM_dupallocN(src);
- out->chanhash = NULL;
- out->agroups.first= out->agroups.last= NULL;
- out->ikdata = NULL;
- out->ikparam = MEM_dupallocN(src->ikparam);
- out->flag |= POSE_GAME_ENGINE;
- BLI_duplicatelist(&out->chanbase, &src->chanbase);
-
- /* remap pointers */
- ghash= BLI_ghash_new(BLI_ghashutil_ptrhash, BLI_ghashutil_ptrcmp, "game_copy_pose gh");
-
- pchan= (bPoseChannel *)src->chanbase.first;
- outpchan= (bPoseChannel *)out->chanbase.first;
- for (; pchan; pchan=pchan->next, outpchan=outpchan->next)
- BLI_ghash_insert(ghash, pchan, outpchan);
-
- for (pchan = (bPoseChannel *)out->chanbase.first; pchan; pchan = pchan->next) {
- pchan->parent= (bPoseChannel *)BLI_ghash_lookup(ghash, pchan->parent);
- pchan->child= (bPoseChannel *)BLI_ghash_lookup(ghash, pchan->child);
-
- if (copy_constraint) {
- ListBase listb;
- // copy all constraint for backward compatibility
- // BKE_constraints_copy NULLs listb, no need to make extern for this operation.
- BKE_constraints_copy(&listb, &pchan->constraints, false);
- pchan->constraints= listb;
- }
- else {
- BLI_listbase_clear(&pchan->constraints);
- }
-
- if (pchan->custom) {
- id_us_plus(&pchan->custom->id);
- }
-
- // fails to link, props are not used in the BGE yet.
-#if 0
- if (pchan->prop)
- pchan->prop= IDP_CopyProperty(pchan->prop);
-#endif
- pchan->prop= NULL;
- }
-
- BLI_ghash_free(ghash, NULL, NULL);
- // set acceleration structure for channel lookup
- BKE_pose_channels_hash_make(out);
- *dst=out;
-}
-
-
-
-/* Only allowed for Poses with identical channels */
-static void game_blend_poses(bPose *dst, bPose *src, float srcweight, short mode)
-{
- bPoseChannel *dchan;
- const bPoseChannel *schan;
- bConstraint *dcon, *scon;
- float dstweight;
- int i;
-
- if (mode == BL_Action::ACT_BLEND_BLEND)
- {
- dstweight = 1.0f - srcweight;
- } else if (mode == BL_Action::ACT_BLEND_ADD)
- {
- dstweight = 1.0f;
- } else {
- dstweight = 1.0f;
- }
-
- schan= (bPoseChannel *)src->chanbase.first;
- for (dchan = (bPoseChannel *)dst->chanbase.first; dchan; dchan=(bPoseChannel *)dchan->next, schan= (bPoseChannel *)schan->next) {
- // always blend on all channels since we don't know which one has been set
- /* quat interpolation done separate */
- if (schan->rotmode == ROT_MODE_QUAT) {
- float dquat[4], squat[4];
-
- copy_qt_qt(dquat, dchan->quat);
- copy_qt_qt(squat, schan->quat);
- // Normalize quaternions so that interpolation/multiplication result is correct.
- normalize_qt(dquat);
- normalize_qt(squat);
-
- if (mode==BL_Action::ACT_BLEND_BLEND)
- interp_qt_qtqt(dchan->quat, dquat, squat, srcweight);
- else {
- mul_fac_qt_fl(squat, srcweight);
- mul_qt_qtqt(dchan->quat, dquat, squat);
- }
-
- normalize_qt(dchan->quat);
- }
-
- for (i=0; i<3; i++) {
- /* blending for loc and scale are pretty self-explanatory... */
- dchan->loc[i] = (dchan->loc[i]*dstweight) + (schan->loc[i]*srcweight);
- dchan->size[i] = 1.0f + ((dchan->size[i]-1.0f)*dstweight) + ((schan->size[i]-1.0f)*srcweight);
-
- /* euler-rotation interpolation done here instead... */
- // FIXME: are these results decent?
- if (schan->rotmode)
- dchan->eul[i] = (dchan->eul[i]*dstweight) + (schan->eul[i]*srcweight);
- }
- for (dcon= (bConstraint *)dchan->constraints.first, scon= (bConstraint *)schan->constraints.first;
- dcon && scon;
- dcon = dcon->next, scon = scon->next)
- {
- /* no 'add' option for constraint blending */
- dcon->enforce= dcon->enforce*(1.0f-srcweight) + scon->enforce*srcweight;
- }
- }
-
- /* this pose is now in src time */
- dst->ctime= src->ctime;
-}
-
-BL_ArmatureObject::BL_ArmatureObject(
- void* sgReplicationInfo,
- SG_Callbacks callbacks,
- Object *armature,
- Scene *scene,
- int vert_deform_type)
-
-: KX_GameObject(sgReplicationInfo,callbacks),
- m_controlledConstraints(),
- m_poseChannels(),
- m_scene(scene), // maybe remove later. needed for BKE_pose_where_is
- m_lastframe(0.0),
- m_timestep(0.040),
- m_vert_deform_type(vert_deform_type),
- m_constraintNumber(0),
- m_channelNumber(0),
- m_lastapplyframe(0.0)
-{
- m_origObjArma = armature; // Keep a copy of the original armature so we can fix drivers later
- m_objArma = BKE_object_copy(G.main, armature);
- m_objArma->data = BKE_armature_copy(G.main, (bArmature *)armature->data);
- // During object replication ob->data is increase, we decrease it now because we get a copy.
- id_us_min(&((bArmature *)m_origObjArma->data)->id);
- m_pose = m_objArma->pose;
- // need this to get iTaSC working ok in the BGE
- m_pose->flag |= POSE_GAME_ENGINE;
- memcpy(m_obmat, m_objArma->obmat, sizeof(m_obmat));
-
- // The side-effect of this method registers this object as "animatable" with the KX_Scene.
- GetActionManager();
-}
-
-BL_ArmatureObject::~BL_ArmatureObject()
-{
- BL_ArmatureConstraint* constraint;
- while ((constraint = m_controlledConstraints.Remove()) != NULL) {
- delete constraint;
- }
- BL_ArmatureChannel* channel;
- while ((channel = static_cast<BL_ArmatureChannel*>(m_poseChannels.Remove())) != NULL) {
- delete channel;
- }
-
- if (m_objArma) {
- BKE_libblock_free(G.main, m_objArma->data);
- BKE_libblock_free(G.main, m_objArma);
- }
-}
-
-
-void BL_ArmatureObject::LoadConstraints(KX_BlenderSceneConverter* converter)
-{
- // first delete any existing constraint (should not have any)
- while (!m_controlledConstraints.Empty()) {
- BL_ArmatureConstraint* constraint = m_controlledConstraints.Remove();
- delete constraint;
- }
- m_constraintNumber = 0;
-
- // list all the constraint and convert them to BL_ArmatureConstraint
- // get the persistent pose structure
- bPoseChannel* pchan;
- bConstraint* pcon;
- const bConstraintTypeInfo* cti;
- Object* blendtarget;
- KX_GameObject* gametarget;
- KX_GameObject* gamesubtarget;
-
- // and locate the constraint
- for (pchan = (bPoseChannel *)m_pose->chanbase.first; pchan; pchan = pchan->next) {
- for (pcon = (bConstraint *)pchan->constraints.first; pcon; pcon = pcon->next) {
- if (pcon->flag & CONSTRAINT_DISABLE)
- continue;
- // which constraint should we support?
- switch (pcon->type) {
- case CONSTRAINT_TYPE_TRACKTO:
- case CONSTRAINT_TYPE_DAMPTRACK:
- case CONSTRAINT_TYPE_KINEMATIC:
- case CONSTRAINT_TYPE_ROTLIKE:
- case CONSTRAINT_TYPE_LOCLIKE:
- case CONSTRAINT_TYPE_MINMAX:
- case CONSTRAINT_TYPE_SIZELIKE:
- case CONSTRAINT_TYPE_LOCKTRACK:
- case CONSTRAINT_TYPE_STRETCHTO:
- case CONSTRAINT_TYPE_CLAMPTO:
- case CONSTRAINT_TYPE_TRANSFORM:
- case CONSTRAINT_TYPE_DISTLIMIT:
- case CONSTRAINT_TYPE_TRANSLIKE:
- cti = BKE_constraint_typeinfo_get(pcon);
- gametarget = gamesubtarget = NULL;
- if (cti && cti->get_constraint_targets) {
- ListBase listb = { NULL, NULL };
- cti->get_constraint_targets(pcon, &listb);
- if (listb.first) {
- bConstraintTarget* target = (bConstraintTarget*)listb.first;
- if (target->tar && target->tar != m_objArma) {
- // only remember external objects, self target is handled automatically
- blendtarget = target->tar;
- gametarget = converter->FindGameObject(blendtarget);
- }
- if (target->next != NULL) {
- // secondary target
- target = target->next;
- if (target->tar && target->tar != m_objArma) {
- // only track external object
- blendtarget = target->tar;
- gamesubtarget = converter->FindGameObject(blendtarget);
- }
- }
- }
- if (cti->flush_constraint_targets)
- cti->flush_constraint_targets(pcon, &listb, 1);
- }
- BL_ArmatureConstraint* constraint = new BL_ArmatureConstraint(this, pchan, pcon, gametarget, gamesubtarget);
- m_controlledConstraints.AddBack(constraint);
- m_constraintNumber++;
- }
- }
- }
-
- // If we have constraints, make sure we get treated as an "animated" object
- if (m_constraintNumber > 0)
- GetActionManager();
-}
-
-BL_ArmatureConstraint* BL_ArmatureObject::GetConstraint(const char* posechannel, const char* constraintname)
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- BL_ArmatureConstraint* constraint = *cit;
- if (constraint->Match(posechannel, constraintname))
- return constraint;
- }
- return NULL;
-}
-
-BL_ArmatureConstraint* BL_ArmatureObject::GetConstraint(const char* posechannelconstraint)
-{
- // performance: use hash string instead of plain string compare
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- BL_ArmatureConstraint* constraint = *cit;
- if (!strcmp(constraint->GetName(), posechannelconstraint))
- return constraint;
- }
- return NULL;
-}
-
-BL_ArmatureConstraint* BL_ArmatureObject::GetConstraint(int index)
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end() && index; ++cit, --index);
- return (cit.end()) ? NULL : *cit;
-}
-
-/* this function is called to populate the m_poseChannels list */
-void BL_ArmatureObject::LoadChannels()
-{
- if (m_poseChannels.Empty()) {
- bPoseChannel* pchan;
- BL_ArmatureChannel* proxy;
-
- m_channelNumber = 0;
- for (pchan = (bPoseChannel *)m_pose->chanbase.first; pchan; pchan=(bPoseChannel *)pchan->next) {
- proxy = new BL_ArmatureChannel(this, pchan);
- m_poseChannels.AddBack(proxy);
- m_channelNumber++;
- }
- }
-}
-
-BL_ArmatureChannel* BL_ArmatureObject::GetChannel(bPoseChannel* pchan)
-{
- LoadChannels();
- SG_DList::iterator<BL_ArmatureChannel> cit(m_poseChannels);
- for (cit.begin(); !cit.end(); ++cit)
- {
- BL_ArmatureChannel* channel = *cit;
- if (channel->m_posechannel == pchan)
- return channel;
- }
- return NULL;
-}
-
-BL_ArmatureChannel* BL_ArmatureObject::GetChannel(const char* str)
-{
- LoadChannels();
- SG_DList::iterator<BL_ArmatureChannel> cit(m_poseChannels);
- for (cit.begin(); !cit.end(); ++cit)
- {
- BL_ArmatureChannel* channel = *cit;
- if (!strcmp(channel->m_posechannel->name, str))
- return channel;
- }
- return NULL;
-}
-
-BL_ArmatureChannel* BL_ArmatureObject::GetChannel(int index)
-{
- LoadChannels();
- if (index < 0 || index >= m_channelNumber)
- return NULL;
- SG_DList::iterator<BL_ArmatureChannel> cit(m_poseChannels);
- for (cit.begin(); !cit.end() && index; ++cit, --index);
- return (cit.end()) ? NULL : *cit;
-}
-
-CValue* BL_ArmatureObject::GetReplica()
-{
- BL_ArmatureObject* replica = new BL_ArmatureObject(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void BL_ArmatureObject::ProcessReplica()
-{
- KX_GameObject::ProcessReplica();
-
- bArmature* tmp = (bArmature*)m_objArma->data;
- m_objArma = BKE_object_copy(G.main, m_objArma);
- m_objArma->data = BKE_armature_copy(G.main, tmp);
- m_pose = m_objArma->pose;
-}
-
-void BL_ArmatureObject::ReParentLogic()
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->ReParent(this);
- }
- KX_GameObject::ReParentLogic();
-}
-
-void BL_ArmatureObject::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->Relink(obj_map);
- }
- KX_GameObject::Relink(obj_map);
-}
-
-bool BL_ArmatureObject::UnlinkObject(SCA_IObject* clientobj)
-{
- // clientobj is being deleted, make sure we don't hold any reference to it
- bool res = false;
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- res |= (*cit)->UnlinkObject(clientobj);
- }
- return res;
-}
-
-void BL_ArmatureObject::ApplyPose()
-{
- m_armpose = m_objArma->pose;
- m_objArma->pose = m_pose;
- // in the GE, we use ctime to store the timestep
- m_pose->ctime = (float)m_timestep;
- //m_scene->r.cfra++;
- if (m_lastapplyframe != m_lastframe) {
- // update the constraint if any, first put them all off so that only the active ones will be updated
- SG_DList::iterator<BL_ArmatureConstraint> cit(m_controlledConstraints);
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->UpdateTarget();
- }
- // update ourself
- UpdateBlenderObjectMatrix(m_objArma);
- BKE_pose_where_is(m_scene, m_objArma); // XXX
- // restore ourself
- memcpy(m_objArma->obmat, m_obmat, sizeof(m_obmat));
- // restore active targets
- for (cit.begin(); !cit.end(); ++cit) {
- (*cit)->RestoreTarget();
- }
- m_lastapplyframe = m_lastframe;
- }
-}
-
-void BL_ArmatureObject::RestorePose()
-{
- m_objArma->pose = m_armpose;
- m_armpose = NULL;
-}
-
-void BL_ArmatureObject::SetPose(bPose *pose)
-{
- extract_pose_from_pose(m_pose, pose);
- m_lastapplyframe = -1.0;
-}
-
-void BL_ArmatureObject::SetPoseByAction(bAction *action, float localtime)
-{
- Object *arm = GetArmatureObject();
-
- PointerRNA ptrrna;
- RNA_id_pointer_create(&arm->id, &ptrrna);
-
- animsys_evaluate_action(&ptrrna, action, NULL, localtime);
-}
-
-void BL_ArmatureObject::BlendInPose(bPose *blend_pose, float weight, short mode)
-{
- game_blend_poses(m_pose, blend_pose, weight, mode);
-}
-
-bool BL_ArmatureObject::UpdateTimestep(double curtime)
-{
- if (curtime != m_lastframe) {
- // compute the timestep for the underlying IK algorithm
- m_timestep = curtime-m_lastframe;
- m_lastframe= curtime;
- }
-
- return false;
-}
-
-void BL_ArmatureObject::GetPose(bPose **pose)
-{
- /* If the caller supplies a null pose, create a new one. */
- /* Otherwise, copy the armature's pose channels into the caller-supplied pose */
-
- if (!*pose) {
- /* probably not to good of an idea to
- * duplicate everything, but it clears up
- * a crash and memory leakage when
- * &BL_ActionActuator::m_pose is freed
- */
- game_copy_pose(pose, m_pose, 0);
- }
- else {
- if (*pose == m_pose)
- // no need to copy if the pointers are the same
- return;
-
- extract_pose_from_pose(*pose, m_pose);
- }
-}
-
-double BL_ArmatureObject::GetLastFrame()
-{
- return m_lastframe;
-}
-
-bool BL_ArmatureObject::GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix)
-{
- bPoseChannel *pchan;
-
- ApplyPose();
- pchan = BKE_pose_channel_find_name(m_objArma->pose, bone->name);
- if (pchan)
- matrix.setValue(&pchan->pose_mat[0][0]);
- RestorePose();
-
- return (pchan != NULL);
-}
-
-float BL_ArmatureObject::GetBoneLength(Bone* bone) const
-{
- return (float)(MT_Point3(bone->head) - MT_Point3(bone->tail)).length();
-}
-
-#ifdef WITH_PYTHON
-
-// PYTHON
-
-PyTypeObject BL_ArmatureObject::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ArmatureObject",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- &KX_GameObject::Sequence,
- &KX_GameObject::Mapping,
- 0,0,0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_GameObject::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef BL_ArmatureObject::Methods[] = {
- KX_PYMETHODTABLE_NOARGS(BL_ArmatureObject, update),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ArmatureObject::Attributes[] = {
-
- KX_PYATTRIBUTE_RO_FUNCTION("constraints", BL_ArmatureObject, pyattr_get_constraints),
- KX_PYATTRIBUTE_RO_FUNCTION("channels", BL_ArmatureObject, pyattr_get_channels),
- {NULL} //Sentinel
-};
-
-static int bl_armature_object_get_constraints_size_cb(void *self_v)
-{
- return ((BL_ArmatureObject *)self_v)->GetConstraintNumber();
-}
-
-static PyObject *bl_armature_object_get_constraints_item_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetConstraint(index)->GetProxy();
-}
-
-static const char *bl_armature_object_get_constraints_item_name_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetConstraint(index)->GetName();
-}
-
-PyObject *BL_ArmatureObject::pyattr_get_constraints(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return (new CListWrapper(self_v,
- ((BL_ArmatureObject *)self_v)->GetProxy(),
- NULL,
- bl_armature_object_get_constraints_size_cb,
- bl_armature_object_get_constraints_item_cb,
- bl_armature_object_get_constraints_item_name_cb,
- NULL))->NewProxy(true);
-}
-
-static int bl_armature_object_get_channels_size_cb(void *self_v)
-{
- return ((BL_ArmatureObject *)self_v)->GetChannelNumber();
-}
-
-static PyObject *bl_armature_object_get_channels_item_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetChannel(index)->GetProxy();
-}
-
-static const char *bl_armature_object_get_channels_item_name_cb(void *self_v, int index)
-{
- return ((BL_ArmatureObject *)self_v)->GetChannel(index)->GetName();
-}
-
-PyObject *BL_ArmatureObject::pyattr_get_channels(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ArmatureObject *self = static_cast<BL_ArmatureObject *>(self_v);
- self->LoadChannels(); // make sure we have the channels
- return (new CListWrapper(self_v,
- self->GetProxy(),
- NULL,
- bl_armature_object_get_channels_size_cb,
- bl_armature_object_get_channels_item_cb,
- bl_armature_object_get_channels_item_name_cb,
- NULL))->NewProxy(true);
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(BL_ArmatureObject, update,
- "update()\n"
- "Make sure that the armature will be updated on next graphic frame.\n"
- "This is automatically done if a KX_ArmatureActuator with mode run is active\n"
- "or if an action is playing. This function is useful in other cases.\n")
-{
- UpdateTimestep(KX_GetActiveEngine()->GetFrameTime());
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ArmatureObject.h b/source/gameengine/Converter/BL_ArmatureObject.h
deleted file mode 100644
index 691e73d6bde..00000000000
--- a/source/gameengine/Converter/BL_ArmatureObject.h
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ArmatureObject.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_ARMATUREOBJECT_H__
-#define __BL_ARMATUREOBJECT_H__
-
-#include "KX_GameObject.h"
-#include "BL_ArmatureConstraint.h"
-#include "BL_ArmatureChannel.h"
-
-#include "SG_IObject.h"
-#include <vector>
-#include <algorithm>
-
-struct bArmature;
-struct Bone;
-struct bConstraint;
-class BL_ActionActuator;
-class BL_ArmatureActuator;
-class MT_Matrix4x4;
-struct Object;
-class KX_BlenderSceneConverter;
-
-class BL_ArmatureObject : public KX_GameObject
-{
- Py_Header
-public:
-
- double GetLastFrame ();
- virtual void ProcessReplica();
- virtual void ReParentLogic();
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual bool UnlinkObject(SCA_IObject* clientobj);
-
- BL_ArmatureObject(
- void* sgReplicationInfo,
- SG_Callbacks callbacks,
- Object *armature,
- Scene *scene,
- int vert_deform_type
- );
- virtual ~BL_ArmatureObject();
-
- virtual CValue* GetReplica();
- void GetPose(struct bPose **pose);
- void SetPose (struct bPose *pose);
- struct bPose *GetOrigPose() {return m_pose;} // never edit this, only for accessing names
-
- void ApplyPose();
- void SetPoseByAction(struct bAction* action, float localtime);
- void BlendInPose(struct bPose *blend_pose, float weight, short mode);
- void RestorePose();
-
- bool UpdateTimestep(double curtime);
-
- struct bArmature *GetArmature() { return (bArmature*)m_objArma->data; }
- const struct bArmature * GetArmature() const { return (bArmature*)m_objArma->data; }
- const struct Scene * GetScene() const { return m_scene; }
-
- Object* GetArmatureObject() {return m_objArma;}
- Object* GetOrigArmatureObject() {return m_origObjArma;}
-
- int GetVertDeformType() {return m_vert_deform_type;}
-
- // for constraint python API
- void LoadConstraints(KX_BlenderSceneConverter* converter);
- size_t GetConstraintNumber() const { return m_constraintNumber; }
- BL_ArmatureConstraint* GetConstraint(const char* posechannel, const char* constraint);
- BL_ArmatureConstraint* GetConstraint(const char* posechannelconstraint);
- BL_ArmatureConstraint* GetConstraint(int index);
- // for pose channel python API
- void LoadChannels();
- size_t GetChannelNumber() const { return m_channelNumber; }
- BL_ArmatureChannel* GetChannel(bPoseChannel* channel);
- BL_ArmatureChannel* GetChannel(const char* channel);
- BL_ArmatureChannel* GetChannel(int index);
-
- /// Retrieve the pose matrix for the specified bone.
- /// Returns true on success.
- bool GetBoneMatrix(Bone* bone, MT_Matrix4x4& matrix);
-
- /// Returns the bone length. The end of the bone is in the local y direction.
- float GetBoneLength(Bone* bone) const;
-
- virtual int GetGameObjectType() { return OBJ_ARMATURE; }
-
-#ifdef WITH_PYTHON
-
- // PYTHON
- static PyObject *pyattr_get_constraints(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_channels(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- KX_PYMETHOD_DOC_NOARGS(BL_ArmatureObject, update);
-
-#endif /* WITH_PYTHON */
-
-protected:
- /* list element: BL_ArmatureConstraint. Use SG_DListHead to have automatic list replication */
- SG_DListHead<BL_ArmatureConstraint> m_controlledConstraints;
- /* list element: BL_ArmatureChannel. Use SG_DList to avoid list replication */
- SG_DList m_poseChannels;
- Object *m_objArma;
- Object *m_origObjArma;
- struct bPose *m_pose;
- struct bPose *m_armpose;
- struct Scene *m_scene; // need for BKE_pose_where_is
- double m_lastframe;
- double m_timestep; // delta since last pose evaluation.
- int m_vert_deform_type;
- size_t m_constraintNumber;
- size_t m_channelNumber;
- // store the original armature object matrix
- float m_obmat[4][4];
-
- double m_lastapplyframe;
-};
-
-#endif /* __BL_ARMATUREOBJECT_H__ */
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.cpp b/source/gameengine/Converter/BL_BlenderDataConversion.cpp
deleted file mode 100644
index a12437befaa..00000000000
--- a/source/gameengine/Converter/BL_BlenderDataConversion.cpp
+++ /dev/null
@@ -1,2467 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Convert blender data to ketsji
- */
-
-/** \file gameengine/Converter/BL_BlenderDataConversion.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-/* Since threaded object update we've disabled in-place
- * curve evaluation (in cases when applying curve modifier
- * with target curve non-evaluated yet).
- *
- * This requires game engine to take care of DAG and object
- * evaluation (currently it's designed to export only objects
- * it able to render).
- *
- * This workaround will make sure that curve_cache for curves
- * is up-to-date.
- */
-#define THREADED_DAG_WORKAROUND
-
-#include <math.h>
-#include <vector>
-#include <algorithm>
-
-#include "BL_BlenderDataConversion.h"
-
-#include "MT_Transform.h"
-#include "MT_MinMax.h"
-
-#include "PHY_Pro.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-#include "RAS_MeshObject.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_ILightObject.h"
-
-#include "KX_ConvertActuators.h"
-#include "KX_ConvertControllers.h"
-#include "KX_ConvertSensors.h"
-#include "SCA_LogicManager.h"
-#include "SCA_TimeEventManager.h"
-
-#include "KX_ClientObjectInfo.h"
-#include "KX_Scene.h"
-#include "KX_GameObject.h"
-#include "KX_Light.h"
-#include "KX_Camera.h"
-#include "KX_EmptyObject.h"
-#include "KX_FontObject.h"
-
-#include "RAS_TexMatrix.h"
-#include "RAS_ICanvas.h"
-#include "RAS_Polygon.h"
-#include "RAS_TexVert.h"
-#include "RAS_BucketManager.h"
-#include "RAS_IPolygonMaterial.h"
-#include "BL_Material.h"
-#include "KX_BlenderMaterial.h"
-#include "BL_Texture.h"
-
-#include "BKE_main.h"
-#include "BKE_global.h"
-#include "BKE_object.h"
-#include "BL_ModifierDeformer.h"
-#include "BL_ShapeDeformer.h"
-#include "BL_SkinDeformer.h"
-#include "BL_MeshDeformer.h"
-#include "KX_SoftBodyDeformer.h"
-#include "BLI_utildefines.h"
-#include "BLI_listbase.h"
-
-#include "KX_WorldInfo.h"
-
-#include "KX_KetsjiEngine.h"
-#include "KX_BlenderSceneConverter.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-/* This list includes only data type definitions */
-#include "DNA_object_types.h"
-#include "DNA_material_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_image_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_group_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_property_types.h"
-#include "DNA_text_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_view3d_types.h"
-#include "DNA_world_types.h"
-#include "DNA_sound_types.h"
-#include "DNA_key_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_object_force_types.h"
-#include "DNA_constraint_types.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "BKE_key.h"
-#include "BKE_mesh.h"
-
-#include "BLI_math.h"
-
-extern "C" {
-#include "BKE_scene.h"
-#include "BKE_customdata.h"
-#include "BKE_cdderivedmesh.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_material.h" /* give_current_material */
-#include "BKE_image.h"
-#include "IMB_imbuf_types.h"
-#include "BKE_displist.h"
-
-extern Material defmaterial; /* material.c */
-}
-
-/* end of blender include block */
-
-#include "KX_BlenderInputDevice.h"
-#include "KX_ConvertProperties.h"
-
-#include "SG_Node.h"
-#include "SG_BBox.h"
-#include "SG_Tree.h"
-#include "KX_SG_NodeRelationships.h"
-#include "KX_SG_BoneParentNodeRelationship.h"
-
-#ifdef WITH_BULLET
-#include "CcdPhysicsEnvironment.h"
-#include "CcdGraphicController.h"
-#endif
-
-#include "KX_MotionState.h"
-
-#include "BL_ArmatureObject.h"
-#include "BL_DeformableGameObject.h"
-
-#include "KX_NavMeshObject.h"
-#include "KX_ObstacleSimulation.h"
-
-#include "BLI_threads.h"
-
-
-static bool default_light_mode = 0;
-
-static std::map<int, SCA_IInputDevice::KX_EnumInputs> create_translate_table()
-{
- std::map<int, SCA_IInputDevice::KX_EnumInputs> m;
-
- /* The reverse table. In order to not confuse ourselves, we */
- /* immediately convert all events that come in to KX codes. */
- m[LEFTMOUSE ] = SCA_IInputDevice::KX_LEFTMOUSE;
- m[MIDDLEMOUSE ] = SCA_IInputDevice::KX_MIDDLEMOUSE;
- m[RIGHTMOUSE ] = SCA_IInputDevice::KX_RIGHTMOUSE;
- m[WHEELUPMOUSE ] = SCA_IInputDevice::KX_WHEELUPMOUSE;
- m[WHEELDOWNMOUSE ] = SCA_IInputDevice::KX_WHEELDOWNMOUSE;
- m[MOUSEX ] = SCA_IInputDevice::KX_MOUSEX;
- m[MOUSEY ] = SCA_IInputDevice::KX_MOUSEY;
-
- // TIMERS
-
- m[TIMER0 ] = SCA_IInputDevice::KX_TIMER0;
- m[TIMER1 ] = SCA_IInputDevice::KX_TIMER1;
- m[TIMER2 ] = SCA_IInputDevice::KX_TIMER2;
-
- // SYSTEM
-
-#if 0
- /* **** XXX **** */
- m[KEYBD ] = SCA_IInputDevice::KX_KEYBD;
- m[RAWKEYBD ] = SCA_IInputDevice::KX_RAWKEYBD;
- m[REDRAW ] = SCA_IInputDevice::KX_REDRAW;
- m[INPUTCHANGE ] = SCA_IInputDevice::KX_INPUTCHANGE;
- m[QFULL ] = SCA_IInputDevice::KX_QFULL;
- m[WINFREEZE ] = SCA_IInputDevice::KX_WINFREEZE;
- m[WINTHAW ] = SCA_IInputDevice::KX_WINTHAW;
- m[WINCLOSE ] = SCA_IInputDevice::KX_WINCLOSE;
- m[WINQUIT ] = SCA_IInputDevice::KX_WINQUIT;
- m[Q_FIRSTTIME ] = SCA_IInputDevice::KX_Q_FIRSTTIME;
- /* **** XXX **** */
-#endif
-
- // standard keyboard
-
- m[AKEY ] = SCA_IInputDevice::KX_AKEY;
- m[BKEY ] = SCA_IInputDevice::KX_BKEY;
- m[CKEY ] = SCA_IInputDevice::KX_CKEY;
- m[DKEY ] = SCA_IInputDevice::KX_DKEY;
- m[EKEY ] = SCA_IInputDevice::KX_EKEY;
- m[FKEY ] = SCA_IInputDevice::KX_FKEY;
- m[GKEY ] = SCA_IInputDevice::KX_GKEY;
- m[HKEY ] = SCA_IInputDevice::KX_HKEY;
- m[IKEY ] = SCA_IInputDevice::KX_IKEY;
- m[JKEY ] = SCA_IInputDevice::KX_JKEY;
- m[KKEY ] = SCA_IInputDevice::KX_KKEY;
- m[LKEY ] = SCA_IInputDevice::KX_LKEY;
- m[MKEY ] = SCA_IInputDevice::KX_MKEY;
- m[NKEY ] = SCA_IInputDevice::KX_NKEY;
- m[OKEY ] = SCA_IInputDevice::KX_OKEY;
- m[PKEY ] = SCA_IInputDevice::KX_PKEY;
- m[QKEY ] = SCA_IInputDevice::KX_QKEY;
- m[RKEY ] = SCA_IInputDevice::KX_RKEY;
- m[SKEY ] = SCA_IInputDevice::KX_SKEY;
- m[TKEY ] = SCA_IInputDevice::KX_TKEY;
- m[UKEY ] = SCA_IInputDevice::KX_UKEY;
- m[VKEY ] = SCA_IInputDevice::KX_VKEY;
- m[WKEY ] = SCA_IInputDevice::KX_WKEY;
- m[XKEY ] = SCA_IInputDevice::KX_XKEY;
- m[YKEY ] = SCA_IInputDevice::KX_YKEY;
- m[ZKEY ] = SCA_IInputDevice::KX_ZKEY;
-
- m[ZEROKEY ] = SCA_IInputDevice::KX_ZEROKEY;
- m[ONEKEY ] = SCA_IInputDevice::KX_ONEKEY;
- m[TWOKEY ] = SCA_IInputDevice::KX_TWOKEY;
- m[THREEKEY ] = SCA_IInputDevice::KX_THREEKEY;
- m[FOURKEY ] = SCA_IInputDevice::KX_FOURKEY;
- m[FIVEKEY ] = SCA_IInputDevice::KX_FIVEKEY;
- m[SIXKEY ] = SCA_IInputDevice::KX_SIXKEY;
- m[SEVENKEY ] = SCA_IInputDevice::KX_SEVENKEY;
- m[EIGHTKEY ] = SCA_IInputDevice::KX_EIGHTKEY;
- m[NINEKEY ] = SCA_IInputDevice::KX_NINEKEY;
-
- m[CAPSLOCKKEY ] = SCA_IInputDevice::KX_CAPSLOCKKEY;
-
- m[LEFTCTRLKEY ] = SCA_IInputDevice::KX_LEFTCTRLKEY;
- m[LEFTALTKEY ] = SCA_IInputDevice::KX_LEFTALTKEY;
- m[RIGHTALTKEY ] = SCA_IInputDevice::KX_RIGHTALTKEY;
- m[RIGHTCTRLKEY ] = SCA_IInputDevice::KX_RIGHTCTRLKEY;
- m[RIGHTSHIFTKEY ] = SCA_IInputDevice::KX_RIGHTSHIFTKEY;
- m[LEFTSHIFTKEY ] = SCA_IInputDevice::KX_LEFTSHIFTKEY;
-
- m[ESCKEY ] = SCA_IInputDevice::KX_ESCKEY;
- m[TABKEY ] = SCA_IInputDevice::KX_TABKEY;
- m[RETKEY ] = SCA_IInputDevice::KX_RETKEY;
- m[SPACEKEY ] = SCA_IInputDevice::KX_SPACEKEY;
- m[LINEFEEDKEY ] = SCA_IInputDevice::KX_LINEFEEDKEY;
- m[BACKSPACEKEY ] = SCA_IInputDevice::KX_BACKSPACEKEY;
- m[DELKEY ] = SCA_IInputDevice::KX_DELKEY;
- m[SEMICOLONKEY ] = SCA_IInputDevice::KX_SEMICOLONKEY;
- m[PERIODKEY ] = SCA_IInputDevice::KX_PERIODKEY;
- m[COMMAKEY ] = SCA_IInputDevice::KX_COMMAKEY;
- m[QUOTEKEY ] = SCA_IInputDevice::KX_QUOTEKEY;
- m[ACCENTGRAVEKEY ] = SCA_IInputDevice::KX_ACCENTGRAVEKEY;
- m[MINUSKEY ] = SCA_IInputDevice::KX_MINUSKEY;
- m[PLUSKEY ] = SCA_IInputDevice::KX_PLUSKEY;
- m[SLASHKEY ] = SCA_IInputDevice::KX_SLASHKEY;
- m[BACKSLASHKEY ] = SCA_IInputDevice::KX_BACKSLASHKEY;
- m[EQUALKEY ] = SCA_IInputDevice::KX_EQUALKEY;
- m[LEFTBRACKETKEY ] = SCA_IInputDevice::KX_LEFTBRACKETKEY;
- m[RIGHTBRACKETKEY ] = SCA_IInputDevice::KX_RIGHTBRACKETKEY;
-
- m[LEFTARROWKEY ] = SCA_IInputDevice::KX_LEFTARROWKEY;
- m[DOWNARROWKEY ] = SCA_IInputDevice::KX_DOWNARROWKEY;
- m[RIGHTARROWKEY ] = SCA_IInputDevice::KX_RIGHTARROWKEY;
- m[UPARROWKEY ] = SCA_IInputDevice::KX_UPARROWKEY;
-
- m[PAD2 ] = SCA_IInputDevice::KX_PAD2;
- m[PAD4 ] = SCA_IInputDevice::KX_PAD4;
- m[PAD6 ] = SCA_IInputDevice::KX_PAD6;
- m[PAD8 ] = SCA_IInputDevice::KX_PAD8;
-
- m[PAD1 ] = SCA_IInputDevice::KX_PAD1;
- m[PAD3 ] = SCA_IInputDevice::KX_PAD3;
- m[PAD5 ] = SCA_IInputDevice::KX_PAD5;
- m[PAD7 ] = SCA_IInputDevice::KX_PAD7;
- m[PAD9 ] = SCA_IInputDevice::KX_PAD9;
-
- m[PADPERIOD ] = SCA_IInputDevice::KX_PADPERIOD;
- m[PADSLASHKEY ] = SCA_IInputDevice::KX_PADSLASHKEY;
- m[PADASTERKEY ] = SCA_IInputDevice::KX_PADASTERKEY;
-
- m[PAD0 ] = SCA_IInputDevice::KX_PAD0;
- m[PADMINUS ] = SCA_IInputDevice::KX_PADMINUS;
- m[PADENTER ] = SCA_IInputDevice::KX_PADENTER;
- m[PADPLUSKEY ] = SCA_IInputDevice::KX_PADPLUSKEY;
-
-
- m[F1KEY ] = SCA_IInputDevice::KX_F1KEY;
- m[F2KEY ] = SCA_IInputDevice::KX_F2KEY;
- m[F3KEY ] = SCA_IInputDevice::KX_F3KEY;
- m[F4KEY ] = SCA_IInputDevice::KX_F4KEY;
- m[F5KEY ] = SCA_IInputDevice::KX_F5KEY;
- m[F6KEY ] = SCA_IInputDevice::KX_F6KEY;
- m[F7KEY ] = SCA_IInputDevice::KX_F7KEY;
- m[F8KEY ] = SCA_IInputDevice::KX_F8KEY;
- m[F9KEY ] = SCA_IInputDevice::KX_F9KEY;
- m[F10KEY ] = SCA_IInputDevice::KX_F10KEY;
- m[F11KEY ] = SCA_IInputDevice::KX_F11KEY;
- m[F12KEY ] = SCA_IInputDevice::KX_F12KEY;
- m[F13KEY ] = SCA_IInputDevice::KX_F13KEY;
- m[F14KEY ] = SCA_IInputDevice::KX_F14KEY;
- m[F15KEY ] = SCA_IInputDevice::KX_F15KEY;
- m[F16KEY ] = SCA_IInputDevice::KX_F16KEY;
- m[F17KEY ] = SCA_IInputDevice::KX_F17KEY;
- m[F18KEY ] = SCA_IInputDevice::KX_F18KEY;
- m[F19KEY ] = SCA_IInputDevice::KX_F19KEY;
-
- m[OSKEY ] = SCA_IInputDevice::KX_OSKEY;
-
- m[PAUSEKEY ] = SCA_IInputDevice::KX_PAUSEKEY;
- m[INSERTKEY ] = SCA_IInputDevice::KX_INSERTKEY;
- m[HOMEKEY ] = SCA_IInputDevice::KX_HOMEKEY;
- m[PAGEUPKEY ] = SCA_IInputDevice::KX_PAGEUPKEY;
- m[PAGEDOWNKEY ] = SCA_IInputDevice::KX_PAGEDOWNKEY;
- m[ENDKEY ] = SCA_IInputDevice::KX_ENDKEY;
-
- return m;
-}
-
-static std::map<int, SCA_IInputDevice::KX_EnumInputs> gReverseKeyTranslateTable = create_translate_table();
-
-SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code)
-{
- return gReverseKeyTranslateTable[key_code];
-}
-
-static unsigned int KX_rgbaint2uint_new(unsigned int icol)
-{
- union
- {
- unsigned int integer;
- unsigned char cp[4];
- } out_color, in_color;
-
- in_color.integer = icol;
- out_color.cp[0] = in_color.cp[3]; // red
- out_color.cp[1] = in_color.cp[2]; // green
- out_color.cp[2] = in_color.cp[1]; // blue
- out_color.cp[3] = in_color.cp[0]; // alpha
-
- return out_color.integer;
-}
-
-/* Now the real converting starts... */
-static unsigned int KX_Mcol2uint_new(MCol col)
-{
- /* color has to be converted without endian sensitivity. So no shifting! */
- union
- {
- MCol col;
- unsigned int integer;
- unsigned char cp[4];
- } out_color, in_color;
-
- in_color.col = col;
- out_color.cp[0] = in_color.cp[3]; // red
- out_color.cp[1] = in_color.cp[2]; // green
- out_color.cp[2] = in_color.cp[1]; // blue
- out_color.cp[3] = in_color.cp[0]; // alpha
-
- return out_color.integer;
-}
-
-static void SetDefaultLightMode(Scene* scene)
-{
- default_light_mode = false;
- Scene *sce_iter;
- Base *base;
-
- for (SETLOOPER(scene, sce_iter, base))
- {
- if (base->object->type == OB_LAMP)
- {
- default_light_mode = true;
- return;
- }
- }
-}
-
-
-static bool GetMaterialUseVColor(Material *ma, const bool glslmat)
-{
- if (ma) {
- /* glsl uses vertex colors, otherwise use material setting
- * defmaterial doesn't have VERTEXCOLP as default [#34505] */
- return (glslmat || ma == &defmaterial || (ma->mode & MA_VERTEXCOLP) != 0);
- }
- else {
- /* no material, use vertex colors */
- return true;
- }
-}
-
-// --
-static void GetRGB(
- const bool use_vcol,
- MFace* mface,
- MCol* mmcol,
- Material *mat,
- unsigned int c[4])
-{
- unsigned int color = 0xFFFFFFFFL;
- if (use_vcol == true) {
- if (mmcol) {
- c[0] = KX_Mcol2uint_new(mmcol[0]);
- c[1] = KX_Mcol2uint_new(mmcol[1]);
- c[2] = KX_Mcol2uint_new(mmcol[2]);
- if (mface->v4)
- c[3] = KX_Mcol2uint_new(mmcol[3]);
- }
- else { // backup white
- c[0] = KX_rgbaint2uint_new(color);
- c[1] = KX_rgbaint2uint_new(color);
- c[2] = KX_rgbaint2uint_new(color);
- if (mface->v4)
- c[3] = KX_rgbaint2uint_new( color );
- }
- }
- else {
- /* material rgba */
- if (mat) {
- union {
- unsigned char cp[4];
- unsigned int integer;
- } col_converter;
- col_converter.cp[3] = (unsigned char) (mat->r * 255.0f);
- col_converter.cp[2] = (unsigned char) (mat->g * 255.0f);
- col_converter.cp[1] = (unsigned char) (mat->b * 255.0f);
- col_converter.cp[0] = (unsigned char) (mat->alpha * 255.0f);
- color = col_converter.integer;
- }
- c[0] = KX_rgbaint2uint_new(color);
- c[1] = KX_rgbaint2uint_new(color);
- c[2] = KX_rgbaint2uint_new(color);
- if (mface->v4) {
- c[3] = KX_rgbaint2uint_new(color);
- }
- }
-
-#if 0 /* white, unused */
- {
- c[0] = KX_rgbaint2uint_new(color);
- c[1] = KX_rgbaint2uint_new(color);
- c[2] = KX_rgbaint2uint_new(color);
- if (mface->v4)
- c[3] = KX_rgbaint2uint_new(color);
- }
-#endif
-}
-
-typedef struct MTF_localLayer {
- MTFace *face;
- const char *name;
-} MTF_localLayer;
-
-static void GetUVs(BL_Material *material, MTF_localLayer *layers, MFace *mface, MTFace *tface, MT_Point2 uvs[4][MAXTEX])
-{
- int unit = 0;
- if (tface)
- {
-
- uvs[0][0].setValue(tface->uv[0]);
- uvs[1][0].setValue(tface->uv[1]);
- uvs[2][0].setValue(tface->uv[2]);
-
- if (mface->v4)
- uvs[3][0].setValue(tface->uv[3]);
- }
- else
- {
- uvs[0][0] = uvs[1][0] = uvs[2][0] = uvs[3][0] = MT_Point2(0.f, 0.f);
- }
-
- vector<STR_String> found_layers;
-
- for (int vind = 0; vind<MAXTEX; vind++)
- {
- BL_Mapping &map = material->mapping[vind];
-
- if (!(map.mapping & USEUV)) continue;
-
- if (std::find(found_layers.begin(), found_layers.end(), map.uvCoName) != found_layers.end())
- continue;
-
- //If no UVSet is specified, try grabbing one from the UV/Image editor
- if (map.uvCoName.IsEmpty() && tface)
- {
- uvs[0][unit].setValue(tface->uv[0]);
- uvs[1][unit].setValue(tface->uv[1]);
- uvs[2][unit].setValue(tface->uv[2]);
-
- if (mface->v4)
- uvs[3][unit].setValue(tface->uv[3]);
-
- ++unit;
- continue;
- }
-
-
- for (int lay=0; lay<MAX_MTFACE; lay++)
- {
- MTF_localLayer& layer = layers[lay];
- if (layer.face == 0) break;
-
- if (map.uvCoName.IsEmpty() || strcmp(map.uvCoName.ReadPtr(), layer.name)==0)
- {
- uvs[0][unit].setValue(layer.face->uv[0]);
- uvs[1][unit].setValue(layer.face->uv[1]);
- uvs[2][unit].setValue(layer.face->uv[2]);
-
- if (mface->v4)
- uvs[3][unit].setValue(layer.face->uv[3]);
- else
- uvs[3][unit].setValue(0.0f, 0.0f);
-
- ++unit;
- found_layers.push_back(map.uvCoName);
- break;
- }
- }
- }
-}
-
-// ------------------------------------
-static bool ConvertMaterial(
- BL_Material *material,
- Material *mat,
- MTFace *tface,
- const char *tfaceName,
- MFace *mface,
- MCol *mmcol,
- bool glslmat)
-{
- material->Initialize();
- int texalpha = 0;
- const bool validmat = (mat != NULL);
- const bool validface = (tface != NULL);
- const bool use_vcol = GetMaterialUseVColor(mat, glslmat);
-
- material->IdMode = DEFAULT_BLENDER;
- material->glslmat = (validmat) ? glslmat: false;
- material->materialindex = mface->mat_nr;
-
- // --------------------------------
- if (validmat) {
-
- // use lighting?
- material->ras_mode |= (mat->mode & MA_SHLESS) ? 0 : USE_LIGHT;
- material->ras_mode |= (mat->game.flag & GEMAT_BACKCULL) ? 0 : TWOSIDED;
-
- // cast shadows?
- material->ras_mode |= ((mat->mode2 & MA_CASTSHADOW) && (mat->mode & MA_SHADBUF)) ? CAST_SHADOW : 0;
-
- // only shadows?
- material->ras_mode |= (mat->mode & MA_ONLYCAST) ? ONLY_SHADOW : 0;
-
- MTex *mttmp = NULL;
- int valid_index = 0;
-
- /* In Multitexture use the face texture if and only if
- * it is set in the buttons
- * In GLSL is not working yet :/ 3.2011 */
- bool facetex = false;
- if (validface && mat->mode & MA_FACETEXTURE) {
- facetex = true;
- }
-
- // foreach MTex
- for (int i = 0; i < MAXTEX; i++) {
- // use face tex
- if (i == 0 && facetex ) {
- facetex = false;
- Image *tmp = (Image *)(tface->tpage);
-
- if (tmp) {
- material->img[i] = tmp;
- material->texname[i] = material->img[i]->id.name;
- material->flag[i] |= MIPMAP;
-
- material->flag[i] |= (mat->game.alpha_blend & GEMAT_ALPHA_SORT) ? USEALPHA : 0;
- material->flag[i] |= (mat->game.alpha_blend & GEMAT_ALPHA) ? USEALPHA : 0;
- material->flag[i] |= (mat->game.alpha_blend & GEMAT_ADD) ? CALCALPHA : 0;
-
- if (material->img[i]->flag & IMA_REFLECT) {
- material->mapping[i].mapping |= USEREFL;
- }
- else {
- mttmp = getMTexFromMaterial(mat, i);
- if (mttmp && (mttmp->texco & TEXCO_UV)) {
- /* string may be "" but thats detected as empty after */
- material->mapping[i].uvCoName = mttmp->uvname;
- }
- material->mapping[i].mapping |= USEUV;
- }
-
- valid_index++;
- }
- else {
- material->img[i] = 0;
- material->texname[i] = "";
- }
- continue;
- }
-
- mttmp = getMTexFromMaterial(mat, i);
- if (mttmp) {
- if (mttmp->tex) {
- if (mttmp->tex->type == TEX_IMAGE) {
- material->mtexname[i] = mttmp->tex->id.name;
- material->img[i] = mttmp->tex->ima;
- if (material->img[i]) {
-
- material->texname[i] = material->img[i]->id.name;
- material->flag[i] |= (mttmp->tex->imaflag &TEX_MIPMAP) ? MIPMAP : 0;
- if (material->img[i] && (material->img[i]->flag & IMA_IGNORE_ALPHA) == 0) {
- material->flag[i] |= USEALPHA;
- }
- if (mttmp->tex->imaflag & TEX_CALCALPHA) {
- material->flag[i] |= CALCALPHA;
- }
- else if (mttmp->tex->flag & TEX_NEGALPHA) {
- material->flag[i] |= USENEGALPHA;
- }
-
- material->color_blend[i] = mttmp->colfac;
- material->flag[i] |= (mttmp->mapto & MAP_ALPHA) ? TEXALPHA : 0;
- material->flag[i] |= (mttmp->texflag & MTEX_NEGATIVE) ? TEXNEG : 0;
-
- if (!glslmat && (material->flag[i] & TEXALPHA)) {
- texalpha = 1;
- }
- }
- }
- else if (mttmp->tex->type == TEX_ENVMAP) {
- if (mttmp->tex->env->stype == ENV_LOAD) {
- material->mtexname[i] = mttmp->tex->id.name;
- EnvMap *env = mttmp->tex->env;
- env->ima = mttmp->tex->ima;
- material->cubemap[i] = env;
-
- if (material->cubemap[i]) {
- if (!material->cubemap[i]->cube[0]) {
- BL_Texture::SplitEnvMap(material->cubemap[i]);
- }
-
- material->texname[i] = material->cubemap[i]->ima->id.name;
- material->mapping[i].mapping |= USEENV;
- }
- }
- }
-#if 0 /* this flag isn't used anymore */
- material->flag[i] |= (BKE_animdata_from_id(mat->id) != NULL) ? HASIPO : 0;
-#endif
- /// --------------------------------
- // mapping methods
- if (mat->septex & (1 << i)) {
- // If this texture slot isn't in use, set it to disabled to prevent multi-uv problems
- material->mapping[i].mapping = DISABLE;
- }
- else {
- material->mapping[i].mapping |= (mttmp->texco & TEXCO_REFL) ? USEREFL : 0;
-
- if (mttmp->texco & TEXCO_OBJECT) {
- material->mapping[i].mapping |= USEOBJ;
- if (mttmp->object) {
- material->mapping[i].objconame = mttmp->object->id.name;
- }
- }
- else if (mttmp->texco & TEXCO_REFL) {
- material->mapping[i].mapping |= USEREFL;
- }
- else if (mttmp->texco & (TEXCO_ORCO | TEXCO_GLOB)) {
- material->mapping[i].mapping |= USEORCO;
- }
- else if (mttmp->texco & TEXCO_UV) {
- /* string may be "" but thats detected as empty after */
- material->mapping[i].uvCoName = mttmp->uvname;
- material->mapping[i].mapping |= USEUV;
- }
- else if (mttmp->texco & TEXCO_NORM) {
- material->mapping[i].mapping |= USENORM;
- }
- else if (mttmp->texco & TEXCO_TANGENT) {
- material->mapping[i].mapping |= USETANG;
- }
- else {
- material->mapping[i].mapping |= DISABLE;
- }
-
- material->mapping[i].scale[0] = mttmp->size[0];
- material->mapping[i].scale[1] = mttmp->size[1];
- material->mapping[i].scale[2] = mttmp->size[2];
- material->mapping[i].offsets[0] = mttmp->ofs[0];
- material->mapping[i].offsets[1] = mttmp->ofs[1];
- material->mapping[i].offsets[2] = mttmp->ofs[2];
-
- material->mapping[i].projplane[0] = mttmp->projx;
- material->mapping[i].projplane[1] = mttmp->projy;
- material->mapping[i].projplane[2] = mttmp->projz;
- }
- /// --------------------------------
-
- switch (mttmp->blendtype) {
- case MTEX_BLEND:
- material->blend_mode[i] = BLEND_MIX;
- break;
- case MTEX_MUL:
- material->blend_mode[i] = BLEND_MUL;
- break;
- case MTEX_ADD:
- material->blend_mode[i] = BLEND_ADD;
- break;
- case MTEX_SUB:
- material->blend_mode[i] = BLEND_SUB;
- break;
- case MTEX_SCREEN:
- material->blend_mode[i] = BLEND_SCR;
- break;
- }
- valid_index++;
- }
- }
- }
-
- // above one tex the switches here
- // are not used
- switch (valid_index) {
- case 0:
- material->IdMode = DEFAULT_BLENDER;
- break;
- case 1:
- material->IdMode = ONETEX;
- break;
- default:
- material->IdMode = GREATERTHAN2;
- break;
- }
- material->SetUsers(mat->id.us);
-
- material->num_enabled = valid_index;
-
- material->speccolor[0] = mat->specr;
- material->speccolor[1] = mat->specg;
- material->speccolor[2] = mat->specb;
- material->hard = (float)mat->har / 4.0f;
- material->matcolor[0] = mat->r;
- material->matcolor[1] = mat->g;
- material->matcolor[2] = mat->b;
- material->matcolor[3] = mat->alpha;
- material->alpha = mat->alpha;
- material->emit = mat->emit;
- material->spec_f = mat->spec;
- material->ref = mat->ref;
- material->amb = mat->amb;
-
- material->ras_mode |= (mat->material_type == MA_TYPE_WIRE) ? WIRE : 0;
- }
- else { // No Material
- int valid = 0;
-
- // check for tface tex to fallback on
- if (validface) {
- material->img[0] = (Image *)(tface->tpage);
- // ------------------------
- if (material->img[0]) {
- material->texname[0] = material->img[0]->id.name;
- material->mapping[0].mapping |= ((material->img[0]->flag & IMA_REFLECT) != 0) ? USEREFL : 0;
-
- /* see if depth of the image is 32bits */
- if (BKE_image_has_alpha(material->img[0])) {
- material->flag[0] |= USEALPHA;
- material->alphablend = GEMAT_ALPHA;
- }
- else {
- material->alphablend = GEMAT_SOLID;
- }
- valid++;
- }
- }
- else {
- material->alphablend = GEMAT_SOLID;
- }
-
- material->SetUsers(-1);
- material->num_enabled = valid;
- material->IdMode = TEXFACE;
- material->speccolor[0] = 1.0f;
- material->speccolor[1] = 1.0f;
- material->speccolor[2] = 1.0f;
- material->hard = 35.0f;
- material->matcolor[0] = 0.5f;
- material->matcolor[1] = 0.5f;
- material->matcolor[2] = 0.5f;
- material->spec_f = 0.5f;
- material->ref = 0.8f;
-
- // No material - old default TexFace properties
- material->ras_mode |= USE_LIGHT;
- }
-
- /* No material, what to do? let's see what is in the UV and set the material accordingly
- * light and visible is always on */
- if (validface) {
- material->tile = tface->tile;
- }
- else {
- // nothing at all
- material->alphablend = GEMAT_SOLID;
- material->tile = 0;
- }
-
- if (validmat && validface) {
- material->alphablend = mat->game.alpha_blend;
- }
-
- // with ztransp enabled, enforce alpha blending mode
- if (validmat && (mat->mode & MA_TRANSP) && (mat->mode & MA_ZTRANSP) && (material->alphablend == GEMAT_SOLID)) {
- material->alphablend = GEMAT_ALPHA;
- }
-
- // always zsort alpha + add
- if ((ELEM(material->alphablend, GEMAT_ALPHA, GEMAT_ALPHA_SORT, GEMAT_ADD) || texalpha) && (material->alphablend != GEMAT_CLIP)) {
- material->ras_mode |= ALPHA;
- material->ras_mode |= (mat && (mat->game.alpha_blend & GEMAT_ALPHA_SORT)) ? ZSORT : 0;
- }
-
- // XXX The RGB values here were meant to be temporary storage for the conversion process,
- // but fonts now make use of them too, so we leave them in for now.
- unsigned int rgb[4];
- GetRGB(use_vcol, mface, mmcol, mat, rgb);
-
- // swap the material color, so MCol on bitmap font works
- if (validmat && (use_vcol == false) && (mat->game.flag & GEMAT_TEXT)) {
- material->rgb[0] = KX_rgbaint2uint_new(rgb[0]);
- material->rgb[1] = KX_rgbaint2uint_new(rgb[1]);
- material->rgb[2] = KX_rgbaint2uint_new(rgb[2]);
- material->rgb[3] = KX_rgbaint2uint_new(rgb[3]);
- }
-
- if (validmat) {
- material->matname =(mat->id.name);
- }
-
- if (tface) {
- ME_MTEXFACE_CPY(&material->mtexpoly, tface);
- }
- else {
- memset(&material->mtexpoly, 0, sizeof(material->mtexpoly));
- }
- material->material = mat;
- return true;
-}
-
-static RAS_MaterialBucket *material_from_mesh(Material *ma, MFace *mface, MTFace *tface, MCol *mcol, MTF_localLayer *layers, int lightlayer, unsigned int *rgb, MT_Point2 uvs[4][RAS_TexVert::MAX_UNIT], const char *tfaceName, KX_Scene* scene, KX_BlenderSceneConverter *converter)
-{
- RAS_IPolyMaterial* polymat = converter->FindCachedPolyMaterial(scene, ma);
- BL_Material* bl_mat = converter->FindCachedBlenderMaterial(scene, ma);
- KX_BlenderMaterial* kx_blmat = NULL;
-
- /* first is the BL_Material */
- if (!bl_mat)
- {
- bl_mat = new BL_Material();
-
- ConvertMaterial(bl_mat, ma, tface, tfaceName, mface, mcol,
- converter->GetGLSLMaterials());
-
- if (ma && (ma->mode & MA_FACETEXTURE) == 0)
- converter->CacheBlenderMaterial(scene, ma, bl_mat);
- }
-
- const bool use_vcol = GetMaterialUseVColor(ma, bl_mat->glslmat);
- GetRGB(use_vcol, mface, mcol, ma, rgb);
-
- GetUVs(bl_mat, layers, mface, tface, uvs);
-
- /* then the KX_BlenderMaterial */
- if (polymat == NULL)
- {
- kx_blmat = new KX_BlenderMaterial();
-
- kx_blmat->Initialize(scene, bl_mat, (ma?&ma->game:NULL), lightlayer);
- polymat = static_cast<RAS_IPolyMaterial*>(kx_blmat);
- if (ma && (ma->mode & MA_FACETEXTURE) == 0)
- converter->CachePolyMaterial(scene, ma, polymat);
- }
-
- // see if a bucket was reused or a new one was created
- // this way only one KX_BlenderMaterial object has to exist per bucket
- bool bucketCreated;
- RAS_MaterialBucket* bucket = scene->FindBucket(polymat, bucketCreated);
-
- // this is needed to free up memory afterwards.
- // the converter will also prevent duplicates from being registered,
- // so just register everything.
- converter->RegisterPolyMaterial(polymat);
- converter->RegisterBlenderMaterial(bl_mat);
-
- return bucket;
-}
-
-/* blenderobj can be NULL, make sure its checked for */
-RAS_MeshObject* BL_ConvertMesh(Mesh* mesh, Object* blenderobj, KX_Scene* scene, KX_BlenderSceneConverter *converter, bool libloading)
-{
- RAS_MeshObject *meshobj;
- int lightlayer = blenderobj ? blenderobj->lay:(1<<20)-1; // all layers if no object.
-
- // Without checking names, we get some reuse we don't want that can cause
- // problems with material LoDs.
- if (blenderobj && ((meshobj = converter->FindGameMesh(mesh/*, ob->lay*/)) != NULL)) {
- const char *bge_name = meshobj->GetName().ReadPtr();
- const char *blender_name = ((ID *)blenderobj->data)->name + 2;
- if (STREQ(bge_name, blender_name)) {
- return meshobj;
- }
- }
-
- // Get DerivedMesh data
- DerivedMesh *dm = CDDM_from_mesh(mesh);
- DM_ensure_tessface(dm);
-
- MVert *mvert = dm->getVertArray(dm);
- int totvert = dm->getNumVerts(dm);
-
- MFace *mface = dm->getTessFaceArray(dm);
- MTFace *tface = static_cast<MTFace*>(dm->getTessFaceDataArray(dm, CD_MTFACE));
- MCol *mcol = static_cast<MCol*>(dm->getTessFaceDataArray(dm, CD_MCOL));
- float (*tangent)[4] = NULL;
- int totface = dm->getNumTessFaces(dm);
- const char *tfaceName = "";
-
- /* needs to be rewritten for loopdata */
- if (tface) {
- if (CustomData_get_layer_index(&dm->faceData, CD_TANGENT) == -1) {
- bool generate_data = false;
- if (CustomData_get_layer_index(&dm->loopData, CD_TANGENT) == -1) {
- DM_calc_loop_tangents(dm, true, NULL, 0);
- generate_data = true;
- }
- DM_generate_tangent_tessface_data(dm, generate_data);
- }
- tangent = (float(*)[4])dm->getTessFaceDataArray(dm, CD_TANGENT);
- }
-
- meshobj = new RAS_MeshObject(mesh);
-
- // Extract avaiable layers
- MTF_localLayer *layers = new MTF_localLayer[MAX_MTFACE];
- for (int lay=0; lay<MAX_MTFACE; lay++) {
- layers[lay].face = 0;
- layers[lay].name = "";
- }
-
- int validLayers = 0;
- for (int i=0; i<dm->faceData.totlayer; i++)
- {
- if (dm->faceData.layers[i].type == CD_MTFACE)
- {
- if (validLayers >= MAX_MTFACE) {
- printf("%s: corrupted mesh %s - too many CD_MTFACE layers\n", __func__, mesh->id.name);
- break;
- }
-
- layers[validLayers].face = (MTFace*)(dm->faceData.layers[i].data);
- layers[validLayers].name = dm->faceData.layers[i].name;
- if (tface == layers[validLayers].face)
- tfaceName = layers[validLayers].name;
- validLayers++;
- }
- }
-
- meshobj->SetName(mesh->id.name + 2);
- meshobj->m_sharedvertex_map.resize(totvert);
-
- Material* ma = 0;
- MT_Point2 uvs[4][RAS_TexVert::MAX_UNIT];
- unsigned int rgb[4] = {0};
-
- MT_Point3 pt[4];
- MT_Vector3 no[4];
- MT_Vector4 tan[4];
-
- /* ugh, if there is a less annoying way to do this please use that.
- * since these are converted from floats to floats, theres no real
- * advantage to use MT_ types - campbell */
- for (unsigned int i = 0; i < 4; i++) {
- const float zero_vec[4] = {0.0f};
- pt[i].setValue(zero_vec);
- no[i].setValue(zero_vec);
- tan[i].setValue(zero_vec);
- }
-
- /* we need to manually initialize the uvs (MoTo doesn't do that) [#34550] */
- for (unsigned int i = 0; i < RAS_TexVert::MAX_UNIT; i++) {
- uvs[0][i] = uvs[1][i] = uvs[2][i] = uvs[3][i] = MT_Point2(0.f, 0.f);
- }
-
- for (int f=0;f<totface;f++,mface++)
- {
- /* get coordinates, normals and tangents */
- pt[0].setValue(mvert[mface->v1].co);
- pt[1].setValue(mvert[mface->v2].co);
- pt[2].setValue(mvert[mface->v3].co);
- if (mface->v4) pt[3].setValue(mvert[mface->v4].co);
-
- if (mface->flag & ME_SMOOTH) {
- float n0[3], n1[3], n2[3], n3[3];
-
- normal_short_to_float_v3(n0, mvert[mface->v1].no);
- normal_short_to_float_v3(n1, mvert[mface->v2].no);
- normal_short_to_float_v3(n2, mvert[mface->v3].no);
- no[0] = n0;
- no[1] = n1;
- no[2] = n2;
-
- if (mface->v4) {
- normal_short_to_float_v3(n3, mvert[mface->v4].no);
- no[3] = n3;
- }
- }
- else {
- float fno[3];
-
- if (mface->v4)
- normal_quad_v3(fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co, mvert[mface->v4].co);
- else
- normal_tri_v3(fno,mvert[mface->v1].co, mvert[mface->v2].co, mvert[mface->v3].co);
-
- no[0] = no[1] = no[2] = no[3] = MT_Vector3(fno);
- }
-
- if (tangent) {
- tan[0] = tangent[f*4 + 0];
- tan[1] = tangent[f*4 + 1];
- tan[2] = tangent[f*4 + 2];
-
- if (mface->v4)
- tan[3] = tangent[f*4 + 3];
- }
- if (blenderobj)
- ma = give_current_material(blenderobj, mface->mat_nr+1);
- else
- ma = mesh->mat ? mesh->mat[mface->mat_nr]:NULL;
-
- // Check for blender material
- if (ma == NULL) {
- ma= &defmaterial;
- }
-
- {
-
- RAS_MaterialBucket* bucket = material_from_mesh(ma, mface, tface, mcol, layers, lightlayer, rgb, uvs, tfaceName, scene, converter);
-
- // set render flags
- bool visible = ((ma->game.flag & GEMAT_INVISIBLE)==0);
- bool twoside = ((ma->game.flag & GEMAT_BACKCULL)==0);
- bool collider = ((ma->game.flag & GEMAT_NOPHYSICS)==0);
-
- /* mark face as flat, so vertices are split */
- bool flat = (mface->flag & ME_SMOOTH) == 0;
-
- int nverts = (mface->v4)? 4: 3;
-
- RAS_Polygon *poly = meshobj->AddPolygon(bucket, nverts);
-
- poly->SetVisible(visible);
- poly->SetCollider(collider);
- poly->SetTwoside(twoside);
- //poly->SetEdgeCode(mface->edcode);
-
- meshobj->AddVertex(poly,0,pt[0],uvs[0],tan[0],rgb[0],no[0],flat,mface->v1);
- meshobj->AddVertex(poly,1,pt[1],uvs[1],tan[1],rgb[1],no[1],flat,mface->v2);
- meshobj->AddVertex(poly,2,pt[2],uvs[2],tan[2],rgb[2],no[2],flat,mface->v3);
-
- if (nverts==4)
- meshobj->AddVertex(poly,3,pt[3],uvs[3],tan[3],rgb[3],no[3],flat,mface->v4);
- }
-
- if (tface)
- tface++;
- if (mcol)
- mcol+=4;
-
- for (int lay=0; lay<MAX_MTFACE; lay++)
- {
- MTF_localLayer &layer = layers[lay];
- if (layer.face == 0) break;
-
- layer.face++;
- }
- }
- // keep meshobj->m_sharedvertex_map for reinstance phys mesh.
- // 2.49a and before it did: meshobj->m_sharedvertex_map.clear();
- // but this didnt save much ram. - Campbell
- meshobj->EndConversion();
-
- // pre calculate texture generation
- // However, we want to delay this if we're libloading so we can make sure we have the right scene.
- if (!libloading) {
- for (list<RAS_MeshMaterial>::iterator mit = meshobj->GetFirstMaterial();
- mit != meshobj->GetLastMaterial(); ++ mit) {
- mit->m_bucket->GetPolyMaterial()->OnConstruction();
- }
- }
-
- if (layers)
- delete []layers;
-
- dm->release(dm);
-
- converter->RegisterGameMesh(meshobj, mesh);
- return meshobj;
-}
-
-
-
-static PHY_MaterialProps *CreateMaterialFromBlenderObject(struct Object* blenderobject)
-{
- PHY_MaterialProps *materialProps = new PHY_MaterialProps;
-
- MT_assert(materialProps && "Create physics material properties failed");
-
- Material* blendermat = give_current_material(blenderobject, 1);
-
- if (blendermat)
- {
- MT_assert(0.0f <= blendermat->reflect && blendermat->reflect <= 1.0f);
-
- materialProps->m_restitution = blendermat->reflect;
- materialProps->m_friction = blendermat->friction;
- materialProps->m_fh_spring = blendermat->fh;
- materialProps->m_fh_damping = blendermat->xyfrict;
- materialProps->m_fh_distance = blendermat->fhdist;
- materialProps->m_fh_normal = (blendermat->dynamode & MA_FH_NOR) != 0;
- }
- else {
- //give some defaults
- materialProps->m_restitution = 0.f;
- materialProps->m_friction = 0.5;
- materialProps->m_fh_spring = 0.f;
- materialProps->m_fh_damping = 0.f;
- materialProps->m_fh_distance = 0.f;
- materialProps->m_fh_normal = false;
-
- }
-
- return materialProps;
-}
-
-static PHY_ShapeProps *CreateShapePropsFromBlenderObject(struct Object* blenderobject)
-{
- PHY_ShapeProps *shapeProps = new PHY_ShapeProps;
-
- MT_assert(shapeProps);
-
- shapeProps->m_mass = blenderobject->mass;
-
-// This needs to be fixed in blender. For now, we use:
-
-// in Blender, inertia stands for the size value which is equivalent to
-// the sphere radius
- shapeProps->m_inertia = blenderobject->formfactor;
-
- MT_assert(0.0f <= blenderobject->damping && blenderobject->damping <= 1.0f);
- MT_assert(0.0f <= blenderobject->rdamping && blenderobject->rdamping <= 1.0f);
-
- shapeProps->m_lin_drag = 1.0f - blenderobject->damping;
- shapeProps->m_ang_drag = 1.0f - blenderobject->rdamping;
-
- shapeProps->m_friction_scaling[0] = blenderobject->anisotropicFriction[0];
- shapeProps->m_friction_scaling[1] = blenderobject->anisotropicFriction[1];
- shapeProps->m_friction_scaling[2] = blenderobject->anisotropicFriction[2];
- shapeProps->m_do_anisotropic = ((blenderobject->gameflag & OB_ANISOTROPIC_FRICTION) != 0);
-
- shapeProps->m_do_fh = (blenderobject->gameflag & OB_DO_FH) != 0;
- shapeProps->m_do_rot_fh = (blenderobject->gameflag & OB_ROT_FH) != 0;
-
-// velocity clamping XXX
- shapeProps->m_clamp_vel_min = blenderobject->min_vel;
- shapeProps->m_clamp_vel_max = blenderobject->max_vel;
- shapeProps->m_clamp_angvel_min = blenderobject->min_angvel;
- shapeProps->m_clamp_angvel_max = blenderobject->max_angvel;
-
-// Character physics properties
- shapeProps->m_step_height = blenderobject->step_height;
- shapeProps->m_jump_speed = blenderobject->jump_speed;
- shapeProps->m_fall_speed = blenderobject->fall_speed;
- shapeProps->m_max_jumps = blenderobject->max_jumps;
-
- return shapeProps;
-}
-
-
-
-
-
-//////////////////////////////////////////////////////////
-
-
-
-static float my_boundbox_mesh(Mesh *me, float *loc, float *size)
-{
- MVert *mvert;
- BoundBox *bb;
- float min[3], max[3];
- float mloc[3], msize[3];
- float radius_sq=0.0f, vert_radius_sq, *co;
- int a;
-
- if (me->bb==0) {
- me->bb = BKE_boundbox_alloc_unit();
- }
- bb= me->bb;
-
- INIT_MINMAX(min, max);
-
- if (!loc) loc= mloc;
- if (!size) size= msize;
-
- mvert= me->mvert;
- for (a = 0; a<me->totvert; a++, mvert++) {
- co = mvert->co;
-
- /* bounds */
- minmax_v3v3_v3(min, max, co);
-
- /* radius */
-
- vert_radius_sq = len_squared_v3(co);
- if (vert_radius_sq > radius_sq)
- radius_sq = vert_radius_sq;
- }
-
- if (me->totvert) {
- loc[0] = (min[0] + max[0]) / 2.0f;
- loc[1] = (min[1] + max[1]) / 2.0f;
- loc[2] = (min[2] + max[2]) / 2.0f;
-
- size[0] = (max[0] - min[0]) / 2.0f;
- size[1] = (max[1] - min[1]) / 2.0f;
- size[2] = (max[2] - min[2]) / 2.0f;
- }
- else {
- loc[0] = loc[1] = loc[2] = 0.0f;
- size[0] = size[1] = size[2] = 0.0f;
- }
-
- bb->vec[0][0] = bb->vec[1][0] = bb->vec[2][0] = bb->vec[3][0] = loc[0]-size[0];
- bb->vec[4][0] = bb->vec[5][0] = bb->vec[6][0] = bb->vec[7][0] = loc[0]+size[0];
-
- bb->vec[0][1] = bb->vec[1][1] = bb->vec[4][1] = bb->vec[5][1] = loc[1]-size[1];
- bb->vec[2][1] = bb->vec[3][1] = bb->vec[6][1] = bb->vec[7][1] = loc[1]+size[1];
-
- bb->vec[0][2] = bb->vec[3][2] = bb->vec[4][2] = bb->vec[7][2] = loc[2]-size[2];
- bb->vec[1][2] = bb->vec[2][2] = bb->vec[5][2] = bb->vec[6][2] = loc[2]+size[2];
-
- return sqrtf_signed(radius_sq);
-}
-
-//////////////////////////////////////////////////////
-
-
-static void BL_CreateGraphicObjectNew(KX_GameObject* gameobj,
- const MT_Point3& localAabbMin,
- const MT_Point3& localAabbMax,
- KX_Scene* kxscene,
- bool isActive,
- e_PhysicsEngine physics_engine)
-{
- if (gameobj->GetMeshCount() > 0)
- {
- switch (physics_engine)
- {
-#ifdef WITH_BULLET
- case UseBullet:
- {
- CcdPhysicsEnvironment* env = (CcdPhysicsEnvironment*)kxscene->GetPhysicsEnvironment();
- assert(env);
- PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
- CcdGraphicController* ctrl = new CcdGraphicController(env, motionstate);
- gameobj->SetGraphicController(ctrl);
- ctrl->SetNewClientInfo(gameobj->getClientInfo());
- ctrl->SetLocalAabb(localAabbMin, localAabbMax);
- if (isActive) {
- // add first, this will create the proxy handle, only if the object is visible
- if (gameobj->GetVisible())
- env->AddCcdGraphicController(ctrl);
- // update the mesh if there is a deformer, this will also update the bounding box for modifiers
- RAS_Deformer* deformer = gameobj->GetDeformer();
- if (deformer)
- deformer->UpdateBuckets();
- }
- }
- break;
-#endif
- default:
- break;
- }
- }
-}
-
-static void BL_CreatePhysicsObjectNew(KX_GameObject* gameobj,
- struct Object* blenderobject,
- RAS_MeshObject* meshobj,
- KX_Scene* kxscene,
- int activeLayerBitInfo,
- KX_BlenderSceneConverter *converter,
- bool processCompoundChildren
- )
-
-{
- //SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
- //int userigidbody = SYS_GetCommandLineInt(syshandle,"norigidbody",0);
- //bool bRigidBody = (userigidbody == 0);
-
- // object has physics representation?
- if (!(blenderobject->gameflag & OB_COLLISION)) {
- // Respond to all collisions so that Near sensors work on No Collision
- // objects.
- gameobj->SetUserCollisionGroup(0xffff);
- gameobj->SetUserCollisionMask(0xffff);
- return;
- }
-
- gameobj->SetUserCollisionGroup(blenderobject->col_group);
- gameobj->SetUserCollisionMask(blenderobject->col_mask);
-
- // get Root Parent of blenderobject
- struct Object* parent= blenderobject->parent;
- while (parent && parent->parent) {
- parent= parent->parent;
- }
-
- bool isCompoundChild = false;
- bool hasCompoundChildren = !parent && (blenderobject->gameflag & OB_CHILD) && !(blenderobject->gameflag & OB_SOFT_BODY);
-
- /* When the parent is not OB_DYNAMIC and has no OB_COLLISION then it gets no bullet controller
- * and cant be apart of the parents compound shape, same goes for OB_SOFT_BODY */
- if (parent && (parent->gameflag & (OB_DYNAMIC | OB_COLLISION))) {
- if ((parent->gameflag & OB_CHILD)!=0 && (blenderobject->gameflag & OB_CHILD) && !(parent->gameflag & OB_SOFT_BODY)) {
- isCompoundChild = true;
- }
- }
- if (processCompoundChildren != isCompoundChild)
- return;
-
-
- PHY_ShapeProps* shapeprops =
- CreateShapePropsFromBlenderObject(blenderobject);
-
-
- PHY_MaterialProps* smmaterial =
- CreateMaterialFromBlenderObject(blenderobject);
-
- DerivedMesh* dm = NULL;
- if (gameobj->GetDeformer())
- dm = gameobj->GetDeformer()->GetPhysicsMesh();
-
- class PHY_IMotionState* motionstate = new KX_MotionState(gameobj->GetSGNode());
-
- kxscene->GetPhysicsEnvironment()->ConvertObject(gameobj, meshobj, dm, kxscene, shapeprops, smmaterial, motionstate, activeLayerBitInfo, isCompoundChild, hasCompoundChildren);
-
- bool isActor = (blenderobject->gameflag & OB_ACTOR)!=0;
- bool isSensor = (blenderobject->gameflag & OB_SENSOR) != 0;
- gameobj->getClientInfo()->m_type =
- (isSensor) ? ((isActor) ? KX_ClientObjectInfo::OBACTORSENSOR : KX_ClientObjectInfo::OBSENSOR) :
- (isActor) ? KX_ClientObjectInfo::ACTOR : KX_ClientObjectInfo::STATIC;
-
- // should we record animation for this object?
- if ((blenderobject->gameflag & OB_RECORD_ANIMATION) != 0)
- gameobj->SetRecordAnimation(true);
-
- delete shapeprops;
- delete smmaterial;
- if (dm) {
- dm->needsFree = 1;
- dm->release(dm);
- }
-}
-
-
-
-
-
-static KX_LightObject *gamelight_from_blamp(Object *ob, Lamp *la, unsigned int layerflag, KX_Scene *kxscene, RAS_IRasterizer *rasterizer, KX_BlenderSceneConverter *converter)
-{
- RAS_ILightObject *lightobj = rasterizer->CreateLight();
- KX_LightObject *gamelight;
-
- lightobj->m_att1 = la->att1;
- lightobj->m_att2 = (la->mode & LA_QUAD) ? la->att2 : 0.0f;
- lightobj->m_coeff_const = la->coeff_const;
- lightobj->m_coeff_lin = la->coeff_lin;
- lightobj->m_coeff_quad = la->coeff_quad;
- lightobj->m_color[0] = la->r;
- lightobj->m_color[1] = la->g;
- lightobj->m_color[2] = la->b;
- lightobj->m_distance = la->dist;
- lightobj->m_energy = la->energy;
- lightobj->m_shadowclipstart = la->clipsta;
- lightobj->m_shadowclipend = la->clipend;
- lightobj->m_shadowbias = la->bias;
- lightobj->m_shadowbleedbias = la->bleedbias;
- lightobj->m_shadowmaptype = la->shadowmap_type;
- lightobj->m_shadowfrustumsize = la->shadow_frustum_size;
- lightobj->m_shadowcolor[0] = la->shdwr;
- lightobj->m_shadowcolor[1] = la->shdwg;
- lightobj->m_shadowcolor[2] = la->shdwb;
- lightobj->m_layer = layerflag;
- lightobj->m_spotblend = la->spotblend;
- lightobj->m_spotsize = la->spotsize;
-
- lightobj->m_nodiffuse = (la->mode & LA_NO_DIFF) != 0;
- lightobj->m_nospecular = (la->mode & LA_NO_SPEC) != 0;
-
- bool glslmat = converter->GetGLSLMaterials();
-
- // in GLSL NEGATIVE LAMP is handled inside the lamp update function
- if (glslmat==0) {
- if (la->mode & LA_NEG)
- {
- lightobj->m_color[0] = -lightobj->m_color[0];
- lightobj->m_color[1] = -lightobj->m_color[1];
- lightobj->m_color[2] = -lightobj->m_color[2];
- }
- }
-
- if (la->type==LA_SUN) {
- lightobj->m_type = RAS_ILightObject::LIGHT_SUN;
- } else if (la->type==LA_SPOT) {
- lightobj->m_type = RAS_ILightObject::LIGHT_SPOT;
- } else {
- lightobj->m_type = RAS_ILightObject::LIGHT_NORMAL;
- }
-
- gamelight = new KX_LightObject(kxscene, KX_Scene::m_callbacks, rasterizer,
- lightobj, glslmat);
-
- return gamelight;
-}
-
-static KX_Camera *gamecamera_from_bcamera(Object *ob, KX_Scene *kxscene, KX_BlenderSceneConverter *converter)
-{
- Camera* ca = static_cast<Camera*>(ob->data);
- RAS_CameraData camdata(ca->lens, ca->ortho_scale, ca->sensor_x, ca->sensor_y, ca->sensor_fit, ca->shiftx, ca->shifty, ca->clipsta, ca->clipend, ca->type == CAM_PERSP, ca->YF_dofdist);
- KX_Camera *gamecamera;
-
- gamecamera= new KX_Camera(kxscene, KX_Scene::m_callbacks, camdata);
- gamecamera->SetName(ca->id.name + 2);
-
- return gamecamera;
-}
-
-static KX_GameObject *gameobject_from_blenderobject(
- Object *ob,
- KX_Scene *kxscene,
- RAS_IRasterizer *rendertools,
- KX_BlenderSceneConverter *converter,
- bool libloading)
-{
- KX_GameObject *gameobj = NULL;
- Scene *blenderscene = kxscene->GetBlenderScene();
-
- switch (ob->type) {
- case OB_LAMP:
- {
- KX_LightObject* gamelight = gamelight_from_blamp(ob, static_cast<Lamp*>(ob->data), ob->lay, kxscene, rendertools, converter);
- gameobj = gamelight;
-
- if (blenderscene->lay & ob->lay)
- {
- gamelight->AddRef();
- kxscene->GetLightList()->Add(gamelight);
- }
-
- break;
- }
-
- case OB_CAMERA:
- {
- KX_Camera* gamecamera = gamecamera_from_bcamera(ob, kxscene, converter);
- gameobj = gamecamera;
-
- //don't add a reference: the camera list in kxscene->m_cameras is not released at the end
- //gamecamera->AddRef();
- kxscene->AddCamera(gamecamera);
-
- break;
- }
-
- case OB_MESH:
- {
- Mesh* mesh = static_cast<Mesh*>(ob->data);
- float center[3], extents[3];
- float radius = my_boundbox_mesh((Mesh*) ob->data, center, extents);
- RAS_MeshObject* meshobj = BL_ConvertMesh(mesh,ob,kxscene,converter, libloading);
-
- // needed for python scripting
- kxscene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
-
- if (ob->gameflag & OB_NAVMESH)
- {
- gameobj = new KX_NavMeshObject(kxscene,KX_Scene::m_callbacks);
- gameobj->AddMesh(meshobj);
- break;
- }
-
- gameobj = new BL_DeformableGameObject(ob,kxscene,KX_Scene::m_callbacks);
-
- // set transformation
- gameobj->AddMesh(meshobj);
-
- // gather levels of detail
- if (BLI_listbase_count_at_most(&ob->lodlevels, 2) > 1) {
- LodLevel *lod = ((LodLevel*)ob->lodlevels.first)->next;
- Mesh* lodmesh = mesh;
- Object* lodmatob = ob;
- gameobj->AddLodMesh(meshobj);
- for (; lod; lod = lod->next) {
- if (!lod->source || lod->source->type != OB_MESH) continue;
- if (lod->flags & OB_LOD_USE_MESH) {
- lodmesh = static_cast<Mesh*>(lod->source->data);
- }
- if (lod->flags & OB_LOD_USE_MAT) {
- lodmatob = lod->source;
- }
- gameobj->AddLodMesh(BL_ConvertMesh(lodmesh, lodmatob, kxscene, converter, libloading));
- }
- if (blenderscene->gm.lodflag & SCE_LOD_USE_HYST) {
- kxscene->SetLodHysteresis(true);
- kxscene->SetLodHysteresisValue(blenderscene->gm.scehysteresis);
- }
- }
-
- // for all objects: check whether they want to
- // respond to updates
- bool ignoreActivityCulling =
- ((ob->gameflag2 & OB_NEVER_DO_ACTIVITY_CULLING)!=0);
- gameobj->SetIgnoreActivityCulling(ignoreActivityCulling);
- gameobj->SetOccluder((ob->gameflag & OB_OCCLUDER) != 0, false);
-
- // we only want obcolor used if there is a material in the mesh
- // that requires it
- Material *mat= NULL;
- bool bUseObjectColor=false;
-
- for (int i=0;i<mesh->totcol;i++) {
- mat=mesh->mat[i];
- if (!mat) break;
- if ((mat->shade_flag & MA_OBCOLOR)) {
- bUseObjectColor = true;
- break;
- }
- }
- if (bUseObjectColor)
- gameobj->SetObjectColor(ob->col);
-
- // two options exists for deform: shape keys and armature
- // only support relative shape key
- bool bHasShapeKey = mesh->key != NULL && mesh->key->type==KEY_RELATIVE;
- bool bHasDvert = mesh->dvert != NULL && ob->defbase.first;
- bool bHasArmature = (BL_ModifierDeformer::HasArmatureDeformer(ob) && ob->parent && ob->parent->type == OB_ARMATURE && bHasDvert);
- bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(ob);
-#ifdef WITH_BULLET
- bool bHasSoftBody = (!ob->parent && (ob->gameflag & OB_SOFT_BODY));
-#endif
- if (bHasModifier) {
- BL_ModifierDeformer *dcont = new BL_ModifierDeformer((BL_DeformableGameObject *)gameobj,
- kxscene->GetBlenderScene(), ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
- } else if (bHasShapeKey) {
- // not that we can have shape keys without dvert!
- BL_ShapeDeformer *dcont = new BL_ShapeDeformer((BL_DeformableGameObject*)gameobj,
- ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
- } else if (bHasArmature) {
- BL_SkinDeformer *dcont = new BL_SkinDeformer((BL_DeformableGameObject*)gameobj,
- ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
- } else if (bHasDvert) {
- // this case correspond to a mesh that can potentially deform but not with the
- // object to which it is attached for the moment. A skin mesh was created in
- // BL_ConvertMesh() so must create a deformer too!
- BL_MeshDeformer *dcont = new BL_MeshDeformer((BL_DeformableGameObject*)gameobj,
- ob, meshobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
-#ifdef WITH_BULLET
- } else if (bHasSoftBody) {
- KX_SoftBodyDeformer *dcont = new KX_SoftBodyDeformer(meshobj, (BL_DeformableGameObject*)gameobj);
- ((BL_DeformableGameObject*)gameobj)->SetDeformer(dcont);
-#endif
- }
-
- MT_Point3 min = MT_Point3(center) - MT_Vector3(extents);
- MT_Point3 max = MT_Point3(center) + MT_Vector3(extents);
- SG_BBox bbox = SG_BBox(min, max);
- gameobj->GetSGNode()->SetBBox(bbox);
- gameobj->GetSGNode()->SetRadius(radius);
-
- break;
- }
-
- case OB_ARMATURE:
- {
- bArmature *arm = (bArmature*)ob->data;
- gameobj = new BL_ArmatureObject(
- kxscene,
- KX_Scene::m_callbacks,
- ob,
- kxscene->GetBlenderScene(), // handle
- arm->gevertdeformer
- );
- /* Get the current pose from the armature object and apply it as the rest pose */
- break;
- }
-
- case OB_EMPTY:
- {
- gameobj = new KX_EmptyObject(kxscene,KX_Scene::m_callbacks);
- // set transformation
- break;
- }
-
- case OB_FONT:
- {
- bool do_color_management = BKE_scene_check_color_management_enabled(blenderscene);
- /* font objects have no bounding box */
- gameobj = new KX_FontObject(kxscene,KX_Scene::m_callbacks, rendertools, ob, do_color_management);
-
- /* add to the list only the visible fonts */
- if ((ob->lay & kxscene->GetBlenderScene()->lay) != 0)
- kxscene->AddFont(static_cast<KX_FontObject*>(gameobj));
- break;
- }
-
-#ifdef THREADED_DAG_WORKAROUND
- case OB_CURVE:
- {
- if (ob->curve_cache == NULL) {
- BKE_displist_make_curveTypes(blenderscene, ob, false);
- }
- }
-#endif
-
- }
- if (gameobj)
- {
- gameobj->SetLayer(ob->lay);
- gameobj->SetBlenderObject(ob);
- /* set the visibility state based on the objects render option in the outliner */
- if (ob->restrictflag & OB_RESTRICT_RENDER) gameobj->SetVisible(0, 0);
- }
- return gameobj;
-}
-
-struct parentChildLink {
- struct Object* m_blenderchild;
- SG_Node* m_gamechildnode;
-};
-
-static bPoseChannel *get_active_posechannel2(Object *ob)
-{
- bArmature *arm= (bArmature*)ob->data;
- bPoseChannel *pchan;
-
- /* find active */
- for (pchan= (bPoseChannel *)ob->pose->chanbase.first; pchan; pchan= pchan->next) {
- if (pchan->bone && (pchan->bone == arm->act_bone) && (pchan->bone->layer & arm->layer))
- return pchan;
- }
-
- return NULL;
-}
-
-static ListBase *get_active_constraints2(Object *ob)
-{
- if (!ob)
- return NULL;
-
- // XXX - shouldnt we care about the pose data and not the mode???
- if (ob->mode & OB_MODE_POSE) {
- bPoseChannel *pchan;
-
- pchan = get_active_posechannel2(ob);
- if (pchan)
- return &pchan->constraints;
- }
- else
- return &ob->constraints;
-
- return NULL;
-}
-
-static void UNUSED_FUNCTION(print_active_constraints2)(Object *ob) //not used, use to debug
-{
- bConstraint* curcon;
- ListBase* conlist = get_active_constraints2(ob);
-
- if (conlist) {
- for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
- printf("%i\n",curcon->type);
- }
- }
-}
-
-// Copy base layer to object layer like in BKE_scene_set_background
-static void blenderSceneSetBackground(Scene *blenderscene)
-{
- Scene *it;
- Base *base;
-
- for (SETLOOPER(blenderscene, it, base)) {
- base->object->lay = base->lay;
- base->object->flag = base->flag;
- }
-}
-
-static KX_GameObject* getGameOb(STR_String busc,CListValue* sumolist)
-{
-
- for (int j=0;j<sumolist->GetCount();j++)
- {
- KX_GameObject* gameobje = (KX_GameObject*) sumolist->GetValue(j);
- if (gameobje->GetName()==busc)
- return gameobje;
- }
-
- return 0;
-
-}
-
-static bool bl_isConstraintInList(KX_GameObject *gameobj, set<KX_GameObject*> convertedlist)
-{
- set<KX_GameObject*>::iterator gobit;
- for (gobit = convertedlist.begin(); gobit != convertedlist.end(); gobit++) {
- if ((*gobit)->GetName() == gameobj->GetName())
- return true;
- }
- return false;
-}
-
-/* helper for BL_ConvertBlenderObjects, avoids code duplication
- * note: all var names match args are passed from the caller */
-static void bl_ConvertBlenderObject_Single(
- KX_BlenderSceneConverter *converter,
- Object *blenderobject,
- vector<parentChildLink> &vec_parent_child,
- CListValue* logicbrick_conversionlist,
- CListValue* objectlist, CListValue* inactivelist, CListValue* sumolist,
- KX_Scene* kxscene, KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr, SCA_TimeEventManager* timemgr,
- bool isInActiveLayer
- )
-{
- MT_Point3 pos(
- blenderobject->loc[0]+blenderobject->dloc[0],
- blenderobject->loc[1]+blenderobject->dloc[1],
- blenderobject->loc[2]+blenderobject->dloc[2]
- );
-
- MT_Matrix3x3 rotation;
- float rotmat[3][3];
- BKE_object_rot_to_mat3(blenderobject, rotmat, false);
- rotation.setValue3x3((float*)rotmat);
-
- MT_Vector3 scale(blenderobject->size);
-
- gameobj->NodeSetLocalPosition(pos);
- gameobj->NodeSetLocalOrientation(rotation);
- gameobj->NodeSetLocalScale(scale);
- gameobj->NodeUpdateGS(0);
-
- sumolist->Add(gameobj->AddRef());
-
- BL_ConvertProperties(blenderobject,gameobj,timemgr,kxscene,isInActiveLayer);
-
- gameobj->SetName(blenderobject->id.name + 2);
-
- // update children/parent hierarchy
- if (blenderobject->parent != 0)
- {
- // blender has an additional 'parentinverse' offset in each object
- SG_Callbacks callback(NULL,NULL,NULL,KX_Scene::KX_ScenegraphUpdateFunc,KX_Scene::KX_ScenegraphRescheduleFunc);
- SG_Node* parentinversenode = new SG_Node(NULL,kxscene,callback);
-
- // define a normal parent relationship for this node.
- KX_NormalParentRelation * parent_relation = KX_NormalParentRelation::New();
- parentinversenode->SetParentRelation(parent_relation);
-
- parentChildLink pclink;
- pclink.m_blenderchild = blenderobject;
- pclink.m_gamechildnode = parentinversenode;
- vec_parent_child.push_back(pclink);
-
- float* fl = (float*) blenderobject->parentinv;
- MT_Transform parinvtrans(fl);
- parentinversenode->SetLocalPosition(parinvtrans.getOrigin());
- // problem here: the parent inverse transform combines scaling and rotation
- // in the basis but the scenegraph needs separate rotation and scaling.
- // This is not important for OpenGL (it uses 4x4 matrix) but it is important
- // for the physic engine that needs a separate scaling
- //parentinversenode->SetLocalOrientation(parinvtrans.getBasis());
-
- // Extract the rotation and the scaling from the basis
- MT_Matrix3x3 ori(parinvtrans.getBasis());
- MT_Vector3 x(ori.getColumn(0));
- MT_Vector3 y(ori.getColumn(1));
- MT_Vector3 z(ori.getColumn(2));
- MT_Vector3 parscale(x.length(), y.length(), z.length());
- if (!MT_fuzzyZero(parscale[0]))
- x /= parscale[0];
- if (!MT_fuzzyZero(parscale[1]))
- y /= parscale[1];
- if (!MT_fuzzyZero(parscale[2]))
- z /= parscale[2];
- ori.setColumn(0, x);
- ori.setColumn(1, y);
- ori.setColumn(2, z);
- parentinversenode->SetLocalOrientation(ori);
- parentinversenode->SetLocalScale(parscale);
-
- parentinversenode->AddChild(gameobj->GetSGNode());
- }
-
- // needed for python scripting
- logicmgr->RegisterGameObjectName(gameobj->GetName(),gameobj);
-
- // needed for group duplication
- logicmgr->RegisterGameObj(blenderobject, gameobj);
- for (int i = 0; i < gameobj->GetMeshCount(); i++)
- logicmgr->RegisterGameMeshName(gameobj->GetMesh(i)->GetName(), blenderobject);
-
- converter->RegisterGameObject(gameobj, blenderobject);
- // this was put in rapidly, needs to be looked at more closely
- // only draw/use objects in active 'blender' layers
-
- logicbrick_conversionlist->Add(gameobj->AddRef());
-
- if (isInActiveLayer)
- {
- objectlist->Add(gameobj->AddRef());
- //tf.Add(gameobj->GetSGNode());
-
- gameobj->NodeUpdateGS(0);
- gameobj->AddMeshUser();
- }
- else
- {
- //we must store this object otherwise it will be deleted
- //at the end of this function if it is not a root object
- inactivelist->Add(gameobj->AddRef());
- }
-}
-
-
-// convert blender objects into ketsji gameobjects
-void BL_ConvertBlenderObjects(struct Main* maggie,
- KX_Scene* kxscene,
- KX_KetsjiEngine* ketsjiEngine,
- e_PhysicsEngine physics_engine,
- RAS_IRasterizer* rendertools,
- RAS_ICanvas* canvas,
- KX_BlenderSceneConverter* converter,
- bool alwaysUseExpandFraming,
- bool libloading
- )
-{
-
-#define BL_CONVERTBLENDEROBJECT_SINGLE \
- bl_ConvertBlenderObject_Single(converter, \
- blenderobject, \
- vec_parent_child, \
- logicbrick_conversionlist, \
- objectlist, inactivelist, sumolist, \
- kxscene, gameobj, \
- logicmgr, timemgr, \
- isInActiveLayer \
- )
-
-
-
- Scene *blenderscene = kxscene->GetBlenderScene();
- // for SETLOOPER
- Scene *sce_iter;
- Base *base;
-
- // Get the frame settings of the canvas.
- // Get the aspect ratio of the canvas as designed by the user.
-
- RAS_FrameSettings::RAS_FrameType frame_type;
- int aspect_width;
- int aspect_height;
- set<Group*> grouplist; // list of groups to be converted
- set<Object*> allblobj; // all objects converted
- set<Object*> groupobj; // objects from groups (never in active layer)
-
- // This is bad, but we use this to make sure the first time this is called
- // is not in a separate thread.
- BL_Texture::GetMaxUnits();
-
- /* We have to ensure that group definitions are only converted once
- * push all converted group members to this set.
- * This will happen when a group instance is made from a linked group instance
- * and both are on the active layer. */
- set<KX_GameObject*> convertedlist;
-
- if (alwaysUseExpandFraming) {
- frame_type = RAS_FrameSettings::e_frame_extend;
- aspect_width = canvas->GetWidth();
- aspect_height = canvas->GetHeight();
- } else {
- if (blenderscene->gm.framing.type == SCE_GAMEFRAMING_BARS) {
- frame_type = RAS_FrameSettings::e_frame_bars;
- } else if (blenderscene->gm.framing.type == SCE_GAMEFRAMING_EXTEND) {
- frame_type = RAS_FrameSettings::e_frame_extend;
- } else {
- frame_type = RAS_FrameSettings::e_frame_scale;
- }
-
- aspect_width = (int)(blenderscene->r.xsch * blenderscene->r.xasp);
- aspect_height = (int)(blenderscene->r.ysch * blenderscene->r.yasp);
- }
-
- RAS_FrameSettings frame_settings(
- frame_type,
- blenderscene->gm.framing.col[0],
- blenderscene->gm.framing.col[1],
- blenderscene->gm.framing.col[2],
- aspect_width,
- aspect_height
- );
- kxscene->SetFramingType(frame_settings);
-
- kxscene->SetGravity(MT_Vector3(0,0, -blenderscene->gm.gravity));
-
- /* set activity culling parameters */
- kxscene->SetActivityCulling( (blenderscene->gm.mode & WO_ACTIVITY_CULLING) != 0);
- kxscene->SetActivityCullingRadius(blenderscene->gm.activityBoxRadius);
- kxscene->SetDbvtCulling((blenderscene->gm.mode & WO_DBVT_CULLING) != 0);
-
- // no occlusion culling by default
- kxscene->SetDbvtOcclusionRes(0);
-
- int activeLayerBitInfo = blenderscene->lay;
-
- // list of all object converted, active and inactive
- CListValue* sumolist = new CListValue();
-
- vector<parentChildLink> vec_parent_child;
-
- CListValue* objectlist = kxscene->GetObjectList();
- CListValue* inactivelist = kxscene->GetInactiveList();
- CListValue* parentlist = kxscene->GetRootParentList();
-
- SCA_LogicManager* logicmgr = kxscene->GetLogicManager();
- SCA_TimeEventManager* timemgr = kxscene->GetTimeEventManager();
-
- CListValue* logicbrick_conversionlist = new CListValue();
-
- //SG_TreeFactory tf;
-
- // Convert actions to actionmap
- bAction *curAct;
- for (curAct = (bAction*)maggie->action.first; curAct; curAct=(bAction*)curAct->id.next)
- {
- logicmgr->RegisterActionName(curAct->id.name + 2, curAct);
- }
-
- SetDefaultLightMode(blenderscene);
-
- blenderSceneSetBackground(blenderscene);
-
- // Let's support scene set.
- // Beware of name conflict in linked data, it will not crash but will create confusion
- // in Python scripting and in certain actuators (replace mesh). Linked scene *should* have
- // no conflicting name for Object, Object data and Action.
- for (SETLOOPER(blenderscene, sce_iter, base))
- {
- Object* blenderobject = base->object;
- allblobj.insert(blenderobject);
-
- KX_GameObject* gameobj = gameobject_from_blenderobject(
- base->object,
- kxscene,
- rendertools,
- converter,
- libloading);
-
- bool isInActiveLayer = (blenderobject->lay & activeLayerBitInfo) !=0;
- if (gameobj)
- {
- /* macro calls object conversion funcs */
- BL_CONVERTBLENDEROBJECT_SINGLE;
-
- if (gameobj->IsDupliGroup()) {
- grouplist.insert(blenderobject->dup_group);
- }
-
- /* Note about memory leak issues:
- * When a CValue derived class is created, m_refcount is initialized to 1
- * so the class must be released after being used to make sure that it won't
- * hang in memory. If the object needs to be stored for a long time,
- * use AddRef() so that this Release() does not free the object.
- * Make sure that for any AddRef() there is a Release()!!!!
- * Do the same for any object derived from CValue, CExpression and NG_NetworkMessage
- */
- gameobj->Release();
- }
- }
-
- if (!grouplist.empty())
- {
- // now convert the group referenced by dupli group object
- // keep track of all groups already converted
- set<Group*> allgrouplist = grouplist;
- set<Group*> tempglist;
- // recurse
- while (!grouplist.empty())
- {
- set<Group*>::iterator git;
- tempglist.clear();
- tempglist.swap(grouplist);
- for (git=tempglist.begin(); git!=tempglist.end(); git++)
- {
- Group* group = *git;
- GroupObject* go;
- for (go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next)
- {
- Object* blenderobject = go->ob;
- if (converter->FindGameObject(blenderobject) == NULL)
- {
- allblobj.insert(blenderobject);
- groupobj.insert(blenderobject);
- KX_GameObject* gameobj = gameobject_from_blenderobject(
- blenderobject,
- kxscene,
- rendertools,
- converter,
- libloading);
-
- bool isInActiveLayer = false;
- if (gameobj) {
- /* Insert object to the constraint game object list
- * so we can check later if there is a instance in the scene or
- * an instance and its actual group definition. */
- convertedlist.insert((KX_GameObject*)gameobj->AddRef());
-
- /* macro calls object conversion funcs */
- BL_CONVERTBLENDEROBJECT_SINGLE;
-
- if (gameobj->IsDupliGroup())
- {
- if (allgrouplist.insert(blenderobject->dup_group).second)
- {
- grouplist.insert(blenderobject->dup_group);
- }
- }
-
- /* see comment above re: mem leaks */
- gameobj->Release();
- }
- }
- }
- }
- }
- }
-
- // non-camera objects not supported as camera currently
- if (blenderscene->camera && blenderscene->camera->type == OB_CAMERA) {
- KX_Camera *gamecamera= (KX_Camera*) converter->FindGameObject(blenderscene->camera);
-
- if (gamecamera)
- kxscene->SetActiveCamera(gamecamera);
- }
-
- // Set up armatures
- set<Object*>::iterator oit;
- for (oit=allblobj.begin(); oit!=allblobj.end(); oit++)
- {
- Object* blenderobj = *oit;
- if (blenderobj->type==OB_MESH) {
- Mesh *me = (Mesh*)blenderobj->data;
-
- if (me->dvert) {
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)converter->FindGameObject(blenderobj);
-
- if (obj && BL_ModifierDeformer::HasArmatureDeformer(blenderobj) && blenderobj->parent && blenderobj->parent->type==OB_ARMATURE) {
- KX_GameObject *par = converter->FindGameObject(blenderobj->parent);
- if (par && obj->GetDeformer())
- ((BL_SkinDeformer*)obj->GetDeformer())->SetArmature((BL_ArmatureObject*) par);
- }
- }
- }
- }
-
- // create hierarchy information
- int i;
- vector<parentChildLink>::iterator pcit;
-
- for (pcit = vec_parent_child.begin();!(pcit==vec_parent_child.end());++pcit)
- {
-
- struct Object* blenderchild = pcit->m_blenderchild;
- struct Object* blenderparent = blenderchild->parent;
- KX_GameObject* parentobj = converter->FindGameObject(blenderparent);
- KX_GameObject* childobj = converter->FindGameObject(blenderchild);
-
- assert(childobj);
-
- if (!parentobj || objectlist->SearchValue(childobj) != objectlist->SearchValue(parentobj))
- {
- // special case: the parent and child object are not in the same layer.
- // This weird situation is used in Apricot for test purposes.
- // Resolve it by not converting the child
- childobj->GetSGNode()->DisconnectFromParent();
- delete pcit->m_gamechildnode;
- // Now destroy the child object but also all its descendent that may already be linked
- // Remove the child reference in the local list!
- // Note: there may be descendents already if the children of the child were processed
- // by this loop before the child. In that case, we must remove the children also
- CListValue* childrenlist = childobj->GetChildrenRecursive();
- childrenlist->Add(childobj->AddRef());
- for ( i=0;i<childrenlist->GetCount();i++)
- {
- KX_GameObject* obj = static_cast<KX_GameObject*>(childrenlist->GetValue(i));
- if (sumolist->RemoveValue(obj))
- obj->Release();
- if (logicbrick_conversionlist->RemoveValue(obj))
- obj->Release();
- }
- childrenlist->Release();
-
- // now destroy recursively
- converter->UnregisterGameObject(childobj); // removing objects during conversion make sure this runs too
- kxscene->RemoveObject(childobj);
-
- continue;
- }
-
- switch (blenderchild->partype)
- {
- case PARVERT1:
- {
- // creat a new vertex parent relationship for this node.
- KX_VertexParentRelation * vertex_parent_relation = KX_VertexParentRelation::New();
- pcit->m_gamechildnode->SetParentRelation(vertex_parent_relation);
- break;
- }
- case PARSLOW:
- {
- // creat a new slow parent relationship for this node.
- KX_SlowParentRelation * slow_parent_relation = KX_SlowParentRelation::New(blenderchild->sf);
- pcit->m_gamechildnode->SetParentRelation(slow_parent_relation);
- break;
- }
- case PARBONE:
- {
- // parent this to a bone
- Bone *parent_bone = BKE_armature_find_bone_name(BKE_armature_from_object(blenderchild->parent),
- blenderchild->parsubstr);
-
- if (parent_bone) {
- KX_BoneParentRelation *bone_parent_relation = KX_BoneParentRelation::New(parent_bone);
- pcit->m_gamechildnode->SetParentRelation(bone_parent_relation);
- }
-
- break;
- }
- case PARSKEL: // skinned - ignore
- break;
- case PAROBJECT:
- case PARVERT3:
- default:
- // unhandled
- break;
- }
-
- parentobj-> GetSGNode()->AddChild(pcit->m_gamechildnode);
- }
- vec_parent_child.clear();
-
- // find 'root' parents (object that has not parents in SceneGraph)
- for (i=0;i<sumolist->GetCount();++i)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetSGNode()->GetSGParent() == 0)
- {
- parentlist->Add(gameobj->AddRef());
- gameobj->NodeUpdateGS(0);
- }
- }
-
- // create graphic controller for culling
- if (kxscene->GetDbvtCulling())
- {
- bool occlusion = false;
- for (i=0; i<sumolist->GetCount();i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetMeshCount() > 0)
- {
- MT_Point3 box[2];
- gameobj->GetSGNode()->BBox().getmm(box, MT_Transform::Identity());
- // box[0] is the min, box[1] is the max
- bool isactive = objectlist->SearchValue(gameobj);
- BL_CreateGraphicObjectNew(gameobj,box[0],box[1],kxscene,isactive,physics_engine);
- if (gameobj->GetOccluder())
- occlusion = true;
- }
- }
- if (occlusion)
- kxscene->SetDbvtOcclusionRes(blenderscene->gm.occlusionRes);
- }
- if (blenderscene->world)
- kxscene->GetPhysicsEnvironment()->SetNumTimeSubSteps(blenderscene->gm.physubstep);
-
- // now that the scenegraph is complete, let's instantiate the deformers.
- // We need that to create reusable derived mesh and physic shapes
- for (i=0;i<sumolist->GetCount();++i)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetDeformer())
- gameobj->GetDeformer()->UpdateBuckets();
- }
-
- // Set up armature constraints and shapekey drivers
- for (i=0;i<sumolist->GetCount();++i)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- {
- BL_ArmatureObject *armobj = (BL_ArmatureObject*)gameobj;
- armobj->LoadConstraints(converter);
-
- CListValue *children = armobj->GetChildren();
- for (int j=0; j<children->GetCount();++j)
- {
- BL_ShapeDeformer *deform = dynamic_cast<BL_ShapeDeformer*>(((KX_GameObject*)children->GetValue(j))->GetDeformer());
- if (deform)
- deform->LoadShapeDrivers(armobj);
- }
-
- children->Release();
- }
- }
-
- bool processCompoundChildren = false;
- // create physics information
- for (i=0;i<sumolist->GetCount();i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- struct Object* blenderobject = gameobj->GetBlenderObject();
- int nummeshes = gameobj->GetMeshCount();
- RAS_MeshObject* meshobj = 0;
- if (nummeshes > 0)
- {
- meshobj = gameobj->GetMesh(0);
- }
- int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0;
- BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren);
- }
-
- processCompoundChildren = true;
- // create physics information
- for (i=0;i<sumolist->GetCount();i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) sumolist->GetValue(i);
- struct Object* blenderobject = gameobj->GetBlenderObject();
- int nummeshes = gameobj->GetMeshCount();
- RAS_MeshObject* meshobj = 0;
- if (nummeshes > 0)
- {
- meshobj = gameobj->GetMesh(0);
- }
- int layerMask = (groupobj.find(blenderobject) == groupobj.end()) ? activeLayerBitInfo : 0;
- BL_CreatePhysicsObjectNew(gameobj,blenderobject,meshobj,kxscene,layerMask,converter,processCompoundChildren);
- }
-
- // create physics joints
- for (i=0;i<sumolist->GetCount();i++)
- {
- PHY_IPhysicsEnvironment *physEnv = kxscene->GetPhysicsEnvironment();
- KX_GameObject *gameobj = (KX_GameObject *)sumolist->GetValue(i);
- struct Object *blenderobject = gameobj->GetBlenderObject();
- ListBase *conlist = get_active_constraints2(blenderobject);
- bConstraint *curcon;
-
- if (!conlist)
- continue;
-
- for (curcon = (bConstraint *)conlist->first; curcon; curcon = (bConstraint *)curcon->next) {
- if (curcon->type != CONSTRAINT_TYPE_RIGIDBODYJOINT)
- continue;
-
- bRigidBodyJointConstraint *dat = (bRigidBodyJointConstraint *)curcon->data;
-
- /* Skip if no target or a child object is selected or constraints are deactivated */
- if (!dat->tar || dat->child || (curcon->flag & CONSTRAINT_OFF))
- continue;
-
- /* Store constraints of grouped and instanced objects for all layers */
- gameobj->AddConstraint(dat);
-
- /** if it's during libload we only add constraints in the object but
- * doesn't create it. Constraint will be replicated later in scene->MergeScene
- */
- if (libloading)
- continue;
-
- /* Skipped already converted constraints.
- * This will happen when a group instance is made from a linked group instance
- * and both are on the active layer. */
- if (bl_isConstraintInList(gameobj, convertedlist))
- continue;
-
- KX_GameObject *gotar = getGameOb(dat->tar->id.name + 2, sumolist);
-
- if (gotar && (gotar->GetLayer()&activeLayerBitInfo) && gotar->GetPhysicsController() &&
- (gameobj->GetLayer()&activeLayerBitInfo) && gameobj->GetPhysicsController())
- {
- physEnv->SetupObjectConstraints(gameobj, gotar, dat);
- }
- }
- }
-
- /* cleanup converted set of group objects */
- set<KX_GameObject*>::iterator gobit;
- for (gobit = convertedlist.begin(); gobit != convertedlist.end(); gobit++)
- (*gobit)->Release();
-
- convertedlist.clear();
- sumolist->Release();
-
- // convert world
- KX_WorldInfo* worldinfo = new KX_WorldInfo(blenderscene, blenderscene->world);
- converter->RegisterWorldInfo(worldinfo);
- kxscene->SetWorldInfo(worldinfo);
-
- //create object representations for obstacle simulation
- KX_ObstacleSimulation* obssimulation = kxscene->GetObstacleSimulation();
- if (obssimulation)
- {
- for ( i=0;i<objectlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
- struct Object* blenderobject = gameobj->GetBlenderObject();
- if (blenderobject->gameflag & OB_HASOBSTACLE)
- {
- obssimulation->AddObstacleForObj(gameobj);
- }
- }
- }
-
- //process navigation mesh objects
- for ( i=0; i<objectlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
- struct Object* blenderobject = gameobj->GetBlenderObject();
- if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH))
- {
- KX_NavMeshObject* navmesh = static_cast<KX_NavMeshObject*>(gameobj);
- navmesh->SetVisible(0, true);
- navmesh->BuildNavMesh();
- if (obssimulation)
- obssimulation->AddObstaclesForNavMesh(navmesh);
- }
- }
- for ( i=0; i<inactivelist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(inactivelist->GetValue(i));
- struct Object* blenderobject = gameobj->GetBlenderObject();
- if (blenderobject->type==OB_MESH && (blenderobject->gameflag & OB_NAVMESH))
- {
- KX_NavMeshObject* navmesh = static_cast<KX_NavMeshObject*>(gameobj);
- navmesh->SetVisible(0, true);
- }
- }
-
- // convert logic bricks, sensors, controllers and actuators
- for (i=0;i<logicbrick_conversionlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
- struct Object* blenderobj = gameobj->GetBlenderObject();
- int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
- bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
- BL_ConvertActuators(maggie->name, blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,converter);
- }
- for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
- struct Object* blenderobj = gameobj->GetBlenderObject();
- int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
- bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
- BL_ConvertControllers(blenderobj,gameobj,logicmgr, layerMask,isInActiveLayer,converter, libloading);
- }
- for ( i=0;i<logicbrick_conversionlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(logicbrick_conversionlist->GetValue(i));
- struct Object* blenderobj = gameobj->GetBlenderObject();
- int layerMask = (groupobj.find(blenderobj) == groupobj.end()) ? activeLayerBitInfo : 0;
- bool isInActiveLayer = (blenderobj->lay & layerMask)!=0;
- BL_ConvertSensors(blenderobj,gameobj,logicmgr,kxscene,ketsjiEngine,layerMask,isInActiveLayer,canvas,converter);
- // set the init state to all objects
- gameobj->SetInitState((blenderobj->init_state)?blenderobj->init_state:blenderobj->state);
- }
- // apply the initial state to controllers, only on the active objects as this registers the sensors
- for ( i=0;i<objectlist->GetCount();i++)
- {
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(objectlist->GetValue(i));
- gameobj->ResetState();
- }
-
- logicbrick_conversionlist->Release();
-
- // Calculate the scene btree -
- // too slow - commented out.
- //kxscene->SetNodeTree(tf.MakeTree());
-
- // instantiate dupli group, we will loop trough the object
- // that are in active layers. Note that duplicating group
- // has the effect of adding objects at the end of objectlist.
- // Only loop through the first part of the list.
- int objcount = objectlist->GetCount();
- for (i=0;i<objcount;i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*) objectlist->GetValue(i);
- if (gameobj->IsDupliGroup())
- {
- kxscene->DupliGroupRecurse(gameobj, 0);
- }
- }
-
- KX_Camera *activecam = kxscene->GetActiveCamera();
- MT_Scalar distance = (activecam)? activecam->GetCameraFar() - activecam->GetCameraNear(): 100.0f;
- RAS_BucketManager *bucketmanager = kxscene->GetBucketManager();
- bucketmanager->OptimizeBuckets(distance);
-}
-
diff --git a/source/gameengine/Converter/BL_BlenderDataConversion.h b/source/gameengine/Converter/BL_BlenderDataConversion.h
deleted file mode 100644
index 22210cc6035..00000000000
--- a/source/gameengine/Converter/BL_BlenderDataConversion.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_BlenderDataConversion.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_BLENDERDATACONVERSION_H__
-#define __BL_BLENDERDATACONVERSION_H__
-
-#include "CTR_HashedPtr.h"
-#include "STR_String.h"
-#include "EXP_Python.h"
-#include "KX_PhysicsEngineEnums.h"
-#include "SCA_IInputDevice.h"
-
-class RAS_MeshObject* BL_ConvertMesh(struct Mesh* mesh,struct Object* lightobj,class KX_Scene* scene, class KX_BlenderSceneConverter *converter, bool libloading);
-
-void BL_ConvertBlenderObjects(struct Main* maggie,
- class KX_Scene* kxscene,
- class KX_KetsjiEngine* ketsjiEngine,
- e_PhysicsEngine physics_engine,
- class RAS_IRasterizer* rendertools,
- class RAS_ICanvas* canvas,
- class KX_BlenderSceneConverter* sceneconverter,
- bool alwaysUseExpandFraming,
- bool libloading=false
- );
-
-SCA_IInputDevice::KX_EnumInputs ConvertKeyCode(int key_code);
-
-#endif /* __BL_BLENDERDATACONVERSION_H__ */
diff --git a/source/gameengine/Converter/BL_DeformableGameObject.cpp b/source/gameengine/Converter/BL_DeformableGameObject.cpp
deleted file mode 100644
index 3a4a27a6722..00000000000
--- a/source/gameengine/Converter/BL_DeformableGameObject.cpp
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_DeformableGameObject.cpp
- * \ingroup bgeconv
- */
-
-
-#include "BL_DeformableGameObject.h"
-#include "BL_ShapeDeformer.h"
-#include "BL_ShapeActionActuator.h"
-#include "RAS_MaterialBucket.h"
-
-
-BL_DeformableGameObject::~BL_DeformableGameObject()
-{
- if (m_pDeformer)
- delete m_pDeformer; // __NLA : Temporary until we decide where to put this
-}
-
-void BL_DeformableGameObject::ProcessReplica()
-{
- KX_GameObject::ProcessReplica();
-
- if (m_pDeformer)
- m_pDeformer= (BL_MeshDeformer*)m_pDeformer->GetReplica();
-}
-
-CValue* BL_DeformableGameObject::GetReplica()
-{
-
- BL_DeformableGameObject* replica = new BL_DeformableGameObject(*this);//m_float,GetName());
- replica->ProcessReplica();
- return replica;
-}
-
-bool BL_DeformableGameObject::SetActiveAction(BL_ShapeActionActuator *act, short priority, double curtime)
-{
- if (curtime != m_lastframe) {
- m_activePriority = 9999;
- m_lastframe= curtime;
- m_activeAct = NULL;
- }
-
- if (priority<=m_activePriority)
- {
- if (m_activeAct && (m_activeAct!=act))
- m_activeAct->SetBlendTime(0.0f); /* Reset the blend timer */
- m_activeAct = act;
- m_activePriority = priority;
- m_lastframe = curtime;
-
- return true;
- }
- else {
- act->SetBlendTime(0.0f);
- return false;
- }
-}
-
-bool BL_DeformableGameObject::GetShape(vector<float> &shape)
-{
- shape.clear();
- BL_ShapeDeformer* shape_deformer = dynamic_cast<BL_ShapeDeformer*>(m_pDeformer);
- if (shape_deformer)
- {
- // this check is normally superfluous: a shape deformer can only be created if the mesh
- // has relative keys
- Key* key = shape_deformer->GetKey();
- if (key && key->type==KEY_RELATIVE)
- {
- KeyBlock *kb;
- for (kb = (KeyBlock *)key->block.first; kb; kb = (KeyBlock *)kb->next)
- {
- shape.push_back(kb->curval);
- }
- }
- }
- return !shape.empty();
-}
-
-void BL_DeformableGameObject::SetDeformer(class RAS_Deformer* deformer)
-{
- m_pDeformer = deformer;
-
- SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
- for (mit.begin(); !mit.end(); ++mit)
- {
- (*mit)->SetDeformer(deformer);
- }
-}
-
diff --git a/source/gameengine/Converter/BL_DeformableGameObject.h b/source/gameengine/Converter/BL_DeformableGameObject.h
deleted file mode 100644
index 95e3b7c517d..00000000000
--- a/source/gameengine/Converter/BL_DeformableGameObject.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_DeformableGameObject.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_DEFORMABLEGAMEOBJECT_H__
-#define __BL_DEFORMABLEGAMEOBJECT_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) // get rid of stupid stl-visual compiler debug warning
-#endif
-
-#include "DNA_mesh_types.h"
-#include "KX_GameObject.h"
-#include "BL_MeshDeformer.h"
-#include "KX_SoftBodyDeformer.h"
-#include <vector>
-
-class BL_ShapeActionActuator;
-struct Key;
-
-class BL_DeformableGameObject : public KX_GameObject
-{
-public:
- CValue* GetReplica();
-
- double GetLastFrame ()
- {
- return m_lastframe;
- }
- Object* GetBlendObject()
- {
- return m_blendobj;
- }
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*>*map)
- {
- if (m_pDeformer)
- m_pDeformer->Relink (map);
- KX_GameObject::Relink(map);
- };
- void ProcessReplica();
-
- BL_DeformableGameObject(Object* blendobj, void* sgReplicationInfo, SG_Callbacks callbacks) :
- KX_GameObject(sgReplicationInfo,callbacks),
- m_pDeformer(NULL),
- m_activeAct(NULL),
- m_lastframe(0.0),
- m_blendobj(blendobj),
- m_activePriority(9999)
- {
- m_isDeformable = true;
- };
- virtual ~BL_DeformableGameObject();
- bool SetActiveAction(class BL_ShapeActionActuator *act, short priority, double curtime);
-
- bool GetShape(vector<float> &shape);
-
- virtual void SetDeformer(class RAS_Deformer* deformer);
- virtual class RAS_Deformer* GetDeformer()
- {
- return m_pDeformer;
- }
-
-public:
-
-protected:
-
- RAS_Deformer *m_pDeformer;
-
- class BL_ShapeActionActuator *m_activeAct;
- double m_lastframe;
- Object* m_blendobj;
- short m_activePriority;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_DeformableGameObject")
-#endif
-};
-
-#endif /* __BL_DEFORMABLEGAMEOBJECT_H__ */
diff --git a/source/gameengine/Converter/BL_MeshDeformer.cpp b/source/gameengine/Converter/BL_MeshDeformer.cpp
deleted file mode 100644
index 911ff245ab4..00000000000
--- a/source/gameengine/Converter/BL_MeshDeformer.cpp
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Simple deformation controller that restores a mesh to its rest position
- */
-
-/** \file gameengine/Converter/BL_MeshDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning( disable:4786 )
-#endif
-
-#include "RAS_IPolygonMaterial.h"
-#include "BL_DeformableGameObject.h"
-#include "BL_MeshDeformer.h"
-#include "RAS_MeshObject.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "BLI_math.h"
-
-bool BL_MeshDeformer::Apply(RAS_IPolyMaterial*)
-{
- size_t i;
-
- // only apply once per frame if the mesh is actually modified
- if (m_pMeshObject->MeshModified() &&
- m_lastDeformUpdate != m_gameobj->GetLastFrame())
- {
- // For each material
- for (list<RAS_MeshMaterial>::iterator mit= m_pMeshObject->GetFirstMaterial();
- mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- if (!mit->m_slots[(void*)m_gameobj])
- continue;
-
- RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
- RAS_MeshSlot::iterator it;
-
- // for each array
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- // For each vertex
- for (i=it.startvertex; i<it.endvertex; i++) {
- RAS_TexVert& v = it.vertex[i];
- v.SetXYZ(m_bmesh->mvert[v.getOrigIndex()].co);
- }
- }
- }
-
- m_lastDeformUpdate = m_gameobj->GetLastFrame();
-
- return true;
- }
-
- return false;
-}
-
-BL_MeshDeformer::~BL_MeshDeformer()
-{
- if (m_transverts)
- delete [] m_transverts;
- if (m_transnors)
- delete [] m_transnors;
-}
-
-void BL_MeshDeformer::ProcessReplica()
-{
- m_transverts = NULL;
- m_transnors = NULL;
- m_tvtot = 0;
- m_bDynamic=false;
- m_lastDeformUpdate = -1;
-}
-
-void BL_MeshDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*map)
-{
- void **h_obj = (*map)[m_gameobj];
-
- if (h_obj)
- m_gameobj = (BL_DeformableGameObject*)(*h_obj);
- else
- m_gameobj = NULL;
-}
-
-/**
- * \warning This function is expensive!
- */
-void BL_MeshDeformer::RecalcNormals()
-{
- /* We don't normalize for performance, not doing it for faces normals
- * gives area-weight normals which often look better anyway, and use
- * GL_NORMALIZE so we don't have to do per vertex normalization either
- * since the GPU can do it faster */
- list<RAS_MeshMaterial>::iterator mit;
- RAS_MeshSlot::iterator it;
- size_t i;
-
- /* set vertex normals to zero */
- memset(m_transnors, 0, sizeof(float)*3*m_bmesh->totvert);
-
- /* add face normals to vertices. */
- for (mit = m_pMeshObject->GetFirstMaterial();
- mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- if (!mit->m_slots[(void*)m_gameobj])
- continue;
-
- RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
-
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- int nvert = (int)it.array->m_type;
-
- for (i=0; i<it.totindex; i+=nvert) {
- RAS_TexVert& v1 = it.vertex[it.index[i]];
- RAS_TexVert& v2 = it.vertex[it.index[i+1]];
- RAS_TexVert& v3 = it.vertex[it.index[i+2]];
- RAS_TexVert *v4 = NULL;
-
- const float *co1 = m_transverts[v1.getOrigIndex()];
- const float *co2 = m_transverts[v2.getOrigIndex()];
- const float *co3 = m_transverts[v3.getOrigIndex()];
- const float *co4 = NULL;
-
- /* compute face normal */
- float fnor[3], n1[3], n2[3];
-
- if (nvert == 4) {
- v4 = &it.vertex[it.index[i+3]];
- co4 = m_transverts[v4->getOrigIndex()];
-
- n1[0] = co1[0] - co3[0];
- n1[1] = co1[1] - co3[1];
- n1[2] = co1[2] - co3[2];
-
- n2[0] = co2[0] - co4[0];
- n2[1] = co2[1] - co4[1];
- n2[2] = co2[2] - co4[2];
- }
- else {
- n1[0] = co1[0] - co2[0];
- n2[0] = co2[0] - co3[0];
- n1[1] = co1[1] - co2[1];
-
- n2[1] = co2[1] - co3[1];
- n1[2] = co1[2] - co2[2];
- n2[2] = co2[2] - co3[2];
- }
-
- fnor[0] = n1[1] * n2[2] - n1[2] * n2[1];
- fnor[1] = n1[2] * n2[0] - n1[0] * n2[2];
- fnor[2] = n1[0] * n2[1] - n1[1] * n2[0];
- normalize_v3(fnor);
-
- /* add to vertices for smooth normals */
- float *vn1 = m_transnors[v1.getOrigIndex()];
- float *vn2 = m_transnors[v2.getOrigIndex()];
- float *vn3 = m_transnors[v3.getOrigIndex()];
-
- vn1[0] += fnor[0]; vn1[1] += fnor[1]; vn1[2] += fnor[2];
- vn2[0] += fnor[0]; vn2[1] += fnor[1]; vn2[2] += fnor[2];
- vn3[0] += fnor[0]; vn3[1] += fnor[1]; vn3[2] += fnor[2];
-
- if (v4) {
- float *vn4 = m_transnors[v4->getOrigIndex()];
- vn4[0] += fnor[0]; vn4[1] += fnor[1]; vn4[2] += fnor[2];
- }
-
- /* in case of flat - just assign, the vertices are split */
- if (v1.getFlag() & RAS_TexVert::FLAT) {
- v1.SetNormal(fnor);
- v2.SetNormal(fnor);
- v3.SetNormal(fnor);
- if (v4)
- v4->SetNormal(fnor);
- }
- }
- }
- }
-
- /* assign smooth vertex normals */
- for (mit = m_pMeshObject->GetFirstMaterial();
- mit != m_pMeshObject->GetLastMaterial(); ++ mit) {
- if (!mit->m_slots[(void*)m_gameobj])
- continue;
-
- RAS_MeshSlot *slot = *mit->m_slots[(void*)m_gameobj];
-
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- for (i=it.startvertex; i<it.endvertex; i++) {
- RAS_TexVert& v = it.vertex[i];
-
- if (!(v.getFlag() & RAS_TexVert::FLAT))
- v.SetNormal(m_transnors[v.getOrigIndex()]); //.safe_normalized()
- }
- }
- }
-}
-
-void BL_MeshDeformer::VerifyStorage()
-{
- /* Ensure that we have the right number of verts assigned */
- if (m_tvtot!=m_bmesh->totvert) {
- if (m_transverts)
- delete [] m_transverts;
- if (m_transnors)
- delete [] m_transnors;
-
- m_transverts=new float[m_bmesh->totvert][3];
- m_transnors=new float[m_bmesh->totvert][3];
- m_tvtot = m_bmesh->totvert;
- }
-}
-
diff --git a/source/gameengine/Converter/BL_MeshDeformer.h b/source/gameengine/Converter/BL_MeshDeformer.h
deleted file mode 100644
index 6e84cdf03f8..00000000000
--- a/source/gameengine/Converter/BL_MeshDeformer.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_MeshDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_MESHDEFORMER_H__
-#define __BL_MESHDEFORMER_H__
-
-#include "RAS_Deformer.h"
-#include "DNA_object_types.h"
-#include "DNA_key_types.h"
-#include "MT_Point3.h"
-#include <stdlib.h>
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-class BL_DeformableGameObject;
-
-class BL_MeshDeformer : public RAS_Deformer
-{
-public:
- void VerifyStorage();
- void RecalcNormals();
- virtual void Relink(CTR_Map<class CTR_HashedPtr, void*>*map);
- BL_MeshDeformer(BL_DeformableGameObject *gameobj,
- struct Object* obj,
- class RAS_MeshObject *meshobj ):
- m_pMeshObject(meshobj),
- m_bmesh((struct Mesh*)(obj->data)),
- m_transverts(0),
- m_transnors(0),
- m_objMesh(obj),
- m_tvtot(0),
- m_gameobj(gameobj),
- m_lastDeformUpdate(-1)
- {};
- virtual ~BL_MeshDeformer();
- virtual void SetSimulatedTime(double time) {}
- virtual bool Apply(class RAS_IPolyMaterial *mat);
- virtual bool Update(void) { return false; }
- virtual bool UpdateBuckets(void) { return false; }
- virtual RAS_Deformer* GetReplica() {return NULL;}
- virtual void ProcessReplica();
- struct Mesh* GetMesh() { return m_bmesh; }
- virtual class RAS_MeshObject* GetRasMesh() { return m_pMeshObject; }
- virtual float (* GetTransVerts(int *tot))[3] { *tot= m_tvtot; return m_transverts; }
- // virtual void InitDeform(double time) {}
-
-protected:
- class RAS_MeshObject* m_pMeshObject;
- struct Mesh* m_bmesh;
-
- // this is so m_transverts doesn't need to be converted
- // before deformation
- float (*m_transverts)[3];
- float (*m_transnors)[3];
- struct Object* m_objMesh;
- // --
- int m_tvtot;
- BL_DeformableGameObject* m_gameobj;
- double m_lastDeformUpdate;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_MeshDeformer")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Converter/BL_ModifierDeformer.cpp b/source/gameengine/Converter/BL_ModifierDeformer.cpp
deleted file mode 100644
index b40fb7a9f47..00000000000
--- a/source/gameengine/Converter/BL_ModifierDeformer.cpp
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ModifierDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "MEM_guardedalloc.h"
-#include "BL_ModifierDeformer.h"
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_MeshObject.h"
-#include "PHY_IGraphicController.h"
-
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_key_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_modifier_types.h"
-#include "DNA_scene_types.h"
-#include "BLI_utildefines.h"
-#include "BKE_armature.h"
-#include "BKE_action.h"
-#include "BKE_key.h"
-#include "BKE_ipo.h"
-#include "MT_Point3.h"
-
-extern "C"{
- #include "BKE_customdata.h"
- #include "BKE_DerivedMesh.h"
- #include "BKE_lattice.h"
- #include "BKE_modifier.h"
-}
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-BL_ModifierDeformer::~BL_ModifierDeformer()
-{
- if (m_dm) {
- // deformedOnly is used as a user counter
- if (--m_dm->deformedOnly == 0) {
- m_dm->needsFree = 1;
- m_dm->release(m_dm);
- }
- }
-};
-
-RAS_Deformer *BL_ModifierDeformer::GetReplica()
-{
- BL_ModifierDeformer *result;
-
- result = new BL_ModifierDeformer(*this);
- result->ProcessReplica();
- return result;
-}
-
-void BL_ModifierDeformer::ProcessReplica()
-{
- /* Note! - This is not inherited from PyObjectPlus */
- BL_ShapeDeformer::ProcessReplica();
- if (m_dm)
- // by default try to reuse mesh, deformedOnly is used as a user count
- m_dm->deformedOnly++;
- // this will force an update and if the mesh cannot be reused, a new one will be created
- m_lastModifierUpdate = -1;
-}
-
-bool BL_ModifierDeformer::HasCompatibleDeformer(Object *ob)
-{
- if (!ob->modifiers.first)
- return false;
- // soft body cannot use mesh modifiers
- if ((ob->gameflag & OB_SOFT_BODY) != 0)
- return false;
- ModifierData* md;
- for (md = (ModifierData *)ob->modifiers.first; md; md = md->next) {
- if (modifier_dependsOnTime(md))
- continue;
- if (!(md->mode & eModifierMode_Realtime))
- continue;
- /* armature modifier are handled by SkinDeformer, not ModifierDeformer */
- if (md->type == eModifierType_Armature )
- continue;
- return true;
- }
- return false;
-}
-
-bool BL_ModifierDeformer::HasArmatureDeformer(Object *ob)
-{
- if (!ob->modifiers.first)
- return false;
-
- ModifierData* md = (ModifierData*)ob->modifiers.first;
- if (md->type == eModifierType_Armature )
- return true;
-
- return false;
-}
-
-// return a deformed mesh that supports mapping (with a valid CD_ORIGINDEX layer)
-struct DerivedMesh* BL_ModifierDeformer::GetPhysicsMesh()
-{
- /* we need to compute the deformed mesh taking into account the current
- * shape and skin deformers, we cannot just call mesh_create_derived_physics()
- * because that would use the m_transvers already deformed previously by BL_ModifierDeformer::Update(),
- * so restart from scratch by forcing a full update the shape/skin deformers
- * (will do nothing if there is no such deformer) */
- BL_ShapeDeformer::ForceUpdate();
- BL_ShapeDeformer::Update();
- // now apply the modifiers but without those that don't support mapping
- Object* blendobj = m_gameobj->GetBlendObject();
- /* hack: the modifiers require that the mesh is attached to the object
- * It may not be the case here because of replace mesh actuator */
- Mesh *oldmesh = (Mesh*)blendobj->data;
- blendobj->data = m_bmesh;
- DerivedMesh *dm = mesh_create_derived_physics(m_scene, blendobj, m_transverts, CD_MASK_MESH);
- /* restore object data */
- blendobj->data = oldmesh;
- /* m_transverts is correct here (takes into account deform only modifiers) */
- /* the derived mesh returned by this function must be released by the caller !!! */
- return dm;
-}
-
-bool BL_ModifierDeformer::Update(void)
-{
- bool bShapeUpdate = BL_ShapeDeformer::Update();
-
- if (bShapeUpdate || m_lastModifierUpdate != m_gameobj->GetLastFrame()) {
- // static derived mesh are not updated
- if (m_dm == NULL || m_bDynamic) {
- /* execute the modifiers */
- Object* blendobj = m_gameobj->GetBlendObject();
- /* hack: the modifiers require that the mesh is attached to the object
- * It may not be the case here because of replace mesh actuator */
- Mesh *oldmesh = (Mesh*)blendobj->data;
- blendobj->data = m_bmesh;
- /* execute the modifiers */
- DerivedMesh *dm = mesh_create_derived_no_virtual(m_scene, blendobj, m_transverts, CD_MASK_MESH);
- /* restore object data */
- blendobj->data = oldmesh;
- /* free the current derived mesh and replace, (dm should never be NULL) */
- if (m_dm != NULL) {
- // HACK! use deformedOnly as a user counter
- if (--m_dm->deformedOnly == 0) {
- m_dm->needsFree = 1;
- m_dm->release(m_dm);
- }
- }
- m_dm = dm;
- // get rid of temporary data
- m_dm->needsFree = 0;
- m_dm->release(m_dm);
- // HACK! use deformedOnly as a user counter
- m_dm->deformedOnly = 1;
- DM_update_materials(m_dm, blendobj);
- /* update the graphic controller */
- PHY_IGraphicController *ctrl = m_gameobj->GetGraphicController();
- if (ctrl) {
- float min[3], max[3];
- INIT_MINMAX(min, max);
- m_dm->getMinMax(m_dm, min, max);
- ctrl->SetLocalAabb(min, max);
- }
- }
- m_lastModifierUpdate=m_gameobj->GetLastFrame();
- bShapeUpdate = true;
-
- int nmat = m_pMeshObject->NumMaterials();
- for (int imat=0; imat<nmat; imat++) {
- RAS_MeshMaterial *mmat = m_pMeshObject->GetMeshMaterial(imat);
- RAS_MeshSlot **slot = mmat->m_slots[(void*)m_gameobj];
- if (!slot || !*slot)
- continue;
- (*slot)->m_pDerivedMesh = m_dm;
- }
- }
- return bShapeUpdate;
-}
-
-bool BL_ModifierDeformer::Apply(RAS_IPolyMaterial *mat)
-{
- if (!Update())
- return false;
-
- return true;
-}
diff --git a/source/gameengine/Converter/BL_ModifierDeformer.h b/source/gameengine/Converter/BL_ModifierDeformer.h
deleted file mode 100644
index 4efe4ca5bfc..00000000000
--- a/source/gameengine/Converter/BL_ModifierDeformer.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ModifierDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_MODIFIERDEFORMER_H__
-#define __BL_MODIFIERDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-#include "BL_ShapeDeformer.h"
-#include "BL_DeformableGameObject.h"
-#include <vector>
-
-struct DerivedMesh;
-struct Object;
-
-class BL_ModifierDeformer : public BL_ShapeDeformer
-{
-public:
- static bool HasCompatibleDeformer(Object *ob);
- static bool HasArmatureDeformer(Object *ob);
-
-
- BL_ModifierDeformer(BL_DeformableGameObject *gameobj,
- Scene *scene,
- Object *bmeshobj,
- RAS_MeshObject *mesh)
- :
- BL_ShapeDeformer(gameobj,bmeshobj, mesh),
- m_lastModifierUpdate(-1),
- m_scene(scene),
- m_dm(NULL)
- {
- m_recalcNormal = false;
- }
-
- /* this second constructor is needed for making a mesh deformable on the fly. */
- BL_ModifierDeformer(BL_DeformableGameObject *gameobj,
- struct Scene *scene,
- struct Object *bmeshobj_old,
- struct Object *bmeshobj_new,
- class RAS_MeshObject *mesh,
- bool release_object,
- BL_ArmatureObject* arma = NULL)
- :
- BL_ShapeDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, false, arma),
- m_lastModifierUpdate(-1),
- m_scene(scene),
- m_dm(NULL)
- {
- /* pass */
- }
-
- virtual void ProcessReplica();
- virtual RAS_Deformer *GetReplica();
- virtual ~BL_ModifierDeformer();
- virtual bool UseVertexArray()
- {
- return false;
- }
-
- bool Update (void);
- bool Apply(RAS_IPolyMaterial *mat);
- void ForceUpdate()
- {
- m_lastModifierUpdate = -1.0;
- };
- virtual struct DerivedMesh* GetFinalMesh()
- {
- return m_dm;
- }
- // The derived mesh returned by this function must be released!
- virtual struct DerivedMesh* GetPhysicsMesh();
-
-protected:
- double m_lastModifierUpdate;
- Scene *m_scene;
- DerivedMesh *m_dm;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ModifierDeformer")
-#endif
-};
-
-#endif /* __BL_MODIFIERDEFORMER_H__ */
diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.cpp b/source/gameengine/Converter/BL_ShapeActionActuator.cpp
deleted file mode 100644
index f21db419ebc..00000000000
--- a/source/gameengine/Converter/BL_ShapeActionActuator.cpp
+++ /dev/null
@@ -1,563 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ShapeActionActuator.cpp
- * \ingroup bgeconv
- */
-
-
-#include <cmath>
-
-#include "SCA_LogicManager.h"
-#include "BL_ShapeActionActuator.h"
-#include "BL_ShapeDeformer.h"
-#include "KX_GameObject.h"
-#include "STR_HashedString.h"
-#include "DNA_nla_types.h"
-#include "DNA_action_types.h"
-#include "DNA_anim_types.h"
-#include "DNA_scene_types.h"
-#include "BKE_action.h"
-#include "DNA_armature_types.h"
-#include "MEM_guardedalloc.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "MT_Matrix4x4.h"
-
-#include "EXP_FloatValue.h"
-#include "EXP_PyObjectPlus.h"
-
-extern "C" {
- #include "BKE_animsys.h"
- #include "BKE_key.h"
- #include "RNA_access.h"
-}
-
-BL_ShapeActionActuator::BL_ShapeActionActuator(SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blendin,
- short priority,
- float stride)
- : SCA_IActuator(gameobj, KX_ACT_SHAPEACTION),
-
- m_lastpos(0, 0, 0),
- m_blendframe(0),
- m_flag(0),
- m_startframe (starttime),
- m_endframe(endtime) ,
- m_starttime(0),
- m_localtime(starttime),
- m_lastUpdate(-1),
- m_blendin(blendin),
- m_blendstart(0),
- m_stridelength(stride),
- m_playtype(playtype),
- m_priority(priority),
- m_action(action),
- m_framepropname(framepropname),
- m_propname(propname)
-{
- m_idptr = new PointerRNA();
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent();
- BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
- RNA_id_pointer_create(&shape_deformer->GetKey()->id, m_idptr);
-};
-
-BL_ShapeActionActuator::~BL_ShapeActionActuator()
-{
- if (m_idptr)
- delete m_idptr;
-}
-
-void BL_ShapeActionActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
- m_localtime=m_startframe;
- m_lastUpdate=-1;
-}
-
-void BL_ShapeActionActuator::SetBlendTime(float newtime)
-{
- m_blendframe = newtime;
-}
-
-CValue* BL_ShapeActionActuator::GetReplica()
-{
- BL_ShapeActionActuator* replica = new BL_ShapeActionActuator(*this);//m_float,GetName());
- replica->ProcessReplica();
- return replica;
-}
-
-bool BL_ShapeActionActuator::ClampLocalTime()
-{
- if (m_startframe < m_endframe) {
- if (m_localtime < m_startframe)
- {
- m_localtime = m_startframe;
- return true;
- }
- else if (m_localtime > m_endframe)
- {
- m_localtime = m_endframe;
- return true;
- }
- } else {
- if (m_localtime > m_startframe)
- {
- m_localtime = m_startframe;
- return true;
- }
- else if (m_localtime < m_endframe)
- {
- m_localtime = m_endframe;
- return true;
- }
- }
- return false;
-}
-
-void BL_ShapeActionActuator::SetStartTime(float curtime)
-{
- float direction = m_startframe < m_endframe ? 1.0 : -1.0;
-
- if (!(m_flag & ACT_FLAG_REVERSE))
- m_starttime = curtime - direction*(m_localtime - m_startframe)/KX_KetsjiEngine::GetAnimFrameRate();
- else
- m_starttime = curtime - direction*(m_endframe - m_localtime)/KX_KetsjiEngine::GetAnimFrameRate();
-}
-
-void BL_ShapeActionActuator::SetLocalTime(float curtime)
-{
- float delta_time = (curtime - m_starttime)*KX_KetsjiEngine::GetAnimFrameRate();
-
- if (m_endframe < m_startframe)
- delta_time = -delta_time;
-
- if (!(m_flag & ACT_FLAG_REVERSE))
- m_localtime = m_startframe + delta_time;
- else
- m_localtime = m_endframe - delta_time;
-}
-
-void BL_ShapeActionActuator::BlendShape(Key* key, float srcweight)
-{
- vector<float>::const_iterator it;
- float dstweight;
- KeyBlock *kb;
-
- dstweight = 1.0F - srcweight;
-
- for (it=m_blendshape.begin(), kb = (KeyBlock *)key->block.first;
- kb && it != m_blendshape.end();
- kb = (KeyBlock *)kb->next, it++)
- {
- kb->curval = kb->curval * dstweight + (*it) * srcweight;
- }
-}
-
-bool BL_ShapeActionActuator::Update(double curtime, bool frame)
-{
- bool bNegativeEvent = false;
- bool bPositiveEvent = false;
- bool keepgoing = true;
- bool wrap = false;
- bool apply=true;
- int priority;
- float newweight;
-
- curtime -= KX_KetsjiEngine::GetSuspendedDelta();
-
- // result = true if animation has to be continued, false if animation stops
- // maybe there are events for us in the queue !
- if (frame)
- {
- bNegativeEvent = m_negevent;
- bPositiveEvent = m_posevent;
- RemoveAllEvents();
-
- if (bPositiveEvent)
- m_flag |= ACT_FLAG_ACTIVE;
-
- if (bNegativeEvent)
- {
- if (!(m_flag & ACT_FLAG_ACTIVE))
- return false;
- m_flag &= ~ACT_FLAG_ACTIVE;
- }
- }
-
- /* This action can only be attached to a deform object */
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)GetParent();
- float length = m_endframe - m_startframe;
-
- priority = m_priority;
-
- /* Determine pre-incrementation behavior and set appropriate flags */
- switch (m_playtype) {
- case ACT_ACTION_MOTION:
- if (bNegativeEvent) {
- keepgoing=false;
- apply=false;
- };
- break;
- case ACT_ACTION_FROM_PROP:
- if (bNegativeEvent) {
- apply=false;
- keepgoing=false;
- }
- break;
- case ACT_ACTION_LOOP_END:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_KEYUP;
- m_flag &= ~ACT_FLAG_REVERSE;
- m_flag |= ACT_FLAG_LOCKINPUT;
- m_localtime = m_startframe;
- m_starttime = curtime;
- }
- }
- if (bNegativeEvent) {
- m_flag |= ACT_FLAG_KEYUP;
- }
- break;
- case ACT_ACTION_LOOP_STOP:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_REVERSE;
- m_flag &= ~ACT_FLAG_KEYUP;
- m_flag |= ACT_FLAG_LOCKINPUT;
- SetStartTime(curtime);
- }
- }
- if (bNegativeEvent) {
- m_flag |= ACT_FLAG_KEYUP;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- keepgoing=false;
- apply=false;
- }
- break;
- case ACT_ACTION_PINGPONG:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_KEYUP;
- m_localtime = m_starttime;
- m_starttime = curtime;
- m_flag |= ACT_FLAG_LOCKINPUT;
- }
- }
- break;
- case ACT_ACTION_FLIPPER:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_REVERSE;
- m_flag |= ACT_FLAG_LOCKINPUT;
- SetStartTime(curtime);
- }
- }
- else if (bNegativeEvent) {
- m_flag |= ACT_FLAG_REVERSE;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- SetStartTime(curtime);
- }
- break;
- case ACT_ACTION_PLAY:
- if (bPositiveEvent) {
- if (!(m_flag & ACT_FLAG_LOCKINPUT)) {
- m_flag &= ~ACT_FLAG_REVERSE;
- m_localtime = m_starttime;
- m_starttime = curtime;
- m_flag |= ACT_FLAG_LOCKINPUT;
- }
- }
- break;
- default:
- break;
- }
-
- /* Perform increment */
- if (keepgoing) {
- if (m_playtype == ACT_ACTION_MOTION) {
- MT_Point3 newpos;
- MT_Point3 deltapos;
-
- newpos = obj->NodeGetWorldPosition();
-
- /* Find displacement */
- deltapos = newpos-m_lastpos;
- m_localtime += (length/m_stridelength) * deltapos.length();
- m_lastpos = newpos;
- }
- else {
- SetLocalTime(curtime);
- }
- }
-
- /* Check if a wrapping response is needed */
- if (length) {
- if (m_localtime < m_startframe || m_localtime > m_endframe)
- {
- m_localtime = m_startframe + fmod(m_localtime, length);
- wrap = true;
- }
- }
- else
- m_localtime = m_startframe;
-
- /* Perform post-increment tasks */
- switch (m_playtype) {
- case ACT_ACTION_FROM_PROP:
- {
- CValue* propval = GetParent()->GetProperty(m_propname);
- if (propval)
- m_localtime = propval->GetNumber();
-
- if (bNegativeEvent) {
- keepgoing=false;
- }
- }
- break;
- case ACT_ACTION_MOTION:
- break;
- case ACT_ACTION_LOOP_STOP:
- break;
- case ACT_ACTION_PINGPONG:
- if (wrap) {
- if (!(m_flag & ACT_FLAG_REVERSE))
- m_localtime = m_endframe;
- else
- m_localtime = m_startframe;
-
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- m_flag ^= ACT_FLAG_REVERSE; //flip direction
- keepgoing = false;
- }
- break;
- case ACT_ACTION_FLIPPER:
- if (wrap) {
- if (!(m_flag & ACT_FLAG_REVERSE)) {
- m_localtime=m_endframe;
- //keepgoing = false;
- }
- else {
- m_localtime=m_startframe;
- keepgoing = false;
- }
- }
- break;
- case ACT_ACTION_LOOP_END:
- if (wrap) {
- if (m_flag & ACT_FLAG_KEYUP) {
- keepgoing = false;
- m_localtime = m_endframe;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- }
- SetStartTime(curtime);
- }
- break;
- case ACT_ACTION_PLAY:
- if (wrap) {
- m_localtime = m_endframe;
- keepgoing = false;
- m_flag &= ~ACT_FLAG_LOCKINPUT;
- }
- break;
- default:
- keepgoing = false;
- break;
- }
-
- /* Set the property if its defined */
- if (m_framepropname[0] != '\0') {
- CValue* propowner = GetParent();
- CValue* oldprop = propowner->GetProperty(m_framepropname);
- CValue* newval = new CFloatValue(m_localtime);
- if (oldprop) {
- oldprop->SetValue(newval);
- } else {
- propowner->SetProperty(m_framepropname, newval);
- }
- newval->Release();
- }
-
- if (bNegativeEvent)
- m_blendframe=0.0f;
-
- /* Apply the pose if necessary*/
- if (apply) {
-
- /* Priority test */
- if (obj->SetActiveAction(this, priority, curtime)) {
- BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
- Key *key = NULL;
-
- if (shape_deformer)
- key = shape_deformer->GetKey();
-
- if (!key) {
- // this could happen if the mesh was changed in the middle of an action
- // and the new mesh has no key, stop the action
- keepgoing = false;
- }
- else {
- ListBase tchanbase= {NULL, NULL};
-
- if (m_blendin && m_blendframe==0.0f) {
- // this is the start of the blending, remember the startup shape
- obj->GetShape(m_blendshape);
- m_blendstart = curtime;
- }
-
- KeyBlock *kb;
- // We go through and clear out the keyblocks so there isn't any interference
- // from other shape actions
- for (kb=(KeyBlock *)key->block.first; kb; kb=(KeyBlock *)kb->next)
- kb->curval = 0.f;
-
- animsys_evaluate_action(m_idptr, m_action, NULL, m_localtime);
-
- // XXX - in 2.5 theres no way to do this. possibly not that important to support - Campbell
- if (0) { // XXX !execute_ipochannels(&tchanbase)) {
- // no update, this is possible if action does not match the keys, stop the action
- keepgoing = false;
- }
- else {
- // the key have changed, apply blending if needed
- if (m_blendin && (m_blendframe<m_blendin)) {
- newweight = (m_blendframe/(float)m_blendin);
-
- BlendShape(key, 1.0f - newweight);
-
- /* Increment current blending percentage */
- m_blendframe = (curtime - m_blendstart)*KX_KetsjiEngine::GetAnimFrameRate();
- if (m_blendframe>m_blendin)
- m_blendframe = m_blendin;
- }
- m_lastUpdate = m_localtime;
- }
- BLI_freelistN(&tchanbase);
- }
- }
- else {
- m_blendframe = 0.0f;
- }
- }
-
- if (!keepgoing) {
- m_blendframe = 0.0f;
- }
- return keepgoing;
-};
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-
-PyTypeObject BL_ShapeActionActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_ShapeActionActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-
-PyMethodDef BL_ShapeActionActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef BL_ShapeActionActuator::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RW("frameStart", 0, MAXFRAMEF, BL_ShapeActionActuator, m_startframe),
- KX_PYATTRIBUTE_FLOAT_RW("frameEnd", 0, MAXFRAMEF, BL_ShapeActionActuator, m_endframe),
- KX_PYATTRIBUTE_FLOAT_RW("blendIn", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendin),
- KX_PYATTRIBUTE_RW_FUNCTION("action", BL_ShapeActionActuator, pyattr_get_action, pyattr_set_action),
- KX_PYATTRIBUTE_SHORT_RW("priority", 0, 100, false, BL_ShapeActionActuator, m_priority),
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("frame", 0, MAXFRAMEF, BL_ShapeActionActuator, m_localtime, CheckFrame),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_propname),
- KX_PYATTRIBUTE_STRING_RW("framePropName", 0, MAX_PROP_NAME, false, BL_ShapeActionActuator, m_framepropname),
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("blendTime", 0, MAXFRAMEF, BL_ShapeActionActuator, m_blendframe, CheckBlendTime),
- KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",0,100,false,BL_ShapeActionActuator,m_playtype,CheckType),
- { NULL } //Sentinel
-};
-
-PyObject *BL_ShapeActionActuator::pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- BL_ShapeActionActuator* self = static_cast<BL_ShapeActionActuator*>(self_v);
- return PyUnicode_FromString(self->GetAction() ? self->GetAction()->id.name+2 : "");
-}
-
-int BL_ShapeActionActuator::pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- BL_ShapeActionActuator* self = static_cast<BL_ShapeActionActuator*>(self_v);
- /* exact copy of BL_ActionActuator's function from here down */
- if (!PyUnicode_Check(value))
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, expected the string name of the action");
- return PY_SET_ATTR_FAIL;
- }
-
- bAction *action= NULL;
- STR_String val = _PyUnicode_AsString(value);
-
- if (val != "")
- {
- action= (bAction*)self->GetLogicManager()->GetActionByName(val);
- if (action==NULL)
- {
- PyErr_SetString(PyExc_ValueError, "actuator.action = val: Shape Action Actuator, action not found!");
- return PY_SET_ATTR_FAIL;
- }
- }
-
- self->SetAction(action);
- return PY_SET_ATTR_SUCCESS;
-
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/BL_ShapeActionActuator.h b/source/gameengine/Converter/BL_ShapeActionActuator.h
deleted file mode 100644
index e96d0e0ebb4..00000000000
--- a/source/gameengine/Converter/BL_ShapeActionActuator.h
+++ /dev/null
@@ -1,144 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ShapeActionActuator.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_SHAPEACTIONACTUATOR_H__
-#define __BL_SHAPEACTIONACTUATOR_H__
-
-#include "CTR_HashedPtr.h"
-#include "SCA_IActuator.h"
-#include "BL_ActionActuator.h"
-#include "MT_Point3.h"
-#include <vector>
-
-struct Key;
-class BL_ShapeActionActuator : public SCA_IActuator
-{
-public:
- Py_Header
- BL_ShapeActionActuator(SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& framepropname,
- float starttime,
- float endtime,
- struct bAction *action,
- short playtype,
- short blendin,
- short priority,
- float stride);
- virtual ~BL_ShapeActionActuator();
- virtual bool Update(double curtime, bool frame);
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
-
- void SetBlendTime (float newtime);
- void BlendShape(struct Key* key, float weight);
-
- bAction* GetAction() { return m_action; }
- void SetAction(bAction* act) { m_action= act; }
-
-#ifdef WITH_PYTHON
-
- static PyObject* pyattr_get_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_action(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static int CheckBlendTime(void *self, const PyAttributeDef*)
- {
- BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
-
- if (act->m_blendframe > act->m_blendin)
- act->m_blendframe = act->m_blendin;
-
- return 0;
- }
- static int CheckFrame(void *self, const PyAttributeDef*)
- {
- BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
-
- if (act->m_localtime < act->m_startframe)
- act->m_localtime = act->m_startframe;
- else if (act->m_localtime > act->m_endframe)
- act->m_localtime = act->m_endframe;
-
- return 0;
- }
- static int CheckType(void *self, const PyAttributeDef*)
- {
- BL_ShapeActionActuator* act = reinterpret_cast<BL_ShapeActionActuator*>(self);
-
- switch (act->m_playtype) {
- case ACT_ACTION_PLAY:
- case ACT_ACTION_PINGPONG:
- case ACT_ACTION_FLIPPER:
- case ACT_ACTION_LOOP_STOP:
- case ACT_ACTION_LOOP_END:
- case ACT_ACTION_FROM_PROP:
- return 0;
- default:
- PyErr_SetString(PyExc_ValueError, "Shape Action Actuator, invalid play type supplied");
- return 1;
- }
-
- }
-
-#endif /* WITH_PYTHON */
-
-protected:
-
- void SetStartTime(float curtime);
- void SetLocalTime(float curtime);
- bool ClampLocalTime();
-
- MT_Point3 m_lastpos;
- float m_blendframe;
- int m_flag;
- /** The frame this action starts */
- float m_startframe;
- /** The frame this action ends */
- float m_endframe;
- /** The time this action started */
- float m_starttime;
- /** The current time of the action */
- float m_localtime;
-
- float m_lastUpdate;
- float m_blendin;
- float m_blendstart;
- float m_stridelength;
- short m_playtype;
- short m_priority;
- struct bAction *m_action;
- STR_String m_framepropname;
- STR_String m_propname;
- vector<float> m_blendshape;
- struct PointerRNA *m_idptr;
-};
-
-#endif /* __BL_SHAPEACTIONACTUATOR_H__ */
diff --git a/source/gameengine/Converter/BL_ShapeDeformer.cpp b/source/gameengine/Converter/BL_ShapeDeformer.cpp
deleted file mode 100644
index 94256a64d75..00000000000
--- a/source/gameengine/Converter/BL_ShapeDeformer.cpp
+++ /dev/null
@@ -1,237 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_ShapeDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "MEM_guardedalloc.h"
-#include "BL_ShapeDeformer.h"
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_MeshObject.h"
-
-#include "DNA_anim_types.h"
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_key_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "BKE_armature.h"
-#include "BKE_action.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_key.h"
-#include "BKE_fcurve.h"
-#include "BKE_ipo.h"
-#include "BKE_library.h"
-#include "MT_Point3.h"
-
-extern "C"{
- #include "BKE_lattice.h"
- #include "BKE_animsys.h"
-}
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-#define __NLA_DEFNORMALS
-//#undef __NLA_DEFNORMALS
-
-BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- Object *bmeshobj,
- RAS_MeshObject *mesh)
- :
- BL_SkinDeformer(gameobj,bmeshobj, mesh),
- m_useShapeDrivers(false),
- m_lastShapeUpdate(-1)
-{
- m_key = m_bmesh->key ? BKE_key_copy(G.main, m_bmesh->key) : NULL;
-};
-
-/* this second constructor is needed for making a mesh deformable on the fly. */
-BL_ShapeDeformer::BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- Object *bmeshobj_old,
- Object *bmeshobj_new,
- RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma)
- :
- BL_SkinDeformer(gameobj, bmeshobj_old, bmeshobj_new, mesh, release_object, recalc_normal, arma),
- m_useShapeDrivers(false),
- m_lastShapeUpdate(-1)
-{
- m_key = m_bmesh->key ? BKE_key_copy(G.main, m_bmesh->key) : NULL;
-};
-
-BL_ShapeDeformer::~BL_ShapeDeformer()
-{
- if (m_key)
- {
- BKE_libblock_free(G.main, m_key);
- m_key = NULL;
- }
-};
-
-RAS_Deformer *BL_ShapeDeformer::GetReplica()
-{
- BL_ShapeDeformer *result;
-
- result = new BL_ShapeDeformer(*this);
- result->ProcessReplica();
- return result;
-}
-
-void BL_ShapeDeformer::ProcessReplica()
-{
- BL_SkinDeformer::ProcessReplica();
- m_lastShapeUpdate = -1;
-
- m_key = m_key ? BKE_key_copy(G.main, m_key) : NULL;
-}
-
-bool BL_ShapeDeformer::LoadShapeDrivers(KX_GameObject* parent)
-{
- // Only load shape drivers if we have a key
- if (GetKey() == NULL) {
- m_useShapeDrivers = false;
- return false;
- }
-
- // Fix drivers since BL_ArmatureObject makes copies
- if (parent->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE && GetKey()->adt) {
- BL_ArmatureObject *arma = (BL_ArmatureObject*)parent;
- FCurve *fcu;
-
- for (fcu = (FCurve*)GetKey()->adt->drivers.first; fcu; fcu = (FCurve*)fcu->next) {
-
- DriverVar *dvar;
- for (dvar = (DriverVar*)fcu->driver->variables.first; dvar; dvar = (DriverVar*)dvar->next) {
- DRIVER_TARGETS_USED_LOOPER(dvar)
- {
- if (dtar->id) {
- if ((Object*)dtar->id == arma->GetOrigArmatureObject())
- dtar->id = (ID*)arma->GetArmatureObject();
- }
- }
- DRIVER_TARGETS_LOOPER_END
- }
- }
- }
-
- // This used to check if we had drivers from this armature,
- // now we just assume we want to use shape drivers
- // and let the animsys handle things.
- m_useShapeDrivers = true;
-
- return true;
-}
-
-bool BL_ShapeDeformer::ExecuteShapeDrivers(void)
-{
- if (m_useShapeDrivers && PoseUpdated()) {
- // We don't need an actual time, just use 0
- BKE_animsys_evaluate_animdata(NULL, &GetKey()->id, GetKey()->adt, 0.f, ADT_RECALC_DRIVERS);
-
- ForceUpdate();
- m_bDynamic = true;
- return true;
- }
- return false;
-}
-
-bool BL_ShapeDeformer::Update(void)
-{
- bool bShapeUpdate = false;
- bool bSkinUpdate = false;
-
- ExecuteShapeDrivers();
-
- /* See if the object shape has changed */
- if (m_lastShapeUpdate != m_gameobj->GetLastFrame()) {
- /* the key coefficient have been set already, we just need to blend the keys */
- Object* blendobj = m_gameobj->GetBlendObject();
-
- /* we will blend the key directly in m_transverts array: it is used by armature as the start position */
- /* m_key can be NULL in case of Modifier deformer */
- if (m_key) {
- WeightsArrayCache cache = {0, NULL};
- float **per_keyblock_weights;
-
- /* store verts locally */
- VerifyStorage();
-
- per_keyblock_weights = BKE_keyblock_get_per_block_weights(blendobj, m_key, &cache);
- BKE_key_evaluate_relative(0, m_bmesh->totvert, m_bmesh->totvert, (char *)(float *)m_transverts,
- m_key, NULL, per_keyblock_weights, 0); /* last arg is ignored */
- BKE_keyblock_free_per_block_weights(m_key, per_keyblock_weights, &cache);
-
- m_bDynamic = true;
- }
-
- // Don't release the weight array as in Blender, it will most likely be reusable on next frame
- // The weight array are ultimately deleted when the skin mesh is destroyed
-
- /* Update the current frame */
- m_lastShapeUpdate=m_gameobj->GetLastFrame();
-
- // As we have changed, the mesh, the skin deformer must update as well.
- // This will force the update
- BL_SkinDeformer::ForceUpdate();
- bShapeUpdate = true;
- }
- // check for armature deform
- bSkinUpdate = BL_SkinDeformer::UpdateInternal(bShapeUpdate && m_bDynamic);
-
- // non dynamic deformer = Modifer without armature and shape keys, no need to create storage
- if (!bSkinUpdate && bShapeUpdate && m_bDynamic) {
- // this means that there is no armature, we still need to
- // update the normal (was not done after shape key calculation)
-
-#ifdef __NLA_DEFNORMALS
- if (m_recalcNormal)
- RecalcNormals();
-#endif
-
- // We also need to handle transverts now (used to be in BL_SkinDeformer::Apply())
- UpdateTransverts();
- bSkinUpdate = true;
- }
-
- return bSkinUpdate;
-}
-
-Key *BL_ShapeDeformer::GetKey()
-{
- return m_key;
-}
diff --git a/source/gameengine/Converter/BL_ShapeDeformer.h b/source/gameengine/Converter/BL_ShapeDeformer.h
deleted file mode 100644
index f6746dd2302..00000000000
--- a/source/gameengine/Converter/BL_ShapeDeformer.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ShapeDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_SHAPEDEFORMER_H__
-#define __BL_SHAPEDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-#include "BL_SkinDeformer.h"
-#include "BL_DeformableGameObject.h"
-#include <vector>
-
-class BL_ShapeDeformer : public BL_SkinDeformer
-{
-public:
- BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- Object *bmeshobj,
- RAS_MeshObject *mesh);
-
- /* this second constructor is needed for making a mesh deformable on the fly. */
- BL_ShapeDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj_old,
- struct Object *bmeshobj_new,
- class RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma = NULL);
-
- virtual RAS_Deformer *GetReplica();
- virtual void ProcessReplica();
- virtual ~BL_ShapeDeformer();
-
- bool Update (void);
- bool LoadShapeDrivers(KX_GameObject* parent);
- bool ExecuteShapeDrivers(void);
-
- struct Key *GetKey();
-
- void ForceUpdate()
- {
- m_lastShapeUpdate = -1.0;
- };
-
-protected:
- bool m_useShapeDrivers;
- double m_lastShapeUpdate;
- struct Key* m_key;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ShapeDeformer")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Converter/BL_SkinDeformer.cpp b/source/gameengine/Converter/BL_SkinDeformer.cpp
deleted file mode 100644
index 68da99f9fa5..00000000000
--- a/source/gameengine/Converter/BL_SkinDeformer.cpp
+++ /dev/null
@@ -1,384 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/BL_SkinDeformer.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-// Eigen3 stuff used for BGEDeformVerts
-#include <Eigen/Core>
-#include <Eigen/LU>
-
-#include "BL_SkinDeformer.h"
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_MeshObject.h"
-
-//#include "BL_ArmatureController.h"
-#include "DNA_armature_types.h"
-#include "DNA_action_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_modifier_types.h"
-#include "BLI_utildefines.h"
-#include "BKE_armature.h"
-#include "BKE_action.h"
-#include "MT_Point3.h"
-
-extern "C"{
- #include "BKE_lattice.h"
- #include "BKE_deform.h"
-}
-
-
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-
-#define __NLA_DEFNORMALS
-//#undef __NLA_DEFNORMALS
-
-static short get_deformflags(struct Object *bmeshobj)
-{
- short flags = ARM_DEF_VGROUP;
-
- ModifierData *md;
- for (md = (ModifierData *)bmeshobj->modifiers.first; md; md = md->next)
- {
- if (md->type == eModifierType_Armature)
- {
- flags |= ((ArmatureModifierData*)md)->deformflag;
- break;
- }
- }
-
- return flags;
-}
-
-BL_SkinDeformer::BL_SkinDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj,
- class RAS_MeshObject *mesh,
- BL_ArmatureObject* arma)
- : //
- BL_MeshDeformer(gameobj, bmeshobj, mesh),
- m_armobj(arma),
- m_lastArmaUpdate(-1),
- //m_defbase(&bmeshobj->defbase),
- m_releaseobject(false),
- m_poseApplied(false),
- m_recalcNormal(true),
- m_copyNormals(false),
- m_dfnrToPC(NULL)
-{
- copy_m4_m4(m_obmat, bmeshobj->obmat);
- m_deformflags = get_deformflags(bmeshobj);
-};
-
-BL_SkinDeformer::BL_SkinDeformer(
- BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj_old, // Blender object that owns the new mesh
- struct Object *bmeshobj_new, // Blender object that owns the original mesh
- class RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma) :
- BL_MeshDeformer(gameobj, bmeshobj_old, mesh),
- m_armobj(arma),
- m_lastArmaUpdate(-1),
- //m_defbase(&bmeshobj_old->defbase),
- m_releaseobject(release_object),
- m_recalcNormal(recalc_normal),
- m_copyNormals(false),
- m_dfnrToPC(NULL)
- {
- // this is needed to ensure correct deformation of mesh:
- // the deformation is done with Blender's armature_deform_verts() function
- // that takes an object as parameter and not a mesh. The object matrice is used
- // in the calculation, so we must use the matrix of the original object to
- // simulate a pure replacement of the mesh.
- copy_m4_m4(m_obmat, bmeshobj_new->obmat);
- m_deformflags = get_deformflags(bmeshobj_new);
- }
-
-BL_SkinDeformer::~BL_SkinDeformer()
-{
- if (m_releaseobject && m_armobj)
- m_armobj->Release();
- if (m_dfnrToPC)
- delete [] m_dfnrToPC;
-}
-
-void BL_SkinDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*map)
-{
- if (m_armobj) {
- void **h_obj = (*map)[m_armobj];
-
- if (h_obj)
- m_armobj = (BL_ArmatureObject*)(*h_obj);
- else
- m_armobj=NULL;
- }
-
- BL_MeshDeformer::Relink(map);
-}
-
-bool BL_SkinDeformer::Apply(RAS_IPolyMaterial *mat)
-{
- // We do everything in UpdateInternal() now so we can thread it.
- // All that is left is telling the rasterizer if we've changed the mesh
- bool retval = !m_poseApplied;
- m_poseApplied = true;
- return retval;
-}
-
-RAS_Deformer *BL_SkinDeformer::GetReplica()
-{
- BL_SkinDeformer *result;
-
- result = new BL_SkinDeformer(*this);
- /* there is m_armobj that must be fixed but we cannot do it now, it will be done in Relink */
- result->ProcessReplica();
- return result;
-}
-
-void BL_SkinDeformer::ProcessReplica()
-{
- BL_MeshDeformer::ProcessReplica();
- m_lastArmaUpdate = -1;
- m_releaseobject = false;
- m_dfnrToPC = NULL;
-}
-
-void BL_SkinDeformer::BlenderDeformVerts()
-{
- float obmat[4][4]; // the original object matrix
- Object* par_arma = m_armobj->GetArmatureObject();
-
- // save matrix first
- copy_m4_m4(obmat, m_objMesh->obmat);
- // set reference matrix
- copy_m4_m4(m_objMesh->obmat, m_obmat);
-
- armature_deform_verts( par_arma, m_objMesh, NULL, m_transverts, NULL, m_bmesh->totvert, m_deformflags, NULL, NULL );
-
- // restore matrix
- copy_m4_m4(m_objMesh->obmat, obmat);
-
-#ifdef __NLA_DEFNORMALS
- if (m_recalcNormal)
- RecalcNormals();
-#endif
-}
-
-void BL_SkinDeformer::BGEDeformVerts()
-{
- Object *par_arma = m_armobj->GetArmatureObject();
- MDeformVert *dverts = m_bmesh->dvert;
- bDeformGroup *dg;
- int defbase_tot;
- Eigen::Matrix4f pre_mat, post_mat, chan_mat, norm_chan_mat;
-
- if (!dverts)
- return;
-
- defbase_tot = BLI_listbase_count(&m_objMesh->defbase);
-
- if (m_dfnrToPC == NULL)
- {
- m_dfnrToPC = new bPoseChannel*[defbase_tot];
- int i;
- for (i=0, dg=(bDeformGroup*)m_objMesh->defbase.first;
- dg;
- ++i, dg = dg->next)
- {
- m_dfnrToPC[i] = BKE_pose_channel_find_name(par_arma->pose, dg->name);
-
- if (m_dfnrToPC[i] && m_dfnrToPC[i]->bone->flag & BONE_NO_DEFORM)
- m_dfnrToPC[i] = NULL;
- }
- }
-
- post_mat = Eigen::Matrix4f::Map((float*)m_obmat).inverse() * Eigen::Matrix4f::Map((float*)m_armobj->GetArmatureObject()->obmat);
- pre_mat = post_mat.inverse();
-
- MDeformVert *dv= dverts;
- MDeformWeight *dw;
-
- for (int i=0; i<m_bmesh->totvert; ++i, dv++)
- {
- float contrib = 0.f, weight, max_weight=-1.f;
- bPoseChannel *pchan=NULL;
- Eigen::Map<Eigen::Vector3f> norm = Eigen::Vector3f::Map(m_transnors[i]);
- Eigen::Vector4f vec(0, 0, 0, 1);
- Eigen::Vector4f co(m_transverts[i][0],
- m_transverts[i][1],
- m_transverts[i][2],
- 1.f);
-
- if (!dv->totweight)
- continue;
-
- co = pre_mat * co;
-
- dw= dv->dw;
-
- for (unsigned int j= dv->totweight; j != 0; j--, dw++)
- {
- const int index = dw->def_nr;
-
- if (index < defbase_tot && (pchan=m_dfnrToPC[index]))
- {
- weight = dw->weight;
-
- if (weight)
- {
- chan_mat = Eigen::Matrix4f::Map((float*)pchan->chan_mat);
-
- // Update Vertex Position
- vec.noalias() += (chan_mat*co - co)*weight;
-
- // Save the most influential channel so we can use it to update the vertex normal
- if (weight > max_weight)
- {
- max_weight = weight;
- norm_chan_mat = chan_mat;
- }
-
- contrib += weight;
- }
- }
- }
-
- // Update Vertex Normal
- norm = norm_chan_mat.topLeftCorner<3, 3>()*norm;
-
- co.noalias() += vec/contrib;
- co[3] = 1.f; // Make sure we have a 1 for the w component!
-
- co = post_mat * co;
-
- m_transverts[i][0] = co[0];
- m_transverts[i][1] = co[1];
- m_transverts[i][2] = co[2];
- }
- m_copyNormals = true;
-}
-
-void BL_SkinDeformer::UpdateTransverts()
-{
- RAS_MeshSlot::iterator it;
- RAS_MeshMaterial *mmat;
- RAS_MeshSlot *slot;
- size_t i, nmat, imat;
-
- if (m_transverts) {
- // the vertex cache is unique to this deformer, no need to update it
- // if it wasn't updated! We must update all the materials at once
- // because we will not get here again for the other material
- nmat = m_pMeshObject->NumMaterials();
- for (imat=0; imat<nmat; imat++) {
- mmat = m_pMeshObject->GetMeshMaterial(imat);
- if (!mmat->m_slots[(void*)m_gameobj])
- continue;
-
- slot = *mmat->m_slots[(void*)m_gameobj];
-
- // for each array
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- // for each vertex
- // copy the untransformed data from the original mvert
- for (i=it.startvertex; i<it.endvertex; i++) {
- RAS_TexVert& v = it.vertex[i];
- v.SetXYZ(m_transverts[v.getOrigIndex()]);
- if (m_copyNormals)
- v.SetNormal(m_transnors[v.getOrigIndex()]);
- }
- }
- }
-
- if (m_copyNormals)
- m_copyNormals = false;
- }
-}
-
-bool BL_SkinDeformer::UpdateInternal(bool shape_applied)
-{
- /* See if the armature has been updated for this frame */
- if (PoseUpdated()) {
-
- if (!shape_applied) {
- /* store verts locally */
- VerifyStorage();
-
- /* duplicate */
- for (int v =0; v<m_bmesh->totvert; v++)
- {
- copy_v3_v3(m_transverts[v], m_bmesh->mvert[v].co);
- normal_short_to_float_v3(m_transnors[v], m_bmesh->mvert[v].no);
- }
- }
-
- m_armobj->ApplyPose();
-
- if (m_armobj->GetVertDeformType() == ARM_VDEF_BGE_CPU)
- BGEDeformVerts();
- else
- BlenderDeformVerts();
-
- /* Update the current frame */
- m_lastArmaUpdate=m_armobj->GetLastFrame();
-
- m_armobj->RestorePose();
- /* dynamic vertex, cannot use display list */
- m_bDynamic = true;
-
- UpdateTransverts();
-
- m_poseApplied = false;
-
- /* indicate that the m_transverts and normals are up to date */
- return true;
- }
-
- return false;
-}
-
-bool BL_SkinDeformer::Update(void)
-{
- return UpdateInternal(false);
-}
-
-/* XXX note: I propose to drop this function */
-void BL_SkinDeformer::SetArmature(BL_ArmatureObject *armobj)
-{
- // only used to set the object now
- m_armobj = armobj;
-}
diff --git a/source/gameengine/Converter/BL_SkinDeformer.h b/source/gameengine/Converter/BL_SkinDeformer.h
deleted file mode 100644
index 79043f60db8..00000000000
--- a/source/gameengine/Converter/BL_SkinDeformer.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_SkinDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __BL_SKINDEFORMER_H__
-#define __BL_SKINDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif /* WIN32 */
-
-#include "CTR_HashedPtr.h"
-#include "BL_MeshDeformer.h"
-#include "BL_ArmatureObject.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_object_types.h"
-#include "BKE_armature.h"
-
-#include "RAS_Deformer.h"
-
-
-class BL_SkinDeformer : public BL_MeshDeformer
-{
-public:
-// void SetArmatureController (BL_ArmatureController *cont);
- virtual void Relink(CTR_Map<class CTR_HashedPtr, void*>*map);
- void SetArmature (class BL_ArmatureObject *armobj);
-
- BL_SkinDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj,
- class RAS_MeshObject *mesh,
- BL_ArmatureObject* arma = NULL);
-
- /* this second constructor is needed for making a mesh deformable on the fly. */
- BL_SkinDeformer(BL_DeformableGameObject *gameobj,
- struct Object *bmeshobj_old,
- struct Object *bmeshobj_new,
- class RAS_MeshObject *mesh,
- bool release_object,
- bool recalc_normal,
- BL_ArmatureObject* arma = NULL);
-
- virtual RAS_Deformer *GetReplica();
- virtual void ProcessReplica();
-
- virtual ~BL_SkinDeformer();
- bool Update (void);
- bool UpdateInternal (bool shape_applied);
- bool Apply (class RAS_IPolyMaterial *polymat);
- bool UpdateBuckets(void)
- {
- // update the deformer and all the mesh slots; Apply() does it well, so just call it.
- return Apply(NULL);
- }
- bool PoseUpdated(void)
- {
- if (m_armobj && m_lastArmaUpdate!=m_armobj->GetLastFrame()) {
- return true;
- }
- return false;
- }
-
- void ForceUpdate()
- {
- m_lastArmaUpdate = -1.0;
- };
- virtual bool ShareVertexArray()
- {
- return false;
- }
-
-protected:
- BL_ArmatureObject* m_armobj; // Our parent object
- float m_time;
- double m_lastArmaUpdate;
- //ListBase* m_defbase;
- float m_obmat[4][4]; // the reference matrix for skeleton deform
- bool m_releaseobject;
- bool m_poseApplied;
- bool m_recalcNormal;
- bool m_copyNormals; // dirty flag so we know if Apply() needs to copy normal information (used for BGEDeformVerts())
- struct bPoseChannel** m_dfnrToPC;
- short m_deformflags;
-
- void BlenderDeformVerts();
- void BGEDeformVerts();
-
- void UpdateTransverts();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_SkinDeformer")
-#endif
-};
-
-#endif /* __BL_SKINDEFORMER_H__ */
diff --git a/source/gameengine/Converter/CMakeLists.txt b/source/gameengine/Converter/CMakeLists.txt
deleted file mode 100644
index 4db9fcebd06..00000000000
--- a/source/gameengine/Converter/CMakeLists.txt
+++ /dev/null
@@ -1,123 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../BlenderRoutines
- ../Expressions
- ../GameLogic
- ../Ketsji
- ../Ketsji/KXNetwork
- ../Network
- ../Network/LoopBackNetwork
- ../Physics/Bullet
- ../Physics/Dummy
- ../Physics/common
- ../Rasterizer
- ../Rasterizer/RAS_OpenGLRasterizer
- ../SceneGraph
- ../../blender
- ../../blender/blenkernel
- ../../blender/blenlib
- ../../blender/blenloader
- ../../blender/gpu
- ../../blender/ikplugin
- ../../blender/imbuf
- ../../blender/makesdna
- ../../blender/makesrna
- ../../blender/windowmanager
- ../../../intern/container
- ../../../intern/guardedalloc
- ../../../intern/string
-)
-
-set(INC_SYS
- ../../../intern/moto/include
- ../../../extern/recastnavigation/Detour/Include
- ${EIGEN3_INCLUDE_DIRS}
- ${PTHREADS_INCLUDE_DIRS}
- ${BOOST_INCLUDE_DIR}
-)
-
-set(SRC
- BL_ActionActuator.cpp
- BL_ArmatureActuator.cpp
- BL_ArmatureChannel.cpp
- BL_ArmatureConstraint.cpp
- BL_ArmatureObject.cpp
- BL_BlenderDataConversion.cpp
- BL_DeformableGameObject.cpp
- BL_MeshDeformer.cpp
- BL_ModifierDeformer.cpp
- BL_ShapeActionActuator.cpp
- BL_ShapeDeformer.cpp
- BL_SkinDeformer.cpp
- KX_BlenderScalarInterpolator.cpp
- KX_BlenderSceneConverter.cpp
- KX_ConvertActuators.cpp
- KX_ConvertControllers.cpp
- KX_ConvertProperties.cpp
- KX_ConvertSensors.cpp
- KX_LibLoadStatus.cpp
- KX_SoftBodyDeformer.cpp
-
- BL_ActionActuator.h
- BL_ArmatureActuator.h
- BL_ArmatureChannel.h
- BL_ArmatureConstraint.h
- BL_ArmatureObject.h
- BL_BlenderDataConversion.h
- BL_DeformableGameObject.h
- BL_MeshDeformer.h
- BL_ModifierDeformer.h
- BL_ShapeActionActuator.h
- BL_ShapeDeformer.h
- BL_SkinDeformer.h
- KX_BlenderScalarInterpolator.h
- KX_BlenderSceneConverter.h
- KX_ConvertActuators.h
- KX_ConvertControllers.h
- KX_ConvertProperties.h
- KX_ConvertSensors.h
- KX_LibLoadStatus.h
- KX_SoftBodyDeformer.h
-)
-
-if(WITH_BULLET)
- list(APPEND INC_SYS
- ${BULLET_INCLUDE_DIRS}
- )
- add_definitions(-DWITH_BULLET)
-endif()
-
-if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
-
- list(APPEND INC_SYS
- ${AUDASPACE_C_INCLUDE_DIRS}
- )
-endif()
-
-blender_add_lib(ge_converter "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp b/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp
deleted file mode 100644
index 4d344cdf16a..00000000000
--- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.cpp
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_BlenderScalarInterpolator.cpp
- * \ingroup bgeconv
- */
-
-
-#include "KX_BlenderScalarInterpolator.h"
-
-#include <cstring>
-
-extern "C" {
-#include "DNA_action_types.h"
-#include "DNA_anim_types.h"
-#include "BKE_fcurve.h"
-}
-
-float BL_ScalarInterpolator::GetValue(float currentTime) const
-{
- // XXX 2.4x IPO_GetFloatValue(m_blender_adt, m_channel, currentTime);
- return evaluate_fcurve(m_fcu, currentTime);
-}
-
-BL_InterpolatorList::BL_InterpolatorList(bAction *action)
-{
- if (action==NULL)
- return;
-
- for (FCurve *fcu = (FCurve *)action->curves.first; fcu; fcu = fcu->next) {
- if (fcu->rna_path) {
- BL_ScalarInterpolator *new_ipo = new BL_ScalarInterpolator(fcu);
- //assert(new_ipo);
- push_back(new_ipo);
- }
- }
-}
-
-BL_InterpolatorList::~BL_InterpolatorList()
-{
- BL_InterpolatorList::iterator i;
- for (i = begin(); !(i == end()); ++i) {
- delete *i;
- }
-}
-
-KX_IScalarInterpolator *BL_InterpolatorList::GetScalarInterpolator(const char *rna_path, int array_index)
-{
- for (BL_InterpolatorList::iterator i = begin(); (i != end()) ; i++ )
- {
- FCurve *fcu= (static_cast<BL_ScalarInterpolator *>(*i))->GetFCurve();
- if (array_index==fcu->array_index && strcmp(rna_path, fcu->rna_path)==0)
- return *i;
- }
- return NULL;
-}
-
diff --git a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h b/source/gameengine/Converter/KX_BlenderScalarInterpolator.h
deleted file mode 100644
index d828910233f..00000000000
--- a/source/gameengine/Converter/KX_BlenderScalarInterpolator.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderScalarInterpolator.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_BLENDERSCALARINTERPOLATOR_H__
-#define __KX_BLENDERSCALARINTERPOLATOR_H__
-
-#include <vector>
-
-#include "KX_IScalarInterpolator.h"
-
-typedef unsigned short BL_IpoChannel;
-
-class BL_ScalarInterpolator : public KX_IScalarInterpolator {
-public:
- BL_ScalarInterpolator() {} // required for use in STL list
- BL_ScalarInterpolator(struct FCurve* fcu) :
- m_fcu(fcu)
- {}
-
- virtual ~BL_ScalarInterpolator() {}
-
- virtual float GetValue(float currentTime) const;
- struct FCurve *GetFCurve() { return m_fcu; }
-
-private:
- struct FCurve *m_fcu;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ScalarInterpolator")
-#endif
-};
-
-
-class BL_InterpolatorList : public std::vector<KX_IScalarInterpolator *> {
-public:
- BL_InterpolatorList(struct bAction *action);
- ~BL_InterpolatorList();
-
- KX_IScalarInterpolator *GetScalarInterpolator(const char *rna_path, int array_index);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_InterpolatorList")
-#endif
-};
-
-#endif /* __KX_BLENDERSCALARINTERPOLATOR_H__ */
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp b/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
deleted file mode 100644
index 08b569fa4c2..00000000000
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.cpp
+++ /dev/null
@@ -1,1477 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_BlenderSceneConverter.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* suppress stl-MSVC debug info warning */
-#endif
-
-#include "KX_Scene.h"
-#include "KX_GameObject.h"
-#include "KX_IpoConvert.h"
-#include "RAS_MeshObject.h"
-#include "KX_PhysicsEngineEnums.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "KX_KetsjiEngine.h"
-#include "KX_PythonInit.h" // So we can handle adding new text datablocks for Python to import
-#include "BL_Material.h"
-#include "BL_ActionActuator.h"
-#include "KX_BlenderMaterial.h"
-
-
-#include "BL_System.h"
-
-#include "DummyPhysicsEnvironment.h"
-
-
-#ifdef WITH_BULLET
-#include "CcdPhysicsEnvironment.h"
-#endif
-
-#include "KX_LibLoadStatus.h"
-#include "KX_BlenderScalarInterpolator.h"
-#include "BL_BlenderDataConversion.h"
-#include "KX_WorldInfo.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-/* This list includes only data type definitions */
-#include "DNA_scene_types.h"
-#include "DNA_world_types.h"
-#include "BKE_main.h"
-#include "BKE_fcurve.h"
-
-#include "BLI_math.h"
-
-extern "C"
-{
-#include "DNA_object_types.h"
-#include "DNA_curve_types.h"
-#include "DNA_mesh_types.h"
-#include "DNA_material_types.h"
-#include "BLI_blenlib.h"
-#include "MEM_guardedalloc.h"
-#include "BKE_global.h"
-#include "BKE_animsys.h"
-#include "BKE_library.h"
-#include "BKE_material.h" // BKE_material_copy
-#include "BKE_mesh.h" // BKE_mesh_copy
-#include "DNA_space_types.h"
-#include "DNA_anim_types.h"
-#include "DNA_action_types.h"
-#include "RNA_define.h"
-#include "../../blender/editors/include/ED_keyframing.h"
-}
-
-/* Only for dynamic loading and merging */
-#include "RAS_BucketManager.h" // XXX cant stay
-#include "KX_BlenderSceneConverter.h"
-#include "KX_MeshProxy.h"
-extern "C" {
- #include "PIL_time.h"
- #include "BKE_context.h"
- #include "BLO_readfile.h"
- #include "BKE_idcode.h"
- #include "BKE_report.h"
- #include "DNA_space_types.h"
- #include "DNA_windowmanager_types.h" /* report api */
- #include "../../blender/blenlib/BLI_linklist.h"
-}
-
-#include "BLI_task.h"
-
-// This is used to avoid including BLI_task.h in KX_BlenderSceneConverter.h
-typedef struct ThreadInfo {
- TaskPool *m_pool;
- ThreadMutex m_mutex;
-} ThreadInfo;
-
-KX_BlenderSceneConverter::KX_BlenderSceneConverter(
- Main *maggie,
- KX_KetsjiEngine *engine)
- :m_maggie(maggie),
- m_ketsjiEngine(engine),
- m_alwaysUseExpandFraming(false),
- m_usemat(false),
- m_useglslmat(false),
- m_use_mat_cache(true)
-{
- BKE_main_id_tag_all(maggie, LIB_TAG_DOIT, false); /* avoid re-tagging later on */
- m_newfilename = "";
- m_threadinfo = new ThreadInfo();
- m_threadinfo->m_pool = BLI_task_pool_create(engine->GetTaskScheduler(), NULL);
- BLI_mutex_init(&m_threadinfo->m_mutex);
-}
-
-KX_BlenderSceneConverter::~KX_BlenderSceneConverter()
-{
- // clears meshes, and hashmaps from blender to gameengine data
- // delete sumoshapes
-
- int numAdtLists = m_map_blender_to_gameAdtList.size();
- for (int i = 0; i < numAdtLists; i++) {
- BL_InterpolatorList *adtList = *m_map_blender_to_gameAdtList.at(i);
-
- delete (adtList);
- }
-
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator itw = m_worldinfos.begin();
- while (itw != m_worldinfos.end()) {
- delete itw->second;
- itw++;
- }
- m_worldinfos.clear();
-
- vector<pair<KX_Scene *,RAS_IPolyMaterial *> >::iterator itp = m_polymaterials.begin();
- while (itp != m_polymaterials.end()) {
- delete itp->second;
- itp++;
- }
- m_polymaterials.clear();
-
- // delete after RAS_IPolyMaterial
- vector<pair<KX_Scene *,BL_Material *> >::iterator itmat = m_materials.begin();
- while (itmat != m_materials.end()) {
- delete itmat->second;
- itmat++;
- }
- m_materials.clear();
-
- vector<pair<KX_Scene *,RAS_MeshObject *> >::iterator itm = m_meshobjects.begin();
- while (itm != m_meshobjects.end()) {
- delete itm->second;
- itm++;
- }
- m_meshobjects.clear();
-
- /* free any data that was dynamically loaded */
- while (m_DynamicMaggie.size() != 0) {
- FreeBlendFile(m_DynamicMaggie[0]);
- }
-
- m_DynamicMaggie.clear();
-
- if (m_threadinfo) {
- /* Thread infos like mutex must be freed after FreeBlendFile function.
- Because it needs to lock the mutex, even if there's no active task when it's
- in the scene converter destructor. */
- BLI_task_pool_free(m_threadinfo->m_pool);
- BLI_mutex_end(&m_threadinfo->m_mutex);
- delete m_threadinfo;
- }
-}
-
-void KX_BlenderSceneConverter::SetNewFileName(const STR_String &filename)
-{
- m_newfilename = filename;
-}
-
-bool KX_BlenderSceneConverter::TryAndLoadNewFile()
-{
- bool result = false;
-
- return result;
-}
-
-Scene *KX_BlenderSceneConverter::GetBlenderSceneForName(const STR_String &name)
-{
- Scene *sce;
-
- /**
- * Find the specified scene by name, or NULL if nothing matches.
- */
- if ((sce = (Scene *)BLI_findstring(&m_maggie->scene, name.ReadPtr(), offsetof(ID, name) + 2)))
- return sce;
-
- for (vector<Main *>::iterator it=m_DynamicMaggie.begin(); !(it == m_DynamicMaggie.end()); it++) {
- Main *main = *it;
-
- if ((sce= (Scene *)BLI_findstring(&main->scene, name.ReadPtr(), offsetof(ID, name) + 2)))
- return sce;
- }
-
- return NULL;
-}
-
-void KX_BlenderSceneConverter::ConvertScene(KX_Scene *destinationscene, RAS_IRasterizer *rendertools,
- RAS_ICanvas *canvas, bool libloading)
-{
- //find out which physics engine
- Scene *blenderscene = destinationscene->GetBlenderScene();
-
- PHY_IPhysicsEnvironment *phy_env = NULL;
-
- e_PhysicsEngine physics_engine = UseBullet;
- // hook for registration function during conversion.
- m_currentScene = destinationscene;
- destinationscene->SetSceneConverter(this);
-
- // This doesn't really seem to do anything except cause potential issues
- // when doing threaded conversion, so it's disabled for now.
- // SG_SetActiveStage(SG_STAGE_CONVERTER);
-
- switch (blenderscene->gm.physicsEngine) {
-#ifdef WITH_BULLET
- case WOPHY_BULLET:
- {
- SYS_SystemHandle syshandle = SYS_GetSystem(); /*unused*/
- int visualizePhysics = SYS_GetCommandLineInt(syshandle, "show_physics", 0);
-
- phy_env = CcdPhysicsEnvironment::Create(blenderscene, visualizePhysics);
- physics_engine = UseBullet;
- break;
- }
-#endif
- default:
- case WOPHY_NONE:
- {
- // We should probably use some sort of factory here
- phy_env = new DummyPhysicsEnvironment();
- physics_engine = UseNone;
- break;
- }
- }
-
- destinationscene->SetPhysicsEnvironment(phy_env);
-
- BL_ConvertBlenderObjects(
- m_maggie,
- destinationscene,
- m_ketsjiEngine,
- physics_engine,
- rendertools,
- canvas,
- this,
- m_alwaysUseExpandFraming,
- libloading);
-
- //These lookup are not needed during game
- m_map_blender_to_gameactuator.clear();
- m_map_blender_to_gamecontroller.clear();
- m_map_blender_to_gameobject.clear();
-
- //Clearing this lookup table has the effect of disabling the cache of meshes
- //between scenes, even if they are shared in the blend file.
- //This cache mecanism is buggy so I leave it disable and the memory leak
- //that would result from this is fixed in RemoveScene()
- m_map_mesh_to_gamemesh.clear();
-}
-
-// This function removes all entities stored in the converter for that scene
-// It should be used instead of direct delete scene
-// Note that there was some provision for sharing entities (meshes...) between
-// scenes but that is now disabled so all scene will have their own copy
-// and we can delete them here. If the sharing is reactivated, change this code too..
-// (see KX_BlenderSceneConverter::ConvertScene)
-void KX_BlenderSceneConverter::RemoveScene(KX_Scene *scene)
-{
- int i, size;
- // delete the scene first as it will stop the use of entities
- delete scene;
- // delete the entities of this scene
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator worldit;
- size = m_worldinfos.size();
- for (i = 0, worldit = m_worldinfos.begin(); i < size; ) {
- if (worldit->first == scene) {
- delete worldit->second;
- *worldit = m_worldinfos.back();
- m_worldinfos.pop_back();
- size--;
- }
- else {
- i++;
- worldit++;
- }
- }
-
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator polymit;
- size = m_polymaterials.size();
- for (i = 0, polymit = m_polymaterials.begin(); i < size; ) {
- if (polymit->first == scene) {
- m_polymat_cache[scene].erase(polymit->second->GetBlenderMaterial());
- delete polymit->second;
- *polymit = m_polymaterials.back();
- m_polymaterials.pop_back();
- size--;
- }
- else {
- i++;
- polymit++;
- }
- }
-
- m_polymat_cache.erase(scene);
-
- vector<pair<KX_Scene *, BL_Material *> >::iterator matit;
- size = m_materials.size();
- for (i = 0, matit = m_materials.begin(); i < size; ) {
- if (matit->first == scene) {
- m_mat_cache[scene].erase(matit->second->material);
- delete matit->second;
- *matit = m_materials.back();
- m_materials.pop_back();
- size--;
- }
- else {
- i++;
- matit++;
- }
- }
-
- m_mat_cache.erase(scene);
-
- vector<pair<KX_Scene *, RAS_MeshObject *> >::iterator meshit;
- size = m_meshobjects.size();
- for (i = 0, meshit = m_meshobjects.begin(); i < size; ) {
- if (meshit->first == scene) {
- delete meshit->second;
- *meshit = m_meshobjects.back();
- m_meshobjects.pop_back();
- size--;
- }
- else {
- i++;
- meshit++;
- }
- }
-}
-
-// use blender materials
-void KX_BlenderSceneConverter::SetMaterials(bool val)
-{
- m_usemat = val;
- m_useglslmat = false;
-}
-
-void KX_BlenderSceneConverter::SetGLSLMaterials(bool val)
-{
- m_usemat = val;
- m_useglslmat = val;
-}
-
-void KX_BlenderSceneConverter::SetCacheMaterials(bool val)
-{
- m_use_mat_cache = val;
-}
-
-bool KX_BlenderSceneConverter::GetMaterials()
-{
- return m_usemat;
-}
-
-bool KX_BlenderSceneConverter::GetGLSLMaterials()
-{
- return m_useglslmat;
-}
-
-bool KX_BlenderSceneConverter::GetCacheMaterials()
-{
- return m_use_mat_cache;
-}
-
-void KX_BlenderSceneConverter::RegisterBlenderMaterial(BL_Material *mat)
-{
- // First make sure we don't register the material twice
- vector<pair<KX_Scene *, BL_Material *> >::iterator it;
- for (it = m_materials.begin(); it != m_materials.end(); ++it)
- if (it->second == mat)
- return;
-
- m_materials.push_back(pair<KX_Scene *, BL_Material *> (m_currentScene, mat));
-}
-
-void KX_BlenderSceneConverter::SetAlwaysUseExpandFraming(bool to_what)
-{
- m_alwaysUseExpandFraming= to_what;
-}
-
-void KX_BlenderSceneConverter::RegisterGameObject(KX_GameObject *gameobject, Object *for_blenderobject)
-{
- /* only maintained while converting, freed during game runtime */
- m_map_blender_to_gameobject.insert(CHashedPtr(for_blenderobject), gameobject);
-}
-
-/* only need to run this during conversion since
- * m_map_blender_to_gameobject is freed after conversion */
-void KX_BlenderSceneConverter::UnregisterGameObject(KX_GameObject *gameobject)
-{
- Object *bobp = gameobject->GetBlenderObject();
- if (bobp) {
- CHashedPtr bptr(bobp);
- KX_GameObject **gobp = m_map_blender_to_gameobject[bptr];
- if (gobp && *gobp == gameobject) {
- // also maintain m_map_blender_to_gameobject if the gameobject
- // being removed is matching the blender object
- m_map_blender_to_gameobject.remove(bptr);
- }
- }
-}
-
-KX_GameObject *KX_BlenderSceneConverter::FindGameObject(Object *for_blenderobject)
-{
- KX_GameObject **obp = m_map_blender_to_gameobject[CHashedPtr(for_blenderobject)];
-
- return obp ? *obp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterGameMesh(RAS_MeshObject *gamemesh, Mesh *for_blendermesh)
-{
- if (for_blendermesh) { /* dynamically loaded meshes we don't want to keep lookups for */
- m_map_mesh_to_gamemesh.insert(CHashedPtr(for_blendermesh),gamemesh);
- }
- m_meshobjects.push_back(pair<KX_Scene *, RAS_MeshObject *> (m_currentScene,gamemesh));
-}
-
-RAS_MeshObject *KX_BlenderSceneConverter::FindGameMesh(Mesh *for_blendermesh)
-{
- RAS_MeshObject **meshp = m_map_mesh_to_gamemesh[CHashedPtr(for_blendermesh)];
-
- if (meshp) {
- return *meshp;
- }
- else {
- return NULL;
- }
-}
-
-void KX_BlenderSceneConverter::RegisterPolyMaterial(RAS_IPolyMaterial *polymat)
-{
- // First make sure we don't register the material twice
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator it;
- for (it = m_polymaterials.begin(); it != m_polymaterials.end(); ++it)
- if (it->second == polymat)
- return;
- m_polymaterials.push_back(pair<KX_Scene *, RAS_IPolyMaterial *> (m_currentScene, polymat));
-}
-
-void KX_BlenderSceneConverter::CachePolyMaterial(KX_Scene *scene, Material *mat, RAS_IPolyMaterial *polymat)
-{
- if (m_use_mat_cache && mat)
- m_polymat_cache[scene][mat] = polymat;
-}
-
-RAS_IPolyMaterial *KX_BlenderSceneConverter::FindCachedPolyMaterial(KX_Scene *scene, Material *mat)
-{
- return (m_use_mat_cache) ? m_polymat_cache[scene][mat] : NULL;
-}
-
-void KX_BlenderSceneConverter::CacheBlenderMaterial(KX_Scene *scene, Material *mat, BL_Material *blmat)
-{
- if (m_use_mat_cache && mat)
- m_mat_cache[scene][mat] = blmat;
-}
-
-BL_Material *KX_BlenderSceneConverter::FindCachedBlenderMaterial(KX_Scene *scene, Material *mat)
-{
- return (m_use_mat_cache) ? m_mat_cache[scene][mat] : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterInterpolatorList(BL_InterpolatorList *actList, bAction *for_act)
-{
- m_map_blender_to_gameAdtList.insert(CHashedPtr(for_act), actList);
-}
-
-BL_InterpolatorList *KX_BlenderSceneConverter::FindInterpolatorList(bAction *for_act)
-{
- BL_InterpolatorList **listp = m_map_blender_to_gameAdtList[CHashedPtr(for_act)];
- return listp ? *listp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterGameActuator(SCA_IActuator *act, bActuator *for_actuator)
-{
- m_map_blender_to_gameactuator.insert(CHashedPtr(for_actuator), act);
-}
-
-SCA_IActuator *KX_BlenderSceneConverter::FindGameActuator(bActuator *for_actuator)
-{
- SCA_IActuator **actp = m_map_blender_to_gameactuator[CHashedPtr(for_actuator)];
- return actp ? *actp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterGameController(SCA_IController *cont, bController *for_controller)
-{
- m_map_blender_to_gamecontroller.insert(CHashedPtr(for_controller), cont);
-}
-
-SCA_IController *KX_BlenderSceneConverter::FindGameController(bController *for_controller)
-{
- SCA_IController **contp = m_map_blender_to_gamecontroller[CHashedPtr(for_controller)];
- return contp ? *contp : NULL;
-}
-
-void KX_BlenderSceneConverter::RegisterWorldInfo(KX_WorldInfo *worldinfo)
-{
- m_worldinfos.push_back(pair<KX_Scene *, KX_WorldInfo *> (m_currentScene, worldinfo));
-}
-
-void KX_BlenderSceneConverter::ResetPhysicsObjectsAnimationIpo(bool clearIpo)
-{
- //TODO this entire function is deprecated, written for 2.4x
- //the functionality should be rewritten, currently it does nothing
-
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
- int i;
- for (i = 0; i < numScenes; i++) {
- KX_Scene *scene = scenes->at(i);
- CListValue *parentList = scene->GetRootParentList();
- int numObjects = parentList->GetCount();
- int g;
- for (g = 0; g < numObjects; g++) {
- KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g);
- if (gameObj->IsRecordAnimation()) {
- Object *blenderObject = gameObj->GetBlenderObject();
- if (blenderObject) {
-#if 0
- //erase existing ipo's
- Ipo* ipo = blenderObject->ipo;//findIpoForName(blenderObject->id.name+2);
- if (ipo) { //clear the curve data
- if (clearIpo) {//rcruiz
- IpoCurve *icu1;
-
- int numCurves = 0;
- for ( icu1 = (IpoCurve*)ipo->curve.first; icu1; ) {
-
- IpoCurve* tmpicu = icu1;
-
- /*int i;
- BezTriple *bezt;
- for ( bezt = tmpicu->bezt, i = 0; i < tmpicu->totvert; i++, bezt++) {
- printf("(%f,%f,%f),(%f,%f,%f),(%f,%f,%f)\n",bezt->vec[0][0],bezt->vec[0][1],bezt->vec[0][2],bezt->vec[1][0],bezt->vec[1][1],bezt->vec[1][2],bezt->vec[2][0],bezt->vec[2][1],bezt->vec[2][2]);
- }*/
-
- icu1 = icu1->next;
- numCurves++;
-
- BLI_remlink( &( blenderObject->ipo->curve ), tmpicu );
- if ( tmpicu->bezt )
- MEM_freeN( tmpicu->bezt );
- MEM_freeN( tmpicu );
- localDel_ipoCurve( tmpicu );
- }
- }
- }
- else {
- ipo = NULL; // XXX add_ipo(blenderObject->id.name+2, ID_OB);
- blenderObject->ipo = ipo;
- }
-#endif
- }
- }
- }
- }
-}
-
-void KX_BlenderSceneConverter::resetNoneDynamicObjectToIpo()
-{
- //TODO the functionality should be rewritten
-}
-
-// this generates ipo curves for position, rotation, allowing to use game physics in animation
-void KX_BlenderSceneConverter::WritePhysicsObjectToAnimationIpo(int frameNumber)
-{
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
- int i;
- for (i = 0; i < numScenes; i++) {
- KX_Scene *scene = scenes->at(i);
- //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment();
- CListValue *parentList = scene->GetObjectList();
- int numObjects = parentList->GetCount();
- int g;
- for (g = 0; g < numObjects; g++) {
- KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g);
- Object *blenderObject = gameObj->GetBlenderObject();
- if (blenderObject && blenderObject->parent == NULL && gameObj->IsRecordAnimation()) {
- if (blenderObject->adt == NULL)
- BKE_animdata_add_id(&blenderObject->id);
-
- if (blenderObject->adt) {
- const MT_Point3 &position = gameObj->NodeGetWorldPosition();
- //const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
- const MT_Matrix3x3 &orn = gameObj->NodeGetWorldOrientation();
-
- position.getValue(blenderObject->loc);
-
- float tmat[3][3];
- for (int r = 0; r < 3; r++)
- for (int c = 0; c < 3; c++)
- tmat[r][c] = (float)orn[c][r];
-
- mat3_to_compatible_eul(blenderObject->rot, blenderObject->rot, tmat);
-
- insert_keyframe(NULL, &blenderObject->id, NULL, NULL, "location", -1, (float)frameNumber, BEZT_KEYTYPE_JITTER, INSERTKEY_FAST);
- insert_keyframe(NULL, &blenderObject->id, NULL, NULL, "rotation_euler", -1, (float)frameNumber, BEZT_KEYTYPE_JITTER, INSERTKEY_FAST);
-
-#if 0
- const MT_Point3& position = gameObj->NodeGetWorldPosition();
- //const MT_Vector3& scale = gameObj->NodeGetWorldScaling();
- const MT_Matrix3x3& orn = gameObj->NodeGetWorldOrientation();
-
- float eulerAngles[3];
- float eulerAnglesOld[3] = {0.0f, 0.0f, 0.0f};
- float tmat[3][3];
-
- // XXX animato
- Ipo* ipo = blenderObject->ipo;
-
- //create the curves, if not existing, set linear if new
-
- IpoCurve *icu_lx = findIpoCurve((IpoCurve *)ipo->curve.first,"LocX");
- if (!icu_lx) {
- icu_lx = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_LOC_X, 1);
- if (icu_lx) icu_lx->ipo = IPO_LIN;
- }
- IpoCurve *icu_ly = findIpoCurve((IpoCurve *)ipo->curve.first,"LocY");
- if (!icu_ly) {
- icu_ly = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_LOC_Y, 1);
- if (icu_ly) icu_ly->ipo = IPO_LIN;
- }
- IpoCurve *icu_lz = findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ");
- if (!icu_lz) {
- icu_lz = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_LOC_Z, 1);
- if (icu_lz) icu_lz->ipo = IPO_LIN;
- }
- IpoCurve *icu_rx = findIpoCurve((IpoCurve *)ipo->curve.first,"RotX");
- if (!icu_rx) {
- icu_rx = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_ROT_X, 1);
- if (icu_rx) icu_rx->ipo = IPO_LIN;
- }
- IpoCurve *icu_ry = findIpoCurve((IpoCurve *)ipo->curve.first,"RotY");
- if (!icu_ry) {
- icu_ry = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_ROT_Y, 1);
- if (icu_ry) icu_ry->ipo = IPO_LIN;
- }
- IpoCurve *icu_rz = findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ");
- if (!icu_rz) {
- icu_rz = verify_ipocurve(&blenderObject->id, ipo->blocktype, NULL, NULL, NULL, OB_ROT_Z, 1);
- if (icu_rz) icu_rz->ipo = IPO_LIN;
- }
-
- if (icu_rx) eulerAnglesOld[0] = eval_icu( icu_rx, frameNumber - 1 ) / ((180 / 3.14159265f) / 10);
- if (icu_ry) eulerAnglesOld[1] = eval_icu( icu_ry, frameNumber - 1 ) / ((180 / 3.14159265f) / 10);
- if (icu_rz) eulerAnglesOld[2] = eval_icu( icu_rz, frameNumber - 1 ) / ((180 / 3.14159265f) / 10);
-
- // orn.getValue((float *)tmat); // uses the wrong ordering, cant use this
- for (int r = 0; r < 3; r++)
- for (int c = 0; c < 3; c++)
- tmat[r][c] = orn[c][r];
-
- // mat3_to_eul( eulerAngles,tmat); // better to use Mat3ToCompatibleEul
- mat3_to_compatible_eul( eulerAngles, eulerAnglesOld,tmat);
-
- //eval_icu
- for (int x = 0; x < 3; x++)
- eulerAngles[x] *= (float) ((180 / 3.14159265f) / 10.0);
-
- //fill the curves with data
- if (icu_lx) insert_vert_icu(icu_lx, frameNumber, position.x(), 1);
- if (icu_ly) insert_vert_icu(icu_ly, frameNumber, position.y(), 1);
- if (icu_lz) insert_vert_icu(icu_lz, frameNumber, position.z(), 1);
- if (icu_rx) insert_vert_icu(icu_rx, frameNumber, eulerAngles[0], 1);
- if (icu_ry) insert_vert_icu(icu_ry, frameNumber, eulerAngles[1], 1);
- if (icu_rz) insert_vert_icu(icu_rz, frameNumber, eulerAngles[2], 1);
-
- // Handles are corrected at the end, testhandles_ipocurve isn't needed yet
-#endif
- }
- }
- }
- }
-}
-
-void KX_BlenderSceneConverter::TestHandlesPhysicsObjectToAnimationIpo()
-{
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
- int i;
- for (i = 0; i < numScenes; i++) {
- KX_Scene *scene = scenes->at(i);
- //PHY_IPhysicsEnvironment* physEnv = scene->GetPhysicsEnvironment();
- CListValue *parentList = scene->GetRootParentList();
- int numObjects = parentList->GetCount();
- int g;
- for (g = 0; g < numObjects; g++) {
- KX_GameObject *gameObj = (KX_GameObject *)parentList->GetValue(g);
- if (gameObj->IsRecordAnimation()) {
- Object *blenderObject = gameObj->GetBlenderObject();
- if (blenderObject && blenderObject->adt) {
- bAction *act = verify_adt_action(&blenderObject->id, false);
- FCurve *fcu;
-
- if (!act) {
- continue;
- }
-
- /* for now, not much choice but to run this on all curves... */
- for (fcu = (FCurve *)act->curves.first; fcu; fcu = fcu->next) {
- /* Note: calling `sort_time_fcurve()` here is not needed, since
- * all keys have been added in 'right' order. */
- calchandles_fcurve(fcu);
- }
-#if 0
- // XXX animato
- Ipo* ipo = blenderObject->ipo;
-
- //create the curves, if not existing
- //testhandles_ipocurve checks for NULL
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocX"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocY"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"LocZ"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotX"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotY"));
- testhandles_ipocurve(findIpoCurve((IpoCurve *)ipo->curve.first,"RotZ"));
-#endif
- }
- }
- }
- }
-}
-
-#ifdef WITH_PYTHON
-PyObject *KX_BlenderSceneConverter::GetPyNamespace()
-{
- return m_ketsjiEngine->GetPyNamespace();
-}
-#endif
-
-vector<Main *> &KX_BlenderSceneConverter::GetMainDynamic()
-{
- return m_DynamicMaggie;
-}
-
-Main *KX_BlenderSceneConverter::GetMainDynamicPath(const char *path)
-{
- for (vector<Main *>::iterator it = m_DynamicMaggie.begin(); !(it == m_DynamicMaggie.end()); it++)
- if (BLI_path_cmp((*it)->name, path) == 0)
- return *it;
-
- return NULL;
-}
-
-void KX_BlenderSceneConverter::MergeAsyncLoads()
-{
- vector<KX_Scene *> *merge_scenes;
-
- vector<KX_LibLoadStatus *>::iterator mit;
- vector<KX_Scene *>::iterator sit;
-
- BLI_mutex_lock(&m_threadinfo->m_mutex);
-
- for (mit = m_mergequeue.begin(); mit != m_mergequeue.end(); ++mit) {
- merge_scenes = (vector<KX_Scene *> *)(*mit)->GetData();
-
- for (sit=merge_scenes->begin(); sit!=merge_scenes->end(); ++sit) {
- (*mit)->GetMergeScene()->MergeScene(*sit);
- delete (*sit);
- }
-
- delete merge_scenes;
- (*mit)->SetData(NULL);
-
- (*mit)->Finish();
- }
-
- m_mergequeue.clear();
-
- BLI_mutex_unlock(&m_threadinfo->m_mutex);
-}
-
-void KX_BlenderSceneConverter::FinalizeAsyncLoads()
-{
- // Finish all loading libraries.
- if (m_threadinfo) {
- BLI_task_pool_work_and_wait(m_threadinfo->m_pool);
- }
- // Merge all libraries data in the current scene, to avoid memory leak of unmerged scenes.
- MergeAsyncLoads();
-}
-
-void KX_BlenderSceneConverter::AddScenesToMergeQueue(KX_LibLoadStatus *status)
-{
- BLI_mutex_lock(&m_threadinfo->m_mutex);
- m_mergequeue.push_back(status);
- BLI_mutex_unlock(&m_threadinfo->m_mutex);
-}
-
-static void async_convert(TaskPool *pool, void *ptr, int UNUSED(threadid))
-{
- KX_Scene *new_scene = NULL;
- KX_LibLoadStatus *status = (KX_LibLoadStatus *)ptr;
- vector<Scene *> *scenes = (vector<Scene *> *)status->GetData();
- vector<KX_Scene *> *merge_scenes = new vector<KX_Scene *>(); // Deleted in MergeAsyncLoads
-
- for (unsigned int i = 0; i < scenes->size(); ++i) {
- new_scene = status->GetEngine()->CreateScene((*scenes)[i], true);
-
- if (new_scene)
- merge_scenes->push_back(new_scene);
-
- status->AddProgress((1.0f / scenes->size()) * 0.9f); // We'll call conversion 90% and merging 10% for now
- }
-
- delete scenes;
- status->SetData(merge_scenes);
-
- status->GetConverter()->AddScenesToMergeQueue(status);
-}
-
-KX_LibLoadStatus *KX_BlenderSceneConverter::LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options)
-{
- BlendHandle *bpy_openlib = BLO_blendhandle_from_memory(data, length);
-
- // Error checking is done in LinkBlendFile
- return LinkBlendFile(bpy_openlib, path, group, scene_merge, err_str, options);
-}
-
-KX_LibLoadStatus *KX_BlenderSceneConverter::LinkBlendFilePath(const char *filepath, char *group, KX_Scene *scene_merge, char **err_str, short options)
-{
- BlendHandle *bpy_openlib = BLO_blendhandle_from_file(filepath, NULL);
-
- // Error checking is done in LinkBlendFile
- return LinkBlendFile(bpy_openlib, filepath, group, scene_merge, err_str, options);
-}
-
-static void load_datablocks(Main *main_tmp, BlendHandle *bpy_openlib, const char *path, int idcode)
-{
- LinkNode *names = NULL;
-
- int totnames_dummy;
- names = BLO_blendhandle_get_datablock_names(bpy_openlib, idcode, &totnames_dummy);
-
- int i = 0;
- LinkNode *n = names;
- while (n) {
- BLO_library_link_named_part(main_tmp, &bpy_openlib, idcode, (char *)n->link);
- n = (LinkNode *)n->next;
- i++;
- }
- BLI_linklist_free(names, free); /* free linklist *and* each node's data */
-}
-
-KX_LibLoadStatus *KX_BlenderSceneConverter::LinkBlendFile(BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options)
-{
- Main *main_newlib; /* stored as a dynamic 'main' until we free it */
- const int idcode = BKE_idcode_from_name(group);
- ReportList reports;
- static char err_local[255];
-
-// TIMEIT_START(bge_link_blend_file);
-
- KX_LibLoadStatus *status;
-
- /* only scene and mesh supported right now */
- if (idcode != ID_SCE && idcode != ID_ME && idcode != ID_AC) {
- snprintf(err_local, sizeof(err_local), "invalid ID type given \"%s\"\n", group);
- *err_str = err_local;
- BLO_blendhandle_close(bpy_openlib);
- return NULL;
- }
-
- if (GetMainDynamicPath(path)) {
- snprintf(err_local, sizeof(err_local), "blend file already open \"%s\"\n", path);
- *err_str = err_local;
- BLO_blendhandle_close(bpy_openlib);
- return NULL;
- }
-
- if (bpy_openlib == NULL) {
- snprintf(err_local, sizeof(err_local), "could not open blendfile \"%s\"\n", path);
- *err_str = err_local;
- return NULL;
- }
-
- main_newlib = BKE_main_new();
- BKE_reports_init(&reports, RPT_STORE);
-
- short flag = 0; /* don't need any special options */
- /* created only for linking, then freed */
- Main *main_tmp = BLO_library_link_begin(main_newlib, &bpy_openlib, (char *)path);
-
- load_datablocks(main_tmp, bpy_openlib, path, idcode);
-
- if (idcode == ID_SCE && options & LIB_LOAD_LOAD_SCRIPTS) {
- load_datablocks(main_tmp, bpy_openlib, path, ID_TXT);
- }
-
- /* now do another round of linking for Scenes so all actions are properly loaded */
- if (idcode == ID_SCE && options & LIB_LOAD_LOAD_ACTIONS) {
- load_datablocks(main_tmp, bpy_openlib, path, ID_AC);
- }
-
- BLO_library_link_end(main_tmp, &bpy_openlib, flag, NULL, NULL);
-
- BLO_blendhandle_close(bpy_openlib);
-
- BKE_reports_clear(&reports);
- /* done linking */
-
- /* needed for lookups*/
- GetMainDynamic().push_back(main_newlib);
- BLI_strncpy(main_newlib->name, path, sizeof(main_newlib->name));
-
-
- status = new KX_LibLoadStatus(this, m_ketsjiEngine, scene_merge, path);
-
- if (idcode == ID_ME) {
- /* Convert all new meshes into BGE meshes */
- ID *mesh;
-
- for (mesh = (ID *)main_newlib->mesh.first; mesh; mesh = (ID *)mesh->next ) {
- if (options & LIB_LOAD_VERBOSE)
- printf("MeshName: %s\n", mesh->name + 2);
- RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)mesh, NULL, scene_merge, this, false); // For now only use the libloading option for scenes, which need to handle materials/shaders
- scene_merge->GetLogicManager()->RegisterMeshName(meshobj->GetName(), meshobj);
- }
- }
- else if (idcode == ID_AC) {
- /* Convert all actions */
- ID *action;
-
- for (action= (ID *)main_newlib->action.first; action; action = (ID *)action->next) {
- if (options & LIB_LOAD_VERBOSE)
- printf("ActionName: %s\n", action->name + 2);
- scene_merge->GetLogicManager()->RegisterActionName(action->name + 2, action);
- }
- }
- else if (idcode == ID_SCE) {
- /* Merge all new linked in scene into the existing one */
- ID *scene;
- // scenes gets deleted by the thread when it's done using it (look in async_convert())
- vector<Scene *> *scenes = (options & LIB_LOAD_ASYNC) ? new vector<Scene *>() : NULL;
-
- for (scene = (ID *)main_newlib->scene.first; scene; scene = (ID *)scene->next ) {
- if (options & LIB_LOAD_VERBOSE)
- printf("SceneName: %s\n", scene->name + 2);
-
- if (options & LIB_LOAD_ASYNC) {
- scenes->push_back((Scene *)scene);
- }
- else {
- /* merge into the base scene */
- KX_Scene* other = m_ketsjiEngine->CreateScene((Scene *)scene, true);
- scene_merge->MergeScene(other);
-
- // RemoveScene(other); // Don't run this, it frees the entire scene converter data, just delete the scene
- delete other;
- }
- }
-
- if (options & LIB_LOAD_ASYNC) {
- status->SetData(scenes);
- BLI_task_pool_push(m_threadinfo->m_pool, async_convert, (void *)status, false, TASK_PRIORITY_LOW);
- }
-
-#ifdef WITH_PYTHON
- /* Handle any text datablocks */
- if (options & LIB_LOAD_LOAD_SCRIPTS)
- addImportMain(main_newlib);
-#endif
-
- /* Now handle all the actions */
- if (options & LIB_LOAD_LOAD_ACTIONS) {
- ID *action;
-
- for (action = (ID *)main_newlib->action.first; action; action = (ID *)action->next) {
- if (options & LIB_LOAD_VERBOSE)
- printf("ActionName: %s\n", action->name + 2);
- scene_merge->GetLogicManager()->RegisterActionName(action->name + 2, action);
- }
- }
- }
-
- if (!(options & LIB_LOAD_ASYNC))
- status->Finish();
-
-// TIMEIT_END(bge_link_blend_file);
-
- m_status_map[main_newlib->name] = status;
- return status;
-}
-
-/* Note m_map_*** are all ok and don't need to be freed
- * most are temp and NewRemoveObject frees m_map_gameobject_to_blender */
-bool KX_BlenderSceneConverter::FreeBlendFile(Main *maggie)
-{
- int maggie_index = -1;
- int i = 0;
-
- if (maggie == NULL)
- return false;
-
- // If the given library is currently in loading, we do nothing.
- if (m_status_map.count(maggie->name)) {
- BLI_mutex_lock(&m_threadinfo->m_mutex);
- const bool finished = m_status_map[maggie->name]->IsFinished();
- BLI_mutex_unlock(&m_threadinfo->m_mutex);
-
- if (!finished) {
- printf("Library (%s) is currently being loaded asynchronously, and cannot be freed until this process is done\n", maggie->name);
- return false;
- }
- }
-
- /* tag all false except the one we remove */
- for (vector<Main *>::iterator it = m_DynamicMaggie.begin(); !(it == m_DynamicMaggie.end()); it++) {
- Main *main = *it;
- if (main != maggie) {
- BKE_main_id_tag_all(main, LIB_TAG_DOIT, false);
- }
- else {
- maggie_index = i;
- }
- i++;
- }
-
- /* should never happen but just to be safe */
- if (maggie_index == -1)
- return false;
-
- m_DynamicMaggie.erase(m_DynamicMaggie.begin() + maggie_index);
- BKE_main_id_tag_all(maggie, LIB_TAG_DOIT, true);
-
- /* free all tagged objects */
- KX_SceneList *scenes = m_ketsjiEngine->CurrentScenes();
- int numScenes = scenes->size();
-
- for (int scene_idx = 0; scene_idx < numScenes; scene_idx++) {
- KX_Scene *scene = scenes->at(scene_idx);
- if (IS_TAGGED(scene->GetBlenderScene())) {
- m_ketsjiEngine->RemoveScene(scene->GetName());
- m_mat_cache.erase(scene);
- m_polymat_cache.erase(scene);
- scene_idx--;
- numScenes--;
- }
- else {
- /* in case the mesh might be refered to later */
- {
- CTR_Map<STR_HashedString, void *> &mapStringToMeshes = scene->GetLogicManager()->GetMeshMap();
-
- for (int i = 0; i < mapStringToMeshes.size(); i++) {
- RAS_MeshObject *meshobj = (RAS_MeshObject *) *mapStringToMeshes.at(i);
- if (meshobj && IS_TAGGED(meshobj->GetMesh())) {
- STR_HashedString mn = meshobj->GetName();
- mapStringToMeshes.remove(mn);
- m_map_mesh_to_gamemesh.remove(CHashedPtr(meshobj->GetMesh()));
- i--;
- }
- }
- }
-
- /* Now unregister actions */
- {
- CTR_Map<STR_HashedString, void *> &mapStringToActions = scene->GetLogicManager()->GetActionMap();
-
- for (int i = 0; i < mapStringToActions.size(); i++) {
- ID *action = (ID*) *mapStringToActions.at(i);
-
- if (IS_TAGGED(action)) {
- STR_HashedString an = action->name + 2;
- mapStringToActions.remove(an);
- m_map_blender_to_gameAdtList.remove(CHashedPtr(action));
- i--;
- }
- }
- }
-
- //scene->FreeTagged(); /* removed tagged objects and meshes*/
- CListValue *obj_lists[] = {scene->GetObjectList(), scene->GetInactiveList(), NULL};
-
- for (int ob_ls_idx = 0; obj_lists[ob_ls_idx]; ob_ls_idx++) {
- CListValue *obs = obj_lists[ob_ls_idx];
- RAS_MeshObject *mesh;
-
- for (int ob_idx = 0; ob_idx < obs->GetCount(); ob_idx++) {
- KX_GameObject *gameobj = (KX_GameObject*)obs->GetValue(ob_idx);
- if (IS_TAGGED(gameobj->GetBlenderObject())) {
- int size_before = obs->GetCount();
-
- /* Eventually calls RemoveNodeDestructObject
- * frees m_map_gameobject_to_blender from UnregisterGameObject */
- scene->RemoveObject(gameobj);
-
- if (size_before != obs->GetCount())
- ob_idx--;
- else {
- printf("ERROR COULD NOT REMOVE \"%s\"\n", gameobj->GetName().ReadPtr());
- }
- }
- else {
- gameobj->RemoveTaggedActions();
- /* free the mesh, we could be referecing a linked one! */
- int mesh_index = gameobj->GetMeshCount();
- while (mesh_index--) {
- mesh = gameobj->GetMesh(mesh_index);
- if (IS_TAGGED(mesh->GetMesh())) {
- gameobj->RemoveMeshes(); /* XXX - slack, should only remove meshes that are library items but mostly objects only have 1 mesh */
- break;
- }
- else {
- /* also free the mesh if it's using a tagged material */
- int mat_index = mesh->NumMaterials();
- while (mat_index--) {
- if (IS_TAGGED(mesh->GetMeshMaterial(mat_index)->m_bucket->GetPolyMaterial()->GetBlenderMaterial())) {
- gameobj->RemoveMeshes(); /* XXX - slack, same as above */
- break;
- }
- }
- }
- }
-
- /* make sure action actuators are not referencing tagged actions */
- for (unsigned int act_idx = 0; act_idx < gameobj->GetActuators().size(); act_idx++) {
- if (gameobj->GetActuators()[act_idx]->IsType(SCA_IActuator::KX_ACT_ACTION)) {
- BL_ActionActuator *act = (BL_ActionActuator *)gameobj->GetActuators()[act_idx];
- if (IS_TAGGED(act->GetAction()))
- act->SetAction(NULL);
- }
- }
- }
- }
- }
- }
- }
-
- int size;
-
- // delete the entities of this scene
- /* TODO - */
-#if 0
- vector<pair<KX_Scene*,KX_WorldInfo*> >::iterator worldit;
- size = m_worldinfos.size();
- for (i=0, worldit=m_worldinfos.begin(); i<size; ) {
- if ((*worldit).second) {
- delete (*worldit).second;
- *worldit = m_worldinfos.back();
- m_worldinfos.pop_back();
- size--;
- } else {
- i++;
- worldit++;
- }
- }
-#endif
-
-
- /* Worlds don't reference original blender data so we need to make a set from them */
- typedef std::set<KX_WorldInfo *> KX_WorldInfoSet;
- KX_WorldInfoSet worldset;
- for (int scene_idx = 0; scene_idx < numScenes; scene_idx++) {
- KX_Scene *scene = scenes->at(scene_idx);
- if (scene->GetWorldInfo())
- worldset.insert(scene->GetWorldInfo());
- }
-
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator worldit;
- size = m_worldinfos.size();
- for (i = 0, worldit = m_worldinfos.begin(); i < size;) {
- if (worldit->second && (worldset.count(worldit->second)) == 0) {
- delete worldit->second;
- *worldit = m_worldinfos.back();
- m_worldinfos.pop_back();
- size--;
- }
- else {
- i++;
- worldit++;
- }
- }
- worldset.clear();
- /* done freeing the worlds */
-
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator polymit;
- size = m_polymaterials.size();
-
- for (i = 0, polymit = m_polymaterials.begin(); i < size; ) {
- RAS_IPolyMaterial *mat = polymit->second;
- Material *bmat = NULL;
-
- KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial *>(mat);
- bmat = bl_mat->GetBlenderMaterial();
-
- if (IS_TAGGED(bmat)) {
- /* only remove from bucket */
- polymit->first->GetBucketManager()->RemoveMaterial(mat);
- }
-
- i++;
- polymit++;
- }
-
- for (i = 0, polymit = m_polymaterials.begin(); i < size; ) {
- RAS_IPolyMaterial *mat = polymit->second;
- Material *bmat = NULL;
-
- KX_BlenderMaterial *bl_mat = static_cast<KX_BlenderMaterial*>(mat);
- bmat = bl_mat->GetBlenderMaterial();
-
- if (IS_TAGGED(bmat)) {
- // Remove the poly material coresponding to this Blender Material.
- m_polymat_cache[polymit->first].erase(bmat);
- delete polymit->second;
- *polymit = m_polymaterials.back();
- m_polymaterials.pop_back();
- size--;
- } else {
- i++;
- polymit++;
- }
- }
-
- vector<pair<KX_Scene *, BL_Material *> >::iterator matit;
- size = m_materials.size();
- for (i = 0, matit = m_materials.begin(); i < size; ) {
- BL_Material *mat = matit->second;
- if (IS_TAGGED(mat->material)) {
- // Remove the bl material coresponding to this Blender Material.
- m_mat_cache[matit->first].erase(mat->material);
- delete matit->second;
- *matit = m_materials.back();
- m_materials.pop_back();
- size--;
- }
- else {
- i++;
- matit++;
- }
- }
-
- vector<pair<KX_Scene *, RAS_MeshObject *> >::iterator meshit;
- RAS_BucketManager::BucketList::iterator bit;
- list<RAS_MeshSlot>::iterator msit;
- RAS_BucketManager::BucketList buckets;
-
- size = m_meshobjects.size();
- for (i = 0, meshit = m_meshobjects.begin(); i < size;) {
- RAS_MeshObject *me = meshit->second;
- if (IS_TAGGED(me->GetMesh())) {
- // Before deleting the mesh object, make sure the rasterizer is
- // no longer referencing it.
- buckets = meshit->first->GetBucketManager()->GetSolidBuckets();
- for (bit = buckets.begin(); bit != buckets.end(); bit++) {
- msit = (*bit)->msBegin();
-
- while (msit != (*bit)->msEnd()) {
- if (msit->m_mesh == meshit->second)
- (*bit)->RemoveMesh(&(*msit++));
- else
- msit++;
- }
- }
-
- // And now the alpha buckets
- buckets = meshit->first->GetBucketManager()->GetAlphaBuckets();
- for (bit = buckets.begin(); bit != buckets.end(); bit++) {
- msit = (*bit)->msBegin();
-
- while (msit != (*bit)->msEnd()) {
- if (msit->m_mesh == meshit->second)
- (*bit)->RemoveMesh(&(*msit++));
- else
- msit++;
- }
- }
-
- // Now it should be safe to delete
- delete meshit->second;
- *meshit = m_meshobjects.back();
- m_meshobjects.pop_back();
- size--;
- }
- else {
- i++;
- meshit++;
- }
- }
-
-#ifdef WITH_PYTHON
- /* make sure this maggie is removed from the import list if it's there
- * (this operation is safe if it isn't in the list) */
- removeImportMain(maggie);
-#endif
-
- delete m_status_map[maggie->name];
- m_status_map.erase(maggie->name);
-
- BKE_main_free(maggie);
-
- return true;
-}
-
-bool KX_BlenderSceneConverter::FreeBlendFile(const char *path)
-{
- return FreeBlendFile(GetMainDynamicPath(path));
-}
-
-bool KX_BlenderSceneConverter::MergeScene(KX_Scene *to, KX_Scene *from)
-{
- {
- vector<pair<KX_Scene *, KX_WorldInfo *> >::iterator itp = m_worldinfos.begin();
- while (itp != m_worldinfos.end()) {
- if (itp->first == from)
- itp->first = to;
- itp++;
- }
- }
-
- {
- vector<pair<KX_Scene *, RAS_IPolyMaterial *> >::iterator itp = m_polymaterials.begin();
- while (itp != m_polymaterials.end()) {
- if (itp->first == from) {
- itp->first = to;
-
- /* also switch internal data */
- RAS_IPolyMaterial *mat = itp->second;
- mat->Replace_IScene(to);
- }
- itp++;
- }
- }
-
- {
- vector<pair<KX_Scene *, RAS_MeshObject *> >::iterator itp = m_meshobjects.begin();
- while (itp != m_meshobjects.end()) {
- if (itp->first == from)
- itp->first = to;
- itp++;
- }
- }
-
- {
- vector<pair<KX_Scene *, BL_Material *> >::iterator itp = m_materials.begin();
- while (itp != m_materials.end()) {
- if (itp->first == from)
- itp->first = to;
- itp++;
- }
- }
-
- MaterialCache::iterator matcacheit = m_mat_cache.find(from);
- if (matcacheit != m_mat_cache.end()) {
- // Merge cached BL_Material map.
- m_mat_cache[to].insert(matcacheit->second.begin(), matcacheit->second.end());
- m_mat_cache.erase(matcacheit);
- }
-
- PolyMaterialCache::iterator polymatcacheit = m_polymat_cache.find(from);
- if (polymatcacheit != m_polymat_cache.end()) {
- // Merge cached RAS_IPolyMaterial map.
- m_polymat_cache[to].insert(polymatcacheit->second.begin(), polymatcacheit->second.end());
- m_polymat_cache.erase(polymatcacheit);
- }
-
- return true;
-}
-
-/* This function merges a mesh from the current scene into another main
- * it does not convert */
-RAS_MeshObject *KX_BlenderSceneConverter::ConvertMeshSpecial(KX_Scene *kx_scene, Main *maggie, const char *name)
-{
- /* Find a mesh in the current main */
- ID *me= static_cast<ID *>(BLI_findstring(&m_maggie->mesh, name, offsetof(ID, name) + 2));
- Main *from_maggie = m_maggie;
-
- if (me == NULL) {
- // The mesh wasn't in the current main, try any dynamic (i.e., LibLoaded) ones
- vector<Main *>::iterator it;
-
- for (it = GetMainDynamic().begin(); it != GetMainDynamic().end(); it++) {
- me = static_cast<ID *>(BLI_findstring(&(*it)->mesh, name, offsetof(ID, name) + 2));
- from_maggie = *it;
-
- if (me)
- break;
- }
- }
-
- if (me == NULL) {
- printf("Could not be found \"%s\"\n", name);
- return NULL;
- }
-
- /* Watch this!, if its used in the original scene can cause big troubles */
- if (me->us > 0) {
-#ifdef DEBUG
- printf("Mesh has a user \"%s\"\n", name);
-#endif
- me = (ID*)BKE_mesh_copy(from_maggie, (Mesh*)me);
- id_us_min(me);
- }
- BLI_remlink(&from_maggie->mesh, me); /* even if we made the copy it needs to be removed */
- BLI_addtail(&maggie->mesh, me);
-
- /* Must copy the materials this uses else we cant free them */
- {
- Mesh *mesh = (Mesh *)me;
-
- /* ensure all materials are tagged */
- for (int i = 0; i < mesh->totcol; i++) {
- if (mesh->mat[i])
- mesh->mat[i]->id.tag &= ~LIB_TAG_DOIT;
- }
-
- for (int i = 0; i < mesh->totcol; i++) {
- Material *mat_old = mesh->mat[i];
-
- /* if its tagged its a replaced material */
- if (mat_old && (mat_old->id.tag & LIB_TAG_DOIT) == 0) {
- Material *mat_old = mesh->mat[i];
- Material *mat_new = BKE_material_copy(from_maggie, mat_old);
-
- mat_new->id.tag |= LIB_TAG_DOIT;
- id_us_min(&mat_old->id);
-
- BLI_remlink(&from_maggie->mat, mat_new); // BKE_material_copy uses G.main, and there is no BKE_material_copy_ex
- BLI_addtail(&maggie->mat, mat_new);
-
- mesh->mat[i] = mat_new;
-
- /* the same material may be used twice */
- for (int j = i + 1; j < mesh->totcol; j++) {
- if (mesh->mat[j] == mat_old) {
- mesh->mat[j] = mat_new;
- id_us_plus(&mat_new->id);
- id_us_min(&mat_old->id);
- }
- }
- }
- }
- }
-
- m_currentScene = kx_scene; // This needs to be set in case we LibLoaded earlier
- RAS_MeshObject *meshobj = BL_ConvertMesh((Mesh *)me, NULL, kx_scene, this, false);
- kx_scene->GetLogicManager()->RegisterMeshName(meshobj->GetName(),meshobj);
- m_map_mesh_to_gamemesh.clear(); /* This is at runtime so no need to keep this, BL_ConvertMesh adds */
- return meshobj;
-}
diff --git a/source/gameengine/Converter/KX_BlenderSceneConverter.h b/source/gameengine/Converter/KX_BlenderSceneConverter.h
deleted file mode 100644
index 40c71a4d74b..00000000000
--- a/source/gameengine/Converter/KX_BlenderSceneConverter.h
+++ /dev/null
@@ -1,232 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_BlenderSceneConverter.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_BLENDERSCENECONVERTER_H__
-#define __KX_BLENDERSCENECONVERTER_H__
-
-#include "EXP_HashedPtr.h"
-#include "CTR_Map.h"
-#include <stdio.h>
-
-#include "KX_ISceneConverter.h"
-#include "KX_IpoConvert.h"
-
-#include <map>
-
-using namespace std;
-
-class KX_WorldInfo;
-class SCA_IActuator;
-class SCA_IController;
-class RAS_MeshObject;
-class RAS_IPolyMaterial;
-class BL_InterpolatorList;
-class BL_Material;
-struct Main;
-struct Scene;
-struct ThreadInfo;
-struct Material;
-
-typedef map<KX_Scene*, map<Material*, BL_Material*> > MaterialCache;
-typedef map<KX_Scene*, map<Material*, RAS_IPolyMaterial*> > PolyMaterialCache;
-
-class KX_BlenderSceneConverter : public KX_ISceneConverter
-{
- // Use vector of pairs to allow removal of entities between scene switch
- vector<pair<KX_Scene*,KX_WorldInfo*> > m_worldinfos;
- vector<pair<KX_Scene*,RAS_IPolyMaterial*> > m_polymaterials;
- vector<pair<KX_Scene*,RAS_MeshObject*> > m_meshobjects;
- vector<pair<KX_Scene*,BL_Material *> > m_materials;
-
- vector<class KX_LibLoadStatus*> m_mergequeue;
- ThreadInfo *m_threadinfo;
-
- // Cached material conversions
- MaterialCache m_mat_cache;
- PolyMaterialCache m_polymat_cache;
-
- // Saved KX_LibLoadStatus objects
- map<char *, class KX_LibLoadStatus*> m_status_map;
-
- // Should also have a list of collision shapes.
- // For the time being this is held in KX_Scene::m_shapes
-
- CTR_Map<CHashedPtr,KX_GameObject*> m_map_blender_to_gameobject; /* cleared after conversion */
- CTR_Map<CHashedPtr,RAS_MeshObject*> m_map_mesh_to_gamemesh; /* cleared after conversion */
- CTR_Map<CHashedPtr,SCA_IActuator*> m_map_blender_to_gameactuator; /* cleared after conversion */
- CTR_Map<CHashedPtr,SCA_IController*>m_map_blender_to_gamecontroller; /* cleared after conversion */
-
- CTR_Map<CHashedPtr,BL_InterpolatorList*> m_map_blender_to_gameAdtList;
-
- Main* m_maggie;
- vector<struct Main*> m_DynamicMaggie;
-
- STR_String m_newfilename;
- class KX_KetsjiEngine* m_ketsjiEngine;
- class KX_Scene* m_currentScene; // Scene being converted
- bool m_alwaysUseExpandFraming;
- bool m_usemat;
- bool m_useglslmat;
- bool m_use_mat_cache;
-
-public:
- KX_BlenderSceneConverter(
- Main* maggie,
- class KX_KetsjiEngine* engine
- );
-
- virtual ~KX_BlenderSceneConverter();
-
- /* Scenename: name of the scene to be converted.
- * destinationscene: pass an empty scene, everything goes into this
- * dictobj: python dictionary (for pythoncontrollers)
- */
- virtual void ConvertScene(
- class KX_Scene* destinationscene,
- class RAS_IRasterizer* rendertools,
- class RAS_ICanvas* canvas,
- bool libloading=false
- );
- virtual void RemoveScene(class KX_Scene *scene);
-
- void SetNewFileName(const STR_String& filename);
- bool TryAndLoadNewFile();
-
- void SetAlwaysUseExpandFraming(bool to_what);
-
- void RegisterGameObject(KX_GameObject *gameobject, struct Object *for_blenderobject);
- void UnregisterGameObject(KX_GameObject *gameobject);
- KX_GameObject *FindGameObject(struct Object *for_blenderobject);
-
- void RegisterGameMesh(RAS_MeshObject *gamemesh, struct Mesh *for_blendermesh);
- RAS_MeshObject *FindGameMesh(struct Mesh *for_blendermesh/*, unsigned int onlayer*/);
-
- void RegisterPolyMaterial(RAS_IPolyMaterial *polymat);
- void CachePolyMaterial(KX_Scene *scene, Material *mat, RAS_IPolyMaterial *polymat);
- RAS_IPolyMaterial *FindCachedPolyMaterial(KX_Scene *scene, Material *mat);
-
- void RegisterBlenderMaterial(BL_Material *mat);
- void CacheBlenderMaterial(KX_Scene *scene, Material *mat, BL_Material *blmat);
- BL_Material *FindCachedBlenderMaterial(KX_Scene *scene, Material *mat);
-
- void RegisterInterpolatorList(BL_InterpolatorList *actList, struct bAction *for_act);
- BL_InterpolatorList *FindInterpolatorList(struct bAction *for_act);
-
- void RegisterGameActuator(SCA_IActuator *act, struct bActuator *for_actuator);
- SCA_IActuator *FindGameActuator(struct bActuator *for_actuator);
-
- void RegisterGameController(SCA_IController *cont, struct bController *for_controller);
- SCA_IController *FindGameController(struct bController *for_controller);
-
- void RegisterWorldInfo(KX_WorldInfo *worldinfo);
-
- virtual void ResetPhysicsObjectsAnimationIpo(bool clearIpo);
-
- ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic
- virtual void resetNoneDynamicObjectToIpo();
-
- ///this generates ipo curves for position, rotation, allowing to use game physics in animation
- virtual void WritePhysicsObjectToAnimationIpo(int frameNumber);
- virtual void TestHandlesPhysicsObjectToAnimationIpo();
-
- // use blender materials
- virtual void SetMaterials(bool val);
- virtual bool GetMaterials();
-
- // use blender glsl materials
- virtual void SetGLSLMaterials(bool val);
- virtual bool GetGLSLMaterials();
-
- // cache materials during conversion
- virtual void SetCacheMaterials(bool val);
- virtual bool GetCacheMaterials();
-
- struct Scene* GetBlenderSceneForName(const STR_String& name);
-
-// struct Main* GetMain() { return m_maggie; }
- struct Main* GetMainDynamicPath(const char *path);
- vector<struct Main*> &GetMainDynamic();
-
- class KX_LibLoadStatus *LinkBlendFileMemory(void *data, int length, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options);
- class KX_LibLoadStatus *LinkBlendFilePath(const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options);
- class KX_LibLoadStatus *LinkBlendFile(struct BlendHandle *bpy_openlib, const char *path, char *group, KX_Scene *scene_merge, char **err_str, short options);
- bool MergeScene(KX_Scene *to, KX_Scene *from);
- RAS_MeshObject *ConvertMeshSpecial(KX_Scene* kx_scene, Main *maggie, const char *name);
- bool FreeBlendFile(struct Main *maggie);
- bool FreeBlendFile(const char *path);
-
- virtual void MergeAsyncLoads();
- virtual void FinalizeAsyncLoads();
- void AddScenesToMergeQueue(class KX_LibLoadStatus *status);
-
- void PrintStats() {
- printf("BGE STATS!\n");
-
- printf("\nAssets...\n");
- printf("\t m_worldinfos: %d\n", (int)m_worldinfos.size());
- printf("\t m_polymaterials: %d\n", (int)m_polymaterials.size());
- printf("\t m_meshobjects: %d\n", (int)m_meshobjects.size());
- printf("\t m_materials: %d\n", (int)m_materials.size());
-
- printf("\nMappings...\n");
- printf("\t m_map_blender_to_gameobject: %d\n", m_map_blender_to_gameobject.size());
- printf("\t m_map_mesh_to_gamemesh: %d\n", m_map_mesh_to_gamemesh.size());
- printf("\t m_map_blender_to_gameactuator: %d\n", m_map_blender_to_gameactuator.size());
- printf("\t m_map_blender_to_gamecontroller: %d\n", m_map_blender_to_gamecontroller.size());
- printf("\t m_map_blender_to_gameAdtList: %d\n", m_map_blender_to_gameAdtList.size());
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_printmemlist_pydict();
-#endif
-// /printf("\t m_ketsjiEngine->m_scenes: %d\n", m_ketsjiEngine->CurrentScenes()->size());
- }
-
- /* LibLoad Options */
- enum
- {
- LIB_LOAD_LOAD_ACTIONS = 1,
- LIB_LOAD_VERBOSE = 2,
- LIB_LOAD_LOAD_SCRIPTS = 4,
- LIB_LOAD_ASYNC = 8,
- };
-
-
-
-#ifdef WITH_PYTHON
- PyObject *GetPyNamespace();
-#endif
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BlenderSceneConverter")
-#endif
-};
-
-#endif /* __KX_BLENDERSCENECONVERTER_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertActuators.cpp b/source/gameengine/Converter/KX_ConvertActuators.cpp
deleted file mode 100644
index 974dcbca95b..00000000000
--- a/source/gameengine/Converter/KX_ConvertActuators.cpp
+++ /dev/null
@@ -1,1146 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Convert Blender actuators for use in the GameEngine
- */
-
-/** \file gameengine/Converter/KX_ConvertActuators.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include <math.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "KX_BlenderSceneConverter.h"
-#include "KX_ConvertActuators.h"
-
-#ifdef WITH_AUDASPACE
-# include AUD_SOUND_H
-#endif
-
-// Actuators
-//SCA logiclibrary native logicbricks
-#include "SCA_PropertyActuator.h"
-#include "SCA_LogicManager.h"
-#include "SCA_RandomActuator.h"
-#include "SCA_2DFilterActuator.h"
-
-// Ketsji specific logicbricks
-#include "KX_SceneActuator.h"
-#include "KX_SoundActuator.h"
-#include "KX_ObjectActuator.h"
-#include "KX_TrackToActuator.h"
-#include "KX_ConstraintActuator.h"
-#include "KX_CameraActuator.h"
-#include "KX_GameActuator.h"
-#include "KX_StateActuator.h"
-#include "KX_VisibilityActuator.h"
-#include "KX_SCA_AddObjectActuator.h"
-#include "KX_SCA_EndObjectActuator.h"
-#include "KX_SCA_ReplaceMeshActuator.h"
-#include "KX_ParentActuator.h"
-#include "KX_SCA_DynamicActuator.h"
-#include "KX_SteeringActuator.h"
-#include "KX_MouseActuator.h"
-
-#include "KX_Scene.h"
-#include "KX_KetsjiEngine.h"
-
-#include "EXP_IntValue.h"
-#include "KX_GameObject.h"
-
-/* This little block needed for linking to Blender... */
-#include "BKE_text.h"
-#include "BLI_blenlib.h"
-#include "BLI_math.h"
-#include "BLI_path_util.h"
-
-#include "KX_NetworkMessageActuator.h"
-
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_sound_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_actuator_types.h"
-#include "DNA_packedFile_types.h"
-#include "BL_ActionActuator.h"
-#include "BL_ShapeActionActuator.h"
-#include "BL_ArmatureActuator.h"
-#include "RNA_access.h"
-#include "BL_Action.h"
-/* end of blender include block */
-
-#include "BL_BlenderDataConversion.h"
-
-/**
- * KX_flt_trunc needed to round 'almost' zero values to zero, else velocities etc. are incorrectly set
- */
-
-BLI_INLINE float KX_flt_trunc(const float x)
-{
- return ( x < 0.0001f && x > -0.0001f ) ? 0.0f : x;
-}
-
-void BL_ConvertActuators(const char* maggiename,
- struct Object* blenderobject,
- KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr,
- KX_Scene* scene,
- KX_KetsjiEngine* ketsjiEngine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- KX_BlenderSceneConverter* converter
- )
-{
-
- int uniqueint = 0;
- int actcount = 0;
- int executePriority = 0;
- bActuator* bact = (bActuator*) blenderobject->actuators.first;
- while (bact)
- {
- actcount++;
- bact = bact->next;
- }
- gameobj->ReserveActuator(actcount);
- bact = (bActuator*) blenderobject->actuators.first;
- while (bact)
- {
- STR_String uniquename = bact->name;
- STR_String& objectname = gameobj->GetName();
-
- SCA_IActuator* baseact = NULL;
- switch (bact->type)
- {
- case ACT_OBJECT:
- {
- bObjectActuator* obact = (bObjectActuator*) bact->data;
- KX_GameObject* obref = NULL;
- MT_Vector3 forcevec(KX_flt_trunc(obact->forceloc[0]),
- KX_flt_trunc(obact->forceloc[1]),
- KX_flt_trunc(obact->forceloc[2]));
- MT_Vector3 torquevec(obact->forcerot[0],
- obact->forcerot[1],
- obact->forcerot[2]);
- MT_Vector3 dlocvec(KX_flt_trunc(obact->dloc[0]),
- KX_flt_trunc(obact->dloc[1]),
- KX_flt_trunc(obact->dloc[2]));
- MT_Vector3 drotvec(KX_flt_trunc(obact->drot[0]),
- obact->drot[1],obact->drot[2]);
- MT_Vector3 linvelvec(KX_flt_trunc(obact->linearvelocity[0]),
- KX_flt_trunc(obact->linearvelocity[1]),
- KX_flt_trunc(obact->linearvelocity[2]));
- MT_Vector3 angvelvec(KX_flt_trunc(obact->angularvelocity[0]),
- KX_flt_trunc(obact->angularvelocity[1]),
- KX_flt_trunc(obact->angularvelocity[2]));
- short damping = obact->damping;
-
- /* Blender uses a bit vector internally for the local-flags. In */
- /* KX, we have four bools. The compiler should be smart enough */
- /* to do the right thing. We need to explicitly convert here! */
-
- KX_LocalFlags bitLocalFlag;
-
- bitLocalFlag.Force = bool((obact->flag & ACT_FORCE_LOCAL)!=0);
- bitLocalFlag.Torque = bool((obact->flag & ACT_TORQUE_LOCAL) !=0);//rlocal;
- bitLocalFlag.DLoc = bool((obact->flag & ACT_DLOC_LOCAL)!=0);
- bitLocalFlag.DRot = bool((obact->flag & ACT_DROT_LOCAL)!=0);
- bitLocalFlag.LinearVelocity = bool((obact->flag & ACT_LIN_VEL_LOCAL)!=0);
- bitLocalFlag.AngularVelocity = bool((obact->flag & ACT_ANG_VEL_LOCAL)!=0);
- bitLocalFlag.ServoControl = bool(obact->type == ACT_OBJECT_SERVO);
- bitLocalFlag.CharacterMotion = bool(obact->type == ACT_OBJECT_CHARACTER);
- bitLocalFlag.CharacterJump = bool((obact->flag & ACT_CHAR_JUMP)!=0);
- bitLocalFlag.AddOrSetLinV = bool((obact->flag & ACT_ADD_LIN_VEL)!=0);
- bitLocalFlag.AddOrSetCharLoc = bool((obact->flag & ACT_ADD_CHAR_LOC)!=0);
- if (obact->reference && bitLocalFlag.ServoControl)
- {
- obref = converter->FindGameObject(obact->reference);
- }
-
- KX_ObjectActuator* tmpbaseact = new KX_ObjectActuator(
- gameobj,
- obref,
- forcevec.getValue(),
- torquevec.getValue(),
- dlocvec.getValue(),
- drotvec.getValue(),
- linvelvec.getValue(),
- angvelvec.getValue(),
- damping,
- bitLocalFlag);
- baseact = tmpbaseact;
- break;
- }
- case ACT_ACTION:
- {
- bActionActuator* actact = (bActionActuator*) bact->data;
- STR_String propname = actact->name;
- STR_String propframe = actact->frameProp;
-
- short ipo_flags = 0;
-
- // Convert flags
- if (actact->flag & ACT_IPOFORCE) ipo_flags |= BL_Action::ACT_IPOFLAG_FORCE;
- if (actact->flag & ACT_IPOLOCAL) ipo_flags |= BL_Action::ACT_IPOFLAG_LOCAL;
- if (actact->flag & ACT_IPOADD) ipo_flags |= BL_Action::ACT_IPOFLAG_ADD;
- if (actact->flag & ACT_IPOCHILD) ipo_flags |= BL_Action::ACT_IPOFLAG_CHILD;
-
- BL_ActionActuator* tmpbaseact = new BL_ActionActuator(
- gameobj,
- propname,
- propframe,
- actact->sta,
- actact->end,
- actact->act,
- actact->type, // + 1, because Blender starts to count at zero,
- actact->blend_mode,
- actact->blendin,
- actact->priority,
- actact->layer,
- actact->layer_weight,
- ipo_flags,
- actact->end_reset,
- actact->stridelength
- // Ketsji at 1, because zero is reserved for "NoDef"
- );
- baseact= tmpbaseact;
- break;
- }
- case ACT_SHAPEACTION:
- {
- if (blenderobject->type==OB_MESH) {
- bActionActuator* actact = (bActionActuator*) bact->data;
- STR_String propname = actact->name;
- STR_String propframe = actact->frameProp;
-
- BL_ShapeActionActuator* tmpbaseact = new BL_ShapeActionActuator(
- gameobj,
- propname,
- propframe,
- actact->sta,
- actact->end,
- actact->act,
- actact->type, // + 1, because Blender starts to count at zero,
- actact->blendin,
- actact->priority,
- actact->stridelength);
- // Ketsji at 1, because zero is reserved for "NoDef"
- baseact= tmpbaseact;
- break;
- }
- else
- printf ("Discarded shape action actuator from non-mesh object [%s]\n", blenderobject->id.name+2);
- }
- case ACT_LAMP:
- {
- break;
- }
- case ACT_CAMERA:
- {
- bCameraActuator *camact = (bCameraActuator *) bact->data;
- if (camact->ob) {
- KX_GameObject *tmpgob = converter->FindGameObject(camact->ob);
-
- /* visifac, fac and axis are not copied from the struct... */
- /* that's some internal state... */
- KX_CameraActuator *tmpcamact = new KX_CameraActuator(
- gameobj,
- tmpgob,
- camact->height,
- camact->min,
- camact->max,
- camact->axis,
- camact->damping);
- baseact = tmpcamact;
- }
- break;
- }
- case ACT_MESSAGE:
- {
- bMessageActuator *msgAct = (bMessageActuator *) bact->data;
-
- /* Get the name of the properties that objects must own that
- * we're sending to, if present
- */
- STR_String toPropName = msgAct->toPropName;
-
- /* Get the Message Subject to send.
- */
- STR_String subject = msgAct->subject;
-
- /* Get the bodyType
- */
- int bodyType = msgAct->bodyType;
-
- /* Get the body (text message or property name whose value
- * we'll be sending, might be empty
- */
- const STR_String body = msgAct->body;
-
- KX_NetworkMessageActuator *tmpmsgact = new KX_NetworkMessageActuator(
- gameobj, // actuator controlling object
- scene->GetNetworkScene(), // needed for replication
- toPropName,
- subject,
- bodyType,
- body);
- baseact = tmpmsgact;
- break;
- }
- case ACT_MATERIAL:
- {
- break;
- }
- case ACT_SOUND:
- {
- bSoundActuator* soundact = (bSoundActuator*) bact->data;
- /* get type, and possibly a start and end frame */
- KX_SoundActuator::KX_SOUNDACT_TYPE
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
-
- switch (soundact->type) {
- case ACT_SND_PLAY_STOP_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYSTOP;
- break;
- case ACT_SND_PLAY_END_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_PLAYEND;
- break;
- case ACT_SND_LOOP_STOP_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPSTOP;
- break;
- case ACT_SND_LOOP_END_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPEND;
- break;
- case ACT_SND_LOOP_BIDIRECTIONAL_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL;
- break;
- case ACT_SND_LOOP_BIDIRECTIONAL_STOP_SOUND:
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP;
- break;
-
- default:
- /* This is an error!!! */
- soundActuatorType = KX_SoundActuator::KX_SOUNDACT_NODEF;
- }
-
- if (soundActuatorType != KX_SoundActuator::KX_SOUNDACT_NODEF)
- {
- bSound* sound = soundact->sound;
- bool is3d = soundact->flag & ACT_SND_3D_SOUND ? true : false;
- AUD_Sound* snd_sound = NULL;
- KX_3DSoundSettings settings;
- settings.cone_inner_angle = RAD2DEGF(soundact->sound3D.cone_inner_angle);
- settings.cone_outer_angle = RAD2DEGF(soundact->sound3D.cone_outer_angle);
- settings.cone_outer_gain = soundact->sound3D.cone_outer_gain;
- settings.max_distance = soundact->sound3D.max_distance;
- settings.max_gain = soundact->sound3D.max_gain;
- settings.min_gain = soundact->sound3D.min_gain;
- settings.reference_distance = soundact->sound3D.reference_distance;
- settings.rolloff_factor = soundact->sound3D.rolloff_factor;
-
- if (!sound)
- {
- std::cout << "WARNING: Sound actuator \"" << bact->name <<
- "\" from object \"" << blenderobject->id.name+2 <<
- "\" has no sound datablock." << std::endl;
- }
- else
- {
- snd_sound = sound->playback_handle;
-
- // if sound shall be 3D but isn't mono, we have to make it mono!
- if (is3d)
- {
- snd_sound = AUD_Sound_rechannel(snd_sound, AUD_CHANNELS_MONO);
- }
- }
- KX_SoundActuator* tmpsoundact =
- new KX_SoundActuator(gameobj,
- snd_sound,
- soundact->volume,
- (float)(expf((soundact->pitch / 12.0f) * (float)M_LN2)),
- is3d,
- settings,
- soundActuatorType);
-
- // if we made it mono, we have to free it
- if (sound && snd_sound && snd_sound != sound->playback_handle) {
- AUD_Sound_free(snd_sound);
- }
-
- tmpsoundact->SetName(bact->name);
- baseact = tmpsoundact;
- }
- break;
- }
- case ACT_PROPERTY:
- {
- bPropertyActuator* propact = (bPropertyActuator*) bact->data;
- SCA_IObject* destinationObj = NULL;
-
- /*
- * here the destinationobject is searched. problem with multiple scenes: other scenes
- * have not been converted yet, so the destobj will not be found, so the prop will
- * not be copied.
- * possible solutions:
- * - convert everything when possible and not realtime only when needed.
- * - let the object-with-property report itself to the act when converted
- */
- if (propact->ob)
- destinationObj = converter->FindGameObject(propact->ob);
-
- SCA_PropertyActuator* tmppropact = new SCA_PropertyActuator(
- gameobj,
- destinationObj,
- propact->name,
- propact->value,
- propact->type + 1); // + 1 because Ketsji Logic starts
- // with 0 for KX_ACT_PROP_NODEF
- baseact = tmppropact;
- break;
- }
- case ACT_EDIT_OBJECT:
- {
- bEditObjectActuator *editobact
- = (bEditObjectActuator *) bact->data;
- /* There are four different kinds of 'edit object' thingies */
- /* The alternative to this lengthy conversion is packing */
- /* several actuators in one, which is not very nice design.. */
- switch (editobact->type) {
- case ACT_EDOB_ADD_OBJECT:
- {
-
- // does the 'original' for replication exists, and
- // is it in a non-active layer ?
- SCA_IObject* originalval = NULL;
- if (editobact->ob)
- {
- if (editobact->ob->lay & activeLayerBitInfo)
- {
- fprintf(stderr, "Warning, object \"%s\" from AddObject actuator \"%s\" is not in a hidden layer.\n", objectname.Ptr(), uniquename.Ptr());
- }
- else {
- originalval = converter->FindGameObject(editobact->ob);
- }
- }
-
- KX_SCA_AddObjectActuator* tmpaddact = new KX_SCA_AddObjectActuator(
- gameobj,
- originalval,
- editobact->time,
- scene,
- editobact->linVelocity,
- (editobact->localflag & ACT_EDOB_LOCAL_LINV) != 0,
- editobact->angVelocity,
- (editobact->localflag & ACT_EDOB_LOCAL_ANGV) != 0);
-
- //editobact->ob to gameobj
- baseact = tmpaddact;
- }
- break;
- case ACT_EDOB_END_OBJECT:
- {
- KX_SCA_EndObjectActuator* tmpendact
- = new KX_SCA_EndObjectActuator(gameobj,scene);
- baseact = tmpendact;
- }
- break;
- case ACT_EDOB_REPLACE_MESH:
- {
- RAS_MeshObject *tmpmesh = converter->FindGameMesh(editobact->me);
-
- if (!tmpmesh) {
- std::cout << "Warning: object \"" << objectname <<
- "\" from ReplaceMesh actuator \"" << uniquename <<
- "\" uses a mesh not owned by an object in scene \"" <<
- scene->GetName() << "\"." << std::endl;
- }
-
- KX_SCA_ReplaceMeshActuator* tmpreplaceact = new KX_SCA_ReplaceMeshActuator(
- gameobj,
- tmpmesh,
- scene,
- (editobact->flag & ACT_EDOB_REPLACE_MESH_NOGFX) == 0,
- (editobact->flag & ACT_EDOB_REPLACE_MESH_PHYS) != 0);
-
- baseact = tmpreplaceact;
- }
- break;
- case ACT_EDOB_TRACK_TO:
- {
- SCA_IObject* originalval = NULL;
- if (editobact->ob)
- originalval = converter->FindGameObject(editobact->ob);
-
- KX_TrackToActuator* tmptrackact = new KX_TrackToActuator(
- gameobj,
- originalval,
- editobact->time,
- editobact->flag,
- editobact->trackflag,
- editobact->upflag);
- baseact = tmptrackact;
- break;
- }
- case ACT_EDOB_DYNAMICS:
- {
- KX_SCA_DynamicActuator* tmpdynact = new KX_SCA_DynamicActuator(
- gameobj,
- editobact->dyn_operation,
- editobact->mass);
- baseact = tmpdynact;
- }
- }
- break;
- }
- case ACT_CONSTRAINT:
- {
- float min = 0.0, max = 0.0;
- char *prop = NULL;
- KX_ConstraintActuator::KX_CONSTRAINTTYPE locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF;
- bConstraintActuator *conact
- = (bConstraintActuator*) bact->data;
- /* convert settings... degrees in the ui become radians */
- /* internally */
- if (conact->type == ACT_CONST_TYPE_ORI) {
- min = conact->minloc[0];
- max = conact->maxloc[0];
- switch (conact->mode) {
- case ACT_CONST_DIRPX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX;
- break;
- case ACT_CONST_DIRPY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY;
- break;
- case ACT_CONST_DIRPZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ;
- break;
- }
- } else if (conact->type == ACT_CONST_TYPE_DIST) {
- switch (conact->mode) {
- case ACT_CONST_DIRPX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRPY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRPZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- case ACT_CONST_DIRNX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRNY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRNZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- }
- prop = conact->matprop;
- } else if (conact->type == ACT_CONST_TYPE_FH) {
- switch (conact->mode) {
- case ACT_CONST_DIRPX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRPY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRPZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- case ACT_CONST_DIRNX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_DIRNY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_DIRNZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- }
- prop = conact->matprop;
- } else {
- switch (conact->flag) {
- case ACT_CONST_LOCX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX;
- min = conact->minloc[0];
- max = conact->maxloc[0];
- break;
- case ACT_CONST_LOCY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY;
- min = conact->minloc[1];
- max = conact->maxloc[1];
- break;
- case ACT_CONST_LOCZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ;
- min = conact->minloc[2];
- max = conact->maxloc[2];
- break;
- case ACT_CONST_ROTX:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX;
- min = conact->minrot[0] * (float)MT_RADS_PER_DEG;
- max = conact->maxrot[0] * (float)MT_RADS_PER_DEG;
- break;
- case ACT_CONST_ROTY:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY;
- min = conact->minrot[1] * (float)MT_RADS_PER_DEG;
- max = conact->maxrot[1] * (float)MT_RADS_PER_DEG;
- break;
- case ACT_CONST_ROTZ:
- locrot = KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ;
- min = conact->minrot[2] * (float)MT_RADS_PER_DEG;
- max = conact->maxrot[2] * (float)MT_RADS_PER_DEG;
- break;
- default:
- ; /* error */
- }
- }
- KX_ConstraintActuator *tmpconact = new KX_ConstraintActuator(
- gameobj,
- conact->damp,
- conact->rotdamp,
- min,
- max,
- conact->maxrot,
- locrot,
- conact->time,
- conact->flag,
- prop);
- baseact = tmpconact;
- break;
- }
- case ACT_GROUP:
- {
- // deprecated
- }
- break;
- case ACT_SCENE:
- {
- bSceneActuator *sceneact = (bSceneActuator *) bact->data;
- STR_String nextSceneName("");
-
- KX_SceneActuator* tmpsceneact;
- int mode = KX_SceneActuator::KX_SCENE_NODEF;
- KX_Camera *cam = NULL;
- //KX_Scene* scene = NULL;
- switch (sceneact->type)
- {
- case ACT_SCENE_RESUME:
- case ACT_SCENE_SUSPEND:
- case ACT_SCENE_ADD_FRONT:
- case ACT_SCENE_ADD_BACK:
- case ACT_SCENE_REMOVE:
- case ACT_SCENE_SET:
- {
- switch (sceneact->type)
- {
- case ACT_SCENE_RESUME:
- mode = KX_SceneActuator::KX_SCENE_RESUME;
- break;
- case ACT_SCENE_SUSPEND:
- mode = KX_SceneActuator::KX_SCENE_SUSPEND;
- break;
- case ACT_SCENE_ADD_FRONT:
- mode = KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE;
- break;
- case ACT_SCENE_ADD_BACK:
- mode = KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE;
- break;
- case ACT_SCENE_REMOVE:
- mode = KX_SceneActuator::KX_SCENE_REMOVE_SCENE;
- break;
- case ACT_SCENE_SET:
- default:
- mode = KX_SceneActuator::KX_SCENE_SET_SCENE;
- break;
- };
-
- if (sceneact->scene) {
- nextSceneName = sceneact->scene->id.name + 2;
- }
-
- break;
- }
- case ACT_SCENE_CAMERA:
- mode = KX_SceneActuator::KX_SCENE_SET_CAMERA;
- if (sceneact->camera)
- {
- KX_GameObject *tmp = converter->FindGameObject(sceneact->camera);
- if (tmp && tmp->GetGameObjectType() == SCA_IObject::OBJ_CAMERA)
- cam = (KX_Camera*)tmp;
- }
- break;
- case ACT_SCENE_RESTART:
- {
-
- mode = KX_SceneActuator::KX_SCENE_RESTART;
- break;
- }
- default:
- ; /* flag error */
- }
- tmpsceneact = new KX_SceneActuator(
- gameobj,
- mode,
- scene,
- ketsjiEngine,
- nextSceneName,
- cam);
- baseact = tmpsceneact;
- break;
- }
- case ACT_GAME:
- {
- bGameActuator *gameact = (bGameActuator *) bact->data;
- KX_GameActuator* tmpgameact;
- STR_String filename = maggiename;
- STR_String loadinganimationname = "";
- int mode = KX_GameActuator::KX_GAME_NODEF;
- switch (gameact->type)
- {
- case ACT_GAME_LOAD:
- {
- mode = KX_GameActuator::KX_GAME_LOAD;
- filename = gameact->filename;
- loadinganimationname = gameact->loadaniname;
- break;
- }
- case ACT_GAME_START:
- {
- mode = KX_GameActuator::KX_GAME_START;
- filename = gameact->filename;
- loadinganimationname = gameact->loadaniname;
- break;
- }
- case ACT_GAME_RESTART:
- {
- mode = KX_GameActuator::KX_GAME_RESTART;
- break;
- }
- case ACT_GAME_QUIT:
- {
- mode = KX_GameActuator::KX_GAME_QUIT;
- break;
- }
- case ACT_GAME_SAVECFG:
- {
- mode = KX_GameActuator::KX_GAME_SAVECFG;
- break;
- }
- case ACT_GAME_LOADCFG:
- {
- mode = KX_GameActuator::KX_GAME_LOADCFG;
- break;
- }
- case ACT_GAME_SCREENSHOT:
- {
- mode = KX_GameActuator::KX_GAME_SCREENSHOT;
- filename = gameact->filename;
- break;
- }
- default:
- ; /* flag error */
- }
- tmpgameact = new KX_GameActuator(
- gameobj,
- mode,
- filename,
- loadinganimationname,
- scene,
- ketsjiEngine);
- baseact = tmpgameact;
-
- break;
- }
- case ACT_RANDOM:
- {
- bRandomActuator *randAct
- = (bRandomActuator *) bact->data;
-
- unsigned long seedArg = randAct->seed;
- if (seedArg == 0)
- {
- seedArg = (int)(ketsjiEngine->GetRealTime()*100000.0);
- seedArg ^= (intptr_t)randAct;
- }
- SCA_RandomActuator::KX_RANDOMACT_MODE modeArg
- = SCA_RandomActuator::KX_RANDOMACT_NODEF;
- SCA_RandomActuator *tmprandomact;
- float paraArg1 = 0.0;
- float paraArg2 = 0.0;
-
- switch (randAct->distribution) {
- case ACT_RANDOM_BOOL_CONST:
- modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST;
- paraArg1 = (float) randAct->int_arg_1;
- break;
- case ACT_RANDOM_BOOL_UNIFORM:
- modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM;
- break;
- case ACT_RANDOM_BOOL_BERNOUILLI:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI;
- break;
- case ACT_RANDOM_INT_CONST:
- modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_CONST;
- paraArg1 = (float) randAct->int_arg_1;
- break;
- case ACT_RANDOM_INT_UNIFORM:
- paraArg1 = (float) randAct->int_arg_1;
- paraArg2 = (float) randAct->int_arg_2;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM;
- break;
- case ACT_RANDOM_INT_POISSON:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_INT_POISSON;
- break;
- case ACT_RANDOM_FLOAT_CONST:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST;
- break;
- case ACT_RANDOM_FLOAT_UNIFORM:
- paraArg1 = randAct->float_arg_1;
- paraArg2 = randAct->float_arg_2;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM;
- break;
- case ACT_RANDOM_FLOAT_NORMAL:
- paraArg1 = randAct->float_arg_1;
- paraArg2 = randAct->float_arg_2;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL;
- break;
- case ACT_RANDOM_FLOAT_NEGATIVE_EXPONENTIAL:
- paraArg1 = randAct->float_arg_1;
- modeArg = SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
- break;
- default:
- ; /* error */
- }
- tmprandomact = new SCA_RandomActuator(
- gameobj,
- seedArg,
- modeArg,
- paraArg1,
- paraArg2,
- randAct->propname);
- baseact = tmprandomact;
- }
- break;
-
- case ACT_VISIBILITY:
- {
- bVisibilityActuator *vis_act = (bVisibilityActuator *) bact->data;
- KX_VisibilityActuator * tmp_vis_act = NULL;
- bool v = ((vis_act->flag & ACT_VISIBILITY_INVISIBLE) != 0);
- bool o = ((vis_act->flag & ACT_VISIBILITY_OCCLUSION) != 0);
- bool recursive = ((vis_act->flag & ACT_VISIBILITY_RECURSIVE) != 0);
-
- tmp_vis_act = new KX_VisibilityActuator(gameobj, !v, o, recursive);
-
- baseact = tmp_vis_act;
- }
- break;
-
- case ACT_STATE:
- {
- bStateActuator *sta_act = (bStateActuator *) bact->data;
- KX_StateActuator * tmp_sta_act = NULL;
-
- tmp_sta_act =
- new KX_StateActuator(gameobj, sta_act->type, sta_act->mask);
-
- baseact = tmp_sta_act;
- }
- break;
-
- case ACT_2DFILTER:
- {
- bTwoDFilterActuator *_2dfilter = (bTwoDFilterActuator*) bact->data;
- SCA_2DFilterActuator *tmp = NULL;
-
- RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode;
- switch (_2dfilter->type) {
- case ACT_2DFILTER_MOTIONBLUR:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR;
- break;
- case ACT_2DFILTER_BLUR:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_BLUR;
- break;
- case ACT_2DFILTER_SHARPEN:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_SHARPEN;
- break;
- case ACT_2DFILTER_DILATION:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_DILATION;
- break;
- case ACT_2DFILTER_EROSION:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_EROSION;
- break;
- case ACT_2DFILTER_LAPLACIAN:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN;
- break;
- case ACT_2DFILTER_SOBEL:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_SOBEL;
- break;
- case ACT_2DFILTER_PREWITT:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_PREWITT;
- break;
- case ACT_2DFILTER_GRAYSCALE:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE;
- break;
- case ACT_2DFILTER_SEPIA:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_SEPIA;
- break;
- case ACT_2DFILTER_INVERT:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_INVERT;
- break;
- case ACT_2DFILTER_CUSTOMFILTER:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER;
- break;
- case ACT_2DFILTER_NOFILTER:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
- break;
- case ACT_2DFILTER_DISABLED:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_DISABLED;
- break;
- case ACT_2DFILTER_ENABLED:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_ENABLED;
- break;
- default:
- filtermode = RAS_2DFilterManager::RAS_2DFILTER_NOFILTER;
- break;
- }
-
- tmp = new SCA_2DFilterActuator(gameobj, filtermode, _2dfilter->flag,
- _2dfilter->float_arg, _2dfilter->int_arg,
- ketsjiEngine->GetRasterizer(), scene);
-
- if (_2dfilter->text)
- {
- char *buf;
- // this is some blender specific code
- buf = txt_to_buf(_2dfilter->text);
- if (buf)
- {
- tmp->SetShaderText(buf);
- MEM_freeN(buf);
- }
- }
-
- baseact = tmp;
-
- }
- break;
- case ACT_PARENT:
- {
- bParentActuator *parAct = (bParentActuator *) bact->data;
- int mode = KX_ParentActuator::KX_PARENT_NODEF;
- bool addToCompound = true;
- bool ghost = true;
- KX_GameObject *tmpgob = NULL;
-
- switch (parAct->type) {
- case ACT_PARENT_SET:
- mode = KX_ParentActuator::KX_PARENT_SET;
- tmpgob = converter->FindGameObject(parAct->ob);
- addToCompound = !(parAct->flag & ACT_PARENT_COMPOUND);
- ghost = !(parAct->flag & ACT_PARENT_GHOST);
- break;
- case ACT_PARENT_REMOVE:
- mode = KX_ParentActuator::KX_PARENT_REMOVE;
- tmpgob = NULL;
- break;
- }
-
- KX_ParentActuator *tmpparact
- = new KX_ParentActuator(gameobj,
- mode,
- addToCompound,
- ghost,
- tmpgob);
- baseact = tmpparact;
- break;
- }
-
- case ACT_ARMATURE:
- {
- bArmatureActuator* armAct = (bArmatureActuator*) bact->data;
- KX_GameObject *tmpgob = converter->FindGameObject(armAct->target);
- KX_GameObject *subgob = converter->FindGameObject(armAct->subtarget);
- BL_ArmatureActuator* tmparmact = new BL_ArmatureActuator(
- gameobj,
- armAct->type,
- armAct->posechannel,
- armAct->constraint,
- tmpgob,
- subgob,
- armAct->weight,
- armAct->influence);
- baseact = tmparmact;
- break;
- }
- case ACT_STEERING:
- {
- bSteeringActuator *stAct = (bSteeringActuator *) bact->data;
- KX_GameObject *navmeshob = NULL;
- if (stAct->navmesh)
- {
- PointerRNA settings_ptr;
- RNA_pointer_create((ID *)stAct->navmesh, &RNA_GameObjectSettings, stAct->navmesh, &settings_ptr);
- if (RNA_enum_get(&settings_ptr, "physics_type") == OB_BODY_TYPE_NAVMESH)
- navmeshob = converter->FindGameObject(stAct->navmesh);
- }
- KX_GameObject *targetob = converter->FindGameObject(stAct->target);
-
- int mode = KX_SteeringActuator::KX_STEERING_NODEF;
- switch (stAct->type) {
- case ACT_STEERING_SEEK:
- mode = KX_SteeringActuator::KX_STEERING_SEEK;
- break;
- case ACT_STEERING_FLEE:
- mode = KX_SteeringActuator::KX_STEERING_FLEE;
- break;
- case ACT_STEERING_PATHFOLLOWING:
- mode = KX_SteeringActuator::KX_STEERING_PATHFOLLOWING;
- break;
- }
-
- bool selfTerminated = (stAct->flag & ACT_STEERING_SELFTERMINATED) !=0;
- bool enableVisualization = (stAct->flag & ACT_STEERING_ENABLEVISUALIZATION) !=0;
- short facingMode = (stAct->flag & ACT_STEERING_AUTOMATICFACING) ? stAct->facingaxis : 0;
- bool normalup = (stAct->flag & ACT_STEERING_NORMALUP) !=0;
- bool lockzvel = (stAct->flag & ACT_STEERING_LOCKZVEL) !=0;
- KX_SteeringActuator *tmpstact
- = new KX_SteeringActuator(gameobj, mode, targetob, navmeshob,stAct->dist,
- stAct->velocity, stAct->acceleration, stAct->turnspeed,
- selfTerminated, stAct->updateTime,
- scene->GetObstacleSimulation(), facingMode, normalup, enableVisualization, lockzvel);
- baseact = tmpstact;
- break;
- }
- case ACT_MOUSE:
- {
- bMouseActuator* mouAct = (bMouseActuator*) bact->data;
- int mode = KX_MouseActuator::KX_ACT_MOUSE_NODEF;
-
- switch (mouAct->type) {
- case ACT_MOUSE_VISIBILITY:
- {
- mode = KX_MouseActuator::KX_ACT_MOUSE_VISIBILITY;
- break;
- }
- case ACT_MOUSE_LOOK:
- {
- mode = KX_MouseActuator::KX_ACT_MOUSE_LOOK;
- break;
- }
- }
-
- bool visible = (mouAct->flag & ACT_MOUSE_VISIBLE) != 0;
- bool use_axis[2] = {(mouAct->flag & ACT_MOUSE_USE_AXIS_X) != 0, (mouAct->flag & ACT_MOUSE_USE_AXIS_Y) != 0};
- bool reset[2] = {(mouAct->flag & ACT_MOUSE_RESET_X) != 0, (mouAct->flag & ACT_MOUSE_RESET_Y) != 0};
- bool local[2] = {(mouAct->flag & ACT_MOUSE_LOCAL_X) != 0, (mouAct->flag & ACT_MOUSE_LOCAL_Y) != 0};
-
- SCA_MouseManager* eventmgr = (SCA_MouseManager*) logicmgr->FindEventManager(SCA_EventManager::MOUSE_EVENTMGR);
- if (eventmgr) {
- KX_MouseActuator* tmpbaseact = new KX_MouseActuator(gameobj,
- ketsjiEngine,
- eventmgr,
- mode,
- visible,
- use_axis,
- mouAct->threshold,
- reset,
- mouAct->object_axis,
- local,
- mouAct->sensitivity,
- mouAct->limit_x,
- mouAct->limit_y);
- baseact = tmpbaseact;
- } else {
- //cout << "\n Couldn't find mouse event manager..."; - should throw an error here...
- }
- break;
- }
- default:
- ; /* generate some error */
- }
-
- if (baseact && !(bact->flag & ACT_DEACTIVATE))
- {
- baseact->SetExecutePriority(executePriority++);
- uniquename += "#ACT#";
- uniqueint++;
- CIntValue* uniqueval = new CIntValue(uniqueint);
- uniquename += uniqueval->GetText();
- uniqueval->Release();
- baseact->SetName(bact->name);
- baseact->SetLogicManager(logicmgr);
- //gameobj->SetProperty(uniquename,baseact);
- gameobj->AddActuator(baseact);
-
- converter->RegisterGameActuator(baseact, bact);
- // done with baseact, release it
- baseact->Release();
- }
- else if (baseact)
- baseact->Release();
-
- bact = bact->next;
- }
-}
-
-
diff --git a/source/gameengine/Converter/KX_ConvertActuators.h b/source/gameengine/Converter/KX_ConvertActuators.h
deleted file mode 100644
index 688b5db50ce..00000000000
--- a/source/gameengine/Converter/KX_ConvertActuators.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertActuators.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTACTUATORS_H__
-#define __KX_CONVERTACTUATORS_H__
-
-void BL_ConvertActuators(const char* maggiename,
- struct Object* blenderobject,
- class KX_GameObject* gameobj,
- class SCA_LogicManager* logicmgr,
- class KX_Scene* scene,
- class KX_KetsjiEngine* ketsjiEngine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- class KX_BlenderSceneConverter* converter);
-
-#endif /* __KX_CONVERTACTUATORS_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertControllers.cpp b/source/gameengine/Converter/KX_ConvertControllers.cpp
deleted file mode 100644
index f55d81adb80..00000000000
--- a/source/gameengine/Converter/KX_ConvertControllers.cpp
+++ /dev/null
@@ -1,250 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_ConvertControllers.cpp
- * \ingroup bgeconv
- */
-
-
-#include "MEM_guardedalloc.h"
-
-#include "KX_BlenderSceneConverter.h"
-#include "KX_ConvertControllers.h"
-#include "EXP_Python.h"
-
-// Controller
-#include "SCA_ANDController.h"
-#include "SCA_ORController.h"
-#include "SCA_NANDController.h"
-#include "SCA_NORController.h"
-#include "SCA_XORController.h"
-#include "SCA_XNORController.h"
-#include "SCA_PythonController.h"
-#include "SCA_ExpressionController.h"
-
-#include "SCA_LogicManager.h"
-#include "KX_GameObject.h"
-#include "EXP_IntValue.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_text_types.h"
-
-#include "BKE_text.h"
-
-#include "BLI_blenlib.h"
-
-/* end of blender include block */
-
-
- static void
-LinkControllerToActuators(
- SCA_IController *game_controller,
- bController* bcontr,
- SCA_LogicManager* logicmgr,
- KX_BlenderSceneConverter* converter
-) {
- // Iterate through the actuators of the game blender
- // controller and find the corresponding ketsji actuator.
-
- game_controller->ReserveActuator(bcontr->totlinks);
- for (int i=0;i<bcontr->totlinks;i++)
- {
- bActuator* bact = (bActuator*) bcontr->links[i];
- SCA_IActuator *game_actuator = converter->FindGameActuator(bact);
- if (game_actuator) {
- logicmgr->RegisterToActuator(game_controller, game_actuator);
- }
- }
-}
-
-
-void BL_ConvertControllers(
- struct Object* blenderobject,
- class KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- KX_BlenderSceneConverter* converter,
- bool libloading
-) {
- int uniqueint=0;
- int count = 0;
- int executePriority=0;
- bController* bcontr = (bController*)blenderobject->controllers.first;
- while (bcontr)
- {
- bcontr = bcontr->next;
- count++;
- }
- gameobj->ReserveController(count);
- bcontr = (bController*)blenderobject->controllers.first;
- while (bcontr)
- {
- SCA_IController* gamecontroller = NULL;
- switch (bcontr->type) {
- case CONT_LOGIC_AND:
- {
- gamecontroller = new SCA_ANDController(gameobj);
- break;
- }
- case CONT_LOGIC_OR:
- {
- gamecontroller = new SCA_ORController(gameobj);
- break;
- }
- case CONT_LOGIC_NAND:
- {
- gamecontroller = new SCA_NANDController(gameobj);
- break;
- }
- case CONT_LOGIC_NOR:
- {
- gamecontroller = new SCA_NORController(gameobj);
- break;
- }
- case CONT_LOGIC_XOR:
- {
- gamecontroller = new SCA_XORController(gameobj);
- break;
- }
- case CONT_LOGIC_XNOR:
- {
- gamecontroller = new SCA_XNORController(gameobj);
- break;
- }
- case CONT_EXPRESSION:
- {
- bExpressionCont* bexpcont = (bExpressionCont*) bcontr->data;
- STR_String expressiontext = STR_String(bexpcont->str);
- if (expressiontext.Length() > 0)
- {
- gamecontroller = new SCA_ExpressionController(gameobj,expressiontext);
- }
- break;
- }
- case CONT_PYTHON:
- {
- bPythonCont* pycont = (bPythonCont*) bcontr->data;
- SCA_PythonController* pyctrl = new SCA_PythonController(gameobj, pycont->mode);
- gamecontroller = pyctrl;
-#ifdef WITH_PYTHON
- // When libloading, this is delayed to KX_Scene::MergeScene_LogicBrick to avoid GIL issues
- if (!libloading)
- pyctrl->SetNamespace(converter->GetPyNamespace());
-
- if (pycont->mode==SCA_PythonController::SCA_PYEXEC_SCRIPT) {
- if (pycont->text)
- {
- char *buf;
- // this is some blender specific code
- buf= txt_to_buf(pycont->text);
- if (buf)
- {
- pyctrl->SetScriptText(STR_String(buf));
- pyctrl->SetScriptName(pycont->text->id.name+2);
- MEM_freeN(buf);
- }
-
- }
- }
- else {
- /* let the controller print any warnings here when importing */
- pyctrl->SetScriptText(STR_String(pycont->module));
- pyctrl->SetScriptName(pycont->module); /* will be something like module.func so using it as the name is OK */
-
- if (pycont->flag & CONT_PY_DEBUG) {
- printf("\nDebuging \"%s\", module for object %s\n\texpect worse performance.\n", pycont->module, blenderobject->id.name+2);
- pyctrl->SetDebug(true);
- }
- }
-#endif // WITH_PYTHON
-
- break;
- }
- default:
- {
-
- }
- }
-
- if (gamecontroller && !(bcontr->flag & CONT_DEACTIVATE))
- {
- LinkControllerToActuators(gamecontroller,bcontr,logicmgr,converter);
- gamecontroller->SetExecutePriority(executePriority++);
- gamecontroller->SetBookmark((bcontr->flag & CONT_PRIO) != 0);
- gamecontroller->SetState(bcontr->state_mask);
- STR_String uniquename = bcontr->name;
- uniquename += "#CONTR#";
- uniqueint++;
- CIntValue* uniqueval = new CIntValue(uniqueint);
- uniquename += uniqueval->GetText();
- uniqueval->Release();
- //unique name was never implemented for sensors and actuators, only for controllers
- //and it's producing difference in the keys for the lists: obj.controllers/sensors/actuators
- //at some point it should either be implemented globally (and saved as a separate var) or removed.
- //gamecontroller->SetName(uniquename);
- gamecontroller->SetName(bcontr->name);
- gamecontroller->SetLogicManager(logicmgr);
- gameobj->AddController(gamecontroller);
-
- converter->RegisterGameController(gamecontroller, bcontr);
-
-#ifdef WITH_PYTHON
- // When libloading, this is delayed to KX_Scene::MergeScene_LogicBrick to avoid GIL issues
- if (!libloading && bcontr->type==CONT_PYTHON) {
- SCA_PythonController *pyctrl= static_cast<SCA_PythonController*>(gamecontroller);
- /* not strictly needed but gives syntax errors early on and
- * gives more predictable performance for larger scripts */
- if (pyctrl->m_mode==SCA_PythonController::SCA_PYEXEC_SCRIPT)
- pyctrl->Compile();
- else {
- /* We cant do this because importing runs the script which could end up accessing
- * internal BGE functions, this is unstable while we're converting the scene.
- * This is a pity because its useful to see errors at startup but cant help it */
-
- // pyctrl->Import();
- }
- }
-
-#endif // WITH_PYTHON
-
- //done with gamecontroller
- gamecontroller->Release();
- }
- else if (gamecontroller)
- gamecontroller->Release();
-
- bcontr = bcontr->next;
- }
-
-}
diff --git a/source/gameengine/Converter/KX_ConvertControllers.h b/source/gameengine/Converter/KX_ConvertControllers.h
deleted file mode 100644
index 2f93d70a6f9..00000000000
--- a/source/gameengine/Converter/KX_ConvertControllers.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertControllers.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTCONTROLLERS_H__
-#define __KX_CONVERTCONTROLLERS_H__
-
-#include "EXP_Python.h"
-
-void BL_ConvertControllers(
- struct Object* blenderobject,
- class KX_GameObject* gameobj,
- class SCA_LogicManager* logicmgr,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- class KX_BlenderSceneConverter* converter,
- bool libloading
-);
-
-#endif /* __KX_CONVERTCONTROLLERS_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertProperties.cpp b/source/gameengine/Converter/KX_ConvertProperties.cpp
deleted file mode 100644
index 2cb61207fb5..00000000000
--- a/source/gameengine/Converter/KX_ConvertProperties.cpp
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_ConvertProperties.cpp
- * \ingroup bgeconv
- */
-
-
-#include "KX_ConvertProperties.h"
-
-
-#include "DNA_object_types.h"
-#include "DNA_property_types.h"
-/* end of blender include block */
-
-
-#include "EXP_Value.h"
-#include "EXP_VectorValue.h"
-#include "EXP_BoolValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_FloatValue.h"
-#include "KX_GameObject.h"
-#include "EXP_IntValue.h"
-#include "SCA_TimeEventManager.h"
-#include "SCA_IScene.h"
-
-#include "KX_FontObject.h"
-#include "DNA_curve_types.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-extern "C" {
- #include "BKE_property.h"
-}
-
-/* prototype */
-void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer);
-
-void BL_ConvertProperties(Object* object,KX_GameObject* gameobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
-{
-
- bProperty* prop = (bProperty*)object->prop.first;
- CValue* propval;
- bool show_debug_info;
-
- while (prop) {
- propval = NULL;
- show_debug_info = bool (prop->flag & PROP_DEBUG);
-
- switch (prop->type) {
- case GPROP_BOOL:
- {
- propval = new CBoolValue((bool)(prop->data != 0));
- gameobj->SetProperty(prop->name,propval);
- //promp->poin= &prop->data;
- break;
- }
- case GPROP_INT:
- {
- propval = new CIntValue((int)prop->data);
- gameobj->SetProperty(prop->name,propval);
- break;
- }
- case GPROP_FLOAT:
- {
- //prop->poin= &prop->data;
- float floatprop = *((float*)&prop->data);
- propval = new CFloatValue(floatprop);
- gameobj->SetProperty(prop->name,propval);
- }
- break;
- case GPROP_STRING:
- {
- //prop->poin= callocN(MAX_PROPSTRING, "property string");
- propval = new CStringValue((char*)prop->poin,"");
- gameobj->SetProperty(prop->name,propval);
- break;
- }
- case GPROP_TIME:
- {
- float floatprop = *((float*)&prop->data);
-
- CValue* timeval = new CFloatValue(floatprop);
- // set a subproperty called 'timer' so that
- // we can register the replica of this property
- // at the time a game object is replicated (AddObjectActuator triggers this)
- CValue *bval = new CBoolValue(true);
- timeval->SetProperty("timer",bval);
- bval->Release();
- if (isInActiveLayer)
- {
- timemgr->AddTimeProperty(timeval);
- }
-
- propval = timeval;
- gameobj->SetProperty(prop->name,timeval);
-
- }
- default:
- {
- // todo make an assert etc.
- }
- }
-
- if (propval)
- {
- if (show_debug_info && isInActiveLayer)
- {
- scene->AddDebugProperty(gameobj,STR_String(prop->name));
- }
- // done with propval, release it
- propval->Release();
- }
-
-#ifdef WITH_PYTHON
- /* Warn if we double up on attributes, this isn't quite right since it wont find inherited attributes however there arnt many */
- for (PyAttributeDef *attrdef = KX_GameObject::Attributes; attrdef->m_name; attrdef++) {
- if (strcmp(prop->name, attrdef->m_name)==0) {
- printf("Warning! user defined property name \"%s\" is also a python attribute for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name);
- break;
- }
- }
- for (PyMethodDef *methdef = KX_GameObject::Methods; methdef->ml_name; methdef++) {
- if (strcmp(prop->name, methdef->ml_name)==0) {
- printf("Warning! user defined property name \"%s\" is also a python method for object \"%s\"\n\tUse ob[\"%s\"] syntax to avoid conflict\n", prop->name, object->id.name+2, prop->name);
- break;
- }
- }
- /* end warning check */
-#endif // WITH_PYTHON
-
- prop = prop->next;
- }
- // check if state needs to be debugged
- if (object->scaflag & OB_DEBUGSTATE && isInActiveLayer)
- {
- // reserve name for object state
- scene->AddDebugProperty(gameobj,STR_String("__state__"));
- }
-
- /* Font Objects need to 'copy' the Font Object data body to ["Text"] */
- if (object->type == OB_FONT)
- {
- BL_ConvertTextProperty(object, (KX_FontObject *)gameobj, timemgr, scene, isInActiveLayer);
- }
-}
-
-void BL_ConvertTextProperty(Object* object, KX_FontObject* fontobj,SCA_TimeEventManager* timemgr,SCA_IScene* scene, bool isInActiveLayer)
-{
- CValue* tprop = fontobj->GetProperty("Text");
- if (!tprop) return;
- bProperty* prop = BKE_bproperty_object_get(object, "Text");
- if (!prop) return;
-
- Curve *curve = static_cast<Curve *>(object->data);
- STR_String str = curve->str;
- CValue* propval = NULL;
-
- switch (prop->type) {
- case GPROP_BOOL:
- {
- int value = atoi(str);
- propval = new CBoolValue((bool)(value != 0));
- tprop->SetValue(propval);
- break;
- }
- case GPROP_INT:
- {
- int value = atoi(str);
- propval = new CIntValue(value);
- tprop->SetValue(propval);
- break;
- }
- case GPROP_FLOAT:
- {
- float floatprop = (float)atof(str);
- propval = new CFloatValue(floatprop);
- tprop->SetValue(propval);
- break;
- }
- case GPROP_STRING:
- {
- propval = new CStringValue(str, "");
- tprop->SetValue(propval);
- break;
- }
- case GPROP_TIME:
- {
- float floatprop = (float)atof(str);
-
- CValue* timeval = new CFloatValue(floatprop);
- // set a subproperty called 'timer' so that
- // we can register the replica of this property
- // at the time a game object is replicated (AddObjectActuator triggers this)
- CValue *bval = new CBoolValue(true);
- timeval->SetProperty("timer",bval);
- bval->Release();
- if (isInActiveLayer)
- {
- timemgr->AddTimeProperty(timeval);
- }
-
- propval = timeval;
- tprop->SetValue(timeval);
- }
- default:
- {
- // todo make an assert etc.
- }
- }
-
- if (propval) {
- propval->Release();
- }
-}
-
diff --git a/source/gameengine/Converter/KX_ConvertProperties.h b/source/gameengine/Converter/KX_ConvertProperties.h
deleted file mode 100644
index 8f96cc21af6..00000000000
--- a/source/gameengine/Converter/KX_ConvertProperties.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertProperties.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTPROPERTIES_H__
-#define __KX_CONVERTPROPERTIES_H__
-
-void BL_ConvertProperties(struct Object* object,
- class KX_GameObject* gameobj,
- class SCA_TimeEventManager* timemgr,
- class SCA_IScene* scene,
- bool isInActiveLayer);
-
-#endif /* __KX_CONVERTPROPERTIES_H__ */
diff --git a/source/gameengine/Converter/KX_ConvertSensors.cpp b/source/gameengine/Converter/KX_ConvertSensors.cpp
deleted file mode 100644
index 5e897bb4a62..00000000000
--- a/source/gameengine/Converter/KX_ConvertSensors.cpp
+++ /dev/null
@@ -1,663 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_ConvertSensors.cpp
- * \ingroup bgeconv
- *
- * Conversion of Blender data blocks to KX sensor system
- */
-
-#include <stdio.h>
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "wm_event_types.h"
-#include "KX_BlenderSceneConverter.h"
-#include "KX_ConvertSensors.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef _MSC_VER
-# include "BLI_winstuff.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_material_types.h"
-#include "DNA_sensor_types.h"
-#include "DNA_controller_types.h"
-#include "DNA_actuator_types.h" /* for SENS_ALL_KEYS ? this define is
- * probably misplaced */
-/* end of blender include block */
-
-#include "RAS_IPolygonMaterial.h"
-// Sensors
-#include "KX_GameObject.h"
-#include "RAS_MeshObject.h"
-#include "SCA_KeyboardSensor.h"
-#include "SCA_MouseSensor.h"
-#include "SCA_AlwaysSensor.h"
-#include "KX_TouchSensor.h"
-#include "KX_NearSensor.h"
-#include "KX_RadarSensor.h"
-#include "KX_MouseFocusSensor.h"
-#include "KX_ArmatureSensor.h"
-#include "SCA_JoystickSensor.h"
-#include "KX_NetworkMessageSensor.h"
-#include "SCA_ActuatorSensor.h"
-#include "SCA_DelaySensor.h"
-
-
-#include "SCA_PropertySensor.h"
-#include "SCA_RandomSensor.h"
-#include "KX_RaySensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-#include "KX_BlenderInputDevice.h"
-#include "KX_Scene.h"
-#include "EXP_IntValue.h"
-#include "KX_BlenderKeyboardDevice.h"
-#include "RAS_ICanvas.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-#include "KX_KetsjiEngine.h"
-#include "BL_BlenderDataConversion.h"
-
-void BL_ConvertSensors(struct Object* blenderobject,
- class KX_GameObject* gameobj,
- SCA_LogicManager* logicmgr,
- KX_Scene* kxscene,
- KX_KetsjiEngine* kxengine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- RAS_ICanvas* canvas,
- KX_BlenderSceneConverter* converter
- )
-{
-
- int executePriority = 0;
- int uniqueint = 0;
- int count = 0;
- bSensor* sens = (bSensor*)blenderobject->sensors.first;
- bool pos_pulsemode = false;
- bool neg_pulsemode = false;
- int skipped_ticks = 0;
- bool invert = false;
- bool level = false;
- bool tap = false;
-
- while (sens)
- {
- sens = sens->next;
- count++;
- }
- gameobj->ReserveSensor(count);
- sens = (bSensor*)blenderobject->sensors.first;
-
- while (sens) {
- if (!(sens->flag & SENS_DEACTIVATE)) {
- SCA_ISensor* gamesensor=NULL;
- /* All sensors have a pulse toggle, skipped ticks parameter, and invert field. */
- /* These are extracted here, and set when the sensor is added to the */
- /* list. */
- pos_pulsemode = (sens->pulse & SENS_PULSE_REPEAT)!=0;
- neg_pulsemode = (sens->pulse & SENS_NEG_PULSE_MODE)!=0;
-
- skipped_ticks = sens->freq;
- invert = !(sens->invert == 0);
- level = !(sens->level == 0);
- tap = !(sens->tap == 0);
-
- switch (sens->type)
- {
- case SENS_ALWAYS:
- {
-
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- gamesensor = new SCA_AlwaysSensor(eventmgr, gameobj);
- }
-
- break;
- }
-
- case SENS_DELAY:
- {
- // we can reuse the Always event manager for the delay sensor
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- bDelaySensor* delaysensor = (bDelaySensor*)sens->data;
- gamesensor = new SCA_DelaySensor(eventmgr,
- gameobj,
- delaysensor->delay,
- delaysensor->duration,
- (delaysensor->flag & SENS_DELAY_REPEAT) != 0);
- }
- break;
- }
-
- case SENS_COLLISION:
- {
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
- if (eventmgr)
- {
- // collision sensor can sense both materials and properties.
-
- bool bFindMaterial = false, bTouchPulse = false;
-
- bCollisionSensor* blendertouchsensor = (bCollisionSensor*)sens->data;
-
- bFindMaterial = (blendertouchsensor->mode & SENS_COLLISION_MATERIAL);
- bTouchPulse = (blendertouchsensor->mode & SENS_COLLISION_PULSE);
-
-
- const STR_String touchPropOrMatName = bFindMaterial ?
- blendertouchsensor->materialName : blendertouchsensor->name;
-
-
- if (gameobj->GetPhysicsController())
- {
- gamesensor = new KX_TouchSensor(eventmgr,
- gameobj,
- bFindMaterial,
- bTouchPulse,
- touchPropOrMatName);
- }
-
- }
-
- break;
- }
- case SENS_MESSAGE:
- {
- KX_NetworkEventManager* eventmgr = (KX_NetworkEventManager*)
- logicmgr->FindEventManager(SCA_EventManager::NETWORK_EVENTMGR);
- if (eventmgr) {
- bMessageSensor* msgSens = (bMessageSensor*) sens->data;
-
- /* Get our NetworkScene */
- NG_NetworkScene *NetworkScene = kxscene->GetNetworkScene();
- /* filter on the incoming subjects, might be empty */
- const STR_String subject = msgSens->subject;
-
- gamesensor = new KX_NetworkMessageSensor(
- eventmgr, // our eventmanager
- NetworkScene, // our NetworkScene
- gameobj, // the sensor controlling object
- subject); // subject to filter on
- }
- break;
- }
- case SENS_NEAR:
- {
-
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
- if (eventmgr)
- {
- bNearSensor* blendernearsensor = (bNearSensor*)sens->data;
- const STR_String nearpropertyname = (char *)blendernearsensor->name;
-
- //DT_ShapeHandle shape = DT_Sphere(0.0);
-
- // this sumoObject is not deleted by a gameobj, so delete it ourself
- // later (memleaks)!
- float radius = blendernearsensor->dist;
- const MT_Vector3& wpos = gameobj->NodeGetWorldPosition();
- bool bFindMaterial = false;
- PHY_IPhysicsController* physCtrl = kxscene->GetPhysicsEnvironment()->CreateSphereController(radius,wpos);
-
- //will be done in KX_TouchEventManager::RegisterSensor()
- //if (isInActiveLayer)
- // kxscene->GetPhysicsEnvironment()->addSensor(physCtrl);
-
-
-
- gamesensor = new KX_NearSensor(eventmgr,gameobj,
- blendernearsensor->dist,
- blendernearsensor->resetdist,
- bFindMaterial,
- nearpropertyname,
- physCtrl);
-
- }
- break;
- }
-
-
- case SENS_KEYBOARD:
- {
- /* temporary input device, for converting the code for the keyboard sensor */
-
- bKeyboardSensor* blenderkeybdsensor = (bKeyboardSensor*)sens->data;
- SCA_KeyboardManager* eventmgr = (SCA_KeyboardManager*) logicmgr->FindEventManager(SCA_EventManager::KEYBOARD_EVENTMGR);
- if (eventmgr)
- {
- gamesensor = new SCA_KeyboardSensor(eventmgr,
- ConvertKeyCode(blenderkeybdsensor->key),
- ConvertKeyCode(blenderkeybdsensor->qual),
- ConvertKeyCode(blenderkeybdsensor->qual2),
- (blenderkeybdsensor->type == SENS_ALL_KEYS),
- blenderkeybdsensor->targetName,
- blenderkeybdsensor->toggleName,
- gameobj,
- KX_KetsjiEngine::GetExitKey()); // blenderkeybdsensor->pad);
-
- }
-
- break;
- }
- case SENS_MOUSE:
- {
- int keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_NODEF;
- int trackfocus = 0;
- bMouseSensor *bmouse = (bMouseSensor *)sens->data;
-
- /* There are two main types of mouse sensors. If there is
- * no focus-related behavior requested, we can make do
- * with a basic sensor. This cuts down memory usage and
- * gives a slight performance gain. */
-
- SCA_MouseManager *eventmgr
- = (SCA_MouseManager*) logicmgr->FindEventManager(SCA_EventManager::MOUSE_EVENTMGR);
- if (eventmgr) {
-
- /* Determine key mode. There is at most one active mode. */
- switch (bmouse->type) {
- case BL_SENS_MOUSE_LEFT_BUTTON:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_LEFTBUTTON;
- break;
- case BL_SENS_MOUSE_MIDDLE_BUTTON:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MIDDLEBUTTON;
- break;
- case BL_SENS_MOUSE_RIGHT_BUTTON:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_RIGHTBUTTON;
- break;
- case BL_SENS_MOUSE_WHEEL_UP:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELUP;
- break;
- case BL_SENS_MOUSE_WHEEL_DOWN:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_WHEELDOWN;
- break;
- case BL_SENS_MOUSE_MOVEMENT:
- keytype = SCA_MouseSensor::KX_MOUSESENSORMODE_MOVEMENT;
- break;
- case BL_SENS_MOUSE_MOUSEOVER:
- trackfocus = 1;
- break;
- case BL_SENS_MOUSE_MOUSEOVER_ANY:
- trackfocus = 2;
- break;
-
- default:
- ; /* error */
- }
-
- /* initial mouse position */
- int startx = canvas->GetWidth()/2;
- int starty = canvas->GetHeight()/2;
-
- if (!trackfocus) {
- /* plain, simple mouse sensor */
- gamesensor = new SCA_MouseSensor(eventmgr,
- startx,starty,
- keytype,
- gameobj);
- } else {
- /* give us a focus-aware sensor */
- bool bFindMaterial = (bmouse->mode & SENS_COLLISION_MATERIAL);
- bool bXRay = (bmouse->flag & SENS_RAY_XRAY);
- STR_String checkname = (bFindMaterial? bmouse->matname : bmouse->propname);
-
- gamesensor = new KX_MouseFocusSensor(eventmgr,
- startx,
- starty,
- keytype,
- trackfocus,
- (bmouse->flag & SENS_MOUSE_FOCUS_PULSE) ? true:false,
- checkname,
- bFindMaterial,
- bXRay,
- kxscene,
- kxengine,
- gameobj);
- }
- } else {
- // cout << "\n Could't find mouse event manager..."; - should throw an error here...
- }
- break;
- }
- case SENS_PROPERTY:
- {
- bPropertySensor* blenderpropsensor = (bPropertySensor*) sens->data;
- SCA_EventManager* eventmgr
- = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- STR_String propname=blenderpropsensor->name;
- STR_String propval=blenderpropsensor->value;
- STR_String propmaxval=blenderpropsensor->maxvalue;
-
- SCA_PropertySensor::KX_PROPSENSOR_TYPE
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NODEF;
-
- /* Better do an explicit conversion here! (was implicit */
- /* before...) */
- switch (blenderpropsensor->type) {
- case SENS_PROP_EQUAL:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EQUAL;
- break;
- case SENS_PROP_NEQUAL:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL;
- break;
- case SENS_PROP_INTERVAL:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_INTERVAL;
- break;
- case SENS_PROP_CHANGED:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_CHANGED;
- break;
- case SENS_PROP_EXPRESSION:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION;
- /* error */
- break;
- case SENS_PROP_LESSTHAN:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_LESSTHAN;
- break;
- case SENS_PROP_GREATERTHAN:
- propchecktype = SCA_PropertySensor::KX_PROPSENSOR_GREATERTHAN;
- break;
- default:
- ; /* error */
- }
- gamesensor = new SCA_PropertySensor(eventmgr,gameobj,propname,propval,propmaxval,propchecktype);
- }
-
- break;
- }
- case SENS_ACTUATOR:
- {
- bActuatorSensor* blenderactsensor = (bActuatorSensor*) sens->data;
- // we will reuse the property event manager, there is nothing special with this sensor
- SCA_EventManager* eventmgr
- = logicmgr->FindEventManager(SCA_EventManager::ACTUATOR_EVENTMGR);
- if (eventmgr)
- {
- STR_String propname=blenderactsensor->name;
- gamesensor = new SCA_ActuatorSensor(eventmgr,gameobj,propname);
- }
- break;
- }
-
- case SENS_ARMATURE:
- {
- bArmatureSensor* blenderarmsensor = (bArmatureSensor*) sens->data;
- // we will reuse the property event manager, there is nothing special with this sensor
- SCA_EventManager* eventmgr
- = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- STR_String bonename=blenderarmsensor->posechannel;
- STR_String constraintname=blenderarmsensor->constraint;
- gamesensor = new KX_ArmatureSensor(eventmgr,gameobj,bonename,constraintname, blenderarmsensor->type, blenderarmsensor->value);
- }
- break;
- }
-
- case SENS_RADAR:
- {
-
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::TOUCH_EVENTMGR);
- if (eventmgr)
- {
- bRadarSensor* blenderradarsensor = (bRadarSensor*) sens->data;
- const STR_String radarpropertyname = blenderradarsensor->name;
-
- int radaraxis = blenderradarsensor->axis;
-
- MT_Scalar coneheight = blenderradarsensor->range;
-
- // janco: the angle was doubled, so should I divide the factor in 2
- // or the blenderradarsensor->angle?
- // nzc: the angle is the opening angle. We need to init with
- // the axis-hull angle,so /2.0.
- MT_Scalar factor = tan(blenderradarsensor->angle * 0.5f);
- //MT_Scalar coneradius = coneheight * (factor / 2);
- MT_Scalar coneradius = coneheight * factor;
-
-
- // this sumoObject is not deleted by a gameobj, so delete it ourself
- // later (memleaks)!
- MT_Scalar smallmargin = 0.0;
- MT_Scalar largemargin = 0.0;
-
- bool bFindMaterial = false;
- PHY_IPhysicsController* ctrl = kxscene->GetPhysicsEnvironment()->CreateConeController((float)coneradius, (float)coneheight);
-
- gamesensor = new KX_RadarSensor(
- eventmgr,
- gameobj,
- ctrl,
- coneradius,
- coneheight,
- radaraxis,
- smallmargin,
- largemargin,
- bFindMaterial,
- radarpropertyname);
-
- }
-
- break;
- }
- case SENS_RAY:
- {
- bRaySensor* blenderraysensor = (bRaySensor*) sens->data;
-
- //blenderradarsensor->angle;
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- bool bFindMaterial = (blenderraysensor->mode & SENS_COLLISION_MATERIAL);
- bool bXRay = (blenderraysensor->mode & SENS_RAY_XRAY);
-
- STR_String checkname = (bFindMaterial? blenderraysensor->matname : blenderraysensor->propname);
-
- // don't want to get rays of length 0.0 or so
- double distance = (blenderraysensor->range < 0.01f ? 0.01f : blenderraysensor->range);
- int axis = blenderraysensor->axisflag;
-
-
- gamesensor = new KX_RaySensor(eventmgr,
- gameobj,
- checkname,
- bFindMaterial,
- bXRay,
- distance,
- axis,
- kxscene);
-
- }
- break;
- }
-
- case SENS_RANDOM:
- {
- bRandomSensor* blenderrndsensor = (bRandomSensor*) sens->data;
- // some files didn't write randomsensor, avoid crash now for NULL ptr's
- if (blenderrndsensor)
- {
- SCA_EventManager* eventmgr = logicmgr->FindEventManager(SCA_EventManager::BASIC_EVENTMGR);
- if (eventmgr)
- {
- int randomSeed = blenderrndsensor->seed;
- if (randomSeed == 0)
- {
- randomSeed = (int)(kxengine->GetRealTime()*100000.0);
- randomSeed ^= (intptr_t)blenderrndsensor;
- }
- gamesensor = new SCA_RandomSensor(eventmgr, gameobj, randomSeed);
- }
- }
- break;
- }
- case SENS_JOYSTICK:
- {
- int joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_NODEF;
-
- bJoystickSensor* bjoy = (bJoystickSensor*) sens->data;
-
- SCA_JoystickManager *eventmgr
- = (SCA_JoystickManager*) logicmgr->FindEventManager(SCA_EventManager::JOY_EVENTMGR);
- if (eventmgr)
- {
- int axis =0;
- int axisf =0;
- int button =0;
- int hat =0;
- int hatf =0;
- int prec =0;
-
- switch (bjoy->type) {
- case SENS_JOY_AXIS:
- axis = bjoy->axis;
- axisf = bjoy->axisf;
- prec = bjoy->precision;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS;
- break;
- case SENS_JOY_BUTTON:
- button = bjoy->button;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_BUTTON;
- break;
- case SENS_JOY_HAT:
- hat = bjoy->hat;
- hatf = bjoy->hatf;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_HAT;
- break;
- case SENS_JOY_AXIS_SINGLE:
- axis = bjoy->axis_single;
- prec = bjoy->precision;
- joysticktype = SCA_JoystickSensor::KX_JOYSENSORMODE_AXIS_SINGLE;
- break;
- default:
- printf("Error: bad case statement\n");
- break;
- }
- gamesensor = new SCA_JoystickSensor(
- eventmgr,
- gameobj,
- bjoy->joyindex,
- joysticktype,
- axis,axisf,
- prec,
- button,
- hat,hatf,
- (bjoy->flag & SENS_JOY_ANY_EVENT));
- }
- else
- {
- printf("Error there was a problem finding the event manager\n");
- }
-
- break;
- }
- default:
- {
- }
- }
-
- if (gamesensor)
- {
- gamesensor->SetExecutePriority(executePriority++);
- STR_String uniquename = sens->name;
- uniquename += "#SENS#";
- uniqueint++;
- CIntValue* uniqueval = new CIntValue(uniqueint);
- uniquename += uniqueval->GetText();
- uniqueval->Release();
-
- /* Conversion succeeded, so we can set the generic props here. */
- gamesensor->SetPulseMode(pos_pulsemode,
- neg_pulsemode,
- skipped_ticks);
- gamesensor->SetInvert(invert);
- gamesensor->SetLevel(level);
- gamesensor->SetTap(tap);
- gamesensor->SetName(sens->name);
- gamesensor->SetLogicManager(logicmgr);
-
- gameobj->AddSensor(gamesensor);
-
- // only register to manager if it's in an active layer
- // Make registration dynamic: only when sensor is activated
- //if (isInActiveLayer)
- // gamesensor->RegisterToManager();
-
- gamesensor->ReserveController(sens->totlinks);
- for (int i=0;i<sens->totlinks;i++)
- {
- bController* linkedcont = (bController*) sens->links[i];
- if (linkedcont) {
- // If the controller is deactived doesn't register it
- if (!(linkedcont->flag & CONT_DEACTIVATE)) {
- SCA_IController* gamecont = converter->FindGameController(linkedcont);
-
- if (gamecont) {
- logicmgr->RegisterToSensor(gamecont,gamesensor);
- }
- else {
- printf("Warning, sensor \"%s\" could not find its controller "
- "(link %d of %d) from object \"%s\"\n"
- "\tthere has been an error converting the blender controller for the game engine,"
- "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
- }
- }
- }
- else {
- printf("Warning, sensor \"%s\" has lost a link to a controller "
- "(link %d of %d) from object \"%s\"\n"
- "\tpossible causes are partially appended objects or an error reading the file,"
- "logic may be incorrect\n", sens->name, i+1, sens->totlinks, blenderobject->id.name+2);
- }
- }
- // special case: Keyboard sensor with no link
- // this combination is usually used for key logging.
- if (sens->type == SENS_KEYBOARD && sens->totlinks == 0) {
- // Force the registration so that the sensor runs
- gamesensor->IncLink();
- }
-
- // done with gamesensor
- gamesensor->Release();
-
- }
- }
-
- sens=sens->next;
- }
-}
-
diff --git a/source/gameengine/Converter/KX_ConvertSensors.h b/source/gameengine/Converter/KX_ConvertSensors.h
deleted file mode 100644
index 56248721a37..00000000000
--- a/source/gameengine/Converter/KX_ConvertSensors.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConvertSensors.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_CONVERTSENSORS_H__
-#define __KX_CONVERTSENSORS_H__
-
-void BL_ConvertSensors(struct Object* blenderobject,
- class KX_GameObject* gameobj,
- class SCA_LogicManager* logicmgr,
- class KX_Scene* kxscene,
- class KX_KetsjiEngine* kxengine,
- int activeLayerBitInfo,
- bool isInActiveLayer,
- class RAS_ICanvas* canvas,
- class KX_BlenderSceneConverter* converter);
-
-#endif /* __KX_CONVERTSENSORS_H__ */
diff --git a/source/gameengine/Converter/KX_LibLoadStatus.cpp b/source/gameengine/Converter/KX_LibLoadStatus.cpp
deleted file mode 100644
index 66fcd998269..00000000000
--- a/source/gameengine/Converter/KX_LibLoadStatus.cpp
+++ /dev/null
@@ -1,255 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_LibLoadStatus.cpp
- * \ingroup bgeconv
- */
-
-#include "KX_LibLoadStatus.h"
-#include "PIL_time.h"
-
-KX_LibLoadStatus::KX_LibLoadStatus(class KX_BlenderSceneConverter* kx_converter,
- class KX_KetsjiEngine* kx_engine,
- class KX_Scene* merge_scene,
- const char *path) :
- m_converter(kx_converter),
- m_engine(kx_engine),
- m_mergescene(merge_scene),
- m_data(NULL),
- m_libname(path),
- m_progress(0.0f),
- m_finished(false)
-#ifdef WITH_PYTHON
- ,
- m_finish_cb(NULL),
- m_progress_cb(NULL)
-#endif
-{
- m_endtime = m_starttime = PIL_check_seconds_timer();
-}
-
-void KX_LibLoadStatus::Finish()
-{
- m_finished = true;
- m_progress = 1.f;
- m_endtime = PIL_check_seconds_timer();
-
- RunFinishCallback();
- RunProgressCallback();
-}
-
-void KX_LibLoadStatus::RunFinishCallback()
-{
-#ifdef WITH_PYTHON
- if (m_finish_cb) {
- PyObject* args = Py_BuildValue("(O)", GetProxy());
-
- if (!PyObject_Call(m_finish_cb, args, NULL)) {
- PyErr_Print();
- PyErr_Clear();
- }
-
- Py_DECREF(args);
- }
-#endif
-}
-
-void KX_LibLoadStatus::RunProgressCallback()
-{
-// Progess callbacks are causing threading problems with Python, so they're disabled for now
-#if 0
-#ifdef WITH_PYTHON
- if (m_progress_cb) {
- //PyGILState_STATE gstate = PyGILState_Ensure();
- PyObject* args = Py_BuildValue("(O)", GetProxy());
-
- if (!PyObject_Call(m_progress_cb, args, NULL)) {
- PyErr_Print();
- PyErr_Clear();
- }
-
- Py_DECREF(args);
- //PyGILState_Release(gstate);
- }
-#endif
-#endif
-}
-
-class KX_BlenderSceneConverter *KX_LibLoadStatus::GetConverter()
-{
- return m_converter;
-}
-
-class KX_KetsjiEngine *KX_LibLoadStatus::GetEngine()
-{
- return m_engine;
-}
-
-class KX_Scene *KX_LibLoadStatus::GetMergeScene()
-{
- return m_mergescene;
-}
-
-void KX_LibLoadStatus::SetLibName(const char *name)
-{
- m_libname = name;
-}
-
-const char *KX_LibLoadStatus::GetLibName()
-{
- return m_libname;
-}
-
-void KX_LibLoadStatus::SetData(void *data)
-{
- m_data = data;
-}
-
-void *KX_LibLoadStatus::GetData()
-{
- return m_data;
-}
-
-void KX_LibLoadStatus::SetProgress(float progress)
-{
- m_progress = progress;
- RunProgressCallback();
-}
-
-float KX_LibLoadStatus::GetProgress()
-{
- return m_progress;
-}
-
-void KX_LibLoadStatus::AddProgress(float progress)
-{
- m_progress += progress;
- RunProgressCallback();
-}
-
-#ifdef WITH_PYTHON
-
-PyMethodDef KX_LibLoadStatus::Methods[] =
-{
- {NULL} //Sentinel
-};
-
-PyAttributeDef KX_LibLoadStatus::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("onFinish", KX_LibLoadStatus, pyattr_get_onfinish, pyattr_set_onfinish),
- // KX_PYATTRIBUTE_RW_FUNCTION("onProgress", KX_LibLoadStatus, pyattr_get_onprogress, pyattr_set_onprogress),
- KX_PYATTRIBUTE_FLOAT_RO("progress", KX_LibLoadStatus, m_progress),
- KX_PYATTRIBUTE_STRING_RO("libraryName", KX_LibLoadStatus, m_libname),
- KX_PYATTRIBUTE_RO_FUNCTION("timeTaken", KX_LibLoadStatus, pyattr_get_timetaken),
- KX_PYATTRIBUTE_BOOL_RO("finished", KX_LibLoadStatus, m_finished),
- { NULL } //Sentinel
-};
-
-PyTypeObject KX_LibLoadStatus::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_LibLoadStatus",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-
-PyObject* KX_LibLoadStatus::pyattr_get_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (self->m_finish_cb) {
- Py_INCREF(self->m_finish_cb);
- return self->m_finish_cb;
- }
-
- Py_RETURN_NONE;
-}
-
-int KX_LibLoadStatus::pyattr_set_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (!PyCallable_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "KX_LibLoadStatus.onFinished requires a callable object");
- return PY_SET_ATTR_FAIL;
- }
-
- if (self->m_finish_cb)
- Py_DECREF(self->m_finish_cb);
-
- Py_INCREF(value);
- self->m_finish_cb = value;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_LibLoadStatus::pyattr_get_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (self->m_progress_cb) {
- Py_INCREF(self->m_progress_cb);
- return self->m_progress_cb;
- }
-
- Py_RETURN_NONE;
-}
-
-int KX_LibLoadStatus::pyattr_set_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- if (!PyCallable_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "KX_LibLoadStatus.onProgress requires a callable object");
- return PY_SET_ATTR_FAIL;
- }
-
- if (self->m_progress_cb)
- Py_DECREF(self->m_progress_cb);
-
- Py_INCREF(value);
- self->m_progress_cb = value;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_LibLoadStatus::pyattr_get_timetaken(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LibLoadStatus* self = static_cast<KX_LibLoadStatus*>(self_v);
-
- return PyFloat_FromDouble(self->m_endtime - self->m_starttime);
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Converter/KX_LibLoadStatus.h b/source/gameengine/Converter/KX_LibLoadStatus.h
deleted file mode 100644
index fd51bfddd85..00000000000
--- a/source/gameengine/Converter/KX_LibLoadStatus.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_LibLoadStatus.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_LIBLOADSTATUS_H__
-#define __KX_LIBLOADSTATUS_H__
-
-#include "EXP_PyObjectPlus.h"
-
-class KX_LibLoadStatus : public PyObjectPlus
-{
- Py_Header
-private:
- class KX_BlenderSceneConverter* m_converter;
- class KX_KetsjiEngine* m_engine;
- class KX_Scene* m_mergescene;
- void* m_data;
- STR_String m_libname;
-
- float m_progress;
- double m_starttime;
- double m_endtime;
-
- // The current status of this libload, used by the scene converter.
- bool m_finished;
-
-#ifdef WITH_PYTHON
- PyObject* m_finish_cb;
- PyObject* m_progress_cb;
-#endif
-
-public:
- KX_LibLoadStatus(class KX_BlenderSceneConverter* kx_converter,
- class KX_KetsjiEngine* kx_engine,
- class KX_Scene* merge_scene,
- const char *path);
-
- void Finish(); // Called when the libload is done
- void RunFinishCallback();
- void RunProgressCallback();
-
- class KX_BlenderSceneConverter *GetConverter();
- class KX_KetsjiEngine *GetEngine();
- class KX_Scene *GetMergeScene();
-
- void SetLibName(const char *name);
- const char *GetLibName();
-
- void SetData(void *data);
- void *GetData();
-
- inline bool IsFinished() const
- {
- return m_finished;
- }
-
- void SetProgress(float progress);
- float GetProgress();
- void AddProgress(float progress);
-
-#ifdef WITH_PYTHON
- static PyObject* pyattr_get_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_onfinish(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_onprogress(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_timetaken(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-};
-
-#endif // __KX_LIBLOADSTATUS_H__
diff --git a/source/gameengine/Converter/KX_SoftBodyDeformer.cpp b/source/gameengine/Converter/KX_SoftBodyDeformer.cpp
deleted file mode 100644
index 877aebff556..00000000000
--- a/source/gameengine/Converter/KX_SoftBodyDeformer.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Converter/KX_SoftBodyDeformer.cpp
- * \ingroup bgeconv
- */
-
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif //WIN32
-
-#include "MT_assert.h"
-
-#include "KX_SoftBodyDeformer.h"
-#include "RAS_MeshObject.h"
-#include "CTR_Map.h"
-#include "CTR_HashedPtr.h"
-
-#ifdef WITH_BULLET
-
-#include "CcdPhysicsEnvironment.h"
-#include "CcdPhysicsController.h"
-#include "BulletSoftBody/btSoftBody.h"
-
-#include "btBulletDynamicsCommon.h"
-
-void KX_SoftBodyDeformer::Relink(CTR_Map<class CTR_HashedPtr, void*>*map)
-{
- void **h_obj = (*map)[m_gameobj];
-
- if (h_obj) {
- m_gameobj = (BL_DeformableGameObject*)(*h_obj);
- m_pMeshObject = m_gameobj->GetMesh(0);
- } else {
- m_gameobj = NULL;
- m_pMeshObject = NULL;
- }
-}
-
-bool KX_SoftBodyDeformer::Apply(class RAS_IPolyMaterial *polymat)
-{
- CcdPhysicsController* ctrl = (CcdPhysicsController*) m_gameobj->GetPhysicsController();
- if (!ctrl)
- return false;
-
- btSoftBody* softBody= ctrl->GetSoftBody();
- if (!softBody)
- return false;
-
- //printf("apply\n");
- RAS_MeshSlot::iterator it;
- RAS_MeshMaterial *mmat;
- RAS_MeshSlot *slot;
- size_t i;
-
- // update the vertex in m_transverts
- Update();
-
- // The vertex cache can only be updated for this deformer:
- // Duplicated objects with more than one ploymaterial (=multiple mesh slot per object)
- // share the same mesh (=the same cache). As the rendering is done per polymaterial
- // cycling through the objects, the entire mesh cache cannot be updated in one shot.
- mmat = m_pMeshObject->GetMeshMaterial(polymat);
- if (!mmat->m_slots[(void*)m_gameobj])
- return true;
-
- slot = *mmat->m_slots[(void*)m_gameobj];
-
- // for each array
- for (slot->begin(it); !slot->end(it); slot->next(it))
- {
- btSoftBody::tNodeArray& nodes(softBody->m_nodes);
-
- int index = 0;
- for (i=it.startvertex; i<it.endvertex; i++,index++) {
- RAS_TexVert& v = it.vertex[i];
- btAssert(v.getSoftBodyIndex() >= 0);
-
- MT_Point3 pt (
- nodes[v.getSoftBodyIndex()].m_x.getX(),
- nodes[v.getSoftBodyIndex()].m_x.getY(),
- nodes[v.getSoftBodyIndex()].m_x.getZ());
- v.SetXYZ(pt);
-
- MT_Vector3 normal (
- nodes[v.getSoftBodyIndex()].m_n.getX(),
- nodes[v.getSoftBodyIndex()].m_n.getY(),
- nodes[v.getSoftBodyIndex()].m_n.getZ());
- v.SetNormal(normal);
-
- }
- }
- return true;
-}
-
-#endif
diff --git a/source/gameengine/Converter/KX_SoftBodyDeformer.h b/source/gameengine/Converter/KX_SoftBodyDeformer.h
deleted file mode 100644
index d7bc088e1c0..00000000000
--- a/source/gameengine/Converter/KX_SoftBodyDeformer.h
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SoftBodyDeformer.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_SOFTBODYDEFORMER_H__
-#define __KX_SOFTBODYDEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-#include "RAS_Deformer.h"
-#include "BL_DeformableGameObject.h"
-#include <vector>
-
-
-class KX_SoftBodyDeformer : public RAS_Deformer
-{
- class RAS_MeshObject* m_pMeshObject;
- class BL_DeformableGameObject* m_gameobj;
-
-public:
- KX_SoftBodyDeformer(RAS_MeshObject* pMeshObject,BL_DeformableGameObject* gameobj)
- :m_pMeshObject(pMeshObject),
- m_gameobj(gameobj)
- {
- //printf("KX_SoftBodyDeformer\n");
- };
-
- virtual ~KX_SoftBodyDeformer()
- {
- //printf("~KX_SoftBodyDeformer\n");
- };
- virtual void Relink(CTR_Map<class CTR_HashedPtr, void*>*map);
- virtual bool Apply(class RAS_IPolyMaterial *polymat);
- virtual bool Update(void)
- {
- //printf("update\n");
- m_bDynamic = true;
- return true;//??
- }
- virtual bool UpdateBuckets(void)
- {
- // this is to update the mesh slots outside the rasterizer,
- // no need to do it for this deformer, it's done in any case in Apply()
- return false;
- }
-
- virtual RAS_Deformer *GetReplica()
- {
- KX_SoftBodyDeformer* deformer = new KX_SoftBodyDeformer(*this);
- deformer->ProcessReplica();
- return deformer;
- }
- virtual void ProcessReplica()
- {
- // we have two pointers to deal with but we cannot do it now, will be done in Relink
- m_bDynamic = false;
- }
- virtual bool SkipVertexTransform()
- {
- return true;
- }
-
-protected:
- //class RAS_MeshObject *m_pMesh;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ShapeDeformer")
-#endif
-};
-
-
-#endif
-
diff --git a/source/gameengine/Expressions/CMakeLists.txt b/source/gameengine/Expressions/CMakeLists.txt
deleted file mode 100644
index 9c563a46ea2..00000000000
--- a/source/gameengine/Expressions/CMakeLists.txt
+++ /dev/null
@@ -1,91 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../SceneGraph
- ../../blender/blenlib
- ../../../intern/guardedalloc
- ../../../intern/string
-)
-
-set(INC_SYS
- ../../../intern/moto/include
-)
-
-set(SRC
- intern/BoolValue.cpp
- intern/ConstExpr.cpp
- intern/EmptyValue.cpp
- intern/ErrorValue.cpp
- intern/Expression.cpp
- intern/FloatValue.cpp
- intern/IdentifierExpr.cpp
- intern/IfExpr.cpp
- intern/InputParser.cpp
- intern/IntValue.cpp
- intern/HashedPtr.cpp
- intern/ListValue.cpp
- intern/Operator1Expr.cpp
- intern/Operator2Expr.cpp
- intern/PyObjectPlus.cpp
- intern/StringValue.cpp
- intern/Value.cpp
- intern/VectorValue.cpp
- intern/ListWrapper.cpp
-
- EXP_BoolValue.h
- EXP_ConstExpr.h
- EXP_EmptyValue.h
- EXP_ErrorValue.h
- EXP_Expression.h
- EXP_FloatValue.h
- EXP_HashedPtr.h
- EXP_IdentifierExpr.h
- EXP_IfExpr.h
- EXP_InputParser.h
- EXP_IntValue.h
- EXP_ListValue.h
- EXP_Operator1Expr.h
- EXP_Operator2Expr.h
- EXP_PyObjectPlus.h
- EXP_Python.h
- EXP_StringValue.h
- EXP_Value.h
- EXP_VectorValue.h
- EXP_VoidValue.h
- EXP_ListWrapper.h
-
-)
-
-if(WITH_PYTHON)
- list(APPEND SRC
- intern/PythonCallBack.cpp
-
- EXP_PythonCallBack.h
- )
-endif()
-
-blender_add_lib(ge_logic_expressions "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Expressions/EXP_BoolValue.h b/source/gameengine/Expressions/EXP_BoolValue.h
deleted file mode 100644
index 98ba1d75e52..00000000000
--- a/source/gameengine/Expressions/EXP_BoolValue.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * BoolValue.h: interface for the CBoolValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_BoolValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_BOOLVALUE_H__
-#define __EXP_BOOLVALUE_H__
-
-#include "EXP_Value.h"
-
-/**
- * Smart Boolean Value class.
- * Is used by parser when an expression tree is build containing booleans.
- */
-
-class CBoolValue : public CPropValue
-{
-
- //PLUGIN_DECLARE_SERIAL(CBoolValue,CValue)
-
-public:
- static const STR_String sTrueString;
- static const STR_String sFalseString;
-
- CBoolValue();
- CBoolValue(bool inBool);
- CBoolValue(bool innie, const char *name, AllocationTYPE alloctype = CValue::HEAPVALUE);
-
- virtual const STR_String& GetText();
- virtual double GetNumber();
- virtual int GetValueType();
- bool GetBool();
- virtual void SetValue(CValue* newval);
-
- virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
-
- void Configure(CValue* menuvalue);
- virtual CValue* GetReplica();
-#ifdef WITH_PYTHON
- virtual PyObject* ConvertValueToPython();
-#endif
-
-private:
- bool m_bool;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CBoolValue")
-#endif
-};
-
-#endif /* __EXP_BOOLVALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_ConstExpr.h b/source/gameengine/Expressions/EXP_ConstExpr.h
deleted file mode 100644
index b4456dacdf3..00000000000
--- a/source/gameengine/Expressions/EXP_ConstExpr.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ConstExpr.h: interface for the CConstExpr class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_ConstExpr.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_CONSTEXPR_H__
-#define __EXP_CONSTEXPR_H__
-
-#include "EXP_Expression.h"
-#include "EXP_Value.h" // Added by ClassView
-
-class CConstExpr : public CExpression
-{
- //PLUGIN_DECLARE_SERIAL_EXPRESSION (CConstExpr,CExpression)
-public:
- virtual bool MergeExpression(CExpression* otherexpr);
-
- void BroadcastOperators(VALUE_OPERATOR op);
-
- virtual unsigned char GetExpressionID();
- CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks);
- //bool IsInside(float x,float y,float z,bool bBorderInclude=true);
- bool NeedsRecalculated();
- void ClearModified();
- virtual double GetNumber();
- virtual CValue* Calculate();
- CConstExpr(CValue* constval);
- CConstExpr();
- virtual ~CConstExpr();
-
-
-private:
- CValue* m_value;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CConstExpr")
-#endif
-};
-
-#endif /* __EXP_CONSTEXPR_H__ */
diff --git a/source/gameengine/Expressions/EXP_EmptyValue.h b/source/gameengine/Expressions/EXP_EmptyValue.h
deleted file mode 100644
index d23addb9f9f..00000000000
--- a/source/gameengine/Expressions/EXP_EmptyValue.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * EmptyValue.h: interface for the CEmptyValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_EmptyValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_EMPTYVALUE_H__
-#define __EXP_EMPTYVALUE_H__
-
-#include "EXP_Value.h"
-
-class CListValue;
-
-class CEmptyValue : public CPropValue
-{
- //PLUGIN_DECLARE_SERIAL (CEmptyValue,CValue)
-public:
- CEmptyValue();
- virtual ~CEmptyValue();
-
- virtual const STR_String & GetText();
- virtual double GetNumber();
- virtual int GetValueType();
- CListValue* GetPolySoup();
- virtual double* GetVector3(bool bGetTransformedVec=false);
- bool IsInside(CValue* testpoint,bool bBorderInclude=true);
- CValue * Calc(VALUE_OPERATOR op, CValue *val);
- CValue * CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- virtual CValue* GetReplica();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CEmptyValue")
-#endif
-};
-
-#endif /* __EXP_EMPTYVALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_ErrorValue.h b/source/gameengine/Expressions/EXP_ErrorValue.h
deleted file mode 100644
index a6f91ca200a..00000000000
--- a/source/gameengine/Expressions/EXP_ErrorValue.h
+++ /dev/null
@@ -1,47 +0,0 @@
-/*
- * ErrorValue.h: interface for the CErrorValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_ErrorValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_ERRORVALUE_H__
-#define __EXP_ERRORVALUE_H__
-
-#include "EXP_Value.h"
-
-class CErrorValue : public CPropValue
-{
-
-public:
- virtual const STR_String & GetText();
- virtual double GetNumber();
- virtual int GetValueType();
- CErrorValue();
- CErrorValue(const char *errmsg);
- virtual ~CErrorValue();
- virtual CValue* Calc(VALUE_OPERATOR op, CValue* val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- virtual CValue* GetReplica();
-
-private:
- STR_String m_strErrorText;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CErrorValue")
-#endif
-};
-
-#endif /* __EXP_ERRORVALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_Expression.h b/source/gameengine/Expressions/EXP_Expression.h
deleted file mode 100644
index 66a6e9476ff..00000000000
--- a/source/gameengine/Expressions/EXP_Expression.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * Expression.h: interface for the CExpression class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_Expression.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_EXPRESSION_H__
-#define __EXP_EXPRESSION_H__
-
-#include "EXP_Value.h"
-
-//extern int gRefCountExpr; // only for debugging purposes (detect mem.leaks)
-
-
-#define PLUGIN_DECLARE_SERIAL_EXPRESSION(class_name, base_class_name) \
-public: \
- virtual base_class_name * Copy() { \
- return new class_name; \
- } \
- virtual bool EdSerialize(CompressorArchive& arch, \
- class CFactoryManager* facmgr, \
- bool bIsStoring); \
- virtual bool EdIdSerialize(CompressorArchive& arch, \
- class CFactoryManager* facmgr, \
- bool bIsStoring) \
- { \
- if (bIsStoring) \
- { \
- unsigned char exprID = GetExpressionID(); \
- arch << exprID; \
- } \
- return true; \
- } \
-
-
-
-class CExpression;
-
-
-// for undo/redo system the deletion in the expressiontree can be restored by replacing broken links 'inplace'
-class CBrokenLinkInfo
-{
- public:
- CBrokenLinkInfo(CExpression** pmemexpr,CExpression* expr)
- :m_pmemExpr(pmemexpr),
- m_pExpr(expr)
- {
- assertd(pmemexpr);
- m_bRestored=false;
- };
-
- virtual ~CBrokenLinkInfo();
- void RestoreLink();
- void BreakLink();
-
-
- // members vars
- private:
- CExpression** m_pmemExpr;
- CExpression* m_pExpr;
- bool m_bRestored;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CBrokenLinkInfo")
-#endif
-};
-
-
-
-
-
-
-
-
-class CExpression
-{
-public:
- enum {
- COPERATOR1EXPRESSIONID = 1,
- COPERATOR2EXPRESSIONID = 2,
- CCONSTEXPRESSIONID = 3,
- CIFEXPRESSIONID = 4,
- COPERATORVAREXPRESSIONID = 5,
- CIDENTIFIEREXPRESSIONID = 6
- };
-
-
-protected:
- virtual ~CExpression() = 0; //pure virtual
-public:
- virtual bool MergeExpression(CExpression* otherexpr) = 0;
- CExpression();
-
-
- virtual CValue* Calculate() = 0; //pure virtual
- virtual unsigned char GetExpressionID() = 0;
- //virtual bool IsInside(float x,float y,float z,bool bBorderInclude=true) = 0; //pure virtual
- virtual bool NeedsRecalculated() = 0; // another pure one
- virtual CExpression * CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks) =0; // another pure one
- virtual void ClearModified() = 0; // another pure one
- //virtual CExpression * Copy() =0;
- virtual void BroadcastOperators(VALUE_OPERATOR op) =0;
-
- virtual CExpression * AddRef() { // please leave multiline, for debugger !!!
-
-#ifdef DEBUG
- //gRefCountExpr++;
- assertd(m_refcount < 255);
-#endif
- m_refcount++;
- return this;
- };
- virtual CExpression* Release(CExpression* complicatedtrick=NULL) {
-#ifdef DEBUG
- //gRefCountExpr--;
-#endif
- if (--m_refcount < 1)
- {
- delete this;
- } //else
- // return this;
- return complicatedtrick;
- };
-
-
-protected:
-
- int m_refcount;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CExpression")
-#endif
-};
-
-#endif /* __EXP_EXPRESSION_H__ */
diff --git a/source/gameengine/Expressions/EXP_FloatValue.h b/source/gameengine/Expressions/EXP_FloatValue.h
deleted file mode 100644
index 3c16c57d16d..00000000000
--- a/source/gameengine/Expressions/EXP_FloatValue.h
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * FloatValue.h: interface for the CFloatValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_FloatValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_FLOATVALUE_H__
-#define __EXP_FLOATVALUE_H__
-
-#include "EXP_Value.h"
-
-class CFloatValue : public CPropValue
-{
- //PLUGIN_DECLARE_SERIAL (CFloatValue,CValue)
-public:
- CFloatValue();
- CFloatValue(float fl);
- CFloatValue(float fl,const char *name,AllocationTYPE alloctype=CValue::HEAPVALUE);
-
- virtual const STR_String & GetText();
-
- void Configure(CValue* menuvalue);
- virtual double GetNumber();
- virtual int GetValueType();
- virtual void SetValue(CValue* newval);
- float GetFloat();
- void SetFloat(float fl);
- virtual ~CFloatValue();
- virtual CValue* GetReplica();
- virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
-#ifdef WITH_PYTHON
- virtual PyObject* ConvertValueToPython();
-#endif
-
-protected:
- float m_float;
- STR_String* m_pstrRep;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CFloatValue")
-#endif
-};
-
-#endif /* __EXP_FLOATVALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_HashedPtr.h b/source/gameengine/Expressions/EXP_HashedPtr.h
deleted file mode 100644
index 7c7c5f6e5ec..00000000000
--- a/source/gameengine/Expressions/EXP_HashedPtr.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file EXP_HashedPtr.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_HASHEDPTR_H__
-#define __EXP_HASHEDPTR_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class CHashedPtr
-{
- void* m_valptr;
-
-public:
- CHashedPtr(void* val);
-
- unsigned int hash() const;
-
- inline friend bool operator ==( const CHashedPtr & rhs,const CHashedPtr & lhs)
- {
- return rhs.m_valptr == lhs.m_valptr;
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CHashedPtr")
-#endif
-};
-
-#endif /* __EXP_HASHEDPTR_H__ */
diff --git a/source/gameengine/Expressions/EXP_IdentifierExpr.h b/source/gameengine/Expressions/EXP_IdentifierExpr.h
deleted file mode 100644
index 96ef3677cf3..00000000000
--- a/source/gameengine/Expressions/EXP_IdentifierExpr.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file EXP_IdentifierExpr.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_IDENTIFIEREXPR_H__
-#define __EXP_IDENTIFIEREXPR_H__
-
-#include "EXP_Expression.h"
-
-class CIdentifierExpr : public CExpression
-{
- CValue* m_idContext;
- STR_String m_identifier;
-public:
- CIdentifierExpr(const STR_String& identifier,CValue* id_context);
- virtual ~CIdentifierExpr();
-
- virtual CValue* Calculate();
- virtual bool MergeExpression(CExpression* otherexpr);
- virtual unsigned char GetExpressionID();
- virtual bool NeedsRecalculated();
- virtual CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks);
- virtual void ClearModified();
- virtual void BroadcastOperators(VALUE_OPERATOR op);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIdentifierExpr")
-#endif
-};
-
-#endif /* __EXP_IDENTIFIEREXPR_H__ */
diff --git a/source/gameengine/Expressions/EXP_IfExpr.h b/source/gameengine/Expressions/EXP_IfExpr.h
deleted file mode 100644
index 43b4b8faf53..00000000000
--- a/source/gameengine/Expressions/EXP_IfExpr.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * IfExpr.h: interface for the CIfExpr class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_IfExpr.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_IFEXPR_H__
-#define __EXP_IFEXPR_H__
-
-#include "EXP_Expression.h"
-
-class CIfExpr : public CExpression
-{
- //PLUGIN_DECLARE_SERIAL_EXPRESSION (CIfExpr,CExpression)
-
-private:
- CExpression *m_guard, *m_e1, *m_e2;
-
-public:
- virtual bool MergeExpression(CExpression* otherexpr);
- CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2);
- CIfExpr();
-
- virtual unsigned char GetExpressionID();
- virtual ~CIfExpr();
- virtual CValue* Calculate();
-
- virtual bool IsInside(float x,float y,float z,bool bBorderInclude=true);
- virtual bool NeedsRecalculated();
-
-
- virtual CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks);
- virtual void ClearModified();
- virtual void BroadcastOperators(VALUE_OPERATOR op);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIfExpr")
-#endif
-};
-
-#endif /* __EXP_IFEXPR_H__ */
diff --git a/source/gameengine/Expressions/EXP_InputParser.h b/source/gameengine/Expressions/EXP_InputParser.h
deleted file mode 100644
index 80471009a16..00000000000
--- a/source/gameengine/Expressions/EXP_InputParser.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * Parser.h: interface for the CParser class.
- * Eindhoven University of Technology 1997
- * OOPS team (Serge vd Boom, Erwin Coumans, Tom Geelen, Wynke Stuylemeier)
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_InputParser.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_INPUTPARSER_H__
-#define __EXP_INPUTPARSER_H__
-
-class CParser;
-#include "EXP_Expression.h"
-
-
-class CParser
-{
-public:
- CParser();
- virtual ~CParser();
-
- float GetFloat(STR_String& txt);
- CValue* GetValue(STR_String& txt, bool bFallbackToText=false);
- CExpression* ProcessText(const char *intext);
- void SetContext(CValue* context);
-
-private:
- enum symbols {
- errorsym,
- lbracksym,
- rbracksym,
- cellsym,
- commasym,
- opsym,
- constsym,
- sumsym,
- ifsym,
- whocodedsym,
- eolsym,
- idsym
- }; // all kinds of symbols
-
- enum optype {
- OPmodulus,
- OPplus,
- OPminus,
- OPtimes,
- OPdivide,
- OPand,
- OPor,
- OPequal,
- OPunequal,
- OPgreater,
- OPless,
- OPgreaterequal,
- OPlessequal,
- OPnot
- }; // all kinds of operators
-
- enum consttype {
- booltype,
- inttype,
- floattype,
- stringtype
- }; // all kinds of constants
-
- int sym, // current symbol
- opkind, // kind of operator, if symbol is an operator
- constkind; // kind of operator, if symbol is a constant
-
- char ch; // current character
- int chcount; // index to character in input string
- CExpression *errmsg; // contains a errormessage, if scanner error
-
- STR_String text, // contains a copy of the original text
- const_as_string; // string representation of the symbol, if symbol is a constant
- bool boolvalue; // value of the boolean, if symbol is a constant of type boolean
- CValue* m_identifierContext;// context in which identifiers are looked up
-
-
- void ScanError(const char *str);
- CExpression* Error(const char *str);
- void NextCh();
- void TermChar(char c);
- void DigRep();
- void CharRep();
- void GrabString(int start);
- void GrabRealString(int start);
- void NextSym();
-#if 0 /* not used yet */
- int MakeInt();
-#endif
- const char *Symbol2Str(int s);
- void Term(int s);
- int Priority(int optor);
- CExpression *Ex(int i);
- CExpression *Expr();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CParser")
-#endif
-};
-
-#endif /* __EXP_INPUTPARSER_H__ */
-
diff --git a/source/gameengine/Expressions/EXP_IntValue.h b/source/gameengine/Expressions/EXP_IntValue.h
deleted file mode 100644
index a1cd96a888e..00000000000
--- a/source/gameengine/Expressions/EXP_IntValue.h
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * IntValue.h: interface for the CIntValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_IntValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_INTVALUE_H__
-#define __EXP_INTVALUE_H__
-
-
-#include "EXP_Value.h"
-
-typedef long long cInt;
-
-class CIntValue : public CPropValue
-{
- //PLUGIN_DECLARE_SERIAL (CIntValue,CValue)
-
-public:
- virtual const STR_String& GetText();
- virtual double GetNumber();
- virtual int GetValueType();
-
- cInt GetInt();
- CIntValue();
- CIntValue(cInt innie);
- CIntValue(cInt innie,
- const char *name,
- AllocationTYPE alloctype=CValue::HEAPVALUE);
-
- virtual CValue* Calc(VALUE_OPERATOR op,
- CValue *val);
-
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype,
- VALUE_OPERATOR op,
- CValue *val);
-
- virtual void SetValue(CValue* newval);
-
- void Configure(CValue* menuvalue);
- void AddConfigurationData(CValue* menuvalue);
- virtual CValue* GetReplica();
-
-#ifdef WITH_PYTHON
- virtual PyObject* ConvertValueToPython();
-#endif
-
-protected:
- virtual ~CIntValue();
-
-private:
- cInt m_int;
- STR_String* m_pstrRep;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CIntValue")
-#endif
-};
-
-#endif /* __EXP_INTVALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_ListValue.h b/source/gameengine/Expressions/EXP_ListValue.h
deleted file mode 100644
index f5421066f62..00000000000
--- a/source/gameengine/Expressions/EXP_ListValue.h
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * ListValue.h: interface for the CListValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_ListValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_LISTVALUE_H__
-#define __EXP_LISTVALUE_H__
-
-#include "EXP_Value.h"
-
-class CListValue : public CPropValue
-{
- Py_Header
- //PLUGIN_DECLARE_SERIAL (CListValue,CValue)
-
-public:
- CListValue();
- virtual ~CListValue();
-
- void AddConfigurationData(CValue* menuvalue);
- void Configure(CValue* menuvalue);
- void Add(CValue* value);
-
- /** \attention not implemented yet :( */
- virtual CValue* Calc(VALUE_OPERATOR op,CValue *val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype,
- VALUE_OPERATOR op,
- CValue* val);
- virtual double GetNumber();
- virtual int GetValueType();
- virtual CValue* GetReplica();
-
-public:
- void MergeList(CListValue* otherlist);
- bool RemoveValue(CValue* val);
- void SetReleaseOnDestruct(bool bReleaseContents);
- bool SearchValue(CValue* val);
-
- CValue* FindValue(const STR_String & name);
- CValue* FindValue(const char *name);
-
- void ReleaseAndRemoveAll();
- virtual void SetModified(bool bModified);
- virtual inline bool IsModified();
- void Remove(int i);
- void Resize(int num);
- void SetValue(int i,CValue* val);
- CValue* GetValue(int i) { assertd(i < m_pValueArray.size()); return m_pValueArray[i]; }
- int GetCount() { return m_pValueArray.size(); }
- virtual const STR_String & GetText();
-
- bool CheckEqual(CValue* first,CValue* second);
-
-#ifdef WITH_PYTHON
- virtual PyObject *py_repr(void) {
- PyObject *py_proxy= this->GetProxy();
- PyObject *py_list= PySequence_List(py_proxy);
- PyObject *py_string= PyObject_Repr(py_list);
- Py_DECREF(py_list);
- Py_DECREF(py_proxy);
- return py_string;
- }
-
- KX_PYMETHOD_O(CListValue,append);
- KX_PYMETHOD_NOARGS(CListValue,reverse);
- KX_PYMETHOD_O(CListValue,index);
- KX_PYMETHOD_O(CListValue,count);
- KX_PYMETHOD_VARARGS(CListValue,get);
- KX_PYMETHOD_O(CListValue,from_id);
-#endif
-
-private:
-
- std::vector<CValue*> m_pValueArray;
- bool m_bReleaseContents;
-};
-
-#endif /* __EXP_LISTVALUE_H__ */
-
diff --git a/source/gameengine/Expressions/EXP_ListWrapper.h b/source/gameengine/Expressions/EXP_ListWrapper.h
deleted file mode 100644
index e4c97691acb..00000000000
--- a/source/gameengine/Expressions/EXP_ListWrapper.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Porteries Tristan.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file EXP_ListWrapper.h
- * \ingroup expressions
- */
-
-#ifdef WITH_PYTHON
-
-#ifndef __EXP_LISTWRAPPER_H__
-#define __EXP_LISTWRAPPER_H__
-
-#include "EXP_Value.h"
-
-class CListWrapper : public CValue
-{
- Py_Header
-private:
- /** The client instance passed as first argument of each callback.
- * We use a void * instead of a template to avoid to declare this class
- * for each use in KX_PythonInitTypes.
- */
- void *m_client;
-
- // The python object which owned this list.
- PyObject *m_base;
-
- /// Returns true if the list is still valid, else each call will raise an error.
- bool (*m_checkValid)(void *);
-
- /// Returns the list size.
- int (*m_getSize)(void *);
-
- /// Returns the list item for the giving index.
- PyObject *(*m_getItem)(void *, int);
-
- /// Returns name item for the giving index, used for python operator list["name"].
- const char *(*m_getItemName)(void *, int);
-
- /// Sets the nex item to the index place, return false when failed item conversion.
- bool (*m_setItem)(void *, int, PyObject *);
-
-public:
- CListWrapper(void *client,
- PyObject *base,
- bool (*checkValid)(void *),
- int (*getSize)(void *),
- PyObject *(*getItem)(void *, int),
- const char *(*getItemName)(void *, int),
- bool (*setItem)(void *, int, PyObject *));
- ~CListWrapper();
-
- /// \section Python Interface
- bool CheckValid();
- int GetSize();
- PyObject *GetItem(int index);
- const char *GetItemName(int index);
- bool SetItem(int index, PyObject *item);
- bool AllowSetItem();
- bool AllowGetItemByName();
-
- /// \section CValue Inherited Functions.
- virtual const STR_String &GetText();
- virtual void SetName(const char *name);
- virtual STR_String &GetName();
- virtual CValue *GetReplica();
- virtual CValue *Calc(VALUE_OPERATOR op, CValue *val);
- virtual CValue *CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- virtual double GetNumber();
- virtual int GetValueType();
- virtual PyObject *py_repr();
-
- // Python list operators.
- static PySequenceMethods py_as_sequence;
- // Python dictionnary operators.
- static PyMappingMethods py_as_mapping;
-
- static Py_ssize_t py_len(PyObject *self);
- static PyObject *py_get_item(PyObject *self, Py_ssize_t index);
- static int py_set_item(PyObject *self, Py_ssize_t index, PyObject *value);
- static PyObject *py_mapping_subscript(PyObject *self, PyObject *key);
- static int py_mapping_ass_subscript(PyObject *self, PyObject *key, PyObject *value);
- static int py_contains(PyObject *self, PyObject *key);
-
- KX_PYMETHOD_VARARGS(CListWrapper, Get);
-};
-
-#endif // __EXP_LISTWRAPPER_H__
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Expressions/EXP_Operator1Expr.h b/source/gameengine/Expressions/EXP_Operator1Expr.h
deleted file mode 100644
index 9a05ce9c0c4..00000000000
--- a/source/gameengine/Expressions/EXP_Operator1Expr.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Operator1Expr.h: interface for the COperator1Expr class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_Operator1Expr.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_OPERATOR1EXPR_H__
-#define __EXP_OPERATOR1EXPR_H__
-
-#include "EXP_Expression.h"
-
-class COperator1Expr : public CExpression
-{
- //PLUGIN_DECLARE_SERIAL_EXPRESSION (COperator1Expr,CExpression)
-
-
-
-public:
- virtual bool MergeExpression(CExpression* otherexpr);
- virtual void BroadcastOperators(VALUE_OPERATOR op);
-
- virtual unsigned char GetExpressionID() { return COPERATOR1EXPRESSIONID; }
- CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks);
- //virtual bool IsInside(float x,float y,float z,bool bBorderInclude = true);
- virtual bool NeedsRecalculated();
- void ClearModified() {
- if (m_lhs)
- m_lhs->ClearModified();
- }
- virtual CValue* Calculate();
- COperator1Expr(VALUE_OPERATOR op, CExpression *lhs);
- COperator1Expr();
- virtual ~COperator1Expr();
-
-
-
-private:
- VALUE_OPERATOR m_op;
- CExpression * m_lhs;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:")
-#endif
-};
-
-#endif /* __EXP_OPERATOR1EXPR_H__ */
diff --git a/source/gameengine/Expressions/EXP_Operator2Expr.h b/source/gameengine/Expressions/EXP_Operator2Expr.h
deleted file mode 100644
index cd7a492fde0..00000000000
--- a/source/gameengine/Expressions/EXP_Operator2Expr.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * Operator2Expr.h: interface for the COperator2Expr class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_Operator2Expr.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_OPERATOR2EXPR_H__
-#define __EXP_OPERATOR2EXPR_H__
-
-
-#include "EXP_Expression.h"
-#include "EXP_Value.h" // Added by ClassView
-
-class COperator2Expr : public CExpression
-{
- //PLUGIN_DECLARE_SERIAL_EXPRESSION (COperator2Expr,CExpression)
-
-public:
- virtual bool MergeExpression(CExpression* otherexpr);
- virtual unsigned char GetExpressionID() { return COPERATOR2EXPRESSIONID; }
- virtual void BroadcastOperators(VALUE_OPERATOR op);
- CExpression* CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks);
- //virtual bool IsInside(float x,float y,float z,bool bBorderInclude=true);
- //virtual bool IsLeftInside(float x,float y,float z,bool bBorderInclude);
- //virtual bool IsRightInside(float x,float y,float z,bool bBorderInclude);
- bool NeedsRecalculated();
- void ClearModified() {
- if (m_lhs)
- m_lhs->ClearModified();
- if (m_rhs)
- m_rhs->ClearModified();
- }
- virtual CValue* Calculate();
- COperator2Expr(VALUE_OPERATOR op, CExpression *lhs, CExpression *rhs);
- COperator2Expr();
- virtual ~COperator2Expr();
-
-
-protected:
- CExpression * m_rhs;
- CExpression * m_lhs;
- CValue* m_cached_calculate; // cached result
-
-private:
- VALUE_OPERATOR m_op;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:COperator2Expr")
-#endif
-};
-
-#endif /* __EXP_OPERATOR2EXPR_H__ */
-
diff --git a/source/gameengine/Expressions/EXP_PyObjectPlus.h b/source/gameengine/Expressions/EXP_PyObjectPlus.h
deleted file mode 100644
index 32dc79cf6eb..00000000000
--- a/source/gameengine/Expressions/EXP_PyObjectPlus.h
+++ /dev/null
@@ -1,648 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file EXP_PyObjectPlus.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_PYOBJECTPLUS_H__
-#define __EXP_PYOBJECTPLUS_H__
-
-/* for now keep weakrefs optional */
-#define USE_WEAKREFS
-
-
-#ifndef __cplusplus // c++ only
-#error Must be compiled with C++
-#endif
-
-#include "EXP_Python.h"
-#include "STR_String.h"
-#include "MT_Vector3.h"
-#include "SG_QList.h"
-#include <stddef.h>
-
-#ifdef WITH_PYTHON
-#ifdef USE_MATHUTILS
-extern "C" {
-#include "../../blender/python/mathutils/mathutils.h" /* so we can have mathutils callbacks */
-#include "../../blender/python/generic/py_capi_utils.h" /* for PyC_LineSpit only */
-}
-#endif
-
-#define MAX_PROP_NAME 64
-
-/* Use with ShowDeprecationWarning macro */
-typedef struct {
- bool warn_done;
- void *link;
-} WarnLink;
-
-#define ShowDeprecationWarning(old_way, new_way) \
-{ \
- static WarnLink wlink = {false, NULL}; \
- if ((PyObjectPlus::m_ignore_deprecation_warnings || wlink.warn_done)==0) \
- { \
- PyObjectPlus::ShowDeprecationWarning_func(old_way, new_way); \
- \
- WarnLink *wlink_last= PyObjectPlus::GetDeprecationWarningLinkLast(); \
- wlink.warn_done = true; \
- wlink.link = NULL; \
- \
- if (wlink_last) { \
- wlink_last->link= (void *)&(wlink); \
- PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \
- } \
- else { \
- PyObjectPlus::SetDeprecationWarningFirst(&(wlink)); \
- PyObjectPlus::SetDeprecationWarningLinkLast(&(wlink)); \
- } \
- } \
-} \
-
-
-
-typedef struct PyObjectPlus_Proxy {
- PyObject_HEAD /* required python macro */
- class PyObjectPlus *ref; // pointer to GE object, it holds a reference to this proxy
- void *ptr; // optional pointer to generic structure, the structure holds no reference to this proxy
- bool py_owns; // true if the object pointed by ref should be deleted when the proxy is deleted
- bool py_ref; // true if proxy is connected to a GE object (ref is used)
-#ifdef USE_WEAKREFS
- PyObject *in_weakreflist; // weak reference enabler
-#endif
-} PyObjectPlus_Proxy;
-
-#define BGE_PROXY_ERROR_MSG "Blender Game Engine data has been freed, cannot use this python variable"
-#define BGE_PROXY_REF(_self) (((PyObjectPlus_Proxy *)_self)->ref)
-#define BGE_PROXY_PTR(_self) (((PyObjectPlus_Proxy *)_self)->ptr)
-#define BGE_PROXY_PYOWNS(_self) (((PyObjectPlus_Proxy *)_self)->py_owns)
-#define BGE_PROXY_PYREF(_self) (((PyObjectPlus_Proxy *)_self)->py_ref)
-#ifdef USE_WEAKREFS
-# define BGE_PROXY_WKREF(_self) (((PyObjectPlus_Proxy *)_self)->in_weakreflist)
-#endif
-
-/* Note, sometimes we don't care what BGE type this is as long as its a proxy */
-#define BGE_PROXY_CHECK_TYPE(_type) ((_type)->tp_dealloc == PyObjectPlus::py_base_dealloc)
-
-/* Opposite of BGE_PROXY_REF */
-#define BGE_PROXY_FROM_REF(_self) (((PyObjectPlus *)_self)->GetProxy())
-/* Same as 'BGE_PROXY_REF' but doesn't incref. */
-#define BGE_PROXY_FROM_REF_BORROW(_self) _bge_proxy_from_ref_borrow((void *)_self)
-
-
-// This must be the first line of each
-// PyC++ class
-// AttributesPtr correspond to attributes of proxy generic pointer
-// each PyC++ class must be registered in KX_PythonInitTypes.cpp
-#define __Py_Header \
-public: \
- static PyTypeObject Type; \
- static PyMethodDef Methods[]; \
- static PyAttributeDef Attributes[]; \
- virtual PyTypeObject *GetType(void) { \
- return &Type; \
- } \
- virtual PyObject *GetProxy() { \
- return GetProxyPlus_Ext(this, &Type, NULL); \
- } \
- virtual PyObject *NewProxy(bool py_owns) { \
- return NewProxyPlus_Ext(this, &Type, NULL, py_owns); \
- } \
-
-// leave above line empty (macro)!
-// use this macro for class that use generic pointer in proxy
-// GetProxy() and NewProxy() must be defined to set the correct pointer in the proxy
-#define __Py_HeaderPtr \
-public: \
- static PyTypeObject Type; \
- static PyMethodDef Methods[]; \
- static PyAttributeDef Attributes[]; \
- static PyAttributeDef AttributesPtr[]; \
- virtual PyTypeObject *GetType(void) { \
- return &Type; \
- } \
- virtual PyObject *GetProxy(); \
- virtual PyObject *NewProxy(bool py_owns); \
-
-// leave above line empty (macro)!
-#ifdef WITH_CXX_GUARDEDALLOC
-#define Py_Header __Py_Header \
- void *operator new(size_t num_bytes) { \
- return MEM_mallocN(num_bytes, Type.tp_name); \
- } \
- void operator delete(void *mem) { \
- MEM_freeN(mem); \
- } \
-
-#else
-# define Py_Header __Py_Header
-#endif
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#define Py_HeaderPtr __Py_HeaderPtr \
- void *operator new(size_t num_bytes) { \
- return MEM_mallocN(num_bytes, Type.tp_name); \
- } \
- void operator delete(void *mem) { \
- MEM_freeN(mem); \
- } \
-
-#else
-# define Py_HeaderPtr __Py_HeaderPtr
-#endif
-
-/*
- * nonzero values are an error for setattr
- * however because of the nested lookups we need to know if the errors
- * was because the attribute didnt exits of if there was some problem setting the value
- */
-
-#define PY_SET_ATTR_COERCE_FAIL 2
-#define PY_SET_ATTR_FAIL 1
-#define PY_SET_ATTR_MISSING -1
-#define PY_SET_ATTR_SUCCESS 0
-
-/**
- * These macros are helpful when embedding Python routines. The second
- * macro is one that also requires a documentation string
- */
-#define KX_PYMETHOD(class_name, method_name) \
- PyObject *Py##method_name(PyObject *args, PyObject *kwds); \
- static PyObject * \
- sPy##method_name(PyObject *self, PyObject *args, PyObject *kwds) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "() - " \
- BGE_PROXY_ERROR_MSG); \
- return NULL; \
- } \
- return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \
- } \
-
-#define KX_PYMETHOD_VARARGS(class_name, method_name) \
- PyObject *Py##method_name(PyObject *args); \
- static PyObject* \
- sPy##method_name(PyObject *self, PyObject *args) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "() - " \
- BGE_PROXY_ERROR_MSG); return NULL; \
- } \
- return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \
- } \
-
-#define KX_PYMETHOD_NOARGS(class_name, method_name) \
- PyObject *Py##method_name(); \
- static PyObject* \
- sPy##method_name(PyObject *self) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "() - " \
- BGE_PROXY_ERROR_MSG); return NULL; \
- } \
- return((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \
- } \
-
-#define KX_PYMETHOD_O(class_name, method_name) \
- PyObject *Py##method_name(PyObject *value); \
- static PyObject* \
- sPy##method_name(PyObject *self, PyObject *value) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "(value) - " \
- BGE_PROXY_ERROR_MSG); return NULL; \
- } \
- return((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \
- } \
-
-#define KX_PYMETHOD_DOC(class_name, method_name) \
- PyObject *Py##method_name(PyObject *args, PyObject *kwds); \
- static PyObject* \
- sPy##method_name(PyObject *self, PyObject *args, PyObject *kwds) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "(...) - " \
- BGE_PROXY_ERROR_MSG); return NULL; \
- } \
- return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args, kwds); \
- } \
- static const char method_name##_doc[]; \
-
-#define KX_PYMETHOD_DOC_VARARGS(class_name, method_name) \
- PyObject *Py##method_name(PyObject *args); \
- static PyObject* \
- sPy##method_name(PyObject *self, PyObject *args) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "(...) - " \
- BGE_PROXY_ERROR_MSG); \
- return NULL; \
- } \
- return((class_name*)BGE_PROXY_REF(self))->Py##method_name(args); \
- } \
- static const char method_name##_doc[]; \
-
-#define KX_PYMETHOD_DOC_O(class_name, method_name) \
- PyObject *Py##method_name(PyObject *value); \
- static PyObject * \
- sPy##method_name(PyObject *self, PyObject *value) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "(value) - " \
- BGE_PROXY_ERROR_MSG); \
- return NULL; \
- } \
- return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(value); \
- } \
- static const char method_name##_doc[]; \
-
-#define KX_PYMETHOD_DOC_NOARGS(class_name, method_name) \
- PyObject *Py##method_name(); \
- static PyObject * \
- sPy##method_name(PyObject *self) { \
- if (BGE_PROXY_REF(self)==NULL) { \
- PyErr_SetString(PyExc_RuntimeError, \
- #class_name "." #method_name "() - " \
- BGE_PROXY_ERROR_MSG); \
- return NULL; \
- } \
- return ((class_name*)BGE_PROXY_REF(self))->Py##method_name(); \
- } \
- static const char method_name##_doc[]; \
-
-
-/* The line above should remain empty */
-/**
- * Method table macro (with doc)
- */
-#define KX_PYMETHODTABLE(class_name, method_name) \
- {#method_name, (PyCFunction) class_name::sPy##method_name, METH_VARARGS, (const char *)class_name::method_name##_doc}
-
-#define KX_PYMETHODTABLE_O(class_name, method_name) \
- {#method_name, (PyCFunction) class_name::sPy##method_name, METH_O, (const char *)class_name::method_name##_doc}
-
-#define KX_PYMETHODTABLE_NOARGS(class_name, method_name) \
- {#method_name, (PyCFunction) class_name::sPy##method_name, METH_NOARGS, (const char *)class_name::method_name##_doc}
-
-#define KX_PYMETHODTABLE_KEYWORDS(class_name, method_name) \
- {#method_name, (PyCFunction) class_name::sPy##method_name, METH_VARARGS|METH_KEYWORDS, (const char *)class_name::method_name##_doc}
-
-/**
- * Function implementation macro
- */
-#define KX_PYMETHODDEF_DOC(class_name, method_name, doc_string) \
-const char class_name::method_name##_doc[] = doc_string; \
-PyObject *class_name::Py##method_name(PyObject *args, PyObject *kwds)
-
-#define KX_PYMETHODDEF_DOC_VARARGS(class_name, method_name, doc_string) \
-const char class_name::method_name##_doc[] = doc_string; \
-PyObject *class_name::Py##method_name(PyObject *args)
-
-#define KX_PYMETHODDEF_DOC_O(class_name, method_name, doc_string) \
-const char class_name::method_name##_doc[] = doc_string; \
-PyObject *class_name::Py##method_name(PyObject *value)
-
-#define KX_PYMETHODDEF_DOC_NOARGS(class_name, method_name, doc_string) \
-const char class_name::method_name##_doc[] = doc_string; \
-PyObject *class_name::Py##method_name()
-
-/**
- * Attribute management
- */
-enum KX_PYATTRIBUTE_TYPE {
- KX_PYATTRIBUTE_TYPE_BOOL,
- KX_PYATTRIBUTE_TYPE_ENUM,
- KX_PYATTRIBUTE_TYPE_SHORT,
- KX_PYATTRIBUTE_TYPE_INT,
- KX_PYATTRIBUTE_TYPE_FLOAT,
- KX_PYATTRIBUTE_TYPE_STRING,
- KX_PYATTRIBUTE_TYPE_DUMMY,
- KX_PYATTRIBUTE_TYPE_FUNCTION,
- KX_PYATTRIBUTE_TYPE_VECTOR,
- KX_PYATTRIBUTE_TYPE_FLAG,
- KX_PYATTRIBUTE_TYPE_CHAR
-};
-
-enum KX_PYATTRIBUTE_ACCESS {
- KX_PYATTRIBUTE_RW,
- KX_PYATTRIBUTE_RO
-};
-
-struct KX_PYATTRIBUTE_DEF;
-typedef int (*KX_PYATTRIBUTE_CHECK_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-typedef int (*KX_PYATTRIBUTE_SET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-typedef PyObject *(*KX_PYATTRIBUTE_GET_FUNCTION)(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-
-typedef struct KX_PYATTRIBUTE_DEF {
- const char *m_name; // name of the python attribute
- KX_PYATTRIBUTE_TYPE m_type; // type of value
- KX_PYATTRIBUTE_ACCESS m_access; // read/write access or read-only
- int m_imin; // minimum value in case of integer attributes
- // (for string: minimum string length, for flag: mask value, for float: matrix row size)
- int m_imax; // maximum value in case of integer attributes
- // (for string: maximum string length, for flag: 1 if flag is negative, float: vector/matrix col size)
- float m_fmin; // minimum value in case of float attributes
- float m_fmax; // maximum value in case of float attributes
- bool m_clamp; // enforce min/max value by clamping
- bool m_usePtr; // the attribute uses the proxy generic pointer, set at runtime
- size_t m_offset; // position of field in structure
- size_t m_size; // size of field for runtime verification (enum only)
- size_t m_length; // length of array, 1=simple attribute
- KX_PYATTRIBUTE_CHECK_FUNCTION m_checkFunction; // static function to check the assignment, returns 0 if no error
- KX_PYATTRIBUTE_SET_FUNCTION m_setFunction; // static function to check the assignment, returns 0 if no error
- KX_PYATTRIBUTE_GET_FUNCTION m_getFunction; // static function to check the assignment, returns 0 if no error
-
- // The following pointers are just used to have compile time check for attribute type.
- // It would have been good to use a union but that would require C99 compatibility
- // to initialize specific union fields through designated initializers.
- struct {
- bool *m_boolPtr;
- short int *m_shortPtr;
- int *m_intPtr;
- float *m_floatPtr;
- STR_String *m_stringPtr;
- MT_Vector3 *m_vectorPtr;
- char *m_charPtr;
- } m_typeCheck;
-} PyAttributeDef;
-
-#define KX_PYATTRIBUTE_BOOL_RW(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_BOOL_RW_CHECK(name, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RW, 0, 1, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_BOOL_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_BOOL, KX_PYATTRIBUTE_RO, 0, 1, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {&((object *)0)->field, NULL, NULL, NULL, NULL, NULL, NULL} }
-
-/* attribute points to a single bit of an integer field, attribute=true if bit is set */
-#define KX_PYATTRIBUTE_FLAG_RW(name, object, field, bit) \
- { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLAG_RW_CHECK(name, object, field, bit, function) \
- { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLAG_RO(name, object, field, bit) \
- { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-
-/* attribute points to a single bit of an integer field, attribute=true if bit is set*/
-#define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW(name, object, field, bit) \
- { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLAG_NEGATIVE_RW_CHECK(name, object, field, bit, function) \
- { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RW, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLAG_NEGATIVE_RO(name, object, field, bit) \
- { name, KX_PYATTRIBUTE_TYPE_FLAG, KX_PYATTRIBUTE_RO, bit, 1, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-
-// enum field cannot be mapped to pointer (because we would need a pointer for each enum)
-// use field size to verify mapping at runtime only, assuming enum size is equal to int size.
-#define KX_PYATTRIBUTE_ENUM_RW(name, min, max, clamp, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_ENUM_RW_CHECK(name, min, max, clamp, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_ENUM_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_ENUM, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-
-#define KX_PYATTRIBUTE_SHORT_RW(name, min, max, clamp, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_SHORT_RW_CHECK(name, min, max, clamp, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_SHORT_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_SHORT_ARRAY_RW(name, min, max, clamp, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_SHORT_ARRAY_RW_CHECK(name, min, max, clamp, object, field, length, function) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_SHORT_ARRAY_RO(name, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, ((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-// SHORT_LIST
-#define KX_PYATTRIBUTE_SHORT_LIST_RW(name, min, max, clamp, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_SHORT_LIST_RW_CHECK(name, min, max, clamp, object, field, length, function) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_SHORT_LIST_RO(name, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_SHORT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, &((object *)0)->field, NULL, NULL, NULL, NULL, NULL} }
-
-#define KX_PYATTRIBUTE_INT_RW(name, min, max, clamp, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_INT_RW_CHECK(name, min, max, clamp, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_INT_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_INT_ARRAY_RW(name, min, max, clamp, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_INT_ARRAY_RW_CHECK(name, min, max, clamp, object, field, length, function) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_INT_ARRAY_RO(name, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, ((object *)0)->field, NULL, NULL, NULL, NULL} }
-// INT_LIST
-#define KX_PYATTRIBUTE_INT_LIST_RW(name, min, max, clamp, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_INT_LIST_RW_CHECK(name, min, max, clamp, object, field, length, function) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_INT_LIST_RO(name, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_INT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, &((object *)0)->field, NULL, NULL, NULL, NULL} }
-
-// always clamp for float
-#define KX_PYATTRIBUTE_FLOAT_RW(name, min, max, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_RW_CHECK(name, min, max, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, &((object *)0)->field, NULL, NULL, NULL} }
-// field must be float[n], returns a sequence
-#define KX_PYATTRIBUTE_FLOAT_ARRAY_RW(name, min, max, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK(name, min, max, object, field, length, function) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, length, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_ARRAY_RO(name, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, length, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} }
-// field must be float[n], returns a vector
-#define KX_PYATTRIBUTE_FLOAT_VECTOR_RW(name, min, max, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_VECTOR_RW_CHECK(name, min, max, object, field, length, function) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, 0, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_VECTOR_RO(name, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, 0, length, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field, NULL, NULL, NULL} }
-// field must be float[n][n], returns a matrix
-#define KX_PYATTRIBUTE_FLOAT_MATRIX_RW(name, min, max, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, length, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_MATRIX_RW_CHECK(name, min, max, object, field, length, function) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RW, length, length, min, max, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_FLOAT_MATRIX_RO(name, object, field, length) \
- { name, KX_PYATTRIBUTE_TYPE_FLOAT, KX_PYATTRIBUTE_RO, length, length, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, ((object *)0)->field[0], NULL, NULL, NULL} }
-
-// only for STR_String member
-#define KX_PYATTRIBUTE_STRING_RW(name, min, max, clamp, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} }
-#define KX_PYATTRIBUTE_STRING_RW_CHECK(name, min, max, clamp, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RW, min, max, 0.f, 0.f, clamp, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} }
-#define KX_PYATTRIBUTE_STRING_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_STRING, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, &((object *)0)->field, NULL, NULL} }
-
-// only for char [] array
-#define KX_PYATTRIBUTE_CHAR_RW(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} }
-#define KX_PYATTRIBUTE_CHAR_RW_CHECK(name, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, true, false, offsetof(object, field), sizeof(((object *)0)->field), 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} }
-#define KX_PYATTRIBUTE_CHAR_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_CHAR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), sizeof(((object *)0)->field), 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, NULL, ((object *)0)->field} }
-
-// for MT_Vector3 member
-#define KX_PYATTRIBUTE_VECTOR_RW(name, min, max, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} }
-#define KX_PYATTRIBUTE_VECTOR_RW_CHECK(name, min, max, clamp, object, field, function) \
- { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RW, 0, 0, min, max, true, false, offsetof(object, field), 0, 1, &object::function, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} }
-#define KX_PYATTRIBUTE_VECTOR_RO(name, object, field) \
- { name, KX_PYATTRIBUTE_TYPE_VECTOR, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, offsetof(object, field), 0, 1 , NULL, NULL, NULL, {NULL, NULL, NULL, NULL, NULL, &((object *)0)->field, NULL} }
-
-#define KX_PYATTRIBUTE_RW_FUNCTION(name, object, getfunction, setfunction) \
- { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_RO_FUNCTION(name, object, getfunction) \
- { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0.f, false, false, 0, 0, 1, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_ARRAY_RW_FUNCTION(name, object, length, getfunction, setfunction) \
- { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RW, 0, 0, 0.f, 0, f, false, false, 0, 0, length, NULL, &object::setfunction, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-#define KX_PYATTRIBUTE_ARRAY_RO_FUNCTION(name, object, length, getfunction) \
- { name, KX_PYATTRIBUTE_TYPE_FUNCTION, KX_PYATTRIBUTE_RO, 0, 0, 0.f, 0, f, false, false, 0, 0, length, NULL, NULL, &object::getfunction, {NULL, NULL, NULL, NULL, NULL, NULL, NULL} }
-
-
-/*------------------------------
- * PyObjectPlus
- *------------------------------ */
-typedef PyTypeObject *PyParentObject; /* Define the PyParent Object */
-
-#else // WITH_PYTHON
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#define Py_Header \
-public: \
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlus") \
-
-
-#define Py_HeaderPtr \
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PyObjectPlusPtr") \
-
-#else // WITH_CXX_GUARDEDALLOC
-
-#define Py_Header \
-public: \
-
-#define Py_HeaderPtr \
-public: \
-
-#endif /* WITH_CXX_GUARDEDALLOC */
-
-#endif
-
-
-// By making SG_QList the ultimate parent for PyObjectPlus objects, it
-// allows to put them in 2 different dynamic lists at the same time
-// The use of these links is interesting because they free of memory allocation
-// but it's very important not to mess up with them. If you decide that
-// the SG_QList or SG_DList component is used for something for a certain class,
-// they cannot can be used for anything else at a parent level!
-// What these lists are and what they are used for must be carefully documented
-// at the level where they are used.
-// DON'T MAKE ANY USE OF THESE LIST AT THIS LEVEL, they are already used
-// at SCA_IActuator, SCA_ISensor, SCA_IController level which rules out the
-// possibility to use them at SCA_ILogicBrick, CValue and PyObjectPlus level.
-class PyObjectPlus : public SG_QList
-{ // The PyObjectPlus abstract class
- Py_Header // Always start with Py_Header
-
-public:
- PyObjectPlus();
-
- virtual ~PyObjectPlus(); // destructor
-
-#ifdef WITH_PYTHON
- PyObject *m_proxy; /* actually a PyObjectPlus_Proxy */
-
- /* These static functions are referenced by ALL PyObjectPlus_Proxy types
- * they take the C++ reference from the PyObjectPlus_Proxy and call
- * its own virtual py_repr, py_base_dealloc, etc. functions.
- */
-
- static PyObject* py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds); /* allows subclassing */
- static void py_base_dealloc(PyObject *self);
- static PyObject* py_base_repr(PyObject *self);
-
- /* These are all virtual python methods that are defined in each class
- * Our own fake subclassing calls these on each class, then calls the parent */
- virtual PyObject* py_repr(void);
- /* subclass may overwrite this function to implement more sophisticated method of validating a proxy */
- virtual bool py_is_valid(void) { return true; }
-
- static PyObject* py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef);
- static int py_set_attrdef(PyObject *self_py, PyObject *value, const PyAttributeDef *attrdef);
-
- /* Kindof dumb, always returns True, the false case is checked for, before this function gets accessed */
- static PyObject* pyattr_get_invalid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- static PyObject *GetProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr);
- /* self=NULL => proxy to generic pointer detached from GE object
- * if py_owns is true, the memory pointed by ptr will be deleted automatically with MEM_freeN
- * self!=NULL=> proxy attached to GE object, ptr is optional and point to a struct from which attributes can be defined
- * if py_owns is true, the object will be deleted automatically, ptr will NOT be deleted
- * (assume object destructor takes care of it) */
- static PyObject *NewProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr, bool py_owns);
-
- static WarnLink* GetDeprecationWarningLinkFirst(void);
- static WarnLink* GetDeprecationWarningLinkLast(void);
- static void SetDeprecationWarningFirst(WarnLink* wlink);
- static void SetDeprecationWarningLinkLast(WarnLink* wlink);
- static void NullDeprecationWarning();
-
- /** enable/disable display of deprecation warnings */
- static void SetDeprecationWarnings(bool ignoreDeprecationWarnings);
- /** Shows a deprecation warning */
- static void ShowDeprecationWarning_func(const char *method, const char *prop);
- static void ClearDeprecationWarning();
-
-#endif
-
- void InvalidateProxy();
-
- /**
- * Makes sure any internal data owned by this class is deep copied.
- */
- virtual void ProcessReplica();
-
- static bool m_ignore_deprecation_warnings;
-};
-
-#ifdef WITH_PYTHON
-PyObject *PyUnicode_From_STR_String(const STR_String& str);
-
-inline PyObject *_bge_proxy_from_ref_borrow(void *self_v)
-{
- PyObject *self_proxy = BGE_PROXY_FROM_REF(self_v);
- /* this is typically _very_ bad practice,
- * however we know the proxy is owned by 'self_v' */
- self_proxy->ob_refcnt--;
- return self_proxy;
-}
-
-#endif
-
-#endif /* __EXP_PYOBJECTPLUS_H__ */
diff --git a/source/gameengine/Expressions/EXP_Python.h b/source/gameengine/Expressions/EXP_Python.h
deleted file mode 100644
index f904151085e..00000000000
--- a/source/gameengine/Expressions/EXP_Python.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file EXP_Python.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_PYTHON_H__
-#define __EXP_PYTHON_H__
-
-//#define USE_DL_EXPORT
-
-/* python redefines, quiet the compiler */
-#ifdef _XOPEN_SOURCE
-#undef _XOPEN_SOURCE
-#endif
-
-#ifdef _POSIX_C_SOURCE
-#undef _POSIX_C_SOURCE
-#endif
-
-#ifdef WITH_PYTHON
-#include "Python.h"
-
-#define USE_MATHUTILS // Blender 2.5x api will use mathutils, for a while we might want to test without it
-
-#endif
-
-#ifdef __FreeBSD__
-#include <osreldate.h>
-#if __FreeBSD_version > 500039
-#undef isalnum
-#undef isalpha
-#undef iscntrl
-#undef isdigit
-#undef isgraph
-#undef islower
-#undef isprint
-#undef ispunct
-#undef isspace
-#undef isupper
-#undef isxdigit
-#undef tolower
-#undef toupper
-#endif
-#endif
-
-#ifdef __APPLE__
-#undef isalnum
-#undef isalpha
-#undef islower
-#undef isspace
-#undef isupper
-#undef tolower
-#undef toupper
-#endif
-
-#endif /* __EXP_PYTHON_H__ */
diff --git a/source/gameengine/Expressions/EXP_PythonCallBack.h b/source/gameengine/Expressions/EXP_PythonCallBack.h
deleted file mode 100644
index f0cbcac0c6f..00000000000
--- a/source/gameengine/Expressions/EXP_PythonCallBack.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Porteries Tristan.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file EXP_PythonCallBack.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_PYTHON_CALLBACK_H__
-#define __EXP_PYTHON_CALLBACK_H__
-
-#include "EXP_Python.h"
-
-/** Execute each functions with at least one argument
- * \param functionlist The python list which contains callbacks.
- * \param arglist The first item in the tuple to execute callbacks (can be NULL for no arguments).
- * \param minargcount The minimum of quantity of arguments possible.
- * \param maxargcount The maximum of quantity of arguments possible.
- */
-void RunPythonCallBackList(PyObject *functionlist, PyObject **arglist, unsigned int minargcount, unsigned int maxargcount);
-
-#endif // __EXP_PYTHON_CALLBACK_H__
diff --git a/source/gameengine/Expressions/EXP_StringValue.h b/source/gameengine/Expressions/EXP_StringValue.h
deleted file mode 100644
index ca59ebf1f82..00000000000
--- a/source/gameengine/Expressions/EXP_StringValue.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * StringValue.h: interface for the CStringValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_StringValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_STRINGVALUE_H__
-#define __EXP_STRINGVALUE_H__
-
-#include "EXP_Value.h"
-
-class CStringValue : public CPropValue
-{
-
-
- //PLUGIN_DECLARE_SERIAL(CStringValue,CValue)
-public:
- /// Construction / destruction
- CStringValue();
- CStringValue(const char *txt, const char *name, AllocationTYPE alloctype = CValue::HEAPVALUE);
-
- virtual ~CStringValue() {}
- /// CValue implementation
- virtual bool IsEqual(const STR_String & other);
- virtual const STR_String & GetText();
- virtual double GetNumber();
- virtual int GetValueType();
-
- virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- virtual void SetValue(CValue* newval) { m_strString = newval->GetText(); SetModified(true); }
- virtual CValue* GetReplica();
-#ifdef WITH_PYTHON
- virtual PyObject* ConvertValueToPython() {
- return PyUnicode_From_STR_String(m_strString);
- }
-#endif /* WITH_PYTHON */
-
-private:
- // data member
- STR_String m_strString;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CStringValue")
-#endif
-};
-
-#endif /* __EXP_STRINGVALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_Value.h b/source/gameengine/Expressions/EXP_Value.h
deleted file mode 100644
index 014fc59405f..00000000000
--- a/source/gameengine/Expressions/EXP_Value.h
+++ /dev/null
@@ -1,432 +0,0 @@
-/*
- * Value.h: interface for the CValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_Value.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_VALUE_H__
-#define __EXP_VALUE_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include <map> // array functionality for the propertylist
-#include "STR_String.h" // STR_String class
-
-using namespace std;
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-#ifndef GEN_NO_ASSERT
-#undef assert
-#define assert(exp) ((void)NULL)
-#endif
-
-
-#ifndef GEN_NO_TRACE
-#undef trace
-#define trace(exp) ((void)NULL)
-#endif
-
-#ifndef GEN_NO_DEBUG
-#undef debug
-#define debug(exp) ((void)NULL)
-#endif
-
-#ifndef GEN_NO_ASSERTD
-#undef assertd
-#define assertd(exp) ((void)NULL)
-#endif
-
-enum VALUE_OPERATOR {
-
- VALUE_MOD_OPERATOR, // %
- VALUE_ADD_OPERATOR, // +
- VALUE_SUB_OPERATOR, // -
- VALUE_MUL_OPERATOR, // *
- VALUE_DIV_OPERATOR, // /
- VALUE_NEG_OPERATOR, // -
- VALUE_POS_OPERATOR, // +
- VALUE_AND_OPERATOR, // &&
- VALUE_OR_OPERATOR, // ||
- VALUE_EQL_OPERATOR, // ==
- VALUE_NEQ_OPERATOR, // !=
- VALUE_GRE_OPERATOR, // >
- VALUE_LES_OPERATOR, // <
- VALUE_GEQ_OPERATOR, // >=
- VALUE_LEQ_OPERATOR, // <=
- VALUE_NOT_OPERATOR, // !
- VALUE_NO_OPERATOR // no operation at all
-};
-
-enum VALUE_DATA_TYPE {
- VALUE_NO_TYPE, // abstract baseclass
- VALUE_INT_TYPE,
- VALUE_FLOAT_TYPE,
- VALUE_STRING_TYPE,
- VALUE_BOOL_TYPE,
- VALUE_ERROR_TYPE,
- VALUE_EMPTY_TYPE,
- VALUE_LIST_TYPE,
- VALUE_VOID_TYPE,
- VALUE_VECTOR_TYPE,
- VALUE_MAX_TYPE //only here to provide number of types
-};
-
-
-
-#ifdef DEBUG
-//extern int gRefCountValue; // debugonly variable to check if all CValue Refences are Dereferenced at programexit
-#endif
-
-struct HashableInt
-{
- HashableInt(int id) : mData(id) { }
-
- unsigned long Hash() const { return 0;} ////}gHash(&mData, sizeof(int));}
-
- bool operator==(HashableInt rhs) { return mData == rhs.mData; }
-
- int mData;
-};
-
-
-//
-// Bitfield that stores the flags for each CValue derived class
-//
-struct ValueFlags {
- ValueFlags() :
- Modified(true),
- Selected(false),
- Affected(false),
- ReleaseRequested(false),
- Error(false),
- RefCountDisabled(false),
- HasProperties(false),
- HasName(false),
- Visible(true),
- CustomFlag1(false),
- CustomFlag2(false)
- {
- }
-
- unsigned short Modified : 1;
- unsigned short Selected : 1;
- unsigned short Affected : 1;
- unsigned short ReleaseRequested : 1;
- unsigned short Error : 1;
- unsigned short RefCountDisabled : 1;
- unsigned short HasProperties : 1;
- unsigned short HasName : 1;
- unsigned short Visible : 1;
- unsigned short CustomFlag1 : 1;
- unsigned short CustomFlag2 : 1;
-
-
-};
-
-/**
- * Base Class for all Actions performed on CValue's. Can be extended for undo/redo system in future.
- */
-class CAction
-{
-public:
- CAction() {
- };
- virtual ~CAction() {
- };
- virtual void Execute() const =0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CAction")
-#endif
-};
-
-
-#include "EXP_PyObjectPlus.h"
-#ifdef WITH_PYTHON
-#include "object.h"
-#endif
-
-/**
- * Baseclass CValue
- *
- * Together with CExpression, CValue and it's derived classes can be used to
- * parse expressions into a parsetree with error detecting/correcting capabilities
- * also expandable by a CFactory pluginsystem
- *
- * Base class for all editor functionality, flexible object type that allows
- * calculations and uses reference counting for memory management.
- *
- * Features:
- * - Reference Counting (AddRef() / Release())
- * - Calculations (Calc() / CalcFinal())
- * - Configuration (Configure())
- * - Serialization (EdSerialize() / EdIdSerialize() / EdPtrSerialize() and macro PLUGIN_DECLARE_SERIAL
- * - Property system (SetProperty() / GetProperty() / FindIdentifier())
- * - Replication (GetReplica())
- * - Flags (IsSelected() / IsModified() / SetSelected()...)
- *
- * - Some small editor-specific things added
- * - A helperclass CompressorArchive handles the serialization
- *
- */
-class CValue : public PyObjectPlus
-
-{
-Py_Header
-public:
- enum AllocationTYPE {
- STACKVALUE = 0,
- HEAPVALUE = 1
- };
-
- enum DrawTYPE {
- STARTFRAME = 0,
- ENDFRAME = 1,
- INTERFRAME = 2
- };
-
-
- // Construction / Destruction
- CValue();
-
-#ifdef WITH_PYTHON
- //static PyObject *PyMake(PyObject *, PyObject *);
- virtual PyObject *py_repr(void)
- {
- return PyUnicode_From_STR_String(GetText());
- }
-
- virtual PyObject *ConvertValueToPython() {
- return NULL;
- }
-
- virtual CValue *ConvertPythonToValue(PyObject *pyobj, const bool do_type_exception, const char *error_prefix);
-
- static PyObject *pyattr_get_name(void *self, const KX_PYATTRIBUTE_DEF *attrdef);
-
- virtual PyObject *ConvertKeysToPython( void );
-#endif /* WITH_PYTHON */
-
-
-
- // Expression Calculation
- virtual CValue* Calc(VALUE_OPERATOR op, CValue *val) = 0;
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) = 0;
- virtual void SetOwnerExpression(class CExpression* expr);
-
-
-
- void Execute(const CAction& a)
- {
- a.Execute();
- };
-
- /// Reference Counting
- int GetRefCount()
- {
- return m_refcount;
- }
-
- // Add a reference to this value
- CValue *AddRef()
- {
- // Increase global reference count, used to see at the end of the program
- // if all CValue-derived classes have been dereferenced to 0
- //debug(gRefCountValue++);
-#ifdef DEBUG
- //gRefCountValue++;
-#endif
- m_refcount++;
- return this;
- }
-
- // Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
- int Release()
- {
- // Decrease global reference count, used to see at the end of the program
- // if all CValue-derived classes have been dereferenced to 0
- //debug(gRefCountValue--);
-#ifdef DEBUG
- //gRefCountValue--;
-#endif
- // Decrease local reference count, if it reaches 0 the object should be freed
- if (--m_refcount > 0)
- {
- // Reference count normal, return new reference count
- return m_refcount;
- }
- else
- {
- // Reference count reached 0, delete ourselves and return 0
- // MT_assert(m_refcount==0, "Reference count reached sub-zero, object released too much");
-
- delete this;
- return 0;
- }
- }
-
-
- /// Property Management
- virtual void SetProperty(const STR_String& name,CValue* ioProperty); // Set property <ioProperty>, overwrites and releases a previous property with the same name if needed
- virtual void SetProperty(const char* name,CValue* ioProperty);
- virtual CValue* GetProperty(const char* inName); // Get pointer to a property with name <inName>, returns NULL if there is no property named <inName>
- virtual CValue* GetProperty(const STR_String & inName);
- const STR_String& GetPropertyText(const STR_String & inName); // Get text description of property with name <inName>, returns an empty string if there is no property named <inName>
- float GetPropertyNumber(const STR_String& inName,float defnumber);
- virtual bool RemoveProperty(const char *inName); // Remove the property named <inName>, returns true if the property was succesfully removed, false if property was not found or could not be removed
- virtual vector<STR_String> GetPropertyNames();
- virtual void ClearProperties(); // Clear all properties
-
- virtual void SetPropertiesModified(bool inModified); // Set all properties' modified flag to <inModified>
- virtual bool IsAnyPropertyModified(); // Check if any of the properties in this value have been modified
-
- virtual CValue* GetProperty(int inIndex); // Get property number <inIndex>
- virtual int GetPropertyCount(); // Get the amount of properties assiocated with this value
-
- virtual CValue* FindIdentifier(const STR_String& identifiername);
- /** Set the wireframe color of this value depending on the CSG
- * operator type <op>
- * \attention: not implemented */
- virtual void SetColorOperator(VALUE_OPERATOR op);
-
- virtual const STR_String & GetText() = 0;
- virtual double GetNumber() = 0;
- virtual int GetValueType(); // Get Prop value type
- double* ZeroVector() { return m_sZeroVec; }
- virtual double* GetVector3(bool bGetTransformedVec = false);
-
- virtual STR_String& GetName() = 0; // Retrieve the name of the value
- virtual void SetName(const char *name) = 0; // Set the name of the value
- /** Sets the value to this cvalue.
- * \attention this particular function should never be called. Why not abstract? */
- virtual void SetValue(CValue* newval);
- virtual CValue* GetReplica() =0;
- virtual void ProcessReplica();
- //virtual CValue* Copy() = 0;
-
- STR_String op2str(VALUE_OPERATOR op);
-
- // setting / getting flags
- inline void SetSelected(bool bSelected) { m_ValFlags.Selected = bSelected; }
- virtual void SetModified(bool bModified) { m_ValFlags.Modified = bModified; }
- virtual void SetAffected(bool bAffected=true) { m_ValFlags.Affected = bAffected; }
- inline void SetReleaseRequested(bool bReleaseRequested) { m_ValFlags.ReleaseRequested=bReleaseRequested; }
- inline void SetError(bool err) { m_ValFlags.Error=err; }
- inline void SetVisible (bool vis) { m_ValFlags.Visible=vis; }
-
- virtual bool IsModified() { return m_ValFlags.Modified; }
- inline bool IsError() { return m_ValFlags.Error; }
- virtual bool IsAffected() { return m_ValFlags.Affected || m_ValFlags.Modified; }
- virtual bool IsSelected() { return m_ValFlags.Selected; }
- inline bool IsReleaseRequested() { return m_ValFlags.ReleaseRequested; }
- virtual bool IsVisible() { return m_ValFlags.Visible;}
- virtual void SetCustomFlag1(bool bCustomFlag) { m_ValFlags.CustomFlag1 = bCustomFlag;}
- virtual bool IsCustomFlag1() { return m_ValFlags.CustomFlag1;}
-
- virtual void SetCustomFlag2(bool bCustomFlag) { m_ValFlags.CustomFlag2 = bCustomFlag;}
- virtual bool IsCustomFlag2() { return m_ValFlags.CustomFlag2;}
-
-protected:
- virtual void DisableRefCount(); // Disable reference counting for this value
- //virtual void AddDataToReplica(CValue* replica);
- virtual ~CValue();
-private:
- // Member variables
- std::map<STR_String,CValue*>* m_pNamedPropertyArray; // Properties for user/game etc
- ValueFlags m_ValFlags; // Frequently used flags in a bitfield (low memoryusage)
- int m_refcount; // Reference Counter
- static double m_sZeroVec[3];
-
-};
-
-
-
-//
-// Declare a CValue or CExpression or CWhatever to be serialized by the editor.
-//
-// This macro introduces the EdSerialize() function (which must be implemented by
-// the client) and the EdIdSerialize() function (which is implemented by this macro).
-//
-// The generated Copy() function returns a pointer to <root_base_class_name> type
-// of object. So, for *any* CValue-derived object this should be set to CValue,
-// for *any* CExpression-derived object this should be set to CExpression.
-//
-#define PLUGIN_DECLARE_SERIAL(class_name, root_base_class_name) \
-public: \
- virtual root_base_class_name *Copy() { \
- return new class_name; \
- } \
- virtual bool EdSerialize(CompressorArchive& arch, \
- class CFactoryManager* facmgr, \
- bool bIsStoring); \
- virtual bool EdIdSerialize(CompressorArchive& arch, \
- class CFactoryManager* facmgr, \
- bool bIsStoring) \
- { \
- if (bIsStoring) \
- arch.StoreString(#class_name); \
- return false; \
- } \
-
-
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-////////////////////////////////////////////////////////////////////////////////
-
-// CPropValue is a CValue derived class, that implements the identification (String name)
-// SetName() / GetName(),
-// normal classes should derive from CPropValue, real lightweight classes straight from CValue
-
-
-class CPropValue : public CValue
-{
-public:
- CPropValue() :
- CValue(),
- m_strNewName()
-
- {
- }
-
- virtual ~CPropValue()
- {
- }
-
- virtual void SetName(const char *name) {
- m_strNewName = name;
- }
-
- virtual STR_String& GetName() {
- //STR_String namefromprop = GetPropertyText("Name");
- //if (namefromprop.Length() > 0)
- // return namefromprop;
- return m_strNewName;
- } // name of Value
-
-protected:
- STR_String m_strNewName; // Identification
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CPropValue")
-#endif
-};
-
-#endif /* __EXP_VALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_VectorValue.h b/source/gameengine/Expressions/EXP_VectorValue.h
deleted file mode 100644
index d87d5097156..00000000000
--- a/source/gameengine/Expressions/EXP_VectorValue.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/*
- * VectorValue.h: interface for the CVectorValue class.
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-/** \file EXP_VectorValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_VECTORVALUE_H__
-#define __EXP_VECTORVALUE_H__
-
-#include "EXP_Value.h"
-
-#define KX_X 0
-#define KX_Y 1
-#define KX_Z 2
-
-
-class CVectorValue : public CPropValue
-{
- //PLUGIN_DECLARE_SERIAL(CVectorValue,CValue)
-
-public:
- //void Transform(rcMatrix4x4 mat);
- virtual void SetValue(CValue* newval);
- void SetVector(double newvec[]);
- void Configure(CValue* menuvalue);
- virtual double* GetVector3(bool bGetTransformedVec=false);
- virtual double GetNumber();
- virtual int GetValueType();
-
- CValue* Calc(VALUE_OPERATOR op, CValue *val) {
- return val->CalcFinal(VALUE_VECTOR_TYPE, op, this);
- }
-
- CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
-
-
- CVectorValue(double vec[3], const char *name,AllocationTYPE alloctype=CValue::HEAPVALUE);
- CVectorValue() {};
-
- CVectorValue(double vec[3], AllocationTYPE alloctype=CValue::HEAPVALUE);
- CVectorValue(float x,float y,float z, AllocationTYPE alloctype = CValue::HEAPVALUE);
- virtual ~CVectorValue();
- //virtual bool ExportT3D(File *txtfile,bool bNoName=false);
- void AddConfigurationData(CValue* menuvalue);
-
-
-
- virtual CValue* GetReplica();
- virtual const STR_String & GetText();
-
-#if 0
- void SnapPoint(float num,int snap)
- {
- if (num > 0) num += ((float)snap / 2);
- else num -= ((float)snap / 2);
- num = (long)(((long)(num / snap)) * snap);
- };
-
- void SnapPosition(const double snapvec[])
- {
-
- if (snapvec[KX_X] >= 1)
- SnapPoint(m_vec[KX_X],snapvec[KX_X]);
- if (snapvec[KX_Y] >= 1)
- SnapPoint(m_vec[KX_Y],snapvec[KX_Y]);
- if (snapvec[KX_Z] >= 1)
- SnapPoint(m_vec[KX_Z],snapvec[KX_Z]);
-
- }
-#endif
-
-protected:
- double m_vec[3];
- double m_transformedvec[3];
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CVectorValue")
-#endif
-};
-
-#endif /* __EXP_VECTORVALUE_H__ */
diff --git a/source/gameengine/Expressions/EXP_VoidValue.h b/source/gameengine/Expressions/EXP_VoidValue.h
deleted file mode 100644
index 8b2c29488d7..00000000000
--- a/source/gameengine/Expressions/EXP_VoidValue.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * VoidValue.h: interface for the CVoidValue class.
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file EXP_VoidValue.h
- * \ingroup expressions
- */
-
-#ifndef __EXP_VOIDVALUE_H__
-#define __EXP_VOIDVALUE_H__
-
-#include "EXP_Value.h"
-
-//
-// Void value, used to transport *any* type of data
-//
-class CVoidValue : public CPropValue
-{
- //PLUGIN_DECLARE_SERIAL (CVoidValue,CValue)
-
-public:
- /// Construction/destruction
- CVoidValue() : m_bDeleteOnDestruct(false), m_pAnything(NULL) { }
- CVoidValue(void *voidptr, bool bDeleteOnDestruct, AllocationTYPE alloctype) :
- m_bDeleteOnDestruct(bDeleteOnDestruct),
- m_pAnything(voidptr)
- {
- if (alloctype == STACKVALUE) {
- CValue::DisableRefCount();
- }
- }
- virtual ~CVoidValue(); /* Destruct void value, delete memory if we're owning it */
-
- /// Value -> String or number
- virtual const STR_String & GetText(); /* Get string description of void value (unimplemented) */
- virtual double GetNumber() { return -1; }
- virtual int GetValueType() { return VALUE_VOID_TYPE; }
-
- /// Value calculation
- virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue* val);
-
- /// Value replication
- virtual CValue* GetReplica();
-
- /// Data members
- bool m_bDeleteOnDestruct;
- void* m_pAnything;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CVoidValue")
-#endif
-};
-
-#endif /* __EXP_VOIDVALUE_H__ */
diff --git a/source/gameengine/Expressions/intern/BoolValue.cpp b/source/gameengine/Expressions/intern/BoolValue.cpp
deleted file mode 100644
index 1523a9212ba..00000000000
--- a/source/gameengine/Expressions/intern/BoolValue.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/** \file gameengine/Expressions/BoolValue.cpp
- * \ingroup expressions
- */
-
-// BoolValue.cpp: implementation of the CBoolValue class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_BoolValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_VoidValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-const STR_String CBoolValue::sTrueString = "TRUE";
-const STR_String CBoolValue::sFalseString = "FALSE";
-
-CBoolValue::CBoolValue()
-/*
- * pre: false
- * effect: constructs a new CBoolValue
- */
-{
- trace("Bool constructor error");
-}
-
-
-
-CBoolValue::CBoolValue(bool inBool)
-: m_bool(inBool)
-{
-} // Constructs a new CBoolValue containing <inBool>
-
-
-
-CBoolValue::CBoolValue(bool innie,const char *name,AllocationTYPE alloctype)
-{
- m_bool = innie;
- SetName(name);
-
- if (alloctype == CValue::STACKVALUE)
- CValue::DisableRefCount();
-}
-
-
-
-void CBoolValue::SetValue(CValue* newval)
-{
- m_bool = (newval->GetNumber() != 0);
- SetModified(true);
-}
-
-
-
-CValue* CBoolValue::Calc(VALUE_OPERATOR op, CValue *val)
-/*
-pre:
-ret: a new object containing the result of applying operator op to this
-object and val
-*/
-{
- switch (op)
- {
- case VALUE_POS_OPERATOR:
- case VALUE_NEG_OPERATOR:
- {
- return new CErrorValue (op2str(op) + GetText());
- break;
- }
- case VALUE_NOT_OPERATOR:
- {
- return new CBoolValue (!m_bool);
- break;
- }
- default:
- {
- return val->CalcFinal(VALUE_BOOL_TYPE, op, this);
- break;
- }
- }
-}
-
-
-
-CValue* CBoolValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-/*
-pre: the type of val is dtype
-ret: a new object containing the result of applying operator op to val and
-this object
-*/
-{
- CValue *ret;
-
- switch (dtype) {
- case VALUE_EMPTY_TYPE:
- case VALUE_BOOL_TYPE:
- {
- switch (op) {
- case VALUE_AND_OPERATOR:
- {
- ret = new CBoolValue (((CBoolValue *) val)->GetBool() && m_bool);
- break;
- }
- case VALUE_OR_OPERATOR:
- {
- ret = new CBoolValue (((CBoolValue *) val)->GetBool() || m_bool);
- break;
- }
- case VALUE_EQL_OPERATOR:
- {
- ret = new CBoolValue (((CBoolValue *) val)->GetBool() == m_bool);
- break;
- }
- case VALUE_NEQ_OPERATOR:
- {
- ret = new CBoolValue (((CBoolValue *) val)->GetBool() != m_bool);
- break;
- }
- case VALUE_NOT_OPERATOR:
- {
- return new CBoolValue (!m_bool);
- break;
- }
- default:
- {
- ret = new CErrorValue(val->GetText() + op2str(op) +
- "[operator not allowed on booleans]");
- break;
- }
- }
- break;
- }
- case VALUE_STRING_TYPE:
- {
- switch (op) {
- case VALUE_ADD_OPERATOR:
- {
- ret = new CStringValue(val->GetText() + GetText(),"");
- break;
- }
- default:
- {
- ret = new CErrorValue(val->GetText() + op2str(op) + "[Only + allowed on boolean and string]");
- break;
- }
- }
- break;
- }
- default:
- ret = new CErrorValue("[type mismatch]" + op2str(op) + GetText());
- }
-
- return ret;
-}
-
-
-
-bool CBoolValue::GetBool()
-/*
-pre:
-ret: the bool stored in the object
-*/
-{
- return m_bool;
-}
-
-
-
-double CBoolValue::GetNumber()
-{
- return (double)m_bool;
-}
-
-
-
-int CBoolValue::GetValueType()
-{
- return VALUE_BOOL_TYPE;
-}
-
-
-
-const STR_String& CBoolValue::GetText()
-{
- return m_bool ? sTrueString : sFalseString;
-}
-
-
-
-CValue* CBoolValue::GetReplica()
-{
- CBoolValue* replica = new CBoolValue(*this);
- replica->ProcessReplica();
-
- return replica;
-}
-
-#ifdef WITH_PYTHON
-PyObject *CBoolValue::ConvertValueToPython()
-{
- return PyBool_FromLong(m_bool != 0);
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Expressions/intern/ConstExpr.cpp b/source/gameengine/Expressions/intern/ConstExpr.cpp
deleted file mode 100644
index 597427ecfe5..00000000000
--- a/source/gameengine/Expressions/intern/ConstExpr.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/** \file gameengine/Expressions/ConstExpr.cpp
- * \ingroup expressions
- */
-// ConstExpr.cpp: implementation of the CConstExpr class.
-
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_Value.h" // for precompiled header
-#include "EXP_ConstExpr.h"
-#include "EXP_VectorValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CConstExpr::CConstExpr()
-{
-}
-
-
-
-CConstExpr::CConstExpr(CValue* constval)
-/*
-pre:
-effect: constructs a CConstExpr cointing the value constval
-*/
-{
- m_value = constval;
-// m_bModified=true;
-}
-
-
-
-CConstExpr::~CConstExpr()
-/*
-pre:
-effect: deletes the object
-*/
-{
- if (m_value)
- m_value->Release();
-}
-
-
-
-unsigned char CConstExpr::GetExpressionID()
-{
- return CCONSTEXPRESSIONID;
-}
-
-
-
-CValue* CConstExpr::Calculate()
-/*
-pre:
-ret: a new object containing the value of the stored CValue
-*/
-{
- return m_value->AddRef();
-}
-
-
-
-void CConstExpr::ClearModified()
-{
- if (m_value)
- {
- m_value->SetModified(false);
- m_value->SetAffected(false);
- }
-}
-
-
-
-double CConstExpr::GetNumber()
-{
- return -1;
-}
-
-
-
-bool CConstExpr::NeedsRecalculated()
-{
- return m_value->IsAffected(); // IsAffected is m_bModified OR m_bAffected !!!
-}
-
-
-
-CExpression* CConstExpr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks)
-{
-// parent checks if child is still useful.
-// When for example it's value it's deleted flag set
-// then release Value, and return NULL in case of constexpression
-// else return this...
-
- assertd(m_value);
- if (m_value->IsReleaseRequested())
- {
- AddRef(); //numchanges++;
- return Release();
- }
- else
- return this;
-}
-
-
-
-void CConstExpr::BroadcastOperators(VALUE_OPERATOR op)
-{
- assertd(m_value);
- m_value->SetColorOperator(op);
-}
-
-
-
-bool CConstExpr::MergeExpression(CExpression *otherexpr)
-{
- assertd(false);
- return false;
-}
diff --git a/source/gameengine/Expressions/intern/EmptyValue.cpp b/source/gameengine/Expressions/intern/EmptyValue.cpp
deleted file mode 100644
index 9227626777d..00000000000
--- a/source/gameengine/Expressions/intern/EmptyValue.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/** \file gameengine/Expressions/EmptyValue.cpp
- * \ingroup expressions
- */
-
-// EmptyValue.cpp: implementation of the CEmptyValue class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_EmptyValue.h"
-#include "EXP_IntValue.h"
-#include "EXP_FloatValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_ListValue.h"
-#include "EXP_VoidValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CEmptyValue::CEmptyValue()
-/*
- * pre:
- * effect: constructs a new CEmptyValue
- */
-{
- SetModified(false);
-}
-
-
-
-CEmptyValue::~CEmptyValue()
-/*
- * pre:
- * effect: deletes the object
- */
-{
-
-}
-
-
-
-CValue *CEmptyValue::Calc(VALUE_OPERATOR op, CValue *val)
-/*
- * pre:
- * ret: a new object containing the result of applying operator op to this
- * object and val
- */
-{
- return val->CalcFinal(VALUE_EMPTY_TYPE, op, this);
-
-}
-
-
-
-CValue * CEmptyValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-/*
- * pre: the type of val is dtype
- * ret: a new object containing the result of applying operator op to val and
- * this object
- */
-{
- return val->AddRef();
-}
-
-
-
-double CEmptyValue::GetNumber()
-{
- return 0;
-}
-
-
-
-int CEmptyValue::GetValueType()
-{
- return VALUE_EMPTY_TYPE;
-}
-
-
-
-CListValue* CEmptyValue::GetPolySoup()
-{
- CListValue* soup = new CListValue();
- //don't add any poly, while it's an empty value
- return soup;
-}
-
-
-
-bool CEmptyValue::IsInside(CValue* testpoint,bool bBorderInclude)
-{
- // empty space is solid, so always inside
- return true;
-}
-
-
-
-double* CEmptyValue::GetVector3(bool bGetTransformedVec)
-{
- assertd(false); // don't get vector from me
- return ZeroVector();
-}
-
-
-
-static STR_String emptyString = STR_String("");
-
-
-const STR_String & CEmptyValue::GetText()
-{
- return emptyString;
-}
-
-
-
-CValue* CEmptyValue::GetReplica()
-{
- CEmptyValue* replica = new CEmptyValue(*this);
- replica->ProcessReplica();
- return replica;
-}
-
diff --git a/source/gameengine/Expressions/intern/ErrorValue.cpp b/source/gameengine/Expressions/intern/ErrorValue.cpp
deleted file mode 100644
index c03ceb88073..00000000000
--- a/source/gameengine/Expressions/intern/ErrorValue.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/** \file gameengine/Expressions/ErrorValue.cpp
- * \ingroup expressions
- */
-// ErrorValue.cpp: implementation of the CErrorValue class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_ErrorValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CErrorValue::CErrorValue()
-/*
-pre:
-effect: constructs a new CErrorValue containing errormessage "Error"
-*/
-{
- m_strErrorText = "Error";
- SetError(true);
-}
-
-
-
-CErrorValue::CErrorValue(const char *errmsg)
-/*
-pre:
-effect: constructs a new CErrorValue containing errormessage errmsg
-*/
-{
- m_strErrorText = "[";
- m_strErrorText += errmsg;
- m_strErrorText += "]";
- SetError(true);
-}
-
-
-
-CErrorValue::~CErrorValue()
-/*
-pre:
-effect: deletes the object
-*/
-{
-
-}
-
-
-
-CValue* CErrorValue::Calc(VALUE_OPERATOR op, CValue *val)
-/*
-pre:
-ret: a new object containing the result of applying operator op to this
- object and val
-*/
-{
- CValue* errorval;
-
- switch (op)
- {
- case VALUE_POS_OPERATOR:
- case VALUE_NEG_OPERATOR:
- case VALUE_NOT_OPERATOR:
- {
- errorval = new CErrorValue (op2str(op) + GetText());
- break;
- }
- default:
- {
- errorval = val->CalcFinal(VALUE_ERROR_TYPE, op, this);
- break;
- }
- }
-
- return errorval;
-}
-
-
-
-CValue* CErrorValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-/*
-pre: the type of val is dtype
-ret: a new object containing the result of applying operator op to val and
- this object
-*/
-{
- return new CErrorValue (val->GetText() + op2str(op) + GetText());
-}
-
-
-
-double CErrorValue::GetNumber()
-{
- return -1;
-}
-
-
-
-int CErrorValue::GetValueType()
-{
- return VALUE_ERROR_TYPE;
-}
-
-
-
-const STR_String & CErrorValue::GetText()
-{
- return m_strErrorText;
-}
-
-
-
-CValue* CErrorValue::GetReplica()
-{
- // who would want a copy of an error ?
- trace ("Error: ErrorValue::GetReplica() not implemented yet");
- assertd(false);
-
- return NULL;
-}
diff --git a/source/gameengine/Expressions/intern/Expression.cpp b/source/gameengine/Expressions/intern/Expression.cpp
deleted file mode 100644
index 6a98a15aa12..00000000000
--- a/source/gameengine/Expressions/intern/Expression.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/** \file gameengine/Expressions/Expression.cpp
- * \ingroup expressions
- */
-// Expression.cpp: implementation of the CExpression class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_Expression.h"
-#include "EXP_ErrorValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-#ifdef DEBUG
-//int gRefCountExpr;
-#endif
-CExpression::CExpression()// : m_cached_calculate(NULL)
-{
- m_refcount = 1;
-#ifdef DEBUG
- //gRefCountExpr++;
-#endif
-}
-
-CExpression::~CExpression()
-{
- assert (m_refcount == 0);
-}
-
-
-
-// destuctor for CBrokenLinkInfo
-CBrokenLinkInfo::~CBrokenLinkInfo()
-{
- if (m_pExpr && !m_bRestored)
- m_pExpr->Release();
-}
-
-
-void CBrokenLinkInfo::RestoreLink()
-{
-
-
- assertd(m_pExpr);
-
- if (m_pExpr)
- {
- if (!m_bRestored) {
- m_bRestored=true;
-
- }
- if (*m_pmemExpr)
- {
- (*m_pmemExpr)->Release();
- }
- *m_pmemExpr = m_pExpr;
-
-// m_pExpr=NULL;
- }
-}
-
-void CBrokenLinkInfo::BreakLink()
-{
- m_bRestored=false;
- m_pExpr->AddRef();
-}
-
diff --git a/source/gameengine/Expressions/intern/FloatValue.cpp b/source/gameengine/Expressions/intern/FloatValue.cpp
deleted file mode 100644
index 0f86a429d81..00000000000
--- a/source/gameengine/Expressions/intern/FloatValue.cpp
+++ /dev/null
@@ -1,329 +0,0 @@
-/** \file gameengine/Expressions/FloatValue.cpp
- * \ingroup expressions
- */
-// FloatValue.cpp: implementation of the CFloatValue class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_FloatValue.h"
-#include "EXP_IntValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_BoolValue.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_VoidValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CFloatValue::CFloatValue()
-/*
-pre: false
-effect: constructs a new CFloatValue
-*/
-{
- m_pstrRep=NULL;
-}
-
-
-
-CFloatValue::CFloatValue(float fl)
-/*
-pre:
-effect: constructs a new CFloatValue containing value fl
-*/
-{
- m_float = fl;
- m_pstrRep=NULL;
-}
-
-
-
-CFloatValue::CFloatValue(float fl,const char *name,AllocationTYPE alloctype)
-/*
-pre:
-effect: constructs a new CFloatValue containing value fl
-*/
-{
-
- m_float = fl;
- SetName(name);
- if (alloctype==CValue::STACKVALUE)
- {
- CValue::DisableRefCount();
-
- }
- m_pstrRep=NULL;
-}
-
-
-
-CFloatValue::~CFloatValue()
-/*
-pre:
-effect: deletes the object
-*/
-{
- if (m_pstrRep)
- delete m_pstrRep;
-}
-
-
-
-CValue* CFloatValue::Calc(VALUE_OPERATOR op, CValue *val)
-/*
-pre:
-ret: a new object containing the result of applying operator op to this
- object and val
-*/
-{
- //return val->CalcFloat(op, this);
- switch (op)
- {
- case VALUE_POS_OPERATOR:
- return new CFloatValue (m_float);
- break;
- case VALUE_NEG_OPERATOR:
- return new CFloatValue (-m_float);
- break;
- case VALUE_NOT_OPERATOR:
- return new CBoolValue (m_float == 0.f);
- break;
- case VALUE_AND_OPERATOR:
- case VALUE_OR_OPERATOR:
- return new CErrorValue(val->GetText() + op2str(op) + "only allowed on booleans");
- break;
- default:
- return val->CalcFinal(VALUE_FLOAT_TYPE, op, this);
- break;
- }
-}
-
-
-
-CValue* CFloatValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-/*
-pre: the type of val is dtype
-ret: a new object containing the result of applying operator op to val and
- this object
-*/
-{
- CValue *ret;
-
- switch (dtype) {
- case VALUE_INT_TYPE:
- {
- switch (op) {
- case VALUE_MOD_OPERATOR:
- ret = new CFloatValue(fmod(((CIntValue *) val)->GetInt(), m_float));
- break;
- case VALUE_ADD_OPERATOR:
- ret = new CFloatValue(((CIntValue *) val)->GetInt() + m_float);
- break;
- case VALUE_SUB_OPERATOR:
- ret = new CFloatValue(((CIntValue *) val)->GetInt() - m_float);
- break;
- case VALUE_MUL_OPERATOR:
- ret = new CFloatValue(((CIntValue *) val)->GetInt() * m_float);
- break;
- case VALUE_DIV_OPERATOR:
- if (m_float == 0)
- ret = new CErrorValue("Division by zero");
- else
- ret = new CFloatValue (((CIntValue *) val)->GetInt() / m_float);
- break;
- case VALUE_EQL_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() == m_float);
- break;
- case VALUE_NEQ_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() != m_float);
- break;
- case VALUE_GRE_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() > m_float);
- break;
- case VALUE_LES_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() < m_float);
- break;
- case VALUE_GEQ_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() >= m_float);
- break;
- case VALUE_LEQ_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() <= m_float);
- break;
- case VALUE_NOT_OPERATOR:
- ret = new CBoolValue(m_float == 0);
- break;
- default:
- ret = new CErrorValue("illegal operator. please send a bug report.");
- break;
- }
- break;
- }
- case VALUE_EMPTY_TYPE:
- case VALUE_FLOAT_TYPE:
- {
- switch (op) {
- case VALUE_MOD_OPERATOR:
- ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_float));
- break;
- case VALUE_ADD_OPERATOR:
- ret = new CFloatValue(((CFloatValue *) val)->GetFloat() + m_float);
- break;
- case VALUE_SUB_OPERATOR:
- ret = new CFloatValue(((CFloatValue *) val)->GetFloat() - m_float);
- break;
- case VALUE_MUL_OPERATOR:
- ret = new CFloatValue(((CFloatValue *) val)->GetFloat() * m_float);
- break;
- case VALUE_DIV_OPERATOR:
- if (m_float == 0)
- ret = new CErrorValue("Division by zero");
- else
- ret = new CFloatValue (((CFloatValue *) val)->GetFloat() / m_float);
- break;
- case VALUE_EQL_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() == m_float);
- break;
- case VALUE_NEQ_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() != m_float);
- break;
- case VALUE_GRE_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() > m_float);
- break;
- case VALUE_LES_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() < m_float);
- break;
- case VALUE_GEQ_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() >= m_float);
- break;
- case VALUE_LEQ_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() <= m_float);
- break;
- case VALUE_NEG_OPERATOR:
- ret = new CFloatValue (-m_float);
- break;
- case VALUE_POS_OPERATOR:
- ret = new CFloatValue (m_float);
- break;
- case VALUE_NOT_OPERATOR:
- ret = new CBoolValue(m_float == 0);
- break;
- default:
- ret = new CErrorValue("illegal operator. please send a bug report.");
- break;
- }
- break;
- }
- case VALUE_STRING_TYPE:
- {
- switch (op) {
- case VALUE_ADD_OPERATOR:
- ret = new CStringValue(val->GetText() + GetText(),"");
- break;
- case VALUE_EQL_OPERATOR:
- case VALUE_NEQ_OPERATOR:
- case VALUE_GRE_OPERATOR:
- case VALUE_LES_OPERATOR:
- case VALUE_GEQ_OPERATOR:
- case VALUE_LEQ_OPERATOR:
- ret = new CErrorValue("[Cannot compare string with float]" + op2str(op) + GetText());
- break;
- default:
- ret = new CErrorValue("[operator not allowed on strings]" + op2str(op) + GetText());
- break;
- }
- break;
- }
- case VALUE_BOOL_TYPE:
- ret = new CErrorValue("[operator not valid on boolean and float]" + op2str(op) + GetText());
- break;
- case VALUE_ERROR_TYPE:
- ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
- break;
- default:
- ret = new CErrorValue("illegal type. contact your dealer (if any)");
- break;
- }
- return ret;
-}
-
-
-
-void CFloatValue::SetFloat(float fl)
-{
- m_float = fl;
- SetModified(true);
-}
-
-
-
-float CFloatValue::GetFloat()
-/*
-pre:
-ret: the float stored in the object
-*/
-{
- return m_float;
-}
-
-
-
-double CFloatValue::GetNumber()
-{
- return m_float;
-}
-
-
-
-int CFloatValue::GetValueType()
-{
- return VALUE_FLOAT_TYPE;
-}
-
-
-
-void CFloatValue::SetValue(CValue* newval)
-{
- m_float = (float)newval->GetNumber();
- SetModified(true);
-}
-
-
-
-const STR_String & CFloatValue::GetText()
-{
- if (!m_pstrRep)
- m_pstrRep = new STR_String();
-
- m_pstrRep->Format("%f",m_float);
- return *m_pstrRep;
-}
-
-
-
-CValue* CFloatValue::GetReplica()
-{
- CFloatValue* replica = new CFloatValue(*this);
- replica->m_pstrRep = NULL; /* should be in CFloatValue::ProcessReplica() but its not defined, no matter */
- replica->ProcessReplica();
-
- return replica;
-}
-
-
-#ifdef WITH_PYTHON
-PyObject *CFloatValue::ConvertValueToPython()
-{
- return PyFloat_FromDouble(m_float);
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Expressions/intern/HashedPtr.cpp b/source/gameengine/Expressions/intern/HashedPtr.cpp
deleted file mode 100644
index 11d9482f993..00000000000
--- a/source/gameengine/Expressions/intern/HashedPtr.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Expressions/KX_HashedPtr.cpp
- * \ingroup expressions
- */
-
-
-#include "EXP_HashedPtr.h"
-
-
-CHashedPtr::CHashedPtr(void* val) : m_valptr(val)
-{
-}
-
-
-unsigned int CHashedPtr::hash() const
-{
-#if defined(_WIN64)
- unsigned __int64 key = (unsigned __int64)m_valptr;
-#else
- unsigned long key = (unsigned long)m_valptr;
-#endif
-
- key += ~(key << 16);
- key ^= (key >> 5);
- key += (key << 3);
- key ^= (key >> 13);
- key += ~(key << 9);
- key ^= (key >> 17);
-
- return (unsigned int)(key & 0xffffffff);
-}
diff --git a/source/gameengine/Expressions/intern/IdentifierExpr.cpp b/source/gameengine/Expressions/intern/IdentifierExpr.cpp
deleted file mode 100644
index 8fbbf41cd63..00000000000
--- a/source/gameengine/Expressions/intern/IdentifierExpr.cpp
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Expressions/IdentifierExpr.cpp
- * \ingroup expressions
- */
-
-
-#include "EXP_IdentifierExpr.h"
-
-CIdentifierExpr::CIdentifierExpr(const STR_String& identifier,CValue* id_context)
-:m_identifier(identifier)
-{
- if (id_context)
- m_idContext = id_context->AddRef();
- else
- m_idContext=NULL;
-}
-
-
-CIdentifierExpr::~CIdentifierExpr()
-{
- if (m_idContext)
- m_idContext->Release();
-}
-
-
-
-CValue* CIdentifierExpr::Calculate()
-{
- CValue* result = NULL;
- if (m_idContext)
- result = m_idContext->FindIdentifier(m_identifier);
-
- return result;
-}
-
-
-
-bool CIdentifierExpr::MergeExpression(CExpression* otherexpr)
-{
- return false;
-}
-
-
-
-unsigned char CIdentifierExpr::GetExpressionID()
-{
- return CIDENTIFIEREXPRESSIONID;
-}
-
-
-
-bool CIdentifierExpr::NeedsRecalculated()
-{
- return true;
-}
-
-
-
-CExpression* CIdentifierExpr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks)
-{
- assertd(false); // not implemented yet
- return NULL;
-}
-
-
-
-void CIdentifierExpr::ClearModified()
-{
- assertd(false); // not implemented yet
-}
-
-
-
-void CIdentifierExpr::BroadcastOperators(VALUE_OPERATOR op)
-{
- assertd(false); // not implemented yet
-}
diff --git a/source/gameengine/Expressions/intern/IfExpr.cpp b/source/gameengine/Expressions/intern/IfExpr.cpp
deleted file mode 100644
index b4e2fe7315b..00000000000
--- a/source/gameengine/Expressions/intern/IfExpr.cpp
+++ /dev/null
@@ -1,144 +0,0 @@
-/** \file gameengine/Expressions/IfExpr.cpp
- * \ingroup expressions
- */
-// IfExpr.cpp: implementation of the CIfExpr class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_IfExpr.h"
-#include "EXP_EmptyValue.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_BoolValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-
-CIfExpr::CIfExpr()
-{
-}
-
-
-
-/*
- * pre:
- * effect: constructs an CifExpr-object corresponding to IF(guard, e1, e2)
- */
-CIfExpr::CIfExpr(CExpression *guard, CExpression *e1, CExpression *e2)
-{
- m_guard = guard;
- m_e1 = e1;
- m_e2 = e2;
-}
-
-
-
-/*
- * pre:
- * effect: dereferences the object
- */
-CIfExpr::~CIfExpr()
-{
- if (m_guard)
- m_guard->Release();
-
- if (m_e1)
- m_e1->Release();
-
- if (m_e2)
- m_e2->Release();
-}
-
-
-
-/**
- * pre:
- * ret: a new object containing the value of m_e1 if m_guard is a boolean true
- * a new object containing the value of m_e2 if m_guard is a boolean false
- * an new errorvalue if m_guard is not a boolean
- */
-CValue* CIfExpr::Calculate()
-{
- CValue *guardval;
- guardval = m_guard->Calculate();
- const STR_String& text = guardval->GetText();
- guardval->Release();
-
- if (&text == &CBoolValue::sTrueString)
- {
- return m_e1->Calculate();
- }
- else if (&text == &CBoolValue::sFalseString)
- {
- return m_e2->Calculate();
- }
- else
- {
- return new CErrorValue("Guard should be of boolean type");
- }
-}
-
-
-
-bool CIfExpr::MergeExpression(CExpression *otherexpr)
-{
- assertd(false);
- return false;
-}
-
-
-
-bool CIfExpr::IsInside(float x,float y,float z,bool bBorderInclude)
-{
- assertd(false);
- return false;
-}
-
-
-
-bool CIfExpr::NeedsRecalculated()
-{
- return (m_guard->NeedsRecalculated() ||
- m_e1->NeedsRecalculated() ||
- m_e2->NeedsRecalculated());
-}
-
-
-
-CExpression* CIfExpr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks)
-{
- assertd(false);
- return NULL;
-}
-
-
-
-void CIfExpr::ClearModified()
-{
- assertd(false);
-}
-
-
-
-void CIfExpr::BroadcastOperators(VALUE_OPERATOR op)
-{
- assertd(false);
-}
-
-
-
-unsigned char CIfExpr::GetExpressionID()
-{
- return CIFEXPRESSIONID;
-}
diff --git a/source/gameengine/Expressions/intern/InputParser.cpp b/source/gameengine/Expressions/intern/InputParser.cpp
deleted file mode 100644
index 583d8da63cb..00000000000
--- a/source/gameengine/Expressions/intern/InputParser.cpp
+++ /dev/null
@@ -1,669 +0,0 @@
-/** \file gameengine/Expressions/InputParser.cpp
- * \ingroup expressions
- */
-// Parser.cpp: implementation of the CParser class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include <stdlib.h>
-
-#include "MT_assert.h"
-
-#include "EXP_Value.h"
-#include "EXP_InputParser.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_IntValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_FloatValue.h"
-#include "EXP_BoolValue.h"
-#include "EXP_EmptyValue.h"
-#include "EXP_ConstExpr.h"
-#include "EXP_Operator2Expr.h"
-#include "EXP_Operator1Expr.h"
-#include "EXP_IdentifierExpr.h"
-
-// this is disable at the moment, I expected a memleak from it, but the error-cleanup was the reason
-// well, looks we don't need it anyway, until maybe the Curved Surfaces are integrated into CSG
-// cool things like (IF(LOD==1,CCurvedValue,IF(LOD==2,CCurvedValue2)) etc...
-#include "EXP_IfExpr.h"
-
-#if defined(WIN32) || defined(WIN64)
-#define strcasecmp _stricmp
-
-#ifndef strtoll
-#define strtoll _strtoi64
-#endif
-
-#endif /* Def WIN32 or Def WIN64 */
-
-#define NUM_PRIORITY 6
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CParser::CParser() : m_identifierContext(NULL)
-{
-}
-
-
-
-CParser::~CParser()
-{
- if (m_identifierContext)
- m_identifierContext->Release();
-}
-
-
-
-void CParser::ScanError(const char *str)
-{
- // sets the global variable errmsg to an errormessage with
- // contents str, appending if it already exists
- // AfxMessageBox("Parse Error:"+str,MB_ICONERROR);
- if (errmsg)
- errmsg = new COperator2Expr(VALUE_ADD_OPERATOR, errmsg, Error(str));
- else
- errmsg = Error(str);
-
- sym = errorsym;
-}
-
-
-
-CExpression* CParser::Error(const char *str)
-{
- // makes and returns a new CConstExpr filled with an CErrorValue
- // with string str
- // AfxMessageBox("Error:"+str,MB_ICONERROR);
- return new CConstExpr(new CErrorValue(str));
-}
-
-
-
-void CParser::NextCh()
-{
- // sets the global variable ch to the next character, if it exists
- // and increases the global variable chcount
- chcount++;
-
- if (chcount < text.Length())
- ch = text[chcount];
- else
- ch = 0x00;
-}
-
-
-
-void CParser::TermChar(char c)
-{
- // generates an error if the next char isn't the specified char c,
- // otherwise, skip the char
- if (ch == c)
- {
- NextCh();
- }
- else
- {
- STR_String str;
- str.Format("Warning: %c expected\ncontinuing without it", c);
- trace(str);
- }
-}
-
-
-
-void CParser::DigRep()
-{
- // changes the current character to the first character that
- // isn't a decimal
- while ((ch >= '0') && (ch <= '9'))
- NextCh();
-}
-
-
-
-void CParser::CharRep()
-{
- // changes the current character to the first character that
- // isn't an alphanumeric character
- while (((ch >= '0') && (ch <= '9'))
- || ((ch >= 'a') && (ch <= 'z'))
- || ((ch >= 'A') && (ch <= 'Z'))
- || (ch == '.') || (ch == '_'))
- NextCh();
-}
-
-
-
-void CParser::GrabString(int start)
-{
- // puts part of the input string into the global variable
- // const_as_string, from position start, to position chchount
- const_as_string = text.Mid(start, chcount-start);
-}
-
-
-
-void CParser::GrabRealString(int start)
-{
- // works like GrabString but converting \\n to \n
- // puts part of the input string into the global variable
- // const_as_string, from position start, to position chchount
-
- int i;
- char tmpch;
-
- const_as_string = STR_String();
- for (i=start;i<chcount;i++) {
- tmpch= text[i];
- if ((tmpch =='\\') && (text[i+1] == 'n')) {
- tmpch = '\n';
- i++;
- }
- const_as_string += tmpch;
- }
-}
-
-
-
-void CParser::NextSym()
-{
- // sets the global variable sym to the next symbol, and
- // if it is an operator
- // sets the global variable opkind to the kind of operator
- // if it is a constant
- // sets the global variable constkind to the kind of operator
- // if it is a reference to a cell
- // sets the global variable cellcoord to the kind of operator
-
- errmsg = NULL;
- while (ch == ' ' || ch == 0x9)
- NextCh();
-
- switch (ch) {
- case '(':
- sym = lbracksym; NextCh();
- break;
- case ')':
- sym = rbracksym; NextCh();
- break;
- case ',':
- sym = commasym; NextCh();
- break;
- case '%' :
- sym = opsym; opkind = OPmodulus; NextCh();
- break;
- case '+' :
- sym = opsym; opkind = OPplus; NextCh();
- break;
- case '-' :
- sym = opsym; opkind = OPminus; NextCh();
- break;
- case '*' :
- sym = opsym; opkind = OPtimes; NextCh();
- break;
- case '/' :
- sym = opsym; opkind = OPdivide; NextCh();
- break;
- case '&' :
- sym = opsym; opkind = OPand; NextCh(); TermChar('&');
- break;
- case '|' :
- sym = opsym; opkind = OPor; NextCh(); TermChar('|');
- break;
- case '=' :
- sym = opsym; opkind = OPequal; NextCh(); TermChar('=');
- break;
- case '!' :
- sym = opsym;
- NextCh();
- if (ch == '=')
- {
- opkind = OPunequal;
- NextCh();
- }
- else
- {
- opkind = OPnot;
- }
- break;
- case '>':
- sym = opsym;
- NextCh();
- if (ch == '=')
- {
- opkind = OPgreaterequal;
- NextCh();
- }
- else
- {
- opkind = OPgreater;
- }
- break;
- case '<':
- sym = opsym;
- NextCh();
- if (ch == '=') {
- opkind = OPlessequal;
- NextCh();
- } else {
- opkind = OPless;
- }
- break;
- case '\"' :
- {
- int start;
- sym = constsym;
- constkind = stringtype;
- NextCh();
- start = chcount;
- while ((ch != '\"') && (ch != 0x0))
- NextCh();
- GrabRealString(start);
- TermChar('\"'); // check for eol before '\"'
- break;
- }
- case 0x0: sym = eolsym; break;
- default:
- {
- int start;
- start = chcount;
- DigRep();
- if ((start != chcount) || (ch == '.')) { // number
- sym = constsym;
- if (ch == '.') {
- constkind = floattype;
- NextCh();
- DigRep();
- }
- else constkind = inttype;
- if ((ch == 'e') || (ch == 'E')) {
- int mark;
- constkind = floattype;
- NextCh();
- if ((ch == '+') || (ch == '-')) NextCh();
- mark = chcount;
- DigRep();
- if (mark == chcount) {
- ScanError("Number expected after 'E'");
- return;
- }
- }
- GrabString(start);
- } else if (((ch >= 'a') && (ch <= 'z'))
- || ((ch >= 'A') && (ch <= 'Z')))
- { // reserved word?
-
- start = chcount;
- CharRep();
- GrabString(start);
- if (!strcasecmp(const_as_string, "SUM")) {
- sym = sumsym;
- }
- else if (!strcasecmp(const_as_string, "NOT")) {
- sym = opsym;
- opkind = OPnot;
- }
- else if (!strcasecmp(const_as_string, "AND")) {
- sym = opsym; opkind = OPand;
- }
- else if (!strcasecmp(const_as_string, "OR")) {
- sym = opsym; opkind = OPor;
- }
- else if (!strcasecmp(const_as_string, "IF"))
- sym = ifsym;
- else if (!strcasecmp(const_as_string, "WHOMADE"))
- sym = whocodedsym;
- else if (!strcasecmp(const_as_string, "FALSE")) {
- sym = constsym; constkind = booltype; boolvalue = false;
- } else if (!strcasecmp(const_as_string, "TRUE")) {
- sym = constsym; constkind = booltype; boolvalue = true;
- } else {
- sym = idsym;
- //STR_String str;
- //str.Format("'%s' makes no sense here", (const char*)funstr);
- //ScanError(str);
- }
- } else { // unknown symbol
- STR_String str;
- str.Format("Unexpected character '%c'", ch);
- NextCh();
- ScanError(str);
- return;
- }
- }
- }
-}
-
-#if 0
-int CParser::MakeInt()
-{
- // returns the integer representation of the value in the global
- // variable const_as_string
- // pre: const_as_string contains only numercal chars
- return atoi(const_as_string);
-}
-#endif
-
-const char *CParser::Symbol2Str(int s)
-{
- // returns a string representation of of symbol s,
- // for use in Term when generating an error
- switch (s) {
- case errorsym: return "error";
- case lbracksym: return "(";
- case rbracksym: return ")";
- case commasym: return ",";
- case opsym: return "operator";
- case constsym: return "constant";
- case sumsym: return "SUM";
- case ifsym: return "IF";
- case whocodedsym: return "WHOMADE";
- case eolsym: return "end of line";
- case idsym: return "identifier";
- }
- return "unknown"; // should not happen
-}
-
-void CParser::Term(int s)
-{
- // generates an error if the next symbol isn't the specified symbol s
- // otherwise, skip the symbol
- if (s == sym) {
- NextSym();
- }
- else {
- STR_String msg;
- msg.Format("Warning: %s expected\ncontinuing without it", Symbol2Str(s));
-
-// AfxMessageBox(msg,MB_ICONERROR);
-
- trace(msg);
- }
-}
-
-int CParser::Priority(int optorkind)
-{
- // returns the priority of an operator
- // higher number means higher priority
- switch (optorkind) {
- case OPor: return 1;
- case OPand: return 2;
- case OPgreater:
- case OPless:
- case OPgreaterequal:
- case OPlessequal:
- case OPequal:
- case OPunequal: return 3;
- case OPplus:
- case OPminus: return 4;
- case OPmodulus:
- case OPtimes:
- case OPdivide: return 5;
- }
- MT_assert(false);
- return 0; // should not happen
-}
-
-CExpression *CParser::Ex(int i)
-{
- // parses an expression in the imput, starting at priority i, and
- // returns an CExpression, containing the parsed input
- CExpression *e1 = NULL, *e2 = NULL;
- int opkind2;
-
- if (i < NUM_PRIORITY) {
- e1 = Ex(i + 1);
- while ((sym == opsym) && (Priority(opkind) == i)) {
- opkind2 = opkind;
- NextSym();
- e2 = Ex(i + 1);
- switch (opkind2) {
- case OPmodulus: e1 = new COperator2Expr(VALUE_MOD_OPERATOR,e1, e2); break;
- case OPplus: e1 = new COperator2Expr(VALUE_ADD_OPERATOR,e1, e2); break;
- case OPminus: e1 = new COperator2Expr(VALUE_SUB_OPERATOR,e1, e2); break;
- case OPtimes: e1 = new COperator2Expr(VALUE_MUL_OPERATOR,e1, e2); break;
- case OPdivide: e1 = new COperator2Expr(VALUE_DIV_OPERATOR,e1, e2); break;
- case OPand: e1 = new COperator2Expr(VALUE_AND_OPERATOR,e1, e2); break;
- case OPor: e1 = new COperator2Expr(VALUE_OR_OPERATOR,e1, e2); break;
- case OPequal: e1 = new COperator2Expr(VALUE_EQL_OPERATOR,e1, e2); break;
- case OPunequal: e1 = new COperator2Expr(VALUE_NEQ_OPERATOR,e1, e2); break;
- case OPgreater: e1 = new COperator2Expr(VALUE_GRE_OPERATOR,e1, e2); break;
- case OPless: e1 = new COperator2Expr(VALUE_LES_OPERATOR,e1, e2); break;
- case OPgreaterequal: e1 = new COperator2Expr(VALUE_GEQ_OPERATOR,e1, e2); break;
- case OPlessequal: e1 = new COperator2Expr(VALUE_LEQ_OPERATOR,e1, e2); break;
- default: MT_assert(false); break; // should not happen
- }
- }
- } else if (i == NUM_PRIORITY) {
- if ((sym == opsym)
- && ( (opkind == OPminus) || (opkind == OPnot) || (opkind == OPplus) )
- )
- {
- NextSym();
- switch (opkind) {
- /* +1 is also a valid number! */
- case OPplus: e1 = new COperator1Expr(VALUE_POS_OPERATOR, Ex(NUM_PRIORITY)); break;
- case OPminus: e1 = new COperator1Expr(VALUE_NEG_OPERATOR, Ex(NUM_PRIORITY)); break;
- case OPnot: e1 = new COperator1Expr(VALUE_NOT_OPERATOR, Ex(NUM_PRIORITY)); break;
- default:
- {
- // should not happen
- e1 = Error("operator +, - or ! expected");
- }
- }
- }
- else {
- switch (sym) {
- case constsym:
- {
- switch (constkind) {
- case booltype:
- e1 = new CConstExpr(new CBoolValue(boolvalue));
- break;
- case inttype:
- {
- cInt temp;
- temp = strtoll(const_as_string, NULL, 10); /* atoi is for int only */
- e1 = new CConstExpr(new CIntValue(temp));
- break;
- }
- case floattype:
- {
- double temp;
- temp = atof(const_as_string);
- e1 = new CConstExpr(new CFloatValue(temp));
- break;
- }
- case stringtype:
- e1 = new CConstExpr(new CStringValue(const_as_string,""));
- break;
- default :
- MT_assert(false);
- break;
- }
- NextSym();
- break;
- }
- case lbracksym:
- NextSym();
- e1 = Ex(1);
- Term(rbracksym);
- break;
- case ifsym:
- {
- CExpression *e3;
- NextSym();
- Term(lbracksym);
- e1 = Ex(1);
- Term(commasym);
- e2 = Ex(1);
- if (sym == commasym) {
- NextSym();
- e3 = Ex(1);
- } else {
- e3 = new CConstExpr(new CEmptyValue());
- }
- Term(rbracksym);
- e1 = new CIfExpr(e1, e2, e3);
- break;
- }
- case idsym:
- {
- e1 = new CIdentifierExpr(const_as_string,m_identifierContext);
- NextSym();
-
- break;
- }
- case errorsym:
- {
- MT_assert(!e1);
- STR_String errtext="[no info]";
- if (errmsg)
- {
- CValue* errmsgval = errmsg->Calculate();
- errtext=errmsgval->GetText();
- errmsgval->Release();
-
- //e1 = Error(errmsg->Calculate()->GetText());//new CConstExpr(errmsg->Calculate());
-
- if ( !(errmsg->Release()) )
- {
- errmsg=NULL;
- } else {
- // does this happen ?
- MT_assert("does this happen");
- }
- }
- e1 = Error(errtext);
-
- break;
- }
- default:
- NextSym();
- //return Error("Expression expected");
- MT_assert(!e1);
- e1 = Error("Expression expected");
- }
- }
- }
- return e1;
-}
-
-CExpression *CParser::Expr()
-{
- // parses an expression in the imput, and
- // returns an CExpression, containing the parsed input
- return Ex(1);
-}
-
-CExpression* CParser::ProcessText
-(const char *intext) {
-
- // and parses the string in intext and returns it.
-
-
- CExpression* expr;
- text = intext;
-
-
- chcount = 0;
- if (text.Length() == 0) {
- return NULL;
- }
-
- ch = text[0];
- /* if (ch != '=') {
- * expr = new CConstExpr(new CStringValue(text));
- * *dependent = deplist;
- * return expr;
- * } else
- */
- // NextCh();
- NextSym();
- expr = Expr();
- if (sym != eolsym) {
- CExpression* oldexpr = expr;
- expr = new COperator2Expr(VALUE_ADD_OPERATOR,
- oldexpr, Error(STR_String("Extra characters after expression")));//new CConstExpr(new CErrorValue("Extra characters after expression")));
- }
- if (errmsg)
- errmsg->Release();
-
- return expr;
-}
-
-
-
-float CParser::GetFloat(STR_String& txt)
-{
- // returns parsed text into a float
- // empty string returns -1
-
-// AfxMessageBox("parsed string="+txt);
- CValue* val=NULL;
- float result=-1;
-// String tmpstr;
-
- CExpression* expr = ProcessText(txt);
- if (expr) {
- val = expr->Calculate();
- result=(float)val->GetNumber();
-
-
-
- val->Release();
- expr->Release();
- }
-// tmpstr.Format("parseresult=%g",result);
-// AfxMessageBox(tmpstr);
- return result;
-}
-
-CValue* CParser::GetValue(STR_String& txt, bool bFallbackToText)
-{
- // returns parsed text into a value,
- // empty string returns NULL value !
- // if bFallbackToText then unparsed stuff is put into text
-
- CValue* result=NULL;
- CExpression* expr = ProcessText(txt);
- if (expr) {
- result = expr->Calculate();
- expr->Release();
- }
- if (result)
- {
- // if the parsed stuff lead to an errorvalue, don't return errors, just NULL
- if (result->IsError()) {
- result->Release();
- result=NULL;
- if (bFallbackToText) {
- if (txt.Length()>0)
- {
- result = new CStringValue(txt,"");
- }
- }
- }
- }
- return result;
-}
-
-void CParser::SetContext(CValue* context)
-{
- if (m_identifierContext)
- {
- m_identifierContext->Release();
- }
- m_identifierContext = context;
-}
diff --git a/source/gameengine/Expressions/intern/IntValue.cpp b/source/gameengine/Expressions/intern/IntValue.cpp
deleted file mode 100644
index 7b2e841f13f..00000000000
--- a/source/gameengine/Expressions/intern/IntValue.cpp
+++ /dev/null
@@ -1,344 +0,0 @@
-/** \file gameengine/Expressions/IntValue.cpp
- * \ingroup expressions
- */
-// IntValue.cpp: implementation of the CIntValue class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include <stdio.h>
-
-#include "EXP_IntValue.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_FloatValue.h"
-#include "EXP_BoolValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_VoidValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CIntValue::CIntValue()
-/*
-pre: false
-effect: constructs a new CIntValue
-*/
-{
-
-#ifdef DEBUG_
- m_textval = "Int illegal constructor";
-#endif
- m_pstrRep=NULL;
-}
-
-
-
-CIntValue::CIntValue(cInt innie)
-/*
-pre:
-effect: constructs a new CIntValue containing cInt innie
-*/
-{
- m_int = innie;
- m_pstrRep=NULL;
-}
-
-
-
-CIntValue::CIntValue(cInt innie,const char *name,AllocationTYPE alloctype)
-{
- m_int = innie;
- SetName(name);
-
- if (alloctype==CValue::STACKVALUE)
- {
- CValue::DisableRefCount();
- }
- m_pstrRep=NULL;
-
-}
-
-
-
-CIntValue::~CIntValue()
-/*
-pre:
-effect: deletes the object
-*/
-{
- if (m_pstrRep)
- delete m_pstrRep;
-}
-
-
-
-CValue* CIntValue::Calc(VALUE_OPERATOR op, CValue *val)
-/*
-pre:
-ret: a new object containing the result of applying operator op to this
-object and val
-*/
-{
- //return val->CalcInt(op, this);
- switch (op) {
- case VALUE_POS_OPERATOR:
- return new CIntValue (m_int);
- break;
- case VALUE_NEG_OPERATOR:
- return new CIntValue (-m_int);
- break;
- case VALUE_NOT_OPERATOR:
- return new CBoolValue (m_int == 0);
- break;
- case VALUE_AND_OPERATOR:
- case VALUE_OR_OPERATOR:
- return new CErrorValue(val->GetText() + op2str(op) + "only allowed on booleans");
- break;
- default:
- return val->CalcFinal(VALUE_INT_TYPE, op, this);
- break;
- }
-}
-
-/*
- * pre: the type of val is dtype
- * ret: a new object containing the result of applying operator op to val and
- * this object
- */
-CValue* CIntValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-{
- CValue *ret;
-
- switch (dtype) {
- case VALUE_EMPTY_TYPE:
- case VALUE_INT_TYPE:
- {
- switch (op) {
- case VALUE_MOD_OPERATOR:
- ret = new CIntValue (((CIntValue *) val)->GetInt() % m_int);
- break;
- case VALUE_ADD_OPERATOR:
- ret = new CIntValue (((CIntValue *) val)->GetInt() + m_int);
- break;
- case VALUE_SUB_OPERATOR:
- ret = new CIntValue (((CIntValue *) val)->GetInt() - m_int);
- break;
- case VALUE_MUL_OPERATOR:
- ret = new CIntValue (((CIntValue *) val)->GetInt() * m_int);
- break;
- case VALUE_DIV_OPERATOR:
- if (m_int == 0) {
- if (val->GetNumber() == 0) {
- ret = new CErrorValue("Not a Number");
- }
- else {
- ret = new CErrorValue("Division by zero");
- }
- }
- else
- ret = new CIntValue (((CIntValue *) val)->GetInt() / m_int);
- break;
- case VALUE_EQL_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() == m_int);
- break;
- case VALUE_NEQ_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() != m_int);
- break;
- case VALUE_GRE_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() > m_int);
- break;
- case VALUE_LES_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() < m_int);
- break;
- case VALUE_GEQ_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() >= m_int);
- break;
- case VALUE_LEQ_OPERATOR:
- ret = new CBoolValue(((CIntValue *) val)->GetInt() <= m_int);
- break;
- case VALUE_NEG_OPERATOR:
- ret = new CIntValue (-m_int);
- break;
- case VALUE_POS_OPERATOR:
- ret = new CIntValue (m_int);
- break;
- case VALUE_NOT_OPERATOR:
- ret = new CBoolValue(m_int == 0);
- break;
- default:
- printf("Found op: %d\n", op);
- ret = new CErrorValue("illegal operator. please send a bug report.");
- break;
- }
- break;
- }
- case VALUE_FLOAT_TYPE:
- {
- switch (op) {
- case VALUE_MOD_OPERATOR:
- ret = new CFloatValue(fmod(((CFloatValue *) val)->GetFloat(), m_int));
- break;
- case VALUE_ADD_OPERATOR:
- ret = new CFloatValue (((CFloatValue *) val)->GetFloat() + m_int);
- break;
- case VALUE_SUB_OPERATOR:
- ret = new CFloatValue (((CFloatValue *) val)->GetFloat() - m_int);
- break;
- case VALUE_MUL_OPERATOR:
- ret = new CFloatValue (((CFloatValue *) val)->GetFloat() * m_int);
- break;
- case VALUE_DIV_OPERATOR:
- if (m_int == 0)
- ret = new CErrorValue("Division by zero");
- else
- ret = new CFloatValue (((CFloatValue *) val)->GetFloat() / m_int);
- break;
- case VALUE_EQL_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() == m_int);
- break;
- case VALUE_NEQ_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() != m_int);
- break;
- case VALUE_GRE_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() > m_int);
- break;
- case VALUE_LES_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() < m_int);
- break;
- case VALUE_GEQ_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() >= m_int);
- break;
- case VALUE_LEQ_OPERATOR:
- ret = new CBoolValue(((CFloatValue *) val)->GetFloat() <= m_int);
- break;
- case VALUE_NOT_OPERATOR:
- ret = new CBoolValue(m_int == 0);
- break;
- default:
- ret = new CErrorValue("illegal operator. please send a bug report.");
- break;
- }
- break;
- }
- case VALUE_STRING_TYPE:
- {
- switch (op) {
- case VALUE_ADD_OPERATOR:
- ret = new CStringValue(val->GetText() + GetText(),"");
- break;
- case VALUE_EQL_OPERATOR:
- case VALUE_NEQ_OPERATOR:
- case VALUE_GRE_OPERATOR:
- case VALUE_LES_OPERATOR:
- case VALUE_GEQ_OPERATOR:
- case VALUE_LEQ_OPERATOR:
- ret = new CErrorValue("[Cannot compare string with integer]" + op2str(op) + GetText());
- break;
- default:
- ret = new CErrorValue("[operator not allowed on strings]" + op2str(op) + GetText());
- break;
- }
- break;
- }
- case VALUE_BOOL_TYPE:
- ret = new CErrorValue("[operator not valid on boolean and integer]" + op2str(op) + GetText());
- break;
-#if 0
- case VALUE_EMPTY_TYPE:
- {
- switch (op) {
- case VALUE_ADD_OPERATOR:
- ret = new CIntValue (m_int);
- break;
- case VALUE_SUB_OPERATOR:
- ret = new CIntValue (-m_int);
- break;
- default:
- {
- ret = new CErrorValue(op2str(op) + GetText());
- }
- }
- break;
- }
-#endif
- case VALUE_ERROR_TYPE:
- ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
- break;
- default:
- ret = new CErrorValue("illegal type. contact your dealer (if any)");
- break;
- }
- return ret;
-}
-
-
-/**
- * pre:
- * ret: the cInt stored in the object
- */
-cInt CIntValue::GetInt()
-{
- return m_int;
-}
-
-
-
-double CIntValue::GetNumber()
-{
- return (double) m_int;
-}
-
-
-
-int CIntValue::GetValueType()
-{
- return VALUE_INT_TYPE;
-}
-
-
-
-const STR_String & CIntValue::GetText()
-{
- if (!m_pstrRep)
- m_pstrRep=new STR_String();
- m_pstrRep->Format("%lld",m_int);
-
- return *m_pstrRep;
-}
-
-
-
-CValue* CIntValue::GetReplica()
-{
- CIntValue* replica = new CIntValue(*this);
- replica->ProcessReplica();
- replica->m_pstrRep = NULL;
-
- return replica;
-}
-
-
-
-void CIntValue::SetValue(CValue* newval)
-{
- m_int = (cInt)newval->GetNumber();
- SetModified(true);
-}
-
-
-#ifdef WITH_PYTHON
-PyObject *CIntValue::ConvertValueToPython()
-{
- return PyLong_FromLongLong(m_int);
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Expressions/intern/ListValue.cpp b/source/gameengine/Expressions/intern/ListValue.cpp
deleted file mode 100644
index 557ce7be300..00000000000
--- a/source/gameengine/Expressions/intern/ListValue.cpp
+++ /dev/null
@@ -1,702 +0,0 @@
-/** \file gameengine/Expressions/ListValue.cpp
- * \ingroup expressions
- */
-// ListValue.cpp: implementation of the CListValue class.
-//
-//////////////////////////////////////////////////////////////////////
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include <stdio.h>
-
-#include "EXP_ListValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_VoidValue.h"
-#include <algorithm>
-#include "EXP_BoolValue.h"
-
-#include "BLI_sys_types.h" /* for intptr_t support */
-
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CListValue::CListValue()
-: CPropValue()
-{
- m_bReleaseContents=true;
-}
-
-
-
-CListValue::~CListValue()
-{
-
- if (m_bReleaseContents) {
- for (unsigned int i=0;i<m_pValueArray.size();i++) {
- m_pValueArray[i]->Release();
- }
- }
-}
-
-
-static STR_String gstrListRep=STR_String("List");
-
-const STR_String & CListValue::GetText()
-{
- gstrListRep = "[";
- STR_String commastr = "";
-
- for (int i=0;i<GetCount();i++)
- {
- gstrListRep += commastr;
- gstrListRep += GetValue(i)->GetText();
- commastr = ",";
- }
- gstrListRep += "]";
-
- return gstrListRep;
-}
-
-
-
-CValue* CListValue::GetReplica()
-{
- CListValue* replica = new CListValue(*this);
-
- replica->ProcessReplica();
-
- replica->m_bReleaseContents=true; // for copy, complete array is copied for now...
- // copy all values
- int numelements = m_pValueArray.size();
- unsigned int i=0;
- replica->m_pValueArray.resize(numelements);
- for (i=0;i<m_pValueArray.size();i++)
- replica->m_pValueArray[i] = m_pValueArray[i]->GetReplica();
-
-
- return replica;
-};
-
-
-
-void CListValue::SetValue(int i, CValue *val)
-{
- assertd(i < m_pValueArray.size());
- m_pValueArray[i]=val;
-}
-
-
-
-void CListValue::Resize(int num)
-{
- m_pValueArray.resize(num);
-}
-
-
-
-void CListValue::Remove(int i)
-{
- assertd(i<m_pValueArray.size());
- m_pValueArray.erase(m_pValueArray.begin()+i);
-}
-
-
-
-void CListValue::ReleaseAndRemoveAll()
-{
- for (unsigned int i=0;i<m_pValueArray.size();i++)
- m_pValueArray[i]->Release();
- m_pValueArray.clear();//.Clear();
-}
-
-
-
-CValue* CListValue::FindValue(const STR_String &name)
-{
- for (int i=0; i < GetCount(); i++)
- if (GetValue(i)->GetName() == name)
- return GetValue(i);
-
- return NULL;
-}
-
-CValue* CListValue::FindValue(const char *name)
-{
- for (int i=0; i < GetCount(); i++)
- if (GetValue(i)->GetName() == name)
- return GetValue(i);
-
- return NULL;
-}
-
-bool CListValue::SearchValue(CValue *val)
-{
- for (int i=0;i<GetCount();i++)
- if (val == GetValue(i))
- return true;
- return false;
-}
-
-
-
-void CListValue::SetReleaseOnDestruct(bool bReleaseContents)
-{
- m_bReleaseContents = bReleaseContents;
-}
-
-
-
-bool CListValue::RemoveValue(CValue *val)
-{
- bool result=false;
-
- for (int i=GetCount()-1;i>=0;i--)
- if (val == GetValue(i))
- {
- Remove(i);
- result=true;
- }
- return result;
-}
-
-
-
-void CListValue::MergeList(CListValue *otherlist)
-{
-
- int numelements = this->GetCount();
- int numotherelements = otherlist->GetCount();
-
-
- Resize(numelements+numotherelements);
-
- for (int i=0;i<numotherelements;i++)
- {
- SetValue(i+numelements,otherlist->GetValue(i)->AddRef());
- }
-}
-
-bool CListValue::CheckEqual(CValue* first,CValue* second)
-{
- bool result = false;
-
- CValue* eqval = ((CValue*)first)->Calc(VALUE_EQL_OPERATOR,(CValue*)second);
-
- if (eqval==NULL)
- return false;
- const STR_String& text = eqval->GetText();
- if (&text==&CBoolValue::sTrueString)
- {
- result = true;
- }
- eqval->Release();
- return result;
-
-}
-
-
-/* ---------------------------------------------------------------------
- * Some stuff taken from the header
- * --------------------------------------------------------------------- */
-CValue* CListValue::Calc(VALUE_OPERATOR op,CValue *val)
-{
- //assert(false); // todo: implement me!
- static int error_printed = 0;
- if (error_printed==0) {
- fprintf(stderr, "CValueList::Calc not yet implemented\n");
- error_printed = 1;
- }
- return NULL;
-}
-
-CValue* CListValue::CalcFinal(VALUE_DATA_TYPE dtype,
- VALUE_OPERATOR op,
- CValue* val)
-{
- //assert(false); // todo: implement me!
- static int error_printed = 0;
- if (error_printed==0) {
- fprintf(stderr, "CValueList::CalcFinal not yet implemented\n");
- error_printed = 1;
- }
- return NULL;
-}
-
-
-
-void CListValue::Add(CValue* value)
-{
- m_pValueArray.push_back(value);
-}
-
-
-
-double CListValue::GetNumber()
-{
- return -1;
-}
-
-
-
-int CListValue::GetValueType()
-{
- return VALUE_LIST_TYPE;
-}
-
-
-
-void CListValue::SetModified(bool bModified)
-{
- CValue::SetModified(bModified);
- int numels = GetCount();
-
- for (int i=0;i<numels;i++)
- GetValue(i)->SetModified(bModified);
-}
-
-
-
-bool CListValue::IsModified()
-{
- bool bmod = CValue::IsModified(); //normal own flag
- int numels = GetCount();
-
- for (int i=0;i<numels;i++)
- bmod = bmod || GetValue(i)->IsModified();
-
- return bmod;
-}
-
-#ifdef WITH_PYTHON
-
-/* --------------------------------------------------------------------- */
-/* Python interface ---------------------------------------------------- */
-/* --------------------------------------------------------------------- */
-
-static Py_ssize_t listvalue_bufferlen(PyObject *self)
-{
- CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self));
- if (list==NULL)
- return 0;
-
- return (Py_ssize_t)list->GetCount();
-}
-
-static PyObject *listvalue_buffer_item(PyObject *self, Py_ssize_t index)
-{
- CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self));
- CValue *cval;
-
- if (list==NULL) {
- PyErr_SetString(PyExc_SystemError, "val = CList[i], " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- int count = list->GetCount();
-
- if (index < 0)
- index = count+index;
-
- if (index < 0 || index >= count) {
- PyErr_SetString(PyExc_IndexError, "CList[i]: Python ListIndex out of range in CValueList");
- return NULL;
- }
-
- cval= list->GetValue(index);
-
- PyObject *pyobj = cval->ConvertValueToPython();
- if (pyobj)
- return pyobj;
- else
- return cval->GetProxy();
-}
-
-
-/* just slice it into a python list... */
-static PyObject *listvalue_buffer_slice(CListValue *list, Py_ssize_t start, Py_ssize_t stop)
-{
- PyObject *newlist;
- Py_ssize_t i, j;
-
- /* caller needs to validate negative index */
-#if 0
- Py_ssize_t len = list->GetCount();
-
- if (start > len) start = len;
- if (stop > len) stop = len;
-#endif
-
- newlist = PyList_New(stop - start);
- if (!newlist)
- return NULL;
-
- for (i = start, j = 0; i < stop; i++, j++) {
- PyObject *pyobj = list->GetValue(i)->ConvertValueToPython();
- if (!pyobj) {
- pyobj = list->GetValue(i)->GetProxy();
- }
- PyList_SET_ITEM(newlist, j, pyobj);
- }
- return newlist;
-}
-
-
-static PyObject *listvalue_mapping_subscript(PyObject *self, PyObject *key)
-{
- CListValue *list= static_cast<CListValue *>(BGE_PROXY_REF(self));
- if (list==NULL) {
- PyErr_SetString(PyExc_SystemError, "value = CList[i], " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- if (PyUnicode_Check(key)) {
- CValue *item = ((CListValue*) list)->FindValue(_PyUnicode_AsString(key));
- if (item) {
- PyObject *pyobj = item->ConvertValueToPython();
- if (pyobj)
- return pyobj;
- else
- return item->GetProxy();
- }
- }
- else if (PyIndex_Check(key)) {
- Py_ssize_t index = PyLong_AsSsize_t(key);
- return listvalue_buffer_item(self, index); /* wont add a ref */
- }
- else if (PySlice_Check(key)) {
- Py_ssize_t start, stop, step, slicelength;
-
- if (PySlice_GetIndicesEx(key, list->GetCount(), &start, &stop, &step, &slicelength) < 0)
- return NULL;
-
- if (slicelength <= 0) {
- return PyList_New(0);
- }
- else if (step == 1) {
- return listvalue_buffer_slice(list, start, stop);
- }
- else {
- PyErr_SetString(PyExc_TypeError, "CList[slice]: slice steps not supported");
- return NULL;
- }
- }
-
- PyErr_Format(PyExc_KeyError,
- "CList[key]: '%R' key not in list", key);
- return NULL;
-}
-
-/* clist + list, return a list that python owns */
-static PyObject *listvalue_buffer_concat(PyObject *self, PyObject *other)
-{
- CListValue *listval= static_cast<CListValue *>(BGE_PROXY_REF(self));
- Py_ssize_t i, numitems, numitems_orig;
-
- if (listval==NULL) {
- PyErr_SetString(PyExc_SystemError, "CList+other, " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- numitems_orig= listval->GetCount();
-
- // for now, we support CListValue concatenated with items
- // and CListValue concatenated to Python Lists
- // and CListValue concatenated with another CListValue
-
- /* Shallow copy, don't use listval->GetReplica(), it will screw up with KX_GameObjects */
- CListValue* listval_new = new CListValue();
-
- if (PyList_Check(other))
- {
- CValue* listitemval;
- bool error = false;
-
- numitems = PyList_GET_SIZE(other);
-
- /* copy the first part of the list */
- listval_new->Resize(numitems_orig + numitems);
- for (i=0;i<numitems_orig;i++)
- listval_new->SetValue(i, listval->GetValue(i)->AddRef());
-
- for (i=0;i<numitems;i++)
- {
- listitemval = listval->ConvertPythonToValue(PyList_GET_ITEM(other, i), true, "cList + pyList: CListValue, ");
-
- if (listitemval) {
- listval_new->SetValue(i+numitems_orig, listitemval);
- } else {
- error= true;
- break;
- }
- }
-
- if (error) {
- listval_new->Resize(numitems_orig+i); /* resize so we don't try release NULL pointers */
- listval_new->Release();
- return NULL; /* ConvertPythonToValue above sets the error */
- }
-
- }
- else if (PyObject_TypeCheck(other, &CListValue::Type)) {
- // add items from otherlist to this list
- CListValue* otherval = static_cast<CListValue *>(BGE_PROXY_REF(other));
- if (otherval==NULL) {
- listval_new->Release();
- PyErr_SetString(PyExc_SystemError, "CList+other, " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- numitems = otherval->GetCount();
-
- /* copy the first part of the list */
- listval_new->Resize(numitems_orig + numitems); /* resize so we don't try release NULL pointers */
- for (i=0;i<numitems_orig;i++)
- listval_new->SetValue(i, listval->GetValue(i)->AddRef());
-
- /* now copy the other part of the list */
- for (i=0;i<numitems;i++)
- listval_new->SetValue(i+numitems_orig, otherval->GetValue(i)->AddRef());
-
- }
- return listval_new->NewProxy(true); /* python owns this list */
-}
-
-static int listvalue_buffer_contains(PyObject *self_v, PyObject *value)
-{
- CListValue *self = static_cast<CListValue *>(BGE_PROXY_REF(self_v));
-
- if (self == NULL) {
- PyErr_SetString(PyExc_SystemError, "val in CList, " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (PyUnicode_Check(value)) {
- if (self->FindValue((const char *)_PyUnicode_AsString(value))) {
- return 1;
- }
- }
- else if (PyObject_TypeCheck(value, &CValue::Type)) { /* not dict like at all but this worked before __contains__ was used */
- CValue *item= static_cast<CValue *>(BGE_PROXY_REF(value));
- for (int i=0; i < self->GetCount(); i++)
- if (self->GetValue(i) == item) // Com
- return 1;
-
- } // not using CheckEqual
-
- return 0;
-}
-
-
-static PySequenceMethods listvalue_as_sequence = {
- listvalue_bufferlen,//(inquiry)buffer_length, /*sq_length*/
- listvalue_buffer_concat, /*sq_concat*/
- NULL, /*sq_repeat*/
- listvalue_buffer_item, /*sq_item*/
-// TODO, slicing in py3
- NULL, // listvalue_buffer_slice, /*sq_slice*/
- NULL, /*sq_ass_item*/
- NULL, /*sq_ass_slice*/
- (objobjproc)listvalue_buffer_contains, /* sq_contains */
- (binaryfunc) NULL, /* sq_inplace_concat */
- (ssizeargfunc) NULL, /* sq_inplace_repeat */
-};
-
-
-
-/* Is this one used ? */
-static PyMappingMethods instance_as_mapping = {
- listvalue_bufferlen, /*mp_length*/
- listvalue_mapping_subscript, /*mp_subscript*/
- NULL /*mp_ass_subscript*/
-};
-
-
-
-PyTypeObject CListValue::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "CListValue", /*tp_name*/
- sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- py_base_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- py_base_repr, /*tp_repr*/
- 0, /*tp_as_number*/
- &listvalue_as_sequence, /*tp_as_sequence*/
- &instance_as_mapping, /*tp_as_mapping*/
- 0, /*tp_hash*/
- 0, /*tp_call */
- 0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef CListValue::Methods[] = {
- /* List style access */
- {"append", (PyCFunction)CListValue::sPyappend,METH_O},
- {"reverse", (PyCFunction)CListValue::sPyreverse,METH_NOARGS},
- {"index", (PyCFunction)CListValue::sPyindex,METH_O},
- {"count", (PyCFunction)CListValue::sPycount,METH_O},
-
- /* Dict style access */
- {"get", (PyCFunction)CListValue::sPyget,METH_VARARGS},
-
- /* Own cvalue funcs */
- {"from_id", (PyCFunction)CListValue::sPyfrom_id,METH_O},
-
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef CListValue::Attributes[] = {
- { NULL } //Sentinel
-};
-
-PyObject *CListValue::Pyappend(PyObject *value)
-{
- CValue *objval = ConvertPythonToValue(value, true, "CList.append(i): CValueList, ");
-
- if (!objval) /* ConvertPythonToValue sets the error */
- return NULL;
-
- if (!BGE_PROXY_PYOWNS(m_proxy)) {
- PyErr_SetString(PyExc_TypeError,
- "CList.append(i): internal values can't be modified");
- return NULL;
- }
-
- Add(objval);
-
- Py_RETURN_NONE;
-}
-
-PyObject *CListValue::Pyreverse()
-{
- if (!BGE_PROXY_PYOWNS(m_proxy)) {
- PyErr_SetString(PyExc_TypeError,
- "CList.reverse(): internal values can't be modified");
- return NULL;
- }
-
- std::reverse(m_pValueArray.begin(),m_pValueArray.end());
- Py_RETURN_NONE;
-}
-
-PyObject *CListValue::Pyindex(PyObject *value)
-{
- PyObject *result = NULL;
-
- CValue *checkobj = ConvertPythonToValue(value, true, "val = cList[i]: CValueList, ");
- if (checkobj==NULL)
- return NULL; /* ConvertPythonToValue sets the error */
-
- int numelem = GetCount();
- for (int i=0;i<numelem;i++)
- {
- CValue* elem = GetValue(i);
- if (checkobj==elem || CheckEqual(checkobj,elem))
- {
- result = PyLong_FromLong(i);
- break;
- }
- }
- checkobj->Release();
-
- if (result==NULL) {
- PyErr_SetString(PyExc_ValueError, "CList.index(x): x not in CListValue");
- }
- return result;
-
-}
-
-
-
-PyObject *CListValue::Pycount(PyObject *value)
-{
- int numfound = 0;
-
- CValue *checkobj = ConvertPythonToValue(value, false, ""); /* error ignored */
-
- if (checkobj==NULL) { /* in this case just return that there are no items in the list */
- PyErr_Clear();
- return PyLong_FromLong(0);
- }
-
- int numelem = GetCount();
- for (int i=0;i<numelem;i++)
- {
- CValue* elem = GetValue(i);
- if (checkobj==elem || CheckEqual(checkobj,elem))
- {
- numfound ++;
- }
- }
- checkobj->Release();
-
- return PyLong_FromLong(numfound);
-}
-
-/* Matches python dict.get(key, [default]) */
-PyObject *CListValue::Pyget(PyObject *args)
-{
- char *key;
- PyObject *def = Py_None;
-
- if (!PyArg_ParseTuple(args, "s|O:get", &key, &def))
- return NULL;
-
- CValue *item = FindValue((const char *)key);
- if (item) {
- PyObject *pyobj = item->ConvertValueToPython();
- if (pyobj)
- return pyobj;
- else
- return item->GetProxy();
- }
- Py_INCREF(def);
- return def;
-}
-
-
-PyObject *CListValue::Pyfrom_id(PyObject *value)
-{
- uintptr_t id= (uintptr_t)PyLong_AsVoidPtr(value);
-
- if (PyErr_Occurred())
- return NULL;
-
- int numelem = GetCount();
- for (int i=0;i<numelem;i++)
- {
- if (reinterpret_cast<uintptr_t>(m_pValueArray[i]->m_proxy) == id)
- return GetValue(i)->GetProxy();
- }
- PyErr_SetString(PyExc_IndexError, "from_id(#): id not found in CValueList");
- return NULL;
-
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Expressions/intern/ListWrapper.cpp b/source/gameengine/Expressions/intern/ListWrapper.cpp
deleted file mode 100644
index db1518a4388..00000000000
--- a/source/gameengine/Expressions/intern/ListWrapper.cpp
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Porteries Tristan.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file ListWrapper.cpp
- * \ingroup expressions
- */
-
-#ifdef WITH_PYTHON
-
-#include "EXP_ListWrapper.h"
-
-static STR_String pythonGeneratorList = "ListWrapper";
-
-CListWrapper::CListWrapper(void *client,
- PyObject *base,
- bool (*checkValid)(void *),
- int (*getSize)(void *),
- PyObject *(*getItem)(void *, int),
- const char *(*getItemName)(void *, int),
- bool (*setItem)(void *, int, PyObject *))
-:m_client(client),
-m_base(base),
-m_checkValid(checkValid),
-m_getSize(getSize),
-m_getItem(getItem),
-m_getItemName(getItemName),
-m_setItem(setItem)
-{
- // Incref to always have a existing pointer.
- Py_INCREF(m_base);
-}
-
-CListWrapper::~CListWrapper()
-{
- Py_DECREF(m_base);
-}
-
-bool CListWrapper::CheckValid()
-{
- if (m_base && !BGE_PROXY_REF(m_base)) {
- return false;
- }
- return m_checkValid ? (*m_checkValid)(m_client) : true;
-}
-
-int CListWrapper::GetSize()
-{
- return (*m_getSize)(m_client);
-}
-
-PyObject *CListWrapper::GetItem(int index)
-{
- return (*m_getItem)(m_client, index);
-}
-
-const char *CListWrapper::GetItemName(int index)
-{
- return (*m_getItemName)(m_client, index);
-}
-
-bool CListWrapper::SetItem(int index, PyObject *item)
-{
- return (*m_setItem)(m_client, index, item);
-}
-
-bool CListWrapper::AllowSetItem()
-{
- return m_setItem != NULL;
-}
-
-bool CListWrapper::AllowGetItemByName()
-{
- return m_getItemName != NULL;
-}
-
-// ================================================================
-
-const STR_String &CListWrapper::GetText()
-{
- return pythonGeneratorList;
-}
-
-void CListWrapper::SetName(const char *name)
-{
-}
-
-STR_String &CListWrapper::GetName()
-{
- return pythonGeneratorList;
-}
-
-CValue *CListWrapper::GetReplica()
-{
- return NULL;
-}
-
-CValue *CListWrapper::Calc(VALUE_OPERATOR op, CValue *val)
-{
- return NULL;
-}
-
-CValue *CListWrapper::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-{
- return NULL;
-}
-
-double CListWrapper::GetNumber()
-{
- return -1;
-}
-
-int CListWrapper::GetValueType()
-{
- return -1;
-}
-
-// We convert all elements to python objects to make a proper repr string.
-PyObject *CListWrapper::py_repr()
-{
- if (!CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "CListWrapper : repr, " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- PyObject *py_proxy = GetProxy();
- PyObject *py_list = PySequence_List(py_proxy);
- PyObject *py_string = PyObject_Repr(py_list);
- Py_DECREF(py_list);
- Py_DECREF(py_proxy);
- return py_string;
-}
-
-
-Py_ssize_t CListWrapper::py_len(PyObject *self)
-{
- CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self);
- // Invalid list.
- if (!list->CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "len(CListWrapper), " BGE_PROXY_ERROR_MSG);
- return 0;
- }
-
- return (Py_ssize_t)list->GetSize();
-}
-
-PyObject *CListWrapper::py_get_item(PyObject *self, Py_ssize_t index)
-{
- CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self);
- // Invalid list.
- if (!list->CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "val = CListWrapper[i], " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- int size = list->GetSize();
-
- if (index < 0) {
- index = size + index;
- }
- if (index < 0 || index >= size) {
- PyErr_SetString(PyExc_IndexError, "CListWrapper[i]: List index out of range in CListWrapper");
- return NULL;
- }
-
- PyObject *pyobj = list->GetItem(index);
-
- return pyobj;
-}
-
-int CListWrapper::py_set_item(PyObject *self, Py_ssize_t index, PyObject *value)
-{
- CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self);
- // Invalid list.
- if (!list->CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "CListWrapper[i] = val, " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (!list->AllowSetItem()) {
- PyErr_SetString(PyExc_TypeError, "CListWrapper's item type doesn't support assignment");
- return -1;
- }
-
- if (!value) {
- PyErr_SetString(PyExc_TypeError, "CListWrapper doesn't support item deletion");
- return -1;
- }
-
- int size = list->GetSize();
-
- if (index < 0) {
- index = size + index;
- }
- if (index < 0 || index >= size) {
- PyErr_SetString(PyExc_IndexError, "CListWrapper[i]: List index out of range in CListWrapper");
- return -1;
- }
-
- if (!list->SetItem(index, value)) {
- return -1;
- }
- return 0;
-}
-
-PyObject *CListWrapper::py_mapping_subscript(PyObject *self, PyObject *key)
-{
- CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self);
- // Invalid list.
- if (!list->CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "val = CListWrapper[key], " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- if (PyIndex_Check(key)) {
- Py_ssize_t index = PyLong_AsSsize_t(key);
- return py_get_item(self, index);
- }
- else if (PyUnicode_Check(key)) {
- if (!list->AllowGetItemByName()) {
- PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key");
- return NULL;
- }
-
- const char *name = _PyUnicode_AsString(key);
- int size = list->GetSize();
-
- for (unsigned int i = 0; i < size; ++i) {
- if (strcmp(list->GetItemName(i), name) == 0) {
- return list->GetItem(i);
- }
- }
-
- PyErr_Format(PyExc_KeyError, "requested item \"%s\" does not exist", name);
- return NULL;
- }
-
- PyErr_Format(PyExc_KeyError, "CListWrapper[key]: '%R' key not in list", key);
- return NULL;
-}
-
-int CListWrapper::py_mapping_ass_subscript(PyObject *self, PyObject *key, PyObject *value)
-{
- CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self);
- // Invalid list.
- if (!list->CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "val = CListWrapper[key], " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (!list->AllowSetItem()) {
- PyErr_SetString(PyExc_TypeError, "CListWrapper's item type doesn't support assignment");
- return -1;
- }
-
- if (PyIndex_Check(key)) {
- Py_ssize_t index = PyLong_AsSsize_t(key);
- return py_set_item(self, index, value);
- }
- else if (PyUnicode_Check(key)) {
- if (!list->AllowGetItemByName()) {
- PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key");
- return -1;
- }
-
- const char *name = _PyUnicode_AsString(key);
- int size = list->GetSize();
-
- for (unsigned int i = 0; i < size; ++i) {
- if (strcmp(list->GetItemName(i), name) == 0) {
- if (!list->SetItem(i, value)) {
- return -1;
- }
- return 0;
- }
- }
-
- PyErr_Format(PyExc_KeyError, "requested item \"%s\" does not exist", name);
- return -1;
- }
-
- PyErr_Format(PyExc_KeyError, "CListWrapper[key]: '%R' key not in list", key);
- return -1;
-}
-
-int CListWrapper::py_contains(PyObject *self, PyObject *key)
-{
- CListWrapper *list = (CListWrapper *)BGE_PROXY_REF(self);
- // Invalid list.
- if (!list->CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "val = CListWrapper[i], " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (!list->AllowGetItemByName()) {
- PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key");
- return -1;
- }
-
- if (!PyUnicode_Check(key)) {
- PyErr_SetString(PyExc_SystemError, "key in list, CListWrapper: key must be a string");
- return -1;
- }
-
- const char *name = _PyUnicode_AsString(key);
- int size = list->GetSize();
-
- for (unsigned int i = 0; i < size; ++i) {
- if (strcmp(list->GetItemName(i), name) == 0) {
- return 1;
- }
- }
-
- return 0;
-}
-
-PySequenceMethods CListWrapper::py_as_sequence = {
- py_len, // sq_length
- NULL, // sq_concat
- NULL, // sq_repeat
- py_get_item, // sq_item
- NULL, // sq_slice
- py_set_item, // sq_ass_item
- NULL, // sq_ass_slice
- (objobjproc)py_contains, // sq_contains
- (binaryfunc) NULL, // sq_inplace_concat
- (ssizeargfunc) NULL, // sq_inplace_repeat
-};
-
-PyMappingMethods CListWrapper::py_as_mapping = {
- py_len, // mp_length
- py_mapping_subscript, // mp_subscript
- py_mapping_ass_subscript // mp_ass_subscript
-};
-
-PyTypeObject CListWrapper::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "CListWrapper", // tp_name
- sizeof(PyObjectPlus_Proxy), // tp_basicsize
- 0, // tp_itemsize
- py_base_dealloc, // tp_dealloc
- 0, // tp_print
- 0, // tp_getattr
- 0, // tp_setattr
- 0, // tp_compare
- py_base_repr, // tp_repr
- 0, // tp_as_number
- &py_as_sequence, // tp_as_sequence
- &py_as_mapping, // tp_as_mapping
- 0, // tp_hash
- 0, // tp_call
- 0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef CListWrapper::Methods[] = {
- {"get", (PyCFunction)CListWrapper::sPyGet, METH_VARARGS},
- {NULL, NULL} //Sentinel
-};
-
-PyAttributeDef CListWrapper::Attributes[] = {
- {NULL} //Sentinel
-};
-
-/* Matches python dict.get(key, [default]) */
-PyObject *CListWrapper::PyGet(PyObject *args)
-{
- char *name;
- PyObject *def = Py_None;
-
- // Invalid list.
- if (!CheckValid()) {
- PyErr_SetString(PyExc_SystemError, "val = CListWrapper[i], " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- if (!AllowGetItemByName()) {
- PyErr_SetString(PyExc_SystemError, "CListWrapper's item type doesn't support access by key");
- return NULL;
- }
-
- if (!PyArg_ParseTuple(args, "s|O:get", &name, &def)) {
- return NULL;
- }
-
- for (unsigned int i = 0; i < GetSize(); ++i) {
- if (strcmp(GetItemName(i), name) == 0) {
- return GetItem(i);
- }
- }
-
- Py_INCREF(def);
- return def;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Expressions/intern/Operator1Expr.cpp b/source/gameengine/Expressions/intern/Operator1Expr.cpp
deleted file mode 100644
index add0376f487..00000000000
--- a/source/gameengine/Expressions/intern/Operator1Expr.cpp
+++ /dev/null
@@ -1,151 +0,0 @@
-/** \file gameengine/Expressions/Operator1Expr.cpp
- * \ingroup expressions
- */
-// Operator1Expr.cpp: implementation of the COperator1Expr class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_Operator1Expr.h"
-#include "EXP_EmptyValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-COperator1Expr::COperator1Expr()
-/*
-pre:
-effect: constucts an empty COperator1Expr
-*/
-{
- m_lhs = NULL;
-}
-
-COperator1Expr::COperator1Expr(VALUE_OPERATOR op, CExpression *lhs)
-/*
-pre:
-effect: constucts a COperator1Expr with op and lhs in it
-*/
-{
- m_lhs = lhs;
- m_op = op;
-}
-
-COperator1Expr::~COperator1Expr()
-/*
-pre:
-effect: deletes the object
-*/
-{
- if (m_lhs) m_lhs->Release();
-}
-
-CValue * COperator1Expr::Calculate()
-/*
-pre:
-ret: a new object containing the result of applying the operator m_op to the
- value of m_lhs
-*/
-{
- CValue *ret;
- CValue *temp = m_lhs->Calculate();
- CValue* empty = new CEmptyValue();
- ret = empty->Calc(m_op, temp);
- empty->Release();
- temp->Release();
-
- return ret;
-}
-
-/*
-bool COperator1Expr::IsInside(float x, float y, float z,bool bBorderInclude)
-{
-
- bool result = true;
- switch (m_op)
- {
-
- case VALUE_ADD_OPERATOR:
- {
-
- if (m_lhs)
- {
- result = result || m_lhs->IsInside(x,y,z,bBorderInclude);
- }
- break;
- }
- case VALUE_SUB_OPERATOR:
- {
- result = true;
- if (m_lhs)
- {
- result = result && (!m_lhs->IsInside(x,y,z,bBorderInclude));
- }
- break;
- }
- }
- return result;
-}
-
-*/
-bool COperator1Expr::NeedsRecalculated()
-{
- return m_lhs->NeedsRecalculated();
-}
-
-CExpression* COperator1Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks)
-{
-
- CExpression* newlhs = m_lhs->CheckLink(brokenlinks);
-
- if (newlhs)
- {
- if (newlhs==m_lhs) {
- // not changed
- } else {
- // changed
- //numchanges++;
- newlhs->AddRef();
-
- //m_lhs->Release();
- brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs));
-
- m_lhs = newlhs;
- }
- return this;
- } else {
- //numchanges++;
- AddRef();
-
- return Release();
- }
-
-}
-
-void COperator1Expr::BroadcastOperators(VALUE_OPERATOR op)
-{
- if (m_lhs)
- m_lhs->BroadcastOperators(m_op);
-}
-
-
-
-
-bool COperator1Expr::MergeExpression(CExpression *otherexpr)
-{
- if (m_lhs)
- return m_lhs->MergeExpression(otherexpr);
-
- assertd(false); // should not get here, expression is not compatible for merge
- return false;
-}
diff --git a/source/gameengine/Expressions/intern/Operator2Expr.cpp b/source/gameengine/Expressions/intern/Operator2Expr.cpp
deleted file mode 100644
index 0a7f30b8cc8..00000000000
--- a/source/gameengine/Expressions/intern/Operator2Expr.cpp
+++ /dev/null
@@ -1,276 +0,0 @@
-/** \file gameengine/Expressions/Operator2Expr.cpp
- * \ingroup expressions
- */
-// Operator2Expr.cpp: implementation of the COperator2Expr class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-// 31 dec 1998 - big update: try to use the cached data for updating, instead of
-// rebuilding completely it from left and right node. Modified flags and bounding boxes
-// have to do the trick
-// when expression is cached, there will be a call to UpdateCalc() instead of Calc()
-
-#include "EXP_Operator2Expr.h"
-#include "EXP_StringValue.h"
-#include "EXP_VoidValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-COperator2Expr::COperator2Expr(VALUE_OPERATOR op, CExpression *lhs, CExpression *rhs)
-:
-m_rhs(rhs),
-m_lhs(lhs),
-m_cached_calculate(NULL),
-m_op(op)
-/*
-pre:
-effect: constucts a COperator2Expr with op, lhs and rhs in it
-*/
-{
-
-}
-
-COperator2Expr::COperator2Expr():
-m_rhs(NULL),
-m_lhs(NULL),
-m_cached_calculate(NULL)
-
-/*
-pre:
-effect: constucts an empty COperator2Expr
-*/
-{
-
-}
-
-COperator2Expr::~COperator2Expr()
-/*
-pre:
-effect: deletes the object
-*/
-{
- if (m_lhs)
- m_lhs->Release();
- if (m_rhs)
- m_rhs->Release();
- if (m_cached_calculate)
- m_cached_calculate->Release();
-
-}
-CValue* COperator2Expr::Calculate()
-/*
-pre:
-ret: a new object containing the result of applying operator m_op to m_lhs
-and m_rhs
-*/
-{
-
- bool leftmodified,rightmodified;
- leftmodified = m_lhs->NeedsRecalculated();
- rightmodified = m_rhs->NeedsRecalculated();
-
- // if no modifications on both left and right subtree, and result is already calculated
- // then just return cached result...
- if (!leftmodified && !rightmodified && (m_cached_calculate))
- {
- // not modified, just return m_cached_calculate
- } else {
- // if not yet calculated, or modified...
-
-
- if (m_cached_calculate) {
- m_cached_calculate->Release();
- m_cached_calculate=NULL;
- }
-
- CValue* ffleft = m_lhs->Calculate();
- CValue* ffright = m_rhs->Calculate();
-
- ffleft->SetOwnerExpression(this);//->m_pOwnerExpression=this;
- ffright->SetOwnerExpression(this);//->m_pOwnerExpression=this;
-
- m_cached_calculate = ffleft->Calc(m_op,ffright);
-
- //if (m_cached_calculate)
- // m_cached_calculate->Action(CValue::SETOWNEREXPR,&CVoidValue(this,false,CValue::STACKVALUE));
-
- ffleft->Release();
- ffright->Release();
- }
-
- return m_cached_calculate->AddRef();
-
-}
-
-#if 0
-bool COperator2Expr::IsInside(float x, float y, float z,bool bBorderInclude)
-{
- bool inside;
- inside = false;
-
- switch (m_op) {
- case VALUE_ADD_OPERATOR:
- {
- // inside = first || second; // optimized with early out if first is inside
- // todo: calculate smallest leaf first ! is much faster...
-
- bool second;//first ;//,second;
-
- //first = m_lhs->IsInside(x,y,z);
- second = m_rhs->IsInside(x,y,z,bBorderInclude);
- if (second)
- return true; //early out
-
- // second = m_rhs->IsInside(x,y,z);
-
- return m_lhs->IsInside(x,y,z,bBorderInclude);
-
- break;
- }
-
- case VALUE_SUB_OPERATOR:
- {
- //inside = first && !second; // optimized with early out
- // todo: same as with add_operator: calc smallest leaf first
-
- bool second;//first ;//,second;
- //first = m_lhs->IsInside(x,y,z);
- second = m_rhs->IsInside(x,y,z,bBorderInclude);
- if (second)
- return false;
-
- // second space get subtracted -> negate!
- //second = m_rhs->IsInside(x,y,z);
-
- return (m_lhs->IsInside(x,y,z,bBorderInclude));
-
-
- break;
- }
- default:
- {
- assert(false);
- // not yet implemented, only add or sub csg operations
- }
- }
-
- return inside;
-}
-
-bool COperator2Expr::IsRightInside(float x, float y, float z,bool bBorderInclude)
-{
- return m_rhs->IsInside(x,y,z,bBorderInclude);
-}
-
-bool COperator2Expr::IsLeftInside(float x, float y, float z,bool bBorderInclude)
-{
- return m_lhs->IsInside(x,y,z,bBorderInclude);
-}
-#endif
-
-bool COperator2Expr::NeedsRecalculated()
-{
- // added some lines, just for debugging purposes, it could be a one-liner :)
- //bool modleft
- //bool modright;
- assertd(m_lhs);
- assertd(m_rhs);
-
- //modright = m_rhs->NeedsRecalculated();
- if (m_rhs->NeedsRecalculated()) // early out
- return true;
- return m_lhs->NeedsRecalculated();
- //modleft = m_lhs->NeedsRecalculated();
- //return (modleft || modright);
-
-}
-
-
-
-CExpression* COperator2Expr::CheckLink(std::vector<CBrokenLinkInfo*>& brokenlinks)
-{
-// if both children are 'dead', return NULL
-// if only one child is alive, return that child
-// if both childresn are alive, return this
-
-
-// bool leftalive = true,rightalive=true;
- /* Does this mean the function will always bomb? */
- assertd(false);
- assert(m_lhs);
- assert(m_rhs);
-/*
- if (m_cached_calculate)
- m_cached_calculate->Action(CValue::REFRESH_CACHE);
-
- CExpression* newlhs = m_lhs->CheckLink(brokenlinks);
- CExpression* newrhs = m_rhs->CheckLink(brokenlinks);
-
- if (m_lhs != newlhs)
- {
- brokenlinks.push_back(new CBrokenLinkInfo(&m_lhs,m_lhs));
- }
-
- if (m_rhs != newrhs)
- {
- brokenlinks.push_back(new CBrokenLinkInfo(&m_rhs,m_rhs));
- }
-
-
-
- m_lhs = newlhs;
- m_rhs = newrhs;
-
- if (m_lhs && m_rhs) {
- return this;
- }
-
- AddRef();
- if (m_lhs)
- return Release(m_lhs->AddRef());
-
- if (m_rhs)
- return Release(m_rhs->AddRef());
-/
-
- */
- return Release();
-}
-
-
-bool COperator2Expr::MergeExpression(CExpression *otherexpr)
-{
- if (m_lhs)
- {
- if (m_lhs->GetExpressionID() == CExpression::CCONSTEXPRESSIONID)
- {
- // cross fingers ;) replace constexpr by new tree...
- m_lhs->Release();
- m_lhs = otherexpr->AddRef();
- return true;
- }
- }
-
- assertd(false);
- return false;
-}
-
-
-void COperator2Expr::BroadcastOperators(VALUE_OPERATOR op)
-{
- if (m_lhs)
- m_lhs->BroadcastOperators(m_op);
- if (m_rhs)
- m_rhs->BroadcastOperators(m_op);
-}
diff --git a/source/gameengine/Expressions/intern/PyObjectPlus.cpp b/source/gameengine/Expressions/intern/PyObjectPlus.cpp
deleted file mode 100644
index 1e4a59aeb5c..00000000000
--- a/source/gameengine/Expressions/intern/PyObjectPlus.cpp
+++ /dev/null
@@ -1,1226 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Expressions/PyObjectPlus.cpp
- * \ingroup expressions
- */
-
-
-/*------------------------------
- * PyObjectPlus cpp
- *
- * C++ library routines for Crawl 3.2
- *
- * Derived from work by
- * David Redish
- * graduate student
- * Computer Science Department
- * Carnegie Mellon University (CMU)
- * Center for the Neural Basis of Cognition (CNBC)
- * http://www.python.org/doc/PyCPP.html
- *
- * ----------------------------- */
-#include <stdlib.h>
-#include <stddef.h>
-
-#include "EXP_PyObjectPlus.h"
-#include "STR_String.h"
-#include "MT_Vector3.h"
-#include "MEM_guardedalloc.h"
-
-PyObjectPlus::~PyObjectPlus()
-{
-#ifdef WITH_PYTHON
- if (m_proxy) {
- BGE_PROXY_REF(m_proxy)= NULL;
- Py_DECREF(m_proxy); /* Remove own reference, python may still have 1 */
- }
-// assert(ob_refcnt==0);
-#endif
-}
-
-PyObjectPlus::PyObjectPlus() : SG_QList() // constructor
-{
-#ifdef WITH_PYTHON
- m_proxy= NULL;
-#endif
-};
-
-void PyObjectPlus::ProcessReplica()
-{
-#ifdef WITH_PYTHON
- /* Clear the proxy, will be created again if needed with GetProxy()
- * otherwise the PyObject will point to the wrong reference */
- m_proxy= NULL;
-#endif
-}
-
-/* Sometimes we might want to manually invalidate a BGE type even if
- * it hasn't been released by the BGE, say for example when an object
- * is removed from a scene, accessing it may cause problems.
- *
- * In this case the current proxy is made invalid, disowned,
- * and will raise an error on access. However if python can get access
- * to this class again it will make a new proxy and work as expected.
- */
-void PyObjectPlus::InvalidateProxy() // check typename of each parent
-{
-#ifdef WITH_PYTHON
- if (m_proxy) {
- BGE_PROXY_REF(m_proxy)=NULL;
- Py_DECREF(m_proxy);
- m_proxy= NULL;
- }
-#endif
-}
-
-
-#ifdef WITH_PYTHON
-
-/*------------------------------
- * PyObjectPlus Type -- Every class, even the abstract one should have a Type
- * ----------------------------- */
-
-
-PyTypeObject PyObjectPlus::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "PyObjectPlus", /*tp_name*/
- sizeof(PyObjectPlus_Proxy), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- py_base_dealloc, /* tp_dealloc */
- 0, /* printfunc tp_print; */
- 0, /* getattrfunc tp_getattr; */
- 0, /* setattrfunc tp_setattr; */
- 0, /* tp_compare */ /* DEPRECATED in python 3.0! */
- py_base_repr, /* tp_repr */
- 0, 0, 0, 0, 0, 0, 0, 0, 0, /* Method suites for standard classes */
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /* long tp_flags; */
- 0, 0, 0, 0,
- /* weak reference enabler */
-#ifdef USE_WEAKREFS
- offsetof(PyObjectPlus_Proxy, in_weakreflist), /* long tp_weaklistoffset; */
-#else
- 0,
-#endif
- 0, 0,
- Methods,
- 0,
- 0,
- NULL // no subtype
-};
-
-PyObject *PyObjectPlus::py_base_repr(PyObject *self) // This should be the entry in Type.
-{
- PyObjectPlus *self_plus= BGE_PROXY_REF(self);
- if (self_plus==NULL) {
- PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG);
- return NULL;
- }
- return self_plus->py_repr();
-}
-
-
-PyObject *PyObjectPlus::py_base_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PyTypeObject *base_type;
-
- /* one or more args is needed */
- if (!PyTuple_GET_SIZE(args)) {
- PyErr_SetString(PyExc_TypeError,
- "Expected at least one argument");
- return NULL;
- }
-
- PyObjectPlus_Proxy *base = (PyObjectPlus_Proxy *)PyTuple_GET_ITEM(args, 0);
-
- /**
- * the 'base' PyObject may be subclassed (multiple times even)
- * we need to find the first C++ defined class to check 'type'
- * is a subclass of the base arguments type.
- *
- * This way we can share one tp_new function for every PyObjectPlus
- *
- * eg.
- *
- * # CustomOb is called 'type' in this C code
- * \code{.py}
- * class CustomOb(GameTypes.KX_GameObject):
- * pass
- *
- * # this calls py_base_new(...), the type of 'CustomOb' is checked to be a subclass of the 'cont.owner' type
- * ob = CustomOb(cont.owner)
- * \endcode
- * */
- base_type= Py_TYPE(base);
- while (base_type && !BGE_PROXY_CHECK_TYPE(base_type))
- base_type= base_type->tp_base;
-
- if (base_type==NULL || !BGE_PROXY_CHECK_TYPE(base_type)) {
- PyErr_SetString(PyExc_TypeError, "can't subclass from a blender game type because the argument given is not a game class or subclass");
- return NULL;
- }
-
- /* use base_type rather than Py_TYPE(base) because we could already be subtyped */
- if (!PyType_IsSubtype(type, base_type)) {
- PyErr_Format(PyExc_TypeError, "can't subclass blender game type <%s> from <%s> because it is not a subclass", base_type->tp_name, type->tp_name);
- return NULL;
- }
-
- /* invalidate the existing base and return a new subclassed one,
- * this is a bit dodgy in that it also attaches its self to the existing object
- * which is not really 'correct' python OO but for our use its OK. */
-
- PyObjectPlus_Proxy *ret = (PyObjectPlus_Proxy *) type->tp_alloc(type, 0); /* starts with 1 ref, used for the return ref' */
- ret->ref= base->ref;
- ret->ptr= base->ptr;
- ret->py_owns= base->py_owns;
- ret->py_ref = base->py_ref;
-
- if (ret->py_ref) {
- base->ref= NULL; /* invalidate! disallow further access */
- base->ptr = NULL;
- if (ret->ref)
- ret->ref->m_proxy= NULL;
- /* 'base' may be freed after this func finished but not necessarily
- * there is no reference to the BGE data now so it will throw an error on access */
- Py_DECREF(base);
- if (ret->ref) {
- ret->ref->m_proxy= (PyObject *)ret; /* no need to add a ref because one is added when creating. */
- Py_INCREF(ret); /* we return a new ref but m_proxy holds a ref so we need to add one */
- }
- } else {
- // generic structures don't hold a reference to this proxy, so don't increment ref count
- if (ret->py_owns)
- // but if the proxy owns the structure, there can be only one owner
- base->ptr= NULL;
- }
-
- return (PyObject *)ret;
-}
-
-/**
- * \param self A PyObjectPlus_Proxy
- */
-void PyObjectPlus::py_base_dealloc(PyObject *self) // python wrapper
-{
-#ifdef USE_WEAKREFS
- if (BGE_PROXY_WKREF(self) != NULL)
- PyObject_ClearWeakRefs((PyObject *) self);
-#endif
-
- if (BGE_PROXY_PYREF(self)) {
- PyObjectPlus *self_plus= BGE_PROXY_REF(self);
- if (self_plus) {
- if (BGE_PROXY_PYOWNS(self)) { /* Does python own this?, then delete it */
- self_plus->m_proxy = NULL; /* Need this to stop ~PyObjectPlus from decrefing m_proxy otherwise its decref'd twice and py-debug crashes */
- delete self_plus;
- }
- BGE_PROXY_REF(self)= NULL; // not really needed
- }
- // the generic pointer is not deleted directly, only through self_plus
- BGE_PROXY_PTR(self)= NULL; // not really needed
- } else {
- void *ptr= BGE_PROXY_PTR(self);
- if (ptr) {
- if (BGE_PROXY_PYOWNS(self)) { /* Does python own this?, then delete it */
- // generic structure owned by python MUST be created though MEM_alloc
- MEM_freeN(ptr);
- }
- BGE_PROXY_PTR(self)= NULL; // not really needed
- }
- }
-#if 0
- /* is ok normally but not for subtyping, use tp_free instead. */
- PyObject_DEL( self );
-#else
- Py_TYPE(self)->tp_free(self);
-#endif
-};
-
-/*------------------------------
- * PyObjectPlus Methods -- Every class, even the abstract one should have a Methods
-------------------------------*/
-PyMethodDef PyObjectPlus::Methods[] = {
- {NULL, NULL} /* Sentinel */
-};
-
-#define BGE_PY_ATTR_INVALID (&(PyObjectPlus::Attributes[0]))
-PyAttributeDef PyObjectPlus::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("invalid", PyObjectPlus, pyattr_get_invalid),
- {NULL} //Sentinel
-};
-
-
-
-PyObject *PyObjectPlus::pyattr_get_invalid(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return PyBool_FromLong(self_v ? 0:1);
-}
-
-/* note, this is called as a python 'getset, where the PyAttributeDef is the closure */
-PyObject *PyObjectPlus::py_get_attrdef(PyObject *self_py, const PyAttributeDef *attrdef)
-{
- PyObjectPlus *ref= (BGE_PROXY_REF(self_py));
- char* ptr = (attrdef->m_usePtr) ? (char*)BGE_PROXY_PTR(self_py) : (char*)ref;
- if (ptr == NULL || (BGE_PROXY_PYREF(self_py) && (ref==NULL || !ref->py_is_valid()))) {
- if (attrdef == BGE_PY_ATTR_INVALID)
- Py_RETURN_TRUE; // don't bother running the function
-
- PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_DUMMY)
- {
- // fake attribute, ignore
- return NULL;
- }
- if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION)
- {
- // the attribute has no field correspondence, handover processing to function.
- if (attrdef->m_getFunction == NULL)
- return NULL;
- return (*attrdef->m_getFunction)(ptr, attrdef);
- }
- ptr += attrdef->m_offset;
- if (attrdef->m_length > 1)
- {
- PyObject *resultlist = PyList_New(attrdef->m_length);
- for (unsigned int i=0; i<attrdef->m_length; i++)
- {
- switch (attrdef->m_type) {
- case KX_PYATTRIBUTE_TYPE_BOOL:
- {
- bool *val = reinterpret_cast<bool*>(ptr);
- ptr += sizeof(bool);
- PyList_SET_ITEM(resultlist, i, PyBool_FromLong(*val));
- break;
- }
- case KX_PYATTRIBUTE_TYPE_SHORT:
- {
- short int *val = reinterpret_cast<short int*>(ptr);
- ptr += sizeof(short int);
- PyList_SET_ITEM(resultlist, i, PyLong_FromLong(*val));
- break;
- }
- case KX_PYATTRIBUTE_TYPE_ENUM:
- // enum are like int, just make sure the field size is the same
- if (sizeof(int) != attrdef->m_size)
- {
- Py_DECREF(resultlist);
- return NULL;
- }
- ATTR_FALLTHROUGH;
- case KX_PYATTRIBUTE_TYPE_INT:
- {
- int *val = reinterpret_cast<int*>(ptr);
- ptr += sizeof(int);
- PyList_SET_ITEM(resultlist, i, PyLong_FromLong(*val));
- break;
- }
- case KX_PYATTRIBUTE_TYPE_FLOAT:
- {
- float *val = reinterpret_cast<float*>(ptr);
- ptr += sizeof(float);
- PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble(*val));
- break;
- }
- default:
- // no support for array of complex data
- Py_DECREF(resultlist);
- return NULL;
- }
- }
- return resultlist;
- }
- else
- {
- switch (attrdef->m_type) {
- case KX_PYATTRIBUTE_TYPE_FLAG:
- {
- bool bval;
- switch (attrdef->m_size) {
- case 1:
- {
- unsigned char *val = reinterpret_cast<unsigned char*>(ptr);
- bval = (*val & attrdef->m_imin);
- break;
- }
- case 2:
- {
- unsigned short *val = reinterpret_cast<unsigned short*>(ptr);
- bval = (*val & attrdef->m_imin);
- break;
- }
- case 4:
- {
- unsigned int *val = reinterpret_cast<unsigned int*>(ptr);
- bval = (*val & attrdef->m_imin);
- break;
- }
- default:
- return NULL;
- }
- if (attrdef->m_imax)
- bval = !bval;
- return PyBool_FromLong(bval);
- }
- case KX_PYATTRIBUTE_TYPE_BOOL:
- {
- bool *val = reinterpret_cast<bool*>(ptr);
- return PyBool_FromLong(*val);
- }
- case KX_PYATTRIBUTE_TYPE_SHORT:
- {
- short int *val = reinterpret_cast<short int*>(ptr);
- return PyLong_FromLong(*val);
- }
- case KX_PYATTRIBUTE_TYPE_ENUM:
- // enum are like int, just make sure the field size is the same
- if (sizeof(int) != attrdef->m_size)
- {
- return NULL;
- }
- ATTR_FALLTHROUGH;
- case KX_PYATTRIBUTE_TYPE_INT:
- {
- int *val = reinterpret_cast<int*>(ptr);
- return PyLong_FromLong(*val);
- }
- case KX_PYATTRIBUTE_TYPE_FLOAT:
- {
- float *val = reinterpret_cast<float*>(ptr);
- if (attrdef->m_imin == 0) {
- if (attrdef->m_imax == 0) {
- return PyFloat_FromDouble(*val);
- } else {
- // vector, verify size
- if (attrdef->m_size != attrdef->m_imax*sizeof(float))
- {
- return NULL;
- }
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject(val, attrdef->m_imax, NULL);
-#else
- PyObject *resultlist = PyList_New(attrdef->m_imax);
- for (unsigned int i=0; i<attrdef->m_imax; i++)
- {
- PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble(val[i]));
- }
- return resultlist;
-#endif
- }
- } else {
- // matrix case
- if (attrdef->m_size != attrdef->m_imax*attrdef->m_imin*sizeof(float))
- {
- return NULL;
- }
-#ifdef USE_MATHUTILS
- return Matrix_CreatePyObject_wrap(val, attrdef->m_imin, attrdef->m_imax, NULL);
-#else
- PyObject *collist = PyList_New(attrdef->m_imin);
- for (unsigned int i=0; i<attrdef->m_imin; i++)
- {
- PyObject *col = PyList_New(attrdef->m_imax);
- for (unsigned int j=0; j<attrdef->m_imax; j++)
- {
- PyList_SET_ITEM(col, j, PyFloat_FromDouble(val[j]));
- }
- PyList_SET_ITEM(collist, i, col);
- val += attrdef->m_imax;
- }
- return collist;
-#endif
- }
- }
- case KX_PYATTRIBUTE_TYPE_VECTOR:
- {
- MT_Vector3 *val = reinterpret_cast<MT_Vector3*>(ptr);
-#ifdef USE_MATHUTILS
- float fval[3];
- val->getValue(fval);
- return Vector_CreatePyObject(fval, 3, NULL);
-#else
- PyObject *resultlist = PyList_New(3);
- for (unsigned int i=0; i<3; i++)
- {
- PyList_SET_ITEM(resultlist, i, PyFloat_FromDouble((*val)[i]));
- }
- return resultlist;
-#endif
- }
- case KX_PYATTRIBUTE_TYPE_STRING:
- {
- STR_String *val = reinterpret_cast<STR_String*>(ptr);
- return PyUnicode_From_STR_String(*val);
- }
- case KX_PYATTRIBUTE_TYPE_CHAR:
- {
- return PyUnicode_FromString(ptr);
- }
- default:
- return NULL;
- }
- }
-}
-
-
-static bool py_check_attr_float(float *var, PyObject *value, const PyAttributeDef *attrdef)
-{
- float val = PyFloat_AsDouble(value);
- if (val == -1.0f && PyErr_Occurred())
- {
- PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
- return false;
- }
- if (attrdef->m_clamp)
- {
- if (val < attrdef->m_fmin)
- val = attrdef->m_fmin;
- else if (val > attrdef->m_fmax)
- val = attrdef->m_fmax;
- }
- else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
- {
- PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name);
- return false;
- }
- *var = (float)val;
- return true;
-}
-
-/* note, this is called as a python getset */
-int PyObjectPlus::py_set_attrdef(PyObject *self_py, PyObject *value, const PyAttributeDef *attrdef)
-{
- PyObjectPlus *ref= (BGE_PROXY_REF(self_py));
- char* ptr = (attrdef->m_usePtr) ? (char*)BGE_PROXY_PTR(self_py) : (char*)ref;
- if (ref==NULL || !ref->py_is_valid() || ptr==NULL) {
- PyErr_SetString(PyExc_SystemError, BGE_PROXY_ERROR_MSG);
- return PY_SET_ATTR_FAIL;
- }
-
- void *undoBuffer = NULL;
- void *sourceBuffer = NULL;
- size_t bufferSize = 0;
- PyObject *item = NULL; // to store object that must be dereferenced in case of error
- PyObject *list = NULL; // to store object that must be dereferenced in case of error
-
- ptr += attrdef->m_offset;
- if (attrdef->m_length > 1)
- {
- if (!PySequence_Check(value))
- {
- PyErr_Format(PyExc_TypeError, "expected a sequence for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
- if (PySequence_Size(value) != attrdef->m_length)
- {
- PyErr_Format(PyExc_TypeError, "incorrect number of elements in sequence for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
- switch (attrdef->m_type)
- {
- case KX_PYATTRIBUTE_TYPE_FUNCTION:
- if (attrdef->m_setFunction == NULL)
- {
- PyErr_Format(PyExc_AttributeError, "function attribute without function for attribute \"%s\", report to blender.org", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
- return (*attrdef->m_setFunction)(ref, attrdef, value);
- case KX_PYATTRIBUTE_TYPE_BOOL:
- bufferSize = sizeof(bool);
- break;
- case KX_PYATTRIBUTE_TYPE_SHORT:
- bufferSize = sizeof(short int);
- break;
- case KX_PYATTRIBUTE_TYPE_ENUM:
- case KX_PYATTRIBUTE_TYPE_INT:
- bufferSize = sizeof(int);
- break;
- case KX_PYATTRIBUTE_TYPE_FLOAT:
- bufferSize = sizeof(float);
- break;
- default:
- // should not happen
- PyErr_Format(PyExc_AttributeError, "Unsupported attribute type for attribute \"%s\", report to blender.org", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
- // let's implement a smart undo method
- bufferSize *= attrdef->m_length;
- undoBuffer = malloc(bufferSize);
- sourceBuffer = ptr;
- if (undoBuffer)
- {
- memcpy(undoBuffer, sourceBuffer, bufferSize);
- }
- for (int i=0; i<attrdef->m_length; i++)
- {
- item = PySequence_GetItem(value, i); /* new ref */
- switch (attrdef->m_type)
- {
- case KX_PYATTRIBUTE_TYPE_BOOL:
- {
- bool *var = reinterpret_cast<bool*>(ptr);
- ptr += sizeof(bool);
- if (PyLong_Check(item))
- {
- *var = (PyLong_AsLong(item) != 0);
- }
- else if (PyBool_Check(item))
- {
- *var = (item == Py_True);
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_SHORT:
- {
- short int *var = reinterpret_cast<short int*>(ptr);
- ptr += sizeof(short int);
- if (PyLong_Check(item))
- {
- int val = PyLong_AsLong(item);
- if (attrdef->m_clamp)
- {
- if (val < attrdef->m_imin)
- val = attrdef->m_imin;
- else if (val > attrdef->m_imax)
- val = attrdef->m_imax;
- }
- else if (val < attrdef->m_imin || val > attrdef->m_imax)
- {
- PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- *var = (short int)val;
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_ENUM:
- // enum are equivalent to int, just make sure that the field size matches:
- if (sizeof(int) != attrdef->m_size)
- {
- PyErr_Format(PyExc_AttributeError, "Size check error for attribute, \"%s\", report to blender.org", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- ATTR_FALLTHROUGH;
- case KX_PYATTRIBUTE_TYPE_INT:
- {
- int *var = reinterpret_cast<int*>(ptr);
- ptr += sizeof(int);
- if (PyLong_Check(item))
- {
- int val = PyLong_AsLong(item);
- if (attrdef->m_clamp)
- {
- if (val < attrdef->m_imin)
- val = attrdef->m_imin;
- else if (val > attrdef->m_imax)
- val = attrdef->m_imax;
- }
- else if (val < attrdef->m_imin || val > attrdef->m_imax)
- {
- PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- *var = (int)val;
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_FLOAT:
- {
- float *var = reinterpret_cast<float*>(ptr);
- ptr += sizeof(float);
- float val = PyFloat_AsDouble(item);
- if (val == -1.0f && PyErr_Occurred())
- {
- PyErr_Format(PyExc_TypeError, "expected a float for attribute \"%s\"", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- else if (attrdef->m_clamp)
- {
- if (val < attrdef->m_fmin)
- val = attrdef->m_fmin;
- else if (val > attrdef->m_fmax)
- val = attrdef->m_fmax;
- }
- else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
- {
- PyErr_Format(PyExc_ValueError, "item value out of range for attribute \"%s\"", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- *var = (float)val;
- break;
- }
- default:
- // should not happen
- PyErr_Format(PyExc_AttributeError, "type check error for attribute \"%s\", report to blender.org", attrdef->m_name);
- goto UNDO_AND_ERROR;
- }
- // finished using item, release
- Py_DECREF(item);
- item = NULL;
- }
- // no error, call check function if any
- if (attrdef->m_checkFunction != NULL)
- {
- if ((*attrdef->m_checkFunction)(ref, attrdef) != 0)
- {
- // if the checing function didnt set an error then set a generic one here so we don't set an error with no exception
- if (PyErr_Occurred()==0)
- PyErr_Format(PyExc_AttributeError, "type check error for attribute \"%s\", reasion unknown", attrdef->m_name);
-
- // post check returned an error, restore values
- UNDO_AND_ERROR:
- if (undoBuffer)
- {
- memcpy(sourceBuffer, undoBuffer, bufferSize);
- free(undoBuffer);
- }
- if (item)
- Py_DECREF(item);
- return PY_SET_ATTR_FAIL;
- }
- }
- if (undoBuffer)
- free(undoBuffer);
- return PY_SET_ATTR_SUCCESS;
- }
- else // simple attribute value
- {
- if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_FUNCTION)
- {
- if (attrdef->m_setFunction == NULL)
- {
- PyErr_Format(PyExc_AttributeError, "function attribute without function \"%s\", report to blender.org", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
- return (*attrdef->m_setFunction)(ref, attrdef, value);
- }
- if (attrdef->m_checkFunction != NULL || attrdef->m_type == KX_PYATTRIBUTE_TYPE_VECTOR)
- {
- // post check function is provided, prepare undo buffer
- sourceBuffer = ptr;
- switch (attrdef->m_type)
- {
- case KX_PYATTRIBUTE_TYPE_BOOL:
- bufferSize = sizeof(bool);
- break;
- case KX_PYATTRIBUTE_TYPE_SHORT:
- bufferSize = sizeof(short);
- break;
- case KX_PYATTRIBUTE_TYPE_ENUM:
- case KX_PYATTRIBUTE_TYPE_FLAG:
- case KX_PYATTRIBUTE_TYPE_CHAR:
- bufferSize = attrdef->m_size;
- break;
- case KX_PYATTRIBUTE_TYPE_INT:
- bufferSize = sizeof(int);
- break;
- case KX_PYATTRIBUTE_TYPE_FLOAT:
- bufferSize = sizeof(float);
- if (attrdef->m_imax)
- bufferSize *= attrdef->m_imax;
- if (attrdef->m_imin)
- bufferSize *= attrdef->m_imin;
- break;
- case KX_PYATTRIBUTE_TYPE_STRING:
- sourceBuffer = reinterpret_cast<STR_String*>(ptr)->Ptr();
- if (sourceBuffer)
- bufferSize = strlen(reinterpret_cast<char*>(sourceBuffer))+1;
- break;
- case KX_PYATTRIBUTE_TYPE_VECTOR:
- bufferSize = sizeof(MT_Vector3);
- break;
- default:
- PyErr_Format(PyExc_AttributeError, "unknown type for attribute \"%s\", report to blender.org", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
- if (bufferSize)
- {
- undoBuffer = malloc(bufferSize);
- if (undoBuffer)
- {
- memcpy(undoBuffer, sourceBuffer, bufferSize);
- }
- }
- }
-
- switch (attrdef->m_type)
- {
- case KX_PYATTRIBUTE_TYPE_BOOL:
- {
- bool *var = reinterpret_cast<bool*>(ptr);
- if (PyLong_Check(value))
- {
- *var = (PyLong_AsLong(value) != 0);
- }
- else if (PyBool_Check(value))
- {
- *var = (value == Py_True);
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_FLAG:
- {
- bool bval;
- if (PyLong_Check(value))
- {
- bval = (PyLong_AsLong(value) != 0);
- }
- else if (PyBool_Check(value))
- {
- bval = (value == Py_True);
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected an integer or a bool for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- if (attrdef->m_imax)
- bval = !bval;
- switch (attrdef->m_size) {
- case 1:
- {
- unsigned char *val = reinterpret_cast<unsigned char*>(ptr);
- *val = (*val & ~attrdef->m_imin) | ((bval)?attrdef->m_imin:0);
- break;
- }
- case 2:
- {
- unsigned short *val = reinterpret_cast<unsigned short*>(ptr);
- *val = (*val & ~attrdef->m_imin) | ((bval)?attrdef->m_imin:0);
- break;
- }
- case 4:
- {
- unsigned int *val = reinterpret_cast<unsigned int*>(ptr);
- *val = (*val & ~attrdef->m_imin) | ((bval)?attrdef->m_imin:0);
- break;
- }
- default:
- PyErr_Format(PyExc_TypeError, "internal error: unsupported flag field \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_SHORT:
- {
- short int *var = reinterpret_cast<short int*>(ptr);
- if (PyLong_Check(value))
- {
- int val = PyLong_AsLong(value);
- if (attrdef->m_clamp)
- {
- if (val < attrdef->m_imin)
- val = attrdef->m_imin;
- else if (val > attrdef->m_imax)
- val = attrdef->m_imax;
- }
- else if (val < attrdef->m_imin || val > attrdef->m_imax)
- {
- PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- *var = (short int)val;
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_ENUM:
- // enum are equivalent to int, just make sure that the field size matches:
- if (sizeof(int) != attrdef->m_size)
- {
- PyErr_Format(PyExc_AttributeError, "attribute size check error for attribute \"%s\", report to blender.org", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- ATTR_FALLTHROUGH;
- case KX_PYATTRIBUTE_TYPE_INT:
- {
- int *var = reinterpret_cast<int*>(ptr);
- if (PyLong_Check(value))
- {
- int val = PyLong_AsLong(value);
- if (attrdef->m_clamp)
- {
- if (val < attrdef->m_imin)
- val = attrdef->m_imin;
- else if (val > attrdef->m_imax)
- val = attrdef->m_imax;
- }
- else if (val < attrdef->m_imin || val > attrdef->m_imax)
- {
- PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- *var = (int)val;
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_FLOAT:
- {
- float *var = reinterpret_cast<float*>(ptr);
- if (attrdef->m_imin != 0)
- {
- if (attrdef->m_size != attrdef->m_imin*attrdef->m_imax*sizeof(float))
- {
- PyErr_Format(PyExc_TypeError, "internal error: incorrect field size for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- if (!PySequence_Check(value) || PySequence_Size(value) != attrdef->m_imin)
- {
- PyErr_Format(PyExc_TypeError, "expected a sequence of [%d][%d] floats for attribute \"%s\"", attrdef->m_imin, attrdef->m_imax, attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- for (int i=0; i<attrdef->m_imin; i++)
- {
- PyObject *list = PySequence_GetItem(value, i); /* new ref */
- if (!PySequence_Check(list) || PySequence_Size(list) != attrdef->m_imax)
- {
- PyErr_Format(PyExc_TypeError, "expected a sequence of [%d][%d] floats for attribute \"%s\"", attrdef->m_imin, attrdef->m_imax, attrdef->m_name);
- goto RESTORE_AND_ERROR;
- }
- for (int j=0; j<attrdef->m_imax; j++)
- {
- item = PySequence_GetItem(list, j); /* new ref */
- if (!py_check_attr_float(var, item, attrdef))
- {
- PyErr_Format(PyExc_TypeError, "expected a sequence of [%d][%d] floats for attribute \"%s\"", attrdef->m_imin, attrdef->m_imax, attrdef->m_name);
- goto RESTORE_AND_ERROR;
- }
- Py_DECREF(item);
- item = NULL;
- ++var;
- }
- Py_DECREF(list);
- list = NULL;
- }
- }
- else if (attrdef->m_imax != 0)
- {
- if (attrdef->m_size != attrdef->m_imax*sizeof(float))
- {
- PyErr_Format(PyExc_TypeError, "internal error: incorrect field size for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- if (!PySequence_Check(value) || PySequence_Size(value) != attrdef->m_imax)
- {
- PyErr_Format(PyExc_TypeError, "expected a sequence of [%d] floats for attribute \"%s\"", attrdef->m_imax, attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- for (int i=0; i<attrdef->m_imax; i++)
- {
- item = PySequence_GetItem(value, i); /* new ref */
- if (!py_check_attr_float(var, item, attrdef))
- {
- goto RESTORE_AND_ERROR;
- }
- Py_DECREF(item);
- item = NULL;
- ++var;
- }
- }
- else
- {
- if (!py_check_attr_float(var, value, attrdef))
- goto FREE_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_VECTOR:
- {
- if (!PySequence_Check(value) || PySequence_Size(value) != 3)
- {
- PyErr_Format(PyExc_TypeError, "expected a sequence of 3 floats for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- MT_Vector3 *var = reinterpret_cast<MT_Vector3*>(ptr);
- for (int i=0; i<3; i++)
- {
- item = PySequence_GetItem(value, i); /* new ref */
- float val = PyFloat_AsDouble(item);
- Py_DECREF(item);
- item = NULL;
- if (val == -1.0f && PyErr_Occurred())
- {
- PyErr_Format(PyExc_TypeError, "expected a sequence of 3 floats for attribute \"%s\"", attrdef->m_name);
- goto RESTORE_AND_ERROR;
- }
- else if (attrdef->m_clamp)
- {
- if (val < attrdef->m_fmin)
- val = attrdef->m_fmin;
- else if (val > attrdef->m_fmax)
- val = attrdef->m_fmax;
- }
- else if (val < attrdef->m_fmin || val > attrdef->m_fmax)
- {
- PyErr_Format(PyExc_ValueError, "value out of range for attribute \"%s\"", attrdef->m_name);
- goto RESTORE_AND_ERROR;
- }
- (*var)[i] = (MT_Scalar)val;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_CHAR:
- {
- if (PyUnicode_Check(value))
- {
- Py_ssize_t val_size;
- const char *val = _PyUnicode_AsStringAndSize(value, &val_size);
- strncpy(ptr, val, attrdef->m_size);
- ptr[attrdef->m_size-1] = 0;
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected a string for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- break;
- }
- case KX_PYATTRIBUTE_TYPE_STRING:
- {
- STR_String *var = reinterpret_cast<STR_String*>(ptr);
- if (PyUnicode_Check(value))
- {
- Py_ssize_t val_len;
- const char *val = _PyUnicode_AsStringAndSize(value, &val_len); /* XXX, should be 'const' but we do a silly trick to have a shorter string */
- if (attrdef->m_clamp)
- {
- if (val_len < attrdef->m_imin)
- {
- // can't increase the length of the string
- PyErr_Format(PyExc_ValueError, "string length too short for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- else if (val_len > attrdef->m_imax)
- {
- // trim the string
- var->SetLength(attrdef->m_imax);
- memcpy(var->Ptr(), val, attrdef->m_imax - 1);
- break;
- }
- } else if (val_len < attrdef->m_imin || val_len > attrdef->m_imax)
- {
- PyErr_Format(PyExc_ValueError, "string length out of range for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- *var = val;
- }
- else
- {
- PyErr_Format(PyExc_TypeError, "expected a string for attribute \"%s\"", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- break;
- }
- default:
- // should not happen
- PyErr_Format(PyExc_AttributeError, "unknown type for attribute \"%s\", report to blender.org", attrdef->m_name);
- goto FREE_AND_ERROR;
- }
- }
- // check if post processing is needed
- if (attrdef->m_checkFunction != NULL)
- {
- if ((*attrdef->m_checkFunction)(ref, attrdef) != 0)
- {
- // restore value
- RESTORE_AND_ERROR:
- if (undoBuffer)
- {
- if (attrdef->m_type == KX_PYATTRIBUTE_TYPE_STRING)
- {
- // special case for STR_String: restore the string
- STR_String *var = reinterpret_cast<STR_String*>(ptr);
- *var = reinterpret_cast<char*>(undoBuffer);
- }
- else
- {
- // other field type have direct values
- memcpy(ptr, undoBuffer, bufferSize);
- }
- }
- FREE_AND_ERROR:
- if (undoBuffer)
- free(undoBuffer);
- if (list)
- Py_DECREF(list);
- if (item)
- Py_DECREF(item);
- return 1;
- }
- }
- if (undoBuffer)
- free(undoBuffer);
- return 0;
-}
-
-
-
-/*------------------------------
- * PyObjectPlus repr -- representations
-------------------------------*/
-PyObject *PyObjectPlus::py_repr(void)
-{
- PyErr_SetString(PyExc_SystemError, "Representation not overridden by object.");
- return NULL;
-}
-
-PyObject *PyObjectPlus::GetProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr)
-{
- if (self->m_proxy==NULL)
- {
- self->m_proxy = reinterpret_cast<PyObject *>PyObject_NEW( PyObjectPlus_Proxy, tp);
- BGE_PROXY_PYOWNS(self->m_proxy) = false;
- BGE_PROXY_PYREF(self->m_proxy) = true;
-#ifdef USE_WEAKREFS
- BGE_PROXY_WKREF(self->m_proxy) = NULL;
-#endif
- }
- //PyObject_Print(self->m_proxy, stdout, 0);
- //printf("ref %d\n", self->m_proxy->ob_refcnt);
-
- BGE_PROXY_REF(self->m_proxy) = self; /* Its possible this was set to NULL, so set it back here */
- BGE_PROXY_PTR(self->m_proxy) = ptr;
- Py_INCREF(self->m_proxy); /* we own one, thos ones fore the return */
- return self->m_proxy;
-}
-
-PyObject *PyObjectPlus::NewProxyPlus_Ext(PyObjectPlus *self, PyTypeObject *tp, void *ptr, bool py_owns)
-{
- if (!self)
- {
- // in case of proxy without reference to game object
- PyObject *proxy = reinterpret_cast<PyObject *>PyObject_NEW( PyObjectPlus_Proxy, tp);
- BGE_PROXY_PYREF(proxy) = false;
- BGE_PROXY_PYOWNS(proxy) = py_owns;
- BGE_PROXY_REF(proxy) = NULL;
- BGE_PROXY_PTR(proxy) = ptr;
-#ifdef USE_WEAKREFS
- BGE_PROXY_WKREF(proxy) = NULL;
-#endif
- return proxy;
- }
- if (self->m_proxy)
- {
- if (py_owns)
- { /* Free */
- BGE_PROXY_REF(self->m_proxy) = NULL;
- Py_DECREF(self->m_proxy);
- self->m_proxy= NULL;
- }
- else {
- Py_INCREF(self->m_proxy);
- return self->m_proxy;
- }
-
- }
-
- GetProxyPlus_Ext(self, tp, ptr);
- if (py_owns) {
- BGE_PROXY_PYOWNS(self->m_proxy) = py_owns;
- Py_DECREF(self->m_proxy); /* could avoid thrashing here but for now its ok */
- }
- return self->m_proxy;
-}
-
-PyObject *PyUnicode_From_STR_String(const STR_String& str)
-{
- return PyUnicode_FromStringAndSize(str.ReadPtr(), str.Length());
-}
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////
-/* deprecation warning management */
-
-bool PyObjectPlus::m_ignore_deprecation_warnings(false);
-void PyObjectPlus::SetDeprecationWarnings(bool ignoreDeprecationWarnings)
-{
- m_ignore_deprecation_warnings = ignoreDeprecationWarnings;
-}
-
-void PyObjectPlus::ShowDeprecationWarning_func(const char *old_way, const char *new_way)
-{
- printf("Method %s is deprecated, please use %s instead.\n", old_way, new_way);
- PyC_LineSpit();
-}
-
-void PyObjectPlus::ClearDeprecationWarning()
-{
- WarnLink *wlink_next;
- WarnLink *wlink = GetDeprecationWarningLinkFirst();
-
- while (wlink) {
- wlink->warn_done= false; /* no need to NULL the link, its cleared before adding to the list next time round */
- wlink_next= reinterpret_cast<WarnLink *>(wlink->link);
- wlink->link= NULL;
- wlink= wlink_next;
- }
- NullDeprecationWarning();
-}
-
-static WarnLink *m_base_wlink_first = NULL;
-static WarnLink *m_base_wlink_last = NULL;
-
-WarnLink* PyObjectPlus::GetDeprecationWarningLinkFirst(void) {return m_base_wlink_first;}
-WarnLink* PyObjectPlus::GetDeprecationWarningLinkLast(void) {return m_base_wlink_last;}
-void PyObjectPlus::SetDeprecationWarningFirst(WarnLink* wlink) {m_base_wlink_first= wlink;}
-void PyObjectPlus::SetDeprecationWarningLinkLast(WarnLink* wlink) {m_base_wlink_last= wlink;}
-void PyObjectPlus::NullDeprecationWarning() {m_base_wlink_first= m_base_wlink_last= NULL;}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Expressions/intern/PythonCallBack.cpp b/source/gameengine/Expressions/intern/PythonCallBack.cpp
deleted file mode 100644
index 3fb84569eca..00000000000
--- a/source/gameengine/Expressions/intern/PythonCallBack.cpp
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Porteries Tristan.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Expressions/intern/PythonCallBack.cpp
- * \ingroup expressions
- */
-
-#include "EXP_PythonCallBack.h"
-#include <iostream>
-#include <stdarg.h>
-
-#include "BLI_alloca.h"
-
-/** Check if a python value is a function and have the correct number of arguments.
- * \param value The python value to check.
- * \param minargcount The minimum of arguments possible.
- * \param maxargcount The maximum of arguments possible.
- * \param r_argcount The number of argument of this function, this variable will be
- * changed in the function.
- */
-static PyObject *CheckPythonFunction(PyObject *value, unsigned int minargcount, unsigned int maxargcount, unsigned int &r_argcount)
-{
- if (PyMethod_Check(value)) {
- PyCodeObject *code = ((PyCodeObject *)PyFunction_GET_CODE(PyMethod_GET_FUNCTION(value)));
- // *args support
- r_argcount = (code->co_flags & CO_VARARGS) ? maxargcount : (code->co_argcount - 1);
- }
- else if (PyFunction_Check(value)) {
- PyCodeObject *code = ((PyCodeObject *)PyFunction_GET_CODE(value));
- // *args support
- r_argcount = (code->co_flags & CO_VARARGS) ? maxargcount : code->co_argcount;
- }
- else { // is not a methode or a function
- PyErr_Format(PyExc_TypeError, "items must be functions or methodes, not %s",
- Py_TYPE(value)->tp_name);
- return NULL;
- }
-
- if (r_argcount < minargcount || r_argcount > maxargcount) {
- // wrong number of arguments
- PyErr_Format(PyExc_TypeError, "methode or function (%s) has invalid number of arguments (%i) must be between %i and %i",
- Py_TYPE(value)->tp_name, r_argcount, minargcount, maxargcount);
- return NULL;
- }
-
- return value;
-}
-
-/** Create a python tuple to call a python function
- * \param argcount The lenght of the tuple.
- * \param arglist The fully list of python arguments [size >= argcount].
- */
-static PyObject *CreatePythonTuple(unsigned int argcount, PyObject **arglist)
-{
- PyObject *tuple = PyTuple_New(argcount);
-
- for (unsigned int i = 0; i < argcount; ++i) {
- PyObject *item = arglist[i];
- // increment reference and copy it in a new tuple
- Py_INCREF(item);
- PyTuple_SET_ITEM(tuple, i, item);
- }
-
- return tuple;
-}
-
-void RunPythonCallBackList(PyObject *functionlist, PyObject **arglist, unsigned int minargcount, unsigned int maxargcount)
-{
- unsigned int size = PyList_Size(functionlist);
- PyObject **argTuples = (PyObject **)BLI_array_alloca(argTuples, maxargcount - minargcount + 1);
- memset(argTuples, 0, sizeof(PyObject *) * (maxargcount - minargcount + 1));
-
- for (unsigned int i = 0; i < size; ++i) {
- unsigned int funcargcount = 0;
-
- PyObject *item = PyList_GET_ITEM(functionlist, i);
- PyObject *func = CheckPythonFunction(item, minargcount, maxargcount, funcargcount);
- if (!func) { // this item fails the check
- PyErr_Print();
- PyErr_Clear();
- continue;
- }
-
- // get correct argument tuple.
- PyObject *tuple = argTuples[funcargcount - minargcount];
- if (!tuple)
- argTuples[funcargcount - minargcount] = tuple = CreatePythonTuple(funcargcount, arglist);
-
- PyObject *ret = PyObject_Call(func, tuple, NULL);
- if (!ret) { // if ret is NULL this seems that the function doesn't work !
- PyErr_Print();
- PyErr_Clear();
- }
- else
- Py_DECREF(ret);
- }
-
- for (unsigned int i = 0; i <= (maxargcount - minargcount); ++i)
- Py_XDECREF(argTuples[i]);
-}
diff --git a/source/gameengine/Expressions/intern/StringValue.cpp b/source/gameengine/Expressions/intern/StringValue.cpp
deleted file mode 100644
index ddf61dc441c..00000000000
--- a/source/gameengine/Expressions/intern/StringValue.cpp
+++ /dev/null
@@ -1,147 +0,0 @@
-/** \file gameengine/Expressions/StringValue.cpp
- * \ingroup expressions
- */
-// StringValue.cpp: implementation of the CStringValue class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#include "EXP_StringValue.h"
-#include "EXP_BoolValue.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_VoidValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-/**
- * pre: false
- * effect: constructs a new CStringValue
- */
-CStringValue::CStringValue()
-{
- m_strString = "[Illegal String constructor call]";
-}
-
-/**
- * pre:
- * effect: constructs a new CStringValue containing text txt
- */
-CStringValue::CStringValue(const char *txt,const char *name,AllocationTYPE alloctype)
-{
- m_strString = txt;
- SetName(name);
-
- if (alloctype==CValue::STACKVALUE)
- {
- CValue::DisableRefCount();
-
- }
-
-
-}
-
-
-/**
- * pre:
- * ret: a new object containing the result of applying operator op to this
- * object and val
- */
-CValue* CStringValue::Calc(VALUE_OPERATOR op, CValue *val)
-{
- //return val->CalrcString(op, this);
- return val->CalcFinal(VALUE_STRING_TYPE, op, this);
-}
-
-/**
- * pre: the type of val is dtype
- * ret: a new object containing the result of applying operator op to val and
- * this object
- */
-CValue* CStringValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-{
- CValue *ret;
-
- if (op == VALUE_ADD_OPERATOR) {
- if (dtype == VALUE_ERROR_TYPE)
- ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
- else
- ret = new CStringValue(val->GetText() + GetText(),"");
- }
- else {
- if (dtype == VALUE_STRING_TYPE || dtype == VALUE_EMPTY_TYPE) {
- switch (op) {
- case VALUE_EQL_OPERATOR:
- ret = new CBoolValue(val->GetText() == GetText());
- break;
- case VALUE_NEQ_OPERATOR:
- ret = new CBoolValue(val->GetText() != GetText());
- break;
- case VALUE_GRE_OPERATOR:
- ret = new CBoolValue(val->GetText() > GetText());
- break;
- case VALUE_LES_OPERATOR:
- ret = new CBoolValue(val->GetText() < GetText());
- break;
- case VALUE_GEQ_OPERATOR:
- ret = new CBoolValue(val->GetText() >= GetText());
- break;
- case VALUE_LEQ_OPERATOR:
- ret = new CBoolValue(val->GetText() <= GetText());
- break;
- default:
- ret = new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]");
- break;
- }
- }
- else {
- ret = new CErrorValue(val->GetText() + op2str(op) + "[operator not allowed on strings]");
- }
- }
- return ret;
-}
-
-
-
-double CStringValue::GetNumber()
-{
- return -1;
-}
-
-
-
-int CStringValue::GetValueType()
-{
- return VALUE_STRING_TYPE;
-}
-
-
-
-const STR_String & CStringValue::GetText()
-{
- return m_strString;
-}
-
-bool CStringValue::IsEqual(const STR_String & other)
-{
- return (m_strString == other);
-}
-
-CValue* CStringValue::GetReplica()
-{
- CStringValue* replica = new CStringValue(*this);
- replica->ProcessReplica();
- return replica;
-};
-
-
diff --git a/source/gameengine/Expressions/intern/Value.cpp b/source/gameengine/Expressions/intern/Value.cpp
deleted file mode 100644
index f8796a76e76..00000000000
--- a/source/gameengine/Expressions/intern/Value.cpp
+++ /dev/null
@@ -1,672 +0,0 @@
-/** \file gameengine/Expressions/Value.cpp
- * \ingroup expressions
- */
-// Value.cpp: implementation of the CValue class.
-// developed at Eindhoven University of Technology, 1997
-// by the OOPS team
-//////////////////////////////////////////////////////////////////////
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-#include "EXP_Value.h"
-#include "EXP_BoolValue.h"
-#include "EXP_FloatValue.h"
-#include "EXP_IntValue.h"
-#include "EXP_VectorValue.h"
-#include "EXP_VoidValue.h"
-#include "EXP_StringValue.h"
-#include "EXP_ErrorValue.h"
-#include "EXP_ListValue.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-double CValue::m_sZeroVec[3] = {0.0,0.0,0.0};
-
-#ifdef WITH_PYTHON
-
-PyTypeObject CValue::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "CValue",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- 0,0,0,0,0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef CValue::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-#endif // WITH_PYTHON
-
-
-/*#define CVALUE_DEBUG*/
-#ifdef CVALUE_DEBUG
-int gRefCount;
-struct SmartCValueRef
-{
- CValue *m_ref;
- int m_count;
- SmartCValueRef(CValue *ref)
- {
- m_ref = ref;
- m_count = gRefCount++;
- }
-};
-
-#include <vector>
-
-std::vector<SmartCValueRef> gRefList;
-#endif
-
-#ifdef DEBUG
-//int gRefCountValue;
-#endif
-
-CValue::CValue()
- : PyObjectPlus(),
-
-m_pNamedPropertyArray(NULL),
-m_refcount(1)
-/*
-pre: false
-effect: constucts a CValue
-*/
-{
- //debug(gRefCountValue++) // debugging
-#ifdef DEBUG
- //gRefCountValue++;
-#ifdef CVALUE_DEBUG
- gRefList.push_back(SmartCValueRef(this));
-#endif
-#endif
-}
-
-
-
-CValue::~CValue()
-/*
-pre:
-effect: deletes the object
-*/
-{
- ClearProperties();
-
- assertd (m_refcount==0);
-#ifdef CVALUE_DEBUG
- std::vector<SmartCValueRef>::iterator it;
- for (it=gRefList.begin(); it!=gRefList.end(); it++)
- {
- if (it->m_ref == this)
- {
- *it = gRefList.back();
- gRefList.pop_back();
- break;
- }
- }
-#endif
-}
-
-
-/* UNUSED */
-#if 0
-#define VALUE_SUB(val1, val2) (val1)->Calc(VALUE_SUB_OPERATOR, val2)
-#define VALUE_MUL(val1, val2) (val1)->Calc(VALUE_MUL_OPERATOR, val2)
-#define VALUE_DIV(val1, val2) (val1)->Calc(VALUE_DIV_OPERATOR, val2)
-#define VALUE_NEG(val1) (val1)->Calc(VALUE_NEG_OPERATOR, val1)
-#define VALUE_POS(val1) (val1)->Calc(VALUE_POS_OPERATOR, val1)
-#endif
-
-STR_String CValue::op2str(VALUE_OPERATOR op)
-{
- //pre:
- //ret: the stringrepresentation of operator op
-
- STR_String opmsg;
- switch (op) {
- case VALUE_MOD_OPERATOR:
- opmsg = " % ";
- break;
- case VALUE_ADD_OPERATOR:
- opmsg = " + ";
- break;
- case VALUE_SUB_OPERATOR:
- opmsg = " - ";
- break;
- case VALUE_MUL_OPERATOR:
- opmsg = " * ";
- break;
- case VALUE_DIV_OPERATOR:
- opmsg = " / ";
- break;
- case VALUE_NEG_OPERATOR:
- opmsg = " -";
- break;
- case VALUE_POS_OPERATOR:
- opmsg = " +";
- break;
- case VALUE_AND_OPERATOR:
- opmsg = " & ";
- break;
- case VALUE_OR_OPERATOR:
- opmsg = " | ";
- break;
- case VALUE_EQL_OPERATOR:
- opmsg = " = ";
- break;
- case VALUE_NEQ_OPERATOR:
- opmsg = " != ";
- break;
- case VALUE_NOT_OPERATOR:
- opmsg = " !";
- break;
- default:
- opmsg="Error in Errorhandling routine.";
- // AfxMessageBox("Invalid operator");
- break;
- }
- return opmsg;
-}
-
-
-
-
-
-//---------------------------------------------------------------------------------------------------------------------
-// Property Management
-//---------------------------------------------------------------------------------------------------------------------
-
-
-
-//
-// Set property <ioProperty>, overwrites and releases a previous property with the same name if needed
-//
-void CValue::SetProperty(const STR_String & name,CValue* ioProperty)
-{
- if (ioProperty==NULL)
- { // Check if somebody is setting an empty property
- trace("Warning:trying to set empty property!");
- return;
- }
-
- if (m_pNamedPropertyArray)
- { // Try to replace property (if so -> exit as soon as we replaced it)
- CValue* oldval = (*m_pNamedPropertyArray)[name];
- if (oldval)
- oldval->Release();
- }
- else { // Make sure we have a property array
- m_pNamedPropertyArray = new std::map<STR_String,CValue *>;
- }
-
- // Add property at end of array
- (*m_pNamedPropertyArray)[name] = ioProperty->AddRef();//->Add(ioProperty);
-}
-
-void CValue::SetProperty(const char* name,CValue* ioProperty)
-{
- if (ioProperty==NULL)
- { // Check if somebody is setting an empty property
- trace("Warning:trying to set empty property!");
- return;
- }
-
- if (m_pNamedPropertyArray)
- { // Try to replace property (if so -> exit as soon as we replaced it)
- CValue* oldval = (*m_pNamedPropertyArray)[name];
- if (oldval)
- oldval->Release();
- }
- else { // Make sure we have a property array
- m_pNamedPropertyArray = new std::map<STR_String,CValue *>;
- }
-
- // Add property at end of array
- (*m_pNamedPropertyArray)[name] = ioProperty->AddRef();//->Add(ioProperty);
-}
-
-//
-// Get pointer to a property with name <inName>, returns NULL if there is no property named <inName>
-//
-CValue* CValue::GetProperty(const STR_String & inName)
-{
- if (m_pNamedPropertyArray) {
- std::map<STR_String,CValue*>::iterator it = m_pNamedPropertyArray->find(inName);
- if (it != m_pNamedPropertyArray->end())
- return (*it).second;
- }
- return NULL;
-}
-
-CValue* CValue::GetProperty(const char *inName)
-{
- if (m_pNamedPropertyArray) {
- std::map<STR_String,CValue*>::iterator it = m_pNamedPropertyArray->find(inName);
- if (it != m_pNamedPropertyArray->end())
- return (*it).second;
- }
- return NULL;
-}
-
-//
-// Get text description of property with name <inName>, returns an empty string if there is no property named <inName>
-//
-const STR_String& CValue::GetPropertyText(const STR_String & inName)
-{
- const static STR_String sEmpty("");
-
- CValue *property = GetProperty(inName);
- if (property)
- return property->GetText();
- else
- return sEmpty;
-}
-
-float CValue::GetPropertyNumber(const STR_String& inName,float defnumber)
-{
- CValue *property = GetProperty(inName);
- if (property)
- return property->GetNumber();
- else
- return defnumber;
-}
-
-
-
-//
-// Remove the property named <inName>, returns true if the property was succesfully removed, false if property was not found or could not be removed
-//
-bool CValue::RemoveProperty(const char *inName)
-{
- // Check if there are properties at all which can be removed
- if (m_pNamedPropertyArray)
- {
- std::map<STR_String,CValue*>::iterator it = m_pNamedPropertyArray->find(inName);
- if (it != m_pNamedPropertyArray->end())
- {
- ((*it).second)->Release();
- m_pNamedPropertyArray->erase(it);
- return true;
- }
- }
-
- return false;
-}
-
-//
-// Get Property Names
-//
-vector<STR_String> CValue::GetPropertyNames()
-{
- vector<STR_String> result;
- if (!m_pNamedPropertyArray) return result;
- result.reserve(m_pNamedPropertyArray->size());
-
- std::map<STR_String,CValue*>::iterator it;
- for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++)
- {
- result.push_back((*it).first);
- }
- return result;
-}
-
-//
-// Clear all properties
-//
-void CValue::ClearProperties()
-{
- // Check if we have any properties
- if (m_pNamedPropertyArray == NULL)
- return;
-
- // Remove all properties
- std::map<STR_String,CValue*>::iterator it;
- for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++)
- {
- CValue* tmpval = (*it).second;
- //STR_String name = (*it).first;
- tmpval->Release();
- }
-
- // Delete property array
- delete m_pNamedPropertyArray;
- m_pNamedPropertyArray=NULL;
-}
-
-
-
-//
-// Set all properties' modified flag to <inModified>
-//
-void CValue::SetPropertiesModified(bool inModified)
-{
- if (!m_pNamedPropertyArray) return;
- std::map<STR_String,CValue*>::iterator it;
-
- for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++)
- ((*it).second)->SetModified(inModified);
-}
-
-
-
-//
-// Check if any of the properties in this value have been modified
-//
-bool CValue::IsAnyPropertyModified()
-{
- if (!m_pNamedPropertyArray) return false;
- std::map<STR_String,CValue*>::iterator it;
-
- for (it= m_pNamedPropertyArray->begin();(it != m_pNamedPropertyArray->end()); it++)
- if (((*it).second)->IsModified())
- return true;
-
- return false;
-}
-
-
-
-//
-// Get property number <inIndex>
-//
-CValue* CValue::GetProperty(int inIndex)
-{
-
- int count=0;
- CValue* result = NULL;
-
- if (m_pNamedPropertyArray)
- {
- std::map<STR_String,CValue*>::iterator it;
- for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++)
- {
- if (count++ == inIndex)
- {
- result = (*it).second;
- break;
- }
- }
-
- }
- return result;
-}
-
-
-
-//
-// Get the amount of properties assiocated with this value
-//
-int CValue::GetPropertyCount()
-{
- if (m_pNamedPropertyArray)
- return m_pNamedPropertyArray->size();
- else
- return 0;
-}
-
-
-double* CValue::GetVector3(bool bGetTransformedVec)
-{
- assertd(false); // don't get vector from me
- return m_sZeroVec;//::sZero;
-}
-
-
-/*---------------------------------------------------------------------------------------------------------------------
- Reference Counting
----------------------------------------------------------------------------------------------------------------------*/
-
-
-
-//
-// Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
-//
-
-
-
-//
-// Disable reference counting for this value
-//
-void CValue::DisableRefCount()
-{
- assertd(m_refcount == 1);
- m_refcount--;
-
- //debug(gRefCountValue--);
-#ifdef DEBUG
- //gRefCountValue--;
-#endif
- m_ValFlags.RefCountDisabled=true;
-}
-
-
-
-void CValue::ProcessReplica() /* was AddDataToReplica in 2.48 */
-{
- m_refcount = 1;
-
-#ifdef DEBUG
- //gRefCountValue++;
-#endif
- PyObjectPlus::ProcessReplica();
-
- m_ValFlags.RefCountDisabled = false;
-
- /* copy all props */
- if (m_pNamedPropertyArray)
- {
- std::map<STR_String,CValue*> *pOldArray = m_pNamedPropertyArray;
- m_pNamedPropertyArray=NULL;
- std::map<STR_String,CValue*>::iterator it;
- for (it= pOldArray->begin(); (it != pOldArray->end()); it++)
- {
- CValue *val = (*it).second->GetReplica();
- SetProperty((*it).first,val);
- val->Release();
- }
- }
-}
-
-
-
-int CValue::GetValueType()
-{
- return VALUE_NO_TYPE;
-}
-
-
-
-CValue* CValue::FindIdentifier(const STR_String& identifiername)
-{
-
- CValue* result = NULL;
-
- int pos = 0;
- // if a dot exists, explode the name into pieces to get the subcontext
- if ((pos=identifiername.Find('.'))>=0)
- {
- const STR_String rightstring = identifiername.Right(identifiername.Length() -1 - pos);
- const STR_String leftstring = identifiername.Left(pos);
- CValue* tempresult = GetProperty(leftstring);
- if (tempresult)
- {
- result=tempresult->FindIdentifier(rightstring);
- }
- } else
- {
- result = GetProperty(identifiername);
- if (result)
- return result->AddRef();
- }
- if (!result)
- {
- // warning here !!!
- result = new CErrorValue(identifiername+" not found");
- }
- return result;
-}
-
-#ifdef WITH_PYTHON
-
-PyAttributeDef CValue::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("name", CValue, pyattr_get_name),
- { NULL } //Sentinel
-};
-
-PyObject *CValue::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- CValue * self = static_cast<CValue *> (self_v);
- return PyUnicode_From_STR_String(self->GetName());
-}
-
-/**
- * There are 2 reasons this could return NULL
- * - unsupported type.
- * - error converting (overflow).
- *
- * \param do_type_exception Use to skip raising an exception for unknown types.
- */
-CValue *CValue::ConvertPythonToValue(PyObject *pyobj, const bool do_type_exception, const char *error_prefix)
-{
-
- CValue *vallie;
- /* refcounting is broking here! - this crashes anyway, just store a python list for KX_GameObject */
-#if 0
- if (PyList_Check(pyobj))
- {
- CListValue* listval = new CListValue();
- bool error = false;
-
- Py_ssize_t i;
- Py_ssize_t numitems = PyList_GET_SIZE(pyobj);
- for (i=0;i<numitems;i++)
- {
- PyObject *listitem = PyList_GET_ITEM(pyobj,i); /* borrowed ref */
- CValue* listitemval = ConvertPythonToValue(listitem, error_prefix);
- if (listitemval)
- {
- listval->Add(listitemval);
- } else
- {
- error = true;
- }
- }
- if (!error)
- {
- // jippie! could be converted
- vallie = listval;
- } else
- {
- // list could not be converted... bad luck
- listval->Release();
- }
-
- } else
-#endif
- /* note: Boolean check should go before Int check [#34677] */
- if (PyBool_Check(pyobj))
- {
- vallie = new CBoolValue( (bool)PyLong_AsLongLong(pyobj) );
- } else
- if (PyFloat_Check(pyobj))
- {
- const double tval = PyFloat_AsDouble(pyobj);
- if (tval > (double)FLT_MAX || tval < (double)-FLT_MAX) {
- PyErr_Format(PyExc_OverflowError, "%soverflow converting from float, out of internal range", error_prefix);
- vallie = NULL;
- }
- else {
- vallie = new CFloatValue((float)tval);
- }
- } else
- if (PyLong_Check(pyobj))
- {
- vallie = new CIntValue( (cInt)PyLong_AsLongLong(pyobj) );
- } else
- if (PyUnicode_Check(pyobj))
- {
- vallie = new CStringValue(_PyUnicode_AsString(pyobj),"");
- } else
- if (PyObject_TypeCheck(pyobj, &CValue::Type)) /* Note, don't let these get assigned to GameObject props, must check elsewhere */
- {
- vallie = (static_cast<CValue *>(BGE_PROXY_REF(pyobj)))->AddRef();
- }
- else {
- if (do_type_exception) {
- /* return an error value from the caller */
- PyErr_Format(PyExc_TypeError, "%scould convert python value to a game engine property", error_prefix);
- }
- vallie = NULL;
- }
- return vallie;
-
-}
-
-PyObject *CValue::ConvertKeysToPython(void)
-{
- if (m_pNamedPropertyArray)
- {
- PyObject *pylist= PyList_New(m_pNamedPropertyArray->size());
- Py_ssize_t i= 0;
-
- std::map<STR_String,CValue*>::iterator it;
- for (it= m_pNamedPropertyArray->begin(); (it != m_pNamedPropertyArray->end()); it++)
- {
- PyList_SET_ITEM(pylist, i++, PyUnicode_From_STR_String((*it).first));
- }
-
- return pylist;
- }
- else {
- return PyList_New(0);
- }
-}
-
-#endif // WITH_PYTHON
-
-
-///////////////////////////////////////////////////////////////////////////////////////////////
-///////////////////////////////////////////////////////////////////////////////////////////////
-/* These implementations were moved out of the header */
-
-void CValue::SetOwnerExpression(class CExpression* expr)
-{
- /* intentionally empty */
-}
-
-void CValue::SetColorOperator(VALUE_OPERATOR op)
-{
- /* intentionally empty */
-}
-void CValue::SetValue(CValue* newval)
-{
- // no one should get here
- assertd(newval->GetNumber() == 10121969);
-}
diff --git a/source/gameengine/Expressions/intern/VectorValue.cpp b/source/gameengine/Expressions/intern/VectorValue.cpp
deleted file mode 100644
index a3d44116317..00000000000
--- a/source/gameengine/Expressions/intern/VectorValue.cpp
+++ /dev/null
@@ -1,225 +0,0 @@
-/** \file gameengine/Expressions/VectorValue.cpp
- * \ingroup expressions
- */
-// VectorValue.cpp: implementation of the CVectorValue class.
-/*
- * Copyright (c) 1996-2000 Erwin Coumans <coockie@acm.org>
- *
- * Permission to use, copy, modify, distribute and sell this software
- * and its documentation for any purpose is hereby granted without fee,
- * provided that the above copyright notice appear in all copies and
- * that both that copyright notice and this permission notice appear
- * in supporting documentation. Erwin Coumans makes no
- * representations about the suitability of this software for any
- * purpose. It is provided "as is" without express or implied warranty.
- *
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "EXP_Value.h"
-#include "EXP_VectorValue.h"
-#include "EXP_ErrorValue.h"
-//#include "MatrixValue.h"
-#include "EXP_VoidValue.h"
-#include "EXP_StringValue.h"
-//#include "FactoryManager.h"
-
-
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CVectorValue::CVectorValue(float x,float y,float z, AllocationTYPE alloctype)
-{
- SetCustomFlag1(false);//FancyOutput=false;
-
- if (alloctype == STACKVALUE)
- {
- CValue::DisableRefCount();
- };
-
- m_vec[KX_X] = m_transformedvec[KX_X] = x;
- m_vec[KX_Y] = m_transformedvec[KX_Y] = y;
- m_vec[KX_Z] = m_transformedvec[KX_Z] = z;
-
-}
-CVectorValue::CVectorValue(double vec[3], const char *name,AllocationTYPE alloctype)
-{
-
- SetCustomFlag1(false);//FancyOutput=false;
-
- m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X];
- m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y];
- m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z];
-
- if (alloctype == STACKVALUE)
- {
- CValue::DisableRefCount();
-
- }
-
- SetName(name);
-}
-
-CVectorValue::CVectorValue(double vec[3], AllocationTYPE alloctype)
-{
-
- SetCustomFlag1(false);//FancyOutput=false;
-
- m_vec[KX_X] = m_transformedvec[KX_X] = vec[KX_X];
- m_vec[KX_Y] = m_transformedvec[KX_Y] = vec[KX_Y];
- m_vec[KX_Z] = m_transformedvec[KX_Z] = vec[KX_Z];
-
- if (alloctype == STACKVALUE)
- {
- CValue::DisableRefCount();
-
- }
-
-
-}
-CVectorValue::~CVectorValue()
-{
-
-}
-
-/**
- * pre: the type of val is dtype
- * ret: a new object containing the result of applying operator op to val and
- * this object
- */
-CValue* CVectorValue::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-{
- CValue *ret = NULL;
-
- switch (op) {
- case VALUE_ADD_OPERATOR:
- {
- switch (dtype)
- {
- case VALUE_EMPTY_TYPE:
- case VALUE_VECTOR_TYPE:
- {
- ret = new CVectorValue(
- val->GetVector3()[KX_X] + GetVector3()[KX_X],
- val->GetVector3()[KX_Y] + GetVector3()[KX_Y],
- val->GetVector3()[KX_Z] + GetVector3()[KX_Z],
- CValue::HEAPVALUE);
- ret->SetName(GetName());
- break;
- }
-
- default:
- ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
- }
- break;
- }
- case VALUE_MUL_OPERATOR:
- {
- switch (dtype)
- {
-
- case VALUE_EMPTY_TYPE:
- case VALUE_VECTOR_TYPE:
- {
- //MT_Vector3 supports 'scaling' by another vector, instead of using general transform, Gino?
- //ret = new CVectorValue(val->GetVector3().Scaled(GetVector3()),GetName());
- break;
- }
- case VALUE_FLOAT_TYPE:
- {
- ret = new CVectorValue(
- val->GetVector3()[KX_X] * GetVector3()[KX_X],
- val->GetVector3()[KX_Y] * GetVector3()[KX_Y],
- val->GetVector3()[KX_Z] * GetVector3()[KX_Z],
- CValue::HEAPVALUE);
- ret->SetName(GetName());
- break;
- }
-
- default:
- ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
- }
- break;
-
- }
-
- default:
- ret = new CErrorValue(val->GetText() + op2str(op) + GetText());
- }
-
-
- return ret;
-}
-
-double CVectorValue::GetNumber()
-{
- return m_vec[KX_X];
-}
-
-
-
-int CVectorValue::GetValueType()
-{
- return VALUE_VECTOR_TYPE;
-}
-
-
-
-double* CVectorValue::GetVector3(bool bGetTransformedVec)
-{
- if (bGetTransformedVec)
- return m_transformedvec;
- // else
- return m_vec;
-}
-
-
-
-
-
-void CVectorValue::SetVector(double newvec[])
-{
- m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X];
- m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y];
- m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z];
-
- SetModified(true);
-}
-
-
-void CVectorValue::SetValue(CValue *newval)
-{
-
- double* newvec = ((CVectorValue*)newval)->GetVector3();
- m_vec[KX_X] = m_transformedvec[KX_X] = newvec[KX_X];
- m_vec[KX_Y] = m_transformedvec[KX_Y] = newvec[KX_Y];
- m_vec[KX_Z] = m_transformedvec[KX_Z] = newvec[KX_Z];
-
- SetModified(true);
-}
-
-static const STR_String gstrVectorStr=STR_String();
-const STR_String & CVectorValue::GetText()
-{
- assertd(false);
- return gstrVectorStr;
-}
-
-CValue* CVectorValue::GetReplica()
-{
- CVectorValue* replica = new CVectorValue(*this);
- replica->ProcessReplica();
- return replica;
-};
-
-#if 0
-void CVectorValue::Transform(rcMatrix4x4 mat)
-{
- m_transformedvec = mat*m_vec;
-}
-#endif
diff --git a/source/gameengine/GameLogic/CMakeLists.txt b/source/gameengine/GameLogic/CMakeLists.txt
deleted file mode 100644
index b9eec74f6f4..00000000000
--- a/source/gameengine/GameLogic/CMakeLists.txt
+++ /dev/null
@@ -1,147 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../Expressions
- ../Rasterizer
- ../SceneGraph
- ../../blender/blenlib
- ../../../intern/container
- ../../../intern/string
- ../../../intern/ghost
-)
-
-set(INC_SYS
- ../../../intern/moto/include
-)
-
-set(SRC
- SCA_2DFilterActuator.cpp
- SCA_ANDController.cpp
- SCA_ActuatorEventManager.cpp
- SCA_ActuatorSensor.cpp
- SCA_AlwaysEventManager.cpp
- SCA_AlwaysSensor.cpp
- SCA_BasicEventManager.cpp
- SCA_DelaySensor.cpp
- SCA_EventManager.cpp
- SCA_ExpressionController.cpp
- SCA_IActuator.cpp
- SCA_IController.cpp
- SCA_IInputDevice.cpp
- SCA_ILogicBrick.cpp
- SCA_IObject.cpp
- SCA_IScene.cpp
- SCA_ISensor.cpp
- SCA_JoystickManager.cpp
- SCA_JoystickSensor.cpp
- SCA_KeyboardManager.cpp
- SCA_KeyboardSensor.cpp
- SCA_LogicManager.cpp
- SCA_MouseManager.cpp
- SCA_MouseSensor.cpp
- SCA_NANDController.cpp
- SCA_NORController.cpp
- SCA_ORController.cpp
- SCA_PropertyActuator.cpp
- SCA_PropertyEventManager.cpp
- SCA_PropertySensor.cpp
- SCA_PythonController.cpp
- SCA_PythonJoystick.cpp
- SCA_PythonKeyboard.cpp
- SCA_PythonMouse.cpp
- SCA_RandomActuator.cpp
- SCA_RandomEventManager.cpp
- SCA_RandomNumberGenerator.cpp
- SCA_RandomSensor.cpp
- SCA_TimeEventManager.cpp
- SCA_XNORController.cpp
- SCA_XORController.cpp
- Joystick/SCA_Joystick.cpp
- Joystick/SCA_JoystickEvents.cpp
-
- SCA_2DFilterActuator.h
- SCA_ANDController.h
- SCA_ActuatorEventManager.h
- SCA_ActuatorSensor.h
- SCA_AlwaysEventManager.h
- SCA_AlwaysSensor.h
- SCA_BasicEventManager.h
- SCA_DelaySensor.h
- SCA_EventManager.h
- SCA_ExpressionController.h
- SCA_IActuator.h
- SCA_IController.h
- SCA_IInputDevice.h
- SCA_ILogicBrick.h
- SCA_IObject.h
- SCA_IScene.h
- SCA_ISensor.h
- SCA_JoystickManager.h
- SCA_JoystickSensor.h
- SCA_KeyboardManager.h
- SCA_KeyboardSensor.h
- SCA_LogicManager.h
- SCA_MouseManager.h
- SCA_MouseSensor.h
- SCA_NANDController.h
- SCA_NORController.h
- SCA_ORController.h
- SCA_PropertyActuator.h
- SCA_PropertyEventManager.h
- SCA_PropertySensor.h
- SCA_PythonController.h
- SCA_PythonJoystick.h
- SCA_PythonKeyboard.h
- SCA_PythonMouse.h
- SCA_RandomActuator.h
- SCA_RandomEventManager.h
- SCA_RandomNumberGenerator.h
- SCA_RandomSensor.h
- SCA_TimeEventManager.h
- SCA_XNORController.h
- SCA_XORController.h
- Joystick/SCA_Joystick.h
- Joystick/SCA_JoystickDefines.h
- Joystick/SCA_JoystickPrivate.h
-)
-
-if(WITH_SDL)
- list(APPEND INC_SYS
- ${SDL_INCLUDE_DIR}
- )
-
- add_definitions(-DWITH_SDL)
-
- if(WITH_GHOST_SDL)
- add_definitions(-DWITH_GHOST_SDL)
- endif()
- if(WITH_SDL_DYNLOAD)
- add_definitions(-DWITH_SDL_DYNLOAD)
- endif()
-endif()
-
-blender_add_lib(ge_logic "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp b/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
deleted file mode 100644
index 9f532527a80..00000000000
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.cpp
+++ /dev/null
@@ -1,382 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): snailrose.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/Joystick/SCA_Joystick.cpp
- * \ingroup gamelogic
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "SCA_Joystick.h"
-#include "SCA_JoystickPrivate.h"
-
-#include "BLI_path_util.h"
-
-#ifdef WITH_SDL
-# ifdef WITH_SDL_DYNLOAD
-# define SDL_CHECK(x) ((x) != (void *)0)
-# else
-# define SDL_CHECK(x) true
-# endif
-#endif
-
-SCA_Joystick::SCA_Joystick(short int index)
- :
- m_joyindex(index),
- m_prec(3200),
- m_axismax(-1),
- m_buttonmax(-1),
- m_hatmax(-1),
- m_isinit(0),
- m_istrig_axis(0),
- m_istrig_button(0),
- m_istrig_hat(0)
-{
- for (int i=0; i < JOYAXIS_MAX; i++)
- m_axis_array[i] = 0;
-
- for (int i=0; i < JOYHAT_MAX; i++)
- m_hat_array[i] = 0;
-
-#ifdef WITH_SDL
- m_private = new PrivateData();
-#endif
-}
-
-
-SCA_Joystick::~SCA_Joystick()
-
-{
-#ifdef WITH_SDL
- delete m_private;
-#endif
-}
-
-SCA_Joystick *SCA_Joystick::m_instance[JOYINDEX_MAX];
-int SCA_Joystick::m_joynum = 0;
-int SCA_Joystick::m_refCount = 0;
-
-SCA_Joystick *SCA_Joystick::GetInstance( short int joyindex )
-{
-#ifndef WITH_SDL
- return NULL;
-#else /* WITH_SDL */
- if (!SDL_CHECK(SDL_InitSubSystem)) {
- return NULL;
- }
- if (joyindex < 0 || joyindex >= JOYINDEX_MAX) {
- JOYSTICK_ECHO("Error-invalid joystick index: " << joyindex);
- return NULL;
- }
-
- if (m_refCount == 0)
- {
- int i;
-
- /* The video subsystem is required for joystick input to work. However,
- * when GHOST is running under SDL, video is initialized elsewhere. We
- * also need to set the videodriver to dummy, and do it here to avoid
- * interfering with addons that may use SDL too.
- *
- * We also init SDL once only. */
-# ifdef WITH_GHOST_SDL
- int success = (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1 );
-# else
- /* set and restore environment variable */
- char *videodriver = getenv("SDL_VIDEODRIVER");
- BLI_setenv("SDL_VIDEODRIVER", "dummy");
-
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- int success = (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1 );
-#else
- int success = (SDL_InitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO) != -1 );
-#endif
-
- BLI_setenv("SDL_VIDEODRIVER", videodriver);
-# endif
-
- if (!success) {
- JOYSTICK_ECHO("Error-Initializing-SDL: " << SDL_GetError());
- return NULL;
- }
-
- m_joynum = SDL_NumJoysticks();
-
- for (i = 0; i < m_joynum; i++) {
- m_instance[i] = new SCA_Joystick(i);
- m_instance[i]->CreateJoystickDevice();
- }
- m_refCount = 1;
- }
- else
- {
- m_refCount++;
- }
- return m_instance[joyindex];
-#endif /* WITH_SDL */
-}
-
-void SCA_Joystick::ReleaseInstance()
-{
- if (--m_refCount == 0)
- {
-#ifdef WITH_SDL
- if (!SDL_CHECK(SDL_QuitSubSystem)) {
- return;
- }
- for (int i = 0; i < m_joynum; i++) {
- if (m_instance[i]) {
- m_instance[i]->DestroyJoystickDevice();
- delete m_instance[i];
- }
- m_instance[i] = NULL;
- }
-
- /* The video subsystem is required for joystick input to work. However,
- * when GHOST is running under SDL, video is freed elsewhere.
- * Do this once only. */
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_QuitSubSystem(SDL_INIT_JOYSTICK);
-#else
- SDL_QuitSubSystem(SDL_INIT_JOYSTICK | SDL_INIT_VIDEO);
-#endif
-#endif /* WITH_SDL */
- }
-}
-
-void SCA_Joystick::cSetPrecision(int val)
-{
- m_prec = val;
-}
-
-
-bool SCA_Joystick::aAxisPairIsPositive(int axis)
-{
- return (pAxisTest(axis) > m_prec) ? true:false;
-}
-
-bool SCA_Joystick::aAxisPairDirectionIsPositive(int axis, int dir)
-{
-
- int res;
-
- if (dir==JOYAXIS_UP || dir==JOYAXIS_DOWN)
- res = pGetAxis(axis, 1);
- else /* JOYAXIS_LEFT || JOYAXIS_RIGHT */
- res = pGetAxis(axis, 0);
-
- if (dir==JOYAXIS_DOWN || dir==JOYAXIS_RIGHT)
- return (res > m_prec) ? true : false;
- else /* JOYAXIS_UP || JOYAXIS_LEFT */
- return (res < -m_prec) ? true : false;
-}
-
-bool SCA_Joystick::aAxisIsPositive(int axis_single)
-{
- return abs(m_axis_array[axis_single]) > m_prec ? true:false;
-}
-
-bool SCA_Joystick::aAnyButtonPressIsPositive(void)
-{
-#ifdef WITH_SDL
- if (!SDL_CHECK(SDL_JoystickGetButton)) {
- return false;
- }
- /* this is needed for the "all events" option
- * so we know if there are no buttons pressed */
- for (int i=0; i<m_buttonmax; i++)
- if (SDL_JoystickGetButton(m_private->m_joystick, i))
- return true;
-#endif
- return false;
-}
-
-bool SCA_Joystick::aButtonPressIsPositive(int button)
-{
-#ifndef WITH_SDL
- return false;
-#else
- bool result;
- result = SDL_CHECK(SDL_JoystickGetButton) && SDL_JoystickGetButton(m_private->m_joystick, button);
- return result;
-#endif
-}
-
-
-bool SCA_Joystick::aButtonReleaseIsPositive(int button)
-{
-#ifndef WITH_SDL
- return false;
-#else
- bool result;
- result = !(SDL_CHECK(SDL_JoystickGetButton) && SDL_JoystickGetButton(m_private->m_joystick, button));
- return result;
-#endif
-}
-
-
-bool SCA_Joystick::aHatIsPositive(int hatnum, int dir)
-{
- return (GetHat(hatnum)==dir) ? true : false;
-}
-
-int SCA_Joystick::GetNumberOfAxes()
-{
- return m_axismax;
-}
-
-
-int SCA_Joystick::GetNumberOfButtons()
-{
- return m_buttonmax;
-}
-
-
-int SCA_Joystick::GetNumberOfHats()
-{
- return m_hatmax;
-}
-
-bool SCA_Joystick::CreateJoystickDevice(void)
-{
-#ifndef WITH_SDL
- m_isinit = true;
- m_axismax = m_buttonmax = m_hatmax = 0;
- return false;
-#else /* WITH_SDL */
- if (m_isinit == false && SDL_CHECK(SDL_JoystickOpen)) {
- if (m_joyindex>=m_joynum) {
- /* don't print a message, because this is done anyway */
- //JOYSTICK_ECHO("Joystick-Error: " << SDL_NumJoysticks() << " avaiable joystick(s)");
-
- /* Need this so python args can return empty lists */
- m_axismax = m_buttonmax = m_hatmax = 0;
- return false;
- }
-
- m_private->m_joystick = SDL_JoystickOpen(m_joyindex);
- SDL_JoystickEventState(SDL_ENABLE);
- m_isinit = true;
-
- JOYSTICK_ECHO("Joystick " << m_joyindex << " initialized");
-
- /* must run after being initialized */
- m_axismax = SDL_JoystickNumAxes(m_private->m_joystick);
- m_buttonmax = SDL_JoystickNumButtons(m_private->m_joystick);
- m_hatmax = SDL_JoystickNumHats(m_private->m_joystick);
-
- if (m_axismax > JOYAXIS_MAX) m_axismax = JOYAXIS_MAX; /* very unlikely */
- else if (m_axismax < 0) m_axismax = 0;
-
- if (m_hatmax > JOYHAT_MAX) m_hatmax = JOYHAT_MAX; /* very unlikely */
- else if (m_hatmax < 0) m_hatmax = 0;
-
- if (m_buttonmax < 0) m_buttonmax = 0;
-
- }
- return true;
-#endif /* WITH_SDL */
-}
-
-
-void SCA_Joystick::DestroyJoystickDevice(void)
-{
-#ifdef WITH_SDL
- if (m_isinit) {
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- if (SDL_CHECK(SDL_JoystickGetAttached) && SDL_JoystickGetAttached(m_private->m_joystick))
-#else
- if (SDL_CHECK(SDL_JoystickOpened) && SDL_JoystickOpened(m_joyindex))
-#endif
- {
- JOYSTICK_ECHO("Closing-joystick " << m_joyindex);
- SDL_JoystickClose(m_private->m_joystick);
- }
- m_isinit = false;
- }
-#endif /* WITH_SDL */
-}
-
-int SCA_Joystick::Connected(void)
-{
-#ifdef WITH_SDL
- if (m_isinit &&
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- SDL_CHECK(SDL_JoystickGetAttached) && SDL_JoystickGetAttached(m_private->m_joystick)
-#else
- SDL_CHECK(SDL_JoystickOpened) && SDL_JoystickOpened(m_joyindex)
-#endif
- )
- {
- return 1;
- }
-#endif
- return 0;
-}
-
-int SCA_Joystick::pGetAxis(int axisnum, int udlr)
-{
-#ifdef WITH_SDL
- return m_axis_array[(axisnum*2)+udlr];
-#endif
- return 0;
-}
-
-int SCA_Joystick::pAxisTest(int axisnum)
-{
-#ifdef WITH_SDL
- /* Use ints instead of shorts here to avoid problems when we get -32768.
- * When we take the negative of that later, we should get 32768, which is greater
- * than what a short can hold. In other words, abs(MIN_SHORT) > MAX_SHRT. */
- int i1 = m_axis_array[(axisnum * 2)];
- int i2 = m_axis_array[(axisnum * 2) + 1];
-
- /* long winded way to do:
- * return max_ff(absf(i1), absf(i2))
- * ...avoid abs from math.h */
- if (i1 < 0) i1 = -i1;
- if (i2 < 0) i2 = -i2;
- if (i1 <i2) return i2;
- else return i1;
-#else /* WITH_SDL */
- return 0;
-#endif /* WITH_SDL */
-}
-
-const char *SCA_Joystick::GetName()
-{
-#ifdef WITH_SDL
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- return (SDL_CHECK(SDL_JoystickName)) ? SDL_JoystickName(m_private->m_joystick) : "";
-#else
- return (SDL_CHECK(SDL_JoystickName)) ? SDL_JoystickName(m_joyindex) : "";
-#endif
-#else /* WITH_SDL */
- return "";
-#endif /* WITH_SDL */
-}
diff --git a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h b/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
deleted file mode 100644
index c9221753d45..00000000000
--- a/source/gameengine/GameLogic/Joystick/SCA_Joystick.h
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): snailrose.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_Joystick.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_JOYSTICK_H__
-#define __SCA_JOYSTICK_H__
-
-#include "SCA_JoystickDefines.h"
-#ifdef WITH_SDL
-/* SDL force defines __SSE__ and __SSE2__ flags, which generates warnings
- * because we pass those defines via command line as well. For until there's
- * proper ifndef added to SDL headers we ignore the redefinition warning.
- */
-# ifdef _MSC_VER
-# pragma warning(push)
-# pragma warning(disable : 4005)
-# endif
-# include "SDL.h"
-# ifdef _MSC_VER
-# pragma warning(pop)
-# endif
-#endif
-
-/**
- * Basic Joystick class
- * I will make this class a singleton because there should be only one joystick
- * even if there are more than one scene using it and count how many scene are using it.
- * The underlying joystick should only be removed when the last scene is removed
- */
-
-class SCA_Joystick
-
-{
- static SCA_Joystick *m_instance[JOYINDEX_MAX];
- static int m_joynum;
- static int m_refCount;
-
- class PrivateData;
-#ifdef WITH_SDL
- PrivateData *m_private;
-#endif
- int m_joyindex;
-
- /**
- *support for JOYAXIS_MAX axes (in pairs)
- */
- int m_axis_array[JOYAXIS_MAX];
-
- /**
- *support for JOYHAT_MAX hats (each is a direction)
- */
- int m_hat_array[JOYHAT_MAX];
-
- /**
- * Precision or range of the axes
- */
- int m_prec;
-
- /**
- * max # of buttons avail
- */
-
- int m_axismax;
- int m_buttonmax;
- int m_hatmax;
-
- /** is the joystick initialized ?*/
- bool m_isinit;
-
-
- /** is triggered for each event type */
- bool m_istrig_axis;
- bool m_istrig_button;
- bool m_istrig_hat;
-
-#ifdef WITH_SDL
- /**
- * event callbacks
- */
- void OnAxisMotion(SDL_Event *sdl_event);
- void OnHatMotion(SDL_Event *sdl_event);
- void OnButtonUp(SDL_Event *sdl_event);
- void OnButtonDown(SDL_Event *sdl_event);
- void OnNothing(SDL_Event *sdl_event);
-#if 0 /* not used yet */
- void OnBallMotion(SDL_Event *sdl_event) {}
-#endif
-
-#endif /* WITH_SDL */
- /**
- * Open the joystick
- */
- bool CreateJoystickDevice(void);
-
- /**
- * Close the joystick
- */
- void DestroyJoystickDevice(void);
-
- /**
- * fills the axis member values
- */
- void pFillButtons(void);
-
- /**
- * returns m_axis_array
- */
-
- int pAxisTest(int axisnum);
- /**
- * returns m_axis_array
- */
- int pGetAxis(int axisnum, int udlr);
-
- SCA_Joystick(short int index);
-
- ~SCA_Joystick();
-
-public:
-
- static SCA_Joystick *GetInstance(short int joyindex);
- static void HandleEvents(void);
- void ReleaseInstance();
-
-
- /*
- */
- bool aAxisPairIsPositive(int axis);
- bool aAxisPairDirectionIsPositive(int axis, int dir); /* function assumes joysticks are in axis pairs */
- bool aAxisIsPositive(int axis_single); /* check a single axis only */
-
- bool aAnyButtonPressIsPositive(void);
- bool aButtonPressIsPositive(int button);
- bool aButtonReleaseIsPositive(int button);
- bool aHatIsPositive(int hatnum, int dir);
-
- /**
- * precision is default '3200' which is overridden by input
- */
-
- void cSetPrecision(int val);
-
- int GetAxisPosition(int index) {
- return m_axis_array[index];
- }
-
- int GetHat(int index) {
- return m_hat_array[index];
- }
-
- int GetThreshold(void) {
- return m_prec;
- }
-
- bool IsTrigAxis(void) {
- return m_istrig_axis;
- }
-
- bool IsTrigButton(void) {
- return m_istrig_button;
- }
-
- bool IsTrigHat(void) {
- return m_istrig_hat;
- }
-
- /**
- * returns the # of...
- */
-
- int GetNumberOfAxes(void);
- int GetNumberOfButtons(void);
- int GetNumberOfHats(void);
-
- /**
- * Test if the joystick is connected
- */
- int Connected(void);
-
- /**
- * Name of the joytsick
- */
- const char *GetName();
-};
-
-#endif
-
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
deleted file mode 100644
index 566e5567507..00000000000
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickDefines.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): snailrose.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_JoystickDefines.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_JOYSTICKDEFINES_H__
-#define __SCA_JOYSTICKDEFINES_H__
-
-#ifdef main
-#undef main
-#endif
-
-#ifndef DEBUG
-# define JOYSTICK_ECHO(x)
-#else
-# include <iostream>
-# define JOYSTICK_ECHO(x) std::cout << x << std::endl;
-#endif
-
-#define JOYINDEX_MAX 8
-#define JOYAXIS_MAX 16
-#define JOYBUT_MAX 18
-#define JOYHAT_MAX 4
-
-#define JOYAXIS_RIGHT 0
-#define JOYAXIS_UP 1
-#define JOYAXIS_DOWN 3
-#define JOYAXIS_LEFT 2
-
-#endif
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp b/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
deleted file mode 100644
index 1dee1de9de2..00000000000
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): snailrose.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/Joystick/SCA_JoystickEvents.cpp
- * \ingroup gamelogic
- */
-
-#include "SCA_Joystick.h"
-#include "SCA_JoystickPrivate.h"
-
-#ifdef _MSC_VER
-# include <cstdio> /* printf */
-#endif
-
-#ifdef WITH_SDL
-void SCA_Joystick::OnAxisMotion(SDL_Event* sdl_event)
-{
- if (sdl_event->jaxis.axis >= JOYAXIS_MAX)
- return;
-
- m_axis_array[sdl_event->jaxis.axis] = sdl_event->jaxis.value;
- m_istrig_axis = 1;
-}
-
-/* See notes below in the event loop */
-void SCA_Joystick::OnHatMotion(SDL_Event* sdl_event)
-{
- if (sdl_event->jhat.hat >= JOYHAT_MAX)
- return;
-
- m_hat_array[sdl_event->jhat.hat] = sdl_event->jhat.value;
- m_istrig_hat = 1;
-}
-
-/* See notes below in the event loop */
-void SCA_Joystick::OnButtonUp(SDL_Event* sdl_event)
-{
- m_istrig_button = 1;
-}
-
-
-void SCA_Joystick::OnButtonDown(SDL_Event* sdl_event)
-{
- //if (sdl_event->jbutton.button > m_buttonmax) /* unsigned int so always above 0 */
- // return;
- // sdl_event->jbutton.button;
-
- m_istrig_button = 1;
-}
-
-
-void SCA_Joystick::OnNothing(SDL_Event* sdl_event)
-{
- m_istrig_axis = m_istrig_button = m_istrig_hat = 0;
-}
-
-void SCA_Joystick::HandleEvents(void)
-{
- SDL_Event sdl_event;
-
-#ifdef WITH_SDL_DYNLOAD
- if (SDL_PollEvent == (void*)0) {
- return;
- }
-#endif
-
- int i;
- for (i=0; i<m_joynum; i++) { /* could use JOYINDEX_MAX but no reason to */
- if (SCA_Joystick::m_instance[i])
- SCA_Joystick::m_instance[i]->OnNothing(&sdl_event);
- }
-
- while (SDL_PollEvent(&sdl_event)) {
- /* Note! m_instance[sdl_event.jaxis.which]
- * will segfault if over JOYINDEX_MAX, not too nice but what are the chances? */
-
- /* Note!, with buttons, this wont care which button is pressed,
- * only to set 'm_istrig_button', actual pressed buttons are detected by SDL_JoystickGetButton */
-
- /* Note!, if you manage to press and release a button within 1 logic tick
- * it wont work as it should */
-
- switch (sdl_event.type) {
- case SDL_JOYAXISMOTION:
- SCA_Joystick::m_instance[sdl_event.jaxis.which]->OnAxisMotion(&sdl_event);
- break;
- case SDL_JOYHATMOTION:
- SCA_Joystick::m_instance[sdl_event.jhat.which]->OnHatMotion(&sdl_event);
- break;
- case SDL_JOYBUTTONUP:
- SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonUp(&sdl_event);
- break;
- case SDL_JOYBUTTONDOWN:
- SCA_Joystick::m_instance[sdl_event.jbutton.which]->OnButtonDown(&sdl_event);
- break;
-#if 0 /* Not used yet */
- case SDL_JOYBALLMOTION:
- SCA_Joystick::m_instance[sdl_event.jball.which]->OnBallMotion(&sdl_event);
- break;
-#endif
-#if SDL_VERSION_ATLEAST(2, 0, 0)
- case SDL_JOYDEVICEADDED:
- case SDL_JOYDEVICEREMOVED:
- /* pass */
- break;
-#endif
- default:
- printf("SCA_Joystick::HandleEvents, Unknown SDL event (%d), this should not happen\n", sdl_event.type);
- break;
- }
- }
-}
-#endif /* WITH_SDL */
diff --git a/source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h b/source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h
deleted file mode 100644
index 472a7353190..00000000000
--- a/source/gameengine/GameLogic/Joystick/SCA_JoystickPrivate.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): snailrose.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_JoystickPrivate.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_JOYSTICKPRIVATE_H__
-#define __SCA_JOYSTICKPRIVATE_H__
-#include "SCA_Joystick.h"
-
-#ifdef WITH_SDL
-class SCA_Joystick::PrivateData
-{
-public:
- /*
- * The Joystick
- */
- SDL_Joystick* m_joystick;
-
- PrivateData()
- : m_joystick(NULL)
- {
- }
-};
-#endif /* WITH_SDL */
-
-#endif
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp b/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
deleted file mode 100644
index 6a87d3ccb98..00000000000
--- a/source/gameengine/GameLogic/SCA_2DFilterActuator.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * SCA_2DFilterActuator.cpp
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_2DFilterActuator.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_IActuator.h"
-#include "SCA_2DFilterActuator.h"
-
-#include <iostream>
-
-SCA_2DFilterActuator::~SCA_2DFilterActuator()
-{
-}
-
-SCA_2DFilterActuator::SCA_2DFilterActuator(
- SCA_IObject *gameobj,
- RAS_2DFilterManager::RAS_2DFILTER_MODE type,
- short flag,
- float float_arg,
- int int_arg,
- RAS_IRasterizer* rasterizer,
- SCA_IScene* scene)
- : SCA_IActuator(gameobj, KX_ACT_2DFILTER),
- m_type(type),
- m_disableMotionBlur(flag),
- m_float_arg(float_arg),
- m_int_arg(int_arg),
- m_rasterizer(rasterizer),
- m_scene(scene)
-{
- m_gameobj = NULL;
- if (gameobj) {
- m_propNames = gameobj->GetPropertyNames();
- m_gameobj = gameobj;
- }
-}
-
-
-CValue* SCA_2DFilterActuator::GetReplica()
-{
- SCA_2DFilterActuator* replica = new SCA_2DFilterActuator(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-
-bool SCA_2DFilterActuator::Update()
-{
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- if ( m_type == RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR )
- {
- if (!m_disableMotionBlur)
- m_rasterizer->EnableMotionBlur(m_float_arg);
- else
- m_rasterizer->DisableMotionBlur();
-
- return false;
- }
- else if (m_type < RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS)
- {
- m_scene->Update2DFilter(m_propNames, m_gameobj, m_type, m_int_arg, m_shaderText);
- }
- // once the filter is in place, no need to update it again => disable the actuator
- return false;
-}
-
-
-void SCA_2DFilterActuator::SetScene(SCA_IScene *scene)
-{
- m_scene = scene;
-}
-
-void SCA_2DFilterActuator::SetShaderText(const char *text)
-{
- m_shaderText = text;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_2DFilterActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_2DFilterActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_2DFilterActuator::Methods[] = {
- /* add python functions to deal with m_msg... */
- {NULL,NULL}
-};
-
-PyAttributeDef SCA_2DFilterActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("shaderText", 0, 64000, false, SCA_2DFilterActuator, m_shaderText),
- KX_PYATTRIBUTE_SHORT_RW("disableMotionBlur", 0, 1, true, SCA_2DFilterActuator, m_disableMotionBlur),
- KX_PYATTRIBUTE_ENUM_RW("mode",RAS_2DFilterManager::RAS_2DFILTER_ENABLED,RAS_2DFilterManager::RAS_2DFILTER_NUMBER_OF_FILTERS,false,SCA_2DFilterActuator,m_type),
- KX_PYATTRIBUTE_INT_RW("passNumber", 0, 100, true, SCA_2DFilterActuator, m_int_arg),
- KX_PYATTRIBUTE_FLOAT_RW("value", 0.0, 100.0, SCA_2DFilterActuator, m_float_arg),
- { NULL } //Sentinel
-};
-
-#endif
diff --git a/source/gameengine/GameLogic/SCA_2DFilterActuator.h b/source/gameengine/GameLogic/SCA_2DFilterActuator.h
deleted file mode 100644
index 4635a8ad9f8..00000000000
--- a/source/gameengine/GameLogic/SCA_2DFilterActuator.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * SCA_2DFilterActuator.h
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_2DFilterActuator.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_2DFILTERACTUATOR_H__
-#define __SCA_2DFILTERACTUATOR_H__
-
-#include "RAS_IRasterizer.h"
-#include "SCA_IActuator.h"
-#include "SCA_IScene.h"
-
-class SCA_2DFilterActuator : public SCA_IActuator
-{
- Py_Header
-
-private:
- vector<STR_String> m_propNames;
- RAS_2DFilterManager::RAS_2DFILTER_MODE m_type;
- short m_disableMotionBlur;
- float m_float_arg;
- int m_int_arg;
- STR_String m_shaderText;
- RAS_IRasterizer* m_rasterizer;
- SCA_IScene* m_scene;
-
-public:
-
- SCA_2DFilterActuator(
- class SCA_IObject* gameobj,
- RAS_2DFilterManager::RAS_2DFILTER_MODE type,
- short flag,
- float float_arg,
- int int_arg,
- RAS_IRasterizer* rasterizer,
- SCA_IScene* scene);
-
- void SetShaderText(const char *text);
- virtual ~SCA_2DFilterActuator();
- virtual bool Update();
-
- void SetScene(SCA_IScene *scene);
-
- virtual CValue* GetReplica();
-};
-#endif
diff --git a/source/gameengine/GameLogic/SCA_ANDController.cpp b/source/gameengine/GameLogic/SCA_ANDController.cpp
deleted file mode 100644
index 2cb7406779c..00000000000
--- a/source/gameengine/GameLogic/SCA_ANDController.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 'And' together all inputs
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_ANDController.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_ANDController.h"
-#include "SCA_ISensor.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_ANDController::SCA_ANDController(SCA_IObject* gameobj)
- :
- SCA_IController(gameobj)
-{
-}
-
-
-
-SCA_ANDController::~SCA_ANDController()
-{
-}
-
-
-
-void SCA_ANDController::Trigger(SCA_LogicManager* logicmgr)
-{
-
- bool sensorresult = true;
-
- for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- !(is==m_linkedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- if (!sensor->GetState())
- {
- sensorresult = false;
- break;
- }
- }
-
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,sensorresult);
- }
-}
-
-
-
-CValue* SCA_ANDController::GetReplica()
-{
- CValue* replica = new SCA_ANDController(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_ANDController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_ANDController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IController::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_ANDController::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_ANDController::Attributes[] = {
- { NULL } //Sentinel
-};
-#endif // WITH_PYTHON
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ANDController.h b/source/gameengine/GameLogic/SCA_ANDController.h
deleted file mode 100644
index ff152d6d2fb..00000000000
--- a/source/gameengine/GameLogic/SCA_ANDController.h
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- * SCA_ANDController.h
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_ANDController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ANDCONTROLLER_H__
-#define __SCA_ANDCONTROLLER_H__
-
-#include "SCA_IController.h"
-
-class SCA_ANDController : public SCA_IController
-{
- Py_Header
- //virtual void Trigger(class SCA_LogicManager* logicmgr);
-public:
- SCA_ANDController(SCA_IObject* gameobj);
- virtual ~SCA_ANDController();
- virtual CValue* GetReplica();
- virtual void Trigger(SCA_LogicManager* logicmgr);
-};
-
-#endif /* __SCA_ANDCONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp b/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp
deleted file mode 100644
index fcb236f0913..00000000000
--- a/source/gameengine/GameLogic/SCA_ActuatorEventManager.cpp
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_ActuatorEventManager.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_ISensor.h"
-#include "SCA_ActuatorEventManager.h"
-#include "SCA_ActuatorSensor.h"
-
-
-SCA_ActuatorEventManager::SCA_ActuatorEventManager(class SCA_LogicManager* logicmgr)
- : SCA_EventManager(logicmgr, ACTUATOR_EVENTMGR)
-{
-}
-
-
-
-SCA_ActuatorEventManager::~SCA_ActuatorEventManager()
-{
-
-}
-
-void SCA_ActuatorEventManager::NextFrame()
-{
- // check for changed actuator
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Activate(m_logicmgr);
- }
-}
-
-void SCA_ActuatorEventManager::UpdateFrame()
-{
- // update the state of actuator before executing them
- SG_DList::iterator<SCA_ActuatorSensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Update();
- }
-}
diff --git a/source/gameengine/GameLogic/SCA_ActuatorEventManager.h b/source/gameengine/GameLogic/SCA_ActuatorEventManager.h
deleted file mode 100644
index 997be1145db..00000000000
--- a/source/gameengine/GameLogic/SCA_ActuatorEventManager.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_ActuatorEventManager.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ACTUATOREVENTMANAGER_H__
-#define __SCA_ACTUATOREVENTMANAGER_H__
-
-#include "SCA_EventManager.h"
-
-#include <vector>
-
-using namespace std;
-
-class SCA_ActuatorEventManager : public SCA_EventManager
-{
-public:
- SCA_ActuatorEventManager(class SCA_LogicManager* logicmgr);
- virtual ~SCA_ActuatorEventManager();
- virtual void NextFrame();
- virtual void UpdateFrame();
- //SCA_LogicManager* GetLogicManager() { return m_logicmgr;}
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_ActuatorEventManager")
-#endif
-};
-
-#endif /* __SCA_ACTUATOREVENTMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp b/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
deleted file mode 100644
index 8b7702228ce..00000000000
--- a/source/gameengine/GameLogic/SCA_ActuatorSensor.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * Actuator sensor
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_ActuatorSensor.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include <iostream>
-#include "SCA_ActuatorSensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-
-SCA_ActuatorSensor::SCA_ActuatorSensor(SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const STR_String& actname)
- : SCA_ISensor(gameobj,eventmgr),
- m_checkactname(actname)
-{
- m_actuator = GetParent()->FindActuator(m_checkactname);
- Init();
-}
-
-void SCA_ActuatorSensor::Init()
-{
- m_lastresult = m_invert?true:false;
- m_midresult = m_lastresult;
- m_reset = true;
-}
-
-CValue* SCA_ActuatorSensor::GetReplica()
-{
- SCA_ActuatorSensor* replica = new SCA_ActuatorSensor(*this);
- // m_range_expr must be recalculated on replica!
- replica->ProcessReplica();
- replica->Init();
-
- return replica;
-}
-
-void SCA_ActuatorSensor::ReParent(SCA_IObject* parent)
-{
- m_actuator = parent->FindActuator(m_checkactname);
- SCA_ISensor::ReParent(parent);
-}
-
-bool SCA_ActuatorSensor::IsPositiveTrigger()
-{
- bool result = m_lastresult;
- if (m_invert)
- result = !result;
-
- return result;
-}
-
-
-
-SCA_ActuatorSensor::~SCA_ActuatorSensor()
-{
-}
-
-
-
-bool SCA_ActuatorSensor::Evaluate()
-{
- if (m_actuator)
- {
- bool result = m_actuator->IsActive();
- bool reset = m_reset && m_level;
-
- m_reset = false;
- if (m_lastresult != result || m_midresult != result)
- {
- m_lastresult = m_midresult = result;
- return true;
- }
- return (reset) ? true : false;
- }
- return false;
-}
-
-void SCA_ActuatorSensor::Update()
-{
- if (m_actuator)
- {
- m_midresult = m_actuator->IsActive() && !m_actuator->IsNegativeEvent();
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_ActuatorSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_ActuatorSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_ActuatorSensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_ActuatorSensor::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW_CHECK("actuator",0,MAX_PROP_NAME,false,SCA_ActuatorSensor,m_checkactname,CheckActuator),
- { NULL } //Sentinel
-};
-
-int SCA_ActuatorSensor::CheckActuator(void *self, const PyAttributeDef*)
-{
- SCA_ActuatorSensor* sensor = reinterpret_cast<SCA_ActuatorSensor*>(self);
- SCA_IActuator* act = sensor->GetParent()->FindActuator(sensor->m_checkactname);
- if (act) {
- sensor->m_actuator = act;
- return 0;
- }
- PyErr_SetString(PyExc_AttributeError, "string does not correspond to an actuator");
- return 1;
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ActuatorSensor.h b/source/gameengine/GameLogic/SCA_ActuatorSensor.h
deleted file mode 100644
index 6005bd3ac6c..00000000000
--- a/source/gameengine/GameLogic/SCA_ActuatorSensor.h
+++ /dev/null
@@ -1,70 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __SCA_ACTUATORSENSOR_H__
-#define __SCA_ACTUATORSENSOR_H__
-
-/** \file SCA_ActuatorSensor.h
- * \ingroup gamelogic
- */
-
-#include "SCA_ISensor.h"
-#include "SCA_IActuator.h"
-
-class SCA_ActuatorSensor : public SCA_ISensor
-{
- Py_Header
- STR_String m_checkactname;
- bool m_lastresult;
- bool m_midresult;
- protected:
- SCA_IActuator* m_actuator;
-public:
- SCA_ActuatorSensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const STR_String& actname);
-
- virtual ~SCA_ActuatorSensor();
- virtual CValue* GetReplica();
- virtual void Init();
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual void ReParent(SCA_IObject* parent);
- void Update();
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- static int CheckActuator(void *self, const PyAttributeDef*);
-
-#endif /* WITH_PYTHON */
-};
-
-#endif /* __SCA_ACTUATORSENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp b/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp
deleted file mode 100644
index 22746953a27..00000000000
--- a/source/gameengine/GameLogic/SCA_AlwaysEventManager.cpp
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Manager for 'always' events. Since always sensors can operate in pulse
- * mode, they need to be activated.
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_AlwaysEventManager.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_AlwaysEventManager.h"
-#include "SCA_LogicManager.h"
-#include <vector>
-#include "SCA_ISensor.h"
-
-using namespace std;
-
-SCA_AlwaysEventManager::SCA_AlwaysEventManager(class SCA_LogicManager* logicmgr)
- : SCA_EventManager(logicmgr, ALWAYS_EVENTMGR)
-{
-}
-
-
-
-void SCA_AlwaysEventManager::NextFrame()
-{
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Activate(m_logicmgr);
- }
-}
-
diff --git a/source/gameengine/GameLogic/SCA_AlwaysEventManager.h b/source/gameengine/GameLogic/SCA_AlwaysEventManager.h
deleted file mode 100644
index 47293c75726..00000000000
--- a/source/gameengine/GameLogic/SCA_AlwaysEventManager.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_AlwaysEventManager.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ALWAYSEVENTMANAGER_H__
-#define __SCA_ALWAYSEVENTMANAGER_H__
-#include "SCA_EventManager.h"
-#include <vector>
-
-using namespace std;
-class SCA_AlwaysEventManager : public SCA_EventManager
-{
-public:
- SCA_AlwaysEventManager(class SCA_LogicManager* logicmgr);
- virtual void NextFrame();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_AlwaysEventManager")
-#endif
-};
-
-#endif /* __SCA_ALWAYSEVENTMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp b/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
deleted file mode 100644
index 1a6a82a33eb..00000000000
--- a/source/gameengine/GameLogic/SCA_AlwaysSensor.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * Always trigger
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_AlwaysSensor.cpp
- * \ingroup gamelogic
- */
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning( disable:4786 )
-#endif
-
-#include "SCA_AlwaysSensor.h"
-#include "SCA_LogicManager.h"
-#include "SCA_EventManager.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_AlwaysSensor::SCA_AlwaysSensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj)
- : SCA_ISensor(gameobj,eventmgr)
-{
- //SetDrawColor(255,0,0);
- Init();
-}
-
-void SCA_AlwaysSensor::Init()
-{
- m_alwaysresult = true;
-}
-
-SCA_AlwaysSensor::~SCA_AlwaysSensor()
-{
- /* intentionally empty */
-}
-
-
-
-CValue* SCA_AlwaysSensor::GetReplica()
-{
- CValue* replica = new SCA_AlwaysSensor(*this);//m_float,GetName());
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-
-
-bool SCA_AlwaysSensor::IsPositiveTrigger()
-{
- return (m_invert ? false : true);
-}
-
-
-
-bool SCA_AlwaysSensor::Evaluate()
-{
- /* Nice! :) */
- //return true;
- /* even nicer ;) */
- //return false;
-
- /* nicest ! */
- bool result = m_alwaysresult;
- m_alwaysresult = false;
- return result;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_AlwaysSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_AlwaysSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_AlwaysSensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_AlwaysSensor::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_AlwaysSensor.h b/source/gameengine/GameLogic/SCA_AlwaysSensor.h
deleted file mode 100644
index e0ab4279b1c..00000000000
--- a/source/gameengine/GameLogic/SCA_AlwaysSensor.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * SCA_AlwaysSensor.h
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_AlwaysSensor.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ALWAYSSENSOR_H__
-#define __SCA_ALWAYSSENSOR_H__
-#include "SCA_ISensor.h"
-
-class SCA_AlwaysSensor : public SCA_ISensor
-{
- Py_Header
- bool m_alwaysresult;
-public:
- SCA_AlwaysSensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj);
- virtual ~SCA_AlwaysSensor();
- virtual CValue* GetReplica();
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual void Init();
-};
-
-#endif /* __SCA_ALWAYSSENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_BasicEventManager.cpp b/source/gameengine/GameLogic/SCA_BasicEventManager.cpp
deleted file mode 100644
index e87f9b8f0e4..00000000000
--- a/source/gameengine/GameLogic/SCA_BasicEventManager.cpp
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * Manager for 'always' events. Since always sensors can operate in pulse
- * mode, they need to be activated.
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_BasicEventManager.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_BasicEventManager.h"
-#include "SCA_LogicManager.h"
-#include <vector>
-#include "SCA_ISensor.h"
-
-using namespace std;
-
-SCA_BasicEventManager::SCA_BasicEventManager(class SCA_LogicManager* logicmgr)
- : SCA_EventManager(logicmgr, BASIC_EVENTMGR)
-{
-}
-
-SCA_BasicEventManager::~SCA_BasicEventManager()
-{
-}
-
-void SCA_BasicEventManager::NextFrame()
-{
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Activate(m_logicmgr);
- }
-}
-
diff --git a/source/gameengine/GameLogic/SCA_BasicEventManager.h b/source/gameengine/GameLogic/SCA_BasicEventManager.h
deleted file mode 100644
index a015233454b..00000000000
--- a/source/gameengine/GameLogic/SCA_BasicEventManager.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Manager for sensor that only need to call Update
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_BasicEventManager.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_BASICEVENTMANAGER_H__
-#define __SCA_BASICEVENTMANAGER_H__
-
-#include "SCA_EventManager.h"
-#include <vector>
-
-using namespace std;
-
-class SCA_BasicEventManager : public SCA_EventManager
-{
-public:
- SCA_BasicEventManager(class SCA_LogicManager* logicmgr);
- ~SCA_BasicEventManager();
-
- virtual void NextFrame();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_BasicEventManager")
-#endif
-};
-
-#endif /* __SCA_BASICEVENTMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.cpp b/source/gameengine/GameLogic/SCA_DelaySensor.cpp
deleted file mode 100644
index af751cffc2e..00000000000
--- a/source/gameengine/GameLogic/SCA_DelaySensor.cpp
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Delay trigger
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_DelaySensor.cpp
- * \ingroup gamelogic
- */
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning( disable:4786 )
-#endif
-
-#include <stddef.h>
-
-#include "SCA_DelaySensor.h"
-#include "SCA_LogicManager.h"
-#include "SCA_EventManager.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_DelaySensor::SCA_DelaySensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- int delay,
- int duration,
- bool repeat)
- : SCA_ISensor(gameobj,eventmgr),
- m_repeat(repeat),
- m_delay(delay),
- m_duration(duration)
-{
- Init();
-}
-
-void SCA_DelaySensor::Init()
-{
- m_lastResult = false;
- m_frameCount = -1;
- m_reset = true;
-}
-
-SCA_DelaySensor::~SCA_DelaySensor()
-{
- /* intentionally empty */
-}
-
-CValue* SCA_DelaySensor::GetReplica()
-{
- CValue* replica = new SCA_DelaySensor(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-
-
-bool SCA_DelaySensor::IsPositiveTrigger()
-{
- return (m_invert ? !m_lastResult : m_lastResult);
-}
-
-bool SCA_DelaySensor::Evaluate()
-{
- bool trigger = false;
- bool result;
-
- if (m_frameCount==-1) {
- // this is needed to ensure ON trigger in case delay==0
- // and avoid spurious OFF trigger when duration==0
- m_lastResult = false;
- m_frameCount = 0;
- }
-
- if (m_frameCount<m_delay) {
- m_frameCount++;
- result = false;
- } else if (m_duration > 0) {
- if (m_frameCount < m_delay+m_duration) {
- m_frameCount++;
- result = true;
- } else {
- result = false;
- if (m_repeat)
- m_frameCount = -1;
- }
- } else {
- result = true;
- if (m_repeat)
- m_frameCount = -1;
- }
- if ((m_reset && m_level) || result != m_lastResult)
- trigger = true;
- m_reset = false;
- m_lastResult = result;
- return trigger;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_DelaySensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_DelaySensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_DelaySensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_DelaySensor::Attributes[] = {
- KX_PYATTRIBUTE_INT_RW("delay",0,100000,true,SCA_DelaySensor,m_delay),
- KX_PYATTRIBUTE_INT_RW("duration",0,100000,true,SCA_DelaySensor,m_duration),
- KX_PYATTRIBUTE_BOOL_RW("repeat",SCA_DelaySensor,m_repeat),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_DelaySensor.h b/source/gameengine/GameLogic/SCA_DelaySensor.h
deleted file mode 100644
index 9b39de7e099..00000000000
--- a/source/gameengine/GameLogic/SCA_DelaySensor.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * SCA_DelaySensor.h
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_DelaySensor.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_DELAYSENSOR_H__
-#define __SCA_DELAYSENSOR_H__
-#include "SCA_ISensor.h"
-
-class SCA_DelaySensor : public SCA_ISensor
-{
- Py_Header
- bool m_lastResult;
- bool m_repeat;
- int m_delay;
- int m_duration;
- int m_frameCount;
-
-public:
- SCA_DelaySensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- int delay,
- int duration,
- bool repeat);
- virtual ~SCA_DelaySensor();
- virtual CValue* GetReplica();
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual void Init();
-
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-};
-
-#endif /* __SCA_DELAYSENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_EventManager.cpp b/source/gameengine/GameLogic/SCA_EventManager.cpp
deleted file mode 100644
index ffe1ea2dc30..00000000000
--- a/source/gameengine/GameLogic/SCA_EventManager.cpp
+++ /dev/null
@@ -1,83 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_EventManager.cpp
- * \ingroup gamelogic
- */
-
-
-#include <assert.h>
-#include "SCA_EventManager.h"
-#include "SCA_ISensor.h"
-
-
-SCA_EventManager::SCA_EventManager(SCA_LogicManager* logicmgr, EVENT_MANAGER_TYPE mgrtype)
- :m_logicmgr(logicmgr),
- m_mgrtype(mgrtype)
-{
-}
-
-
-
-SCA_EventManager::~SCA_EventManager()
-{
- // all sensors should be removed
- assert(m_sensors.Empty());
-}
-
-void SCA_EventManager::RegisterSensor(class SCA_ISensor* sensor)
-{
- m_sensors.AddBack(sensor);
-}
-
-void SCA_EventManager::RemoveSensor(class SCA_ISensor* sensor)
-{
- sensor->Delink();
-}
-
-void SCA_EventManager::NextFrame(double curtime, double fixedtime)
-{
- NextFrame();
-}
-
-void SCA_EventManager::NextFrame()
-{
- assert(false); // && "Event managers should override a NextFrame method");
-}
-
-void SCA_EventManager::EndFrame()
-{
-}
-
-void SCA_EventManager::UpdateFrame()
-{
-}
-
-int SCA_EventManager::GetType()
-{
- return (int) m_mgrtype;
-}
diff --git a/source/gameengine/GameLogic/SCA_EventManager.h b/source/gameengine/GameLogic/SCA_EventManager.h
deleted file mode 100644
index eb9a6d9aca1..00000000000
--- a/source/gameengine/GameLogic/SCA_EventManager.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_EventManager.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_EVENTMANAGER_H__
-#define __SCA_EVENTMANAGER_H__
-
-#include <vector>
-#include <set>
-#include <algorithm>
-
-#include "SG_DList.h"
-
-class SCA_EventManager
-{
-protected:
- class SCA_LogicManager* m_logicmgr; /* all event manager subclasses use this (other then TimeEventManager) */
-
- // use a set to speed-up insertion/removal
- //std::set <class SCA_ISensor*> m_sensors;
- SG_DList m_sensors;
-
-public:
- enum EVENT_MANAGER_TYPE {
- KEYBOARD_EVENTMGR = 0,
- MOUSE_EVENTMGR,
- ALWAYS_EVENTMGR,
- TOUCH_EVENTMGR,
- PROPERTY_EVENTMGR,
- TIME_EVENTMGR,
- RANDOM_EVENTMGR,
- RAY_EVENTMGR,
- NETWORK_EVENTMGR,
- JOY_EVENTMGR,
- ACTUATOR_EVENTMGR,
- BASIC_EVENTMGR
- };
-
- SCA_EventManager(SCA_LogicManager* logicmgr, EVENT_MANAGER_TYPE mgrtype);
- virtual ~SCA_EventManager();
-
- virtual void RemoveSensor(class SCA_ISensor* sensor);
- virtual void NextFrame(double curtime, double fixedtime);
- virtual void NextFrame();
- virtual void UpdateFrame();
- virtual void EndFrame();
- virtual void RegisterSensor(class SCA_ISensor* sensor);
- int GetType();
- //SG_DList &GetSensors() { return m_sensors; }
-
-
- void Replace_LogicManager(SCA_LogicManager* logicmgr) { m_logicmgr= logicmgr; }
-
-protected:
- EVENT_MANAGER_TYPE m_mgrtype;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_EventManager")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.cpp b/source/gameengine/GameLogic/SCA_ExpressionController.cpp
deleted file mode 100644
index ef058e215d6..00000000000
--- a/source/gameengine/GameLogic/SCA_ExpressionController.cpp
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- * 'Expression Controller enables to calculate an expression that wires inputs to output
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_ExpressionController.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_ExpressionController.h"
-#include "SCA_ISensor.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-#include "EXP_InputParser.h"
-#include "MT_Transform.h" // for fuzzyZero
-
-#include <stdio.h>
-
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_ExpressionController::SCA_ExpressionController(SCA_IObject* gameobj,
- const STR_String& exprtext)
- :SCA_IController(gameobj),
- m_exprText(exprtext),
- m_exprCache(NULL)
-{
-}
-
-
-
-SCA_ExpressionController::~SCA_ExpressionController()
-{
- if (m_exprCache)
- m_exprCache->Release();
-}
-
-
-
-CValue* SCA_ExpressionController::GetReplica()
-{
- SCA_ExpressionController* replica = new SCA_ExpressionController(*this);
- replica->m_exprText = m_exprText;
- replica->m_exprCache = NULL;
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-
-// Forced deletion of precalculated expression to break reference loop
-// Use this function when you know that you won't use the sensor anymore
-void SCA_ExpressionController::Delete()
-{
- if (m_exprCache)
- {
- m_exprCache->Release();
- m_exprCache = NULL;
- }
- Release();
-}
-
-
-void SCA_ExpressionController::Trigger(SCA_LogicManager* logicmgr)
-{
-
- bool expressionresult = false;
- if (!m_exprCache)
- {
- CParser parser;
- parser.SetContext(this->AddRef());
- m_exprCache = parser.ProcessText(m_exprText);
- }
- if (m_exprCache)
- {
- CValue* value = m_exprCache->Calculate();
- if (value)
- {
- if (value->IsError())
- {
- printf("%s\n", value->GetText().ReadPtr());
- } else
- {
- float num = (float)value->GetNumber();
- expressionresult = !MT_fuzzyZero(num);
- }
- value->Release();
-
- }
- }
-
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,expressionresult);
- }
-}
-
-
-
-CValue* SCA_ExpressionController::FindIdentifier(const STR_String& identifiername)
-{
-
- CValue* identifierval = NULL;
-
- for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- !(is==m_linkedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- if (sensor->GetName() == identifiername)
- {
- identifierval = new CBoolValue(sensor->GetState());
- //identifierval = sensor->AddRef();
- break;
- }
-
- //if (!sensor->IsPositiveTrigger())
- //{
- // sensorresult = false;
- // break;
- //}
- }
-
- if (identifierval)
- return identifierval;
-
- return GetParent()->FindIdentifier(identifiername);
-
-}
diff --git a/source/gameengine/GameLogic/SCA_ExpressionController.h b/source/gameengine/GameLogic/SCA_ExpressionController.h
deleted file mode 100644
index c16944ccde1..00000000000
--- a/source/gameengine/GameLogic/SCA_ExpressionController.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * KX_EXPRESSIONController.h
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_ExpressionController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_EXPRESSIONCONTROLLER_H__
-#define __SCA_EXPRESSIONCONTROLLER_H__
-
-#include "SCA_IController.h"
-
-class SCA_ExpressionController : public SCA_IController
-{
-// Py_Header
- STR_String m_exprText;
- CExpression* m_exprCache;
-
-public:
- SCA_ExpressionController(SCA_IObject* gameobj,
- const STR_String& exprtext);
-
- virtual ~SCA_ExpressionController();
- virtual CValue* GetReplica();
- virtual void Trigger(SCA_LogicManager* logicmgr);
- virtual CValue* FindIdentifier(const STR_String& identifiername);
- /**
- * used to release the expression cache
- * so that self references are removed before the controller itself is released
- */
- virtual void Delete();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_ExpressionController")
-#endif
-};
-
-#endif /* __SCA_EXPRESSIONCONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_IActuator.cpp b/source/gameengine/GameLogic/SCA_IActuator.cpp
deleted file mode 100644
index 9a355fdf3c9..00000000000
--- a/source/gameengine/GameLogic/SCA_IActuator.cpp
+++ /dev/null
@@ -1,140 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_IActuator.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_IActuator.h"
-#include <stdio.h>
-
-using namespace std;
-
-SCA_IActuator::SCA_IActuator(SCA_IObject* gameobj, KX_ACTUATOR_TYPE type) :
- SCA_ILogicBrick(gameobj),
- m_type(type),
- m_links(0),
- m_posevent(false),
- m_negevent(false)
-{
- // nothing to do
-}
-
-bool SCA_IActuator::Update(double curtime, bool frame)
-{
- if (frame)
- return Update();
-
- return true;
-}
-
-bool SCA_IActuator::Update()
-{
- assert(false && "Actuators should override an Update method.");
- return false;
-}
-
-void SCA_IActuator::Activate(SG_DList& head)
-{
- if (QEmpty())
- {
- InsertActiveQList(m_gameobj->m_activeActuators);
- head.AddBack(&m_gameobj->m_activeActuators);
- }
-}
-
-// this function is only used to deactivate actuators outside the logic loop
-// e.g. when an object is deleted.
-void SCA_IActuator::Deactivate()
-{
- if (QDelink())
- {
- // the actuator was in the active list
- if (m_gameobj->m_activeActuators.QEmpty())
- // the owner object has no more active actuators, remove it from the global list
- m_gameobj->m_activeActuators.Delink();
- }
-}
-
-
-void SCA_IActuator::ProcessReplica()
-{
- SCA_ILogicBrick::ProcessReplica();
- RemoveAllEvents();
- m_linkedcontrollers.clear();
-}
-
-
-
-SCA_IActuator::~SCA_IActuator()
-{
- RemoveAllEvents();
-}
-
-void SCA_IActuator::DecLink()
-{
- m_links--;
- if (m_links < 0)
- {
- printf("Warning: actuator %s has negative m_links: %d\n", m_name.Ptr(), m_links);
- m_links = 0;
- }
-}
-
-void SCA_IActuator::LinkToController(SCA_IController* controller)
-{
- m_linkedcontrollers.push_back(controller);
-}
-
-void SCA_IActuator::UnlinkController(SCA_IController* controller)
-{
- std::vector<class SCA_IController*>::iterator contit;
- for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
- {
- if ((*contit) == controller)
- {
- *contit = m_linkedcontrollers.back();
- m_linkedcontrollers.pop_back();
- return;
- }
- }
- printf("Missing link from actuator %s:%s to controller %s:%s\n",
- m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
- controller->GetParent()->GetName().ReadPtr(), controller->GetName().ReadPtr());
-}
-
-void SCA_IActuator::UnlinkAllControllers()
-{
- std::vector<class SCA_IController*>::iterator contit;
- for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
- {
- (*contit)->UnlinkActuator(this);
- }
- m_linkedcontrollers.clear();
-}
-
diff --git a/source/gameengine/GameLogic/SCA_IActuator.h b/source/gameengine/GameLogic/SCA_IActuator.h
deleted file mode 100644
index b63cb633b4e..00000000000
--- a/source/gameengine/GameLogic/SCA_IActuator.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_IActuator.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_IACTUATOR_H__
-#define __SCA_IACTUATOR_H__
-
-#include "SCA_IController.h"
-#include <vector>
-
-/**
- * Use of SG_DList : None
- * Use of SG_QList : element of activated actuator list of their owner
- * Head: SCA_IObject::m_activeActuators
- */
-class SCA_IActuator : public SCA_ILogicBrick
-{
- friend class SCA_LogicManager;
-protected:
- int m_type;
- int m_links; // number of active links to controllers
- // when 0, the actuator is automatically stopped
- //std::vector<CValue*> m_events;
- bool m_posevent;
- bool m_negevent;
-
- std::vector<class SCA_IController*> m_linkedcontrollers;
-
- void RemoveAllEvents()
- {
- m_posevent = false;
- m_negevent = false;
- }
-
-
-public:
- /**
- * This class also inherits the default copy constructors
- */
- enum KX_ACTUATOR_TYPE {
- KX_ACT_OBJECT,
- KX_ACT_IPO,
- KX_ACT_CAMERA,
- KX_ACT_SOUND,
- KX_ACT_PROPERTY,
- KX_ACT_ADD_OBJECT,
- KX_ACT_END_OBJECT,
- KX_ACT_DYNAMIC,
- KX_ACT_REPLACE_MESH,
- KX_ACT_TRACKTO,
- KX_ACT_CONSTRAINT,
- KX_ACT_SCENE,
- KX_ACT_RANDOM,
- KX_ACT_MESSAGE,
- KX_ACT_ACTION,
- KX_ACT_CD,
- KX_ACT_GAME,
- KX_ACT_VISIBILITY,
- KX_ACT_2DFILTER,
- KX_ACT_PARENT,
- KX_ACT_SHAPEACTION,
- KX_ACT_STATE,
- KX_ACT_ARMATURE,
- KX_ACT_STEERING,
- KX_ACT_MOUSE,
- };
-
- SCA_IActuator(SCA_IObject* gameobj, KX_ACTUATOR_TYPE type);
-
- /**
- * UnlinkObject(...)
- * Certain actuator use gameobject pointers (like TractTo actuator)
- * This function can be called when an object is removed to make
- * sure that the actuator will not use it anymore.
- */
-
- virtual bool UnlinkObject(SCA_IObject* clientobj) { return false; }
-
- /**
- * Update(...)
- * Update the actuator based upon the events received since
- * the last call to Update, the current time and deltatime the
- * time elapsed in this frame ?
- * It is the responsibility of concrete Actuators to clear
- * their event's. This is usually done in the Update() method via
- * a call to RemoveAllEvents()
- */
-
-
- virtual bool Update(double curtime, bool frame);
- virtual bool Update();
-
- /**
- * Add an event to an actuator.
- */
- //void AddEvent(CValue* event)
- void AddEvent(bool event)
- {
- if (event)
- m_posevent = true;
- else
- m_negevent = true;
- }
-
- virtual void ProcessReplica();
-
- /**
- * Return true if all the current events
- * are negative. The definition of negative event is
- * not immediately clear. But usually refers to key-up events
- * or events where no action is required.
- */
- bool IsNegativeEvent() const
- {
- return !m_posevent && m_negevent;
- }
-
- virtual ~SCA_IActuator();
-
- /**
- * remove this actuator from the list of active actuators
- */
- virtual void Deactivate();
- virtual void Activate(SG_DList& head);
-
- void LinkToController(SCA_IController* controller);
- void UnlinkController(class SCA_IController* cont);
- void UnlinkAllControllers();
-
- void ClrLink() { m_links=0; }
- void IncLink() { m_links++; }
- virtual void DecLink();
- bool IsNoLink() const { return !m_links; }
- bool IsType(KX_ACTUATOR_TYPE type) { return m_type == type; }
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_IActuator")
-#endif
-};
-
-#endif /* __SCA_IACTUATOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_IController.cpp b/source/gameengine/GameLogic/SCA_IController.cpp
deleted file mode 100644
index c4176d66688..00000000000
--- a/source/gameengine/GameLogic/SCA_IController.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_IController.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_IController.h"
-#include "SCA_LogicManager.h"
-#include "SCA_IActuator.h"
-#include "SCA_ISensor.h"
-#include "EXP_PyObjectPlus.h"
-#include "EXP_ListWrapper.h"
-
-#include <stdio.h>
-
-SCA_IController::SCA_IController(SCA_IObject* gameobj)
- :
- SCA_ILogicBrick(gameobj),
- m_statemask(0),
- m_justActivated(false)
-{
-}
-
-
-
-SCA_IController::~SCA_IController()
-{
- //UnlinkAllActuators();
-}
-
-
-
-std::vector<class SCA_ISensor*>& SCA_IController::GetLinkedSensors()
-{
- return m_linkedsensors;
-}
-
-
-
-std::vector<class SCA_IActuator*>& SCA_IController::GetLinkedActuators()
-{
- return m_linkedactuators;
-}
-
-
-
-void SCA_IController::UnlinkAllSensors()
-{
- std::vector<class SCA_ISensor*>::iterator sensit;
- for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
- {
- if (IsActive())
- {
- (*sensit)->DecLink();
- }
- (*sensit)->UnlinkController(this);
- }
- m_linkedsensors.clear();
-}
-
-
-
-void SCA_IController::UnlinkAllActuators()
-{
- std::vector<class SCA_IActuator*>::iterator actit;
- for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
- {
- if (IsActive())
- {
- (*actit)->DecLink();
- }
- (*actit)->UnlinkController(this);
- }
- m_linkedactuators.clear();
-}
-
-void SCA_IController::LinkToActuator(SCA_IActuator* actua)
-{
- m_linkedactuators.push_back(actua);
- if (IsActive())
- {
- actua->IncLink();
- }
-}
-
-void SCA_IController::UnlinkActuator(class SCA_IActuator* actua)
-{
- std::vector<class SCA_IActuator*>::iterator actit;
- for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
- {
- if ((*actit) == actua)
- {
- if (IsActive())
- {
- (*actit)->DecLink();
- }
- *actit = m_linkedactuators.back();
- m_linkedactuators.pop_back();
- return;
- }
- }
- printf("Missing link from controller %s:%s to actuator %s:%s\n",
- m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
- actua->GetParent()->GetName().ReadPtr(), actua->GetName().ReadPtr());
-}
-
-void SCA_IController::LinkToSensor(SCA_ISensor* sensor)
-{
- m_linkedsensors.push_back(sensor);
- if (IsActive())
- {
- sensor->IncLink();
- }
-}
-
-void SCA_IController::UnlinkSensor(class SCA_ISensor* sensor)
-{
- std::vector<class SCA_ISensor*>::iterator sensit;
- for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
- {
- if ((*sensit) == sensor)
- {
- if (IsActive())
- {
- sensor->DecLink();
- }
- *sensit = m_linkedsensors.back();
- m_linkedsensors.pop_back();
- return;
- }
- }
- printf("Missing link from controller %s:%s to sensor %s:%s\n",
- m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
- sensor->GetParent()->GetName().ReadPtr(), sensor->GetName().ReadPtr());
-}
-
-
-void SCA_IController::ApplyState(unsigned int state)
-{
- std::vector<class SCA_IActuator*>::iterator actit;
- std::vector<class SCA_ISensor*>::iterator sensit;
-
- if (m_statemask & state)
- {
- if (!IsActive())
- {
- // reactive the controller, all the links to actuator are valid again
- for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
- {
- (*actit)->IncLink();
- }
-
- for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
- {
- (*sensit)->IncLink();
- }
- SetActive(true);
- m_justActivated = true;
- }
- } else if (IsActive())
- {
- for (actit = m_linkedactuators.begin();!(actit==m_linkedactuators.end());++actit)
- {
- (*actit)->DecLink();
- }
- for (sensit = m_linkedsensors.begin();!(sensit==m_linkedsensors.end());++sensit)
- {
- (*sensit)->DecLink();
- }
- SetActive(false);
- m_justActivated = false;
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* Python api */
-
-PyTypeObject SCA_IController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_IController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ILogicBrick::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_IController::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_IController::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("state", SCA_IController, pyattr_get_state),
- KX_PYATTRIBUTE_RO_FUNCTION("sensors", SCA_IController, pyattr_get_sensors),
- KX_PYATTRIBUTE_RO_FUNCTION("actuators", SCA_IController, pyattr_get_actuators),
- KX_PYATTRIBUTE_BOOL_RW("useHighPriority",SCA_IController,m_bookmark),
- { NULL } //Sentinel
-};
-
-PyObject *SCA_IController::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_IController* self = static_cast<SCA_IController*>(self_v);
- return PyLong_FromLong(self->m_statemask);
-}
-
-static int sca_icontroller_get_sensors_size_cb(void *self_v)
-{
- return ((SCA_IController *)self_v)->GetLinkedSensors().size();
-}
-
-static PyObject *sca_icontroller_get_sensors_item_cb(void *self_v, int index)
-{
- return ((SCA_IController *)self_v)->GetLinkedSensors()[index]->GetProxy();
-}
-
-static const char *sca_icontroller_get_sensors_item_name_cb(void *self_v, int index)
-{
- return ((SCA_IController *)self_v)->GetLinkedSensors()[index]->GetName().ReadPtr();
-}
-
-PyObject *SCA_IController::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return (new CListWrapper(self_v,
- ((SCA_IController *)self_v)->GetProxy(),
- NULL,
- sca_icontroller_get_sensors_size_cb,
- sca_icontroller_get_sensors_item_cb,
- sca_icontroller_get_sensors_item_name_cb,
- NULL))->NewProxy(true);
-}
-
-static int sca_icontroller_get_actuators_size_cb(void *self_v)
-{
- return ((SCA_IController *)self_v)->GetLinkedActuators().size();
-}
-
-static PyObject *sca_icontroller_get_actuators_item_cb(void *self_v, int index)
-{
- return ((SCA_IController *)self_v)->GetLinkedActuators()[index]->GetProxy();
-}
-
-static const char *sca_icontroller_get_actuators_item_name_cb(void *self_v, int index)
-{
- return ((SCA_IController *)self_v)->GetLinkedActuators()[index]->GetName().ReadPtr();
-}
-
-PyObject *SCA_IController::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return (new CListWrapper(self_v,
- ((SCA_IController *)self_v)->GetProxy(),
- NULL,
- sca_icontroller_get_actuators_size_cb,
- sca_icontroller_get_actuators_item_cb,
- sca_icontroller_get_actuators_item_name_cb,
- NULL))->NewProxy(true);
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/GameLogic/SCA_IController.h b/source/gameengine/GameLogic/SCA_IController.h
deleted file mode 100644
index 4ec872c2316..00000000000
--- a/source/gameengine/GameLogic/SCA_IController.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_IController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ICONTROLLER_H__
-#define __SCA_ICONTROLLER_H__
-
-#include "SCA_ILogicBrick.h"
-#include "EXP_PyObjectPlus.h"
-
-/**
- * Use of SG_DList element: none
- * Use of SG_QList element: build ordered list of activated controller on the owner object
- * Head: SCA_IObject::m_activeControllers
- */
-class SCA_IController : public SCA_ILogicBrick
-{
- Py_Header
-protected:
- std::vector<class SCA_ISensor*> m_linkedsensors;
- std::vector<class SCA_IActuator*> m_linkedactuators;
- unsigned int m_statemask;
- bool m_justActivated;
- bool m_bookmark;
-public:
- SCA_IController(SCA_IObject* gameobj);
- virtual ~SCA_IController();
- virtual void Trigger(class SCA_LogicManager* logicmgr)=0;
- void LinkToSensor(SCA_ISensor* sensor);
- void LinkToActuator(SCA_IActuator*);
- std::vector<class SCA_ISensor*>& GetLinkedSensors();
- std::vector<class SCA_IActuator*>& GetLinkedActuators();
- void ReserveActuator(int num)
- {
- m_linkedactuators.reserve(num);
- }
- void UnlinkAllSensors();
- void UnlinkAllActuators();
- void UnlinkActuator(class SCA_IActuator* actua);
- void UnlinkSensor(class SCA_ISensor* sensor);
- void SetState(unsigned int state) { m_statemask = state; }
- void ApplyState(unsigned int state);
- void Deactivate()
- {
- // the controller can only be part of a sensor m_newControllers list
- Delink();
- }
- bool IsJustActivated()
- {
- return m_justActivated;
- }
- void ClrJustActivated()
- {
- m_justActivated = false;
- }
- void SetBookmark(bool bookmark)
- {
- m_bookmark = bookmark;
- }
- void Activate(SG_DList& head)
- {
- if (QEmpty())
- {
- if (m_bookmark)
- {
- m_gameobj->m_activeBookmarkedControllers.QAddBack(this);
- head.AddFront(&m_gameobj->m_activeBookmarkedControllers);
- }
- else
- {
- InsertActiveQList(m_gameobj->m_activeControllers);
- head.AddBack(&m_gameobj->m_activeControllers);
- }
- }
- }
-
-
-#ifdef WITH_PYTHON
- static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif /* WITH_PYTHON */
-};
-
-#endif /* __SCA_ICONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_IInputDevice.cpp b/source/gameengine/GameLogic/SCA_IInputDevice.cpp
deleted file mode 100644
index f4fce034c87..00000000000
--- a/source/gameengine/GameLogic/SCA_IInputDevice.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_IInputDevice.cpp
- * \ingroup gamelogic
- */
-
-
-#include <assert.h>
-#include "SCA_IInputDevice.h"
-
-SCA_IInputDevice::SCA_IInputDevice()
- :
- m_currentTable(0)
-{
- ClearStatusTable(0);
- ClearStatusTable(1);
-}
-
-
-
-SCA_IInputDevice::~SCA_IInputDevice()
-{
-}
-
-void SCA_IInputDevice::HookEscape()
-{
- assert(false && "This device does not support hooking escape.");
-}
-
-void SCA_IInputDevice::ClearStatusTable(int tableid)
-{
- for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
- m_eventStatusTables[tableid][i]=SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS,0);
-}
-
-
-
-const SCA_InputEvent& SCA_IInputDevice::GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
-// cerr << "SCA_IInputDevice::GetEventValue" << endl;
- return m_eventStatusTables[m_currentTable][inputcode];
-}
-
-
-
-int SCA_IInputDevice::GetNumActiveEvents()
-{
- int num = 0;
-
- // cerr << "SCA_IInputDevice::GetNumActiveEvents" << endl;
-
- for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
- {
- const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
- if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
- || (event.m_status == SCA_InputEvent::KX_ACTIVE))
- num++;
- }
-
- return num;
-}
-
-
-
-int SCA_IInputDevice::GetNumJustEvents()
-{
- int num = 0;
-
- // cerr << "SCA_IInputDevice::GetNumJustEvents" << endl;
-
- for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
- {
- const SCA_InputEvent& event = m_eventStatusTables[m_currentTable][i];
- if ((event.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
- || (event.m_status == SCA_InputEvent::KX_JUSTRELEASED))
- num++;
- }
-
- return num;
-}
-
-
-
-void SCA_IInputDevice::NextFrame()
-{
- m_currentTable = 1 - m_currentTable;
-
- // cerr << "SCA_IInputDevice::NextFrame " << GetNumActiveEvents() << endl;
-
- for (int i=0;i<SCA_IInputDevice::KX_MAX_KEYS;i++)
- {
- switch (m_eventStatusTables[1 - m_currentTable][i].m_status)
- {
- case SCA_InputEvent::KX_NO_INPUTSTATUS:
- m_eventStatusTables[m_currentTable][i]
- = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
- break;
- case SCA_InputEvent::KX_JUSTACTIVATED:
- m_eventStatusTables[m_currentTable][i]
- = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
- break;
- case SCA_InputEvent::KX_ACTIVE:
- m_eventStatusTables[m_currentTable][i]
- = SCA_InputEvent(SCA_InputEvent::KX_ACTIVE, 1);
- break;
- case SCA_InputEvent::KX_JUSTRELEASED:
- m_eventStatusTables[m_currentTable][i]
- = SCA_InputEvent(SCA_InputEvent::KX_NO_INPUTSTATUS, 1);
- break;
- default:
- ; /* error */
- }
- }
-}
diff --git a/source/gameengine/GameLogic/SCA_IInputDevice.h b/source/gameengine/GameLogic/SCA_IInputDevice.h
deleted file mode 100644
index f306ae4f26b..00000000000
--- a/source/gameengine/GameLogic/SCA_IInputDevice.h
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_IInputDevice.h
- * \ingroup gamelogic
- * \brief Interface for input devices. The defines for keyboard/system/mouse events
- * here are for internal use in the KX module.
- *
- */
-
-#ifndef __SCA_IINPUTDEVICE_H__
-#define __SCA_IINPUTDEVICE_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class SCA_InputEvent
-{
-
-public:
- enum SCA_EnumInputs {
-
- KX_NO_INPUTSTATUS = 0,
- KX_JUSTACTIVATED,
- KX_ACTIVE,
- KX_JUSTRELEASED,
- };
-
- SCA_InputEvent(SCA_EnumInputs status=KX_NO_INPUTSTATUS,int eventval=0, int unicode=0)
- : m_status(status),
- m_eventval(eventval),
- m_unicode(unicode)
- {
-
- }
-
- SCA_EnumInputs m_status;
- int m_eventval;
- unsigned int m_unicode;
-};
-
-/* Originally from wm_event_types.h, now only used by GameEngine */
-#define MOUSEX MOUSEMOVE
-#define MOUSEY ACTIONMOUSE
-
-class SCA_IInputDevice
-{
-
-
-public:
-
- SCA_IInputDevice();
- virtual ~SCA_IInputDevice();
-
- enum KX_EnumInputs {
-
- KX_NOKEY = 0,
-
- // TIMERS
-
- KX_TIMER0,
- KX_TIMER1,
- KX_TIMER2,
-
- // SYSTEM
-
- /* Moved to avoid clashes with KX_RETKEY */
- KX_KEYBD,
- KX_RAWKEYBD,
- KX_REDRAW,
- KX_INPUTCHANGE,
- KX_QFULL,
- KX_WINFREEZE,
- KX_WINTHAW,
- /* thaw is 11 */
-
- /* move past retkey*/
- KX_WINCLOSE = 14,
- KX_WINQUIT,
- KX_Q_FIRSTTIME,
- /* sequence ends on 16 */
-
- // standard keyboard
-
- /* Because of the above preamble, KX_BEGINKEY is 15 ! This
- * means that KX_RETKEY on 13d (0Dh)) will double up with
- * KX_WINQUIT! Why is it 13? Because ascii 13d is Ctrl-M aka
- * CR! Its little brother, LF has 10d (0Ah). This is
- * dangerous, since the keyboards start scanning at
- * KX_BEGINKEY. I think the keyboard system should push its
- * key events instead of demanding the user to poll the
- * table... But that's for another time... The fix for now is
- * to move the above system events into a 'safe' (ie. unused)
- * range. I am loathe to move it away from this 'magical'
- * coincidence.. it's probably exploited somewhere. I hope the
- * close and quit events don't mess up 'normal' kb code
- * scanning.
- * */
- KX_BEGINKEY = 12,
-
- KX_RETKEY = 13,
- KX_SPACEKEY = 32,
- KX_PADASTERKEY = 42,
- KX_COMMAKEY = 44,
- KX_MINUSKEY = 45,
- KX_PERIODKEY = 46,
- KX_PLUSKEY = 47,
- KX_ZEROKEY = 48,
-
- KX_ONEKEY, // =49
- KX_TWOKEY,
- KX_THREEKEY,
- KX_FOURKEY,
- KX_FIVEKEY,
- KX_SIXKEY,
- KX_SEVENKEY,
- KX_EIGHTKEY,
- KX_NINEKEY, // = 57
-
- KX_AKEY = 97,
- KX_BKEY,
- KX_CKEY,
- KX_DKEY,
- KX_EKEY,
- KX_FKEY,
- KX_GKEY,
- KX_HKEY,
- KX_IKEY,
- KX_JKEY,
- KX_KKEY,
- KX_LKEY,
- KX_MKEY,
- KX_NKEY, // =110
- KX_OKEY,
- KX_PKEY,
- KX_QKEY,
- KX_RKEY,
- KX_SKEY,
- KX_TKEY,
- KX_UKEY,
- KX_VKEY,
- KX_WKEY,
- KX_XKEY, // =120
- KX_YKEY,
- KX_ZKEY, // =122
-
-
-
- KX_CAPSLOCKKEY, // 123
-
- KX_LEFTCTRLKEY, // 124
- KX_LEFTALTKEY,
- KX_RIGHTALTKEY,
- KX_RIGHTCTRLKEY,
- KX_RIGHTSHIFTKEY,
- KX_LEFTSHIFTKEY,// 129
-
- KX_ESCKEY, // 130
- KX_TABKEY, //131
-
-
- KX_LINEFEEDKEY, // 132
- KX_BACKSPACEKEY,
- KX_DELKEY,
- KX_SEMICOLONKEY, // 135
-
-
- KX_QUOTEKEY, //136
- KX_ACCENTGRAVEKEY, //137
-
- KX_SLASHKEY, //138
- KX_BACKSLASHKEY,
- KX_EQUALKEY,
- KX_LEFTBRACKETKEY,
- KX_RIGHTBRACKETKEY, // 142
-
- KX_LEFTARROWKEY, // 145
- KX_DOWNARROWKEY,
- KX_RIGHTARROWKEY,
- KX_UPARROWKEY, // 148
-
- KX_PAD2 ,
- KX_PAD4 ,
- KX_PAD6 ,
- KX_PAD8 ,
-
- KX_PAD1 ,
- KX_PAD3 ,
- KX_PAD5 ,
- KX_PAD7 ,
- KX_PAD9 ,
-
- KX_PADPERIOD,
- KX_PADSLASHKEY,
-
-
-
- KX_PAD0 ,
- KX_PADMINUS,
- KX_PADENTER,
- KX_PADPLUSKEY,
-
-
- KX_F1KEY ,
- KX_F2KEY ,
- KX_F3KEY ,
- KX_F4KEY ,
- KX_F5KEY ,
- KX_F6KEY ,
- KX_F7KEY ,
- KX_F8KEY ,
- KX_F9KEY ,
- KX_F10KEY,
- KX_F11KEY,
- KX_F12KEY,
- KX_F13KEY,
- KX_F14KEY,
- KX_F15KEY,
- KX_F16KEY,
- KX_F17KEY,
- KX_F18KEY,
- KX_F19KEY,
-
- KX_OSKEY,
-
- KX_PAUSEKEY,
- KX_INSERTKEY,
- KX_HOMEKEY ,
- KX_PAGEUPKEY,
- KX_PAGEDOWNKEY,
- KX_ENDKEY,
-
- // MOUSE
- KX_BEGINMOUSE,
-
- KX_BEGINMOUSEBUTTONS,
-
- KX_LEFTMOUSE,
- KX_MIDDLEMOUSE,
- KX_RIGHTMOUSE,
-
- KX_ENDMOUSEBUTTONS,
-
- KX_WHEELUPMOUSE,
- KX_WHEELDOWNMOUSE,
-
- KX_MOUSEX,
- KX_MOUSEY,
-
- KX_ENDMOUSE,
-
-
-
- KX_MAX_KEYS
-
- }; // enum
-
-
-protected:
- /**
- * m_eventStatusTables are two tables that contain current and previous
- * status of all events
- */
-
- SCA_InputEvent m_eventStatusTables[2][SCA_IInputDevice::KX_MAX_KEYS];
- /**
- * m_currentTable is index for m_keyStatusTable that toggle between 0 or 1
- */
- int m_currentTable;
- void ClearStatusTable(int tableid);
-
-public:
- virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
- virtual const SCA_InputEvent& GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode);
-
- /**
- * Count active events(active and just_activated)
- */
- virtual int GetNumActiveEvents();
-
- /**
- * Get the number of remapping events (just_activated, just_released)
- */
- virtual int GetNumJustEvents();
-
- virtual void HookEscape();
-
- /**
- * Next frame: we calculate the new key states. This goes as follows:
- *
- * KX_NO_INPUTSTATUS -> KX_NO_INPUTSTATUS
- * KX_JUSTACTIVATED -> KX_ACTIVE
- * KX_ACTIVE -> KX_ACTIVE
- * KX_JUSTRELEASED -> KX_NO_INPUTSTATUS
- *
- * Getting new events provides the
- * KX_NO_INPUTSTATUS->KX_JUSTACTIVATED and
- * KX_ACTIVE->KX_JUSTRELEASED transitions.
- */
- virtual void NextFrame();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_InputEvent")
-#endif
-};
-
-#endif /* __SCA_IINPUTDEVICE_H__ */
-
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp b/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
deleted file mode 100644
index d0a6e4540c9..00000000000
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.cpp
+++ /dev/null
@@ -1,271 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_ILogicBrick.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_ILogicBrick.h"
-#include "EXP_PyObjectPlus.h"
-
-SCA_ILogicBrick::SCA_ILogicBrick(SCA_IObject* gameobj)
- :
- CValue(),
- m_gameobj(gameobj),
- m_logicManager(NULL),
- m_Execute_Priority(0),
- m_Execute_Ueber_Priority(0),
- m_bActive(false),
- m_eventval(0)
-{
- m_text = "KX_LogicBrick";
-}
-
-
-
-SCA_ILogicBrick::~SCA_ILogicBrick()
-{
- RemoveEvent();
-}
-
-
-
-void SCA_ILogicBrick::SetExecutePriority(int execute_Priority)
-{
- m_Execute_Priority = execute_Priority;
-}
-
-
-
-void SCA_ILogicBrick::SetUeberExecutePriority(int execute_Priority)
-{
- m_Execute_Ueber_Priority = execute_Priority;
-}
-
-
-
-void SCA_ILogicBrick::ReParent(SCA_IObject* parent)
-{
- m_gameobj = parent;
-}
-
-void SCA_ILogicBrick::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- // nothing to do
-}
-
-CValue* SCA_ILogicBrick::Calc(VALUE_OPERATOR op, CValue *val)
-{
- CValue* temp = new CBoolValue(false,"");
- CValue* result = temp->Calc(op,val);
- temp->Release();
-
- return result;
-}
-
-
-
-CValue* SCA_ILogicBrick::CalcFinal(VALUE_DATA_TYPE dtype,
- VALUE_OPERATOR op,
- CValue *val)
-{
- // same as bool implementation, so...
- CValue* temp = new CBoolValue(false,"");
- CValue* result = temp->CalcFinal(dtype,op,val);
- temp->Release();
-
- return result;
-}
-
-
-
-const STR_String& SCA_ILogicBrick::GetText()
-{
- if (m_name.Length())
- return m_name;
-
- return m_text;
-}
-
-
-
-double SCA_ILogicBrick::GetNumber()
-{
- return -1;
-}
-
-
-
-STR_String& SCA_ILogicBrick::GetName()
-{
- return m_name;
-}
-
-
-
-void SCA_ILogicBrick::SetName(const char *name)
-{
- m_name = name;
-}
-
-bool SCA_ILogicBrick::LessComparedTo(SCA_ILogicBrick* other)
-{
- return (this->m_Execute_Ueber_Priority < other->m_Execute_Ueber_Priority)
- || ((this->m_Execute_Ueber_Priority == other->m_Execute_Ueber_Priority) &&
- (this->m_Execute_Priority < other->m_Execute_Priority));
-}
-
-void SCA_ILogicBrick::SetLogicManager(SCA_LogicManager *logicmgr)
-{
- m_logicManager = logicmgr;
-}
-
-SCA_LogicManager *SCA_ILogicBrick::GetLogicManager()
-{
- return m_logicManager;
-}
-
-void SCA_ILogicBrick::RegisterEvent(CValue* eventval)
-{
- if (m_eventval)
- m_eventval->Release();
-
- m_eventval = eventval->AddRef();
-}
-
-
-void SCA_ILogicBrick::RemoveEvent()
-{
- if (m_eventval)
- {
- m_eventval->Release();
- m_eventval = NULL;
- }
-}
-
-
-
-CValue* SCA_ILogicBrick::GetEvent()
-{
- if (m_eventval)
- {
- return m_eventval->AddRef();
- }
-
- return NULL;
-}
-
-
-
-#ifdef WITH_PYTHON
-
-/* python stuff */
-
-PyTypeObject SCA_ILogicBrick::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_ILogicBrick",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_ILogicBrick::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_ILogicBrick::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("owner", SCA_ILogicBrick, pyattr_get_owner),
- KX_PYATTRIBUTE_INT_RW("executePriority",0,100000,false,SCA_ILogicBrick,m_Execute_Priority),
- KX_PYATTRIBUTE_STRING_RO("name", SCA_ILogicBrick, m_name),
- {NULL} //Sentinel
-};
-
-int SCA_ILogicBrick::CheckProperty(void *self, const PyAttributeDef *attrdef)
-{
- if (attrdef->m_type != KX_PYATTRIBUTE_TYPE_STRING || attrdef->m_length != 1) {
- PyErr_SetString(PyExc_AttributeError, "inconsistent check function for attribute type, report to blender.org");
- return 1;
- }
- SCA_ILogicBrick* brick = reinterpret_cast<SCA_ILogicBrick*>(self);
- STR_String* var = reinterpret_cast<STR_String*>((char*)self+attrdef->m_offset);
- CValue* prop = brick->GetParent()->FindIdentifier(*var);
- bool error = prop->IsError();
- prop->Release();
- if (error) {
- PyErr_SetString(PyExc_ValueError, "string does not correspond to a property");
- return 1;
- }
- return 0;
-}
-
-/*Attribute functions */
-PyObject *SCA_ILogicBrick::pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ILogicBrick* self = static_cast<SCA_ILogicBrick*>(self_v);
- CValue* parent = self->GetParent();
-
- if (parent)
- return parent->GetProxy();
-
- Py_RETURN_NONE;
-}
-
-
-
-/* Conversions for making life better. */
-bool SCA_ILogicBrick::PyArgToBool(int boolArg)
-{
- if (boolArg) {
- return true;
- } else {
- return false;
- }
-}
-
-PyObject *SCA_ILogicBrick::BoolToPyArg(bool boolarg)
-{
- return PyLong_FromLong(boolarg ? KX_TRUE: KX_FALSE);
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/GameLogic/SCA_ILogicBrick.h b/source/gameengine/GameLogic/SCA_ILogicBrick.h
deleted file mode 100644
index f9ef18cc348..00000000000
--- a/source/gameengine/GameLogic/SCA_ILogicBrick.h
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_ILogicBrick.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ILOGICBRICK_H__
-#define __SCA_ILOGICBRICK_H__
-
-#include "EXP_Value.h"
-#include "SCA_IObject.h"
-#include "EXP_BoolValue.h"
-#include "CTR_Map.h"
-#include "CTR_HashedPtr.h"
-
-class NG_NetworkScene;
-class SCA_IScene;
-class SCA_LogicManager;
-
-class SCA_ILogicBrick : public CValue
-{
- Py_Header
-protected:
- SCA_IObject* m_gameobj;
- SCA_LogicManager *m_logicManager;
- int m_Execute_Priority;
- int m_Execute_Ueber_Priority;
-
- bool m_bActive;
- CValue* m_eventval;
- STR_String m_text;
- STR_String m_name;
- //unsigned long m_drawcolor;
- void RegisterEvent(CValue* eventval);
- void RemoveEvent();
- CValue* GetEvent();
-
-public:
- SCA_ILogicBrick(SCA_IObject* gameobj);
- virtual ~SCA_ILogicBrick();
-
- void SetExecutePriority(int execute_Priority);
- void SetUeberExecutePriority(int execute_Priority);
-
- SCA_IObject* GetParent() { return m_gameobj; }
-
- virtual void ReParent(SCA_IObject* parent);
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual void Delete() { Release(); }
-
- // act as a BoolValue (with value IsPositiveTrigger)
- virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
-
- virtual const STR_String & GetText();
- virtual double GetNumber();
- virtual STR_String& GetName();
- virtual void SetName(const char *);
-
- bool IsActive()
- {
- return m_bActive;
- }
-
- void SetActive(bool active)
- {
- m_bActive=active;
- }
-
- // insert in a QList at position corresponding to m_Execute_Priority
- void InsertActiveQList(SG_QList& head)
- {
- SG_QList::iterator<SCA_ILogicBrick> it(head);
- for (it.begin(); !it.end() && m_Execute_Priority > (*it)->m_Execute_Priority; ++it);
- it.add_back(this);
- }
-
- // insert in a QList at position corresponding to m_Execute_Priority
- // inside a longer list that contains elements of other objects.
- // Sorting is done only between the elements of the same object.
- // head is the head of the combined list
- // current points to the first element of the object in the list, NULL if none yet
- void InsertSelfActiveQList(SG_QList& head, SG_QList** current)
- {
- if (!*current)
- {
- // first element can be put anywhere
- head.QAddBack(this);
- *current = this;
- return;
- }
- // note: we assume current points actually to one o our element, skip the tests
- SG_QList::iterator<SCA_ILogicBrick> it(head,*current);
- if (m_Execute_Priority <= (*it)->m_Execute_Priority)
- {
- // this element comes before the first
- *current = this;
- }
- else {
- for (++it; !it.end() && (*it)->m_gameobj == m_gameobj && m_Execute_Priority > (*it)->m_Execute_Priority; ++it);
- }
- it.add_back(this);
- }
-
- virtual bool LessComparedTo(SCA_ILogicBrick* other);
-
- virtual void SetLogicManager(SCA_LogicManager *logicmgr);
- SCA_LogicManager *GetLogicManager();
-
- /* for moving logic bricks between scenes */
- virtual void Replace_IScene(SCA_IScene *val) {}
- virtual void Replace_NetworkScene(NG_NetworkScene *val) {}
-
-#ifdef WITH_PYTHON
- // python methods
-
- static PyObject* pyattr_get_owner(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- // check that attribute is a property
- static int CheckProperty(void *self, const PyAttributeDef *attrdef);
-
- enum KX_BOOL_TYPE {
- KX_BOOL_NODEF = 0,
- KX_TRUE,
- KX_FALSE,
- KX_BOOL_MAX
- };
-
-
-protected:
- /* Some conversions to go with the bool type. */
- /** Convert a KX_TRUE, KX_FALSE in Python to a c++ value. */
- bool PyArgToBool(int boolArg);
-
- /** Convert a a c++ value to KX_TRUE, KX_FALSE in Python. */
- PyObject *BoolToPyArg(bool);
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __SCA_ILOGICBRICK_H__ */
diff --git a/source/gameengine/GameLogic/SCA_IObject.cpp b/source/gameengine/GameLogic/SCA_IObject.cpp
deleted file mode 100644
index 526e695e792..00000000000
--- a/source/gameengine/GameLogic/SCA_IObject.cpp
+++ /dev/null
@@ -1,349 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_IObject.cpp
- * \ingroup gamelogic
- */
-
-#include <iostream>
-#include <algorithm>
-
-#include "SCA_IObject.h"
-#include "SCA_ISensor.h"
-#include "SCA_IController.h"
-#include "SCA_IActuator.h"
-#include "MT_Point3.h"
-#include "EXP_ListValue.h"
-
-MT_Point3 SCA_IObject::m_sDummy=MT_Point3(0,0,0);
-SG_QList SCA_IObject::m_activeBookmarkedControllers;
-
-SCA_IObject::SCA_IObject():
- CValue(),
- m_initState(0),
- m_state(0),
- m_firstState(NULL)
-{
- m_suspended = false;
-}
-
-SCA_IObject::~SCA_IObject()
-{
- SCA_SensorList::iterator its;
- for (its = m_sensors.begin(); !(its == m_sensors.end()); ++its)
- {
- //Use Delete for sensor to ensure proper cleaning
- (*its)->Delete();
- //((CValue*)(*its))->Release();
- }
- SCA_ControllerList::iterator itc;
- for (itc = m_controllers.begin(); !(itc == m_controllers.end()); ++itc)
- {
- //Use Delete for controller to ensure proper cleaning (expression controller)
- (*itc)->Delete();
- //((CValue*)(*itc))->Release();
- }
- SCA_ActuatorList::iterator ita;
- for (ita = m_registeredActuators.begin(); !(ita==m_registeredActuators.end()); ++ita)
- {
- (*ita)->UnlinkObject(this);
- }
- for (ita = m_actuators.begin(); !(ita==m_actuators.end()); ++ita)
- {
- (*ita)->Delete();
- }
-
- SCA_ObjectList::iterator ito;
- for (ito = m_registeredObjects.begin(); !(ito==m_registeredObjects.end()); ++ito)
- {
- (*ito)->UnlinkObject(this);
- }
-
- //T_InterpolatorList::iterator i;
- //for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- // delete *i;
- //}
-}
-
-void SCA_IObject::AddSensor(SCA_ISensor* act)
-{
- act->AddRef();
- m_sensors.push_back(act);
-}
-
-
-
-void SCA_IObject::AddController(SCA_IController* act)
-{
- act->AddRef();
- m_controllers.push_back(act);
-}
-
-
-
-void SCA_IObject::AddActuator(SCA_IActuator* act)
-{
- act->AddRef();
- m_actuators.push_back(act);
-}
-
-void SCA_IObject::RegisterActuator(SCA_IActuator* act)
-{
- // don't increase ref count, it would create dead lock
- m_registeredActuators.push_back(act);
-}
-
-void SCA_IObject::UnregisterActuator(SCA_IActuator* act)
-{
- SCA_ActuatorList::iterator ita;
- for (ita = m_registeredActuators.begin(); ita != m_registeredActuators.end(); ++ita)
- {
- if ((*ita) == act) {
- (*ita) = m_registeredActuators.back();
- m_registeredActuators.pop_back();
- break;
- }
- }
-}
-
-void SCA_IObject::RegisterObject(SCA_IObject* obj)
-{
- // one object may be registered multiple times via constraint target
- // store multiple reference, this will serve as registration counter
- m_registeredObjects.push_back(obj);
-}
-
-void SCA_IObject::UnregisterObject(SCA_IObject* obj)
-{
- SCA_ObjectList::iterator ito;
- for (ito = m_registeredObjects.begin(); ito != m_registeredObjects.end(); ++ito)
- {
- if ((*ito) == obj) {
- (*ito) = m_registeredObjects.back();
- m_registeredObjects.pop_back();
- break;
- }
- }
-}
-
-void SCA_IObject::ReParentLogic()
-{
- SCA_ActuatorList& oldactuators = GetActuators();
- int act = 0;
- SCA_ActuatorList::iterator ita;
- for (ita = oldactuators.begin(); !(ita==oldactuators.end()); ++ita)
- {
- SCA_IActuator* newactuator = (SCA_IActuator*) (*ita)->GetReplica();
- newactuator->ReParent(this);
- // actuators are initially not connected to any controller
- newactuator->SetActive(false);
- newactuator->ClrLink();
- oldactuators[act++] = newactuator;
- }
-
- SCA_ControllerList& oldcontrollers = GetControllers();
- int con = 0;
- SCA_ControllerList::iterator itc;
- for (itc = oldcontrollers.begin(); !(itc==oldcontrollers.end()); ++itc)
- {
- SCA_IController* newcontroller = (SCA_IController*)(*itc)->GetReplica();
- newcontroller->ReParent(this);
- newcontroller->SetActive(false);
- oldcontrollers[con++]=newcontroller;
-
- }
- // convert sensors last so that actuators are already available for Actuator sensor
- SCA_SensorList& oldsensors = GetSensors();
- int sen = 0;
- SCA_SensorList::iterator its;
- for (its = oldsensors.begin(); !(its==oldsensors.end()); ++its)
- {
- SCA_ISensor* newsensor = (SCA_ISensor*)(*its)->GetReplica();
- newsensor->ReParent(this);
- newsensor->SetActive(false);
- // sensors are initially not connected to any controller
- newsensor->ClrLink();
- oldsensors[sen++] = newsensor;
- }
-
- // a new object cannot be client of any actuator
- m_registeredActuators.clear();
- m_registeredObjects.clear();
-}
-
-
-
-SCA_ISensor* SCA_IObject::FindSensor(const STR_String& sensorname)
-{
- SCA_ISensor* foundsensor = NULL;
-
- for (SCA_SensorList::iterator its = m_sensors.begin();!(its==m_sensors.end());++its)
- {
- if ((*its)->GetName() == sensorname)
- {
- foundsensor = (*its);
- break;
- }
- }
- return foundsensor;
-}
-
-
-
-SCA_IController* SCA_IObject::FindController(const STR_String& controllername)
-{
- SCA_IController* foundcontroller = NULL;
-
- for (SCA_ControllerList::iterator itc = m_controllers.begin();!(itc==m_controllers.end());++itc)
- {
- if ((*itc)->GetName() == controllername)
- {
- foundcontroller = (*itc);
- break;
- }
- }
- return foundcontroller;
-}
-
-
-
-SCA_IActuator* SCA_IObject::FindActuator(const STR_String& actuatorname)
-{
- SCA_IActuator* foundactuator = NULL;
-
- for (SCA_ActuatorList::iterator ita = m_actuators.begin();!(ita==m_actuators.end());++ita)
- {
- if ((*ita)->GetName() == actuatorname)
- {
- foundactuator = (*ita);
- break;
- }
- }
-
- return foundactuator;
-}
-
-
-void SCA_IObject::Suspend()
-{
- if ((!m_ignore_activity_culling)
- && (!m_suspended)) {
- m_suspended = true;
- /* flag suspend for all sensors */
- SCA_SensorList::iterator i = m_sensors.begin();
- while (i != m_sensors.end()) {
- (*i)->Suspend();
- ++i;
- }
- }
-}
-
-
-
-void SCA_IObject::Resume(void)
-{
- if (m_suspended) {
- m_suspended = false;
- /* unflag suspend for all sensors */
- SCA_SensorList::iterator i = m_sensors.begin();
- while (i != m_sensors.end()) {
- (*i)->Resume();
- ++i;
- }
- }
-}
-
-void SCA_IObject::SetState(unsigned int state)
-{
- unsigned int tmpstate;
- SCA_ControllerList::iterator contit;
-
- // we will update the state in two steps:
- // 1) set the new state bits that are 1
- // 2) clr the new state bits that are 0
- // This to ensure continuity if a sensor is attached to two states
- // that are switching state: no need to deactive and reactive the sensor
-
- tmpstate = m_state | state;
- if (tmpstate != m_state)
- {
- // update the status of the controllers
- for (contit = m_controllers.begin(); contit != m_controllers.end(); ++contit)
- {
- (*contit)->ApplyState(tmpstate);
- }
- }
- m_state = state;
- if (m_state != tmpstate)
- {
- for (contit = m_controllers.begin(); contit != m_controllers.end(); ++contit)
- {
- (*contit)->ApplyState(m_state);
- }
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_IObject::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_IObject",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_IObject::Methods[] = {
- //{"setOrientation", (PyCFunction) SCA_IObject::sPySetOrientation, METH_VARARGS},
- //{"getOrientation", (PyCFunction) SCA_IObject::sPyGetOrientation, METH_VARARGS},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_IObject::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/GameLogic/SCA_IObject.h b/source/gameengine/GameLogic/SCA_IObject.h
deleted file mode 100644
index 29a21fd8708..00000000000
--- a/source/gameengine/GameLogic/SCA_IObject.h
+++ /dev/null
@@ -1,229 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/** \file SCA_IObject.h
- * \ingroup gamelogic
- * \brief An abstract object that has some logic, python scripting and
- * reference counting Note: transformation stuff has been moved to
- * SceneGraph
- */
-
-#ifndef __SCA_IOBJECT_H__
-#define __SCA_IOBJECT_H__
-
-#include "EXP_Value.h"
-#include <vector>
-
-class SCA_IObject;
-class SCA_ISensor;
-class SCA_IController;
-class SCA_IActuator;
-
-#ifdef WITH_PYTHON
-template<class T> T PyVecTo(PyObject *);
-#endif
-
-typedef std::vector<SCA_ISensor *> SCA_SensorList;
-typedef std::vector<SCA_IController *> SCA_ControllerList;
-typedef std::vector<SCA_IActuator *> SCA_ActuatorList;
-typedef std::vector<SCA_IObject *> SCA_ObjectList;
-
-class SCA_IObject : public CValue
-{
-
- Py_Header
-
-protected:
- friend class KX_StateActuator;
- friend class SCA_IActuator;
- friend class SCA_IController;
- SCA_SensorList m_sensors;
- SCA_ControllerList m_controllers;
- SCA_ActuatorList m_actuators;
- SCA_ActuatorList m_registeredActuators; // actuators that use a pointer to this object
- SCA_ObjectList m_registeredObjects; // objects that hold reference to this object
-
- // SG_Dlist: element of objects with active actuators
- // Head: SCA_LogicManager::m_activeActuators
- // SG_QList: Head of active actuators list on this object
- // Elements: SCA_IActuator
- SG_QList m_activeActuators;
- // SG_Dlist: element of list os lists with active controllers
- // Head: SCA_LogicManager::m_activeControllers
- // SG_QList: Head of active controller list on this object
- // Elements: SCA_IController
- SG_QList m_activeControllers;
- // SG_Dlist: element of list of lists of active controllers
- // Head: SCA_LogicManager::m_activeControllers
- // SG_QList: Head of active bookmarked controller list globally
- // Elements: SCA_IController with bookmark option
- static SG_QList m_activeBookmarkedControllers;
-
- static class MT_Point3 m_sDummy;
-
- /**
- * Ignore activity culling requests?
- */
- bool m_ignore_activity_culling;
-
- /**
- * Ignore updates?
- */
- bool m_suspended;
-
- /**
- * init state of object (used when object is created)
- */
- unsigned int m_initState;
-
- /**
- * current state = bit mask of state that are active
- */
- unsigned int m_state;
-
- /**
- * pointer inside state actuator list for sorting
- */
- SG_QList* m_firstState;
-
-public:
-
- SCA_IObject();
- virtual ~SCA_IObject();
-
- SCA_ControllerList& GetControllers()
- {
- return m_controllers;
- }
- SCA_SensorList& GetSensors()
- {
- return m_sensors;
- }
- SCA_ActuatorList& GetActuators()
- {
- return m_actuators;
- }
- SG_QList& GetActiveActuators()
- {
- return m_activeActuators;
- }
-
- void AddSensor(SCA_ISensor* act);
- void ReserveSensor(int num)
- {
- m_sensors.reserve(num);
- }
- void AddController(SCA_IController* act);
- void ReserveController(int num)
- {
- m_controllers.reserve(num);
- }
- void AddActuator(SCA_IActuator* act);
- void ReserveActuator(int num)
- {
- m_actuators.reserve(num);
- }
- void RegisterActuator(SCA_IActuator* act);
- void UnregisterActuator(SCA_IActuator* act);
-
- void RegisterObject(SCA_IObject* objs);
- void UnregisterObject(SCA_IObject* objs);
- /**
- * UnlinkObject(...)
- * this object is informed that one of the object to which it holds a reference is deleted
- * returns true if there was indeed a reference.
- */
- virtual bool UnlinkObject(SCA_IObject* clientobj) { return false; }
-
- SCA_ISensor* FindSensor(const STR_String& sensorname);
- SCA_IActuator* FindActuator(const STR_String& actuatorname);
- SCA_IController* FindController(const STR_String& controllername);
-
- void SetCurrentTime(float currentTime) {}
-
- virtual void ReParentLogic();
-
- /**
- * Set whether or not to ignore activity culling requests
- */
- void SetIgnoreActivityCulling(bool b)
- {
- m_ignore_activity_culling = b;
- }
-
- /**
- * Set whether or not this object wants to ignore activity culling
- * requests
- */
- bool GetIgnoreActivityCulling()
- {
- return m_ignore_activity_culling;
- }
-
- /**
- * Suspend all progress.
- */
- void Suspend(void);
-
- /**
- * Resume progress
- */
- void Resume(void);
-
- /**
- * Set init state
- */
- void SetInitState(unsigned int initState) { m_initState = initState; }
-
- /**
- * initialize the state when object is created
- */
- void ResetState(void) { SetState(m_initState); }
-
- /**
- * Set the object state
- */
- void SetState(unsigned int state);
-
- /**
- * Get the object state
- */
- unsigned int GetState(void) { return m_state; }
-
-// const class MT_Point3& ConvertPythonPylist(PyObject *pylist);
-
- virtual int GetGameObjectType() {return -1;}
-
- typedef enum ObjectTypes {
- OBJ_ARMATURE=0,
- OBJ_CAMERA=1,
- OBJ_LIGHT=2,
- OBJ_TEXT=3
- } ObjectTypes;
-
-};
-
-#endif /* __SCA_IOBJECT_H__ */
diff --git a/source/gameengine/GameLogic/SCA_IScene.cpp b/source/gameengine/GameLogic/SCA_IScene.cpp
deleted file mode 100644
index a4c905096d7..00000000000
--- a/source/gameengine/GameLogic/SCA_IScene.cpp
+++ /dev/null
@@ -1,145 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_IScene.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_IScene.h"
-#include "EXP_Value.h"
-
-SCA_DebugProp::SCA_DebugProp(): m_obj(NULL)
-{
-}
-
-SCA_DebugProp::~SCA_DebugProp()
-{
- if (m_obj)
- m_obj->Release();
-}
-
-SCA_IScene::SCA_IScene()
-{
-}
-
-void SCA_IScene::RemoveAllDebugProperties()
-{
- for (std::vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
- !(it==m_debugList.end());++it)
- {
- delete (*it);
- }
- m_debugList.clear();
-}
-
-
-SCA_IScene::~SCA_IScene()
-{
- RemoveAllDebugProperties();
-}
-
-
-std::vector<SCA_DebugProp*>& SCA_IScene::GetDebugProperties()
-{
- return m_debugList;
-}
-
-
-bool SCA_IScene::PropertyInDebugList( class CValue *gameobj, const STR_String &name )
-{
- for (std::vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
- !(it==m_debugList.end());++it) {
- STR_String debugname = (*it)->m_name;
- CValue *debugobj = (*it)->m_obj;
-
- if (debugobj == gameobj && debugname == name)
- return true;
- }
- return false;
-}
-
-
-bool SCA_IScene::ObjectInDebugList( class CValue *gameobj )
-{
- for (std::vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
- !(it==m_debugList.end());++it) {
- CValue* debugobj = (*it)->m_obj;
-
- if (debugobj == gameobj)
- return true;
- }
- return false;
-}
-
-
-void SCA_IScene::AddDebugProperty(class CValue* debugprop,
- const STR_String &name)
-{
- if (m_debugList.size() < DEBUG_MAX_DISPLAY) {
- SCA_DebugProp* dprop = new SCA_DebugProp();
- dprop->m_obj = debugprop;
- debugprop->AddRef();
- dprop->m_name = name;
- m_debugList.push_back(dprop);
- }
-}
-
-
-void SCA_IScene::RemoveDebugProperty(class CValue *gameobj,
- const STR_String &name)
-{
- vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
- while (it != m_debugList.end()) {
- STR_String debugname = (*it)->m_name;
- CValue *debugobj = (*it)->m_obj;
-
- if (debugobj == gameobj && debugname == name) {
- delete (*it);
- m_debugList.erase(it);
- break;
- }
- ++it;
- }
-}
-
-
-void SCA_IScene::RemoveObjectDebugProperties(class CValue* gameobj)
-{
- vector<SCA_DebugProp*>::iterator it = m_debugList.begin();
- while (it != m_debugList.end()) {
- CValue* debugobj = (*it)->m_obj;
-
- if (debugobj == gameobj) {
- delete (*it);
- m_debugList.erase(it);
- continue;
- }
- ++it;
- }
-}
-
diff --git a/source/gameengine/GameLogic/SCA_IScene.h b/source/gameengine/GameLogic/SCA_IScene.h
deleted file mode 100644
index b76b5636b13..00000000000
--- a/source/gameengine/GameLogic/SCA_IScene.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_IScene.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ISCENE_H__
-#define __SCA_ISCENE_H__
-
-#include <vector>
-
-#include "STR_String.h"
-#include "RAS_2DFilterManager.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-#define DEBUG_MAX_DISPLAY 100
-
-struct SCA_DebugProp
-{
- class CValue* m_obj;
- STR_String m_name;
- SCA_DebugProp();
- ~SCA_DebugProp();
-};
-
-class SCA_IScene
-{
- std::vector<SCA_DebugProp*> m_debugList;
-public:
- SCA_IScene();
- virtual ~SCA_IScene();
- virtual class SCA_IObject* AddReplicaObject(class CValue* gameobj,
- class CValue* locationobj,
- int lifespan=0)=0;
- virtual void RemoveObject(class CValue* gameobj)=0;
- virtual void DelayedRemoveObject(class CValue* gameobj)=0;
- //virtual void DelayedReleaseObject(class CValue* gameobj)=0;
-
- virtual void ReplaceMesh(class CValue* gameobj,
- void* meshobj, bool use_gfx, bool use_phys)=0;
- std::vector<SCA_DebugProp*>& GetDebugProperties();
- bool PropertyInDebugList(class CValue *gameobj, const STR_String &name);
- bool ObjectInDebugList(class CValue *gameobj);
- void RemoveAllDebugProperties();
- void AddDebugProperty(class CValue* debugprop, const STR_String &name);
- void RemoveDebugProperty(class CValue *gameobj, const STR_String &name);
- void RemoveObjectDebugProperties(class CValue* gameobj);
-
- virtual void Update2DFilter(std::vector<STR_String>& propNames, void* gameObj,
- RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode,
- int pass, STR_String& text) {}
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_IScene")
-#endif
-};
-
-#endif /* __SCA_ISCENE_H__ */
diff --git a/source/gameengine/GameLogic/SCA_ISensor.cpp b/source/gameengine/GameLogic/SCA_ISensor.cpp
deleted file mode 100644
index 66dd69f93c4..00000000000
--- a/source/gameengine/GameLogic/SCA_ISensor.cpp
+++ /dev/null
@@ -1,471 +0,0 @@
-/*
- * Abstract class for sensor logic bricks
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_ISensor.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_ISensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-// needed for IsTriggered()
-#include "SCA_PythonController.h"
-
-#include <stdio.h>
-
-/* Native functions */
-void SCA_ISensor::ReParent(SCA_IObject* parent)
-{
- SCA_ILogicBrick::ReParent(parent);
- // will be done when the sensor is activated
- //m_eventmgr->RegisterSensor(this);
- //this->SetActive(false);
-}
-
-
-SCA_ISensor::SCA_ISensor(SCA_IObject* gameobj,
- class SCA_EventManager* eventmgr) :
- SCA_ILogicBrick(gameobj)
-{
- m_links = 0;
- m_suspended = false;
- m_invert = false;
- m_level = false;
- m_tap = false;
- m_reset = false;
- m_pos_ticks = 0;
- m_neg_ticks = 0;
- m_pos_pulsemode = false;
- m_neg_pulsemode = false;
- m_skipped_ticks = 0;
- m_state = false;
- m_prev_state = false;
-
- m_eventmgr = eventmgr;
-}
-
-
-SCA_ISensor::~SCA_ISensor()
-{
- // intentionally empty
-}
-
-void SCA_ISensor::ProcessReplica()
-{
- SCA_ILogicBrick::ProcessReplica();
- m_linkedcontrollers.clear();
-}
-
-bool SCA_ISensor::IsPositiveTrigger()
-{
- bool result = false;
-
- if (m_eventval) {
- result = (m_eventval->GetNumber() != 0.0);
- }
- if (m_invert) {
- result = !result;
- }
-
- return result;
-}
-
-void SCA_ISensor::SetPulseMode(bool posmode,
- bool negmode,
- int skippedticks)
-{
- m_pos_pulsemode = posmode;
- m_neg_pulsemode = negmode;
- m_skipped_ticks = skippedticks;
-}
-
-void SCA_ISensor::SetInvert(bool inv)
-{
- m_invert = inv;
-}
-
-void SCA_ISensor::SetLevel(bool lvl)
-{
- m_level = lvl;
-}
-
-void SCA_ISensor::SetTap(bool tap)
-{
- m_tap = tap;
-}
-
-
-double SCA_ISensor::GetNumber()
-{
- return GetState();
-}
-
-void SCA_ISensor::Suspend()
-{
- m_suspended = true;
-}
-
-bool SCA_ISensor::IsSuspended()
-{
- return m_suspended;
-}
-
-void SCA_ISensor::Resume()
-{
- m_suspended = false;
-}
-
-void SCA_ISensor::Init()
-{
- printf("Sensor %s has no init function, please report this bug to Blender.org\n", m_name.Ptr());
-}
-
-void SCA_ISensor::DecLink()
-{
- m_links--;
- if (m_links < 0)
- {
- printf("Warning: sensor %s has negative m_links: %d\n", m_name.Ptr(), m_links);
- m_links = 0;
- }
- if (!m_links)
- {
- // sensor is detached from all controllers, remove it from manager
- UnregisterToManager();
- }
-}
-
-void SCA_ISensor::RegisterToManager()
-{
- // sensor is just activated, initialize it
- Init();
- m_state = false;
- m_eventmgr->RegisterSensor(this);
-}
-
-void SCA_ISensor::Replace_EventManager(class SCA_LogicManager* logicmgr)
-{
- if (m_links) { /* true if we're used currently */
-
- m_eventmgr->RemoveSensor(this);
- m_eventmgr= logicmgr->FindEventManager(m_eventmgr->GetType());
- m_eventmgr->RegisterSensor(this);
- }
- else {
- m_eventmgr= logicmgr->FindEventManager(m_eventmgr->GetType());
- }
-}
-
-void SCA_ISensor::LinkToController(SCA_IController* controller)
-{
- m_linkedcontrollers.push_back(controller);
-}
-
-void SCA_ISensor::UnlinkController(SCA_IController* controller)
-{
- std::vector<class SCA_IController*>::iterator contit;
- for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
- {
- if ((*contit) == controller)
- {
- *contit = m_linkedcontrollers.back();
- m_linkedcontrollers.pop_back();
- return;
- }
- }
- printf("Missing link from sensor %s:%s to controller %s:%s\n",
- m_gameobj->GetName().ReadPtr(), GetName().ReadPtr(),
- controller->GetParent()->GetName().ReadPtr(), controller->GetName().ReadPtr());
-}
-
-void SCA_ISensor::UnlinkAllControllers()
-{
- std::vector<class SCA_IController*>::iterator contit;
- for (contit = m_linkedcontrollers.begin();!(contit==m_linkedcontrollers.end());++contit)
- {
- (*contit)->UnlinkSensor(this);
- }
- m_linkedcontrollers.clear();
-}
-
-void SCA_ISensor::UnregisterToManager()
-{
- m_eventmgr->RemoveSensor(this);
- m_links = 0;
-}
-
-void SCA_ISensor::ActivateControllers(class SCA_LogicManager* logicmgr)
-{
- for (vector<SCA_IController*>::const_iterator c= m_linkedcontrollers.begin();
- c!=m_linkedcontrollers.end();++c)
- {
- SCA_IController* contr = *c;
- if (contr->IsActive())
- logicmgr->AddTriggeredController(contr, this);
- }
-}
-
-void SCA_ISensor::Activate(class SCA_LogicManager* logicmgr)
-{
-
- // calculate if a __triggering__ is wanted
- // don't evaluate a sensor that is not connected to any controller
- if (m_links && !m_suspended) {
- bool result = this->Evaluate();
- // store the state for the rest of the logic system
- m_prev_state = m_state;
- m_state = this->IsPositiveTrigger();
- if (result) {
- // the sensor triggered this frame
- if (m_state || !m_tap) {
- ActivateControllers(logicmgr);
- // reset these counters so that pulse are synchronized with transition
- m_pos_ticks = 0;
- m_neg_ticks = 0;
- } else
- {
- result = false;
- }
- } else
- {
- /* First, the pulsing behavior, if pulse mode is
- * active. It seems something goes wrong if pulse mode is
- * not set :( */
- if (m_pos_pulsemode) {
- m_pos_ticks++;
- if (m_pos_ticks > m_skipped_ticks) {
- if ( m_state )
- {
- ActivateControllers(logicmgr);
- result = true;
- }
- m_pos_ticks = 0;
- }
- }
- // negative pulse doesn't make sense in tap mode, skip
- if (m_neg_pulsemode && !m_tap)
- {
- m_neg_ticks++;
- if (m_neg_ticks > m_skipped_ticks) {
- if (!m_state )
- {
- ActivateControllers(logicmgr);
- result = true;
- }
- m_neg_ticks = 0;
- }
- }
- }
- if (m_tap)
- {
- // in tap mode: we send always a negative pulse immediately after a positive pulse
- if (!result)
- {
- // the sensor did not trigger on this frame
- if (m_prev_state)
- {
- // but it triggered on previous frame => send a negative pulse
- ActivateControllers(logicmgr);
- result = true;
- }
- // in any case, absence of trigger means sensor off
- m_state = false;
- }
- }
- if (!result && m_level)
- {
- // This level sensor is connected to at least one controller that was just made
- // active but it did not generate an event yet, do it now to those controllers only
- for (vector<SCA_IController*>::const_iterator c= m_linkedcontrollers.begin();
- c!=m_linkedcontrollers.end();++c)
- {
- SCA_IController* contr = *c;
- if (contr->IsJustActivated())
- logicmgr->AddTriggeredController(contr, this);
- }
- }
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ----------------------------------------------- */
-/* Python Functions */
-/* ----------------------------------------------- */
-
-KX_PYMETHODDEF_DOC_NOARGS(SCA_ISensor, reset,
-"reset()\n"
-"\tReset sensor internal state, effect depends on the type of sensor and settings.\n"
-"\tThe sensor is put in its initial state as if it was just activated.\n")
-{
- Init();
- m_prev_state = false;
- Py_RETURN_NONE;
-}
-
-/* ----------------------------------------------- */
-/* Python Integration Hooks */
-/* ----------------------------------------------- */
-
-PyTypeObject SCA_ISensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_ISensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ILogicBrick::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_ISensor::Methods[] = {
- KX_PYMETHODTABLE_NOARGS(SCA_ISensor, reset),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_ISensor::Attributes[] = {
- KX_PYATTRIBUTE_BOOL_RW("usePosPulseMode",SCA_ISensor,m_pos_pulsemode),
- KX_PYATTRIBUTE_BOOL_RW("useNegPulseMode",SCA_ISensor,m_neg_pulsemode),
- KX_PYATTRIBUTE_INT_RW("skippedTicks",0,100000,true,SCA_ISensor,m_skipped_ticks),
- KX_PYATTRIBUTE_BOOL_RW("invert",SCA_ISensor,m_invert),
- KX_PYATTRIBUTE_BOOL_RW_CHECK("level",SCA_ISensor,m_level,pyattr_check_level),
- KX_PYATTRIBUTE_BOOL_RW_CHECK("tap",SCA_ISensor,m_tap,pyattr_check_tap),
- KX_PYATTRIBUTE_RO_FUNCTION("triggered", SCA_ISensor, pyattr_get_triggered),
- KX_PYATTRIBUTE_RO_FUNCTION("positive", SCA_ISensor, pyattr_get_positive),
- KX_PYATTRIBUTE_RO_FUNCTION("status", SCA_ISensor, pyattr_get_status),
- KX_PYATTRIBUTE_RO_FUNCTION("pos_ticks", SCA_ISensor, pyattr_get_posTicks),
- KX_PYATTRIBUTE_RO_FUNCTION("neg_ticks", SCA_ISensor, pyattr_get_negTicks),
- KX_PYATTRIBUTE_RW_FUNCTION("frequency", SCA_ISensor, pyattr_get_frequency, pyattr_set_frequency),
- { NULL } //Sentinel
-};
-
-
-PyObject *SCA_ISensor::pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor* self = static_cast<SCA_ISensor*>(self_v);
- bool retval = false;
- if (SCA_PythonController::m_sCurrentController)
- retval = SCA_PythonController::m_sCurrentController->IsTriggered(self);
- return PyBool_FromLong(retval);
-}
-
-PyObject *SCA_ISensor::pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor* self = static_cast<SCA_ISensor*>(self_v);
- return PyBool_FromLong(self->GetState());
-}
-
-PyObject *SCA_ISensor::pyattr_get_status(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor* self = static_cast<SCA_ISensor*>(self_v);
- int status = 0;
- if (self->GetState())
- {
- if (self->GetState() == self->GetPrevState())
- {
- status = 2;
- }
- else
- {
- status = 1;
- }
- }
- else if (self->GetState() != self->GetPrevState())
- {
- status = 3;
- }
- return PyLong_FromLong(status);
-}
-
-PyObject *SCA_ISensor::pyattr_get_posTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor* self = static_cast<SCA_ISensor*>(self_v);
- return PyLong_FromLong(self->GetPosTicks());
-}
-
-PyObject *SCA_ISensor::pyattr_get_negTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor* self = static_cast<SCA_ISensor*>(self_v);
- return PyLong_FromLong(self->GetNegTicks());
-}
-
-int SCA_ISensor::pyattr_check_level(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor* self = static_cast<SCA_ISensor*>(self_v);
- if (self->m_level)
- self->m_tap = false;
- return 0;
-}
-
-int SCA_ISensor::pyattr_check_tap(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor* self = static_cast<SCA_ISensor*>(self_v);
- if (self->m_tap)
- self->m_level = false;
- return 0;
-}
-
-PyObject *SCA_ISensor::pyattr_get_frequency(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_ISensor *self = static_cast<SCA_ISensor*>(self_v);
- ShowDeprecationWarning("SCA_ISensor.frequency", "SCA_ISensor.skippedTicks");
- return PyLong_FromLong(self->m_skipped_ticks);
-}
-
-int SCA_ISensor::pyattr_set_frequency(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- SCA_ISensor *self = static_cast<SCA_ISensor*>(self_v);
- ShowDeprecationWarning("SCA_ISensor.frequency", "SCA_ISensor.skippedTicks");
- if (PyLong_Check(value)) {
- self->m_skipped_ticks = PyLong_AsLong(value);
- return PY_SET_ATTR_SUCCESS;
- }
- else {
- PyErr_SetString(PyExc_TypeError, "sensor.frequency = int: Sensor, expected an integer");
- return PY_SET_ATTR_FAIL;
- }
-}
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ISensor.h b/source/gameengine/GameLogic/SCA_ISensor.h
deleted file mode 100644
index 1e82f3ab11f..00000000000
--- a/source/gameengine/GameLogic/SCA_ISensor.h
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_ISensor.h
- * \ingroup gamelogic
- * \brief Interface Class for all logic Sensors. Implements
- * pulsemode and pulsefrequency, and event suppression.
- */
-
-#ifndef __SCA_ISENSOR_H__
-#define __SCA_ISENSOR_H__
-
-#include "SCA_IController.h"
-
-#include <vector>
-
-/**
- * Interface Class for all logic Sensors. Implements
- * pulsemode,pulsefrequency
- * Use of SG_DList element: link sensors to their respective event manager
- * Head: SCA_EventManager::m_sensors
- * Use of SG_QList element: not used
- */
-class SCA_ISensor : public SCA_ILogicBrick
-{
- Py_Header
-protected:
- class SCA_EventManager* m_eventmgr;
-
- /** Pulse positive pulses? */
- bool m_pos_pulsemode;
-
- /** Pulse negative pulses? */
- bool m_neg_pulsemode;
-
- /** Number of skipped ticks between two active pulses. */
- int m_skipped_ticks;
-
- /** Number of ticks since the last positive pulse. */
- int m_pos_ticks;
-
- /** Number of ticks since the last negative pulse. */
- int m_neg_ticks;
-
- /** invert the output signal*/
- bool m_invert;
-
- /** detect level instead of edge*/
- bool m_level;
-
- /** tap mode */
- bool m_tap;
-
- /** sensor has been reset */
- bool m_reset;
-
- /** Sensor must ignore updates? */
- bool m_suspended;
-
- /** number of connections to controller */
- int m_links;
-
- /** current sensor state */
- bool m_state;
-
- /** previous state (for tap option) */
- bool m_prev_state;
-
- std::vector<class SCA_IController*> m_linkedcontrollers;
-
-public:
-
- enum sensortype {
- ST_NONE = 0,
- ST_TOUCH,
- ST_NEAR,
- ST_RADAR,
- // to be updated as needed
- };
-
- SCA_ISensor(SCA_IObject* gameobj,
- class SCA_EventManager* eventmgr);
- ~SCA_ISensor();
- virtual void ReParent(SCA_IObject* parent);
-
- /** Because we want sensors to share some behavior, the Activate has */
- /* an implementation on this level. It requires an evaluate on the lower */
- /* level of individual sensors. Mapping the old activate()s is easy. */
- /* The IsPosTrig() also has to change, to keep things consistent. */
- void Activate(class SCA_LogicManager* logicmgr);
- virtual bool Evaluate() = 0;
- virtual bool IsPositiveTrigger();
- virtual void Init();
-
- virtual CValue* GetReplica()=0;
-
- /** Set parameters for the pulsing behavior.
- * \param posmode Trigger positive pulses?
- * \param negmode Trigger negative pulses?
- * \param freq Frequency to use when doing pulsing.
- */
- void SetPulseMode(bool posmode,
- bool negmode,
- int skippedticks);
-
- /** Set inversion of pulses on or off. */
- void SetInvert(bool inv);
- /** set the level detection on or off */
- void SetLevel(bool lvl);
- void SetTap(bool tap);
-
- virtual void RegisterToManager();
- virtual void UnregisterToManager();
- void Replace_EventManager(class SCA_LogicManager* logicmgr);
- void ReserveController(int num)
- {
- m_linkedcontrollers.reserve(num);
- }
- void LinkToController(SCA_IController* controller);
- void UnlinkController(SCA_IController* controller);
- void UnlinkAllControllers();
- void ActivateControllers(class SCA_LogicManager* logicmgr);
-
- virtual void ProcessReplica();
-
- virtual double GetNumber();
-
- virtual sensortype GetSensorType() { return ST_NONE; }
-
- /** Stop sensing for a while. */
- void Suspend();
-
- /** Is this sensor switched off? */
- bool IsSuspended();
-
- /** get the state of the sensor: positive or negative */
- bool GetState()
- {
- return m_state;
- }
-
- /** get the previous state of the sensor: positive or negative */
- bool GetPrevState()
- {
- return m_prev_state;
- }
-
- /** get the number of ticks since the last positive pulse */
- int GetPosTicks()
- {
- return m_pos_ticks;
- }
-
- /** get the number of ticks since the last negative pulse */
- int GetNegTicks()
- {
- return m_neg_ticks;
- }
-
- /** Resume sensing. */
- void Resume();
-
- void ClrLink()
- { m_links = 0; }
- void IncLink()
- { if (!m_links++) RegisterToManager(); }
- void DecLink();
- bool IsNoLink() const
- { return !m_links; }
-
-#ifdef WITH_PYTHON
- /* Python functions: */
- KX_PYMETHOD_DOC_NOARGS(SCA_ISensor,reset);
-
- static PyObject* pyattr_get_triggered(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_positive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_status(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_posTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_negTicks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_frequency(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_frequency(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static int pyattr_check_level(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_check_tap(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- enum SensorStatus {
- KX_SENSOR_INACTIVE = 0,
- KX_SENSOR_JUST_ACTIVATED,
- KX_SENSOR_ACTIVE,
- KX_SENSOR_JUST_DEACTIVATED
-
- };
-#endif /* WITH_PYTHON */
-};
-
-#endif /* __SCA_ISENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_JoystickManager.cpp b/source/gameengine/GameLogic/SCA_JoystickManager.cpp
deleted file mode 100644
index 780e4e9ce88..00000000000
--- a/source/gameengine/GameLogic/SCA_JoystickManager.cpp
+++ /dev/null
@@ -1,92 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_JoystickManager.cpp
- * \ingroup gamelogic
- */
-
-#include "SCA_JoystickSensor.h"
-#include "SCA_JoystickManager.h"
-#include "SCA_LogicManager.h"
-//#include <vector>
-#include "SCA_ISensor.h"
-
-//using namespace std;
-
-
-SCA_JoystickManager::SCA_JoystickManager(class SCA_LogicManager* logicmgr)
- : SCA_EventManager(logicmgr, JOY_EVENTMGR)
-{
- int i;
- for (i=0; i<JOYINDEX_MAX; i++) {
- m_joystick[i] = SCA_Joystick::GetInstance( i );
- }
-}
-
-
-SCA_JoystickManager::~SCA_JoystickManager()
-{
- int i;
- for (i=0; i<JOYINDEX_MAX; i++) {
- if (m_joystick[i])
- m_joystick[i]->ReleaseInstance();
- }
-}
-
-
-void SCA_JoystickManager::NextFrame(double curtime,double deltatime)
-{
- // We should always handle events in case we want to grab them with Python
-#ifdef WITH_SDL
- SCA_Joystick::HandleEvents(); /* Handle all SDL Joystick events */
-#endif
-
- if (m_sensors.Empty()) {
- return;
- }
- else {
- ;
- SG_DList::iterator<SCA_JoystickSensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- SCA_JoystickSensor* joysensor = *it;
- if (!joysensor->IsSuspended())
- {
- joysensor->Activate(m_logicmgr);
- }
- }
- }
-}
-
-
-SCA_Joystick *SCA_JoystickManager::GetJoystickDevice( short int joyindex)
-{
- /*
- *Return the instance of SCA_Joystick for use
- */
- return m_joystick[joyindex];
-}
diff --git a/source/gameengine/GameLogic/SCA_JoystickManager.h b/source/gameengine/GameLogic/SCA_JoystickManager.h
deleted file mode 100644
index 60dcaea4ef2..00000000000
--- a/source/gameengine/GameLogic/SCA_JoystickManager.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_JoystickManager.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_JOYSTICKMANAGER_H__
-#define __SCA_JOYSTICKMANAGER_H__
-
-#include "SCA_EventManager.h"
-#include "Joystick/SCA_Joystick.h"
-#include <vector>
-
-using namespace std;
-class SCA_JoystickManager : public SCA_EventManager
-{
- /**
- * SDL Joystick Class Instance
- */
- SCA_Joystick *m_joystick[JOYINDEX_MAX];
-public:
- SCA_JoystickManager(class SCA_LogicManager* logicmgr);
- virtual ~SCA_JoystickManager();
- virtual void NextFrame(double curtime,double deltatime);
- SCA_Joystick* GetJoystickDevice(short int joyindex);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_JoystickManager")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp b/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
deleted file mode 100644
index 56df9692e72..00000000000
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.cpp
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_JoystickSensor.cpp
- * \ingroup gamelogic
- */
-
-#include "SCA_JoystickManager.h"
-#include "SCA_JoystickSensor.h"
-
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-
-#include "EXP_PyObjectPlus.h"
-
-#include <stdio.h>
-#include <stddef.h>
-#include <iostream>
-
-
-
-SCA_JoystickSensor::SCA_JoystickSensor(class SCA_JoystickManager* eventmgr,
- SCA_IObject* gameobj,
- short int joyindex,
- short int joymode,
- int axis, int axisf,int prec,
- int button,
- int hat, int hatf, bool allevents)
- :SCA_ISensor(gameobj,eventmgr),
- m_axis(axis),
- m_axisf(axisf),
- m_button(button),
- m_hat(hat),
- m_hatf(hatf),
- m_precision(prec),
- m_joymode(joymode),
- m_joyindex(joyindex),
- m_bAllEvents(allevents)
-{
-/*
-std::cout << " axis " << m_axis << std::endl;
-std::cout << " axis flag " << m_axisf << std::endl;
-std::cout << " precision " << m_precision << std::endl;
-std::cout << " button " << m_button << std::endl;
-std::cout << " hat " << m_hat << std::endl;
-std::cout << " hat flag " << m_hatf << std::endl;
-*/
- Init();
-}
-
-void SCA_JoystickSensor::Init()
-{
- m_istrig=(m_invert)?1:0;
- m_istrig_prev=0;
- m_reset = true;
-}
-
-SCA_JoystickSensor::~SCA_JoystickSensor()
-{
-}
-
-
-CValue* SCA_JoystickSensor::GetReplica()
-{
- SCA_JoystickSensor* replica = new SCA_JoystickSensor(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
- replica->Init();
- return replica;
-}
-
-
-bool SCA_JoystickSensor::IsPositiveTrigger()
-{
- bool result = m_istrig;
- if (m_invert)
- result = !result;
- return result;
-}
-
-
-bool SCA_JoystickSensor::Evaluate()
-{
- SCA_Joystick *js = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex);
- bool result = false;
- bool reset = m_reset && m_level;
-
- if (js==NULL) /* no joystick - don't do anything */
- return false;
-
- m_reset = false;
-
- switch (m_joymode) {
- case KX_JOYSENSORMODE_AXIS:
- {
- /* what is what!
- * m_axisf == JOYAXIS_RIGHT, JOYAXIS_UP, JOYAXIS_DOWN, JOYAXIS_LEFT
- * m_axisf == 1 == up
- * m_axisf == 2 == left
- * m_axisf == 3 == down
- *
- * numberof== m_axis (1-4), range is half of JOYAXIS_MAX since
- * it assumes the axis joysticks are axis parirs (0,1), (2,3), etc
- * also note that this starts at 1 where functions its used
- * with expect a zero index.
- */
-
- if (!js->IsTrigAxis() && !reset) /* No events from SDL? - don't bother */
- return false;
-
- js->cSetPrecision(m_precision);
- if (m_bAllEvents) {
- if (js->aAxisPairIsPositive(m_axis-1)) { /* use zero based axis index internally */
- m_istrig = 1;
- result = true;
- }
- else {
- if (m_istrig) {
- m_istrig = 0;
- result = true;
- }
- }
- }
- else {
- if (js->aAxisPairDirectionIsPositive(m_axis-1, m_axisf)) { /* use zero based axis index internally */
- m_istrig = 1;
- result = true;
- }
- else {
- if (m_istrig) {
- m_istrig = 0;
- result = true;
- }
- }
- }
- break;
- }
- case KX_JOYSENSORMODE_AXIS_SINGLE:
- {
- /* Like KX_JOYSENSORMODE_AXIS but don't pair up axis */
- if (!js->IsTrigAxis() && !reset) /* No events from SDL? - don't bother */
- return false;
-
- /* No need for 'm_bAllEvents' check here since were only checking 1 axis */
- js->cSetPrecision(m_precision);
- if (js->aAxisIsPositive(m_axis-1)) { /* use zero based axis index internally */
- m_istrig = 1;
- result = true;
- }
- else {
- if (m_istrig) {
- m_istrig = 0;
- result = true;
- }
- }
- break;
- }
-
- case KX_JOYSENSORMODE_BUTTON:
- {
- /* what is what!
- * m_button = the actual button in question
- */
- if (!js->IsTrigButton() && !reset) /* No events from SDL? - don't bother */
- return false;
-
- if (( m_bAllEvents && js->aAnyButtonPressIsPositive()) || (!m_bAllEvents && js->aButtonPressIsPositive(m_button))) {
- m_istrig = 1;
- result = true;
- }
- else {
- if (m_istrig) {
- m_istrig = 0;
- result = true;
- }
- }
- break;
- }
- case KX_JOYSENSORMODE_HAT:
- {
- /* what is what!
- * numberof = m_hat -- max 4
- * direction= m_hatf -- max 12
- */
-
- if (!js->IsTrigHat() && !reset) /* No events from SDL? - don't bother */
- return false;
-
- if ((m_bAllEvents && js->GetHat(m_hat-1)) || js->aHatIsPositive(m_hat-1, m_hatf)) {
- m_istrig = 1;
- result = true;
- }
- else {
- if (m_istrig) {
- m_istrig = 0;
- result = true;
- }
- }
- break;
- }
- /* test for ball anyone ?*/
- default:
- printf("Error invalid switch statement\n");
- break;
- }
-
- /* if not all events are enabled, only send a positive pulse when
- * the button state changes */
- if (!m_bAllEvents) {
- if (m_istrig_prev == m_istrig) {
- result = false;
- }
- else {
- m_istrig_prev = m_istrig;
- }
- }
-
- if (reset)
- result = true;
-
- return result;
-}
-
-
-bool SCA_JoystickSensor::isValid(SCA_JoystickSensor::KX_JOYSENSORMODE m)
-{
- bool res = false;
- res = ((m > KX_JOYSENSORMODE_NODEF) && (m < KX_JOYSENSORMODE_MAX));
- return res;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_JoystickSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_JoystickSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_JoystickSensor::Methods[] = {
- {"getButtonActiveList",(PyCFunction) SCA_JoystickSensor::sPyGetButtonActiveList, METH_NOARGS,(const char *)GetButtonActiveList_doc},
- {"getButtonStatus",(PyCFunction) SCA_JoystickSensor::sPyGetButtonStatus, METH_VARARGS,(const char *)GetButtonStatus_doc},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_JoystickSensor::Attributes[] = {
- KX_PYATTRIBUTE_SHORT_RW("index",0,JOYINDEX_MAX-1,true,SCA_JoystickSensor,m_joyindex),
- KX_PYATTRIBUTE_INT_RW("threshold",0,32768,true,SCA_JoystickSensor,m_precision),
- KX_PYATTRIBUTE_INT_RW("button",0,100,false,SCA_JoystickSensor,m_button),
- KX_PYATTRIBUTE_INT_LIST_RW_CHECK("axis",0,3,true,SCA_JoystickSensor,m_axis,2,CheckAxis),
- KX_PYATTRIBUTE_INT_LIST_RW_CHECK("hat",0,12,true,SCA_JoystickSensor,m_hat,2,CheckHat),
- KX_PYATTRIBUTE_RO_FUNCTION("axisValues", SCA_JoystickSensor, pyattr_get_axis_values),
- KX_PYATTRIBUTE_RO_FUNCTION("axisSingle", SCA_JoystickSensor, pyattr_get_axis_single),
- KX_PYATTRIBUTE_RO_FUNCTION("hatValues", SCA_JoystickSensor, pyattr_get_hat_values),
- KX_PYATTRIBUTE_RO_FUNCTION("hatSingle", SCA_JoystickSensor, pyattr_get_hat_single),
- KX_PYATTRIBUTE_RO_FUNCTION("numAxis", SCA_JoystickSensor, pyattr_get_num_axis),
- KX_PYATTRIBUTE_RO_FUNCTION("numButtons", SCA_JoystickSensor, pyattr_get_num_buttons),
- KX_PYATTRIBUTE_RO_FUNCTION("numHats", SCA_JoystickSensor, pyattr_get_num_hats),
- KX_PYATTRIBUTE_RO_FUNCTION("connected", SCA_JoystickSensor, pyattr_get_connected),
- { NULL } //Sentinel
-};
-
-/* get button active list -------------------------------------------------- */
-const char SCA_JoystickSensor::GetButtonActiveList_doc[] =
-"getButtonActiveList\n"
-"\tReturns a list containing the indices of the button currently pressed.\n";
-PyObject *SCA_JoystickSensor::PyGetButtonActiveList( )
-{
- SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex);
- PyObject *ls = PyList_New(0);
- PyObject *value;
- int i;
-
- if (joy) {
- for (i=0; i < joy->GetNumberOfButtons(); i++) {
- if (joy->aButtonPressIsPositive(i)) {
- value = PyLong_FromLong(i);
- PyList_Append(ls, value);
- Py_DECREF(value);
- }
- }
- }
- return ls;
-}
-
-/* get button status -------------------------------------------------- */
-const char SCA_JoystickSensor::GetButtonStatus_doc[] =
-"getButtonStatus(buttonIndex)\n"
-"\tReturns a bool of the current pressed state of the specified button.\n";
-PyObject *SCA_JoystickSensor::PyGetButtonStatus( PyObject *args )
-{
- SCA_Joystick *joy = ((SCA_JoystickManager *)m_eventmgr)->GetJoystickDevice(m_joyindex);
- int index;
-
- if (!PyArg_ParseTuple(args, "i:getButtonStatus", &index)) {
- return NULL;
- }
- if (joy && index >= 0 && index < joy->GetNumberOfButtons()) {
- return PyBool_FromLong(joy->aButtonPressIsPositive(index) ? 1 : 0);
- }
- return PyBool_FromLong(0);
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
-
- int axis_index = (joy ? joy->GetNumberOfAxes() : 0);
- PyObject *list = PyList_New(axis_index);
-
- while (axis_index--) {
- PyList_SET_ITEM(list, axis_index, PyLong_FromLong(joy->GetAxisPosition(axis_index)));
- }
-
- return list;
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
-
- if (self->m_joymode != KX_JOYSENSORMODE_AXIS_SINGLE) {
- PyErr_SetString(PyExc_AttributeError, "val = sensor.axisSingle: Joystick Sensor, not 'Single Axis' type");
- return NULL;
- }
-
- return PyLong_FromLong(joy ? joy->GetAxisPosition(self->m_axis - 1) : 0);
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_hat_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
-
- int hat_index = (joy ? joy->GetNumberOfHats() : 0);
- PyObject *list = PyList_New(hat_index);
-
- while (hat_index--) {
- PyList_SET_ITEM(list, hat_index, PyLong_FromLong(joy->GetHat(hat_index)));
- }
-
- return list;
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_hat_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
-
- return PyLong_FromLong(joy ? joy->GetHat(self->m_hat - 1) : 0);
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
- return PyLong_FromLong( joy ? joy->GetNumberOfAxes() : 0 );
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
- return PyLong_FromLong( joy ? joy->GetNumberOfButtons() : 0 );
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
- return PyLong_FromLong( joy ? joy->GetNumberOfHats() : 0 );
-}
-
-PyObject *SCA_JoystickSensor::pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_JoystickSensor* self = static_cast<SCA_JoystickSensor*>(self_v);
- SCA_Joystick *joy = ((SCA_JoystickManager *)self->m_eventmgr)->GetJoystickDevice(self->m_joyindex);
- return PyBool_FromLong( joy ? joy->Connected() : 0 );
-}
-
-#endif
diff --git a/source/gameengine/GameLogic/SCA_JoystickSensor.h b/source/gameengine/GameLogic/SCA_JoystickSensor.h
deleted file mode 100644
index 6c6dc019a5e..00000000000
--- a/source/gameengine/GameLogic/SCA_JoystickSensor.h
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_JoystickSensor.h
- * \ingroup gamelogic
- */
-
-
-#ifndef __JOYSENSOR_H__
-#define __JOYSENSOR_H__
-
-#include "SCA_ISensor.h"
-#include "Joystick/SCA_JoystickDefines.h"
-
-class SCA_JoystickSensor :public SCA_ISensor
-{
- Py_Header
-
- /**
- * Axis 1-JOYAXIS_MAX, MUST be followed by m_axisf
- */
- int m_axis;
- /**
- * Axis flag to find direction, MUST be an int
- */
- int m_axisf;
- /**
- * The actual button
- */
- int m_button;
- /**
- * Flag for a pressed or released button
- */
- int m_buttonf;
- /**
- * The actual hat 1-JOYHAT_MAX. MUST be followed by m_hatf
- */
- int m_hat;
- /**
- * Flag to find direction 1-12, MUST be an int
- */
- int m_hatf;
- /**
- * The threshold value the axis acts upon
- */
- int m_precision;
- /**
- * Is an event triggered ?
- */
- bool m_istrig;
- /**
- * Last trigger state for this sensors joystick,
- * Otherwise it will trigger all the time
- * this is used to see if the trigger state changes.
- */
- bool m_istrig_prev;
- /**
- * The mode to determine axis,button or hat
- */
- short int m_joymode;
- /**
- * Select which joystick to use
- */
- short int m_joyindex;
-
- /**
- * Detect all events for the currently selected type
- */
- bool m_bAllEvents;
-
- enum KX_JOYSENSORMODE {
- KX_JOYSENSORMODE_NODEF = 0,
- KX_JOYSENSORMODE_AXIS,
- KX_JOYSENSORMODE_BUTTON,
- KX_JOYSENSORMODE_HAT,
- KX_JOYSENSORMODE_AXIS_SINGLE,
- KX_JOYSENSORMODE_MAX
- };
- bool isValid(KX_JOYSENSORMODE);
-
-public:
- SCA_JoystickSensor(class SCA_JoystickManager* eventmgr,
- SCA_IObject* gameobj,
- short int joyindex,
- short int joymode,
- int axis, int axisf,int prec,
- int button,
- int hat, int hatf, bool allevents);
- virtual ~SCA_JoystickSensor();
- virtual CValue* GetReplica();
-
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual void Init();
-
- short int GetJoyIndex(void) {
- return m_joyindex;
- }
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /* Joystick Index */
- KX_PYMETHOD_DOC_NOARGS(SCA_JoystickSensor,GetButtonActiveList)
- KX_PYMETHOD_DOC_VARARGS(SCA_JoystickSensor,GetButtonStatus)
-
- static PyObject* pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_axis_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_hat_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_hat_single(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_num_axis(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_num_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_num_hats(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_connected(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
-
- /* attribute check */
- static int CheckAxis(void *self, const PyAttributeDef*)
- {
- SCA_JoystickSensor* sensor = reinterpret_cast<SCA_JoystickSensor*>(self);
- if (sensor->m_axis < 1)
- sensor->m_axis = 1;
- else if (sensor->m_axis > JOYAXIS_MAX)
- sensor->m_axis = JOYAXIS_MAX;
- return 0;
- }
- static int CheckHat(void *self, const PyAttributeDef*)
- {
- SCA_JoystickSensor* sensor = reinterpret_cast<SCA_JoystickSensor*>(self);
- if (sensor->m_hat < 1)
- sensor->m_hat = 1;
- else if (sensor->m_hat > JOYHAT_MAX)
- sensor->m_hat = JOYHAT_MAX;
- return 0;
- }
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __JOYSENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_KeyboardManager.cpp b/source/gameengine/GameLogic/SCA_KeyboardManager.cpp
deleted file mode 100644
index 778ba9e9a2c..00000000000
--- a/source/gameengine/GameLogic/SCA_KeyboardManager.cpp
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * Manager for keyboard events
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_KeyboardManager.cpp
- * \ingroup gamelogic
- */
-
-
-#include "EXP_BoolValue.h"
-#include "SCA_KeyboardManager.h"
-#include "SCA_KeyboardSensor.h"
-#include "EXP_IntValue.h"
-#include <vector>
-
-SCA_KeyboardManager::SCA_KeyboardManager(SCA_LogicManager* logicmgr,
- SCA_IInputDevice* inputdev)
- : SCA_EventManager(logicmgr, KEYBOARD_EVENTMGR),
- m_inputDevice(inputdev)
-{
-}
-
-
-
-SCA_KeyboardManager::~SCA_KeyboardManager()
-{
-}
-
-
-
-SCA_IInputDevice* SCA_KeyboardManager::GetInputDevice()
-{
- return m_inputDevice;
-}
-
-
-
-void SCA_KeyboardManager::NextFrame()
-{
- //const SCA_InputEvent& event = GetEventValue(SCA_IInputDevice::KX_EnumInputs inputcode)=0;
-// cerr << "SCA_KeyboardManager::NextFrame"<< endl;
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Activate(m_logicmgr);
- }
-}
-
-bool SCA_KeyboardManager::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
- return false;
- //return m_kxsystem->IsPressed(inputcode);
-}
-
diff --git a/source/gameengine/GameLogic/SCA_KeyboardManager.h b/source/gameengine/GameLogic/SCA_KeyboardManager.h
deleted file mode 100644
index cd1cbf4adee..00000000000
--- a/source/gameengine/GameLogic/SCA_KeyboardManager.h
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_KeyboardManager.h
- * \ingroup gamelogic
- * \brief Manager for keyboard events
- *
- */
-
-#ifndef __SCA_KEYBOARDMANAGER_H__
-#define __SCA_KEYBOARDMANAGER_H__
-
-
-#include "SCA_EventManager.h"
-
-#include <vector>
-
-using namespace std;
-
-#include "SCA_IInputDevice.h"
-
-
-class SCA_KeyboardManager : public SCA_EventManager
-{
- class SCA_IInputDevice* m_inputDevice;
-
-public:
- SCA_KeyboardManager(class SCA_LogicManager* logicmgr,class SCA_IInputDevice* inputdev);
- virtual ~SCA_KeyboardManager();
-
- bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode);
-
- virtual void NextFrame();
- SCA_IInputDevice* GetInputDevice();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_KeyboardManager")
-#endif
-};
-
-#endif /* __SCA_KEYBOARDMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp b/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
deleted file mode 100644
index 414a685d358..00000000000
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.cpp
+++ /dev/null
@@ -1,668 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Sensor for keyboard input
- */
-
-/** \file gameengine/GameLogic/SCA_KeyboardSensor.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_KeyboardSensor.h"
-#include "SCA_KeyboardManager.h"
-#include "SCA_LogicManager.h"
-#include "EXP_StringValue.h"
-#include "SCA_IInputDevice.h"
-
-extern "C" {
- #include "BLI_string_utf8.h"
- #include "BLI_string_cursor_utf8.h"
-}
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_KeyboardSensor::SCA_KeyboardSensor(SCA_KeyboardManager* keybdmgr,
- short int hotkey,
- short int qual,
- short int qual2,
- bool bAllKeys,
- const STR_String& targetProp,
- const STR_String& toggleProp,
- SCA_IObject* gameobj,
- short int exitKey)
- :SCA_ISensor(gameobj,keybdmgr),
- m_hotkey(hotkey),
- m_qual(qual),
- m_qual2(qual2),
- m_bAllKeys(bAllKeys),
- m_targetprop(targetProp),
- m_toggleprop(toggleProp)
-{
- if (hotkey == exitKey)
- keybdmgr->GetInputDevice()->HookEscape();
-// SetDrawColor(0xff0000ff);
- Init();
-}
-
-
-
-SCA_KeyboardSensor::~SCA_KeyboardSensor()
-{
-}
-
-void SCA_KeyboardSensor::Init()
-{
- // this function is used when the sensor is disconnected from all controllers
- // by the state engine. It reinitializes the sensor as if it was just created.
- // However, if the target key is pressed when the sensor is reactivated, it
- // will not generated an event (see remark in Evaluate()).
- m_val = (m_invert)?1:0;
- m_reset = true;
-}
-
-CValue* SCA_KeyboardSensor::GetReplica()
-{
- SCA_KeyboardSensor* replica = new SCA_KeyboardSensor(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
- replica->Init();
- return replica;
-}
-
-
-
-short int SCA_KeyboardSensor::GetHotkey()
-{
- return m_hotkey;
-}
-
-
-
-bool SCA_KeyboardSensor::IsPositiveTrigger()
-{
- bool result = (m_val != 0);
-
- if (m_invert)
- result = !result;
-
- return result;
-}
-
-
-
-bool SCA_KeyboardSensor::TriggerOnAllKeys()
-{
- return m_bAllKeys;
-}
-
-
-
-bool SCA_KeyboardSensor::Evaluate()
-{
- bool result = false;
- bool reset = m_reset && m_level;
- bool qual = true;
- bool qual_change = false;
- short int m_val_orig = m_val;
-
- SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
- // cerr << "SCA_KeyboardSensor::Eval event, sensing for "<< m_hotkey << " at device " << inputdev << "\n";
-
- /* See if we need to do logging: togPropState exists and is
- * different from 0 */
- CValue* myparent = GetParent();
- CValue* togPropState = myparent->GetProperty(m_toggleprop);
- if (togPropState &&
- (((int)togPropState->GetNumber()) != 0) )
- {
- LogKeystrokes();
- }
-
- m_reset = false;
-
- /* Now see whether events must be bounced. */
- if (m_bAllKeys)
- {
- bool justactivated = false;
- bool justreleased = false;
- bool active = false;
-
- for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++)
- {
- const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i);
- switch (inevent.m_status)
- {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- justactivated = true;
- break;
- case SCA_InputEvent::KX_JUSTRELEASED:
- justreleased = true;
- break;
- case SCA_InputEvent::KX_ACTIVE:
- active = true;
- break;
- case SCA_InputEvent::KX_NO_INPUTSTATUS:
- /* do nothing */
- break;
- }
- }
-
- if (justactivated)
- {
- m_val=1;
- result = true;
- } else
- {
- if (justreleased)
- {
- m_val=(active)?1:0;
- result = true;
- } else
- {
- if (active)
- {
- if (m_val == 0)
- {
- m_val = 1;
- if (m_level) {
- result = true;
- }
- }
- } else
- {
- if (m_val == 1)
- {
- m_val = 0;
- result = true;
- }
- }
- }
- if (m_tap)
- // special case for tap mode: only generate event for new activation
- result = false;
- }
-
-
- } else
- {
-
- // cerr << "======= SCA_KeyboardSensor::Evaluate:: peeking at key status" << endl;
- const SCA_InputEvent & inevent = inputdev->GetEventValue(
- (SCA_IInputDevice::KX_EnumInputs) m_hotkey);
-
- // cerr << "======= SCA_KeyboardSensor::Evaluate:: status: " << inevent.m_status << endl;
-
-
- /* Check qualifier keys
- * - see if the qualifiers we request are pressed - 'qual' true/false
- * - see if the qualifiers we request changed their state - 'qual_change' true/false
- */
- if (m_qual > 0) {
- const SCA_InputEvent & qualevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) m_qual);
- switch (qualevent.m_status) {
- case SCA_InputEvent::KX_NO_INPUTSTATUS:
- qual = false;
- break;
- case SCA_InputEvent::KX_JUSTRELEASED:
- qual_change = true;
- qual = false;
- break;
- case SCA_InputEvent::KX_JUSTACTIVATED:
- qual_change = true;
- case SCA_InputEvent::KX_ACTIVE:
- /* do nothing */
- break;
- }
- }
- if (m_qual2 > 0 && qual==true) {
- const SCA_InputEvent & qualevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) m_qual2);
- /* copy of above */
- switch (qualevent.m_status) {
- case SCA_InputEvent::KX_NO_INPUTSTATUS:
- qual = false;
- break;
- case SCA_InputEvent::KX_JUSTRELEASED:
- qual_change = true;
- qual = false;
- break;
- case SCA_InputEvent::KX_JUSTACTIVATED:
- qual_change = true;
- case SCA_InputEvent::KX_ACTIVE:
- /* do nothing */
- break;
- }
- }
- /* done reading qualifiers */
-
- if (inevent.m_status == SCA_InputEvent::KX_NO_INPUTSTATUS)
- {
- if (m_val == 1)
- {
- // this situation may occur after a scene suspend: the keyboard release
- // event was not captured, produce now the event off
- m_val = 0;
- result = true;
- }
- } else
- {
- if (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED)
- {
- m_val=1;
- result = true;
- } else
- {
- if (inevent.m_status == SCA_InputEvent::KX_JUSTRELEASED)
- {
- m_val = 0;
- result = true;
- } else
- {
- if (inevent.m_status == SCA_InputEvent::KX_ACTIVE)
- {
- if (m_val == 0)
- {
- m_val = 1;
- if (m_level)
- {
- result = true;
- }
- }
- }
- }
- }
- }
-
- /* Modify the key state based on qual(s)
- * Tested carefully. don't touch unless your really sure.
- * note, this will only change the results if key modifiers are set.
- *
- * When all modifiers and keys are positive
- * - pulse true
- *
- * When ANY of the modifiers or main key become inactive,
- * - pulse false
- */
- if (qual==false) { /* one of the qualifiers are not pressed */
- if (m_val_orig && qual_change) { /* we were originally enabled, but a qualifier changed */
- result = true;
- } else {
- result = false;
- }
- m_val = 0; /* since one of the qualifiers is not on, set the state to false */
- } else { /* we done have any qualifiers or they are all pressed */
- if (m_val && qual_change) { /* the main key state is true and our qualifier just changed */
- result = true;
- }
- }
- /* done with key quals */
-
- }
-
- if (reset)
- // force an event
- result = true;
- return result;
-
-}
-
-void SCA_KeyboardSensor::AddToTargetProp(int keyIndex, int unicode)
-{
- if (IsPrintable(keyIndex)) {
- CValue* tprop = GetParent()->GetProperty(m_targetprop);
-
- if (IsDelete(keyIndex)) {
- /* Make a new property. Deletes can be ignored. */
- if (tprop) {
- /* overwrite the old property */
- /* strip one char, if possible */
- STR_String newprop = tprop->GetText();
- int oldlength = newprop.Length();
- if (oldlength >= 1 ) {
- int newlength=oldlength;
-
- BLI_str_cursor_step_prev_utf8(newprop, newprop.Length(), &newlength);
- newprop.SetLength(newlength);
-
- CStringValue * newstringprop = new CStringValue(newprop, m_targetprop);
- GetParent()->SetProperty(m_targetprop, newstringprop);
- newstringprop->Release();
- }
- }
- }
- else {
- char utf8_buf[7];
- size_t utf8_len;
-
- utf8_len = BLI_str_utf8_from_unicode(unicode, utf8_buf);
- utf8_buf[utf8_len] = '\0';
-
- STR_String newprop = tprop ? (tprop->GetText() + utf8_buf) : utf8_buf;
-
- CStringValue * newstringprop = new CStringValue(newprop, m_targetprop);
- GetParent()->SetProperty(m_targetprop, newstringprop);
- newstringprop->Release();
- }
- }
-}
-
-/**
- * Tests whether shift is pressed
- */
-bool SCA_KeyboardSensor::IsShifted(void)
-{
- SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
-
- if ( (inputdev->GetEventValue(SCA_IInputDevice::KX_RIGHTSHIFTKEY).m_status
- == SCA_InputEvent::KX_ACTIVE)
- || (inputdev->GetEventValue(SCA_IInputDevice::KX_RIGHTSHIFTKEY).m_status
- == SCA_InputEvent::KX_JUSTACTIVATED)
- || (inputdev->GetEventValue(SCA_IInputDevice::KX_LEFTSHIFTKEY).m_status
- == SCA_InputEvent::KX_ACTIVE)
- || (inputdev->GetEventValue(SCA_IInputDevice::KX_LEFTSHIFTKEY).m_status
- == SCA_InputEvent::KX_JUSTACTIVATED)
- ) {
- return true;
- }
- else {
- return false;
- }
-}
-
-void SCA_KeyboardSensor::LogKeystrokes(void)
-{
- SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
- int num = inputdev->GetNumActiveEvents();
-
- /* weird loop, this one... */
- if (num > 0)
- {
-
- int index = 0;
- /* Check on all keys whether they were pushed. This does not
- * untangle the ordering, so don't type too fast :) */
- for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++)
- {
- const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i);
- if (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED) //NO_INPUTSTATUS)
- {
- if (index < num)
- {
- AddToTargetProp(i, inevent.m_unicode);
- index++;
- }
- }
- }
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python Functions */
-/* ------------------------------------------------------------------------- */
-
-KX_PYMETHODDEF_DOC_O(SCA_KeyboardSensor, getKeyStatus,
-"getKeyStatus(keycode)\n"
-"\tGet the given key's status (KX_NO_INPUTSTATUS, KX_JUSTACTIVATED, KX_ACTIVE or KX_JUSTRELEASED).\n")
-{
- if (!PyLong_Check(value)) {
- PyErr_SetString(PyExc_ValueError, "sensor.getKeyStatus(int): Keyboard Sensor, expected an int");
- return NULL;
- }
-
- SCA_IInputDevice::KX_EnumInputs keycode = (SCA_IInputDevice::KX_EnumInputs)PyLong_AsLong(value);
-
- if ((keycode < SCA_IInputDevice::KX_BEGINKEY) ||
- (keycode > SCA_IInputDevice::KX_ENDKEY))
- {
- PyErr_SetString(PyExc_AttributeError, "sensor.getKeyStatus(int): Keyboard Sensor, invalid keycode specified!");
- return NULL;
- }
-
- SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)m_eventmgr)->GetInputDevice();
- const SCA_InputEvent & inevent = inputdev->GetEventValue(keycode);
- return PyLong_FromLong(inevent.m_status);
-}
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject SCA_KeyboardSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_KeyboardSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_KeyboardSensor::Methods[] = {
- KX_PYMETHODTABLE_O(SCA_KeyboardSensor, getKeyStatus),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_KeyboardSensor::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_KeyboardSensor, pyattr_get_events),
- KX_PYATTRIBUTE_BOOL_RW("useAllKeys",SCA_KeyboardSensor,m_bAllKeys),
- KX_PYATTRIBUTE_INT_RW("key",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_hotkey),
- KX_PYATTRIBUTE_SHORT_RW("hold1",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual),
- KX_PYATTRIBUTE_SHORT_RW("hold2",0,SCA_IInputDevice::KX_ENDKEY,true,SCA_KeyboardSensor,m_qual2),
- KX_PYATTRIBUTE_STRING_RW("toggleProperty",0,MAX_PROP_NAME,false,SCA_KeyboardSensor,m_toggleprop),
- KX_PYATTRIBUTE_STRING_RW("targetProperty",0,MAX_PROP_NAME,false,SCA_KeyboardSensor,m_targetprop),
- { NULL } //Sentinel
-};
-
-
-PyObject *SCA_KeyboardSensor::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_KeyboardSensor* self = static_cast<SCA_KeyboardSensor*>(self_v);
-
- SCA_IInputDevice* inputdev = ((SCA_KeyboardManager *)self->m_eventmgr)->GetInputDevice();
-
- PyObject *resultlist = PyList_New(0);
-
- for (int i=SCA_IInputDevice::KX_BEGINKEY ; i<= SCA_IInputDevice::KX_ENDKEY;i++)
- {
- const SCA_InputEvent & inevent = inputdev->GetEventValue((SCA_IInputDevice::KX_EnumInputs) i);
- if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS)
- {
- PyObject *keypair = PyList_New(2);
- PyList_SET_ITEM(keypair,0,PyLong_FromLong(i));
- PyList_SET_ITEM(keypair,1,PyLong_FromLong(inevent.m_status));
- PyList_Append(resultlist,keypair);
- Py_DECREF(keypair);
- }
- }
- return resultlist;
-}
-
-#endif // WITH_PYTHON
-
-/* Accessed from python */
-
-// this code looks ugly, please use an ordinary hashtable
-
-char ToCharacter(int keyIndex, bool shifted)
-{
- /* numerals */
- if ( (keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
- && (keyIndex <= SCA_IInputDevice::KX_NINEKEY) ) {
- if (shifted) {
- char numshift[] = ")!@#$%^&*(";
- return numshift[keyIndex - '0'];
- } else {
- return keyIndex - SCA_IInputDevice::KX_ZEROKEY + '0';
- }
- }
-
- /* letters... always lowercase... is that desirable? */
- if ( (keyIndex >= SCA_IInputDevice::KX_AKEY)
- && (keyIndex <= SCA_IInputDevice::KX_ZKEY) ) {
- if (shifted) {
- return keyIndex - SCA_IInputDevice::KX_AKEY + 'A';
- } else {
- return keyIndex - SCA_IInputDevice::KX_AKEY + 'a';
- }
- }
-
- if (keyIndex == SCA_IInputDevice::KX_SPACEKEY) {
- return ' ';
- }
- if (keyIndex == SCA_IInputDevice::KX_RETKEY || keyIndex == SCA_IInputDevice::KX_PADENTER) {
- return '\n';
- }
-
-
- if (keyIndex == SCA_IInputDevice::KX_PADASTERKEY) {
- return '*';
- }
-
- if (keyIndex == SCA_IInputDevice::KX_TABKEY) {
- return '\t';
- }
-
- /* comma to period */
- char commatoperiod[] = ",-.";
- char commatoperiodshifted[] = "<_>";
- if (keyIndex == SCA_IInputDevice::KX_COMMAKEY) {
- if (shifted) {
- return commatoperiodshifted[0];
- } else {
- return commatoperiod[0];
- }
- }
- if (keyIndex == SCA_IInputDevice::KX_MINUSKEY) {
- if (shifted) {
- return commatoperiodshifted[1];
- } else {
- return commatoperiod[1];
- }
- }
- if (keyIndex == SCA_IInputDevice::KX_PERIODKEY) {
- if (shifted) {
- return commatoperiodshifted[2];
- } else {
- return commatoperiod[2];
- }
- }
-
- /* semicolon to rightbracket */
- char semicolontorightbracket[] = ";\'`/\\=[]";
- char semicolontorightbracketshifted[] = ":\"~\?|+{}";
- if ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
- && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY)) {
- if (shifted) {
- return semicolontorightbracketshifted[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
- } else {
- return semicolontorightbracket[keyIndex - SCA_IInputDevice::KX_SEMICOLONKEY];
- }
- }
-
- /* keypad2 to padplus */
- char pad2topadplus[] = "246813579. 0- +";
- if ((keyIndex >= SCA_IInputDevice::KX_PAD2)
- && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY)) {
- return pad2topadplus[keyIndex - SCA_IInputDevice::KX_PAD2];
- }
-
- return '!';
-}
-
-
-
-/**
- * Determine whether this character can be printed. We cannot use
- * the library functions here, because we need to test our own
- * keycodes. */
-bool IsPrintable(int keyIndex)
-{
- /* only print
- * - numerals: KX_ZEROKEY to KX_NINEKEY
- * - alphas: KX_AKEY to KX_ZKEY.
- * - specials: KX_RETKEY, KX_PADASTERKEY, KX_PADCOMMAKEY to KX_PERIODKEY,
- * KX_TABKEY, KX_SEMICOLONKEY to KX_RIGHTBRACKETKEY,
- * KX_PAD2 to KX_PADPLUSKEY
- * - delete and backspace: also printable in the sense that they modify
- * the string
- * - retkey: should this be printable?
- * - virgule: prints a space... don't know which key that's supposed
- * to be...
- */
- if ( ((keyIndex >= SCA_IInputDevice::KX_ZEROKEY)
- && (keyIndex <= SCA_IInputDevice::KX_NINEKEY))
- || ((keyIndex >= SCA_IInputDevice::KX_AKEY)
- && (keyIndex <= SCA_IInputDevice::KX_ZKEY))
- || (keyIndex == SCA_IInputDevice::KX_SPACEKEY)
- || (keyIndex == SCA_IInputDevice::KX_RETKEY)
- || (keyIndex == SCA_IInputDevice::KX_PADENTER)
- || (keyIndex == SCA_IInputDevice::KX_PADASTERKEY)
- || (keyIndex == SCA_IInputDevice::KX_TABKEY)
- || ((keyIndex >= SCA_IInputDevice::KX_COMMAKEY)
- && (keyIndex <= SCA_IInputDevice::KX_PERIODKEY))
- || ((keyIndex >= SCA_IInputDevice::KX_SEMICOLONKEY)
- && (keyIndex <= SCA_IInputDevice::KX_RIGHTBRACKETKEY))
- || ((keyIndex >= SCA_IInputDevice::KX_PAD2)
- && (keyIndex <= SCA_IInputDevice::KX_PADPLUSKEY))
- || (keyIndex == SCA_IInputDevice::KX_DELKEY)
- || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY)
- )
- {
- return true;
- } else {
- return false;
- }
-}
-
-/**
- * Tests whether this is a delete key.
- */
-bool IsDelete(int keyIndex)
-{
- if ( (keyIndex == SCA_IInputDevice::KX_DELKEY)
- || (keyIndex == SCA_IInputDevice::KX_BACKSPACEKEY) ) {
- return true;
- } else {
- return false;
- }
-}
diff --git a/source/gameengine/GameLogic/SCA_KeyboardSensor.h b/source/gameengine/GameLogic/SCA_KeyboardSensor.h
deleted file mode 100644
index 51d7756bd1f..00000000000
--- a/source/gameengine/GameLogic/SCA_KeyboardSensor.h
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_KeyboardSensor.h
- * \ingroup gamelogic
- * \brief Sensor for keyboard input
- */
-
-#ifndef __SCA_KEYBOARDSENSOR_H__
-#define __SCA_KEYBOARDSENSOR_H__
-
-#include "SCA_ISensor.h"
-#include "EXP_BoolValue.h"
-#include <list>
-
-/**
- * The keyboard sensor listens to the keyboard, and passes on events
- * on selected keystrokes. It has an alternate mode in which it logs
- * keypresses to a property. Note that these modes are not mutually
- * exclusive. */
-class SCA_KeyboardSensor : public SCA_ISensor
-{
- Py_Header
-
- /**
- * the key this sensor is sensing for
- */
- int m_hotkey;
- short int m_qual,m_qual2;
- short int m_val;
- /**
- * If this toggle is true, all incoming key events generate a
- * response.
- */
- bool m_bAllKeys;
-
- /**
- * The name of the property to which logged text is appended. If
- * this property is not defined, no logging takes place.
- */
- STR_String m_targetprop;
- /**
- * The property that indicates whether or not to log text when in
- * logging mode. If the property equals 0, no logging is done. For
- * all other values, logging is active. Logging can only become
- * active if there is a property to log to. Logging is independent
- * from hotkey settings. */
- STR_String m_toggleprop;
-
- /**
- * Log the keystrokes from the current input buffer.
- */
- void LogKeystrokes(void);
-
- /**
- * Adds this key-code to the target prop.
- */
- void AddToTargetProp(int keyIndex, int unicode);
-
- /**
- * Tests whether shift is pressed.
- */
- bool IsShifted(void);
-
-public:
- SCA_KeyboardSensor(class SCA_KeyboardManager* keybdmgr,
- short int hotkey,
- short int qual,
- short int qual2,
- bool bAllKeys,
- const STR_String& targetProp,
- const STR_String& toggleProp,
- SCA_IObject* gameobj,
- short int exitKey);
- virtual ~SCA_KeyboardSensor();
- virtual CValue* GetReplica();
- virtual void Init();
-
-
- short int GetHotkey();
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- bool TriggerOnAllKeys();
-
-#ifdef WITH_PYTHON
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- // KeyEvents:
- KX_PYMETHOD_DOC_NOARGS(SCA_KeyboardSensor,getEventList);
- // KeyStatus:
- KX_PYMETHOD_DOC_O(SCA_KeyboardSensor,getKeyStatus);
-
- static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-};
-
-
-/**
- * Transform keycodes to something printable.
- */
-char ToCharacter(int keyIndex, bool shifted);
-
-/**
- * Determine whether this character can be printed. We cannot use
- * the library functions here, because we need to test our own
- * keycodes. */
-bool IsPrintable(int keyIndex);
-
-/**
- * Tests whether this is a delete key.
- */
-bool IsDelete(int keyIndex);
-
-
-#endif /* __SCA_KEYBOARDSENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_LogicManager.cpp b/source/gameengine/GameLogic/SCA_LogicManager.cpp
deleted file mode 100644
index 978f6d6b836..00000000000
--- a/source/gameengine/GameLogic/SCA_LogicManager.cpp
+++ /dev/null
@@ -1,342 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Regulates the top-level logic behavior for one scene.
- */
-
-/** \file gameengine/GameLogic/SCA_LogicManager.cpp
- * \ingroup gamelogic
- */
-
-#include "EXP_Value.h"
-#include "SCA_LogicManager.h"
-#include "SCA_ISensor.h"
-#include "SCA_IController.h"
-#include "SCA_IActuator.h"
-#include "SCA_EventManager.h"
-#include "SCA_PythonController.h"
-#include <set>
-
-
-SCA_LogicManager::SCA_LogicManager()
-{
-}
-
-
-
-SCA_LogicManager::~SCA_LogicManager()
-{
- for (vector<SCA_EventManager*>::iterator it = m_eventmanagers.begin();!(it==m_eventmanagers.end());++it)
- {
- delete (*it);
- }
- m_eventmanagers.clear();
- assert(m_activeActuators.Empty());
-}
-
-#if 0
-// this kind of fixes bug 398 but breakes games, so better leave it out for now.
-// a removed object's gameobject (and logicbricks and stuff) didn't get released
-// because it was still in the m_mapStringToGameObjects map.
-void SCA_LogicManager::RemoveGameObject(const STR_String& gameobjname)
-{
- int numgameobj = m_mapStringToGameObjects.size();
- for (int i = 0; i < numgameobj; i++)
- {
- CValue** gameobjptr = m_mapStringToGameObjects.at(i);
- assert(gameobjptr);
-
- if (gameobjptr)
- {
- if ((*gameobjptr)->GetName() == gameobjname)
- (*gameobjptr)->Release();
- }
- }
-
- m_mapStringToGameObjects.remove(gameobjname);
-}
-#endif
-
-
-void SCA_LogicManager::RegisterEventManager(SCA_EventManager* eventmgr)
-{
- m_eventmanagers.push_back(eventmgr);
-}
-
-
-
-void SCA_LogicManager::RegisterGameObjectName(const STR_String& gameobjname,
- CValue* gameobj)
-{
- STR_HashedString mn = gameobjname;
- m_mapStringToGameObjects.insert(mn,gameobj);
-}
-
-
-
-void SCA_LogicManager::RegisterGameMeshName(const STR_String& gamemeshname, void* blendobj)
-{
- STR_HashedString mn = gamemeshname;
- m_map_gamemeshname_to_blendobj.insert(mn, blendobj);
-}
-
-
-
-void SCA_LogicManager::RegisterGameObj(void* blendobj, CValue* gameobj)
-{
- m_map_blendobj_to_gameobj.insert(CHashedPtr(blendobj), gameobj);
-}
-
-void SCA_LogicManager::UnregisterGameObj(void* blendobj, CValue* gameobj)
-{
- void **obp = m_map_blendobj_to_gameobj[CHashedPtr(blendobj)];
- if (obp && (CValue*)(*obp) == gameobj)
- m_map_blendobj_to_gameobj.remove(CHashedPtr(blendobj));
-}
-
-CValue* SCA_LogicManager::GetGameObjectByName(const STR_String& gameobjname)
-{
- STR_HashedString mn = gameobjname;
- CValue** gameptr = m_mapStringToGameObjects[mn];
-
- if (gameptr)
- return *gameptr;
-
- return NULL;
-}
-
-
-CValue* SCA_LogicManager::FindGameObjByBlendObj(void* blendobj)
-{
- void **obp= m_map_blendobj_to_gameobj[CHashedPtr(blendobj)];
- return obp?(CValue*)(*obp):NULL;
-}
-
-
-
-void* SCA_LogicManager::FindBlendObjByGameMeshName(const STR_String& gamemeshname)
-{
- STR_HashedString mn = gamemeshname;
- void **obp= m_map_gamemeshname_to_blendobj[mn];
- return obp?*obp:NULL;
-}
-
-
-
-void SCA_LogicManager::RemoveSensor(SCA_ISensor* sensor)
-{
- sensor->UnlinkAllControllers();
- sensor->UnregisterToManager();
-}
-
-void SCA_LogicManager::RemoveController(SCA_IController* controller)
-{
- controller->UnlinkAllSensors();
- controller->UnlinkAllActuators();
- controller->Deactivate();
-}
-
-
-void SCA_LogicManager::RemoveActuator(SCA_IActuator* actuator)
-{
- actuator->UnlinkAllControllers();
- actuator->Deactivate();
- actuator->SetActive(false);
-}
-
-
-
-void SCA_LogicManager::RegisterToSensor(SCA_IController* controller,SCA_ISensor* sensor)
-{
- sensor->LinkToController(controller);
- controller->LinkToSensor(sensor);
-}
-
-
-
-void SCA_LogicManager::RegisterToActuator(SCA_IController* controller,SCA_IActuator* actua)
-{
- actua->LinkToController(controller);
- controller->LinkToActuator(actua);
-}
-
-
-
-void SCA_LogicManager::BeginFrame(double curtime, double fixedtime)
-{
- for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++)
- (*ie)->NextFrame(curtime, fixedtime);
-
- for (SG_QList* obj = (SG_QList*)m_triggeredControllerSet.Remove();
- obj != NULL;
- obj = (SG_QList*)m_triggeredControllerSet.Remove())
- {
- for (SCA_IController* contr = (SCA_IController*)obj->QRemove();
- contr != NULL;
- contr = (SCA_IController*)obj->QRemove())
- {
- contr->Trigger(this);
- contr->ClrJustActivated();
- }
- }
-}
-
-
-
-void SCA_LogicManager::UpdateFrame(double curtime, bool frame)
-{
- for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin(); !(ie==m_eventmanagers.end()); ie++)
- (*ie)->UpdateFrame();
-
- SG_DList::iterator<SG_QList> io(m_activeActuators);
- for (io.begin(); !io.end(); )
- {
- SG_QList* ahead = *io;
- // increment now so that we can remove the current element
- ++io;
- SG_QList::iterator<SCA_IActuator> ia(*ahead);
- for (ia.begin(); !ia.end(); )
- {
- SCA_IActuator* actua = *ia;
- // increment first to allow removal of inactive actuators.
- ++ia;
- if (!actua->Update(curtime, frame))
- {
- // this actuator is not active anymore, remove
- actua->QDelink();
- actua->SetActive(false);
- } else if (actua->IsNoLink())
- {
- // This actuator has no more links but it still active
- // make sure it will get a negative event on next frame to stop it
- // Do this check after Update() rather than before to make sure
- // that all the actuators that are activated at same time than a state
- // actuator have a chance to execute.
- bool event = false;
- actua->RemoveAllEvents();
- actua->AddEvent(event);
- }
- }
- if (ahead->QEmpty())
- {
- // no more active controller, remove from main list
- ahead->Delink();
- }
- }
-}
-
-
-
-void *SCA_LogicManager::GetActionByName(const STR_String& actname)
-{
- STR_HashedString an = actname;
- void** actptr = m_mapStringToActions[an];
-
- if (actptr)
- return *actptr;
-
- return NULL;
-}
-
-
-
-void* SCA_LogicManager::GetMeshByName(const STR_String& meshname)
-{
- STR_HashedString mn = meshname;
- void** meshptr = m_mapStringToMeshes[mn];
-
- if (meshptr)
- return *meshptr;
-
- return NULL;
-}
-
-
-
-void SCA_LogicManager::RegisterMeshName(const STR_String& meshname,void* mesh)
-{
- STR_HashedString mn = meshname;
- m_mapStringToMeshes.insert(mn,mesh);
-}
-
-void SCA_LogicManager::UnregisterMeshName(const STR_String& meshname,void* mesh)
-{
- STR_HashedString mn = meshname;
- m_mapStringToMeshes.remove(mn);
-}
-
-
-void SCA_LogicManager::RegisterActionName(const STR_String& actname,void* action)
-{
- STR_HashedString an = actname;
- m_mapStringToActions.insert(an, action);
-}
-
-
-
-void SCA_LogicManager::EndFrame()
-{
- for (vector<SCA_EventManager*>::const_iterator ie=m_eventmanagers.begin();
- !(ie==m_eventmanagers.end());ie++)
- {
- (*ie)->EndFrame();
- }
-}
-
-
-void SCA_LogicManager::AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor)
-{
- controller->Activate(m_triggeredControllerSet);
-
-#ifdef WITH_PYTHON
-
- // so that the controller knows which sensor has activited it
- // only needed for python controller
- // Note that this is safe even if the controller is subclassed.
- if (controller->GetType() == &SCA_PythonController::Type)
- {
- SCA_PythonController* pythonController = (SCA_PythonController*)controller;
- pythonController->AddTriggeredSensor(sensor);
- }
-#endif
-}
-
-SCA_EventManager* SCA_LogicManager::FindEventManager(int eventmgrtype)
-{
- // find an eventmanager of a certain type
- SCA_EventManager* eventmgr = NULL;
-
- for (vector<SCA_EventManager*>::const_iterator i=
- m_eventmanagers.begin();!(i==m_eventmanagers.end());i++)
- {
- SCA_EventManager* emgr = *i;
- if (emgr->GetType() == eventmgrtype)
- {
- eventmgr = emgr;
- break;
- }
- }
- return eventmgr;
-}
diff --git a/source/gameengine/GameLogic/SCA_LogicManager.h b/source/gameengine/GameLogic/SCA_LogicManager.h
deleted file mode 100644
index 7319bb537dd..00000000000
--- a/source/gameengine/GameLogic/SCA_LogicManager.h
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-/** \file SCA_LogicManager.h
- * \ingroup gamelogic
- * \brief Regulates the top-level logic behavior for one scene.
- */
-#ifndef __SCA_LOGICMANAGER_H__
-#define __SCA_LOGICMANAGER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include <vector>
-//#include "CTR_Map.h"
-#include <set>
-#include <map>
-#include <list>
-
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include "EXP_Value.h"
-#include "SG_QList.h"
-
-#include "EXP_HashedPtr.h"
-
-using namespace std;
-typedef std::list<class SCA_IController*> controllerlist;
-typedef std::map<class SCA_ISensor*,controllerlist > sensormap_t;
-
-/**
- * This manager handles sensor, controllers and actuators.
- * logic executes each frame the following way:
- * find triggering sensors
- * build list of controllers that are triggered by these triggering sensors
- * process all triggered controllers
- * during this phase actuators can be added to the active actuator list
- * process all active actuators
- * clear triggering sensors
- * clear triggered controllers
- * (actuators may be active during a longer timeframe)
- */
-
-#include "SCA_ILogicBrick.h"
-#include "SCA_IActuator.h"
-#include "SCA_EventManager.h"
-
-
-class SCA_LogicManager
-{
- vector<class SCA_EventManager*> m_eventmanagers;
-
- // SG_DList: Head of objects having activated actuators
- // element: SCA_IObject::m_activeActuators
- SG_DList m_activeActuators;
- // SG_DList: Head of objects having activated controllers
- // element: SCA_IObject::m_activeControllers
- SG_DList m_triggeredControllerSet;
-
- // need to find better way for this
- // also known as FactoryManager...
- CTR_Map<STR_HashedString,CValue*> m_mapStringToGameObjects;
- CTR_Map<STR_HashedString,void*> m_mapStringToMeshes;
- CTR_Map<STR_HashedString,void*> m_mapStringToActions;
-
- CTR_Map<STR_HashedString,void*> m_map_gamemeshname_to_blendobj;
- CTR_Map<CHashedPtr,void*> m_map_blendobj_to_gameobj;
-public:
- SCA_LogicManager();
- virtual ~SCA_LogicManager();
-
- //void SetKeyboardManager(SCA_KeyboardManager* keyboardmgr) { m_keyboardmgr=keyboardmgr;}
- void RegisterEventManager(SCA_EventManager* eventmgr);
- void RegisterToSensor(SCA_IController* controller,
- class SCA_ISensor* sensor);
- void RegisterToActuator(SCA_IController* controller,
- class SCA_IActuator* actuator);
-
- void BeginFrame(double curtime, double fixedtime);
- void UpdateFrame(double curtime, bool frame);
- void EndFrame();
- void AddActiveActuator(SCA_IActuator* actua,bool event)
- {
- actua->SetActive(true);
- actua->Activate(m_activeActuators);
- actua->AddEvent(event);
- }
-
- void AddTriggeredController(SCA_IController* controller, SCA_ISensor* sensor);
- SCA_EventManager* FindEventManager(int eventmgrtype);
- vector<class SCA_EventManager*> GetEventManagers() { return m_eventmanagers; }
-
- void RemoveGameObject(const STR_String& gameobjname);
-
- /**
- * remove Logic Bricks from the running logicmanager
- */
- void RemoveSensor(SCA_ISensor* sensor);
- void RemoveController(SCA_IController* controller);
- void RemoveActuator(SCA_IActuator* actuator);
-
-
- // for the scripting... needs a FactoryManager later (if we would have time... ;)
- void RegisterMeshName(const STR_String& meshname,void* mesh);
- void UnregisterMeshName(const STR_String& meshname,void* mesh);
- CTR_Map<STR_HashedString,void*>& GetMeshMap() { return m_mapStringToMeshes; }
- CTR_Map<STR_HashedString,void*>& GetActionMap() { return m_mapStringToActions; }
-
- void RegisterActionName(const STR_String& actname,void* action);
-
- void* GetActionByName (const STR_String& actname);
- void* GetMeshByName(const STR_String& meshname);
-
- void RegisterGameObjectName(const STR_String& gameobjname,CValue* gameobj);
- class CValue* GetGameObjectByName(const STR_String& gameobjname);
-
- void RegisterGameMeshName(const STR_String& gamemeshname, void* blendobj);
- void* FindBlendObjByGameMeshName(const STR_String& gamemeshname);
-
- void RegisterGameObj(void* blendobj, CValue* gameobj);
- void UnregisterGameObj(void* blendobj, CValue* gameobj);
- CValue* FindGameObjByBlendObj(void* blendobj);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_LogicManager")
-#endif
-};
-
-#endif /* __SCA_LOGICMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_MouseManager.cpp b/source/gameengine/GameLogic/SCA_MouseManager.cpp
deleted file mode 100644
index 51c03d1e350..00000000000
--- a/source/gameengine/GameLogic/SCA_MouseManager.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * Manager for mouse events
- *
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_MouseManager.cpp
- * \ingroup gamelogic
- */
-
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning( disable:4786 )
-#endif
-
-#include "EXP_BoolValue.h"
-#include "SCA_MouseManager.h"
-#include "SCA_MouseSensor.h"
-#include "EXP_IntValue.h"
-#include "RAS_ICanvas.h"
-
-
-SCA_MouseManager::SCA_MouseManager(SCA_LogicManager* logicmgr,
- SCA_IInputDevice* mousedev,
- RAS_ICanvas* canvas)
- : SCA_EventManager(logicmgr, MOUSE_EVENTMGR),
- m_mousedevice (mousedev),
- m_canvas(canvas)
-{
- m_xpos = 0;
- m_ypos = 0;
-}
-
-
-
-SCA_MouseManager::~SCA_MouseManager()
-{
-}
-
-
-
-SCA_IInputDevice* SCA_MouseManager::GetInputDevice()
-{
- return m_mousedevice;
-}
-
-
-
-void SCA_MouseManager::NextFrame()
-{
- if (m_mousedevice)
- {
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- SCA_MouseSensor* mousesensor = (SCA_MouseSensor*)(*it);
- // (0,0) is the Upper Left corner in our local window
- // coordinates
- if (!mousesensor->IsSuspended())
- {
- const SCA_InputEvent& event1 =
- m_mousedevice->GetEventValue(SCA_IInputDevice::KX_MOUSEX);
- const SCA_InputEvent& event2 =
- m_mousedevice->GetEventValue(SCA_IInputDevice::KX_MOUSEY);
-
- int mx = this->m_canvas->GetMouseX(event1.m_eventval);
- int my = this->m_canvas->GetMouseY(event2.m_eventval);
-
- mousesensor->setX(mx);
- mousesensor->setY(my);
-
- mousesensor->Activate(m_logicmgr);
- }
- }
- }
-}
-
-bool SCA_MouseManager::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
- /* We should guard for non-mouse events maybe? A rather silly side */
- /* effect here is that position-change events are considered presses as */
- /* well. */
-
- return m_mousedevice->IsPressed(inputcode);
-}
diff --git a/source/gameengine/GameLogic/SCA_MouseManager.h b/source/gameengine/GameLogic/SCA_MouseManager.h
deleted file mode 100644
index a57e52070a7..00000000000
--- a/source/gameengine/GameLogic/SCA_MouseManager.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_MouseManager.h
- * \ingroup gamelogic
- * \brief Manager for mouse events.
- *
- */
-
-
-#ifndef __SCA_MOUSEMANAGER_H__
-#define __SCA_MOUSEMANAGER_H__
-
-
-#include "SCA_EventManager.h"
-
-#include <vector>
-
-using namespace std;
-
-#include "SCA_IInputDevice.h"
-
-
-class SCA_MouseManager : public SCA_EventManager
-{
-
- class SCA_IInputDevice* m_mousedevice;
- class RAS_ICanvas* m_canvas;
-
- unsigned short m_xpos; // Cached location of the mouse pointer
- unsigned short m_ypos;
-
-public:
- SCA_MouseManager(class SCA_LogicManager* logicmgr,class SCA_IInputDevice* mousedev, class RAS_ICanvas* canvas);
- virtual ~SCA_MouseManager();
-
- /**
- * Checks whether a mouse button is depressed. Ignores requests on non-
- * mouse related events. Can also flag mouse movement.
- */
- bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode);
- virtual void NextFrame();
- SCA_IInputDevice* GetInputDevice();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_MouseManager")
-#endif
-};
-
-#endif /* __SCA_MOUSEMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.cpp b/source/gameengine/GameLogic/SCA_MouseSensor.cpp
deleted file mode 100644
index 2479e859dea..00000000000
--- a/source/gameengine/GameLogic/SCA_MouseSensor.cpp
+++ /dev/null
@@ -1,317 +0,0 @@
-/*
- * Sensor for mouse input
- *
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): José I. Romero (cleanup and fixes)
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_MouseSensor.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_MouseSensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_MouseManager.h"
-#include "SCA_LogicManager.h"
-#include "SCA_IInputDevice.h"
-#include "EXP_ConstExpr.h"
-#include <iostream>
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_MouseSensor::SCA_MouseSensor(SCA_MouseManager* eventmgr,
- int startx,int starty,
- short int mousemode,
- SCA_IObject* gameobj)
- : SCA_ISensor(gameobj,eventmgr),
- m_x(startx),
- m_y(starty)
-{
- m_mousemode = mousemode;
- m_triggermode = true;
-
- UpdateHotkey(this);
- Init();
-}
-
-void SCA_MouseSensor::Init()
-{
- m_val = (m_invert)?1:0; /* stores the latest attribute */
- m_reset = true;
-}
-
-SCA_MouseSensor::~SCA_MouseSensor()
-{
- /* Nothing to be done here. */
-}
-
-void SCA_MouseSensor::UpdateHotkey(void *self)
-{
- // gosh, this function is so damn stupid
- // its here because of a design mistake in the mouse sensor, it should only
- // have 3 trigger modes (button, wheel, move), and let the user set the
- // hotkey separately, like the other sensors. but instead it has a mode for
- // each friggin key and i have to update the hotkey based on it... genius!
- SCA_MouseSensor* sensor = reinterpret_cast<SCA_MouseSensor*>(self);
-
- switch (sensor->m_mousemode) {
- case KX_MOUSESENSORMODE_LEFTBUTTON:
- sensor->m_hotkey = SCA_IInputDevice::KX_LEFTMOUSE;
- break;
- case KX_MOUSESENSORMODE_MIDDLEBUTTON:
- sensor->m_hotkey = SCA_IInputDevice::KX_MIDDLEMOUSE;
- break;
- case KX_MOUSESENSORMODE_RIGHTBUTTON:
- sensor->m_hotkey = SCA_IInputDevice::KX_RIGHTMOUSE;
- break;
- case KX_MOUSESENSORMODE_WHEELUP:
- sensor->m_hotkey = SCA_IInputDevice::KX_WHEELUPMOUSE;
- break;
- case KX_MOUSESENSORMODE_WHEELDOWN:
- sensor->m_hotkey = SCA_IInputDevice::KX_WHEELDOWNMOUSE;
- break;
- default:
- ; /* ignore, no hotkey */
- }
-}
-
-CValue* SCA_MouseSensor::GetReplica()
-{
- SCA_MouseSensor* replica = new SCA_MouseSensor(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
- replica->Init();
-
- return replica;
-}
-
-
-
-bool SCA_MouseSensor::IsPositiveTrigger()
-{
- bool result = (m_val != 0);
- if (m_invert)
- result = !result;
-
- return result;
-}
-
-
-
-short int SCA_MouseSensor::GetModeKey()
-{
- return m_mousemode;
-}
-
-
-
-SCA_IInputDevice::KX_EnumInputs SCA_MouseSensor::GetHotKey()
-{
- return m_hotkey;
-}
-
-
-
-bool SCA_MouseSensor::Evaluate()
-{
- bool result = false;
- bool reset = m_reset && m_level;
- SCA_IInputDevice* mousedev = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice();
-
- m_reset = false;
- switch (m_mousemode) {
- case KX_MOUSESENSORMODE_LEFTBUTTON:
- case KX_MOUSESENSORMODE_MIDDLEBUTTON:
- case KX_MOUSESENSORMODE_RIGHTBUTTON:
- case KX_MOUSESENSORMODE_WHEELUP:
- case KX_MOUSESENSORMODE_WHEELDOWN:
- {
- const SCA_InputEvent& mevent = mousedev->GetEventValue(m_hotkey);
- switch (mevent.m_status) {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- m_val = 1;
- result = true;
- break;
- case SCA_InputEvent::KX_JUSTRELEASED:
- m_val = 0;
- result = true;
- break;
- case SCA_InputEvent::KX_ACTIVE:
- if (m_val == 0)
- {
- m_val = 1;
- if (m_level)
- result = true;
- }
- break;
- default:
- if (m_val == 1)
- {
- m_val = 0;
- result = true;
- }
- break;
- }
- break;
- }
- case KX_MOUSESENSORMODE_MOVEMENT:
- {
- const SCA_InputEvent& eventX = mousedev->GetEventValue(SCA_IInputDevice::KX_MOUSEX);
- const SCA_InputEvent& eventY = mousedev->GetEventValue(SCA_IInputDevice::KX_MOUSEY);
-
- if (eventX.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- eventY.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- eventX.m_status == SCA_InputEvent::KX_ACTIVE ||
- eventY.m_status == SCA_InputEvent::KX_ACTIVE)
- {
- m_val = 1;
- result = true;
- }
- else if (eventX.m_status == SCA_InputEvent::KX_JUSTRELEASED ||
- eventY.m_status == SCA_InputEvent::KX_JUSTRELEASED )
- {
- m_val = 0;
- result = true;
- }
- else //KX_NO_IMPUTSTATUS
- {
- if (m_val == 1)
- {
- m_val = 0;
- result = true;
- }
- }
-
- break;
- }
- default:
- ; /* error */
- }
-
- if (reset)
- // force an event
- result = true;
- return result;
-}
-
-void SCA_MouseSensor::setX(short x)
-{
- m_x = x;
-}
-
-void SCA_MouseSensor::setY(short y)
-{
- m_y = y;
-}
-
-bool SCA_MouseSensor::isValid(SCA_MouseSensor::KX_MOUSESENSORMODE m)
-{
- return ((m > KX_MOUSESENSORMODE_NODEF) && (m < KX_MOUSESENSORMODE_MAX));
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-KX_PYMETHODDEF_DOC_O(SCA_MouseSensor, getButtonStatus,
-"getButtonStatus(button)\n"
-"\tGet the given button's status (KX_INPUT_NONE, KX_INPUT_NONE, KX_INPUT_JUST_ACTIVATED, KX_INPUT_ACTIVE, KX_INPUT_JUST_RELEASED).\n")
-{
- if (PyLong_Check(value))
- {
- SCA_IInputDevice::KX_EnumInputs button = (SCA_IInputDevice::KX_EnumInputs)PyLong_AsLong(value);
-
- if ((button < SCA_IInputDevice::KX_LEFTMOUSE) ||
- (button > SCA_IInputDevice::KX_RIGHTMOUSE))
- {
- PyErr_SetString(PyExc_ValueError, "sensor.getButtonStatus(int): Mouse Sensor, invalid button specified!");
- return NULL;
- }
-
- SCA_IInputDevice* mousedev = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice();
- const SCA_InputEvent& event = mousedev->GetEventValue(button);
- return PyLong_FromLong(event.m_status);
- }
-
- Py_RETURN_NONE;
-}
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject SCA_MouseSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_MouseSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_MouseSensor::Methods[] = {
- KX_PYMETHODTABLE_O(SCA_MouseSensor, getButtonStatus),
- {NULL,NULL} //Sentinel
-};
-
-int SCA_MouseSensor::UpdateHotkeyPy(void *self, const PyAttributeDef*)
-{
- UpdateHotkey(self);
- // return value is used in py_setattro(),
- // 0=attribute checked ok (see Attributes array definition)
- return 0;
-}
-
-PyAttributeDef SCA_MouseSensor::Attributes[] = {
- KX_PYATTRIBUTE_SHORT_RW_CHECK("mode",KX_MOUSESENSORMODE_NODEF,KX_MOUSESENSORMODE_MAX-1,true,SCA_MouseSensor,m_mousemode,UpdateHotkeyPy),
- KX_PYATTRIBUTE_SHORT_LIST_RO("position",SCA_MouseSensor,m_x,2),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_MouseSensor.h b/source/gameengine/GameLogic/SCA_MouseSensor.h
deleted file mode 100644
index 2660aaeacb5..00000000000
--- a/source/gameengine/GameLogic/SCA_MouseSensor.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): José I. Romero (cleanup and fixes)
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_MouseSensor.h
- * \ingroup gamelogic
- * \brief Senses mouse events
- */
-
-#ifndef __SCA_MOUSESENSOR_H__
-#define __SCA_MOUSESENSOR_H__
-
-#include "SCA_ISensor.h"
-#include "EXP_BoolValue.h"
-#include "SCA_IInputDevice.h"
-
-class SCA_MouseSensor : public SCA_ISensor
-{
- Py_Header
-
- /**
- * Use SCA_IInputDevice values to encode the mouse mode for now.
- */
- short int m_mousemode;
- /**
- * Triggermode true means all mouse events trigger. Useful mainly
- * for button presses.
- */
- bool m_triggermode;
- /**
- * Remember the last state update
- */
- int m_val;
-
- SCA_IInputDevice::KX_EnumInputs m_hotkey;
-
- /**
- * valid x coordinate, MUST be followed by y coordinate
- */
- short m_x;
-
- /**
- * valid y coordinate
- */
- short m_y;
-
- public:
- /**
- * Allowable modes for the trigger status of the mouse sensor.
- */
- enum KX_MOUSESENSORMODE {
- KX_MOUSESENSORMODE_NODEF = 0,
- KX_MOUSESENSORMODE_LEFTBUTTON,
- KX_MOUSESENSORMODE_MIDDLEBUTTON,
- KX_MOUSESENSORMODE_RIGHTBUTTON,
- KX_MOUSESENSORMODE_WHEELUP,
- KX_MOUSESENSORMODE_WHEELDOWN,
- KX_MOUSESENSORMODE_POSITION,
- KX_MOUSESENSORMODE_POSITIONX,
- KX_MOUSESENSORMODE_POSITIONY,
- KX_MOUSESENSORMODE_MOVEMENT,
- KX_MOUSESENSORMODE_MAX
- };
-
- bool isValid(KX_MOUSESENSORMODE);
-
- SCA_MouseSensor(class SCA_MouseManager* keybdmgr,
- int startx,int starty,
- short int mousemode,
- SCA_IObject* gameobj);
-
- virtual ~SCA_MouseSensor();
- virtual CValue* GetReplica();
- virtual bool Evaluate();
- virtual void Init();
- virtual bool IsPositiveTrigger();
- short int GetModeKey();
- SCA_IInputDevice::KX_EnumInputs GetHotKey();
- void setX(short x);
- void setY(short y);
-
- static void UpdateHotkey(void *self);
-
-
-#ifdef WITH_PYTHON
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- static int UpdateHotkeyPy(void *self, const PyAttributeDef *);
-
- // get button status
- KX_PYMETHOD_DOC_O(SCA_MouseSensor,getButtonStatus);
-#endif
-};
-
-#endif /* __SCA_MOUSESENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_NANDController.cpp b/source/gameengine/GameLogic/SCA_NANDController.cpp
deleted file mode 100644
index 6a00c110e2b..00000000000
--- a/source/gameengine/GameLogic/SCA_NANDController.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 'Nand' together all inputs
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_NANDController.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_NANDController.h"
-#include "SCA_ISensor.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_NANDController::SCA_NANDController(SCA_IObject* gameobj)
- :
- SCA_IController(gameobj)
-{
-}
-
-
-
-SCA_NANDController::~SCA_NANDController()
-{
-}
-
-
-
-void SCA_NANDController::Trigger(SCA_LogicManager* logicmgr)
-{
-
- bool sensorresult = false;
-
- for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- !(is==m_linkedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- if (!sensor->GetState())
- {
- sensorresult = true;
- break;
- }
- }
-
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,sensorresult);
- }
-}
-
-
-
-CValue* SCA_NANDController::GetReplica()
-{
- CValue* replica = new SCA_NANDController(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_NANDController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_NANDController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IController::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_NANDController::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_NANDController::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_NANDController.h b/source/gameengine/GameLogic/SCA_NANDController.h
deleted file mode 100644
index a3f02908dd2..00000000000
--- a/source/gameengine/GameLogic/SCA_NANDController.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_NANDController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_NANDCONTROLLER_H__
-#define __SCA_NANDCONTROLLER_H__
-
-#include "SCA_IController.h"
-
-class SCA_NANDController : public SCA_IController
-{
- Py_Header
- //virtual void Trigger(class SCA_LogicManager* logicmgr);
-public:
- SCA_NANDController(SCA_IObject* gameobj);
- virtual ~SCA_NANDController();
- virtual CValue* GetReplica();
- virtual void Trigger(SCA_LogicManager* logicmgr);
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-};
-
-#endif /* __SCA_NANDCONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_NORController.cpp b/source/gameengine/GameLogic/SCA_NORController.cpp
deleted file mode 100644
index fb09617e060..00000000000
--- a/source/gameengine/GameLogic/SCA_NORController.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * 'Nor' together all inputs
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_NORController.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_NORController.h"
-#include "SCA_ISensor.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_NORController::SCA_NORController(SCA_IObject* gameobj)
- :
- SCA_IController(gameobj)
-{
-}
-
-
-
-SCA_NORController::~SCA_NORController()
-{
-}
-
-
-
-void SCA_NORController::Trigger(SCA_LogicManager* logicmgr)
-{
-
- bool sensorresult = true;
-
- for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- !(is==m_linkedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- if (sensor->GetState())
- {
- sensorresult = false;
- break;
- }
- }
-
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,sensorresult);
- }
-}
-
-
-
-CValue* SCA_NORController::GetReplica()
-{
- CValue* replica = new SCA_NORController(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_NORController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_NORController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IController::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_NORController::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_NORController::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_NORController.h b/source/gameengine/GameLogic/SCA_NORController.h
deleted file mode 100644
index ec8159de8d1..00000000000
--- a/source/gameengine/GameLogic/SCA_NORController.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_NORController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_NORCONTROLLER_H__
-#define __SCA_NORCONTROLLER_H__
-
-#include "SCA_IController.h"
-
-class SCA_NORController : public SCA_IController
-{
- Py_Header
- //virtual void Trigger(class SCA_LogicManager* logicmgr);
-public:
- SCA_NORController(SCA_IObject* gameobj);
- virtual ~SCA_NORController();
- virtual CValue* GetReplica();
- virtual void Trigger(SCA_LogicManager* logicmgr);
-};
-
-#endif /* __SCA_NORCONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_ORController.cpp b/source/gameengine/GameLogic/SCA_ORController.cpp
deleted file mode 100644
index 8a59bdf1b89..00000000000
--- a/source/gameengine/GameLogic/SCA_ORController.cpp
+++ /dev/null
@@ -1,129 +0,0 @@
-/*
- * 'Or' together all inputs
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_ORController.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_ORController.h"
-#include "SCA_ISensor.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_ORController::SCA_ORController(SCA_IObject* gameobj)
- :SCA_IController(gameobj)
-{
-}
-
-
-
-SCA_ORController::~SCA_ORController()
-{
-}
-
-
-
-CValue* SCA_ORController::GetReplica()
-{
- CValue* replica = new SCA_ORController(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-
-void SCA_ORController::Trigger(SCA_LogicManager* logicmgr)
-{
-
- bool sensorresult = false;
- SCA_ISensor* sensor;
-
- vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- while ( (!sensorresult) && (!(is==m_linkedsensors.end())) )
- {
- sensor = *is;
- if (sensor->GetState()) sensorresult = true;
- is++;
- }
-
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,sensorresult);
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_ORController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_ORController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IController::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_ORController::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_ORController::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_ORController.h b/source/gameengine/GameLogic/SCA_ORController.h
deleted file mode 100644
index 9499c893c72..00000000000
--- a/source/gameengine/GameLogic/SCA_ORController.h
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_ORController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_ORCONTROLLER_H__
-#define __SCA_ORCONTROLLER_H__
-
-#include "SCA_IController.h"
-
-class SCA_ORController : public SCA_IController
-{
- Py_Header
- //virtual void Trigger(class SCA_LogicManager* logicmgr);
-public:
- SCA_ORController(SCA_IObject* gameobj);
-
- virtual ~SCA_ORController();
- virtual CValue* GetReplica();
- virtual void Trigger(SCA_LogicManager* logicmgr);
-};
-
-#endif /* __SCA_ORCONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp b/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
deleted file mode 100644
index f2907ca6361..00000000000
--- a/source/gameengine/GameLogic/SCA_PropertyActuator.cpp
+++ /dev/null
@@ -1,293 +0,0 @@
-/*
- * Assign, change, copy properties
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_PropertyActuator.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_PropertyActuator.h"
-#include "EXP_InputParser.h"
-#include "EXP_Operator2Expr.h"
-#include "EXP_ConstExpr.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_PropertyActuator::SCA_PropertyActuator(SCA_IObject* gameobj,SCA_IObject* sourceObj,const STR_String& propname,const STR_String& expr,int acttype)
- : SCA_IActuator(gameobj, KX_ACT_PROPERTY),
- m_type(acttype),
- m_propname(propname),
- m_exprtxt(expr),
- m_sourceObj(sourceObj)
-{
- // protect ourselves against someone else deleting the source object
- // don't protect against ourselves: it would create a dead lock
- if (m_sourceObj)
- m_sourceObj->RegisterActuator(this);
-}
-
-SCA_PropertyActuator::~SCA_PropertyActuator()
-{
- if (m_sourceObj)
- m_sourceObj->UnregisterActuator(this);
-}
-
-bool SCA_PropertyActuator::Update()
-{
- bool result = false;
-
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
- CValue* propowner = GetParent();
-
- if (bNegativeEvent)
- {
- if (m_type==KX_ACT_PROP_LEVEL)
- {
- CValue* newval = new CBoolValue(false);
- CValue* oldprop = propowner->GetProperty(m_propname);
- if (oldprop)
- {
- oldprop->SetValue(newval);
- }
- newval->Release();
- }
- return false;
- }
-
-
- CParser parser;
- parser.SetContext( propowner->AddRef());
-
- CExpression* userexpr= NULL;
-
- if (m_type==KX_ACT_PROP_TOGGLE)
- {
- /* don't use */
- CValue* newval;
- CValue* oldprop = propowner->GetProperty(m_propname);
- if (oldprop)
- {
- newval = new CBoolValue((oldprop->GetNumber()==0.0) ? true:false);
- oldprop->SetValue(newval);
- } else
- { /* as not been assigned, evaluate as false, so assign true */
- newval = new CBoolValue(true);
- propowner->SetProperty(m_propname,newval);
- }
- newval->Release();
- }
- else if (m_type==KX_ACT_PROP_LEVEL)
- {
- CValue* newval = new CBoolValue(true);
- CValue* oldprop = propowner->GetProperty(m_propname);
- if (oldprop)
- {
- oldprop->SetValue(newval);
- } else
- {
- propowner->SetProperty(m_propname,newval);
- }
- newval->Release();
- }
- else if ((userexpr = parser.ProcessText(m_exprtxt))) {
- switch (m_type)
- {
-
- case KX_ACT_PROP_ASSIGN:
- {
-
- CValue* newval = userexpr->Calculate();
- CValue* oldprop = propowner->GetProperty(m_propname);
- if (oldprop)
- {
- oldprop->SetValue(newval);
- } else
- {
- propowner->SetProperty(m_propname,newval);
- }
- newval->Release();
- break;
- }
- case KX_ACT_PROP_ADD:
- {
- CValue* oldprop = propowner->GetProperty(m_propname);
- if (oldprop)
- {
- // int waarde = (int)oldprop->GetNumber(); /*unused*/
- CExpression* expr = new COperator2Expr(VALUE_ADD_OPERATOR,new CConstExpr(oldprop->AddRef()),
- userexpr->AddRef());
-
- CValue* newprop = expr->Calculate();
- oldprop->SetValue(newprop);
- newprop->Release();
- expr->Release();
-
- }
-
- break;
- }
- case KX_ACT_PROP_COPY:
- {
- if (m_sourceObj)
- {
- CValue* copyprop = m_sourceObj->GetProperty(m_exprtxt);
- if (copyprop)
- {
- CValue *val = copyprop->GetReplica();
- GetParent()->SetProperty(
- m_propname,
- val);
- val->Release();
-
- }
- }
- break;
- }
- /* case KX_ACT_PROP_TOGGLE: */ /* accounted for above, no need for userexpr */
- default:
- {
-
- }
- }
-
- userexpr->Release();
- }
-
- return result;
-}
-
- bool
-
-SCA_PropertyActuator::
-
-isValid(
-
- SCA_PropertyActuator::KX_ACT_PROP_MODE mode
-
-) {
- bool res = false;
- res = ((mode > KX_ACT_PROP_NODEF) && (mode < KX_ACT_PROP_MAX));
- return res;
-}
-
-
- CValue*
-
-SCA_PropertyActuator::
-
-GetReplica()
-{
-
- SCA_PropertyActuator* replica = new SCA_PropertyActuator(*this);
-
- replica->ProcessReplica();
- return replica;
-
-};
-
-void SCA_PropertyActuator::ProcessReplica()
-{
- // no need to check for self reference like in the constructor:
- // the replica will always have a different parent
- if (m_sourceObj)
- m_sourceObj->RegisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-bool SCA_PropertyActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == m_sourceObj)
- {
- // this object is being deleted, we cannot continue to track it.
- m_sourceObj = NULL;
- return true;
- }
- return false;
-}
-
-void SCA_PropertyActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_sourceObj];
- if (h_obj) {
- if (m_sourceObj)
- m_sourceObj->UnregisterActuator(this);
- m_sourceObj = (SCA_IObject*)(*h_obj);
- m_sourceObj->RegisterActuator(this);
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_PropertyActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_PropertyActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_PropertyActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_PropertyActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,MAX_PROP_NAME,false,SCA_PropertyActuator,m_propname,CheckProperty),
- KX_PYATTRIBUTE_STRING_RW("value",0,100,false,SCA_PropertyActuator,m_exprtxt),
- KX_PYATTRIBUTE_INT_RW("mode", KX_ACT_PROP_NODEF+1, KX_ACT_PROP_MAX-1, false, SCA_PropertyActuator, m_type), /* ATTR_TODO add constents to game logic dict */
- { NULL } //Sentinel
-};
-
-#endif
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_PropertyActuator.h b/source/gameengine/GameLogic/SCA_PropertyActuator.h
deleted file mode 100644
index 228ecf94bc4..00000000000
--- a/source/gameengine/GameLogic/SCA_PropertyActuator.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_PropertyActuator.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_PROPERTYACTUATOR_H__
-#define __SCA_PROPERTYACTUATOR_H__
-
-#include "SCA_IActuator.h"
-
-class SCA_PropertyActuator : public SCA_IActuator
-{
- Py_Header
-
- enum KX_ACT_PROP_MODE {
- KX_ACT_PROP_NODEF = 0,
- KX_ACT_PROP_ASSIGN,
- KX_ACT_PROP_ADD,
- KX_ACT_PROP_COPY,
- KX_ACT_PROP_TOGGLE,
- KX_ACT_PROP_LEVEL,
- KX_ACT_PROP_MAX
- };
-
- /**check whether this value is valid */
- bool isValid(KX_ACT_PROP_MODE mode);
-
- int m_type;
- STR_String m_propname;
- STR_String m_exprtxt;
- SCA_IObject* m_sourceObj; // for copy property actuator
-
-public:
-
-
-
- SCA_PropertyActuator(
- SCA_IObject* gameobj,
- SCA_IObject* sourceObj,
- const STR_String& propname,
- const STR_String& expr,
- int acttype);
-
-
- ~SCA_PropertyActuator();
-
- CValue*
- GetReplica(
- );
-
- virtual void ProcessReplica();
- virtual bool UnlinkObject(SCA_IObject* clientobj);
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
-
- virtual bool
- Update();
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
-};
-
-#endif /* __KX_PROPERTYACTUATOR_DOC */
diff --git a/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp b/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp
deleted file mode 100644
index 854069690da..00000000000
--- a/source/gameengine/GameLogic/SCA_PropertyEventManager.cpp
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_PropertyEventManager.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_ISensor.h"
-#include "SCA_PropertyEventManager.h"
-
-
-SCA_PropertyEventManager::SCA_PropertyEventManager(class SCA_LogicManager* logicmgr)
- : SCA_EventManager(logicmgr, PROPERTY_EVENTMGR)
-{
-}
-
-
-
-SCA_PropertyEventManager::~SCA_PropertyEventManager()
-{
-
-}
-
-void SCA_PropertyEventManager::NextFrame()
-{
- // check for changed properties
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Activate(m_logicmgr);
- }
-}
diff --git a/source/gameengine/GameLogic/SCA_PropertyEventManager.h b/source/gameengine/GameLogic/SCA_PropertyEventManager.h
deleted file mode 100644
index 554fe686df2..00000000000
--- a/source/gameengine/GameLogic/SCA_PropertyEventManager.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_PropertyEventManager.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_PROPERTYEVENTMANAGER_H__
-#define __SCA_PROPERTYEVENTMANAGER_H__
-
-#include "SCA_EventManager.h"
-
-#include <vector>
-
-using namespace std;
-
-class SCA_PropertyEventManager : public SCA_EventManager
-{
-public:
- SCA_PropertyEventManager(class SCA_LogicManager* logicmgr);
- virtual ~SCA_PropertyEventManager();
- virtual void NextFrame();
- //SCA_LogicManager* GetLogicManager() { return m_logicmgr;}
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_PropertyEventManager")
-#endif
-};
-
-#endif /* __SCA_PROPERTYEVENTMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.cpp b/source/gameengine/GameLogic/SCA_PropertySensor.cpp
deleted file mode 100644
index e34a5296139..00000000000
--- a/source/gameengine/GameLogic/SCA_PropertySensor.cpp
+++ /dev/null
@@ -1,332 +0,0 @@
-/*
- * Property sensor
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_PropertySensor.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include <iostream>
-#include "SCA_PropertySensor.h"
-#include "EXP_Operator2Expr.h"
-#include "EXP_ConstExpr.h"
-#include "EXP_InputParser.h"
-#include "EXP_StringValue.h"
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-#include "EXP_FloatValue.h"
-#include <stdio.h>
-
-SCA_PropertySensor::SCA_PropertySensor(SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& propval,
- const STR_String& propmaxval,
- KX_PROPSENSOR_TYPE checktype)
- : SCA_ISensor(gameobj,eventmgr),
- m_checktype(checktype),
- m_checkpropval(propval),
- m_checkpropmaxval(propmaxval),
- m_checkpropname(propname)
-{
- //CParser pars;
- //pars.SetContext(this->AddRef());
- //CValue* resultval = m_rightexpr->Calculate();
-
- CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname);
- if (!orgprop->IsError())
- {
- m_previoustext = orgprop->GetText();
- }
- orgprop->Release();
-
- Init();
-}
-
-void SCA_PropertySensor::Init()
-{
- m_recentresult = false;
- m_lastresult = m_invert?true:false;
- m_reset = true;
-}
-
-CValue* SCA_PropertySensor::GetReplica()
-{
- SCA_PropertySensor* replica = new SCA_PropertySensor(*this);
- // m_range_expr must be recalculated on replica!
- replica->ProcessReplica();
- replica->Init();
-
- return replica;
-}
-
-
-
-bool SCA_PropertySensor::IsPositiveTrigger()
-{
- bool result = m_recentresult;//CheckPropertyCondition();
- if (m_invert)
- result = !result;
-
- return result;
-}
-
-
-
-SCA_PropertySensor::~SCA_PropertySensor()
-{
-}
-
-
-
-bool SCA_PropertySensor::Evaluate()
-{
- bool result = CheckPropertyCondition();
- bool reset = m_reset && m_level;
-
- m_reset = false;
- if (m_lastresult!=result)
- {
- m_lastresult = result;
- return true;
- }
- return (reset) ? true : false;
-}
-
-
-bool SCA_PropertySensor::CheckPropertyCondition()
-{
- m_recentresult=false;
- bool result=false;
- bool reverse = false;
- switch (m_checktype)
- {
- case KX_PROPSENSOR_NOTEQUAL:
- reverse = true;
- ATTR_FALLTHROUGH;
- case KX_PROPSENSOR_EQUAL:
- {
- CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname);
- if (!orgprop->IsError())
- {
- const STR_String& testprop = orgprop->GetText();
- // Force strings to upper case, to avoid confusion in
- // bool tests. It's stupid the prop's identity is lost
- // on the way here...
- if ((&testprop == &CBoolValue::sTrueString) || (&testprop == &CBoolValue::sFalseString)) {
- m_checkpropval.Upper();
- }
- result = (testprop == m_checkpropval);
-
- /* Patch: floating point values cant use strings usefully since you can have "0.0" == "0.0000"
- * this could be made into a generic Value class function for comparing values with a string.
- */
- if (result==false && (orgprop->GetValueType() == VALUE_FLOAT_TYPE)) {
- float f;
- if (sscanf(m_checkpropval.ReadPtr(), "%f", &f) == 1) {
- result = (f == ((CFloatValue *)orgprop)->GetFloat());
- }
- else {
- /* error */
- }
- }
- /* end patch */
- }
- orgprop->Release();
-
- if (reverse)
- result = !result;
- break;
-
- }
-
- case KX_PROPSENSOR_EXPRESSION:
- {
-#if 0
- if (m_rightexpr)
- {
- CValue* resultval = m_rightexpr->Calculate();
- if (resultval->IsError())
- {
- int i=0;
- STR_String errortest = resultval->GetText();
- printf(errortest);
-
- } else
- {
- result = resultval->GetNumber() != 0;
- }
- }
-#endif
- break;
- }
- case KX_PROPSENSOR_INTERVAL:
- {
- CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname);
- if (!orgprop->IsError())
- {
- const float min = m_checkpropval.ToFloat();
- const float max = m_checkpropmaxval.ToFloat();
- float val;
-
- if (orgprop->GetValueType() == VALUE_STRING_TYPE) {
- val = orgprop->GetText().ToFloat();
- }
- else {
- val = orgprop->GetNumber();
- }
-
- result = (min <= val) && (val <= max);
- }
- orgprop->Release();
-
- break;
- }
- case KX_PROPSENSOR_CHANGED:
- {
- CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname);
-
- if (!orgprop->IsError())
- {
- if (m_previoustext != orgprop->GetText())
- {
- m_previoustext = orgprop->GetText();
- result = true;
- }
- }
- orgprop->Release();
-
- //cout << " \nSens:Prop:changed!"; /* need implementation here!!! */
- break;
- }
- case KX_PROPSENSOR_LESSTHAN:
- reverse = true;
- ATTR_FALLTHROUGH;
- case KX_PROPSENSOR_GREATERTHAN:
- {
- CValue* orgprop = GetParent()->FindIdentifier(m_checkpropname);
- if (!orgprop->IsError())
- {
- const float ref = m_checkpropval.ToFloat();
- float val;
-
- if (orgprop->GetValueType() == VALUE_STRING_TYPE) {
- val = orgprop->GetText().ToFloat();
- }
- else {
- val = orgprop->GetNumber();
- }
-
- if (reverse) {
- result = val < ref;
- }
- else {
- result = val > ref;
- }
-
- }
- orgprop->Release();
-
- break;
- }
- default:
- ; /* error */
- }
-
- //the concept of Edge and Level triggering has unwanted effect for KX_PROPSENSOR_CHANGED
- //see Game Engine bugtracker [ #3809 ]
- m_recentresult = result;
-
- return result;
-}
-
-CValue* SCA_PropertySensor::FindIdentifier(const STR_String& identifiername)
-{
- return GetParent()->FindIdentifier(identifiername);
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-int SCA_PropertySensor::validValueForProperty(void *self, const PyAttributeDef*)
-{
- /* If someone actually do type checking please make sure the 'max' and 'min'
- * are checked as well (currently they are calling the PrecalculateRangeExpression
- * function directly */
-
- /* There is no type checking at this moment, unfortunately... */
- return 0;
-}
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_PropertySensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_PropertySensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_PropertySensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_PropertySensor::Attributes[] = {
- KX_PYATTRIBUTE_INT_RW("mode",KX_PROPSENSOR_NODEF,KX_PROPSENSOR_MAX-1,false,SCA_PropertySensor,m_checktype),
- KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,MAX_PROP_NAME,false,SCA_PropertySensor,m_checkpropname,CheckProperty),
- KX_PYATTRIBUTE_STRING_RW_CHECK("value",0,100,false,SCA_PropertySensor,m_checkpropval,validValueForProperty),
- KX_PYATTRIBUTE_STRING_RW_CHECK("min",0,100,false,SCA_PropertySensor,m_checkpropval,validValueForProperty),
- KX_PYATTRIBUTE_STRING_RW_CHECK("max",0,100,false,SCA_PropertySensor,m_checkpropmaxval,validValueForProperty),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_PropertySensor.h b/source/gameengine/GameLogic/SCA_PropertySensor.h
deleted file mode 100644
index f9cfb5fb1d2..00000000000
--- a/source/gameengine/GameLogic/SCA_PropertySensor.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_PropertySensor.h
- * \ingroup gamelogic
- * \brief Property sensor
- */
-
-#ifndef __SCA_PROPERTYSENSOR_H__
-#define __SCA_PROPERTYSENSOR_H__
-
-#include "SCA_ISensor.h"
-
-class SCA_PropertySensor : public SCA_ISensor
-{
- Py_Header
- //class CExpression* m_rightexpr;
- int m_checktype;
- STR_String m_checkpropval;
- STR_String m_checkpropmaxval;
- STR_String m_checkpropname;
- STR_String m_previoustext;
- bool m_lastresult;
- bool m_recentresult;
-
- protected:
-
-public:
- enum KX_PROPSENSOR_TYPE {
- KX_PROPSENSOR_NODEF = 0,
- KX_PROPSENSOR_EQUAL,
- KX_PROPSENSOR_NOTEQUAL,
- KX_PROPSENSOR_INTERVAL,
- KX_PROPSENSOR_CHANGED,
- KX_PROPSENSOR_EXPRESSION,
- KX_PROPSENSOR_LESSTHAN,
- KX_PROPSENSOR_GREATERTHAN,
- KX_PROPSENSOR_MAX
- };
-
- const STR_String S_KX_PROPSENSOR_EQ_STRING;
-
- SCA_PropertySensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const STR_String& propname,
- const STR_String& propval,
- const STR_String& propmaxval,
- KX_PROPSENSOR_TYPE checktype);
-
- virtual ~SCA_PropertySensor();
- virtual CValue* GetReplica();
- virtual void Init();
- bool CheckPropertyCondition();
-
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual CValue* FindIdentifier(const STR_String& identifiername);
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /**
- * Test whether this is a sensible value (type check)
- */
- static int validValueForProperty(void* self, const PyAttributeDef*);
-
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/GameLogic/SCA_PythonController.cpp b/source/gameengine/GameLogic/SCA_PythonController.cpp
deleted file mode 100644
index fd2e723741c..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonController.cpp
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- * Execute Python scripts
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_PythonController.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_PythonController.h"
-#include "SCA_LogicManager.h"
-#include "SCA_ISensor.h"
-#include "SCA_IActuator.h"
-#include "EXP_PyObjectPlus.h"
-
-#ifdef WITH_PYTHON
-#include "compile.h"
-#include "eval.h"
-#endif // WITH_PYTHON
-
-#include <algorithm>
-
-
-// initialize static member variables
-SCA_PythonController* SCA_PythonController::m_sCurrentController = NULL;
-
-
-SCA_PythonController::SCA_PythonController(SCA_IObject* gameobj, int mode)
- : SCA_IController(gameobj),
-#ifdef WITH_PYTHON
- m_bytecode(NULL),
- m_function(NULL),
-#endif
- m_function_argc(0),
- m_bModified(true),
- m_debug(false),
- m_mode(mode)
-#ifdef WITH_PYTHON
- , m_pythondictionary(NULL)
-#endif
-
-{
-
-}
-
-#if 0
-//debugging
-CValue *SCA_PythonController::AddRef()
-{
- //printf("AddRef refcount = %i\n",GetRefCount());
- return CValue::AddRef();
-}
-int SCA_PythonController::Release()
-{
- //printf("Release refcount = %i\n",GetRefCount());
- return CValue::Release();
-}
-#endif
-
-SCA_PythonController::~SCA_PythonController()
-{
-
-#ifdef WITH_PYTHON
- //printf("released python byte script\n");
-
- Py_XDECREF(m_bytecode);
- Py_XDECREF(m_function);
-
- if (m_pythondictionary) {
- // break any circular references in the dictionary
- PyDict_Clear(m_pythondictionary);
- Py_DECREF(m_pythondictionary);
- }
-#endif
-}
-
-
-
-CValue* SCA_PythonController::GetReplica()
-{
- SCA_PythonController* replica = new SCA_PythonController(*this);
-
-#ifdef WITH_PYTHON
- /* why is this needed at all??? - m_bytecode is NULL'd below so this doesnt make sense
- * but removing it crashes blender (with YoFrankie). so leave in for now - Campbell */
- Py_XINCREF(replica->m_bytecode);
-
- Py_XINCREF(replica->m_function); // this is ok since its not set to NULL
- replica->m_bModified = replica->m_bytecode == NULL;
-
- // The replica->m_pythondictionary is stolen - replace with a copy.
- if (m_pythondictionary)
- replica->m_pythondictionary = PyDict_Copy(m_pythondictionary);
-
-#if 0
- // The other option is to incref the replica->m_pythondictionary -
- // the replica objects can then share data.
- if (m_pythondictionary)
- Py_INCREF(replica->m_pythondictionary);
-#endif
-
-#endif /* WITH_PYTHON */
-
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-
-
-void SCA_PythonController::SetScriptText(const STR_String& text)
-{
- m_scriptText = text;
- m_bModified = true;
-}
-
-
-
-void SCA_PythonController::SetScriptName(const STR_String& name)
-{
- m_scriptName = name;
-}
-
-
-#ifdef WITH_PYTHON
-void SCA_PythonController::SetNamespace(PyObject* pythondictionary)
-{
- if (m_pythondictionary)
- {
- PyDict_Clear(m_pythondictionary);
- Py_DECREF(m_pythondictionary);
- }
- m_pythondictionary = PyDict_Copy(pythondictionary); /* new reference */
-
- /* Without __file__ set the sys.argv[0] is used for the filename
- * which ends up with lines from the blender binary being printed in the console */
- PyObject *value = PyUnicode_From_STR_String(m_scriptName);
- PyDict_SetItemString(m_pythondictionary, "__file__", value);
- Py_DECREF(value);
-
-}
-#endif
-
-bool SCA_PythonController::IsTriggered(class SCA_ISensor* sensor)
-{
- if (std::find(m_triggeredSensors.begin(), m_triggeredSensors.end(), sensor) !=
- m_triggeredSensors.end())
- {
- return true;
- }
- else {
- return false;
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* warning, self is not the SCA_PythonController, its a PyObjectPlus_Proxy */
-PyObject *SCA_PythonController::sPyGetCurrentController(PyObject *self)
-{
- if (m_sCurrentController==NULL)
- {
- PyErr_SetString(PyExc_SystemError, "bge.logic.getCurrentController(), this function is being run outside the python controllers context, or blenders internal state is corrupt.");
- return NULL;
- }
- return m_sCurrentController->GetProxy();
-}
-
-SCA_IActuator* SCA_PythonController::LinkedActuatorFromPy(PyObject *value)
-{
- // for safety, todo: only allow for registered actuators (pointertable)
- // we don't want to crash gameengine/blender by python scripts
- std::vector<SCA_IActuator*> lacts = m_sCurrentController->GetLinkedActuators();
- std::vector<SCA_IActuator*>::iterator it;
-
- if (PyUnicode_Check(value)) {
- /* get the actuator from the name */
- const char *name= _PyUnicode_AsString(value);
- for (it = lacts.begin(); it!= lacts.end(); ++it) {
- if ( name == (*it)->GetName() ) {
- return *it;
- }
- }
- }
- else if (PyObject_TypeCheck(value, &SCA_IActuator::Type)) {
- PyObjectPlus *value_plus= BGE_PROXY_REF(value);
- for (it = lacts.begin(); it!= lacts.end(); ++it) {
- if (static_cast<SCA_IActuator*>(value_plus) == (*it)) {
- return *it;
- }
- }
- }
-
- /* set the exception */
- PyErr_Format(PyExc_ValueError,
- "%R not in this python controllers actuator list", value);
-
- return NULL;
-}
-
-const char* SCA_PythonController::sPyGetCurrentController__doc__ = "getCurrentController()";
-
-PyTypeObject SCA_PythonController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_PythonController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IController::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_PythonController::Methods[] = {
- {"activate", (PyCFunction) SCA_PythonController::sPyActivate, METH_O},
- {"deactivate", (PyCFunction) SCA_PythonController::sPyDeActivate, METH_O},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_PythonController::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("script", SCA_PythonController, pyattr_get_script, pyattr_set_script),
- KX_PYATTRIBUTE_INT_RO("mode", SCA_PythonController, m_mode),
- { NULL } //Sentinel
-};
-
-void SCA_PythonController::ErrorPrint(const char *error_msg)
-{
- // If GetParent() is NULL, then most likely the object this controller
- // was attached to is gone (e.g., removed by LibFree()). Also, GetName()
- // can be a bad pointer if GetParent() is NULL, so better be safe and
- // flag it as unavailable as well
- const char *obj_name, *ctr_name;
- if (GetParent()) {
- obj_name = GetParent()->GetName().ReadPtr();
- ctr_name = GetName().ReadPtr();
- } else {
- obj_name = ctr_name = "Unavailable";
- }
- printf("%s - object '%s', controller '%s':\n", error_msg, obj_name, ctr_name);
- PyErr_Print();
-
- /* Added in 2.48a, the last_traceback can reference Objects for example, increasing
- * their user count. Not to mention holding references to wrapped data.
- * This is especially bad when the PyObject for the wrapped data is freed, after blender
- * has already dealocated the pointer */
- PySys_SetObject("last_traceback", NULL);
- PyErr_Clear(); /* just to be sure */
-}
-
-bool SCA_PythonController::Compile()
-{
- //printf("py script modified '%s'\n", m_scriptName.Ptr());
- m_bModified= false;
-
- // if a script already exists, decref it before replace the pointer to a new script
- if (m_bytecode) {
- Py_DECREF(m_bytecode);
- m_bytecode=NULL;
- }
-
- // recompile the scripttext into bytecode
- m_bytecode = Py_CompileString(m_scriptText.Ptr(), m_scriptName.Ptr(), Py_file_input);
-
- if (m_bytecode) {
- return true;
- } else {
- ErrorPrint("Python error compiling script");
- return false;
- }
-}
-
-bool SCA_PythonController::Import()
-{
- //printf("py module modified '%s'\n", m_scriptName.Ptr());
- m_bModified= false;
-
- /* in case we re-import */
- Py_XDECREF(m_function);
- m_function= NULL;
-
- STR_String mod_path_str= m_scriptText; /* just for storage, use C style string access */
- char *mod_path= mod_path_str.Ptr();
- char *function_string;
-
- function_string= strrchr(mod_path, '.');
-
- if (function_string == NULL) {
- printf("Python module name formatting error in object '%s', controller '%s':\n\texpected 'SomeModule.Func', got '%s'\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr());
- return false;
- }
-
- *function_string= '\0';
- function_string++;
-
- // Import the module and print an error if it's not found
- PyObject *mod = PyImport_ImportModule(mod_path);
-
- if (mod == NULL) {
- ErrorPrint("Python module can't be imported");
- return false;
- }
-
- if (m_debug)
- mod = PyImport_ReloadModule(mod);
-
- if (mod == NULL) {
- ErrorPrint("Python module can't be reloaded");
- return false;
- }
-
- // Get the function object
- m_function = PyObject_GetAttrString(mod, function_string);
-
- // DECREF the module as we don't need it anymore
- Py_DECREF(mod);
-
- if (m_function==NULL) {
- if (PyErr_Occurred())
- ErrorPrint("Python controller found the module but could not access the function");
- else
- printf("Python module error in object '%s', controller '%s':\n '%s' module found but function missing\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr());
- return false;
- }
-
- if (!PyCallable_Check(m_function)) {
- Py_DECREF(m_function);
- m_function = NULL;
- printf("Python module function error in object '%s', controller '%s':\n '%s' not callable\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr());
- return false;
- }
-
- m_function_argc = 0; /* rare cases this could be a function that isn't defined in python, assume zero args */
- if (PyFunction_Check(m_function)) {
- m_function_argc= ((PyCodeObject *)PyFunction_GET_CODE(m_function))->co_argcount;
- }
-
- if (m_function_argc > 1) {
- Py_DECREF(m_function);
- m_function = NULL;
- printf("Python module function in object '%s', controller '%s':\n '%s' takes %d args, should be zero or 1 controller arg\n", GetParent()->GetName().Ptr(), GetName().Ptr(), m_scriptText.Ptr(), m_function_argc);
- return false;
- }
-
- return true;
-}
-
-
-void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
-{
- m_sCurrentController = this;
-
- PyObject *excdict= NULL;
- PyObject *resultobj= NULL;
-
- switch (m_mode) {
- case SCA_PYEXEC_SCRIPT:
- {
- if (m_bModified)
- if (Compile()==false) // sets m_bModified to false
- return;
- if (!m_bytecode)
- return;
-
- /*
- * This part here with excdict is a temporary patch
- * to avoid python/gameengine crashes when python
- * inadvertently holds references to game objects
- * in global variables.
- *
- * The idea is always make a fresh dictionary, and
- * destroy it right after it is used to make sure
- * python won't hold any gameobject references.
- *
- * Note that the PyDict_Clear _is_ necessary before
- * the Py_DECREF() because it is possible for the
- * variables inside the dictionary to hold references
- * to the dictionary (ie. generate a cycle), so we
- * break it by hand, then DECREF (which in this case
- * should always ensure excdict is cleared).
- */
-
- excdict= PyDict_Copy(m_pythondictionary);
-
- resultobj = PyEval_EvalCode((PyObject *)m_bytecode, excdict, excdict);
-
- /* PyRun_SimpleString(m_scriptText.Ptr()); */
- break;
- }
- case SCA_PYEXEC_MODULE:
- {
- if (m_bModified || m_debug)
- if (Import()==false) // sets m_bModified to false
- return;
- if (!m_function)
- return;
-
- PyObject *args= NULL;
-
- if (m_function_argc==1) {
- args = PyTuple_New(1);
- PyTuple_SET_ITEM(args, 0, GetProxy());
- }
-
- resultobj = PyObject_CallObject(m_function, args);
- Py_XDECREF(args);
- break;
- }
-
- } /* end switch */
-
-
- /* Free the return value and print the error */
- if (resultobj)
- Py_DECREF(resultobj);
- else
- ErrorPrint("Python script error");
-
- if (excdict) /* Only for SCA_PYEXEC_SCRIPT types */
- {
- /* clear after PyErrPrint - seems it can be using
- * something in this dictionary and crash? */
- // This doesn't appear to be needed anymore
- //PyDict_Clear(excdict);
- Py_DECREF(excdict);
- }
-
- m_triggeredSensors.clear();
- m_sCurrentController = NULL;
-}
-
-PyObject *SCA_PythonController::PyActivate(PyObject *value)
-{
- if (m_sCurrentController != this) {
- PyErr_SetString(PyExc_SystemError, "Cannot activate an actuator from a non-active controller");
- return NULL;
- }
-
- SCA_IActuator* actu = LinkedActuatorFromPy(value);
- if (actu==NULL)
- return NULL;
-
- m_logicManager->AddActiveActuator((SCA_IActuator*)actu, true);
- Py_RETURN_NONE;
-}
-
-PyObject *SCA_PythonController::PyDeActivate(PyObject *value)
-{
- if (m_sCurrentController != this) {
- PyErr_SetString(PyExc_SystemError, "Cannot deactivate an actuator from a non-active controller");
- return NULL;
- }
-
- SCA_IActuator* actu = LinkedActuatorFromPy(value);
- if (actu==NULL)
- return NULL;
-
- m_logicManager->AddActiveActuator((SCA_IActuator*)actu, false);
- Py_RETURN_NONE;
-}
-
-PyObject *SCA_PythonController::pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- //SCA_PythonController* self = static_cast<SCA_PythonController*>(static_cast<SCA_IController*>(static_cast<SCA_ILogicBrick*>(static_cast<CValue*>(static_cast<PyObjectPlus*>(self_v)))));
- // static_cast<void *>(dynamic_cast<Derived *>(obj)) - static_cast<void *>(obj)
-
- SCA_PythonController* self = static_cast<SCA_PythonController*>(self_v);
- return PyUnicode_From_STR_String(self->m_scriptText);
-}
-
-
-
-int SCA_PythonController::pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- SCA_PythonController* self = static_cast<SCA_PythonController*>(self_v);
-
- const char *scriptArg = _PyUnicode_AsString(value);
-
- if (scriptArg==NULL) {
- PyErr_SetString(PyExc_TypeError, "controller.script = string: Python Controller, expected a string script text");
- return PY_SET_ATTR_FAIL;
- }
-
- /* set scripttext sets m_bModified to true,
- * so next time the script is needed, a reparse into byte code is done */
- self->SetScriptText(scriptArg);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#else // WITH_PYTHON
-
-void SCA_PythonController::Trigger(SCA_LogicManager* logicmgr)
-{
- /* intentionally blank */
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_PythonController.h b/source/gameengine/GameLogic/SCA_PythonController.h
deleted file mode 100644
index 11241da9117..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonController.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_PythonController.h
- * \ingroup gamelogic
- * \brief Execute Python scripts
- */
-
-#ifndef __SCA_PYTHONCONTROLLER_H__
-#define __SCA_PYTHONCONTROLLER_H__
-
-#include "SCA_IController.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-
-#include <vector>
-
-class SCA_IObject;
-class SCA_PythonController : public SCA_IController
-{
- Py_Header
-#ifdef WITH_PYTHON
- struct _object * m_bytecode; /* SCA_PYEXEC_SCRIPT only */
- PyObject* m_function; /* SCA_PYEXEC_MODULE only */
-#endif
- int m_function_argc;
- bool m_bModified;
- bool m_debug; /* use with SCA_PYEXEC_MODULE for reloading every logic run */
- int m_mode;
-
-
- protected:
- STR_String m_scriptText;
- STR_String m_scriptName;
-#ifdef WITH_PYTHON
- PyObject* m_pythondictionary; /* for SCA_PYEXEC_SCRIPT only */
- PyObject* m_pythonfunction; /* for SCA_PYEXEC_MODULE only */
-#endif
- std::vector<class SCA_ISensor*> m_triggeredSensors;
-
- public:
- enum SCA_PyExecMode
- {
- SCA_PYEXEC_SCRIPT = 0,
- SCA_PYEXEC_MODULE,
- SCA_PYEXEC_MAX
- };
-
- static SCA_PythonController* m_sCurrentController; // protected !!!
-
- //for debugging
- //virtual CValue* AddRef();
- //virtual int Release(); // Release a reference to this value (when reference count reaches 0, the value is removed from the heap)
-
- SCA_PythonController(SCA_IObject* gameobj, int mode);
- virtual ~SCA_PythonController();
-
- virtual CValue* GetReplica();
- virtual void Trigger(class SCA_LogicManager* logicmgr);
-
- void SetScriptText(const STR_String& text);
- void SetScriptName(const STR_String& name);
-#ifdef WITH_PYTHON
- void SetNamespace(PyObject* pythondictionary);
-#endif
- void SetDebug(bool debug) { m_debug = debug; }
- void AddTriggeredSensor(class SCA_ISensor* sensor)
- { m_triggeredSensors.push_back(sensor); }
- bool IsTriggered(class SCA_ISensor* sensor);
- bool Compile();
- bool Import();
- void ErrorPrint(const char *error_msg);
-
-#ifdef WITH_PYTHON
- static const char *sPyGetCurrentController__doc__;
- static PyObject *sPyGetCurrentController(PyObject *self);
- static const char *sPyAddActiveActuator__doc__;
- static PyObject *sPyAddActiveActuator(PyObject *self,
- PyObject *args);
- static SCA_IActuator* LinkedActuatorFromPy(PyObject *value);
-
-
- KX_PYMETHOD_O(SCA_PythonController,Activate);
- KX_PYMETHOD_O(SCA_PythonController,DeActivate);
- KX_PYMETHOD_O(SCA_PythonController,SetScript);
- KX_PYMETHOD_NOARGS(SCA_PythonController,GetScript);
-
-
- static PyObject* pyattr_get_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_script(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif
-};
-
-#endif /* __SCA_PYTHONCONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_PythonJoystick.cpp b/source/gameengine/GameLogic/SCA_PythonJoystick.cpp
deleted file mode 100644
index 9b24ad7bcf2..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonJoystick.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_PythonJoystick.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_PythonJoystick.h"
-#include "./Joystick/SCA_Joystick.h"
-#include "SCA_IInputDevice.h"
-
-//#include "GHOST_C-api.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_PythonJoystick::SCA_PythonJoystick(SCA_Joystick* joystick)
-: PyObjectPlus(),
-m_joystick(joystick)
-{
-#ifdef WITH_PYTHON
- m_event_dict = PyDict_New();
-#endif
-}
-
-SCA_PythonJoystick::~SCA_PythonJoystick()
-{
- // The joystick reference we got in the constructor was a new instance,
- // so we release it here
- m_joystick->ReleaseInstance();
-
-#ifdef WITH_PYTHON
- PyDict_Clear(m_event_dict);
- Py_DECREF(m_event_dict);
-#endif
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-PyObject* SCA_PythonJoystick::py_repr(void)
-{
- return PyUnicode_FromString(m_joystick->GetName());
-}
-
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_PythonJoystick::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_PythonJoystick",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_PythonJoystick::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_PythonJoystick::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("numButtons", SCA_PythonJoystick, pyattr_get_num_x),
- KX_PYATTRIBUTE_RO_FUNCTION("numHats", SCA_PythonJoystick, pyattr_get_num_x),
- KX_PYATTRIBUTE_RO_FUNCTION("numAxis", SCA_PythonJoystick, pyattr_get_num_x),
- KX_PYATTRIBUTE_RO_FUNCTION("activeButtons", SCA_PythonJoystick, pyattr_get_active_buttons),
- KX_PYATTRIBUTE_RO_FUNCTION("hatValues", SCA_PythonJoystick, pyattr_get_hat_values),
- KX_PYATTRIBUTE_RO_FUNCTION("axisValues", SCA_PythonJoystick, pyattr_get_axis_values),
- KX_PYATTRIBUTE_RO_FUNCTION("name", SCA_PythonJoystick, pyattr_get_name),
- { NULL } //Sentinel
-};
-
-// Use one function for numAxis, numButtons, and numHats
-PyObject* SCA_PythonJoystick::pyattr_get_num_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonJoystick* self = static_cast<SCA_PythonJoystick*>(self_v);
-
- if (strcmp(attrdef->m_name, "numButtons") == 0)
- return PyLong_FromLong(self->m_joystick->GetNumberOfButtons());
- else if (strcmp(attrdef->m_name, "numAxis") == 0)
- return PyLong_FromLong(self->m_joystick->GetNumberOfAxes());
- else if (strcmp(attrdef->m_name, "numHats") == 0)
- return PyLong_FromLong(self->m_joystick->GetNumberOfHats());
-
- // If we got here, we have a problem...
- PyErr_SetString(PyExc_AttributeError, "invalid attribute");
- return NULL;
-}
-
-PyObject* SCA_PythonJoystick::pyattr_get_active_buttons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonJoystick* self = static_cast<SCA_PythonJoystick*>(self_v);
-
- const int button_number = self->m_joystick->GetNumberOfButtons();
-
- PyObject *list = PyList_New(0);
- PyObject *value;
-
- for (int i=0; i < button_number; i++) {
- if (self->m_joystick->aButtonPressIsPositive(i)) {
- value = PyLong_FromLong(i);
- PyList_Append(list, value);
- Py_DECREF(value);
- }
- }
-
- return list;
-}
-
-PyObject* SCA_PythonJoystick::pyattr_get_hat_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonJoystick* self = static_cast<SCA_PythonJoystick*>(self_v);
-
- int hat_index = self->m_joystick->GetNumberOfHats();
- PyObject *list = PyList_New(hat_index);
-
- while (hat_index--) {
- PyList_SET_ITEM(list, hat_index, PyLong_FromLong(self->m_joystick->GetHat(hat_index)));
- }
-
- return list;
-}
-
-PyObject* SCA_PythonJoystick::pyattr_get_axis_values(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonJoystick* self = static_cast<SCA_PythonJoystick*>(self_v);
-
- int axis_index = self->m_joystick->GetNumberOfAxes();
- PyObject *list = PyList_New(axis_index);
- int position;
-
- while (axis_index--) {
- position = self->m_joystick->GetAxisPosition(axis_index);
-
- // We get back a range from -32768 to 32767, so we use an if here to
- // get a perfect -1.0 to 1.0 mapping. Some oddball system might have an
- // actual min of -32767 for shorts, so we use SHRT_MIN/MAX to be safe.
- if (position < 0)
- PyList_SET_ITEM(list, axis_index, PyFloat_FromDouble(position/((double)-SHRT_MIN)));
- else
- PyList_SET_ITEM(list, axis_index, PyFloat_FromDouble(position/(double)SHRT_MAX));
- }
-
- return list;
-}
-
-PyObject* SCA_PythonJoystick::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonJoystick* self = static_cast<SCA_PythonJoystick*>(self_v);
-
- return PyUnicode_FromString(self->m_joystick->GetName());
-}
-#endif
diff --git a/source/gameengine/GameLogic/SCA_PythonJoystick.h b/source/gameengine/GameLogic/SCA_PythonJoystick.h
deleted file mode 100644
index ecde00d28b9..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonJoystick.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_PythonJoystick.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_PYTHONJOYSTICK_H__
-#define __SCA_PYTHONJOYSTICK_H__
-
-#include "EXP_PyObjectPlus.h"
-
-class SCA_PythonJoystick : public PyObjectPlus
-{
- Py_Header
-private:
- class SCA_Joystick *m_joystick;
-#ifdef WITH_PYTHON
- PyObject* m_event_dict;
-#endif
-public:
- SCA_PythonJoystick(class SCA_Joystick* joystick);
- virtual ~SCA_PythonJoystick();
-
-#ifdef WITH_PYTHON
- virtual PyObject* py_repr(void);
-
- static PyObject* pyattr_get_num_x(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_active_buttons(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_hat_values(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_axis_values(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-};
-
-#endif //__SCA_PYTHONJOYSTICK_H__
-
diff --git a/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp b/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
deleted file mode 100644
index 9a96a7b0334..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonKeyboard.cpp
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_PythonKeyboard.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_PythonKeyboard.h"
-#include "SCA_IInputDevice.h"
-
-#include "GHOST_C-api.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_PythonKeyboard::SCA_PythonKeyboard(SCA_IInputDevice* keyboard)
-: PyObjectPlus(),
-m_keyboard(keyboard)
-{
-#ifdef WITH_PYTHON
- m_event_dict = PyDict_New();
-#endif
-}
-
-SCA_PythonKeyboard::~SCA_PythonKeyboard()
-{
-#ifdef WITH_PYTHON
- PyDict_Clear(m_event_dict);
- Py_DECREF(m_event_dict);
-#endif
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* clipboard */
-static PyObject *gPyGetClipboard(PyObject *args, PyObject *kwds)
-{
- char *buf = (char *)GHOST_getClipboard(0);
- return PyUnicode_FromString(buf?buf:"");
-}
-
-static PyObject *gPySetClipboard(PyObject *args, PyObject *value)
-{
- char* buf;
- if (!PyArg_ParseTuple(value,"s:setClipboard",&buf))
- Py_RETURN_NONE;
-
- GHOST_putClipboard((GHOST_TInt8 *)buf, 0);
- Py_RETURN_NONE;
-}
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_PythonKeyboard::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_PythonKeyboard",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_PythonKeyboard::Methods[] = {
- {"getClipboard", (PyCFunction) gPyGetClipboard, METH_VARARGS, "getCliboard doc"},
- {"setClipboard", (PyCFunction) gPySetClipboard, METH_VARARGS, "setCliboard doc"},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_PythonKeyboard::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonKeyboard, pyattr_get_events),
- KX_PYATTRIBUTE_RO_FUNCTION("active_events", SCA_PythonKeyboard, pyattr_get_active_events),
- { NULL } //Sentinel
-};
-
-PyObject *SCA_PythonKeyboard::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v);
-
- for (int i = SCA_IInputDevice::KX_BEGINKEY; i <= SCA_IInputDevice::KX_ENDKEY; i++) {
- const SCA_InputEvent & inevent = self->m_keyboard->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
- PyObject *key = PyLong_FromLong(i);
- PyObject *value = PyLong_FromLong(inevent.m_status);
-
- PyDict_SetItem(self->m_event_dict, key, value);
-
- Py_DECREF(key);
- Py_DECREF(value);
- }
- Py_INCREF(self->m_event_dict);
- return self->m_event_dict;
-}
-
-PyObject *SCA_PythonKeyboard::pyattr_get_active_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonKeyboard* self = static_cast<SCA_PythonKeyboard*>(self_v);
-
- PyDict_Clear(self->m_event_dict);
-
- for (int i = SCA_IInputDevice::KX_BEGINKEY; i <= SCA_IInputDevice::KX_ENDKEY; i++) {
- const SCA_InputEvent & inevent = self->m_keyboard->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
-
- if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS) {
- PyObject *key = PyLong_FromLong(i);
- PyObject *value = PyLong_FromLong(inevent.m_status);
-
- PyDict_SetItem(self->m_event_dict, key, value);
-
- Py_DECREF(key);
- Py_DECREF(value);
- }
- }
- Py_INCREF(self->m_event_dict);
- return self->m_event_dict;
-}
-
-#endif
diff --git a/source/gameengine/GameLogic/SCA_PythonKeyboard.h b/source/gameengine/GameLogic/SCA_PythonKeyboard.h
deleted file mode 100644
index 3cbe250378c..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonKeyboard.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_PythonKeyboard.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_PYTHONKEYBOARD_H__
-#define __SCA_PYTHONKEYBOARD_H__
-
-#include "EXP_PyObjectPlus.h"
-
-class SCA_PythonKeyboard : public PyObjectPlus
-{
- Py_Header
-private:
- class SCA_IInputDevice *m_keyboard;
-#ifdef WITH_PYTHON
- PyObject *m_event_dict;
-#endif
-public:
- SCA_PythonKeyboard(class SCA_IInputDevice* keyboard);
- virtual ~SCA_PythonKeyboard();
-
-#ifdef WITH_PYTHON
- static PyObject* pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_active_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-};
-
-#endif /* __SCA_PYTHONKEYBOARD_H__ */
diff --git a/source/gameengine/GameLogic/SCA_PythonMouse.cpp b/source/gameengine/GameLogic/SCA_PythonMouse.cpp
deleted file mode 100644
index 184b306a665..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonMouse.cpp
+++ /dev/null
@@ -1,206 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_PythonMouse.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_PythonMouse.h"
-#include "SCA_IInputDevice.h"
-#include "RAS_ICanvas.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_PythonMouse::SCA_PythonMouse(SCA_IInputDevice* mouse, RAS_ICanvas* canvas)
-: PyObjectPlus(),
-m_mouse(mouse),
-m_canvas(canvas)
-{
-#ifdef WITH_PYTHON
- m_event_dict = PyDict_New();
-#endif
-}
-
-SCA_PythonMouse::~SCA_PythonMouse()
-{
-#ifdef WITH_PYTHON
- PyDict_Clear(m_event_dict);
- Py_DECREF(m_event_dict);
-#endif
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_PythonMouse::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_PythonMouse",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_PythonMouse::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_PythonMouse::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("events", SCA_PythonMouse, pyattr_get_events),
- KX_PYATTRIBUTE_RO_FUNCTION("active_events", SCA_PythonMouse, pyattr_get_active_events),
- KX_PYATTRIBUTE_RW_FUNCTION("position", SCA_PythonMouse, pyattr_get_position, pyattr_set_position),
- KX_PYATTRIBUTE_RW_FUNCTION("visible", SCA_PythonMouse, pyattr_get_visible, pyattr_set_visible),
- { NULL } //Sentinel
-};
-
-PyObject *SCA_PythonMouse::pyattr_get_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
-
- for (int i = SCA_IInputDevice::KX_BEGINMOUSE; i <= SCA_IInputDevice::KX_ENDMOUSE; i++) {
- const SCA_InputEvent &inevent = self->m_mouse->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
- PyObject *key = PyLong_FromLong(i);
- PyObject *value = PyLong_FromLong(inevent.m_status);
-
- PyDict_SetItem(self->m_event_dict, key, value);
-
- Py_DECREF(key);
- Py_DECREF(value);
- }
- Py_INCREF(self->m_event_dict);
- return self->m_event_dict;
-}
-
-PyObject *SCA_PythonMouse::pyattr_get_active_events(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
-
- PyDict_Clear(self->m_event_dict);
-
- for (int i = SCA_IInputDevice::KX_BEGINMOUSE; i <= SCA_IInputDevice::KX_ENDMOUSE; i++) {
- const SCA_InputEvent &inevent = self->m_mouse->GetEventValue((SCA_IInputDevice::KX_EnumInputs)i);
-
- if (inevent.m_status != SCA_InputEvent::KX_NO_INPUTSTATUS) {
-
- PyObject *key = PyLong_FromLong(i);
- PyObject *value = PyLong_FromLong(inevent.m_status);
-
- PyDict_SetItem(self->m_event_dict, key, value);
-
- Py_DECREF(key);
- Py_DECREF(value);
- }
- }
- Py_INCREF(self->m_event_dict);
- return self->m_event_dict;
-}
-
-PyObject *SCA_PythonMouse::pyattr_get_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
- const SCA_InputEvent & xevent = self->m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEX);
- const SCA_InputEvent & yevent = self->m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEY);
-
- float x_coord, y_coord;
-
- x_coord = self->m_canvas->GetMouseNormalizedX(xevent.m_eventval);
- y_coord = self->m_canvas->GetMouseNormalizedY(yevent.m_eventval);
-
- PyObject *ret = PyTuple_New(2);
-
- PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(x_coord));
- PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(y_coord));
-
- return ret;
-}
-
-int SCA_PythonMouse::pyattr_set_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
- int x, y;
- float pyx, pyy;
- if (!PyArg_ParseTuple(value, "ff:position", &pyx, &pyy))
- return PY_SET_ATTR_FAIL;
-
- x = (int)(pyx*self->m_canvas->GetWidth());
- y = (int)(pyy*self->m_canvas->GetHeight());
-
- self->m_canvas->SetMousePosition(x, y);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *SCA_PythonMouse::pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
-
- int visible;
-
- if (self->m_canvas->GetMouseState() == RAS_ICanvas::MOUSE_INVISIBLE)
- visible = 0;
- else
- visible = 1;
-
- return PyBool_FromLong(visible);
-}
-
-int SCA_PythonMouse::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- SCA_PythonMouse* self = static_cast<SCA_PythonMouse*>(self_v);
-
- int visible = PyObject_IsTrue(value);
-
- if (visible == -1)
- {
- PyErr_SetString(PyExc_AttributeError, "SCA_PythonMouse.visible = bool: SCA_PythonMouse, expected True or False");
- return PY_SET_ATTR_FAIL;
- }
-
- if (visible)
- self->m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
- else
- self->m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif
diff --git a/source/gameengine/GameLogic/SCA_PythonMouse.h b/source/gameengine/GameLogic/SCA_PythonMouse.h
deleted file mode 100644
index 6dde90b3482..00000000000
--- a/source/gameengine/GameLogic/SCA_PythonMouse.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_PythonMouse.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_PYTHONMOUSE_H__
-#define __SCA_PYTHONMOUSE_H__
-
-#include "EXP_PyObjectPlus.h"
-
-class SCA_PythonMouse : public PyObjectPlus
-{
- Py_Header
-private:
- class SCA_IInputDevice *m_mouse;
- class RAS_ICanvas *m_canvas;
-#ifdef WITH_PYTHON
- PyObject *m_event_dict;
-#endif
-public:
- SCA_PythonMouse(class SCA_IInputDevice* mouse, class RAS_ICanvas* canvas);
- virtual ~SCA_PythonMouse();
-
- void Show(bool visible);
-
-#ifdef WITH_PYTHON
- KX_PYMETHOD_DOC(SCA_PythonMouse, show);
-
- static PyObject *pyattr_get_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_active_events(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_visible(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_visible(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif
-};
-
-#endif /* __SCA_PYTHONMOUSE_H__ */
diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.cpp b/source/gameengine/GameLogic/SCA_RandomActuator.cpp
deleted file mode 100644
index 8d75be9089d..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomActuator.cpp
+++ /dev/null
@@ -1,543 +0,0 @@
-/*
- * Set random/camera stuff
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_RandomActuator.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-#include <math.h>
-
-#include "EXP_BoolValue.h"
-#include "EXP_IntValue.h"
-#include "EXP_FloatValue.h"
-#include "SCA_IActuator.h"
-#include "SCA_RandomActuator.h"
-#include "MT_Transform.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_RandomActuator::SCA_RandomActuator(SCA_IObject *gameobj,
- long seed,
- SCA_RandomActuator::KX_RANDOMACT_MODE mode,
- float para1,
- float para2,
- const STR_String &propName)
- : SCA_IActuator(gameobj, KX_ACT_RANDOM),
- m_propname(propName),
- m_parameter1(para1),
- m_parameter2(para2),
- m_distribution(mode)
-{
- m_base = new SCA_RandomNumberGenerator(seed);
- m_counter = 0;
- enforceConstraints();
-}
-
-
-
-SCA_RandomActuator::~SCA_RandomActuator()
-{
- m_base->Release();
-}
-
-
-
-CValue* SCA_RandomActuator::GetReplica()
-{
- SCA_RandomActuator* replica = new SCA_RandomActuator(*this);
- // replication just copy the m_base pointer => common random generator
- replica->ProcessReplica();
- return replica;
-}
-
-void SCA_RandomActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
- // increment reference count so that we can release the generator at the end
- m_base->AddRef();
-}
-
-
-
-bool SCA_RandomActuator::Update()
-{
- //bool result = false; /*unused*/
- bool bNegativeEvent = IsNegativeEvent();
-
- RemoveAllEvents();
-
-
- CValue *tmpval = NULL;
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- switch (m_distribution) {
- case KX_RANDOMACT_BOOL_CONST: {
- /* un petit peu filthy */
- bool res = !(m_parameter1 < 0.5);
- tmpval = new CBoolValue(res);
- }
- break;
- case KX_RANDOMACT_BOOL_UNIFORM: {
- /* flip a coin */
- bool res;
- if (m_counter > 31) {
- m_previous = m_base->Draw();
- res = ((m_previous & 0x1) == 0);
- m_counter = 1;
- } else {
- res = (((m_previous >> m_counter) & 0x1) == 0);
- m_counter++;
- }
- tmpval = new CBoolValue(res);
- }
- break;
- case KX_RANDOMACT_BOOL_BERNOUILLI: {
- /* 'percentage' */
- bool res;
- res = (m_base->DrawFloat() < m_parameter1);
- tmpval = new CBoolValue(res);
- }
- break;
- case KX_RANDOMACT_INT_CONST: {
- /* constant */
- tmpval = new CIntValue((int) floor(m_parameter1));
- }
- break;
- case KX_RANDOMACT_INT_UNIFORM: {
- /* uniform (toss a die) */
- int res;
- /* The [0, 1] interval is projected onto the [min, max+1] domain, */
- /* and then rounded. */
- res = (int)floor( ((m_parameter2 - m_parameter1 + 1) * m_base->DrawFloat()) + m_parameter1);
- tmpval = new CIntValue(res);
- }
- break;
- case KX_RANDOMACT_INT_POISSON: {
- /* poisson (queues) */
- /* If x_1, x_2, ... is a sequence of random numbers with uniform */
- /* distribution between zero and one, k is the first integer for */
- /* which the product x_1*x_2*...*x_k < exp(-\lamba). */
- float a, b;
- int res = 0;
- /* The - sign is important here! The number to test for, a, must be */
- /* between 0 and 1. */
- a = exp(-m_parameter1);
- /* a quickly reaches 0.... so we guard explicitly for that. */
- if (a < FLT_MIN) a = FLT_MIN;
- b = m_base->DrawFloat();
- while (b >= a) {
- b = b * m_base->DrawFloat();
- res++;
- };
- tmpval = new CIntValue(res);
- }
- break;
- case KX_RANDOMACT_FLOAT_CONST: {
- /* constant */
- tmpval = new CFloatValue(m_parameter1);
- }
- break;
- case KX_RANDOMACT_FLOAT_UNIFORM: {
- float res = ((m_parameter2 - m_parameter1) * m_base->DrawFloat()) + m_parameter1;
- tmpval = new CFloatValue(res);
- }
- break;
- case KX_RANDOMACT_FLOAT_NORMAL: {
- /* normal (big numbers): para1 = mean, para2 = std dev */
-
- /* 070301 - nzc: Changed the termination condition. I think I
- * made a small mistake here, but it only affects distro's where
- * the seed equals 0. In that case, the algorithm locks. Let's
- * just guard that case separately.
- */
-
- float x = 0.0, y = 0.0, s = 0.0, t = 0.0;
- if (m_base->GetSeed() == 0) {
- /* 070301 - nzc: Just taking the mean here seems reasonable. */
- tmpval = new CFloatValue(m_parameter1);
- }
- else {
- /* 070301 - nzc
- * Now, with seed != 0, we will most assuredly get some
- * sensible values. The termination condition states two
- * things:
- * 1. s >= 0 is not allowed: to prevent the distro from
- * getting a bias towards high values. This is a small
- * correction, really, and might also be left out.
- * 2. s == 0 is not allowed: to prevent a division by zero
- * when renormalising the drawn value to the desired
- * distribution shape. As a side effect, the distro will
- * never yield the exact mean.
- * I am not sure whether this is consistent, since the error
- * cause by #2 is of the same magnitude as the one
- * prevented by #1. The error introduced into the SD will be
- * improved, though. By how much? Hard to say... If you like
- * the maths, feel free to analyse. Be aware that this is
- * one of the really old standard algorithms. I think the
- * original came in Fortran, was translated to Pascal, and
- * then someone came up with the C code. My guess it that
- * this will be quite sufficient here.
- */
- do {
- x = 2.0f * m_base->DrawFloat() - 1.0f;
- y = 2.0f * m_base->DrawFloat() - 1.0f;
- s = x * x + y * y;
- } while ((s >= 1.0f) || (s == 0.0f));
- t = x * sqrtf((-2.0 * log(s)) / s);
- tmpval = new CFloatValue(m_parameter1 + m_parameter2 * t);
- }
- }
- break;
- case KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL: {
- /* 1st order fall-off. I am very partial to using the half-life as */
- /* controlling parameter. Using the 'normal' exponent is not very */
- /* intuitive... */
- /* tmpval = new CFloatValue( (1.0 / m_parameter1) */
- tmpval = new CFloatValue((m_parameter1) * (-log(1.0 - m_base->DrawFloat())));
-
- }
- break;
- default:
- {
- /* unknown distribution... */
- static bool randomWarning = false;
- if (!randomWarning) {
- randomWarning = true;
- std::cout << "RandomActuator '" << GetName() << "' has an unknown distribution." << std::endl;
- }
- return false;
- }
- }
-
- /* Round up: assign it */
- CValue *prop = GetParent()->GetProperty(m_propname);
- if (prop) {
- prop->SetValue(tmpval);
- }
- tmpval->Release();
-
- return false;
-}
-
-void SCA_RandomActuator::enforceConstraints()
-{
- /* The constraints that are checked here are the ones fundamental to */
- /* the various distributions. Limitations of the algorithms are checked */
- /* elsewhere (or they should be... ). */
- switch (m_distribution) {
- case KX_RANDOMACT_BOOL_CONST:
- case KX_RANDOMACT_BOOL_UNIFORM:
- case KX_RANDOMACT_INT_CONST:
- case KX_RANDOMACT_INT_UNIFORM:
- case KX_RANDOMACT_FLOAT_UNIFORM:
- case KX_RANDOMACT_FLOAT_CONST:
- ; /* Nothing to be done here. We allow uniform distro's to have */
- /* 'funny' domains, i.e. max < min. This does not give problems. */
- break;
- case KX_RANDOMACT_BOOL_BERNOUILLI:
- /* clamp to [0, 1] */
- if (m_parameter1 < 0.0) {
- m_parameter1 = 0.0;
- } else if (m_parameter1 > 1.0) {
- m_parameter1 = 1.0;
- }
- break;
- case KX_RANDOMACT_INT_POISSON:
- /* non-negative */
- if (m_parameter1 < 0.0) {
- m_parameter1 = 0.0;
- }
- break;
- case KX_RANDOMACT_FLOAT_NORMAL:
- /* standard dev. is non-negative */
- if (m_parameter2 < 0.0) {
- m_parameter2 = 0.0;
- }
- break;
- case KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL:
- /* halflife must be non-negative */
- if (m_parameter1 < 0.0) {
- m_parameter1 = 0.0;
- }
- break;
- default:
- ; /* unknown distribution... */
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_RandomActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_RandomActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_RandomActuator::Methods[] = {
- KX_PYMETHODTABLE(SCA_RandomActuator, setBoolConst),
- KX_PYMETHODTABLE_NOARGS(SCA_RandomActuator, setBoolUniform),
- KX_PYMETHODTABLE(SCA_RandomActuator, setBoolBernouilli),
-
- KX_PYMETHODTABLE(SCA_RandomActuator, setIntConst),
- KX_PYMETHODTABLE(SCA_RandomActuator, setIntUniform),
- KX_PYMETHODTABLE(SCA_RandomActuator, setIntPoisson),
-
- KX_PYMETHODTABLE(SCA_RandomActuator, setFloatConst),
- KX_PYMETHODTABLE(SCA_RandomActuator, setFloatUniform),
- KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNormal),
- KX_PYMETHODTABLE(SCA_RandomActuator, setFloatNegativeExponential),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_RandomActuator::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RO("para1",SCA_RandomActuator,m_parameter1),
- KX_PYATTRIBUTE_FLOAT_RO("para2",SCA_RandomActuator,m_parameter2),
- KX_PYATTRIBUTE_ENUM_RO("distribution",SCA_RandomActuator,m_distribution),
- KX_PYATTRIBUTE_STRING_RW_CHECK("propName",0,MAX_PROP_NAME,false,SCA_RandomActuator,m_propname,CheckProperty),
- KX_PYATTRIBUTE_RW_FUNCTION("seed",SCA_RandomActuator,pyattr_get_seed,pyattr_set_seed),
- { NULL } //Sentinel
-};
-
-PyObject *SCA_RandomActuator::pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_RandomActuator* act = static_cast<SCA_RandomActuator*>(self);
- return PyLong_FromLong(act->m_base->GetSeed());
-}
-
-int SCA_RandomActuator::pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- SCA_RandomActuator* act = static_cast<SCA_RandomActuator*>(self);
- if (PyLong_Check(value)) {
- act->m_base->SetSeed(PyLong_AsLong(value));
- return PY_SET_ATTR_SUCCESS;
- }
- else {
- PyErr_SetString(PyExc_TypeError, "actuator.seed = int: Random Actuator, expected an integer");
- return PY_SET_ATTR_FAIL;
- }
-}
-
-/* 11. setBoolConst */
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolConst,
-"setBoolConst(value)\n"
-"\t- value: 0 or 1\n"
-"\tSet this generator to produce a constant boolean value.\n")
-{
- int paraArg;
- if (!PyArg_ParseTuple(args, "i:setBoolConst", &paraArg)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_BOOL_CONST;
- m_parameter1 = (paraArg) ? 1.0 : 0.0;
-
- Py_RETURN_NONE;
-}
-/* 12. setBoolUniform, */
-KX_PYMETHODDEF_DOC_NOARGS(SCA_RandomActuator, setBoolUniform,
-"setBoolUniform()\n"
-"\tSet this generator to produce true and false, each with 50%% chance of occurring\n")
-{
- /* no args */
- m_distribution = KX_RANDOMACT_BOOL_UNIFORM;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 13. setBoolBernouilli, */
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli,
-"setBoolBernouilli(value)\n"
-"\t- value: a float between 0 and 1\n"
-"\tReturn false value * 100%% of the time.\n")
-{
- float paraArg;
- if (!PyArg_ParseTuple(args, "f:setBoolBernouilli", &paraArg)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_BOOL_BERNOUILLI;
- m_parameter1 = paraArg;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 14. setIntConst,*/
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntConst,
-"setIntConst(value)\n"
-"\t- value: integer\n"
-"\tAlways return value\n")
-{
- int paraArg;
- if (!PyArg_ParseTuple(args, "i:setIntConst", &paraArg)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_INT_CONST;
- m_parameter1 = paraArg;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 15. setIntUniform,*/
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntUniform,
-"setIntUniform(lower_bound, upper_bound)\n"
-"\t- lower_bound: integer\n"
-"\t- upper_bound: integer\n"
-"\tReturn a random integer between lower_bound and\n"
-"\tupper_bound. The boundaries are included.\n")
-{
- int paraArg1, paraArg2;
- if (!PyArg_ParseTuple(args, "ii:setIntUniform", &paraArg1, &paraArg2)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_INT_UNIFORM;
- m_parameter1 = paraArg1;
- m_parameter2 = paraArg2;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 16. setIntPoisson, */
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setIntPoisson,
-"setIntPoisson(value)\n"
-"\t- value: float\n"
-"\tReturn a Poisson-distributed number. This performs a series\n"
-"\tof Bernouilli tests with parameter value. It returns the\n"
-"\tnumber of tries needed to achieve succes.\n")
-{
- float paraArg;
- if (!PyArg_ParseTuple(args, "f:setIntPoisson", &paraArg)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_INT_POISSON;
- m_parameter1 = paraArg;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 17. setFloatConst */
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatConst,
-"setFloatConst(value)\n"
-"\t- value: float\n"
-"\tAlways return value\n")
-{
- float paraArg;
- if (!PyArg_ParseTuple(args, "f:setFloatConst", &paraArg)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_FLOAT_CONST;
- m_parameter1 = paraArg;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 18. setFloatUniform, */
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatUniform,
-"setFloatUniform(lower_bound, upper_bound)\n"
-"\t- lower_bound: float\n"
-"\t- upper_bound: float\n"
-"\tReturn a random integer between lower_bound and\n"
-"\tupper_bound.\n")
-{
- float paraArg1, paraArg2;
- if (!PyArg_ParseTuple(args, "ff:setFloatUniform", &paraArg1, &paraArg2)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_FLOAT_UNIFORM;
- m_parameter1 = paraArg1;
- m_parameter2 = paraArg2;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 19. setFloatNormal, */
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNormal,
-"setFloatNormal(mean, standard_deviation)\n"
-"\t- mean: float\n"
-"\t- standard_deviation: float\n"
-"\tReturn normal-distributed numbers. The average is mean, and the\n"
-"\tdeviation from the mean is characterized by standard_deviation.\n")
-{
- float paraArg1, paraArg2;
- if (!PyArg_ParseTuple(args, "ff:setFloatNormal", &paraArg1, &paraArg2)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_FLOAT_NORMAL;
- m_parameter1 = paraArg1;
- m_parameter2 = paraArg2;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-/* 20. setFloatNegativeExponential, */
-KX_PYMETHODDEF_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential,
-"setFloatNegativeExponential(half_life)\n"
-"\t- half_life: float\n"
-"\tReturn negative-exponentially distributed numbers. The half-life 'time'\n"
-"\tis characterized by half_life.\n")
-{
- float paraArg;
- if (!PyArg_ParseTuple(args, "f:setFloatNegativeExponential", &paraArg)) {
- return NULL;
- }
-
- m_distribution = KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL;
- m_parameter1 = paraArg;
- enforceConstraints();
- Py_RETURN_NONE;
-}
-
-#endif
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_RandomActuator.h b/source/gameengine/GameLogic/SCA_RandomActuator.h
deleted file mode 100644
index 32b29fc4f43..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomActuator.h
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_RandomActuator.h
- * \ingroup gamelogic
- * \brief Draw a random number, and put it in a property
- */
-
-#ifndef __SCA_RANDOMACTUATOR_H__
-#define __SCA_RANDOMACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "SCA_RandomNumberGenerator.h"
-
-class SCA_RandomActuator : public SCA_IActuator
-{
- Py_Header
- /** Property to assign to */
- STR_String m_propname;
-
- /** First parameter. The meaning of the parameters depends on the
- * distribution */
- float m_parameter1;
- /** Second parameter. The meaning of the parameters depends on the
- * distribution */
- float m_parameter2;
-
- /** The base generator */
- SCA_RandomNumberGenerator *m_base;
-
- /** just a generic, persistent counter */
- int m_counter;
-
- /** cache for the previous draw */
- long m_previous;
-
- /** apply constraints for the chosen distribution to the parameters */
- void enforceConstraints(void);
-
- public:
-
- enum KX_RANDOMACT_MODE {
- KX_RANDOMACT_NODEF,
- KX_RANDOMACT_BOOL_CONST,
- KX_RANDOMACT_BOOL_UNIFORM,
- KX_RANDOMACT_BOOL_BERNOUILLI,
- KX_RANDOMACT_INT_CONST,
- KX_RANDOMACT_INT_UNIFORM,
- KX_RANDOMACT_INT_POISSON,
- KX_RANDOMACT_FLOAT_CONST,
- KX_RANDOMACT_FLOAT_UNIFORM,
- KX_RANDOMACT_FLOAT_NORMAL,
- KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL,
- KX_RANDOMACT_MAX
- };
- /** distribution type */
- KX_RANDOMACT_MODE m_distribution;
-
- SCA_RandomActuator(class SCA_IObject* gameobj,
- long seed,
- KX_RANDOMACT_MODE mode,
- float para1,
- float para2,
- const STR_String &propName);
- virtual ~SCA_RandomActuator();
- virtual bool Update();
-
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- static PyObject *pyattr_get_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_seed(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolConst);
- KX_PYMETHOD_DOC_NOARGS(SCA_RandomActuator, setBoolUniform);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setBoolBernouilli);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntConst);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntUniform);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setIntPoisson);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatConst);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatUniform);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNormal);
- KX_PYMETHOD_DOC_VARARGS(SCA_RandomActuator, setFloatNegativeExponential);
-
-#endif /* WITH_PYTHON */
-
-}; /* end of class KX_EditObjectActuator : public SCA_PropertyActuator */
-
-#endif
-
diff --git a/source/gameengine/GameLogic/SCA_RandomEventManager.cpp b/source/gameengine/GameLogic/SCA_RandomEventManager.cpp
deleted file mode 100644
index 2ec6eb1db1b..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomEventManager.cpp
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * Manager for random events
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_RandomEventManager.cpp
- * \ingroup gamelogic
- */
-
-#include "SCA_RandomEventManager.h"
-#include "SCA_LogicManager.h"
-#include "SCA_ISensor.h"
-#include <vector>
-using namespace std;
-
-#include <iostream>
-#include <stdio.h>
-
-SCA_RandomEventManager::SCA_RandomEventManager(class SCA_LogicManager* logicmgr)
- : SCA_EventManager(logicmgr, RANDOM_EVENTMGR)
-{
-}
-
-
-void SCA_RandomEventManager::NextFrame()
-{
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Activate(m_logicmgr);
- }
-}
-
diff --git a/source/gameengine/GameLogic/SCA_RandomEventManager.h b/source/gameengine/GameLogic/SCA_RandomEventManager.h
deleted file mode 100644
index 2d83c5fcdca..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomEventManager.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_RandomEventManager.h
- * \ingroup gamelogic
- * \brief Manager for random events
- */
-
-#ifndef __SCA_RANDOMEVENTMANAGER_H__
-#define __SCA_RANDOMEVENTMANAGER_H__
-
-#include "SCA_EventManager.h"
-#include <vector>
-
-using namespace std;
-
-class SCA_RandomEventManager : public SCA_EventManager
-{
-public:
- SCA_RandomEventManager(class SCA_LogicManager* logicmgr);
-
- virtual void NextFrame();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_RandomEventManager")
-#endif
-};
-
-#endif /* __SCA_RANDOMEVENTMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp b/source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp
deleted file mode 100644
index eca678f4e89..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/** \file gameengine/GameLogic/SCA_RandomNumberGenerator.cpp
- * \ingroup gamelogic
- */
-/**
- * Generate random numbers that can be used by other components. We
- * convert to different types/distributions elsewhere. This just
- * delivers a clean, random bitvector.
- *
- */
-
-/* A C-program for MT19937: Real number version */
-/* genrand() generates one pseudorandom real number (double) */
-/* which is uniformly distributed on [0,1]-interval, for each */
-/* call. sgenrand(seed) set initial values to the working area */
-/* of 624 words. Before genrand(), sgenrand(seed) must be */
-/* called once. (seed is any 32-bit integer except for 0). */
-/* Integer generator is obtained by modifying two lines. */
-/* Coded by Takuji Nishimura, considering the suggestions by */
-/* Topher Cooper and Marc Rieffel in July-Aug. 1997. */
-
-/* This library is free software; you can redistribute it and/or */
-/* modify it under the terms of the GNU Library General Public */
-/* License as published by the Free Software Foundation; either */
-/* version 2 of the License, or (at your option) any later */
-/* version. */
-/* This library 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 Library General Public License for more details. */
-/* You should have received a copy of the GNU Library General */
-/* Public License along with this library; if not, write to the */
-/* Free Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA */
-/* 02110-1301, USA */
-
-/* Copyright (C) 1997 Makoto Matsumoto and Takuji Nishimura. */
-/* When you use this, send an email to: matumoto@math.keio.ac.jp */
-/* with an appropriate reference to your work. */
-
-#include <limits.h>
-#include "SCA_RandomNumberGenerator.h"
-
-/* Period parameters */
-#define N 624
-#define M 397
-#define MATRIX_A 0x9908b0df /* constant vector a */
-#define UPPER_MASK 0x80000000 /* most significant w-r bits */
-#define LOWER_MASK 0x7fffffff /* least significant r bits */
-
-/* Tempering parameters */
-#define TEMPERING_MASK_B 0x9d2c5680
-#define TEMPERING_MASK_C 0xefc60000
-#define TEMPERING_SHIFT_U(y) (y >> 11)
-#define TEMPERING_SHIFT_S(y) (y << 7)
-#define TEMPERING_SHIFT_T(y) (y << 15)
-#define TEMPERING_SHIFT_L(y) (y >> 18)
-
-SCA_RandomNumberGenerator::SCA_RandomNumberGenerator(long seed)
-{
- // int mti = N + 1; /*unused*/
- m_seed = seed;
- m_refcount = 1;
- SetStartVector();
-}
-
-SCA_RandomNumberGenerator::~SCA_RandomNumberGenerator()
-{
- /* intentionally empty */
-}
-
-void SCA_RandomNumberGenerator::SetStartVector(void)
-{
- /* setting initial seeds to mt[N] using */
- /* the generator Line 25 of Table 1 in */
- /* [KNUTH 1981, The Art of Computer Programming */
- /* Vol. 2 (2nd Ed.), pp102] */
- mt[0] = m_seed & 0xffffffff;
- for (mti = 1; mti < N; mti++)
- mt[mti] = (69069 * mt[mti-1]) & 0xffffffff;
-}
-
-long SCA_RandomNumberGenerator::GetSeed() { return m_seed; }
-void SCA_RandomNumberGenerator::SetSeed(long newseed)
-{
- m_seed = newseed;
- SetStartVector();
-}
-
-/**
- * This is the important part: copied verbatim :)
- */
-unsigned long SCA_RandomNumberGenerator::Draw()
-{
- static unsigned long mag01[2] = { 0x0, MATRIX_A };
- /* mag01[x] = x * MATRIX_A for x=0,1 */
-
- unsigned long y;
-
- if (mti >= N) { /* generate N words at one time */
- int kk;
-
- /* I set this in the constructor, so it is always satisfied ! */
- // if (mti == N+1) /* if sgenrand() has not been called, */
- // GEN_srand(4357); /* a default initial seed is used */
-
- for (kk = 0; kk < N - M; kk++) {
- y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
- mt[kk] = mt[kk+M] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- for (; kk < N-1; kk++) {
- y = (mt[kk] & UPPER_MASK) | (mt[kk+1] & LOWER_MASK);
- mt[kk] = mt[kk+(M-N)] ^ (y >> 1) ^ mag01[y & 0x1];
- }
- y = (mt[N-1] & UPPER_MASK) | (mt[0] & LOWER_MASK);
- mt[N-1] = mt[M-1] ^ (y >> 1) ^ mag01[y & 0x1];
-
- mti = 0;
- }
-
- y = mt[mti++];
- y ^= TEMPERING_SHIFT_U(y);
- y ^= TEMPERING_SHIFT_S(y) & TEMPERING_MASK_B;
- y ^= TEMPERING_SHIFT_T(y) & TEMPERING_MASK_C;
- y ^= TEMPERING_SHIFT_L(y);
-
- return y;
-}
-
-float SCA_RandomNumberGenerator::DrawFloat()
-{
- return ( (float) Draw()/ (unsigned long) 0xffffffff );
-}
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.h b/source/gameengine/GameLogic/SCA_RandomNumberGenerator.h
deleted file mode 100644
index 10818cb4e8f..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomNumberGenerator.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_RandomNumberGenerator.h
- * \ingroup gamelogic
- * \brief Generate random numbers that can be used by other components. Each
- * generator needs its own generator, so that the seed can be set
- * on a per-generator basis.
- */
-
-#ifndef __SCA_RANDOMNUMBERGENERATOR_H__
-#define __SCA_RANDOMNUMBERGENERATOR_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class SCA_RandomNumberGenerator {
-
- /* reference counted for memleak */
- int m_refcount;
-
- /** base seed */
- long m_seed;
-
- /* A bit silly.. The N parameter is a define in the .cpp file */
- /** the array for the state vector */
- /* unsigned long mt[N]; */
- unsigned long mt[624];
-
- /** mti==N+1 means mt[KX_MT_VectorLength] is not initialized */
- int mti; /* initialized in the cpp file */
-
- /** Calculate a start vector */
- void SetStartVector(void);
- public:
- SCA_RandomNumberGenerator(long seed);
- ~SCA_RandomNumberGenerator();
- unsigned long Draw();
- float DrawFloat();
- long GetSeed();
- void SetSeed(long newseed);
- SCA_RandomNumberGenerator* AddRef()
- {
- ++m_refcount;
- return this;
- }
- void Release()
- {
- if (--m_refcount == 0)
- delete this;
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_RandomNumberGenerator")
-#endif
-};
-
-#endif /* __SCA_RANDOMNUMBERGENERATOR_H__ */
-
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.cpp b/source/gameengine/GameLogic/SCA_RandomSensor.cpp
deleted file mode 100644
index 8f2dc8d80f5..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomSensor.cpp
+++ /dev/null
@@ -1,187 +0,0 @@
-/*
- * Generate random pulses
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_RandomSensor.cpp
- * \ingroup gamelogic
- */
-
-
-#include <stddef.h>
-
-#include "SCA_RandomSensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_RandomEventManager.h"
-#include "SCA_LogicManager.h"
-#include "EXP_ConstExpr.h"
-#include <iostream>
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_RandomSensor::SCA_RandomSensor(SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- int startseed)
- : SCA_ISensor(gameobj,eventmgr)
-{
- m_basegenerator = new SCA_RandomNumberGenerator(startseed);
- Init();
-}
-
-
-
-SCA_RandomSensor::~SCA_RandomSensor()
-{
- m_basegenerator->Release();
-}
-
-void SCA_RandomSensor::Init()
-{
- m_iteration = 0;
- m_interval = 0;
- m_lastdraw = false;
- m_currentDraw = m_basegenerator->Draw();
-}
-
-
-CValue* SCA_RandomSensor::GetReplica()
-{
- CValue* replica = new SCA_RandomSensor(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-void SCA_RandomSensor::ProcessReplica()
-{
- SCA_ISensor::ProcessReplica();
- // increment reference count so that we can release the generator at this end
- m_basegenerator->AddRef();
-}
-
-
-bool SCA_RandomSensor::IsPositiveTrigger()
-{
- return (m_invert !=m_lastdraw);
-}
-
-
-bool SCA_RandomSensor::Evaluate()
-{
- /* Random generator is the generator from Line 25 of Table 1 in */
- /* [KNUTH 1981, The Art of Computer Programming Vol. 2 */
- /* (2nd Ed.), pp102] */
- /* It's a very simple max. length sequence generator. We can */
- /* draw 32 bool values before having to generate the next */
- /* sequence value. There are some theorems that will tell you */
- /* this is a reasonable way of generating bools. Check Knuth. */
- /* Furthermore, we only draw each <delay>-eth frame. */
-
- bool evaluateResult = false;
-
- if (++m_interval > m_skipped_ticks) {
- bool drawResult = false;
- m_interval = 0;
- if (m_iteration > 31) {
- m_currentDraw = m_basegenerator->Draw();
- drawResult = (m_currentDraw & 0x1) == 0;
- m_iteration = 1;
- } else {
- drawResult = ((m_currentDraw >> m_iteration) & 0x1) == 0;
- m_iteration++;
- }
- evaluateResult = drawResult != m_lastdraw;
- m_lastdraw = drawResult;
- }
-
- /* now pass this result to some controller */
- return evaluateResult;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_RandomSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_RandomSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_RandomSensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_RandomSensor::Attributes[] = {
- KX_PYATTRIBUTE_BOOL_RO("lastDraw",SCA_RandomSensor,m_lastdraw),
- KX_PYATTRIBUTE_RW_FUNCTION("seed", SCA_RandomSensor, pyattr_get_seed, pyattr_set_seed),
- {NULL} //Sentinel
-};
-
-PyObject *SCA_RandomSensor::pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- SCA_RandomSensor* self = static_cast<SCA_RandomSensor*>(self_v);
- return PyLong_FromLong(self->m_basegenerator->GetSeed());
-}
-
-int SCA_RandomSensor::pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- SCA_RandomSensor* self = static_cast<SCA_RandomSensor*>(self_v);
- if (!PyLong_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "sensor.seed = int: Random Sensor, expected an integer");
- return PY_SET_ATTR_FAIL;
- }
- self->m_basegenerator->SetSeed(PyLong_AsLong(value));
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_RandomSensor.h b/source/gameengine/GameLogic/SCA_RandomSensor.h
deleted file mode 100644
index 66107b7b74b..00000000000
--- a/source/gameengine/GameLogic/SCA_RandomSensor.h
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_RandomSensor.h
- * \ingroup gamelogic
- * \brief Generate random pulses
- */
-
-#ifndef __SCA_RANDOMSENSOR_H__
-#define __SCA_RANDOMSENSOR_H__
-
-#include "SCA_ISensor.h"
-#include "EXP_BoolValue.h"
-#include "SCA_RandomNumberGenerator.h"
-
-class SCA_RandomSensor : public SCA_ISensor
-{
- Py_Header
-
- unsigned int m_currentDraw;
- int m_iteration;
- int m_interval;
- SCA_RandomNumberGenerator *m_basegenerator;
- bool m_lastdraw;
-public:
- SCA_RandomSensor(class SCA_EventManager* rndmgr,
- SCA_IObject* gameobj,
- int startseed);
- virtual ~SCA_RandomSensor();
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual void Init();
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- static PyObject* pyattr_get_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_seed(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif
-};
-
-#endif /* __SCA_RANDOMSENSOR_H__ */
diff --git a/source/gameengine/GameLogic/SCA_TimeEventManager.cpp b/source/gameengine/GameLogic/SCA_TimeEventManager.cpp
deleted file mode 100644
index c56a1496823..00000000000
--- a/source/gameengine/GameLogic/SCA_TimeEventManager.cpp
+++ /dev/null
@@ -1,120 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_TimeEventManager.cpp
- * \ingroup gamelogic
- */
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning(disable:4786)
-#endif
-
-#include "SCA_TimeEventManager.h"
-
-#include "SCA_LogicManager.h"
-#include "EXP_FloatValue.h"
-
-SCA_TimeEventManager::SCA_TimeEventManager(SCA_LogicManager* logicmgr)
-: SCA_EventManager(NULL, TIME_EVENTMGR)
-{
-}
-
-
-
-SCA_TimeEventManager::~SCA_TimeEventManager()
-{
- for (vector<CValue*>::iterator it = m_timevalues.begin();
- !(it == m_timevalues.end()); ++it)
- {
- (*it)->Release();
- }
-}
-
-
-
-void SCA_TimeEventManager::RegisterSensor(SCA_ISensor* sensor)
-{
- // not yet
-}
-
-void SCA_TimeEventManager::RemoveSensor(SCA_ISensor* sensor)
-{
- // empty
-}
-
-
-
-void SCA_TimeEventManager::NextFrame(double curtime, double fixedtime)
-{
- if (m_timevalues.size() > 0 && fixedtime > 0.0)
- {
- CFloatValue* floatval = new CFloatValue(curtime);
-
- // update sensors, but ... need deltatime !
- for (vector<CValue*>::iterator it = m_timevalues.begin();
- !(it == m_timevalues.end()); ++it)
- {
- float newtime = (*it)->GetNumber() + fixedtime;
- floatval->SetFloat(newtime);
- (*it)->SetValue(floatval);
- }
-
- floatval->Release();
- }
-}
-
-
-
-void SCA_TimeEventManager::AddTimeProperty(CValue* timeval)
-{
- timeval->AddRef();
- m_timevalues.push_back(timeval);
-}
-
-
-
-void SCA_TimeEventManager::RemoveTimeProperty(CValue* timeval)
-{
- for (vector<CValue*>::iterator it = m_timevalues.begin();
- !(it == m_timevalues.end()); ++it)
- {
- if ((*it) == timeval)
- {
- this->m_timevalues.erase(it);
- timeval->Release();
- break;
- }
- }
-}
-
-vector<CValue*> SCA_TimeEventManager::GetTimeValues()
-{
- return m_timevalues;
-}
-
diff --git a/source/gameengine/GameLogic/SCA_TimeEventManager.h b/source/gameengine/GameLogic/SCA_TimeEventManager.h
deleted file mode 100644
index 38d7e3fc4d4..00000000000
--- a/source/gameengine/GameLogic/SCA_TimeEventManager.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_TimeEventManager.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_TIMEEVENTMANAGER_H__
-#define __SCA_TIMEEVENTMANAGER_H__
-
-#include "SCA_EventManager.h"
-#include "EXP_Value.h"
-#include <vector>
-
-using namespace std;
-
-class SCA_TimeEventManager : public SCA_EventManager
-{
- vector<CValue*> m_timevalues; // values that need their time updated regularly
-
-public:
- SCA_TimeEventManager(class SCA_LogicManager* logicmgr);
- virtual ~SCA_TimeEventManager();
-
- virtual void NextFrame(double curtime, double fixedtime);
- virtual void RegisterSensor(class SCA_ISensor* sensor);
- virtual void RemoveSensor(class SCA_ISensor* sensor);
- void AddTimeProperty(CValue* timeval);
- void RemoveTimeProperty(CValue* timeval);
-
- vector<CValue*> GetTimeValues();
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SCA_TimeEventManager")
-#endif
-};
-
-#endif /* __SCA_TIMEEVENTMANAGER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_XNORController.cpp b/source/gameengine/GameLogic/SCA_XNORController.cpp
deleted file mode 100644
index f97d11cabf3..00000000000
--- a/source/gameengine/GameLogic/SCA_XNORController.cpp
+++ /dev/null
@@ -1,137 +0,0 @@
-/*
- * 'Xnor' together all inputs
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_XNORController.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_XNORController.h"
-#include "SCA_ISensor.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_XNORController::SCA_XNORController(SCA_IObject* gameobj)
- :
- SCA_IController(gameobj)
-{
-}
-
-
-
-SCA_XNORController::~SCA_XNORController()
-{
-}
-
-
-
-void SCA_XNORController::Trigger(SCA_LogicManager* logicmgr)
-{
-
- bool sensorresult = true;
-
- for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- !(is==m_linkedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- if (sensor->GetState())
- {
- if (sensorresult == false)
- {
- sensorresult = true;
- break;
- }
- sensorresult = false;
- }
- }
-
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,sensorresult);
- }
-}
-
-
-
-CValue* SCA_XNORController::GetReplica()
-{
- CValue* replica = new SCA_XNORController(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_XNORController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_XNORController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IController::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_XNORController::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_XNORController::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_XNORController.h b/source/gameengine/GameLogic/SCA_XNORController.h
deleted file mode 100644
index c257b71273e..00000000000
--- a/source/gameengine/GameLogic/SCA_XNORController.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_XNORController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_XNORCONTROLLER_H__
-#define __SCA_XNORCONTROLLER_H__
-
-#include "SCA_IController.h"
-
-class SCA_XNORController : public SCA_IController
-{
- Py_Header
- //virtual void Trigger(class SCA_LogicManager* logicmgr);
-public:
- SCA_XNORController(SCA_IObject* gameobj);
- virtual ~SCA_XNORController();
- virtual CValue* GetReplica();
- virtual void Trigger(SCA_LogicManager* logicmgr);
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
-};
-
-#endif /* __SCA_XNORCONTROLLER_H__ */
diff --git a/source/gameengine/GameLogic/SCA_XORController.cpp b/source/gameengine/GameLogic/SCA_XORController.cpp
deleted file mode 100644
index bb1ea822bd8..00000000000
--- a/source/gameengine/GameLogic/SCA_XORController.cpp
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * 'Xor' together all inputs
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GameLogic/SCA_XORController.cpp
- * \ingroup gamelogic
- */
-
-
-#include "SCA_XORController.h"
-#include "SCA_ISensor.h"
-#include "SCA_LogicManager.h"
-#include "EXP_BoolValue.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-SCA_XORController::SCA_XORController(SCA_IObject* gameobj)
- :
- SCA_IController(gameobj)
-{
-}
-
-
-
-SCA_XORController::~SCA_XORController()
-{
-}
-
-
-
-void SCA_XORController::Trigger(SCA_LogicManager* logicmgr)
-{
-
- bool sensorresult = false;
-
- for (vector<SCA_ISensor*>::const_iterator is=m_linkedsensors.begin();
- !(is==m_linkedsensors.end());is++)
- {
- SCA_ISensor* sensor = *is;
- if (sensor->GetState())
- {
- if (sensorresult == true)
- {
- sensorresult = false;
- break;
- }
- sensorresult = true;
- }
- }
-
- for (vector<SCA_IActuator*>::const_iterator i=m_linkedactuators.begin();
- !(i==m_linkedactuators.end());i++)
- {
- SCA_IActuator* actua = *i;
- logicmgr->AddActiveActuator(actua,sensorresult);
- }
-}
-
-
-
-CValue* SCA_XORController::GetReplica()
-{
- CValue* replica = new SCA_XORController(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject SCA_XORController::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "SCA_XORController",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IController::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef SCA_XORController::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef SCA_XORController::Attributes[] = {
- { NULL } //Sentinel
-};
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/GameLogic/SCA_XORController.h b/source/gameengine/GameLogic/SCA_XORController.h
deleted file mode 100644
index c64a3380ede..00000000000
--- a/source/gameengine/GameLogic/SCA_XORController.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SCA_XORController.h
- * \ingroup gamelogic
- */
-
-#ifndef __SCA_XORCONTROLLER_H__
-#define __SCA_XORCONTROLLER_H__
-
-#include "SCA_IController.h"
-
-class SCA_XORController : public SCA_IController
-{
- Py_Header
- //virtual void Trigger(class SCA_LogicManager* logicmgr);
-public:
- SCA_XORController(SCA_IObject* gameobj);
- virtual ~SCA_XORController();
- virtual CValue* GetReplica();
- virtual void Trigger(SCA_LogicManager* logicmgr);
-};
-
-#endif /* __SCA_XORCONTROLLER_H__ */
diff --git a/source/gameengine/GamePlayer/CMakeLists.txt b/source/gameengine/GamePlayer/CMakeLists.txt
deleted file mode 100644
index e77609985dc..00000000000
--- a/source/gameengine/GamePlayer/CMakeLists.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-add_subdirectory(common)
-add_subdirectory(ghost)
diff --git a/source/gameengine/GamePlayer/common/CMakeLists.txt b/source/gameengine/GamePlayer/common/CMakeLists.txt
deleted file mode 100644
index e6c980de566..00000000000
--- a/source/gameengine/GamePlayer/common/CMakeLists.txt
+++ /dev/null
@@ -1,75 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../ghost
- ../../BlenderRoutines
- ../../Converter
- ../../Expressions
- ../../GameLogic
- ../../Ketsji
- ../../Network
- ../../Network/LoopBackNetwork
- ../../Physics/common
- ../../Rasterizer
- ../../Rasterizer/RAS_OpenGLRasterizer
- ../../SceneGraph
- ../../../blender
- ../../../blender/blenfont
- ../../../blender/blenkernel
- ../../../blender/blenlib
- ../../../blender/blenloader
- ../../../blender/gpu
- ../../../blender/imbuf
- ../../../blender/makesdna
- ../../../../intern/container
- ../../../../intern/ghost
- ../../../../intern/glew-mx
- ../../../../intern/guardedalloc
- ../../../../intern/string
-)
-
-set(INC_SYS
- ../../../../intern/moto/include
- ${GLEW_INCLUDE_PATH}
- ${PYTHON_INCLUDE_DIRS}
- ${PNG_INCLUDE_DIRS}
- ${ZLIB_INCLUDE_DIRS}
-)
-
-set(SRC
- GPC_Canvas.cpp
- GPC_KeyboardDevice.cpp
- GPC_MouseDevice.cpp
-
- GPC_Canvas.h
- GPC_KeyboardDevice.h
- GPC_MouseDevice.h
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-blender_add_lib_nolist(ge_player_common "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp b/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
deleted file mode 100644
index 2b355407d46..00000000000
--- a/source/gameengine/GamePlayer/common/GPC_Canvas.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GamePlayer/common/GPC_Canvas.cpp
- * \ingroup player
- */
-
-
-#include "RAS_IPolygonMaterial.h"
-#include "GPC_Canvas.h"
-
-#include "DNA_scene_types.h"
-#include "DNA_space_types.h"
-
-#include "BKE_image.h"
-#include "MEM_guardedalloc.h"
-
-
-GPC_Canvas::GPC_Canvas(
- int width,
- int height
-) :
- m_width(width),
- m_height(height)
-{
- // initialize area so that it's available for game logic on frame 1 (ImageViewport)
- m_displayarea.m_x1 = 0;
- m_displayarea.m_y1 = 0;
- m_displayarea.m_x2 = width;
- m_displayarea.m_y2 = height;
- m_frame = 1;
-
- glGetIntegerv(GL_VIEWPORT, (GLint*)m_viewport);
-}
-
-
-GPC_Canvas::~GPC_Canvas()
-{
-}
-
-
-void GPC_Canvas::Resize(int width, int height)
-{
- m_width = width;
- m_height = height;
-
- // initialize area so that it's available for game logic on frame 1 (ImageViewport)
- m_displayarea.m_x1 = 0;
- m_displayarea.m_y1 = 0;
- m_displayarea.m_x2 = width;
- m_displayarea.m_y2 = height;
-}
-
-
-void GPC_Canvas::ClearColor(float r, float g, float b, float a)
-{
- ::glClearColor(r,g,b,a);
-}
-
-void GPC_Canvas::SetViewPort(int x1, int y1, int x2, int y2)
-{
- /* x1 and y1 are the min pixel coordinate (e.g. 0)
- x2 and y2 are the max pixel coordinate
- the width,height is calculated including both pixels
- therefore: max - min + 1
- */
-
- /* XXX, nasty, this needs to go somewhere else,
- * but where... definitely need to clean up this
- * whole canvas/rendertools mess.
- */
- glEnable(GL_SCISSOR_TEST);
-
- m_viewport[0] = x1;
- m_viewport[1] = y1;
- m_viewport[2] = x2-x1 + 1;
- m_viewport[3] = y2-y1 + 1;
-
- glViewport(x1,y1,x2-x1 + 1,y2-y1 + 1);
- glScissor(x1,y1,x2-x1 + 1,y2-y1 + 1);
-}
-
-void GPC_Canvas::UpdateViewPort(int x1, int y1, int x2, int y2)
-{
- m_viewport[0] = x1;
- m_viewport[1] = y1;
- m_viewport[2] = x2;
- m_viewport[3] = y2;
-}
-
-const int *GPC_Canvas::GetViewPort()
-{
-#ifdef DEBUG
- // If we're in a debug build, we might as well make sure our values don't differ
- // from what the gpu thinks we have. This could lead to nasty, hard to find bugs.
- int viewport[4];
- glGetIntegerv(GL_VIEWPORT, viewport);
- assert(viewport[0] == m_viewport[0]);
- assert(viewport[1] == m_viewport[1]);
- assert(viewport[2] == m_viewport[2]);
- assert(viewport[3] == m_viewport[3]);
-#endif
-
- return m_viewport;
-}
-
-void GPC_Canvas::ClearBuffer(
- int type
-) {
-
- int ogltype = 0;
- if (type & RAS_ICanvas::COLOR_BUFFER )
- ogltype |= GL_COLOR_BUFFER_BIT;
- if (type & RAS_ICanvas::DEPTH_BUFFER )
- ogltype |= GL_DEPTH_BUFFER_BIT;
-
- ::glClear(ogltype);
-}
-
- void
-GPC_Canvas::
-MakeScreenShot(
- const char* filename
-) {
- // copy image data
- unsigned int dumpsx = GetWidth();
- unsigned int dumpsy = GetHeight();
- unsigned int *pixels = (unsigned int *)MEM_mallocN(sizeof(int) * dumpsx * dumpsy, "pixels");
-
- if (!pixels) {
- std::cout << "Cannot allocate pixels array" << std::endl;
- return;
- }
-
- glReadPixels(0, 0, dumpsx, dumpsy, GL_RGBA, GL_UNSIGNED_BYTE, pixels);
-
- // initialize image file format data
- ImageFormatData *im_format = (ImageFormatData *)MEM_mallocN(sizeof(ImageFormatData), "im_format");
- BKE_imformat_defaults(im_format);
-
- /* save_screenshot() frees dumprect and im_format */
- save_screenshot(filename, dumpsx, dumpsy, pixels, im_format);
-}
-
diff --git a/source/gameengine/GamePlayer/common/GPC_Canvas.h b/source/gameengine/GamePlayer/common/GPC_Canvas.h
deleted file mode 100644
index 688ed8ac0f4..00000000000
--- a/source/gameengine/GamePlayer/common/GPC_Canvas.h
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPC_Canvas.h
- * \ingroup player
- */
-
-#ifndef __GPC_CANVAS_H__
-#define __GPC_CANVAS_H__
-
-#include "RAS_ICanvas.h"
-#include "RAS_Rect.h"
-
-#ifdef WIN32
-# pragma warning (disable:4786) // suppress stl-MSVC debug info warning
-# include <windows.h>
-#endif /* WIN32 */
-
-#include "GPU_glew.h"
-
-#include <map>
-
-
-class GPC_Canvas : public RAS_ICanvas
-{
-protected:
-
- /** Width of the context. */
- int m_width;
- /** Height of the context. */
- int m_height;
- /** Rect that defines the area used for rendering,
- * relative to the context */
- RAS_Rect m_displayarea;
-
- int m_viewport[4];
-
-public:
-
- GPC_Canvas(int width, int height);
-
- virtual ~GPC_Canvas();
-
- void Resize(int width, int height);
-
- virtual void ResizeWindow(int width, int height) {}
-
- virtual void GetDisplayDimensions(int &width, int &height) {}
-
- /**
- * \section Methods inherited from abstract base class RAS_ICanvas.
- */
-
- int
- GetWidth(
- ) const {
- return m_width;
- }
-
- int
- GetHeight(
- ) const {
- return m_height;
- }
-
- const
- RAS_Rect &
- GetDisplayArea(
- ) const {
- return m_displayarea;
- };
-
- void
- SetDisplayArea(
- RAS_Rect *rect
- ) {
- m_displayarea= *rect;
- };
-
- RAS_Rect &
- GetWindowArea(
- ) {
- return m_displayarea;
- }
-
- void
- BeginFrame(
- ) {};
-
- /**
- * Draws overlay banners and progress bars.
- */
- void
- EndFrame(
- ) {};
-
- void SetViewPort(int x1, int y1, int x2, int y2);
- void UpdateViewPort(int x1, int y1, int x2, int y2);
- const int *GetViewPort();
-
- void ClearColor(float r, float g, float b, float a);
-
- /**
- * \section Methods inherited from abstract base class RAS_ICanvas.
- * Semantics are not yet honored.
- */
-
- void SetMouseState(RAS_MouseState mousestate)
- {
- // not yet
- }
-
- void SetMousePosition(int x, int y)
- {
- // not yet
- }
-
- virtual void MakeScreenShot(const char* filename);
-
- void ClearBuffer(int type);
-};
-
-#endif /* __GPC_CANVAS_H__ */
diff --git a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp
deleted file mode 100644
index 0821d1d3b23..00000000000
--- a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GamePlayer/common/GPC_KeyboardDevice.cpp
- * \ingroup player
- */
-
-
-#include "GPC_KeyboardDevice.h"
-
-#include <cstdlib>
-
-/**
- * NextFrame toggles currentTable with previousTable,
- * and copies relevant event information from previous to current table
- * (pressed keys need to be remembered).
- */
-void GPC_KeyboardDevice::NextFrame()
-{
- SCA_IInputDevice::NextFrame();
-
- // Now convert justpressed key events into regular (active) keyevents
- int previousTable = 1-m_currentTable;
- for (int keyevent= KX_BEGINKEY; keyevent<= KX_ENDKEY;keyevent++)
- {
- SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][keyevent];
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- oldevent.m_status == SCA_InputEvent::KX_ACTIVE )
- {
- m_eventStatusTables[m_currentTable][keyevent] = oldevent;
- m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_ACTIVE;
- //m_eventStatusTables[m_currentTable][keyevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- }
- }
-}
-
-
-
-/**
- * ConvertBPEvent translates Windows keyboard events into ketsji kbd events.
- * Extra event information is stored, like ramp-mode (just released/pressed)
- */
-bool GPC_KeyboardDevice::ConvertEvent(int incode, int val, unsigned int unicode)
-{
- bool result = false;
-
- // convert event
- KX_EnumInputs kxevent = this->ToNative(incode);
-
- // only process it, if it's a key
- if (kxevent >= KX_BEGINKEY && kxevent <= KX_ENDKEY)
- {
- int previousTable = 1-m_currentTable;
-
- if (val > 0)
- {
- if (kxevent == SCA_IInputDevice::KX_ESCKEY && val != 0 && !m_hookesc)
- result = true;
-
- // todo: convert val ??
- m_eventStatusTables[m_currentTable][kxevent].m_eventval = val ; //???
- m_eventStatusTables[m_currentTable][kxevent].m_unicode = unicode ;
-
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- case SCA_InputEvent::KX_ACTIVE:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
- break;
- }
-
- case SCA_InputEvent::KX_NO_INPUTSTATUS:
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- }
- }
-
- } else
- {
-
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- case SCA_InputEvent::KX_ACTIVE:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
- }
- }
- }
- }
- return result;
-}
-
-void GPC_KeyboardDevice::HookEscape()
-{
- m_hookesc = true;
-}
diff --git a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h b/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h
deleted file mode 100644
index d9842a42e0a..00000000000
--- a/source/gameengine/GamePlayer/common/GPC_KeyboardDevice.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPC_KeyboardDevice.h
- * \ingroup player
- */
-
-#ifndef __GPC_KEYBOARDDEVICE_H__
-#define __GPC_KEYBOARDDEVICE_H__
-
-#ifdef WIN32
-#pragma warning (disable:4786)
-#endif /* WIN32 */
-
-#include "SCA_IInputDevice.h"
-
-#include <map>
-
-
-/**
- * System independent implementation of SCA_IInputDevice.
- * System dependent keyboard devices need only to inherit this class
- * and fill the m_reverseKeyTranslateTable key translation map.
- * \see SCA_IInputDevice
- */
-
-class GPC_KeyboardDevice : public SCA_IInputDevice
-{
-protected:
-
- /**
- * This map converts system dependent keyboard codes into Ketsji codes.
- * System dependent keyboard codes are stored as ints.
- */
- std::map<int, KX_EnumInputs> m_reverseKeyTranslateTable;
- short m_exitkey;
-
-public:
- bool m_hookesc;
- GPC_KeyboardDevice()
- : m_hookesc(false)
- {
- }
-
- virtual ~GPC_KeyboardDevice(void)
- {
- }
-
- virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
- {
- return false;
- }
-
- virtual void NextFrame();
-
- virtual KX_EnumInputs ToNative(int incode)
- {
- return m_reverseKeyTranslateTable[incode];
- }
-
- virtual bool ConvertEvent(int incode, int val, unsigned int unicode);
-
- virtual void HookEscape();
-};
-
-#endif /* __GPC_KEYBOARDDEVICE_H__ */
diff --git a/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp b/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp
deleted file mode 100644
index 94045d532af..00000000000
--- a/source/gameengine/GamePlayer/common/GPC_MouseDevice.cpp
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GamePlayer/common/GPC_MouseDevice.cpp
- * \ingroup player
- */
-
-
-#include "GPC_MouseDevice.h"
-
-GPC_MouseDevice::GPC_MouseDevice()
-{
-
-}
-GPC_MouseDevice::~GPC_MouseDevice()
-{
-
-}
-
-/**
- * IsPressed gives boolean information about mouse status, true if pressed, false if not.
- */
-bool GPC_MouseDevice::IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode)
-{
- const SCA_InputEvent & inevent = m_eventStatusTables[m_currentTable][inputcode];
- bool pressed = (inevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- inevent.m_status == SCA_InputEvent::KX_ACTIVE);
- return pressed;
-}
-
-
-/**
- * NextFrame toggles currentTable with previousTable,
- * and copies relevant event information from previous to current table
- * (pressed keys need to be remembered).
- */
-void GPC_MouseDevice::NextFrame()
-{
- SCA_IInputDevice::NextFrame();
-
- // Convert just pressed events into regular (active) events
- int previousTable = 1-m_currentTable;
- for (int mouseevent= KX_BEGINMOUSE; mouseevent< KX_ENDMOUSEBUTTONS; mouseevent++) {
- SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mouseevent];
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- oldevent.m_status == SCA_InputEvent::KX_ACTIVE)
- {
- m_eventStatusTables[m_currentTable][mouseevent] = oldevent;
- m_eventStatusTables[m_currentTable][mouseevent].m_status = SCA_InputEvent::KX_ACTIVE;
- }
- }
- for (int mousemove= KX_ENDMOUSEBUTTONS; mousemove< KX_ENDMOUSE; mousemove++) {
- SCA_InputEvent& oldevent = m_eventStatusTables[previousTable][mousemove];
- m_eventStatusTables[m_currentTable][mousemove] = oldevent;
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTACTIVATED ||
- oldevent.m_status == SCA_InputEvent::KX_ACTIVE)
- {
- m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_JUSTRELEASED;
- }
- else {
- if (oldevent.m_status == SCA_InputEvent::KX_JUSTRELEASED) {
- m_eventStatusTables[m_currentTable][mousemove].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
- }
- }
- }
-}
-
-
-bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown)
-{
- bool result = false;
-
- switch (button)
- {
- case buttonLeft:
- result = ConvertEvent(KX_LEFTMOUSE, isDown, 0);
- break;
- case buttonMiddle:
- result = ConvertEvent(KX_MIDDLEMOUSE, isDown, 0);
- break;
- case buttonRight:
- result = ConvertEvent(KX_RIGHTMOUSE, isDown, 0);
- break;
- case buttonWheelUp:
- result = ConvertEvent(KX_WHEELUPMOUSE, isDown, 0);
- break;
- case buttonWheelDown:
- result = ConvertEvent(KX_WHEELDOWNMOUSE, isDown, 0);
- break;
- default:
- // Should not happen!
- break;
- }
-
- return result;
-}
-
-/**
- * Splits combined button and x,y cursor move events into separate Ketsji
- * x and y move and button events.
- */
-bool GPC_MouseDevice::ConvertButtonEvent(TButtonId button, bool isDown, int x, int y)
-{
- // First update state tables for cursor move.
- bool result = ConvertMoveEvent(x, y);
-
- // Now update for button state.
- if (result) {
- result = ConvertButtonEvent(button, isDown);
- }
-
- return result;
-}
-
-/**
- * Splits combined x,y move into separate Ketsji x and y move events.
- */
-bool GPC_MouseDevice::ConvertMoveEvent(int x, int y)
-{
- bool result;
-
- // Convert to local coordinates?
- result = ConvertEvent(KX_MOUSEX, x, 0);
- if (result) {
- result = ConvertEvent(KX_MOUSEY, y, 0);
- }
-
- return result;
-}
-
-
-bool GPC_MouseDevice::ConvertEvent(KX_EnumInputs kxevent, int eventval, unsigned int unicode)
-{
- bool result = true;
-
- // Only process it, if it's a mouse event
- if (kxevent > KX_BEGINMOUSE && kxevent < KX_ENDMOUSE) {
- int previousTable = 1-m_currentTable;
-
- if (eventval > 0) {
- m_eventStatusTables[m_currentTable][kxevent].m_eventval = eventval;
-
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
- case SCA_InputEvent::KX_ACTIVE:
- case SCA_InputEvent::KX_JUSTACTIVATED:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
- break;
- }
- case SCA_InputEvent::KX_JUSTRELEASED:
- {
- if ( kxevent > KX_BEGINMOUSEBUTTONS && kxevent < KX_ENDMOUSEBUTTONS)
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- } else
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_ACTIVE;
-
- }
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTACTIVATED;
- }
- }
-
- }
- else {
- switch (m_eventStatusTables[previousTable][kxevent].m_status)
- {
- case SCA_InputEvent::KX_JUSTACTIVATED:
- case SCA_InputEvent::KX_ACTIVE:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_JUSTRELEASED;
- break;
- }
- default:
- {
- m_eventStatusTables[m_currentTable][kxevent].m_status = SCA_InputEvent::KX_NO_INPUTSTATUS;
- }
- }
- }
- }
- else {
- result = false;
- }
- return result;
-}
diff --git a/source/gameengine/GamePlayer/common/GPC_MouseDevice.h b/source/gameengine/GamePlayer/common/GPC_MouseDevice.h
deleted file mode 100644
index 24922197723..00000000000
--- a/source/gameengine/GamePlayer/common/GPC_MouseDevice.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPC_MouseDevice.h
- * \ingroup player
- */
-
-#ifndef __GPC_MOUSEDEVICE_H__
-#define __GPC_MOUSEDEVICE_H__
-
-#ifdef WIN32
-#pragma warning (disable:4786)
-#endif /* WIN32 */
-
-#include "SCA_IInputDevice.h"
-
-
-/**
- * Generic Ketsji mouse device.
- * \see SCA_IInputDevice
- */
-class GPC_MouseDevice : public SCA_IInputDevice
-{
-public:
- /**
- * Button identifier.
- */
- typedef enum {
- buttonLeft,
- buttonMiddle,
- buttonRight,
- buttonWheelUp,
- buttonWheelDown
- } TButtonId;
-
- GPC_MouseDevice();
- virtual ~GPC_MouseDevice(void);
-
- virtual bool IsPressed(SCA_IInputDevice::KX_EnumInputs inputcode);
- virtual void NextFrame();
-
- /**
- * Call this routine to update the mouse device when a button state changes.
- * \param button Which button state changes.
- * \param isDown The new state of the button.
- * \return Indication as to whether the event was processed.
- */
- virtual bool ConvertButtonEvent(TButtonId button, bool isDown);
-
- /**
- * Call this routine to update the mouse device when a button state and
- * cursor position changes at the same time (e.g. in Win32 messages).
- * \param button Which button state changes.
- * \param isDown The new state of the button.
- * \param x Position x-coordinate of the cursor at the time of the state change.
- * \param y Position y-coordinate of the cursor at the time of the state change.
- * \return Indication as to whether the event was processed.
- */
- virtual bool ConvertButtonEvent(TButtonId button, bool isDown, int x, int y);
-
- /**
- * Call this routine to update the mouse device when the cursor has moved.
- * \param x Position x-coordinate of the cursor.
- * \param y Position y-coordinate of the cursor.
- * \return Indication as to whether the event was processed.
- */
- virtual bool ConvertMoveEvent(int x, int y);
-
-protected:
- /**
- * This routine converts a single mouse event to a Ketsji mouse event.
- * \param kxevent Ketsji event code.
- * \param eventval Value for this event.
- * \return Indication as to whether the event was processed.
- */
- virtual bool ConvertEvent(KX_EnumInputs kxevent, int eventval, unsigned int unicode);
-};
-
-#endif /* __GPC_MOUSEDEVICE_H__ */
diff --git a/source/gameengine/GamePlayer/ghost/CMakeLists.txt b/source/gameengine/GamePlayer/ghost/CMakeLists.txt
deleted file mode 100644
index 577e25d6198..00000000000
--- a/source/gameengine/GamePlayer/ghost/CMakeLists.txt
+++ /dev/null
@@ -1,111 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../common
- ../../BlenderRoutines
- ../../Converter
- ../../Expressions
- ../../GameLogic
- ../../Ketsji
- ../../Network
- ../../Network/LoopBackNetwork
- ../../Physics/common
- ../../Rasterizer
- ../../Rasterizer/RAS_OpenGLRasterizer
- ../../SceneGraph
- ../../../blender
- ../../../blender/blenfont
- ../../../blender/blenkernel
- ../../../blender/blenlib
- ../../../blender/blenloader
- ../../../blender/blentranslation
- ../../../blender/gpu
- ../../../blender/imbuf
- ../../../blender/makesdna
- ../../../blender/makesrna
- ../../../../intern/container
- ../../../../intern/ghost
- ../../../../intern/glew-mx
- ../../../../intern/guardedalloc
- ../../../../intern/string
- ../../../../intern/memutil
-)
-
-set(INC_SYS
- ../../../../intern/moto/include
- ${GLEW_INCLUDE_PATH}
- ${PYTHON_INCLUDE_DIRS}
- ${BOOST_INCLUDE_DIR}
-)
-
-set(SRC
- GPG_Application.cpp
- GPG_Canvas.cpp
- GPG_KeyboardDevice.cpp
- GPG_System.cpp
- GPG_ghost.cpp
-
- GPG_Application.h
- GPG_Canvas.h
- GPG_KeyboardDevice.h
- GPG_System.h
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-if(WIN32)
- blender_include_dirs(../../../../intern/utfconv)
-endif()
-
-if(WITH_INPUT_NDOF)
- add_definitions(-DWITH_INPUT_NDOF)
-endif(WITH_INPUT_NDOF)
-
-if(WITH_CODEC_FFMPEG)
- add_definitions(-DWITH_FFMPEG)
-endif()
-
-if(WITH_INTERNATIONAL)
- add_definitions(-DWITH_INTERNATIONAL)
-endif()
-
-if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
-
- list(APPEND INC_SYS
- ${AUDASPACE_C_INCLUDE_DIRS}
- )
-endif()
-
-if(WITH_SDL AND WITH_SDL_DYNLOAD)
- list(APPEND INC
- ../../../../extern/sdlew/include
- )
- add_definitions(-DWITH_SDL_DYNLOAD)
-endif()
-
-blender_add_lib_nolist(ge_player_ghost "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp b/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
deleted file mode 100644
index 50c34bbadaf..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.cpp
+++ /dev/null
@@ -1,998 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * GHOST Blender Player application implementation file.
- */
-
-/** \file gameengine/GamePlayer/ghost/GPG_Application.cpp
- * \ingroup player
- */
-
-
-#ifdef WIN32
-# pragma warning (disable:4786) // suppress stl-MSVC debug info warning
-# include <windows.h>
-#endif
-
-#include "GPU_glew.h"
-#include "GPU_extensions.h"
-#include "GPU_init_exit.h"
-
-#include "GPG_Application.h"
-#include "BL_BlenderDataConversion.h"
-
-#include <iostream>
-#include <MT_assert.h>
-#include <stdlib.h>
-
-/**********************************
- * Begin Blender include block
- **********************************/
-#ifdef __cplusplus
-extern "C"
-{
-#endif // __cplusplus
-#include "BLI_blenlib.h"
-#include "BLO_readfile.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_sound.h"
-#include "IMB_imbuf.h"
-#include "DNA_scene_types.h"
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-/**********************************
- * End Blender include block
- **********************************/
-
-
-#include "BL_System.h"
-#include "KX_KetsjiEngine.h"
-
-// include files needed by "KX_BlenderSceneConverter.h"
-#include "CTR_Map.h"
-#include "SCA_IActuator.h"
-#include "RAS_MeshObject.h"
-#include "RAS_OpenGLRasterizer.h"
-#include "RAS_ListRasterizer.h"
-#include "KX_PythonInit.h"
-#include "KX_PyConstraintBinding.h"
-#include "BL_Material.h" // MAXTEX
-
-#include "KX_BlenderSceneConverter.h"
-#include "NG_LoopBackNetworkDeviceInterface.h"
-
-#include "GPC_MouseDevice.h"
-#include "GPG_Canvas.h"
-#include "GPG_KeyboardDevice.h"
-#include "GPG_System.h"
-
-#include "STR_String.h"
-
-#include "GHOST_ISystem.h"
-#include "GHOST_IEvent.h"
-#include "GHOST_IEventConsumer.h"
-#include "GHOST_IWindow.h"
-#include "GHOST_Rect.h"
-
-#ifdef WITH_AUDASPACE
-# include AUD_DEVICE_H
-#endif
-
-static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time);
-
-static GHOST_ISystem* fSystem = 0;
-static const int kTimerFreq = 10;
-
-GPG_Application::GPG_Application(GHOST_ISystem* system)
- : m_startSceneName(""),
- m_startScene(0),
- m_maggie(0),
- m_kxStartScene(NULL),
- m_exitRequested(0),
- m_system(system),
- m_mainWindow(0),
- m_frameTimer(0),
- m_cursor(GHOST_kStandardCursorFirstCursor),
- m_engineInitialized(0),
- m_engineRunning(0),
- m_isEmbedded(false),
- m_ketsjiengine(0),
- m_kxsystem(0),
- m_keyboard(0),
- m_mouse(0),
- m_canvas(0),
- m_rasterizer(0),
- m_sceneconverter(0),
- m_networkdevice(0),
- m_blendermat(0),
- m_blenderglslmat(0),
- m_pyGlobalDictString(0),
- m_pyGlobalDictString_Length(0)
-{
- fSystem = system;
-}
-
-
-
-GPG_Application::~GPG_Application(void)
-{
- if (m_pyGlobalDictString) {
- delete [] m_pyGlobalDictString;
- m_pyGlobalDictString = 0;
- m_pyGlobalDictString_Length = 0;
- }
-
- exitEngine();
- fSystem->disposeWindow(m_mainWindow);
-}
-
-
-
-bool GPG_Application::SetGameEngineData(struct Main* maggie, Scene *scene, GlobalSettings *gs, int argc, char **argv)
-{
- bool result = false;
-
- if (maggie != NULL && scene != NULL)
- {
-// XXX G.scene = scene;
- m_maggie = maggie;
- m_startSceneName = scene->id.name+2;
- m_startScene = scene;
- result = true;
- }
-
- /* Python needs these */
- m_argc= argc;
- m_argv= argv;
-
- /* Global Settings */
- m_globalSettings= gs;
-
- return result;
-}
-
-
-#ifdef WIN32
-#define SCR_SAVE_MOUSE_MOVE_THRESHOLD 15
-
-static HWND found_ghost_window_hwnd;
-static GHOST_IWindow* ghost_window_to_find;
-static WNDPROC ghost_wnd_proc;
-static POINT scr_save_mouse_pos;
-
-static LRESULT CALLBACK screenSaverWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
-{
- BOOL close = false;
- switch (uMsg)
- {
- case WM_MOUSEMOVE:
- {
- POINT pt;
- GetCursorPos(&pt);
- LONG dx = scr_save_mouse_pos.x - pt.x;
- LONG dy = scr_save_mouse_pos.y - pt.y;
- if (abs(dx) > SCR_SAVE_MOUSE_MOVE_THRESHOLD
- || abs(dy) > SCR_SAVE_MOUSE_MOVE_THRESHOLD)
- {
- close = true;
- }
- scr_save_mouse_pos = pt;
- break;
- }
- case WM_LBUTTONDOWN:
- case WM_MBUTTONDOWN:
- case WM_RBUTTONDOWN:
- case WM_KEYDOWN:
- close = true;
- }
- if (close)
- PostMessage(hwnd,WM_CLOSE,0,0);
- return CallWindowProc(ghost_wnd_proc, hwnd, uMsg, wParam, lParam);
-}
-
-BOOL CALLBACK findGhostWindowHWNDProc(HWND hwnd, LPARAM lParam)
-{
- GHOST_IWindow *p = (GHOST_IWindow*) GetWindowLongPtr(hwnd, GWLP_USERDATA);
- BOOL ret = true;
- if (p == ghost_window_to_find)
- {
- found_ghost_window_hwnd = hwnd;
- ret = false;
- }
- return ret;
-}
-
-static HWND findGhostWindowHWND(GHOST_IWindow* window)
-{
- found_ghost_window_hwnd = NULL;
- ghost_window_to_find = window;
- EnumWindows(findGhostWindowHWNDProc, NULL);
- return found_ghost_window_hwnd;
-}
-
-bool GPG_Application::startScreenSaverPreview(
- HWND parentWindow,
- const bool stereoVisual,
- const int stereoMode,
- const GHOST_TUns16 samples)
-{
- bool success = false;
-
- RECT rc;
- if (GetWindowRect(parentWindow, &rc))
- {
- int windowWidth = rc.right - rc.left;
- int windowHeight = rc.bottom - rc.top;
- STR_String title = "";
- GHOST_GLSettings glSettings = {0};
-
- if (stereoVisual) {
- glSettings.flags |= GHOST_glStereoVisual;
- }
- glSettings.numOfAASamples = samples;
-
- m_mainWindow = fSystem->createWindow(title, 0, 0, windowWidth, windowHeight, GHOST_kWindowStateMinimized,
- GHOST_kDrawingContextTypeOpenGL, glSettings);
- if (!m_mainWindow) {
- printf("error: could not create main window\n");
- exit(-1);
- }
-
- HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow);
- if (!ghost_hwnd) {
- printf("error: could find main window\n");
- exit(-1);
- }
-
- SetParent(ghost_hwnd, parentWindow);
- LONG_PTR style = GetWindowLongPtr(ghost_hwnd, GWL_STYLE);
- LONG_PTR exstyle = GetWindowLongPtr(ghost_hwnd, GWL_EXSTYLE);
-
- RECT adjrc = { 0, 0, windowWidth, windowHeight };
- AdjustWindowRectEx(&adjrc, style, false, exstyle);
-
- style = (style & (~(WS_POPUP|WS_OVERLAPPEDWINDOW|WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_THICKFRAME|WS_MINIMIZEBOX|WS_MAXIMIZEBOX|WS_TILEDWINDOW ))) | WS_CHILD;
- SetWindowLongPtr(ghost_hwnd, GWL_STYLE, style);
- SetWindowPos(ghost_hwnd, NULL, adjrc.left, adjrc.top, 0, 0, SWP_NOZORDER|SWP_NOSIZE|SWP_NOACTIVATE);
-
- /* Check the size of the client rectangle of the window and resize the window
- * so that the client rectangle has the size requested.
- */
- m_mainWindow->setClientSize(windowWidth, windowHeight);
-
- success = initEngine(m_mainWindow, stereoMode);
- if (success) {
- success = startEngine();
- }
-
- }
- return success;
-}
-
-bool GPG_Application::startScreenSaverFullScreen(
- int width,
- int height,
- int bpp,int frequency,
- const bool stereoVisual,
- const int stereoMode,
- const GHOST_TUns16 samples)
-{
- bool ret = startFullScreen(width, height, bpp, frequency, stereoVisual, stereoMode, 0, samples);
- if (ret)
- {
- HWND ghost_hwnd = findGhostWindowHWND(m_mainWindow);
- if (ghost_hwnd != NULL)
- {
- GetCursorPos(&scr_save_mouse_pos);
- ghost_wnd_proc = (WNDPROC) GetWindowLongPtr(ghost_hwnd, GWLP_WNDPROC);
- SetWindowLongPtr(ghost_hwnd,GWLP_WNDPROC, (uintptr_t) screenSaverWindowProc);
- }
- }
- return ret;
-}
-
-#endif
-
-bool GPG_Application::startWindow(
- STR_String& title,
- int windowLeft,
- int windowTop,
- int windowWidth,
- int windowHeight,
- const bool stereoVisual,
- const int stereoMode,
- const int alphaBackground,
- const GHOST_TUns16 samples)
-{
- GHOST_GLSettings glSettings = {0};
- bool success;
- // Create the main window
- //STR_String title ("Blender Player - GHOST");
- if (stereoVisual)
- glSettings.flags |= GHOST_glStereoVisual;
- if (alphaBackground)
- glSettings.flags |= GHOST_glAlphaBackground;
- glSettings.numOfAASamples = samples;
-
- m_mainWindow = fSystem->createWindow(title, windowLeft, windowTop, windowWidth, windowHeight, GHOST_kWindowStateNormal,
- GHOST_kDrawingContextTypeOpenGL, glSettings);
- if (!m_mainWindow) {
- printf("error: could not create main window\n");
- exit(-1);
- }
-
- /* Check the size of the client rectangle of the window and resize the window
- * so that the client rectangle has the size requested.
- */
- m_mainWindow->setClientSize(windowWidth, windowHeight);
- m_mainWindow->setCursorVisibility(false);
-
- success = initEngine(m_mainWindow, stereoMode);
- if (success) {
- success = startEngine();
- }
- return success;
-}
-
-bool GPG_Application::startEmbeddedWindow(
- STR_String& title,
- const GHOST_TEmbedderWindowID parentWindow,
- const bool stereoVisual,
- const int stereoMode,
- const int alphaBackground,
- const GHOST_TUns16 samples)
-{
- GHOST_TWindowState state = GHOST_kWindowStateNormal;
- GHOST_GLSettings glSettings = {0};
-
- if (stereoVisual)
- glSettings.flags |= GHOST_glStereoVisual;
- if (alphaBackground)
- glSettings.flags |= GHOST_glAlphaBackground;
- glSettings.numOfAASamples = samples;
-
- if (parentWindow != 0)
- state = GHOST_kWindowStateEmbedded;
- m_mainWindow = fSystem->createWindow(title, 0, 0, 0, 0, state,
- GHOST_kDrawingContextTypeOpenGL, glSettings, parentWindow);
-
- if (!m_mainWindow) {
- printf("error: could not create main window\n");
- exit(-1);
- }
- m_isEmbedded = true;
-
- bool success = initEngine(m_mainWindow, stereoMode);
- if (success) {
- success = startEngine();
- }
- return success;
-}
-
-
-bool GPG_Application::startFullScreen(
- int width,
- int height,
- int bpp,int frequency,
- const bool stereoVisual,
- const int stereoMode,
- const int alphaBackground,
- const GHOST_TUns16 samples,
- bool useDesktop)
-{
- bool success;
- GHOST_TUns32 sysWidth=0, sysHeight=0;
- fSystem->getMainDisplayDimensions(sysWidth, sysHeight);
- // Create the main window
- GHOST_DisplaySetting setting;
- setting.xPixels = (useDesktop) ? sysWidth : width;
- setting.yPixels = (useDesktop) ? sysHeight : height;
- setting.bpp = bpp;
- setting.frequency = frequency;
-
- fSystem->beginFullScreen(setting, &m_mainWindow, stereoVisual, alphaBackground, samples);
- m_mainWindow->setCursorVisibility(false);
- /* note that X11 ignores this (it uses a window internally for fullscreen) */
- m_mainWindow->setState(GHOST_kWindowStateFullScreen);
-
- success = initEngine(m_mainWindow, stereoMode);
- if (success) {
- success = startEngine();
- }
- return success;
-}
-
-
-
-
-bool GPG_Application::StartGameEngine(int stereoMode)
-{
- bool success = initEngine(m_mainWindow, stereoMode);
-
- if (success)
- success = startEngine();
-
- return success;
-}
-
-
-
-void GPG_Application::StopGameEngine()
-{
- exitEngine();
-}
-
-
-
-bool GPG_Application::processEvent(GHOST_IEvent* event)
-{
- bool handled = true;
-
- switch (event->getType())
- {
- case GHOST_kEventUnknown:
- break;
-
- case GHOST_kEventButtonDown:
- handled = handleButton(event, true);
- break;
-
- case GHOST_kEventButtonUp:
- handled = handleButton(event, false);
- break;
-
- case GHOST_kEventWheel:
- handled = handleWheel(event);
- break;
-
- case GHOST_kEventCursorMove:
- handled = handleCursorMove(event);
- break;
-
- case GHOST_kEventKeyDown:
- handleKey(event, true);
- break;
-
- case GHOST_kEventKeyUp:
- handleKey(event, false);
- break;
-
-
- case GHOST_kEventWindowClose:
- case GHOST_kEventQuit:
- m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
- break;
-
- case GHOST_kEventWindowActivate:
- handled = false;
- break;
- case GHOST_kEventWindowDeactivate:
- handled = false;
- break;
-
- // The player now runs as often as it can (repsecting vsync and fixedtime).
- // This allows the player to break 100fps, but this code is being left here
- // as reference. (see EngineNextFrame)
- //case GHOST_kEventWindowUpdate:
- // {
- // GHOST_IWindow* window = event->getWindow();
- // if (!m_system->validWindow(window)) break;
- // // Update the state of the game engine
- // if (m_kxsystem && !m_exitRequested)
- // {
- // // Proceed to next frame
- // window->activateDrawingContext();
-
- // // first check if we want to exit
- // m_exitRequested = m_ketsjiengine->GetExitCode();
- //
- // // kick the engine
- // bool renderFrame = m_ketsjiengine->NextFrame();
- // if (renderFrame)
- // {
- // // render the frame
- // m_ketsjiengine->Render();
- // }
- // }
- // m_exitString = m_ketsjiengine->GetExitString();
- // }
- // break;
- //
- case GHOST_kEventWindowSize:
- {
- GHOST_IWindow* window = event->getWindow();
- if (!m_system->validWindow(window)) break;
- if (m_canvas) {
- GHOST_Rect bnds;
- window->getClientBounds(bnds);
- m_canvas->Resize(bnds.getWidth(), bnds.getHeight());
- m_ketsjiengine->Resize();
- }
- }
- break;
-
- default:
- handled = false;
- break;
- }
- return handled;
-}
-
-
-
-int GPG_Application::getExitRequested(void)
-{
- return m_exitRequested;
-}
-
-
-GlobalSettings* GPG_Application::getGlobalSettings(void)
-{
- return m_ketsjiengine->GetGlobalSettings();
-}
-
-
-
-const STR_String& GPG_Application::getExitString(void)
-{
- return m_exitString;
-}
-
-
-
-bool GPG_Application::initEngine(GHOST_IWindow* window, const int stereoMode)
-{
- if (!m_engineInitialized)
- {
- GPU_init();
-
- // get and set the preferences
- SYS_SystemHandle syshandle = SYS_GetSystem();
- if (!syshandle)
- return false;
-
- // SYS_WriteCommandLineInt(syshandle, "fixedtime", 0);
- // SYS_WriteCommandLineInt(syshandle, "vertexarrays",1);
- GameData *gm= &m_startScene->gm;
- bool properties = (SYS_GetCommandLineInt(syshandle, "show_properties", 0) != 0);
- bool profile = (SYS_GetCommandLineInt(syshandle, "show_profile", 0) != 0);
-
- bool showPhysics = (gm->flag & GAME_SHOW_PHYSICS);
- SYS_WriteCommandLineInt(syshandle, "show_physics", showPhysics);
-
- bool fixed_framerate= (SYS_GetCommandLineInt(syshandle, "fixedtime", (gm->flag & GAME_ENABLE_ALL_FRAMES)) != 0);
- bool frameRate = (SYS_GetCommandLineInt(syshandle, "show_framerate", 0) != 0);
- bool useLists = (SYS_GetCommandLineInt(syshandle, "displaylists", gm->flag & GAME_DISPLAY_LISTS) != 0) && GPU_display_list_support();
- bool nodepwarnings = (SYS_GetCommandLineInt(syshandle, "ignore_deprecation_warnings", 1) != 0);
- bool restrictAnimFPS = (gm->flag & GAME_RESTRICT_ANIM_UPDATES) != 0;
-
- m_blendermat = (SYS_GetCommandLineInt(syshandle, "blender_material", 1) != 0);
- m_blenderglslmat = (SYS_GetCommandLineInt(syshandle, "blender_glsl_material", 1) != 0);
-
- // create the canvas, rasterizer and rendertools
- m_canvas = new GPG_Canvas(window);
- if (!m_canvas)
- return false;
-
- if (gm->vsync == VSYNC_ADAPTIVE)
- m_canvas->SetSwapInterval(-1);
- else
- m_canvas->SetSwapInterval((gm->vsync == VSYNC_ON) ? 1 : 0);
-
- m_canvas->Init();
- if (gm->flag & GAME_SHOW_MOUSE)
- m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
-
- RAS_STORAGE_TYPE raster_storage = RAS_AUTO_STORAGE;
-
- if (gm->raster_storage == RAS_STORE_VBO) {
- raster_storage = RAS_VBO;
- }
- else if (gm->raster_storage == RAS_STORE_VA) {
- raster_storage = RAS_VA;
- }
- //Don't use displaylists with VBOs
- //If auto starts using VBOs, make sure to check for that here
- if (useLists && raster_storage != RAS_VBO)
- m_rasterizer = new RAS_ListRasterizer(m_canvas, true, raster_storage);
- else
- m_rasterizer = new RAS_OpenGLRasterizer(m_canvas, raster_storage);
-
- /* Stereo parameters - Eye Separation from the UI - stereomode from the command-line/UI */
- m_rasterizer->SetStereoMode((RAS_IRasterizer::StereoMode) stereoMode);
- m_rasterizer->SetEyeSeparation(m_startScene->gm.eyeseparation);
-
- if (!m_rasterizer)
- goto initFailed;
-
- m_rasterizer->PrintHardwareInfo();
-
- // create the inputdevices
- m_keyboard = new GPG_KeyboardDevice();
- if (!m_keyboard)
- goto initFailed;
-
- m_mouse = new GPC_MouseDevice();
- if (!m_mouse)
- goto initFailed;
-
- // create a networkdevice
- m_networkdevice = new NG_LoopBackNetworkDeviceInterface();
- if (!m_networkdevice)
- goto initFailed;
-
- BKE_sound_init(m_maggie);
-
- // create a ketsjisystem (only needed for timing and stuff)
- m_kxsystem = new GPG_System (m_system);
- if (!m_kxsystem)
- goto initFailed;
-
- // create the ketsjiengine
- m_ketsjiengine = new KX_KetsjiEngine(m_kxsystem);
-
- // set the devices
- m_ketsjiengine->SetKeyboardDevice(m_keyboard);
- m_ketsjiengine->SetMouseDevice(m_mouse);
- m_ketsjiengine->SetNetworkDevice(m_networkdevice);
- m_ketsjiengine->SetCanvas(m_canvas);
- m_ketsjiengine->SetRasterizer(m_rasterizer);
-
- KX_KetsjiEngine::SetExitKey(ConvertKeyCode(gm->exitkey));
-#ifdef WITH_PYTHON
- CValue::SetDeprecationWarnings(nodepwarnings);
-#else
- (void)nodepwarnings;
-#endif
-
- m_ketsjiengine->SetUseFixedTime(fixed_framerate);
- m_ketsjiengine->SetTimingDisplay(frameRate, profile, properties);
- m_ketsjiengine->SetRestrictAnimationFPS(restrictAnimFPS);
-
- //set the global settings (carried over if restart/load new files)
- m_ketsjiengine->SetGlobalSettings(m_globalSettings);
- m_ketsjiengine->SetRender(true);
-
- m_engineInitialized = true;
- }
-
- return m_engineInitialized;
-initFailed:
- BKE_sound_exit();
- delete m_kxsystem;
- delete m_networkdevice;
- delete m_mouse;
- delete m_keyboard;
- delete m_rasterizer;
- delete m_canvas;
- m_canvas = NULL;
- m_rasterizer = NULL;
- m_keyboard = NULL;
- m_mouse = NULL;
- m_networkdevice = NULL;
- m_kxsystem = NULL;
- return false;
-}
-
-
-
-bool GPG_Application::startEngine(void)
-{
- if (m_engineRunning) {
- return false;
- }
-
- // Temporary hack to disable banner display for NaN approved content.
- /*
- m_canvas->SetBannerDisplayEnabled(true);
- Camera* cam;
- cam = (Camera*)scene->camera->data;
- if (cam) {
- if (((cam->flag) & 48)==48) {
- m_canvas->SetBannerDisplayEnabled(false);
- }
- }
- else {
- showError(CString("Camera data invalid."));
- return false;
- }
- */
-
- // create a scene converter, create and convert the stratingscene
- m_sceneconverter = new KX_BlenderSceneConverter(m_maggie, m_ketsjiengine);
- if (m_sceneconverter)
- {
- STR_String m_kxStartScenename = m_startSceneName.Ptr();
- m_ketsjiengine->SetSceneConverter(m_sceneconverter);
-
- // if (always_use_expand_framing)
- // sceneconverter->SetAlwaysUseExpandFraming(true);
- if (m_blendermat)
- m_sceneconverter->SetMaterials(true);
- if (m_blenderglslmat && (m_globalSettings->matmode == GAME_MAT_GLSL))
- m_sceneconverter->SetGLSLMaterials(true);
- if (m_startScene->gm.flag & GAME_NO_MATERIAL_CACHING)
- m_sceneconverter->SetCacheMaterials(false);
-
- m_kxStartScene = new KX_Scene(m_keyboard,
- m_mouse,
- m_networkdevice,
- m_kxStartScenename,
- m_startScene,
- m_canvas);
-
-#ifdef WITH_PYTHON
- // some python things
- PyObject *gameLogic, *gameLogic_keys;
- setupGamePython(m_ketsjiengine, m_kxStartScene, m_maggie, NULL, &gameLogic, &gameLogic_keys, m_argc, m_argv);
-#endif // WITH_PYTHON
-
- //initialize Dome Settings
- if (m_startScene->gm.stereoflag == STEREO_DOME)
- m_ketsjiengine->InitDome(m_startScene->gm.dome.res, m_startScene->gm.dome.mode, m_startScene->gm.dome.angle, m_startScene->gm.dome.resbuf, m_startScene->gm.dome.tilt, m_startScene->gm.dome.warptext);
-
- // initialize 3D Audio Settings
- AUD_Device* device = BKE_sound_get_device();
- AUD_Device_setSpeedOfSound(device, m_startScene->audio.speed_of_sound);
- AUD_Device_setDopplerFactor(device, m_startScene->audio.doppler_factor);
- AUD_Device_setDistanceModel(device, AUD_DistanceModel(m_startScene->audio.distance_model));
-
-#ifdef WITH_PYTHON
- // Set the GameLogic.globalDict from marshal'd data, so we can
- // load new blend files and keep data in GameLogic.globalDict
- loadGamePythonConfig(m_pyGlobalDictString, m_pyGlobalDictString_Length);
-#endif
- m_sceneconverter->ConvertScene(
- m_kxStartScene,
- m_rasterizer,
- m_canvas);
- m_ketsjiengine->AddScene(m_kxStartScene);
-
- // Create a timer that is used to kick the engine
- if (!m_frameTimer) {
- m_frameTimer = m_system->installTimer(0, kTimerFreq, frameTimerProc, m_mainWindow);
- }
- m_rasterizer->Init();
- m_ketsjiengine->StartEngine(true);
- m_engineRunning = true;
-
- // Set the animation playback rate for ipo's and actions
- // the framerate below should patch with FPS macro defined in blendef.h
- // Could be in StartEngine set the framerate, we need the scene to do this
- Scene *scene= m_kxStartScene->GetBlenderScene(); // needed for macro
- m_ketsjiengine->SetAnimFrameRate(FPS);
- }
-
- if (!m_engineRunning)
- {
- stopEngine();
- }
-
- return m_engineRunning;
-}
-
-
-void GPG_Application::stopEngine()
-{
-#ifdef WITH_PYTHON
- // GameLogic.globalDict gets converted into a buffer, and sorted in
- // m_pyGlobalDictString so we can restore after python has stopped
- // and started between .blend file loads.
- if (m_pyGlobalDictString) {
- delete [] m_pyGlobalDictString;
- m_pyGlobalDictString = 0;
- }
-
- m_pyGlobalDictString_Length = saveGamePythonConfig(&m_pyGlobalDictString);
-#endif
-
- m_ketsjiengine->StopEngine();
- m_networkdevice->Disconnect();
-
- if (m_sceneconverter) {
- delete m_sceneconverter;
- m_sceneconverter = 0;
- }
- if (m_system && m_frameTimer) {
- m_system->removeTimer(m_frameTimer);
- m_frameTimer = 0;
- }
-
- m_engineRunning = false;
-}
-
-void GPG_Application::EngineNextFrame()
-{
- // Update the state of the game engine
- if (m_kxsystem && !m_exitRequested)
- {
- // Proceed to next frame
- if (m_mainWindow)
- m_mainWindow->activateDrawingContext();
-
- // first check if we want to exit
- m_exitRequested = m_ketsjiengine->GetExitCode();
-
- // kick the engine
- bool renderFrame = m_ketsjiengine->NextFrame();
- if (renderFrame && m_mainWindow)
- {
- // render the frame
- m_ketsjiengine->Render();
- }
- }
- m_exitString = m_ketsjiengine->GetExitString();
-}
-
-void GPG_Application::exitEngine()
-{
- // We only want to kill the engine if it has been initialized
- if (!m_engineInitialized)
- return;
-
- BKE_sound_exit();
- if (m_ketsjiengine)
- {
- stopEngine();
- delete m_ketsjiengine;
- m_ketsjiengine = 0;
- }
- if (m_kxsystem)
- {
- delete m_kxsystem;
- m_kxsystem = 0;
- }
- if (m_networkdevice)
- {
- delete m_networkdevice;
- m_networkdevice = 0;
- }
- if (m_mouse)
- {
- delete m_mouse;
- m_mouse = 0;
- }
- if (m_keyboard)
- {
- delete m_keyboard;
- m_keyboard = 0;
- }
- if (m_rasterizer)
- {
- delete m_rasterizer;
- m_rasterizer = 0;
- }
- if (m_canvas)
- {
- delete m_canvas;
- m_canvas = 0;
- }
-
- GPU_exit();
-
-#ifdef WITH_PYTHON
- // Call this after we're sure nothing needs Python anymore (e.g., destructors)
- exitGamePlayerPythonScripting();
-#endif
-
- m_exitRequested = 0;
- m_engineInitialized = false;
-}
-
-bool GPG_Application::handleWheel(GHOST_IEvent* event)
-{
- bool handled = false;
- MT_assert(event);
- if (m_mouse)
- {
- GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
- GHOST_TEventWheelData* wheelData = static_cast<GHOST_TEventWheelData*>(eventData);
- GPC_MouseDevice::TButtonId button;
- if (wheelData->z > 0)
- button = GPC_MouseDevice::buttonWheelUp;
- else
- button = GPC_MouseDevice::buttonWheelDown;
- m_mouse->ConvertButtonEvent(button, true);
- handled = true;
- }
- return handled;
-}
-
-bool GPG_Application::handleButton(GHOST_IEvent* event, bool isDown)
-{
- bool handled = false;
- MT_assert(event);
- if (m_mouse)
- {
- GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
- GHOST_TEventButtonData* buttonData = static_cast<GHOST_TEventButtonData*>(eventData);
- GPC_MouseDevice::TButtonId button;
- switch (buttonData->button)
- {
- case GHOST_kButtonMaskMiddle:
- button = GPC_MouseDevice::buttonMiddle;
- break;
- case GHOST_kButtonMaskRight:
- button = GPC_MouseDevice::buttonRight;
- break;
- case GHOST_kButtonMaskLeft:
- default:
- button = GPC_MouseDevice::buttonLeft;
- break;
- }
- m_mouse->ConvertButtonEvent(button, isDown);
- handled = true;
- }
- return handled;
-}
-
-
-bool GPG_Application::handleCursorMove(GHOST_IEvent* event)
-{
- bool handled = false;
- MT_assert(event);
- if (m_mouse && m_mainWindow)
- {
- GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
- GHOST_TEventCursorData* cursorData = static_cast<GHOST_TEventCursorData*>(eventData);
- GHOST_TInt32 x, y;
- m_mainWindow->screenToClient(cursorData->x, cursorData->y, x, y);
- m_mouse->ConvertMoveEvent(x, y);
- handled = true;
- }
- return handled;
-}
-
-
-bool GPG_Application::handleKey(GHOST_IEvent* event, bool isDown)
-{
- bool handled = false;
- MT_assert(event);
- if (m_keyboard)
- {
- GHOST_TEventDataPtr eventData = ((GHOST_IEvent*)event)->getData();
- GHOST_TEventKeyData* keyData = static_cast<GHOST_TEventKeyData*>(eventData);
- unsigned int unicode = keyData->utf8_buf[0] ? BLI_str_utf8_as_unicode(keyData->utf8_buf) : keyData->ascii;
-
- if (m_keyboard->ToNative(keyData->key) == KX_KetsjiEngine::GetExitKey() && !m_keyboard->m_hookesc && !m_isEmbedded) {
- m_exitRequested = KX_EXIT_REQUEST_OUTSIDE;
- }
- m_keyboard->ConvertEvent(keyData->key, isDown, unicode);
- handled = true;
- }
- return handled;
-}
-
-
-
-static void frameTimerProc(GHOST_ITimerTask* task, GHOST_TUns64 time)
-{
- GHOST_IWindow* window = (GHOST_IWindow*)task->getUserData();
- if (fSystem->validWindow(window)) {
- window->invalidate();
- }
-}
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Application.h b/source/gameengine/GamePlayer/ghost/GPG_Application.h
deleted file mode 100644
index e757cc10e32..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_Application.h
+++ /dev/null
@@ -1,181 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPG_Application.h
- * \ingroup player
- * \brief GHOST Blender Player application declaration file.
- */
-
-#include "GHOST_IEventConsumer.h"
-#include "STR_String.h"
-
-#ifdef WIN32
-#include <wtypes.h>
-#endif
-
-#include "KX_KetsjiEngine.h"
-
-class KX_KetsjiEngine;
-class KX_Scene;
-class KX_ISceneConverter;
-class NG_LoopBackNetworkDeviceInterface;
-class RAS_IRasterizer;
-class GHOST_IEvent;
-class GHOST_ISystem;
-class GHOST_ITimerTask;
-class GHOST_IWindow;
-class GPC_MouseDevice;
-class GPG_Canvas;
-class GPG_KeyboardDevice;
-class GPG_System;
-struct Main;
-struct Scene;
-
-class GPG_Application : public GHOST_IEventConsumer
-{
-public:
- GPG_Application(GHOST_ISystem* system);
- ~GPG_Application(void);
-
- bool SetGameEngineData(struct Main* maggie, struct Scene* scene, GlobalSettings* gs, int argc, char** argv);
- bool startWindow(STR_String& title,
- int windowLeft, int windowTop,
- int windowWidth, int windowHeight,
- const bool stereoVisual, const int stereoMode, const int alphaBackground=0, const GHOST_TUns16 samples=0);
- bool startFullScreen(int width, int height,
- int bpp, int frequency,
- const bool stereoVisual, const int stereoMode, const int alphaBackground = 0,
- const GHOST_TUns16 samples=0, bool useDesktop=false);
- bool startEmbeddedWindow(STR_String& title, const GHOST_TEmbedderWindowID parent_window,
- const bool stereoVisual, const int stereoMode, const int alphaBackground=0, const GHOST_TUns16 samples=0);
-#ifdef WIN32
- bool startScreenSaverFullScreen(int width, int height,
- int bpp, int frequency,
- const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0);
- bool startScreenSaverPreview(HWND parentWindow,
- const bool stereoVisual, const int stereoMode, const GHOST_TUns16 samples=0);
-#endif
-
- virtual bool processEvent(GHOST_IEvent* event);
- int getExitRequested(void);
- const STR_String& getExitString(void);
- GlobalSettings* getGlobalSettings(void);
-
- inline KX_Scene *GetStartScene() const
- {
- return m_kxStartScene;
- }
-
- bool StartGameEngine(int stereoMode);
- void StopGameEngine();
- void EngineNextFrame();
-
-protected:
- bool handleWheel(GHOST_IEvent* event);
- bool handleButton(GHOST_IEvent* event, bool isDown);
- bool handleCursorMove(GHOST_IEvent* event);
- bool handleKey(GHOST_IEvent* event, bool isDown);
-
- /**
- * Initializes the game engine.
- */
- bool initEngine(GHOST_IWindow* window, int stereoMode);
-
- /**
- * Starts the game engine.
- */
- bool startEngine(void);
-
- /**
- * Stop the game engine.
- */
- void stopEngine(void);
-
- /**
- * Shuts the game engine down.
- */
- void exitEngine(void);
- short m_exitkey;
-
- /* The game data */
- STR_String m_startSceneName;
- struct Scene* m_startScene;
- struct Main* m_maggie;
- KX_Scene *m_kxStartScene;
-
- /* Exit state. */
- int m_exitRequested;
- STR_String m_exitString;
- GlobalSettings* m_globalSettings;
-
- /* GHOST system abstraction. */
- GHOST_ISystem* m_system;
- /* Main window. */
- GHOST_IWindow* m_mainWindow;
- /* Timer to advance frames. */
- GHOST_ITimerTask* m_frameTimer;
- /* The cursor shape displayed. */
- GHOST_TStandardCursor m_cursor;
-
- /** Engine construction state. */
- bool m_engineInitialized;
- /** Engine state. */
- bool m_engineRunning;
- /** Running on embedded window */
- bool m_isEmbedded;
-
- /** the gameengine itself */
- KX_KetsjiEngine* m_ketsjiengine;
- /** The game engine's system abstraction. */
- GPG_System* m_kxsystem;
- /** The game engine's keyboard abstraction. */
- GPG_KeyboardDevice* m_keyboard;
- /** The game engine's mouse abstraction. */
- GPC_MouseDevice* m_mouse;
- /** The game engine's canvas abstraction. */
- GPG_Canvas* m_canvas;
- /** the rasterizer */
- RAS_IRasterizer* m_rasterizer;
- /** Converts Blender data files. */
- KX_ISceneConverter* m_sceneconverter;
- /** Network interface. */
- NG_LoopBackNetworkDeviceInterface* m_networkdevice;
-
- bool m_blendermat;
- bool m_blenderglslmat;
-
- /*
- * GameLogic.globalDict as a string so that loading new blend files can use the same dict.
- * Do this because python starts/stops when loading blend files.
- */
- char* m_pyGlobalDictString;
- int m_pyGlobalDictString_Length;
-
- /* argc and argv need to be passed on to python */
- int m_argc;
- char** m_argv;
-};
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp b/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
deleted file mode 100644
index 09eb1691dae..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.cpp
+++ /dev/null
@@ -1,177 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/GamePlayer/ghost/GPG_Canvas.cpp
- * \ingroup player
- */
-
-
-#include "GPG_Canvas.h"
-#include <assert.h>
-#include "GHOST_ISystem.h"
-
-GPG_Canvas::GPG_Canvas(GHOST_IWindow* window)
-: GPC_Canvas(0, 0), m_window(window)
-{
- if (m_window)
- {
- GHOST_Rect bnds;
- m_window->getClientBounds(bnds);
- this->Resize(bnds.getWidth(), bnds.getHeight());
- }
-}
-
-
-GPG_Canvas::~GPG_Canvas(void)
-{
-}
-
-
-void GPG_Canvas::Init()
-{
- if (m_window)
- {
- m_window->setDrawingContextType(GHOST_kDrawingContextTypeOpenGL);
- assert(m_window->getDrawingContextType() == GHOST_kDrawingContextTypeOpenGL);
- }
-}
-
-void GPG_Canvas::SetMousePosition(int x, int y)
-{
- GHOST_ISystem* system = GHOST_ISystem::getSystem();
- if (system && m_window)
- {
- GHOST_TInt32 gx = (GHOST_TInt32)x;
- GHOST_TInt32 gy = (GHOST_TInt32)y;
- GHOST_TInt32 cx;
- GHOST_TInt32 cy;
- m_window->clientToScreen(gx, gy, cx, cy);
- system->setCursorPosition(cx, cy);
- }
-}
-
-
-void GPG_Canvas::SetMouseState(RAS_MouseState mousestate)
-{
- m_mousestate = mousestate;
-
- if (m_window)
- {
- switch (mousestate)
- {
- case MOUSE_INVISIBLE:
- m_window->setCursorVisibility(false);
- break;
- case MOUSE_WAIT:
- m_window->setCursorShape(GHOST_kStandardCursorWait);
- m_window->setCursorVisibility(true);
- break;
- case MOUSE_NORMAL:
- m_window->setCursorShape(GHOST_kStandardCursorDefault);
- m_window->setCursorVisibility(true);
- break;
- }
- }
-}
-
-
-void GPG_Canvas::SwapBuffers()
-{
- if (m_window)
- {
- m_window->swapBuffers();
- }
-}
-
-void GPG_Canvas::SetSwapInterval(int interval)
-{
- if (m_window)
- m_window->setSwapInterval(interval);
-}
-
-bool GPG_Canvas::GetSwapInterval(int& intervalOut)
-{
- if (m_window)
- return (bool)m_window->getSwapInterval(intervalOut);
-
- return false;
-}
-
-void GPG_Canvas::GetDisplayDimensions(int &width, int &height)
- {
- unsigned int uiwidth;
- unsigned int uiheight;
-
- GHOST_ISystem *system = GHOST_ISystem::getSystem();
- system->getMainDisplayDimensions(uiwidth, uiheight);
-
- width = uiwidth;
- height = uiheight;
-}
-
-void GPG_Canvas::ResizeWindow(int width, int height)
-{
- if (m_window->getState() == GHOST_kWindowStateFullScreen)
- {
- GHOST_ISystem* system = GHOST_ISystem::getSystem();
- GHOST_DisplaySetting setting;
- setting.xPixels = width;
- setting.yPixels = height;
- //XXX allow these to be changed or kept from previous state
- setting.bpp = 32;
- setting.frequency = 60;
-
- system->updateFullScreen(setting, &m_window);
- }
-
- m_window->setClientSize(width, height);
-
- Resize(width, height);
-}
-
-void GPG_Canvas::SetFullScreen(bool enable)
-{
- if (enable)
- m_window->setState(GHOST_kWindowStateFullScreen);
- else
- m_window->setState(GHOST_kWindowStateNormal);
-}
-
-bool GPG_Canvas::GetFullScreen()
-{
- return m_window->getState() == GHOST_kWindowStateFullScreen;
-}
-
-float GPG_Canvas::GetMouseNormalizedX(int x)
-{
- return float(x)/this->GetWidth();
-}
-
-float GPG_Canvas::GetMouseNormalizedY(int y)
-{
- return float(y)/this->GetHeight();
-}
diff --git a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h b/source/gameengine/GamePlayer/ghost/GPG_Canvas.h
deleted file mode 100644
index 18afbf6cd9e..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_Canvas.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPG_Canvas.h
- * \ingroup player
- */
-
-#ifndef __GPG_CANVAS_H__
-#define __GPG_CANVAS_H__
-
-#ifdef WIN32
-#pragma warning (disable:4786)
-#endif /* WIN32 */
-
-#include "GPC_Canvas.h"
-
-#include "GHOST_IWindow.h"
-
-
-class GPG_Canvas : public GPC_Canvas
-{
-protected:
- /** GHOST window. */
- GHOST_IWindow* m_window;
-
-public:
- GPG_Canvas(GHOST_IWindow* window);
- virtual ~GPG_Canvas(void);
-
- virtual void Init(void);
- virtual void SetMousePosition(int x, int y);
- virtual void SetMouseState(RAS_MouseState mousestate);
- virtual void SwapBuffers();
- virtual void SetSwapInterval(int interval);
- virtual bool GetSwapInterval(int& intervalOut);
-
- virtual int GetMouseX(int x) { return x; }
- virtual int GetMouseY(int y) { return y; }
- virtual float GetMouseNormalizedX(int x);
- virtual float GetMouseNormalizedY(int y);
-
- virtual void GetDisplayDimensions(int &width, int &height);
-
- virtual void ResizeWindow(int width, int height);
- virtual void SetFullScreen(bool enable);
- virtual bool GetFullScreen();
-
- bool BeginDraw() { return true; }
- void EndDraw() {};
-};
-
-#endif /* __GPG_CANVAS_H__ */
diff --git a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp b/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp
deleted file mode 100644
index eefaa3730cf..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp
+++ /dev/null
@@ -1,165 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * GHOST Blender Player keyboard device implementation.
- */
-
-/** \file gameengine/GamePlayer/ghost/GPG_KeyboardDevice.cpp
- * \ingroup player
- */
-
-
-#include "GPG_KeyboardDevice.h"
-
-GPG_KeyboardDevice::GPG_KeyboardDevice(void)
-{
- m_reverseKeyTranslateTable[GHOST_kKeyA ] = KX_AKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyB ] = KX_BKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyC ] = KX_CKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyD ] = KX_DKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyE ] = KX_EKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF ] = KX_FKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyG ] = KX_GKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyH ] = KX_HKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyI ] = KX_IKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyJ ] = KX_JKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyK ] = KX_KKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyL ] = KX_LKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyM ] = KX_MKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyN ] = KX_NKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyO ] = KX_OKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyP ] = KX_PKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyQ ] = KX_QKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyR ] = KX_RKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyS ] = KX_SKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyT ] = KX_TKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyU ] = KX_UKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyV ] = KX_VKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyW ] = KX_WKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyX ] = KX_XKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyY ] = KX_YKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyZ ] = KX_ZKEY ;
-
- m_reverseKeyTranslateTable[GHOST_kKey0 ] = KX_ZEROKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey1 ] = KX_ONEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey2 ] = KX_TWOKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey3 ] = KX_THREEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey4 ] = KX_FOURKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey5 ] = KX_FIVEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey6 ] = KX_SIXKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey7 ] = KX_SEVENKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey8 ] = KX_EIGHTKEY ;
- m_reverseKeyTranslateTable[GHOST_kKey9 ] = KX_NINEKEY ;
-
- // Middle keyboard area keys
- m_reverseKeyTranslateTable[GHOST_kKeyPause ] = KX_PAUSEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyInsert ] = KX_INSERTKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyDelete ] = KX_DELKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyHome ] = KX_HOMEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyEnd ] = KX_ENDKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyUpPage ] = KX_PAGEUPKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyDownPage ] = KX_PAGEDOWNKEY ;
-
- // Arrow keys
- m_reverseKeyTranslateTable[GHOST_kKeyUpArrow ] = KX_UPARROWKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyDownArrow ] = KX_DOWNARROWKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyLeftArrow ] = KX_LEFTARROWKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyRightArrow ] = KX_RIGHTARROWKEY ;
-
- // Function keys
- m_reverseKeyTranslateTable[GHOST_kKeyF1 ] = KX_F1KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF2 ] = KX_F2KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF3 ] = KX_F3KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF4 ] = KX_F4KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF5 ] = KX_F5KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF6 ] = KX_F6KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF7 ] = KX_F7KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF8 ] = KX_F8KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF9 ] = KX_F9KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF10 ] = KX_F10KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF11 ] = KX_F11KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF12 ] = KX_F12KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF13 ] = KX_F13KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF14 ] = KX_F14KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF15 ] = KX_F15KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF16 ] = KX_F16KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF17 ] = KX_F17KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF18 ] = KX_F18KEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyF19 ] = KX_F19KEY ;
-
-
- // Numpad keys
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad0 ] = KX_PAD0 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad1 ] = KX_PAD1 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad2 ] = KX_PAD2 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad3 ] = KX_PAD3 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad4 ] = KX_PAD4 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad5 ] = KX_PAD5 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad6 ] = KX_PAD6 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad7 ] = KX_PAD7 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad8 ] = KX_PAD8 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpad9 ] = KX_PAD9 ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpadAsterisk ] = KX_PADASTERKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpadPlus ] = KX_PADPLUSKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpadPeriod ] = KX_PADPERIOD ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpadMinus ] = KX_PADMINUS ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpadSlash ] = KX_PADSLASHKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyNumpadEnter ] = KX_PADENTER ;
-
- // Other keys
- m_reverseKeyTranslateTable[GHOST_kKeyCapsLock ] = KX_CAPSLOCKKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyEsc ] = KX_ESCKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyTab ] = KX_TABKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeySpace ] = KX_SPACEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyEnter ] = KX_RETKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyBackSpace ] = KX_BACKSPACEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeySemicolon ] = KX_SEMICOLONKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyPeriod ] = KX_PERIODKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyComma ] = KX_COMMAKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyQuote ] = KX_QUOTEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyAccentGrave ] = KX_ACCENTGRAVEKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyMinus ] = KX_MINUSKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyPlus ] = KX_PLUSKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeySlash ] = KX_SLASHKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyBackslash ] = KX_BACKSLASHKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyEqual ] = KX_EQUALKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyLeftBracket ] = KX_LEFTBRACKETKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyRightBracket ] = KX_RIGHTBRACKETKEY ;
-
- m_reverseKeyTranslateTable[GHOST_kKeyOS ] = KX_OSKEY ;
-
- // Modifier keys.
- m_reverseKeyTranslateTable[GHOST_kKeyLeftControl ] = KX_LEFTCTRLKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyRightControl ] = KX_RIGHTCTRLKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyLeftAlt ] = KX_LEFTALTKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyRightAlt ] = KX_RIGHTALTKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyLeftShift ] = KX_LEFTSHIFTKEY ;
- m_reverseKeyTranslateTable[GHOST_kKeyRightShift ] = KX_RIGHTSHIFTKEY ;
-}
-
-
-GPG_KeyboardDevice::~GPG_KeyboardDevice(void)
-{
-}
diff --git a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h b/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h
deleted file mode 100644
index ff8d56db40a..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_KeyboardDevice.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPG_KeyboardDevice.h
- * \ingroup player
- * \brief GHOST Blender Player keyboard device.
- */
-
-#ifndef __GPG_KEYBOARDDEVICE_H__
-#define __GPG_KEYBOARDDEVICE_H__
-
-#ifdef WIN32
-#pragma warning (disable:4786)
-#endif /* WIN32 */
-
-#include "GHOST_Types.h"
-#include "GPC_KeyboardDevice.h"
-
-/**
- * GHOST implementation of GPC_KeyboardDevice.
- * The contructor fills the keyboard code translation map.
- * Base class GPC_KeyboardDevice does the rest.
- * \see SCA_IInputDevice
- */
-class GPG_KeyboardDevice : public GPC_KeyboardDevice
-{
-public:
- GPG_KeyboardDevice(void);
- virtual ~GPG_KeyboardDevice(void);
-};
-
-#endif /* __GPG_KEYBOARDDEVICE_H__ */
diff --git a/source/gameengine/GamePlayer/ghost/GPG_System.cpp b/source/gameengine/GamePlayer/ghost/GPG_System.cpp
deleted file mode 100644
index 669ab0532d9..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_System.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Blender Player system on GHOST.
- */
-
-/** \file gameengine/GamePlayer/ghost/GPG_System.cpp
- * \ingroup player
- */
-
-
-#include "GPG_System.h"
-#include <assert.h>
-#include "GHOST_ISystem.h"
-
-GPG_System::GPG_System(GHOST_ISystem* system)
-: m_system(system)
-{
- assert(m_system);
-}
-
-
-double GPG_System::GetTimeInSeconds()
-{
- GHOST_TInt64 millis = (GHOST_TInt64)m_system->getMilliSeconds();
- double time = (double)millis;
- time /= 1000.0;
- return time;
-}
-
-
diff --git a/source/gameengine/GamePlayer/ghost/GPG_System.h b/source/gameengine/GamePlayer/ghost/GPG_System.h
deleted file mode 100644
index 1ec7a06d1cf..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_System.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file GPG_System.h
- * \ingroup player
- * \brief Blender Player system on GHOST.
- */
-
-#ifndef __GPG_SYSTEM_H__
-#define __GPG_SYSTEM_H__
-
-#ifdef WIN32
-#pragma warning (disable:4786) // suppress stl-MSVC debug info warning
-#endif /* WIN32 */
-
-#include "KX_ISystem.h"
-
-class GHOST_ISystem;
-
-class GPG_System : public KX_ISystem
-{
- GHOST_ISystem* m_system;
-
-public:
- GPG_System(GHOST_ISystem* system);
-
- virtual double GetTimeInSeconds();
-};
-
-#endif /* __GPG_SYSTEM_H__ */
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
deleted file mode 100644
index 906e9d9a821..00000000000
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ /dev/null
@@ -1,1227 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Start up of the Blender Player on GHOST.
- */
-
-/** \file gameengine/GamePlayer/ghost/GPG_ghost.cpp
- * \ingroup player
- */
-
-
-#include <iostream>
-#include <math.h>
-
-#ifdef __linux__
-#ifdef __alpha__
-#include <signal.h>
-#endif /* __alpha__ */
-#endif /* __linux__ */
-
-#include "KX_KetsjiEngine.h"
-#include "KX_PythonInit.h"
-#include "KX_PythonMain.h"
-#include "KX_PyConstraintBinding.h" // for PHY_SetActiveEnvironment
-
-/**********************************
- * Begin Blender include block
- **********************************/
-#ifdef __cplusplus
-extern "C"
-{
-#endif // __cplusplus
-#include "MEM_guardedalloc.h"
-#include "MEM_CacheLimiterC-Api.h"
-
-#include "BLI_threads.h"
-#include "BLI_mempool.h"
-#include "BLI_blenlib.h"
-
-#include "DNA_scene_types.h"
-#include "DNA_userdef_types.h"
-#include "DNA_genfile.h"
-
-#include "BLO_readfile.h"
-#include "BLO_runtime.h"
-
-#include "BKE_appdir.h"
-#include "BKE_blender.h"
-#include "BKE_depsgraph.h"
-#include "BKE_global.h"
-#include "BKE_icons.h"
-#include "BKE_image.h"
-#include "BKE_node.h"
-#include "BKE_report.h"
-#include "BKE_library.h"
-#include "BKE_library_remap.h"
-#include "BKE_modifier.h"
-#include "BKE_material.h"
-#include "BKE_text.h"
-#include "BKE_sound.h"
-
-#include "IMB_imbuf.h"
-#include "IMB_moviecache.h"
-
-#ifdef __APPLE__
- int GHOST_HACK_getFirstFile(char buf[]);
-#endif
-
-// For BLF
-#include "BLF_api.h"
-#include "BLT_translation.h"
-#include "BLT_lang.h"
-extern int datatoc_bfont_ttf_size;
-extern char datatoc_bfont_ttf[];
-extern int datatoc_bmonofont_ttf_size;
-extern char datatoc_bmonofont_ttf[];
-
-#ifdef __cplusplus
-}
-#endif // __cplusplus
-
-#include "GPU_draw.h"
-
-/**********************************
- * End Blender include block
- **********************************/
-
-#include "BL_System.h"
-#include "GPG_Application.h"
-
-#include "GHOST_ISystem.h"
-#include "RAS_IRasterizer.h"
-
-#include "BKE_main.h"
-
-#include "RNA_define.h"
-
-#ifdef WIN32
-# include <windows.h>
-# if !defined(DEBUG)
-# include <wincon.h>
-# endif // !defined(DEBUG)
-# if defined(_MSC_VER) && defined(_M_X64)
-# include <math.h> /* needed for _set_FMA3_enable */
-# endif
-# include "utfconv.h"
-#endif // WIN32
-
-#ifdef WITH_SDL_DYNLOAD
-# include "sdlew.h"
-#endif
-
-const int kMinWindowWidth = 100;
-const int kMinWindowHeight = 100;
-
-static void mem_error_cb(const char *errorStr)
-{
- fprintf(stderr, "%s", errorStr);
- fflush(stderr);
-}
-
-// library.c will only free window managers with a callback function.
-// We don't actually use a wmWindowManager, but loading a blendfile
-// loads wmWindows, so we need to free those.
-static void wm_free(bContext *C, wmWindowManager *wm)
-{
- BLI_freelistN(&wm->windows);
-}
-
-#ifdef WIN32
-typedef enum {
- SCREEN_SAVER_MODE_NONE = 0,
- SCREEN_SAVER_MODE_PREVIEW,
- SCREEN_SAVER_MODE_SAVER,
- SCREEN_SAVER_MODE_CONFIGURATION,
- SCREEN_SAVER_MODE_PASSWORD,
-} ScreenSaverMode;
-
-static ScreenSaverMode scr_saver_mode = SCREEN_SAVER_MODE_NONE;
-static HWND scr_saver_hwnd = NULL;
-
-static BOOL scr_saver_init(int argc, char **argv)
-{
- scr_saver_mode = SCREEN_SAVER_MODE_NONE;
- scr_saver_hwnd = NULL;
- BOOL ret = false;
-
- int len = ::strlen(argv[0]);
- if (len > 4 && !::stricmp(".scr", argv[0] + len - 4))
- {
- scr_saver_mode = SCREEN_SAVER_MODE_CONFIGURATION;
- ret = true;
- if (argc >= 2)
- {
- if (argc >= 3)
- {
- scr_saver_hwnd = (HWND) ::atoi(argv[2]);
- }
- if (!::stricmp("/c", argv[1]))
- {
- scr_saver_mode = SCREEN_SAVER_MODE_CONFIGURATION;
- if (scr_saver_hwnd == NULL)
- scr_saver_hwnd = ::GetForegroundWindow();
- }
- else if (!::stricmp("/s", argv[1]))
- {
- scr_saver_mode = SCREEN_SAVER_MODE_SAVER;
- }
- else if (!::stricmp("/a", argv[1]))
- {
- scr_saver_mode = SCREEN_SAVER_MODE_PASSWORD;
- }
- else if (!::stricmp("/p", argv[1])
- || !::stricmp("/l", argv[1]))
- {
- scr_saver_mode = SCREEN_SAVER_MODE_PREVIEW;
- }
- }
- }
- return ret;
-}
-
-#endif /* WIN32 */
-
-static void usage(const char* program, bool isBlenderPlayer)
-{
- const char * consoleoption;
- const char * example_filename = "";
- const char * example_pathname = "";
-
-#ifdef _WIN32
- consoleoption = "[-c] ";
-#else
- consoleoption = "";
-#endif
-
- if (isBlenderPlayer) {
- example_filename = "filename.blend";
-#ifdef _WIN32
- example_pathname = "c:\\";
-#else
- example_pathname = "/home/user/";
-#endif
- }
- printf("\n");
- printf("usage: %s [--options] %s\n\n", program, example_filename);
- printf("Available options are: [-w [w h l t]] [-f [fw fh fb ff]] %s[-g gamengineoptions] ", consoleoption);
- printf("[-s stereomode] [-m aasamples]\n");
- printf("Optional parameters must be passed in order.\n");
- printf("Default values are set in the blend file.\n\n");
- printf(" -h: Prints this command summary\n\n");
- printf(" -w: display in a window\n");
- printf(" --Optional parameters--\n");
- printf(" w = window width\n");
- printf(" h = window height\n");
- printf(" l = window left coordinate\n");
- printf(" t = window top coordinate\n");
- printf(" Note: To define 'w' or 'h', both must be used.");
- printf("Also, to define 'l' or 't', all four parameters must be used.\n");
- printf(" Example: -w or -w 500 300 or -w 500 300 0 0\n\n");
- printf(" -f: start game in fullscreen mode\n");
- printf(" --Optional parameters--\n");
- printf(" fw = fullscreen mode pixel width (use 0 to detect automatically)\n");
- printf(" fh = fullscreen mode pixel height (use 0 to detect automatically)\n");
- printf(" fb = fullscreen mode bits per pixel (default unless set in the blend file: 32)\n");
- printf(" ff = fullscreen mode frequency (default unless set in the blend file: 60)\n");
- printf(" Note: To define 'fw'' or 'fh'', both must be used.\n");
- printf(" Example: -f or -f 1024 768 or -f 0 0 16 or -f 1024 728 16 30\n\n");
- printf(" -s: start player in stereoscopy mode (requires 3D capable hardware)\n");
- printf(" stereomode: nostereo (default unless stereo is set in the blend file)\n");
- printf(" anaglyph (Red-Blue glasses)\n");
- printf(" sidebyside (Left Right)\n");
- printf(" syncdoubling (Above Below)\n");
- printf(" 3dtvtopbottom (Squashed Top-Bottom for passive glasses)\n");
- printf(" interlace (Interlace horizontally)\n");
- printf(" vinterlace (Vertical interlace for autostereo display)\n");
- printf(" hwpageflip (Quad buffered shutter glasses)\n");
- printf(" Example: -s sidebyside or -s vinterlace\n\n");
- printf(" -D: start player in dome mode\n");
- printf(" --Optional parameters--\n");
- printf(" angle = field of view in degrees\n");
- printf(" tilt = tilt angle in degrees\n");
- printf(" warpdata = a file to use for warping the image (absolute path)\n");
- printf(" mode: fisheye (Fisheye)\n");
- printf(" truncatedfront (Front-Truncated)\n");
- printf(" truncatedrear (Rear-Truncated)\n");
- printf(" cubemap (Cube Map)\n");
- printf(" sphericalpanoramic (Spherical Panoramic)\n");
- printf(" Example: -D or -D mode cubemap\n\n");
- printf(" -m: maximum anti-aliasing (eg. 2,4,8,16)\n\n");
- printf(" -i: parent window's ID\n\n");
-#ifdef _WIN32
- printf(" -c: keep console window open\n\n");
-#endif
- printf(" -d: turn debugging on\n\n");
- printf(" -g: game engine options:\n\n");
- printf(" Name Default Description\n");
- printf(" ------------------------------------------------------------------------\n");
- printf(" fixedtime 0 \"Enable all frames\"\n");
- printf(" nomipmap 0 Disable mipmaps\n");
- printf(" show_framerate 0 Show the frame rate\n");
- printf(" show_properties 0 Show debug properties\n");
- printf(" show_profile 0 Show profiling information\n");
- printf(" blender_material 0 Enable material settings\n");
- printf(" ignore_deprecation_warnings 1 Ignore deprecation warnings\n");
- printf("\n");
- printf(" - : all arguments after this are ignored, allowing python to access them from sys.argv\n");
- printf("\n");
- printf("example: %s -w 320 200 10 10 -g noaudio %s%s\n", program, example_pathname, example_filename);
- printf("example: %s -g show_framerate = 0 %s%s\n", program, example_pathname, example_filename);
- printf("example: %s -i 232421 -m 16 %s%s\n\n", program, example_pathname, example_filename);
-}
-
-static void get_filename(int argc, char **argv, char *filename)
-{
-#ifdef __APPLE__
- /* On Mac we park the game file (called game.blend) in the application bundle.
- * The executable is located in the bundle as well.
- * Therefore, we can locate the game relative to the executable.
- */
- int srclen = ::strlen(argv[0]);
- int len = 0;
- char *gamefile = NULL;
-
- filename[0] = '\0';
-
- if (argc > 1) {
- if (BLI_exists(argv[argc-1])) {
- BLI_strncpy(filename, argv[argc-1], FILE_MAX);
- }
- if (::strncmp(argv[argc-1], "-psn_", 5)==0) {
- static char firstfilebuf[512];
- if (GHOST_HACK_getFirstFile(firstfilebuf)) {
- BLI_strncpy(filename, firstfilebuf, FILE_MAX);
- }
- }
- }
-
- srclen -= ::strlen("MacOS/blenderplayer");
- if (srclen > 0) {
- len = srclen + ::strlen("Resources/game.blend");
- gamefile = new char [len + 1];
- ::strcpy(gamefile, argv[0]);
- ::strcpy(gamefile + srclen, "Resources/game.blend");
- //::printf("looking for file: %s\n", filename);
-
- if (BLI_exists(gamefile))
- BLI_strncpy(filename, gamefile, FILE_MAX);
-
- delete [] gamefile;
- }
-
-#else
- filename[0] = '\0';
-
- if (argc > 1)
- BLI_strncpy(filename, argv[argc-1], FILE_MAX);
-#endif // !_APPLE
-}
-
-static BlendFileData *load_game_data(const char *progname, char *filename = NULL, char *relativename = NULL)
-{
- ReportList reports;
- BlendFileData *bfd = NULL;
-
- BKE_reports_init(&reports, RPT_STORE);
-
- /* try to load ourself, will only work if we are a runtime */
- if (BLO_is_a_runtime(progname)) {
- bfd= BLO_read_runtime(progname, &reports);
- if (bfd) {
- bfd->type= BLENFILETYPE_RUNTIME;
- BLI_strncpy(bfd->main->name, progname, sizeof(bfd->main->name));
- }
- } else {
- bfd= BLO_read_from_file(progname, &reports, BLO_READ_SKIP_NONE);
- }
-
- if (!bfd && filename) {
- bfd = load_game_data(filename);
- if (!bfd) {
- printf("Loading %s failed: ", filename);
- BKE_reports_print(&reports, RPT_ERROR);
- }
- }
-
- BKE_reports_clear(&reports);
-
- return bfd;
-}
-
-static bool GPG_NextFrame(GHOST_ISystem* system, GPG_Application *app, int &exitcode, STR_String &exitstring, GlobalSettings *gs)
-{
- bool run = true;
- system->processEvents(false);
- system->dispatchEvents();
- app->EngineNextFrame();
- if ((exitcode = app->getExitRequested())) {
- run = false;
- exitstring = app->getExitString();
- *gs = *app->getGlobalSettings();
- }
- return run;
-}
-
-struct GPG_NextFrameState {
- GHOST_ISystem* system;
- GPG_Application *app;
- GlobalSettings *gs;
-} gpg_nextframestate;
-
-static int GPG_PyNextFrame(void *state0)
-{
- GPG_NextFrameState *state = (GPG_NextFrameState *) state0;
- int exitcode;
- STR_String exitstring;
- bool run = GPG_NextFrame(state->system, state->app, exitcode, exitstring, state->gs);
- if (run) return 0;
- else {
- if (exitcode)
- fprintf(stderr, "Exit code %d: %s\n", exitcode, exitstring.ReadPtr());
- return 1;
- }
-}
-
-int main(
- int argc,
-#ifdef WIN32
- char **UNUSED(argv_c)
-#else
- char **argv
-#endif
- )
-{
- int i;
- int argc_py_clamped= argc; /* use this so python args can be added after ' - ' */
- bool error = false;
- SYS_SystemHandle syshandle = SYS_GetSystem();
- bool fullScreen = false;
- bool fullScreenParFound = false;
- bool windowParFound = false;
-#ifdef WIN32
- bool closeConsole = true;
-#endif
- RAS_IRasterizer::StereoMode stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
- bool stereoWindow = false;
- bool stereoParFound = false;
- int stereoFlag = STEREO_NOSTEREO;
- int domeFov = -1;
- int domeTilt = -200;
- int domeMode = 0;
- char* domeWarp = NULL;
- Text *domeText = NULL;
- int windowLeft = 100;
- int windowTop = 100;
- int windowWidth = 640;
- int windowHeight = 480;
- GHOST_TUns32 fullScreenWidth = 0;
- GHOST_TUns32 fullScreenHeight= 0;
- int fullScreenBpp = 32;
- int fullScreenFrequency = 60;
- GHOST_TEmbedderWindowID parentWindow = 0;
- bool isBlenderPlayer = false; //true when lauching from blender or command line. false for bundled player
- int validArguments=0;
- bool samplesParFound = false;
- GHOST_TUns16 aasamples = 0;
- int alphaBackground = 0;
-
-#ifdef WIN32
- char **argv;
- int argv_num;
-
- /* We delay loading of openmp so we can set the policy here. */
-# if defined(_MSC_VER)
- _putenv_s("OMP_WAIT_POLICY", "PASSIVE");
-# endif
-
- /* FMA3 support in the 2013 CRT is broken on Vista and Windows 7 RTM (fixed in SP1). Just disable it. */
-# if defined(_MSC_VER) && defined(_M_X64)
- _set_FMA3_enable(0);
-# endif
-
- /* Win32 Unicode Args */
- /* NOTE: cannot use guardedalloc malloc here, as it's not yet initialized
- * (it depends on the args passed in, which is what we're getting here!)
- */
- {
- wchar_t **argv_16 = CommandLineToArgvW(GetCommandLineW(), &argc);
- argv = (char**)malloc(argc * sizeof(char *));
- for (argv_num = 0; argv_num < argc; argv_num++) {
- argv[argv_num] = alloc_utf_8_from_16(argv_16[argv_num], 0);
- }
- LocalFree(argv_16);
- }
-#endif /* WIN32 */
-
-#ifdef __linux__
-#ifdef __alpha__
- signal (SIGFPE, SIG_IGN);
-#endif /* __alpha__ */
-#endif /* __linux__ */
-
-#ifdef WITH_SDL_DYNLOAD
- sdlewInit();
-#endif
-
- BKE_appdir_program_path_init(argv[0]);
- BKE_tempdir_init(NULL);
-
- // We don't use threads directly in the BGE, but we need to call this so things like
- // freeing up GPU_Textures works correctly.
- BLI_threadapi_init();
-
- DNA_sdna_current_init();
-
- RNA_init();
-
- init_nodesystem();
-
- BKE_blender_globals_init();
-
- // We load our own G.main, so free the one that BKE_blender_globals_init() gives us
- BKE_main_free(G.main);
- G.main = NULL;
-
- MEM_CacheLimiter_set_disabled(true);
- IMB_init();
- BKE_images_init();
- BKE_modifier_init();
- DAG_init();
-
-#ifdef WITH_FFMPEG
- IMB_ffmpeg_init();
-#endif
-
- // Setup builtin font for BLF (mostly copied from creator.c, wm_init_exit.c and interface_style.c)
- BLF_init();
- BLT_lang_init();
- BLT_lang_set("");
-
- BLF_load_mem("default", (unsigned char*)datatoc_bfont_ttf, datatoc_bfont_ttf_size);
- if (blf_mono_font == -1)
- blf_mono_font = BLF_load_mem_unique("monospace", (unsigned char*)datatoc_bmonofont_ttf, datatoc_bmonofont_ttf_size);
-
- // Parse command line options
-#if defined(DEBUG)
- printf("argv[0] = '%s'\n", argv[0]);
-#endif
-
-#ifdef WIN32
- if (scr_saver_init(argc, argv))
- {
- switch (scr_saver_mode)
- {
- case SCREEN_SAVER_MODE_CONFIGURATION:
- MessageBox(scr_saver_hwnd, "This screen saver has no options that you can set", "Screen Saver", MB_OK);
- break;
- case SCREEN_SAVER_MODE_PASSWORD:
- /* This is W95 only, which we currently do not support.
- * Fall-back to normal screen saver behavior in that case... */
- case SCREEN_SAVER_MODE_SAVER:
- fullScreen = true;
- fullScreenParFound = true;
- break;
-
- case SCREEN_SAVER_MODE_PREVIEW:
- /* This will actually be handled somewhere below... */
- break;
- }
- }
-#endif
- // XXX add the ability to change this values to the command line parsing.
- U.mixbufsize = 2048;
- U.audiodevice = 2;
- U.audiorate = 44100;
- U.audioformat = 0x24;
- U.audiochannels = 2;
-
- // XXX this one too
- U.anisotropic_filter = 2;
- // enable fast mipmap generation
- U.use_gpu_mipmap = 1;
-
- BKE_sound_init_once();
-
- // Initialize a default material for meshes without materials.
- init_def_material();
-
- BKE_library_callback_free_window_manager_set(wm_free);
-
- /* if running blenderplayer the last argument can't be parsed since it has to be the filename. else it is bundled */
- isBlenderPlayer = !BLO_is_a_runtime(argv[0]);
- if (isBlenderPlayer)
- validArguments = argc - 1;
- else
- validArguments = argc;
-
-
- /* Parsing command line arguments (can be set from WM_OT_blenderplayer_start) */
-#if defined(DEBUG)
- printf("Parsing command line arguments...\n");
- printf("Num of arguments is: %i\n", validArguments-1); //-1 because i starts at 1
-#endif
-
- for (i = 1; (i < validArguments) && !error
-#ifdef WIN32
- && scr_saver_mode == SCREEN_SAVER_MODE_NONE
-#endif
- ;)
-
- {
-#if defined(DEBUG)
- printf("argv[%d] = '%s'\n", i, argv[i]);
-#endif
- if (argv[i][0] == '-')
- {
- /* ignore all args after " - ", allow python to have own args */
- if (argv[i][1]=='\0') {
- argc_py_clamped= i;
- break;
- }
-
- switch (argv[i][1])
- {
- case 'g': //game engine options (show_framerate, fixedtime, etc)
- {
- i++;
- if (i <= validArguments)
- {
- char* paramname = argv[i];
- // Check for single value versus assignment
- if (i+1 <= validArguments && (*(argv[i+1]) == '='))
- {
- i++;
- if (i + 1 <= validArguments)
- {
- i++;
- // Assignment
- SYS_WriteCommandLineInt(syshandle, paramname, atoi(argv[i]));
- SYS_WriteCommandLineFloat(syshandle, paramname, atof(argv[i]));
- SYS_WriteCommandLineString(syshandle, paramname, argv[i]);
-#if defined(DEBUG)
- printf("%s = '%s'\n", paramname, argv[i]);
-#endif
- i++;
- }
- else
- {
- error = true;
- printf("error: argument assignment %s without value.\n", paramname);
- }
- }
- else
- {
-// SYS_WriteCommandLineInt(syshandle, argv[i++], 1);
- }
- }
- break;
- }
- case 'd': //debug on
- {
- i++;
- G.debug |= G_DEBUG;
- MEM_set_memory_debug();
-#ifndef NDEBUG
- BLI_mempool_set_memory_debug();
-#endif
- break;
- }
- case 'f': //fullscreen mode
- {
- i++;
- fullScreen = true;
- fullScreenParFound = true;
- if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
- {
- fullScreenWidth = atoi(argv[i++]);
- fullScreenHeight = atoi(argv[i++]);
- if ((i + 1) <= validArguments && argv[i][0] != '-')
- {
- fullScreenBpp = atoi(argv[i++]);
- if ((i + 1) <= validArguments && argv[i][0] != '-')
- fullScreenFrequency = atoi(argv[i++]);
- }
- }
- else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
- {
- error = true;
- printf("error: to define fullscreen width or height, both options must be used.\n");
- }
- break;
- }
- case 'w': //display in a window
- {
- i++;
- fullScreen = false;
- windowParFound = true;
-
- // Parse window position and size options
- if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
- {
- windowWidth = atoi(argv[i++]);
- windowHeight = atoi(argv[i++]);
-
- if ((i + 2) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
- {
- windowLeft = atoi(argv[i++]);
- windowTop = atoi(argv[i++]);
- }
- else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
- {
- error = true;
- printf("error: to define the window left or right coordinates, both options must be used.\n");
- }
- }
- else if ((i + 1) <= validArguments && argv[i][0] != '-' && argv[i+1][0] != '-')
- {
- error = true;
- printf("error: to define the window's width or height, both options must be used.\n");
- }
- break;
- }
- case 'h': //display help
- {
- usage(argv[0], isBlenderPlayer);
- return 0;
- break;
- }
- case 'i': //parent window ID
- {
- i++;
- if ( (i + 1) <= validArguments )
- parentWindow = (GHOST_TEmbedderWindowID)atoll(argv[i++]);
- else {
- error = true;
- printf("error: too few options for parent window argument.\n");
- }
-#if defined(DEBUG)
- printf("XWindows ID = %d\n", parentWindow);
-#endif // defined(DEBUG)
- break;
- }
- case 'm': //maximum anti-aliasing (eg. 2,4,8,16)
- {
- i++;
- samplesParFound = true;
- if ((i+1) <= validArguments )
- aasamples = atoi(argv[i++]);
- else
- {
- error = true;
- printf("error: No argument supplied for -m");
- }
- break;
- }
- case 'c': //keep console (windows only)
- {
- i++;
-#ifdef WIN32
- closeConsole = false;
-#endif
- break;
- }
- case 's': //stereo mode
- {
- i++;
- if ((i + 1) <= validArguments)
- {
- stereoParFound = true;
- stereoFlag = STEREO_ENABLED;
-
- if (!strcmp(argv[i], "nostereo")) // may not be redundant if the file has different setting
- {
- stereomode = RAS_IRasterizer::RAS_STEREO_NOSTEREO;
- stereoFlag = STEREO_NOSTEREO;
- }
-
- // only the hardware pageflip method needs a stereo window
- else if (!strcmp(argv[i], "hwpageflip")) {
- stereomode = RAS_IRasterizer::RAS_STEREO_QUADBUFFERED;
- stereoWindow = true;
- }
- else if (!strcmp(argv[i], "syncdoubling"))
- stereomode = RAS_IRasterizer::RAS_STEREO_ABOVEBELOW;
-
- else if (!strcmp(argv[i], "3dtvtopbottom"))
- stereomode = RAS_IRasterizer::RAS_STEREO_3DTVTOPBOTTOM;
-
- else if (!strcmp(argv[i], "anaglyph"))
- stereomode = RAS_IRasterizer::RAS_STEREO_ANAGLYPH;
-
- else if (!strcmp(argv[i], "sidebyside"))
- stereomode = RAS_IRasterizer::RAS_STEREO_SIDEBYSIDE;
-
- else if (!strcmp(argv[i], "interlace"))
- stereomode = RAS_IRasterizer::RAS_STEREO_INTERLACED;
-
- else if (!strcmp(argv[i], "vinterlace"))
- stereomode = RAS_IRasterizer::RAS_STEREO_VINTERLACE;
-
-#if 0
-// // future stuff
-// else if (!strcmp(argv[i], "stencil")
-// stereomode = RAS_STEREO_STENCIL;
-#endif
- else
- {
- error = true;
- printf("error: stereomode '%s' unrecognized.\n", argv[i]);
- }
-
- i++;
- }
- else
- {
- error = true;
- printf("error: too few options for stereo argument.\n");
- }
- break;
- }
- case 'D': //dome mode
- {
- stereoFlag = STEREO_DOME;
- stereomode = RAS_IRasterizer::RAS_STEREO_DOME;
- i++;
- if ((i + 1) <= validArguments)
- {
- if (!strcmp(argv[i], "angle")) {
- i++;
- domeFov = atoi(argv[i++]);
- }
- if (!strcmp(argv[i], "tilt")) {
- i++;
- domeTilt = atoi(argv[i++]);
- }
- if (!strcmp(argv[i], "warpdata")) {
- i++;
- domeWarp = argv[i++];
- }
- if (!strcmp(argv[i], "mode")) {
- i++;
- if (!strcmp(argv[i], "fisheye"))
- domeMode = DOME_FISHEYE;
-
- else if (!strcmp(argv[i], "truncatedfront"))
- domeMode = DOME_TRUNCATED_FRONT;
-
- else if (!strcmp(argv[i], "truncatedrear"))
- domeMode = DOME_TRUNCATED_REAR;
-
- else if (!strcmp(argv[i], "cubemap"))
- domeMode = DOME_ENVMAP;
-
- else if (!strcmp(argv[i], "sphericalpanoramic"))
- domeMode = DOME_PANORAM_SPH;
-
- else
- printf("error: %s is not a valid dome mode.\n", argv[i]);
- }
- i++;
- }
- break;
- }
- case 'a': // allow window to blend with display background
- {
- i++;
- alphaBackground = 1;
- break;
- }
- default: //not recognized
- {
- printf("Unknown argument: %s\n", argv[i++]);
- break;
- }
- }
- }
- else
- {
- i++;
- }
- }
-
- if ((windowWidth < kMinWindowWidth) || (windowHeight < kMinWindowHeight))
- {
- error = true;
- printf("error: window size too small.\n");
- }
-
- if (error )
- {
- usage(argv[0], isBlenderPlayer);
- return 0;
- }
-
-#ifdef WIN32
- if (scr_saver_mode != SCREEN_SAVER_MODE_CONFIGURATION)
-#endif
- {
- // Create the system
- if (GHOST_ISystem::createSystem() == GHOST_kSuccess) {
- GHOST_ISystem* system = GHOST_ISystem::getSystem();
- assertd(system);
-
- if (!fullScreenWidth || !fullScreenHeight)
- system->getMainDisplayDimensions(fullScreenWidth, fullScreenHeight);
- // process first batch of events. If the user
- // drops a file on top off the blenderplayer icon, we
- // receive an event with the filename
-
- system->processEvents(0);
-
- // this bracket is needed for app (see below) to get out
- // of scope before GHOST_ISystem::disposeSystem() is called.
- {
- int exitcode = KX_EXIT_REQUEST_NO_REQUEST;
- STR_String exitstring = "";
- GPG_Application app(system);
- bool firstTimeRunning = true;
- char filename[FILE_MAX];
- char pathname[FILE_MAX];
- char *titlename;
-
- get_filename(argc_py_clamped, argv, filename);
- if (filename[0])
- BLI_path_cwd(filename, sizeof(filename));
-
-
- // fill the GlobalSettings with the first scene files
- // those may change during the game and persist after using Game Actuator
- GlobalSettings gs;
-
- do {
- // Read the Blender file
- BlendFileData *bfd;
-
- // if we got an exitcode 3 (KX_EXIT_REQUEST_START_OTHER_GAME) load a different file
- if (exitcode == KX_EXIT_REQUEST_START_OTHER_GAME)
- {
- char basedpath[FILE_MAX];
-
- // base the actuator filename relative to the last file
- BLI_strncpy(basedpath, exitstring.Ptr(), sizeof(basedpath));
- BLI_path_abs(basedpath, pathname);
-
- bfd = load_game_data(basedpath);
-
- if (!bfd) {
- // just add "//" in front of it
- char temppath[FILE_MAX] = "//";
- BLI_strncpy(temppath + 2, basedpath, FILE_MAX - 2);
-
- BLI_path_abs(temppath, pathname);
- bfd = load_game_data(temppath);
- }
- }
- else {
- bfd = load_game_data(BKE_appdir_program_path(), filename[0]? filename: NULL);
- }
-
-#if defined(DEBUG)
- printf("Game data loaded from %s\n", filename);
-#endif
-
- if (!bfd) {
- usage(argv[0], isBlenderPlayer);
- error = true;
- exitcode = KX_EXIT_REQUEST_QUIT_GAME;
- }
- else {
- /* Setting options according to the blend file if not overriden in the command line */
-#ifdef WIN32
-#if !defined(DEBUG)
- if (closeConsole) {
- system->toggleConsole(0); // Close a console window
- }
-#endif // !defined(DEBUG)
-#endif // WIN32
- Main *maggie = bfd->main;
- Scene *scene = bfd->curscene;
- G.main = maggie;
-
- if (firstTimeRunning) {
- G.fileflags = bfd->fileflags;
-
- gs.matmode= scene->gm.matmode;
- gs.glslflag= scene->gm.flag;
- }
-
- //Seg Fault; icon.c gIcons == 0
- BKE_icons_init(1);
-
- titlename = maggie->name;
-
- // Check whether the game should be displayed full-screen
- if ((!fullScreenParFound) && (!windowParFound)) {
- // Only use file settings when command line did not override
- if ((scene->gm.playerflag & GAME_PLAYER_FULLSCREEN)) {
- //printf("fullscreen option found in Blender file\n");
- fullScreen = true;
- fullScreenWidth= scene->gm.xplay;
- fullScreenHeight= scene->gm.yplay;
- fullScreenFrequency= scene->gm.freqplay;
- fullScreenBpp = scene->gm.depth;
- }
- else
- {
- fullScreen = false;
- windowWidth = scene->gm.xplay;
- windowHeight = scene->gm.yplay;
- }
- }
-
-
- // Check whether the game should be displayed in stereo (dome included)
- if (!stereoParFound) {
- // Only use file settings when command line did not override
- if (scene->gm.stereoflag == STEREO_ENABLED) {
- stereomode = (RAS_IRasterizer::StereoMode) scene->gm.stereomode;
- if (stereomode == RAS_IRasterizer::RAS_STEREO_QUADBUFFERED)
- stereoWindow = true;
- }
- }
- else {
- scene->gm.stereoflag = STEREO_ENABLED;
- }
-
- if (!samplesParFound)
- aasamples = scene->gm.aasamples;
-
- // Dome specific settings
- if (stereoFlag == STEREO_DOME) {
- stereomode = RAS_IRasterizer::RAS_STEREO_DOME;
- scene->gm.stereoflag = STEREO_DOME;
- if (domeFov > 89)
- scene->gm.dome.angle = domeFov;
- if (domeTilt > -180)
- scene->gm.dome.tilt = domeTilt;
- if (domeMode > 0)
- scene->gm.dome.mode = domeMode;
- if (domeWarp) {
- //XXX to do: convert relative to absolute path
- domeText= BKE_text_load(G.main, domeWarp, "");
- if (!domeText)
- printf("error: invalid warpdata text file - %s\n", domeWarp);
- else
- scene->gm.dome.warptext = domeText;
- }
- }
-
- // GPG_Application app (system, maggie, startscenename);
- app.SetGameEngineData(maggie, scene, &gs, argc, argv); /* this argc cant be argc_py_clamped, since python uses it */
- BLI_strncpy(pathname, maggie->name, sizeof(pathname));
- if (G.main != maggie) {
- BLI_strncpy(G.main->name, maggie->name, sizeof(G.main->name));
- }
-#ifdef WITH_PYTHON
- setGamePythonPath(G.main->name);
-#endif
- if (firstTimeRunning) {
- firstTimeRunning = false;
-
- if (fullScreen) {
-#ifdef WIN32
- if (scr_saver_mode == SCREEN_SAVER_MODE_SAVER)
- {
- app.startScreenSaverFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
- stereoWindow, stereomode, aasamples);
- }
- else
-#endif
- {
- app.startFullScreen(fullScreenWidth, fullScreenHeight, fullScreenBpp, fullScreenFrequency,
- stereoWindow, stereomode, alphaBackground, aasamples, (scene->gm.playerflag & GAME_PLAYER_DESKTOP_RESOLUTION));
- }
- }
- else
- {
-#ifdef __APPLE__
- // on Mac's we'll show the executable name instead of the 'game.blend' name
- char tempname[1024], *appstring;
- ::strcpy(tempname, titlename);
-
- appstring = strstr(tempname, ".app/");
- if (appstring) {
- appstring[2] = 0;
- titlename = &tempname[0];
- }
-#endif
- // Strip the path so that we have the name of the game file
- STR_String path = titlename;
-#ifndef WIN32
- vector<STR_String> parts = path.Explode('/');
-#else // WIN32
- vector<STR_String> parts = path.Explode('\\');
-#endif // WIN32
- STR_String title;
- if (parts.size()) {
- title = parts[parts.size()-1];
- parts = title.Explode('.');
- if (parts.size() > 1)
- {
- title = parts[0];
- }
- }
- else {
- title = "blenderplayer";
- }
-#ifdef WIN32
- if (scr_saver_mode == SCREEN_SAVER_MODE_PREVIEW)
- {
- app.startScreenSaverPreview(scr_saver_hwnd, stereoWindow, stereomode, aasamples);
- }
- else
-#endif
- {
- if (parentWindow != 0)
- app.startEmbeddedWindow(title, parentWindow, stereoWindow, stereomode, aasamples);
- else
- app.startWindow(title, windowLeft, windowTop, windowWidth, windowHeight,
- stereoWindow, stereomode, alphaBackground, aasamples);
-
- if (SYS_GetCommandLineInt(syshandle, "nomipmap", 0)) {
- GPU_set_mipmap(0);
- }
-
- GPU_set_anisotropic(U.anisotropic_filter);
- GPU_set_gpu_mipmapping(U.use_gpu_mipmap);
- }
- }
- }
- else {
- app.StartGameEngine(stereomode);
- exitcode = KX_EXIT_REQUEST_NO_REQUEST;
- }
-
- // Add the application as event consumer
- system->addEventConsumer(&app);
-
- // Enter main loop
- bool run = true;
- char *python_main = NULL;
- pynextframestate.state = NULL;
- pynextframestate.func = NULL;
-#ifdef WITH_PYTHON
- python_main = KX_GetPythonMain(scene);
-#endif // WITH_PYTHON
- if (python_main) {
- char *python_code = KX_GetPythonCode(maggie, python_main);
- if (python_code) {
-#ifdef WITH_PYTHON
- // Set python environement variable.
- KX_Scene *startscene = app.GetStartScene();
- KX_SetActiveScene(startscene);
- PHY_SetActiveEnvironment(startscene->GetPhysicsEnvironment());
-
- gpg_nextframestate.system = system;
- gpg_nextframestate.app = &app;
- gpg_nextframestate.gs = &gs;
- pynextframestate.state = &gpg_nextframestate;
- pynextframestate.func = &GPG_PyNextFrame;
-
- printf("Yielding control to Python script '%s'...\n", python_main);
- PyRun_SimpleString(python_code);
- printf("Exit Python script '%s'\n", python_main);
-#endif // WITH_PYTHON
- MEM_freeN(python_code);
- }
- else {
- fprintf(stderr, "ERROR: cannot yield control to Python: no Python text data-block named '%s'\n", python_main);
- }
- }
- else {
- while (run) {
- run = GPG_NextFrame(system, &app, exitcode, exitstring, &gs);
- }
- }
- app.StopGameEngine();
-
- /* 'app' is freed automatic when out of scope.
- * removal is needed else the system will free an already freed value */
- system->removeEventConsumer(&app);
-
- BLO_blendfiledata_free(bfd);
- /* G.main == bfd->main, it gets referenced in free_nodesystem so we can't have a dangling pointer */
- G.main = NULL;
- if (python_main) MEM_freeN(python_main);
- }
- } while (exitcode == KX_EXIT_REQUEST_RESTART_GAME || exitcode == KX_EXIT_REQUEST_START_OTHER_GAME);
- }
-
- // Seg Fault; icon.c gIcons == 0
- BKE_icons_free();
-
- // Dispose the system
- GHOST_ISystem::disposeSystem();
- }
- else {
- error = true;
- printf("error: couldn't create a system.\n");
- }
- }
-
- /* refer to WM_exit_ext() and BKE_blender_free(),
- * these are not called in the player but we need to match some of there behavior here,
- * if the order of function calls or blenders state isn't matching that of blender proper,
- * we may get troubles later on */
-
- free_nodesystem();
-
- // Cleanup
- RNA_exit();
- BLF_exit();
-
-#ifdef WITH_INTERNATIONAL
- BLF_free_unifont();
- BLF_free_unifont_mono();
- BLT_lang_free();
-#endif
-
- IMB_exit();
- BKE_images_exit();
- DAG_exit();
- IMB_moviecache_destruct();
-
- SYS_DeleteSystem(syshandle);
-
- int totblock= MEM_get_memory_blocks_in_use();
- if (totblock!=0) {
- printf("Error Totblock: %d\n",totblock);
- MEM_set_error_callback(mem_error_cb);
- MEM_printmemlist();
- }
-
- BKE_tempdir_session_purge();
-
-#ifdef WIN32
- while (argv_num) {
- free(argv[--argv_num]);
- }
- free(argv);
- argv = NULL;
-#endif
-
- return error ? -1 : 0;
-}
diff --git a/source/gameengine/Ketsji/BL_Action.cpp b/source/gameengine/Ketsji/BL_Action.cpp
deleted file mode 100644
index 7175eb877dd..00000000000
--- a/source/gameengine/Ketsji/BL_Action.cpp
+++ /dev/null
@@ -1,534 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_Action.cpp
- * \ingroup ketsji
- */
-
-#include <cstdlib>
-#include <stdio.h>
-
-#include "BL_Action.h"
-#include "BL_ArmatureObject.h"
-#include "BL_DeformableGameObject.h"
-#include "BL_ShapeDeformer.h"
-#include "KX_IpoConvert.h"
-#include "KX_GameObject.h"
-
-#include "SG_Controller.h"
-
-// These three are for getting the action from the logic manager
-#include "KX_Scene.h"
-#include "SCA_LogicManager.h"
-
-extern "C" {
-#include "BKE_animsys.h"
-#include "BKE_action.h"
-#include "RNA_access.h"
-#include "RNA_define.h"
-
-// Needed for material IPOs
-#include "BKE_material.h"
-#include "DNA_material_types.h"
-#include "DNA_scene_types.h"
-}
-
-#include "MEM_guardedalloc.h"
-#include "BKE_library.h"
-#include "BKE_global.h"
-
-#include "BLI_threads.h" // for lock
-
-/* Lock to solve animation thread issues.
- * A spin lock is better than a mutex in case of short wait
- * because spin lock stop the thread by a loop contrary to mutex
- * which switch all memory, process.
- */
-static SpinLock BL_ActionLock;
-
-BL_Action::BL_Action(class KX_GameObject* gameobj)
-:
- m_action(NULL),
- m_tmpaction(NULL),
- m_blendpose(NULL),
- m_blendinpose(NULL),
- m_obj(gameobj),
- m_startframe(0.f),
- m_endframe(0.f),
- m_localframe(0.f),
- m_blendin(0.f),
- m_blendframe(0.f),
- m_blendstart(0.f),
- m_speed(0.f),
- m_priority(0),
- m_playmode(ACT_MODE_PLAY),
- m_blendmode(ACT_BLEND_BLEND),
- m_ipo_flags(0),
- m_done(true),
- m_calc_localtime(true),
- m_initializedTime(false)
-{
-}
-
-BL_Action::~BL_Action()
-{
- if (m_blendpose)
- BKE_pose_free(m_blendpose);
- if (m_blendinpose)
- BKE_pose_free(m_blendinpose);
- ClearControllerList();
-
- if (m_tmpaction) {
- BKE_libblock_free(G.main, m_tmpaction);
- m_tmpaction = NULL;
- }
-}
-
-void BL_Action::ClearControllerList()
-{
- // Clear out the controller list
- std::vector<SG_Controller*>::iterator it;
- for (it = m_sg_contr_list.begin(); it != m_sg_contr_list.end(); it++)
- {
- m_obj->GetSGNode()->RemoveSGController((*it));
- delete *it;
- }
-
- m_sg_contr_list.clear();
-}
-
-bool BL_Action::Play(const char* name,
- float start,
- float end,
- short priority,
- float blendin,
- short play_mode,
- float layer_weight,
- short ipo_flags,
- float playback_speed,
- short blend_mode)
-{
-
- // Only start playing a new action if we're done, or if
- // the new action has a higher priority
- if (!IsDone() && priority > m_priority)
- return false;
- m_priority = priority;
- bAction* prev_action = m_action;
-
- KX_Scene* kxscene = m_obj->GetScene();
-
- // First try to load the action
- m_action = (bAction*)kxscene->GetLogicManager()->GetActionByName(name);
- if (!m_action)
- {
- printf("Failed to load action: %s\n", name);
- m_done = true;
- return false;
- }
-
- // If we have the same settings, don't play again
- // This is to resolve potential issues with pulses on sensors such as the ones
- // reported in bug #29412. The fix is here so it works for both logic bricks and Python.
- // However, this may eventually lead to issues where a user wants to override an already
- // playing action with the same action and settings. If this becomes an issue,
- // then this fix may have to be re-evaluated.
- if (!IsDone() && m_action == prev_action && m_startframe == start && m_endframe == end
- && m_priority == priority && m_speed == playback_speed)
- return false;
-
- // Keep a copy of the action for threading purposes
- if (m_tmpaction) {
- BKE_libblock_free(G.main, m_tmpaction);
- m_tmpaction = NULL;
- }
- m_tmpaction = BKE_action_copy(G.main, m_action);
-
- // First get rid of any old controllers
- ClearControllerList();
-
- // Create an SG_Controller
- SG_Controller *sg_contr = BL_CreateIPO(m_action, m_obj, kxscene->GetSceneConverter());
- m_sg_contr_list.push_back(sg_contr);
- m_obj->GetSGNode()->AddSGController(sg_contr);
- sg_contr->SetObject(m_obj->GetSGNode());
-
- // World
- sg_contr = BL_CreateWorldIPO(m_action, kxscene->GetBlenderScene()->world, kxscene->GetSceneConverter());
- if (sg_contr) {
- m_sg_contr_list.push_back(sg_contr);
- m_obj->GetSGNode()->AddSGController(sg_contr);
- sg_contr->SetObject(m_obj->GetSGNode());
- }
-
- // Try obcolor
- sg_contr = BL_CreateObColorIPO(m_action, m_obj, kxscene->GetSceneConverter());
- if (sg_contr) {
- m_sg_contr_list.push_back(sg_contr);
- m_obj->GetSGNode()->AddSGController(sg_contr);
- sg_contr->SetObject(m_obj->GetSGNode());
- }
-
- // Now try materials
- if (m_obj->GetBlenderObject()->totcol==1) {
- Material *mat = give_current_material(m_obj->GetBlenderObject(), 1);
- if (mat) {
- sg_contr = BL_CreateMaterialIpo(m_action, mat, 0, m_obj, kxscene->GetSceneConverter());
- if (sg_contr) {
- m_sg_contr_list.push_back(sg_contr);
- m_obj->GetSGNode()->AddSGController(sg_contr);
- sg_contr->SetObject(m_obj->GetSGNode());
- }
- }
- } else {
- Material *mat;
- STR_HashedString matname;
-
- for (int matidx = 1; matidx <= m_obj->GetBlenderObject()->totcol; ++matidx) {
- mat = give_current_material(m_obj->GetBlenderObject(), matidx);
- if (mat) {
- matname = mat->id.name;
- sg_contr = BL_CreateMaterialIpo(m_action, mat, matname.hash(), m_obj, kxscene->GetSceneConverter());
- if (sg_contr) {
- m_sg_contr_list.push_back(sg_contr);
- m_obj->GetSGNode()->AddSGController(sg_contr);
- sg_contr->SetObject(m_obj->GetSGNode());
- }
- }
- }
- }
-
- // Extra controllers
- if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT)
- {
- sg_contr = BL_CreateLampIPO(m_action, m_obj, kxscene->GetSceneConverter());
- m_sg_contr_list.push_back(sg_contr);
- m_obj->GetSGNode()->AddSGController(sg_contr);
- sg_contr->SetObject(m_obj->GetSGNode());
- }
- else if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA)
- {
- sg_contr = BL_CreateCameraIPO(m_action, m_obj, kxscene->GetSceneConverter());
- m_sg_contr_list.push_back(sg_contr);
- m_obj->GetSGNode()->AddSGController(sg_contr);
- sg_contr->SetObject(m_obj->GetSGNode());
- }
-
- m_ipo_flags = ipo_flags;
- InitIPO();
-
- // Setup blendin shapes/poses
- if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- {
- BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj;
- obj->GetPose(&m_blendinpose);
- }
- else
- {
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj;
- BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
-
- if (shape_deformer && shape_deformer->GetKey())
- {
- obj->GetShape(m_blendinshape);
-
- // Now that we have the previous blend shape saved, we can clear out the key to avoid any
- // further interference.
- KeyBlock *kb;
- for (kb=(KeyBlock *)shape_deformer->GetKey()->block.first; kb; kb=(KeyBlock *)kb->next)
- kb->curval = 0.f;
- }
- }
-
- // Now that we have an action, we have something we can play
- m_starttime = -1.f; // We get the start time on our first update
- m_startframe = m_localframe = start;
- m_endframe = end;
- m_blendin = blendin;
- m_playmode = play_mode;
- m_blendmode = blend_mode;
- m_blendframe = 0.f;
- m_blendstart = 0.f;
- m_speed = playback_speed;
- m_layer_weight = layer_weight;
-
- m_done = false;
- m_initializedTime = false;
-
- return true;
-}
-
-bool BL_Action::IsDone()
-{
- return m_done;
-}
-
-void BL_Action::InitIPO()
-{
- // Initialize the IPOs
- std::vector<SG_Controller*>::iterator it;
- for (it = m_sg_contr_list.begin(); it != m_sg_contr_list.end(); it++)
- {
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, m_ipo_flags & ACT_IPOFLAG_FORCE);
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, m_ipo_flags & ACT_IPOFLAG_ADD);
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, m_ipo_flags & ACT_IPOFLAG_LOCAL);
- }
-}
-
-bAction *BL_Action::GetAction()
-{
- return (IsDone()) ? NULL : m_action;
-}
-
-float BL_Action::GetFrame()
-{
- return m_localframe;
-}
-
-const char *BL_Action::GetName()
-{
- if (m_action != NULL) {
- return m_action->id.name + 2;
- }
- else {
- return "";
- }
-
-
-}
-
-void BL_Action::SetFrame(float frame)
-{
- // Clamp the frame to the start and end frame
- if (frame < min(m_startframe, m_endframe))
- frame = min(m_startframe, m_endframe);
- else if (frame > max(m_startframe, m_endframe))
- frame = max(m_startframe, m_endframe);
-
- m_localframe = frame;
- m_calc_localtime = false;
-}
-
-void BL_Action::SetPlayMode(short play_mode)
-{
- m_playmode = play_mode;
-}
-
-void BL_Action::SetTimes(float start, float end)
-{
- m_startframe = start;
- m_endframe = end;
-}
-
-void BL_Action::SetLocalTime(float curtime)
-{
- float dt = (curtime-m_starttime)*(float)KX_KetsjiEngine::GetAnimFrameRate()*m_speed;
-
- if (m_endframe < m_startframe)
- dt = -dt;
-
- m_localframe = m_startframe + dt;
-}
-
-void BL_Action::ResetStartTime(float curtime)
-{
- float dt = (m_localframe > m_startframe) ? m_localframe - m_startframe : m_startframe - m_localframe;
-
- m_starttime = curtime - dt / ((float)KX_KetsjiEngine::GetAnimFrameRate()*m_speed);
- SetLocalTime(curtime);
-}
-
-void BL_Action::IncrementBlending(float curtime)
-{
- // Setup m_blendstart if we need to
- if (m_blendstart == 0.f)
- m_blendstart = curtime;
-
- // Bump the blend frame
- m_blendframe = (curtime - m_blendstart)*(float)KX_KetsjiEngine::GetAnimFrameRate();
-
- // Clamp
- if (m_blendframe>m_blendin)
- m_blendframe = m_blendin;
-}
-
-
-void BL_Action::BlendShape(Key* key, float srcweight, std::vector<float>& blendshape)
-{
- vector<float>::const_iterator it;
- float dstweight;
- KeyBlock *kb;
-
- dstweight = 1.0F - srcweight;
- //printf("Dst: %f\tSrc: %f\n", srcweight, dstweight);
- for (it=blendshape.begin(), kb = (KeyBlock *)key->block.first;
- kb && it != blendshape.end();
- kb = (KeyBlock *)kb->next, it++)
- {
- //printf("OirgKeys: %f\t%f\n", kb->curval, (*it));
- kb->curval = kb->curval * dstweight + (*it) * srcweight;
- //printf("NewKey: %f\n", kb->curval);
- }
- //printf("\n");
-}
-
-void BL_Action::Update(float curtime)
-{
- // Don't bother if we're done with the animation
- if (m_done)
- return;
-
- curtime -= (float)KX_KetsjiEngine::GetSuspendedDelta();
-
- // Grab the start time here so we don't end up with a negative m_localframe when
- // suspending and resuming scenes.
- if (!m_initializedTime) {
- m_starttime = curtime;
- m_initializedTime = true;
- }
-
- if (m_calc_localtime)
- SetLocalTime(curtime);
- else
- {
- ResetStartTime(curtime);
- m_calc_localtime = true;
- }
-
- // Handle wrap around
- if (m_localframe < min(m_startframe, m_endframe) || m_localframe > max(m_startframe, m_endframe)) {
- switch (m_playmode) {
- case ACT_MODE_PLAY:
- // Clamp
- m_localframe = m_endframe;
- m_done = true;
- break;
- case ACT_MODE_LOOP:
- // Put the time back to the beginning
- m_localframe = m_startframe;
- m_starttime = curtime;
- break;
- case ACT_MODE_PING_PONG:
- // Swap the start and end frames
- float temp = m_startframe;
- m_startframe = m_endframe;
- m_endframe = temp;
-
- m_starttime = curtime;
-
- break;
- }
- }
-
- if (m_obj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- {
- BL_ArmatureObject *obj = (BL_ArmatureObject*)m_obj;
-
- if (m_layer_weight >= 0)
- obj->GetPose(&m_blendpose);
-
- // Extract the pose from the action
- obj->SetPoseByAction(m_tmpaction, m_localframe);
-
- // Handle blending between armature actions
- if (m_blendin && m_blendframe<m_blendin)
- {
- IncrementBlending(curtime);
-
- // Calculate weight
- float weight = 1.f - (m_blendframe/m_blendin);
-
- // Blend the poses
- obj->BlendInPose(m_blendinpose, weight, ACT_BLEND_BLEND);
- }
-
-
- // Handle layer blending
- if (m_layer_weight >= 0)
- obj->BlendInPose(m_blendpose, m_layer_weight, m_blendmode);
-
- obj->UpdateTimestep(curtime);
- }
- else
- {
- BL_DeformableGameObject *obj = (BL_DeformableGameObject*)m_obj;
- BL_ShapeDeformer *shape_deformer = dynamic_cast<BL_ShapeDeformer*>(obj->GetDeformer());
-
- // Handle shape actions if we have any
- if (shape_deformer && shape_deformer->GetKey())
- {
- Key *key = shape_deformer->GetKey();
-
- PointerRNA ptrrna;
- RNA_id_pointer_create(&key->id, &ptrrna);
-
- animsys_evaluate_action(&ptrrna, m_tmpaction, NULL, m_localframe);
-
- // Handle blending between shape actions
- if (m_blendin && m_blendframe < m_blendin)
- {
- IncrementBlending(curtime);
-
- float weight = 1.f - (m_blendframe/m_blendin);
-
- // We go through and clear out the keyblocks so there isn't any interference
- // from other shape actions
- KeyBlock *kb;
- for (kb=(KeyBlock *)key->block.first; kb; kb=(KeyBlock *)kb->next)
- kb->curval = 0.f;
-
- // Now blend the shape
- BlendShape(key, weight, m_blendinshape);
- }
-
- // Handle layer blending
- if (m_layer_weight >= 0)
- {
- obj->GetShape(m_blendshape);
- BlendShape(key, m_layer_weight, m_blendshape);
- }
-
- obj->SetActiveAction(NULL, 0, curtime);
- }
- }
-
- BLI_spin_lock(&BL_ActionLock);
- /* This function is not thread safe because of recursive scene graph transform
- * updates on children. e.g: If an object and one of its children is animated,
- * the both can write transform at the same time. A thread lock avoid problems. */
- m_obj->UpdateIPO(m_localframe, m_ipo_flags & ACT_IPOFLAG_CHILD);
- BLI_spin_unlock(&BL_ActionLock);
-
- if (m_done)
- ClearControllerList();
-}
-
-void BL_Action::InitLock()
-{
- BLI_spin_init(&BL_ActionLock);
-}
-
-void BL_Action::EndLock()
-{
- BLI_spin_end(&BL_ActionLock);
-}
diff --git a/source/gameengine/Ketsji/BL_Action.h b/source/gameengine/Ketsji/BL_Action.h
deleted file mode 100644
index f4c2975a547..00000000000
--- a/source/gameengine/Ketsji/BL_Action.h
+++ /dev/null
@@ -1,151 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_Action.h
- * \ingroup ketsji
- */
-
-#ifndef __BL_ACTION_H__
-#define __BL_ACTION_H__
-
-
-#include <vector>
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class BL_Action
-{
-private:
- struct bAction* m_action;
- struct bAction* m_tmpaction;
- struct bPose* m_blendpose;
- struct bPose* m_blendinpose;
- std::vector<class SG_Controller*> m_sg_contr_list;
- class KX_GameObject* m_obj;
- std::vector<float> m_blendshape;
- std::vector<float> m_blendinshape;
-
- float m_startframe;
- float m_endframe;
- /// The current action frame.
- float m_localframe;
- float m_starttime;
-
- float m_blendin;
- float m_blendframe;
- float m_blendstart;
-
- float m_layer_weight;
-
- float m_speed;
-
- short m_priority;
-
- short m_playmode;
- short m_blendmode;
-
- short m_ipo_flags;
-
- bool m_done;
- bool m_calc_localtime;
- /// Set to true when m_starttime is initialized in Update.
- bool m_initializedTime;
-
- void ClearControllerList();
- void InitIPO();
- void SetLocalTime(float curtime);
- void ResetStartTime(float curtime);
- void IncrementBlending(float curtime);
- void BlendShape(struct Key* key, float srcweight, std::vector<float>& blendshape);
-public:
- BL_Action(class KX_GameObject* gameobj);
- ~BL_Action();
-
- /**
- * Play an action
- */
- bool Play(const char* name,
- float start,
- float end,
- short priority,
- float blendin,
- short play_mode,
- float layer_weight,
- short ipo_flags,
- float playback_speed,
- short blend_mode);
- /**
- * Whether or not the action is still playing
- */
- bool IsDone();
- /**
- * Update the action's frame, etc.
- */
- void Update(float curtime);
-
- // Accessors
- float GetFrame();
- const char *GetName();
-
- struct bAction *GetAction();
-
- // Mutators
- void SetFrame(float frame);
- void SetPlayMode(short play_mode);
- void SetTimes(float start, float end);
-
- enum
- {
- ACT_MODE_PLAY = 0,
- ACT_MODE_LOOP,
- ACT_MODE_PING_PONG,
- ACT_MODE_MAX,
- };
-
- enum
- {
- ACT_BLEND_BLEND=0,
- ACT_BLEND_ADD=1,
- ACT_BLEND_MAX,
- };
-
- enum
- {
- ACT_IPOFLAG_FORCE = 1,
- ACT_IPOFLAG_LOCAL = 2,
- ACT_IPOFLAG_ADD = 4,
- ACT_IPOFLAG_CHILD = 8,
- };
-
- /// Initialize a lock for animation thread issues.
- static void InitLock();
- /// Finalize a lock for animation thread issues.
- static void EndLock();
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_Action")
-#endif
-};
-
-#endif /* BL_ACTION */
diff --git a/source/gameengine/Ketsji/BL_ActionManager.cpp b/source/gameengine/Ketsji/BL_ActionManager.cpp
deleted file mode 100644
index 35f605f1a5f..00000000000
--- a/source/gameengine/Ketsji/BL_ActionManager.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ActionManager.cpp
- * \ingroup ketsji
- */
-
-#include "BL_Action.h"
-#include "BL_ActionManager.h"
-#include "DNA_ID.h"
-
-#define IS_TAGGED(_id) ((_id) && (((ID *)_id)->tag & LIB_TAG_DOIT))
-
-BL_ActionManager::BL_ActionManager(class KX_GameObject *obj):
- m_obj(obj),
- m_prevUpdate(-1.0f)
-{
-}
-
-BL_ActionManager::~BL_ActionManager()
-{
- BL_ActionMap::iterator it;
-
- for (it = m_layers.begin(); it != m_layers.end(); it++)
- delete it->second;
-
- m_layers.clear();
-}
-
-BL_Action *BL_ActionManager::GetAction(short layer)
-{
- BL_ActionMap::iterator it = m_layers.find(layer);
-
- return (it != m_layers.end()) ? it->second : 0;
-}
-
-float BL_ActionManager::GetActionFrame(short layer)
-{
- BL_Action *action = GetAction(layer);
-
- return action ? action->GetFrame() : 0.f;
-}
-
-const char *BL_ActionManager::GetActionName(short layer)
-{
- BL_Action *action = GetAction(layer);
- return action ? action->GetName() : "";
-}
-
-void BL_ActionManager::SetActionFrame(short layer, float frame)
-{
- BL_Action *action = GetAction(layer);
-
- if (action) action->SetFrame(frame);
-}
-
-struct bAction *BL_ActionManager::GetCurrentAction(short layer)
-{
- BL_Action *action = GetAction(layer);
-
- return action ? action->GetAction() : 0;
-}
-
-void BL_ActionManager::SetPlayMode(short layer, short mode)
-{
- BL_Action *action = GetAction(layer);
-
- if (action) action->SetPlayMode(mode);
-}
-
-void BL_ActionManager::SetTimes(short layer, float start, float end)
-{
- BL_Action *action = GetAction(layer);
-
- if (action) action->SetTimes(start, end);
-}
-
-bool BL_ActionManager::PlayAction(const char* name,
- float start,
- float end,
- short layer,
- short priority,
- float blendin,
- short play_mode,
- float layer_weight,
- short ipo_flags,
- float playback_speed,
- short blend_mode)
-{
- // Only this method will create layer if non-existent
- BL_Action *action = GetAction(layer);
- if (!action) {
- action = new BL_Action(m_obj);
- m_layers[layer] = action;
- }
-
- // Disable layer blending on the first layer
- if (layer == 0) layer_weight = -1.f;
-
- return action->Play(name, start, end, priority, blendin, play_mode, layer_weight, ipo_flags, playback_speed, blend_mode);
-}
-
-void BL_ActionManager::StopAction(short layer)
-{
- BL_Action *action = GetAction(layer);
-
- if (action) {
- m_layers.erase(layer);
- delete action;
- }
-}
-
-void BL_ActionManager::RemoveTaggedActions()
-{
- for (BL_ActionMap::iterator it = m_layers.begin(); it != m_layers.end();) {
- if (IS_TAGGED(it->second->GetAction())) {
- delete it->second;
- m_layers.erase(it++);
- }
- else
- ++it;
- }
-}
-
-bool BL_ActionManager::IsActionDone(short layer)
-{
- BL_Action *action = GetAction(layer);
-
- return action ? action->IsDone() : true;
-}
-
-void BL_ActionManager::Update(float curtime)
-{
- if (m_prevUpdate == curtime)
- return;
- m_prevUpdate = curtime;
-
- BL_ActionMap::iterator it;
- for (it = m_layers.begin(); it != m_layers.end(); ++it)
- {
- if (!it->second->IsDone()) {
- it->second->Update(curtime);
- }
- }
-}
diff --git a/source/gameengine/Ketsji/BL_ActionManager.h b/source/gameengine/Ketsji/BL_ActionManager.h
deleted file mode 100644
index 69c6d611df0..00000000000
--- a/source/gameengine/Ketsji/BL_ActionManager.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Mitchell Stokes.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_ActionManager.h
- * \ingroup ketsji
- */
-
-#ifndef __BL_ACTIONMANAGER_H__
-#define __BL_ACTIONMANAGER_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
- #include "MEM_guardedalloc.h"
-#endif
-
-#include <map>
-
-// Currently, we use the max value of a short.
-// We should switch to unsigned short; doesn't make sense to support negative layers.
-// This will also give us 64k layers instead of 32k.
-#define MAX_ACTION_LAYERS 32767
-
-class BL_Action;
-
-/**
- * BL_ActionManager is responsible for handling a KX_GameObject's actions.
- */
-class BL_ActionManager
-{
-private:
- typedef std::map<short,BL_Action*> BL_ActionMap;
-
- class KX_GameObject* m_obj;
- BL_ActionMap m_layers;
-
- // The last update time to avoid double animation update.
- float m_prevUpdate;
-
- /**
- * Check if an action exists
- */
- BL_Action* GetAction(short layer);
-
-public:
- BL_ActionManager(class KX_GameObject* obj);
- ~BL_ActionManager();
-
- bool PlayAction(const char* name,
- float start,
- float end,
- short layer=0,
- short priority=0,
- float blendin=0.f,
- short play_mode=0,
- float layer_weight=0.f,
- short ipo_flags=0,
- float playback_speed=1.f,
- short blend_mode=0);
- /**
- * Gets the current frame of an action
- */
- float GetActionFrame(short layer);
-
- /**
- * Gets the name of the current action
- */
- const char *GetActionName(short layer);
-
- /**
- * Sets the current frame of an action
- */
- void SetActionFrame(short layer, float frame);
-
- /**
- * Gets the currently running action on the given layer
- */
- struct bAction *GetCurrentAction(short layer);
-
- /**
- * Sets play mode of the action on the given layer
- */
- void SetPlayMode(short layer, short mode);
-
- /**
- * Sets the start and end times of the action on the given layer
- */
- void SetTimes(short layer, float start, float end);
-
- /**
- * Stop playing the action on the given layer
- */
- void StopAction(short layer);
-
- /**
- * Remove playing tagged actions.
- */
- void RemoveTaggedActions();
-
- /**
- * Check if an action has finished playing
- */
- bool IsActionDone(short layer);
-
- /**
- * Update any running actions
- */
- void Update(float);
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_ActionManager")
-#endif
-};
-
-#endif /* BL_ACTIONMANAGER */
diff --git a/source/gameengine/Ketsji/BL_BlenderShader.cpp b/source/gameengine/Ketsji/BL_BlenderShader.cpp
deleted file mode 100644
index 9cbd61590b6..00000000000
--- a/source/gameengine/Ketsji/BL_BlenderShader.cpp
+++ /dev/null
@@ -1,188 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/BL_BlenderShader.cpp
- * \ingroup ketsji
- */
-
-#include "DNA_customdata_types.h"
-#include "DNA_material_types.h"
-#include "DNA_scene_types.h"
-
-#include "BLI_utildefines.h"
-
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_DerivedMesh.h"
-
-#include "BL_BlenderShader.h"
-#include "BL_Material.h"
-
-#include "GPU_material.h"
-#include "GPU_shader.h"
-
-#include "RAS_BucketManager.h"
-#include "RAS_MeshObject.h"
-#include "RAS_IRasterizer.h"
-
-BL_BlenderShader::BL_BlenderShader(KX_Scene *scene, struct Material *ma, int lightlayer)
-:
- mMat(ma),
- mLightLayer(lightlayer),
- mGPUMat(NULL)
-{
- mBlenderScene = scene->GetBlenderScene();
- mAlphaBlend = GPU_BLEND_SOLID;
-
- ReloadMaterial();
-}
-
-BL_BlenderShader::~BL_BlenderShader()
-{
- if (mGPUMat)
- GPU_material_unbind(mGPUMat);
-}
-
-void BL_BlenderShader::ReloadMaterial()
-{
- mGPUMat = (mMat) ? GPU_material_from_blender(mBlenderScene, mMat, false) : NULL;
-}
-
-void BL_BlenderShader::SetProg(bool enable, double time, RAS_IRasterizer* rasty)
-{
- if (VerifyShader()) {
- if (enable) {
- assert(rasty != NULL); // XXX Kinda hacky, but SetProg() should always have the rasterizer if enable is true
-
- float viewmat[4][4], viewinvmat[4][4];
- const MT_Matrix4x4& view = rasty->GetViewMatrix();
- const MT_Matrix4x4& viewinv = rasty->GetViewInvMatrix();
- view.getValue(&viewmat[0][0]);
- viewinv.getValue(&viewinvmat[0][0]);
-
- GPU_material_bind(mGPUMat, mLightLayer, mBlenderScene->lay, time, 1, viewmat, viewinvmat, NULL, false);
- }
- else
- GPU_material_unbind(mGPUMat);
- }
-}
-
-int BL_BlenderShader::GetAttribNum()
-{
- GPUVertexAttribs attribs;
- int i, enabled = 0;
-
- if (!VerifyShader())
- return enabled;
-
- GPU_material_vertex_attributes(mGPUMat, &attribs);
-
- for (i = 0; i < attribs.totlayer; i++)
- if (attribs.layer[i].glindex+1 > enabled)
- enabled= attribs.layer[i].glindex+1;
-
- if (enabled > BL_MAX_ATTRIB)
- enabled = BL_MAX_ATTRIB;
-
- return enabled;
-}
-
-void BL_BlenderShader::SetAttribs(RAS_IRasterizer* ras, const BL_Material *mat)
-{
- GPUVertexAttribs attribs;
- GPUMaterial *gpumat;
- int i, attrib_num, uv = 0;
-
- ras->SetAttribNum(0);
-
- if (!VerifyShader())
- return;
-
- gpumat = mGPUMat;
- if (ras->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED || (ras->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW &&
- mat->alphablend != GEMAT_SOLID && !ras->GetUsingOverrideShader())) {
- GPU_material_vertex_attributes(gpumat, &attribs);
- attrib_num = GetAttribNum();
-
- ras->SetTexCoordNum(0);
- ras->SetAttribNum(attrib_num);
- for (i = 0; i < attrib_num; i++)
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_DISABLE, i);
-
- for (i = 0; i < attribs.totlayer; i++) {
- if (attribs.layer[i].glindex > attrib_num)
- continue;
-
- if (attribs.layer[i].type == CD_MTFACE)
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_UV, attribs.layer[i].glindex, uv++);
- else if (attribs.layer[i].type == CD_TANGENT)
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT, attribs.layer[i].glindex);
- else if (attribs.layer[i].type == CD_ORCO)
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_ORCO, attribs.layer[i].glindex);
- else if (attribs.layer[i].type == CD_NORMAL)
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_NORM, attribs.layer[i].glindex);
- else if (attribs.layer[i].type == CD_MCOL)
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_VCOL, attribs.layer[i].glindex);
- else
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_DISABLE, attribs.layer[i].glindex);
- }
- }
-}
-
-void BL_BlenderShader::Update(const RAS_MeshSlot & ms, RAS_IRasterizer* rasty )
-{
- float obmat[4][4], viewmat[4][4], obcol[4];
- GPUMaterial *gpumat;
-
- gpumat = mGPUMat;
-
- if (!gpumat || !GPU_material_bound(gpumat))
- return;
-
- MT_Matrix4x4 model;
- model.setValue(ms.m_OpenGLMatrix);
-
- // note: getValue gives back column major as needed by OpenGL
- model.getValue(&obmat[0][0]);
-
- if (ms.m_bObjectColor)
- ms.m_RGBAcolor.getValue(&obcol[0]);
- else
- obcol[0] = obcol[1] = obcol[2] = obcol[3] = 1.0f;
-
- rasty->GetViewMatrix().getValue(&viewmat[0][0]);
- float auto_bump_scale = ms.m_pDerivedMesh!=0 ? ms.m_pDerivedMesh->auto_bump_scale : 1.0f;
- GPU_material_bind_uniforms(gpumat, obmat, viewmat, obcol, auto_bump_scale, NULL, NULL);
-
- mAlphaBlend = GPU_material_alpha_blend(gpumat, obcol);
-}
-
-int BL_BlenderShader::GetAlphaBlend()
-{
- return mAlphaBlend;
-}
-
-bool BL_BlenderShader::Equals(BL_BlenderShader *blshader)
-{
- /* to avoid unneeded state switches */
- return (blshader && mMat == blshader->mMat && mLightLayer == blshader->mLightLayer);
-}
-
-// eof
diff --git a/source/gameengine/Ketsji/BL_BlenderShader.h b/source/gameengine/Ketsji/BL_BlenderShader.h
deleted file mode 100644
index e03bb5a11d9..00000000000
--- a/source/gameengine/Ketsji/BL_BlenderShader.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BL_BlenderShader.h
- * \ingroup ketsji
- */
-
-#ifndef __BL_BLENDERSHADER_H__
-#define __BL_BLENDERSHADER_H__
-
-#include "GPU_material.h"
-
-#include "MT_Matrix4x4.h"
-#include "MT_Matrix3x3.h"
-#include "MT_Tuple2.h"
-#include "MT_Tuple3.h"
-#include "MT_Tuple4.h"
-
-#include "RAS_IPolygonMaterial.h"
-
-#include "KX_Scene.h"
-
-struct Material;
-struct Scene;
-class BL_Material;
-
-#define BL_MAX_ATTRIB 16
-
-/**
- * BL_BlenderShader
- * Blender GPU shader material
- */
-class BL_BlenderShader
-{
-private:
- struct Scene *mBlenderScene;
- struct Material *mMat;
- int mLightLayer;
- int mAlphaBlend;
- GPUMaterial *mGPUMat;
-
- bool VerifyShader()
- {
- return (NULL != mGPUMat);
- }
-
-public:
- BL_BlenderShader(KX_Scene *scene, struct Material *ma, int lightlayer);
- virtual ~BL_BlenderShader();
-
- bool Ok()
- {
- // same as VerifyShared
- return (NULL != mGPUMat);
- }
- void SetProg(bool enable, double time=0.0, RAS_IRasterizer* rasty=NULL);
-
- int GetAttribNum();
- void SetAttribs(class RAS_IRasterizer* ras, const BL_Material *mat);
- void Update(const class RAS_MeshSlot & ms, class RAS_IRasterizer* rasty);
- void ReloadMaterial();
- int GetAlphaBlend();
-
- bool Equals(BL_BlenderShader *blshader);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_BlenderShader")
-#endif
-};
-
-#endif /* __BL_BLENDERSHADER_H__ */
diff --git a/source/gameengine/Ketsji/BL_Material.cpp b/source/gameengine/Ketsji/BL_Material.cpp
deleted file mode 100644
index 4f707e6267f..00000000000
--- a/source/gameengine/Ketsji/BL_Material.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/BL_Material.cpp
- * \ingroup ketsji
- */
-
-#include "BL_Material.h"
-#include "DNA_material_types.h"
-#include "DNA_texture_types.h"
-#include "DNA_image_types.h"
-#include "DNA_mesh_types.h"
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-
-MTex* getMTexFromMaterial(Material *mat, int index)
-{
- if (mat && (index >= 0) && (index < MAX_MTEX)) {
- return mat->mtex[index];
- }
- else {
- return NULL;
- }
-}
-
-BL_Material::BL_Material()
-{
- Initialize();
-}
-
-void BL_Material::Initialize()
-{
- rgb[0] = 0xFFFFFFFFL;
- rgb[1] = 0xFFFFFFFFL;
- rgb[2] = 0xFFFFFFFFL;
- rgb[3] = 0xFFFFFFFFL;
- IdMode = 0;
- ras_mode = 0;
- glslmat = 0;
- tile = 0;
- matname = "NoMaterial";
- matcolor[0] = 0.5f;
- matcolor[1] = 0.5f;
- matcolor[2] = 0.5f;
- matcolor[3] = 0.5f;
- speccolor[0] = 1.f;
- speccolor[1] = 1.f;
- speccolor[2] = 1.f;
- alphablend = 0;
- hard = 50.f;
- spec_f = 0.5f;
- alpha = 1.f;
- emit = 0.f;
- material = 0;
- memset(&mtexpoly, 0, sizeof(mtexpoly));
- materialindex = 0;
- amb=0.5f;
- num_enabled = 0;
- num_users = 1;
- share = false;
-
- int i;
-
- for (i = 0; i < MAXTEX; i++) // :(
- {
- mapping[i].mapping = 0;
- mapping[i].offsets[0] = 0.f;
- mapping[i].offsets[1] = 0.f;
- mapping[i].offsets[2] = 0.f;
- mapping[i].scale[0] = 1.f;
- mapping[i].scale[1] = 1.f;
- mapping[i].scale[2] = 1.f;
- mapping[i].projplane[0] = PROJX;
- mapping[i].projplane[1] = PROJY;
- mapping[i].projplane[2] = PROJZ;
- mapping[i].objconame = "";
- mtexname[i] = "NULL";
- imageId[i]="NULL";
- flag[i] = 0;
- texname[i] = "NULL";
- tilexrep[i] = 1;
- tileyrep[i] = 1;
- color_blend[i] = 1.f;
- blend_mode[i] = 0;
- img[i] = 0;
- cubemap[i] = 0;
- }
-}
-
-void BL_Material::SetSharedMaterial(bool v)
-{
- if ((v && num_users == -1) || num_users > 1 )
- share = true;
- else
- share = false;
-}
-
-bool BL_Material::IsShared()
-{
- return share;
-}
-
-void BL_Material::SetUsers(int num)
-{
- num_users = num;
-}
-
diff --git a/source/gameengine/Ketsji/BL_Material.h b/source/gameengine/Ketsji/BL_Material.h
deleted file mode 100644
index 9207a41f56d..00000000000
--- a/source/gameengine/Ketsji/BL_Material.h
+++ /dev/null
@@ -1,183 +0,0 @@
-
-/** \file BL_Material.h
- * \ingroup ketsji
- */
-
-#ifndef __BL_MATERIAL_H__
-#define __BL_MATERIAL_H__
-
-#include "STR_String.h"
-#include "MT_Point2.h"
-#include "DNA_meshdata_types.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-// --
-struct MTex;
-struct Material;
-struct Image;
-struct MTFace;
-struct MTex;
-struct Material;
-struct EnvMap;
-// --
-
-/** max units
- * this will default to users available units
- * to build with more available, just increment this value
- * although the more you add the slower the search time will be.
- * we will go for eight, which should be enough
- */
-#define MAXTEX 8 //match in RAS_TexVert & RAS_OpenGLRasterizer
-
-// different mapping modes
-class BL_Mapping
-{
-public:
- int mapping;
- float scale[3];
- float offsets[3];
- int projplane[3];
- STR_String objconame;
- STR_String uvCoName;
-};
-
-// base material struct
-class BL_Material
-{
-private:
- int num_users;
- bool share;
-
-public:
- // -----------------------------------
- BL_Material();
- void Initialize();
-
- int IdMode;
- unsigned int ras_mode;
- bool glslmat;
-
- STR_String texname[MAXTEX];
- unsigned int flag[MAXTEX];
- int tile,tilexrep[MAXTEX],tileyrep[MAXTEX];
- STR_String matname;
- STR_String mtexname[MAXTEX];
- int materialindex;
-
- float matcolor[4];
- float speccolor[3];
- short alphablend, pad;
-
- float hard, spec_f;
- float alpha, emit, color_blend[MAXTEX], ref;
- float amb;
-
- int blend_mode[MAXTEX];
-
- int num_enabled;
-
- BL_Mapping mapping[MAXTEX];
- STR_String imageId[MAXTEX];
-
-
- Material* material;
- MTexPoly mtexpoly; /* copy of the derived meshes tface */
- Image* img[MAXTEX];
- EnvMap* cubemap[MAXTEX];
-
- unsigned int rgb[4];
-
- void SetSharedMaterial(bool v);
- bool IsShared();
- void SetUsers(int num);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_Material")
-#endif
-};
-
-// BL_Material::IdMode
-enum BL_IdMode {
- DEFAULT_BLENDER=-1,
- TEXFACE,
- ONETEX,
- TWOTEX,
- GREATERTHAN2
-};
-
-// BL_Material::blend_mode[index]
-enum BL_BlendMode
-{
- BLEND_MIX=1,
- BLEND_ADD,
- BLEND_SUB,
- BLEND_MUL,
- BLEND_SCR
-};
-
-// -------------------------------------
-// BL_Material::flag[index]
-enum BL_flag
-{
- MIPMAP=1, // set to use mipmaps
- CALCALPHA=2, // additive
- USEALPHA=4, // use actual alpha channel
- TEXALPHA=8, // use alpha combiner functions
- TEXNEG=16, // negate blending
- /*HASIPO=32,*/ // unused, commeted for now.
- USENEGALPHA=64
-};
-
-// BL_Material::ras_mode
-enum BL_ras_mode
-{
- // POLY_VIS=1,
- COLLIDER=2,
- ZSORT=4,
- ALPHA=8,
- // TRIANGLE=16,
- USE_LIGHT=32,
- WIRE=64,
- CAST_SHADOW=128,
- TEX=256,
- TWOSIDED=512,
- ONLY_SHADOW=1024,
-};
-
-// -------------------------------------
-// BL_Material::mapping[index]::mapping
-enum BL_MappingFlag
-{
- USEENV =1,
- // --
- USEREFL =2,
- USEOBJ =4,
- USENORM =8,
- USEORCO =16,
- USEUV =32,
- USETANG =64,
- DISABLE =128,
- USECUSTOMUV=256
-};
-
-// BL_Material::BL_Mapping::projplane
-enum BL_MappingProj
-{
- PROJN=0,
- PROJX,
- PROJY,
- PROJZ
-};
-
-// ------------------------------------
-//extern void initBL_Material(BL_Material* mat);
-extern MTex* getMTexFromMaterial(Material *mat, int index);
-// ------------------------------------
-
-#endif
-
-
diff --git a/source/gameengine/Ketsji/BL_Shader.cpp b/source/gameengine/Ketsji/BL_Shader.cpp
deleted file mode 100644
index d344e18c313..00000000000
--- a/source/gameengine/Ketsji/BL_Shader.cpp
+++ /dev/null
@@ -1,1478 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/BL_Shader.cpp
- * \ingroup ketsji
- */
-
-#include "GPU_glew.h"
-
-#include <iostream>
-#include "BL_Shader.h"
-#include "BL_Material.h"
-
-#include "MT_assert.h"
-#include "MT_Matrix4x4.h"
-#include "MT_Matrix3x3.h"
-#include "KX_PyMath.h"
-#include "KX_PythonInit.h"
-#include "MEM_guardedalloc.h"
-
-#include "RAS_MeshObject.h"
-#include "RAS_IRasterizer.h"
-
-#define spit(x) std::cout << x << std::endl;
-
-#define SORT_UNIFORMS 1
-#define UNIFORM_MAX_LEN (int)sizeof(float) * 16
-#define MAX_LOG_LEN 262144 // bounds
-
-BL_Uniform::BL_Uniform(int data_size)
- :
- mLoc(-1),
- mDirty(true),
- mType(UNI_NONE),
- mTranspose(0),
- mDataLen(data_size)
-{
-#ifdef SORT_UNIFORMS
- MT_assert((int)mDataLen <= UNIFORM_MAX_LEN);
- mData = (void *)MEM_mallocN(mDataLen, "shader-uniform-alloc");
-#endif
-}
-
-BL_Uniform::~BL_Uniform()
-{
-#ifdef SORT_UNIFORMS
- if (mData) {
- MEM_freeN(mData);
- mData = NULL;
- }
-#endif
-}
-
-bool BL_Uniform::Apply(class BL_Shader *shader)
-{
-#ifdef SORT_UNIFORMS
- RAS_IRasterizer *ras;
- MT_assert(mType > UNI_NONE && mType < UNI_MAX && mData);
-
- if (!mDirty)
- return false;
-
- mDirty = false;
- switch (mType) {
- case UNI_FLOAT:
- {
- float *f = (float *)mData;
- glUniform1fARB(mLoc, (GLfloat)*f);
- break;
- }
- case UNI_FLOAT_EYE:
- {
- float *f = (float*)mData;
- ras = KX_GetActiveEngine()->GetRasterizer();
- *f = (ras->GetEye() == RAS_IRasterizer::RAS_STEREO_LEFTEYE) ? 0.0f : 0.5f;
- glUniform1fARB(mLoc, (GLfloat)*f);
- mDirty = (ras->Stereo()) ? true : false;
- break;
- }
- case UNI_INT:
- {
- int *f = (int *)mData;
- glUniform1iARB(mLoc, (GLint)*f);
- break;
- }
- case UNI_FLOAT2:
- {
- float *f = (float *)mData;
- glUniform2fvARB(mLoc, 1, (GLfloat *)f);
- break;
- }
- case UNI_FLOAT3:
- {
- float *f = (float *)mData;
- glUniform3fvARB(mLoc, 1, (GLfloat *)f);
- break;
- }
- case UNI_FLOAT4:
- {
- float *f = (float *)mData;
- glUniform4fvARB(mLoc, 1, (GLfloat *)f);
- break;
- }
- case UNI_INT2:
- {
- int *f = (int *)mData;
- glUniform2ivARB(mLoc, 1, (GLint *)f);
- break;
- }
- case UNI_INT3:
- {
- int *f = (int *)mData;
- glUniform3ivARB(mLoc, 1, (GLint *)f);
- break;
- }
- case UNI_INT4:
- {
- int *f = (int *)mData;
- glUniform4ivARB(mLoc, 1, (GLint *)f);
- break;
- }
- case UNI_MAT4:
- {
- float *f = (float *)mData;
- glUniformMatrix4fvARB(mLoc, 1, mTranspose ? GL_TRUE : GL_FALSE, (GLfloat *)f);
- break;
- }
- case UNI_MAT3:
- {
- float *f = (float *)mData;
- glUniformMatrix3fvARB(mLoc, 1, mTranspose ? GL_TRUE : GL_FALSE, (GLfloat *)f);
- break;
- }
- }
- return mDirty;
-#endif
-}
-
-void BL_Uniform::SetData(int location, int type, bool transpose)
-{
-#ifdef SORT_UNIFORMS
- mType = type;
- mLoc = location;
- mDirty = true;
-#endif
-}
-
-bool BL_Shader::Ok()const
-{
- return (mShader != 0 && mOk && mUse);
-}
-
-BL_Shader::BL_Shader()
- :
- PyObjectPlus(),
- mShader(0),
- mPass(1),
- mOk(0),
- mUse(0),
- mAttr(0),
- vertProg(NULL),
- fragProg(NULL),
- mError(0),
- mDirty(true)
-{
- // if !GLEW_ARB_shader_objects this class will not be used
- //for (int i=0; i<MAXTEX; i++) {
- // mSampler[i] = BL_Sampler();
- //}
-}
-
-BL_Shader::~BL_Shader()
-{
- //for (int i=0; i<MAXTEX; i++) {
- // if (mSampler[i].mOwn) {
- // if (mSampler[i].mTexture)
- // mSampler[i].mTexture->DeleteTex();
- // }
- //}
- ClearUniforms();
-
- if (mShader) {
- glDeleteObjectARB(mShader);
- mShader = 0;
- }
-
- vertProg = NULL;
- fragProg = NULL;
- mOk = 0;
- glUseProgramObjectARB(0);
-}
-
-void BL_Shader::ClearUniforms()
-{
- BL_UniformVec::iterator it = mUniforms.begin();
- while (it != mUniforms.end()) {
- delete *it;
- it++;
- }
- mUniforms.clear();
-
- BL_UniformVecDef::iterator itp = mPreDef.begin();
- while (itp != mPreDef.end()) {
- delete *itp;
- itp++;
- }
- mPreDef.clear();
-}
-
-BL_Uniform *BL_Shader::FindUniform(const int location)
-{
-#ifdef SORT_UNIFORMS
- BL_UniformVec::iterator it = mUniforms.begin();
- while (it != mUniforms.end()) {
- if ((*it)->GetLocation() == location) {
- return *it;
- }
- it++;
- }
-#endif
- return NULL;
-}
-
-void BL_Shader::SetUniformfv(int location, int type, float *param, int size, bool transpose)
-{
-#ifdef SORT_UNIFORMS
- BL_Uniform *uni = FindUniform(location);
-
- if (uni) {
- memcpy(uni->getData(), param, size);
- uni->SetData(location, type, transpose);
- }
- else {
- uni = new BL_Uniform(size);
- memcpy(uni->getData(), param, size);
- uni->SetData(location, type, transpose);
- mUniforms.push_back(uni);
- }
-
- mDirty = true;
-#endif
-}
-
-void BL_Shader::SetUniformiv(int location, int type, int *param, int size, bool transpose)
-{
-#ifdef SORT_UNIFORMS
- BL_Uniform *uni = FindUniform(location);
-
- if (uni) {
- memcpy(uni->getData(), param, size);
- uni->SetData(location, type, transpose);
- }
- else {
- uni = new BL_Uniform(size);
- memcpy(uni->getData(), param, size);
- uni->SetData(location, type, transpose);
- mUniforms.push_back(uni);
- }
-
- mDirty = true;
-#endif
-}
-
-void BL_Shader::ApplyShader()
-{
-#ifdef SORT_UNIFORMS
- if (!mDirty) {
- return;
- }
-
- mDirty = false;
- for (unsigned int i=0; i<mUniforms.size(); i++) {
- mDirty |= mUniforms[i]->Apply(this);
- }
-#endif
-}
-
-void BL_Shader::UnloadShader()
-{
- //
-}
-
-bool BL_Shader::LinkProgram()
-{
- int vertlen = 0, fraglen = 0, proglen = 0;
- int vertstatus = 0, fragstatus = 0, progstatus = 0;
- unsigned int tmpVert = 0, tmpFrag = 0, tmpProg = 0;
- int char_len = 0;
- char *logInf = NULL;
-
- if (mError) {
- goto programError;
- }
-
- if (!vertProg || !fragProg) {
- spit("Invalid GLSL sources");
- return false;
- }
-
- if (!GLEW_ARB_fragment_shader) {
- spit("Fragment shaders not supported");
- return false;
- }
-
- if (!GLEW_ARB_vertex_shader) {
- spit("Vertex shaders not supported");
- return false;
- }
-
- if (vertProg[0] != 0) {
- // -- vertex shader ------------------
- tmpVert = glCreateShaderObjectARB(GL_VERTEX_SHADER_ARB);
- glShaderSourceARB(tmpVert, 1, (const char**)&vertProg, 0);
- glCompileShaderARB(tmpVert);
- glGetObjectParameterivARB(tmpVert, GL_OBJECT_INFO_LOG_LENGTH_ARB, (GLint*)&vertlen);
-
- // print info if any
- if (vertlen > 0 && vertlen < MAX_LOG_LEN) {
- logInf = (char*)MEM_mallocN(vertlen, "vert-log");
- glGetInfoLogARB(tmpVert, vertlen, (GLsizei*)&char_len, logInf);
- if (char_len > 0) {
- spit("---- Vertex Shader Error ----");
- spit(logInf);
- }
- MEM_freeN(logInf);
- logInf = 0;
- }
- // check for compile errors
- glGetObjectParameterivARB(tmpVert, GL_OBJECT_COMPILE_STATUS_ARB, (GLint*)&vertstatus);
- if (!vertstatus) {
- spit("---- Vertex shader failed to compile ----");
- goto programError;
- }
- }
-
- if (fragProg[0] != 0) {
- // -- fragment shader ----------------
- tmpFrag = glCreateShaderObjectARB(GL_FRAGMENT_SHADER_ARB);
- glShaderSourceARB(tmpFrag, 1, (const char**)&fragProg, 0);
- glCompileShaderARB(tmpFrag);
- glGetObjectParameterivARB(tmpFrag, GL_OBJECT_INFO_LOG_LENGTH_ARB, (GLint*)&fraglen);
- if (fraglen > 0 && fraglen < MAX_LOG_LEN) {
- logInf = (char*)MEM_mallocN(fraglen, "frag-log");
- glGetInfoLogARB(tmpFrag, fraglen, (GLsizei*)&char_len, logInf);
- if (char_len > 0) {
- spit("---- Fragment Shader Error ----");
- spit(logInf);
- }
- MEM_freeN(logInf);
- logInf = 0;
- }
-
- glGetObjectParameterivARB(tmpFrag, GL_OBJECT_COMPILE_STATUS_ARB, (GLint*)&fragstatus);
- if (!fragstatus) {
- spit("---- Fragment shader failed to compile ----");
- goto programError;
- }
- }
-
- if (!tmpFrag && !tmpVert) {
- spit("---- No shader given ----");
- goto programError;
- }
-
- // -- program ------------------------
- // set compiled vert/frag shader & link
- tmpProg = glCreateProgramObjectARB();
- if (tmpVert) {
- glAttachObjectARB(tmpProg, tmpVert);
- }
- if (tmpFrag) {
- glAttachObjectARB(tmpProg, tmpFrag);
- }
- glLinkProgramARB(tmpProg);
- glGetObjectParameterivARB(tmpProg, GL_OBJECT_INFO_LOG_LENGTH_ARB, (GLint *)&proglen);
- glGetObjectParameterivARB(tmpProg, GL_OBJECT_LINK_STATUS_ARB, (GLint *)&progstatus);
-
- if (proglen > 0 && proglen < MAX_LOG_LEN) {
- logInf = (char *)MEM_mallocN(proglen, "prog-log");
- glGetInfoLogARB(tmpProg, proglen, (GLsizei *)&char_len, logInf);
-
- if (char_len > 0) {
- spit("---- GLSL Program ----");
- spit(logInf);
- }
-
- MEM_freeN(logInf);
- logInf = 0;
- }
-
- if (!progstatus) {
- spit("---- GLSL program failed to link ----");
- goto programError;
- }
-
- // set
- mShader = tmpProg;
- if (tmpVert) {
- glDeleteObjectARB(tmpVert);
- }
- if (tmpFrag) {
- glDeleteObjectARB(tmpFrag);
- }
- mOk = 1;
- mError = 0;
- return true;
-
-programError:
- if (tmpVert) {
- glDeleteObjectARB(tmpVert);
- tmpVert = 0;
- }
-
- if (tmpFrag) {
- glDeleteObjectARB(tmpFrag);
- tmpFrag = 0;
- }
-
- if (tmpProg) {
- glDeleteObjectARB(tmpProg);
- tmpProg = 0;
- }
-
- mOk = 0;
- mUse = 0;
- mError = 1;
- return false;
-}
-
-const char *BL_Shader::GetVertPtr()
-{
- return vertProg ? vertProg : NULL;
-}
-
-const char *BL_Shader::GetFragPtr()
-{
- return fragProg ? fragProg : NULL;
-}
-
-void BL_Shader::SetVertPtr(char *vert)
-{
- vertProg = vert;
-}
-
-void BL_Shader::SetFragPtr(char *frag)
-{
- fragProg = frag;
-}
-
-unsigned int BL_Shader::GetProg()
-{
- return mShader;
-}
-
-//const BL_Sampler *BL_Shader::GetSampler(int i)
-//{
-// MT_assert(i<=MAXTEX);
-// return &mSampler[i];
-//}
-
-void BL_Shader::SetSampler(int loc, int unit)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- glUniform1iARB(loc, unit);
- }
-}
-
-//void BL_Shader::InitializeSampler(int unit, BL_Texture *texture)
-//{
-// MT_assert(unit <= MAXTEX);
-// mSampler[unit].mTexture = texture;
-// mSampler[unit].mLoc = -1;
-// mSampler[unit].mOwn = 0;
-//}
-
-void BL_Shader::SetProg(bool enable)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- if (mShader != 0 && mOk && enable) {
- glUseProgramObjectARB(mShader);
- }
- else {
- glUseProgramObjectARB(0);
- }
- }
-}
-
-void BL_Shader::Update(const RAS_MeshSlot &ms, RAS_IRasterizer *rasty)
-{
- if (!Ok() || !mPreDef.size()) {
- return;
- }
-
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- MT_Matrix4x4 model;
- model.setValue(ms.m_OpenGLMatrix);
- const MT_Matrix4x4 &view = rasty->GetViewMatrix();
-
- if (mAttr == SHD_TANGENT) {
- ms.m_mesh->SetMeshModified(true);
- }
-
- BL_UniformVecDef::iterator it;
- for (it = mPreDef.begin(); it != mPreDef.end(); it++) {
- BL_DefUniform *uni = (*it);
-
- if (uni->mLoc == -1) {
- continue;
- }
-
- switch (uni->mType) {
- case MODELMATRIX:
- {
- SetUniform(uni->mLoc, model);
- break;
- }
- case MODELMATRIX_TRANSPOSE:
- {
- SetUniform(uni->mLoc, model, true);
- break;
- }
- case MODELMATRIX_INVERSE:
- {
- model.invert();
- SetUniform(uni->mLoc, model);
- break;
- }
- case MODELMATRIX_INVERSETRANSPOSE:
- {
- model.invert();
- SetUniform(uni->mLoc, model, true);
- break;
- }
- case MODELVIEWMATRIX:
- {
- SetUniform(uni->mLoc, view * model);
- break;
- }
- case MODELVIEWMATRIX_TRANSPOSE:
- {
- MT_Matrix4x4 mat(view * model);
- SetUniform(uni->mLoc, mat, true);
- break;
- }
- case MODELVIEWMATRIX_INVERSE:
- {
- MT_Matrix4x4 mat(view * model);
- mat.invert();
- SetUniform(uni->mLoc, mat);
- break;
- }
- case MODELVIEWMATRIX_INVERSETRANSPOSE:
- {
- MT_Matrix4x4 mat(view * model);
- mat.invert();
- SetUniform(uni->mLoc, mat, true);
- break;
- }
- case CAM_POS:
- {
- MT_Point3 pos(rasty->GetCameraPosition());
- SetUniform(uni->mLoc, pos);
- break;
- }
- case VIEWMATRIX:
- {
- SetUniform(uni->mLoc, view);
- break;
- }
- case VIEWMATRIX_TRANSPOSE:
- {
- SetUniform(uni->mLoc, view, true);
- break;
- }
- case VIEWMATRIX_INVERSE:
- {
- MT_Matrix4x4 viewinv = view;
- viewinv.invert();
- SetUniform(uni->mLoc, view);
- break;
- }
- case VIEWMATRIX_INVERSETRANSPOSE:
- {
- MT_Matrix4x4 viewinv = view;
- viewinv.invert();
- SetUniform(uni->mLoc, view, true);
- break;
- }
- case CONSTANT_TIMER:
- {
- SetUniform(uni->mLoc, (float)rasty->GetTime());
- break;
- }
- default:
- break;
- }
- }
- }
-}
-
-int BL_Shader::GetAttribLocation(const char *name)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- return glGetAttribLocationARB(mShader, name);
- }
-
- return -1;
-}
-
-void BL_Shader::BindAttribute(const char *attr, int loc)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- glBindAttribLocationARB(mShader, loc, attr);
- }
-}
-
-int BL_Shader::GetUniformLocation(const char *name)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- MT_assert(mShader != 0);
- int location = glGetUniformLocationARB(mShader, name);
-
- if (location == -1) {
- spit("Invalid uniform value: " << name << ".");
- }
-
- return location;
- }
- return -1;
-}
-
-void BL_Shader::SetUniform(int uniform, const MT_Tuple2 &vec)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- float value[2];
- vec.getValue(value);
- glUniform2fvARB(uniform, 1, value);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const MT_Tuple3 &vec)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- float value[3];
- vec.getValue(value);
- glUniform3fvARB(uniform, 1, value);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const MT_Tuple4 &vec)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- float value[4];
- vec.getValue(value);
- glUniform4fvARB(uniform, 1, value);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const unsigned int &val)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- glUniform1iARB(uniform, val);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const int val)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- glUniform1iARB(uniform, val);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const float &val)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- glUniform1fARB(uniform, val);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const MT_Matrix4x4 &vec, bool transpose)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- float value[16];
- // note: getValue gives back column major as needed by OpenGL
- vec.getValue(value);
- glUniformMatrix4fvARB(uniform, 1, transpose ? GL_TRUE : GL_FALSE, value);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const MT_Matrix3x3 &vec, bool transpose)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- float value[9];
- value[0] = (float)vec[0][0];
- value[1] = (float)vec[1][0];
- value[2] = (float)vec[2][0];
- value[3] = (float)vec[0][1];
- value[4] = (float)vec[1][1];
- value[5] = (float)vec[2][1];
- value[6] = (float)vec[0][2];
- value[7] = (float)vec[1][2];
- value[8] = (float)vec[2][2];
- glUniformMatrix3fvARB(uniform, 1, transpose ? GL_TRUE : GL_FALSE, value);
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const float *val, int len)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- if (len == 2) {
- glUniform2fvARB(uniform, 1, (GLfloat *)val);
- }
- else if (len == 3) {
- glUniform3fvARB(uniform, 1, (GLfloat *)val);
- }
- else if (len == 4) {
- glUniform4fvARB(uniform, 1, (GLfloat *)val);
- }
- else {
- MT_assert(0);
- }
- }
-}
-
-void BL_Shader::SetUniform(int uniform, const int *val, int len)
-{
- if (GLEW_ARB_fragment_shader && GLEW_ARB_vertex_shader && GLEW_ARB_shader_objects) {
- if (len == 2) {
- glUniform2ivARB(uniform, 1, (GLint *)val);
- }
- else if (len == 3) {
- glUniform3ivARB(uniform, 1, (GLint *)val);
- }
- else if (len == 4) {
- glUniform4ivARB(uniform, 1, (GLint *)val);
- }
- else {
- MT_assert(0);
- }
- }
-}
-
-#ifdef WITH_PYTHON
-PyMethodDef BL_Shader::Methods[] = {
- // creation
- KX_PYMETHODTABLE(BL_Shader, setSource),
- KX_PYMETHODTABLE(BL_Shader, delSource),
- KX_PYMETHODTABLE(BL_Shader, getVertexProg),
- KX_PYMETHODTABLE(BL_Shader, getFragmentProg),
- KX_PYMETHODTABLE(BL_Shader, setNumberOfPasses),
- KX_PYMETHODTABLE(BL_Shader, validate),
- // access functions
- KX_PYMETHODTABLE(BL_Shader, isValid),
- KX_PYMETHODTABLE(BL_Shader, setUniformEyef),
- KX_PYMETHODTABLE(BL_Shader, setUniform1f),
- KX_PYMETHODTABLE(BL_Shader, setUniform2f),
- KX_PYMETHODTABLE(BL_Shader, setUniform3f),
- KX_PYMETHODTABLE(BL_Shader, setUniform4f),
- KX_PYMETHODTABLE(BL_Shader, setUniform1i),
- KX_PYMETHODTABLE(BL_Shader, setUniform2i),
- KX_PYMETHODTABLE(BL_Shader, setUniform3i),
- KX_PYMETHODTABLE(BL_Shader, setUniform4i),
- KX_PYMETHODTABLE(BL_Shader, setAttrib),
- KX_PYMETHODTABLE(BL_Shader, setUniformfv),
- KX_PYMETHODTABLE(BL_Shader, setUniformiv),
- KX_PYMETHODTABLE(BL_Shader, setUniformDef),
- KX_PYMETHODTABLE(BL_Shader, setSampler),
- KX_PYMETHODTABLE(BL_Shader, setUniformMatrix4),
- KX_PYMETHODTABLE(BL_Shader, setUniformMatrix3),
- {NULL, NULL} //Sentinel
-};
-
-PyAttributeDef BL_Shader::Attributes[] = {
- {NULL} //Sentinel
-};
-
-PyTypeObject BL_Shader::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "BL_Shader",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0, 0, 0, 0, 0, 0, 0, 0, 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0, 0, 0, 0, 0, 0, 0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0, 0, 0, 0, 0, 0,
- py_base_new
-};
-
-KX_PYMETHODDEF_DOC(BL_Shader, setSource, " setSource(vertexProgram, fragmentProgram)")
-{
- if (mShader != 0 && mOk) {
- // already set...
- Py_RETURN_NONE;
- }
-
- char *v, *f;
- int apply = 0;
-
- if (PyArg_ParseTuple(args, "ssi:setSource", &v, &f, &apply)) {
- vertProg = v;
- fragProg = f;
-
- if (LinkProgram()) {
- glUseProgramObjectARB(mShader);
- mUse = apply != 0;
- Py_RETURN_NONE;
- }
-
- vertProg = NULL;
- fragProg = NULL;
- mUse = 0;
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-
-KX_PYMETHODDEF_DOC(BL_Shader, delSource, "delSource( )")
-{
- ClearUniforms();
- glUseProgramObjectARB(0);
- glDeleteObjectARB(mShader);
- mShader = 0;
- mOk = 0;
- mUse = 0;
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, isValid, "isValid()")
-{
- return PyBool_FromLong((mShader != 0 && mOk));
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, getVertexProg, "getVertexProg( )")
-{
- return PyUnicode_FromString(vertProg ? vertProg : "");
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, getFragmentProg, "getFragmentProg( )")
-{
- return PyUnicode_FromString(fragProg ? fragProg : "");
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, validate, "validate()")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- if (mShader == 0) {
- PyErr_SetString(PyExc_TypeError, "shader.validate(): BL_Shader, invalid shader object");
- return NULL;
- }
-
- int stat = 0;
- glValidateProgramARB(mShader);
- glGetObjectParameterivARB(mShader, GL_OBJECT_VALIDATE_STATUS_ARB, (GLint *)&stat);
-
- if (stat > 0 && stat < MAX_LOG_LEN) {
- int char_len = 0;
- char *logInf = (char *)MEM_mallocN(stat, "validate-log");
-
- glGetInfoLogARB(mShader, stat, (GLsizei *)&char_len, logInf);
-
- if (char_len > 0) {
- spit("---- GLSL Validation ----");
- spit(logInf);
- }
- MEM_freeN(logInf);
- logInf = NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-KX_PYMETHODDEF_DOC(BL_Shader, setSampler, "setSampler(name, index)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- int index = -1;
-
- if (PyArg_ParseTuple(args, "si:setSampler", &uniform, &index)) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
- if (index >= MAXTEX || index < 0) {
- spit("Invalid texture sample index: " << index);
- }
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT, &index, (sizeof(int)));
-#else
- SetUniform(loc, index);
-#endif
- //if (index <= MAXTEX)
- // mSampler[index].mLoc = loc;
- //else
- // spit("Invalid texture sample index: " << index);
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setNumberOfPasses, "setNumberOfPasses( max-pass )")
-{
- int pass = 1;
-
- if (!PyArg_ParseTuple(args, "i:setNumberOfPasses", &pass)) {
- return NULL;
- }
-
- mPass = 1;
- Py_RETURN_NONE;
-}
-
-/// access functions
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform1f, "setUniform1f(name, fx)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- float value = 0.0f;
-
- if (PyArg_ParseTuple(args, "sf:setUniform1f", &uniform, &value)) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT, &value, sizeof(float));
-#else
- SetUniform(loc, (float)value);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform2f, "setUniform2f(name, fx, fy)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- float array[2] = {0.0f, 0.0f};
-
- if (PyArg_ParseTuple(args, "sff:setUniform2f", &uniform, &array[0], &array[1])) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT2, array, (sizeof(float) * 2));
-#else
- SetUniform(loc, array, 2);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform3f, "setUniform3f(name, fx,fy,fz) ")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- float array[3] = {0.0f, 0.0f, 0.0f};
-
- if (PyArg_ParseTuple(args, "sfff:setUniform3f", &uniform, &array[0], &array[1], &array[2])) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT3, array, (sizeof(float) * 3));
-#else
- SetUniform(loc, array, 3);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform4f, "setUniform4f(name, fx,fy,fz, fw) ")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- float array[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-
- if (PyArg_ParseTuple(args, "sffff:setUniform4f", &uniform, &array[0], &array[1], &array[2], &array[3])) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT4, array, (sizeof(float) * 4));
-#else
- SetUniform(loc, array, 4);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniformEyef, "setUniformEyef(name)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
- const char *uniform;
- float value = 0.0f;
- if (PyArg_ParseTuple(args, "s:setUniformEyef", &uniform)) {
- int loc = GetUniformLocation(uniform);
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT_EYE, &value, sizeof(float));
-#else
- SetUniform(loc, (int)value);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform1i, "setUniform1i(name, ix)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- int value = 0;
-
- if (PyArg_ParseTuple(args, "si:setUniform1i", &uniform, &value)) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT, &value, sizeof(int));
-#else
- SetUniform(loc, (int)value);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform2i, "setUniform2i(name, ix, iy)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- int array[2] = {0, 0};
-
- if (PyArg_ParseTuple(args, "sii:setUniform2i", &uniform, &array[0], &array[1])) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT2, array, sizeof(int) * 2);
-#else
- SetUniform(loc, array, 2);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform3i, "setUniform3i(name, ix,iy,iz) ")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- int array[3] = {0, 0, 0};
-
- if (PyArg_ParseTuple(args, "siii:setUniform3i", &uniform, &array[0], &array[1], &array[2])) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT3, array, sizeof(int) * 3);
-#else
- SetUniform(loc, array, 3);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniform4i, "setUniform4i(name, ix,iy,iz, iw) ")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- int array[4] = {0, 0, 0, 0};
-
- if (PyArg_ParseTuple(args, "siiii:setUniform4i", &uniform, &array[0], &array[1], &array[2], &array[3])) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT4, array, sizeof(int) * 4);
-#else
- SetUniform(loc, array, 4);
-#endif
- }
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniformfv, "setUniformfv(float (list2 or list3 or list4))")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform = "";
- PyObject *listPtr = NULL;
- float array_data[4] = {0.0f, 0.0f, 0.0f, 0.0f};
-
- if (PyArg_ParseTuple(args, "sO:setUniformfv", &uniform, &listPtr)) {
- int loc = GetUniformLocation(uniform);
- if (loc != -1) {
- if (PySequence_Check(listPtr)) {
- unsigned int list_size = PySequence_Size(listPtr);
-
- for (unsigned int i = 0; (i < list_size && i < 4); i++) {
- PyObject *item = PySequence_GetItem(listPtr, i);
- array_data[i] = (float)PyFloat_AsDouble(item);
- Py_DECREF(item);
- }
-
- switch (list_size) {
- case 2:
- {
- float array2[2] = {array_data[0], array_data[1]};
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT2, array2, sizeof(float) * 2);
-#else
- SetUniform(loc, array2, 2);
-#endif
- Py_RETURN_NONE;
- break;
- }
- case 3:
- {
- float array3[3] = {array_data[0], array_data[1], array_data[2]};
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT3, array3, sizeof(float) * 3);
-#else
- SetUniform(loc, array3, 3);
-#endif
- Py_RETURN_NONE;
- break;
- }
- case 4:
- {
- float array4[4] = {array_data[0], array_data[1], array_data[2], array_data[3]};
-#ifdef SORT_UNIFORMS
- SetUniformfv(loc, BL_Uniform::UNI_FLOAT4, array4, sizeof(float) * 4);
-#else
- SetUniform(loc, array4, 4);
-#endif
- Py_RETURN_NONE;
- break;
- }
- default:
- {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniform4i(name, ix,iy,iz, iw): BL_Shader. invalid list size");
- return NULL;
- break;
- }
- }
- }
- }
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniformiv, "setUniformiv(uniform_name, (list2 or list3 or list4))")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform = "";
- PyObject *listPtr = NULL;
- int array_data[4] = {0, 0, 0, 0};
-
- if (!PyArg_ParseTuple(args, "sO:setUniformiv", &uniform, &listPtr)) {
- return NULL;
- }
-
- int loc = GetUniformLocation(uniform);
-
- if (loc == -1) {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniformiv(...): BL_Shader, first string argument is not a valid uniform value");
- return NULL;
- }
-
- if (!PySequence_Check(listPtr)) {
- PyErr_SetString(PyExc_TypeError, "shader.setUniformiv(...): BL_Shader, second argument is not a sequence");
- return NULL;
- }
-
- unsigned int list_size = PySequence_Size(listPtr);
-
- for (unsigned int i = 0; (i < list_size && i < 4); i++) {
- PyObject *item = PySequence_GetItem(listPtr, i);
- array_data[i] = PyLong_AsLong(item);
- Py_DECREF(item);
- }
-
- if (PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniformiv(...): BL_Shader, one or more values in the list is not an int");
- return NULL;
- }
-
- // Sanity checks done!
- switch (list_size) {
- case 2:
- {
- int array2[2] = {array_data[0], array_data[1]};
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT2, array2, sizeof(int) * 2);
-#else
- SetUniform(loc, array2, 2);
-#endif
- Py_RETURN_NONE;
- break;
- }
- case 3:
- {
- int array3[3] = {array_data[0], array_data[1], array_data[2]};
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT3, array3, sizeof(int) * 3);
-#else
- SetUniform(loc, array3, 3);
-#endif
- Py_RETURN_NONE;
- break;
- }
- case 4:
- {
- int array4[4] = {array_data[0], array_data[1], array_data[2], array_data[3]};
-#ifdef SORT_UNIFORMS
- SetUniformiv(loc, BL_Uniform::UNI_INT4, array4, sizeof(int) * 4);
-#else
- SetUniform(loc, array4, 4);
-#endif
- Py_RETURN_NONE;
- break;
- }
- default:
- {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniformiv(...): BL_Shader, second argument, invalid list size, expected an int "
- "list between 2 and 4");
- return NULL;
- break;
- }
- }
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniformMatrix4,
- "setUniformMatrix4(uniform_name, mat-4x4, transpose(row-major=true, col-major=false)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- float matr[16] = {
- 1.0f, 0.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 0.0f, 1.0f
- };
-
- const char *uniform;
- PyObject *matrix = NULL;
- int transp = 0; // python use column major by default, so no transpose....
-
- if (!PyArg_ParseTuple(args, "sO|i:setUniformMatrix4", &uniform, &matrix, &transp)) {
- return NULL;
- }
-
- int loc = GetUniformLocation(uniform);
-
- if (loc == -1) {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniformMatrix4(...): BL_Shader, first string argument is not a valid uniform value");
- return NULL;
- }
-
- MT_Matrix4x4 mat;
-
- if (!PyMatTo(matrix, mat)) {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniformMatrix4(...): BL_Shader, second argument cannot be converted into a 4x4 matrix");
- return NULL;
- }
-
- // Sanity checks done!
-#ifdef SORT_UNIFORMS
- mat.getValue(matr);
- SetUniformfv(loc, BL_Uniform::UNI_MAT4, matr, (sizeof(float) * 16), (transp != 0));
-#else
- SetUniform(loc, mat, (transp != 0));
-#endif
- Py_RETURN_NONE;
-}
-
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniformMatrix3,
- "setUniformMatrix3(uniform_name, list[3x3], transpose(row-major=true, col-major=false)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- float matr[9] = {
- 1.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 1.0f,
- };
-
- const char *uniform;
- PyObject *matrix = NULL;
- int transp = 0; // python use column major by default, so no transpose....
-
- if (!PyArg_ParseTuple(args, "sO|i:setUniformMatrix3", &uniform, &matrix, &transp)) {
- return NULL;
- }
-
- int loc = GetUniformLocation(uniform);
-
- if (loc == -1) {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniformMatrix3(...): BL_Shader, first string argument is not a valid uniform value");
- return NULL;
- }
-
- MT_Matrix3x3 mat;
-
- if (!PyMatTo(matrix, mat)) {
- PyErr_SetString(PyExc_TypeError,
- "shader.setUniformMatrix3(...): BL_Shader, second argument cannot be converted into a 3x3 matrix");
- return NULL;
- }
-
-#ifdef SORT_UNIFORMS
- mat.getValue3x3(matr);
- SetUniformfv(loc, BL_Uniform::UNI_MAT3, matr, (sizeof(float) * 9), (transp != 0));
-#else
- SetUniform(loc, mat, (transp != 0));
-#endif
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(BL_Shader, setAttrib, "setAttrib(enum)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- int attr = 0;
-
- if (!PyArg_ParseTuple(args, "i:setAttrib", &attr)) {
- return NULL;
- }
-
- attr = SHD_TANGENT; // user input is ignored for now, there is only 1 attr
-
- if (mShader == 0) {
- PyErr_SetString(PyExc_ValueError, "shader.setAttrib() BL_Shader, invalid shader object");
- return NULL;
- }
-
- mAttr = attr;
- glUseProgramObjectARB(mShader);
- glBindAttribLocationARB(mShader, mAttr, "Tangent");
- Py_RETURN_NONE;
-}
-
-
-KX_PYMETHODDEF_DOC(BL_Shader, setUniformDef, "setUniformDef(name, enum)")
-{
- if (mError) {
- Py_RETURN_NONE;
- }
-
- const char *uniform;
- int nloc = 0;
- if (PyArg_ParseTuple(args, "si:setUniformDef", &uniform, &nloc)) {
- int loc = GetUniformLocation(uniform);
-
- if (loc != -1) {
- bool defined = false;
- BL_UniformVecDef::iterator it = mPreDef.begin();
- while (it != mPreDef.end()) {
- if ((*it)->mLoc == loc) {
- defined = true;
- break;
- }
- it++;
- }
-
- if (defined) {
- Py_RETURN_NONE;
- }
-
- BL_DefUniform *uni = new BL_DefUniform();
- uni->mLoc = loc;
- uni->mType = nloc;
- uni->mFlag = 0;
- mPreDef.push_back(uni);
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-#endif // WITH_PYTHON
-
-// eof
diff --git a/source/gameengine/Ketsji/BL_Shader.h b/source/gameengine/Ketsji/BL_Shader.h
deleted file mode 100644
index 5de715d67d4..00000000000
--- a/source/gameengine/Ketsji/BL_Shader.h
+++ /dev/null
@@ -1,241 +0,0 @@
-
-/** \file BL_Shader.h
- * \ingroup ketsji
- */
-
-#ifndef __BL_SHADER_H__
-#define __BL_SHADER_H__
-
-#include "EXP_PyObjectPlus.h"
-#include "BL_Material.h"
-#include "BL_Texture.h"
-#include "MT_Matrix4x4.h"
-#include "MT_Matrix3x3.h"
-#include "MT_Tuple2.h"
-#include "MT_Tuple3.h"
-#include "MT_Tuple4.h"
-
-/**
- * BL_Sampler
- * Sampler access
- */
-class BL_Sampler
-{
-public:
- BL_Sampler()
- :
- mLoc(-1)
- {
- }
-
- int mLoc; // Sampler location
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_Sampler")
-#endif
-};
-
-/**
- * BL_Uniform
- * uniform storage
- */
-class BL_Uniform
-{
-private:
- int mLoc; // Uniform location
- void *mData; // Memory allocated for variable
- bool mDirty; // Caching variable
- int mType; // Enum UniformTypes
- bool mTranspose; // Transpose matrices
- const int mDataLen; // Length of our data
-public:
- BL_Uniform(int data_size);
- ~BL_Uniform();
-
- enum UniformTypes {
- UNI_NONE = 0,
- UNI_INT,
- UNI_FLOAT,
- UNI_INT2,
- UNI_FLOAT2,
- UNI_INT3,
- UNI_FLOAT3,
- UNI_INT4,
- UNI_FLOAT4,
- UNI_MAT3,
- UNI_MAT4,
- UNI_FLOAT_EYE,
- UNI_MAX
- };
-
- bool Apply(class BL_Shader *shader);
- void SetData(int location, int type, bool transpose = false);
- int GetLocation() { return mLoc; }
- void *getData() { return mData; }
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_Uniform")
-#endif
-};
-
-/**
- * BL_DefUniform
- * pre defined uniform storage
- */
-class BL_DefUniform
-{
-public:
- BL_DefUniform()
- :
- mType(0),
- mLoc(0),
- mFlag(0)
- {
- }
-
- int mType;
- int mLoc;
- unsigned int mFlag;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_DefUniform")
-#endif
-};
-
-/**
- * BL_Shader
- * shader access
- */
-class BL_Shader : public PyObjectPlus
-{
- Py_Header
-private:
- typedef std::vector<BL_Uniform *> BL_UniformVec;
- typedef std::vector<BL_DefUniform *> BL_UniformVecDef;
-
- unsigned int mShader; // Shader object
- int mPass; // 1.. unused
- bool mOk; // Valid and ok
- bool mUse;
- //BL_Sampler mSampler[MAXTEX]; // Number of samplers
- int mAttr; // Tangent attribute
- const char *vertProg; // Vertex program string
- const char *fragProg; // Fragment program string
- bool mError;
- bool mDirty;
-
- // Stored uniform variables
- BL_UniformVec mUniforms;
- BL_UniformVecDef mPreDef;
-
- // Compiles and links the shader
- bool LinkProgram();
-
- // search by location
- BL_Uniform *FindUniform(const int location);
-
- // clears uniform data
- void ClearUniforms();
-
-public:
- BL_Shader();
- virtual ~BL_Shader();
-
- // Unused for now tangent is set as tex coords
- enum AttribTypes {
- SHD_TANGENT = 1
- };
-
- enum GenType {
- MODELVIEWMATRIX,
- MODELVIEWMATRIX_TRANSPOSE,
- MODELVIEWMATRIX_INVERSE,
- MODELVIEWMATRIX_INVERSETRANSPOSE,
- MODELMATRIX,
- MODELMATRIX_TRANSPOSE,
- MODELMATRIX_INVERSE,
- MODELMATRIX_INVERSETRANSPOSE,
- VIEWMATRIX,
- VIEWMATRIX_TRANSPOSE,
- VIEWMATRIX_INVERSE,
- VIEWMATRIX_INVERSETRANSPOSE,
- CAM_POS,
- CONSTANT_TIMER
- };
-
- const char *GetVertPtr();
- const char *GetFragPtr();
- void SetVertPtr(char *vert);
- void SetFragPtr(char *frag);
- int getNumPass() { return mPass; }
- bool GetError() { return mError; }
-
- //const BL_Sampler *GetSampler(int i);
- void SetSampler(int loc, int unit);
- bool Ok() const;
- unsigned int GetProg();
- void SetProg(bool enable);
- int GetAttribute() { return mAttr; }
-
- // Apply methods : sets colected uniforms
- void ApplyShader();
- void UnloadShader();
-
- // Update predefined uniforms each render call
- void Update(const class RAS_MeshSlot &ms, class RAS_IRasterizer *rasty);
-
- // Set sampler units (copied)
- //void InitializeSampler(int unit, BL_Texture *texture);
- void SetUniformfv(int location, int type, float *param, int size, bool transpose = false);
- void SetUniformiv(int location, int type, int *param, int size, bool transpose = false);
- int GetAttribLocation(const char *name);
- void BindAttribute(const char *attr, int loc);
- int GetUniformLocation(const char *name);
- void SetUniform(int uniform, const MT_Tuple2 &vec);
- void SetUniform(int uniform, const MT_Tuple3 &vec);
- void SetUniform(int uniform, const MT_Tuple4 &vec);
- void SetUniform(int uniform, const MT_Matrix4x4 &vec, bool transpose = false);
- void SetUniform(int uniform, const MT_Matrix3x3 &vec, bool transpose = false);
- void SetUniform(int uniform, const float &val);
- void SetUniform(int uniform, const float *val, int len);
- void SetUniform(int uniform, const int *val, int len);
- void SetUniform(int uniform, const unsigned int &val);
- void SetUniform(int uniform, const int val);
-
- // Python interface
-#ifdef WITH_PYTHON
- virtual PyObject *py_repr()
- {
- return PyUnicode_FromFormat("BL_Shader\n\tvertex shader:%s\n\n\tfragment shader%s\n\n", vertProg, fragProg);
- }
-
- // -----------------------------------
- KX_PYMETHOD_DOC(BL_Shader, setSource);
- KX_PYMETHOD_DOC(BL_Shader, delSource);
- KX_PYMETHOD_DOC(BL_Shader, getVertexProg);
- KX_PYMETHOD_DOC(BL_Shader, getFragmentProg);
- KX_PYMETHOD_DOC(BL_Shader, setNumberOfPasses);
- KX_PYMETHOD_DOC(BL_Shader, isValid);
- KX_PYMETHOD_DOC(BL_Shader, validate);
-
- // -----------------------------------
- KX_PYMETHOD_DOC(BL_Shader, setUniform4f);
- KX_PYMETHOD_DOC(BL_Shader, setUniform3f);
- KX_PYMETHOD_DOC(BL_Shader, setUniform2f);
- KX_PYMETHOD_DOC(BL_Shader, setUniform1f);
- KX_PYMETHOD_DOC(BL_Shader, setUniform4i);
- KX_PYMETHOD_DOC(BL_Shader, setUniform3i);
- KX_PYMETHOD_DOC(BL_Shader, setUniform2i);
- KX_PYMETHOD_DOC(BL_Shader, setUniform1i);
- KX_PYMETHOD_DOC(BL_Shader, setUniformEyef);
- KX_PYMETHOD_DOC(BL_Shader, setUniformfv);
- KX_PYMETHOD_DOC(BL_Shader, setUniformiv);
- KX_PYMETHOD_DOC(BL_Shader, setUniformMatrix4);
- KX_PYMETHOD_DOC(BL_Shader, setUniformMatrix3);
- KX_PYMETHOD_DOC(BL_Shader, setUniformDef);
- KX_PYMETHOD_DOC(BL_Shader, setAttrib);
- KX_PYMETHOD_DOC(BL_Shader, setSampler);
-#endif
-};
-
-#endif /* __BL_SHADER_H__ */
diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp
deleted file mode 100644
index c3b799b9424..00000000000
--- a/source/gameengine/Ketsji/BL_Texture.cpp
+++ /dev/null
@@ -1,759 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/BL_Texture.cpp
- * \ingroup ketsji
- */
-
-#include "GPU_glew.h"
-
-#include <iostream>
-#include <map>
-#include <stdlib.h>
-
-#include "BL_Material.h"
-#include "BL_Texture.h"
-#include "MT_assert.h"
-
-#include "DNA_texture_types.h"
-#include "DNA_image_types.h"
-#include "IMB_imbuf_types.h"
-#include "BKE_image.h"
-#include "BLI_blenlib.h"
-
-#include "RAS_ICanvas.h"
-#include "RAS_Rect.h"
-
-#include "KX_GameObject.h"
-
-#define spit(x) std::cout << x << std::endl;
-
-#include "MEM_guardedalloc.h"
-#include "GPU_draw.h"
-#include "GPU_extensions.h"
-
-extern "C" {
- // envmaps
- #include "IMB_imbuf.h"
- void my_envmap_split_ima(EnvMap *env, ImBuf *ibuf);
- void my_free_envmapdata(EnvMap *env);
-}
-
-// (n&(n-1)) zeros the least significant bit of n
-static int is_power_of_2_i(int num)
-{
- return ((num)&(num-1))==0;
-}
-static int power_of_2_min_i(int num)
-{
- while (!is_power_of_2_i(num))
- num= num&(num-1);
- return num;
-}
-
-// Place holder for a full texture manager
-class BL_TextureObject
-{
-public:
- unsigned int gl_texture;
- void* ref_buffer;
-};
-
-typedef std::map<char*, BL_TextureObject> BL_TextureMap;
-static BL_TextureMap g_textureManager;
-static GLint g_max_units = -1;
-
-
-BL_Texture::BL_Texture()
-: mTexture(0),
- mOk(0),
- mNeedsDeleted(0),
- mType(0),
- mUnit(0),
- mEnvState(0)
-{
- // --
-}
-
-BL_Texture::~BL_Texture()
-{
- // --
-}
-
-void BL_Texture::DeleteTex()
-{
- if ( mNeedsDeleted ) {
- glDeleteTextures(1, (GLuint*)&mTexture);
- mNeedsDeleted = 0;
- mOk = 0;
- }
-
- if (mEnvState) {
- glDeleteLists((GLuint)mEnvState, 1);
- mEnvState =0;
- }
-
- if (mDisableState) {
- glDeleteLists((GLuint)mDisableState, 1);
- mDisableState =0;
- }
- g_textureManager.clear();
-}
-
-
-bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap)
-{
-
- ImBuf *ibuf;
- if (!img || img->ok==0)
- {
- mOk = false;
- return mOk;
- }
-
- ibuf= BKE_image_acquire_ibuf(img, NULL, NULL);
- if (ibuf==NULL)
- {
- img->ok = 0;
- mOk = false;
- return mOk;
- }
-
- mipmap = mipmap && GPU_get_mipmap();
-
- mTexture = img->bindcode[TEXTARGET_TEXTURE_2D];
- mType = GL_TEXTURE_2D;
- mUnit = unit;
-
- ActivateUnit(mUnit);
-
- if (mTexture != 0) {
- glBindTexture(GL_TEXTURE_2D, mTexture );
- Validate();
- BKE_image_release_ibuf(img, ibuf, NULL);
- return mOk;
- }
-
- // look for an existing gl image
- BL_TextureMap::iterator mapLook = g_textureManager.find(img->id.name);
- if (mapLook != g_textureManager.end())
- {
- if (mapLook->second.gl_texture != 0)
- {
- mTexture = mapLook->second.gl_texture;
- glBindTexture(GL_TEXTURE_2D, mTexture);
- mOk = IsValid();
- BKE_image_release_ibuf(img, ibuf, NULL);
- return mOk;
- }
- }
-
- mNeedsDeleted = 1;
- glGenTextures(1, (GLuint*)&mTexture);
-
-#ifdef WITH_DDS
- if (ibuf->ftype == IMB_FTYPE_DDS)
- InitGLCompressedTex(ibuf, mipmap);
- else
- InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap);
-#else
- InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap);
-#endif
-
- // track created units
- BL_TextureObject obj;
- obj.gl_texture = mTexture;
- obj.ref_buffer = img;
- g_textureManager.insert(std::pair<char*, BL_TextureObject>((char*)img->id.name, obj));
-
-
- glDisable(GL_TEXTURE_2D);
- ActivateUnit(0);
- Validate();
-
- BKE_image_release_ibuf(img, ibuf, NULL);
-
- return mOk;
-}
-
-void BL_Texture::InitGLTex(unsigned int *pix,int x,int y,bool mipmap)
-{
- if (!GPU_full_non_power_of_two_support() && (!is_power_of_2_i(x) || !is_power_of_2_i(y)) ) {
- InitNonPow2Tex(pix, x,y,mipmap);
- return;
- }
-
- glBindTexture(GL_TEXTURE_2D, mTexture );
- if ( mipmap ) {
- int i;
- ImBuf *ibuf;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- ibuf = IMB_allocFromBuffer(pix, NULL, x, y);
-
- IMB_makemipmap(ibuf, true);
-
- for (i = 0; i < ibuf->miptot; i++) {
- ImBuf *mip = IMB_getmipmap(ibuf, i);
-
- glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, mip->x, mip->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip->rect);
- }
- IMB_freeImBuf(ibuf);
- }
- else {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, x, y, 0, GL_RGBA, GL_UNSIGNED_BYTE, pix );
- }
-
- if (GLEW_EXT_texture_filter_anisotropic)
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-}
-
-void BL_Texture::InitGLCompressedTex(ImBuf *ibuf, bool mipmap)
-{
-#ifndef WITH_DDS
- // Fall back to uncompressed if DDS isn't enabled
- InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap);
- return;
-#else
- glBindTexture(GL_TEXTURE_2D, mTexture);
-
- if (GPU_upload_dxt_texture(ibuf) == 0) {
- InitGLTex(ibuf->rect, ibuf->x, ibuf->y, mipmap);
- return;
- }
-#endif
-}
-
-void BL_Texture::InitNonPow2Tex(unsigned int *pix,int x,int y,bool mipmap)
-{
- int nx= power_of_2_min_i(x);
- int ny= power_of_2_min_i(y);
-
- ImBuf *ibuf = IMB_allocFromBuffer(pix, NULL, x, y);
- IMB_scaleImBuf(ibuf, nx, ny);
-
- glBindTexture(GL_TEXTURE_2D, mTexture );
-
- if ( mipmap ) {
- int i;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- IMB_makemipmap(ibuf, true);
-
- for (i = 0; i < ibuf->miptot; i++) {
- ImBuf *mip = IMB_getmipmap(ibuf, i);
-
- glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, mip->x, mip->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip->rect);
- }
- }
- else {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, nx, ny, 0, GL_RGBA, GL_UNSIGNED_BYTE, ibuf->rect );
- }
-
- if (GLEW_EXT_texture_filter_anisotropic)
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, GPU_get_anisotropic());
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
- IMB_freeImBuf(ibuf);
-}
-
-
-bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap)
-{
- if (!GLEW_ARB_texture_cube_map)
- {
- spit("cubemaps not supported");
- mOk = false;
- return mOk;
- }
- else if (!cubemap || cubemap->ima->ok==0)
- {
- mOk = false;
- return mOk;
- }
-
- ImBuf *ibuf= BKE_image_acquire_ibuf(cubemap->ima, NULL, NULL);
- if (ibuf==0)
- {
- cubemap->ima->ok = 0;
- mOk = false;
- return mOk;
- }
-
- mNeedsDeleted = 1;
- mType = GL_TEXTURE_CUBE_MAP_ARB;
- mTexture = 0;
- mUnit = unit;
-
- ActivateUnit(mUnit);
-
- BL_TextureMap::iterator mapLook = g_textureManager.find(cubemap->ima->id.name);
- if (mapLook != g_textureManager.end())
- {
- if (mapLook->second.gl_texture != 0 && mapLook->second.ref_buffer == cubemap->ima)
- {
- mTexture = mapLook->second.gl_texture;
- glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mTexture);
- mOk = IsValid();
- BKE_image_release_ibuf(cubemap->ima, ibuf, NULL);
- return mOk;
- }
- }
-
-
- glGenTextures(1, (GLuint*)&mTexture);
- glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mTexture);
-
-
- // track created units
- BL_TextureObject obj;
- obj.gl_texture = mTexture;
- obj.ref_buffer = cubemap->ima;
- g_textureManager.insert(std::pair<char*, BL_TextureObject>((char*)cubemap->ima->id.name, obj));
-
-
- bool needs_split = false;
- if (!cubemap->cube[0])
- {
- needs_split = true;
- spit ("Re-Generating texture buffer");
- }
-
- if (needs_split)
- my_envmap_split_ima(cubemap, ibuf);
-
-
- if (!is_power_of_2_i(cubemap->cube[0]->x) || !is_power_of_2_i(cubemap->cube[0]->y))
- {
- spit("invalid envmap size please render with CubeRes @ power of two");
-
- my_free_envmapdata(cubemap);
- mOk = false;
- BKE_image_release_ibuf(cubemap->ima, ibuf, NULL);
- return mOk;
- }
-
-
-#define SetCubeMapFace(face, num) \
- glTexImage2D(face, 0,GL_RGBA, \
- cubemap->cube[num]->x, \
- cubemap->cube[num]->y, \
- 0, GL_RGBA, GL_UNSIGNED_BYTE, \
- cubemap->cube[num]->rect)
-
- SetCubeMapFace(GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB, 5);
- SetCubeMapFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB, 3);
- SetCubeMapFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB, 0);
- SetCubeMapFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB, 1);
- SetCubeMapFace(GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB, 2);
- SetCubeMapFace(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB, 4);
-
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MIN_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_MAG_FILTER, GL_LINEAR );
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE );
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE );
- if (GLEW_VERSION_1_2)
- glTexParameteri( GL_TEXTURE_CUBE_MAP_ARB, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE );
-
- if (needs_split)
- my_free_envmapdata(cubemap);
-
-
-
- glDisable(GL_TEXTURE_CUBE_MAP_ARB);
- ActivateUnit(0);
-
- mOk = IsValid();
-
- BKE_image_release_ibuf(cubemap->ima, ibuf, NULL);
-
- return mOk;
-}
-
-bool BL_Texture::IsValid()
-{
- return (mTexture!= 0)?glIsTexture(mTexture)!=0:false;
-}
-
-
-void BL_Texture::Validate()
-{
- mOk = IsValid();
-}
-
-
-bool BL_Texture::Ok()
-{
- return (mTexture!= 0);
-}
-
-
-unsigned int BL_Texture::GetTextureType() const
-{
- return mType;
-}
-
-int BL_Texture::GetMaxUnits()
-{
- if (g_max_units < 0) {
- GLint unit = 0;
- glGetIntegerv(GL_MAX_TEXTURE_IMAGE_UNITS_ARB, &unit);
- g_max_units = (MAXTEX >= unit) ? unit : MAXTEX;
- }
-
- return g_max_units;
-}
-
-void BL_Texture::ActivateFirst()
-{
- if (GLEW_ARB_multitexture)
- glActiveTextureARB(GL_TEXTURE0_ARB);
-}
-
-void BL_Texture::ActivateUnit(int unit)
-{
- if (GLEW_ARB_multitexture)
- if (unit <= MAXTEX)
- glActiveTextureARB(GL_TEXTURE0_ARB+unit);
-}
-
-
-void BL_Texture::DisableUnit()
-{
- if (GLEW_ARB_multitexture)
- glActiveTextureARB(GL_TEXTURE0_ARB+mUnit);
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
-
- if (GLEW_ARB_texture_cube_map && glIsEnabled(GL_TEXTURE_CUBE_MAP_ARB))
- glDisable(GL_TEXTURE_CUBE_MAP_ARB);
- else
- {
- if (glIsEnabled(GL_TEXTURE_2D))
- glDisable(GL_TEXTURE_2D);
- }
-
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- glDisable(GL_TEXTURE_GEN_R);
- glDisable(GL_TEXTURE_GEN_Q);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
-}
-
-
-void BL_Texture::DisableAllTextures()
-{
- for (int i=0; i<MAXTEX; i++) {
- if (GLEW_ARB_multitexture)
- glActiveTextureARB(GL_TEXTURE0_ARB+i);
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glDisable(GL_TEXTURE_2D);
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- glDisable(GL_TEXTURE_GEN_R);
- glDisable(GL_TEXTURE_GEN_Q);
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
- }
-
- if (GLEW_ARB_multitexture)
- glActiveTextureARB(GL_TEXTURE0_ARB);
-}
-
-
-void BL_Texture::ActivateTexture()
-{
- if (GLEW_ARB_multitexture)
- glActiveTextureARB(GL_TEXTURE0_ARB+mUnit);
-
- if (mType == GL_TEXTURE_CUBE_MAP_ARB && GLEW_ARB_texture_cube_map)
- {
- glBindTexture( GL_TEXTURE_CUBE_MAP_ARB, mTexture );
- glEnable(GL_TEXTURE_CUBE_MAP_ARB);
- }
- else {
- if (GLEW_ARB_texture_cube_map )
- glDisable(GL_TEXTURE_CUBE_MAP_ARB);
-
- glBindTexture( GL_TEXTURE_2D, mTexture );
- glEnable(GL_TEXTURE_2D);
- }
-}
-
-void BL_Texture::SetMapping(int mode)
-{
-
- if (!(mode &USEREFL)) {
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- glDisable(GL_TEXTURE_GEN_R);
- glDisable(GL_TEXTURE_GEN_Q);
- return;
- }
-
- if ( mType == GL_TEXTURE_CUBE_MAP_ARB &&
- GLEW_ARB_texture_cube_map &&
- mode &USEREFL)
- {
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB );
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB );
- glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_REFLECTION_MAP_ARB );
-
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glEnable(GL_TEXTURE_GEN_R);
- glDisable(GL_TEXTURE_GEN_Q);
- return;
- }
- else
- {
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_SPHERE_MAP );
-
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glDisable(GL_TEXTURE_GEN_R);
- glDisable(GL_TEXTURE_GEN_Q);
- }
-}
-
-
-void BL_Texture::setTexEnv(BL_Material *mat, bool modulate)
-{
- if (modulate || !GLEW_ARB_texture_env_combine) {
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE );
- return;
- }
-
- if (glIsList(mEnvState))
- {
- glCallList(mEnvState);
- return;
- }
- if (!mEnvState)
- mEnvState = glGenLists(1);
-
- glNewList(mEnvState, GL_COMPILE_AND_EXECUTE);
-
- glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_COMBINE_ARB );
-
- GLfloat blend_operand = GL_SRC_COLOR;
- GLfloat blend_operand_prev = GL_SRC_COLOR;
- GLfloat alphaOp = GL_SRC_ALPHA;
-
- GLenum combiner = GL_COMBINE_RGB_ARB;
- GLenum source0 = GL_SOURCE0_RGB_ARB;
- GLenum source1 = GL_SOURCE1_RGB_ARB;
- GLenum source2 = GL_SOURCE2_RGB_ARB;
- GLenum op0 = GL_OPERAND0_RGB_ARB;
- GLenum op1 = GL_OPERAND1_RGB_ARB;
- GLenum op2 = GL_OPERAND2_RGB_ARB;
-
- // switch to alpha combiners
- if ( mat->flag[mUnit] &TEXALPHA ) {
- combiner = GL_COMBINE_ALPHA_ARB;
- source0 = GL_SOURCE0_ALPHA_ARB;
- source1 = GL_SOURCE1_ALPHA_ARB;
- source2 = GL_SOURCE2_ALPHA_ARB;
- op0 = GL_OPERAND0_ALPHA_ARB;
- op1 = GL_OPERAND1_ALPHA_ARB;
- op2 = GL_OPERAND2_ALPHA_ARB;
- blend_operand = GL_SRC_ALPHA;
- blend_operand_prev = GL_SRC_ALPHA;
- // invert
- if (mat->flag[mUnit] &TEXNEG) {
- blend_operand_prev = GL_ONE_MINUS_SRC_ALPHA;
- blend_operand = GL_ONE_MINUS_SRC_ALPHA;
- }
- }
- else {
- if (mat->flag[mUnit] &TEXNEG) {
- blend_operand_prev=GL_ONE_MINUS_SRC_COLOR;
- blend_operand = GL_ONE_MINUS_SRC_COLOR;
- }
- }
- bool using_alpha = false;
-
- if (mat->flag[mUnit] &USEALPHA) {
- alphaOp = GL_ONE_MINUS_SRC_ALPHA;
- using_alpha=true;
- }
- else if (mat->flag[mUnit] &USENEGALPHA) {
- alphaOp = GL_SRC_ALPHA;
- using_alpha = true;
- }
-
- switch (mat->blend_mode[mUnit]) {
- case BLEND_MIX:
- {
- // ------------------------------
- if (!using_alpha) {
- GLfloat base_col[4];
- base_col[0] = base_col[1] = base_col[2] = 0.f;
- base_col[3] = 1.f-mat->color_blend[mUnit];
- glTexEnvfv( GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR,base_col );
- }
- glTexEnvf( GL_TEXTURE_ENV, combiner, GL_INTERPOLATE_ARB);
- glTexEnvf( GL_TEXTURE_ENV, source0, GL_PREVIOUS_ARB);
- glTexEnvf( GL_TEXTURE_ENV, op0, blend_operand_prev );
- glTexEnvf( GL_TEXTURE_ENV, source1, GL_TEXTURE );
- glTexEnvf( GL_TEXTURE_ENV, op1, blend_operand);
- if (!using_alpha)
- glTexEnvf( GL_TEXTURE_ENV, source2, GL_CONSTANT_ARB );
- else
- glTexEnvf( GL_TEXTURE_ENV, source2, GL_TEXTURE );
-
- glTexEnvf( GL_TEXTURE_ENV, op2, alphaOp);
- }break;
- case BLEND_MUL:
- {
- // ------------------------------
- glTexEnvf( GL_TEXTURE_ENV, combiner, GL_MODULATE);
- glTexEnvf( GL_TEXTURE_ENV, source0, GL_PREVIOUS_ARB);
- glTexEnvf( GL_TEXTURE_ENV, op0, blend_operand_prev);
- glTexEnvf( GL_TEXTURE_ENV, source1, GL_TEXTURE );
- if (using_alpha)
- glTexEnvf( GL_TEXTURE_ENV, op1, alphaOp);
- else
- glTexEnvf( GL_TEXTURE_ENV, op1, blend_operand);
- }break;
- case BLEND_ADD:
- {
- // ------------------------------
- glTexEnvf( GL_TEXTURE_ENV, combiner, GL_ADD_SIGNED_ARB);
- glTexEnvf( GL_TEXTURE_ENV, source0, GL_PREVIOUS_ARB );
- glTexEnvf( GL_TEXTURE_ENV, op0, blend_operand_prev );
- glTexEnvf( GL_TEXTURE_ENV, source1, GL_TEXTURE );
- if (using_alpha)
- glTexEnvf( GL_TEXTURE_ENV, op1, alphaOp);
- else
- glTexEnvf( GL_TEXTURE_ENV, op1, blend_operand);
- }break;
- case BLEND_SUB:
- {
- // ------------------------------
- glTexEnvf( GL_TEXTURE_ENV, combiner, GL_SUBTRACT_ARB);
- glTexEnvf( GL_TEXTURE_ENV, source0, GL_PREVIOUS_ARB );
- glTexEnvf( GL_TEXTURE_ENV, op0, blend_operand_prev );
- glTexEnvf( GL_TEXTURE_ENV, source1, GL_TEXTURE );
- glTexEnvf( GL_TEXTURE_ENV, op1, blend_operand);
- }break;
- case BLEND_SCR:
- {
- // ------------------------------
- glTexEnvf( GL_TEXTURE_ENV, combiner, GL_ADD);
- glTexEnvf( GL_TEXTURE_ENV, source0, GL_PREVIOUS_ARB );
- glTexEnvf( GL_TEXTURE_ENV, op0, blend_operand_prev );
- glTexEnvf( GL_TEXTURE_ENV, source1, GL_TEXTURE );
- if (using_alpha)
- glTexEnvf( GL_TEXTURE_ENV, op1, alphaOp);
- else
- glTexEnvf( GL_TEXTURE_ENV, op1, blend_operand);
- } break;
- }
- glTexEnvf( GL_TEXTURE_ENV, GL_RGB_SCALE_ARB, 1.0f);
-
- glEndList();
-}
-
-int BL_Texture::GetPow2(int n)
-{
- if (!is_power_of_2_i(n))
- n = power_of_2_min_i(n);
-
- return n;
-}
-
-void BL_Texture::SplitEnvMap(EnvMap *map)
-{
- if (!map || !map->ima || (map->ima && !map->ima->ok)) return;
- ImBuf *ibuf= BKE_image_acquire_ibuf(map->ima, NULL, NULL);
- if (ibuf) {
- my_envmap_split_ima(map, ibuf);
- BKE_image_release_ibuf(map->ima, ibuf, NULL);
- }
-}
-
-unsigned int BL_Texture::mDisableState = 0;
-
-extern "C" {
-
-void my_envmap_split_ima(EnvMap *env, ImBuf *ibuf)
-{
- int dx, part;
-
- my_free_envmapdata(env);
-
- dx= ibuf->y;
- dx/= 2;
- if (3*dx != ibuf->x) {
- printf("Incorrect envmap size\n");
- env->ok= 0;
- env->ima->ok= 0;
- }
- else {
- for (part=0; part<6; part++) {
- env->cube[part] = IMB_allocImBuf(dx, dx, 24, IB_rect);
- }
- IMB_rectcpy(env->cube[0], ibuf,
- 0, 0, 0, 0, dx, dx);
- IMB_rectcpy(env->cube[1], ibuf,
- 0, 0, dx, 0, dx, dx);
- IMB_rectcpy(env->cube[2], ibuf,
- 0, 0, 2*dx, 0, dx, dx);
- IMB_rectcpy(env->cube[3], ibuf,
- 0, 0, 0, dx, dx, dx);
- IMB_rectcpy(env->cube[4], ibuf,
- 0, 0, dx, dx, dx, dx);
- IMB_rectcpy(env->cube[5], ibuf,
- 0, 0, 2*dx, dx, dx, dx);
-
- env->ok= 2;// ENV_OSA
- }
-}
-
-
-void my_free_envmapdata(EnvMap *env)
-{
- unsigned int part;
-
- for (part=0; part<6; part++) {
- ImBuf *ibuf= env->cube[part];
- if (ibuf) {
- IMB_freeImBuf(ibuf);
- env->cube[part] = NULL;
- }
- }
- env->ok= 0;
-}
-
-
-} // extern C
-
diff --git a/source/gameengine/Ketsji/BL_Texture.h b/source/gameengine/Ketsji/BL_Texture.h
deleted file mode 100644
index cd18ef93822..00000000000
--- a/source/gameengine/Ketsji/BL_Texture.h
+++ /dev/null
@@ -1,82 +0,0 @@
-
-/** \file BL_Texture.h
- * \ingroup ketsji
- */
-
-#ifndef __BL_TEXTURE_H__
-#define __BL_TEXTURE_H__
-
-// #include <vector>
-// #include <map>
-
-#include "MT_Matrix4x4.h"
-#include "KX_Camera.h"
-
-// --
-struct Image;
-struct EnvMap;
-class BL_Material;
-class RAS_Rect;
-class RAS_ICanvas;
-//class RTData;
-
-#include "STR_String.h"
-
-class BL_Texture
-{
-private:
- unsigned int mTexture; // Bound texture unit data
- bool mOk; // ...
- bool mNeedsDeleted; // If generated
- unsigned int mType; // enum TEXTURE_2D | CUBE_MAP
- int mUnit; // Texture unit associated with mTexture
- unsigned int mEnvState; // cache textureEnv
- static unsigned int mDisableState; // speed up disabling calls
-
- void InitNonPow2Tex(unsigned int *p,int x,int y,bool mipmap );
- void InitGLTex(unsigned int *p,int x,int y,bool mipmap );
- void InitGLCompressedTex(struct ImBuf *p, bool mipmap);
-public:
- BL_Texture();
- ~BL_Texture( );
-
- bool Ok();
- int GetUnit() {return mUnit;}
- void SetUnit(int unit) {mUnit = unit;}
-
- unsigned int GetTextureType() const;
- void DeleteTex();
-
- bool InitFromImage(int unit, Image *img, bool mipmap);
- bool InitCubeMap(int unit,EnvMap *cubemap );
-
- bool IsValid();
- void Validate();
-
- static void ActivateFirst();
- static void DisableAllTextures();
- static void ActivateUnit(int unit);
- static int GetMaxUnits();
- static int GetPow2(int x);
- static void SplitEnvMap(EnvMap *map);
-
-
- void ActivateTexture();
- void SetMapping(int mode);
- void DisableUnit();
- void setTexEnv(BL_Material *mat, bool modulate=false);
- unsigned int swapTexture (unsigned int newTex) {
- // swap texture codes
- unsigned int tmp = mTexture;
- mTexture = newTex;
- // return original texture code
- return tmp;
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:BL_Texture")
-#endif
-};
-
-#endif /* __BL_TEXTURE_H__ */
diff --git a/source/gameengine/Ketsji/CMakeLists.txt b/source/gameengine/Ketsji/CMakeLists.txt
deleted file mode 100644
index 417f54cc8b9..00000000000
--- a/source/gameengine/Ketsji/CMakeLists.txt
+++ /dev/null
@@ -1,265 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- KXNetwork
- ../BlenderRoutines
- ../Converter
- ../Expressions
- ../GameLogic
- ../Network
- ../Network/LoopBackNetwork
- ../Physics/common
- ../Rasterizer
- ../Rasterizer/RAS_OpenGLRasterizer
- ../SceneGraph
- ../../blender
- ../../blender/blenfont
- ../../blender/blenkernel
- ../../blender/blenlib
- ../../blender/blenloader
- ../../blender/gpu
- ../../blender/imbuf
- ../../blender/makesdna
- ../../blender/makesrna
- ../../blender/python
- ../../blender/python/generic
- ../../blender/python/mathutils
- ../../../intern/container
- ../../../intern/glew-mx
- ../../../intern/guardedalloc
- ../../../intern/string
-)
-
-set(INC_SYS
- ../../../intern/moto/include
- ../../../extern/recastnavigation/Recast/Include
- ../../../extern/recastnavigation/Detour/Include
- ${PTHREADS_INCLUDE_DIRS}
- ${GLEW_INCLUDE_PATH}
- ${BOOST_INCLUDE_DIR}
-)
-
-set(SRC
- BL_Action.cpp
- BL_ActionManager.cpp
- BL_BlenderShader.cpp
- BL_Material.cpp
- BL_Shader.cpp
- BL_Texture.cpp
- KX_ArmatureSensor.cpp
- KX_BlenderMaterial.cpp
- KX_Camera.cpp
- KX_CameraActuator.cpp
- KX_CameraIpoSGController.cpp
- KX_CharacterWrapper.cpp
- KX_ConstraintActuator.cpp
- KX_ConstraintWrapper.cpp
- KX_Dome.cpp
- KX_EmptyObject.cpp
- KX_FontObject.cpp
- KX_GameActuator.cpp
- KX_GameObject.cpp
- KX_IpoConvert.cpp
- KX_IPO_SGController.cpp
- KX_KetsjiEngine.cpp
- KX_Light.cpp
- KX_LightIpoSGController.cpp
- KX_MaterialIpoController.cpp
- KX_MeshProxy.cpp
- KX_MotionState.cpp
- KX_MouseActuator.cpp
- KX_MouseFocusSensor.cpp
- KX_NavMeshObject.cpp
- KX_NearSensor.cpp
- KX_ObColorIpoSGController.cpp
- KX_ObjectActuator.cpp
- KX_ObstacleSimulation.cpp
- KX_OrientationInterpolator.cpp
- KX_ParentActuator.cpp
- KX_PolyProxy.cpp
- KX_PositionInterpolator.cpp
- KX_PyConstraintBinding.cpp
- KX_PyMath.cpp
- KX_PythonInit.cpp
- KX_PythonInitTypes.cpp
- KX_PythonMain.cpp
- KX_RadarSensor.cpp
- KX_RayCast.cpp
- KX_RayEventManager.cpp
- KX_RaySensor.cpp
- KX_SCA_AddObjectActuator.cpp
- KX_SCA_DynamicActuator.cpp
- KX_SCA_EndObjectActuator.cpp
- KX_SCA_ReplaceMeshActuator.cpp
- KX_SG_BoneParentNodeRelationship.cpp
- KX_SG_NodeRelationships.cpp
- KX_ScalarInterpolator.cpp
- KX_ScalingInterpolator.cpp
- KX_Scene.cpp
- KX_SceneActuator.cpp
- KX_SoundActuator.cpp
- KX_StateActuator.cpp
- KX_SteeringActuator.cpp
- KX_TimeCategoryLogger.cpp
- KX_TimeLogger.cpp
- KX_TouchEventManager.cpp
- KX_TouchSensor.cpp
- KX_TrackToActuator.cpp
- KX_VehicleWrapper.cpp
- KX_VertexProxy.cpp
- KX_VisibilityActuator.cpp
- KX_WorldInfo.cpp
- KX_WorldIpoController.cpp
-
- BL_Action.h
- BL_ActionManager.h
- BL_BlenderShader.h
- BL_Material.h
- BL_Shader.h
- BL_Texture.h
- KX_ArmatureSensor.h
- KX_BlenderMaterial.h
- KX_Camera.h
- KX_CameraActuator.h
- KX_CameraIpoSGController.h
- KX_CharacterWrapper.h
- KX_ClientObjectInfo.h
- KX_ConstraintActuator.h
- KX_ConstraintWrapper.h
- KX_Dome.h
- KX_EmptyObject.h
- KX_FontObject.h
- KX_GameActuator.h
- KX_GameObject.h
- KX_IInterpolator.h
- KX_IpoConvert.h
- KX_IPOTransform.h
- KX_IPO_SGController.h
- KX_IScalarInterpolator.h
- KX_ISceneConverter.h
- KX_ISystem.h
- KX_KetsjiEngine.h
- KX_Light.h
- KX_LightIpoSGController.h
- KX_MaterialIpoController.h
- KX_MeshProxy.h
- KX_MotionState.h
- KX_MouseActuator.h
- KX_MouseFocusSensor.h
- KX_NavMeshObject.h
- KX_NearSensor.h
- KX_ObColorIpoSGController.h
- KX_ObjectActuator.h
- KX_ObstacleSimulation.h
- KX_OrientationInterpolator.h
- KX_ParentActuator.h
- KX_PhysicsEngineEnums.h
- KX_PolyProxy.h
- KX_PositionInterpolator.h
- KX_PyConstraintBinding.h
- KX_PyMath.h
- KX_PythonInit.h
- KX_PythonInitTypes.h
- KX_PythonMain.h
- KX_RadarSensor.h
- KX_RayCast.h
- KX_RayEventManager.h
- KX_RaySensor.h
- KX_SCA_AddObjectActuator.h
- KX_SCA_DynamicActuator.h
- KX_SCA_EndObjectActuator.h
- KX_SCA_ReplaceMeshActuator.h
- KX_SG_BoneParentNodeRelationship.h
- KX_SG_NodeRelationships.h
- KX_ScalarInterpolator.h
- KX_ScalingInterpolator.h
- KX_Scene.h
- KX_SceneActuator.h
- KX_SoundActuator.h
- KX_StateActuator.h
- KX_SteeringActuator.h
- KX_TimeCategoryLogger.h
- KX_TimeLogger.h
- KX_TouchEventManager.h
- KX_TouchSensor.h
- KX_TrackToActuator.h
- KX_VehicleWrapper.h
- KX_VertexProxy.h
- KX_VisibilityActuator.h
- KX_WorldInfo.h
- KX_WorldIpoController.h
-
- # orphan headers (not apart of a library)
- ../Physics/common/PHY_DynamicTypes.h
- ../Physics/common/PHY_ICharacter.h
- ../Physics/common/PHY_IController.h
- ../Physics/common/PHY_IGraphicController.h
- ../Physics/common/PHY_IMotionState.h
- ../Physics/common/PHY_IPhysicsController.h
- ../Physics/common/PHY_IPhysicsEnvironment.h
- ../Physics/common/PHY_IVehicle.h
- ../Physics/common/PHY_Pro.h
-
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-if(WITH_IMAGE_DDS)
- add_definitions(-DWITH_DDS)
-endif()
-
-if(WITH_SDL)
- list(APPEND INC_SYS
- ${SDL_INCLUDE_DIR}
- )
- add_definitions(-DWITH_SDL)
-endif()
-
-if(WITH_CODEC_FFMPEG)
- add_definitions(-DWITH_FFMPEG)
-endif()
-
-if(WITH_AUDASPACE)
- add_definitions(${AUDASPACE_DEFINITIONS})
-
- list(APPEND INC_SYS
- ${AUDASPACE_C_INCLUDE_DIRS}
- ${AUDASPACE_PY_INCLUDE_DIRS}
- )
-endif()
-
-if(WITH_BULLET)
- list(APPEND INC
- ../Physics/Bullet
- )
- list(APPEND INC_SYS
- ${BULLET_INCLUDE_DIRS}
- )
- add_definitions(-DWITH_BULLET)
-endif()
-
-blender_add_lib(ge_logic_ketsji "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Ketsji/KXNetwork/CMakeLists.txt b/source/gameengine/Ketsji/KXNetwork/CMakeLists.txt
deleted file mode 100644
index cfc6ded4e65..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/CMakeLists.txt
+++ /dev/null
@@ -1,56 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ..
- ../../Expressions
- ../../GameLogic
- ../../Network
- ../../SceneGraph
- ../../../blender/blenlib
- ../../../../intern/container
- ../../../../intern/string
-)
-
-set(INC_SYS
- ../../../../intern/moto/include
-)
-
-set(SRC
- KX_NetworkEventManager.cpp
- KX_NetworkMessageActuator.cpp
- KX_NetworkMessageSensor.cpp
- KX_NetworkObjectActuator.cpp
- KX_NetworkObjectSensor.cpp
-
- KX_NetworkEventManager.h
- KX_NetworkMessageActuator.h
- KX_NetworkMessageSensor.h
- KX_NetworkObjectActuator.h
- KX_NetworkObjectSensor.h
-)
-
-blender_add_lib(ge_logic_network "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp
deleted file mode 100644
index 8c6392ee825..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Ketsji Logic Extension: Network Event Manager generic implementation
- */
-
-/** \file gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.cpp
- * \ingroup ketsjinet
- */
-
-
-// Ketsji specific sensor part
-#include "SCA_ISensor.h"
-
-// Ketsji specific network part
-#include "KX_NetworkEventManager.h"
-
-// Network module specific
-#include "NG_NetworkDeviceInterface.h"
-#include "NG_NetworkMessage.h"
-#include "NG_NetworkObject.h"
-
-KX_NetworkEventManager::KX_NetworkEventManager(class SCA_LogicManager*
-logicmgr, class NG_NetworkDeviceInterface *ndi) :
-SCA_EventManager(logicmgr, NETWORK_EVENTMGR), m_ndi(ndi)
-{
- //printf("KX_NetworkEventManager constructor\n");
-}
-
-KX_NetworkEventManager::~KX_NetworkEventManager()
-{
- //printf("KX_NetworkEventManager destructor\n");
-}
-
-void KX_NetworkEventManager::NextFrame()
-{
-// printf("KX_NetworkEventManager::proceed %.2f - %.2f\n", curtime, deltatime);
- // each frame, the logicmanager will call the network
- // eventmanager to look for network events, and process it's
- // 'network' sensors
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
-// printf("KX_NetworkEventManager::proceed sensor %.2f\n", curtime);
- // process queue
- (*it)->Activate(m_logicmgr);
- }
-
- // now a list of triggerer sensors has been built
-}
-
-void KX_NetworkEventManager::EndFrame()
-{
-}
-
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h
deleted file mode 100644
index 9a13b6d53e2..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkEventManager.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_NetworkEventManager.h
- * \ingroup ketsjinet
- * \brief Ketsji Logic Extension: Network Event Manager class
- */
-
-#ifndef __KX_NETWORKEVENTMANAGER_H__
-#define __KX_NETWORKEVENTMANAGER_H__
-
-#include "SCA_EventManager.h"
-
-class KX_NetworkEventManager : public SCA_EventManager
-{
- class NG_NetworkDeviceInterface* m_ndi;
-
-public:
- KX_NetworkEventManager(class SCA_LogicManager* logicmgr,
- class NG_NetworkDeviceInterface *ndi);
- virtual ~KX_NetworkEventManager ();
-
- virtual void NextFrame();
- virtual void EndFrame();
-
- SCA_LogicManager* GetLogicManager() { return m_logicmgr; }
- class NG_NetworkDeviceInterface* GetNetworkDevice() {
- return m_ndi; }
-};
-
-#endif /* __KX_NETWORKEVENTMANAGER_H__ */
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
deleted file mode 100644
index 2741907bfe6..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Ketsji Logic Extension: Network Message Actuator generic implementation
- */
-
-/** \file gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.cpp
- * \ingroup ketsjinet
- */
-
-
-#include <stddef.h>
-
-#include "NG_NetworkScene.h"
-#include "KX_NetworkMessageActuator.h"
-
-KX_NetworkMessageActuator::KX_NetworkMessageActuator(
- SCA_IObject* gameobj, // the actuator controlling object
- NG_NetworkScene* networkscene, // needed for replication
- const STR_String &toPropName,
- const STR_String &subject,
- int bodyType,
- const STR_String &body) :
- SCA_IActuator(gameobj, KX_ACT_MESSAGE),
- m_networkscene(networkscene),
- m_toPropName(toPropName),
- m_subject(subject),
- m_bPropBody(bodyType),
- m_body(body)
-{
-}
-
-KX_NetworkMessageActuator::~KX_NetworkMessageActuator()
-{
-}
-
-// returns true if the actuators needs to be running over several frames
-bool KX_NetworkMessageActuator::Update()
-{
- //printf("update messageactuator\n");
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent) {
- return false; // do nothing on negative events
- //printf("messageactuator false event\n");
- }
- //printf("messageactuator true event\n");
-
- if (m_bPropBody) // ACT_MESG_PROP in DNA_actuator_types.h
- {
- m_networkscene->SendMessage(
- m_toPropName,
- GetParent()->GetName(),
- m_subject,
- GetParent()->GetPropertyText(m_body));
- } else
- {
- m_networkscene->SendMessage(
- m_toPropName,
- GetParent()->GetName(),
- m_subject,
- m_body);
- }
- return false;
-}
-
-CValue* KX_NetworkMessageActuator::GetReplica()
-{
- KX_NetworkMessageActuator* replica = new KX_NetworkMessageActuator(*this);
- replica->ProcessReplica();
-
- return replica;
-}
-
-#ifdef WITH_PYTHON
-
-/* -------------------------------------------------------------------- */
-/* Python interface --------------------------------------------------- */
-/* -------------------------------------------------------------------- */
-
-/* Integration hooks -------------------------------------------------- */
-PyTypeObject KX_NetworkMessageActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_NetworkMessageActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_NetworkMessageActuator::Methods[] = {
- {NULL,NULL} // Sentinel
-};
-
-PyAttributeDef KX_NetworkMessageActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_NetworkMessageActuator, m_toPropName),
- KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageActuator, m_subject),
- KX_PYATTRIBUTE_BOOL_RW("usePropBody", KX_NetworkMessageActuator, m_bPropBody),
- KX_PYATTRIBUTE_STRING_RW("body", 0, 16384, false, KX_NetworkMessageActuator, m_body),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h
deleted file mode 100644
index 325a7be9bd7..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageActuator.h
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_NetworkMessageActuator.h
- * \ingroup ketsjinet
- * \brief Ketsji Logic Extension: Network Message Actuator class
- */
-
-#ifndef __KX_NETWORKMESSAGEACTUATOR_H__
-#define __KX_NETWORKMESSAGEACTUATOR_H__
-
-#include "STR_String.h"
-#include "SCA_IActuator.h"
-#include "NG_NetworkMessage.h"
-
-class KX_NetworkMessageActuator : public SCA_IActuator
-{
- Py_Header
- bool m_lastEvent;
- class NG_NetworkScene* m_networkscene; // needed for replication
- STR_String m_toPropName;
- STR_String m_subject;
- bool m_bPropBody;
- STR_String m_body;
-public:
- KX_NetworkMessageActuator(
- SCA_IObject* gameobj,
- NG_NetworkScene* networkscene,
- const STR_String &toPropName,
- const STR_String &subject,
- int bodyType,
- const STR_String &body);
- virtual ~KX_NetworkMessageActuator();
-
- virtual bool Update();
- virtual CValue* GetReplica();
- virtual void Replace_NetworkScene(NG_NetworkScene *val)
- {
- m_networkscene= val;
- };
-
- /* ------------------------------------------------------------ */
- /* Python interface ------------------------------------------- */
- /* ------------------------------------------------------------ */
-
-};
-
-#endif /* __KX_NETWORKMESSAGEACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
deleted file mode 100644
index 1fadd9382e0..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
+++ /dev/null
@@ -1,224 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Ketsji Logic Extension: Network Message Sensor generic implementation
- */
-
-/** \file gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.cpp
- * \ingroup ketsjinet
- */
-
-
-#include <stddef.h>
-
-#include "KX_NetworkMessageSensor.h"
-#include "KX_NetworkEventManager.h"
-#include "NG_NetworkMessage.h"
-#include "NG_NetworkScene.h"
-#include "NG_NetworkObject.h"
-#include "SCA_IObject.h"
-#include "EXP_InputParser.h"
-#include "EXP_ListValue.h"
-#include "EXP_StringValue.h"
-
-#ifdef NAN_NET_DEBUG
- #include <iostream>
-#endif
-
-KX_NetworkMessageSensor::KX_NetworkMessageSensor(
- class KX_NetworkEventManager* eventmgr, // our eventmanager
- class NG_NetworkScene *NetworkScene, // our scene
- SCA_IObject* gameobj, // the sensor controlling object
- const STR_String &subject
- ) :
- SCA_ISensor(gameobj,eventmgr),
- m_NetworkScene(NetworkScene),
- m_subject(subject),
- m_frame_message_count (0),
- m_BodyList(NULL),
- m_SubjectList(NULL)
-{
- Init();
-}
-
-void KX_NetworkMessageSensor::Init()
-{
- m_IsUp = false;
-}
-
-KX_NetworkMessageSensor::~KX_NetworkMessageSensor()
-{
-}
-
-CValue* KX_NetworkMessageSensor::GetReplica()
-{
- // This is the standard sensor implementation of GetReplica
- // There may be more network message sensor specific stuff to do here.
- CValue* replica = new KX_NetworkMessageSensor(*this);
-
- if (replica == NULL) return NULL;
- replica->ProcessReplica();
-
- return replica;
-}
-
-// Return true only for flank (UP and DOWN)
-bool KX_NetworkMessageSensor::Evaluate()
-{
- bool result = false;
- bool WasUp = m_IsUp;
-
- m_IsUp = false;
-
- if (m_BodyList) {
- m_BodyList->Release();
- m_BodyList = NULL;
- }
-
- if (m_SubjectList) {
- m_SubjectList->Release();
- m_SubjectList = NULL;
- }
-
- STR_String& toname=GetParent()->GetName();
- STR_String& subject = this->m_subject;
-
- vector<NG_NetworkMessage*> messages =
- m_NetworkScene->FindMessages(toname,"",subject,true);
-
- m_frame_message_count = messages.size();
-
- if (!messages.empty()) {
-#ifdef NAN_NET_DEBUG
- printf("KX_NetworkMessageSensor found one or more messages\n");
-#endif
- m_IsUp = true;
- m_BodyList = new CListValue();
- m_SubjectList = new CListValue();
- }
-
- vector<NG_NetworkMessage*>::iterator mesit;
- for (mesit=messages.begin();mesit!=messages.end();mesit++)
- {
- // save the body
- const STR_String& body = (*mesit)->GetMessageText();
- // save the subject
- const STR_String& messub = (*mesit)->GetSubject();
-#ifdef NAN_NET_DEBUG
- if (body) {
- cout << "body [" << body << "]\n";
- }
-#endif
- m_BodyList->Add(new CStringValue(body,"body"));
- // Store Subject
- m_SubjectList->Add(new CStringValue(messub,"subject"));
-
- // free the message
- (*mesit)->Release();
- }
- messages.clear();
-
- result = (WasUp != m_IsUp);
-
- // Return always true if a message was received otherwise we can loose messages
- if (m_IsUp)
- return true;
- // Is it useful to return also true when the first frame without a message??
- // This will cause a fast on/off cycle that seems useless!
- return result;
-}
-
-// return true for being up (no flank needed)
-bool KX_NetworkMessageSensor::IsPositiveTrigger()
-{
-// printf("KX_NetworkMessageSensor IsPositiveTrigger\n");
- //attempt to fix [ #3809 ] IPO Actuator does not work with some Sensors
- //a better solution is to properly introduce separate Edge and Level triggering concept
-
- return m_IsUp;
-}
-
-#ifdef WITH_PYTHON
-
-/* --------------------------------------------------------------------- */
-/* Python interface ---------------------------------------------------- */
-/* --------------------------------------------------------------------- */
-
-/* Integration hooks --------------------------------------------------- */
-PyTypeObject KX_NetworkMessageSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_NetworkMessageSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_NetworkMessageSensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_NetworkMessageSensor::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("subject", 0, 100, false, KX_NetworkMessageSensor, m_subject),
- KX_PYATTRIBUTE_INT_RO("frameMessageCount", KX_NetworkMessageSensor, m_frame_message_count),
- KX_PYATTRIBUTE_RO_FUNCTION("bodies", KX_NetworkMessageSensor, pyattr_get_bodies),
- KX_PYATTRIBUTE_RO_FUNCTION("subjects", KX_NetworkMessageSensor, pyattr_get_subjects),
- { NULL } //Sentinel
-};
-
-PyObject *KX_NetworkMessageSensor::pyattr_get_bodies(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_NetworkMessageSensor *self = static_cast<KX_NetworkMessageSensor*>(self_v);
- if (self->m_BodyList) {
- return self->m_BodyList->GetProxy();
- } else {
- return (new CListValue())->NewProxy(true);
- }
-}
-
-PyObject *KX_NetworkMessageSensor::pyattr_get_subjects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_NetworkMessageSensor *self = static_cast<KX_NetworkMessageSensor*>(self_v);
- if (self->m_SubjectList) {
- return self->m_SubjectList->GetProxy();
- } else {
- return (new CListValue())->NewProxy(true);
- }
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h
deleted file mode 100644
index a1f0692b7b3..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkMessageSensor.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_NetworkMessageSensor.h
- * \ingroup ketsjinet
- * \brief Ketsji Logic Extension: Network Message Sensor class
- */
-#ifndef __KX_NETWORKMESSAGESENSOR_H__
-#define __KX_NETWORKMESSAGESENSOR_H__
-
-#include "SCA_ISensor.h"
-
-class KX_NetworkEventManager;
-class NG_NetworkScene;
-
-class KX_NetworkMessageSensor : public SCA_ISensor
-{
- // note: Py_Header MUST BE the first listed here
- Py_Header
- NG_NetworkScene *m_NetworkScene;
-
- // The subject we filter on.
- STR_String m_subject;
-
- // The number of messages caught since the last frame.
- int m_frame_message_count;
-
- bool m_IsUp;
-
- class CListValue* m_BodyList;
- class CListValue* m_SubjectList;
-public:
- KX_NetworkMessageSensor(
- KX_NetworkEventManager* eventmgr, // our eventmanager
- NG_NetworkScene *NetworkScene, // our scene
- SCA_IObject* gameobj, // the sensor controlling object
- const STR_String &subject
- );
- virtual ~KX_NetworkMessageSensor();
-
- virtual CValue* GetReplica();
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual void Init();
- void EndFrame();
-
- virtual void Replace_NetworkScene(NG_NetworkScene *val)
- {
- m_NetworkScene= val;
- };
-
-#ifdef WITH_PYTHON
-
- /* ------------------------------------------------------------- */
- /* Python interface -------------------------------------------- */
- /* ------------------------------------------------------------- */
-
- /* attributes */
- static PyObject* pyattr_get_bodies(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_subjects(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __KX_NETWORKMESSAGESENSOR_H__ */
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.cpp
deleted file mode 100644
index b8032f8e037..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.cpp
+++ /dev/null
@@ -1,31 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.cpp
- * \ingroup ketsjinet
- */
-
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.h
deleted file mode 100644
index 36e0e6c39ec..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KXNetwork/KX_NetworkObjectActuator.h
- * \ingroup ketsjinet
- */
-
-
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.cpp b/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.cpp
deleted file mode 100644
index bc6da2e4143..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.cpp
- * \ingroup ketsjinet
- */
-
-
diff --git a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.h b/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.h
deleted file mode 100644
index 00aa53feb27..00000000000
--- a/source/gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.h
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KXNetwork/KX_NetworkObjectSensor.h
- * \ingroup ketsjinet
- */
-
-
diff --git a/source/gameengine/Ketsji/KX_ArmatureSensor.cpp b/source/gameengine/Ketsji/KX_ArmatureSensor.cpp
deleted file mode 100644
index c111a4de0eb..00000000000
--- a/source/gameengine/Ketsji/KX_ArmatureSensor.cpp
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * Armature sensor
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ArmatureSensor.cpp
- * \ingroup ketsji
- */
-
-
-#include "DNA_action_types.h"
-#include "DNA_constraint_types.h"
-#include "BKE_constraint.h"
-#include "DNA_sensor_types.h"
-
-#include "BL_ArmatureObject.h"
-#include "KX_ArmatureSensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-
-KX_ArmatureSensor::KX_ArmatureSensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const char *posechannel,
- const char *constraintname,
- int type,
- float value)
- : SCA_ISensor(gameobj,eventmgr),
- m_constraint(NULL),
- m_posechannel(posechannel),
- m_constraintname(constraintname),
- m_type(type),
- m_value(value)
-{
- FindConstraint();
-}
-
-void KX_ArmatureSensor::Init()
-{
- m_lastresult = m_invert?true:false;
- m_result = false;
- m_reset = true;
-}
-
-void KX_ArmatureSensor::FindConstraint()
-{
- m_constraint = NULL;
-
- if (m_gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) {
- BL_ArmatureObject* armobj = (BL_ArmatureObject*)m_gameobj;
- // get the persistent pose structure
- bPose* pose = armobj->GetOrigPose();
- bPoseChannel* pchan;
- bConstraint* pcon;
- // and locate the constraint
- for (pchan = (bPoseChannel*)pose->chanbase.first; pchan; pchan=(bPoseChannel*)pchan->next) {
- if (!strcmp(pchan->name, m_posechannel)) {
- // now locate the constraint
- for (pcon = (bConstraint *)pchan->constraints.first; pcon; pcon = (bConstraint *)pcon->next) {
- if (!strcmp(pcon->name, m_constraintname)) {
- if (pcon->flag & CONSTRAINT_DISABLE)
- /* this constraint is not valid, can't use it */
- break;
- m_constraint = pcon;
- break;
- }
- }
- break;
- }
- }
- }
-}
-
-
-CValue* KX_ArmatureSensor::GetReplica()
-{
- KX_ArmatureSensor* replica = new KX_ArmatureSensor(*this);
- // m_range_expr must be recalculated on replica!
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_ArmatureSensor::ReParent(SCA_IObject* parent)
-{
- SCA_ISensor::ReParent(parent);
- // must remap the constraint
- FindConstraint();
-}
-
-bool KX_ArmatureSensor::IsPositiveTrigger()
-{
- return (m_invert) ? !m_result : m_result;
-}
-
-
-KX_ArmatureSensor::~KX_ArmatureSensor()
-{
-}
-
-bool KX_ArmatureSensor::Evaluate()
-{
- bool reset = m_reset && m_level;
-
- m_reset = false;
- if (!m_constraint)
- return false;
- switch (m_type) {
- case SENS_ARM_STATE_CHANGED:
- m_result = !(m_constraint->flag & CONSTRAINT_OFF);
- break;
- case SENS_ARM_LIN_ERROR_BELOW:
- m_result = (m_constraint->lin_error < m_value);
- break;
- case SENS_ARM_LIN_ERROR_ABOVE:
- m_result = (m_constraint->lin_error > m_value);
- break;
- case SENS_ARM_ROT_ERROR_BELOW:
- m_result = (m_constraint->rot_error < m_value);
- break;
- case SENS_ARM_ROT_ERROR_ABOVE:
- m_result = (m_constraint->rot_error > m_value);
- break;
- }
- if (m_lastresult!=m_result)
- {
- m_lastresult = m_result;
- return true;
- }
- return (reset) ? true : false;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_ArmatureSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_ArmatureSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_ArmatureSensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_ArmatureSensor::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("constraint", KX_ArmatureSensor, pyattr_get_constraint),
- KX_PYATTRIBUTE_FLOAT_RW("value",-FLT_MAX,FLT_MAX,KX_ArmatureSensor,m_value),
- KX_PYATTRIBUTE_INT_RW("type",0,SENS_ARM_MAXTYPE,false,KX_ArmatureSensor,m_type),
- { NULL } //Sentinel
-};
-
-PyObject *KX_ArmatureSensor::pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ArmatureSensor* sensor = static_cast<KX_ArmatureSensor*>(self);
- if (sensor->m_gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE) {
- BL_ArmatureObject* armobj = (BL_ArmatureObject*)sensor->m_gameobj;
- BL_ArmatureConstraint* constraint = armobj->GetConstraint(sensor->m_posechannel, sensor->m_constraintname);
- if (constraint)
- return constraint->GetProxy();
- }
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_ArmatureSensor.h b/source/gameengine/Ketsji/KX_ArmatureSensor.h
deleted file mode 100644
index b3ea905d198..00000000000
--- a/source/gameengine/Ketsji/KX_ArmatureSensor.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ArmatureSensor.h
- * \ingroup ketsji
- * \brief Property sensor
- */
-
-#ifndef __KX_ARMATURESENSOR_H__
-#define __KX_ARMATURESENSOR_H__
-
-struct bConstraint;
-
-#include "SCA_ISensor.h"
-#include "DNA_sensor_types.h"
-
-class KX_ArmatureSensor : public SCA_ISensor
-{
- Py_Header
- //class CExpression* m_rightexpr;
-
-protected:
-
-public:
- KX_ArmatureSensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const char *posechannel,
- const char *constraintname,
- int type,
- float value);
-
- /**
- * For property sensor, it is used to release the pre-calculated expression
- * so that self references are removed before the sensor itself is released
- */
- virtual ~KX_ArmatureSensor();
- virtual CValue* GetReplica();
- virtual void ReParent(SCA_IObject* parent);
- virtual void Init();
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
-
- // identify the constraint that this actuator controls
- void FindConstraint();
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
- static PyObject *pyattr_get_constraint(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-
-#endif /* WITH_PYTHON */
-
-private:
- struct bConstraint* m_constraint;
- STR_String m_posechannel;
- STR_String m_constraintname;
- int m_type;
- float m_value;
- bool m_result;
- bool m_lastresult;
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp b/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
deleted file mode 100644
index d26e35f8138..00000000000
--- a/source/gameengine/Ketsji/KX_BlenderMaterial.cpp
+++ /dev/null
@@ -1,1345 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_BlenderMaterial.cpp
- * \ingroup ketsji
- */
-
-#include "GPU_glew.h"
-
-#include "KX_BlenderMaterial.h"
-#include "BL_Material.h"
-#include "KX_Scene.h"
-#include "KX_Light.h"
-#include "KX_GameObject.h"
-#include "KX_MeshProxy.h"
-#include "KX_PyMath.h"
-
-#include "MT_Vector3.h"
-#include "MT_Vector4.h"
-#include "MT_Matrix4x4.h"
-
-#include "RAS_BucketManager.h"
-#include "RAS_MeshObject.h"
-#include "RAS_IRasterizer.h"
-
-#include "GPU_draw.h"
-
-#include "STR_HashedString.h"
-
-// ------------------------------------
-#include "DNA_object_types.h"
-#include "DNA_material_types.h"
-#include "DNA_image_types.h"
-#include "DNA_meshdata_types.h"
-#include "BKE_mesh.h"
-// ------------------------------------
-#include "BLI_utildefines.h"
-#include "BLI_math.h"
-
-#define spit(x) std::cout << x << std::endl;
-
-BL_Shader *KX_BlenderMaterial::mLastShader = NULL;
-BL_BlenderShader *KX_BlenderMaterial::mLastBlenderShader = NULL;
-
-//static PyObject *gTextureDict = 0;
-
-KX_BlenderMaterial::KX_BlenderMaterial()
-: PyObjectPlus(),
- RAS_IPolyMaterial(),
- mMaterial(NULL),
- mShader(0),
- mBlenderShader(0),
- mScene(NULL),
- mUserDefBlend(0),
- mModified(0),
- mConstructed(false),
- mPass(0)
-{
-}
-
-void KX_BlenderMaterial::Initialize(
- KX_Scene *scene,
- BL_Material *data,
- GameSettings *game,
- int lightlayer)
-{
- RAS_IPolyMaterial::Initialize(
- data->texname[0],
- data->matname,
- data->materialindex,
- data->tile,
- data->tilexrep[0],
- data->tileyrep[0],
- data->alphablend,
- ((data->ras_mode &ALPHA)!=0),
- ((data->ras_mode &ZSORT)!=0),
- ((data->ras_mode &USE_LIGHT)!=0),
- ((data->ras_mode &TEX)),
- game
- );
- Material *ma = data->material;
-
- // Save material data to restore on exit
- mSavedData.r = ma->r;
- mSavedData.g = ma->g;
- mSavedData.b = ma->b;
- mSavedData.a = ma->alpha;
- mSavedData.specr = ma->specr;
- mSavedData.specg = ma->specg;
- mSavedData.specb = ma->specb;
- mSavedData.spec = ma->spec;
- mSavedData.ref = ma->ref;
- mSavedData.hardness = ma->har;
- mSavedData.emit = ma->emit;
-
- mMaterial = data;
- mShader = 0;
- mBlenderShader = 0;
- mScene = scene;
- mUserDefBlend = 0;
- mModified = 0;
- mConstructed = false;
- mPass = 0;
- mLightLayer = lightlayer;
- // --------------------------------
- // RAS_IPolyMaterial variables...
- m_flag |= RAS_BLENDERMAT;
- m_flag |= (mMaterial->IdMode>=ONETEX)? RAS_MULTITEX: 0;
- m_flag |= ((mMaterial->ras_mode & USE_LIGHT)!=0)? RAS_MULTILIGHT: 0;
- m_flag |= (mMaterial->glslmat)? RAS_BLENDERGLSL: 0;
- m_flag |= ((mMaterial->ras_mode & CAST_SHADOW)!=0)? RAS_CASTSHADOW: 0;
- m_flag |= ((mMaterial->ras_mode & ONLY_SHADOW)!=0)? RAS_ONLYSHADOW: 0;
-
- // test the sum of the various modes for equality
- // so we can ether accept or reject this material
- // as being equal, this is rather important to
- // prevent material bleeding
- for (int i=0; i<BL_Texture::GetMaxUnits(); i++) {
- m_multimode += (mMaterial->flag[i] + mMaterial->blend_mode[i]);
- }
- m_multimode += mMaterial->IdMode+ (mMaterial->ras_mode & ~(USE_LIGHT));
-}
-
-KX_BlenderMaterial::~KX_BlenderMaterial()
-{
- Material *ma = mMaterial->material;
- // Restore Blender material data
- ma->r = mSavedData.r;
- ma->g = mSavedData.g;
- ma->b = mSavedData.b;
- ma->alpha = mSavedData.a;
- ma->specr = mSavedData.specr;
- ma->specg = mSavedData.specg;
- ma->specb = mSavedData.specb;
- ma->spec = mSavedData.spec;
- ma->ref = mSavedData.ref;
- ma->har = mSavedData.hardness;
- ma->emit = mSavedData.emit;
-
- // cleanup work
- if (mConstructed)
- // clean only if material was actually used
- OnExit();
-}
-
-MTexPoly *KX_BlenderMaterial::GetMTexPoly() const
-{
- // fonts on polys
- return &mMaterial->mtexpoly;
-}
-
-unsigned int* KX_BlenderMaterial::GetMCol() const
-{
- // fonts on polys
- return mMaterial->rgb;
-}
-
-void KX_BlenderMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
-{
- if (mMaterial) {
- *rgba++ = (unsigned char)(mMaterial->matcolor[0] * 255.0f);
- *rgba++ = (unsigned char)(mMaterial->matcolor[1] * 255.0f);
- *rgba++ = (unsigned char)(mMaterial->matcolor[2] * 255.0f);
- *rgba++ = (unsigned char)(mMaterial->matcolor[3] * 255.0f);
- } else
- RAS_IPolyMaterial::GetMaterialRGBAColor(rgba);
-}
-
-Material *KX_BlenderMaterial::GetBlenderMaterial() const
-{
- return mMaterial->material;
-}
-
-Image *KX_BlenderMaterial::GetBlenderImage() const
-{
- return mMaterial->mtexpoly.tpage;
-}
-
-Scene* KX_BlenderMaterial::GetBlenderScene() const
-{
- return mScene->GetBlenderScene();
-}
-
-void KX_BlenderMaterial::ReleaseMaterial()
-{
- if (mBlenderShader)
- mBlenderShader->ReloadMaterial();
-}
-
-void KX_BlenderMaterial::InitTextures()
-{
- // for each unique material...
- int i;
- for (i=0; i<BL_Texture::GetMaxUnits(); i++) {
- if ( mMaterial->mapping[i].mapping & USEENV ) {
- if (!GLEW_ARB_texture_cube_map) {
- spit("CubeMap textures not supported");
- continue;
- }
- if (!mTextures[i].InitCubeMap(i, mMaterial->cubemap[i] ) )
- spit("unable to initialize image("<<i<<") in "<<
- mMaterial->matname<< ", image will not be available");
- }
- /* If we're using glsl materials, the textures are handled by bf_gpu, so don't load them twice!
- * However, if we're using a custom shader, then we still need to load the textures ourselves. */
- else if (!mMaterial->glslmat || mShader) {
- if ( mMaterial->img[i] ) {
- if ( ! mTextures[i].InitFromImage(i, mMaterial->img[i], (mMaterial->flag[i] &MIPMAP)!=0 ))
- spit("unable to initialize image("<<i<<") in "<<
- mMaterial->matname<< ", image will not be available");
- }
- }
- }
-}
-
-void KX_BlenderMaterial::OnConstruction()
-{
- if (mConstructed)
- // when material are reused between objects
- return;
-
- if (mMaterial->glslmat)
- SetBlenderGLSLShader();
-
- InitTextures();
-
- mBlendFunc[0] =0;
- mBlendFunc[1] =0;
- mConstructed = true;
-}
-
-void KX_BlenderMaterial::EndFrame()
-{
- if (mLastBlenderShader) {
- mLastBlenderShader->SetProg(false);
- mLastBlenderShader = NULL;
- }
-
- if (mLastShader) {
- mLastShader->SetProg(false);
- mLastShader = NULL;
- }
-}
-
-void KX_BlenderMaterial::OnExit()
-{
- if ( mShader ) {
- //note, the shader here is allocated, per unique material
- //and this function is called per face
- if (mShader == mLastShader) {
- mShader->SetProg(false);
- mLastShader = NULL;
- }
-
- delete mShader;
- mShader = 0;
- }
-
- if ( mBlenderShader ) {
- if (mBlenderShader == mLastBlenderShader) {
- mBlenderShader->SetProg(false);
- mLastBlenderShader = NULL;
- }
-
- delete mBlenderShader;
- mBlenderShader = 0;
- }
-
- BL_Texture::ActivateFirst();
- for (int i=0; i<BL_Texture::GetMaxUnits(); i++) {
- if (!mTextures[i].Ok()) continue;
- BL_Texture::ActivateUnit(i);
- mTextures[i].DeleteTex();
- mTextures[i].DisableUnit();
- }
-
- /* used to call with 'mMaterial->tface' but this can be a freed array,
- * see: [#30493], so just call with NULL, this is best since it clears
- * the 'lastface' pointer in GPU too - campbell */
- GPU_set_tpage(NULL, 1, mMaterial->alphablend);
-}
-
-
-void KX_BlenderMaterial::setShaderData( bool enable, RAS_IRasterizer *ras)
-{
- MT_assert(GLEW_ARB_shader_objects && mShader);
-
- int i;
- if ( !enable || !mShader->Ok() ) {
- // frame cleanup.
- if (mShader == mLastShader) {
- mShader->SetProg(false);
- mLastShader = NULL;
- }
-
- ras->SetAlphaBlend(TF_SOLID);
- BL_Texture::DisableAllTextures();
- return;
- }
-
- BL_Texture::DisableAllTextures();
- mShader->SetProg(true);
- mLastShader = mShader;
-
- BL_Texture::ActivateFirst();
-
- mShader->ApplyShader();
-
- // for each enabled unit
- for (i=0; i<BL_Texture::GetMaxUnits(); i++) {
- if (!mTextures[i].Ok()) continue;
- mTextures[i].ActivateTexture();
- mTextures[0].SetMapping(mMaterial->mapping[i].mapping);
- }
-
- if (!mUserDefBlend) {
- ras->SetAlphaBlend(mMaterial->alphablend);
- }
- else {
- ras->SetAlphaBlend(TF_SOLID);
- ras->SetAlphaBlend(-1); // indicates custom mode
-
- // tested to be valid enums
- glEnable(GL_BLEND);
- glBlendFunc(mBlendFunc[0], mBlendFunc[1]);
- }
-}
-
-void KX_BlenderMaterial::setBlenderShaderData( bool enable, RAS_IRasterizer *ras)
-{
- if ( !enable || !mBlenderShader->Ok() ) {
- ras->SetAlphaBlend(TF_SOLID);
-
- // frame cleanup.
- if (mLastBlenderShader) {
- mLastBlenderShader->SetProg(false);
- mLastBlenderShader= NULL;
- }
- else
- BL_Texture::DisableAllTextures();
-
- return;
- }
-
- if (!mBlenderShader->Equals(mLastBlenderShader)) {
- ras->SetAlphaBlend(mMaterial->alphablend);
-
- if (mLastBlenderShader)
- mLastBlenderShader->SetProg(false);
- else
- BL_Texture::DisableAllTextures();
-
- mBlenderShader->SetProg(true, ras->GetTime(), ras);
- mLastBlenderShader= mBlenderShader;
- }
-}
-
-void KX_BlenderMaterial::setTexData( bool enable, RAS_IRasterizer *ras)
-{
- BL_Texture::DisableAllTextures();
-
- if ( !enable ) {
- ras->SetAlphaBlend(TF_SOLID);
- return;
- }
-
- BL_Texture::ActivateFirst();
-
- if ( mMaterial->IdMode == DEFAULT_BLENDER ) {
- ras->SetAlphaBlend(mMaterial->alphablend);
- return;
- }
-
- if ( mMaterial->IdMode == TEXFACE ) {
- // no material connected to the object
- if ( mTextures[0].Ok() ) {
- mTextures[0].ActivateTexture();
- mTextures[0].setTexEnv(0, true);
- mTextures[0].SetMapping(mMaterial->mapping[0].mapping);
- ras->SetAlphaBlend(mMaterial->alphablend);
- }
- return;
- }
-
- int mode = 0,i=0;
- for (i=0; i<BL_Texture::GetMaxUnits(); i++) {
- if ( !mTextures[i].Ok() ) continue;
-
- mTextures[i].ActivateTexture();
- mTextures[i].setTexEnv(mMaterial);
- mode = mMaterial->mapping[i].mapping;
-
- if (mode &USEOBJ)
- setObjectMatrixData(i, ras);
- else
- mTextures[i].SetMapping(mode);
-
- if (!(mode &USEOBJ))
- setTexMatrixData( i );
- }
-
- if (!mUserDefBlend) {
- ras->SetAlphaBlend(mMaterial->alphablend);
- }
- else {
- ras->SetAlphaBlend(TF_SOLID);
- ras->SetAlphaBlend(-1); // indicates custom mode
-
- glEnable(GL_BLEND);
- glBlendFunc(mBlendFunc[0], mBlendFunc[1]);
- }
-}
-
-void
-KX_BlenderMaterial::ActivatShaders(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo)const
-{
- KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this);
-
- // reset...
- if (tmp->mMaterial->IsShared())
- cachingInfo =0;
-
- if (mLastBlenderShader) {
- mLastBlenderShader->SetProg(false);
- mLastBlenderShader= NULL;
- }
-
- if (GetCachingInfo() != cachingInfo) {
-
- if (!cachingInfo)
- tmp->setShaderData(false, rasty);
-
- cachingInfo = GetCachingInfo();
-
- if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)
- tmp->setShaderData(true, rasty);
- else if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW && mMaterial->alphablend != GEMAT_SOLID && !rasty->GetUsingOverrideShader())
- tmp->setShaderData(true, rasty);
- else
- tmp->setShaderData(false, rasty);
-
- if (mMaterial->ras_mode &TWOSIDED)
- rasty->SetCullFace(false);
- else
- rasty->SetCullFace(true);
-
- if ((mMaterial->ras_mode &WIRE) ||
- (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
- {
- if (mMaterial->ras_mode &WIRE)
- rasty->SetCullFace(false);
- rasty->SetLines(true);
- }
- else
- rasty->SetLines(false);
- ActivatGLMaterials(rasty);
- ActivateTexGen(rasty);
- }
-
- //ActivatGLMaterials(rasty);
- //ActivateTexGen(rasty);
-}
-
-void
-KX_BlenderMaterial::ActivateBlenderShaders(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo)const
-{
- KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this);
-
- if (mLastShader) {
- mLastShader->SetProg(false);
- mLastShader= NULL;
- }
-
- if (GetCachingInfo() != cachingInfo) {
- if (!cachingInfo)
- tmp->setBlenderShaderData(false, rasty);
-
- cachingInfo = GetCachingInfo();
-
- if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)
- tmp->setBlenderShaderData(true, rasty);
- else if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW && mMaterial->alphablend != GEMAT_SOLID && !rasty->GetUsingOverrideShader())
- tmp->setBlenderShaderData(true, rasty);
- else
- tmp->setBlenderShaderData(false, rasty);
-
- if (mMaterial->ras_mode &TWOSIDED)
- rasty->SetCullFace(false);
- else
- rasty->SetCullFace(true);
-
- if ((mMaterial->ras_mode &WIRE) ||
- (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
- {
- if (mMaterial->ras_mode &WIRE)
- rasty->SetCullFace(false);
- rasty->SetLines(true);
- }
- else
- rasty->SetLines(false);
-
- ActivatGLMaterials(rasty);
- mBlenderShader->SetAttribs(rasty, mMaterial);
- }
-}
-
-void
-KX_BlenderMaterial::ActivateMat(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo
- )const
-{
- KX_BlenderMaterial *tmp = const_cast<KX_BlenderMaterial*>(this);
-
- if (mLastShader) {
- mLastShader->SetProg(false);
- mLastShader= NULL;
- }
-
- if (mLastBlenderShader) {
- mLastBlenderShader->SetProg(false);
- mLastBlenderShader= NULL;
- }
-
- if (GetCachingInfo() != cachingInfo) {
- if (!cachingInfo)
- tmp->setTexData( false,rasty );
-
- cachingInfo = GetCachingInfo();
-
- if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED)
- tmp->setTexData( true,rasty );
- else if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW && mMaterial->alphablend != GEMAT_SOLID && !rasty->GetUsingOverrideShader())
- tmp->setTexData(true, rasty);
- else
- tmp->setTexData( false,rasty);
-
- if (mMaterial->ras_mode &TWOSIDED)
- rasty->SetCullFace(false);
- else
- rasty->SetCullFace(true);
-
- if ((mMaterial->ras_mode &WIRE) ||
- (rasty->GetDrawingMode() <= RAS_IRasterizer::KX_WIREFRAME))
- {
- if (mMaterial->ras_mode &WIRE)
- rasty->SetCullFace(false);
- rasty->SetLines(true);
- }
- else
- rasty->SetLines(false);
- ActivatGLMaterials(rasty);
- ActivateTexGen(rasty);
- }
-
- //ActivatGLMaterials(rasty);
- //ActivateTexGen(rasty);
-}
-
-bool
-KX_BlenderMaterial::Activate(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo
- )const
-{
- if (GLEW_ARB_shader_objects && (mShader && mShader->Ok())) {
- if ((mPass++) < mShader->getNumPass() ) {
- ActivatShaders(rasty, cachingInfo);
- return true;
- }
- else {
- if (mShader == mLastShader) {
- mShader->SetProg(false);
- mLastShader = NULL;
- }
- mPass = 0;
- return false;
- }
- }
- else if ( GLEW_ARB_shader_objects && (mBlenderShader && mBlenderShader->Ok() ) ) {
- if (mPass++ == 0) {
- ActivateBlenderShaders(rasty, cachingInfo);
- return true;
- }
- else {
- mPass = 0;
- return false;
- }
- }
- else {
- if (mPass++ == 0) {
- ActivateMat(rasty, cachingInfo);
- return true;
- }
- else {
- mPass = 0;
- return false;
- }
- }
-}
-
-bool KX_BlenderMaterial::UsesLighting(RAS_IRasterizer *rasty) const
-{
- if (!RAS_IPolyMaterial::UsesLighting(rasty))
- return false;
-
- if (mShader && mShader->Ok())
- return true;
- else if (mBlenderShader && mBlenderShader->Ok())
- return false;
- else
- return true;
-}
-
-void KX_BlenderMaterial::ActivateMeshSlot(const RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const
-{
- if (mShader && GLEW_ARB_shader_objects) {
- mShader->Update(ms, rasty);
- }
- else if (mBlenderShader && GLEW_ARB_shader_objects) {
- int alphablend;
-
- mBlenderShader->Update(ms, rasty);
-
- /* we do blend modes here, because they can change per object
- * with the same material due to obcolor/obalpha */
- alphablend = mBlenderShader->GetAlphaBlend();
- if (ELEM(alphablend, GEMAT_SOLID, GEMAT_ALPHA, GEMAT_ALPHA_SORT) && mMaterial->alphablend != GEMAT_SOLID)
- alphablend = mMaterial->alphablend;
-
- rasty->SetAlphaBlend(alphablend);
- }
-}
-
-void KX_BlenderMaterial::ActivatGLMaterials( RAS_IRasterizer* rasty )const
-{
- if (mShader || !mBlenderShader) {
- rasty->SetSpecularity(
- mMaterial->speccolor[0]*mMaterial->spec_f,
- mMaterial->speccolor[1]*mMaterial->spec_f,
- mMaterial->speccolor[2]*mMaterial->spec_f,
- mMaterial->spec_f
- );
-
- rasty->SetShinyness( mMaterial->hard );
-
- rasty->SetDiffuse(
- mMaterial->matcolor[0]*mMaterial->ref+mMaterial->emit,
- mMaterial->matcolor[1]*mMaterial->ref+mMaterial->emit,
- mMaterial->matcolor[2]*mMaterial->ref+mMaterial->emit,
- 1.0f);
-
- rasty->SetEmissive(
- mMaterial->matcolor[0]*mMaterial->emit,
- mMaterial->matcolor[1]*mMaterial->emit,
- mMaterial->matcolor[2]*mMaterial->emit,
- 1.0f );
-
- rasty->SetAmbient(mMaterial->amb);
- }
-
- if (mMaterial->material)
- rasty->SetPolygonOffset(-mMaterial->material->zoffs, 0.0f);
-}
-
-
-void KX_BlenderMaterial::ActivateTexGen(RAS_IRasterizer *ras) const
-{
- if (ras->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED ||
- (ras->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW && mMaterial->alphablend != GEMAT_SOLID && !ras->GetUsingOverrideShader())) {
- ras->SetAttribNum(0);
- if (mShader && GLEW_ARB_shader_objects) {
- if (mShader->GetAttribute() == BL_Shader::SHD_TANGENT) {
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXCO_DISABLE, 0);
- ras->SetAttrib(RAS_IRasterizer::RAS_TEXTANGENT, 1);
- ras->SetAttribNum(2);
- }
- }
-
- ras->SetTexCoordNum(mMaterial->num_enabled);
-
- for (int i=0; i<BL_Texture::GetMaxUnits(); i++) {
- int mode = mMaterial->mapping[i].mapping;
-
- if ( mode &(USEREFL|USEOBJ))
- ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_GEN, i);
- else if (mode &USEORCO)
- ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_ORCO, i);
- else if (mode &USENORM)
- ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_NORM, i);
- else if (mode &USEUV)
- ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_UV, i);
- else if (mode &USETANG)
- ras->SetTexCoord(RAS_IRasterizer::RAS_TEXTANGENT, i);
- else
- ras->SetTexCoord(RAS_IRasterizer::RAS_TEXCO_DISABLE, i);
- }
- }
-}
-
-void KX_BlenderMaterial::setTexMatrixData(int i)
-{
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
-
- if ( GLEW_ARB_texture_cube_map &&
- mTextures[i].GetTextureType() == GL_TEXTURE_CUBE_MAP_ARB &&
- mMaterial->mapping[i].mapping & USEREFL) {
- glScalef(
- mMaterial->mapping[i].scale[0],
- -mMaterial->mapping[i].scale[1],
- -mMaterial->mapping[i].scale[2]
- );
- }
- else
- {
- glScalef(
- mMaterial->mapping[i].scale[0],
- mMaterial->mapping[i].scale[1],
- mMaterial->mapping[i].scale[2]
- );
- }
- glTranslatef(
- mMaterial->mapping[i].offsets[0],
- mMaterial->mapping[i].offsets[1],
- mMaterial->mapping[i].offsets[2]
- );
-
- glMatrixMode(GL_MODELVIEW);
-
-}
-
-static void GetProjPlane(BL_Material *mat, int index,int num, float*param)
-{
- param[0]=param[1]=param[2]=param[3]=0.f;
- if ( mat->mapping[index].projplane[num] == PROJX )
- param[0] = 1.f;
- else if ( mat->mapping[index].projplane[num] == PROJY )
- param[1] = 1.f;
- else if ( mat->mapping[index].projplane[num] == PROJZ)
- param[2] = 1.f;
-}
-
-void KX_BlenderMaterial::setObjectMatrixData(int i, RAS_IRasterizer *ras)
-{
- KX_GameObject *obj =
- (KX_GameObject*)
- mScene->GetObjectList()->FindValue(mMaterial->mapping[i].objconame);
-
- if (!obj) return;
-
- glTexGeni(GL_S, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );
- glTexGeni(GL_T, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );
- glTexGeni(GL_R, GL_TEXTURE_GEN_MODE, GL_EYE_LINEAR );
-
- GLenum plane = GL_EYE_PLANE;
-
- // figure plane gen
- float proj[4] = {0.f,0.f,0.f,0.f};
- GetProjPlane(mMaterial, i, 0, proj);
- glTexGenfv(GL_S, plane, proj);
-
- GetProjPlane(mMaterial, i, 1, proj);
- glTexGenfv(GL_T, plane, proj);
-
- GetProjPlane(mMaterial, i, 2, proj);
- glTexGenfv(GL_R, plane, proj);
-
- glEnable(GL_TEXTURE_GEN_S);
- glEnable(GL_TEXTURE_GEN_T);
- glEnable(GL_TEXTURE_GEN_R);
-
- const MT_Matrix4x4& mvmat = ras->GetViewMatrix();
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glScalef(
- mMaterial->mapping[i].scale[0],
- mMaterial->mapping[i].scale[1],
- mMaterial->mapping[i].scale[2]
- );
-
- MT_Point3 pos = obj->NodeGetWorldPosition();
- MT_Vector4 matmul = MT_Vector4(pos[0], pos[1], pos[2], 1.f);
- MT_Vector4 t = mvmat*matmul;
-
- glTranslatef( (float)(-t[0]), (float)(-t[1]), (float)(-t[2]) );
-
- glMatrixMode(GL_MODELVIEW);
-
-}
-
-// ------------------------------------
-void KX_BlenderMaterial::UpdateIPO(
- MT_Vector4 rgba,
- MT_Vector3 specrgb,
- MT_Scalar hard,
- MT_Scalar spec,
- MT_Scalar ref,
- MT_Scalar emit,
- MT_Scalar alpha
- )
-{
- // only works one deep now
-
- // GLSL Multitexture Input
- mMaterial->material->specr = mMaterial->speccolor[0] = (float)(specrgb)[0];
- mMaterial->material->specg = mMaterial->speccolor[1] = (float)(specrgb)[1];
- mMaterial->material->specb = mMaterial->speccolor[2] = (float)(specrgb)[2];
- mMaterial->material->r = mMaterial->matcolor[0] = (float)(rgba[0]);
- mMaterial->material->g = mMaterial->matcolor[1] = (float)(rgba[1]);
- mMaterial->material->b = mMaterial->matcolor[2] = (float)(rgba[2]);
- mMaterial->material->alpha = mMaterial->alpha = (float)(rgba[3]);
- mMaterial->material->har = mMaterial->hard = (float)(hard);
- mMaterial->material->emit = mMaterial->emit = (float)(emit);
- mMaterial->material->spec = mMaterial->spec_f = (float)(spec);
- mMaterial->material->ref = mMaterial->ref = (float)(ref);
-}
-
-void KX_BlenderMaterial::Replace_IScene(SCA_IScene *val)
-{
- mScene= static_cast<KX_Scene *>(val);
-
- OnConstruction();
-}
-
-BL_Material *KX_BlenderMaterial::GetBLMaterial()
-{
- return mMaterial;
-}
-
-void KX_BlenderMaterial::SetBlenderGLSLShader()
-{
- if (!mBlenderShader)
- mBlenderShader = new BL_BlenderShader(mScene, mMaterial->material, mLightLayer);
-
- if (!mBlenderShader->Ok()) {
- delete mBlenderShader;
- mBlenderShader = 0;
- }
-}
-
-#ifdef USE_MATHUTILS
-
-#define MATHUTILS_COL_CB_MATERIAL_SPECULAR_COLOR 1
-#define MATHUTILS_COL_CB_MATERIAL_DIFFUSE_COLOR 2
-
-static unsigned char mathutils_kxblendermaterial_color_cb_index = -1; /* index for our callbacks */
-
-static int mathutils_kxblendermaterial_generic_check(BaseMathObject *bmo)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>BGE_PROXY_REF(bmo->cb_user);
- if (!self)
- return -1;
-
- return 0;
-}
-
-static int mathutils_kxblendermaterial_color_get(BaseMathObject *bmo, int subtype)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial*>BGE_PROXY_REF(bmo->cb_user);
- if (!self)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_COL_CB_MATERIAL_DIFFUSE_COLOR:
- {
- copy_v3_v3(bmo->data, self->GetBLMaterial()->matcolor);
- break;
- }
- case MATHUTILS_COL_CB_MATERIAL_SPECULAR_COLOR:
- {
- copy_v3_v3(bmo->data, self->GetBLMaterial()->speccolor);
- break;
- }
- }
-
- return 0;
-}
-
-static int mathutils_kxblendermaterial_color_set(BaseMathObject *bmo, int subtype)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>BGE_PROXY_REF(bmo->cb_user);
- if (!self)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_COL_CB_MATERIAL_DIFFUSE_COLOR:
- {
- BL_Material *mat = self->GetBLMaterial();
- copy_v3_v3(mat->matcolor, bmo->data);
- mat->material->r = bmo->data[0];
- mat->material->g = bmo->data[1];
- mat->material->b = bmo->data[2];
- break;
- }
- case MATHUTILS_COL_CB_MATERIAL_SPECULAR_COLOR:
- {
- BL_Material *mat = self->GetBLMaterial();
- copy_v3_v3(mat->speccolor, bmo->data);
- mat->material->specr = bmo->data[0];
- mat->material->specg = bmo->data[1];
- mat->material->specb = bmo->data[2];
- break;
- }
- }
-
- return 0;
-}
-
-static int mathutils_kxblendermaterial_color_get_index(BaseMathObject *bmo, int subtype, int index)
-{
- /* lazy, avoid repeteing the case statement */
- if (mathutils_kxblendermaterial_color_get(bmo, subtype) == -1)
- return -1;
- return 0;
-}
-
-static int mathutils_kxblendermaterial_color_set_index(BaseMathObject *bmo, int subtype, int index)
-{
- float f = bmo->data[index];
-
- /* lazy, avoid repeateing the case statement */
- if (mathutils_kxblendermaterial_color_get(bmo, subtype) == -1)
- return -1;
-
- bmo->data[index] = f;
- return mathutils_kxblendermaterial_color_set(bmo, subtype);
-}
-
-static Mathutils_Callback mathutils_kxblendermaterial_color_cb = {
- mathutils_kxblendermaterial_generic_check,
- mathutils_kxblendermaterial_color_get,
- mathutils_kxblendermaterial_color_set,
- mathutils_kxblendermaterial_color_get_index,
- mathutils_kxblendermaterial_color_set_index
-};
-
-
-void KX_BlenderMaterial_Mathutils_Callback_Init()
-{
- // register mathutils callbacks, ok to run more than once.
- mathutils_kxblendermaterial_color_cb_index = Mathutils_RegisterCallback(&mathutils_kxblendermaterial_color_cb);
-}
-
-#endif // USE_MATHUTILS
-
-#ifdef WITH_PYTHON
-
-PyMethodDef KX_BlenderMaterial::Methods[] =
-{
- KX_PYMETHODTABLE( KX_BlenderMaterial, getShader ),
- KX_PYMETHODTABLE( KX_BlenderMaterial, getMaterialIndex ),
- KX_PYMETHODTABLE( KX_BlenderMaterial, getTextureBindcode ),
- KX_PYMETHODTABLE( KX_BlenderMaterial, setBlending ),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_BlenderMaterial::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("shader", KX_BlenderMaterial, pyattr_get_shader),
- KX_PYATTRIBUTE_RO_FUNCTION("material_index", KX_BlenderMaterial, pyattr_get_materialIndex),
- KX_PYATTRIBUTE_RW_FUNCTION("blending", KX_BlenderMaterial, pyattr_get_blending, pyattr_set_blending),
- KX_PYATTRIBUTE_RW_FUNCTION("alpha", KX_BlenderMaterial, pyattr_get_alpha, pyattr_set_alpha),
- KX_PYATTRIBUTE_RW_FUNCTION("hardness", KX_BlenderMaterial, pyattr_get_hardness, pyattr_set_hardness),
- KX_PYATTRIBUTE_RW_FUNCTION("specularIntensity", KX_BlenderMaterial, pyattr_get_specular_intensity, pyattr_set_specular_intensity),
- KX_PYATTRIBUTE_RW_FUNCTION("specularColor", KX_BlenderMaterial, pyattr_get_specular_color, pyattr_set_specular_color),
- KX_PYATTRIBUTE_RW_FUNCTION("diffuseIntensity", KX_BlenderMaterial, pyattr_get_diffuse_intensity, pyattr_set_diffuse_intensity),
- KX_PYATTRIBUTE_RW_FUNCTION("diffuseColor", KX_BlenderMaterial, pyattr_get_diffuse_color, pyattr_set_diffuse_color),
- KX_PYATTRIBUTE_RW_FUNCTION("emit", KX_BlenderMaterial, pyattr_get_emit, pyattr_set_emit),
-
- { NULL } //Sentinel
-};
-
-PyTypeObject KX_BlenderMaterial::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_BlenderMaterial",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyObject *KX_BlenderMaterial::pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial* self = static_cast<KX_BlenderMaterial*>(self_v);
- return self->PygetShader(NULL, NULL);
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial* self = static_cast<KX_BlenderMaterial*>(self_v);
- return PyLong_FromLong(self->GetMaterialIndex());
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial* self = static_cast<KX_BlenderMaterial*>(self_v);
- unsigned int* bfunc = self->getBlendFunc();
- return Py_BuildValue("(ll)", (long int)bfunc[0], (long int)bfunc[1]);
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- return PyFloat_FromDouble(self->GetBLMaterial()->alpha);
-}
-
-int KX_BlenderMaterial::pyattr_set_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- float val = PyFloat_AsDouble(value);
-
- if (val == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_AttributeError, "material.%s = float: KX_BlenderMaterial, expected a float", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
-
- CLAMP(val, 0.0f, 1.0f);
-
- BL_Material *mat = self->GetBLMaterial();
- mat->alpha = mat->material->alpha = val;
- return PY_SET_ATTR_SUCCESS;
-}
-PyObject *KX_BlenderMaterial::pyattr_get_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- return PyLong_FromLong(self->GetBLMaterial()->hard);
-}
-
-int KX_BlenderMaterial::pyattr_set_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- int val = PyLong_AsLong(value);
-
- if (val == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_AttributeError, "material.%s = int: KX_BlenderMaterial, expected a int", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
-
- CLAMP(val, 1, 511);
-
- BL_Material *mat = self->GetBLMaterial();
- mat->hard = mat->material->har = val;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- return PyFloat_FromDouble(self->GetBLMaterial()->spec_f);
-}
-
-int KX_BlenderMaterial::pyattr_set_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- float val = PyFloat_AsDouble(value);
-
- if (val == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_AttributeError, "material.%s = float: KX_BlenderMaterial, expected a float", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
-
- CLAMP(val, 0.0f, 1.0f);
-
- BL_Material *mat = self->GetBLMaterial();
- mat->spec_f = mat->material->spec = val;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Color_CreatePyObject_cb(BGE_PROXY_FROM_REF(self_v), mathutils_kxblendermaterial_color_cb_index, MATHUTILS_COL_CB_MATERIAL_SPECULAR_COLOR);
-#else
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- return PyColorFromVector(MT_Vector3(self->GetBLMaterial()->speccolor));
-#endif
-}
-
-int KX_BlenderMaterial::pyattr_set_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- MT_Vector3 color;
- if (!PyVecTo(value, color))
- return PY_SET_ATTR_FAIL;
-
- BL_Material *mat = self->GetBLMaterial();
- color.getValue(mat->speccolor);
- mat->material->specr = color[0];
- mat->material->specg = color[1];
- mat->material->specb = color[2];
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- return PyFloat_FromDouble(self->GetBLMaterial()->ref);
-}
-
-int KX_BlenderMaterial::pyattr_set_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- float val = PyFloat_AsDouble(value);
-
- if (val == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_AttributeError, "material.%s = float: KX_BlenderMaterial, expected a float", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
-
- CLAMP(val, 0.0f, 1.0f);
-
- BL_Material *mat = self->GetBLMaterial();
- mat->ref = mat->material->ref = val;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Color_CreatePyObject_cb(BGE_PROXY_FROM_REF(self_v), mathutils_kxblendermaterial_color_cb_index, MATHUTILS_COL_CB_MATERIAL_DIFFUSE_COLOR);
-#else
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- return PyColorFromVector(MT_Vector3(self->GetBLMaterial()->matcolor));
-#endif
-}
-
-int KX_BlenderMaterial::pyattr_set_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- MT_Vector3 color;
- if (!PyVecTo(value, color))
- return PY_SET_ATTR_FAIL;
-
- BL_Material *mat = self->GetBLMaterial();
- color.getValue(mat->matcolor);
- mat->material->r = color[0];
- mat->material->g = color[1];
- mat->material->b = color[2];
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_BlenderMaterial::pyattr_get_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- return PyFloat_FromDouble(self->GetBLMaterial()->emit);
-}
-
-int KX_BlenderMaterial::pyattr_set_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial *self = static_cast<KX_BlenderMaterial *>(self_v);
- float val = PyFloat_AsDouble(value);
-
- if (val == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_AttributeError, "material.%s = float: KX_BlenderMaterial, expected a float", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
-
- CLAMP(val, 0.0f, 2.0f);
-
- BL_Material *mat = self->GetBLMaterial();
- mat->emit = mat->material->emit = val;
- return PY_SET_ATTR_SUCCESS;
-}
-
-int KX_BlenderMaterial::pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_BlenderMaterial* self = static_cast<KX_BlenderMaterial*>(self_v);
- PyObject *obj = self->PysetBlending(value, NULL);
- if (obj)
- {
- Py_DECREF(obj);
- return 0;
- }
- return -1;
-}
-
-KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getShader , "getShader()")
-{
- if ( !GLEW_ARB_fragment_shader) {
- if (!mModified)
- spit("Fragment shaders not supported");
-
- mModified = true;
- Py_RETURN_NONE;
- }
-
- if ( !GLEW_ARB_vertex_shader) {
- if (!mModified)
- spit("Vertex shaders not supported");
-
- mModified = true;
- Py_RETURN_NONE;
- }
-
- if (!GLEW_ARB_shader_objects) {
- if (!mModified)
- spit("GLSL not supported");
- mModified = true;
- Py_RETURN_NONE;
- }
- else {
- // returns Py_None on error
- // the calling script will need to check
-
- if (!mShader && !mModified) {
- mShader = new BL_Shader();
- mModified = true;
-
- // Using a custom shader, make sure to initialize textures
- InitTextures();
- }
-
- if (mShader && !mShader->GetError()) {
- m_flag &= ~RAS_BLENDERGLSL;
- mMaterial->SetSharedMaterial(true);
- mScene->GetBucketManager()->ReleaseDisplayLists(this);
- return mShader->GetProxy();
- }
- else {
- // decref all references to the object
- // then delete it!
- // We will then go back to fixed functionality
- // for this material
- if (mShader) {
- delete mShader; /* will handle python de-referencing */
- mShader=0;
- }
- }
- Py_RETURN_NONE;
- }
- PyErr_SetString(PyExc_ValueError, "material.getShader(): KX_BlenderMaterial, GLSL Error");
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getMaterialIndex, "getMaterialIndex()")
-{
- return PyLong_FromLong(GetMaterialIndex());
-}
-
-KX_PYMETHODDEF_DOC( KX_BlenderMaterial, getTexture, "getTexture( index )" )
-{
- // TODO: enable python switching
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC( KX_BlenderMaterial, setTexture , "setTexture( index, tex)")
-{
- // TODO: enable python switching
- return NULL;
-}
-
-static const unsigned int GL_array[11] = {
- GL_ZERO,
- GL_ONE,
- GL_SRC_COLOR,
- GL_ONE_MINUS_SRC_COLOR,
- GL_DST_COLOR,
- GL_ONE_MINUS_DST_COLOR,
- GL_SRC_ALPHA,
- GL_ONE_MINUS_SRC_ALPHA,
- GL_DST_ALPHA,
- GL_ONE_MINUS_DST_ALPHA,
- GL_SRC_ALPHA_SATURATE
-};
-
-KX_PYMETHODDEF_DOC( KX_BlenderMaterial, setBlending , "setBlending( bge.logic.src, bge.logic.dest)")
-{
- unsigned int b[2];
- if (PyArg_ParseTuple(args, "ii:setBlending", &b[0], &b[1]))
- {
- bool value_found[2] = {false, false};
- for (int i=0; i<11; i++)
- {
- if (b[0] == GL_array[i]) {
- value_found[0] = true;
- mBlendFunc[0] = b[0];
- }
- if (b[1] == GL_array[i]) {
- value_found[1] = true;
- mBlendFunc[1] = b[1];
- }
- if (value_found[0] && value_found[1]) break;
- }
- if (!value_found[0] || !value_found[1]) {
- PyErr_SetString(PyExc_ValueError, "material.setBlending(int, int): KX_BlenderMaterial, invalid enum.");
- return NULL;
- }
- mUserDefBlend = true;
- Py_RETURN_NONE;
- }
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC(KX_BlenderMaterial, getTextureBindcode, "getTextureBindcode(texslot)")
-{
- unsigned int texslot;
- if (!PyArg_ParseTuple(args, "i:texslot", &texslot)) {
- PyErr_SetString(PyExc_ValueError, "material.getTextureBindcode(texslot): KX_BlenderMaterial, expected an int.");
- return NULL;
- }
- Image *ima = getImage(texslot);
- if (ima) {
- unsigned int *bindcode = ima->bindcode;
- return PyLong_FromLong(*bindcode);
- }
- PyErr_SetString(PyExc_ValueError, "material.getTextureBindcode(texslot): KX_BlenderMaterial, invalid texture slot.");
- return NULL;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_BlenderMaterial.h b/source/gameengine/Ketsji/KX_BlenderMaterial.h
deleted file mode 100644
index a3d10c0a89d..00000000000
--- a/source/gameengine/Ketsji/KX_BlenderMaterial.h
+++ /dev/null
@@ -1,201 +0,0 @@
-
-/** \file KX_BlenderMaterial.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_BLENDERMATERIAL_H__
-#define __KX_BLENDERMATERIAL_H__
-
-#include <vector>
-
-
-#include "RAS_IPolygonMaterial.h"
-#include "BL_Material.h"
-#include "BL_Texture.h"
-#include "BL_Shader.h"
-#include "BL_BlenderShader.h"
-
-#include "EXP_PyObjectPlus.h"
-
-#include "MT_Vector3.h"
-#include "MT_Vector4.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-#include "SCA_IScene.h" /* only for Replace_IScene */
-#include "KX_Scene.h"
-
-struct MTFace;
-class KX_Scene;
-
-
-#ifdef USE_MATHUTILS
-void KX_BlenderMaterial_Mathutils_Callback_Init(void);
-#endif
-
-class KX_BlenderMaterial : public PyObjectPlus, public RAS_IPolyMaterial
-{
- Py_Header
-public:
- // --------------------------------
- KX_BlenderMaterial();
- void Initialize(
- class KX_Scene* scene,
- BL_Material* mat,
- GameSettings* game,
- int lightlayer
- );
-
- virtual ~KX_BlenderMaterial();
-
- // --------------------------------
- virtual TCachingInfo GetCachingInfo(void) const {
- return (void*) this;
- }
-
- virtual
- bool Activate(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo
- ) const;
-
- virtual
- void ActivateMeshSlot(
- const RAS_MeshSlot & ms,
- RAS_IRasterizer* rasty
- ) const;
-
- void ActivateMat(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo
- )const;
-
- void ActivatShaders(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo
- )const;
-
- void ActivateBlenderShaders(
- RAS_IRasterizer* rasty,
- TCachingInfo& cachingInfo
- )const;
-
- Material* GetBlenderMaterial() const;
- Image* GetBlenderImage() const;
- MTexPoly *GetMTexPoly() const;
- unsigned int* GetMCol() const;
- BL_Texture * getTex (unsigned int idx) {
- return (idx < MAXTEX) ? mTextures + idx : NULL;
- }
- Image * getImage (unsigned int idx) {
- return (idx < MAXTEX && mMaterial) ? mMaterial->img[idx] : NULL;
- }
- unsigned int* getBlendFunc() {
- return mBlendFunc;
- }
- // for ipos
- void UpdateIPO(
- MT_Vector4 rgba, MT_Vector3 specrgb,
- MT_Scalar hard, MT_Scalar spec,
- MT_Scalar ref, MT_Scalar emit, MT_Scalar alpha
- );
-
- virtual void Replace_IScene(SCA_IScene *val);
-
- BL_Material *GetBLMaterial();
-
-#ifdef WITH_PYTHON
- // --------------------------------
- virtual PyObject *py_repr(void) { return PyUnicode_From_STR_String(mMaterial->matname); }
-
- static PyObject *pyattr_get_shader(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_materialIndex(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_blending(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_alpha(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_hardness(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_specular_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_specular_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_diffuse_intensity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_diffuse_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_emit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- KX_PYMETHOD_DOC(KX_BlenderMaterial, getShader);
- KX_PYMETHOD_DOC(KX_BlenderMaterial, getMaterialIndex);
- KX_PYMETHOD_DOC(KX_BlenderMaterial, getTexture);
- KX_PYMETHOD_DOC(KX_BlenderMaterial, setTexture);
- KX_PYMETHOD_DOC(KX_BlenderMaterial, getTextureBindcode);
-
- KX_PYMETHOD_DOC(KX_BlenderMaterial, setBlending);
-#endif /* WITH_PYTHON */
-
- // --------------------------------
- // pre calculate to avoid pops/lag at startup
- virtual void OnConstruction();
-
- static void EndFrame();
-
-private:
- BL_Material* mMaterial;
- BL_Shader* mShader;
- BL_BlenderShader* mBlenderShader;
- KX_Scene* mScene;
- BL_Texture mTextures[MAXTEX]; // texture array
- bool mUserDefBlend;
- unsigned int mBlendFunc[2];
- bool mModified;
- bool mConstructed; // if false, don't clean on exit
- int mLightLayer;
-
- struct {
- float r, g, b, a;
- float specr, specg, specb;
- float spec;
- float ref;
- float hardness;
- float emit;
- } mSavedData;
-
- void InitTextures();
-
- void SetBlenderGLSLShader();
-
- void ActivatGLMaterials( RAS_IRasterizer* rasty )const;
- void ActivateTexGen( RAS_IRasterizer *ras ) const;
-
- bool UsesLighting(RAS_IRasterizer *rasty) const;
- void GetMaterialRGBAColor(unsigned char *rgba) const;
- Scene* GetBlenderScene() const;
- void ReleaseMaterial();
-
- // message centers
- void setTexData( bool enable,RAS_IRasterizer *ras);
- void setBlenderShaderData( bool enable, RAS_IRasterizer *ras);
- void setShaderData( bool enable, RAS_IRasterizer *ras);
-
- void setObjectMatrixData(int i, RAS_IRasterizer *ras);
- void setTexMatrixData(int i);
-
- void setLightData();
-
- // cleanup stuff
- void OnExit();
-
- // shader chacing
- static BL_BlenderShader *mLastBlenderShader;
- static BL_Shader *mLastShader;
-
- mutable int mPass;
-};
-
-
-#endif
diff --git a/source/gameengine/Ketsji/KX_Camera.cpp b/source/gameengine/Ketsji/KX_Camera.cpp
deleted file mode 100644
index 89aea80bb67..00000000000
--- a/source/gameengine/Ketsji/KX_Camera.cpp
+++ /dev/null
@@ -1,1167 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Camera in the gameengine. Cameras are also used for views.
- */
-
-/** \file gameengine/Ketsji/KX_Camera.cpp
- * \ingroup ketsji
- */
-
-
-#include "glew-mx.h"
-#include "KX_Camera.h"
-#include "KX_Scene.h"
-#include "KX_PythonInit.h"
-#include "EXP_Python.h"
-#include "KX_PyMath.h"
-
-#include "RAS_ICanvas.h"
-
-KX_Camera::KX_Camera(void* sgReplicationInfo,
- SG_Callbacks callbacks,
- const RAS_CameraData& camdata,
- bool frustum_culling,
- bool delete_node)
- :
- KX_GameObject(sgReplicationInfo,callbacks),
- m_camdata(camdata),
- m_dirty(true),
- m_normalized(false),
- m_frustum_culling(frustum_culling),
- m_set_projection_matrix(false),
- m_set_frustum_center(false),
- m_delete_node(delete_node)
-{
- // setting a name would be nice...
- m_name = "cam";
- m_projection_matrix.setIdentity();
- m_modelview_matrix.setIdentity();
-}
-
-
-KX_Camera::~KX_Camera()
-{
- if (m_delete_node && m_pSGNode)
- {
- // for shadow camera, avoids memleak
- delete m_pSGNode;
- m_pSGNode = NULL;
- }
-}
-
-
-CValue* KX_Camera::GetReplica()
-{
- KX_Camera* replica = new KX_Camera(*this);
-
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-void KX_Camera::ProcessReplica()
-{
- KX_GameObject::ProcessReplica();
- // replicated camera are always registered in the scene
- m_delete_node = false;
-}
-
-MT_Transform KX_Camera::GetWorldToCamera() const
-{
- MT_Transform camtrans;
- camtrans.invert(MT_Transform(NodeGetWorldPosition(), NodeGetWorldOrientation()));
-
- return camtrans;
-}
-
-
-
-MT_Transform KX_Camera::GetCameraToWorld() const
-{
- return MT_Transform(NodeGetWorldPosition(), NodeGetWorldOrientation());
-}
-
-
-
-void KX_Camera::CorrectLookUp(MT_Scalar speed)
-{
-}
-
-
-
-const MT_Point3 KX_Camera::GetCameraLocation() const
-{
- /* this is the camera locatio in cam coords... */
- //return m_trans1.getOrigin();
- //return MT_Point3(0,0,0); <-----
- /* .... I want it in world coords */
- //MT_Transform trans;
- //trans.setBasis(NodeGetWorldOrientation());
-
- return NodeGetWorldPosition();
-}
-
-
-
-/* I want the camera orientation as well. */
-const MT_Quaternion KX_Camera::GetCameraOrientation() const
-{
- return NodeGetWorldOrientation().getRotation();
-}
-
-
-
-/**
- * Sets the projection matrix that is used by the rasterizer.
- */
-void KX_Camera::SetProjectionMatrix(const MT_Matrix4x4 & mat)
-{
- m_projection_matrix = mat;
- m_dirty = true;
- m_set_projection_matrix = true;
- m_set_frustum_center = false;
-}
-
-
-
-/**
- * Sets the modelview matrix that is used by the rasterizer.
- */
-void KX_Camera::SetModelviewMatrix(const MT_Matrix4x4 & mat)
-{
- m_modelview_matrix = mat;
- m_dirty = true;
- m_set_frustum_center = false;
-}
-
-
-
-/**
- * Gets the projection matrix that is used by the rasterizer.
- */
-const MT_Matrix4x4& KX_Camera::GetProjectionMatrix() const
-{
- return m_projection_matrix;
-}
-
-
-
-/**
- * Gets the modelview matrix that is used by the rasterizer.
- */
-const MT_Matrix4x4& KX_Camera::GetModelviewMatrix() const
-{
- return m_modelview_matrix;
-}
-
-
-bool KX_Camera::hasValidProjectionMatrix() const
-{
- return m_set_projection_matrix;
-}
-
-void KX_Camera::InvalidateProjectionMatrix(bool valid)
-{
- m_set_projection_matrix = valid;
-}
-
-
-/**
- * These getters retrieve the clip data and the focal length
- */
-float KX_Camera::GetLens() const
-{
- return m_camdata.m_lens;
-}
-
-float KX_Camera::GetScale() const
-{
- return m_camdata.m_scale;
-}
-
-/**
- * Gets the horizontal size of the sensor - for camera matching.
- */
-float KX_Camera::GetSensorWidth() const
-{
- return m_camdata.m_sensor_x;
-}
-
-/**
- * Gets the vertical size of the sensor - for camera matching.
- */
-float KX_Camera::GetSensorHeight() const
-{
- return m_camdata.m_sensor_y;
-}
-/** Gets the mode FOV is calculating from sensor dimensions */
-short KX_Camera::GetSensorFit() const
-{
- return m_camdata.m_sensor_fit;
-}
-
-/**
- * Gets the horizontal shift of the sensor - for camera matching.
- */
-float KX_Camera::GetShiftHorizontal() const
-{
- return m_camdata.m_shift_x;
-}
-
-/**
- * Gets the vertical shift of the sensor - for camera matching.
- */
-float KX_Camera::GetShiftVertical() const
-{
- return m_camdata.m_shift_y;
-}
-
-float KX_Camera::GetCameraNear() const
-{
- return m_camdata.m_clipstart;
-}
-
-
-
-float KX_Camera::GetCameraFar() const
-{
- return m_camdata.m_clipend;
-}
-
-float KX_Camera::GetFocalLength() const
-{
- return m_camdata.m_focallength;
-}
-
-
-
-RAS_CameraData* KX_Camera::GetCameraData()
-{
- return &m_camdata;
-}
-
-void KX_Camera::ExtractClipPlanes()
-{
- if (!m_dirty)
- return;
-
- MT_Matrix4x4 m = m_projection_matrix * m_modelview_matrix;
- // Left clip plane
- m_planes[0] = m[3] + m[0];
- // Right clip plane
- m_planes[1] = m[3] - m[0];
- // Top clip plane
- m_planes[2] = m[3] - m[1];
- // Bottom clip plane
- m_planes[3] = m[3] + m[1];
- // Near clip plane
- m_planes[4] = m[3] + m[2];
- // Far clip plane
- m_planes[5] = m[3] - m[2];
-
- m_dirty = false;
- m_normalized = false;
-}
-
-void KX_Camera::NormalizeClipPlanes()
-{
- if (m_normalized)
- return;
-
- for (unsigned int p = 0; p < 6; p++)
- {
- MT_Scalar factor = sqrtf(m_planes[p][0]*m_planes[p][0] + m_planes[p][1]*m_planes[p][1] + m_planes[p][2]*m_planes[p][2]);
- if (!MT_fuzzyZero(factor))
- m_planes[p] /= factor;
- }
-
- m_normalized = true;
-}
-
-void KX_Camera::ExtractFrustumSphere()
-{
- if (m_set_frustum_center)
- return;
-
- // compute sphere for the general case and not only symmetric frustum:
- // the mirror code in ImageRender can use very asymmetric frustum.
- // We will put the sphere center on the line that goes from origin to the center of the far clipping plane
- // This is the optimal position if the frustum is symmetric or very asymmetric and probably close
- // to optimal for the general case. The sphere center position is computed so that the distance to
- // the near and far extreme frustum points are equal.
-
- // get the transformation matrix from device coordinate to camera coordinate
- MT_Matrix4x4 clip_camcs_matrix = m_projection_matrix;
- clip_camcs_matrix.invert();
-
- if (m_projection_matrix[3][3] == MT_Scalar(0.0f))
- {
- // frustum projection
- // detect which of the corner of the far clipping plane is the farthest to the origin
- MT_Vector4 nfar; // far point in device normalized coordinate
- MT_Point3 farpoint; // most extreme far point in camera coordinate
- MT_Point3 nearpoint;// most extreme near point in camera coordinate
- MT_Point3 farcenter(0.0f, 0.0f, 0.0f);// center of far cliping plane in camera coordinate
- MT_Scalar F=-1.0f, N; // square distance of far and near point to origin
- MT_Scalar f, n; // distance of far and near point to z axis. f is always > 0 but n can be < 0
- MT_Scalar e, s; // far and near clipping distance (<0)
- MT_Scalar c; // slope of center line = distance of far clipping center to z axis / far clipping distance
- MT_Scalar z; // projection of sphere center on z axis (<0)
- // tmp value
- MT_Vector4 npoint(1.0f, 1.0f, 1.0f, 1.0f);
- MT_Vector4 hpoint;
- MT_Point3 point;
- MT_Scalar len;
- for (int i=0; i<4; i++)
- {
- hpoint = clip_camcs_matrix*npoint;
- point.setValue(hpoint[0]/hpoint[3], hpoint[1]/hpoint[3], hpoint[2]/hpoint[3]);
- len = point.dot(point);
- if (len > F)
- {
- nfar = npoint;
- farpoint = point;
- F = len;
- }
- // rotate by 90 degree along the z axis to walk through the 4 extreme points of the far clipping plane
- len = npoint[0];
- npoint[0] = -npoint[1];
- npoint[1] = len;
- farcenter += point;
- }
- // the far center is the average of the far clipping points
- farcenter *= 0.25f;
- // the extreme near point is the opposite point on the near clipping plane
- nfar.setValue(-nfar[0], -nfar[1], -1.0f, 1.0f);
- nfar = clip_camcs_matrix*nfar;
- nearpoint.setValue(nfar[0]/nfar[3], nfar[1]/nfar[3], nfar[2]/nfar[3]);
- // this is a frustum projection
- N = nearpoint.dot(nearpoint);
- e = farpoint[2];
- s = nearpoint[2];
- // projection on XY plane for distance to axis computation
- MT_Point2 farxy(farpoint[0], farpoint[1]);
- // f is forced positive by construction
- f = farxy.length();
- // get corresponding point on the near plane
- farxy *= s/e;
- // this formula preserve the sign of n
- n = f*s/e - MT_Point2(nearpoint[0]-farxy[0], nearpoint[1]-farxy[1]).length();
- c = MT_Point2(farcenter[0], farcenter[1]).length()/e;
- // the big formula, it simplifies to (F-N)/(2(e-s)) for the symmetric case
- z = (F-N)/(2.0f*(e-s+c*(f-n)));
- m_frustum_center = MT_Point3(farcenter[0]*z/e, farcenter[1]*z/e, z);
- m_frustum_radius = m_frustum_center.distance(farpoint);
- }
- else
- {
- // orthographic projection
- // The most extreme points on the near and far plane. (normalized device coords)
- MT_Vector4 hnear(1.0f, 1.0f, 1.0f, 1.0f), hfar(-1.0f, -1.0f, -1.0f, 1.0f);
-
- // Transform to hom camera local space
- hnear = clip_camcs_matrix*hnear;
- hfar = clip_camcs_matrix*hfar;
-
- // Tranform to 3d camera local space.
- MT_Point3 nearpoint(hnear[0]/hnear[3], hnear[1]/hnear[3], hnear[2]/hnear[3]);
- MT_Point3 farpoint(hfar[0]/hfar[3], hfar[1]/hfar[3], hfar[2]/hfar[3]);
-
- // just use mediant point
- m_frustum_center = (farpoint + nearpoint)*0.5f;
- m_frustum_radius = m_frustum_center.distance(farpoint);
- }
- // Transform to world space.
- m_frustum_center = GetCameraToWorld()(m_frustum_center);
- m_frustum_radius /= fabsf(NodeGetWorldScaling()[NodeGetWorldScaling().closestAxis()]);
-
- m_set_frustum_center = true;
-}
-
-bool KX_Camera::PointInsideFrustum(const MT_Point3& x)
-{
- ExtractClipPlanes();
-
- for ( unsigned int i = 0; i < 6 ; i++ )
- {
- if (m_planes[i][0] * x[0] + m_planes[i][1] * x[1] + m_planes[i][2] * x[2] + m_planes[i][3] < 0.0f)
- return false;
- }
- return true;
-}
-
-int KX_Camera::BoxInsideFrustum(const MT_Point3 *box)
-{
- ExtractClipPlanes();
-
- unsigned int insideCount = 0;
- // 6 view frustum planes
- for ( unsigned int p = 0; p < 6 ; p++ )
- {
- unsigned int behindCount = 0;
- // 8 box vertices.
- for (unsigned int v = 0; v < 8 ; v++)
- {
- if (m_planes[p][0] * box[v][0] + m_planes[p][1] * box[v][1] + m_planes[p][2] * box[v][2] + m_planes[p][3] < 0.0f)
- behindCount++;
- }
-
- // 8 points behind this plane
- if (behindCount == 8)
- return OUTSIDE;
-
- // Every box vertex is on the front side of this plane
- if (!behindCount)
- insideCount++;
- }
-
- // All box vertices are on the front side of all frustum planes.
- if (insideCount == 6)
- return INSIDE;
-
- return INTERSECT;
-}
-
-int KX_Camera::SphereInsideFrustum(const MT_Point3& center, const MT_Scalar &radius)
-{
- ExtractFrustumSphere();
- if (center.distance2(m_frustum_center) > (radius + m_frustum_radius)*(radius + m_frustum_radius))
- return OUTSIDE;
-
- unsigned int p;
- ExtractClipPlanes();
- NormalizeClipPlanes();
-
- MT_Scalar distance;
- int intersect = INSIDE;
- // distance: <-------- OUTSIDE -----|----- INTERSECT -----0----- INTERSECT -----|----- INSIDE -------->
- // -radius radius
- for (p = 0; p < 6; p++)
- {
- distance = m_planes[p][0]*center[0] + m_planes[p][1]*center[1] + m_planes[p][2]*center[2] + m_planes[p][3];
- if (fabsf(distance) <= radius)
- intersect = INTERSECT;
- else if (distance < -radius)
- return OUTSIDE;
- }
-
- return intersect;
-}
-
-bool KX_Camera::GetFrustumCulling() const
-{
- return m_frustum_culling;
-}
-
-void KX_Camera::EnableViewport(bool viewport)
-{
- InvalidateProjectionMatrix(false); // We need to reset projection matrix
- m_camdata.m_viewport = viewport;
-}
-
-void KX_Camera::SetViewport(int left, int bottom, int right, int top)
-{
- m_camdata.m_viewportleft = left;
- m_camdata.m_viewportbottom = bottom;
- m_camdata.m_viewportright = right;
- m_camdata.m_viewporttop = top;
-}
-
-bool KX_Camera::GetViewport() const
-{
- return m_camdata.m_viewport;
-}
-
-int KX_Camera::GetViewportLeft() const
-{
- return m_camdata.m_viewportleft;
-}
-
-int KX_Camera::GetViewportBottom() const
-{
- return m_camdata.m_viewportbottom;
-}
-
-int KX_Camera::GetViewportRight() const
-{
- return m_camdata.m_viewportright;
-}
-
-int KX_Camera::GetViewportTop() const
-{
- return m_camdata.m_viewporttop;
-}
-
-#ifdef WITH_PYTHON
-//----------------------------------------------------------------------------
-//Python
-
-
-PyMethodDef KX_Camera::Methods[] = {
- KX_PYMETHODTABLE(KX_Camera, sphereInsideFrustum),
- KX_PYMETHODTABLE_O(KX_Camera, boxInsideFrustum),
- KX_PYMETHODTABLE_O(KX_Camera, pointInsideFrustum),
- KX_PYMETHODTABLE_NOARGS(KX_Camera, getCameraToWorld),
- KX_PYMETHODTABLE_NOARGS(KX_Camera, getWorldToCamera),
- KX_PYMETHODTABLE(KX_Camera, setViewport),
- KX_PYMETHODTABLE_NOARGS(KX_Camera, setOnTop),
- KX_PYMETHODTABLE_O(KX_Camera, getScreenPosition),
- KX_PYMETHODTABLE(KX_Camera, getScreenVect),
- KX_PYMETHODTABLE(KX_Camera, getScreenRay),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_Camera::Attributes[] = {
-
- KX_PYATTRIBUTE_BOOL_RW("frustum_culling", KX_Camera, m_frustum_culling),
- KX_PYATTRIBUTE_RW_FUNCTION("perspective", KX_Camera, pyattr_get_perspective, pyattr_set_perspective),
-
- KX_PYATTRIBUTE_RW_FUNCTION("lens", KX_Camera, pyattr_get_lens, pyattr_set_lens),
- KX_PYATTRIBUTE_RW_FUNCTION("fov", KX_Camera, pyattr_get_fov, pyattr_set_fov),
- KX_PYATTRIBUTE_RW_FUNCTION("ortho_scale", KX_Camera, pyattr_get_ortho_scale, pyattr_set_ortho_scale),
- KX_PYATTRIBUTE_RW_FUNCTION("near", KX_Camera, pyattr_get_near, pyattr_set_near),
- KX_PYATTRIBUTE_RW_FUNCTION("far", KX_Camera, pyattr_get_far, pyattr_set_far),
- KX_PYATTRIBUTE_RW_FUNCTION("shift_x", KX_Camera, pyattr_get_shift_x, pyattr_set_shift_x),
- KX_PYATTRIBUTE_RW_FUNCTION("shift_y", KX_Camera, pyattr_get_shift_y, pyattr_set_shift_y),
-
- KX_PYATTRIBUTE_RW_FUNCTION("useViewport", KX_Camera, pyattr_get_use_viewport, pyattr_set_use_viewport),
-
- KX_PYATTRIBUTE_RW_FUNCTION("projection_matrix", KX_Camera, pyattr_get_projection_matrix, pyattr_set_projection_matrix),
- KX_PYATTRIBUTE_RO_FUNCTION("modelview_matrix", KX_Camera, pyattr_get_modelview_matrix),
- KX_PYATTRIBUTE_RO_FUNCTION("camera_to_world", KX_Camera, pyattr_get_camera_to_world),
- KX_PYATTRIBUTE_RO_FUNCTION("world_to_camera", KX_Camera, pyattr_get_world_to_camera),
-
- /* Grrr, functions for constants? */
- KX_PYATTRIBUTE_RO_FUNCTION("INSIDE", KX_Camera, pyattr_get_INSIDE),
- KX_PYATTRIBUTE_RO_FUNCTION("OUTSIDE", KX_Camera, pyattr_get_OUTSIDE),
- KX_PYATTRIBUTE_RO_FUNCTION("INTERSECT", KX_Camera, pyattr_get_INTERSECT),
-
- { NULL } //Sentinel
-};
-
-PyTypeObject KX_Camera::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_Camera",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- &KX_GameObject::Sequence,
- &KX_GameObject::Mapping,
- 0,0,0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_GameObject::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, sphereInsideFrustum,
-"sphereInsideFrustum(center, radius) -> Integer\n"
-"\treturns INSIDE, OUTSIDE or INTERSECT if the given sphere is\n"
-"\tinside/outside/intersects this camera's viewing frustum.\n\n"
-"\tcenter = the center of the sphere (in world coordinates.)\n"
-"\tradius = the radius of the sphere\n\n"
-"\tExample:\n"
-"\timport bge.logic\n\n"
-"\tco = bge.logic.getCurrentController()\n"
-"\tcam = co.GetOwner()\n\n"
-"\t# A sphere of radius 4.0 located at [x, y, z] = [1.0, 1.0, 1.0]\n"
-"\tif (cam.sphereInsideFrustum([1.0, 1.0, 1.0], 4) != cam.OUTSIDE):\n"
-"\t\t# Sphere is inside frustum !\n"
-"\t\t# Do something useful !\n"
-"\telse:\n"
-"\t\t# Sphere is outside frustum\n"
-)
-{
- PyObject *pycenter;
- float radius;
- if (PyArg_ParseTuple(args, "Of:sphereInsideFrustum", &pycenter, &radius))
- {
- MT_Point3 center;
- if (PyVecTo(pycenter, center))
- {
- return PyLong_FromLong(SphereInsideFrustum(center, radius)); /* new ref */
- }
- }
-
- PyErr_SetString(PyExc_TypeError, "camera.sphereInsideFrustum(center, radius): KX_Camera, expected arguments: (center, radius)");
-
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC_O(KX_Camera, boxInsideFrustum,
-"boxInsideFrustum(box) -> Integer\n"
-"\treturns INSIDE, OUTSIDE or INTERSECT if the given box is\n"
-"\tinside/outside/intersects this camera's viewing frustum.\n\n"
-"\tbox = a list of the eight (8) corners of the box (in world coordinates.)\n\n"
-"\tExample:\n"
-"\timport bge.logic\n\n"
-"\tco = bge.logic.getCurrentController()\n"
-"\tcam = co.GetOwner()\n\n"
-"\tbox = []\n"
-"\tbox.append([-1.0, -1.0, -1.0])\n"
-"\tbox.append([-1.0, -1.0, 1.0])\n"
-"\tbox.append([-1.0, 1.0, -1.0])\n"
-"\tbox.append([-1.0, 1.0, 1.0])\n"
-"\tbox.append([ 1.0, -1.0, -1.0])\n"
-"\tbox.append([ 1.0, -1.0, 1.0])\n"
-"\tbox.append([ 1.0, 1.0, -1.0])\n"
-"\tbox.append([ 1.0, 1.0, 1.0])\n\n"
-"\tif (cam.boxInsideFrustum(box) != cam.OUTSIDE):\n"
-"\t\t# Box is inside/intersects frustum !\n"
-"\t\t# Do something useful !\n"
-"\telse:\n"
-"\t\t# Box is outside the frustum !\n"
-)
-{
- unsigned int num_points = PySequence_Size(value);
- if (num_points != 8)
- {
- PyErr_Format(PyExc_TypeError, "camera.boxInsideFrustum(box): KX_Camera, expected eight (8) points, got %d", num_points);
- return NULL;
- }
-
- MT_Point3 box[8];
- for (unsigned int p = 0; p < 8 ; p++)
- {
- PyObject *item = PySequence_GetItem(value, p); /* new ref */
- bool error = !PyVecTo(item, box[p]);
- Py_DECREF(item);
- if (error)
- return NULL;
- }
-
- return PyLong_FromLong(BoxInsideFrustum(box)); /* new ref */
-}
-
-KX_PYMETHODDEF_DOC_O(KX_Camera, pointInsideFrustum,
-"pointInsideFrustum(point) -> Bool\n"
-"\treturns 1 if the given point is inside this camera's viewing frustum.\n\n"
-"\tpoint = The point to test (in world coordinates.)\n\n"
-"\tExample:\n"
-"\timport bge.logic\n\n"
-"\tco = bge.logic.getCurrentController()\n"
-"\tcam = co.GetOwner()\n\n"
-"\t# Test point [0.0, 0.0, 0.0]"
-"\tif (cam.pointInsideFrustum([0.0, 0.0, 0.0])):\n"
-"\t\t# Point is inside frustum !\n"
-"\t\t# Do something useful !\n"
-"\telse:\n"
-"\t\t# Box is outside the frustum !\n"
-)
-{
- MT_Point3 point;
- if (PyVecTo(value, point))
- {
- return PyLong_FromLong(PointInsideFrustum(point)); /* new ref */
- }
-
- PyErr_SetString(PyExc_TypeError, "camera.pointInsideFrustum(point): KX_Camera, expected point argument.");
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, getCameraToWorld,
-"getCameraToWorld() -> Matrix4x4\n"
-"\treturns the camera to world transformation matrix, as a list of four lists of four values.\n\n"
-"\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n"
-)
-{
- return PyObjectFrom(GetCameraToWorld()); /* new ref */
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, getWorldToCamera,
-"getWorldToCamera() -> Matrix4x4\n"
-"\treturns the world to camera transformation matrix, as a list of four lists of four values.\n\n"
-"\tie: [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]])\n"
-)
-{
- return PyObjectFrom(GetWorldToCamera()); /* new ref */
-}
-
-KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, setViewport,
-"setViewport(left, bottom, right, top)\n"
-"Sets this camera's viewport\n")
-{
- int left, bottom, right, top;
- if (!PyArg_ParseTuple(args,"iiii:setViewport",&left, &bottom, &right, &top))
- return NULL;
-
- SetViewport(left, bottom, right, top);
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_Camera, setOnTop,
-"setOnTop()\n"
-"Sets this camera's viewport on top\n")
-{
- class KX_Scene* scene = KX_GetActiveScene();
- scene->SetCameraOnTop(this);
- Py_RETURN_NONE;
-}
-
-PyObject *KX_Camera::pyattr_get_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyBool_FromLong(self->m_camdata.m_perspective);
-}
-
-int KX_Camera::pyattr_set_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- int param = PyObject_IsTrue( value );
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.perspective = bool: KX_Camera, expected True/False or 0/1");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_camdata.m_perspective= param;
- self->InvalidateProjectionMatrix();
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyFloat_FromDouble(self->m_camdata.m_lens);
-}
-
-int KX_Camera::pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- float param = PyFloat_AsDouble(value);
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.lens = float: KX_Camera, expected a float greater than zero");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_camdata.m_lens= param;
- self->m_set_projection_matrix = false;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
-
- float lens = self->m_camdata.m_lens;
- float width = self->m_camdata.m_sensor_x;
- float fov = 2.0f * atanf(0.5f * width / lens);
-
- return PyFloat_FromDouble(fov * MT_DEGS_PER_RAD);
-}
-
-int KX_Camera::pyattr_set_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- float fov = PyFloat_AsDouble(value);
- if (fov <= 0.0f) {
- PyErr_SetString(PyExc_AttributeError, "camera.fov = float: KX_Camera, expected a float greater than zero");
- return PY_SET_ATTR_FAIL;
- }
-
- fov *= MT_RADS_PER_DEG;
- float width = self->m_camdata.m_sensor_x;
- float lens = width / (2.0f * tanf(0.5f * fov));
-
- self->m_camdata.m_lens= lens;
- self->m_set_projection_matrix = false;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyFloat_FromDouble(self->m_camdata.m_scale);
-}
-
-int KX_Camera::pyattr_set_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- float param = PyFloat_AsDouble(value);
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.ortho_scale = float: KX_Camera, expected a float greater than zero");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_camdata.m_scale= param;
- self->m_set_projection_matrix = false;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyFloat_FromDouble(self->m_camdata.m_clipstart);
-}
-
-int KX_Camera::pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- float param = PyFloat_AsDouble(value);
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.near = float: KX_Camera, expected a float greater than zero");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_camdata.m_clipstart= param;
- self->m_set_projection_matrix = false;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyFloat_FromDouble(self->m_camdata.m_clipend);
-}
-
-int KX_Camera::pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- float param = PyFloat_AsDouble(value);
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.far = float: KX_Camera, expected a float greater than zero");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_camdata.m_clipend= param;
- self->m_set_projection_matrix = false;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyFloat_FromDouble(self->m_camdata.m_shift_x);
-}
-
-int KX_Camera::pyattr_set_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- float param = PyFloat_AsDouble(value);
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.shift_x = float: KX_Camera, expected a float greater than zero");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_camdata.m_shift_x = param;
- self->m_set_projection_matrix = false;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyFloat_FromDouble(self->m_camdata.m_shift_y);
-}
-
-int KX_Camera::pyattr_set_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- float param = PyFloat_AsDouble(value);
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.shift_y = float: KX_Camera, expected a float greater than zero");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_camdata.m_shift_y = param;
- self->m_set_projection_matrix = false;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyBool_FromLong(self->GetViewport());
-}
-
-int KX_Camera::pyattr_set_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- int param = PyObject_IsTrue( value );
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "camera.useViewport = bool: KX_Camera, expected True or False");
- return PY_SET_ATTR_FAIL;
- }
- self->EnableViewport((bool)param);
- return PY_SET_ATTR_SUCCESS;
-}
-
-
-PyObject *KX_Camera::pyattr_get_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyObjectFrom(self->GetProjectionMatrix());
-}
-
-int KX_Camera::pyattr_set_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- MT_Matrix4x4 mat;
- if (!PyMatTo(value, mat))
- return PY_SET_ATTR_FAIL;
-
- self->SetProjectionMatrix(mat);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Camera::pyattr_get_modelview_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyObjectFrom(self->GetWorldToCamera());
-}
-
-PyObject *KX_Camera::pyattr_get_camera_to_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyObjectFrom(self->GetCameraToWorld());
-}
-
-PyObject *KX_Camera::pyattr_get_world_to_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Camera* self = static_cast<KX_Camera*>(self_v);
- return PyObjectFrom(self->GetWorldToCamera());
-}
-
-
-PyObject *KX_Camera::pyattr_get_INSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{ return PyLong_FromLong(INSIDE); }
-PyObject *KX_Camera::pyattr_get_OUTSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{ return PyLong_FromLong(OUTSIDE); }
-PyObject *KX_Camera::pyattr_get_INTERSECT(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{ return PyLong_FromLong(INTERSECT); }
-
-
-bool ConvertPythonToCamera(PyObject *value, KX_Camera **object, bool py_none_ok, const char *error_prefix)
-{
- if (value==NULL) {
- PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
- *object = NULL;
- return false;
- }
-
- if (value==Py_None) {
- *object = NULL;
-
- if (py_none_ok) {
- return true;
- } else {
- PyErr_Format(PyExc_TypeError, "%s, expected KX_Camera or a KX_Camera name, None is invalid", error_prefix);
- return false;
- }
- }
-
- if (PyUnicode_Check(value)) {
- STR_String value_str = _PyUnicode_AsString(value);
- *object = KX_GetActiveScene()->FindCamera(value_str);
-
- if (*object) {
- return true;
- } else {
- PyErr_Format(PyExc_ValueError,
- "%s, requested name \"%s\" did not match any KX_Camera in this scene",
- error_prefix, _PyUnicode_AsString(value));
- return false;
- }
- }
-
- if (PyObject_TypeCheck(value, &KX_Camera::Type)) {
- *object = static_cast<KX_Camera*>BGE_PROXY_REF(value);
-
- /* sets the error */
- if (*object==NULL) {
- PyErr_Format(PyExc_SystemError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix);
- return false;
- }
-
- return true;
- }
-
- *object = NULL;
-
- if (py_none_ok) {
- PyErr_Format(PyExc_TypeError, "%s, expect a KX_Camera, a string or None", error_prefix);
- } else {
- PyErr_Format(PyExc_TypeError, "%s, expect a KX_Camera or a string", error_prefix);
- }
-
- return false;
-}
-
-KX_PYMETHODDEF_DOC_O(KX_Camera, getScreenPosition,
-"getScreenPosition()\n"
-)
-
-{
- MT_Vector3 vect;
- KX_GameObject *obj = NULL;
-
- if (!PyVecTo(value, vect))
- {
- PyErr_Clear();
-
- if (ConvertPythonToGameObject(GetScene()->GetLogicManager(), value, &obj, true, ""))
- {
- PyErr_Clear();
- vect = MT_Vector3(obj->NodeGetWorldPosition());
- }
- else
- {
- PyErr_SetString(PyExc_TypeError, "Error in getScreenPosition. Expected a Vector3 or a KX_GameObject or a string for a name of a KX_GameObject");
- return NULL;
- }
- }
-
- const GLint *viewport;
- GLdouble win[3];
- GLdouble modelmatrix[16];
- GLdouble projmatrix[16];
-
- MT_Matrix4x4 m_modelmatrix = this->GetWorldToCamera();
- MT_Matrix4x4 m_projmatrix = this->GetProjectionMatrix();
-
- m_modelmatrix.getValue(modelmatrix);
- m_projmatrix.getValue(projmatrix);
-
- viewport = KX_GetActiveEngine()->GetCanvas()->GetViewPort();
-
- gluProject(vect[0], vect[1], vect[2], modelmatrix, projmatrix, viewport, &win[0], &win[1], &win[2]);
-
- vect[0] = (win[0] - viewport[0]) / viewport[2];
- vect[1] = (win[1] - viewport[1]) / viewport[3];
-
- vect[1] = 1.0f - vect[1]; //to follow Blender window coordinate system (Top-Down)
-
- PyObject *ret = PyTuple_New(2);
- if (ret) {
- PyTuple_SET_ITEM(ret, 0, PyFloat_FromDouble(vect[0]));
- PyTuple_SET_ITEM(ret, 1, PyFloat_FromDouble(vect[1]));
- return ret;
- }
-
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, getScreenVect,
-"getScreenVect()\n"
-)
-{
- double x,y;
- if (!PyArg_ParseTuple(args,"dd:getScreenVect",&x,&y))
- return NULL;
-
- y = 1.0 - y; //to follow Blender window coordinate system (Top-Down)
-
- MT_Vector3 vect;
- MT_Point3 campos, screenpos;
-
- const GLint *viewport;
- GLdouble win[3];
- GLdouble modelmatrix[16];
- GLdouble projmatrix[16];
-
- MT_Matrix4x4 m_modelmatrix = this->GetWorldToCamera();
- MT_Matrix4x4 m_projmatrix = this->GetProjectionMatrix();
-
- m_modelmatrix.getValue(modelmatrix);
- m_projmatrix.getValue(projmatrix);
-
- viewport = KX_GetActiveEngine()->GetCanvas()->GetViewPort();
-
- vect[0] = x * viewport[2];
- vect[1] = y * viewport[3];
-
- vect[0] += viewport[0];
- vect[1] += viewport[1];
-
- vect[2] = 0.f;
-
- gluUnProject(vect[0], vect[1], vect[2], modelmatrix, projmatrix, viewport, &win[0], &win[1], &win[2]);
-
- campos = this->GetCameraLocation();
- screenpos = MT_Point3(win[0], win[1], win[2]);
- vect = campos-screenpos;
-
- vect.normalize();
- return PyObjectFrom(vect);
-}
-
-KX_PYMETHODDEF_DOC_VARARGS(KX_Camera, getScreenRay,
-"getScreenRay()\n"
-)
-{
- MT_Vector3 vect;
- double x,y,dist;
- char *propName = NULL;
-
- if (!PyArg_ParseTuple(args,"ddd|s:getScreenRay",&x,&y,&dist,&propName))
- return NULL;
-
- PyObject *argValue = PyTuple_New(2);
- PyTuple_SET_ITEM(argValue, 0, PyFloat_FromDouble(x));
- PyTuple_SET_ITEM(argValue, 1, PyFloat_FromDouble(y));
-
- if (!PyVecTo(PygetScreenVect(argValue), vect))
- {
- Py_DECREF(argValue);
- PyErr_SetString(PyExc_TypeError,
- "Error in getScreenRay. Invalid 2D coordinate. "
- "Expected a normalized 2D screen coordinate, "
- "a distance and an optional property argument");
- return NULL;
- }
- Py_DECREF(argValue);
-
- dist = -dist;
- vect += this->GetCameraLocation();
-
- argValue = (propName?PyTuple_New(3):PyTuple_New(2));
- if (argValue) {
- PyTuple_SET_ITEM(argValue, 0, PyObjectFrom(vect));
- PyTuple_SET_ITEM(argValue, 1, PyFloat_FromDouble(dist));
- if (propName)
- PyTuple_SET_ITEM(argValue, 2, PyUnicode_FromString(propName));
-
- PyObject *ret= this->PyrayCastTo(argValue,NULL);
- Py_DECREF(argValue);
- return ret;
- }
-
- return NULL;
-}
-#endif
diff --git a/source/gameengine/Ketsji/KX_Camera.h b/source/gameengine/Ketsji/KX_Camera.h
deleted file mode 100644
index 8addf0b7aed..00000000000
--- a/source/gameengine/Ketsji/KX_Camera.h
+++ /dev/null
@@ -1,334 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_Camera.h
- * \ingroup ketsji
- * \brief Camera in the gameengine. Cameras are also used for views.
- */
-
-#ifndef __KX_CAMERA_H__
-#define __KX_CAMERA_H__
-
-
-#include "MT_Transform.h"
-#include "MT_Matrix3x3.h"
-#include "MT_Matrix4x4.h"
-#include "MT_Vector3.h"
-#include "MT_Point3.h"
-#include "KX_GameObject.h"
-#include "EXP_IntValue.h"
-#include "RAS_CameraData.h"
-
-#ifdef WITH_PYTHON
-/* utility conversion function */
-bool ConvertPythonToCamera(PyObject *value, KX_Camera **object, bool py_none_ok, const char *error_prefix);
-#endif
-
-class KX_Camera : public KX_GameObject
-{
- Py_Header
-protected:
- friend class KX_Scene;
- /** Camera parameters (clips distances, focal length). These
- * params are closely tied to Blender. In the gameengine, only the
- * projection and modelview matrices are relevant. There's a
- * conversion being done in the engine class. Why is it stored
- * here? It doesn't really have a function here. */
- RAS_CameraData m_camdata;
-
- // Never used, I think...
-// void MoveTo(const MT_Point3& movevec)
-// {
-#if 0
- MT_Transform camtrans;
- camtrans.invert(m_trans1);
- MT_Matrix3x3 camorient = camtrans.getBasis();
- camtrans.translate(camorient.inverse()*movevec);
- m_trans1.invert(camtrans);
-#endif
-// }
-
- /**
- * Storage for the projection matrix that is passed to the
- * rasterizer. */
- MT_Matrix4x4 m_projection_matrix;
- //MT_Matrix4x4 m_projection_matrix1;
-
- /**
- * Storage for the modelview matrix that is passed to the
- * rasterizer. */
- MT_Matrix4x4 m_modelview_matrix;
-
- /**
- * true if the view frustum (modelview/projection matrix)
- * has changed - the clip planes (m_planes) will have to be
- * regenerated.
- */
- bool m_dirty;
- /**
- * true if the frustum planes have been normalized.
- */
- bool m_normalized;
-
- /**
- * View Frustum clip planes.
- */
- MT_Vector4 m_planes[6];
-
- /**
- * This camera is frustum culling.
- * Some cameras (ie if the game was started from a non camera view should not cull.)
- */
- bool m_frustum_culling;
-
- /**
- * true if this camera has a valid projection matrix.
- */
- bool m_set_projection_matrix;
-
- /**
- * The center point of the frustum.
- */
- MT_Point3 m_frustum_center;
- MT_Scalar m_frustum_radius;
- bool m_set_frustum_center;
-
- /**
- * whether the camera should delete the node itself (only for shadow camera)
- */
- bool m_delete_node;
-
- /**
- * Extracts the camera clip frames from the projection and world-to-camera matrices.
- */
- void ExtractClipPlanes();
- /**
- * Normalize the camera clip frames.
- */
- void NormalizeClipPlanes();
- /**
- * Extracts the bound sphere of the view frustum.
- */
- void ExtractFrustumSphere();
- /**
- * return the clip plane
- */
- MT_Vector4 *GetNormalizedClipPlanes()
- {
- ExtractClipPlanes();
- NormalizeClipPlanes();
- return m_planes;
- }
-
-public:
-
- enum { INSIDE, INTERSECT, OUTSIDE };
-
- KX_Camera(void* sgReplicationInfo,SG_Callbacks callbacks,const RAS_CameraData& camdata, bool frustum_culling = true, bool delete_node = false);
- virtual ~KX_Camera();
-
- /**
- * Inherited from CValue -- return a new copy of this
- * instance allocated on the heap. Ownership of the new
- * object belongs with the caller.
- */
- virtual CValue*
- GetReplica(
- );
- virtual void ProcessReplica();
-
- MT_Transform GetWorldToCamera() const;
- MT_Transform GetCameraToWorld() const;
-
- /**
- * Not implemented.
- */
- void CorrectLookUp(MT_Scalar speed);
- const MT_Point3 GetCameraLocation() const;
-
- /* I want the camera orientation as well. */
- const MT_Quaternion GetCameraOrientation() const;
-
- /** Sets the projection matrix that is used by the rasterizer. */
- void SetProjectionMatrix(const MT_Matrix4x4 & mat);
-
- /** Sets the modelview matrix that is used by the rasterizer. */
- void SetModelviewMatrix(const MT_Matrix4x4 & mat);
-
- /** Gets the projection matrix that is used by the rasterizer. */
- const MT_Matrix4x4& GetProjectionMatrix() const;
-
- /** returns true if this camera has been set a projection matrix. */
- bool hasValidProjectionMatrix() const;
-
- /** Sets the validity of the projection matrix. Call this if you change camera
- * data (eg lens, near plane, far plane) and require the projection matrix to be
- * recalculated.
- */
- void InvalidateProjectionMatrix(bool valid = false);
-
- /** Gets the modelview matrix that is used by the rasterizer.
- * \warning If the Camera is a dynamic object then this method may return garbage. Use GetWorldToCamera() instead.
- */
- const MT_Matrix4x4& GetModelviewMatrix() const;
-
- /** Gets the aperture. */
- float GetLens() const;
- /** Gets the ortho scale. */
- float GetScale() const;
- /** Gets the horizontal size of the sensor - for camera matching */
- float GetSensorWidth() const;
- /** Gets the vertical size of the sensor - for camera matching */
- float GetSensorHeight() const;
- /** Gets the mode FOV is calculating from sensor dimensions */
- short GetSensorFit() const;
- /** Gets the horizontal shift of the sensor - for camera matching */
- float GetShiftHorizontal() const;
- /** Gets the vertical shift of the sensor - for camera matching */
- float GetShiftVertical() const;
- /** Gets the near clip distance. */
- float GetCameraNear() const;
- /** Gets the far clip distance. */
- float GetCameraFar() const;
- /** Gets the focal length (only used for stereo rendering) */
- float GetFocalLength() const;
- /** Gets all camera data. */
- RAS_CameraData* GetCameraData();
-
- /**
- * Tests if the given sphere is inside this camera's view frustum.
- *
- * \param center The center of the sphere, in world coordinates.
- * \param radius The radius of the sphere.
- * \return INSIDE, INTERSECT, or OUTSIDE depending on the sphere's relation to the frustum.
- */
- int SphereInsideFrustum(const MT_Point3& center, const MT_Scalar &radius);
- /**
- * Tests the given eight corners of a box with the view frustum.
- *
- * \param box a pointer to eight MT_Point3 representing the world coordinates of the corners of the box.
- * \return INSIDE, INTERSECT, or OUTSIDE depending on the box's relation to the frustum.
- */
- int BoxInsideFrustum(const MT_Point3 *box);
- /**
- * Tests the given point against the view frustum.
- * \return true if the given point is inside or on the view frustum; false if it is outside.
- */
- bool PointInsideFrustum(const MT_Point3& x);
-
- /**
- * Gets this camera's culling status.
- */
- bool GetFrustumCulling() const;
-
- /**
- * Sets this camera's viewport status.
- */
- void EnableViewport(bool viewport);
-
- /**
- * Sets this camera's viewport.
- */
- void SetViewport(int left, int bottom, int right, int top);
-
- /**
- * Gets this camera's viewport status.
- */
- bool GetViewport() const;
-
- /**
- * Gets this camera's viewport left.
- */
- int GetViewportLeft() const;
-
- /**
- * Gets this camera's viewport bottom.
- */
- int GetViewportBottom() const;
-
- /**
- * Gets this camera's viewport right.
- */
- int GetViewportRight() const;
-
- /**
- * Gets this camera's viewport top.
- */
- int GetViewportTop() const;
-
- virtual int GetGameObjectType() { return OBJ_CAMERA; }
-
-#ifdef WITH_PYTHON
- KX_PYMETHOD_DOC_VARARGS(KX_Camera, sphereInsideFrustum);
- KX_PYMETHOD_DOC_O(KX_Camera, boxInsideFrustum);
- KX_PYMETHOD_DOC_O(KX_Camera, pointInsideFrustum);
-
- KX_PYMETHOD_DOC_NOARGS(KX_Camera, getCameraToWorld);
- KX_PYMETHOD_DOC_NOARGS(KX_Camera, getWorldToCamera);
-
- KX_PYMETHOD_DOC_VARARGS(KX_Camera, setViewport);
- KX_PYMETHOD_DOC_NOARGS(KX_Camera, setOnTop);
-
- KX_PYMETHOD_DOC_O(KX_Camera, getScreenPosition);
- KX_PYMETHOD_DOC_VARARGS(KX_Camera, getScreenVect);
- KX_PYMETHOD_DOC_VARARGS(KX_Camera, getScreenRay);
-
- static PyObject* pyattr_get_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_perspective(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_lens(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_fov(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_ortho_scale(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_near(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_far(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_shift_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_shift_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_use_viewport(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_projection_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_modelview_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_camera_to_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_world_to_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- static PyObject* pyattr_get_INSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_OUTSIDE(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_INTERSECT(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-};
-
-#endif /* __KX_CAMERA_H__ */
diff --git a/source/gameengine/Ketsji/KX_CameraActuator.cpp b/source/gameengine/Ketsji/KX_CameraActuator.cpp
deleted file mode 100644
index e488bf3c30a..00000000000
--- a/source/gameengine/Ketsji/KX_CameraActuator.cpp
+++ /dev/null
@@ -1,428 +0,0 @@
-/*
- * KX_CameraActuator.cpp
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- *
- */
-
-/** \file gameengine/Ketsji/KX_CameraActuator.cpp
- * \ingroup ketsji
- */
-
-#include "BLI_math_vector.h"
-
-#include "KX_CameraActuator.h"
-#include <math.h>
-#include <float.h>
-#include "KX_GameObject.h"
-
-#include "EXP_PyObjectPlus.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_CameraActuator::KX_CameraActuator(
- SCA_IObject* gameobj,
- SCA_IObject *obj,
- float hght,
- float minhght,
- float maxhght,
- short axis,
- float damping
-):
- SCA_IActuator(gameobj, KX_ACT_CAMERA),
- m_ob (obj),
- m_height (hght),
- m_minHeight (minhght),
- m_maxHeight (maxhght),
- m_axis(axis),
- m_damping (damping)
-{
- if (m_ob)
- m_ob->RegisterActuator(this);
-}
-
-KX_CameraActuator::~KX_CameraActuator()
-{
- if (m_ob)
- m_ob->UnregisterActuator(this);
-}
-
- CValue*
-KX_CameraActuator::
-GetReplica(
-) {
- KX_CameraActuator* replica = new KX_CameraActuator(*this);
- replica->ProcessReplica();
- return replica;
-};
-
-void KX_CameraActuator::ProcessReplica()
-{
- if (m_ob)
- m_ob->RegisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-bool KX_CameraActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == m_ob)
- {
- // this object is being deleted, we cannot continue to track it.
- m_ob = NULL;
- return true;
- }
- return false;
-}
-
-
-void KX_CameraActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_ob];
- if (h_obj) {
- if (m_ob)
- m_ob->UnregisterActuator(this);
- m_ob = (SCA_IObject*)(*h_obj);
- m_ob->RegisterActuator(this);
- }
-}
-
-/* copied from blender BLI_math ... don't know if there's an equivalent */
-
-static void Kx_VecUpMat3(float vec[3], float mat[3][3], short axis)
-{
-
- // Construct a camera matrix s.t. the specified axis
-
- // maps to the given vector (*vec). Also defines the rotation
-
- // about this axis by mapping one of the other axis to the y-axis.
-
-
- float inp;
- short cox = 0, coy = 0, coz = 0;
-
- /* up range has no meaning, is not really up!
- * see: VecUpMat3old
- */
-
- if (axis==0) {
- cox= 0; coy= 1; coz= 2; /* Y up Z tr */
- }
- if (axis==1) {
- cox= 1; coy= 2; coz= 0; /* Z up X tr */
- }
- if (axis==2) {
- cox= 2; coy= 0; coz= 1; /* X up Y tr */
- }
- if (axis==3) {
- cox= 0; coy= 1; coz= 2; /* Y op -Z tr */
- vec[0] = -vec[0];
- vec[1] = -vec[1];
- vec[2] = -vec[2];
- }
- if (axis==4) {
- cox= 1; coy= 0; coz= 2; /* */
- }
- if (axis==5) {
- cox= 2; coy= 1; coz= 0; /* Y up X tr */
- }
-
- mat[coz][0] = vec[0];
- mat[coz][1] = vec[1];
- mat[coz][2] = vec[2];
- if (normalize_v3((float *)mat[coz]) == 0.f) {
- /* this is a very abnormal situation: the camera has reach the object center exactly
- * We will choose a completely arbitrary direction */
- mat[coz][0] = 1.0f;
- mat[coz][1] = 0.0f;
- mat[coz][2] = 0.0f;
- }
-
- inp = mat[coz][2];
- mat[coy][0] = - inp * mat[coz][0];
- mat[coy][1] = - inp * mat[coz][1];
- mat[coy][2] = 1.0f - inp * mat[coz][2];
-
- if (normalize_v3((float *)mat[coy]) == 0.f) {
- /* the camera is vertical, chose the y axis arbitrary */
- mat[coy][0] = 0.f;
- mat[coy][1] = 1.f;
- mat[coy][2] = 0.f;
- }
-
- cross_v3_v3v3(mat[cox], mat[coy], mat[coz]);
-}
-
-bool KX_CameraActuator::Update(double curtime, bool frame)
-{
- /* wondering... is it really necessary/desirable to suppress negative */
- /* events here? */
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent || !m_ob)
- return false;
-
- KX_GameObject *obj = (KX_GameObject*) GetParent();
- MT_Point3 from = obj->NodeGetWorldPosition();
- MT_Matrix3x3 frommat = obj->NodeGetWorldOrientation();
- /* These casts are _very_ dangerous!!! */
- MT_Point3 lookat = ((KX_GameObject*)m_ob)->NodeGetWorldPosition();
- MT_Matrix3x3 actormat = ((KX_GameObject*)m_ob)->NodeGetWorldOrientation();
-
- float fp1[3]={0}, fp2[3]={0}, rc[3];
- float inp, fac; //, factor = 0.0; /* some factor... */
- float mindistsq, maxdistsq, distsq;
- float mat[3][3];
-
- /* The rules: */
- /* CONSTRAINT 1: not implemented */
- /* CONSTRAINT 2: can camera see actor? */
- /* CONSTRAINT 3: fixed height relative to floor below actor. */
- /* CONSTRAINT 4: camera rotates behind actor */
- /* CONSTRAINT 5: minimum / maximum distance */
- /* CONSTRAINT 6: again: fixed height relative to floor below actor */
- /* CONSTRAINT 7: track to floor below actor */
- /* CONSTRAINT 8: look a little bit left or right, depending on how the
- *
- * character is looking (horizontal x)
- */
-
- /* ...and then set the camera position. Since we assume the parent of */
- /* this actuator is always a camera, just set the parent position and */
- /* rotation. We do not check whether we really have a camera as parent. */
- /* It may be better to turn this into a general tracking actuator later */
- /* on, since lots of plausible relations can be filled in here. */
-
- /* ... set up some parameters ... */
- /* missing here: the 'floorloc' of the actor's shadow */
-
- mindistsq= m_minHeight*m_minHeight;
- maxdistsq= m_maxHeight*m_maxHeight;
-
- /* C1: not checked... is a future option */
-
- /* C2: blender test_visibility function. Can this be a ray-test? */
-
- /* C3: fixed height */
- from[2] = (15.0f * from[2] + lookat[2] + m_height) / 16.0f;
-
-
- /* C4: camera behind actor */
- switch (m_axis) {
- case OB_POSX:
- /* X */
- fp1[0] = actormat[0][0];
- fp1[1] = actormat[1][0];
- fp1[2] = actormat[2][0];
-
- fp2[0] = frommat[0][0];
- fp2[1] = frommat[1][0];
- fp2[2] = frommat[2][0];
- break;
- case OB_POSY:
- /* Y */
- fp1[0] = actormat[0][1];
- fp1[1] = actormat[1][1];
- fp1[2] = actormat[2][1];
-
- fp2[0] = frommat[0][1];
- fp2[1] = frommat[1][1];
- fp2[2] = frommat[2][1];
- break;
- case OB_NEGX:
- /* -X */
- fp1[0] = -actormat[0][0];
- fp1[1] = -actormat[1][0];
- fp1[2] = -actormat[2][0];
-
- fp2[0] = frommat[0][0];
- fp2[1] = frommat[1][0];
- fp2[2] = frommat[2][0];
- break;
- case OB_NEGY:
- /* -Y */
- fp1[0] = -actormat[0][1];
- fp1[1] = -actormat[1][1];
- fp1[2] = -actormat[2][1];
-
- fp2[0] = frommat[0][1];
- fp2[1] = frommat[1][1];
- fp2[2] = frommat[2][1];
- break;
- default:
- assert(0);
- break;
- }
-
- inp = fp1[0]*fp2[0] + fp1[1]*fp2[1] + fp1[2]*fp2[2];
- fac = (-1.0f + inp) * m_damping;
-
- from[0] += fac * fp1[0];
- from[1] += fac * fp1[1];
- from[2] += fac * fp1[2];
-
- /* only for it lies: cross test and perpendicular bites up */
- if (inp < 0.0f) {
- /* Don't do anything if the cross product is too small.
- * The camera up-axis becomes unstable and starts to oscillate.
- * The 0.01f threshold is arbitrary but seems to work well in practice. */
- float cross = fp1[0] * fp2[1] - fp1[1] * fp2[0];
- if (cross > 0.01f) {
- from[0] -= fac * fp1[1];
- from[1] += fac * fp1[0];
- }
- else if (cross < -0.01f) {
- from[0] += fac * fp1[1];
- from[1] -= fac * fp1[0];
- }
- }
-
- /* CONSTRAINT 5: minimum / maximum distance */
-
- rc[0] = (lookat[0]-from[0]);
- rc[1] = (lookat[1]-from[1]);
- rc[2] = (lookat[2]-from[2]);
- distsq = rc[0]*rc[0] + rc[1]*rc[1] + rc[2]*rc[2];
-
- if (distsq > maxdistsq) {
- distsq = 0.15f * (distsq - maxdistsq) / distsq;
-
- from[0] += distsq*rc[0];
- from[1] += distsq*rc[1];
- from[2] += distsq*rc[2];
- }
- else if (distsq < mindistsq) {
- distsq = 0.15f * (mindistsq - distsq) / mindistsq;
-
- from[0] -= distsq*rc[0];
- from[1] -= distsq*rc[1];
- from[2] -= distsq*rc[2];
- }
-
-
- /* CONSTRAINT 7: track to floor below actor */
- rc[0] = (lookat[0]-from[0]);
- rc[1] = (lookat[1]-from[1]);
- rc[2] = (lookat[2]-from[2]);
- Kx_VecUpMat3(rc, mat, 3); /* y up Track -z */
-
-
-
-
- /* now set the camera position and rotation */
-
- obj->NodeSetLocalPosition(from);
-
- actormat[0][0] = mat[0][0]; actormat[0][1] = mat[1][0]; actormat[0][2] = mat[2][0];
- actormat[1][0] = mat[0][1]; actormat[1][1] = mat[1][1]; actormat[1][2] = mat[2][1];
- actormat[2][0] = mat[0][2]; actormat[2][1] = mat[1][2]; actormat[2][2] = mat[2][2];
- obj->NodeSetLocalOrientation(actormat);
-
- return true;
-}
-
-CValue *KX_CameraActuator::findObject(const char *obName)
-{
- /* hook to object system */
- return NULL;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_CameraActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_CameraActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_CameraActuator::Methods[] = {
- {NULL, NULL} //Sentinel
-};
-
-PyAttributeDef KX_CameraActuator::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RW("min",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_minHeight),
- KX_PYATTRIBUTE_FLOAT_RW("max",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_maxHeight),
- KX_PYATTRIBUTE_FLOAT_RW("height",-FLT_MAX,FLT_MAX,KX_CameraActuator,m_height),
- KX_PYATTRIBUTE_SHORT_RW("axis", 0, 5, true, KX_CameraActuator, m_axis),
- KX_PYATTRIBUTE_RW_FUNCTION("object", KX_CameraActuator, pyattr_get_object, pyattr_set_object),
- KX_PYATTRIBUTE_FLOAT_RW("damping",0.f,10.f,KX_CameraActuator,m_damping),
- {NULL}
-};
-
-PyObject *KX_CameraActuator::pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_CameraActuator* self = static_cast<KX_CameraActuator*>(self_v);
- if (self->m_ob==NULL)
- Py_RETURN_NONE;
- else
- return self->m_ob->GetProxy();
-}
-
-int KX_CameraActuator::pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_CameraActuator* self = static_cast<KX_CameraActuator*>(self_v);
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(self->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_CameraActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (self->m_ob)
- self->m_ob->UnregisterActuator(self);
-
- if ((self->m_ob = (SCA_IObject*)gameobj))
- self->m_ob->RegisterActuator(self);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_CameraActuator.h b/source/gameengine/Ketsji/KX_CameraActuator.h
deleted file mode 100644
index fb0a7d88dd9..00000000000
--- a/source/gameengine/Ketsji/KX_CameraActuator.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * KX_CameraActuator.h
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_CameraActuator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_CAMERAACTUATOR_H__
-#define __KX_CAMERAACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "MT_Scalar.h"
-#include "SCA_LogicManager.h"
-
-/**
- * The camera actuator does a Robbie Muller perspective for you. This is a
- * weird set of rules that positions the camera sort of behind the object,
- * tracking, while avoiding any objects between the 'ideal' position and the
- * actor being tracked.
- */
-
-
-class KX_CameraActuator : public SCA_IActuator
-{
- Py_Header
-private :
- /** Object that will be tracked. */
- SCA_IObject *m_ob;
-
- /** height (float), */
- //const MT_Scalar m_height;
- /** min (float), */
- //const MT_Scalar m_minHeight;
- /** max (float), */
- //const MT_Scalar m_maxHeight;
-
- /** height (float), */
- float m_height;
-
- /** min (float), */
- float m_minHeight;
-
- /** max (float), */
- float m_maxHeight;
-
- /** axis the camera tries to get behind: +x/+y/-x/-y */
- short m_axis;
-
- /** damping (float), */
- float m_damping;
-
- /* get the KX_IGameObject with this name */
- CValue *findObject(const char *obName);
-
- /* parse x or y to a toggle pick */
- bool string2axischoice(const char *axisString);
-
- public:
- static STR_String X_AXIS_STRING;
- static STR_String Y_AXIS_STRING;
-
- /**
- * Set the bool toggle to true to use x lock, false for y lock
- */
- KX_CameraActuator(
-
- SCA_IObject *gameobj,
- //const CValue *ob,
- SCA_IObject *ob,
- float hght,
- float minhght,
- float maxhght,
- short axis,
- float damping
- );
-
-
- ~KX_CameraActuator();
-
-
-
- /** Methods Inherited from CValue */
- CValue* GetReplica();
- virtual void ProcessReplica();
-
-
- /** Methods inherited from SCA_IActuator */
- virtual bool Update(
- double curtime,
- bool frame
- );
- virtual bool UnlinkObject(SCA_IObject* clientobj);
-
- /** Methods inherited from SCA_ILogicBrick */
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /* set object to look at */
- static PyObject* pyattr_get_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __KX_CAMERAACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_CameraIpoSGController.cpp b/source/gameengine/Ketsji/KX_CameraIpoSGController.cpp
deleted file mode 100644
index a1c726209e1..00000000000
--- a/source/gameengine/Ketsji/KX_CameraIpoSGController.cpp
+++ /dev/null
@@ -1,126 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_CameraIpoSGController.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_CameraIpoSGController.h"
-#include "KX_ScalarInterpolator.h"
-#include "KX_Camera.h"
-#include "RAS_CameraData.h"
-
-#if defined(_WIN64)
-typedef unsigned __int64 uint_ptr;
-#else
-typedef unsigned long uint_ptr;
-#endif
-
-bool KX_CameraIpoSGController::Update(double currentTime)
-{
- if (m_modified)
- {
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- (*i)->Execute(m_ipotime);
- }
-
- SG_Spatial* ob = (SG_Spatial*)m_pObject;
- KX_Camera* kxcamera = (KX_Camera*) ob->GetSGClientObject();
- RAS_CameraData* camdata = kxcamera->GetCameraData();
-
- if (m_modify_lens)
- camdata->m_lens = m_lens;
-
- if (m_modify_clipstart )
- camdata->m_clipstart = m_clipstart;
-
- if (m_modify_clipend)
- camdata->m_clipend = m_clipend;
-
- if (m_modify_lens || m_modify_clipstart || m_modify_clipend)
- kxcamera->InvalidateProjectionMatrix();
-
- m_modified=false;
- }
- return false;
-}
-
-
-void KX_CameraIpoSGController::AddInterpolator(KX_IInterpolator* interp)
-{
- this->m_interpolators.push_back(interp);
-}
-
-SG_Controller* KX_CameraIpoSGController::GetReplica(class SG_Node* destnode)
-{
- KX_CameraIpoSGController* iporeplica = new KX_CameraIpoSGController(*this);
- // clear object that ipo acts on
- iporeplica->ClearObject();
-
- // dirty hack, ask Gino for a better solution in the ipo implementation
- // hacken en zagen, in what we call datahiding, not written for replication :(
-
- T_InterpolatorList oldlist = m_interpolators;
- iporeplica->m_interpolators.clear();
-
- T_InterpolatorList::iterator i;
- for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
- KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
- iporeplica->AddInterpolator(copyipo);
-
- MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
- uint_ptr orgbase = (uint_ptr)this;
- uint_ptr orgloc = (uint_ptr)scaal;
- uint_ptr offset = orgloc-orgbase;
- uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
- MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
- copyipo->SetNewTarget((MT_Scalar*)blaptr);
- }
-
- return iporeplica;
-}
-
-KX_CameraIpoSGController::~KX_CameraIpoSGController()
-{
-
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- delete (*i);
- }
-
-}
-
- void
-KX_CameraIpoSGController::SetOption(
- int option,
- int value)
-{
- /* Setting options */
-
-}
diff --git a/source/gameengine/Ketsji/KX_CameraIpoSGController.h b/source/gameengine/Ketsji/KX_CameraIpoSGController.h
deleted file mode 100644
index 1f6f211622c..00000000000
--- a/source/gameengine/Ketsji/KX_CameraIpoSGController.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_CameraIpoSGController.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_CAMERAIPOSGCONTROLLER_H__
-#define __KX_CAMERAIPOSGCONTROLLER_H__
-
-#include "SG_Controller.h"
-#include "SG_Spatial.h"
-
-#include "KX_IInterpolator.h"
-
-struct RAS_CameraData;
-
-class KX_CameraIpoSGController : public SG_Controller
-{
-public:
- MT_Scalar m_lens;
- MT_Scalar m_clipstart;
- MT_Scalar m_clipend;
-
-private:
- T_InterpolatorList m_interpolators;
- unsigned short m_modify_lens : 1;
- unsigned short m_modify_clipstart : 1;
- unsigned short m_modify_clipend : 1;
- bool m_modified;
-
- double m_ipotime;
-public:
- KX_CameraIpoSGController() :
- m_modify_lens(false),
- m_modify_clipstart(false),
- m_modify_clipend(false),
- m_modified(true),
- m_ipotime(0.0)
- {}
-
- ~KX_CameraIpoSGController();
- SG_Controller* GetReplica(class SG_Node* destnode);
- bool Update(double time);
-
- void
- SetOption(
- int option,
- int value
- );
-
- void SetSimulatedTime(double time) {
- m_ipotime = time;
- m_modified = true;
- }
- void SetModifyLens(bool modify) {
- m_modify_lens = modify;
- }
- void SetModifyClipEnd(bool modify) {
- m_modify_clipend = modify;
- }
- void SetModifyClipStart(bool modify) {
- m_modify_clipstart = modify;
- }
- void AddInterpolator(KX_IInterpolator* interp);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_CameraIpoSGController")
-#endif
-};
-
-#endif /* __KX_CAMERAIPOSGCONTROLLER_H__ */
diff --git a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp b/source/gameengine/Ketsji/KX_CharacterWrapper.cpp
deleted file mode 100644
index 44f06a9f1eb..00000000000
--- a/source/gameengine/Ketsji/KX_CharacterWrapper.cpp
+++ /dev/null
@@ -1,167 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_CharacterWrapper.cpp
- * \ingroup ketsji
- */
-
-#include "KX_CharacterWrapper.h"
-#include "PHY_ICharacter.h"
-#include "KX_PyMath.h"
-#include "BLI_utildefines.h"
-
-KX_CharacterWrapper::KX_CharacterWrapper(PHY_ICharacter* character) :
- PyObjectPlus(),
- m_character(character)
-{
-}
-
-KX_CharacterWrapper::~KX_CharacterWrapper()
-{
-}
-
-#ifdef WITH_PYTHON
-
-PyTypeObject KX_CharacterWrapper::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_CharacterWrapper",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyAttributeDef KX_CharacterWrapper::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("onGround", KX_CharacterWrapper, pyattr_get_onground),
- KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_CharacterWrapper, pyattr_get_gravity, pyattr_set_gravity),
- KX_PYATTRIBUTE_RW_FUNCTION("maxJumps", KX_CharacterWrapper, pyattr_get_max_jumps, pyattr_set_max_jumps),
- KX_PYATTRIBUTE_RO_FUNCTION("jumpCount", KX_CharacterWrapper, pyattr_get_jump_count),
- KX_PYATTRIBUTE_RW_FUNCTION("walkDirection", KX_CharacterWrapper, pyattr_get_walk_dir, pyattr_set_walk_dir),
- { NULL } //Sentinel
-};
-
-PyObject *KX_CharacterWrapper::pyattr_get_onground(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
-
- return PyBool_FromLong(self->m_character->OnGround());
-}
-
-PyObject *KX_CharacterWrapper::pyattr_get_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
-
- return PyFloat_FromDouble(self->m_character->GetGravity());
-}
-
-int KX_CharacterWrapper::pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
- double param = PyFloat_AsDouble(value);
-
- if (param == -1)
- {
- PyErr_SetString(PyExc_ValueError, "KX_CharacterWrapper.gravity: expected a float");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_character->SetGravity((float)param);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_CharacterWrapper::pyattr_get_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
-
- return PyLong_FromLong(self->m_character->GetMaxJumps());
-}
-
-int KX_CharacterWrapper::pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
- long param = PyLong_AsLong(value);
-
- if (param == -1)
- {
- PyErr_SetString(PyExc_ValueError, "KX_CharacterWrapper.maxJumps: expected an integer");
- return PY_SET_ATTR_FAIL;
- }
-
- CLAMP(param, 0, 255);
-
- self->m_character->SetMaxJumps(param);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_CharacterWrapper::pyattr_get_jump_count(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
-
- return PyLong_FromLong(self->m_character->GetJumpCount());
-}
-
-PyObject *KX_CharacterWrapper::pyattr_get_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
-
- return PyObjectFrom(self->m_character->GetWalkDirection());
-}
-
-int KX_CharacterWrapper::pyattr_set_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_CharacterWrapper* self = static_cast<KX_CharacterWrapper*>(self_v);
- MT_Vector3 dir;
- if (!PyVecTo(value, dir)) {
- PyErr_SetString(PyExc_TypeError, "KX_CharacterWrapper.walkDirection: expected a vector");
- return PY_SET_ATTR_FAIL;
- }
-
- self->m_character->SetWalkDirection(dir);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyMethodDef KX_CharacterWrapper::Methods[] = {
- KX_PYMETHODTABLE_NOARGS(KX_CharacterWrapper, jump),
- {NULL,NULL} //Sentinel
-};
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_CharacterWrapper, jump,
- "jump()\n"
- "makes the character jump.\n")
-{
- m_character->Jump();
-
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_CharacterWrapper.h b/source/gameengine/Ketsji/KX_CharacterWrapper.h
deleted file mode 100644
index dd7ba680ec7..00000000000
--- a/source/gameengine/Ketsji/KX_CharacterWrapper.h
+++ /dev/null
@@ -1,40 +0,0 @@
-
-/** \file KX_CharacterWrapper.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_CHARACTERWRAPPER_H__
-#define __KX_CHARACTERWRAPPER_H__
-
-#include "EXP_Value.h"
-#include "PHY_DynamicTypes.h"
-class PHY_ICharacter;
-
-
-///Python interface to character physics
-class KX_CharacterWrapper : public PyObjectPlus
-{
- Py_Header
-
-public:
- KX_CharacterWrapper(PHY_ICharacter* character);
- virtual ~KX_CharacterWrapper();
-#ifdef WITH_PYTHON
- KX_PYMETHOD_DOC_NOARGS(KX_CharacterWrapper, jump);
-
- static PyObject* pyattr_get_onground(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- static PyObject* pyattr_get_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_max_jumps(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_jump_count(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_walk_dir(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif // WITH_PYTHON
-
-private:
- PHY_ICharacter* m_character;
-};
-
-#endif /* __KX_CHARACTERWRAPPER_H__ */
diff --git a/source/gameengine/Ketsji/KX_ClientObjectInfo.h b/source/gameengine/Ketsji/KX_ClientObjectInfo.h
deleted file mode 100644
index 81ae5b58009..00000000000
--- a/source/gameengine/Ketsji/KX_ClientObjectInfo.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ClientObjectInfo.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_CLIENTOBJECTINFO_H__
-#define __KX_CLIENTOBJECTINFO_H__
-
-/* Note, the way this works with/without sumo is a bit odd */
-
-#include <list>
-
-class SCA_ISensor;
-class KX_GameObject;
-/**
- * Client Type and Additional Info. This structure can be use instead of a bare void* pointer, for safeness, and additional info for callbacks
- */
-struct KX_ClientObjectInfo
-{
- enum clienttype {
- STATIC,
- ACTOR,
- RESERVED1,
- SENSOR,
- OBSENSOR,
- OBACTORSENSOR
- } m_type;
- KX_GameObject* m_gameobject;
- std::list<SCA_ISensor*> m_sensors;
-public:
- KX_ClientObjectInfo(KX_GameObject *gameobject, clienttype type = STATIC) :
- m_type(type),
- m_gameobject(gameobject)
- {}
-
- KX_ClientObjectInfo(const KX_ClientObjectInfo &copy) :
- m_type(copy.m_type),
- m_gameobject(copy.m_gameobject)
- {
- }
-
- virtual ~KX_ClientObjectInfo() {}
-
- virtual bool hasCollisionCallback()
- {
- return m_sensors.size() != 0;
- }
-
- bool isActor() { return m_type <= ACTOR; }
- bool isSensor() { return m_type >= SENSOR && m_type <= OBACTORSENSOR; }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_ClientObjectInfo")
-#endif
-};
-
-#endif /* __KX_CLIENTOBJECTINFO_H__ */
diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp b/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
deleted file mode 100644
index 27c074393b4..00000000000
--- a/source/gameengine/Ketsji/KX_ConstraintActuator.cpp
+++ /dev/null
@@ -1,629 +0,0 @@
-/*
- * Apply a constraint to a position or rotation value
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ConstraintActuator.cpp
- * \ingroup ketsji
- */
-
-
-#include "SCA_IActuator.h"
-#include "KX_ConstraintActuator.h"
-#include "SCA_IObject.h"
-#include "MT_Point3.h"
-#include "MT_Matrix3x3.h"
-#include "KX_GameObject.h"
-#include "KX_RayCast.h"
-#include "KX_PythonInit.h" // KX_GetActiveScene
-#include "RAS_MeshObject.h"
-
-#include <stdio.h>
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_ConstraintActuator::KX_ConstraintActuator(SCA_IObject *gameobj,
- int posDampTime,
- int rotDampTime,
- float minBound,
- float maxBound,
- float refDir[3],
- int locrotxyz,
- int time,
- int option,
- char *property) :
- SCA_IActuator(gameobj, KX_ACT_CONSTRAINT),
- m_refDirVector(refDir),
- m_currentTime(0)
-{
- m_refDirection[0] = refDir[0];
- m_refDirection[1] = refDir[1];
- m_refDirection[2] = refDir[2];
- m_posDampTime = posDampTime;
- m_rotDampTime = rotDampTime;
- m_locrot = locrotxyz;
- m_option = option;
- m_activeTime = time;
- if (property) {
- m_property = property;
- } else {
- m_property = "";
- }
- /* The units of bounds are determined by the type of constraint. To */
- /* make the constraint application easier and more transparent later on, */
- /* I think converting the bounds to the applicable domain makes more */
- /* sense. */
- switch (m_locrot) {
- case KX_ACT_CONSTRAINT_ORIX:
- case KX_ACT_CONSTRAINT_ORIY:
- case KX_ACT_CONSTRAINT_ORIZ:
- {
- MT_Scalar len = m_refDirVector.length();
- if (MT_fuzzyZero(len)) {
- // missing a valid direction
- std::cout << "WARNING: Constraint actuator " << GetName() << ": There is no valid reference direction!" << std::endl;
- m_locrot = KX_ACT_CONSTRAINT_NODEF;
- } else {
- m_refDirection[0] /= len;
- m_refDirection[1] /= len;
- m_refDirection[2] /= len;
- m_refDirVector /= len;
- }
- m_minimumBound = cosf(minBound);
- m_maximumBound = cosf(maxBound);
- m_minimumSine = sinf(minBound);
- m_maximumSine = sinf(maxBound);
- }
- break;
- default:
- m_minimumBound = minBound;
- m_maximumBound = maxBound;
- m_minimumSine = 0.f;
- m_maximumSine = 0.f;
- break;
- }
-
-} /* End of constructor */
-
-KX_ConstraintActuator::~KX_ConstraintActuator()
-{
- // there's nothing to be done here, really....
-} /* end of destructor */
-
-bool KX_ConstraintActuator::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void *UNUSED(data))
-{
-
- m_hitObject = client->m_gameobject;
-
- bool bFound = false;
-
- if (m_property.IsEmpty())
- {
- bFound = true;
- }
- else
- {
- if (m_option & KX_ACT_CONSTRAINT_MATERIAL) {
- for (unsigned int i = 0; i < m_hitObject->GetMeshCount(); ++i) {
- RAS_MeshObject *meshObj = m_hitObject->GetMesh(i);
- for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) {
- bFound = strcmp(m_property.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0;
- if (bFound)
- break;
- }
- }
- }
- else {
- bFound = m_hitObject->GetProperty(m_property) != NULL;
- }
- }
- // update the hit status
- result->m_hitFound = bFound;
- // stop looking
- return true;
-}
-
-/* This function is used to pre-filter the object before casting the ray on them.
- * This is useful for "X-Ray" option when we want to see "through" unwanted object.
- */
-bool KX_ConstraintActuator::NeedRayCast(KX_ClientObjectInfo *client, void *UNUSED(data))
-{
- if (client->m_type > KX_ClientObjectInfo::ACTOR)
- {
- // Unknown type of object, skip it.
- // Should not occur as the sensor objects are filtered in RayTest()
- printf("Invalid client type %d found in ray casting\n", client->m_type);
- return false;
- }
- // no X-Ray function yet
- return true;
-}
-
-bool KX_ConstraintActuator::Update(double curtime, bool frame)
-{
-
- bool result = false;
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (!bNegativeEvent) {
- /* Constraint clamps the values to the specified range, with a sort of */
- /* low-pass filtered time response, if the damp time is unequal to 0. */
-
- /* Having to retrieve location/rotation and setting it afterwards may not */
- /* be efficient enough... Something to look at later. */
- KX_GameObject *obj = (KX_GameObject*) GetParent();
- MT_Point3 position = obj->NodeGetWorldPosition();
- MT_Point3 newposition;
- MT_Vector3 normal, direction, refDirection;
- MT_Matrix3x3 rotation = obj->NodeGetWorldOrientation();
- MT_Scalar filter, newdistance, cosangle;
- int axis, sign;
-
- if (m_posDampTime) {
- filter = m_posDampTime/(1.0f+m_posDampTime);
- } else {
- filter = 0.0f;
- }
- switch (m_locrot) {
- case KX_ACT_CONSTRAINT_ORIX:
- case KX_ACT_CONSTRAINT_ORIY:
- case KX_ACT_CONSTRAINT_ORIZ:
- switch (m_locrot) {
- case KX_ACT_CONSTRAINT_ORIX:
- direction[0] = rotation[0][0];
- direction[1] = rotation[1][0];
- direction[2] = rotation[2][0];
- axis = 0;
- break;
- case KX_ACT_CONSTRAINT_ORIY:
- direction[0] = rotation[0][1];
- direction[1] = rotation[1][1];
- direction[2] = rotation[2][1];
- axis = 1;
- break;
- default:
- direction[0] = rotation[0][2];
- direction[1] = rotation[1][2];
- direction[2] = rotation[2][2];
- axis = 2;
- break;
- }
- if ((m_maximumBound < (1.0f-FLT_EPSILON)) || (m_minimumBound < (1.0f-FLT_EPSILON))) {
- // reference direction needs to be evaluated
- // 1. get the cosine between current direction and target
- cosangle = direction.dot(m_refDirVector);
- if (cosangle >= (m_maximumBound-FLT_EPSILON) && cosangle <= (m_minimumBound+FLT_EPSILON)) {
- // no change to do
- result = true;
- goto CHECK_TIME;
- }
- // 2. define a new reference direction
- // compute local axis with reference direction as X and
- // Y in direction X refDirection plane
- MT_Vector3 zaxis = m_refDirVector.cross(direction);
- if (MT_fuzzyZero2(zaxis.length2())) {
- // direction and refDirection are identical,
- // choose any other direction to define plane
- if (direction[0] < 0.9999f)
- zaxis = m_refDirVector.cross(MT_Vector3(1.0f,0.0f,0.0f));
- else
- zaxis = m_refDirVector.cross(MT_Vector3(0.0f,1.0f,0.0f));
- }
- MT_Vector3 yaxis = zaxis.cross(m_refDirVector);
- yaxis.normalize();
- if (cosangle > m_minimumBound) {
- // angle is too close to reference direction,
- // choose a new reference that is exactly at minimum angle
- refDirection = m_minimumBound * m_refDirVector + m_minimumSine * yaxis;
- } else {
- // angle is too large, choose new reference direction at maximum angle
- refDirection = m_maximumBound * m_refDirVector + m_maximumSine * yaxis;
- }
- } else {
- refDirection = m_refDirVector;
- }
- // apply damping on the direction
- direction = filter*direction + (1.0f-filter)*refDirection;
- obj->AlignAxisToVect(direction, axis);
- result = true;
- goto CHECK_TIME;
- case KX_ACT_CONSTRAINT_DIRPX:
- case KX_ACT_CONSTRAINT_DIRPY:
- case KX_ACT_CONSTRAINT_DIRPZ:
- case KX_ACT_CONSTRAINT_DIRNX:
- case KX_ACT_CONSTRAINT_DIRNY:
- case KX_ACT_CONSTRAINT_DIRNZ:
- switch (m_locrot) {
- case KX_ACT_CONSTRAINT_DIRPX:
- normal[0] = rotation[0][0];
- normal[1] = rotation[1][0];
- normal[2] = rotation[2][0];
- axis = 0; // axis according to KX_GameObject::AlignAxisToVect()
- sign = 0; // X axis will be parrallel to direction of ray
- break;
- case KX_ACT_CONSTRAINT_DIRPY:
- normal[0] = rotation[0][1];
- normal[1] = rotation[1][1];
- normal[2] = rotation[2][1];
- axis = 1;
- sign = 0;
- break;
- case KX_ACT_CONSTRAINT_DIRPZ:
- normal[0] = rotation[0][2];
- normal[1] = rotation[1][2];
- normal[2] = rotation[2][2];
- axis = 2;
- sign = 0;
- break;
- case KX_ACT_CONSTRAINT_DIRNX:
- normal[0] = -rotation[0][0];
- normal[1] = -rotation[1][0];
- normal[2] = -rotation[2][0];
- axis = 0;
- sign = 1;
- break;
- case KX_ACT_CONSTRAINT_DIRNY:
- normal[0] = -rotation[0][1];
- normal[1] = -rotation[1][1];
- normal[2] = -rotation[2][1];
- axis = 1;
- sign = 1;
- break;
- case KX_ACT_CONSTRAINT_DIRNZ:
- normal[0] = -rotation[0][2];
- normal[1] = -rotation[1][2];
- normal[2] = -rotation[2][2];
- axis = 2;
- sign = 1;
- break;
- }
- normal.normalize();
- if (m_option & KX_ACT_CONSTRAINT_LOCAL) {
- // direction of the ray is along the local axis
- direction = normal;
- } else {
- switch (m_locrot) {
- case KX_ACT_CONSTRAINT_DIRPX:
- direction = MT_Vector3(1.0f,0.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_DIRPY:
- direction = MT_Vector3(0.0f,1.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_DIRPZ:
- direction = MT_Vector3(0.0f,0.0f,1.0f);
- break;
- case KX_ACT_CONSTRAINT_DIRNX:
- direction = MT_Vector3(-1.0f,0.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_DIRNY:
- direction = MT_Vector3(0.0f,-1.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_DIRNZ:
- direction = MT_Vector3(0.0f,0.0f,-1.0f);
- break;
- }
- }
- {
- MT_Point3 topoint = position + (m_maximumBound) * direction;
- PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
- PHY_IPhysicsController *spc = obj->GetPhysicsController();
-
- if (!pe) {
- std::cout << "WARNING: Constraint actuator " << GetName() << ": There is no physics environment!" << std::endl;
- goto CHECK_TIME;
- }
- if (!spc) {
- // the object is not physical, we probably want to avoid hitting its own parent
- KX_GameObject *parent = obj->GetParent();
- if (parent) {
- spc = parent->GetPhysicsController();
- }
- }
- KX_RayCast::Callback<KX_ConstraintActuator, void> callback(this,dynamic_cast<PHY_IPhysicsController*>(spc));
- result = KX_RayCast::RayTest(pe, position, topoint, callback);
- if (result) {
- MT_Vector3 newnormal = callback.m_hitNormal;
- // compute new position & orientation
- if ((m_option & (KX_ACT_CONSTRAINT_NORMAL|KX_ACT_CONSTRAINT_DISTANCE)) == 0) {
- // if none option is set, the actuator does nothing but detect ray
- // (works like a sensor)
- goto CHECK_TIME;
- }
- if (m_option & KX_ACT_CONSTRAINT_NORMAL) {
- MT_Scalar rotFilter;
- // apply damping on the direction
- if (m_rotDampTime) {
- rotFilter = m_rotDampTime/(1.0f+m_rotDampTime);
- } else {
- rotFilter = filter;
- }
- newnormal = rotFilter*normal - (1.0f-rotFilter)*newnormal;
- obj->AlignAxisToVect((sign)?-newnormal:newnormal, axis);
- if (m_option & KX_ACT_CONSTRAINT_LOCAL) {
- direction = newnormal;
- direction.normalize();
- }
- }
- if (m_option & KX_ACT_CONSTRAINT_DISTANCE) {
- if (m_posDampTime) {
- newdistance = filter*(position-callback.m_hitPoint).length()+(1.0f-filter)*m_minimumBound;
- } else {
- newdistance = m_minimumBound;
- }
- // logically we should cancel the speed along the ray direction as we set the
- // position along that axis
- spc = obj->GetPhysicsController();
- if (spc && spc->IsDynamic()) {
- MT_Vector3 linV = spc->GetLinearVelocity();
- // cancel the projection along the ray direction
- MT_Scalar fallspeed = linV.dot(direction);
- if (!MT_fuzzyZero(fallspeed))
- spc->SetLinearVelocity(linV-fallspeed*direction,false);
- }
- } else {
- newdistance = (position-callback.m_hitPoint).length();
- }
- newposition = callback.m_hitPoint-newdistance*direction;
- } else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
- // no contact but still keep running
- result = true;
- goto CHECK_TIME;
- }
- }
- break;
- case KX_ACT_CONSTRAINT_FHPX:
- case KX_ACT_CONSTRAINT_FHPY:
- case KX_ACT_CONSTRAINT_FHPZ:
- case KX_ACT_CONSTRAINT_FHNX:
- case KX_ACT_CONSTRAINT_FHNY:
- case KX_ACT_CONSTRAINT_FHNZ:
- switch (m_locrot) {
- case KX_ACT_CONSTRAINT_FHPX:
- normal[0] = -rotation[0][0];
- normal[1] = -rotation[1][0];
- normal[2] = -rotation[2][0];
- direction = MT_Vector3(1.0f,0.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_FHPY:
- normal[0] = -rotation[0][1];
- normal[1] = -rotation[1][1];
- normal[2] = -rotation[2][1];
- direction = MT_Vector3(0.0f,1.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_FHPZ:
- normal[0] = -rotation[0][2];
- normal[1] = -rotation[1][2];
- normal[2] = -rotation[2][2];
- direction = MT_Vector3(0.0f,0.0f,1.0f);
- break;
- case KX_ACT_CONSTRAINT_FHNX:
- normal[0] = rotation[0][0];
- normal[1] = rotation[1][0];
- normal[2] = rotation[2][0];
- direction = MT_Vector3(-1.0f,0.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_FHNY:
- normal[0] = rotation[0][1];
- normal[1] = rotation[1][1];
- normal[2] = rotation[2][1];
- direction = MT_Vector3(0.0f,-1.0f,0.0f);
- break;
- case KX_ACT_CONSTRAINT_FHNZ:
- normal[0] = rotation[0][2];
- normal[1] = rotation[1][2];
- normal[2] = rotation[2][2];
- direction = MT_Vector3(0.0f,0.0f,-1.0f);
- break;
- }
- normal.normalize();
- {
- PHY_IPhysicsEnvironment* pe = KX_GetActiveScene()->GetPhysicsEnvironment();
- PHY_IPhysicsController *spc = obj->GetPhysicsController();
-
- if (!pe) {
- std::cout << "WARNING: Constraint actuator " << GetName() << ": There is no physics environment!" << std::endl;
- goto CHECK_TIME;
- }
- if (!spc || !spc->IsDynamic()) {
- // the object is not dynamic, it won't support setting speed
- goto CHECK_TIME;
- }
- m_hitObject = NULL;
- // distance of Fh area is stored in m_minimum
- MT_Point3 topoint = position + (m_minimumBound+spc->GetRadius()) * direction;
- KX_RayCast::Callback<KX_ConstraintActuator, void> callback(this, spc);
- result = KX_RayCast::RayTest(pe, position, topoint, callback);
- // we expect a hit object
- if (!m_hitObject)
- result = false;
- if (result)
- {
- MT_Vector3 newnormal = callback.m_hitNormal;
- // compute new position & orientation
- MT_Scalar distance = (callback.m_hitPoint-position).length()-spc->GetRadius();
- // estimate the velocity of the hit point
- MT_Point3 relativeHitPoint;
- relativeHitPoint = (callback.m_hitPoint-m_hitObject->NodeGetWorldPosition());
- MT_Vector3 velocityHitPoint = m_hitObject->GetVelocity(relativeHitPoint);
- MT_Vector3 relativeVelocity = spc->GetLinearVelocity() - velocityHitPoint;
- MT_Scalar relativeVelocityRay = direction.dot(relativeVelocity);
- MT_Scalar springExtent = 1.0f - distance/m_minimumBound;
- // Fh force is stored in m_maximum
- MT_Scalar springForce = springExtent * m_maximumBound;
- // damping is stored in m_refDirection [0] = damping, [1] = rot damping
- MT_Scalar springDamp = relativeVelocityRay * m_refDirVector[0];
- MT_Vector3 newVelocity = spc->GetLinearVelocity()-(springForce+springDamp)*direction;
- if (m_option & KX_ACT_CONSTRAINT_NORMAL)
- {
- newVelocity+=(springForce+springDamp)*(newnormal-newnormal.dot(direction)*direction);
- }
- spc->SetLinearVelocity(newVelocity, false);
- if (m_option & KX_ACT_CONSTRAINT_DOROTFH)
- {
- MT_Vector3 angSpring = (normal.cross(newnormal))*m_maximumBound;
- MT_Vector3 angVelocity = spc->GetAngularVelocity();
- // remove component that is parallel to normal
- angVelocity -= angVelocity.dot(newnormal)*newnormal;
- MT_Vector3 angDamp = angVelocity * ((m_refDirVector[1]>MT_EPSILON)?m_refDirVector[1]:m_refDirVector[0]);
- spc->SetAngularVelocity(spc->GetAngularVelocity()+(angSpring-angDamp), false);
- }
- } else if (m_option & KX_ACT_CONSTRAINT_PERMANENT) {
- // no contact but still keep running
- result = true;
- }
- // don't set the position with this constraint
- goto CHECK_TIME;
- }
- break;
- case KX_ACT_CONSTRAINT_LOCX:
- case KX_ACT_CONSTRAINT_LOCY:
- case KX_ACT_CONSTRAINT_LOCZ:
- newposition = position = obj->GetSGNode()->GetLocalPosition();
- switch (m_locrot) {
- case KX_ACT_CONSTRAINT_LOCX:
- Clamp(newposition[0], m_minimumBound, m_maximumBound);
- break;
- case KX_ACT_CONSTRAINT_LOCY:
- Clamp(newposition[1], m_minimumBound, m_maximumBound);
- break;
- case KX_ACT_CONSTRAINT_LOCZ:
- Clamp(newposition[2], m_minimumBound, m_maximumBound);
- break;
- }
- result = true;
- if (m_posDampTime) {
- newposition = filter*position + (1.0f-filter)*newposition;
- }
- obj->NodeSetLocalPosition(newposition);
- goto CHECK_TIME;
- }
- if (result) {
- // set the new position but take into account parent if any
- obj->NodeSetWorldPosition(newposition);
- }
- CHECK_TIME:
- if (result && m_activeTime > 0 ) {
- if (++m_currentTime >= m_activeTime)
- result = false;
- }
- }
- if (!result) {
- m_currentTime = 0;
- }
- return result;
-} /* end of KX_ConstraintActuator::Update(double curtime,double deltatime) */
-
-void KX_ConstraintActuator::Clamp(MT_Scalar &var,
- float min,
- float max) {
- if (var < min) {
- var = min;
- } else if (var > max) {
- var = max;
- }
-}
-
-
-bool KX_ConstraintActuator::IsValidMode(KX_ConstraintActuator::KX_CONSTRAINTTYPE m)
-{
- bool res = false;
-
- if ( (m > KX_ACT_CONSTRAINT_NODEF) && (m < KX_ACT_CONSTRAINT_MAX)) {
- res = true;
- }
-
- return res;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_ConstraintActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_ConstraintActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_ConstraintActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_ConstraintActuator::Attributes[] = {
- KX_PYATTRIBUTE_INT_RW("damp",0,100,true,KX_ConstraintActuator,m_posDampTime),
- KX_PYATTRIBUTE_INT_RW("rotDamp",0,100,true,KX_ConstraintActuator,m_rotDampTime),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RW_CHECK("direction",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_refDirection,3,pyattr_check_direction),
- KX_PYATTRIBUTE_INT_RW("option",0,0xFFFF,false,KX_ConstraintActuator,m_option),
- KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_ConstraintActuator,m_activeTime),
- KX_PYATTRIBUTE_STRING_RW("propName",0,MAX_PROP_NAME,true,KX_ConstraintActuator,m_property),
- KX_PYATTRIBUTE_FLOAT_RW("min",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound),
- KX_PYATTRIBUTE_FLOAT_RW("distance",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_minimumBound),
- KX_PYATTRIBUTE_FLOAT_RW("max",-FLT_MAX,FLT_MAX,KX_ConstraintActuator,m_maximumBound),
- KX_PYATTRIBUTE_FLOAT_RW("rayLength",0,2000.f,KX_ConstraintActuator,m_maximumBound),
- KX_PYATTRIBUTE_INT_RW("limit",KX_ConstraintActuator::KX_ACT_CONSTRAINT_NODEF+1,KX_ConstraintActuator::KX_ACT_CONSTRAINT_MAX-1,false,KX_ConstraintActuator,m_locrot),
- { NULL } //Sentinel
-};
-
-int KX_ConstraintActuator::pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ConstraintActuator* act = static_cast<KX_ConstraintActuator*>(self);
- MT_Vector3 dir(act->m_refDirection);
- MT_Scalar len = dir.length();
- if (MT_fuzzyZero(len)) {
- PyErr_SetString(PyExc_ValueError, "actuator.direction = vec: KX_ConstraintActuator, invalid direction");
- return 1;
- }
- act->m_refDirVector = dir/len;
- return 0;
-}
-
-#endif
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_ConstraintActuator.h b/source/gameengine/Ketsji/KX_ConstraintActuator.h
deleted file mode 100644
index af617655d5e..00000000000
--- a/source/gameengine/Ketsji/KX_ConstraintActuator.h
+++ /dev/null
@@ -1,152 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConstraintActuator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_CONSTRAINTACTUATOR_H__
-#define __KX_CONSTRAINTACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "MT_Scalar.h"
-#include "MT_Vector3.h"
-#include "KX_ClientObjectInfo.h"
-
-#include "BLI_utildefines.h"
-
-class KX_RayCast;
-class KX_GameObject;
-
-class KX_ConstraintActuator : public SCA_IActuator
-{
- Py_Header
-protected:
- // Damp time (int),
- int m_posDampTime;
- int m_rotDampTime;
- // min (float)
- float m_minimumBound;
- // max (float)
- float m_maximumBound;
- // sinus of minimum angle
- float m_minimumSine;
- // sinus of maximum angle
- float m_maximumSine;
- // reference direction
- float m_refDirection[3];
- MT_Vector3 m_refDirVector; // same as m_refDirection
- // locrotxyz choice (pick one): only one choice allowed at a time!
- int m_locrot;
- // active time of actuator
- int m_activeTime;
- int m_currentTime;
- // option
- int m_option;
- // property to check
- STR_String m_property;
- // hit object
- KX_GameObject* m_hitObject;
-
- /**
- * Clamp <var> to <min>, <max>. Borders are included (in as far as
- * float comparisons are good for equality...).
- */
- void Clamp(MT_Scalar &var, float min, float max);
-
-
- public:
- // m_locrot
- enum KX_CONSTRAINTTYPE {
- KX_ACT_CONSTRAINT_NODEF = 0,
- KX_ACT_CONSTRAINT_LOCX,
- KX_ACT_CONSTRAINT_LOCY,
- KX_ACT_CONSTRAINT_LOCZ,
- KX_ACT_CONSTRAINT_ROTX,
- KX_ACT_CONSTRAINT_ROTY,
- KX_ACT_CONSTRAINT_ROTZ,
- KX_ACT_CONSTRAINT_DIRPX,
- KX_ACT_CONSTRAINT_DIRPY,
- KX_ACT_CONSTRAINT_DIRPZ,
- KX_ACT_CONSTRAINT_DIRNX,
- KX_ACT_CONSTRAINT_DIRNY,
- KX_ACT_CONSTRAINT_DIRNZ,
- KX_ACT_CONSTRAINT_ORIX,
- KX_ACT_CONSTRAINT_ORIY,
- KX_ACT_CONSTRAINT_ORIZ,
- KX_ACT_CONSTRAINT_FHPX,
- KX_ACT_CONSTRAINT_FHPY,
- KX_ACT_CONSTRAINT_FHPZ,
- KX_ACT_CONSTRAINT_FHNX,
- KX_ACT_CONSTRAINT_FHNY,
- KX_ACT_CONSTRAINT_FHNZ,
- KX_ACT_CONSTRAINT_MAX
- };
- // match ACT_CONST_... values from BIF_interface.h
- enum KX_CONSTRAINTOPT {
- KX_ACT_CONSTRAINT_NORMAL = 64,
- KX_ACT_CONSTRAINT_MATERIAL = 128,
- KX_ACT_CONSTRAINT_PERMANENT = 256,
- KX_ACT_CONSTRAINT_DISTANCE = 512,
- KX_ACT_CONSTRAINT_LOCAL = 1024,
- KX_ACT_CONSTRAINT_DOROTFH = 2048
- };
- bool IsValidMode(KX_CONSTRAINTTYPE m);
- /// \see KX_RayCast
- bool RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void *UNUSED(data));
- /// \see KX_RayCast
- bool NeedRayCast(KX_ClientObjectInfo *client, void *UNUSED(data));
-
- KX_ConstraintActuator(SCA_IObject* gameobj,
- int posDamptime,
- int rotDampTime,
- float min,
- float max,
- float refDir[3],
- int locrot,
- int time,
- int option,
- char *property);
- virtual ~KX_ConstraintActuator();
- virtual CValue* GetReplica() {
- KX_ConstraintActuator* replica = new KX_ConstraintActuator(*this);
- replica->ProcessReplica();
- return replica;
- };
-
- virtual bool Update(double curtime, bool frame);
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- static int pyattr_check_direction(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_check_min(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-
-};
-
-#endif /* __KX_CONSTRAINTACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp b/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
deleted file mode 100644
index 2f32b5e3216..00000000000
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.cpp
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ConstraintWrapper.cpp
- * \ingroup ketsji
- */
-
-
-#include "EXP_PyObjectPlus.h"
-#include "KX_ConstraintWrapper.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-KX_ConstraintWrapper::KX_ConstraintWrapper(
- PHY_ConstraintType ctype,
- int constraintId,
- PHY_IPhysicsEnvironment* physenv) :
- PyObjectPlus(),
- m_constraintId(constraintId),
- m_constraintType(ctype),
- m_physenv(physenv)
-{
-}
-KX_ConstraintWrapper::~KX_ConstraintWrapper()
-{
-}
-
-#ifdef WITH_PYTHON
-
-PyObject *KX_ConstraintWrapper::PyGetConstraintId()
-{
- return PyLong_FromLong(m_constraintId);
-}
-
-
-PyObject *KX_ConstraintWrapper::PyGetParam(PyObject *args, PyObject *kwds)
-{
- int dof;
- float value;
-
- if (!PyArg_ParseTuple(args,"i:getParam",&dof))
- return NULL;
-
- value = m_physenv->GetConstraintParam(m_constraintId,dof);
- return PyFloat_FromDouble(value);
-
-}
-
-PyObject *KX_ConstraintWrapper::PySetParam(PyObject *args, PyObject *kwds)
-{
- int dof;
- float minLimit,maxLimit;
-
- if (!PyArg_ParseTuple(args,"iff:setParam",&dof,&minLimit,&maxLimit))
- return NULL;
-
- m_physenv->SetConstraintParam(m_constraintId,dof,minLimit,maxLimit);
- Py_RETURN_NONE;
-}
-
-
-//python specific stuff
-PyTypeObject KX_ConstraintWrapper::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_ConstraintWrapper",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_ConstraintWrapper::Methods[] = {
- {"getConstraintId",(PyCFunction) KX_ConstraintWrapper::sPyGetConstraintId, METH_NOARGS},
- {"setParam",(PyCFunction) KX_ConstraintWrapper::sPySetParam, METH_VARARGS},
- {"getParam",(PyCFunction) KX_ConstraintWrapper::sPyGetParam, METH_VARARGS},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_ConstraintWrapper::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("constraint_id", KX_ConstraintWrapper, pyattr_get_constraintId),
- KX_PYATTRIBUTE_RO_FUNCTION("constraint_type", KX_ConstraintWrapper, pyattr_get_constraintType),
- { NULL } //Sentinel
-};
-
-PyObject *KX_ConstraintWrapper::pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ConstraintWrapper* self = static_cast<KX_ConstraintWrapper*>(self_v);
- return self->PyGetConstraintId();
-}
-
-PyObject *KX_ConstraintWrapper::pyattr_get_constraintType(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ConstraintWrapper* self = static_cast<KX_ConstraintWrapper*>(self_v);
- return PyLong_FromLong(self->m_constraintType);
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_ConstraintWrapper.h b/source/gameengine/Ketsji/KX_ConstraintWrapper.h
deleted file mode 100644
index 5e20b7a9aca..00000000000
--- a/source/gameengine/Ketsji/KX_ConstraintWrapper.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ConstraintWrapper.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_CONSTRAINTWRAPPER_H__
-#define __KX_CONSTRAINTWRAPPER_H__
-
-#include "EXP_Value.h"
-#include "PHY_DynamicTypes.h"
-
-class KX_ConstraintWrapper : public PyObjectPlus
-{
- Py_Header
-public:
- KX_ConstraintWrapper(PHY_ConstraintType ctype,int constraintId,class PHY_IPhysicsEnvironment* physenv);
- virtual ~KX_ConstraintWrapper ();
- int getConstraintId() { return m_constraintId; }
-
-#ifdef WITH_PYTHON
- KX_PYMETHOD_NOARGS(KX_ConstraintWrapper,GetConstraintId);
- KX_PYMETHOD(KX_ConstraintWrapper,SetParam);
- KX_PYMETHOD(KX_ConstraintWrapper,GetParam);
-
- static PyObject *pyattr_get_constraintId(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_constraintType(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-
-private:
- int m_constraintId;
- PHY_ConstraintType m_constraintType;
- PHY_IPhysicsEnvironment* m_physenv;
-};
-
-#endif /* __KX_CONSTRAINTWRAPPER_H__ */
diff --git a/source/gameengine/Ketsji/KX_Dome.cpp b/source/gameengine/Ketsji/KX_Dome.cpp
deleted file mode 100644
index d08372e47d4..00000000000
--- a/source/gameengine/Ketsji/KX_Dome.cpp
+++ /dev/null
@@ -1,2051 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Dalai Felinto
- *
- * This code is originally inspired on some of the ideas and codes from Paul Bourke.
- * Developed as part of a Research and Development project for
- * SAT - La Société des arts technologiques.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_Dome.cpp
- * \ingroup ketsji
- */
-
-#include "KX_Dome.h"
-
-#ifdef WITH_PYTHON
-#include <structmember.h>
-#endif
-
-#include <float.h>
-#include <math.h>
-
-#include "DNA_scene_types.h"
-#include "RAS_CameraData.h"
-#include "BLI_math.h"
-
-#include "glew-mx.h"
-
-// constructor
-KX_Dome::KX_Dome (
- RAS_ICanvas* canvas,
- /// rasterizer
- RAS_IRasterizer* rasterizer,
- /// engine
- KX_KetsjiEngine* engine,
-
- short res, //resolution of the mesh
- short mode, //mode - fisheye, truncated, warped, panoramic, ...
- short angle,
- float resbuf, //size adjustment of the buffer
- short tilt,
- struct Text* warptext
-
- ):
- dlistSupported(false),
- canvaswidth(-1), canvasheight(-1),
- m_drawingmode(rasterizer->GetDrawingMode()),
- m_resolution(res),
- m_mode(mode),
- m_angle(angle),
- m_resbuffer(resbuf),
- m_tilt(tilt),
- m_canvas(canvas),
- m_rasterizer(rasterizer),
- m_engine(engine)
-{
- warp.usemesh = false;
- fboSupported = false;
-
- if (mode >= DOME_NUM_MODES)
- m_mode = DOME_FISHEYE;
-
- if (warptext) // it there is a text data try to warp it
- {
- char *buf;
- buf = txt_to_buf(warptext);
- if (buf)
- {
- warp.usemesh = ParseWarpMesh(STR_String(buf));
- MEM_freeN(buf);
- }
- }
-
- //setting the viewport size
- const int *viewport = m_canvas->GetViewPort();
-
- SetViewPort(viewport);
-
- switch (m_mode) {
- case DOME_FISHEYE:
- if (m_angle <= 180) {
- cubetop.resize(1);
- cubebottom.resize(1);
- cubeleft.resize(2);
- cuberight.resize(2);
-
- CreateMeshDome180();
- m_numfaces = 4;
- }
- else if (m_angle > 180) {
- cubetop.resize(2);
- cubebottom.resize(2);
- cubeleft.resize(2);
- cubefront.resize(2);
- cuberight.resize(2);
-
- CreateMeshDome250();
- m_numfaces = 5;
- } break;
- case DOME_ENVMAP:
- m_angle = 360;
- m_numfaces = 6;
- break;
- case DOME_PANORAM_SPH:
- cubeleft.resize(2);
- cubeleftback.resize(2);
- cuberight.resize(2);
- cuberightback.resize(2);
- cubetop.resize(2);
- cubebottom.resize(2);
-
- m_angle = 360;
- CreateMeshPanorama();
- m_numfaces = 6;
- break;
- default: //DOME_TRUNCATED_FRONT and DOME_TRUNCATED_REAR
- if (m_angle <= 180) {
- cubetop.resize(1);
- cubebottom.resize(1);
- cubeleft.resize(2);
- cuberight.resize(2);
-
- CreateMeshDome180();
- m_numfaces = 4;
- }
- else if (m_angle > 180) {
- cubetop.resize(2);
- cubebottom.resize(2);
- cubeleft.resize(2);
- cubefront.resize(2);
- cuberight.resize(2);
-
- CreateMeshDome250();
- m_numfaces = 5;
- } break;
- }
-
- m_numimages =(warp.usemesh?m_numfaces+1:m_numfaces);
-
- CalculateCameraOrientation();
-
- CreateGLImages();
-
- if (warp.usemesh)
- fboSupported = CreateFBO();
-
- dlistSupported = CreateDL();
-}
-
-// destructor
-KX_Dome::~KX_Dome (void)
-{
- ClearGLImages();
-
- if (fboSupported)
- glDeleteFramebuffersEXT(1, &warp.fboId);
-
- if (dlistSupported)
- glDeleteLists(dlistId, (GLsizei) m_numimages);
-}
-
-void KX_Dome::SetViewPort(const int viewport[4])
-{
- if (canvaswidth != m_viewport.GetWidth() || canvasheight != m_viewport.GetHeight())
- {
- m_viewport.SetLeft(viewport[0]);
- m_viewport.SetBottom(viewport[1]);
- m_viewport.SetRight(viewport[2]);
- m_viewport.SetTop(viewport[3]);
-
- CalculateImageSize();
- }
-}
-
-void KX_Dome::CreateGLImages(void)
-{
- glGenTextures(m_numimages, (GLuint*)&domefacesId);
-
- for (int j=0;j<m_numfaces;j++) {
- glBindTexture(GL_TEXTURE_2D, domefacesId[j]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, m_imagesize, m_imagesize, 0, GL_RGB8,
- GL_UNSIGNED_BYTE, NULL);
- glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, m_imagesize, m_imagesize, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- }
- if (warp.usemesh) {
- glBindTexture(GL_TEXTURE_2D, domefacesId[m_numfaces]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, warp.imagesize, warp.imagesize, 0, GL_RGB8,
- GL_UNSIGNED_BYTE, NULL);
- glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 0, 0, warp.imagesize, warp.imagesize, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- }
-}
-
-void KX_Dome::ClearGLImages(void)
-{
- glDeleteTextures(m_numimages, (GLuint*)&domefacesId);
-#if 0
- for (int i=0;i<m_numimages;i++)
- if (glIsTexture(domefacesId[i]))
- glDeleteTextures(1, (GLuint*)&domefacesId[i]);
-#endif
-}
-
-void KX_Dome::CalculateImageSize(void)
-{
- /*
- * - determine the minimum buffer size
- * - reduce the buffer for better performance
- * - create a power of 2 texture bigger than the buffer
- */
- canvaswidth = m_canvas->GetWidth();
- canvasheight = m_canvas->GetHeight();
-
- m_buffersize = (canvaswidth > canvasheight?canvasheight:canvaswidth);
- m_buffersize = (int)(m_buffersize*m_resbuffer); //reduce buffer size for better performance
-
- int i = 0;
- while ((1 << i) <= m_buffersize)
- i++;
- m_imagesize = (1 << i);
-
- if (warp.usemesh) {
- // warp FBO needs to be up to twice as big as m_buffersize to get more resolution
- warp.imagesize = m_imagesize;
- if (m_buffersize == m_imagesize)
- warp.imagesize *= 2;
-
- //if FBO is not working/supported, we use the canvas dimension as buffer
- warp.bufferwidth = canvaswidth;
- warp.bufferheight = canvasheight;
- }
-}
-
-bool KX_Dome::CreateDL()
-{
- dlistId = glGenLists((GLsizei) m_numimages);
- if (dlistId != 0) {
- if (m_mode == DOME_FISHEYE || m_mode == DOME_TRUNCATED_FRONT || m_mode == DOME_TRUNCATED_REAR) {
- glNewList(dlistId, GL_COMPILE);
- GLDrawTriangles(cubetop, nfacestop);
- glEndList();
-
- glNewList(dlistId+1, GL_COMPILE);
- GLDrawTriangles(cubebottom, nfacesbottom);
- glEndList();
-
- glNewList(dlistId+2, GL_COMPILE);
- GLDrawTriangles(cubeleft, nfacesleft);
- glEndList();
-
- glNewList(dlistId+3, GL_COMPILE);
- GLDrawTriangles(cuberight, nfacesright);
- glEndList();
-
- if (m_angle > 180) {
- glNewList(dlistId+4, GL_COMPILE);
- GLDrawTriangles(cubefront, nfacesfront);
- glEndList();
- }
- }
- else if (m_mode == DOME_PANORAM_SPH)
- {
- glNewList(dlistId, GL_COMPILE);
- GLDrawTriangles(cubetop, nfacestop);
- glEndList();
-
- glNewList(dlistId+1, GL_COMPILE);
- GLDrawTriangles(cubebottom, nfacesbottom);
- glEndList();
-
- glNewList(dlistId+2, GL_COMPILE);
- GLDrawTriangles(cubeleft, nfacesleft);
- glEndList();
-
- glNewList(dlistId+3, GL_COMPILE);
- GLDrawTriangles(cuberight, nfacesright);
- glEndList();
-
- glNewList(dlistId+4, GL_COMPILE);
- GLDrawTriangles(cubeleftback, nfacesleftback);
- glEndList();
-
- glNewList(dlistId+5, GL_COMPILE);
- GLDrawTriangles(cuberightback, nfacesrightback);
- glEndList();
- }
-
- if (warp.usemesh) {
- glNewList((dlistId + m_numfaces), GL_COMPILE);
- GLDrawWarpQuads();
- glEndList();
- }
-
- //clearing the vectors
- cubetop.clear();
- cubebottom.clear();
- cuberight.clear();
- cubeleft.clear();
- cubefront.clear();
- cubeleftback.clear();
- cuberightback.clear();
- warp.nodes.clear();
-
- } else // genList failed
- return false;
-
- return true;
-}
-
-bool KX_Dome::CreateFBO(void)
-{
- if (!GLEW_EXT_framebuffer_object)
- {
- printf("Dome Error: FrameBuffer unsupported. Using low resolution warp image.");
- return false;
- }
-
- glGenFramebuffersEXT(1, &warp.fboId);
- if (warp.fboId==0)
- {
- printf("Dome Error: Invalid frame buffer object. Using low resolution warp image.");
- return false;
- }
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, warp.fboId);
-
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT,
- GL_TEXTURE_2D, domefacesId[m_numfaces], 0);
-
- GLenum status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
-
- if (status == GL_FRAMEBUFFER_UNSUPPORTED_EXT)
- {
- printf("Dome Error: FrameBuffer settings unsupported. Using low resolution warp image.");
- return false;
- }
- else if (status != GL_FRAMEBUFFER_COMPLETE_EXT)
- {
- glDeleteFramebuffersEXT(1, &warp.fboId);
- return false;
- }
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
- //nothing failed: we can use the whole FBO as buffersize
- warp.bufferwidth = warp.bufferheight = warp.imagesize;
- return true;
-}
-
-void KX_Dome::GLDrawTriangles(vector <DomeFace>& face, int nfaces)
-{
- int i,j;
- glBegin(GL_TRIANGLES);
- for (i=0;i<nfaces;i++) {
- for (j=0;j<3;j++) {
- glTexCoord2f(face[i].u[j],face[i].v[j]);
- glVertex3f((GLfloat)face[i].verts[j][0],(GLfloat)face[i].verts[j][1],(GLfloat)face[i].verts[j][2]);
- }
- }
- glEnd();
-}
-
-void KX_Dome::GLDrawWarpQuads(void)
-{
- int i, j, i2;
-
- float uv_width = (float)(warp.bufferwidth) / warp.imagesize;
- float uv_height = (float)(warp.bufferheight) / warp.imagesize;
-
- if (warp.mode ==2 ) {
- glBegin(GL_QUADS);
- for (i=0;i<warp.n_height-1;i++) {
- for (j=0;j<warp.n_width-1;j++) {
- if (warp.nodes[i][j].i < 0 || warp.nodes[i+1][j].i < 0 || warp.nodes[i+1][j+1].i < 0 || warp.nodes[i][j+1].i < 0)
- continue;
-
- glColor3f(warp.nodes[i][j+1].i, warp.nodes[i][j+1].i, warp.nodes[i][j+1].i);
- glTexCoord2f((warp.nodes[i][j+1].u * uv_width), (warp.nodes[i][j+1].v * uv_height));
- glVertex3f(warp.nodes[i][j+1].x, warp.nodes[i][j+1].y,0.0f);
-
- glColor3f(warp.nodes[i+1][j+1].i, warp.nodes[i+1][j+1].i, warp.nodes[i+1][j+1].i);
- glTexCoord2f((warp.nodes[i+1][j+1].u * uv_width), (warp.nodes[i+1][j+1].v * uv_height));
- glVertex3f(warp.nodes[i+1][j+1].x, warp.nodes[i+1][j+1].y,0.0f);
-
- glColor3f(warp.nodes[i+1][j].i, warp.nodes[i+1][j].i, warp.nodes[i+1][j].i);
- glTexCoord2f((warp.nodes[i+1][j].u * uv_width), (warp.nodes[i+1][j].v * uv_height));
- glVertex3f(warp.nodes[i+1][j].x, warp.nodes[i+1][j].y,0.0f);
-
- glColor3f(warp.nodes[i][j].i, warp.nodes[i][j].i, warp.nodes[i][j].i);
- glTexCoord2f((warp.nodes[i][j].u * uv_width), (warp.nodes[i][j].v * uv_height));
- glVertex3f(warp.nodes[i][j].x, warp.nodes[i][j].y,0.0f);
- }
- }
- glEnd();
- }
- else if (warp.mode == 1) {
- glBegin(GL_QUADS);
- for (i=0;i<warp.n_height-1;i++) {
- for (j=0;j<warp.n_width-1;j++) {
- i2 = (i+1) % warp.n_width; // Wrap around, i = warp.n_width = 0
-
- if (warp.nodes[i][j].i < 0 || warp.nodes[i2][j].i < 0 || warp.nodes[i2][j+1].i < 0 || warp.nodes[i][j+1].i < 0)
- continue;
-
- glColor3f(warp.nodes[i][j].i,warp.nodes[i][j].i,warp.nodes[i][j].i);
- glTexCoord2f((warp.nodes[i][j].u * uv_width), (warp.nodes[i][j].v * uv_height));
- glVertex3f(warp.nodes[i][j].x,warp.nodes[i][j].y,0.0f);
-
- glColor3f(warp.nodes[i2][j].i,warp.nodes[i2][j].i,warp.nodes[i2][j].i);
- glTexCoord2f((warp.nodes[i2][j].u * uv_width), (warp.nodes[i2][j].v * uv_height));
- glVertex3f(warp.nodes[i2][j].x,warp.nodes[i2][j].y,0.0f);
-
- glColor3f(warp.nodes[i2][j+1].i,warp.nodes[i2][j+1].i,warp.nodes[i2][j+1].i);
- glTexCoord2f((warp.nodes[i2][j+1].u * uv_width), (warp.nodes[i2][j+1].v * uv_height));
- glVertex3f(warp.nodes[i2][j+1].x,warp.nodes[i2][j+1].y,0.0f);
-
- glColor3f(warp.nodes[i2][j+1].i,warp.nodes[i2][j+1].i,warp.nodes[i2][j+1].i);
- glTexCoord2f((warp.nodes[i2][j+1].u * uv_width), (warp.nodes[i2][j+1].v * uv_height));
- glVertex3f(warp.nodes[i2][j+1].x,warp.nodes[i2][j+1].y,0.0f);
-
- }
- }
- glEnd();
- }
- else {
- printf("Dome Error: Warp Mode %d unsupported. Try 1 for Polar Mesh or 2 for Fisheye.\n", warp.mode);
- }
-}
-
-
-bool KX_Dome::ParseWarpMesh(STR_String text)
-{
- /*
- * //Notes about the supported data format:
- * File example::
- * mode
- * width height
- * n0_x n0_y n0_u n0_v n0_i
- * n1_x n1_y n1_u n1_v n1_i
- * n2_x n1_y n2_u n2_v n2_i
- * n3_x n3_y n3_u n3_v n3_i
- * (...)
- * First line is the image type the mesh is support to be applied to: 2 = fisheye, 1=radial
- * The next line has the mesh dimensions
- * Rest of the lines are the nodes of the mesh. Each line has x y u v i
- * (x,y) are the normalized screen coordinates
- * (u,v) texture coordinates
- * i a multiplicative intensity factor
- *
- * x varies from -screen aspect to screen aspect
- * y varies from -1 to 1
- * u and v vary from 0 to 1
- * i ranges from 0 to 1, if negative don't draw that mesh node
- */
- int i;
- int nodeX=0, nodeY=0;
-
- vector<STR_String> columns, lines;
-
- lines = text.Explode('\n');
- if (lines.size() < 6) {
- printf("Dome Error: Warp Mesh File with insufficient data!\n");
- return false;
- }
- columns = lines[1].Explode(' ');
- if (columns.size() == 1)
- columns = lines[1].Explode('\t');
-
- if (columns.size() !=2) {
- printf("Dome Error: Warp Mesh File incorrect. The second line should contain: width height.\n");
- return false;
- }
-
- warp.mode = atoi(lines[0]);// 1 = radial, 2 = fisheye
-
- warp.n_width = atoi(columns[0]);
- warp.n_height = atoi(columns[1]);
-
- if ((int)lines.size() < 2 + (warp.n_width * warp.n_height)) {
- printf("Dome Error: Warp Mesh File with insufficient data!\n");
- return false;
- }
- else {
- warp.nodes = vector<vector<WarpMeshNode> > (warp.n_height, vector<WarpMeshNode>(warp.n_width));
-
- for (i=2; i-2 < (warp.n_width*warp.n_height); i++) {
- columns = lines[i].Explode(' ');
- if (columns.size() == 1)
- columns = lines[i].Explode('\t');
-
- if (columns.size() == 5) {
- nodeX = (i-2)%warp.n_width;
- nodeY = ((i-2) - nodeX) / warp.n_width;
-
- warp.nodes[nodeY][nodeX].x = atof(columns[0]);
- warp.nodes[nodeY][nodeX].y = atof(columns[1]);
- warp.nodes[nodeY][nodeX].u = atof(columns[2]);
- warp.nodes[nodeY][nodeX].v = atof(columns[3]);
- warp.nodes[nodeY][nodeX].i = atof(columns[4]);
- }
- else {
- warp.nodes.clear();
- printf("Dome Error: Warp Mesh File with wrong number of fields. You should use 5: x y u v i.\n");
- return false;
- }
- }
- }
- return true;
-}
-
-void KX_Dome::CreateMeshDome180(void)
-{
- /*
- * 1)- Define the faces of half of a cube
- * - each face is made out of 2 triangles
- * 2) Subdivide the faces
- * - more resolution == more curved lines
- * 3) Spherize the cube
- * - normalize the verts
- * 4) Flatten onto xz plane
- * - transform it onto an equidistant spherical projection techniques to transform the sphere onto a dome image
- */
- int i,j;
- float uv_ratio = (float)(m_buffersize-1) / m_imagesize;
-
- m_radangle = DEG2RADF(m_angle); //calculates the radians angle, used for flattening
-
- //creating faces for the env mapcube 180deg Dome
- // Top Face - just a triangle
- cubetop[0].verts[0][0] = (float)(-M_SQRT2) / 2.0f;
- cubetop[0].verts[0][1] = 0.0f;
- cubetop[0].verts[0][2] = 0.5f;
- cubetop[0].u[0] = 0.0;
- cubetop[0].v[0] = uv_ratio;
-
- cubetop[0].verts[1][0] = 0.0f;
- cubetop[0].verts[1][1] = (float)M_SQRT2 / 2.0f;
- cubetop[0].verts[1][2] = 0.5f;
- cubetop[0].u[1] = 0.0;
- cubetop[0].v[1] = 0.0;
-
- cubetop[0].verts[2][0] = (float)M_SQRT2 / 2.0f;
- cubetop[0].verts[2][1] = 0.0f;
- cubetop[0].verts[2][2] = 0.5f;
- cubetop[0].u[2] = uv_ratio;
- cubetop[0].v[2] = 0.0;
-
- nfacestop = 1;
-
- /* Bottom face - just a triangle */
- cubebottom[0].verts[0][0] = (float)(-M_SQRT2) / 2.0f;
- cubebottom[0].verts[0][1] = 0.0f;
- cubebottom[0].verts[0][2] = -0.5f;
- cubebottom[0].u[0] = uv_ratio;
- cubebottom[0].v[0] = 0.0;
-
- cubebottom[0].verts[1][0] = (float)M_SQRT2 / 2.0f;
- cubebottom[0].verts[1][1] = 0;
- cubebottom[0].verts[1][2] = -0.5f;
- cubebottom[0].u[1] = 0.0;
- cubebottom[0].v[1] = uv_ratio;
-
- cubebottom[0].verts[2][0] = 0.0f;
- cubebottom[0].verts[2][1] = (float)M_SQRT2 / 2.0f;
- cubebottom[0].verts[2][2] = -0.5f;
- cubebottom[0].u[2] = 0.0;
- cubebottom[0].v[2] = 0.0;
-
- nfacesbottom = 1;
-
- /* Left face - two triangles */
-
- cubeleft[0].verts[0][0] = (float)(-M_SQRT2) / 2.0f;
- cubeleft[0].verts[0][1] = 0.0f;
- cubeleft[0].verts[0][2] = -0.5f;
- cubeleft[0].u[0] = 0.0;
- cubeleft[0].v[0] = 0.0;
-
- cubeleft[0].verts[1][0] = 0.0f;
- cubeleft[0].verts[1][1] = (float)M_SQRT2 / 2.0f;
- cubeleft[0].verts[1][2] = -0.5f;
- cubeleft[0].u[1] = uv_ratio;
- cubeleft[0].v[1] = 0.0;
-
- cubeleft[0].verts[2][0] = (float)(-M_SQRT2) / 2.0f;
- cubeleft[0].verts[2][1] = 0.0f;
- cubeleft[0].verts[2][2] = 0.5f;
- cubeleft[0].u[2] = 0.0;
- cubeleft[0].v[2] = uv_ratio;
-
- //second triangle
- cubeleft[1].verts[0][0] = (float)(-M_SQRT2) / 2.0f;
- cubeleft[1].verts[0][1] = 0.0f;
- cubeleft[1].verts[0][2] = 0.5f;
- cubeleft[1].u[0] = 0.0;
- cubeleft[1].v[0] = uv_ratio;
-
- cubeleft[1].verts[1][0] = 0.0f;
- cubeleft[1].verts[1][1] = (float)M_SQRT2 / 2.0f;
- cubeleft[1].verts[1][2] = -0.5f;
- cubeleft[1].u[1] = uv_ratio;
- cubeleft[1].v[1] = 0.0;
-
- cubeleft[1].verts[2][0] = 0.0f;
- cubeleft[1].verts[2][1] = (float)M_SQRT2 / 2.0f;
- cubeleft[1].verts[2][2] = 0.5f;
- cubeleft[1].u[2] = uv_ratio;
- cubeleft[1].v[2] = uv_ratio;
-
- nfacesleft = 2;
-
- /* Right face - two triangles */
- cuberight[0].verts[0][0] = 0.0f;
- cuberight[0].verts[0][1] = (float)M_SQRT2 / 2.0f;
- cuberight[0].verts[0][2] = -0.5f;
- cuberight[0].u[0] = 0.0;
- cuberight[0].v[0] = 0.0;
-
- cuberight[0].verts[1][0] = (float)M_SQRT2 / 2.0f;
- cuberight[0].verts[1][1] = 0.0f;
- cuberight[0].verts[1][2] = -0.5f;
- cuberight[0].u[1] = uv_ratio;
- cuberight[0].v[1] = 0.0;
-
- cuberight[0].verts[2][0] = (float)M_SQRT2 / 2.0f;
- cuberight[0].verts[2][1] = 0.0f;
- cuberight[0].verts[2][2] = 0.5f;
- cuberight[0].u[2] = uv_ratio;
- cuberight[0].v[2] = uv_ratio;
-
- //second triangle
- cuberight[1].verts[0][0] = 0.0f;
- cuberight[1].verts[0][1] = (float)M_SQRT2 / 2.0f;
- cuberight[1].verts[0][2] = -0.5f;
- cuberight[1].u[0] = 0.0;
- cuberight[1].v[0] = 0.0;
-
- cuberight[1].verts[1][0] = (float)M_SQRT2 / 2.0f;
- cuberight[1].verts[1][1] = 0.0f;
- cuberight[1].verts[1][2] = 0.5f;
- cuberight[1].u[1] = uv_ratio;
- cuberight[1].v[1] = uv_ratio;
-
- cuberight[1].verts[2][0] = 0.0f;
- cuberight[1].verts[2][1] = (float)M_SQRT2 / 2.0f;
- cuberight[1].verts[2][2] = 0.5f;
- cuberight[1].u[2] = 0.0;
- cuberight[1].v[2] = uv_ratio;
-
- nfacesright = 2;
-
- //Refine a triangular mesh by bisecting each edge forms 3 new triangles for each existing triangle on each iteration
- //Could be made more efficient for drawing if the triangles were ordered in a fan. Not that important since we are using DisplayLists
-
- for (i=0;i<m_resolution;i++) {
- cubetop.resize(4*nfacestop);
- SplitFace(cubetop,&nfacestop);
- cubebottom.resize(4*nfacesbottom);
- SplitFace(cubebottom,&nfacesbottom);
- cubeleft.resize(4*nfacesleft);
- SplitFace(cubeleft,&nfacesleft);
- cuberight.resize(4*nfacesright);
- SplitFace(cuberight,&nfacesright);
- }
-
- // Turn into a hemisphere
- for (j=0;j<3;j++) {
- for (i=0;i<nfacestop;i++)
- cubetop[i].verts[j].normalize();
- for (i=0;i<nfacesbottom;i++)
- cubebottom[i].verts[j].normalize();
- for (i=0;i<nfacesleft;i++)
- cubeleft[i].verts[j].normalize();
- for (i=0;i<nfacesright;i++)
- cuberight[i].verts[j].normalize();
- }
-
- //flatten onto xz plane
- for (i=0;i<nfacestop;i++)
- FlattenDome(cubetop[i].verts);
- for (i=0;i<nfacesbottom;i++)
- FlattenDome(cubebottom[i].verts);
- for (i=0;i<nfacesleft;i++)
- FlattenDome(cubeleft[i].verts);
- for (i=0;i<nfacesright;i++)
- FlattenDome(cuberight[i].verts);
-
-}
-
-void KX_Dome::CreateMeshDome250(void)
-{
- /*
- * 1)- Define the faces of a cube without the back face
- * - each face is made out of 2 triangles
- * 2) Subdivide the faces
- * - more resolution == more curved lines
- * 3) Spherize the cube
- * - normalize the verts
- * 4) Flatten onto xz plane
- * - transform it onto an equidistant spherical projection techniques to transform the sphere onto a dome image
- */
-
- int i,j;
- float uv_height, uv_base;
- float verts_height;
-
- float rad_ang = m_angle * MT_PI / 180.0f;
- float uv_ratio = (float)(m_buffersize-1) / m_imagesize;
-
- m_radangle = m_angle * (float)M_PI/180.0f;//calculates the radians angle, used for flattening
- /*
- * verts_height is the exactly needed height of the cube faces (not always 1.0).
- * When we want some horizontal information (e.g. for horizontal 220deg domes) we don't need to create and tessellate the whole cube.
- * Therefore the lateral cube faces could be small, and the tessellate mesh would be completely used.
- * (if we always worked with verts_height = 1.0, we would be discarding a lot of the calculated and tessellated geometry).
- *
- * So I came out with this formula:
- * verts_height = tan((rad_ang/2) - (MT_PI/2))*sqrt(2.0);
- *
- * Here we take half the sphere(rad_ang/2) and subtract a quarter of it (MT_PI/2)
- * Therefore we have the length in radians of the dome/sphere over the horizon.
- * Once we take the tangent of that angle, you have the verts coordinate corresponding to the verts on the side faces.
- * Then we need to multiply it by sqrt(2.0) to get the coordinate of the verts on the diagonal of the original cube.
- */
- verts_height = tanf((rad_ang / 2.0f) - (MT_PI / 2.0f)) * (float)M_SQRT2;
-
- uv_height = uv_ratio * ( (verts_height / 2.0f) + 0.5f);
- uv_base = uv_ratio * (1.0f - ((verts_height / 2.0f) + 0.5f));
-
- //creating faces for the env mapcube 180deg Dome
- // Front Face - 2 triangles
- cubefront[0].verts[0][0] =-1.0f;
- cubefront[0].verts[0][1] = 1.0f;
- cubefront[0].verts[0][2] =-1.0f;
- cubefront[0].u[0] = 0.0;
- cubefront[0].v[0] = 0.0;
-
- cubefront[0].verts[1][0] = 1.0f;
- cubefront[0].verts[1][1] = 1.0f;
- cubefront[0].verts[1][2] = 1.0f;
- cubefront[0].u[1] = uv_ratio;
- cubefront[0].v[1] = uv_ratio;
-
- cubefront[0].verts[2][0] =-1.0f;
- cubefront[0].verts[2][1] = 1.0f;
- cubefront[0].verts[2][2] = 1.0f;
- cubefront[0].u[2] = 0.0;
- cubefront[0].v[2] = uv_ratio;
-
- //second triangle
- cubefront[1].verts[0][0] = 1.0f;
- cubefront[1].verts[0][1] = 1.0f;
- cubefront[1].verts[0][2] = 1.0f;
- cubefront[1].u[0] = uv_ratio;
- cubefront[1].v[0] = uv_ratio;
-
- cubefront[1].verts[1][0] =-1.0f;
- cubefront[1].verts[1][1] = 1.0f;
- cubefront[1].verts[1][2] =-1.0f;
- cubefront[1].u[1] = 0.0;
- cubefront[1].v[1] = 0.0;
-
- cubefront[1].verts[2][0] = 1.0f;
- cubefront[1].verts[2][1] = 1.0f;
- cubefront[1].verts[2][2] =-1.0f;
- cubefront[1].u[2] = uv_ratio;
- cubefront[1].v[2] = 0.0;
-
- nfacesfront = 2;
-
- // Left Face - 2 triangles
- cubeleft[0].verts[0][0] =-1.0f;
- cubeleft[0].verts[0][1] = 1.0f;
- cubeleft[0].verts[0][2] =-1.0f;
- cubeleft[0].u[0] = uv_ratio;
- cubeleft[0].v[0] = 0.0;
-
- cubeleft[0].verts[1][0] =-1.0f;
- cubeleft[0].verts[1][1] =-verts_height;
- cubeleft[0].verts[1][2] = 1.0f;
- cubeleft[0].u[1] = uv_base;
- cubeleft[0].v[1] = uv_ratio;
-
- cubeleft[0].verts[2][0] =-1.0f;
- cubeleft[0].verts[2][1] =-verts_height;
- cubeleft[0].verts[2][2] =-1.0f;
- cubeleft[0].u[2] = uv_base;
- cubeleft[0].v[2] = 0.0;
-
- //second triangle
- cubeleft[1].verts[0][0] =-1.0f;
- cubeleft[1].verts[0][1] =-verts_height;
- cubeleft[1].verts[0][2] = 1.0f;
- cubeleft[1].u[0] = uv_base;
- cubeleft[1].v[0] = uv_ratio;
-
- cubeleft[1].verts[1][0] =-1.0f;
- cubeleft[1].verts[1][1] = 1.0f;
- cubeleft[1].verts[1][2] =-1.0f;
- cubeleft[1].u[1] = uv_ratio;
- cubeleft[1].v[1] = 0.0;
-
- cubeleft[1].verts[2][0] =-1.0f;
- cubeleft[1].verts[2][1] = 1.0f;
- cubeleft[1].verts[2][2] = 1.0f;
- cubeleft[1].u[2] = uv_ratio;
- cubeleft[1].v[2] = uv_ratio;
-
- nfacesleft = 2;
-
- // right Face - 2 triangles
- cuberight[0].verts[0][0] = 1.0f;
- cuberight[0].verts[0][1] = 1.0f;
- cuberight[0].verts[0][2] = 1.0f;
- cuberight[0].u[0] = 0.0;
- cuberight[0].v[0] = uv_ratio;
-
- cuberight[0].verts[1][0] = 1.0f;
- cuberight[0].verts[1][1] =-verts_height;
- cuberight[0].verts[1][2] =-1.0f;
- cuberight[0].u[1] = uv_height;
- cuberight[0].v[1] = 0.0;
-
- cuberight[0].verts[2][0] = 1.0f;
- cuberight[0].verts[2][1] =-verts_height;
- cuberight[0].verts[2][2] = 1.0f;
- cuberight[0].u[2] = uv_height;
- cuberight[0].v[2] = uv_ratio;
-
- //second triangle
- cuberight[1].verts[0][0] = 1.0f;
- cuberight[1].verts[0][1] =-verts_height;
- cuberight[1].verts[0][2] =-1.0f;
- cuberight[1].u[0] = uv_height;
- cuberight[1].v[0] = 0.0;
-
- cuberight[1].verts[1][0] = 1.0f;
- cuberight[1].verts[1][1] = 1.0f;
- cuberight[1].verts[1][2] = 1.0f;
- cuberight[1].u[1] = 0.0;
- cuberight[1].v[1] = uv_ratio;
-
- cuberight[1].verts[2][0] = 1.0f;
- cuberight[1].verts[2][1] = 1.0f;
- cuberight[1].verts[2][2] =-1.0f;
- cuberight[1].u[2] = 0.0;
- cuberight[1].v[2] = 0.0;
-
- nfacesright = 2;
-
- // top Face - 2 triangles
- cubetop[0].verts[0][0] =-1.0f;
- cubetop[0].verts[0][1] = 1.0f;
- cubetop[0].verts[0][2] = 1.0f;
- cubetop[0].u[0] = 0.0;
- cubetop[0].v[0] = 0.0;
-
- cubetop[0].verts[1][0] = 1.0f;
- cubetop[0].verts[1][1] =-verts_height;
- cubetop[0].verts[1][2] = 1.0f;
- cubetop[0].u[1] = uv_ratio;
- cubetop[0].v[1] = uv_height;
-
- cubetop[0].verts[2][0] =-1.0f;
- cubetop[0].verts[2][1] =-verts_height;
- cubetop[0].verts[2][2] = 1.0f;
- cubetop[0].u[2] = 0.0;
- cubetop[0].v[2] = uv_height;
-
- //second triangle
- cubetop[1].verts[0][0] = 1.0f;
- cubetop[1].verts[0][1] =-verts_height;
- cubetop[1].verts[0][2] = 1.0f;
- cubetop[1].u[0] = uv_ratio;
- cubetop[1].v[0] = uv_height;
-
- cubetop[1].verts[1][0] =-1.0f;
- cubetop[1].verts[1][1] = 1.0f;
- cubetop[1].verts[1][2] = 1.0f;
- cubetop[1].u[1] = 0.0;
- cubetop[1].v[1] = 0.0;
-
- cubetop[1].verts[2][0] = 1.0f;
- cubetop[1].verts[2][1] = 1.0f;
- cubetop[1].verts[2][2] = 1.0f;
- cubetop[1].u[2] = uv_ratio;
- cubetop[1].v[2] = 0.0;
-
- nfacestop = 2;
-
- // bottom Face - 2 triangles
- cubebottom[0].verts[0][0] =-1.0f;
- cubebottom[0].verts[0][1] =-verts_height;
- cubebottom[0].verts[0][2] =-1.0f;
- cubebottom[0].u[0] = 0.0;
- cubebottom[0].v[0] = uv_base;
-
- cubebottom[0].verts[1][0] = 1.0f;
- cubebottom[0].verts[1][1] = 1.0f;
- cubebottom[0].verts[1][2] =-1.0f;
- cubebottom[0].u[1] = uv_ratio;
- cubebottom[0].v[1] = uv_ratio;
-
- cubebottom[0].verts[2][0] =-1.0f;
- cubebottom[0].verts[2][1] = 1.0f;
- cubebottom[0].verts[2][2] =-1.0f;
- cubebottom[0].u[2] = 0.0;
- cubebottom[0].v[2] = uv_ratio;
-
- //second triangle
- cubebottom[1].verts[0][0] = 1.0f;
- cubebottom[1].verts[0][1] = 1.0f;
- cubebottom[1].verts[0][2] =-1.0f;
- cubebottom[1].u[0] = uv_ratio;
- cubebottom[1].v[0] = uv_ratio;
-
- cubebottom[1].verts[1][0] =-1.0f;
- cubebottom[1].verts[1][1] =-verts_height;
- cubebottom[1].verts[1][2] =-1.0f;
- cubebottom[1].u[1] = 0.0;
- cubebottom[1].v[1] = uv_base;
-
- cubebottom[1].verts[2][0] = 1.0f;
- cubebottom[1].verts[2][1] =-verts_height;
- cubebottom[1].verts[2][2] =-1.0f;
- cubebottom[1].u[2] = uv_ratio;
- cubebottom[1].v[2] = uv_base;
-
- nfacesbottom = 2;
-
- //Refine a triangular mesh by bisecting each edge forms 3 new triangles for each existing triangle on each iteration
- //It could be made more efficient for drawing if the triangles were ordered in a strip!
-
- for (i=0;i<m_resolution;i++) {
- cubefront.resize(4*nfacesfront);
- SplitFace(cubefront,&nfacesfront);
- cubetop.resize(4*nfacestop);
- SplitFace(cubetop,&nfacestop);
- cubebottom.resize(4*nfacesbottom);
- SplitFace(cubebottom,&nfacesbottom);
- cubeleft.resize(4*nfacesleft);
- SplitFace(cubeleft,&nfacesleft);
- cuberight.resize(4*nfacesright);
- SplitFace(cuberight,&nfacesright);
- }
-
- // Turn into a hemisphere/sphere
- for (j=0;j<3;j++) {
- for (i=0;i<nfacesfront;i++)
- cubefront[i].verts[j].normalize();
- for (i=0;i<nfacestop;i++)
- cubetop[i].verts[j].normalize();
- for (i=0;i<nfacesbottom;i++)
- cubebottom[i].verts[j].normalize();
- for (i=0;i<nfacesleft;i++)
- cubeleft[i].verts[j].normalize();
- for (i=0;i<nfacesright;i++)
- cuberight[i].verts[j].normalize();
- }
-
- //flatten onto xz plane
- for (i=0;i<nfacesfront;i++)
- FlattenDome(cubefront[i].verts);
- for (i=0;i<nfacestop;i++)
- FlattenDome(cubetop[i].verts);
- for (i=0;i<nfacesbottom;i++)
- FlattenDome(cubebottom[i].verts);
- for (i=0;i<nfacesleft;i++)
- FlattenDome(cubeleft[i].verts);
- for (i=0;i<nfacesright;i++)
- FlattenDome(cuberight[i].verts);
-}
-
-void KX_Dome::CreateMeshPanorama(void)
-{
- /*
- * 1)- Define the faces of a cube without the top and bottom faces
- * - each face is made out of 2 triangles
- * 2) Subdivide the faces
- * - more resolution == more curved lines
- * 3) Spherize the cube
- * - normalize the verts t
- * 4) Flatten onto xz plane
- * - use spherical projection techniques to transform the sphere onto a flat panorama
- */
- int i,j;
-
- float uv_ratio = (float)(m_buffersize-1) / m_imagesize;
-
- /* Top face - two triangles */
- cubetop[0].verts[0][0] = (float)(-M_SQRT2);
- cubetop[0].verts[0][1] = 0.0f;
- cubetop[0].verts[0][2] = 1.0f;
- cubetop[0].u[0] = 0.0;
- cubetop[0].v[0] = uv_ratio;
-
- cubetop[0].verts[1][0] = 0.0f;
- cubetop[0].verts[1][1] = (float)M_SQRT2;
- cubetop[0].verts[1][2] = 1.0f;
- cubetop[0].u[1] = 0.0;
- cubetop[0].v[1] = 0.0;
-
- //second triangle
- cubetop[0].verts[2][0] = (float)M_SQRT2;
- cubetop[0].verts[2][1] = 0.0f;
- cubetop[0].verts[2][2] = 1.0f;
- cubetop[0].u[2] = uv_ratio;
- cubetop[0].v[2] = 0.0;
-
- cubetop[1].verts[0][0] = (float)M_SQRT2;
- cubetop[1].verts[0][1] = 0.0f;
- cubetop[1].verts[0][2] = 1.0f;
- cubetop[1].u[0] = uv_ratio;
- cubetop[1].v[0] = 0.0;
-
- cubetop[1].verts[1][0] = 0.0f;
- cubetop[1].verts[1][1] = (float)(-M_SQRT2);
- cubetop[1].verts[1][2] = 1.0f;
- cubetop[1].u[1] = uv_ratio;
- cubetop[1].v[1] = uv_ratio;
-
- cubetop[1].verts[2][0] = (float)(-M_SQRT2);
- cubetop[1].verts[2][1] = 0.0f;
- cubetop[1].verts[2][2] = 1.0f;
- cubetop[1].u[2] = 0.0;
- cubetop[1].v[2] = uv_ratio;
-
- nfacestop = 2;
-
- /* Bottom face - two triangles */
- cubebottom[0].verts[0][0] = (float)(-M_SQRT2);
- cubebottom[0].verts[0][1] = 0.0f;
- cubebottom[0].verts[0][2] = -1.0f;
- cubebottom[0].u[0] = uv_ratio;
- cubebottom[0].v[0] = 0.0;
-
- cubebottom[0].verts[1][0] = (float)M_SQRT2;
- cubebottom[0].verts[1][1] = 0.0f;
- cubebottom[0].verts[1][2] = -1.0f;
- cubebottom[0].u[1] = 0.0;
- cubebottom[0].v[1] = uv_ratio;
-
- cubebottom[0].verts[2][0] = 0.0f;
- cubebottom[0].verts[2][1] = (float)M_SQRT2;
- cubebottom[0].verts[2][2] = -1.0f;
- cubebottom[0].u[2] = 0.0;
- cubebottom[0].v[2] = 0.0;
-
- //second triangle
- cubebottom[1].verts[0][0] = (float)M_SQRT2;
- cubebottom[1].verts[0][1] = 0.0f;
- cubebottom[1].verts[0][2] = -1.0f;
- cubebottom[1].u[0] = 0.0;
- cubebottom[1].v[0] = uv_ratio;
-
- cubebottom[1].verts[1][0] = (float)(-M_SQRT2);
- cubebottom[1].verts[1][1] = 0.0f;
- cubebottom[1].verts[1][2] = -1.0f;
- cubebottom[1].u[1] = uv_ratio;
- cubebottom[1].v[1] = 0.0;
-
- cubebottom[1].verts[2][0] = 0.0f;
- cubebottom[1].verts[2][1] = (float)(-M_SQRT2);
- cubebottom[1].verts[2][2] = -1.0f;
- cubebottom[1].u[2] = uv_ratio;
- cubebottom[1].v[2] = uv_ratio;
-
- nfacesbottom = 2;
-
- /* Left Back (135deg) face - two triangles */
-
- cubeleftback[0].verts[0][0] = 0.0f;
- cubeleftback[0].verts[0][1] = (float)(-M_SQRT2);
- cubeleftback[0].verts[0][2] = -1.0f;
- cubeleftback[0].u[0] = 0.0;
- cubeleftback[0].v[0] = 0.0;
-
- cubeleftback[0].verts[1][0] = (float)(-M_SQRT2);
- cubeleftback[0].verts[1][1] = 0.0f;
- cubeleftback[0].verts[1][2] = -1.0f;
- cubeleftback[0].u[1] = uv_ratio;
- cubeleftback[0].v[1] = 0.0;
-
- cubeleftback[0].verts[2][0] = 0.0f;
- cubeleftback[0].verts[2][1] = (float)(-M_SQRT2);
- cubeleftback[0].verts[2][2] = 1.0f;
- cubeleftback[0].u[2] = 0.0;
- cubeleftback[0].v[2] = uv_ratio;
-
- //second triangle
- cubeleftback[1].verts[0][0] = 0.0f;
- cubeleftback[1].verts[0][1] = (float)(-M_SQRT2);
- cubeleftback[1].verts[0][2] = 1.0f;
- cubeleftback[1].u[0] = 0.0;
- cubeleftback[1].v[0] = uv_ratio;
-
- cubeleftback[1].verts[1][0] = (float)(-M_SQRT2);
- cubeleftback[1].verts[1][1] = 0.0f;
- cubeleftback[1].verts[1][2] = -1.0f;
- cubeleftback[1].u[1] = uv_ratio;
- cubeleftback[1].v[1] = 0.0;
-
- cubeleftback[1].verts[2][0] = (float)(-M_SQRT2);
- cubeleftback[1].verts[2][1] = 0.0f;
- cubeleftback[1].verts[2][2] = 1.0f;
- cubeleftback[1].u[2] = uv_ratio;
- cubeleftback[1].v[2] = uv_ratio;
-
- nfacesleftback = 2;
-
- /* Left face - two triangles */
-
- cubeleft[0].verts[0][0] = (float)(-M_SQRT2);
- cubeleft[0].verts[0][1] = 0.0f;
- cubeleft[0].verts[0][2] = -1.0f;
- cubeleft[0].u[0] = 0.0;
- cubeleft[0].v[0] = 0.0;
-
- cubeleft[0].verts[1][0] = 0.0f;
- cubeleft[0].verts[1][1] = (float)M_SQRT2;
- cubeleft[0].verts[1][2] = -1.0f;
- cubeleft[0].u[1] = uv_ratio;
- cubeleft[0].v[1] = 0.0;
-
- cubeleft[0].verts[2][0] = (float)(-M_SQRT2);
- cubeleft[0].verts[2][1] = 0.0f;
- cubeleft[0].verts[2][2] = 1.0f;
- cubeleft[0].u[2] = 0.0;
- cubeleft[0].v[2] = uv_ratio;
-
- //second triangle
- cubeleft[1].verts[0][0] = (float)(-M_SQRT2);
- cubeleft[1].verts[0][1] = 0.0f;
- cubeleft[1].verts[0][2] = 1.0f;
- cubeleft[1].u[0] = 0.0;
- cubeleft[1].v[0] = uv_ratio;
-
- cubeleft[1].verts[1][0] = 0.0f;
- cubeleft[1].verts[1][1] = (float)M_SQRT2;
- cubeleft[1].verts[1][2] = -1.0f;
- cubeleft[1].u[1] = uv_ratio;
- cubeleft[1].v[1] = 0.0;
-
- cubeleft[1].verts[2][0] = 0.0f;
- cubeleft[1].verts[2][1] = (float)M_SQRT2;
- cubeleft[1].verts[2][2] = 1.0f;
- cubeleft[1].u[2] = uv_ratio;
- cubeleft[1].v[2] = uv_ratio;
-
- nfacesleft = 2;
-
- /* Right face - two triangles */
- cuberight[0].verts[0][0] = 0.0f;
- cuberight[0].verts[0][1] = (float)M_SQRT2;
- cuberight[0].verts[0][2] = -1.0f;
- cuberight[0].u[0] = 0.0;
- cuberight[0].v[0] = 0.0;
-
- cuberight[0].verts[1][0] = (float)M_SQRT2;
- cuberight[0].verts[1][1] = 0.0f;
- cuberight[0].verts[1][2] = -1.0f;
- cuberight[0].u[1] = uv_ratio;
- cuberight[0].v[1] = 0.0;
-
- cuberight[0].verts[2][0] = (float)M_SQRT2;
- cuberight[0].verts[2][1] = 0.0f;
- cuberight[0].verts[2][2] = 1.0f;
- cuberight[0].u[2] = uv_ratio;
- cuberight[0].v[2] = uv_ratio;
-
- //second triangle
- cuberight[1].verts[0][0] = 0.0f;
- cuberight[1].verts[0][1] = (float)M_SQRT2;
- cuberight[1].verts[0][2] = -1.0f;
- cuberight[1].u[0] = 0.0;
- cuberight[1].v[0] = 0.0;
-
- cuberight[1].verts[1][0] = (float)M_SQRT2;
- cuberight[1].verts[1][1] = 0.0f;
- cuberight[1].verts[1][2] = 1.0f;
- cuberight[1].u[1] = uv_ratio;
- cuberight[1].v[1] = uv_ratio;
-
- cuberight[1].verts[2][0] = 0.0f;
- cuberight[1].verts[2][1] = (float)M_SQRT2;
- cuberight[1].verts[2][2] = 1.0f;
- cuberight[1].u[2] = 0.0f;
- cuberight[1].v[2] = uv_ratio;
-
- nfacesright = 2;
-
- /* Right Back (-135deg) face - two triangles */
- cuberightback[0].verts[0][0] = (float)M_SQRT2;
- cuberightback[0].verts[0][1] = 0.0f;
- cuberightback[0].verts[0][2] = -1.0f;
- cuberightback[0].u[0] = 0.0;
- cuberightback[0].v[0] = 0.0;
-
- cuberightback[0].verts[1][0] = 0.0f;
- cuberightback[0].verts[1][1] = (float)(-M_SQRT2);
- cuberightback[0].verts[1][2] = -1.0f;
- cuberightback[0].u[1] = uv_ratio;
- cuberightback[0].v[1] = 0.0;
-
- cuberightback[0].verts[2][0] = 0.0f;
- cuberightback[0].verts[2][1] = (float)(-M_SQRT2);
- cuberightback[0].verts[2][2] = 1.0f;
- cuberightback[0].u[2] = uv_ratio;
- cuberightback[0].v[2] = uv_ratio;
-
- //second triangle
- cuberightback[1].verts[0][0] = (float)M_SQRT2;
- cuberightback[1].verts[0][1] = 0.0f;
- cuberightback[1].verts[0][2] = -1.0f;
- cuberightback[1].u[0] = 0.0;
- cuberightback[1].v[0] = 0.0;
-
- cuberightback[1].verts[1][0] = 0.0f;
- cuberightback[1].verts[1][1] = (float)(-M_SQRT2);
- cuberightback[1].verts[1][2] = 1.0f;
- cuberightback[1].u[1] = uv_ratio;
- cuberightback[1].v[1] = uv_ratio;
-
- cuberightback[1].verts[2][0] = (float)M_SQRT2;
- cuberightback[1].verts[2][1] = 0.0f;
- cuberightback[1].verts[2][2] = 1.0f;
- cuberightback[1].u[2] = 0.0;
- cuberightback[1].v[2] = uv_ratio;
-
- nfacesrightback = 2;
-
- // Subdivide the faces
- for (i=0;i<m_resolution;i++)
- {
- cubetop.resize(4*nfacestop);
- SplitFace(cubetop,&nfacestop);
-
- cubebottom.resize(4*nfacesbottom);
- SplitFace(cubebottom,&nfacesbottom);
-
- cubeleft.resize(4*nfacesleft);
- SplitFace(cubeleft,&nfacesleft);
-
- cuberight.resize(4*nfacesright);
- SplitFace(cuberight,&nfacesright);
-
- cubeleftback.resize(4*nfacesleftback);
- SplitFace(cubeleftback,&nfacesleftback);
-
- cuberightback.resize(4*nfacesrightback);
- SplitFace(cuberightback,&nfacesrightback);
- }
-
- // Spherize the cube
- for (j=0;j<3;j++)
- {
- for (i=0;i<nfacestop;i++)
- cubetop[i].verts[j].normalize();
-
- for (i=0;i<nfacesbottom;i++)
- cubebottom[i].verts[j].normalize();
-
- for (i=0;i<nfacesleftback;i++)
- cubeleftback[i].verts[j].normalize();
-
- for (i=0;i<nfacesleft;i++)
- cubeleft[i].verts[j].normalize();
-
- for (i=0;i<nfacesright;i++)
- cuberight[i].verts[j].normalize();
-
- for (i=0;i<nfacesrightback;i++)
- cuberightback[i].verts[j].normalize();
- }
-
- //Flatten onto xz plane
- for (i=0;i<nfacesleftback;i++)
- FlattenPanorama(cubeleftback[i].verts);
-
- for (i=0;i<nfacesleft;i++)
- FlattenPanorama(cubeleft[i].verts);
-
- for (i=0;i<nfacesright;i++)
- FlattenPanorama(cuberight[i].verts);
-
- for (i=0;i<nfacesrightback;i++)
- FlattenPanorama(cuberightback[i].verts);
-
- for (i=0;i<nfacestop;i++)
- FlattenPanorama(cubetop[i].verts);
-
- for (i=0;i<nfacesbottom;i++)
- FlattenPanorama(cubebottom[i].verts);
-}
-
-void KX_Dome::FlattenDome(MT_Vector3 verts[3])
-{
- double phi, r;
-
- for (int i=0;i<3;i++) {
- r = atan2(sqrt(verts[i][0]*verts[i][0] + verts[i][2]*verts[i][2]), verts[i][1]);
- r /= (double)this->m_radangle / 2.0;
-
- phi = atan2(verts[i][2], verts[i][0]);
-
- verts[i][0] = r * cos(phi);
- verts[i][1] = 0.0f;
- verts[i][2] = r * sin(phi);
-
- if (r > 1.0) {
- //round the border
- verts[i][0] = cos(phi);
- verts[i][1] = -3.0f;
- verts[i][2] = sin(phi);
- }
- }
-}
-
-void KX_Dome::FlattenPanorama(MT_Vector3 verts[3])
-{
-// it creates a full spherical panoramic (360deg)
- int i;
- double phi, theta;
- bool edge=false;
-
- for (i=0;i<3;i++) {
- phi = atan2(verts[i][1], verts[i][0]);
- phi *= -1.0; //flipping
-
- if (phi == -MT_PI) //It's on the edge
- edge=true;
-
- verts[i][0] = phi / MT_PI;
- verts[i][1] = 0.0f;
-
- theta = asin(verts[i][2]);
- verts[i][2] = theta / MT_PI;
- }
- if (edge) {
- bool right=false;
-
- for (i=0;i<3;i++) {
- if (fmodf(verts[i][0],1.0f) > 0.0f) {
- right=true;
- break;
- }
- }
- if (right) {
- for (i=0;i<3;i++) {
- if (verts[i][0] < 0.0f)
- verts[i][0] *= -1.0f;
- }
- }
- }
-}
-
-void KX_Dome::SplitFace(vector <DomeFace>& face, int *nfaces)
-{
- int i;
- int n1, n2;
-
- n1 = n2 = *nfaces;
-
- for (i=0;i<n1;i++) {
-
- face[n2].verts[0] = (face[i].verts[0] + face[i].verts[1]) /2;
- face[n2].verts[1] = face[i].verts[1];
- face[n2].verts[2] = (face[i].verts[1] + face[i].verts[2]) /2;
- face[n2].u[0] = (face[i].u[0] + face[i].u[1]) /2;
- face[n2].u[1] = face[i].u[1];
- face[n2].u[2] = (face[i].u[1] + face[i].u[2]) /2;
- face[n2].v[0] = (face[i].v[0] + face[i].v[1]) /2;
- face[n2].v[1] = face[i].v[1];
- face[n2].v[2] = (face[i].v[1] + face[i].v[2]) /2;
-
- face[n2+1].verts[0] = (face[i].verts[1] + face[i].verts[2]) /2;
- face[n2+1].verts[1] = face[i].verts[2];
- face[n2+1].verts[2] = (face[i].verts[2] + face[i].verts[0]) /2;
- face[n2+1].u[0] = (face[i].u[1] + face[i].u[2]) /2;
- face[n2+1].u[1] = face[i].u[2];
- face[n2+1].u[2] = (face[i].u[2] + face[i].u[0]) /2;
- face[n2+1].v[0] = (face[i].v[1] + face[i].v[2]) /2;
- face[n2+1].v[1] = face[i].v[2];
- face[n2+1].v[2] = (face[i].v[2] + face[i].v[0]) /2;
-
- face[n2+2].verts[0] = (face[i].verts[0] + face[i].verts[1]) /2;
- face[n2+2].verts[1] = (face[i].verts[1] + face[i].verts[2]) /2;
- face[n2+2].verts[2] = (face[i].verts[2] + face[i].verts[0]) /2;
- face[n2+2].u[0] = (face[i].u[0] + face[i].u[1]) /2;
- face[n2+2].u[1] = (face[i].u[1] + face[i].u[2]) /2;
- face[n2+2].u[2] = (face[i].u[2] + face[i].u[0]) /2;
- face[n2+2].v[0] = (face[i].v[0] + face[i].v[1]) /2;
- face[n2+2].v[1] = (face[i].v[1] + face[i].v[2]) /2;
- face[n2+2].v[2] = (face[i].v[2] + face[i].v[0]) /2;
-
- //face[i].verts[0] = face[i].verts[0];
- face[i].verts[1] = (face[i].verts[0] + face[i].verts[1]) /2;
- face[i].verts[2] = (face[i].verts[0] + face[i].verts[2]) /2;
- //face[i].u[0] = face[i].u[0];
- face[i].u[1] = (face[i].u[0] + face[i].u[1]) /2;
- face[i].u[2] = (face[i].u[0] + face[i].u[2]) /2;
- //face[i].v[0] = face[i].v[0];
- face[i].v[1] = (face[i].v[0] + face[i].v[1]) /2;
- face[i].v[2] = (face[i].v[0] + face[i].v[2]) /2;
-
- n2 += 3; // number of faces
- }
- *nfaces = n2;
-}
-
-void KX_Dome::CalculateFrustum(KX_Camera *cam)
-{
-#if 0
- // manually creating a 90deg Field of View Frustum
-
- // the original formula:
- top = tan(fov*3.14159f/30.0f)) * near [for fov in degrees]
- fov*0.5f = arctan ((top-bottom)*0.5f / near) [for fov in radians]
- bottom = -top
- left = aspect * bottom
- right = aspect * top
-
- // the equivalent GLU call is:
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- gluPerspective(90.0f,1.0f,cam->GetCameraNear(),cam->GetCameraFar());
-#endif
-
- RAS_FrameFrustum m_frustum; //90 deg. Frustum
-
- m_frustum.camnear = cam->GetCameraNear();
- m_frustum.camfar = cam->GetCameraFar();
-
-// float top = tan(90.0f*MT_PI/360.0f) * m_frustum.camnear;
- float top = m_frustum.camnear; // for deg = 90deg, tan = 1
-
- m_frustum.x1 = -top;
- m_frustum.x2 = top;
- m_frustum.y1 = -top;
- m_frustum.y2 = top;
-
- m_projmat = m_rasterizer->GetFrustumMatrix(
- m_frustum.x1, m_frustum.x2, m_frustum.y1, m_frustum.y2, m_frustum.camnear, m_frustum.camfar);
-}
-
-void KX_Dome::CalculateCameraOrientation()
-{
-/*
- * Uses 4 cameras for angles up to 180deg
- * Uses 5 cameras for angles up to 250deg
- * Uses 6 cameras for angles up to 360deg
- */
- int i;
- float deg45 = MT_PI / 4.0f;
- MT_Scalar c = cosf(deg45);
- MT_Scalar s = sinf(deg45);
-
- if (m_angle <= 180 && (m_mode == DOME_FISHEYE
- || m_mode == DOME_TRUNCATED_FRONT
- || m_mode == DOME_TRUNCATED_REAR)) {
-
- m_locRot[0] = MT_Matrix3x3( // 90deg - Top
- c, -s, 0.0f,
- 0.0f,0.0f, -1.0f,
- s, c, 0.0f);
-
- m_locRot[1] = MT_Matrix3x3( // 90deg - Bottom
- -s, c, 0.0f,
- 0.0f,0.0f, 1.0f,
- s, c, 0.0f);
-
- m_locRot[2] = MT_Matrix3x3( // 45deg - Left
- c, 0.0f, s,
- 0, 1.0f, 0.0f,
- -s, 0.0f, c);
-
- m_locRot[3] = MT_Matrix3x3( // 45deg - Right
- c, 0.0f, -s,
- 0.0f, 1.0f, 0.0f,
- s, 0.0f, c);
-
- } else if (m_mode == DOME_ENVMAP || (m_angle > 180 && (m_mode == DOME_FISHEYE
- || m_mode == DOME_TRUNCATED_FRONT
- || m_mode == DOME_TRUNCATED_REAR))) {
-
- m_locRot[0] = MT_Matrix3x3( // 90deg - Top
- 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f,-1.0f,
- 0.0f, 1.0f, 0.0f);
-
- m_locRot[1] = MT_Matrix3x3( // 90deg - Bottom
- 1.0f, 0.0f, 0.0f,
- 0.0f, 0.0f, 1.0f,
- 0.0f,-1.0f, 0.0f);
-
- m_locRot[2] = MT_Matrix3x3( // -90deg - Left
- 0.0f, 0.0f, 1.0f,
- 0.0f, 1.0f, 0.0f,
- -1.0f, 0.0f, 0.0f);
-
- m_locRot[3] = MT_Matrix3x3( // 90deg - Right
- 0.0f, 0.0f,-1.0f,
- 0.0f, 1.0f, 0.0f,
- 1.0f, 0.0f, 0.0f);
-
- m_locRot[4] = MT_Matrix3x3( // 0deg - Front
- 1.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 1.0f);
-
- m_locRot[5] = MT_Matrix3x3( // 180deg - Back - USED for ENVMAP only
- -1.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f,-1.0f);
-
- } else if (m_mode == DOME_PANORAM_SPH) {
-
- m_locRot[0] = MT_Matrix3x3( // Top
- c, s, 0.0f,
- 0.0f,0.0f, -1.0f,
- -s, c, 0.0f);
-
- m_locRot[1] = MT_Matrix3x3( // Bottom
- c, s, 0.0f,
- 0.0f, 0.0f, 1.0f,
- s, -c, 0.0f);
-
- m_locRot[2] = MT_Matrix3x3( // 45deg - Left
- -s, 0.0f, c,
- 0, 1.0f, 0.0f,
- -c, 0.0f, -s);
-
- m_locRot[3] = MT_Matrix3x3( // 45deg - Right
- c, 0.0f, s,
- 0, 1.0f, 0.0f,
- -s, 0.0f, c);
-
- m_locRot[4] = MT_Matrix3x3( // 135deg - LeftBack
- -s, 0.0f, -c,
- 0.0f, 1.0f, 0.0f,
- c, 0.0f, -s);
-
- m_locRot[5] = MT_Matrix3x3( // 135deg - RightBack
- c, 0.0f, -s,
- 0.0f, 1.0f, 0.0f,
- s, 0.0f, c);
- }
-
- // rotating the camera in horizontal axis
- if (m_tilt)
- {
- float tiltdeg = ((m_tilt % 360) * 2 * MT_PI) / 360;
- c = cosf(tiltdeg);
- s = sinf(tiltdeg);
-
- MT_Matrix3x3 tilt_mat = MT_Matrix3x3(
- 1.0f, 0.0f, 0.0f,
- 0.0f, c, -s,
- 0.0f, s, c
- );
-
- for (i =0;i<6;i++)
- m_locRot[i] = tilt_mat * m_locRot[i];
- }
-}
-
-void KX_Dome::RotateCamera(KX_Camera* cam, int i)
-{
-// I'm not using it, I'm doing inline calls for these commands
-// but it's nice to have it here in case I need it
-
- MT_Matrix3x3 camori = cam->GetSGNode()->GetLocalOrientation();
-
- cam->NodeSetLocalOrientation(camori*m_locRot[i]);
- cam->NodeUpdateGS(0.f);
-
- MT_Transform camtrans(cam->GetWorldToCamera());
- MT_Matrix4x4 viewmat(camtrans);
- m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->NodeGetLocalScaling(), cam->GetCameraData()->m_perspective);
- cam->SetModelviewMatrix(viewmat);
-
- // restore the original orientation
- cam->NodeSetLocalOrientation(camori);
- cam->NodeUpdateGS(0.f);
-}
-
-void KX_Dome::Draw(void)
-{
-
- if (fboSupported) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, warp.fboId);
-
- glViewport(0,0,warp.imagesize, warp.imagesize);
- glScissor(0,0,warp.imagesize, warp.imagesize);
- }
-
- switch (m_mode) {
- case DOME_FISHEYE:
- DrawDomeFisheye();
- break;
- case DOME_ENVMAP:
- DrawEnvMap();
- break;
- case DOME_PANORAM_SPH:
- DrawPanorama();
- break;
- case DOME_TRUNCATED_FRONT:
- DrawDomeFisheye();
- break;
- case DOME_TRUNCATED_REAR:
- DrawDomeFisheye();
- break;
- }
-
- if (warp.usemesh)
- {
- if (fboSupported)
- {
- m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- }
- else
- {
- glBindTexture(GL_TEXTURE_2D, domefacesId[m_numfaces]);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_viewport.GetLeft(), m_viewport.GetBottom(), warp.bufferwidth, warp.bufferheight);
- }
- DrawDomeWarped();
- }
-}
-
-void KX_Dome::DrawEnvMap(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- // Making the viewport always square
-
- int can_width = m_viewport.GetRight();
- int can_height = m_viewport.GetTop();
-
- float ortho_width, ortho_height;
-
- if (warp.usemesh)
- glOrtho((-1.0), 1.0, (-0.66), 0.66, 0.0, 0.0); //stretch the image to reduce resolution lost
-
- else {
- if (can_width/3 <= can_height/2) {
- ortho_width = 1.0f;
- ortho_height = (float)can_height/can_width;
- }
- else {
- ortho_height = 2.0f / 3;
- ortho_width = (float)can_width/can_height * ortho_height;
- }
-
- glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0f, 10.0f);
- }
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0f,0.0f,1.0f, 0.0f,0.0f,0.0f, 0.0f,1.0f,0.0f);
-
- glPolygonMode(GL_FRONT, GL_FILL);
- glShadeModel(GL_SMOOTH);
- glDisable(GL_LIGHTING);
- glDisable(GL_DEPTH_TEST);
-
- glEnable(GL_TEXTURE_2D);
- glColor3f(1.0f,1.0f,1.0f);
-
- float uv_ratio = (float)(m_buffersize-1) / m_imagesize;
- double onebythree = 1.0f / 3;
-
- // domefacesId[0] => (top)
- glBindTexture(GL_TEXTURE_2D, domefacesId[0]);
- glBegin(GL_QUADS);
- glTexCoord2f(uv_ratio,uv_ratio);
- glVertex3f( onebythree, 0.0f, 3.0f);
- glTexCoord2f(0.0f,uv_ratio);
- glVertex3f(-onebythree, 0.0f, 3.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(-onebythree,-2 * onebythree, 3.0f);
- glTexCoord2f(uv_ratio,0.0f);
- glVertex3f(onebythree,-2 * onebythree, 3.0f);
- glEnd();
-
- // domefacesId[1] => (bottom)
- glBindTexture(GL_TEXTURE_2D, domefacesId[1]);
- glBegin(GL_QUADS);
- glTexCoord2f(uv_ratio,uv_ratio);
- glVertex3f(-onebythree, 0.0f, 3.0f);
- glTexCoord2f(0.0f,uv_ratio);
- glVertex3f(-1.0f, 0.0f, 3.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(-1.0f,-2 * onebythree, 3.0f);
- glTexCoord2f(uv_ratio,0.0f);
- glVertex3f(-onebythree,-2 * onebythree, 3.0f);
- glEnd();
-
- // domefacesId[2] => -90deg (left)
- glBindTexture(GL_TEXTURE_2D, domefacesId[2]);
- glBegin(GL_QUADS);
- glTexCoord2f(uv_ratio,uv_ratio);
- glVertex3f(-onebythree, 2 * onebythree, 3.0f);
- glTexCoord2f(0.0f,uv_ratio);
- glVertex3f(-1.0f, 2 * onebythree, 3.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(-1.0f, 0.0f, 3.0f);
- glTexCoord2f(uv_ratio,0.0f);
- glVertex3f(-onebythree, 0.0f, 3.0f);
- glEnd();
-
- // domefacesId[3] => 90deg (right)
- glBindTexture(GL_TEXTURE_2D, domefacesId[3]);
- glBegin(GL_QUADS);
- glTexCoord2f(uv_ratio,uv_ratio);
- glVertex3f( 1.0f, 2 * onebythree, 3.0f);
- glTexCoord2f(0.0f,uv_ratio);
- glVertex3f( onebythree, 2 * onebythree, 3.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f( onebythree, 0.0f, 3.0f);
- glTexCoord2f(uv_ratio,0.0f);
- glVertex3f(1.0f, 0.0f, 3.0f);
- glEnd();
-
- // domefacesId[4] => 0deg (front)
- glBindTexture(GL_TEXTURE_2D, domefacesId[4]);
- glBegin(GL_QUADS);
- glTexCoord2f(uv_ratio,uv_ratio);
- glVertex3f( 1.0f, 0.0f, 3.0f);
- glTexCoord2f(0.0f,uv_ratio);
- glVertex3f( onebythree, 0.0f, 3.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f( onebythree,-2 * onebythree, 3.0f);
- glTexCoord2f(uv_ratio,0.0f);
- glVertex3f(1.0f, -2 * onebythree, 3.0f);
- glEnd();
-
- // domefacesId[5] => 180deg (back)
- glBindTexture(GL_TEXTURE_2D, domefacesId[5]);
- glBegin(GL_QUADS);
- glTexCoord2f(uv_ratio,uv_ratio);
- glVertex3f( onebythree, 2 * onebythree, 3.0f);
- glTexCoord2f(0.0f,uv_ratio);
- glVertex3f(-onebythree, 2 * onebythree, 3.0f);
- glTexCoord2f(0.0f,0.0f);
- glVertex3f(-onebythree, 0.0f, 3.0f);
- glTexCoord2f(uv_ratio,0.0f);
- glVertex3f(onebythree, 0.0f, 3.0f);
- glEnd();
-
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
-}
-
-void KX_Dome::DrawDomeFisheye(void)
-{
- int i;
-
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- // Making the viewport always square
-
- int can_width = m_viewport.GetRight();
- int can_height = m_viewport.GetTop();
-
- float ortho_width, ortho_height;
-
- if (m_mode == DOME_FISHEYE) {
- if (warp.usemesh)
- glOrtho((-1.0f), 1.0f, (-1.0f), 1.0f, -20.0f, 10.0f); //stretch the image to reduce resolution lost
-
- else {
- if (can_width < can_height) {
- ortho_width = 1.0f;
- ortho_height = (float)can_height/can_width;
- }
- else {
- ortho_width = (float)can_width/can_height;
- ortho_height = 1.0f;
- }
-
- glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0f, 10.0f);
- }
- }
- else if (m_mode == DOME_TRUNCATED_FRONT)
- {
- ortho_width = 1.0f;
- ortho_height = 2.0f * ((float)can_height / can_width) - 1.0f;
-
- glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_width, -20.0f, 10.0f);
- }
- else { //m_mode == DOME_TRUNCATED_REAR
- ortho_width = 1.0f;
- ortho_height = 2.0f * ((float)can_height / can_width) - 1.0f;
-
- glOrtho((-ortho_width), ortho_width, (-ortho_width), ortho_height, -20.0f, 10.0f);
- }
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0f,-1.0f,0.0f, 0.0f,0.0f,0.0f, 0.0f,0.0f,1.0f);
-
- if (m_drawingmode == RAS_IRasterizer::KX_WIREFRAME)
- glPolygonMode(GL_FRONT, GL_LINE);
- else
- glPolygonMode(GL_FRONT, GL_FILL);
-
- glShadeModel(GL_SMOOTH);
- glDisable(GL_LIGHTING);
- glDisable(GL_DEPTH_TEST);
-
- glEnable(GL_TEXTURE_2D);
- glColor3f(1.0f,1.0f,1.0f);
-
- if (dlistSupported) {
- for (i=0;i<m_numfaces;i++) {
- glBindTexture(GL_TEXTURE_2D, domefacesId[i]);
- glCallList(dlistId+i);
- }
- }
- else { // DisplayLists not supported
- // top triangle
- glBindTexture(GL_TEXTURE_2D, domefacesId[0]);
- GLDrawTriangles(cubetop, nfacestop);
-
- // bottom triangle
- glBindTexture(GL_TEXTURE_2D, domefacesId[1]);
- GLDrawTriangles(cubebottom, nfacesbottom);
-
- // left triangle
- glBindTexture(GL_TEXTURE_2D, domefacesId[2]);
- GLDrawTriangles(cubeleft, nfacesleft);
-
- // right triangle
- glBindTexture(GL_TEXTURE_2D, domefacesId[3]);
- GLDrawTriangles(cuberight, nfacesright);
-
- if (m_angle > 180) {
- // front triangle
- glBindTexture(GL_TEXTURE_2D, domefacesId[4]);
- GLDrawTriangles(cubefront, nfacesfront);
- }
- }
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
-}
-
-void KX_Dome::DrawPanorama(void)
-{
- int i;
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- // Making the viewport always square
-
- int can_width = m_viewport.GetRight();
- int can_height = m_viewport.GetTop();
-
- float ortho_height = 1.0f;
- float ortho_width = 1.0f;
-
- if (warp.usemesh)
- glOrtho((-1.0f), 1.0f, (-0.5f), 0.5f, -20.0f, 10.0f); //stretch the image to reduce resolution lost
-
- else {
- //using all the screen
- if ((can_width / 2) <= (can_height)) {
- ortho_width = 1.0f;
- ortho_height = (float)can_height/can_width;
- }
- else {
- ortho_width = (float)can_width / can_height * 0.5f;
- ortho_height = 0.5f;
- }
-
- glOrtho((-ortho_width), ortho_width, (-ortho_height), ortho_height, -20.0f, 10.0f);
- }
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0f,-1.0f,0.0f, 0.0f,0.0f,0.0f, 0.0f,0.0f,1.0f);
-
- if (m_drawingmode == RAS_IRasterizer::KX_WIREFRAME)
- glPolygonMode(GL_FRONT, GL_LINE);
- else
- glPolygonMode(GL_FRONT, GL_FILL);
-
- glShadeModel(GL_SMOOTH);
- glDisable(GL_LIGHTING);
- glDisable(GL_DEPTH_TEST);
-
- glEnable(GL_TEXTURE_2D);
- glColor3f(1.0f,1.0f,1.0f);
-
- if (dlistSupported) {
- for (i=0;i<m_numfaces;i++) {
- glBindTexture(GL_TEXTURE_2D, domefacesId[i]);
- glCallList(dlistId+i);
- }
- }
- else {
- // domefacesId[4] => (top)
- glBindTexture(GL_TEXTURE_2D, domefacesId[0]);
- GLDrawTriangles(cubetop, nfacestop);
-
- // domefacesId[5] => (bottom)
- glBindTexture(GL_TEXTURE_2D, domefacesId[1]);
- GLDrawTriangles(cubebottom, nfacesbottom);
-
- // domefacesId[1] => -45deg (left)
- glBindTexture(GL_TEXTURE_2D, domefacesId[2]);
- GLDrawTriangles(cubeleft, nfacesleft);
-
- // domefacesId[2] => 45deg (right)
- glBindTexture(GL_TEXTURE_2D, domefacesId[3]);
- GLDrawTriangles(cuberight, nfacesright);
-
- // domefacesId[0] => -135deg (leftback)
- glBindTexture(GL_TEXTURE_2D, domefacesId[4]);
- GLDrawTriangles(cubeleftback, nfacesleftback);
-
- // domefacesId[3] => 135deg (rightback)
- glBindTexture(GL_TEXTURE_2D, domefacesId[5]);
- GLDrawTriangles(cuberightback, nfacesrightback);
- }
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
-}
-
-void KX_Dome::DrawDomeWarped(void)
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
-
- // Making the viewport always square
- int can_width = m_viewport.GetRight();
- int can_height = m_viewport.GetTop();
-
- double screen_ratio = can_width/ (double) can_height;
-
- glOrtho(-screen_ratio,screen_ratio,-1.0f,1.0f,-20.0f,10.0f);
-
-
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_MODELVIEW);
- glLoadIdentity();
- gluLookAt(0.0f, 0.0f, 1.0f, 0.0f,0.0f,0.0f, 0.0f,1.0f,0.0f);
-
- if (m_drawingmode == RAS_IRasterizer::KX_WIREFRAME)
- glPolygonMode(GL_FRONT, GL_LINE);
- else
- glPolygonMode(GL_FRONT, GL_FILL);
-
- glShadeModel(GL_SMOOTH);
- glDisable(GL_LIGHTING);
- glDisable(GL_DEPTH_TEST);
-
- glEnable(GL_TEXTURE_2D);
- glColor3f(1.0f,1.0f,1.0f);
-
- if (dlistSupported) {
- glBindTexture(GL_TEXTURE_2D, domefacesId[m_numfaces]);
- glCallList(dlistId + m_numfaces);
- }
- else {
- glBindTexture(GL_TEXTURE_2D, domefacesId[m_numfaces]);
- GLDrawWarpQuads();
- }
- glDisable(GL_TEXTURE_2D);
- glEnable(GL_DEPTH_TEST);
-}
-
-void KX_Dome::BindImages(int i)
-{
- glBindTexture(GL_TEXTURE_2D, domefacesId[i]);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_viewport.GetLeft(), m_viewport.GetBottom(), m_buffersize, m_buffersize);
-}
-
-void KX_Dome::RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i)
-{
- if (!cam)
- return;
-
- m_canvas->SetViewPort(0,0,m_buffersize-1,m_buffersize-1);
-
-// m_rasterizer->SetAmbient();
- m_rasterizer->DisplayFog();
-
- CalculateFrustum(cam); //calculates m_projmat
- cam->SetProjectionMatrix(m_projmat);
- m_rasterizer->SetProjectionMatrix(cam->GetProjectionMatrix());
-// Dome_RotateCamera(cam,i);
-
- MT_Matrix3x3 camori = cam->GetSGNode()->GetLocalOrientation();
-
- cam->NodeSetLocalOrientation(camori*m_locRot[i]);
- cam->NodeUpdateGS(0.f);
-
- MT_Transform camtrans(cam->GetWorldToCamera());
- MT_Matrix4x4 viewmat(camtrans);
- m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->NodeGetLocalScaling(), 1.0f);
- cam->SetModelviewMatrix(viewmat);
-
- // restore the original orientation
- cam->NodeSetLocalOrientation(camori);
- cam->NodeUpdateGS(0.f);
-
- scene->CalculateVisibleMeshes(m_rasterizer,cam);
-
- m_engine->UpdateAnimations(scene);
-
- scene->RenderBuckets(camtrans, m_rasterizer);
-}
-
diff --git a/source/gameengine/Ketsji/KX_Dome.h b/source/gameengine/Ketsji/KX_Dome.h
deleted file mode 100644
index 5a0c4588ae2..00000000000
--- a/source/gameengine/Ketsji/KX_Dome.h
+++ /dev/null
@@ -1,197 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Dalai Felinto
- *
- * This source uses some of the ideas and code from Paul Bourke.
- * Developed as part of a Research and Development project for
- * SAT - La Société des arts technologiques.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_Dome.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_DOME_H__
-#define __KX_DOME_H__
-
-#include "KX_Scene.h"
-#include "KX_Camera.h"
-#include "DNA_screen_types.h"
-#include "RAS_ICanvas.h"
-#include "RAS_IRasterizer.h"
-#include "KX_KetsjiEngine.h"
-
-#include "GPU_glew.h"
-#include <vector>
-
-#include "MEM_guardedalloc.h"
-#include "BKE_text.h"
-
-//Dome modes: limit hardcoded in buttons_scene.c
-#define DOME_FISHEYE 1
-#define DOME_TRUNCATED_FRONT 2
-#define DOME_TRUNCATED_REAR 3
-#define DOME_ENVMAP 4
-#define DOME_PANORAM_SPH 5
-#define DOME_NUM_MODES 6
-
-
-/// class for render 3d scene
-class KX_Dome
-{
-public:
- /// constructor
- KX_Dome (RAS_ICanvas* m_canvas,
- /// rasterizer
- RAS_IRasterizer* m_rasterizer,
- /// engine
- KX_KetsjiEngine* m_engine,
-
- short res,
- short mode,
- short angle,
- float resbuf,
- short tilt,
- struct Text* warptext
- );
-
- /// destructor
- virtual ~KX_Dome (void);
-
- //openGL checks:
- bool dlistSupported;
- bool fboSupported;
-
- //openGL names:
- GLuint domefacesId[7]; /* ID of the images -- room for 7 images, using only 4 for 180deg x 360deg dome,
- * 6 for panoramic and +1 for warp mesh */
- GLuint dlistId; /* ID of the Display Lists of the images (used as an offset) */
-
- typedef struct {
- double u[3], v[3];
- MT_Vector3 verts[3]; //three verts
- } DomeFace;
-
- //mesh warp functions
- typedef struct {
- double x, y, u, v, i;
- } WarpMeshNode;
-
- struct {
- bool usemesh;
- int mode;
- int n_width, n_height; //nodes width and height
- int imagesize;
- int bufferwidth, bufferheight;
- GLuint fboId;
- vector <vector <WarpMeshNode> > nodes;
- } warp;
-
- bool ParseWarpMesh(STR_String text);
-
- vector <DomeFace> cubetop, cubebottom, cuberight, cubeleft, cubefront, cubeback; //for fisheye
- vector <DomeFace> cubeleftback, cuberightback; //for panorama
-
- int nfacestop, nfacesbottom, nfacesleft, nfacesright, nfacesfront, nfacesback;
- int nfacesleftback, nfacesrightback;
-
- int GetNumberRenders() { return m_numfaces; }
-
- void RenderDome(void);
- void RenderDomeFrame(KX_Scene* scene, KX_Camera* cam, int i);
- void BindImages(int i);
-
- void SetViewPort(const int viewport[4]);
- void CalculateFrustum(KX_Camera* cam);
- void RotateCamera(KX_Camera* cam, int i);
-
- //Mesh creation Functions
- void CreateMeshDome180(void);
- void CreateMeshDome250(void);
- void CreateMeshPanorama(void);
-
- void SplitFace(vector <DomeFace>& face, int *nfaces);
-
- void FlattenDome(MT_Vector3 verts[3]);
- void FlattenPanorama(MT_Vector3 verts[3]);
-
- //Draw functions
- void GLDrawTriangles(vector <DomeFace>& face, int nfaces);
- void GLDrawWarpQuads(void);
- void Draw(void);
- void DrawDomeFisheye(void);
- void DrawEnvMap(void);
- void DrawPanorama(void);
- void DrawDomeWarped(void);
-
- //setting up openGL
- void CreateGLImages(void);
- void ClearGLImages(void);//called on resize
- bool CreateDL(void); //create Display Lists
- void ClearDL(void); //remove Display Lists
- bool CreateFBO(void);//create FBO (for warp mesh)
- void ClearFBO(void); //remove FBO
-
- void CalculateCameraOrientation();
- void CalculateImageSize(); //set m_imagesize
-
- int canvaswidth;
- int canvasheight;
-
-protected:
- int m_drawingmode;
-
- int m_imagesize;
- int m_buffersize; // canvas small dimension
- int m_numfaces; // 4 to 6 depending on the kind of dome image
- int m_numimages; //numfaces +1 if we have warp mesh
-
- short m_resolution; //resolution to tessellate the mesh
- short m_mode; // the mode (truncated, warped, panoramic,...)
- short m_angle; //the angle of the fisheye
- float m_radangle; //the angle of the fisheye in radians
- float m_resbuffer; //the resolution of the buffer
- short m_tilt; //the dome tilt (camera rotation on horizontal axis)
-
- RAS_Rect m_viewport;
-
- MT_Matrix4x4 m_projmat;
-
- MT_Matrix3x3 m_locRot[6]; // the rotation matrix
-
- /// rendered scene
- KX_Scene * m_scene;
-
- /// canvas
- RAS_ICanvas* m_canvas;
- /// rasterizer
- RAS_IRasterizer* m_rasterizer;
- /// render tools
- RAS_IRenderTools* m_rendertools;
- /// engine
- KX_KetsjiEngine* m_engine;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_Dome")
-#endif
-};
-
-#endif /* __KX_DOME_H__ */
diff --git a/source/gameengine/Ketsji/KX_EmptyObject.cpp b/source/gameengine/Ketsji/KX_EmptyObject.cpp
deleted file mode 100644
index 670329a4350..00000000000
--- a/source/gameengine/Ketsji/KX_EmptyObject.cpp
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_EmptyObject.cpp
- * \ingroup ketsji
- */
-
-#include "KX_EmptyObject.h"
-
-KX_EmptyObject::~KX_EmptyObject()
-{
-
-}
diff --git a/source/gameengine/Ketsji/KX_EmptyObject.h b/source/gameengine/Ketsji/KX_EmptyObject.h
deleted file mode 100644
index 63a0782a544..00000000000
--- a/source/gameengine/Ketsji/KX_EmptyObject.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_EmptyObject.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_EMPTYOBJECT_H__
-#define __KX_EMPTYOBJECT_H__
-#include "KX_GameObject.h"
-
-class KX_EmptyObject : public KX_GameObject
-{
-public:
- KX_EmptyObject(void* sgReplicationInfo,SG_Callbacks callbacks) :
- KX_GameObject(sgReplicationInfo,callbacks)
- {};
- virtual ~KX_EmptyObject();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_EmptyObject")
-#endif
-};
-
-#endif /* __KX_EMPTYOBJECT_H__ */
diff --git a/source/gameengine/Ketsji/KX_FontObject.cpp b/source/gameengine/Ketsji/KX_FontObject.cpp
deleted file mode 100644
index ae79284288d..00000000000
--- a/source/gameengine/Ketsji/KX_FontObject.cpp
+++ /dev/null
@@ -1,300 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_FontObject.cpp
- * \ingroup ketsji
- */
-
-#include "KX_FontObject.h"
-#include "DNA_curve_types.h"
-#include "DNA_vfont_types.h"
-#include "KX_Scene.h"
-#include "KX_PythonInit.h"
-#include "BLI_math.h"
-#include "EXP_StringValue.h"
-#include "RAS_IRasterizer.h"
-
-/* paths needed for font load */
-#include "BLI_blenlib.h"
-#include "BKE_global.h"
-#include "BKE_font.h"
-#include "BKE_main.h"
-#include "DNA_packedFile_types.h"
-
-extern "C" {
-#include "BLF_api.h"
-}
-
-#define BGE_FONT_RES 100
-
-/* proptotype */
-int GetFontId(VFont *font);
-
-static std::vector<STR_String> split_string(STR_String str)
-{
- std::vector<STR_String> text = std::vector<STR_String>();
-
- /* Split the string upon new lines */
- int begin=0, end=0;
- while (end < str.Length())
- {
- if (str.GetAt(end) == '\n')
- {
- text.push_back(str.Mid(begin, end-begin));
- begin = end+1;
- }
- end++;
- }
- //Now grab the last line
- text.push_back(str.Mid(begin, end-begin));
-
- return text;
-}
-
-KX_FontObject::KX_FontObject(void* sgReplicationInfo,
- SG_Callbacks callbacks,
- RAS_IRasterizer* rasterizer,
- Object *ob,
- bool do_color_management):
- KX_GameObject(sgReplicationInfo, callbacks),
- m_object(ob),
- m_dpi(72),
- m_resolution(1.f),
- m_rasterizer(rasterizer),
- m_do_color_management(do_color_management)
-{
- Curve *text = static_cast<Curve *> (ob->data);
- m_text = split_string(text->str);
- m_fsize = text->fsize;
- m_line_spacing = text->linedist;
- m_offset = MT_Vector3(text->xof, text->yof, 0);
-
- m_fontid = GetFontId(text->vfont);
-
- /* initialize the color with the object color and store it in the KX_Object class
- * This is a workaround waiting for the fix:
- * [#25487] BGE: Object Color only works when it has a keyed frame */
- copy_v4_v4(m_color, (const float*) ob->col);
- this->SetObjectColor((const MT_Vector4&) m_color);
-}
-
-KX_FontObject::~KX_FontObject()
-{
- //remove font from the scene list
- //it's handled in KX_Scene::NewRemoveObject
-}
-
-CValue* KX_FontObject::GetReplica()
-{
- KX_FontObject* replica = new KX_FontObject(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_FontObject::ProcessReplica()
-{
- KX_GameObject::ProcessReplica();
-}
-
-int GetFontId(VFont *vfont)
-{
- PackedFile *packedfile=NULL;
- int fontid = -1;
-
- if (vfont->packedfile) {
- packedfile= vfont->packedfile;
- fontid= BLF_load_mem(vfont->name, (unsigned char*)packedfile->data, packedfile->size);
-
- if (fontid == -1) {
- printf("ERROR: packed font \"%s\" could not be loaded.\n", vfont->name);
- fontid = BLF_load("default");
- }
- return fontid;
- }
-
- /* once we have packed working we can load the builtin font */
- const char *filepath = vfont->name;
- if (BKE_vfont_is_builtin(vfont)) {
- fontid = BLF_load("default");
-
- /* XXX the following code is supposed to work (after you add get_builtin_packedfile to BKE_font.h )
- * unfortunately it's crashing on blf_glyph.c:173 because gc->glyph_width_max is 0
- */
- // packedfile=get_builtin_packedfile();
- // fontid= BLF_load_mem(font->name, (unsigned char*)packedfile->data, packedfile->size);
- // return fontid;
-
- return BLF_load("default");
- }
-
- /* convert from absolute to relative */
- char expanded[256]; // font names can be bigger than FILE_MAX (240)
- BLI_strncpy(expanded, filepath, 256);
- BLI_path_abs(expanded, G.main->name);
-
- fontid = BLF_load(expanded);
-
- /* fallback */
- if (fontid == -1)
- fontid = BLF_load("default");
-
- return fontid;
-}
-
-void KX_FontObject::DrawFontText()
-{
- /* Allow for some logic brick control */
- if (this->GetProperty("Text"))
- m_text = split_string(this->GetProperty("Text")->GetText());
-
- /* only draws the text if visible */
- if (this->GetVisible() == 0) return;
-
- /* update the animated color */
- this->GetObjectColor().getValue(m_color);
-
- /* Font Objects don't use the glsl shader, this color management code is copied from gpu_shader_material.glsl */
- float color[4];
- if (m_do_color_management) {
- linearrgb_to_srgb_v4(color, m_color);
- }
- else {
- copy_v4_v4(color, m_color);
- }
-
- /* HARDCODED MULTIPLICATION FACTOR - this will affect the render resolution directly */
- const float RES = BGE_FONT_RES * m_resolution;
-
- const float size = m_fsize * this->NodeGetWorldScaling()[0] * RES;
- const float aspect = m_fsize / size;
-
- /* Get a working copy of the OpenGLMatrix to use */
- float *mat = GetOpenGLMatrix();
-
- /* Account for offset */
- MT_Vector3 offset = this->NodeGetWorldOrientation() * m_offset * this->NodeGetWorldScaling();
- mat[12] += offset[0]; mat[13] += offset[1]; mat[14] += offset[2];
-
- /* Orient the spacing vector */
- MT_Vector3 spacing = MT_Vector3(0.0f, m_fsize*m_line_spacing, 0.0f);
- spacing = this->NodeGetWorldOrientation() * spacing * this->NodeGetWorldScaling()[1];
-
- /* Draw each line, taking spacing into consideration */
- for (int i=0; i<m_text.size(); ++i)
- {
- if (i!=0)
- {
- mat[12] -= spacing[0];
- mat[13] -= spacing[1];
- mat[14] -= spacing[2];
- }
- m_rasterizer->RenderText3D(m_fontid, m_text[i], int(size), m_dpi, color, mat, aspect);
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject KX_FontObject::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_FontObject",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- &KX_GameObject::Sequence,
- &KX_GameObject::Mapping,
- 0,0,0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_GameObject::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_FontObject::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_FontObject::Attributes[] = {
- //KX_PYATTRIBUTE_STRING_RW("text", 0, 280, false, KX_FontObject, m_text[0]), //arbitrary limit. 280 = 140 unicode chars in unicode
- KX_PYATTRIBUTE_RW_FUNCTION("text", KX_FontObject, pyattr_get_text, pyattr_set_text),
- KX_PYATTRIBUTE_FLOAT_RW("size", 0.0001f, 10000.0f, KX_FontObject, m_fsize),
- KX_PYATTRIBUTE_FLOAT_RW("resolution", 0.0001f, 10000.0f, KX_FontObject, m_resolution),
- /* KX_PYATTRIBUTE_INT_RW("dpi", 0, 10000, false, KX_FontObject, m_dpi), */// no real need for expose this I think
- { NULL } //Sentinel
-};
-
-PyObject *KX_FontObject::pyattr_get_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_FontObject* self = static_cast<KX_FontObject*>(self_v);
- STR_String str = STR_String();
- for (int i=0; i<self->m_text.size(); ++i)
- {
- if (i!=0)
- str += '\n';
- str += self->m_text[i];
- }
- return PyUnicode_From_STR_String(str);
-}
-
-int KX_FontObject::pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_FontObject* self = static_cast<KX_FontObject*>(self_v);
- if (!PyUnicode_Check(value))
- return PY_SET_ATTR_FAIL;
- const char *chars = _PyUnicode_AsString(value);
-
- /* Allow for some logic brick control */
- CValue* tprop = self->GetProperty("Text");
- if (tprop) {
- CValue *newstringprop = new CStringValue(STR_String(chars), "Text");
- self->SetProperty("Text", newstringprop);
- newstringprop->Release();
- }
- else {
- self->m_text = split_string(STR_String(chars));
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_FontObject.h b/source/gameengine/Ketsji/KX_FontObject.h
deleted file mode 100644
index bf70eedfde6..00000000000
--- a/source/gameengine/Ketsji/KX_FontObject.h
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_FontObject.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_FONTOBJECT_H__
-#define __KX_FONTOBJECT_H__
-#include "KX_GameObject.h"
-
-class KX_FontObject : public KX_GameObject
-{
-public:
- Py_Header
- KX_FontObject(void* sgReplicationInfo,
- SG_Callbacks callbacks,
- RAS_IRasterizer* rasterizer,
- Object *ob,
- bool do_color_management);
-
- virtual ~KX_FontObject();
-
- void DrawFontText();
-
- /**
- * Inherited from CValue -- return a new copy of this
- * instance allocated on the heap. Ownership of the new
- * object belongs with the caller.
- */
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
- virtual int GetGameObjectType() { return OBJ_TEXT; }
-
-protected:
- std::vector<STR_String> m_text;
- Object* m_object;
- int m_fontid;
- int m_dpi;
- float m_fsize;
- float m_resolution;
- float m_color[4];
- float m_line_spacing;
- MT_Vector3 m_offset;
-
- class RAS_IRasterizer* m_rasterizer; //needed for drawing routine
-
- bool m_do_color_management;
-
-#ifdef WITH_PYTHON
- static PyObject* pyattr_get_text(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_text(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif
-
-};
-
-#endif /* __KX_FONTOBJECT_H__ */
diff --git a/source/gameengine/Ketsji/KX_GameActuator.cpp b/source/gameengine/Ketsji/KX_GameActuator.cpp
deleted file mode 100644
index f1bd253f8b3..00000000000
--- a/source/gameengine/Ketsji/KX_GameActuator.cpp
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * global game stuff
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_GameActuator.cpp
- * \ingroup ketsji
- */
-
-
-#include <stddef.h>
-
-#include "SCA_IActuator.h"
-#include "KX_GameActuator.h"
-//#include <iostream>
-#include "KX_Scene.h"
-#include "KX_KetsjiEngine.h"
-#include "KX_PythonInit.h" /* for config load/saving */
-#include "RAS_ICanvas.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_GameActuator::KX_GameActuator(SCA_IObject *gameobj,
- int mode,
- const STR_String& filename,
- const STR_String& loadinganimationname,
- SCA_IScene* scene,
- KX_KetsjiEngine* ketsjiengine)
- : SCA_IActuator(gameobj, KX_ACT_GAME)
-{
- m_mode = mode;
- m_filename = filename;
- m_loadinganimationname = loadinganimationname;
- m_scene = scene;
- m_ketsjiengine = ketsjiengine;
-} /* End of constructor */
-
-
-
-KX_GameActuator::~KX_GameActuator()
-{
- // there's nothing to be done here, really....
-} /* end of destructor */
-
-
-
-CValue* KX_GameActuator::GetReplica()
-{
- KX_GameActuator* replica = new KX_GameActuator(*this);
- replica->ProcessReplica();
-
- return replica;
-}
-
-
-
-bool KX_GameActuator::Update()
-{
- // bool result = false; /*unused*/
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- switch (m_mode)
- {
- case KX_GAME_LOAD:
- case KX_GAME_START:
- {
- if (m_ketsjiengine)
- {
- STR_String exitstring = "start other game";
- m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME);
- m_ketsjiengine->SetNameNextGame(m_filename);
- m_scene->AddDebugProperty((this)->GetParent(), exitstring);
- }
-
- break;
- }
- case KX_GAME_RESTART:
- {
- if (m_ketsjiengine)
- {
- STR_String exitstring = "restarting game";
- m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME);
- m_ketsjiengine->SetNameNextGame(m_filename);
- m_scene->AddDebugProperty((this)->GetParent(), exitstring);
- }
- break;
- }
- case KX_GAME_QUIT:
- {
- if (m_ketsjiengine)
- {
- STR_String exitstring = "quiting game";
- m_ketsjiengine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME);
- m_scene->AddDebugProperty((this)->GetParent(), exitstring);
- }
- break;
- }
- case KX_GAME_SAVECFG:
- {
-#ifdef WITH_PYTHON
- if (m_ketsjiengine)
- {
- char mashal_path[512];
- char *marshal_buffer = NULL;
- unsigned int marshal_length;
- FILE *fp = NULL;
-
- pathGamePythonConfig(mashal_path);
- marshal_length = saveGamePythonConfig(&marshal_buffer);
-
- if (marshal_length && marshal_buffer) {
- fp = fopen(mashal_path, "wb");
- if (fp) {
- if (fwrite(marshal_buffer, 1, marshal_length, fp) != marshal_length) {
- printf("Warning: could not write marshal data\n");
- }
- fclose(fp);
- } else {
- printf("Warning: could not open marshal file\n");
- }
- } else {
- printf("Warning: could not create marshal buffer\n");
- }
- if (marshal_buffer)
- delete [] marshal_buffer;
- }
- break;
-#endif // WITH_PYTHON
- }
- case KX_GAME_LOADCFG:
- {
-#ifdef WITH_PYTHON
- if (m_ketsjiengine)
- {
- char mashal_path[512];
- char *marshal_buffer;
- int marshal_length;
- FILE *fp = NULL;
- int result;
-
- pathGamePythonConfig(mashal_path);
-
- fp = fopen(mashal_path, "rb");
- if (fp) {
- // obtain file size:
- fseek (fp , 0 , SEEK_END);
- marshal_length = ftell(fp);
- if (marshal_length == -1) {
- printf("warning: could not read position of '%s'\n", mashal_path);
- fclose(fp);
- break;
- }
- rewind(fp);
-
- marshal_buffer = (char*) malloc (sizeof(char)*marshal_length);
-
- result = fread (marshal_buffer, 1, marshal_length, fp);
-
- if (result == marshal_length) {
- loadGamePythonConfig(marshal_buffer, marshal_length);
- } else {
- printf("warning: could not read all of '%s'\n", mashal_path);
- }
-
- free(marshal_buffer);
- fclose(fp);
- } else {
- printf("warning: could not open '%s'\n", mashal_path);
- }
- }
- break;
-#endif // WITH_PYTHON
- }
- case KX_GAME_SCREENSHOT:
- {
- RAS_ICanvas *canvas = m_ketsjiengine->GetCanvas();
- if (canvas) {
- canvas->MakeScreenShot(m_filename);
- }
- else {
- printf("KX_GAME_SCREENSHOT error: Rasterizer not available");
- }
- break;
- }
- default:
- ; /* do nothing? this is an internal error !!! */
- }
-
- return false;
-}
-
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_GameActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_GameActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_GameActuator::Methods[] =
-{
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_GameActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("fileName",0,100,false,KX_GameActuator,m_filename),
- KX_PYATTRIBUTE_INT_RW("mode", KX_GAME_NODEF+1, KX_GAME_MAX-1, true, KX_GameActuator, m_mode),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_GameActuator.h b/source/gameengine/Ketsji/KX_GameActuator.h
deleted file mode 100644
index 57472836bb2..00000000000
--- a/source/gameengine/Ketsji/KX_GameActuator.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_GameActuator.h
- * \ingroup ketsji
- * \brief actuator for global game stuff
- */
-
-#ifndef __KX_GAMEACTUATOR_H__
-#define __KX_GAMEACTUATOR_H__
-
-#include "SCA_IActuator.h"
-
-#include "SCA_IScene.h" /* Replace_IScene only */
-#include "KX_Scene.h" /* Replace_IScene only */
-
-class KX_GameActuator : public SCA_IActuator
-{
- Py_Header
-protected:
- int m_mode;
- bool m_restart;
- STR_String m_filename;
- STR_String m_loadinganimationname;
- class SCA_IScene* m_scene;
- class KX_KetsjiEngine* m_ketsjiengine;
-
- public:
- enum KX_GameActuatorMode
- {
- KX_GAME_NODEF = 0,
- KX_GAME_LOAD,
- KX_GAME_START,
- KX_GAME_RESTART,
- KX_GAME_QUIT,
- KX_GAME_SAVECFG,
- KX_GAME_LOADCFG,
- KX_GAME_SCREENSHOT,
- KX_GAME_MAX
-
- };
-
- KX_GameActuator(SCA_IObject* gameobj,
- int mode,
- const STR_String& filename,
- const STR_String& loadinganimationname,
- SCA_IScene* scene,
- KX_KetsjiEngine* ketsjiEngine);
- virtual ~KX_GameActuator();
-
- virtual CValue* GetReplica();
-
- virtual bool Update();
-
- virtual void Replace_IScene(SCA_IScene *val)
- {
- m_scene= val;
- };
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
-}; /* end of class KX_GameActuator */
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_GameObject.cpp b/source/gameengine/Ketsji/KX_GameObject.cpp
deleted file mode 100644
index 3244400e1bd..00000000000
--- a/source/gameengine/Ketsji/KX_GameObject.cpp
+++ /dev/null
@@ -1,4203 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Game object wrapper
- */
-
-/** \file gameengine/Ketsji/KX_GameObject.cpp
- * \ingroup ketsji
- */
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning( disable:4786 )
-#endif
-
-#include "RAS_IPolygonMaterial.h"
-#include "KX_BlenderMaterial.h"
-#include "KX_GameObject.h"
-#include "KX_Camera.h" // only for their ::Type
-#include "KX_Light.h" // only for their ::Type
-#include "KX_FontObject.h" // only for their ::Type
-#include "RAS_MeshObject.h"
-#include "KX_NavMeshObject.h"
-#include "KX_MeshProxy.h"
-#include "KX_PolyProxy.h"
-#include <stdio.h> // printf
-#include "SG_Controller.h"
-#include "PHY_IGraphicController.h"
-#include "SG_Node.h"
-#include "KX_ClientObjectInfo.h"
-#include "RAS_BucketManager.h"
-#include "KX_RayCast.h"
-#include "KX_PythonInit.h"
-#include "KX_PyMath.h"
-#include "SCA_IActuator.h"
-#include "SCA_ISensor.h"
-#include "SCA_IController.h"
-#include "NG_NetworkScene.h" //Needed for sendMessage()
-#include "KX_ObstacleSimulation.h"
-#include "KX_Scene.h"
-
-#include "BKE_object.h"
-
-#include "BL_ActionManager.h"
-#include "BL_Action.h"
-
-#include "EXP_PyObjectPlus.h" /* python stuff */
-#include "EXP_ListWrapper.h"
-#include "BLI_utildefines.h"
-
-#ifdef WITH_PYTHON
-# include "EXP_PythonCallBack.h"
-# include "python_utildefines.h"
-#endif
-
-// This file defines relationships between parents and children
-// in the game engine.
-
-#include "KX_SG_NodeRelationships.h"
-
-#include "BLI_math.h"
-
-static MT_Point3 dummy_point= MT_Point3(0.0f, 0.0f, 0.0f);
-static MT_Vector3 dummy_scaling = MT_Vector3(1.0f, 1.0f, 1.0f);
-static MT_Matrix3x3 dummy_orientation = MT_Matrix3x3(1.0f, 0.0f, 0.0f,
- 0.0f, 1.0f, 0.0f,
- 0.0f, 0.0f, 1.0f);
-
-KX_GameObject::KX_GameObject(
- void* sgReplicationInfo,
- SG_Callbacks callbacks)
- : SCA_IObject(),
- m_bDyna(false),
- m_layer(0),
- m_currentLodLevel(0),
- m_previousLodLevel(0),
- m_pBlenderObject(NULL),
- m_pBlenderGroupObject(NULL),
- m_bUseObjectColor(false),
- m_bIsNegativeScaling(false),
- m_objectColor(1.0f, 1.0f, 1.0f, 1.0f),
- m_bVisible(true),
- m_bCulled(true),
- m_bOccluder(false),
- m_pPhysicsController(NULL),
- m_pGraphicController(NULL),
- m_pObstacleSimulation(NULL),
- m_pInstanceObjects(NULL),
- m_pDupliGroupObject(NULL),
- m_actionManager(NULL),
- m_bRecordAnimation(false),
- m_isDeformable(false)
-
-#ifdef WITH_PYTHON
- , m_attr_dict(NULL),
- m_collisionCallbacks(NULL)
-#endif
-{
- m_ignore_activity_culling = false;
- m_pClient_info = new KX_ClientObjectInfo(this, KX_ClientObjectInfo::ACTOR);
- m_pSGNode = new SG_Node(this,sgReplicationInfo,callbacks);
-
- // define the relationship between this node and it's parent.
-
- KX_NormalParentRelation * parent_relation =
- KX_NormalParentRelation::New();
- m_pSGNode->SetParentRelation(parent_relation);
-};
-
-
-
-KX_GameObject::~KX_GameObject()
-{
-#ifdef WITH_PYTHON
- if (m_attr_dict) {
- PyDict_Clear(m_attr_dict); /* in case of circular refs or other weird cases */
- /* Py_CLEAR: Py_DECREF's and NULL's */
- Py_CLEAR(m_attr_dict);
- }
- // Unregister collision callbacks
- // Do this before we start freeing physics information like m_pClient_info
- if (m_collisionCallbacks) {
- UnregisterCollisionCallbacks();
- Py_CLEAR(m_collisionCallbacks);
- }
-#endif // WITH_PYTHON
-
- RemoveMeshes();
-
- // is this delete somewhere ?
- //if (m_sumoObj)
- // delete m_sumoObj;
- delete m_pClient_info;
- //if (m_pSGNode)
- // delete m_pSGNode;
- if (m_pSGNode)
- {
- // must go through controllers and make sure they will not use us anymore
- // This is important for KX_BulletPhysicsControllers that unregister themselves
- // from the object when they are deleted.
- SGControllerList::iterator contit;
- SGControllerList& controllers = m_pSGNode->GetSGControllerList();
- for (contit = controllers.begin();contit!=controllers.end();++contit)
- {
- (*contit)->ClearObject();
- }
- m_pSGNode->SetSGClientObject(NULL);
-
- /* m_pSGNode is freed in KX_Scene::RemoveNodeDestructObject */
- }
- if (m_pGraphicController)
- {
- delete m_pGraphicController;
- }
-
- if (m_pPhysicsController)
- {
- delete m_pPhysicsController;
- }
-
- if (m_pObstacleSimulation)
- {
- m_pObstacleSimulation->DestroyObstacleForObj(this);
- }
-
- if (m_actionManager)
- {
- delete m_actionManager;
- }
-
- if (m_pDupliGroupObject)
- {
- m_pDupliGroupObject->Release();
- }
-
- if (m_pInstanceObjects)
- {
- m_pInstanceObjects->Release();
- }
-}
-
-KX_GameObject* KX_GameObject::GetClientObject(KX_ClientObjectInfo *info)
-{
- if (!info)
- return NULL;
- return info->m_gameobject;
-}
-
-CValue* KX_GameObject:: Calc(VALUE_OPERATOR op, CValue *val)
-{
- return NULL;
-}
-
-
-
-CValue* KX_GameObject::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val)
-{
- return NULL;
-}
-
-
-
-const STR_String & KX_GameObject::GetText()
-{
- return m_text;
-}
-
-
-
-double KX_GameObject::GetNumber()
-{
- return 0;
-}
-
-
-
-STR_String& KX_GameObject::GetName()
-{
- return m_name;
-}
-
-
-/* Set the name of the value */
-void KX_GameObject::SetName(const char *name)
-{
- m_name = name;
-}
-
-PHY_IPhysicsController* KX_GameObject::GetPhysicsController()
-{
- return m_pPhysicsController;
-}
-
-KX_GameObject* KX_GameObject::GetDupliGroupObject()
-{
- return m_pDupliGroupObject;
-}
-
-CListValue* KX_GameObject::GetInstanceObjects()
-{
- return m_pInstanceObjects;
-}
-
-void KX_GameObject::AddInstanceObjects(KX_GameObject* obj)
-{
- if (!m_pInstanceObjects)
- m_pInstanceObjects = new CListValue();
-
- obj->AddRef();
- m_pInstanceObjects->Add(obj);
-}
-
-void KX_GameObject::RemoveInstanceObject(KX_GameObject* obj)
-{
- assert(m_pInstanceObjects);
- m_pInstanceObjects->RemoveValue(obj);
- obj->Release();
-}
-
-void KX_GameObject::RemoveDupliGroupObject()
-{
- if (m_pDupliGroupObject) {
- m_pDupliGroupObject->Release();
- m_pDupliGroupObject = NULL;
- }
-}
-
-void KX_GameObject::SetDupliGroupObject(KX_GameObject* obj)
-{
- obj->AddRef();
- m_pDupliGroupObject = obj;
-}
-
-void KX_GameObject::AddConstraint(bRigidBodyJointConstraint *cons)
-{
- m_constraints.push_back(cons);
-}
-
-std::vector<bRigidBodyJointConstraint*> KX_GameObject::GetConstraints()
-{
- return m_constraints;
-}
-
-void KX_GameObject::ClearConstraints()
-{
- m_constraints.clear();
-}
-
-KX_GameObject* KX_GameObject::GetParent()
-{
- KX_GameObject* result = NULL;
- SG_Node* node = m_pSGNode;
-
- while (node && !result)
- {
- node = node->GetSGParent();
- if (node)
- result = (KX_GameObject*)node->GetSGClientObject();
- }
-
- return result;
-
-}
-
-void KX_GameObject::SetParent(KX_Scene *scene, KX_GameObject* obj, bool addToCompound, bool ghost)
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (obj &&
- GetSGNode() && // object is not zombi
- obj->GetSGNode() && // object is not zombi
- GetSGNode()->GetSGParent() != obj->GetSGNode() && // not already parented to same object
- !GetSGNode()->IsAncessor(obj->GetSGNode()) && // no parenting loop
- this != obj) // not the object itself
- {
- // Make sure the objects have some scale
- MT_Vector3 scale1 = NodeGetWorldScaling();
- MT_Vector3 scale2 = obj->NodeGetWorldScaling();
- if (fabs(scale2[0]) < (MT_Scalar)FLT_EPSILON ||
- fabs(scale2[1]) < (MT_Scalar)FLT_EPSILON ||
- fabs(scale2[2]) < (MT_Scalar)FLT_EPSILON ||
- fabs(scale1[0]) < (MT_Scalar)FLT_EPSILON ||
- fabs(scale1[1]) < (MT_Scalar)FLT_EPSILON ||
- fabs(scale1[2]) < (MT_Scalar)FLT_EPSILON) { return; }
-
- // Remove us from our old parent and set our new parent
- RemoveParent(scene);
- obj->GetSGNode()->AddChild(GetSGNode());
-
- if (m_pPhysicsController)
- {
- m_pPhysicsController->SuspendDynamics(ghost);
- }
- // Set us to our new scale, position, and orientation
- scale2[0] = 1.0f/scale2[0];
- scale2[1] = 1.0f/scale2[1];
- scale2[2] = 1.0f/scale2[2];
- scale1 = scale1 * scale2;
- MT_Matrix3x3 invori = obj->NodeGetWorldOrientation().inverse();
- MT_Vector3 newpos = invori*(NodeGetWorldPosition()-obj->NodeGetWorldPosition())*scale2;
-
- NodeSetLocalScale(scale1);
- NodeSetLocalPosition(MT_Point3(newpos[0],newpos[1],newpos[2]));
- NodeSetLocalOrientation(invori*NodeGetWorldOrientation());
- NodeUpdateGS(0.f);
- // object will now be a child, it must be removed from the parent list
- CListValue* rootlist = scene->GetRootParentList();
- if (rootlist->RemoveValue(this))
- // the object was in parent list, decrement ref count as it's now removed
- Release();
- // if the new parent is a compound object, add this object shape to the compound shape.
- // step 0: verify this object has physical controller
- if (m_pPhysicsController && addToCompound)
- {
- // step 1: find the top parent (not necessarily obj)
- KX_GameObject* rootobj = (KX_GameObject*)obj->GetSGNode()->GetRootSGParent()->GetSGClientObject();
- // step 2: verify it has a physical controller and compound shape
- if (rootobj != NULL &&
- rootobj->m_pPhysicsController != NULL &&
- rootobj->m_pPhysicsController->IsCompound())
- {
- rootobj->m_pPhysicsController->AddCompoundChild(m_pPhysicsController);
- }
- }
- // graphically, the object hasn't change place, no need to update m_pGraphicController
- }
-}
-
-void KX_GameObject::RemoveParent(KX_Scene *scene)
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (GetSGNode() && GetSGNode()->GetSGParent())
- {
- // get the root object to remove us from compound object if needed
- KX_GameObject* rootobj = (KX_GameObject*)GetSGNode()->GetRootSGParent()->GetSGClientObject();
- // Set us to the right spot
- GetSGNode()->SetLocalScale(GetSGNode()->GetWorldScaling());
- GetSGNode()->SetLocalOrientation(GetSGNode()->GetWorldOrientation());
- GetSGNode()->SetLocalPosition(GetSGNode()->GetWorldPosition());
-
- // Remove us from our parent
- GetSGNode()->DisconnectFromParent();
- NodeUpdateGS(0.f);
- // the object is now a root object, add it to the parentlist
- CListValue* rootlist = scene->GetRootParentList();
- if (!rootlist->SearchValue(this))
- // object was not in root list, add it now and increment ref count
- rootlist->Add(AddRef());
- if (m_pPhysicsController)
- {
- // in case this controller was added as a child shape to the parent
- if (rootobj != NULL &&
- rootobj->m_pPhysicsController != NULL &&
- rootobj->m_pPhysicsController->IsCompound())
- {
- rootobj->m_pPhysicsController->RemoveCompoundChild(m_pPhysicsController);
- }
- m_pPhysicsController->RestoreDynamics();
- if (m_pPhysicsController->IsDynamic() && (rootobj != NULL && rootobj->m_pPhysicsController))
- {
- // dynamic object should remember the velocity they had while being parented
- MT_Point3 childPoint = GetSGNode()->GetWorldPosition();
- MT_Point3 rootPoint = rootobj->GetSGNode()->GetWorldPosition();
- MT_Point3 relPoint;
- relPoint = (childPoint-rootPoint);
- MT_Vector3 linVel = rootobj->m_pPhysicsController->GetVelocity(relPoint);
- MT_Vector3 angVel = rootobj->m_pPhysicsController->GetAngularVelocity();
- m_pPhysicsController->SetLinearVelocity(linVel, false);
- m_pPhysicsController->SetAngularVelocity(angVel, false);
- }
- }
- // graphically, the object hasn't change place, no need to update m_pGraphicController
- }
-}
-
-BL_ActionManager* KX_GameObject::GetActionManager()
-{
- // We only want to create an action manager if we need it
- if (!m_actionManager)
- {
- GetScene()->AddAnimatedObject(this);
- m_actionManager = new BL_ActionManager(this);
- }
- return m_actionManager;
-}
-
-bool KX_GameObject::PlayAction(const char* name,
- float start,
- float end,
- short layer,
- short priority,
- float blendin,
- short play_mode,
- float layer_weight,
- short ipo_flags,
- float playback_speed,
- short blend_mode)
-{
- return GetActionManager()->PlayAction(name, start, end, layer, priority, blendin, play_mode, layer_weight, ipo_flags, playback_speed, blend_mode);
-}
-
-void KX_GameObject::StopAction(short layer)
-{
- GetActionManager()->StopAction(layer);
-}
-
-void KX_GameObject::RemoveTaggedActions()
-{
- GetActionManager()->RemoveTaggedActions();
-}
-
-bool KX_GameObject::IsActionDone(short layer)
-{
- return GetActionManager()->IsActionDone(layer);
-}
-
-void KX_GameObject::UpdateActionManager(float curtime)
-{
- GetActionManager()->Update(curtime);
-}
-
-float KX_GameObject::GetActionFrame(short layer)
-{
- return GetActionManager()->GetActionFrame(layer);
-}
-
-const char *KX_GameObject::GetActionName(short layer)
-{
- return GetActionManager()->GetActionName(layer);
-}
-
-void KX_GameObject::SetActionFrame(short layer, float frame)
-{
- GetActionManager()->SetActionFrame(layer, frame);
-}
-
-bAction *KX_GameObject::GetCurrentAction(short layer)
-{
- return GetActionManager()->GetCurrentAction(layer);
-}
-
-void KX_GameObject::SetPlayMode(short layer, short mode)
-{
- GetActionManager()->SetPlayMode(layer, mode);
-}
-
-void KX_GameObject::SetTimes(short layer, float start, float end)
-{
- GetActionManager()->SetTimes(layer, start, end);
-}
-
-void KX_GameObject::ProcessReplica()
-{
- SCA_IObject::ProcessReplica();
-
- m_pGraphicController = NULL;
- m_pPhysicsController = NULL;
- m_pSGNode = NULL;
-
- /* Dupli group and instance list are set later in replication.
- * See KX_Scene::DupliGroupRecurse. */
- m_pDupliGroupObject = NULL;
- m_pInstanceObjects = NULL;
- m_pClient_info = new KX_ClientObjectInfo(*m_pClient_info);
- m_pClient_info->m_gameobject = this;
- m_actionManager = NULL;
- m_state = 0;
-
- KX_Scene* scene = KX_GetActiveScene();
- KX_ObstacleSimulation* obssimulation = scene->GetObstacleSimulation();
- struct Object* blenderobject = GetBlenderObject();
- if (obssimulation && (blenderobject->gameflag & OB_HASOBSTACLE))
- {
- obssimulation->AddObstacleForObj(this);
- }
-
-#ifdef WITH_PYTHON
- if (m_attr_dict)
- m_attr_dict= PyDict_Copy(m_attr_dict);
-#endif
-
-}
-
-static void setGraphicController_recursive(SG_Node* node)
-{
- NodeList& children = node->GetSGChildren();
-
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* childnode = (*childit);
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj != NULL) // This is a GameObject
- clientgameobj->ActivateGraphicController(false);
-
- // if the childobj is NULL then this may be an inverse parent link
- // so a non recursive search should still look down this node.
- setGraphicController_recursive(childnode);
- }
-}
-
-
-void KX_GameObject::ActivateGraphicController(bool recurse)
-{
- if (m_pGraphicController)
- {
- m_pGraphicController->Activate(m_bVisible);
- }
- if (recurse)
- {
- setGraphicController_recursive(GetSGNode());
- }
-}
-
-void KX_GameObject::SetUserCollisionGroup(unsigned short group)
-{
- m_userCollisionGroup = group;
- if (m_pPhysicsController)
- m_pPhysicsController->RefreshCollisions();
-}
-void KX_GameObject::SetUserCollisionMask(unsigned short mask)
-{
- m_userCollisionMask = mask;
- if (m_pPhysicsController)
- m_pPhysicsController->RefreshCollisions();
-}
-
-unsigned short KX_GameObject::GetUserCollisionGroup()
-{
- return m_userCollisionGroup;
-}
-unsigned short KX_GameObject::GetUserCollisionMask()
-{
- return m_userCollisionMask;
-}
-
-bool KX_GameObject::CheckCollision(KX_GameObject* other)
-{
- return this->m_userCollisionGroup & other->m_userCollisionMask;
-}
-
-CValue* KX_GameObject::GetReplica()
-{
- KX_GameObject* replica = new KX_GameObject(*this);
-
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-bool KX_GameObject::IsDynamicsSuspended() const
-{
- if (m_pPhysicsController)
- return m_pPhysicsController->IsSuspended();
- return false;
-}
-
-float KX_GameObject::getLinearDamping() const
-{
- if (m_pPhysicsController)
- return m_pPhysicsController->GetLinearDamping();
- return 0;
-}
-
-float KX_GameObject::getAngularDamping() const
-{
- if (m_pPhysicsController)
- return m_pPhysicsController->GetAngularDamping();
- return 0;
-}
-
-void KX_GameObject::setLinearDamping(float damping)
-{
- if (m_pPhysicsController)
- m_pPhysicsController->SetLinearDamping(damping);
-}
-
-
-void KX_GameObject::setAngularDamping(float damping)
-{
- if (m_pPhysicsController)
- m_pPhysicsController->SetAngularDamping(damping);
-}
-
-
-void KX_GameObject::setDamping(float linear, float angular)
-{
- if (m_pPhysicsController)
- m_pPhysicsController->SetDamping(linear, angular);
-}
-
-
-void KX_GameObject::ApplyForce(const MT_Vector3& force,bool local)
-{
- if (m_pPhysicsController)
- m_pPhysicsController->ApplyForce(force,local);
-}
-
-
-
-void KX_GameObject::ApplyTorque(const MT_Vector3& torque,bool local)
-{
- if (m_pPhysicsController)
- m_pPhysicsController->ApplyTorque(torque,local);
-}
-
-
-
-void KX_GameObject::ApplyMovement(const MT_Vector3& dloc,bool local)
-{
- if (GetSGNode())
- {
- if (m_pPhysicsController) // (IsDynamic())
- {
- m_pPhysicsController->RelativeTranslate(dloc,local);
- }
- GetSGNode()->RelativeTranslate(dloc,GetSGNode()->GetSGParent(),local);
- }
-}
-
-
-
-void KX_GameObject::ApplyRotation(const MT_Vector3& drot,bool local)
-{
- MT_Matrix3x3 rotmat(drot);
-
- if (GetSGNode()) {
- GetSGNode()->RelativeRotate(rotmat,local);
-
- if (m_pPhysicsController) { // (IsDynamic())
- m_pPhysicsController->RelativeRotate(rotmat,local);
- }
- }
-}
-
-
-
-/**
- * GetOpenGL Matrix, returns an OpenGL 'compatible' matrix
- */
-float *KX_GameObject::GetOpenGLMatrix()
-{
- // todo: optimize and only update if necessary
- float *fl = m_OpenGL_4x4Matrix.getPointer();
- if (GetSGNode()) {
- MT_Transform trans;
-
- trans.setOrigin(GetSGNode()->GetWorldPosition());
- trans.setBasis(GetSGNode()->GetWorldOrientation());
-
- MT_Vector3 scaling = GetSGNode()->GetWorldScaling();
- m_bIsNegativeScaling = ((scaling[0] < 0.0f) ^ (scaling[1] < 0.0f) ^ (scaling[2] < 0.0f)) ? true : false;
- trans.scale(scaling[0], scaling[1], scaling[2]);
- trans.getValue(fl);
- GetSGNode()->ClearDirty();
- }
- return fl;
-}
-
-void KX_GameObject::UpdateBlenderObjectMatrix(Object* blendobj)
-{
- if (!blendobj)
- blendobj = m_pBlenderObject;
- if (blendobj) {
- const MT_Matrix3x3& rot = NodeGetWorldOrientation();
- const MT_Vector3& scale = NodeGetWorldScaling();
- const MT_Vector3& pos = NodeGetWorldPosition();
- rot.getValue(blendobj->obmat[0]);
- pos.getValue(blendobj->obmat[3]);
- mul_v3_fl(blendobj->obmat[0], scale[0]);
- mul_v3_fl(blendobj->obmat[1], scale[1]);
- mul_v3_fl(blendobj->obmat[2], scale[2]);
- }
-}
-
-void KX_GameObject::AddMeshUser()
-{
- for (size_t i=0;i<m_meshes.size();i++)
- {
- m_meshes[i]->AddMeshUser(this, &m_meshSlots, GetDeformer());
- }
- // set the part of the mesh slot that never change
- float *fl = GetOpenGLMatrixPtr()->getPointer();
-
- SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
-// RAS_MeshSlot* ms;
- for (mit.begin(); !mit.end(); ++mit)
- {
- (*mit)->m_OpenGLMatrix = fl;
- }
- UpdateBuckets(false);
-}
-
-static void UpdateBuckets_recursive(SG_Node* node)
-{
- NodeList& children = node->GetSGChildren();
-
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* childnode = (*childit);
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj != NULL) // This is a GameObject
- clientgameobj->UpdateBuckets(0);
-
- // if the childobj is NULL then this may be an inverse parent link
- // so a non recursive search should still look down this node.
- UpdateBuckets_recursive(childnode);
- }
-}
-
-void KX_GameObject::UpdateBuckets( bool recursive )
-{
- if (GetSGNode()) {
- RAS_MeshSlot *ms;
-
- if (GetSGNode()->IsDirty())
- GetOpenGLMatrix();
-
- SG_QList::iterator<RAS_MeshSlot> mit(m_meshSlots);
- for (mit.begin(); !mit.end(); ++mit)
- {
- ms = *mit;
- ms->m_bObjectColor = m_bUseObjectColor;
- ms->m_RGBAcolor = m_objectColor;
- ms->m_bVisible = m_bVisible;
- ms->m_bCulled = m_bCulled || !m_bVisible;
- if (!ms->m_bCulled)
- ms->m_bucket->ActivateMesh(ms);
-
- /* split if necessary */
-#ifdef USE_SPLIT
- ms->Split();
-#endif
- }
-
- if (recursive) {
- UpdateBuckets_recursive(GetSGNode());
- }
- }
-}
-
-void KX_GameObject::RemoveMeshes()
-{
- for (size_t i=0;i<m_meshes.size();i++)
- m_meshes[i]->RemoveFromBuckets(this);
-
- //note: meshes can be shared, and are deleted by KX_BlenderSceneConverter
-
- m_meshes.clear();
-}
-
-void KX_GameObject::AddLodMesh(RAS_MeshObject* mesh)
-{
- m_lodmeshes.push_back(mesh);
-}
-
-
-static float calcHysteresis(KX_Scene *kxscene, LodLevel *lod)
-{
- float hystvariance = 0.0f;
-
- if (!kxscene->IsActivedLodHysteresis())
- return hystvariance;
-
- short hysteresis = 0;
- // if exists, LoD level hysteresis will override scene hysteresis
- if (lod->next->flags & OB_LOD_USE_HYST)
- hysteresis = lod->next->obhysteresis;
- else
- hysteresis = kxscene->GetLodHysteresisValue();
-
- return hystvariance = MT_abs(lod->next->distance - lod->distance) * hysteresis / 100;
-}
-
-void KX_GameObject::UpdateLod(MT_Vector3 &cam_pos)
-{
- // Handle dupligroups
- if (m_pInstanceObjects) {
- KX_GameObject *instob;
- int count = m_pInstanceObjects->GetCount();
- for (int i = 0; i < count; i++) {
- instob = (KX_GameObject*)m_pInstanceObjects->GetValue(i);
- instob->UpdateLod(cam_pos);
- }
- }
-
- if (m_lodmeshes.empty())
- return;
-
- MT_Vector3 delta = NodeGetWorldPosition() - cam_pos;
- float distance2 = delta.length2();
-
- int level = 0;
- float hystvariance = 0.0f;
- Object *bob = GetBlenderObject();
- LodLevel *lod = (LodLevel *)bob->lodlevels.first;
- KX_Scene *kxscene = GetScene();
-
- for (; lod; lod = lod->next, level++) {
- if (!lod->source || lod->source->type != OB_MESH)
- level--;
-
- if (!lod->next)
- break;
-
- if (level == m_previousLodLevel || level == (m_previousLodLevel + 1)) {
- hystvariance = calcHysteresis(kxscene, lod);
- float newdistance = lod->next->distance + hystvariance;
- if (newdistance * newdistance > distance2)
- break;
- }
- else if (level == (m_previousLodLevel - 1)) {
- hystvariance = calcHysteresis(kxscene, lod);
- float newdistance = lod->next->distance - hystvariance;
- if (newdistance * newdistance > distance2)
- break;
- }
- }
-
- RAS_MeshObject *mesh = m_lodmeshes[level];
- m_currentLodLevel = level;
- if (mesh != m_meshes[0]) {
- m_previousLodLevel = level;
- GetScene()->ReplaceMesh(this, mesh, true, false);
- }
-}
-
-void KX_GameObject::UpdateTransform()
-{
- // HACK: saves function call for dynamic object, they are handled differently
- if (m_pPhysicsController && !m_pPhysicsController->IsDynamic())
- m_pPhysicsController->SetTransform();
- if (m_pGraphicController)
- // update the culling tree
- m_pGraphicController->SetGraphicTransform();
-
-}
-
-void KX_GameObject::UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene)
-{
- ((KX_GameObject*)gameobj)->UpdateTransform();
-}
-
-void KX_GameObject::SynchronizeTransform()
-{
- // only used for sensor object, do full synchronization as bullet doesn't do it
- if (m_pPhysicsController)
- m_pPhysicsController->SetTransform();
- if (m_pGraphicController)
- m_pGraphicController->SetGraphicTransform();
-}
-
-void KX_GameObject::SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene)
-{
- ((KX_GameObject*)gameobj)->SynchronizeTransform();
-}
-
-
-void KX_GameObject::SetDebugColor(unsigned int bgra)
-{
- for (size_t i=0;i<m_meshes.size();i++)
- m_meshes[i]->DebugColor(bgra);
-}
-
-
-
-void KX_GameObject::ResetDebugColor()
-{
- SetDebugColor(0xff000000);
-}
-
-void KX_GameObject::InitIPO(bool ipo_as_force,
- bool ipo_add,
- bool ipo_local)
-{
- SGControllerList::iterator it = GetSGNode()->GetSGControllerList().begin();
-
- while (it != GetSGNode()->GetSGControllerList().end()) {
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_RESET, true);
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_AS_FORCE, ipo_as_force);
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_IPO_ADD, ipo_add);
- (*it)->SetOption(SG_Controller::SG_CONTR_IPO_LOCAL, ipo_local);
- it++;
- }
-}
-
-void KX_GameObject::UpdateIPO(float curframetime,
- bool recurse)
-{
- /* This function shouldn't call BL_Action::Update, not even indirectly,
- * as it will cause deadlock due to the lock in BL_Action::Update. */
-
- // just the 'normal' update procedure.
- GetSGNode()->SetSimulatedTime(curframetime,recurse);
- GetSGNode()->UpdateWorldData(curframetime);
- UpdateTransform();
-}
-
-// IPO update
-void
-KX_GameObject::UpdateMaterialData(
- dword matname_hash,
- MT_Vector4 rgba,
- MT_Vector3 specrgb,
- MT_Scalar hard,
- MT_Scalar spec,
- MT_Scalar ref,
- MT_Scalar emit,
- MT_Scalar alpha
-
- )
-{
- int mesh = 0;
- if (((unsigned int)mesh < m_meshes.size()) && mesh >= 0) {
- list<RAS_MeshMaterial>::iterator mit = m_meshes[mesh]->GetFirstMaterial();
-
- for (; mit != m_meshes[mesh]->GetLastMaterial(); ++mit)
- {
- RAS_IPolyMaterial* poly = mit->m_bucket->GetPolyMaterial();
-
- if (poly->GetFlag() & RAS_BLENDERMAT )
- {
- KX_BlenderMaterial *m = static_cast<KX_BlenderMaterial*>(poly);
-
- if (matname_hash == 0)
- {
- m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha);
- // if mesh has only one material attached to it then use original hack with no need to edit vertices (better performance)
- SetObjectColor(rgba);
- }
- else
- {
- if (matname_hash == poly->GetMaterialNameHash())
- {
- m->UpdateIPO(rgba, specrgb,hard,spec,ref,emit, alpha);
- m_meshes[mesh]->SetVertexColor(poly,rgba);
-
- // no break here, because one blender material can be split into several game engine materials
- // (e.g. one uvsphere material is split into one material at poles with ras_mode TRIANGLE and one material for the body
- // if here was a break then would miss some vertices if material was split
- }
- }
- }
- }
- }
-}
-bool
-KX_GameObject::GetVisible(
- void
- )
-{
- return m_bVisible;
-}
-
-static void setVisible_recursive(SG_Node* node, bool v)
-{
- NodeList& children = node->GetSGChildren();
-
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* childnode = (*childit);
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj != NULL) // This is a GameObject
- clientgameobj->SetVisible(v, 0);
-
- // if the childobj is NULL then this may be an inverse parent link
- // so a non recursive search should still look down this node.
- setVisible_recursive(childnode, v);
- }
-}
-
-
-void
-KX_GameObject::SetVisible(
- bool v,
- bool recursive
- )
-{
- if (GetSGNode()) {
- m_bVisible = v;
- if (m_pGraphicController)
- m_pGraphicController->Activate(m_bVisible);
- if (recursive)
- setVisible_recursive(GetSGNode(), v);
- }
-}
-
-static void setOccluder_recursive(SG_Node* node, bool v)
-{
- NodeList& children = node->GetSGChildren();
-
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* childnode = (*childit);
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj != NULL) // This is a GameObject
- clientgameobj->SetOccluder(v, false);
-
- // if the childobj is NULL then this may be an inverse parent link
- // so a non recursive search should still look down this node.
- setOccluder_recursive(childnode, v);
- }
-}
-
-void
-KX_GameObject::SetOccluder(
- bool v,
- bool recursive
- )
-{
- if (GetSGNode()) {
- m_bOccluder = v;
- if (recursive)
- setOccluder_recursive(GetSGNode(), v);
- }
-}
-
-static void setDebug_recursive(SG_Node *node, bool debug)
-{
- NodeList& children = node->GetSGChildren();
- KX_Scene *scene = KX_GetActiveScene();
-
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit) {
- SG_Node *childnode = (*childit);
- KX_GameObject *clientgameobj = static_cast<KX_GameObject*>( (*childit)->GetSGClientObject());
- if (clientgameobj != NULL) {
- if (debug) {
- if (!scene->ObjectInDebugList(clientgameobj))
- scene->AddObjectDebugProperties(clientgameobj);
- }
- else
- scene->RemoveObjectDebugProperties(clientgameobj);
- }
-
- /* if the childobj is NULL then this may be an inverse parent link
- * so a non recursive search should still look down this node. */
- setDebug_recursive(childnode, debug);
- }
-}
-
-void KX_GameObject::SetUseDebugProperties( bool debug, bool recursive )
-{
- KX_Scene *scene = KX_GetActiveScene();
-
- if (debug) {
- if (!scene->ObjectInDebugList(this))
- scene->AddObjectDebugProperties(this);
- }
- else
- scene->RemoveObjectDebugProperties(this);
-
- if (recursive)
- setDebug_recursive(GetSGNode(), debug);
-}
-
-void
-KX_GameObject::SetLayer(
- int l
- )
-{
- m_layer = l;
-}
-
-int
-KX_GameObject::GetLayer(
- void
- )
-{
- return m_layer;
-}
-
-void KX_GameObject::addLinearVelocity(const MT_Vector3& lin_vel,bool local)
-{
- if (m_pPhysicsController)
- {
- MT_Vector3 lv = local ? NodeGetWorldOrientation() * lin_vel : lin_vel;
- m_pPhysicsController->SetLinearVelocity(lv + m_pPhysicsController->GetLinearVelocity(), 0);
- }
-}
-
-
-
-void KX_GameObject::setLinearVelocity(const MT_Vector3& lin_vel,bool local)
-{
- if (m_pPhysicsController)
- m_pPhysicsController->SetLinearVelocity(lin_vel,local);
-}
-
-
-
-void KX_GameObject::setAngularVelocity(const MT_Vector3& ang_vel,bool local)
-{
- if (m_pPhysicsController)
- m_pPhysicsController->SetAngularVelocity(ang_vel,local);
-}
-
-
-void KX_GameObject::ResolveCombinedVelocities(
- const MT_Vector3 & lin_vel,
- const MT_Vector3 & ang_vel,
- bool lin_vel_local,
- bool ang_vel_local
-) {
- if (m_pPhysicsController)
- {
-
- MT_Vector3 lv = lin_vel_local ? NodeGetWorldOrientation() * lin_vel : lin_vel;
- MT_Vector3 av = ang_vel_local ? NodeGetWorldOrientation() * ang_vel : ang_vel;
- m_pPhysicsController->ResolveCombinedVelocities(
- lv.x(),lv.y(),lv.z(),av.x(),av.y(),av.z());
- }
-}
-
-
-void KX_GameObject::SetObjectColor(const MT_Vector4& rgbavec)
-{
- m_bUseObjectColor = true;
- m_objectColor = rgbavec;
-}
-
-const MT_Vector4& KX_GameObject::GetObjectColor()
-{
- return m_objectColor;
-}
-
-void KX_GameObject::AlignAxisToVect(const MT_Vector3& dir, int axis, float fac)
-{
- const MT_Scalar eps = 3.0f * MT_EPSILON;
- MT_Matrix3x3 orimat;
- MT_Vector3 vect,ori,z,x,y;
- MT_Scalar len;
-
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- vect = dir;
- len = vect.length();
- if (MT_fuzzyZero(len))
- {
- cout << "alignAxisToVect() Error: Null vector!\n";
- return;
- }
-
- if (fac <= 0.0f) {
- return;
- }
-
- // normalize
- vect /= len;
- orimat = GetSGNode()->GetWorldOrientation();
- switch (axis)
- {
- case 0: // align x axis of new coord system to vect
- ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]); // pivot axis
- if (1.0f - MT_abs(vect.dot(ori)) < eps) { // vect parallel to pivot?
- ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]); // change the pivot!
- }
-
- if (fac == 1.0f) {
- x = vect;
- } else {
- x = (vect * fac) + ((orimat * MT_Vector3(1.0f, 0.0f, 0.0f)) * (1.0f - fac));
- len = x.length();
- if (MT_fuzzyZero(len)) x = vect;
- else x /= len;
- }
- y = ori.cross(x);
- z = x.cross(y);
- break;
- case 1: // y axis
- ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]);
- if (1.0f - MT_abs(vect.dot(ori)) < eps) {
- ori.setValue(orimat[0][2], orimat[1][2], orimat[2][2]);
- }
-
- if (fac == 1.0f) {
- y = vect;
- } else {
- y = (vect * fac) + ((orimat * MT_Vector3(0.0f, 1.0f, 0.0f)) * (1.0f - fac));
- len = y.length();
- if (MT_fuzzyZero(len)) y = vect;
- else y /= len;
- }
- z = ori.cross(y);
- x = y.cross(z);
- break;
- case 2: // z axis
- ori.setValue(orimat[0][1], orimat[1][1], orimat[2][1]);
- if (1.0f - MT_abs(vect.dot(ori)) < eps) {
- ori.setValue(orimat[0][0], orimat[1][0], orimat[2][0]);
- }
-
- if (fac == 1.0f) {
- z = vect;
- } else {
- z = (vect * fac) + ((orimat * MT_Vector3(0.0f, 0.0f, 1.0f)) * (1.0f - fac));
- len = z.length();
- if (MT_fuzzyZero(len)) z = vect;
- else z /= len;
- }
- x = ori.cross(z);
- y = z.cross(x);
- break;
- default: // invalid axis specified
- cout << "alignAxisToVect(): Invalid axis '" << axis <<"'\n";
- return;
- }
- x.normalize(); // normalize the new base vectors
- y.normalize();
- z.normalize();
- orimat.setValue(x[0], y[0], z[0],
- x[1], y[1], z[1],
- x[2], y[2], z[2]);
-
- if (GetSGNode()->GetSGParent() != NULL)
- {
- // the object is a child, adapt its local orientation so that
- // the global orientation is aligned as we want (cancelling out the parent orientation)
- MT_Matrix3x3 invori = GetSGNode()->GetSGParent()->GetWorldOrientation().inverse();
- NodeSetLocalOrientation(invori*orimat);
- }
- else {
- NodeSetLocalOrientation(orimat);
- }
-}
-
-MT_Scalar KX_GameObject::GetMass()
-{
- if (m_pPhysicsController)
- {
- return m_pPhysicsController->GetMass();
- }
- return 0.0f;
-}
-
-MT_Vector3 KX_GameObject::GetLocalInertia()
-{
- MT_Vector3 local_inertia(0.0f,0.0f,0.0f);
- if (m_pPhysicsController)
- {
- local_inertia = m_pPhysicsController->GetLocalInertia();
- }
- return local_inertia;
-}
-
-MT_Vector3 KX_GameObject::GetLinearVelocity(bool local)
-{
- MT_Vector3 velocity(0.0f,0.0f,0.0f), locvel;
- MT_Matrix3x3 ori;
- if (m_pPhysicsController)
- {
- velocity = m_pPhysicsController->GetLinearVelocity();
-
- if (local)
- {
- ori = GetSGNode()->GetWorldOrientation();
-
- locvel = velocity * ori;
- return locvel;
- }
- }
- return velocity;
-}
-
-MT_Vector3 KX_GameObject::GetAngularVelocity(bool local)
-{
- MT_Vector3 velocity(0.0f,0.0f,0.0f), locvel;
- MT_Matrix3x3 ori;
- if (m_pPhysicsController)
- {
- velocity = m_pPhysicsController->GetAngularVelocity();
-
- if (local)
- {
- ori = GetSGNode()->GetWorldOrientation();
-
- locvel = velocity * ori;
- return locvel;
- }
- }
- return velocity;
-}
-
-MT_Vector3 KX_GameObject::GetVelocity(const MT_Point3& point)
-{
- if (m_pPhysicsController)
- {
- return m_pPhysicsController->GetVelocity(point);
- }
- return MT_Vector3(0.0f,0.0f,0.0f);
-}
-
-// scenegraph node stuff
-
-void KX_GameObject::NodeSetLocalPosition(const MT_Point3& trans)
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- if (m_pPhysicsController && !GetSGNode()->GetSGParent())
- {
- // don't update physic controller if the object is a child:
- // 1) the transformation will not be right
- // 2) in this case, the physic controller is necessarily a static object
- // that is updated from the normal kinematic synchronization
- m_pPhysicsController->SetPosition(trans);
- }
-
- GetSGNode()->SetLocalPosition(trans);
-
-}
-
-
-
-void KX_GameObject::NodeSetLocalOrientation(const MT_Matrix3x3& rot)
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- if (m_pPhysicsController && !GetSGNode()->GetSGParent())
- {
- // see note above
- m_pPhysicsController->SetOrientation(rot);
- }
- GetSGNode()->SetLocalOrientation(rot);
-}
-
-void KX_GameObject::NodeSetGlobalOrientation(const MT_Matrix3x3& rot)
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- if (GetSGNode()->GetSGParent())
- GetSGNode()->SetLocalOrientation(GetSGNode()->GetSGParent()->GetWorldOrientation().inverse()*rot);
- else
- NodeSetLocalOrientation(rot);
-}
-
-void KX_GameObject::NodeSetLocalScale(const MT_Vector3& scale)
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return;
-
- if (m_pPhysicsController && !GetSGNode()->GetSGParent())
- {
- // see note above
- m_pPhysicsController->SetScaling(scale);
- }
- GetSGNode()->SetLocalScale(scale);
-}
-
-
-
-void KX_GameObject::NodeSetRelativeScale(const MT_Vector3& scale)
-{
- if (GetSGNode())
- {
- GetSGNode()->RelativeScale(scale);
- if (m_pPhysicsController && (!GetSGNode()->GetSGParent()))
- {
- // see note above
- // we can use the local scale: it's the same thing for a root object
- // and the world scale is not yet updated
- MT_Vector3 newscale = GetSGNode()->GetLocalScale();
- m_pPhysicsController->SetScaling(newscale);
- }
- }
-}
-
-void KX_GameObject::NodeSetWorldScale(const MT_Vector3& scale)
-{
- if (!GetSGNode())
- return;
- SG_Node* parent = GetSGNode()->GetSGParent();
- if (parent != NULL)
- {
- // Make sure the objects have some scale
- MT_Vector3 p_scale = parent->GetWorldScaling();
- if (fabs(p_scale[0]) < (MT_Scalar)FLT_EPSILON ||
- fabs(p_scale[1]) < (MT_Scalar)FLT_EPSILON ||
- fabs(p_scale[2]) < (MT_Scalar)FLT_EPSILON)
- {
- return;
- }
-
- p_scale[0] = 1/p_scale[0];
- p_scale[1] = 1/p_scale[1];
- p_scale[2] = 1/p_scale[2];
-
- NodeSetLocalScale(scale * p_scale);
- }
- else
- {
- NodeSetLocalScale(scale);
- }
-}
-
-void KX_GameObject::NodeSetWorldPosition(const MT_Point3& trans)
-{
- if (!GetSGNode())
- return;
- SG_Node* parent = GetSGNode()->GetSGParent();
- if (parent != NULL)
- {
- // Make sure the objects have some scale
- MT_Vector3 scale = parent->GetWorldScaling();
- if (fabs(scale[0]) < (MT_Scalar)FLT_EPSILON ||
- fabs(scale[1]) < (MT_Scalar)FLT_EPSILON ||
- fabs(scale[2]) < (MT_Scalar)FLT_EPSILON)
- {
- return;
- }
- scale[0] = 1.0f/scale[0];
- scale[1] = 1.0f/scale[1];
- scale[2] = 1.0f/scale[2];
- MT_Matrix3x3 invori = parent->GetWorldOrientation().inverse();
- MT_Vector3 newpos = invori*(trans-parent->GetWorldPosition())*scale;
- NodeSetLocalPosition(MT_Point3(newpos[0],newpos[1],newpos[2]));
- }
- else
- {
- NodeSetLocalPosition(trans);
- }
-}
-
-
-void KX_GameObject::NodeUpdateGS(double time)
-{
- if (GetSGNode())
- GetSGNode()->UpdateWorldData(time);
-}
-
-
-
-const MT_Matrix3x3& KX_GameObject::NodeGetWorldOrientation() const
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return dummy_orientation;
- return GetSGNode()->GetWorldOrientation();
-}
-
-const MT_Matrix3x3& KX_GameObject::NodeGetLocalOrientation() const
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return dummy_orientation;
- return GetSGNode()->GetLocalOrientation();
-}
-
-const MT_Vector3& KX_GameObject::NodeGetWorldScaling() const
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return dummy_scaling;
-
- return GetSGNode()->GetWorldScaling();
-}
-
-const MT_Vector3& KX_GameObject::NodeGetLocalScaling() const
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (!GetSGNode())
- return dummy_scaling;
-
- return GetSGNode()->GetLocalScale();
-}
-
-const MT_Point3& KX_GameObject::NodeGetWorldPosition() const
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (GetSGNode())
- return GetSGNode()->GetWorldPosition();
- else
- return dummy_point;
-}
-
-const MT_Point3& KX_GameObject::NodeGetLocalPosition() const
-{
- // check on valid node in case a python controller holds a reference to a deleted object
- if (GetSGNode())
- return GetSGNode()->GetLocalPosition();
- else
- return dummy_point;
-}
-
-
-void KX_GameObject::UnregisterCollisionCallbacks()
-{
- if (!GetPhysicsController()) {
- printf("Warning, trying to unregister collision callbacks for object without collisions: %s!\n", GetName().ReadPtr());
- return;
- }
-
- // Unregister from callbacks
- KX_Scene* scene = GetScene();
- PHY_IPhysicsEnvironment* pe = scene->GetPhysicsEnvironment();
- PHY_IPhysicsController* spc = GetPhysicsController();
- // If we are the last to unregister on this physics controller
- if (pe->RemoveCollisionCallback(spc)) {
- // If we are a sensor object
- if (m_pClient_info->isSensor())
- // Remove sensor body from physics world
- pe->RemoveSensor(spc);
- }
-}
-
-void KX_GameObject::RegisterCollisionCallbacks()
-{
- if (!GetPhysicsController()) {
- printf("Warning, trying to register collision callbacks for object without collisions: %s!\n", GetName().ReadPtr());
- return;
- }
-
- // Register from callbacks
- KX_Scene* scene = GetScene();
- PHY_IPhysicsEnvironment* pe = scene->GetPhysicsEnvironment();
- PHY_IPhysicsController* spc = GetPhysicsController();
- // If we are the first to register on this physics controller
- if (pe->RequestCollisionCallback(spc)) {
- // If we are a sensor object
- if (m_pClient_info->isSensor())
- // Add sensor body to physics world
- pe->AddSensor(spc);
- }
-}
-void KX_GameObject::RunCollisionCallbacks(KX_GameObject *collider, const MT_Vector3 &point, const MT_Vector3 &normal)
-{
-#ifdef WITH_PYTHON
- if (!m_collisionCallbacks || PyList_GET_SIZE(m_collisionCallbacks) == 0)
- return;
-
- PyObject *args[] = {collider->GetProxy(), PyObjectFrom(point), PyObjectFrom(normal)};
- RunPythonCallBackList(m_collisionCallbacks, args, 1, ARRAY_SIZE(args));
-
- for (unsigned int i = 0; i < ARRAY_SIZE(args); ++i) {
- Py_DECREF(args[i]);
- }
-#endif
-}
-
-/* Suspend/ resume: for the dynamic behavior, there is a simple
- * method. For the residual motion, there is not. I wonder what the
- * correct solution is for Sumo. Remove from the motion-update tree?
- *
- * So far, only switch the physics and logic.
- * */
-
-void KX_GameObject::Resume(void)
-{
- if (m_suspended) {
- SCA_IObject::Resume();
- // Child objects must be static, so we block changing to dynamic
- if (GetPhysicsController() && !GetParent())
- GetPhysicsController()->RestoreDynamics();
-
- m_suspended = false;
- }
-}
-
-void KX_GameObject::Suspend()
-{
- if ((!m_ignore_activity_culling) && (!m_suspended)) {
- SCA_IObject::Suspend();
- if (GetPhysicsController())
- GetPhysicsController()->SuspendDynamics();
- m_suspended = true;
- }
-}
-
-static void walk_children(SG_Node* node, CListValue* list, bool recursive)
-{
- if (!node)
- return;
- NodeList& children = node->GetSGChildren();
-
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* childnode = (*childit);
- CValue* childobj = (CValue*)childnode->GetSGClientObject();
- if (childobj != NULL) // This is a GameObject
- {
- // add to the list
- list->Add(childobj->AddRef());
- }
-
- // if the childobj is NULL then this may be an inverse parent link
- // so a non recursive search should still look down this node.
- if (recursive || childobj==NULL) {
- walk_children(childnode, list, recursive);
- }
- }
-}
-
-CListValue* KX_GameObject::GetChildren()
-{
- CListValue* list = new CListValue();
- walk_children(GetSGNode(), list, 0); /* GetSGNode() is always valid or it would have raised an exception before this */
- return list;
-}
-
-CListValue* KX_GameObject::GetChildrenRecursive()
-{
- CListValue* list = new CListValue();
- walk_children(GetSGNode(), list, 1);
- return list;
-}
-
-KX_Scene* KX_GameObject::GetScene()
-{
- SG_Node* node = this->GetSGNode();
- if (node == NULL) {
- // this happens for object in non active layers, rely on static scene then
- return KX_GetActiveScene();
- }
- return static_cast<KX_Scene*>(node->GetSGClientInfo());
-}
-
-/* ---------------------------------------------------------------------
- * Some stuff taken from the header
- * --------------------------------------------------------------------- */
-void KX_GameObject::Relink(CTR_Map<CTR_HashedPtr, void*> *map_parameter)
-{
- // we will relink the sensors and actuators that use object references
- // if the object is part of the replicated hierarchy, use the new
- // object reference instead
- SCA_SensorList& sensorlist = GetSensors();
- SCA_SensorList::iterator sit;
- for (sit=sensorlist.begin(); sit != sensorlist.end(); sit++)
- {
- (*sit)->Relink(map_parameter);
- }
- SCA_ActuatorList& actuatorlist = GetActuators();
- SCA_ActuatorList::iterator ait;
- for (ait=actuatorlist.begin(); ait != actuatorlist.end(); ait++)
- {
- (*ait)->Relink(map_parameter);
- }
-}
-
-#ifdef USE_MATHUTILS
-
-/* These require an SGNode */
-#define MATHUTILS_VEC_CB_POS_LOCAL 1
-#define MATHUTILS_VEC_CB_POS_GLOBAL 2
-#define MATHUTILS_VEC_CB_SCALE_LOCAL 3
-#define MATHUTILS_VEC_CB_SCALE_GLOBAL 4
-#define MATHUTILS_VEC_CB_INERTIA_LOCAL 5
-#define MATHUTILS_VEC_CB_OBJECT_COLOR 6
-#define MATHUTILS_VEC_CB_LINVEL_LOCAL 7
-#define MATHUTILS_VEC_CB_LINVEL_GLOBAL 8
-#define MATHUTILS_VEC_CB_ANGVEL_LOCAL 9
-#define MATHUTILS_VEC_CB_ANGVEL_GLOBAL 10
-
-static unsigned char mathutils_kxgameob_vector_cb_index= -1; /* index for our callbacks */
-
-static int mathutils_kxgameob_generic_check(BaseMathObject *bmo)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- return 0;
-}
-
-static int mathutils_kxgameob_vector_get(BaseMathObject *bmo, int subtype)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
-#define PHYS_ERR(attr) PyErr_SetString(PyExc_AttributeError, "KX_GameObject." attr ", is missing a physics controller")
-
- switch (subtype) {
- case MATHUTILS_VEC_CB_POS_LOCAL:
- self->NodeGetLocalPosition().getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_POS_GLOBAL:
- self->NodeGetWorldPosition().getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_SCALE_LOCAL:
- self->NodeGetLocalScaling().getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_SCALE_GLOBAL:
- self->NodeGetWorldScaling().getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_INERTIA_LOCAL:
- if (!self->GetPhysicsController()) return PHYS_ERR("localInertia"), -1;
- self->GetPhysicsController()->GetLocalInertia().getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_OBJECT_COLOR:
- self->GetObjectColor().getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_LINVEL_LOCAL:
- if (!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), -1;
- self->GetLinearVelocity(true).getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_LINVEL_GLOBAL:
- if (!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), -1;
- self->GetLinearVelocity(false).getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_ANGVEL_LOCAL:
- if (!self->GetPhysicsController()) return PHYS_ERR("localLinearVelocity"), -1;
- self->GetAngularVelocity(true).getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_ANGVEL_GLOBAL:
- if (!self->GetPhysicsController()) return PHYS_ERR("worldLinearVelocity"), -1;
- self->GetAngularVelocity(false).getValue(bmo->data);
- break;
-
- }
-
-#undef PHYS_ERR
-
- return 0;
-}
-
-static int mathutils_kxgameob_vector_set(BaseMathObject *bmo, int subtype)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_VEC_CB_POS_LOCAL:
- self->NodeSetLocalPosition(MT_Point3(bmo->data));
- self->NodeUpdateGS(0.f);
- break;
- case MATHUTILS_VEC_CB_POS_GLOBAL:
- self->NodeSetWorldPosition(MT_Point3(bmo->data));
- self->NodeUpdateGS(0.f);
- break;
- case MATHUTILS_VEC_CB_SCALE_LOCAL:
- self->NodeSetLocalScale(MT_Point3(bmo->data));
- self->NodeUpdateGS(0.f);
- break;
- case MATHUTILS_VEC_CB_SCALE_GLOBAL:
- PyErr_SetString(PyExc_AttributeError, "KX_GameObject.worldScale is read-only");
- return -1;
- case MATHUTILS_VEC_CB_INERTIA_LOCAL:
- /* read only */
- break;
- case MATHUTILS_VEC_CB_OBJECT_COLOR:
- self->SetObjectColor(MT_Vector4(bmo->data));
- break;
- case MATHUTILS_VEC_CB_LINVEL_LOCAL:
- self->setLinearVelocity(MT_Point3(bmo->data),true);
- break;
- case MATHUTILS_VEC_CB_LINVEL_GLOBAL:
- self->setLinearVelocity(MT_Point3(bmo->data),false);
- break;
- case MATHUTILS_VEC_CB_ANGVEL_LOCAL:
- self->setAngularVelocity(MT_Point3(bmo->data),true);
- break;
- case MATHUTILS_VEC_CB_ANGVEL_GLOBAL:
- self->setAngularVelocity(MT_Point3(bmo->data),false);
- break;
- }
-
- return 0;
-}
-
-static int mathutils_kxgameob_vector_get_index(BaseMathObject *bmo, int subtype, int index)
-{
- /* lazy, avoid repeteing the case statement */
- if (mathutils_kxgameob_vector_get(bmo, subtype) == -1)
- return -1;
- return 0;
-}
-
-static int mathutils_kxgameob_vector_set_index(BaseMathObject *bmo, int subtype, int index)
-{
- float f= bmo->data[index];
-
- /* lazy, avoid repeteing the case statement */
- if (mathutils_kxgameob_vector_get(bmo, subtype) == -1)
- return -1;
-
- bmo->data[index] = f;
- return mathutils_kxgameob_vector_set(bmo, subtype);
-}
-
-static Mathutils_Callback mathutils_kxgameob_vector_cb = {
- mathutils_kxgameob_generic_check,
- mathutils_kxgameob_vector_get,
- mathutils_kxgameob_vector_set,
- mathutils_kxgameob_vector_get_index,
- mathutils_kxgameob_vector_set_index
-};
-
-/* Matrix */
-#define MATHUTILS_MAT_CB_ORI_LOCAL 1
-#define MATHUTILS_MAT_CB_ORI_GLOBAL 2
-
-static unsigned char mathutils_kxgameob_matrix_cb_index= -1; /* index for our callbacks */
-
-static int mathutils_kxgameob_matrix_get(BaseMathObject *bmo, int subtype)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_MAT_CB_ORI_LOCAL:
- self->NodeGetLocalOrientation().getValue3x3(bmo->data);
- break;
- case MATHUTILS_MAT_CB_ORI_GLOBAL:
- self->NodeGetWorldOrientation().getValue3x3(bmo->data);
- break;
- }
-
- return 0;
-}
-
-
-static int mathutils_kxgameob_matrix_set(BaseMathObject *bmo, int subtype)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- MT_Matrix3x3 mat3x3;
- switch (subtype) {
- case MATHUTILS_MAT_CB_ORI_LOCAL:
- mat3x3.setValue3x3(bmo->data);
- self->NodeSetLocalOrientation(mat3x3);
- self->NodeUpdateGS(0.f);
- break;
- case MATHUTILS_MAT_CB_ORI_GLOBAL:
- mat3x3.setValue3x3(bmo->data);
- self->NodeSetLocalOrientation(mat3x3);
- self->NodeUpdateGS(0.f);
- break;
- }
-
- return 0;
-}
-
-static Mathutils_Callback mathutils_kxgameob_matrix_cb = {
- mathutils_kxgameob_generic_check,
- mathutils_kxgameob_matrix_get,
- mathutils_kxgameob_matrix_set,
- NULL,
- NULL
-};
-
-
-void KX_GameObject_Mathutils_Callback_Init(void)
-{
- // register mathutils callbacks, ok to run more than once.
- mathutils_kxgameob_vector_cb_index= Mathutils_RegisterCallback(&mathutils_kxgameob_vector_cb);
- mathutils_kxgameob_matrix_cb_index= Mathutils_RegisterCallback(&mathutils_kxgameob_matrix_cb);
-}
-
-#endif // USE_MATHUTILS
-
-#ifdef WITH_PYTHON
-/* ------- python stuff ---------------------------------------------------*/
-PyMethodDef KX_GameObject::Methods[] = {
- {"applyForce", (PyCFunction) KX_GameObject::sPyApplyForce, METH_VARARGS},
- {"applyTorque", (PyCFunction) KX_GameObject::sPyApplyTorque, METH_VARARGS},
- {"applyRotation", (PyCFunction) KX_GameObject::sPyApplyRotation, METH_VARARGS},
- {"applyMovement", (PyCFunction) KX_GameObject::sPyApplyMovement, METH_VARARGS},
- {"getLinearVelocity", (PyCFunction) KX_GameObject::sPyGetLinearVelocity, METH_VARARGS},
- {"setLinearVelocity", (PyCFunction) KX_GameObject::sPySetLinearVelocity, METH_VARARGS},
- {"getAngularVelocity", (PyCFunction) KX_GameObject::sPyGetAngularVelocity, METH_VARARGS},
- {"setAngularVelocity", (PyCFunction) KX_GameObject::sPySetAngularVelocity, METH_VARARGS},
- {"getVelocity", (PyCFunction) KX_GameObject::sPyGetVelocity, METH_VARARGS},
- {"setDamping", (PyCFunction) KX_GameObject::sPySetDamping, METH_VARARGS},
- {"getReactionForce", (PyCFunction) KX_GameObject::sPyGetReactionForce, METH_NOARGS},
- {"alignAxisToVect",(PyCFunction) KX_GameObject::sPyAlignAxisToVect, METH_VARARGS},
- {"getAxisVect",(PyCFunction) KX_GameObject::sPyGetAxisVect, METH_O},
- {"suspendDynamics", (PyCFunction)KX_GameObject::sPySuspendDynamics, METH_VARARGS},
- {"restoreDynamics", (PyCFunction)KX_GameObject::sPyRestoreDynamics,METH_NOARGS},
- {"enableRigidBody", (PyCFunction)KX_GameObject::sPyEnableRigidBody,METH_NOARGS},
- {"disableRigidBody", (PyCFunction)KX_GameObject::sPyDisableRigidBody,METH_NOARGS},
- {"applyImpulse", (PyCFunction) KX_GameObject::sPyApplyImpulse, METH_VARARGS},
- {"setCollisionMargin", (PyCFunction) KX_GameObject::sPySetCollisionMargin, METH_O},
- {"setParent", (PyCFunction)KX_GameObject::sPySetParent,METH_VARARGS},
- {"setVisible",(PyCFunction) KX_GameObject::sPySetVisible, METH_VARARGS},
- {"setOcclusion",(PyCFunction) KX_GameObject::sPySetOcclusion, METH_VARARGS},
- {"removeParent", (PyCFunction)KX_GameObject::sPyRemoveParent,METH_NOARGS},
-
-
- {"getPhysicsId", (PyCFunction)KX_GameObject::sPyGetPhysicsId,METH_NOARGS},
- {"getPropertyNames", (PyCFunction)KX_GameObject::sPyGetPropertyNames,METH_NOARGS},
- {"replaceMesh",(PyCFunction) KX_GameObject::sPyReplaceMesh, METH_VARARGS},
- {"endObject",(PyCFunction) KX_GameObject::sPyEndObject, METH_NOARGS},
- {"reinstancePhysicsMesh", (PyCFunction)KX_GameObject::sPyReinstancePhysicsMesh,METH_VARARGS},
-
- KX_PYMETHODTABLE(KX_GameObject, rayCastTo),
- KX_PYMETHODTABLE(KX_GameObject, rayCast),
- KX_PYMETHODTABLE_O(KX_GameObject, getDistanceTo),
- KX_PYMETHODTABLE_O(KX_GameObject, getVectTo),
- KX_PYMETHODTABLE(KX_GameObject, sendMessage),
- KX_PYMETHODTABLE(KX_GameObject, addDebugProperty),
-
- KX_PYMETHODTABLE_KEYWORDS(KX_GameObject, playAction),
- KX_PYMETHODTABLE(KX_GameObject, stopAction),
- KX_PYMETHODTABLE(KX_GameObject, getActionFrame),
- KX_PYMETHODTABLE(KX_GameObject, getActionName),
- KX_PYMETHODTABLE(KX_GameObject, setActionFrame),
- KX_PYMETHODTABLE(KX_GameObject, isPlayingAction),
-
- // dict style access for props
- {"get",(PyCFunction) KX_GameObject::sPyget, METH_VARARGS},
-
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_GameObject::Attributes[] = {
- KX_PYATTRIBUTE_INT_RO("currentLodLevel", KX_GameObject, m_currentLodLevel),
- KX_PYATTRIBUTE_RO_FUNCTION("name", KX_GameObject, pyattr_get_name),
- KX_PYATTRIBUTE_RO_FUNCTION("parent", KX_GameObject, pyattr_get_parent),
- KX_PYATTRIBUTE_RO_FUNCTION("groupMembers", KX_GameObject, pyattr_get_group_members),
- KX_PYATTRIBUTE_RO_FUNCTION("groupObject", KX_GameObject, pyattr_get_group_object),
- KX_PYATTRIBUTE_RO_FUNCTION("scene", KX_GameObject, pyattr_get_scene),
- KX_PYATTRIBUTE_RO_FUNCTION("life", KX_GameObject, pyattr_get_life),
- KX_PYATTRIBUTE_RW_FUNCTION("mass", KX_GameObject, pyattr_get_mass, pyattr_set_mass),
- KX_PYATTRIBUTE_RO_FUNCTION("isSuspendDynamics", KX_GameObject, pyattr_get_is_suspend_dynamics),
- KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMin", KX_GameObject, pyattr_get_lin_vel_min, pyattr_set_lin_vel_min),
- KX_PYATTRIBUTE_RW_FUNCTION("linVelocityMax", KX_GameObject, pyattr_get_lin_vel_max, pyattr_set_lin_vel_max),
- KX_PYATTRIBUTE_RW_FUNCTION("angularVelocityMin", KX_GameObject, pyattr_get_ang_vel_min, pyattr_set_ang_vel_min),
- KX_PYATTRIBUTE_RW_FUNCTION("angularVelocityMax", KX_GameObject, pyattr_get_ang_vel_max, pyattr_set_ang_vel_max),
- KX_PYATTRIBUTE_RW_FUNCTION("visible", KX_GameObject, pyattr_get_visible, pyattr_set_visible),
- KX_PYATTRIBUTE_RW_FUNCTION("record_animation", KX_GameObject, pyattr_get_record_animation, pyattr_set_record_animation),
- KX_PYATTRIBUTE_BOOL_RW ("occlusion", KX_GameObject, m_bOccluder),
- KX_PYATTRIBUTE_RW_FUNCTION("position", KX_GameObject, pyattr_get_worldPosition, pyattr_set_localPosition),
- KX_PYATTRIBUTE_RO_FUNCTION("localInertia", KX_GameObject, pyattr_get_localInertia),
- KX_PYATTRIBUTE_RW_FUNCTION("orientation",KX_GameObject,pyattr_get_worldOrientation,pyattr_set_localOrientation),
- KX_PYATTRIBUTE_RW_FUNCTION("scaling", KX_GameObject, pyattr_get_worldScaling, pyattr_set_localScaling),
- KX_PYATTRIBUTE_RW_FUNCTION("timeOffset",KX_GameObject, pyattr_get_timeOffset,pyattr_set_timeOffset),
- KX_PYATTRIBUTE_RW_FUNCTION("collisionCallbacks", KX_GameObject, pyattr_get_collisionCallbacks, pyattr_set_collisionCallbacks),
- KX_PYATTRIBUTE_RW_FUNCTION("collisionGroup", KX_GameObject, pyattr_get_collisionGroup, pyattr_set_collisionGroup),
- KX_PYATTRIBUTE_RW_FUNCTION("collisionMask", KX_GameObject, pyattr_get_collisionMask, pyattr_set_collisionMask),
- KX_PYATTRIBUTE_RW_FUNCTION("state", KX_GameObject, pyattr_get_state, pyattr_set_state),
- KX_PYATTRIBUTE_RO_FUNCTION("meshes", KX_GameObject, pyattr_get_meshes),
- KX_PYATTRIBUTE_RW_FUNCTION("localOrientation",KX_GameObject,pyattr_get_localOrientation,pyattr_set_localOrientation),
- KX_PYATTRIBUTE_RW_FUNCTION("worldOrientation",KX_GameObject,pyattr_get_worldOrientation,pyattr_set_worldOrientation),
- KX_PYATTRIBUTE_RW_FUNCTION("localPosition", KX_GameObject, pyattr_get_localPosition, pyattr_set_localPosition),
- KX_PYATTRIBUTE_RW_FUNCTION("worldPosition", KX_GameObject, pyattr_get_worldPosition, pyattr_set_worldPosition),
- KX_PYATTRIBUTE_RW_FUNCTION("localScale", KX_GameObject, pyattr_get_localScaling, pyattr_set_localScaling),
- KX_PYATTRIBUTE_RW_FUNCTION("worldScale", KX_GameObject, pyattr_get_worldScaling, pyattr_set_worldScaling),
- KX_PYATTRIBUTE_RW_FUNCTION("localTransform", KX_GameObject, pyattr_get_localTransform, pyattr_set_localTransform),
- KX_PYATTRIBUTE_RW_FUNCTION("worldTransform", KX_GameObject, pyattr_get_worldTransform, pyattr_set_worldTransform),
- KX_PYATTRIBUTE_RW_FUNCTION("linearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_worldLinearVelocity),
- KX_PYATTRIBUTE_RW_FUNCTION("localLinearVelocity", KX_GameObject, pyattr_get_localLinearVelocity, pyattr_set_localLinearVelocity),
- KX_PYATTRIBUTE_RW_FUNCTION("worldLinearVelocity", KX_GameObject, pyattr_get_worldLinearVelocity, pyattr_set_worldLinearVelocity),
- KX_PYATTRIBUTE_RW_FUNCTION("angularVelocity", KX_GameObject, pyattr_get_localAngularVelocity, pyattr_set_worldAngularVelocity),
- KX_PYATTRIBUTE_RW_FUNCTION("localAngularVelocity", KX_GameObject, pyattr_get_localAngularVelocity, pyattr_set_localAngularVelocity),
- KX_PYATTRIBUTE_RW_FUNCTION("worldAngularVelocity", KX_GameObject, pyattr_get_worldAngularVelocity, pyattr_set_worldAngularVelocity),
- KX_PYATTRIBUTE_RW_FUNCTION("linearDamping", KX_GameObject, pyattr_get_linearDamping, pyattr_set_linearDamping),
- KX_PYATTRIBUTE_RW_FUNCTION("angularDamping", KX_GameObject, pyattr_get_angularDamping, pyattr_set_angularDamping),
- KX_PYATTRIBUTE_RO_FUNCTION("children", KX_GameObject, pyattr_get_children),
- KX_PYATTRIBUTE_RO_FUNCTION("childrenRecursive", KX_GameObject, pyattr_get_children_recursive),
- KX_PYATTRIBUTE_RO_FUNCTION("attrDict", KX_GameObject, pyattr_get_attrDict),
- KX_PYATTRIBUTE_RW_FUNCTION("color", KX_GameObject, pyattr_get_obcolor, pyattr_set_obcolor),
- KX_PYATTRIBUTE_RW_FUNCTION("debug", KX_GameObject, pyattr_get_debug, pyattr_set_debug),
- KX_PYATTRIBUTE_RW_FUNCTION("debugRecursive", KX_GameObject, pyattr_get_debugRecursive, pyattr_set_debugRecursive),
-
- /* experimental, don't rely on these yet */
- KX_PYATTRIBUTE_RO_FUNCTION("sensors", KX_GameObject, pyattr_get_sensors),
- KX_PYATTRIBUTE_RO_FUNCTION("controllers", KX_GameObject, pyattr_get_controllers),
- KX_PYATTRIBUTE_RO_FUNCTION("actuators", KX_GameObject, pyattr_get_actuators),
- {NULL} //Sentinel
-};
-
-PyObject *KX_GameObject::PyReplaceMesh(PyObject *args)
-{
- KX_Scene *scene = KX_GetActiveScene();
- SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
-
- PyObject *value;
- int use_gfx= 1, use_phys= 0;
- RAS_MeshObject *new_mesh;
-
- if (!PyArg_ParseTuple(args,"O|ii:replaceMesh", &value, &use_gfx, &use_phys))
- return NULL;
-
- if (!ConvertPythonToMesh(logicmgr, value, &new_mesh, false, "gameOb.replaceMesh(value): KX_GameObject"))
- return NULL;
-
- scene->ReplaceMesh(this, new_mesh, (bool)use_gfx, (bool)use_phys);
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::PyEndObject()
-{
- KX_Scene* scene = GetScene();
-
- scene->DelayedRemoveObject(this);
-
- Py_RETURN_NONE;
-
-}
-
-PyObject *KX_GameObject::PyReinstancePhysicsMesh(PyObject *args)
-{
- KX_GameObject *gameobj= NULL;
- RAS_MeshObject *mesh= NULL;
- SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
-
- PyObject *gameobj_py= NULL;
- PyObject *mesh_py= NULL;
-
- if ( !PyArg_ParseTuple(args,"|OO:reinstancePhysicsMesh",&gameobj_py, &mesh_py) ||
- (gameobj_py && !ConvertPythonToGameObject(logicmgr, gameobj_py, &gameobj, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject")) ||
- (mesh_py && !ConvertPythonToMesh(logicmgr, mesh_py, &mesh, true, "gameOb.reinstancePhysicsMesh(obj, mesh): KX_GameObject"))
- ) {
- return NULL;
- }
-
- /* gameobj and mesh can be NULL */
- if (GetPhysicsController() && GetPhysicsController()->ReinstancePhysicsShape(gameobj, mesh))
- Py_RETURN_TRUE;
-
- Py_RETURN_FALSE;
-}
-
-static PyObject *Map_GetItem(PyObject *self_v, PyObject *item)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(self_v);
- const char *attr_str= _PyUnicode_AsString(item);
- CValue* resultattr;
- PyObject *pyconvert;
-
- if (self == NULL) {
- PyErr_SetString(PyExc_SystemError, "val = gameOb[key]: KX_GameObject, " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- /* first see if the attributes a string and try get the cvalue attribute */
- if (attr_str && (resultattr=self->GetProperty(attr_str))) {
- pyconvert = resultattr->ConvertValueToPython();
- return pyconvert ? pyconvert:resultattr->GetProxy();
- }
- /* no CValue attribute, try get the python only m_attr_dict attribute */
- else if (self->m_attr_dict && (pyconvert=PyDict_GetItem(self->m_attr_dict, item))) {
-
- if (attr_str)
- PyErr_Clear();
- Py_INCREF(pyconvert);
- return pyconvert;
- }
- else {
- if (attr_str) PyErr_Format(PyExc_KeyError, "value = gameOb[key]: KX_GameObject, key \"%s\" does not exist", attr_str);
- else PyErr_SetString(PyExc_KeyError, "value = gameOb[key]: KX_GameObject, key does not exist");
- return NULL;
- }
-
-}
-
-
-static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(self_v);
- const char *attr_str= _PyUnicode_AsString(key);
- if (attr_str==NULL)
- PyErr_Clear();
-
- if (self == NULL) {
- PyErr_SetString(PyExc_SystemError, "gameOb[key] = value: KX_GameObject, " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (val==NULL) { /* del ob["key"] */
- int del= 0;
-
- /* try remove both just in case */
- if (attr_str)
- del |= (self->RemoveProperty(attr_str)==true) ? 1:0;
-
- if (self->m_attr_dict)
- del |= (PyDict_DelItem(self->m_attr_dict, key)==0) ? 1:0;
-
- if (del==0) {
- if (attr_str) PyErr_Format(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key \"%s\" could not be set", attr_str);
- else PyErr_SetString(PyExc_KeyError, "del gameOb[key]: KX_GameObject, key could not be deleted");
- return -1;
- }
- else if (self->m_attr_dict) {
- PyErr_Clear(); /* PyDict_DelItem sets an error when it fails */
- }
- }
- else { /* ob["key"] = value */
- bool set = false;
-
- /* as CValue */
- if (attr_str && PyObject_TypeCheck(val, &PyObjectPlus::Type)==0) /* don't allow GameObjects for eg to be assigned to CValue props */
- {
- CValue *vallie = self->ConvertPythonToValue(val, false, "gameOb[key] = value: ");
-
- if (vallie) {
- CValue* oldprop = self->GetProperty(attr_str);
-
- if (oldprop)
- oldprop->SetValue(vallie);
- else
- self->SetProperty(attr_str, vallie);
-
- vallie->Release();
- set = true;
-
- /* try remove dict value to avoid double ups */
- if (self->m_attr_dict) {
- if (PyDict_DelItem(self->m_attr_dict, key) != 0)
- PyErr_Clear();
- }
- }
- else if (PyErr_Occurred()) {
- return -1;
- }
- }
-
- if (set == false) {
- if (self->m_attr_dict==NULL) /* lazy init */
- self->m_attr_dict= PyDict_New();
-
-
- if (PyDict_SetItem(self->m_attr_dict, key, val)==0)
- {
- if (attr_str)
- self->RemoveProperty(attr_str); /* overwrite the CValue if it exists */
- set = true;
- }
- else {
- if (attr_str) PyErr_Format(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key \"%s\" not be added to internal dictionary", attr_str);
- else PyErr_SetString(PyExc_KeyError, "gameOb[key] = value: KX_GameObject, key not be added to internal dictionary");
- }
- }
-
- if (set == false) {
- return -1; /* pythons error value */
- }
-
- }
-
- return 0; /* success */
-}
-
-static int Seq_Contains(PyObject *self_v, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>BGE_PROXY_REF(self_v);
-
- if (self == NULL) {
- PyErr_SetString(PyExc_SystemError, "val in gameOb: KX_GameObject, " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (PyUnicode_Check(value) && self->GetProperty(_PyUnicode_AsString(value)))
- return 1;
-
- if (self->m_attr_dict && PyDict_GetItem(self->m_attr_dict, value))
- return 1;
-
- return 0;
-}
-
-
-PyMappingMethods KX_GameObject::Mapping = {
- (lenfunc)NULL , /*inquiry mp_length */
- (binaryfunc)Map_GetItem, /*binaryfunc mp_subscript */
- (objobjargproc)Map_SetItem, /*objobjargproc mp_ass_subscript */
-};
-
-PySequenceMethods KX_GameObject::Sequence = {
- NULL, /* Cant set the len otherwise it can evaluate as false */
- NULL, /* sq_concat */
- NULL, /* sq_repeat */
- NULL, /* sq_item */
- NULL, /* sq_slice */
- NULL, /* sq_ass_item */
- NULL, /* sq_ass_slice */
- (objobjproc)Seq_Contains, /* sq_contains */
- (binaryfunc) NULL, /* sq_inplace_concat */
- (ssizeargfunc) NULL, /* sq_inplace_repeat */
-};
-
-PyTypeObject KX_GameObject::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_GameObject",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- &Sequence,
- &Mapping,
- 0,0,0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IObject::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyObject *KX_GameObject::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyUnicode_From_STR_String(self->GetName());
-}
-
-PyObject *KX_GameObject::pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- KX_GameObject* parent = self->GetParent();
- if (parent) {
- return parent->GetProxy();
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::pyattr_get_group_members(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- CListValue* instances = self->GetInstanceObjects();
- if (instances) {
- return instances->GetProxy();
- }
- Py_RETURN_NONE;
-}
-
-PyObject* KX_GameObject::pyattr_get_collisionCallbacks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- // Only objects with a physics controller should have collision callbacks
- if (!self->GetPhysicsController()) {
- PyErr_SetString(PyExc_AttributeError, "KX_GameObject.collisionCallbacks: attribute only available for objects with collisions enabled");
- return NULL;
- }
-
- // Return the existing callbacks
- if (self->m_collisionCallbacks == NULL)
- {
- self->m_collisionCallbacks = PyList_New(0);
- // Subscribe to collision update from KX_TouchManager
- self->RegisterCollisionCallbacks();
- }
- Py_INCREF(self->m_collisionCallbacks);
- return self->m_collisionCallbacks;
-}
-
-int KX_GameObject::pyattr_set_collisionCallbacks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- // Only objects with a physics controller should have collision callbacks
- if (!self->GetPhysicsController()) {
- PyErr_SetString(PyExc_AttributeError, "KX_GameObject.collisionCallbacks: attribute only available for objects with collisions enabled");
- return PY_SET_ATTR_FAIL;
- }
-
- if (!PyList_CheckExact(value))
- {
- PyErr_SetString(PyExc_ValueError, "Expected a list");
- return PY_SET_ATTR_FAIL;
- }
-
- if (self->m_collisionCallbacks == NULL) {
- self->RegisterCollisionCallbacks();
- } else {
- Py_DECREF(self->m_collisionCallbacks);
- }
-
- Py_INCREF(value);
-
-
- self->m_collisionCallbacks = value;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_collisionGroup(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyLong_FromLong(self->GetUserCollisionGroup());
-}
-
-int KX_GameObject::pyattr_set_collisionGroup(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- int val = PyLong_AsLong(value);
-
- if (val == -1 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, "gameOb.collisionGroup = int: KX_GameObject, expected an int bit field");
- return PY_SET_ATTR_FAIL;
- }
-
- if (val == 0 || val & ~((1 << OB_MAX_COL_MASKS) - 1)) {
- PyErr_Format(PyExc_AttributeError, "gameOb.collisionGroup = int: KX_GameObject, expected a int bit field, 0 < group < %i", (1 << OB_MAX_COL_MASKS));
- return PY_SET_ATTR_FAIL;
- }
-
- self->SetUserCollisionGroup(val);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_collisionMask(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyLong_FromLong(self->GetUserCollisionMask());
-}
-
-int KX_GameObject::pyattr_set_collisionMask(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- int val = PyLong_AsLong(value);
-
- if (val == -1 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, "gameOb.collisionMask = int: KX_GameObject, expected an int bit field");
- return PY_SET_ATTR_FAIL;
- }
-
- if (val == 0 || val & ~((1 << OB_MAX_COL_MASKS) - 1)) {
- PyErr_Format(PyExc_AttributeError, "gameOb.collisionMask = int: KX_GameObject, expected a int bit field, 0 < mask < %i", (1 << OB_MAX_COL_MASKS));
- return PY_SET_ATTR_FAIL;
- }
-
- self->SetUserCollisionMask(val);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_GameObject::pyattr_get_scene(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
- KX_Scene *scene = self->GetScene();
- if (scene) {
- return scene->GetProxy();
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::pyattr_get_group_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- KX_GameObject* pivot = self->GetDupliGroupObject();
- if (pivot) {
- return pivot->GetProxy();
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::pyattr_get_life(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- CValue *life = self->GetProperty("::timebomb");
- if (life)
- // this convert the timebomb seconds to frames, hard coded 50.0f (assuming 50fps)
- // value hardcoded in KX_Scene::AddReplicaObject()
- return PyFloat_FromDouble(life->GetNumber() * 50.0);
- else
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- return PyFloat_FromDouble(spc ? spc->GetMass() : 0.0f);
-}
-
-int KX_GameObject::pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- MT_Scalar val = PyFloat_AsDouble(value);
- if (val < 0.0f) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "gameOb.mass = float: KX_GameObject, expected a float zero or above");
- return PY_SET_ATTR_FAIL;
- }
-
- if (spc)
- spc->SetMass(val);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_is_suspend_dynamics(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- // Only objects with a physics controller can be suspended
- if (!self->GetPhysicsController()) {
- PyErr_SetString(PyExc_AttributeError, "This object has not Physics Controller");
- return NULL;
- }
-
- return PyBool_FromLong(self->IsDynamicsSuspended());
-}
-
-PyObject *KX_GameObject::pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- return PyFloat_FromDouble(spc ? spc->GetLinVelocityMin() : 0.0f);
-}
-
-int KX_GameObject::pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- MT_Scalar val = PyFloat_AsDouble(value);
- if (val < 0.0f) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMin = float: KX_GameObject, expected a float zero or above");
- return PY_SET_ATTR_FAIL;
- }
-
- if (spc)
- spc->SetLinVelocityMin(val);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- return PyFloat_FromDouble(spc ? spc->GetLinVelocityMax() : 0.0f);
-}
-
-int KX_GameObject::pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- MT_Scalar val = PyFloat_AsDouble(value);
- if (val < 0.0f) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "gameOb.linVelocityMax = float: KX_GameObject, expected a float zero or above");
- return PY_SET_ATTR_FAIL;
- }
-
- if (spc)
- spc->SetLinVelocityMax(val);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_ang_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- return PyFloat_FromDouble(spc ? spc->GetAngularVelocityMin() : 0.0f);
-}
-
-int KX_GameObject::pyattr_set_ang_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- MT_Scalar val = PyFloat_AsDouble(value);
- if (val < 0.0f) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError,
- "gameOb.angularVelocityMin = float: KX_GameObject, expected a nonnegative float");
- return PY_SET_ATTR_FAIL;
- }
-
- if (spc)
- spc->SetAngularVelocityMin(val);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_ang_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- return PyFloat_FromDouble(spc ? spc->GetAngularVelocityMax() : 0.0f);
-}
-
-int KX_GameObject::pyattr_set_ang_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
- PHY_IPhysicsController *spc = self->GetPhysicsController();
- MT_Scalar val = PyFloat_AsDouble(value);
- if (val < 0.0f) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError,
- "gameOb.angularVelocityMax = float: KX_GameObject, expected a nonnegative float");
- return PY_SET_ATTR_FAIL;
- }
-
- if (spc)
- spc->SetAngularVelocityMax(val);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-
-PyObject *KX_GameObject::pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyBool_FromLong(self->GetVisible());
-}
-
-int KX_GameObject::pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- int param = PyObject_IsTrue( value );
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "gameOb.visible = bool: KX_GameObject, expected True or False");
- return PY_SET_ATTR_FAIL;
- }
-
- self->SetVisible(param, false);
- self->UpdateBuckets(false);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_record_animation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyBool_FromLong(self->IsRecordAnimation());
-}
-
-int KX_GameObject::pyattr_set_record_animation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- int param = PyObject_IsTrue(value);
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "gameOb.record_animation = bool: KX_GameObject, expected boolean");
- return PY_SET_ATTR_FAIL;
- }
-
- self->SetRecordAnimation(param);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-
-
-PyObject *KX_GameObject::pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_GLOBAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(self->NodeGetWorldPosition());
-#endif
-}
-
-int KX_GameObject::pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Point3 pos;
- if (!PyVecTo(value, pos))
- return PY_SET_ATTR_FAIL;
-
- self->NodeSetWorldPosition(pos);
- self->NodeUpdateGS(0.f);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_POS_LOCAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(self->NodeGetLocalPosition());
-#endif
-}
-
-int KX_GameObject::pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Point3 pos;
- if (!PyVecTo(value, pos))
- return PY_SET_ATTR_FAIL;
-
- self->NodeSetLocalPosition(pos);
- self->NodeUpdateGS(0.f);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_INERTIA_LOCAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- if (self->GetPhysicsController1())
- return PyObjectFrom(self->GetPhysicsController1()->GetLocalInertia());
- return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f);
-#endif
-}
-
-PyObject *KX_GameObject::pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Matrix_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3, 3,
- mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_GLOBAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(self->NodeGetWorldOrientation());
-#endif
-}
-
-int KX_GameObject::pyattr_set_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- /* if value is not a sequence PyOrientationTo makes an error */
- MT_Matrix3x3 rot;
- if (!PyOrientationTo(value, rot, "gameOb.worldOrientation = sequence: KX_GameObject, "))
- return PY_SET_ATTR_FAIL;
-
- self->NodeSetGlobalOrientation(rot);
-
- self->NodeUpdateGS(0.f);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Matrix_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3, 3,
- mathutils_kxgameob_matrix_cb_index, MATHUTILS_MAT_CB_ORI_LOCAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(self->NodeGetLocalOrientation());
-#endif
-}
-
-int KX_GameObject::pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- /* if value is not a sequence PyOrientationTo makes an error */
- MT_Matrix3x3 rot;
- if (!PyOrientationTo(value, rot, "gameOb.localOrientation = sequence: KX_GameObject, "))
- return PY_SET_ATTR_FAIL;
-
- self->NodeSetLocalOrientation(rot);
- self->NodeUpdateGS(0.f);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_GLOBAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(self->NodeGetWorldScaling());
-#endif
-}
-
-int KX_GameObject::pyattr_set_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Vector3 scale;
- if (!PyVecTo(value, scale))
- return PY_SET_ATTR_FAIL;
-
- self->NodeSetWorldScale(scale);
- self->NodeUpdateGS(0.f);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_SCALE_LOCAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(self->NodeGetLocalScaling());
-#endif
-}
-
-int KX_GameObject::pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Vector3 scale;
- if (!PyVecTo(value, scale))
- return PY_SET_ATTR_FAIL;
-
- self->NodeSetLocalScale(scale);
- self->NodeUpdateGS(0.f);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- float mat[16];
-
- MT_Transform trans;
-
- trans.setOrigin(self->GetSGNode()->GetLocalPosition());
- trans.setBasis(self->GetSGNode()->GetLocalOrientation());
-
- MT_Vector3 scaling = self->GetSGNode()->GetLocalScale();
- trans.scale(scaling[0], scaling[1], scaling[2]);
-
- trans.getValue(mat);
-
- return PyObjectFrom(MT_Matrix4x4(mat));
-}
-
-int KX_GameObject::pyattr_set_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Matrix4x4 temp;
- if (!PyMatTo(value, temp))
- return PY_SET_ATTR_FAIL;
-
- float transform[4][4];
- float loc[3], size[3];
- float rot[3][3];
- MT_Matrix3x3 orientation;
-
- temp.getValue(*transform);
- mat4_to_loc_rot_size(loc, rot, size, transform);
-
- self->NodeSetLocalPosition(MT_Point3(loc));
-
- //MT_Matrix3x3's constructor expects a 4x4 matrix
- orientation = MT_Matrix3x3();
- orientation.setValue3x3(*rot);
- self->NodeSetLocalOrientation(orientation);
-
- self->NodeSetLocalScale(MT_Vector3(size));
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- return PyObjectFrom(MT_Matrix4x4(self->GetOpenGLMatrix()));
-}
-
-int KX_GameObject::pyattr_set_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Matrix4x4 temp;
- if (!PyMatTo(value, temp))
- return PY_SET_ATTR_FAIL;
-
- float transform[4][4];
- float loc[3], size[3];
- float rot[3][3];
- MT_Matrix3x3 orientation;
-
- temp.getValue(*transform);
- mat4_to_loc_rot_size(loc, rot, size, transform);
-
- self->NodeSetWorldPosition(MT_Point3(loc));
-
- //MT_Matrix3x3's constructor expects a 4x4 matrix
- orientation = MT_Matrix3x3();
- orientation.setValue3x3(*rot);
- self->NodeSetGlobalOrientation(orientation);
-
- self->NodeSetWorldScale(MT_Vector3(size));
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_LINVEL_GLOBAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(GetLinearVelocity(false));
-#endif
-}
-
-int KX_GameObject::pyattr_set_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Vector3 velocity;
- if (!PyVecTo(value, velocity))
- return PY_SET_ATTR_FAIL;
-
- self->setLinearVelocity(velocity, false);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_LINVEL_LOCAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(GetLinearVelocity(true));
-#endif
-}
-
-int KX_GameObject::pyattr_set_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Vector3 velocity;
- if (!PyVecTo(value, velocity))
- return PY_SET_ATTR_FAIL;
-
- self->setLinearVelocity(velocity, true);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_ANGVEL_GLOBAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(GetAngularVelocity(false));
-#endif
-}
-
-int KX_GameObject::pyattr_set_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Vector3 velocity;
- if (!PyVecTo(value, velocity))
- return PY_SET_ATTR_FAIL;
-
- self->setAngularVelocity(velocity, false);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_ANGVEL_LOCAL);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(GetAngularVelocity(true));
-#endif
-}
-
-int KX_GameObject::pyattr_set_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Vector3 velocity;
- if (!PyVecTo(value, velocity))
- return PY_SET_ATTR_FAIL;
-
- self->setAngularVelocity(velocity, true);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_linearDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyFloat_FromDouble(self->getLinearDamping());
-}
-
-int KX_GameObject::pyattr_set_linearDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- float val = PyFloat_AsDouble(value);
- self->setLinearDamping(val);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_angularDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyFloat_FromDouble(self->getAngularDamping());
-}
-
-int KX_GameObject::pyattr_set_angularDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- float val = PyFloat_AsDouble(value);
- self->setAngularDamping(val);
- return PY_SET_ATTR_SUCCESS;
-}
-
-
-PyObject *KX_GameObject::pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- SG_Node* sg_parent;
- if (self->GetSGNode() && (sg_parent = self->GetSGNode()->GetSGParent()) != NULL && sg_parent->IsSlowParent()) {
- return PyFloat_FromDouble(static_cast<KX_SlowParentRelation *>(sg_parent->GetParentRelation())->GetTimeOffset());
- } else {
- return PyFloat_FromDouble(0.0f);
- }
-}
-
-int KX_GameObject::pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- if (self->GetSGNode()) {
- MT_Scalar val = PyFloat_AsDouble(value);
- SG_Node *sg_parent= self->GetSGNode()->GetSGParent();
- if (val < 0.0f) { /* also accounts for non float */
- PyErr_SetString(PyExc_AttributeError, "gameOb.timeOffset = float: KX_GameObject, expected a float zero or above");
- return PY_SET_ATTR_FAIL;
- }
- if (sg_parent && sg_parent->IsSlowParent())
- static_cast<KX_SlowParentRelation *>(sg_parent->GetParentRelation())->SetTimeOffset(val);
- }
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- int state = 0;
- state |= self->GetState();
- return PyLong_FromLong(state);
-}
-
-int KX_GameObject::pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- int state_i = PyLong_AsLong(value);
- unsigned int state = 0;
-
- if (state_i == -1 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, "gameOb.state = int: KX_GameObject, expected an int bit field");
- return PY_SET_ATTR_FAIL;
- }
-
- state |= state_i;
- if ((state & ((1<<30)-1)) == 0) {
- PyErr_SetString(PyExc_AttributeError, "gameOb.state = int: KX_GameObject, state bitfield was not between 0 and 30 (1<<0 and 1<<29)");
- return PY_SET_ATTR_FAIL;
- }
- self->SetState(state);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_meshes(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- PyObject *meshes= PyList_New(self->m_meshes.size());
- int i;
-
- for (i=0; i < (int)self->m_meshes.size(); i++)
- {
- KX_MeshProxy* meshproxy = new KX_MeshProxy(self->m_meshes[i]);
- PyList_SET_ITEM(meshes, i, meshproxy->NewProxy(true));
- }
-
- return meshes;
-}
-
-PyObject *KX_GameObject::pyattr_get_obcolor(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 4,
- mathutils_kxgameob_vector_cb_index, MATHUTILS_VEC_CB_OBJECT_COLOR);
-#else
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return PyObjectFrom(self->GetObjectColor());
-#endif
-}
-
-int KX_GameObject::pyattr_set_obcolor(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- MT_Vector4 obcolor;
- if (!PyVecTo(value, obcolor))
- return PY_SET_ATTR_FAIL;
-
- self->SetObjectColor(obcolor);
- return PY_SET_ATTR_SUCCESS;
-}
-
-static int kx_game_object_get_sensors_size_cb(void *self_v)
-{
- return ((KX_GameObject *)self_v)->GetSensors().size();
-}
-
-static PyObject *kx_game_object_get_sensors_item_cb(void *self_v, int index)
-{
- return ((KX_GameObject *)self_v)->GetSensors()[index]->GetProxy();
-}
-
-static const char *kx_game_object_get_sensors_item_name_cb(void *self_v, int index)
-{
- return ((KX_GameObject *)self_v)->GetSensors()[index]->GetName().ReadPtr();
-}
-
-/* These are experimental! */
-PyObject *KX_GameObject::pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return (new CListWrapper(self_v,
- ((KX_GameObject *)self_v)->GetProxy(),
- NULL,
- kx_game_object_get_sensors_size_cb,
- kx_game_object_get_sensors_item_cb,
- kx_game_object_get_sensors_item_name_cb,
- NULL))->NewProxy(true);
-}
-
-static int kx_game_object_get_controllers_size_cb(void *self_v)
-{
- return ((KX_GameObject *)self_v)->GetControllers().size();
-}
-
-static PyObject *kx_game_object_get_controllers_item_cb(void *self_v, int index)
-{
- return ((KX_GameObject *)self_v)->GetControllers()[index]->GetProxy();
-}
-
-static const char *kx_game_object_get_controllers_item_name_cb(void *self_v, int index)
-{
- return ((KX_GameObject *)self_v)->GetControllers()[index]->GetName().ReadPtr();
-}
-
-PyObject *KX_GameObject::pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return (new CListWrapper(self_v,
- ((KX_GameObject *)self_v)->GetProxy(),
- NULL,
- kx_game_object_get_controllers_size_cb,
- kx_game_object_get_controllers_item_cb,
- kx_game_object_get_controllers_item_name_cb,
- NULL))->NewProxy(true);
-}
-
-static int kx_game_object_get_actuators_size_cb(void *self_v)
-{
- return ((KX_GameObject *)self_v)->GetActuators().size();
-}
-
-static PyObject *kx_game_object_get_actuators_item_cb(void *self_v, int index)
-{
- return ((KX_GameObject *)self_v)->GetActuators()[index]->GetProxy();
-}
-
-static const char *kx_game_object_get_actuators_item_name_cb(void *self_v, int index)
-{
- return ((KX_GameObject *)self_v)->GetActuators()[index]->GetName().ReadPtr();
-}
-
-PyObject *KX_GameObject::pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return (new CListWrapper(self_v,
- ((KX_GameObject *)self_v)->GetProxy(),
- NULL,
- kx_game_object_get_actuators_size_cb,
- kx_game_object_get_actuators_item_cb,
- kx_game_object_get_actuators_item_name_cb,
- NULL))->NewProxy(true);
-}
-/* End experimental */
-
-PyObject *KX_GameObject::pyattr_get_children(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return self->GetChildren()->NewProxy(true);
-}
-
-PyObject *KX_GameObject::pyattr_get_children_recursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
- return self->GetChildrenRecursive()->NewProxy(true);
-}
-
-PyObject *KX_GameObject::pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_GameObject* self = static_cast<KX_GameObject*>(self_v);
-
- if (self->m_attr_dict==NULL)
- self->m_attr_dict= PyDict_New();
-
- Py_INCREF(self->m_attr_dict);
- return self->m_attr_dict;
-}
-
-PyObject *KX_GameObject::pyattr_get_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene *scene = KX_GetActiveScene();
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
-
- return PyBool_FromLong(scene->ObjectInDebugList(self));
-}
-
-int KX_GameObject::pyattr_set_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
- int param = PyObject_IsTrue(value);
-
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "gameOb.debug = bool: KX_GameObject, expected True or False");
- return PY_SET_ATTR_FAIL;
- }
-
- self->SetUseDebugProperties(param, false);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::pyattr_get_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene *scene = KX_GetActiveScene();
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
-
- return PyBool_FromLong(scene->ObjectInDebugList(self));
-}
-
-int KX_GameObject::pyattr_set_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_GameObject *self = static_cast<KX_GameObject*>(self_v);
- int param = PyObject_IsTrue(value);
-
- if (param == -1) {
- PyErr_SetString(PyExc_AttributeError, "gameOb.debugRecursive = bool: KX_GameObject, expected True or False");
- return PY_SET_ATTR_FAIL;
- }
-
- self->SetUseDebugProperties(param, true);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_GameObject::PyApplyForce(PyObject *args)
-{
- int local = 0;
- PyObject *pyvect;
-
- if (PyArg_ParseTuple(args, "O|i:applyForce", &pyvect, &local)) {
- MT_Vector3 force;
- if (PyVecTo(pyvect, force)) {
- ApplyForce(force, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject *KX_GameObject::PyApplyTorque(PyObject *args)
-{
- int local = 0;
- PyObject *pyvect;
-
- if (PyArg_ParseTuple(args, "O|i:applyTorque", &pyvect, &local)) {
- MT_Vector3 torque;
- if (PyVecTo(pyvect, torque)) {
- ApplyTorque(torque, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject *KX_GameObject::PyApplyRotation(PyObject *args)
-{
- int local = 0;
- PyObject *pyvect;
-
- if (PyArg_ParseTuple(args, "O|i:applyRotation", &pyvect, &local)) {
- MT_Vector3 rotation;
- if (PyVecTo(pyvect, rotation)) {
- ApplyRotation(rotation, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject *KX_GameObject::PyApplyMovement(PyObject *args)
-{
- int local = 0;
- PyObject *pyvect;
-
- if (PyArg_ParseTuple(args, "O|i:applyMovement", &pyvect, &local)) {
- MT_Vector3 movement;
- if (PyVecTo(pyvect, movement)) {
- ApplyMovement(movement, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject *KX_GameObject::PyGetLinearVelocity(PyObject *args)
-{
- // only can get the velocity if we have a physics object connected to us...
- int local = 0;
- if (PyArg_ParseTuple(args,"|i:getLinearVelocity",&local))
- {
- return PyObjectFrom(GetLinearVelocity((local!=0)));
- }
- else
- {
- return NULL;
- }
-}
-
-PyObject *KX_GameObject::PySetLinearVelocity(PyObject *args)
-{
- int local = 0;
- PyObject *pyvect;
-
- if (PyArg_ParseTuple(args,"O|i:setLinearVelocity",&pyvect,&local)) {
- MT_Vector3 velocity;
- if (PyVecTo(pyvect, velocity)) {
- setLinearVelocity(velocity, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject *KX_GameObject::PyGetAngularVelocity(PyObject *args)
-{
- // only can get the velocity if we have a physics object connected to us...
- int local = 0;
- if (PyArg_ParseTuple(args,"|i:getAngularVelocity",&local))
- {
- return PyObjectFrom(GetAngularVelocity((local!=0)));
- }
- else
- {
- return NULL;
- }
-}
-
-PyObject *KX_GameObject::PySetAngularVelocity(PyObject *args)
-{
- int local = 0;
- PyObject *pyvect;
-
- if (PyArg_ParseTuple(args,"O|i:setAngularVelocity",&pyvect,&local)) {
- MT_Vector3 velocity;
- if (PyVecTo(pyvect, velocity)) {
- setAngularVelocity(velocity, (local!=0));
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject *KX_GameObject::PySetDamping(PyObject *args)
-{
- float linear;
- float angular;
-
- if (!PyArg_ParseTuple(args,"ff|i:setDamping", &linear, &angular))
- return NULL;
-
- setDamping(linear, angular);
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::PySetVisible(PyObject *args)
-{
- int visible, recursive = 0;
- if (!PyArg_ParseTuple(args,"i|i:setVisible",&visible, &recursive))
- return NULL;
-
- SetVisible(visible ? true:false, recursive ? true:false);
- UpdateBuckets(recursive ? true:false);
- Py_RETURN_NONE;
-
-}
-
-PyObject *KX_GameObject::PySetOcclusion(PyObject *args)
-{
- int occlusion, recursive = 0;
- if (!PyArg_ParseTuple(args,"i|i:setOcclusion",&occlusion, &recursive))
- return NULL;
-
- SetOccluder(occlusion ? true:false, recursive ? true:false);
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::PyGetVelocity(PyObject *args)
-{
- // only can get the velocity if we have a physics object connected to us...
- MT_Point3 point(0.0f,0.0f,0.0f);
- PyObject *pypos = NULL;
-
- if (!PyArg_ParseTuple(args, "|O:getVelocity", &pypos) || (pypos && !PyVecTo(pypos, point)))
- return NULL;
-
- return PyObjectFrom(GetVelocity(point));
-}
-
-PyObject *KX_GameObject::PyGetReactionForce()
-{
- // only can get the velocity if we have a physics object connected to us...
-
- // XXX - Currently not working with bullet intergration, see KX_BulletPhysicsController.cpp's getReactionForce
-#if 0
- if (GetPhysicsController1())
- return PyObjectFrom(GetPhysicsController1()->getReactionForce());
- return PyObjectFrom(dummy_point);
-#endif
-
- return Py_BuildValue("fff", 0.0f, 0.0f, 0.0f);
-
-}
-
-
-
-PyObject *KX_GameObject::PyEnableRigidBody()
-{
- if (GetPhysicsController())
- GetPhysicsController()->SetRigidBody(true);
-
- Py_RETURN_NONE;
-}
-
-
-
-PyObject *KX_GameObject::PyDisableRigidBody()
-{
- if (GetPhysicsController())
- GetPhysicsController()->SetRigidBody(false);
-
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_GameObject::PySetParent(PyObject *args)
-{
- KX_Scene *scene = KX_GetActiveScene();
- SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
- PyObject *pyobj;
- KX_GameObject *obj;
- int addToCompound=1, ghost=1;
-
- if (!PyArg_ParseTuple(args,"O|ii:setParent", &pyobj, &addToCompound, &ghost)) {
- return NULL; // Python sets a simple error
- }
- if (!ConvertPythonToGameObject(logicmgr, pyobj, &obj, true, "gameOb.setParent(obj): KX_GameObject"))
- return NULL;
- if (obj)
- this->SetParent(scene, obj, addToCompound, ghost);
- Py_RETURN_NONE;
-}
-
-PyObject *KX_GameObject::PyRemoveParent()
-{
- KX_Scene *scene = KX_GetActiveScene();
-
- this->RemoveParent(scene);
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_GameObject::PySetCollisionMargin(PyObject *value)
-{
- float collisionMargin = PyFloat_AsDouble(value);
-
- if (collisionMargin==-1 && PyErr_Occurred()) {
- PyErr_SetString(PyExc_TypeError, "expected a float");
- return NULL;
- }
-
- if (m_pPhysicsController)
- {
- m_pPhysicsController->SetMargin(collisionMargin);
- Py_RETURN_NONE;
- }
- PyErr_SetString(PyExc_RuntimeError, "This object has no physics controller");
- return NULL;
-}
-
-
-
-PyObject *KX_GameObject::PyApplyImpulse(PyObject *args)
-{
- PyObject *pyattach;
- PyObject *pyimpulse;
- int local = 0;
-
- if (!m_pPhysicsController) {
- PyErr_SetString(PyExc_RuntimeError, "This object has no physics controller");
- return NULL;
- }
-
- if (PyArg_ParseTuple(args, "OO|i:applyImpulse", &pyattach, &pyimpulse, &local))
- {
- MT_Point3 attach;
- MT_Vector3 impulse;
- if (PyVecTo(pyattach, attach) && PyVecTo(pyimpulse, impulse))
- {
- m_pPhysicsController->ApplyImpulse(attach, impulse, (local!=0));
- Py_RETURN_NONE;
- }
-
- }
-
- return NULL;
-}
-
-
-
-PyObject *KX_GameObject::PySuspendDynamics(PyObject *args)
-{
- bool ghost = false;
-
- if (!PyArg_ParseTuple(args, "|b", &ghost))
- return NULL;
-
- if (GetPhysicsController())
- GetPhysicsController()->SuspendDynamics(ghost);
-
- Py_RETURN_NONE;
-}
-
-
-
-PyObject *KX_GameObject::PyRestoreDynamics()
-{
- // Child objects must be static, so we block changing to dynamic
- if (GetPhysicsController() && !GetParent())
- GetPhysicsController()->RestoreDynamics();
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_GameObject::PyAlignAxisToVect(PyObject *args)
-{
- PyObject *pyvect;
- int axis = 2; //z axis is the default
- float fac = 1.0f;
-
- if (PyArg_ParseTuple(args,"O|if:alignAxisToVect",&pyvect,&axis, &fac))
- {
- MT_Vector3 vect;
- if (PyVecTo(pyvect, vect)) {
- if (fac > 0.0f) {
- if (fac> 1.0f) fac = 1.0f;
-
- AlignAxisToVect(vect, axis, fac);
- NodeUpdateGS(0.f);
- }
- Py_RETURN_NONE;
- }
- }
- return NULL;
-}
-
-PyObject *KX_GameObject::PyGetAxisVect(PyObject *value)
-{
- MT_Vector3 vect;
- if (PyVecTo(value, vect))
- {
- return PyObjectFrom(NodeGetWorldOrientation() * vect);
- }
- return NULL;
-}
-
-
-PyObject *KX_GameObject::PyGetPhysicsId()
-{
- PHY_IPhysicsController* ctrl = GetPhysicsController();
- unsigned long long physid = 0;
- if (ctrl)
- {
- physid = (unsigned long long)ctrl;
- }
- return PyLong_FromUnsignedLongLong(physid);
-}
-
-PyObject *KX_GameObject::PyGetPropertyNames()
-{
- PyObject *list= ConvertKeysToPython();
-
- if (m_attr_dict) {
- PyObject *key, *value;
- Py_ssize_t pos = 0;
-
- while (PyDict_Next(m_attr_dict, &pos, &key, &value)) {
- PyList_Append(list, key);
- }
- }
- return list;
-}
-
-KX_PYMETHODDEF_DOC_O(KX_GameObject, getDistanceTo,
-"getDistanceTo(other): get distance to another point/KX_GameObject")
-{
- MT_Point3 b;
- if (PyVecTo(value, b))
- {
- return PyFloat_FromDouble(NodeGetWorldPosition().distance(b));
- }
- PyErr_Clear();
-
- SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
- KX_GameObject *other;
- if (ConvertPythonToGameObject(logicmgr, value, &other, false, "gameOb.getDistanceTo(value): KX_GameObject"))
- {
- return PyFloat_FromDouble(NodeGetWorldPosition().distance(other->NodeGetWorldPosition()));
- }
-
- return NULL;
-}
-
-KX_PYMETHODDEF_DOC_O(KX_GameObject, getVectTo,
-"getVectTo(other): get vector and the distance to another point/KX_GameObject\n"
-"Returns a 3-tuple with (distance,worldVector,localVector)\n")
-{
- MT_Point3 toPoint, fromPoint;
- MT_Vector3 toDir, locToDir;
- MT_Scalar distance;
-
- SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
- PyObject *returnValue;
-
- if (!PyVecTo(value, toPoint))
- {
- PyErr_Clear();
-
- KX_GameObject *other;
- if (ConvertPythonToGameObject(logicmgr, value, &other, false, "")) /* error will be overwritten */
- {
- toPoint = other->NodeGetWorldPosition();
- } else
- {
- PyErr_SetString(PyExc_TypeError, "gameOb.getVectTo(other): KX_GameObject, expected a 3D Vector or KX_GameObject type");
- return NULL;
- }
- }
-
- fromPoint = NodeGetWorldPosition();
- toDir = toPoint-fromPoint;
- distance = toDir.length();
-
- if (MT_fuzzyZero(distance))
- {
- //cout << "getVectTo() Error: Null vector!\n";
- locToDir = toDir = MT_Vector3(0.0f,0.0f,0.0f);
- distance = 0.0f;
- } else {
- toDir.normalize();
- locToDir = toDir * NodeGetWorldOrientation();
- }
-
- returnValue = PyTuple_New(3);
- if (returnValue) { // very unlikely to fail, python sets a memory error here.
- PyTuple_SET_ITEM(returnValue, 0, PyFloat_FromDouble(distance));
- PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(toDir));
- PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(locToDir));
- }
- return returnValue;
-}
-
-struct KX_GameObject::RayCastData
-{
- RayCastData(STR_String prop, bool xray, short mask)
- :m_prop(prop),
- m_xray(xray),
- m_mask(mask),
- m_hitObject(NULL)
- {
- }
-
- STR_String m_prop;
- bool m_xray;
- unsigned short m_mask;
- KX_GameObject *m_hitObject;
-};
-
-bool KX_GameObject::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, RayCastData *rayData)
-{
- KX_GameObject* hitKXObj = client->m_gameobject;
-
- // if X-ray option is selected, the unwnted objects were not tested, so get here only with true hit
- // if not, all objects were tested and the front one may not be the correct one.
- if ((rayData->m_xray || rayData->m_prop.Length() == 0 || hitKXObj->GetProperty(rayData->m_prop) != NULL) &&
- hitKXObj->GetUserCollisionGroup() & rayData->m_mask)
- {
- rayData->m_hitObject = hitKXObj;
- return true;
- }
- // return true to stop RayCast::RayTest from looping, the above test was decisive
- // We would want to loop only if we want to get more than one hit point
- return true;
-}
-
-/* this function is used to pre-filter the object before casting the ray on them.
- * This is useful for "X-Ray" option when we want to see "through" unwanted object.
- */
-bool KX_GameObject::NeedRayCast(KX_ClientObjectInfo *client, RayCastData *rayData)
-{
- KX_GameObject* hitKXObj = client->m_gameobject;
-
- if (client->m_type > KX_ClientObjectInfo::ACTOR)
- {
- // Unknown type of object, skip it.
- // Should not occur as the sensor objects are filtered in RayTest()
- printf("Invalid client type %d found in ray casting\n", client->m_type);
- return false;
- }
-
- // if X-Ray option is selected, skip object that don't match the criteria as we see through them
- // if not, test all objects because we don't know yet which one will be on front
- if ((!rayData->m_xray || rayData->m_prop.Length() == 0 || hitKXObj->GetProperty(rayData->m_prop) != NULL) &&
- hitKXObj->GetUserCollisionGroup() & rayData->m_mask)
- {
- return true;
- }
- // skip the object
- return false;
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, rayCastTo,
-"rayCastTo(other,dist,prop): look towards another point/KX_GameObject and return first object hit within dist that matches prop\n"
-" prop = property name that object must have; can be omitted => detect any object\n"
-" dist = max distance to look (can be negative => look behind); 0 or omitted => detect up to other\n"
-" other = 3-tuple or object reference")
-{
- MT_Point3 toPoint;
- PyObject *pyarg;
- float dist = 0.0f;
- char *propName = NULL;
- SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
-
- if (!PyArg_ParseTuple(args,"O|fs:rayCastTo", &pyarg, &dist, &propName)) {
- return NULL; // python sets simple error
- }
-
- if (!PyVecTo(pyarg, toPoint))
- {
- KX_GameObject *other;
- PyErr_Clear();
-
- if (ConvertPythonToGameObject(logicmgr, pyarg, &other, false, "")) /* error will be overwritten */
- {
- toPoint = other->NodeGetWorldPosition();
- } else
- {
- PyErr_SetString(PyExc_TypeError, "gameOb.rayCastTo(other,dist,prop): KX_GameObject, the first argument to rayCastTo must be a vector or a KX_GameObject");
- return NULL;
- }
- }
- MT_Point3 fromPoint = NodeGetWorldPosition();
-
- if (dist != 0.0f)
- toPoint = fromPoint + dist * (toPoint-fromPoint).safe_normalized();
-
- PHY_IPhysicsEnvironment* pe = GetScene()->GetPhysicsEnvironment();
- PHY_IPhysicsController *spc = GetPhysicsController();
- KX_GameObject *parent = GetParent();
- if (!spc && parent)
- spc = parent->GetPhysicsController();
-
- RayCastData rayData(propName, false, (1u << OB_MAX_COL_MASKS) - 1);
- KX_RayCast::Callback<KX_GameObject, RayCastData> callback(this, spc, &rayData);
- if (KX_RayCast::RayTest(pe, fromPoint, toPoint, callback) && rayData.m_hitObject) {
- return rayData.m_hitObject->GetProxy();
- }
-
- Py_RETURN_NONE;
-}
-
-/* faster then Py_BuildValue since some scripts call raycast a lot */
-static PyObject *none_tuple_3()
-{
- PyObject *ret= PyTuple_New(3);
- PyTuple_SET_ITEM(ret, 0, Py_None);
- PyTuple_SET_ITEM(ret, 1, Py_None);
- PyTuple_SET_ITEM(ret, 2, Py_None);
-
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- return ret;
-}
-static PyObject *none_tuple_4()
-{
- PyObject *ret= PyTuple_New(4);
- PyTuple_SET_ITEM(ret, 0, Py_None);
- PyTuple_SET_ITEM(ret, 1, Py_None);
- PyTuple_SET_ITEM(ret, 2, Py_None);
- PyTuple_SET_ITEM(ret, 3, Py_None);
-
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- return ret;
-}
-
-static PyObject *none_tuple_5()
-{
- PyObject *ret= PyTuple_New(5);
- PyTuple_SET_ITEM(ret, 0, Py_None);
- PyTuple_SET_ITEM(ret, 1, Py_None);
- PyTuple_SET_ITEM(ret, 2, Py_None);
- PyTuple_SET_ITEM(ret, 3, Py_None);
- PyTuple_SET_ITEM(ret, 4, Py_None);
-
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- Py_INCREF(Py_None);
- return ret;
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, rayCast,
- "rayCast(to,from,dist,prop,face,xray,poly,mask): cast a ray and return 3-tuple (object,hit,normal) or 4-tuple (object,hit,normal,polygon) or 4-tuple (object,hit,normal,polygon,hituv) of contact point with object within dist that matches prop.\n"
- " If no hit, return (None,None,None) or (None,None,None,None) or (None,None,None,None,None).\n"
-" to = 3-tuple or object reference for destination of ray (if object, use center of object)\n"
-" from = 3-tuple or object reference for origin of ray (if object, use center of object)\n"
-" Can be None or omitted => start from self object center\n"
-" dist = max distance to look (can be negative => look behind); 0 or omitted => detect up to to\n"
-" prop = property name that object must have; can be omitted => detect any object\n"
-" face = normal option: 1=>return face normal; 0 or omitted => normal is oriented towards origin\n"
-" xray = X-ray option: 1=>skip objects that don't match prop; 0 or omitted => stop on first object\n"
-" poly = polygon option: 1=>return value is a 4-tuple and the 4th element is a KX_PolyProxy object\n"
-" which can be None if hit object has no mesh or if there is no hit\n"
-" 2=>return value is a 5-tuple, the 4th element is the KX_PolyProxy object\n"
-" and the 5th element is the vector of UV coordinates at the hit point of the None if there is no UV mapping\n"
-" If 0 or omitted, return value is a 3-tuple\n"
-" mask = collision mask: the collision mask that ray can hit, 0 < mask < 65536\n"
-"Note: The object on which you call this method matters: the ray will ignore it.\n"
-" prop and xray option interact as follow:\n"
-" prop off, xray off: return closest hit or no hit if there is no object on the full extend of the ray\n"
-" prop off, xray on : idem\n"
-" prop on, xray off: return closest hit if it matches prop, no hit otherwise\n"
-" prop on, xray on : return closest hit matching prop or no hit if there is no object matching prop on the full extend of the ray\n")
-{
- MT_Point3 toPoint;
- MT_Point3 fromPoint;
- PyObject *pyto;
- PyObject *pyfrom = NULL;
- float dist = 0.0f;
- char *propName = NULL;
- KX_GameObject *other;
- int face=0, xray=0, poly=0;
- int mask = (1 << OB_MAX_COL_MASKS) - 1;
- SCA_LogicManager *logicmgr = GetScene()->GetLogicManager();
-
- if (!PyArg_ParseTuple(args,"O|Ofsiiii:rayCast", &pyto, &pyfrom, &dist, &propName, &face, &xray, &poly, &mask)) {
- return NULL; // Python sets a simple error
- }
-
- if (!PyVecTo(pyto, toPoint))
- {
- PyErr_Clear();
-
- if (ConvertPythonToGameObject(logicmgr, pyto, &other, false, "")) /* error will be overwritten */
- {
- toPoint = other->NodeGetWorldPosition();
- } else
- {
- PyErr_SetString(PyExc_TypeError, "the first argument to rayCast must be a vector or a KX_GameObject");
- return NULL;
- }
- }
- if (!pyfrom || pyfrom == Py_None)
- {
- fromPoint = NodeGetWorldPosition();
- }
- else if (!PyVecTo(pyfrom, fromPoint))
- {
- PyErr_Clear();
-
- if (ConvertPythonToGameObject(logicmgr, pyfrom, &other, false, "")) /* error will be overwritten */
- {
- fromPoint = other->NodeGetWorldPosition();
- } else
- {
- PyErr_SetString(PyExc_TypeError, "gameOb.rayCast(to,from,dist,prop,face,xray,poly,mask): KX_GameObject, the second optional argument to rayCast must be a vector or a KX_GameObject");
- return NULL;
- }
- }
-
- if (mask == 0 || mask & ~((1 << OB_MAX_COL_MASKS) - 1)) {
- PyErr_Format(PyExc_TypeError, "gameOb.rayCast(to,from,dist,prop,face,xray,poly,mask): KX_GameObject, mask argument to rayCast must be a int bitfield, 0 < mask < %i", (1 << OB_MAX_COL_MASKS));
- return NULL;
- }
-
- if (dist != 0.0f) {
- MT_Vector3 toDir = toPoint-fromPoint;
- if (MT_fuzzyZero(toDir.length2())) {
- //return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
- return none_tuple_3();
- }
- toDir.normalize();
- toPoint = fromPoint + (dist) * toDir;
- } else if (MT_fuzzyZero((toPoint-fromPoint).length2())) {
- //return Py_BuildValue("OOO", Py_None, Py_None, Py_None);
- return none_tuple_3();
- }
-
- PHY_IPhysicsEnvironment* pe = GetScene()->GetPhysicsEnvironment();
- PHY_IPhysicsController *spc = GetPhysicsController();
- KX_GameObject *parent = GetParent();
- if (!spc && parent)
- spc = parent->GetPhysicsController();
-
- // to get the hit results
- RayCastData rayData(propName, xray, mask);
- KX_RayCast::Callback<KX_GameObject, RayCastData> callback(this, spc, &rayData, face, (poly == 2));
-
- if (KX_RayCast::RayTest(pe, fromPoint, toPoint, callback) && rayData.m_hitObject) {
- PyObject *returnValue = (poly == 2) ? PyTuple_New(5) : (poly) ? PyTuple_New(4) : PyTuple_New(3);
- if (returnValue) { // unlikely this would ever fail, if it does python sets an error
- PyTuple_SET_ITEM(returnValue, 0, rayData.m_hitObject->GetProxy());
- PyTuple_SET_ITEM(returnValue, 1, PyObjectFrom(callback.m_hitPoint));
- PyTuple_SET_ITEM(returnValue, 2, PyObjectFrom(callback.m_hitNormal));
- if (poly)
- {
- if (callback.m_hitMesh)
- {
- // if this field is set, then we can trust that m_hitPolygon is a valid polygon
- RAS_Polygon* polygon = callback.m_hitMesh->GetPolygon(callback.m_hitPolygon);
- KX_PolyProxy* polyproxy = new KX_PolyProxy(callback.m_hitMesh, polygon);
- PyTuple_SET_ITEM(returnValue, 3, polyproxy->NewProxy(true));
- if (poly == 2)
- {
- if (callback.m_hitUVOK)
- PyTuple_SET_ITEM(returnValue, 4, PyObjectFrom(callback.m_hitUV));
- else {
- Py_INCREF(Py_None);
- PyTuple_SET_ITEM(returnValue, 4, Py_None);
- }
- }
- }
- else
- {
- Py_INCREF(Py_None);
- PyTuple_SET_ITEM(returnValue, 3, Py_None);
- if (poly==2)
- {
- Py_INCREF(Py_None);
- PyTuple_SET_ITEM(returnValue, 4, Py_None);
- }
- }
- }
- }
- return returnValue;
- }
- // no hit
- if (poly == 2)
- return none_tuple_5();
- else if (poly)
- return none_tuple_4();
- else
- return none_tuple_3();
-}
-
-KX_PYMETHODDEF_DOC_VARARGS(KX_GameObject, sendMessage,
- "sendMessage(subject, [body, to])\n"
-"sends a message in same manner as a message actuator"
-"subject = Subject of the message (string)"
-"body = Message body (string)"
-"to = Name of object to send the message to")
-{
- KX_Scene *scene = KX_GetActiveScene();
- char* subject;
- char* body = (char *)"";
- char* to = (char *)"";
- const STR_String& from = GetName();
-
- if (!PyArg_ParseTuple(args, "s|ss:sendMessage", &subject, &body, &to))
- return NULL;
-
- scene->GetNetworkScene()->SendMessage(to, from, subject, body);
- Py_RETURN_NONE;
-}
-
-static void layer_check(short &layer, const char *method_name)
-{
- if (layer < 0 || layer >= MAX_ACTION_LAYERS)
- {
- printf("KX_GameObject.%s(): given layer (%d) is out of range (0 - %d), setting to 0.\n", method_name, layer, MAX_ACTION_LAYERS-1);
- layer = 0;
- }
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, playAction,
- "playAction(name, start_frame, end_frame, layer=0, priority=0 blendin=0, play_mode=ACT_MODE_PLAY, layer_weight=0.0, ipo_flags=0, speed=1.0)\n"
- "Plays an action\n")
-{
- const char* name;
- float start, end, blendin=0.f, speed=1.f, layer_weight=0.f;
- short layer=0, priority=0;
- short ipo_flags=0;
- short play_mode=0;
- short blend_mode=0;
-
- static const char *kwlist[] = {"name", "start_frame", "end_frame", "layer", "priority", "blendin", "play_mode", "layer_weight", "ipo_flags", "speed", "blend_mode", NULL};
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "sff|hhfhfhfh:playAction", const_cast<char**>(kwlist),
- &name, &start, &end, &layer, &priority, &blendin, &play_mode, &layer_weight, &ipo_flags, &speed, &blend_mode))
- return NULL;
-
- layer_check(layer, "playAction");
-
- if (play_mode < 0 || play_mode > BL_Action::ACT_MODE_MAX)
- {
- printf("KX_GameObject.playAction(): given play_mode (%d) is out of range (0 - %d), setting to ACT_MODE_PLAY", play_mode, BL_Action::ACT_MODE_MAX-1);
- play_mode = BL_Action::ACT_MODE_PLAY;
- }
-
- if (blend_mode < 0 || blend_mode > BL_Action::ACT_BLEND_MAX)
- {
- printf("KX_GameObject.playAction(): given blend_mode (%d) is out of range (0 - %d), setting to ACT_BLEND_BLEND", blend_mode, BL_Action::ACT_BLEND_MAX-1);
- blend_mode = BL_Action::ACT_BLEND_BLEND;
- }
-
- if (layer_weight < 0.f || layer_weight > 1.f)
- {
- printf("KX_GameObject.playAction(): given layer_weight (%f) is out of range (0.0 - 1.0), setting to 0.0", layer_weight);
- layer_weight = 0.f;
- }
-
- PlayAction(name, start, end, layer, priority, blendin, play_mode, layer_weight, ipo_flags, speed, blend_mode);
-
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, stopAction,
- "stopAction(layer=0)\n"
- "Stop playing the action on the given layer\n")
-{
- short layer = 0;
-
- if (!PyArg_ParseTuple(args, "|h:stopAction", &layer))
- return NULL;
-
- layer_check(layer, "stopAction");
-
- StopAction(layer);
-
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, getActionFrame,
- "getActionFrame(layer=0)\n"
- "Gets the current frame of the action playing in the supplied layer\n")
-{
- short layer = 0;
-
- if (!PyArg_ParseTuple(args, "|h:getActionFrame", &layer))
- return NULL;
-
- layer_check(layer, "getActionFrame");
-
- return PyFloat_FromDouble(GetActionFrame(layer));
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, getActionName,
- "getActionName(layer=0)\n"
- "Gets the name of the current action playing in the supplied layer\n")
-{
- short layer = 0;
-
- if (!PyArg_ParseTuple(args, "|h:getActionName", &layer))
- return NULL;
-
- layer_check(layer, "getActionName");
-
- return PyUnicode_FromString(GetActionName(layer));
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, setActionFrame,
- "setActionFrame(frame, layer=0)\n"
- "Set the current frame of the action playing in the supplied layer\n")
-{
- short layer = 0;
- float frame;
-
- if (!PyArg_ParseTuple(args, "f|h:setActionFrame", &frame, &layer))
- return NULL;
-
- layer_check(layer, "setActionFrame");
-
- SetActionFrame(layer, frame);
-
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(KX_GameObject, isPlayingAction,
- "isPlayingAction(layer=0)\n"
- "Checks to see if there is an action playing in the given layer\n")
-{
- short layer = 0;
-
- if (!PyArg_ParseTuple(args, "|h:isPlayingAction", &layer))
- return NULL;
-
- layer_check(layer, "isPlayingAction");
-
- return PyBool_FromLong(!IsActionDone(layer));
-}
-
-
-KX_PYMETHODDEF_DOC(KX_GameObject, addDebugProperty,
-"addDebugProperty(name, visible=1)\n"
-"Added or remove a debug property to the debug list.\n")
-{
- KX_Scene *scene = KX_GetActiveScene();
- char *name;
- int visible = 1;
-
- if (!PyArg_ParseTuple(args,"s|i:debugProperty", &name , &visible))
- return NULL;
-
- if (visible) {
- if (!scene->PropertyInDebugList(this, name))
- scene->AddDebugProperty(this, name);
- }
- else {
- scene->RemoveDebugProperty(this, name);
- }
-
- Py_RETURN_NONE;
-}
-
-
-/* dict style access */
-
-
-/* Matches python dict.get(key, [default]) */
-PyObject *KX_GameObject::Pyget(PyObject *args)
-{
- PyObject *key;
- PyObject *def = Py_None;
- PyObject *ret;
-
- if (!PyArg_ParseTuple(args, "O|O:get", &key, &def))
- return NULL;
-
-
- if (PyUnicode_Check(key)) {
- CValue *item = GetProperty(_PyUnicode_AsString(key));
- if (item) {
- ret = item->ConvertValueToPython();
- if (ret)
- return ret;
- else
- return item->GetProxy();
- }
- }
-
- if (m_attr_dict && (ret=PyDict_GetItem(m_attr_dict, key))) {
- Py_INCREF(ret);
- return ret;
- }
-
- Py_INCREF(def);
- return def;
-}
-
-bool ConvertPythonToGameObject(SCA_LogicManager *manager, PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix)
-{
- if (value==NULL) {
- PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
- *object = NULL;
- return false;
- }
-
- if (value==Py_None) {
- *object = NULL;
-
- if (py_none_ok) {
- return true;
- } else {
- PyErr_Format(PyExc_TypeError, "%s, expected KX_GameObject or a KX_GameObject name, None is invalid", error_prefix);
- return false;
- }
- }
-
- if (PyUnicode_Check(value)) {
- *object = (KX_GameObject*)manager->GetGameObjectByName(STR_String( _PyUnicode_AsString(value) ));
-
- if (*object) {
- return true;
- } else {
- PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_GameObject in this scene", error_prefix, _PyUnicode_AsString(value));
- return false;
- }
- }
-
- if (PyObject_TypeCheck(value, &KX_GameObject::Type) ||
- PyObject_TypeCheck(value, &KX_LightObject::Type) ||
- PyObject_TypeCheck(value, &KX_Camera::Type) ||
- PyObject_TypeCheck(value, &KX_FontObject::Type) ||
- PyObject_TypeCheck(value, &KX_NavMeshObject::Type))
- {
- *object = static_cast<KX_GameObject*>BGE_PROXY_REF(value);
-
- /* sets the error */
- if (*object==NULL) {
- PyErr_Format(PyExc_SystemError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix);
- return false;
- }
-
- return true;
- }
-
- *object = NULL;
-
- if (py_none_ok) {
- PyErr_Format(PyExc_TypeError, "%s, expect a KX_GameObject, a string or None", error_prefix);
- } else {
- PyErr_Format(PyExc_TypeError, "%s, expect a KX_GameObject or a string", error_prefix);
- }
-
- return false;
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_GameObject.h b/source/gameengine/Ketsji/KX_GameObject.h
deleted file mode 100644
index 9c582d3e27a..00000000000
--- a/source/gameengine/Ketsji/KX_GameObject.h
+++ /dev/null
@@ -1,1142 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_GameObject.h
- * \ingroup ketsji
- * \brief General KX game object.
- */
-
-#ifndef __KX_GAMEOBJECT_H__
-#define __KX_GAMEOBJECT_H__
-
-#ifdef _MSC_VER
- /* get rid of this stupid "warning 'this' used in initialiser list", generated by VC when including Solid/Sumo */
-# pragma warning (disable:4355)
-#endif
-
-#include <stddef.h>
-
-#include "EXP_ListValue.h"
-#include "SCA_IObject.h"
-#include "SG_Node.h"
-#include "MT_Transform.h"
-#include "MT_CmMatrix4x4.h"
-#include "CTR_Map.h"
-#include "CTR_HashedPtr.h"
-#include "KX_Scene.h"
-#include "KX_KetsjiEngine.h" /* for m_anim_framerate */
-#include "DNA_constraint_types.h" /* for constraint replication */
-#include "DNA_object_types.h"
-#include "SCA_LogicManager.h" /* for ConvertPythonToGameObject to search object names */
-
-//Forward declarations.
-struct KX_ClientObjectInfo;
-class KX_RayCast;
-class RAS_MeshObject;
-class PHY_IGraphicController;
-class PHY_IPhysicsEnvironment;
-class PHY_IPhysicsController;
-class BL_ActionManager;
-struct Object;
-class KX_ObstacleSimulation;
-struct bAction;
-
-#ifdef WITH_PYTHON
-/* utility conversion function */
-bool ConvertPythonToGameObject(SCA_LogicManager *logicmgr, PyObject *value, KX_GameObject **object, bool py_none_ok, const char *error_prefix);
-#endif
-
-#ifdef USE_MATHUTILS
-void KX_GameObject_Mathutils_Callback_Init(void);
-#endif
-
-/**
- * KX_GameObject is the main class for dynamic objects.
- */
-class KX_GameObject : public SCA_IObject
-{
- Py_Header
-protected:
-
- bool m_bDyna;
- KX_ClientObjectInfo* m_pClient_info;
- STR_String m_name;
- STR_String m_text;
- int m_layer;
- std::vector<RAS_MeshObject*> m_meshes;
- std::vector<RAS_MeshObject*> m_lodmeshes;
- int m_currentLodLevel;
- short m_previousLodLevel;
- SG_QList m_meshSlots; // head of mesh slots of this
- struct Object* m_pBlenderObject;
- struct Object* m_pBlenderGroupObject;
-
- bool m_bUseObjectColor;
- bool m_bIsNegativeScaling;
- MT_Vector4 m_objectColor;
-
- // Bit fields for user control over physics collisions
- unsigned short m_userCollisionGroup;
- unsigned short m_userCollisionMask;
-
- // visible = user setting
- // culled = while rendering, depending on camera
- bool m_bVisible;
- bool m_bCulled;
- bool m_bOccluder;
-
- PHY_IPhysicsController* m_pPhysicsController;
- PHY_IGraphicController* m_pGraphicController;
-
- SG_Node* m_pSGNode;
-
- MT_CmMatrix4x4 m_OpenGL_4x4Matrix;
- std::vector<bRigidBodyJointConstraint*> m_constraints;
-
- KX_ObstacleSimulation* m_pObstacleSimulation;
-
- CListValue* m_pInstanceObjects;
- KX_GameObject* m_pDupliGroupObject;
-
- // The action manager is used to play/stop/update actions
- BL_ActionManager* m_actionManager;
-
- BL_ActionManager* GetActionManager();
-
- bool m_bRecordAnimation;
-
-public:
- bool m_isDeformable;
-
- /**
- * KX_GameObject custom infos for ray cast, it contains property name,
- * collision mask, xray flag and hited object.
- * This structure is created during ray cast and passed as argument
- * "data" to functions KX_GameObject::NeedRayCast and KX_GameObject::RayHit.
- */
- struct RayCastData;
-
- /**
- * Helper function for modules that can't include KX_ClientObjectInfo.h
- */
- static KX_GameObject* GetClientObject(KX_ClientObjectInfo* info);
-
-#ifdef WITH_PYTHON
- // Python attributes that wont convert into CValue
- //
- // there are 2 places attributes can be stored, in the CValue,
- // where attributes are converted into BGE's CValue types
- // these can be used with property actuators
- //
- // For the python API, For types that cannot be converted into CValues (lists, dicts, GameObjects)
- // these will be put into "m_attr_dict", logic bricks cannot access them.
- //
- // rules for setting attributes.
- //
- // * there should NEVER be a CValue and a m_attr_dict attribute with matching names. get/sets make sure of this.
- // * if CValue conversion fails, use a PyObject in "m_attr_dict"
- // * when assigning a value, first see if it can be a CValue, if it can remove the "m_attr_dict" and set the CValue
- //
- PyObject* m_attr_dict;
- PyObject* m_collisionCallbacks;
-#endif
-
- virtual void /* This function should be virtual - derived classed override it */
- Relink(
- CTR_Map<CTR_HashedPtr, void*> *map
- );
-
- /**
- * Compute an OpenGl compatible 4x4 matrix. Has the
- * side effect of storing the result internally. The
- * memory for the matrix remains the property of this class.
- */
- float *
- GetOpenGLMatrix(
- );
-
- /**
- * Return a pointer to a MT_CmMatrix4x4 storing the
- * opengl transformation for this object. This is updated
- * by a call to GetOpenGLMatrix(). This class owns the
- * memory for the returned matrix.
- */
-
- MT_CmMatrix4x4 *
- GetOpenGLMatrixPtr(
- ) {
- return &m_OpenGL_4x4Matrix;
- };
-
- /**
- * Update the blender object obmat field from the object world position
- * if blendobj is NULL, update the object pointed by m_pBlenderObject
- * The user must take action to restore the matrix before leaving the GE.
- * Used in Armature evaluation
- */
- void
- UpdateBlenderObjectMatrix(Object* blendobj=NULL);
-
- /**
- * Used for constraint replication for group instances.
- * The list of constraints is filled during data conversion.
- */
- void AddConstraint(bRigidBodyJointConstraint *cons);
- std::vector<bRigidBodyJointConstraint*> GetConstraints();
- void ClearConstraints();
-
- /**
- * Get a pointer to the game object that is the parent of
- * this object. Or NULL if there is no parent. The returned
- * object is part of a reference counting scheme. Calling
- * this function ups the reference count on the returned
- * object. It is the responsibility of the caller to decrement
- * the reference count when you have finished with it.
- */
- KX_GameObject*
- GetParent(
- );
-
- /**
- * Sets the parent of this object to a game object
- */
- void SetParent(KX_Scene *scene, KX_GameObject *obj, bool addToCompound=true, bool ghost=true);
-
- /**
- * Removes the parent of this object to a game object
- */
- void RemoveParent(KX_Scene *scene);
-
- /*********************************
- * group reference API
- *********************************/
-
- KX_GameObject*
- GetDupliGroupObject(
- );
-
- CListValue*
- GetInstanceObjects(
- );
-
- void
- SetDupliGroupObject(KX_GameObject*
- );
-
- void
- AddInstanceObjects(KX_GameObject*
- );
-
- void
- RemoveDupliGroupObject(
- );
-
- void
- RemoveInstanceObject(KX_GameObject*
- );
- /*********************************
- * Animation API
- *********************************/
-
- /**
- * Adds an action to the object's action manager
- */
- bool PlayAction(const char* name,
- float start,
- float end,
- short layer=0,
- short priority=0,
- float blendin=0.f,
- short play_mode=0,
- float layer_weight=0.f,
- short ipo_flags=0,
- float playback_speed=1.f,
- short blend_mode=0);
-
- /**
- * Gets the current frame of an action
- */
- float GetActionFrame(short layer);
-
- /**
- * Gets the name of the current action
- */
- const char *GetActionName(short layer);
-
- /**
- * Sets the current frame of an action
- */
- void SetActionFrame(short layer, float frame);
-
- /**
- * Gets the currently running action on the given layer
- */
- bAction *GetCurrentAction(short layer);
-
- /**
- * Sets play mode of the action on the given layer
- */
- void SetPlayMode(short layer, short mode);
-
- /**
- * Sets the start and end times of the action on the given layer
- */
- void SetTimes(short layer, float start, float end);
-
- /**
- * Stop playing the action on the given layer
- */
- void StopAction(short layer);
-
- /**
- * Remove playing tagged actions.
- */
- void RemoveTaggedActions();
-
- /**
- * Check if an action has finished playing
- */
- bool IsActionDone(short layer);
-
- /**
- * Kick the object's action manager
- */
- void UpdateActionManager(float curtime);
-
- /*********************************
- * End Animation API
- *********************************/
-
- /**
- * Construct a game object. This class also inherits the
- * default constructors - use those with care!
- */
-
- KX_GameObject(
- void* sgReplicationInfo,
- SG_Callbacks callbacks
- );
-
- virtual
- ~KX_GameObject(
- );
-
- /**
- * \section Stuff which is here due to poor design.
- * Inherited from CValue and needs an implementation.
- * Do not expect these functions do to anything sensible.
- */
-
- /**
- * Inherited from CValue -- does nothing!
- */
- CValue*
- Calc(
- VALUE_OPERATOR op,
- CValue *val
- );
-
- /**
- * Inherited from CValue -- does nothing!
- */
- CValue*
- CalcFinal(
- VALUE_DATA_TYPE dtype,
- VALUE_OPERATOR op,
- CValue *val
- );
-
- /**
- * Inherited from CValue -- does nothing!
- */
- const
- STR_String &
- GetText(
- );
-
- /**
- * Inherited from CValue -- does nothing!
- */
- double
- GetNumber(
- );
-
- /**
- * \section Inherited from CValue. These are the useful
- * part of the CValue interface that this class implements.
- */
-
- /**
- * Inherited from CValue -- returns the name of this object.
- */
- STR_String&
- GetName(
- );
-
- /**
- * Inherited from CValue -- set the name of this object.
- */
- void
- SetName(
- const char *name
- );
-
- /**
- * Inherited from CValue -- return a new copy of this
- * instance allocated on the heap. Ownership of the new
- * object belongs with the caller.
- */
- virtual CValue*
- GetReplica(
- );
-
- /**
- * Inherited from CValue -- Makes sure any internal
- * data owned by this class is deep copied. Called internally
- */
- virtual void
- ProcessReplica();
-
- /**
- * Return the linear velocity of the game object.
- */
- MT_Vector3
- GetLinearVelocity(
- bool local=false
- );
-
- /**
- * Return the linear velocity of a given point in world coordinate
- * but relative to center of object ([0,0,0]=center of object)
- */
- MT_Vector3
- GetVelocity(
- const MT_Point3& position
- );
-
- /**
- * Return the mass of the object
- */
- MT_Scalar
- GetMass();
-
- /**
- * Return the local inertia vector of the object
- */
- MT_Vector3
- GetLocalInertia();
-
- /**
- * Return the angular velocity of the game object.
- */
- MT_Vector3
- GetAngularVelocity(
- bool local=false
- );
-
- /**
- * Align the object to a given normal.
- */
- void
- AlignAxisToVect(
- const MT_Vector3& vect,
- int axis = 2,
- float fac = 1.0
- );
-
- /**
- * Quick'n'dirty obcolor ipo stuff
- */
-
- void
- SetObjectColor(
- const MT_Vector4& rgbavec
- );
-
- const MT_Vector4&
- GetObjectColor();
-
-
- void
- ResolveCombinedVelocities(
- const MT_Vector3 & lin_vel,
- const MT_Vector3 & ang_vel,
- bool lin_vel_local,
- bool ang_vel_local
- );
-
- /**
- * \return a pointer to the physics controller owned by this class.
- */
-
- PHY_IPhysicsController* GetPhysicsController();
-
- void SetPhysicsController(PHY_IPhysicsController* physicscontroller,bool isDynamic)
- {
- m_bDyna = isDynamic;
- m_pPhysicsController = physicscontroller;
- }
-
- virtual class RAS_Deformer* GetDeformer()
- {
- return 0;
- }
- virtual void SetDeformer(class RAS_Deformer* deformer)
- {
-
- }
-
- /**
- * \return a pointer to the graphic controller owner by this class
- */
- PHY_IGraphicController* GetGraphicController()
- {
- return m_pGraphicController;
- }
-
- void SetGraphicController(PHY_IGraphicController* graphiccontroller)
- {
- m_pGraphicController = graphiccontroller;
- }
- /*
- * @add/remove the graphic controller to the physic system
- */
- void ActivateGraphicController(bool recurse);
-
- /** Set the object's collison group
- * \param filter The group bitfield
- */
- void SetUserCollisionGroup(unsigned short filter);
-
- /** Set the object's collison mask
- * \param filter The mask bitfield
- */
- void SetUserCollisionMask(unsigned short mask);
- unsigned short GetUserCollisionGroup();
- unsigned short GetUserCollisionMask();
- /**
- * Extra broadphase check for user controllable collisions
- */
- bool CheckCollision(KX_GameObject *other);
-
- /**
- * \section Coordinate system manipulation functions
- */
-
- void NodeSetLocalPosition(const MT_Point3& trans );
-
- void NodeSetLocalOrientation(const MT_Matrix3x3& rot );
- void NodeSetGlobalOrientation(const MT_Matrix3x3& rot );
-
- void NodeSetLocalScale( const MT_Vector3& scale );
- void NodeSetWorldScale( const MT_Vector3& scale );
-
- void NodeSetRelativeScale( const MT_Vector3& scale );
-
- // adapt local position so that world position is set to desired position
- void NodeSetWorldPosition(const MT_Point3& trans);
-
- void
- NodeUpdateGS(
- double time
- );
-
- const MT_Matrix3x3& NodeGetWorldOrientation( ) const;
- const MT_Vector3& NodeGetWorldScaling( ) const;
- const MT_Point3& NodeGetWorldPosition( ) const;
-
- const MT_Matrix3x3& NodeGetLocalOrientation( ) const;
- const MT_Vector3& NodeGetLocalScaling( ) const;
- const MT_Point3& NodeGetLocalPosition( ) const;
-
- /**
- * \section scene graph node accessor functions.
- */
-
- SG_Node* GetSGNode( )
- {
- return m_pSGNode;
- }
-
- const SG_Node* GetSGNode( ) const
- {
- return m_pSGNode;
- }
-
- /**
- * \section blender object accessor functions.
- */
-
- struct Object* GetBlenderObject( )
- {
- return m_pBlenderObject;
- }
-
- void SetBlenderObject(struct Object* obj)
- {
- m_pBlenderObject = obj;
- }
-
- struct Object* GetBlenderGroupObject( )
- {
- return m_pBlenderGroupObject;
- }
-
- void SetBlenderGroupObject(struct Object* obj)
- {
- m_pBlenderGroupObject = obj;
- }
-
- bool IsDupliGroup()
- {
- return (m_pBlenderObject &&
- (m_pBlenderObject->transflag & OB_DUPLIGROUP) &&
- m_pBlenderObject->dup_group != NULL) ? true : false;
- }
-
- /**
- * Set the Scene graph node for this game object.
- * warning - it is your responsibility to make sure
- * all controllers look at this new node. You must
- * also take care of the memory associated with the
- * old node. This class takes ownership of the new
- * node.
- */
- void SetSGNode(SG_Node* node )
- {
- m_pSGNode = node;
- }
-
- //Is it a dynamic/physics object ?
- bool IsDynamic() const
- {
- return m_bDyna;
- }
-
- bool IsDynamicsSuspended() const;
-
- /**
- * Should we record animation for this object?
- */
-
- void SetRecordAnimation(bool recordAnimation)
- {
- m_bRecordAnimation = recordAnimation;
- }
-
- bool IsRecordAnimation() const
- {
- return m_bRecordAnimation;
- }
-
- /**
- * Check if this object has a vertex parent relationship
- */
- bool IsVertexParent( )
- {
- return (m_pSGNode && m_pSGNode->GetSGParent() && m_pSGNode->GetSGParent()->IsVertexParent());
- }
-
- /// \see KX_RayCast
- bool RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, RayCastData *rayData);
- /// \see KX_RayCast
- bool NeedRayCast(KX_ClientObjectInfo *client, RayCastData *rayData);
-
-
- /**
- * \section Physics accessors for this node.
- *
- * All these calls get passed directly to the physics controller
- * owned by this object.
- * This is real interface bloat. Why not just use the physics controller
- * directly? I think this is because the python interface is in the wrong
- * place.
- */
-
- void
- ApplyForce(
- const MT_Vector3& force, bool local
- );
-
- void
- ApplyTorque(
- const MT_Vector3& torque,
- bool local
- );
-
- void
- ApplyRotation(
- const MT_Vector3& drot,
- bool local
- );
-
- void
- ApplyMovement(
- const MT_Vector3& dloc,
- bool local
- );
-
- void
- addLinearVelocity(
- const MT_Vector3& lin_vel,
- bool local
- );
-
- void
- setLinearVelocity(
- const MT_Vector3& lin_vel,
- bool local
- );
-
- void
- setAngularVelocity(
- const MT_Vector3& ang_vel,
- bool local
- );
-
- virtual float getLinearDamping() const;
- virtual float getAngularDamping() const;
- virtual void setLinearDamping(float damping);
- virtual void setAngularDamping(float damping);
- virtual void setDamping(float linear, float angular);
-
- /**
- * Update the physics object transform based upon the current SG_Node
- * position.
- */
- void
- UpdateTransform(
- );
-
- static void UpdateTransformFunc(SG_IObject* node, void* gameobj, void* scene);
-
- /**
- * only used for sensor objects
- */
- void SynchronizeTransform();
-
- static void SynchronizeTransformFunc(SG_IObject* node, void* gameobj, void* scene);
-
- /**
- * Function to set IPO option at start of IPO
- */
- void
- InitIPO(
- bool ipo_as_force,
- bool ipo_add,
- bool ipo_local
- );
-
- /**
- * Odd function to update an ipo. ???
- */
- void
- UpdateIPO(
- float curframetime,
- bool recurse
- );
- /**
- * Updates Material Ipo data
- */
- void
- UpdateMaterialData(
- dword matname_hash,
- MT_Vector4 rgba,
- MT_Vector3 specrgb,
- MT_Scalar hard,
- MT_Scalar spec,
- MT_Scalar ref,
- MT_Scalar emit,
- MT_Scalar alpha
- );
-
- /**
- * \section Mesh accessor functions.
- */
-
- /**
- * Update buckets to indicate that there is a new
- * user of this object's meshes.
- */
- void
- AddMeshUser(
- );
-
- /**
- * Update buckets with data about the mesh after
- * creating or duplicating the object, changing
- * visibility, object color, .. .
- */
- void
- UpdateBuckets(
- bool recursive
- );
-
- /**
- * Clear the meshes associated with this class
- * and remove from the bucketing system.
- * Don't think this actually deletes any of the meshes.
- */
- void
- RemoveMeshes(
- );
-
- /**
- * Add a mesh to the set of meshes associated with this
- * node. Meshes added in this way are not deleted by this class.
- * Make sure you call RemoveMeshes() before deleting the
- * mesh though,
- */
- void
- AddMesh(
- RAS_MeshObject* mesh
- ) {
- m_meshes.push_back(mesh);
- }
-
- /**
- * Add a level of detail mesh to the object. These should
- * be added in order.
- */
- void
- AddLodMesh(
- RAS_MeshObject* mesh
- );
-
- /**
- * Updates the current lod level based on distance from camera.
- */
- void
- UpdateLod(
- MT_Vector3 &cam_pos
- );
-
- /**
- * Pick out a mesh associated with the integer 'num'.
- */
- RAS_MeshObject*
- GetMesh(
- int num
- ) const {
- return m_meshes[num];
- }
-
- /**
- * Return the number of meshes currently associated with this
- * game object.
- */
- int
- GetMeshCount(
- ) const {
- return m_meshes.size();
- }
-
- /**
- * Set the debug color of the meshes associated with this
- * class. Does this still work?
- */
- void
- SetDebugColor(
- unsigned int bgra
- );
-
- /**
- * Reset the debug color of meshes associated with this class.
- */
- void
- ResetDebugColor(
- );
-
- /**
- * Was this object marked visible? (only for the explicit
- * visibility system).
- */
- bool
- GetVisible(
- void
- );
-
- /**
- * Set visibility flag of this object
- */
- void
- SetVisible(
- bool b,
- bool recursive
- );
-
- /**
- * Was this object culled?
- */
- inline bool
- GetCulled(
- void
- ) { return m_bCulled; }
-
- /**
- * Set culled flag of this object
- */
- inline void
- SetCulled(
- bool c
- ) { m_bCulled = c; }
-
- /**
- * Is this object an occluder?
- */
- inline bool
- GetOccluder(
- void
- ) { return m_bOccluder; }
-
- /**
- * Set occluder flag of this object
- */
- void
- SetOccluder(
- bool v,
- bool recursive
- );
-
- /**
- * Change the layer of the object (when it is added in another layer
- * than the original layer)
- */
- virtual void
- SetLayer(
- int l
- );
-
- /**
- * Get the object layer
- */
- int
- GetLayer(
- void
- );
-
- /**
- * Get the negative scaling state
- */
- bool
- IsNegativeScaling(
- void
- ) { return m_bIsNegativeScaling; }
-
- /**
- * \section Logic bubbling methods.
- */
-
- void RegisterCollisionCallbacks();
- void UnregisterCollisionCallbacks();
- void RunCollisionCallbacks(KX_GameObject *collider, const MT_Vector3 &point, const MT_Vector3 &normal);
- /**
- * Stop making progress
- */
- void Suspend(void);
-
- /**
- * Resume making progress
- */
- void Resume(void);
-
- void RegisterObstacle(KX_ObstacleSimulation* obstacleSimulation)
- {
- m_pObstacleSimulation = obstacleSimulation;
- }
-
- void UnregisterObstacle()
- {
- m_pObstacleSimulation = NULL;
- }
-
- /**
- * add debug object to the debuglist.
- */
- void SetUseDebugProperties(bool debug, bool recursive);
-
- KX_ClientObjectInfo* getClientInfo() { return m_pClient_info; }
-
- CListValue* GetChildren();
- CListValue* GetChildrenRecursive();
-
- KX_Scene* GetScene();
-
-#ifdef WITH_PYTHON
- /**
- * \section Python interface functions.
- */
- virtual PyObject *py_repr(void)
- {
- return PyUnicode_From_STR_String(GetName());
- }
-
- KX_PYMETHOD_O(KX_GameObject,SetWorldPosition);
- KX_PYMETHOD_VARARGS(KX_GameObject, ApplyForce);
- KX_PYMETHOD_VARARGS(KX_GameObject, ApplyTorque);
- KX_PYMETHOD_VARARGS(KX_GameObject, ApplyRotation);
- KX_PYMETHOD_VARARGS(KX_GameObject, ApplyMovement);
- KX_PYMETHOD_VARARGS(KX_GameObject,GetLinearVelocity);
- KX_PYMETHOD_VARARGS(KX_GameObject,SetLinearVelocity);
- KX_PYMETHOD_VARARGS(KX_GameObject,GetAngularVelocity);
- KX_PYMETHOD_VARARGS(KX_GameObject,SetAngularVelocity);
- KX_PYMETHOD_VARARGS(KX_GameObject,GetVelocity);
- KX_PYMETHOD_VARARGS(KX_GameObject,SetDamping);
-
- KX_PYMETHOD_NOARGS(KX_GameObject,GetReactionForce);
-
-
- KX_PYMETHOD_NOARGS(KX_GameObject,GetVisible);
- KX_PYMETHOD_VARARGS(KX_GameObject,SetVisible);
- KX_PYMETHOD_VARARGS(KX_GameObject,SetOcclusion);
- KX_PYMETHOD_NOARGS(KX_GameObject,GetState);
- KX_PYMETHOD_O(KX_GameObject,SetState);
- KX_PYMETHOD_VARARGS(KX_GameObject,AlignAxisToVect);
- KX_PYMETHOD_O(KX_GameObject,GetAxisVect);
- KX_PYMETHOD_VARARGS(KX_GameObject,SuspendDynamics);
- KX_PYMETHOD_NOARGS(KX_GameObject,RestoreDynamics);
- KX_PYMETHOD_NOARGS(KX_GameObject,EnableRigidBody);
- KX_PYMETHOD_NOARGS(KX_GameObject,DisableRigidBody);
- KX_PYMETHOD_VARARGS(KX_GameObject,ApplyImpulse);
- KX_PYMETHOD_O(KX_GameObject,SetCollisionMargin);
- KX_PYMETHOD_NOARGS(KX_GameObject,GetParent);
- KX_PYMETHOD_VARARGS(KX_GameObject,SetParent);
- KX_PYMETHOD_NOARGS(KX_GameObject,RemoveParent);
- KX_PYMETHOD_NOARGS(KX_GameObject,GetChildren);
- KX_PYMETHOD_NOARGS(KX_GameObject,GetChildrenRecursive);
- KX_PYMETHOD_VARARGS(KX_GameObject,GetMesh);
- KX_PYMETHOD_NOARGS(KX_GameObject,GetPhysicsId);
- KX_PYMETHOD_NOARGS(KX_GameObject,GetPropertyNames);
- KX_PYMETHOD_VARARGS(KX_GameObject,ReplaceMesh);
- KX_PYMETHOD_NOARGS(KX_GameObject,EndObject);
- KX_PYMETHOD_DOC(KX_GameObject,rayCastTo);
- KX_PYMETHOD_DOC(KX_GameObject,rayCast);
- KX_PYMETHOD_DOC_O(KX_GameObject,getDistanceTo);
- KX_PYMETHOD_DOC_O(KX_GameObject,getVectTo);
- KX_PYMETHOD_DOC_VARARGS(KX_GameObject, sendMessage);
- KX_PYMETHOD_VARARGS(KX_GameObject, ReinstancePhysicsMesh);
- KX_PYMETHOD_DOC(KX_GameObject, addDebugProperty);
-
- KX_PYMETHOD_DOC(KX_GameObject, playAction);
- KX_PYMETHOD_DOC(KX_GameObject, stopAction);
- KX_PYMETHOD_DOC(KX_GameObject, getActionFrame);
- KX_PYMETHOD_DOC(KX_GameObject, getActionName);
- KX_PYMETHOD_DOC(KX_GameObject, setActionFrame);
- KX_PYMETHOD_DOC(KX_GameObject, isPlayingAction);
-
- /* Dict access */
- KX_PYMETHOD_VARARGS(KX_GameObject,get);
-
- /* attributes */
- static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_parent(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- static PyObject* pyattr_get_group_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_group_members(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_scene(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- static PyObject* pyattr_get_life(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_mass(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_is_suspend_dynamics(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_lin_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_lin_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_ang_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_ang_vel_min(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_ang_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_ang_vel_max(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_record_animation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_record_animation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_worldPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_localPosition(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_localInertia(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_worldOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_localOrientation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_worldScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_localScaling(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_localTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_worldTransform(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_worldLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_localLinearVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_worldAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_localAngularVelocity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_timeOffset(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_state(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_meshes(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_children(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_children_recursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_attrDict(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_obcolor(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_obcolor(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_collisionCallbacks(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_collisionCallbacks(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_collisionGroup(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_collisionGroup(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_collisionMask(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_collisionMask(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_debug(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_debugRecursive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_linearDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_linearDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_angularDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_angularDamping(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- /* Experimental! */
- static PyObject* pyattr_get_sensors(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_controllers(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_actuators(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- /* getitem/setitem */
- static PyMappingMethods Mapping;
- static PySequenceMethods Sequence;
-#endif
-};
-
-
-
-#endif /* __KX_GAMEOBJECT_H__ */
diff --git a/source/gameengine/Ketsji/KX_IInterpolator.h b/source/gameengine/Ketsji/KX_IInterpolator.h
deleted file mode 100644
index 6c0bf2d85cc..00000000000
--- a/source/gameengine/Ketsji/KX_IInterpolator.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_IInterpolator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_IINTERPOLATOR_H__
-#define __KX_IINTERPOLATOR_H__
-
-#include <vector>
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class KX_IInterpolator {
-public:
- virtual ~KX_IInterpolator() {}
-
- virtual void Execute(float currentTime) const = 0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_IInterpolator")
-#endif
-};
-
-typedef std::vector<KX_IInterpolator *> T_InterpolatorList;
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_IPOTransform.h b/source/gameengine/Ketsji/KX_IPOTransform.h
deleted file mode 100644
index a81c432b01e..00000000000
--- a/source/gameengine/Ketsji/KX_IPOTransform.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_IPOTransform.h
- * \ingroup ketsji
- * \brief An abstract object you can move around in a 3d world, and has some logic
- */
-
-#ifndef __KX_IPOTRANSFORM_H__
-#define __KX_IPOTRANSFORM_H__
-
-#include "MT_Transform.h"
-
-class KX_IPOTransform {
-public:
- KX_IPOTransform() :
- m_position(0.0f, 0.0f, 0.0f),
- m_eulerAngles(0.0f, 0.0f, 0.0f),
- m_scaling(1.0f, 1.0f, 1.0f),
- m_deltaPosition(0.0f, 0.0f, 0.0f),
- m_deltaEulerAngles(0.0f, 0.0f, 0.0f),
- m_deltaScaling(0.0f, 0.0f, 0.0f)
- {}
-
- MT_Transform GetTransform() const {
- return MT_Transform(m_position + m_deltaPosition,
- MT_Matrix3x3(m_eulerAngles + m_deltaEulerAngles,
- m_scaling + m_deltaScaling));
- }
-
- MT_Point3& GetPosition() { return m_position; }
- MT_Vector3& GetEulerAngles() { return m_eulerAngles; }
- MT_Vector3& GetScaling() { return m_scaling; }
-
- const MT_Point3& GetPosition() const { return m_position; }
- const MT_Vector3& GetEulerAngles() const { return m_eulerAngles; }
- const MT_Vector3& GetScaling() const { return m_scaling; }
-
- MT_Vector3& GetDeltaPosition() { return m_deltaPosition; }
- MT_Vector3& GetDeltaEulerAngles() { return m_deltaEulerAngles; }
- MT_Vector3& GetDeltaScaling() { return m_deltaScaling; }
-
- void SetPosition(const MT_Point3& pos) { m_position = pos; }
- void SetEulerAngles(const MT_Vector3& eul) { m_eulerAngles = eul; }
- void SetScaling(const MT_Vector3& scaling) { m_scaling = scaling; }
-
- void ClearDeltaStuff() {
- m_deltaPosition.setValue(0.0f, 0.0f, 0.0f);
- m_deltaEulerAngles.setValue(0.0f, 0.0f, 0.0f);
- m_deltaScaling.setValue(0.0f, 0.0f, 0.0f);
- }
-
-protected:
- MT_Point3 m_position;
- MT_Vector3 m_eulerAngles;
- MT_Vector3 m_scaling;
- MT_Vector3 m_deltaPosition;
- MT_Vector3 m_deltaEulerAngles;
- MT_Vector3 m_deltaScaling;
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_IPO_SGController.cpp b/source/gameengine/Ketsji/KX_IPO_SGController.cpp
deleted file mode 100644
index be1a4b4ef3a..00000000000
--- a/source/gameengine/Ketsji/KX_IPO_SGController.cpp
+++ /dev/null
@@ -1,373 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Scenegraph controller for ipos.
- */
-
-/** \file gameengine/Ketsji/KX_IPO_SGController.cpp
- * \ingroup ketsji
- */
-
-
-#if defined(_WIN64)
-typedef unsigned __int64 uint_ptr;
-#else
-typedef unsigned long uint_ptr;
-#endif
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning(disable:4786)
-#endif
-
-#include "KX_IPO_SGController.h"
-#include "KX_ScalarInterpolator.h"
-#include "KX_GameObject.h"
-#include "PHY_IPhysicsController.h"
-#include "DNA_ipo_types.h"
-#include "BLI_math.h"
-
-// All objects should start on frame 1! Will we ever need an object to
-// start on another frame, the 1.0 should change.
-KX_IpoSGController::KX_IpoSGController()
-: m_ipo_as_force(false),
- m_ipo_add(false),
- m_ipo_local(false),
- m_modified(true),
- m_ipotime(1.0),
- m_ipo_start_initialized(false),
- m_ipo_start_euler(0.0f, 0.0f, 0.0f),
- m_ipo_euler_initialized(false)
-{
- m_game_object = NULL;
- for (int i = 0; i < KX_MAX_IPO_CHANNELS; i++)
- m_ipo_channels_active[i] = false;
-}
-
-
-void KX_IpoSGController::SetOption(int option, int value)
-{
- switch (option) {
- case SG_CONTR_IPO_IPO_AS_FORCE:
- m_ipo_as_force = (value != 0);
- m_modified = true;
- break;
- case SG_CONTR_IPO_IPO_ADD:
- m_ipo_add = (value != 0);
- m_modified = true;
- break;
- case SG_CONTR_IPO_RESET:
- if (m_ipo_start_initialized && value) {
- m_ipo_start_initialized = false;
- m_modified = true;
- }
- break;
- case SG_CONTR_IPO_LOCAL:
- if (value/* && ((SG_Node*)m_pObject)->GetSGParent() == NULL*/) {
- // only accept local Ipo if the object has no parent
- m_ipo_local = true;
- }
- else {
- m_ipo_local = false;
- }
- m_modified = true;
- break;
- default:
- ; /* just ignore the rest */
- }
-}
-
-void KX_IpoSGController::UpdateSumoReference()
-{
- if (m_game_object) {
- }
-}
-
-void KX_IpoSGController::SetGameObject(KX_GameObject *go)
-{
- m_game_object = go;
-}
-
-bool KX_IpoSGController::Update(double currentTime)
-{
- if (m_modified) {
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); i != m_interpolators.end(); ++i) {
- (*i)->Execute(m_ipotime);//currentTime);
- }
-
- SG_Spatial *ob = (SG_Spatial *)m_pObject;
-
- //initialization on the first frame of the IPO
- if (!m_ipo_start_initialized) {
- m_ipo_start_point = ob->GetLocalPosition();
- m_ipo_start_orient = ob->GetLocalOrientation();
- m_ipo_start_scale = ob->GetLocalScale();
- m_ipo_start_initialized = true;
- if (!m_ipo_euler_initialized) {
- // do it only once to avoid angle discontinuities
- m_ipo_start_orient.getEuler(m_ipo_start_euler[0], m_ipo_start_euler[1], m_ipo_start_euler[2]);
- m_ipo_euler_initialized = true;
- }
- }
-
- //modifies position?
- if (m_ipo_channels_active[OB_LOC_X] || m_ipo_channels_active[OB_LOC_Y] || m_ipo_channels_active[OB_LOC_Z] ||
- m_ipo_channels_active[OB_DLOC_X] || m_ipo_channels_active[OB_DLOC_Y] || m_ipo_channels_active[OB_DLOC_Z])
- {
- if (m_ipo_as_force == true) {
- if (m_game_object && ob && m_game_object->GetPhysicsController()) {
- MT_Vector3 vec = m_ipo_local ?
- ob->GetWorldOrientation() * m_ipo_xform.GetPosition() :
- m_ipo_xform.GetPosition();
- m_game_object->GetPhysicsController()->ApplyForce(vec, false);
- }
- }
- else {
- // Local ipo should be defined with the object position at (0,0,0)
- // Local transform is applied to the object based on initial position
- MT_Point3 newPosition(0.0f, 0.0f, 0.0f);
-
- if (!m_ipo_add)
- newPosition = ob->GetLocalPosition();
- //apply separate IPO channels if there is any data in them
- //Loc and dLoc act by themselves or are additive
- //LocX and dLocX
- if (m_ipo_channels_active[OB_LOC_X]) {
- newPosition[0] = (m_ipo_channels_active[OB_DLOC_X] ? m_ipo_xform.GetPosition()[0] + m_ipo_xform.GetDeltaPosition()[0] : m_ipo_xform.GetPosition()[0]);
- }
- else if (m_ipo_channels_active[OB_DLOC_X] && m_ipo_start_initialized) {
- newPosition[0] = (((!m_ipo_add) ? m_ipo_start_point[0] : 0.0f) + m_ipo_xform.GetDeltaPosition()[0]);
- }
- //LocY and dLocY
- if (m_ipo_channels_active[OB_LOC_Y]) {
- newPosition[1] = (m_ipo_channels_active[OB_DLOC_Y] ? m_ipo_xform.GetPosition()[1] + m_ipo_xform.GetDeltaPosition()[1] : m_ipo_xform.GetPosition()[1]);
- }
- else if (m_ipo_channels_active[OB_DLOC_Y] && m_ipo_start_initialized) {
- newPosition[1] = (((!m_ipo_add) ? m_ipo_start_point[1] : 0.0f) + m_ipo_xform.GetDeltaPosition()[1]);
- }
- //LocZ and dLocZ
- if (m_ipo_channels_active[OB_LOC_Z]) {
- newPosition[2] = (m_ipo_channels_active[OB_DLOC_Z] ? m_ipo_xform.GetPosition()[2] + m_ipo_xform.GetDeltaPosition()[2] : m_ipo_xform.GetPosition()[2]);
- }
- else if (m_ipo_channels_active[OB_DLOC_Z] && m_ipo_start_initialized) {
- newPosition[2] = (((!m_ipo_add) ? m_ipo_start_point[2] : 0.0f) + m_ipo_xform.GetDeltaPosition()[2]);
- }
- if (m_ipo_add) {
- if (m_ipo_local)
- newPosition = m_ipo_start_point + m_ipo_start_scale*(m_ipo_start_orient*newPosition);
- else
- newPosition = m_ipo_start_point + newPosition;
- }
- if (m_game_object)
- m_game_object->NodeSetLocalPosition(newPosition);
- }
- }
- //modifies orientation?
- if (m_ipo_channels_active[OB_ROT_X] || m_ipo_channels_active[OB_ROT_Y] || m_ipo_channels_active[OB_ROT_Z] ||
- m_ipo_channels_active[OB_DROT_X] || m_ipo_channels_active[OB_DROT_Y] || m_ipo_channels_active[OB_DROT_Z])
- {
- if (m_ipo_as_force) {
- if (m_game_object && ob) {
- m_game_object->ApplyTorque(m_ipo_local ?
- ob->GetWorldOrientation() * m_ipo_xform.GetEulerAngles() :
- m_ipo_xform.GetEulerAngles(), false);
- }
- }
- else if (m_ipo_add) {
- if (m_ipo_start_initialized) {
- double yaw = 0.0, pitch = 0.0, roll = 0.0; //delta Euler angles
-
- //RotX and dRotX
- if (m_ipo_channels_active[OB_ROT_X])
- yaw += m_ipo_xform.GetEulerAngles()[0];
- if (m_ipo_channels_active[OB_DROT_X])
- yaw += m_ipo_xform.GetDeltaEulerAngles()[0];
-
- //RotY dRotY
- if (m_ipo_channels_active[OB_ROT_Y])
- pitch += m_ipo_xform.GetEulerAngles()[1];
- if (m_ipo_channels_active[OB_DROT_Y])
- pitch += m_ipo_xform.GetDeltaEulerAngles()[1];
-
- //RotZ and dRotZ
- if (m_ipo_channels_active[OB_ROT_Z])
- roll += m_ipo_xform.GetEulerAngles()[2];
- if (m_ipo_channels_active[OB_DROT_Z])
- roll += m_ipo_xform.GetDeltaEulerAngles()[2];
-
- MT_Matrix3x3 rotation(MT_Vector3(yaw, pitch, roll));
- if (m_ipo_local)
- rotation = m_ipo_start_orient * rotation;
- else
- rotation = rotation * m_ipo_start_orient;
- if (m_game_object)
- m_game_object->NodeSetLocalOrientation(rotation);
- }
- }
- else if (m_ipo_channels_active[OB_ROT_X] || m_ipo_channels_active[OB_ROT_Y] || m_ipo_channels_active[OB_ROT_Z]) {
- if (m_ipo_euler_initialized) {
- // assume all channel absolute
- // All 3 channels should be specified but if they are not, we will take
- // the value at the start of the game to avoid angle sign reversal
- double yaw = m_ipo_start_euler[0], pitch = m_ipo_start_euler[1], roll = m_ipo_start_euler[2];
-
- //RotX and dRotX
- if (m_ipo_channels_active[OB_ROT_X]) {
- yaw = (m_ipo_channels_active[OB_DROT_X] ? (m_ipo_xform.GetEulerAngles()[0] + m_ipo_xform.GetDeltaEulerAngles()[0]) : m_ipo_xform.GetEulerAngles()[0] );
- }
- else if (m_ipo_channels_active[OB_DROT_X]) {
- yaw += m_ipo_xform.GetDeltaEulerAngles()[0];
- }
-
- //RotY dRotY
- if (m_ipo_channels_active[OB_ROT_Y]) {
- pitch = (m_ipo_channels_active[OB_DROT_Y] ? (m_ipo_xform.GetEulerAngles()[1] + m_ipo_xform.GetDeltaEulerAngles()[1]) : m_ipo_xform.GetEulerAngles()[1] );
- }
- else if (m_ipo_channels_active[OB_DROT_Y]) {
- pitch += m_ipo_xform.GetDeltaEulerAngles()[1];
- }
-
- //RotZ and dRotZ
- if (m_ipo_channels_active[OB_ROT_Z]) {
- roll = (m_ipo_channels_active[OB_DROT_Z] ? (m_ipo_xform.GetEulerAngles()[2] + m_ipo_xform.GetDeltaEulerAngles()[2]) : m_ipo_xform.GetEulerAngles()[2] );
- }
- else if (m_ipo_channels_active[OB_DROT_Z]) {
- roll += m_ipo_xform.GetDeltaEulerAngles()[2];
- }
- if (m_game_object)
- m_game_object->NodeSetLocalOrientation(MT_Vector3(yaw, pitch, roll));
- }
- }
- else if (m_ipo_start_initialized) {
- // only DROT, treat as Add
- double yaw = 0.0, pitch = 0.0, roll = 0.0; //delta Euler angles
-
- //dRotX
- if (m_ipo_channels_active[OB_DROT_X])
- yaw = m_ipo_xform.GetDeltaEulerAngles()[0];
-
- //dRotY
- if (m_ipo_channels_active[OB_DROT_Y])
- pitch = m_ipo_xform.GetDeltaEulerAngles()[1];
-
- //dRotZ
- if (m_ipo_channels_active[OB_DROT_Z])
- roll = m_ipo_xform.GetDeltaEulerAngles()[2];
-
- // dRot are always local
- MT_Matrix3x3 rotation(MT_Vector3(yaw, pitch, roll));
- rotation = m_ipo_start_orient * rotation;
- if (m_game_object)
- m_game_object->NodeSetLocalOrientation(rotation);
- }
- }
- //modifies scale?
- if (m_ipo_channels_active[OB_SIZE_X] || m_ipo_channels_active[OB_SIZE_Y] || m_ipo_channels_active[OB_SIZE_Z] ||
- m_ipo_channels_active[OB_DSIZE_X] || m_ipo_channels_active[OB_DSIZE_Y] || m_ipo_channels_active[OB_DSIZE_Z])
- {
- //default is no scale change
- MT_Vector3 newScale(1.0f, 1.0f, 1.0f);
- if (!m_ipo_add)
- newScale = ob->GetLocalScale();
-
- if (m_ipo_channels_active[OB_SIZE_X]) {
- newScale[0] = (m_ipo_channels_active[OB_DSIZE_X] ? (m_ipo_xform.GetScaling()[0] + m_ipo_xform.GetDeltaScaling()[0]) : m_ipo_xform.GetScaling()[0]);
- }
- else if (m_ipo_channels_active[OB_DSIZE_X] && m_ipo_start_initialized) {
- newScale[0] = (m_ipo_xform.GetDeltaScaling()[0] + ((!m_ipo_add) ? m_ipo_start_scale[0] : 0.0f));
- }
-
- //RotY dRotY
- if (m_ipo_channels_active[OB_SIZE_Y]) {
- newScale[1] = (m_ipo_channels_active[OB_DSIZE_Y] ? (m_ipo_xform.GetScaling()[1] + m_ipo_xform.GetDeltaScaling()[1]): m_ipo_xform.GetScaling()[1]);
- }
- else if (m_ipo_channels_active[OB_DSIZE_Y] && m_ipo_start_initialized) {
- newScale[1] = (m_ipo_xform.GetDeltaScaling()[1] + ((!m_ipo_add)?m_ipo_start_scale[1] : 0.0f));
- }
-
- //RotZ and dRotZ
- if (m_ipo_channels_active[OB_SIZE_Z]) {
- newScale[2] = (m_ipo_channels_active[OB_DSIZE_Z] ? (m_ipo_xform.GetScaling()[2] + m_ipo_xform.GetDeltaScaling()[2]) : m_ipo_xform.GetScaling()[2]);
- }
- else if (m_ipo_channels_active[OB_DSIZE_Z] && m_ipo_start_initialized) {
- newScale[2] = (m_ipo_xform.GetDeltaScaling()[2] + ((!m_ipo_add)?m_ipo_start_scale[2] : 1.0f));
- }
-
- if (m_ipo_add) {
- newScale = m_ipo_start_scale * newScale;
- }
- if (m_game_object)
- m_game_object->NodeSetLocalScale(newScale);
- }
- m_modified = false;
- }
- return false;
-}
-
-void KX_IpoSGController::AddInterpolator(KX_IInterpolator *interp)
-{
- m_interpolators.push_back(interp);
-}
-
-SG_Controller *KX_IpoSGController::GetReplica(SG_Node *destnode)
-{
- KX_IpoSGController *iporeplica = new KX_IpoSGController(*this);
- // clear object that ipo acts on in the replica.
- iporeplica->ClearObject();
- iporeplica->SetGameObject((KX_GameObject *)destnode->GetSGClientObject());
-
- // dirty hack, ask Gino for a better solution in the ipo implementation
- // hacken en zagen, in what we call datahiding, not written for replication :(
-
- T_InterpolatorList oldlist = m_interpolators;
- iporeplica->m_interpolators.clear();
-
- T_InterpolatorList::iterator i;
- for (i = oldlist.begin(); i != oldlist.end(); ++i) {
- KX_ScalarInterpolator *copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator *)*i));
- iporeplica->AddInterpolator(copyipo);
-
- MT_Scalar *scaal = ((KX_ScalarInterpolator *)*i)->GetTarget();
- uint_ptr orgbase = (uint_ptr)&m_ipo_xform;
- uint_ptr orgloc = (uint_ptr)scaal;
- uint_ptr offset = orgloc - orgbase;
- uint_ptr newaddrbase = (uint_ptr)&iporeplica->m_ipo_xform;
- newaddrbase += offset;
- MT_Scalar *blaptr = (MT_Scalar *) newaddrbase;
- copyipo->SetNewTarget((MT_Scalar *)blaptr);
- }
-
- return iporeplica;
-}
-
-KX_IpoSGController::~KX_IpoSGController()
-{
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); i != m_interpolators.end(); ++i) {
- delete (*i);
- }
-}
diff --git a/source/gameengine/Ketsji/KX_IPO_SGController.h b/source/gameengine/Ketsji/KX_IPO_SGController.h
deleted file mode 100644
index 3318761bb88..00000000000
--- a/source/gameengine/Ketsji/KX_IPO_SGController.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_IPO_SGController.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_IPO_SGCONTROLLER_H__
-#define __KX_IPO_SGCONTROLLER_H__
-
-#include "SG_Controller.h"
-#include "SG_Spatial.h"
-
-#include "KX_IPOTransform.h"
-#include "KX_IInterpolator.h"
-
-#define KX_MAX_IPO_CHANNELS 19 //note- [0] is not used
-
-class KX_IpoSGController : public SG_Controller
-{
- KX_IPOTransform m_ipo_xform;
- T_InterpolatorList m_interpolators;
-
- /** Flag for each IPO channel that can be applied to a game object */
- bool m_ipo_channels_active[KX_MAX_IPO_CHANNELS];
-
- /** Interpret the ipo as a force rather than a displacement? */
- bool m_ipo_as_force;
-
- /** Add Ipo curve to current loc/rot/scale */
- bool m_ipo_add;
-
- /** Ipo must be applied in local coordinate rather than in global coordinates (used for force and Add mode)*/
- bool m_ipo_local;
-
- /** Were settings altered since the last update? */
- bool m_modified;
-
- /** Local time of this ipo.*/
- double m_ipotime;
-
- /** Location of the object when the IPO is first fired (for local transformations) */
- MT_Point3 m_ipo_start_point;
-
- /** Orientation of the object when the IPO is first fired (for local transformations) */
- MT_Matrix3x3 m_ipo_start_orient;
-
- /** Scale of the object when the IPO is first fired (for local transformations) */
- MT_Vector3 m_ipo_start_scale;
-
- /** if IPO initial position has been set for local normal IPO */
- bool m_ipo_start_initialized;
-
- /** Euler angles at the start of the game, needed for incomplete ROT Ipo curves */
- MT_Vector3 m_ipo_start_euler;
-
- /** true is m_ipo_start_euler has been initialized */
- bool m_ipo_euler_initialized;
-
- /** A reference to the original game object. */
- class KX_GameObject *m_game_object;
-
-public:
- KX_IpoSGController();
-
- virtual ~KX_IpoSGController();
-
- virtual SG_Controller *GetReplica(class SG_Node *destnode);
-
- void SetOption(int option, int value);
-
- /** Set sumo data. */
- void UpdateSumoReference();
- /** Set reference to the corresponding game object. */
- void SetGameObject(class KX_GameObject *go);
-
- void SetIPOChannelActive(int index, bool value) {
- //indexes found in makesdna\DNA_ipo_types.h
- m_ipo_channels_active[index] = value;
- }
-
- KX_IPOTransform &GetIPOTransform()
- {
- return m_ipo_xform;
- }
-
- void AddInterpolator(KX_IInterpolator *interp);
- virtual bool Update(double time);
- virtual void SetSimulatedTime(double time)
- {
- m_ipotime = time;
- m_modified = true;
- }
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_IpoSGController")
-#endif
-};
-
-#endif /* __KX_IPO_SGCONTROLLER_H__ */
diff --git a/source/gameengine/Ketsji/KX_IScalarInterpolator.h b/source/gameengine/Ketsji/KX_IScalarInterpolator.h
deleted file mode 100644
index 1e822c49c6d..00000000000
--- a/source/gameengine/Ketsji/KX_IScalarInterpolator.h
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_IScalarInterpolator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_ISCALARINTERPOLATOR_H__
-#define __KX_ISCALARINTERPOLATOR_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class KX_IScalarInterpolator {
-public:
- virtual ~KX_IScalarInterpolator() {}
-
- virtual float GetValue(float currentTime) const = 0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_IScalarInterpolator")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_ISceneConverter.h b/source/gameengine/Ketsji/KX_ISceneConverter.h
deleted file mode 100644
index 1963fc7c48f..00000000000
--- a/source/gameengine/Ketsji/KX_ISceneConverter.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ISceneConverter.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_ISCENECONVERTER_H__
-#define __KX_ISCENECONVERTER_H__
-
-#include "STR_String.h"
-#include "EXP_Python.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-struct Scene;
-
-class KX_ISceneConverter
-{
-
-public:
- KX_ISceneConverter() {}
- virtual ~KX_ISceneConverter () {}
-
- /*
- * scenename: name of the scene to be converted,
- * if the scenename is empty, convert the 'default' scene (whatever this means)
- * destinationscene: pass an empty scene, everything goes into this
- * dictobj: python dictionary (for pythoncontrollers)
- */
- virtual void ConvertScene(
- class KX_Scene* destinationscene,
- class RAS_IRasterizer* rendertools,
- class RAS_ICanvas* canvas,
- bool libloading=false)=0;
-
- virtual void RemoveScene(class KX_Scene *scene)=0;
-
- // handle any pending merges from asynchronous loads
- virtual void MergeAsyncLoads()=0;
- virtual void FinalizeAsyncLoads() = 0;
-
- virtual void SetAlwaysUseExpandFraming(bool to_what) = 0;
-
- virtual void SetNewFileName(const STR_String& filename) = 0;
- virtual bool TryAndLoadNewFile() = 0;
-
- virtual void ResetPhysicsObjectsAnimationIpo(bool clearIpo) = 0;
-
- ///this generates ipo curves for position, rotation, allowing to use game physics in animation
- virtual void WritePhysicsObjectToAnimationIpo(int frameNumber) = 0;
- virtual void TestHandlesPhysicsObjectToAnimationIpo() = 0;
-
- ///this is for reseting the position,rotation and scale of the gameobjet that is not dynamic
- virtual void resetNoneDynamicObjectToIpo()=0;
-
- // use blender materials
- virtual void SetMaterials(bool val) =0;
- virtual bool GetMaterials()=0;
-
- // use blender glsl materials
- virtual void SetGLSLMaterials(bool val) =0;
- virtual bool GetGLSLMaterials()=0;
-
- // cache materials during conversion
- virtual void SetCacheMaterials(bool val) =0;
- virtual bool GetCacheMaterials()=0;
-
- virtual struct Scene* GetBlenderSceneForName(const STR_String& name)=0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_ISceneConverter")
-#endif
-};
-
-#endif /* __KX_ISCENECONVERTER_H__ */
diff --git a/source/gameengine/Ketsji/KX_ISystem.h b/source/gameengine/Ketsji/KX_ISystem.h
deleted file mode 100644
index 4ba71f8d239..00000000000
--- a/source/gameengine/Ketsji/KX_ISystem.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ISystem.h
- * \ingroup ketsji
- * \brief Abstract system
- */
-
-#ifndef __KX_ISYSTEM_H__
-#define __KX_ISYSTEM_H__
-
-#include <vector>
-using namespace std;
-
-#include "STR_String.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/**
- * System Abstraction, needed only for getting some timing stuff from the host.
- */
-class KX_ISystem
-{
-public:
- KX_ISystem() {};
- virtual ~KX_ISystem() {};
-
- virtual double GetTimeInSeconds()=0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_ISystem")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_IpoConvert.cpp b/source/gameengine/Ketsji/KX_IpoConvert.cpp
deleted file mode 100644
index 7b00760ee7b..00000000000
--- a/source/gameengine/Ketsji/KX_IpoConvert.cpp
+++ /dev/null
@@ -1,441 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_IpoConvert.cpp
- * \ingroup bgeconv
- */
-
-#ifdef _MSC_VER
- /* don't show stl-warnings */
-# pragma warning (disable:4786)
-#endif
-
-#include "BKE_material.h" /* give_current_material */
-
-#include "KX_GameObject.h"
-#include "KX_IpoConvert.h"
-#include "KX_IInterpolator.h"
-#include "KX_ScalarInterpolator.h"
-
-#include "KX_BlenderScalarInterpolator.h"
-#include "KX_BlenderSceneConverter.h"
-
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-#include "DNA_object_types.h"
-#include "DNA_action_types.h"
-#include "DNA_anim_types.h"
-#include "DNA_ipo_types.h"
-#include "DNA_lamp_types.h"
-#include "DNA_world_types.h"
-#include "DNA_camera_types.h"
-#include "DNA_material_types.h"
-/* end of blender include block */
-
-#include "KX_IPO_SGController.h"
-#include "KX_LightIpoSGController.h"
-#include "KX_CameraIpoSGController.h"
-#include "KX_WorldIpoController.h"
-#include "KX_ObColorIpoSGController.h"
-#include "KX_MaterialIpoController.h"
-
-#include "SG_Node.h"
-
-#include "STR_HashedString.h"
-
-static BL_InterpolatorList *GetAdtList(struct bAction *for_act, KX_BlenderSceneConverter *converter)
-{
- BL_InterpolatorList *adtList= converter->FindInterpolatorList(for_act);
-
- if (!adtList) {
- adtList = new BL_InterpolatorList(for_act);
- converter->RegisterInterpolatorList(adtList, for_act);
- }
-
- return adtList;
-}
-
-SG_Controller *BL_CreateIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
-{
- KX_IpoSGController* ipocontr = new KX_IpoSGController();
- ipocontr->SetGameObject(gameobj);
-
- Object* blenderobject = gameobj->GetBlenderObject();
-
- ipocontr->GetIPOTransform().SetPosition(MT_Point3(blenderobject->loc));
- ipocontr->GetIPOTransform().SetEulerAngles(MT_Vector3(blenderobject->rot));
- ipocontr->GetIPOTransform().SetScaling(MT_Vector3(blenderobject->size));
-
- const char *rotmode, *drotmode;
-
- switch (blenderobject->rotmode) {
- case ROT_MODE_AXISANGLE:
- rotmode = "rotation_axis_angle";
- drotmode = "delta_rotation_axis_angle";
- break;
- case ROT_MODE_QUAT: /* XXX, this isn't working, currently only eulers are supported [#28853] */
- rotmode = "rotation_quaternion";
- drotmode = "delta_rotation_quaternion";
- break;
- default:
- rotmode = "rotation_euler";
- drotmode = "delta_rotation_euler";
- break;
- }
-
- BL_InterpolatorList *adtList= GetAdtList(action, converter);
-
- // For each active channel in the adtList add an
- // interpolator to the game object.
-
- KX_IInterpolator *interpolator;
- KX_IScalarInterpolator *interp;
-
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator("location", i))) {
- interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetPosition()[i]), interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetIPOChannelActive(OB_LOC_X+i, true);
- }
- }
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator("delta_location", i))) {
- interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaPosition()[i]), interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetIPOChannelActive(OB_DLOC_X+i, true);
- }
- }
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator(rotmode, i))) {
- interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetEulerAngles()[i]), interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetIPOChannelActive(OB_ROT_X+i, true);
- }
- }
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator(drotmode, i))) {
- interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaEulerAngles()[i]), interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetIPOChannelActive(OB_DROT_X+i, true);
- }
- }
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator("scale", i))) {
- interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetScaling()[i]), interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetIPOChannelActive(OB_SIZE_X+i, true);
- }
- }
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator("delta_scale", i))) {
- interpolator= new KX_ScalarInterpolator(&(ipocontr->GetIPOTransform().GetDeltaScaling()[i]), interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetIPOChannelActive(OB_DSIZE_X+i, true);
- }
- }
-
-
- return ipocontr;
-}
-
-
-SG_Controller *BL_CreateObColorIPO(struct bAction *action, KX_GameObject* gameobj, KX_BlenderSceneConverter *converter)
-{
- KX_ObColorIpoSGController* ipocontr_obcol=NULL;
- KX_IInterpolator *interpolator;
- KX_IScalarInterpolator *interp;
- BL_InterpolatorList *adtList= GetAdtList(action, converter);
-
- for (int i=0; i<4; i++) {
- if ((interp = adtList->GetScalarInterpolator("color", i))) {
- if (!ipocontr_obcol) {
- ipocontr_obcol = new KX_ObColorIpoSGController();
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr_obcol->m_rgba[i], interp);
- ipocontr_obcol->AddInterpolator(interpolator);
- }
- }
-
- return ipocontr_obcol;
-}
-
-SG_Controller *BL_CreateLampIPO(struct bAction *action, KX_GameObject* lightobj, KX_BlenderSceneConverter *converter)
-{
- KX_LightIpoSGController* ipocontr = new KX_LightIpoSGController();
-
- Lamp *blenderlamp = (Lamp*)lightobj->GetBlenderObject()->data;
-
- ipocontr->m_energy = blenderlamp->energy;
- ipocontr->m_col_rgb[0] = blenderlamp->r;
- ipocontr->m_col_rgb[1] = blenderlamp->g;
- ipocontr->m_col_rgb[2] = blenderlamp->b;
- ipocontr->m_dist = blenderlamp->dist;
-
- BL_InterpolatorList *adtList= GetAdtList(action, converter);
-
- // For each active channel in the adtList add an
- // interpolator to the game object.
-
- KX_IInterpolator *interpolator;
- KX_IScalarInterpolator *interp;
-
- if ((interp= adtList->GetScalarInterpolator("energy", 0))) {
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_energy, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyEnergy(true);
- }
-
- if ((interp = adtList->GetScalarInterpolator("distance", 0))) {
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_dist, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyDist(true);
- }
-
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator("color", i))) {
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_col_rgb[i], interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyColor(true);
- }
- }
-
- return ipocontr;
-}
-
-SG_Controller *BL_CreateCameraIPO(struct bAction *action, KX_GameObject* cameraobj, KX_BlenderSceneConverter *converter)
-{
- KX_CameraIpoSGController* ipocontr = new KX_CameraIpoSGController();
-
- Camera *blendercamera = (Camera*)cameraobj->GetBlenderObject()->data;
-
- ipocontr->m_lens = blendercamera->lens;
- ipocontr->m_clipstart = blendercamera->clipsta;
- ipocontr->m_clipend = blendercamera->clipend;
-
- BL_InterpolatorList *adtList= GetAdtList(action, converter);
-
- // For each active channel in the adtList add an
- // interpolator to the game object.
-
- KX_IInterpolator *interpolator;
- KX_IScalarInterpolator *interp;
-
- if ((interp = adtList->GetScalarInterpolator("lens", 0))) {
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_lens, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyLens(true);
- }
-
- if ((interp = adtList->GetScalarInterpolator("clip_start", 0))) {
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipstart, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyClipStart(true);
- }
-
- if ((interp = adtList->GetScalarInterpolator("clip_end", 0))) {
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_clipend, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyClipEnd(true);
- }
-
- return ipocontr;
-}
-
-
-SG_Controller * BL_CreateWorldIPO( bAction *action, struct World *blenderworld, KX_BlenderSceneConverter *converter )
-{
- KX_WorldIpoController *ipocontr = NULL;
-
- if (blenderworld) {
- BL_InterpolatorList *adtList = GetAdtList(action, converter);
-
- // For each active channel in the adtList add an interpolator to the game object.
- KX_IInterpolator *interpolator;
- KX_IScalarInterpolator *interp;
-
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator("ambient_color", i))) {
- if (!ipocontr) {
- ipocontr = new KX_WorldIpoController();
- }
- interpolator = new KX_ScalarInterpolator(&ipocontr->m_ambi_rgb[i], interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyAmbientColor(true);
- }
- }
-
- for (int i=0; i<3; i++) {
- if ((interp = adtList->GetScalarInterpolator("horizon_color", i))) {
- if (!ipocontr) {
- ipocontr = new KX_WorldIpoController();
- }
- interpolator = new KX_ScalarInterpolator(&ipocontr->m_hori_rgb[i], interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyHorizonColor(true);
- }
- }
-
- if ((interp = adtList->GetScalarInterpolator("mist_settings.start", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_WorldIpoController();
- }
- interpolator = new KX_ScalarInterpolator(&ipocontr->m_mist_start, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyMistStart(true);
- }
-
- if ((interp = adtList->GetScalarInterpolator("mist_settings.depth", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_WorldIpoController();
- }
- interpolator = new KX_ScalarInterpolator(&ipocontr->m_mist_dist, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyMistDist(true);
- }
-
- if ((interp = adtList->GetScalarInterpolator("mist_settings.intensity", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_WorldIpoController();
- }
- interpolator = new KX_ScalarInterpolator(&ipocontr->m_mist_intensity, interp);
- ipocontr->AddInterpolator(interpolator);
- ipocontr->SetModifyMistIntensity(true);
- }
-
- if (ipocontr) {
- ipocontr->m_mist_start = blenderworld->miststa;
- ipocontr->m_mist_dist = blenderworld->mistdist;
- ipocontr->m_mist_intensity = blenderworld->misi;
- ipocontr->m_hori_rgb[0] = blenderworld->horr;
- ipocontr->m_hori_rgb[1] = blenderworld->horg;
- ipocontr->m_hori_rgb[2] = blenderworld->horb;
- ipocontr->m_ambi_rgb[0] = blenderworld->ambr;
- ipocontr->m_ambi_rgb[1] = blenderworld->ambg;
- ipocontr->m_ambi_rgb[2] = blenderworld->ambb;
- }
- }
- return ipocontr;
-}
-
-SG_Controller *BL_CreateMaterialIpo(
- struct bAction *action,
- Material* blendermaterial,
- dword matname_hash,
- KX_GameObject* gameobj,
- KX_BlenderSceneConverter *converter
- )
-{
- KX_MaterialIpoController* ipocontr = NULL;
-
- BL_InterpolatorList *adtList= GetAdtList(action, converter);
- KX_IInterpolator *interpolator;
- KX_IScalarInterpolator *sinterp;
-
- // --
- for (int i=0; i<3; i++) {
- if ((sinterp = adtList->GetScalarInterpolator("diffuse_color", i))) {
- if (!ipocontr) {
- ipocontr = new KX_MaterialIpoController(matname_hash);
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[i], sinterp);
- ipocontr->AddInterpolator(interpolator);
- }
- }
-
- if ((sinterp = adtList->GetScalarInterpolator("alpha", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_MaterialIpoController(matname_hash);
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_rgba[3], sinterp);
- ipocontr->AddInterpolator(interpolator);
- }
-
- for (int i=0; i<3; i++) {
- if ((sinterp = adtList->GetScalarInterpolator("specular_color", i))) {
- if (!ipocontr) {
- ipocontr = new KX_MaterialIpoController(matname_hash);
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_specrgb[i], sinterp);
- ipocontr->AddInterpolator(interpolator);
- }
- }
-
- if ((sinterp = adtList->GetScalarInterpolator("specular_hardness", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_MaterialIpoController(matname_hash);
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_hard, sinterp);
- ipocontr->AddInterpolator(interpolator);
- }
-
- if ((sinterp = adtList->GetScalarInterpolator("specular_intensity", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_MaterialIpoController(matname_hash);
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_spec, sinterp);
- ipocontr->AddInterpolator(interpolator);
- }
-
- if ((sinterp = adtList->GetScalarInterpolator("diffuse_intensity", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_MaterialIpoController(matname_hash);
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_ref, sinterp);
- ipocontr->AddInterpolator(interpolator);
- }
-
- if ((sinterp = adtList->GetScalarInterpolator("emit", 0))) {
- if (!ipocontr) {
- ipocontr = new KX_MaterialIpoController(matname_hash);
- }
- interpolator= new KX_ScalarInterpolator(&ipocontr->m_emit, sinterp);
- ipocontr->AddInterpolator(interpolator);
- }
-
- if (ipocontr) {
- ipocontr->m_rgba[0] = blendermaterial->r;
- ipocontr->m_rgba[1] = blendermaterial->g;
- ipocontr->m_rgba[2] = blendermaterial->b;
- ipocontr->m_rgba[3] = blendermaterial->alpha;
-
- ipocontr->m_specrgb[0] = blendermaterial->specr;
- ipocontr->m_specrgb[1] = blendermaterial->specg;
- ipocontr->m_specrgb[2] = blendermaterial->specb;
-
- ipocontr->m_hard = blendermaterial->har;
- ipocontr->m_spec = blendermaterial->spec;
- ipocontr->m_ref = blendermaterial->ref;
- ipocontr->m_emit = blendermaterial->emit;
- ipocontr->m_alpha = blendermaterial->alpha;
- }
-
- return ipocontr;
-}
diff --git a/source/gameengine/Ketsji/KX_IpoConvert.h b/source/gameengine/Ketsji/KX_IpoConvert.h
deleted file mode 100644
index 6db43552811..00000000000
--- a/source/gameengine/Ketsji/KX_IpoConvert.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_IpoConvert.h
- * \ingroup bgeconv
- */
-
-#ifndef __KX_IPOCONVERT_H__
-#define __KX_IPOCONVERT_H__
-
-struct Object;
-struct bAction;
-class SG_Controller;
-class KX_GameObject;
-class KX_BlenderSceneConverter;
-
-SG_Controller *BL_CreateIPO(bAction *action,
- KX_GameObject* gameobj,
- KX_BlenderSceneConverter *converter);
-
-SG_Controller *BL_CreateObColorIPO(bAction *action,
- KX_GameObject* gameobj,
- KX_BlenderSceneConverter *converter);
-
-SG_Controller *BL_CreateLampIPO(bAction *action,
- KX_GameObject* lightobj,
- KX_BlenderSceneConverter *converter);
-
-SG_Controller *BL_CreateWorldIPO(bAction *action,
- struct World *blenderworld,
- KX_BlenderSceneConverter *converter);
-
-SG_Controller *BL_CreateCameraIPO(bAction *action,
- KX_GameObject* cameraobj,
- KX_BlenderSceneConverter *converter);
-
-SG_Controller *BL_CreateMaterialIpo(
- bAction *action,
- struct Material* blendermaterial,
- dword matname_hash,
- KX_GameObject* gameobj,
- KX_BlenderSceneConverter *converter);
-
-
-#endif /* __KX_IPOCONVERT_H__ */
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp b/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
deleted file mode 100644
index d82a0fd533b..00000000000
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.cpp
+++ /dev/null
@@ -1,2081 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * The engine ties all game modules together.
- */
-
-/** \file gameengine/Ketsji/KX_KetsjiEngine.cpp
- * \ingroup ketsji
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include <iostream>
-#include <stdio.h>
-
-#include "BLI_task.h"
-
-#include "KX_KetsjiEngine.h"
-
-#include "EXP_ListValue.h"
-#include "EXP_IntValue.h"
-#include "EXP_VectorValue.h"
-#include "EXP_BoolValue.h"
-#include "EXP_FloatValue.h"
-
-#include "RAS_BucketManager.h"
-#include "RAS_Rect.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_ICanvas.h"
-#include "RAS_ILightObject.h"
-#include "MT_Vector3.h"
-#include "MT_Transform.h"
-#include "SCA_IInputDevice.h"
-#include "KX_Camera.h"
-#include "KX_Dome.h"
-#include "KX_Light.h"
-#include "KX_PythonInit.h"
-#include "KX_PyConstraintBinding.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-#include "NG_NetworkScene.h"
-#include "NG_NetworkDeviceInterface.h"
-
-#include "KX_WorldInfo.h"
-#include "KX_ISceneConverter.h"
-#include "KX_TimeCategoryLogger.h"
-
-#include "RAS_FramingManager.h"
-#include "DNA_world_types.h"
-#include "DNA_scene_types.h"
-
-#include "KX_NavMeshObject.h"
-
-#include "BL_Action.h" // For managing action lock.
-
-#define DEFAULT_LOGIC_TIC_RATE 60.0
-//#define DEFAULT_PHYSICS_TIC_RATE 60.0
-
-const char KX_KetsjiEngine::m_profileLabels[tc_numCategories][15] = {
- "Physics:", // tc_physics
- "Logic:", // tc_logic
- "Animations:", // tc_animations
- "Network:", // tc_network
- "Scenegraph:", // tc_scenegraph
- "Rasterizer:", // tc_rasterizer
- "Services:", // tc_services
- "Overhead:", // tc_overhead
- "Outside:", // tc_outside
- "GPU Latency:" // tc_latency
-};
-
-double KX_KetsjiEngine::m_ticrate = DEFAULT_LOGIC_TIC_RATE;
-int KX_KetsjiEngine::m_maxLogicFrame = 5;
-int KX_KetsjiEngine::m_maxPhysicsFrame = 5;
-double KX_KetsjiEngine::m_anim_framerate = 25.0;
-double KX_KetsjiEngine::m_suspendedtime = 0.0;
-double KX_KetsjiEngine::m_suspendeddelta = 0.0;
-double KX_KetsjiEngine::m_average_framerate = 0.0;
-bool KX_KetsjiEngine::m_restrict_anim_fps = false;
-short KX_KetsjiEngine::m_exitkey = 130; // ESC Key
-bool KX_KetsjiEngine::m_doRender = true;
-
-/**
- * Constructor of the Ketsji Engine
- */
-KX_KetsjiEngine::KX_KetsjiEngine(KX_ISystem* system)
- : m_canvas(NULL),
- m_rasterizer(NULL),
- m_kxsystem(system),
- m_sceneconverter(NULL),
- m_networkdevice(NULL),
-#ifdef WITH_PYTHON
- m_pythondictionary(NULL),
-#endif
- m_keyboarddevice(NULL),
- m_mousedevice(NULL),
-
- m_bInitialized(false),
- m_activecam(0),
- m_bFixedTime(false),
- m_useExternalClock(false),
-
- m_firstframe(true),
-
- m_frameTime(0.f),
- m_clockTime(0.f),
- m_previousClockTime(0.f),
- m_previousAnimTime(0.f),
- m_timescale(1.0f),
- m_previousRealTime(0.0f),
-
-
- m_exitcode(KX_EXIT_REQUEST_NO_REQUEST),
- m_exitstring(""),
-
- m_cameraZoom(1.0f),
-
- m_overrideCam(false),
- m_overrideCamUseOrtho(false),
- m_overrideCamNear(0.0f),
- m_overrideCamFar(0.0f),
- m_overrideCamZoom(1.0f),
-
- m_stereo(false),
- m_curreye(0),
-
- m_logger(NULL),
-
- // Set up timing info display variables
- m_show_framerate(false),
- m_show_profile(false),
- m_showProperties(false),
- m_showBackground(false),
- m_show_debug_properties(false),
- m_autoAddDebugProperties(true),
-
- m_animation_record(false),
-
- // Default behavior is to hide the cursor every frame.
- m_hideCursor(false),
-
- m_overrideFrameColor(false),
- m_overrideFrameColorR(0.0f),
- m_overrideFrameColorG(0.0f),
- m_overrideFrameColorB(0.0f),
- m_overrideFrameColorA(0.0f),
-
- m_usedome(false)
-{
- // Initialize the time logger
- m_logger = new KX_TimeCategoryLogger (25);
-
- for (int i = tc_first; i < tc_numCategories; i++)
- m_logger->AddCategory((KX_TimeCategory)i);
-
-#ifdef WITH_PYTHON
- m_pyprofiledict = PyDict_New();
-#endif
-
- m_taskscheduler = BLI_task_scheduler_create(TASK_SCHEDULER_AUTO_THREADS);
-
- BL_Action::InitLock();
-}
-
-
-
-/**
- * Destructor of the Ketsji Engine, release all memory
- */
-KX_KetsjiEngine::~KX_KetsjiEngine()
-{
- delete m_logger;
- if (m_usedome)
- delete m_dome;
-
-#ifdef WITH_PYTHON
- Py_CLEAR(m_pyprofiledict);
-#endif
-
- if (m_taskscheduler)
- BLI_task_scheduler_free(m_taskscheduler);
-
- BL_Action::EndLock();
-}
-
-
-
-void KX_KetsjiEngine::SetKeyboardDevice(SCA_IInputDevice* keyboarddevice)
-{
- MT_assert(keyboarddevice);
- m_keyboarddevice = keyboarddevice;
-}
-
-
-
-void KX_KetsjiEngine::SetMouseDevice(SCA_IInputDevice* mousedevice)
-{
- MT_assert(mousedevice);
- m_mousedevice = mousedevice;
-}
-
-
-
-void KX_KetsjiEngine::SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice)
-{
- MT_assert(networkdevice);
- m_networkdevice = networkdevice;
-}
-
-
-void KX_KetsjiEngine::SetCanvas(RAS_ICanvas* canvas)
-{
- MT_assert(canvas);
- m_canvas = canvas;
-}
-
-
-
-void KX_KetsjiEngine::SetRasterizer(RAS_IRasterizer* rasterizer)
-{
- MT_assert(rasterizer);
- m_rasterizer = rasterizer;
-}
-
-#ifdef WITH_PYTHON
-/*
- * At the moment the bge.logic module is imported into 'pythondictionary' after this function is called.
- * if this function ever changes to assign a copy, make sure the game logic module is imported into this dictionary before hand.
- */
-void KX_KetsjiEngine::SetPyNamespace(PyObject *pythondictionary)
-{
- MT_assert(pythondictionary);
- m_pythondictionary = pythondictionary;
-}
-
-PyObject* KX_KetsjiEngine::GetPyProfileDict()
-{
- Py_INCREF(m_pyprofiledict);
- return m_pyprofiledict;
-}
-#endif
-
-
-void KX_KetsjiEngine::SetSceneConverter(KX_ISceneConverter* sceneconverter)
-{
- MT_assert(sceneconverter);
- m_sceneconverter = sceneconverter;
-}
-
-void KX_KetsjiEngine::InitDome(short res, short mode, short angle, float resbuf, short tilt, struct Text* text)
-{
- m_dome = new KX_Dome(m_canvas, m_rasterizer,this, res, mode, angle, resbuf, tilt, text);
- m_usedome = true;
-}
-
-void KX_KetsjiEngine::RenderDome()
-{
- const GLint *viewport = m_canvas->GetViewPort();
-
- m_dome->SetViewPort(viewport);
-
- KX_Scene* firstscene = *m_scenes.begin();
- const RAS_FrameSettings &framesettings = firstscene->GetFramingType();
-
- m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
-
- // hiding mouse cursor each frame
- // (came back when going out of focus and then back in again)
- if (m_hideCursor)
- m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
-
- // clear the entire game screen with the border color
- // only once per frame
-
- m_canvas->BeginDraw();
-
- // BeginFrame() sets the actual drawing area. You can use a part of the window
- if (!BeginFrame())
- return;
-
- KX_SceneList::iterator sceneit;
- KX_Scene* scene = NULL;
-
- int n_renders=m_dome->GetNumberRenders(); // usually 4 or 6
- for (int i=0;i<n_renders;i++) {
- m_canvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER);
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
- // for each scene, call the proceed functions
- {
- scene = *sceneit;
- KX_SetActiveScene(scene);
- KX_Camera* cam = scene->GetActiveCamera();
-
- // pass the scene's worldsettings to the rasterizer
- scene->GetWorldInfo()->UpdateWorldSettings();
-
- // shadow buffers
- if (i == 0) {
- RenderShadowBuffers(scene);
- }
- // Avoid drawing the scene with the active camera twice when its viewport is enabled
- if (cam && !cam->GetViewport())
- {
- if (scene->IsClearingZBuffer())
- m_rasterizer->ClearDepthBuffer();
-
- m_rasterizer->SetAuxilaryClientInfo(scene);
-
- // do the rendering
- m_dome->RenderDomeFrame(scene,cam, i);
- // render all the font objects for this scene
- scene->RenderFonts();
- }
-
- list<class KX_Camera*>* cameras = scene->GetCameras();
-
- // Draw the scene once for each camera with an enabled viewport
- list<KX_Camera*>::iterator it = cameras->begin();
- while (it != cameras->end()) {
- if ((*it)->GetViewport())
- {
- if (scene->IsClearingZBuffer())
- m_rasterizer->ClearDepthBuffer();
-
- m_rasterizer->SetAuxilaryClientInfo(scene);
-
- // do the rendering
- m_dome->RenderDomeFrame(scene, (*it),i);
- // render all the font objects for this scene
- scene->RenderFonts();
- }
-
- it++;
- }
- // Part of PostRenderScene()
- m_rasterizer->MotionBlur();
- scene->Render2DFilters(m_canvas);
- // no RunDrawingCallBacks
- // no FlushDebugLines
- }
- m_dome->BindImages(i);
- }
-
- m_canvas->EndFrame();//XXX do we really need that?
-
- m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
-
- if (m_overrideFrameColor) //XXX why do we want
- {
- // Do not use the framing bar color set in the Blender scenes
- m_canvas->ClearColor(
- m_overrideFrameColorR,
- m_overrideFrameColorG,
- m_overrideFrameColorB,
- m_overrideFrameColorA
- );
- }
- else
- {
- // Use the framing bar color set in the Blender scenes
- m_canvas->ClearColor(
- framesettings.BarRed(),
- framesettings.BarGreen(),
- framesettings.BarBlue(),
- 1.0
- );
- }
- m_dome->Draw();
-
- // Draw Callback for the last scene
-#ifdef WITH_PYTHON
- PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
- scene->RunDrawingCallbacks(scene->GetPostDrawCB());
-#endif
- EndFrame();
-}
-
-/**
- * Ketsji Init(), Initializes data-structures and converts data from
- * Blender into Ketsji native (realtime) format also sets up the
- * graphics context
- */
-void KX_KetsjiEngine::StartEngine(bool clearIpo)
-{
- m_clockTime = m_kxsystem->GetTimeInSeconds();
- m_frameTime = m_kxsystem->GetTimeInSeconds();
- m_previousClockTime = m_kxsystem->GetTimeInSeconds();
- m_previousRealTime = m_kxsystem->GetTimeInSeconds();
-
- m_firstframe = true;
- m_bInitialized = true;
- // there is always one scene enabled at startup
- Scene* scene = m_scenes[0]->GetBlenderScene();
- if (scene)
- {
- m_ticrate = scene->gm.ticrate ? scene->gm.ticrate : DEFAULT_LOGIC_TIC_RATE;
- m_maxLogicFrame = scene->gm.maxlogicstep ? scene->gm.maxlogicstep : 5;
- m_maxPhysicsFrame = scene->gm.maxphystep ? scene->gm.maxlogicstep : 5;
- }
- else
- {
- m_ticrate = DEFAULT_LOGIC_TIC_RATE;
- m_maxLogicFrame = 5;
- m_maxPhysicsFrame = 5;
- }
-
- if (m_animation_record)
- {
- m_sceneconverter->ResetPhysicsObjectsAnimationIpo(clearIpo);
- m_sceneconverter->WritePhysicsObjectToAnimationIpo(m_currentFrame);
- }
-}
-
-void KX_KetsjiEngine::ClearFrame()
-{
- // clear unless we're drawing overlapping stereo
- if (m_rasterizer->InterlacedStereo() &&
- m_rasterizer->GetEye() == RAS_IRasterizer::RAS_STEREO_RIGHTEYE)
- return;
-
- // clear the viewports with the background color of the first scene
- bool doclear = false;
- KX_SceneList::iterator sceneit;
- RAS_Rect clearvp, area, viewport;
-
- for (sceneit = m_scenes.begin(); sceneit != m_scenes.end(); sceneit++)
- {
- KX_Scene* scene = *sceneit;
- //const RAS_FrameSettings &framesettings = scene->GetFramingType();
- list<class KX_Camera*>* cameras = scene->GetCameras();
-
- list<KX_Camera*>::iterator it;
- for (it = cameras->begin(); it != cameras->end(); it++)
- {
- GetSceneViewport(scene, (*it), area, viewport);
-
- if (!doclear) {
- clearvp = viewport;
- doclear = true;
- }
- else {
- if (viewport.GetLeft() < clearvp.GetLeft())
- clearvp.SetLeft(viewport.GetLeft());
- if (viewport.GetBottom() < clearvp.GetBottom())
- clearvp.SetBottom(viewport.GetBottom());
- if (viewport.GetRight() > clearvp.GetRight())
- clearvp.SetRight(viewport.GetRight());
- if (viewport.GetTop() > clearvp.GetTop())
- clearvp.SetTop(viewport.GetTop());
-
- }
- }
- }
-
- if (doclear) {
- KX_Scene* firstscene = *m_scenes.begin();
- firstscene->GetWorldInfo()->UpdateBackGround();
-
- m_canvas->SetViewPort(clearvp.GetLeft(), clearvp.GetBottom(),
- clearvp.GetRight(), clearvp.GetTop());
- m_rasterizer->ClearColorBuffer();
- }
-}
-
-bool KX_KetsjiEngine::BeginFrame()
-{
- // set the area used for rendering (stereo can assign only a subset)
- m_rasterizer->SetRenderArea();
-
- if (m_canvas->BeginDraw())
- {
- ClearFrame();
-
- m_rasterizer->BeginFrame(m_kxsystem->GetTimeInSeconds());
-
- return true;
- }
-
- return false;
-}
-
-
-void KX_KetsjiEngine::EndFrame()
-{
- m_rasterizer->MotionBlur();
-
- // Show profiling info
- m_logger->StartLog(tc_overhead, m_kxsystem->GetTimeInSeconds(), true);
- if (m_show_framerate || m_show_profile || (m_show_debug_properties))
- {
- RenderDebugProperties();
- }
-
- double tottime = m_logger->GetAverage();
- if (tottime < 1e-6)
- tottime = 1e-6;
-
-#ifdef WITH_PYTHON
- for (int i = tc_first; i < tc_numCategories; ++i) {
- double time = m_logger->GetAverage((KX_TimeCategory)i);
- PyObject *val = PyTuple_New(2);
- PyTuple_SetItem(val, 0, PyFloat_FromDouble(time*1000.0));
- PyTuple_SetItem(val, 1, PyFloat_FromDouble(time/tottime * 100.0));
-
- PyDict_SetItemString(m_pyprofiledict, m_profileLabels[i], val);
- Py_DECREF(val);
- }
-#endif
-
- m_average_framerate = 1.0/tottime;
-
- // Go to next profiling measurement, time spent after this call is shown in the next frame.
- m_logger->NextMeasurement(m_kxsystem->GetTimeInSeconds());
-
- m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
- m_rasterizer->EndFrame();
- // swap backbuffer (drawing into this buffer) <-> front/visible buffer
- m_logger->StartLog(tc_latency, m_kxsystem->GetTimeInSeconds(), true);
- m_rasterizer->SwapBuffers();
- m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
-
- m_canvas->EndDraw();
-}
-
-//#include "PIL_time.h"
-//#include "LinearMath/btQuickprof.h"
-
-
-bool KX_KetsjiEngine::NextFrame()
-{
- double timestep = m_timescale / m_ticrate;
- double framestep = timestep;
- // static hidden::Clock sClock;
-
- m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(),true);
-
- //float dt = sClock.getTimeMicroseconds() * 0.000001f;
- //sClock.reset();
-
- /*
- * Clock advancement. There is basically three case:
- * - m_useExternalClock is true, the user is responsible to advance the time
- * manually using setClockTime, so here, we do not do anything.
- * - m_useExternalClock is false, m_bFixedTime is true, we advance for one
- * timestep, which already handle the time scaling parameter
- * - m_useExternalClock is false, m_bFixedTime is false, we consider how much
- * time has elapsed since last call and we scale this time by the time
- * scaling parameter. If m_timescale is 1.0 (default value), the clock
- * corresponds to the computer clock.
- *
- * Once clockTime has been computed, we will compute how many logic frames
- * will be executed before the next rendering phase (which will occur at "clockTime").
- * The game time elapsing between two logic frames (called framestep)
- * depends on several variables:
- * - ticrate
- * - max_physic_frame
- * - max_logic_frame
- * XXX The logic over computation framestep is definitively not clear (and
- * I'm not even sure it is correct). If needed frame is strictly greater
- * than max_physics_frame, we are doing a jump in game time, but keeping
- * framestep = 1 / ticrate, while if frames is greater than
- * max_logic_frame, we increase framestep.
- *
- * XXX render.fps is not considred anywhere.
- */
- if (!m_useExternalClock) {
- if (m_bFixedTime) {
- m_clockTime += timestep;
- }
- else {
- double current_time = m_kxsystem->GetTimeInSeconds();
- double dt = current_time - m_previousRealTime;
- m_previousRealTime = current_time;
- // m_clockTime += dt;
- m_clockTime += dt * m_timescale;
- }
- }
-
- double deltatime = m_clockTime - m_frameTime;
- if (deltatime<0.0)
- {
- // We got here too quickly, which means there is nothing to do, just return and don't render.
- // Not sure if this is the best fix, but it seems to stop the jumping framerate issue (#33088)
- return false;
- }
-
- // Compute the number of logic frames to do each update (fixed tic bricks)
- int frames = int(deltatime * m_ticrate / m_timescale + 1e-6);
-// if (frames>1)
-// printf("****************************************");
-// printf("dt = %f, deltatime = %f, frames = %d\n",dt, deltatime,frames);
-
-// if (!frames)
-// PIL_sleep_ms(1);
- KX_SceneList::iterator sceneit;
-
- if (frames>m_maxPhysicsFrame)
- {
-
- // printf("framedOut: %d\n",frames);
- m_frameTime+=(frames-m_maxPhysicsFrame)*timestep;
- frames = m_maxPhysicsFrame;
- }
-
-
- bool doRender = frames>0;
-
- if (frames > m_maxLogicFrame)
- {
- framestep = (frames*timestep)/m_maxLogicFrame;
- frames = m_maxLogicFrame;
- }
-
- while (frames)
- {
-
-
- m_frameTime += framestep;
-
- m_sceneconverter->MergeAsyncLoads();
-
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); ++sceneit)
- // for each scene, call the proceed functions
- {
- KX_Scene* scene = *sceneit;
-
- /* Suspension holds the physics and logic processing for an
- * entire scene. Objects can be suspended individually, and
- * the settings for that precede the logic and physics
- * update. */
- m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
-
- m_sceneconverter->resetNoneDynamicObjectToIpo(); // this is for none dynamic objects with ipo
-
- scene->UpdateObjectActivity();
-
- if (!scene->IsSuspended())
- {
- // if the scene was suspended recalculate the delta tu "curtime"
- m_suspendedtime = scene->getSuspendedTime();
- if (scene->getSuspendedTime()!=0.0)
- scene->setSuspendedDelta(scene->getSuspendedDelta()+m_clockTime-scene->getSuspendedTime());
- m_suspendeddelta = scene->getSuspendedDelta();
-
-
- m_logger->StartLog(tc_network, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_NETWORK);
- scene->GetNetworkScene()->proceed(m_frameTime);
-
- //m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
- //SG_SetActiveStage(SG_STAGE_NETWORK_UPDATE);
- //scene->UpdateParents(m_frameTime);
-
- m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_PHYSICS1);
- // set Python hooks for each scene
-#ifdef WITH_PYTHON
- PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
-#endif
- KX_SetActiveScene(scene);
-
- scene->GetPhysicsEnvironment()->EndFrame();
-
- // Update scenegraph after physics step. This maps physics calculations
- // into node positions.
- //m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
- //SG_SetActiveStage(SG_STAGE_PHYSICS1_UPDATE);
- //scene->UpdateParents(m_frameTime);
-
- // Process sensors, and controllers
- m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_CONTROLLER);
- scene->LogicBeginFrame(m_frameTime);
-
- // Scenegraph needs to be updated again, because Logic Controllers
- // can affect the local matrices.
- m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_CONTROLLER_UPDATE);
- scene->UpdateParents(m_frameTime);
-
- // Process actuators
-
- // Do some cleanup work for this logic frame
- m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_ACTUATOR);
- scene->LogicUpdateFrame(m_frameTime, true);
-
- scene->LogicEndFrame();
-
- // Actuators can affect the scenegraph
- m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_ACTUATOR_UPDATE);
- scene->UpdateParents(m_frameTime);
-
- // update levels of detail
- scene->UpdateObjectLods();
-
- m_logger->StartLog(tc_physics, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_PHYSICS2);
- scene->GetPhysicsEnvironment()->BeginFrame();
-
- // Perform physics calculations on the scene. This can involve
- // many iterations of the physics solver.
- scene->GetPhysicsEnvironment()->ProceedDeltaTime(m_frameTime,timestep,framestep);//m_deltatimerealDeltaTime);
-
- m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_PHYSICS2_UPDATE);
- scene->UpdateParents(m_frameTime);
-
-
- if (m_animation_record)
- {
- m_sceneconverter->WritePhysicsObjectToAnimationIpo(++m_currentFrame);
- }
-
- scene->setSuspendedTime(0.0);
- } // suspended
- else
- if (scene->getSuspendedTime()==0.0)
- scene->setSuspendedTime(m_clockTime);
-
- m_logger->StartLog(tc_services, m_kxsystem->GetTimeInSeconds(), true);
-
- // invalidates the shadow buffer from previous render/ImageRender because the scene has changed
- scene->SetShadowDone(false);
- }
-
- // update system devices
- m_logger->StartLog(tc_logic, m_kxsystem->GetTimeInSeconds(), true);
- if (m_keyboarddevice)
- m_keyboarddevice->NextFrame();
-
- if (m_mousedevice)
- m_mousedevice->NextFrame();
-
- if (m_networkdevice)
- m_networkdevice->NextFrame();
-
- // scene management
- ProcessScheduledScenes();
-
- frames--;
- }
-
- // Start logging time spent outside main loop
- m_logger->StartLog(tc_outside, m_kxsystem->GetTimeInSeconds(), true);
-
- return doRender && m_doRender;
-}
-
-
-
-void KX_KetsjiEngine::Render()
-{
- if (m_usedome) {
- RenderDome();
- return;
- }
- KX_Scene* firstscene = *m_scenes.begin();
- const RAS_FrameSettings &framesettings = firstscene->GetFramingType();
-
- m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_RENDER);
-
- // hiding mouse cursor each frame
- // (came back when going out of focus and then back in again)
- if (m_hideCursor)
- m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
-
- // clear the entire game screen with the border color
- // only once per frame
- m_canvas->BeginDraw();
- if (m_rasterizer->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED) {
- m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
- if (m_overrideFrameColor)
- {
- // Do not use the framing bar color set in the Blender scenes
- m_canvas->ClearColor(
- m_overrideFrameColorR,
- m_overrideFrameColorG,
- m_overrideFrameColorB,
- m_overrideFrameColorA
- );
- }
- else
- {
- // Use the framing bar color set in the Blender scenes
- m_canvas->ClearColor(
- framesettings.BarRed(),
- framesettings.BarGreen(),
- framesettings.BarBlue(),
- 1.0
- );
- }
- // clear the -whole- viewport
- m_canvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER);
- }
-
- m_rasterizer->SetEye(RAS_IRasterizer::RAS_STEREO_LEFTEYE);
-
- // BeginFrame() sets the actual drawing area. You can use a part of the window
- if (!BeginFrame())
- return;
-
- KX_SceneList::iterator sceneit;
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
- // for each scene, call the proceed functions
- {
- KX_Scene* scene = *sceneit;
- KX_Camera* cam = scene->GetActiveCamera();
- // pass the scene's worldsettings to the rasterizer
- scene->GetWorldInfo()->UpdateWorldSettings();
-
- // this is now done incrementally in KX_Scene::CalculateVisibleMeshes
- //scene->UpdateMeshTransformations();
-
- // shadow buffers
- RenderShadowBuffers(scene);
-
- // Avoid drawing the scene with the active camera twice when its viewport is enabled
- if (cam && !cam->GetViewport())
- {
- if (scene->IsClearingZBuffer())
- m_rasterizer->ClearDepthBuffer();
-
- m_rasterizer->SetAuxilaryClientInfo(scene);
-
- // do the rendering
- RenderFrame(scene, cam);
- }
-
- list<class KX_Camera*>* cameras = scene->GetCameras();
-
- // Draw the scene once for each camera with an enabled viewport
- list<KX_Camera*>::iterator it = cameras->begin();
- while (it != cameras->end()) {
- if ((*it)->GetViewport())
- {
- if (scene->IsClearingZBuffer())
- m_rasterizer->ClearDepthBuffer();
-
- m_rasterizer->SetAuxilaryClientInfo(scene);
-
- // do the rendering
- RenderFrame(scene, (*it));
- }
-
- it++;
- }
- PostRenderScene(scene);
- }
-
- // only one place that checks for stereo
- if (m_rasterizer->Stereo())
- {
- m_rasterizer->SetEye(RAS_IRasterizer::RAS_STEREO_RIGHTEYE);
-
- if (!BeginFrame())
- return;
-
-
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++)
- // for each scene, call the proceed functions
- {
- KX_Scene* scene = *sceneit;
- KX_Camera* cam = scene->GetActiveCamera();
-
- // pass the scene's worldsettings to the rasterizer
- scene->GetWorldInfo()->UpdateWorldSettings();
-
- if (scene->IsClearingZBuffer())
- m_rasterizer->ClearDepthBuffer();
-
- // pass the scene, for picking and raycasting (shadows)
- m_rasterizer->SetAuxilaryClientInfo(scene);
-
- // do the rendering
- //RenderFrame(scene);
- RenderFrame(scene, cam);
-
- list<class KX_Camera*>* cameras = scene->GetCameras();
-
- // Draw the scene once for each camera with an enabled viewport
- list<KX_Camera*>::iterator it = cameras->begin();
- while (it != cameras->end()) {
- if ((*it)->GetViewport())
- {
- if (scene->IsClearingZBuffer())
- m_rasterizer->ClearDepthBuffer();
-
- m_rasterizer->SetAuxilaryClientInfo(scene);
-
- // do the rendering
- RenderFrame(scene, (*it));
- }
-
- it++;
- }
- PostRenderScene(scene);
- }
- } // if (m_rasterizer->Stereo())
-
- EndFrame();
-}
-
-
-
-void KX_KetsjiEngine::RequestExit(int exitrequestmode)
-{
- m_exitcode = exitrequestmode;
-}
-
-
-
-void KX_KetsjiEngine::SetNameNextGame(const STR_String& nextgame)
-{
- m_exitstring = nextgame;
-}
-
-
-
-int KX_KetsjiEngine::GetExitCode()
-{
- // if a game actuator has set an exit code or if there are no scenes left
- if (!m_exitcode)
- {
- if (m_scenes.begin() == m_scenes.end())
- m_exitcode = KX_EXIT_REQUEST_NO_SCENES_LEFT;
- }
-
- // check if the window has been closed.
- if (!m_exitcode)
- {
- //if (!m_canvas->Check()) {
- // m_exitcode = KX_EXIT_REQUEST_OUTSIDE;
- //}
- }
-
- return m_exitcode;
-}
-
-
-
-const STR_String& KX_KetsjiEngine::GetExitString()
-{
- return m_exitstring;
-}
-
-void KX_KetsjiEngine::EnableCameraOverride(const STR_String& forscene)
-{
- m_overrideCam = true;
- m_overrideSceneName = forscene;
-}
-
-void KX_KetsjiEngine::SetCameraZoom(float camzoom)
-{
- m_cameraZoom = camzoom;
-}
-
-void KX_KetsjiEngine::SetCameraOverrideUseOrtho(bool useOrtho)
-{
- m_overrideCamUseOrtho = useOrtho;
-}
-
-void KX_KetsjiEngine::SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat)
-{
- m_overrideCamProjMat = mat;
-}
-
-void KX_KetsjiEngine::SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat)
-{
- m_overrideCamViewMat = mat;
-}
-
-void KX_KetsjiEngine::SetCameraOverrideClipping(float nearfrust, float farfrust)
-{
- m_overrideCamNear = nearfrust;
- m_overrideCamFar = farfrust;
-}
-
-void KX_KetsjiEngine::SetCameraOverrideLens(float lens)
-{
- m_overrideCamLens = lens;
-}
-
-void KX_KetsjiEngine::SetCameraOverrideZoom(float camzoom)
-{
- m_overrideCamZoom = camzoom;
-}
-
-void KX_KetsjiEngine::GetSceneViewport(KX_Scene *scene, KX_Camera* cam, RAS_Rect& area, RAS_Rect& viewport)
-{
- // In this function we make sure the rasterizer settings are up-to-date.
- // We compute the viewport so that logic using this information is up-to-date.
-
- // Note we postpone computation of the projection matrix
- // so that we are using the latest camera position.
- if (cam->GetViewport()) {
- RAS_Rect userviewport;
-
- userviewport.SetLeft(cam->GetViewportLeft());
- userviewport.SetBottom(cam->GetViewportBottom());
- userviewport.SetRight(cam->GetViewportRight());
- userviewport.SetTop(cam->GetViewportTop());
-
- // Don't do bars on user specified viewport
- RAS_FrameSettings settings = scene->GetFramingType();
- if (settings.FrameType() == RAS_FrameSettings::e_frame_bars)
- settings.SetFrameType(RAS_FrameSettings::e_frame_extend);
-
- RAS_FramingManager::ComputeViewport(
- scene->GetFramingType(),
- userviewport,
- viewport
- );
-
- area = userviewport;
- }
- else if ( !m_overrideCam || (scene->GetName() != m_overrideSceneName) || m_overrideCamUseOrtho ) {
- RAS_FramingManager::ComputeViewport(
- scene->GetFramingType(),
- m_canvas->GetDisplayArea(),
- viewport
- );
-
- area = m_canvas->GetDisplayArea();
- } else {
- viewport.SetLeft(0);
- viewport.SetBottom(0);
- viewport.SetRight(int(m_canvas->GetWidth()));
- viewport.SetTop(int(m_canvas->GetHeight()));
-
- area = m_canvas->GetDisplayArea();
- }
-}
-
-void KX_KetsjiEngine::UpdateAnimations(KX_Scene *scene)
-{
- if (scene->IsSuspended()) {
- return;
- }
-
- // Handle the animations independently of the logic time step
- if (GetRestrictAnimationFPS()) {
- double anim_timestep = 1.0 / KX_GetActiveScene()->GetAnimationFPS();
- if (m_frameTime - m_previousAnimTime > anim_timestep || m_frameTime == m_previousAnimTime) {
- // Sanity/debug print to make sure we're actually going at the fps we want (should be close to anim_timestep)
- // printf("Anim fps: %f\n", 1.0/(m_frameTime - m_previousAnimTime));
- m_previousAnimTime = m_frameTime;
- for (KX_SceneList::iterator sceneit = m_scenes.begin(); sceneit != m_scenes.end(); ++sceneit)
- (*sceneit)->UpdateAnimations(m_frameTime);
- }
- }
- else
- scene->UpdateAnimations(m_frameTime);
-}
-
-void KX_KetsjiEngine::RenderShadowBuffers(KX_Scene *scene)
-{
- CListValue *lightlist = scene->GetLightList();
- int i, drawmode;
-
- m_rasterizer->SetAuxilaryClientInfo(scene);
-
- for (i=0; i<lightlist->GetCount(); i++) {
- KX_GameObject *gameobj = (KX_GameObject*)lightlist->GetValue(i);
-
- KX_LightObject *light = (KX_LightObject*)gameobj;
- RAS_ILightObject *raslight = light->GetLightData();
-
- raslight->Update();
-
- if (light->GetVisible() && m_rasterizer->GetDrawingMode() == RAS_IRasterizer::KX_TEXTURED &&
- raslight->HasShadowBuffer())
- {
- /* make temporary camera */
- RAS_CameraData camdata = RAS_CameraData();
- KX_Camera *cam = new KX_Camera(scene, scene->m_callbacks, camdata, true, true);
- cam->SetName("__shadow__cam__");
-
- MT_Transform camtrans;
-
- /* switch drawmode for speed */
- drawmode = m_rasterizer->GetDrawingMode();
- m_rasterizer->SetDrawingMode(RAS_IRasterizer::KX_SHADOW);
-
- /* binds framebuffer object, sets up camera .. */
- raslight->BindShadowBuffer(m_canvas, cam, camtrans);
-
- /* update scene */
- scene->CalculateVisibleMeshes(m_rasterizer, cam, raslight->GetShadowLayer());
-
- m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE);
- UpdateAnimations(scene);
- m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_RENDER);
-
- /* render */
- m_rasterizer->ClearDepthBuffer();
- m_rasterizer->ClearColorBuffer();
- scene->RenderBuckets(camtrans, m_rasterizer);
-
- /* unbind framebuffer object, restore drawmode, free camera */
- raslight->UnbindShadowBuffer();
- m_rasterizer->SetDrawingMode(drawmode);
- cam->Release();
- }
- }
- /* remember that we have a valid shadow buffer for that scene */
- scene->SetShadowDone(true);
-}
-
-// update graphics
-void KX_KetsjiEngine::RenderFrame(KX_Scene* scene, KX_Camera* cam)
-{
- bool override_camera;
- RAS_Rect viewport, area;
- float nearfrust, farfrust, focallength;
-// KX_Camera* cam = scene->GetActiveCamera();
-
- if (!cam)
- return;
-
- KX_SetActiveScene(scene);
-
-#ifdef WITH_PYTHON
- scene->RunDrawingCallbacks(scene->GetPreDrawSetupCB());
-#endif
-
- GetSceneViewport(scene, cam, area, viewport);
-
- // store the computed viewport in the scene
- scene->SetSceneViewport(viewport);
-
- // set the viewport for this frame and scene
- m_canvas->SetViewPort(viewport.GetLeft(), viewport.GetBottom(),
- viewport.GetRight(), viewport.GetTop());
-
- // see KX_BlenderMaterial::Activate
- //m_rasterizer->SetAmbient();
- m_rasterizer->DisplayFog();
-
- override_camera = m_overrideCam && (scene->GetName() == m_overrideSceneName);
- override_camera = override_camera && (cam->GetName() == "__default__cam__");
-
- if (override_camera && m_overrideCamUseOrtho) {
- m_rasterizer->SetProjectionMatrix(m_overrideCamProjMat);
- if (!cam->hasValidProjectionMatrix()) {
- // needed to get frustum planes for culling
- MT_Matrix4x4 projmat;
- projmat.setValue(m_overrideCamProjMat.getPointer());
- cam->SetProjectionMatrix(projmat);
- }
- } else if (cam->hasValidProjectionMatrix())
- {
- m_rasterizer->SetProjectionMatrix(cam->GetProjectionMatrix());
- } else
- {
- RAS_FrameFrustum frustum;
- bool orthographic = !cam->GetCameraData()->m_perspective;
- nearfrust = cam->GetCameraNear();
- farfrust = cam->GetCameraFar();
- focallength = cam->GetFocalLength();
- MT_Matrix4x4 projmat;
-
- if (override_camera) {
- nearfrust = m_overrideCamNear;
- farfrust = m_overrideCamFar;
- }
-
- float camzoom = override_camera ? m_overrideCamZoom : m_cameraZoom;
- if (orthographic) {
-
- RAS_FramingManager::ComputeOrtho(
- scene->GetFramingType(),
- area,
- viewport,
- cam->GetScale(),
- nearfrust,
- farfrust,
- cam->GetSensorFit(),
- cam->GetShiftHorizontal(),
- cam->GetShiftVertical(),
- frustum
- );
- if (!cam->GetViewport()) {
- frustum.x1 *= camzoom;
- frustum.x2 *= camzoom;
- frustum.y1 *= camzoom;
- frustum.y2 *= camzoom;
- }
- projmat = m_rasterizer->GetOrthoMatrix(
- frustum.x1, frustum.x2, frustum.y1, frustum.y2, frustum.camnear, frustum.camfar);
-
- } else {
- RAS_FramingManager::ComputeFrustum(
- scene->GetFramingType(),
- area,
- viewport,
- cam->GetLens(),
- cam->GetSensorWidth(),
- cam->GetSensorHeight(),
- cam->GetSensorFit(),
- cam->GetShiftHorizontal(),
- cam->GetShiftVertical(),
- nearfrust,
- farfrust,
- frustum
- );
-
- if (!cam->GetViewport()) {
- frustum.x1 *= camzoom;
- frustum.x2 *= camzoom;
- frustum.y1 *= camzoom;
- frustum.y2 *= camzoom;
- }
- projmat = m_rasterizer->GetFrustumMatrix(
- frustum.x1, frustum.x2, frustum.y1, frustum.y2, frustum.camnear, frustum.camfar, focallength);
- }
- cam->SetProjectionMatrix(projmat);
-
- // Otherwise the projection matrix for each eye will be the same...
- if (!orthographic && m_rasterizer->Stereo())
- cam->InvalidateProjectionMatrix();
- }
-
- MT_Transform camtrans(cam->GetWorldToCamera());
- MT_Matrix4x4 viewmat(camtrans);
-
- m_rasterizer->SetViewMatrix(viewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->NodeGetLocalScaling(), cam->GetCameraData()->m_perspective);
- cam->SetModelviewMatrix(viewmat);
-
- // The following actually reschedules all vertices to be
- // redrawn. There is a cache between the actual rescheduling
- // and this call though. Visibility is imparted when this call
- // runs through the individual objects.
-
- m_logger->StartLog(tc_scenegraph, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_CULLING);
-
- scene->CalculateVisibleMeshes(m_rasterizer,cam);
-
- m_logger->StartLog(tc_animations, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_ANIMATION_UPDATE);
- UpdateAnimations(scene);
-
- m_logger->StartLog(tc_rasterizer, m_kxsystem->GetTimeInSeconds(), true);
- SG_SetActiveStage(SG_STAGE_RENDER);
-
-#ifdef WITH_PYTHON
- PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
- // Run any pre-drawing python callbacks
- scene->RunDrawingCallbacks(scene->GetPreDrawCB());
-#endif
-
- scene->RenderBuckets(camtrans, m_rasterizer);
-
- // render all the font objects for this scene
- scene->RenderFonts();
-
- if (scene->GetPhysicsEnvironment())
- scene->GetPhysicsEnvironment()->DebugDrawWorld();
-}
-
-/*
- * To run once per scene
- */
-void KX_KetsjiEngine::PostRenderScene(KX_Scene* scene)
-{
- KX_SetActiveScene(scene);
-
- // We need to first make sure our viewport is correct (enabling multiple viewports can mess this up)
- m_canvas->SetViewPort(0, 0, m_canvas->GetWidth(), m_canvas->GetHeight());
-
- m_rasterizer->FlushDebugShapes(scene);
- scene->Render2DFilters(m_canvas);
-
-#ifdef WITH_PYTHON
- PHY_SetActiveEnvironment(scene->GetPhysicsEnvironment());
- scene->RunDrawingCallbacks(scene->GetPostDrawCB());
-
- // Python draw callback can also call debug draw functions, so we have to clear debug shapes.
- m_rasterizer->FlushDebugShapes(scene);
-#endif
-}
-
-void KX_KetsjiEngine::StopEngine()
-{
- if (m_bInitialized)
- {
- m_sceneconverter->FinalizeAsyncLoads();
-
- if (m_animation_record)
- {
-// printf("TestHandlesPhysicsObjectToAnimationIpo\n");
- m_sceneconverter->TestHandlesPhysicsObjectToAnimationIpo();
- }
-
- KX_SceneList::iterator sceneit;
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
- {
- KX_Scene* scene = *sceneit;
- m_sceneconverter->RemoveScene(scene);
- }
- m_scenes.clear();
-
- // cleanup all the stuff
- m_rasterizer->Exit();
- }
-}
-
-// Scene Management is able to switch between scenes
-// and have several scenes running in parallel
-void KX_KetsjiEngine::AddScene(KX_Scene* scene)
-{
- m_scenes.push_back(scene);
- PostProcessScene(scene);
-}
-
-
-
-void KX_KetsjiEngine::PostProcessScene(KX_Scene* scene)
-{
- bool override_camera = (m_overrideCam && (scene->GetName() == m_overrideSceneName));
-
- SG_SetActiveStage(SG_STAGE_SCENE);
-
- // if there is no activecamera, or the camera is being
- // overridden we need to construct a temporary camera
- if (!scene->GetActiveCamera() || override_camera)
- {
- KX_Camera* activecam = NULL;
-
- RAS_CameraData camdata = RAS_CameraData();
- if (override_camera)
- {
- camdata.m_lens = m_overrideCamLens;
- camdata.m_clipstart = m_overrideCamNear;
- camdata.m_clipend = m_overrideCamFar;
-
- camdata.m_perspective= !m_overrideCamUseOrtho;
- }
- activecam = new KX_Camera(scene,KX_Scene::m_callbacks,camdata);
- activecam->SetName("__default__cam__");
-
- // set transformation
- if (override_camera) {
- const MT_CmMatrix4x4& cammatdata = m_overrideCamViewMat;
- MT_Transform trans = MT_Transform(cammatdata.getPointer());
- MT_Transform camtrans;
- camtrans.invert(trans);
-
- activecam->NodeSetLocalPosition(camtrans.getOrigin());
- activecam->NodeSetLocalOrientation(camtrans.getBasis());
- activecam->NodeUpdateGS(0);
- } else {
- activecam->NodeSetLocalPosition(MT_Point3(0.0f, 0.0f, 0.0f));
- activecam->NodeSetLocalOrientation(MT_Vector3(0.0f, 0.0f, 0.0f));
- activecam->NodeUpdateGS(0);
- }
-
- scene->AddCamera(activecam);
- scene->SetActiveCamera(activecam);
- scene->GetObjectList()->Add(activecam->AddRef());
- scene->GetRootParentList()->Add(activecam->AddRef());
- // done with activecam
- activecam->Release();
- }
-
- scene->UpdateParents(0.0);
-}
-
-
-
-void KX_KetsjiEngine::RenderDebugProperties()
-{
- STR_String debugtxt;
- int title_xmargin = -7;
- int title_y_top_margin = 4;
- int title_y_bottom_margin = 2;
-
- int const_xindent = 4;
- int const_ysize = 14;
-
- int xcoord = 12; // mmmm, these constants were taken from blender source
- int ycoord = 17; // to 'mimic' behavior
-
- int profile_indent = 72;
-
- float tottime = m_logger->GetAverage();
- if (tottime < 1e-6f) {
- tottime = 1e-6f;
- }
-
- // Set viewport to entire canvas
- RAS_Rect viewport;
- m_canvas->SetViewPort(0, 0, int(m_canvas->GetWidth()), int(m_canvas->GetHeight()));
-
- if (m_show_framerate || m_show_profile) {
- /* Title for profiling("Profile") */
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- "Profile",
- xcoord + const_xindent + title_xmargin, // Adds the constant x indent (0 for now) to the title x margin
- ycoord,
- m_canvas->GetWidth() /* RdV, TODO ?? */,
- m_canvas->GetHeight() /* RdV, TODO ?? */);
-
- // Increase the indent by default increase
- ycoord += const_ysize;
- // Add the title indent afterwards
- ycoord += title_y_bottom_margin;
- }
-
- /* Framerate display */
- if (m_show_framerate) {
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- "Frametime :",
- xcoord + const_xindent,
- ycoord,
- m_canvas->GetWidth() /* RdV, TODO ?? */,
- m_canvas->GetHeight() /* RdV, TODO ?? */);
-
- debugtxt.Format("%5.1fms (%.1ffps)", tottime * 1000.0f, 1.0f/tottime);
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- debugtxt.ReadPtr(),
- xcoord + const_xindent + profile_indent,
- ycoord,
- m_canvas->GetWidth() /* RdV, TODO ?? */,
- m_canvas->GetHeight() /* RdV, TODO ?? */);
- // Increase the indent by default increase
- ycoord += const_ysize;
- }
-
- /* Profile display */
- if (m_show_profile) {
- for (int j = tc_first; j < tc_numCategories; j++) {
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- m_profileLabels[j],
- xcoord + const_xindent,
- ycoord,
- m_canvas->GetWidth(),
- m_canvas->GetHeight());
-
- double time = m_logger->GetAverage((KX_TimeCategory)j);
-
- debugtxt.Format("%5.2fms | %d%%", (float)time*1000.f, (int)((float)time/tottime * 100.f));
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- debugtxt.ReadPtr(),
- xcoord + const_xindent + profile_indent, ycoord,
- m_canvas->GetWidth(),
- m_canvas->GetHeight());
-
- m_rasterizer->RenderBox2D(xcoord + (int)(2.2f * profile_indent), ycoord, m_canvas->GetWidth(), m_canvas->GetHeight(), (float)time/tottime);
- ycoord += const_ysize;
- }
- }
- // Add the ymargin for titles below the other section of debug info
- ycoord += title_y_top_margin;
-
- /* Property display */
- if (m_show_debug_properties) {
-
- /* Title for debugging("Debug properties") */
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- "Debug Properties",
- xcoord + const_xindent + title_xmargin, // Adds the constant x indent (0 for now) to the title x margin
- ycoord,
- m_canvas->GetWidth() /* RdV, TODO ?? */,
- m_canvas->GetHeight() /* RdV, TODO ?? */);
-
- // Increase the indent by default increase
- ycoord += const_ysize;
- // Add the title indent afterwards
- ycoord += title_y_bottom_margin;
-
- /* Calculate amount of properties that can displayed. */
- unsigned propsAct = 0;
- unsigned propsMax = (m_canvas->GetHeight() - ycoord) / const_ysize;
-
- KX_SceneList::iterator sceneit;
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end(); sceneit++) {
- KX_Scene* scene = *sceneit;
- /* the 'normal' debug props */
- vector<SCA_DebugProp*>& debugproplist = scene->GetDebugProperties();
-
- for (unsigned i=0; i < debugproplist.size() && propsAct < propsMax; i++)
- {
- CValue *propobj = debugproplist[i]->m_obj;
- STR_String objname = propobj->GetName();
- STR_String propname = debugproplist[i]->m_name;
- propsAct++;
- if (propname == "__state__") {
- // reserve name for object state
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(propobj);
- unsigned int state = gameobj->GetState();
- debugtxt = objname + "." + propname + " = ";
- bool first = true;
- for (int statenum=1;state;state >>= 1, statenum++)
- {
- if (state & 1)
- {
- if (!first)
- {
- debugtxt += ",";
- }
- debugtxt += STR_String(statenum);
- first = false;
- }
- }
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- debugtxt.ReadPtr(),
- xcoord + const_xindent,
- ycoord,
- m_canvas->GetWidth(),
- m_canvas->GetHeight());
- ycoord += const_ysize;
- }
- else {
- CValue *propval = propobj->GetProperty(propname);
- if (propval) {
- STR_String text = propval->GetText();
- debugtxt = objname + ": '" + propname + "' = " + text;
- m_rasterizer->RenderText2D(RAS_IRasterizer::RAS_TEXT_PADDED,
- debugtxt.ReadPtr(),
- xcoord + const_xindent,
- ycoord,
- m_canvas->GetWidth(),
- m_canvas->GetHeight());
- ycoord += const_ysize;
- }
- }
- }
- }
- }
-}
-
-
-KX_SceneList* KX_KetsjiEngine::CurrentScenes()
-{
- return &m_scenes;
-}
-
-
-
-KX_Scene* KX_KetsjiEngine::FindScene(const STR_String& scenename)
-{
- KX_SceneList::iterator sceneit = m_scenes.begin();
-
- // bit risky :) better to split the second clause
- while ( (sceneit != m_scenes.end())
- && ((*sceneit)->GetName() != scenename))
- {
- sceneit++;
- }
-
- return ((sceneit == m_scenes.end()) ? NULL : *sceneit);
-}
-
-
-
-void KX_KetsjiEngine::ConvertAndAddScene(const STR_String& scenename,bool overlay)
-{
- // only add scene when it doesn't exist!
- if (FindScene(scenename)) {
- printf("warning: scene %s already exists, not added!\n",scenename.ReadPtr());
- }
- else {
- if (overlay) {
- m_addingOverlayScenes.push_back(scenename);
- }
- else {
- m_addingBackgroundScenes.push_back(scenename);
- }
- }
-}
-
-
-
-
-void KX_KetsjiEngine::RemoveScene(const STR_String& scenename)
-{
- if (FindScene(scenename))
- {
- m_removingScenes.push_back(scenename);
- }
- else
- {
-// STR_String tmpname = scenename;
- std::cout << "warning: scene " << scenename << " does not exist, not removed!" << std::endl;
- }
-}
-
-
-
-void KX_KetsjiEngine::RemoveScheduledScenes()
-{
- if (m_removingScenes.size())
- {
- vector<STR_String>::iterator scenenameit;
- for (scenenameit=m_removingScenes.begin();scenenameit != m_removingScenes.end();scenenameit++)
- {
- STR_String scenename = *scenenameit;
-
- KX_SceneList::iterator sceneit;
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++)
- {
- KX_Scene* scene = *sceneit;
- if (scene->GetName()==scenename)
- {
- m_sceneconverter->RemoveScene(scene);
- m_scenes.erase(sceneit);
- break;
- }
- }
- }
- m_removingScenes.clear();
- }
-}
-
-KX_Scene* KX_KetsjiEngine::CreateScene(Scene *scene, bool libloading)
-{
- KX_Scene* tmpscene = new KX_Scene(m_keyboarddevice,
- m_mousedevice,
- m_networkdevice,
- scene->id.name+2,
- scene,
- m_canvas);
-
- m_sceneconverter->ConvertScene(tmpscene,
- m_rasterizer,
- m_canvas,
- libloading);
-
- return tmpscene;
-}
-
-KX_Scene* KX_KetsjiEngine::CreateScene(const STR_String& scenename)
-{
- Scene *scene = m_sceneconverter->GetBlenderSceneForName(scenename);
- if (!scene)
- return NULL;
- return CreateScene(scene);
-}
-
-void KX_KetsjiEngine::AddScheduledScenes()
-{
- vector<STR_String>::iterator scenenameit;
-
- if (m_addingOverlayScenes.size())
- {
- for (scenenameit = m_addingOverlayScenes.begin();
- scenenameit != m_addingOverlayScenes.end();
- scenenameit++)
- {
- STR_String scenename = *scenenameit;
- KX_Scene* tmpscene = CreateScene(scenename);
- if (tmpscene) {
- m_scenes.push_back(tmpscene);
- PostProcessScene(tmpscene);
- } else {
- printf("warning: scene %s could not be found, not added!\n",scenename.ReadPtr());
- }
- }
- m_addingOverlayScenes.clear();
- }
-
- if (m_addingBackgroundScenes.size())
- {
- for (scenenameit = m_addingBackgroundScenes.begin();
- scenenameit != m_addingBackgroundScenes.end();
- scenenameit++)
- {
- STR_String scenename = *scenenameit;
- KX_Scene* tmpscene = CreateScene(scenename);
- if (tmpscene) {
- m_scenes.insert(m_scenes.begin(),tmpscene);
- PostProcessScene(tmpscene);
- } else {
- printf("warning: scene %s could not be found, not added!\n",scenename.ReadPtr());
- }
- }
- m_addingBackgroundScenes.clear();
- }
-}
-
-
-
-bool KX_KetsjiEngine::ReplaceScene(const STR_String& oldscene,const STR_String& newscene)
-{
- // Don't allow replacement if the new scene doesn't exist.
- // Allows smarter game design (used to have no check here).
- // Note that it creates a small backward compatbility issue
- // for a game that did a replace followed by a lib load with the
- // new scene in the lib => it won't work anymore, the lib
- // must be loaded before doing the replace.
- if (m_sceneconverter->GetBlenderSceneForName(newscene) != NULL) {
- m_replace_scenes.push_back(std::make_pair(oldscene,newscene));
- return true;
- }
- return false;
-}
-
-// replace scene is not the same as removing and adding because the
-// scene must be in exact the same place (to maintain drawingorder)
-// (nzc) - should that not be done with a scene-display list? It seems
-// stupid to rely on the mem allocation order...
-void KX_KetsjiEngine::ReplaceScheduledScenes()
-{
- if (m_replace_scenes.size())
- {
- vector<pair<STR_String,STR_String> >::iterator scenenameit;
-
- for (scenenameit = m_replace_scenes.begin();
- scenenameit != m_replace_scenes.end();
- scenenameit++)
- {
- STR_String oldscenename = (*scenenameit).first;
- STR_String newscenename = (*scenenameit).second;
- int i=0;
- /* Scenes are not supposed to be included twice... I think */
- KX_SceneList::iterator sceneit;
- for (sceneit = m_scenes.begin();sceneit != m_scenes.end() ; sceneit++) {
- KX_Scene* scene = *sceneit;
- if (scene->GetName() == oldscenename) {
- // avoid crash if the new scene doesn't exist, just do nothing
- Scene *blScene = m_sceneconverter->GetBlenderSceneForName(newscenename);
- if (blScene) {
- m_sceneconverter->RemoveScene(scene);
- KX_Scene* tmpscene = CreateScene(blScene);
- m_scenes[i]=tmpscene;
- PostProcessScene(tmpscene);
- }
- else {
- printf("warning: scene %s could not be found, not replaced!\n",newscenename.ReadPtr());
- }
- }
- i++;
- }
- }
- m_replace_scenes.clear();
- }
-}
-
-
-
-void KX_KetsjiEngine::SuspendScene(const STR_String& scenename)
-{
- KX_Scene* scene = FindScene(scenename);
- if (scene) scene->Suspend();
-}
-
-
-
-void KX_KetsjiEngine::ResumeScene(const STR_String& scenename)
-{
- KX_Scene* scene = FindScene(scenename);
- if (scene) scene->Resume();
-}
-
-
-
-void KX_KetsjiEngine::SetUseFixedTime(bool bUseFixedTime)
-{
- m_bFixedTime = bUseFixedTime;
-}
-
-void KX_KetsjiEngine::SetUseExternalClock(bool useExternalClock)
-{
- m_useExternalClock = useExternalClock;
-}
-
-void KX_KetsjiEngine::SetAnimRecordMode(bool animation_record, int startFrame)
-{
- m_animation_record = animation_record;
- if (animation_record)
- {
- // when recording physics keyframes, run at a variable (capped) frame rate (fixed time == full speed)
- m_bFixedTime = false;
- }
- m_currentFrame = startFrame;
-}
-
-int KX_KetsjiEngine::getAnimRecordFrame() const
-{
- return m_currentFrame;
-}
-
-void KX_KetsjiEngine::setAnimRecordFrame(int framenr)
-{
- m_currentFrame = framenr;
-}
-
-bool KX_KetsjiEngine::GetUseFixedTime(void) const
-{
- return m_bFixedTime;
-}
-
-bool KX_KetsjiEngine::GetUseExternalClock(void) const
-{
- return m_useExternalClock;
-}
-
-double KX_KetsjiEngine::GetSuspendedDelta()
-{
- return m_suspendeddelta;
-}
-
-double KX_KetsjiEngine::GetTicRate()
-{
- return m_ticrate;
-}
-
-void KX_KetsjiEngine::SetTicRate(double ticrate)
-{
- m_ticrate = ticrate;
-}
-
-double KX_KetsjiEngine::GetTimeScale() const
-{
- return m_timescale;
-}
-
-void KX_KetsjiEngine::SetTimeScale(double timescale)
-{
- m_timescale = timescale;
-}
-
-int KX_KetsjiEngine::GetMaxLogicFrame()
-{
- return m_maxLogicFrame;
-}
-
-void KX_KetsjiEngine::SetMaxLogicFrame(int frame)
-{
- m_maxLogicFrame = frame;
-}
-
-int KX_KetsjiEngine::GetMaxPhysicsFrame()
-{
- return m_maxPhysicsFrame;
-}
-
-void KX_KetsjiEngine::SetMaxPhysicsFrame(int frame)
-{
- m_maxPhysicsFrame = frame;
-}
-
-bool KX_KetsjiEngine::GetRestrictAnimationFPS()
-{
- return m_restrict_anim_fps;
-}
-
-void KX_KetsjiEngine::SetRestrictAnimationFPS(bool bRestrictAnimFPS)
-{
- m_restrict_anim_fps = bRestrictAnimFPS;
-}
-
-double KX_KetsjiEngine::GetAnimFrameRate()
-{
- return m_anim_framerate;
-}
-
-double KX_KetsjiEngine::GetClockTime(void) const
-{
- return m_clockTime;
-}
-
-void KX_KetsjiEngine::SetClockTime(double externalClockTime)
-{
- m_clockTime = externalClockTime;
-}
-
-double KX_KetsjiEngine::GetFrameTime(void) const
-{
- return m_frameTime;
-}
-
-double KX_KetsjiEngine::GetRealTime(void) const
-{
- return m_kxsystem->GetTimeInSeconds();
-}
-
-void KX_KetsjiEngine::SetAnimFrameRate(double framerate)
-{
- m_anim_framerate = framerate;
-}
-
-double KX_KetsjiEngine::GetAverageFrameRate()
-{
- return m_average_framerate;
-}
-
-void KX_KetsjiEngine::SetExitKey(short key)
-{
- m_exitkey = key;
-}
-
-short KX_KetsjiEngine::GetExitKey()
-{
- return m_exitkey;
-}
-
-void KX_KetsjiEngine::SetRender(bool render)
-{
- m_doRender = render;
-}
-
-bool KX_KetsjiEngine::GetRender()
-{
- return m_doRender;
-}
-
-void KX_KetsjiEngine::SetShowFramerate(bool frameRate)
-{
- m_show_framerate = frameRate;
-}
-
-bool KX_KetsjiEngine::GetShowFramerate()
-{
- return m_show_framerate;
-}
-
-void KX_KetsjiEngine::SetShowProfile(bool profile)
-{
- m_show_profile = profile;
-}
-
-bool KX_KetsjiEngine::GetShowProfile()
-{
- return m_show_profile;
-}
-
-void KX_KetsjiEngine::SetShowProperties(bool properties)
-{
- m_show_debug_properties = properties;
-}
-
-bool KX_KetsjiEngine::GetShowProperties()
-{
- return m_show_debug_properties;
-}
-
-void KX_KetsjiEngine::SetAutoAddDebugProperties(bool add)
-{
- m_autoAddDebugProperties = add;
-}
-
-bool KX_KetsjiEngine::GetAutoAddDebugProperties()
-{
- return m_autoAddDebugProperties;
-}
-
-void KX_KetsjiEngine::SetTimingDisplay(bool frameRate, bool profile, bool properties)
-{
- m_show_framerate = frameRate;
- m_show_profile = profile;
- m_show_debug_properties = properties;
-}
-
-
-
-void KX_KetsjiEngine::GetTimingDisplay(bool& frameRate, bool& profile, bool& properties) const
-{
- frameRate = m_show_framerate;
- profile = m_show_profile;
- properties = m_show_debug_properties;
-}
-
-
-
-void KX_KetsjiEngine::ProcessScheduledScenes(void)
-{
- // Check whether there will be changes to the list of scenes
- if (m_addingOverlayScenes.size() ||
- m_addingBackgroundScenes.size() ||
- m_replace_scenes.size() ||
- m_removingScenes.size()) {
-
- // Change the scene list
- ReplaceScheduledScenes();
- RemoveScheduledScenes();
- AddScheduledScenes();
- }
-}
-
-
-void KX_KetsjiEngine::SetHideCursor(bool hideCursor)
-{
- m_hideCursor = hideCursor;
-}
-
-
-bool KX_KetsjiEngine::GetHideCursor(void) const
-{
- return m_hideCursor;
-}
-
-
-void KX_KetsjiEngine::SetUseOverrideFrameColor(bool overrideFrameColor)
-{
- m_overrideFrameColor = overrideFrameColor;
-}
-
-
-bool KX_KetsjiEngine::GetUseOverrideFrameColor(void) const
-{
- return m_overrideFrameColor;
-}
-
-
-void KX_KetsjiEngine::SetOverrideFrameColor(float r, float g, float b, float a)
-{
- m_overrideFrameColorR = r;
- m_overrideFrameColorG = g;
- m_overrideFrameColorB = b;
- m_overrideFrameColorA = a;
-}
-
-
-void KX_KetsjiEngine::GetOverrideFrameColor(float& r, float& g, float& b, float& a) const
-{
- r = m_overrideFrameColorR;
- g = m_overrideFrameColorG;
- b = m_overrideFrameColorB;
- a = m_overrideFrameColorA;
-}
-
-
-void KX_KetsjiEngine::Resize()
-{
- KX_SceneList::iterator sceneit;
-
- /* extended mode needs to recalculate camera frusta when */
- KX_Scene* firstscene = *m_scenes.begin();
- const RAS_FrameSettings &framesettings = firstscene->GetFramingType();
-
- if (framesettings.FrameType() == RAS_FrameSettings::e_frame_extend) {
- for (sceneit = m_scenes.begin(); sceneit != m_scenes.end(); sceneit++) {
- KX_Camera* cam = ((KX_Scene *)*sceneit)->GetActiveCamera();
- cam->InvalidateProjectionMatrix();
- }
- }
-}
-
-
-void KX_KetsjiEngine::SetGlobalSettings(GlobalSettings* gs)
-{
- m_globalsettings.matmode = gs->matmode;
- m_globalsettings.glslflag = gs->glslflag;
-}
-
-GlobalSettings* KX_KetsjiEngine::GetGlobalSettings(void)
-{
- return &m_globalsettings;
-}
-
diff --git a/source/gameengine/Ketsji/KX_KetsjiEngine.h b/source/gameengine/Ketsji/KX_KetsjiEngine.h
deleted file mode 100644
index 1756214b6dd..00000000000
--- a/source/gameengine/Ketsji/KX_KetsjiEngine.h
+++ /dev/null
@@ -1,553 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- *
- */
-
-/** \file KX_KetsjiEngine.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_KETSJIENGINE_H__
-#define __KX_KETSJIENGINE_H__
-
-#include "MT_CmMatrix4x4.h"
-#include "MT_Matrix4x4.h"
-#include "STR_String.h"
-#include "KX_ISystem.h"
-#include "KX_Scene.h"
-#include "EXP_Python.h"
-#include "KX_WorldInfo.h"
-#include <vector>
-
-struct TaskScheduler;
-class KX_TimeCategoryLogger;
-
-#define LEFT_EYE 1
-#define RIGHT_EYE 2
-
-enum KX_ExitRequestMode
-{
- KX_EXIT_REQUEST_NO_REQUEST = 0,
- KX_EXIT_REQUEST_QUIT_GAME,
- KX_EXIT_REQUEST_RESTART_GAME,
- KX_EXIT_REQUEST_START_OTHER_GAME,
- KX_EXIT_REQUEST_NO_SCENES_LEFT,
- KX_EXIT_REQUEST_BLENDER_ESC,
- KX_EXIT_REQUEST_OUTSIDE,
- KX_EXIT_REQUEST_MAX
-};
-
-typedef struct {
- short matmode;
- short glslflag;
-} GlobalSettings;
-
-/**
- * KX_KetsjiEngine is the core game engine class.
- */
-class KX_KetsjiEngine
-{
-
-private:
- class RAS_ICanvas* m_canvas; // 2D Canvas (2D Rendering Device Context)
- class RAS_IRasterizer* m_rasterizer; // 3D Rasterizer (3D Rendering)
- class KX_ISystem* m_kxsystem;
- class KX_ISceneConverter* m_sceneconverter;
- class NG_NetworkDeviceInterface* m_networkdevice;
-#ifdef WITH_PYTHON
- /* borrowed from sys.modules["__main__"], don't manage ref's */
- PyObject* m_pythondictionary;
- PyObject* m_pyprofiledict;
-#endif
- class SCA_IInputDevice* m_keyboarddevice;
- class SCA_IInputDevice* m_mousedevice;
- class KX_Dome* m_dome; // dome stereo mode
-
- /** Lists of scenes scheduled to be removed at the end of the frame. */
- std::vector<STR_String> m_removingScenes;
- /** Lists of overley scenes scheduled to be added at the end of the frame. */
- std::vector<STR_String> m_addingOverlayScenes;
- /** Lists of background scenes scheduled to be added at the end of the frame. */
- std::vector<STR_String> m_addingBackgroundScenes;
- /** Lists of scenes scheduled to be replaced at the end of the frame. */
- std::vector<std::pair<STR_String,STR_String> > m_replace_scenes;
-
- /* The current list of scenes. */
- KX_SceneList m_scenes;
- /* State variable recording the presence of object debug info in the current scene list. */
- bool m_propertiesPresent;
-
- bool m_bInitialized;
- int m_activecam;
- bool m_bFixedTime;
- bool m_useExternalClock;
-
-
- bool m_firstframe;
- int m_currentFrame;
-
- double m_frameTime; // current logic game time
- double m_clockTime; // game time for the next rendering step
- double m_previousClockTime; // game time of the previous rendering step
- double m_previousAnimTime; //game time when the animations were last updated
- double m_remainingTime;
- double m_timescale; // time scaling parameter. if > 1.0, time goes faster than real-time. If < 1.0, times goes slower than real-time.
- double m_previousRealTime;
-
- static int m_maxLogicFrame; /* maximum number of consecutive logic frame */
- static int m_maxPhysicsFrame; /* maximum number of consecutive physics frame */
- static double m_ticrate;
- static double m_anim_framerate; /* for animation playback only - ipo and action */
-
- static bool m_restrict_anim_fps;
-
- static double m_suspendedtime;
- static double m_suspendeddelta;
-
- static short m_exitkey; /* Key used to exit the BGE */
-
- static bool m_doRender; /* whether or not the scene should be rendered after the logic frame */
-
- int m_exitcode;
- STR_String m_exitstring;
-
- float m_cameraZoom;
-
- bool m_overrideCam;
- STR_String m_overrideSceneName;
-
- bool m_overrideCamUseOrtho;
- MT_CmMatrix4x4 m_overrideCamProjMat;
- MT_CmMatrix4x4 m_overrideCamViewMat;
- float m_overrideCamNear;
- float m_overrideCamFar;
- float m_overrideCamLens;
- /// Default camera zoom.
- float m_overrideCamZoom;
-
- bool m_stereo;
- int m_curreye;
-
- /** Categories for profiling display. */
- typedef enum {
- tc_first = 0,
- tc_physics = 0,
- tc_logic,
- tc_animations,
- tc_network,
- tc_scenegraph,
- tc_rasterizer,
- tc_services, // time spent in miscelaneous activities
- tc_overhead, // profile info drawing overhead
- tc_outside, // time spent outside main loop
- tc_latency, // time spent waiting on the gpu
- tc_numCategories
- } KX_TimeCategory;
-
- /** Time logger. */
- KX_TimeCategoryLogger* m_logger;
-
- /** Labels for profiling display. */
- static const char m_profileLabels[tc_numCategories][15];
- /** Last estimated framerate */
- static double m_average_framerate;
- /** Show the framerate on the game display? */
- bool m_show_framerate;
- /** Show profiling info on the game display? */
- bool m_show_profile;
- /** Show any debug (scene) object properties on the game display? */
- bool m_showProperties;
- /** Show background behind text for readability? */
- bool m_showBackground;
- /** Show debug properties on the game display*/
- bool m_show_debug_properties;
- /** Automatic add debug properties to the debug list*/
- bool m_autoAddDebugProperties;
-
- /** record physics into keyframes */
- bool m_animation_record;
-
- /** Hide cursor every frame? */
- bool m_hideCursor;
-
- /** Override framing bars color? */
- bool m_overrideFrameColor;
- /** Red component of framing bar color. */
- float m_overrideFrameColorR;
- /** Green component of framing bar color. */
- float m_overrideFrameColorG;
- /** Blue component of framing bar color. */
- float m_overrideFrameColorB;
- /** alpha component of framing bar color. */
- float m_overrideFrameColorA;
-
- /** Settings that doesn't go away with Game Actuator */
- GlobalSettings m_globalsettings;
-
- /** Task scheduler for multi-threading */
- TaskScheduler* m_taskscheduler;
-
- void RenderFrame(KX_Scene* scene, KX_Camera* cam);
- void PostRenderScene(KX_Scene* scene);
- void RenderDebugProperties();
-
-public:
- KX_KetsjiEngine(class KX_ISystem* system);
- virtual ~KX_KetsjiEngine();
-
- // set the devices and stuff. the client must take care of creating these
- void SetKeyboardDevice(SCA_IInputDevice* keyboarddevice);
- void SetMouseDevice(SCA_IInputDevice* mousedevice);
- void SetNetworkDevice(NG_NetworkDeviceInterface* networkdevice);
- void SetCanvas(RAS_ICanvas* canvas);
- void SetRasterizer(RAS_IRasterizer* rasterizer);
-#ifdef WITH_PYTHON
- void SetPyNamespace(PyObject *pythondictionary);
- PyObject* GetPyNamespace() { return m_pythondictionary; }
- PyObject* GetPyProfileDict();
-#endif
- void SetSceneConverter(KX_ISceneConverter* sceneconverter);
- KX_ISceneConverter* GetSceneConverter() { return m_sceneconverter; }
- void SetAnimRecordMode(bool animation_record, int startFrame);
-
- int getAnimRecordFrame() const;
- void setAnimRecordFrame(int framenr);
-
- RAS_IRasterizer* GetRasterizer() { return m_rasterizer; }
- RAS_ICanvas* GetCanvas() { return m_canvas; }
- SCA_IInputDevice* GetKeyboardDevice() { return m_keyboarddevice; }
- SCA_IInputDevice* GetMouseDevice() { return m_mousedevice; }
-
- TaskScheduler* GetTaskScheduler() { return m_taskscheduler; }
-
- /// Dome functions
- void InitDome(short res, short mode, short angle, float resbuf, short tilt, struct Text* text);
- void EndDome();
- void RenderDome();
- bool m_usedome;
-
- ///returns true if an update happened to indicate -> Render
- bool NextFrame();
- void Render();
- void RenderShadowBuffers(KX_Scene *scene);
-
- void StartEngine(bool clearIpo);
- void StopEngine();
- void Export(const STR_String& filename);
-
- void RequestExit(int exitrequestmode);
- void SetNameNextGame(const STR_String& nextgame);
- int GetExitCode();
- const STR_String& GetExitString();
-
- KX_SceneList* CurrentScenes();
- KX_Scene* FindScene(const STR_String& scenename);
- void AddScene(class KX_Scene* scene);
- void ConvertAndAddScene(const STR_String& scenename,bool overlay);
-
- void RemoveScene(const STR_String& scenename);
- bool ReplaceScene(const STR_String& oldscene,const STR_String& newscene);
- void SuspendScene(const STR_String& scenename);
- void ResumeScene(const STR_String& scenename);
-
- void GetSceneViewport(KX_Scene* scene, KX_Camera* cam, RAS_Rect& area, RAS_Rect& viewport);
-
- /// Sets zoom for camera objects, useful only with extend and scale framing mode.
- void SetCameraZoom(float camzoom);
-
- void EnableCameraOverride(const STR_String& forscene);
-
- void SetCameraOverrideUseOrtho(bool useOrtho);
- void SetCameraOverrideProjectionMatrix(const MT_CmMatrix4x4& mat);
- void SetCameraOverrideViewMatrix(const MT_CmMatrix4x4& mat);
- void SetCameraOverrideClipping(float near, float far);
- void SetCameraOverrideLens(float lens);
- /// Sets zoom for default camera, = 2 in embedded mode.
- void SetCameraOverrideZoom(float camzoom);
-
- // Update animations for object in this scene
- void UpdateAnimations(KX_Scene *scene);
-
- /**
- * Sets display of all frames.
- * \param bUseFixedTime New setting for display all frames.
- */
- void SetUseFixedTime(bool bUseFixedTime);
-
- /**
- * Returns display of all frames.
- * \return Current setting for display all frames.
- */
- bool GetUseFixedTime(void) const;
-
- /**
- * Sets if the BGE relies on a external clock or its own internal clock
- */
- void SetUseExternalClock(bool bUseExternalClock);
-
- /**
- * Returns if we rely on an external clock
- * \return Current setting
- */
- bool GetUseExternalClock(void) const;
-
- /**
- * Returns next render frame game time
- */
- double GetClockTime(void) const;
-
- /**
- * Set the next render frame game time. It will impact also frame time, as
- * this one is derived from clocktime
- */
- void SetClockTime(double externalClockTime);
-
- /**
- * Returns current logic frame game time
- */
- double GetFrameTime(void) const;
-
- /**
- * Returns the real (system) time
- */
- double GetRealTime(void) const;
-
- /**
- * Returns the difference between the local time of the scene (when it
- * was running and not suspended) and the "curtime"
- */
- static double GetSuspendedDelta();
-
- /**
- * Gets the number of logic updates per second.
- */
- static double GetTicRate();
- /**
- * Sets the number of logic updates per second.
- */
- static void SetTicRate(double ticrate);
- /**
- * Gets the maximum number of logic frame before render frame
- */
- static int GetMaxLogicFrame();
- /**
- * Sets the maximum number of logic frame before render frame
- */
- static void SetMaxLogicFrame(int frame);
- /**
- * Gets the maximum number of physics frame before render frame
- */
- static int GetMaxPhysicsFrame();
- /**
- * Sets the maximum number of physics frame before render frame
- */
- static void SetMaxPhysicsFrame(int frame);
-
- /**
- * Gets whether or not to lock animation updates to the animframerate
- */
- static bool GetRestrictAnimationFPS();
-
- /**
- * Sets whether or not to lock animation updates to the animframerate
- */
- static void SetRestrictAnimationFPS(bool bRestrictAnimFPS);
-
- /**
- * Gets the framerate for playing animations. (actions and ipos)
- */
- static double GetAnimFrameRate();
- /**
- * Sets the framerate for playing animations. (actions and ipos)
- */
- static void SetAnimFrameRate(double framerate);
-
- /**
- * Gets the last estimated average framerate
- */
- static double GetAverageFrameRate();
-
- /**
- * Gets the time scale multiplier
- */
- double GetTimeScale() const;
-
- /**
- * Sets the time scale multiplier
- */
- void SetTimeScale(double scale);
-
- static void SetExitKey(short key);
-
- static short GetExitKey();
-
- /**
- * Activate or deactivates the render of the scene after the logic frame
- * \param render true (render) or false (do not render)
- */
- static void SetRender(bool render);
- /**
- * Get the current render flag value
- */
- static bool GetRender();
-
- /**
- * \Sets the display for frame rate on or off.
- */
- void SetShowFramerate(bool frameRate);
-
- /**
- * \Gets the display for frame rate on or off.
- */
- bool GetShowFramerate();
-
- /**
- * \Sets the display for individual components on or off.
- */
- void SetShowProfile(bool profile);
-
- /**
- * \Gets the display for individual components on or off.
- */
- bool GetShowProfile();
-
- /**
- * \Sets the display of scene object debug properties on or off.
- */
- void SetShowProperties(bool properties);
-
- /**
- * \Gets the display of scene object debug properties on or off.
- */
- bool GetShowProperties();
-
- /**
- * \Sets if the auto adding of scene object debug properties on or off.
- */
- bool GetAutoAddDebugProperties();
-
- /**
- * \Sets the auto adding of scene object debug properties on or off.
- */
- void SetAutoAddDebugProperties(bool add);
-
- /**
- * Activates or deactivates timing information display.
- * \param frameRate Display for frame rate on or off.
- * \param profile Display for individual components on or off.
- * \param properties Display of scene object debug properties on or off.
- */
- void SetTimingDisplay(bool frameRate, bool profile, bool properties);
-
- /**
- * Returns status of timing information display.
- * \param frameRate Display for frame rate on or off.
- * \param profile Display for individual components on or off.
- * \param properties Display of scene object debug properties on or off.
- */
- void GetTimingDisplay(bool& frameRate, bool& profile, bool& properties) const;
-
- /**
- * Sets cursor hiding on every frame.
- * \param hideCursor Turns hiding on or off.
- */
- void SetHideCursor(bool hideCursor);
-
- /**
- * Returns the current setting for cursor hiding.
- * \return The current setting for cursor hiding.
- */
- bool GetHideCursor(void) const;
-
- /**
- * Enables/disables the use of the framing bar color of the Blender file's scenes.
- * \param overrideFrameColor The new setting.
- */
- void SetUseOverrideFrameColor(bool overrideFrameColor);
-
- /**
- * Check if the frame color is being overridden.
- */
- bool GetUseOverrideFrameColor(void) const;
-
- /**
- * Set the color used for framing bar color instead of the one in the Blender file's scenes.
- * \param r Red component of the override color.
- * \param g Green component of the override color.
- * \param b Blue component of the override color.
- */
- void SetOverrideFrameColor(float r, float g, float b, float a);
-
- /**
- * Returns the color used for framing bar color instead of the one in the Blender file's scenes.
- * \param r Red component of the override color.
- * \param g Green component of the override color.
- * \param b Blue component of the override color.
- */
- void GetOverrideFrameColor(float& r, float& g, float& b, float& a) const;
-
- KX_Scene* CreateScene(const STR_String& scenename);
- KX_Scene* CreateScene(Scene *scene, bool libloading=false);
-
- GlobalSettings* GetGlobalSettings(void);
- void SetGlobalSettings(GlobalSettings* gs);
-
- /**
- * Invalidate all the camera matrices and handle other
- * needed changes when resized.
- * It's only called from Blenderplayer.
- */
- void Resize();
-
-protected:
- /**
- * Processes all scheduled scene activity.
- * At the end, if the scene lists have changed,
- * SceneListsChanged(void) is called.
- * \see SceneListsChanged(void).
- */
- void ProcessScheduledScenes(void);
-
- /**
- * This method is invoked when the scene lists have changed.
- */
-
- void RemoveScheduledScenes(void);
- void AddScheduledScenes(void);
- void ReplaceScheduledScenes(void);
- void PostProcessScene(class KX_Scene* scene);
-
- bool BeginFrame();
- void ClearFrame();
- void EndFrame();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_KetsjiEngine")
-#endif
-};
-
-#endif /* __KX_KETSJIENGINE_H__ */
diff --git a/source/gameengine/Ketsji/KX_Light.cpp b/source/gameengine/Ketsji/KX_Light.cpp
deleted file mode 100644
index 5f490747c2b..00000000000
--- a/source/gameengine/Ketsji/KX_Light.cpp
+++ /dev/null
@@ -1,488 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_Light.cpp
- * \ingroup ketsji
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include <stdio.h>
-
-#include "KX_Light.h"
-#include "KX_Camera.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_ICanvas.h"
-#include "RAS_ILightObject.h"
-
-#include "KX_PyMath.h"
-
-#include "DNA_object_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_lamp_types.h"
-
-#include "BKE_scene.h"
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math.h"
-
-KX_LightObject::KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,
- RAS_IRasterizer* rasterizer,
- RAS_ILightObject* lightobj,
- bool glsl)
- : KX_GameObject(sgReplicationInfo,callbacks),
- m_rasterizer(rasterizer)
-{
- m_lightobj = lightobj;
- m_lightobj->m_scene = sgReplicationInfo;
- m_lightobj->m_light = this;
- m_rasterizer->AddLight(m_lightobj);
- m_lightobj->m_glsl = glsl;
- m_blenderscene = ((KX_Scene*)sgReplicationInfo)->GetBlenderScene();
- m_base = NULL;
-};
-
-
-KX_LightObject::~KX_LightObject()
-{
- if (m_lightobj) {
- m_rasterizer->RemoveLight(m_lightobj);
- delete(m_lightobj);
- }
-
- if (m_base) {
- BKE_scene_base_unlink(m_blenderscene, m_base);
- MEM_freeN(m_base);
- }
-}
-
-
-CValue* KX_LightObject::GetReplica()
-{
-
- KX_LightObject* replica = new KX_LightObject(*this);
-
- replica->ProcessReplica();
-
- replica->m_lightobj = m_lightobj->Clone();
- replica->m_lightobj->m_light = replica;
- m_rasterizer->AddLight(replica->m_lightobj);
- if (m_base)
- m_base = NULL;
-
- return replica;
-}
-
-void KX_LightObject::UpdateScene(KX_Scene *kxscene)
-{
- m_lightobj->m_scene = (void*)kxscene;
- m_blenderscene = kxscene->GetBlenderScene();
- m_base = BKE_scene_base_add(m_blenderscene, GetBlenderObject());
-}
-
-void KX_LightObject::SetLayer(int layer)
-{
- KX_GameObject::SetLayer(layer);
- m_lightobj->m_layer = layer;
-}
-
-#ifdef WITH_PYTHON
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject KX_LightObject::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_LightObject",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- &KX_GameObject::Sequence,
- &KX_GameObject::Mapping,
- 0,0,0,
- NULL,
- NULL,
- 0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_GameObject::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_LightObject::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_LightObject::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("layer", KX_LightObject, pyattr_get_layer, pyattr_set_layer),
- KX_PYATTRIBUTE_RW_FUNCTION("energy", KX_LightObject, pyattr_get_energy, pyattr_set_energy),
- KX_PYATTRIBUTE_RW_FUNCTION("distance", KX_LightObject, pyattr_get_distance, pyattr_set_distance),
- KX_PYATTRIBUTE_RW_FUNCTION("color", KX_LightObject, pyattr_get_color, pyattr_set_color),
- KX_PYATTRIBUTE_RW_FUNCTION("lin_attenuation", KX_LightObject, pyattr_get_lin_attenuation, pyattr_set_lin_attenuation),
- KX_PYATTRIBUTE_RW_FUNCTION("quad_attenuation", KX_LightObject, pyattr_get_quad_attenuation, pyattr_set_quad_attenuation),
- KX_PYATTRIBUTE_RW_FUNCTION("spotsize", KX_LightObject, pyattr_get_spotsize, pyattr_set_spotsize),
- KX_PYATTRIBUTE_RW_FUNCTION("spotblend", KX_LightObject, pyattr_get_spotblend, pyattr_set_spotblend),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowClipStart", KX_LightObject, pyattr_get_shadow_clip_start),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowClipEnd", KX_LightObject, pyattr_get_shadow_clip_end),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowFrustumSize", KX_LightObject, pyattr_get_shadow_frustum_size),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowBias", KX_LightObject, pyattr_get_shadow_bias),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowBleedBias", KX_LightObject, pyattr_get_shadow_bleed_bias),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowBindId", KX_LightObject, pyattr_get_shadow_bind_code),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowMapType", KX_LightObject, pyattr_get_shadow_map_type),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowColor", KX_LightObject, pyattr_get_shadow_color),
- KX_PYATTRIBUTE_RO_FUNCTION("useShadow", KX_LightObject, pyattr_get_shadow_active),
- KX_PYATTRIBUTE_RO_FUNCTION("shadowMatrix", KX_LightObject, pyattr_get_shadow_matrix),
- KX_PYATTRIBUTE_RO_FUNCTION("SPOT", KX_LightObject, pyattr_get_typeconst),
- KX_PYATTRIBUTE_RO_FUNCTION("SUN", KX_LightObject, pyattr_get_typeconst),
- KX_PYATTRIBUTE_RO_FUNCTION("NORMAL", KX_LightObject, pyattr_get_typeconst),
- KX_PYATTRIBUTE_RW_FUNCTION("type", KX_LightObject, pyattr_get_type, pyattr_set_type),
- { NULL } //Sentinel
-};
-
-PyObject *KX_LightObject::pyattr_get_layer(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyLong_FromLong(self->m_lightobj->m_layer);
-}
-
-int KX_LightObject::pyattr_set_layer(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- int layer = PyLong_AsLong(value);
-
- if (layer == -1 && PyErr_Occurred()) {
- PyErr_Format(PyExc_TypeError, "expected an integer for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
-
- if (layer < 1) {
- PyErr_Format(PyExc_TypeError, "expected an integer greater than 1 for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
- else if (layer > MAX_LIGHT_LAYERS) {
- PyErr_Format(PyExc_TypeError, "expected an integer less than %i for attribute \"%s\"", MAX_LIGHT_LAYERS, attrdef->m_name);
- return PY_SET_ATTR_FAIL;
- }
-
- self->SetLayer(layer);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_LightObject::pyattr_get_energy(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_energy);
-}
-
-int KX_LightObject::pyattr_set_energy(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
-
- if (PyFloat_Check(value)) {
- float val = PyFloat_AsDouble(value);
- if (val < 0)
- val = 0;
- else if (val > 10)
- val = 10;
-
- self->m_lightobj->m_energy = val;
- return PY_SET_ATTR_SUCCESS;
- }
-
- PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_clip_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_shadowclipstart);
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_clip_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_shadowclipend);
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_frustum_size(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_shadowfrustumsize);
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_bind_code(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyLong_FromLong(self->m_lightobj->GetShadowBindCode());
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_bias(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_shadowbias);
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_bleed_bias(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_shadowbleedbias);
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_map_type(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyLong_FromLong(self->m_lightobj->m_shadowmaptype);
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyObjectFrom(self->m_lightobj->GetShadowMatrix());
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyColorFromVector(MT_Vector3(self->m_lightobj->m_shadowcolor));
-}
-
-PyObject *KX_LightObject::pyattr_get_shadow_active(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject *self = static_cast<KX_LightObject *>(self_v);
- return PyBool_FromLong(self->m_lightobj->HasShadowBuffer());
-}
-
-PyObject *KX_LightObject::pyattr_get_distance(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_distance);
-}
-
-int KX_LightObject::pyattr_set_distance(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
-
- if (PyFloat_Check(value)) {
- float val = PyFloat_AsDouble(value);
- if (val < 0.01f)
- val = 0.01f;
- else if (val > 5000.f)
- val = 5000.f;
-
- self->m_lightobj->m_distance = val;
- return PY_SET_ATTR_SUCCESS;
- }
-
- PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_LightObject::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return Py_BuildValue("[fff]", self->m_lightobj->m_color[0], self->m_lightobj->m_color[1], self->m_lightobj->m_color[2]);
-}
-
-int KX_LightObject::pyattr_set_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
-
- MT_Vector3 color;
- if (PyVecTo(value, color))
- {
- self->m_lightobj->m_color[0] = color[0];
- self->m_lightobj->m_color[1] = color[1];
- self->m_lightobj->m_color[2] = color[2];
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_LightObject::pyattr_get_lin_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_att1);
-}
-
-int KX_LightObject::pyattr_set_lin_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
-
- if (PyFloat_Check(value)) {
- float val = PyFloat_AsDouble(value);
- if (val < 0.f)
- val = 0.f;
- else if (val > 1.f)
- val = 1.f;
-
- self->m_lightobj->m_att1 = val;
- return PY_SET_ATTR_SUCCESS;
- }
-
- PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_LightObject::pyattr_get_quad_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_att2);
-}
-
-int KX_LightObject::pyattr_set_quad_attenuation(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
-
- if (PyFloat_Check(value)) {
- float val = PyFloat_AsDouble(value);
- if (val < 0.f)
- val = 0.f;
- else if (val > 1.f)
- val = 1.f;
-
- self->m_lightobj->m_att2 = val;
- return PY_SET_ATTR_SUCCESS;
- }
-
- PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_LightObject::pyattr_get_spotsize(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return PyFloat_FromDouble(RAD2DEG(self->m_lightobj->m_spotsize));
-}
-
-int KX_LightObject::pyattr_set_spotsize(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
-
- if (PyFloat_Check(value)) {
- double val = PyFloat_AsDouble(value);
- if (val < 0.0)
- val = 0.0;
- else if (val > 180.0)
- val = 180.0;
-
- self->m_lightobj->m_spotsize = (float)DEG2RAD(val);
- return PY_SET_ATTR_SUCCESS;
- }
-
- PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
-}
-PyObject *KX_LightObject::pyattr_get_spotblend(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return PyFloat_FromDouble(self->m_lightobj->m_spotblend);
-}
-
-int KX_LightObject::pyattr_set_spotblend(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
-
- if (PyFloat_Check(value)) {
- float val = (float)PyFloat_AsDouble(value);
- if (val < 0.f)
- val = 0.f;
- else if (val > 1.f)
- val = 1.f;
-
- self->m_lightobj->m_spotblend = val;
- return PY_SET_ATTR_SUCCESS;
- }
-
- PyErr_Format(PyExc_TypeError, "expected float value for attribute \"%s\"", attrdef->m_name);
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_LightObject::pyattr_get_typeconst(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- PyObject *retvalue;
-
- const char* type = attrdef->m_name;
-
- if (!strcmp(type, "SPOT")) {
- retvalue = PyLong_FromLong(RAS_ILightObject::LIGHT_SPOT);
- } else if (!strcmp(type, "SUN")) {
- retvalue = PyLong_FromLong(RAS_ILightObject::LIGHT_SUN);
- } else if (!strcmp(type, "NORMAL")) {
- retvalue = PyLong_FromLong(RAS_ILightObject::LIGHT_NORMAL);
- }
- else {
- /* should never happen */
- PyErr_SetString(PyExc_TypeError, "light.type: internal error, invalid light type");
- retvalue = NULL;
- }
-
- return retvalue;
-}
-
-PyObject *KX_LightObject::pyattr_get_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- return PyLong_FromLong(self->m_lightobj->m_type);
-}
-
-int KX_LightObject::pyattr_set_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_LightObject* self = static_cast<KX_LightObject*>(self_v);
- const int val = PyLong_AsLong(value);
- if ((val==-1 && PyErr_Occurred()) || val<0 || val>2) {
- PyErr_SetString(PyExc_ValueError, "light.type= val: KX_LightObject, expected an int between 0 and 2");
- return PY_SET_ATTR_FAIL;
- }
-
- switch (val) {
- case 0:
- self->m_lightobj->m_type = self->m_lightobj->LIGHT_SPOT;
- break;
- case 1:
- self->m_lightobj->m_type = self->m_lightobj->LIGHT_SUN;
- break;
- case 2:
- self->m_lightobj->m_type = self->m_lightobj->LIGHT_NORMAL;
- break;
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_Light.h b/source/gameengine/Ketsji/KX_Light.h
deleted file mode 100644
index b446acd6e63..00000000000
--- a/source/gameengine/Ketsji/KX_Light.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_Light.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_LIGHT_H__
-#define __KX_LIGHT_H__
-
-#include "KX_GameObject.h"
-
-#define MAX_LIGHT_LAYERS ((1 << 20) - 1)
-
-struct GPULamp;
-struct Scene;
-struct Base;
-class KX_Camera;
-class RAS_IRasterizer;
-class RAS_ILightObject;
-class MT_Transform;
-
-class KX_LightObject : public KX_GameObject
-{
- Py_Header
-protected:
- RAS_ILightObject* m_lightobj;
- class RAS_IRasterizer* m_rasterizer; //needed for registering and replication of lightobj
- Scene* m_blenderscene;
- Base* m_base;
-
-public:
- KX_LightObject(void* sgReplicationInfo,SG_Callbacks callbacks,RAS_IRasterizer* rasterizer,RAS_ILightObject* lightobj, bool glsl);
- virtual ~KX_LightObject();
- virtual CValue* GetReplica();
- RAS_ILightObject* GetLightData() { return m_lightobj;}
-
- void UpdateScene(class KX_Scene *kxscene);
- virtual void SetLayer(int layer);
-
- virtual int GetGameObjectType() { return OBJ_LIGHT; }
-
-#ifdef WITH_PYTHON
- /* attributes */
- static PyObject* pyattr_get_layer(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_layer(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_energy(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_energy(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_shadow_clip_start(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_clip_end(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_frustum_size(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_bind_code(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_bias(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_bleed_bias(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_map_type(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_active(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_shadow_matrix(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_distance(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_distance(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_color(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_color(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_lin_attenuation(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_lin_attenuation(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_quad_attenuation(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_quad_attenuation(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_spotsize(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_spotsize(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_spotblend(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_spotblend(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_typeconst(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_type(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif
-};
-
-#endif /* __KX_LIGHT_H__ */
diff --git a/source/gameengine/Ketsji/KX_LightIpoSGController.cpp b/source/gameengine/Ketsji/KX_LightIpoSGController.cpp
deleted file mode 100644
index 6b641f7a63f..00000000000
--- a/source/gameengine/Ketsji/KX_LightIpoSGController.cpp
+++ /dev/null
@@ -1,122 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_LightIpoSGController.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_LightIpoSGController.h"
-#include "KX_ScalarInterpolator.h"
-#include "KX_Light.h"
-#include "RAS_ILightObject.h"
-
-#if defined(_WIN64)
-typedef unsigned __int64 uint_ptr;
-#else
-typedef unsigned long uint_ptr;
-#endif
-
-bool KX_LightIpoSGController::Update(double currentTime)
-{
- if (m_modified)
- {
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- (*i)->Execute(m_ipotime);//currentTime);
- }
-
- RAS_ILightObject *lightobj;
-
- SG_Spatial* ob = (SG_Spatial*)m_pObject;
- KX_LightObject* kxlight = (KX_LightObject*) ob->GetSGClientObject();
- lightobj = kxlight->GetLightData();
- //lightobj = (KX_Light*)
-
- if (m_modify_energy) {
- lightobj->m_energy = m_energy;
- }
-
- if (m_modify_color) {
- lightobj->m_color[0] = m_col_rgb[0];
- lightobj->m_color[1] = m_col_rgb[1];
- lightobj->m_color[2] = m_col_rgb[2];
- }
-
- if (m_modify_dist) {
- lightobj->m_distance = m_dist;
- }
-
- m_modified=false;
- }
- return false;
-}
-
-
-void KX_LightIpoSGController::AddInterpolator(KX_IInterpolator* interp)
-{
- this->m_interpolators.push_back(interp);
-}
-
-SG_Controller* KX_LightIpoSGController::GetReplica(class SG_Node* destnode)
-{
- KX_LightIpoSGController* iporeplica = new KX_LightIpoSGController(*this);
- // clear object that ipo acts on
- iporeplica->ClearObject();
-
- // dirty hack, ask Gino for a better solution in the ipo implementation
- // hacken en zagen, in what we call datahiding, not written for replication :(
-
- T_InterpolatorList oldlist = m_interpolators;
- iporeplica->m_interpolators.clear();
-
- T_InterpolatorList::iterator i;
- for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
- KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
- iporeplica->AddInterpolator(copyipo);
-
- MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
- uint_ptr orgbase = (uint_ptr)this;
- uint_ptr orgloc = (uint_ptr)scaal;
- uint_ptr offset = orgloc-orgbase;
- uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
- MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
- copyipo->SetNewTarget((MT_Scalar*)blaptr);
- }
-
- return iporeplica;
-}
-
-KX_LightIpoSGController::~KX_LightIpoSGController()
-{
-
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- delete (*i);
- }
-
-}
diff --git a/source/gameengine/Ketsji/KX_LightIpoSGController.h b/source/gameengine/Ketsji/KX_LightIpoSGController.h
deleted file mode 100644
index 151ced6b8f8..00000000000
--- a/source/gameengine/Ketsji/KX_LightIpoSGController.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_LightIpoSGController.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_LIGHTIPOSGCONTROLLER_H__
-#define __KX_LIGHTIPOSGCONTROLLER_H__
-
-#include "SG_Controller.h"
-#include "SG_Spatial.h"
-
-#include "KX_IInterpolator.h"
-
-class RAS_ILightObject;
-
-class KX_LightIpoSGController : public SG_Controller
-{
-public:
- MT_Scalar m_energy;
- MT_Scalar m_col_rgb[3];
- MT_Scalar m_dist;
-
-private:
- T_InterpolatorList m_interpolators;
- unsigned short m_modify_energy : 1;
- unsigned short m_modify_color : 1;
- unsigned short m_modify_dist : 1;
- bool m_modified;
-
- double m_ipotime;
-public:
- KX_LightIpoSGController() :
- m_modify_energy(false),
- m_modify_color(false),
- m_modify_dist(false),
- m_modified(true),
- m_ipotime(0.0)
- {}
-
- virtual ~KX_LightIpoSGController();
-
- virtual SG_Controller* GetReplica(class SG_Node* destnode);
-
- virtual bool Update(double time);
-
- virtual void SetSimulatedTime(double time) {
- m_ipotime = time;
- m_modified = true;
- }
-
- void SetModifyEnergy(bool modify) {
- m_modify_energy = modify;
- }
-
- void SetModifyColor(bool modify) {
- m_modify_color = modify;
- }
-
- void SetModifyDist(bool modify) {
- m_modify_dist = modify;
- }
-
- void
- SetOption(
- int option,
- int value
- ) {
- // intentionally empty
- };
-
- void AddInterpolator(KX_IInterpolator* interp);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_LightIpoSGController")
-#endif
-};
-
-#endif /* __KX_LIGHTIPOSGCONTROLLER_H__ */
diff --git a/source/gameengine/Ketsji/KX_MaterialIpoController.cpp b/source/gameengine/Ketsji/KX_MaterialIpoController.cpp
deleted file mode 100644
index 1faf8f17d54..00000000000
--- a/source/gameengine/Ketsji/KX_MaterialIpoController.cpp
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_MaterialIpoController.cpp
- * \ingroup ketsji
- */
-
-#include "KX_MaterialIpoController.h"
-#include "KX_ScalarInterpolator.h"
-#include "KX_GameObject.h"
-
-#include "BLI_sys_types.h" // for intptr_t support
-
-bool KX_MaterialIpoController::Update(double currentTime)
-{
- if (m_modified)
- {
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- (*i)->Execute(m_ipotime);
- }
-
-
- SG_Spatial* ob = (SG_Spatial*)m_pObject;
- KX_GameObject* kxgameobj= (KX_GameObject*) ob->GetSGClientObject();
-
- //kxgameobj->SetObjectColor(m_rgba);
- kxgameobj->UpdateMaterialData(
- m_matname_hash,
- m_rgba,
- m_specrgb,
- m_hard,
- m_spec,
- m_ref,
- m_emit,
- m_alpha
- );
-
- m_modified=false;
- }
- return false;
-}
-
-
-void KX_MaterialIpoController::AddInterpolator(KX_IInterpolator* interp)
-{
- this->m_interpolators.push_back(interp);
-}
-
-SG_Controller* KX_MaterialIpoController::GetReplica(class SG_Node* destnode)
-{
- KX_MaterialIpoController* iporeplica = new KX_MaterialIpoController(*this);
- // clear object that ipo acts on
- iporeplica->ClearObject();
-
- // dirty hack, ask Gino for a better solution in the ipo implementation
- // hacken en zagen, in what we call datahiding, not written for replication :(
-
- T_InterpolatorList oldlist = m_interpolators;
- iporeplica->m_interpolators.clear();
-
- T_InterpolatorList::iterator i;
- for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
- KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
- iporeplica->AddInterpolator(copyipo);
-
- MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
- intptr_t orgbase = (intptr_t)this;
- intptr_t orgloc = (intptr_t)scaal;
- intptr_t offset = orgloc-orgbase;
- intptr_t newaddrbase = (intptr_t)iporeplica + offset;
- MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
- copyipo->SetNewTarget((MT_Scalar*)blaptr);
- }
-
- return iporeplica;
-}
-
-KX_MaterialIpoController::~KX_MaterialIpoController()
-{
-
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- delete (*i);
- }
-
-}
-
diff --git a/source/gameengine/Ketsji/KX_MaterialIpoController.h b/source/gameengine/Ketsji/KX_MaterialIpoController.h
deleted file mode 100644
index a7e9c2cc1c5..00000000000
--- a/source/gameengine/Ketsji/KX_MaterialIpoController.h
+++ /dev/null
@@ -1,65 +0,0 @@
-
-/** \file KX_MaterialIpoController.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_MATERIALIPOCONTROLLER_H__
-#define __KX_MATERIALIPOCONTROLLER_H__
-
-
-
-#include "SG_Controller.h"
-#include "SG_Spatial.h"
-#include "KX_IInterpolator.h"
-
-#include "STR_String.h" //typedef dword
-
-class KX_MaterialIpoController : public SG_Controller
-{
-public:
- MT_Vector4 m_rgba;
- MT_Vector3 m_specrgb;
- MT_Scalar m_hard;
- MT_Scalar m_spec;
- MT_Scalar m_ref;
- MT_Scalar m_emit;
- MT_Scalar m_alpha;
-
-private:
- T_InterpolatorList m_interpolators;
- bool m_modified;
-
- double m_ipotime;
- dword m_matname_hash;
-public:
- KX_MaterialIpoController(dword matname_hash) :
- m_modified(true),
- m_ipotime(0.0),
- m_matname_hash(matname_hash)
- {}
- virtual ~KX_MaterialIpoController();
- virtual SG_Controller* GetReplica(class SG_Node* destnode);
- virtual bool Update(double time);
- virtual void SetSimulatedTime(double time) {
- m_ipotime = time;
- m_modified = true;
- }
-
- void
- SetOption(
- int option,
- int value
- ) {
- // intentionally empty
- };
-
-
- void AddInterpolator(KX_IInterpolator* interp);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_MaterialIpoController")
-#endif
-};
-
-#endif /* __KX_MATERIALIPOCONTROLLER_H__ */
diff --git a/source/gameengine/Ketsji/KX_MeshProxy.cpp b/source/gameengine/Ketsji/KX_MeshProxy.cpp
deleted file mode 100644
index 8da3542b4d6..00000000000
--- a/source/gameengine/Ketsji/KX_MeshProxy.cpp
+++ /dev/null
@@ -1,464 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_MeshProxy.cpp
- * \ingroup ketsji
- */
-
-
-#ifdef WITH_PYTHON
-
-#include "KX_MeshProxy.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_MeshObject.h"
-
-#include "KX_VertexProxy.h"
-#include "KX_PolyProxy.h"
-
-#include "KX_BlenderMaterial.h"
-
-#include "KX_PyMath.h"
-
-#include "SCA_LogicManager.h"
-
-#include "EXP_PyObjectPlus.h"
-
-PyTypeObject KX_MeshProxy::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_MeshProxy",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_MeshProxy::Methods[] = {
- {"getMaterialName", (PyCFunction)KX_MeshProxy::sPyGetMaterialName,METH_VARARGS},
- {"getTextureName", (PyCFunction)KX_MeshProxy::sPyGetTextureName,METH_VARARGS},
- {"getVertexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetVertexArrayLength,METH_VARARGS},
- {"getVertex", (PyCFunction)KX_MeshProxy::sPyGetVertex,METH_VARARGS},
- {"getPolygon", (PyCFunction)KX_MeshProxy::sPyGetPolygon,METH_VARARGS},
- {"transform", (PyCFunction)KX_MeshProxy::sPyTransform,METH_VARARGS},
- {"transformUV", (PyCFunction)KX_MeshProxy::sPyTransformUV,METH_VARARGS},
- //{"getIndexArrayLength", (PyCFunction)KX_MeshProxy::sPyGetIndexArrayLength,METH_VARARGS},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_MeshProxy::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("materials", KX_MeshProxy, pyattr_get_materials),
- KX_PYATTRIBUTE_RO_FUNCTION("numPolygons", KX_MeshProxy, pyattr_get_numPolygons),
- KX_PYATTRIBUTE_RO_FUNCTION("numMaterials", KX_MeshProxy, pyattr_get_numMaterials),
-
- { NULL } //Sentinel
-};
-
-void KX_MeshProxy::SetMeshModified(bool v)
-{
- m_meshobj->SetMeshModified(v);
-}
-
-KX_MeshProxy::KX_MeshProxy(RAS_MeshObject* mesh)
- : CValue(), m_meshobj(mesh)
-{
-}
-
-KX_MeshProxy::~KX_MeshProxy()
-{
-}
-
-
-
-// stuff for cvalue related things
-CValue* KX_MeshProxy::Calc(VALUE_OPERATOR op, CValue *val) { return NULL;}
-CValue* KX_MeshProxy::CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val) { return NULL;}
-
-const STR_String & KX_MeshProxy::GetText() {return m_meshobj->GetName();};
-double KX_MeshProxy::GetNumber() { return -1;}
-STR_String& KX_MeshProxy::GetName() { return m_meshobj->GetName();}
-void KX_MeshProxy::SetName(const char *name) { };
-CValue* KX_MeshProxy::GetReplica() { return NULL;}
-
-
-// stuff for python integration
-
-PyObject *KX_MeshProxy::PyGetMaterialName(PyObject *args, PyObject *kwds)
-{
- int matid= 1;
- STR_String matname;
-
- if (PyArg_ParseTuple(args,"i:getMaterialName",&matid))
- {
- matname = m_meshobj->GetMaterialName(matid);
- }
- else {
- return NULL;
- }
-
- return PyUnicode_From_STR_String(matname);
-
-}
-
-
-PyObject *KX_MeshProxy::PyGetTextureName(PyObject *args, PyObject *kwds)
-{
- int matid= 1;
- STR_String matname;
-
- if (PyArg_ParseTuple(args,"i:getTextureName",&matid))
- {
- matname = m_meshobj->GetTextureName(matid);
- }
- else {
- return NULL;
- }
-
- return PyUnicode_From_STR_String(matname);
-
-}
-
-PyObject *KX_MeshProxy::PyGetVertexArrayLength(PyObject *args, PyObject *kwds)
-{
- int matid= 0;
- int length = 0;
-
-
- if (!PyArg_ParseTuple(args,"i:getVertexArrayLength",&matid))
- return NULL;
-
-
- RAS_MeshMaterial *mmat = m_meshobj->GetMeshMaterial(matid); /* can be NULL*/
-
- if (mmat)
- {
- RAS_IPolyMaterial* mat = mmat->m_bucket->GetPolyMaterial();
- if (mat)
- length = m_meshobj->NumVertices(mat);
- }
-
- return PyLong_FromLong(length);
-}
-
-
-PyObject *KX_MeshProxy::PyGetVertex(PyObject *args, PyObject *kwds)
-{
- int vertexindex;
- int matindex;
-
- if (!PyArg_ParseTuple(args,"ii:getVertex",&matindex,&vertexindex))
- return NULL;
-
- RAS_TexVert* vertex = m_meshobj->GetVertex(matindex,vertexindex);
-
- if (vertex==NULL) {
- PyErr_SetString(PyExc_ValueError, "mesh.getVertex(mat_idx, vert_idx): KX_MeshProxy, could not get a vertex at the given indices");
- return NULL;
- }
-
- return (new KX_VertexProxy(this, vertex))->NewProxy(true);
-}
-
-PyObject *KX_MeshProxy::PyGetPolygon(PyObject *args, PyObject *kwds)
-{
- int polyindex= 1;
- PyObject *polyob = NULL;
-
- if (!PyArg_ParseTuple(args,"i:getPolygon",&polyindex))
- return NULL;
-
- if (polyindex<0 || polyindex >= m_meshobj->NumPolygons())
- {
- PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, invalid polygon index");
- return NULL;
- }
-
-
- RAS_Polygon* polygon = m_meshobj->GetPolygon(polyindex);
- if (polygon)
- {
- polyob = (new KX_PolyProxy(m_meshobj, polygon))->NewProxy(true);
- }
- else {
- PyErr_SetString(PyExc_AttributeError, "mesh.getPolygon(int): KX_MeshProxy, polygon is NULL, unknown reason");
- }
- return polyob;
-}
-
-PyObject *KX_MeshProxy::PyTransform(PyObject *args, PyObject *kwds)
-{
- int matindex;
- PyObject *pymat;
- bool ok = false;
-
- MT_Matrix4x4 transform;
-
- if (!PyArg_ParseTuple(args,"iO:transform", &matindex, &pymat) ||
- !PyMatTo(pymat, transform))
- {
- return NULL;
- }
-
- MT_Matrix4x4 ntransform = transform.inverse().transposed();
- ntransform[0][3] = ntransform[1][3] = ntransform[2][3] = 0.0f;
-
- /* transform mesh verts */
- unsigned int mit_index = 0;
- for (list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial();
- (mit != m_meshobj->GetLastMaterial());
- ++mit, ++mit_index)
- {
- if (matindex == -1) {
- /* always transform */
- }
- else if (matindex == mit_index) {
- /* we found the right index! */
- }
- else {
- continue;
- }
-
- RAS_MeshSlot *slot = mit->m_baseslot;
- RAS_MeshSlot::iterator it;
- ok = true;
-
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- size_t i;
- for (i = it.startvertex; i < it.endvertex; i++) {
- RAS_TexVert *vert = &it.vertex[i];
- vert->Transform(transform, ntransform);
- }
- }
-
- /* if we set a material index, quit when done */
- if (matindex == mit_index) {
- break;
- }
- }
-
- if (ok == false) {
- PyErr_Format(PyExc_ValueError,
- "mesh.transform(...): invalid material index %d", matindex);
- return NULL;
- }
-
- m_meshobj->SetMeshModified(true);
-
- Py_RETURN_NONE;
-}
-
-PyObject *KX_MeshProxy::PyTransformUV(PyObject *args, PyObject *kwds)
-{
- int matindex;
- PyObject *pymat;
- int uvindex = -1;
- int uvindex_from = -1;
- bool ok = false;
-
- MT_Matrix4x4 transform;
-
- if (!PyArg_ParseTuple(args,"iO|iii:transformUV", &matindex, &pymat, &uvindex, &uvindex_from) ||
- !PyMatTo(pymat, transform))
- {
- return NULL;
- }
-
- if (uvindex < -1 || uvindex > 1) {
- PyErr_Format(PyExc_ValueError,
- "mesh.transformUV(...): invalid uv_index %d", uvindex);
- return NULL;
- }
- if (uvindex_from < -1 || uvindex_from > 1) {
- PyErr_Format(PyExc_ValueError,
- "mesh.transformUV(...): invalid uv_index_from %d", uvindex);
- return NULL;
- }
- if (uvindex_from == uvindex) {
- uvindex_from = -1;
- }
-
- /* transform mesh verts */
- unsigned int mit_index = 0;
- for (list<RAS_MeshMaterial>::iterator mit = m_meshobj->GetFirstMaterial();
- (mit != m_meshobj->GetLastMaterial());
- ++mit, ++mit_index)
- {
- if (matindex == -1) {
- /* always transform */
- }
- else if (matindex == mit_index) {
- /* we found the right index! */
- }
- else {
- continue;
- }
-
- RAS_MeshSlot *slot = mit->m_baseslot;
- RAS_MeshSlot::iterator it;
- ok = true;
-
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- size_t i;
-
- for (i = it.startvertex; i < it.endvertex; i++) {
- RAS_TexVert *vert = &it.vertex[i];
- if (uvindex_from != -1) {
- if (uvindex_from == 0) vert->SetUV(1, vert->getUV(0));
- else vert->SetUV(0, vert->getUV(1));
- }
-
- switch (uvindex) {
- case 0:
- vert->TransformUV(0, transform);
- break;
- case 1:
- vert->TransformUV(1, transform);
- break;
- case -1:
- vert->TransformUV(0, transform);
- vert->TransformUV(1, transform);
- break;
- }
- }
- }
-
- /* if we set a material index, quit when done */
- if (matindex == mit_index) {
- break;
- }
- }
-
- if (ok == false) {
- PyErr_Format(PyExc_ValueError,
- "mesh.transformUV(...): invalid material index %d", matindex);
- return NULL;
- }
-
- m_meshobj->SetMeshModified(true);
-
- Py_RETURN_NONE;
-}
-
-PyObject *KX_MeshProxy::pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MeshProxy* self = static_cast<KX_MeshProxy*>(self_v);
-
- int tot= self->m_meshobj->NumMaterials();
- int i;
-
- PyObject *materials = PyList_New( tot );
-
- list<RAS_MeshMaterial>::iterator mit= self->m_meshobj->GetFirstMaterial();
-
-
- for (i=0; i<tot; mit++, i++) {
- RAS_IPolyMaterial *polymat = mit->m_bucket->GetPolyMaterial();
- KX_BlenderMaterial *mat = static_cast<KX_BlenderMaterial *>(polymat);
- PyList_SET_ITEM(materials, i, mat->GetProxy());
- }
- return materials;
-}
-
-PyObject *KX_MeshProxy::pyattr_get_numMaterials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MeshProxy * self = static_cast<KX_MeshProxy *> (self_v);
- return PyLong_FromLong(self->m_meshobj->NumMaterials());
-}
-
-PyObject *KX_MeshProxy::pyattr_get_numPolygons(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MeshProxy * self = static_cast<KX_MeshProxy *> (self_v);
- return PyLong_FromLong(self->m_meshobj->NumPolygons());
-}
-
-/* a close copy of ConvertPythonToGameObject but for meshes */
-bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, RAS_MeshObject **object, bool py_none_ok, const char *error_prefix)
-{
- if (value==NULL) {
- PyErr_Format(PyExc_TypeError, "%s, python pointer NULL, should never happen", error_prefix);
- *object = NULL;
- return false;
- }
-
- if (value==Py_None) {
- *object = NULL;
-
- if (py_none_ok) {
- return true;
- } else {
- PyErr_Format(PyExc_TypeError, "%s, expected KX_MeshProxy or a KX_MeshProxy name, None is invalid", error_prefix);
- return false;
- }
- }
-
- if (PyUnicode_Check(value)) {
- *object = (RAS_MeshObject*)logicmgr->GetMeshByName(STR_String( _PyUnicode_AsString(value) ));
-
- if (*object) {
- return true;
- } else {
- PyErr_Format(PyExc_ValueError, "%s, requested name \"%s\" did not match any KX_MeshProxy in this scene", error_prefix, _PyUnicode_AsString(value));
- return false;
- }
- }
-
- if (PyObject_TypeCheck(value, &KX_MeshProxy::Type)) {
- KX_MeshProxy *kx_mesh = static_cast<KX_MeshProxy*>BGE_PROXY_REF(value);
-
- /* sets the error */
- if (kx_mesh==NULL) {
- PyErr_Format(PyExc_SystemError, "%s, " BGE_PROXY_ERROR_MSG, error_prefix);
- return false;
- }
-
- *object = kx_mesh->GetMesh();
- return true;
- }
-
- *object = NULL;
-
- if (py_none_ok) {
- PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy, a string or None", error_prefix);
- } else {
- PyErr_Format(PyExc_TypeError, "%s, expect a KX_MeshProxy or a string", error_prefix);
- }
-
- return false;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_MeshProxy.h b/source/gameengine/Ketsji/KX_MeshProxy.h
deleted file mode 100644
index dbd7987f785..00000000000
--- a/source/gameengine/Ketsji/KX_MeshProxy.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_MeshProxy.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_MESHPROXY_H__
-#define __KX_MESHPROXY_H__
-
-#ifdef WITH_PYTHON
-
-#include "SCA_IObject.h"
-
-class SCA_LogicManager;
-/* utility conversion function */
-bool ConvertPythonToMesh(SCA_LogicManager *logicmgr, PyObject *value, class RAS_MeshObject **object, bool py_none_ok, const char *error_prefix);
-
-class KX_MeshProxy : public CValue
-{
- Py_Header
-
- class RAS_MeshObject* m_meshobj;
-public:
- KX_MeshProxy(class RAS_MeshObject* mesh);
- virtual ~KX_MeshProxy();
-
- void SetMeshModified(bool v);
-
- // stuff for cvalue related things
- virtual CValue* Calc(VALUE_OPERATOR op, CValue *val);
- virtual CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- virtual const STR_String & GetText();
- virtual double GetNumber();
- virtual RAS_MeshObject* GetMesh() { return m_meshobj; }
- virtual STR_String& GetName();
- virtual void SetName(const char *name); // Set the name of the value
- virtual CValue* GetReplica();
-
-// stuff for python integration
-
- KX_PYMETHOD(KX_MeshProxy,GetNumMaterials); // Deprecated
- KX_PYMETHOD(KX_MeshProxy,GetMaterialName);
- KX_PYMETHOD(KX_MeshProxy,GetTextureName);
- KX_PYMETHOD_NOARGS(KX_MeshProxy,GetNumPolygons); // Deprecated
-
- // both take materialid (int)
- KX_PYMETHOD(KX_MeshProxy,GetVertexArrayLength);
- KX_PYMETHOD(KX_MeshProxy,GetVertex);
- KX_PYMETHOD(KX_MeshProxy,GetPolygon);
- KX_PYMETHOD(KX_MeshProxy,Transform);
- KX_PYMETHOD(KX_MeshProxy,TransformUV);
-
- static PyObject *pyattr_get_materials(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_numMaterials(void *self, const KX_PYATTRIBUTE_DEF * attrdef);
- static PyObject *pyattr_get_numPolygons(void *self, const KX_PYATTRIBUTE_DEF * attrdef);
-};
-
-#endif /* WITH_PYTHON */
-
-#endif /* __KX_MESHPROXY_H__ */
diff --git a/source/gameengine/Ketsji/KX_MotionState.cpp b/source/gameengine/Ketsji/KX_MotionState.cpp
deleted file mode 100644
index 4728f71a6ea..00000000000
--- a/source/gameengine/Ketsji/KX_MotionState.cpp
+++ /dev/null
@@ -1,106 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_MotionState.cpp
- * \ingroup ketsji
- */
-
-#include "KX_MotionState.h"
-#include "SG_Spatial.h"
-
-KX_MotionState::KX_MotionState(SG_Spatial* node) : m_node(node)
-{
-
-}
-
-KX_MotionState::~KX_MotionState()
-{
-}
-
-void KX_MotionState::GetWorldPosition(float& posX,float& posY,float& posZ)
-{
- const MT_Point3& pos = m_node->GetWorldPosition();
- posX = pos[0];
- posY = pos[1];
- posZ = pos[2];
-}
-
-void KX_MotionState::GetWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
-{
- const MT_Vector3& scale = m_node->GetWorldScaling();
- scaleX = scale[0];
- scaleY = scale[1];
- scaleZ = scale[2];
-}
-
-void KX_MotionState::GetWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
-{
- MT_Quaternion orn = m_node->GetWorldOrientation().getRotation();
- quatIma0 = orn[0];
- quatIma1 = orn[1];
- quatIma2 = orn[2];
- quatReal = orn[3];
-}
-
-void KX_MotionState::GetWorldOrientation(float* ori)
-{
- const MT_Matrix3x3& mat = m_node->GetWorldOrientation();
- mat.getValue(ori);
-}
-
-void KX_MotionState::SetWorldOrientation(const float* ori)
-{
- m_node->SetLocalOrientation(ori);
-}
-
-void KX_MotionState::SetWorldPosition(float posX,float posY,float posZ)
-{
- m_node->SetLocalPosition(MT_Point3(posX,posY,posZ));
- //m_node->SetWorldPosition(MT_Point3(posX,posY,posZ));
-}
-
-void KX_MotionState::SetWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
-{
- MT_Quaternion orn;
- orn[0] = quatIma0;
- orn[1] = quatIma1;
- orn[2] = quatIma2;
- orn[3] = quatReal;
-
- m_node->SetLocalOrientation(orn);
- //m_node->SetWorldOrientation(orn);
-
-}
-
-void KX_MotionState::CalculateWorldTransformations()
-{
- //Not needed, will be done in KX_Scene::UpdateParents() after the physics simulation
- //bool parentUpdated = false;
- //m_node->ComputeWorldTransforms(NULL, parentUpdated);
-}
-
-
diff --git a/source/gameengine/Ketsji/KX_MotionState.h b/source/gameengine/Ketsji/KX_MotionState.h
deleted file mode 100644
index 38046fe4ff9..00000000000
--- a/source/gameengine/Ketsji/KX_MotionState.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_MotionState.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_MOTIONSTATE_H__
-#define __KX_MOTIONSTATE_H__
-
-#include "PHY_IMotionState.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class KX_MotionState : public PHY_IMotionState
-{
- class SG_Spatial* m_node;
-
-public:
- KX_MotionState(class SG_Spatial* spatial);
- virtual ~KX_MotionState();
-
- virtual void GetWorldPosition(float& posX,float& posY,float& posZ);
- virtual void GetWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
- virtual void GetWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
- virtual void SetWorldPosition(float posX,float posY,float posZ);
- virtual void SetWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
- virtual void GetWorldOrientation(float* ori);
- virtual void SetWorldOrientation(const float* ori);
-
- virtual void CalculateWorldTransformations();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_MotionState")
-#endif
-};
-
-#endif /* __KX_MOTIONSTATE_H__ */
diff --git a/source/gameengine/Ketsji/KX_MouseActuator.cpp b/source/gameengine/Ketsji/KX_MouseActuator.cpp
deleted file mode 100644
index 6aa0d588b50..00000000000
--- a/source/gameengine/Ketsji/KX_MouseActuator.cpp
+++ /dev/null
@@ -1,539 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Geoffrey Gollmer, Jorge Bernal
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "KX_MouseActuator.h"
-#include "KX_KetsjiEngine.h"
-#include "SCA_MouseManager.h"
-#include "SCA_IInputDevice.h"
-#include "RAS_ICanvas.h"
-#include "KX_GameObject.h"
-#include "MT_Vector3.h"
-#include "MT_Scalar.h"
-#include "MT_assert.h"
-#include "limits.h"
-
-#include "BLI_math.h"
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_MouseActuator::KX_MouseActuator(
- SCA_IObject* gameobj,
-
- KX_KetsjiEngine* ketsjiEngine,
- SCA_MouseManager* eventmgr,
- int acttype,
- bool visible,
- bool* use_axis,
- float* threshold,
- bool* reset,
- int* object_axis,
- bool* local,
- float* sensitivity,
- float* limit_x,
- float* limit_y
-):
- SCA_IActuator(gameobj, KX_ACT_MOUSE),
- m_ketsji(ketsjiEngine),
- m_eventmgr(eventmgr),
- m_type(acttype),
- m_visible(visible),
- m_use_axis_x(use_axis[0]),
- m_use_axis_y(use_axis[1]),
- m_reset_x(reset[0]),
- m_reset_y(reset[1]),
- m_local_x(local[0]),
- m_local_y(local[1])
-{
- m_canvas = m_ketsji->GetCanvas();
- m_oldposition[0] = m_oldposition[1] = -1.f;
- m_limit_x[0] = limit_x[0];
- m_limit_x[1] = limit_x[1];
- m_limit_y[0] = limit_y[0];
- m_limit_y[1] = limit_y[1];
- m_threshold[0] = threshold[0];
- m_threshold[1] = threshold[1];
- m_object_axis[0] = object_axis[0];
- m_object_axis[1] = object_axis[1];
- m_sensitivity[0] = sensitivity[0];
- m_sensitivity[1] = sensitivity[1];
- m_angle[0] = 0.f;
- m_angle[1] = 0.f;
-}
-
-KX_MouseActuator::~KX_MouseActuator()
-{
-}
-
-bool KX_MouseActuator::Update()
-{
- bool result = false;
-
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent());
-
- m_mouse = ((SCA_MouseManager *)m_eventmgr)->GetInputDevice();
-
- switch (m_type) {
- case KX_ACT_MOUSE_VISIBILITY:
- {
- if (m_visible) {
- if (m_canvas) {
- m_canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
- }
- }
- else {
- if (m_canvas) {
- m_canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
- }
- }
- break;
- }
- case KX_ACT_MOUSE_LOOK:
- {
- if (m_mouse) {
-
- float position[2];
- float movement[2];
- MT_Vector3 rotation;
- float setposition[2] = {0.0f};
- float center_x = 0.5f, center_y = 0.5f;
-
- getMousePosition(position);
-
- movement[0] = position[0];
- movement[1] = position[1];
-
- //preventing undesired drifting when resolution is odd
- if ((m_canvas->GetWidth() % 2) != 0) {
- center_x = ((m_canvas->GetWidth() - 1.0f) / 2.0f) / (m_canvas->GetWidth());
- }
- if ((m_canvas->GetHeight() % 2) != 0) {
- center_y = ((m_canvas->GetHeight() - 1.0f) / 2.0f) / (m_canvas->GetHeight());
- }
-
- //preventing initial skipping.
- if ((m_oldposition[0] <= -0.9f) && (m_oldposition[1] <= -0.9f)) {
-
- if (m_reset_x) {
- m_oldposition[0] = center_x;
- }
- else {
- m_oldposition[0] = position[0];
- }
-
- if (m_reset_y) {
- m_oldposition[1] = center_y;
- }
- else {
- m_oldposition[1] = position[1];
- }
- setMousePosition(m_oldposition[0], m_oldposition[1]);
- break;
- }
-
- //Calculating X axis.
- if (m_use_axis_x) {
-
- if (m_reset_x) {
- setposition[0] = center_x;
- movement[0] -= center_x;
- }
- else {
- setposition[0] = position[0];
- movement[0] -= m_oldposition[0];
- }
-
- movement[0] *= -1.0f;
-
- /* Don't apply the rotation when we are under a certain threshold for mouse
- movement */
-
- if (((movement[0] > (m_threshold[0] / 10.0f)) ||
- ((movement[0] * (-1.0f)) > (m_threshold[0] / 10.0f)))) {
-
- movement[0] *= m_sensitivity[0];
-
- if ((m_limit_x[0] != 0.0f) && ((m_angle[0] + movement[0]) <= m_limit_x[0])) {
- movement[0] = m_limit_x[0] - m_angle[0];
- }
-
- if ((m_limit_x[1] != 0.0f) && ((m_angle[0] + movement[0]) >= m_limit_x[1])) {
- movement[0] = m_limit_x[1] - m_angle[0];
- }
-
- m_angle[0] += movement[0];
-
- switch (m_object_axis[0]) {
- case KX_ACT_MOUSE_OBJECT_AXIS_X:
- {
- rotation = MT_Vector3(movement[0], 0.0f, 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Y:
- {
- rotation = MT_Vector3(0.0f, movement[0], 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Z:
- {
- rotation = MT_Vector3(0.0f, 0.0f, movement[0]);
- break;
- }
- default:
- break;
- }
- parent->ApplyRotation(rotation, m_local_x);
- }
- }
- else {
- setposition[0] = center_x;
- }
-
- //Calculating Y axis.
- if (m_use_axis_y) {
-
- if (m_reset_y) {
- setposition[1] = center_y;
- movement[1] -= center_y;
- }
- else {
- setposition[1] = position[1];
- movement[1] -= m_oldposition[1];
- }
-
- movement[1] *= -1.0f;
-
- /* Don't apply the rotation when we are under a certain threshold for mouse
- movement */
-
- if (((movement[1] > (m_threshold[1] / 10.0f)) ||
- ((movement[1] * (-1.0f)) > (m_threshold[1] / 10.0f)))) {
-
- movement[1] *= m_sensitivity[1];
-
- if ((m_limit_y[0] != 0.0f) && ((m_angle[1] + movement[1]) <= m_limit_y[0])) {
- movement[1] = m_limit_y[0] - m_angle[1];
- }
-
- if ((m_limit_y[1] != 0.0f) && ((m_angle[1] + movement[1]) >= m_limit_y[1])) {
- movement[1] = m_limit_y[1] - m_angle[1];
- }
-
- m_angle[1] += movement[1];
-
- switch (m_object_axis[1])
- {
- case KX_ACT_MOUSE_OBJECT_AXIS_X:
- {
- rotation = MT_Vector3(movement[1], 0.0f, 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Y:
- {
- rotation = MT_Vector3(0.0f, movement[1], 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Z:
- {
- rotation = MT_Vector3(0.0f, 0.0f, movement[1]);
- break;
- }
- default:
- break;
- }
- parent->ApplyRotation(rotation, m_local_y);
- }
- }
- else {
- setposition[1] = center_y;
- }
-
- // only trigger mouse event when it is necessary
- if (m_oldposition[0] != position[0] || m_oldposition[1] != position[1]) {
- setMousePosition(setposition[0], setposition[1]);
- }
-
- m_oldposition[0] = position[0];
- m_oldposition[1] = position[1];
-
- }
- else {
- //printf("\nNo input device detected for mouse actuator\n");
- }
- break;
- }
- default:
- break;
- }
- return result;
-}
-
-bool KX_MouseActuator::isValid(KX_MouseActuator::KX_ACT_MOUSE_MODE mode)
-{
- return ((mode > KX_ACT_MOUSE_NODEF) && (mode < KX_ACT_MOUSE_MAX));
-}
-
-
-CValue* KX_MouseActuator::GetReplica()
-{
- KX_MouseActuator* replica = new KX_MouseActuator(*this);
-
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_MouseActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
-}
-
-void KX_MouseActuator::getMousePosition(float* pos)
-{
- MT_assert(m_mouse);
- const SCA_InputEvent & xevent = m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEX);
- const SCA_InputEvent & yevent = m_mouse->GetEventValue(SCA_IInputDevice::KX_MOUSEY);
-
- pos[0] = m_canvas->GetMouseNormalizedX(xevent.m_eventval);
- pos[1] = m_canvas->GetMouseNormalizedY(yevent.m_eventval);
-}
-
-void KX_MouseActuator::setMousePosition(float fx, float fy)
-{
- int x, y;
-
- x = (int)(fx * m_canvas->GetWidth());
- y = (int)(fy * m_canvas->GetHeight());
-
- m_canvas->SetMousePosition(x, y);
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_MouseActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_MouseActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_MouseActuator::Methods[] = {
- {"reset", (PyCFunction) KX_MouseActuator::sPyReset, METH_NOARGS,"reset() : undo rotation caused by actuator\n"},
- {NULL,NULL} //Sentinel
-};
-
-
-
-PyAttributeDef KX_MouseActuator::Attributes[] = {
- KX_PYATTRIBUTE_BOOL_RW("visible", KX_MouseActuator, m_visible),
- KX_PYATTRIBUTE_BOOL_RW("use_axis_x", KX_MouseActuator, m_use_axis_x),
- KX_PYATTRIBUTE_BOOL_RW("use_axis_y", KX_MouseActuator, m_use_axis_y),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RW("threshold", 0.0f, 0.5f, KX_MouseActuator, m_threshold, 2),
- KX_PYATTRIBUTE_BOOL_RW("reset_x", KX_MouseActuator, m_reset_x),
- KX_PYATTRIBUTE_BOOL_RW("reset_y", KX_MouseActuator, m_reset_y),
- KX_PYATTRIBUTE_INT_ARRAY_RW("object_axis", 0, 2, 1, KX_MouseActuator, m_object_axis, 2),
- KX_PYATTRIBUTE_BOOL_RW("local_x", KX_MouseActuator, m_local_x),
- KX_PYATTRIBUTE_BOOL_RW("local_y", KX_MouseActuator, m_local_y),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RW("sensitivity", -FLT_MAX, FLT_MAX, KX_MouseActuator, m_sensitivity, 2),
- KX_PYATTRIBUTE_RW_FUNCTION("limit_x", KX_MouseActuator, pyattr_get_limit_x, pyattr_set_limit_x),
- KX_PYATTRIBUTE_RW_FUNCTION("limit_y", KX_MouseActuator, pyattr_get_limit_y, pyattr_set_limit_y),
- KX_PYATTRIBUTE_RW_FUNCTION("angle", KX_MouseActuator, pyattr_get_angle, pyattr_set_angle),
- { NULL } //Sentinel
-};
-
-PyObject* KX_MouseActuator::pyattr_get_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v);
- return Py_BuildValue("[f,f]", (self->m_limit_x[0] / (float)M_PI * 180.0f), (self->m_limit_x[1] / (float)M_PI * 180.0f));
-}
-
-int KX_MouseActuator::pyattr_set_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- PyObject *item1, *item2;
- KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v);
-
- if (!PyList_Check(value))
- return PY_SET_ATTR_FAIL;
-
- if (PyList_Size(value) != 2)
- return PY_SET_ATTR_FAIL;
-
- item1 = PyList_GET_ITEM(value, 0);
- item2 = PyList_GET_ITEM(value, 1);
-
- if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) {
- return PY_SET_ATTR_FAIL;
- }
- else {
- self->m_limit_x[0] = (float)((PyFloat_AsDouble(item1) * M_PI) / 180.0f);
- self->m_limit_x[1] = (float)((PyFloat_AsDouble(item2) * M_PI) / 180.0f);
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_MouseActuator::pyattr_get_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v);
- return Py_BuildValue("[f,f]", (self->m_limit_y[0] / (float)M_PI * 180.0f), (self->m_limit_y[1] / (float)M_PI * 180.0f));
-}
-
-int KX_MouseActuator::pyattr_set_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- PyObject *item1, *item2;
- KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v);
-
- if (!PyList_Check(value))
- return PY_SET_ATTR_FAIL;
-
- if (PyList_Size(value) != 2)
- return PY_SET_ATTR_FAIL;
-
- item1 = PyList_GET_ITEM(value, 0);
- item2 = PyList_GET_ITEM(value, 1);
-
- if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) {
- return PY_SET_ATTR_FAIL;
- }
- else {
- self->m_limit_y[0] = (float)((PyFloat_AsDouble(item1) * M_PI) / 180.0f);
- self->m_limit_y[1] = (float)((PyFloat_AsDouble(item2) * M_PI) / 180.0f);
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_MouseActuator::pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v);
- return Py_BuildValue("[f,f]", (self->m_angle[0] / (float)M_PI * 180.0f), (self->m_angle[1] / (float)M_PI * 180.0f));
-}
-
-int KX_MouseActuator::pyattr_set_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- PyObject *item1, *item2;
- KX_MouseActuator* self= static_cast<KX_MouseActuator*>(self_v);
-
- if (!PyList_Check(value))
- return PY_SET_ATTR_FAIL;
-
- if (PyList_Size(value) != 2)
- return PY_SET_ATTR_FAIL;
-
- item1 = PyList_GET_ITEM(value, 0);
- item2 = PyList_GET_ITEM(value, 1);
-
- if (!(PyFloat_Check(item1)) || !(PyFloat_Check(item2))) {
- return PY_SET_ATTR_FAIL;
- }
- else {
- self->m_angle[0] = ((float)(PyFloat_AsDouble(item1) * M_PI) / 180.0f);
- self->m_angle[1] = ((float)(PyFloat_AsDouble(item2) * M_PI) / 180.0f);
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject* KX_MouseActuator::PyReset()
-{
- MT_Vector3 rotation;
- KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent());
-
- switch (m_object_axis[0]) {
- case KX_ACT_MOUSE_OBJECT_AXIS_X:
- {
- rotation = MT_Vector3(-1.0f * m_angle[0], 0.0f, 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Y:
- {
- rotation = MT_Vector3(0.0f, -1.0f * m_angle[0], 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Z:
- {
- rotation = MT_Vector3(0.0f, 0.0f, -1.0f * m_angle[0]);
- break;
- }
- default:
- break;
- }
- parent->ApplyRotation(rotation, m_local_x);
-
- switch (m_object_axis[1]) {
- case KX_ACT_MOUSE_OBJECT_AXIS_X:
- {
- rotation = MT_Vector3(-1.0f * m_angle[1], 0.0f, 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Y:
- {
- rotation = MT_Vector3(0.0f, -1.0f * m_angle[1], 0.0f);
- break;
- }
- case KX_ACT_MOUSE_OBJECT_AXIS_Z:
- {
- rotation = MT_Vector3(0.0f, 0.0f, -1.0f * m_angle[1]);
- break;
- }
- default:
- break;
- }
- parent->ApplyRotation(rotation, m_local_y);
-
- m_angle[0] = 0.0f;
- m_angle[1] = 0.0f;
-
- Py_RETURN_NONE;
-}
-
-#endif /* WITH_PYTHON */
diff --git a/source/gameengine/Ketsji/KX_MouseActuator.h b/source/gameengine/Ketsji/KX_MouseActuator.h
deleted file mode 100644
index e244e271428..00000000000
--- a/source/gameengine/Ketsji/KX_MouseActuator.h
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Geoffrey Gollmer, Jorge Bernal
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __KX_MOUSEACTUATOR
-#define __KX_MOUSEACTUATOR
-
-#include "SCA_IActuator.h"
-
-class KX_KetsjiEngine;
-class SCA_MouseManager;
-class SCA_IInputDevice;
-class RAS_ICanvas;
-
-class KX_MouseActuator : public SCA_IActuator
-{
- Py_Header
-
-private:
-
- KX_KetsjiEngine* m_ketsji;
- SCA_MouseManager* m_eventmgr;
- SCA_IInputDevice* m_mouse;
- RAS_ICanvas* m_canvas;
- int m_type;
-
- bool m_visible;
-
- bool m_use_axis_x; /* 0 for calculate axis, 1 for ignore axis */
- bool m_use_axis_y;
- float m_threshold[2];
- bool m_reset_x; /* 0=reset, 1=free */
- bool m_reset_y;
- int m_object_axis[2]; /* 0=x, 1=y, 2=z */
- bool m_local_x; /* 0=local, 1=global*/
- bool m_local_y;
- float m_sensitivity[2];
- float m_limit_x[2];
- float m_limit_y[2];
-
- float m_oldposition[2];
- float m_angle[2];
-
-public:
-
- enum KX_ACT_MOUSE_OBJECT_AXIS {
- KX_ACT_MOUSE_OBJECT_AXIS_X = 0,
- KX_ACT_MOUSE_OBJECT_AXIS_Y,
- KX_ACT_MOUSE_OBJECT_AXIS_Z
- };
-
- enum KX_ACT_MOUSE_MODE {
- KX_ACT_MOUSE_NODEF = 0,
- KX_ACT_MOUSE_VISIBILITY,
- KX_ACT_MOUSE_LOOK,
- KX_ACT_MOUSE_MAX
- };
-
- KX_MouseActuator(
- SCA_IObject* gameobj,
- KX_KetsjiEngine* ketsjiEngine,
- SCA_MouseManager* eventmgr,
- int acttype,
- bool visible,
- bool* use_axis,
- float* threshold,
- bool* reset,
- int* object_axis,
- bool* local,
- float* sensitivity,
- float* limit_x,
- float* limit_y
- );
-
-
- ~KX_MouseActuator();
-
- CValue* GetReplica();
- virtual void ProcessReplica();
-
- virtual bool Update();
-
- /* check whether this value is valid */
- bool isValid(KX_ACT_MOUSE_MODE mode);
-
- virtual void getMousePosition(float*);
- virtual void setMousePosition(float, float);
-
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /* Methods */
-
- KX_PYMETHOD_DOC_NOARGS(KX_MouseActuator,Reset);
-
- /* Attributes */
-
- static PyObject* pyattr_get_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_limit_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_limit_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject* pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif /* WITH_PYTHON */
-
-};
-
-#endif //__KX_MOUSEACTUATOR_DOC
diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp b/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
deleted file mode 100644
index 451078d4a36..00000000000
--- a/source/gameengine/Ketsji/KX_MouseFocusSensor.cpp
+++ /dev/null
@@ -1,520 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * KX_MouseFocusSensor determines mouse in/out/over events.
- */
-
-/** \file gameengine/Ketsji/KX_MouseFocusSensor.cpp
- * \ingroup ketsji
- */
-
-#ifdef _MSC_VER
- /* This warning tells us about truncation of __long__ stl-generated names.
- * It can occasionally cause DevStudio to have internal compiler warnings. */
-# pragma warning(disable:4786)
-#endif
-
-#include <stdio.h>
-
-#include "MT_Point3.h"
-#include "RAS_FramingManager.h"
-#include "RAS_ICanvas.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_MeshObject.h"
-#include "SCA_IScene.h"
-#include "KX_Scene.h"
-#include "KX_Camera.h"
-#include "KX_MouseFocusSensor.h"
-#include "KX_PyMath.h"
-
-#include "KX_RayCast.h"
-#include "PHY_IPhysicsController.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-
-#include "KX_ClientObjectInfo.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_MouseFocusSensor::KX_MouseFocusSensor(SCA_MouseManager* eventmgr,
- int startx,
- int starty,
- short int mousemode,
- int focusmode,
- bool bTouchPulse,
- const STR_String& propname,
- bool bFindMaterial,
- bool bXRay,
- KX_Scene* kxscene,
- KX_KetsjiEngine *kxengine,
- SCA_IObject* gameobj)
- : SCA_MouseSensor(eventmgr, startx, starty, mousemode, gameobj),
- m_focusmode(focusmode),
- m_bTouchPulse(bTouchPulse),
- m_bXRay(bXRay),
- m_bFindMaterial(bFindMaterial),
- m_propertyname(propname),
- m_kxscene(kxscene),
- m_kxengine(kxengine)
-{
- Init();
-}
-
-void KX_MouseFocusSensor::Init()
-{
- m_mouse_over_in_previous_frame = (m_invert)?true:false;
- m_positive_event = false;
- m_hitObject = 0;
- m_hitObject_Last = NULL;
- m_reset = true;
-
- m_hitPosition.setValue(0,0,0);
- m_prevTargetPoint.setValue(0,0,0);
- m_prevSourcePoint.setValue(0,0,0);
- m_hitNormal.setValue(0,0,1);
-}
-
-bool KX_MouseFocusSensor::Evaluate()
-{
- bool result = false;
- bool obHasFocus = false;
- bool reset = m_reset && m_level;
-
-// cout << "evaluate focus mouse sensor "<<endl;
- m_reset = false;
- if (m_focusmode) {
- /* Focus behavior required. Test mouse-on. The rest is
- * equivalent to handling a key. */
- obHasFocus = ParentObjectHasFocus();
-
- if (!obHasFocus) {
- m_positive_event = false;
- if (m_mouse_over_in_previous_frame) {
- result = true;
- }
- } else {
- m_positive_event = true;
- if (!m_mouse_over_in_previous_frame) {
- result = true;
- }
- else if (m_bTouchPulse && (m_hitObject != m_hitObject_Last)) {
- result = true;
- }
- }
- if (reset) {
- // force an event
- result = true;
- }
- } else {
- /* No focus behavior required: revert to the basic mode. This
- * mode is never used, because the converter never makes this
- * sensor for a mouse-key event. It is here for
- * completeness. */
- result = SCA_MouseSensor::Evaluate();
- m_positive_event = (m_val!=0);
- }
-
- m_mouse_over_in_previous_frame = obHasFocus;
- m_hitObject_Last = (void *)m_hitObject;
-
- return result;
-}
-
-bool KX_MouseFocusSensor::RayHit(KX_ClientObjectInfo *client_info, KX_RayCast *result, void *UNUSED(data))
-{
- KX_GameObject* hitKXObj = client_info->m_gameobject;
-
- /* Is this me? In the ray test, there are a lot of extra checks
- * for aliasing artifacts from self-hits. That doesn't happen
- * here, so a simple test suffices. Or does the camera also get
- * self-hits? (No, and the raysensor shouldn't do it either, since
- * self-hits are excluded by setting the correct ignore-object.)
- * Hitspots now become valid. */
- KX_GameObject* thisObj = (KX_GameObject*) GetParent();
-
- bool bFound = false;
-
- if ((m_focusmode == 2) || hitKXObj == thisObj)
- {
- if (m_propertyname.Length() == 0)
- {
- bFound = true;
- }
- else
- {
- if (m_bFindMaterial) {
- for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) {
- RAS_MeshObject *meshObj = hitKXObj->GetMesh(i);
- for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) {
- bFound = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0;
- if (bFound)
- break;
- }
- }
- }
- else {
- bFound = hitKXObj->GetProperty(m_propertyname) != NULL;
- }
- }
-
- if (bFound)
- {
- m_hitObject = hitKXObj;
- m_hitPosition = result->m_hitPoint;
- m_hitNormal = result->m_hitNormal;
- m_hitUV = result->m_hitUV;
- return true;
- }
- }
-
- return true; // object must be visible to trigger
- //return false; // occluded objects can trigger
-}
-
-/* this function is used to pre-filter the object before casting the ray on them.
- * This is useful for "X-Ray" option when we want to see "through" unwanted object.
- */
-bool KX_MouseFocusSensor::NeedRayCast(KX_ClientObjectInfo *client, void *UNUSED(data))
-{
- KX_GameObject *hitKXObj = client->m_gameobject;
-
- if (client->m_type > KX_ClientObjectInfo::ACTOR)
- {
- // Unknown type of object, skip it.
- // Should not occur as the sensor objects are filtered in RayTest()
- printf("Invalid client type %d found ray casting\n", client->m_type);
- return false;
- }
- if (m_bXRay && m_propertyname.Length() != 0)
- {
- if (m_bFindMaterial)
- {
- bool found = false;
- for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) {
- RAS_MeshObject *meshObj = hitKXObj->GetMesh(i);
- for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) {
- found = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0;
- if (found)
- break;
- }
- }
- if (!found)
- return false;
- }
- else
- {
- if (hitKXObj->GetProperty(m_propertyname) == NULL)
- return false;
- }
- }
- return true;
-}
-
-bool KX_MouseFocusSensor::ParentObjectHasFocusCamera(KX_Camera *cam)
-{
- /* All screen handling in the gameengine is done by GL,
- * specifically the model/view and projection parts. The viewport
- * part is in the creator.
- *
- * The theory is this:
- * WCS - world coordinates
- * -> wcs_camcs_trafo ->
- * camCS - camera coordinates
- * -> camcs_clip_trafo ->
- * clipCS - normalized device coordinates?
- * -> normview_win_trafo
- * winCS - window coordinates
- *
- * The first two transforms are respectively the model/view and
- * the projection matrix. These are passed to the rasterizer, and
- * we store them in the camera for easy access.
- *
- * For normalized device coords (xn = x/w, yn = y/w/zw) the
- * windows coords become (lb = left bottom)
- *
- * xwin = [(xn + 1.0) * width]/2 + x_lb
- * ywin = [(yn + 1.0) * height]/2 + y_lb
- *
- * Inverting (blender y is flipped!):
- *
- * xn = 2(xwin - x_lb)/width - 1.0
- * yn = 2(ywin - y_lb)/height - 1.0
- * = 2(height - y_blender - y_lb)/height - 1.0
- * = 1.0 - 2(y_blender - y_lb)/height
- *
- * */
-
-
- /* Because we don't want to worry about resize events, camera
- * changes and all that crap, we just determine this over and
- * over. Stop whining. We have lots of other calculations to do
- * here as well. These reads are not the main cost. If there is no
- * canvas, the test is irrelevant. The 1.0 makes sure the
- * calculations don't bomb. Maybe we should explicitly guard for
- * division by 0.0...*/
-
- RAS_Rect area, viewport;
- short m_y_inv = m_kxengine->GetCanvas()->GetHeight()-m_y;
-
- m_kxengine->GetSceneViewport(m_kxscene, cam, area, viewport);
-
- /* Check if the mouse is in the viewport */
- if (( m_x < viewport.m_x2 && // less than right
- m_x > viewport.m_x1 && // more than then left
- m_y_inv < viewport.m_y2 && // below top
- m_y_inv > viewport.m_y1) == 0) // above bottom
- {
- return false;
- }
-
- float height = float(viewport.m_y2 - viewport.m_y1 + 1);
- float width = float(viewport.m_x2 - viewport.m_x1 + 1);
-
- float x_lb = float(viewport.m_x1);
- float y_lb = float(viewport.m_y1);
-
- MT_Vector4 frompoint;
- MT_Vector4 topoint;
-
- /* m_y_inv - inverting for a bounds check is only part of it, now make relative to view bounds */
- m_y_inv = (viewport.m_y2 - m_y_inv) + viewport.m_y1;
-
-
- /* There's some strangeness I don't fully get here... These values
- * _should_ be wrong! - see from point Z values */
-
-
- /* build the from and to point in normalized device coordinates
- * Normalized device coordinates are [-1,1] in x, y, z
- *
- * The actual z coordinates used don't have to be exact just infront and
- * behind of the near and far clip planes.
- */
- frompoint.setValue( (2 * (m_x-x_lb) / width) - 1.0f,
- 1.0f - (2 * (m_y_inv - y_lb) / height),
- -1.0f,
- 1.0f );
-
- topoint.setValue( (2 * (m_x-x_lb) / width) - 1.0f,
- 1.0f - (2 * (m_y_inv-y_lb) / height),
- 1.0f,
- 1.0f );
-
- /* camera to world */
- MT_Matrix4x4 camcs_wcs_matrix = MT_Matrix4x4(cam->GetCameraToWorld());
-
- /* badly defined, the first time round.... I wonder why... I might
- * want to guard against floating point errors here.*/
- MT_Matrix4x4 clip_camcs_matrix = MT_Matrix4x4(cam->GetProjectionMatrix());
- clip_camcs_matrix.invert();
-
- /* shoot-points: clip to cam to wcs . win to clip was already done.*/
- frompoint = clip_camcs_matrix * frompoint;
- topoint = clip_camcs_matrix * topoint;
- /* clipstart = - (frompoint[2] / frompoint[3])
- * clipend = - (topoint[2] / topoint[3]) */
- frompoint = camcs_wcs_matrix * frompoint;
- topoint = camcs_wcs_matrix * topoint;
-
- /* from hom wcs to 3d wcs: */
- m_prevSourcePoint.setValue( frompoint[0]/frompoint[3],
- frompoint[1]/frompoint[3],
- frompoint[2]/frompoint[3]);
-
- m_prevTargetPoint.setValue( topoint[0]/topoint[3],
- topoint[1]/topoint[3],
- topoint[2]/topoint[3]);
-
- /* 2. Get the object from PhysicsEnvironment */
- /* Shoot! Beware that the first argument here is an
- * ignore-object. We don't ignore anything... */
- PHY_IPhysicsController* physics_controller = cam->GetPhysicsController();
- PHY_IPhysicsEnvironment* physics_environment = m_kxscene->GetPhysicsEnvironment();
-
- // get UV mapping
- KX_RayCast::Callback<KX_MouseFocusSensor, void> callback(this,physics_controller,NULL,false,true);
-
- KX_RayCast::RayTest(physics_environment, m_prevSourcePoint, m_prevTargetPoint, callback);
-
- if (m_hitObject)
- return true;
-
- return false;
-}
-
-bool KX_MouseFocusSensor::ParentObjectHasFocus()
-{
- m_hitObject = 0;
- m_hitPosition.setValue(0,0,0);
- m_hitNormal.setValue(1,0,0);
-
- KX_Camera *cam= m_kxscene->GetActiveCamera();
-
- if (ParentObjectHasFocusCamera(cam))
- return true;
-
- list<class KX_Camera*>* cameras = m_kxscene->GetCameras();
- list<KX_Camera*>::iterator it = cameras->begin();
-
- while (it != cameras->end()) {
- if (((*it) != cam) && (*it)->GetViewport())
- if (ParentObjectHasFocusCamera(*it))
- return true;
-
- it++;
- }
-
- return false;
-}
-
-const MT_Point3& KX_MouseFocusSensor::RaySource() const
-{
- return m_prevSourcePoint;
-}
-
-const MT_Point3& KX_MouseFocusSensor::RayTarget() const
-{
- return m_prevTargetPoint;
-}
-
-const MT_Point3& KX_MouseFocusSensor::HitPosition() const
-{
- return m_hitPosition;
-}
-
-const MT_Vector3& KX_MouseFocusSensor::HitNormal() const
-{
- return m_hitNormal;
-}
-
-const MT_Vector2& KX_MouseFocusSensor::HitUV() const
-{
- return m_hitUV;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_MouseFocusSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_MouseFocusSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_MouseSensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_MouseFocusSensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_MouseFocusSensor::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("raySource", KX_MouseFocusSensor, pyattr_get_ray_source),
- KX_PYATTRIBUTE_RO_FUNCTION("rayTarget", KX_MouseFocusSensor, pyattr_get_ray_target),
- KX_PYATTRIBUTE_RO_FUNCTION("rayDirection", KX_MouseFocusSensor, pyattr_get_ray_direction),
- KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_MouseFocusSensor, pyattr_get_hit_object),
- KX_PYATTRIBUTE_RO_FUNCTION("hitPosition", KX_MouseFocusSensor, pyattr_get_hit_position),
- KX_PYATTRIBUTE_RO_FUNCTION("hitNormal", KX_MouseFocusSensor, pyattr_get_hit_normal),
- KX_PYATTRIBUTE_RO_FUNCTION("hitUV", KX_MouseFocusSensor, pyattr_get_hit_uv),
- KX_PYATTRIBUTE_BOOL_RW("usePulseFocus", KX_MouseFocusSensor, m_bTouchPulse),
- KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_MouseFocusSensor, m_bXRay),
- KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_MouseFocusSensor, m_bFindMaterial),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_MouseFocusSensor, m_propertyname),
- { NULL } //Sentinel
-};
-
-/* Attributes */
-PyObject *KX_MouseFocusSensor::pyattr_get_ray_source(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
- return PyObjectFrom(self->RaySource());
-}
-
-PyObject *KX_MouseFocusSensor::pyattr_get_ray_target(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
- return PyObjectFrom(self->RayTarget());
-}
-
-PyObject *KX_MouseFocusSensor::pyattr_get_ray_direction(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
- MT_Vector3 dir = self->RayTarget() - self->RaySource();
- if (MT_fuzzyZero(dir)) dir.setValue(0,0,0);
- else dir.normalize();
- return PyObjectFrom(dir);
-}
-
-PyObject *KX_MouseFocusSensor::pyattr_get_hit_object(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
-
- if (self->m_hitObject)
- return self->m_hitObject->GetProxy();
-
- Py_RETURN_NONE;
-}
-
-PyObject *KX_MouseFocusSensor::pyattr_get_hit_position(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
- return PyObjectFrom(self->HitPosition());
-}
-
-PyObject *KX_MouseFocusSensor::pyattr_get_hit_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
- return PyObjectFrom(self->HitNormal());
-}
-
-PyObject *KX_MouseFocusSensor::pyattr_get_hit_uv(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_MouseFocusSensor* self = static_cast<KX_MouseFocusSensor*>(self_v);
- return PyObjectFrom(self->HitUV());
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
-
diff --git a/source/gameengine/Ketsji/KX_MouseFocusSensor.h b/source/gameengine/Ketsji/KX_MouseFocusSensor.h
deleted file mode 100644
index dd9295b2ff4..00000000000
--- a/source/gameengine/Ketsji/KX_MouseFocusSensor.h
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_MouseFocusSensor.h
- * \ingroup ketsji
- * \brief KX_MouseFocusSensor determines mouse in/out/over events.
- */
-
-#ifndef __KX_MOUSEFOCUSSENSOR_H__
-#define __KX_MOUSEFOCUSSENSOR_H__
-
-#include "SCA_MouseSensor.h"
-
-#include "BLI_utildefines.h"
-
-class KX_RayCast;
-
-/**
- * The mouse focus sensor extends the basic SCA_MouseSensor. It has
- * been placed in KX because it needs access to the rasterizer and
- * SuMO.
- *
- * - extend the valid modes?
- * - */
-class KX_MouseFocusSensor : public SCA_MouseSensor
-{
-
- Py_Header
-
- public:
-
- KX_MouseFocusSensor(class SCA_MouseManager* eventmgr,
- int startx,
- int starty,
- short int mousemode,
- int focusmode,
- bool bTouchPulse,
- const STR_String& propname,
- bool bFindMaterial,
- bool bXRay,
- KX_Scene* kxscene,
- KX_KetsjiEngine* kxengine,
- SCA_IObject* gameobj);
-
- virtual ~KX_MouseFocusSensor() { }
- virtual CValue* GetReplica() {
- CValue* replica = new KX_MouseFocusSensor(*this);
- // this will copy properties and so on...
- replica->ProcessReplica();
- return replica;
- };
-
- virtual void Replace_IScene(SCA_IScene *val)
- {
- m_kxscene= static_cast<KX_Scene *>(val);
- };
-
-
- /**
- * \attention Overrides default evaluate.
- */
- virtual bool Evaluate();
- virtual void Init();
-
- virtual bool IsPositiveTrigger() {
- bool result = m_positive_event;
- if (m_invert) result = !result;
- return result;
- };
-
- /// \see KX_RayCast
- bool RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void *UNUSED(data));
- /// \see KX_RayCast
- bool NeedRayCast(KX_ClientObjectInfo *client, void *UNUSED(data));
-
- const MT_Point3& RaySource() const;
- const MT_Point3& RayTarget() const;
- const MT_Point3& HitPosition() const;
- const MT_Vector3& HitNormal() const;
- const MT_Vector2& HitUV() const;
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /* attributes */
- static PyObject* pyattr_get_ray_source(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_ray_target(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_ray_direction(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_hit_object(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_hit_position(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_hit_normal(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_hit_uv(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
-#endif /* WITH_PYTHON */
-
- /* --------------------------------------------------------------------- */
- SCA_IObject* m_hitObject;
- void* m_hitObject_Last; /* only use for comparison, never access */
-
- private:
- /**
- * The focus mode. 1 for handling focus, 0 for not handling, 2 for focus on any object
- */
- int m_focusmode;
-
- /**
- * Flags whether the previous test showed a mouse-over.
- */
- bool m_mouse_over_in_previous_frame;
-
- /**
- * Flags whether changes in hit object should trigger a pulse
- */
- bool m_bTouchPulse;
-
- /**
- * Flags get through other objects
- */
- bool m_bXRay;
-
- /**
- * Flags material
- */
- bool m_bFindMaterial;
-
- /**
- * Property or material name
- */
- STR_String m_propertyname;
-
- /**
- * Flags whether the previous test evaluated positive.
- */
- bool m_positive_event;
-
- /**
- * Tests whether the object is in mouse focus for this camera
- */
- bool ParentObjectHasFocusCamera(KX_Camera *cam);
-
- /**
- * Tests whether the object is in mouse focus in this scene.
- */
- bool ParentObjectHasFocus(void);
-
- /**
- * (in game world coordinates) the place where the object was hit.
- */
- MT_Point3 m_hitPosition;
-
- /**
- * (in game world coordinates) the position to which to shoot the ray.
- */
- MT_Point3 m_prevTargetPoint;
-
- /**
- * (in game world coordinates) the position from which to shoot the ray.
- */
- MT_Point3 m_prevSourcePoint;
-
- /**
- * (in game world coordinates) the face normal of the vertex where
- * the object was hit. */
- MT_Vector3 m_hitNormal;
-
- /**
- * UV texture coordinate of the hit point if any, (0,0) otherwise
- */
- MT_Vector2 m_hitUV;
-
- /**
- * The KX scene that holds the camera. The camera position
- * determines a part of the start location of the picking ray. */
- KX_Scene* m_kxscene;
-
- /**
- * The KX engine is needed for computing the viewport */
- KX_KetsjiEngine* m_kxengine;
-};
-
-#endif /* __KX_MOUSESENSOR */
diff --git a/source/gameengine/Ketsji/KX_NavMeshObject.cpp b/source/gameengine/Ketsji/KX_NavMeshObject.cpp
deleted file mode 100644
index 5beda2e038a..00000000000
--- a/source/gameengine/Ketsji/KX_NavMeshObject.cpp
+++ /dev/null
@@ -1,743 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_math_vector.h"
-#include "KX_NavMeshObject.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-extern "C" {
-#include "BKE_scene.h"
-#include "BKE_customdata.h"
-#include "BKE_cdderivedmesh.h"
-#include "BKE_DerivedMesh.h"
-#include "BKE_navmesh_conversion.h"
-}
-
-#include "KX_PythonInit.h"
-#include "KX_PyMath.h"
-#include "EXP_Value.h"
-#include "Recast.h"
-#include "DetourStatNavMeshBuilder.h"
-#include "KX_ObstacleSimulation.h"
-
-#define MAX_PATH_LEN 256
-static const float polyPickExt[3] = {2, 4, 2};
-
-static void calcMeshBounds(const float* vert, int nverts, float* bmin, float* bmax)
-{
- bmin[0] = bmax[0] = vert[0];
- bmin[1] = bmax[1] = vert[1];
- bmin[2] = bmax[2] = vert[2];
- for (int i=1; i<nverts; i++)
- {
- if (bmin[0]>vert[3*i+0]) bmin[0] = vert[3*i+0];
- if (bmin[1]>vert[3*i+1]) bmin[1] = vert[3*i+1];
- if (bmin[2]>vert[3*i+2]) bmin[2] = vert[3*i+2];
-
- if (bmax[0]<vert[3*i+0]) bmax[0] = vert[3*i+0];
- if (bmax[1]<vert[3*i+1]) bmax[1] = vert[3*i+1];
- if (bmax[2]<vert[3*i+2]) bmax[2] = vert[3*i+2];
- }
-}
-
-inline void flipAxes(float* vec)
-{
- std::swap(vec[1],vec[2]);
-}
-KX_NavMeshObject::KX_NavMeshObject(void* sgReplicationInfo, SG_Callbacks callbacks)
-: KX_GameObject(sgReplicationInfo, callbacks)
-, m_navMesh(NULL)
-{
-
-}
-
-KX_NavMeshObject::~KX_NavMeshObject()
-{
- if (m_navMesh)
- delete m_navMesh;
-}
-
-CValue* KX_NavMeshObject::GetReplica()
-{
- KX_NavMeshObject* replica = new KX_NavMeshObject(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_NavMeshObject::ProcessReplica()
-{
- KX_GameObject::ProcessReplica();
- m_navMesh = NULL; /* without this, building frees the navmesh we copied from */
- if (!BuildNavMesh()) {
- std::cout << "Error in " << __func__ << ": unable to build navigation mesh" << std::endl;
- return;
- }
- KX_Scene* scene = KX_GetActiveScene();
- KX_ObstacleSimulation* obssimulation = scene->GetObstacleSimulation();
- if (obssimulation)
- obssimulation->AddObstaclesForNavMesh(this);
-}
-
-bool KX_NavMeshObject::BuildVertIndArrays(float *&vertices, int& nverts,
- unsigned short* &polys, int& npolys, unsigned short *&dmeshes,
- float *&dvertices, int &ndvertsuniq, unsigned short *&dtris,
- int& ndtris, int &vertsPerPoly)
-{
- DerivedMesh* dm = mesh_create_derived_no_virtual(GetScene()->GetBlenderScene(), GetBlenderObject(),
- NULL, CD_MASK_MESH);
- CustomData *pdata = dm->getPolyDataLayout(dm);
- int* recastData = (int*) CustomData_get_layer(pdata, CD_RECAST);
- if (recastData)
- {
- int *dtrisToPolysMap=NULL, *dtrisToTrisMap=NULL, *trisToFacesMap=NULL;
- int nAllVerts = 0;
- float *allVerts = NULL;
- buildNavMeshDataByDerivedMesh(dm, &vertsPerPoly, &nAllVerts, &allVerts, &ndtris, &dtris,
- &npolys, &dmeshes, &polys, &dtrisToPolysMap, &dtrisToTrisMap, &trisToFacesMap);
-
- MEM_SAFE_FREE(dtrisToPolysMap);
- MEM_SAFE_FREE(dtrisToTrisMap);
- MEM_SAFE_FREE(trisToFacesMap);
-
- unsigned short *verticesMap = (unsigned short *)MEM_mallocN(sizeof(*verticesMap) * nAllVerts, __func__);
- memset(verticesMap, 0xff, sizeof(*verticesMap) * nAllVerts);
- int curIdx = 0;
- //vertices - mesh verts
- //iterate over all polys and create map for their vertices first...
- for (int polyidx=0; polyidx<npolys; polyidx++)
- {
- unsigned short* poly = &polys[polyidx*vertsPerPoly*2];
- for (int i=0; i<vertsPerPoly; i++)
- {
- unsigned short idx = poly[i];
- if (idx==0xffff)
- break;
- if (verticesMap[idx]==0xffff)
- {
- verticesMap[idx] = curIdx++;
- }
- poly[i] = verticesMap[idx];
- }
- }
- nverts = curIdx;
- //...then iterate over detailed meshes
- //transform indices to local ones (for each navigation polygon)
- for (int polyidx=0; polyidx<npolys; polyidx++)
- {
- unsigned short *poly = &polys[polyidx*vertsPerPoly*2];
- int nv = polyNumVerts(poly, vertsPerPoly);
- unsigned short *dmesh = &dmeshes[4*polyidx];
- unsigned short tribase = dmesh[2];
- unsigned short trinum = dmesh[3];
- unsigned short vbase = curIdx;
- for (int j=0; j<trinum; j++)
- {
- unsigned short* dtri = &dtris[(tribase+j)*3*2];
- for (int k=0; k<3; k++)
- {
- int newVertexIdx = verticesMap[dtri[k]];
- if (newVertexIdx==0xffff)
- {
- newVertexIdx = curIdx++;
- verticesMap[dtri[k]] = newVertexIdx;
- }
-
- if (newVertexIdx<nverts)
- {
- //it's polygon vertex ("shared")
- int idxInPoly = polyFindVertex(poly, vertsPerPoly, newVertexIdx);
- if (idxInPoly==-1)
- {
- printf("Building NavMeshObject: Error! Can't find vertex in polygon\n");
- return false;
- }
- dtri[k] = idxInPoly;
- }
- else
- {
- dtri[k] = newVertexIdx - vbase + nv;
- }
- }
- }
- dmesh[0] = vbase-nverts; //verts base
- dmesh[1] = curIdx-vbase; //verts num
- }
-
- vertices = new float[nverts*3];
- ndvertsuniq = curIdx - nverts;
- if (ndvertsuniq>0)
- {
- dvertices = new float[ndvertsuniq*3];
- }
- for (int vi=0; vi<nAllVerts; vi++)
- {
- int newIdx = verticesMap[vi];
- if (newIdx!=0xffff)
- {
- if (newIdx<nverts)
- {
- //navigation mesh vertex
- memcpy(vertices+3*newIdx, allVerts+3*vi, 3*sizeof(float));
- }
- else
- {
- //detailed mesh vertex
- memcpy(dvertices+3*(newIdx-nverts), allVerts+3*vi, 3*sizeof(float));
- }
- }
- }
-
- MEM_SAFE_FREE(allVerts);
-
- MEM_freeN(verticesMap);
- }
- else
- {
- //create from RAS_MeshObject (detailed mesh is fake)
- RAS_MeshObject* meshobj = GetMesh(0);
- vertsPerPoly = 3;
- nverts = meshobj->m_sharedvertex_map.size();
- if (nverts >= 0xffff)
- return false;
- //calculate count of tris
- int nmeshpolys = meshobj->NumPolygons();
- npolys = nmeshpolys;
- for (int p=0; p<nmeshpolys; p++)
- {
- int vertcount = meshobj->GetPolygon(p)->VertexCount();
- npolys+=vertcount-3;
- }
-
- //create verts
- vertices = new float[nverts*3];
- float* vert = vertices;
- for (int vi=0; vi<nverts; vi++)
- {
- const float* pos = !meshobj->m_sharedvertex_map[vi].empty() ? meshobj->GetVertexLocation(vi) : NULL;
- if (pos)
- copy_v3_v3(vert, pos);
- else
- {
- memset(vert, 0, 3*sizeof(float)); //vertex isn't in any poly, set dummy zero coordinates
- }
- vert+=3;
- }
-
- //create tris
- polys = (unsigned short *)MEM_callocN(sizeof(unsigned short)*3*2*npolys, "BuildVertIndArrays polys");
- memset(polys, 0xff, sizeof(unsigned short)*3*2*npolys);
- unsigned short *poly = polys;
- RAS_Polygon* raspoly;
- for (int p=0; p<nmeshpolys; p++)
- {
- raspoly = meshobj->GetPolygon(p);
- for (int v=0; v<raspoly->VertexCount()-2; v++)
- {
- poly[0] = raspoly->GetVertex(0)->getOrigIndex();
- for (size_t i=1; i<3; i++)
- {
- poly[i] = raspoly->GetVertex(v+i)->getOrigIndex();
- }
- poly += 6;
- }
- }
- dmeshes = NULL;
- dvertices = NULL;
- ndvertsuniq = 0;
- dtris = NULL;
- ndtris = npolys;
- }
- dm->release(dm);
-
- return true;
-}
-
-
-bool KX_NavMeshObject::BuildNavMesh()
-{
- if (m_navMesh)
- {
- delete m_navMesh;
- m_navMesh = NULL;
- }
-
- if (GetMeshCount()==0)
- {
- printf("Can't find mesh for navmesh object: %s\n", m_name.ReadPtr());
- return false;
- }
-
- float *vertices = NULL, *dvertices = NULL;
- unsigned short *polys = NULL, *dtris = NULL, *dmeshes = NULL;
- int nverts = 0, npolys = 0, ndvertsuniq = 0, ndtris = 0;
- int vertsPerPoly = 0;
- if (!BuildVertIndArrays(vertices, nverts, polys, npolys,
- dmeshes, dvertices, ndvertsuniq, dtris, ndtris, vertsPerPoly )
- || vertsPerPoly<3)
- {
- printf("Can't build navigation mesh data for object:%s\n", m_name.ReadPtr());
- if (vertices) {
- delete[] vertices;
- }
- if (dvertices) {
- delete[] dvertices;
- }
- return false;
- }
-
- MT_Point3 pos;
- if (dmeshes==NULL)
- {
- for (int i=0; i<nverts; i++)
- {
- flipAxes(&vertices[i*3]);
- }
- for (int i=0; i<ndvertsuniq; i++)
- {
- flipAxes(&dvertices[i*3]);
- }
- }
-
- if (!buildMeshAdjacency(polys, npolys, nverts, vertsPerPoly)) {
- std::cout << __func__ << ": unable to build mesh adjacency information." << std::endl;
- delete[] vertices;
- return false;
- }
-
- float cs = 0.2f;
-
- if (!nverts || !npolys)
- {
- if (vertices) delete[] vertices;
- return false;
- }
-
- float bmin[3], bmax[3];
- calcMeshBounds(vertices, nverts, bmin, bmax);
- //quantize vertex pos
- unsigned short* vertsi = new unsigned short[3*nverts];
- float ics = 1.f/cs;
- for (int i=0; i<nverts; i++)
- {
- vertsi[3*i+0] = static_cast<unsigned short>((vertices[3*i+0]-bmin[0])*ics);
- vertsi[3*i+1] = static_cast<unsigned short>((vertices[3*i+1]-bmin[1])*ics);
- vertsi[3*i+2] = static_cast<unsigned short>((vertices[3*i+2]-bmin[2])*ics);
- }
-
- // Calculate data size
- const int headerSize = sizeof(dtStatNavMeshHeader);
- const int vertsSize = sizeof(float)*3*nverts;
- const int polysSize = sizeof(dtStatPoly)*npolys;
- const int nodesSize = sizeof(dtStatBVNode)*npolys*2;
- const int detailMeshesSize = sizeof(dtStatPolyDetail)*npolys;
- const int detailVertsSize = sizeof(float)*3*ndvertsuniq;
- const int detailTrisSize = sizeof(unsigned char)*4*ndtris;
-
- const int dataSize = headerSize + vertsSize + polysSize + nodesSize +
- detailMeshesSize + detailVertsSize + detailTrisSize;
- unsigned char* data = new unsigned char[dataSize];
- if (!data)
- return false;
- memset(data, 0, dataSize);
-
- unsigned char* d = data;
- dtStatNavMeshHeader* header = (dtStatNavMeshHeader*)d; d += headerSize;
- float* navVerts = (float*)d; d += vertsSize;
- dtStatPoly* navPolys = (dtStatPoly*)d; d += polysSize;
- dtStatBVNode* navNodes = (dtStatBVNode*)d; d += nodesSize;
- dtStatPolyDetail* navDMeshes = (dtStatPolyDetail*)d; d += detailMeshesSize;
- float* navDVerts = (float*)d; d += detailVertsSize;
- unsigned char* navDTris = (unsigned char*)d; d += detailTrisSize;
-
- // Store header
- header->magic = DT_STAT_NAVMESH_MAGIC;
- header->version = DT_STAT_NAVMESH_VERSION;
- header->npolys = npolys;
- header->nverts = nverts;
- header->cs = cs;
- header->bmin[0] = bmin[0];
- header->bmin[1] = bmin[1];
- header->bmin[2] = bmin[2];
- header->bmax[0] = bmax[0];
- header->bmax[1] = bmax[1];
- header->bmax[2] = bmax[2];
- header->ndmeshes = npolys;
- header->ndverts = ndvertsuniq;
- header->ndtris = ndtris;
-
- // Store vertices
- for (int i = 0; i < nverts; ++i)
- {
- const unsigned short* iv = &vertsi[i*3];
- float* v = &navVerts[i*3];
- v[0] = bmin[0] + iv[0] * cs;
- v[1] = bmin[1] + iv[1] * cs;
- v[2] = bmin[2] + iv[2] * cs;
- }
- //memcpy(navVerts, vertices, nverts*3*sizeof(float));
-
- // Store polygons
- const unsigned short* src = polys;
- for (int i = 0; i < npolys; ++i)
- {
- dtStatPoly* p = &navPolys[i];
- p->nv = 0;
- for (int j = 0; j < vertsPerPoly; ++j)
- {
- if (src[j] == 0xffff) break;
- p->v[j] = src[j];
- p->n[j] = src[vertsPerPoly+j]+1;
- p->nv++;
- }
- src += vertsPerPoly*2;
- }
-
- header->nnodes = createBVTree(vertsi, nverts, polys, npolys, vertsPerPoly,
- cs, cs, npolys*2, navNodes);
-
-
- if (dmeshes==NULL)
- {
- //create fake detail meshes
- for (int i = 0; i < npolys; ++i)
- {
- dtStatPolyDetail& dtl = navDMeshes[i];
- dtl.vbase = 0;
- dtl.nverts = 0;
- dtl.tbase = i;
- dtl.ntris = 1;
- }
- // setup triangles.
- unsigned char* tri = navDTris;
- for (size_t i=0; i<ndtris; i++)
- {
- for (size_t j=0; j<3; j++)
- tri[4*i+j] = j;
- }
- }
- else
- {
- //verts
- memcpy(navDVerts, dvertices, ndvertsuniq*3*sizeof(float));
- //tris
- unsigned char* tri = navDTris;
- for (size_t i=0; i<ndtris; i++)
- {
- for (size_t j=0; j<3; j++)
- tri[4*i+j] = dtris[6*i+j];
- }
- //detailed meshes
- for (int i = 0; i < npolys; ++i)
- {
- dtStatPolyDetail& dtl = navDMeshes[i];
- dtl.vbase = dmeshes[i*4+0];
- dtl.nverts = dmeshes[i*4+1];
- dtl.tbase = dmeshes[i*4+2];
- dtl.ntris = dmeshes[i*4+3];
- }
- }
-
- m_navMesh = new dtStatNavMesh;
- m_navMesh->init(data, dataSize, true);
-
- delete [] vertices;
-
- /* navmesh conversion is using C guarded alloc for memory allocaitons */
- MEM_freeN(polys);
- if (dmeshes) MEM_freeN(dmeshes);
- if (dtris) MEM_freeN(dtris);
-
- if (dvertices)
- delete [] dvertices;
-
- if (vertsi)
- delete [] vertsi;
-
- return true;
-}
-
-dtStatNavMesh* KX_NavMeshObject::GetNavMesh()
-{
- return m_navMesh;
-}
-
-void KX_NavMeshObject::DrawNavMesh(NavMeshRenderMode renderMode)
-{
- if (!m_navMesh)
- return;
- MT_Vector3 color(0.f, 0.f, 0.f);
-
- switch (renderMode)
- {
- case RM_POLYS :
- case RM_WALLS :
- for (int pi=0; pi<m_navMesh->getPolyCount(); pi++)
- {
- const dtStatPoly* poly = m_navMesh->getPoly(pi);
-
- for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
- {
- if (poly->n[j] && renderMode==RM_WALLS)
- continue;
- const float* vif = m_navMesh->getVertex(poly->v[i]);
- const float* vjf = m_navMesh->getVertex(poly->v[j]);
- MT_Point3 vi(vif[0], vif[2], vif[1]);
- MT_Point3 vj(vjf[0], vjf[2], vjf[1]);
- vi = TransformToWorldCoords(vi);
- vj = TransformToWorldCoords(vj);
- KX_RasterizerDrawDebugLine(vi, vj, color);
- }
- }
- break;
- case RM_TRIS :
- for (int i = 0; i < m_navMesh->getPolyDetailCount(); ++i)
- {
- const dtStatPoly* p = m_navMesh->getPoly(i);
- const dtStatPolyDetail* pd = m_navMesh->getPolyDetail(i);
-
- for (int j = 0; j < pd->ntris; ++j)
- {
- const unsigned char* t = m_navMesh->getDetailTri(pd->tbase+j);
- MT_Point3 tri[3];
- for (int k = 0; k < 3; ++k)
- {
- const float* v;
- if (t[k] < p->nv)
- v = m_navMesh->getVertex(p->v[t[k]]);
- else
- v = m_navMesh->getDetailVertex(pd->vbase+(t[k]-p->nv));
- float pos[3];
- rcVcopy(pos, v);
- flipAxes(pos);
- tri[k].setValue(pos);
- }
-
- for (int k=0; k<3; k++)
- tri[k] = TransformToWorldCoords(tri[k]);
-
- for (int k=0; k<3; k++)
- KX_RasterizerDrawDebugLine(tri[k], tri[(k+1)%3], color);
- }
- }
- break;
- default:
- /* pass */
- break;
- }
-}
-
-MT_Point3 KX_NavMeshObject::TransformToLocalCoords(const MT_Point3& wpos)
-{
- MT_Matrix3x3 orientation = NodeGetWorldOrientation();
- const MT_Vector3& scaling = NodeGetWorldScaling();
- orientation.scale(scaling[0], scaling[1], scaling[2]);
- MT_Transform worldtr(NodeGetWorldPosition(), orientation);
- MT_Transform invworldtr;
- invworldtr.invert(worldtr);
- MT_Point3 lpos = invworldtr(wpos);
- return lpos;
-}
-
-MT_Point3 KX_NavMeshObject::TransformToWorldCoords(const MT_Point3& lpos)
-{
- MT_Matrix3x3 orientation = NodeGetWorldOrientation();
- const MT_Vector3& scaling = NodeGetWorldScaling();
- orientation.scale(scaling[0], scaling[1], scaling[2]);
- MT_Transform worldtr(NodeGetWorldPosition(), orientation);
- MT_Point3 wpos = worldtr(lpos);
- return wpos;
-}
-
-int KX_NavMeshObject::FindPath(const MT_Point3& from, const MT_Point3& to, float* path, int maxPathLen)
-{
- if (!m_navMesh)
- return 0;
- MT_Point3 localfrom = TransformToLocalCoords(from);
- MT_Point3 localto = TransformToLocalCoords(to);
- float spos[3], epos[3];
- localfrom.getValue(spos); flipAxes(spos);
- localto.getValue(epos); flipAxes(epos);
- dtStatPolyRef sPolyRef = m_navMesh->findNearestPoly(spos, polyPickExt);
- dtStatPolyRef ePolyRef = m_navMesh->findNearestPoly(epos, polyPickExt);
-
- int pathLen = 0;
- if (sPolyRef && ePolyRef)
- {
- dtStatPolyRef* polys = new dtStatPolyRef[maxPathLen];
- int npolys;
- npolys = m_navMesh->findPath(sPolyRef, ePolyRef, spos, epos, polys, maxPathLen);
- if (npolys)
- {
- pathLen = m_navMesh->findStraightPath(spos, epos, polys, npolys, path, maxPathLen);
- for (int i=0; i<pathLen; i++)
- {
- flipAxes(&path[i*3]);
- MT_Point3 waypoint(&path[i*3]);
- waypoint = TransformToWorldCoords(waypoint);
- waypoint.getValue(&path[i*3]);
- }
- }
-
- delete[] polys;
- }
-
- return pathLen;
-}
-
-float KX_NavMeshObject::Raycast(const MT_Point3& from, const MT_Point3& to)
-{
- if (!m_navMesh)
- return 0.f;
- MT_Point3 localfrom = TransformToLocalCoords(from);
- MT_Point3 localto = TransformToLocalCoords(to);
- float spos[3], epos[3];
- localfrom.getValue(spos); flipAxes(spos);
- localto.getValue(epos); flipAxes(epos);
- dtStatPolyRef sPolyRef = m_navMesh->findNearestPoly(spos, polyPickExt);
- float t=0;
- static dtStatPolyRef polys[MAX_PATH_LEN];
- m_navMesh->raycast(sPolyRef, spos, epos, t, polys, MAX_PATH_LEN);
- return t;
-}
-
-void KX_NavMeshObject::DrawPath(const float *path, int pathLen, const MT_Vector3& color)
-{
- MT_Vector3 a,b;
- for (int i=0; i<pathLen-1; i++)
- {
- a.setValue(&path[3*i]);
- b.setValue(&path[3*(i+1)]);
- KX_RasterizerDrawDebugLine(a, b, color);
- }
-}
-
-
-#ifdef WITH_PYTHON
-//----------------------------------------------------------------------------
-//Python
-
-PyTypeObject KX_NavMeshObject::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_NavMeshObject",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- 0,
- 0,
- 0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_GameObject::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyAttributeDef KX_NavMeshObject::Attributes[] = {
- { NULL } //Sentinel
-};
-
-//KX_PYMETHODTABLE_NOARGS(KX_GameObject, getD),
-PyMethodDef KX_NavMeshObject::Methods[] = {
- KX_PYMETHODTABLE(KX_NavMeshObject, findPath),
- KX_PYMETHODTABLE(KX_NavMeshObject, raycast),
- KX_PYMETHODTABLE(KX_NavMeshObject, draw),
- KX_PYMETHODTABLE(KX_NavMeshObject, rebuild),
- {NULL,NULL} //Sentinel
-};
-
-KX_PYMETHODDEF_DOC(KX_NavMeshObject, findPath,
- "findPath(start, goal): find path from start to goal points\n"
- "Returns a path as list of points)\n")
-{
- PyObject *ob_from, *ob_to;
- if (!PyArg_ParseTuple(args,"OO:getPath",&ob_from,&ob_to))
- return NULL;
- MT_Point3 from, to;
- if (!PyVecTo(ob_from, from) || !PyVecTo(ob_to, to))
- return NULL;
-
- float path[MAX_PATH_LEN*3];
- int pathLen = FindPath(from, to, path, MAX_PATH_LEN);
- PyObject *pathList = PyList_New( pathLen );
- for (int i=0; i<pathLen; i++)
- {
- MT_Point3 point(&path[3*i]);
- PyList_SET_ITEM(pathList, i, PyObjectFrom(point));
- }
-
- return pathList;
-}
-
-KX_PYMETHODDEF_DOC(KX_NavMeshObject, raycast,
- "raycast(start, goal): raycast from start to goal points\n"
- "Returns hit factor)\n")
-{
- PyObject *ob_from, *ob_to;
- if (!PyArg_ParseTuple(args,"OO:getPath",&ob_from,&ob_to))
- return NULL;
- MT_Point3 from, to;
- if (!PyVecTo(ob_from, from) || !PyVecTo(ob_to, to))
- return NULL;
- float hit = Raycast(from, to);
- return PyFloat_FromDouble(hit);
-}
-
-KX_PYMETHODDEF_DOC(KX_NavMeshObject, draw,
- "draw(mode): navigation mesh debug drawing\n"
- "mode: WALLS, POLYS, TRIS\n")
-{
- int arg;
- NavMeshRenderMode renderMode = RM_TRIS;
- if (PyArg_ParseTuple(args,"i:rebuild",&arg) && arg>=0 && arg<RM_MAX)
- renderMode = (NavMeshRenderMode)arg;
- DrawNavMesh(renderMode);
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_NavMeshObject, rebuild,
- "rebuild(): rebuild navigation mesh\n")
-{
- BuildNavMesh();
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_NavMeshObject.h b/source/gameengine/Ketsji/KX_NavMeshObject.h
deleted file mode 100644
index af178f9aaee..00000000000
--- a/source/gameengine/Ketsji/KX_NavMeshObject.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-#ifndef __KX_NAVMESHOBJECT_H__
-#define __KX_NAVMESHOBJECT_H__
-#include "DetourStatNavMesh.h"
-#include "KX_GameObject.h"
-#include "EXP_PyObjectPlus.h"
-#include <vector>
-
-class RAS_MeshObject;
-class MT_Transform;
-
-class KX_NavMeshObject: public KX_GameObject
-{
- Py_Header
-
-protected:
- dtStatNavMesh* m_navMesh;
-
- bool BuildVertIndArrays(float *&vertices, int& nverts,
- unsigned short* &polys, int& npolys, unsigned short *&dmeshes,
- float *&dvertices, int &ndvertsuniq, unsigned short* &dtris,
- int& ndtris, int &vertsPerPoly);
-
-public:
- KX_NavMeshObject(void* sgReplicationInfo, SG_Callbacks callbacks);
- ~KX_NavMeshObject();
-
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
-
-
- bool BuildNavMesh();
- dtStatNavMesh* GetNavMesh();
- int FindPath(const MT_Point3& from, const MT_Point3& to, float* path, int maxPathLen);
- float Raycast(const MT_Point3& from, const MT_Point3& to);
-
- enum NavMeshRenderMode {RM_WALLS, RM_POLYS, RM_TRIS, RM_MAX};
- void DrawNavMesh(NavMeshRenderMode mode);
- void DrawPath(const float *path, int pathLen, const MT_Vector3& color);
-
- MT_Point3 TransformToLocalCoords(const MT_Point3& wpos);
- MT_Point3 TransformToWorldCoords(const MT_Point3& lpos);
-#ifdef WITH_PYTHON
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- KX_PYMETHOD_DOC(KX_NavMeshObject, findPath);
- KX_PYMETHOD_DOC(KX_NavMeshObject, raycast);
- KX_PYMETHOD_DOC(KX_NavMeshObject, draw);
- KX_PYMETHOD_DOC_NOARGS(KX_NavMeshObject, rebuild);
-#endif /* WITH_PYTHON */
-};
-
-#endif /* __KX_NAVMESHOBJECT_H__ */
diff --git a/source/gameengine/Ketsji/KX_NearSensor.cpp b/source/gameengine/Ketsji/KX_NearSensor.cpp
deleted file mode 100644
index 92ab8f412d9..00000000000
--- a/source/gameengine/Ketsji/KX_NearSensor.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Sense if other objects are near
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_NearSensor.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_NearSensor.h"
-#include "SCA_LogicManager.h"
-#include "KX_GameObject.h"
-#include "KX_TouchEventManager.h"
-#include "KX_Scene.h" // needed to create a replica
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IPhysicsController.h"
-#include "PHY_IMotionState.h"
-
-KX_NearSensor::KX_NearSensor(SCA_EventManager* eventmgr,
- KX_GameObject* gameobj,
- float margin,
- float resetmargin,
- bool bFindMaterial,
- const STR_String& touchedpropname,
- PHY_IPhysicsController* ctrl)
- :KX_TouchSensor(eventmgr,
- gameobj,
- bFindMaterial,
- false,
- touchedpropname),
- m_Margin(margin),
- m_ResetMargin(resetmargin)
-
-{
-
- gameobj->getClientInfo()->m_sensors.remove(this);
- m_client_info = new KX_ClientObjectInfo(gameobj, KX_ClientObjectInfo::SENSOR);
- m_client_info->m_sensors.push_back(this);
-
- //DT_ShapeHandle shape = (DT_ShapeHandle) vshape;
- m_physCtrl = ctrl;
- if (m_physCtrl)
- {
- m_physCtrl->SetMargin(m_Margin);
- m_physCtrl->SetNewClientInfo(m_client_info);
- }
- SynchronizeTransform();
-}
-
-void KX_NearSensor::SynchronizeTransform()
-{
- // The near and radar sensors are using a different physical object which is
- // not linked to the parent object, must synchronize it.
- if (m_physCtrl)
- {
- PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
- KX_GameObject* parent = ((KX_GameObject*)GetParent());
- const MT_Point3& pos = parent->NodeGetWorldPosition();
- float ori[12];
- parent->NodeGetWorldOrientation().getValue(ori);
- motionState->SetWorldPosition(pos[0], pos[1], pos[2]);
- motionState->SetWorldOrientation(ori);
- m_physCtrl->WriteMotionStateToDynamics(true);
- }
-}
-
-CValue* KX_NearSensor::GetReplica()
-{
- KX_NearSensor* replica = new KX_NearSensor(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_NearSensor::ProcessReplica()
-{
- KX_TouchSensor::ProcessReplica();
-
- m_client_info = new KX_ClientObjectInfo(m_client_info->m_gameobject, KX_ClientObjectInfo::SENSOR);
-
- if (m_physCtrl)
- {
- m_physCtrl = m_physCtrl->GetReplicaForSensors();
- if (m_physCtrl)
- {
- //static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->addSensor(replica->m_physCtrl);
- m_physCtrl->SetMargin(m_Margin);
- m_physCtrl->SetNewClientInfo(m_client_info);
- }
-
- }
-}
-
-void KX_NearSensor::ReParent(SCA_IObject* parent)
-{
- SCA_ISensor::ReParent(parent);
- m_client_info->m_gameobject = static_cast<KX_GameObject*>(parent);
- m_client_info->m_sensors.push_back(this);
- //Synchronize here with the actual parent.
- SynchronizeTransform();
-}
-
-
-
-KX_NearSensor::~KX_NearSensor()
-{
- // for nearsensor, the sensor is the 'owner' of sumoobj
- // for touchsensor, it's the parent
- if (m_physCtrl)
- {
- //static_cast<KX_TouchEventManager*>(m_eventmgr)->GetPhysicsEnvironment()->removeSensor(m_physCtrl);
- delete m_physCtrl;
- m_physCtrl = NULL;
- }
-
-
- if (m_client_info)
- delete m_client_info;
-}
-
-void KX_NearSensor::SetPhysCtrlRadius()
-{
- if (m_bTriggered)
- {
- if (m_physCtrl)
- {
- m_physCtrl->SetRadius(m_ResetMargin);
- }
- } else
- {
- if (m_physCtrl)
- {
- m_physCtrl->SetRadius(m_Margin);
- }
- }
-}
-
-bool KX_NearSensor::Evaluate()
-{
- bool result = false;
-// KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
-
- if (m_bTriggered != m_bLastTriggered)
- {
- m_bLastTriggered = m_bTriggered;
-
- SetPhysCtrlRadius();
-
- result = true;
- }
-
- return result;
-}
-
-// this function is called at broad phase stage to check if the two controller
-// need to interact at all. It is used for Near/Radar sensor that don't need to
-// check collision with object not included in filter
-bool KX_NearSensor::BroadPhaseFilterCollision(void*obj1,void*obj2)
-{
- KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
-
- // need the mapping from PHY_IPhysicsController to gameobjects now
- assert(obj1==m_physCtrl && obj2);
- KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*>((static_cast<PHY_IPhysicsController*>(obj2))->GetNewClientInfo());
-
- KX_GameObject* gameobj = ( client_info ?
- client_info->m_gameobject :
- NULL);
-
- if (gameobj && (gameobj != parent))
- {
- // only take valid colliders
- if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
- {
- if ((m_touchedpropname.Length() == 0) ||
- (gameobj->GetProperty(m_touchedpropname)))
- {
- return true;
- }
- }
- }
-
- return false;
-}
-
-bool KX_NearSensor::NewHandleCollision(void *obj1, void *obj2, const PHY_CollData *coll_data)
-{
-// KX_TouchEventManager* toucheventmgr = static_cast<KX_TouchEventManager*>(m_eventmgr);
-// KX_GameObject* parent = static_cast<KX_GameObject*>(GetParent());
-
- // need the mapping from PHY_IPhysicsController to gameobjects now
-
- KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*> (obj1 == m_physCtrl?
- ((PHY_IPhysicsController*)obj2)->GetNewClientInfo() :
- ((PHY_IPhysicsController*)obj1)->GetNewClientInfo());
-
- KX_GameObject* gameobj = ( client_info ?
- client_info->m_gameobject :
- NULL);
-
- // Add the same check as in SCA_ISensor::Activate(),
- // we don't want to record collision when the sensor is not active.
- if (m_links && !m_suspended &&
- gameobj /* done in BroadPhaseFilterCollision() && (gameobj != parent)*/)
- {
- if (!m_colliders->SearchValue(gameobj))
- m_colliders->Add(gameobj->AddRef());
- // only take valid colliders
- // These checks are done already in BroadPhaseFilterCollision()
- //if (client_info->m_type == KX_ClientObjectInfo::ACTOR)
- //{
- // if ((m_touchedpropname.Length() == 0) ||
- // (gameobj->GetProperty(m_touchedpropname)))
- // {
- m_bTriggered = true;
- m_hitObject = gameobj;
- // }
- //}
- }
-
- return false; // was DT_CONTINUE; but this was defined in Sumo as false
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python Functions */
-/* ------------------------------------------------------------------------- */
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject KX_NearSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_NearSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_TouchSensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_NearSensor::Methods[] = {
- //No methods
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_NearSensor::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("distance", 0, 10000, KX_NearSensor, m_Margin, CheckResetDistance),
- KX_PYATTRIBUTE_FLOAT_RW_CHECK("resetDistance", 0, 10000, KX_NearSensor, m_ResetMargin, CheckResetDistance),
- {NULL} //Sentinel
-};
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_NearSensor.h b/source/gameengine/Ketsji/KX_NearSensor.h
deleted file mode 100644
index ef6e15f602f..00000000000
--- a/source/gameengine/Ketsji/KX_NearSensor.h
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_NearSensor.h
- * \ingroup ketsji
- * \brief Sense if other objects are near
- */
-
-#ifndef __KX_NEARSENSOR_H__
-#define __KX_NEARSENSOR_H__
-
-#include "KX_TouchSensor.h"
-#include "KX_ClientObjectInfo.h"
-
-class KX_Scene;
-struct PHY_CollData;
-
-class KX_NearSensor : public KX_TouchSensor
-{
- Py_Header
-protected:
- float m_Margin;
- float m_ResetMargin;
-
- KX_ClientObjectInfo* m_client_info;
-public:
- KX_NearSensor(class SCA_EventManager* eventmgr,
- class KX_GameObject* gameobj,
- float margin,
- float resetmargin,
- bool bFindMaterial,
- const STR_String& touchedpropname,
- PHY_IPhysicsController* ctrl);
-#if 0
-public:
- KX_NearSensor(class SCA_EventManager* eventmgr,
- class KX_GameObject* gameobj,
- double margin,
- double resetmargin,
- bool bFindMaterial,
- const STR_String& touchedpropname,
- class KX_Scene* scene);
-#endif
- virtual ~KX_NearSensor();
- virtual void SynchronizeTransform();
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
- virtual void SetPhysCtrlRadius();
- virtual bool Evaluate();
-
- virtual void ReParent(SCA_IObject* parent);
- virtual bool NewHandleCollision(void* obj1,void* obj2,
- const PHY_CollData * coll_data);
- virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2);
- virtual bool BroadPhaseSensorFilterCollision(void* obj1,void* obj2) { return false; }
- virtual sensortype GetSensorType() { return ST_NEAR; }
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- //No methods
-
- //This method is used to make sure the distance does not exceed the reset distance
- static int CheckResetDistance(void *self, const PyAttributeDef*)
- {
- KX_NearSensor* sensor = reinterpret_cast<KX_NearSensor*>(self);
-
- if (sensor->m_Margin > sensor->m_ResetMargin)
- sensor->m_ResetMargin = sensor->m_Margin;
-
- sensor->SetPhysCtrlRadius();
-
- return 0;
- }
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __KX_NEARSENSOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_ObColorIpoSGController.cpp b/source/gameengine/Ketsji/KX_ObColorIpoSGController.cpp
deleted file mode 100644
index 7f81f221c07..00000000000
--- a/source/gameengine/Ketsji/KX_ObColorIpoSGController.cpp
+++ /dev/null
@@ -1,110 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ObColorIpoSGController.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_ObColorIpoSGController.h"
-#include "KX_ScalarInterpolator.h"
-#include "KX_GameObject.h"
-
-#if defined(_WIN64)
-typedef unsigned __int64 uint_ptr;
-#else
-typedef unsigned long uint_ptr;
-#endif
-
-
-bool KX_ObColorIpoSGController::Update(double currentTime)
-{
- if (m_modified)
- {
- SG_Spatial* ob = (SG_Spatial*)m_pObject;
- KX_GameObject* kxgameobj= (KX_GameObject*) ob->GetSGClientObject();
-
- m_rgba = kxgameobj->GetObjectColor();
-
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- (*i)->Execute(m_ipotime);
- }
-
-
- kxgameobj->SetObjectColor(m_rgba);
-
-
- m_modified=false;
- }
- return false;
-}
-
-
-void KX_ObColorIpoSGController::AddInterpolator(KX_IInterpolator* interp)
-{
- this->m_interpolators.push_back(interp);
-}
-
-SG_Controller* KX_ObColorIpoSGController::GetReplica(class SG_Node* destnode)
-{
- KX_ObColorIpoSGController* iporeplica = new KX_ObColorIpoSGController(*this);
- // clear object that ipo acts on
- iporeplica->ClearObject();
-
- // dirty hack, ask Gino for a better solution in the ipo implementation
- // hacken en zagen, in what we call datahiding, not written for replication :(
-
- T_InterpolatorList oldlist = m_interpolators;
- iporeplica->m_interpolators.clear();
-
- T_InterpolatorList::iterator i;
- for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
- KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
- iporeplica->AddInterpolator(copyipo);
-
- MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
- uint_ptr orgbase = (uint_ptr)this;
- uint_ptr orgloc = (uint_ptr)scaal;
- uint_ptr offset = orgloc-orgbase;
- uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
- MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
- copyipo->SetNewTarget((MT_Scalar*)blaptr);
- }
-
- return iporeplica;
-}
-
-KX_ObColorIpoSGController::~KX_ObColorIpoSGController()
-{
-
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- delete (*i);
- }
-
-}
diff --git a/source/gameengine/Ketsji/KX_ObColorIpoSGController.h b/source/gameengine/Ketsji/KX_ObColorIpoSGController.h
deleted file mode 100644
index a7b0b2c4ffc..00000000000
--- a/source/gameengine/Ketsji/KX_ObColorIpoSGController.h
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ObColorIpoSGController.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_OBCOLORIPOSGCONTROLLER_H__
-#define __KX_OBCOLORIPOSGCONTROLLER_H__
-
-#include "SG_Controller.h"
-#include "SG_Spatial.h"
-#include "KX_IInterpolator.h"
-
-class KX_ObColorIpoSGController : public SG_Controller
-{
-public:
- MT_Vector4 m_rgba;
-
-
-private:
- T_InterpolatorList m_interpolators;
- bool m_modified;
-
- double m_ipotime;
-public:
- KX_ObColorIpoSGController() :
- m_modified(true),
- m_ipotime(0.0)
- {}
- virtual ~KX_ObColorIpoSGController();
- virtual SG_Controller* GetReplica(class SG_Node* destnode);
- virtual bool Update(double time);
- virtual void SetSimulatedTime(double time) {
- m_ipotime = time;
- m_modified = true;
- }
-
- void
- SetOption(
- int option,
- int value
- ) {
- // intentionally empty
- };
-
-
- void AddInterpolator(KX_IInterpolator* interp);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_ObColorIpoSGController")
-#endif
-};
-
-#endif /* __KX_OBCOLORIPOSGCONTROLLER_H__ */
diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.cpp b/source/gameengine/Ketsji/KX_ObjectActuator.cpp
deleted file mode 100644
index 8c1dee7940f..00000000000
--- a/source/gameengine/Ketsji/KX_ObjectActuator.cpp
+++ /dev/null
@@ -1,709 +0,0 @@
-/*
- * Do translation/rotation actions
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ObjectActuator.cpp
- * \ingroup ketsji
- */
-
-#include <stdio.h>
-
-#include "KX_ObjectActuator.h"
-#include "KX_GameObject.h"
-#include "KX_PyMath.h" // For PyVecTo - should this include be put in PyObjectPlus?
-#include "PHY_IPhysicsController.h"
-#include "PHY_ICharacter.h"
-#include "PHY_IPhysicsEnvironment.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_ObjectActuator::
-KX_ObjectActuator(
- SCA_IObject* gameobj,
- KX_GameObject* refobj,
- const MT_Vector3& force,
- const MT_Vector3& torque,
- const MT_Vector3& dloc,
- const MT_Vector3& drot,
- const MT_Vector3& linV,
- const MT_Vector3& angV,
- const short damping,
- const KX_LocalFlags& flag
-) :
- SCA_IActuator(gameobj, KX_ACT_OBJECT),
- m_force(force),
- m_torque(torque),
- m_dloc(dloc),
- m_drot(drot),
- m_linear_velocity(linV),
- m_angular_velocity(angV),
- m_linear_length2(0.0f),
- m_current_linear_factor(0.0f),
- m_current_angular_factor(0.0f),
- m_damping(damping),
- m_previous_error(0.0f,0.0f,0.0f),
- m_error_accumulator(0.0f,0.0f,0.0f),
- m_bitLocalFlag (flag),
- m_reference(refobj),
- m_active_combined_velocity (false),
- m_linear_damping_active(false),
- m_angular_damping_active(false),
- m_jumping(false)
-{
- if (m_bitLocalFlag.ServoControl)
- {
- // in servo motion, the force is local if the target velocity is local
- m_bitLocalFlag.Force = m_bitLocalFlag.LinearVelocity;
-
- m_pid = m_torque;
- }
- if (m_bitLocalFlag.CharacterMotion)
- {
- KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent());
- PHY_ICharacter *character = parent->GetScene()->GetPhysicsEnvironment()->GetCharacterController(parent);
-
- if (!character)
- {
- printf("Character motion enabled on non-character object (%s), falling back to simple motion.\n", parent->GetName().Ptr());
- m_bitLocalFlag.CharacterMotion = false;
- }
- }
- if (m_reference)
- m_reference->RegisterActuator(this);
- UpdateFuzzyFlags();
-}
-
-KX_ObjectActuator::~KX_ObjectActuator()
-{
- if (m_reference)
- m_reference->UnregisterActuator(this);
-}
-
-bool KX_ObjectActuator::Update()
-{
-
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- KX_GameObject *parent = static_cast<KX_GameObject *>(GetParent());
- PHY_ICharacter *character = parent->GetScene()->GetPhysicsEnvironment()->GetCharacterController(parent);
-
- if (bNegativeEvent) {
- // If we previously set the linear velocity we now have to inform
- // the physics controller that we no longer wish to apply it and that
- // it should reconcile the externally set velocity with it's
- // own velocity.
- if (m_active_combined_velocity) {
- if (parent)
- parent->ResolveCombinedVelocities(
- m_linear_velocity,
- m_angular_velocity,
- (m_bitLocalFlag.LinearVelocity) != 0,
- (m_bitLocalFlag.AngularVelocity) != 0
- );
- m_active_combined_velocity = false;
- }
-
- // Explicitly stop the movement if we're using character motion
- if (m_bitLocalFlag.CharacterMotion) {
- character->SetWalkDirection(MT_Vector3 (0.0f, 0.0f, 0.0f));
- }
-
- m_linear_damping_active = false;
- m_angular_damping_active = false;
- m_error_accumulator.setValue(0.0f,0.0f,0.0f);
- m_previous_error.setValue(0.0f,0.0f,0.0f);
- m_jumping = false;
- return false;
-
- } else if (parent)
- {
- if (m_bitLocalFlag.ServoControl)
- {
- // In this mode, we try to reach a target speed using force
- // As we don't know the friction, we must implement a generic
- // servo control to achieve the speed in a configurable
- // v = current velocity
- // V = target velocity
- // e = V-v = speed error
- // dt = time interval since previous update
- // I = sum(e(t)*dt)
- // dv = e(t) - e(t-1)
- // KP, KD, KI : coefficient
- // F = KP*e+KI*I+KD*dv
- MT_Scalar mass = parent->GetMass();
- if (mass < MT_EPSILON)
- return false;
- MT_Vector3 v = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
- if (m_reference)
- {
- const MT_Point3& mypos = parent->NodeGetWorldPosition();
- const MT_Point3& refpos = m_reference->NodeGetWorldPosition();
- MT_Point3 relpos;
- relpos = (mypos-refpos);
- MT_Vector3 vel= m_reference->GetVelocity(relpos);
- if (m_bitLocalFlag.LinearVelocity)
- // must convert in local space
- vel = parent->NodeGetWorldOrientation().transposed()*vel;
- v -= vel;
- }
- MT_Vector3 e = m_linear_velocity - v;
- MT_Vector3 dv = e - m_previous_error;
- MT_Vector3 I = m_error_accumulator + e;
-
- m_force = m_pid.x()*e+m_pid.y()*I+m_pid.z()*dv;
- // to automatically adapt the PID coefficient to mass;
- m_force *= mass;
- if (m_bitLocalFlag.Torque)
- {
- if (m_force[0] > m_dloc[0])
- {
- m_force[0] = m_dloc[0];
- I[0] = m_error_accumulator[0];
- } else if (m_force[0] < m_drot[0])
- {
- m_force[0] = m_drot[0];
- I[0] = m_error_accumulator[0];
- }
- }
- if (m_bitLocalFlag.DLoc)
- {
- if (m_force[1] > m_dloc[1])
- {
- m_force[1] = m_dloc[1];
- I[1] = m_error_accumulator[1];
- } else if (m_force[1] < m_drot[1])
- {
- m_force[1] = m_drot[1];
- I[1] = m_error_accumulator[1];
- }
- }
- if (m_bitLocalFlag.DRot)
- {
- if (m_force[2] > m_dloc[2])
- {
- m_force[2] = m_dloc[2];
- I[2] = m_error_accumulator[2];
- } else if (m_force[2] < m_drot[2])
- {
- m_force[2] = m_drot[2];
- I[2] = m_error_accumulator[2];
- }
- }
- m_previous_error = e;
- m_error_accumulator = I;
- parent->ApplyForce(m_force,(m_bitLocalFlag.LinearVelocity) != 0);
- }
- else if (m_bitLocalFlag.CharacterMotion) {
- MT_Vector3 dir = m_dloc;
-
- if (m_bitLocalFlag.DLoc) {
- MT_Matrix3x3 basis = parent->GetPhysicsController()->GetOrientation();
- dir = basis * dir;
- }
-
- if (m_bitLocalFlag.AddOrSetCharLoc) {
- MT_Vector3 old_dir = character->GetWalkDirection();
-
- if (!old_dir.fuzzyZero()) {
- MT_Scalar mag = old_dir.length();
-
- dir = dir + old_dir;
- if (!dir.fuzzyZero())
- dir = dir.normalized() * mag;
- }
- }
-
- // We always want to set the walk direction since a walk direction of (0, 0, 0) should stop the character
- character->SetWalkDirection(dir/parent->GetScene()->GetPhysicsEnvironment()->GetNumTimeSubSteps());
-
- if (!m_bitLocalFlag.ZeroDRot)
- {
- parent->ApplyRotation(m_drot,(m_bitLocalFlag.DRot) != 0);
- }
-
- if (m_bitLocalFlag.CharacterJump) {
- if (!m_jumping) {
- character->Jump();
- m_jumping = true;
- }
- else if (character->OnGround())
- m_jumping = false;
- }
- }
- else {
- if (!m_bitLocalFlag.ZeroForce)
- {
- parent->ApplyForce(m_force,(m_bitLocalFlag.Force) != 0);
- }
- if (!m_bitLocalFlag.ZeroTorque)
- {
- parent->ApplyTorque(m_torque,(m_bitLocalFlag.Torque) != 0);
- }
- if (!m_bitLocalFlag.ZeroDLoc)
- {
- parent->ApplyMovement(m_dloc,(m_bitLocalFlag.DLoc) != 0);
- }
- if (!m_bitLocalFlag.ZeroDRot)
- {
- parent->ApplyRotation(m_drot,(m_bitLocalFlag.DRot) != 0);
- }
- if (!m_bitLocalFlag.ZeroLinearVelocity)
- {
- if (m_bitLocalFlag.AddOrSetLinV) {
- parent->addLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
- } else {
- m_active_combined_velocity = true;
- if (m_damping > 0) {
- MT_Vector3 linV;
- if (!m_linear_damping_active) {
- // delta and the start speed (depends on the existing speed in that direction)
- linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
- // keep only the projection along the desired direction
- m_current_linear_factor = linV.dot(m_linear_velocity)/m_linear_length2;
- m_linear_damping_active = true;
- }
- if (m_current_linear_factor < 1.0f)
- m_current_linear_factor += 1.0f/m_damping;
- if (m_current_linear_factor > 1.0f)
- m_current_linear_factor = 1.0f;
- linV = m_current_linear_factor * m_linear_velocity;
- parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0);
- } else {
- parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
- }
- }
- }
- if (!m_bitLocalFlag.ZeroAngularVelocity)
- {
- m_active_combined_velocity = true;
- if (m_damping > 0) {
- MT_Vector3 angV;
- if (!m_angular_damping_active) {
- // delta and the start speed (depends on the existing speed in that direction)
- angV = parent->GetAngularVelocity(m_bitLocalFlag.AngularVelocity);
- // keep only the projection along the desired direction
- m_current_angular_factor = angV.dot(m_angular_velocity)/m_angular_length2;
- m_angular_damping_active = true;
- }
- if (m_current_angular_factor < 1.0f)
- m_current_angular_factor += 1.0f/m_damping;
- if (m_current_angular_factor > 1.0f)
- m_current_angular_factor = 1.0f;
- angV = m_current_angular_factor * m_angular_velocity;
- parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0);
- } else {
- parent->setAngularVelocity(m_angular_velocity,(m_bitLocalFlag.AngularVelocity) != 0);
- }
- }
- }
-
- }
- return true;
-}
-
-
-
-CValue* KX_ObjectActuator::GetReplica()
-{
- KX_ObjectActuator* replica = new KX_ObjectActuator(*this);//m_float,GetName());
- replica->ProcessReplica();
-
- return replica;
-}
-
-void KX_ObjectActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
- if (m_reference)
- m_reference->RegisterActuator(this);
-}
-
-bool KX_ObjectActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == (SCA_IObject*)m_reference)
- {
- // this object is being deleted, we cannot continue to use it as reference.
- m_reference = NULL;
- return true;
- }
- return false;
-}
-
-void KX_ObjectActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_reference];
- if (h_obj) {
- if (m_reference)
- m_reference->UnregisterActuator(this);
- m_reference = (KX_GameObject*)(*h_obj);
- m_reference->RegisterActuator(this);
- }
-}
-
-/* some 'standard' utilities... */
-bool KX_ObjectActuator::isValid(KX_ObjectActuator::KX_OBJECT_ACT_VEC_TYPE type)
-{
- bool res = false;
- res = (type > KX_OBJECT_ACT_NODEF) && (type < KX_OBJECT_ACT_MAX);
- return res;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_ObjectActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_ObjectActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_ObjectActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_ObjectActuator::Attributes[] = {
- KX_PYATTRIBUTE_VECTOR_RW_CHECK("force", -1000, 1000, false, KX_ObjectActuator, m_force, PyUpdateFuzzyFlags),
- KX_PYATTRIBUTE_BOOL_RW("useLocalForce", KX_ObjectActuator, m_bitLocalFlag.Force),
- KX_PYATTRIBUTE_VECTOR_RW_CHECK("torque", -1000, 1000, false, KX_ObjectActuator, m_torque, PyUpdateFuzzyFlags),
- KX_PYATTRIBUTE_BOOL_RW("useLocalTorque", KX_ObjectActuator, m_bitLocalFlag.Torque),
- KX_PYATTRIBUTE_VECTOR_RW_CHECK("dLoc", -1000, 1000, false, KX_ObjectActuator, m_dloc, PyUpdateFuzzyFlags),
- KX_PYATTRIBUTE_BOOL_RW("useLocalDLoc", KX_ObjectActuator, m_bitLocalFlag.DLoc),
- KX_PYATTRIBUTE_VECTOR_RW_CHECK("dRot", -1000, 1000, false, KX_ObjectActuator, m_drot, PyUpdateFuzzyFlags),
- KX_PYATTRIBUTE_BOOL_RW("useLocalDRot", KX_ObjectActuator, m_bitLocalFlag.DRot),
-#ifdef USE_MATHUTILS
- KX_PYATTRIBUTE_RW_FUNCTION("linV", KX_ObjectActuator, pyattr_get_linV, pyattr_set_linV),
- KX_PYATTRIBUTE_RW_FUNCTION("angV", KX_ObjectActuator, pyattr_get_angV, pyattr_set_angV),
-#else
- KX_PYATTRIBUTE_VECTOR_RW_CHECK("linV", -1000, 1000, false, KX_ObjectActuator, m_linear_velocity, PyUpdateFuzzyFlags),
- KX_PYATTRIBUTE_VECTOR_RW_CHECK("angV", -1000, 1000, false, KX_ObjectActuator, m_angular_velocity, PyUpdateFuzzyFlags),
-#endif
- KX_PYATTRIBUTE_BOOL_RW("useLocalLinV", KX_ObjectActuator, m_bitLocalFlag.LinearVelocity),
- KX_PYATTRIBUTE_BOOL_RW("useLocalAngV", KX_ObjectActuator, m_bitLocalFlag.AngularVelocity),
- KX_PYATTRIBUTE_SHORT_RW("damping", 0, 1000, false, KX_ObjectActuator, m_damping),
- KX_PYATTRIBUTE_RW_FUNCTION("forceLimitX", KX_ObjectActuator, pyattr_get_forceLimitX, pyattr_set_forceLimitX),
- KX_PYATTRIBUTE_RW_FUNCTION("forceLimitY", KX_ObjectActuator, pyattr_get_forceLimitY, pyattr_set_forceLimitY),
- KX_PYATTRIBUTE_RW_FUNCTION("forceLimitZ", KX_ObjectActuator, pyattr_get_forceLimitZ, pyattr_set_forceLimitZ),
- KX_PYATTRIBUTE_VECTOR_RW_CHECK("pid", -100, 200, true, KX_ObjectActuator, m_pid, PyCheckPid),
- KX_PYATTRIBUTE_RW_FUNCTION("reference", KX_ObjectActuator,pyattr_get_reference,pyattr_set_reference),
- { NULL } //Sentinel
-};
-
-/* Attribute get/set functions */
-
-#ifdef USE_MATHUTILS
-
-/* These require an SGNode */
-#define MATHUTILS_VEC_CB_LINV 1
-#define MATHUTILS_VEC_CB_ANGV 2
-
-static unsigned char mathutils_kxobactu_vector_cb_index = -1; /* index for our callbacks */
-
-static int mathutils_obactu_generic_check(BaseMathObject *bmo)
-{
- KX_ObjectActuator* self = static_cast<KX_ObjectActuator*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- return 0;
-}
-
-static int mathutils_obactu_vector_get(BaseMathObject *bmo, int subtype)
-{
- KX_ObjectActuator* self = static_cast<KX_ObjectActuator*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_VEC_CB_LINV:
- self->m_linear_velocity.getValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_ANGV:
- self->m_angular_velocity.getValue(bmo->data);
- break;
- }
-
- return 0;
-}
-
-static int mathutils_obactu_vector_set(BaseMathObject *bmo, int subtype)
-{
- KX_ObjectActuator* self = static_cast<KX_ObjectActuator*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_VEC_CB_LINV:
- self->m_linear_velocity.setValue(bmo->data);
- break;
- case MATHUTILS_VEC_CB_ANGV:
- self->m_angular_velocity.setValue(bmo->data);
- break;
- }
-
- return 0;
-}
-
-static int mathutils_obactu_vector_get_index(BaseMathObject *bmo, int subtype, int index)
-{
- /* lazy, avoid repeteing the case statement */
- if (mathutils_obactu_vector_get(bmo, subtype) == -1)
- return -1;
- return 0;
-}
-
-static int mathutils_obactu_vector_set_index(BaseMathObject *bmo, int subtype, int index)
-{
- float f = bmo->data[index];
-
- /* lazy, avoid repeteing the case statement */
- if (mathutils_obactu_vector_get(bmo, subtype) == -1)
- return -1;
-
- bmo->data[index] = f;
- return mathutils_obactu_vector_set(bmo, subtype);
-}
-
-static Mathutils_Callback mathutils_obactu_vector_cb = {
- mathutils_obactu_generic_check,
- mathutils_obactu_vector_get,
- mathutils_obactu_vector_set,
- mathutils_obactu_vector_get_index,
- mathutils_obactu_vector_set_index
-};
-
-PyObject *KX_ObjectActuator::pyattr_get_linV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxobactu_vector_cb_index, MATHUTILS_VEC_CB_LINV);
-}
-
-int KX_ObjectActuator::pyattr_set_linV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_ObjectActuator* self = static_cast<KX_ObjectActuator*>(self_v);
- if (!PyVecTo(value, self->m_linear_velocity))
- return PY_SET_ATTR_FAIL;
-
- self->UpdateFuzzyFlags();
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_ObjectActuator::pyattr_get_angV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- return Vector_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v), 3,
- mathutils_kxobactu_vector_cb_index, MATHUTILS_VEC_CB_ANGV);
-}
-
-int KX_ObjectActuator::pyattr_set_angV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_ObjectActuator* self = static_cast<KX_ObjectActuator*>(self_v);
- if (!PyVecTo(value, self->m_angular_velocity))
- return PY_SET_ATTR_FAIL;
-
- self->UpdateFuzzyFlags();
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-
-void KX_ObjectActuator_Mathutils_Callback_Init(void)
-{
- // register mathutils callbacks, ok to run more than once.
- mathutils_kxobactu_vector_cb_index = Mathutils_RegisterCallback(&mathutils_obactu_vector_cb);
-}
-
-#endif // USE_MATHUTILS
-
-PyObject *KX_ObjectActuator::pyattr_get_forceLimitX(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ObjectActuator* self = reinterpret_cast<KX_ObjectActuator*>(self_v);
- PyObject *retVal = PyList_New(3);
-
- PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(self->m_drot[0]));
- PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(self->m_dloc[0]));
- PyList_SET_ITEM(retVal, 2, PyBool_FromLong(self->m_bitLocalFlag.Torque));
-
- return retVal;
-}
-
-int KX_ObjectActuator::pyattr_set_forceLimitX(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_ObjectActuator* self = reinterpret_cast<KX_ObjectActuator*>(self_v);
-
- PyObject *seq = PySequence_Fast(value, "");
- if (seq && PySequence_Fast_GET_SIZE(seq) == 3)
- {
- self->m_drot[0] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0));
- self->m_dloc[0] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1));
- self->m_bitLocalFlag.Torque = (PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 2)) != 0);
-
- if (!PyErr_Occurred())
- {
- Py_DECREF(seq);
- return PY_SET_ATTR_SUCCESS;
- }
- }
-
- Py_XDECREF(seq);
-
- PyErr_SetString(PyExc_ValueError, "expected a sequence of 2 floats and a bool");
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_ObjectActuator::pyattr_get_forceLimitY(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ObjectActuator* self = reinterpret_cast<KX_ObjectActuator*>(self_v);
- PyObject *retVal = PyList_New(3);
-
- PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(self->m_drot[1]));
- PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(self->m_dloc[1]));
- PyList_SET_ITEM(retVal, 2, PyBool_FromLong(self->m_bitLocalFlag.DLoc));
-
- return retVal;
-}
-
-int KX_ObjectActuator::pyattr_set_forceLimitY(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_ObjectActuator* self = reinterpret_cast<KX_ObjectActuator*>(self_v);
-
- PyObject *seq = PySequence_Fast(value, "");
- if (seq && PySequence_Fast_GET_SIZE(seq) == 3)
- {
- self->m_drot[1] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0));
- self->m_dloc[1] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1));
- self->m_bitLocalFlag.DLoc = (PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 2)) != 0);
-
- if (!PyErr_Occurred())
- {
- Py_DECREF(seq);
- return PY_SET_ATTR_SUCCESS;
- }
- }
-
- Py_XDECREF(seq);
-
- PyErr_SetString(PyExc_ValueError, "expected a sequence of 2 floats and a bool");
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_ObjectActuator::pyattr_get_forceLimitZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ObjectActuator* self = reinterpret_cast<KX_ObjectActuator*>(self_v);
- PyObject *retVal = PyList_New(3);
-
- PyList_SET_ITEM(retVal, 0, PyFloat_FromDouble(self->m_drot[2]));
- PyList_SET_ITEM(retVal, 1, PyFloat_FromDouble(self->m_dloc[2]));
- PyList_SET_ITEM(retVal, 2, PyBool_FromLong(self->m_bitLocalFlag.DRot));
-
- return retVal;
-}
-
-int KX_ObjectActuator::pyattr_set_forceLimitZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_ObjectActuator* self = reinterpret_cast<KX_ObjectActuator*>(self_v);
-
- PyObject *seq = PySequence_Fast(value, "");
- if (seq && PySequence_Fast_GET_SIZE(seq) == 3)
- {
- self->m_drot[2] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0));
- self->m_dloc[2] = PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1));
- self->m_bitLocalFlag.DRot = (PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 2)) != 0);
-
- if (!PyErr_Occurred())
- {
- Py_DECREF(seq);
- return PY_SET_ATTR_SUCCESS;
- }
- }
-
- Py_XDECREF(seq);
-
- PyErr_SetString(PyExc_ValueError, "expected a sequence of 2 floats and a bool");
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_ObjectActuator::pyattr_get_reference(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ObjectActuator* actuator = static_cast<KX_ObjectActuator*>(self);
- if (!actuator->m_reference)
- Py_RETURN_NONE;
-
- return actuator->m_reference->GetProxy();
-}
-
-int KX_ObjectActuator::pyattr_set_reference(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_ObjectActuator* actuator = static_cast<KX_ObjectActuator*>(self);
- KX_GameObject *refOb;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &refOb, true, "actu.reference = value: KX_ObjectActuator"))
- return PY_SET_ATTR_FAIL;
-
- if (actuator->m_reference)
- actuator->m_reference->UnregisterActuator(actuator);
-
- if (refOb==NULL) {
- actuator->m_reference= NULL;
- }
- else {
- actuator->m_reference = refOb;
- actuator->m_reference->RegisterActuator(actuator);
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_ObjectActuator.h b/source/gameengine/Ketsji/KX_ObjectActuator.h
deleted file mode 100644
index 919c6acf03b..00000000000
--- a/source/gameengine/Ketsji/KX_ObjectActuator.h
+++ /dev/null
@@ -1,234 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ObjectActuator.h
- * \ingroup ketsji
- * \brief Do translation/rotation actions
- */
-
-#ifndef __KX_OBJECTACTUATOR_H__
-#define __KX_OBJECTACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "MT_Vector3.h"
-
-#ifdef USE_MATHUTILS
-void KX_ObjectActuator_Mathutils_Callback_Init(void);
-#endif
-
-class KX_GameObject;
-
-//
-// Stores the flags for each CValue derived class
-//
-struct KX_LocalFlags {
- KX_LocalFlags() :
- Force(false),
- Torque(false),
- DRot(false),
- DLoc(false),
- LinearVelocity(false),
- AngularVelocity(false),
- AddOrSetLinV(false),
- AddOrSetCharLoc(false),
- ServoControl(false),
- CharacterMotion(false),
- CharacterJump(false),
- ZeroForce(false),
- ZeroTorque(false),
- ZeroDRot(false),
- ZeroDLoc(false),
- ZeroLinearVelocity(false),
- ZeroAngularVelocity(false)
- {
- }
-
- bool Force;
- bool Torque;
- bool DRot;
- bool DLoc;
- bool LinearVelocity;
- bool AngularVelocity;
- bool AddOrSetLinV;
- bool AddOrSetCharLoc;
- bool ServoControl;
- bool CharacterMotion;
- bool CharacterJump;
- bool ZeroForce;
- bool ZeroTorque;
- bool ZeroDRot;
- bool ZeroDLoc;
- bool ZeroLinearVelocity;
- bool ZeroAngularVelocity;
-};
-
-class KX_ObjectActuator : public SCA_IActuator
-{
- Py_Header
-
- MT_Vector3 m_force;
- MT_Vector3 m_torque;
- MT_Vector3 m_dloc;
- MT_Vector3 m_drot;
- MT_Vector3 m_linear_velocity;
- MT_Vector3 m_angular_velocity;
- MT_Vector3 m_pid;
- MT_Scalar m_linear_length2;
- MT_Scalar m_angular_length2;
- // used in damping
- MT_Scalar m_current_linear_factor;
- MT_Scalar m_current_angular_factor;
- short m_damping;
- // used in servo control
- MT_Vector3 m_previous_error;
- MT_Vector3 m_error_accumulator;
- KX_LocalFlags m_bitLocalFlag;
- KX_GameObject* m_reference;
- // A hack bool -- oh no sorry everyone
- // This bool is used to check if we have informed
- // the physics object that we are no longer
- // setting linear velocity.
-
- bool m_active_combined_velocity;
- bool m_linear_damping_active;
- bool m_angular_damping_active;
- bool m_jumping;
-
-public:
- enum KX_OBJECT_ACT_VEC_TYPE {
- KX_OBJECT_ACT_NODEF = 0,
- KX_OBJECT_ACT_FORCE,
- KX_OBJECT_ACT_TORQUE,
- KX_OBJECT_ACT_DLOC,
- KX_OBJECT_ACT_DROT,
- KX_OBJECT_ACT_LINEAR_VELOCITY,
- KX_OBJECT_ACT_ANGULAR_VELOCITY,
- KX_OBJECT_ACT_MAX
- };
-
- /**
- * Check whether this is a valid vector mode
- */
- bool isValid(KX_OBJECT_ACT_VEC_TYPE type);
-
- KX_ObjectActuator(
- SCA_IObject* gameobj,
- KX_GameObject* refobj,
- const MT_Vector3& force,
- const MT_Vector3& torque,
- const MT_Vector3& dloc,
- const MT_Vector3& drot,
- const MT_Vector3& linV,
- const MT_Vector3& angV,
- const short damping,
- const KX_LocalFlags& flag
- );
- ~KX_ObjectActuator();
- CValue* GetReplica();
- void ProcessReplica();
- bool UnlinkObject(SCA_IObject* clientobj);
- void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
-
- void SetForceLoc(const double force[3]) { /*m_force=force;*/ }
- void UpdateFuzzyFlags()
- {
- m_bitLocalFlag.ZeroForce = MT_fuzzyZero(m_force);
- m_bitLocalFlag.ZeroTorque = MT_fuzzyZero(m_torque);
- m_bitLocalFlag.ZeroDLoc = MT_fuzzyZero(m_dloc);
- m_bitLocalFlag.ZeroDRot = MT_fuzzyZero(m_drot);
- m_bitLocalFlag.ZeroLinearVelocity = MT_fuzzyZero(m_linear_velocity);
- m_linear_length2 = (m_bitLocalFlag.ZeroLinearVelocity) ? 0.0f : m_linear_velocity.length2();
- m_bitLocalFlag.ZeroAngularVelocity = MT_fuzzyZero(m_angular_velocity);
- m_angular_length2 = (m_bitLocalFlag.ZeroAngularVelocity) ? 0.0f : m_angular_velocity.length2();
- }
- virtual bool Update();
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /* Attributes */
- static PyObject* pyattr_get_forceLimitX(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_forceLimitX(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_forceLimitY(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_forceLimitY(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_forceLimitZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_forceLimitZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_reference(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_reference(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
-#ifdef USE_MATHUTILS
- static PyObject* pyattr_get_linV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_linV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_angV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_angV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-#endif
-
- // This lets the attribute macros use UpdateFuzzyFlags()
- static int PyUpdateFuzzyFlags(void *self, const PyAttributeDef *attrdef)
- {
- KX_ObjectActuator* act = reinterpret_cast<KX_ObjectActuator*>(self);
- act->UpdateFuzzyFlags();
- return 0;
- }
-
- // This is the keep the PID values in check after they are assigned with Python
- static int PyCheckPid(void *self, const PyAttributeDef *attrdef)
- {
- KX_ObjectActuator* act = reinterpret_cast<KX_ObjectActuator*>(self);
-
- //P 0 to 200
- if (act->m_pid[0] < 0) {
- act->m_pid[0] = 0;
- } else if (act->m_pid[0] > 200) {
- act->m_pid[0] = 200;
- }
-
- //I 0 to 3
- if (act->m_pid[1] < 0) {
- act->m_pid[1] = 0;
- } else if (act->m_pid[1] > 3) {
- act->m_pid[1] = 3;
- }
-
- //D -100 to 100
- if (act->m_pid[2] < -100) {
- act->m_pid[2] = -100;
- } else if (act->m_pid[2] > 100) {
- act->m_pid[2] = 100;
- }
-
- return 0;
- }
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __KX_OBJECTACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp b/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
deleted file mode 100644
index c84b2474c90..00000000000
--- a/source/gameengine/Ketsji/KX_ObstacleSimulation.cpp
+++ /dev/null
@@ -1,832 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ObstacleSimulation.cpp
- * \ingroup ketsji
- *
- * Simulation for obstacle avoidance behavior
- */
-
-#include "KX_ObstacleSimulation.h"
-#include "KX_NavMeshObject.h"
-#include "KX_PythonInit.h"
-#include "DNA_object_types.h"
-#include "BLI_math.h"
-
-namespace
-{
- inline float perp(const MT_Vector2& a, const MT_Vector2& b) { return a.x()*b.y() - a.y()*b.x(); }
-
- inline float sqr(float x) { return x * x; }
- inline float lerp(float a, float b, float t) { return a + (b - a) * t; }
- inline float clamp(float a, float mn, float mx) { return a < mn ? mn : (a > mx ? mx : a); }
- inline void vset(float v[2], float x, float y) { v[0] = x; v[1] = y; }
-}
-
-/* grr, seems moto provides no nice way to do this */
-#define MT_3D_AS_2D(v) MT_Vector2((v)[0], (v)[1])
-
-static int sweepCircleCircle(
- const MT_Vector2 &pos0, const MT_Scalar r0, const MT_Vector2 &v,
- const MT_Vector2 &pos1, const MT_Scalar r1,
- float& tmin, float& tmax)
-{
- static const float EPS = 0.0001f;
- MT_Vector2 c0(pos0.x(), pos0.y());
- MT_Vector2 c1(pos1.x(), pos1.y());
- MT_Vector2 s = c1 - c0;
- MT_Scalar r = r0+r1;
- float c = s.length2() - r*r;
- float a = v.length2();
- if (a < EPS) return 0; // not moving
-
- // Overlap, calc time to exit.
- float b = MT_dot(v,s);
- float d = b*b - a*c;
- if (d < 0.0f) return 0; // no intersection.
- tmin = (b - sqrtf(d)) / a;
- tmax = (b + sqrtf(d)) / a;
- return 1;
-}
-
-static int sweepCircleSegment(
- const MT_Vector2 &pos0, const MT_Scalar r0, const MT_Vector2 &v,
- const MT_Vector2& pa, const MT_Vector2 &pb, const MT_Scalar sr,
- float& tmin, float &tmax)
-{
- // equation parameters
- MT_Vector2 c0(pos0.x(), pos0.y());
- MT_Vector2 sa(pa.x(), pa.y());
- MT_Vector2 sb(pb.x(), pb.y());
- MT_Vector2 L = sb-sa;
- MT_Vector2 H = c0-sa;
- MT_Scalar radius = r0+sr;
- float l2 = L.length2();
- float r2 = radius * radius;
- float dl = perp(v, L);
- float hl = perp(H, L);
- float a = dl * dl;
- float b = 2.0f * hl * dl;
- float c = hl * hl - (r2 * l2);
- float d = (b*b) - (4.0f * a * c);
-
- // infinite line missed by infinite ray.
- if (d < 0.0f)
- return 0;
-
- d = sqrtf(d);
- tmin = (-b - d) / (2.0f * a);
- tmax = (-b + d) / (2.0f * a);
-
- // line missed by ray range.
- /* if (tmax < 0.0f || tmin > 1.0f)
- return 0;*/
-
- // find what part of the ray was collided.
- MT_Vector2 Pedge;
- Pedge = c0+v*tmin;
- H = Pedge - sa;
- float e0 = MT_dot(H, L) / l2;
- Pedge = c0 + v*tmax;
- H = Pedge - sa;
- float e1 = MT_dot(H, L) / l2;
-
- if (e0 < 0.0f || e1 < 0.0f)
- {
- float ctmin, ctmax;
- if (sweepCircleCircle(pos0, r0, v, pa, sr, ctmin, ctmax))
- {
- if (e0 < 0.0f && ctmin > tmin)
- tmin = ctmin;
- if (e1 < 0.0f && ctmax < tmax)
- tmax = ctmax;
- }
- else
- {
- return 0;
- }
- }
-
- if (e0 > 1.0f || e1 > 1.0f)
- {
- float ctmin, ctmax;
- if (sweepCircleCircle(pos0, r0, v, pb, sr, ctmin, ctmax))
- {
- if (e0 > 1.0f && ctmin > tmin)
- tmin = ctmin;
- if (e1 > 1.0f && ctmax < tmax)
- tmax = ctmax;
- }
- else
- {
- return 0;
- }
- }
-
- return 1;
-}
-
-static bool inBetweenAngle(float a, float amin, float amax, float& t)
-{
- if (amax < amin) amax += (float)M_PI*2;
- if (a < amin-(float)M_PI) a += (float)M_PI*2;
- if (a > amin+(float)M_PI) a -= (float)M_PI*2;
- if (a >= amin && a < amax)
- {
- t = (a-amin) / (amax-amin);
- return true;
- }
- return false;
-}
-
-static float interpolateToi(float a, const float* dir, const float* toi, const int ntoi)
-{
- for (int i = 0; i < ntoi; ++i)
- {
- int next = (i+1) % ntoi;
- float t;
- if (inBetweenAngle(a, dir[i], dir[next], t))
- {
- return lerp(toi[i], toi[next], t);
- }
- }
- return 0;
-}
-
-KX_ObstacleSimulation::KX_ObstacleSimulation(MT_Scalar levelHeight, bool enableVisualization)
-: m_levelHeight(levelHeight)
-, m_enableVisualization(enableVisualization)
-{
-
-}
-
-KX_ObstacleSimulation::~KX_ObstacleSimulation()
-{
- for (size_t i=0; i<m_obstacles.size(); i++)
- {
- KX_Obstacle* obs = m_obstacles[i];
- delete obs;
- }
- m_obstacles.clear();
-}
-KX_Obstacle* KX_ObstacleSimulation::CreateObstacle(KX_GameObject* gameobj)
-{
- KX_Obstacle* obstacle = new KX_Obstacle();
- obstacle->m_gameObj = gameobj;
-
- vset(obstacle->vel, 0,0);
- vset(obstacle->pvel, 0,0);
- vset(obstacle->dvel, 0,0);
- vset(obstacle->nvel, 0,0);
- for (int i = 0; i < VEL_HIST_SIZE; ++i)
- vset(&obstacle->hvel[i*2], 0,0);
- obstacle->hhead = 0;
-
- gameobj->RegisterObstacle(this);
- m_obstacles.push_back(obstacle);
- return obstacle;
-}
-
-void KX_ObstacleSimulation::AddObstacleForObj(KX_GameObject* gameobj)
-{
- KX_Obstacle* obstacle = CreateObstacle(gameobj);
- struct Object* blenderobject = gameobj->GetBlenderObject();
- obstacle->m_type = KX_OBSTACLE_OBJ;
- obstacle->m_shape = KX_OBSTACLE_CIRCLE;
- obstacle->m_rad = blenderobject->obstacleRad;
-}
-
-void KX_ObstacleSimulation::AddObstaclesForNavMesh(KX_NavMeshObject* navmeshobj)
-{
- dtStatNavMesh* navmesh = navmeshobj->GetNavMesh();
- if (navmesh)
- {
- int npoly = navmesh->getPolyCount();
- for (int pi=0; pi<npoly; pi++)
- {
- const dtStatPoly* poly = navmesh->getPoly(pi);
-
- for (int i = 0, j = (int)poly->nv-1; i < (int)poly->nv; j = i++)
- {
- if (poly->n[j]) continue;
- const float* vj = navmesh->getVertex(poly->v[j]);
- const float* vi = navmesh->getVertex(poly->v[i]);
-
- KX_Obstacle* obstacle = CreateObstacle(navmeshobj);
- obstacle->m_type = KX_OBSTACLE_NAV_MESH;
- obstacle->m_shape = KX_OBSTACLE_SEGMENT;
- obstacle->m_pos = MT_Point3(vj[0], vj[2], vj[1]);
- obstacle->m_pos2 = MT_Point3(vi[0], vi[2], vi[1]);
- obstacle->m_rad = 0;
- }
- }
- }
-}
-
-void KX_ObstacleSimulation::DestroyObstacleForObj(KX_GameObject* gameobj)
-{
- for (size_t i=0; i<m_obstacles.size(); )
- {
- if (m_obstacles[i]->m_gameObj == gameobj)
- {
- KX_Obstacle* obstacle = m_obstacles[i];
- obstacle->m_gameObj->UnregisterObstacle();
- m_obstacles[i] = m_obstacles.back();
- m_obstacles.pop_back();
- delete obstacle;
- }
- else
- i++;
- }
-}
-
-void KX_ObstacleSimulation::UpdateObstacles()
-{
- for (size_t i=0; i<m_obstacles.size(); i++)
- {
- if (m_obstacles[i]->m_type==KX_OBSTACLE_NAV_MESH || m_obstacles[i]->m_shape==KX_OBSTACLE_SEGMENT)
- continue;
-
- KX_Obstacle* obs = m_obstacles[i];
- obs->m_pos = obs->m_gameObj->NodeGetWorldPosition();
- obs->vel[0] = obs->m_gameObj->GetLinearVelocity().x();
- obs->vel[1] = obs->m_gameObj->GetLinearVelocity().y();
-
- // Update velocity history and calculate perceived (average) velocity.
- copy_v2_v2(&obs->hvel[obs->hhead * 2], obs->vel);
- obs->hhead = (obs->hhead+1) % VEL_HIST_SIZE;
- vset(obs->pvel,0,0);
- for (int j = 0; j < VEL_HIST_SIZE; ++j)
- add_v2_v2v2(obs->pvel, obs->pvel, &obs->hvel[j * 2]);
- mul_v2_fl(obs->pvel, 1.0f / VEL_HIST_SIZE);
- }
-}
-
-KX_Obstacle* KX_ObstacleSimulation::GetObstacle(KX_GameObject* gameobj)
-{
- for (size_t i=0; i<m_obstacles.size(); i++)
- {
- if (m_obstacles[i]->m_gameObj == gameobj)
- return m_obstacles[i];
- }
-
- return NULL;
-}
-
-void KX_ObstacleSimulation::AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle)
-{
-}
-
-void KX_ObstacleSimulation::DrawObstacles()
-{
- if (!m_enableVisualization)
- return;
- static const MT_Vector3 bluecolor(0,0,1);
- static const MT_Vector3 normal(0.0f, 0.0f, 1.0f);
- static const int SECTORS_NUM = 32;
- for (size_t i=0; i<m_obstacles.size(); i++)
- {
- if (m_obstacles[i]->m_shape==KX_OBSTACLE_SEGMENT)
- {
- MT_Point3 p1 = m_obstacles[i]->m_pos;
- MT_Point3 p2 = m_obstacles[i]->m_pos2;
- //apply world transform
- if (m_obstacles[i]->m_type == KX_OBSTACLE_NAV_MESH)
- {
- KX_NavMeshObject* navmeshobj = static_cast<KX_NavMeshObject*>(m_obstacles[i]->m_gameObj);
- p1 = navmeshobj->TransformToWorldCoords(p1);
- p2 = navmeshobj->TransformToWorldCoords(p2);
- }
-
- KX_RasterizerDrawDebugLine(p1, p2, bluecolor);
- }
- else if (m_obstacles[i]->m_shape==KX_OBSTACLE_CIRCLE)
- {
- KX_RasterizerDrawDebugCircle(m_obstacles[i]->m_pos, m_obstacles[i]->m_rad, bluecolor,
- normal, SECTORS_NUM);
- }
- }
-}
-
-static MT_Point3 nearestPointToObstacle(MT_Point3& pos ,KX_Obstacle* obstacle)
-{
- switch (obstacle->m_shape)
- {
- case KX_OBSTACLE_SEGMENT :
- {
- MT_Vector3 ab = obstacle->m_pos2 - obstacle->m_pos;
- if (!ab.fuzzyZero())
- {
- const MT_Scalar dist = ab.length();
- MT_Vector3 abdir = ab.normalized();
- MT_Vector3 v = pos - obstacle->m_pos;
- MT_Scalar proj = abdir.dot(v);
- CLAMP(proj, 0, dist);
- MT_Point3 res = obstacle->m_pos + abdir*proj;
- return res;
- }
- ATTR_FALLTHROUGH;
- }
- case KX_OBSTACLE_CIRCLE :
- default:
- return obstacle->m_pos;
- }
-}
-
-static bool filterObstacle(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj, KX_Obstacle* otherObst,
- float levelHeight)
-{
- //filter obstacles by type
- if ( (otherObst == activeObst) ||
- (otherObst->m_type==KX_OBSTACLE_NAV_MESH && otherObst->m_gameObj!=activeNavMeshObj) )
- return false;
-
- //filter obstacles by position
- MT_Point3 p = nearestPointToObstacle(activeObst->m_pos, otherObst);
- if ( fabsf(activeObst->m_pos.z() - p.z()) > levelHeight)
- return false;
-
- return true;
-}
-
-///////////*********TOI_rays**********/////////////////
-KX_ObstacleSimulationTOI::KX_ObstacleSimulationTOI(MT_Scalar levelHeight, bool enableVisualization)
-: KX_ObstacleSimulation(levelHeight, enableVisualization),
- m_maxSamples(32),
- m_minToi(0.0f),
- m_maxToi(0.0f),
- m_velWeight(1.0f),
- m_curVelWeight(1.0f),
- m_toiWeight(1.0f),
- m_collisionWeight(1.0f)
-{
-}
-
-
-void KX_ObstacleSimulationTOI::AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- MT_Vector3& velocity, MT_Scalar maxDeltaSpeed, MT_Scalar maxDeltaAngle)
-{
- int nobs = m_obstacles.size();
- int obstidx = std::find(m_obstacles.begin(), m_obstacles.end(), activeObst) - m_obstacles.begin();
- if (obstidx == nobs)
- return;
-
- vset(activeObst->dvel, velocity.x(), velocity.y());
-
- //apply RVO
- sampleRVO(activeObst, activeNavMeshObj, maxDeltaAngle);
-
- // Fake dynamic constraint.
- float dv[2];
- float vel[2];
- sub_v2_v2v2(dv, activeObst->nvel, activeObst->vel);
- float ds = len_v2(dv);
- if (ds > maxDeltaSpeed || ds<-maxDeltaSpeed)
- mul_v2_fl(dv, fabs(maxDeltaSpeed / ds));
- add_v2_v2v2(vel, activeObst->vel, dv);
-
- velocity.x() = vel[0];
- velocity.y() = vel[1];
-}
-
-///////////*********TOI_rays**********/////////////////
-static const int AVOID_MAX_STEPS = 128;
-struct TOICircle
-{
- TOICircle() : n(0), minToi(0), maxToi(1) {}
- float toi[AVOID_MAX_STEPS]; // Time of impact (seconds)
- float toie[AVOID_MAX_STEPS]; // Time of exit (seconds)
- float dir[AVOID_MAX_STEPS]; // Direction (radians)
- int n; // Number of samples
- float minToi, maxToi; // Min/max TOI (seconds)
-};
-
-KX_ObstacleSimulationTOI_rays::KX_ObstacleSimulationTOI_rays(MT_Scalar levelHeight, bool enableVisualization):
- KX_ObstacleSimulationTOI(levelHeight, enableVisualization)
-{
- m_maxSamples = 32;
- m_minToi = 0.5f;
- m_maxToi = 1.2f;
- m_velWeight = 4.0f;
- m_toiWeight = 1.0f;
- m_collisionWeight = 100.0f;
-}
-
-
-void KX_ObstacleSimulationTOI_rays::sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- const float maxDeltaAngle)
-{
- MT_Vector2 vel(activeObst->dvel[0], activeObst->dvel[1]);
- float vmax = (float) vel.length();
- float odir = (float) atan2(vel.y(), vel.x());
-
- MT_Vector2 ddir = vel;
- ddir.normalize();
-
- float bestScore = FLT_MAX;
- float bestDir = odir;
- float bestToi = 0;
-
- TOICircle tc;
- tc.n = m_maxSamples;
- tc.minToi = m_minToi;
- tc.maxToi = m_maxToi;
-
- const int iforw = m_maxSamples/2;
- const float aoff = (float)iforw / (float)m_maxSamples;
-
- size_t nobs = m_obstacles.size();
- for (int iter = 0; iter < m_maxSamples; ++iter)
- {
- // Calculate sample velocity
- const float ndir = ((float)iter/(float)m_maxSamples) - aoff;
- const float dir = odir+ndir*(float)M_PI*2.0f;
- MT_Vector2 svel;
- svel.x() = cosf(dir) * vmax;
- svel.y() = sinf(dir) * vmax;
-
- // Find min time of impact and exit amongst all obstacles.
- float tmin = m_maxToi;
- float tmine = 0.0f;
- for (int i = 0; i < nobs; ++i)
- {
- KX_Obstacle* ob = m_obstacles[i];
- bool res = filterObstacle(activeObst, activeNavMeshObj, ob, m_levelHeight);
- if (!res)
- continue;
-
- float htmin,htmax;
-
- if (ob->m_shape == KX_OBSTACLE_CIRCLE)
- {
- MT_Vector2 vab;
- if (len_v2(ob->vel) < 0.01f * 0.01f) {
- // Stationary, use VO
- vab = svel;
- }
- else
- {
- // Moving, use RVO
- vab = 2*svel - vel - ob->vel;
- }
-
- if (!sweepCircleCircle(MT_3D_AS_2D(activeObst->m_pos), activeObst->m_rad,
- vab, MT_3D_AS_2D(ob->m_pos), ob->m_rad, htmin, htmax))
- {
- continue;
- }
- }
- else if (ob->m_shape == KX_OBSTACLE_SEGMENT)
- {
- MT_Point3 p1 = ob->m_pos;
- MT_Point3 p2 = ob->m_pos2;
- //apply world transform
- if (ob->m_type == KX_OBSTACLE_NAV_MESH)
- {
- KX_NavMeshObject* navmeshobj = static_cast<KX_NavMeshObject*>(ob->m_gameObj);
- p1 = navmeshobj->TransformToWorldCoords(p1);
- p2 = navmeshobj->TransformToWorldCoords(p2);
- }
-
- if (!sweepCircleSegment(MT_3D_AS_2D(activeObst->m_pos), activeObst->m_rad, svel,
- MT_3D_AS_2D(p1), MT_3D_AS_2D(p2), ob->m_rad, htmin, htmax))
- {
- continue;
- }
- }
- else {
- continue;
- }
-
- if (htmin > 0.0f)
- {
- // The closest obstacle is somewhere ahead of us, keep track of nearest obstacle.
- if (htmin < tmin)
- tmin = htmin;
- }
- else if (htmax > 0.0f)
- {
- // The agent overlaps the obstacle, keep track of first safe exit.
- if (htmax > tmine)
- tmine = htmax;
- }
- }
-
- // Calculate sample penalties and final score.
- const float apen = m_velWeight * fabsf(ndir);
- const float tpen = m_toiWeight * (1.0f/(0.0001f+tmin/m_maxToi));
- const float cpen = m_collisionWeight * (tmine/m_minToi)*(tmine/m_minToi);
- const float score = apen + tpen + cpen;
-
- // Update best score.
- if (score < bestScore)
- {
- bestDir = dir;
- bestToi = tmin;
- bestScore = score;
- }
-
- tc.dir[iter] = dir;
- tc.toi[iter] = tmin;
- tc.toie[iter] = tmine;
- }
-
- if (len_v2(activeObst->vel) > 0.1f) {
- // Constrain max turn rate.
- float cura = atan2(activeObst->vel[1],activeObst->vel[0]);
- float da = bestDir - cura;
- if (da < -M_PI) da += (float)M_PI*2;
- if (da > M_PI) da -= (float)M_PI*2;
- if (da < -maxDeltaAngle)
- {
- bestDir = cura - maxDeltaAngle;
- bestToi = min(bestToi, interpolateToi(bestDir, tc.dir, tc.toi, tc.n));
- }
- else if (da > maxDeltaAngle)
- {
- bestDir = cura + maxDeltaAngle;
- bestToi = min(bestToi, interpolateToi(bestDir, tc.dir, tc.toi, tc.n));
- }
- }
-
- // Adjust speed when time of impact is less than min TOI.
- if (bestToi < m_minToi)
- vmax *= bestToi/m_minToi;
-
- // New steering velocity.
- activeObst->nvel[0] = cosf(bestDir) * vmax;
- activeObst->nvel[1] = sinf(bestDir) * vmax;
-}
-
-///////////********* TOI_cells**********/////////////////
-
-static void processSamples(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- KX_Obstacles& obstacles, float levelHeight, const float vmax,
- const float* spos, const float cs, const int nspos, float* res,
- float maxToi, float velWeight, float curVelWeight, float sideWeight,
- float toiWeight)
-{
- vset(res, 0,0);
-
- const float ivmax = 1.0f / vmax;
-
- float adir[2] /*, adist */;
- if (normalize_v2_v2(adir, activeObst->pvel) <= 0.01f) {
- zero_v2(adir);
- }
-
- float activeObstPos[2];
- vset(activeObstPos, activeObst->m_pos.x(), activeObst->m_pos.y());
- /* adist = vdot(adir, activeObstPos); */
-
- float minPenalty = FLT_MAX;
-
- for (int n = 0; n < nspos; ++n)
- {
- float vcand[2];
- copy_v2_v2(vcand, &spos[n * 2]);
-
- // Find min time of impact and exit amongst all obstacles.
- float tmin = maxToi;
- float side = 0;
- int nside = 0;
-
- for (int i = 0; i < obstacles.size(); ++i)
- {
- KX_Obstacle* ob = obstacles[i];
- bool res = filterObstacle(activeObst, activeNavMeshObj, ob, levelHeight);
- if (!res)
- continue;
- float htmin, htmax;
-
- if (ob->m_shape==KX_OBSTACLE_CIRCLE)
- {
- float vab[2];
-
- // Moving, use RVO
- mul_v2_v2fl(vab, vcand, 2);
- sub_v2_v2v2(vab, vab, activeObst->vel);
- sub_v2_v2v2(vab, vab, ob->vel);
-
- // Side
- // NOTE: dp, and dv are constant over the whole calculation,
- // they can be precomputed per object.
- const float* pa = activeObstPos;
- float pb[2];
- vset(pb, ob->m_pos.x(), ob->m_pos.y());
-
- const float orig[2] = {0, 0};
- float dp[2], dv[2], np[2];
- sub_v2_v2v2(dp, pb, pa);
- normalize_v2(dp);
- sub_v2_v2v2(dv, ob->dvel, activeObst->dvel);
-
- /* TODO: use line_point_side_v2 */
- if (area_tri_signed_v2(orig, dp, dv) < 0.01f) {
- np[0] = -dp[1];
- np[1] = dp[0];
- }
- else {
- np[0] = dp[1];
- np[1] = -dp[0];
- }
-
- side += clamp(min(dot_v2v2(dp, vab),
- dot_v2v2(np, vab)) * 2.0f, 0.0f, 1.0f);
- nside++;
-
- if (!sweepCircleCircle(MT_3D_AS_2D(activeObst->m_pos), activeObst->m_rad,
- vab, MT_3D_AS_2D(ob->m_pos), ob->m_rad, htmin, htmax))
- {
- continue;
- }
-
- // Handle overlapping obstacles.
- if (htmin < 0.0f && htmax > 0.0f)
- {
- // Avoid more when overlapped.
- htmin = -htmin * 0.5f;
- }
- }
- else if (ob->m_shape == KX_OBSTACLE_SEGMENT)
- {
- MT_Point3 p1 = ob->m_pos;
- MT_Point3 p2 = ob->m_pos2;
- //apply world transform
- if (ob->m_type == KX_OBSTACLE_NAV_MESH)
- {
- KX_NavMeshObject* navmeshobj = static_cast<KX_NavMeshObject*>(ob->m_gameObj);
- p1 = navmeshobj->TransformToWorldCoords(p1);
- p2 = navmeshobj->TransformToWorldCoords(p2);
- }
- float p[2], q[2];
- vset(p, p1.x(), p1.y());
- vset(q, p2.x(), p2.y());
-
- // NOTE: the segments are assumed to come from a navmesh which is shrunken by
- // the agent radius, hence the use of really small radius.
- // This can be handle more efficiently by using seg-seg test instead.
- // If the whole segment is to be treated as obstacle, use agent->rad instead of 0.01f!
- const float r = 0.01f; // agent->rad
- if (dist_squared_to_line_segment_v2(activeObstPos, p, q) < sqr(r + ob->m_rad)) {
- float sdir[2], snorm[2];
- sub_v2_v2v2(sdir, q, p);
- snorm[0] = sdir[1];
- snorm[1] = -sdir[0];
- // If the velocity is pointing towards the segment, no collision.
- if (dot_v2v2(snorm, vcand) < 0.0f)
- continue;
- // Else immediate collision.
- htmin = 0.0f;
- htmax = 10.0f;
- }
- else
- {
- if (!sweepCircleSegment(activeObstPos, r, vcand, p, q, ob->m_rad, htmin, htmax))
- continue;
- }
-
- // Avoid less when facing walls.
- htmin *= 2.0f;
- }
- else {
- continue;
- }
-
- if (htmin >= 0.0f)
- {
- // The closest obstacle is somewhere ahead of us, keep track of nearest obstacle.
- if (htmin < tmin)
- tmin = htmin;
- }
- }
-
- // Normalize side bias, to prevent it dominating too much.
- if (nside)
- side /= nside;
-
- const float vpen = velWeight * (len_v2v2(vcand, activeObst->dvel) * ivmax);
- const float vcpen = curVelWeight * (len_v2v2(vcand, activeObst->vel) * ivmax);
- const float spen = sideWeight * side;
- const float tpen = toiWeight * (1.0f/(0.1f+tmin/maxToi));
-
- const float penalty = vpen + vcpen + spen + tpen;
-
- if (penalty < minPenalty) {
- minPenalty = penalty;
- copy_v2_v2(res, vcand);
- }
- }
-}
-
-void KX_ObstacleSimulationTOI_cells::sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- const float maxDeltaAngle)
-{
- vset(activeObst->nvel, 0.f, 0.f);
- float vmax = len_v2(activeObst->dvel);
-
- float* spos = new float[2*m_maxSamples];
- int nspos = 0;
-
- if (!m_adaptive)
- {
- const float cvx = activeObst->dvel[0]*m_bias;
- const float cvy = activeObst->dvel[1]*m_bias;
- float vmax = len_v2(activeObst->dvel);
- const float vrange = vmax*(1-m_bias);
- const float cs = 1.0f / (float)m_sampleRadius*vrange;
-
- for (int y = -m_sampleRadius; y <= m_sampleRadius; ++y)
- {
- for (int x = -m_sampleRadius; x <= m_sampleRadius; ++x)
- {
- if (nspos < m_maxSamples)
- {
- const float vx = cvx + (float)(x+0.5f)*cs;
- const float vy = cvy + (float)(y+0.5f)*cs;
- if (vx*vx+vy*vy > sqr(vmax+cs/2)) continue;
- spos[nspos*2+0] = vx;
- spos[nspos*2+1] = vy;
- nspos++;
- }
- }
- }
- processSamples(activeObst, activeNavMeshObj, m_obstacles, m_levelHeight, vmax, spos, cs/2,
- nspos, activeObst->nvel, m_maxToi, m_velWeight, m_curVelWeight, m_collisionWeight, m_toiWeight);
- }
- else
- {
- int rad;
- float res[2];
- float cs;
- // First sample location.
- rad = 4;
- res[0] = activeObst->dvel[0]*m_bias;
- res[1] = activeObst->dvel[1]*m_bias;
- cs = vmax*(2-m_bias*2) / (float)(rad-1);
-
- for (int k = 0; k < 5; ++k)
- {
- const float half = (rad-1)*cs*0.5f;
-
- nspos = 0;
- for (int y = 0; y < rad; ++y)
- {
- for (int x = 0; x < rad; ++x)
- {
- const float v_xy[2] = {
- res[0] + x * cs - half,
- res[1] + y * cs - half};
-
- if (len_squared_v2(v_xy) > sqr(vmax + cs / 2))
- continue;
-
- copy_v2_v2(&spos[nspos * 2 + 0], v_xy);
- nspos++;
- }
- }
-
- processSamples(activeObst, activeNavMeshObj, m_obstacles, m_levelHeight, vmax, spos, cs/2,
- nspos, res, m_maxToi, m_velWeight, m_curVelWeight, m_collisionWeight, m_toiWeight);
-
- cs *= 0.5f;
- }
- copy_v2_v2(activeObst->nvel, res);
- }
-
- delete [] spos;
-}
-
-KX_ObstacleSimulationTOI_cells::KX_ObstacleSimulationTOI_cells(MT_Scalar levelHeight, bool enableVisualization)
-: KX_ObstacleSimulationTOI(levelHeight, enableVisualization)
-, m_bias(0.4f)
-, m_adaptive(true)
-, m_sampleRadius(15)
-{
- m_maxSamples = (m_sampleRadius*2+1)*(m_sampleRadius*2+1) + 100;
- m_maxToi = 1.5f;
- m_velWeight = 2.0f;
- m_curVelWeight = 0.75f;
- m_toiWeight = 2.5f;
- m_collisionWeight = 0.75f; //side_weight
-}
diff --git a/source/gameengine/Ketsji/KX_ObstacleSimulation.h b/source/gameengine/Ketsji/KX_ObstacleSimulation.h
deleted file mode 100644
index 50589b5bc69..00000000000
--- a/source/gameengine/Ketsji/KX_ObstacleSimulation.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Simulation for obstacle avoidance behavior
- * (based on Cane Project - http://code.google.com/p/cane by Mikko Mononen (c) 2009)
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __KX_OBSTACLESIMULATION_H__
-#define __KX_OBSTACLESIMULATION_H__
-
-#include <vector>
-#include "MT_Point2.h"
-#include "MT_Point3.h"
-
-class KX_GameObject;
-class KX_NavMeshObject;
-
-enum KX_OBSTACLE_TYPE
-{
- KX_OBSTACLE_OBJ,
- KX_OBSTACLE_NAV_MESH,
-};
-
-enum KX_OBSTACLE_SHAPE
-{
- KX_OBSTACLE_CIRCLE,
- KX_OBSTACLE_SEGMENT,
-};
-
-#define VEL_HIST_SIZE 6
-struct KX_Obstacle
-{
- KX_OBSTACLE_TYPE m_type;
- KX_OBSTACLE_SHAPE m_shape;
- MT_Point3 m_pos;
- MT_Point3 m_pos2;
- MT_Scalar m_rad;
-
- float vel[2];
- float pvel[2];
- float dvel[2];
- float nvel[2];
- float hvel[VEL_HIST_SIZE*2];
- int hhead;
-
-
- KX_GameObject* m_gameObj;
-};
-typedef std::vector<KX_Obstacle*> KX_Obstacles;
-
-class KX_ObstacleSimulation
-{
-protected:
- KX_Obstacles m_obstacles;
-
- MT_Scalar m_levelHeight;
- bool m_enableVisualization;
-
- KX_Obstacle* CreateObstacle(KX_GameObject* gameobj);
-public:
- KX_ObstacleSimulation(MT_Scalar levelHeight, bool enableVisualization);
- virtual ~KX_ObstacleSimulation();
-
- void DrawObstacles();
- //void DebugDraw();
-
- void AddObstacleForObj(KX_GameObject* gameobj);
- void DestroyObstacleForObj(KX_GameObject* gameobj);
- void AddObstaclesForNavMesh(KX_NavMeshObject* navmesh);
- KX_Obstacle* GetObstacle(KX_GameObject* gameobj);
- void UpdateObstacles();
- virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle);
-
-};
-class KX_ObstacleSimulationTOI: public KX_ObstacleSimulation
-{
-protected:
- int m_maxSamples; // Number of sample steps
- float m_minToi; // Min TOI
- float m_maxToi; // Max TOI
- float m_velWeight; // Sample selection angle weight
- float m_curVelWeight; // Sample selection current velocity weight
- float m_toiWeight; // Sample selection TOI weight
- float m_collisionWeight; // Sample selection collision weight
-
- virtual void sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- const float maxDeltaAngle) = 0;
-public:
- KX_ObstacleSimulationTOI(MT_Scalar levelHeight, bool enableVisualization);
- virtual void AdjustObstacleVelocity(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- MT_Vector3& velocity, MT_Scalar maxDeltaSpeed,MT_Scalar maxDeltaAngle);
-};
-
-class KX_ObstacleSimulationTOI_rays: public KX_ObstacleSimulationTOI
-{
-protected:
- virtual void sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- const float maxDeltaAngle);
-public:
- KX_ObstacleSimulationTOI_rays(MT_Scalar levelHeight, bool enableVisualization);
-};
-
-class KX_ObstacleSimulationTOI_cells: public KX_ObstacleSimulationTOI
-{
-protected:
- float m_bias;
- bool m_adaptive;
- int m_sampleRadius;
- virtual void sampleRVO(KX_Obstacle* activeObst, KX_NavMeshObject* activeNavMeshObj,
- const float maxDeltaAngle);
-public:
- KX_ObstacleSimulationTOI_cells(MT_Scalar levelHeight, bool enableVisualization);
-};
-
-#endif
diff --git a/source/gameengine/Ketsji/KX_OrientationInterpolator.cpp b/source/gameengine/Ketsji/KX_OrientationInterpolator.cpp
deleted file mode 100644
index bcaa1e60e92..00000000000
--- a/source/gameengine/Ketsji/KX_OrientationInterpolator.cpp
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_OrientationInterpolator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_OrientationInterpolator.h"
-#include "MT_Matrix3x3.h"
-#include "KX_IScalarInterpolator.h"
-
-void KX_OrientationInterpolator::Execute(float currentTime) const
-{
- MT_Vector3 eul(m_ipos[0]->GetValue(currentTime),
- m_ipos[1]->GetValue(currentTime),
- m_ipos[2]->GetValue(currentTime));
- MT_Scalar ci = cosf(eul[0]);
- MT_Scalar cj = cosf(eul[1]);
- MT_Scalar ch = cosf(eul[2]);
- MT_Scalar si = sinf(eul[0]);
- MT_Scalar sj = sinf(eul[1]);
- MT_Scalar sh = sinf(eul[2]);
- MT_Scalar cc = ci*ch;
- MT_Scalar cs = ci*sh;
- MT_Scalar sc = si*ch;
- MT_Scalar ss = si*sh;
-
- m_target.setValue(cj*ch, sj*sc-cs, sj*cc+ss,
- cj*sh, sj*ss+cc, sj*cs-sc,
- -sj, cj*si, cj*ci);
-}
diff --git a/source/gameengine/Ketsji/KX_OrientationInterpolator.h b/source/gameengine/Ketsji/KX_OrientationInterpolator.h
deleted file mode 100644
index 59014b70174..00000000000
--- a/source/gameengine/Ketsji/KX_OrientationInterpolator.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_OrientationInterpolator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_ORIENTATIONINTERPOLATOR_H__
-#define __KX_ORIENTATIONINTERPOLATOR_H__
-
-#include "KX_IInterpolator.h"
-
-class MT_Matrix3x3;
-class KX_IScalarInterpolator;
-
-class KX_OrientationInterpolator : public KX_IInterpolator {
-public:
- KX_OrientationInterpolator(MT_Matrix3x3& target,
- KX_IScalarInterpolator **ipos)
- : m_target(target)
- {
- m_ipos[0] = ipos[0];
- m_ipos[1] = ipos[1];
- m_ipos[2] = ipos[2];
- }
-
- virtual void Execute(float currentTime) const;
-
-private:
- MT_Matrix3x3& m_target;
- KX_IScalarInterpolator *m_ipos[3];
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_OrientationInterpolator")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_ParentActuator.cpp b/source/gameengine/Ketsji/KX_ParentActuator.cpp
deleted file mode 100644
index 0b133400920..00000000000
--- a/source/gameengine/Ketsji/KX_ParentActuator.cpp
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * Set or remove an objects parent
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ParentActuator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_ParentActuator.h"
-#include "KX_GameObject.h"
-#include "KX_PythonInit.h"
-
-#include "EXP_PyObjectPlus.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_ParentActuator::KX_ParentActuator(SCA_IObject *gameobj,
- int mode,
- bool addToCompound,
- bool ghost,
- SCA_IObject *ob)
- : SCA_IActuator(gameobj, KX_ACT_PARENT),
- m_mode(mode),
- m_addToCompound(addToCompound),
- m_ghost(ghost),
- m_ob(ob)
-{
- if (m_ob)
- m_ob->RegisterActuator(this);
-}
-
-
-
-KX_ParentActuator::~KX_ParentActuator()
-{
- if (m_ob)
- m_ob->UnregisterActuator(this);
-}
-
-
-
-CValue* KX_ParentActuator::GetReplica()
-{
- KX_ParentActuator* replica = new KX_ParentActuator(*this);
- // replication just copy the m_base pointer => common random generator
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_ParentActuator::ProcessReplica()
-{
- if (m_ob)
- m_ob->RegisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-
-bool KX_ParentActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == m_ob)
- {
- // this object is being deleted, we cannot continue to track it.
- m_ob = NULL;
- return true;
- }
- return false;
-}
-
-void KX_ParentActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_ob];
- if (h_obj) {
- if (m_ob)
- m_ob->UnregisterActuator(this);
- m_ob = (SCA_IObject*)(*h_obj);
- m_ob->RegisterActuator(this);
- }
-}
-
-
-
-bool KX_ParentActuator::Update()
-{
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- KX_GameObject *obj = (KX_GameObject*) GetParent();
- KX_Scene *scene = KX_GetActiveScene();
- switch (m_mode) {
- case KX_PARENT_SET:
- if (m_ob)
- obj->SetParent(scene, (KX_GameObject*)m_ob, m_addToCompound, m_ghost);
- break;
- case KX_PARENT_REMOVE:
- obj->RemoveParent(scene);
- break;
- };
-
- return false;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_ParentActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_ParentActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_ParentActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_ParentActuator::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("object", KX_ParentActuator, pyattr_get_object, pyattr_set_object),
- KX_PYATTRIBUTE_INT_RW("mode", KX_PARENT_NODEF+1, KX_PARENT_MAX-1, true, KX_ParentActuator, m_mode),
- KX_PYATTRIBUTE_BOOL_RW("compound", KX_ParentActuator, m_addToCompound),
- KX_PYATTRIBUTE_BOOL_RW("ghost", KX_ParentActuator, m_ghost),
- { NULL } //Sentinel
-};
-
-PyObject *KX_ParentActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self);
- if (!actuator->m_ob)
- Py_RETURN_NONE;
- else
- return actuator->m_ob->GetProxy();
-}
-
-int KX_ParentActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_ParentActuator* actuator = static_cast<KX_ParentActuator*>(self);
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_ParentActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (actuator->m_ob != NULL)
- actuator->m_ob->UnregisterActuator(actuator);
-
- actuator->m_ob = (SCA_IObject*) gameobj;
-
- if (actuator->m_ob)
- actuator->m_ob->RegisterActuator(actuator);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_ParentActuator.h b/source/gameengine/Ketsji/KX_ParentActuator.h
deleted file mode 100644
index 40baac6b2b2..00000000000
--- a/source/gameengine/Ketsji/KX_ParentActuator.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ParentActuator.h
- * \ingroup ketsji
- * \brief Set or remove an objects parent
- */
-
-#ifndef __KX_PARENTACTUATOR_H__
-#define __KX_PARENTACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "SCA_LogicManager.h"
-
-class KX_ParentActuator : public SCA_IActuator
-{
- Py_Header
-
- /** Mode */
- int m_mode;
-
- /** option */
- bool m_addToCompound;
- bool m_ghost;
- /** Object to set as parent */
- SCA_IObject *m_ob;
-
-
-
-public:
- enum KX_PARENTACT_MODE
- {
- KX_PARENT_NODEF = 0,
- KX_PARENT_SET,
- KX_PARENT_REMOVE,
- KX_PARENT_MAX
-
- };
-
- KX_ParentActuator(class SCA_IObject* gameobj,
- int mode,
- bool addToCompound,
- bool ghost,
- SCA_IObject *ob);
- virtual ~KX_ParentActuator();
- virtual bool Update();
-
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual bool UnlinkObject(SCA_IObject* clientobj);
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /* These are used to get and set m_ob */
- static PyObject *pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
-#endif /* WITH_PYTHON */
-
-}; /* end of class KX_ParentActuator : public SCA_PropertyActuator */
-
-#endif /* __KX_PARENTACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h b/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h
deleted file mode 100644
index ca99c2e7526..00000000000
--- a/source/gameengine/Ketsji/KX_PhysicsEngineEnums.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PhysicsEngineEnums.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_PHYSICSENGINEENUMS_H__
-#define __KX_PHYSICSENGINEENUMS_H__
-
-enum e_PhysicsEngine
-{
- NoSelection = -1,
- UseNone = 0,
- UseBullet = 5,
-};
-
-#endif /* __KX_PHYSICSENGINEENUMS_H__ */
diff --git a/source/gameengine/Ketsji/KX_PolyProxy.cpp b/source/gameengine/Ketsji/KX_PolyProxy.cpp
deleted file mode 100644
index 4454543161b..00000000000
--- a/source/gameengine/Ketsji/KX_PolyProxy.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_PolyProxy.cpp
- * \ingroup ketsji
- */
-
-
-#ifdef WITH_PYTHON
-
-#include "KX_PolyProxy.h"
-#include "KX_MeshProxy.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-#include "KX_BlenderMaterial.h"
-
-#include "KX_PyMath.h"
-
-PyTypeObject KX_PolyProxy::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_PolyProxy",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_PolyProxy::Methods[] = {
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMaterialIndex),
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getNumVertex),
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,isVisible),
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,isCollider),
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMaterialName),
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getTextureName),
- KX_PYMETHODTABLE(KX_PolyProxy,getVertexIndex),
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMesh),
- KX_PYMETHODTABLE_NOARGS(KX_PolyProxy,getMaterial),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_PolyProxy::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("material_name", KX_PolyProxy, pyattr_get_material_name),
- KX_PYATTRIBUTE_RO_FUNCTION("texture_name", KX_PolyProxy, pyattr_get_texture_name),
- KX_PYATTRIBUTE_RO_FUNCTION("material", KX_PolyProxy, pyattr_get_material),
- KX_PYATTRIBUTE_RO_FUNCTION("material_id", KX_PolyProxy, pyattr_get_material_id),
- KX_PYATTRIBUTE_RO_FUNCTION("v1", KX_PolyProxy, pyattr_get_v1),
- KX_PYATTRIBUTE_RO_FUNCTION("v2", KX_PolyProxy, pyattr_get_v2),
- KX_PYATTRIBUTE_RO_FUNCTION("v3", KX_PolyProxy, pyattr_get_v3),
- KX_PYATTRIBUTE_RO_FUNCTION("v4", KX_PolyProxy, pyattr_get_v4),
- KX_PYATTRIBUTE_RO_FUNCTION("visible", KX_PolyProxy, pyattr_get_visible),
- KX_PYATTRIBUTE_RO_FUNCTION("collide", KX_PolyProxy, pyattr_get_collide),
- { NULL } //Sentinel
-};
-
-KX_PolyProxy::KX_PolyProxy(const RAS_MeshObject*mesh, RAS_Polygon* polygon)
-: m_polygon(polygon),
- m_mesh((RAS_MeshObject*)mesh)
-{
-}
-
-KX_PolyProxy::~KX_PolyProxy()
-{
-}
-
-
-// stuff for cvalue related things
-CValue* KX_PolyProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;}
-CValue* KX_PolyProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;}
-static STR_String sPolyName = "polygone";
-const STR_String & KX_PolyProxy::GetText() {return sPolyName;};
-double KX_PolyProxy::GetNumber() { return -1;}
-STR_String& KX_PolyProxy::GetName() { return sPolyName;}
-void KX_PolyProxy::SetName(const char *) { };
-CValue* KX_PolyProxy::GetReplica() { return NULL;}
-
-// stuff for python integration
-
-PyObject *KX_PolyProxy::pyattr_get_material_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
- return self->PygetMaterialName();
-}
-
-PyObject *KX_PolyProxy::pyattr_get_texture_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
- return self->PygetTextureName();
-}
-
-PyObject *KX_PolyProxy::pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
- return self->PygetMaterial();
-}
-
-PyObject *KX_PolyProxy::pyattr_get_material_id(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
- return self->PygetMaterialIndex();
-}
-
-PyObject *KX_PolyProxy::pyattr_get_v1(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
-
- return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(0));
-}
-
-PyObject *KX_PolyProxy::pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
-
- return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(1));
-}
-
-PyObject *KX_PolyProxy::pyattr_get_v3(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
-
- return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(2));
-}
-
-PyObject *KX_PolyProxy::pyattr_get_v4(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
-
- if (3 < self->m_polygon->VertexCount())
- {
- return PyLong_FromLong(self->m_polygon->GetVertexOffsetAbsolute(3));
- }
- return PyLong_FromLong(0);
-}
-
-PyObject *KX_PolyProxy::pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
- return self->PyisVisible();
-}
-
-PyObject *KX_PolyProxy::pyattr_get_collide(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_PolyProxy* self = static_cast<KX_PolyProxy*>(self_v);
- return self->PyisCollider();
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterialIndex,
-"getMaterialIndex() : return the material index of the polygon in the mesh\n")
-{
- RAS_MaterialBucket* polyBucket = m_polygon->GetMaterial();
- unsigned int matid;
- for (matid=0; matid<(unsigned int)m_mesh->NumMaterials(); matid++)
- {
- RAS_MeshMaterial* meshMat = m_mesh->GetMeshMaterial(matid);
- if (meshMat->m_bucket == polyBucket)
- // found it
- break;
- }
- return PyLong_FromLong(matid);
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getNumVertex,
-"getNumVertex() : returns the number of vertex of the polygon, 3 or 4\n")
-{
- return PyLong_FromLong(m_polygon->VertexCount());
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, isVisible,
-"isVisible() : returns whether the polygon is visible or not\n")
-{
- return PyLong_FromLong(m_polygon->IsVisible());
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, isCollider,
-"isCollider() : returns whether the polygon is receives collision or not\n")
-{
- return PyLong_FromLong(m_polygon->IsCollider());
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterialName,
-"getMaterialName() : returns the polygon material name, \"NoMaterial\" if no material\n")
-{
- return PyUnicode_From_STR_String(m_polygon->GetMaterial()->GetPolyMaterial()->GetMaterialName());
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getTextureName,
-"getTexturelName() : returns the polygon texture name, \"NULL\" if no texture\n")
-{
- return PyUnicode_From_STR_String(m_polygon->GetMaterial()->GetPolyMaterial()->GetTextureName());
-}
-
-KX_PYMETHODDEF_DOC(KX_PolyProxy, getVertexIndex,
-"getVertexIndex(vertex) : returns the mesh vertex index of a polygon vertex\n"
-"vertex: index of the vertex in the polygon: 0->3\n"
-"return value can be used to retrieve the vertex details through mesh proxy\n"
-"Note: getVertexIndex(3) on a triangle polygon returns 0\n")
-{
- int index;
- if (!PyArg_ParseTuple(args,"i:getVertexIndex",&index))
- {
- return NULL;
- }
- if (index < 0 || index > 3)
- {
- PyErr_SetString(PyExc_AttributeError, "poly.getVertexIndex(int): KX_PolyProxy, expected an index between 0-3");
- return NULL;
- }
- if (index < m_polygon->VertexCount())
- {
- return PyLong_FromLong(m_polygon->GetVertexOffsetAbsolute(index));
- }
- return PyLong_FromLong(0);
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMesh,
-"getMesh() : returns a mesh proxy\n")
-{
- KX_MeshProxy* meshproxy = new KX_MeshProxy((RAS_MeshObject*)m_mesh);
- return meshproxy->NewProxy(true);
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_PolyProxy, getMaterial,
-"getMaterial() : returns a material\n")
-{
- RAS_IPolyMaterial *polymat = m_polygon->GetMaterial()->GetPolyMaterial();
- KX_BlenderMaterial* mat = static_cast<KX_BlenderMaterial*>(polymat);
- return mat->GetProxy();
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_PolyProxy.h b/source/gameengine/Ketsji/KX_PolyProxy.h
deleted file mode 100644
index 837e7f8354c..00000000000
--- a/source/gameengine/Ketsji/KX_PolyProxy.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PolyProxy.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_POLYPROXY_H__
-#define __KX_POLYPROXY_H__
-
-#ifdef WITH_PYTHON
-
-#include "SCA_IObject.h"
-
-class KX_PolyProxy : public CValue
-{
- Py_Header
-protected:
- class RAS_Polygon* m_polygon;
- class RAS_MeshObject* m_mesh;
-public:
- KX_PolyProxy(const class RAS_MeshObject*mesh, class RAS_Polygon* polygon);
- virtual ~KX_PolyProxy();
-
- // stuff for cvalue related things
- CValue* Calc(VALUE_OPERATOR op, CValue *val);
- CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- const STR_String & GetText();
- double GetNumber();
- STR_String& GetName();
- void SetName(const char *name); // Set the name of the value
- CValue* GetReplica();
-
-
-// stuff for python integration
- static PyObject *pyattr_get_material_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_texture_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_material(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_material_id(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_v1(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_v3(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_v4(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_visible(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_collide(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMaterialIndex)
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getNumVertex)
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,isVisible)
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,isCollider)
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMaterialName)
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getTextureName)
- KX_PYMETHOD_DOC(KX_PolyProxy,getVertexIndex)
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMesh)
- KX_PYMETHOD_DOC_NOARGS(KX_PolyProxy,getMaterial)
-
-};
-
-#endif /* WITH_PYTHON */
-
-#endif /* __KX_POLYPROXY_H__ */
diff --git a/source/gameengine/Ketsji/KX_PositionInterpolator.cpp b/source/gameengine/Ketsji/KX_PositionInterpolator.cpp
deleted file mode 100644
index 1e217ecf616..00000000000
--- a/source/gameengine/Ketsji/KX_PositionInterpolator.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_PositionInterpolator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_PositionInterpolator.h"
-#include "MT_Point3.h"
-#include "KX_IScalarInterpolator.h"
-
-void KX_PositionInterpolator::Execute(float currentTime) const
-{
- m_target.setValue(m_ipos[0]->GetValue(currentTime),
- m_ipos[1]->GetValue(currentTime),
- m_ipos[2]->GetValue(currentTime));
-}
diff --git a/source/gameengine/Ketsji/KX_PositionInterpolator.h b/source/gameengine/Ketsji/KX_PositionInterpolator.h
deleted file mode 100644
index b5ab053bb0e..00000000000
--- a/source/gameengine/Ketsji/KX_PositionInterpolator.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PositionInterpolator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_POSITIONINTERPOLATOR_H__
-#define __KX_POSITIONINTERPOLATOR_H__
-
-#include "KX_IInterpolator.h"
-
-class MT_Point3;
-class KX_IScalarInterpolator;
-
-class KX_PositionInterpolator : public KX_IInterpolator {
-public:
- KX_PositionInterpolator(MT_Point3& target,
- KX_IScalarInterpolator *ipos[]) :
- m_target(target)
- {
- m_ipos[0] = ipos[0];
- m_ipos[1] = ipos[1];
- m_ipos[2] = ipos[2];
- }
-
- virtual void Execute(float currentTime) const;
-
-private:
- MT_Point3& m_target;
- KX_IScalarInterpolator *m_ipos[3];
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_PositionInterpolator")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp b/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
deleted file mode 100644
index 81fe3be1fcf..00000000000
--- a/source/gameengine/Ketsji/KX_PyConstraintBinding.cpp
+++ /dev/null
@@ -1,750 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_PyConstraintBinding.cpp
- * \ingroup ketsji
- */
-
-#include "KX_PyConstraintBinding.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "KX_ConstraintWrapper.h"
-#include "KX_VehicleWrapper.h"
-#include "KX_CharacterWrapper.h"
-#include "PHY_IPhysicsController.h"
-#include "PHY_IVehicle.h"
-#include "PHY_DynamicTypes.h"
-#include "MT_Matrix3x3.h"
-
-#include "KX_GameObject.h" // ConvertPythonToGameObject()
-#include "KX_PythonInit.h"
-
-#include "EXP_PyObjectPlus.h"
-
-#ifdef WITH_BULLET
-# include "LinearMath/btIDebugDraw.h"
-#endif
-
-#ifdef WITH_PYTHON
-
-// macro copied from KX_PythonInit.cpp
-#define KX_MACRO_addTypesToDict(dict, name, name2) PyDict_SetItemString(dict, #name, item=PyLong_FromLong(name2)); Py_DECREF(item)
-
-// nasty glob variable to connect scripting language
-// if there is a better way (without global), please do so!
-static PHY_IPhysicsEnvironment* g_CurrentActivePhysicsEnvironment = NULL;
-
-
-PyDoc_STRVAR(PhysicsConstraints_module_documentation,
-"This is the Python API for the Physics Constraints"
-);
-
-PyDoc_STRVAR(gPySetGravity__doc__,
-"setGravity(float x,float y,float z)\n"
-""
-);
-PyDoc_STRVAR(gPySetDebugMode__doc__,
-"setDebugMode(int mode)\n"
-""
-);
-
-PyDoc_STRVAR(gPySetNumIterations__doc__,
-"setNumIterations(int numiter)\n"
-"This sets the number of iterations for an iterative constraint solver"
-);
-PyDoc_STRVAR(gPySetNumTimeSubSteps__doc__,
-"setNumTimeSubSteps(int numsubstep)\n"
-"This sets the number of substeps for each physics proceed. Tradeoff quality for performance."
-);
-
-PyDoc_STRVAR(gPySetDeactivationTime__doc__,
-"setDeactivationTime(float time)\n"
-"This sets the time after which a resting rigidbody gets deactived"
-);
-PyDoc_STRVAR(gPySetDeactivationLinearTreshold__doc__,
-"setDeactivationLinearTreshold(float linearTreshold)\n"
-""
-);
-PyDoc_STRVAR(gPySetDeactivationAngularTreshold__doc__,
-"setDeactivationAngularTreshold(float angularTreshold)\n"
-""
-);
-PyDoc_STRVAR(gPySetContactBreakingTreshold__doc__,
-"setContactBreakingTreshold(float breakingTreshold)\n"
-"Reasonable default is 0.02 (if units are meters)"
-);
-
-PyDoc_STRVAR(gPySetCcdMode__doc__,
-"setCcdMode(int ccdMode)\n"
-"Very experimental, not recommended"
-);
-PyDoc_STRVAR(gPySetSorConstant__doc__,
-"setSorConstant(float sor)\n"
-"Very experimental, not recommended"
-);
-PyDoc_STRVAR(gPySetSolverTau__doc__,
-"setTau(float tau)\n"
-"Very experimental, not recommended"
-);
-PyDoc_STRVAR(gPySetSolverDamping__doc__,
-"setDamping(float damping)\n"
-"Very experimental, not recommended"
-);
-PyDoc_STRVAR(gPySetLinearAirDamping__doc__,
-"setLinearAirDamping(float damping)\n"
-"Very experimental, not recommended"
-);
-PyDoc_STRVAR(gPySetUseEpa__doc__,
-"setUseEpa(int epa)\n"
-"Very experimental, not recommended"
-);
-PyDoc_STRVAR(gPySetSolverType__doc__,
-"setSolverType(int solverType)\n"
-"Very experimental, not recommended"
-);
-
-PyDoc_STRVAR(gPyCreateConstraint__doc__,
-"createConstraint(ob1,ob2,float restLength,float restitution,float damping)\n"
-""
-);
-PyDoc_STRVAR(gPyGetVehicleConstraint__doc__,
-"getVehicleConstraint(int constraintId)\n"
-""
-);
-PyDoc_STRVAR(gPyGetCharacter__doc__,
-"getCharacter(KX_GameObject obj)\n"
-""
-);
-PyDoc_STRVAR(gPyRemoveConstraint__doc__,
-"removeConstraint(int constraintId)\n"
-""
-);
-PyDoc_STRVAR(gPyGetAppliedImpulse__doc__,
-"getAppliedImpulse(int constraintId)\n"
-""
-);
-
-
-
-
-static PyObject *gPySetGravity(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float x,y,z;
- if (PyArg_ParseTuple(args,"fff",&x,&y,&z))
- {
- if (PHY_GetActiveEnvironment())
- PHY_GetActiveEnvironment()->SetGravity(x,y,z);
- }
- else {
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetDebugMode(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- int mode;
- if (PyArg_ParseTuple(args,"i",&mode))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetDebugMode(mode);
-
- }
-
- }
- else {
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-
-
-static PyObject *gPySetNumTimeSubSteps(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- int substep;
- if (PyArg_ParseTuple(args,"i",&substep))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetNumTimeSubSteps(substep);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-static PyObject *gPySetNumIterations(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- int iter;
- if (PyArg_ParseTuple(args,"i",&iter))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetNumIterations(iter);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-static PyObject *gPySetDeactivationTime(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float deactive_time;
- if (PyArg_ParseTuple(args,"f",&deactive_time))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetDeactivationTime(deactive_time);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-static PyObject *gPySetDeactivationLinearTreshold(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float linearDeactivationTreshold;
- if (PyArg_ParseTuple(args,"f",&linearDeactivationTreshold))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetDeactivationLinearTreshold( linearDeactivationTreshold);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-static PyObject *gPySetDeactivationAngularTreshold(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float angularDeactivationTreshold;
- if (PyArg_ParseTuple(args,"f",&angularDeactivationTreshold))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetDeactivationAngularTreshold( angularDeactivationTreshold);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetContactBreakingTreshold(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float contactBreakingTreshold;
- if (PyArg_ParseTuple(args,"f",&contactBreakingTreshold))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetContactBreakingTreshold( contactBreakingTreshold);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-static PyObject *gPySetCcdMode(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float ccdMode;
- if (PyArg_ParseTuple(args,"f",&ccdMode))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetCcdMode( ccdMode);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetSorConstant(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float sor;
- if (PyArg_ParseTuple(args,"f",&sor))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetSolverSorConstant( sor);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetSolverTau(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float tau;
- if (PyArg_ParseTuple(args,"f",&tau))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetSolverTau( tau);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-static PyObject *gPySetSolverDamping(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float damping;
- if (PyArg_ParseTuple(args,"f",&damping))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetSolverDamping( damping);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetLinearAirDamping(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float damping;
- if (PyArg_ParseTuple(args,"f",&damping))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetLinearAirDamping( damping);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-static PyObject *gPySetUseEpa(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- int epa;
- if (PyArg_ParseTuple(args,"i",&epa))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetUseEpa(epa);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-static PyObject *gPySetSolverType(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- int solverType;
- if (PyArg_ParseTuple(args,"i",&solverType))
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->SetSolverType(solverType);
- }
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-
-static PyObject *gPyGetVehicleConstraint(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
-#if defined(_WIN64)
- __int64 constraintid;
- if (PyArg_ParseTuple(args,"L",&constraintid))
-#else
- long constraintid;
- if (PyArg_ParseTuple(args,"l",&constraintid))
-#endif
- {
- if (PHY_GetActiveEnvironment())
- {
-
- PHY_IVehicle* vehicle = PHY_GetActiveEnvironment()->GetVehicleConstraint(constraintid);
- if (vehicle)
- {
- KX_VehicleWrapper* pyWrapper = new KX_VehicleWrapper(vehicle,PHY_GetActiveEnvironment());
- return pyWrapper->NewProxy(true);
- }
-
- }
- }
- else {
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject* gPyGetCharacter(PyObject* self,
- PyObject* args,
- PyObject* kwds)
-{
- PyObject* pyob;
- KX_GameObject *ob;
-
- if (!PyArg_ParseTuple(args,"O", &pyob))
- return NULL;
-
- if (!ConvertPythonToGameObject(KX_GetActiveScene()->GetLogicManager(), pyob, &ob, false, "bge.constraints.getCharacter(value)"))
- return NULL;
-
- if (PHY_GetActiveEnvironment())
- {
-
- PHY_ICharacter* character= PHY_GetActiveEnvironment()->GetCharacterController(ob);
- if (character)
- {
- KX_CharacterWrapper* pyWrapper = new KX_CharacterWrapper(character);
- return pyWrapper->NewProxy(true);
- }
-
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyCreateConstraint(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- /* FIXME - physicsid is a long being cast to a pointer, should at least use PyCapsule */
- unsigned long long physicsid = 0, physicsid2 = 0;
- int constrainttype = 0;
- int flag = 0;
- float pivotX = 0.0f, pivotY = 0.0f, pivotZ = 0.0f, axisX = 0.0f, axisY = 0.0f, axisZ = 0.0f;
-
- static const char *kwlist[] = {"physicsid_1", "physicsid_2", "constraint_type", "pivot_x", "pivot_y", "pivot_z",
- "axis_x", "axis_y", "axis_z", "flag", NULL};
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "KKi|ffffffi:createConstraint", (char **)kwlist,
- &physicsid, &physicsid2, &constrainttype,
- &pivotX, &pivotY, &pivotZ, &axisX, &axisY, &axisZ, &flag))
- {
- return NULL;
- }
-
- if (PHY_GetActiveEnvironment()) {
- PHY_IPhysicsController *physctrl = (PHY_IPhysicsController*)physicsid;
- PHY_IPhysicsController *physctrl2 = (PHY_IPhysicsController*)physicsid2;
- if (physctrl) { //TODO:check for existence of this pointer!
- //convert from euler angle into axis
- const float deg2rad = 0.017453292f;
-
- //we need to pass a full constraint frame, not just axis
- //localConstraintFrameBasis
- MT_Matrix3x3 localCFrame(MT_Vector3(deg2rad*axisX, deg2rad*axisY, deg2rad*axisZ));
- MT_Vector3 axis0 = localCFrame.getColumn(0);
- MT_Vector3 axis1 = localCFrame.getColumn(1);
- MT_Vector3 axis2 = localCFrame.getColumn(2);
-
- int constraintid = PHY_GetActiveEnvironment()->CreateConstraint(
- physctrl, physctrl2, (enum PHY_ConstraintType)constrainttype, pivotX, pivotY, pivotZ,
- (float)axis0.x(), (float)axis0.y(), (float)axis0.z(),
- (float)axis1.x(), (float)axis1.y(), (float)axis1.z(),
- (float)axis2.x(), (float)axis2.y(), (float)axis2.z(), flag);
-
- KX_ConstraintWrapper *wrap = new KX_ConstraintWrapper(
- (enum PHY_ConstraintType)constrainttype, constraintid, PHY_GetActiveEnvironment());
-
- return wrap->NewProxy(true);
- }
- }
- Py_RETURN_NONE;
-}
-
-
-
-
-static PyObject *gPyGetAppliedImpulse(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
- float appliedImpulse = 0.f;
-
-#if defined(_WIN64)
- __int64 constraintid;
- if (PyArg_ParseTuple(args,"L",&constraintid))
-#else
- long constraintid;
- if (PyArg_ParseTuple(args,"l",&constraintid))
-#endif
- {
- if (PHY_GetActiveEnvironment())
- {
- appliedImpulse = PHY_GetActiveEnvironment()->GetAppliedImpulse(constraintid);
- }
- }
- else {
- return NULL;
- }
-
- return PyFloat_FromDouble(appliedImpulse);
-}
-
-
-static PyObject *gPyRemoveConstraint(PyObject *self,
- PyObject *args,
- PyObject *kwds)
-{
-#if defined(_WIN64)
- __int64 constraintid;
- if (PyArg_ParseTuple(args,"L",&constraintid))
-#else
- long constraintid;
- if (PyArg_ParseTuple(args,"l",&constraintid))
-#endif
- {
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->RemoveConstraintById(constraintid);
- }
- }
- else {
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyExportBulletFile(PyObject *, PyObject *args)
-{
- char* filename;
- if (!PyArg_ParseTuple(args,"s:exportBulletFile",&filename))
- return NULL;
-
- if (PHY_GetActiveEnvironment())
- {
- PHY_GetActiveEnvironment()->ExportFile(filename);
- }
- Py_RETURN_NONE;
-}
-
-static struct PyMethodDef physicsconstraints_methods[] = {
- {"setGravity",(PyCFunction) gPySetGravity,
- METH_VARARGS, (const char*)gPySetGravity__doc__},
- {"setDebugMode",(PyCFunction) gPySetDebugMode,
- METH_VARARGS, (const char *)gPySetDebugMode__doc__},
-
- /// settings that influence quality of the rigidbody dynamics
- {"setNumIterations",(PyCFunction) gPySetNumIterations,
- METH_VARARGS, (const char *)gPySetNumIterations__doc__},
-
- {"setNumTimeSubSteps",(PyCFunction) gPySetNumTimeSubSteps,
- METH_VARARGS, (const char *)gPySetNumTimeSubSteps__doc__},
-
- {"setDeactivationTime",(PyCFunction) gPySetDeactivationTime,
- METH_VARARGS, (const char *)gPySetDeactivationTime__doc__},
-
- {"setDeactivationLinearTreshold",(PyCFunction) gPySetDeactivationLinearTreshold,
- METH_VARARGS, (const char *)gPySetDeactivationLinearTreshold__doc__},
- {"setDeactivationAngularTreshold",(PyCFunction) gPySetDeactivationAngularTreshold,
- METH_VARARGS, (const char *)gPySetDeactivationAngularTreshold__doc__},
-
- {"setContactBreakingTreshold",(PyCFunction) gPySetContactBreakingTreshold,
- METH_VARARGS, (const char *)gPySetContactBreakingTreshold__doc__},
- {"setCcdMode",(PyCFunction) gPySetCcdMode,
- METH_VARARGS, (const char *)gPySetCcdMode__doc__},
- {"setSorConstant",(PyCFunction) gPySetSorConstant,
- METH_VARARGS, (const char *)gPySetSorConstant__doc__},
- {"setSolverTau",(PyCFunction) gPySetSolverTau,
- METH_VARARGS, (const char *)gPySetSolverTau__doc__},
- {"setSolverDamping",(PyCFunction) gPySetSolverDamping,
- METH_VARARGS, (const char *)gPySetSolverDamping__doc__},
-
- {"setLinearAirDamping",(PyCFunction) gPySetLinearAirDamping,
- METH_VARARGS, (const char *)gPySetLinearAirDamping__doc__},
-
- {"setUseEpa",(PyCFunction) gPySetUseEpa,
- METH_VARARGS, (const char *)gPySetUseEpa__doc__},
- {"setSolverType",(PyCFunction) gPySetSolverType,
- METH_VARARGS, (const char *)gPySetSolverType__doc__},
-
-
- {"createConstraint",(PyCFunction) gPyCreateConstraint,
- METH_VARARGS|METH_KEYWORDS, (const char *)gPyCreateConstraint__doc__},
- {"getVehicleConstraint",(PyCFunction) gPyGetVehicleConstraint,
- METH_VARARGS, (const char *)gPyGetVehicleConstraint__doc__},
-
- {"getCharacter",(PyCFunction) gPyGetCharacter,
- METH_VARARGS, (const char *)gPyGetCharacter__doc__},
-
- {"removeConstraint",(PyCFunction) gPyRemoveConstraint,
- METH_VARARGS, (const char *)gPyRemoveConstraint__doc__},
- {"getAppliedImpulse",(PyCFunction) gPyGetAppliedImpulse,
- METH_VARARGS, (const char *)gPyGetAppliedImpulse__doc__},
-
- {"exportBulletFile",(PyCFunction)gPyExportBulletFile,
- METH_VARARGS, "export a .bullet file"},
-
- //sentinel
- { NULL, (PyCFunction) NULL, 0, NULL }
-};
-
-static struct PyModuleDef PhysicsConstraints_module_def = {
- PyModuleDef_HEAD_INIT,
- "PhysicsConstraints", /* m_name */
- PhysicsConstraints_module_documentation, /* m_doc */
- 0, /* m_size */
- physicsconstraints_methods, /* m_methods */
- 0, /* m_reload */
- 0, /* m_traverse */
- 0, /* m_clear */
- 0, /* m_free */
-};
-
-PyMODINIT_FUNC initConstraintPythonBinding()
-{
-
- PyObject *ErrorObject;
- PyObject *m;
- PyObject *d;
- PyObject *item;
-
- m = PyModule_Create(&PhysicsConstraints_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), PhysicsConstraints_module_def.m_name, m);
-
- // Add some symbolic constants to the module
- d = PyModule_GetDict(m);
- ErrorObject = PyUnicode_FromString("PhysicsConstraints.error");
- PyDict_SetItemString(d, "error", ErrorObject);
- Py_DECREF(ErrorObject);
-
-#ifdef WITH_BULLET
- //Debug Modes constants to be used with setDebugMode() python function
- KX_MACRO_addTypesToDict(d, DBG_NODEBUG, btIDebugDraw::DBG_NoDebug);
- KX_MACRO_addTypesToDict(d, DBG_DRAWWIREFRAME, btIDebugDraw::DBG_DrawWireframe);
- KX_MACRO_addTypesToDict(d, DBG_DRAWAABB, btIDebugDraw::DBG_DrawAabb);
- KX_MACRO_addTypesToDict(d, DBG_DRAWFREATURESTEXT, btIDebugDraw::DBG_DrawFeaturesText);
- KX_MACRO_addTypesToDict(d, DBG_DRAWCONTACTPOINTS, btIDebugDraw::DBG_DrawContactPoints);
- KX_MACRO_addTypesToDict(d, DBG_NOHELPTEXT, btIDebugDraw::DBG_NoHelpText);
- KX_MACRO_addTypesToDict(d, DBG_DRAWTEXT, btIDebugDraw::DBG_DrawText);
- KX_MACRO_addTypesToDict(d, DBG_PROFILETIMINGS, btIDebugDraw::DBG_ProfileTimings);
- KX_MACRO_addTypesToDict(d, DBG_ENABLESATCOMPARISION, btIDebugDraw::DBG_EnableSatComparison);
- KX_MACRO_addTypesToDict(d, DBG_DISABLEBULLETLCP, btIDebugDraw::DBG_DisableBulletLCP);
- KX_MACRO_addTypesToDict(d, DBG_ENABLECCD, btIDebugDraw::DBG_EnableCCD);
- KX_MACRO_addTypesToDict(d, DBG_DRAWCONSTRAINTS, btIDebugDraw::DBG_DrawConstraints);
- KX_MACRO_addTypesToDict(d, DBG_DRAWCONSTRAINTLIMITS, btIDebugDraw::DBG_DrawConstraintLimits);
- KX_MACRO_addTypesToDict(d, DBG_FASTWIREFRAME, btIDebugDraw::DBG_FastWireframe);
-#endif // WITH_BULLET
-
- //Constraint types to be used with createConstraint() python function
- KX_MACRO_addTypesToDict(d, POINTTOPOINT_CONSTRAINT, PHY_POINT2POINT_CONSTRAINT);
- KX_MACRO_addTypesToDict(d, LINEHINGE_CONSTRAINT, PHY_LINEHINGE_CONSTRAINT);
- KX_MACRO_addTypesToDict(d, ANGULAR_CONSTRAINT, PHY_ANGULAR_CONSTRAINT);
- KX_MACRO_addTypesToDict(d, CONETWIST_CONSTRAINT, PHY_CONE_TWIST_CONSTRAINT);
- KX_MACRO_addTypesToDict(d, VEHICLE_CONSTRAINT, PHY_VEHICLE_CONSTRAINT);
- KX_MACRO_addTypesToDict(d, GENERIC_6DOF_CONSTRAINT, PHY_GENERIC_6DOF_CONSTRAINT);
-
- // Check for errors
- if (PyErr_Occurred()) {
- Py_FatalError("can't initialize module PhysicsConstraints");
- }
-
- return m;
-}
-
-#if 0
-static void KX_RemovePythonConstraintBinding()
-{
-}
-#endif
-
-void PHY_SetActiveEnvironment(class PHY_IPhysicsEnvironment* env)
-{
- g_CurrentActivePhysicsEnvironment = env;
-}
-
-PHY_IPhysicsEnvironment* PHY_GetActiveEnvironment()
-{
- return g_CurrentActivePhysicsEnvironment;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_PyConstraintBinding.h b/source/gameengine/Ketsji/KX_PyConstraintBinding.h
deleted file mode 100644
index 2bf9f7e197d..00000000000
--- a/source/gameengine/Ketsji/KX_PyConstraintBinding.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PyConstraintBinding.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_PYCONSTRAINTBINDING_H__
-#define __KX_PYCONSTRAINTBINDING_H__
-
-#ifdef WITH_PYTHON
-
-#include <Python.h>
-
-PyMODINIT_FUNC initConstraintPythonBinding();
-
-void PHY_SetActiveEnvironment(class PHY_IPhysicsEnvironment* env);
-PHY_IPhysicsEnvironment* PHY_GetActiveEnvironment();
-#endif /* WITH_PYTHON */
-
-#endif /* __KX_PYCONSTRAINTBINDING_H__ */
diff --git a/source/gameengine/Ketsji/KX_PyMath.cpp b/source/gameengine/Ketsji/KX_PyMath.cpp
deleted file mode 100644
index ee05fd442ab..00000000000
--- a/source/gameengine/Ketsji/KX_PyMath.cpp
+++ /dev/null
@@ -1,215 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Initialize Python thingies.
- */
-
-/** \file gameengine/Ketsji/KX_PyMath.cpp
- * \ingroup ketsji
- */
-
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#ifdef WITH_PYTHON
-
-#include "MT_Vector3.h"
-#include "MT_Vector4.h"
-#include "MT_Matrix4x4.h"
-#include "MT_Point2.h"
-
-#include "EXP_ListValue.h"
-
-#include "EXP_Python.h"
-#include "KX_PyMath.h"
-
-bool PyOrientationTo(PyObject *pyval, MT_Matrix3x3 &rot, const char *error_prefix)
-{
- int size= PySequence_Size(pyval);
-
- if (size == 4)
- {
- MT_Quaternion qrot;
- if (PyQuatTo(pyval, qrot))
- {
- rot.setRotation(qrot);
- return true;
- }
- }
- else if (size == 3) {
- /* 3x3 matrix or euler */
- MT_Vector3 erot;
- if (PyVecTo(pyval, erot))
- {
- rot.setEuler(erot);
- return true;
- }
- PyErr_Clear();
-
- if (PyMatTo(pyval, rot))
- {
- return true;
- }
- }
-
- PyErr_Format(PyExc_TypeError, "%s, could not set the orientation from a 3x3 matrix, quaternion or euler sequence", error_prefix);
- return false;
-}
-
-bool PyQuatTo(PyObject *pyval, MT_Quaternion &qrot)
-{
- if (!PyVecTo(pyval, qrot))
- return false;
-
- /* annoying!, Blender/Mathutils have the W axis first! */
- MT_Scalar w = qrot[0]; /* from python, this is actually the W */
- qrot[0] = qrot[1];
- qrot[1] = qrot[2];
- qrot[2] = qrot[3];
- qrot[3] = w;
-
- return true;
-}
-
-PyObject *PyObjectFrom(const MT_Matrix4x4 &mat)
-{
-#ifdef USE_MATHUTILS
- float fmat[16];
- mat.getValue(fmat);
- return Matrix_CreatePyObject(fmat, 4, 4, NULL);
-#else
- PyObject *collist = PyList_New(4);
- PyObject *col;
- int i;
-
- for (i=0; i < 4; i++) {
- col = PyList_New(4);
- PyList_SET_ITEM(col, 0, PyFloat_FromDouble(mat[0][i]));
- PyList_SET_ITEM(col, 1, PyFloat_FromDouble(mat[1][i]));
- PyList_SET_ITEM(col, 2, PyFloat_FromDouble(mat[2][i]));
- PyList_SET_ITEM(col, 3, PyFloat_FromDouble(mat[3][i]));
- PyList_SET_ITEM(collist, i, col);
- }
-
- return collist;
-#endif
-}
-
-PyObject *PyObjectFrom(const MT_Matrix3x3 &mat)
-{
-#ifdef USE_MATHUTILS
- float fmat[9];
- mat.getValue3x3(fmat);
- return Matrix_CreatePyObject(fmat, 3, 3, NULL);
-#else
- PyObject *collist = PyList_New(3);
- PyObject *col;
- int i;
-
- for (i=0; i < 3; i++) {
- col = PyList_New(3);
- PyList_SET_ITEM(col, 0, PyFloat_FromDouble(mat[0][i]));
- PyList_SET_ITEM(col, 1, PyFloat_FromDouble(mat[1][i]));
- PyList_SET_ITEM(col, 2, PyFloat_FromDouble(mat[2][i]));
- PyList_SET_ITEM(collist, i, col);
- }
-
- return collist;
-#endif
-}
-
-#ifdef USE_MATHUTILS
-PyObject *PyObjectFrom(const MT_Quaternion &qrot)
-{
- /* NOTE, were re-ordering here for Mathutils compat */
- float fvec[4];
- qrot.getValue(fvec);
- return Quaternion_CreatePyObject(fvec, NULL);
-}
-#endif
-
-PyObject *PyObjectFrom(const MT_Tuple4 &vec)
-{
-#ifdef USE_MATHUTILS
- float fvec[4];
- vec.getValue(fvec);
- return Vector_CreatePyObject(fvec, 4, NULL);
-#else
- PyObject *list = PyList_New(4);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(vec[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(vec[2]));
- PyList_SET_ITEM(list, 3, PyFloat_FromDouble(vec[3]));
- return list;
-#endif
-}
-
-PyObject *PyObjectFrom(const MT_Tuple3 &vec)
-{
-#ifdef USE_MATHUTILS
- float fvec[3];
- vec.getValue(fvec);
- return Vector_CreatePyObject(fvec, 3, NULL);
-#else
- PyObject *list = PyList_New(3);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(vec[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(vec[2]));
- return list;
-#endif
-}
-
-PyObject *PyObjectFrom(const MT_Tuple2 &vec)
-{
-#ifdef USE_MATHUTILS
- float fvec[2];
- vec.getValue(fvec);
- return Vector_CreatePyObject(fvec, 2, NULL);
-#else
- PyObject *list = PyList_New(2);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(vec[1]));
- return list;
-#endif
-}
-
-PyObject *PyColorFromVector(const MT_Vector3 &vec)
-{
-#ifdef USE_MATHUTILS
- float fvec[3];
- vec.getValue(fvec);
- return Color_CreatePyObject(fvec, NULL);
-#else
- PyObject *list = PyList_New(3);
- PyList_SET_ITEM(list, 0, PyFloat_FromDouble(vec[0]));
- PyList_SET_ITEM(list, 1, PyFloat_FromDouble(vec[1]));
- PyList_SET_ITEM(list, 2, PyFloat_FromDouble(vec[2]));
- return list;
-#endif
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_PyMath.h b/source/gameengine/Ketsji/KX_PyMath.h
deleted file mode 100644
index 917fd0fcda6..00000000000
--- a/source/gameengine/Ketsji/KX_PyMath.h
+++ /dev/null
@@ -1,281 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PyMath.h
- * \ingroup ketsji
- * \brief Initialize Python thingies.
- */
-
-#ifndef __KX_PYMATH_H__
-#define __KX_PYMATH_H__
-
-#include "MT_Point2.h"
-#include "MT_Point3.h"
-#include "MT_Vector2.h"
-#include "MT_Vector3.h"
-#include "MT_Vector4.h"
-#include "MT_Matrix3x3.h"
-#include "MT_Matrix4x4.h"
-
-#include "EXP_Python.h"
-#include "EXP_PyObjectPlus.h"
-
-#ifdef WITH_PYTHON
-#ifdef USE_MATHUTILS
-extern "C" {
-#include "../../blender/python/mathutils/mathutils.h" /* so we can have mathutils callbacks */
-}
-#endif
-
-inline unsigned int Size(const MT_Matrix4x4&) { return 4; }
-inline unsigned int Size(const MT_Matrix3x3&) { return 3; }
-inline unsigned int Size(const MT_Tuple2&) { return 2; }
-inline unsigned int Size(const MT_Tuple3&) { return 3; }
-inline unsigned int Size(const MT_Tuple4&) { return 4; }
-
-/**
- * Converts the given python matrix (column-major) to an MT class (row-major).
- */
-template<class T>
-bool PyMatTo(PyObject *pymat, T& mat)
-{
- bool noerror = true;
- mat.setIdentity();
-
-
-#ifdef USE_MATHUTILS
-
- if (MatrixObject_Check(pymat))
- {
- MatrixObject *pymatrix = (MatrixObject *)pymat;
-
- if (BaseMath_ReadCallback(pymatrix) == -1)
- return false;
-
- if (pymatrix->num_col != Size(mat) || pymatrix->num_row != Size(mat))
- return false;
-
- for (unsigned int row = 0; row < Size(mat); row++)
- {
- for (unsigned int col = 0; col < Size(mat); col++)
- {
- mat[row][col] = *(pymatrix->matrix + col * pymatrix->num_row + row);
- }
- }
- }
- else
-
-#endif /* USE_MATHUTILS */
-
-
- if (PySequence_Check(pymat))
- {
- unsigned int rows = PySequence_Size(pymat);
- if (rows != Size(mat))
- return false;
-
- for (unsigned int row = 0; noerror && row < rows; row++)
- {
- PyObject *pyrow = PySequence_GetItem(pymat, row); /* new ref */
- if (!PyErr_Occurred() && PySequence_Check(pyrow))
- {
- unsigned int cols = PySequence_Size(pyrow);
- if (cols != Size(mat)) {
- noerror = false;
- }
- else {
- for (unsigned int col = 0; col < cols; col++) {
- PyObject *item = PySequence_GetItem(pyrow, col); /* new ref */
- mat[row][col] = PyFloat_AsDouble(item);
- Py_DECREF(item);
- }
- }
- }
- else {
- noerror = false;
- }
- Py_DECREF(pyrow);
- }
- } else
- noerror = false;
-
- if (noerror==false)
- PyErr_SetString(PyExc_TypeError, "could not be converted to a matrix (sequence of sequences)");
-
- return noerror;
-}
-
-/**
- * Converts a python sequence to a MT class.
- */
-template<class T>
-bool PyVecTo(PyObject *pyval, T& vec)
-{
-#ifdef USE_MATHUTILS
- /* no need for BaseMath_ReadCallback() here, reading the sequences will do this */
-
- if (VectorObject_Check(pyval)) {
- VectorObject *pyvec= (VectorObject *)pyval;
- if (BaseMath_ReadCallback(pyvec) == -1) {
- return false; /* exception raised */
- }
- if (pyvec->size != Size(vec)) {
- PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", pyvec->size, Size(vec));
- return false;
- }
- vec.setValue((float *) pyvec->vec);
- return true;
- }
- else if (QuaternionObject_Check(pyval)) {
- QuaternionObject *pyquat= (QuaternionObject *)pyval;
- if (BaseMath_ReadCallback(pyquat) == -1) {
- return false; /* exception raised */
- }
- if (4 != Size(vec)) {
- PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", 4, Size(vec));
- return false;
- }
- /* xyzw -> wxyz reordering is done by PyQuatTo */
- vec.setValue((float *) pyquat->quat);
- return true;
- }
- else if (EulerObject_Check(pyval)) {
- EulerObject *pyeul= (EulerObject *)pyval;
- if (BaseMath_ReadCallback(pyeul) == -1) {
- return false; /* exception raised */
- }
- if (3 != Size(vec)) {
- PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", 3, Size(vec));
- return false;
- }
- vec.setValue((float *) pyeul->eul);
- return true;
- }
- else
-#endif
- if (PyTuple_Check(pyval)) {
- unsigned int numitems = PyTuple_GET_SIZE(pyval);
- if (numitems != Size(vec)) {
- PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", numitems, Size(vec));
- return false;
- }
-
- for (unsigned int x = 0; x < numitems; x++)
- vec[x] = PyFloat_AsDouble(PyTuple_GET_ITEM(pyval, x)); /* borrow ref */
-
- if (PyErr_Occurred()) {
- PyErr_SetString(PyExc_AttributeError, "one or more of the items in the sequence was not a float");
- return false;
- }
-
- return true;
- }
- else if (PyObject_TypeCheck(pyval, (PyTypeObject *)&PyObjectPlus::Type)) {
- /* note, include this check because PySequence_Check does too much introspection
- * on the PyObject (like getting its __class__, on a BGE type this means searching up
- * the parent list each time only to discover its not a sequence.
- * GameObjects are often used as an alternative to vectors so this is a common case
- * better to do a quick check for it, likely the error below will be ignored.
- *
- * This is not 'correct' since we have proxy type CListValues's which could
- * contain floats/ints but there no cases of CValueLists being this way
- */
- PyErr_Format(PyExc_AttributeError, "expected a sequence type");
- return false;
- }
- else if (PySequence_Check(pyval)) {
- unsigned int numitems = PySequence_Size(pyval);
- if (numitems != Size(vec)) {
- PyErr_Format(PyExc_AttributeError, "error setting vector, %d args, should be %d", numitems, Size(vec));
- return false;
- }
-
- for (unsigned int x = 0; x < numitems; x++) {
- PyObject *item = PySequence_GetItem(pyval, x); /* new ref */
- vec[x] = PyFloat_AsDouble(item);
- Py_DECREF(item);
- }
-
- if (PyErr_Occurred()) {
- PyErr_SetString(PyExc_AttributeError, "one or more of the items in the sequence was not a float");
- return false;
- }
-
- return true;
- }
- else {
- PyErr_Format(PyExc_AttributeError, "not a sequence type, expected a sequence of numbers size %d", Size(vec));
- }
-
- return false;
-}
-
-
-bool PyQuatTo(PyObject *pyval, MT_Quaternion &qrot);
-
-bool PyOrientationTo(PyObject *pyval, MT_Matrix3x3 &mat, const char *error_prefix);
-
-/**
- * Converts an MT_Matrix4x4 to a python object.
- */
-PyObject *PyObjectFrom(const MT_Matrix4x4 &mat);
-
-/**
- * Converts an MT_Matrix3x3 to a python object.
- */
-PyObject *PyObjectFrom(const MT_Matrix3x3 &mat);
-
-/**
- * Converts an MT_Tuple2 to a python object.
- */
-PyObject *PyObjectFrom(const MT_Tuple2 &vec);
-
-/**
- * Converts an MT_Tuple3 to a python object
- */
-PyObject *PyObjectFrom(const MT_Tuple3 &vec);
-
-#ifdef USE_MATHUTILS
-/**
- * Converts an MT_Quaternion to a python object.
- */
-PyObject *PyObjectFrom(const MT_Quaternion &qrot);
-#endif
-
-/**
- * Converts an MT_Tuple4 to a python object.
- */
-PyObject *PyObjectFrom(const MT_Tuple4 &pos);
-
-#endif
-
-/**
- * Converts an MT_Vector3 to a python color object.
- */
-PyObject *PyColorFromVector(const MT_Vector3 &vec);
-
-#endif /* WITH_PYTHON */
diff --git a/source/gameengine/Ketsji/KX_PythonInit.cpp b/source/gameengine/Ketsji/KX_PythonInit.cpp
deleted file mode 100644
index 5540aad7a3f..00000000000
--- a/source/gameengine/Ketsji/KX_PythonInit.cpp
+++ /dev/null
@@ -1,2953 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Initialize Python thingies.
- */
-
-/** \file gameengine/Ketsji/KX_PythonInit.cpp
- * \ingroup ketsji
- */
-
-#include "GPU_glew.h"
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#ifdef WITH_PYTHON
-# ifdef _XOPEN_SOURCE
-# undef _XOPEN_SOURCE
-# endif
-# include <Python.h>
-
-extern "C" {
- # include "BLI_utildefines.h"
- # include "python_utildefines.h"
- # include "bpy_internal_import.h" /* from the blender python api, but we want to import text too! */
- # include "py_capi_utils.h"
- # include "mathutils.h" // 'mathutils' module copied here so the blenderlayer can use.
- # include "bgl.h"
- # include "blf_py_api.h"
-
- # include "marshal.h" /* python header for loading/saving dicts */
-}
-#include "../../../../intern/audaspace/intern/AUD_PyInit.h"
-
-#endif /* WITH_PYTHON */
-
-#include "KX_PythonInit.h"
-
-// directory header for py function getBlendFileList
-#ifndef WIN32
-# include <dirent.h>
-# include <stdlib.h>
-#else
-# include <io.h>
-# include "BLI_winstuff.h"
-#endif
-
-//python physics binding
-#include "KX_PyConstraintBinding.h"
-
-#include "KX_KetsjiEngine.h"
-#include "KX_RadarSensor.h"
-#include "KX_RaySensor.h"
-#include "KX_ArmatureSensor.h"
-#include "KX_SceneActuator.h"
-#include "KX_GameActuator.h"
-#include "KX_ParentActuator.h"
-#include "KX_SCA_DynamicActuator.h"
-#include "KX_SteeringActuator.h"
-#include "KX_NavMeshObject.h"
-#include "KX_MouseActuator.h"
-#include "KX_TrackToActuator.h"
-
-#include "SCA_IInputDevice.h"
-#include "SCA_PropertySensor.h"
-#include "SCA_RandomActuator.h"
-#include "SCA_KeyboardSensor.h" /* IsPrintable, ToCharacter */
-#include "SCA_JoystickManager.h" /* JOYINDEX_MAX */
-#include "SCA_PythonJoystick.h"
-#include "SCA_PythonKeyboard.h"
-#include "SCA_PythonMouse.h"
-#include "KX_ConstraintActuator.h"
-#include "KX_SoundActuator.h"
-#include "KX_StateActuator.h"
-#include "BL_ActionActuator.h"
-#include "BL_ArmatureObject.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_ICanvas.h"
-#include "RAS_IOffScreen.h"
-#include "RAS_BucketManager.h"
-#include "RAS_2DFilterManager.h"
-#include "MT_Vector3.h"
-#include "MT_Point3.h"
-#include "EXP_ListValue.h"
-#include "EXP_InputParser.h"
-#include "KX_Scene.h"
-
-#include "NG_NetworkScene.h" //Needed for sendMessage()
-
-#include "BL_Shader.h"
-#include "BL_Action.h"
-
-#include "KX_PyMath.h"
-
-#include "EXP_PyObjectPlus.h"
-
-#include "KX_PythonInitTypes.h"
-
-/* we only need this to get a list of libraries from the main struct */
-#include "DNA_ID.h"
-#include "DNA_scene_types.h"
-
-#include "PHY_IPhysicsEnvironment.h"
-
-extern "C" {
-#include "BKE_main.h"
-#include "BKE_global.h"
-#include "BKE_library.h"
-#include "BKE_appdir.h"
-#include "BKE_blender_version.h"
-#include "BLI_blenlib.h"
-#include "GPU_material.h"
-#include "MEM_guardedalloc.h"
-}
-
-/* for converting new scenes */
-#include "KX_BlenderSceneConverter.h"
-#include "KX_LibLoadStatus.h"
-#include "KX_MeshProxy.h" /* for creating a new library of mesh objects */
-extern "C" {
- #include "BKE_idcode.h"
-}
-
-// 'local' copy of canvas ptr, for window height/width python scripts
-
-#ifdef WITH_PYTHON
-
-static RAS_ICanvas* gp_Canvas = NULL;
-static char gp_GamePythonPath[FILE_MAX] = "";
-static char gp_GamePythonPathOrig[FILE_MAX] = ""; // not super happy about this, but we need to remember the first loaded file for the global/dict load save
-
-static SCA_PythonKeyboard* gp_PythonKeyboard = NULL;
-static SCA_PythonMouse* gp_PythonMouse = NULL;
-static SCA_PythonJoystick* gp_PythonJoysticks[JOYINDEX_MAX] = {NULL};
-#endif // WITH_PYTHON
-
-static KX_Scene* gp_KetsjiScene = NULL;
-static KX_KetsjiEngine* gp_KetsjiEngine = NULL;
-static RAS_IRasterizer* gp_Rasterizer = NULL;
-
-
-void KX_SetActiveScene(class KX_Scene* scene)
-{
- gp_KetsjiScene = scene;
-}
-
-class KX_Scene* KX_GetActiveScene()
-{
- return gp_KetsjiScene;
-}
-
-class KX_KetsjiEngine* KX_GetActiveEngine()
-{
- return gp_KetsjiEngine;
-}
-
-/* why is this in python? */
-void KX_RasterizerDrawDebugLine(const MT_Vector3& from,const MT_Vector3& to,const MT_Vector3& color)
-{
- if (gp_Rasterizer)
- gp_Rasterizer->DrawDebugLine(gp_KetsjiScene, from, to, color);
-}
-
-void KX_RasterizerDrawDebugCircle(const MT_Vector3& center, const MT_Scalar radius, const MT_Vector3& color,
- const MT_Vector3& normal, int nsector)
-{
- if (gp_Rasterizer)
- gp_Rasterizer->DrawDebugCircle(gp_KetsjiScene, center, radius, color, normal, nsector);
-}
-
-#ifdef WITH_PYTHON
-
-
-static struct {
- PyObject *path;
- PyObject *meta_path;
- PyObject *modules;
-} gp_sys_backup = {NULL};
-
-/* Macro for building the keyboard translation */
-//#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, PyLong_FromLong(SCA_IInputDevice::KX_##name))
-//#define KX_MACRO_addToDict(dict, name) PyDict_SetItemString(dict, #name, item=PyLong_FromLong(name)); Py_DECREF(item)
-/* For the defines for types from logic bricks, we do stuff explicitly... */
-#define KX_MACRO_addTypesToDict(dict, name, value) KX_MACRO_addTypesToDict_fn(dict, #name, value)
-static void KX_MACRO_addTypesToDict_fn(PyObject *dict, const char *name, long value)
-{
- PyObject *item;
-
- item = PyLong_FromLong(value);
- PyDict_SetItemString(dict, name, item);
- Py_DECREF(item);
-}
-
-
-
-// temporarily python stuff, will be put in another place later !
-#include "EXP_Python.h"
-#include "SCA_PythonController.h"
-// List of methods defined in the module
-
-static PyObject *ErrorObject;
-
-PyDoc_STRVAR(gPyGetRandomFloat_doc,
-"getRandomFloat()\n"
-"returns a random floating point value in the range [0..1]"
-);
-static PyObject *gPyGetRandomFloat(PyObject *)
-{
- return PyFloat_FromDouble(MT_random());
-}
-
-static PyObject *gPySetGravity(PyObject *, PyObject *value)
-{
- MT_Vector3 vec;
- if (!PyVecTo(value, vec))
- return NULL;
-
- if (gp_KetsjiScene)
- gp_KetsjiScene->SetGravity(vec);
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(gPyExpandPath_doc,
-"expandPath(path)\n"
-"Converts a blender internal path into a proper file system path.\n"
-" path - the string path to convert.\n"
-"Use / as directory separator in path\n"
-"You can use '//' at the start of the string to define a relative path."
-"Blender replaces that string by the directory of the current .blend or runtime file to make a full path name.\n"
-"The function also converts the directory separator to the local file system format."
-);
-static PyObject *gPyExpandPath(PyObject *, PyObject *args)
-{
- char expanded[FILE_MAX];
- char* filename;
-
- if (!PyArg_ParseTuple(args,"s:ExpandPath",&filename))
- return NULL;
-
- BLI_strncpy(expanded, filename, FILE_MAX);
- BLI_path_abs(expanded, gp_GamePythonPath);
- return PyC_UnicodeFromByte(expanded);
-}
-
-PyDoc_STRVAR(gPyStartGame_doc,
-"startGame(blend)\n"
-"Loads the blend file"
-);
-static PyObject *gPyStartGame(PyObject *, PyObject *args)
-{
- char* blendfile;
-
- if (!PyArg_ParseTuple(args, "s:startGame", &blendfile))
- return NULL;
-
- gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_START_OTHER_GAME);
- gp_KetsjiEngine->SetNameNextGame(blendfile);
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(gPyEndGame_doc,
-"endGame()\n"
-"Ends the current game"
-);
-static PyObject *gPyEndGame(PyObject *)
-{
- gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_QUIT_GAME);
-
- //printf("%s\n", gp_GamePythonPath);
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(gPyRestartGame_doc,
-"restartGame()\n"
-"Restarts the current game by reloading the .blend file"
-);
-static PyObject *gPyRestartGame(PyObject *)
-{
- gp_KetsjiEngine->RequestExit(KX_EXIT_REQUEST_RESTART_GAME);
- gp_KetsjiEngine->SetNameNextGame(gp_GamePythonPath);
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(gPySaveGlobalDict_doc,
-"saveGlobalDict()\n"
-"Saves bge.logic.globalDict to a file"
-);
-static PyObject *gPySaveGlobalDict(PyObject *)
-{
- char marshal_path[512];
- char *marshal_buffer = NULL;
- unsigned int marshal_length;
- FILE *fp = NULL;
-
- pathGamePythonConfig(marshal_path);
- marshal_length = saveGamePythonConfig(&marshal_buffer);
-
- if (marshal_length && marshal_buffer)
- {
- fp = fopen(marshal_path, "wb");
-
- if (fp)
- {
- if (fwrite(marshal_buffer, 1, marshal_length, fp) != marshal_length)
- printf("Warning: could not write marshal data\n");
-
- fclose(fp);
- } else {
- printf("Warning: could not open marshal file\n");
- }
- } else {
- printf("Warning: could not create marshal buffer\n");
- }
-
- if (marshal_buffer)
- delete [] marshal_buffer;
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(gPyLoadGlobalDict_doc,
-"LoadGlobalDict()\n"
-"Loads bge.logic.globalDict from a file"
-);
-static PyObject *gPyLoadGlobalDict(PyObject *)
-{
- char marshal_path[512];
- char *marshal_buffer = NULL;
- int marshal_length;
- FILE *fp = NULL;
- int result;
-
- pathGamePythonConfig(marshal_path);
-
- fp = fopen(marshal_path, "rb");
-
- if (fp) {
- // obtain file size:
- fseek (fp, 0, SEEK_END);
- marshal_length = ftell(fp);
- if (marshal_length == -1) {
- printf("Warning: could not read position of '%s'\n", marshal_path);
- fclose(fp);
- Py_RETURN_NONE;
- }
- rewind(fp);
-
- marshal_buffer = (char*)malloc (sizeof(char)*marshal_length);
-
- result = fread(marshal_buffer, 1, marshal_length, fp);
-
- if (result == marshal_length) {
- loadGamePythonConfig(marshal_buffer, marshal_length);
- } else {
- printf("Warning: could not read all of '%s'\n", marshal_path);
- }
-
- free(marshal_buffer);
- fclose(fp);
- } else {
- printf("Warning: could not open '%s'\n", marshal_path);
- }
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(gPyGetProfileInfo_doc,
-"getProfileInfo()\n"
-"returns a dictionary with profiling information"
-);
-static PyObject *gPyGetProfileInfo(PyObject *)
-{
- return gp_KetsjiEngine->GetPyProfileDict();
-}
-
-PyDoc_STRVAR(gPySendMessage_doc,
-"sendMessage(subject, [body, to, from])\n"
-"sends a message in same manner as a message actuator"
-" subject = Subject of the message"
-" body = Message body"
-" to = Name of object to send the message to"
-" from = Name of object to send the string from"
-);
-static PyObject *gPySendMessage(PyObject *, PyObject *args)
-{
- char* subject;
- char* body = (char *)"";
- char* to = (char *)"";
- char* from = (char *)"";
-
- if (!PyArg_ParseTuple(args, "s|sss:sendMessage", &subject, &body, &to, &from))
- return NULL;
-
- gp_KetsjiScene->GetNetworkScene()->SendMessage(to, from, subject, body);
-
- Py_RETURN_NONE;
-}
-
-// this gets a pointer to an array filled with floats
-static PyObject *gPyGetSpectrum(PyObject *)
-{
- PyObject *resultlist = PyList_New(512);
-
- for (int index = 0; index < 512; index++)
- {
- PyList_SET_ITEM(resultlist, index, PyFloat_FromDouble(0.0));
- }
-
- return resultlist;
-}
-
-static PyObject *gPySetLogicTicRate(PyObject *, PyObject *args)
-{
- float ticrate;
- if (!PyArg_ParseTuple(args, "f:setLogicTicRate", &ticrate))
- return NULL;
-
- KX_KetsjiEngine::SetTicRate(ticrate);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetLogicTicRate(PyObject *)
-{
- return PyFloat_FromDouble(KX_KetsjiEngine::GetTicRate());
-}
-
-static PyObject *gPySetExitKey(PyObject *, PyObject *args)
-{
- short exitkey;
- if (!PyArg_ParseTuple(args, "h:setExitKey", &exitkey))
- return NULL;
- KX_KetsjiEngine::SetExitKey(exitkey);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetExitKey(PyObject *)
-{
- return PyLong_FromLong(KX_KetsjiEngine::GetExitKey());
-}
-
-static PyObject *gPySetRender(PyObject *, PyObject *args)
-{
- int render;
- if (!PyArg_ParseTuple(args, "i:setRender", &render))
- return NULL;
- KX_KetsjiEngine::SetRender(render);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetRender(PyObject *)
-{
- return PyBool_FromLong(KX_KetsjiEngine::GetRender());
-}
-
-
-static PyObject *gPySetMaxLogicFrame(PyObject *, PyObject *args)
-{
- int frame;
- if (!PyArg_ParseTuple(args, "i:setMaxLogicFrame", &frame))
- return NULL;
-
- KX_KetsjiEngine::SetMaxLogicFrame(frame);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetMaxLogicFrame(PyObject *)
-{
- return PyLong_FromLong(KX_KetsjiEngine::GetMaxLogicFrame());
-}
-
-static PyObject *gPySetMaxPhysicsFrame(PyObject *, PyObject *args)
-{
- int frame;
- if (!PyArg_ParseTuple(args, "i:setMaxPhysicsFrame", &frame))
- return NULL;
-
- KX_KetsjiEngine::SetMaxPhysicsFrame(frame);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetMaxPhysicsFrame(PyObject *)
-{
- return PyLong_FromLong(KX_KetsjiEngine::GetMaxPhysicsFrame());
-}
-
-static PyObject *gPySetPhysicsTicRate(PyObject *, PyObject *args)
-{
- float ticrate;
- if (!PyArg_ParseTuple(args, "f:setPhysicsTicRate", &ticrate))
- return NULL;
-
- PHY_GetActiveEnvironment()->SetFixedTimeStep(true,ticrate);
- Py_RETURN_NONE;
-}
-#if 0 // unused
-static PyObject *gPySetPhysicsDebug(PyObject *, PyObject *args)
-{
- int debugMode;
- if (!PyArg_ParseTuple(args, "i:setPhysicsDebug", &debugMode))
- return NULL;
-
- PHY_GetActiveEnvironment()->setDebugMode(debugMode);
- Py_RETURN_NONE;
-}
-#endif
-
-
-static PyObject *gPyGetPhysicsTicRate(PyObject *)
-{
- return PyFloat_FromDouble(PHY_GetActiveEnvironment()->GetFixedTimeStep());
-}
-
-static PyObject *gPySetAnimRecordFrame(PyObject *, PyObject *args)
-{
- int anim_record_frame;
-
- if (!PyArg_ParseTuple(args, "i:setAnimRecordFrame", &anim_record_frame))
- return NULL;
-
- if (anim_record_frame < 0 && (U.flag & USER_NONEGFRAMES)) {
- PyErr_Format(PyExc_ValueError, "Frame number must be non-negative (was %i).", anim_record_frame);
- return NULL;
- }
-
- gp_KetsjiEngine->setAnimRecordFrame(anim_record_frame);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetAnimRecordFrame(PyObject *)
-{
- return PyLong_FromLong(gp_KetsjiEngine->getAnimRecordFrame());
-}
-
-static PyObject *gPyGetAverageFrameRate(PyObject *)
-{
- return PyFloat_FromDouble(KX_KetsjiEngine::GetAverageFrameRate());
-}
-
-static PyObject *gPyGetUseExternalClock(PyObject *)
-{
- return PyBool_FromLong(gp_KetsjiEngine->GetUseExternalClock());
-}
-
-static PyObject *gPySetUseExternalClock(PyObject *, PyObject *args)
-{
- bool bUseExternalClock;
-
- if (!PyArg_ParseTuple(args, "p:setUseExternalClock", &bUseExternalClock))
- return NULL;
-
- gp_KetsjiEngine->SetUseExternalClock(bUseExternalClock);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetClockTime(PyObject *)
-{
- return PyFloat_FromDouble(gp_KetsjiEngine->GetClockTime());
-}
-
-static PyObject *gPySetClockTime(PyObject *, PyObject *args)
-{
- double externalClockTime;
-
- if (!PyArg_ParseTuple(args, "d:setClockTime", &externalClockTime))
- return NULL;
-
- gp_KetsjiEngine->SetClockTime(externalClockTime);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetFrameTime(PyObject *)
-{
- return PyFloat_FromDouble(gp_KetsjiEngine->GetFrameTime());
-}
-
-static PyObject *gPyGetRealTime(PyObject *)
-{
- return PyFloat_FromDouble(gp_KetsjiEngine->GetRealTime());
-}
-
-static PyObject *gPyGetTimeScale(PyObject *)
-{
- return PyFloat_FromDouble(gp_KetsjiEngine->GetTimeScale());
-}
-
-static PyObject *gPySetTimeScale(PyObject *, PyObject *args)
-{
- double time_scale;
-
- if (!PyArg_ParseTuple(args, "d:setTimeScale", &time_scale))
- return NULL;
-
- gp_KetsjiEngine->SetTimeScale(time_scale);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetBlendFileList(PyObject *, PyObject *args)
-{
- char cpath[sizeof(gp_GamePythonPath)];
- char *searchpath = NULL;
- PyObject *list, *value;
-
- DIR *dp;
- struct dirent *dirp;
-
- if (!PyArg_ParseTuple(args, "|s:getBlendFileList", &searchpath))
- return NULL;
-
- list = PyList_New(0);
-
- if (searchpath) {
- BLI_strncpy(cpath, searchpath, FILE_MAX);
- BLI_path_abs(cpath, gp_GamePythonPath);
- } else {
- /* Get the dir only */
- BLI_split_dir_part(gp_GamePythonPath, cpath, sizeof(cpath));
- }
-
- if ((dp = opendir(cpath)) == NULL) {
- /* todo, show the errno, this shouldnt happen anyway if the blendfile is readable */
- fprintf(stderr, "Could not read directory (%s) failed, code %d (%s)\n", cpath, errno, strerror(errno));
- return list;
- }
-
- while ((dirp = readdir(dp)) != NULL) {
- if (BLI_testextensie(dirp->d_name, ".blend")) {
- value = PyC_UnicodeFromByte(dirp->d_name);
- PyList_Append(list, value);
- Py_DECREF(value);
- }
- }
-
- closedir(dp);
- return list;
-}
-
-PyDoc_STRVAR(gPyAddScene_doc,
-"addScene(name, [overlay])\n"
-"Adds a scene to the game engine.\n"
-" name = Name of the scene\n"
-" overlay = Overlay or underlay"
-);
-static PyObject *gPyAddScene(PyObject *, PyObject *args)
-{
- char* name;
- int overlay = 1;
-
- if (!PyArg_ParseTuple(args, "s|i:addScene", &name , &overlay))
- return NULL;
-
- gp_KetsjiEngine->ConvertAndAddScene(name, (overlay != 0));
-
- Py_RETURN_NONE;
-}
-
-PyDoc_STRVAR(gPyGetCurrentScene_doc,
-"getCurrentScene()\n"
-"Gets a reference to the current scene."
-);
-static PyObject *gPyGetCurrentScene(PyObject *self)
-{
- return gp_KetsjiScene->GetProxy();
-}
-
-PyDoc_STRVAR(gPyGetSceneList_doc,
-"getSceneList()\n"
-"Return a list of converted scenes."
-);
-static PyObject *gPyGetSceneList(PyObject *self)
-{
- KX_KetsjiEngine* m_engine = KX_GetActiveEngine();
- PyObject *list;
- KX_SceneList* scenes = m_engine->CurrentScenes();
- int numScenes = scenes->size();
- int i;
-
- list = PyList_New(numScenes);
-
- for (i=0;i<numScenes;i++)
- {
- KX_Scene* scene = scenes->at(i);
- PyList_SET_ITEM(list, i, scene->GetProxy());
- }
-
- return list;
-}
-
-static PyObject *pyPrintStats(PyObject *,PyObject *,PyObject *)
-{
- gp_KetsjiScene->GetSceneConverter()->PrintStats();
- Py_RETURN_NONE;
-}
-
-static PyObject *pyPrintExt(PyObject *,PyObject *,PyObject *)
-{
- if (gp_Rasterizer)
- gp_Rasterizer->PrintHardwareInfo();
- else
- printf("Warning: no rasterizer detected for PrintGLInfo!\n");
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gLibLoad(PyObject *, PyObject *args, PyObject *kwds)
-{
- KX_Scene *kx_scene= gp_KetsjiScene;
- char *path;
- char *group;
- Py_buffer py_buffer;
- py_buffer.buf = NULL;
- char *err_str= NULL;
- KX_LibLoadStatus *status = NULL;
-
- short options=0;
- int load_actions=0, verbose=0, load_scripts=1, async=0;
-
- static const char *kwlist[] = {"path", "group", "buffer", "load_actions", "verbose", "load_scripts", "async", NULL};
-
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "ss|y*iiIi:LibLoad", const_cast<char**>(kwlist),
- &path, &group, &py_buffer, &load_actions, &verbose, &load_scripts, &async))
- return NULL;
-
- /* setup options */
- if (load_actions != 0)
- options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_ACTIONS;
- if (verbose != 0)
- options |= KX_BlenderSceneConverter::LIB_LOAD_VERBOSE;
- if (load_scripts != 0)
- options |= KX_BlenderSceneConverter::LIB_LOAD_LOAD_SCRIPTS;
- if (async != 0)
- options |= KX_BlenderSceneConverter::LIB_LOAD_ASYNC;
-
- if (!py_buffer.buf)
- {
- char abs_path[FILE_MAX];
- // Make the path absolute
- BLI_strncpy(abs_path, path, sizeof(abs_path));
- BLI_path_abs(abs_path, gp_GamePythonPath);
-
- if ((status=kx_scene->GetSceneConverter()->LinkBlendFilePath(abs_path, group, kx_scene, &err_str, options))) {
- return status->GetProxy();
- }
- }
- else
- {
-
- if ((status=kx_scene->GetSceneConverter()->LinkBlendFileMemory(py_buffer.buf, py_buffer.len, path, group, kx_scene, &err_str, options))) {
- PyBuffer_Release(&py_buffer);
- return status->GetProxy();
- }
-
- PyBuffer_Release(&py_buffer);
- }
-
- if (err_str) {
- PyErr_SetString(PyExc_ValueError, err_str);
- return NULL;
- }
-
- Py_RETURN_FALSE;
-}
-
-static PyObject *gLibNew(PyObject *, PyObject *args)
-{
- KX_Scene *kx_scene= gp_KetsjiScene;
- char *path;
- char *group;
- const char *name;
- PyObject *names;
- int idcode;
-
- if (!PyArg_ParseTuple(args,"ssO!:LibNew",&path, &group, &PyList_Type, &names))
- return NULL;
-
- if (kx_scene->GetSceneConverter()->GetMainDynamicPath(path))
- {
- PyErr_SetString(PyExc_KeyError, "the name of the path given exists");
- return NULL;
- }
-
- idcode= BKE_idcode_from_name(group);
- if (idcode==0) {
- PyErr_Format(PyExc_ValueError, "invalid group given \"%s\"", group);
- return NULL;
- }
-
- Main *maggie=BKE_main_new();
- kx_scene->GetSceneConverter()->GetMainDynamic().push_back(maggie);
- strncpy(maggie->name, path, sizeof(maggie->name)-1);
-
- /* Copy the object into main */
- if (idcode==ID_ME) {
- PyObject *ret= PyList_New(0);
- PyObject *item;
- for (Py_ssize_t i= 0; i < PyList_GET_SIZE(names); i++) {
- name= _PyUnicode_AsString(PyList_GET_ITEM(names, i));
- if (name) {
- RAS_MeshObject *meshobj= kx_scene->GetSceneConverter()->ConvertMeshSpecial(kx_scene, maggie, name);
- if (meshobj) {
- KX_MeshProxy* meshproxy = new KX_MeshProxy(meshobj);
- item= meshproxy->NewProxy(true);
- PyList_Append(ret, item);
- Py_DECREF(item);
- }
- }
- else {
- PyErr_Clear(); /* wasnt a string, ignore for now */
- }
- }
-
- return ret;
- }
- else {
- PyErr_Format(PyExc_ValueError, "only \"Mesh\" group currently supported");
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gLibFree(PyObject *, PyObject *args)
-{
- KX_Scene *kx_scene= gp_KetsjiScene;
- char *path;
-
- if (!PyArg_ParseTuple(args,"s:LibFree",&path))
- return NULL;
-
- if (kx_scene->GetSceneConverter()->FreeBlendFile(path))
- {
- Py_RETURN_TRUE;
- }
- else {
- Py_RETURN_FALSE;
- }
-}
-
-static PyObject *gLibList(PyObject *, PyObject *args)
-{
- vector<Main*> &dynMaggie = gp_KetsjiScene->GetSceneConverter()->GetMainDynamic();
- int i= 0;
- PyObject *list= PyList_New(dynMaggie.size());
-
- for (vector<Main*>::iterator it=dynMaggie.begin(); !(it==dynMaggie.end()); it++)
- {
- PyList_SET_ITEM(list, i++, PyUnicode_FromString( (*it)->name) );
- }
-
- return list;
-}
-
-struct PyNextFrameState pynextframestate;
-static PyObject *gPyNextFrame(PyObject *)
-{
- if (pynextframestate.func == NULL) Py_RETURN_NONE;
- if (pynextframestate.state == NULL) Py_RETURN_NONE; //should never happen; raise exception instead?
-
- if (pynextframestate.func(pynextframestate.state)) //nonzero = stop
- {
- Py_RETURN_TRUE;
- }
- else // 0 = go on
- {
- Py_RETURN_FALSE;
- }
-}
-
-
-static struct PyMethodDef game_methods[] = {
- {"expandPath", (PyCFunction)gPyExpandPath, METH_VARARGS, (const char *)gPyExpandPath_doc},
- {"startGame", (PyCFunction)gPyStartGame, METH_VARARGS, (const char *)gPyStartGame_doc},
- {"endGame", (PyCFunction)gPyEndGame, METH_NOARGS, (const char *)gPyEndGame_doc},
- {"restartGame", (PyCFunction)gPyRestartGame, METH_NOARGS, (const char *)gPyRestartGame_doc},
- {"saveGlobalDict", (PyCFunction)gPySaveGlobalDict, METH_NOARGS, (const char *)gPySaveGlobalDict_doc},
- {"loadGlobalDict", (PyCFunction)gPyLoadGlobalDict, METH_NOARGS, (const char *)gPyLoadGlobalDict_doc},
- {"sendMessage", (PyCFunction)gPySendMessage, METH_VARARGS, (const char *)gPySendMessage_doc},
- {"getCurrentController", (PyCFunction) SCA_PythonController::sPyGetCurrentController, METH_NOARGS, SCA_PythonController::sPyGetCurrentController__doc__},
- {"getCurrentScene", (PyCFunction) gPyGetCurrentScene, METH_NOARGS, gPyGetCurrentScene_doc},
- {"getSceneList", (PyCFunction) gPyGetSceneList, METH_NOARGS, (const char *)gPyGetSceneList_doc},
- {"addScene", (PyCFunction)gPyAddScene, METH_VARARGS, (const char *)gPyAddScene_doc},
- {"getRandomFloat",(PyCFunction) gPyGetRandomFloat, METH_NOARGS, (const char *)gPyGetRandomFloat_doc},
- {"setGravity",(PyCFunction) gPySetGravity, METH_O, (const char *)"set Gravitation"},
- {"getSpectrum",(PyCFunction) gPyGetSpectrum, METH_NOARGS, (const char *)"get audio spectrum"},
- {"getMaxLogicFrame", (PyCFunction) gPyGetMaxLogicFrame, METH_NOARGS, (const char *)"Gets the max number of logic frame per render frame"},
- {"setMaxLogicFrame", (PyCFunction) gPySetMaxLogicFrame, METH_VARARGS, (const char *)"Sets the max number of logic frame per render frame"},
- {"getMaxPhysicsFrame", (PyCFunction) gPyGetMaxPhysicsFrame, METH_NOARGS, (const char *)"Gets the max number of physics frame per render frame"},
- {"setMaxPhysicsFrame", (PyCFunction) gPySetMaxPhysicsFrame, METH_VARARGS, (const char *)"Sets the max number of physics farme per render frame"},
- {"getLogicTicRate", (PyCFunction) gPyGetLogicTicRate, METH_NOARGS, (const char *)"Gets the logic tic rate"},
- {"setLogicTicRate", (PyCFunction) gPySetLogicTicRate, METH_VARARGS, (const char *)"Sets the logic tic rate"},
- {"getPhysicsTicRate", (PyCFunction) gPyGetPhysicsTicRate, METH_NOARGS, (const char *)"Gets the physics tic rate"},
- {"setPhysicsTicRate", (PyCFunction) gPySetPhysicsTicRate, METH_VARARGS, (const char *)"Sets the physics tic rate"},
- {"getAnimRecordFrame", (PyCFunction) gPyGetAnimRecordFrame, METH_NOARGS, (const char *)"Gets the current frame number used for animation recording"},
- {"setAnimRecordFrame", (PyCFunction) gPySetAnimRecordFrame, METH_VARARGS, (const char *)"Sets the current frame number used for animation recording"},
- {"getExitKey", (PyCFunction) gPyGetExitKey, METH_NOARGS, (const char *)"Gets the key used to exit the game engine"},
- {"setExitKey", (PyCFunction) gPySetExitKey, METH_VARARGS, (const char *)"Sets the key used to exit the game engine"},
- {"setRender", (PyCFunction) gPySetRender, METH_VARARGS, (const char *)"Set the global render flag"},
- {"getRender", (PyCFunction) gPyGetRender, METH_NOARGS, (const char *)"get the global render flag value"},
- {"getUseExternalClock", (PyCFunction) gPyGetUseExternalClock, METH_NOARGS, (const char *)"Get if we use the time provided by an external clock"},
- {"setUseExternalClock", (PyCFunction) gPySetUseExternalClock, METH_VARARGS, (const char *)"Set if we use the time provided by an external clock"},
- {"getClockTime", (PyCFunction) gPyGetClockTime, METH_NOARGS, (const char *)"Get the last BGE render time. "
- "The BGE render time is the simulated time corresponding to the next scene that will be renderered"},
- {"setClockTime", (PyCFunction) gPySetClockTime, METH_VARARGS, (const char *)"Set the BGE render time. "
- "The BGE render time is the simulated time corresponding to the next scene that will be rendered"},
- {"getFrameTime", (PyCFunction) gPyGetFrameTime, METH_NOARGS, (const char *)"Get the BGE last frametime. "
- "The BGE frame time is the simulated time corresponding to the last call of the logic system"},
- {"getRealTime", (PyCFunction) gPyGetRealTime, METH_NOARGS, (const char *)"Get the real system time. "
- "The real-time corresponds to the system time" },
- {"getAverageFrameRate", (PyCFunction) gPyGetAverageFrameRate, METH_NOARGS, (const char *)"Gets the estimated average frame rate"},
- {"getTimeScale", (PyCFunction) gPyGetTimeScale, METH_NOARGS, (const char *)"Get the time multiplier"},
- {"setTimeScale", (PyCFunction) gPySetTimeScale, METH_VARARGS, (const char *)"Set the time multiplier"},
- {"getBlendFileList", (PyCFunction)gPyGetBlendFileList, METH_VARARGS, (const char *)"Gets a list of blend files in the same directory as the current blend file"},
- {"PrintGLInfo", (PyCFunction)pyPrintExt, METH_NOARGS, (const char *)"Prints GL Extension Info"},
- {"PrintMemInfo", (PyCFunction)pyPrintStats, METH_NOARGS, (const char *)"Print engine statistics"},
- {"NextFrame", (PyCFunction)gPyNextFrame, METH_NOARGS, (const char *)"Render next frame (if Python has control)"},
- {"getProfileInfo", (PyCFunction)gPyGetProfileInfo, METH_NOARGS, gPyGetProfileInfo_doc},
- /* library functions */
- {"LibLoad", (PyCFunction)gLibLoad, METH_VARARGS|METH_KEYWORDS, (const char *)""},
- {"LibNew", (PyCFunction)gLibNew, METH_VARARGS, (const char *)""},
- {"LibFree", (PyCFunction)gLibFree, METH_VARARGS, (const char *)""},
- {"LibList", (PyCFunction)gLibList, METH_VARARGS, (const char *)""},
-
- {NULL, (PyCFunction) NULL, 0, NULL }
-};
-
-static PyObject *gPyGetWindowHeight(PyObject *, PyObject *args)
-{
- return PyLong_FromLong((gp_Canvas ? gp_Canvas->GetHeight() : 0));
-}
-
-
-
-static PyObject *gPyGetWindowWidth(PyObject *, PyObject *args)
-{
- return PyLong_FromLong((gp_Canvas ? gp_Canvas->GetWidth() : 0));
-}
-
-
-
-// temporarility visibility thing, will be moved to rasterizer/renderer later
-bool gUseVisibilityTemp = false;
-
-static PyObject *gPyEnableVisibility(PyObject *, PyObject *args)
-{
- int visible;
- if (!PyArg_ParseTuple(args,"i:enableVisibility",&visible))
- return NULL;
-
- gUseVisibilityTemp = (visible != 0);
- Py_RETURN_NONE;
-}
-
-
-
-static PyObject *gPyShowMouse(PyObject *, PyObject *args)
-{
- int visible;
- if (!PyArg_ParseTuple(args,"i:showMouse",&visible))
- return NULL;
-
- if (visible)
- {
- if (gp_Canvas)
- gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_NORMAL);
- } else
- {
- if (gp_Canvas)
- gp_Canvas->SetMouseState(RAS_ICanvas::MOUSE_INVISIBLE);
- }
-
- Py_RETURN_NONE;
-}
-
-
-
-static PyObject *gPySetMousePosition(PyObject *, PyObject *args)
-{
- int x,y;
- if (!PyArg_ParseTuple(args,"ii:setMousePosition",&x,&y))
- return NULL;
-
- if (gp_Canvas)
- gp_Canvas->SetMousePosition(x,y);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetEyeSeparation(PyObject *, PyObject *args)
-{
- float sep;
- if (!PyArg_ParseTuple(args, "f:setEyeSeparation", &sep))
- return NULL;
-
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setEyeSeparation(float), Rasterizer not available");
- return NULL;
- }
-
- gp_Rasterizer->SetEyeSeparation(sep);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetEyeSeparation(PyObject *)
-{
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getEyeSeparation(), Rasterizer not available");
- return NULL;
- }
-
- return PyFloat_FromDouble(gp_Rasterizer->GetEyeSeparation());
-}
-
-static PyObject *gPySetFocalLength(PyObject *, PyObject *args)
-{
- float focus;
- if (!PyArg_ParseTuple(args, "f:setFocalLength", &focus))
- return NULL;
-
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setFocalLength(float), Rasterizer not available");
- return NULL;
- }
-
- gp_Rasterizer->SetFocalLength(focus);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetFocalLength(PyObject *, PyObject *, PyObject *)
-{
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getFocalLength(), Rasterizer not available");
- return NULL;
- }
-
- return PyFloat_FromDouble(gp_Rasterizer->GetFocalLength());
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetStereoEye(PyObject *, PyObject *, PyObject *)
-{
- int flag = RAS_IRasterizer::RAS_STEREO_LEFTEYE;
-
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getStereoEye(), Rasterizer not available");
- return NULL;
- }
-
- if (gp_Rasterizer->Stereo())
- flag = gp_Rasterizer->GetEye();
-
- return PyLong_FromLong(flag);
-}
-
-static PyObject *gPySetBackgroundColor(PyObject *, PyObject *value)
-{
- MT_Vector4 vec;
- if (!PyVecTo(value, vec))
- return NULL;
-
- KX_WorldInfo *wi = gp_KetsjiScene->GetWorldInfo();
- if (!wi->hasWorld()) {
- PyErr_SetString(PyExc_RuntimeError, "bge.render.SetBackgroundColor(color), World not available");
- return NULL;
- }
-
- ShowDeprecationWarning("setBackgroundColor()", "KX_WorldInfo.background_color");
- wi->setBackColor((float)vec[0], (float)vec[1], (float)vec[2]);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyMakeScreenshot(PyObject *, PyObject *args)
-{
- char* filename;
- if (!PyArg_ParseTuple(args,"s:makeScreenshot",&filename))
- return NULL;
-
- if (gp_Canvas)
- {
- gp_Canvas->MakeScreenShot(filename);
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyEnableMotionBlur(PyObject *, PyObject *args)
-{
- float motionblurvalue;
- if (!PyArg_ParseTuple(args,"f:enableMotionBlur",&motionblurvalue))
- return NULL;
-
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.enableMotionBlur(float), Rasterizer not available");
- return NULL;
- }
-
- gp_Rasterizer->EnableMotionBlur(motionblurvalue);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyDisableMotionBlur(PyObject *)
-{
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.disableMotionBlur(), Rasterizer not available");
- return NULL;
- }
-
- gp_Rasterizer->DisableMotionBlur();
-
- Py_RETURN_NONE;
-}
-
-static int getGLSLSettingFlag(const char *setting)
-{
- if (strcmp(setting, "lights") == 0)
- return GAME_GLSL_NO_LIGHTS;
- else if (strcmp(setting, "shaders") == 0)
- return GAME_GLSL_NO_SHADERS;
- else if (strcmp(setting, "shadows") == 0)
- return GAME_GLSL_NO_SHADOWS;
- else if (strcmp(setting, "ramps") == 0)
- return GAME_GLSL_NO_RAMPS;
- else if (strcmp(setting, "nodes") == 0)
- return GAME_GLSL_NO_NODES;
- else if (strcmp(setting, "extra_textures") == 0)
- return GAME_GLSL_NO_EXTRA_TEX;
- else
- return -1;
-}
-
-static PyObject *gPySetGLSLMaterialSetting(PyObject *,
- PyObject *args,
- PyObject *)
-{
- GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
- char *setting;
- int enable, flag, sceneflag;
-
- if (!PyArg_ParseTuple(args,"si:setGLSLMaterialSetting",&setting,&enable))
- return NULL;
-
- flag = getGLSLSettingFlag(setting);
-
- if (flag == -1) {
- PyErr_SetString(PyExc_ValueError, "Rasterizer.setGLSLMaterialSetting(string): glsl setting is not known");
- return NULL;
- }
-
- sceneflag= gs->glslflag;
-
- if (enable)
- gs->glslflag &= ~flag;
- else
- gs->glslflag |= flag;
-
- /* display lists and GLSL materials need to be remade */
- if (sceneflag != gs->glslflag) {
- GPU_materials_free();
- if (gp_KetsjiEngine) {
- KX_SceneList *scenes = gp_KetsjiEngine->CurrentScenes();
- KX_SceneList::iterator it;
-
- for (it=scenes->begin(); it!=scenes->end(); it++) {
- // temporarily store the glsl settings in the scene for the GLSL materials
- (*it)->GetBlenderScene()->gm.flag = gs->glslflag;
- if ((*it)->GetBucketManager()) {
- (*it)->GetBucketManager()->ReleaseDisplayLists();
- (*it)->GetBucketManager()->ReleaseMaterials();
- }
- }
- }
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetGLSLMaterialSetting(PyObject *,
- PyObject *args,
- PyObject *)
-{
- GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
- char *setting;
- int enabled = 0, flag;
-
- if (!PyArg_ParseTuple(args,"s:getGLSLMaterialSetting",&setting))
- return NULL;
-
- flag = getGLSLSettingFlag(setting);
-
- if (flag == -1) {
- PyErr_SetString(PyExc_ValueError, "Rasterizer.getGLSLMaterialSetting(string): glsl setting is not known");
- return NULL;
- }
-
- enabled = ((gs->glslflag & flag) != 0);
- return PyLong_FromLong(enabled);
-}
-
-#define KX_BLENDER_MULTITEX_MATERIAL 1
-#define KX_BLENDER_GLSL_MATERIAL 2
-
-static PyObject *gPySetMaterialType(PyObject *,
- PyObject *args,
- PyObject *)
-{
- GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
- int type;
-
- if (!PyArg_ParseTuple(args,"i:setMaterialType",&type))
- return NULL;
-
- if (type == KX_BLENDER_GLSL_MATERIAL)
- gs->matmode= GAME_MAT_GLSL;
- else if (type == KX_BLENDER_MULTITEX_MATERIAL)
- gs->matmode= GAME_MAT_MULTITEX;
- else {
- PyErr_SetString(PyExc_ValueError, "Rasterizer.setMaterialType(int): material type is not known");
- return NULL;
- }
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetMaterialType(PyObject *)
-{
- GlobalSettings *gs= gp_KetsjiEngine->GetGlobalSettings();
- int flag;
-
- if (gs->matmode == GAME_MAT_GLSL)
- flag = KX_BLENDER_GLSL_MATERIAL;
- else
- flag = KX_BLENDER_MULTITEX_MATERIAL;
-
- return PyLong_FromLong(flag);
-}
-
-static PyObject *gPySetAnisotropicFiltering(PyObject *, PyObject *args)
-{
- short level;
-
- if (!PyArg_ParseTuple(args, "h:setAnisotropicFiltering", &level))
- return NULL;
-
- if (level != 1 && level != 2 && level != 4 && level != 8 && level != 16) {
- PyErr_SetString(PyExc_ValueError, "Rasterizer.setAnisotropicFiltering(level): Expected value of 1, 2, 4, 8, or 16 for value");
- return NULL;
- }
-
- gp_Rasterizer->SetAnisotropicFiltering(level);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetAnisotropicFiltering(PyObject *, PyObject *args)
-{
- return PyLong_FromLong(gp_Rasterizer->GetAnisotropicFiltering());
-}
-
-static PyObject *gPyDrawLine(PyObject *, PyObject *args)
-{
- PyObject *ob_from;
- PyObject *ob_to;
- PyObject *ob_color;
-
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.drawLine(obFrom, obTo, color): Rasterizer not available");
- return NULL;
- }
-
- if (!PyArg_ParseTuple(args,"OOO:drawLine",&ob_from,&ob_to,&ob_color))
- return NULL;
-
- MT_Vector3 from;
- MT_Vector3 to;
- MT_Vector3 color;
- if (!PyVecTo(ob_from, from))
- return NULL;
- if (!PyVecTo(ob_to, to))
- return NULL;
- if (!PyVecTo(ob_color, color))
- return NULL;
-
- gp_Rasterizer->DrawDebugLine(gp_KetsjiScene, from, to, color);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetWindowSize(PyObject *, PyObject *args)
-{
- int width, height;
- if (!PyArg_ParseTuple(args, "ii:resize", &width, &height))
- return NULL;
-
- gp_Canvas->ResizeWindow(width, height);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPySetFullScreen(PyObject *, PyObject *value)
-{
- gp_Canvas->SetFullScreen(PyObject_IsTrue(value));
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetFullScreen(PyObject *)
-{
- return PyBool_FromLong(gp_Canvas->GetFullScreen());
-}
-
-static PyObject *gPySetMipmapping(PyObject *, PyObject *args)
-{
- int val = 0;
-
- if (!PyArg_ParseTuple(args, "i:setMipmapping", &val))
- return NULL;
-
- if (val < 0 || val > RAS_IRasterizer::RAS_MIPMAP_MAX) {
- PyErr_SetString(PyExc_ValueError, "Rasterizer.setMipmapping(val): invalid mipmaping option");
- return NULL;
- }
-
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.setMipmapping(val): Rasterizer not available");
- return NULL;
- }
-
- gp_Rasterizer->SetMipmapping((RAS_IRasterizer::MipmapOption)val);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetMipmapping(PyObject *)
-{
- if (!gp_Rasterizer) {
- PyErr_SetString(PyExc_RuntimeError, "Rasterizer.getMipmapping(): Rasterizer not available");
- return NULL;
- }
- return PyLong_FromLong(gp_Rasterizer->GetMipmapping());
-}
-
-static PyObject *gPySetVsync(PyObject *, PyObject *args)
-{
- int interval;
-
- if (!PyArg_ParseTuple(args, "i:setVsync", &interval))
- return NULL;
-
- if (interval < 0 || interval > VSYNC_ADAPTIVE) {
- PyErr_SetString(PyExc_ValueError, "Rasterizer.setVsync(value): value must be VSYNC_OFF, VSYNC_ON, or VSYNC_ADAPTIVE");
- return NULL;
- }
-
- if (interval == VSYNC_ADAPTIVE)
- interval = -1;
- gp_Canvas->SetSwapInterval((interval == VSYNC_ON) ? 1 : 0);
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetVsync(PyObject *)
-{
- int interval = 0;
- gp_Canvas->GetSwapInterval(interval);
- return PyLong_FromLong(interval);
-}
-
-static PyObject *gPyShowFramerate(PyObject *, PyObject *args)
-{
- int visible;
- if (!PyArg_ParseTuple(args,"i:showFramerate",&visible))
- return NULL;
-
- if (visible && gp_KetsjiEngine)
- gp_KetsjiEngine->SetShowFramerate(true);
- else
- gp_KetsjiEngine->SetShowFramerate(false);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyShowProfile(PyObject *, PyObject *args)
-{
- int visible;
- if (!PyArg_ParseTuple(args,"i:showProfile",&visible))
- return NULL;
-
- if (visible && gp_KetsjiEngine)
- gp_KetsjiEngine->SetShowProfile(true);
- else
- gp_KetsjiEngine->SetShowProfile(false);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyShowProperties(PyObject *, PyObject *args)
-{
- int visible;
- if (!PyArg_ParseTuple(args,"i:showProperties",&visible))
- return NULL;
-
- if (visible && gp_KetsjiEngine)
- gp_KetsjiEngine->SetShowProperties(true);
- else
- gp_KetsjiEngine->SetShowProperties(false);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyAutoDebugList(PyObject *, PyObject *args)
-{
- int add;
- if (!PyArg_ParseTuple(args,"i:autoAddProperties",&add))
- return NULL;
-
- if (add && gp_KetsjiEngine)
- gp_KetsjiEngine->SetAutoAddDebugProperties(true);
- else
- gp_KetsjiEngine->SetAutoAddDebugProperties(false);
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyClearDebugList(PyObject *)
-{
- if (gp_KetsjiScene)
- gp_KetsjiScene->RemoveAllDebugProperties();
-
- Py_RETURN_NONE;
-}
-
-static PyObject *gPyGetDisplayDimensions(PyObject *)
-{
- PyObject *result;
- int width, height;
-
- gp_Canvas->GetDisplayDimensions(width, height);
-
- result = PyTuple_New(2);
- PyTuple_SET_ITEMS(result,
- PyLong_FromLong(width),
- PyLong_FromLong(height));
-
- return result;
-}
-
-
-/* python wrapper around RAS_IOffScreen
- * Should eventually gets its own file
- */
-
-static void PyRASOffScreen__tp_dealloc(PyRASOffScreen *self)
-{
- if (self->ofs)
- delete self->ofs;
- Py_TYPE(self)->tp_free((PyObject *)self);
-}
-
-PyDoc_STRVAR(py_RASOffScreen_doc,
-"RASOffscreen(width, height) -> new GPU Offscreen object"
-"initialized to hold a framebuffer object of ``width`` x ``height``.\n"
-""
-);
-
-PyDoc_STRVAR(RASOffScreen_width_doc, "Offscreen buffer width.\n\n:type: integer");
-static PyObject *RASOffScreen_width_get(PyRASOffScreen *self, void *UNUSED(type))
-{
- return PyLong_FromLong(self->ofs->GetWidth());
-}
-
-PyDoc_STRVAR(RASOffScreen_height_doc, "Offscreen buffer height.\n\n:type: GLsizei");
-static PyObject *RASOffScreen_height_get(PyRASOffScreen *self, void *UNUSED(type))
-{
- return PyLong_FromLong(self->ofs->GetHeight());
-}
-
-PyDoc_STRVAR(RASOffScreen_color_doc, "Offscreen buffer texture object (if target is RAS_OFS_RENDER_TEXTURE).\n\n:type: GLuint");
-static PyObject *RASOffScreen_color_get(PyRASOffScreen *self, void *UNUSED(type))
-{
- return PyLong_FromLong(self->ofs->GetColor());
-}
-
-static PyGetSetDef RASOffScreen_getseters[] = {
- {(char *)"width", (getter)RASOffScreen_width_get, (setter)NULL, RASOffScreen_width_doc, NULL},
- {(char *)"height", (getter)RASOffScreen_height_get, (setter)NULL, RASOffScreen_height_doc, NULL},
- {(char *)"color", (getter)RASOffScreen_color_get, (setter)NULL, RASOffScreen_color_doc, NULL},
- {NULL, NULL, NULL, NULL, NULL} /* Sentinel */
-};
-
-static int PyRASOffScreen__tp_init(PyRASOffScreen *self, PyObject *args, PyObject *kwargs)
-{
- int width, height, samples, target;
- const char *keywords[] = {"width", "height", "samples", "target", NULL};
-
- samples = 0;
- target = RAS_IOffScreen::RAS_OFS_RENDER_BUFFER;
- if (!PyArg_ParseTupleAndKeywords(args, kwargs, "ii|ii:RASOffscreen", (char **)keywords, &width, &height, &samples, &target)) {
- return -1;
- }
-
- if (width <= 0) {
- PyErr_SetString(PyExc_ValueError, "negative 'width' given");
- return -1;
- }
-
- if (height <= 0) {
- PyErr_SetString(PyExc_ValueError, "negative 'height' given");
- return -1;
- }
-
- if (samples < 0) {
- PyErr_SetString(PyExc_ValueError, "negative 'samples' given");
- return -1;
- }
-
- if (target != RAS_IOffScreen::RAS_OFS_RENDER_BUFFER && target != RAS_IOffScreen::RAS_OFS_RENDER_TEXTURE)
- {
- PyErr_SetString(PyExc_ValueError, "invalid 'target' given, can only be RAS_OFS_RENDER_BUFFER or RAS_OFS_RENDER_TEXTURE");
- return -1;
- }
- if (!gp_Rasterizer)
- {
- PyErr_SetString(PyExc_SystemError, "no rasterizer");
- return -1;
- }
- self->ofs = gp_Rasterizer->CreateOffScreen(width, height, samples, target);
- if (!self->ofs) {
- PyErr_SetString(PyExc_SystemError, "creation failed");
- return -1;
- }
- return 0;
-}
-
-PyTypeObject PyRASOffScreen_Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "RASOffScreen", /* tp_name */
- sizeof(PyRASOffScreen), /* tp_basicsize */
- 0, /* tp_itemsize */
- /* methods */
- (destructor)PyRASOffScreen__tp_dealloc, /* tp_dealloc */
- NULL, /* tp_print */
- NULL, /* tp_getattr */
- NULL, /* tp_setattr */
- NULL, /* tp_compare */
- NULL, /* tp_repr */
- NULL, /* tp_as_number */
- NULL, /* tp_as_sequence */
- NULL, /* tp_as_mapping */
- NULL, /* tp_hash */
- NULL, /* tp_call */
- NULL, /* tp_str */
- NULL, /* tp_getattro */
- NULL, /* tp_setattro */
- NULL, /* tp_as_buffer */
- Py_TPFLAGS_DEFAULT, /* tp_flags */
- py_RASOffScreen_doc, /* Documentation string */
- NULL, /* tp_traverse */
- NULL, /* tp_clear */
- NULL, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- NULL, /* tp_iter */
- NULL, /* tp_iternext */
- NULL, /* tp_methods */
- NULL, /* tp_members */
- RASOffScreen_getseters, /* tp_getset */
- NULL, /* tp_base */
- NULL, /* tp_dict */
- NULL, /* tp_descr_get */
- NULL, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PyRASOffScreen__tp_init, /* tp_init */
- (allocfunc)PyType_GenericAlloc, /* tp_alloc */
- (newfunc)PyType_GenericNew, /* tp_new */
- (freefunc)0, /* tp_free */
- NULL, /* tp_is_gc */
- NULL, /* tp_bases */
- NULL, /* tp_mro */
- NULL, /* tp_cache */
- NULL, /* tp_subclasses */
- NULL, /* tp_weaklist */
- (destructor) NULL /* tp_del */
-};
-
-
-static PyObject *gPyOffScreenCreate(PyObject *UNUSED(self), PyObject *args)
-{
- int width;
- int height;
- int samples;
- int target;
-
- samples = 0;
- if (!PyArg_ParseTuple(args, "ii|ii:offScreenCreate", &width, &height, &samples, &target))
- return NULL;
-
- return PyObject_CallObject((PyObject *) &PyRASOffScreen_Type, args);
-}
-
-PyDoc_STRVAR(Rasterizer_module_documentation,
-"This is the Python API for the game engine of Rasterizer"
-);
-
-static struct PyMethodDef rasterizer_methods[] = {
- {"getWindowWidth",(PyCFunction) gPyGetWindowWidth,
- METH_VARARGS, "getWindowWidth doc"},
- {"getWindowHeight",(PyCFunction) gPyGetWindowHeight,
- METH_VARARGS, "getWindowHeight doc"},
- {"makeScreenshot",(PyCFunction)gPyMakeScreenshot,
- METH_VARARGS, "make Screenshot doc"},
- {"enableVisibility",(PyCFunction) gPyEnableVisibility,
- METH_VARARGS, "enableVisibility doc"},
- {"showMouse",(PyCFunction) gPyShowMouse,
- METH_VARARGS, "showMouse(bool visible)"},
- {"setMousePosition",(PyCFunction) gPySetMousePosition,
- METH_VARARGS, "setMousePosition(int x,int y)"},
- {"setBackgroundColor",(PyCFunction)gPySetBackgroundColor,METH_O,"set Background Color (rgb)"},
- {"enableMotionBlur",(PyCFunction)gPyEnableMotionBlur,METH_VARARGS,"enable motion blur"},
- {"disableMotionBlur",(PyCFunction)gPyDisableMotionBlur,METH_NOARGS,"disable motion blur"},
-
- {"setEyeSeparation", (PyCFunction) gPySetEyeSeparation, METH_VARARGS, "set the eye separation for stereo mode"},
- {"getEyeSeparation", (PyCFunction) gPyGetEyeSeparation, METH_NOARGS, "get the eye separation for stereo mode"},
- {"setFocalLength", (PyCFunction) gPySetFocalLength, METH_VARARGS, "set the focal length for stereo mode"},
- {"getFocalLength", (PyCFunction) gPyGetFocalLength, METH_VARARGS, "get the focal length for stereo mode"},
- {"getStereoEye", (PyCFunction) gPyGetStereoEye, METH_VARARGS, "get the current stereoscopy eye being rendered"},
- {"setMaterialMode",(PyCFunction) gPySetMaterialType,
- METH_VARARGS, "set the material mode to use for OpenGL rendering"},
- {"getMaterialMode",(PyCFunction) gPyGetMaterialType,
- METH_NOARGS, "get the material mode being used for OpenGL rendering"},
- {"setGLSLMaterialSetting",(PyCFunction) gPySetGLSLMaterialSetting,
- METH_VARARGS, "set the state of a GLSL material setting"},
- {"getGLSLMaterialSetting",(PyCFunction) gPyGetGLSLMaterialSetting,
- METH_VARARGS, "get the state of a GLSL material setting"},
- {"setAnisotropicFiltering", (PyCFunction) gPySetAnisotropicFiltering,
- METH_VARARGS, "set the anisotropic filtering level (must be one of 1, 2, 4, 8, 16)"},
- {"getAnisotropicFiltering", (PyCFunction) gPyGetAnisotropicFiltering,
- METH_VARARGS, "get the anisotropic filtering level"},
- {"drawLine", (PyCFunction) gPyDrawLine,
- METH_VARARGS, "draw a line on the screen"},
- {"setWindowSize", (PyCFunction) gPySetWindowSize, METH_VARARGS, ""},
- {"setFullScreen", (PyCFunction) gPySetFullScreen, METH_O, ""},
- {"getFullScreen", (PyCFunction) gPyGetFullScreen, METH_NOARGS, ""},
- {"getDisplayDimensions", (PyCFunction) gPyGetDisplayDimensions, METH_NOARGS,
- "Get the actual dimensions, in pixels, of the physical display (e.g., the monitor)."},
- {"setMipmapping", (PyCFunction) gPySetMipmapping, METH_VARARGS, ""},
- {"getMipmapping", (PyCFunction) gPyGetMipmapping, METH_NOARGS, ""},
- {"setVsync", (PyCFunction) gPySetVsync, METH_VARARGS, ""},
- {"getVsync", (PyCFunction) gPyGetVsync, METH_NOARGS, ""},
- {"showFramerate",(PyCFunction) gPyShowFramerate, METH_VARARGS, "show or hide the framerate"},
- {"showProfile",(PyCFunction) gPyShowProfile, METH_VARARGS, "show or hide the profile"},
- {"showProperties",(PyCFunction) gPyShowProperties, METH_VARARGS, "show or hide the debug properties"},
- {"autoDebugList",(PyCFunction) gPyAutoDebugList, METH_VARARGS, "enable or disable auto adding debug properties to the debug list"},
- {"clearDebugList",(PyCFunction) gPyClearDebugList, METH_NOARGS, "clears the debug property list"},
- {"offScreenCreate", (PyCFunction) gPyOffScreenCreate, METH_VARARGS, "create an offscreen buffer object, arguments are width and height in pixels"},
- { NULL, (PyCFunction) NULL, 0, NULL }
-};
-
-
-
-PyDoc_STRVAR(GameLogic_module_documentation,
-"This is the Python API for the game engine of bge.logic"
-);
-
-static struct PyModuleDef GameLogic_module_def = {
- {}, /* m_base */
- "GameLogic", /* m_name */
- GameLogic_module_documentation, /* m_doc */
- 0, /* m_size */
- game_methods, /* m_methods */
- 0, /* m_reload */
- 0, /* m_traverse */
- 0, /* m_clear */
- 0, /* m_free */
-};
-
-PyMODINIT_FUNC initGameLogicPythonBinding()
-{
- PyObject *m;
- PyObject *d;
- PyObject *item; /* temp PyObject *storage */
-
- gUseVisibilityTemp=false;
-
- PyObjectPlus::ClearDeprecationWarning(); /* Not that nice to call here but makes sure warnings are reset between loading scenes */
-
- m = PyModule_Create(&GameLogic_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), GameLogic_module_def.m_name, m);
-
-
- // Add some symbolic constants to the module
- d = PyModule_GetDict(m);
-
- // can be overwritten later for gameEngine instances that can load new blend files and re-initialize this module
- // for now its safe to make sure it exists for other areas such as the web plugin
-
- PyDict_SetItemString(d, "globalDict", item=PyDict_New()); Py_DECREF(item);
-
- // Add keyboard and mouse attributes to this module
- MT_assert(!gp_PythonKeyboard);
- gp_PythonKeyboard = new SCA_PythonKeyboard(gp_KetsjiEngine->GetKeyboardDevice());
- PyDict_SetItemString(d, "keyboard", gp_PythonKeyboard->NewProxy(true));
-
- MT_assert(!gp_PythonMouse);
- gp_PythonMouse = new SCA_PythonMouse(gp_KetsjiEngine->GetMouseDevice(), gp_Canvas);
- PyDict_SetItemString(d, "mouse", gp_PythonMouse->NewProxy(true));
-
- PyObject* joylist = PyList_New(JOYINDEX_MAX);
- for (int i=0; i<JOYINDEX_MAX; ++i) {
- SCA_Joystick *joy = SCA_Joystick::GetInstance(i);
- PyObject *item;
-
- if (joy && joy->Connected()) {
- gp_PythonJoysticks[i] = new SCA_PythonJoystick(joy);
- item = gp_PythonJoysticks[i]->NewProxy(true);
- }
- else {
- if (joy) {
- joy->ReleaseInstance();
- }
- item = Py_None;
- }
-
- Py_INCREF(item);
- PyList_SET_ITEM(joylist, i, item);
- }
- PyDict_SetItemString(d, "joysticks", joylist);
-
- ErrorObject = PyUnicode_FromString("GameLogic.error");
- PyDict_SetItemString(d, "error", ErrorObject);
- Py_DECREF(ErrorObject);
-
- // XXXX Add constants here
- /* To use logic bricks, we need some sort of constants. Here, we associate */
- /* constants and sumbolic names. Add them to dictionary d. */
-
- /* 1. true and false: needed for everyone */
- KX_MACRO_addTypesToDict(d, KX_TRUE, SCA_ILogicBrick::KX_TRUE);
- KX_MACRO_addTypesToDict(d, KX_FALSE, SCA_ILogicBrick::KX_FALSE);
-
- /* 2. Property sensor */
- KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EQUAL, SCA_PropertySensor::KX_PROPSENSOR_EQUAL);
- KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_NOTEQUAL, SCA_PropertySensor::KX_PROPSENSOR_NOTEQUAL);
- KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_INTERVAL, SCA_PropertySensor::KX_PROPSENSOR_INTERVAL);
- KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_CHANGED, SCA_PropertySensor::KX_PROPSENSOR_CHANGED);
- KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_EXPRESSION, SCA_PropertySensor::KX_PROPSENSOR_EXPRESSION);
- KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_LESSTHAN, SCA_PropertySensor::KX_PROPSENSOR_LESSTHAN);
- KX_MACRO_addTypesToDict(d, KX_PROPSENSOR_GREATERTHAN, SCA_PropertySensor::KX_PROPSENSOR_GREATERTHAN);
-
- /* 3. Constraint actuator */
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCX);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCY);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCZ);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTX);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTY);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ROTZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ROTZ);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPX);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPY);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRPZ);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNX);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNY);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DIRNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DIRNZ);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIX);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIY);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_ORIZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_ORIZ);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPX);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPY);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHPZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHPZ);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNX, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNX);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNY, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNY);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_FHNZ, KX_ConstraintActuator::KX_ACT_CONSTRAINT_FHNZ);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_NORMAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_NORMAL);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_MATERIAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_MATERIAL);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_PERMANENT, KX_ConstraintActuator::KX_ACT_CONSTRAINT_PERMANENT);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DISTANCE, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DISTANCE);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_LOCAL, KX_ConstraintActuator::KX_ACT_CONSTRAINT_LOCAL);
- KX_MACRO_addTypesToDict(d, KX_CONSTRAINTACT_DOROTFH, KX_ConstraintActuator::KX_ACT_CONSTRAINT_DOROTFH);
-
- /* 4. Random distribution types */
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_CONST, SCA_RandomActuator::KX_RANDOMACT_BOOL_CONST);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_UNIFORM, SCA_RandomActuator::KX_RANDOMACT_BOOL_UNIFORM);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_BOOL_BERNOUILLI, SCA_RandomActuator::KX_RANDOMACT_BOOL_BERNOUILLI);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_CONST, SCA_RandomActuator::KX_RANDOMACT_INT_CONST);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_UNIFORM, SCA_RandomActuator::KX_RANDOMACT_INT_UNIFORM);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_INT_POISSON, SCA_RandomActuator::KX_RANDOMACT_INT_POISSON);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_CONST, SCA_RandomActuator::KX_RANDOMACT_FLOAT_CONST);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_UNIFORM, SCA_RandomActuator::KX_RANDOMACT_FLOAT_UNIFORM);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NORMAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NORMAL);
- KX_MACRO_addTypesToDict(d, KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL, SCA_RandomActuator::KX_RANDOMACT_FLOAT_NEGATIVE_EXPONENTIAL);
-
- /* 5. Sound actuator */
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP, KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND, KX_SoundActuator::KX_SOUNDACT_PLAYEND);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP, KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND, KX_SoundActuator::KX_SOUNDACT_LOOPEND);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
-
- /* 6. Action actuator */
- KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PLAY, ACT_ACTION_PLAY);
- KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PINGPONG, ACT_ACTION_PINGPONG);
- KX_MACRO_addTypesToDict(d, KX_ACTIONACT_FLIPPER, ACT_ACTION_FLIPPER);
- KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPSTOP, ACT_ACTION_LOOP_STOP);
- KX_MACRO_addTypesToDict(d, KX_ACTIONACT_LOOPEND, ACT_ACTION_LOOP_END);
- KX_MACRO_addTypesToDict(d, KX_ACTIONACT_PROPERTY, ACT_ACTION_FROM_PROP);
-
- /* 7. GL_BlendFunc */
- KX_MACRO_addTypesToDict(d, BL_ZERO, GL_ZERO);
- KX_MACRO_addTypesToDict(d, BL_ONE, GL_ONE);
- KX_MACRO_addTypesToDict(d, BL_SRC_COLOR, GL_SRC_COLOR);
- KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR);
- KX_MACRO_addTypesToDict(d, BL_DST_COLOR, GL_DST_COLOR);
- KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_COLOR, GL_ONE_MINUS_DST_COLOR);
- KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA, GL_SRC_ALPHA);
- KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- KX_MACRO_addTypesToDict(d, BL_DST_ALPHA, GL_DST_ALPHA);
- KX_MACRO_addTypesToDict(d, BL_ONE_MINUS_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA);
- KX_MACRO_addTypesToDict(d, BL_SRC_ALPHA_SATURATE, GL_SRC_ALPHA_SATURATE);
-
-
- /* 8. UniformTypes */
- KX_MACRO_addTypesToDict(d, SHD_TANGENT, BL_Shader::SHD_TANGENT);
- KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX, BL_Shader::MODELVIEWMATRIX);
- KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_TRANSPOSE, BL_Shader::MODELVIEWMATRIX_TRANSPOSE);
- KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSE, BL_Shader::MODELVIEWMATRIX_INVERSE);
- KX_MACRO_addTypesToDict(d, MODELVIEWMATRIX_INVERSETRANSPOSE, BL_Shader::MODELVIEWMATRIX_INVERSETRANSPOSE);
- KX_MACRO_addTypesToDict(d, MODELMATRIX, BL_Shader::MODELMATRIX);
- KX_MACRO_addTypesToDict(d, MODELMATRIX_TRANSPOSE, BL_Shader::MODELMATRIX_TRANSPOSE);
- KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSE, BL_Shader::MODELMATRIX_INVERSE);
- KX_MACRO_addTypesToDict(d, MODELMATRIX_INVERSETRANSPOSE, BL_Shader::MODELMATRIX_INVERSETRANSPOSE);
- KX_MACRO_addTypesToDict(d, VIEWMATRIX, BL_Shader::VIEWMATRIX);
- KX_MACRO_addTypesToDict(d, VIEWMATRIX_TRANSPOSE, BL_Shader::VIEWMATRIX_TRANSPOSE);
- KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSE, BL_Shader::VIEWMATRIX_INVERSE);
- KX_MACRO_addTypesToDict(d, VIEWMATRIX_INVERSETRANSPOSE, BL_Shader::VIEWMATRIX_INVERSETRANSPOSE);
- KX_MACRO_addTypesToDict(d, CAM_POS, BL_Shader::CAM_POS);
- KX_MACRO_addTypesToDict(d, CONSTANT_TIMER, BL_Shader::CONSTANT_TIMER);
-
- /* 9. state actuator */
- KX_MACRO_addTypesToDict(d, KX_STATE1, (1<<0));
- KX_MACRO_addTypesToDict(d, KX_STATE2, (1<<1));
- KX_MACRO_addTypesToDict(d, KX_STATE3, (1<<2));
- KX_MACRO_addTypesToDict(d, KX_STATE4, (1<<3));
- KX_MACRO_addTypesToDict(d, KX_STATE5, (1<<4));
- KX_MACRO_addTypesToDict(d, KX_STATE6, (1<<5));
- KX_MACRO_addTypesToDict(d, KX_STATE7, (1<<6));
- KX_MACRO_addTypesToDict(d, KX_STATE8, (1<<7));
- KX_MACRO_addTypesToDict(d, KX_STATE9, (1<<8));
- KX_MACRO_addTypesToDict(d, KX_STATE10, (1<<9));
- KX_MACRO_addTypesToDict(d, KX_STATE11, (1<<10));
- KX_MACRO_addTypesToDict(d, KX_STATE12, (1<<11));
- KX_MACRO_addTypesToDict(d, KX_STATE13, (1<<12));
- KX_MACRO_addTypesToDict(d, KX_STATE14, (1<<13));
- KX_MACRO_addTypesToDict(d, KX_STATE15, (1<<14));
- KX_MACRO_addTypesToDict(d, KX_STATE16, (1<<15));
- KX_MACRO_addTypesToDict(d, KX_STATE17, (1<<16));
- KX_MACRO_addTypesToDict(d, KX_STATE18, (1<<17));
- KX_MACRO_addTypesToDict(d, KX_STATE19, (1<<18));
- KX_MACRO_addTypesToDict(d, KX_STATE20, (1<<19));
- KX_MACRO_addTypesToDict(d, KX_STATE21, (1<<20));
- KX_MACRO_addTypesToDict(d, KX_STATE22, (1<<21));
- KX_MACRO_addTypesToDict(d, KX_STATE23, (1<<22));
- KX_MACRO_addTypesToDict(d, KX_STATE24, (1<<23));
- KX_MACRO_addTypesToDict(d, KX_STATE25, (1<<24));
- KX_MACRO_addTypesToDict(d, KX_STATE26, (1<<25));
- KX_MACRO_addTypesToDict(d, KX_STATE27, (1<<26));
- KX_MACRO_addTypesToDict(d, KX_STATE28, (1<<27));
- KX_MACRO_addTypesToDict(d, KX_STATE29, (1<<28));
- KX_MACRO_addTypesToDict(d, KX_STATE30, (1<<29));
-
- /* All Sensors */
- KX_MACRO_addTypesToDict(d, KX_SENSOR_JUST_ACTIVATED, SCA_ISensor::KX_SENSOR_JUST_ACTIVATED);
- KX_MACRO_addTypesToDict(d, KX_SENSOR_ACTIVE, SCA_ISensor::KX_SENSOR_ACTIVE);
- KX_MACRO_addTypesToDict(d, KX_SENSOR_JUST_DEACTIVATED, SCA_ISensor::KX_SENSOR_JUST_DEACTIVATED);
- KX_MACRO_addTypesToDict(d, KX_SENSOR_INACTIVE, SCA_ISensor::KX_SENSOR_INACTIVE);
-
- /* Radar Sensor */
- KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_X, KX_RadarSensor::KX_RADAR_AXIS_POS_X);
- KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Y, KX_RadarSensor::KX_RADAR_AXIS_POS_Y);
- KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_POS_Z, KX_RadarSensor::KX_RADAR_AXIS_POS_Z);
- KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_X, KX_RadarSensor::KX_RADAR_AXIS_NEG_X);
- KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Y, KX_RadarSensor::KX_RADAR_AXIS_NEG_Y);
- KX_MACRO_addTypesToDict(d, KX_RADAR_AXIS_NEG_Z, KX_RadarSensor::KX_RADAR_AXIS_NEG_Z);
-
- /* Ray Sensor */
- KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_X, KX_RaySensor::KX_RAY_AXIS_POS_X);
- KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_Y, KX_RaySensor::KX_RAY_AXIS_POS_Y);
- KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_POS_Z, KX_RaySensor::KX_RAY_AXIS_POS_Z);
- KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_X, KX_RaySensor::KX_RAY_AXIS_NEG_X);
- KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Y, KX_RaySensor::KX_RAY_AXIS_NEG_Y);
- KX_MACRO_addTypesToDict(d, KX_RAY_AXIS_NEG_Z, KX_RaySensor::KX_RAY_AXIS_NEG_Z);
-
- /* TrackTo Actuator */
- KX_MACRO_addTypesToDict(d, KX_TRACK_UPAXIS_POS_X, KX_TrackToActuator::KX_TRACK_UPAXIS_POS_X);
- KX_MACRO_addTypesToDict(d, KX_TRACK_UPAXIS_POS_Y, KX_TrackToActuator::KX_TRACK_UPAXIS_POS_Y);
- KX_MACRO_addTypesToDict(d, KX_TRACK_UPAXIS_POS_Z, KX_TrackToActuator::KX_TRACK_UPAXIS_POS_Z);
- KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_POS_X, KX_TrackToActuator::KX_TRACK_TRAXIS_POS_X);
- KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_POS_Y, KX_TrackToActuator::KX_TRACK_TRAXIS_POS_Y);
- KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_POS_Z, KX_TrackToActuator::KX_TRACK_TRAXIS_POS_Z);
- KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_NEG_X, KX_TrackToActuator::KX_TRACK_TRAXIS_NEG_X);
- KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_NEG_Y, KX_TrackToActuator::KX_TRACK_TRAXIS_NEG_Y);
- KX_MACRO_addTypesToDict(d, KX_TRACK_TRAXIS_NEG_Z, KX_TrackToActuator::KX_TRACK_TRAXIS_NEG_Z);
-
- /* Dynamic actuator */
- KX_MACRO_addTypesToDict(d, KX_DYN_RESTORE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_RESTORE_DYNAMICS);
- KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_DYNAMICS, KX_SCA_DynamicActuator::KX_DYN_DISABLE_DYNAMICS);
- KX_MACRO_addTypesToDict(d, KX_DYN_ENABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_ENABLE_RIGID_BODY);
- KX_MACRO_addTypesToDict(d, KX_DYN_DISABLE_RIGID_BODY, KX_SCA_DynamicActuator::KX_DYN_DISABLE_RIGID_BODY);
- KX_MACRO_addTypesToDict(d, KX_DYN_SET_MASS, KX_SCA_DynamicActuator::KX_DYN_SET_MASS);
-
- /* Input & Mouse Sensor */
- KX_MACRO_addTypesToDict(d, KX_INPUT_NONE, SCA_InputEvent::KX_NO_INPUTSTATUS);
- KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_ACTIVATED, SCA_InputEvent::KX_JUSTACTIVATED);
- KX_MACRO_addTypesToDict(d, KX_INPUT_ACTIVE, SCA_InputEvent::KX_ACTIVE);
- KX_MACRO_addTypesToDict(d, KX_INPUT_JUST_RELEASED, SCA_InputEvent::KX_JUSTRELEASED);
-
- KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_LEFT, SCA_IInputDevice::KX_LEFTMOUSE);
- KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_MIDDLE, SCA_IInputDevice::KX_MIDDLEMOUSE);
- KX_MACRO_addTypesToDict(d, KX_MOUSE_BUT_RIGHT, SCA_IInputDevice::KX_RIGHTMOUSE);
-
- /* 2D Filter Actuator */
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_ENABLED, RAS_2DFilterManager::RAS_2DFILTER_ENABLED);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_DISABLED, RAS_2DFilterManager::RAS_2DFILTER_DISABLED);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_NOFILTER, RAS_2DFilterManager::RAS_2DFILTER_NOFILTER);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_MOTIONBLUR, RAS_2DFilterManager::RAS_2DFILTER_MOTIONBLUR);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_BLUR, RAS_2DFilterManager::RAS_2DFILTER_BLUR);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SHARPEN, RAS_2DFilterManager::RAS_2DFILTER_SHARPEN);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_DILATION, RAS_2DFilterManager::RAS_2DFILTER_DILATION);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_EROSION, RAS_2DFilterManager::RAS_2DFILTER_EROSION);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_LAPLACIAN, RAS_2DFilterManager::RAS_2DFILTER_LAPLACIAN);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SOBEL, RAS_2DFilterManager::RAS_2DFILTER_SOBEL);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_PREWITT, RAS_2DFilterManager::RAS_2DFILTER_PREWITT);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_GRAYSCALE, RAS_2DFilterManager::RAS_2DFILTER_GRAYSCALE);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_SEPIA, RAS_2DFilterManager::RAS_2DFILTER_SEPIA);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_INVERT, RAS_2DFilterManager::RAS_2DFILTER_INVERT);
- KX_MACRO_addTypesToDict(d, RAS_2DFILTER_CUSTOMFILTER, RAS_2DFilterManager::RAS_2DFILTER_CUSTOMFILTER);
-
- /* Sound Actuator */
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYSTOP, KX_SoundActuator::KX_SOUNDACT_PLAYSTOP);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_PLAYEND, KX_SoundActuator::KX_SOUNDACT_PLAYEND);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPSTOP, KX_SoundActuator::KX_SOUNDACT_LOOPSTOP);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPEND, KX_SoundActuator:: KX_SOUNDACT_LOOPEND);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL);
- KX_MACRO_addTypesToDict(d, KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP, KX_SoundActuator::KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP);
-
- /* State Actuator */
- KX_MACRO_addTypesToDict(d, KX_STATE_OP_CPY, KX_StateActuator::OP_CPY);
- KX_MACRO_addTypesToDict(d, KX_STATE_OP_SET, KX_StateActuator::OP_SET);
- KX_MACRO_addTypesToDict(d, KX_STATE_OP_CLR, KX_StateActuator::OP_CLR);
- KX_MACRO_addTypesToDict(d, KX_STATE_OP_NEG, KX_StateActuator::OP_NEG);
-
- /* Game Actuator Modes */
- KX_MACRO_addTypesToDict(d, KX_GAME_LOAD, KX_GameActuator::KX_GAME_LOAD);
- KX_MACRO_addTypesToDict(d, KX_GAME_START, KX_GameActuator::KX_GAME_START);
- KX_MACRO_addTypesToDict(d, KX_GAME_RESTART, KX_GameActuator::KX_GAME_RESTART);
- KX_MACRO_addTypesToDict(d, KX_GAME_QUIT, KX_GameActuator::KX_GAME_QUIT);
- KX_MACRO_addTypesToDict(d, KX_GAME_SAVECFG, KX_GameActuator::KX_GAME_SAVECFG);
- KX_MACRO_addTypesToDict(d, KX_GAME_LOADCFG, KX_GameActuator::KX_GAME_LOADCFG);
- KX_MACRO_addTypesToDict(d, KX_GAME_SCREENSHOT, KX_GameActuator::KX_GAME_SCREENSHOT);
-
- /* Scene Actuator Modes */
- KX_MACRO_addTypesToDict(d, KX_SCENE_RESTART, KX_SceneActuator::KX_SCENE_RESTART);
- KX_MACRO_addTypesToDict(d, KX_SCENE_SET_SCENE, KX_SceneActuator::KX_SCENE_SET_SCENE);
- KX_MACRO_addTypesToDict(d, KX_SCENE_SET_CAMERA, KX_SceneActuator::KX_SCENE_SET_CAMERA);
- KX_MACRO_addTypesToDict(d, KX_SCENE_ADD_FRONT_SCENE, KX_SceneActuator::KX_SCENE_ADD_FRONT_SCENE);
- KX_MACRO_addTypesToDict(d, KX_SCENE_ADD_BACK_SCENE, KX_SceneActuator::KX_SCENE_ADD_BACK_SCENE);
- KX_MACRO_addTypesToDict(d, KX_SCENE_REMOVE_SCENE, KX_SceneActuator::KX_SCENE_REMOVE_SCENE);
- KX_MACRO_addTypesToDict(d, KX_SCENE_SUSPEND, KX_SceneActuator::KX_SCENE_SUSPEND);
- KX_MACRO_addTypesToDict(d, KX_SCENE_RESUME, KX_SceneActuator::KX_SCENE_RESUME);
-
- /* Parent Actuator Modes */
- KX_MACRO_addTypesToDict(d, KX_PARENT_SET, KX_ParentActuator::KX_PARENT_SET);
- KX_MACRO_addTypesToDict(d, KX_PARENT_REMOVE, KX_ParentActuator::KX_PARENT_REMOVE);
-
- /* BL_ArmatureConstraint type */
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_TRACKTO, CONSTRAINT_TYPE_TRACKTO);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_KINEMATIC, CONSTRAINT_TYPE_KINEMATIC);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_ROTLIKE, CONSTRAINT_TYPE_ROTLIKE);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_LOCLIKE, CONSTRAINT_TYPE_LOCLIKE);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_MINMAX, CONSTRAINT_TYPE_MINMAX);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_SIZELIKE, CONSTRAINT_TYPE_SIZELIKE);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_LOCKTRACK, CONSTRAINT_TYPE_LOCKTRACK);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_STRETCHTO, CONSTRAINT_TYPE_STRETCHTO);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_CLAMPTO, CONSTRAINT_TYPE_CLAMPTO);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_TRANSFORM, CONSTRAINT_TYPE_TRANSFORM);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_TYPE_DISTLIMIT, CONSTRAINT_TYPE_DISTLIMIT);
- /* BL_ArmatureConstraint ik_type */
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_COPYPOSE, CONSTRAINT_IK_COPYPOSE);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_DISTANCE, CONSTRAINT_IK_DISTANCE);
- /* BL_ArmatureConstraint ik_mode */
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_INSIDE, LIMITDIST_INSIDE);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_OUTSIDE, LIMITDIST_OUTSIDE);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_MODE_ONSURFACE, LIMITDIST_ONSURFACE);
- /* BL_ArmatureConstraint ik_flag */
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_TIP, CONSTRAINT_IK_TIP);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_ROT, CONSTRAINT_IK_ROT);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_STRETCH, CONSTRAINT_IK_STRETCH);
- KX_MACRO_addTypesToDict(d, CONSTRAINT_IK_FLAG_POS, CONSTRAINT_IK_POS);
- /* KX_ArmatureSensor type */
- KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_STATE_CHANGED, SENS_ARM_STATE_CHANGED);
- KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_LIN_ERROR_BELOW, SENS_ARM_LIN_ERROR_BELOW);
- KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_LIN_ERROR_ABOVE, SENS_ARM_LIN_ERROR_ABOVE);
- KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_ROT_ERROR_BELOW, SENS_ARM_ROT_ERROR_BELOW);
- KX_MACRO_addTypesToDict(d, KX_ARMSENSOR_ROT_ERROR_ABOVE, SENS_ARM_ROT_ERROR_ABOVE);
-
- /* BL_ArmatureActuator type */
- KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_RUN, ACT_ARM_RUN);
- KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_ENABLE, ACT_ARM_ENABLE);
- KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_DISABLE, ACT_ARM_DISABLE);
- KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETTARGET, ACT_ARM_SETTARGET);
- KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETWEIGHT, ACT_ARM_SETWEIGHT);
- KX_MACRO_addTypesToDict(d, KX_ACT_ARMATURE_SETINFLUENCE, ACT_ARM_SETINFLUENCE);
-
- /* BL_Armature Channel rotation_mode */
- KX_MACRO_addTypesToDict(d, ROT_MODE_QUAT, ROT_MODE_QUAT);
- KX_MACRO_addTypesToDict(d, ROT_MODE_XYZ, ROT_MODE_XYZ);
- KX_MACRO_addTypesToDict(d, ROT_MODE_XZY, ROT_MODE_XZY);
- KX_MACRO_addTypesToDict(d, ROT_MODE_YXZ, ROT_MODE_YXZ);
- KX_MACRO_addTypesToDict(d, ROT_MODE_YZX, ROT_MODE_YZX);
- KX_MACRO_addTypesToDict(d, ROT_MODE_ZXY, ROT_MODE_ZXY);
- KX_MACRO_addTypesToDict(d, ROT_MODE_ZYX, ROT_MODE_ZYX);
-
- /* Steering actuator */
- KX_MACRO_addTypesToDict(d, KX_STEERING_SEEK, KX_SteeringActuator::KX_STEERING_SEEK);
- KX_MACRO_addTypesToDict(d, KX_STEERING_FLEE, KX_SteeringActuator::KX_STEERING_FLEE);
- KX_MACRO_addTypesToDict(d, KX_STEERING_PATHFOLLOWING, KX_SteeringActuator::KX_STEERING_PATHFOLLOWING);
-
- /* KX_NavMeshObject render mode */
- KX_MACRO_addTypesToDict(d, RM_WALLS, KX_NavMeshObject::RM_WALLS);
- KX_MACRO_addTypesToDict(d, RM_POLYS, KX_NavMeshObject::RM_POLYS);
- KX_MACRO_addTypesToDict(d, RM_TRIS, KX_NavMeshObject::RM_TRIS);
-
- /* BL_Action play modes */
- KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_PLAY, BL_Action::ACT_MODE_PLAY);
- KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_LOOP, BL_Action::ACT_MODE_LOOP);
- KX_MACRO_addTypesToDict(d, KX_ACTION_MODE_PING_PONG, BL_Action::ACT_MODE_PING_PONG);
-
- /* BL_Action blend modes */
- KX_MACRO_addTypesToDict(d, KX_ACTION_BLEND_BLEND, BL_Action::ACT_BLEND_BLEND);
- KX_MACRO_addTypesToDict(d, KX_ACTION_BLEND_ADD, BL_Action::ACT_BLEND_ADD);
-
- /* Mouse Actuator object axis*/
- KX_MACRO_addTypesToDict(d, KX_ACT_MOUSE_OBJECT_AXIS_X, KX_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_X);
- KX_MACRO_addTypesToDict(d, KX_ACT_MOUSE_OBJECT_AXIS_Y, KX_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_Y);
- KX_MACRO_addTypesToDict(d, KX_ACT_MOUSE_OBJECT_AXIS_Z, KX_MouseActuator::KX_ACT_MOUSE_OBJECT_AXIS_Z);
-
-
- // Check for errors
- if (PyErr_Occurred())
- {
- Py_FatalError("can't initialize module bge.logic");
- }
-
- return m;
-}
-
-/**
- * Explanation of
- *
- * - backupPySysObjects() : stores sys.path in #gp_sys_backup
- * - initPySysObjects(main) : initializes the blendfile and library paths
- * - restorePySysObjects() : restores sys.path from #gp_sys_backup
- *
- * These exist so the current blend dir "//" can always be used to import modules from.
- * the reason we need a few functions for this is that python is not only used by the game engine
- * so we cant just add to sys.path all the time, it would leave pythons state in a mess.
- * It would also be incorrect since loading blend files for new levels etc would always add to sys.path
- *
- * To play nice with blenders python, the sys.path is backed up and the current blendfile along
- * with all its lib paths are added to the sys path.
- * When loading a new blendfile, the original sys.path is restored and the new paths are added over the top.
- */
-
-/**
- * So we can have external modules mixed with our blend files.
- */
-static void backupPySysObjects(void)
-{
- PyObject *sys_path = PySys_GetObject("path");
- PyObject *sys_meta_path = PySys_GetObject("meta_path");
- PyObject *sys_mods = PySys_GetObject("modules");
-
- /* paths */
- Py_XDECREF(gp_sys_backup.path); /* just in case its set */
- gp_sys_backup.path = PyList_GetSlice(sys_path, 0, INT_MAX); /* copy the list */
-
- /* meta_paths */
- Py_XDECREF(gp_sys_backup.meta_path); /* just in case its set */
- gp_sys_backup.meta_path = PyList_GetSlice(sys_meta_path, 0, INT_MAX); /* copy the list */
-
- /* modules */
- Py_XDECREF(gp_sys_backup.modules); /* just in case its set */
- gp_sys_backup.modules = PyDict_Copy(sys_mods); /* copy the dict */
-
-}
-
-/* for initPySysObjects only,
- * takes a blend path and adds a scripts dir from it
- *
- * "/home/me/foo.blend" -> "/home/me/scripts"
- */
-static void initPySysObjects__append(PyObject *sys_path, const char *filename)
-{
- PyObject *item;
- char expanded[FILE_MAX];
-
- BLI_split_dir_part(filename, expanded, sizeof(expanded)); /* get the dir part of filename only */
- BLI_path_abs(expanded, gp_GamePythonPath); /* filename from lib->filename is (always?) absolute, so this may not be needed but it wont hurt */
- BLI_cleanup_file(gp_GamePythonPath, expanded); /* Don't use BLI_cleanup_dir because it adds a slash - BREAKS WIN32 ONLY */
- item = PyC_UnicodeFromByte(expanded);
-
-// printf("SysPath - '%s', '%s', '%s'\n", expanded, filename, gp_GamePythonPath);
-
- if (PySequence_Index(sys_path, item) == -1) {
- PyErr_Clear(); /* PySequence_Index sets a ValueError */
- PyList_Insert(sys_path, 0, item);
- }
-
- Py_DECREF(item);
-}
-static void initPySysObjects(Main *maggie)
-{
- PyObject *sys_path = PySys_GetObject("path");
- PyObject *sys_meta_path = PySys_GetObject("meta_path");
-
- if (gp_sys_backup.path == NULL) {
- /* backup */
- backupPySysObjects();
- }
- else {
- /* get the original sys path when the BGE started */
- PyList_SetSlice(sys_path, 0, INT_MAX, gp_sys_backup.path);
- PyList_SetSlice(sys_meta_path, 0, INT_MAX, gp_sys_backup.meta_path);
- }
-
- Library *lib= (Library *)maggie->library.first;
-
- while (lib) {
- /* lib->name wont work in some cases (on win32),
- * even when expanding with gp_GamePythonPath, using lib->filename is less trouble */
- initPySysObjects__append(sys_path, lib->filepath);
- lib= (Library *)lib->id.next;
- }
-
- initPySysObjects__append(sys_path, gp_GamePythonPath);
-
-// fprintf(stderr, "\nNew Path: %d ", PyList_GET_SIZE(sys_path));
-// PyObject_Print(sys_path, stderr, 0);
-}
-
-static void restorePySysObjects(void)
-{
- if (gp_sys_backup.path == NULL) {
- return;
- }
-
- /* will never fail */
- PyObject *sys_path = PySys_GetObject("path");
- PyObject *sys_meta_path = PySys_GetObject("meta_path");
- PyObject *sys_mods = PySys_GetObject("modules");
-
- /* paths */
- PyList_SetSlice(sys_path, 0, INT_MAX, gp_sys_backup.path);
- Py_DECREF(gp_sys_backup.path);
- gp_sys_backup.path = NULL;
-
- /* meta_path */
- PyList_SetSlice(sys_meta_path, 0, INT_MAX, gp_sys_backup.meta_path);
- Py_DECREF(gp_sys_backup.meta_path);
- gp_sys_backup.meta_path = NULL;
-
- /* modules */
- PyDict_Clear(sys_mods);
- PyDict_Update(sys_mods, gp_sys_backup.modules);
- Py_DECREF(gp_sys_backup.modules);
- gp_sys_backup.modules = NULL;
-
-
-// fprintf(stderr, "\nRestore Path: %d ", PyList_GET_SIZE(sys_path));
-// PyObject_Print(sys_path, stderr, 0);
-}
-
-void addImportMain(struct Main *maggie)
-{
- bpy_import_main_extra_add(maggie);
-}
-
-void removeImportMain(struct Main *maggie)
-{
- bpy_import_main_extra_remove(maggie);
-}
-
-
-PyDoc_STRVAR(BGE_module_documentation,
- "This module contains submodules for the Blender Game Engine.\n"
-);
-
-static struct PyModuleDef BGE_module_def = {
- PyModuleDef_HEAD_INIT,
- "bge", /* m_name */
- BGE_module_documentation, /* m_doc */
- 0, /* m_size */
- NULL, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
-};
-
-PyMODINIT_FUNC initBGE(void)
-{
- PyObject *mod;
- PyObject *submodule;
- PyObject *sys_modules = PyThreadState_GET()->interp->modules;
- const char *mod_full;
-
- mod = PyModule_Create(&BGE_module_def);
-
- /* skip "bge." */
-#define SUBMOD (mod_full + 4)
-
- mod_full = "bge.app";
- PyModule_AddObject(mod, SUBMOD, (submodule = initApplicationPythonBinding()));
- PyDict_SetItemString(sys_modules, mod_full, submodule);
- Py_INCREF(submodule);
-
- mod_full = "bge.constraints";
- PyModule_AddObject(mod, SUBMOD, (submodule = initConstraintPythonBinding()));
- PyDict_SetItemString(sys_modules, mod_full, submodule);
- Py_INCREF(submodule);
-
- mod_full = "bge.events";
- PyModule_AddObject(mod, SUBMOD, (submodule = initGameKeysPythonBinding()));
- PyDict_SetItemString(sys_modules, mod_full, submodule);
- Py_INCREF(submodule);
-
- mod_full = "bge.logic";
- PyModule_AddObject(mod, SUBMOD, (submodule = initGameLogicPythonBinding()));
- PyDict_SetItemString(sys_modules, mod_full, submodule);
- Py_INCREF(submodule);
-
- mod_full = "bge.render";
- PyModule_AddObject(mod, SUBMOD, (submodule = initRasterizerPythonBinding()));
- PyDict_SetItemString(sys_modules, mod_full, submodule);
- Py_INCREF(submodule);
-
- mod_full = "bge.texture";
- PyModule_AddObject(mod, SUBMOD, (submodule = initVideoTexturePythonBinding()));
- PyDict_SetItemString(sys_modules, mod_full, submodule);
- Py_INCREF(submodule);
-
- mod_full = "bge.types";
- PyModule_AddObject(mod, SUBMOD, (submodule = initGameTypesPythonBinding()));
- PyDict_SetItemString(sys_modules, mod_full, submodule);
- Py_INCREF(submodule);
-
-#undef SUBMOD
-
- return mod;
-}
-
-
-/* minimal required blender modules to run blenderplayer */
-static struct _inittab bge_internal_modules[] = {
- {"mathutils", PyInit_mathutils},
- {"bgl", BPyInit_bgl},
- {"blf", BPyInit_blf},
- {"aud", AUD_initPython},
- {NULL, NULL}
-};
-
-/**
- * Python is not initialized.
- * see bpy_interface.c's BPY_python_start() which shares the same functionality in blender.
- */
-PyObject *initGamePlayerPythonScripting(Main *maggie, int argc, char** argv)
-{
- /* Yet another gotcha in the py api
- * Cant run PySys_SetArgv more than once because this adds the
- * binary dir to the sys.path each time.
- * Id have thought python being totally restarted would make this ok but
- * somehow it remembers the sys.path - Campbell
- */
- static bool first_time = true;
- const char * const py_path_bundle = BKE_appdir_folder_id(BLENDER_SYSTEM_PYTHON, NULL);
-
- /* not essential but nice to set our name */
- static wchar_t program_path_wchar[FILE_MAX]; /* python holds a reference */
- BLI_strncpy_wchar_from_utf8(program_path_wchar, BKE_appdir_program_path(), ARRAY_SIZE(program_path_wchar));
- Py_SetProgramName(program_path_wchar);
-
- /* Update, Py3.3 resolves attempting to parse non-existing header */
-#if 0
- /* Python 3.2 now looks for '2.xx/python/include/python3.2d/pyconfig.h' to
- * parse from the 'sysconfig' module which is used by 'site',
- * so for now disable site. alternatively we could copy the file. */
- if (py_path_bundle != NULL) {
- Py_NoSiteFlag = 1; /* inhibits the automatic importing of 'site' */
- }
-#endif
-
- Py_FrozenFlag = 1;
-
- /* must run before python initializes */
- PyImport_ExtendInittab(bge_internal_modules);
-
- /* find local python installation */
- PyC_SetHomePath(py_path_bundle);
-
- Py_Initialize();
-
- if (argv && first_time) { /* browser plugins don't currently set this */
- // Until python support ascii again, we use our own.
- // PySys_SetArgv(argc, argv);
- int i;
- PyObject *py_argv= PyList_New(argc);
-
- for (i=0; i<argc; i++)
- PyList_SET_ITEM(py_argv, i, PyC_UnicodeFromByte(argv[i]));
-
- PySys_SetObject("argv", py_argv);
- Py_DECREF(py_argv);
- }
-
- /* Initialize thread support (also acquires lock) */
- PyEval_InitThreads();
-
- bpy_import_init(PyEval_GetBuiltins());
-
- bpy_import_main_set(maggie);
-
- initPySysObjects(maggie);
-
- /* mathutils types are used by the BGE even if we don't import them */
- {
- PyObject *mod = PyImport_ImportModuleLevel("mathutils", NULL, NULL, NULL, 0);
- Py_DECREF(mod);
- }
-
-#ifdef WITH_AUDASPACE
- /* accessing a SoundActuator's sound results in a crash if aud is not initialized... */
- {
- PyObject *mod = PyImport_ImportModuleLevel("aud", NULL, NULL, NULL, 0);
- Py_DECREF(mod);
- }
-#endif
-
- PyDict_SetItemString(PyImport_GetModuleDict(), "bge", initBGE());
-
- first_time = false;
-
- PyObjectPlus::ClearDeprecationWarning();
-
- return PyC_DefaultNameSpace(NULL);
-}
-
-void exitGamePlayerPythonScripting()
-{
- /* Clean up the Python mouse and keyboard */
- delete gp_PythonKeyboard;
- gp_PythonKeyboard = NULL;
-
- delete gp_PythonMouse;
- gp_PythonMouse = NULL;
-
- for (int i=0; i<JOYINDEX_MAX; ++i) {
- if (gp_PythonJoysticks[i]) {
- delete gp_PythonJoysticks[i];
- gp_PythonJoysticks[i] = NULL;
- }
- }
-
- /* since python restarts we cant let the python backup of the sys.path hang around in a global pointer */
- restorePySysObjects(); /* get back the original sys.path and clear the backup */
-
- Py_Finalize();
- bpy_import_main_set(NULL);
- PyObjectPlus::ClearDeprecationWarning();
-}
-
-
-
-/**
- * Python is already initialized.
- */
-PyObject *initGamePythonScripting(Main *maggie)
-{
- /* no need to Py_SetProgramName, it was already taken care of in BPY_python_start */
-
- bpy_import_main_set(maggie);
-
- initPySysObjects(maggie);
-
-#ifdef WITH_AUDASPACE
- /* accessing a SoundActuator's sound results in a crash if aud is not initialized... */
- {
- PyObject *mod= PyImport_ImportModuleLevel("aud", NULL, NULL, NULL, 0);
- Py_DECREF(mod);
- }
-#endif
-
- PyDict_SetItemString(PyImport_GetModuleDict(), "bge", initBGE());
-
- PyObjectPlus::NullDeprecationWarning();
-
- return PyC_DefaultNameSpace(NULL);
-}
-
-void exitGamePythonScripting()
-{
- /* Clean up the Python mouse and keyboard */
- delete gp_PythonKeyboard;
- gp_PythonKeyboard = NULL;
-
- delete gp_PythonMouse;
- gp_PythonMouse = NULL;
-
- for (int i=0; i<JOYINDEX_MAX; ++i) {
- if (gp_PythonJoysticks[i]) {
- delete gp_PythonJoysticks[i];
- gp_PythonJoysticks[i] = NULL;
- }
- }
-
- restorePySysObjects(); /* get back the original sys.path and clear the backup */
- bpy_import_main_set(NULL);
- PyObjectPlus::ClearDeprecationWarning();
-}
-
-/* similar to the above functions except it sets up the namespace
- * and other more general things */
-void setupGamePython(KX_KetsjiEngine* ketsjiengine, KX_Scene *startscene, Main *blenderdata,
- PyObject *pyGlobalDict, PyObject **gameLogic, PyObject **gameLogic_keys, int argc, char** argv)
-{
- PyObject *modules, *dictionaryobject;
-
- gp_Canvas = ketsjiengine->GetCanvas();
- gp_Rasterizer = ketsjiengine->GetRasterizer();
- gp_KetsjiEngine = ketsjiengine;
- gp_KetsjiScene = startscene;
-
- if (argv) /* player only */
- dictionaryobject= initGamePlayerPythonScripting(blenderdata, argc, argv);
- else
- dictionaryobject= initGamePythonScripting(blenderdata);
-
- ketsjiengine->SetPyNamespace(dictionaryobject);
-
- modules = PyImport_GetModuleDict();
-
- *gameLogic = PyDict_GetItemString(modules, "GameLogic");
- /* is set in initGameLogicPythonBinding so only set here if we want it to persist between scenes */
- if (pyGlobalDict)
- PyDict_SetItemString(PyModule_GetDict(*gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
-
- *gameLogic_keys = PyDict_Keys(PyModule_GetDict(*gameLogic));
-}
-
-static struct PyModuleDef Rasterizer_module_def = {
- PyModuleDef_HEAD_INIT,
- "Rasterizer", /* m_name */
- Rasterizer_module_documentation, /* m_doc */
- 0, /* m_size */
- rasterizer_methods, /* m_methods */
- 0, /* m_reload */
- 0, /* m_traverse */
- 0, /* m_clear */
- 0, /* m_free */
-};
-
-PyMODINIT_FUNC initRasterizerPythonBinding()
-{
- PyObject *m;
- PyObject *d;
-
- PyType_Ready(&PyRASOffScreen_Type);
-
- m = PyModule_Create(&Rasterizer_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), Rasterizer_module_def.m_name, m);
-
-
- // Add some symbolic constants to the module
- d = PyModule_GetDict(m);
- ErrorObject = PyUnicode_FromString("Rasterizer.error");
- PyDict_SetItemString(d, "error", ErrorObject);
- Py_DECREF(ErrorObject);
-
- /* needed for get/setMaterialType */
- KX_MACRO_addTypesToDict(d, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL);
- KX_MACRO_addTypesToDict(d, KX_BLENDER_GLSL_MATERIAL, KX_BLENDER_GLSL_MATERIAL);
-
- KX_MACRO_addTypesToDict(d, RAS_MIPMAP_NONE, RAS_IRasterizer::RAS_MIPMAP_NONE);
- KX_MACRO_addTypesToDict(d, RAS_MIPMAP_NEAREST, RAS_IRasterizer::RAS_MIPMAP_NEAREST);
- KX_MACRO_addTypesToDict(d, RAS_MIPMAP_LINEAR, RAS_IRasterizer::RAS_MIPMAP_LINEAR);
-
- /* for get/setVsync */
- KX_MACRO_addTypesToDict(d, VSYNC_OFF, VSYNC_OFF);
- KX_MACRO_addTypesToDict(d, VSYNC_ON, VSYNC_ON);
- KX_MACRO_addTypesToDict(d, VSYNC_ADAPTIVE, VSYNC_ADAPTIVE);
-
- /* stereoscopy */
- KX_MACRO_addTypesToDict(d, LEFT_EYE, RAS_IRasterizer::RAS_STEREO_LEFTEYE);
- KX_MACRO_addTypesToDict(d, RIGHT_EYE, RAS_IRasterizer::RAS_STEREO_RIGHTEYE);
-
- /* offscreen render */
- KX_MACRO_addTypesToDict(d, RAS_OFS_RENDER_BUFFER, RAS_IOffScreen::RAS_OFS_RENDER_BUFFER);
- KX_MACRO_addTypesToDict(d, RAS_OFS_RENDER_TEXTURE, RAS_IOffScreen::RAS_OFS_RENDER_TEXTURE);
-
-
- // XXXX Add constants here
-
- // Check for errors
- if (PyErr_Occurred())
- {
- Py_FatalError("can't initialize module Rasterizer");
- }
-
- return m;
-}
-
-
-
-/* ------------------------------------------------------------------------- */
-/* GameKeys: symbolic constants for key mapping */
-/* ------------------------------------------------------------------------- */
-
-PyDoc_STRVAR(GameKeys_module_documentation,
-"This modules provides defines for key-codes"
-);
-
-PyDoc_STRVAR(gPyEventToString_doc,
-"EventToString(event)\n"
-"Take a valid event from the GameKeys module or Keyboard Sensor and return a name"
-);
-
-static PyObject *gPyEventToString(PyObject *, PyObject *value)
-{
- PyObject *mod, *dict, *key, *val, *ret = NULL;
- Py_ssize_t pos = 0;
-
- mod = PyImport_ImportModule( "GameKeys" );
- if (!mod)
- return NULL;
-
- dict = PyModule_GetDict(mod);
-
- while (PyDict_Next(dict, &pos, &key, &val)) {
- if (PyObject_RichCompareBool(value, val, Py_EQ)) {
- ret = key;
- break;
- }
- }
-
- PyErr_Clear(); // in case there was an error clearing
- Py_DECREF(mod);
- if (!ret) PyErr_SetString(PyExc_ValueError, "GameKeys.EventToString(int): expected a valid int keyboard event");
- else Py_INCREF(ret);
-
- return ret;
-}
-
-
-PyDoc_STRVAR(gPyEventToCharacter_doc,
-"EventToCharacter(event, is_shift)\n"
-"Take a valid event from the GameKeys module or Keyboard Sensor and return a character"
-);
-
-static PyObject *gPyEventToCharacter(PyObject *, PyObject *args)
-{
- int event, shift;
- if (!PyArg_ParseTuple(args,"ii:EventToCharacter", &event, &shift))
- return NULL;
-
- if (IsPrintable(event)) {
- char ch[2] = {'\0', '\0'};
- ch[0] = ToCharacter(event, (bool)shift);
- return PyUnicode_FromString(ch);
- }
- else {
- return PyUnicode_FromString("");
- }
-}
-
-
-static struct PyMethodDef gamekeys_methods[] = {
- {"EventToCharacter", (PyCFunction)gPyEventToCharacter, METH_VARARGS, (const char *)gPyEventToCharacter_doc},
- {"EventToString", (PyCFunction)gPyEventToString, METH_O, (const char *)gPyEventToString_doc},
- { NULL, (PyCFunction) NULL, 0, NULL }
-};
-
-static struct PyModuleDef GameKeys_module_def = {
- PyModuleDef_HEAD_INIT,
- "GameKeys", /* m_name */
- GameKeys_module_documentation, /* m_doc */
- 0, /* m_size */
- gamekeys_methods, /* m_methods */
- 0, /* m_reload */
- 0, /* m_traverse */
- 0, /* m_clear */
- 0, /* m_free */
-};
-
-PyMODINIT_FUNC initGameKeysPythonBinding()
-{
- PyObject *m;
- PyObject *d;
-
- m = PyModule_Create(&GameKeys_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), GameKeys_module_def.m_name, m);
-
- // Add some symbolic constants to the module
- d = PyModule_GetDict(m);
-
- // XXXX Add constants here
-
- KX_MACRO_addTypesToDict(d, AKEY, SCA_IInputDevice::KX_AKEY);
- KX_MACRO_addTypesToDict(d, BKEY, SCA_IInputDevice::KX_BKEY);
- KX_MACRO_addTypesToDict(d, CKEY, SCA_IInputDevice::KX_CKEY);
- KX_MACRO_addTypesToDict(d, DKEY, SCA_IInputDevice::KX_DKEY);
- KX_MACRO_addTypesToDict(d, EKEY, SCA_IInputDevice::KX_EKEY);
- KX_MACRO_addTypesToDict(d, FKEY, SCA_IInputDevice::KX_FKEY);
- KX_MACRO_addTypesToDict(d, GKEY, SCA_IInputDevice::KX_GKEY);
- KX_MACRO_addTypesToDict(d, HKEY, SCA_IInputDevice::KX_HKEY);
- KX_MACRO_addTypesToDict(d, IKEY, SCA_IInputDevice::KX_IKEY);
- KX_MACRO_addTypesToDict(d, JKEY, SCA_IInputDevice::KX_JKEY);
- KX_MACRO_addTypesToDict(d, KKEY, SCA_IInputDevice::KX_KKEY);
- KX_MACRO_addTypesToDict(d, LKEY, SCA_IInputDevice::KX_LKEY);
- KX_MACRO_addTypesToDict(d, MKEY, SCA_IInputDevice::KX_MKEY);
- KX_MACRO_addTypesToDict(d, NKEY, SCA_IInputDevice::KX_NKEY);
- KX_MACRO_addTypesToDict(d, OKEY, SCA_IInputDevice::KX_OKEY);
- KX_MACRO_addTypesToDict(d, PKEY, SCA_IInputDevice::KX_PKEY);
- KX_MACRO_addTypesToDict(d, QKEY, SCA_IInputDevice::KX_QKEY);
- KX_MACRO_addTypesToDict(d, RKEY, SCA_IInputDevice::KX_RKEY);
- KX_MACRO_addTypesToDict(d, SKEY, SCA_IInputDevice::KX_SKEY);
- KX_MACRO_addTypesToDict(d, TKEY, SCA_IInputDevice::KX_TKEY);
- KX_MACRO_addTypesToDict(d, UKEY, SCA_IInputDevice::KX_UKEY);
- KX_MACRO_addTypesToDict(d, VKEY, SCA_IInputDevice::KX_VKEY);
- KX_MACRO_addTypesToDict(d, WKEY, SCA_IInputDevice::KX_WKEY);
- KX_MACRO_addTypesToDict(d, XKEY, SCA_IInputDevice::KX_XKEY);
- KX_MACRO_addTypesToDict(d, YKEY, SCA_IInputDevice::KX_YKEY);
- KX_MACRO_addTypesToDict(d, ZKEY, SCA_IInputDevice::KX_ZKEY);
-
- KX_MACRO_addTypesToDict(d, ZEROKEY, SCA_IInputDevice::KX_ZEROKEY);
- KX_MACRO_addTypesToDict(d, ONEKEY, SCA_IInputDevice::KX_ONEKEY);
- KX_MACRO_addTypesToDict(d, TWOKEY, SCA_IInputDevice::KX_TWOKEY);
- KX_MACRO_addTypesToDict(d, THREEKEY, SCA_IInputDevice::KX_THREEKEY);
- KX_MACRO_addTypesToDict(d, FOURKEY, SCA_IInputDevice::KX_FOURKEY);
- KX_MACRO_addTypesToDict(d, FIVEKEY, SCA_IInputDevice::KX_FIVEKEY);
- KX_MACRO_addTypesToDict(d, SIXKEY, SCA_IInputDevice::KX_SIXKEY);
- KX_MACRO_addTypesToDict(d, SEVENKEY, SCA_IInputDevice::KX_SEVENKEY);
- KX_MACRO_addTypesToDict(d, EIGHTKEY, SCA_IInputDevice::KX_EIGHTKEY);
- KX_MACRO_addTypesToDict(d, NINEKEY, SCA_IInputDevice::KX_NINEKEY);
-
- KX_MACRO_addTypesToDict(d, CAPSLOCKKEY, SCA_IInputDevice::KX_CAPSLOCKKEY);
-
- KX_MACRO_addTypesToDict(d, LEFTCTRLKEY, SCA_IInputDevice::KX_LEFTCTRLKEY);
- KX_MACRO_addTypesToDict(d, LEFTALTKEY, SCA_IInputDevice::KX_LEFTALTKEY);
- KX_MACRO_addTypesToDict(d, RIGHTALTKEY, SCA_IInputDevice::KX_RIGHTALTKEY);
- KX_MACRO_addTypesToDict(d, RIGHTCTRLKEY, SCA_IInputDevice::KX_RIGHTCTRLKEY);
- KX_MACRO_addTypesToDict(d, RIGHTSHIFTKEY, SCA_IInputDevice::KX_RIGHTSHIFTKEY);
- KX_MACRO_addTypesToDict(d, LEFTSHIFTKEY, SCA_IInputDevice::KX_LEFTSHIFTKEY);
-
- KX_MACRO_addTypesToDict(d, ESCKEY, SCA_IInputDevice::KX_ESCKEY);
- KX_MACRO_addTypesToDict(d, TABKEY, SCA_IInputDevice::KX_TABKEY);
- KX_MACRO_addTypesToDict(d, RETKEY, SCA_IInputDevice::KX_RETKEY);
- KX_MACRO_addTypesToDict(d, ENTERKEY, SCA_IInputDevice::KX_RETKEY);
- KX_MACRO_addTypesToDict(d, SPACEKEY, SCA_IInputDevice::KX_SPACEKEY);
- KX_MACRO_addTypesToDict(d, LINEFEEDKEY, SCA_IInputDevice::KX_LINEFEEDKEY);
- KX_MACRO_addTypesToDict(d, BACKSPACEKEY, SCA_IInputDevice::KX_BACKSPACEKEY);
- KX_MACRO_addTypesToDict(d, DELKEY, SCA_IInputDevice::KX_DELKEY);
- KX_MACRO_addTypesToDict(d, SEMICOLONKEY, SCA_IInputDevice::KX_SEMICOLONKEY);
- KX_MACRO_addTypesToDict(d, PERIODKEY, SCA_IInputDevice::KX_PERIODKEY);
- KX_MACRO_addTypesToDict(d, COMMAKEY, SCA_IInputDevice::KX_COMMAKEY);
- KX_MACRO_addTypesToDict(d, QUOTEKEY, SCA_IInputDevice::KX_QUOTEKEY);
- KX_MACRO_addTypesToDict(d, ACCENTGRAVEKEY, SCA_IInputDevice::KX_ACCENTGRAVEKEY);
- KX_MACRO_addTypesToDict(d, MINUSKEY, SCA_IInputDevice::KX_MINUSKEY);
- KX_MACRO_addTypesToDict(d, SLASHKEY, SCA_IInputDevice::KX_SLASHKEY);
- KX_MACRO_addTypesToDict(d, BACKSLASHKEY, SCA_IInputDevice::KX_BACKSLASHKEY);
- KX_MACRO_addTypesToDict(d, EQUALKEY, SCA_IInputDevice::KX_EQUALKEY);
- KX_MACRO_addTypesToDict(d, LEFTBRACKETKEY, SCA_IInputDevice::KX_LEFTBRACKETKEY);
- KX_MACRO_addTypesToDict(d, RIGHTBRACKETKEY, SCA_IInputDevice::KX_RIGHTBRACKETKEY);
-
- KX_MACRO_addTypesToDict(d, LEFTARROWKEY, SCA_IInputDevice::KX_LEFTARROWKEY);
- KX_MACRO_addTypesToDict(d, DOWNARROWKEY, SCA_IInputDevice::KX_DOWNARROWKEY);
- KX_MACRO_addTypesToDict(d, RIGHTARROWKEY, SCA_IInputDevice::KX_RIGHTARROWKEY);
- KX_MACRO_addTypesToDict(d, UPARROWKEY, SCA_IInputDevice::KX_UPARROWKEY);
-
- KX_MACRO_addTypesToDict(d, PAD2 , SCA_IInputDevice::KX_PAD2);
- KX_MACRO_addTypesToDict(d, PAD4 , SCA_IInputDevice::KX_PAD4);
- KX_MACRO_addTypesToDict(d, PAD6 , SCA_IInputDevice::KX_PAD6);
- KX_MACRO_addTypesToDict(d, PAD8 , SCA_IInputDevice::KX_PAD8);
-
- KX_MACRO_addTypesToDict(d, PAD1 , SCA_IInputDevice::KX_PAD1);
- KX_MACRO_addTypesToDict(d, PAD3 , SCA_IInputDevice::KX_PAD3);
- KX_MACRO_addTypesToDict(d, PAD5 , SCA_IInputDevice::KX_PAD5);
- KX_MACRO_addTypesToDict(d, PAD7 , SCA_IInputDevice::KX_PAD7);
- KX_MACRO_addTypesToDict(d, PAD9 , SCA_IInputDevice::KX_PAD9);
-
- KX_MACRO_addTypesToDict(d, PADPERIOD, SCA_IInputDevice::KX_PADPERIOD);
- KX_MACRO_addTypesToDict(d, PADSLASHKEY, SCA_IInputDevice::KX_PADSLASHKEY);
- KX_MACRO_addTypesToDict(d, PADASTERKEY, SCA_IInputDevice::KX_PADASTERKEY);
-
-
- KX_MACRO_addTypesToDict(d, PAD0, SCA_IInputDevice::KX_PAD0);
- KX_MACRO_addTypesToDict(d, PADMINUS, SCA_IInputDevice::KX_PADMINUS);
- KX_MACRO_addTypesToDict(d, PADENTER, SCA_IInputDevice::KX_PADENTER);
- KX_MACRO_addTypesToDict(d, PADPLUSKEY, SCA_IInputDevice::KX_PADPLUSKEY);
-
-
- KX_MACRO_addTypesToDict(d, F1KEY, SCA_IInputDevice::KX_F1KEY);
- KX_MACRO_addTypesToDict(d, F2KEY, SCA_IInputDevice::KX_F2KEY);
- KX_MACRO_addTypesToDict(d, F3KEY, SCA_IInputDevice::KX_F3KEY);
- KX_MACRO_addTypesToDict(d, F4KEY, SCA_IInputDevice::KX_F4KEY);
- KX_MACRO_addTypesToDict(d, F5KEY, SCA_IInputDevice::KX_F5KEY);
- KX_MACRO_addTypesToDict(d, F6KEY, SCA_IInputDevice::KX_F6KEY);
- KX_MACRO_addTypesToDict(d, F7KEY, SCA_IInputDevice::KX_F7KEY);
- KX_MACRO_addTypesToDict(d, F8KEY, SCA_IInputDevice::KX_F8KEY);
- KX_MACRO_addTypesToDict(d, F9KEY, SCA_IInputDevice::KX_F9KEY);
- KX_MACRO_addTypesToDict(d, F10KEY, SCA_IInputDevice::KX_F10KEY);
- KX_MACRO_addTypesToDict(d, F11KEY, SCA_IInputDevice::KX_F11KEY);
- KX_MACRO_addTypesToDict(d, F12KEY, SCA_IInputDevice::KX_F12KEY);
- KX_MACRO_addTypesToDict(d, F13KEY, SCA_IInputDevice::KX_F13KEY);
- KX_MACRO_addTypesToDict(d, F14KEY, SCA_IInputDevice::KX_F14KEY);
- KX_MACRO_addTypesToDict(d, F15KEY, SCA_IInputDevice::KX_F15KEY);
- KX_MACRO_addTypesToDict(d, F16KEY, SCA_IInputDevice::KX_F16KEY);
- KX_MACRO_addTypesToDict(d, F17KEY, SCA_IInputDevice::KX_F17KEY);
- KX_MACRO_addTypesToDict(d, F18KEY, SCA_IInputDevice::KX_F18KEY);
- KX_MACRO_addTypesToDict(d, F19KEY, SCA_IInputDevice::KX_F19KEY);
-
- KX_MACRO_addTypesToDict(d, OSKEY, SCA_IInputDevice::KX_OSKEY);
-
- KX_MACRO_addTypesToDict(d, PAUSEKEY, SCA_IInputDevice::KX_PAUSEKEY);
- KX_MACRO_addTypesToDict(d, INSERTKEY, SCA_IInputDevice::KX_INSERTKEY);
- KX_MACRO_addTypesToDict(d, HOMEKEY, SCA_IInputDevice::KX_HOMEKEY);
- KX_MACRO_addTypesToDict(d, PAGEUPKEY, SCA_IInputDevice::KX_PAGEUPKEY);
- KX_MACRO_addTypesToDict(d, PAGEDOWNKEY, SCA_IInputDevice::KX_PAGEDOWNKEY);
- KX_MACRO_addTypesToDict(d, ENDKEY, SCA_IInputDevice::KX_ENDKEY);
-
- // MOUSE
- KX_MACRO_addTypesToDict(d, LEFTMOUSE, SCA_IInputDevice::KX_LEFTMOUSE);
- KX_MACRO_addTypesToDict(d, MIDDLEMOUSE, SCA_IInputDevice::KX_MIDDLEMOUSE);
- KX_MACRO_addTypesToDict(d, RIGHTMOUSE, SCA_IInputDevice::KX_RIGHTMOUSE);
- KX_MACRO_addTypesToDict(d, WHEELUPMOUSE, SCA_IInputDevice::KX_WHEELUPMOUSE);
- KX_MACRO_addTypesToDict(d, WHEELDOWNMOUSE, SCA_IInputDevice::KX_WHEELDOWNMOUSE);
- KX_MACRO_addTypesToDict(d, MOUSEX, SCA_IInputDevice::KX_MOUSEX);
- KX_MACRO_addTypesToDict(d, MOUSEY, SCA_IInputDevice::KX_MOUSEY);
-
- // Check for errors
- if (PyErr_Occurred())
- {
- Py_FatalError("can't initialize module GameKeys");
- }
-
- return m;
-}
-
-
-
-/* ------------------------------------------------------------------------- */
-/* Application: application values that remain unchanged during runtime */
-/* ------------------------------------------------------------------------- */
-
-PyDoc_STRVAR(Application_module_documentation,
- "This module contains application values that remain unchanged during runtime."
- );
-
-static struct PyModuleDef Application_module_def = {
- PyModuleDef_HEAD_INIT,
- "bge.app", /* m_name */
- Application_module_documentation, /* m_doc */
- 0, /* m_size */
- NULL, /* m_methods */
- 0, /* m_reload */
- 0, /* m_traverse */
- 0, /* m_clear */
- 0, /* m_free */
-};
-
-PyMODINIT_FUNC initApplicationPythonBinding()
-{
- PyObject *m;
- PyObject *d;
-
- m = PyModule_Create(&Application_module_def);
-
- // Add some symbolic constants to the module
- d = PyModule_GetDict(m);
-
- PyDict_SetItemString(d, "version", Py_BuildValue("(iii)",
- BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION));
- PyDict_SetItemString(d, "version_string", PyUnicode_FromFormat("%d.%02d (sub %d)",
- BLENDER_VERSION / 100, BLENDER_VERSION % 100, BLENDER_SUBVERSION));
- PyDict_SetItemString(d, "version_char", PyUnicode_FromString(
- STRINGIFY(BLENDER_VERSION_CHAR)));
-
- PyDict_SetItemString(d, "has_texture_ffmpeg",
-#ifdef WITH_FFMPEG
- Py_True
-#else
- Py_False
-#endif
- );
- PyDict_SetItemString(d, "has_joystick",
-#ifdef WITH_SDL
- Py_True
-#else
- Py_False
-#endif
- );
- PyDict_SetItemString(d, "has_physics",
-#ifdef WITH_BULLET
- Py_True
-#else
- Py_False
-#endif
- );
-
- // Check for errors
- if (PyErr_Occurred()) {
- PyErr_Print();
- PyErr_Clear();
- }
-
- return m;
-}
-
-
-// utility function for loading and saving the globalDict
-int saveGamePythonConfig( char **marshal_buffer)
-{
- int marshal_length = 0;
- PyObject *gameLogic = PyImport_ImportModule("GameLogic");
- if (gameLogic) {
- PyObject *pyGlobalDict = PyDict_GetItemString(PyModule_GetDict(gameLogic), "globalDict"); // Same as importing the module
- if (pyGlobalDict) {
-#ifdef Py_MARSHAL_VERSION
- PyObject *pyGlobalDictMarshal = PyMarshal_WriteObjectToString( pyGlobalDict, 2); // Py_MARSHAL_VERSION == 2 as of Py2.5
-#else
- PyObject *pyGlobalDictMarshal = PyMarshal_WriteObjectToString( pyGlobalDict );
-#endif
- if (pyGlobalDictMarshal) {
- // for testing only
- // PyObject_Print(pyGlobalDictMarshal, stderr, 0);
- char *marshal_cstring;
-
- marshal_cstring = PyBytes_AsString(pyGlobalDictMarshal); // py3 uses byte arrays
- marshal_length= PyBytes_Size(pyGlobalDictMarshal);
- *marshal_buffer = new char[marshal_length + 1];
- memcpy(*marshal_buffer, marshal_cstring, marshal_length);
- Py_DECREF(pyGlobalDictMarshal);
- } else {
- printf("Error, bge.logic.globalDict could not be marshal'd\n");
- }
- } else {
- printf("Error, bge.logic.globalDict was removed\n");
- }
- Py_DECREF(gameLogic);
- } else {
- PyErr_Clear();
- printf("Error, bge.logic failed to import bge.logic.globalDict will be lost\n");
- }
- return marshal_length;
-}
-
-int loadGamePythonConfig(char *marshal_buffer, int marshal_length)
-{
- /* Restore the dict */
- if (marshal_buffer) {
- PyObject *gameLogic = PyImport_ImportModule("GameLogic");
-
- if (gameLogic) {
- PyObject *pyGlobalDict = PyMarshal_ReadObjectFromString(marshal_buffer, marshal_length);
- if (pyGlobalDict) {
- PyObject *pyGlobalDict_orig = PyDict_GetItemString(PyModule_GetDict(gameLogic), "globalDict"); // Same as importing the module.
- if (pyGlobalDict_orig) {
- PyDict_Clear(pyGlobalDict_orig);
- PyDict_Update(pyGlobalDict_orig, pyGlobalDict);
- } else {
- /* this should not happen, but cant find the original globalDict, just assign it then */
- PyDict_SetItemString(PyModule_GetDict(gameLogic), "globalDict", pyGlobalDict); // Same as importing the module.
- }
- Py_DECREF(gameLogic);
- Py_DECREF(pyGlobalDict);
- return 1;
- } else {
- Py_DECREF(gameLogic);
- PyErr_Clear();
- printf("Error could not marshall string\n");
- }
- }
- else {
- PyErr_Clear();
- printf("Error, bge.logic failed to import bge.logic.globalDict will be lost\n");
- }
- }
- return 0;
-}
-
-void pathGamePythonConfig(char *path)
-{
- int len = strlen(gp_GamePythonPathOrig); // Always use the first loaded blend filename
-
- BLI_strncpy(path, gp_GamePythonPathOrig, sizeof(gp_GamePythonPathOrig));
-
- /* replace extension */
- if (BLI_testextensie(path, ".blend")) {
- strcpy(path+(len-6), ".bgeconf");
- } else {
- strcpy(path+len, ".bgeconf");
- }
-}
-
-void setGamePythonPath(const char *path)
-{
- BLI_strncpy(gp_GamePythonPath, path, sizeof(gp_GamePythonPath));
- BLI_cleanup_file(NULL, gp_GamePythonPath); /* not absolutely needed but makes resolving path problems less confusing later */
-
- if (gp_GamePythonPathOrig[0] == '\0')
- BLI_strncpy(gp_GamePythonPathOrig, path, sizeof(gp_GamePythonPathOrig));
-}
-
-// we need this so while blender is open (not blenderplayer)
-// loading new blendfiles will reset this on starting the
-// engine but loading blend files within the BGE wont overwrite gp_GamePythonPathOrig
-void resetGamePythonPath()
-{
- gp_GamePythonPathOrig[0] = '\0';
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_PythonInit.h b/source/gameengine/Ketsji/KX_PythonInit.h
deleted file mode 100644
index 6550934a916..00000000000
--- a/source/gameengine/Ketsji/KX_PythonInit.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PythonInit.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_PYTHONINIT_H__
-#define __KX_PYTHONINIT_H__
-
-#include "EXP_Python.h"
-#include "STR_String.h"
-#include "MT_Vector3.h"
-
-class KX_KetsjiEngine;
-class KX_Scene;
-
-typedef enum {
- psl_Lowest = 0,
- psl_Highest,
-} TPythonSecurityLevel;
-
-extern bool gUseVisibilityTemp;
-
-#ifdef WITH_PYTHON
-PyMODINIT_FUNC initBGE(void);
-PyMODINIT_FUNC initApplicationPythonBinding(void);
-PyMODINIT_FUNC initGameLogicPythonBinding(void);
-PyMODINIT_FUNC initGameKeysPythonBinding(void);
-PyMODINIT_FUNC initRasterizerPythonBinding(void);
-PyMODINIT_FUNC initVideoTexturePythonBinding(void);
-PyObject *initGamePlayerPythonScripting(struct Main *maggie, int argc, char **argv);
-PyObject *initGamePythonScripting(struct Main *maggie);
-
-void exitGamePlayerPythonScripting();
-void exitGamePythonScripting();
-void setupGamePython(KX_KetsjiEngine *ketsjiengine, KX_Scene *startscene, Main *blenderdata,
- PyObject *pyGlobalDict, PyObject **gameLogic, PyObject **gameLogic_keys, int argc, char **argv);
-void setGamePythonPath(const char *path);
-void resetGamePythonPath();
-void pathGamePythonConfig(char *path);
-int saveGamePythonConfig(char **marshal_buffer);
-int loadGamePythonConfig(char *marshal_buffer, int marshal_length);
-#endif
-
-void addImportMain(struct Main *maggie);
-void removeImportMain(struct Main *maggie);
-
-class KX_KetsjiEngine;
-class KX_Scene;
-
-void KX_SetActiveScene(KX_Scene *scene);
-KX_Scene *KX_GetActiveScene();
-KX_KetsjiEngine *KX_GetActiveEngine();
-
-typedef int (*PyNextFrameFunc)(void *);
-
-struct PyNextFrameState {
- /** can be either a GPG_NextFrameState or a BL_KetsjiNextFrameState */
- void *state;
- /** can be either GPG_PyNextFrame or BL_KetsjiPyNextFrame */
- PyNextFrameFunc func;
-};
-extern struct PyNextFrameState pynextframestate;
-
-void KX_RasterizerDrawDebugLine(const MT_Vector3 &from,const MT_Vector3 &to,const MT_Vector3 &color);
-void KX_RasterizerDrawDebugCircle(const MT_Vector3 &center, const MT_Scalar radius, const MT_Vector3 &color,
- const MT_Vector3 &normal, int nsector);
-
-
-#endif /* __KX_PYTHONINIT_H__ */
diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp b/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
deleted file mode 100644
index 4a999e37f2b..00000000000
--- a/source/gameengine/Ketsji/KX_PythonInitTypes.cpp
+++ /dev/null
@@ -1,286 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Campbell Barton
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_PythonInitTypes.cpp
- * \ingroup ketsji
- */
-
-#ifdef WITH_PYTHON
-
-#include "KX_PythonInitTypes.h"
-
-/* Only for Class::Parents */
-#include "BL_BlenderShader.h"
-#include "BL_ShapeActionActuator.h"
-#include "BL_ArmatureActuator.h"
-#include "BL_ArmatureConstraint.h"
-#include "BL_ArmatureObject.h"
-#include "BL_ArmatureChannel.h"
-#include "KX_WorldInfo.h"
-#include "KX_ArmatureSensor.h"
-#include "KX_BlenderMaterial.h"
-#include "KX_CameraActuator.h"
-#include "KX_CharacterWrapper.h"
-#include "KX_ConstraintActuator.h"
-#include "KX_ConstraintWrapper.h"
-#include "KX_GameActuator.h"
-#include "KX_LibLoadStatus.h"
-#include "KX_Light.h"
-#include "KX_FontObject.h"
-#include "KX_MeshProxy.h"
-#include "KX_MouseFocusSensor.h"
-#include "KX_NetworkMessageActuator.h"
-#include "KX_NetworkMessageSensor.h"
-#include "KX_ObjectActuator.h"
-#include "KX_ParentActuator.h"
-#include "KX_PolyProxy.h"
-#include "KX_SCA_AddObjectActuator.h"
-#include "KX_SCA_EndObjectActuator.h"
-#include "KX_SCA_ReplaceMeshActuator.h"
-#include "KX_SceneActuator.h"
-#include "KX_StateActuator.h"
-#include "KX_SteeringActuator.h"
-#include "KX_TrackToActuator.h"
-#include "KX_VehicleWrapper.h"
-#include "KX_VertexProxy.h"
-#include "SCA_2DFilterActuator.h"
-#include "SCA_ANDController.h"
-#include "SCA_ActuatorSensor.h"
-#include "SCA_AlwaysSensor.h"
-#include "SCA_DelaySensor.h"
-#include "SCA_JoystickSensor.h"
-#include "SCA_KeyboardSensor.h"
-#include "SCA_MouseSensor.h"
-#include "SCA_NANDController.h"
-#include "SCA_NORController.h"
-#include "SCA_ORController.h"
-#include "SCA_RandomSensor.h"
-#include "SCA_XNORController.h"
-#include "SCA_XORController.h"
-#include "SCA_PythonJoystick.h"
-#include "SCA_PythonKeyboard.h"
-#include "SCA_PythonMouse.h"
-#include "KX_NearSensor.h"
-#include "KX_RadarSensor.h"
-#include "KX_RaySensor.h"
-#include "KX_SCA_DynamicActuator.h"
-#include "KX_SoundActuator.h"
-#include "KX_TouchSensor.h"
-#include "KX_VisibilityActuator.h"
-#include "SCA_PropertySensor.h"
-#include "SCA_PythonController.h"
-#include "SCA_RandomActuator.h"
-#include "SCA_IController.h"
-#include "KX_NavMeshObject.h"
-#include "KX_MouseActuator.h"
-#include "EXP_ListWrapper.h"
-
-static void PyType_Attr_Set(PyGetSetDef *attr_getset, PyAttributeDef *attr)
-{
- attr_getset->name= (char *)attr->m_name;
- attr_getset->doc= NULL;
-
- attr_getset->get= reinterpret_cast<getter>(PyObjectPlus::py_get_attrdef);
-
- if (attr->m_access==KX_PYATTRIBUTE_RO)
- attr_getset->set= NULL;
- else
- attr_getset->set= reinterpret_cast<setter>(PyObjectPlus::py_set_attrdef);
-
- attr_getset->closure= reinterpret_cast<void *>(attr);
-}
-
-static void PyType_Ready_ADD(PyObject *dict, PyTypeObject *tp, PyAttributeDef *attributes, PyAttributeDef *attributesPtr, int init_getset)
-{
- PyAttributeDef *attr;
-
- if (init_getset) {
- /* we need to do this for all types before calling PyType_Ready
- * since they will call the parents PyType_Ready and those might not have initialized vars yet */
-
- //if (tp->tp_base==NULL)
- // printf("Debug: No Parents - '%s'\n" , tp->tp_name);
-
- if (tp->tp_getset==NULL && ((attributes && attributes->m_name) || (attributesPtr && attributesPtr->m_name))) {
- PyGetSetDef *attr_getset;
- int attr_tot= 0;
-
- if (attributes) {
- for (attr= attributes; attr->m_name; attr++, attr_tot++)
- attr->m_usePtr = false;
- }
- if (attributesPtr) {
- for (attr= attributesPtr; attr->m_name; attr++, attr_tot++)
- attr->m_usePtr = true;
- }
-
- tp->tp_getset = attr_getset = reinterpret_cast<PyGetSetDef *>(PyMem_Malloc((attr_tot+1) * sizeof(PyGetSetDef))); // XXX - Todo, free
-
- if (attributes) {
- for (attr= attributes; attr->m_name; attr++, attr_getset++) {
- PyType_Attr_Set(attr_getset, attr);
- }
- }
- if (attributesPtr) {
- for (attr= attributesPtr; attr->m_name; attr++, attr_getset++) {
- PyType_Attr_Set(attr_getset, attr);
- }
- }
- memset(attr_getset, 0, sizeof(PyGetSetDef));
- }
- } else {
- PyType_Ready(tp);
- PyDict_SetItemString(dict, tp->tp_name, reinterpret_cast<PyObject *>(tp));
- }
-
-}
-
-
-#define PyType_Ready_Attr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, NULL, i)
-#define PyType_Ready_AttrPtr(d, n, i) PyType_Ready_ADD(d, &n::Type, n::Attributes, n::AttributesPtr, i)
-
-
-
-PyDoc_STRVAR(GameTypes_module_documentation,
-"This module provides access to the game engine data types."
-);
-static struct PyModuleDef GameTypes_module_def = {
- PyModuleDef_HEAD_INIT,
- "GameTypes", /* m_name */
- GameTypes_module_documentation, /* m_doc */
- 0, /* m_size */
- NULL, /* m_methods */
- NULL, /* m_reload */
- NULL, /* m_traverse */
- NULL, /* m_clear */
- NULL, /* m_free */
-};
-
-
-PyMODINIT_FUNC initGameTypesPythonBinding(void)
-{
- PyObject *m;
- PyObject *dict;
-
- m = PyModule_Create(&GameTypes_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), GameTypes_module_def.m_name, m);
-
- dict = PyModule_GetDict(m);
-
- for (int init_getset= 1; init_getset > -1; init_getset--) { /* run twice, once to init the getsets another to run PyType_Ready */
- PyType_Ready_Attr(dict, BL_ActionActuator, init_getset);
- PyType_Ready_Attr(dict, BL_Shader, init_getset);
- PyType_Ready_Attr(dict, BL_ShapeActionActuator, init_getset);
- PyType_Ready_Attr(dict, BL_ArmatureObject, init_getset);
- PyType_Ready_Attr(dict, BL_ArmatureActuator, init_getset);
- PyType_Ready_Attr(dict, BL_ArmatureConstraint, init_getset);
- PyType_Ready_AttrPtr(dict, BL_ArmatureBone, init_getset);
- PyType_Ready_AttrPtr(dict, BL_ArmatureChannel, init_getset);
- // PyType_Ready_Attr(dict, CPropValue, init_getset); // doesn't use Py_Header
- PyType_Ready_Attr(dict, CListValue, init_getset);
- PyType_Ready_Attr(dict, CListWrapper, init_getset);
- PyType_Ready_Attr(dict, CValue, init_getset);
- PyType_Ready_Attr(dict, KX_ArmatureSensor, init_getset);
- PyType_Ready_Attr(dict, KX_BlenderMaterial, init_getset);
- PyType_Ready_Attr(dict, KX_Camera, init_getset);
- PyType_Ready_Attr(dict, KX_CameraActuator, init_getset);
- PyType_Ready_Attr(dict, KX_CharacterWrapper, init_getset);
- PyType_Ready_Attr(dict, KX_ConstraintActuator, init_getset);
- PyType_Ready_Attr(dict, KX_ConstraintWrapper, init_getset);
- PyType_Ready_Attr(dict, KX_GameActuator, init_getset);
- PyType_Ready_Attr(dict, KX_GameObject, init_getset);
- PyType_Ready_Attr(dict, KX_LibLoadStatus, init_getset);
- PyType_Ready_Attr(dict, KX_LightObject, init_getset);
- PyType_Ready_Attr(dict, KX_FontObject, init_getset);
- PyType_Ready_Attr(dict, KX_MeshProxy, init_getset);
- PyType_Ready_Attr(dict, KX_MouseFocusSensor, init_getset);
- PyType_Ready_Attr(dict, KX_NearSensor, init_getset);
- PyType_Ready_Attr(dict, KX_NetworkMessageActuator, init_getset);
- PyType_Ready_Attr(dict, KX_NetworkMessageSensor, init_getset);
- PyType_Ready_Attr(dict, KX_ObjectActuator, init_getset);
- PyType_Ready_Attr(dict, KX_ParentActuator, init_getset);
- PyType_Ready_Attr(dict, KX_PolyProxy, init_getset);
- PyType_Ready_Attr(dict, KX_RadarSensor, init_getset);
- PyType_Ready_Attr(dict, KX_RaySensor, init_getset);
- PyType_Ready_Attr(dict, KX_SCA_AddObjectActuator, init_getset);
- PyType_Ready_Attr(dict, KX_SCA_DynamicActuator, init_getset);
- PyType_Ready_Attr(dict, KX_SCA_EndObjectActuator, init_getset);
- PyType_Ready_Attr(dict, KX_SCA_ReplaceMeshActuator, init_getset);
- PyType_Ready_Attr(dict, KX_Scene, init_getset);
- PyType_Ready_Attr(dict, KX_WorldInfo, init_getset);
- PyType_Ready_Attr(dict, KX_NavMeshObject, init_getset);
- PyType_Ready_Attr(dict, KX_SceneActuator, init_getset);
- PyType_Ready_Attr(dict, KX_SoundActuator, init_getset);
- PyType_Ready_Attr(dict, KX_StateActuator, init_getset);
- PyType_Ready_Attr(dict, KX_SteeringActuator, init_getset);
- PyType_Ready_Attr(dict, KX_TouchSensor, init_getset);
- PyType_Ready_Attr(dict, KX_TrackToActuator, init_getset);
- PyType_Ready_Attr(dict, KX_VehicleWrapper, init_getset);
- PyType_Ready_Attr(dict, KX_VertexProxy, init_getset);
- PyType_Ready_Attr(dict, KX_VisibilityActuator, init_getset);
- PyType_Ready_Attr(dict, KX_MouseActuator, init_getset);
- PyType_Ready_Attr(dict, PyObjectPlus, init_getset);
- PyType_Ready_Attr(dict, SCA_2DFilterActuator, init_getset);
- PyType_Ready_Attr(dict, SCA_ANDController, init_getset);
- // PyType_Ready_Attr(dict, SCA_Actuator, init_getset); // doesn't use Py_Header
- PyType_Ready_Attr(dict, SCA_ActuatorSensor, init_getset);
- PyType_Ready_Attr(dict, SCA_AlwaysSensor, init_getset);
- PyType_Ready_Attr(dict, SCA_DelaySensor, init_getset);
- PyType_Ready_Attr(dict, SCA_ILogicBrick, init_getset);
- PyType_Ready_Attr(dict, SCA_IObject, init_getset);
- PyType_Ready_Attr(dict, SCA_ISensor, init_getset);
- PyType_Ready_Attr(dict, SCA_JoystickSensor, init_getset);
- PyType_Ready_Attr(dict, SCA_KeyboardSensor, init_getset);
- PyType_Ready_Attr(dict, SCA_MouseSensor, init_getset);
- PyType_Ready_Attr(dict, SCA_NANDController, init_getset);
- PyType_Ready_Attr(dict, SCA_NORController, init_getset);
- PyType_Ready_Attr(dict, SCA_ORController, init_getset);
- PyType_Ready_Attr(dict, SCA_PropertyActuator, init_getset);
- PyType_Ready_Attr(dict, SCA_PropertySensor, init_getset);
- PyType_Ready_Attr(dict, SCA_PythonController, init_getset);
- PyType_Ready_Attr(dict, SCA_RandomActuator, init_getset);
- PyType_Ready_Attr(dict, SCA_RandomSensor, init_getset);
- PyType_Ready_Attr(dict, SCA_XNORController, init_getset);
- PyType_Ready_Attr(dict, SCA_XORController, init_getset);
- PyType_Ready_Attr(dict, SCA_IController, init_getset);
- PyType_Ready_Attr(dict, SCA_PythonJoystick, init_getset);
- PyType_Ready_Attr(dict, SCA_PythonKeyboard, init_getset);
- PyType_Ready_Attr(dict, SCA_PythonMouse, init_getset);
- }
-
-#ifdef USE_MATHUTILS
- /* Init mathutils callbacks */
- KX_GameObject_Mathutils_Callback_Init();
- KX_ObjectActuator_Mathutils_Callback_Init();
- KX_WorldInfo_Mathutils_Callback_Init();
- KX_BlenderMaterial_Mathutils_Callback_Init();
-#endif
-
- return m;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_PythonInitTypes.h b/source/gameengine/Ketsji/KX_PythonInitTypes.h
deleted file mode 100644
index cfc49a1dc93..00000000000
--- a/source/gameengine/Ketsji/KX_PythonInitTypes.h
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Campbell Barton
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PythonInitTypes.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_PYTHON_INIT_TYPES__
-#define __KX_PYTHON_INIT_TYPES__
-
-#ifdef WITH_PYTHON
-#include <Python.h>
-PyMODINIT_FUNC initGameTypesPythonBinding(void);
-#endif
-
-#endif /* __KX_PYTHON_INIT_TYPES__ */
diff --git a/source/gameengine/Ketsji/KX_PythonMain.cpp b/source/gameengine/Ketsji/KX_PythonMain.cpp
deleted file mode 100644
index 740bb102fd9..00000000000
--- a/source/gameengine/Ketsji/KX_PythonMain.cpp
+++ /dev/null
@@ -1,71 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): Benoit Bolsee
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_PythonMain.cpp
- * \ingroup ketsji
- */
-
-#include "KX_PythonMain.h"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <stddef.h>
-
-#include "MEM_guardedalloc.h"
-
-#include "BLI_string.h"
-#include "BLI_listbase.h"
-
-#include "BKE_text.h"
-#include "BKE_main.h"
-#include "BKE_idprop.h"
-
-
-#ifdef __cplusplus
-}
-#endif
-
-extern "C" char *KX_GetPythonMain(struct Scene *scene)
-{
- /* examine custom scene properties */
- if (scene->id.properties) {
- IDProperty *item = IDP_GetPropertyTypeFromGroup(scene->id.properties, "__main__", IDP_STRING);
- if (item) {
- return BLI_strdup(IDP_String(item));
- }
- }
-
- return NULL;
-}
-
-extern "C" char *KX_GetPythonCode(Main *bmain, char *python_main)
-{
- Text *text;
-
- if ((text = (Text *)BLI_findstring(&bmain->text, python_main, offsetof(ID, name) + 2))) {
- return txt_to_buf(text);
- }
-
- return NULL;
-}
diff --git a/source/gameengine/Ketsji/KX_PythonMain.h b/source/gameengine/Ketsji/KX_PythonMain.h
deleted file mode 100644
index c627a4a147a..00000000000
--- a/source/gameengine/Ketsji/KX_PythonMain.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_PythonMain.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_PYTHON_MAIN__
-#define __KX_PYTHON_MAIN__
-
-#include "BLI_sys_types.h"
-#include "BKE_main.h"
-#include "DNA_scene_types.h"
-extern "C" char *KX_GetPythonMain(struct Scene* scene);
-extern "C" char *KX_GetPythonCode(struct Main *main, char *python_main);
-
-#endif /* __KX_PYTHON_MAIN__ */
diff --git a/source/gameengine/Ketsji/KX_RadarSensor.cpp b/source/gameengine/Ketsji/KX_RadarSensor.cpp
deleted file mode 100644
index 861e3f70296..00000000000
--- a/source/gameengine/Ketsji/KX_RadarSensor.cpp
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_RadarSensor.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_RadarSensor.h"
-#include "KX_GameObject.h"
-#include "KX_PyMath.h"
-#include "PHY_IPhysicsController.h"
-#include "PHY_IMotionState.h"
-#include "DNA_sensor_types.h"
-
-/**
- * RadarSensor constructor. Creates a near-sensor derived class, with a cone collision shape.
- */
-KX_RadarSensor::KX_RadarSensor(SCA_EventManager* eventmgr,
- KX_GameObject* gameobj,
- PHY_IPhysicsController* physCtrl,
- double coneradius,
- double coneheight,
- int axis,
- double margin,
- double resetmargin,
- bool bFindMaterial,
- const STR_String& touchedpropname)
-
- : KX_NearSensor(
- eventmgr,
- gameobj,
- //DT_NewCone(coneradius,coneheight),
- margin,
- resetmargin,
- bFindMaterial,
- touchedpropname,
- physCtrl),
-
- m_coneradius(coneradius),
- m_coneheight(coneheight),
- m_axis(axis)
-{
- m_client_info->m_type = KX_ClientObjectInfo::SENSOR;
- //m_client_info->m_clientobject = gameobj;
- //m_client_info->m_auxilary_info = NULL;
- //sumoObj->setClientObject(&m_client_info);
-}
-
-KX_RadarSensor::~KX_RadarSensor()
-{
-
-}
-
-CValue* KX_RadarSensor::GetReplica()
-{
- KX_RadarSensor* replica = new KX_RadarSensor(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-/**
- * Transforms the collision object. A cone is not correctly centered
- * for usage. */
-void KX_RadarSensor::SynchronizeTransform()
-{
- // Getting the parent location was commented out. Why?
- MT_Transform trans;
- trans.setOrigin(((KX_GameObject*)GetParent())->NodeGetWorldPosition());
- trans.setBasis(((KX_GameObject*)GetParent())->NodeGetWorldOrientation());
- // What is the default orientation? pointing in the -y direction?
- // is the geometry correctly converted?
-
- // a collision cone is oriented
- // center the cone correctly
- // depends on the radar 'axis'
- switch (m_axis)
- {
- case SENS_RADAR_X_AXIS: // +X Axis
- {
- MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(90));
- trans.rotate(rotquatje);
- trans.translate(MT_Vector3 (0, -m_coneheight/2.0f, 0));
- break;
- };
- case SENS_RADAR_Y_AXIS: // +Y Axis
- {
- MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
- trans.rotate(rotquatje);
- trans.translate(MT_Vector3 (0, -m_coneheight/2.0f, 0));
- break;
- };
- case SENS_RADAR_Z_AXIS: // +Z Axis
- {
- MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-90));
- trans.rotate(rotquatje);
- trans.translate(MT_Vector3 (0, -m_coneheight/2.0f, 0));
- break;
- };
- case SENS_RADAR_NEG_X_AXIS: // -X Axis
- {
- MT_Quaternion rotquatje(MT_Vector3(0,0,1),MT_radians(-90));
- trans.rotate(rotquatje);
- trans.translate(MT_Vector3 (0, -m_coneheight/2.0f, 0));
- break;
- };
- case SENS_RADAR_NEG_Y_AXIS: // -Y Axis
- {
- //MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(-180));
- //trans.rotate(rotquatje);
- trans.translate(MT_Vector3 (0, -m_coneheight/2.0f, 0));
- break;
- };
- case SENS_RADAR_NEG_Z_AXIS: // -Z Axis
- {
- MT_Quaternion rotquatje(MT_Vector3(1,0,0),MT_radians(90));
- trans.rotate(rotquatje);
- trans.translate(MT_Vector3 (0, -m_coneheight/2.0f, 0));
- break;
- };
- default:
- {
- }
- }
-
- //Using a temp variable to translate MT_Point3 to float[3].
- //float[3] works better for the Python interface.
- MT_Point3 temp = trans.getOrigin();
- m_cone_origin[0] = temp[0];
- m_cone_origin[1] = temp[1];
- m_cone_origin[2] = temp[2];
-
- temp = trans(MT_Point3(0, -m_coneheight/2.0f, 0));
- m_cone_target[0] = temp[0];
- m_cone_target[1] = temp[1];
- m_cone_target[2] = temp[2];
-
-
- if (m_physCtrl)
- {
- PHY_IMotionState* motionState = m_physCtrl->GetMotionState();
- const MT_Point3& pos = trans.getOrigin();
- float ori[12];
- trans.getBasis().getValue(ori);
- motionState->SetWorldPosition(pos[0], pos[1], pos[2]);
- motionState->SetWorldOrientation(ori);
- m_physCtrl->WriteMotionStateToDynamics(true);
- }
-
-}
-
-/* ------------------------------------------------------------------------- */
-/* Python Functions */
-/* ------------------------------------------------------------------------- */
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python Integration Hooks */
-/* ------------------------------------------------------------------------- */
-PyTypeObject KX_RadarSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_RadarSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &KX_NearSensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_RadarSensor::Methods[] = {
- {NULL} //Sentinel
-};
-
-PyAttributeDef KX_RadarSensor::Attributes[] = {
- KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneOrigin", KX_RadarSensor, m_cone_origin, 3),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RO("coneTarget", KX_RadarSensor, m_cone_target, 3),
- KX_PYATTRIBUTE_FLOAT_RO("distance", KX_RadarSensor, m_coneheight),
- KX_PYATTRIBUTE_RO_FUNCTION("angle", KX_RadarSensor, pyattr_get_angle),
- KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RadarSensor, m_axis),
- {NULL} //Sentinel
-};
-
-PyObject *KX_RadarSensor::pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_RadarSensor* self = static_cast<KX_RadarSensor*>(self_v);
-
- // The original angle from the gui was converted, so we recalculate the value here to maintain
- // consistency between Python and the gui
- return PyFloat_FromDouble(MT_degrees(atan(self->m_coneradius / self->m_coneheight)) * 2);
-
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_RadarSensor.h b/source/gameengine/Ketsji/KX_RadarSensor.h
deleted file mode 100644
index 6a2d50ffa3a..00000000000
--- a/source/gameengine/Ketsji/KX_RadarSensor.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_RadarSensor.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_RADARSENSOR_H__
-#define __KX_RADARSENSOR_H__
-
-#include "KX_NearSensor.h"
-#include "MT_Point3.h"
-
-/**
- * Radar 'cone' sensor. Very similar to a near-sensor, but instead of a sphere, a cone is used.
- */
-class KX_RadarSensor : public KX_NearSensor
-{
- protected:
- Py_Header
-
- float m_coneradius;
-
- /**
- * Height of the cone.
- */
- float m_coneheight;
- int m_axis;
-
- /**
- * The previous position of the origin of the cone.
- */
- float m_cone_origin[3];
-
- /**
- * The previous direction of the cone (origin to bottom plane).
- */
- float m_cone_target[3];
-
-public:
-
- KX_RadarSensor(SCA_EventManager* eventmgr,
- KX_GameObject* gameobj,
- PHY_IPhysicsController* physCtrl,
- double coneradius,
- double coneheight,
- int axis,
- double margin,
- double resetmargin,
- bool bFindMaterial,
- const STR_String& touchedpropname);
- KX_RadarSensor();
- virtual ~KX_RadarSensor();
- virtual void SynchronizeTransform();
- virtual CValue* GetReplica();
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
- enum RadarAxis {
- KX_RADAR_AXIS_POS_X = 0,
- KX_RADAR_AXIS_POS_Y,
- KX_RADAR_AXIS_POS_Z,
- KX_RADAR_AXIS_NEG_X,
- KX_RADAR_AXIS_NEG_Y,
- KX_RADAR_AXIS_NEG_Z
- };
-
- virtual sensortype GetSensorType() { return ST_RADAR; }
- /* python */
-#ifdef WITH_PYTHON
- static PyObject* pyattr_get_angle(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-#endif
-};
-
-#endif /* __KX_RADARSENSOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_RayCast.cpp b/source/gameengine/Ketsji/KX_RayCast.cpp
deleted file mode 100644
index 478019c6304..00000000000
--- a/source/gameengine/Ketsji/KX_RayCast.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * KX_MouseFocusSensor determines mouse in/out/over events.
- */
-
-/** \file gameengine/Ketsji/KX_RayCast.cpp
- * \ingroup ketsji
- */
-
-
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "KX_RayCast.h"
-
-#include "MT_Point3.h"
-#include "MT_Vector3.h"
-
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IPhysicsController.h"
-
-KX_RayCast::KX_RayCast(PHY_IPhysicsController* ignoreController, bool faceNormal, bool faceUV)
- :PHY_IRayCastFilterCallback(ignoreController, faceNormal, faceUV)
-{
-}
-
-void KX_RayCast::reportHit(PHY_RayCastResult* result)
-{
- m_hitFound = true;
- m_hitPoint = MT_Vector3(result->m_hitPoint);
- m_hitNormal = MT_Vector3(result->m_hitNormal);
- m_hitUVOK = result->m_hitUVOK;
- m_hitUV = MT_Vector2(result->m_hitUV);
- m_hitMesh = result->m_meshObject;
- m_hitPolygon = result->m_polygon;
-}
-
-bool KX_RayCast::RayTest(PHY_IPhysicsEnvironment* physics_environment, const MT_Point3& _frompoint, const MT_Point3& topoint, KX_RayCast& callback)
-{
- if (physics_environment==NULL) return false; /* prevents crashing in some cases */
-
- // Loops over all physics objects between frompoint and topoint,
- // calling callback.RayHit for each one.
- //
- // callback.RayHit should return true to stop looking, or false to continue.
- //
- // returns true if an object was found, false if not.
-
- MT_Point3 frompoint(_frompoint);
- const MT_Vector3 todir( (topoint - frompoint).safe_normalized() );
- MT_Point3 prevpoint(_frompoint+todir*(-1.f));
-
- PHY_IPhysicsController* hit_controller;
-
- while ((hit_controller = physics_environment->RayTest(callback,
- frompoint.x(),frompoint.y(),frompoint.z(),
- topoint.x(),topoint.y(),topoint.z())) != NULL)
- {
- KX_ClientObjectInfo *info = static_cast<KX_ClientObjectInfo*>(hit_controller->GetNewClientInfo());
-
- if (!info)
- {
- printf("no info!\n");
- MT_assert(info && "Physics controller with no client object info");
- break;
- }
-
- // The biggest danger to endless loop, prevent this by checking that the
- // hit point always progresses along the ray direction..
- prevpoint -= callback.m_hitPoint;
- if (prevpoint.length2() < MT_EPSILON)
- break;
-
- if (callback.RayHit(info))
- // caller may decide to stop the loop and still cancel the hit
- return callback.m_hitFound;
-
- // Skip past the object and keep tracing.
- // Note that retrieving in a single shot multiple hit points would be possible
- // but it would require some change in Bullet.
- prevpoint = callback.m_hitPoint;
- /* We add 0.001 of fudge, so that if the margin && radius == 0.0, we don't endless loop. */
- MT_Scalar marg = 0.001f + hit_controller->GetMargin();
- marg *= 2.f;
- /* Calculate the other side of this object */
- MT_Scalar h = MT_abs(todir.dot(callback.m_hitNormal));
- if (h <= 0.01f)
- // the normal is almost orthogonal to the ray direction, cannot compute the other side
- break;
- marg /= h;
- frompoint = callback.m_hitPoint + marg * todir;
- // verify that we are not passed the to point
- if ((topoint - frompoint).dot(todir) < 0.f)
- break;
- }
- return false;
-}
-
diff --git a/source/gameengine/Ketsji/KX_RayCast.h b/source/gameengine/Ketsji/KX_RayCast.h
deleted file mode 100644
index c977fb8f385..00000000000
--- a/source/gameengine/Ketsji/KX_RayCast.h
+++ /dev/null
@@ -1,149 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_RayCast.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_RAYCAST_H__
-#define __KX_RAYCAST_H__
-
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IPhysicsController.h"
-#include "MT_Vector2.h"
-#include "MT_Point3.h"
-#include "MT_Vector3.h"
-
-class RAS_MeshObject;
-struct KX_ClientObjectInfo;
-
-/**
- * Defines a function for doing a ray cast.
- *
- * eg KX_RayCast::RayTest(ignore_physics_controller, physics_environment, frompoint, topoint, result_point, result_normal, KX_RayCast::Callback<MyClass, MyDataClass>(this, data)
- *
- * Calls myclass->NeedRayCast(client, data) for all client in environment
- * and myclass->RayHit(client, hit_point, hit_normal, data) for all client
- * between frompoint and topoint
- *
- * myclass->NeedRayCast should return true to ray test the current client.
- *
- * myclass->RayHit should return true to end the raycast, false to ignore the current client and to continue.
- *
- * Returns true if a client was accepted, false if nothing found.
- */
-class KX_RayCast : public PHY_IRayCastFilterCallback
-{
-public:
- bool m_hitFound;
- MT_Point3 m_hitPoint;
- MT_Vector3 m_hitNormal;
- const RAS_MeshObject* m_hitMesh;
- int m_hitPolygon;
- int m_hitUVOK; // !=0 if UV coordinate in m_hitUV is valid
- MT_Vector2 m_hitUV;
-
- KX_RayCast(PHY_IPhysicsController* ignoreController, bool faceNormal, bool faceUV);
- virtual ~KX_RayCast() {}
-
- /**
- * The physic environment returns the ray casting result through this function
- */
- virtual void reportHit(PHY_RayCastResult* result);
-
- /** ray test callback.
- * either override this in your class, or use a callback wrapper.
- */
- virtual bool RayHit(KX_ClientObjectInfo* client) = 0;
-
- /**
- * Callback wrapper.
- *
- * Construct with KX_RayCast::Callback<MyClass, MyDataClass>(this, data)
- * and pass to KX_RayCast::RayTest
- */
- template<class T, class dataT> class Callback;
-
- /// Public interface.
- /// Implement bool RayHit in your class to receive ray callbacks.
- static bool RayTest(
- PHY_IPhysicsEnvironment* physics_environment,
- const MT_Point3& frompoint,
- const MT_Point3& topoint,
- KX_RayCast& callback);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_RayCast")
-#endif
-};
-
-template<class T, class dataT>
-class KX_RayCast::Callback : public KX_RayCast
-{
- T *self;
- /**
- * Some user info passed as argument in constructor.
- * It contains all info needed to check client in NeedRayCast
- * and RayHit.
- */
- dataT *data;
-public:
- Callback(T *_self, PHY_IPhysicsController *controller = NULL, dataT *_data = NULL, bool faceNormal = false, bool faceUV = false)
- : KX_RayCast(controller, faceNormal, faceUV),
- self(_self),
- data(_data)
- {
- }
-
- ~Callback() {}
-
- virtual bool RayHit(KX_ClientObjectInfo* client)
- {
- return self->RayHit(client, this, data);
- }
-
- virtual bool needBroadphaseRayCast(PHY_IPhysicsController* controller)
- {
- KX_ClientObjectInfo* info = static_cast<KX_ClientObjectInfo*>(controller->GetNewClientInfo());
-
- if (!info)
- {
- MT_assert(info && "Physics controller with no client object info");
- return false;
- }
- return self->NeedRayCast(info, data);
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_RayCast::Callback")
-#endif
-};
-
-
-#endif
diff --git a/source/gameengine/Ketsji/KX_RayEventManager.cpp b/source/gameengine/Ketsji/KX_RayEventManager.cpp
deleted file mode 100644
index 661c7eb6f64..00000000000
--- a/source/gameengine/Ketsji/KX_RayEventManager.cpp
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * Manager for ray events
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_RayEventManager.cpp
- * \ingroup ketsji
- */
-
-#include "KX_RayEventManager.h"
-#include "SCA_LogicManager.h"
-#include "SCA_ISensor.h"
-#include <vector>
-
-using namespace std;
-
-#include <iostream>
-#include <stdio.h>
-
-void KX_RayEventManager::NextFrame()
-{
- SG_DList::iterator<SCA_ISensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->Activate(m_logicmgr);
- }
-}
-
diff --git a/source/gameengine/Ketsji/KX_RayEventManager.h b/source/gameengine/Ketsji/KX_RayEventManager.h
deleted file mode 100644
index 07506b9e32b..00000000000
--- a/source/gameengine/Ketsji/KX_RayEventManager.h
+++ /dev/null
@@ -1,53 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_RayEventManager.h
- * \ingroup ketsji
- * \brief Manager for ray events
- */
-
-#ifndef __KX_RAYEVENTMANAGER_H__
-#define __KX_RAYEVENTMANAGER_H__
-#include "SCA_EventManager.h"
-#include <vector>
-using namespace std;
-
-class KX_RayEventManager : public SCA_EventManager
-{
-public:
- KX_RayEventManager(class SCA_LogicManager* logicmgr)
- : SCA_EventManager(logicmgr, RAY_EVENTMGR)
- {}
- virtual void NextFrame();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_RayEventManager")
-#endif
-};
-
-#endif /* __KX_RAYEVENTMANAGER_H__ */
diff --git a/source/gameengine/Ketsji/KX_RaySensor.cpp b/source/gameengine/Ketsji/KX_RaySensor.cpp
deleted file mode 100644
index 4ffb5f332db..00000000000
--- a/source/gameengine/Ketsji/KX_RaySensor.cpp
+++ /dev/null
@@ -1,383 +0,0 @@
-/*
- * Cast a ray and feel for objects
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_RaySensor.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_RaySensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_RandomEventManager.h"
-#include "SCA_LogicManager.h"
-#include "SCA_IObject.h"
-#include "KX_ClientObjectInfo.h"
-#include "KX_GameObject.h"
-#include "KX_Scene.h"
-#include "KX_RayCast.h"
-#include "KX_PyMath.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IPhysicsController.h"
-#include "DNA_sensor_types.h"
-#include "RAS_MeshObject.h"
-
-#include <stdio.h>
-
-
-KX_RaySensor::KX_RaySensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const STR_String& propname,
- bool bFindMaterial,
- bool bXRay,
- double distance,
- int axis,
- KX_Scene* ketsjiScene)
- : SCA_ISensor(gameobj,eventmgr),
- m_propertyname(propname),
- m_bFindMaterial(bFindMaterial),
- m_bXRay(bXRay),
- m_distance(distance),
- m_scene(ketsjiScene),
- m_axis(axis),
- m_hitMaterial("")
-{
- Init();
-}
-
-void KX_RaySensor::Init()
-{
- m_bTriggered = (m_invert)?true:false;
- m_rayHit = false;
- m_hitObject = NULL;
- m_reset = true;
-}
-
-KX_RaySensor::~KX_RaySensor()
-{
- /* Nothing to be done here. */
-}
-
-
-
-CValue* KX_RaySensor::GetReplica()
-{
- KX_RaySensor* replica = new KX_RaySensor(*this);
- replica->ProcessReplica();
- replica->Init();
-
- return replica;
-}
-
-
-
-bool KX_RaySensor::IsPositiveTrigger()
-{
- bool result = m_rayHit;
-
- if (m_invert)
- result = !result;
-
- return result;
-}
-
-bool KX_RaySensor::RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void *UNUSED(data))
-{
-
- KX_GameObject* hitKXObj = client->m_gameobject;
- bool bFound = false;
- bool hitMaterial = false;
-
- if (m_propertyname.Length() == 0)
- {
- bFound = true;
- }
- else
- {
- if (m_bFindMaterial) {
- for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) {
- RAS_MeshObject *meshObj = hitKXObj->GetMesh(i);
- for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) {
- bFound = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0;
- if (bFound) {
- hitMaterial = true;
- break;
- }
- }
- }
- }
- else {
- bFound = hitKXObj->GetProperty(m_propertyname) != NULL;
- }
- }
-
- if (bFound)
- {
- m_rayHit = true;
- m_hitObject = hitKXObj;
- m_hitPosition[0] = result->m_hitPoint[0];
- m_hitPosition[1] = result->m_hitPoint[1];
- m_hitPosition[2] = result->m_hitPoint[2];
-
- m_hitNormal[0] = result->m_hitNormal[0];
- m_hitNormal[1] = result->m_hitNormal[1];
- m_hitNormal[2] = result->m_hitNormal[2];
-
- m_hitMaterial = hitMaterial;
- }
- // no multi-hit search yet
- return true;
-}
-
-/* this function is used to pre-filter the object before casting the ray on them.
- * This is useful for "X-Ray" option when we want to see "through" unwanted object.
- */
-bool KX_RaySensor::NeedRayCast(KX_ClientObjectInfo *client, void *UNUSED(data))
-{
- KX_GameObject *hitKXObj = client->m_gameobject;
-
- if (client->m_type > KX_ClientObjectInfo::ACTOR)
- {
- // Unknown type of object, skip it.
- // Should not occur as the sensor objects are filtered in RayTest()
- printf("Invalid client type %d found ray casting\n", client->m_type);
- return false;
- }
- if (m_bXRay && m_propertyname.Length() != 0)
- {
- if (m_bFindMaterial) {
- bool found = false;
- for (unsigned int i = 0; i < hitKXObj->GetMeshCount(); ++i) {
- RAS_MeshObject *meshObj = hitKXObj->GetMesh(i);
- for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) {
- found = strcmp(m_propertyname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0;
- if (found)
- break;
- }
- }
- if (!found)
- return false;
- }
- else {
- if (hitKXObj->GetProperty(m_propertyname) == NULL)
- return false;
- }
- }
- return true;
-}
-
-bool KX_RaySensor::Evaluate()
-{
- bool result = false;
- bool reset = m_reset && m_level;
- m_rayHit = false;
- m_hitObject = NULL;
- m_hitPosition[0] = 0;
- m_hitPosition[1] = 0;
- m_hitPosition[2] = 0;
-
- m_hitNormal[0] = 1;
- m_hitNormal[1] = 0;
- m_hitNormal[2] = 0;
-
- KX_GameObject* obj = (KX_GameObject*)GetParent();
- MT_Point3 frompoint = obj->NodeGetWorldPosition();
- MT_Matrix3x3 matje = obj->NodeGetWorldOrientation();
- MT_Matrix3x3 invmat = matje.inverse();
-
- MT_Vector3 todir;
- m_reset = false;
- switch (m_axis)
- {
- case SENS_RAY_X_AXIS: // X
- {
- todir[0] = invmat[0][0];
- todir[1] = invmat[0][1];
- todir[2] = invmat[0][2];
- break;
- }
- case SENS_RAY_Y_AXIS: // Y
- {
- todir[0] = invmat[1][0];
- todir[1] = invmat[1][1];
- todir[2] = invmat[1][2];
- break;
- }
- case SENS_RAY_Z_AXIS: // Z
- {
- todir[0] = invmat[2][0];
- todir[1] = invmat[2][1];
- todir[2] = invmat[2][2];
- break;
- }
- case SENS_RAY_NEG_X_AXIS: // -X
- {
- todir[0] = -invmat[0][0];
- todir[1] = -invmat[0][1];
- todir[2] = -invmat[0][2];
- break;
- }
- case SENS_RAY_NEG_Y_AXIS: // -Y
- {
- todir[0] = -invmat[1][0];
- todir[1] = -invmat[1][1];
- todir[2] = -invmat[1][2];
- break;
- }
- case SENS_RAY_NEG_Z_AXIS: // -Z
- {
- todir[0] = -invmat[2][0];
- todir[1] = -invmat[2][1];
- todir[2] = -invmat[2][2];
- break;
- }
- }
- todir.normalize();
- m_rayDirection[0] = todir[0];
- m_rayDirection[1] = todir[1];
- m_rayDirection[2] = todir[2];
-
- MT_Point3 topoint = frompoint + (m_distance) * todir;
- PHY_IPhysicsEnvironment* pe = m_scene->GetPhysicsEnvironment();
-
- if (!pe)
- {
- std::cout << "WARNING: Ray sensor " << GetName() << ": There is no physics environment!" << std::endl;
- std::cout << " Check universe for malfunction." << std::endl;
- return false;
- }
-
- PHY_IPhysicsController *spc = obj->GetPhysicsController();
- KX_GameObject *parent = obj->GetParent();
- if (!spc && parent)
- spc = parent->GetPhysicsController();
-
-
- PHY_IPhysicsEnvironment* physics_environment = this->m_scene->GetPhysicsEnvironment();
-
-
- KX_RayCast::Callback<KX_RaySensor, void> callback(this, spc);
- KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback);
-
- /* now pass this result to some controller */
-
- if (m_rayHit)
- {
- if (!m_bTriggered)
- {
- // notify logicsystem that ray is now hitting
- result = true;
- m_bTriggered = true;
- }
- else
- {
- // notify logicsystem that ray is STILL hitting ...
- result = false;
-
- }
- }
- else
- {
- if (m_bTriggered)
- {
- m_bTriggered = false;
- // notify logicsystem that ray JUST left the Object
- result = true;
- }
- else
- {
- result = false;
- }
-
- }
- if (reset)
- // force an event
- result = true;
-
- return result;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_RaySensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_RaySensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-
-};
-
-PyMethodDef KX_RaySensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_RaySensor::Attributes[] = {
- KX_PYATTRIBUTE_BOOL_RW("useMaterial", KX_RaySensor, m_bFindMaterial),
- KX_PYATTRIBUTE_BOOL_RW("useXRay", KX_RaySensor, m_bXRay),
- KX_PYATTRIBUTE_FLOAT_RW("range", 0, 10000, KX_RaySensor, m_distance),
- KX_PYATTRIBUTE_STRING_RW("propName", 0, MAX_PROP_NAME, false, KX_RaySensor, m_propertyname),
- KX_PYATTRIBUTE_INT_RW("axis", 0, 5, true, KX_RaySensor, m_axis),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitPosition", KX_RaySensor, m_hitPosition, 3),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RO("rayDirection", KX_RaySensor, m_rayDirection, 3),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RO("hitNormal", KX_RaySensor, m_hitNormal, 3),
- KX_PYATTRIBUTE_STRING_RO("hitMaterial", KX_RaySensor, m_hitMaterial),
- KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_RaySensor, pyattr_get_hitobject),
- { NULL } //Sentinel
-};
-
-PyObject *KX_RaySensor::pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_RaySensor* self = static_cast<KX_RaySensor*>(self_v);
- if (self->m_hitObject)
- return self->m_hitObject->GetProxy();
-
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_RaySensor.h b/source/gameengine/Ketsji/KX_RaySensor.h
deleted file mode 100644
index 1901bb04f86..00000000000
--- a/source/gameengine/Ketsji/KX_RaySensor.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_RaySensor.h
- * \ingroup ketsji
- * \brief Cast a ray and feel for objects
- */
-
-#ifndef __KX_RAYSENSOR_H__
-#define __KX_RAYSENSOR_H__
-
-#include "SCA_ISensor.h"
-#include "MT_Point3.h"
-#include "SCA_IScene.h" /* only for scene replace */
-#include "KX_Scene.h" /* only for scene replace */
-
-#include "BLI_utildefines.h"
-
-struct KX_ClientObjectInfo;
-class KX_RayCast;
-
-class KX_RaySensor : public SCA_ISensor
-{
- Py_Header
- STR_String m_propertyname;
- bool m_bFindMaterial;
- bool m_bXRay;
- float m_distance;
- class KX_Scene* m_scene;
- bool m_bTriggered;
- int m_axis;
- bool m_rayHit;
- float m_hitPosition[3];
- SCA_IObject* m_hitObject;
- float m_hitNormal[3];
- float m_rayDirection[3];
- STR_String m_hitMaterial;
-
-public:
- KX_RaySensor(class SCA_EventManager* eventmgr,
- SCA_IObject* gameobj,
- const STR_String& propname,
- bool bFindMaterial,
- bool bXRay,
- double distance,
- int axis,
- class KX_Scene* ketsjiScene);
- virtual ~KX_RaySensor();
- virtual CValue* GetReplica();
-
- virtual bool Evaluate();
- virtual bool IsPositiveTrigger();
- virtual void Init();
-
- /// \see KX_RayCast
- bool RayHit(KX_ClientObjectInfo *client, KX_RayCast *result, void *UNUSED(data));
- /// \see KX_RayCast
- bool NeedRayCast(KX_ClientObjectInfo *client, void *UNUSED(data));
-
- virtual void Replace_IScene(SCA_IScene *val)
- {
- m_scene= static_cast<KX_Scene *>(val);
- }
-
- //Python Interface
- // odd order, see: SENS_RAY_X_AXIS
- enum RayAxis {
- KX_RAY_AXIS_POS_X = 1,
- KX_RAY_AXIS_POS_Y = 0,
- KX_RAY_AXIS_POS_Z = 2,
- KX_RAY_AXIS_NEG_X = 3,
- KX_RAY_AXIS_NEG_Y = 4,
- KX_RAY_AXIS_NEG_Z = 5,
- };
-
-#ifdef WITH_PYTHON
-
- /* Attributes */
- static PyObject *pyattr_get_hitobject(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __KX_RAYSENSOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
deleted file mode 100644
index bb38d8269b7..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
+++ /dev/null
@@ -1,284 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_SCA_AddObjectActuator.cpp
- * \ingroup ketsji
- *
- * Add an object when this actuator is triggered
- */
-
-/* Previously existed as:
- * \source\gameengine\GameLogic\SCA_AddObjectActuator.cpp
- * Please look here for revision history. */
-
-#include "KX_SCA_AddObjectActuator.h"
-#include "SCA_IScene.h"
-#include "KX_GameObject.h"
-#include "EXP_PyObjectPlus.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_SCA_AddObjectActuator::KX_SCA_AddObjectActuator(SCA_IObject *gameobj,
- SCA_IObject *original,
- int time,
- SCA_IScene* scene,
- const float *linvel,
- bool linv_local,
- const float *angvel,
- bool angv_local)
- :
- SCA_IActuator(gameobj, KX_ACT_ADD_OBJECT),
- m_OriginalObject(original),
- m_scene(scene),
-
- m_localLinvFlag(linv_local),
- m_localAngvFlag(angv_local)
-{
- m_linear_velocity[0] = linvel[0];
- m_linear_velocity[1] = linvel[1];
- m_linear_velocity[2] = linvel[2];
- m_angular_velocity[0] = angvel[0];
- m_angular_velocity[1] = angvel[1];
- m_angular_velocity[2] = angvel[2];
-
- if (m_OriginalObject)
- m_OriginalObject->RegisterActuator(this);
-
- m_lastCreatedObject = NULL;
- m_timeProp = time;
-}
-
-
-
-KX_SCA_AddObjectActuator::~KX_SCA_AddObjectActuator()
-{
- if (m_OriginalObject)
- m_OriginalObject->UnregisterActuator(this);
- if (m_lastCreatedObject)
- m_lastCreatedObject->UnregisterActuator(this);
-}
-
-
-
-bool KX_SCA_AddObjectActuator::Update()
-{
- //bool result = false; /*unused*/
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent) return false; // do nothing on negative events
-
- InstantAddObject();
-
-
- return false;
-}
-
-
-
-
-SCA_IObject* KX_SCA_AddObjectActuator::GetLastCreatedObject() const
-{
- return m_lastCreatedObject;
-}
-
-
-
-CValue* KX_SCA_AddObjectActuator::GetReplica()
-{
- KX_SCA_AddObjectActuator* replica = new KX_SCA_AddObjectActuator(*this);
-
- if (replica == NULL)
- return NULL;
-
- // this will copy properties and so on...
- replica->ProcessReplica();
-
- return replica;
-}
-
-void KX_SCA_AddObjectActuator::ProcessReplica()
-{
- if (m_OriginalObject)
- m_OriginalObject->RegisterActuator(this);
- m_lastCreatedObject=NULL;
- SCA_IActuator::ProcessReplica();
-}
-
-bool KX_SCA_AddObjectActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == m_OriginalObject)
- {
- // this object is being deleted, we cannot continue to track it.
- m_OriginalObject = NULL;
- return true;
- }
- if (clientobj == m_lastCreatedObject)
- {
- // this object is being deleted, we cannot continue to track it.
- m_lastCreatedObject = NULL;
- return true;
- }
- return false;
-}
-
-void KX_SCA_AddObjectActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_OriginalObject];
- if (h_obj) {
- if (m_OriginalObject)
- m_OriginalObject->UnregisterActuator(this);
- m_OriginalObject = (SCA_IObject*)(*h_obj);
- m_OriginalObject->RegisterActuator(this);
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_SCA_AddObjectActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_SCA_AddObjectActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_SCA_AddObjectActuator::Methods[] = {
- {"instantAddObject", (PyCFunction) KX_SCA_AddObjectActuator::sPyInstantAddObject, METH_NOARGS, NULL},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_SCA_AddObjectActuator::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("object",KX_SCA_AddObjectActuator,pyattr_get_object,pyattr_set_object),
- KX_PYATTRIBUTE_RO_FUNCTION("objectLastCreated",KX_SCA_AddObjectActuator,pyattr_get_objectLastCreated),
- KX_PYATTRIBUTE_INT_RW("time",0,2000,true,KX_SCA_AddObjectActuator,m_timeProp),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RW("linearVelocity",-FLT_MAX,FLT_MAX,KX_SCA_AddObjectActuator,m_linear_velocity,3),
- KX_PYATTRIBUTE_FLOAT_ARRAY_RW("angularVelocity",-FLT_MAX,FLT_MAX,KX_SCA_AddObjectActuator,m_angular_velocity,3),
- { NULL } //Sentinel
-};
-
-PyObject *KX_SCA_AddObjectActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
- if (!actuator->m_OriginalObject)
- Py_RETURN_NONE;
- else
- return actuator->m_OriginalObject->GetProxy();
-}
-
-int KX_SCA_AddObjectActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SCA_AddObjectActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (actuator->m_OriginalObject != NULL)
- actuator->m_OriginalObject->UnregisterActuator(actuator);
-
- actuator->m_OriginalObject = (SCA_IObject*)gameobj;
-
- if (actuator->m_OriginalObject)
- actuator->m_OriginalObject->RegisterActuator(actuator);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_SCA_AddObjectActuator::pyattr_get_objectLastCreated(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SCA_AddObjectActuator* actuator = static_cast<KX_SCA_AddObjectActuator*>(self);
- if (!actuator->m_lastCreatedObject)
- Py_RETURN_NONE;
- else
- return actuator->m_lastCreatedObject->GetProxy();
-}
-
-PyObject *KX_SCA_AddObjectActuator::PyInstantAddObject()
-{
- InstantAddObject();
-
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
-
-void KX_SCA_AddObjectActuator::InstantAddObject()
-{
- if (m_OriginalObject)
- {
- // Add an identical object, with properties inherited from the original object
- // Now it needs to be added to the current scene.
- SCA_IObject* replica = m_scene->AddReplicaObject(m_OriginalObject,GetParent(),m_timeProp );
- KX_GameObject * game_obj = static_cast<KX_GameObject *>(replica);
- game_obj->setLinearVelocity(m_linear_velocity, m_localLinvFlag);
- game_obj->setAngularVelocity(m_angular_velocity,m_localAngvFlag);
- game_obj->ResolveCombinedVelocities(m_linear_velocity, m_angular_velocity, m_localLinvFlag, m_localAngvFlag);
-
- // keep a copy of the last object, to allow python scripters to change it
- if (m_lastCreatedObject)
- {
- //Let's not keep a reference to the object: it's bad, if the object is deleted
- //this will force to keep a "zombie" in the game for no good reason.
- //m_scene->DelayedReleaseObject(m_lastCreatedObject);
- //m_lastCreatedObject->Release();
-
- //Instead we use the registration mechanism
- m_lastCreatedObject->UnregisterActuator(this);
- m_lastCreatedObject = NULL;
- }
-
- m_lastCreatedObject = replica;
- // no reference
- //m_lastCreatedObject->AddRef();
- // but registration
- m_lastCreatedObject->RegisterActuator(this);
- // finished using replica? then release it
- replica->Release();
- }
-}
diff --git a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h
deleted file mode 100644
index 976f3c58d68..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_AddObjectActuator.h
+++ /dev/null
@@ -1,133 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SCA_AddObjectActuator.h
- * \ingroup ketsji
- * \attention Previously existed as: source/gameengine/GameLogic/SCA_AddObjectActuator.h
- * Please look here for revision history.
- */
-
-#ifndef __KX_SCA_ADDOBJECTACTUATOR_H__
-#define __KX_SCA_ADDOBJECTACTUATOR_H__
-
-/* Actuator tree */
-#include "SCA_IActuator.h"
-#include "SCA_LogicManager.h"
-
-#include "MT_Vector3.h"
-
-
-class SCA_IScene;
-
-class KX_SCA_AddObjectActuator : public SCA_IActuator
-{
- Py_Header
-
- /// Time field: lifetime of the new object
- int m_timeProp;
-
- /// Original object reference (object to replicate)
- SCA_IObject* m_OriginalObject;
-
- /// Object will be added to the following scene
- SCA_IScene* m_scene;
-
- /// Linear velocity upon creation of the object.
- float m_linear_velocity[3];
- /// Apply the velocity locally
- bool m_localLinvFlag;
-
- /// Angular velocity upon creation of the object.
- float m_angular_velocity[3];
- /// Apply the velocity locally
- bool m_localAngvFlag;
-
-
-
-
- SCA_IObject* m_lastCreatedObject;
-
-public:
-
- /**
- * This class also has the default constructors
- * available. Use with care!
- */
-
- KX_SCA_AddObjectActuator(
- SCA_IObject *gameobj,
- SCA_IObject *original,
- int time,
- SCA_IScene* scene,
- const float *linvel,
- bool linv_local,
- const float *angvel,
- bool angv_local
- );
-
- ~KX_SCA_AddObjectActuator(void);
-
- CValue*
- GetReplica(
- );
-
- virtual void
- ProcessReplica();
-
- virtual void Replace_IScene(SCA_IScene *val)
- {
- m_scene= val;
- };
-
- virtual bool
- UnlinkObject(SCA_IObject* clientobj);
-
- virtual void
- Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
-
- virtual bool
- Update();
-
- SCA_IObject *
- GetLastCreatedObject(
- ) const;
-
- void InstantAddObject();
-
-#ifdef WITH_PYTHON
-
- KX_PYMETHOD_DOC_NOARGS(KX_SCA_AddObjectActuator,InstantAddObject);
-
- static PyObject *pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_objectLastCreated(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-
-#endif /* WITH_PYTHON */
-
-}; /* end of class KX_SCA_AddObjectActuator : public KX_EditObjectActuator */
-
-#endif /* __KX_SCA_ADDOBJECTACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
deleted file mode 100644
index a4220424c6f..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_SCA_DynamicActuator.cpp
- * \ingroup ketsji
- * Adjust dynamics settings for this object
- */
-
-/* Previously existed as:
- * \source\gameengine\GameLogic\SCA_DynamicActuator.cpp
- * Please look here for revision history. */
-
-#include "KX_SCA_DynamicActuator.h"
-#include "PHY_IPhysicsController.h"
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-
-PyTypeObject KX_SCA_DynamicActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_SCA_DynamicActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_SCA_DynamicActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_SCA_DynamicActuator::Attributes[] = {
- KX_PYATTRIBUTE_SHORT_RW("mode",0,4,false,KX_SCA_DynamicActuator,m_dyn_operation),
- KX_PYATTRIBUTE_FLOAT_RW("mass",0.0f,FLT_MAX,KX_SCA_DynamicActuator,m_setmass),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_SCA_DynamicActuator::KX_SCA_DynamicActuator(SCA_IObject *gameobj,
- short dyn_operation,
- float setmass) :
-
- SCA_IActuator(gameobj, KX_ACT_DYNAMIC),
- m_dyn_operation(dyn_operation),
- m_setmass(setmass)
-{
-} /* End of constructor */
-
-
-KX_SCA_DynamicActuator::~KX_SCA_DynamicActuator()
-{
- // there's nothing to be done here, really....
-} /* end of destructor */
-
-
-
-bool KX_SCA_DynamicActuator::Update()
-{
- // bool result = false; /*unused*/
- KX_GameObject *obj = (KX_GameObject*) GetParent();
- bool bNegativeEvent = IsNegativeEvent();
- PHY_IPhysicsController* controller;
- RemoveAllEvents();
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- if (!obj)
- return false; // object not accessible, shouldnt happen
- controller = obj->GetPhysicsController();
- if (!controller)
- return false; // no physic object
-
- switch (m_dyn_operation)
- {
- case 0:
- // Child objects must be static, so we block changing to dynamic
- if (!obj->GetParent())
- controller->RestoreDynamics();
- break;
- case 1:
- controller->SuspendDynamics();
- break;
- case 2:
- controller->SetRigidBody(true);
- break;
- case 3:
- controller->SetRigidBody(false);
- break;
- case 4:
- controller->SetMass(m_setmass);
- break;
- }
-
- return false;
-}
-
-
-
-CValue* KX_SCA_DynamicActuator::GetReplica()
-{
- KX_SCA_DynamicActuator* replica =
- new KX_SCA_DynamicActuator(*this);
-
- if (replica == NULL)
- return NULL;
-
- replica->ProcessReplica();
- return replica;
-};
-
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h b/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h
deleted file mode 100644
index 4eb337c54f5..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_DynamicActuator.h
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Campbell Barton
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SCA_DynamicActuator.h
- * \ingroup ketsji
- * \brief Add object to the game world on action of this actuator
- */
-
-#ifndef __KX_SCA_DYNAMICACTUATOR_H__
-#define __KX_SCA_DYNAMICACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "SCA_PropertyActuator.h"
-#include "SCA_LogicManager.h"
-
-#include "KX_GameObject.h"
-
-class KX_SCA_DynamicActuator : public SCA_IActuator
-{
- Py_Header
-
- // dynamics operation to apply to the game object
- short m_dyn_operation;
- float m_setmass;
- public:
- KX_SCA_DynamicActuator(
- SCA_IObject* gameobj,
- short dyn_operation,
- float setmass
- );
-
- ~KX_SCA_DynamicActuator(
- );
-
- CValue*
- GetReplica(
- );
-
- virtual bool
- Update();
-
- //Python Interface
- enum DynamicOperation {
- KX_DYN_RESTORE_DYNAMICS = 0,
- KX_DYN_DISABLE_DYNAMICS,
- KX_DYN_ENABLE_RIGID_BODY,
- KX_DYN_DISABLE_RIGID_BODY,
- KX_DYN_SET_MASS,
- };
-};
-
-#endif
diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp
deleted file mode 100644
index 81c9dc91603..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_SCA_EndObjectActuator.cpp
- * \ingroup ketsji
- */
-
-
-//
-
-// Remove the actuator's parent when triggered
-//
-// Previously existed as:
-// \source\gameengine\GameLogic\SCA_EndObjectActuator.cpp
-// Please look here for revision history.
-
-#include "SCA_IActuator.h"
-#include "KX_SCA_EndObjectActuator.h"
-#include "SCA_IScene.h"
-
-KX_SCA_EndObjectActuator::KX_SCA_EndObjectActuator(SCA_IObject *gameobj,
- SCA_IScene* scene):
- SCA_IActuator(gameobj, KX_ACT_END_OBJECT),
- m_scene(scene)
-{
- // intentionally empty
-} /* End of constructor */
-
-
-
-KX_SCA_EndObjectActuator::~KX_SCA_EndObjectActuator()
-{
- // there's nothing to be done here, really....
-} /* end of destructor */
-
-
-
-bool KX_SCA_EndObjectActuator::Update()
-{
- // bool result = false; /*unused*/
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
- m_scene->DelayedRemoveObject(GetParent());
-
- return false;
-}
-
-
-
-CValue* KX_SCA_EndObjectActuator::GetReplica()
-{
- KX_SCA_EndObjectActuator* replica =
- new KX_SCA_EndObjectActuator(*this);
- if (replica == NULL) return NULL;
-
- replica->ProcessReplica();
- return replica;
-};
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions : integration hooks */
-/* ------------------------------------------------------------------------- */
-
-PyTypeObject KX_SCA_EndObjectActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_SCA_EndObjectActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_SCA_EndObjectActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_SCA_EndObjectActuator::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h b/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h
deleted file mode 100644
index 3399ed90667..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_EndObjectActuator.h
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SCA_EndObjectActuator.h
- * \ingroup ketsji
- * \brief Add object to the game world on action of this actuator
- * \attention Previously existed as: source/gameengine/GameLogic/SCA_EndObjectActuator.h
- * Please look here for revision history.
- */
-
-#ifndef __KX_SCA_ENDOBJECTACTUATOR_H__
-#define __KX_SCA_ENDOBJECTACTUATOR_H__
-
-#include "SCA_IActuator.h"
-
-class SCA_IScene;
-
-class KX_SCA_EndObjectActuator : public SCA_IActuator
-{
- Py_Header
- SCA_IScene* m_scene;
-
- public:
- KX_SCA_EndObjectActuator(
- SCA_IObject* gameobj,
- SCA_IScene* scene
- );
-
- ~KX_SCA_EndObjectActuator();
-
- CValue*
- GetReplica(
- );
-
- virtual bool
- Update();
-
- virtual void Replace_IScene(SCA_IScene *val)
- {
- m_scene= val;
- };
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
-}; /* end of class KX_EditObjectActuator : public SCA_PropertyActuator */
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
deleted file mode 100644
index 1bf76de0b40..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.cpp
- * \ingroup ketsji
- *
- * Replace the mesh for this actuator's parent
- */
-
-//
-// Previously existed as:
-
-// \source\gameengine\GameLogic\SCA_ReplaceMeshActuator.cpp
-
-// Please look here for revision history.
-
-#include <stddef.h>
-
-#include "KX_SCA_ReplaceMeshActuator.h"
-#include "KX_MeshProxy.h"
-
-#include "EXP_PyObjectPlus.h"
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-
-PyTypeObject KX_SCA_ReplaceMeshActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_SCA_ReplaceMeshActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_SCA_ReplaceMeshActuator::Methods[] = {
- KX_PYMETHODTABLE(KX_SCA_ReplaceMeshActuator, instantReplaceMesh),
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_SCA_ReplaceMeshActuator::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("mesh", KX_SCA_ReplaceMeshActuator, pyattr_get_mesh, pyattr_set_mesh),
- KX_PYATTRIBUTE_BOOL_RW ("useDisplayMesh", KX_SCA_ReplaceMeshActuator, m_use_gfx),
- KX_PYATTRIBUTE_BOOL_RW ("usePhysicsMesh", KX_SCA_ReplaceMeshActuator, m_use_phys),
- { NULL } //Sentinel
-};
-
-PyObject *KX_SCA_ReplaceMeshActuator::pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
- if (!actuator->m_mesh)
- Py_RETURN_NONE;
- KX_MeshProxy* meshproxy = new KX_MeshProxy(actuator->m_mesh);
- return meshproxy->NewProxy(true);
-}
-
-int KX_SCA_ReplaceMeshActuator::pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_SCA_ReplaceMeshActuator* actuator = static_cast<KX_SCA_ReplaceMeshActuator*>(self);
- RAS_MeshObject* new_mesh;
-
- if (!ConvertPythonToMesh(actuator->GetLogicManager(), value, &new_mesh, true, "actuator.mesh = value: KX_SCA_ReplaceMeshActuator"))
- return PY_SET_ATTR_FAIL;
-
- actuator->m_mesh = new_mesh;
- return PY_SET_ATTR_SUCCESS;
-}
-
-KX_PYMETHODDEF_DOC(KX_SCA_ReplaceMeshActuator, instantReplaceMesh,
-"instantReplaceMesh() : immediately replace mesh without delay\n")
-{
- InstantReplaceMesh();
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_SCA_ReplaceMeshActuator::KX_SCA_ReplaceMeshActuator(SCA_IObject *gameobj,
- class RAS_MeshObject *mesh,
- SCA_IScene* scene,
- bool use_gfx,
- bool use_phys) :
-
- SCA_IActuator(gameobj, KX_ACT_REPLACE_MESH),
- m_mesh(mesh),
- m_scene(scene),
- m_use_gfx(use_gfx),
- m_use_phys(use_phys)
-{
-} /* End of constructor */
-
-
-
-KX_SCA_ReplaceMeshActuator::~KX_SCA_ReplaceMeshActuator()
-{
- // there's nothing to be done here, really....
-} /* end of destructor */
-
-
-
-bool KX_SCA_ReplaceMeshActuator::Update()
-{
- // bool result = false; /*unused*/
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- if (m_mesh || m_use_phys) /* NULL mesh is ok if were updating physics */
- m_scene->ReplaceMesh(GetParent(),m_mesh, m_use_gfx, m_use_phys);
-
- return false;
-}
-
-
-
-CValue* KX_SCA_ReplaceMeshActuator::GetReplica()
-{
- KX_SCA_ReplaceMeshActuator* replica =
- new KX_SCA_ReplaceMeshActuator(*this);
-
- if (replica == NULL)
- return NULL;
-
- replica->ProcessReplica();
-
- return replica;
-};
-
-void KX_SCA_ReplaceMeshActuator::InstantReplaceMesh()
-{
- if (m_mesh) m_scene->ReplaceMesh(GetParent(),m_mesh, m_use_gfx, m_use_phys);
-}
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h b/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h
deleted file mode 100644
index 4370b5d4a4f..00000000000
--- a/source/gameengine/Ketsji/KX_SCA_ReplaceMeshActuator.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SCA_ReplaceMeshActuator.h
- * \ingroup ketsji
- * \brief Add object to the game world on action of this actuator
- * \attention Previously existed as: source/gameengine/GameLogic/SCA_ReplaceMeshActuator.h
- * Please look here for revision history.
- */
-
-#ifndef __KX_SCA_REPLACEMESHACTUATOR_H__
-#define __KX_SCA_REPLACEMESHACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "SCA_PropertyActuator.h"
-#include "SCA_LogicManager.h"
-#include "SCA_IScene.h"
-
-#include "RAS_MeshObject.h"
-
-class KX_SCA_ReplaceMeshActuator : public SCA_IActuator
-{
- Py_Header
-
- // mesh reference (mesh to replace)
- RAS_MeshObject* m_mesh;
- SCA_IScene* m_scene;
- bool m_use_gfx;
- bool m_use_phys;
-
- public:
- KX_SCA_ReplaceMeshActuator(
- SCA_IObject* gameobj,
- RAS_MeshObject *mesh,
- SCA_IScene* scene,
- bool use_gfx,
- bool use_phys
- );
-
- ~KX_SCA_ReplaceMeshActuator(
- );
-
- CValue*
- GetReplica(
- );
-
- virtual bool
- Update();
-
- void InstantReplaceMesh();
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- virtual void Replace_IScene(SCA_IScene *val)
- {
- m_scene= val;
- };
-
- static PyObject *pyattr_get_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_mesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- KX_PYMETHOD_DOC(KX_SCA_ReplaceMeshActuator,instantReplaceMesh);
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __KX_SCA_REPLACEMESHACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
deleted file mode 100644
index 5a13cf5440d..00000000000
--- a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
+++ /dev/null
@@ -1,155 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.cpp
- * \ingroup ketsji
- */
-
-
-#include <iostream>
-
-#include "KX_SG_BoneParentNodeRelationship.h"
-
-#include "MT_Matrix4x4.h"
-#include "BL_ArmatureObject.h"
-
-
-/**
- * Implementation of classes defined in KX_SG_BoneParentNodeRelationship.h
- */
-
-/**
- * first of all KX_SG_BoneParentRelation
- */
-
- KX_BoneParentRelation *
-KX_BoneParentRelation::
-New(Bone* bone
-) {
- return new KX_BoneParentRelation(bone);
-}
-
- bool
-KX_BoneParentRelation::
-UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
-) {
- MT_assert(child != NULL);
-
- // This way of accessing child coordinates is a bit cumbersome
- // be nice to have non constant reference access to these values.
-
- const MT_Vector3 & child_scale = child->GetLocalScale();
- const MT_Point3 & child_pos = child->GetLocalPosition();
- const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
- // we don't know if the armature has been updated or not, assume yes
- parentUpdated = true;
-
- // the childs world locations which we will update.
-
- MT_Vector3 child_w_scale;
- MT_Point3 child_w_pos;
- MT_Matrix3x3 child_w_rotation;
-
- bool valid_parent_transform = false;
-
- if (parent)
- {
- BL_ArmatureObject *armature = (BL_ArmatureObject*)(parent->GetSGClientObject());
- if (armature)
- {
- MT_Matrix4x4 parent_matrix;
- if (armature->GetBoneMatrix(m_bone, parent_matrix))
- {
- // Get the child's transform, and the bone matrix.
- MT_Matrix4x4 child_transform (
- MT_Transform(child_pos + MT_Vector3(0.0f, armature->GetBoneLength(m_bone), 0.0f),
- child_rotation.scaled(
- child_scale[0],
- child_scale[1],
- child_scale[2])));
-
- // The child's world transform is parent * child
- parent_matrix = parent->GetWorldTransform() * parent_matrix;
- child_transform = parent_matrix * child_transform;
-
- // Recompute the child transform components from the transform.
- child_w_scale.setValue(
- MT_Vector3(child_transform[0][0], child_transform[0][1], child_transform[0][2]).length(),
- MT_Vector3(child_transform[1][0], child_transform[1][1], child_transform[1][2]).length(),
- MT_Vector3(child_transform[2][0], child_transform[2][1], child_transform[2][2]).length());
- child_w_rotation.setValue(child_transform[0][0], child_transform[0][1], child_transform[0][2],
- child_transform[1][0], child_transform[1][1], child_transform[1][2],
- child_transform[2][0], child_transform[2][1], child_transform[2][2]);
- child_w_rotation.scale(1.0f/child_w_scale[0], 1.0f/child_w_scale[1], 1.0f/child_w_scale[2]);
-
- child_w_pos = MT_Point3(child_transform[0][3], child_transform[1][3], child_transform[2][3]);
-
- valid_parent_transform = true;
- }
- }
- }
-
- if (valid_parent_transform)
- {
- child->SetWorldScale(child_w_scale);
- child->SetWorldPosition(child_w_pos);
- child->SetWorldOrientation(child_w_rotation);
- }
- else {
- child->SetWorldFromLocalTransform();
- }
- child->ClearModified();
- // this node must always be updated, so reschedule it for next time
- child->ActivateRecheduleUpdateCallback();
- return valid_parent_transform;
-}
-
- SG_ParentRelation *
-KX_BoneParentRelation::
-NewCopy(
-) {
- KX_BoneParentRelation* bone_parent = new KX_BoneParentRelation(m_bone);
- return bone_parent;
-}
-
-KX_BoneParentRelation::
-~KX_BoneParentRelation(
-) {
- //nothing to do
-}
-
-
-KX_BoneParentRelation::
-KX_BoneParentRelation(Bone* bone
-)
-: m_bone(bone)
-{
- // nothing to do
-}
diff --git a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h b/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h
deleted file mode 100644
index 6f4fd482198..00000000000
--- a/source/gameengine/Ketsji/KX_SG_BoneParentNodeRelationship.h
+++ /dev/null
@@ -1,96 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- *
- */
-
-/** \file KX_SG_BoneParentNodeRelationship.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_SG_BONEPARENTNODERELATIONSHIP_H__
-#define __KX_SG_BONEPARENTNODERELATIONSHIP_H__
-
-#include "SG_Spatial.h"
-#include "SG_ParentRelation.h"
-
-struct Bone;
-
-/**
- * Bone parent relationship parents a child SG_Spatial frame to a
- * bone in an armature object.
- */
-class KX_BoneParentRelation : public SG_ParentRelation
-{
-
-public :
- /**
- * Allocate and construct a new KX_SG_BoneParentRelation
- * on the heap.
- *
- * bone is the bone id to use. Currently it is a pointer
- * to a Blender struct Bone - this should be fixed if
- */
-
- static
- KX_BoneParentRelation *
- New(Bone* bone
- );
-
- /**
- * Updates the childs world coordinates relative to the parent's
- * world coordinates.
- *
- * Parent should be a BL_ArmatureObject.
- */
- bool
- UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
- );
-
- /**
- * Create a copy of this relationship
- */
- SG_ParentRelation *
- NewCopy(
- );
-
- ~KX_BoneParentRelation(
- );
-
-private :
- Bone* m_bone;
- KX_BoneParentRelation(Bone* bone
- );
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_BoneParentRelation")
-#endif
-};
-
-#endif
diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp b/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
deleted file mode 100644
index e80de76861e..00000000000
--- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.cpp
+++ /dev/null
@@ -1,298 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_SG_NodeRelationships.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_SG_NodeRelationships.h"
-
-/**
- * Implementation of classes defined in KX_SG_NodeRelationships.h
- */
-
-/**
- * first of all KX_NormalParentRelation
- */
-
- KX_NormalParentRelation *
-KX_NormalParentRelation::
-New(
-) {
- return new KX_NormalParentRelation();
-}
-
- bool
-KX_NormalParentRelation::
-UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
-) {
- MT_assert(child != NULL);
-
- if (!parentUpdated && !child->IsModified())
- return false;
-
- parentUpdated = true;
-
- if (parent==NULL) { /* Simple case */
- child->SetWorldFromLocalTransform();
- child->ClearModified();
- return true; //false;
- }
- else {
- // the childs world locations which we will update.
- const MT_Vector3 & p_world_scale = parent->GetWorldScaling();
- const MT_Point3 & p_world_pos = parent->GetWorldPosition();
- const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation();
-
- child->SetWorldScale(p_world_scale * child->GetLocalScale());
- child->SetWorldOrientation(p_world_rotation * child->GetLocalOrientation());
- child->SetWorldPosition(p_world_pos + p_world_scale * (p_world_rotation * child->GetLocalPosition()));
- child->ClearModified();
- return true;
- }
-}
-
- SG_ParentRelation *
-KX_NormalParentRelation::
-NewCopy(
-) {
- return new KX_NormalParentRelation();
-}
-
-KX_NormalParentRelation::
-~KX_NormalParentRelation(
-) {
- //nothing to do
-}
-
-
-KX_NormalParentRelation::
-KX_NormalParentRelation(
-) {
- // nothing to do
-}
-
-/**
- * Next KX_VertexParentRelation
- */
-
-
- KX_VertexParentRelation *
-KX_VertexParentRelation::
-New(
-) {
- return new KX_VertexParentRelation();
-}
-
-/**
- * Method inherited from KX_ParentRelation
- */
-
- bool
-KX_VertexParentRelation::
-UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
-) {
-
- MT_assert(child != NULL);
-
- if (!parentUpdated && !child->IsModified())
- return false;
-
- child->SetWorldScale(child->GetLocalScale());
-
- if (parent)
- child->SetWorldPosition(child->GetLocalPosition()+parent->GetWorldPosition());
- else
- child->SetWorldPosition(child->GetLocalPosition());
-
- child->SetWorldOrientation(child->GetLocalOrientation());
- child->ClearModified();
- return true; //parent != NULL;
-}
-
-/**
- * Method inherited from KX_ParentRelation
- */
-
- SG_ParentRelation *
-KX_VertexParentRelation::
-NewCopy(
-) {
- return new KX_VertexParentRelation();
-};
-
-KX_VertexParentRelation::
-~KX_VertexParentRelation(
-) {
- //nothing to do
-}
-
-
-KX_VertexParentRelation::
-KX_VertexParentRelation(
-) {
- //nothing to do
-}
-
-
-/**
- * Slow parent relationship
- */
-
- KX_SlowParentRelation *
-KX_SlowParentRelation::
-New(
- MT_Scalar relaxation
-) {
- return new KX_SlowParentRelation(relaxation);
-}
-
-/**
- * Method inherited from KX_ParentRelation
- */
-
- bool
-KX_SlowParentRelation::
-UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
-) {
- MT_assert(child != NULL);
-
- // the child will move even if the parent is not
- parentUpdated = true;
-
- const MT_Vector3 & child_scale = child->GetLocalScale();
- const MT_Point3 & child_pos = child->GetLocalPosition();
- const MT_Matrix3x3 & child_rotation = child->GetLocalOrientation();
-
- // the childs world locations which we will update.
-
- MT_Vector3 child_w_scale;
- MT_Point3 child_w_pos;
- MT_Matrix3x3 child_w_rotation;
-
- if (parent) {
-
- // This is a slow parent relation
- // first compute the normal child world coordinates.
-
- MT_Vector3 child_n_scale;
- MT_Point3 child_n_pos;
- MT_Matrix3x3 child_n_rotation;
-
- const MT_Vector3 & p_world_scale = parent->GetWorldScaling();
- const MT_Point3 & p_world_pos = parent->GetWorldPosition();
- const MT_Matrix3x3 & p_world_rotation = parent->GetWorldOrientation();
-
- child_n_scale = p_world_scale * child_scale;
- child_n_rotation = p_world_rotation * child_rotation;
-
- child_n_pos = p_world_pos + p_world_scale *
- (p_world_rotation * child_pos);
-
-
- if (m_initialized) {
-
- // get the current world positions
-
- child_w_scale = child->GetWorldScaling();
- child_w_pos = child->GetWorldPosition();
- child_w_rotation = child->GetWorldOrientation();
-
- // now 'interpolate' the normal coordinates with the last
- // world coordinates to get the new world coordinates.
-
- MT_Scalar weight = MT_Scalar(1)/(m_relax + 1);
- child_w_scale = (m_relax * child_w_scale + child_n_scale) * weight;
- child_w_pos = (m_relax * child_w_pos + child_n_pos) * weight;
- // for rotation we must go through quaternion
- MT_Quaternion child_w_quat = child_w_rotation.getRotation().slerp(child_n_rotation.getRotation(), weight);
- child_w_rotation.setRotation(child_w_quat);
- //FIXME: update physics controller.
- } else {
- child_w_scale = child_n_scale;
- child_w_pos = child_n_pos;
- child_w_rotation = child_n_rotation;
- m_initialized = true;
- }
-
- } else {
-
- child_w_scale = child_scale;
- child_w_pos = child_pos;
- child_w_rotation = child_rotation;
- }
-
- child->SetWorldScale(child_w_scale);
- child->SetWorldPosition(child_w_pos);
- child->SetWorldOrientation(child_w_rotation);
- child->ClearModified();
- // this node must always be updated, so reschedule it for next time
- child->ActivateRecheduleUpdateCallback();
-
- return true; //parent != NULL;
-}
-
-/**
- * Method inherited from KX_ParentRelation
- */
-
- SG_ParentRelation *
-KX_SlowParentRelation::
-NewCopy(
-) {
- return new KX_SlowParentRelation(m_relax);
-}
-
-KX_SlowParentRelation::
-KX_SlowParentRelation(
- MT_Scalar relaxation
-):
- m_relax(relaxation),
- m_initialized(false)
-{
- //nothing to do
-}
-
-KX_SlowParentRelation::
-~KX_SlowParentRelation(
-) {
- //nothing to do
-}
-
-
-
-
diff --git a/source/gameengine/Ketsji/KX_SG_NodeRelationships.h b/source/gameengine/Ketsji/KX_SG_NodeRelationships.h
deleted file mode 100644
index 5d777f5028f..00000000000
--- a/source/gameengine/Ketsji/KX_SG_NodeRelationships.h
+++ /dev/null
@@ -1,231 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- *
- */
-
-/** \file KX_SG_NodeRelationships.h
- * \ingroup ketsji
- * \section KX_SG_NodeRelationships
- * This file provides common concrete implementations of
- * SG_ParentRelation used by the game engine. These are
- * KX_SlowParentRelation a slow parent relationship.
- * KX_NormalParentRelation a normal parent relationship where
- * orientation and position are inherited from the parent by
- * the child.
- * KX_VertexParentRelation only location information is
- * inherited by the child.
- */
-
-#ifndef __KX_SG_NODERELATIONSHIPS_H__
-#define __KX_SG_NODERELATIONSHIPS_H__
-
-#include "SG_Spatial.h"
-#include "SG_ParentRelation.h"
-
-class KX_NormalParentRelation : public SG_ParentRelation
-{
-
-public :
- /**
- * Allocate and construct a new KX_NormalParentRelation
- * on the heap.
- */
-
- static
- KX_NormalParentRelation *
- New(
- );
-
- /**
- * Method inherited from KX_ParentRelation
- */
-
- bool
- UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
- );
-
- /**
- * Method inherited from KX_ParentRelation
- */
-
- SG_ParentRelation *
- NewCopy(
- );
-
- ~KX_NormalParentRelation(
- );
-
-private :
-
- KX_NormalParentRelation(
- );
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_NormalParentRelation")
-#endif
-};
-
-
-class KX_VertexParentRelation : public SG_ParentRelation
-{
-
-public :
-
- /**
- * Allocate and construct a new KX_VertexParentRelation
- * on the heap.
- */
-
- static
- KX_VertexParentRelation *
- New(
- );
-
- /**
- * Method inherited from KX_ParentRelation
- */
-
- bool
- UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
- );
-
- /**
- * Method inherited from KX_ParentRelation
- */
-
- SG_ParentRelation *
- NewCopy(
- );
-
- ~KX_VertexParentRelation(
- );
-
- bool
- IsVertexRelation(
- ) {
- return true;
- }
-
-private :
-
- KX_VertexParentRelation(
- );
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_VertexParentRelation")
-#endif
-};
-
-
-class KX_SlowParentRelation : public SG_ParentRelation
-{
-
-public :
-
- /**
- * Allocate and construct a new KX_VertexParentRelation
- * on the heap.
- */
-
- static
- KX_SlowParentRelation *
- New(
- MT_Scalar relaxation
- );
-
- /**
- * Method inherited from KX_ParentRelation
- */
-
- bool
- UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
- );
-
- /**
- * Method inherited from KX_ParentRelation
- */
-
- SG_ParentRelation *
- NewCopy(
- );
-
- MT_Scalar
- GetTimeOffset(
- ) { return m_relax; }
-
- void
- SetTimeOffset(
- MT_Scalar relaxation
- ) { m_relax = relaxation; }
-
- ~KX_SlowParentRelation(
- );
-
- bool
- IsSlowRelation(
- ) {
- return true;
- }
-
-private :
-
- KX_SlowParentRelation(
- MT_Scalar relaxation
- );
-
- // the relaxation coefficient.
-
- MT_Scalar m_relax;
-
- /**
- * Looks like a hack flag to me.
- * We need to compute valid world coordinates the first
- * time we update spatial data of the child. This is done
- * by just doing a normal parent relation the first time
- * UpdateChildCoordinates is called and then doing the
- * slow parent relation
- */
-
- bool m_initialized;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_SlowParentRelation")
-#endif
-};
-
-#endif
diff --git a/source/gameengine/Ketsji/KX_ScalarInterpolator.cpp b/source/gameengine/Ketsji/KX_ScalarInterpolator.cpp
deleted file mode 100644
index e234a9621b8..00000000000
--- a/source/gameengine/Ketsji/KX_ScalarInterpolator.cpp
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ScalarInterpolator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_ScalarInterpolator.h"
-#include "KX_IScalarInterpolator.h"
-
-void KX_ScalarInterpolator::Execute(float currentTime) const
-{
- *m_target = m_ipo->GetValue(currentTime);
-}
diff --git a/source/gameengine/Ketsji/KX_ScalarInterpolator.h b/source/gameengine/Ketsji/KX_ScalarInterpolator.h
deleted file mode 100644
index 5d8c3163376..00000000000
--- a/source/gameengine/Ketsji/KX_ScalarInterpolator.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ScalarInterpolator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_SCALARINTERPOLATOR_H__
-#define __KX_SCALARINTERPOLATOR_H__
-
-#include "MT_Scalar.h"
-#include "KX_IInterpolator.h"
-
-class KX_IScalarInterpolator;
-
-class KX_ScalarInterpolator : public KX_IInterpolator {
-public:
- KX_ScalarInterpolator(MT_Scalar* target,
- KX_IScalarInterpolator *ipo) :
- m_target(target),
- m_ipo(ipo)
- {}
-
- virtual ~KX_ScalarInterpolator() {}
- virtual void Execute(float currentTime) const;
- void SetNewTarget(MT_Scalar* newtarget)
- {
- m_target=newtarget;
- }
- MT_Scalar* GetTarget()
- {
- return m_target;
- }
-private:
- MT_Scalar* m_target;
- KX_IScalarInterpolator *m_ipo;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_ScalarInterpolator")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_ScalingInterpolator.cpp b/source/gameengine/Ketsji/KX_ScalingInterpolator.cpp
deleted file mode 100644
index dd40cbd22fd..00000000000
--- a/source/gameengine/Ketsji/KX_ScalingInterpolator.cpp
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_ScalingInterpolator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_ScalingInterpolator.h"
-#include "MT_Vector3.h"
-#include "KX_IScalarInterpolator.h"
-
-void KX_ScalingInterpolator::Execute(float currentTime) const
-{
- m_target.setValue(m_ipos[0]->GetValue(currentTime),
- m_ipos[1]->GetValue(currentTime),
- m_ipos[2]->GetValue(currentTime));
-}
diff --git a/source/gameengine/Ketsji/KX_ScalingInterpolator.h b/source/gameengine/Ketsji/KX_ScalingInterpolator.h
deleted file mode 100644
index 52b6d0cf8cc..00000000000
--- a/source/gameengine/Ketsji/KX_ScalingInterpolator.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_ScalingInterpolator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_SCALINGINTERPOLATOR_H__
-#define __KX_SCALINGINTERPOLATOR_H__
-
-#include "KX_IInterpolator.h"
-
-class MT_Vector3;
-class KX_IScalarInterpolator;
-
-class KX_ScalingInterpolator : public KX_IInterpolator {
-public:
- KX_ScalingInterpolator(MT_Vector3& target,
- KX_IScalarInterpolator *ipos[])
- : m_target(target)
- {
- m_ipos[0] = ipos[0];
- m_ipos[1] = ipos[1];
- m_ipos[2] = ipos[2];
- }
-
- virtual void Execute(float currentTime) const;
-
-private:
- MT_Vector3& m_target;
- KX_IScalarInterpolator *m_ipos[3];
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_ScalingInterpolator")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_Scene.cpp b/source/gameengine/Ketsji/KX_Scene.cpp
deleted file mode 100644
index b3061087344..00000000000
--- a/source/gameengine/Ketsji/KX_Scene.cpp
+++ /dev/null
@@ -1,2644 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Ketsji scene. Holds references to all scene data.
- */
-
-/** \file gameengine/Ketsji/KX_Scene.cpp
- * \ingroup ketsji
- */
-
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include <stdio.h>
-
-#include "KX_Scene.h"
-#include "KX_PythonInit.h"
-#include "MT_assert.h"
-#include "KX_KetsjiEngine.h"
-#include "KX_BlenderMaterial.h"
-#include "KX_FontObject.h"
-#include "RAS_IPolygonMaterial.h"
-#include "EXP_ListValue.h"
-#include "SCA_LogicManager.h"
-#include "SCA_TimeEventManager.h"
-//#include "SCA_AlwaysEventManager.h"
-//#include "SCA_RandomEventManager.h"
-//#include "KX_RayEventManager.h"
-#include "SCA_2DFilterActuator.h"
-#include "SCA_PythonController.h"
-#include "KX_TouchEventManager.h"
-#include "SCA_KeyboardManager.h"
-#include "SCA_MouseManager.h"
-//#include "SCA_PropertyEventManager.h"
-#include "SCA_ActuatorEventManager.h"
-#include "SCA_BasicEventManager.h"
-#include "KX_Camera.h"
-#include "SCA_JoystickManager.h"
-#include "KX_PyMath.h"
-#include "RAS_MeshObject.h"
-#include "SCA_IScene.h"
-
-#include "RAS_IRasterizer.h"
-#include "RAS_ICanvas.h"
-#include "RAS_BucketManager.h"
-
-#include "EXP_FloatValue.h"
-#include "SCA_IController.h"
-#include "SCA_IActuator.h"
-#include "SG_Node.h"
-#include "BL_System.h"
-#include "SG_Controller.h"
-#include "SG_IObject.h"
-#include "SG_Tree.h"
-#include "DNA_group_types.h"
-#include "DNA_scene_types.h"
-#include "DNA_property_types.h"
-
-#include "KX_SG_NodeRelationships.h"
-
-#include "KX_NetworkEventManager.h"
-#include "NG_NetworkScene.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IGraphicController.h"
-#include "PHY_IPhysicsController.h"
-#include "KX_BlenderSceneConverter.h"
-#include "KX_MotionState.h"
-
-#include "BL_ModifierDeformer.h"
-#include "BL_ShapeDeformer.h"
-#include "BL_DeformableGameObject.h"
-#include "KX_ObstacleSimulation.h"
-
-#ifdef WITH_BULLET
-# include "KX_SoftBodyDeformer.h"
-#endif
-
-#ifdef WITH_PYTHON
-# include "EXP_PythonCallBack.h"
-#endif
-
-#include "KX_Light.h"
-
-#include "BLI_task.h"
-
-static void *KX_SceneReplicationFunc(SG_IObject* node,void* gameobj,void* scene)
-{
- KX_GameObject* replica = ((KX_Scene*)scene)->AddNodeReplicaObject(node,(KX_GameObject*)gameobj);
-
- if (replica)
- replica->Release();
-
- return (void*)replica;
-}
-
-static void *KX_SceneDestructionFunc(SG_IObject* node,void* gameobj,void* scene)
-{
- ((KX_Scene*)scene)->RemoveNodeDestructObject(node,(KX_GameObject*)gameobj);
-
- return NULL;
-};
-
-bool KX_Scene::KX_ScenegraphUpdateFunc(SG_IObject* node,void* gameobj,void* scene)
-{
- return ((SG_Node*)node)->Schedule(((KX_Scene*)scene)->m_sghead);
-}
-
-bool KX_Scene::KX_ScenegraphRescheduleFunc(SG_IObject* node,void* gameobj,void* scene)
-{
- return ((SG_Node*)node)->Reschedule(((KX_Scene*)scene)->m_sghead);
-}
-
-SG_Callbacks KX_Scene::m_callbacks = SG_Callbacks(
- KX_SceneReplicationFunc,
- KX_SceneDestructionFunc,
- KX_GameObject::UpdateTransformFunc,
- KX_Scene::KX_ScenegraphUpdateFunc,
- KX_Scene::KX_ScenegraphRescheduleFunc);
-
-// temporarily var until there is a button in the userinterface
-// (defined in KX_PythonInit.cpp)
-extern bool gUseVisibilityTemp;
-
-KX_Scene::KX_Scene(class SCA_IInputDevice* keyboarddevice,
- class SCA_IInputDevice* mousedevice,
- class NG_NetworkDeviceInterface *ndi,
- const STR_String& sceneName,
- Scene *scene,
- class RAS_ICanvas* canvas):
- PyObjectPlus(),
- m_keyboardmgr(NULL),
- m_mousemgr(NULL),
- m_sceneConverter(NULL),
- m_physicsEnvironment(0),
- m_sceneName(sceneName),
- m_networkDeviceInterface(ndi),
- m_active_camera(NULL),
- m_ueberExecutionPriority(0),
- m_blenderScene(scene),
- m_isActivedHysteresis(false),
- m_lodHysteresisValue(0)
-{
- m_suspendedtime = 0.0;
- m_suspendeddelta = 0.0;
-
- m_dbvt_culling = false;
- m_dbvt_occlusion_res = 0;
- m_activity_culling = false;
- m_suspend = false;
- m_isclearingZbuffer = true;
- m_isShadowDone = false;
- m_tempObjectList = new CListValue();
- m_objectlist = new CListValue();
- m_parentlist = new CListValue();
- m_lightlist= new CListValue();
- m_inactivelist = new CListValue();
- m_euthanasyobjects = new CListValue();
- m_animatedlist = new CListValue();
-
- m_logicmgr = new SCA_LogicManager();
-
- m_timemgr = new SCA_TimeEventManager(m_logicmgr);
- m_keyboardmgr = new SCA_KeyboardManager(m_logicmgr,keyboarddevice);
- m_mousemgr = new SCA_MouseManager(m_logicmgr,mousedevice, canvas);
-
- //SCA_AlwaysEventManager* alwaysmgr = new SCA_AlwaysEventManager(m_logicmgr);
- //SCA_PropertyEventManager* propmgr = new SCA_PropertyEventManager(m_logicmgr);
- SCA_ActuatorEventManager* actmgr = new SCA_ActuatorEventManager(m_logicmgr);
- //SCA_RandomEventManager* rndmgr = new SCA_RandomEventManager(m_logicmgr);
- SCA_BasicEventManager* basicmgr = new SCA_BasicEventManager(m_logicmgr);
- //KX_RayEventManager* raymgr = new KX_RayEventManager(m_logicmgr);
-
- KX_NetworkEventManager* netmgr = new KX_NetworkEventManager(m_logicmgr, ndi);
-
-
-
- //m_logicmgr->RegisterEventManager(alwaysmgr);
- //m_logicmgr->RegisterEventManager(propmgr);
- m_logicmgr->RegisterEventManager(actmgr);
- m_logicmgr->RegisterEventManager(m_keyboardmgr);
- m_logicmgr->RegisterEventManager(m_mousemgr);
- m_logicmgr->RegisterEventManager(m_timemgr);
- //m_logicmgr->RegisterEventManager(rndmgr);
- //m_logicmgr->RegisterEventManager(raymgr);
- m_logicmgr->RegisterEventManager(netmgr);
- m_logicmgr->RegisterEventManager(basicmgr);
-
-
- SYS_SystemHandle hSystem = SYS_GetSystem();
- bool nojoystick= SYS_GetCommandLineInt(hSystem,"nojoystick",0);
- if (!nojoystick)
- {
- SCA_JoystickManager *joymgr = new SCA_JoystickManager(m_logicmgr);
- m_logicmgr->RegisterEventManager(joymgr);
- }
-
- MT_assert (m_networkDeviceInterface != NULL);
- m_networkScene = new NG_NetworkScene(m_networkDeviceInterface);
-
- m_rootnode = NULL;
-
- m_bucketmanager=new RAS_BucketManager();
-
- bool showObstacleSimulation = (scene->gm.flag & GAME_SHOW_OBSTACLE_SIMULATION) != 0;
- switch (scene->gm.obstacleSimulation)
- {
- case OBSTSIMULATION_TOI_rays:
- m_obstacleSimulation = new KX_ObstacleSimulationTOI_rays((MT_Scalar)scene->gm.levelHeight, showObstacleSimulation);
- break;
- case OBSTSIMULATION_TOI_cells:
- m_obstacleSimulation = new KX_ObstacleSimulationTOI_cells((MT_Scalar)scene->gm.levelHeight, showObstacleSimulation);
- break;
- default:
- m_obstacleSimulation = NULL;
- }
-
-#ifdef WITH_PYTHON
- m_attr_dict = NULL;
- m_draw_call_pre = NULL;
- m_draw_call_post = NULL;
- m_draw_setup_call_pre = NULL;
-#endif
-}
-
-
-
-KX_Scene::~KX_Scene()
-{
- // The release of debug properties used to be in SCA_IScene::~SCA_IScene
- // It's still there but we remove all properties here otherwise some
- // reference might be hanging and causing late release of objects
- RemoveAllDebugProperties();
-
- while (GetRootParentList()->GetCount() > 0)
- {
- KX_GameObject* parentobj = (KX_GameObject*) GetRootParentList()->GetValue(0);
- this->RemoveObject(parentobj);
- }
-
- if (m_obstacleSimulation)
- delete m_obstacleSimulation;
-
- if (m_objectlist)
- m_objectlist->Release();
-
- if (m_parentlist)
- m_parentlist->Release();
-
- if (m_inactivelist)
- m_inactivelist->Release();
-
- if (m_lightlist)
- m_lightlist->Release();
-
- if (m_tempObjectList)
- m_tempObjectList->Release();
-
- if (m_euthanasyobjects)
- m_euthanasyobjects->Release();
-
- if (m_animatedlist)
- m_animatedlist->Release();
-
- if (m_logicmgr)
- delete m_logicmgr;
-
- if (m_physicsEnvironment)
- delete m_physicsEnvironment;
-
- if (m_networkScene)
- delete m_networkScene;
-
- if (m_bucketmanager)
- {
- delete m_bucketmanager;
- }
-
-#ifdef WITH_PYTHON
- if (m_attr_dict) {
- PyDict_Clear(m_attr_dict);
- /* Py_CLEAR: Py_DECREF's and NULL's */
- Py_CLEAR(m_attr_dict);
- }
-
- /* these may be NULL but the macro checks */
- Py_CLEAR(m_draw_call_pre);
- Py_CLEAR(m_draw_call_post);
-#endif
-}
-
-RAS_BucketManager* KX_Scene::GetBucketManager()
-{
- return m_bucketmanager;
-}
-
-
-CListValue* KX_Scene::GetTempObjectList()
-{
- return m_tempObjectList;
-}
-
-CListValue* KX_Scene::GetObjectList()
-{
- return m_objectlist;
-}
-
-
-CListValue* KX_Scene::GetRootParentList()
-{
- return m_parentlist;
-}
-
-CListValue* KX_Scene::GetInactiveList()
-{
- return m_inactivelist;
-}
-
-
-
-CListValue* KX_Scene::GetLightList()
-{
- return m_lightlist;
-}
-
-SCA_LogicManager* KX_Scene::GetLogicManager()
-{
- return m_logicmgr;
-}
-
-SCA_TimeEventManager* KX_Scene::GetTimeEventManager()
-{
- return m_timemgr;
-}
-
-
-
-
-list<class KX_Camera*>* KX_Scene::GetCameras()
-{
- return &m_cameras;
-}
-
-void KX_Scene::SetFramingType(RAS_FrameSettings & frame_settings)
-{
- m_frame_settings = frame_settings;
-};
-
-/**
- * Return a const reference to the framing
- * type set by the above call.
- * The contents are not guaranteed to be sensible
- * if you don't call the above function.
- */
-const RAS_FrameSettings& KX_Scene::GetFramingType() const
-{
- return m_frame_settings;
-};
-
-
-
-/**
- * Store the current scene's viewport on the
- * game engine canvas.
- */
-void KX_Scene::SetSceneViewport(const RAS_Rect &viewport)
-{
- m_viewport = viewport;
-}
-
-
-
-const RAS_Rect& KX_Scene::GetSceneViewport() const
-{
- return m_viewport;
-}
-
-
-
-void KX_Scene::SetWorldInfo(class KX_WorldInfo* worldinfo)
-{
- m_worldinfo = worldinfo;
-}
-
-
-
-class KX_WorldInfo* KX_Scene::GetWorldInfo()
-{
- return m_worldinfo;
-}
-
-
-const STR_String& KX_Scene::GetName()
-{
- return m_sceneName;
-}
-
-
-void KX_Scene::Suspend()
-{
- m_suspend = true;
-}
-
-void KX_Scene::Resume()
-{
- m_suspend = false;
-}
-
-void KX_Scene::SetActivityCulling(bool b)
-{
- m_activity_culling = b;
-}
-
-bool KX_Scene::IsSuspended()
-{
- return m_suspend;
-}
-
-bool KX_Scene::IsClearingZBuffer()
-{
- return m_isclearingZbuffer;
-}
-
-void KX_Scene::EnableZBufferClearing(bool isclearingZbuffer)
-{
- m_isclearingZbuffer = isclearingZbuffer;
-}
-
-void KX_Scene::AddObjectDebugProperties(class KX_GameObject* gameobj)
-{
- Object* blenderobject = gameobj->GetBlenderObject();
- bProperty* prop = (bProperty*)blenderobject->prop.first;
-
- while (prop) {
- if (prop->flag & PROP_DEBUG)
- AddDebugProperty(gameobj,STR_String(prop->name));
- prop = prop->next;
- }
-
- if (blenderobject->scaflag & OB_DEBUGSTATE)
- AddDebugProperty(gameobj,STR_String("__state__"));
-}
-
-void KX_Scene::RemoveNodeDestructObject(class SG_IObject* node,class CValue* gameobj)
-{
- KX_GameObject* orgobj = (KX_GameObject*)gameobj;
- if (NewRemoveObject(orgobj) != 0)
- {
- // object is not yet deleted because a reference is hanging somewhere.
- // This should not happen anymore since we use proxy object for Python
- // confident enough to put an assert?
- //assert(false);
- printf("Zombie object! name=%s\n", orgobj->GetName().ReadPtr());
- orgobj->SetSGNode(NULL);
- PHY_IGraphicController* ctrl = orgobj->GetGraphicController();
- if (ctrl)
- {
- // a graphic controller is set, we must delete it as the node will be deleted
- delete ctrl;
- orgobj->SetGraphicController(NULL);
- }
- }
- if (node)
- delete node;
-}
-
-KX_GameObject* KX_Scene::AddNodeReplicaObject(class SG_IObject* node, class CValue* gameobj)
-{
- // for group duplication, limit the duplication of the hierarchy to the
- // objects that are part of the group.
- if (!IsObjectInGroup(gameobj))
- return NULL;
-
- KX_GameObject* orgobj = (KX_GameObject*)gameobj;
- KX_GameObject* newobj = (KX_GameObject*)orgobj->GetReplica();
- m_map_gameobject_to_replica.insert(orgobj, newobj);
-
- // also register 'timers' (time properties) of the replica
- int numprops = newobj->GetPropertyCount();
-
- for (int i = 0; i < numprops; i++)
- {
- CValue* prop = newobj->GetProperty(i);
-
- if (prop->GetProperty("timer"))
- this->m_timemgr->AddTimeProperty(prop);
- }
-
- if (node)
- {
- newobj->SetSGNode((SG_Node*)node);
- }
- else
- {
- m_rootnode = new SG_Node(newobj,this,KX_Scene::m_callbacks);
-
- // this fixes part of the scaling-added object bug
- SG_Node* orgnode = orgobj->GetSGNode();
- m_rootnode->SetLocalScale(orgnode->GetLocalScale());
- m_rootnode->SetLocalPosition(orgnode->GetLocalPosition());
- m_rootnode->SetLocalOrientation(orgnode->GetLocalOrientation());
-
- // define the relationship between this node and it's parent.
- KX_NormalParentRelation * parent_relation =
- KX_NormalParentRelation::New();
- m_rootnode->SetParentRelation(parent_relation);
-
- newobj->SetSGNode(m_rootnode);
- }
-
- SG_IObject* replicanode = newobj->GetSGNode();
-// SG_Node* rootnode = (replicanode == m_rootnode ? NULL : m_rootnode);
-
- replicanode->SetSGClientObject(newobj);
-
- // this is the list of object that are send to the graphics pipeline
- m_objectlist->Add(newobj->AddRef());
- if (newobj->GetGameObjectType()==SCA_IObject::OBJ_LIGHT)
- m_lightlist->Add(newobj->AddRef());
- else if (newobj->GetGameObjectType()==SCA_IObject::OBJ_TEXT)
- AddFont((KX_FontObject*)newobj);
- newobj->AddMeshUser();
-
- // logic cannot be replicated, until the whole hierarchy is replicated.
- m_logicHierarchicalGameObjects.push_back(newobj);
- //replicate controllers of this node
- SGControllerList scenegraphcontrollers = orgobj->GetSGNode()->GetSGControllerList();
- replicanode->RemoveAllControllers();
- SGControllerList::iterator cit;
- //int numcont = scenegraphcontrollers.size();
-
- for (cit = scenegraphcontrollers.begin();!(cit==scenegraphcontrollers.end());++cit)
- {
- // controller replication is quite complicated
- // only replicate ipo controller for now
-
- SG_Controller* replicacontroller = (*cit)->GetReplica((SG_Node*) replicanode);
- if (replicacontroller)
- {
- replicacontroller->SetObject(replicanode);
- replicanode->AddSGController(replicacontroller);
- }
- }
- // replicate graphic controller
- if (orgobj->GetGraphicController())
- {
- PHY_IMotionState* motionstate = new KX_MotionState(newobj->GetSGNode());
- PHY_IGraphicController* newctrl = orgobj->GetGraphicController()->GetReplica(motionstate);
- newctrl->SetNewClientInfo(newobj->getClientInfo());
- newobj->SetGraphicController(newctrl);
- }
-
- // replicate physics controller
- if (orgobj->GetPhysicsController())
- {
- PHY_IMotionState* motionstate = new KX_MotionState(newobj->GetSGNode());
- PHY_IPhysicsController* newctrl = orgobj->GetPhysicsController()->GetReplica();
-
- KX_GameObject *parent = newobj->GetParent();
- PHY_IPhysicsController* parentctrl = (parent) ? parent->GetPhysicsController() : NULL;
-
- newctrl->SetNewClientInfo(newobj->getClientInfo());
- newobj->SetPhysicsController(newctrl, newobj->IsDynamic());
- newctrl->PostProcessReplica(motionstate, parentctrl);
-
- // Child objects must be static
- if (parent)
- newctrl->SuspendDynamics();
- }
-
- return newobj;
-}
-
-
-
-// before calling this method KX_Scene::ReplicateLogic(), make sure to
-// have called 'GameObject::ReParentLogic' for each object this
-// hierarchy that's because first ALL bricks must exist in the new
-// replica of the hierarchy in order to make cross-links work properly
-// !
-// It is VERY important that the order of sensors and actuators in
-// the replicated object is preserved: it is used to reconnect the logic.
-// This method is more robust then using the bricks name in case of complex
-// group replication. The replication of logic bricks is done in
-// SCA_IObject::ReParentLogic(), make sure it preserves the order of the bricks.
-void KX_Scene::ReplicateLogic(KX_GameObject* newobj)
-{
- /* add properties to debug list, for added objects and DupliGroups */
- if (KX_GetActiveEngine()->GetAutoAddDebugProperties()) {
- AddObjectDebugProperties(newobj);
- }
- // also relink the controller to sensors/actuators
- SCA_ControllerList& controllers = newobj->GetControllers();
- //SCA_SensorList& sensors = newobj->GetSensors();
- //SCA_ActuatorList& actuators = newobj->GetActuators();
-
- for (SCA_ControllerList::iterator itc = controllers.begin(); !(itc==controllers.end());itc++)
- {
- SCA_IController* cont = (*itc);
- cont->SetUeberExecutePriority(m_ueberExecutionPriority);
- vector<SCA_ISensor*> linkedsensors = cont->GetLinkedSensors();
- vector<SCA_IActuator*> linkedactuators = cont->GetLinkedActuators();
-
- // disconnect the sensors and actuators
- // do it directly on the list at this controller is not connected to anything at this stage
- cont->GetLinkedSensors().clear();
- cont->GetLinkedActuators().clear();
-
- // now relink each sensor
- for (vector<SCA_ISensor*>::iterator its = linkedsensors.begin();!(its==linkedsensors.end());its++)
- {
- SCA_ISensor* oldsensor = (*its);
- SCA_IObject* oldsensorobj = oldsensor->GetParent();
- SCA_IObject* newsensorobj = NULL;
-
- // the original owner of the sensor has been replicated?
- void **h_obj = m_map_gameobject_to_replica[oldsensorobj];
- if (h_obj)
- newsensorobj = (SCA_IObject*)(*h_obj);
- if (!newsensorobj)
- {
- // no, then the sensor points outside the hierarchy, keep it the same
- if (m_objectlist->SearchValue(oldsensorobj))
- // only replicate links that points to active objects
- m_logicmgr->RegisterToSensor(cont,oldsensor);
- }
- else
- {
- // yes, then the new sensor has the same position
- SCA_SensorList& sensorlist = oldsensorobj->GetSensors();
- SCA_SensorList::iterator sit;
- SCA_ISensor* newsensor = NULL;
- int sensorpos;
-
- for (sensorpos=0, sit=sensorlist.begin(); sit!=sensorlist.end(); sit++, sensorpos++)
- {
- if ((*sit) == oldsensor)
- {
- newsensor = newsensorobj->GetSensors().at(sensorpos);
- break;
- }
- }
- assert(newsensor != NULL);
- m_logicmgr->RegisterToSensor(cont,newsensor);
- }
- }
-
- // now relink each actuator
- for (vector<SCA_IActuator*>::iterator ita = linkedactuators.begin();!(ita==linkedactuators.end());ita++)
- {
- SCA_IActuator* oldactuator = (*ita);
- SCA_IObject* oldactuatorobj = oldactuator->GetParent();
- SCA_IObject* newactuatorobj = NULL;
-
- // the original owner of the sensor has been replicated?
- void **h_obj = m_map_gameobject_to_replica[oldactuatorobj];
- if (h_obj)
- newactuatorobj = (SCA_IObject*)(*h_obj);
-
- if (!newactuatorobj)
- {
- // no, then the sensor points outside the hierarchy, keep it the same
- if (m_objectlist->SearchValue(oldactuatorobj))
- // only replicate links that points to active objects
- m_logicmgr->RegisterToActuator(cont,oldactuator);
- }
- else
- {
- // yes, then the new sensor has the same position
- SCA_ActuatorList& actuatorlist = oldactuatorobj->GetActuators();
- SCA_ActuatorList::iterator ait;
- SCA_IActuator* newactuator = NULL;
- int actuatorpos;
-
- for (actuatorpos=0, ait=actuatorlist.begin(); ait!=actuatorlist.end(); ait++, actuatorpos++)
- {
- if ((*ait) == oldactuator)
- {
- newactuator = newactuatorobj->GetActuators().at(actuatorpos);
- break;
- }
- }
- assert(newactuator != NULL);
- m_logicmgr->RegisterToActuator(cont,newactuator);
- newactuator->SetUeberExecutePriority(m_ueberExecutionPriority);
- }
- }
- }
- // ready to set initial state
- newobj->ResetState();
-}
-
-void KX_Scene::DupliGroupRecurse(CValue* obj, int level)
-{
- KX_GameObject* groupobj = (KX_GameObject*) obj;
- KX_GameObject* replica;
- KX_GameObject* gameobj;
- Object* blgroupobj = groupobj->GetBlenderObject();
- Group* group;
- GroupObject *go;
- vector<KX_GameObject*> duplilist;
-
- if (!groupobj->GetSGNode() ||
- !groupobj->IsDupliGroup() ||
- level>MAX_DUPLI_RECUR)
- return;
-
- // we will add one group at a time
- m_logicHierarchicalGameObjects.clear();
- m_map_gameobject_to_replica.clear();
- m_ueberExecutionPriority++;
- // for groups will do something special:
- // we will force the creation of objects to those in the group only
- // Again, this is match what Blender is doing (it doesn't care of parent relationship)
- m_groupGameObjects.clear();
-
- group = blgroupobj->dup_group;
- for (go=(GroupObject*)group->gobject.first; go; go=(GroupObject*)go->next)
- {
- Object* blenderobj = go->ob;
- if (blgroupobj == blenderobj)
- // this check is also in group_duplilist()
- continue;
-
- gameobj = (KX_GameObject*)m_logicmgr->FindGameObjByBlendObj(blenderobj);
- if (gameobj == NULL)
- {
- // this object has not been converted!!!
- // Should not happen as dupli group are created automatically
- continue;
- }
-
- gameobj->SetBlenderGroupObject(blgroupobj);
-
- if ((blenderobj->lay & group->layer)==0)
- {
- // object is not visible in the 3D view, will not be instantiated
- continue;
- }
- m_groupGameObjects.insert(gameobj);
- }
-
- set<CValue*>::iterator oit;
- for (oit=m_groupGameObjects.begin(); oit != m_groupGameObjects.end(); oit++)
- {
- gameobj = (KX_GameObject*)(*oit);
-
- KX_GameObject *parent = gameobj->GetParent();
- if (parent != NULL)
- {
- // this object is not a top parent. Either it is the child of another
- // object in the group and it will be added automatically when the parent
- // is added. Or it is the child of an object outside the group and the group
- // is inconsistent, skip it anyway
- continue;
- }
- replica = (KX_GameObject*) AddNodeReplicaObject(NULL,gameobj);
- // add to 'rootparent' list (this is the list of top hierarchy objects, updated each frame)
- m_parentlist->Add(replica->AddRef());
-
- // recurse replication into children nodes
- NodeList& children = gameobj->GetSGNode()->GetSGChildren();
-
- replica->GetSGNode()->ClearSGChildren();
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* orgnode = (*childit);
- SG_Node* childreplicanode = orgnode->GetSGReplica();
- if (childreplicanode)
- replica->GetSGNode()->AddChild(childreplicanode);
- }
- // don't replicate logic now: we assume that the objects in the group can have
- // logic relationship, even outside parent relationship
- // In order to match 3D view, the position of groupobj is used as a
- // transformation matrix instead of the new position. This means that
- // the group reference point is 0,0,0
-
- // get the rootnode's scale
- MT_Vector3 newscale = groupobj->NodeGetWorldScaling();
- // set the replica's relative scale with the rootnode's scale
- replica->NodeSetRelativeScale(newscale);
-
- MT_Point3 offset(group->dupli_ofs);
- MT_Point3 newpos = groupobj->NodeGetWorldPosition() +
- newscale*(groupobj->NodeGetWorldOrientation() * (gameobj->NodeGetWorldPosition()-offset));
- replica->NodeSetLocalPosition(newpos);
- // set the orientation after position for softbody!
- MT_Matrix3x3 newori = groupobj->NodeGetWorldOrientation() * gameobj->NodeGetWorldOrientation();
- replica->NodeSetLocalOrientation(newori);
- // update scenegraph for entire tree of children
- replica->GetSGNode()->UpdateWorldData(0);
- replica->GetSGNode()->SetBBox(gameobj->GetSGNode()->BBox());
- replica->GetSGNode()->SetRadius(gameobj->GetSGNode()->Radius());
- // we can now add the graphic controller to the physic engine
- replica->ActivateGraphicController(true);
-
- // done with replica
- replica->Release();
- }
-
- // the logic must be replicated first because we need
- // the new logic bricks before relinking
- vector<KX_GameObject*>::iterator git;
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- (*git)->ReParentLogic();
- }
-
- // relink any pointers as necessary, sort of a temporary solution
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- // this will also relink the actuator to objects within the hierarchy
- (*git)->Relink(&m_map_gameobject_to_replica);
- // add the object in the layer of the parent
- (*git)->SetLayer(groupobj->GetLayer());
- }
-
- // replicate crosslinks etc. between logic bricks
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- ReplicateLogic((*git));
- }
-
- // now look if object in the hierarchy have dupli group and recurse
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- /* Replicate all constraints. */
- if ((*git)->GetPhysicsController()) {
- (*git)->GetPhysicsController()->ReplicateConstraints((*git), m_logicHierarchicalGameObjects);
- (*git)->ClearConstraints();
- }
-
- if ((*git) != groupobj && (*git)->IsDupliGroup())
- // can't instantiate group immediately as it destroys m_logicHierarchicalGameObjects
- duplilist.push_back((*git));
-
- if ((*git)->GetBlenderGroupObject() == blgroupobj) {
- // set references for dupli-group
- // groupobj holds a list of all objects, that belongs to this group
- groupobj->AddInstanceObjects((*git));
-
- // every object gets the reference to its dupli-group object
- (*git)->SetDupliGroupObject(groupobj);
- }
- }
-
- for (git = duplilist.begin(); !(git == duplilist.end()); ++git)
- {
- DupliGroupRecurse((*git), level+1);
- }
-}
-
-
-SCA_IObject* KX_Scene::AddReplicaObject(class CValue* originalobject,
- class CValue* referenceobject,
- int lifespan)
-{
-
- m_logicHierarchicalGameObjects.clear();
- m_map_gameobject_to_replica.clear();
- m_groupGameObjects.clear();
-
- KX_GameObject* originalobj = (KX_GameObject*) originalobject;
- KX_GameObject* referenceobj = (KX_GameObject*) referenceobject;
-
- m_ueberExecutionPriority++;
-
- // lets create a replica
- KX_GameObject* replica = (KX_GameObject*) AddNodeReplicaObject(NULL,originalobj);
-
- // add a timebomb to this object
- // lifespan of zero means 'this object lives forever'
- if (lifespan > 0)
- {
- // for now, convert between so called frames and realtime
- m_tempObjectList->Add(replica->AddRef());
- // this convert the life from frames to sort-of seconds, hard coded 0.02 that assumes we have 50 frames per second
- // if you change this value, make sure you change it in KX_GameObject::pyattr_get_life property too
- CValue *fval = new CFloatValue(lifespan*0.02f);
- replica->SetProperty("::timebomb",fval);
- fval->Release();
- }
-
- // add to 'rootparent' list (this is the list of top hierarchy objects, updated each frame)
- m_parentlist->Add(replica->AddRef());
-
- // recurse replication into children nodes
-
- NodeList& children = originalobj->GetSGNode()->GetSGChildren();
-
- replica->GetSGNode()->ClearSGChildren();
- for (NodeList::iterator childit = children.begin();!(childit==children.end());++childit)
- {
- SG_Node* orgnode = (*childit);
- SG_Node* childreplicanode = orgnode->GetSGReplica();
- if (childreplicanode)
- replica->GetSGNode()->AddChild(childreplicanode);
- }
-
- if (referenceobj) {
- // At this stage all the objects in the hierarchy have been duplicated,
- // we can update the scenegraph, we need it for the duplication of logic
- MT_Point3 newpos = referenceobj->NodeGetWorldPosition();
- replica->NodeSetLocalPosition(newpos);
-
- MT_Matrix3x3 newori = referenceobj->NodeGetWorldOrientation();
- replica->NodeSetLocalOrientation(newori);
-
- // get the rootnode's scale
- MT_Vector3 newscale = referenceobj->GetSGNode()->GetRootSGParent()->GetLocalScale();
- // set the replica's relative scale with the rootnode's scale
- replica->NodeSetRelativeScale(newscale);
- }
-
- replica->GetSGNode()->UpdateWorldData(0);
- replica->GetSGNode()->SetBBox(originalobj->GetSGNode()->BBox());
- replica->GetSGNode()->SetRadius(originalobj->GetSGNode()->Radius());
- // the size is correct, we can add the graphic controller to the physic engine
- replica->ActivateGraphicController(true);
-
- // now replicate logic
- vector<KX_GameObject*>::iterator git;
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- (*git)->ReParentLogic();
- }
-
- // relink any pointers as necessary, sort of a temporary solution
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- // this will also relink the actuators in the hierarchy
- (*git)->Relink(&m_map_gameobject_to_replica);
- if (referenceobj) {
- // add the object in the layer of the reference object
- (*git)->SetLayer(referenceobj->GetLayer());
- }
- else {
- // We don't know what layer set, so we set all visible layers in the blender scene.
- (*git)->SetLayer(m_blenderScene->lay);
- }
- }
-
- // replicate crosslinks etc. between logic bricks
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- ReplicateLogic((*git));
- }
-
- // check if there are objects with dupligroup in the hierarchy
- vector<KX_GameObject*> duplilist;
- for (git = m_logicHierarchicalGameObjects.begin();!(git==m_logicHierarchicalGameObjects.end());++git)
- {
- if ((*git)->IsDupliGroup())
- {
- // separate list as m_logicHierarchicalGameObjects is also used by DupliGroupRecurse()
- duplilist.push_back(*git);
- }
- }
- for (git = duplilist.begin();!(git==duplilist.end());++git)
- {
- DupliGroupRecurse(*git, 0);
- }
- // don't release replica here because we are returning it, not done with it...
- return replica;
-}
-
-
-
-void KX_Scene::RemoveObject(class CValue* gameobj)
-{
- KX_GameObject* newobj = (KX_GameObject*) gameobj;
-
- // disconnect child from parent
- SG_Node* node = newobj->GetSGNode();
-
- if (node)
- {
- node->DisconnectFromParent();
-
- // recursively destruct
- node->Destruct();
- }
- //no need to do that: the object is destroyed and memory released
- //newobj->SetSGNode(0);
-}
-
-void KX_Scene::RemoveDupliGroup(class CValue *gameobj)
-{
- KX_GameObject *newobj = (KX_GameObject *) gameobj;
-
- if (newobj->IsDupliGroup()) {
- for (int i = 0; i < newobj->GetInstanceObjects()->GetCount(); i++) {
- CValue *obj = newobj->GetInstanceObjects()->GetValue(i);
- DelayedRemoveObject(obj);
- }
- }
-}
-
-void KX_Scene::DelayedRemoveObject(class CValue* gameobj)
-{
- RemoveDupliGroup(gameobj);
-
- if (!m_euthanasyobjects->SearchValue(gameobj))
- {
- m_euthanasyobjects->Add(gameobj->AddRef());
- }
-}
-
-int KX_Scene::NewRemoveObject(class CValue* gameobj)
-{
- int ret;
- KX_GameObject* newobj = (KX_GameObject*) gameobj;
-
- /* remove property from debug list */
- RemoveObjectDebugProperties(newobj);
-
- /* Invalidate the python reference, since the object may exist in script lists
- * its possible that it wont be automatically invalidated, so do it manually here,
- *
- * if for some reason the object is added back into the scene python can always get a new Proxy
- */
- newobj->InvalidateProxy();
-
- // keep the blender->game object association up to date
- // note that all the replicas of an object will have the same
- // blender object, that's why we need to check the game object
- // as only the deletion of the original object must be recorded
- m_logicmgr->UnregisterGameObj(newobj->GetBlenderObject(), gameobj);
-
- //todo: look at this
- //GetPhysicsEnvironment()->RemovePhysicsController(gameobj->getPhysicsController());
-
- // remove all sensors/controllers/actuators from logicsystem...
-
- SCA_SensorList& sensors = newobj->GetSensors();
- for (SCA_SensorList::iterator its = sensors.begin();
- !(its==sensors.end());its++)
- {
- m_logicmgr->RemoveSensor(*its);
- }
-
- SCA_ControllerList& controllers = newobj->GetControllers();
- for (SCA_ControllerList::iterator itc = controllers.begin();
- !(itc==controllers.end());itc++)
- {
- m_logicmgr->RemoveController(*itc);
- (*itc)->ReParent(NULL);
- }
-
- SCA_ActuatorList& actuators = newobj->GetActuators();
- for (SCA_ActuatorList::iterator ita = actuators.begin();
- !(ita==actuators.end());ita++)
- {
- m_logicmgr->RemoveActuator(*ita);
- }
- // the sensors/controllers/actuators must also be released, this is done in ~SCA_IObject
-
- // now remove the timer properties from the time manager
- int numprops = newobj->GetPropertyCount();
-
- for (int i = 0; i < numprops; i++)
- {
- CValue* propval = newobj->GetProperty(i);
- if (propval->GetProperty("timer"))
- {
- m_timemgr->RemoveTimeProperty(propval);
- }
- }
-
- // if the object is the dupligroup proxy, you have to cleanup all m_pDupliGroupObject's in all
- // instances refering to this group
- if (newobj->GetInstanceObjects()) {
- for (int i = 0; i < newobj->GetInstanceObjects()->GetCount(); i++) {
- KX_GameObject* instance = (KX_GameObject*)newobj->GetInstanceObjects()->GetValue(i);
- instance->RemoveDupliGroupObject();
- }
- }
-
- // if this object was part of a group, make sure to remove it from that group's instance list
- KX_GameObject* group = newobj->GetDupliGroupObject();
- if (group)
- group->RemoveInstanceObject(newobj);
-
- newobj->RemoveMeshes();
-
- switch (newobj->GetGameObjectType()) {
- case SCA_IObject::OBJ_CAMERA:
- m_cameras.remove((KX_Camera *)newobj);
- break;
- case SCA_IObject::OBJ_TEXT:
- m_fonts.remove((KX_FontObject *)newobj);
- break;
- }
-
- ret = 1;
- if (newobj->GetGameObjectType()==SCA_IObject::OBJ_LIGHT && m_lightlist->RemoveValue(newobj))
- ret = newobj->Release();
- if (m_objectlist->RemoveValue(newobj))
- ret = newobj->Release();
- if (m_tempObjectList->RemoveValue(newobj))
- ret = newobj->Release();
- if (m_parentlist->RemoveValue(newobj))
- ret = newobj->Release();
- if (m_inactivelist->RemoveValue(newobj))
- ret = newobj->Release();
- if (m_euthanasyobjects->RemoveValue(newobj))
- ret = newobj->Release();
- if (m_animatedlist->RemoveValue(newobj))
- ret = newobj->Release();
-
- /* Warning 'newobj' maye be freed now, only compare, don't access */
-
-
- if (newobj == m_active_camera)
- {
- //no AddRef done on m_active_camera so no Release
- //m_active_camera->Release();
- m_active_camera = NULL;
- }
-
- /* currently does nothing, keep in case we need to Unregister something */
-#if 0
- if (m_sceneConverter)
- m_sceneConverter->UnregisterGameObject(newobj);
-#endif
-
- // return value will be 0 if the object is actually deleted (all reference gone)
-
- return ret;
-}
-
-
-
-void KX_Scene::ReplaceMesh(class CValue* obj,void* meshobj, bool use_gfx, bool use_phys)
-{
- KX_GameObject* gameobj = static_cast<KX_GameObject*>(obj);
- RAS_MeshObject* mesh = static_cast<RAS_MeshObject*>(meshobj);
-
- if (!gameobj) {
- std::cout << "KX_Scene::ReplaceMesh Warning: invalid object, doing nothing" << std::endl;
- return;
- }
-
- if (use_gfx && mesh != NULL)
- {
- gameobj->RemoveMeshes();
- gameobj->AddMesh(mesh);
-
- if (gameobj->m_isDeformable)
- {
- BL_DeformableGameObject* newobj = static_cast<BL_DeformableGameObject*>( gameobj );
-
- if (newobj->GetDeformer())
- {
- delete newobj->GetDeformer();
- newobj->SetDeformer(NULL);
- }
-
- if (mesh->GetMesh())
- {
- // we must create a new deformer but which one?
- KX_GameObject* parentobj = newobj->GetParent();
- // this always return the original game object (also for replicate)
- Object* blendobj = newobj->GetBlenderObject();
- // object that owns the new mesh
- Object* oldblendobj = static_cast<struct Object*>(m_logicmgr->FindBlendObjByGameMeshName(mesh->GetName()));
- Mesh* blendmesh = mesh->GetMesh();
-
- bool bHasModifier = BL_ModifierDeformer::HasCompatibleDeformer(blendobj);
- bool bHasShapeKey = blendmesh->key != NULL && blendmesh->key->type==KEY_RELATIVE;
- bool bHasDvert = blendmesh->dvert != NULL;
- bool bHasArmature =
- BL_ModifierDeformer::HasArmatureDeformer(blendobj) &&
- parentobj && // current parent is armature
- parentobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE &&
- oldblendobj && // needed for mesh deform
- blendobj->parent && // original object had armature (not sure this test is needed)
- blendobj->parent->type == OB_ARMATURE &&
- blendmesh->dvert!=NULL; // mesh has vertex group
-#ifdef WITH_BULLET
- bool bHasSoftBody = (!parentobj && (blendobj->gameflag & OB_SOFT_BODY));
-#endif
-
- if (oldblendobj==NULL) {
- if (bHasModifier || bHasShapeKey || bHasDvert || bHasArmature) {
- std::cout << "warning: ReplaceMesh() new mesh is not used in an object from the current scene, you will get incorrect behavior" << std::endl;
- bHasShapeKey= bHasDvert= bHasArmature=bHasModifier= false;
- }
- }
-
- if (bHasModifier)
- {
- BL_ModifierDeformer* modifierDeformer;
- if (bHasShapeKey || bHasArmature)
- {
- modifierDeformer = new BL_ModifierDeformer(
- newobj,
- m_blenderScene,
- oldblendobj, blendobj,
- mesh,
- true,
- static_cast<BL_ArmatureObject*>( parentobj->AddRef() )
- );
- modifierDeformer->LoadShapeDrivers(parentobj);
- }
- else
- {
- modifierDeformer = new BL_ModifierDeformer(
- newobj,
- m_blenderScene,
- oldblendobj, blendobj,
- mesh,
- false,
- NULL
- );
- }
- newobj->SetDeformer(modifierDeformer);
- }
- else if (bHasShapeKey) {
- BL_ShapeDeformer* shapeDeformer;
- if (bHasArmature)
- {
- shapeDeformer = new BL_ShapeDeformer(
- newobj,
- oldblendobj, blendobj,
- mesh,
- true,
- true,
- static_cast<BL_ArmatureObject*>( parentobj->AddRef() )
- );
- shapeDeformer->LoadShapeDrivers(parentobj);
- }
- else
- {
- shapeDeformer = new BL_ShapeDeformer(
- newobj,
- oldblendobj, blendobj,
- mesh,
- false,
- true,
- NULL
- );
- }
- newobj->SetDeformer( shapeDeformer);
- }
- else if (bHasArmature)
- {
- BL_SkinDeformer* skinDeformer = new BL_SkinDeformer(
- newobj,
- oldblendobj, blendobj,
- mesh,
- true,
- true,
- static_cast<BL_ArmatureObject*>( parentobj->AddRef() )
- );
- newobj->SetDeformer(skinDeformer);
- }
- else if (bHasDvert)
- {
- BL_MeshDeformer* meshdeformer = new BL_MeshDeformer(
- newobj, oldblendobj, mesh
- );
- newobj->SetDeformer(meshdeformer);
- }
-#ifdef WITH_BULLET
- else if (bHasSoftBody)
- {
- KX_SoftBodyDeformer *softdeformer = new KX_SoftBodyDeformer(mesh, newobj);
- newobj->SetDeformer(softdeformer);
- }
-#endif
- }
- }
-
- gameobj->AddMeshUser();
- }
-
- if (use_phys) { /* update the new assigned mesh with the physics mesh */
- if (gameobj->GetPhysicsController())
- gameobj->GetPhysicsController()->ReinstancePhysicsShape(NULL, use_gfx?NULL:mesh);
- }
-}
-
-/* Font Object routines */
-void KX_Scene::AddFont(KX_FontObject* font)
-{
- if (!FindFont(font))
- m_fonts.push_back(font);
-}
-
-KX_FontObject* KX_Scene::FindFont(KX_FontObject* font)
-{
- list<KX_FontObject*>::iterator it = m_fonts.begin();
-
- while ((it != m_fonts.end()) && ((*it) != font))
- {
- ++it;
- }
-
- return ((it == m_fonts.end()) ? NULL : (*it));
-}
-
-
-/* Camera Object routines */
-KX_Camera* KX_Scene::FindCamera(KX_Camera* cam)
-{
- list<KX_Camera*>::iterator it = m_cameras.begin();
-
- while ((it != m_cameras.end()) && ((*it) != cam)) {
- it++;
- }
-
- return ((it == m_cameras.end()) ? NULL : (*it));
-}
-
-
-KX_Camera* KX_Scene::FindCamera(STR_String& name)
-{
- list<KX_Camera*>::iterator it = m_cameras.begin();
-
- while ((it != m_cameras.end()) && ((*it)->GetName() != name)) {
- it++;
- }
-
- return ((it == m_cameras.end()) ? NULL : (*it));
-}
-
-void KX_Scene::AddCamera(KX_Camera* cam)
-{
- if (!FindCamera(cam))
- m_cameras.push_back(cam);
-}
-
-
-KX_Camera* KX_Scene::GetActiveCamera()
-{
- // NULL if not defined
- return m_active_camera;
-}
-
-
-void KX_Scene::SetActiveCamera(KX_Camera* cam)
-{
- // only set if the cam is in the active list? Or add it otherwise?
- if (!FindCamera(cam)) {
- AddCamera(cam);
- if (cam) std::cout << "Added cam " << cam->GetName() << std::endl;
- }
-
- m_active_camera = cam;
-}
-
-void KX_Scene::SetCameraOnTop(KX_Camera* cam)
-{
- if (!FindCamera(cam)) {
- // adding is always done at the back, so that's all that needs to be done
- AddCamera(cam);
- if (cam) std::cout << "Added cam " << cam->GetName() << std::endl;
- } else {
- m_cameras.remove(cam);
- m_cameras.push_back(cam);
- }
-}
-
-void KX_Scene::MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera* cam, int layer)
-{
- int intersect = KX_Camera::INTERSECT;
- KX_GameObject *gameobj = node->Client()?(KX_GameObject*) node->Client()->GetSGClientObject():NULL;
- bool visible = (gameobj && gameobj->GetVisible() && (!layer || (gameobj->GetLayer() & layer)));
- bool dotest = visible || node->Left() || node->Right();
-
- /* If the camera is inside the box, assume intersect. */
- if (dotest && !node->inside( cam->NodeGetWorldPosition()))
- {
- MT_Scalar radius = node->Radius();
- MT_Point3 center = node->Center();
-
- intersect = cam->SphereInsideFrustum(center, radius);
-
- if (intersect == KX_Camera::INTERSECT)
- {
- MT_Point3 box[8];
- node->get(box);
- intersect = cam->BoxInsideFrustum(box);
- }
- }
-
- switch (intersect)
- {
- case KX_Camera::OUTSIDE:
- MarkSubTreeVisible(node, rasty, false, cam);
- break;
- case KX_Camera::INTERSECT:
- if (gameobj)
- MarkVisible(rasty, gameobj, cam, layer);
- if (node->Left())
- MarkVisible(node->Left(), rasty, cam, layer);
- if (node->Right())
- MarkVisible(node->Right(), rasty, cam, layer);
- break;
- case KX_Camera::INSIDE:
- MarkSubTreeVisible(node, rasty, true, cam, layer);
- break;
- }
-}
-
-void KX_Scene::MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible, KX_Camera* cam, int layer)
-{
- if (node->Client())
- {
- KX_GameObject *gameobj = (KX_GameObject*) node->Client()->GetSGClientObject();
- if (gameobj->GetVisible())
- {
- if (visible)
- {
- int nummeshes = gameobj->GetMeshCount();
-
- // this adds the vertices to the display list
- for (int m=0;m<nummeshes;m++)
- (gameobj->GetMesh(m))->SchedulePolygons(rasty->GetDrawingMode());
- }
-
- gameobj->SetCulled(!visible);
- gameobj->UpdateBuckets(false);
- }
- }
- if (node->Left())
- MarkSubTreeVisible(node->Left(), rasty, visible, cam, layer);
- if (node->Right())
- MarkSubTreeVisible(node->Right(), rasty, visible, cam, layer);
-}
-
-void KX_Scene::MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj,KX_Camera* cam,int layer)
-{
- // User (Python/Actuator) has forced object invisible...
- if (!gameobj->GetSGNode() || !gameobj->GetVisible())
- return;
-
- // Shadow lamp layers
- if (layer && !(gameobj->GetLayer() & layer)) {
- gameobj->SetCulled(true);
- gameobj->UpdateBuckets(false);
- return;
- }
-
- // If Frustum culling is off, the object is always visible.
- bool vis = !cam->GetFrustumCulling();
-
- // If the camera is inside this node, then the object is visible.
- if (!vis)
- {
- vis = gameobj->GetSGNode()->inside( cam->GetCameraLocation() );
- }
-
- // Test the object's bound sphere against the view frustum.
- if (!vis)
- {
- MT_Vector3 scale = gameobj->GetSGNode()->GetWorldScaling();
- MT_Scalar radius = fabs(scale[scale.closestAxis()] * gameobj->GetSGNode()->Radius());
- switch (cam->SphereInsideFrustum(gameobj->NodeGetWorldPosition(), radius))
- {
- case KX_Camera::INSIDE:
- vis = true;
- break;
- case KX_Camera::OUTSIDE:
- vis = false;
- break;
- case KX_Camera::INTERSECT:
- // Test the object's bound box against the view frustum.
- MT_Point3 box[8];
- gameobj->GetSGNode()->getBBox(box);
- vis = cam->BoxInsideFrustum(box) != KX_Camera::OUTSIDE;
- break;
- }
- }
-
- if (vis)
- {
- int nummeshes = gameobj->GetMeshCount();
-
- for (int m=0;m<nummeshes;m++)
- {
- // this adds the vertices to the display list
- (gameobj->GetMesh(m))->SchedulePolygons(rasty->GetDrawingMode());
- }
- // Visibility/ non-visibility are marked
- // elsewhere now.
- gameobj->SetCulled(false);
- gameobj->UpdateBuckets(false);
- } else {
- gameobj->SetCulled(true);
- gameobj->UpdateBuckets(false);
- }
-}
-
-void KX_Scene::PhysicsCullingCallback(KX_ClientObjectInfo *objectInfo, void* cullingInfo)
-{
- KX_GameObject* gameobj = objectInfo->m_gameobject;
- if (!gameobj->GetVisible())
- // ideally, invisible objects should be removed from the culling tree temporarily
- return;
- if (((CullingInfo*)cullingInfo)->m_layer && !(gameobj->GetLayer() & ((CullingInfo*)cullingInfo)->m_layer))
- // used for shadow: object is not in shadow layer
- return;
-
- // make object visible
- gameobj->SetCulled(false);
- gameobj->UpdateBuckets(false);
-}
-
-void KX_Scene::CalculateVisibleMeshes(RAS_IRasterizer* rasty,KX_Camera* cam, int layer)
-{
- bool dbvt_culling = false;
- if (m_dbvt_culling)
- {
- /* Reset KX_GameObject m_bCulled to true before doing culling
- * since DBVT culling will only set it to false.
- * This is similar to what RAS_BucketManager does for RAS_MeshSlot culling.
- */
- for (int i = 0; i < m_objectlist->GetCount(); i++) {
- KX_GameObject *gameobj = static_cast<KX_GameObject*>(m_objectlist->GetValue(i));
- gameobj->SetCulled(true);
- }
-
- // test culling through Bullet
- MT_Vector4 planes[6];
- // get the clip planes
- MT_Vector4* cplanes = cam->GetNormalizedClipPlanes();
- // and convert
- planes[0].setValue(cplanes[4].getValue()); // near
- planes[1].setValue(cplanes[5].getValue()); // far
- planes[2].setValue(cplanes[0].getValue()); // left
- planes[3].setValue(cplanes[1].getValue()); // right
- planes[4].setValue(cplanes[2].getValue()); // top
- planes[5].setValue(cplanes[3].getValue()); // bottom
- CullingInfo info(layer);
-
- float mvmat[16] = {0};
- cam->GetModelviewMatrix().getValue(mvmat);
- float pmat[16] = {0};
- cam->GetProjectionMatrix().getValue(pmat);
-
- dbvt_culling = m_physicsEnvironment->CullingTest(PhysicsCullingCallback,&info,planes,5,m_dbvt_occlusion_res,
- KX_GetActiveEngine()->GetCanvas()->GetViewPort(),
- mvmat, pmat);
- }
- if (!dbvt_culling) {
- // the physics engine couldn't help us, do it the hard way
- for (int i = 0; i < m_objectlist->GetCount(); i++)
- {
- MarkVisible(rasty, static_cast<KX_GameObject*>(m_objectlist->GetValue(i)), cam, layer);
- }
- }
-}
-
-// logic stuff
-void KX_Scene::LogicBeginFrame(double curtime)
-{
- // have a look at temp objects ...
- int lastobj = m_tempObjectList->GetCount() - 1;
-
- for (int i = lastobj; i >= 0; i--)
- {
- CValue* objval = m_tempObjectList->GetValue(i);
- CFloatValue* propval = (CFloatValue*) objval->GetProperty("::timebomb");
-
- if (propval)
- {
- float timeleft = (float)(propval->GetNumber() - 1.0/KX_KetsjiEngine::GetTicRate());
-
- if (timeleft > 0)
- {
- propval->SetFloat(timeleft);
- }
- else
- {
- DelayedRemoveObject(objval);
- // remove obj
- }
- }
- else
- {
- // all object is the tempObjectList should have a clock
- }
- }
- m_logicmgr->BeginFrame(curtime, 1.0/KX_KetsjiEngine::GetTicRate());
-}
-
-void KX_Scene::AddAnimatedObject(CValue* gameobj)
-{
- gameobj->AddRef();
- m_animatedlist->Add(gameobj);
-}
-
-static void update_anim_thread_func(TaskPool *pool, void *taskdata, int UNUSED(threadid))
-{
- KX_GameObject *gameobj, *child, *parent;
- CListValue *children;
- bool needs_update;
- double curtime = *(double*)BLI_task_pool_userdata(pool);
-
- gameobj = (KX_GameObject*)taskdata;
-
- // Non-armature updates are fast enough, so just update them
- needs_update = gameobj->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE;
-
- if (!needs_update) {
- // If we got here, we're looking to update an armature, so check its children meshes
- // to see if we need to bother with a more expensive pose update
- children = gameobj->GetChildren();
-
- bool has_mesh = false, has_non_mesh = false;
-
- // Check for meshes that haven't been culled
- for (int j=0; j<children->GetCount(); ++j) {
- child = (KX_GameObject*)children->GetValue(j);
-
- if (!child->GetCulled()) {
- needs_update = true;
- break;
- }
-
- if (child->GetMeshCount() == 0)
- has_non_mesh = true;
- else
- has_mesh = true;
- }
-
- // If we didn't find a non-culled mesh, check to see
- // if we even have any meshes, and update if this
- // armature has only non-mesh children.
- if (!needs_update && !has_mesh && has_non_mesh)
- needs_update = true;
-
- children->Release();
- }
-
- if (needs_update) {
- gameobj->UpdateActionManager(curtime);
- children = gameobj->GetChildren();
- parent = gameobj->GetParent();
-
- // Only do deformers here if they are not parented to an armature, otherwise the armature will
- // handle updating its children
- if (gameobj->GetDeformer() && (!parent || parent->GetGameObjectType() != SCA_IObject::OBJ_ARMATURE))
- gameobj->GetDeformer()->Update();
-
- for (int j=0; j<children->GetCount(); ++j) {
- child = (KX_GameObject*)children->GetValue(j);
-
- if (child->GetDeformer()) {
- child->GetDeformer()->Update();
- }
- }
-
- children->Release();
- }
-}
-
-void KX_Scene::UpdateAnimations(double curtime)
-{
- TaskPool *pool = BLI_task_pool_create(KX_GetActiveEngine()->GetTaskScheduler(), &curtime);
-
- for (int i=0; i<m_animatedlist->GetCount(); ++i) {
- BLI_task_pool_push(pool, update_anim_thread_func, m_animatedlist->GetValue(i), false, TASK_PRIORITY_LOW);
- }
-
- BLI_task_pool_work_and_wait(pool);
- BLI_task_pool_free(pool);
-}
-
-void KX_Scene::LogicUpdateFrame(double curtime, bool frame)
-{
- m_logicmgr->UpdateFrame(curtime, frame);
-}
-
-
-
-void KX_Scene::LogicEndFrame()
-{
- m_logicmgr->EndFrame();
- int numobj;
-
- KX_GameObject* obj;
-
- while ((numobj = m_euthanasyobjects->GetCount()) > 0)
- {
- // remove the object from this list to make sure we will not hit it again
- obj = (KX_GameObject*)m_euthanasyobjects->GetValue(numobj-1);
- m_euthanasyobjects->Remove(numobj-1);
- obj->Release();
- RemoveObject(obj);
- }
-
- //prepare obstacle simulation for new frame
- if (m_obstacleSimulation)
- m_obstacleSimulation->UpdateObstacles();
-}
-
-
-
-/**
- * UpdateParents: SceneGraph transformation update.
- */
-void KX_Scene::UpdateParents(double curtime)
-{
- // we use the SG dynamic list
- SG_Node* node;
-
- while ((node = SG_Node::GetNextScheduled(m_sghead)) != NULL)
- {
- node->UpdateWorldData(curtime);
- }
-
- //for (int i=0; i<GetRootParentList()->GetCount(); i++)
- //{
- // KX_GameObject* parentobj = (KX_GameObject*)GetRootParentList()->GetValue(i);
- // parentobj->NodeUpdateGS(curtime);
- //}
-
- // the list must be empty here
- assert(m_sghead.Empty());
- // some nodes may be ready for reschedule, move them to schedule list for next time
- while ((node = SG_Node::GetNextRescheduled(m_sghead)) != NULL)
- {
- node->Schedule(m_sghead);
- }
-}
-
-
-RAS_MaterialBucket* KX_Scene::FindBucket(class RAS_IPolyMaterial* polymat, bool &bucketCreated)
-{
- return m_bucketmanager->FindBucket(polymat, bucketCreated);
-}
-
-
-
-void KX_Scene::RenderBuckets(const MT_Transform & cameratransform,
- class RAS_IRasterizer* rasty)
-{
- m_bucketmanager->Renderbuckets(cameratransform,rasty);
- KX_BlenderMaterial::EndFrame();
-}
-
-void KX_Scene::RenderFonts()
-{
- list<KX_FontObject*>::iterator it = m_fonts.begin();
- while (it != m_fonts.end()) {
- (*it)->DrawFontText();
- ++it;
- }
-}
-
-void KX_Scene::UpdateObjectLods(void)
-{
- KX_GameObject* gameobj;
-
- if (!this->m_active_camera)
- return;
-
- MT_Vector3 cam_pos = this->m_active_camera->NodeGetWorldPosition();
-
- for (int i = 0; i < this->GetObjectList()->GetCount(); i++) {
- gameobj = (KX_GameObject*) GetObjectList()->GetValue(i);
- if (!gameobj->GetCulled()) {
- gameobj->UpdateLod(cam_pos);
- }
- }
-}
-
-void KX_Scene::SetLodHysteresis(bool active)
-{
- m_isActivedHysteresis = active;
-}
-
-bool KX_Scene::IsActivedLodHysteresis(void)
-{
- return m_isActivedHysteresis;
-}
-
-void KX_Scene::SetLodHysteresisValue(int hysteresisvalue)
-{
- m_lodHysteresisValue = hysteresisvalue;
-}
-
-int KX_Scene::GetLodHysteresisValue(void)
-{
- return m_lodHysteresisValue;
-}
-
-void KX_Scene::UpdateObjectActivity(void)
-{
- if (m_activity_culling) {
- /* determine the activity criterium and set objects accordingly */
- int i=0;
-
- MT_Point3 camloc = GetActiveCamera()->NodeGetWorldPosition(); //GetCameraLocation();
-
- for (i=0;i<GetObjectList()->GetCount();i++)
- {
- KX_GameObject* ob = (KX_GameObject*) GetObjectList()->GetValue(i);
-
- if (!ob->GetIgnoreActivityCulling()) {
- /* Simple test: more than 10 away from the camera, count
- * Manhattan distance. */
- MT_Point3 obpos = ob->NodeGetWorldPosition();
-
- if ((fabsf(camloc[0] - obpos[0]) > m_activity_box_radius) ||
- (fabsf(camloc[1] - obpos[1]) > m_activity_box_radius) ||
- (fabsf(camloc[2] - obpos[2]) > m_activity_box_radius) )
- {
- ob->Suspend();
- }
- else {
- ob->Resume();
- }
- }
- }
- }
-}
-
-void KX_Scene::SetActivityCullingRadius(float f)
-{
- if (f < 0.5f)
- f = 0.5f;
- m_activity_box_radius = f;
-}
-
-NG_NetworkDeviceInterface* KX_Scene::GetNetworkDeviceInterface()
-{
- return m_networkDeviceInterface;
-}
-
-NG_NetworkScene* KX_Scene::GetNetworkScene()
-{
- return m_networkScene;
-}
-
-void KX_Scene::SetNetworkDeviceInterface(NG_NetworkDeviceInterface* newInterface)
-{
- m_networkDeviceInterface = newInterface;
-}
-
-void KX_Scene::SetNetworkScene(NG_NetworkScene *newScene)
-{
- m_networkScene = newScene;
-}
-
-
-void KX_Scene::SetGravity(const MT_Vector3& gravity)
-{
- GetPhysicsEnvironment()->SetGravity(gravity[0],gravity[1],gravity[2]);
-}
-
-MT_Vector3 KX_Scene::GetGravity()
-{
- MT_Vector3 gravity;
-
- GetPhysicsEnvironment()->GetGravity(gravity);
-
- return gravity;
-}
-
-void KX_Scene::SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter)
-{
- m_sceneConverter = sceneConverter;
-}
-
-void KX_Scene::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv)
-{
- m_physicsEnvironment = physEnv;
- if (m_physicsEnvironment) {
- KX_TouchEventManager* touchmgr = new KX_TouchEventManager(m_logicmgr, physEnv);
- m_logicmgr->RegisterEventManager(touchmgr);
- }
-}
-
-void KX_Scene::setSuspendedTime(double suspendedtime)
-{
- m_suspendedtime = suspendedtime;
-}
-double KX_Scene::getSuspendedTime()
-{
- return m_suspendedtime;
-}
-void KX_Scene::setSuspendedDelta(double suspendeddelta)
-{
- m_suspendeddelta = suspendeddelta;
-}
-double KX_Scene::getSuspendedDelta()
-{
- return m_suspendeddelta;
-}
-
-short KX_Scene::GetAnimationFPS()
-{
- return m_blenderScene->r.frs_sec;
-}
-
-static void MergeScene_LogicBrick(SCA_ILogicBrick* brick, KX_Scene *from, KX_Scene *to)
-{
- SCA_LogicManager *logicmgr= to->GetLogicManager();
-
- brick->Replace_IScene(to);
- brick->Replace_NetworkScene(to->GetNetworkScene());
- brick->SetLogicManager(to->GetLogicManager());
-
- // If we end up replacing a KX_TouchEventManager, we need to make sure
- // physics controllers are properly in place. In other words, do this
- // after merging physics controllers!
- SCA_ISensor *sensor= dynamic_cast<class SCA_ISensor *>(brick);
- if (sensor) {
- sensor->Replace_EventManager(logicmgr);
- }
-
- SCA_2DFilterActuator *filter_actuator = dynamic_cast<class SCA_2DFilterActuator*>(brick);
- if (filter_actuator) {
- filter_actuator->SetScene(to);
- }
-
-#ifdef WITH_PYTHON
- // Python must be called from the main thread unless we want to deal
- // with GIL issues. So, this is delayed until here in case of async
- // libload (originally in KX_ConvertControllers)
- SCA_PythonController *pyctrl = dynamic_cast<SCA_PythonController*>(brick);
- if (pyctrl) {
- pyctrl->SetNamespace(KX_GetActiveEngine()->GetPyNamespace());
-
- if (pyctrl->m_mode==SCA_PythonController::SCA_PYEXEC_SCRIPT)
- pyctrl->Compile();
- }
-#endif
-}
-
-static void MergeScene_GameObject(KX_GameObject* gameobj, KX_Scene *to, KX_Scene *from)
-{
- {
- SCA_ActuatorList& actuators= gameobj->GetActuators();
- SCA_ActuatorList::iterator ita;
-
- for (ita = actuators.begin(); !(ita==actuators.end()); ++ita)
- {
- MergeScene_LogicBrick(*ita, from, to);
- }
- }
-
-
- {
- SCA_SensorList& sensors= gameobj->GetSensors();
- SCA_SensorList::iterator its;
-
- for (its = sensors.begin(); !(its==sensors.end()); ++its)
- {
- MergeScene_LogicBrick(*its, from, to);
- }
- }
-
- {
- SCA_ControllerList& controllers= gameobj->GetControllers();
- SCA_ControllerList::iterator itc;
-
- for (itc = controllers.begin(); !(itc==controllers.end()); ++itc)
- {
- SCA_IController *cont= *itc;
- MergeScene_LogicBrick(cont, from, to);
- }
- }
-
- /* graphics controller */
- PHY_IController *ctrl = gameobj->GetGraphicController();
- if (ctrl) {
- /* SHOULD update the m_cullingTree */
- ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
- }
-
- ctrl = gameobj->GetPhysicsController();
- if (ctrl) {
- ctrl->SetPhysicsEnvironment(to->GetPhysicsEnvironment());
- }
-
- /* SG_Node can hold a scene reference */
- SG_Node *sg= gameobj->GetSGNode();
- if (sg) {
- if (sg->GetSGClientInfo() == from) {
- sg->SetSGClientInfo(to);
-
- /* Make sure to grab the children too since they might not be tied to a game object */
- NodeList children = sg->GetSGChildren();
- for (int i=0; i<children.size(); i++)
- children[i]->SetSGClientInfo(to);
- }
- }
- /* If the object is a light, update it's scene */
- if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_LIGHT)
- ((KX_LightObject*)gameobj)->UpdateScene(to);
-
- if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_CAMERA)
- to->AddCamera((KX_Camera*)gameobj);
-
- // All armatures should be in the animated object list to be umpdated.
- if (gameobj->GetGameObjectType() == SCA_IObject::OBJ_ARMATURE)
- to->AddAnimatedObject(gameobj);
-
- /* Add the object to the scene's logic manager */
- to->GetLogicManager()->RegisterGameObjectName(gameobj->GetName(), gameobj);
- to->GetLogicManager()->RegisterGameObj(gameobj->GetBlenderObject(), gameobj);
-
- for (int i = 0; i < gameobj->GetMeshCount(); ++i) {
- RAS_MeshObject *meshobj = gameobj->GetMesh(i);
- // Register the mesh object by name and blender object.
- to->GetLogicManager()->RegisterGameMeshName(meshobj->GetName(), gameobj->GetBlenderObject());
- to->GetLogicManager()->RegisterMeshName(meshobj->GetName(), meshobj);
- }
-}
-
-bool KX_Scene::MergeScene(KX_Scene *other)
-{
- PHY_IPhysicsEnvironment *env = this->GetPhysicsEnvironment();
- PHY_IPhysicsEnvironment *env_other = other->GetPhysicsEnvironment();
-
- if ((env==NULL) != (env_other==NULL)) /* TODO - even when both scenes have NONE physics, the other is loaded with bullet enabled, ??? */
- {
- printf("KX_Scene::MergeScene: physics scenes type differ, aborting\n");
- printf("\tsource %d, terget %d\n", (int)(env!=NULL), (int)(env_other!=NULL));
- return false;
- }
-
- if (GetSceneConverter() != other->GetSceneConverter()) {
- printf("KX_Scene::MergeScene: converters differ, aborting\n");
- return false;
- }
-
-
- GetBucketManager()->MergeBucketManager(other->GetBucketManager(), this);
-
-
- /* active + inactive == all ??? - lets hope so */
- for (int i = 0; i < other->GetObjectList()->GetCount(); i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*)other->GetObjectList()->GetValue(i);
- MergeScene_GameObject(gameobj, this, other);
-
- /* add properties to debug list for LibLoad objects */
- if (KX_GetActiveEngine()->GetAutoAddDebugProperties()) {
- AddObjectDebugProperties(gameobj);
- }
-
- gameobj->UpdateBuckets(false); /* only for active objects */
- }
-
- for (int i = 0; i < other->GetInactiveList()->GetCount(); i++)
- {
- KX_GameObject* gameobj = (KX_GameObject*)other->GetInactiveList()->GetValue(i);
- MergeScene_GameObject(gameobj, this, other);
- }
-
- if (env) {
- env->MergeEnvironment(env_other);
- CListValue *otherObjects = other->GetObjectList();
-
- // List of all physics objects to merge (needed by ReplicateConstraints).
- std::vector<KX_GameObject *> physicsObjects;
- for (unsigned int i = 0; i < otherObjects->GetCount(); ++i) {
- KX_GameObject *gameobj = (KX_GameObject *)otherObjects->GetValue(i);
- if (gameobj->GetPhysicsController()) {
- physicsObjects.push_back(gameobj);
- }
- }
-
- for (unsigned int i = 0; i < physicsObjects.size(); ++i) {
- KX_GameObject *gameobj = physicsObjects[i];
- // Replicate all constraints in the right physics environment.
- gameobj->GetPhysicsController()->ReplicateConstraints(gameobj, physicsObjects);
- gameobj->ClearConstraints();
- }
- }
-
-
- GetTempObjectList()->MergeList(other->GetTempObjectList());
- other->GetTempObjectList()->ReleaseAndRemoveAll();
-
- GetObjectList()->MergeList(other->GetObjectList());
- other->GetObjectList()->ReleaseAndRemoveAll();
-
- GetInactiveList()->MergeList(other->GetInactiveList());
- other->GetInactiveList()->ReleaseAndRemoveAll();
-
- GetRootParentList()->MergeList(other->GetRootParentList());
- other->GetRootParentList()->ReleaseAndRemoveAll();
-
- GetLightList()->MergeList(other->GetLightList());
- other->GetLightList()->ReleaseAndRemoveAll();
-
- /* move materials across, assume they both use the same scene-converters
- * Do this after lights are merged so materials can use the lights in shaders
- */
- GetSceneConverter()->MergeScene(this, other);
-
- /* merge logic */
- {
- SCA_LogicManager *logicmgr= GetLogicManager();
- SCA_LogicManager *logicmgr_other= other->GetLogicManager();
-
- vector<class SCA_EventManager*>evtmgrs= logicmgr->GetEventManagers();
- //vector<class SCA_EventManager*>evtmgrs_others= logicmgr_other->GetEventManagers();
-
- //SCA_EventManager *evtmgr;
- SCA_EventManager *evtmgr_other;
-
- for (unsigned int i= 0; i < evtmgrs.size(); i++) {
- evtmgr_other= logicmgr_other->FindEventManager(evtmgrs[i]->GetType());
-
- if (evtmgr_other) /* unlikely but possible one scene has a joystick and not the other */
- evtmgr_other->Replace_LogicManager(logicmgr);
-
- /* when merging objects sensors are moved across into the new manager, don't need to do this here */
- }
-
- /* grab any timer properties from the other scene */
- SCA_TimeEventManager *timemgr= GetTimeEventManager();
- SCA_TimeEventManager *timemgr_other= other->GetTimeEventManager();
- vector<CValue*> times = timemgr_other->GetTimeValues();
-
- for (unsigned int i= 0; i < times.size(); i++) {
- timemgr->AddTimeProperty(times[i]);
- }
-
- }
- return true;
-}
-
-void KX_Scene::Update2DFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text)
-{
- m_filtermanager.EnableFilter(propNames, gameObj, filtermode, pass, text);
-}
-
-void KX_Scene::Render2DFilters(RAS_ICanvas* canvas)
-{
- m_filtermanager.RenderFilters(canvas);
-}
-
-#ifdef WITH_PYTHON
-
-void KX_Scene::RunDrawingCallbacks(PyObject *cb_list)
-{
- if (!cb_list || PyList_GET_SIZE(cb_list) == 0)
- return;
-
- RunPythonCallBackList(cb_list, NULL, 0, 0);
-}
-
-//----------------------------------------------------------------------------
-//Python
-
-PyTypeObject KX_Scene::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_Scene",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,
- &Sequence,
- &Mapping,
- 0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_Scene::Methods[] = {
- KX_PYMETHODTABLE(KX_Scene, addObject),
- KX_PYMETHODTABLE(KX_Scene, end),
- KX_PYMETHODTABLE(KX_Scene, restart),
- KX_PYMETHODTABLE(KX_Scene, replace),
- KX_PYMETHODTABLE(KX_Scene, suspend),
- KX_PYMETHODTABLE(KX_Scene, resume),
- KX_PYMETHODTABLE(KX_Scene, drawObstacleSimulation),
-
-
- /* dict style access */
- KX_PYMETHODTABLE(KX_Scene, get),
-
- {NULL,NULL} //Sentinel
-};
-static PyObject *Map_GetItem(PyObject *self_v, PyObject *item)
-{
- KX_Scene* self = static_cast<KX_Scene*>BGE_PROXY_REF(self_v);
- const char *attr_str= _PyUnicode_AsString(item);
- PyObject *pyconvert;
-
- if (self == NULL) {
- PyErr_SetString(PyExc_SystemError, "val = scene[key]: KX_Scene, " BGE_PROXY_ERROR_MSG);
- return NULL;
- }
-
- if (!self->m_attr_dict)
- self->m_attr_dict = PyDict_New();
-
- if (self->m_attr_dict && (pyconvert=PyDict_GetItem(self->m_attr_dict, item))) {
-
- if (attr_str)
- PyErr_Clear();
- Py_INCREF(pyconvert);
- return pyconvert;
- }
- else {
- if (attr_str) PyErr_Format(PyExc_KeyError, "value = scene[key]: KX_Scene, key \"%s\" does not exist", attr_str);
- else PyErr_SetString(PyExc_KeyError, "value = scene[key]: KX_Scene, key does not exist");
- return NULL;
- }
-
-}
-
-static int Map_SetItem(PyObject *self_v, PyObject *key, PyObject *val)
-{
- KX_Scene* self = static_cast<KX_Scene*>BGE_PROXY_REF(self_v);
- const char *attr_str= _PyUnicode_AsString(key);
- if (attr_str==NULL)
- PyErr_Clear();
-
- if (self == NULL) {
- PyErr_SetString(PyExc_SystemError, "scene[key] = value: KX_Scene, " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (!self->m_attr_dict)
- self->m_attr_dict = PyDict_New();
-
- if (val==NULL) { /* del ob["key"] */
- int del= 0;
-
- if (self->m_attr_dict)
- del |= (PyDict_DelItem(self->m_attr_dict, key)==0) ? 1:0;
-
- if (del==0) {
- if (attr_str) PyErr_Format(PyExc_KeyError, "scene[key] = value: KX_Scene, key \"%s\" could not be set", attr_str);
- else PyErr_SetString(PyExc_KeyError, "del scene[key]: KX_Scene, key could not be deleted");
- return -1;
- }
- else if (self->m_attr_dict) {
- PyErr_Clear(); /* PyDict_DelItem sets an error when it fails */
- }
- }
- else { /* ob["key"] = value */
- int set = 0;
-
- if (self->m_attr_dict==NULL) /* lazy init */
- self->m_attr_dict= PyDict_New();
-
-
- if (PyDict_SetItem(self->m_attr_dict, key, val)==0)
- set= 1;
- else
- PyErr_SetString(PyExc_KeyError, "scene[key] = value: KX_Scene, key not be added to internal dictionary");
-
- if (set==0)
- return -1; /* pythons error value */
-
- }
-
- return 0; /* success */
-}
-
-static int Seq_Contains(PyObject *self_v, PyObject *value)
-{
- KX_Scene* self = static_cast<KX_Scene*>BGE_PROXY_REF(self_v);
-
- if (self == NULL) {
- PyErr_SetString(PyExc_SystemError, "val in scene: KX_Scene, " BGE_PROXY_ERROR_MSG);
- return -1;
- }
-
- if (!self->m_attr_dict)
- self->m_attr_dict = PyDict_New();
-
- if (self->m_attr_dict && PyDict_GetItem(self->m_attr_dict, value))
- return 1;
-
- return 0;
-}
-
-PyMappingMethods KX_Scene::Mapping = {
- (lenfunc)NULL, /* inquiry mp_length */
- (binaryfunc)Map_GetItem, /* binaryfunc mp_subscript */
- (objobjargproc)Map_SetItem, /* objobjargproc mp_ass_subscript */
-};
-
-PySequenceMethods KX_Scene::Sequence = {
- NULL, /* Cant set the len otherwise it can evaluate as false */
- NULL, /* sq_concat */
- NULL, /* sq_repeat */
- NULL, /* sq_item */
- NULL, /* sq_slice */
- NULL, /* sq_ass_item */
- NULL, /* sq_ass_slice */
- (objobjproc)Seq_Contains, /* sq_contains */
- (binaryfunc) NULL, /* sq_inplace_concat */
- (ssizeargfunc) NULL, /* sq_inplace_repeat */
-};
-
-PyObject *KX_Scene::pyattr_get_name(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- return PyUnicode_From_STR_String(self->GetName());
-}
-
-PyObject *KX_Scene::pyattr_get_objects(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- return self->GetObjectList()->GetProxy();
-}
-
-PyObject *KX_Scene::pyattr_get_objects_inactive(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- return self->GetInactiveList()->GetProxy();
-}
-
-PyObject *KX_Scene::pyattr_get_lights(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- return self->GetLightList()->GetProxy();
-}
-
-PyObject *KX_Scene::pyattr_get_world(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- KX_WorldInfo *world = self->GetWorldInfo();
-
- if (world->GetName() != "") {
- return world->GetProxy();
- }
- else {
- Py_RETURN_NONE;
- }
-}
-
-PyObject *KX_Scene::pyattr_get_cameras(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- /* With refcounts in this case...
- * the new CListValue is owned by python, so its possible python holds onto it longer then the BGE
- * however this is the same with "scene.objects + []", when you make a copy by adding lists.
- */
-
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- CListValue* clist = new CListValue();
-
- /* return self->GetCameras()->GetProxy(); */
-
- list<KX_Camera*>::iterator it = self->GetCameras()->begin();
- while (it != self->GetCameras()->end()) {
- clist->Add((*it)->AddRef());
- it++;
- }
-
- return clist->NewProxy(true);
-}
-
-PyObject *KX_Scene::pyattr_get_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- KX_Camera* cam= self->GetActiveCamera();
- if (cam)
- return self->GetActiveCamera()->GetProxy();
- else
- Py_RETURN_NONE;
-}
-
-
-int KX_Scene::pyattr_set_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
- KX_Camera *camOb;
-
- if (!ConvertPythonToCamera(value, &camOb, false, "scene.active_camera = value: KX_Scene"))
- return PY_SET_ATTR_FAIL;
-
- self->SetActiveCamera(camOb);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Scene::pyattr_get_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- if (self->m_draw_call_pre==NULL)
- self->m_draw_call_pre= PyList_New(0);
- Py_INCREF(self->m_draw_call_pre);
- return self->m_draw_call_pre;
-}
-
-PyObject *KX_Scene::pyattr_get_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- if (self->m_draw_call_post==NULL)
- self->m_draw_call_post= PyList_New(0);
- Py_INCREF(self->m_draw_call_post);
- return self->m_draw_call_post;
-}
-
-PyObject *KX_Scene::pyattr_get_drawing_setup_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- if (self->m_draw_setup_call_pre == NULL)
- self->m_draw_setup_call_pre = PyList_New(0);
-
- Py_INCREF(self->m_draw_setup_call_pre);
- return self->m_draw_setup_call_pre;
-}
-
-int KX_Scene::pyattr_set_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- if (!PyList_CheckExact(value))
- {
- PyErr_SetString(PyExc_ValueError, "Expected a list");
- return PY_SET_ATTR_FAIL;
- }
- Py_XDECREF(self->m_draw_call_pre);
-
- Py_INCREF(value);
- self->m_draw_call_pre = value;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-int KX_Scene::pyattr_set_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- if (!PyList_CheckExact(value))
- {
- PyErr_SetString(PyExc_ValueError, "Expected a list");
- return PY_SET_ATTR_FAIL;
- }
- Py_XDECREF(self->m_draw_call_post);
-
- Py_INCREF(value);
- self->m_draw_call_post = value;
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-int KX_Scene::pyattr_set_drawing_setup_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- if (!PyList_CheckExact(value)) {
- PyErr_SetString(PyExc_ValueError, "Expected a list");
- return PY_SET_ATTR_FAIL;
- }
-
- Py_XDECREF(self->m_draw_setup_call_pre);
- Py_INCREF(value);
-
- self->m_draw_setup_call_pre = value;
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_Scene::pyattr_get_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- return PyObjectFrom(self->GetGravity());
-}
-
-int KX_Scene::pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_Scene* self = static_cast<KX_Scene*>(self_v);
-
- MT_Vector3 vec;
- if (!PyVecTo(value, vec))
- return PY_SET_ATTR_FAIL;
-
- self->SetGravity(vec);
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyAttributeDef KX_Scene::Attributes[] = {
- KX_PYATTRIBUTE_RO_FUNCTION("name", KX_Scene, pyattr_get_name),
- KX_PYATTRIBUTE_RO_FUNCTION("objects", KX_Scene, pyattr_get_objects),
- KX_PYATTRIBUTE_RO_FUNCTION("objectsInactive", KX_Scene, pyattr_get_objects_inactive),
- KX_PYATTRIBUTE_RO_FUNCTION("lights", KX_Scene, pyattr_get_lights),
- KX_PYATTRIBUTE_RO_FUNCTION("cameras", KX_Scene, pyattr_get_cameras),
- KX_PYATTRIBUTE_RO_FUNCTION("world", KX_Scene, pyattr_get_world),
- KX_PYATTRIBUTE_RW_FUNCTION("active_camera", KX_Scene, pyattr_get_active_camera, pyattr_set_active_camera),
- KX_PYATTRIBUTE_RW_FUNCTION("pre_draw", KX_Scene, pyattr_get_drawing_callback_pre, pyattr_set_drawing_callback_pre),
- KX_PYATTRIBUTE_RW_FUNCTION("post_draw", KX_Scene, pyattr_get_drawing_callback_post, pyattr_set_drawing_callback_post),
- KX_PYATTRIBUTE_RW_FUNCTION("pre_draw_setup", KX_Scene, pyattr_get_drawing_setup_callback_pre, pyattr_set_drawing_setup_callback_pre),
- KX_PYATTRIBUTE_RW_FUNCTION("gravity", KX_Scene, pyattr_get_gravity, pyattr_set_gravity),
- KX_PYATTRIBUTE_BOOL_RO("suspended", KX_Scene, m_suspend),
- KX_PYATTRIBUTE_BOOL_RO("activity_culling", KX_Scene, m_activity_culling),
- KX_PYATTRIBUTE_FLOAT_RW("activity_culling_radius", 0.5f, FLT_MAX, KX_Scene, m_activity_box_radius),
- KX_PYATTRIBUTE_BOOL_RO("dbvt_culling", KX_Scene, m_dbvt_culling),
- { NULL } //Sentinel
-};
-
-KX_PYMETHODDEF_DOC(KX_Scene, addObject,
-"addObject(object, other, time=0)\n"
-"Returns the added object.\n")
-{
- PyObject *pyob, *pyreference = Py_None;
- KX_GameObject *ob, *reference;
-
- int time = 0;
-
- if (!PyArg_ParseTuple(args, "O|Oi:addObject", &pyob, &pyreference, &time))
- return NULL;
-
- if (!ConvertPythonToGameObject(m_logicmgr, pyob, &ob, false, "scene.addObject(object, reference, time): KX_Scene (first argument)") ||
- !ConvertPythonToGameObject(m_logicmgr, pyreference, &reference, true, "scene.addObject(object, reference, time): KX_Scene (second argument)"))
- return NULL;
-
- if (!m_inactivelist->SearchValue(ob)) {
- PyErr_Format(PyExc_ValueError, "scene.addObject(object, reference, time): KX_Scene (first argument): object must be in an inactive layer");
- return NULL;
- }
- SCA_IObject *replica = AddReplicaObject((SCA_IObject*)ob, reference, time);
-
- // release here because AddReplicaObject AddRef's
- // the object is added to the scene so we don't want python to own a reference
- replica->Release();
- return replica->GetProxy();
-}
-
-KX_PYMETHODDEF_DOC(KX_Scene, end,
-"end()\n"
-"Removes this scene from the game.\n")
-{
-
- KX_GetActiveEngine()->RemoveScene(m_sceneName);
-
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(KX_Scene, restart,
- "restart()\n"
- "Restarts this scene.\n")
-{
- KX_GetActiveEngine()->ReplaceScene(m_sceneName, m_sceneName);
-
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(KX_Scene, replace,
- "replace(newScene)\n"
- "Replaces this scene with another one.\n"
- "Return True if the new scene exists and scheduled for replacement, False otherwise.\n")
-{
- char* name;
-
- if (!PyArg_ParseTuple(args, "s:replace", &name))
- return NULL;
-
- if (KX_GetActiveEngine()->ReplaceScene(m_sceneName, name))
- Py_RETURN_TRUE;
-
- Py_RETURN_FALSE;
-}
-
-KX_PYMETHODDEF_DOC(KX_Scene, suspend,
- "suspend()\n"
- "Suspends this scene.\n")
-{
- Suspend();
-
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(KX_Scene, resume,
- "resume()\n"
- "Resumes this scene.\n")
-{
- Resume();
-
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC(KX_Scene, drawObstacleSimulation,
- "drawObstacleSimulation()\n"
- "Draw debug visualization of obstacle simulation.\n")
-{
- if (GetObstacleSimulation())
- GetObstacleSimulation()->DrawObstacles();
-
- Py_RETURN_NONE;
-}
-
-/* Matches python dict.get(key, [default]) */
-KX_PYMETHODDEF_DOC(KX_Scene, get, "")
-{
- PyObject *key;
- PyObject *def = Py_None;
- PyObject *ret;
-
- if (!PyArg_ParseTuple(args, "O|O:get", &key, &def))
- return NULL;
-
- if (m_attr_dict && (ret=PyDict_GetItem(m_attr_dict, key))) {
- Py_INCREF(ret);
- return ret;
- }
-
- Py_INCREF(def);
- return def;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_Scene.h b/source/gameengine/Ketsji/KX_Scene.h
deleted file mode 100644
index 6d8ae8a321b..00000000000
--- a/source/gameengine/Ketsji/KX_Scene.h
+++ /dev/null
@@ -1,697 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_Scene.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_SCENE_H__
-#define __KX_SCENE_H__
-
-
-#include "KX_PhysicsEngineEnums.h"
-
-#include <vector>
-#include <set>
-#include <list>
-
-#include "CTR_Map.h"
-#include "CTR_HashedPtr.h"
-#include "SG_IObject.h"
-#include "SCA_IScene.h"
-#include "MT_Transform.h"
-
-#include "RAS_FramingManager.h"
-#include "RAS_Rect.h"
-
-
-#include "EXP_PyObjectPlus.h"
-#include "RAS_2DFilterManager.h"
-
-/**
- * \section Forward declarations
- */
-struct SM_MaterialProps;
-struct SM_ShapeProps;
-struct Scene;
-
-class CTR_HashedPtr;
-class CListValue;
-class CValue;
-class SCA_LogicManager;
-class SCA_KeyboardManager;
-class SCA_TimeEventManager;
-class SCA_MouseManager;
-class SCA_ISystem;
-class SCA_IInputDevice;
-class NG_NetworkDeviceInterface;
-class NG_NetworkScene;
-class SG_IObject;
-class SG_Node;
-class SG_Tree;
-class KX_WorldInfo;
-class KX_Camera;
-class KX_GameObject;
-class KX_LightObject;
-class RAS_BucketManager;
-class RAS_MaterialBucket;
-class RAS_IPolyMaterial;
-class RAS_IRasterizer;
-class RAS_IRenderTools;
-class SCA_JoystickManager;
-class btCollisionShape;
-class KX_BlenderSceneConverter;
-struct KX_ClientObjectInfo;
-class KX_ObstacleSimulation;
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/* for ID freeing */
-#define IS_TAGGED(_id) ((_id) && (((ID *)_id)->tag & LIB_TAG_DOIT))
-
-/**
- * The KX_Scene holds all data for an independent scene. It relates
- * KX_Objects to the specific objects in the modules.
- * */
-class KX_Scene : public PyObjectPlus, public SCA_IScene
-{
- Py_Header
-
-#ifdef WITH_PYTHON
- PyObject* m_attr_dict;
- PyObject* m_draw_call_pre;
- PyObject* m_draw_call_post;
- PyObject* m_draw_setup_call_pre;
-#endif
-
- struct CullingInfo {
- int m_layer;
- CullingInfo(int layer) : m_layer(layer) {}
- };
-
-protected:
- RAS_BucketManager* m_bucketmanager;
- CListValue* m_tempObjectList;
-
- /**
- * The list of objects which have been removed during the
- * course of one frame. They are actually destroyed in
- * LogicEndFrame() via a call to RemoveObject().
- */
- CListValue* m_euthanasyobjects;
-
- CListValue* m_objectlist;
- CListValue* m_parentlist; // all 'root' parents
- CListValue* m_lightlist;
- CListValue* m_inactivelist; // all objects that are not in the active layer
- CListValue* m_animatedlist; // all animated objects
-
- SG_QList m_sghead; // list of nodes that needs scenegraph update
- // the Dlist is not object that must be updated
- // the Qlist is for objects that needs to be rescheduled
- // for updates after udpate is over (slow parent, bone parent)
-
-
- /**
- * The set of cameras for this scene
- */
- std::list<class KX_Camera*> m_cameras;
-
- /**
- * The set of fonts for this scene
- */
- std::list<class KX_FontObject*> m_fonts;
-
-
- /**
- * Various SCA managers used by the scene
- */
- SCA_LogicManager* m_logicmgr;
- SCA_KeyboardManager* m_keyboardmgr;
- SCA_MouseManager* m_mousemgr;
- SCA_TimeEventManager* m_timemgr;
-
- // Scene converter where many scene entities are registered
- // Used to deregister objects that are deleted
- class KX_BlenderSceneConverter* m_sceneConverter;
- /**
- * physics engine abstraction
- */
- //e_PhysicsEngine m_physicsEngine; //who needs this ?
- class PHY_IPhysicsEnvironment* m_physicsEnvironment;
-
- /**
- * Does this scene clear the z-buffer?
- */
- bool m_isclearingZbuffer;
-
- /**
- * Does the shadow buffer needs calculing
- */
- bool m_isShadowDone;
-
- /**
- * The name of the scene
- */
- STR_String m_sceneName;
-
- /**
- * stores the world-settings for a scene
- */
- KX_WorldInfo* m_worldinfo;
-
- /**
- * \section Different scenes, linked to ketsji scene
- */
-
- /**
- * Network scene.
- */
- NG_NetworkDeviceInterface* m_networkDeviceInterface;
- NG_NetworkScene* m_networkScene;
-
- /**
- * A temporary variable used to parent objects together on
- * replication. Don't get confused by the name it is not
- * the scene's root node!
- */
- SG_Node* m_rootnode;
-
- /**
- * The active camera for the scene
- */
- KX_Camera* m_active_camera;
-
- /**
- * Another temporary variable outstaying its welcome
- * used in AddReplicaObject to map game objects to their
- * replicas so pointers can be updated.
- */
- CTR_Map <CTR_HashedPtr, void*> m_map_gameobject_to_replica;
-
- /**
- * Another temporary variable outstaying its welcome
- * used in AddReplicaObject to keep a record of all added
- * objects. Logic can only be updated when all objects
- * have been updated. This stores a list of the new objects.
- */
- std::vector<KX_GameObject*> m_logicHierarchicalGameObjects;
-
- /**
- * This temporary variable will contain the list of
- * object that can be added during group instantiation.
- * objects outside this list will not be added (can
- * happen with children that are outside the group).
- * Used in AddReplicaObject. If the list is empty, it
- * means don't care.
- */
- std::set<CValue*> m_groupGameObjects;
-
- /**
- * Pointer to system variable passed in in constructor
- * only used in constructor so we do not need to keep it
- * around in this class.
- */
-
- SCA_ISystem* m_kxsystem;
-
- /**
- * The execution priority of replicated object actuators?
- */
- int m_ueberExecutionPriority;
-
- /**
- * Activity 'bubble' settings :
- * Suspend (freeze) the entire scene.
- */
- bool m_suspend;
-
- /**
- * Radius in Manhattan distance of the box for activity culling.
- */
- float m_activity_box_radius;
-
- /**
- * Toggle to enable or disable activity culling.
- */
- bool m_activity_culling;
-
- /**
- * Toggle to enable or disable culling via DBVT broadphase of Bullet.
- */
- bool m_dbvt_culling;
-
- /**
- * Occlusion culling resolution
- */
- int m_dbvt_occlusion_res;
-
- /**
- * The framing settings used by this scene
- */
-
- RAS_FrameSettings m_frame_settings;
-
- /**
- * This scenes viewport into the game engine
- * canvas.Maintained externally, initially [0,0] -> [0,0]
- */
- RAS_Rect m_viewport;
-
- /**
- * Visibility testing functions.
- */
- void MarkVisible(SG_Tree *node, RAS_IRasterizer* rasty, KX_Camera*cam,int layer=0);
- void MarkSubTreeVisible(SG_Tree *node, RAS_IRasterizer* rasty, bool visible, KX_Camera*cam,int layer=0);
- void MarkVisible(RAS_IRasterizer* rasty, KX_GameObject* gameobj, KX_Camera*cam, int layer=0);
- static void PhysicsCullingCallback(KX_ClientObjectInfo* objectInfo, void* cullingInfo);
-
- double m_suspendedtime;
- double m_suspendeddelta;
-
- struct Scene* m_blenderScene;
-
- RAS_2DFilterManager m_filtermanager;
-
- KX_ObstacleSimulation* m_obstacleSimulation;
-
- /**
- * LOD Hysteresis settings
- */
- bool m_isActivedHysteresis;
- int m_lodHysteresisValue;
-
-public:
- KX_Scene(class SCA_IInputDevice* keyboarddevice,
- class SCA_IInputDevice* mousedevice,
- class NG_NetworkDeviceInterface* ndi,
- const STR_String& scenename,
- struct Scene* scene,
- class RAS_ICanvas* canvas);
-
- virtual
- ~KX_Scene();
-
- RAS_BucketManager* GetBucketManager();
- RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial* polymat, bool &bucketCreated);
- void RenderBuckets(const MT_Transform& cameratransform,
- RAS_IRasterizer* rasty);
-
- /**
- * Update all transforms according to the scenegraph.
- */
- static bool KX_ScenegraphUpdateFunc(SG_IObject* node,void* gameobj,void* scene);
- static bool KX_ScenegraphRescheduleFunc(SG_IObject* node,void* gameobj,void* scene);
- void UpdateParents(double curtime);
- void DupliGroupRecurse(CValue* gameobj, int level);
- bool IsObjectInGroup(CValue* gameobj)
- {
- return (m_groupGameObjects.empty() ||
- m_groupGameObjects.find(gameobj) != m_groupGameObjects.end());
- }
- void AddObjectDebugProperties(class KX_GameObject* gameobj);
- SCA_IObject* AddReplicaObject(CValue* gameobj,
- CValue* locationobj,
- int lifespan=0);
- KX_GameObject* AddNodeReplicaObject(SG_IObject* node,
- CValue* gameobj);
- void RemoveNodeDestructObject(SG_IObject* node,
- CValue* gameobj);
- void RemoveObject(CValue* gameobj);
- void RemoveDupliGroup(CValue *gameobj);
- void DelayedRemoveObject(CValue* gameobj);
-
- int NewRemoveObject(CValue* gameobj);
- void ReplaceMesh(CValue* gameobj,
- void* meshob, bool use_gfx, bool use_phys);
-
- void AddAnimatedObject(CValue* gameobj);
-
- /**
- * \section Logic stuff
- * Initiate an update of the logic system.
- */
- void LogicBeginFrame(double curtime);
- void LogicUpdateFrame(double curtime, bool frame);
- void UpdateAnimations(double curtime);
-
- void
- LogicEndFrame(
- );
-
- CListValue*
- GetTempObjectList(
- );
-
- CListValue*
- GetObjectList(
- );
-
- CListValue*
- GetInactiveList(
- );
-
- CListValue*
- GetRootParentList(
- );
-
- CListValue*
- GetLightList(
- );
-
- SCA_LogicManager *
- GetLogicManager(
- );
-
- SCA_TimeEventManager *
- GetTimeEventManager(
- );
-
- /** Font Routines */
-
- /** Find a font in the scene by pointer. */
- KX_FontObject*
- FindFont(
- KX_FontObject*
- );
-
- /** Add a camera to this scene. */
- void
- AddFont(
- KX_FontObject*
- );
-
- /** Render the fonts in this scene. */
- void
- RenderFonts(
- );
-
- /** Camera Routines */
-
- std::list<class KX_Camera*>*
- GetCameras(
- );
-
-
- /** Find a camera in the scene by pointer. */
- KX_Camera*
- FindCamera(
- KX_Camera*
- );
-
- /** Find a scene in the scene by name. */
- KX_Camera*
- FindCamera(
- STR_String&
- );
-
- /** Add a camera to this scene. */
- void
- AddCamera(
- KX_Camera*
- );
-
- /** Find the currently active camera. */
- KX_Camera*
- GetActiveCamera(
- );
-
- /**
- * Set this camera to be the active camera in the scene. If the
- * camera is not present in the camera list, it will be added
- */
-
- void
- SetActiveCamera(
- class KX_Camera*
- );
-
- /**
- * Move this camera to the end of the list so that it is rendered last.
- * If the camera is not on the list, it will be added
- */
- void
- SetCameraOnTop(
- class KX_Camera*
- );
-
- /**
- * Activates new desired canvas width set at design time.
- * \param width The new desired width.
- */
- void
- SetCanvasDesignWidth(
- unsigned int width
- );
- /**
- * Activates new desired canvas height set at design time.
- * \param width The new desired height.
- */
- void
- SetCanvasDesignHeight(
- unsigned int height
- );
- /**
- * Returns the current desired canvas width set at design time.
- * \return The desired width.
- */
- unsigned int
- GetCanvasDesignWidth(
- void
- ) const;
-
- /**
- * Returns the current desired canvas height set at design time.
- * \return The desired height.
- */
- unsigned int
- GetCanvasDesignHeight(
- void
- ) const;
-
- /**
- * Set the framing options for this scene
- */
-
- void
- SetFramingType(
- RAS_FrameSettings & frame_settings
- );
-
- /**
- * Return a const reference to the framing
- * type set by the above call.
- * The contents are not guaranteed to be sensible
- * if you don't call the above function.
- */
-
- const
- RAS_FrameSettings &
- GetFramingType(
- ) const;
-
- /**
- * Store the current scene's viewport on the
- * game engine canvas.
- */
- void SetSceneViewport(const RAS_Rect &viewport);
-
- /**
- * Get the current scene's viewport on the
- * game engine canvas. This maintained
- * externally in KX_GameEngine
- */
- const RAS_Rect& GetSceneViewport() const;
-
- /**
- * \section Accessors to different scenes of this scene
- */
- void SetNetworkDeviceInterface(NG_NetworkDeviceInterface* newInterface);
- void SetNetworkScene(NG_NetworkScene *newScene);
- void SetWorldInfo(class KX_WorldInfo* wi);
- KX_WorldInfo* GetWorldInfo();
- void CalculateVisibleMeshes(RAS_IRasterizer* rasty, KX_Camera *cam, int layer=0);
- KX_Camera* GetpCamera();
- NG_NetworkDeviceInterface* GetNetworkDeviceInterface();
- NG_NetworkScene* GetNetworkScene();
- KX_BlenderSceneConverter *GetSceneConverter() { return m_sceneConverter; }
-
- /**
- * Replicate the logic bricks associated to this object.
- */
-
- void ReplicateLogic(class KX_GameObject* newobj);
- static SG_Callbacks m_callbacks;
-
- const STR_String& GetName();
-
- // Suspend the entire scene.
- void Suspend();
-
- // Resume a suspended scene.
- void Resume();
-
- // Update the mesh for objects based on level of detail settings
- void UpdateObjectLods(void);
-
- // LoD Hysteresis functions
- void SetLodHysteresis(bool active);
- bool IsActivedLodHysteresis();
- void SetLodHysteresisValue(int hysteresisvalue);
- int GetLodHysteresisValue();
-
- // Update the activity box settings for objects in this scene, if needed.
- void UpdateObjectActivity(void);
-
- // Enable/disable activity culling.
- void SetActivityCulling(bool b);
-
- // Set the radius of the activity culling box.
- void SetActivityCullingRadius(float f);
- bool IsSuspended();
- bool IsClearingZBuffer();
- void EnableZBufferClearing(bool isclearingZbuffer);
- bool IsShadowDone() { return m_isShadowDone; }
- void SetShadowDone(bool b) { m_isShadowDone = b; }
- // use of DBVT tree for camera culling
- void SetDbvtCulling(bool b) { m_dbvt_culling = b; }
- bool GetDbvtCulling() { return m_dbvt_culling; }
- void SetDbvtOcclusionRes(int i) { m_dbvt_occlusion_res = i; }
- int GetDbvtOcclusionRes() { return m_dbvt_occlusion_res; }
-
- void SetSceneConverter(class KX_BlenderSceneConverter* sceneConverter);
-
- class PHY_IPhysicsEnvironment* GetPhysicsEnvironment()
- {
- return m_physicsEnvironment;
- }
-
- void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* physEnv);
-
- void SetGravity(const MT_Vector3& gravity);
- MT_Vector3 GetGravity();
-
- short GetAnimationFPS();
-
- /**
- * Sets the node tree for this scene.
- */
- void SetNodeTree(SG_Tree* root);
-
- /**
- * 2D Filters
- */
- void Update2DFilter(std::vector<STR_String>& propNames, void* gameObj, RAS_2DFilterManager::RAS_2DFILTER_MODE filtermode, int pass, STR_String& text);
- void Render2DFilters(RAS_ICanvas* canvas);
-
- KX_ObstacleSimulation* GetObstacleSimulation() { return m_obstacleSimulation; }
-
-#ifdef WITH_PYTHON
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- KX_PYMETHOD_DOC(KX_Scene, addObject);
- KX_PYMETHOD_DOC(KX_Scene, end);
- KX_PYMETHOD_DOC(KX_Scene, restart);
- KX_PYMETHOD_DOC(KX_Scene, replace);
- KX_PYMETHOD_DOC(KX_Scene, suspend);
- KX_PYMETHOD_DOC(KX_Scene, resume);
- KX_PYMETHOD_DOC(KX_Scene, get);
- KX_PYMETHOD_DOC(KX_Scene, drawObstacleSimulation);
-
-
- /* attributes */
- static PyObject* pyattr_get_name(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_objects(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_objects_inactive(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_lights(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_cameras(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_world(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_active_camera(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_active_camera(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_drawing_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_drawing_callback_pre(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_drawing_callback_post(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_drawing_callback_post(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_drawing_setup_callback_pre(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_drawing_setup_callback_pre(void *selv_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject* pyattr_get_gravity(void* self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_gravity(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- virtual PyObject *py_repr(void) { return PyUnicode_From_STR_String(GetName()); }
-
- /* getitem/setitem */
- static PyMappingMethods Mapping;
- static PySequenceMethods Sequence;
-
- /**
- * Run the registered python drawing functions.
- */
- void RunDrawingCallbacks(PyObject *cb_list);
-
- PyObject *GetPreDrawCB() { return m_draw_call_pre; }
- PyObject *GetPostDrawCB() { return m_draw_call_post; }
- PyObject *GetPreDrawSetupCB() { return m_draw_setup_call_pre; }
-#endif
-
- /**
- * Sets the time the scene was suspended
- */
- void setSuspendedTime(double suspendedtime);
- /**
- * Returns the "curtime" the scene was suspended
- */
- double getSuspendedTime();
- /**
- * Sets the difference between the local time of the scene (when it
- * was running and not suspended) and the "curtime"
- */
- void setSuspendedDelta(double suspendeddelta);
- /**
- * Returns the difference between the local time of the scene (when it
- * was running and not suspended) and the "curtime"
- */
- double getSuspendedDelta();
- /**
- * Returns the Blender scene this was made from
- */
- struct Scene *GetBlenderScene() { return m_blenderScene; }
-
- bool MergeScene(KX_Scene *other);
-
-
- //void PrintStats(int verbose_level) {
- // m_bucketmanager->PrintStats(verbose_level)
- //}
-};
-
-typedef std::vector<KX_Scene*> KX_SceneList;
-
-#endif /* __KX_SCENE_H__ */
diff --git a/source/gameengine/Ketsji/KX_SceneActuator.cpp b/source/gameengine/Ketsji/KX_SceneActuator.cpp
deleted file mode 100644
index 6fe33fd2f63..00000000000
--- a/source/gameengine/Ketsji/KX_SceneActuator.cpp
+++ /dev/null
@@ -1,292 +0,0 @@
-/*
- * Set scene/camera stuff
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_SceneActuator.cpp
- * \ingroup ketsji
- */
-
-
-#include "SCA_IActuator.h"
-#include "KX_SceneActuator.h"
-#include <iostream>
-#include "KX_Scene.h"
-#include "KX_Camera.h"
-#include "KX_KetsjiEngine.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_SceneActuator::KX_SceneActuator(SCA_IObject *gameobj,
- int mode,
- KX_Scene *scene,
- KX_KetsjiEngine* ketsjiEngine,
- const STR_String& nextSceneName,
- KX_Camera* camera)
- : SCA_IActuator(gameobj, KX_ACT_SCENE)
-{
- m_mode = mode;
- m_scene = scene;
- m_KetsjiEngine=ketsjiEngine;
- m_camera = camera;
- m_nextSceneName = nextSceneName;
- if (m_camera)
- m_camera->RegisterActuator(this);
-} /* End of constructor */
-
-
-
-KX_SceneActuator::~KX_SceneActuator()
-{
- if (m_camera)
- m_camera->UnregisterActuator(this);
-} /* end of destructor */
-
-
-
-CValue* KX_SceneActuator::GetReplica()
-{
- KX_SceneActuator* replica = new KX_SceneActuator(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_SceneActuator::ProcessReplica()
-{
- if (m_camera)
- m_camera->RegisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-bool KX_SceneActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == (SCA_IObject*)m_camera)
- {
- // this object is being deleted, we cannot continue to track it.
- m_camera = NULL;
- return true;
- }
- return false;
-}
-
-void KX_SceneActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_camera];
- if (h_obj) {
- if (m_camera)
- m_camera->UnregisterActuator(this);
- m_camera = (KX_Camera*)(*h_obj);
- m_camera->RegisterActuator(this);
- }
-}
-
-
-bool KX_SceneActuator::Update()
-{
- // bool result = false; /*unused*/
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent)
- return false; // do nothing on negative events
-
- switch (m_mode)
- {
- case KX_SCENE_RESTART:
- {
- m_KetsjiEngine->ReplaceScene(m_scene->GetName(),m_scene->GetName());
- break;
- }
- case KX_SCENE_SET_CAMERA:
- if (m_camera)
- {
- m_scene->SetActiveCamera(m_camera);
- }
- else
- {
- // if no camera is set and the parent object is a camera, use it as the camera
- SCA_IObject* parent = GetParent();
- if (parent->GetGameObjectType()==SCA_IObject::OBJ_CAMERA)
- {
- m_scene->SetActiveCamera((KX_Camera*)parent);
- }
- }
- break;
- default:
- break;
- }
-
- if (!m_nextSceneName.Length())
- return false;
-
- switch (m_mode)
- {
- case KX_SCENE_SET_SCENE:
- {
- m_KetsjiEngine->ReplaceScene(m_scene->GetName(),m_nextSceneName);
- break;
- }
- case KX_SCENE_ADD_FRONT_SCENE:
- {
- bool overlay=true;
- m_KetsjiEngine->ConvertAndAddScene(m_nextSceneName,overlay);
- break;
- }
- case KX_SCENE_ADD_BACK_SCENE:
- {
- bool overlay=false;
- m_KetsjiEngine->ConvertAndAddScene(m_nextSceneName,overlay);
- break;
- }
- case KX_SCENE_REMOVE_SCENE:
- {
- m_KetsjiEngine->RemoveScene(m_nextSceneName);
- break;
- }
- case KX_SCENE_SUSPEND:
- {
- m_KetsjiEngine->SuspendScene(m_nextSceneName);
- break;
- }
- case KX_SCENE_RESUME:
- {
- m_KetsjiEngine->ResumeScene(m_nextSceneName);
- break;
- }
- default:
- ; /* do nothing? this is an internal error !!! */
- }
-
- return false;
-}
-
-
-
-/* returns a camera if the name is valid */
-KX_Camera* KX_SceneActuator::FindCamera(const char *camName)
-{
- KX_SceneList* sl = m_KetsjiEngine->CurrentScenes();
- STR_String name = STR_String(camName);
- KX_SceneList::iterator it = sl->begin();
- KX_Camera* cam = NULL;
-
- while ((it != sl->end()) && (!cam))
- {
- cam = (*it)->FindCamera(name);
- it++;
- }
-
- return cam;
-}
-
-
-
-KX_Scene* KX_SceneActuator::FindScene(const char *sceneName)
-{
- return m_KetsjiEngine->FindScene(sceneName);
-}
-
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_SceneActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_SceneActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_SceneActuator::Methods[] =
-{
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_SceneActuator::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("scene",0,MAX_ID_NAME-2,true,KX_SceneActuator,m_nextSceneName),
- KX_PYATTRIBUTE_RW_FUNCTION("camera",KX_SceneActuator,pyattr_get_camera,pyattr_set_camera),
- KX_PYATTRIBUTE_BOOL_RW("useRestart", KX_SceneActuator, m_restart),
- KX_PYATTRIBUTE_INT_RW("mode", KX_SCENE_NODEF+1, KX_SCENE_MAX-1, true, KX_SceneActuator, m_mode),
- { NULL } //Sentinel
-};
-
-PyObject *KX_SceneActuator::pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
- if (!actuator->m_camera)
- Py_RETURN_NONE;
-
- return actuator->m_camera->GetProxy();
-}
-
-int KX_SceneActuator::pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_SceneActuator* actuator = static_cast<KX_SceneActuator*>(self);
- KX_Camera *camOb;
-
- if (!ConvertPythonToCamera(value, &camOb, true, "actu.camera = value: KX_SceneActuator"))
- return PY_SET_ATTR_FAIL;
-
- if (actuator->m_camera)
- actuator->m_camera->UnregisterActuator(actuator);
-
- if (camOb==NULL) {
- actuator->m_camera= NULL;
- }
- else {
- actuator->m_camera = camOb;
- actuator->m_camera->RegisterActuator(actuator);
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_SceneActuator.h b/source/gameengine/Ketsji/KX_SceneActuator.h
deleted file mode 100644
index 389e9208ef3..00000000000
--- a/source/gameengine/Ketsji/KX_SceneActuator.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SceneActuator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_SCENEACTUATOR_H__
-#define __KX_SCENEACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "SCA_IScene.h" /* Replace_IScene only */
-#include "KX_Scene.h" /* Replace_IScene only */
-
-class KX_SceneActuator : public SCA_IActuator
-{
- Py_Header
-
- int m_mode;
- // (restart) has become a toggle internally... not in the interface though
- bool m_restart;
- // (set Scene) Scene
- /** The current scene. */
- class KX_Scene* m_scene;
- class KX_KetsjiEngine* m_KetsjiEngine;
- /** The scene to switch to. */
- STR_String m_nextSceneName;
-
- // (Set Camera) Object
- class KX_Camera* m_camera;
-
- /** Is this a valid scene? */
- class KX_Scene* FindScene(const char* sceneName);
- /** Is this a valid camera? */
- class KX_Camera* FindCamera(const char* cameraName);
-
- public:
- enum SCA_SceneActuatorMode
- {
- KX_SCENE_NODEF = 0,
- KX_SCENE_RESTART,
- KX_SCENE_SET_SCENE,
- KX_SCENE_SET_CAMERA,
- KX_SCENE_ADD_FRONT_SCENE,
- KX_SCENE_ADD_BACK_SCENE,
- KX_SCENE_REMOVE_SCENE,
- KX_SCENE_SUSPEND,
- KX_SCENE_RESUME,
- KX_SCENE_MAX
- };
-
- KX_SceneActuator(SCA_IObject* gameobj,
- int mode,
- KX_Scene* scene,
- KX_KetsjiEngine* ketsjiEngine,
- const STR_String& nextSceneName,
- KX_Camera* camera);
- virtual ~KX_SceneActuator();
-
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
- virtual bool UnlinkObject(SCA_IObject* clientobj);
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
-
- virtual bool Update();
-
-#ifdef WITH_PYTHON
-
- virtual void Replace_IScene(SCA_IScene *val)
- {
- m_scene= static_cast<KX_Scene *>(val);
- };
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- static PyObject *pyattr_get_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_camera(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
-#endif /* WITH_PYTHON */
-
-}; /* end of class KXSceneActuator */
-
-#endif
diff --git a/source/gameengine/Ketsji/KX_SoundActuator.cpp b/source/gameengine/Ketsji/KX_SoundActuator.cpp
deleted file mode 100644
index 64aab31ba22..00000000000
--- a/source/gameengine/Ketsji/KX_SoundActuator.cpp
+++ /dev/null
@@ -1,573 +0,0 @@
-/*
- * KX_SoundActuator.cpp
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- *
- */
-
-/** \file gameengine/Ketsji/KX_SoundActuator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_SoundActuator.h"
-
-#ifdef WITH_AUDASPACE
-# ifdef WITH_SYSTEM_AUDASPACE
-typedef float sample_t;
-# include AUD_PYTHON_H
-# endif
-# include AUD_SOUND_H
-# include AUD_SPECIAL_H
-# include AUD_DEVICE_H
-# include AUD_HANDLE_H
-#endif
-
-#include "KX_GameObject.h"
-#include "KX_PyMath.h" // needed for PyObjectFrom()
-#include "KX_PythonInit.h"
-#include "KX_Camera.h"
-#include <iostream>
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-KX_SoundActuator::KX_SoundActuator(SCA_IObject* gameobj,
- AUD_Sound* sound,
- float volume,
- float pitch,
- bool is3d,
- KX_3DSoundSettings settings,
- KX_SOUNDACT_TYPE type)//,
- : SCA_IActuator(gameobj, KX_ACT_SOUND)
-{
- m_sound = sound ? AUD_Sound_copy(sound) : NULL;
- m_handle = NULL;
- m_volume = volume;
- m_pitch = pitch;
- m_is3d = is3d;
- m_3d = settings;
- m_type = type;
- m_isplaying = false;
-}
-
-
-
-KX_SoundActuator::~KX_SoundActuator()
-{
- if (m_handle) {
- AUD_Handle_stop(m_handle);
- }
-
- if (m_sound) {
- AUD_Sound_free(m_sound);
- }
-}
-
-void KX_SoundActuator::play()
-{
- if (m_handle) {
- AUD_Handle_stop(m_handle);
- m_handle = NULL;
- }
-
- if (!m_sound)
- return;
-
- // this is the sound that will be played and not deleted afterwards
- AUD_Sound* sound = m_sound;
-
- bool loop = false;
-
- switch (m_type)
- {
- case KX_SOUNDACT_LOOPBIDIRECTIONAL:
- case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
- sound = AUD_Sound_pingpong(sound);
- ATTR_FALLTHROUGH;
- case KX_SOUNDACT_LOOPEND:
- case KX_SOUNDACT_LOOPSTOP:
- loop = true;
- break;
- case KX_SOUNDACT_PLAYSTOP:
- case KX_SOUNDACT_PLAYEND:
- default:
- break;
- }
-
- AUD_Device* device = AUD_Device_getCurrent();
- m_handle = AUD_Device_play(device, sound, false);
- AUD_Device_free(device);
-
- // in case of pingpong, we have to free the sound
- if (sound != m_sound)
- AUD_Sound_free(sound);
-
- if (m_handle != NULL) {
- if (m_is3d) {
- AUD_Handle_setRelative(m_handle, true);
- AUD_Handle_setVolumeMaximum(m_handle, m_3d.max_gain);
- AUD_Handle_setVolumeMinimum(m_handle, m_3d.min_gain);
- AUD_Handle_setDistanceReference(m_handle, m_3d.reference_distance);
- AUD_Handle_setDistanceMaximum(m_handle, m_3d.max_distance);
- AUD_Handle_setAttenuation(m_handle, m_3d.rolloff_factor);
- AUD_Handle_setConeAngleInner(m_handle, m_3d.cone_inner_angle);
- AUD_Handle_setConeAngleOuter(m_handle, m_3d.cone_outer_angle);
- AUD_Handle_setConeVolumeOuter(m_handle, m_3d.cone_outer_gain);
- }
-
- if (loop)
- AUD_Handle_setLoopCount(m_handle, -1);
- AUD_Handle_setPitch(m_handle, m_pitch);
- AUD_Handle_setVolume(m_handle, m_volume);
- }
-
- m_isplaying = true;
-}
-
-CValue* KX_SoundActuator::GetReplica()
-{
- KX_SoundActuator* replica = new KX_SoundActuator(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_SoundActuator::ProcessReplica()
-{
- SCA_IActuator::ProcessReplica();
- m_handle = NULL;
- m_sound = AUD_Sound_copy(m_sound);
-}
-
-bool KX_SoundActuator::Update(double curtime, bool frame)
-{
- if (!frame)
- return true;
- bool result = false;
-
- // do nothing on negative events, otherwise sounds are played twice!
- bool bNegativeEvent = IsNegativeEvent();
- bool bPositiveEvent = m_posevent;
-
- RemoveAllEvents();
-
- if (!m_sound)
- return false;
-
- // actual audio device playing state
- bool isplaying = m_handle ? (AUD_Handle_getStatus(m_handle) == AUD_STATUS_PLAYING) : false;
-
- if (bNegativeEvent)
- {
- // here must be a check if it is still playing
- if (m_isplaying && isplaying)
- {
- switch (m_type)
- {
- case KX_SOUNDACT_PLAYSTOP:
- case KX_SOUNDACT_LOOPSTOP:
- case KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP:
- {
- // stop immediately
- if (m_handle)
- {
- AUD_Handle_stop(m_handle);
- m_handle = NULL;
- }
- break;
- }
- case KX_SOUNDACT_PLAYEND:
- {
- // do nothing, sound will stop anyway when it's finished
- break;
- }
- case KX_SOUNDACT_LOOPEND:
- case KX_SOUNDACT_LOOPBIDIRECTIONAL:
- {
- // stop the looping so that the sound stops when it finished
- if (m_handle)
- AUD_Handle_setLoopCount(m_handle, 0);
- break;
- }
- default:
- // implement me !!
- break;
- }
- }
- // remember that we tried to stop the actuator
- m_isplaying = false;
- }
-
-#if 1
- // Warning: when de-activating the actuator, after a single negative event this runs again with...
- // m_posevent==false && m_posevent==false, in this case IsNegativeEvent() returns false
- // and assumes this is a positive event.
- // check that we actually have a positive event so as not to play sounds when being disabled.
- else if (bPositiveEvent) /* <- added since 2.49 */
-#else
- else // <- works in most cases except a loop-end sound will never stop unless
- // the negative pulse is done continuesly
-#endif
- {
- if (!m_isplaying)
- play();
- }
- // verify that the sound is still playing
- isplaying = m_handle ? (AUD_Handle_getStatus(m_handle) == AUD_STATUS_PLAYING) : false;
-
- if (isplaying)
- {
- if (m_is3d)
- {
- KX_Camera* cam = KX_GetActiveScene()->GetActiveCamera();
- if (cam)
- {
- KX_GameObject* obj = (KX_GameObject*)this->GetParent();
- MT_Point3 p;
- MT_Matrix3x3 Mo;
- float data[4];
-
- Mo = cam->NodeGetWorldOrientation().inverse();
- p = (obj->NodeGetWorldPosition() - cam->NodeGetWorldPosition());
- p = Mo * p;
- p.getValue(data);
- AUD_Handle_setLocation(m_handle, data);
- p = (obj->GetLinearVelocity() - cam->GetLinearVelocity());
- p = Mo * p;
- p.getValue(data);
- AUD_Handle_setVelocity(m_handle, data);
- (Mo * obj->NodeGetWorldOrientation()).getRotation().getValue(data);
- AUD_Handle_setOrientation(m_handle, data);
- }
- }
- result = true;
- }
- else
- {
- m_isplaying = false;
- result = false;
- }
- return result;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_SoundActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_SoundActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_SoundActuator::Methods[] = {
- KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, startSound),
- KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, pauseSound),
- KX_PYMETHODTABLE_NOARGS(KX_SoundActuator, stopSound),
- {NULL, NULL} //Sentinel
-};
-
-PyAttributeDef KX_SoundActuator::Attributes[] = {
- KX_PYATTRIBUTE_BOOL_RO("is3D", KX_SoundActuator, m_is3d),
- KX_PYATTRIBUTE_RW_FUNCTION("volume_maximum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("volume_minimum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("distance_reference", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("distance_maximum", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("attenuation", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_inner", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("cone_angle_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("cone_volume_outer", KX_SoundActuator, pyattr_get_3d_property, pyattr_set_3d_property),
- KX_PYATTRIBUTE_RW_FUNCTION("sound", KX_SoundActuator, pyattr_get_sound, pyattr_set_sound),
-
- KX_PYATTRIBUTE_RW_FUNCTION("time", KX_SoundActuator, pyattr_get_audposition, pyattr_set_audposition),
- KX_PYATTRIBUTE_RW_FUNCTION("volume", KX_SoundActuator, pyattr_get_gain, pyattr_set_gain),
- KX_PYATTRIBUTE_RW_FUNCTION("pitch", KX_SoundActuator, pyattr_get_pitch, pyattr_set_pitch),
- KX_PYATTRIBUTE_ENUM_RW("mode",KX_SoundActuator::KX_SOUNDACT_NODEF+1,KX_SoundActuator::KX_SOUNDACT_MAX-1,false,KX_SoundActuator,m_type),
- { NULL } //Sentinel
-};
-
-/* Methods ----------------------------------------------------------------- */
-KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, startSound,
-"startSound()\n"
-"\tStarts the sound.\n")
-{
- switch (m_handle ? AUD_Handle_getStatus(m_handle) : AUD_STATUS_INVALID) {
- case AUD_STATUS_PLAYING:
- break;
- case AUD_STATUS_PAUSED:
- AUD_Handle_resume(m_handle);
- break;
- default:
- play();
- }
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, pauseSound,
-"pauseSound()\n"
-"\tPauses the sound.\n")
-{
- if (m_handle)
- AUD_Handle_pause(m_handle);
- Py_RETURN_NONE;
-}
-
-KX_PYMETHODDEF_DOC_NOARGS(KX_SoundActuator, stopSound,
-"stopSound()\n"
-"\tStops the sound.\n")
-{
- if (m_handle)
- {
- AUD_Handle_stop(m_handle);
- m_handle = NULL;
- }
- Py_RETURN_NONE;
-}
-
-/* Atribute setting and getting -------------------------------------------- */
-PyObject *KX_SoundActuator::pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- const char* prop = attrdef->m_name;
- float result_value = 0.0f;
-
- if (!strcmp(prop, "volume_maximum")) {
- result_value = actuator->m_3d.max_gain;
-
- } else if (!strcmp(prop, "volume_minimum")) {
- result_value = actuator->m_3d.min_gain;
-
- } else if (!strcmp(prop, "distance_reference")) {
- result_value = actuator->m_3d.reference_distance;
-
- } else if (!strcmp(prop, "distance_maximum")) {
- result_value = actuator->m_3d.max_distance;
-
- } else if (!strcmp(prop, "attenuation")) {
- result_value = actuator->m_3d.rolloff_factor;
-
- } else if (!strcmp(prop, "cone_angle_inner")) {
- result_value = actuator->m_3d.cone_inner_angle;
-
- } else if (!strcmp(prop, "cone_angle_outer")) {
- result_value = actuator->m_3d.cone_outer_angle;
-
- } else if (!strcmp(prop, "cone_volume_outer")) {
- result_value = actuator->m_3d.cone_outer_gain;
-
- } else {
- Py_RETURN_NONE;
- }
-
- PyObject *result = PyFloat_FromDouble(result_value);
- return result;
-}
-
-PyObject *KX_SoundActuator::pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- float position = 0.0f;
-
- if (actuator->m_handle)
- position = AUD_Handle_getPosition(actuator->m_handle);
-
- PyObject *result = PyFloat_FromDouble(position);
-
- return result;
-}
-
-PyObject *KX_SoundActuator::pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- float gain = actuator->m_volume;
-
- PyObject *result = PyFloat_FromDouble(gain);
-
- return result;
-}
-
-PyObject *KX_SoundActuator::pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- float pitch = actuator->m_pitch;
-
- PyObject *result = PyFloat_FromDouble(pitch);
-
- return result;
-}
-
-PyObject *KX_SoundActuator::pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- if (actuator->m_sound)
- return (PyObject *)AUD_getPythonSound(actuator->m_sound);
- else
- Py_RETURN_NONE;
-}
-
-int KX_SoundActuator::pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- const char* prop = attrdef->m_name;
- float prop_value = 0.0f;
-
- if (!PyArg_Parse(value, "f", &prop_value))
- return PY_SET_ATTR_FAIL;
-
- // if sound is working and 3D, set the new setting
- if (!actuator->m_is3d)
- return PY_SET_ATTR_FAIL;
-
- if (!strcmp(prop, "volume_maximum")) {
- actuator->m_3d.max_gain = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setVolumeMaximum(actuator->m_handle, prop_value);
-
- } else if (!strcmp(prop, "volume_minimum")) {
- actuator->m_3d.min_gain = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setVolumeMinimum(actuator->m_handle, prop_value);
-
- } else if (!strcmp(prop, "distance_reference")) {
- actuator->m_3d.reference_distance = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setDistanceReference(actuator->m_handle, prop_value);
-
- } else if (!strcmp(prop, "distance_maximum")) {
- actuator->m_3d.max_distance = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setDistanceMaximum(actuator->m_handle, prop_value);
-
- } else if (!strcmp(prop, "attenuation")) {
- actuator->m_3d.rolloff_factor = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setAttenuation(actuator->m_handle, prop_value);
-
- } else if (!strcmp(prop, "cone_angle_inner")) {
- actuator->m_3d.cone_inner_angle = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setConeAngleInner(actuator->m_handle, prop_value);
-
- } else if (!strcmp(prop, "cone_angle_outer")) {
- actuator->m_3d.cone_outer_angle = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setConeAngleOuter(actuator->m_handle, prop_value);
-
- } else if (!strcmp(prop, "cone_volume_outer")) {
- actuator->m_3d.cone_outer_gain = prop_value;
- if (actuator->m_handle)
- AUD_Handle_setConeVolumeOuter(actuator->m_handle, prop_value);
-
- } else {
- return PY_SET_ATTR_FAIL;
- }
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-int KX_SoundActuator::pyattr_set_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
-
- float position = 1.0f;
- if (!PyArg_Parse(value, "f", &position))
- return PY_SET_ATTR_FAIL;
-
- if (actuator->m_handle)
- AUD_Handle_setPosition(actuator->m_handle, position);
- return PY_SET_ATTR_SUCCESS;
-}
-
-int KX_SoundActuator::pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- float gain = 1.0f;
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- if (!PyArg_Parse(value, "f", &gain))
- return PY_SET_ATTR_FAIL;
-
- actuator->m_volume = gain;
- if (actuator->m_handle)
- AUD_Handle_setVolume(actuator->m_handle, gain);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-int KX_SoundActuator::pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- float pitch = 1.0f;
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- if (!PyArg_Parse(value, "f", &pitch))
- return PY_SET_ATTR_FAIL;
-
- actuator->m_pitch = pitch;
- if (actuator->m_handle)
- AUD_Handle_setPitch(actuator->m_handle, pitch);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-int KX_SoundActuator::pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- PyObject *sound = NULL;
- KX_SoundActuator * actuator = static_cast<KX_SoundActuator *> (self);
- if (!PyArg_Parse(value, "O", &sound))
- return PY_SET_ATTR_FAIL;
-
- AUD_Sound *snd = AUD_getSoundFromPython(sound);
-
- if (snd)
- {
- AUD_Sound_free(actuator->m_sound);
- actuator->m_sound = snd;
- return PY_SET_ATTR_SUCCESS;
- }
-
- return PY_SET_ATTR_FAIL;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_SoundActuator.h b/source/gameengine/Ketsji/KX_SoundActuator.h
deleted file mode 100644
index 5ec2fda722f..00000000000
--- a/source/gameengine/Ketsji/KX_SoundActuator.h
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_SoundActuator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_SOUNDACTUATOR_H__
-#define __KX_SOUNDACTUATOR_H__
-
-#include "SCA_IActuator.h"
-
-#ifdef WITH_AUDASPACE
-# include AUD_SOUND_H
-# include AUD_HANDLE_H
-#endif
-
-#include "BKE_sound.h"
-
-typedef struct KX_3DSoundSettings {
- float min_gain;
- float max_gain;
- float reference_distance;
- float max_distance;
- float rolloff_factor;
- float cone_inner_angle;
- float cone_outer_angle;
- float cone_outer_gain;
-} KX_3DSoundSettings;
-
-class KX_SoundActuator : public SCA_IActuator
-{
- Py_Header
- bool m_isplaying;
- AUD_Sound* m_sound;
- float m_volume;
- float m_pitch;
- bool m_is3d;
- KX_3DSoundSettings m_3d;
- AUD_Handle* m_handle;
-
- void play();
-
-public:
-
- enum KX_SOUNDACT_TYPE
- {
- KX_SOUNDACT_NODEF = 0,
- KX_SOUNDACT_PLAYSTOP,
- KX_SOUNDACT_PLAYEND,
- KX_SOUNDACT_LOOPSTOP,
- KX_SOUNDACT_LOOPEND,
- KX_SOUNDACT_LOOPBIDIRECTIONAL,
- KX_SOUNDACT_LOOPBIDIRECTIONAL_STOP,
- KX_SOUNDACT_MAX
- };
-
- KX_SOUNDACT_TYPE m_type;
-
- KX_SoundActuator(SCA_IObject* gameobj,
- AUD_Sound *sound,
- float volume,
- float pitch,
- bool is3d,
- KX_3DSoundSettings settings,
- KX_SOUNDACT_TYPE type);
-
- ~KX_SoundActuator();
-
- virtual bool Update(double curtime, bool frame);
-
- CValue* GetReplica();
- void ProcessReplica();
-
-#ifdef WITH_PYTHON
-
- /* -------------------------------------------------------------------- */
- /* Python interface --------------------------------------------------- */
- /* -------------------------------------------------------------------- */
-
- KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, startSound);
- KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, pauseSound);
- KX_PYMETHOD_DOC_NOARGS(KX_SoundActuator, stopSound);
-
- static int pyattr_set_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- static PyObject *pyattr_get_3d_property(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_audposition(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_gain(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_pitch(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_type(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_sound(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-
-#endif /* WITH_PYTHON */
-
-};
-
-#endif /* __KX_SOUNDACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_StateActuator.cpp b/source/gameengine/Ketsji/KX_StateActuator.cpp
deleted file mode 100644
index d918f87c4bf..00000000000
--- a/source/gameengine/Ketsji/KX_StateActuator.cpp
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Actuator to toggle visibility/invisibility of objects
- */
-
-/** \file gameengine/Ketsji/KX_StateActuator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_StateActuator.h"
-#include "KX_GameObject.h"
-
-KX_StateActuator::KX_StateActuator(
- SCA_IObject* gameobj,
- int operation,
- unsigned int mask
- )
- : SCA_IActuator(gameobj, KX_ACT_STATE),
- m_operation(operation),
- m_mask(mask)
-{
- // intentionally empty
-}
-
-KX_StateActuator::~KX_StateActuator(
- void
- )
-{
- // intentionally empty
-}
-
-// used to put state actuator to be executed before any other actuators
-SG_QList KX_StateActuator::m_stateActuatorHead;
-
-CValue*
-KX_StateActuator::GetReplica(
- void
- )
-{
- KX_StateActuator* replica = new KX_StateActuator(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-bool
-KX_StateActuator::Update()
-{
- bool bNegativeEvent = IsNegativeEvent();
- unsigned int objMask;
-
- // execution of state actuator means that we are in the execution phase, reset this pointer
- // because all the active actuator of this object will be removed for sure.
- m_gameobj->m_firstState = NULL;
- RemoveAllEvents();
- if (bNegativeEvent) return false;
-
- KX_GameObject *obj = (KX_GameObject*) GetParent();
-
- objMask = obj->GetState();
- switch (m_operation)
- {
- case OP_CPY:
- objMask = m_mask;
- break;
- case OP_SET:
- objMask |= m_mask;
- break;
- case OP_CLR:
- objMask &= ~m_mask;
- break;
- case OP_NEG:
- objMask ^= m_mask;
- break;
- default:
- // unsupported operation, no nothing
- return false;
- }
- obj->SetState(objMask);
- return false;
-}
-
-// this function is only used to deactivate actuators outside the logic loop
-// e.g. when an object is deleted.
-void KX_StateActuator::Deactivate()
-{
- if (QDelink())
- {
- // the actuator was in the active list
- if (m_stateActuatorHead.QEmpty())
- // no more state object active
- m_stateActuatorHead.Delink();
- }
-}
-
-void KX_StateActuator::Activate(SG_DList& head)
-{
- // sort the state actuators per object on the global list
- if (QEmpty())
- {
- InsertSelfActiveQList(m_stateActuatorHead, &m_gameobj->m_firstState);
- // add front to make sure it runs before other actuators
- head.AddFront(&m_stateActuatorHead);
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_StateActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_StateActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_StateActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_StateActuator::Attributes[] = {
- KX_PYATTRIBUTE_INT_RW("operation",KX_StateActuator::OP_NOP+1,KX_StateActuator::OP_COUNT-1,false,KX_StateActuator,m_operation),
- KX_PYATTRIBUTE_INT_RW("mask",0,0x3FFFFFFF,false,KX_StateActuator,m_mask),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_StateActuator.h b/source/gameengine/Ketsji/KX_StateActuator.h
deleted file mode 100644
index 5ed065d3604..00000000000
--- a/source/gameengine/Ketsji/KX_StateActuator.h
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_StateActuator.h
- * \ingroup ketsji
- * \brief Actuator to toggle visibility/invisibility of objects
- */
-
-#ifndef __KX_STATEACTUATOR_H__
-#define __KX_STATEACTUATOR_H__
-
-#include "SCA_IActuator.h"
-
-
-/*
- * Use of SG_DList : element of actuator being deactivated
- * Head: SCA_LogicManager::m_removedActuators
- * Use of SG_QList : element of global activated state actuator list
- * Head: KX_StateActuator::m_stateActuatorHead
- */
-class KX_StateActuator : public SCA_IActuator
-{
- Py_Header
-
- /** Make visible? */
- enum {
- OP_NOP = -1,
- OP_CPY = 0,
- OP_SET,
- OP_CLR,
- OP_NEG,
- OP_COUNT
- };
- // SG_Dlist: element of objects with active actuators, always put in front of the list
- // Head: SCA_LogicManager::m_activeActuators
- // SG_QList: Head of active state actuators list globally
- // Elements: KX_StateActuator
- static SG_QList m_stateActuatorHead;
- int m_operation;
- int m_mask;
-
- public:
-
- KX_StateActuator(
- SCA_IObject* gameobj,
- int operation,
- unsigned int mask
- );
-
- virtual
- ~KX_StateActuator(
- void
- );
-
- virtual CValue*
- GetReplica(
- void
- );
-
- virtual bool
- Update();
-
- virtual void Deactivate();
- virtual void Activate(SG_DList& head);
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_SteeringActuator.cpp b/source/gameengine/Ketsji/KX_SteeringActuator.cpp
deleted file mode 100644
index d3a7b665e61..00000000000
--- a/source/gameengine/Ketsji/KX_SteeringActuator.cpp
+++ /dev/null
@@ -1,639 +0,0 @@
-/*
- * Add steering behaviors
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "BLI_math.h"
-#include "KX_SteeringActuator.h"
-#include "KX_GameObject.h"
-#include "KX_NavMeshObject.h"
-#include "KX_ObstacleSimulation.h"
-#include "KX_PythonInit.h"
-#include "KX_PyMath.h"
-#include "Recast.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_SteeringActuator::KX_SteeringActuator(SCA_IObject *gameobj,
- int mode,
- KX_GameObject *target,
- KX_GameObject *navmesh,
- float distance,
- float velocity,
- float acceleration,
- float turnspeed,
- bool isSelfTerminated,
- int pathUpdatePeriod,
- KX_ObstacleSimulation* simulation,
- short facingmode,
- bool normalup,
- bool enableVisualization,
- bool lockzvel)
- : SCA_IActuator(gameobj, KX_ACT_STEERING),
- m_target(target),
- m_mode(mode),
- m_distance(distance),
- m_velocity(velocity),
- m_acceleration(acceleration),
- m_turnspeed(turnspeed),
- m_simulation(simulation),
- m_updateTime(0),
- m_obstacle(NULL),
- m_isActive(false),
- m_isSelfTerminated(isSelfTerminated),
- m_enableVisualization(enableVisualization),
- m_facingMode(facingmode),
- m_normalUp(normalup),
- m_pathLen(0),
- m_pathUpdatePeriod(pathUpdatePeriod),
- m_lockzvel(lockzvel),
- m_wayPointIdx(-1),
- m_steerVec(MT_Vector3(0, 0, 0))
-{
- m_navmesh = static_cast<KX_NavMeshObject*>(navmesh);
- if (m_navmesh)
- m_navmesh->RegisterActuator(this);
- if (m_target)
- m_target->RegisterActuator(this);
-
- if (m_simulation)
- m_obstacle = m_simulation->GetObstacle((KX_GameObject*)gameobj);
- KX_GameObject* parent = ((KX_GameObject*)gameobj)->GetParent();
- if (m_facingMode>0 && parent)
- {
- m_parentlocalmat = parent->GetSGNode()->GetLocalOrientation();
- }
- else
- m_parentlocalmat.setIdentity();
-}
-
-KX_SteeringActuator::~KX_SteeringActuator()
-{
- if (m_navmesh)
- m_navmesh->UnregisterActuator(this);
- if (m_target)
- m_target->UnregisterActuator(this);
-}
-
-CValue* KX_SteeringActuator::GetReplica()
-{
- KX_SteeringActuator* replica = new KX_SteeringActuator(*this);
- // replication just copy the m_base pointer => common random generator
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_SteeringActuator::ProcessReplica()
-{
- if (m_target)
- m_target->RegisterActuator(this);
- if (m_navmesh)
- m_navmesh->RegisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-void KX_SteeringActuator::ReParent(SCA_IObject* parent)
-{
- SCA_IActuator::ReParent(parent);
- if (m_simulation)
- m_obstacle = m_simulation->GetObstacle((KX_GameObject*)m_gameobj);
-}
-
-bool KX_SteeringActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == m_target)
- {
- m_target = NULL;
- return true;
- }
- else if (clientobj == m_navmesh)
- {
- m_navmesh = NULL;
- return true;
- }
- return false;
-}
-
-void KX_SteeringActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_target];
- if (h_obj) {
- if (m_target)
- m_target->UnregisterActuator(this);
- m_target = (KX_GameObject*)(*h_obj);
- m_target->RegisterActuator(this);
- }
-
- h_obj = (*obj_map)[m_navmesh];
- if (h_obj) {
- if (m_navmesh)
- m_navmesh->UnregisterActuator(this);
- m_navmesh = (KX_NavMeshObject*)(*h_obj);
- m_navmesh->RegisterActuator(this);
- }
-}
-
-bool KX_SteeringActuator::Update(double curtime, bool frame)
-{
- if (frame)
- {
- double delta = curtime - m_updateTime;
- m_updateTime = curtime;
-
- if (m_posevent && !m_isActive)
- {
- delta = 0.0;
- m_pathUpdateTime = -1.0;
- m_updateTime = curtime;
- m_isActive = true;
- }
- bool bNegativeEvent = IsNegativeEvent();
- if (bNegativeEvent)
- m_isActive = false;
-
- RemoveAllEvents();
-
- if (!delta)
- return true;
-
- if (bNegativeEvent || !m_target)
- return false; // do nothing on negative events
-
- KX_GameObject *obj = (KX_GameObject*) GetParent();
- const MT_Point3& mypos = obj->NodeGetWorldPosition();
- const MT_Point3& targpos = m_target->NodeGetWorldPosition();
- MT_Vector3 vectotarg = targpos - mypos;
- MT_Vector3 vectotarg2d = vectotarg;
- vectotarg2d.z() = 0.0f;
- m_steerVec = MT_Vector3(0.0f, 0.0f, 0.0f);
- bool apply_steerforce = false;
- bool terminate = true;
-
- switch (m_mode) {
- case KX_STEERING_SEEK:
- if (vectotarg2d.length2()>m_distance*m_distance)
- {
- terminate = false;
- m_steerVec = vectotarg;
- m_steerVec.normalize();
- apply_steerforce = true;
- }
- break;
- case KX_STEERING_FLEE:
- if (vectotarg2d.length2()<m_distance*m_distance)
- {
- terminate = false;
- m_steerVec = -vectotarg;
- m_steerVec.normalize();
- apply_steerforce = true;
- }
- break;
- case KX_STEERING_PATHFOLLOWING:
- if (m_navmesh && vectotarg.length2()>m_distance*m_distance)
- {
- terminate = false;
-
- static const MT_Scalar WAYPOINT_RADIUS(0.25f);
-
- if (m_pathUpdateTime<0 || (m_pathUpdatePeriod>=0 &&
- curtime - m_pathUpdateTime>((double)m_pathUpdatePeriod/1000.0)))
- {
- m_pathUpdateTime = curtime;
- m_pathLen = m_navmesh->FindPath(mypos, targpos, m_path, MAX_PATH_LENGTH);
- m_wayPointIdx = m_pathLen > 1 ? 1 : -1;
- }
-
- if (m_wayPointIdx>0)
- {
- MT_Vector3 waypoint(&m_path[3*m_wayPointIdx]);
- if ((waypoint-mypos).length2()<WAYPOINT_RADIUS*WAYPOINT_RADIUS)
- {
- m_wayPointIdx++;
- if (m_wayPointIdx>=m_pathLen)
- {
- m_wayPointIdx = -1;
- terminate = true;
- }
- else
- waypoint.setValue(&m_path[3*m_wayPointIdx]);
- }
-
- m_steerVec = waypoint - mypos;
- apply_steerforce = true;
-
-
- if (m_enableVisualization)
- {
- //debug draw
- static const MT_Vector3 PATH_COLOR(1.0f,0.0f,0.0f);
- m_navmesh->DrawPath(m_path, m_pathLen, PATH_COLOR);
- }
- }
-
- }
- break;
- }
-
- if (apply_steerforce)
- {
- bool isdyna = obj->IsDynamic();
- if (isdyna)
- m_steerVec.z() = 0;
- if (!m_steerVec.fuzzyZero())
- m_steerVec.normalize();
- MT_Vector3 newvel = m_velocity * m_steerVec;
-
- //adjust velocity to avoid obstacles
- if (m_simulation && m_obstacle /*&& !newvel.fuzzyZero()*/)
- {
- if (m_enableVisualization)
- KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(1.0f, 0.0f, 0.0f));
- m_simulation->AdjustObstacleVelocity(m_obstacle, m_mode!=KX_STEERING_PATHFOLLOWING ? m_navmesh : NULL,
- newvel, m_acceleration*(float)delta, m_turnspeed/(180.0f*(float)(M_PI*delta)));
- if (m_enableVisualization)
- KX_RasterizerDrawDebugLine(mypos, mypos + newvel, MT_Vector3(0.0f, 1.0f, 0.0f));
- }
-
- HandleActorFace(newvel);
- if (isdyna)
- {
- //temporary solution: set 2D steering velocity directly to obj
- //correct way is to apply physical force
- MT_Vector3 curvel = obj->GetLinearVelocity();
-
- if (m_lockzvel)
- newvel.z() = 0.0f;
- else
- newvel.z() = curvel.z();
-
- obj->setLinearVelocity(newvel, false);
- }
- else
- {
- MT_Vector3 movement = delta*newvel;
- obj->ApplyMovement(movement, false);
- }
- }
- else
- {
- if (m_simulation && m_obstacle)
- {
- m_obstacle->dvel[0] = 0.f;
- m_obstacle->dvel[1] = 0.f;
- }
-
- }
-
- if (terminate && m_isSelfTerminated)
- return false;
- }
-
- return true;
-}
-
-const MT_Vector3& KX_SteeringActuator::GetSteeringVec()
-{
- static MT_Vector3 ZERO_VECTOR(0, 0, 0);
- if (m_isActive)
- return m_steerVec;
- else
- return ZERO_VECTOR;
-}
-
-inline float vdot2(const float* a, const float* b)
-{
- return a[0]*b[0] + a[2]*b[2];
-}
-static bool barDistSqPointToTri(const float* p, const float* a, const float* b, const float* c)
-{
- float v0[3], v1[3], v2[3];
- rcVsub(v0, c,a);
- rcVsub(v1, b,a);
- rcVsub(v2, p,a);
-
- const float dot00 = vdot2(v0, v0);
- const float dot01 = vdot2(v0, v1);
- const float dot02 = vdot2(v0, v2);
- const float dot11 = vdot2(v1, v1);
- const float dot12 = vdot2(v1, v2);
-
- // Compute barycentric coordinates
- float invDenom = 1.0f / (dot00 * dot11 - dot01 * dot01);
- float u = (dot11 * dot02 - dot01 * dot12) * invDenom;
- float v = (dot00 * dot12 - dot01 * dot02) * invDenom;
-
- float ud = u<0.f ? -u : (u>1.f ? u-1.f : 0.f);
- float vd = v<0.f ? -v : (v>1.f ? v-1.f : 0.f);
- return ud * ud + vd * vd;
-}
-
-inline void flipAxes(float* vec)
-{
- std::swap(vec[1],vec[2]);
-}
-
-static bool getNavmeshNormal(dtStatNavMesh* navmesh, const MT_Vector3& pos, MT_Vector3& normal)
-{
- static const float polyPickExt[3] = {2, 4, 2};
- float spos[3];
- pos.getValue(spos);
- flipAxes(spos);
- dtStatPolyRef sPolyRef = navmesh->findNearestPoly(spos, polyPickExt);
- if (sPolyRef == 0)
- return false;
- const dtStatPoly* p = navmesh->getPoly(sPolyRef-1);
- const dtStatPolyDetail* pd = navmesh->getPolyDetail(sPolyRef-1);
-
- float distMin = FLT_MAX;
- int idxMin = -1;
- for (int i = 0; i < pd->ntris; ++i)
- {
- const unsigned char* t = navmesh->getDetailTri(pd->tbase+i);
- const float* v[3];
- for (int j = 0; j < 3; ++j)
- {
- if (t[j] < p->nv)
- v[j] = navmesh->getVertex(p->v[t[j]]);
- else
- v[j] = navmesh->getDetailVertex(pd->vbase+(t[j]-p->nv));
- }
- float dist = barDistSqPointToTri(spos, v[0], v[1], v[2]);
- if (dist<distMin)
- {
- distMin = dist;
- idxMin = i;
- }
- }
-
- if (idxMin>=0)
- {
- const unsigned char* t = navmesh->getDetailTri(pd->tbase+idxMin);
- const float* v[3];
- for (int j = 0; j < 3; ++j)
- {
- if (t[j] < p->nv)
- v[j] = navmesh->getVertex(p->v[t[j]]);
- else
- v[j] = navmesh->getDetailVertex(pd->vbase+(t[j]-p->nv));
- }
- MT_Vector3 tri[3];
- for (size_t j=0; j<3; j++)
- tri[j].setValue(v[j][0],v[j][2],v[j][1]);
- MT_Vector3 a,b;
- a = tri[1]-tri[0];
- b = tri[2]-tri[0];
- normal = b.cross(a).safe_normalized();
- return true;
- }
-
- return false;
-}
-
-void KX_SteeringActuator::HandleActorFace(MT_Vector3& velocity)
-{
- if (m_facingMode==0 && (!m_navmesh || !m_normalUp))
- return;
- KX_GameObject* curobj = (KX_GameObject*) GetParent();
- MT_Vector3 dir = m_facingMode==0 ? curobj->NodeGetLocalOrientation().getColumn(1) : velocity;
- if (dir.fuzzyZero())
- return;
- dir.normalize();
- MT_Vector3 up(0,0,1);
- MT_Vector3 left;
- MT_Matrix3x3 mat;
-
- if (m_navmesh && m_normalUp)
- {
- dtStatNavMesh* navmesh = m_navmesh->GetNavMesh();
- MT_Vector3 normal;
- MT_Vector3 trpos = m_navmesh->TransformToLocalCoords(curobj->NodeGetWorldPosition());
- if (getNavmeshNormal(navmesh, trpos, normal))
- {
-
- left = (dir.cross(up)).safe_normalized();
- dir = (-left.cross(normal)).safe_normalized();
- up = normal;
- }
- }
-
- switch (m_facingMode)
- {
- case 1: // TRACK X
- {
- left = dir.safe_normalized();
- dir = -(left.cross(up)).safe_normalized();
- break;
- };
- case 2: // TRACK Y
- {
- left = (dir.cross(up)).safe_normalized();
- break;
- }
-
- case 3: // track Z
- {
- left = up.safe_normalized();
- up = dir.safe_normalized();
- dir = left;
- left = (dir.cross(up)).safe_normalized();
- break;
- }
-
- case 4: // TRACK -X
- {
- left = -dir.safe_normalized();
- dir = -(left.cross(up)).safe_normalized();
- break;
- };
- case 5: // TRACK -Y
- {
- left = (-dir.cross(up)).safe_normalized();
- dir = -dir;
- break;
- }
- case 6: // track -Z
- {
- left = up.safe_normalized();
- up = -dir.safe_normalized();
- dir = left;
- left = (dir.cross(up)).safe_normalized();
- break;
- }
- }
-
- mat.setValue (
- left[0], dir[0],up[0],
- left[1], dir[1],up[1],
- left[2], dir[2],up[2]
- );
-
-
-
- KX_GameObject* parentObject = curobj->GetParent();
- if (parentObject)
- {
- MT_Point3 localpos;
- localpos = curobj->GetSGNode()->GetLocalPosition();
- MT_Matrix3x3 parentmatinv;
- parentmatinv = parentObject->NodeGetWorldOrientation ().inverse ();
- mat = parentmatinv * mat;
- mat = m_parentlocalmat * mat;
- curobj->NodeSetLocalOrientation(mat);
- curobj->NodeSetLocalPosition(localpos);
- }
- else
- {
- curobj->NodeSetLocalOrientation(mat);
- }
-
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_SteeringActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_SteeringActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_SteeringActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_SteeringActuator::Attributes[] = {
- KX_PYATTRIBUTE_INT_RW("behavior", KX_STEERING_NODEF+1, KX_STEERING_MAX-1, true, KX_SteeringActuator, m_mode),
- KX_PYATTRIBUTE_RW_FUNCTION("target", KX_SteeringActuator, pyattr_get_target, pyattr_set_target),
- KX_PYATTRIBUTE_RW_FUNCTION("navmesh", KX_SteeringActuator, pyattr_get_navmesh, pyattr_set_navmesh),
- KX_PYATTRIBUTE_FLOAT_RW("distance", 0.0f, 1000.0f, KX_SteeringActuator, m_distance),
- KX_PYATTRIBUTE_FLOAT_RW("velocity", 0.0f, 1000.0f, KX_SteeringActuator, m_velocity),
- KX_PYATTRIBUTE_FLOAT_RW("acceleration", 0.0f, 1000.0f, KX_SteeringActuator, m_acceleration),
- KX_PYATTRIBUTE_FLOAT_RW("turnspeed", 0.0f, 720.0f, KX_SteeringActuator, m_turnspeed),
- KX_PYATTRIBUTE_BOOL_RW("selfterminated", KX_SteeringActuator, m_isSelfTerminated),
- KX_PYATTRIBUTE_BOOL_RW("enableVisualization", KX_SteeringActuator, m_enableVisualization),
- KX_PYATTRIBUTE_RO_FUNCTION("steeringVec", KX_SteeringActuator, pyattr_get_steeringVec),
- KX_PYATTRIBUTE_SHORT_RW("facingMode", 0, 6, true, KX_SteeringActuator, m_facingMode),
- KX_PYATTRIBUTE_INT_RW("pathUpdatePeriod", -1, 100000, true, KX_SteeringActuator, m_pathUpdatePeriod),
- KX_PYATTRIBUTE_BOOL_RW("lockZVelocity", KX_SteeringActuator, m_lockzvel),
- { NULL } //Sentinel
-};
-
-PyObject *KX_SteeringActuator::pyattr_get_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
- if (!actuator->m_target)
- Py_RETURN_NONE;
- else
- return actuator->m_target->GetProxy();
-}
-
-int KX_SteeringActuator::pyattr_set_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (actuator->m_target != NULL)
- actuator->m_target->UnregisterActuator(actuator);
-
- actuator->m_target = (KX_GameObject*) gameobj;
-
- if (actuator->m_target)
- actuator->m_target->RegisterActuator(actuator);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_SteeringActuator::pyattr_get_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
- if (!actuator->m_navmesh)
- Py_RETURN_NONE;
- else
- return actuator->m_navmesh->GetProxy();
-}
-
-int KX_SteeringActuator::pyattr_set_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_SteeringActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (dynamic_cast<KX_NavMeshObject *>(gameobj) == NULL) {
- PyErr_Format(PyExc_TypeError, "KX_NavMeshObject is expected");
- return PY_SET_ATTR_FAIL;
- }
-
- if (actuator->m_navmesh != NULL)
- actuator->m_navmesh->UnregisterActuator(actuator);
-
- actuator->m_navmesh = static_cast<KX_NavMeshObject*>(gameobj);
-
- if (actuator->m_navmesh)
- actuator->m_navmesh->RegisterActuator(actuator);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-PyObject *KX_SteeringActuator::pyattr_get_steeringVec(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_SteeringActuator* actuator = static_cast<KX_SteeringActuator*>(self);
- const MT_Vector3& steeringVec = actuator->GetSteeringVec();
- return PyObjectFrom(steeringVec);
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
-
diff --git a/source/gameengine/Ketsji/KX_SteeringActuator.h b/source/gameengine/Ketsji/KX_SteeringActuator.h
deleted file mode 100644
index 3273471c166..00000000000
--- a/source/gameengine/Ketsji/KX_SteeringActuator.h
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Add steering behaviors
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __KX_STEERINGACTUATOR_H__
-#define __KX_STEERINGACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "SCA_LogicManager.h"
-#include "MT_Matrix3x3.h"
-
-class KX_GameObject;
-class KX_NavMeshObject;
-struct KX_Obstacle;
-class KX_ObstacleSimulation;
-const int MAX_PATH_LENGTH = 128;
-
-class KX_SteeringActuator : public SCA_IActuator
-{
- Py_Header
-
- /** Target object */
- KX_GameObject *m_target;
- KX_NavMeshObject *m_navmesh;
- int m_mode;
- float m_distance;
- float m_velocity;
- float m_acceleration;
- float m_turnspeed;
- KX_ObstacleSimulation* m_simulation;
-
- double m_updateTime;
- KX_Obstacle* m_obstacle;
- bool m_isActive;
- bool m_isSelfTerminated;
- bool m_enableVisualization;
- short m_facingMode;
- bool m_normalUp;
- float m_path[MAX_PATH_LENGTH*3];
- int m_pathLen;
- int m_pathUpdatePeriod;
- double m_pathUpdateTime;
- bool m_lockzvel;
- int m_wayPointIdx;
- MT_Matrix3x3 m_parentlocalmat;
- MT_Vector3 m_steerVec;
- void HandleActorFace(MT_Vector3& velocity);
-public:
- enum KX_STEERINGACT_MODE
- {
- KX_STEERING_NODEF = 0,
- KX_STEERING_SEEK,
- KX_STEERING_FLEE,
- KX_STEERING_PATHFOLLOWING,
- KX_STEERING_MAX
- };
-
- KX_SteeringActuator(class SCA_IObject* gameobj,
- int mode,
- KX_GameObject *target,
- KX_GameObject *navmesh,
- float distance,
- float velocity,
- float acceleration,
- float turnspeed,
- bool isSelfTerminated,
- int pathUpdatePeriod,
- KX_ObstacleSimulation* simulation,
- short facingmode,
- bool normalup,
- bool enableVisualization,
- bool lockzvel);
- virtual ~KX_SteeringActuator();
- virtual bool Update(double curtime, bool frame);
-
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
- virtual void ReParent(SCA_IObject* parent);
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual bool UnlinkObject(SCA_IObject* clientobj);
- const MT_Vector3& GetSteeringVec();
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- /* These are used to get and set m_target */
- static PyObject *pyattr_get_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_target(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_navmesh(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_steeringVec(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
-
-
-#endif /* WITH_PYTHON */
-
-}; /* end of class KX_SteeringActuator : public SCA_PropertyActuator */
-
-#endif /* __KX_STEERINGACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp b/source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp
deleted file mode 100644
index 13717993c4c..00000000000
--- a/source/gameengine/Ketsji/KX_TimeCategoryLogger.cpp
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_TimeCategoryLogger.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_TimeCategoryLogger.h"
-
-KX_TimeCategoryLogger::KX_TimeCategoryLogger(unsigned int maxNumMeasurements)
-: m_maxNumMeasurements(maxNumMeasurements)
-{
-}
-
-
-KX_TimeCategoryLogger::~KX_TimeCategoryLogger(void)
-{
- DisposeLoggers();
-}
-
-
-void KX_TimeCategoryLogger::SetMaxNumMeasurements(unsigned int maxNumMeasurements)
-{
- KX_TimeLoggerMap::iterator it;
- for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
- it->second->SetMaxNumMeasurements(maxNumMeasurements);
- }
- m_maxNumMeasurements = maxNumMeasurements;
-}
-
-
-unsigned int KX_TimeCategoryLogger::GetMaxNumMeasurements(void) const
-{
- return m_maxNumMeasurements;
-}
-
-
-void KX_TimeCategoryLogger::AddCategory(TimeCategory tc)
-{
- // Only add if not already present
- if (m_loggers.find(tc) == m_loggers.end()) {
- KX_TimeLogger* logger = new KX_TimeLogger(m_maxNumMeasurements);
- //assert(logger);
- m_loggers.insert(KX_TimeLoggerMap::value_type(tc, logger));
- }
-}
-
-
-void KX_TimeCategoryLogger::StartLog(TimeCategory tc, double now, bool endOtherCategories)
-{
- if (endOtherCategories) {
- KX_TimeLoggerMap::iterator it;
- for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
- if (it->first != tc) {
- it->second->EndLog(now);
- }
- }
- }
- //assert(m_loggers[tc] != m_loggers.end());
- m_loggers[tc]->StartLog(now);
-}
-
-
-void KX_TimeCategoryLogger::EndLog(TimeCategory tc, double now)
-{
- //assert(m_loggers[tc] != m_loggers.end());
- m_loggers[tc]->EndLog(now);
-}
-
-
-void KX_TimeCategoryLogger::EndLog(double now)
-{
- KX_TimeLoggerMap::iterator it;
- for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
- it->second->EndLog(now);
- }
-}
-
-
-void KX_TimeCategoryLogger::NextMeasurement(double now)
-{
- KX_TimeLoggerMap::iterator it;
- for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
- it->second->NextMeasurement(now);
- }
-}
-
-
-double KX_TimeCategoryLogger::GetAverage(TimeCategory tc)
-{
- //assert(m_loggers[tc] != m_loggers.end());
- return m_loggers[tc]->GetAverage();
-}
-
-
-double KX_TimeCategoryLogger::GetAverage(void)
-{
- double time = 0.0;
-
- KX_TimeLoggerMap::iterator it;
- for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
- time += it->second->GetAverage();
- }
-
- return time;
-}
-
-
-void KX_TimeCategoryLogger::DisposeLoggers(void)
-{
- KX_TimeLoggerMap::iterator it;
- for (it = m_loggers.begin(); it != m_loggers.end(); it++) {
- delete it->second;
- }
-}
-
diff --git a/source/gameengine/Ketsji/KX_TimeCategoryLogger.h b/source/gameengine/Ketsji/KX_TimeCategoryLogger.h
deleted file mode 100644
index e097454fca7..00000000000
--- a/source/gameengine/Ketsji/KX_TimeCategoryLogger.h
+++ /dev/null
@@ -1,136 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_TimeCategoryLogger.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_TIMECATEGORYLOGGER_H__
-#define __KX_TIMECATEGORYLOGGER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* suppress stl-MSVC debug info warning */
-#endif
-
-#include <map>
-
-#include "KX_TimeLogger.h"
-
-/**
- * Stores and manages time measurements by category.
- * Categories can be added dynamically.
- * Average measurements can be established for each separate category
- * or for all categories together.
- */
-class KX_TimeCategoryLogger {
-public:
- typedef int TimeCategory;
-
- /**
- * Constructor.
- * \param maxNumMesasurements Maximum number of measurements stored (> 1).
- */
- KX_TimeCategoryLogger(unsigned int maxNumMeasurements = 10);
-
- /**
- * Destructor.
- */
- virtual ~KX_TimeCategoryLogger(void);
-
- /**
- * Changes the maximum number of measurements that can be stored.
- */
- virtual void SetMaxNumMeasurements(unsigned int maxNumMeasurements);
-
- /**
- * Changes the maximum number of measurements that can be stored.
- */
- virtual unsigned int GetMaxNumMeasurements(void) const;
-
- /**
- * Adds a category.
- * \param category The new category.
- */
- virtual void AddCategory(TimeCategory tc);
-
- /**
- * Starts logging in current measurement for the given category.
- * \param tc The category to log to.
- * \param now The current time.
- * \param endOtherCategories Whether to stop logging to other categories.
- */
- virtual void StartLog(TimeCategory tc, double now, bool endOtherCategories = true);
-
- /**
- * End logging in current measurement for the given category.
- * \param tc The category to log to.
- * \param now The current time.
- */
- virtual void EndLog(TimeCategory tc, double now);
-
- /**
- * End logging in current measurement for all categories.
- * \param now The current time.
- */
- virtual void EndLog(double now);
-
- /**
- * Logs time in next measurement.
- * \param now The current time.
- */
- virtual void NextMeasurement(double now);
-
- /**
- * Returns average of all but the current measurement time.
- * \return The average of all but the current measurement.
- */
- virtual double GetAverage(TimeCategory tc);
-
- /**
- * Returns average for grand total.
- */
- virtual double GetAverage(void);
-
-protected:
- /**
- * Disposes loggers.
- */
- virtual void DisposeLoggers(void);
-
- /** Storage for the loggers. */
- typedef std::map<TimeCategory, KX_TimeLogger*> KX_TimeLoggerMap;
- KX_TimeLoggerMap m_loggers;
- /** Maximum number of measurements. */
- unsigned int m_maxNumMeasurements;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_TimeCategoryLogger")
-#endif
-};
-
-#endif /* __KX_TIMECATEGORYLOGGER_H__ */
diff --git a/source/gameengine/Ketsji/KX_TimeLogger.cpp b/source/gameengine/Ketsji/KX_TimeLogger.cpp
deleted file mode 100644
index 12106245c4d..00000000000
--- a/source/gameengine/Ketsji/KX_TimeLogger.cpp
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_TimeLogger.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_TimeLogger.h"
-
-KX_TimeLogger::KX_TimeLogger(unsigned int maxNumMeasurements) :
- m_maxNumMeasurements(maxNumMeasurements),
- m_logStart(0),
- m_logging(false)
-{
-}
-
-
-KX_TimeLogger::~KX_TimeLogger(void)
-{
-}
-
-
-void KX_TimeLogger::SetMaxNumMeasurements(unsigned int maxNumMeasurements)
-{
- if ((m_maxNumMeasurements != maxNumMeasurements) && maxNumMeasurements) {
- // Actual removing is done in NextMeasurement()
- m_maxNumMeasurements = maxNumMeasurements;
- }
-}
-
-
-unsigned int KX_TimeLogger::GetMaxNumMeasurements(void) const
-{
- return m_maxNumMeasurements;
-}
-
-
-void KX_TimeLogger::StartLog(double now)
-{
- if (!m_logging) {
- m_logging = true;
- m_logStart = now;
- }
-}
-
-
-void KX_TimeLogger::EndLog(double now)
-{
- if (m_logging) {
- m_logging = false;
- double time = now - m_logStart;
- if (m_measurements.size() > 0) {
- m_measurements[0] += time;
- }
- }
-}
-
-
-void KX_TimeLogger::NextMeasurement(double now)
-{
- // End logging to current measurement
- EndLog(now);
-
- // Add a new measurement at the front
- double m = 0.0;
- m_measurements.push_front(m);
-
- // Remove measurement if we grow beyond the maximum size
- if ((m_measurements.size()) > m_maxNumMeasurements) {
- while (m_measurements.size() > m_maxNumMeasurements) {
- m_measurements.pop_back();
- }
- }
-}
-
-
-
-double KX_TimeLogger::GetAverage(void) const
-{
- double avg = 0.0;
-
- unsigned int numMeasurements = m_measurements.size();
- if (numMeasurements > 1) {
- for (unsigned int i = 1; i < numMeasurements; i++) {
- avg += m_measurements[i];
- }
- avg /= (double)numMeasurements - 1.0;
- }
-
- return avg;
-}
-
diff --git a/source/gameengine/Ketsji/KX_TimeLogger.h b/source/gameengine/Ketsji/KX_TimeLogger.h
deleted file mode 100644
index 59d7bdc84e3..00000000000
--- a/source/gameengine/Ketsji/KX_TimeLogger.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_TimeLogger.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_TIMELOGGER_H__
-#define __KX_TIMELOGGER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* suppress stl-MSVC debug info warning */
-#endif
-
-#include <deque>
-
-#ifdef WITH_CXX_GUARDEDALLOC
-# include "MEM_guardedalloc.h"
-#endif
-
-/**
- * Stores and manages time measurements.
- */
-class KX_TimeLogger {
-public:
- /**
- * Constructor.
- * \param maxNumMesasurements Maximum number of measurements stored (>1).
- */
- KX_TimeLogger(unsigned int maxNumMeasurements = 10);
-
- /**
- * Destructor.
- */
- virtual ~KX_TimeLogger(void);
-
- /**
- * Changes the maximum number of measurements that can be stored.
- */
- virtual void SetMaxNumMeasurements(unsigned int maxNumMeasurements);
-
- /**
- * Changes the maximum number of measurements that can be stored.
- */
- virtual unsigned int GetMaxNumMeasurements(void) const;
-
- /**
- * Starts logging in current measurement.
- * \param now The current time.
- */
- virtual void StartLog(double now);
-
- /**
- * End logging in current measurement.
- * \param now The current time.
- */
- virtual void EndLog(double now);
-
- /**
- * Logs time in next measurement.
- * \param now The current time.
- */
- virtual void NextMeasurement(double now);
-
- /**
- * Returns average of all but the current measurement.
- * \return The average of all but the current measurement.
- */
- virtual double GetAverage(void) const;
-
-protected:
- /** Storage for the measurements. */
- std::deque<double> m_measurements;
-
- /** Maximum number of measurements. */
- unsigned int m_maxNumMeasurements;
-
- /** Time at start of logging. */
- double m_logStart;
-
- /** State of logging. */
- bool m_logging;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_TimeLogger")
-#endif
-};
-
-#endif /* __KX_TIMELOGGER_H__ */
diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.cpp b/source/gameengine/Ketsji/KX_TouchEventManager.cpp
deleted file mode 100644
index 7f167652464..00000000000
--- a/source/gameengine/Ketsji/KX_TouchEventManager.cpp
+++ /dev/null
@@ -1,246 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_TouchEventManager.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_TouchEventManager.h"
-#include "SCA_ISensor.h"
-#include "KX_TouchSensor.h"
-#include "KX_GameObject.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IPhysicsController.h"
-
-
-KX_TouchEventManager::KX_TouchEventManager(class SCA_LogicManager* logicmgr,
- PHY_IPhysicsEnvironment* physEnv)
- : SCA_EventManager(logicmgr, TOUCH_EVENTMGR),
- m_physEnv(physEnv)
-{
- //notm_scene->addTouchCallback(STATIC_RESPONSE, KX_TouchEventManager::collisionResponse, this);
-
- //m_scene->addTouchCallback(OBJECT_RESPONSE, KX_TouchEventManager::collisionResponse, this);
- //m_scene->addTouchCallback(SENSOR_RESPONSE, KX_TouchEventManager::collisionResponse, this);
-
- m_physEnv->AddTouchCallback(PHY_OBJECT_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
- m_physEnv->AddTouchCallback(PHY_SENSOR_RESPONSE, KX_TouchEventManager::newCollisionResponse, this);
- m_physEnv->AddTouchCallback(PHY_BROADPH_RESPONSE, KX_TouchEventManager::newBroadphaseResponse, this);
-
-}
-
-bool KX_TouchEventManager::NewHandleCollision(void* object1, void* object2, const PHY_CollData *coll_data)
-{
-
- PHY_IPhysicsController* obj1 = static_cast<PHY_IPhysicsController*>(object1);
- PHY_IPhysicsController* obj2 = static_cast<PHY_IPhysicsController*>(object2);
-
- m_newCollisions.insert(NewCollision(obj1, obj2, coll_data));
-
- return false;
-}
-
-
-bool KX_TouchEventManager::newCollisionResponse(void *client_data,
- void *object1,
- void *object2,
- const PHY_CollData *coll_data)
-{
- KX_TouchEventManager *touchmgr = (KX_TouchEventManager *) client_data;
- touchmgr->NewHandleCollision(object1, object2, coll_data);
- return false;
-}
-
-bool KX_TouchEventManager::newBroadphaseResponse(void *client_data,
- void *object1,
- void *object2,
- const PHY_CollData *coll_data)
-{
- PHY_IPhysicsController* ctrl1 = static_cast<PHY_IPhysicsController*>(object1);
- PHY_IPhysicsController* ctrl2 = static_cast<PHY_IPhysicsController*>(object2);
-
- KX_ClientObjectInfo *info1 = (ctrl1) ? static_cast<KX_ClientObjectInfo*>(ctrl1->GetNewClientInfo()) : NULL;
- KX_ClientObjectInfo *info2 = (ctrl2) ? static_cast<KX_ClientObjectInfo*>(ctrl2->GetNewClientInfo()) : NULL;
-
- // This call back should only be called for controllers of Near and Radar sensor
- if (!info1)
- return true;
-
- // Get KX_GameObjects for callbacks
- KX_GameObject* gobj1 = info1->m_gameobject;
- KX_GameObject* gobj2 = (info2) ? info2->m_gameobject : NULL;
-
- bool has_py_callbacks = false;
-
-#ifdef WITH_PYTHON
- // Consider callbacks for broadphase inclusion if it's a sensor object type
- if (gobj1 && gobj2)
- has_py_callbacks = gobj1->m_collisionCallbacks || gobj2->m_collisionCallbacks;
-#else
- (void)gobj1;
- (void)gobj2;
-#endif
-
- switch (info1->m_type)
- {
- case KX_ClientObjectInfo::SENSOR:
- if (info1->m_sensors.size() == 1)
- {
- // only one sensor for this type of object
- KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*info1->m_sensors.begin());
- return touchsensor->BroadPhaseFilterCollision(object1, object2);
- }
- break;
- case KX_ClientObjectInfo::OBSENSOR:
- case KX_ClientObjectInfo::OBACTORSENSOR:
- // this object may have multiple collision sensors,
- // check is any of them is interested in this object
- for (std::list<SCA_ISensor*>::iterator it = info1->m_sensors.begin();
- it != info1->m_sensors.end();
- ++it)
- {
- if ((*it)->GetSensorType() == SCA_ISensor::ST_TOUCH)
- {
- KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(*it);
- if (touchsensor->BroadPhaseSensorFilterCollision(object1, object2))
- return true;
- }
- }
-
- return has_py_callbacks;
-
- // quiet the compiler
- case KX_ClientObjectInfo::STATIC:
- case KX_ClientObjectInfo::ACTOR:
- case KX_ClientObjectInfo::RESERVED1:
- /* do nothing*/
- break;
- }
- return true;
-}
-
-void KX_TouchEventManager::RegisterSensor(SCA_ISensor* sensor)
-{
- KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
- if (m_sensors.AddBack(touchsensor))
- // the sensor was effectively inserted, register it
- touchsensor->RegisterSumo(this);
-}
-
-void KX_TouchEventManager::RemoveSensor(SCA_ISensor* sensor)
-{
- KX_TouchSensor* touchsensor = static_cast<KX_TouchSensor*>(sensor);
- if (touchsensor->Delink())
- // the sensor was effectively removed, unregister it
- touchsensor->UnregisterSumo(this);
-}
-
-
-
-void KX_TouchEventManager::EndFrame()
-{
- SG_DList::iterator<KX_TouchSensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- {
- (*it)->EndFrame();
- }
-}
-
-
-
-void KX_TouchEventManager::NextFrame()
-{
- SG_DList::iterator<KX_TouchSensor> it(m_sensors);
- for (it.begin();!it.end();++it)
- (*it)->SynchronizeTransform();
-
- for (std::set<NewCollision>::iterator cit = m_newCollisions.begin(); cit != m_newCollisions.end(); ++cit)
- {
- // Controllers
- PHY_IPhysicsController* ctrl1 = (*cit).first;
- PHY_IPhysicsController* ctrl2 = (*cit).second;
-
- // Sensor iterator
- list<SCA_ISensor*>::iterator sit;
-
- // First client info
- KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*>(ctrl1->GetNewClientInfo());
- // First gameobject
- KX_GameObject *kxObj1 = KX_GameObject::GetClientObject(client_info);
- // Invoke sensor response for each object
- if (client_info) {
- for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit) {
- static_cast<KX_TouchSensor*>(*sit)->NewHandleCollision(ctrl1, ctrl2, NULL);
- }
- }
-
- // Second client info
- client_info = static_cast<KX_ClientObjectInfo *>(ctrl2->GetNewClientInfo());
- // Second gameobject
- KX_GameObject *kxObj2 = KX_GameObject::GetClientObject(client_info);
- if (client_info) {
- for ( sit = client_info->m_sensors.begin(); sit != client_info->m_sensors.end(); ++sit) {
- static_cast<KX_TouchSensor*>(*sit)->NewHandleCollision(ctrl2, ctrl1, NULL);
- }
- }
- // Run python callbacks
- PHY_CollData *colldata = cit->colldata;
- kxObj1->RunCollisionCallbacks(kxObj2, colldata->m_point1, colldata->m_normal);
- kxObj2->RunCollisionCallbacks(kxObj1, colldata->m_point2, -colldata->m_normal);
-
- delete cit->colldata;
- }
-
- m_newCollisions.clear();
-
- for (it.begin();!it.end();++it)
- (*it)->Activate(m_logicmgr);
- }
-
-
-KX_TouchEventManager::NewCollision::NewCollision(PHY_IPhysicsController *first,
- PHY_IPhysicsController *second,
- const PHY_CollData *colldata)
- : first(first), second(second), colldata(new PHY_CollData(*colldata))
-{}
-
-KX_TouchEventManager::NewCollision::NewCollision(const NewCollision &to_copy)
- : first(to_copy.first), second(to_copy.second), colldata(to_copy.colldata)
-{}
-
-bool KX_TouchEventManager::NewCollision::operator<(const NewCollision &other) const
-{
- //see strict weak ordering: https://support.microsoft.com/en-us/kb/949171
- if (first == other.first) {
- if (second == other.second) {
- return colldata < other.colldata;
- }
- return second < other.second;
- }
- return first < other.first;
-}
diff --git a/source/gameengine/Ketsji/KX_TouchEventManager.h b/source/gameengine/Ketsji/KX_TouchEventManager.h
deleted file mode 100644
index d9c6fdad307..00000000000
--- a/source/gameengine/Ketsji/KX_TouchEventManager.h
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_TouchEventManager.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_TOUCHEVENTMANAGER_H__
-#define __KX_TOUCHEVENTMANAGER_H__
-
-
-#include "SCA_EventManager.h"
-#include "KX_TouchSensor.h"
-#include "KX_GameObject.h"
-
-#include <vector>
-#include <set>
-
-class SCA_ISensor;
-class PHY_IPhysicsEnvironment;
-
-class KX_TouchEventManager : public SCA_EventManager
-{
- /**
- * Contains two colliding objects and the first contact point.
- */
- class NewCollision {
- public:
- PHY_IPhysicsController *first;
- PHY_IPhysicsController *second;
- PHY_CollData *colldata;
-
- /**
- * Creates a copy of the given PHY_CollData; freeing that copy should be done by the owner of
- * the NewCollision object.
- *
- * This allows us to efficiently store NewCollision objects in a std::set without creating more
- * copies of colldata, as the NewCollision copy constructor reuses the pointer and doesn't clone
- * it again. */
- NewCollision(PHY_IPhysicsController *first,
- PHY_IPhysicsController *second,
- const PHY_CollData *colldata);
- NewCollision(const NewCollision &to_copy);
- bool operator<(const NewCollision &other) const;
- };
-
- PHY_IPhysicsEnvironment* m_physEnv;
-
- std::set<NewCollision> m_newCollisions;
-
-
- static bool newCollisionResponse(void *client_data,
- void *object1,
- void *object2,
- const PHY_CollData *coll_data);
-
- static bool newBroadphaseResponse(void *client_data,
- void *object1,
- void *object2,
- const PHY_CollData *coll_data);
-
- virtual bool NewHandleCollision(void* obj1,void* obj2,
- const PHY_CollData * coll_data);
-
-
-
-
-
-public:
- KX_TouchEventManager(class SCA_LogicManager* logicmgr,
- PHY_IPhysicsEnvironment* physEnv);
- virtual void NextFrame();
- virtual void EndFrame();
- virtual void RegisterSensor(SCA_ISensor* sensor);
- virtual void RemoveSensor(SCA_ISensor* sensor);
- SCA_LogicManager* GetLogicManager() { return m_logicmgr;}
- PHY_IPhysicsEnvironment *GetPhysicsEnvironment() { return m_physEnv; }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_TouchEventManager")
-#endif
-};
-
-#endif /* __KX_TOUCHEVENTMANAGER_H__ */
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.cpp b/source/gameengine/Ketsji/KX_TouchSensor.cpp
deleted file mode 100644
index 593d3e844e8..00000000000
--- a/source/gameengine/Ketsji/KX_TouchSensor.cpp
+++ /dev/null
@@ -1,362 +0,0 @@
-/*
- * Senses touch and collision events
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_TouchSensor.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_TouchSensor.h"
-#include "SCA_EventManager.h"
-#include "SCA_LogicManager.h"
-#include "KX_GameObject.h"
-#include "KX_TouchEventManager.h"
-
-#include "PHY_IPhysicsController.h"
-
-#include "RAS_MeshObject.h"
-
-#include <iostream>
-#include "PHY_IPhysicsEnvironment.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-void KX_TouchSensor::SynchronizeTransform()
-{
- // the touch sensor does not require any synchronization: it uses
- // the same physical object which is already synchronized by Blender
-}
-
-
-void KX_TouchSensor::EndFrame()
-{
- m_colliders->ReleaseAndRemoveAll();
- m_hitObject = NULL;
- m_bTriggered = false;
- m_bColliderHash = 0;
-}
-
-void KX_TouchSensor::UnregisterToManager()
-{
- // before unregistering the sensor, make sure we release all references
- EndFrame();
- SCA_ISensor::UnregisterToManager();
-}
-
-bool KX_TouchSensor::Evaluate()
-{
- bool result = false;
- bool reset = m_reset && m_level;
- m_reset = false;
- if (m_bTriggered != m_bLastTriggered)
- {
- m_bLastTriggered = m_bTriggered;
- if (!m_bTriggered)
- m_hitObject = NULL;
- result = true;
- }
- if (reset)
- // force an event
- result = true;
-
- if (m_bTouchPulse) { /* pulse on changes to the colliders */
- int count = m_colliders->GetCount();
-
- if (m_bLastCount!=count || m_bColliderHash!=m_bLastColliderHash) {
- m_bLastCount = count;
- m_bLastColliderHash= m_bColliderHash;
- result = true;
- }
- }
- return result;
-}
-
-KX_TouchSensor::KX_TouchSensor(SCA_EventManager* eventmgr,KX_GameObject* gameobj,bool bFindMaterial,bool bTouchPulse,const STR_String& touchedpropname)
-:SCA_ISensor(gameobj,eventmgr),
-m_touchedpropname(touchedpropname),
-m_bFindMaterial(bFindMaterial),
-m_bTouchPulse(bTouchPulse),
-m_hitMaterial("")
-/*m_sumoObj(sumoObj),*/
-{
-// KX_TouchEventManager* touchmgr = (KX_TouchEventManager*) eventmgr;
-// m_resptable = touchmgr->GetResponseTable();
-
-// m_solidHandle = m_sumoObj->getObjectHandle();
-
- m_colliders = new CListValue();
-
- KX_ClientObjectInfo *client_info = gameobj->getClientInfo();
- //client_info->m_gameobject = gameobj;
- //client_info->m_auxilary_info = NULL;
- client_info->m_sensors.push_back(this);
-
- m_physCtrl = gameobj->GetPhysicsController();
- MT_assert( !gameobj->GetPhysicsController() || m_physCtrl );
- Init();
-}
-
-void KX_TouchSensor::Init()
-{
- m_bCollision = false;
- m_bTriggered = false;
- m_bLastTriggered = (m_invert)?true:false;
- m_bLastCount = 0;
- m_bColliderHash = m_bLastColliderHash = 0;
- m_hitObject = NULL;
- m_reset = true;
-}
-
-KX_TouchSensor::~KX_TouchSensor()
-{
- //DT_ClearObjectResponse(m_resptable,m_solidHandle);
- m_colliders->Release();
-}
-
-CValue* KX_TouchSensor::GetReplica()
-{
- KX_TouchSensor* replica = new KX_TouchSensor(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-void KX_TouchSensor::ProcessReplica()
-{
- SCA_ISensor::ProcessReplica();
- m_colliders = new CListValue();
- Init();
-}
-
-void KX_TouchSensor::ReParent(SCA_IObject* parent)
-{
- KX_GameObject *gameobj = static_cast<KX_GameObject *>(parent);
- PHY_IPhysicsController *sphy = ((KX_GameObject*)parent)->GetPhysicsController();
- if (sphy)
- m_physCtrl = sphy;
-
-// m_solidHandle = m_sumoObj->getObjectHandle();
- KX_ClientObjectInfo *client_info = gameobj->getClientInfo();
- //client_info->m_gameobject = gameobj;
- //client_info->m_auxilary_info = NULL;
-
- client_info->m_sensors.push_back(this);
- SCA_ISensor::ReParent(parent);
-}
-
-void KX_TouchSensor::RegisterSumo(KX_TouchEventManager *touchman)
-{
- if (m_physCtrl)
- {
- if (touchman->GetPhysicsEnvironment()->RequestCollisionCallback(m_physCtrl))
- {
- KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->GetNewClientInfo());
- if (client_info->isSensor())
- touchman->GetPhysicsEnvironment()->AddSensor(m_physCtrl);
- }
- }
-}
-void KX_TouchSensor::UnregisterSumo(KX_TouchEventManager* touchman)
-{
- if (m_physCtrl)
- {
- if (touchman->GetPhysicsEnvironment()->RemoveCollisionCallback(m_physCtrl))
- {
- // no more sensor on the controller, can remove it if it is a sensor object
- KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->GetNewClientInfo());
- if (client_info->isSensor())
- touchman->GetPhysicsEnvironment()->RemoveSensor(m_physCtrl);
- }
- }
-}
-
-// this function is called only for sensor objects
-// return true if the controller can collide with the object
-bool KX_TouchSensor::BroadPhaseSensorFilterCollision(void*obj1,void*obj2)
-{
- assert(obj1==m_physCtrl && obj2);
-
- KX_GameObject* myobj = (KX_GameObject*)GetParent();
- KX_GameObject* myparent = myobj->GetParent();
- KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*>(((PHY_IPhysicsController*)obj2)->GetNewClientInfo());
- KX_ClientObjectInfo *my_client_info = static_cast<KX_ClientObjectInfo*>(m_physCtrl->GetNewClientInfo());
- KX_GameObject* otherobj = ( client_info ? client_info->m_gameobject : NULL);
-
- // we can only check on persistent characteristic: m_link and m_suspended are not
- // good candidate because they are transient. That must be handled at another level
- if (!otherobj ||
- otherobj == myparent || // don't interact with our parent
- (my_client_info->m_type == KX_ClientObjectInfo::OBACTORSENSOR &&
- client_info->m_type != KX_ClientObjectInfo::ACTOR)) // only with actor objects
- return false;
-
- bool found = m_touchedpropname.IsEmpty();
- if (!found)
- {
- if (m_bFindMaterial) {
- for (unsigned int i = 0; i < otherobj->GetMeshCount(); ++i) {
- RAS_MeshObject *meshObj = otherobj->GetMesh(i);
- for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) {
- found = strcmp(m_touchedpropname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0;
- if (found)
- break;
- }
- }
- }
- else {
- found = (otherobj->GetProperty(m_touchedpropname) != NULL);
- }
- }
- return found;
-}
-
-bool KX_TouchSensor::NewHandleCollision(void*object1,void*object2,const PHY_CollData* colldata)
-{
-// KX_TouchEventManager* toucheventmgr = (KX_TouchEventManager*)m_eventmgr;
- KX_GameObject* parent = (KX_GameObject*)GetParent();
-
- // need the mapping from PHY_IPhysicsController to gameobjects now
-
- KX_ClientObjectInfo *client_info = static_cast<KX_ClientObjectInfo*> (object1 == m_physCtrl?
- ((PHY_IPhysicsController*)object2)->GetNewClientInfo():
- ((PHY_IPhysicsController*)object1)->GetNewClientInfo());
-
- KX_GameObject* gameobj = ( client_info ?
- client_info->m_gameobject :
- NULL);
-
- // add the same check as in SCA_ISensor::Activate(),
- // we don't want to record collision when the sensor is not active.
- if (m_links && !m_suspended &&
- gameobj && (gameobj != parent) && client_info->isActor())
- {
-
- bool found = m_touchedpropname.IsEmpty();
- bool hitMaterial = false;
- if (!found)
- {
- if (m_bFindMaterial) {
- for (unsigned int i = 0; i < gameobj->GetMeshCount(); ++i) {
- RAS_MeshObject *meshObj = gameobj->GetMesh(i);
- for (unsigned int j = 0; j < meshObj->NumMaterials(); ++j) {
- found = strcmp(m_touchedpropname.ReadPtr(), meshObj->GetMaterialName(j).ReadPtr() + 2) == 0;
- if (found) {
- hitMaterial = true;
- break;
- }
- }
- }
- }
- else {
- found = (gameobj->GetProperty(m_touchedpropname) != NULL);
- }
- }
- if (found)
- {
- if (!m_colliders->SearchValue(gameobj)) {
- m_colliders->Add(gameobj->AddRef());
-
- if (m_bTouchPulse)
- m_bColliderHash += (uint_ptr)(static_cast<void *>(&gameobj));
- }
- m_bTriggered = true;
- m_hitObject = gameobj;
- m_hitMaterial = hitMaterial;
- //printf("KX_TouchSensor::HandleCollision\n");
- }
-
- }
- return false; // was DT_CONTINUE but this was defined in sumo as false.
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_TouchSensor::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_TouchSensor",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_ISensor::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_TouchSensor::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_TouchSensor::Attributes[] = {
- KX_PYATTRIBUTE_STRING_RW("propName",0,MAX_PROP_NAME,false,KX_TouchSensor,m_touchedpropname),
- KX_PYATTRIBUTE_BOOL_RW("useMaterial",KX_TouchSensor,m_bFindMaterial),
- KX_PYATTRIBUTE_BOOL_RW("usePulseCollision",KX_TouchSensor,m_bTouchPulse),
- KX_PYATTRIBUTE_STRING_RO("hitMaterial", KX_TouchSensor, m_hitMaterial),
- KX_PYATTRIBUTE_RO_FUNCTION("hitObject", KX_TouchSensor, pyattr_get_object_hit),
- KX_PYATTRIBUTE_RO_FUNCTION("hitObjectList", KX_TouchSensor, pyattr_get_object_hit_list),
- { NULL } //Sentinel
-};
-
-/* Python API */
-
-PyObject *KX_TouchSensor::pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_TouchSensor* self = static_cast<KX_TouchSensor*>(self_v);
-
- if (self->m_hitObject)
- return self->m_hitObject->GetProxy();
- else
- Py_RETURN_NONE;
-}
-
-PyObject *KX_TouchSensor::pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_TouchSensor* self = static_cast<KX_TouchSensor*>(self_v);
- return self->m_colliders->GetProxy();
-}
-
-#endif
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_TouchSensor.h b/source/gameengine/Ketsji/KX_TouchSensor.h
deleted file mode 100644
index e1b5725a32b..00000000000
--- a/source/gameengine/Ketsji/KX_TouchSensor.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_TouchSensor.h
- * \ingroup ketsji
- * \brief Senses touch and collision events
- */
-
-#ifndef __KX_TOUCHSENSOR_H__
-#define __KX_TOUCHSENSOR_H__
-
-#include "SCA_ISensor.h"
-#include "EXP_ListValue.h"
-
-struct PHY_CollData;
-
-#include "KX_ClientObjectInfo.h"
-
-#if defined(_WIN64)
-typedef unsigned __int64 uint_ptr;
-#else
-typedef unsigned long uint_ptr;
-#endif
-
-class KX_TouchEventManager;
-
-class KX_TouchSensor : public SCA_ISensor
-{
-protected:
- Py_Header
-
- /**
- * The sensor should only look for objects with this property.
- */
- STR_String m_touchedpropname;
- bool m_bFindMaterial;
- bool m_bTouchPulse; /* changes in the colliding objects trigger pulses */
-
- class PHY_IPhysicsController* m_physCtrl;
-
- bool m_bCollision;
- bool m_bTriggered;
- bool m_bLastTriggered;
-
- // Use with m_bTouchPulse to detect changes
- int m_bLastCount; /* size of m_colliders last tick */
- uint_ptr m_bColliderHash; /* hash collision objects pointers to trigger in case one object collides and another takes its place */
- uint_ptr m_bLastColliderHash;
-
- SCA_IObject* m_hitObject;
- class CListValue* m_colliders;
- STR_String m_hitMaterial;
-
-public:
- KX_TouchSensor(class SCA_EventManager* eventmgr,
- class KX_GameObject* gameobj,
- bool bFindMaterial,
- bool bTouchPulse,
- const STR_String& touchedpropname);
- virtual ~KX_TouchSensor();
-
- virtual CValue* GetReplica();
- virtual void ProcessReplica();
- virtual void SynchronizeTransform();
- virtual bool Evaluate();
- virtual void Init();
- virtual void ReParent(SCA_IObject* parent);
-
- virtual void RegisterSumo(KX_TouchEventManager* touchman);
- virtual void UnregisterSumo(KX_TouchEventManager* touchman);
- virtual void UnregisterToManager();
-
-#if 0
- virtual DT_Bool HandleCollision(void* obj1,void* obj2,
- const DT_CollData * coll_data);
-#endif
-
- virtual bool NewHandleCollision(void*obj1,void*obj2,const PHY_CollData* colldata);
-
- // Allows to do pre-filtering and save computation time
- // obj1 = sensor physical controller, obj2 = physical controller of second object
- // return value = true if collision should be checked on pair of object
- virtual bool BroadPhaseFilterCollision(void*obj1,void*obj2) { return true; }
- virtual bool BroadPhaseSensorFilterCollision(void*obj1,void*obj2);
- virtual sensortype GetSensorType() { return ST_TOUCH; }
-
-
- virtual bool IsPositiveTrigger() {
- bool result = m_bTriggered;
- if (m_invert) result = !result;
- return result;
- }
-
- virtual void EndFrame();
-
- class PHY_IPhysicsController* GetPhysicsController() { return m_physCtrl; }
-
-
- // todo: put some info for collision maybe
-
-#ifdef WITH_PYTHON
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
- static PyObject* pyattr_get_object_hit(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject* pyattr_get_object_hit_list(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
-
-#endif
-
-};
-
-#endif /* __KX_TOUCHSENSOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.cpp b/source/gameengine/Ketsji/KX_TrackToActuator.cpp
deleted file mode 100644
index a8fa9b0815d..00000000000
--- a/source/gameengine/Ketsji/KX_TrackToActuator.cpp
+++ /dev/null
@@ -1,430 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_TrackToActuator.cpp
- * \ingroup ketsji
- *
- * Replace the mesh for this actuator's parent
- */
-
-/* m_trackflag is used to determine the forward tracking direction
- * m_upflag for the up direction
- * normal situation is +y for forward, +z for up */
-
-#include "MT_Scalar.h"
-#include "SCA_IActuator.h"
-#include "KX_TrackToActuator.h"
-#include "SCA_IScene.h"
-#include "SCA_LogicManager.h"
-#include <math.h>
-#include <iostream>
-#include "KX_GameObject.h"
-
-#include "EXP_PyObjectPlus.h"
-
-/* ------------------------------------------------------------------------- */
-/* Native functions */
-/* ------------------------------------------------------------------------- */
-
-KX_TrackToActuator::KX_TrackToActuator(SCA_IObject *gameobj,
- SCA_IObject *ob,
- int time,
- bool allow3D,
- int trackflag,
- int upflag)
- : SCA_IActuator(gameobj, KX_ACT_TRACKTO)
-{
- m_time = time;
- m_allow3D = allow3D;
- m_object = ob;
- m_trackflag = trackflag;
- m_upflag = upflag;
- m_parentobj = 0;
-
- if (m_object)
- m_object->RegisterActuator(this);
-
- {
- // if the object is vertex parented, don't check parent orientation as the link is broken
- if (!((KX_GameObject*)gameobj)->IsVertexParent()) {
- m_parentobj = ((KX_GameObject*)gameobj)->GetParent(); // check if the object is parented
- if (m_parentobj) {
- // if so, store the initial local rotation
- // this is needed to revert the effect of the parent inverse node (TBC)
- m_parentlocalmat = m_parentobj->GetSGNode()->GetLocalOrientation();
- // use registration mechanism rather than AddRef, it creates zombie objects
- m_parentobj->RegisterActuator(this);
- }
- }
- }
-
-} /* End of constructor */
-
-
-
-/* old function from Blender */
-static MT_Matrix3x3 EulToMat3(float eul[3])
-{
- MT_Matrix3x3 mat;
- float ci, cj, ch, si, sj, sh, cc, cs, sc, ss;
-
- ci = cosf(eul[0]);
- cj = cosf(eul[1]);
- ch = cosf(eul[2]);
- si = sinf(eul[0]);
- sj = sinf(eul[1]);
- sh = sinf(eul[2]);
- cc = ci*ch;
- cs = ci*sh;
- sc = si*ch;
- ss = si*sh;
-
- mat[0][0] = cj*ch;
- mat[1][0] = sj*sc-cs;
- mat[2][0] = sj*cc+ss;
- mat[0][1] = cj*sh;
- mat[1][1] = sj*ss+cc;
- mat[2][1] = sj*cs-sc;
- mat[0][2] = -sj;
- mat[1][2] = cj*si;
- mat[2][2] = cj*ci;
-
- return mat;
-}
-
-
-
-/* old function from Blender */
-static void Mat3ToEulOld(MT_Matrix3x3 mat, float eul[3])
-{
- const float cy = sqrtf(mat[0][0] * mat[0][0] + mat[0][1] * mat[0][1]);
-
- if (cy > (float)(16.0f * FLT_EPSILON)) {
- eul[0] = atan2f( mat[1][2], mat[2][2]);
- eul[1] = atan2f(-mat[0][2], cy);
- eul[2] = atan2f( mat[0][1], mat[0][0]);
- }
- else {
- eul[0] = atan2f(-mat[2][1], mat[1][1]);
- eul[1] = atan2f(-mat[0][2], cy);
- eul[2] = 0.0f;
- }
-}
-
-
-
-/* old function from Blender */
-static void compatible_eulFast(float *eul, float *oldrot)
-{
- float dx, dy, dz;
-
- /* angular difference of 360 degrees */
-
- dx = eul[0] - oldrot[0];
- dy = eul[1] - oldrot[1];
- dz = eul[2] - oldrot[2];
-
- if (fabsf(dx) > (float)MT_PI) {
- if (dx > 0.0f) eul[0] -= (float)MT_2_PI; else eul[0] += (float)MT_2_PI;
- }
- if (fabsf(dy) > (float)MT_PI) {
- if (dy > 0.0f) eul[1] -= (float)MT_2_PI; else eul[1] += (float)MT_2_PI;
- }
- if (fabsf(dz) > (float)MT_PI) {
- if (dz > 0.0f) eul[2] -= (float)MT_2_PI; else eul[2] += (float)MT_2_PI;
- }
-}
-
-
-
-static MT_Matrix3x3 matrix3x3_interpol(MT_Matrix3x3 oldmat, MT_Matrix3x3 mat, int m_time)
-{
- float eul[3], oldeul[3];
-
- Mat3ToEulOld(oldmat, oldeul);
- Mat3ToEulOld(mat, eul);
- compatible_eulFast(eul, oldeul);
-
- eul[0] = (m_time * oldeul[0] + eul[0]) / (1.0f + m_time);
- eul[1] = (m_time * oldeul[1] + eul[1]) / (1.0f + m_time);
- eul[2] = (m_time * oldeul[2] + eul[2]) / (1.0f + m_time);
-
- return EulToMat3(eul);
-}
-
-static float basis_cross(int n, int m)
-{
- switch (n - m) {
- case 1:
- case -2:
- return 1.0f;
-
- case -1:
- case 2:
- return -1.0f;
-
- default:
- return 0.0f;
- }
-}
-
-/* vectomat function obtained from constrain.c and modified to work with MOTO library */
-static MT_Matrix3x3 vectomat(MT_Vector3 vec, short axis, short upflag, short threedimup)
-{
- MT_Matrix3x3 mat;
- MT_Vector3 y(MT_Scalar(0.0f), MT_Scalar(1.0f), MT_Scalar(0.0f));
- MT_Vector3 z(MT_Scalar(0.0f), MT_Scalar(0.0f), MT_Scalar(1.0f)); /* world Z axis is the global up axis */
- MT_Vector3 proj;
- MT_Vector3 right;
- MT_Scalar mul;
- int right_index;
-
- /* Normalized Vec vector*/
- vec = vec.safe_normalized_vec(z);
-
- /* if 2D doesn't move the up vector */
- if (!threedimup) {
- vec.setValue(MT_Scalar(vec[0]), MT_Scalar(vec[1]), MT_Scalar(0.0f));
- vec = (vec - z.dot(vec)*z).safe_normalized_vec(z);
- }
-
- if (axis > 2)
- axis -= 3;
- else
- vec = -vec;
-
- /* project the up vector onto the plane specified by vec */
- /* first z onto vec... */
- mul = z.dot(vec) / vec.dot(vec);
- proj = vec * mul;
- /* then onto the plane */
- proj = z - proj;
- /* proj specifies the transformation of the up axis */
- proj = proj.safe_normalized_vec(y);
-
- /* Normalized cross product of vec and proj specifies transformation of the right axis */
- right = proj.cross(vec);
- right.normalize();
-
- if (axis != upflag) {
- right_index = 3 - axis - upflag;
-
- /* account for up direction, track direction */
- right = right * basis_cross(axis, upflag);
- mat.setRow(right_index, right);
- mat.setRow(upflag, proj);
- mat.setRow(axis, vec);
- mat = mat.inverse();
- }
- /* identity matrix - don't do anything if the two axes are the same */
- else {
- mat.setIdentity();
- }
-
- return mat;
-}
-
-KX_TrackToActuator::~KX_TrackToActuator()
-{
- if (m_object)
- m_object->UnregisterActuator(this);
- if (m_parentobj)
- m_parentobj->UnregisterActuator(this);
-} /* end of destructor */
-
-void KX_TrackToActuator::ProcessReplica()
-{
- // the replica is tracking the same object => register it
- if (m_object)
- m_object->RegisterActuator(this);
- if (m_parentobj)
- m_parentobj->RegisterActuator(this);
- SCA_IActuator::ProcessReplica();
-}
-
-
-bool KX_TrackToActuator::UnlinkObject(SCA_IObject* clientobj)
-{
- if (clientobj == m_object)
- {
- // this object is being deleted, we cannot continue to track it.
- m_object = NULL;
- return true;
- }
- if (clientobj == m_parentobj)
- {
- m_parentobj = NULL;
- return true;
- }
- return false;
-}
-
-void KX_TrackToActuator::Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map)
-{
- void **h_obj = (*obj_map)[m_object];
- if (h_obj) {
- if (m_object)
- m_object->UnregisterActuator(this);
- m_object = (SCA_IObject*)(*h_obj);
- m_object->RegisterActuator(this);
- }
-
- void **h_parobj = (*obj_map)[m_parentobj];
- if (h_parobj) {
- if (m_parentobj)
- m_parentobj->UnregisterActuator(this);
- m_parentobj= (KX_GameObject*)(*h_parobj);
- m_parentobj->RegisterActuator(this);
- }
-}
-
-
-bool KX_TrackToActuator::Update(double curtime, bool frame)
-{
- bool result = false;
- bool bNegativeEvent = IsNegativeEvent();
- RemoveAllEvents();
-
- if (bNegativeEvent)
- {
- // do nothing on negative events
- }
- else if (m_object)
- {
- KX_GameObject* curobj = (KX_GameObject*) GetParent();
- MT_Vector3 dir = curobj->NodeGetWorldPosition() - ((KX_GameObject*)m_object)->NodeGetWorldPosition();
- MT_Matrix3x3 mat;
- MT_Matrix3x3 oldmat;
-
- mat = vectomat(dir, m_trackflag, m_upflag, m_allow3D);
- oldmat = curobj->NodeGetWorldOrientation();
-
- /* erwin should rewrite this! */
- mat = matrix3x3_interpol(oldmat, mat, m_time);
-
- /* check if the model is parented and calculate the child transform */
- if (m_parentobj) {
-
- MT_Point3 localpos;
- localpos = curobj->GetSGNode()->GetLocalPosition();
- // Get the inverse of the parent matrix
- MT_Matrix3x3 parentmatinv;
- parentmatinv = m_parentobj->NodeGetWorldOrientation().inverse();
- // transform the local coordinate system into the parents system
- mat = parentmatinv * mat;
- // append the initial parent local rotation matrix
- mat = m_parentlocalmat * mat;
-
- // set the models tranformation properties
- curobj->NodeSetLocalOrientation(mat);
- curobj->NodeSetLocalPosition(localpos);
- //curobj->UpdateTransform();
- }
- else {
- curobj->NodeSetLocalOrientation(mat);
- }
-
- result = true;
- }
-
- return result;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_TrackToActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_TrackToActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_TrackToActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_TrackToActuator::Attributes[] = {
- KX_PYATTRIBUTE_INT_RW("time",0,1000,true,KX_TrackToActuator,m_time),
- KX_PYATTRIBUTE_BOOL_RW("use3D",KX_TrackToActuator,m_allow3D),
- KX_PYATTRIBUTE_INT_RW("upAxis", 0, 2, true, KX_TrackToActuator,m_upflag),
- KX_PYATTRIBUTE_INT_RW("trackAxis", 0, 5, true, KX_TrackToActuator,m_trackflag),
- KX_PYATTRIBUTE_RW_FUNCTION("object", KX_TrackToActuator, pyattr_get_object, pyattr_set_object),
-
- { NULL } //Sentinel
-};
-
-PyObject *KX_TrackToActuator::pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self);
- if (!actuator->m_object)
- Py_RETURN_NONE;
- else
- return actuator->m_object->GetProxy();
-}
-
-int KX_TrackToActuator::pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_TrackToActuator* actuator = static_cast<KX_TrackToActuator*>(self);
- KX_GameObject *gameobj;
-
- if (!ConvertPythonToGameObject(actuator->GetLogicManager(), value, &gameobj, true, "actuator.object = value: KX_TrackToActuator"))
- return PY_SET_ATTR_FAIL; // ConvertPythonToGameObject sets the error
-
- if (actuator->m_object != NULL)
- actuator->m_object->UnregisterActuator(actuator);
-
- actuator->m_object = (SCA_IObject*) gameobj;
-
- if (actuator->m_object)
- actuator->m_object->RegisterActuator(actuator);
-
- return PY_SET_ATTR_SUCCESS;
-}
-
-#endif // WITH_PYTHON
-
-/* eof */
diff --git a/source/gameengine/Ketsji/KX_TrackToActuator.h b/source/gameengine/Ketsji/KX_TrackToActuator.h
deleted file mode 100644
index 124014eede2..00000000000
--- a/source/gameengine/Ketsji/KX_TrackToActuator.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_TrackToActuator.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_TRACKTOACTUATOR_H__
-#define __KX_TRACKTOACTUATOR_H__
-
-#include "SCA_IActuator.h"
-#include "SCA_IObject.h"
-#include "MT_Matrix3x3.h"
-#include "KX_GameObject.h"
-
-
-class KX_TrackToActuator : public SCA_IActuator
-{
- Py_Header
- // Object reference. Actually, we use the object's 'life'
- SCA_IObject* m_object;
- // 3d toggle
- bool m_allow3D;
- // time field
- int m_time;
- int m_trackflag;
- int m_upflag;
-
- MT_Matrix3x3 m_parentlocalmat;
- KX_GameObject* m_parentobj;
-
- public:
- KX_TrackToActuator(SCA_IObject* gameobj, SCA_IObject *ob, int time,
- bool threedee,int trackflag,int upflag);
- virtual ~KX_TrackToActuator();
- virtual CValue* GetReplica() {
- KX_TrackToActuator* replica = new KX_TrackToActuator(*this);
- replica->ProcessReplica();
- return replica;
- };
-
- virtual void ProcessReplica();
- virtual bool UnlinkObject(SCA_IObject* clientobj);
- virtual void Relink(CTR_Map<CTR_HashedPtr, void*> *obj_map);
- virtual bool Update(double curtime, bool frame);
-
- //Python Interface
- enum UpAxis {
- KX_TRACK_UPAXIS_POS_X = 0,
- KX_TRACK_UPAXIS_POS_Y,
- KX_TRACK_UPAXIS_POS_Z
- };
- enum TrackAxis {
- KX_TRACK_TRAXIS_POS_X = 0,
- KX_TRACK_TRAXIS_POS_Y,
- KX_TRACK_TRAXIS_POS_Z,
- KX_TRACK_TRAXIS_NEG_X,
- KX_TRACK_TRAXIS_NEG_Y,
- KX_TRACK_TRAXIS_NEG_Z
- };
-
-#ifdef WITH_PYTHON
-
- /* Python part */
-
- /* These are used to get and set m_ob */
- static PyObject *pyattr_get_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_object(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
-#endif /* WITH_PYTHON */
-
-}; /* end of class KX_TrackToActuator : public KX_EditObjectActuator */
-
-#endif /* __KX_TRACKTOACTUATOR_H__ */
diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp b/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
deleted file mode 100644
index ddae645802c..00000000000
--- a/source/gameengine/Ketsji/KX_VehicleWrapper.cpp
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_VehicleWrapper.cpp
- * \ingroup ketsji
- */
-
-#include "EXP_PyObjectPlus.h"
-
-#include "KX_VehicleWrapper.h"
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IVehicle.h"
-#include "KX_PyMath.h"
-#include "KX_GameObject.h"
-#include "KX_MotionState.h"
-#include "KX_PythonInit.h"
-
-KX_VehicleWrapper::KX_VehicleWrapper(
- PHY_IVehicle* vehicle,
- PHY_IPhysicsEnvironment* physenv) :
- PyObjectPlus(),
- m_vehicle(vehicle),
- m_physenv(physenv)
-{
-}
-
-KX_VehicleWrapper::~KX_VehicleWrapper()
-{
- int numMotion = m_motionStates.size();
- for (int i=0;i<numMotion;i++)
- {
- PHY_IMotionState* motionState = m_motionStates[i];
- delete motionState;
- }
- m_motionStates.clear();
-}
-
-#ifdef WITH_PYTHON
-
-
-static bool raise_exc_wheel(PHY_IVehicle *vehicle, int i, const char *method)
-{
- if (i < 0 || i >= vehicle->GetNumWheels()) {
- PyErr_Format(PyExc_ValueError,
- "%s(...): wheel index %d out of range (0 to %d).", method, i, vehicle->GetNumWheels() - 1);
- return true;
- }
- else {
- return false;
- }
-}
-
-#define WHEEL_INDEX_CHECK_OR_RETURN(i, method) \
- if (raise_exc_wheel(m_vehicle, i, method)) {return NULL;} (void)0
-
-
-PyObject *KX_VehicleWrapper::PyAddWheel(PyObject *args)
-{
-
- PyObject *pylistPos,*pylistDir,*pylistAxleDir;
- PyObject *wheelGameObject;
- float suspensionRestLength,wheelRadius;
- int hasSteering;
-
-
- if (PyArg_ParseTuple(args,"OOOOffi:addWheel",&wheelGameObject,&pylistPos,&pylistDir,&pylistAxleDir,&suspensionRestLength,&wheelRadius,&hasSteering))
- {
- KX_GameObject *gameOb;
- if (!ConvertPythonToGameObject(KX_GetActiveScene()->GetLogicManager(), wheelGameObject, &gameOb, false, "vehicle.addWheel(...): KX_VehicleWrapper (first argument)"))
- return NULL;
-
- if (gameOb->GetSGNode())
- {
- MT_Vector3 attachPos,attachDir,attachAxle;
- if (!PyVecTo(pylistPos,attachPos)) {
- PyErr_SetString(PyExc_AttributeError,
- "addWheel(...) Unable to add wheel. attachPos must be a vector with 3 elements.");
- return NULL;
- }
- if (!PyVecTo(pylistDir,attachDir)) {
- PyErr_SetString(PyExc_AttributeError,
- "addWheel(...) Unable to add wheel. downDir must be a vector with 3 elements.");
- return NULL;
- }
- if (!PyVecTo(pylistAxleDir,attachAxle)) {
- PyErr_SetString(PyExc_AttributeError,
- "addWheel(...) Unable to add wheel. axleDir must be a vector with 3 elements.");
- return NULL;
- }
-
- //someone reverse some conventions inside Bullet (axle winding)
- attachAxle = -attachAxle;
-
- if (wheelRadius <= 0) {
- PyErr_SetString(PyExc_AttributeError,
- "addWheel(...) Unable to add wheel. wheelRadius must be positive.");
- return NULL;
- }
-
- PHY_IMotionState *motionState = new KX_MotionState(gameOb->GetSGNode());
- m_vehicle->AddWheel(motionState,attachPos,attachDir,attachAxle,suspensionRestLength,wheelRadius,hasSteering);
- }
-
- } else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_VehicleWrapper::PyGetWheelPosition(PyObject *args)
-{
-
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"i:getWheelPosition",&wheelIndex))
- {
- float position[3];
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "getWheelPosition");
-
- m_vehicle->GetWheelPosition(wheelIndex,position[0],position[1],position[2]);
- MT_Vector3 pos(position[0],position[1],position[2]);
- return PyObjectFrom(pos);
- }
- return NULL;
-}
-
-PyObject *KX_VehicleWrapper::PyGetWheelRotation(PyObject *args)
-{
- int wheelIndex;
- if (PyArg_ParseTuple(args,"i:getWheelRotation",&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "getWheelRotation");
-
- return PyFloat_FromDouble(m_vehicle->GetWheelRotation(wheelIndex));
- }
- return NULL;
-}
-
-PyObject *KX_VehicleWrapper::PyGetWheelOrientationQuaternion(PyObject *args)
-{
- int wheelIndex;
- if (PyArg_ParseTuple(args,"i:getWheelOrientationQuaternion",&wheelIndex))
- {
- float orn[4];
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "getWheelOrientationQuaternion");
-
- m_vehicle->GetWheelOrientationQuaternion(wheelIndex,orn[0],orn[1],orn[2],orn[3]);
- MT_Quaternion quatorn(orn[0],orn[1],orn[2],orn[3]);
- MT_Matrix3x3 ornmat(quatorn);
- return PyObjectFrom(ornmat);
- }
- return NULL;
-
-}
-
-
-PyObject *KX_VehicleWrapper::PyGetNumWheels(PyObject *args)
-{
- return PyLong_FromLong(m_vehicle->GetNumWheels());
-}
-
-
-PyObject *KX_VehicleWrapper::PyGetConstraintId(PyObject *args)
-{
- return PyLong_FromLong(m_vehicle->GetUserConstraintId());
-}
-
-
-PyObject *KX_VehicleWrapper::PyApplyEngineForce(PyObject *args)
-{
- float force;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:applyEngineForce",&force,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "applyEngineForce");
-
- force *= -1.f;//someone reverse some conventions inside Bullet (axle winding)
- m_vehicle->ApplyEngineForce(force,wheelIndex);
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_VehicleWrapper::PySetTyreFriction(PyObject *args)
-{
- float wheelFriction;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:setTyreFriction",&wheelFriction,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "setTyreFriction");
-
- m_vehicle->SetWheelFriction(wheelFriction,wheelIndex);
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_VehicleWrapper::PySetSuspensionStiffness(PyObject *args)
-{
- float suspensionStiffness;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:setSuspensionStiffness",&suspensionStiffness,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "setSuspensionStiffness");
-
- m_vehicle->SetSuspensionStiffness(suspensionStiffness,wheelIndex);
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_VehicleWrapper::PySetSuspensionDamping(PyObject *args)
-{
- float suspensionDamping;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:setSuspensionDamping",&suspensionDamping,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "setSuspensionDamping");
-
- m_vehicle->SetSuspensionDamping(suspensionDamping,wheelIndex);
- } else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_VehicleWrapper::PySetSuspensionCompression(PyObject *args)
-{
- float suspensionCompression;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:setSuspensionCompression",&suspensionCompression,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "setSuspensionCompression");
-
- m_vehicle->SetSuspensionCompression(suspensionCompression,wheelIndex);
- } else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-PyObject *KX_VehicleWrapper::PySetRollInfluence(PyObject *args)
-{
- float rollInfluence;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:setRollInfluence",&rollInfluence,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "setRollInfluence");
-
- m_vehicle->SetRollInfluence(rollInfluence,wheelIndex);
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_VehicleWrapper::PyApplyBraking(PyObject *args)
-{
- float braking;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:applyBraking",&braking,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "applyBraking");
-
- m_vehicle->ApplyBraking(braking,wheelIndex);
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_VehicleWrapper::PySetSteeringValue(PyObject *args)
-{
- float steeringValue;
- int wheelIndex;
-
- if (PyArg_ParseTuple(args,"fi:setSteeringValue",&steeringValue,&wheelIndex))
- {
- WHEEL_INDEX_CHECK_OR_RETURN(wheelIndex, "setSteeringValue");
-
- m_vehicle->SetSteeringValue(steeringValue,wheelIndex);
- }
- else {
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_VehicleWrapper::PyGetConstraintType(PyObject *args)
-{
- return PyLong_FromLong(m_vehicle->GetUserConstraintType());
-}
-
-
-
-
-
-//python specific stuff
-PyTypeObject KX_VehicleWrapper::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_VehicleWrapper",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_VehicleWrapper::Methods[] = {
- {"addWheel",(PyCFunction) KX_VehicleWrapper::sPyAddWheel, METH_VARARGS},
- {"getNumWheels",(PyCFunction) KX_VehicleWrapper::sPyGetNumWheels, METH_VARARGS},
- {"getWheelOrientationQuaternion",(PyCFunction) KX_VehicleWrapper::sPyGetWheelOrientationQuaternion, METH_VARARGS},
- {"getWheelRotation",(PyCFunction) KX_VehicleWrapper::sPyGetWheelRotation, METH_VARARGS},
- {"getWheelPosition",(PyCFunction) KX_VehicleWrapper::sPyGetWheelPosition, METH_VARARGS},
- {"getConstraintId",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintId, METH_VARARGS},
- {"getConstraintType",(PyCFunction) KX_VehicleWrapper::sPyGetConstraintType, METH_VARARGS},
- {"setSteeringValue",(PyCFunction) KX_VehicleWrapper::sPySetSteeringValue, METH_VARARGS},
- {"applyEngineForce",(PyCFunction) KX_VehicleWrapper::sPyApplyEngineForce, METH_VARARGS},
- {"applyBraking",(PyCFunction) KX_VehicleWrapper::sPyApplyBraking, METH_VARARGS},
- {"setTyreFriction",(PyCFunction) KX_VehicleWrapper::sPySetTyreFriction, METH_VARARGS},
- {"setSuspensionStiffness",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionStiffness, METH_VARARGS},
- {"setSuspensionDamping",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionDamping, METH_VARARGS},
- {"setSuspensionCompression",(PyCFunction) KX_VehicleWrapper::sPySetSuspensionCompression, METH_VARARGS},
- {"setRollInfluence",(PyCFunction) KX_VehicleWrapper::sPySetRollInfluence, METH_VARARGS},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_VehicleWrapper::Attributes[] = {
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_VehicleWrapper.h b/source/gameengine/Ketsji/KX_VehicleWrapper.h
deleted file mode 100644
index 22b9591f48b..00000000000
--- a/source/gameengine/Ketsji/KX_VehicleWrapper.h
+++ /dev/null
@@ -1,61 +0,0 @@
-
-/** \file KX_VehicleWrapper.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_VEHICLEWRAPPER_H__
-#define __KX_VEHICLEWRAPPER_H__
-
-#include "EXP_Value.h"
-class PHY_IVehicle;
-class PHY_IMotionState;
-
-#include <vector>
-
-///Python interface to physics vehicles (primarily 4-wheel cars and 2wheel bikes)
-class KX_VehicleWrapper : public PyObjectPlus
-{
- Py_Header
-
- std::vector<PHY_IMotionState*> m_motionStates;
-
-public:
- KX_VehicleWrapper(PHY_IVehicle* vehicle,class PHY_IPhysicsEnvironment* physenv);
- virtual ~KX_VehicleWrapper ();
- int getConstraintId();
-
-#ifdef WITH_PYTHON
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,AddWheel);
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetNumWheels);
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetWheelOrientationQuaternion);
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetWheelRotation);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetWheelPosition);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetConstraintId);
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,GetConstraintType);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSteeringValue);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,ApplyEngineForce);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,ApplyBraking);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetTyreFriction);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSuspensionStiffness);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSuspensionDamping);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetSuspensionCompression);
-
- KX_PYMETHOD_VARARGS(KX_VehicleWrapper,SetRollInfluence);
-#endif /* WITH_PYTHON */
-
-private:
- PHY_IVehicle* m_vehicle;
- PHY_IPhysicsEnvironment* m_physenv;
-};
-
-#endif /* __KX_VEHICLEWRAPPER_H__ */
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.cpp b/source/gameengine/Ketsji/KX_VertexProxy.cpp
deleted file mode 100644
index 40f4c462801..00000000000
--- a/source/gameengine/Ketsji/KX_VertexProxy.cpp
+++ /dev/null
@@ -1,595 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_VertexProxy.cpp
- * \ingroup ketsji
- */
-
-
-#ifdef WITH_PYTHON
-
-#include "KX_VertexProxy.h"
-#include "KX_MeshProxy.h"
-#include "RAS_TexVert.h"
-
-#include "KX_PyMath.h"
-
-PyTypeObject KX_VertexProxy::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_VertexProxy",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &CValue::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_VertexProxy::Methods[] = {
- {"getXYZ", (PyCFunction)KX_VertexProxy::sPyGetXYZ,METH_NOARGS},
- {"setXYZ", (PyCFunction)KX_VertexProxy::sPySetXYZ,METH_O},
- {"getUV", (PyCFunction)KX_VertexProxy::sPyGetUV1, METH_NOARGS},
- {"setUV", (PyCFunction)KX_VertexProxy::sPySetUV1, METH_O},
-
- {"getUV2", (PyCFunction)KX_VertexProxy::sPyGetUV2,METH_NOARGS},
- {"setUV2", (PyCFunction)KX_VertexProxy::sPySetUV2,METH_VARARGS},
-
- {"getRGBA", (PyCFunction)KX_VertexProxy::sPyGetRGBA,METH_NOARGS},
- {"setRGBA", (PyCFunction)KX_VertexProxy::sPySetRGBA,METH_O},
- {"getNormal", (PyCFunction)KX_VertexProxy::sPyGetNormal,METH_NOARGS},
- {"setNormal", (PyCFunction)KX_VertexProxy::sPySetNormal,METH_O},
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_VertexProxy::Attributes[] = {
- KX_PYATTRIBUTE_RW_FUNCTION("x", KX_VertexProxy, pyattr_get_x, pyattr_set_x),
- KX_PYATTRIBUTE_RW_FUNCTION("y", KX_VertexProxy, pyattr_get_y, pyattr_set_y),
- KX_PYATTRIBUTE_RW_FUNCTION("z", KX_VertexProxy, pyattr_get_z, pyattr_set_z),
-
- KX_PYATTRIBUTE_RW_FUNCTION("r", KX_VertexProxy, pyattr_get_r, pyattr_set_r),
- KX_PYATTRIBUTE_RW_FUNCTION("g", KX_VertexProxy, pyattr_get_g, pyattr_set_g),
- KX_PYATTRIBUTE_RW_FUNCTION("b", KX_VertexProxy, pyattr_get_b, pyattr_set_b),
- KX_PYATTRIBUTE_RW_FUNCTION("a", KX_VertexProxy, pyattr_get_a, pyattr_set_a),
-
- KX_PYATTRIBUTE_RW_FUNCTION("u", KX_VertexProxy, pyattr_get_u, pyattr_set_u),
- KX_PYATTRIBUTE_RW_FUNCTION("v", KX_VertexProxy, pyattr_get_v, pyattr_set_v),
-
- KX_PYATTRIBUTE_RW_FUNCTION("u2", KX_VertexProxy, pyattr_get_u2, pyattr_set_u2),
- KX_PYATTRIBUTE_RW_FUNCTION("v2", KX_VertexProxy, pyattr_get_v2, pyattr_set_v2),
-
- KX_PYATTRIBUTE_RW_FUNCTION("XYZ", KX_VertexProxy, pyattr_get_XYZ, pyattr_set_XYZ),
- KX_PYATTRIBUTE_RW_FUNCTION("UV", KX_VertexProxy, pyattr_get_UV, pyattr_set_UV),
- KX_PYATTRIBUTE_RW_FUNCTION("uvs", KX_VertexProxy, pyattr_get_uvs, pyattr_set_uvs),
-
- KX_PYATTRIBUTE_RW_FUNCTION("color", KX_VertexProxy, pyattr_get_color, pyattr_set_color),
- KX_PYATTRIBUTE_RW_FUNCTION("normal", KX_VertexProxy, pyattr_get_normal, pyattr_set_normal),
-
- { NULL } //Sentinel
-};
-
-PyObject *KX_VertexProxy::pyattr_get_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getXYZ()[0]);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getXYZ()[1]);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_z(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getXYZ()[2]);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_r(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getRGBA()[0]/255.0);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_g(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getRGBA()[1]/255.0);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_b(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getRGBA()[2]/255.0);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_a(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getRGBA()[3]/255.0);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_u(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getUV(0)[0]);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_v(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getUV(0)[1]);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_u2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getUV(1)[0]);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyFloat_FromDouble(self->m_vertex->getUV(1)[1]);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_XYZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyObjectFrom(MT_Vector3(self->m_vertex->getXYZ()));
-}
-
-PyObject *KX_VertexProxy::pyattr_get_UV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyObjectFrom(MT_Point2(self->m_vertex->getUV(0)));
-}
-
-PyObject *KX_VertexProxy::pyattr_get_uvs(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
-
- PyObject* uvlist = PyList_New(RAS_TexVert::MAX_UNIT);
- for (int i=0; i<RAS_TexVert::MAX_UNIT; ++i)
- {
- PyList_SET_ITEM(uvlist, i, PyObjectFrom(MT_Point2(self->m_vertex->getUV(i))));
- }
-
- return uvlist;
-}
-
-PyObject *KX_VertexProxy::pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- const unsigned char *colp = self->m_vertex->getRGBA();
- MT_Vector4 color(colp[0], colp[1], colp[2], colp[3]);
- color /= 255.0f;
- return PyObjectFrom(color);
-}
-
-PyObject *KX_VertexProxy::pyattr_get_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- return PyObjectFrom(MT_Vector3(self->m_vertex->getNormal()));
-}
-
-int KX_VertexProxy::pyattr_set_x(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- MT_Point3 pos(self->m_vertex->getXYZ());
- pos.x() = val;
- self->m_vertex->SetXYZ(pos);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_y(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- MT_Point3 pos(self->m_vertex->getXYZ());
- pos.y() = val;
- self->m_vertex->SetXYZ(pos);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_z(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- MT_Point3 pos(self->m_vertex->getXYZ());
- pos.z() = val;
- self->m_vertex->SetXYZ(pos);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_u(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- MT_Point2 uv = self->m_vertex->getUV(0);
- uv[0] = val;
- self->m_vertex->SetUV(0, uv);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_v(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- MT_Point2 uv = self->m_vertex->getUV(0);
- uv[1] = val;
- self->m_vertex->SetUV(0, uv);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_u2(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- MT_Point2 uv = self->m_vertex->getUV(1);
- uv[0] = val;
- self->m_vertex->SetUV(1, uv);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_v2(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- MT_Point2 uv = self->m_vertex->getUV(1);
- uv[1] = val;
- self->m_vertex->SetUV(1, uv);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_r(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
- unsigned char *cp = (unsigned char*) &icol;
- val *= 255.0f;
- cp[0] = (unsigned char) val;
- self->m_vertex->SetRGBA(icol);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_g(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
- unsigned char *cp = (unsigned char*) &icol;
- val *= 255.0f;
- cp[1] = (unsigned char) val;
- self->m_vertex->SetRGBA(icol);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_b(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
- unsigned char *cp = (unsigned char*) &icol;
- val *= 255.0f;
- cp[2] = (unsigned char) val;
- self->m_vertex->SetRGBA(icol);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_a(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PyFloat_Check(value))
- {
- float val = PyFloat_AsDouble(value);
- unsigned int icol = *((const unsigned int *)self->m_vertex->getRGBA());
- unsigned char *cp = (unsigned char*) &icol;
- val *= 255.0f;
- cp[3] = (unsigned char) val;
- self->m_vertex->SetRGBA(icol);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_XYZ(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PySequence_Check(value))
- {
- MT_Point3 vec;
- if (PyVecTo(value, vec))
- {
- self->m_vertex->SetXYZ(vec);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_UV(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PySequence_Check(value))
- {
- MT_Point2 vec;
- if (PyVecTo(value, vec)) {
- self->m_vertex->SetUV(0, vec);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_uvs(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self= static_cast<KX_VertexProxy*>(self_v);
- if (PySequence_Check(value))
- {
- MT_Point2 vec;
- for (int i=0; i<PySequence_Size(value) && i<RAS_TexVert::MAX_UNIT; ++i)
- {
- if (PyVecTo(PySequence_GetItem(value, i), vec))
- {
- self->m_vertex->SetUV(i, vec);
- self->m_mesh->SetMeshModified(true);
- }
- else
- {
- PyErr_SetString(PyExc_AttributeError, STR_String().Format("list[%d] was not a vector", i).ReadPtr());
- return PY_SET_ATTR_FAIL;
- }
- }
-
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_color(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PySequence_Check(value))
- {
- MT_Vector4 vec;
- if (PyVecTo(value, vec))
- {
- self->m_vertex->SetRGBA(vec);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- }
- return PY_SET_ATTR_FAIL;
-}
-
-int KX_VertexProxy::pyattr_set_normal(void *self_v, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_VertexProxy* self = static_cast<KX_VertexProxy*>(self_v);
- if (PySequence_Check(value))
- {
- MT_Vector3 vec;
- if (PyVecTo(value, vec))
- {
- self->m_vertex->SetNormal(vec);
- self->m_mesh->SetMeshModified(true);
- return PY_SET_ATTR_SUCCESS;
- }
- }
- return PY_SET_ATTR_FAIL;
-}
-
-KX_VertexProxy::KX_VertexProxy(KX_MeshProxy*mesh, RAS_TexVert* vertex)
-: m_vertex(vertex),
- m_mesh(mesh)
-{
- /* see bug [#27071] */
- Py_INCREF(m_mesh->GetProxy());
-}
-
-KX_VertexProxy::~KX_VertexProxy()
-{
- /* see bug [#27071] */
- Py_DECREF(m_mesh->GetProxy());
-}
-
-
-
-// stuff for cvalue related things
-CValue* KX_VertexProxy::Calc(VALUE_OPERATOR, CValue *) { return NULL;}
-CValue* KX_VertexProxy::CalcFinal(VALUE_DATA_TYPE, VALUE_OPERATOR, CValue *) { return NULL;}
-static STR_String sVertexName = "vertex";
-const STR_String & KX_VertexProxy::GetText() {return sVertexName;};
-double KX_VertexProxy::GetNumber() { return -1;}
-STR_String& KX_VertexProxy::GetName() { return sVertexName;}
-void KX_VertexProxy::SetName(const char *) { };
-CValue* KX_VertexProxy::GetReplica() { return NULL;}
-
-// stuff for python integration
-
-PyObject *KX_VertexProxy::PyGetXYZ()
-{
- return PyObjectFrom(MT_Point3(m_vertex->getXYZ()));
-}
-
-PyObject *KX_VertexProxy::PySetXYZ(PyObject *value)
-{
- MT_Point3 vec;
- if (!PyVecTo(value, vec))
- return NULL;
-
- m_vertex->SetXYZ(vec);
- m_mesh->SetMeshModified(true);
- Py_RETURN_NONE;
-}
-
-PyObject *KX_VertexProxy::PyGetNormal()
-{
- return PyObjectFrom(MT_Vector3(m_vertex->getNormal()));
-}
-
-PyObject *KX_VertexProxy::PySetNormal(PyObject *value)
-{
- MT_Vector3 vec;
- if (!PyVecTo(value, vec))
- return NULL;
-
- m_vertex->SetNormal(vec);
- m_mesh->SetMeshModified(true);
- Py_RETURN_NONE;
-}
-
-
-PyObject *KX_VertexProxy::PyGetRGBA()
-{
- int *rgba = (int *) m_vertex->getRGBA();
- return PyLong_FromLong(*rgba);
-}
-
-PyObject *KX_VertexProxy::PySetRGBA(PyObject *value)
-{
- if (PyLong_Check(value)) {
- int rgba = PyLong_AsLong(value);
- m_vertex->SetRGBA(rgba);
- m_mesh->SetMeshModified(true);
- Py_RETURN_NONE;
- }
- else {
- MT_Vector4 vec;
- if (PyVecTo(value, vec))
- {
- m_vertex->SetRGBA(vec);
- m_mesh->SetMeshModified(true);
- Py_RETURN_NONE;
- }
- }
-
- PyErr_SetString(PyExc_TypeError, "vert.setRGBA(value): KX_VertexProxy, expected a 4D vector or an int");
- return NULL;
-}
-
-
-PyObject *KX_VertexProxy::PyGetUV1()
-{
- return PyObjectFrom(MT_Vector2(m_vertex->getUV(0)));
-}
-
-PyObject *KX_VertexProxy::PySetUV1(PyObject *value)
-{
- MT_Point2 vec;
- if (!PyVecTo(value, vec))
- return NULL;
-
- m_vertex->SetUV(0, vec);
- m_mesh->SetMeshModified(true);
- Py_RETURN_NONE;
-}
-
-PyObject *KX_VertexProxy::PyGetUV2()
-{
- return PyObjectFrom(MT_Vector2(m_vertex->getUV(1)));
-}
-
-PyObject *KX_VertexProxy::PySetUV2(PyObject *args)
-{
- MT_Point2 vec;
- if (!PyVecTo(args, vec))
- return NULL;
-
- m_vertex->SetUV(1, vec);
- m_mesh->SetMeshModified(true);
- Py_RETURN_NONE;
-}
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_VertexProxy.h b/source/gameengine/Ketsji/KX_VertexProxy.h
deleted file mode 100644
index 8070825ad11..00000000000
--- a/source/gameengine/Ketsji/KX_VertexProxy.h
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_VertexProxy.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_VERTEXPROXY_H__
-#define __KX_VERTEXPROXY_H__
-
-#ifdef WITH_PYTHON
-
-#include "SCA_IObject.h"
-
-class KX_VertexProxy : public CValue
-{
- Py_Header
-protected:
-
- class RAS_TexVert* m_vertex;
- class KX_MeshProxy* m_mesh;
-public:
- KX_VertexProxy(class KX_MeshProxy*mesh, class RAS_TexVert* vertex);
- virtual ~KX_VertexProxy();
-
- // stuff for cvalue related things
- CValue* Calc(VALUE_OPERATOR op, CValue *val);
- CValue* CalcFinal(VALUE_DATA_TYPE dtype, VALUE_OPERATOR op, CValue *val);
- const STR_String & GetText();
- double GetNumber();
- STR_String& GetName();
- void SetName(const char *name); // Set the name of the value
- CValue* GetReplica();
-
-
-// stuff for python integration
-
- static PyObject *pyattr_get_x(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_y(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_z(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_r(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_g(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_b(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_a(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_u(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_v(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_u2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_v2(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_XYZ(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_UV(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_normal(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_uvs(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_x(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_y(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_z(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_u(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_v(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_u2(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_v2(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_r(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_g(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_b(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_a(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_XYZ(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_UV(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_color(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_normal(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static int pyattr_set_uvs(void *self, const struct KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
-
- KX_PYMETHOD_NOARGS(KX_VertexProxy,GetXYZ);
- KX_PYMETHOD_O(KX_VertexProxy,SetXYZ);
- KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV1);
- KX_PYMETHOD_O(KX_VertexProxy,SetUV1);
-
- KX_PYMETHOD_NOARGS(KX_VertexProxy,GetUV2);
- KX_PYMETHOD_VARARGS(KX_VertexProxy,SetUV2);
-
- KX_PYMETHOD_NOARGS(KX_VertexProxy,GetRGBA);
- KX_PYMETHOD_O(KX_VertexProxy,SetRGBA);
- KX_PYMETHOD_NOARGS(KX_VertexProxy,GetNormal);
- KX_PYMETHOD_O(KX_VertexProxy,SetNormal);
-
-};
-
-#endif /* WITH_PYTHON */
-
-#endif /* __KX_VERTEXPROXY_H__ */
diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp b/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
deleted file mode 100644
index 6f689e228b9..00000000000
--- a/source/gameengine/Ketsji/KX_VisibilityActuator.cpp
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Actuator to toggle visibility/invisibility of objects
- */
-
-/** \file gameengine/Ketsji/KX_VisibilityActuator.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_VisibilityActuator.h"
-#include "KX_GameObject.h"
-
-KX_VisibilityActuator::KX_VisibilityActuator(
- SCA_IObject* gameobj,
- bool visible,
- bool occlusion,
- bool recursive
- )
- : SCA_IActuator(gameobj, KX_ACT_VISIBILITY),
- m_visible(visible),
- m_occlusion(occlusion),
- m_recursive(recursive)
-{
- // intentionally empty
-}
-
-KX_VisibilityActuator::~KX_VisibilityActuator(
- void
- )
-{
- // intentionally empty
-}
-
-CValue*
-KX_VisibilityActuator::GetReplica(
- void
- )
-{
- KX_VisibilityActuator* replica = new KX_VisibilityActuator(*this);
- replica->ProcessReplica();
- return replica;
-}
-
-bool
-KX_VisibilityActuator::Update()
-{
- bool bNegativeEvent = IsNegativeEvent();
-
- RemoveAllEvents();
- if (bNegativeEvent) return false;
-
- KX_GameObject *obj = (KX_GameObject*) GetParent();
-
- obj->SetVisible(m_visible, m_recursive);
- obj->SetOccluder(m_occlusion, m_recursive);
- obj->UpdateBuckets(m_recursive);
-
- return false;
-}
-
-#ifdef WITH_PYTHON
-
-/* ------------------------------------------------------------------------- */
-/* Python functions */
-/* ------------------------------------------------------------------------- */
-
-
-
-/* Integration hooks ------------------------------------------------------- */
-PyTypeObject KX_VisibilityActuator::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_VisibilityActuator",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &SCA_IActuator::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_VisibilityActuator::Methods[] = {
- {NULL,NULL} //Sentinel
-};
-
-PyAttributeDef KX_VisibilityActuator::Attributes[] = {
- KX_PYATTRIBUTE_BOOL_RW("visibility", KX_VisibilityActuator, m_visible),
- KX_PYATTRIBUTE_BOOL_RW("useOcclusion", KX_VisibilityActuator, m_occlusion),
- KX_PYATTRIBUTE_BOOL_RW("useRecursion", KX_VisibilityActuator, m_recursive),
- { NULL } //Sentinel
-};
-
-#endif // WITH_PYTHON
diff --git a/source/gameengine/Ketsji/KX_VisibilityActuator.h b/source/gameengine/Ketsji/KX_VisibilityActuator.h
deleted file mode 100644
index a207844db74..00000000000
--- a/source/gameengine/Ketsji/KX_VisibilityActuator.h
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_VisibilityActuator.h
- * \ingroup ketsji
- * \brief Actuator to toggle visibility/invisibility of objects
- */
-
-#ifndef __KX_VISIBILITYACTUATOR_H__
-#define __KX_VISIBILITYACTUATOR_H__
-
-#include "SCA_IActuator.h"
-
-class KX_VisibilityActuator : public SCA_IActuator
-{
- Py_Header
-
- /** Make visible? */
- bool m_visible;
- bool m_occlusion;
- bool m_recursive;
-
- public:
-
- KX_VisibilityActuator(
- SCA_IObject* gameobj,
- bool visible,
- bool occlusion,
- bool recursive);
-
- virtual
- ~KX_VisibilityActuator(
- void
- );
-
- virtual CValue*
- GetReplica(
- void
- );
-
- virtual bool
- Update();
-
- /* --------------------------------------------------------------------- */
- /* Python interface ---------------------------------------------------- */
- /* --------------------------------------------------------------------- */
-
-};
-
-#endif
-
diff --git a/source/gameengine/Ketsji/KX_WorldInfo.cpp b/source/gameengine/Ketsji/KX_WorldInfo.cpp
deleted file mode 100644
index be8b1ce92fc..00000000000
--- a/source/gameengine/Ketsji/KX_WorldInfo.cpp
+++ /dev/null
@@ -1,494 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_WorldInfo.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_WorldInfo.h"
-#include "KX_PythonInit.h"
-#include "KX_PyMath.h"
-#include "RAS_IRasterizer.h"
-#include "GPU_material.h"
-
-/* This little block needed for linking to Blender... */
-#ifdef WIN32
-#include "BLI_winstuff.h"
-#endif
-
-/* This list includes only data type definitions */
-#include "DNA_scene_types.h"
-#include "DNA_world_types.h"
-
-#include "BLI_math.h"
-
-#include "BKE_global.h"
-#include "BKE_scene.h"
-/* end of blender include block */
-
-
-KX_WorldInfo::KX_WorldInfo(Scene *blenderscene, World *blenderworld)
-{
- if (blenderworld) {
- m_name = blenderworld->id.name + 2;
- m_do_color_management = BKE_scene_check_color_management_enabled(blenderscene);
- m_hasworld = true;
- m_hasmist = ((blenderworld->mode) & WO_MIST ? true : false);
- m_misttype = blenderworld->mistype;
- m_miststart = blenderworld->miststa;
- m_mistdistance = blenderworld->mistdist;
- m_mistintensity = blenderworld->misi;
- setMistColor(blenderworld->horr, blenderworld->horg, blenderworld->horb);
- setBackColor(blenderworld->horr, blenderworld->horg, blenderworld->horb);
- setAmbientColor(blenderworld->ambr, blenderworld->ambg, blenderworld->ambb);
- }
- else {
- m_hasworld = false;
- }
-}
-
-KX_WorldInfo::~KX_WorldInfo()
-{
-}
-
-const STR_String& KX_WorldInfo::GetName()
-{
- return m_name;
-}
-
-bool KX_WorldInfo::hasWorld()
-{
- return m_hasworld;
-}
-
-void KX_WorldInfo::setBackColor(float r, float g, float b)
-{
- m_backgroundcolor[0] = r;
- m_backgroundcolor[1] = g;
- m_backgroundcolor[2] = b;
-
- if (m_do_color_management) {
- linearrgb_to_srgb_v3_v3(m_con_backgroundcolor, m_backgroundcolor);
- }
- else {
- copy_v3_v3(m_con_backgroundcolor, m_backgroundcolor);
- }
-}
-
-const float *KX_WorldInfo::getBackColorConverted() const
-{
- return m_con_backgroundcolor;
-}
-
-void KX_WorldInfo::setMistType(short type)
-{
- m_misttype = type;
-}
-
-void KX_WorldInfo::setUseMist(bool enable)
-{
- m_hasmist = enable;
-}
-
-void KX_WorldInfo::setMistStart(float d)
-{
- m_miststart = d;
-}
-
-void KX_WorldInfo::setMistDistance(float d)
-{
- m_mistdistance = d;
-}
-
-void KX_WorldInfo::setMistIntensity(float intensity)
-{
- m_mistintensity = intensity;
-}
-void KX_WorldInfo::setMistColor(float r, float g, float b)
-{
- m_mistcolor[0] = r;
- m_mistcolor[1] = g;
- m_mistcolor[2] = b;
-
- if (m_do_color_management) {
- linearrgb_to_srgb_v3_v3(m_con_mistcolor, m_mistcolor);
- }
- else {
- copy_v3_v3(m_con_mistcolor, m_mistcolor);
- }
-}
-
-void KX_WorldInfo::setAmbientColor(float r, float g, float b)
-{
- m_ambientcolor[0] = r;
- m_ambientcolor[1] = g;
- m_ambientcolor[2] = b;
-
- if (m_do_color_management) {
- linearrgb_to_srgb_v3_v3(m_con_ambientcolor, m_ambientcolor);
- }
- else {
- copy_v3_v3(m_con_ambientcolor, m_ambientcolor);
- }
-}
-
-void KX_WorldInfo::UpdateBackGround()
-{
- if (m_hasworld) {
- RAS_IRasterizer *m_rasterizer = KX_GetActiveEngine()->GetRasterizer();
-
- if (m_rasterizer->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID) {
- m_rasterizer->SetBackColor(m_con_backgroundcolor);
- GPU_horizon_update_color(m_backgroundcolor);
- }
- }
-}
-
-void KX_WorldInfo::UpdateWorldSettings()
-{
- if (m_hasworld) {
- RAS_IRasterizer *m_rasterizer = KX_GetActiveEngine()->GetRasterizer();
-
- if (m_rasterizer->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID) {
- m_rasterizer->SetAmbientColor(m_con_ambientcolor);
- GPU_ambient_update_color(m_ambientcolor);
-
- if (m_hasmist) {
- m_rasterizer->SetFog(m_misttype, m_miststart, m_mistdistance, m_mistintensity, m_con_mistcolor);
- GPU_mist_update_values(m_misttype, m_miststart, m_mistdistance, m_mistintensity, m_mistcolor);
- m_rasterizer->EnableFog(true);
- GPU_mist_update_enable(true);
- }
- else {
- m_rasterizer->EnableFog(false);
- GPU_mist_update_enable(false);
- }
- }
- }
-}
-
-#ifdef WITH_PYTHON
-
-/* -------------------------------------------------------------------------
- * Python functions
- * ------------------------------------------------------------------------- */
-PyObject *KX_WorldInfo::py_repr(void)
-{
- return PyUnicode_From_STR_String(GetName());
-}
-
-/* -------------------------------------------------------------------------
- * Python Integration Hooks
- * ------------------------------------------------------------------------- */
-PyTypeObject KX_WorldInfo::Type = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "KX_WorldInfo",
- sizeof(PyObjectPlus_Proxy),
- 0,
- py_base_dealloc,
- 0,
- 0,
- 0,
- 0,
- py_base_repr,
- 0,0,0,0,0,0,0,0,0,
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
- 0,0,0,0,0,0,0,
- Methods,
- 0,
- 0,
- &PyObjectPlus::Type,
- 0,0,0,0,0,0,
- py_base_new
-};
-
-PyMethodDef KX_WorldInfo::Methods[] = {
- {NULL,NULL} /* Sentinel */
-};
-
-PyAttributeDef KX_WorldInfo::Attributes[] = {
- KX_PYATTRIBUTE_BOOL_RW("mistEnable", KX_WorldInfo, m_hasmist),
- KX_PYATTRIBUTE_FLOAT_RW("mistStart", 0.0f, 10000.0f, KX_WorldInfo, m_miststart),
- KX_PYATTRIBUTE_FLOAT_RW("mistDistance", 0.001f, 10000.0f, KX_WorldInfo, m_mistdistance),
- KX_PYATTRIBUTE_FLOAT_RW("mistIntensity", 0.0f, 1.0f, KX_WorldInfo, m_mistintensity),
- KX_PYATTRIBUTE_SHORT_RW("mistType", 0, 2, true, KX_WorldInfo, m_misttype),
- KX_PYATTRIBUTE_RO_FUNCTION("KX_MIST_QUADRATIC", KX_WorldInfo, pyattr_get_mist_typeconst),
- KX_PYATTRIBUTE_RO_FUNCTION("KX_MIST_LINEAR", KX_WorldInfo, pyattr_get_mist_typeconst),
- KX_PYATTRIBUTE_RO_FUNCTION("KX_MIST_INV_QUADRATIC", KX_WorldInfo, pyattr_get_mist_typeconst),
- KX_PYATTRIBUTE_RW_FUNCTION("mistColor", KX_WorldInfo, pyattr_get_mist_color, pyattr_set_mist_color),
- KX_PYATTRIBUTE_RW_FUNCTION("backgroundColor", KX_WorldInfo, pyattr_get_back_color, pyattr_set_back_color),
- KX_PYATTRIBUTE_RW_FUNCTION("ambientColor", KX_WorldInfo, pyattr_get_ambient_color, pyattr_set_ambient_color),
- { NULL } /* Sentinel */
-};
-
-/* Attribute get/set functions */
-
-#ifdef USE_MATHUTILS
-
-/*----------------------mathutils callbacks ----------------------------*/
-
-/* subtype */
-#define MATHUTILS_COL_CB_MIST_COLOR 1
-#define MATHUTILS_COL_CB_BACK_COLOR 2
-#define MATHUTILS_COL_CB_AMBIENT_COLOR 3
-
-static unsigned char mathutils_world_color_cb_index = -1; /* index for our callbacks */
-
-static int mathutils_world_generic_check(BaseMathObject *bmo)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- return 0;
-}
-
-static int mathutils_world_color_get(BaseMathObject *bmo, int subtype)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
- if (self == NULL)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_COL_CB_MIST_COLOR:
- copy_v3_v3(bmo->data, self->m_mistcolor);
- break;
- case MATHUTILS_COL_CB_BACK_COLOR:
- copy_v3_v3(bmo->data, self->m_backgroundcolor);
- break;
- case MATHUTILS_COL_CB_AMBIENT_COLOR:
- copy_v3_v3(bmo->data, self->m_ambientcolor);
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-static int mathutils_world_color_set(BaseMathObject *bmo, int subtype)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
-
- if (self == NULL)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_COL_CB_MIST_COLOR:
- self->setMistColor(bmo->data[0], bmo->data[1], bmo->data[2]);
- break;
- case MATHUTILS_COL_CB_BACK_COLOR:
- self->setBackColor(bmo->data[0], bmo->data[1], bmo->data[2]);
- break;
- case MATHUTILS_COL_CB_AMBIENT_COLOR:
- self->setAmbientColor(bmo->data[0], bmo->data[1], bmo->data[2]);
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-static int mathutils_world_color_get_index(BaseMathObject *bmo, int subtype, int index)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
-
- if (self == NULL)
- return -1;
-
- switch (subtype) {
- case MATHUTILS_COL_CB_MIST_COLOR:
- {
- const float *color = self->m_mistcolor;
- bmo->data[index] = color[index];
- }
- break;
- case MATHUTILS_COL_CB_BACK_COLOR:
- {
- const float *color = self->m_backgroundcolor;
- bmo->data[index] = color[index];
- }
- break;
- case MATHUTILS_COL_CB_AMBIENT_COLOR:
- {
- const float *color = self->m_ambientcolor;
- bmo->data[index] = color[index];
- }
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-static int mathutils_world_color_set_index(BaseMathObject *bmo, int subtype, int index)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>BGE_PROXY_REF(bmo->cb_user);
-
- if (self == NULL)
- return -1;
-
- float color[4];
- switch (subtype) {
- case MATHUTILS_COL_CB_MIST_COLOR:
- copy_v3_v3(color, self->m_mistcolor);
- color[index] = bmo->data[index];
- self->setMistColor(color[0], color[1], color[2]);
- break;
- case MATHUTILS_COL_CB_BACK_COLOR:
- copy_v3_v3(color, self->m_backgroundcolor);
- color[index] = bmo->data[index];
- self->setBackColor(color[0], color[1], color[2]);
- break;
- case MATHUTILS_COL_CB_AMBIENT_COLOR:
- copy_v3_v3(color, self->m_ambientcolor);
- color[index] = bmo->data[index];
- self->setAmbientColor(color[0], color[1], color[2]);
- break;
- default:
- return -1;
- }
- return 0;
-}
-
-static Mathutils_Callback mathutils_world_color_cb = {
- mathutils_world_generic_check,
- mathutils_world_color_get,
- mathutils_world_color_set,
- mathutils_world_color_get_index,
- mathutils_world_color_set_index
-};
-
-void KX_WorldInfo_Mathutils_Callback_Init()
-{
- // register mathutils callbacks, ok to run more than once.
- mathutils_world_color_cb_index = Mathutils_RegisterCallback(&mathutils_world_color_cb);
-}
-#endif // USE_MATHUTILS
-
-
-PyObject *KX_WorldInfo::pyattr_get_mist_typeconst(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
- PyObject *retvalue;
-
- const char* type = attrdef->m_name;
-
- if (!strcmp(type, "KX_MIST_QUADRATIC")) {
- retvalue = PyLong_FromLong(KX_MIST_QUADRATIC);
- }
- else if (!strcmp(type, "KX_MIST_LINEAR")) {
- retvalue = PyLong_FromLong(KX_MIST_LINEAR);
- }
- else if (!strcmp(type, "KX_MIST_INV_QUADRATIC")) {
- retvalue = PyLong_FromLong(KX_MIST_INV_QUADRATIC);
- }
- else {
- /* should never happen */
- PyErr_SetString(PyExc_TypeError, "invalid mist type");
- retvalue = NULL;
- }
-
- return retvalue;
-}
-
-PyObject *KX_WorldInfo::pyattr_get_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Color_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v),
- mathutils_world_color_cb_index, MATHUTILS_COL_CB_MIST_COLOR);
-#else
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
- return PyObjectFrom(MT_Vector3(self->m_mistcolor));
-#endif
-}
-
-int KX_WorldInfo::pyattr_set_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
-
- MT_Vector3 color;
- if (PyVecTo(value, color))
- {
- self->setMistColor(color[0], color[1], color[2]);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_WorldInfo::pyattr_get_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-
-#ifdef USE_MATHUTILS
- return Color_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v),
- mathutils_world_color_cb_index, MATHUTILS_COL_CB_BACK_COLOR);
-#else
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
- return PyObjectFrom(MT_Vector3(self->m_backgroundcolor));
-#endif
-}
-
-int KX_WorldInfo::pyattr_set_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
-
- MT_Vector3 color;
- if (PyVecTo(value, color))
- {
- self->setBackColor(color[0], color[1], color[2]);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-PyObject *KX_WorldInfo::pyattr_get_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef)
-{
-#ifdef USE_MATHUTILS
- return Color_CreatePyObject_cb(
- BGE_PROXY_FROM_REF_BORROW(self_v),
- mathutils_world_color_cb_index, MATHUTILS_COL_CB_AMBIENT_COLOR);
-#else
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
- return PyObjectFrom(MT_Vector3(self->m_ambientcolor));
-#endif
-}
-
-int KX_WorldInfo::pyattr_set_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value)
-{
- KX_WorldInfo *self = static_cast<KX_WorldInfo*>(self_v);
-
- MT_Vector3 color;
- if (PyVecTo(value, color))
- {
- self->setAmbientColor(color[0], color[1], color[2]);
- return PY_SET_ATTR_SUCCESS;
- }
- return PY_SET_ATTR_FAIL;
-}
-
-#endif /* WITH_PYTHON */
diff --git a/source/gameengine/Ketsji/KX_WorldInfo.h b/source/gameengine/Ketsji/KX_WorldInfo.h
deleted file mode 100644
index b155faf2837..00000000000
--- a/source/gameengine/Ketsji/KX_WorldInfo.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_WorldInfo.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_WORLDINFO_H__
-#define __KX_WORLDINFO_H__
-
-#include "MT_Scalar.h"
-#include "KX_KetsjiEngine.h"
-#include "EXP_PyObjectPlus.h"
-
-#ifdef USE_MATHUTILS
-void KX_WorldInfo_Mathutils_Callback_Init(void);
-#endif
-
-struct Scene;
-struct World;
-
-class KX_WorldInfo : public PyObjectPlus
-{
- Py_Header
-
- STR_String m_name;
- bool m_do_color_management;
- bool m_hasworld;
- bool m_hasmist;
- short m_misttype;
- float m_miststart;
- float m_mistdistance;
- float m_mistintensity;
- float m_mistcolor[3];
- float m_backgroundcolor[3];
- float m_ambientcolor[3];
- float m_con_mistcolor[3];
- float m_con_backgroundcolor[3];
- float m_con_ambientcolor[3];
-
-public:
- /**
- * Mist options
- */
- enum MistType {
- KX_MIST_QUADRATIC,
- KX_MIST_LINEAR,
- KX_MIST_INV_QUADRATIC,
- };
-
- KX_WorldInfo(Scene *blenderscene, World *blenderworld);
- ~KX_WorldInfo();
-
- const STR_String &GetName();
- bool hasWorld();
- void setUseMist(bool enable);
- void setMistType(short type);
- void setMistStart(float d);
- void setMistDistance(float d);
- void setMistIntensity(float intensity);
- void setMistColor(float r, float g, float b);
- void setBackColor(float r, float g, float b);
- const float *getBackColorConverted() const;
- void setAmbientColor(float r, float g, float b);
- void UpdateBackGround();
- void UpdateWorldSettings();
-
-#ifdef WITH_PYTHON
- /* attributes */
- static PyObject *pyattr_get_mist_typeconst(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static PyObject *pyattr_get_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_mist_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_back_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- static PyObject *pyattr_get_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef);
- static int pyattr_set_ambient_color(void *self_v, const KX_PYATTRIBUTE_DEF *attrdef, PyObject *value);
- virtual PyObject *py_repr(void);
-#endif
-};
-
-#endif /* __KX_WORLDINFO_H__ */
diff --git a/source/gameengine/Ketsji/KX_WorldIpoController.cpp b/source/gameengine/Ketsji/KX_WorldIpoController.cpp
deleted file mode 100644
index 1123e07ebcc..00000000000
--- a/source/gameengine/Ketsji/KX_WorldIpoController.cpp
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Ketsji/KX_WorldIpoController.cpp
- * \ingroup ketsji
- */
-
-
-#include "KX_WorldIpoController.h"
-#include "KX_ScalarInterpolator.h"
-#include "KX_WorldInfo.h"
-#include "KX_PythonInit.h"
-#include "KX_Scene.h"
-
-#if defined(_WIN64)
-typedef unsigned __int64 uint_ptr;
-#else
-typedef unsigned long uint_ptr;
-#endif
-
-bool KX_WorldIpoController::Update(double currentTime)
-{
- if (m_modified) {
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- (*i)->Execute(m_ipotime);
- }
-
- KX_WorldInfo *world = KX_GetActiveScene()->GetWorldInfo();
-
- if (m_modify_mist_start) {
- world->setMistStart(m_mist_start);
- }
-
- if (m_modify_mist_dist) {
- world->setMistDistance(m_mist_dist);
- }
-
- if (m_modify_mist_intensity) {
- world->setMistIntensity(m_mist_intensity);
- }
-
- if (m_modify_horizon_color) {
- world->setBackColor(m_hori_rgb[0], m_hori_rgb[1], m_hori_rgb[2]);
- world->setMistColor(m_hori_rgb[0], m_hori_rgb[1], m_hori_rgb[2]);
- }
-
- if (m_modify_ambient_color) {
- world->setAmbientColor(m_ambi_rgb[0], m_ambi_rgb[1], m_ambi_rgb[2]);
- }
-
- m_modified = false;
- }
- return false;
-}
-
-
-void KX_WorldIpoController::AddInterpolator(KX_IInterpolator* interp)
-{
- this->m_interpolators.push_back(interp);
-}
-
-
-SG_Controller* KX_WorldIpoController::GetReplica(class SG_Node* destnode)
-{
- KX_WorldIpoController* iporeplica = new KX_WorldIpoController(*this);
- // clear object that ipo acts on
- iporeplica->ClearObject();
-
- // dirty hack, ask Gino for a better solution in the ipo implementation
- // hacken en zagen, in what we call datahiding, not written for replication :(
-
- T_InterpolatorList oldlist = m_interpolators;
- iporeplica->m_interpolators.clear();
-
- T_InterpolatorList::iterator i;
- for (i = oldlist.begin(); !(i == oldlist.end()); ++i) {
- KX_ScalarInterpolator* copyipo = new KX_ScalarInterpolator(*((KX_ScalarInterpolator*)*i));
- iporeplica->AddInterpolator(copyipo);
-
- MT_Scalar* scaal = ((KX_ScalarInterpolator*)*i)->GetTarget();
- uint_ptr orgbase = (uint_ptr)this;
- uint_ptr orgloc = (uint_ptr)scaal;
- uint_ptr offset = orgloc-orgbase;
- uint_ptr newaddrbase = (uint_ptr)iporeplica + offset;
- MT_Scalar* blaptr = (MT_Scalar*) newaddrbase;
- copyipo->SetNewTarget((MT_Scalar*)blaptr);
- }
-
- return iporeplica;
-}
-
-KX_WorldIpoController::~KX_WorldIpoController()
-{
-
- T_InterpolatorList::iterator i;
- for (i = m_interpolators.begin(); !(i == m_interpolators.end()); ++i) {
- delete (*i);
- }
-
-}
diff --git a/source/gameengine/Ketsji/KX_WorldIpoController.h b/source/gameengine/Ketsji/KX_WorldIpoController.h
deleted file mode 100644
index 704f421573e..00000000000
--- a/source/gameengine/Ketsji/KX_WorldIpoController.h
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file KX_WorldIpoController.h
- * \ingroup ketsji
- */
-
-#ifndef __KX_WORLDIPOCONTROLLER_H__
-#define __KX_WORLDIPOCONTROLLER_H__
-
-#include "SG_Controller.h"
-#include "SG_Spatial.h"
-#include "KX_IInterpolator.h"
-
-class KX_WorldIpoController : public SG_Controller
-{
-public:
- MT_Scalar m_mist_start;
- MT_Scalar m_mist_dist;
- MT_Scalar m_mist_intensity;
- MT_Scalar m_hori_rgb[3];
- MT_Scalar m_ambi_rgb[3];
-
-private:
- T_InterpolatorList m_interpolators;
- unsigned short m_modify_mist_start : 1;
- unsigned short m_modify_mist_dist : 1;
- unsigned short m_modify_mist_intensity : 1;
- unsigned short m_modify_horizon_color : 1;
- unsigned short m_modify_ambient_color : 1;
- bool m_modified;
-
- double m_ipotime;
-
-public:
- KX_WorldIpoController() :
- m_modify_mist_start(false),
- m_modify_mist_dist(false),
- m_modify_mist_intensity(false),
- m_modify_horizon_color(false),
- m_modify_ambient_color(false),
- m_modified(true),
- m_ipotime(0.0)
- {}
-
- virtual ~KX_WorldIpoController();
-
- virtual SG_Controller* GetReplica(class SG_Node* destnode);
-
- virtual bool Update(double time);
-
- virtual void SetSimulatedTime(double time) {
- m_ipotime = time;
- m_modified = true;
- }
-
- void SetModifyMistStart(bool modify) {
- m_modify_mist_start = modify;
- }
-
- void SetModifyMistDist(bool modify) {
- m_modify_mist_dist = modify;
- }
-
- void SetModifyMistIntensity(bool modify) {
- m_modify_mist_intensity = modify;
- }
-
- void SetModifyHorizonColor(bool modify) {
- m_modify_horizon_color = modify;
- }
-
- void SetModifyAmbientColor(bool modify) {
- m_modify_ambient_color = modify;
- }
-
- void
- SetOption(
- int option,
- int value
- ) {
- // intentionally empty
- };
-
- void AddInterpolator(KX_IInterpolator* interp);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:KX_WorldIpoController")
-#endif
-};
-
-#endif /* __KX_WORLDIPOCONTROLLER_H__ */
diff --git a/source/gameengine/Network/CMakeLists.txt b/source/gameengine/Network/CMakeLists.txt
deleted file mode 100644
index 019fc3e6032..00000000000
--- a/source/gameengine/Network/CMakeLists.txt
+++ /dev/null
@@ -1,48 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../../../intern/container
- ../../../intern/string
- ../../blender/blenlib
-)
-
-set(INC_SYS
- ../../../intern/moto/include
-)
-
-set(SRC
- NG_NetworkMessage.cpp
- NG_NetworkObject.cpp
- NG_NetworkScene.cpp
-
- NG_NetworkDeviceInterface.h
- NG_NetworkMessage.h
- NG_NetworkObject.h
- NG_NetworkScene.h
-)
-
-blender_add_lib(ge_logic_ngnetwork "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Network/LoopBackNetwork/CMakeLists.txt b/source/gameengine/Network/LoopBackNetwork/CMakeLists.txt
deleted file mode 100644
index 75877575614..00000000000
--- a/source/gameengine/Network/LoopBackNetwork/CMakeLists.txt
+++ /dev/null
@@ -1,43 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ..
- ../../../../intern/container
- ../../../../intern/string
-)
-
-set(INC_SYS
-
-)
-
-set(SRC
- NG_LoopBackNetworkDeviceInterface.cpp
-
- NG_LoopBackNetworkDeviceInterface.h
-)
-
-blender_add_lib(ge_logic_loopbacknetwork "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp b/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp
deleted file mode 100644
index c57bd304ca2..00000000000
--- a/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp
+++ /dev/null
@@ -1,112 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * LoopbackNetworkDeviceInterface derived from NG_NetworkDeviceInterface
- */
-
-/** \file gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.cpp
- * \ingroup bgenetlb
- */
-
-
-#include "NG_LoopBackNetworkDeviceInterface.h"
-#include "NG_NetworkMessage.h"
-
-using namespace std;
-
-// temporary debugging printf's
-#ifdef NAN_NET_DEBUG
- #include <stdio.h>
-#endif
-
-NG_LoopBackNetworkDeviceInterface::NG_LoopBackNetworkDeviceInterface()
-{
- m_currentQueue=0;
- Online(); // LoopBackdevices are 'online' immediately
-}
-
-NG_LoopBackNetworkDeviceInterface::~NG_LoopBackNetworkDeviceInterface()
-{
-}
-
-// perhaps this should go to the shared/common implementation too
-void NG_LoopBackNetworkDeviceInterface::NextFrame()
-{
- // Release reference to the messages while emptying the queue
- while (m_messages[m_currentQueue].size() > 0) {
-#ifdef NAN_NET_DEBUG
- printf("NG_LBNDI::NextFrame %d '%s'\n", m_currentQueue, m_messages[m_currentQueue][0]->GetSubject().ReadPtr());
-#endif
- // Should do assert(m_events[0]);
- m_messages[m_currentQueue][0]->Release();
- m_messages[m_currentQueue].pop_front();
- }
- //m_messages[m_currentQueue].clear();
-
- m_currentQueue=1-m_currentQueue;
-}
-
-void NG_LoopBackNetworkDeviceInterface::SendNetworkMessage(NG_NetworkMessage* nwmsg)
-{
-#ifdef NAN_NET_DEBUG
- printf("NG_LBNDI::SendNetworkMessage %d, '%s'->'%s' '%s' '%s'\n",
- 1-m_currentQueue,
- nwmsg->GetDestinationName().ReadPtr(),
- nwmsg->GetSenderName().ReadPtr(),
- nwmsg->GetSubject().ReadPtr(),
- nwmsg->GetMessageText().ReadPtr());
-#endif
- int backqueue = 1-m_currentQueue;
-
- nwmsg->AddRef();
- m_messages[backqueue].push_back(nwmsg);
-}
-
-vector<NG_NetworkMessage*> NG_LoopBackNetworkDeviceInterface::RetrieveNetworkMessages()
-{
- vector<NG_NetworkMessage*> messages;
-
- std::deque<NG_NetworkMessage*>::iterator mesit=m_messages[m_currentQueue].begin();
- for (; !(mesit == m_messages[m_currentQueue].end()); ++mesit)
- {
-
- // We don't increase the reference count for these messages. We
- // are passing a vector of messages in the interface and not
- // explicitily storing the messgaes for long term usage
-
- messages.push_back(*mesit);
-
-#ifdef NAN_NET_DEBUG
- printf("NG_LBNDI::RetrieveNetworkMessages %d '%s'->'%s' '%s' '%s'\n",
- m_currentQueue,
- (*mesit)->GetDestinationName().ReadPtr(),
- (*mesit)->GetSenderName().ReadPtr(),
- (*mesit)->GetSubject().ReadPtr(),
- (*mesit)->GetMessageText().ReadPtr());
-#endif
- }
- return messages;
-}
-
diff --git a/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.h b/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.h
deleted file mode 100644
index 8bbb1e91e35..00000000000
--- a/source/gameengine/Network/LoopBackNetwork/NG_LoopBackNetworkDeviceInterface.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file NG_LoopBackNetworkDeviceInterface.h
- * \ingroup bgenetlb
- * \brief LoopbackNetworkDeviceInterface derived from NG_NetworkDeviceInterface
- */
-#ifndef __NG_LOOPBACKNETWORKDEVICEINTERFACE_H__
-#define __NG_LOOPBACKNETWORKDEVICEINTERFACE_H__
-
-#include <deque>
-#include "NG_NetworkDeviceInterface.h"
-
-class NG_LoopBackNetworkDeviceInterface : public NG_NetworkDeviceInterface
-{
- std::deque<NG_NetworkMessage*> m_messages[2];
- int m_currentQueue;
-
-public:
- NG_LoopBackNetworkDeviceInterface();
- virtual ~NG_LoopBackNetworkDeviceInterface();
-
- /**
- * Clear message buffer
- */
- virtual void NextFrame();
-
- bool Connect(char *address, unsigned int port, char *password,
- unsigned int localport, unsigned int timeout)
- {
- return true;
- }
- bool Disconnect(void) {return true;}
-
- virtual void SendNetworkMessage(class NG_NetworkMessage* msg);
- virtual std::vector<NG_NetworkMessage*> RetrieveNetworkMessages();
-};
-
-#endif /* __NG_LOOPBACKNETWORKDEVICEINTERFACE_H__ */
diff --git a/source/gameengine/Network/NG_NetworkDeviceInterface.h b/source/gameengine/Network/NG_NetworkDeviceInterface.h
deleted file mode 100644
index 7fcf799db31..00000000000
--- a/source/gameengine/Network/NG_NetworkDeviceInterface.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file NG_NetworkDeviceInterface.h
- * \ingroup bgenet
- * \brief Functions like (de)initialize network, get library version
- * To be derived by loopback and network libraries
- */
-
-#ifndef __NG_NETWORKDEVICEINTERFACE_H__
-#define __NG_NETWORKDEVICEINTERFACE_H__
-
-#include "NG_NetworkMessage.h"
-#include <vector>
-
-class NG_NetworkDeviceInterface
-{
-private:
- // candidates for shared/common implementation class
- bool m_online;
-public:
- NG_NetworkDeviceInterface() {}
- virtual ~NG_NetworkDeviceInterface() {}
-
- virtual void NextFrame()=0;
-
- /**
- * Mark network connection online
- */
- void Online(void) { m_online = true; }
- /**
- * Mark network connection offline
- */
- void Offline(void) { m_online = false; }
- /**
- * Is the network connection established ?
- */
- bool IsOnline(void) { return m_online; }
-
- virtual bool Connect(char *address, unsigned int port, char *password,
- unsigned int localport, unsigned int timeout)=0;
- virtual bool Disconnect(void)=0;
-
- virtual void SendNetworkMessage(NG_NetworkMessage* msg)=0;
- /**
- * read NG_NetworkMessage from library buffer, may be
- * irrelevant for loopbackdevices
- */
-
- virtual std::vector<NG_NetworkMessage*> RetrieveNetworkMessages()=0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:NG_NetworkDeviceInterface")
-#endif
-};
-
-#endif /* __NG_NETWORKDEVICEINTERFACE_H__ */
diff --git a/source/gameengine/Network/NG_NetworkMessage.cpp b/source/gameengine/Network/NG_NetworkMessage.cpp
deleted file mode 100644
index 23ae2529b7a..00000000000
--- a/source/gameengine/Network/NG_NetworkMessage.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * generic Network Message implementation
- */
-
-/** \file gameengine/Network/NG_NetworkMessage.cpp
- * \ingroup bgenet
- */
-
-#include "NG_NetworkMessage.h"
-#include <assert.h>
-
-int NG_NetworkMessage::s_nextID = 3; // just some number to start with
-
-NG_NetworkMessage::NG_NetworkMessage(
- const STR_String& to,
- const STR_String& from,
- const STR_String& subject,
- const STR_String& body) :
- m_uniqueMessageID(s_nextID++),
- m_refcount(1),
- m_to(to),
- m_from(from),
- m_subject(subject),
- m_message(body)
-{
-}
-
-NG_NetworkMessage::~NG_NetworkMessage()
-{
- assert(m_refcount==0);
-}
diff --git a/source/gameengine/Network/NG_NetworkMessage.h b/source/gameengine/Network/NG_NetworkMessage.h
deleted file mode 100644
index 6ed266557fc..00000000000
--- a/source/gameengine/Network/NG_NetworkMessage.h
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file NG_NetworkMessage.h
- * \ingroup bgenet
- * \brief generic Network Message class
- */
-#ifndef __NG_NETWORKMESSAGE_H__
-#define __NG_NETWORKMESSAGE_H__
-
-#include "STR_HashedString.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class NG_NetworkMessage
-{
- static int s_nextID;
- int m_uniqueMessageID; // intern counting MessageID
- unsigned int m_ClientId;
- int m_refcount;
-
- STR_String m_to; // receiver
- STR_String m_from; // sender
- STR_String m_subject; // empty or propName
- STR_String m_message; // message or propValue
-
-protected:
- ~NG_NetworkMessage();
-
-public:
- NG_NetworkMessage(
- const STR_String& to,
- const STR_String& from,
- const STR_String& subject,
- const STR_String& body);
-
- void AddRef() {
- m_refcount++;
- }
-
- // This is not nice code you should'nt need to resort to
- // delete this.
- void Release()
- {
- if (! --m_refcount)
- {
- delete this;
- }
- }
-
- /**
- * set the content of this message
- */
- void SetMessageText(const STR_String& msgtext) {
- m_message = msgtext;
- }
-
- /**
- * get the (read-only) To part of this message
- */
- const STR_String& GetDestinationName() { return m_to; }
-
- /**
- * get the (read-only) From part of this message
- */
- const STR_String& GetSenderName() { return m_from; }
-
- /**
- * get the (read-only) Subject part of this message
- */
- const STR_String& GetSubject() { return m_subject; }
-
- /**
- * get the (read-only) Body part of this message
- */
- const STR_String& GetMessageText() {
-//cout << "GetMessageText " << m_message << "\n";
- return m_message;
- }
- const STR_String& GetMessageText() const {
-//cout << "GetMessageText " << m_message << "\n";
- return m_message;
- }
-
- /**
- * Set the NetworkMessage sender identifier
- */
- void SetSender(unsigned int ClientId) {
- m_ClientId = ClientId;
- }
-
- /**
- * Get the NetworkMessage sender identifier
- */
- unsigned int GetSender(void) {
- return m_ClientId;
- }
-
- /**
- * get the unique Network Message ID
- */
- int GetMessageID() {
- return m_uniqueMessageID;
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:NG_NetworkMessage")
-#endif
-};
-
-#endif /* __NG_NETWORKMESSAGE_H__ */
diff --git a/source/gameengine/Network/NG_NetworkObject.cpp b/source/gameengine/Network/NG_NetworkObject.cpp
deleted file mode 100644
index 5cd42a2e45a..00000000000
--- a/source/gameengine/Network/NG_NetworkObject.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * NetworkGame_NetworkObject generic Network Object implementation
- */
-
-/** \file gameengine/Network/NG_NetworkObject.cpp
- * \ingroup bgenet
- */
-
-#include "NG_NetworkObject.h"
-
-NG_NetworkObject::NG_NetworkObject()
-{
-}
-
-NG_NetworkObject::~NG_NetworkObject()
-{
-}
-
-const STR_String& NG_NetworkObject::GetName()
-{
- return m_name;
-}
diff --git a/source/gameengine/Network/NG_NetworkObject.h b/source/gameengine/Network/NG_NetworkObject.h
deleted file mode 100644
index 54459cad55d..00000000000
--- a/source/gameengine/Network/NG_NetworkObject.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file NG_NetworkObject.h
- * \ingroup bgenet
- * \brief generic Network Object class
- */
-#ifndef __NG_NETWORKOBJECT_H__
-#define __NG_NETWORKOBJECT_H__
-
-#include "STR_String.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class NG_NetworkObject
-{
- STR_String m_name;
-public:
- NG_NetworkObject();
- ~NG_NetworkObject();
- const STR_String& GetName();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:NG_NetworkObject")
-#endif
-};
-
-#endif /* __NG_NETWORKOBJECT_H__ */
diff --git a/source/gameengine/Network/NG_NetworkScene.cpp b/source/gameengine/Network/NG_NetworkScene.cpp
deleted file mode 100644
index 3dbfb53d03d..00000000000
--- a/source/gameengine/Network/NG_NetworkScene.cpp
+++ /dev/null
@@ -1,272 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * NetworkSceneManagement generic implementation
- */
-
-/** \file gameengine/Network/NG_NetworkScene.cpp
- * \ingroup bgenet
- */
-
-#include <stdio.h>
-#include <MT_assert.h>
-#include <algorithm>
-
-#include "NG_NetworkScene.h"
-#include "NG_NetworkDeviceInterface.h"
-#include "NG_NetworkMessage.h"
-#include "NG_NetworkObject.h"
-
-NG_NetworkScene::NG_NetworkScene(NG_NetworkDeviceInterface* nic)
-{
- m_networkdevice = nic;
-}
-
-NG_NetworkScene::~NG_NetworkScene()
-{
- ClearAllMessageMaps();
-}
-
-/**
- * progress one frame, handle all network traffic
- */
-void NG_NetworkScene::proceed(double curtime)
-{
- if (!m_networkdevice) return;
- if (!m_networkdevice->IsOnline()) return;
-
- ClearAllMessageMaps();
-
- // read all NetworkMessages from the device
- vector<NG_NetworkMessage*> messages =
- m_networkdevice->RetrieveNetworkMessages();
-
- vector<NG_NetworkMessage*>::iterator mesit = messages.begin();
- for (; !(mesit == messages.end()); mesit++) {
- NG_NetworkMessage* message = (*mesit);
- vector<NG_NetworkMessage*>* tmplist=NULL;
-
- vector<NG_NetworkMessage*>** tmplistptr =
- m_messagesByDestinationName[message->GetDestinationName()];
- // if there is already a vector of messages, append, else create
- // a new vector and insert into map
- if (!tmplistptr) {
- tmplist = new vector<NG_NetworkMessage*>;
- m_messagesByDestinationName.insert(message->GetDestinationName(),
- tmplist);
- } else {
- tmplist = *tmplistptr;
- }
- message->AddRef();
- tmplist->push_back(message);
- tmplist = NULL;
-
- tmplistptr = m_messagesBySenderName[message->GetSenderName()];
- // if there is already a vector of messages, append, else create
- // a new vector and insert into map
- if (!tmplistptr) {
- tmplist = new vector<NG_NetworkMessage*>;
- m_messagesBySenderName.insert(message->GetSenderName(), tmplist);
- } else {
- tmplist = *tmplistptr;
- }
- message->AddRef();
- tmplist->push_back(message);
- tmplist = NULL;
-
- tmplistptr = m_messagesBySubject[message->GetSubject()];
- // if there is already a vector of messages, append, else create
- // a new vector and insert into map
- if (!tmplistptr) {
- tmplist = new vector<NG_NetworkMessage*>;
- m_messagesBySubject.insert(message->GetSubject(), tmplist);
- } else {
- tmplist = *tmplistptr;
- }
- message->AddRef();
- tmplist->push_back(message);
- tmplist = NULL;
- }
-}
-
-/**
- * add a network object to the network scene
- */
-void NG_NetworkScene::AddObject(NG_NetworkObject* object)
-{
- if (! m_networkdevice->IsOnline()) return;
-
- const STR_String& name = object->GetName();
- m_networkObjects.insert(name, object);
-}
-
-/**
- * remove a network object from the network scene
- */
-void NG_NetworkScene::RemoveObject(NG_NetworkObject* object)
-{
- if (! m_networkdevice->IsOnline()) return;
-
- const STR_String& name = object->GetName();
- m_networkObjects.remove(name);
-}
-
-/**
- * remove all network scene objects at once
- */
-void NG_NetworkScene::RemoveAllObjects()
-{
- m_networkObjects.clear();
-}
-
-/**
- * get a single network object given its name
- */
-NG_NetworkObject* NG_NetworkScene::FindNetworkObject(const STR_String& objname)
-{
- NG_NetworkObject *nwobj = NULL;
- if (! m_networkdevice->IsOnline()) return nwobj;
-
- NG_NetworkObject **nwobjptr = m_networkObjects[objname];
- if (nwobjptr) {
- nwobj = *nwobjptr;
- }
-
- return nwobj;
-}
-
-bool NG_NetworkScene::ConstraintsAreValid(
- const STR_String& from,
- const STR_String& subject,
- NG_NetworkMessage* message)
-{
- vector<NG_NetworkMessage*>** fromlistptr = m_messagesBySenderName[from];
- vector<NG_NetworkMessage*>** subjectlistptr = m_messagesBySubject[subject];
-
- vector<NG_NetworkMessage*>* fromlist = (fromlistptr ? *fromlistptr : NULL);
- vector<NG_NetworkMessage*>* subjectlist = (subjectlistptr ? *subjectlistptr : NULL);
-
- return (
- ( from.IsEmpty() || (!fromlist ? false : (!(std::find(fromlist->begin(), fromlist->end(), message) == fromlist->end())))
- ) &&
- ( subject.IsEmpty() || (!subjectlist ? false : (!(std::find(subjectlist->begin(), subjectlist->end(), message) == subjectlist->end())))
- ));
-}
-
-vector<NG_NetworkMessage*> NG_NetworkScene::FindMessages(
- const STR_String& to,
- const STR_String& from,
- const STR_String& subject,
- bool spamallowed)
-{
- vector<NG_NetworkMessage*> foundmessages;
- bool notfound = false;
-
- // broad phase
- notfound = ((to.IsEmpty() || spamallowed) ? notfound : m_messagesByDestinationName[to] == NULL);
- if (!notfound)
- notfound = (from.IsEmpty() ? notfound : m_messagesBySenderName[from] == NULL);
- if (!notfound)
- notfound = (subject.IsEmpty() ? notfound : m_messagesBySubject[subject] == NULL);
- if (notfound) {
- // it's definitely NOT in the scene, so stop looking
- } else { // narrow phase
- // possibly it's there, but maybe not (false hit)
- if (to.IsEmpty()) {
- // take all messages, and check other fields
- MT_assert(!"objectnames that are empty are not valid, so make it a hobby project :)\n");
- } else {
- //todo: find intersection of messages (that are in other 2 maps)
- vector<NG_NetworkMessage*>** tolistptr = m_messagesByDestinationName[to];
- if (tolistptr) {
- vector<NG_NetworkMessage*>* tolist = *tolistptr;
- vector<NG_NetworkMessage*>::iterator listit;
- for (listit=tolist->begin();!(listit==tolist->end());listit++) {
- NG_NetworkMessage* message = *listit;
- if (ConstraintsAreValid(from, subject, message)) {
- message->AddRef();
- foundmessages.push_back(message);
- }
- }
- }
- // TODO find intersection of messages (that are in other 2 maps)
- if (spamallowed) {
- tolistptr = m_messagesByDestinationName[""];
- if (tolistptr) {
- vector<NG_NetworkMessage*>* tolist = *tolistptr;
- vector<NG_NetworkMessage*>::iterator listit;
- for (listit=tolist->begin();!(listit==tolist->end());listit++) {
- NG_NetworkMessage* message = *listit;
- if (ConstraintsAreValid(from, subject, message)) {
- message->AddRef();
- foundmessages.push_back(message);
- }
- }
- }
- }
- }
- }
- return foundmessages;
-}
-
-void NG_NetworkScene::SendMessage(
- const STR_String& to,
- const STR_String& from,
- const STR_String& subject,
- const STR_String& message)
-{
- NG_NetworkMessage* msg = new NG_NetworkMessage(to, from, subject, message);
- m_networkdevice->SendNetworkMessage(msg);
- msg->Release();
-}
-
-void NG_NetworkScene::ClearAllMessageMaps(void)
-{
- ClearMessageMap(m_messagesByDestinationName);
- ClearMessageMap(m_messagesBySenderName);
- ClearMessageMap(m_messagesBySubject);
-}
-
-void NG_NetworkScene::ClearMessageMap(TMessageMap& map)
-{
- // Release the messages in the map
- for (int i = 0; i < map.size(); i++) {
- vector<NG_NetworkMessage*>* msglist;
- msglist = *(map.at(i));
-
- // Iterate through the current vector and release all it's messages
- vector<NG_NetworkMessage*>::iterator msgit;
- for (msgit = msglist->begin(); msgit != msglist->end(); msgit++) {
- (*msgit)->Release();
- }
-
- // Delete the actual vector
- delete (msglist);
- }
-
- // Empty the map
- map.clear();
-}
-
diff --git a/source/gameengine/Network/NG_NetworkScene.h b/source/gameengine/Network/NG_NetworkScene.h
deleted file mode 100644
index e6233852ee2..00000000000
--- a/source/gameengine/Network/NG_NetworkScene.h
+++ /dev/null
@@ -1,118 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file NG_NetworkScene.h
- * \ingroup bgenet
- * \brief NetworkSceneManagement generic class
- */
-#ifndef __NG_NETWORKSCENE_H__
-#define __NG_NETWORKSCENE_H__
-
-#include "CTR_Map.h"
-#include "STR_HashedString.h"
-#include <vector>
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-//MSVC defines SendMessage as a win api function, even though we aren't using it
-#ifdef SendMessage
-# undef SendMessage
-#endif
-
-using namespace std;
-
-class NG_NetworkDeviceInterface;
-
-class NG_NetworkScene
-{
- class NG_NetworkDeviceInterface *m_networkdevice;
- CTR_Map<STR_HashedString, class NG_NetworkObject *> m_networkObjects;
-
- // CTR_Maps used as a 'Bloom' filter
- typedef CTR_Map<STR_HashedString, std::vector<class NG_NetworkMessage*>* > TMessageMap;
- TMessageMap m_messagesByDestinationName;
- TMessageMap m_messagesBySenderName;
- TMessageMap m_messagesBySubject;
-
-public:
- NG_NetworkScene(NG_NetworkDeviceInterface *nic);
- ~NG_NetworkScene();
-
- /**
- * progress one frame, handle all network traffic
- */
- void proceed(double curtime);
-
- /**
- * add a networkobject to the scene
- */
- void AddObject(NG_NetworkObject* object);
-
- /**
- * remove a networkobject to the scene
- */
- void RemoveObject(NG_NetworkObject* object);
-
- /**
- * remove all objects at once
- */
- void RemoveAllObjects();
-
- /**
- * send a message (ascii text) over the network
- */
- void SendMessage(const STR_String& to,const STR_String& from,const STR_String& subject,const STR_String& message);
-
- /**
- * find an object by name
- */
- NG_NetworkObject* FindNetworkObject(const STR_String& objname);
-
- bool ConstraintsAreValid(const STR_String& from,const STR_String& subject,class NG_NetworkMessage* message);
- vector<NG_NetworkMessage*> FindMessages(const STR_String& to,const STR_String& from,const STR_String& subject,bool spamallowed);
-
-protected:
- /**
- * Releases messages in message map members.
- */
- void ClearAllMessageMaps(void);
-
- /**
- * Releases messages for the given message map.
- * \param map Message map with messages.
- */
- void ClearMessageMap(TMessageMap& map);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:NG_NetworkScene")
-#endif
-};
-
-#endif /* __NG_NETWORKSCENE_H__ */
diff --git a/source/gameengine/Physics/Bullet/CMakeLists.txt b/source/gameengine/Physics/Bullet/CMakeLists.txt
deleted file mode 100644
index 8b00f1b47fa..00000000000
--- a/source/gameengine/Physics/Bullet/CMakeLists.txt
+++ /dev/null
@@ -1,73 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-# since this includes bullet we get errors from the headers too
-remove_strict_flags()
-
-set(INC
- .
- ../common
- ../../Converter
- ../../Expressions
- ../../GameLogic
- ../../Ketsji
- ../../Rasterizer
- ../../SceneGraph
- ../../../blender/blenkernel
- ../../../blender/blenlib
- ../../../blender/gpu
- ../../../blender/makesdna
- ../../../../intern/container
- ../../../../intern/guardedalloc
- ../../../../intern/glew-mx
- ../../../../intern/string
-)
-
-set(INC_SYS
- ../../../../intern/moto/include
- ${GLEW_INCLUDE_PATH}
- ${PYTHON_INCLUDE_DIRS}
-)
-
-set(SRC
- CcdPhysicsEnvironment.cpp
- CcdPhysicsController.cpp
- CcdGraphicController.cpp
-
- CcdGraphicController.h
- CcdPhysicsController.h
- CcdPhysicsEnvironment.h
-)
-
-if(WITH_BULLET)
- list(APPEND INC_SYS
- ${BULLET_INCLUDE_DIRS}
- )
- add_definitions(-DWITH_BULLET)
-endif()
-
-add_definitions(${GL_DEFINITIONS})
-
-blender_add_lib(ge_phys_bullet "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Physics/Bullet/CcdGraphicController.cpp b/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
deleted file mode 100644
index 470a5431843..00000000000
--- a/source/gameengine/Physics/Bullet/CcdGraphicController.cpp
+++ /dev/null
@@ -1,152 +0,0 @@
-/** \file gameengine/Physics/Bullet/CcdGraphicController.cpp
- * \ingroup physbullet
- */
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-#include "CcdPhysicsEnvironment.h"
-#include "CcdGraphicController.h"
-#include "btBulletDynamicsCommon.h"
-#include "MT_Point3.h"
-
-
-CcdGraphicController::CcdGraphicController (CcdPhysicsEnvironment* phyEnv, PHY_IMotionState* motionState) :
- m_localAabbMin(0.f, 0.f, 0.f),
- m_localAabbMax(0.f, 0.f, 0.f),
- m_motionState(motionState),
- m_phyEnv(phyEnv),
- m_handle(NULL),
- m_newClientInfo(NULL)
-{
-}
-
-CcdGraphicController::~CcdGraphicController()
-{
- if (m_phyEnv)
- m_phyEnv->RemoveCcdGraphicController(this);
-
- if (m_motionState)
- delete m_motionState;
-}
-
-void CcdGraphicController::SetLocalAabb(const btVector3& aabbMin,const btVector3& aabbMax)
-{
- m_localAabbMin = aabbMin;
- m_localAabbMax = aabbMax;
- SetGraphicTransform();
-}
-
-void CcdGraphicController::SetLocalAabb(const MT_Point3& aabbMin,const MT_Point3& aabbMax)
-{
- m_localAabbMin.setValue(aabbMin[0],aabbMin[1],aabbMin[2]);
- m_localAabbMax.setValue(aabbMax[0],aabbMax[1],aabbMax[2]);
- SetGraphicTransform();
-}
-
-void CcdGraphicController::SetLocalAabb(const MT_Vector3& aabbMin,const MT_Vector3& aabbMax)
-{
- m_localAabbMin.setValue(aabbMin[0],aabbMin[1],aabbMin[2]);
- m_localAabbMax.setValue(aabbMax[0],aabbMax[1],aabbMax[2]);
- SetGraphicTransform();
-}
-
-void CcdGraphicController::SetLocalAabb(const float* aabbMin,const float* aabbMax)
-{
- m_localAabbMin.setValue(aabbMin[0],aabbMin[1],aabbMin[2]);
- m_localAabbMax.setValue(aabbMax[0],aabbMax[1],aabbMax[2]);
- SetGraphicTransform();
-}
-
-void CcdGraphicController::GetAabb(btVector3& aabbMin, btVector3& aabbMax)
-{
- btVector3 pos;
- btVector3 scale;
- float ori[12];
- m_motionState->GetWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);
- m_motionState->GetWorldScaling(scale.m_floats[0],scale.m_floats[1],scale.m_floats[2]);
- m_motionState->GetWorldOrientation(ori);
- btMatrix3x3 rot(ori[0], ori[4], ori[8],
- ori[1], ori[5], ori[9],
- ori[2], ori[6], ori[10]);
-
- btVector3 localAabbMin = m_localAabbMin;
- btVector3 localAabbMax = m_localAabbMax;
- btVector3 tmpAabbMin = m_localAabbMin * scale;
- btVector3 tmpAabbMax = m_localAabbMax * scale;
-
- localAabbMin[0] = (scale.getX() >= 0.0f) ? tmpAabbMin[0] : tmpAabbMax[0];
- localAabbMin[1] = (scale.getY() >= 0.0f) ? tmpAabbMin[1] : tmpAabbMax[1];
- localAabbMin[2] = (scale.getZ() >= 0.0f) ? tmpAabbMin[2] : tmpAabbMax[2];
- localAabbMax[0] = (scale.getX() <= 0.0f) ? tmpAabbMin[0] : tmpAabbMax[0];
- localAabbMax[1] = (scale.getY() <= 0.0f) ? tmpAabbMin[1] : tmpAabbMax[1];
- localAabbMax[2] = (scale.getZ() <= 0.0f) ? tmpAabbMin[2] : tmpAabbMax[2];
-
- btVector3 localHalfExtents = btScalar(0.5f)*(localAabbMax-localAabbMin);
- btVector3 localCenter = btScalar(0.5f)*(localAabbMax+localAabbMin);
-
- btMatrix3x3 abs_b = rot.absolute();
- btVector3 center = rot*localCenter + pos;
- btVector3 extent = abs_b*localHalfExtents;
- aabbMin = center - extent;
- aabbMax = center + extent;
-}
-
-bool CcdGraphicController::SetGraphicTransform()
-{
- if (!m_handle)
- return false;
- btVector3 aabbMin;
- btVector3 aabbMax;
- GetAabb(aabbMin, aabbMax);
- // update Aabb in broadphase
- m_phyEnv->GetCullingTree()->setAabb(m_handle,aabbMin,aabbMax,NULL);
- return true;
-}
-
-PHY_IGraphicController* CcdGraphicController::GetReplica(class PHY_IMotionState* motionState)
-{
- CcdGraphicController* replica = new CcdGraphicController(*this);
- replica->m_motionState = motionState;
- replica->m_newClientInfo = NULL;
- replica->m_handle = NULL;
- // don't add the graphic controller now: work around a bug in Bullet with rescaling,
- // (the scale of the controller is not yet defined).
- //m_phyEnv->addCcdGraphicController(replica);
- return replica;
-}
-
-void CcdGraphicController::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* env)
-{
- CcdPhysicsEnvironment* phyEnv = static_cast<CcdPhysicsEnvironment*>(env);
- /* Updates the m_phyEnv's m_cullingTree & m_cullingCache */
- if (GetBroadphaseHandle()) {
- /* insert into the new physics scene */
- Activate(false);
- m_phyEnv= phyEnv;
- Activate(true);
- }
- else {
- m_phyEnv= phyEnv;
- }
-}
-
-void CcdGraphicController::Activate(bool active)
-{
- if (active)
- m_phyEnv->AddCcdGraphicController(this);
- else
- m_phyEnv->RemoveCcdGraphicController(this);
-
-}
diff --git a/source/gameengine/Physics/Bullet/CcdGraphicController.h b/source/gameengine/Physics/Bullet/CcdGraphicController.h
deleted file mode 100644
index e76ad86301e..00000000000
--- a/source/gameengine/Physics/Bullet/CcdGraphicController.h
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-/** \file CcdGraphicController.h
- * \ingroup physbullet
- */
-
-
-#ifndef __CCDGRAPHICCONTROLLER_H__
-#define __CCDGRAPHICCONTROLLER_H__
-
-#include "PHY_IGraphicController.h"
-
-#include "btBulletDynamicsCommon.h"
-#include "LinearMath/btTransform.h"
-
-#include "PHY_IMotionState.h"
-#include "MT_Point3.h"
-
-class CcdPhysicsEnvironment;
-class btCollisionObject;
-
-///CcdGraphicController is a graphic object that supports view frustrum culling and occlusion
-class CcdGraphicController : public PHY_IGraphicController
-{
-public:
- CcdGraphicController(CcdPhysicsEnvironment* phyEnv, PHY_IMotionState* motionState);
-
- virtual ~CcdGraphicController();
-
- void SetLocalAabb(const btVector3& aabbMin,const btVector3& aabbMax);
- void SetLocalAabb(const MT_Point3& aabbMin,const MT_Point3& aabbMax);
- virtual void SetLocalAabb(const MT_Vector3& aabbMin,const MT_Vector3& aabbMax);
- virtual void SetLocalAabb(const float aabbMin[3],const float aabbMax[3]);
-
- PHY_IMotionState* GetMotionState() { return m_motionState; }
- void GetAabb(btVector3& aabbMin, btVector3& aabbMax);
-
- virtual void SetBroadphaseHandle(btBroadphaseProxy* handle) { m_handle = handle; }
- virtual btBroadphaseProxy* GetBroadphaseHandle() { return m_handle; }
-
- virtual void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment* env);
-
- ////////////////////////////////////
- // PHY_IGraphicController interface
- ////////////////////////////////////
-
- /**
- * Updates the Aabb based on the motion state
- */
- virtual bool SetGraphicTransform();
- /**
- * Add/remove to environment
- */
- virtual void Activate(bool active);
-
- // client info for culling
- virtual void* GetNewClientInfo() { return m_newClientInfo; }
- virtual void SetNewClientInfo(void* clientinfo) { m_newClientInfo = clientinfo; }
- virtual PHY_IGraphicController* GetReplica(class PHY_IMotionState* motionstate);
-
-private:
- // unscaled aabb corner
- btVector3 m_localAabbMin;
- btVector3 m_localAabbMax;
-
- PHY_IMotionState* m_motionState;
- CcdPhysicsEnvironment* m_phyEnv;
- btBroadphaseProxy* m_handle;
- void* m_newClientInfo;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CcdGraphicController")
-#endif
-};
-
-#endif /* BULLET2_PHYSICSCONTROLLER_H */
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
deleted file mode 100644
index c79e1c23ef6..00000000000
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.cpp
+++ /dev/null
@@ -1,2664 +0,0 @@
-/** \file gameengine/Physics/Bullet/CcdPhysicsController.cpp
- * \ingroup physbullet
- */
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-#ifndef WIN32
-#include <stdint.h>
-#endif
-
-#include "CcdPhysicsController.h"
-#include "btBulletDynamicsCommon.h"
-#include "BulletCollision/CollisionDispatch/btGhostObject.h"
-#include "BulletCollision/CollisionShapes/btScaledBvhTriangleMeshShape.h"
-#include "BulletCollision/CollisionShapes/btTriangleIndexVertexArray.h"
-
-#include "PHY_IMotionState.h"
-#include "CcdPhysicsEnvironment.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-#include "RAS_Deformer.h"
-#include "KX_GameObject.h"
-
-#include "BulletSoftBody/btSoftBody.h"
-#include "BulletSoftBody/btSoftBodyInternals.h"
-#include "BulletSoftBody/btSoftBodyHelpers.h"
-#include "LinearMath/btConvexHull.h"
-#include "BulletCollision/Gimpact/btGImpactShape.h"
-
-#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
-
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-
-extern "C"{
- #include "BLI_utildefines.h"
- #include "BKE_cdderivedmesh.h"
-}
-
-
-class BP_Proxy;
-
-///todo: fill all the empty CcdPhysicsController methods, hook them up to the btRigidBody class
-
-//'temporarily' global variables
-//float gDeactivationTime = 2.f;
-//bool gDisableDeactivation = false;
-extern float gDeactivationTime;
-extern bool gDisableDeactivation;
-
-
-float gLinearSleepingTreshold;
-float gAngularSleepingTreshold;
-
-BlenderBulletCharacterController::BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight)
- : btKinematicCharacterController(ghost,shape,stepHeight,2),
- m_motionState(motionState),
- m_jumps(0),
- m_maxJumps(1)
-{
-}
-
-void BlenderBulletCharacterController::updateAction(btCollisionWorld *collisionWorld, btScalar dt)
-{
- if (onGround())
- m_jumps = 0;
-
- btKinematicCharacterController::updateAction(collisionWorld,dt);
- m_motionState->setWorldTransform(getGhostObject()->getWorldTransform());
-}
-
-unsigned char BlenderBulletCharacterController::getMaxJumps() const
-{
- return m_maxJumps;
-}
-
-void BlenderBulletCharacterController::setMaxJumps(unsigned char maxJumps)
-{
- m_maxJumps = maxJumps;
-}
-
-unsigned char BlenderBulletCharacterController::getJumpCount() const
-{
- return m_jumps;
-}
-
-bool BlenderBulletCharacterController::canJump() const
-{
- return (onGround() && m_maxJumps > 0) || m_jumps < m_maxJumps;
-}
-
-void BlenderBulletCharacterController::jump()
-{
- if (!canJump())
- return;
-
- m_verticalVelocity = m_jumpSpeed;
- m_wasJumping = true;
- m_jumps++;
-}
-
-const btVector3& BlenderBulletCharacterController::getWalkDirection()
-{
- return m_walkDirection;
-}
-
-bool CleanPairCallback::processOverlap(btBroadphasePair &pair)
-{
- if ((pair.m_pProxy0 == m_cleanProxy) || (pair.m_pProxy1 == m_cleanProxy)) {
- m_pairCache->cleanOverlappingPair(pair, m_dispatcher);
- CcdPhysicsController *ctrl0 = (CcdPhysicsController*)(((btCollisionObject*)pair.m_pProxy0->m_clientObject)->getUserPointer());
- CcdPhysicsController *ctrl1 = (CcdPhysicsController*)(((btCollisionObject*)pair.m_pProxy1->m_clientObject)->getUserPointer());
- ctrl0->GetCollisionObject()->activate(false);
- ctrl1->GetCollisionObject()->activate(false);
- }
- return false;
-}
-
-CcdPhysicsController::CcdPhysicsController (const CcdConstructionInfo& ci)
-:m_cci(ci)
-{
- m_prototypeTransformInitialized = false;
- m_softbodyMappingDone = false;
- m_collisionDelay = 0;
- m_newClientInfo = 0;
- m_registerCount = 0;
- m_softBodyTransformInitialized = false;
- m_parentCtrl = 0;
- // copy pointers locally to allow smart release
- m_MotionState = ci.m_MotionState;
- m_collisionShape = ci.m_collisionShape;
- // apply scaling before creating rigid body
- m_collisionShape->setLocalScaling(m_cci.m_scaling);
- if (m_cci.m_mass)
- m_collisionShape->calculateLocalInertia(m_cci.m_mass, m_cci.m_localInertiaTensor);
- // shape info is shared, increment ref count
- m_shapeInfo = ci.m_shapeInfo;
- if (m_shapeInfo)
- m_shapeInfo->AddRef();
-
- m_bulletChildShape = NULL;
-
- m_bulletMotionState = 0;
- m_characterController = 0;
- m_savedCollisionFlags = 0;
- m_savedCollisionFilterGroup = 0;
- m_savedCollisionFilterMask = 0;
- m_savedMass = 0.0f;
- m_savedDyna = false;
- m_suspended = false;
-
- CreateRigidbody();
-}
-
-void CcdPhysicsController::addCcdConstraintRef(btTypedConstraint* c)
-{
- int index = m_ccdConstraintRefs.findLinearSearch(c);
- if (index == m_ccdConstraintRefs.size())
- m_ccdConstraintRefs.push_back(c);
-}
-
-void CcdPhysicsController::removeCcdConstraintRef(btTypedConstraint* c)
-{
- m_ccdConstraintRefs.remove(c);
-}
-
-btTypedConstraint* CcdPhysicsController::getCcdConstraintRef(int index)
-{
- return m_ccdConstraintRefs[index];
-}
-
-int CcdPhysicsController::getNumCcdConstraintRefs() const
-{
- return m_ccdConstraintRefs.size();
-}
-
-btTransform& CcdPhysicsController::GetTransformFromMotionState(PHY_IMotionState* motionState)
-{
- static btTransform trans;
- btVector3 tmp;
- motionState->GetWorldPosition(tmp.m_floats[0], tmp.m_floats[1], tmp.m_floats[2]);
- trans.setOrigin(tmp);
-
- float ori[12];
- motionState->GetWorldOrientation(ori);
- trans.getBasis().setFromOpenGLSubMatrix(ori);
- //btQuaternion orn;
- //motionState->getWorldOrientation(orn[0],orn[1],orn[2],orn[3]);
- //trans.setRotation(orn);
- return trans;
-
-}
-
-class BlenderBulletMotionState : public btMotionState
-{
- PHY_IMotionState* m_blenderMotionState;
-
-public:
-
- BlenderBulletMotionState(PHY_IMotionState* bms)
- :m_blenderMotionState(bms)
- {
-
- }
-
- void getWorldTransform(btTransform& worldTrans ) const
- {
- btVector3 pos;
- float ori[12];
-
- m_blenderMotionState->GetWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);
- m_blenderMotionState->GetWorldOrientation(ori);
- worldTrans.setOrigin(pos);
- worldTrans.getBasis().setFromOpenGLSubMatrix(ori);
- }
-
- void setWorldTransform(const btTransform& worldTrans)
- {
- m_blenderMotionState->SetWorldPosition(worldTrans.getOrigin().getX(),worldTrans.getOrigin().getY(),worldTrans.getOrigin().getZ());
- btQuaternion rotQuat = worldTrans.getRotation();
- m_blenderMotionState->SetWorldOrientation(rotQuat[0],rotQuat[1],rotQuat[2],rotQuat[3]);
- m_blenderMotionState->CalculateWorldTransformations();
- }
-
-};
-
-btRigidBody* CcdPhysicsController::GetRigidBody()
-{
- return btRigidBody::upcast(m_object);
-}
-const btRigidBody* CcdPhysicsController::GetRigidBody() const
-{
- return btRigidBody::upcast(m_object);
-}
-
-btCollisionObject* CcdPhysicsController::GetCollisionObject()
-{
- return m_object;
-}
-btSoftBody* CcdPhysicsController::GetSoftBody()
-{
- return btSoftBody::upcast(m_object);
-}
-btKinematicCharacterController* CcdPhysicsController::GetCharacterController()
-{
- return m_characterController;
-}
-
-#include "BulletSoftBody/btSoftBodyHelpers.h"
-
-
-bool CcdPhysicsController::CreateSoftbody()
-{
- int shapeType = m_cci.m_collisionShape ? m_cci.m_collisionShape->getShapeType() : 0;
-
- //disable soft body until first sneak preview is ready
- if (!m_cci.m_bSoft || !m_cci.m_collisionShape ||
- ((shapeType != CONVEX_HULL_SHAPE_PROXYTYPE)&&
- (shapeType != TRIANGLE_MESH_SHAPE_PROXYTYPE) &&
- (shapeType != SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE)))
- {
- return false;
- }
-
- btRigidBody::btRigidBodyConstructionInfo rbci(m_cci.m_mass,m_bulletMotionState,m_collisionShape,m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
- rbci.m_linearDamping = m_cci.m_linearDamping;
- rbci.m_angularDamping = m_cci.m_angularDamping;
- rbci.m_friction = m_cci.m_friction;
- rbci.m_restitution = m_cci.m_restitution;
-
- btVector3 p(0.0f,0.0f,0.0f);// = getOrigin();
- //btSoftBody* psb=btSoftBodyHelpers::CreateRope(worldInfo, btVector3(-10,0,i*0.25),btVector3(10,0,i*0.25), 16,1+2);
- btSoftBody* psb = 0;
- btSoftBodyWorldInfo& worldInfo = m_cci.m_physicsEnv->GetDynamicsWorld()->getWorldInfo();
-
- if (m_cci.m_collisionShape->getShapeType() == CONVEX_HULL_SHAPE_PROXYTYPE) {
- btConvexHullShape* convexHull = (btConvexHullShape* )m_cci.m_collisionShape;
- {
- int nvertices = convexHull->getNumPoints();
- const btVector3* vertices = convexHull->getPoints();
-
- HullDesc hdsc(QF_TRIANGLES,nvertices,vertices);
- HullResult hres;
- HullLibrary hlib; /*??*/
- hdsc.mMaxVertices=nvertices;
- hlib.CreateConvexHull(hdsc,hres);
-
- psb = new btSoftBody(&worldInfo, (int)hres.mNumOutputVertices,
- &hres.m_OutputVertices[0], 0);
- for (int i = 0; i < (int)hres.mNumFaces; ++i) {
- const unsigned int idx[3] = {hres.m_Indices[i * 3 + 0],
- hres.m_Indices[i * 3 + 1],
- hres.m_Indices[i * 3 + 2]};
- if (idx[0] < idx[1]) psb->appendLink(idx[0], idx[1]);
- if (idx[1] < idx[2]) psb->appendLink(idx[1], idx[2]);
- if (idx[2] < idx[0]) psb->appendLink(idx[2], idx[0]);
- psb->appendFace(idx[0], idx[1], idx[2]);
- }
- hlib.ReleaseResult(hres);
- }
- }
- else {
- int numtris = 0;
- if (m_cci.m_collisionShape->getShapeType() ==SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE)
- {
- btScaledBvhTriangleMeshShape* scaledtrimeshshape = (btScaledBvhTriangleMeshShape*) m_cci.m_collisionShape;
- btBvhTriangleMeshShape* trimeshshape = scaledtrimeshshape->getChildShape();
-
- ///only deal with meshes that have 1 sub part/component, for now
- if (trimeshshape->getMeshInterface()->getNumSubParts()==1)
- {
- unsigned char* vertexBase;
- btScalar* scaledVertexBase;
- btVector3 localScaling;
- PHY_ScalarType vertexType;
- int numverts;
- int vertexstride;
- unsigned char* indexbase;
- int indexstride;
- PHY_ScalarType indexType;
- trimeshshape->getMeshInterface()->getLockedVertexIndexBase(&vertexBase,numverts,vertexType,vertexstride,&indexbase,indexstride,numtris,indexType);
- localScaling = scaledtrimeshshape->getLocalScaling();
- scaledVertexBase = new btScalar[numverts*3];
- for (int i=0; i<numverts*3; i+=3)
- {
- scaledVertexBase[i] = ((const btScalar*)vertexBase)[i] * localScaling.getX();
- scaledVertexBase[i+1] = ((const btScalar*)vertexBase)[i+1] * localScaling.getY();
- scaledVertexBase[i+2] = ((const btScalar*)vertexBase)[i+2] * localScaling.getZ();
- }
- psb = btSoftBodyHelpers::CreateFromTriMesh(worldInfo,scaledVertexBase,(const int*)indexbase,numtris,false);
- delete [] scaledVertexBase;
- }
- } else
- {
- btTriangleMeshShape* trimeshshape = (btTriangleMeshShape*) m_cci.m_collisionShape;
- ///only deal with meshes that have 1 sub part/component, for now
- if (trimeshshape->getMeshInterface()->getNumSubParts()==1)
- {
- unsigned char* vertexBase;
- PHY_ScalarType vertexType;
- int numverts;
- int vertexstride;
- unsigned char* indexbase;
- int indexstride;
- PHY_ScalarType indexType;
- trimeshshape->getMeshInterface()->getLockedVertexIndexBase(&vertexBase,numverts,vertexType,vertexstride,&indexbase,indexstride,numtris,indexType);
-
- psb = btSoftBodyHelpers::CreateFromTriMesh(worldInfo,(const btScalar*)vertexBase,(const int*)indexbase,numtris,false);
- }
- }
- // store face tag so that we can find our original face when doing ray casting
- btSoftBody::Face* ft;
- int i;
- for (i=0, ft=&psb->m_faces[0]; i<numtris; ++i, ++ft)
- {
- // Hack!! use m_tag to store the face number, normally it is a pointer
- // add 1 to make sure it is never 0
- ft->m_tag = (void*)((uintptr_t)(i+1));
- }
- }
- if (m_cci.m_margin > 0.f)
- {
- psb->getCollisionShape()->setMargin(m_cci.m_margin);
- psb->updateBounds();
- }
- m_object = psb;
-
- //btSoftBody::Material* pm=psb->appendMaterial();
- btSoftBody::Material* pm=psb->m_materials[0];
- pm->m_kLST = m_cci.m_soft_linStiff;
- pm->m_kAST = m_cci.m_soft_angStiff;
- pm->m_kVST = m_cci.m_soft_volume;
- psb->m_cfg.collisions = 0;
-
- if (m_cci.m_soft_collisionflags & CCD_BSB_COL_CL_RS)
- {
- psb->m_cfg.collisions += btSoftBody::fCollision::CL_RS;
- } else
- {
- psb->m_cfg.collisions += btSoftBody::fCollision::SDF_RS;
- }
- if (m_cci.m_soft_collisionflags & CCD_BSB_COL_CL_SS)
- {
- psb->m_cfg.collisions += btSoftBody::fCollision::CL_SS;
- } else
- {
- psb->m_cfg.collisions += btSoftBody::fCollision::VF_SS;
- }
-
-
- psb->m_cfg.kSRHR_CL = m_cci.m_soft_kSRHR_CL; /* Soft vs rigid hardness [0,1] (cluster only) */
- psb->m_cfg.kSKHR_CL = m_cci.m_soft_kSKHR_CL; /* Soft vs kinetic hardness [0,1] (cluster only) */
- psb->m_cfg.kSSHR_CL = m_cci.m_soft_kSSHR_CL; /* Soft vs soft hardness [0,1] (cluster only) */
- psb->m_cfg.kSR_SPLT_CL = m_cci.m_soft_kSR_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
-
- psb->m_cfg.kSK_SPLT_CL = m_cci.m_soft_kSK_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- psb->m_cfg.kSS_SPLT_CL = m_cci.m_soft_kSS_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- psb->m_cfg.kVCF = m_cci.m_soft_kVCF; /* Velocities correction factor (Baumgarte) */
- psb->m_cfg.kDP = m_cci.m_soft_kDP; /* Damping coefficient [0,1] */
-
- psb->m_cfg.kDG = m_cci.m_soft_kDG; /* Drag coefficient [0,+inf] */
- psb->m_cfg.kLF = m_cci.m_soft_kLF; /* Lift coefficient [0,+inf] */
- psb->m_cfg.kPR = m_cci.m_soft_kPR; /* Pressure coefficient [-inf,+inf] */
- psb->m_cfg.kVC = m_cci.m_soft_kVC; /* Volume conversation coefficient [0,+inf] */
-
- psb->m_cfg.kDF = m_cci.m_soft_kDF; /* Dynamic friction coefficient [0,1] */
- psb->m_cfg.kMT = m_cci.m_soft_kMT; /* Pose matching coefficient [0,1] */
- psb->m_cfg.kCHR = m_cci.m_soft_kCHR; /* Rigid contacts hardness [0,1] */
- psb->m_cfg.kKHR = m_cci.m_soft_kKHR; /* Kinetic contacts hardness [0,1] */
-
- psb->m_cfg.kSHR = m_cci.m_soft_kSHR; /* Soft contacts hardness [0,1] */
- psb->m_cfg.kAHR = m_cci.m_soft_kAHR; /* Anchors hardness [0,1] */
-
- if (m_cci.m_gamesoftFlag & CCD_BSB_BENDING_CONSTRAINTS)//OB_SB_GOAL)
- {
- psb->generateBendingConstraints(2,pm);
- }
-
- psb->m_cfg.piterations = m_cci.m_soft_piterations;
- psb->m_cfg.viterations = m_cci.m_soft_viterations;
- psb->m_cfg.diterations = m_cci.m_soft_diterations;
- psb->m_cfg.citerations = m_cci.m_soft_citerations;
-
- if (m_cci.m_gamesoftFlag & CCD_BSB_SHAPE_MATCHING)//OB_SB_GOAL)
- {
- psb->setPose(false,true);//
- } else
- {
- psb->setPose(true,false);
- }
-
- psb->randomizeConstraints();
-
- if (m_cci.m_soft_collisionflags & (CCD_BSB_COL_CL_RS+CCD_BSB_COL_CL_SS))
- {
- psb->generateClusters(m_cci.m_soft_numclusteriterations);
- }
-
- psb->setTotalMass(m_cci.m_mass);
-
- psb->setCollisionFlags(0);
-
- ///create a mapping between graphics mesh vertices and soft body vertices
- {
- RAS_MeshObject* rasMesh= GetShapeInfo()->GetMesh();
-
- if (rasMesh && !m_softbodyMappingDone)
- {
- //printf("apply\n");
- RAS_MeshSlot::iterator it;
- RAS_MeshMaterial *mmat;
- RAS_MeshSlot *slot;
- size_t i;
-
- //for each material
- for (int m=0;m<rasMesh->NumMaterials();m++)
- {
- mmat = rasMesh->GetMeshMaterial(m);
-
- slot = mmat->m_baseslot;
- for (slot->begin(it); !slot->end(it); slot->next(it))
- {
- int index = 0;
- for (i=it.startvertex; i<it.endvertex; i++,index++)
- {
- RAS_TexVert* vertex = &it.vertex[i];
- //search closest index, and store it in vertex
- vertex->setSoftBodyIndex(0);
- btScalar maxDistSqr = 1e30;
- btSoftBody::tNodeArray& nodes(psb->m_nodes);
- btVector3 xyz = btVector3(vertex->getXYZ()[0],vertex->getXYZ()[1],vertex->getXYZ()[2]);
- for (int n=0;n<nodes.size();n++)
- {
- btScalar distSqr = (nodes[n].m_x - xyz).length2();
- if (distSqr<maxDistSqr)
- {
- maxDistSqr = distSqr;
-
- vertex->setSoftBodyIndex(n);
- }
- }
- }
- }
- }
- }
- }
- m_softbodyMappingDone = true;
-
- btTransform startTrans;
- rbci.m_motionState->getWorldTransform(startTrans);
-
- m_MotionState->SetWorldPosition(startTrans.getOrigin().getX(),startTrans.getOrigin().getY(),startTrans.getOrigin().getZ());
- m_MotionState->SetWorldOrientation(0,0,0,1);
-
- if (!m_prototypeTransformInitialized)
- {
- m_prototypeTransformInitialized = true;
- m_softBodyTransformInitialized = true;
- psb->transform(startTrans);
- }
- m_object->setCollisionFlags(m_object->getCollisionFlags() | m_cci.m_collisionFlags);
- if (m_cci.m_do_anisotropic)
- m_object->setAnisotropicFriction(m_cci.m_anisotropicFriction);
- return true;
-}
-
-bool CcdPhysicsController::CreateCharacterController()
-{
- if (!m_cci.m_bCharacter)
- return false;
-
- m_object = new btPairCachingGhostObject();
- m_object->setCollisionShape(m_collisionShape);
- m_object->setCollisionFlags(btCollisionObject::CF_CHARACTER_OBJECT);
-
- btTransform trans;
- m_bulletMotionState->getWorldTransform(trans);
- m_object->setWorldTransform(trans);
-
- m_characterController = new BlenderBulletCharacterController(m_bulletMotionState,(btPairCachingGhostObject*)m_object,(btConvexShape*)m_collisionShape,m_cci.m_stepHeight);
-
- m_characterController->setJumpSpeed(m_cci.m_jumpSpeed);
- m_characterController->setFallSpeed(m_cci.m_fallSpeed);
- m_characterController->setMaxJumps(m_cci.m_maxJumps);
-
- return true;
-}
-
-void CcdPhysicsController::CreateRigidbody()
-{
-
- //btTransform trans = GetTransformFromMotionState(m_MotionState);
- m_bulletMotionState = new BlenderBulletMotionState(m_MotionState);
-
- ///either create a btCollisionObject, btRigidBody or btSoftBody
- if (CreateSoftbody() || CreateCharacterController())
- // soft body created, done
- return;
-
- //create a rgid collision object
- btRigidBody::btRigidBodyConstructionInfo rbci(m_cci.m_mass,m_bulletMotionState,m_collisionShape,m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
- rbci.m_linearDamping = m_cci.m_linearDamping;
- rbci.m_angularDamping = m_cci.m_angularDamping;
- rbci.m_friction = m_cci.m_friction;
- rbci.m_restitution = m_cci.m_restitution;
- m_object = new btRigidBody(rbci);
-
- //
- // init the rigidbody properly
- //
-
- //setMassProps this also sets collisionFlags
- //convert collision flags!
- //special case: a near/radar sensor controller should not be defined static or it will
- //generate loads of static-static collision messages on the console
- if (m_cci.m_bSensor)
- {
- // reset the flags that have been set so far
- GetCollisionObject()->setCollisionFlags(0);
- // sensor must never go to sleep: they need to detect continously
- GetCollisionObject()->setActivationState(DISABLE_DEACTIVATION);
- }
- GetCollisionObject()->setCollisionFlags(m_object->getCollisionFlags() | m_cci.m_collisionFlags);
- btRigidBody* body = GetRigidBody();
-
- if (body)
- {
- body->setGravity( m_cci.m_gravity);
- body->setDamping(m_cci.m_linearDamping, m_cci.m_angularDamping);
-
- if (!m_cci.m_bRigid)
- {
- body->setAngularFactor(0.f);
- }
- // use bullet's default contact processing theshold, blender's old default of 1 is too small here.
- // if there's really a need to change this, it should be exposed in the ui first.
-// body->setContactProcessingThreshold(m_cci.m_contactProcessingThreshold);
- body->setSleepingThresholds(gLinearSleepingTreshold, gAngularSleepingTreshold);
-
- }
- if (m_object && m_cci.m_do_anisotropic)
- {
- m_object->setAnisotropicFriction(m_cci.m_anisotropicFriction);
- }
-
-}
-
-static void DeleteBulletShape(btCollisionShape* shape, bool free)
-{
- if (shape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE) {
- /* If we use Bullet scaled shape (btScaledBvhTriangleMeshShape) we have to
- * free the child of the unscaled shape (btTriangleMeshShape) here.
- */
- btTriangleMeshShape *meshShape = ((btScaledBvhTriangleMeshShape *)shape)->getChildShape();
- if (meshShape)
- delete meshShape;
- }
- if (free) {
- delete shape;
- }
-}
-
-bool CcdPhysicsController::DeleteControllerShape( )
-{
- if (m_collisionShape)
- {
- // collision shape is always unique to the controller, can delete it here
- if (m_collisionShape->isCompound())
- {
- // bullet does not delete the child shape, must do it here
- btCompoundShape* compoundShape = (btCompoundShape*)m_collisionShape;
- int numChild = compoundShape->getNumChildShapes();
- for (int i=numChild-1 ; i >= 0; i--)
- {
- btCollisionShape* childShape = compoundShape->getChildShape(i);
- DeleteBulletShape(childShape, true);
- }
- }
- DeleteBulletShape(m_collisionShape, true);
-
- return true;
- }
-
- return false;
-}
-
-bool CcdPhysicsController::ReplaceControllerShape(btCollisionShape *newShape)
-{
- if (m_collisionShape)
- DeleteControllerShape();
-
- // If newShape is NULL it means to create a new Bullet shape.
- if (!newShape)
- newShape = m_shapeInfo->CreateBulletShape(m_cci.m_margin, m_cci.m_bGimpact, !m_cci.m_bSoft);
-
- m_object->setCollisionShape(newShape);
- m_collisionShape = newShape;
- m_cci.m_collisionShape = newShape;
-
- btSoftBody *softBody = GetSoftBody();
- if (softBody) {
- btSoftRigidDynamicsWorld *world = GetPhysicsEnvironment()->GetDynamicsWorld();
- // remove the old softBody
- world->removeSoftBody(softBody);
-
- // soft body must be recreated
- delete m_object;
- m_object = NULL;
- // force complete reinitialization
- m_softbodyMappingDone = false;
- m_prototypeTransformInitialized = false;
- m_softBodyTransformInitialized = false;
-
- CreateSoftbody();
- assert(m_object);
-
- btSoftBody *newSoftBody = GetSoftBody();
- // set the user
- newSoftBody->setUserPointer(this);
- // add the new softbody
- world->addSoftBody(newSoftBody);
- }
-
- return true;
-}
-
-CcdPhysicsController::~CcdPhysicsController()
-{
- //will be reference counted, due to sharing
- if (m_cci.m_physicsEnv)
- m_cci.m_physicsEnv->RemoveCcdPhysicsController(this);
-
- if (m_MotionState)
- delete m_MotionState;
- if (m_bulletMotionState)
- delete m_bulletMotionState;
- if (m_characterController)
- delete m_characterController;
- delete m_object;
-
- DeleteControllerShape();
-
- if (m_shapeInfo)
- {
- m_shapeInfo->Release();
- }
-}
-
-void CcdPhysicsController::SimulationTick(float timestep)
-{
- btRigidBody *body = GetRigidBody();
- if (!body || body->isStaticObject())
- return;
-
- // Clamp linear velocity
- if (m_cci.m_clamp_vel_max > 0.0f || m_cci.m_clamp_vel_min > 0.0f) {
- const btVector3 &linvel = body->getLinearVelocity();
- btScalar len = linvel.length();
-
- if (m_cci.m_clamp_vel_max > 0.0f && len > m_cci.m_clamp_vel_max)
- body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_max / len));
- else if (m_cci.m_clamp_vel_min > 0.0f && !btFuzzyZero(len) && len < m_cci.m_clamp_vel_min)
- body->setLinearVelocity(linvel * (m_cci.m_clamp_vel_min / len));
- }
-
- // Clamp angular velocity
- if (m_cci.m_clamp_angvel_max > 0.0f || m_cci.m_clamp_angvel_min > 0.0f) {
- const btVector3 &angvel = body->getAngularVelocity();
- btScalar len = angvel.length();
-
- if (m_cci.m_clamp_angvel_max > 0.0f && len > m_cci.m_clamp_angvel_max)
- body->setAngularVelocity(angvel * (m_cci.m_clamp_angvel_max / len));
- else if (m_cci.m_clamp_angvel_min > 0.0f && !btFuzzyZero(len) && len < m_cci.m_clamp_angvel_min)
- body->setAngularVelocity(angvel * (m_cci.m_clamp_angvel_min / len));
- }
-}
-
-
-/**
- * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
- */
-bool CcdPhysicsController::SynchronizeMotionStates(float time)
-{
- //sync non-static to motionstate, and static from motionstate (todo: add kinematic etc.)
-
- btSoftBody* sb = GetSoftBody();
- if (sb)
- {
- if (sb->m_pose.m_bframe)
- {
- btVector3 worldPos = sb->m_pose.m_com;
- btQuaternion worldquat;
- btMatrix3x3 trs = sb->m_pose.m_rot*sb->m_pose.m_scl;
- trs.getRotation(worldquat);
- m_MotionState->SetWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
- m_MotionState->SetWorldOrientation(worldquat[0],worldquat[1],worldquat[2],worldquat[3]);
- }
- else
- {
- btVector3 aabbMin,aabbMax;
- sb->getAabb(aabbMin,aabbMax);
- btVector3 worldPos = (aabbMax+aabbMin)*0.5f;
- m_MotionState->SetWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
- }
- m_MotionState->CalculateWorldTransformations();
- return true;
- }
-
- btRigidBody* body = GetRigidBody();
-
- if (body && !body->isStaticObject())
- {
- const btTransform& xform = body->getCenterOfMassTransform();
- const btMatrix3x3& worldOri = xform.getBasis();
- const btVector3& worldPos = xform.getOrigin();
- float ori[12];
- worldOri.getOpenGLSubMatrix(ori);
- m_MotionState->SetWorldOrientation(ori);
- m_MotionState->SetWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
- m_MotionState->CalculateWorldTransformations();
-
- float scale[3];
- m_MotionState->GetWorldScaling(scale[0],scale[1],scale[2]);
- btVector3 scaling(scale[0],scale[1],scale[2]);
- GetCollisionShape()->setLocalScaling(scaling);
- } else
- {
- btVector3 worldPos;
- btQuaternion worldquat;
-
-/* m_MotionState->getWorldPosition(worldPos[0],worldPos[1],worldPos[2]);
- m_MotionState->getWorldOrientation(worldquat[0],worldquat[1],worldquat[2],worldquat[3]);
- btTransform oldTrans = m_body->getCenterOfMassTransform();
- btTransform newTrans(worldquat,worldPos);
-
- SetCenterOfMassTransform(newTrans);
- //need to keep track of previous position for friction effects...
-
- m_MotionState->calculateWorldTransformations();
-*/
- float scale[3];
- m_MotionState->GetWorldScaling(scale[0],scale[1],scale[2]);
- btVector3 scaling(scale[0],scale[1],scale[2]);
- GetCollisionShape()->setLocalScaling(scaling);
- }
- return true;
-
-}
-
- /**
- * WriteMotionStateToDynamics synchronizes dynas, kinematic and deformable entities (and do 'late binding')
- */
-
-void CcdPhysicsController::WriteMotionStateToDynamics(bool nondynaonly)
-{
- btTransform& xform = CcdPhysicsController::GetTransformFromMotionState(m_MotionState);
- SetCenterOfMassTransform(xform);
-}
-
-void CcdPhysicsController::WriteDynamicsToMotionState()
-{
-}
- // controller replication
-void CcdPhysicsController::PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)
-{
- SetParentCtrl((CcdPhysicsController*)parentctrl);
- m_softBodyTransformInitialized=false;
- m_MotionState = motionstate;
- m_registerCount = 0;
- m_collisionShape = NULL;
-
- // Clear all old constraints.
- m_ccdConstraintRefs.clear();
-
- // always create a new shape to avoid scaling bug
- if (m_shapeInfo)
- {
- m_shapeInfo->AddRef();
- m_collisionShape = m_shapeInfo->CreateBulletShape(m_cci.m_margin, m_cci.m_bGimpact, !m_cci.m_bSoft);
-
- if (m_collisionShape)
- {
- // new shape has no scaling, apply initial scaling
- //m_collisionShape->setMargin(m_cci.m_margin);
- m_collisionShape->setLocalScaling(m_cci.m_scaling);
-
- if (m_cci.m_mass)
- m_collisionShape->calculateLocalInertia(m_cci.m_mass, m_cci.m_localInertiaTensor);
- }
- }
-
- // load some characterists that are not
- btRigidBody* oldbody = GetRigidBody();
- m_object = 0;
- CreateRigidbody();
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- if (m_cci.m_mass)
- {
- body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
- }
-
- if (oldbody)
- {
- body->setLinearFactor(oldbody->getLinearFactor());
- body->setAngularFactor(oldbody->getAngularFactor());
- if (oldbody->getActivationState() == DISABLE_DEACTIVATION)
- body->setActivationState(DISABLE_DEACTIVATION);
- }
- }
- // sensor object are added when needed
- if (!m_cci.m_bSensor)
- m_cci.m_physicsEnv->AddCcdPhysicsController(this);
-
-
-}
-
-void CcdPhysicsController::SetPhysicsEnvironment(class PHY_IPhysicsEnvironment *env)
-{
- // can safely assume CCD environment
- CcdPhysicsEnvironment *physicsEnv = static_cast<CcdPhysicsEnvironment*>(env);
-
- if (m_cci.m_physicsEnv != physicsEnv)
- {
- // since the environment is changing, we must also move the controler to the
- // new environment. Note that we don't handle sensor explicitly: this
- // function can be called on sensor but only when they are not registered
- if (m_cci.m_physicsEnv->RemoveCcdPhysicsController(this))
- {
- physicsEnv->AddCcdPhysicsController(this);
-
- // Set the object to be active so it can at least by evaluated once.
- // This fixes issues with static objects not having their physics meshes
- // in the right spot when lib loading.
- this->GetCollisionObject()->setActivationState(ACTIVE_TAG);
- }
- m_cci.m_physicsEnv = physicsEnv;
- }
-}
-
-void CcdPhysicsController::SetCenterOfMassTransform(btTransform& xform)
-{
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- body->setCenterOfMassTransform(xform);
- } else
- {
- //either collision object or soft body?
- if (GetSoftBody())
- {
-
- } else
- {
-
- if (m_object->isStaticOrKinematicObject())
- {
- m_object->setInterpolationWorldTransform(m_object->getWorldTransform());
- } else
- {
- m_object->setInterpolationWorldTransform(xform);
- }
- m_object->setWorldTransform(xform);
- }
- }
-}
-
- // kinematic methods
-void CcdPhysicsController::RelativeTranslate(const MT_Vector3& dlocin,bool local)
-{
- if (m_object)
- {
- m_object->activate(true);
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- // kinematic object should not set the transform, it disturbs the velocity interpolation
- return;
- }
-
- btVector3 dloc(dlocin.x(), dlocin.y(), dlocin.z());
- btTransform xform = m_object->getWorldTransform();
-
- if (local)
- dloc = xform.getBasis()*dloc;
-
- xform.setOrigin(xform.getOrigin() + dloc);
- SetCenterOfMassTransform(xform);
- }
-
-}
-
-void CcdPhysicsController::RelativeRotate(const MT_Matrix3x3& rotval,bool local)
-{
- if (m_object)
- {
- m_object->activate(true);
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- // kinematic object should not set the transform, it disturbs the velocity interpolation
- return;
- }
-
- btMatrix3x3 drotmat(rotval[0].x(), rotval[0].y(), rotval[0].z(),
- rotval[1].x(), rotval[1].y(), rotval[1].z(),
- rotval[2].x(), rotval[2].y(), rotval[2].z());
-
-
- btMatrix3x3 currentOrn;
- GetWorldOrientation(currentOrn);
-
- btTransform xform = m_object->getWorldTransform();
-
- xform.setBasis(xform.getBasis()*(local ?
- drotmat : (currentOrn.inverse() * drotmat * currentOrn)));
-
- SetCenterOfMassTransform(xform);
- }
-}
-
-
-void CcdPhysicsController::GetWorldOrientation(btMatrix3x3& mat)
-{
- float ori[12];
- m_MotionState->GetWorldOrientation(ori);
- mat.setFromOpenGLSubMatrix(ori);
-}
-
-MT_Matrix3x3 CcdPhysicsController::GetOrientation()
-{
- btMatrix3x3 orn = m_object->getWorldTransform().getBasis();
- return MT_Matrix3x3(orn[0][0], orn[0][1], orn[0][2], orn[1][0], orn[1][1], orn[1][2], orn[2][0], orn[2][1], orn[2][2]);
-}
-
-void CcdPhysicsController::SetOrientation(const MT_Matrix3x3& orn)
-{
- btMatrix3x3 btmat(orn[0][0], orn[0][1], orn[0][2], orn[1][0], orn[1][1], orn[1][2], orn[2][0], orn[2][1], orn[2][2]);
- SetWorldOrientation(btmat);
-}
-
-void CcdPhysicsController::SetWorldOrientation(const btMatrix3x3& orn)
-{
- if (m_object)
- {
- m_object->activate(true);
- if (m_object->isStaticObject() && !m_cci.m_bSensor)
- {
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- }
- // not required
- //m_MotionState->setWorldOrientation(quatImag0,quatImag1,quatImag2,quatReal);
- btTransform xform = m_object->getWorldTransform();
- xform.setBasis(orn);
- SetCenterOfMassTransform(xform);
- // not required
- //m_bulletMotionState->setWorldTransform(xform);
- //only once!
- if (!m_softBodyTransformInitialized && GetSoftBody())
- {
- m_softbodyStartTrans.setBasis(orn);
- xform.setOrigin(m_softbodyStartTrans.getOrigin());
- GetSoftBody()->transform(xform);
- m_softBodyTransformInitialized = true;
- }
-
- }
-
-}
-
-void CcdPhysicsController::SetPosition(const MT_Vector3& pos)
-{
- if (m_object)
- {
- m_object->activate(true);
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- // kinematic object should not set the transform, it disturbs the velocity interpolation
- return;
- }
- // not required, this function is only used to update the physic controller
- //m_MotionState->setWorldPosition(posX,posY,posZ);
- btTransform xform = m_object->getWorldTransform();
- xform.setOrigin(btVector3(pos.x(), pos.y(), pos.z()));
- SetCenterOfMassTransform(xform);
- if (!m_softBodyTransformInitialized)
- m_softbodyStartTrans.setOrigin(xform.getOrigin());
- // not required
- //m_bulletMotionState->setWorldTransform(xform);
- }
-}
-
-void CcdPhysicsController::ForceWorldTransform(const btMatrix3x3& mat, const btVector3& pos)
-{
- if (m_object)
- {
- btTransform& xform = m_object->getWorldTransform();
- xform.setBasis(mat);
- xform.setOrigin(pos);
- }
-}
-
-
-void CcdPhysicsController::ResolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ)
-{
-}
-
-void CcdPhysicsController::RefreshCollisions()
-{
- // the object is in an inactive layer so it's useless to update it and can cause problems
- if (!GetPhysicsEnvironment()->IsActiveCcdPhysicsController(this))
- return;
-
- btSoftRigidDynamicsWorld *dw = GetPhysicsEnvironment()->GetDynamicsWorld();
- btBroadphaseProxy *proxy = m_object->getBroadphaseHandle();
- btDispatcher *dispatcher = dw->getDispatcher();
- btOverlappingPairCache *pairCache = dw->getPairCache();
-
- CleanPairCallback cleanPairs(proxy, pairCache, dispatcher);
- pairCache->processAllOverlappingPairs(&cleanPairs, dispatcher);
-
- // Forcibly recreate the physics object
- btBroadphaseProxy* handle = m_object->getBroadphaseHandle();
- GetPhysicsEnvironment()->UpdateCcdPhysicsController(this, GetMass(), m_object->getCollisionFlags(), handle->m_collisionFilterGroup, handle->m_collisionFilterMask);
-}
-
-void CcdPhysicsController::SuspendDynamics(bool ghost)
-{
- btRigidBody *body = GetRigidBody();
- if (body && !m_suspended && !GetConstructionInfo().m_bSensor && GetPhysicsEnvironment()->IsActiveCcdPhysicsController(this))
- {
- btBroadphaseProxy* handle = body->getBroadphaseHandle();
-
- m_savedCollisionFlags = body->getCollisionFlags();
- m_savedMass = GetMass();
- m_savedDyna = m_cci.m_bDyna;
- m_savedCollisionFilterGroup = handle->m_collisionFilterGroup;
- m_savedCollisionFilterMask = handle->m_collisionFilterMask;
- m_suspended = true;
- GetPhysicsEnvironment()->UpdateCcdPhysicsController(this,
- 0.0f,
- btCollisionObject::CF_STATIC_OBJECT|((ghost)?btCollisionObject::CF_NO_CONTACT_RESPONSE:(m_savedCollisionFlags&btCollisionObject::CF_NO_CONTACT_RESPONSE)),
- btBroadphaseProxy::StaticFilter,
- btBroadphaseProxy::AllFilter ^ btBroadphaseProxy::StaticFilter);
- m_cci.m_bDyna = false;
- }
-}
-
-void CcdPhysicsController::RestoreDynamics()
-{
- btRigidBody *body = GetRigidBody();
- if (body && m_suspended && GetPhysicsEnvironment()->IsActiveCcdPhysicsController(this))
- {
- // before make sure any position change that was done in this logic frame are accounted for
- SetTransform();
- GetPhysicsEnvironment()->UpdateCcdPhysicsController(this,
- m_savedMass,
- m_savedCollisionFlags,
- m_savedCollisionFilterGroup,
- m_savedCollisionFilterMask);
- body->activate();
- m_cci.m_bDyna = m_savedDyna;
- m_suspended = false;
- }
-}
-
-void CcdPhysicsController::GetPosition(MT_Vector3& pos) const
-{
- const btTransform& xform = m_object->getWorldTransform();
- pos[0] = xform.getOrigin().x();
- pos[1] = xform.getOrigin().y();
- pos[2] = xform.getOrigin().z();
-}
-
-void CcdPhysicsController::SetScaling(const MT_Vector3& scale)
-{
- if (!btFuzzyZero(m_cci.m_scaling.x()-scale.x()) ||
- !btFuzzyZero(m_cci.m_scaling.y()-scale.y()) ||
- !btFuzzyZero(m_cci.m_scaling.z()-scale.z()))
- {
- m_cci.m_scaling = btVector3(scale.x(),scale.y(),scale.z());
-
- if (m_object && m_object->getCollisionShape())
- {
- m_object->activate(true); // without this, sleeping objects scale wont be applied in bullet if python changes the scale - Campbell.
- m_object->getCollisionShape()->setLocalScaling(m_cci.m_scaling);
-
- //printf("no inertia recalc for fixed objects with mass=0\n");
- btRigidBody* body = GetRigidBody();
- if (body && m_cci.m_mass)
- {
- body->getCollisionShape()->calculateLocalInertia(m_cci.m_mass, m_cci.m_localInertiaTensor);
- body->setMassProps(m_cci.m_mass, m_cci.m_localInertiaTensor * m_cci.m_inertiaFactor);
- }
-
- }
- }
-}
-
-void CcdPhysicsController::SetTransform()
-{
- btVector3 pos;
- btVector3 scale;
- float ori[12];
- m_MotionState->GetWorldPosition(pos.m_floats[0],pos.m_floats[1],pos.m_floats[2]);
- m_MotionState->GetWorldScaling(scale.m_floats[0],scale.m_floats[1],scale.m_floats[2]);
- m_MotionState->GetWorldOrientation(ori);
- btMatrix3x3 rot(ori[0], ori[4], ori[8],
- ori[1], ori[5], ori[9],
- ori[2], ori[6], ori[10]);
- ForceWorldTransform(rot, pos);
-
- if (!IsDynamic() && !GetConstructionInfo().m_bSensor && !GetCharacterController())
- {
- btCollisionObject* object = GetRigidBody();
- object->setActivationState(ACTIVE_TAG);
- object->setCollisionFlags(object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- }
-}
-
-MT_Scalar CcdPhysicsController::GetMass()
-{
- if (GetSoftBody())
- return GetSoftBody()->getTotalMass();
-
- MT_Scalar invmass = 0.f;
- if (GetRigidBody())
- invmass = GetRigidBody()->getInvMass();
- if (invmass)
- return 1.f/invmass;
- return 0.f;
-
-}
-
-void CcdPhysicsController::SetMass(MT_Scalar newmass)
-{
- btRigidBody *body = GetRigidBody();
- if (body && !m_suspended && newmass>MT_EPSILON && GetMass()>MT_EPSILON)
- {
- btBroadphaseProxy* handle = body->getBroadphaseHandle();
- GetPhysicsEnvironment()->UpdateCcdPhysicsController(this,
- newmass,
- body->getCollisionFlags(),
- handle->m_collisionFilterGroup,
- handle->m_collisionFilterMask);
- }
-}
-
- // physics methods
-void CcdPhysicsController::ApplyTorque(const MT_Vector3& torquein,bool local)
-{
- btVector3 torque(torquein.x(),torquein.y(),torquein.z());
- btTransform xform = m_object->getWorldTransform();
-
-
- if (m_object && torque.length2() > (SIMD_EPSILON*SIMD_EPSILON))
- {
- btRigidBody* body = GetRigidBody();
- m_object->activate();
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- return;
- }
- if (local)
- {
- torque = xform.getBasis()*torque;
- }
- if (body)
- {
- if (m_cci.m_bRigid)
- {
- body->applyTorque(torque);
- }
- else
- {
- //workaround for incompatibility between 'DYNAMIC' game object, and angular factor
- //a DYNAMIC object has some inconsistency: it has no angular effect due to collisions, but still has torque
- const btVector3 angFac = body->getAngularFactor();
- btVector3 tmpFac(1,1,1);
- body->setAngularFactor(tmpFac);
- body->applyTorque(torque);
- body->setAngularFactor(angFac);
- }
- }
- }
-}
-
-void CcdPhysicsController::ApplyForce(const MT_Vector3& forcein,bool local)
-{
- btVector3 force(forcein.x(),forcein.y(),forcein.z());
-
-
- if (m_object && force.length2() > (SIMD_EPSILON*SIMD_EPSILON))
- {
- m_object->activate();
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- return;
- }
- btTransform xform = m_object->getWorldTransform();
-
- if (local)
- {
- force = xform.getBasis()*force;
- }
- btRigidBody* body = GetRigidBody();
- if (body)
- body->applyCentralForce(force);
- btSoftBody* soft = GetSoftBody();
- if (soft)
- {
- // the force is applied on each node, must reduce it in the same extend
- if (soft->m_nodes.size() > 0)
- force /= soft->m_nodes.size();
- soft->addForce(force);
- }
- }
-}
-void CcdPhysicsController::SetAngularVelocity(const MT_Vector3& ang_vel,bool local)
-{
- btVector3 angvel(ang_vel.x(),ang_vel.y(),ang_vel.z());
-
- /* Refuse tiny tiny velocities, as they might cause instabilities. */
- float vel_squared = angvel.length2();
- if (vel_squared > 0 && vel_squared <= (SIMD_EPSILON*SIMD_EPSILON))
- angvel = btVector3(0, 0, 0);
-
- if (m_object)
- {
- m_object->activate(true);
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- return;
- }
- btTransform xform = m_object->getWorldTransform();
- if (local)
- {
- angvel = xform.getBasis()*angvel;
- }
- btRigidBody* body = GetRigidBody();
- if (body)
- body->setAngularVelocity(angvel);
- }
-
-}
-void CcdPhysicsController::SetLinearVelocity(const MT_Vector3& lin_vel,bool local)
-{
- btVector3 linVel(lin_vel.x(),lin_vel.y(),lin_vel.z());
-
- /* Refuse tiny tiny velocities, as they might cause instabilities. */
- float vel_squared = linVel.length2();
- if (vel_squared > 0 && vel_squared <= (SIMD_EPSILON*SIMD_EPSILON))
- linVel = btVector3(0, 0, 0);
-
- if (m_object)
- {
- m_object->activate(true);
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- return;
- }
-
- btSoftBody* soft = GetSoftBody();
- if (soft)
- {
- if (local)
- {
- linVel = m_softbodyStartTrans.getBasis()*linVel;
- }
- soft->setVelocity(linVel);
- } else
- {
- btTransform xform = m_object->getWorldTransform();
- if (local)
- {
- linVel = xform.getBasis()*linVel;
- }
- btRigidBody* body = GetRigidBody();
- if (body)
- body->setLinearVelocity(linVel);
- }
- }
-}
-void CcdPhysicsController::ApplyImpulse(const MT_Point3& attach, const MT_Vector3& impulsein, bool local)
-{
- btVector3 pos;
- btVector3 impulse(impulsein.x(), impulsein.y(), impulsein.z());
-
- if (m_object && impulse.length2() > (SIMD_EPSILON*SIMD_EPSILON))
- {
- m_object->activate();
- if (m_object->isStaticObject())
- {
- if (!m_cci.m_bSensor)
- m_object->setCollisionFlags(m_object->getCollisionFlags() | btCollisionObject::CF_KINEMATIC_OBJECT);
- return;
- }
-
- btTransform xform = m_object->getWorldTransform();
-
- if (local)
- {
- pos = btVector3(attach.x(), attach.y(), attach.z());
- impulse = xform.getBasis() * impulse;
- }
- else {
- /* If the point of impulse application is not equal to the object position
- * then an angular momentum is generated in the object*/
- pos = btVector3(attach.x()-xform.getOrigin().x(), attach.y()-xform.getOrigin().y(), attach.z()-xform.getOrigin().z());
- }
-
- btRigidBody* body = GetRigidBody();
- if (body)
- body->applyImpulse(impulse,pos);
-
- }
-
-}
-
-void CcdPhysicsController::Jump()
-{
- if (m_object && m_characterController)
- m_characterController->jump();
-}
-
-void CcdPhysicsController::SetActive(bool active)
-{
-}
-
-float CcdPhysicsController::GetLinearDamping() const
-{
- const btRigidBody* body = GetRigidBody();
- if (body)
- return body->getLinearDamping();
- return 0;
-}
-
-float CcdPhysicsController::GetAngularDamping() const
-{
- const btRigidBody* body = GetRigidBody();
- if (body)
- return body->getAngularDamping();
- return 0;
-}
-
-void CcdPhysicsController::SetLinearDamping(float damping)
-{
- SetDamping(damping, GetAngularDamping());
-}
-
-void CcdPhysicsController::SetAngularDamping(float damping)
-{
- SetDamping(GetLinearDamping(), damping);
-}
-
-void CcdPhysicsController::SetDamping(float linear, float angular)
-{
- btRigidBody* body = GetRigidBody();
- if (!body) return;
-
- body->setDamping(linear, angular);
-}
-
-
- // reading out information from physics
-MT_Vector3 CcdPhysicsController::GetLinearVelocity()
-{
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- const btVector3& linvel = body->getLinearVelocity();
- return MT_Vector3(linvel.x(), linvel.y(), linvel.z());
- }
-
- return MT_Vector3(0.f, 0.f, 0.f);
-}
-
-MT_Vector3 CcdPhysicsController::GetAngularVelocity()
-{
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- const btVector3& angvel= body->getAngularVelocity();
- return MT_Vector3(angvel.x(), angvel.y(), angvel.z());
- }
-
- return MT_Vector3(0.f, 0.f, 0.f);
-}
-
-MT_Vector3 CcdPhysicsController::GetVelocity(const MT_Point3 &posin)
-{
- btVector3 pos(posin.x(), posin.y(), posin.z());
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- btVector3 linvel = body->getVelocityInLocalPoint(pos);
- return MT_Vector3(linvel.x(), linvel.y(), linvel.z());
- }
-
- return MT_Vector3(0.f, 0.f, 0.f);
-}
-
-MT_Vector3 CcdPhysicsController::GetLocalInertia()
-{
- MT_Vector3 inertia(0.f, 0.f, 0.f);
- btVector3 inv_inertia;
- if (GetRigidBody()) {
- inv_inertia = GetRigidBody()->getInvInertiaDiagLocal();
- if (!btFuzzyZero(inv_inertia.getX()) &&
- !btFuzzyZero(inv_inertia.getY()) &&
- !btFuzzyZero(inv_inertia.getZ()))
- inertia = MT_Vector3(1.f/inv_inertia.getX(), 1.f/inv_inertia.getY(), 1.f/inv_inertia.getZ());
- }
- return inertia;
-}
-
- // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted
-void CcdPhysicsController::SetRigidBody(bool rigid)
-{
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- m_cci.m_bRigid = rigid;
- if (!rigid) {
- body->setAngularFactor(0.f);
- body->setAngularVelocity(btVector3(0.f, 0.f, 0.f));
- }
- else
- body->setAngularFactor(m_cci.m_angularFactor);
- }
-}
-
- // clientinfo for raycasts for example
-void* CcdPhysicsController::GetNewClientInfo()
-{
- return m_newClientInfo;
-}
-void CcdPhysicsController::SetNewClientInfo(void* clientinfo)
-{
- m_newClientInfo = clientinfo;
-
- if (m_cci.m_bSensor)
- {
- // use a different callback function for sensor object,
- // bullet will not synchronize, we must do it explicitly
- SG_Callbacks& callbacks = KX_GameObject::GetClientObject((KX_ClientObjectInfo*)clientinfo)->GetSGNode()->GetCallBackFunctions();
- callbacks.m_updatefunc = KX_GameObject::SynchronizeTransformFunc;
- }
-}
-
-
-void CcdPhysicsController::UpdateDeactivation(float timeStep)
-{
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- body->updateDeactivation( timeStep);
- }
-}
-
-bool CcdPhysicsController::WantsSleeping()
-{
- btRigidBody* body = GetRigidBody();
- if (body)
- {
- return body->wantsSleeping();
- }
- //check it out
- return true;
-}
-/* This function dynamically adds the collision shape of another controller to
- * the current controller shape provided it is a compound shape.
- * The idea is that dynamic parenting on a compound object will dynamically extend the shape
- */
-void CcdPhysicsController::AddCompoundChild(PHY_IPhysicsController* child)
-{
- if (child == NULL || !IsCompound())
- return;
- // other controller must be a bullet controller too
- // verify that body and shape exist and match
- CcdPhysicsController* childCtrl = dynamic_cast<CcdPhysicsController*>(child);
- btRigidBody* rootBody = GetRigidBody();
- btRigidBody* childBody = childCtrl->GetRigidBody();
- if (!rootBody || !childBody)
- return;
- const btCollisionShape* rootShape = rootBody->getCollisionShape();
- const btCollisionShape* childShape = childBody->getCollisionShape();
- if (!rootShape ||
- !childShape ||
- rootShape->getShapeType() != COMPOUND_SHAPE_PROXYTYPE)
- return;
- btCompoundShape* compoundShape = (btCompoundShape*)rootShape;
- // compute relative transformation between parent and child
- btTransform rootTrans;
- btTransform childTrans;
- rootBody->getMotionState()->getWorldTransform(rootTrans);
- childBody->getMotionState()->getWorldTransform(childTrans);
- btVector3 rootScale = rootShape->getLocalScaling();
- rootScale[0] = 1.0f/rootScale[0];
- rootScale[1] = 1.0f/rootScale[1];
- rootScale[2] = 1.0f/rootScale[2];
- // relative scale = child_scale/parent_scale
- btVector3 relativeScale = childShape->getLocalScaling()*rootScale;
- btMatrix3x3 rootRotInverse = rootTrans.getBasis().transpose();
- // relative pos = parent_rot^-1 * ((parent_pos-child_pos)/parent_scale)
- btVector3 relativePos = rootRotInverse*((childTrans.getOrigin()-rootTrans.getOrigin())*rootScale);
- // relative rot = parent_rot^-1 * child_rot
- btMatrix3x3 relativeRot = rootRotInverse*childTrans.getBasis();
- // create a proxy shape info to store the transformation
- CcdShapeConstructionInfo* proxyShapeInfo = new CcdShapeConstructionInfo();
- // store the transformation to this object shapeinfo
- proxyShapeInfo->m_childTrans.setOrigin(relativePos);
- proxyShapeInfo->m_childTrans.setBasis(relativeRot);
- proxyShapeInfo->m_childScale.setValue(relativeScale[0], relativeScale[1], relativeScale[2]);
- // we will need this to make sure that we remove the right proxy later when unparenting
- proxyShapeInfo->m_userData = childCtrl;
- proxyShapeInfo->SetProxy(childCtrl->GetShapeInfo()->AddRef());
- // add to parent compound shapeinfo (increments ref count)
- GetShapeInfo()->AddShape(proxyShapeInfo);
- // create new bullet collision shape from the object shapeinfo and set scaling
- btCollisionShape* newChildShape = proxyShapeInfo->CreateBulletShape(childCtrl->GetMargin(), childCtrl->GetConstructionInfo().m_bGimpact, true);
- newChildShape->setLocalScaling(relativeScale);
- // add bullet collision shape to parent compound collision shape
- compoundShape->addChildShape(proxyShapeInfo->m_childTrans,newChildShape);
- // proxyShapeInfo is not needed anymore, release it
- proxyShapeInfo->Release();
- // remember we created this shape
- childCtrl->m_bulletChildShape = newChildShape;
- // recompute inertia of parent
- if (!rootBody->isStaticOrKinematicObject())
- {
- btVector3 localInertia;
- float mass = 1.f/rootBody->getInvMass();
- compoundShape->calculateLocalInertia(mass,localInertia);
- rootBody->setMassProps(mass,localInertia);
- }
- // must update the broadphase cache,
- GetPhysicsEnvironment()->RefreshCcdPhysicsController(this);
- // remove the children
- GetPhysicsEnvironment()->RemoveCcdPhysicsController(childCtrl);
-}
-
-/* Reverse function of the above, it will remove a shape from a compound shape
- * provided that the former was added to the later using AddCompoundChild()
- */
-void CcdPhysicsController::RemoveCompoundChild(PHY_IPhysicsController* child)
-{
- if (child == NULL || !IsCompound())
- return;
- // other controller must be a bullet controller too
- // verify that body and shape exist and match
- CcdPhysicsController* childCtrl = dynamic_cast<CcdPhysicsController*>(child);
- btRigidBody* rootBody = GetRigidBody();
- btRigidBody* childBody = childCtrl->GetRigidBody();
- if (!rootBody || !childBody)
- return;
- const btCollisionShape* rootShape = rootBody->getCollisionShape();
- if (!rootShape ||
- rootShape->getShapeType() != COMPOUND_SHAPE_PROXYTYPE)
- return;
- btCompoundShape* compoundShape = (btCompoundShape*)rootShape;
- // retrieve the shapeInfo
- CcdShapeConstructionInfo* childShapeInfo = childCtrl->GetShapeInfo();
- CcdShapeConstructionInfo* rootShapeInfo = GetShapeInfo();
- // and verify that the child is part of the parent
- int i = rootShapeInfo->FindChildShape(childShapeInfo, childCtrl);
- if (i < 0)
- return;
- rootShapeInfo->RemoveChildShape(i);
- if (childCtrl->m_bulletChildShape)
- {
- int numChildren = compoundShape->getNumChildShapes();
- for (i=0; i<numChildren; i++)
- {
- if (compoundShape->getChildShape(i) == childCtrl->m_bulletChildShape)
- {
- compoundShape->removeChildShapeByIndex(i);
- compoundShape->recalculateLocalAabb();
- break;
- }
- }
- delete childCtrl->m_bulletChildShape;
- childCtrl->m_bulletChildShape = NULL;
- }
- // recompute inertia of parent
- if (!rootBody->isStaticOrKinematicObject())
- {
- btVector3 localInertia;
- float mass = 1.f/rootBody->getInvMass();
- compoundShape->calculateLocalInertia(mass,localInertia);
- rootBody->setMassProps(mass,localInertia);
- }
- // must update the broadphase cache,
- GetPhysicsEnvironment()->RefreshCcdPhysicsController(this);
- // reactivate the children
- GetPhysicsEnvironment()->AddCcdPhysicsController(childCtrl);
-}
-
-PHY_IPhysicsController* CcdPhysicsController::GetReplica()
-{
- CcdPhysicsController* replica = new CcdPhysicsController(*this);
- return replica;
-}
-
-// Keeping this separate for now, maybe we can combine it with GetReplica()...
-PHY_IPhysicsController* CcdPhysicsController::GetReplicaForSensors()
-{
- // This is used only to replicate Near and Radar sensor controllers
- // The replication of object physics controller is done in KX_BulletPhysicsController::GetReplica()
- CcdConstructionInfo cinfo = m_cci;
- if (m_shapeInfo)
- {
- // This situation does not normally happen
- cinfo.m_collisionShape = m_shapeInfo->CreateBulletShape(m_cci.m_margin, m_cci.m_bGimpact, !m_cci.m_bSoft);
- }
- else if (m_collisionShape)
- {
- switch (m_collisionShape->getShapeType())
- {
- case SPHERE_SHAPE_PROXYTYPE:
- {
- btSphereShape* orgShape = (btSphereShape*)m_collisionShape;
- cinfo.m_collisionShape = new btSphereShape(*orgShape);
- break;
- }
-
- case CONE_SHAPE_PROXYTYPE:
- {
- btConeShape* orgShape = (btConeShape*)m_collisionShape;
- cinfo.m_collisionShape = new btConeShape(*orgShape);
- break;
- }
-
- default:
- {
- return 0;
- }
- }
- }
-
- cinfo.m_MotionState = new DefaultMotionState();
- cinfo.m_shapeInfo = m_shapeInfo;
-
- CcdPhysicsController* replica = new CcdPhysicsController(cinfo);
- return replica;
-}
-
-/* Refresh the physics object from either an object or a mesh.
- * from_gameobj and from_meshobj can be NULL
- *
- * when setting the mesh, the following vars get priority
- * 1) from_meshobj - creates the phys mesh from RAS_MeshObject
- * 2) from_gameobj - creates the phys mesh from the DerivedMesh where possible, else the RAS_MeshObject
- * 3) this - update the phys mesh from DerivedMesh or RAS_MeshObject
- *
- * Most of the logic behind this is in m_shapeInfo->UpdateMesh(...)
- */
-bool CcdPhysicsController::ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject *from_meshobj)
-{
- if (m_shapeInfo->m_shapeType != PHY_SHAPE_MESH)
- return false;
-
- if (!from_gameobj && !from_meshobj)
- from_gameobj = KX_GameObject::GetClientObject((KX_ClientObjectInfo*)GetNewClientInfo());
-
- /* updates the arrays used for making the new bullet mesh */
- m_shapeInfo->UpdateMesh(from_gameobj, from_meshobj);
-
- /* create the new bullet mesh */
- GetPhysicsEnvironment()->UpdateCcdPhysicsControllerShape(m_shapeInfo);
-
- return true;
-}
-
-void CcdPhysicsController::ReplicateConstraints(KX_GameObject *replica, std::vector<KX_GameObject*> constobj)
-{
- if (replica->GetConstraints().size() == 0 || !replica->GetPhysicsController())
- return;
-
- PHY_IPhysicsEnvironment *physEnv = GetPhysicsEnvironment();
-
- vector<bRigidBodyJointConstraint*> constraints = replica->GetConstraints();
- vector<bRigidBodyJointConstraint*>::iterator consit;
-
- /* Object could have some constraints, iterate over all of theme to ensure that every constraint is recreated. */
- for (consit = constraints.begin(); consit != constraints.end(); ++consit) {
- /* Try to find the constraint targets in the list of group objects. */
- bRigidBodyJointConstraint *dat = (*consit);
- vector<KX_GameObject*>::iterator memit;
- for (memit = constobj.begin(); memit != constobj.end(); ++memit) {
- KX_GameObject *member = (*memit);
- /* If the group member is the actual target for the constraint. */
- if (dat->tar->id.name + 2 == member->GetName() && member->GetPhysicsController())
- physEnv->SetupObjectConstraints(replica, member, dat);
- }
- }
-
-}
-
-///////////////////////////////////////////////////////////
-///A small utility class, DefaultMotionState
-///
-///////////////////////////////////////////////////////////
-
-DefaultMotionState::DefaultMotionState()
-{
- m_worldTransform.setIdentity();
- m_localScaling.setValue(1.f,1.f,1.f);
-}
-
-
-DefaultMotionState::~DefaultMotionState()
-{
-
-}
-
-void DefaultMotionState::GetWorldPosition(float& posX,float& posY,float& posZ)
-{
- posX = m_worldTransform.getOrigin().x();
- posY = m_worldTransform.getOrigin().y();
- posZ = m_worldTransform.getOrigin().z();
-}
-
-void DefaultMotionState::GetWorldScaling(float& scaleX,float& scaleY,float& scaleZ)
-{
- scaleX = m_localScaling.getX();
- scaleY = m_localScaling.getY();
- scaleZ = m_localScaling.getZ();
-}
-
-void DefaultMotionState::GetWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)
-{
- btQuaternion quat = m_worldTransform.getRotation();
- quatIma0 = quat.x();
- quatIma1 = quat.y();
- quatIma2 = quat.z();
- quatReal = quat[3];
-}
-
-void DefaultMotionState::GetWorldOrientation(float* ori)
-{
- m_worldTransform.getBasis().getOpenGLSubMatrix(ori);
-}
-
-void DefaultMotionState::SetWorldOrientation(const float* ori)
-{
- m_worldTransform.getBasis().setFromOpenGLSubMatrix(ori);
-}
-void DefaultMotionState::SetWorldPosition(float posX,float posY,float posZ)
-{
- btVector3 pos(posX,posY,posZ);
- m_worldTransform.setOrigin( pos );
-}
-
-void DefaultMotionState::SetWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)
-{
- btQuaternion orn(quatIma0,quatIma1,quatIma2,quatReal);
- m_worldTransform.setRotation( orn );
-}
-
-void DefaultMotionState::CalculateWorldTransformations()
-{
-
-}
-
-// Shape constructor
-std::map<RAS_MeshObject*, CcdShapeConstructionInfo*> CcdShapeConstructionInfo::m_meshShapeMap;
-
-CcdShapeConstructionInfo* CcdShapeConstructionInfo::FindMesh(RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope)
-{
- if (polytope || dm)
- // not yet supported
- return NULL;
-
- std::map<RAS_MeshObject*,CcdShapeConstructionInfo*>::const_iterator mit = m_meshShapeMap.find(mesh);
- if (mit != m_meshShapeMap.end())
- return mit->second;
- return NULL;
-}
-
-bool CcdShapeConstructionInfo::SetMesh(RAS_MeshObject *meshobj, DerivedMesh *dm, bool polytope)
-{
- int numpolys, numverts;
-
- // assume no shape information
- // no support for dynamic change of shape yet
- assert(IsUnused());
- m_shapeType = PHY_SHAPE_NONE;
- m_meshObject = NULL;
- bool free_dm = false;
-
- // No mesh object or mesh has no polys
- if (!meshobj || !meshobj->HasColliderPolygon()) {
- m_vertexArray.clear();
- m_polygonIndexArray.clear();
- m_triFaceArray.clear();
- m_triFaceUVcoArray.clear();
- return false;
- }
-
- if (!dm) {
- free_dm = true;
- dm = CDDM_from_mesh(meshobj->GetMesh());
- }
-
- // Some meshes with modifiers returns 0 polys, call DM_ensure_tessface avoid this.
- DM_ensure_tessface(dm);
-
- MVert *mvert = dm->getVertArray(dm);
- MFace *mface = dm->getTessFaceArray(dm);
- numpolys = dm->getNumTessFaces(dm);
- numverts = dm->getNumVerts(dm);
- MTFace *tface = (MTFace *)dm->getTessFaceDataArray(dm, CD_MTFACE);
-
- /* double lookup */
- const int *index_mf_to_mpoly = (const int *)dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
- const int *index_mp_to_orig = (const int *)dm->getPolyDataArray(dm, CD_ORIGINDEX);
- if (!index_mf_to_mpoly) {
- index_mp_to_orig = NULL;
- }
-
- m_shapeType = (polytope) ? PHY_SHAPE_POLYTOPE : PHY_SHAPE_MESH;
-
- /* Convert blender geometry into bullet mesh, need these vars for mapping */
- std::vector<bool> vert_tag_array(numverts, false);
- unsigned int tot_bt_verts = 0;
-
- if (polytope) {
- // Tag verts we're using
- for (int p2 = 0; p2 < numpolys; p2++) {
- MFace *mf = &mface[p2];
- const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2;
- RAS_Polygon *poly = (origi != ORIGINDEX_NONE) ? meshobj->GetPolygon(origi) : NULL;
-
- // only add polygons that have the collision flag set
- if (poly && poly->IsCollider()) {
- if (!vert_tag_array[mf->v1]) {
- vert_tag_array[mf->v1] = true;
- tot_bt_verts++;
- }
- if (!vert_tag_array[mf->v2]) {
- vert_tag_array[mf->v2] = true;
- tot_bt_verts++;
- }
- if (!vert_tag_array[mf->v3]) {
- vert_tag_array[mf->v3] = true;
- tot_bt_verts++;
- }
- if (mf->v4 && !vert_tag_array[mf->v4]) {
- vert_tag_array[mf->v4] = true;
- tot_bt_verts++;
- }
- }
- }
-
- /* Can happen with ngons */
- if (!tot_bt_verts) {
- goto cleanup_empty_mesh;
- }
-
- m_vertexArray.resize(tot_bt_verts * 3);
-
- btScalar *bt = &m_vertexArray[0];
-
- for (int p2 = 0; p2 < numpolys; p2++) {
- MFace *mf = &mface[p2];
- const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2;
- RAS_Polygon *poly = (origi != ORIGINDEX_NONE) ? meshobj->GetPolygon(origi) : NULL;
-
- // only add polygons that have the collisionflag set
- if (poly->IsCollider()) {
- if (vert_tag_array[mf->v1]) {
- const float *vtx = mvert[mf->v1].co;
- vert_tag_array[mf->v1] = false;
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
- }
- if (vert_tag_array[mf->v2]) {
- const float *vtx = mvert[mf->v2].co;
- vert_tag_array[mf->v2] = false;
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
- }
- if (vert_tag_array[mf->v3]) {
- const float *vtx = mvert[mf->v3].co;
- vert_tag_array[mf->v3] = false;
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
- }
- if (mf->v4 && vert_tag_array[mf->v4]) {
- const float *vtx = mvert[mf->v4].co;
- vert_tag_array[mf->v4] = false;
- *bt++ = vtx[0];
- *bt++ = vtx[1];
- *bt++ = vtx[2];
- }
- }
- }
- }
- else {
- unsigned int tot_bt_tris = 0;
- std::vector<int> vert_remap_array(numverts, 0);
-
- // Tag verts we're using
- for (int p2 = 0; p2 < numpolys; p2++) {
- MFace *mf = &mface[p2];
- const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2;
- RAS_Polygon *poly = (origi != ORIGINDEX_NONE) ? meshobj->GetPolygon(origi) : NULL;
-
- // only add polygons that have the collision flag set
- if (poly && poly->IsCollider()) {
- if (!vert_tag_array[mf->v1]) {
- vert_tag_array[mf->v1] = true;
- vert_remap_array[mf->v1] = tot_bt_verts;
- tot_bt_verts++;
- }
- if (!vert_tag_array[mf->v2]) {
- vert_tag_array[mf->v2] = true;
- vert_remap_array[mf->v2] = tot_bt_verts;
- tot_bt_verts++;
- }
- if (!vert_tag_array[mf->v3]) {
- vert_tag_array[mf->v3] = true;
- vert_remap_array[mf->v3] = tot_bt_verts;
- tot_bt_verts++;
- }
- if (mf->v4 && !vert_tag_array[mf->v4]) {
- vert_tag_array[mf->v4] = true;
- vert_remap_array[mf->v4] = tot_bt_verts;
- tot_bt_verts++;
- }
- tot_bt_tris += (mf->v4 ? 2 : 1); /* a quad or a tri */
- }
- }
-
- /* Can happen with ngons */
- if (!tot_bt_verts) {
- goto cleanup_empty_mesh;
- }
-
- m_vertexArray.resize(tot_bt_verts * 3);
- m_polygonIndexArray.resize(tot_bt_tris);
- m_triFaceArray.resize(tot_bt_tris * 3);
- btScalar *bt = &m_vertexArray[0];
- int *poly_index_pt = &m_polygonIndexArray[0];
- int *tri_pt = &m_triFaceArray[0];
-
- UVco *uv_pt = NULL;
- if (tface) {
- m_triFaceUVcoArray.resize(tot_bt_tris * 3);
- uv_pt = &m_triFaceUVcoArray[0];
- }
- else
- m_triFaceUVcoArray.clear();
-
- for (int p2 = 0; p2 < numpolys; p2++) {
- MFace *mf = &mface[p2];
- MTFace *tf = (tface) ? &tface[p2] : NULL;
- const int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, p2) : p2;
- RAS_Polygon *poly = (origi != ORIGINDEX_NONE) ? meshobj->GetPolygon(origi) : NULL;
-
- // only add polygons that have the collisionflag set
- if (poly && poly->IsCollider()) {
- MVert *v1 = &mvert[mf->v1];
- MVert *v2 = &mvert[mf->v2];
- MVert *v3 = &mvert[mf->v3];
-
- // the face indices
- tri_pt[0] = vert_remap_array[mf->v1];
- tri_pt[1] = vert_remap_array[mf->v2];
- tri_pt[2] = vert_remap_array[mf->v3];
- tri_pt = tri_pt + 3;
- if (tf) {
- uv_pt[0].uv[0] = tf->uv[0][0];
- uv_pt[0].uv[1] = tf->uv[0][1];
- uv_pt[1].uv[0] = tf->uv[1][0];
- uv_pt[1].uv[1] = tf->uv[1][1];
- uv_pt[2].uv[0] = tf->uv[2][0];
- uv_pt[2].uv[1] = tf->uv[2][1];
- uv_pt += 3;
- }
-
- // m_polygonIndexArray
- *poly_index_pt = origi;
- poly_index_pt++;
-
- // the vertex location
- if (vert_tag_array[mf->v1]) { /* *** v1 *** */
- vert_tag_array[mf->v1] = false;
- *bt++ = v1->co[0];
- *bt++ = v1->co[1];
- *bt++ = v1->co[2];
- }
- if (vert_tag_array[mf->v2]) { /* *** v2 *** */
- vert_tag_array[mf->v2] = false;
- *bt++ = v2->co[0];
- *bt++ = v2->co[1];
- *bt++ = v2->co[2];
- }
- if (vert_tag_array[mf->v3]) { /* *** v3 *** */
- vert_tag_array[mf->v3] = false;
- *bt++ = v3->co[0];
- *bt++ = v3->co[1];
- *bt++ = v3->co[2];
- }
-
- if (mf->v4)
- {
- MVert *v4 = &mvert[mf->v4];
-
- tri_pt[0] = vert_remap_array[mf->v1];
- tri_pt[1] = vert_remap_array[mf->v3];
- tri_pt[2] = vert_remap_array[mf->v4];
- tri_pt = tri_pt + 3;
- if (tf)
- {
- uv_pt[0].uv[0] = tf->uv[0][0];
- uv_pt[0].uv[1] = tf->uv[0][1];
- uv_pt[1].uv[0] = tf->uv[2][0];
- uv_pt[1].uv[1] = tf->uv[2][1];
- uv_pt[2].uv[0] = tf->uv[3][0];
- uv_pt[2].uv[1] = tf->uv[3][1];
- uv_pt += 3;
- }
-
- // m_polygonIndexArray
- *poly_index_pt = origi;
- poly_index_pt++;
-
- // the vertex location
- if (vert_tag_array[mf->v4]) { /* *** v4 *** */
- vert_tag_array[mf->v4] = false;
- *bt++ = v4->co[0];
- *bt++ = v4->co[1];
- *bt++ = v4->co[2];
- }
- }
- }
- }
-
-
- /* If this ever gets confusing, print out an OBJ file for debugging */
-#if 0
- printf("# vert count %d\n", m_vertexArray.size());
- for (i = 0; i < m_vertexArray.size(); i += 1) {
- printf("v %.6f %.6f %.6f\n", m_vertexArray[i].x(), m_vertexArray[i].y(), m_vertexArray[i].z());
- }
-
- printf("# face count %d\n", m_triFaceArray.size());
- for (i = 0; i < m_triFaceArray.size(); i += 3) {
- printf("f %d %d %d\n", m_triFaceArray[i] + 1, m_triFaceArray[i + 1] + 1, m_triFaceArray[i + 2] + 1);
- }
-#endif
-
- }
-
-#if 0
- if (validpolys == false)
- {
- // should not happen
- m_shapeType = PHY_SHAPE_NONE;
- return false;
- }
-#endif
-
- m_meshObject = meshobj;
- if (free_dm) {
- dm->release(dm);
- dm = NULL;
- }
-
- // sharing only on static mesh at present, if you change that, you must also change in FindMesh
- if (!polytope && !dm) {
- // triangle shape can be shared, store the mesh object in the map
- m_meshShapeMap.insert(std::pair<RAS_MeshObject *, CcdShapeConstructionInfo *>(meshobj, this));
- }
- return true;
-
-
-cleanup_empty_mesh:
- m_shapeType = PHY_SHAPE_NONE;
- m_meshObject = NULL;
- m_vertexArray.clear();
- m_polygonIndexArray.clear();
- m_triFaceArray.clear();
- m_triFaceUVcoArray.clear();
- if (free_dm) {
- dm->release(dm);
- }
- return false;
-}
-
-#include <cstdio>
-
-/* Updates the arrays used by CreateBulletShape(),
- * take care that recalcLocalAabb() runs after CreateBulletShape is called.
- * */
-bool CcdShapeConstructionInfo::UpdateMesh(class KX_GameObject *gameobj, class RAS_MeshObject *meshobj)
-{
- int numpolys;
- int numverts;
-
- unsigned int tot_bt_tris = 0;
- unsigned int tot_bt_verts = 0;
-
- int i, j;
- int v_orig;
-
- /* Use for looping over verts in a face as a try or 2 tris */
- const int quad_verts[7] = {0, 1, 2, 0, 2, 3, -1};
- const int tri_verts[4] = {0, 1, 2, -1};
- const int *fv_pt;
-
- if (!gameobj && !meshobj)
- return false;
-
- if (m_shapeType != PHY_SHAPE_MESH)
- return false;
-
- RAS_Deformer *deformer = gameobj ? gameobj->GetDeformer() : NULL;
- DerivedMesh *dm = NULL;
-
- if (deformer)
- dm = deformer->GetPhysicsMesh();
-
- /* get the mesh from the object if not defined */
- if (!meshobj) {
- /* modifier mesh */
- if (dm)
- meshobj = deformer->GetRasMesh();
-
- /* game object first mesh */
- if (!meshobj) {
- if (gameobj->GetMeshCount() > 0) {
- meshobj = gameobj->GetMesh(0);
- }
- }
- }
-
- if (dm && deformer->GetRasMesh() == meshobj) {
- /*
- * Derived Mesh Update
- *
- * */
-
- MVert *mvert = dm->getVertArray(dm);
- MFace *mface = dm->getTessFaceArray(dm);
- numpolys = dm->getNumTessFaces(dm);
- numverts = dm->getNumVerts(dm);
-
- /* double lookup */
- const int *index_mf_to_mpoly = (const int *)dm->getTessFaceDataArray(dm, CD_ORIGINDEX);
- const int *index_mp_to_orig = (const int *)dm->getPolyDataArray(dm, CD_ORIGINDEX);
- if (!index_mf_to_mpoly) {
- index_mp_to_orig = NULL;
- }
-
- MFace *mf;
- MVert *mv;
-
- if (CustomData_has_layer(&dm->faceData, CD_MTFACE)) {
- MTFace *tface = (MTFace *)dm->getTessFaceDataArray(dm, CD_MTFACE);
- MTFace *tf;
-
- std::vector<bool> vert_tag_array(numverts, false);
- std::vector<int> vert_remap_array(numverts, 0);
-
- for (mf = mface, tf = tface, i = 0; i < numpolys; mf++, tf++, i++) {
- if (tf->mode & TF_DYNAMIC) {
- int flen;
-
- if (mf->v4) {
- tot_bt_tris += 2;
- flen = 4;
- }
- else {
- tot_bt_tris++;
- flen = 3;
- }
-
- for (j = 0; j < flen; j++) {
- v_orig = (*(&mf->v1 + j));
-
- if (!vert_tag_array[v_orig]) {
- vert_tag_array[v_orig] = true;
- vert_remap_array[v_orig] = tot_bt_verts;
- tot_bt_verts++;
- }
- }
- }
- }
-
- m_vertexArray.resize(tot_bt_verts * 3);
- btScalar *bt = &m_vertexArray[0];
-
- m_triFaceArray.resize(tot_bt_tris * 3);
- int *tri_pt = &m_triFaceArray[0];
-
- m_triFaceUVcoArray.resize(tot_bt_tris * 3);
- UVco *uv_pt = &m_triFaceUVcoArray[0];
-
- m_polygonIndexArray.resize(tot_bt_tris);
- int *poly_index_pt = &m_polygonIndexArray[0];
-
- for (mf = mface, tf = tface, i = 0; i < numpolys; mf++, tf++, i++) {
- if (tf->mode & TF_DYNAMIC) {
- int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i;
-
- if (mf->v4) {
- fv_pt = quad_verts;
- *poly_index_pt++ = origi;
- *poly_index_pt++ = origi;
- }
- else {
- fv_pt = tri_verts;
- *poly_index_pt++ = origi;
- }
-
- for (; *fv_pt > -1; fv_pt++) {
- v_orig = (*(&mf->v1 + (*fv_pt)));
-
- if (vert_tag_array[v_orig])
- {
- mv = mvert + v_orig;
- *bt++ = mv->co[0];
- *bt++ = mv->co[1];
- *bt++ = mv->co[2];
-
- vert_tag_array[v_orig] = false;
- }
- *tri_pt++ = vert_remap_array[v_orig];
- uv_pt->uv[0] = tf->uv[*fv_pt][0];
- uv_pt->uv[1] = tf->uv[*fv_pt][1];
- uv_pt++;
- }
- }
- }
- }
- else {
- /* no need for a vertex mapping. simple/fast */
-
- tot_bt_verts = numverts;
-
- for (mf = mface, i = 0; i < numpolys; mf++, i++) {
- tot_bt_tris += (mf->v4 ? 2 : 1);
- }
-
- m_vertexArray.resize(tot_bt_verts * 3);
- btScalar *bt = &m_vertexArray[0];
-
- m_triFaceArray.resize(tot_bt_tris * 3);
- int *tri_pt = &m_triFaceArray[0];
-
- m_polygonIndexArray.resize(tot_bt_tris);
- int *poly_index_pt = &m_polygonIndexArray[0];
-
- m_triFaceUVcoArray.clear();
-
- for (mv = mvert, i = 0; i < numverts; mv++, i++) {
- *bt++ = mv->co[0]; *bt++ = mv->co[1]; *bt++ = mv->co[2];
- }
-
- for (mf = mface, i = 0; i < numpolys; mf++, i++) {
- int origi = index_mf_to_mpoly ? DM_origindex_mface_mpoly(index_mf_to_mpoly, index_mp_to_orig, i) : i;
-
- if (mf->v4) {
- fv_pt = quad_verts;
- *poly_index_pt++ = origi;
- *poly_index_pt++ = origi;
- }
- else {
- fv_pt = tri_verts;
- *poly_index_pt++ = origi;
- }
-
- for (; *fv_pt > -1; fv_pt++)
- *tri_pt++ = (*(&mf->v1 + (*fv_pt)));
- }
- }
- }
- else { /*
- * RAS Mesh Update
- *
- * */
- /* Note!, gameobj can be NULL here */
-
- /* transverts are only used for deformed RAS_Meshes, the RAS_TexVert data
- * is too hard to get at, see below for details */
- float(*transverts)[3] = NULL;
- int transverts_tot = 0; /* with deformed meshes - should always be greater than the max orginal index, or we get crashes */
-
- if (deformer) {
- /* map locations from the deformed array
- *
- * Could call deformer->Update(); but rely on redraw updating.
- * */
- transverts = deformer->GetTransVerts(&transverts_tot);
- }
-
- // Tag verts we're using
- numpolys = meshobj->NumPolygons();
- numverts = meshobj->m_sharedvertex_map.size();
- const float *xyz;
-
-
- std::vector<bool> vert_tag_array(numverts, false);
- std::vector<int> vert_remap_array(numverts, 0);
-
- for (int p = 0; p < numpolys; p++) {
- RAS_Polygon *poly = meshobj->GetPolygon(p);
- if (poly->IsCollider()) {
- for (i = 0; i < poly->VertexCount(); i++) {
- v_orig = poly->GetVertex(i)->getOrigIndex();
- if (!vert_tag_array[v_orig]) {
- vert_tag_array[v_orig] = true;
- vert_remap_array[v_orig] = tot_bt_verts;
- tot_bt_verts++;
- }
- }
- tot_bt_tris += (poly->VertexCount() == 4 ? 2 : 1);
- }
- }
-
- // This case happens when none of the polys are colliders
- if (tot_bt_tris == 0 || tot_bt_verts == 0)
- return false;
-
- m_vertexArray.resize(tot_bt_verts * 3);
- btScalar *bt = &m_vertexArray[0];
-
- m_triFaceArray.resize(tot_bt_tris * 3);
- int *tri_pt = &m_triFaceArray[0];
-
- /* cant be used for anything useful in this case, since we don't rely on the original mesh
- * will just be an array like pythons range(tot_bt_tris) */
- m_polygonIndexArray.resize(tot_bt_tris);
-
-
- int p = 0;
- int t = 0;
- while (t < tot_bt_tris) {
- RAS_Polygon *poly = meshobj->GetPolygon(p);
-
- if (poly->IsCollider()) {
- /* quad or tri loop */
- fv_pt = (poly->VertexCount() == 3 ? tri_verts : quad_verts);
-
- for (; *fv_pt > -1; fv_pt++) {
- v_orig = poly->GetVertex(*fv_pt)->getOrigIndex();
- if (vert_tag_array[v_orig]) {
- if (transverts) {
- /* deformed mesh, using RAS_TexVert locations would be too troublesome
- * because they are use the gameob as a hash in the material slot */
- *bt++ = transverts[v_orig][0];
- *bt++ = transverts[v_orig][1];
- *bt++ = transverts[v_orig][2];
- }
- else {
- /* static mesh python may have modified */
- xyz = meshobj->GetVertexLocation(v_orig);
- *bt++ = xyz[0];
- *bt++ = xyz[1];
- *bt++ = xyz[2];
- }
- vert_tag_array[v_orig] = false;
- }
- *tri_pt++ = vert_remap_array[v_orig];
- }
- }
- // first triangle
- m_polygonIndexArray[t] = p;
-
- // if the poly is a quad we transform it in two triangles
- if (poly->VertexCount() == 4) {
- t++;
- // second triangle
- m_polygonIndexArray[t] = p;
- }
- t++;
- p++;
- }
- }
-
-#if 0
- /* needs #include <cstdio> */
- printf("# vert count %d\n", m_vertexArray.size());
- for (int i = 0; i < m_vertexArray.size(); i += 3) {
- printf("v %.6f %.6f %.6f\n", m_vertexArray[i], m_vertexArray[i + 1], m_vertexArray[i + 2]);
- }
-
- printf("# face count %d\n", m_triFaceArray.size());
- for (int i = 0; i < m_triFaceArray.size(); i += 3) {
- printf("f %d %d %d\n", m_triFaceArray[i] + 1, m_triFaceArray[i + 1] + 1, m_triFaceArray[i + 2] + 1);
- }
-#endif
-
- /* force recreation of the m_triangleIndexVertexArray.
- * If this has multiple users we cant delete */
- if (m_triangleIndexVertexArray) {
- m_forceReInstance = true;
- }
-
- // Make sure to also replace the mesh in the shape map! Otherwise we leave dangling references when we free.
- // Note, this whole business could cause issues with shared meshes. If we update one mesh, do we replace
- // them all?
- std::map<RAS_MeshObject *, CcdShapeConstructionInfo *>::iterator mit = m_meshShapeMap.find(m_meshObject);
- if (mit != m_meshShapeMap.end()) {
- m_meshShapeMap.erase(mit);
- m_meshShapeMap[meshobj] = this;
- }
-
- m_meshObject = meshobj;
-
- if (dm) {
- dm->needsFree = 1;
- dm->release(dm);
- }
- return true;
-}
-
-bool CcdShapeConstructionInfo::SetProxy(CcdShapeConstructionInfo* shapeInfo)
-{
- if (shapeInfo == NULL)
- return false;
- // no support for dynamic change
- assert(IsUnused());
- m_shapeType = PHY_SHAPE_PROXY;
- m_shapeProxy = shapeInfo;
- return true;
-}
-
-btCollisionShape* CcdShapeConstructionInfo::CreateBulletShape(btScalar margin, bool useGimpact, bool useBvh)
-{
- btCollisionShape* collisionShape = 0;
- btCompoundShape* compoundShape = 0;
-
- if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL)
- return m_shapeProxy->CreateBulletShape(margin, useGimpact, useBvh);
-
- switch (m_shapeType)
- {
- default:
- break;
-
- case PHY_SHAPE_BOX:
- collisionShape = new btBoxShape(m_halfExtend);
- collisionShape->setMargin(margin);
- break;
-
- case PHY_SHAPE_SPHERE:
- collisionShape = new btSphereShape(m_radius);
- collisionShape->setMargin(margin);
- break;
-
- case PHY_SHAPE_CYLINDER:
- collisionShape = new btCylinderShapeZ(m_halfExtend);
- collisionShape->setMargin(margin);
- break;
-
- case PHY_SHAPE_CONE:
- collisionShape = new btConeShapeZ(m_radius, m_height);
- collisionShape->setMargin(margin);
- break;
-
- case PHY_SHAPE_POLYTOPE:
- collisionShape = new btConvexHullShape(&m_vertexArray[0], m_vertexArray.size()/3, 3*sizeof(btScalar));
- collisionShape->setMargin(margin);
- break;
-
- case PHY_SHAPE_CAPSULE:
- collisionShape = new btCapsuleShapeZ(m_radius, m_height);
- collisionShape->setMargin(margin);
- break;
-
- case PHY_SHAPE_MESH:
- // Let's use the latest btScaledBvhTriangleMeshShape: it allows true sharing of
- // triangle mesh information between duplicates => drastic performance increase when
- // duplicating complex mesh objects.
- // BUT it causes a small performance decrease when sharing is not required:
- // 9 multiplications/additions and one function call for each triangle that passes the mid phase filtering
- // One possible optimization is to use directly the btBvhTriangleMeshShape when the scale is 1,1,1
- // and btScaledBvhTriangleMeshShape otherwise.
- if (useGimpact) {
- if (!m_triangleIndexVertexArray || m_forceReInstance) {
- if (m_triangleIndexVertexArray)
- delete m_triangleIndexVertexArray;
-
- m_triangleIndexVertexArray = new btTriangleIndexVertexArray(
- m_polygonIndexArray.size(),
- m_triFaceArray.data(),
- 3 * sizeof(int),
- m_vertexArray.size() / 3,
- &m_vertexArray[0],
- 3 * sizeof(btScalar));
- m_forceReInstance = false;
- }
-
- btGImpactMeshShape *gimpactShape = new btGImpactMeshShape(m_triangleIndexVertexArray);
- gimpactShape->setMargin(margin);
- gimpactShape->updateBound();
- collisionShape = gimpactShape;
- }
- else {
- if (!m_triangleIndexVertexArray || m_forceReInstance) {
- ///enable welding, only for the objects that need it (such as soft bodies)
- if (0.0f != m_weldingThreshold1) {
- btTriangleMesh *collisionMeshData = new btTriangleMesh(true, false);
- collisionMeshData->m_weldingThreshold = m_weldingThreshold1;
- bool removeDuplicateVertices = true;
- // m_vertexArray not in multiple of 3 anymore, use m_triFaceArray
- for (unsigned int i = 0; i < m_triFaceArray.size(); i += 3) {
- btScalar *bt = &m_vertexArray[3 * m_triFaceArray[i]];
- btVector3 v1(bt[0], bt[1], bt[2]);
- bt = &m_vertexArray[3 * m_triFaceArray[i + 1]];
- btVector3 v2(bt[0], bt[1], bt[2]);
- bt = &m_vertexArray[3 * m_triFaceArray[i + 2]];
- btVector3 v3(bt[0], bt[1], bt[2]);
- collisionMeshData->addTriangle(v1, v2, v3, removeDuplicateVertices);
- }
- m_triangleIndexVertexArray = collisionMeshData;
- }
- else {
- m_triangleIndexVertexArray = new btTriangleIndexVertexArray(
- m_polygonIndexArray.size(),
- m_triFaceArray.data(),
- 3 * sizeof(int),
- m_vertexArray.size() / 3,
- &m_vertexArray[0],
- 3 * sizeof(btScalar));
- }
-
- m_forceReInstance = false;
- }
-
- btBvhTriangleMeshShape *unscaledShape = new btBvhTriangleMeshShape(m_triangleIndexVertexArray, true, useBvh);
- unscaledShape->setMargin(margin);
- collisionShape = new btScaledBvhTriangleMeshShape(unscaledShape, btVector3(1.0f, 1.0f, 1.0f));
- collisionShape->setMargin(margin);
- }
- break;
-
- case PHY_SHAPE_COMPOUND:
- if (m_shapeArray.size() > 0)
- {
- compoundShape = new btCompoundShape();
- for (std::vector<CcdShapeConstructionInfo*>::iterator sit = m_shapeArray.begin();
- sit != m_shapeArray.end();
- sit++)
- {
- collisionShape = (*sit)->CreateBulletShape(margin, useGimpact, useBvh);
- if (collisionShape)
- {
- collisionShape->setLocalScaling((*sit)->m_childScale);
- compoundShape->addChildShape((*sit)->m_childTrans, collisionShape);
- }
- }
- collisionShape = compoundShape;
- }
- break;
- }
- return collisionShape;
-}
-
-void CcdShapeConstructionInfo::AddShape(CcdShapeConstructionInfo* shapeInfo)
-{
- m_shapeArray.push_back(shapeInfo);
- shapeInfo->AddRef();
-}
-
-CcdShapeConstructionInfo::~CcdShapeConstructionInfo()
-{
- for (std::vector<CcdShapeConstructionInfo*>::iterator sit = m_shapeArray.begin();
- sit != m_shapeArray.end();
- sit++)
- {
- (*sit)->Release();
- }
- m_shapeArray.clear();
-
- if (m_triangleIndexVertexArray)
- delete m_triangleIndexVertexArray;
- m_vertexArray.clear();
- if (m_shapeType == PHY_SHAPE_MESH && m_meshObject != NULL)
- {
- std::map<RAS_MeshObject*,CcdShapeConstructionInfo*>::iterator mit = m_meshShapeMap.find(m_meshObject);
- if (mit != m_meshShapeMap.end() && mit->second == this)
- {
- m_meshShapeMap.erase(mit);
- }
- }
- if (m_shapeType == PHY_SHAPE_PROXY && m_shapeProxy != NULL)
- {
- m_shapeProxy->Release();
- }
-}
-
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsController.h b/source/gameengine/Physics/Bullet/CcdPhysicsController.h
deleted file mode 100644
index 831e7346df7..00000000000
--- a/source/gameengine/Physics/Bullet/CcdPhysicsController.h
+++ /dev/null
@@ -1,832 +0,0 @@
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-/** \file CcdPhysicsController.h
- * \ingroup physbullet
- */
-
-
-#ifndef __CCDPHYSICSCONTROLLER_H__
-#define __CCDPHYSICSCONTROLLER_H__
-
-#include <vector>
-#include <map>
-
-#include "PHY_IPhysicsController.h"
-
-/// PHY_IPhysicsController is the abstract simplified Interface to a physical object.
-/// It contains the IMotionState and IDeformableMesh Interfaces.
-#include "btBulletDynamicsCommon.h"
-#include "BulletDynamics/Character/btKinematicCharacterController.h"
-#include "LinearMath/btTransform.h"
-
-#include "PHY_IMotionState.h"
-#include "PHY_ICharacter.h"
-
-extern float gDeactivationTime;
-extern float gLinearSleepingTreshold;
-extern float gAngularSleepingTreshold;
-extern bool gDisableDeactivation;
-class CcdPhysicsEnvironment;
-class btMotionState;
-class RAS_MeshObject;
-struct DerivedMesh;
-class btCollisionShape;
-
-
-#define CCD_BSB_SHAPE_MATCHING 2
-#define CCD_BSB_BENDING_CONSTRAINTS 8
-#define CCD_BSB_AERO_VPOINT 16 /* aero model, Vertex normals are oriented toward velocity*/
-#define CCD_BSB_AERO_VTWOSIDE 32 /* aero model, Vertex normals are flipped to match velocity */
-
-/* BulletSoftBody.collisionflags */
-#define CCD_BSB_COL_SDF_RS 2 /* SDF based rigid vs soft */
-#define CCD_BSB_COL_CL_RS 4 /* Cluster based rigid vs soft */
-#define CCD_BSB_COL_CL_SS 8 /* Cluster based soft vs soft */
-#define CCD_BSB_COL_VF_SS 16 /* Vertex/Face based soft vs soft */
-
-
-// Shape contructor
-// It contains all the information needed to create a simple bullet shape at runtime
-class CcdShapeConstructionInfo
-{
-public:
- struct UVco
- {
- float uv[2];
- };
-
- static CcdShapeConstructionInfo* FindMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope);
-
- CcdShapeConstructionInfo() :
- m_shapeType(PHY_SHAPE_NONE),
- m_radius(1.0f),
- m_height(1.0f),
- m_halfExtend(0.f,0.f,0.f),
- m_childScale(1.0f,1.0f,1.0f),
- m_userData(NULL),
- m_refCount(1),
- m_meshObject(NULL),
- m_triangleIndexVertexArray(NULL),
- m_forceReInstance(false),
- m_weldingThreshold1(0.f),
- m_shapeProxy(NULL)
- {
- m_childTrans.setIdentity();
- }
-
- ~CcdShapeConstructionInfo();
-
- CcdShapeConstructionInfo* AddRef()
- {
- m_refCount++;
- return this;
- }
-
- int Release()
- {
- if (--m_refCount > 0)
- return m_refCount;
- delete this;
- return 0;
- }
-
- bool IsUnused(void)
- {
- return (m_meshObject==NULL && m_shapeArray.size() == 0 && m_shapeProxy == NULL);
- }
-
- void AddShape(CcdShapeConstructionInfo* shapeInfo);
-
- btStridingMeshInterface *GetMeshInterface()
- {
- return m_triangleIndexVertexArray;
- }
-
- CcdShapeConstructionInfo* GetChildShape(int i)
- {
- if (i < 0 || i >= (int)m_shapeArray.size())
- return NULL;
-
- return m_shapeArray.at(i);
- }
- int FindChildShape(CcdShapeConstructionInfo* shapeInfo, void* userData)
- {
- if (shapeInfo == NULL)
- return -1;
- for (int i=0; i<(int)m_shapeArray.size(); i++)
- {
- CcdShapeConstructionInfo* childInfo = m_shapeArray.at(i);
- if ((userData == NULL || userData == childInfo->m_userData) &&
- (childInfo == shapeInfo ||
- (childInfo->m_shapeType == PHY_SHAPE_PROXY &&
- childInfo->m_shapeProxy == shapeInfo)))
- return i;
- }
- return -1;
- }
-
- bool RemoveChildShape(int i)
- {
- if (i < 0 || i >= (int)m_shapeArray.size())
- return false;
- m_shapeArray.at(i)->Release();
- if (i < (int)m_shapeArray.size()-1)
- m_shapeArray[i] = m_shapeArray.back();
- m_shapeArray.pop_back();
- return true;
- }
-
- bool SetMesh(class RAS_MeshObject* mesh, struct DerivedMesh* dm, bool polytope);
- RAS_MeshObject* GetMesh(void)
- {
- return m_meshObject;
- }
-
- bool UpdateMesh(class KX_GameObject* gameobj, class RAS_MeshObject* mesh);
-
-
- bool SetProxy(CcdShapeConstructionInfo* shapeInfo);
- CcdShapeConstructionInfo* GetProxy(void)
- {
- return m_shapeProxy;
- }
-
- btCollisionShape* CreateBulletShape(btScalar margin, bool useGimpact=false, bool useBvh=true);
-
- // member variables
- PHY_ShapeType m_shapeType;
- btScalar m_radius;
- btScalar m_height;
- btVector3 m_halfExtend;
- btTransform m_childTrans;
- btVector3 m_childScale;
- void* m_userData;
- btAlignedObjectArray<btScalar> m_vertexArray; // Contains both vertex array for polytope shape and
- // triangle array for concave mesh shape. Each vertex is 3 consecutive values
- // In this case a triangle is made of 3 consecutive points
- std::vector<int> m_polygonIndexArray; // Contains the array of polygon index in the
- // original mesh that correspond to shape triangles.
- // only set for concave mesh shape.
-
- std::vector<int> m_triFaceArray; // Contains an array of triplets of face indices
- // quads turn into 2 tris
-
- std::vector<UVco> m_triFaceUVcoArray; // Contains an array of pair of UV coordinate for each vertex of faces
- // quads turn into 2 tris
-
- void setVertexWeldingThreshold1(float threshold)
- {
- m_weldingThreshold1 = threshold*threshold;
- }
-protected:
- static std::map<RAS_MeshObject*, CcdShapeConstructionInfo*> m_meshShapeMap;
- int m_refCount; // this class is shared between replicas
- // keep track of users so that we can release it
- RAS_MeshObject* m_meshObject; // Keep a pointer to the original mesh
- // The list of vertexes and indexes for the triangle mesh, shared between Bullet shape.
- btTriangleIndexVertexArray *m_triangleIndexVertexArray;
- std::vector<CcdShapeConstructionInfo*> m_shapeArray; // for compound shapes
- bool m_forceReInstance; //use gimpact for concave dynamic/moving collision detection
- float m_weldingThreshold1; //welding closeby vertices together can improve softbody stability etc.
- CcdShapeConstructionInfo* m_shapeProxy; // only used for PHY_SHAPE_PROXY, pointer to actual shape info
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CcdShapeConstructionInfo")
-#endif
-};
-
-struct CcdConstructionInfo
-{
-
- ///CollisionFilterGroups provides some optional usage of basic collision filtering
- ///this is done during broadphase, so very early in the pipeline
- ///more advanced collision filtering should be done in btCollisionDispatcher::NeedsCollision
- enum CollisionFilterGroups
- {
- DefaultFilter = 1,
- StaticFilter = 2,
- KinematicFilter = 4,
- DebrisFilter = 8,
- SensorFilter = 16,
- CharacterFilter = 32,
- AllFilter = DefaultFilter | StaticFilter | KinematicFilter | DebrisFilter | SensorFilter | CharacterFilter,
- };
-
-
- CcdConstructionInfo()
- :m_localInertiaTensor(1.f, 1.f, 1.f),
- m_gravity(0,0,0),
- m_scaling(1.f,1.f,1.f),
- m_linearFactor(0.f, 0.f, 0.f),
- m_angularFactor(0.f, 0.f, 0.f),
- m_mass(0.f),
- m_clamp_vel_min(-1.f),
- m_clamp_vel_max(-1.f),
- m_clamp_angvel_min(0.0f),
- m_clamp_angvel_max(0.0f),
- m_restitution(0.1f),
- m_friction(0.5f),
- m_linearDamping(0.1f),
- m_angularDamping(0.1f),
- m_margin(0.06f),
- m_gamesoftFlag(0),
- m_soft_linStiff(1.f),
- m_soft_angStiff(1.f),
- m_soft_volume(1.f),
- m_soft_viterations(0),
- m_soft_piterations(1),
- m_soft_diterations(0),
- m_soft_citerations(4),
- m_soft_kSRHR_CL(0.1f),
- m_soft_kSKHR_CL(1.f),
- m_soft_kSSHR_CL(0.5f),
- m_soft_kSR_SPLT_CL(0.5f),
- m_soft_kSK_SPLT_CL(0.5f),
- m_soft_kSS_SPLT_CL(0.5f),
- m_soft_kVCF(1.f),
- m_soft_kDP(0.f),
- m_soft_kDG(0.f),
- m_soft_kLF(0.f),
- m_soft_kPR(0.f),
- m_soft_kVC(0.f),
- m_soft_kDF(0.2f),
- m_soft_kMT(0),
- m_soft_kCHR(1.0f),
- m_soft_kKHR(0.1f),
- m_soft_kSHR(1.0f),
- m_soft_kAHR(0.7f),
- m_collisionFlags(0),
- m_bDyna(false),
- m_bRigid(false),
- m_bSoft(false),
- m_bSensor(false),
- m_bCharacter(false),
- m_bGimpact(false),
- m_collisionFilterGroup(DefaultFilter),
- m_collisionFilterMask(AllFilter),
- m_collisionShape(0),
- m_MotionState(0),
- m_shapeInfo(0),
- m_physicsEnv(0),
- m_inertiaFactor(1.f),
- m_do_anisotropic(false),
- m_anisotropicFriction(1.f,1.f,1.f),
- m_do_fh(false),
- m_do_rot_fh(false),
- m_fh_spring(0.f),
- m_fh_damping(0.f),
- m_fh_distance(1.f),
- m_fh_normal(false)
- // m_contactProcessingThreshold(1e10f)
- {
-
- }
-
- btVector3 m_localInertiaTensor;
- btVector3 m_gravity;
- btVector3 m_scaling;
- btVector3 m_linearFactor;
- btVector3 m_angularFactor;
- btScalar m_mass;
- btScalar m_clamp_vel_min;
- btScalar m_clamp_vel_max;
- btScalar m_clamp_angvel_min; // Minimum angular velocity, in radians/sec.
- btScalar m_clamp_angvel_max; // Maximum angular velocity, in radians/sec.
- btScalar m_restitution;
- btScalar m_friction;
- btScalar m_linearDamping;
- btScalar m_angularDamping;
- btScalar m_margin;
-
- ////////////////////
- float m_stepHeight;
- float m_jumpSpeed;
- float m_fallSpeed;
- unsigned char m_maxJumps;
-
- int m_gamesoftFlag;
- float m_soft_linStiff; /* linear stiffness 0..1 */
- float m_soft_angStiff; /* angular stiffness 0..1 */
- float m_soft_volume; /* volume preservation 0..1 */
-
- int m_soft_viterations; /* Velocities solver iterations */
- int m_soft_piterations; /* Positions solver iterations */
- int m_soft_diterations; /* Drift solver iterations */
- int m_soft_citerations; /* Cluster solver iterations */
-
- float m_soft_kSRHR_CL; /* Soft vs rigid hardness [0,1] (cluster only) */
- float m_soft_kSKHR_CL; /* Soft vs kinetic hardness [0,1] (cluster only) */
- float m_soft_kSSHR_CL; /* Soft vs soft hardness [0,1] (cluster only) */
- float m_soft_kSR_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
-
- float m_soft_kSK_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- float m_soft_kSS_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- float m_soft_kVCF; /* Velocities correction factor (Baumgarte) */
- float m_soft_kDP; /* Damping coefficient [0,1] */
-
- float m_soft_kDG; /* Drag coefficient [0,+inf] */
- float m_soft_kLF; /* Lift coefficient [0,+inf] */
- float m_soft_kPR; /* Pressure coefficient [-inf,+inf] */
- float m_soft_kVC; /* Volume conversation coefficient [0,+inf] */
-
- float m_soft_kDF; /* Dynamic friction coefficient [0,1] */
- float m_soft_kMT; /* Pose matching coefficient [0,1] */
- float m_soft_kCHR; /* Rigid contacts hardness [0,1] */
- float m_soft_kKHR; /* Kinetic contacts hardness [0,1] */
-
- float m_soft_kSHR; /* Soft contacts hardness [0,1] */
- float m_soft_kAHR; /* Anchors hardness [0,1] */
- int m_soft_collisionflags; /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
- int m_soft_numclusteriterations; /* number of iterations to refine collision clusters*/
-///////////////////
-
-
-
- int m_collisionFlags;
- bool m_bDyna;
- bool m_bRigid;
- bool m_bSoft;
- bool m_bSensor;
- bool m_bCharacter;
- bool m_bGimpact; // use Gimpact for mesh body
-
- ///optional use of collision group/mask:
- ///only collision with object goups that match the collision mask.
- ///this is very basic early out. advanced collision filtering should be
- ///done in the btCollisionDispatcher::NeedsCollision and NeedsResponse
- ///both values default to 1
- short int m_collisionFilterGroup;
- short int m_collisionFilterMask;
-
- ///these pointers are used as argument passing for the CcdPhysicsController constructor
- ///and not anymore after that
- class btCollisionShape* m_collisionShape;
- class PHY_IMotionState* m_MotionState;
- class CcdShapeConstructionInfo* m_shapeInfo;
-
- CcdPhysicsEnvironment* m_physicsEnv; //needed for self-replication
- float m_inertiaFactor;//tweak the inertia (hooked up to Blender 'formfactor'
- bool m_do_anisotropic;
- btVector3 m_anisotropicFriction;
-
- bool m_do_fh; ///< Should the object have a linear Fh spring?
- bool m_do_rot_fh; ///< Should the object have an angular Fh spring?
- btScalar m_fh_spring; ///< Spring constant (both linear and angular)
- btScalar m_fh_damping; ///< Damping factor (linear and angular) in range [0, 1]
- btScalar m_fh_distance; ///< The range above the surface where Fh is active.
- bool m_fh_normal; ///< Should the object slide off slopes?
- float m_radius;//for fh backwards compatibility
-
- ///m_contactProcessingThreshold allows to process contact points with positive distance
- ///normally only contacts with negative distance (penetration) are solved
- ///however, rigid body stacking is more stable when positive contacts are still passed into the constraint solver
- ///this might sometimes lead to collisions with 'internal edges' such as a sliding character controller
- ///so disable/set m_contactProcessingThreshold to zero for sliding characters etc.
- // float m_contactProcessingThreshold;///< Process contacts with positive distance in range [0..INF]
-};
-
-class btRigidBody;
-class btCollisionObject;
-class btSoftBody;
-class btPairCachingGhostObject;
-
-class BlenderBulletCharacterController : public btKinematicCharacterController, public PHY_ICharacter
-{
-private:
- btMotionState* m_motionState;
- unsigned char m_jumps;
- unsigned char m_maxJumps;
-
-public:
- BlenderBulletCharacterController(btMotionState *motionState, btPairCachingGhostObject *ghost, btConvexShape* shape, float stepHeight);
-
- virtual void updateAction(btCollisionWorld *collisionWorld, btScalar dt);
-
- unsigned char getMaxJumps() const;
-
- void setMaxJumps(unsigned char maxJumps);
-
- unsigned char getJumpCount() const;
-
- virtual bool canJump() const;
-
- virtual void jump();
-
- const btVector3& getWalkDirection();
-
- // PHY_ICharacter interface
- virtual void Jump() { jump(); }
- virtual bool OnGround() { return onGround(); }
- virtual float GetGravity() { return getGravity(); }
- virtual void SetGravity(float gravity) { setGravity(gravity); }
- virtual unsigned char GetMaxJumps() { return getMaxJumps(); }
- virtual void SetMaxJumps(unsigned char maxJumps) { setMaxJumps(maxJumps); }
- virtual unsigned char GetJumpCount() { return getJumpCount(); }
- virtual void SetWalkDirection(const MT_Vector3& dir)
- {
- btVector3 vec = btVector3(dir[0], dir[1], dir[2]);
- setWalkDirection(vec);
- }
- virtual MT_Vector3 GetWalkDirection()
- {
- btVector3 vec = getWalkDirection();
- return MT_Vector3(vec[0], vec[1], vec[2]);
- }
-
-#ifdef WITH_CXX_GUARDEDALLOC
- using PHY_ICharacter::operator new;
- using PHY_ICharacter::operator delete;
-#endif
-};
-
-class CleanPairCallback : public btOverlapCallback
-{
- btBroadphaseProxy *m_cleanProxy;
- btOverlappingPairCache *m_pairCache;
- btDispatcher *m_dispatcher;
-
-public:
- CleanPairCallback(btBroadphaseProxy *cleanProxy, btOverlappingPairCache *pairCache, btDispatcher *dispatcher)
- :m_cleanProxy(cleanProxy),
- m_pairCache(pairCache),
- m_dispatcher(dispatcher)
- {
- }
-
- virtual bool processOverlap(btBroadphasePair &pair);
-};
-
-///CcdPhysicsController is a physics object that supports continuous collision detection and time of impact based physics resolution.
-class CcdPhysicsController : public PHY_IPhysicsController
-{
-protected:
- btCollisionObject* m_object;
- BlenderBulletCharacterController* m_characterController;
-
-
- class PHY_IMotionState* m_MotionState;
- btMotionState* m_bulletMotionState;
- class btCollisionShape* m_collisionShape;
- class CcdShapeConstructionInfo* m_shapeInfo;
- btCollisionShape* m_bulletChildShape;
-
- btAlignedObjectArray<btTypedConstraint*> m_ccdConstraintRefs; // keep track of typed constraints referencing this rigid body
- friend class CcdPhysicsEnvironment; // needed when updating the controller
-
- //some book keeping for replication
- bool m_softbodyMappingDone;
- bool m_softBodyTransformInitialized;
- bool m_prototypeTransformInitialized;
- btTransform m_softbodyStartTrans;
-
-
- void* m_newClientInfo;
- int m_registerCount; // needed when multiple sensors use the same controller
- CcdConstructionInfo m_cci;//needed for replication
-
- CcdPhysicsController* m_parentCtrl;
-
- int m_savedCollisionFlags;
- short m_savedCollisionFilterGroup;
- short m_savedCollisionFilterMask;
- MT_Scalar m_savedMass;
- bool m_savedDyna;
- bool m_suspended;
-
-
- void GetWorldOrientation(btMatrix3x3& mat);
-
- void CreateRigidbody();
- bool CreateSoftbody();
- bool CreateCharacterController();
-
- bool Register() {
- return (m_registerCount++ == 0) ? true : false;
- }
- bool Unregister() {
- return (--m_registerCount == 0) ? true : false;
- }
-
- bool Registered() const
- {
- return (m_registerCount != 0);
- }
-
- void addCcdConstraintRef(btTypedConstraint* c);
- void removeCcdConstraintRef(btTypedConstraint* c);
- btTypedConstraint* getCcdConstraintRef(int index);
- int getNumCcdConstraintRefs() const;
-
- void SetWorldOrientation(const btMatrix3x3& mat);
- void ForceWorldTransform(const btMatrix3x3& mat, const btVector3& pos);
-
- public:
-
- int m_collisionDelay;
-
-
- CcdPhysicsController (const CcdConstructionInfo& ci);
-
- /**
- * Delete the current Bullet shape used in the rigid body.
- */
- bool DeleteControllerShape();
-
- /**
- * Delete the old Bullet shape and set the new Bullet shape : newShape
- * \param newShape The new Bullet shape to set, if is NULL we create a new Bullet shape
- */
- bool ReplaceControllerShape(btCollisionShape *newShape);
-
- virtual ~CcdPhysicsController();
-
- CcdConstructionInfo& GetConstructionInfo()
- {
- return m_cci;
- }
- const CcdConstructionInfo& GetConstructionInfo() const
- {
- return m_cci;
- }
-
-
- btRigidBody* GetRigidBody();
- const btRigidBody* GetRigidBody() const;
- btCollisionObject* GetCollisionObject();
- btSoftBody* GetSoftBody();
- btKinematicCharacterController* GetCharacterController();
-
- CcdShapeConstructionInfo* GetShapeInfo() { return m_shapeInfo; }
-
- btCollisionShape* GetCollisionShape() {
- return m_object->getCollisionShape();
- }
- ////////////////////////////////////
- // PHY_IPhysicsController interface
- ////////////////////////////////////
-
-
- /**
- * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
- */
- virtual bool SynchronizeMotionStates(float time);
-
- /**
- * Called for every physics simulation step. Use this method for
- * things like limiting linear and angular velocity.
- */
- void SimulationTick(float timestep);
-
- /**
- * WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
- */
-
- virtual void WriteMotionStateToDynamics(bool nondynaonly);
- virtual void WriteDynamicsToMotionState();
-
- // controller replication
- virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl);
- virtual void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment *env);
-
- // kinematic methods
- virtual void RelativeTranslate(const MT_Vector3& dloc,bool local);
- virtual void RelativeRotate(const MT_Matrix3x3&rotval, bool local);
- virtual MT_Matrix3x3 GetOrientation();
- virtual void SetOrientation(const MT_Matrix3x3& orn);
- virtual void SetPosition(const MT_Vector3& pos);
- virtual void GetPosition(MT_Vector3& pos) const;
- virtual void SetScaling(const MT_Vector3& scale);
- virtual void SetTransform();
-
- virtual MT_Scalar GetMass();
- virtual void SetMass(MT_Scalar newmass);
-
- // physics methods
- virtual void ApplyImpulse(const MT_Point3& attach, const MT_Vector3& impulsein, bool local);
- virtual void ApplyTorque(const MT_Vector3& torque,bool local);
- virtual void ApplyForce(const MT_Vector3& force,bool local);
- virtual void SetAngularVelocity(const MT_Vector3& ang_vel,bool local);
- virtual void SetLinearVelocity(const MT_Vector3& lin_vel,bool local);
- virtual void Jump();
- virtual void SetActive(bool active);
-
- virtual float GetLinearDamping() const;
- virtual float GetAngularDamping() const;
- virtual void SetLinearDamping(float damping);
- virtual void SetAngularDamping(float damping);
- virtual void SetDamping(float linear, float angular);
-
- // reading out information from physics
- virtual MT_Vector3 GetLinearVelocity();
- virtual MT_Vector3 GetAngularVelocity();
- virtual MT_Vector3 GetVelocity(const MT_Point3& posin);
- virtual MT_Vector3 GetLocalInertia();
-
- // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted
- virtual void SetRigidBody(bool rigid);
-
-
- virtual void ResolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ);
- virtual void RefreshCollisions();
- virtual void SuspendDynamics(bool ghost);
- virtual void RestoreDynamics();
-
- // Shape control
- virtual void AddCompoundChild(PHY_IPhysicsController* child);
- virtual void RemoveCompoundChild(PHY_IPhysicsController* child);
-
- // clientinfo for raycasts for example
- virtual void* GetNewClientInfo();
- virtual void SetNewClientInfo(void* clientinfo);
- virtual PHY_IPhysicsController* GetReplica();
- virtual PHY_IPhysicsController* GetReplicaForSensors();
-
- ///There should be no 'SetCollisionFilterGroup' method, as changing this during run-time is will result in errors
- short int GetCollisionFilterGroup() const
- {
- return m_cci.m_collisionFilterGroup;
- }
- ///There should be no 'SetCollisionFilterGroup' method, as changing this during run-time is will result in errors
- short int GetCollisionFilterMask() const
- {
- return m_cci.m_collisionFilterMask;
- }
-
- virtual void CalcXform() {}
- virtual void SetMargin(float margin)
- {
- if (m_collisionShape) {
- m_collisionShape->setMargin(margin);
- // if the shape use a unscaled shape we have also to set the correct margin in it
- if (m_collisionShape->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE)
- ((btScaledBvhTriangleMeshShape *)m_collisionShape)->getChildShape()->setMargin(margin);
- }
- }
- virtual float GetMargin() const
- {
- return (m_collisionShape) ? m_collisionShape->getMargin() : 0.f;
- }
- virtual float GetRadius() const
- {
- // this is not the actual shape radius, it's only used for Fh support
- return m_cci.m_radius;
- }
- virtual void SetRadius(float margin)
- {
- if (m_collisionShape && m_collisionShape->getShapeType() == SPHERE_SHAPE_PROXYTYPE)
- {
- btSphereShape* sphereShape = static_cast<btSphereShape*>(m_collisionShape);
- sphereShape->setUnscaledRadius(margin);
- }
- m_cci.m_radius = margin;
- }
-
- // velocity clamping
- virtual void SetLinVelocityMin(float val)
- {
- m_cci.m_clamp_vel_min= val;
- }
- virtual float GetLinVelocityMin() const
- {
- return m_cci.m_clamp_vel_min;
- }
- virtual void SetLinVelocityMax(float val)
- {
- m_cci.m_clamp_vel_max= val;
- }
- virtual float GetLinVelocityMax() const
- {
- return m_cci.m_clamp_vel_max;
- }
-
- virtual void SetAngularVelocityMin(float val)
- {
- m_cci.m_clamp_angvel_min = val;
- }
- virtual float GetAngularVelocityMin() const
- {
- return m_cci.m_clamp_angvel_min;
- }
- virtual void SetAngularVelocityMax(float val)
- {
- m_cci.m_clamp_angvel_max = val;
- }
- virtual float GetAngularVelocityMax() const
- {
- return m_cci.m_clamp_angvel_max;
- }
-
- bool WantsSleeping();
-
- void UpdateDeactivation(float timeStep);
-
- void SetCenterOfMassTransform(btTransform& xform);
-
- static btTransform& GetTransformFromMotionState(PHY_IMotionState* motionState);
-
- void setAabb(const btVector3& aabbMin,const btVector3& aabbMax);
-
-
- class PHY_IMotionState* GetMotionState()
- {
- return m_MotionState;
- }
-
- const class PHY_IMotionState* GetMotionState() const
- {
- return m_MotionState;
- }
-
- class CcdPhysicsEnvironment* GetPhysicsEnvironment()
- {
- return m_cci.m_physicsEnv;
- }
-
- void SetParentCtrl(CcdPhysicsController* parentCtrl)
- {
- m_parentCtrl = parentCtrl;
- }
-
- CcdPhysicsController* GetParentCtrl()
- {
- return m_parentCtrl;
- }
-
- const CcdPhysicsController* GetParentCtrl() const
- {
- return m_parentCtrl;
- }
-
- virtual bool IsDynamic()
- {
- return GetConstructionInfo().m_bDyna;
- }
-
- virtual bool IsSuspended() const
- {
- return m_suspended;
- }
-
- virtual bool IsCompound()
- {
- return GetConstructionInfo().m_shapeInfo->m_shapeType == PHY_SHAPE_COMPOUND;
- }
-
- virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj);
-
- /* Method to replicate rigid body joint contraints for group instances. */
- virtual void ReplicateConstraints(KX_GameObject *gameobj, std::vector<KX_GameObject*> constobj);
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CcdPhysicsController")
-#endif
-};
-
-
-
-
-///DefaultMotionState implements standard motionstate, using btTransform
-class DefaultMotionState : public PHY_IMotionState
-
-{
- public:
- DefaultMotionState();
-
- virtual ~DefaultMotionState();
-
- virtual void GetWorldPosition(float& posX,float& posY,float& posZ);
- virtual void GetWorldScaling(float& scaleX,float& scaleY,float& scaleZ);
- virtual void GetWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal);
-
- virtual void SetWorldPosition(float posX,float posY,float posZ);
- virtual void SetWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal);
- virtual void GetWorldOrientation(float* ori);
- virtual void SetWorldOrientation(const float* ori);
-
- virtual void CalculateWorldTransformations();
-
- btTransform m_worldTransform;
- btVector3 m_localScaling;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:DefaultMotionState")
-#endif
-};
-
-
-#endif /* __CCDPHYSICSCONTROLLER_H__ */
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
deleted file mode 100644
index 78d2d88cc65..00000000000
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
+++ /dev/null
@@ -1,3795 +0,0 @@
-/** \file gameengine/Physics/Bullet/CcdPhysicsEnvironment.cpp
- * \ingroup physbullet
- */
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-
-
-
-#include "CcdPhysicsEnvironment.h"
-#include "CcdPhysicsController.h"
-#include "CcdGraphicController.h"
-
-#include <algorithm>
-#include "btBulletDynamicsCommon.h"
-#include "LinearMath/btIDebugDraw.h"
-#include "BulletCollision/CollisionDispatch/btGhostObject.h"
-#include "BulletCollision/CollisionDispatch/btSimulationIslandManager.h"
-#include "BulletSoftBody/btSoftRigidDynamicsWorld.h"
-#include "BulletSoftBody/btSoftBodyRigidBodyCollisionConfiguration.h"
-#include "BulletCollision/Gimpact/btGImpactCollisionAlgorithm.h"
-#include "BulletCollision/NarrowPhaseCollision/btRaycastCallback.h"
-
-//profiling/timings
-#include "LinearMath/btQuickprof.h"
-
-
-#include "PHY_IMotionState.h"
-#include "PHY_ICharacter.h"
-#include "PHY_Pro.h"
-#include "KX_GameObject.h"
-#include "KX_PythonInit.h" // for KX_RasterizerDrawDebugLine
-#include "KX_BlenderSceneConverter.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-#include "RAS_TexVert.h"
-
-#include "DNA_scene_types.h"
-#include "DNA_world_types.h"
-#include "DNA_object_force_types.h"
-
-extern "C" {
- #include "BLI_utildefines.h"
- #include "BKE_object.h"
-}
-
-#define CCD_CONSTRAINT_DISABLE_LINKED_COLLISION 0x80
-
-#ifdef NEW_BULLET_VEHICLE_SUPPORT
-#include "BulletDynamics/Vehicle/btRaycastVehicle.h"
-#include "BulletDynamics/Vehicle/btVehicleRaycaster.h"
-#include "BulletDynamics/Vehicle/btWheelInfo.h"
-#include "PHY_IVehicle.h"
-static btRaycastVehicle::btVehicleTuning gTuning;
-
-#endif //NEW_BULLET_VEHICLE_SUPPORT
-#include "LinearMath/btAabbUtil2.h"
-#include "MT_Matrix4x4.h"
-#include "MT_Vector3.h"
-#include "MT_MinMax.h"
-
-#ifdef WIN32
-void DrawRasterizerLine(const float* from,const float* to,int color);
-#endif
-
-
-#include "BulletDynamics/ConstraintSolver/btContactConstraint.h"
-
-
-#include <stdio.h>
-#include <string.h> // for memset
-
-// This was copied from the old KX_ConvertPhysicsObjects
-#ifdef WIN32
-#ifdef _MSC_VER
-//only use SIMD Hull code under Win32
-//#define TEST_HULL 1
-#ifdef TEST_HULL
-#define USE_HULL 1
-//#define TEST_SIMD_HULL 1
-
-#include "NarrowPhaseCollision/Hull.h"
-#endif //#ifdef TEST_HULL
-
-#endif //_MSC_VER
-#endif //WIN32
-
-#ifdef NEW_BULLET_VEHICLE_SUPPORT
-class WrapperVehicle : public PHY_IVehicle
-{
-
- btRaycastVehicle* m_vehicle;
- PHY_IPhysicsController* m_chassis;
-
-public:
-
- WrapperVehicle(btRaycastVehicle* vehicle,PHY_IPhysicsController* chassis)
- :m_vehicle(vehicle),
- m_chassis(chassis)
- {
- }
-
- ~WrapperVehicle()
- {
- delete m_vehicle;
- }
-
- btRaycastVehicle* GetVehicle()
- {
- return m_vehicle;
- }
-
- PHY_IPhysicsController* GetChassis()
- {
- return m_chassis;
- }
-
- virtual void AddWheel(
- PHY_IMotionState* motionState,
- MT_Vector3 connectionPoint,
- MT_Vector3 downDirection,
- MT_Vector3 axleDirection,
- float suspensionRestLength,
- float wheelRadius,
- bool hasSteering
- )
- {
- btVector3 connectionPointCS0(connectionPoint[0],connectionPoint[1],connectionPoint[2]);
- btVector3 wheelDirectionCS0(downDirection[0],downDirection[1],downDirection[2]);
- btVector3 wheelAxle(axleDirection[0],axleDirection[1],axleDirection[2]);
-
-
- btWheelInfo& info = m_vehicle->addWheel(connectionPointCS0,wheelDirectionCS0,wheelAxle,
- suspensionRestLength,wheelRadius,gTuning,hasSteering);
- info.m_clientInfo = motionState;
-
- }
-
- void SyncWheels()
- {
- int numWheels = GetNumWheels();
- int i;
- for (i=0;i<numWheels;i++)
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(i);
- PHY_IMotionState* motionState = (PHY_IMotionState*)info.m_clientInfo;
- // m_vehicle->updateWheelTransformsWS(info,false);
- m_vehicle->updateWheelTransform(i,false);
- btTransform trans = m_vehicle->getWheelInfo(i).m_worldTransform;
- btQuaternion orn = trans.getRotation();
- const btVector3& pos = trans.getOrigin();
- motionState->SetWorldOrientation(orn.x(),orn.y(),orn.z(),orn[3]);
- motionState->SetWorldPosition(pos.x(),pos.y(),pos.z());
-
- }
- }
-
- virtual int GetNumWheels() const
- {
- return m_vehicle->getNumWheels();
- }
-
- virtual void GetWheelPosition(int wheelIndex,float& posX,float& posY,float& posZ) const
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btVector3 origin = m_vehicle->getWheelTransformWS(wheelIndex).getOrigin();
-
- posX = origin.x();
- posY = origin.y();
- posZ = origin.z();
- }
- }
-
- virtual void GetWheelOrientationQuaternion(int wheelIndex,float& quatX,float& quatY,float& quatZ,float& quatW) const
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btQuaternion quat = m_vehicle->getWheelTransformWS(wheelIndex).getRotation();
-
- quatX = quat.x();
- quatY = quat.y();
- quatZ = quat.z();
- quatW = quat.w();
- }
- }
-
- virtual float GetWheelRotation(int wheelIndex) const
- {
- float rotation = 0.f;
-
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
- rotation = info.m_rotation;
- }
-
- return rotation;
- }
-
-
-
- virtual int GetUserConstraintId() const
- {
- return m_vehicle->getUserConstraintId();
- }
-
- virtual int GetUserConstraintType() const
- {
- return m_vehicle->getUserConstraintType();
- }
-
- virtual void SetSteeringValue(float steering,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels())) {
- m_vehicle->setSteeringValue(steering,wheelIndex);
- }
- }
-
- virtual void ApplyEngineForce(float force,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels())) {
- m_vehicle->applyEngineForce(force,wheelIndex);
- }
- }
-
- virtual void ApplyBraking(float braking,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
- info.m_brake = braking;
- }
- }
-
- virtual void SetWheelFriction(float friction,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
- info.m_frictionSlip = friction;
- }
-
- }
-
- virtual void SetSuspensionStiffness(float suspensionStiffness,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
- info.m_suspensionStiffness = suspensionStiffness;
-
- }
- }
-
- virtual void SetSuspensionDamping(float suspensionDamping,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
- info.m_wheelsDampingRelaxation = suspensionDamping;
- }
- }
-
- virtual void SetSuspensionCompression(float suspensionCompression,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
- info.m_wheelsDampingCompression = suspensionCompression;
- }
- }
-
-
-
- virtual void SetRollInfluence(float rollInfluence,int wheelIndex)
- {
- if ((wheelIndex>=0) && (wheelIndex< m_vehicle->getNumWheels()))
- {
- btWheelInfo& info = m_vehicle->getWheelInfo(wheelIndex);
- info.m_rollInfluence = rollInfluence;
- }
- }
-
- virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex)
- {
- m_vehicle->setCoordinateSystem(rightIndex,upIndex,forwardIndex);
- }
-
-
-
-};
-
-class BlenderVehicleRaycaster: public btDefaultVehicleRaycaster
-{
- btDynamicsWorld* m_dynamicsWorld;
-public:
- BlenderVehicleRaycaster(btDynamicsWorld* world)
- :btDefaultVehicleRaycaster(world), m_dynamicsWorld(world)
- {
- }
-
- virtual void* castRay(const btVector3& from,const btVector3& to, btVehicleRaycasterResult& result)
- {
- // RayResultCallback& resultCallback;
-
- btCollisionWorld::ClosestRayResultCallback rayCallback(from,to);
-
- // We override btDefaultVehicleRaycaster so we can set this flag, otherwise our
- // vehicles go crazy (http://bulletphysics.org/Bullet/phpBB3/viewtopic.php?t=9662)
- rayCallback.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest;
-
- m_dynamicsWorld->rayTest(from, to, rayCallback);
-
- if (rayCallback.hasHit())
- {
-
- const btRigidBody* body = btRigidBody::upcast(rayCallback.m_collisionObject);
- if (body && body->hasContactResponse())
- {
- result.m_hitPointInWorld = rayCallback.m_hitPointWorld;
- result.m_hitNormalInWorld = rayCallback.m_hitNormalWorld;
- result.m_hitNormalInWorld.normalize();
- result.m_distFraction = rayCallback.m_closestHitFraction;
- return (void*)body;
- }
- }
- return 0;
- }
-};
-#endif //NEW_BULLET_VEHICLE_SUPPORT
-
-class CcdOverlapFilterCallBack : public btOverlapFilterCallback
-{
-private:
- class CcdPhysicsEnvironment* m_physEnv;
-public:
- CcdOverlapFilterCallBack(CcdPhysicsEnvironment* env) :
- m_physEnv(env)
- {
- }
- virtual ~CcdOverlapFilterCallBack()
- {
- }
- // return true when pairs need collision
- virtual bool needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const;
-};
-
-
-void CcdPhysicsEnvironment::SetDebugDrawer(btIDebugDraw* debugDrawer)
-{
- if (debugDrawer && m_dynamicsWorld)
- m_dynamicsWorld->setDebugDrawer(debugDrawer);
- m_debugDrawer = debugDrawer;
-}
-
-#if 0
-static void DrawAabb(btIDebugDraw* debugDrawer,const btVector3& from,const btVector3& to,const btVector3& color)
-{
- btVector3 halfExtents = (to-from)* 0.5f;
- btVector3 center = (to+from) *0.5f;
- int i,j;
-
- btVector3 edgecoord(1.f,1.f,1.f),pa,pb;
- for (i=0;i<4;i++)
- {
- for (j=0;j<3;j++)
- {
- pa = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
- edgecoord[2]*halfExtents[2]);
- pa+=center;
-
- int othercoord = j%3;
- edgecoord[othercoord]*=-1.f;
- pb = btVector3(edgecoord[0]*halfExtents[0], edgecoord[1]*halfExtents[1],
- edgecoord[2]*halfExtents[2]);
- pb+=center;
-
- debugDrawer->drawLine(pa,pb,color);
- }
- edgecoord = btVector3(-1.f,-1.f,-1.f);
- if (i<3)
- edgecoord[i]*=-1.f;
- }
-}
-#endif
-
-
-
-
-
-CcdPhysicsEnvironment::CcdPhysicsEnvironment(bool useDbvtCulling,btDispatcher* dispatcher,btOverlappingPairCache* pairCache)
-:m_cullingCache(NULL),
-m_cullingTree(NULL),
-m_numIterations(10),
-m_numTimeSubSteps(1),
-m_ccdMode(0),
-m_solverType(-1),
-m_profileTimings(0),
-m_enableSatCollisionDetection(false),
-m_deactivationTime(2.0f),
-m_linearDeactivationThreshold(0.8f),
-m_angularDeactivationThreshold(1.0f),
-m_contactBreakingThreshold(0.02f),
-m_solver(NULL),
-m_ownPairCache(NULL),
-m_filterCallback(NULL),
-m_ghostPairCallback(NULL),
-m_ownDispatcher(NULL),
-m_scalingPropagated(false)
-{
-
- for (int i=0;i<PHY_NUM_RESPONSE;i++)
- {
- m_triggerCallbacks[i] = 0;
- }
-
-// m_collisionConfiguration = new btDefaultCollisionConfiguration();
- m_collisionConfiguration = new btSoftBodyRigidBodyCollisionConfiguration();
- //m_collisionConfiguration->setConvexConvexMultipointIterations();
-
- if (!dispatcher)
- {
- btCollisionDispatcher* disp = new btCollisionDispatcher(m_collisionConfiguration);
- dispatcher = disp;
- btGImpactCollisionAlgorithm::registerAlgorithm(disp);
- m_ownDispatcher = dispatcher;
- }
-
- //m_broadphase = new btAxisSweep3(btVector3(-1000,-1000,-1000),btVector3(1000,1000,1000));
- //m_broadphase = new btSimpleBroadphase();
- m_broadphase = new btDbvtBroadphase();
- // avoid any collision in the culling tree
- if (useDbvtCulling) {
- m_cullingCache = new btNullPairCache();
- m_cullingTree = new btDbvtBroadphase(m_cullingCache);
- }
-
- m_filterCallback = new CcdOverlapFilterCallBack(this);
- m_ghostPairCallback = new btGhostPairCallback();
- m_broadphase->getOverlappingPairCache()->setOverlapFilterCallback(m_filterCallback);
- m_broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(m_ghostPairCallback);
-
- SetSolverType(1);//issues with quickstep and memory allocations
-// m_dynamicsWorld = new btDiscreteDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
- m_dynamicsWorld = new btSoftRigidDynamicsWorld(dispatcher,m_broadphase,m_solver,m_collisionConfiguration);
- m_dynamicsWorld->setInternalTickCallback(&CcdPhysicsEnvironment::StaticSimulationSubtickCallback, this);
- //m_dynamicsWorld->getSolverInfo().m_linearSlop = 0.01f;
- //m_dynamicsWorld->getSolverInfo().m_solverMode= SOLVER_USE_WARMSTARTING + SOLVER_USE_2_FRICTION_DIRECTIONS + SOLVER_RANDMIZE_ORDER + SOLVER_USE_FRICTION_WARMSTARTING;
-
- m_debugDrawer = 0;
- SetGravity(0.f,0.f,-9.81f);
-}
-
-void CcdPhysicsEnvironment::AddCcdPhysicsController(CcdPhysicsController* ctrl)
-{
- // the controller is already added we do nothing
- if (!m_controllers.insert(ctrl).second) {
- return;
- }
-
- btRigidBody* body = ctrl->GetRigidBody();
- btCollisionObject* obj = ctrl->GetCollisionObject();
-
- //this m_userPointer is just used for triggers, see CallbackTriggers
- obj->setUserPointer(ctrl);
- if (body) {
- body->setGravity(m_gravity);
- body->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold);
- }
-
- if (body)
- {
- //use explicit group/filter for finer control over collision in bullet => near/radar sensor
- m_dynamicsWorld->addRigidBody(body, ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask());
- } else
- {
- if (ctrl->GetSoftBody())
- {
- btSoftBody* softBody = ctrl->GetSoftBody();
- m_dynamicsWorld->addSoftBody(softBody);
- } else
- {
- if (obj->getCollisionShape())
- {
- m_dynamicsWorld->addCollisionObject(obj, ctrl->GetCollisionFilterGroup(), ctrl->GetCollisionFilterMask());
- }
- if (ctrl->GetCharacterController())
- {
- m_dynamicsWorld->addAction(ctrl->GetCharacterController());
- }
- }
- }
- if (obj->isStaticOrKinematicObject())
- {
- obj->setActivationState(ISLAND_SLEEPING);
- }
-
- assert(obj->getBroadphaseHandle());
-}
-
-void CcdPhysicsEnvironment::RemoveConstraint(btTypedConstraint *con)
-{
- btRigidBody &rbA = con->getRigidBodyA();
- btRigidBody &rbB = con->getRigidBodyB();
- rbA.activate();
- rbB.activate();
- m_dynamicsWorld->removeConstraint(con);
-
- if (rbA.getUserPointer()) {
- ((CcdPhysicsController *)rbA.getUserPointer())->removeCcdConstraintRef(con);
- }
-
- if (rbB.getUserPointer()) {
- ((CcdPhysicsController *)rbB.getUserPointer())->removeCcdConstraintRef(con);
- }
-
- /* Since we remove the constraint in the onwer and the target, we can delete it,
- * KX_ConstraintWrapper keep the constraint id not the pointer, so no problems. */
- delete con;
-}
-
-bool CcdPhysicsEnvironment::RemoveCcdPhysicsController(CcdPhysicsController* ctrl)
-{
- // if the physics controller is already removed we do nothing
- if (!m_controllers.erase(ctrl)) {
- return false;
- }
-
- //also remove constraint
- btRigidBody* body = ctrl->GetRigidBody();
- if (body)
- {
- btBroadphaseProxy *proxy = ctrl->GetCollisionObject()->getBroadphaseHandle();
- btDispatcher *dispatcher = m_dynamicsWorld->getDispatcher();
- btOverlappingPairCache *pairCache = m_dynamicsWorld->getPairCache();
-
- CleanPairCallback cleanPairs(proxy, pairCache, dispatcher);
- pairCache->processAllOverlappingPairs(&cleanPairs, dispatcher);
-
- for (int i = ctrl->getNumCcdConstraintRefs() - 1; i >= 0; i--)
- {
- btTypedConstraint* con = ctrl->getCcdConstraintRef(i);
- RemoveConstraint(con);
- }
- m_dynamicsWorld->removeRigidBody(ctrl->GetRigidBody());
-
- // Handle potential vehicle constraints
- int numVehicles = m_wrapperVehicles.size();
- int vehicle_constraint = 0;
- for (int i=0;i<numVehicles;i++)
- {
- WrapperVehicle* wrapperVehicle = m_wrapperVehicles[i];
- if (wrapperVehicle->GetChassis() == ctrl)
- vehicle_constraint = wrapperVehicle->GetVehicle()->getUserConstraintId();
- }
-
- if (vehicle_constraint > 0)
- RemoveConstraintById(vehicle_constraint);
- } else
- {
- //if a softbody
- if (ctrl->GetSoftBody())
- {
- m_dynamicsWorld->removeSoftBody(ctrl->GetSoftBody());
- } else
- {
- m_dynamicsWorld->removeCollisionObject(ctrl->GetCollisionObject());
-
- if (ctrl->GetCharacterController())
- {
- m_dynamicsWorld->removeAction(ctrl->GetCharacterController());
- }
- }
- }
-
- return true;
-}
-
-void CcdPhysicsEnvironment::UpdateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask)
-{
- // this function is used when the collisionning group of a controller is changed
- // remove and add the collistioning object
- btRigidBody* body = ctrl->GetRigidBody();
- btSoftBody *softBody = ctrl->GetSoftBody();
- btCollisionObject* obj = ctrl->GetCollisionObject();
- if (obj)
- {
- btVector3 inertia(0.0f,0.0f,0.0f);
- m_dynamicsWorld->removeCollisionObject(obj);
- obj->setCollisionFlags(newCollisionFlags);
- if (body)
- {
- if (newMass)
- body->getCollisionShape()->calculateLocalInertia(newMass, inertia);
- body->setMassProps(newMass, inertia);
- m_dynamicsWorld->addRigidBody(body, newCollisionGroup, newCollisionMask);
- }
- else if (softBody) {
- m_dynamicsWorld->addSoftBody(softBody);
- }
- else {
- m_dynamicsWorld->addCollisionObject(obj, newCollisionGroup, newCollisionMask);
- }
- }
- // to avoid nasty interaction, we must update the property of the controller as well
- ctrl->m_cci.m_mass = newMass;
- ctrl->m_cci.m_collisionFilterGroup = newCollisionGroup;
- ctrl->m_cci.m_collisionFilterMask = newCollisionMask;
- ctrl->m_cci.m_collisionFlags = newCollisionFlags;
-}
-
-void CcdPhysicsEnvironment::RefreshCcdPhysicsController(CcdPhysicsController* ctrl)
-{
- btCollisionObject* obj = ctrl->GetCollisionObject();
- if (obj)
- {
- btBroadphaseProxy* proxy = obj->getBroadphaseHandle();
- if (proxy)
- {
- m_dynamicsWorld->getPairCache()->cleanProxyFromPairs(proxy,m_dynamicsWorld->getDispatcher());
- }
- }
-}
-
-bool CcdPhysicsEnvironment::IsActiveCcdPhysicsController(CcdPhysicsController *ctrl)
-{
- return (m_controllers.find(ctrl) != m_controllers.end());
-}
-
-void CcdPhysicsEnvironment::AddCcdGraphicController(CcdGraphicController* ctrl)
-{
- if (m_cullingTree && !ctrl->GetBroadphaseHandle())
- {
- btVector3 minAabb;
- btVector3 maxAabb;
- ctrl->GetAabb(minAabb, maxAabb);
-
- ctrl->SetBroadphaseHandle(m_cullingTree->createProxy(
- minAabb,
- maxAabb,
- INVALID_SHAPE_PROXYTYPE, // this parameter is not used
- ctrl,
- 0, // this object does not collision with anything
- 0,
- NULL, // dispatcher => this parameter is not used
- 0));
-
- assert(ctrl->GetBroadphaseHandle());
- }
-}
-
-void CcdPhysicsEnvironment::RemoveCcdGraphicController(CcdGraphicController* ctrl)
-{
- if (m_cullingTree)
- {
- btBroadphaseProxy* bp = ctrl->GetBroadphaseHandle();
- if (bp)
- {
- m_cullingTree->destroyProxy(bp,NULL);
- ctrl->SetBroadphaseHandle(0);
- }
- }
-}
-
-void CcdPhysicsEnvironment::UpdateCcdPhysicsControllerShape(CcdShapeConstructionInfo *shapeInfo)
-{
- for (std::set<CcdPhysicsController *>::iterator it = m_controllers.begin(); it != m_controllers.end(); ++it) {
- CcdPhysicsController *ctrl = *it;
-
- if (ctrl->GetShapeInfo() != shapeInfo)
- continue;
-
- ctrl->ReplaceControllerShape(NULL);
- RefreshCcdPhysicsController(ctrl);
- }
-}
-
-void CcdPhysicsEnvironment::BeginFrame()
-{
-
-}
-
-void CcdPhysicsEnvironment::DebugDrawWorld()
-{
- if (m_dynamicsWorld->getDebugDrawer() && m_dynamicsWorld->getDebugDrawer()->getDebugMode() >0)
- m_dynamicsWorld->debugDrawWorld();
-}
-
-void CcdPhysicsEnvironment::StaticSimulationSubtickCallback(btDynamicsWorld *world, btScalar timeStep)
-{
- // Get the pointer to the CcdPhysicsEnvironment associated with this Bullet world.
- CcdPhysicsEnvironment *this_ = static_cast<CcdPhysicsEnvironment*>(world->getWorldUserInfo());
- this_->SimulationSubtickCallback(timeStep);
-}
-
-void CcdPhysicsEnvironment::SimulationSubtickCallback(btScalar timeStep)
-{
- std::set<CcdPhysicsController*>::iterator it;
-
- for (it = m_controllers.begin(); it != m_controllers.end(); it++) {
- (*it)->SimulationTick(timeStep);
- }
-}
-
-bool CcdPhysicsEnvironment::ProceedDeltaTime(double curTime,float timeStep,float interval)
-{
- std::set<CcdPhysicsController*>::iterator it;
- int i;
-
- // Update Bullet global variables.
- gDeactivationTime = m_deactivationTime;
- gContactBreakingThreshold = m_contactBreakingThreshold;
-
- for (it=m_controllers.begin(); it!=m_controllers.end(); it++)
- {
- (*it)->SynchronizeMotionStates(timeStep);
- }
-
- float subStep = timeStep / float(m_numTimeSubSteps);
- i = m_dynamicsWorld->stepSimulation(interval,25,subStep);//perform always a full simulation step
-//uncomment next line to see where Bullet spend its time (printf in console)
-//CProfileManager::dumpAll();
-
- ProcessFhSprings(curTime,i*subStep);
-
- for (it=m_controllers.begin(); it!=m_controllers.end(); it++)
- {
- (*it)->SynchronizeMotionStates(timeStep);
- }
-
- //for (it=m_controllers.begin(); it!=m_controllers.end(); it++)
- //{
- // (*it)->SynchronizeMotionStates(timeStep);
- //}
-
- for (i=0;i<m_wrapperVehicles.size();i++)
- {
- WrapperVehicle* veh = m_wrapperVehicles[i];
- veh->SyncWheels();
- }
-
-
- CallbackTriggers();
-
- return true;
-}
-
-class ClosestRayResultCallbackNotMe : public btCollisionWorld::ClosestRayResultCallback
-{
- btCollisionObject* m_owner;
- btCollisionObject* m_parent;
-
-public:
- ClosestRayResultCallbackNotMe(const btVector3& rayFromWorld,const btVector3& rayToWorld,btCollisionObject* owner,btCollisionObject* parent)
- :btCollisionWorld::ClosestRayResultCallback(rayFromWorld,rayToWorld),
- m_owner(owner),
- m_parent(parent)
- {
-
- }
-
- virtual bool needsCollision(btBroadphaseProxy* proxy0) const
- {
- //don't collide with self
- if (proxy0->m_clientObject == m_owner)
- return false;
-
- if (proxy0->m_clientObject == m_parent)
- return false;
-
- return btCollisionWorld::ClosestRayResultCallback::needsCollision(proxy0);
- }
-
-};
-
-void CcdPhysicsEnvironment::ProcessFhSprings(double curTime,float interval)
-{
- std::set<CcdPhysicsController*>::iterator it;
- // Add epsilon to the tick rate for numerical stability
- int numIter = (int)(interval*(KX_KetsjiEngine::GetTicRate() + 0.001f));
-
- for (it=m_controllers.begin(); it!=m_controllers.end(); it++)
- {
- CcdPhysicsController* ctrl = (*it);
- btRigidBody* body = ctrl->GetRigidBody();
-
- if (body && (ctrl->GetConstructionInfo().m_do_fh || ctrl->GetConstructionInfo().m_do_rot_fh))
- {
- //printf("has Fh or RotFh\n");
- //re-implement SM_FhObject.cpp using btCollisionWorld::rayTest and info from ctrl->getConstructionInfo()
- //send a ray from {0.0, 0.0, 0.0} towards {0.0, 0.0, -10.0}, in local coordinates
- CcdPhysicsController* parentCtrl = ctrl->GetParentCtrl();
- btRigidBody* parentBody = parentCtrl?parentCtrl->GetRigidBody() : 0;
- btRigidBody* cl_object = parentBody ? parentBody : body;
-
- if (body->isStaticOrKinematicObject())
- continue;
-
- btVector3 rayDirLocal(0,0,-10);
-
- //m_dynamicsWorld
- //ctrl->GetRigidBody();
- btVector3 rayFromWorld = body->getCenterOfMassPosition();
- //btVector3 rayToWorld = rayFromWorld + body->getCenterOfMassTransform().getBasis() * rayDirLocal;
- //ray always points down the z axis in world space...
- btVector3 rayToWorld = rayFromWorld + rayDirLocal;
-
- ClosestRayResultCallbackNotMe resultCallback(rayFromWorld,rayToWorld,body,parentBody);
-
- m_dynamicsWorld->rayTest(rayFromWorld,rayToWorld,resultCallback);
- if (resultCallback.hasHit())
- {
- //we hit this one: resultCallback.m_collisionObject;
- CcdPhysicsController* controller = static_cast<CcdPhysicsController*>(resultCallback.m_collisionObject->getUserPointer());
-
- if (controller)
- {
- if (controller->GetConstructionInfo().m_fh_distance < SIMD_EPSILON)
- continue;
-
- btRigidBody* hit_object = controller->GetRigidBody();
- if (!hit_object)
- continue;
-
- CcdConstructionInfo& hitObjShapeProps = controller->GetConstructionInfo();
-
- float distance = resultCallback.m_closestHitFraction*rayDirLocal.length()-ctrl->GetConstructionInfo().m_radius;
- if (distance >= hitObjShapeProps.m_fh_distance)
- continue;
-
-
-
- //btVector3 ray_dir = cl_object->getCenterOfMassTransform().getBasis()* rayDirLocal.normalized();
- btVector3 ray_dir = rayDirLocal.normalized();
- btVector3 normal = resultCallback.m_hitNormalWorld;
- normal.normalize();
-
- for (int i=0; i<numIter; i++)
- {
- if (ctrl->GetConstructionInfo().m_do_fh)
- {
- btVector3 lspot = cl_object->getCenterOfMassPosition() +
- rayDirLocal * resultCallback.m_closestHitFraction;
-
-
-
-
- lspot -= hit_object->getCenterOfMassPosition();
- btVector3 rel_vel = cl_object->getLinearVelocity() - hit_object->getVelocityInLocalPoint(lspot);
- btScalar rel_vel_ray = ray_dir.dot(rel_vel);
- btScalar spring_extent = 1.0f - distance / hitObjShapeProps.m_fh_distance;
-
- btScalar i_spring = spring_extent * hitObjShapeProps.m_fh_spring;
- btScalar i_damp = rel_vel_ray * hitObjShapeProps.m_fh_damping;
-
- cl_object->setLinearVelocity(cl_object->getLinearVelocity() + (-(i_spring + i_damp) * ray_dir));
- if (hitObjShapeProps.m_fh_normal)
- {
- cl_object->setLinearVelocity(cl_object->getLinearVelocity()+(i_spring + i_damp) *(normal - normal.dot(ray_dir) * ray_dir));
- }
-
- btVector3 lateral = rel_vel - rel_vel_ray * ray_dir;
-
-
- if (ctrl->GetConstructionInfo().m_do_anisotropic) {
- //Bullet basis contains no scaling/shear etc.
- const btMatrix3x3& lcs = cl_object->getCenterOfMassTransform().getBasis();
- btVector3 loc_lateral = lateral * lcs;
- const btVector3& friction_scaling = cl_object->getAnisotropicFriction();
- loc_lateral *= friction_scaling;
- lateral = lcs * loc_lateral;
- }
-
- btScalar rel_vel_lateral = lateral.length();
-
- if (rel_vel_lateral > SIMD_EPSILON) {
- btScalar friction_factor = hit_object->getFriction();//cl_object->getFriction();
-
- btScalar max_friction = friction_factor * btMax(btScalar(0.0f), i_spring);
-
- btScalar rel_mom_lateral = rel_vel_lateral / cl_object->getInvMass();
-
- btVector3 friction = (rel_mom_lateral > max_friction) ?
- -lateral * (max_friction / rel_vel_lateral) :
- -lateral;
-
- cl_object->applyCentralImpulse(friction);
- }
- }
-
-
- if (ctrl->GetConstructionInfo().m_do_rot_fh) {
- btVector3 up2 = cl_object->getWorldTransform().getBasis().getColumn(2);
-
- btVector3 t_spring = up2.cross(normal) * hitObjShapeProps.m_fh_spring;
- btVector3 ang_vel = cl_object->getAngularVelocity();
-
- // only rotations that tilt relative to the normal are damped
- ang_vel -= ang_vel.dot(normal) * normal;
-
- btVector3 t_damp = ang_vel * hitObjShapeProps.m_fh_damping;
-
- cl_object->setAngularVelocity(cl_object->getAngularVelocity() + (t_spring - t_damp));
- }
- }
- }
- }
- }
- }
-}
-
-int CcdPhysicsEnvironment::GetDebugMode() const
-{
- if (m_debugDrawer) {
- return m_debugDrawer->getDebugMode();
- }
- return 0;
-}
-
-void CcdPhysicsEnvironment::SetDebugMode(int debugMode)
-{
- if (m_debugDrawer) {
- m_debugDrawer->setDebugMode(debugMode);
- }
-}
-
-void CcdPhysicsEnvironment::SetNumIterations(int numIter)
-{
- m_numIterations = numIter;
-}
-void CcdPhysicsEnvironment::SetDeactivationTime(float dTime)
-{
- m_deactivationTime = dTime;
-}
-void CcdPhysicsEnvironment::SetDeactivationLinearTreshold(float linTresh)
-{
- m_linearDeactivationThreshold = linTresh;
-
- // Update from all controllers.
- for (std::set<CcdPhysicsController*>::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) {
- if ((*it)->GetRigidBody())
- (*it)->GetRigidBody()->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold);
- }
-}
-void CcdPhysicsEnvironment::SetDeactivationAngularTreshold(float angTresh)
-{
- m_angularDeactivationThreshold = angTresh;
-
- // Update from all controllers.
- for (std::set<CcdPhysicsController*>::iterator it = m_controllers.begin(); it != m_controllers.end(); it++) {
- if ((*it)->GetRigidBody())
- (*it)->GetRigidBody()->setSleepingThresholds(m_linearDeactivationThreshold, m_angularDeactivationThreshold);
- }
-}
-
-void CcdPhysicsEnvironment::SetContactBreakingTreshold(float contactBreakingTreshold)
-{
- m_contactBreakingThreshold = contactBreakingTreshold;
-}
-
-
-void CcdPhysicsEnvironment::SetCcdMode(int ccdMode)
-{
- m_ccdMode = ccdMode;
-}
-
-
-void CcdPhysicsEnvironment::SetSolverSorConstant(float sor)
-{
- m_dynamicsWorld->getSolverInfo().m_sor = sor;
-}
-
-void CcdPhysicsEnvironment::SetSolverTau(float tau)
-{
- m_dynamicsWorld->getSolverInfo().m_tau = tau;
-}
-void CcdPhysicsEnvironment::SetSolverDamping(float damping)
-{
- m_dynamicsWorld->getSolverInfo().m_damping = damping;
-}
-
-
-void CcdPhysicsEnvironment::SetLinearAirDamping(float damping)
-{
- //gLinearAirDamping = damping;
-}
-
-void CcdPhysicsEnvironment::SetUseEpa(bool epa)
-{
- //gUseEpa = epa;
-}
-
-void CcdPhysicsEnvironment::SetSolverType(int solverType)
-{
-
- switch (solverType)
- {
- case 1:
- {
- if (m_solverType != solverType)
- {
-
- m_solver = new btSequentialImpulseConstraintSolver();
-
-
- break;
- }
- }
-
- case 0:
- default:
- if (m_solverType != solverType)
- {
-// m_solver = new OdeConstraintSolver();
-
- break;
- }
-
- };
-
- m_solverType = solverType;
-}
-
-
-
-void CcdPhysicsEnvironment::GetGravity(MT_Vector3& grav)
-{
- const btVector3& gravity = m_dynamicsWorld->getGravity();
- grav[0] = gravity.getX();
- grav[1] = gravity.getY();
- grav[2] = gravity.getZ();
-}
-
-
-void CcdPhysicsEnvironment::SetGravity(float x,float y,float z)
-{
- m_gravity = btVector3(x,y,z);
- m_dynamicsWorld->setGravity(m_gravity);
- m_dynamicsWorld->getWorldInfo().m_gravity.setValue(x,y,z);
-}
-
-
-
-
-static int gConstraintUid = 1;
-
-//Following the COLLADA physics specification for constraints
-int CcdPhysicsEnvironment::CreateUniversalD6Constraint(
- class PHY_IPhysicsController* ctrlRef,class PHY_IPhysicsController* ctrlOther,
- btTransform& frameInA,
- btTransform& frameInB,
- const btVector3& linearMinLimits,
- const btVector3& linearMaxLimits,
- const btVector3& angularMinLimits,
- const btVector3& angularMaxLimits,int flags
-)
-{
-
- bool disableCollisionBetweenLinkedBodies = (0!=(flags & CCD_CONSTRAINT_DISABLE_LINKED_COLLISION));
-
- //we could either add some logic to recognize ball-socket and hinge, or let that up to the user
- //perhaps some warning or hint that hinge/ball-socket is more efficient?
-
-
- btGeneric6DofConstraint* genericConstraint = 0;
- CcdPhysicsController* ctrl0 = (CcdPhysicsController*) ctrlRef;
- CcdPhysicsController* ctrl1 = (CcdPhysicsController*) ctrlOther;
-
- btRigidBody* rb0 = ctrl0->GetRigidBody();
- btRigidBody* rb1 = ctrl1->GetRigidBody();
-
- if (rb1)
- {
-
-
- bool useReferenceFrameA = true;
- genericConstraint = new btGeneric6DofSpringConstraint(
- *rb0,*rb1,
- frameInA,frameInB,useReferenceFrameA);
- genericConstraint->setLinearLowerLimit(linearMinLimits);
- genericConstraint->setLinearUpperLimit(linearMaxLimits);
- genericConstraint->setAngularLowerLimit(angularMinLimits);
- genericConstraint->setAngularUpperLimit(angularMaxLimits);
- } else
- {
- // TODO: Implement single body case...
- //No, we can use a fixed rigidbody in above code, rather than unnecessary duplation of code
-
- }
-
- if (genericConstraint)
- {
- // m_constraints.push_back(genericConstraint);
- m_dynamicsWorld->addConstraint(genericConstraint,disableCollisionBetweenLinkedBodies);
-
- genericConstraint->setUserConstraintId(gConstraintUid++);
- genericConstraint->setUserConstraintType(PHY_GENERIC_6DOF_CONSTRAINT);
- //64 bit systems can't cast pointer to int. could use size_t instead.
- return genericConstraint->getUserConstraintId();
- }
- return 0;
-}
-
-void CcdPhysicsEnvironment::RemoveConstraintById(int constraintId)
-{
- // For soft body constraints
- if (constraintId == 0)
- return;
-
- int i;
- int numConstraints = m_dynamicsWorld->getNumConstraints();
- for (i=0;i<numConstraints;i++)
- {
- btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
- if (constraint->getUserConstraintId() == constraintId)
- {
- RemoveConstraint(constraint);
- break;
- }
- }
-
- WrapperVehicle *vehicle;
- if ((vehicle = (WrapperVehicle*)GetVehicleConstraint(constraintId)))
- {
- m_dynamicsWorld->removeVehicle(vehicle->GetVehicle());
- m_wrapperVehicles.erase(std::remove(m_wrapperVehicles.begin(), m_wrapperVehicles.end(), vehicle));
- delete vehicle;
- }
-}
-
-
-struct FilterClosestRayResultCallback : public btCollisionWorld::ClosestRayResultCallback
-{
- PHY_IRayCastFilterCallback& m_phyRayFilter;
- const btCollisionShape* m_hitTriangleShape;
- int m_hitTriangleIndex;
-
-
- FilterClosestRayResultCallback (PHY_IRayCastFilterCallback& phyRayFilter,const btVector3& rayFrom,const btVector3& rayTo)
- : btCollisionWorld::ClosestRayResultCallback(rayFrom,rayTo),
- m_phyRayFilter(phyRayFilter),
- m_hitTriangleShape(NULL),
- m_hitTriangleIndex(0)
- {
- }
-
- virtual ~FilterClosestRayResultCallback()
- {
- }
-
- virtual bool needsCollision(btBroadphaseProxy* proxy0) const
- {
- if (!(proxy0->m_collisionFilterGroup & m_collisionFilterMask))
- return false;
- if (!(m_collisionFilterGroup & proxy0->m_collisionFilterMask))
- return false;
- btCollisionObject* object = (btCollisionObject*)proxy0->m_clientObject;
- CcdPhysicsController* phyCtrl = static_cast<CcdPhysicsController*>(object->getUserPointer());
- if (phyCtrl == m_phyRayFilter.m_ignoreController)
- return false;
- return m_phyRayFilter.needBroadphaseRayCast(phyCtrl);
- }
-
- virtual btScalar addSingleResult(btCollisionWorld::LocalRayResult& rayResult,bool normalInWorldSpace)
- {
- //CcdPhysicsController* curHit = static_cast<CcdPhysicsController*>(rayResult.m_collisionObject->getUserPointer());
- // save shape information as ClosestRayResultCallback::AddSingleResult() does not do it
- if (rayResult.m_localShapeInfo)
- {
- m_hitTriangleShape = rayResult.m_collisionObject->getCollisionShape();
- m_hitTriangleIndex = rayResult.m_localShapeInfo->m_triangleIndex;
- } else
- {
- m_hitTriangleShape = NULL;
- m_hitTriangleIndex = 0;
- }
- return ClosestRayResultCallback::addSingleResult(rayResult,normalInWorldSpace);
- }
-
-};
-
-static bool GetHitTriangle(btCollisionShape* shape, CcdShapeConstructionInfo* shapeInfo, int hitTriangleIndex, btVector3 triangle[])
-{
- // this code is copied from Bullet
- const unsigned char *vertexbase;
- int numverts;
- PHY_ScalarType type;
- int stride;
- const unsigned char *indexbase;
- int indexstride;
- int numfaces;
- PHY_ScalarType indicestype;
- btStridingMeshInterface* meshInterface = shapeInfo->GetMeshInterface();
-
- if (!meshInterface)
- return false;
-
- meshInterface->getLockedReadOnlyVertexIndexBase(
- &vertexbase,
- numverts,
- type,
- stride,
- &indexbase,
- indexstride,
- numfaces,
- indicestype,
- 0);
-
- unsigned int* gfxbase = (unsigned int*)(indexbase+hitTriangleIndex*indexstride);
- const btVector3& meshScaling = shape->getLocalScaling();
- for (int j=2;j>=0;j--)
- {
- int graphicsindex = (indicestype == PHY_SHORT) ? ((unsigned short *)gfxbase)[j] : gfxbase[j];
-
- btScalar* graphicsbase = (btScalar*)(vertexbase+graphicsindex*stride);
-
- triangle[j] = btVector3(graphicsbase[0]*meshScaling.getX(),graphicsbase[1]*meshScaling.getY(),graphicsbase[2]*meshScaling.getZ());
- }
- meshInterface->unLockReadOnlyVertexBase(0);
- return true;
-}
-
-PHY_IPhysicsController* CcdPhysicsEnvironment::RayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)
-{
- btVector3 rayFrom(fromX,fromY,fromZ);
- btVector3 rayTo(toX,toY,toZ);
-
- btVector3 hitPointWorld,normalWorld;
-
- //Either Ray Cast with or without filtering
-
- //btCollisionWorld::ClosestRayResultCallback rayCallback(rayFrom,rayTo);
- FilterClosestRayResultCallback rayCallback(filterCallback,rayFrom,rayTo);
-
-
- PHY_RayCastResult result;
- memset(&result, 0, sizeof(result));
-
- // don't collision with sensor object
- rayCallback.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
- // use faster (less accurate) ray callback, works better with 0 collision margins
- rayCallback.m_flags |= btTriangleRaycastCallback::kF_UseSubSimplexConvexCastRaytest;
- //, ,filterCallback.m_faceNormal);
-
- m_dynamicsWorld->rayTest(rayFrom,rayTo,rayCallback);
- if (rayCallback.hasHit())
- {
- CcdPhysicsController* controller = static_cast<CcdPhysicsController*>(rayCallback.m_collisionObject->getUserPointer());
- result.m_controller = controller;
- result.m_hitPoint[0] = rayCallback.m_hitPointWorld.getX();
- result.m_hitPoint[1] = rayCallback.m_hitPointWorld.getY();
- result.m_hitPoint[2] = rayCallback.m_hitPointWorld.getZ();
-
- if (rayCallback.m_hitTriangleShape != NULL)
- {
- // identify the mesh polygon
- CcdShapeConstructionInfo* shapeInfo = controller->m_shapeInfo;
- if (shapeInfo)
- {
- btCollisionShape* shape = controller->GetCollisionObject()->getCollisionShape();
- if (shape->isCompound())
- {
- btCompoundShape* compoundShape = (btCompoundShape*)shape;
- CcdShapeConstructionInfo* compoundShapeInfo = shapeInfo;
- // need to search which sub-shape has been hit
- for (int i=0; i<compoundShape->getNumChildShapes(); i++)
- {
- shapeInfo = compoundShapeInfo->GetChildShape(i);
- shape=compoundShape->getChildShape(i);
- if (shape == rayCallback.m_hitTriangleShape)
- break;
- }
- }
- if (shape == rayCallback.m_hitTriangleShape &&
- rayCallback.m_hitTriangleIndex < shapeInfo->m_polygonIndexArray.size())
- {
- // save original collision shape triangle for soft body
- int hitTriangleIndex = rayCallback.m_hitTriangleIndex;
-
- result.m_meshObject = shapeInfo->GetMesh();
- if (shape->isSoftBody())
- {
- // soft body using different face numbering because of randomization
- // hopefully we have stored the original face number in m_tag
- const btSoftBody* softBody = static_cast<const btSoftBody*>(rayCallback.m_collisionObject);
- if (softBody->m_faces[hitTriangleIndex].m_tag != 0)
- {
- rayCallback.m_hitTriangleIndex = (int)((uintptr_t)(softBody->m_faces[hitTriangleIndex].m_tag)-1);
- }
- }
- // retrieve the original mesh polygon (in case of quad->tri conversion)
- result.m_polygon = shapeInfo->m_polygonIndexArray.at(rayCallback.m_hitTriangleIndex);
- // hit triangle in world coordinate, for face normal and UV coordinate
- btVector3 triangle[3];
- bool triangleOK = false;
- if (filterCallback.m_faceUV && (3*rayCallback.m_hitTriangleIndex) < shapeInfo->m_triFaceUVcoArray.size())
- {
- // interpolate the UV coordinate of the hit point
- CcdShapeConstructionInfo::UVco* uvCo = &shapeInfo->m_triFaceUVcoArray[3*rayCallback.m_hitTriangleIndex];
- // 1. get the 3 coordinate of the triangle in world space
- btVector3 v1, v2, v3;
- if (shape->isSoftBody())
- {
- // soft body give points directly in world coordinate
- const btSoftBody* softBody = static_cast<const btSoftBody*>(rayCallback.m_collisionObject);
- v1 = softBody->m_faces[hitTriangleIndex].m_n[0]->m_x;
- v2 = softBody->m_faces[hitTriangleIndex].m_n[1]->m_x;
- v3 = softBody->m_faces[hitTriangleIndex].m_n[2]->m_x;
- } else
- {
- // for rigid body we must apply the world transform
- triangleOK = GetHitTriangle(shape, shapeInfo, hitTriangleIndex, triangle);
- if (!triangleOK)
- // if we cannot get the triangle, no use to continue
- goto SKIP_UV_NORMAL;
- v1 = rayCallback.m_collisionObject->getWorldTransform()(triangle[0]);
- v2 = rayCallback.m_collisionObject->getWorldTransform()(triangle[1]);
- v3 = rayCallback.m_collisionObject->getWorldTransform()(triangle[2]);
- }
- // 2. compute barycentric coordinate of the hit point
- btVector3 v = v2-v1;
- btVector3 w = v3-v1;
- btVector3 u = v.cross(w);
- btScalar A = u.length();
-
- v = v2-rayCallback.m_hitPointWorld;
- w = v3-rayCallback.m_hitPointWorld;
- u = v.cross(w);
- btScalar A1 = u.length();
-
- v = rayCallback.m_hitPointWorld-v1;
- w = v3-v1;
- u = v.cross(w);
- btScalar A2 = u.length();
-
- btVector3 baryCo;
- baryCo.setX(A1/A);
- baryCo.setY(A2/A);
- baryCo.setZ(1.0f-baryCo.getX()-baryCo.getY());
- // 3. compute UV coordinate
- result.m_hitUV[0] = baryCo.getX()*uvCo[0].uv[0] + baryCo.getY()*uvCo[1].uv[0] + baryCo.getZ()*uvCo[2].uv[0];
- result.m_hitUV[1] = baryCo.getX()*uvCo[0].uv[1] + baryCo.getY()*uvCo[1].uv[1] + baryCo.getZ()*uvCo[2].uv[1];
- result.m_hitUVOK = 1;
- }
-
- // Bullet returns the normal from "outside".
- // If the user requests the real normal, compute it now
- if (filterCallback.m_faceNormal)
- {
- if (shape->isSoftBody())
- {
- // we can get the real normal directly from the body
- const btSoftBody* softBody = static_cast<const btSoftBody*>(rayCallback.m_collisionObject);
- rayCallback.m_hitNormalWorld = softBody->m_faces[hitTriangleIndex].m_normal;
- } else
- {
- if (!triangleOK)
- triangleOK = GetHitTriangle(shape, shapeInfo, hitTriangleIndex, triangle);
- if (triangleOK)
- {
- btVector3 triangleNormal;
- triangleNormal = (triangle[1]-triangle[0]).cross(triangle[2]-triangle[0]);
- rayCallback.m_hitNormalWorld = rayCallback.m_collisionObject->getWorldTransform().getBasis()*triangleNormal;
- }
- }
- }
- SKIP_UV_NORMAL:
- ;
- }
- }
- }
- if (rayCallback.m_hitNormalWorld.length2() > (SIMD_EPSILON*SIMD_EPSILON))
- {
- rayCallback.m_hitNormalWorld.normalize();
- } else
- {
- rayCallback.m_hitNormalWorld.setValue(1,0,0);
- }
- result.m_hitNormal[0] = rayCallback.m_hitNormalWorld.getX();
- result.m_hitNormal[1] = rayCallback.m_hitNormalWorld.getY();
- result.m_hitNormal[2] = rayCallback.m_hitNormalWorld.getZ();
- filterCallback.reportHit(&result);
- }
-
-
- return result.m_controller;
-}
-
-// Handles occlusion culling.
-// The implementation is based on the CDTestFramework
-struct OcclusionBuffer
-{
- struct WriteOCL
- {
- static inline bool Process(btScalar &q, btScalar v)
- {
- if (q < v) {
- q = v;
- }
- return false;
- }
- static inline void Occlusion(bool &flag)
- {
- flag = true;
- }
- };
-
- struct QueryOCL
- {
- static inline bool Process(btScalar &q, btScalar v)
- {
- return (q <= v);
- }
- static inline void Occlusion(bool &flag)
- {
- }
- };
-
- btScalar *m_buffer;
- size_t m_bufferSize;
- bool m_initialized;
- bool m_occlusion;
- int m_sizes[2];
- btScalar m_scales[2];
- btScalar m_offsets[2];
- btScalar m_wtc[16]; // world to clip transform
- btScalar m_mtc[16]; // model to clip transform
- // constructor: size=largest dimension of the buffer.
- // Buffer size depends on aspect ratio
- OcclusionBuffer()
- {
- m_initialized = false;
- m_occlusion = false;
- m_buffer = NULL;
- m_bufferSize = 0;
- }
- // multiplication of column major matrices: m = m1 * m2
- template<typename T1, typename T2>
- void CMmat4mul(btScalar *m, const T1 *m1, const T2 *m2)
- {
- m[0] = btScalar(m1[0] * m2[0] + m1[4] * m2[1] + m1[8] * m2[2] + m1[12] * m2[3]);
- m[1] = btScalar(m1[1] * m2[0] + m1[5] * m2[1] + m1[9] * m2[2] + m1[13] * m2[3]);
- m[2] = btScalar(m1[2] * m2[0] + m1[6] * m2[1] + m1[10] * m2[2] + m1[14] * m2[3]);
- m[3] = btScalar(m1[3] * m2[0] + m1[7] * m2[1] + m1[11] * m2[2] + m1[15] * m2[3]);
-
- m[4] = btScalar(m1[0] * m2[4] + m1[4] * m2[5] + m1[8] * m2[6] + m1[12] * m2[7]);
- m[5] = btScalar(m1[1] * m2[4] + m1[5] * m2[5] + m1[9] * m2[6] + m1[13] * m2[7]);
- m[6] = btScalar(m1[2] * m2[4] + m1[6] * m2[5] + m1[10] * m2[6] + m1[14] * m2[7]);
- m[7] = btScalar(m1[3] * m2[4] + m1[7] * m2[5] + m1[11] * m2[6] + m1[15] * m2[7]);
-
- m[8] = btScalar(m1[0] * m2[8] + m1[4] * m2[9] + m1[8] * m2[10] + m1[12] * m2[11]);
- m[9] = btScalar(m1[1] * m2[8] + m1[5] * m2[9] + m1[9] * m2[10] + m1[13] * m2[11]);
- m[10] = btScalar(m1[2] * m2[8] + m1[6] * m2[9] + m1[10] * m2[10] + m1[14] * m2[11]);
- m[11] = btScalar(m1[3] * m2[8] + m1[7] * m2[9] + m1[11] * m2[10] + m1[15] * m2[11]);
-
- m[12] = btScalar(m1[0] * m2[12] + m1[4] * m2[13] + m1[8] * m2[14] + m1[12] * m2[15]);
- m[13] = btScalar(m1[1] * m2[12] + m1[5] * m2[13] + m1[9] * m2[14] + m1[13] * m2[15]);
- m[14] = btScalar(m1[2] * m2[12] + m1[6] * m2[13] + m1[10] * m2[14] + m1[14] * m2[15]);
- m[15] = btScalar(m1[3] * m2[12] + m1[7] * m2[13] + m1[11] * m2[14] + m1[15] * m2[15]);
- }
-
- void setup(int size, const int *view, float modelview[16], float projection[16])
- {
- m_initialized = false;
- m_occlusion = false;
- // compute the size of the buffer
- int maxsize = (view[2] > view[3]) ? view[2] : view[3];
- assert(maxsize > 0);
- double ratio = 1.0 / (2 * maxsize);
- // ensure even number
- m_sizes[0] = 2 * ((int)(size * view[2] * ratio + 0.5));
- m_sizes[1] = 2 * ((int)(size * view[3] * ratio + 0.5));
- m_scales[0] = btScalar(m_sizes[0] / 2);
- m_scales[1] = btScalar(m_sizes[1] / 2);
- m_offsets[0] = m_scales[0] + 0.5f;
- m_offsets[1] = m_scales[1] + 0.5f;
- // prepare matrix
- // at this time of the rendering, the modelview matrix is the
- // world to camera transformation and the projection matrix is
- // camera to clip transformation. combine both so that
- CMmat4mul(m_wtc, projection, modelview);
- }
-
- void initialize()
- {
- size_t newsize = (m_sizes[0] * m_sizes[1]) * sizeof(btScalar);
- if (m_buffer) {
- // see if we can reuse
- if (newsize > m_bufferSize) {
- free(m_buffer);
- m_buffer = NULL;
- m_bufferSize = 0;
- }
- }
- if (!m_buffer) {
- m_buffer = (btScalar *)calloc(1, newsize);
- m_bufferSize = newsize;
- }
- else {
- // buffer exists already, just clears it
- memset(m_buffer, 0, newsize);
- }
- // memory allocate must succeed
- assert(m_buffer != NULL);
- m_initialized = true;
- m_occlusion = false;
- }
-
- void SetModelMatrix(float *fl)
- {
- CMmat4mul(m_mtc,m_wtc,fl);
- if (!m_initialized) {
- initialize();
- }
- }
-
- // transform a segment in world coordinate to clip coordinate
- void transformW(const btVector3 &x, btVector4 &t)
- {
- t[0] = x[0] * m_wtc[0] + x[1] * m_wtc[4] + x[2] * m_wtc[8] + m_wtc[12];
- t[1] = x[0] * m_wtc[1] + x[1] * m_wtc[5] + x[2] * m_wtc[9] + m_wtc[13];
- t[2] = x[0] * m_wtc[2] + x[1] * m_wtc[6] + x[2] * m_wtc[10] + m_wtc[14];
- t[3] = x[0] * m_wtc[3] + x[1] * m_wtc[7] + x[2] * m_wtc[11] + m_wtc[15];
- }
-
- void transformM(const float *x, btVector4 &t)
- {
- t[0] = x[0] * m_mtc[0] + x[1] * m_mtc[4] + x[2] * m_mtc[8] + m_mtc[12];
- t[1] = x[0] * m_mtc[1] + x[1] * m_mtc[5] + x[2] * m_mtc[9] + m_mtc[13];
- t[2] = x[0] * m_mtc[2] + x[1] * m_mtc[6] + x[2] * m_mtc[10] + m_mtc[14];
- t[3] = x[0] * m_mtc[3] + x[1] * m_mtc[7] + x[2] * m_mtc[11] + m_mtc[15];
- }
- // convert polygon to device coordinates
- static bool project(btVector4 *p, int n)
- {
- for (int i = 0; i < n; ++i) {
- p[i][2] = 1 / p[i][3];
- p[i][0] *= p[i][2];
- p[i][1] *= p[i][2];
- }
- return true;
- }
- // pi: closed polygon in clip coordinate, NP = number of segments
- // po: same polygon with clipped segments removed
- template <const int NP>
- static int clip(const btVector4 *pi, btVector4 *po)
- {
- btScalar s[2 * NP];
- btVector4 pn[2 * NP];
- int i, j, m, n, ni;
- // deal with near clipping
- for (i = 0, m = 0; i < NP; ++i) {
- s[i] = pi[i][2] + pi[i][3];
- if (s[i] < 0) {
- m += 1 << i;
- }
- }
- if (m == ((1 << NP) - 1)) {
- return 0;
- }
- if (m != 0) {
- for (i = NP - 1, j = 0, n = 0; j < NP; i = j++) {
- const btVector4 &a = pi[i];
- const btVector4 &b = pi[j];
- const btScalar t = s[i] / (a[3] + a[2] - b[3] - b[2]);
- if ((t > 0) && (t < 1)) {
- pn[n][0] = a[0] + (b[0] - a[0]) * t;
- pn[n][1] = a[1] + (b[1] - a[1]) * t;
- pn[n][2] = a[2] + (b[2] - a[2]) * t;
- pn[n][3] = a[3] + (b[3] - a[3]) * t;
- ++n;
- }
- if (s[j] > 0) {
- pn[n++] = b;
- }
- }
- // ready to test far clipping, start from the modified polygon
- pi = pn;
- ni = n;
- }
- else {
- // no clipping on the near plane, keep same vector
- ni = NP;
- }
- // now deal with far clipping
- for (i = 0, m = 0; i < ni; ++i) {
- s[i] = pi[i][2] - pi[i][3];
- if (s[i] > 0) {
- m += 1 << i;
- }
- }
- if (m == ((1 << ni) - 1)) {
- return 0;
- }
- if (m != 0) {
- for (i = ni - 1, j = 0, n = 0;j < ni; i = j++) {
- const btVector4 &a = pi[i];
- const btVector4 &b = pi[j];
- const btScalar t = s[i] / (a[2] - a[3] - b[2] + b[3]);
- if ((t > 0) && (t < 1)) {
- po[n][0] = a[0] + (b[0] - a[0]) * t;
- po[n][1] = a[1] + (b[1] - a[1]) * t;
- po[n][2] = a[2] + (b[2] - a[2]) * t;
- po[n][3] = a[3] + (b[3] - a[3]) * t;
- ++n;
- }
- if (s[j] < 0) {
- po[n++] = b;
- }
- }
- return n;
- }
- for (int i = 0; i < ni; ++i) {
- po[i] = pi[i];
- }
- return ni;
- }
- // write or check a triangle to buffer. a,b,c in device coordinates (-1,+1)
- template <typename POLICY>
- inline bool draw(const btVector4 &a,
- const btVector4 &b,
- const btVector4 &c,
- const float face,
- const btScalar minarea)
- {
- const btScalar a2 = btCross(b - a, c - a)[2];
- if ((face * a2) < 0.0f || btFabs(a2) < minarea) {
- return false;
- }
- // further down we are normally going to write to the Zbuffer, mark it so
- POLICY::Occlusion(m_occlusion);
-
- int x[3], y[3], ib = 1, ic = 2;
- btScalar z[3];
- x[0] = (int)(a.x() * m_scales[0] + m_offsets[0]);
- y[0] = (int)(a.y() * m_scales[1] + m_offsets[1]);
- z[0] = a.z();
- if (a2 < 0.f) {
- // negative aire is possible with double face => must
- // change the order of b and c otherwise the algorithm doesn't work
- ib = 2;
- ic = 1;
- }
- x[ib] = (int)(b.x() * m_scales[0] + m_offsets[0]);
- x[ic] = (int)(c.x() * m_scales[0] + m_offsets[0]);
- y[ib] = (int)(b.y() * m_scales[1] + m_offsets[1]);
- y[ic] = (int)(c.y() * m_scales[1] + m_offsets[1]);
- z[ib] = b.z();
- z[ic] = c.z();
- const int mix = btMax(0, btMin(x[0], btMin(x[1], x[2])));
- const int mxx = btMin(m_sizes[0], 1 + btMax(x[0], btMax(x[1], x[2])));
- const int miy = btMax(0, btMin(y[0], btMin(y[1], y[2])));
- const int mxy = btMin(m_sizes[1], 1 + btMax(y[0], btMax(y[1], y[2])));
- const int width = mxx - mix;
- const int height = mxy - miy;
- if ((width * height) <= 1) {
- // degenerated in at most one single pixel
- btScalar *scan = &m_buffer[miy * m_sizes[0] + mix];
- // use for loop to detect the case where width or height == 0
- for (int iy = miy; iy < mxy; ++iy) {
- for (int ix = mix; ix < mxx; ++ix) {
- if (POLICY::Process(*scan, z[0])) {
- return true;
- }
- if (POLICY::Process(*scan, z[1])) {
- return true;
- }
- if (POLICY::Process(*scan, z[2])) {
- return true;
- }
- }
- }
- }
- else if (width == 1) {
- // Degenerated in at least 2 vertical lines
- // The algorithm below doesn't work when face has a single pixel width
- // We cannot use general formulas because the plane is degenerated.
- // We have to interpolate along the 3 edges that overlaps and process each pixel.
- // sort the y coord to make formula simpler
- int ytmp;
- btScalar ztmp;
- if (y[0] > y[1]) {
- ytmp = y[1];
- y[1] = y[0];
- y[0] = ytmp;
- ztmp = z[1];
- z[1] = z[0];
- z[0] = ztmp;
- }
- if (y[0] > y[2]) {
- ytmp = y[2];
- y[2] = y[0];
- y[0] = ytmp;
- ztmp = z[2];
- z[2] = z[0];
- z[0] = ztmp;
- }
- if (y[1] > y[2]) {
- ytmp = y[2];
- y[2] = y[1];
- y[1] = ytmp;
- ztmp = z[2];
- z[2] = z[1];
- z[1] = ztmp;
- }
- int dy[] = {y[0] - y[1],
- y[1] - y[2],
- y[2] - y[0]};
- btScalar dzy[3];
- dzy[0] = (dy[0]) ? (z[0] - z[1]) / dy[0] : btScalar(0.0f);
- dzy[1] = (dy[1]) ? (z[1] - z[2]) / dy[1] : btScalar(0.0f);
- dzy[2] = (dy[2]) ? (z[2] - z[0]) / dy[2] : btScalar(0.0f);
- btScalar v[3] = {dzy[0] * (miy - y[0]) + z[0],
- dzy[1] * (miy - y[1]) + z[1],
- dzy[2] * (miy - y[2]) + z[2]};
- dy[0] = y[1] - y[0];
- dy[1] = y[0] - y[1];
- dy[2] = y[2] - y[0];
- btScalar *scan = &m_buffer[miy * m_sizes[0] + mix];
- for (int iy = miy; iy < mxy; ++iy) {
- if (dy[0] >= 0 && POLICY::Process(*scan, v[0])) {
- return true;
- }
- if (dy[1] >= 0 && POLICY::Process(*scan, v[1])) {
- return true;
- }
- if (dy[2] >= 0 && POLICY::Process(*scan, v[2])) {
- return true;
- }
- scan += m_sizes[0];
- v[0] += dzy[0];
- v[1] += dzy[1];
- v[2] += dzy[2];
- dy[0]--;
- dy[1]++;
- dy[2]--;
- }
- }
- else if (height == 1) {
- // Degenerated in at least 2 horizontal lines
- // The algorithm below doesn't work when face has a single pixel width
- // We cannot use general formulas because the plane is degenerated.
- // We have to interpolate along the 3 edges that overlaps and process each pixel.
- int xtmp;
- btScalar ztmp;
- if (x[0] > x[1]) {
- xtmp = x[1];
- x[1] = x[0];
- x[0] = xtmp;
- ztmp = z[1];
- z[1] = z[0];
- z[0] = ztmp;
- }
- if (x[0] > x[2]) {
- xtmp = x[2];
- x[2] = x[0];
- x[0] = xtmp;
- ztmp = z[2];
- z[2] = z[0];
- z[0] = ztmp;
- }
- if (x[1] > x[2]) {
- xtmp = x[2];
- x[2] = x[1];
- x[1] = xtmp;
- ztmp = z[2];
- z[2] = z[1];
- z[1] = ztmp;
- }
- int dx[] = {x[0] - x[1],
- x[1] - x[2],
- x[2] - x[0]};
- btScalar dzx[3];
- dzx[0] = (dx[0]) ? (z[0]-z[1]) / dx[0] : btScalar(0.0f);
- dzx[1] = (dx[1]) ? (z[1]-z[2]) / dx[1] : btScalar(0.0f);
- dzx[2] = (dx[2]) ? (z[2]-z[0]) / dx[2] : btScalar(0.0f);
- btScalar v[3] = {dzx[0] * (mix - x[0]) + z[0],
- dzx[1] * (mix - x[1]) + z[1],
- dzx[2] * (mix - x[2]) + z[2]};
- dx[0] = x[1] - x[0];
- dx[1] = x[0] - x[1];
- dx[2] = x[2] - x[0];
- btScalar *scan = &m_buffer[miy * m_sizes[0] + mix];
- for (int ix = mix; ix < mxx; ++ix) {
- if (dx[0] >= 0 && POLICY::Process(*scan, v[0])) {
- return true;
- }
- if (dx[1] >= 0 && POLICY::Process(*scan, v[1])) {
- return true;
- }
- if (dx[2] >= 0 && POLICY::Process(*scan, v[2])) {
- return true;
- }
- scan++;
- v[0] += dzx[0];
- v[1] += dzx[1];
- v[2] += dzx[2];
- dx[0]--;
- dx[1]++;
- dx[2]--;
- }
- }
- else {
- // general case
- const int dx[] = {y[0] - y[1],
- y[1] - y[2],
- y[2] - y[0]};
- const int dy[] = {x[1] - x[0] - dx[0] * width,
- x[2] - x[1] - dx[1] * width,
- x[0] - x[2] - dx[2] * width};
- const int a = x[2] * y[0] + x[0] * y[1] - x[2] * y[1] - x[0] * y[2] + x[1] * y[2] - x[1] * y[0];
- const btScalar ia = 1 / (btScalar)a;
- const btScalar dzx = ia * (y[2] * (z[1] - z[0]) + y[1] * (z[0] - z[2]) + y[0] * (z[2] - z[1]));
- const btScalar dzy = ia * (x[2] * (z[0] - z[1]) + x[0] * (z[1] - z[2]) + x[1] * (z[2] - z[0])) - (dzx * width);
- int c[] = {miy * x[1] + mix * y[0] - x[1] * y[0] - mix * y[1] + x[0] * y[1] - miy * x[0],
- miy * x[2] + mix * y[1] - x[2] * y[1] - mix * y[2] + x[1] * y[2] - miy * x[1],
- miy * x[0] + mix * y[2] - x[0] * y[2] - mix * y[0] + x[2] * y[0] - miy * x[2]};
- btScalar v = ia * ((z[2] * c[0]) + (z[0] * c[1]) + (z[1] * c[2]));
- btScalar *scan = &m_buffer[miy * m_sizes[0]];
-
- for (int iy = miy; iy < mxy; ++iy) {
- for (int ix = mix; ix < mxx; ++ix) {
- if ((c[0] >= 0) && (c[1] >= 0) && (c[2] >= 0)) {
- if (POLICY::Process(scan[ix], v)) {
- return true;
- }
- }
- c[0] += dx[0]; c[1] += dx[1]; c[2] += dx[2]; v += dzx;
- }
- c[0] += dy[0]; c[1] += dy[1]; c[2] += dy[2]; v += dzy;
- scan += m_sizes[0];
- }
- }
- return false;
- }
- // clip than write or check a polygon
- template <const int NP, typename POLICY>
- inline bool clipDraw(const btVector4 *p,
- const float face,
- btScalar minarea)
- {
- btVector4 o[NP * 2];
- int n = clip<NP>(p, o);
- bool earlyexit = false;
- if (n) {
- project(o, n);
- for (int i = 2; i < n && !earlyexit; ++i) {
- earlyexit |= draw<POLICY>(o[0], o[i - 1], o[i], face, minarea);
- }
- }
- return earlyexit;
- }
- // add a triangle (in model coordinate)
- // face = 0.f if face is double side,
- // = 1.f if face is single sided and scale is positive
- // = -1.f if face is single sided and scale is negative
- void appendOccluderM(const float *a,
- const float *b,
- const float *c,
- const float face)
- {
- btVector4 p[3];
- transformM(a, p[0]);
- transformM(b, p[1]);
- transformM(c, p[2]);
- clipDraw<3, WriteOCL>(p, face, btScalar(0.0f));
- }
- // add a quad (in model coordinate)
- void appendOccluderM(const float *a,
- const float *b,
- const float *c,
- const float *d,
- const float face)
- {
- btVector4 p[4];
- transformM(a, p[0]);
- transformM(b, p[1]);
- transformM(c, p[2]);
- transformM(d, p[3]);
- clipDraw<4, WriteOCL>(p, face, btScalar(0.0f));
- }
- // query occluder for a box (c=center, e=extend) in world coordinate
- inline bool queryOccluderW(const btVector3 &c,
- const btVector3 &e)
- {
- if (!m_occlusion) {
- // no occlusion yet, no need to check
- return true;
- }
- btVector4 x[8];
- transformW(btVector3(c[0] - e[0], c[1] - e[1], c[2] - e[2]), x[0]);
- transformW(btVector3(c[0] + e[0], c[1] - e[1], c[2] - e[2]), x[1]);
- transformW(btVector3(c[0] + e[0], c[1] + e[1], c[2] - e[2]), x[2]);
- transformW(btVector3(c[0] - e[0], c[1] + e[1], c[2] - e[2]), x[3]);
- transformW(btVector3(c[0] - e[0], c[1] - e[1], c[2] + e[2]), x[4]);
- transformW(btVector3(c[0] + e[0], c[1] - e[1], c[2] + e[2]), x[5]);
- transformW(btVector3(c[0] + e[0], c[1] + e[1], c[2] + e[2]), x[6]);
- transformW(btVector3(c[0] - e[0], c[1] + e[1], c[2] + e[2]), x[7]);
-
- for (int i = 0; i < 8; ++i) {
- // the box is clipped, it's probably a large box, don't waste our time to check
- if ((x[i][2] + x[i][3]) <= 0) {
- return true;
- }
- }
- static const int d[] = {1, 0, 3, 2,
- 4, 5, 6, 7,
- 4, 7, 3, 0,
- 6, 5, 1, 2,
- 7, 6, 2, 3,
- 5, 4, 0, 1};
- for (unsigned int i = 0; i < (sizeof(d) / sizeof(d[0]));) {
- const btVector4 p[] = {x[d[i + 0]],
- x[d[i + 1]],
- x[d[i + 2]],
- x[d[i + 3]]};
- i += 4;
- if (clipDraw<4, QueryOCL>(p, 1.0f, 0.0f)) {
- return true;
- }
- }
- return false;
- }
-};
-
-
-struct DbvtCullingCallback : btDbvt::ICollide
-{
- PHY_CullingCallback m_clientCallback;
- void* m_userData;
- OcclusionBuffer *m_ocb;
-
- DbvtCullingCallback(PHY_CullingCallback clientCallback, void* userData)
- {
- m_clientCallback = clientCallback;
- m_userData = userData;
- m_ocb = NULL;
- }
- bool Descent(const btDbvtNode* node)
- {
- return(m_ocb->queryOccluderW(node->volume.Center(),node->volume.Extents()));
- }
- void Process(const btDbvtNode* node,btScalar depth)
- {
- Process(node);
- }
- void Process(const btDbvtNode* leaf)
- {
- btBroadphaseProxy* proxy=(btBroadphaseProxy*)leaf->data;
- // the client object is a graphic controller
- CcdGraphicController* ctrl = static_cast<CcdGraphicController*>(proxy->m_clientObject);
- KX_ClientObjectInfo *info = (KX_ClientObjectInfo*)ctrl->GetNewClientInfo();
- if (m_ocb)
- {
- // means we are doing occlusion culling. Check if this object is an occluders
- KX_GameObject* gameobj = KX_GameObject::GetClientObject(info);
- if (gameobj && gameobj->GetOccluder())
- {
- float *fl = gameobj->GetOpenGLMatrixPtr()->getPointer();
- // this will create the occlusion buffer if not already done
- // and compute the transformation from model local space to clip space
- m_ocb->SetModelMatrix(fl);
- float face = (gameobj->IsNegativeScaling()) ? -1.0f : 1.0f;
- // walk through the meshes and for each add to buffer
- for (int i=0; i<gameobj->GetMeshCount(); i++)
- {
- RAS_MeshObject* meshobj = gameobj->GetMesh(i);
- const float *v1, *v2, *v3, *v4;
-
- int polycount = meshobj->NumPolygons();
- for (int j=0; j<polycount; j++)
- {
- RAS_Polygon* poly = meshobj->GetPolygon(j);
- switch (poly->VertexCount())
- {
- case 3:
- v1 = poly->GetVertex(0)->getXYZ();
- v2 = poly->GetVertex(1)->getXYZ();
- v3 = poly->GetVertex(2)->getXYZ();
- m_ocb->appendOccluderM(v1,v2,v3,((poly->IsTwoside())?0.f:face));
- break;
- case 4:
- v1 = poly->GetVertex(0)->getXYZ();
- v2 = poly->GetVertex(1)->getXYZ();
- v3 = poly->GetVertex(2)->getXYZ();
- v4 = poly->GetVertex(3)->getXYZ();
- m_ocb->appendOccluderM(v1,v2,v3,v4,((poly->IsTwoside())?0.f:face));
- break;
- }
- }
- }
- }
- }
- if (info)
- (*m_clientCallback)(info, m_userData);
- }
-};
-
-static OcclusionBuffer gOcb;
-bool CcdPhysicsEnvironment::CullingTest(PHY_CullingCallback callback, void* userData, MT_Vector4 *planes, int nplanes, int occlusionRes, const int *viewport, float modelview[16], float projection[16])
-{
- if (!m_cullingTree)
- return false;
- DbvtCullingCallback dispatcher(callback, userData);
- btVector3 planes_n[6];
- btScalar planes_o[6];
- if (nplanes > 6)
- nplanes = 6;
- for (int i=0; i<nplanes; i++)
- {
- planes_n[i].setValue(planes[i][0], planes[i][1], planes[i][2]);
- planes_o[i] = planes[i][3];
- }
- // if occlusionRes != 0 => occlusion culling
- if (occlusionRes)
- {
- gOcb.setup(occlusionRes, viewport, modelview, projection);
- dispatcher.m_ocb = &gOcb;
- // occlusion culling, the direction of the view is taken from the first plan which MUST be the near plane
- btDbvt::collideOCL(m_cullingTree->m_sets[1].m_root,planes_n,planes_o,planes_n[0],nplanes,dispatcher);
- btDbvt::collideOCL(m_cullingTree->m_sets[0].m_root,planes_n,planes_o,planes_n[0],nplanes,dispatcher);
- }
- else {
- btDbvt::collideKDOP(m_cullingTree->m_sets[1].m_root,planes_n,planes_o,nplanes,dispatcher);
- btDbvt::collideKDOP(m_cullingTree->m_sets[0].m_root,planes_n,planes_o,nplanes,dispatcher);
- }
- return true;
-}
-
-int CcdPhysicsEnvironment::GetNumContactPoints()
-{
- return 0;
-}
-
-void CcdPhysicsEnvironment::GetContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ)
-{
-
-}
-
-
-
-
-btBroadphaseInterface* CcdPhysicsEnvironment::GetBroadphase()
-{
- return m_dynamicsWorld->getBroadphase();
-}
-
-btDispatcher* CcdPhysicsEnvironment::GetDispatcher()
-{
- return m_dynamicsWorld->getDispatcher();
-}
-
-void CcdPhysicsEnvironment::MergeEnvironment(PHY_IPhysicsEnvironment *other_env)
-{
- CcdPhysicsEnvironment *other = dynamic_cast<CcdPhysicsEnvironment*>(other_env);
- if (other == NULL) {
- printf("KX_Scene::MergeScene: Other scene is not using Bullet physics, not merging physics.\n");
- return;
- }
-
- std::set<CcdPhysicsController*>::iterator it;
-
- while (other->m_controllers.begin() != other->m_controllers.end())
- {
- it= other->m_controllers.begin();
- CcdPhysicsController* ctrl= (*it);
-
- other->RemoveCcdPhysicsController(ctrl);
- this->AddCcdPhysicsController(ctrl);
- }
-}
-
-CcdPhysicsEnvironment::~CcdPhysicsEnvironment()
-{
-
-#ifdef NEW_BULLET_VEHICLE_SUPPORT
- m_wrapperVehicles.clear();
-#endif //NEW_BULLET_VEHICLE_SUPPORT
-
- //m_broadphase->DestroyScene();
- //delete broadphase ? release reference on broadphase ?
-
- //first delete scene, then dispatcher, because pairs have to release manifolds on the dispatcher
- //delete m_dispatcher;
- delete m_dynamicsWorld;
-
-
- if (NULL != m_ownPairCache)
- delete m_ownPairCache;
-
- if (NULL != m_ownDispatcher)
- delete m_ownDispatcher;
-
- if (NULL != m_solver)
- delete m_solver;
-
- if (NULL != m_debugDrawer)
- delete m_debugDrawer;
-
- if (NULL != m_filterCallback)
- delete m_filterCallback;
-
- if (NULL != m_ghostPairCallback)
- delete m_ghostPairCallback;
-
- if (NULL != m_collisionConfiguration)
- delete m_collisionConfiguration;
-
- if (NULL != m_broadphase)
- delete m_broadphase;
-
- if (NULL != m_cullingTree)
- delete m_cullingTree;
-
- if (NULL != m_cullingCache)
- delete m_cullingCache;
-
-}
-
-
-float CcdPhysicsEnvironment::GetConstraintParam(int constraintId,int param)
-{
- btTypedConstraint* typedConstraint = GetConstraintById(constraintId);
- if (!typedConstraint)
- return 0.0f;
-
- switch (typedConstraint->getUserConstraintType())
- {
- case PHY_GENERIC_6DOF_CONSTRAINT:
- {
-
- switch (param)
- {
- case 0: case 1: case 2:
- {
- //param = 0..2 are linear constraint values
- btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
- genCons->calculateTransforms();
- return genCons->getRelativePivotPosition(param);
- break;
- }
- case 3: case 4: case 5:
- {
- //param = 3..5 are relative constraint (Euler) angles
- btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
- genCons->calculateTransforms();
- return genCons->getAngle(param-3);
- break;
- }
- default:
- {
- }
- }
- break;
- };
- default:
- {
- };
- };
- return 0.f;
-}
-
-void CcdPhysicsEnvironment::SetConstraintParam(int constraintId,int param,float value0,float value1)
-{
- btTypedConstraint* typedConstraint = GetConstraintById(constraintId);
- if (!typedConstraint)
- return;
-
- switch (typedConstraint->getUserConstraintType())
- {
- case PHY_GENERIC_6DOF_CONSTRAINT:
- {
-
- switch (param)
- {
- case 0: case 1: case 2: case 3: case 4: case 5:
- {
- //param = 0..5 are constraint limits, with low/high limit value
- btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
- genCons->setLimit(param,value0,value1);
- break;
- }
- case 6: case 7: case 8:
- {
- //param = 6,7,8 are translational motors, with value0=target velocity, value1 = max motor force
- btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
- int transMotorIndex = param-6;
- btTranslationalLimitMotor* transMotor = genCons->getTranslationalLimitMotor();
- transMotor->m_targetVelocity[transMotorIndex] = value0;
- transMotor->m_maxMotorForce[transMotorIndex] = value1;
- transMotor->m_enableMotor[transMotorIndex] = (value1>0.f);
- break;
- }
- case 9: case 10: case 11:
- {
- //param = 9,10,11 are rotational motors, with value0=target velocity, value1 = max motor force
- btGeneric6DofConstraint* genCons = (btGeneric6DofConstraint*)typedConstraint;
- int angMotorIndex = param-9;
- btRotationalLimitMotor* rotMotor = genCons->getRotationalLimitMotor(angMotorIndex);
- rotMotor->m_enableMotor = (value1 > 0.f);
- rotMotor->m_targetVelocity = value0;
- rotMotor->m_maxMotorForce = value1;
- break;
- }
-
- case 12: case 13: case 14: case 15: case 16: case 17:
- {
- //param 12-17 are for motorized springs on each of the degrees of freedom
- btGeneric6DofSpringConstraint* genCons = (btGeneric6DofSpringConstraint*)typedConstraint;
- int springIndex = param-12;
- if (value0!=0.f)
- {
- bool springEnabled = true;
- genCons->setStiffness(springIndex,value0);
- genCons->setDamping(springIndex,value1);
- genCons->enableSpring(springIndex,springEnabled);
- genCons->setEquilibriumPoint(springIndex);
- } else
- {
- bool springEnabled = false;
- genCons->enableSpring(springIndex,springEnabled);
- }
- break;
- }
-
- default:
- {
- }
- };
- break;
- };
- case PHY_CONE_TWIST_CONSTRAINT:
- {
- switch (param)
- {
- case 3: case 4: case 5:
- {
- //param = 3,4,5 are constraint limits, high limit values
- btConeTwistConstraint* coneTwist = (btConeTwistConstraint*)typedConstraint;
- if (value1<0.0f)
- coneTwist->setLimit(param,btScalar(BT_LARGE_FLOAT));
- else
- coneTwist->setLimit(param,value1);
- break;
- }
- default:
- {
- }
- };
- break;
- };
- case PHY_ANGULAR_CONSTRAINT:
- case PHY_LINEHINGE_CONSTRAINT:
- {
- switch (param)
- {
- case 3:
- {
- //param = 3 is a constraint limit, with low/high limit value
- btHingeConstraint* hingeCons = (btHingeConstraint*)typedConstraint;
- hingeCons->setLimit(value0,value1);
- break;
- }
- default:
- {
- }
- }
- break;
- };
- default:
- {
- };
- };
-}
-
-btTypedConstraint* CcdPhysicsEnvironment::GetConstraintById(int constraintId)
-{
- // For soft body constraints
- if (constraintId == 0)
- return NULL;
-
- int numConstraints = m_dynamicsWorld->getNumConstraints();
- int i;
- for (i=0;i<numConstraints;i++)
- {
- btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
- if (constraint->getUserConstraintId()==constraintId)
- {
- return constraint;
- }
- }
- return 0;
-}
-
-
-void CcdPhysicsEnvironment::AddSensor(PHY_IPhysicsController* ctrl)
-{
- CcdPhysicsController* ctrl1 = (CcdPhysicsController* )ctrl;
- AddCcdPhysicsController(ctrl1);
-}
-
-bool CcdPhysicsEnvironment::RemoveCollisionCallback(PHY_IPhysicsController* ctrl)
-{
- CcdPhysicsController* ccdCtrl = (CcdPhysicsController*)ctrl;
- return ccdCtrl->Unregister();
-}
-
-
-void CcdPhysicsEnvironment::RemoveSensor(PHY_IPhysicsController* ctrl)
-{
- RemoveCcdPhysicsController((CcdPhysicsController*)ctrl);
-}
-
-void CcdPhysicsEnvironment::AddTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
-{
- /* printf("addTouchCallback\n(response class = %i)\n",response_class);
-
- //map PHY_ convention into SM_ convention
- switch (response_class)
- {
- case PHY_FH_RESPONSE:
- printf("PHY_FH_RESPONSE\n");
- break;
- case PHY_SENSOR_RESPONSE:
- printf("PHY_SENSOR_RESPONSE\n");
- break;
- case PHY_CAMERA_RESPONSE:
- printf("PHY_CAMERA_RESPONSE\n");
- break;
- case PHY_OBJECT_RESPONSE:
- printf("PHY_OBJECT_RESPONSE\n");
- break;
- case PHY_STATIC_RESPONSE:
- printf("PHY_STATIC_RESPONSE\n");
- break;
- default:
- assert(0);
- return;
- }
- */
-
- m_triggerCallbacks[response_class] = callback;
- m_triggerCallbacksUserPtrs[response_class] = user;
-
-}
-bool CcdPhysicsEnvironment::RequestCollisionCallback(PHY_IPhysicsController* ctrl)
-{
- CcdPhysicsController* ccdCtrl = static_cast<CcdPhysicsController*>(ctrl);
- return ccdCtrl->Register();
-}
-
-void CcdPhysicsEnvironment::CallbackTriggers()
-{
- bool draw_contact_points = m_debugDrawer && (m_debugDrawer->getDebugMode() & btIDebugDraw::DBG_DrawContactPoints);
-
- if (!m_triggerCallbacks[PHY_OBJECT_RESPONSE] && !draw_contact_points)
- return;
-
- //walk over all overlapping pairs, and if one of the involved bodies is registered for trigger callback, perform callback
- btDispatcher* dispatcher = m_dynamicsWorld->getDispatcher();
- int numManifolds = dispatcher->getNumManifolds();
- for (int i=0;i<numManifolds;i++)
- {
- bool colliding_ctrl0 = true;
- btPersistentManifold* manifold = dispatcher->getManifoldByIndexInternal(i);
- int numContacts = manifold->getNumContacts();
- if (!numContacts) continue;
-
- const btRigidBody* rb0 = static_cast<const btRigidBody*>(manifold->getBody0());
- const btRigidBody* rb1 = static_cast<const btRigidBody*>(manifold->getBody1());
- if (draw_contact_points)
- {
- for (int j=0;j<numContacts;j++)
- {
- btVector3 color(1,1,0);
- const btManifoldPoint& cp = manifold->getContactPoint(j);
- m_debugDrawer->drawContactPoint(cp.m_positionWorldOnB,
- cp.m_normalWorldOnB,
- cp.getDistance(),
- cp.getLifeTime(),
- color);
- }
- }
-
- //m_internalOwner is set in 'addPhysicsController'
- CcdPhysicsController* ctrl0 = static_cast<CcdPhysicsController*>(rb0->getUserPointer());
- CcdPhysicsController* ctrl1 = static_cast<CcdPhysicsController*>(rb1->getUserPointer());
- bool usecallback = false;
-
- // Test if one of the controller is registered and use collision callback.
- if (ctrl0->Registered())
- usecallback = true;
- else if (ctrl1->Registered()) {
- colliding_ctrl0 = false;
- usecallback = true;
- }
-
- if (usecallback) {
- static PHY_CollData coll_data;
- const btManifoldPoint &cp = manifold->getContactPoint(0);
-
- /* Make sure that "point1" is always on the object we report on, and
- * "point2" on the other object. Also ensure the normal is oriented
- * correctly. */
- btVector3 point1 = colliding_ctrl0 ? cp.m_positionWorldOnA : cp.m_positionWorldOnB;
- btVector3 point2 = colliding_ctrl0 ? cp.m_positionWorldOnB : cp.m_positionWorldOnA;
- btVector3 normal = colliding_ctrl0 ? -cp.m_normalWorldOnB : cp.m_normalWorldOnB;
-
- coll_data.m_point1 = MT_Vector3(point1.m_floats);
- coll_data.m_point2 = MT_Vector3(point2.m_floats);
- coll_data.m_normal = MT_Vector3(normal.m_floats);
-
- m_triggerCallbacks[PHY_OBJECT_RESPONSE](m_triggerCallbacksUserPtrs[PHY_OBJECT_RESPONSE],
- ctrl0, ctrl1, &coll_data);
- }
- // Bullet does not refresh the manifold contact point for object without contact response
- // may need to remove this when a newer Bullet version is integrated
- if (!dispatcher->needsResponse(rb0, rb1))
- {
- // Refresh algorithm fails sometimes when there is penetration
- // (usuall the case with ghost and sensor objects)
- // Let's just clear the manifold, in any case, it is recomputed on each frame.
- manifold->clearManifold(); //refreshContactPoints(rb0->getCenterOfMassTransform(),rb1->getCenterOfMassTransform());
- }
- }
-}
-
-// This call back is called before a pair is added in the cache
-// Handy to remove objects that must be ignored by sensors
-bool CcdOverlapFilterCallBack::needBroadphaseCollision(btBroadphaseProxy* proxy0,btBroadphaseProxy* proxy1) const
-{
- btCollisionObject *colObj0, *colObj1;
- CcdPhysicsController *sensorCtrl, *objCtrl;
-
- KX_GameObject *kxObj0 = KX_GameObject::GetClientObject(
- (KX_ClientObjectInfo*)
- ((CcdPhysicsController*)
- (((btCollisionObject*)proxy0->m_clientObject)->getUserPointer()))
- ->GetNewClientInfo());
- KX_GameObject *kxObj1 = KX_GameObject::GetClientObject(
- (KX_ClientObjectInfo*)
- ((CcdPhysicsController*)
- (((btCollisionObject*)proxy1->m_clientObject)->getUserPointer()))
- ->GetNewClientInfo());
-
- // First check the filters. Note that this is called during scene
- // conversion, so we can't assume the KX_GameObject instances exist. This
- // may make some objects erroneously collide on the first frame, but the
- // alternative is to have them erroneously miss.
- bool collides;
- collides = (proxy0->m_collisionFilterGroup & proxy1->m_collisionFilterMask) != 0;
- collides = collides && (proxy1->m_collisionFilterGroup & proxy0->m_collisionFilterMask);
- if (kxObj0 && kxObj1) {
- collides = collides && kxObj0->CheckCollision(kxObj1);
- collides = collides && kxObj1->CheckCollision(kxObj0);
- }
- if (!collides)
- return false;
-
- // additional check for sensor object
- if (proxy0->m_collisionFilterGroup & btBroadphaseProxy::SensorTrigger)
- {
- // this is a sensor object, the other one can't be a sensor object because
- // they exclude each other in the above test
- assert(!(proxy1->m_collisionFilterGroup & btBroadphaseProxy::SensorTrigger));
- colObj0 = (btCollisionObject*)proxy0->m_clientObject;
- colObj1 = (btCollisionObject*)proxy1->m_clientObject;
- }
- else if (proxy1->m_collisionFilterGroup & btBroadphaseProxy::SensorTrigger)
- {
- colObj0 = (btCollisionObject*)proxy1->m_clientObject;
- colObj1 = (btCollisionObject*)proxy0->m_clientObject;
- }
- else
- {
- return true;
- }
- if (!colObj0 || !colObj1)
- return false;
- sensorCtrl = static_cast<CcdPhysicsController*>(colObj0->getUserPointer());
- objCtrl = static_cast<CcdPhysicsController*>(colObj1->getUserPointer());
- if (m_physEnv->m_triggerCallbacks[PHY_BROADPH_RESPONSE])
- {
- return m_physEnv->m_triggerCallbacks[PHY_BROADPH_RESPONSE](m_physEnv->m_triggerCallbacksUserPtrs[PHY_BROADPH_RESPONSE], sensorCtrl, objCtrl, 0);
- }
- return true;
-}
-
-
-#ifdef NEW_BULLET_VEHICLE_SUPPORT
-
-//complex constraint for vehicles
-PHY_IVehicle* CcdPhysicsEnvironment::GetVehicleConstraint(int constraintId)
-{
- int i;
-
- int numVehicles = m_wrapperVehicles.size();
- for (i=0;i<numVehicles;i++)
- {
- WrapperVehicle* wrapperVehicle = m_wrapperVehicles[i];
- if (wrapperVehicle->GetVehicle()->getUserConstraintId() == constraintId)
- return wrapperVehicle;
- }
-
- return 0;
-}
-
-#endif //NEW_BULLET_VEHICLE_SUPPORT
-
-
-PHY_ICharacter* CcdPhysicsEnvironment::GetCharacterController(KX_GameObject *ob)
-{
- CcdPhysicsController* controller = (CcdPhysicsController*)ob->GetPhysicsController();
- return (controller) ? dynamic_cast<BlenderBulletCharacterController*>(controller->GetCharacterController()) : NULL;
-}
-
-
-PHY_IPhysicsController* CcdPhysicsEnvironment::CreateSphereController(float radius,const MT_Vector3& position)
-{
-
- CcdConstructionInfo cinfo;
- memset(&cinfo, 0, sizeof(cinfo)); /* avoid uninitialized values */
- cinfo.m_collisionShape = new btSphereShape(radius); // memory leak! The shape is not deleted by Bullet and we cannot add it to the KX_Scene.m_shapes list
- cinfo.m_MotionState = 0;
- cinfo.m_physicsEnv = this;
- // declare this object as Dyamic rather than static!!
- // The reason as it is designed to detect all type of object, including static object
- // It would cause static-static message to be printed on the console otherwise
- cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE | btCollisionObject::CF_STATIC_OBJECT;
- DefaultMotionState* motionState = new DefaultMotionState();
- cinfo.m_MotionState = motionState;
- // we will add later the possibility to select the filter from option
- cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
- cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
- cinfo.m_bSensor = true;
- motionState->m_worldTransform.setIdentity();
- motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));
-
- CcdPhysicsController* sphereController = new CcdPhysicsController(cinfo);
-
- return sphereController;
-}
-
-int findClosestNode(btSoftBody* sb,const btVector3& worldPoint);
-int findClosestNode(btSoftBody* sb,const btVector3& worldPoint)
-{
- int node = -1;
-
- btSoftBody::tNodeArray& nodes(sb->m_nodes);
- float maxDistSqr = 1e30f;
-
- for (int n=0;n<nodes.size();n++)
- {
- btScalar distSqr = (nodes[n].m_x - worldPoint).length2();
- if (distSqr<maxDistSqr)
- {
- maxDistSqr = distSqr;
- node = n;
- }
- }
- return node;
-}
-
-int CcdPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController* ctrl0,class PHY_IPhysicsController* ctrl1,PHY_ConstraintType type,
- float pivotX,float pivotY,float pivotZ,
- float axisX,float axisY,float axisZ,
- float axis1X,float axis1Y,float axis1Z,
- float axis2X,float axis2Y,float axis2Z,int flags
- )
-{
-
- bool disableCollisionBetweenLinkedBodies = (0!=(flags & CCD_CONSTRAINT_DISABLE_LINKED_COLLISION));
-
-
-
- CcdPhysicsController* c0 = (CcdPhysicsController*)ctrl0;
- CcdPhysicsController* c1 = (CcdPhysicsController*)ctrl1;
-
- btRigidBody* rb0 = c0 ? c0->GetRigidBody() : 0;
- btRigidBody* rb1 = c1 ? c1->GetRigidBody() : 0;
-
-
-
-
- bool rb0static = rb0 ? rb0->isStaticOrKinematicObject() : true;
- bool rb1static = rb1 ? rb1->isStaticOrKinematicObject() : true;
-
- btCollisionObject* colObj0 = c0->GetCollisionObject();
- if (!colObj0)
- {
- return 0;
- }
-
- btVector3 pivotInA(pivotX,pivotY,pivotZ);
-
-
-
- //it might be a soft body, let's try
- btSoftBody* sb0 = c0 ? c0->GetSoftBody() : 0;
- btSoftBody* sb1 = c1 ? c1->GetSoftBody() : 0;
- if (sb0 && sb1)
- {
- //not between two soft bodies?
- return 0;
- }
-
- if (sb0)
- {
- //either cluster or node attach, let's find closest node first
- //the soft body doesn't have a 'real' world transform, so get its initial world transform for now
- btVector3 pivotPointSoftWorld = sb0->m_initialWorldTransform(pivotInA);
- int node=findClosestNode(sb0,pivotPointSoftWorld);
- if (node >=0)
- {
- bool clusterconstaint = false;
-/*
- switch (type)
- {
- case PHY_LINEHINGE_CONSTRAINT:
- {
- if (sb0->clusterCount() && rb1)
- {
- btSoftBody::LJoint::Specs ls;
- ls.erp=0.5f;
- ls.position=sb0->clusterCom(0);
- sb0->appendLinearJoint(ls,rb1);
- clusterconstaint = true;
- break;
- }
- }
- case PHY_GENERIC_6DOF_CONSTRAINT:
- {
- if (sb0->clusterCount() && rb1)
- {
- btSoftBody::AJoint::Specs as;
- as.erp = 1;
- as.cfm = 1;
- as.axis.setValue(axisX,axisY,axisZ);
- sb0->appendAngularJoint(as,rb1);
- clusterconstaint = true;
- break;
- }
-
- break;
- }
- default:
- {
-
- }
- };
- */
-
- if (!clusterconstaint)
- {
- if (rb1)
- {
- sb0->appendAnchor(node,rb1,disableCollisionBetweenLinkedBodies);
- } else
- {
- sb0->setMass(node,0.f);
- }
- }
-
-
- }
- return 0;//can't remove soft body anchors yet
- }
-
- if (sb1)
- {
- btVector3 pivotPointAWorld = colObj0->getWorldTransform()(pivotInA);
- int node=findClosestNode(sb1,pivotPointAWorld);
- if (node >=0)
- {
- bool clusterconstaint = false;
-
- /*
- switch (type)
- {
- case PHY_LINEHINGE_CONSTRAINT:
- {
- if (sb1->clusterCount() && rb0)
- {
- btSoftBody::LJoint::Specs ls;
- ls.erp=0.5f;
- ls.position=sb1->clusterCom(0);
- sb1->appendLinearJoint(ls,rb0);
- clusterconstaint = true;
- break;
- }
- }
- case PHY_GENERIC_6DOF_CONSTRAINT:
- {
- if (sb1->clusterCount() && rb0)
- {
- btSoftBody::AJoint::Specs as;
- as.erp = 1;
- as.cfm = 1;
- as.axis.setValue(axisX,axisY,axisZ);
- sb1->appendAngularJoint(as,rb0);
- clusterconstaint = true;
- break;
- }
-
- break;
- }
- default:
- {
-
-
- }
- };*/
-
-
- if (!clusterconstaint)
- {
- if (rb0)
- {
- sb1->appendAnchor(node,rb0,disableCollisionBetweenLinkedBodies);
- } else
- {
- sb1->setMass(node,0.f);
- }
- }
-
-
- }
- return 0;//can't remove soft body anchors yet
- }
-
- if (rb0static && rb1static)
- {
-
- return 0;
- }
-
-
- if (!rb0)
- return 0;
-
- btVector3 pivotInB = rb1 ? rb1->getCenterOfMassTransform().inverse()(rb0->getCenterOfMassTransform()(pivotInA)) :
- rb0->getCenterOfMassTransform() * pivotInA;
- btVector3 axisInA(axisX,axisY,axisZ);
-
-
- bool angularOnly = false;
-
- switch (type)
- {
- case PHY_POINT2POINT_CONSTRAINT:
- {
- // If either of the controllers is missing, we can't do anything.
- if (!c0 || !c1) return 0;
-
- btPoint2PointConstraint* p2p = 0;
-
- if (rb1)
- {
- p2p = new btPoint2PointConstraint(*rb0,
- *rb1,pivotInA,pivotInB);
- } else
- {
- p2p = new btPoint2PointConstraint(*rb0,
- pivotInA);
- }
-
- c0->addCcdConstraintRef(p2p);
- c1->addCcdConstraintRef(p2p);
- m_dynamicsWorld->addConstraint(p2p,disableCollisionBetweenLinkedBodies);
-// m_constraints.push_back(p2p);
-
- p2p->setUserConstraintId(gConstraintUid++);
- p2p->setUserConstraintType(type);
- //64 bit systems can't cast pointer to int. could use size_t instead.
- return p2p->getUserConstraintId();
-
- break;
- }
-
- case PHY_GENERIC_6DOF_CONSTRAINT:
- {
- // If either of the controllers is missing, we can't do anything.
- if (!c0 || !c1) return 0;
-
- btGeneric6DofConstraint* genericConstraint = 0;
-
- if (rb1)
- {
- btTransform frameInA;
- btTransform frameInB;
-
- btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
- if (axis1.length() == 0.0f)
- {
- btPlaneSpace1( axisInA, axis1, axis2 );
- }
-
- frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
- axisInA.y(), axis1.y(), axis2.y(),
- axisInA.z(), axis1.z(), axis2.z() );
- frameInA.setOrigin( pivotInA );
-
- btTransform inv = rb1->getCenterOfMassTransform().inverse();
-
- btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA;
-
- frameInB = inv * globalFrameA;
- bool useReferenceFrameA = true;
-
- genericConstraint = new btGeneric6DofSpringConstraint(
- *rb0,*rb1,
- frameInA,frameInB,useReferenceFrameA);
-
-
- } else
- {
- static btRigidBody s_fixedObject2( 0,0,0);
- btTransform frameInA;
- btTransform frameInB;
-
- btVector3 axis1, axis2;
- btPlaneSpace1( axisInA, axis1, axis2 );
-
- frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
- axisInA.y(), axis1.y(), axis2.y(),
- axisInA.z(), axis1.z(), axis2.z() );
-
- frameInA.setOrigin( pivotInA );
-
- ///frameInB in worldspace
- frameInB = rb0->getCenterOfMassTransform() * frameInA;
-
- bool useReferenceFrameA = true;
- genericConstraint = new btGeneric6DofSpringConstraint(
- *rb0,s_fixedObject2,
- frameInA,frameInB,useReferenceFrameA);
- }
-
- if (genericConstraint)
- {
- //m_constraints.push_back(genericConstraint);
- c0->addCcdConstraintRef(genericConstraint);
- c1->addCcdConstraintRef(genericConstraint);
- m_dynamicsWorld->addConstraint(genericConstraint,disableCollisionBetweenLinkedBodies);
- genericConstraint->setUserConstraintId(gConstraintUid++);
- genericConstraint->setUserConstraintType(type);
- //64 bit systems can't cast pointer to int. could use size_t instead.
- return genericConstraint->getUserConstraintId();
- }
-
- break;
- }
- case PHY_CONE_TWIST_CONSTRAINT:
- {
- // If either of the controllers is missing, we can't do anything.
- if (!c0 || !c1) return 0;
-
- btConeTwistConstraint* coneTwistContraint = 0;
-
-
- if (rb1)
- {
- btTransform frameInA;
- btTransform frameInB;
-
- btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
- if (axis1.length() == 0.0f)
- {
- btPlaneSpace1( axisInA, axis1, axis2 );
- }
-
- frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
- axisInA.y(), axis1.y(), axis2.y(),
- axisInA.z(), axis1.z(), axis2.z() );
- frameInA.setOrigin( pivotInA );
-
- btTransform inv = rb1->getCenterOfMassTransform().inverse();
-
- btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA;
-
- frameInB = inv * globalFrameA;
-
- coneTwistContraint = new btConeTwistConstraint( *rb0,*rb1,
- frameInA,frameInB);
-
-
- } else
- {
- static btRigidBody s_fixedObject2( 0,0,0);
- btTransform frameInA;
- btTransform frameInB;
-
- btVector3 axis1, axis2;
- btPlaneSpace1( axisInA, axis1, axis2 );
-
- frameInA.getBasis().setValue( axisInA.x(), axis1.x(), axis2.x(),
- axisInA.y(), axis1.y(), axis2.y(),
- axisInA.z(), axis1.z(), axis2.z() );
-
- frameInA.setOrigin( pivotInA );
-
- ///frameInB in worldspace
- frameInB = rb0->getCenterOfMassTransform() * frameInA;
-
- coneTwistContraint = new btConeTwistConstraint(
- *rb0,s_fixedObject2,
- frameInA,frameInB);
- }
-
- if (coneTwistContraint)
- {
- //m_constraints.push_back(genericConstraint);
- c0->addCcdConstraintRef(coneTwistContraint);
- c1->addCcdConstraintRef(coneTwistContraint);
- m_dynamicsWorld->addConstraint(coneTwistContraint,disableCollisionBetweenLinkedBodies);
- coneTwistContraint->setUserConstraintId(gConstraintUid++);
- coneTwistContraint->setUserConstraintType(type);
- //64 bit systems can't cast pointer to int. could use size_t instead.
- return coneTwistContraint->getUserConstraintId();
- }
-
-
-
- break;
- }
- case PHY_ANGULAR_CONSTRAINT:
- angularOnly = true;
-
-
- case PHY_LINEHINGE_CONSTRAINT:
- {
- // If either of the controllers is missing, we can't do anything.
- if (!c0 || !c1) return 0;
-
- btHingeConstraint* hinge = 0;
-
- if (rb1)
- {
- // We know the orientations so we should use them instead of
- // having btHingeConstraint fill in the blanks any way it wants to.
- btTransform frameInA;
- btTransform frameInB;
-
- btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
- if (axis1.length() == 0.0f)
- {
- btPlaneSpace1( axisInA, axis1, axis2 );
- }
-
- // Internally btHingeConstraint's hinge-axis is z
- frameInA.getBasis().setValue( axis1.x(), axis2.x(), axisInA.x(),
- axis1.y(), axis2.y(), axisInA.y(),
- axis1.z(), axis2.z(), axisInA.z() );
-
- frameInA.setOrigin( pivotInA );
-
- btTransform inv = rb1->getCenterOfMassTransform().inverse();
-
- btTransform globalFrameA = rb0->getCenterOfMassTransform() * frameInA;
-
- frameInB = inv * globalFrameA;
-
- hinge = new btHingeConstraint(*rb0,*rb1,frameInA,frameInB);
-
-
- } else
- {
- static btRigidBody s_fixedObject2( 0,0,0);
-
- btTransform frameInA;
- btTransform frameInB;
-
- btVector3 axis1(axis1X,axis1Y,axis1Z), axis2(axis2X,axis2Y,axis2Z);
- if (axis1.length() == 0.0f)
- {
- btPlaneSpace1( axisInA, axis1, axis2 );
- }
-
- // Internally btHingeConstraint's hinge-axis is z
- frameInA.getBasis().setValue( axis1.x(), axis2.x(), axisInA.x(),
- axis1.y(), axis2.y(), axisInA.y(),
- axis1.z(), axis2.z(), axisInA.z() );
- frameInA.setOrigin( pivotInA );
- frameInB = rb0->getCenterOfMassTransform() * frameInA;
-
- hinge = new btHingeConstraint(*rb0, s_fixedObject2, frameInA, frameInB);
- }
- hinge->setAngularOnly(angularOnly);
-
- //m_constraints.push_back(hinge);
- c0->addCcdConstraintRef(hinge);
- c1->addCcdConstraintRef(hinge);
- m_dynamicsWorld->addConstraint(hinge,disableCollisionBetweenLinkedBodies);
- hinge->setUserConstraintId(gConstraintUid++);
- hinge->setUserConstraintType(type);
- //64 bit systems can't cast pointer to int. could use size_t instead.
- return hinge->getUserConstraintId();
- break;
- }
-#ifdef NEW_BULLET_VEHICLE_SUPPORT
-
- case PHY_VEHICLE_CONSTRAINT:
- {
- btRaycastVehicle::btVehicleTuning* tuning = new btRaycastVehicle::btVehicleTuning();
- btRigidBody* chassis = rb0;
- btDefaultVehicleRaycaster* raycaster = new BlenderVehicleRaycaster(m_dynamicsWorld);
- btRaycastVehicle* vehicle = new btRaycastVehicle(*tuning,chassis,raycaster);
- WrapperVehicle* wrapperVehicle = new WrapperVehicle(vehicle,ctrl0);
- m_wrapperVehicles.push_back(wrapperVehicle);
- m_dynamicsWorld->addVehicle(vehicle);
- vehicle->setUserConstraintId(gConstraintUid++);
- vehicle->setUserConstraintType(type);
- return vehicle->getUserConstraintId();
-
- break;
- };
-#endif //NEW_BULLET_VEHICLE_SUPPORT
-
- default:
- {
- }
- };
-
- //btRigidBody& rbA,btRigidBody& rbB, const btVector3& pivotInA,const btVector3& pivotInB
-
- return 0;
-
-}
-
-
-
-PHY_IPhysicsController* CcdPhysicsEnvironment::CreateConeController(float coneradius,float coneheight)
-{
- CcdConstructionInfo cinfo;
-//don't memset cinfo: this is C++ and values should be set in the constructor!
-
- // we don't need a CcdShapeConstructionInfo for this shape:
- // it is simple enough for the standard copy constructor (see CcdPhysicsController::GetReplica)
- cinfo.m_collisionShape = new btConeShape(coneradius,coneheight);
- cinfo.m_MotionState = 0;
- cinfo.m_physicsEnv = this;
- cinfo.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE | btCollisionObject::CF_STATIC_OBJECT;
- DefaultMotionState* motionState = new DefaultMotionState();
- cinfo.m_MotionState = motionState;
-
- // we will add later the possibility to select the filter from option
- cinfo.m_collisionFilterMask = CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter;
- cinfo.m_collisionFilterGroup = CcdConstructionInfo::SensorFilter;
- cinfo.m_bSensor = true;
- motionState->m_worldTransform.setIdentity();
-// motionState->m_worldTransform.setOrigin(btVector3(position[0],position[1],position[2]));
-
- CcdPhysicsController* sphereController = new CcdPhysicsController(cinfo);
-
-
- return sphereController;
-}
-
-float CcdPhysicsEnvironment::getAppliedImpulse(int constraintid)
-{
- // For soft body constraints
- if (constraintid == 0)
- return 0.0f;
-
- int i;
- int numConstraints = m_dynamicsWorld->getNumConstraints();
- for (i=0;i<numConstraints;i++)
- {
- btTypedConstraint* constraint = m_dynamicsWorld->getConstraint(i);
- if (constraint->getUserConstraintId() == constraintid)
- {
- return constraint->getAppliedImpulse();
- }
- }
-
- return 0.f;
-}
-
-void CcdPhysicsEnvironment::ExportFile(const char* filename)
-{
- btDefaultSerializer* serializer = new btDefaultSerializer();
-
-
- for (int i=0;i<m_dynamicsWorld->getNumCollisionObjects();i++)
- {
-
- btCollisionObject* colObj = m_dynamicsWorld->getCollisionObjectArray()[i];
-
- CcdPhysicsController* controller = static_cast<CcdPhysicsController*>(colObj->getUserPointer());
- if (controller)
- {
- const char* name = KX_GameObject::GetClientObject((KX_ClientObjectInfo*)controller->GetNewClientInfo())->GetName();
- if (name)
- {
- serializer->registerNameForPointer(colObj,name);
- }
- }
- }
-
- m_dynamicsWorld->serialize(serializer);
-
- FILE* file = fopen(filename,"wb");
- if (file)
- {
- fwrite(serializer->getBufferPointer(),serializer->getCurrentBufferSize(),1, file);
- fclose(file);
- }
-}
-
-struct BlenderDebugDraw : public btIDebugDraw
-{
- BlenderDebugDraw () :
- m_debugMode(0)
- {
- }
-
- int m_debugMode;
-
- virtual void drawLine(const btVector3& from,const btVector3& to,const btVector3& color)
- {
- if (m_debugMode >0)
- {
- MT_Vector3 kxfrom(from[0],from[1],from[2]);
- MT_Vector3 kxto(to[0],to[1],to[2]);
- MT_Vector3 kxcolor(color[0],color[1],color[2]);
-
- KX_RasterizerDrawDebugLine(kxfrom,kxto,kxcolor);
- }
- }
-
- virtual void reportErrorWarning(const char* warningString)
- {
-
- }
-
- virtual void drawContactPoint(const btVector3& PointOnB,const btVector3& normalOnB,float distance,int lifeTime,const btVector3& color)
- {
- drawLine(PointOnB, PointOnB + normalOnB, color);
- drawSphere(PointOnB, 0.1f, color);
- }
-
- virtual void setDebugMode(int debugMode)
- {
- m_debugMode = debugMode;
- }
- virtual int getDebugMode() const
- {
- return m_debugMode;
- }
- ///todo: find out if Blender can do this
- virtual void draw3dText(const btVector3& location,const char* textString)
- {
-
- }
-
-};
-
-CcdPhysicsEnvironment *CcdPhysicsEnvironment::Create(Scene *blenderscene, bool visualizePhysics)
-{
- CcdPhysicsEnvironment* ccdPhysEnv = new CcdPhysicsEnvironment((blenderscene->gm.mode & WO_DBVT_CULLING) != 0);
- ccdPhysEnv->SetDebugDrawer(new BlenderDebugDraw());
- ccdPhysEnv->SetDeactivationLinearTreshold(blenderscene->gm.lineardeactthreshold);
- ccdPhysEnv->SetDeactivationAngularTreshold(blenderscene->gm.angulardeactthreshold);
- ccdPhysEnv->SetDeactivationTime(blenderscene->gm.deactivationtime);
-
- if (visualizePhysics)
- ccdPhysEnv->SetDebugMode(btIDebugDraw::DBG_DrawWireframe|btIDebugDraw::DBG_DrawAabb|btIDebugDraw::DBG_DrawContactPoints|btIDebugDraw::DBG_DrawText|btIDebugDraw::DBG_DrawConstraintLimits|btIDebugDraw::DBG_DrawConstraints);
-
- return ccdPhysEnv;
-}
-
-void CcdPhysicsEnvironment::ConvertObject(KX_GameObject *gameobj, RAS_MeshObject *meshobj, DerivedMesh *dm, KX_Scene *kxscene, PHY_ShapeProps *shapeprops, PHY_MaterialProps *smmaterial, PHY_IMotionState *motionstate, int activeLayerBitInfo, bool isCompoundChild, bool hasCompoundChildren)
-{
- Object* blenderobject = gameobj->GetBlenderObject();
-
- bool isbulletdyna = (blenderobject->gameflag & OB_DYNAMIC) != 0;
- bool isbulletsensor = (blenderobject->gameflag & OB_SENSOR) != 0;
- bool isbulletchar = (blenderobject->gameflag & OB_CHARACTER) != 0;
- bool isbulletsoftbody = (blenderobject->gameflag & OB_SOFT_BODY) != 0;
- bool isbulletrigidbody = (blenderobject->gameflag & OB_RIGID_BODY) != 0;
- bool useGimpact = false;
- CcdConstructionInfo ci;
- class CcdShapeConstructionInfo *shapeInfo = new CcdShapeConstructionInfo();
-
- // get Root Parent of blenderobject
- Object *blenderparent = blenderobject->parent;
- while (blenderparent && blenderparent->parent) {
- blenderparent = blenderparent->parent;
- }
-
- KX_GameObject *parent = NULL;
- if (blenderparent)
- {
- KX_BlenderSceneConverter *converter = (KX_BlenderSceneConverter*)KX_GetActiveEngine()->GetSceneConverter();
- parent = converter->FindGameObject(blenderparent);
- isbulletsoftbody = false;
- }
-
- if (!isbulletdyna)
- {
- ci.m_collisionFlags |= btCollisionObject::CF_STATIC_OBJECT;
- }
- if ((blenderobject->gameflag & (OB_GHOST | OB_SENSOR | OB_CHARACTER)) != 0)
- {
- ci.m_collisionFlags |= btCollisionObject::CF_NO_CONTACT_RESPONSE;
- }
-
- ci.m_MotionState = motionstate;
- ci.m_gravity = btVector3(0,0,0);
- ci.m_linearFactor = btVector3(((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_AXIS) !=0)? 0 : 1,
- ((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_AXIS) !=0)? 0 : 1,
- ((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_AXIS) !=0)? 0 : 1);
- ci.m_angularFactor = btVector3(((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_X_ROT_AXIS) !=0)? 0 : 1,
- ((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Y_ROT_AXIS) !=0)? 0 : 1,
- ((blenderobject->gameflag2 & OB_LOCK_RIGID_BODY_Z_ROT_AXIS) !=0)? 0 : 1);
- ci.m_localInertiaTensor =btVector3(0,0,0);
- ci.m_mass = isbulletdyna ? shapeprops->m_mass : 0.f;
- ci.m_clamp_vel_min = shapeprops->m_clamp_vel_min;
- ci.m_clamp_vel_max = shapeprops->m_clamp_vel_max;
- ci.m_clamp_angvel_min = shapeprops->m_clamp_angvel_min;
- ci.m_clamp_angvel_max = shapeprops->m_clamp_angvel_max;
- ci.m_stepHeight = isbulletchar ? shapeprops->m_step_height : 0.f;
- ci.m_jumpSpeed = isbulletchar ? shapeprops->m_jump_speed : 0.f;
- ci.m_fallSpeed = isbulletchar ? shapeprops->m_fall_speed : 0.f;
- ci.m_maxJumps = isbulletchar ? shapeprops->m_max_jumps : 0;
-
- //mmm, for now, take this for the size of the dynamicobject
- // Blender uses inertia for radius of dynamic object
- shapeInfo->m_radius = ci.m_radius = blenderobject->inertia;
- useGimpact = ((isbulletdyna || isbulletsensor) && !isbulletsoftbody);
-
- if (isbulletsoftbody)
- {
- if (blenderobject->bsoft)
- {
- ci.m_margin = blenderobject->bsoft->margin;
- ci.m_gamesoftFlag = blenderobject->bsoft->flag;
-
- ci.m_soft_linStiff = blenderobject->bsoft->linStiff;
- ci.m_soft_angStiff = blenderobject->bsoft->angStiff; /* angular stiffness 0..1 */
- ci.m_soft_volume = blenderobject->bsoft->volume; /* volume preservation 0..1 */
-
- ci.m_soft_viterations = blenderobject->bsoft->viterations; /* Velocities solver iterations */
- ci.m_soft_piterations = blenderobject->bsoft->piterations; /* Positions solver iterations */
- ci.m_soft_diterations = blenderobject->bsoft->diterations; /* Drift solver iterations */
- ci.m_soft_citerations = blenderobject->bsoft->citerations; /* Cluster solver iterations */
-
- ci.m_soft_kSRHR_CL = blenderobject->bsoft->kSRHR_CL; /* Soft vs rigid hardness [0,1] (cluster only) */
- ci.m_soft_kSKHR_CL = blenderobject->bsoft->kSKHR_CL; /* Soft vs kinetic hardness [0,1] (cluster only) */
- ci.m_soft_kSSHR_CL = blenderobject->bsoft->kSSHR_CL; /* Soft vs soft hardness [0,1] (cluster only) */
- ci.m_soft_kSR_SPLT_CL = blenderobject->bsoft->kSR_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
-
- ci.m_soft_kSK_SPLT_CL = blenderobject->bsoft->kSK_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- ci.m_soft_kSS_SPLT_CL = blenderobject->bsoft->kSS_SPLT_CL; /* Soft vs rigid impulse split [0,1] (cluster only) */
- ci.m_soft_kVCF = blenderobject->bsoft->kVCF; /* Velocities correction factor (Baumgarte) */
- ci.m_soft_kDP = blenderobject->bsoft->kDP; /* Damping coefficient [0,1] */
-
- ci.m_soft_kDG = blenderobject->bsoft->kDG; /* Drag coefficient [0,+inf] */
- ci.m_soft_kLF = blenderobject->bsoft->kLF; /* Lift coefficient [0,+inf] */
- ci.m_soft_kPR = blenderobject->bsoft->kPR; /* Pressure coefficient [-inf,+inf] */
- ci.m_soft_kVC = blenderobject->bsoft->kVC; /* Volume conversation coefficient [0,+inf] */
-
- ci.m_soft_kDF = blenderobject->bsoft->kDF; /* Dynamic friction coefficient [0,1] */
- ci.m_soft_kMT = blenderobject->bsoft->kMT; /* Pose matching coefficient [0,1] */
- ci.m_soft_kCHR = blenderobject->bsoft->kCHR; /* Rigid contacts hardness [0,1] */
- ci.m_soft_kKHR = blenderobject->bsoft->kKHR; /* Kinetic contacts hardness [0,1] */
-
- ci.m_soft_kSHR = blenderobject->bsoft->kSHR; /* Soft contacts hardness [0,1] */
- ci.m_soft_kAHR = blenderobject->bsoft->kAHR; /* Anchors hardness [0,1] */
- ci.m_soft_collisionflags = blenderobject->bsoft->collisionflags; /* Vertex/Face or Signed Distance Field(SDF) or Clusters, Soft versus Soft or Rigid */
- ci.m_soft_numclusteriterations = blenderobject->bsoft->numclusteriterations; /* number of iterations to refine collision clusters*/
-
- }
- else
- {
- ci.m_margin = 0.f;
- ci.m_gamesoftFlag = OB_BSB_BENDING_CONSTRAINTS | OB_BSB_SHAPE_MATCHING | OB_BSB_AERO_VPOINT;
-
- ci.m_soft_linStiff = 0.5f;
- ci.m_soft_angStiff = 1.f; /* angular stiffness 0..1 */
- ci.m_soft_volume = 1.f; /* volume preservation 0..1 */
-
- ci.m_soft_viterations = 0;
- ci.m_soft_piterations = 1;
- ci.m_soft_diterations = 0;
- ci.m_soft_citerations = 4;
-
- ci.m_soft_kSRHR_CL = 0.1f;
- ci.m_soft_kSKHR_CL = 1.f;
- ci.m_soft_kSSHR_CL = 0.5f;
- ci.m_soft_kSR_SPLT_CL = 0.5f;
-
- ci.m_soft_kSK_SPLT_CL = 0.5f;
- ci.m_soft_kSS_SPLT_CL = 0.5f;
- ci.m_soft_kVCF = 1;
- ci.m_soft_kDP = 0;
-
- ci.m_soft_kDG = 0;
- ci.m_soft_kLF = 0;
- ci.m_soft_kPR = 0;
- ci.m_soft_kVC = 0;
-
- ci.m_soft_kDF = 0.2f;
- ci.m_soft_kMT = 0.05f;
- ci.m_soft_kCHR = 1.0f;
- ci.m_soft_kKHR = 0.1f;
-
- ci.m_soft_kSHR = 1.f;
- ci.m_soft_kAHR = 0.7f;
- ci.m_soft_collisionflags = OB_BSB_COL_SDF_RS + OB_BSB_COL_VF_SS;
- ci.m_soft_numclusteriterations = 16;
- }
- }
- else
- {
- ci.m_margin = blenderobject->margin;
- }
-
- ci.m_localInertiaTensor = btVector3(ci.m_mass/3.f,ci.m_mass/3.f,ci.m_mass/3.f);
-
- btCollisionShape* bm = 0;
-
- char bounds = isbulletdyna ? OB_BOUND_SPHERE : OB_BOUND_TRIANGLE_MESH;
- if (!(blenderobject->gameflag & OB_BOUNDS))
- {
- if (blenderobject->gameflag & OB_SOFT_BODY)
- bounds = OB_BOUND_TRIANGLE_MESH;
- else if (blenderobject->gameflag & OB_CHARACTER)
- bounds = OB_BOUND_SPHERE;
- }
- else
- {
- if (ELEM(blenderobject->collision_boundtype, OB_BOUND_CONVEX_HULL, OB_BOUND_TRIANGLE_MESH)
- && blenderobject->type != OB_MESH)
- {
- // Can't use triangle mesh or convex hull on a non-mesh object, fall-back to sphere
- bounds = OB_BOUND_SPHERE;
- }
- else
- bounds = blenderobject->collision_boundtype;
- }
-
- // Get bounds information
- float bounds_center[3], bounds_extends[3];
- BoundBox *bb= BKE_object_boundbox_get(blenderobject);
- if (bb==NULL)
- {
- bounds_center[0] = bounds_center[1] = bounds_center[2] = 0.0f;
- bounds_extends[0] = bounds_extends[1] = bounds_extends[2] = 1.0f;
- }
- else
- {
- bounds_extends[0] = 0.5f * fabsf(bb->vec[0][0] - bb->vec[4][0]);
- bounds_extends[1] = 0.5f * fabsf(bb->vec[0][1] - bb->vec[2][1]);
- bounds_extends[2] = 0.5f * fabsf(bb->vec[0][2] - bb->vec[1][2]);
-
- bounds_center[0] = 0.5f * (bb->vec[0][0] + bb->vec[4][0]);
- bounds_center[1] = 0.5f * (bb->vec[0][1] + bb->vec[2][1]);
- bounds_center[2] = 0.5f * (bb->vec[0][2] + bb->vec[1][2]);
- }
-
- switch (bounds)
- {
- case OB_BOUND_SPHERE:
- {
- //float radius = objprop->m_radius;
- //btVector3 inertiaHalfExtents (
- // radius,
- // radius,
- // radius);
-
- //blender doesn't support multisphere, but for testing:
-
- //bm = new MultiSphereShape(inertiaHalfExtents,,&trans.getOrigin(),&radius,1);
- shapeInfo->m_shapeType = PHY_SHAPE_SPHERE;
- // XXX We calculated the radius but didn't use it?
- // objprop.m_boundobject.c.m_radius = MT_max(bb.m_extends[0], MT_max(bb.m_extends[1], bb.m_extends[2]));
- bm = shapeInfo->CreateBulletShape(ci.m_margin);
- break;
- };
- case OB_BOUND_BOX:
- {
- shapeInfo->m_halfExtend.setValue(
- 2.f * bounds_extends[0],
- 2.f * bounds_extends[1],
- 2.f * bounds_extends[2]);
-
- shapeInfo->m_halfExtend /= 2.0f;
- shapeInfo->m_halfExtend = shapeInfo->m_halfExtend.absolute();
- shapeInfo->m_shapeType = PHY_SHAPE_BOX;
- bm = shapeInfo->CreateBulletShape(ci.m_margin);
- break;
- };
- case OB_BOUND_CYLINDER:
- {
- float radius = MT_max(bounds_extends[0], bounds_extends[1]);
- shapeInfo->m_halfExtend.setValue(
- radius,
- radius,
- bounds_extends[2]
- );
- shapeInfo->m_shapeType = PHY_SHAPE_CYLINDER;
- bm = shapeInfo->CreateBulletShape(ci.m_margin);
- break;
- }
-
- case OB_BOUND_CONE:
- {
- shapeInfo->m_radius = MT_max(bounds_extends[0], bounds_extends[1]);
- shapeInfo->m_height = 2.f * bounds_extends[2];
- shapeInfo->m_shapeType = PHY_SHAPE_CONE;
- bm = shapeInfo->CreateBulletShape(ci.m_margin);
- break;
- }
- case OB_BOUND_CONVEX_HULL:
- {
- shapeInfo->SetMesh(meshobj, dm,true);
- bm = shapeInfo->CreateBulletShape(ci.m_margin);
- break;
- }
- case OB_BOUND_CAPSULE:
- {
- shapeInfo->m_radius = MT_max(bounds_extends[0], bounds_extends[1]);
- shapeInfo->m_height = 2.f * (bounds_extends[2] - shapeInfo->m_radius);
- if (shapeInfo->m_height < 0.f)
- shapeInfo->m_height = 0.f;
- shapeInfo->m_shapeType = PHY_SHAPE_CAPSULE;
- bm = shapeInfo->CreateBulletShape(ci.m_margin);
- break;
- }
- case OB_BOUND_TRIANGLE_MESH:
- {
- // mesh shapes can be shared, check first if we already have a shape on that mesh
- class CcdShapeConstructionInfo *sharedShapeInfo = CcdShapeConstructionInfo::FindMesh(meshobj, dm, false);
- if (sharedShapeInfo != NULL)
- {
- shapeInfo->Release();
- shapeInfo = sharedShapeInfo;
- shapeInfo->AddRef();
- } else
- {
- shapeInfo->SetMesh(meshobj, dm, false);
- }
-
- // Soft bodies can benefit from welding, don't do it on non-soft bodies
- if (isbulletsoftbody)
- {
- // disable welding: it doesn't bring any additional stability and it breaks the relation between soft body collision shape and graphic mesh
- // shapeInfo->setVertexWeldingThreshold1((blenderobject->bsoft) ? blenderobject->bsoft->welding ? 0.f);
- shapeInfo->setVertexWeldingThreshold1(0.f); //todo: expose this to the UI
- }
-
- bm = shapeInfo->CreateBulletShape(ci.m_margin, useGimpact, !isbulletsoftbody);
- //should we compute inertia for dynamic shape?
- //bm->calculateLocalInertia(ci.m_mass,ci.m_localInertiaTensor);
-
- break;
- }
- }
-
-
-// ci.m_localInertiaTensor.setValue(0.1f,0.1f,0.1f);
-
- if (!bm)
- {
- delete motionstate;
- shapeInfo->Release();
- return;
- }
-
- //bm->setMargin(ci.m_margin);
-
-
- if (isCompoundChild)
- {
- //find parent, compound shape and add to it
- //take relative transform into account!
- CcdPhysicsController* parentCtrl = (CcdPhysicsController*)parent->GetPhysicsController();
- assert(parentCtrl);
-
- // only makes compound shape if parent has a physics controller (i.e not an empty, etc)
- if (parentCtrl) {
- CcdShapeConstructionInfo* parentShapeInfo = parentCtrl->GetShapeInfo();
- btRigidBody* rigidbody = parentCtrl->GetRigidBody();
- btCollisionShape* colShape = rigidbody->getCollisionShape();
- assert(colShape->isCompound());
- btCompoundShape* compoundShape = (btCompoundShape*)colShape;
-
- // compute the local transform from parent, this may include several node in the chain
- SG_Node* gameNode = gameobj->GetSGNode();
- SG_Node* parentNode = parent->GetSGNode();
- // relative transform
- MT_Vector3 parentScale = parentNode->GetWorldScaling();
- parentScale[0] = MT_Scalar(1.0f)/parentScale[0];
- parentScale[1] = MT_Scalar(1.0f)/parentScale[1];
- parentScale[2] = MT_Scalar(1.0f)/parentScale[2];
- MT_Vector3 relativeScale = gameNode->GetWorldScaling() * parentScale;
- MT_Matrix3x3 parentInvRot = parentNode->GetWorldOrientation().transposed();
- MT_Vector3 relativePos = parentInvRot*((gameNode->GetWorldPosition()-parentNode->GetWorldPosition())*parentScale);
- MT_Matrix3x3 relativeRot = parentInvRot*gameNode->GetWorldOrientation();
-
- shapeInfo->m_childScale.setValue(relativeScale[0],relativeScale[1],relativeScale[2]);
- bm->setLocalScaling(shapeInfo->m_childScale);
- shapeInfo->m_childTrans.getOrigin().setValue(relativePos[0],relativePos[1],relativePos[2]);
- float rot[12];
- relativeRot.getValue(rot);
- shapeInfo->m_childTrans.getBasis().setFromOpenGLSubMatrix(rot);
-
- parentShapeInfo->AddShape(shapeInfo);
- compoundShape->addChildShape(shapeInfo->m_childTrans,bm);
- //do some recalc?
- //recalc inertia for rigidbody
- if (!rigidbody->isStaticOrKinematicObject())
- {
- btVector3 localInertia;
- float mass = 1.f/rigidbody->getInvMass();
- compoundShape->calculateLocalInertia(mass,localInertia);
- rigidbody->setMassProps(mass,localInertia);
- }
- shapeInfo->Release();
- // delete motionstate as it's not used
- delete motionstate;
- }
- return;
- }
-
- if (hasCompoundChildren)
- {
- // create a compound shape info
- CcdShapeConstructionInfo *compoundShapeInfo = new CcdShapeConstructionInfo();
- compoundShapeInfo->m_shapeType = PHY_SHAPE_COMPOUND;
- compoundShapeInfo->AddShape(shapeInfo);
- // create the compound shape manually as we already have the child shape
- btCompoundShape* compoundShape = new btCompoundShape();
- compoundShape->addChildShape(shapeInfo->m_childTrans,bm);
- // now replace the shape
- bm = compoundShape;
- shapeInfo->Release();
- shapeInfo = compoundShapeInfo;
- }
-
-
-
-
-
-
-#ifdef TEST_SIMD_HULL
- if (bm->IsPolyhedral())
- {
- PolyhedralConvexShape* polyhedron = static_cast<PolyhedralConvexShape*>(bm);
- if (!polyhedron->m_optionalHull)
- {
- //first convert vertices in 'Point3' format
- int numPoints = polyhedron->GetNumVertices();
- Point3* points = new Point3[numPoints+1];
- //first 4 points should not be co-planar, so add central point to satisfy MakeHull
- points[0] = Point3(0.f,0.f,0.f);
-
- btVector3 vertex;
- for (int p=0;p<numPoints;p++)
- {
- polyhedron->GetVertex(p,vertex);
- points[p+1] = Point3(vertex.getX(),vertex.getY(),vertex.getZ());
- }
-
- Hull* hull = Hull::MakeHull(numPoints+1,points);
- polyhedron->m_optionalHull = hull;
- }
-
- }
-#endif //TEST_SIMD_HULL
-
-
- ci.m_collisionShape = bm;
- ci.m_shapeInfo = shapeInfo;
- ci.m_friction = smmaterial->m_friction;//tweak the friction a bit, so the default 0.5 works nice
- ci.m_restitution = smmaterial->m_restitution;
- ci.m_physicsEnv = this;
- // drag / damping is inverted
- ci.m_linearDamping = 1.f - shapeprops->m_lin_drag;
- ci.m_angularDamping = 1.f - shapeprops->m_ang_drag;
- //need a bit of damping, else system doesn't behave well
- ci.m_inertiaFactor = shapeprops->m_inertia/0.4f;//defaults to 0.4, don't want to change behavior
-
- ci.m_do_anisotropic = shapeprops->m_do_anisotropic;
- ci.m_anisotropicFriction.setValue(shapeprops->m_friction_scaling[0],shapeprops->m_friction_scaling[1],shapeprops->m_friction_scaling[2]);
-
-
-//////////
- //do Fh, do Rot Fh
- ci.m_do_fh = shapeprops->m_do_fh;
- ci.m_do_rot_fh = shapeprops->m_do_rot_fh;
- ci.m_fh_damping = smmaterial->m_fh_damping;
- ci.m_fh_distance = smmaterial->m_fh_distance;
- ci.m_fh_normal = smmaterial->m_fh_normal;
- ci.m_fh_spring = smmaterial->m_fh_spring;
-
- ci.m_collisionFilterGroup =
- (isbulletsensor) ? short(CcdConstructionInfo::SensorFilter) :
- (isbulletdyna) ? short(CcdConstructionInfo::DefaultFilter) :
- (isbulletchar) ? short(CcdConstructionInfo::CharacterFilter) :
- short(CcdConstructionInfo::StaticFilter);
- ci.m_collisionFilterMask =
- (isbulletsensor) ? short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::SensorFilter) :
- (isbulletdyna) ? short(CcdConstructionInfo::AllFilter) :
- (isbulletchar) ? short(CcdConstructionInfo::AllFilter) :
- short(CcdConstructionInfo::AllFilter ^ CcdConstructionInfo::StaticFilter);
- ci.m_bRigid = isbulletdyna && isbulletrigidbody;
- ci.m_bSoft = isbulletsoftbody;
- ci.m_bDyna = isbulletdyna;
- ci.m_bSensor = isbulletsensor;
- ci.m_bCharacter = isbulletchar;
- ci.m_bGimpact = useGimpact;
- MT_Vector3 scaling = gameobj->NodeGetWorldScaling();
- ci.m_scaling.setValue(scaling[0], scaling[1], scaling[2]);
- CcdPhysicsController* physicscontroller = new CcdPhysicsController(ci);
- // shapeInfo is reference counted, decrement now as we don't use it anymore
- if (shapeInfo)
- shapeInfo->Release();
-
- gameobj->SetPhysicsController(physicscontroller,isbulletdyna);
-
- // record animation for dynamic objects
- if (isbulletdyna)
- gameobj->SetRecordAnimation(true);
-
- physicscontroller->SetNewClientInfo(gameobj->getClientInfo());
-
- // don't add automatically sensor object, they are added when a collision sensor is registered
- if (!isbulletsensor && (blenderobject->lay & activeLayerBitInfo) != 0)
- {
- this->AddCcdPhysicsController( physicscontroller);
- }
-
- {
- btRigidBody* rbody = physicscontroller->GetRigidBody();
-
- if (rbody)
- {
- rbody->setLinearFactor(ci.m_linearFactor);
-
- if (isbulletrigidbody)
- {
- rbody->setAngularFactor(ci.m_angularFactor);
- }
-
- if (rbody && (blenderobject->gameflag & OB_COLLISION_RESPONSE) != 0)
- {
- rbody->setActivationState(DISABLE_DEACTIVATION);
- }
- }
- }
-
- if (parent)
- physicscontroller->SuspendDynamics(false);
-
- CcdPhysicsController* parentCtrl = parent ? (CcdPhysicsController*)parent->GetPhysicsController() : 0;
- physicscontroller->SetParentCtrl(parentCtrl);
-
-
- //Now done directly in ci.m_collisionFlags so that it propagates to replica
- //if (objprop->m_ghost)
- //{
- // rbody->setCollisionFlags(rbody->getCollisionFlags() | btCollisionObject::CF_NO_CONTACT_RESPONSE);
- //}
-
- if (isbulletdyna && !isbulletrigidbody)
- {
-#if 0
- //setting the inertia could achieve similar results to constraint the up
- //but it is prone to instability, so use special 'Angular' constraint
- btVector3 inertia = physicscontroller->GetRigidBody()->getInvInertiaDiagLocal();
- inertia.setX(0.f);
- inertia.setZ(0.f);
-
- physicscontroller->GetRigidBody()->setInvInertiaDiagLocal(inertia);
- physicscontroller->GetRigidBody()->updateInertiaTensor();
-#endif
-
- //this->createConstraint(physicscontroller,0,PHY_ANGULAR_CONSTRAINT,0,0,0,0,0,1);
-
- //Now done directly in ci.m_bRigid so that it propagates to replica
- //physicscontroller->GetRigidBody()->setAngularFactor(0.f);
- ;
- }
-
-
- STR_String materialname;
- if (meshobj)
- materialname = meshobj->GetMaterialName(0);
-
-
-#if 0
- ///test for soft bodies
- if (objprop->m_softbody && physicscontroller)
- {
- btSoftBody* softBody = physicscontroller->GetSoftBody();
- if (softBody && gameobj->GetMesh(0))//only the first mesh, if any
- {
- //should be a mesh then, so add a soft body deformer
- KX_SoftBodyDeformer* softbodyDeformer = new KX_SoftBodyDeformer( gameobj->GetMesh(0),(BL_DeformableGameObject*)gameobj);
- gameobj->SetDeformer(softbodyDeformer);
- }
- }
-#endif
-}
-
-
-void CcdPhysicsEnvironment::SetupObjectConstraints(KX_GameObject *obj_src, KX_GameObject *obj_dest,
- bRigidBodyJointConstraint *dat)
-{
- PHY_IPhysicsController *phy_src = obj_src->GetPhysicsController();
- PHY_IPhysicsController *phy_dest = obj_dest->GetPhysicsController();
- PHY_IPhysicsEnvironment *phys_env = obj_src->GetScene()->GetPhysicsEnvironment();
-
- /* We need to pass a full constraint frame, not just axis. */
- MT_Matrix3x3 localCFrame(MT_Vector3(dat->axX,dat->axY,dat->axZ));
- MT_Vector3 axis0 = localCFrame.getColumn(0);
- MT_Vector3 axis1 = localCFrame.getColumn(1);
- MT_Vector3 axis2 = localCFrame.getColumn(2);
- MT_Vector3 scale = obj_src->NodeGetWorldScaling();
-
- /* Apply not only the pivot and axis values, but also take scale into count
- * this is not working well, if only one or two axis are scaled, but works ok on
- * homogeneous scaling. */
- int constraintId = phys_env->CreateConstraint(
- phy_src, phy_dest, (PHY_ConstraintType)dat->type,
- (float)(dat->pivX * scale.x()), (float)(dat->pivY * scale.y()), (float)(dat->pivZ * scale.z()),
- (float)(axis0.x() * scale.x()), (float)(axis0.y() * scale.y()), (float)(axis0.z() * scale.z()),
- (float)(axis1.x() * scale.x()), (float)(axis1.y() * scale.y()), (float)(axis1.z() * scale.z()),
- (float)(axis2.x() * scale.x()), (float)(axis2.y() * scale.y()), (float)(axis2.z() * scale.z()),
- dat->flag);
-
- /* PHY_POINT2POINT_CONSTRAINT = 1,
- * PHY_LINEHINGE_CONSTRAINT = 2,
- * PHY_ANGULAR_CONSTRAINT = 3,
- * PHY_CONE_TWIST_CONSTRAINT = 4,
- * PHY_VEHICLE_CONSTRAINT = 11,
- * PHY_GENERIC_6DOF_CONSTRAINT = 12 */
-
- if (!constraintId)
- return;
-
- int dof = 0;
- int dof_max = 0;
- int dofbit = 0;
-
- switch (dat->type) {
- /* Set all the limits for generic 6DOF constraint. */
- case PHY_GENERIC_6DOF_CONSTRAINT:
- dof_max = 6;
- dofbit = 1;
- break;
- /* Set XYZ angular limits for cone twist constraint. */
- case PHY_CONE_TWIST_CONSTRAINT:
- dof = 3;
- dof_max = 6;
- dofbit = 1 << 3;
- break;
- /* Set only X angular limits for line hinge and angular constraint. */
- case PHY_LINEHINGE_CONSTRAINT:
- case PHY_ANGULAR_CONSTRAINT:
- dof = 3;
- dof_max = 4;
- dofbit = 1 << 3;
- break;
- default:
- break;
- }
-
- for (; dof < dof_max; dof++) {
- if (dat->flag & dofbit) {
- phys_env->SetConstraintParam(constraintId, dof, dat->minLimit[dof], dat->maxLimit[dof]);
- }
- else {
- /* minLimit > maxLimit means free (no limit) for this degree of freedom. */
- phys_env->SetConstraintParam(constraintId, dof, 1.0f, -1.0f);
- }
- dofbit <<= 1;
- }
-
-}
diff --git a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h b/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
deleted file mode 100644
index a64d2c8f15f..00000000000
--- a/source/gameengine/Physics/Bullet/CcdPhysicsEnvironment.h
+++ /dev/null
@@ -1,345 +0,0 @@
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-/** \file CcdPhysicsEnvironment.h
- * \ingroup physbullet
- * See also \ref bulletdoc
- */
-
-#ifndef __CCDPHYSICSENVIRONMENT_H__
-#define __CCDPHYSICSENVIRONMENT_H__
-
-#include "PHY_IPhysicsEnvironment.h"
-#include "KX_KetsjiEngine.h"
-
-#include <vector>
-#include <set>
-#include <map>
-class CcdPhysicsController;
-class CcdGraphicController;
-#include "LinearMath/btVector3.h"
-#include "LinearMath/btTransform.h"
-
-
-
-
-class btTypedConstraint;
-class btSimulationIslandManager;
-class btCollisionDispatcher;
-class btDispatcher;
-//#include "btBroadphaseInterface.h"
-
-//switch on/off new vehicle support
-#define NEW_BULLET_VEHICLE_SUPPORT 1
-
-#include "BulletDynamics/ConstraintSolver/btContactSolverInfo.h"
-
-class WrapperVehicle;
-class btPersistentManifold;
-class btBroadphaseInterface;
-struct btDbvtBroadphase;
-class btOverlappingPairCache;
-class btIDebugDraw;
-class btDynamicsWorld;
-class PHY_IVehicle;
-class CcdOverlapFilterCallBack;
-class CcdShapeConstructionInfo;
-
-/** CcdPhysicsEnvironment is an experimental mainloop for physics simulation using optional continuous collision detection.
- * Physics Environment takes care of stepping the simulation and is a container for physics entities.
- * It stores rigidbodies,constraints, materials etc.
- * A derived class may be able to 'construct' entities by loading and/or converting
- */
-class CcdPhysicsEnvironment : public PHY_IPhysicsEnvironment
-{
- friend class CcdOverlapFilterCallBack;
- btVector3 m_gravity;
-
- // Removes the constraint and his references from the owner and the target.
- void RemoveConstraint(btTypedConstraint *con);
-
-protected:
- btIDebugDraw* m_debugDrawer;
-
- class btDefaultCollisionConfiguration* m_collisionConfiguration;
- class btBroadphaseInterface* m_broadphase; // broadphase for dynamic world
- // for culling only
- btOverlappingPairCache* m_cullingCache;
- struct btDbvtBroadphase* m_cullingTree; // broadphase for culling
-
- //solver iterations
- int m_numIterations;
-
- //timestep subdivisions
- int m_numTimeSubSteps;
-
-
- int m_ccdMode;
- int m_solverType;
- int m_profileTimings;
- bool m_enableSatCollisionDetection;
-
- float m_deactivationTime;
- float m_linearDeactivationThreshold;
- float m_angularDeactivationThreshold;
- float m_contactBreakingThreshold;
-
- void ProcessFhSprings(double curTime,float timeStep);
-
- public:
- CcdPhysicsEnvironment(bool useDbvtCulling, btDispatcher* dispatcher=0, btOverlappingPairCache* pairCache=0);
-
- virtual ~CcdPhysicsEnvironment();
-
- /////////////////////////////////////
- //PHY_IPhysicsEnvironment interface
- /////////////////////////////////////
-
- /// Perform an integration step of duration 'timeStep'.
-
- virtual void SetDebugDrawer(btIDebugDraw* debugDrawer);
-
- virtual void SetNumIterations(int numIter);
- virtual void SetNumTimeSubSteps(int numTimeSubSteps)
- {
- m_numTimeSubSteps = numTimeSubSteps;
- }
- virtual void SetDeactivationTime(float dTime);
- virtual void SetDeactivationLinearTreshold(float linTresh);
- virtual void SetDeactivationAngularTreshold(float angTresh);
- virtual void SetContactBreakingTreshold(float contactBreakingTreshold);
- virtual void SetCcdMode(int ccdMode);
- virtual void SetSolverType(int solverType);
- virtual void SetSolverSorConstant(float sor);
- virtual void SetSolverTau(float tau);
- virtual void SetSolverDamping(float damping);
- virtual void SetLinearAirDamping(float damping);
- virtual void SetUseEpa(bool epa);
-
- virtual int GetNumTimeSubSteps()
- {
- return m_numTimeSubSteps;
- }
-
- virtual void BeginFrame();
- virtual void EndFrame() {}
- /// Perform an integration step of duration 'timeStep'.
- virtual bool ProceedDeltaTime(double curTime,float timeStep,float interval);
-
- /**
- * Called by Bullet for every physical simulation (sub)tick.
- * Our constructor registers this callback to Bullet, which stores a pointer to 'this' in
- * the btDynamicsWorld::getWorldUserInfo() pointer.
- */
- static void StaticSimulationSubtickCallback(btDynamicsWorld *world, btScalar timeStep);
- void SimulationSubtickCallback(btScalar timeStep);
-
- virtual void DebugDrawWorld();
-// virtual bool proceedDeltaTimeOneStep(float timeStep);
-
- virtual void SetFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)
- {
- SetNumTimeSubSteps((int)(fixedTimeStep / KX_KetsjiEngine::GetTicRate()));
- }
- //returns 0.f if no fixed timestep is used
-
- virtual float GetFixedTimeStep() { return 0.f; }
-
- virtual void SetDebugMode(int debugMode);
- virtual int GetDebugMode()const;
-
- virtual void SetGravity(float x,float y,float z);
- virtual void GetGravity(MT_Vector3& grav);
-
-
- virtual int CreateConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
- float pivotX,float pivotY,float pivotZ,
- float axisX,float axisY,float axisZ,
- float axis1X=0,float axis1Y=0,float axis1Z=0,
- float axis2X=0,float axis2Y=0,float axis2Z=0,int flag=0
- );
-
-
- //Following the COLLADA physics specification for constraints
- virtual int CreateUniversalD6Constraint(
- class PHY_IPhysicsController* ctrlRef,class PHY_IPhysicsController* ctrlOther,
- btTransform& localAttachmentFrameRef,
- btTransform& localAttachmentOther,
- const btVector3& linearMinLimits,
- const btVector3& linearMaxLimits,
- const btVector3& angularMinLimits,
- const btVector3& angularMaxLimits,int flags
- );
-
-
- virtual void SetConstraintParam(int constraintId,int param,float value,float value1);
-
- virtual float GetConstraintParam(int constraintId,int param);
-
- virtual void RemoveConstraintById(int constraintid);
-
- virtual float getAppliedImpulse(int constraintid);
-
-
- virtual void CallbackTriggers();
-
-
-#ifdef NEW_BULLET_VEHICLE_SUPPORT
- //complex constraint for vehicles
- virtual PHY_IVehicle* GetVehicleConstraint(int constraintId);
-#else
- virtual class PHY_IVehicle* GetVehicleConstraint(int constraintId)
- {
- return 0;
- }
-#endif /* NEW_BULLET_VEHICLE_SUPPORT */
- // Character physics wrapper
- virtual PHY_ICharacter* GetCharacterController(class KX_GameObject* ob);
-
- btTypedConstraint* GetConstraintById(int constraintId);
-
- virtual PHY_IPhysicsController* RayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ);
- virtual bool CullingTest(PHY_CullingCallback callback, void* userData, MT_Vector4* planes, int nplanes, int occlusionRes, const int *viewport, float modelview[16], float projection[16]);
-
-
- //Methods for gamelogic collision/physics callbacks
- virtual void AddSensor(PHY_IPhysicsController* ctrl);
- virtual void RemoveSensor(PHY_IPhysicsController* ctrl);
- virtual void AddTouchCallback(int response_class, PHY_ResponseCallback callback, void *user);
- virtual bool RequestCollisionCallback(PHY_IPhysicsController* ctrl);
- virtual bool RemoveCollisionCallback(PHY_IPhysicsController* ctrl);
- //These two methods are used *solely* to create controllers for Near/Radar sensor! Don't use for anything else
- virtual PHY_IPhysicsController* CreateSphereController(float radius,const MT_Vector3& position);
- virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight);
-
-
- virtual int GetNumContactPoints();
-
- virtual void GetContactPoint(int i,float& hitX,float& hitY,float& hitZ,float& normalX,float& normalY,float& normalZ);
-
- //////////////////////
- //CcdPhysicsEnvironment interface
- ////////////////////////
-
- void AddCcdPhysicsController(CcdPhysicsController* ctrl);
-
- bool RemoveCcdPhysicsController(CcdPhysicsController* ctrl);
-
- void UpdateCcdPhysicsController(CcdPhysicsController* ctrl, btScalar newMass, int newCollisionFlags, short int newCollisionGroup, short int newCollisionMask);
-
- void RefreshCcdPhysicsController(CcdPhysicsController* ctrl);
-
- bool IsActiveCcdPhysicsController(CcdPhysicsController *ctrl);
-
- void AddCcdGraphicController(CcdGraphicController* ctrl);
-
- void RemoveCcdGraphicController(CcdGraphicController* ctrl);
-
- /**
- * Update all physics controllers shape which use the same shape construction info.
- * Call RecreateControllerShape on controllers which use the same shape
- * construction info that argument shapeInfo.
- * You need to call this function when the shape construction info changed.
- */
- void UpdateCcdPhysicsControllerShape(CcdShapeConstructionInfo *shapeInfo);
-
- btBroadphaseInterface* GetBroadphase();
- btDbvtBroadphase* GetCullingTree() { return m_cullingTree; }
-
- btDispatcher* GetDispatcher();
-
-
- bool IsSatCollisionDetectionEnabled() const
- {
- return m_enableSatCollisionDetection;
- }
-
- void EnableSatCollisionDetection(bool enableSat)
- {
- m_enableSatCollisionDetection = enableSat;
- }
-
-
- const btPersistentManifold* GetManifold(int index) const;
-
-
- void SyncMotionStates(float timeStep);
-
- class btSoftRigidDynamicsWorld* GetDynamicsWorld()
- {
- return m_dynamicsWorld;
- }
-
- class btConstraintSolver* GetConstraintSolver();
-
- void MergeEnvironment(PHY_IPhysicsEnvironment *other_env);
-
- static CcdPhysicsEnvironment *Create(struct Scene *blenderscene, bool visualizePhysics);
-
- virtual void ConvertObject(KX_GameObject* gameobj,
- RAS_MeshObject* meshobj,
- DerivedMesh* dm,
- KX_Scene* kxscene,
- PHY_ShapeProps* shapeprops,
- PHY_MaterialProps* smmaterial,
- PHY_IMotionState *motionstate,
- int activeLayerBitInfo,
- bool isCompoundChild,
- bool hasCompoundChildren);
-
- /* Set the rigid body joints constraints values for converted objects and replicated group instances. */
- virtual void SetupObjectConstraints(KX_GameObject *obj_src, KX_GameObject *obj_dest,
- bRigidBodyJointConstraint *dat);
-
- protected:
-
-
-
- std::set<CcdPhysicsController*> m_controllers;
-
- PHY_ResponseCallback m_triggerCallbacks[PHY_NUM_RESPONSE];
- void* m_triggerCallbacksUserPtrs[PHY_NUM_RESPONSE];
-
- std::vector<WrapperVehicle*> m_wrapperVehicles;
-
- //use explicit btSoftRigidDynamicsWorld/btDiscreteDynamicsWorld* so that we have access to
- //btDiscreteDynamicsWorld::addRigidBody(body,filter,group)
- //so that we can set the body collision filter/group at the time of creation
- //and not afterwards (breaks the collision system for radar/near sensor)
- //Ideally we would like to have access to this function from the btDynamicsWorld interface
- //class btDynamicsWorld* m_dynamicsWorld;
- class btSoftRigidDynamicsWorld* m_dynamicsWorld;
-
- class btConstraintSolver* m_solver;
-
- class btOverlappingPairCache* m_ownPairCache;
-
- class CcdOverlapFilterCallBack* m_filterCallback;
-
- class btGhostPairCallback* m_ghostPairCallback;
-
- class btDispatcher* m_ownDispatcher;
-
- bool m_scalingPropagated;
-
- virtual void ExportFile(const char* filename);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:CcdPhysicsEnvironment")
-#endif
-};
-
-#endif /* __CCDPHYSICSENVIRONMENT_H__ */
diff --git a/source/gameengine/Physics/Dummy/CMakeLists.txt b/source/gameengine/Physics/Dummy/CMakeLists.txt
deleted file mode 100644
index 692331f1ce4..00000000000
--- a/source/gameengine/Physics/Dummy/CMakeLists.txt
+++ /dev/null
@@ -1,41 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../common
-)
-
-set(INC_SYS
- ../../../../intern/moto/include
-)
-
-set(SRC
- DummyPhysicsEnvironment.cpp
-
- DummyPhysicsEnvironment.h
-)
-
-blender_add_lib(ge_phys_dummy "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
deleted file mode 100644
index 99db56bfcef..00000000000
--- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Physics/Dummy/DummyPhysicsEnvironment.cpp
- * \ingroup physdummy
- */
-
-
-#include <stddef.h>
-
-#include "DummyPhysicsEnvironment.h"
-#include "PHY_IMotionState.h"
-
-DummyPhysicsEnvironment::DummyPhysicsEnvironment()
-{
- // create physicsengine data
-}
-
-
-
-DummyPhysicsEnvironment::~DummyPhysicsEnvironment()
-{
- //destroy physicsengine data
-}
-
-void DummyPhysicsEnvironment::BeginFrame()
-{
- // beginning of logic frame: apply forces
-}
-
-void DummyPhysicsEnvironment::EndFrame()
-{
- // end of logic frame: clear forces
-}
-
-
-
-bool DummyPhysicsEnvironment::ProceedDeltaTime(double curTime,float timeStep,float interval)
-{
- //step physics simulation, typically perform
-
- //collision detection
- //solve constraints
- //integrate solution
- // return true if an update was done.
- return true;
-}
-void DummyPhysicsEnvironment::SetFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)
-{
-}
-
-float DummyPhysicsEnvironment::GetFixedTimeStep()
-{
- return 0.f;
-}
-
-int DummyPhysicsEnvironment::GetDebugMode() const
-{
- return 0;
-}
-
-void DummyPhysicsEnvironment::SetGravity(float x,float y,float z)
-{
-}
-
-void DummyPhysicsEnvironment::GetGravity(class MT_Vector3& grav)
-{
-}
-
-
-
-
-int DummyPhysicsEnvironment::CreateConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
- float pivotX,float pivotY,float pivotZ,float axisX,float axisY,float axisZ,
- float axis1X,float axis1Y,float axis1Z,
- float axis2X,float axis2Y,float axis2Z,int flag
- )
-{
-
- int constraintid = 0;
- return constraintid;
-
-}
-
-void DummyPhysicsEnvironment::RemoveConstraintById(int constraintid)
-{
- if (constraintid)
- {
- }
-}
-
-PHY_IPhysicsController* DummyPhysicsEnvironment::RayTest(PHY_IRayCastFilterCallback &filterCallback,float fromX,float fromY,float fromZ, float toX,float toY,float toZ)
-{
- //collision detection / raytesting
- return NULL;
-}
-
diff --git a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h b/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
deleted file mode 100644
index 3e9379dd60d..00000000000
--- a/source/gameengine/Physics/Dummy/DummyPhysicsEnvironment.h
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file DummyPhysicsEnvironment.h
- * \ingroup physdummy
- */
-
-#ifndef __DUMMYPHYSICSENVIRONMENT_H__
-#define __DUMMYPHYSICSENVIRONMENT_H__
-
-#include "PHY_IPhysicsEnvironment.h"
-#include "PHY_IMotionState.h"
-
-/**
- * DummyPhysicsEnvironment is an empty placeholder
- * Alternatives are ODE,Sumo and Dynamo PhysicsEnvironments
- * Use DummyPhysicsEnvironment as a base to integrate your own physics engine
- * Physics Environment takes care of stepping the simulation and is a container for physics entities (rigidbodies,constraints, materials etc.)
- *
- * A derived class may be able to 'construct' entities by loading and/or converting
- */
-class DummyPhysicsEnvironment : public PHY_IPhysicsEnvironment
-{
-
-public:
- DummyPhysicsEnvironment ();
- virtual ~DummyPhysicsEnvironment ();
- virtual void BeginFrame();
- virtual void EndFrame();
-// Perform an integration step of duration 'timeStep'.
- virtual bool ProceedDeltaTime(double curTime,float timeStep,float interval);
- virtual void SetFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep);
- virtual float GetFixedTimeStep();
-
- virtual int GetDebugMode() const;
-
- virtual void SetGravity(float x,float y,float z);
- virtual void GetGravity(class MT_Vector3& grav);
-
- virtual int CreateConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
- float pivotX,float pivotY,float pivotZ,
- float axisX,float axisY,float axisZ,
- float axis1X=0,float axis1Y=0,float axis1Z=0,
- float axis2X=0,float axis2Y=0,float axis2Z=0,int flag=0
- );
-
- virtual void RemoveConstraintById(int constraintid);
-
- //complex constraint for vehicles
- virtual PHY_IVehicle* GetVehicleConstraint(int constraintId)
- {
- return 0;
- }
-
- // Character physics wrapper
- virtual PHY_ICharacter* GetCharacterController(class KX_GameObject* ob)
- {
- return 0;
- }
-
- virtual PHY_IPhysicsController* RayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ);
- virtual bool CullingTest(PHY_CullingCallback callback, void* userData, class MT_Vector4* planes, int nplanes, int occlusionRes, const int *viewport, float modelview[16], float projection[16]) { return false; }
-
-
- //gamelogic callbacks
- virtual void AddSensor(PHY_IPhysicsController* ctrl) {}
- virtual void RemoveSensor(PHY_IPhysicsController* ctrl) {}
- virtual void AddTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)
- {
- }
- virtual bool RequestCollisionCallback(PHY_IPhysicsController* ctrl) { return false; }
- virtual bool RemoveCollisionCallback(PHY_IPhysicsController* ctrl) { return false;}
- virtual PHY_IPhysicsController* CreateSphereController(float radius,const class MT_Vector3& position) {return 0;}
- virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight) { return 0;}
-
- virtual void SetConstraintParam(int constraintId,int param,float value,float value1)
- {
- }
-
- virtual float GetConstraintParam(int constraintId,int param)
- {
- return 0.f;
- }
-
- virtual void MergeEnvironment(PHY_IPhysicsEnvironment *other_env)
- {
- // Dummy, nothing to do here
- }
-
- virtual void ConvertObject(KX_GameObject* gameobj,
- RAS_MeshObject* meshobj,
- DerivedMesh* dm,
- KX_Scene* kxscene,
- PHY_ShapeProps* shapeprops,
- PHY_MaterialProps* smmaterial,
- PHY_IMotionState *motionstate,
- int activeLayerBitInfo,
- bool isCompoundChild,
- bool hasCompoundChildren)
- {
- // All we need to do is handle the motionstate (we're supposed to own it)
- delete motionstate;
- }
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:DummyPhysicsEnvironment")
-#endif
-};
-
-#endif /* __DUMMYPHYSICSENVIRONMENT_H__ */
diff --git a/source/gameengine/Physics/common/PHY_DynamicTypes.h b/source/gameengine/Physics/common/PHY_DynamicTypes.h
deleted file mode 100644
index d10f48ad7a4..00000000000
--- a/source/gameengine/Physics/common/PHY_DynamicTypes.h
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
-Bullet Continuous Collision Detection and Physics Library
-Copyright (c) 2003-2006 Erwin Coumans http://continuousphysics.com/Bullet/
-
-This software is provided 'as-is', without any express or implied warranty.
-In no event will the authors be held liable for any damages arising from the use of this software.
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it freely,
-subject to the following restrictions:
-
-1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
-2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
-3. This notice may not be removed or altered from any source distribution.
-*/
-
-/** \file PHY_DynamicTypes.h
- * \ingroup phys
- */
-
-#ifndef __PHY_DYNAMICTYPES_H__
-#define __PHY_DYNAMICTYPES_H__
-
-#include "MT_Vector3.h"
-
-struct KX_ClientObjectInfo;
-
-enum
-{
- PHY_FH_RESPONSE,
- PHY_SENSOR_RESPONSE, /* Touch Sensors */
- PHY_CAMERA_RESPONSE, /* Visibility Culling */
- PHY_OBJECT_RESPONSE, /* Object Dynamic Geometry Response */
- PHY_STATIC_RESPONSE, /* Static Geometry Response */
- PHY_BROADPH_RESPONSE, /* broadphase Response */
-
- PHY_NUM_RESPONSE
-};
-
-typedef struct PHY_CollData {
- MT_Vector3 m_point1; /* Point in object1 in world coordinates */
- MT_Vector3 m_point2; /* Point in object2 in world coordinates */
- MT_Vector3 m_normal; /* point2 - point1 */
-} PHY_CollData;
-
-
-typedef bool (*PHY_ResponseCallback)(void *client_data,
- void *client_object1,
- void *client_object2,
- const PHY_CollData *coll_data);
-typedef void (*PHY_CullingCallback)(KX_ClientObjectInfo* info, void* param);
-
-
-/// PHY_PhysicsType enumerates all possible Physics Entities.
-/// It is mainly used to create/add Physics Objects
-
-typedef enum PHY_PhysicsType {
- PHY_CONVEX_RIGIDBODY=16386,
- PHY_CONCAVE_RIGIDBODY=16399,
- PHY_CONVEX_FIXEDBODY=16388,//'collision object'
- PHY_CONCAVE_FIXEDBODY=16401,
- PHY_CONVEX_KINEMATICBODY=16387,//
- PHY_CONCAVE_KINEMATICBODY=16400,
- PHY_CONVEX_PHANTOMBODY=16398,
- PHY_CONCAVE_PHANTOMBODY=16402
-} PHY_PhysicsType;
-
-/// PHY_ConstraintType enumerates all supported Constraint Types
-typedef enum PHY_ConstraintType {
- PHY_POINT2POINT_CONSTRAINT=1,
- PHY_LINEHINGE_CONSTRAINT=2,
- PHY_ANGULAR_CONSTRAINT = 3,//hinge without ball socket
- PHY_CONE_TWIST_CONSTRAINT = 4,
- PHY_VEHICLE_CONSTRAINT=11,//complex 'constraint' that turns a rigidbody into a vehicle
- PHY_GENERIC_6DOF_CONSTRAINT=12,//can leave any of the 6 degree of freedom 'free' or 'locked'
-
-} PHY_ConstraintType;
-
-typedef enum PHY_ShapeType {
- PHY_SHAPE_NONE,
- PHY_SHAPE_BOX,
- PHY_SHAPE_SPHERE,
- PHY_SHAPE_CYLINDER,
- PHY_SHAPE_CONE,
- PHY_SHAPE_CAPSULE,
- PHY_SHAPE_MESH,
- PHY_SHAPE_POLYTOPE,
- PHY_SHAPE_COMPOUND,
- PHY_SHAPE_PROXY
-} PHY_ShapeType;
-
-#endif /* __PHY_DYNAMICTYPES_H__ */
diff --git a/source/gameengine/Physics/common/PHY_ICharacter.h b/source/gameengine/Physics/common/PHY_ICharacter.h
deleted file mode 100644
index 1a924904b7d..00000000000
--- a/source/gameengine/Physics/common/PHY_ICharacter.h
+++ /dev/null
@@ -1,39 +0,0 @@
-
-/** \file PHY_ICharacter.h
- * \ingroup phys
- */
-
-#ifndef __PHY_ICHARACTER_H__
-#define __PHY_ICHARACTER_H__
-
-//PHY_ICharacter provides a generic interface for "character" controllers
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class PHY_ICharacter
-{
-public:
- virtual ~PHY_ICharacter() {};
-
- virtual void Jump()= 0;
- virtual bool OnGround()= 0;
-
- virtual float GetGravity()= 0;
- virtual void SetGravity(float gravity)= 0;
-
- virtual unsigned char GetMaxJumps() = 0;
- virtual void SetMaxJumps(unsigned char maxJumps) = 0;
-
- virtual unsigned char GetJumpCount() = 0;
-
- virtual void SetWalkDirection(const class MT_Vector3& dir)=0;
- virtual MT_Vector3 GetWalkDirection()=0;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_ICharacter")
-#endif
-};
-
-#endif //__PHY_ICHARACTER_H__
diff --git a/source/gameengine/Physics/common/PHY_IController.h b/source/gameengine/Physics/common/PHY_IController.h
deleted file mode 100644
index 741fae8d2ad..00000000000
--- a/source/gameengine/Physics/common/PHY_IController.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file PHY_IController.h
- * \ingroup phys
- */
-
-#ifndef __PHY_ICONTROLLER_H__
-#define __PHY_ICONTROLLER_H__
-
-#include "PHY_DynamicTypes.h"
-
-class PHY_IPhysicsEnvironment;
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/**
- * PHY_IController is the abstract simplified Interface to objects
- * controlled by the physics engine. This includes the physics objects
- * and the graphics object for view frustrum and occlusion culling.
- */
-class PHY_IController
-{
- public:
- virtual ~PHY_IController() {};
- // clientinfo for raycasts for example
- virtual void* GetNewClientInfo()=0;
- virtual void SetNewClientInfo(void* clientinfo)=0;
- virtual void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment *env)=0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IController")
-#endif
-};
-
-#endif /* __PHY_ICONTROLLER_H__ */
diff --git a/source/gameengine/Physics/common/PHY_IGraphicController.h b/source/gameengine/Physics/common/PHY_IGraphicController.h
deleted file mode 100644
index b047edd93eb..00000000000
--- a/source/gameengine/Physics/common/PHY_IGraphicController.h
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file PHY_IGraphicController.h
- * \ingroup phys
- */
-
-#ifndef __PHY_IGRAPHICCONTROLLER_H__
-#define __PHY_IGRAPHICCONTROLLER_H__
-
-#include "PHY_IController.h"
-
-
-/**
- * PHY_IPhysicsController is the abstract simplified Interface to a physical object.
- * It contains the IMotionState and IDeformableMesh Interfaces.
- */
-class PHY_IGraphicController : public PHY_IController
-{
- public:
- /**
- * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
- */
- virtual bool SetGraphicTransform()=0;
- virtual void Activate(bool active=true)=0;
- virtual void SetLocalAabb(const class MT_Vector3& aabbMin,const class MT_Vector3& aabbMax)=0;
- virtual void SetLocalAabb(const float* aabbMin,const float* aabbMax)=0;
-
- virtual PHY_IGraphicController* GetReplica(class PHY_IMotionState* motionstate) {return 0;}
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IController")
-#endif
-};
-
-#endif /* __PHY_IGRAPHICCONTROLLER_H__ */
diff --git a/source/gameengine/Physics/common/PHY_IMotionState.h b/source/gameengine/Physics/common/PHY_IMotionState.h
deleted file mode 100644
index e803d658713..00000000000
--- a/source/gameengine/Physics/common/PHY_IMotionState.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file PHY_IMotionState.h
- * \ingroup phys
- */
-
-#ifndef __PHY_IMOTIONSTATE_H__
-#define __PHY_IMOTIONSTATE_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/**
- * PHY_IMotionState is the Interface to explicitly synchronize the world transformation.
- * Default implementations for mayor graphics libraries like OpenGL and DirectX can be provided.
- */
-class PHY_IMotionState
-
-{
- public:
- virtual ~PHY_IMotionState() {};
-
- virtual void GetWorldPosition(float& posX,float& posY,float& posZ)=0;
- virtual void GetWorldScaling(float& scaleX,float& scaleY,float& scaleZ)=0;
- virtual void GetWorldOrientation(float& quatIma0,float& quatIma1,float& quatIma2,float& quatReal)=0;
- // ori = array 12 floats, [0..3] = first column + 0, [4..7] = second column, [8..11] = third column
- virtual void GetWorldOrientation(float* ori)=0;
- virtual void SetWorldOrientation(const float* ori)=0;
-
- virtual void SetWorldPosition(float posX,float posY,float posZ)=0;
- virtual void SetWorldOrientation(float quatIma0,float quatIma1,float quatIma2,float quatReal)=0;
-
-
- virtual void CalculateWorldTransformations()=0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IMotionState")
-#endif
-};
-
-#endif /* __PHY_IMOTIONSTATE_H__ */
diff --git a/source/gameengine/Physics/common/PHY_IPhysicsController.h b/source/gameengine/Physics/common/PHY_IPhysicsController.h
deleted file mode 100644
index 4c6e8c71ef7..00000000000
--- a/source/gameengine/Physics/common/PHY_IPhysicsController.h
+++ /dev/null
@@ -1,154 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file PHY_IPhysicsController.h
- * \ingroup phys
- */
-
-#ifndef __PHY_IPHYSICSCONTROLLER_H__
-#define __PHY_IPHYSICSCONTROLLER_H__
-
-#include <vector>
-#include "PHY_IController.h"
-
-class PHY_IMotionState;
-class PHY_IPhysicsEnvironment;
-
-class MT_Vector3;
-class MT_Point3;
-class MT_Matrix3x3;
-
-class KX_GameObject;
-class RAS_MeshObject;
-
-/**
- * PHY_IPhysicsController is the abstract simplified Interface to a physical object.
- * It contains the IMotionState and IDeformableMesh Interfaces.
- */
-class PHY_IPhysicsController : public PHY_IController
-{
-
- public:
- virtual ~PHY_IPhysicsController() {};
- /**
- * SynchronizeMotionStates ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
- */
- virtual bool SynchronizeMotionStates(float time)=0;
- /**
- * WriteMotionStateToDynamics ynchronizes dynas, kinematic and deformable entities (and do 'late binding')
- */
-
- virtual void WriteMotionStateToDynamics(bool nondynaonly)=0;
- virtual void WriteDynamicsToMotionState()=0;
- virtual class PHY_IMotionState* GetMotionState() = 0;
- // controller replication
- virtual void PostProcessReplica(class PHY_IMotionState* motionstate,class PHY_IPhysicsController* parentctrl)=0;
- virtual void SetPhysicsEnvironment(class PHY_IPhysicsEnvironment *env)=0;
-
- // kinematic methods
- virtual void RelativeTranslate(const MT_Vector3& dloc,bool local)=0;
- virtual void RelativeRotate(const MT_Matrix3x3&,bool local)=0;
- virtual MT_Matrix3x3 GetOrientation()=0;
- virtual void SetOrientation(const MT_Matrix3x3& orn)=0;
- virtual void SetPosition(const MT_Vector3& pos)=0;
- virtual void GetPosition(MT_Vector3& pos) const=0;
- virtual void SetScaling(const MT_Vector3& scale)=0;
- virtual void SetTransform()=0;
-
- virtual MT_Scalar GetMass()=0;
- virtual void SetMass(MT_Scalar newmass)=0;
-
- // physics methods
- virtual void ApplyImpulse(const MT_Point3& attach, const MT_Vector3& impulse,bool local)=0;
- virtual void ApplyTorque(const MT_Vector3& torque,bool local)=0;
- virtual void ApplyForce(const MT_Vector3& force,bool local)=0;
- virtual void SetAngularVelocity(const MT_Vector3& ang_vel,bool local)=0;
- virtual void SetLinearVelocity(const MT_Vector3& lin_vel,bool local)=0;
- virtual void ResolveCombinedVelocities(float linvelX,float linvelY,float linvelZ,float angVelX,float angVelY,float angVelZ) = 0;
-
- virtual float GetLinearDamping() const=0;
- virtual float GetAngularDamping() const=0;
- virtual void SetLinearDamping(float damping)=0;
- virtual void SetAngularDamping(float damping)=0;
- virtual void SetDamping(float linear, float angular)=0;
-
- virtual void RefreshCollisions() = 0;
- virtual void SuspendDynamics(bool ghost=false)=0;
- virtual void RestoreDynamics()=0;
-
- virtual void SetActive(bool active)=0;
-
- // reading out information from physics
- virtual MT_Vector3 GetLinearVelocity()=0;
- virtual MT_Vector3 GetAngularVelocity()=0;
- virtual MT_Vector3 GetVelocity(const MT_Point3& pos)=0;
- virtual MT_Vector3 GetLocalInertia()=0;
-
- // dyna's that are rigidbody are free in orientation, dyna's with non-rigidbody are restricted
- virtual void SetRigidBody(bool rigid)=0;
-
- virtual PHY_IPhysicsController* GetReplica() {return 0;}
- virtual PHY_IPhysicsController* GetReplicaForSensors() {return 0;}
-
- virtual void CalcXform() =0;
- virtual void SetMargin(float margin) =0;
- virtual float GetMargin() const=0;
- virtual float GetRadius() const=0;
- virtual void SetRadius(float margin) = 0;
-
- virtual float GetLinVelocityMin() const=0;
- virtual void SetLinVelocityMin(float val) = 0;
- virtual float GetLinVelocityMax() const=0;
- virtual void SetLinVelocityMax(float val) = 0;
-
- virtual void SetAngularVelocityMin(float val) = 0;
- virtual float GetAngularVelocityMin() const = 0;
- virtual void SetAngularVelocityMax(float val) = 0;
- virtual float GetAngularVelocityMax() const = 0;
-
- MT_Vector3 GetWorldPosition(MT_Vector3& localpos);
-
- // Shape control
- virtual void AddCompoundChild(PHY_IPhysicsController* child) = 0;
- virtual void RemoveCompoundChild(PHY_IPhysicsController* child) = 0;
-
-
- virtual bool IsDynamic() = 0;
- virtual bool IsCompound() = 0;
- virtual bool IsSuspended() const = 0;
-
- virtual bool ReinstancePhysicsShape(KX_GameObject *from_gameobj, RAS_MeshObject* from_meshobj) = 0;
-
- /* Method to replicate rigid body joint contraints for group instances. */
- virtual void ReplicateConstraints(KX_GameObject *gameobj, std::vector<KX_GameObject*> constobj) = 0;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IPhysicsController")
-#endif
-};
-
-#endif /* __PHY_IPHYSICSCONTROLLER_H__ */
diff --git a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h b/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
deleted file mode 100644
index 72ec7b1edd0..00000000000
--- a/source/gameengine/Physics/common/PHY_IPhysicsEnvironment.h
+++ /dev/null
@@ -1,226 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file PHY_IPhysicsEnvironment.h
- * \ingroup phys
- */
-
-#ifndef __PHY_IPHYSICSENVIRONMENT_H__
-#define __PHY_IPHYSICSENVIRONMENT_H__
-
-#include "PHY_DynamicTypes.h"
-#include "MT_Vector2.h"
-#include "MT_Vector3.h"
-#include "MT_Vector4.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class PHY_IVehicle;
-class PHY_ICharacter;
-class RAS_MeshObject;
-class PHY_IPhysicsController;
-
-
-class RAS_MeshObject;
-struct DerivedMesh;
-class KX_GameObject;
-class KX_Scene;
-
-struct PHY_ShapeProps;
-struct PHY_MaterialProps;
-class PHY_IMotionState;
-struct bRigidBodyJointConstraint;
-
-/**
- * pass back information from rayTest
- */
-struct PHY_RayCastResult
-{
- PHY_IPhysicsController* m_controller;
- MT_Vector3 m_hitPoint;
- MT_Vector3 m_hitNormal;
- const RAS_MeshObject* m_meshObject; // !=NULL for mesh object (only for Bullet controllers)
- int m_polygon; // index of the polygon hit by the ray,
- // only if m_meshObject != NULL
- int m_hitUVOK; // !=0 if UV coordinate in m_hitUV is valid
- MT_Vector2 m_hitUV; // UV coordinates of hit point
-};
-
-/**
- * This class replaces the ignoreController parameter of rayTest function.
- * It allows more sophisticated filtering on the physics controller before computing the ray intersection to save CPU.
- * It is only used to its full extend by the Ccd physics environment (Bullet).
- */
-class PHY_IRayCastFilterCallback
-{
-public:
- PHY_IPhysicsController* m_ignoreController;
- bool m_faceNormal;
- bool m_faceUV;
-
- virtual ~PHY_IRayCastFilterCallback()
- {
- }
-
- virtual bool needBroadphaseRayCast(PHY_IPhysicsController* controller)
- {
- return true;
- }
-
- virtual void reportHit(PHY_RayCastResult* result) = 0;
-
- PHY_IRayCastFilterCallback(PHY_IPhysicsController* ignoreController, bool faceNormal=false, bool faceUV=false)
- :m_ignoreController(ignoreController),
- m_faceNormal(faceNormal),
- m_faceUV(faceUV)
- {
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IRayCastFilterCallback")
-#endif
-};
-
-/**
- * Physics Environment takes care of stepping the simulation and is a container for physics entities
- * (rigidbodies,constraints, materials etc.)
- * A derived class may be able to 'construct' entities by loading and/or converting
- */
-class PHY_IPhysicsEnvironment
-{
- public:
- virtual ~PHY_IPhysicsEnvironment() {}
- virtual void BeginFrame() = 0;
- virtual void EndFrame() = 0;
- /// Perform an integration step of duration 'timeStep'.
- virtual bool ProceedDeltaTime(double curTime,float timeStep,float interval)=0;
- ///draw debug lines (make sure to call this during the render phase, otherwise lines are not drawn properly)
- virtual void DebugDrawWorld() {}
- virtual void SetFixedTimeStep(bool useFixedTimeStep,float fixedTimeStep)=0;
- //returns 0.f if no fixed timestep is used
- virtual float GetFixedTimeStep()=0;
-
- ///getDebugMode return the actual debug visualization state
- virtual int GetDebugMode()const=0;
- ///setDebugMode is used to support several ways of debug lines, contact point visualization
- virtual void SetDebugMode(int debugMode) {}
- ///setNumIterations set the number of iterations for iterative solvers
- virtual void SetNumIterations(int numIter) {}
- ///setNumTimeSubSteps set the number of divisions of the timestep. Tradeoff quality versus performance.
- virtual void SetNumTimeSubSteps(int numTimeSubSteps) {}
- virtual int GetNumTimeSubSteps() {return 0; }
- ///setDeactivationTime sets the minimum time that an objects has to stay within the velocity tresholds until it gets fully deactivated
- virtual void SetDeactivationTime(float dTime) {}
- ///setDeactivationLinearTreshold sets the linear velocity treshold, see setDeactivationTime
- virtual void SetDeactivationLinearTreshold(float linTresh) {}
- ///setDeactivationAngularTreshold sets the angular velocity treshold, see setDeactivationTime
- virtual void SetDeactivationAngularTreshold(float angTresh) {}
- ///setContactBreakingTreshold sets tresholds to do with contact point management
- virtual void SetContactBreakingTreshold(float contactBreakingTreshold) {}
- ///continuous collision detection mode, very experimental for Bullet
- virtual void SetCcdMode(int ccdMode) {}
- ///successive overrelaxation constant, in case PSOR is used, values in between 1 and 2 guarantee converging behavior
- virtual void SetSolverSorConstant(float sor) {}
- ///setSolverType, internal setting, chooses solvertype, PSOR, Dantzig, impulse based, penalty based
- virtual void SetSolverType(int solverType) {}
- ///setTau sets the spring constant of a penalty based solver
- virtual void SetSolverTau(float tau) {}
- ///setDamping sets the damper constant of a penalty based solver
- virtual void SetSolverDamping(float damping) {}
- ///linear air damping for rigidbodies
- virtual void SetLinearAirDamping(float damping) {}
- /// penetrationdepth setting
- virtual void SetUseEpa(bool epa) {}
-
- virtual void SetGravity(float x,float y,float z)=0;
- virtual void GetGravity(MT_Vector3& grav) = 0;
-
- virtual int CreateConstraint(class PHY_IPhysicsController* ctrl,class PHY_IPhysicsController* ctrl2,PHY_ConstraintType type,
- float pivotX,float pivotY,float pivotZ,
- float axis0X,float axis0Y,float axis0Z,
- float axis1X=0,float axis1Y=0,float axis1Z=0,
- float axis2X=0,float axis2Y=0,float axis2Z=0,int flag=0
- )=0;
- virtual void RemoveConstraintById(int constraintid) = 0;
- virtual float GetAppliedImpulse(int constraintid) { return 0.0f; }
-
-
- //complex constraint for vehicles
- virtual PHY_IVehicle* GetVehicleConstraint(int constraintId) =0;
-
- // Character physics wrapper
- virtual PHY_ICharacter* GetCharacterController(class KX_GameObject* ob) =0;
-
- virtual PHY_IPhysicsController* RayTest(PHY_IRayCastFilterCallback &filterCallback, float fromX,float fromY,float fromZ, float toX,float toY,float toZ)=0;
-
- //culling based on physical broad phase
- // the plane number must be set as follow: near, far, left, right, top, botton
- // the near plane must be the first one and must always be present, it is used to get the direction of the view
- virtual bool CullingTest(PHY_CullingCallback callback, void *userData, MT_Vector4* planeNormals, int planeNumber, int occlusionRes, const int *viewport, float modelview[16], float projection[16]) = 0;
-
- //Methods for gamelogic collision/physics callbacks
- //todo:
- virtual void AddSensor(PHY_IPhysicsController* ctrl)=0;
- virtual void RemoveSensor(PHY_IPhysicsController* ctrl)=0;
- virtual void AddTouchCallback(int response_class, PHY_ResponseCallback callback, void *user)=0;
- virtual bool RequestCollisionCallback(PHY_IPhysicsController* ctrl)=0;
- virtual bool RemoveCollisionCallback(PHY_IPhysicsController* ctrl)=0;
- //These two methods are *solely* used to create controllers for sensor! Don't use for anything else
- virtual PHY_IPhysicsController* CreateSphereController(float radius,const MT_Vector3& position) =0;
- virtual PHY_IPhysicsController* CreateConeController(float coneradius,float coneheight)=0;
-
- virtual void SetConstraintParam(int constraintId,int param,float value,float value1) = 0;
- virtual float GetConstraintParam(int constraintId,int param) = 0;
-
- virtual void ExportFile(const char* filename) {};
-
- virtual void MergeEnvironment(PHY_IPhysicsEnvironment *other_env) = 0;
-
- virtual void ConvertObject(KX_GameObject* gameobj,
- RAS_MeshObject* meshobj,
- DerivedMesh* dm,
- KX_Scene* kxscene,
- PHY_ShapeProps* shapeprops,
- PHY_MaterialProps* smmaterial,
- PHY_IMotionState *motionstate,
- int activeLayerBitInfo,
- bool isCompoundChild,
- bool hasCompoundChildren) = 0;
-
- /* Set the rigid body joints constraints values for converted objects and replicated group instances. */
- virtual void SetupObjectConstraints(KX_GameObject *obj_src, KX_GameObject *obj_dest,
- bRigidBodyJointConstraint *dat) {}
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IPhysicsEnvironment")
-#endif
-};
-
-#endif /* __PHY_IPHYSICSENVIRONMENT_H__ */
diff --git a/source/gameengine/Physics/common/PHY_IVehicle.h b/source/gameengine/Physics/common/PHY_IVehicle.h
deleted file mode 100644
index 7e4a49e923e..00000000000
--- a/source/gameengine/Physics/common/PHY_IVehicle.h
+++ /dev/null
@@ -1,69 +0,0 @@
-
-/** \file PHY_IVehicle.h
- * \ingroup phys
- */
-
-#ifndef __PHY_IVEHICLE_H__
-#define __PHY_IVEHICLE_H__
-
-//PHY_IVehicle provides a generic interface for (raycast based) vehicles. Mostly targetting 4 wheel cars and 2 wheel motorbikes.
-
-class PHY_IMotionState;
-#include "PHY_DynamicTypes.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class PHY_IVehicle
-{
-public:
- virtual ~PHY_IVehicle() {};
-
- virtual void AddWheel(
- PHY_IMotionState* motionState,
- MT_Vector3 connectionPoint,
- MT_Vector3 downDirection,
- MT_Vector3 axleDirection,
- float suspensionRestLength,
- float wheelRadius,
- bool hasSteering
- ) = 0;
-
-
- virtual int GetNumWheels() const = 0;
-
- virtual void GetWheelPosition(int wheelIndex,float& posX,float& posY,float& posZ) const = 0;
- virtual void GetWheelOrientationQuaternion(int wheelIndex,float& quatX,float& quatY,float& quatZ,float& quatW) const = 0;
- virtual float GetWheelRotation(int wheelIndex) const = 0;
-
- virtual int GetUserConstraintId() const =0;
- virtual int GetUserConstraintType() const =0;
-
- //some basic steering/braking/tuning/balancing (bikes)
-
- virtual void SetSteeringValue(float steering,int wheelIndex) = 0;
-
- virtual void ApplyEngineForce(float force,int wheelIndex) = 0;
-
- virtual void ApplyBraking(float braking,int wheelIndex) = 0;
-
- virtual void SetWheelFriction(float friction,int wheelIndex) = 0;
-
- virtual void SetSuspensionStiffness(float suspensionStiffness,int wheelIndex) = 0;
-
- virtual void SetSuspensionDamping(float suspensionStiffness,int wheelIndex) = 0;
-
- virtual void SetSuspensionCompression(float suspensionStiffness,int wheelIndex) = 0;
-
- virtual void SetRollInfluence(float rollInfluence,int wheelIndex) = 0;
-
- virtual void SetCoordinateSystem(int rightIndex,int upIndex,int forwardIndex) =0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:PHY_IVehicle")
-#endif
-};
-
-#endif /* __PHY_IVEHICLE_H__ */
diff --git a/source/gameengine/Physics/common/PHY_Pro.h b/source/gameengine/Physics/common/PHY_Pro.h
deleted file mode 100644
index bfe574e73cb..00000000000
--- a/source/gameengine/Physics/common/PHY_Pro.h
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file PHY_Pro.h
- * \ingroup phys
- */
-
-#ifndef __PHY_PRO_H__
-#define __PHY_PRO_H__
-
-#include <MT_Scalar.h>
-
-// Properties of dynamic objects
-struct PHY_ShapeProps {
- MT_Scalar m_mass; // Total mass
- MT_Scalar m_inertia; // Inertia, should be a tensor some time
- MT_Scalar m_lin_drag; // Linear drag (air, water) 0 = concrete, 1 = vacuum, inverted and called dampening in blenders UI
- MT_Scalar m_ang_drag; // Angular drag, inverted and called dampening in blenders UI
- MT_Scalar m_friction_scaling[3]; // Scaling for anisotropic friction. Component in range [0, 1]
- MT_Scalar m_clamp_vel_min; // Clamp the minimum velocity, this ensures an object moves at a minimum speed unless its stationary
- MT_Scalar m_clamp_vel_max; // Clamp max velocity
- MT_Scalar m_clamp_angvel_min; // Clamp the minimum angular velocity.
- MT_Scalar m_clamp_angvel_max; // Clamp the maximum angular velocity.
- bool m_do_anisotropic; // Should I do anisotropic friction?
- bool m_do_fh; // Should the object have a linear Fh spring?
- bool m_do_rot_fh; // Should the object have an angular Fh spring?
- MT_Scalar m_step_height; // Max height of climbable steps (Character)
- MT_Scalar m_jump_speed; // Velocity of jumps (Character)
- MT_Scalar m_fall_speed; // Max velocity of falling (Character)
- unsigned char m_max_jumps; // Max ammount of jumps (Character)
-};
-
-
-// Properties of collidable objects (non-ghost objects)
-struct PHY_MaterialProps {
- MT_Scalar m_restitution; // restitution of energie after a collision 0 = inelastic, 1 = elastic
- MT_Scalar m_friction; // Coulomb friction (= ratio between the normal en maximum friction force)
- MT_Scalar m_fh_spring; // Spring constant (both linear and angular)
- MT_Scalar m_fh_damping; // Damping factor (linear and angular) in range [0, 1]
- MT_Scalar m_fh_distance; // The range above the surface where Fh is active.
- bool m_fh_normal; // Should the object slide off slopes?
-};
-
-#endif /* __PHY_PRO_H__ */
diff --git a/source/gameengine/Rasterizer/CMakeLists.txt b/source/gameengine/Rasterizer/CMakeLists.txt
deleted file mode 100644
index fc7dc90e03b..00000000000
--- a/source/gameengine/Rasterizer/CMakeLists.txt
+++ /dev/null
@@ -1,92 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../Expressions
- ../Ketsji
- ../SceneGraph
- ../../blender/makesdna
- ../../blender/blenlib
- ../../blender/blenkernel
- ../../blender/gpu
- ../../blender/imbuf
- ../../../intern/container
- ../../../intern/glew-mx
- ../../../intern/guardedalloc
- ../../../intern/string
-)
-
-set(INC_SYS
- ../../../intern/moto/include
- ${GLEW_INCLUDE_PATH}
- ${PYTHON_INCLUDE_DIRS}
-)
-
-set(SRC
- RAS_2DFilterManager.cpp
- RAS_BucketManager.cpp
- RAS_FramingManager.cpp
- RAS_IPolygonMaterial.cpp
- RAS_MaterialBucket.cpp
- RAS_MeshObject.cpp
- RAS_Polygon.cpp
- RAS_TexVert.cpp
- RAS_texmatrix.cpp
- RAS_ICanvas.cpp
-
- RAS_2DFilterManager.h
- RAS_BucketManager.h
- RAS_CameraData.h
- RAS_Deformer.h
- RAS_FramingManager.h
- RAS_ICanvas.h
- RAS_IPolygonMaterial.h
- RAS_IRasterizer.h
- RAS_ILightObject.h
- RAS_IOffScreen.h
- RAS_ISync.h
- RAS_MaterialBucket.h
- RAS_MeshObject.h
- RAS_ObjectColor.h
- RAS_Polygon.h
- RAS_Rect.h
- RAS_TexMatrix.h
- RAS_TexVert.h
- RAS_OpenGLFilters/RAS_Blur2DFilter.h
- RAS_OpenGLFilters/RAS_Dilation2DFilter.h
- RAS_OpenGLFilters/RAS_Erosion2DFilter.h
- RAS_OpenGLFilters/RAS_GrayScale2DFilter.h
- RAS_OpenGLFilters/RAS_Invert2DFilter.h
- RAS_OpenGLFilters/RAS_Laplacian2DFilter.h
- RAS_OpenGLFilters/RAS_Prewitt2DFilter.h
- RAS_OpenGLFilters/RAS_Sepia2DFilter.h
- RAS_OpenGLFilters/RAS_Sharpen2DFilter.h
- RAS_OpenGLFilters/RAS_Sobel2DFilter.h
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-blender_add_lib(ge_rasterizer "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp b/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
deleted file mode 100644
index f379e2eb486..00000000000
--- a/source/gameengine/Rasterizer/RAS_2DFilterManager.cpp
+++ /dev/null
@@ -1,562 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_2DFilterManager.cpp
- * \ingroup bgerast
- */
-
-#include "BLI_utildefines.h"
-
-#include "RAS_OpenGLFilters/RAS_Blur2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Sharpen2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Dilation2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Erosion2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Laplacian2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Sobel2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Prewitt2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_GrayScale2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Sepia2DFilter.h"
-#include "RAS_OpenGLFilters/RAS_Invert2DFilter.h"
-
-#include "STR_String.h"
-#include "RAS_ICanvas.h"
-#include "RAS_Rect.h"
-#include "RAS_2DFilterManager.h"
-#include <iostream>
-
-#include "GPU_glew.h"
-
-#include <stdio.h>
-
-#include "EXP_Value.h"
-
-RAS_2DFilterManager::RAS_2DFilterManager():
-texturewidth(-1), textureheight(-1),
-/* numberoffilters(0), */ /* UNUSED */ need_tex_update(true)
-{
- isshadersupported = GLEW_ARB_shader_objects &&
- GLEW_ARB_fragment_shader && GLEW_ARB_multitexture;
-
- /* used to return before 2.49 but need to initialize values so don't */
- if (!isshadersupported)
- std::cout<<"shaders not supported!" << std::endl;
-
- int passindex;
- for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
- {
- m_filters[passindex] = 0;
- m_enabled[passindex] = 0;
- texflag[passindex] = 0;
- m_gameObjects[passindex] = NULL;
- }
- texname[0] = texname[1] = texname[2] = -1;
- errorprinted= false;
-}
-
-RAS_2DFilterManager::~RAS_2DFilterManager()
-{
- FreeTextures();
-
- for (int passindex = 0; passindex < MAX_RENDER_PASS; passindex++) {
- if (m_filters[passindex]) {
- glDeleteObjectARB(m_filters[passindex]);
- }
- }
-}
-
-void RAS_2DFilterManager::PrintShaderErrors(unsigned int shader, const char *task, const char *code)
-{
- GLcharARB log[5000];
- GLsizei length = 0;
- const char *c, *pos, *end;
- int line = 1;
-
- if (errorprinted)
- return;
-
- errorprinted= true;
-
- glGetInfoLogARB(shader, sizeof(log), &length, log);
- end = code + strlen(code);
-
- printf("2D Filter GLSL Shader: %s error:\n", task);
-
- c = code;
- while ((c < end) && (pos = strchr(c, '\n'))) {
- printf("%2d ", line);
- fwrite(c, (pos+1)-c, 1, stdout);
- c = pos+1;
- line++;
- }
-
- puts(c);
- puts(log);
- puts("\n");
-}
-
-unsigned int RAS_2DFilterManager::CreateShaderProgram(const char* shadersource)
-{
- GLuint program = 0;
- GLuint fShader = glCreateShaderObjectARB(GL_FRAGMENT_SHADER);
- GLint success;
-
- glShaderSourceARB(fShader, 1, (const char**)&shadersource, NULL);
-
- glCompileShaderARB(fShader);
-
-
- glGetObjectParameterivARB(fShader, GL_COMPILE_STATUS, &success);
- if (!success) {
- /*Shader Comile Error*/
- PrintShaderErrors(fShader, "compile", shadersource);
- goto fail;
- }
-
- program = glCreateProgramObjectARB();
- glAttachObjectARB(program, fShader);
-
- glLinkProgramARB(program);
- glGetObjectParameterivARB(program, GL_LINK_STATUS, &success);
- if (!success) {
- /*Program Link Error*/
- PrintShaderErrors(fShader, "link", shadersource);
- goto fail;
- }
-
- glValidateProgramARB(program);
- glGetObjectParameterivARB(program, GL_VALIDATE_STATUS, &success);
- if (!success) {
- /*Program Validation Error*/
- PrintShaderErrors(fShader, "validate", shadersource);
- goto fail;
- }
-
- /* owned by 'program' */
- if (fShader) {
- glDeleteObjectARB(fShader);
- }
-
- return program;
-
-
-fail:
- if (fShader) {
- glDeleteObjectARB(fShader);
- }
-
- if (program) {
- glDeleteObjectARB(program);
- }
- return 0;
-}
-
-unsigned int RAS_2DFilterManager::CreateShaderProgram(int filtermode)
-{
- switch (filtermode) {
- case RAS_2DFILTER_BLUR:
- return CreateShaderProgram(BlurFragmentShader);
- case RAS_2DFILTER_SHARPEN:
- return CreateShaderProgram(SharpenFragmentShader);
- case RAS_2DFILTER_DILATION:
- return CreateShaderProgram(DilationFragmentShader);
- case RAS_2DFILTER_EROSION:
- return CreateShaderProgram(ErosionFragmentShader);
- case RAS_2DFILTER_LAPLACIAN:
- return CreateShaderProgram(LaplacionFragmentShader);
- case RAS_2DFILTER_SOBEL:
- return CreateShaderProgram(SobelFragmentShader);
- case RAS_2DFILTER_PREWITT:
- return CreateShaderProgram(PrewittFragmentShader);
- case RAS_2DFILTER_GRAYSCALE:
- return CreateShaderProgram(GrayScaleFragmentShader);
- case RAS_2DFILTER_SEPIA:
- return CreateShaderProgram(SepiaFragmentShader);
- case RAS_2DFILTER_INVERT:
- return CreateShaderProgram(InvertFragmentShader);
- }
- return 0;
-}
-
-void RAS_2DFilterManager::AnalyseShader(int passindex, vector<STR_String>& propNames)
-{
- texflag[passindex] = 0;
- if (glGetUniformLocationARB(m_filters[passindex], "bgl_DepthTexture") != -1)
- {
- if (GLEW_ARB_depth_texture)
- texflag[passindex] |= 0x1;
- }
- if (glGetUniformLocationARB(m_filters[passindex], "bgl_LuminanceTexture") != -1)
- {
- texflag[passindex] |= 0x2;
- }
-
- if (m_gameObjects[passindex])
- {
- int objProperties = propNames.size();
- int i;
- for (i=0; i<objProperties; i++)
- if (glGetUniformLocationARB(m_filters[passindex], propNames[i]) != -1)
- m_properties[passindex].push_back(propNames[i]);
- }
-}
-
-void RAS_2DFilterManager::StartShaderProgram(int passindex)
-{
- GLint uniformLoc;
- glUseProgramObjectARB(m_filters[passindex]);
- uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_RenderedTexture");
- glActiveTextureARB(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, texname[0]);
-
- if (uniformLoc != -1)
- {
- glUniform1iARB(uniformLoc, 0);
- }
-
- /* send depth texture to glsl program if it needs */
- if (texflag[passindex] & 0x1) {
- uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_DepthTexture");
- glActiveTextureARB(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, texname[1]);
-
- if (uniformLoc != -1)
- {
- glUniform1iARB(uniformLoc, 1);
- }
- }
-
- /* send luminance texture to glsl program if it needs */
- if (texflag[passindex] & 0x2) {
- uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_LuminanceTexture");
- glActiveTextureARB(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, texname[2]);
-
- if (uniformLoc != -1)
- {
- glUniform1iARB(uniformLoc, 2);
- }
- }
-
- uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_TextureCoordinateOffset");
- if (uniformLoc != -1)
- {
- glUniform2fvARB(uniformLoc, 9, textureoffsets);
- }
- uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_RenderedTextureWidth");
- if (uniformLoc != -1)
- {
- glUniform1fARB(uniformLoc,texturewidth);
- }
- uniformLoc = glGetUniformLocationARB(m_filters[passindex], "bgl_RenderedTextureHeight");
- if (uniformLoc != -1)
- {
- glUniform1fARB(uniformLoc,textureheight);
- }
-
- int i, objProperties = m_properties[passindex].size();
- for (i=0; i<objProperties; i++)
- {
- uniformLoc = glGetUniformLocationARB(m_filters[passindex], m_properties[passindex][i]);
-
- if (uniformLoc == -1)
- continue;
-
- CValue *property = ((CValue *)m_gameObjects[passindex])->GetProperty(m_properties[passindex][i]);
-
- if (!property)
- continue;
-
- switch (property->GetValueType()) {
- case VALUE_INT_TYPE:
- glUniform1iARB(uniformLoc, property->GetNumber());
- break;
- case VALUE_FLOAT_TYPE:
- glUniform1fARB(uniformLoc, property->GetNumber());
- break;
- default:
- break;
- }
- }
-}
-
-void RAS_2DFilterManager::EndShaderProgram()
-{
- glUseProgramObjectARB(0);
-}
-
-void RAS_2DFilterManager::FreeTextures()
-{
- if (texname[0]!=(unsigned int)-1)
- glDeleteTextures(1, (GLuint*)&texname[0]);
- if (texname[1]!=(unsigned int)-1)
- glDeleteTextures(1, (GLuint*)&texname[1]);
- if (texname[2]!=(unsigned int)-1)
- glDeleteTextures(1, (GLuint*)&texname[2]);
-}
-
-void RAS_2DFilterManager::SetupTextures(bool depth, bool luminance)
-{
- FreeTextures();
-
- glGenTextures(1, (GLuint*)&texname[0]);
- glBindTexture(GL_TEXTURE_2D, texname[0]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, texturewidth, textureheight, 0, GL_RGBA,
- GL_UNSIGNED_BYTE, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
-
- if (depth) {
- glGenTextures(1, (GLuint*)&texname[1]);
- glBindTexture(GL_TEXTURE_2D, texname[1]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, texturewidth,textureheight,
- 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE,NULL);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE,
- GL_NONE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- }
-
- if (luminance) {
- glGenTextures(1, (GLuint*)&texname[2]);
- glBindTexture(GL_TEXTURE_2D, texname[2]);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE16, texturewidth, textureheight,
- 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, 0);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- }
-}
-
-void RAS_2DFilterManager::UpdateOffsetMatrix(RAS_ICanvas* canvas)
-{
- /* RAS_Rect canvas_rect = canvas->GetWindowArea(); */ /* UNUSED */
- texturewidth = canvas->GetWidth()+1;
- textureheight = canvas->GetHeight()+1;
- GLint i,j;
-
- if (!GL_ARB_texture_non_power_of_two)
- {
- i = 0;
- while ((1 << i) <= texturewidth)
- i++;
- texturewidth = (1 << (i));
-
- // Now for height
- i = 0;
- while ((1 << i) <= textureheight)
- i++;
- textureheight = (1 << (i));
- }
-
- GLfloat xInc = 1.0f / (GLfloat)texturewidth;
- GLfloat yInc = 1.0f / (GLfloat)textureheight;
-
- for (i = 0; i < 3; i++)
- {
- for (j = 0; j < 3; j++)
- {
- textureoffsets[(((i*3)+j)*2)+0] = (-1.0f * xInc) + ((GLfloat)i * xInc);
- textureoffsets[(((i*3)+j)*2)+1] = (-1.0f * yInc) + ((GLfloat)j * yInc);
- }
- }
-}
-
-void RAS_2DFilterManager::UpdateCanvasTextureCoord(const int viewport[4])
-{
- /*
- * This function update canvascoord[].
- * These parameters are used to create texcoord[1]
- * That way we can access the texcoord relative to the canvas:
- * (0.0,0.0) bottom left, (1.0,1.0) top right, (0.5,0.5) center
- */
- canvascoord[0] = (GLfloat) viewport[0] / -viewport[2];
- canvascoord[1] = (GLfloat) (texturewidth - viewport[0]) / viewport[2];
-
- canvascoord[2] = (GLfloat) viewport[1] / -viewport[3];
- canvascoord[3] = (GLfloat)(textureheight - viewport[1]) / viewport[3];
-}
-
-void RAS_2DFilterManager::RenderFilters(RAS_ICanvas* canvas)
-{
- bool need_depth=false;
- bool need_luminance=false;
- int num_filters = 0;
-
- int passindex;
-
- if (!isshadersupported)
- return;
-
- for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
- {
- if (m_filters[passindex] && m_enabled[passindex]) {
- num_filters ++;
- if (texflag[passindex] & 0x1)
- need_depth = true;
- if (texflag[passindex] & 0x2)
- need_luminance = true;
- if (need_depth && need_luminance)
- break;
- }
- }
-
- if (num_filters <= 0)
- return;
-
- const int *viewport = canvas->GetViewPort();
-
- if (texturewidth != viewport[2] || textureheight != viewport[3])
- {
- UpdateOffsetMatrix(canvas);
- UpdateCanvasTextureCoord(viewport);
- need_tex_update = true;
- }
-
- if (need_tex_update)
- {
- SetupTextures(need_depth, need_luminance);
- need_tex_update = false;
- }
-
- if (need_depth) {
- glActiveTextureARB(GL_TEXTURE1);
- glBindTexture(GL_TEXTURE_2D, texname[1]);
- glCopyTexImage2D(GL_TEXTURE_2D,0,GL_DEPTH_COMPONENT, viewport[0], viewport[1], viewport[2], viewport[3], 0);
- }
-
- if (need_luminance) {
- glActiveTextureARB(GL_TEXTURE2);
- glBindTexture(GL_TEXTURE_2D, texname[2]);
- glCopyTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE16, viewport[0], viewport[1], viewport[2], viewport[3], 0);
- }
-
- // reverting to texunit 0, without this we get bug [#28462]
- glActiveTextureARB(GL_TEXTURE0);
-
- // We do this to make side-by-side stereo rendering work correctly with 2D filters. It would probably be nicer to just set the viewport,
- // but it can be easier for writing shaders to have the coordinates for the whole screen instead of just part of the screen.
- RAS_Rect scissor_rect = canvas->GetDisplayArea();
-
- glScissor(scissor_rect.GetLeft() + viewport[0],
- scissor_rect.GetBottom() + viewport[1],
- scissor_rect.GetWidth() + 1,
- scissor_rect.GetHeight() + 1);
-
- glDisable(GL_DEPTH_TEST);
- // in case the previous material was wire
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
- // if the last rendered face had alpha add it would messes with the color of the plane we apply 2DFilter to
- glDisable(GL_BLEND);
- // fix for [#34523] alpha buffer is now available for all OSs
- glDisable(GL_ALPHA_TEST);
-
- glPushMatrix(); //GL_MODELVIEW
- glLoadIdentity(); // GL_MODELVIEW
- glMatrixMode(GL_TEXTURE);
- glLoadIdentity();
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- for (passindex =0; passindex<MAX_RENDER_PASS; passindex++)
- {
- if (m_filters[passindex] && m_enabled[passindex])
- {
- StartShaderProgram(passindex);
-
- glActiveTextureARB(GL_TEXTURE0);
- glBindTexture(GL_TEXTURE_2D, texname[0]);
- glCopyTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, viewport[0], viewport[1], viewport[2], viewport[3], 0); // Don't use texturewidth and textureheight in case we don't have NPOT support
- glClear(GL_COLOR_BUFFER_BIT);
-
- glBegin(GL_QUADS);
- glColor4f(1.f, 1.f, 1.f, 1.f);
- glTexCoord2f(1.0f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[1], canvascoord[3]); glVertex2f(1.0f,1.0f);
- glTexCoord2f(0.0f, 1.0f); glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[0], canvascoord[3]); glVertex2f(-1.0f,1.0f);
- glTexCoord2f(0.0f, 0.0f); glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[0], canvascoord[2]); glVertex2f(-1.0f,-1.0f);
- glTexCoord2f(1.0f, 0.0f); glMultiTexCoord2fARB(GL_TEXTURE3_ARB, canvascoord[1], canvascoord[2]); glVertex2f(1.0f,-1.0f);
- glEnd();
- }
- }
-
- glEnable(GL_DEPTH_TEST);
- EndShaderProgram();
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
-}
-
-void RAS_2DFilterManager::EnableFilter(vector<STR_String>& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text)
-{
- if (!isshadersupported)
- return;
- if (pass<0 || pass>=MAX_RENDER_PASS)
- return;
- need_tex_update = true;
- if (mode == RAS_2DFILTER_DISABLED)
- {
- m_enabled[pass] = 0;
- return;
- }
-
- if (mode == RAS_2DFILTER_ENABLED)
- {
- m_enabled[pass] = 1;
- return;
- }
-
- if (mode == RAS_2DFILTER_NOFILTER)
- {
- if (m_filters[pass])
- glDeleteObjectARB(m_filters[pass]);
- m_enabled[pass] = 0;
- m_filters[pass] = 0;
- m_gameObjects[pass] = NULL;
- m_properties[pass].clear();
- texflag[pass] = 0;
- return;
- }
-
- if (mode == RAS_2DFILTER_CUSTOMFILTER)
- {
- if (m_filters[pass])
- glDeleteObjectARB(m_filters[pass]);
- m_filters[pass] = CreateShaderProgram(text.Ptr());
- m_gameObjects[pass] = gameObj;
- AnalyseShader(pass, propNames);
- m_enabled[pass] = 1;
- return;
- }
-
- // We've checked all other cases, which means we must be dealing with a builtin filter
- if (m_filters[pass])
- glDeleteObjectARB(m_filters[pass]);
- m_filters[pass] = CreateShaderProgram(mode);
- m_gameObjects[pass] = NULL;
- AnalyseShader(pass, propNames);
- m_enabled[pass] = 1;
-}
diff --git a/source/gameengine/Rasterizer/RAS_2DFilterManager.h b/source/gameengine/Rasterizer/RAS_2DFilterManager.h
deleted file mode 100644
index bb727fe3b29..00000000000
--- a/source/gameengine/Rasterizer/RAS_2DFilterManager.h
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_2DFilterManager.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_2DFILTERMANAGER_H__
-#define __RAS_2DFILTERMANAGER_H__
-
-#define MAX_RENDER_PASS 100
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class RAS_ICanvas;
-
-class RAS_2DFilterManager
-{
-private:
- unsigned int CreateShaderProgram(const char* shadersource);
- unsigned int CreateShaderProgram(int filtermode);
- void AnalyseShader(int passindex, std::vector<STR_String>& propNames);
- void StartShaderProgram(int passindex);
- void EndShaderProgram();
- void PrintShaderErrors(unsigned int shader, const char *task, const char *code);
-
- void SetupTextures(bool depth, bool luminance);
- void FreeTextures();
-
- void UpdateOffsetMatrix(RAS_ICanvas* canvas);
- void UpdateCanvasTextureCoord(const int viewport[4]);
-
- float canvascoord[4];
- float textureoffsets[18];
- /* float view[4]; */ /* UNUSED */
- /* texname[0] contains render to texture, texname[1] contains depth texture, texname[2] contains luminance texture*/
- unsigned int texname[3];
- int texturewidth;
- int textureheight;
- /* int numberoffilters; */ /* UNUSED */
- /* bit 0: enable/disable depth texture
- * bit 1: enable/disable luminance texture*/
- short texflag[MAX_RENDER_PASS];
-
- bool isshadersupported;
- bool errorprinted;
- bool need_tex_update;
-
- unsigned int m_filters[MAX_RENDER_PASS];
- short m_enabled[MAX_RENDER_PASS];
-
- // stores object properties to send to shaders in each pass
- std::vector<STR_String> m_properties[MAX_RENDER_PASS];
- void* m_gameObjects[MAX_RENDER_PASS];
-public:
- enum RAS_2DFILTER_MODE {
- RAS_2DFILTER_ENABLED = -2,
- RAS_2DFILTER_DISABLED = -1,
- RAS_2DFILTER_NOFILTER = 0,
- RAS_2DFILTER_MOTIONBLUR,
- RAS_2DFILTER_BLUR,
- RAS_2DFILTER_SHARPEN,
- RAS_2DFILTER_DILATION,
- RAS_2DFILTER_EROSION,
- RAS_2DFILTER_LAPLACIAN,
- RAS_2DFILTER_SOBEL,
- RAS_2DFILTER_PREWITT,
- RAS_2DFILTER_GRAYSCALE,
- RAS_2DFILTER_SEPIA,
- RAS_2DFILTER_INVERT,
- RAS_2DFILTER_CUSTOMFILTER,
- RAS_2DFILTER_NUMBER_OF_FILTERS
- };
-
- RAS_2DFilterManager();
-
- ~RAS_2DFilterManager();
-
- void RenderFilters(RAS_ICanvas* canvas);
-
- void EnableFilter(std::vector<STR_String>& propNames, void* gameObj, RAS_2DFILTER_MODE mode, int pass, STR_String& text);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_2DFilterManager")
-#endif
-};
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.cpp b/source/gameengine/Rasterizer/RAS_BucketManager.cpp
deleted file mode 100644
index deca7cbed9f..00000000000
--- a/source/gameengine/Rasterizer/RAS_BucketManager.cpp
+++ /dev/null
@@ -1,380 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_BucketManager.cpp
- * \ingroup bgerast
- */
-
-#ifdef _MSC_VER
- /* don't show these anoying STL warnings */
-# pragma warning (disable:4786)
-#endif
-
-#include "RAS_MaterialBucket.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_IRasterizer.h"
-
-#include "RAS_BucketManager.h"
-
-#include <algorithm>
-/* sorting */
-
-struct RAS_BucketManager::sortedmeshslot
-{
-public:
- MT_Scalar m_z; /* depth */
- RAS_MeshSlot *m_ms; /* mesh slot */
- RAS_MaterialBucket *m_bucket; /* buck mesh slot came from */
-
- sortedmeshslot() {}
-
- void set(RAS_MeshSlot *ms, RAS_MaterialBucket *bucket, const MT_Vector3& pnorm)
- {
- // would be good to use the actual bounding box center instead
- MT_Point3 pos(ms->m_OpenGLMatrix[12], ms->m_OpenGLMatrix[13], ms->m_OpenGLMatrix[14]);
-
- m_z = MT_dot(pnorm, pos);
- m_ms = ms;
- m_bucket = bucket;
- }
-};
-
-struct RAS_BucketManager::backtofront
-{
- bool operator()(const sortedmeshslot &a, const sortedmeshslot &b)
- {
- return (a.m_z < b.m_z) || (a.m_z == b.m_z && a.m_ms < b.m_ms);
- }
-};
-
-struct RAS_BucketManager::fronttoback
-{
- bool operator()(const sortedmeshslot &a, const sortedmeshslot &b)
- {
- return (a.m_z > b.m_z) || (a.m_z == b.m_z && a.m_ms > b.m_ms);
- }
-};
-
-/* bucket manager */
-
-RAS_BucketManager::RAS_BucketManager()
-{
-
-}
-
-RAS_BucketManager::~RAS_BucketManager()
-{
- BucketList::iterator it;
-
- for (it = m_SolidBuckets.begin(); it != m_SolidBuckets.end(); it++)
- delete (*it);
-
- for (it = m_AlphaBuckets.begin(); it != m_AlphaBuckets.end(); it++)
- delete(*it);
-
- m_SolidBuckets.clear();
- m_AlphaBuckets.clear();
-}
-
-void RAS_BucketManager::OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha)
-{
- BucketList::iterator bit;
- list<RAS_MeshSlot>::iterator mit;
- size_t size = 0, i = 0;
-
- /* Camera's near plane equation: pnorm.dot(point) + pval,
- * but we leave out pval since it's constant anyway */
- const MT_Vector3 pnorm(cameratrans.getBasis()[2]);
-
- for (bit = buckets.begin(); bit != buckets.end(); ++bit)
- {
- SG_DList::iterator<RAS_MeshSlot> mit((*bit)->GetActiveMeshSlots());
- for (mit.begin(); !mit.end(); ++mit)
- size++;
- }
-
- slots.resize(size);
-
- for (bit = buckets.begin(); bit != buckets.end(); ++bit)
- {
- RAS_MaterialBucket* bucket = *bit;
- RAS_MeshSlot* ms;
- // remove the mesh slot from the list, it culls them automatically for next frame
- while ((ms = bucket->GetNextActiveMeshSlot())) {
- slots[i++].set(ms, bucket, pnorm);
- }
- }
-
- if (alpha)
- sort(slots.begin(), slots.end(), backtofront());
- else
- sort(slots.begin(), slots.end(), fronttoback());
-}
-
-void RAS_BucketManager::RenderAlphaBuckets(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
-{
- vector<sortedmeshslot> slots;
- vector<sortedmeshslot>::iterator sit;
-
- // Having depth masks disabled/enabled gives different artifacts in
- // case no sorting is done or is done inexact. For compatibility, we
- // disable it.
- if (rasty->GetDrawingMode() != RAS_IRasterizer::KX_SHADOW)
- rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_DISABLED);
-
- OrderBuckets(cameratrans, m_AlphaBuckets, slots, true);
-
- for (sit=slots.begin(); sit!=slots.end(); ++sit) {
- rasty->SetClientObject(sit->m_ms->m_clientObj);
-
- while (sit->m_bucket->ActivateMaterial(cameratrans, rasty))
- sit->m_bucket->RenderMeshSlot(cameratrans, rasty, *(sit->m_ms));
-
- // make this mesh slot culled automatically for next frame
- // it will be culled out by frustum culling
- sit->m_ms->SetCulled(true);
- }
-
- rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED);
-}
-
-void RAS_BucketManager::RenderSolidBuckets(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
-{
- BucketList::iterator bit;
-
- rasty->SetDepthMask(RAS_IRasterizer::KX_DEPTHMASK_ENABLED);
-
- for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit) {
-#if 1
- RAS_MaterialBucket* bucket = *bit;
- RAS_MeshSlot* ms;
- // remove the mesh slot from the list, it culls them automatically for next frame
- while ((ms = bucket->GetNextActiveMeshSlot())) {
- rasty->SetClientObject(ms->m_clientObj);
- while (bucket->ActivateMaterial(cameratrans, rasty))
- bucket->RenderMeshSlot(cameratrans, rasty, *ms);
-
- // make this mesh slot culled automatically for next frame
- // it will be culled out by frustum culling
- ms->SetCulled(true);
- }
-#else
- list<RAS_MeshSlot>::iterator mit;
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
- if (mit->IsCulled())
- continue;
-
- rasty->SetClientObject(rasty, mit->m_clientObj);
-
- while ((*bit)->ActivateMaterial(cameratrans, rasty))
- (*bit)->RenderMeshSlot(cameratrans, rasty, *mit);
-
- // make this mesh slot culled automatically for next frame
- // it will be culled out by frustum culling
- mit->SetCulled(true);
- }
-#endif
- }
-
- /* this code draws meshes order front-to-back instead to reduce overdraw.
- * it turned out slower due to much material state switching, a more clever
- * algorithm might do better. */
-#if 0
- vector<sortedmeshslot> slots;
- vector<sortedmeshslot>::iterator sit;
-
- OrderBuckets(cameratrans, m_SolidBuckets, slots, false);
-
- for (sit=slots.begin(); sit!=slots.end(); ++sit) {
- rendertools->SetClientObject(rasty, sit->m_ms->m_clientObj);
-
- while (sit->m_bucket->ActivateMaterial(cameratrans, rasty))
- sit->m_bucket->RenderMeshSlot(cameratrans, rasty, *(sit->m_ms));
- }
-#endif
-}
-
-void RAS_BucketManager::Renderbuckets(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
-{
- /* beginning each frame, clear (texture/material) caching information */
- rasty->ClearCachingInfo();
-
- RenderSolidBuckets(cameratrans, rasty);
- RenderAlphaBuckets(cameratrans, rasty);
-
- /* If we're drawing shadows and bucket wasn't rendered (outside of the lamp frustum or doesn't cast shadows)
- * then the mesh is still modified, so we don't want to set MeshModified to false yet (it will mess up
- * updating display lists). Just leave this step for the main render pass.
- */
- if (rasty->GetDrawingMode() != RAS_IRasterizer::KX_SHADOW) {
- /* All meshes should be up to date now */
- /* Don't do this while processing buckets because some meshes are split between buckets */
- BucketList::iterator bit;
- list<RAS_MeshSlot>::iterator mit;
- for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit) {
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
- mit->m_mesh->SetMeshModified(false);
- }
- }
- for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit) {
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
- mit->m_mesh->SetMeshModified(false);
- }
- }
- }
-
-
- rasty->SetClientObject(NULL);
-}
-
-RAS_MaterialBucket *RAS_BucketManager::FindBucket(RAS_IPolyMaterial *material, bool &bucketCreated)
-{
- BucketList::iterator it;
-
- bucketCreated = false;
-
- for (it = m_SolidBuckets.begin(); it != m_SolidBuckets.end(); it++)
- if (*(*it)->GetPolyMaterial() == *material)
- return *it;
-
- for (it = m_AlphaBuckets.begin(); it != m_AlphaBuckets.end(); it++)
- if (*(*it)->GetPolyMaterial() == *material)
- return *it;
-
- RAS_MaterialBucket *bucket = new RAS_MaterialBucket(material);
- bucketCreated = true;
-
- if (bucket->IsAlpha())
- m_AlphaBuckets.push_back(bucket);
- else
- m_SolidBuckets.push_back(bucket);
-
- return bucket;
-}
-
-void RAS_BucketManager::OptimizeBuckets(MT_Scalar distance)
-{
- BucketList::iterator bit;
-
- distance = 10.0f;
-
- for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit)
- (*bit)->Optimize(distance);
- for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit)
- (*bit)->Optimize(distance);
-}
-
-void RAS_BucketManager::ReleaseDisplayLists(RAS_IPolyMaterial *mat)
-{
- BucketList::iterator bit;
- list<RAS_MeshSlot>::iterator mit;
-
- for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit) {
- if (mat == NULL || (mat == (*bit)->GetPolyMaterial())) {
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
- if (mit->m_DisplayList) {
- mit->m_DisplayList->Release();
- mit->m_DisplayList = NULL;
- }
- }
- }
- }
-
- for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit) {
- if (mat == NULL || (mat == (*bit)->GetPolyMaterial())) {
- for (mit = (*bit)->msBegin(); mit != (*bit)->msEnd(); ++mit) {
- if (mit->m_DisplayList) {
- mit->m_DisplayList->Release();
- mit->m_DisplayList = NULL;
- }
- }
- }
- }
-}
-
-void RAS_BucketManager::ReleaseMaterials(RAS_IPolyMaterial * mat)
-{
- BucketList::iterator bit;
- list<RAS_MeshSlot>::iterator mit;
-
- for (bit = m_SolidBuckets.begin(); bit != m_SolidBuckets.end(); ++bit) {
- if (mat == NULL || (mat == (*bit)->GetPolyMaterial())) {
- (*bit)->GetPolyMaterial()->ReleaseMaterial();
- }
- }
-
- for (bit = m_AlphaBuckets.begin(); bit != m_AlphaBuckets.end(); ++bit) {
- if (mat == NULL || (mat == (*bit)->GetPolyMaterial())) {
- (*bit)->GetPolyMaterial()->ReleaseMaterial();
- }
- }
-}
-
-/* frees the bucket, only used when freeing scenes */
-void RAS_BucketManager::RemoveMaterial(RAS_IPolyMaterial * mat)
-{
- BucketList::iterator bit, bitp;
- list<RAS_MeshSlot>::iterator mit;
- int i;
-
-
- for (i=0; i<m_SolidBuckets.size(); i++) {
- RAS_MaterialBucket *bucket = m_SolidBuckets[i];
- if (mat == bucket->GetPolyMaterial()) {
- m_SolidBuckets.erase(m_SolidBuckets.begin()+i);
- delete bucket;
- i--;
- }
- }
-
- for (int i=0; i<m_AlphaBuckets.size(); i++) {
- RAS_MaterialBucket *bucket = m_AlphaBuckets[i];
- if (mat == bucket->GetPolyMaterial()) {
- m_AlphaBuckets.erase(m_AlphaBuckets.begin()+i);
- delete bucket;
- i--;
- }
- }
-}
-
-//#include <stdio.h>
-
-void RAS_BucketManager::MergeBucketManager(RAS_BucketManager *other, SCA_IScene *scene)
-{
- /* concatenate lists */
- // printf("BEFORE %d %d\n", GetSolidBuckets().size(), GetAlphaBuckets().size());
-
- GetSolidBuckets().insert( GetSolidBuckets().end(), other->GetSolidBuckets().begin(), other->GetSolidBuckets().end() );
- other->GetSolidBuckets().clear();
-
- GetAlphaBuckets().insert( GetAlphaBuckets().end(), other->GetAlphaBuckets().begin(), other->GetAlphaBuckets().end() );
- other->GetAlphaBuckets().clear();
- //printf("AFTER %d %d\n", GetSolidBuckets().size(), GetAlphaBuckets().size());
-}
-
diff --git a/source/gameengine/Rasterizer/RAS_BucketManager.h b/source/gameengine/Rasterizer/RAS_BucketManager.h
deleted file mode 100644
index 5ed212ebee0..00000000000
--- a/source/gameengine/Rasterizer/RAS_BucketManager.h
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_BucketManager.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_BUCKETMANAGER_H__
-#define __RAS_BUCKETMANAGER_H__
-
-#include "MT_Transform.h"
-#include "RAS_MaterialBucket.h"
-
-#include <vector>
-
-class RAS_BucketManager
-{
-public:
- typedef std::vector<class RAS_MaterialBucket*> BucketList;
-private:
- BucketList m_SolidBuckets;
- BucketList m_AlphaBuckets;
-
- struct sortedmeshslot;
- struct backtofront;
- struct fronttoback;
-
-public:
- RAS_BucketManager();
- virtual ~RAS_BucketManager();
-
- void Renderbuckets(const MT_Transform & cameratrans, RAS_IRasterizer* rasty);
-
- RAS_MaterialBucket* FindBucket(RAS_IPolyMaterial *material, bool &bucketCreated);
- void OptimizeBuckets(MT_Scalar distance);
-
- void ReleaseDisplayLists(RAS_IPolyMaterial *material = NULL);
- void ReleaseMaterials(RAS_IPolyMaterial *material = NULL);
-
- void RemoveMaterial(RAS_IPolyMaterial *mat); // freeing scenes only
-
- /* for merging */
- void MergeBucketManager(RAS_BucketManager *other, SCA_IScene *scene);
- BucketList & GetSolidBuckets() {return m_SolidBuckets;}
- BucketList & GetAlphaBuckets() {return m_AlphaBuckets;}
-
- /*void PrintStats(int verbose_level) {
- printf("\nMappings...\n");
- printf("\t m_SolidBuckets: %d\n", m_SolidBuckets.size());
- printf("\t\t m_SolidBuckets: %d\n", m_SolidBuckets.size());
- printf("\t m_AlphaBuckets: %d\n", m_AlphaBuckets.size());
- }*/
-
-
-private:
- void OrderBuckets(const MT_Transform& cameratrans, BucketList& buckets, vector<sortedmeshslot>& slots, bool alpha);
-
- void RenderSolidBuckets(const MT_Transform& cameratrans,
- RAS_IRasterizer* rasty);
- void RenderAlphaBuckets(const MT_Transform& cameratrans,
- RAS_IRasterizer* rasty);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_BucketManager")
-#endif
-};
-
-#endif /* __RAS_BUCKETMANAGER_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_CameraData.h b/source/gameengine/Rasterizer/RAS_CameraData.h
deleted file mode 100644
index bc8433afd05..00000000000
--- a/source/gameengine/Rasterizer/RAS_CameraData.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_CameraData.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_CAMERADATA_H__
-#define __RAS_CAMERADATA_H__
-
-struct RAS_CameraData
-{
- float m_lens;
- float m_scale;
- float m_sensor_x;
- float m_sensor_y;
- short m_sensor_fit;
- float m_shift_x;
- float m_shift_y;
- float m_clipstart;
- float m_clipend;
- bool m_perspective;
- bool m_viewport;
- int m_viewportleft;
- int m_viewportbottom;
- int m_viewportright;
- int m_viewporttop;
- float m_focallength;
-
- RAS_CameraData(float lens = 35.0f, float scale = 6.0f, float sensor_x = 32.0f, float sensor_y = 18.0f, short sensor_fit = 0,
- float shift_x = 0.0f, float shift_y = 0.0f,
- float clipstart = 0.1f, float clipend = 5000.0f, bool perspective = true,
- float focallength = 3.0f, bool viewport = false, int viewportleft = 0, int viewportbottom = 0,
- int viewportright = 0, int viewporttop = 0) :
- m_lens(lens),
- m_scale(scale),
- m_sensor_x(sensor_x),
- m_sensor_y(sensor_y),
- m_sensor_fit(sensor_fit),
- m_shift_x(shift_x),
- m_shift_y(shift_y),
- m_clipstart(clipstart),
- m_clipend(clipend),
- m_perspective(perspective),
- m_viewport(viewport),
- m_viewportleft(viewportleft),
- m_viewportbottom(viewportbottom),
- m_viewportright(viewportright),
- m_viewporttop(viewporttop),
- m_focallength(focallength)
- {
- }
-};
-
-#endif /* __RAS_CAMERADATA_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_Deformer.h b/source/gameengine/Rasterizer/RAS_Deformer.h
deleted file mode 100644
index 058f2304f3d..00000000000
--- a/source/gameengine/Rasterizer/RAS_Deformer.h
+++ /dev/null
@@ -1,103 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Deformer.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_DEFORMER_H__
-#define __RAS_DEFORMER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786) /* get rid of stupid stl-visual compiler debug warning */
-#endif
-
-#include <stdlib.h>
-#include "CTR_Map.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-struct DerivedMesh;
-class RAS_MeshObject;
-
-class RAS_Deformer
-{
-public:
- RAS_Deformer() : m_pMesh(NULL), m_bDynamic(false) {}
- virtual ~RAS_Deformer() {}
- virtual void Relink(CTR_Map<class CTR_HashedPtr, void*>*map)=0;
- virtual bool Apply(class RAS_IPolyMaterial *polymat)=0;
- virtual bool Update(void)=0;
- virtual bool UpdateBuckets(void)=0;
- virtual RAS_Deformer *GetReplica()=0;
- virtual void ProcessReplica()=0;
- virtual bool SkipVertexTransform()
- {
- return false;
- }
- virtual bool ShareVertexArray()
- {
- return true;
- }
- virtual bool UseVertexArray()
- {
- return true;
- }
- // true when deformer produces varying vertex (shape or armature)
- bool IsDynamic()
- {
- return m_bDynamic;
- }
- virtual struct DerivedMesh* GetFinalMesh()
- {
- return NULL;
- }
- virtual struct DerivedMesh* GetPhysicsMesh()
- {
- return NULL;
- }
- virtual class RAS_MeshObject* GetRasMesh()
- {
- /* m_pMesh does not seem to be being used?? */
- return NULL;
- }
- virtual float (* GetTransVerts(int *tot))[3] { *tot= 0; return NULL; }
-
-protected:
- class RAS_MeshObject *m_pMesh;
- bool m_bDynamic;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_Deformer")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Rasterizer/RAS_FramingManager.cpp b/source/gameengine/Rasterizer/RAS_FramingManager.cpp
deleted file mode 100644
index 8b0ec22fde3..00000000000
--- a/source/gameengine/Rasterizer/RAS_FramingManager.cpp
+++ /dev/null
@@ -1,425 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_FramingManager.cpp
- * \ingroup bgerast
- */
-
-
-#include "RAS_FramingManager.h"
-#include "RAS_Rect.h"
-
- void
-RAS_FramingManager::
-ComputeDefaultFrustum(
- const float camnear,
- const float camfar,
- const float lens,
- const float sensor_x, const float sensor_y,
- const short sensor_fit,
- const float shift_x,
- const float shift_y,
- const float design_aspect_ratio,
- RAS_FrameFrustum & frustum
-) {
- float size;
- float halfSize;
- float sizeX;
- float sizeY;
- float offsetX;
- float offsetY;
-
- if (sensor_fit==RAS_SENSORFIT_AUTO) {
- size = sensor_x * camnear / lens;
- halfSize = size * 0.5f;
-
- if (design_aspect_ratio > 1.f) {
- // halfsize defines the width
- sizeX = halfSize;
- sizeY = halfSize/design_aspect_ratio;
- } else {
- // halfsize defines the height
- sizeX = halfSize * design_aspect_ratio;
- sizeY = halfSize;
- }
- }
- else if (sensor_fit==RAS_SENSORFIT_HOR) {
- size = sensor_x * camnear / lens;
- halfSize = size * 0.5f;
- sizeX = halfSize;
- sizeY = halfSize/design_aspect_ratio;
- }
- else {
- size = sensor_y * camnear / lens;
- halfSize = size * 0.5f;
- sizeX = halfSize * design_aspect_ratio;
- sizeY = halfSize;
- }
-
- offsetX = size * shift_x;
- offsetY = size * shift_y;
-
- frustum.x2 = sizeX + offsetX;
- frustum.x1 = -sizeX + offsetX;
- frustum.y2 = sizeY + offsetY;
- frustum.y1 = -sizeY + offsetY;
- frustum.camnear = camnear;
- frustum.camfar = camfar;
-}
-
- void
-RAS_FramingManager::
-ComputeDefaultOrtho(
- const float camnear,
- const float camfar,
- const float scale,
- const float design_aspect_ratio,
- const short sensor_fit,
- const float shift_x,
- const float shift_y,
- RAS_FrameFrustum & frustum
-)
-{
- float halfSize = scale*0.5f;
- float sizeX;
- float sizeY;
- float offsetX;
- float offsetY;
-
- if (sensor_fit==RAS_SENSORFIT_AUTO) {
- if (design_aspect_ratio > 1.f) {
- // halfsize defines the width
- sizeX = halfSize;
- sizeY = halfSize/design_aspect_ratio;
- } else {
- // halfsize defines the height
- sizeX = halfSize * design_aspect_ratio;
- sizeY = halfSize;
- }
- }
- else if (sensor_fit==RAS_SENSORFIT_HOR) {
- sizeX = halfSize;
- sizeY = halfSize/design_aspect_ratio;
- }
- else {
- sizeX = halfSize * design_aspect_ratio;
- sizeY = halfSize;
- }
-
- offsetX = scale * shift_x;
- offsetY = scale * shift_y;
-
- frustum.x2 = sizeX + offsetX;
- frustum.x1 = -sizeX + offsetX;
- frustum.y2 = sizeY + offsetY;
- frustum.y1 = -sizeY + offsetY;
- frustum.camnear = camnear;
- frustum.camfar = camfar;
-}
-
-
- void
-RAS_FramingManager::
-ComputeBestFitViewRect(
- const RAS_Rect &availableViewport,
- const float design_aspect_ratio,
- RAS_Rect &viewport
-) {
- // try and honour the aspect ratio when setting the
- // drawable area. If we don't do this we are liable
- // to get a lot of distortion in the rendered image.
-
- int width = availableViewport.GetWidth();
- int height = availableViewport.GetHeight();
- float window_aspect = float(width)/float(height);
-
- if (window_aspect < design_aspect_ratio) {
- int v_height = (int)(width / design_aspect_ratio);
- int left_over = (height - v_height) / 2;
-
- viewport.SetLeft(availableViewport.GetLeft());
- viewport.SetBottom(availableViewport.GetBottom() + left_over);
- viewport.SetRight(availableViewport.GetLeft() + width);
- viewport.SetTop(availableViewport.GetBottom() + left_over + v_height);
-
- } else {
- int v_width = (int)(height * design_aspect_ratio);
- int left_over = (width - v_width) / 2;
-
- viewport.SetLeft(availableViewport.GetLeft() + left_over);
- viewport.SetBottom(availableViewport.GetBottom());
- viewport.SetRight(availableViewport.GetLeft() + v_width + left_over);
- viewport.SetTop(availableViewport.GetBottom() + height);
- }
-}
-
- void
-RAS_FramingManager::
-ComputeViewport(
- const RAS_FrameSettings &settings,
- const RAS_Rect &availableViewport,
- RAS_Rect &viewport
-) {
-
- RAS_FrameSettings::RAS_FrameType type = settings.FrameType();
- const int winx = availableViewport.GetWidth();
- const int winy = availableViewport.GetHeight();
-
- const float design_width = float(settings.DesignAspectWidth());
- const float design_height = float(settings.DesignAspectHeight());
-
- float design_aspect_ratio = float(1);
-
- if (design_height == float(0)) {
- // well this is ill defined
- // lets just scale the thing
-
- type = RAS_FrameSettings::e_frame_scale;
- } else {
- design_aspect_ratio = design_width/design_height;
- }
-
- switch (type) {
-
- case RAS_FrameSettings::e_frame_scale :
- case RAS_FrameSettings::e_frame_extend:
- {
- viewport.SetLeft(availableViewport.GetLeft());
- viewport.SetBottom(availableViewport.GetBottom());
- viewport.SetRight(availableViewport.GetLeft() + int(winx));
- viewport.SetTop(availableViewport.GetBottom() + int(winy));
-
- break;
- }
-
- case RAS_FrameSettings::e_frame_bars:
- {
- ComputeBestFitViewRect(
- availableViewport,
- design_aspect_ratio,
- viewport
- );
-
- break;
- }
- default :
- break;
- }
-}
-
- void
-RAS_FramingManager::
-ComputeFrustum(
- const RAS_FrameSettings &settings,
- const RAS_Rect &availableViewport,
- const RAS_Rect &viewport,
- const float lens,
- const float sensor_x, const float sensor_y, const short sensor_fit,
- const float shift_x,
- const float shift_y,
- const float camnear,
- const float camfar,
- RAS_FrameFrustum &frustum
-) {
-
- RAS_FrameSettings::RAS_FrameType type = settings.FrameType();
-
- const float design_width = float(settings.DesignAspectWidth());
- const float design_height = float(settings.DesignAspectHeight());
-
- float design_aspect_ratio = float(1);
-
- if (design_height == float(0)) {
- // well this is ill defined
- // lets just scale the thing
-
- type = RAS_FrameSettings::e_frame_scale;
- } else {
- design_aspect_ratio = design_width/design_height;
- }
-
- ComputeDefaultFrustum(
- camnear,
- camfar,
- lens,
- sensor_x,
- sensor_y,
- sensor_fit,
- shift_x,
- shift_y,
- design_aspect_ratio,
- frustum
- );
-
- switch (type) {
-
- case RAS_FrameSettings::e_frame_extend:
- {
- float x_scale, y_scale;
- switch (sensor_fit) {
- case RAS_SENSORFIT_HOR:
- {
- x_scale = 1.0f;
- y_scale = float(viewport.GetHeight()) / float(viewport.GetWidth());
- break;
- }
- case RAS_SENSORFIT_VERT:
- {
- x_scale = float(viewport.GetWidth()) / float(viewport.GetHeight());
- y_scale = 1.0f;
- break;
- }
- case RAS_SENSORFIT_AUTO:
- default:
- {
- RAS_Rect vt;
- ComputeBestFitViewRect(
- availableViewport,
- design_aspect_ratio,
- vt
- );
-
- // now scale the calculated frustum by the difference
- // between vt and the viewport in each axis.
- // These are always > 1
-
- x_scale = float(viewport.GetWidth())/float(vt.GetWidth());
- y_scale = float(viewport.GetHeight())/float(vt.GetHeight());
- break;
- }
- }
-
- frustum.x1 *= x_scale;
- frustum.x2 *= x_scale;
- frustum.y1 *= y_scale;
- frustum.y2 *= y_scale;
-
- break;
- }
- case RAS_FrameSettings::e_frame_scale :
- case RAS_FrameSettings::e_frame_bars:
- default :
- break;
- }
-}
-
- void
-RAS_FramingManager::
- ComputeOrtho(
- const RAS_FrameSettings &settings,
- const RAS_Rect &availableViewport,
- const RAS_Rect &viewport,
- const float scale,
- const float camnear,
- const float camfar,
- const short sensor_fit,
- const float shift_x,
- const float shift_y,
- RAS_FrameFrustum &frustum
- )
-{
- RAS_FrameSettings::RAS_FrameType type = settings.FrameType();
-
- const float design_width = float(settings.DesignAspectWidth());
- const float design_height = float(settings.DesignAspectHeight());
-
- float design_aspect_ratio = float(1);
-
- if (design_height == float(0)) {
- // well this is ill defined
- // lets just scale the thing
- type = RAS_FrameSettings::e_frame_scale;
- } else {
- design_aspect_ratio = design_width/design_height;
- }
-
-
- ComputeDefaultOrtho(
- camnear,
- camfar,
- scale,
- design_aspect_ratio,
- sensor_fit,
- shift_x,
- shift_y,
- frustum
- );
-
- switch (type) {
-
- case RAS_FrameSettings::e_frame_extend:
- {
- float x_scale, y_scale;
- switch (sensor_fit) {
- case RAS_SENSORFIT_HOR:
- {
- x_scale = 1.0f;
- y_scale = float(viewport.GetHeight()) / float(viewport.GetWidth());
- break;
- }
- case RAS_SENSORFIT_VERT:
- {
- x_scale = float(viewport.GetWidth()) / float(viewport.GetHeight());
- y_scale = 1.0f;
- break;
- }
- case RAS_SENSORFIT_AUTO:
- default:
- {
- RAS_Rect vt;
- ComputeBestFitViewRect(
- availableViewport,
- design_aspect_ratio,
- vt
- );
-
- // now scale the calculated frustum by the difference
- // between vt and the viewport in each axis.
- // These are always > 1
-
- x_scale = float(viewport.GetWidth())/float(vt.GetWidth());
- y_scale = float(viewport.GetHeight())/float(vt.GetHeight());
- break;
- }
- }
-
- frustum.x1 *= x_scale;
- frustum.x2 *= x_scale;
- frustum.y1 *= y_scale;
- frustum.y2 *= y_scale;
-
- break;
- }
- case RAS_FrameSettings::e_frame_scale :
- case RAS_FrameSettings::e_frame_bars:
- default :
- break;
- }
-
-}
-
-
diff --git a/source/gameengine/Rasterizer/RAS_FramingManager.h b/source/gameengine/Rasterizer/RAS_FramingManager.h
deleted file mode 100644
index cb86a7a4484..00000000000
--- a/source/gameengine/Rasterizer/RAS_FramingManager.h
+++ /dev/null
@@ -1,316 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_FramingManager.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_FRAMINGMANAGER_H__
-#define __RAS_FRAMINGMANAGER_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class RAS_Rect;
-
-/**
- * \section RAS_FrameSettings
- * This is a value type describing the framing used
- * by a particular scene in the game engine.
- * Each KX_Scene contains a RAS_FrameSetting describing
- * how the frustum and viewport are to be modified
- * depending on the canvas size.
- *
- * e_frame_scale means that the viewport is set to the current
- * canvas size. If the view frustum aspect ratio is different
- * to the canvas aspect this will lead to stretching.
- *
- * e_frame_extend means that the best fit viewport will be
- * computed based upon the design aspect ratio
- * and the view frustum will be adjusted so that
- * more of the scene is visible.
- *
- * e_frame_bars means that the best fit viewport will be
- * be computed based upon the design aspect ratio.
- */
-
-class RAS_FrameSettings
-{
-public :
- /**
- * enum defining the policy to use
- * in each axis.
- */
- enum RAS_FrameType {
- e_frame_scale,
- e_frame_extend,
- e_frame_bars
- };
-
- /**
- * Constructor
- */
-
- RAS_FrameSettings(
- RAS_FrameType frame_type,
- float bar_r,
- float bar_g,
- float bar_b,
- unsigned int design_aspect_width,
- unsigned int design_aspect_height
- ):
- m_frame_type(frame_type),
- m_bar_r(bar_r),
- m_bar_g(bar_g),
- m_bar_b(bar_b),
- m_design_aspect_width(design_aspect_width),
- m_design_aspect_height(design_aspect_height)
- {
- };
-
- RAS_FrameSettings(
- ):
- m_frame_type(e_frame_scale),
- m_bar_r(0),
- m_bar_g(0),
- m_bar_b(0),
- m_design_aspect_width(1),
- m_design_aspect_height(1)
- {
- };
-
- /**
- * Accessors
- */
-
- const
- RAS_FrameType &
- FrameType(
- ) const {
- return m_frame_type;
- };
-
- void
- SetFrameType(
- RAS_FrameType type
- ) {
- m_frame_type = type;
- };
-
- float
- BarRed(
- ) const {
- return m_bar_r;
- };
-
- float
- BarGreen(
- ) const {
- return m_bar_g;
- };
-
- float
- BarBlue(
- ) const {
- return m_bar_b;
- };
-
- unsigned int
- DesignAspectWidth(
- ) const {
- return m_design_aspect_width;
- };
-
- unsigned int
- DesignAspectHeight(
- ) const {
- return m_design_aspect_height;
- };
-
-private :
-
- RAS_FrameType m_frame_type;
- float m_bar_r;
- float m_bar_g;
- float m_bar_b;
- unsigned int m_design_aspect_width;
- unsigned int m_design_aspect_height;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_FrameSettings")
-#endif
-};
-
-struct RAS_FrameFrustum
-{
- float camnear,camfar;
- float x1,y1;
- float x2,y2;
-};
-
-/* must match R_CULLING_... from DNA_scene_types.h */
-enum RAS_CullingMode
-{
- RAS_CULLING_DBVT = 0,
- RAS_CULLING_NORMAL,
- RAS_CULLING_NONE
-};
-
-/* Should match CAMERA_SENSOR_FIT... from DNA_camera_types.h */
-enum RAS_SensorFit
-{
- RAS_SENSORFIT_AUTO = 0,
- RAS_SENSORFIT_HOR,
- RAS_SENSORFIT_VERT
-};
-
-/**
- * \section RAS_FramingManager
- * This class helps to compute a view frustum
- * and a viewport rectangle given the
- * above settings and a description of the
- * current canvas dimensions.
- *
- * You do not have to instantiate this class
- * directly, it only contains static helper functions
- */
-
-class RAS_FramingManager
-{
-public :
-
- /**
- * Compute a viewport given
- * a RAS_FrameSettings and a description of the
- * canvas.
- */
-
- static
- void
- ComputeViewport(
- const RAS_FrameSettings &settings,
- const RAS_Rect &availableViewport,
- RAS_Rect &viewport
- );
-
-
- /**
- * compute a frustum given a valid viewport,
- * RAS_FrameSettings, canvas description
- * and camera description
- */
-
- static
- void
- ComputeOrtho(
- const RAS_FrameSettings &settings,
- const RAS_Rect &availableViewport,
- const RAS_Rect &viewport,
- const float scale,
- const float camnear,
- const float camfar,
- const short sensor_fit,
- const float shift_x,
- const float shift_y,
- RAS_FrameFrustum &frustum
- );
-
- static
- void
- ComputeFrustum(
- const RAS_FrameSettings &settings,
- const RAS_Rect &availableViewport,
- const RAS_Rect &viewport,
- const float lens,
- const float sensor_x, const float sensor_y, const short sensor_fit,
- const float shift_x,
- const float shift_y,
- const float camnear,
- const float camfar,
- RAS_FrameFrustum &frustum
- );
-
- static
- void
- ComputeDefaultFrustum(
- const float camnear,
- const float camfar,
- const float lens,
- const float sensor_x, const float sensor_y,
- const short sensor_fit,
- const float shift_x,
- const float shift_y,
- const float design_aspect_ratio,
- RAS_FrameFrustum & frustum
- );
-
- static
- void
- ComputeDefaultOrtho(
- const float camnear,
- const float camfar,
- const float scale,
- const float design_aspect_ratio,
- const short sensor_fit,
- const float shift_x,
- const float shift_y,
- RAS_FrameFrustum & frustum
- );
-
-private :
-
- static
- void
- ComputeBestFitViewRect(
- const RAS_Rect &availableViewport,
- const float design_aspect_ratio,
- RAS_Rect &viewport
- );
-
-
-
- /**
- * Private constructor - this class is not meant
- * for instantiation.
- */
-
- RAS_FramingManager(
- );
-
- RAS_FramingManager(
- const RAS_FramingManager &
- );
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_FramingManager")
-#endif
-};
-
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_ICanvas.cpp b/source/gameengine/Rasterizer/RAS_ICanvas.cpp
deleted file mode 100644
index 808d257f8f0..00000000000
--- a/source/gameengine/Rasterizer/RAS_ICanvas.cpp
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_ICanvas.cpp
- * \ingroup bgerast
- */
-
-#include "RAS_ICanvas.h"
-#include "DNA_scene_types.h"
-
-#include "BKE_image.h"
-#include "BKE_global.h"
-#include "BKE_main.h"
-
-#include "BLI_task.h"
-#include "BLI_path_util.h"
-#include "BLI_string.h"
-
-#include "MEM_guardedalloc.h"
-
-extern "C" {
-#include "IMB_imbuf.h"
-#include "IMB_imbuf_types.h"
-}
-
-
-// Task data for saving screenshots in a different thread.
-struct ScreenshotTaskData
-{
- unsigned int *dumprect;
- int dumpsx;
- int dumpsy;
- char *path;
- ImageFormatData *im_format;
-};
-
-/**
- * Function that actually performs the image compression and saving to disk of a screenshot.
- * Run in a separate thread by RAS_ICanvas::save_screenshot().
- *
- * @param taskdata Must point to a ScreenshotTaskData object. This function takes ownership
- * of all pointers in the ScreenshotTaskData, and frees them.
- */
-void save_screenshot_thread_func(TaskPool *__restrict pool, void *taskdata, int threadid);
-
-
-RAS_ICanvas::RAS_ICanvas()
-{
- m_taskscheduler = BLI_task_scheduler_create(TASK_SCHEDULER_AUTO_THREADS);
- m_taskpool = BLI_task_pool_create(m_taskscheduler, NULL);
-}
-
-RAS_ICanvas::~RAS_ICanvas()
-{
- if (m_taskpool) {
- BLI_task_pool_work_and_wait(m_taskpool);
- BLI_task_pool_free(m_taskpool);
- m_taskpool = NULL;
- }
-
- if (m_taskscheduler) {
- BLI_task_scheduler_free(m_taskscheduler);
- m_taskscheduler = NULL;
- }
-}
-
-
-void save_screenshot_thread_func(TaskPool *__restrict UNUSED(pool), void *taskdata, int UNUSED(threadid))
-{
- ScreenshotTaskData *task = static_cast<ScreenshotTaskData *>(taskdata);
-
- /* create and save imbuf */
- ImBuf *ibuf = IMB_allocImBuf(task->dumpsx, task->dumpsy, 24, 0);
- ibuf->rect = task->dumprect;
-
- BKE_imbuf_write_as(ibuf, task->path, task->im_format, false);
-
- ibuf->rect = NULL;
- IMB_freeImBuf(ibuf);
- MEM_freeN(task->dumprect);
- MEM_freeN(task->path);
- MEM_freeN(task->im_format);
-}
-
-
-void RAS_ICanvas::save_screenshot(const char *filename, int dumpsx, int dumpsy, unsigned int *dumprect,
- ImageFormatData * im_format)
-{
- /* create file path */
- char *path = (char *)MEM_mallocN(FILE_MAX, "screenshot-path");
- BLI_strncpy(path, filename, FILE_MAX);
- BLI_path_abs(path, G.main->name);
- BLI_path_frame(path, m_frame, 0);
- m_frame++;
- BKE_image_path_ensure_ext_from_imtype(path, im_format->imtype);
-
- /* Save the actual file in a different thread, so that the
- * game engine can keep running at full speed. */
- ScreenshotTaskData *task = (ScreenshotTaskData *)MEM_mallocN(sizeof(ScreenshotTaskData), "screenshot-data");
- task->dumprect = dumprect;
- task->dumpsx = dumpsx;
- task->dumpsy = dumpsy;
- task->path = path;
- task->im_format = im_format;
-
- BLI_task_pool_push(m_taskpool,
- save_screenshot_thread_func,
- task,
- true, // free task data
- TASK_PRIORITY_LOW);
-}
diff --git a/source/gameengine/Rasterizer/RAS_ICanvas.h b/source/gameengine/Rasterizer/RAS_ICanvas.h
deleted file mode 100644
index 91cc13c8f85..00000000000
--- a/source/gameengine/Rasterizer/RAS_ICanvas.h
+++ /dev/null
@@ -1,287 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_ICanvas.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_ICANVAS_H__
-#define __RAS_ICANVAS_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class RAS_Rect;
-struct TaskScheduler;
-struct TaskPool;
-struct ImageFormatData;
-
-/**
- * 2D rendering device context. The connection from 3d rendercontext to 2d surface.
- */
-class RAS_ICanvas
-{
-public:
- enum BufferType {
- COLOR_BUFFER=1,
- DEPTH_BUFFER=2
- };
-
- enum RAS_MouseState
- {
- MOUSE_INVISIBLE=1,
- MOUSE_WAIT,
- MOUSE_NORMAL
- };
-
- RAS_ICanvas();
- virtual ~RAS_ICanvas();
-
- virtual
- void
- Init(
- ) = 0;
-
- virtual
- void
- BeginFrame(
- )=0;
-
- virtual
- void
- EndFrame(
- )=0;
-
- /**
- * Initializes the canvas for drawing. Drawing to the canvas is
- * only allowed between BeginDraw() and EndDraw().
- *
- * \retval false Acquiring the canvas failed.
- * \retval true Acquiring the canvas succeeded.
- *
- */
-
- virtual
- bool
- BeginDraw(
- )=0;
-
- /**
- * Unitializes the canvas for drawing.
- */
-
- virtual
- void
- EndDraw(
- )=0;
-
-
- /// probably needs some arguments for PS2 in future
- virtual
- void
- SwapBuffers(
- )=0;
-
- virtual
- void
- SetSwapInterval(
- int interval
- )=0;
-
- virtual
- bool
- GetSwapInterval(
- int& intervalOut
- )=0;
-
- virtual
- void
- ClearBuffer(
- int type
- )=0;
-
- virtual
- void
- ClearColor(
- float r,
- float g,
- float b,
- float a
- )=0;
-
- virtual
- int
- GetWidth(
- ) const = 0;
-
- virtual
- int
- GetHeight(
- ) const = 0;
-
- virtual
- int
- GetMouseX(int x
- )=0;
-
- virtual
- int
- GetMouseY(int y
- )= 0;
-
- virtual
- float
- GetMouseNormalizedX(int x
- )=0;
-
- virtual
- float
- GetMouseNormalizedY(int y
- )= 0;
-
- virtual
- const RAS_Rect &
- GetDisplayArea(
- ) const = 0;
-
- virtual
- void
- SetDisplayArea(RAS_Rect *rect
- ) = 0;
-
- /**
- * Used to get canvas area within blender.
- */
- virtual
- RAS_Rect &
- GetWindowArea(
- ) = 0;
-
- /**
- * Set the visible view-port
- */
-
- virtual
- void
- SetViewPort(
- int x1, int y1,
- int x2, int y2
- ) = 0;
-
- /**
- * Update the Canvas' viewport (used when the viewport changes without using SetViewPort()
- * eg: Shadow buffers and FBOs
- */
-
- virtual
- void
- UpdateViewPort(
- int x1, int y1,
- int x2, int y2
- ) = 0;
-
- /**
- * Get the visible viewport
- */
- virtual
- const int*
- GetViewPort() = 0;
-
- virtual
- void
- SetMouseState(
- RAS_MouseState mousestate
- )=0;
-
- virtual
- void
- SetMousePosition(
- int x,
- int y
- )=0;
-
- virtual
- RAS_MouseState
- GetMouseState()
- {
- return m_mousestate;
- }
-
- virtual
- void
- MakeScreenShot(
- const char* filename
- )=0;
-
- virtual void GetDisplayDimensions(int &width, int &height) = 0;
-
- virtual
- void
- ResizeWindow(
- int width,
- int height
- )=0;
-
- virtual
- void
- SetFullScreen(
- bool enable
- )=0;
-
- virtual
- bool
- GetFullScreen()=0;
-
-
-
-protected:
- RAS_MouseState m_mousestate;
- int m_frame; /// frame number for screenshots.
- TaskScheduler *m_taskscheduler;
- TaskPool *m_taskpool;
-
- /**
- * Saves screenshot data to a file. The actual compression and disk I/O is performed in
- * a separate thread.
- *
- * @param filename name of the file, can contain "###" for sequential numbering. A copy of the string
- * is made, so the pointer can be freed by the caller.
- * @param dumpsx width in pixels.
- * @param dumpsy height in pixels.
- * @param dumprect pixel data; ownership is passed to this function, which also frees the data.
- * @param im_format image format for the file; ownership is passed to this function, which also frees the data.
- */
- void save_screenshot(const char *filename, int dumpsx, int dumpsy, unsigned int *dumprect,
- ImageFormatData * im_format);
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_ICanvas")
-#endif
-};
-
-#endif /* __RAS_ICANVAS_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_ILightObject.h b/source/gameengine/Rasterizer/RAS_ILightObject.h
deleted file mode 100644
index a3d55c925d6..00000000000
--- a/source/gameengine/Rasterizer/RAS_ILightObject.h
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Mitchell Stokes
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_ILightObject.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_LIGHTOBJECT_H__
-#define __RAS_LIGHTOBJECT_H__
-
-class RAS_ICanvas;
-
-class KX_Camera;
-class KX_Scene;
-
-class MT_Transform;
-class MT_Matrix4x4;
-
-struct Image;
-
-class RAS_ILightObject
-{
-public:
- enum LightType {
- LIGHT_SPOT,
- LIGHT_SUN,
- LIGHT_NORMAL
- };
- bool m_modified;
- int m_layer;
- void *m_scene;
- void *m_light;
-
- float m_energy;
- float m_distance;
- float m_shadowclipstart;
- float m_shadowfrustumsize;
- float m_shadowclipend;
- float m_shadowbias;
- float m_shadowbleedbias;
- short m_shadowmaptype;
- float m_shadowcolor[3];
-
- float m_color[3];
-
- float m_att1;
- float m_att2;
- float m_coeff_const, m_coeff_lin, m_coeff_quad;
- float m_spotsize;
- float m_spotblend;
-
- LightType m_type;
-
- bool m_nodiffuse;
- bool m_nospecular;
- bool m_glsl;
-
- virtual ~RAS_ILightObject() {}
- virtual RAS_ILightObject* Clone() = 0;
-
- virtual bool HasShadowBuffer() = 0;
- virtual int GetShadowBindCode() = 0;
- virtual MT_Matrix4x4 GetShadowMatrix() = 0;
- virtual int GetShadowLayer() = 0;
- virtual void BindShadowBuffer(RAS_ICanvas *canvas, KX_Camera *cam, MT_Transform& camtrans) = 0;
- virtual void UnbindShadowBuffer() = 0;
- virtual Image *GetTextureImage(short texslot) = 0;
- virtual void Update() = 0;
-};
-
-#endif /* __RAS_LIGHTOBJECT_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_IOffScreen.h b/source/gameengine/Rasterizer/RAS_IOffScreen.h
deleted file mode 100644
index d61a31504b8..00000000000
--- a/source/gameengine/Rasterizer/RAS_IOffScreen.h
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_IOffScreen.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_OFFSCREEN_H__
-#define __RAS_OFFSCREEN_H__
-
-#include "EXP_Python.h"
-
-class RAS_ICanvas;
-
-class MT_Transform;
-
-struct Image;
-
-class RAS_IOffScreen
-{
-public:
- enum RAS_OFS_BIND_MODE {
- RAS_OFS_BIND_RENDER = 0,
- RAS_OFS_BIND_READ,
- };
- enum RAS_OFS_RENDER_TARGET {
- RAS_OFS_RENDER_BUFFER = 0, // use render buffer as render target
- RAS_OFS_RENDER_TEXTURE, // use texture as render target
- };
-
- int m_width;
- int m_height;
- int m_samples;
- int m_color; // if used, holds the texture object, 0 if not used
-
- virtual ~RAS_IOffScreen() {}
-
- virtual bool Create(int width, int height, int samples, RAS_OFS_RENDER_TARGET target) = 0;
- virtual void Destroy() = 0;
- virtual void Bind(RAS_OFS_BIND_MODE mode) = 0;
- virtual void Blit() = 0;
- virtual void Unbind() = 0;
- virtual void MipMap() = 0;
-
- virtual int GetWidth() { return m_width; }
- virtual int GetHeight() { return m_height; }
- virtual int GetSamples() { return m_samples; }
- virtual int GetColor() { return m_color; }
-};
-
-#ifdef WITH_PYTHON
-typedef struct {
- PyObject_HEAD
- RAS_IOffScreen *ofs;
-} PyRASOffScreen;
-
-extern PyTypeObject PyRASOffScreen_Type;
-#endif
-
-#endif /* __RAS_OFFSCREEN_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
deleted file mode 100644
index 2a736aa7deb..00000000000
--- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
+++ /dev/null
@@ -1,296 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_IPolygonMaterial.cpp
- * \ingroup bgerast
- */
-
-
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_IRasterizer.h"
-
-#include "DNA_material_types.h"
-
-void RAS_IPolyMaterial::Initialize(
- const STR_String& texname,
- const STR_String& matname,
- int materialindex,
- int tile,
- int tilexrep,
- int tileyrep,
- int alphablend,
- bool alpha,
- bool zsort,
- bool light,
- bool image,
- struct GameSettings* game)
-{
- m_texturename = texname;
- m_materialname = matname;
- m_materialindex = materialindex;
- m_tile = tile;
- m_tilexrep = tilexrep;
- m_tileyrep = tileyrep;
- m_alphablend = alphablend;
- m_alpha = alpha;
- m_zsort = zsort;
- m_light = light;
- m_polymatid = m_newpolymatid++;
- m_flag = 0;
- m_multimode = 0;
- m_shininess = 35.0f;
- m_specular.setValue(0.5f,0.5f,0.5f);
- m_specularity = 1.0f;
- m_diffuse.setValue(0.5f,0.5f,0.5f);
- m_drawingmode = ConvertFaceMode(game, image);
-}
-
-RAS_IPolyMaterial::RAS_IPolyMaterial()
- : m_texturename("__Dummy_Texture_Name__"),
- m_materialname("__Dummy_Material_Name__"),
- m_tile(0),
- m_tilexrep(0),
- m_tileyrep(0),
- m_drawingmode (0),
- m_alphablend(0),
- m_alpha(false),
- m_zsort(false),
- m_light(false),
- m_materialindex(0),
- m_polymatid(0),
- m_flag(0),
- m_multimode(0)
-{
- m_shininess = 35.0f;
- m_specular = MT_Vector3(0.5f,0.5f,0.5f);
- m_specularity = 1.0f;
- m_diffuse = MT_Vector3(0.5f,0.5f,0.5f);
-}
-
-RAS_IPolyMaterial::RAS_IPolyMaterial(const STR_String& texname,
- const STR_String& matname,
- int materialindex,
- int tile,
- int tilexrep,
- int tileyrep,
- int alphablend,
- bool alpha,
- bool zsort)
- : m_texturename(texname),
- m_materialname(matname),
- m_tile(tile),
- m_tilexrep(tilexrep),
- m_tileyrep(tileyrep),
- m_alphablend(alphablend),
- m_alpha(alpha),
- m_zsort(zsort),
- m_materialindex(materialindex),
- m_polymatid(m_newpolymatid++),
- m_flag(0),
- m_multimode(0)
-{
- m_shininess = 35.0f;
- m_specular = MT_Vector3(0.5f,0.5f,0.5f);
- m_specularity = 1.0f;
- m_diffuse = MT_Vector3(0.5f,0.5f,0.5f);
-}
-
-
-bool RAS_IPolyMaterial::Equals(const RAS_IPolyMaterial& lhs) const
-{
- if (m_flag &RAS_BLENDERMAT)
- {
- bool test = (
- this->m_multimode == lhs.m_multimode &&
- this->m_flag == lhs.m_flag &&
- this->m_drawingmode == lhs.m_drawingmode &&
- this->m_alphablend == lhs.m_alphablend &&
- this->m_texturename.hash() == lhs.m_texturename.hash() &&
- this->m_materialname.hash() == lhs.m_materialname.hash()
- );
-
- return test;
- }
- else
- {
- return (
- this->m_tile == lhs.m_tile &&
- this->m_tilexrep == lhs.m_tilexrep &&
- this->m_tileyrep == lhs.m_tileyrep &&
- this->m_alphablend == lhs.m_alphablend &&
- this->m_alpha == lhs.m_alpha &&
- this->m_zsort == lhs.m_zsort &&
- this->m_light == lhs.m_light &&
- this->m_drawingmode == lhs.m_drawingmode &&
- this->m_texturename.hash() == lhs.m_texturename.hash() &&
- this->m_materialname.hash() == lhs.m_materialname.hash()
- );
- }
-}
-
-int RAS_IPolyMaterial::ConvertFaceMode(struct GameSettings *game, bool image) const
-{
- if (!game) return (image?GEMAT_TEX:0);
-
- int modefinal = 0;
-
- int orimode = game->face_orientation;
- int alpha_blend = game->alpha_blend;
- int flags = game->flag & (GEMAT_TEXT | GEMAT_BACKCULL);
-
- modefinal = orimode | alpha_blend | flags;
- modefinal |= (image ? GEMAT_TEX : 0);
-
- return modefinal;
-}
-
-void RAS_IPolyMaterial::GetMaterialRGBAColor(unsigned char *rgba) const
-{
- *rgba++ = 0xFF;
- *rgba++ = 0xFF;
- *rgba++ = 0xFF;
- *rgba++ = 0xFF;
-}
-
-bool RAS_IPolyMaterial::Less(const RAS_IPolyMaterial& rhs) const
-{
- if (Equals(rhs))
- return false;
-
- return m_polymatid < rhs.m_polymatid;
-}
-
-bool RAS_IPolyMaterial::IsAlpha() const
-{
- return m_alpha || m_zsort;
-}
-
-bool RAS_IPolyMaterial::IsZSort() const
-{
- return m_zsort;
-}
-
-unsigned int RAS_IPolyMaterial::hash() const
-{
- return m_texturename.hash();
-}
-
-int RAS_IPolyMaterial::GetDrawingMode() const
-{
- return m_drawingmode;
-}
-
-const STR_String& RAS_IPolyMaterial::GetMaterialName() const
-{
- return m_materialname;
-}
-
-dword RAS_IPolyMaterial::GetMaterialNameHash() const
-{
- return m_materialname.hash();
-}
-
-const STR_String& RAS_IPolyMaterial::GetTextureName() const
-{
- return m_texturename;
-}
-
-int RAS_IPolyMaterial::GetMaterialIndex() const
-{
- return m_materialindex;
-}
-
-Material *RAS_IPolyMaterial::GetBlenderMaterial() const
-{
- return NULL;
-}
-
-Image *RAS_IPolyMaterial::GetBlenderImage() const
-{
- return NULL;
-}
-MTexPoly *RAS_IPolyMaterial::GetMTexPoly() const
-{
- return NULL;
-}
-
-unsigned int *RAS_IPolyMaterial::GetMCol() const
-{
- return NULL;
-}
-
-Scene* RAS_IPolyMaterial::GetBlenderScene() const
-{
- return NULL;
-}
-
-void RAS_IPolyMaterial::ReleaseMaterial()
-{
-}
-
-unsigned int RAS_IPolyMaterial::GetFlag() const
-{
- return m_flag;
-}
-
-bool RAS_IPolyMaterial::UsesLighting(RAS_IRasterizer *rasty) const
-{
- bool dolights = false;
-
- if (m_flag & RAS_BLENDERMAT) {
- dolights = (m_flag & RAS_MULTILIGHT) != 0;
- }
- else if (rasty->GetDrawingMode() < RAS_IRasterizer::KX_SOLID) {
- /* pass */
- }
- else if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW) {
- /* pass */
- }
- else {
- dolights = m_light;
- }
-
- return dolights;
-}
-
-bool RAS_IPolyMaterial::CastsShadows() const
-{
- return (m_flag & RAS_CASTSHADOW) != 0;
-}
-
-bool RAS_IPolyMaterial::OnlyShadow() const
-{
- return (m_flag & RAS_ONLYSHADOW) != 0;
-}
-
-bool RAS_IPolyMaterial::UsesObjectColor() const
-{
- return !(m_flag & RAS_BLENDERGLSL);
-}
-
-unsigned int RAS_IPolyMaterial::m_newpolymatid = 0;
-
diff --git a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h b/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
deleted file mode 100644
index a34f7a9b390..00000000000
--- a/source/gameengine/Rasterizer/RAS_IPolygonMaterial.h
+++ /dev/null
@@ -1,208 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_IPolygonMaterial.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_IPOLYGONMATERIAL_H__
-#define __RAS_IPOLYGONMATERIAL_H__
-
-#include "STR_HashedString.h"
-
-#include "MT_Vector3.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class RAS_IRasterizer;
-struct MTexPoly;
-struct Material;
-struct Image;
-struct Scene;
-class SCA_IScene;
-struct GameSettings;
-
-enum MaterialProps
-{
- RAS_ZSORT =1,
- RAS_TRANSPARENT =2,
- RAS_TRIANGLE =4,
- RAS_MULTITEX =8,
- RAS_MULTILIGHT =16,
- RAS_BLENDERMAT =32,
- RAS_GLSHADER =64,
- RAS_AUTOGEN =128,
- RAS_NORMAL =256,
- RAS_DEFMULTI =512,
- RAS_BLENDERGLSL =1024,
- RAS_CASTSHADOW =2048,
- RAS_ONLYSHADOW =4096,
-};
-
-/**
- * Polygon Material on which the material buckets are sorted
- *
- */
-class RAS_IPolyMaterial
-{
- //todo: remove these variables from this interface/protocol class
-protected:
- STR_HashedString m_texturename;
- STR_HashedString m_materialname; //also needed for touchsensor
- int m_tile;
- int m_tilexrep,m_tileyrep;
- int m_drawingmode;
- int m_alphablend;
- bool m_alpha;
- bool m_zsort;
- bool m_light;
- int m_materialindex;
-
- unsigned int m_polymatid;
- static unsigned int m_newpolymatid;
-
- // will move...
- unsigned int m_flag;//MaterialProps
- int m_multimode; // sum of values
-public:
- MT_Vector3 m_diffuse;
- float m_shininess;
- MT_Vector3 m_specular;
- float m_specularity;
-
- /** Used to store caching information for materials. */
- typedef void* TCachingInfo;
-
- // care! these are taken from blender polygonflags, see file DNA_mesh_types.h for #define TF_BILLBOARD etc.
- enum MaterialFlags
- {
- BILLBOARD_SCREENALIGNED = 512, /* GEMAT_HALO */
- BILLBOARD_AXISALIGNED = 1024, /* GEMAT_BILLBOARD */
- SHADOW =2048 /* GEMAT_SHADOW */
- };
-
- RAS_IPolyMaterial();
- RAS_IPolyMaterial(const STR_String& texname,
- const STR_String& matname,
- int materialindex,
- int tile,
- int tilexrep,
- int tileyrep,
- int transp,
- bool alpha,
- bool zsort);
- void Initialize(const STR_String& texname,
- const STR_String& matname,
- int materialindex,
- int tile,
- int tilexrep,
- int tileyrep,
- int transp,
- bool alpha,
- bool zsort,
- bool light,
- bool image,
- struct GameSettings* game);
-
- virtual ~RAS_IPolyMaterial() {}
-
- /**
- * Returns the caching information for this material,
- * This can be used to speed up the rasterizing process.
- * \return The caching information.
- */
- virtual TCachingInfo GetCachingInfo(void) const { return 0; }
-
- /**
- * Activates the material in the rasterizer.
- * On entry, the cachingInfo contains info about the last activated material.
- * On exit, the cachingInfo should contain updated info about this material.
- * \param rasty The rasterizer in which the material should be active.
- * \param cachingInfo The information about the material used to speed up rasterizing.
- */
- virtual bool Activate(RAS_IRasterizer* rasty, TCachingInfo& cachingInfo) const
- {
- return false;
- }
- virtual void ActivateMeshSlot(const class RAS_MeshSlot & ms, RAS_IRasterizer* rasty) const {}
-
- virtual bool Equals(const RAS_IPolyMaterial& lhs) const;
- bool Less(const RAS_IPolyMaterial& rhs) const;
- //int GetLightLayer() const;
- bool IsAlpha() const;
- bool IsZSort() const;
- unsigned int hash() const;
- int GetDrawingMode() const;
- const STR_String& GetMaterialName() const;
- dword GetMaterialNameHash() const;
- const STR_String& GetTextureName() const;
- unsigned int GetFlag() const;
- int GetMaterialIndex() const;
-
- virtual Material* GetBlenderMaterial() const;
- virtual Image* GetBlenderImage() const;
- virtual MTexPoly* GetMTexPoly() const;
- virtual unsigned int* GetMCol() const;
- virtual Scene* GetBlenderScene() const;
- virtual void ReleaseMaterial();
- virtual void GetMaterialRGBAColor(unsigned char *rgba) const;
- virtual bool UsesLighting(RAS_IRasterizer *rasty) const;
- virtual bool UsesObjectColor() const;
- virtual bool CastsShadows() const;
- virtual bool OnlyShadow() const;
-
- virtual void Replace_IScene(SCA_IScene *val) {} /* overridden by KX_BlenderMaterial */
-
- /**
- * \return the equivalent drawing mode for the material settings (equivalent to old TexFace tface->mode).
- */
- int ConvertFaceMode(struct GameSettings *game, bool image) const;
-
- /*
- * PreCalculate texture gen
- */
- virtual void OnConstruction() {}
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_IPolyMaterial")
-#endif
-};
-
-inline bool operator ==( const RAS_IPolyMaterial & rhs,const RAS_IPolyMaterial & lhs)
-{
- return ( rhs.Equals(lhs));
-}
-
-inline bool operator < ( const RAS_IPolyMaterial & lhs, const RAS_IPolyMaterial & rhs)
-{
- return lhs.Less(rhs);
-}
-
-#endif /* __RAS_IPOLYGONMATERIAL_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_IRasterizer.h b/source/gameengine/Rasterizer/RAS_IRasterizer.h
deleted file mode 100644
index dc92408915b..00000000000
--- a/source/gameengine/Rasterizer/RAS_IRasterizer.h
+++ /dev/null
@@ -1,506 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_IRasterizer.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_IRASTERIZER_H__
-#define __RAS_IRASTERIZER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "STR_HashedString.h"
-
-#include "MT_CmMatrix4x4.h"
-#include "MT_Matrix4x4.h"
-
-#include "RAS_TexVert.h"
-
-#include <vector>
-using namespace std;
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class RAS_ICanvas;
-class RAS_IPolyMaterial;
-class RAS_MeshSlot;
-class RAS_ILightObject;
-class SCA_IScene;
-class RAS_IOffScreen;
-class RAS_ISync;
-
-typedef vector<unsigned short> KX_IndexArray;
-typedef vector<RAS_TexVert> KX_VertexArray;
-typedef vector<KX_VertexArray *> vecVertexArray;
-typedef vector<KX_IndexArray *> vecIndexArrays;
-
-/**
- * 3D rendering device context interface.
- */
-class RAS_IRasterizer
-{
-public:
- enum RAS_TEXT_RENDER_MODE {
- RAS_TEXT_RENDER_NODEF = 0,
- RAS_TEXT_NORMAL,
- RAS_TEXT_PADDED,
- RAS_TEXT_MAX,
- };
-
- RAS_IRasterizer(RAS_ICanvas* canv) {};
- virtual ~RAS_IRasterizer() {};
-
- /**
- * Drawing types
- */
- enum DrawType {
- KX_BOUNDINGBOX = 1,
- KX_WIREFRAME,
- KX_SOLID,
- KX_SHADED,
- KX_TEXTURED,
- KX_SHADOW,
- };
-
- /**
- * Drawing modes
- */
-
- enum DrawMode {
- KX_MODE_LINES = 1,
- KX_MODE_TRIANGLES,
- KX_MODE_QUADS,
- };
-
- /**
- * Valid SetDepthMask parameters
- */
- enum DepthMask {
- KX_DEPTHMASK_ENABLED = 1,
- KX_DEPTHMASK_DISABLED,
- };
-
- /**
- */
- enum {
- RAS_RENDER_3DPOLYGON_TEXT = 64, /* GEMAT_TEXT */
- KX_BACKCULL = 16, /* GEMAT_BACKCULL */
- KX_TEX = 4096, /* GEMAT_TEX */
- KX_LINES = 32768,
- };
-
- /**
- * Stereo mode types
- */
- enum StereoMode {
- RAS_STEREO_NOSTEREO = 1,
- RAS_STEREO_QUADBUFFERED,
- RAS_STEREO_ABOVEBELOW,
- RAS_STEREO_INTERLACED,
- RAS_STEREO_ANAGLYPH,
- RAS_STEREO_SIDEBYSIDE,
- RAS_STEREO_VINTERLACE,
- RAS_STEREO_DOME,
- RAS_STEREO_3DTVTOPBOTTOM,
-
- RAS_STEREO_MAXSTEREO
- };
-
- /**
- * Texture gen modes.
- */
- enum TexCoGen {
- RAS_TEXCO_GEN, /* < GPU will generate texture coordinates */
- RAS_TEXCO_ORCO, /* < Vertex coordinates (object space) */
- RAS_TEXCO_GLOB, /* < Vertex coordinates (world space) */
- RAS_TEXCO_UV, /* < UV coordinates */
- RAS_TEXCO_OBJECT, /* < Use another object's position as coordinates */
- RAS_TEXCO_LAVECTOR, /* < Light vector as coordinates */
- RAS_TEXCO_VIEW, /* < View vector as coordinates */
- RAS_TEXCO_STICKY, /* < Sticky coordinates */
- RAS_TEXCO_WINDOW, /* < Window coordinates */
- RAS_TEXCO_NORM, /* < Normal coordinates */
- RAS_TEXTANGENT, /* < */
- RAS_TEXCO_VCOL, /* < Vertex Color */
- RAS_TEXCO_DISABLE, /* < Disable this texture unit (cached) */
- };
-
- /**
- * Render pass identifiers for stereo.
- */
- enum StereoEye {
- RAS_STEREO_LEFTEYE = 1,
- RAS_STEREO_RIGHTEYE,
- };
-
- /**
- * Mipmap options
- */
- enum MipmapOption {
- RAS_MIPMAP_NONE,
- RAS_MIPMAP_NEAREST,
- RAS_MIPMAP_LINEAR,
-
- RAS_MIPMAP_MAX, /* Should always be last */
- };
-
- /**
- * SetDepthMask enables or disables writing a fragment's depth value
- * to the Z buffer.
- */
- virtual void SetDepthMask(DepthMask depthmask) = 0;
-
- /**
- * SetMaterial sets the material settings for subsequent primitives
- * to be rendered with.
- * The material will be cached.
- */
- virtual bool SetMaterial(const RAS_IPolyMaterial &mat) = 0;
-
- /**
- * Init initializes the renderer.
- */
- virtual bool Init() = 0;
-
- /**
- * Exit cleans up the renderer.
- */
- virtual void Exit() = 0;
-
- /**
- * BeginFrame is called at the start of each frame.
- */
- virtual bool BeginFrame(double time) = 0;
-
- /**
- * ClearColorBuffer clears the color buffer.
- */
- virtual void ClearColorBuffer() = 0;
-
- /**
- * ClearDepthBuffer clears the depth buffer.
- */
- virtual void ClearDepthBuffer() = 0;
-
- /**
- * ClearCachingInfo clears the currently cached material.
- */
- virtual void ClearCachingInfo(void) = 0;
-
- /**
- * EndFrame is called at the end of each frame.
- */
- virtual void EndFrame() = 0;
-
- /**
- * SetRenderArea sets the render area from the 2d canvas.
- * Returns true if only of subset of the canvas is used.
- */
- virtual void SetRenderArea() = 0;
-
- // Stereo Functions
- /**
- * SetStereoMode will set the stereo mode
- */
- virtual void SetStereoMode(const StereoMode stereomode) = 0;
-
- /**
- * Stereo can be used to query if the rasterizer is in stereo mode.
- * \return true if stereo mode is enabled.
- */
- virtual bool Stereo() = 0;
- virtual StereoMode GetStereoMode() = 0;
- virtual bool InterlacedStereo() = 0;
-
- /**
- * Sets which eye buffer subsequent primitives will be rendered to.
- */
- virtual void SetEye(const StereoEye eye) = 0;
- virtual StereoEye GetEye() = 0;
-
- /**
- * Sets the distance between eyes for stereo mode.
- */
- virtual void SetEyeSeparation(const float eyeseparation) = 0;
- virtual float GetEyeSeparation() = 0;
-
- /**
- * Sets the focal length for stereo mode.
- */
- virtual void SetFocalLength(const float focallength) = 0;
- virtual float GetFocalLength() = 0;
-
- /**
- * Create an offscreen render buffer that can be used as target for render.
- * For the time being, it is only used in VideoTexture for custom render.
- */
- virtual RAS_IOffScreen *CreateOffScreen(int width, int height, int samples, int target) = 0;
-
- /**
- * Create a sync object
- * For use with offscreen render
- */
- virtual RAS_ISync *CreateSync(int type) = 0;
-
- /**
- * SwapBuffers swaps the back buffer with the front buffer.
- */
- virtual void SwapBuffers() = 0;
-
- // Drawing Functions
- /**
- * IndexPrimitives: Renders primitives from mesh slot.
- */
- virtual void IndexPrimitives(class RAS_MeshSlot &ms) = 0;
-
- /**
- * IndexPrimitives_3DText will render text into the polygons.
- */
- virtual void IndexPrimitives_3DText(class RAS_MeshSlot &ms, class RAS_IPolyMaterial *polymat) = 0;
-
- virtual void SetProjectionMatrix(MT_CmMatrix4x4 &mat) = 0;
-
- /* This one should become our final version, methinks. */
- /**
- * Set the projection matrix for the rasterizer. This projects
- * from camera coordinates to window coordinates.
- * \param mat The projection matrix.
- */
- virtual void SetProjectionMatrix(const MT_Matrix4x4 &mat) = 0;
-
- /**
- * Sets the modelview matrix.
- */
- virtual void SetViewMatrix(const MT_Matrix4x4 &mat, const MT_Matrix3x3 &ori,
- const MT_Point3 &pos, const MT_Vector3 &scale, bool perspective) = 0;
-
- /**
- */
- virtual const MT_Point3& GetCameraPosition() = 0;
- virtual bool GetCameraOrtho() = 0;
-
- /**
- * Fog
- */
- virtual void SetFog(short type, float start, float dist, float intensity, float color[3]) = 0;
- virtual void DisplayFog() = 0;
- virtual void EnableFog(bool enable) = 0;
-
- virtual void SetBackColor(float color[3]) = 0;
-
- /**
- * \param drawingmode = KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
- */
- virtual void SetDrawingMode(int drawingmode) = 0;
-
- /**
- * \return the current drawing mode: KX_BOUNDINGBOX, KX_WIREFRAME, KX_SOLID, KX_SHADED or KX_TEXTURED.
- */
- virtual int GetDrawingMode() = 0;
-
- /**
- * Sets face culling
- */
- virtual void SetCullFace(bool enable) = 0;
-
- /**
- * Sets wireframe mode.
- */
- virtual void SetLines(bool enable) = 0;
-
- /**
- */
- virtual double GetTime() = 0;
-
- /**
- * Generates a projection matrix from the specified frustum.
- * \param left the left clipping plane
- * \param right the right clipping plane
- * \param bottom the bottom clipping plane
- * \param top the top clipping plane
- * \param frustnear the near clipping plane
- * \param frustfar the far clipping plane
- * \return a 4x4 matrix representing the projection transform.
- */
- virtual MT_Matrix4x4 GetFrustumMatrix(
- float left, float right, float bottom, float top,
- float frustnear, float frustfar,
- float focallength = 0.0f, bool perspective = true) = 0;
-
- /**
- * Generates a orthographic projection matrix from the specified frustum.
- * \param left the left clipping plane
- * \param right the right clipping plane
- * \param bottom the bottom clipping plane
- * \param top the top clipping plane
- * \param frustnear the near clipping plane
- * \param frustfar the far clipping plane
- * \return a 4x4 matrix representing the projection transform.
- */
- virtual MT_Matrix4x4 GetOrthoMatrix(
- float left, float right, float bottom, float top,
- float frustnear, float frustfar) = 0;
-
- /**
- * Sets the specular color component of the lighting equation.
- */
- virtual void SetSpecularity(float specX, float specY, float specZ, float specval) = 0;
-
- /**
- * Sets the specular exponent component of the lighting equation.
- */
- virtual void SetShinyness(float shiny) = 0;
-
- /**
- * Sets the diffuse color component of the lighting equation.
- */
- virtual void SetDiffuse(float difX,float difY, float difZ, float diffuse) = 0;
-
- /**
- * Sets the emissive color component of the lighting equation.
- */
- virtual void SetEmissive(float eX, float eY, float eZ, float e) = 0;
-
- virtual void SetAmbientColor(float color[3]) = 0;
- virtual void SetAmbient(float factor) = 0;
-
- /**
- * Sets a polygon offset. z depth will be: z1 = mult*z0 + add
- */
- virtual void SetPolygonOffset(float mult, float add) = 0;
-
- virtual void DrawDebugLine(SCA_IScene *scene, const MT_Vector3 &from, const MT_Vector3 &to, const MT_Vector3& color) = 0;
- virtual void DrawDebugCircle(SCA_IScene *scene, const MT_Vector3 &center, const MT_Scalar radius,
- const MT_Vector3 &color, const MT_Vector3 &normal, int nsector) = 0;
- virtual void FlushDebugShapes(SCA_IScene *scene) = 0;
-
- virtual void SetTexCoordNum(int num) = 0;
- virtual void SetAttribNum(int num) = 0;
- virtual void SetTexCoord(TexCoGen coords, int unit) = 0;
- virtual void SetAttrib(TexCoGen coords, int unit, int layer = 0) = 0;
-
- virtual const MT_Matrix4x4 &GetViewMatrix() const = 0;
- virtual const MT_Matrix4x4 &GetViewInvMatrix() const = 0;
-
- virtual bool QueryLists() { return false; }
- virtual bool QueryArrays() { return false; }
-
- virtual void EnableMotionBlur(float motionblurvalue) = 0;
- virtual void DisableMotionBlur() = 0;
-
- virtual float GetMotionBlurValue() = 0;
- virtual int GetMotionBlurState() = 0;
- virtual void SetMotionBlurState(int newstate) = 0;
-
- virtual void SetAlphaBlend(int alphablend) = 0;
- virtual void SetFrontFace(bool ccw) = 0;
-
- virtual void SetAnisotropicFiltering(short level) = 0;
- virtual short GetAnisotropicFiltering() = 0;
-
- virtual void SetMipmapping(MipmapOption val) = 0;
- virtual MipmapOption GetMipmapping() = 0;
-
- virtual void SetUsingOverrideShader(bool val) = 0;
- virtual bool GetUsingOverrideShader() = 0;
-
- /**
- * Render Tools
- */
- virtual void applyTransform(float *oglmatrix, int drawingmode) = 0;
-
- /**
- * Renders 2D boxes.
- * \param xco Position on the screen (origin in lower left corner).
- * \param yco Position on the screen (origin in lower left corner).
- * \param width Width of the canvas to draw to.
- * \param height Height of the canvas to draw to.
- * \param percentage Percentage of bar.
- */
- virtual void RenderBox2D(int xco, int yco, int width, int height, float percentage) = 0;
-
- /**
- * Renders 3D text string using BFL.
- * \param fontid The id of the font.
- * \param text The string to render.
- * \param size The size of the text.
- * \param dpi The resolution of the text.
- * \param color The color of the object.
- * \param mat The Matrix of the text object.
- * \param aspect A scaling factor to compensate for the size.
- */
- virtual void RenderText3D(
- int fontid, const char *text, int size, int dpi,
- const float color[4], const float mat[16], float aspect) = 0;
-
- /**
- * Renders 2D text string.
- * \param mode The type of text
- * \param text The string to render.
- * \param xco Position on the screen (origin in lower left corner).
- * \param yco Position on the screen (origin in lower left corner).
- * \param width Width of the canvas to draw to.
- * \param height Height of the canvas to draw to.
- */
- virtual void RenderText2D(
- RAS_TEXT_RENDER_MODE mode, const char *text,
- int xco, int yco, int width, int height) = 0;
-
- virtual void ProcessLighting(bool uselights, const MT_Transform &trans) = 0;
-
- virtual void PushMatrix() = 0;
-
- virtual void PopMatrix() = 0;
-
- virtual RAS_ILightObject *CreateLight() = 0;
-
- virtual void AddLight(RAS_ILightObject *lightobject) = 0;
-
- virtual void RemoveLight(RAS_ILightObject *lightobject) = 0;
-
- virtual void MotionBlur() = 0;
-
- virtual void SetClientObject(void *obj) = 0;
-
- virtual void SetAuxilaryClientInfo(void *inf) = 0;
-
- /**
- * Prints information about what the hardware supports.
- */
- virtual void PrintHardwareInfo() = 0;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_IRasterizer")
-#endif
-};
-
-#endif /* __RAS_IRASTERIZER_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_ISync.h b/source/gameengine/Rasterizer/RAS_ISync.h
deleted file mode 100644
index 7e34172c2a3..00000000000
--- a/source/gameengine/Rasterizer/RAS_ISync.h
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_ISync.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_ISYNC_H__
-#define __RAS_ISYNC_H__
-
-class RAS_ISync
-{
-public:
- enum RAS_SYNC_TYPE {
- RAS_SYNC_TYPE_FENCE = 0,
- };
- virtual ~RAS_ISync() {}
-
- virtual bool Create(RAS_SYNC_TYPE type) = 0;
- virtual void Destroy() = 0;
- virtual void Wait() = 0;
-};
-
-#endif /* __RAS_ISYNC_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp b/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
deleted file mode 100644
index 9cd8f77adfd..00000000000
--- a/source/gameengine/Rasterizer/RAS_MaterialBucket.cpp
+++ /dev/null
@@ -1,679 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_MaterialBucket.cpp
- * \ingroup bgerast
- */
-
-
-#include "RAS_MaterialBucket.h"
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#ifdef WIN32
-#include <windows.h>
-#endif // WIN32
-
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_TexVert.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Deformer.h" // __NLA
-
-/* mesh slot */
-
-RAS_MeshSlot::RAS_MeshSlot() : SG_QList()
-{
- m_clientObj = NULL;
- m_pDeformer = NULL;
- m_OpenGLMatrix = NULL;
- m_mesh = NULL;
- m_bucket = NULL;
- m_bVisible = false;
- m_bCulled = true;
- m_bObjectColor = false;
- m_RGBAcolor = MT_Vector4(0.0f, 0.0f, 0.0f, 0.0f);
- m_DisplayList = NULL;
- m_bDisplayList = true;
- m_joinSlot = NULL;
- m_pDerivedMesh = NULL;
-}
-
-RAS_MeshSlot::~RAS_MeshSlot()
-{
- RAS_DisplayArrayList::iterator it;
-
-#ifdef USE_SPLIT
- Split(true);
-
- while (m_joinedSlots.size())
- m_joinedSlots.front()->Split(true);
-#endif
-
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- (*it)->m_users--;
- if ((*it)->m_users == 0)
- delete *it;
- }
-
- if (m_DisplayList) {
- m_DisplayList->Release();
- m_DisplayList = NULL;
- }
-}
-
-RAS_MeshSlot::RAS_MeshSlot(const RAS_MeshSlot& slot) : SG_QList()
-{
- RAS_DisplayArrayList::iterator it;
-
- m_clientObj = NULL;
- m_pDeformer = NULL;
- m_pDerivedMesh = NULL;
- m_OpenGLMatrix = NULL;
- m_mesh = slot.m_mesh;
- m_bucket = slot.m_bucket;
- m_bVisible = slot.m_bVisible;
- m_bCulled = slot.m_bCulled;
- m_bObjectColor = slot.m_bObjectColor;
- m_RGBAcolor = slot.m_RGBAcolor;
- m_DisplayList = NULL;
- m_bDisplayList = slot.m_bDisplayList;
- m_joinSlot = NULL;
- m_currentArray = slot.m_currentArray;
- m_displayArrays = slot.m_displayArrays;
- m_joinedSlots = slot.m_joinedSlots;
-
- m_startarray = slot.m_startarray;
- m_startvertex = slot.m_startvertex;
- m_startindex = slot.m_startindex;
- m_endarray = slot.m_endarray;
- m_endvertex = slot.m_endvertex;
- m_endindex = slot.m_endindex;
-
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- // don't copy display arrays for now because it breaks python
- // access to vertices, but we'll need a solution if we want to
- // join display arrays for reducing draw calls.
- //*it = new RAS_DisplayArray(**it);
- //(*it)->m_users = 1;
-
- (*it)->m_users++;
- }
-}
-
-void RAS_MeshSlot::init(RAS_MaterialBucket *bucket, int numverts)
-{
- m_bucket = bucket;
-
- SetDisplayArray(numverts);
-
- m_startarray = 0;
- m_startvertex = 0;
- m_startindex = 0;
- m_endarray = 0;
- m_endvertex = 0;
- m_endindex = 0;
-}
-
-void RAS_MeshSlot::begin(RAS_MeshSlot::iterator& it)
-{
- int startvertex, endvertex;
- int startindex, endindex;
-
- it.array = m_displayArrays.empty() ? NULL : m_displayArrays[m_startarray];
-
- if (it.array == NULL || it.array->m_index.size() == 0 || it.array->m_vertex.size() == 0) {
- it.array = NULL;
- it.vertex = NULL;
- it.index = NULL;
- it.startvertex = 0;
- it.endvertex = 0;
- it.totindex = 0;
- }
- else {
- startvertex = m_startvertex;
- endvertex = (m_startarray == m_endarray)? m_endvertex: it.array->m_vertex.size();
- startindex = m_startindex;
- endindex = (m_startarray == m_endarray)? m_endindex: it.array->m_index.size();
-
- it.vertex = &it.array->m_vertex[0];
- it.index = &it.array->m_index[startindex];
- it.startvertex = startvertex;
- it.endvertex = endvertex;
- it.totindex = endindex-startindex;
- it.arraynum = m_startarray;
- }
-}
-
-void RAS_MeshSlot::next(RAS_MeshSlot::iterator& it)
-{
- int startvertex, endvertex;
- int startindex, endindex;
-
- if (it.arraynum == (size_t)m_endarray) {
- it.array = NULL;
- it.vertex = NULL;
- it.index = NULL;
- it.startvertex = 0;
- it.endvertex = 0;
- it.totindex = 0;
- }
- else {
- it.arraynum++;
- it.array = m_displayArrays[it.arraynum];
-
- startindex = 0;
- endindex = (it.arraynum == (size_t)m_endarray)? m_endindex: it.array->m_index.size();
- startvertex = 0;
- endvertex = (it.arraynum == (size_t)m_endarray)? m_endvertex: it.array->m_vertex.size();
-
- it.vertex = &it.array->m_vertex[0];
- it.index = &it.array->m_index[startindex];
- it.startvertex = startvertex;
- it.endvertex = endvertex;
- it.totindex = endindex-startindex;
- }
-}
-
-bool RAS_MeshSlot::end(RAS_MeshSlot::iterator& it)
-{
- return (it.array == NULL);
-}
-
-RAS_DisplayArray *RAS_MeshSlot::CurrentDisplayArray()
-{
- return m_currentArray;
-}
-
-void RAS_MeshSlot::SetDisplayArray(int numverts)
-{
- RAS_DisplayArrayList::iterator it;
- RAS_DisplayArray *darray = NULL;
-
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- darray = *it;
-
- if (darray->m_type == numverts) {
- if (darray->m_index.size()+numverts >= RAS_DisplayArray::BUCKET_MAX_INDEX)
- darray = NULL;
- else if (darray->m_vertex.size()+numverts >= RAS_DisplayArray::BUCKET_MAX_VERTEX)
- darray = NULL;
- else
- break;
- }
- else
- darray = NULL;
- }
-
- if (!darray) {
- darray = new RAS_DisplayArray();
- darray->m_users = 1;
-
- if (numverts == 2) darray->m_type = RAS_DisplayArray::LINE;
- else if (numverts == 3) darray->m_type = RAS_DisplayArray::TRIANGLE;
- else darray->m_type = RAS_DisplayArray::QUAD;
-
- m_displayArrays.push_back(darray);
-
- if (numverts == 2)
- darray->m_type = RAS_DisplayArray::LINE;
- else if (numverts == 3)
- darray->m_type = RAS_DisplayArray::TRIANGLE;
- else if (numverts == 4)
- darray->m_type = RAS_DisplayArray::QUAD;
-
- m_endarray = m_displayArrays.size()-1;
- m_endvertex = 0;
- m_endindex = 0;
- }
-
- m_currentArray = darray;
-}
-
-void RAS_MeshSlot::AddPolygon(int numverts)
-{
- SetDisplayArray(numverts);
-}
-
-int RAS_MeshSlot::AddVertex(const RAS_TexVert& tv)
-{
- RAS_DisplayArray *darray;
- int offset;
-
- darray = m_currentArray;
- darray->m_vertex.push_back(tv);
- offset = darray->m_vertex.size()-1;
-
- if (darray == m_displayArrays[m_endarray])
- m_endvertex++;
-
- return offset;
-}
-
-void RAS_MeshSlot::AddPolygonVertex(int offset)
-{
- RAS_DisplayArray *darray;
-
- darray = m_currentArray;
- darray->m_index.push_back(offset);
-
- if (darray == m_displayArrays[m_endarray])
- m_endindex++;
-}
-
-void RAS_MeshSlot::UpdateDisplayArraysOffset()
-{
- unsigned int offset = 0;
- for (unsigned short i = 0; i < m_displayArrays.size(); ++i) {
- RAS_DisplayArray *darray = m_displayArrays[i];
- darray->m_offset = offset;
- offset += darray->m_vertex.size();
- }
-}
-
-void RAS_MeshSlot::SetDeformer(RAS_Deformer* deformer)
-{
- if (deformer && m_pDeformer != deformer) {
- RAS_DisplayArrayList::iterator it;
- if (deformer->ShareVertexArray()) {
- // this deformer uses the base vertex array, first release the current ones
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- (*it)->m_users--;
- if ((*it)->m_users == 0)
- delete *it;
- }
- m_displayArrays.clear();
- // then hook to the base ones
- RAS_MeshMaterial *mmat = m_mesh->GetMeshMaterial(m_bucket->GetPolyMaterial());
- if (mmat && mmat->m_baseslot) {
- m_displayArrays = mmat->m_baseslot->m_displayArrays;
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- (*it)->m_users++;
- }
- }
- }
- else {
- // no sharing
- // we create local copy of RAS_DisplayArray when we have a deformer:
- // this way we can avoid conflict between the vertex cache of duplicates
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- if (deformer->UseVertexArray()) {
- // the deformer makes use of vertex array, make sure we have our local copy
- if ((*it)->m_users > 1) {
- // only need to copy if there are other users
- // note that this is the usual case as vertex arrays are held by the material base slot
- RAS_DisplayArray *newarray = new RAS_DisplayArray(*(*it));
- newarray->m_users = 1;
- (*it)->m_users--;
- *it = newarray;
- }
- } else {
- // the deformer is not using vertex array (Modifier), release them
- (*it)->m_users--;
- if ((*it)->m_users == 0)
- delete *it;
- }
- }
- if (!deformer->UseVertexArray()) {
- m_displayArrays.clear();
- m_startarray = 0;
- m_startvertex = 0;
- m_startindex = 0;
- m_endarray = 0;
- m_endvertex = 0;
- m_endindex = 0;
- }
- }
- }
- m_pDeformer = deformer;
-}
-
-bool RAS_MeshSlot::Equals(RAS_MeshSlot *target)
-{
- if (!m_OpenGLMatrix || !target->m_OpenGLMatrix)
- return false;
- if (m_pDeformer || target->m_pDeformer)
- return false;
- if (m_bVisible != target->m_bVisible)
- return false;
- if (m_bObjectColor != target->m_bObjectColor)
- return false;
- if (m_bObjectColor && !(m_RGBAcolor == target->m_RGBAcolor))
- return false;
-
- return true;
-}
-
-bool RAS_MeshSlot::Join(RAS_MeshSlot *target, MT_Scalar distance)
-{
- RAS_DisplayArrayList::iterator it;
- iterator mit;
- size_t i;
-
- // verify if we can join
- if (m_joinSlot || (m_joinedSlots.empty() == false) || target->m_joinSlot)
- return false;
-
- if (!Equals(target))
- return false;
-
- MT_Vector3 co(&m_OpenGLMatrix[12]);
- MT_Vector3 targetco(&target->m_OpenGLMatrix[12]);
-
- if ((co - targetco).length() > distance)
- return false;
-
- MT_Matrix4x4 mat(m_OpenGLMatrix);
- MT_Matrix4x4 targetmat(target->m_OpenGLMatrix);
- targetmat.invert();
-
- MT_Matrix4x4 transform = targetmat*mat;
-
- // m_mesh, clientobj
- m_joinSlot = target;
- m_joinInvTransform = transform;
- m_joinInvTransform.invert();
- target->m_joinedSlots.push_back(this);
-
- MT_Matrix4x4 ntransform = m_joinInvTransform.transposed();
- ntransform[0][3] = ntransform[1][3] = ntransform[2][3] = 0.0f;
-
- for (begin(mit); !end(mit); next(mit))
- for (i=mit.startvertex; i<mit.endvertex; i++)
- mit.vertex[i].Transform(transform, ntransform);
-
- /* We know we'll need a list at least this big, reserve in advance */
- target->m_displayArrays.reserve(target->m_displayArrays.size() + m_displayArrays.size());
-
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- target->m_displayArrays.push_back(*it);
- target->m_endarray++;
- target->m_endvertex = target->m_displayArrays.back()->m_vertex.size();
- target->m_endindex = target->m_displayArrays.back()->m_index.size();
- }
-
- if (m_DisplayList) {
- m_DisplayList->Release();
- m_DisplayList = NULL;
- }
- if (target->m_DisplayList) {
- target->m_DisplayList->Release();
- target->m_DisplayList = NULL;
- }
-
- return true;
-#if 0
- return false;
-#endif
-}
-
-bool RAS_MeshSlot::Split(bool force)
-{
- list<RAS_MeshSlot*>::iterator jit;
- RAS_MeshSlot *target = m_joinSlot;
- RAS_DisplayArrayList::iterator it, jt;
- iterator mit;
- size_t i, found0 = 0, found1 = 0;
-
- if (target && (force || !Equals(target))) {
- m_joinSlot = NULL;
-
- for (jit=target->m_joinedSlots.begin(); jit!=target->m_joinedSlots.end(); jit++) {
- if (*jit == this) {
- target->m_joinedSlots.erase(jit);
- found0 = 1;
- break;
- }
- }
-
- if (!found0)
- abort();
-
- for (it=m_displayArrays.begin(); it!=m_displayArrays.end(); it++) {
- found1 = 0;
- for (jt=target->m_displayArrays.begin(); jt!=target->m_displayArrays.end(); jt++) {
- if (*jt == *it) {
- target->m_displayArrays.erase(jt);
- target->m_endarray--;
- found1 = 1;
- break;
- }
- }
-
- if (!found1)
- abort();
- }
-
- if (target->m_displayArrays.empty() == false) {
- target->m_endvertex = target->m_displayArrays.back()->m_vertex.size();
- target->m_endindex = target->m_displayArrays.back()->m_index.size();
- }
- else {
- target->m_endvertex = 0;
- target->m_endindex = 0;
- }
-
- MT_Matrix4x4 ntransform = m_joinInvTransform.inverse().transposed();
- ntransform[0][3] = ntransform[1][3] = ntransform[2][3] = 0.0f;
-
- for (begin(mit); !end(mit); next(mit))
- for (i=mit.startvertex; i<mit.endvertex; i++)
- mit.vertex[i].Transform(m_joinInvTransform, ntransform);
-
- if (target->m_DisplayList) {
- target->m_DisplayList->Release();
- target->m_DisplayList = NULL;
- }
-
- return true;
- }
-
- return false;
-}
-
-
-#ifdef USE_SPLIT
-bool RAS_MeshSlot::IsCulled()
-{
- if (m_joinSlot)
- return true;
- if (!m_bCulled)
- return false;
- list<RAS_MeshSlot*>::iterator it;
- for (it=m_joinedSlots.begin(); it!=m_joinedSlots.end(); it++)
- if (!(*it)->m_bCulled)
- return false;
- return true;
-}
-#endif
-
-/* material bucket sorting */
-
-struct RAS_MaterialBucket::less
-{
- bool operator()(const RAS_MaterialBucket* x, const RAS_MaterialBucket* y) const
- {
- return *x->GetPolyMaterial() < *y->GetPolyMaterial();
- }
-};
-
-/* material bucket */
-
-RAS_MaterialBucket::RAS_MaterialBucket(RAS_IPolyMaterial* mat)
-{
- m_material = mat;
-}
-
-RAS_MaterialBucket::~RAS_MaterialBucket()
-{
-}
-
-RAS_IPolyMaterial* RAS_MaterialBucket::GetPolyMaterial() const
-{
- return m_material;
-}
-
-bool RAS_MaterialBucket::IsAlpha() const
-{
- return (m_material->IsAlpha());
-}
-
-bool RAS_MaterialBucket::IsZSort() const
-{
- return (m_material->IsZSort());
-}
-
-RAS_MeshSlot* RAS_MaterialBucket::AddMesh(int numverts)
-{
- RAS_MeshSlot *ms;
-
- m_meshSlots.push_back(RAS_MeshSlot());
-
- ms = &m_meshSlots.back();
- ms->init(this, numverts);
-
- return ms;
-}
-
-RAS_MeshSlot* RAS_MaterialBucket::CopyMesh(RAS_MeshSlot *ms)
-{
- m_meshSlots.push_back(RAS_MeshSlot(*ms));
-
- return &m_meshSlots.back();
-}
-
-void RAS_MaterialBucket::RemoveMesh(RAS_MeshSlot* ms)
-{
- list<RAS_MeshSlot>::iterator it;
-
- for (it=m_meshSlots.begin(); it!=m_meshSlots.end(); it++) {
- if (&*it == ms) {
- m_meshSlots.erase(it);
- return;
- }
- }
-}
-
-list<RAS_MeshSlot>::iterator RAS_MaterialBucket::msBegin()
-{
- return m_meshSlots.begin();
-}
-
-list<RAS_MeshSlot>::iterator RAS_MaterialBucket::msEnd()
-{
- return m_meshSlots.end();
-}
-
-bool RAS_MaterialBucket::ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty)
-{
- bool uselights;
-
- if (rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW && !m_material->CastsShadows())
- return false;
-
- if (rasty->GetDrawingMode() != RAS_IRasterizer::KX_SHADOW && m_material->OnlyShadow())
- return false;
-
- if (!rasty->SetMaterial(*m_material))
- return false;
-
- uselights= m_material->UsesLighting(rasty);
- rasty->ProcessLighting(uselights, cameratrans);
-
- return true;
-}
-
-void RAS_MaterialBucket::RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_MeshSlot &ms)
-{
- m_material->ActivateMeshSlot(ms, rasty);
-
- if (ms.m_pDeformer)
- {
- if (ms.m_pDeformer->Apply(m_material))
- ms.m_mesh->SetMeshModified(true);
- // KX_ReInstanceShapeFromMesh(ms.m_mesh); // Recompute the physics mesh. (Can't call KX_* from RAS_)
- }
-
- if (IsZSort() && rasty->GetDrawingMode() >= RAS_IRasterizer::KX_SOLID)
- ms.m_mesh->SortPolygons(ms, cameratrans*MT_Transform(ms.m_OpenGLMatrix));
-
- rasty->PushMatrix();
- if (!ms.m_pDeformer || !ms.m_pDeformer->SkipVertexTransform())
- {
- rasty->applyTransform(ms.m_OpenGLMatrix,m_material->GetDrawingMode());
- }
-
- if (rasty->QueryLists())
- if (ms.m_DisplayList)
- ms.m_DisplayList->SetModified(ms.m_mesh->MeshModified());
-
- // verify if we can use display list, not for deformed object, and
- // also don't create a new display list when drawing shadow buffers,
- // then it won't have texture coordinates for actual drawing. also
- // for zsort we can't make a display list, since the polygon order
- // changes all the time.
- if (ms.m_pDeformer && ms.m_pDeformer->IsDynamic())
- ms.m_bDisplayList = false;
- else if (!ms.m_DisplayList && rasty->GetDrawingMode() == RAS_IRasterizer::KX_SHADOW)
- ms.m_bDisplayList = false;
- else if (IsZSort())
- ms.m_bDisplayList = false;
- else if (m_material->UsesObjectColor() && ms.m_bObjectColor)
- ms.m_bDisplayList = false;
- else
- ms.m_bDisplayList = true;
-
- if (m_material->GetDrawingMode() & RAS_IRasterizer::RAS_RENDER_3DPOLYGON_TEXT) {
- // for text drawing using faces
- rasty->IndexPrimitives_3DText(ms, m_material);
- }
- else {
- rasty->IndexPrimitives(ms);
- }
-
- rasty->PopMatrix();
-}
-
-void RAS_MaterialBucket::Optimize(MT_Scalar distance)
-{
- /* TODO: still have to check before this works correct:
- * - lightlayer, frontface, text, billboard
- * - make it work with physics */
-
-#if 0
- list<RAS_MeshSlot>::iterator it;
- list<RAS_MeshSlot>::iterator jt;
-
- // greed joining on all following buckets
- for (it=m_meshSlots.begin(); it!=m_meshSlots.end(); it++)
- for (jt=it, jt++; jt!=m_meshSlots.end(); jt++)
- jt->Join(&*it, distance);
-#endif
-}
-
diff --git a/source/gameengine/Rasterizer/RAS_MaterialBucket.h b/source/gameengine/Rasterizer/RAS_MaterialBucket.h
deleted file mode 100644
index 75cc382c78c..00000000000
--- a/source/gameengine/Rasterizer/RAS_MaterialBucket.h
+++ /dev/null
@@ -1,267 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_MaterialBucket.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_MATERIALBUCKET_H__
-#define __RAS_MATERIALBUCKET_H__
-
-#include "RAS_TexVert.h"
-#include "CTR_Map.h"
-#include "SG_QList.h"
-
-#include "MT_Transform.h"
-#include "MT_Matrix4x4.h"
-
-#include <vector>
-#include <set>
-#include <list>
-
-class RAS_MaterialBucket;
-struct DerivedMesh;
-class CTR_HashedPtr;
-class RAS_Deformer;
-class RAS_IPolyMaterial;
-class RAS_IRasterizer;
-class RAS_MeshObject;
-
-using namespace std;
-
-/* Display List Slot */
-
-class KX_ListSlot
-{
-protected:
- int m_refcount;
-public:
- KX_ListSlot() { m_refcount = 1; }
- virtual ~KX_ListSlot() {}
- virtual int Release() {
- if (--m_refcount > 0)
- return m_refcount;
- delete this;
- return 0;
- }
- virtual KX_ListSlot* AddRef() {
- m_refcount++;
- return this;
- }
- virtual void SetModified(bool mod)=0;
-};
-
-/* An array with data used for OpenGL drawing */
-
-class RAS_DisplayArray
-{
-public:
- /** The offset relation to the previous RAS_DisplayArray.
- * For the user vertex are one big list but in C++ source
- * it's two different lists if we use quads and triangles.
- * So to fix that we add an offset.
- * This value is set in UpdateDisplayArraysOffset().
- */
- unsigned int m_offset;
- vector<RAS_TexVert> m_vertex;
- vector<unsigned short> m_index;
- /* LINE currently isn't used */
- enum { LINE = 2, TRIANGLE = 3, QUAD = 4 } m_type;
- //RAS_MeshSlot *m_origSlot;
-
- /* Number of RAS_MeshSlot using this array */
- int m_users;
-
- enum { BUCKET_MAX_INDEX = 65535 };
- enum { BUCKET_MAX_VERTEX = 65535 };
-};
-
-/* Entry of a RAS_MeshObject into RAS_MaterialBucket */
-typedef std::vector<RAS_DisplayArray*> RAS_DisplayArrayList;
-
-// The QList is used to link the mesh slots to the object
-// The DList is used to link the visible mesh slots to the material bucket
-class RAS_MeshSlot : public SG_QList
-{
- friend class RAS_ListRasterizer;
-private:
- // indices into display arrays
- int m_startarray;
- int m_endarray;
- int m_startindex;
- int m_endindex;
- int m_startvertex;
- int m_endvertex;
- RAS_DisplayArrayList m_displayArrays;
-
- // for construction only
- RAS_DisplayArray* m_currentArray;
-
-public:
- // for rendering
- RAS_MaterialBucket* m_bucket;
- RAS_MeshObject* m_mesh;
- void* m_clientObj;
- RAS_Deformer* m_pDeformer;
- DerivedMesh* m_pDerivedMesh;
- float* m_OpenGLMatrix;
- // visibility
- bool m_bVisible;
- bool m_bCulled;
- // object color
- bool m_bObjectColor;
- MT_Vector4 m_RGBAcolor;
- // display lists
- KX_ListSlot* m_DisplayList;
- bool m_bDisplayList;
- // joined mesh slots
- RAS_MeshSlot* m_joinSlot;
- MT_Matrix4x4 m_joinInvTransform;
- list<RAS_MeshSlot*> m_joinedSlots;
-
- RAS_MeshSlot();
- RAS_MeshSlot(const RAS_MeshSlot& slot);
- virtual ~RAS_MeshSlot();
-
- void init(RAS_MaterialBucket *bucket, int numverts);
-
- struct iterator {
- RAS_DisplayArray *array;
- RAS_TexVert *vertex;
- unsigned short *index;
- size_t startvertex;
- size_t endvertex;
- size_t totindex;
- size_t arraynum;
- };
-
- void begin(iterator& it);
- void next(iterator& it);
- bool end(iterator& it);
-
- /* used during construction */
- void SetDisplayArray(int numverts);
- RAS_DisplayArray *CurrentDisplayArray();
- void SetDeformer(RAS_Deformer* deformer);
-
- void AddPolygon(int numverts);
- int AddVertex(const RAS_TexVert& tv);
- void AddPolygonVertex(int offset);
-
- /// Update offset of each display array
- void UpdateDisplayArraysOffset();
-
- /* optimization */
- bool Split(bool force=false);
- bool Join(RAS_MeshSlot *target, MT_Scalar distance);
- bool Equals(RAS_MeshSlot *target);
-#ifdef USE_SPLIT
- bool IsCulled();
-#else
- bool IsCulled() { return m_bCulled; }
-#endif
- void SetCulled(bool culled) { m_bCulled = culled; }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_MeshSlot")
-#endif
-};
-
-/* Used by RAS_MeshObject, to point to it's slots in a bucket */
-
-class RAS_MeshMaterial
-{
-public:
- RAS_MeshSlot *m_baseslot;
- class RAS_MaterialBucket *m_bucket;
-
- /* the KX_GameObject is used as a key here */
- CTR_Map<CTR_HashedPtr,RAS_MeshSlot*> m_slots;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_MeshMaterial")
-#endif
-};
-
-/* Contains a list of display arrays with the same material,
- * and a mesh slot for each mesh that uses display arrays in
- * this bucket */
-
-class RAS_MaterialBucket
-{
-public:
- RAS_MaterialBucket(RAS_IPolyMaterial* mat);
- virtual ~RAS_MaterialBucket();
-
- /* Bucket Sorting */
- struct less;
- typedef set<RAS_MaterialBucket*, less> Set;
-
- /* Material Properties */
- RAS_IPolyMaterial* GetPolyMaterial() const;
- bool IsAlpha() const;
- bool IsZSort() const;
-
- /* Rendering */
- bool ActivateMaterial(const MT_Transform& cameratrans, RAS_IRasterizer* rasty);
- void RenderMeshSlot(const MT_Transform& cameratrans, RAS_IRasterizer* rasty, RAS_MeshSlot &ms);
-
- /* Mesh Slot Access */
- list<RAS_MeshSlot>::iterator msBegin();
- list<RAS_MeshSlot>::iterator msEnd();
-
- class RAS_MeshSlot* AddMesh(int numverts);
- class RAS_MeshSlot* CopyMesh(class RAS_MeshSlot *ms);
- void RemoveMesh(class RAS_MeshSlot* ms);
- void Optimize(MT_Scalar distance);
- void ActivateMesh(RAS_MeshSlot* slot)
- {
- m_activeMeshSlotsHead.AddBack(slot);
- }
- SG_DList& GetActiveMeshSlots()
- {
- return m_activeMeshSlotsHead;
- }
- RAS_MeshSlot* GetNextActiveMeshSlot()
- {
- return (RAS_MeshSlot*)m_activeMeshSlotsHead.Remove();
- }
-
-private:
- list<RAS_MeshSlot> m_meshSlots; // all the mesh slots
- RAS_IPolyMaterial* m_material;
- SG_DList m_activeMeshSlotsHead; // only those which must be rendered
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_MaterialBucket")
-#endif
-};
-
-#endif /* __RAS_MATERIAL_BUCKET */
diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.cpp b/source/gameengine/Rasterizer/RAS_MeshObject.cpp
deleted file mode 100644
index 4360464ed32..00000000000
--- a/source/gameengine/Rasterizer/RAS_MeshObject.cpp
+++ /dev/null
@@ -1,573 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_MeshObject.cpp
- * \ingroup bgerast
- */
-
-#include "DNA_key_types.h"
-#include "DNA_mesh_types.h"
-
-#include "CTR_HashedPtr.h"
-
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-#include "RAS_IPolygonMaterial.h"
-#include "RAS_Deformer.h"
-#include "MT_Point3.h"
-
-#include <algorithm>
-
-
-/* polygon sorting */
-
-struct RAS_MeshObject::polygonSlot
-{
- float m_z;
- int m_index[4];
-
- polygonSlot() {}
-
- /* pnorm is the normal from the plane equation that the distance from is
- * used to sort again. */
- void get(const RAS_TexVert *vertexarray, const unsigned short *indexarray,
- int offset, int nvert, const MT_Vector3& pnorm)
- {
- MT_Vector3 center(0, 0, 0);
- int i;
-
- for (i=0; i<nvert; i++) {
- m_index[i] = indexarray[offset+i];
- center += vertexarray[m_index[i]].getXYZ();
- }
-
- /* note we don't divide center by the number of vertices, since all
- * polygons have the same number of vertices, and that we leave out
- * the 4-th component of the plane equation since it is constant. */
- m_z = MT_dot(pnorm, center);
- }
-
- void set(unsigned short *indexarray, int offset, int nvert)
- {
- int i;
-
- for (i=0; i<nvert; i++)
- indexarray[offset+i] = m_index[i];
- }
-};
-
-struct RAS_MeshObject::backtofront
-{
- bool operator()(const polygonSlot &a, const polygonSlot &b) const
- {
- return a.m_z < b.m_z;
- }
-};
-
-struct RAS_MeshObject::fronttoback
-{
- bool operator()(const polygonSlot &a, const polygonSlot &b) const
- {
- return a.m_z > b.m_z;
- }
-};
-
-/* mesh object */
-
-STR_String RAS_MeshObject::s_emptyname = "";
-
-RAS_MeshObject::RAS_MeshObject(Mesh* mesh)
- : m_bModified(true),
- m_bMeshModified(true),
- m_mesh(mesh)
-{
- if (m_mesh && m_mesh->key)
- {
- KeyBlock *kb;
- int count=0;
- // initialize weight cache for shape objects
- // count how many keys in this mesh
- for (kb= (KeyBlock *)m_mesh->key->block.first; kb; kb= (KeyBlock *)kb->next)
- count++;
- m_cacheWeightIndex.resize(count,-1);
- }
-}
-
-RAS_MeshObject::~RAS_MeshObject()
-{
- vector<RAS_Polygon*>::iterator it;
-
- for (it=m_Polygons.begin(); it!=m_Polygons.end(); it++)
- delete (*it);
-
- m_sharedvertex_map.clear();
- m_Polygons.clear();
- m_materials.clear();
-}
-
-bool RAS_MeshObject::MeshModified()
-{
- return m_bMeshModified;
-}
-
-//unsigned int RAS_MeshObject::GetLightLayer()
-//{
-// return m_lightlayer;
-//}
-
-
-
-int RAS_MeshObject::NumMaterials()
-{
- return m_materials.size();
-}
-
-const STR_String& RAS_MeshObject::GetMaterialName(unsigned int matid)
-{
- RAS_MeshMaterial* mmat = GetMeshMaterial(matid);
-
- if (mmat)
- return mmat->m_bucket->GetPolyMaterial()->GetMaterialName();
-
- return s_emptyname;
-}
-
-RAS_MeshMaterial* RAS_MeshObject::GetMeshMaterial(unsigned int matid)
-{
- if ((m_materials.empty() == false) && (matid < m_materials.size()))
- {
- list<RAS_MeshMaterial>::iterator it = m_materials.begin();
- while (matid--) ++it;
- return &*it;
- }
-
- return NULL;
-}
-
-
-
-int RAS_MeshObject::NumPolygons()
-{
- return m_Polygons.size();
-}
-
-
-
-RAS_Polygon* RAS_MeshObject::GetPolygon(int num) const
-{
- return m_Polygons[num];
-}
-
-
-
-
- list<RAS_MeshMaterial>::iterator GetFirstMaterial();
- list<RAS_MeshMaterial>::iterator GetLastMaterial();
-list<RAS_MeshMaterial>::iterator RAS_MeshObject::GetFirstMaterial()
-{
- return m_materials.begin();
-}
-
-
-
-list<RAS_MeshMaterial>::iterator RAS_MeshObject::GetLastMaterial()
-{
- return m_materials.end();
-}
-
-
-
-void RAS_MeshObject::SetName(const char *name)
-{
- m_name = name;
-}
-
-
-
-STR_String& RAS_MeshObject::GetName()
-{
- return m_name;
-}
-
-
-
-const STR_String& RAS_MeshObject::GetTextureName(unsigned int matid)
-{
- RAS_MeshMaterial* mmat = GetMeshMaterial(matid);
-
- if (mmat)
- return mmat->m_bucket->GetPolyMaterial()->GetTextureName();
-
- return s_emptyname;
-}
-
-RAS_MeshMaterial *RAS_MeshObject::GetMeshMaterial(RAS_IPolyMaterial *mat)
-{
- list<RAS_MeshMaterial>::iterator mit;
-
- /* find a mesh material */
- for (mit = m_materials.begin(); mit != m_materials.end(); mit++)
- if (mit->m_bucket->GetPolyMaterial() == mat)
- return &*mit;
-
- return NULL;
-}
-
-int RAS_MeshObject::GetMaterialId(RAS_IPolyMaterial *mat)
-{
- list<RAS_MeshMaterial>::iterator mit;
- int imat;
-
- /* find a mesh material */
- for (imat=0, mit = m_materials.begin(); mit != m_materials.end(); mit++, imat++)
- if (mit->m_bucket->GetPolyMaterial() == mat)
- return imat;
-
- return -1;
-}
-
-RAS_Polygon* RAS_MeshObject::AddPolygon(RAS_MaterialBucket *bucket, int numverts)
-{
- RAS_MeshMaterial *mmat;
- RAS_Polygon *poly;
- RAS_MeshSlot *slot;
-
- /* find a mesh material */
- mmat = GetMeshMaterial(bucket->GetPolyMaterial());
-
- /* none found, create a new one */
- if (!mmat) {
- RAS_MeshMaterial meshmat;
- meshmat.m_bucket = bucket;
- meshmat.m_baseslot = meshmat.m_bucket->AddMesh(numverts);
- meshmat.m_baseslot->m_mesh = this;
- m_materials.push_back(meshmat);
- mmat = &m_materials.back();
- }
-
- /* add it to the bucket, this also adds new display arrays */
- slot = mmat->m_baseslot;
- slot->AddPolygon(numverts);
-
- /* create a new polygon */
- RAS_DisplayArray *darray = slot->CurrentDisplayArray();
- poly = new RAS_Polygon(bucket, darray, numverts);
- m_Polygons.push_back(poly);
-
- return poly;
-}
-
-void RAS_MeshObject::DebugColor(unsigned int abgr)
-{
- /*int numpolys = NumPolygons();
-
- for (int i=0;i<numpolys;i++) {
- RAS_Polygon* poly = m_polygons[i];
- for (int v=0;v<poly->VertexCount();v++)
- RAS_TexVert* vtx = poly->GetVertex(v)->setDebugRGBA(abgr);
- }
- */
-
- /* m_debugcolor = abgr; */
-}
-
-void RAS_MeshObject::SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba)
-{
- RAS_MeshMaterial *mmat = GetMeshMaterial(mat);
- RAS_MeshSlot *slot = mmat->m_baseslot;
- RAS_MeshSlot::iterator it;
- size_t i;
-
- for (slot->begin(it); !slot->end(it); slot->next(it))
- for (i=it.startvertex; i<it.endvertex; i++)
- it.vertex[i].SetRGBA(rgba);
-}
-
-void RAS_MeshObject::AddVertex(RAS_Polygon *poly, int i,
- const MT_Point3& xyz,
- const MT_Point2 uvs[RAS_TexVert::MAX_UNIT],
- const MT_Vector4& tangent,
- const unsigned int rgba,
- const MT_Vector3& normal,
- bool flat,
- int origindex)
-{
- RAS_TexVert texvert(xyz, uvs, tangent, rgba, normal, flat, origindex);
- RAS_MeshMaterial *mmat;
- RAS_DisplayArray *darray;
- RAS_MeshSlot *slot;
- int offset;
-
- mmat = GetMeshMaterial(poly->GetMaterial()->GetPolyMaterial());
- slot = mmat->m_baseslot;
- darray = slot->CurrentDisplayArray();
-
- { /* Shared Vertex! */
- /* find vertices shared between faces, with the restriction
- * that they exist in the same display array, and have the
- * same uv coordinate etc */
- vector<SharedVertex>& sharedmap = m_sharedvertex_map[origindex];
- vector<SharedVertex>::iterator it;
-
- for (it = sharedmap.begin(); it != sharedmap.end(); it++)
- {
- if (it->m_darray != darray)
- continue;
- if (!it->m_darray->m_vertex[it->m_offset].closeTo(&texvert))
- continue;
-
- /* found one, add it and we're done */
- if (poly->IsVisible())
- slot->AddPolygonVertex(it->m_offset);
- poly->SetVertexOffset(i, it->m_offset);
- return;
- }
- }
-
- /* no shared vertex found, add a new one */
- offset = slot->AddVertex(texvert);
- if (poly->IsVisible())
- slot->AddPolygonVertex(offset);
- poly->SetVertexOffset(i, offset);
-
- { /* Shared Vertex! */
- SharedVertex shared;
- shared.m_darray = darray;
- shared.m_offset = offset;
- m_sharedvertex_map[origindex].push_back(shared);
- }
-}
-
-int RAS_MeshObject::NumVertices(RAS_IPolyMaterial* mat)
-{
- RAS_MeshMaterial *mmat;
- RAS_MeshSlot *slot;
- RAS_MeshSlot::iterator it;
- size_t len = 0;
-
- mmat = GetMeshMaterial(mat);
- slot = mmat->m_baseslot;
- for (slot->begin(it); !slot->end(it); slot->next(it))
- len += it.endvertex - it.startvertex;
-
- return len;
-}
-
-
-RAS_TexVert* RAS_MeshObject::GetVertex(unsigned int matid,
- unsigned int index)
-{
- RAS_MeshMaterial *mmat;
- RAS_MeshSlot *slot;
- RAS_MeshSlot::iterator it;
- size_t len;
-
- mmat = GetMeshMaterial(matid);
-
- if (!mmat)
- return NULL;
-
- slot = mmat->m_baseslot;
- len = 0;
- for (slot->begin(it); !slot->end(it); slot->next(it)) {
- if (index >= len + it.endvertex - it.startvertex)
- len += it.endvertex - it.startvertex;
- else
- return &it.vertex[index - len];
- }
-
- return NULL;
-}
-
-const float* RAS_MeshObject::GetVertexLocation(unsigned int orig_index)
-{
- vector<SharedVertex>& sharedmap = m_sharedvertex_map[orig_index];
- vector<SharedVertex>::iterator it= sharedmap.begin();
- return it->m_darray->m_vertex[it->m_offset].getXYZ();
-}
-
-void RAS_MeshObject::AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer)
-{
- list<RAS_MeshMaterial>::iterator it;
- list<RAS_MeshMaterial>::iterator mit;
-
- for (it = m_materials.begin();it!=m_materials.end();++it) {
- /* always copy from the base slot, which is never removed
- * since new objects can be created with the same mesh data */
- if (deformer && !deformer->UseVertexArray())
- {
- // HACK!
- // this deformer doesn't use vertex array => derive mesh
- // we must keep only the mesh slots that have unique material id
- // this is to match the derived mesh drawing function
- // Need a better solution in the future: scan the derive mesh and create vertex array
- RAS_IPolyMaterial* curmat = it->m_bucket->GetPolyMaterial();
- if (curmat->GetFlag() & RAS_BLENDERGLSL)
- {
- for (mit = m_materials.begin(); mit != it; ++mit)
- {
- RAS_IPolyMaterial* mat = mit->m_bucket->GetPolyMaterial();
- if ((mat->GetFlag() & RAS_BLENDERGLSL) &&
- mat->GetMaterialIndex() == curmat->GetMaterialIndex())
- // no need to convert current mesh slot
- break;
- }
- if (mit != it)
- continue;
- }
- }
- RAS_MeshSlot *ms = it->m_bucket->CopyMesh(it->m_baseslot);
- ms->m_clientObj = clientobj;
- ms->SetDeformer(deformer);
- it->m_slots.insert(clientobj, ms);
- head->QAddBack(ms);
- }
-}
-
-void RAS_MeshObject::RemoveFromBuckets(void *clientobj)
-{
- list<RAS_MeshMaterial>::iterator it;
-
- for (it = m_materials.begin();it!=m_materials.end();++it) {
- RAS_MeshSlot **msp = it->m_slots[clientobj];
-
- if (!msp)
- continue;
-
- RAS_MeshSlot *ms = *msp;
-
- it->m_bucket->RemoveMesh(ms);
- it->m_slots.remove(clientobj);
- }
-}
-
-void RAS_MeshObject::EndConversion()
-{
-#if 0
- m_sharedvertex_map.clear(); // SharedVertex
- vector<vector<SharedVertex> > shared_null(0);
- shared_null.swap( m_sharedvertex_map ); /* really free the memory */
-#endif
-
- for (std::list<RAS_MeshMaterial>::iterator it = m_materials.begin();
- it != m_materials.end();
- ++it)
- {
- RAS_MeshSlot *ms = it->m_baseslot;
- ms->UpdateDisplayArraysOffset();
- }
-}
-
-//void RAS_MeshObject::Transform(const MT_Transform& trans)
-//{
- //m_trans.translate(MT_Vector3(0,0,1));//.operator *=(trans);
-
-// for (int i=0;i<m_Polygons.size();i++)
-// {
-// m_Polygons[i]->Transform(trans);
-// }
-//}
-
-
-/*
-void RAS_MeshObject::RelativeTransform(const MT_Vector3& vec)
-{
- for (int i=0;i<m_Polygons.size();i++)
- {
- m_Polygons[i]->RelativeTransform(vec);
- }
-}
-*/
-
-void RAS_MeshObject::SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform)
-{
- // Limitations: sorting is quite simple, and handles many
- // cases wrong, partially due to polygons being sorted per
- // bucket.
- //
- // a) mixed triangles/quads are sorted wrong
- // b) mixed materials are sorted wrong
- // c) more than 65k faces are sorted wrong
- // d) intersecting objects are sorted wrong
- // e) intersecting polygons are sorted wrong
- //
- // a) can be solved by making all faces either triangles or quads
- // if they need to be z-sorted. c) could be solved by allowing
- // larger buckets, b) and d) cannot be solved easily if we want
- // to avoid excessive state changes while drawing. e) would
- // require splitting polygons.
-
- RAS_MeshSlot::iterator it;
- size_t j;
-
- for (ms.begin(it); !ms.end(it); ms.next(it)) {
- unsigned int nvert = (int)it.array->m_type;
- unsigned int totpoly = it.totindex/nvert;
-
- if (totpoly <= 1)
- continue;
- if (it.array->m_type == RAS_DisplayArray::LINE)
- continue;
-
- // Extract camera Z plane...
- const MT_Vector3 pnorm(transform.getBasis()[2]);
- // unneeded: const MT_Scalar pval = transform.getOrigin()[2];
-
- vector<polygonSlot> poly_slots(totpoly);
-
- /* get indices and z into temporary array */
- for (j=0; j<totpoly; j++)
- poly_slots[j].get(it.vertex, it.index, j*nvert, nvert, pnorm);
-
- /* sort (stable_sort might be better, if flickering happens?) */
- std::sort(poly_slots.begin(), poly_slots.end(), backtofront());
-
- /* get indices from temporary array again */
- for (j=0; j<totpoly; j++)
- poly_slots[j].set(it.index, j*nvert, nvert);
- }
-}
-
-
-bool RAS_MeshObject::HasColliderPolygon()
-{
- int numpolys= NumPolygons();
- for (int p=0; p<numpolys; p++)
- if (m_Polygons[p]->IsCollider())
- return true;
-
- return false;
-}
-
-void RAS_MeshObject::SchedulePolygons(int drawingmode)
-{
- if (m_bModified)
- {
- m_bModified = false;
- m_bMeshModified = true;
- }
-}
diff --git a/source/gameengine/Rasterizer/RAS_MeshObject.h b/source/gameengine/Rasterizer/RAS_MeshObject.h
deleted file mode 100644
index a6f1a1cafc6..00000000000
--- a/source/gameengine/Rasterizer/RAS_MeshObject.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_MeshObject.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_MESHOBJECT_H__
-#define __RAS_MESHOBJECT_H__
-
-#ifdef _MSC_VER
- /* disable the STL warnings ("debug information length > 255") */
-# pragma warning (disable:4786)
-#endif
-
-#include <vector>
-#include <list>
-
-#include "RAS_MaterialBucket.h"
-#include "MT_Transform.h"
-#include "STR_String.h"
-
-struct Mesh;
-class RAS_Deformer;
-class RAS_Polygon;
-
-/* RAS_MeshObject is a mesh used for rendering. It stores polygons,
- * but the actual vertices and index arrays are stored in material
- * buckets, referenced by the list of RAS_MeshMaterials. */
-
-class RAS_MeshObject
-{
-private:
- /* unsigned int m_debugcolor; */ /* UNUSED */
-
- bool m_bModified;
- bool m_bMeshModified;
-
- STR_String m_name;
- static STR_String s_emptyname;
-
- vector<RAS_Polygon*> m_Polygons;
-
- /* polygon sorting */
- struct polygonSlot;
- struct backtofront;
- struct fronttoback;
-
-protected:
- vector<int> m_cacheWeightIndex;
- list<RAS_MeshMaterial> m_materials;
- Mesh* m_mesh;
-
-public:
- // for now, meshes need to be in a certain layer (to avoid sorting on lights in realtime)
- RAS_MeshObject(Mesh* mesh);
- virtual ~RAS_MeshObject();
-
-
- /* materials */
- int NumMaterials();
- const STR_String& GetMaterialName(unsigned int matid);
- const STR_String& GetTextureName(unsigned int matid);
-
- RAS_MeshMaterial* GetMeshMaterial(unsigned int matid);
- RAS_MeshMaterial* GetMeshMaterial(RAS_IPolyMaterial *mat);
- int GetMaterialId(RAS_IPolyMaterial *mat);
-
- list<RAS_MeshMaterial>::iterator GetFirstMaterial();
- list<RAS_MeshMaterial>::iterator GetLastMaterial();
-
- //unsigned int GetLightLayer();
-
- /* name */
- void SetName(const char *name);
- STR_String& GetName();
-
- /* modification state */
- bool MeshModified();
- void SetMeshModified(bool v) { m_bMeshModified = v; }
-
- /* original blender mesh */
- Mesh* GetMesh() { return m_mesh; }
-
- /* mesh construction */
-
- virtual RAS_Polygon* AddPolygon(RAS_MaterialBucket *bucket, int numverts);
- virtual void AddVertex(RAS_Polygon *poly, int i,
- const MT_Point3& xyz,
- const MT_Point2 uvs[RAS_TexVert::MAX_UNIT],
- const MT_Vector4& tangent,
- const unsigned int rgbacolor,
- const MT_Vector3& normal,
- bool flat,
- int origindex);
-
- void SchedulePolygons(int drawingmode);
-
- /* vertex and polygon acces */
- int NumVertices(RAS_IPolyMaterial* mat);
- RAS_TexVert* GetVertex(unsigned int matid, unsigned int index);
- const float* GetVertexLocation(unsigned int orig_index);
-
- int NumPolygons();
- RAS_Polygon* GetPolygon(int num) const;
-
- /* buckets */
- virtual void AddMeshUser(void *clientobj, SG_QList *head, RAS_Deformer* deformer);
-
- void RemoveFromBuckets(void *clientobj);
- void EndConversion();
-
- /* colors */
- void DebugColor(unsigned int abgr);
- void SetVertexColor(RAS_IPolyMaterial* mat,MT_Vector4 rgba);
-
- /* polygon sorting by Z for alpha */
- void SortPolygons(RAS_MeshSlot& ms, const MT_Transform &transform);
-
-
- bool HasColliderPolygon();
-
- /* for construction to find shared vertices */
- struct SharedVertex {
- RAS_DisplayArray *m_darray;
- int m_offset;
- };
-
- vector<vector<SharedVertex> > m_sharedvertex_map;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_MeshObject")
-#endif
-};
-
-#endif /* __RAS_MESHOBJECT_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_ObjectColor.h b/source/gameengine/Rasterizer/RAS_ObjectColor.h
deleted file mode 100644
index 77feffccffc..00000000000
--- a/source/gameengine/Rasterizer/RAS_ObjectColor.h
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_ObjectColor.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_OBJECTCOLOR_H__
-#define __RAS_OBJECTCOLOR_H__
-
-struct RAS_ObjectColor {
- float m_red;
- float m_green;
- float m_blue;
-};
-
-#endif /* __RAS_OBJECTCOLOR_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h
deleted file mode 100644
index 3f1644a5c60..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Blur2DFilter.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Blur2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_BLUR2DFILTER_H__
-#define __RAS_BLUR2DFILTER_H__
-
-static const char *BlurFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-uniform vec2 bgl_TextureCoordinateOffset[9];
-
-void main(void)
-{
- vec4 sample[9];
-
- for (int i = 0; i < 9; i++)
- {
- sample[i] = texture2D(bgl_RenderedTexture,
- gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
- }
-
- gl_FragColor = (sample[0] + (2.0*sample[1]) + sample[2] +
- (2.0*sample[3]) + sample[4] + (2.0*sample[5]) +
- sample[6] + (2.0*sample[7]) + sample[8]) / 13.0;
-}
-);
-#endif
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h
deleted file mode 100644
index 4e863cb6f8d..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Dilation2DFilter.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Dilation2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_DILATION2DFILTER_H__
-#define __RAS_DILATION2DFILTER_H__
-
-static const char *DilationFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-uniform vec2 bgl_TextureCoordinateOffset[9];
-
-void main(void)
-{
- vec4 sample[9];
- vec4 maxValue = vec4(0.0);
-
- for (int i = 0; i < 9; i++)
- {
- sample[i] = texture2D(bgl_RenderedTexture,
- gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
- maxValue = max(sample[i], maxValue);
- }
-
- gl_FragColor = maxValue;
-}
-);
-#endif
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h
deleted file mode 100644
index 56e2c22fe2e..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Erosion2DFilter.h
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Erosion2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_EROSION2DFILTER_H__
-#define __RAS_EROSION2DFILTER_H__
-
-static const char *ErosionFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-uniform vec2 bgl_TextureCoordinateOffset[9];
-
-void main(void)
-{
- vec4 sample[9];
- vec4 minValue = vec4(1.0);
-
- for (int i = 0; i < 9; i++)
- {
- sample[i] = texture2D(bgl_RenderedTexture,
- gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
- minValue = min(sample[i], minValue);
- }
-
- gl_FragColor = minValue;
-}
-);
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h
deleted file mode 100644
index 932d5b16fed..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_GrayScale2DFilter.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_GrayScale2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_GRAYSCALE2DFILTER_H__
-#define __RAS_GRAYSCALE2DFILTER_H__
-
-static const char *GrayScaleFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-
-void main(void)
-{
- vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
- float gray = dot(texcolor.rgb, vec3(0.299, 0.587, 0.114));
- gl_FragColor = vec4(gray, gray, gray, texcolor.a);
-}
-);
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h
deleted file mode 100644
index dce303916ea..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Invert2DFilter.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Invert2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_INVERT2DFILTER_H__
-#define __RAS_INVERT2DFILTER_H__
-
-static const char *InvertFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-
-void main(void)
-{
- vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
- gl_FragColor.rgb = 1.0 - texcolor.rgb;
- gl_FragColor.a = texcolor.a;
-}
-);
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h
deleted file mode 100644
index 9ec5092817d..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Laplacian2DFilter.h
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Laplacian2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_LAPLACIAN2DFILTER_H__
-#define __RAS_LAPLACIAN2DFILTER_H__
-
-static const char *LaplacionFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-uniform vec2 bgl_TextureCoordinateOffset[9];
-
-void main(void)
-{
- vec4 sample[9];
-
- for (int i = 0; i < 9; i++)
- {
- sample[i] = texture2D(bgl_RenderedTexture,
- gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
- }
-
- gl_FragColor = (sample[4] * 8.0) -
- (sample[0] + sample[1] + sample[2] +
- sample[3] + sample[5] +
- sample[6] + sample[7] + sample[8]);
- gl_FragColor = vec4(gl_FragColor.rgb, 1.0);
-}
-);
-#endif
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h
deleted file mode 100644
index 4ae6009fdeb..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Prewitt2DFilter.h
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Prewitt2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_PREWITT2DFILTER_H__
-#define __RAS_PREWITT2DFILTER_H__
-
-static const char *PrewittFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-uniform vec2 bgl_TextureCoordinateOffset[9];
-
-void main(void)
-{
- vec4 sample[9];
-
- for (int i = 0; i < 9; i++)
- {
- sample[i] = texture2D(bgl_RenderedTexture,
- gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
- }
-
- vec4 horizEdge = sample[2] + sample[5] + sample[8] -
- (sample[0] + sample[3] + sample[6]);
-
- vec4 vertEdge = sample[0] + sample[1] + sample[2] -
- (sample[6] + sample[7] + sample[8]);
-
- gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) +
- (vertEdge.rgb * vertEdge.rgb));
- gl_FragColor.a = 1.0;
-}
-
-);
-#endif
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h
deleted file mode 100644
index 16b4e71dfdb..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sepia2DFilter.h
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Sepia2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_SEPIA2DFILTER_H__
-#define __RAS_SEPIA2DFILTER_H__
-
-static const char *SepiaFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-
-void main(void)
-{
- vec4 texcolor = texture2D(bgl_RenderedTexture, gl_TexCoord[0].st);
- float gray = dot(texcolor.rgb, vec3(0.299, 0.587, 0.114));
- gl_FragColor = vec4(gray * vec3(1.2, 1.0, 0.8), texcolor.a);
-}
-);
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h
deleted file mode 100644
index 7512393815b..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sharpen2DFilter.h
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Sharpen2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_SHARPEN2DFILTER_H__
-#define __RAS_SHARPEN2DFILTER_H__
-
-static const char *SharpenFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-uniform vec2 bgl_TextureCoordinateOffset[9];
-
-void main(void)
-{
- vec4 sample[9];
-
- for (int i = 0; i < 9; i++)
- {
- sample[i] = texture2D(bgl_RenderedTexture,
- gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
- }
-
- gl_FragColor = (sample[4] * 9.0) -
- (sample[0] + sample[1] + sample[2] +
- sample[3] + sample[5] +
- sample[6] + sample[7] + sample[8]);
-}
-);
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h b/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h
deleted file mode 100644
index 088ac10a56a..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLFilters/RAS_Sobel2DFilter.h
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Sobel2DFilter.h
- * \ingroup bgerastoglfilters
- */
-
-#ifndef __RAS_SOBEL2DFILTER_H__
-#define __RAS_SOBEL2DFILTER_H__
-
-static const char *SobelFragmentShader = STRINGIFY(
-uniform sampler2D bgl_RenderedTexture;
-uniform vec2 bgl_TextureCoordinateOffset[9];
-
-void main(void)
-{
- vec4 sample[9];
-
- for (int i = 0; i < 9; i++)
- {
- sample[i] = texture2D(bgl_RenderedTexture,
- gl_TexCoord[0].st + bgl_TextureCoordinateOffset[i]);
- }
-
- vec4 horizEdge = sample[2] + (2.0*sample[5]) + sample[8] -
- (sample[0] + (2.0*sample[3]) + sample[6]);
-
- vec4 vertEdge = sample[0] + (2.0*sample[1]) + sample[2] -
- (sample[6] + (2.0*sample[7]) + sample[8]);
-
- gl_FragColor.rgb = sqrt((horizEdge.rgb * horizEdge.rgb) +
- (vertEdge.rgb * vertEdge.rgb));
- gl_FragColor.a = 1.0;
-}
-);
-#endif
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt
deleted file mode 100644
index 89e31b62b41..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/CMakeLists.txt
+++ /dev/null
@@ -1,72 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- ..
- # XXX Remove these <<<
- ../../BlenderRoutines
- ../../Expressions
- ../../GameLogic
- ../../Ketsji
- ../../Physics/common
- # >>>
- ../../SceneGraph
- ../../../blender/blenfont
- ../../../blender/blenkernel
- ../../../blender/blenlib
- ../../../blender/gpu
- ../../../blender/makesdna
- ../../../../intern/container
- ../../../../intern/glew-mx
- ../../../../intern/string
-)
-
-set(INC_SYS
- ../../../../intern/moto/include
- ${GLEW_INCLUDE_PATH}
-)
-
-set(SRC
- RAS_ListRasterizer.cpp
- RAS_OpenGLLight.cpp
- RAS_OpenGLOffScreen.cpp
- RAS_OpenGLSync.cpp
- RAS_OpenGLRasterizer.cpp
- RAS_StorageVA.cpp
- RAS_StorageVBO.cpp
-
- RAS_IStorage.h
- RAS_ListRasterizer.h
- RAS_OpenGLLight.h
- RAS_OpenGLOffScreen.h
- RAS_OpenGLSync.h
- RAS_OpenGLRasterizer.h
- RAS_StorageVA.h
- RAS_StorageVBO.h
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-blender_add_lib(ge_oglrasterizer "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_IStorage.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_IStorage.h
deleted file mode 100644
index ae0cdcd84af..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_IStorage.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __KX_STORAGE
-#define __KX_STORAGE
-
-#ifdef WITH_CXX_GUARDEDALLOC
- #include "MEM_guardedalloc.h"
-#endif
-
-class RAS_MeshSlot;
-
-class RAS_IStorage
-{
-
-public:
- virtual ~RAS_IStorage() {};
-
- virtual bool Init()=0;
- virtual void Exit()=0;
-
- virtual void IndexPrimitives(RAS_MeshSlot& ms)=0;
-
- virtual void SetDrawingMode(int drawingmode)=0;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_IStorage")
-#endif
-};
-
-#endif //__KX_STORAGE
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
deleted file mode 100644
index 71c8cfe745f..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.cpp
- * \ingroup bgerastogl
- */
-
-#include <iostream>
-
-#include "RAS_ListRasterizer.h"
-
-#ifdef WIN32
-#include <windows.h>
-#endif // WIN32
-
-#include "GPU_glew.h"
-
-#include "RAS_MaterialBucket.h"
-#include "RAS_TexVert.h"
-#include "MT_assert.h"
-
-//#if defined(DEBUG)
-//#ifdef WIN32
-//#define spit(x) std::cout << x << std::endl;
-//#endif //WIN32
-//#else
-#define spit(x)
-//#endif
-
-RAS_ListSlot::RAS_ListSlot(RAS_ListRasterizer* rasty)
-: KX_ListSlot(),
- m_list(0),
- m_flag(LIST_MODIFY|LIST_CREATE),
- m_matnr(0),
- m_rasty(rasty)
-{
-}
-
-int RAS_ListSlot::Release()
-{
- if (--m_refcount > 0)
- return m_refcount;
- m_rasty->RemoveListSlot(this);
- delete this;
- return 0;
-}
-
-RAS_ListSlot::~RAS_ListSlot()
-{
- RemoveList();
-}
-
-
-void RAS_ListSlot::RemoveList()
-{
- if (m_list != 0) {
- spit("Releasing display list (" << m_list << ")");
- glDeleteLists((GLuint)m_list, 1);
- m_list =0;
- }
-}
-
-void RAS_ListSlot::DrawList()
-{
- if (m_flag &LIST_MODIFY) {
- if (m_flag &LIST_CREATE) {
- if (m_list == 0) {
- m_list = (unsigned int)glGenLists(1);
- m_flag = m_flag &~ LIST_CREATE;
- spit("Created display list (" << m_list << ")");
- }
- }
- if (m_list != 0)
- glNewList((GLuint)m_list, GL_COMPILE);
-
- m_flag |= LIST_BEGIN;
- return;
- }
- glCallList(m_list);
-}
-
-void RAS_ListSlot::EndList()
-{
- if (m_flag & LIST_BEGIN) {
- glEndList();
- m_flag = m_flag &~(LIST_BEGIN|LIST_MODIFY);
- m_flag |= LIST_END;
- glCallList(m_list);
- }
-}
-
-void RAS_ListSlot::SetModified(bool mod)
-{
- if (mod && !(m_flag & LIST_MODIFY)) {
- spit("Modifying list (" << m_list << ")");
- m_flag = m_flag &~ LIST_END;
- m_flag |= LIST_MODIFY;
- }
-}
-
-bool RAS_ListSlot::End()
-{
- return (m_flag &LIST_END)!=0;
-}
-
-
-
-RAS_ListRasterizer::RAS_ListRasterizer(RAS_ICanvas* canvas, bool lock, RAS_STORAGE_TYPE storage)
-: RAS_OpenGLRasterizer(canvas, storage)
-{
-}
-
-RAS_ListRasterizer::~RAS_ListRasterizer()
-{
- ReleaseAlloc();
-}
-
-void RAS_ListRasterizer::RemoveListSlot(RAS_ListSlot* list)
-{
- if (list->m_flag & LIST_DERIVEDMESH) {
- RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.begin();
- while (it != mDerivedMeshLists.end()) {
- RAS_ListSlots *slots = it->second;
- if (slots->size() > list->m_matnr && slots->at(list->m_matnr) == list) {
- (*slots)[list->m_matnr] = NULL;
- // check if all slots are NULL and if yes, delete the entry
- int i;
- for (i=slots->size(); i-- > 0; ) {
- if (slots->at(i) != NULL)
- break;
- }
- if (i < 0) {
- slots->clear();
- delete slots;
- mDerivedMeshLists.erase(it);
- }
- break;
- }
- ++it;
- }
- } else {
- RAS_ArrayLists::iterator it = mArrayLists.begin();
- while (it != mArrayLists.end()) {
- if (it->second == list) {
- mArrayLists.erase(it);
- break;
- }
- it++;
- }
- }
-}
-
-RAS_ListSlot* RAS_ListRasterizer::FindOrAdd(RAS_MeshSlot& ms)
-{
- /*
- * Keep a copy of constant lists submitted for rendering,
- * this guards against (replicated)new...delete every frame,
- * and we can reuse lists!
- * :: sorted by mesh slot
- */
- RAS_ListSlot* localSlot = (RAS_ListSlot*)ms.m_DisplayList;
- if (!localSlot) {
- if (ms.m_pDerivedMesh) {
- // that means that we draw based on derived mesh, a display list is possible
- // Note that we come here only for static derived mesh
- int matnr = ms.m_bucket->GetPolyMaterial()->GetMaterialIndex();
- RAS_ListSlot* nullSlot = NULL;
- RAS_ListSlots *listVector;
- RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.find(ms.m_pDerivedMesh);
- if (it == mDerivedMeshLists.end()) {
- listVector = new RAS_ListSlots(matnr+4, nullSlot);
- localSlot = new RAS_ListSlot(this);
- localSlot->m_flag |= LIST_DERIVEDMESH;
- localSlot->m_matnr = matnr;
- listVector->at(matnr) = localSlot;
- mDerivedMeshLists.insert(std::pair<DerivedMesh*, RAS_ListSlots*>(ms.m_pDerivedMesh, listVector));
- } else {
- listVector = it->second;
- if (listVector->size() <= matnr)
- listVector->resize(matnr+4, nullSlot);
- if ((localSlot = listVector->at(matnr)) == NULL) {
- localSlot = new RAS_ListSlot(this);
- localSlot->m_flag |= LIST_DERIVEDMESH;
- localSlot->m_matnr = matnr;
- listVector->at(matnr) = localSlot;
- } else {
- localSlot->AddRef();
- }
- }
- } else {
- RAS_ArrayLists::iterator it = mArrayLists.find(ms.m_displayArrays);
- if (it == mArrayLists.end()) {
- localSlot = new RAS_ListSlot(this);
- mArrayLists.insert(std::pair<RAS_DisplayArrayList, RAS_ListSlot*>(ms.m_displayArrays, localSlot));
- } else {
- localSlot = static_cast<RAS_ListSlot*>(it->second->AddRef());
- }
- }
- }
- MT_assert(localSlot);
- return localSlot;
-}
-
-void RAS_ListRasterizer::ReleaseAlloc()
-{
- for (RAS_ArrayLists::iterator it = mArrayLists.begin();it != mArrayLists.end();++it)
- delete it->second;
- mArrayLists.clear();
- for (RAS_DerivedMeshLists::iterator it = mDerivedMeshLists.begin();it != mDerivedMeshLists.end();++it) {
- RAS_ListSlots* slots = it->second;
- for (int i=slots->size(); i-- > 0; ) {
- RAS_ListSlot* slot = slots->at(i);
- if (slot)
- delete slot;
- }
- slots->clear();
- delete slots;
- }
- mDerivedMeshLists.clear();
-}
-
-void RAS_ListRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
-{
- RAS_ListSlot* localSlot =0;
-
- if (ms.m_bDisplayList) {
- localSlot = FindOrAdd(ms);
- localSlot->DrawList();
-
- if (localSlot->End()) {
- // save slot here too, needed for replicas and object using same mesh
- // => they have the same vertexarray but different mesh slot
- ms.m_DisplayList = localSlot;
- return;
- }
- }
-
- RAS_OpenGLRasterizer::IndexPrimitives(ms);
-
- if (ms.m_bDisplayList) {
- localSlot->EndList();
- ms.m_DisplayList = localSlot;
- }
-}
-
-bool RAS_ListRasterizer::Init(void)
-{
- return RAS_OpenGLRasterizer::Init();
-}
-
-void RAS_ListRasterizer::SetDrawingMode(int drawingmode)
-{
- RAS_OpenGLRasterizer::SetDrawingMode(drawingmode);
-}
-
-void RAS_ListRasterizer::Exit()
-{
- RAS_OpenGLRasterizer::Exit();
-}
-
-// eof
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h
deleted file mode 100644
index e3e6931311b..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_ListRasterizer.h
+++ /dev/null
@@ -1,77 +0,0 @@
-
-/** \file RAS_ListRasterizer.h
- * \ingroup bgerastogl
- */
-
-#ifndef __RAS_LISTRASTERIZER_H__
-#define __RAS_LISTRASTERIZER_H__
-
-#include "RAS_MaterialBucket.h"
-#include "RAS_OpenGLRasterizer.h"
-#include <vector>
-#include <map>
-
-class RAS_ListRasterizer;
-class RAS_ListSlot : public KX_ListSlot
-{
- friend class RAS_ListRasterizer;
- unsigned int m_list;
- unsigned int m_flag;
- unsigned int m_matnr;
- RAS_ListRasterizer* m_rasty;
-public:
- RAS_ListSlot(RAS_ListRasterizer* rasty);
- virtual ~RAS_ListSlot();
- virtual void SetModified(bool mod);
- virtual int Release();
-
- void RemoveList();
- void DrawList();
- void EndList();
- bool End();
-
-};
-
-enum RAS_ListSlotFlags {
- LIST_CREATE =1,
- LIST_MODIFY =2,
- LIST_BEGIN =4,
- LIST_END =8,
- LIST_DERIVEDMESH=16,
-};
-
-struct DerivedMesh;
-
-typedef std::map<RAS_DisplayArrayList, RAS_ListSlot*> RAS_ArrayLists;
-typedef std::vector<RAS_ListSlot*> RAS_ListSlots; // indexed by material slot number
-typedef std::map<DerivedMesh*, RAS_ListSlots*> RAS_DerivedMeshLists;
-
-class RAS_ListRasterizer : public RAS_OpenGLRasterizer
-{
- RAS_ArrayLists mArrayLists;
- RAS_DerivedMeshLists mDerivedMeshLists;
-
- RAS_ListSlot* FindOrAdd(class RAS_MeshSlot& ms);
- void ReleaseAlloc();
-
-public:
- void RemoveListSlot(RAS_ListSlot* list);
- RAS_ListRasterizer(RAS_ICanvas* canvas, bool lock, RAS_STORAGE_TYPE storage);
- virtual ~RAS_ListRasterizer();
-
- virtual void IndexPrimitives(class RAS_MeshSlot& ms);
-
- virtual bool Init();
- virtual void Exit();
-
- virtual void SetDrawingMode(int drawingmode);
-
- virtual bool QueryLists() {return true;}
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_ListRasterizer")
-#endif
-};
-
-#endif
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp
deleted file mode 100644
index 69e859f06d9..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.cpp
+++ /dev/null
@@ -1,299 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Mitchell Stokes
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "GPU_glew.h"
-
-#include <stdio.h>
-
-
-#include "RAS_OpenGLLight.h"
-#include "RAS_OpenGLRasterizer.h"
-#include "RAS_ICanvas.h"
-
-#include "MT_CmMatrix4x4.h"
-
-#include "KX_Camera.h"
-#include "KX_Light.h"
-#include "KX_Scene.h"
-
-#include "DNA_lamp_types.h"
-#include "DNA_scene_types.h"
-
-#include "GPU_material.h"
-
-RAS_OpenGLLight::RAS_OpenGLLight(RAS_OpenGLRasterizer *ras)
- :m_rasterizer(ras)
-{
-}
-
-RAS_OpenGLLight::~RAS_OpenGLLight()
-{
- GPULamp *lamp;
- KX_LightObject* kxlight = (KX_LightObject*)m_light;
- Lamp *la = (Lamp*)kxlight->GetBlenderObject()->data;
-
- if ((lamp = GetGPULamp())) {
- float obmat[4][4] = {{0}};
- GPU_lamp_update(lamp, 0, 0, obmat);
- GPU_lamp_update_distance(lamp, la->dist, la->att1, la->att2, la->coeff_const, la->coeff_lin, la->coeff_quad);
- GPU_lamp_update_spot(lamp, la->spotsize, la->spotblend);
- }
-}
-
-bool RAS_OpenGLLight::ApplyFixedFunctionLighting(KX_Scene *kxscene, int oblayer, int slot)
-{
- KX_Scene* lightscene = (KX_Scene*)m_scene;
- KX_LightObject* kxlight = (KX_LightObject*)m_light;
- float vec[4];
- int scenelayer = ~0;
-
- if (kxscene && kxscene->GetBlenderScene())
- scenelayer = kxscene->GetBlenderScene()->lay;
-
- /* only use lights in the same layer as the object */
- if (!(m_layer & oblayer))
- return false;
- /* only use lights in the same scene, and in a visible layer */
- if (kxscene != lightscene || !(m_layer & scenelayer))
- return false;
-
- // lights don't get their openGL matrix updated, do it now
- if (kxlight->GetSGNode()->IsDirty())
- kxlight->GetOpenGLMatrix();
-
- MT_CmMatrix4x4& worldmatrix= *kxlight->GetOpenGLMatrixPtr();
-
- vec[0] = worldmatrix(0,3);
- vec[1] = worldmatrix(1,3);
- vec[2] = worldmatrix(2,3);
- vec[3] = 1.0f;
-
- if (m_type==RAS_ILightObject::LIGHT_SUN) {
-
- vec[0] = worldmatrix(0,2);
- vec[1] = worldmatrix(1,2);
- vec[2] = worldmatrix(2,2);
- //vec[0] = base->object->obmat[2][0];
- //vec[1] = base->object->obmat[2][1];
- //vec[2] = base->object->obmat[2][2];
- vec[3] = 0.0f;
- glLightfv((GLenum)(GL_LIGHT0+slot), GL_POSITION, vec);
- }
- else {
- //vec[3] = 1.0f;
- glLightfv((GLenum)(GL_LIGHT0+slot), GL_POSITION, vec);
- glLightf((GLenum)(GL_LIGHT0+slot), GL_CONSTANT_ATTENUATION, 1.0f);
- glLightf((GLenum)(GL_LIGHT0+slot), GL_LINEAR_ATTENUATION, m_att1/m_distance);
- // without this next line it looks backward compatible.
- //attennuation still is acceptable
- glLightf((GLenum)(GL_LIGHT0+slot), GL_QUADRATIC_ATTENUATION, m_att2/(m_distance*m_distance));
-
- if (m_type==RAS_ILightObject::LIGHT_SPOT) {
- vec[0] = -worldmatrix(0,2);
- vec[1] = -worldmatrix(1,2);
- vec[2] = -worldmatrix(2,2);
- //vec[0] = -base->object->obmat[2][0];
- //vec[1] = -base->object->obmat[2][1];
- //vec[2] = -base->object->obmat[2][2];
- glLightfv((GLenum)(GL_LIGHT0+slot), GL_SPOT_DIRECTION, vec);
- glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_CUTOFF, m_spotsize / 2.0f);
- glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_EXPONENT, 128.0f * m_spotblend);
- }
- else {
- glLightf((GLenum)(GL_LIGHT0+slot), GL_SPOT_CUTOFF, 180.0f);
- }
- }
-
- if (m_nodiffuse) {
- vec[0] = vec[1] = vec[2] = vec[3] = 0.0f;
- }
- else {
- vec[0] = m_energy*m_color[0];
- vec[1] = m_energy*m_color[1];
- vec[2] = m_energy*m_color[2];
- vec[3] = 1.0f;
- }
-
- glLightfv((GLenum)(GL_LIGHT0+slot), GL_DIFFUSE, vec);
- if (m_nospecular)
- {
- vec[0] = vec[1] = vec[2] = vec[3] = 0.0f;
- }
- else if (m_nodiffuse) {
- vec[0] = m_energy*m_color[0];
- vec[1] = m_energy*m_color[1];
- vec[2] = m_energy*m_color[2];
- vec[3] = 1.0f;
- }
-
- glLightfv((GLenum)(GL_LIGHT0+slot), GL_SPECULAR, vec);
- glEnable((GLenum)(GL_LIGHT0+slot));
-
- return true;
-}
-
-GPULamp *RAS_OpenGLLight::GetGPULamp()
-{
- KX_LightObject* kxlight = (KX_LightObject*)m_light;
-
- if (m_glsl)
- return GPU_lamp_from_blender(kxlight->GetScene()->GetBlenderScene(), kxlight->GetBlenderObject(), kxlight->GetBlenderGroupObject());
- else
- return NULL;
-}
-
-
-bool RAS_OpenGLLight::HasShadowBuffer()
-{
- GPULamp *lamp;
-
- if ((lamp = GetGPULamp()))
- return GPU_lamp_has_shadow_buffer(lamp);
- else
- return false;
-}
-
-int RAS_OpenGLLight::GetShadowBindCode()
-{
- GPULamp *lamp;
-
- if ((lamp = GetGPULamp()))
- return GPU_lamp_shadow_bind_code(lamp);
- return -1;
-}
-
-MT_Matrix4x4 RAS_OpenGLLight::GetShadowMatrix()
-{
- GPULamp *lamp;
-
- if ((lamp = GetGPULamp()))
- return MT_Matrix4x4(GPU_lamp_dynpersmat(lamp));
- MT_Matrix4x4 mat;
- mat.setIdentity();
- return mat;
-}
-
-int RAS_OpenGLLight::GetShadowLayer()
-{
- GPULamp *lamp;
-
- if ((lamp = GetGPULamp()))
- return GPU_lamp_shadow_layer(lamp);
- else
- return 0;
-}
-
-void RAS_OpenGLLight::BindShadowBuffer(RAS_ICanvas *canvas, KX_Camera *cam, MT_Transform& camtrans)
-{
- GPULamp *lamp;
- float viewmat[4][4], winmat[4][4];
- int winsize;
-
- /* bind framebuffer */
- lamp = GetGPULamp();
- GPU_lamp_shadow_buffer_bind(lamp, viewmat, &winsize, winmat);
-
- if (GPU_lamp_shadow_buffer_type(lamp) == LA_SHADMAP_VARIANCE)
- m_rasterizer->SetUsingOverrideShader(true);
-
- /* GPU_lamp_shadow_buffer_bind() changes the viewport, so update the canvas */
- canvas->UpdateViewPort(0, 0, winsize, winsize);
-
- /* setup camera transformation */
- MT_Matrix4x4 modelviewmat((float*)viewmat);
- MT_Matrix4x4 projectionmat((float*)winmat);
-
- MT_Transform trans = MT_Transform((float*)viewmat);
- camtrans.invert(trans);
-
- cam->SetModelviewMatrix(modelviewmat);
- cam->SetProjectionMatrix(projectionmat);
-
- cam->NodeSetLocalPosition(camtrans.getOrigin());
- cam->NodeSetLocalOrientation(camtrans.getBasis());
- cam->NodeUpdateGS(0);
-
- /* setup rasterizer transformations */
- /* SetViewMatrix may use stereomode which we temporarily disable here */
- RAS_IRasterizer::StereoMode stereomode = m_rasterizer->GetStereoMode();
- m_rasterizer->SetStereoMode(RAS_IRasterizer::RAS_STEREO_NOSTEREO);
- m_rasterizer->SetProjectionMatrix(projectionmat);
- m_rasterizer->SetViewMatrix(modelviewmat, cam->NodeGetWorldOrientation(), cam->NodeGetWorldPosition(), cam->NodeGetLocalScaling(), cam->GetCameraData()->m_perspective);
- m_rasterizer->SetStereoMode(stereomode);
-}
-
-void RAS_OpenGLLight::UnbindShadowBuffer()
-{
- GPULamp *lamp = GetGPULamp();
- GPU_lamp_shadow_buffer_unbind(lamp);
-
- if (GPU_lamp_shadow_buffer_type(lamp) == LA_SHADMAP_VARIANCE)
- m_rasterizer->SetUsingOverrideShader(false);
-}
-
-Image *RAS_OpenGLLight::GetTextureImage(short texslot)
-{
- KX_LightObject* kxlight = (KX_LightObject*)m_light;
- Lamp *la = (Lamp*)kxlight->GetBlenderObject()->data;
-
- if (texslot >= MAX_MTEX || texslot < 0)
- {
- printf("KX_LightObject::GetTextureImage(): texslot exceeds slot bounds (0-%d)\n", MAX_MTEX-1);
- return NULL;
- }
-
- if (la->mtex[texslot])
- return la->mtex[texslot]->tex->ima;
-
- return NULL;
-}
-
-void RAS_OpenGLLight::Update()
-{
- GPULamp *lamp;
- KX_LightObject* kxlight = (KX_LightObject*)m_light;
-
- if ((lamp = GetGPULamp()) != NULL && kxlight->GetSGNode()) {
- float obmat[4][4];
- // lights don't get their openGL matrix updated, do it now
- if (kxlight->GetSGNode()->IsDirty())
- kxlight->GetOpenGLMatrix();
- float *dobmat = kxlight->GetOpenGLMatrixPtr()->getPointer();
-
- for (int i=0; i<4; i++)
- for (int j=0; j<4; j++, dobmat++)
- obmat[i][j] = (float)*dobmat;
- int hide = kxlight->GetVisible() ? 0 : 1;
- GPU_lamp_update(lamp, m_layer, hide, obmat);
- GPU_lamp_update_colors(lamp, m_color[0], m_color[1],
- m_color[2], m_energy);
- GPU_lamp_update_distance(lamp, m_distance, m_att1, m_att2, m_coeff_const, m_coeff_lin, m_coeff_quad);
- GPU_lamp_update_spot(lamp, m_spotsize, m_spotblend);
- }
-}
-
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.h
deleted file mode 100644
index a520b18c434..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLLight.h
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Mitchell Stokes
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "RAS_ILightObject.h"
-
-class RAS_OpenGLRasterizer;
-struct GPULamp;
-struct Image;
-
-class RAS_OpenGLLight : public RAS_ILightObject
-{
-
- RAS_OpenGLRasterizer *m_rasterizer;
-
- GPULamp *GetGPULamp();
-public:
- RAS_OpenGLLight(RAS_OpenGLRasterizer *ras);
- ~RAS_OpenGLLight();
-
- bool ApplyFixedFunctionLighting(KX_Scene *kxscene, int oblayer, int slot);
-
- RAS_OpenGLLight* Clone() { return new RAS_OpenGLLight(*this); }
-
- bool HasShadowBuffer();
- int GetShadowBindCode();
- MT_Matrix4x4 GetShadowMatrix();
- int GetShadowLayer();
- void BindShadowBuffer(RAS_ICanvas *canvas, KX_Camera *cam, MT_Transform& camtrans);
- void UnbindShadowBuffer();
- Image *GetTextureImage(short texslot);
- void Update();
-};
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp
deleted file mode 100644
index 58b3c61bd05..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.cpp
+++ /dev/null
@@ -1,347 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "GPU_glew.h"
-
-#include <stdio.h>
-
-#include "RAS_OpenGLOffScreen.h"
-#include "RAS_ICanvas.h"
-
-RAS_OpenGLOffScreen::RAS_OpenGLOffScreen(RAS_ICanvas *canvas)
- :m_canvas(canvas), m_depthrb(0), m_colorrb(0), m_depthtx(0), m_colortx(0),
- m_fbo(0), m_blitfbo(0), m_blitrbo(0), m_blittex(0), m_target(RAS_OFS_RENDER_BUFFER), m_bound(false)
-{
- m_width = 0;
- m_height = 0;
- m_samples = 0;
- m_color = 0;
-}
-
-RAS_OpenGLOffScreen::~RAS_OpenGLOffScreen()
-{
- Destroy();
-}
-
-bool RAS_OpenGLOffScreen::Create(int width, int height, int samples, RAS_OFS_RENDER_TARGET target)
-{
- GLenum status;
- GLuint glo[2], fbo;
- GLint max_samples;
- GLenum textarget;
-
- if (m_fbo) {
- printf("RAS_OpenGLOffScreen::Create(): buffer exists already, destroy first\n");
- return false;
- }
- if (target != RAS_IOffScreen::RAS_OFS_RENDER_BUFFER &&
- target != RAS_IOffScreen::RAS_OFS_RENDER_TEXTURE)
- {
- printf("RAS_OpenGLOffScreen::Create(): invalid offscren target\n");
- return false;
- }
- if (!GLEW_EXT_framebuffer_object) {
- printf("RAS_OpenGLOffScreen::Create(): frame buffer not supported\n");
- return false;
- }
- if (samples) {
- if (!GLEW_EXT_framebuffer_multisample ||
- !GLEW_EXT_framebuffer_blit)
- {
- samples = 0;
- }
- }
- if (samples && target == RAS_OFS_RENDER_TEXTURE) {
- // we need this in addition if we use multisample textures
- if (!GLEW_ARB_texture_multisample ||
- !GLEW_EXT_framebuffer_multisample_blit_scaled)
- {
- samples = 0;
- }
- }
- if (samples) {
- max_samples = 0;
- glGetIntegerv(GL_MAX_SAMPLES_EXT , &max_samples);
- if (samples > max_samples)
- samples = max_samples;
- }
- m_target = target;
- fbo = 0;
- glGenFramebuffersEXT(1, &fbo);
- if (fbo == 0) {
- printf("RAS_OpenGLOffScreen::Create(): frame buffer creation failed: %d\n", (int)glGetError());
- return false;
- }
- m_fbo = fbo;
- glo[0] = glo[1] = 0;
- if (target == RAS_OFS_RENDER_TEXTURE) {
- glGenTextures(2, glo);
- if (glo[0] == 0 || glo[1] == 0) {
- printf("RAS_OpenGLOffScreen::Create(): texture creation failed: %d\n", (int)glGetError());
- goto L_ERROR;
- }
- m_depthtx = glo[0];
- m_color = m_colortx = glo[1];
- if (samples) {
- textarget = GL_TEXTURE_2D_MULTISAMPLE;
- glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_depthtx);
- glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_DEPTH_COMPONENT, width, height, true);
- glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, m_colortx);
- glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, samples, GL_RGBA8, width, height, true);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, 0);
- }
- else {
- textarget = GL_TEXTURE_2D;
- glBindTexture(GL_TEXTURE_2D, m_depthtx);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, m_colortx);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glBindTexture(GL_TEXTURE_2D, 0);
- }
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, textarget, m_depthtx, 0);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, textarget, m_colortx, 0);
- }
- else {
- glGenRenderbuffersEXT(2, glo);
- if (glo[0] == 0 || glo[1] == 0) {
- printf("RAS_OpenGLOffScreen::Create(): render buffer creation failed: %d\n", (int)glGetError());
- goto L_ERROR;
- }
- m_depthrb = glo[0];
- m_colorrb = glo[1];
- glBindRenderbufferEXT(GL_RENDERBUFFER, m_depthrb);
- glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, samples, GL_DEPTH_COMPONENT, width, height);
- glBindRenderbufferEXT(GL_RENDERBUFFER, m_colorrb);
- glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, samples, GL_RGBA8, width, height);
- glBindRenderbufferEXT(GL_RENDERBUFFER, 0);
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER, m_depthrb);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER, m_colorrb);
- }
- status = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
-
- if (status != GL_FRAMEBUFFER_COMPLETE_EXT) {
- printf("RAS_OpenGLOffScreen::Create(): frame buffer incomplete: %d\n", (int)status);
- goto L_ERROR;
- }
- m_width = width;
- m_height = height;
-
- if (samples > 0) {
- GLuint blit_tex;
- GLuint blit_fbo;
- // create a secondary FBO to blit to before the pixel can be read
-
- /* write into new single-sample buffer */
- glGenFramebuffersEXT(1, &blit_fbo);
- if (!blit_fbo) {
- printf("RAS_OpenGLOffScreen::Create(): failed creating a FBO for multi-sample offscreen buffer\n");
- goto L_ERROR;
- }
- m_blitfbo = blit_fbo;
- blit_tex = 0;
- if (target == RAS_OFS_RENDER_TEXTURE) {
- glGenTextures(1, &blit_tex);
- if (!blit_tex) {
- printf("RAS_OpenGLOffScreen::Create(): failed creating a texture for multi-sample offscreen buffer\n");
- goto L_ERROR;
- }
- // m_color is the texture where the final render goes, the blit texture in this case
- m_color = m_blittex = blit_tex;
- glBindTexture(GL_TEXTURE_2D, m_blittex);
- glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
- glBindTexture(GL_TEXTURE_2D, 0);
- glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_blitfbo);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, m_blittex, 0);
- }
- else {
- /* create render buffer for new 'fbo_blit' */
- glGenRenderbuffersEXT(1, &blit_tex);
- if (!blit_tex) {
- printf("RAS_OpenGLOffScreen::Create(): failed creating a render buffer for multi-sample offscreen buffer\n");
- goto L_ERROR;
- }
- m_blitrbo = blit_tex;
- glBindRenderbufferEXT(GL_RENDERBUFFER, m_blitrbo);
- glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER, 0, GL_RGBA8, width, height);
- glBindRenderbufferEXT(GL_RENDERBUFFER, 0);
- glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, m_blitfbo);
- glFramebufferRenderbufferEXT(GL_DRAW_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER, m_blitrbo);
- }
- status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER_EXT);
- glBindFramebuffer(GL_DRAW_FRAMEBUFFER_EXT, 0);
- if (status != GL_FRAMEBUFFER_COMPLETE) {
- printf("RAS_OpenGLOffScreen::Create(): frame buffer for multi-sample offscreen buffer incomplete: %d\n", (int)status);
- goto L_ERROR;
- }
- // remember that multisample is enabled
- m_samples = 1;
- }
- return true;
-
-L_ERROR:
- Destroy();
- return false;
-}
-
-void RAS_OpenGLOffScreen::Destroy()
-{
- GLuint globj;
- Unbind();
- if (m_fbo) {
- globj = m_fbo;
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- if (m_target == RAS_OFS_RENDER_TEXTURE) {
- GLenum textarget = (m_samples) ? GL_TEXTURE_2D_MULTISAMPLE : GL_TEXTURE_2D;
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, textarget, 0, 0);
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, textarget, 0, 0);
- }
- else {
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, 0);
- }
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDeleteFramebuffersEXT(1, &globj);
- m_fbo = 0;
- }
- if (m_depthrb) {
- globj = m_depthrb;
- glDeleteRenderbuffers(1, &globj);
- m_depthrb = 0;
- }
- if (m_colorrb) {
- globj = m_colorrb;
- glDeleteRenderbuffers(1, &globj);
- m_colorrb = 0;
- }
- if (m_depthtx) {
- globj = m_depthtx;
- glDeleteTextures(1, &globj);
- m_depthtx = 0;
- }
- if (m_colortx) {
- globj = m_colortx;
- glDeleteTextures(1, &globj);
- m_colortx = 0;
- }
- if (m_blitfbo) {
- globj = m_blitfbo;
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_blitfbo);
- if (m_target == RAS_OFS_RENDER_TEXTURE) {
- glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0);
- }
- else {
- glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, 0);
- }
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glDeleteFramebuffersEXT(1, &globj);
- m_blitfbo = 0;
- }
- if (m_blitrbo) {
- globj = m_blitrbo;
- glDeleteRenderbuffers(1, &globj);
- m_blitrbo = 0;
- }
- if (m_blittex) {
- globj = m_blittex;
- glDeleteTextures(1, &globj);
- m_blittex = 0;
- }
- m_width = 0;
- m_height = 0;
- m_samples = 0;
- m_color = 0;
- m_target = RAS_OFS_RENDER_BUFFER;
-}
-
-void RAS_OpenGLOffScreen::Bind(RAS_OFS_BIND_MODE mode)
-{
- if (m_fbo) {
- if (mode == RAS_OFS_BIND_RENDER) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
- glDrawBuffer(GL_COLOR_ATTACHMENT0_EXT);
- glViewport(0, 0, m_width, m_height);
- glDisable(GL_SCISSOR_TEST);
- }
- else if (!m_blitfbo) {
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, m_fbo);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
- }
- else {
- glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, m_blitfbo);
- glReadBuffer(GL_COLOR_ATTACHMENT0_EXT);
- }
- m_bound = true;
- }
-}
-
-void RAS_OpenGLOffScreen::Unbind()
-{
- if (!m_bound)
- return;
-
- glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);
- glEnable(GL_SCISSOR_TEST);
- glReadBuffer(GL_BACK);
- glDrawBuffer(GL_BACK);
- m_bound = false;
-}
-
-void RAS_OpenGLOffScreen::MipMap()
-{
- if (m_color) {
- glBindTexture(GL_TEXTURE_2D, m_color);
- glGenerateMipmap(GL_TEXTURE_2D);
- glBindTexture(GL_TEXTURE_2D, 0);
- }
-}
-
-void RAS_OpenGLOffScreen::Blit()
-{
- if (m_bound && m_blitfbo) {
- // set the draw target to the secondary FBO, the read target is still the multisample FBO
- glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER, m_blitfbo);
-
- // sample the primary
- glBlitFramebufferEXT(0, 0, m_width, m_height, 0, 0, m_width, m_height, GL_COLOR_BUFFER_BIT, GL_NEAREST);
-
- // make sure the next glReadPixels will read from the secondary buffer
- glBindFramebufferEXT(GL_READ_FRAMEBUFFER, m_blitfbo);
- }
-}
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h
deleted file mode 100644
index 3f6845f1e21..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLOffScreen.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __RAS_OPENGLOFFSCREEN__
-#define __RAS_OPENGLOFFSCREEN__
-
-#include "RAS_IOffScreen.h"
-#include "GPU_extensions.h"
-
-class RAS_ICanvas;
-
-class RAS_OpenGLOffScreen : public RAS_IOffScreen
-{
- RAS_ICanvas *m_canvas;
- // these are GL objects
- unsigned int m_depthrb;
- unsigned int m_colorrb;
- unsigned int m_depthtx;
- unsigned int m_colortx;
- unsigned int m_fbo;
- unsigned int m_blitfbo;
- unsigned int m_blitrbo;
- unsigned int m_blittex;
- RAS_OFS_RENDER_TARGET m_target;
- bool m_bound;
-
-
-public:
- RAS_OpenGLOffScreen(RAS_ICanvas *canvas);
- ~RAS_OpenGLOffScreen();
-
- bool Create(int width, int height, int samples, RAS_OFS_RENDER_TARGET target);
- void Destroy();
- void Bind(RAS_OFS_BIND_MODE mode);
- void Blit();
- void Unbind();
- void MipMap();
-};
-
-#endif /* __RAS_OPENGLOFFSCREEN__ */
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
deleted file mode 100644
index 5eed9b3b8f8..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
+++ /dev/null
@@ -1,1723 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.cpp
- * \ingroup bgerastogl
- */
-
-
-#include <math.h>
-#include <stdlib.h>
-
-#include "RAS_OpenGLRasterizer.h"
-
-#include "GPU_glew.h"
-
-#include "RAS_ICanvas.h"
-#include "RAS_Rect.h"
-#include "RAS_TexVert.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-#include "RAS_ILightObject.h"
-#include "MT_CmMatrix4x4.h"
-
-#include "RAS_OpenGLLight.h"
-#include "RAS_OpenGLOffScreen.h"
-#include "RAS_OpenGLSync.h"
-
-#include "RAS_StorageVA.h"
-#include "RAS_StorageVBO.h"
-
-#include "GPU_draw.h"
-#include "GPU_extensions.h"
-#include "GPU_material.h"
-#include "GPU_shader.h"
-
-extern "C"{
- #include "BLF_api.h"
- #include "BKE_DerivedMesh.h"
-}
-
-
-// XXX Clean these up <<<
-#include "EXP_Value.h"
-#include "KX_Scene.h"
-#include "KX_RayCast.h"
-#include "KX_GameObject.h"
-// >>>
-
-#ifndef M_PI
-#define M_PI 3.14159265358979323846
-#endif
-
-/**
- * 32x32 bit masks for vinterlace stereo mode
- */
-static GLuint left_eye_vinterlace_mask[32];
-static GLuint right_eye_vinterlace_mask[32];
-
-/**
- * 32x32 bit masks for hinterlace stereo mode.
- * Left eye = &hinterlace_mask[0]
- * Right eye = &hinterlace_mask[1]
- */
-static GLuint hinterlace_mask[33];
-
-RAS_OpenGLRasterizer::RAS_OpenGLRasterizer(RAS_ICanvas* canvas, RAS_STORAGE_TYPE storage)
- :RAS_IRasterizer(canvas),
- m_2DCanvas(canvas),
- m_fogenabled(false),
- m_time(0.0f),
- m_campos(0.0f, 0.0f, 0.0f),
- m_camortho(false),
- m_camnegscale(false),
- m_stereomode(RAS_STEREO_NOSTEREO),
- m_curreye(RAS_STEREO_LEFTEYE),
- m_eyeseparation(0.0f),
- m_focallength(0.0f),
- m_setfocallength(false),
- m_noOfScanlines(32),
- m_motionblur(0),
- m_motionblurvalue(-1.0f),
- m_usingoverrideshader(false),
- m_clientobject(NULL),
- m_auxilaryClientInfo(NULL),
- m_drawingmode(KX_TEXTURED),
- m_texco_num(0),
- m_attrib_num(0),
- //m_last_alphablend(GPU_BLEND_SOLID),
- m_last_frontface(true),
- m_materialCachingInfo(0),
- m_storage_type(storage)
-{
- m_viewmatrix.setIdentity();
- m_viewinvmatrix.setIdentity();
-
- for (int i = 0; i < 32; i++)
- {
- left_eye_vinterlace_mask[i] = 0x55555555;
- right_eye_vinterlace_mask[i] = 0xAAAAAAAA;
- hinterlace_mask[i] = (i&1)*0xFFFFFFFF;
- }
- hinterlace_mask[32] = 0;
-
- m_prevafvalue = GPU_get_anisotropic();
-
- if (m_storage_type == RAS_VBO /*|| m_storage_type == RAS_AUTO_STORAGE && GLEW_ARB_vertex_buffer_object*/) {
- m_storage = new RAS_StorageVBO(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer);
- }
- else if ((m_storage_type == RAS_VA) || (m_storage_type == RAS_AUTO_STORAGE)) {
- m_storage = new RAS_StorageVA(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer);
- }
- else {
- printf("Unknown rasterizer storage type, falling back to vertex arrays\n");
- m_storage = new RAS_StorageVA(&m_texco_num, m_texco, &m_attrib_num, m_attrib, m_attrib_layer);
- }
-
- glGetIntegerv(GL_MAX_LIGHTS, (GLint *) &m_numgllights);
- if (m_numgllights < 8)
- m_numgllights = 8;
-}
-
-
-
-RAS_OpenGLRasterizer::~RAS_OpenGLRasterizer()
-{
- // Restore the previous AF value
- GPU_set_anisotropic(m_prevafvalue);
-
- if (m_storage)
- delete m_storage;
-}
-
-bool RAS_OpenGLRasterizer::Init()
-{
- bool storage_init;
- GPU_state_init();
-
-
- m_ambr = 0.0f;
- m_ambg = 0.0f;
- m_ambb = 0.0f;
-
- glDisable(GL_BLEND);
- glDisable(GL_ALPHA_TEST);
- //m_last_alphablend = GPU_BLEND_SOLID;
- GPU_set_material_alpha_blend(GPU_BLEND_SOLID);
-
- glFrontFace(GL_CCW);
- m_last_frontface = true;
-
- m_redback = 0.4375f;
- m_greenback = 0.4375f;
- m_blueback = 0.4375f;
- m_alphaback = 0.0f;
-
- glClearColor(m_redback,m_greenback,m_blueback,m_alphaback);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
-
- glShadeModel(GL_SMOOTH);
-
- storage_init = m_storage->Init();
-
- return true && storage_init;
-}
-
-
-void RAS_OpenGLRasterizer::SetAmbientColor(float color[3])
-{
- m_ambr = color[0];
- m_ambg = color[1];
- m_ambb = color[2];
-}
-
-void RAS_OpenGLRasterizer::SetAmbient(float factor)
-{
- float ambient[] = {m_ambr * factor, m_ambg * factor, m_ambb * factor, 1.0f};
- glLightModelfv(GL_LIGHT_MODEL_AMBIENT, ambient);
-}
-
-void RAS_OpenGLRasterizer::SetBackColor(float color[3])
-{
- m_redback = color[0];
- m_greenback = color[1];
- m_blueback = color[2];
- m_alphaback = 0.0f;
-}
-
-void RAS_OpenGLRasterizer::SetFog(short type, float start, float dist, float intensity, float color[3])
-{
- float params[4] = {color[0], color[1], color[2], 1.0f};
- glFogi(GL_FOG_MODE, GL_LINEAR);
- glFogf(GL_FOG_DENSITY, intensity / 10.0f);
- glFogf(GL_FOG_START, start);
- glFogf(GL_FOG_END, start + dist);
- glFogfv(GL_FOG_COLOR, params);
-}
-
-void RAS_OpenGLRasterizer::EnableFog(bool enable)
-{
- m_fogenabled = enable;
-}
-
-void RAS_OpenGLRasterizer::DisplayFog()
-{
- if ((m_drawingmode >= KX_SOLID) && m_fogenabled) {
- glEnable(GL_FOG);
- }
- else {
- glDisable(GL_FOG);
- }
-}
-
-bool RAS_OpenGLRasterizer::SetMaterial(const RAS_IPolyMaterial& mat)
-{
- return mat.Activate(this, m_materialCachingInfo);
-}
-
-
-
-void RAS_OpenGLRasterizer::Exit()
-{
- m_storage->Exit();
-
- glEnable(GL_CULL_FACE);
- glEnable(GL_DEPTH_TEST);
- glClearDepth(1.0f);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glClearColor(m_redback, m_greenback, m_blueback, m_alphaback);
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
- glDepthMask (GL_TRUE);
- glDepthFunc(GL_LEQUAL);
- glBlendFunc(GL_ONE, GL_ZERO);
-
- glDisable(GL_POLYGON_STIPPLE);
-
- glDisable(GL_LIGHTING);
- if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
- glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SINGLE_COLOR);
-
- EndFrame();
-}
-
-bool RAS_OpenGLRasterizer::BeginFrame(double time)
-{
- m_time = time;
-
- // Blender camera routine destroys the settings
- if (m_drawingmode < KX_SOLID)
- {
- glDisable(GL_CULL_FACE);
- glDisable(GL_DEPTH_TEST);
- }
- else
- {
- glEnable(GL_DEPTH_TEST);
- glEnable(GL_CULL_FACE);
- }
-
- glDisable(GL_BLEND);
- glDisable(GL_ALPHA_TEST);
- //m_last_alphablend = GPU_BLEND_SOLID;
- GPU_set_material_alpha_blend(GPU_BLEND_SOLID);
-
- glFrontFace(GL_CCW);
- m_last_frontface = true;
-
- glShadeModel(GL_SMOOTH);
-
- glEnable(GL_MULTISAMPLE_ARB);
-
- m_2DCanvas->BeginFrame();
-
- // Render Tools
- m_clientobject = NULL;
- m_lastlightlayer = -1;
- m_lastauxinfo = NULL;
- m_lastlighting = true; /* force disable in DisableOpenGLLights() */
- DisableOpenGLLights();
-
- return true;
-}
-
-
-
-void RAS_OpenGLRasterizer::SetDrawingMode(int drawingmode)
-{
- m_drawingmode = drawingmode;
-
- if (m_drawingmode == KX_WIREFRAME)
- glDisable(GL_CULL_FACE);
-
- m_storage->SetDrawingMode(drawingmode);
-}
-
-int RAS_OpenGLRasterizer::GetDrawingMode()
-{
- return m_drawingmode;
-}
-
-
-void RAS_OpenGLRasterizer::SetDepthMask(DepthMask depthmask)
-{
- glDepthMask(depthmask == KX_DEPTHMASK_DISABLED ? GL_FALSE : GL_TRUE);
-}
-
-
-void RAS_OpenGLRasterizer::ClearColorBuffer()
-{
- m_2DCanvas->ClearColor(m_redback,m_greenback,m_blueback,m_alphaback);
- m_2DCanvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER);
-}
-
-
-void RAS_OpenGLRasterizer::ClearDepthBuffer()
-{
- m_2DCanvas->ClearBuffer(RAS_ICanvas::DEPTH_BUFFER);
-}
-
-
-void RAS_OpenGLRasterizer::ClearCachingInfo(void)
-{
- m_materialCachingInfo = 0;
-}
-
-void RAS_OpenGLRasterizer::FlushDebugShapes(SCA_IScene *scene)
-{
- std::vector<OglDebugShape> &debugShapes = m_debugShapes[scene];
- if (debugShapes.empty())
- return;
-
- // DrawDebugLines
- GLboolean light, tex;
-
- light= glIsEnabled(GL_LIGHTING);
- tex= glIsEnabled(GL_TEXTURE_2D);
-
- if (light) glDisable(GL_LIGHTING);
- if (tex) glDisable(GL_TEXTURE_2D);
-
- // draw lines
- glBegin(GL_LINES);
- for (unsigned int i = 0; i < debugShapes.size(); i++) {
- if (debugShapes[i].m_type != OglDebugShape::LINE)
- continue;
- glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], debugShapes[i].m_color[2], 1.0f);
- const MT_Scalar *fromPtr = &debugShapes[i].m_pos.x();
- const MT_Scalar *toPtr= &debugShapes[i].m_param.x();
- glVertex3fv(fromPtr);
- glVertex3fv(toPtr);
- }
- glEnd();
-
- // draw circles
- for (unsigned int i = 0; i < debugShapes.size(); i++) {
- if (debugShapes[i].m_type != OglDebugShape::CIRCLE)
- continue;
- glBegin(GL_LINE_LOOP);
- glColor4f(debugShapes[i].m_color[0], debugShapes[i].m_color[1], debugShapes[i].m_color[2], 1.0f);
-
- static const MT_Vector3 worldUp(0.0f, 0.0f, 1.0f);
- MT_Vector3 norm = debugShapes[i].m_param;
- MT_Matrix3x3 tr;
- if (norm.fuzzyZero() || norm == worldUp)
- {
- tr.setIdentity();
- }
- else
- {
- MT_Vector3 xaxis, yaxis;
- xaxis = MT_cross(norm, worldUp);
- yaxis = MT_cross(xaxis, norm);
- tr.setValue(xaxis.x(), xaxis.y(), xaxis.z(),
- yaxis.x(), yaxis.y(), yaxis.z(),
- norm.x(), norm.y(), norm.z());
- }
- MT_Scalar rad = debugShapes[i].m_param2.x();
- int n = (int)debugShapes[i].m_param2.y();
- for (int j = 0; j<n; j++)
- {
- MT_Scalar theta = j*(float)M_PI*2/n;
- MT_Vector3 pos(cosf(theta) * rad, sinf(theta) * rad, 0.0f);
- pos = pos*tr;
- pos += debugShapes[i].m_pos;
- const MT_Scalar* posPtr = &pos.x();
- glVertex3fv(posPtr);
- }
- glEnd();
- }
-
- if (light) glEnable(GL_LIGHTING);
- if (tex) glEnable(GL_TEXTURE_2D);
-
- debugShapes.clear();
-}
-
-void RAS_OpenGLRasterizer::EndFrame()
-{
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
-
- glDisable(GL_MULTISAMPLE_ARB);
-
- m_2DCanvas->EndFrame();
-}
-
-void RAS_OpenGLRasterizer::SetRenderArea()
-{
- RAS_Rect area;
- // only above/below stereo method needs viewport adjustment
- switch (m_stereomode)
- {
- case RAS_STEREO_ABOVEBELOW:
- switch (m_curreye) {
- case RAS_STEREO_LEFTEYE:
- // upper half of window
- area.SetLeft(0);
- area.SetBottom(m_2DCanvas->GetHeight() -
- int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
-
- area.SetRight(int(m_2DCanvas->GetWidth()));
- area.SetTop(int(m_2DCanvas->GetHeight()));
- m_2DCanvas->SetDisplayArea(&area);
- break;
- case RAS_STEREO_RIGHTEYE:
- // lower half of window
- area.SetLeft(0);
- area.SetBottom(0);
- area.SetRight(int(m_2DCanvas->GetWidth()));
- area.SetTop(int(m_2DCanvas->GetHeight() - m_noOfScanlines) / 2);
- m_2DCanvas->SetDisplayArea(&area);
- break;
- }
- break;
- case RAS_STEREO_3DTVTOPBOTTOM:
- switch (m_curreye) {
- case RAS_STEREO_LEFTEYE:
- // upper half of window
- area.SetLeft(0);
- area.SetBottom(m_2DCanvas->GetHeight() -
- m_2DCanvas->GetHeight() / 2);
-
- area.SetRight(m_2DCanvas->GetWidth());
- area.SetTop(m_2DCanvas->GetHeight());
- m_2DCanvas->SetDisplayArea(&area);
- break;
- case RAS_STEREO_RIGHTEYE:
- // lower half of window
- area.SetLeft(0);
- area.SetBottom(0);
- area.SetRight(m_2DCanvas->GetWidth());
- area.SetTop(m_2DCanvas->GetHeight() / 2);
- m_2DCanvas->SetDisplayArea(&area);
- break;
- }
- break;
- case RAS_STEREO_SIDEBYSIDE:
- switch (m_curreye)
- {
- case RAS_STEREO_LEFTEYE:
- // Left half of window
- area.SetLeft(0);
- area.SetBottom(0);
- area.SetRight(m_2DCanvas->GetWidth()/2);
- area.SetTop(m_2DCanvas->GetHeight());
- m_2DCanvas->SetDisplayArea(&area);
- break;
- case RAS_STEREO_RIGHTEYE:
- // Right half of window
- area.SetLeft(m_2DCanvas->GetWidth()/2);
- area.SetBottom(0);
- area.SetRight(m_2DCanvas->GetWidth());
- area.SetTop(m_2DCanvas->GetHeight());
- m_2DCanvas->SetDisplayArea(&area);
- break;
- }
- break;
- default:
- // every available pixel
- area.SetLeft(0);
- area.SetBottom(0);
- area.SetRight(int(m_2DCanvas->GetWidth()));
- area.SetTop(int(m_2DCanvas->GetHeight()));
- m_2DCanvas->SetDisplayArea(&area);
- break;
- }
-}
-
-void RAS_OpenGLRasterizer::SetStereoMode(const StereoMode stereomode)
-{
- m_stereomode = stereomode;
-}
-
-RAS_IRasterizer::StereoMode RAS_OpenGLRasterizer::GetStereoMode()
-{
- return m_stereomode;
-}
-
-bool RAS_OpenGLRasterizer::Stereo()
-{
- if (m_stereomode > RAS_STEREO_NOSTEREO) // > 0
- return true;
- else
- return false;
-}
-
-bool RAS_OpenGLRasterizer::InterlacedStereo()
-{
- return m_stereomode == RAS_STEREO_VINTERLACE || m_stereomode == RAS_STEREO_INTERLACED;
-}
-
-void RAS_OpenGLRasterizer::SetEye(const StereoEye eye)
-{
- m_curreye = eye;
- switch (m_stereomode)
- {
- case RAS_STEREO_QUADBUFFERED:
- glDrawBuffer(m_curreye == RAS_STEREO_LEFTEYE ? GL_BACK_LEFT : GL_BACK_RIGHT);
- break;
- case RAS_STEREO_ANAGLYPH:
- if (m_curreye == RAS_STEREO_LEFTEYE) {
- glColorMask(GL_TRUE, GL_FALSE, GL_FALSE, GL_FALSE);
- }
- else {
- //glAccum(GL_LOAD, 1.0f);
- glColorMask(GL_FALSE, GL_TRUE, GL_TRUE, GL_FALSE);
- ClearDepthBuffer();
- }
- break;
- case RAS_STEREO_VINTERLACE:
- {
- // OpenGL stippling is deprecated, it is no longer possible to affect all shaders
- // this way, offscreen rendering and then compositing may be the better solution
- glEnable(GL_POLYGON_STIPPLE);
- glPolygonStipple((const GLubyte*) ((m_curreye == RAS_STEREO_LEFTEYE) ? left_eye_vinterlace_mask : right_eye_vinterlace_mask));
- if (m_curreye == RAS_STEREO_RIGHTEYE)
- ClearDepthBuffer();
- break;
- }
- case RAS_STEREO_INTERLACED:
- {
- glEnable(GL_POLYGON_STIPPLE);
- glPolygonStipple((const GLubyte*) &hinterlace_mask[m_curreye == RAS_STEREO_LEFTEYE?0:1]);
- if (m_curreye == RAS_STEREO_RIGHTEYE)
- ClearDepthBuffer();
- break;
- }
- default:
- break;
- }
-}
-
-RAS_IRasterizer::StereoEye RAS_OpenGLRasterizer::GetEye()
-{
- return m_curreye;
-}
-
-
-void RAS_OpenGLRasterizer::SetEyeSeparation(const float eyeseparation)
-{
- m_eyeseparation = eyeseparation;
-}
-
-float RAS_OpenGLRasterizer::GetEyeSeparation()
-{
- return m_eyeseparation;
-}
-
-void RAS_OpenGLRasterizer::SetFocalLength(const float focallength)
-{
- m_focallength = focallength;
- m_setfocallength = true;
-}
-
-float RAS_OpenGLRasterizer::GetFocalLength()
-{
- return m_focallength;
-}
-
-RAS_IOffScreen *RAS_OpenGLRasterizer::CreateOffScreen(int width, int height, int samples, int target)
-{
- RAS_IOffScreen *ofs;
-
- ofs = new RAS_OpenGLOffScreen(m_2DCanvas);
-
- if (!ofs->Create(width, height, samples, (RAS_IOffScreen::RAS_OFS_RENDER_TARGET)target)) {
- delete ofs;
- return NULL;
- }
- return ofs;
-}
-
-RAS_ISync *RAS_OpenGLRasterizer::CreateSync(int type)
-{
- RAS_ISync *sync;
-
- sync = new RAS_OpenGLSync();
-
- if (!sync->Create((RAS_ISync::RAS_SYNC_TYPE)type)) {
- delete sync;
- return NULL;
- }
- return sync;
-}
-
-void RAS_OpenGLRasterizer::SwapBuffers()
-{
- m_2DCanvas->SwapBuffers();
-}
-
-
-
-const MT_Matrix4x4& RAS_OpenGLRasterizer::GetViewMatrix() const
-{
- return m_viewmatrix;
-}
-
-const MT_Matrix4x4& RAS_OpenGLRasterizer::GetViewInvMatrix() const
-{
- return m_viewinvmatrix;
-}
-
-void RAS_OpenGLRasterizer::IndexPrimitives_3DText(RAS_MeshSlot& ms,
- class RAS_IPolyMaterial* polymat)
-{
- bool obcolor = ms.m_bObjectColor;
- MT_Vector4& rgba = ms.m_RGBAcolor;
- RAS_MeshSlot::iterator it;
-
- const STR_String& mytext = ((CValue*)m_clientobject)->GetPropertyText("Text");
-
- // handle object color
- if (obcolor) {
- glDisableClientState(GL_COLOR_ARRAY);
- glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]);
- }
- else
- glEnableClientState(GL_COLOR_ARRAY);
-
- for (ms.begin(it); !ms.end(it); ms.next(it)) {
- RAS_TexVert *vertex;
- size_t i, j, numvert;
-
- numvert = it.array->m_type;
-
- if (it.array->m_type == RAS_DisplayArray::LINE) {
- // line drawing, no text
- glBegin(GL_LINES);
-
- for (i=0; i<it.totindex; i+=2)
- {
- vertex = &it.vertex[it.index[i]];
- glVertex3fv(vertex->getXYZ());
-
- vertex = &it.vertex[it.index[i+1]];
- glVertex3fv(vertex->getXYZ());
- }
-
- glEnd();
- }
- else {
- // triangle and quad text drawing
- for (i=0; i<it.totindex; i+=numvert)
- {
- float v[4][3];
- const float *v_ptr[4] = {NULL};
- const float *uv_ptr[4] = {NULL};
- int glattrib, unit;
-
- for (j=0; j<numvert; j++) {
- vertex = &it.vertex[it.index[i+j]];
-
- v[j][0] = vertex->getXYZ()[0];
- v[j][1] = vertex->getXYZ()[1];
- v[j][2] = vertex->getXYZ()[2];
- v_ptr[j] = v[j];
-
- uv_ptr[j] = vertex->getUV(0);
- }
-
- // find the right opengl attribute
- glattrib = -1;
- if (GLEW_ARB_vertex_program)
- for (unit=0; unit<m_attrib_num; unit++)
- if (m_attrib[unit] == RAS_TEXCO_UV)
- glattrib = unit;
-
- GPU_render_text(
- polymat->GetMTexPoly(), polymat->GetDrawingMode(), mytext, mytext.Length(), polymat->GetMCol(),
- v_ptr, uv_ptr, glattrib);
-
- ClearCachingInfo();
- }
- }
- }
-
- glDisableClientState(GL_COLOR_ARRAY);
-}
-
-void RAS_OpenGLRasterizer::SetTexCoordNum(int num)
-{
- m_texco_num = num;
- if (m_texco_num > RAS_MAX_TEXCO)
- m_texco_num = RAS_MAX_TEXCO;
-}
-
-void RAS_OpenGLRasterizer::SetAttribNum(int num)
-{
- m_attrib_num = num;
- if (m_attrib_num > RAS_MAX_ATTRIB)
- m_attrib_num = RAS_MAX_ATTRIB;
-}
-
-void RAS_OpenGLRasterizer::SetTexCoord(TexCoGen coords, int unit)
-{
- // this changes from material to material
- if (unit < RAS_MAX_TEXCO)
- m_texco[unit] = coords;
-}
-
-void RAS_OpenGLRasterizer::SetAttrib(TexCoGen coords, int unit, int layer)
-{
- // this changes from material to material
- if (unit < RAS_MAX_ATTRIB) {
- m_attrib[unit] = coords;
- m_attrib_layer[unit] = layer;
- }
-}
-
-void RAS_OpenGLRasterizer::IndexPrimitives(RAS_MeshSlot& ms)
-{
- if (ms.m_pDerivedMesh)
- DrawDerivedMesh(ms);
- else
- m_storage->IndexPrimitives(ms);
-}
-
-// Code for hooking into Blender's mesh drawing for derived meshes.
-// If/when we use more of Blender's drawing code, we may be able to
-// clean this up
-static bool current_wireframe;
-static RAS_MaterialBucket *current_bucket;
-static RAS_IPolyMaterial *current_polymat;
-static RAS_MeshSlot *current_ms;
-static RAS_MeshObject *current_mesh;
-static int current_blmat_nr;
-static GPUVertexAttribs current_gpu_attribs;
-static Image *current_image;
-static int CheckMaterialDM(int matnr, void *attribs)
-{
- // only draw the current material
- if (matnr != current_blmat_nr)
- return 0;
- GPUVertexAttribs *gattribs = (GPUVertexAttribs *)attribs;
- if (gattribs)
- memcpy(gattribs, &current_gpu_attribs, sizeof(GPUVertexAttribs));
- return 1;
-}
-
-static DMDrawOption CheckTexDM(MTexPoly *mtexpoly, const bool has_mcol, int matnr)
-{
-
- // index is the original face index, retrieve the polygon
- if (matnr == current_blmat_nr &&
- (mtexpoly == NULL || mtexpoly->tpage == current_image)) {
- // must handle color.
- if (current_wireframe)
- return DM_DRAW_OPTION_NO_MCOL;
- if (current_ms->m_bObjectColor) {
- MT_Vector4& rgba = current_ms->m_RGBAcolor;
- glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]);
- // don't use mcol
- return DM_DRAW_OPTION_NO_MCOL;
- }
- if (!has_mcol) {
- // we have to set the color from the material
- unsigned char rgba[4];
- current_polymat->GetMaterialRGBAColor(rgba);
- glColor4ubv((const GLubyte *)rgba);
- return DM_DRAW_OPTION_NORMAL;
- }
- return DM_DRAW_OPTION_NORMAL;
- }
- return DM_DRAW_OPTION_SKIP;
-}
-
-void RAS_OpenGLRasterizer::DrawDerivedMesh(class RAS_MeshSlot &ms)
-{
- // mesh data is in derived mesh
- current_bucket = ms.m_bucket;
- current_polymat = current_bucket->GetPolyMaterial();
- current_ms = &ms;
- current_mesh = ms.m_mesh;
- current_wireframe = m_drawingmode <= RAS_IRasterizer::KX_WIREFRAME;
- // MCol *mcol = (MCol*)ms.m_pDerivedMesh->getFaceDataArray(ms.m_pDerivedMesh, CD_MCOL); /* UNUSED */
-
- // handle two-side
- if (current_polymat->GetDrawingMode() & RAS_IRasterizer::KX_BACKCULL)
- this->SetCullFace(true);
- else
- this->SetCullFace(false);
-
- if (current_polymat->GetFlag() & RAS_BLENDERGLSL) {
- // GetMaterialIndex return the original mface material index,
- // increment by 1 to match what derived mesh is doing
- current_blmat_nr = current_polymat->GetMaterialIndex()+1;
- // For GLSL we need to retrieve the GPU material attribute
- Material* blmat = current_polymat->GetBlenderMaterial();
- Scene* blscene = current_polymat->GetBlenderScene();
- if (!current_wireframe && blscene && blmat)
- GPU_material_vertex_attributes(GPU_material_from_blender(blscene, blmat, false), &current_gpu_attribs);
- else
- memset(&current_gpu_attribs, 0, sizeof(current_gpu_attribs));
- // DM draw can mess up blending mode, restore at the end
- int current_blend_mode = GPU_get_material_alpha_blend();
- ms.m_pDerivedMesh->drawFacesGLSL(ms.m_pDerivedMesh, CheckMaterialDM);
- GPU_set_material_alpha_blend(current_blend_mode);
- } else {
- //ms.m_pDerivedMesh->drawMappedFacesTex(ms.m_pDerivedMesh, CheckTexfaceDM, mcol);
- current_blmat_nr = current_polymat->GetMaterialIndex();
- current_image = current_polymat->GetBlenderImage();
- ms.m_pDerivedMesh->drawFacesTex(ms.m_pDerivedMesh, CheckTexDM, NULL, NULL, DM_DRAW_USE_ACTIVE_UV);
- }
-}
-
-void RAS_OpenGLRasterizer::SetProjectionMatrix(MT_CmMatrix4x4 &mat)
-{
- glMatrixMode(GL_PROJECTION);
- float* matrix = &mat(0, 0);
- glLoadMatrixf(matrix);
-
- m_camortho = (mat(3, 3) != 0.0f);
-}
-
-void RAS_OpenGLRasterizer::SetProjectionMatrix(const MT_Matrix4x4 & mat)
-{
- glMatrixMode(GL_PROJECTION);
- float matrix[16];
- /* Get into argument. Looks a bit dodgy, but it's ok. */
- mat.getValue(matrix);
- glLoadMatrixf(matrix);
-
- m_camortho = (mat[3][3] != 0.0f);
-}
-
-MT_Matrix4x4 RAS_OpenGLRasterizer::GetFrustumMatrix(
- float left,
- float right,
- float bottom,
- float top,
- float frustnear,
- float frustfar,
- float focallength,
- bool
-) {
- MT_Matrix4x4 result;
- float mat[16];
-
- // correction for stereo
- if (Stereo())
- {
- float near_div_focallength;
- float offset;
-
- // if Rasterizer.setFocalLength is not called we use the camera focallength
- if (!m_setfocallength)
- // if focallength is null we use a value known to be reasonable
- m_focallength = (focallength == 0.f) ? m_eyeseparation * 30.0f
- : focallength;
-
- near_div_focallength = frustnear / m_focallength;
- offset = 0.5f * m_eyeseparation * near_div_focallength;
- switch (m_curreye) {
- case RAS_STEREO_LEFTEYE:
- left += offset;
- right += offset;
- break;
- case RAS_STEREO_RIGHTEYE:
- left -= offset;
- right -= offset;
- break;
- }
- // leave bottom and top untouched
- if (m_stereomode == RAS_STEREO_3DTVTOPBOTTOM) {
- // restore the vertical frustum because the 3DTV will
- // expand the top and bottom part to the full size of the screen
- bottom *= 2.0f;
- top *= 2.0f;
- }
- }
-
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glFrustum(left, right, bottom, top, frustnear, frustfar);
-
- glGetFloatv(GL_PROJECTION_MATRIX, mat);
- result.setValue(mat);
-
- return result;
-}
-
-MT_Matrix4x4 RAS_OpenGLRasterizer::GetOrthoMatrix(
- float left,
- float right,
- float bottom,
- float top,
- float frustnear,
- float frustfar
-) {
- MT_Matrix4x4 result;
- float mat[16];
-
- // stereo is meaningless for orthographic, disable it
- glMatrixMode(GL_PROJECTION);
- glLoadIdentity();
- glOrtho(left, right, bottom, top, frustnear, frustfar);
-
- glGetFloatv(GL_PROJECTION_MATRIX, mat);
- result.setValue(mat);
-
- return result;
-}
-
-
-// next arguments probably contain redundant info, for later...
-void RAS_OpenGLRasterizer::SetViewMatrix(const MT_Matrix4x4 &mat,
- const MT_Matrix3x3 & camOrientMat3x3,
- const MT_Point3 & pos,
- const MT_Vector3 &scale,
- bool perspective)
-{
- m_viewmatrix = mat;
-
- // correction for stereo
- if (Stereo() && perspective)
- {
- MT_Vector3 unitViewDir(0.0f, -1.0f, 0.0f); // minus y direction, Blender convention
- MT_Vector3 unitViewupVec(0.0f, 0.0f, 1.0f);
- MT_Vector3 viewDir, viewupVec;
- MT_Vector3 eyeline;
-
- // actual viewDir
- viewDir = camOrientMat3x3 * unitViewDir; // this is the moto convention, vector on right hand side
- // actual viewup vec
- viewupVec = camOrientMat3x3 * unitViewupVec;
-
- // vector between eyes
- eyeline = viewDir.cross(viewupVec);
-
- switch (m_curreye) {
- case RAS_STEREO_LEFTEYE:
- {
- // translate to left by half the eye distance
- MT_Transform transform;
- transform.setIdentity();
- transform.translate(-(eyeline * m_eyeseparation / 2.0f));
- m_viewmatrix *= transform;
- }
- break;
- case RAS_STEREO_RIGHTEYE:
- {
- // translate to right by half the eye distance
- MT_Transform transform;
- transform.setIdentity();
- transform.translate(eyeline * m_eyeseparation / 2.0f);
- m_viewmatrix *= transform;
- }
- break;
- }
- }
-
- bool negX = (scale[0] < 0.0f);
- bool negY = (scale[1] < 0.0f);
- bool negZ = (scale[2] < 0.0f);
- if (negX || negY || negZ) {
- m_viewmatrix.tscale((negX)?-1.0f:1.0f, (negY)?-1.0f:1.0f, (negZ)?-1.0f:1.0f, 1.0);
- }
- m_viewinvmatrix = m_viewmatrix;
- m_viewinvmatrix.invert();
-
- // note: getValue gives back column major as needed by OpenGL
- MT_Scalar glviewmat[16];
- m_viewmatrix.getValue(glviewmat);
-
- glMatrixMode(GL_MODELVIEW);
- glLoadMatrixf(glviewmat);
- m_campos = pos;
- m_camnegscale = negX ^ negY ^ negZ;
-}
-
-
-const MT_Point3& RAS_OpenGLRasterizer::GetCameraPosition()
-{
- return m_campos;
-}
-
-bool RAS_OpenGLRasterizer::GetCameraOrtho()
-{
- return m_camortho;
-}
-
-void RAS_OpenGLRasterizer::SetCullFace(bool enable)
-{
- if (enable)
- glEnable(GL_CULL_FACE);
- else
- glDisable(GL_CULL_FACE);
-}
-
-void RAS_OpenGLRasterizer::SetLines(bool enable)
-{
- if (enable)
- glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
- else
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
-}
-
-void RAS_OpenGLRasterizer::SetSpecularity(float specX,
- float specY,
- float specZ,
- float specval)
-{
- GLfloat mat_specular[] = {specX, specY, specZ, specval};
- glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, mat_specular);
-}
-
-
-
-void RAS_OpenGLRasterizer::SetShinyness(float shiny)
-{
- GLfloat mat_shininess[] = { shiny };
- glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, mat_shininess);
-}
-
-
-
-void RAS_OpenGLRasterizer::SetDiffuse(float difX,float difY,float difZ,float diffuse)
-{
- GLfloat mat_diffuse [] = {difX, difY,difZ, diffuse};
- glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, mat_diffuse);
-}
-
-void RAS_OpenGLRasterizer::SetEmissive(float eX, float eY, float eZ, float e)
-{
- GLfloat mat_emit [] = {eX,eY,eZ,e};
- glMaterialfv(GL_FRONT_AND_BACK, GL_EMISSION, mat_emit);
-}
-
-
-double RAS_OpenGLRasterizer::GetTime()
-{
- return m_time;
-}
-
-void RAS_OpenGLRasterizer::SetPolygonOffset(float mult, float add)
-{
- glPolygonOffset(mult, add);
- GLint mode = GL_POLYGON_OFFSET_FILL;
- if (m_drawingmode < KX_SHADED)
- mode = GL_POLYGON_OFFSET_LINE;
- if (mult != 0.0f || add != 0.0f)
- glEnable(mode);
- else
- glDisable(mode);
-}
-
-void RAS_OpenGLRasterizer::EnableMotionBlur(float motionblurvalue)
-{
- /* don't just set m_motionblur to 1, but check if it is 0 so
- * we don't reset a motion blur that is already enabled */
- if (m_motionblur == 0)
- m_motionblur = 1;
- m_motionblurvalue = motionblurvalue;
-}
-
-void RAS_OpenGLRasterizer::DisableMotionBlur()
-{
- m_motionblur = 0;
- m_motionblurvalue = -1.0f;
-}
-
-void RAS_OpenGLRasterizer::SetAlphaBlend(int alphablend)
-{
- /* Variance shadow maps don't handle alpha well, best to not allow it for now */
- if (m_drawingmode == KX_SHADOW && m_usingoverrideshader)
- GPU_set_material_alpha_blend(GPU_BLEND_SOLID);
- else
- GPU_set_material_alpha_blend(alphablend);
-/*
- if (alphablend == m_last_alphablend)
- return;
-
- if (alphablend == GPU_BLEND_SOLID) {
- glDisable(GL_BLEND);
- glDisable(GL_ALPHA_TEST);
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- }
- else if (alphablend == GPU_BLEND_ADD) {
- glBlendFunc(GL_ONE, GL_ONE);
- glEnable(GL_BLEND);
- glDisable(GL_ALPHA_TEST);
- }
- else if (alphablend == GPU_BLEND_ALPHA) {
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
- glEnable(GL_BLEND);
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, 0.0f);
- }
- else if (alphablend == GPU_BLEND_CLIP) {
- glDisable(GL_BLEND);
- glEnable(GL_ALPHA_TEST);
- glAlphaFunc(GL_GREATER, 0.5f);
- }
-
- m_last_alphablend = alphablend;
-*/
-}
-
-void RAS_OpenGLRasterizer::SetFrontFace(bool ccw)
-{
- if (m_camnegscale)
- ccw = !ccw;
-
- if (m_last_frontface == ccw)
- return;
-
- if (ccw)
- glFrontFace(GL_CCW);
- else
- glFrontFace(GL_CW);
-
- m_last_frontface = ccw;
-}
-
-void RAS_OpenGLRasterizer::SetAnisotropicFiltering(short level)
-{
- GPU_set_anisotropic((float)level);
-}
-
-short RAS_OpenGLRasterizer::GetAnisotropicFiltering()
-{
- return (short)GPU_get_anisotropic();
-}
-
-void RAS_OpenGLRasterizer::SetMipmapping(MipmapOption val)
-{
- if (val == RAS_IRasterizer::RAS_MIPMAP_LINEAR)
- {
- GPU_set_linear_mipmap(1);
- GPU_set_mipmap(1);
- }
- else if (val == RAS_IRasterizer::RAS_MIPMAP_NEAREST)
- {
- GPU_set_linear_mipmap(0);
- GPU_set_mipmap(1);
- }
- else
- {
- GPU_set_linear_mipmap(0);
- GPU_set_mipmap(0);
- }
-}
-
-RAS_IRasterizer::MipmapOption RAS_OpenGLRasterizer::GetMipmapping()
-{
- if (GPU_get_mipmap()) {
- if (GPU_get_linear_mipmap()) {
- return RAS_IRasterizer::RAS_MIPMAP_LINEAR;
- }
- else {
- return RAS_IRasterizer::RAS_MIPMAP_NEAREST;
- }
- }
- else {
- return RAS_IRasterizer::RAS_MIPMAP_NONE;
- }
-}
-
-void RAS_OpenGLRasterizer::SetUsingOverrideShader(bool val)
-{
- m_usingoverrideshader = val;
-}
-
-bool RAS_OpenGLRasterizer::GetUsingOverrideShader()
-{
- return m_usingoverrideshader;
-}
-
-/**
- * Render Tools
- */
-
-/* ProcessLighting performs lighting on objects. the layer is a bitfield that
- * contains layer information. There are 20 'official' layers in blender. A
- * light is applied on an object only when they are in the same layer. OpenGL
- * has a maximum of 8 lights (simultaneous), so 20 * 8 lights are possible in
- * a scene. */
-
-void RAS_OpenGLRasterizer::ProcessLighting(bool uselights, const MT_Transform& viewmat)
-{
- bool enable = false;
- int layer= -1;
-
- /* find the layer */
- if (uselights) {
- if (m_clientobject)
- layer = static_cast<KX_GameObject*>(m_clientobject)->GetLayer();
- }
-
- /* avoid state switching */
- if (m_lastlightlayer == layer && m_lastauxinfo == m_auxilaryClientInfo)
- return;
-
- m_lastlightlayer = layer;
- m_lastauxinfo = m_auxilaryClientInfo;
-
- /* enable/disable lights as needed */
- if (layer >= 0) {
- //enable = ApplyLights(layer, viewmat);
- // taken from blender source, incompatibility between Blender Object / GameObject
- KX_Scene* kxscene = (KX_Scene*)m_auxilaryClientInfo;
- float glviewmat[16];
- unsigned int count;
- std::vector<RAS_OpenGLLight*>::iterator lit = m_lights.begin();
-
- for (count=0; count<m_numgllights; count++)
- glDisable((GLenum)(GL_LIGHT0+count));
-
- viewmat.getValue(glviewmat);
-
- glPushMatrix();
- glLoadMatrixf(glviewmat);
- for (lit = m_lights.begin(), count = 0; !(lit==m_lights.end()) && count < m_numgllights; ++lit)
- {
- RAS_OpenGLLight* light = (*lit);
-
- if (light->ApplyFixedFunctionLighting(kxscene, layer, count))
- count++;
- }
- glPopMatrix();
-
- enable = count > 0;
- }
-
- if (enable)
- EnableOpenGLLights();
- else
- DisableOpenGLLights();
-}
-
-void RAS_OpenGLRasterizer::EnableOpenGLLights()
-{
- if (m_lastlighting == true)
- return;
-
- glEnable(GL_LIGHTING);
- glEnable(GL_COLOR_MATERIAL);
-
- glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
- glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
- glLightModeli(GL_LIGHT_MODEL_LOCAL_VIEWER, (GetCameraOrtho())? GL_FALSE: GL_TRUE);
- if (GLEW_EXT_separate_specular_color || GLEW_VERSION_1_2)
- glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
-
- m_lastlighting = true;
-}
-
-void RAS_OpenGLRasterizer::DisableOpenGLLights()
-{
- if (m_lastlighting == false)
- return;
-
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
-
- m_lastlighting = false;
-}
-
-RAS_ILightObject *RAS_OpenGLRasterizer::CreateLight()
-{
- return new RAS_OpenGLLight(this);
-}
-
-void RAS_OpenGLRasterizer::AddLight(RAS_ILightObject* lightobject)
-{
- RAS_OpenGLLight* gllight = dynamic_cast<RAS_OpenGLLight*>(lightobject);
- assert(gllight);
- m_lights.push_back(gllight);
-}
-
-void RAS_OpenGLRasterizer::RemoveLight(RAS_ILightObject* lightobject)
-{
- RAS_OpenGLLight* gllight = dynamic_cast<RAS_OpenGLLight*>(lightobject);
- assert(gllight);
-
- std::vector<RAS_OpenGLLight*>::iterator lit =
- std::find(m_lights.begin(),m_lights.end(),gllight);
-
- if (!(lit==m_lights.end()))
- m_lights.erase(lit);
-}
-
-bool RAS_OpenGLRasterizer::RayHit(struct KX_ClientObjectInfo *client, KX_RayCast *result, float *oglmatrix)
-{
- if (result->m_hitMesh) {
-
- RAS_Polygon* poly = result->m_hitMesh->GetPolygon(result->m_hitPolygon);
- if (!poly->IsVisible())
- return false;
-
- MT_Vector3 resultnormal(result->m_hitNormal);
- MT_Vector3 left(oglmatrix[0],oglmatrix[1],oglmatrix[2]);
- MT_Vector3 dir = -(left.cross(resultnormal)).safe_normalized();
- left = (dir.cross(resultnormal)).safe_normalized();
- // for the up vector, we take the 'resultnormal' returned by the physics
-
- float maat[16] = {left[0], left[1], left[2], 0,
- dir[0], dir[1], dir[2], 0,
- resultnormal[0], resultnormal[1], resultnormal[2], 0,
- 0, 0, 0, 1};
-
- glTranslatef(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
- //glMultMatrixd(oglmatrix);
- glMultMatrixf(maat);
- return true;
- }
- else {
- return false;
- }
-}
-
-void RAS_OpenGLRasterizer::applyTransform(float* oglmatrix,int objectdrawmode )
-{
- /* FIXME:
- blender: intern/moto/include/MT_Vector3.inl:42: MT_Vector3 operator/(const
- MT_Vector3&, double): Assertion `!MT_fuzzyZero(s)' failed.
-
- Program received signal SIGABRT, Aborted.
- [Switching to Thread 16384 (LWP 1519)]
- 0x40477571 in kill () from /lib/libc.so.6
- (gdb) bt
- #7 0x08334368 in MT_Vector3::normalized() const ()
- #8 0x0833e6ec in RAS_OpenGLRasterizer::applyTransform(RAS_IRasterizer*, double*, int) ()
- */
-
- if (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED ||
- objectdrawmode & RAS_IPolyMaterial::BILLBOARD_AXISALIGNED)
- {
- // rotate the billboard/halo
- //page 360/361 3D Game Engine Design, David Eberly for a discussion
- // on screen aligned and axis aligned billboards
- // assumed is that the preprocessor transformed all billboard polygons
- // so that their normal points into the positive x direction (1.0f, 0.0f, 0.0f)
- // when new parenting for objects is done, this rotation
- // will be moved into the object
-
- MT_Point3 objpos (oglmatrix[12],oglmatrix[13],oglmatrix[14]);
- MT_Point3 campos = GetCameraPosition();
- MT_Vector3 dir = (campos - objpos).safe_normalized();
- MT_Vector3 up(0,0,1.0f);
-
- KX_GameObject* gameobj = (KX_GameObject*)m_clientobject;
- // get scaling of halo object
- MT_Vector3 size = gameobj->GetSGNode()->GetWorldScaling();
-
- bool screenaligned = (objectdrawmode & RAS_IPolyMaterial::BILLBOARD_SCREENALIGNED)!=0;//false; //either screen or axisaligned
- if (screenaligned)
- {
- up = (up - up.dot(dir) * dir).safe_normalized();
- } else
- {
- dir = (dir - up.dot(dir)*up).safe_normalized();
- }
-
- MT_Vector3 left = dir.normalized();
- dir = (up.cross(left)).normalized();
-
- // we have calculated the row vectors, now we keep
- // local scaling into account:
-
- left *= size[0];
- dir *= size[1];
- up *= size[2];
-
- float maat[16] = {left[0], left[1], left[2], 0,
- dir[0], dir[1], dir[2], 0,
- up[0], up[1], up[2], 0,
- 0, 0, 0, 1};
-
- glTranslatef(objpos[0],objpos[1],objpos[2]);
- glMultMatrixf(maat);
-
- }
- else {
- if (objectdrawmode & RAS_IPolyMaterial::SHADOW)
- {
- // shadow must be cast to the ground, physics system needed here!
- MT_Point3 frompoint(oglmatrix[12],oglmatrix[13],oglmatrix[14]);
- KX_GameObject *gameobj = (KX_GameObject*)m_clientobject;
- MT_Vector3 direction = MT_Vector3(0,0,-1);
-
- direction.normalize();
- direction *= 100000;
-
- MT_Point3 topoint = frompoint + direction;
-
- KX_Scene* kxscene = (KX_Scene*) m_auxilaryClientInfo;
- PHY_IPhysicsEnvironment* physics_environment = kxscene->GetPhysicsEnvironment();
- PHY_IPhysicsController* physics_controller = gameobj->GetPhysicsController();
-
- KX_GameObject *parent = gameobj->GetParent();
- if (!physics_controller && parent)
- physics_controller = parent->GetPhysicsController();
-
- KX_RayCast::Callback<RAS_OpenGLRasterizer, float> callback(this, physics_controller, oglmatrix);
- if (!KX_RayCast::RayTest(physics_environment, frompoint, topoint, callback))
- {
- // couldn't find something to cast the shadow on...
- glMultMatrixf(oglmatrix);
- }
- else
- { // we found the "ground", but the cast matrix doesn't take
- // scaling in consideration, so we must apply the object scale
- MT_Vector3 size = gameobj->GetSGNode()->GetLocalScale();
- glScalef(size[0], size[1], size[2]);
- }
- } else
- {
-
- // 'normal' object
- glMultMatrixf(oglmatrix);
- }
- }
-}
-
-static void DisableForText()
-{
- glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); /* needed for texture fonts otherwise they render as wireframe */
-
- glDisable(GL_BLEND);
- glDisable(GL_ALPHA_TEST);
-
- glDisable(GL_LIGHTING);
- glDisable(GL_COLOR_MATERIAL);
-
- if (GLEW_ARB_multitexture) {
- for (int i=0; i<RAS_MAX_TEXCO; i++) {
- glActiveTextureARB(GL_TEXTURE0_ARB+i);
-
- if (GLEW_ARB_texture_cube_map) {
- glDisable(GL_TEXTURE_CUBE_MAP_ARB);
- glDisable(GL_TEXTURE_GEN_S);
- glDisable(GL_TEXTURE_GEN_T);
- glDisable(GL_TEXTURE_GEN_Q);
- glDisable(GL_TEXTURE_GEN_R);
- }
- glDisable(GL_TEXTURE_2D);
- }
-
- glActiveTextureARB(GL_TEXTURE0_ARB);
- }
- else {
- if (GLEW_ARB_texture_cube_map)
- glDisable(GL_TEXTURE_CUBE_MAP_ARB);
-
- glDisable(GL_TEXTURE_2D);
- }
-}
-
-void RAS_OpenGLRasterizer::RenderBox2D(int xco,
- int yco,
- int width,
- int height,
- float percentage)
-{
- /* This is a rather important line :( The gl-mode hasn't been left
- * behind quite as neatly as we'd have wanted to. I don't know
- * what cause it, though :/ .*/
- glDisable(GL_DEPTH_TEST);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- glOrtho(0, width, 0, height, -100, 100);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- yco = height - yco;
- int barsize = 50;
-
- /* draw in black first */
- glColor3ub(0, 0, 0);
- glBegin(GL_QUADS);
- glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1 + 10);
- glVertex2f(xco + 1, yco - 1 + 10);
- glVertex2f(xco + 1, yco - 1);
- glVertex2f(xco + 1 + 1 + barsize * percentage, yco - 1);
- glEnd();
-
- glColor3ub(255, 255, 255);
- glBegin(GL_QUADS);
- glVertex2f(xco + 1 + barsize * percentage, yco + 10);
- glVertex2f(xco, yco + 10);
- glVertex2f(xco, yco);
- glVertex2f(xco + 1 + barsize * percentage, yco);
- glEnd();
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glEnable(GL_DEPTH_TEST);
-}
-
-void RAS_OpenGLRasterizer::RenderText3D(
- int fontid, const char *text, int size, int dpi,
- const float color[4], const float mat[16], float aspect)
-{
- /* gl prepping */
- DisableForText();
-
- /* the actual drawing */
- glColor4fv(color);
-
- /* multiply the text matrix by the object matrix */
- BLF_enable(fontid, BLF_MATRIX|BLF_ASPECT);
- BLF_matrix(fontid, mat);
-
- /* aspect is the inverse scale that allows you to increase
- * your resolution without sizing the final text size
- * the bigger the size, the smaller the aspect */
- BLF_aspect(fontid, aspect, aspect, aspect);
-
- BLF_size(fontid, size, dpi);
- BLF_position(fontid, 0, 0, 0);
- BLF_draw(fontid, text, 65535);
-
- BLF_disable(fontid, BLF_MATRIX|BLF_ASPECT);
-}
-
-void RAS_OpenGLRasterizer::RenderText2D(
- RAS_TEXT_RENDER_MODE mode,
- const char* text,
- int xco, int yco,
- int width, int height)
-{
- /* This is a rather important line :( The gl-mode hasn't been left
- * behind quite as neatly as we'd have wanted to. I don't know
- * what cause it, though :/ .*/
- DisableForText();
- glDisable(GL_DEPTH_TEST);
-
- glMatrixMode(GL_PROJECTION);
- glPushMatrix();
- glLoadIdentity();
-
- glOrtho(0, width, 0, height, -100, 100);
-
- glMatrixMode(GL_MODELVIEW);
- glPushMatrix();
- glLoadIdentity();
-
- if (mode == RAS_TEXT_PADDED) {
- /* draw in black first */
- glColor3ub(0, 0, 0);
- BLF_size(blf_mono_font, 11, 72);
- BLF_position(blf_mono_font, (float)xco+1, (float)(height-yco-1), 0.0f);
- BLF_draw(blf_mono_font, text, 65535); /* XXX, use real len */
- }
-
- /* the actual drawing */
- glColor3ub(255, 255, 255);
- BLF_size(blf_mono_font, 11, 72);
- BLF_position(blf_mono_font, (float)xco, (float)(height-yco), 0.0f);
- BLF_draw(blf_mono_font, text, 65535); /* XXX, use real len */
-
- glMatrixMode(GL_PROJECTION);
- glPopMatrix();
- glMatrixMode(GL_MODELVIEW);
- glPopMatrix();
- glEnable(GL_DEPTH_TEST);
-}
-
-void RAS_OpenGLRasterizer::PushMatrix()
-{
- glPushMatrix();
-}
-
-void RAS_OpenGLRasterizer::PopMatrix()
-{
- glPopMatrix();
-}
-
-void RAS_OpenGLRasterizer::MotionBlur()
-{
- int state = GetMotionBlurState();
- float motionblurvalue;
- if (state)
- {
- motionblurvalue = GetMotionBlurValue();
- if (state==1)
- {
- // bugfix:load color buffer into accum buffer for the first time(state=1)
- glAccum(GL_LOAD, 1.0f);
- SetMotionBlurState(2);
- }
- else if (motionblurvalue >= 0.0f && motionblurvalue <= 1.0f) {
- glAccum(GL_MULT, motionblurvalue);
- glAccum(GL_ACCUM, 1-motionblurvalue);
- glAccum(GL_RETURN, 1.0f);
- glFlush();
- }
- }
-}
-
-void RAS_OpenGLRasterizer::SetClientObject(void* obj)
-{
- if (m_clientobject != obj)
- {
- bool ccw = (obj == NULL || !((KX_GameObject*)obj)->IsNegativeScaling());
- SetFrontFace(ccw);
-
- m_clientobject = obj;
- }
-}
-
-void RAS_OpenGLRasterizer::SetAuxilaryClientInfo(void* inf)
-{
- m_auxilaryClientInfo = inf;
-}
-
-void RAS_OpenGLRasterizer::PrintHardwareInfo()
-{
- #define pprint(x) std::cout << x << std::endl;
-
- pprint("GL_VENDOR: " << glGetString(GL_VENDOR));
- pprint("GL_RENDERER: " << glGetString(GL_RENDERER));
- pprint("GL_VERSION: " << glGetString(GL_VERSION));
- bool support=0;
- pprint("Supported Extensions...");
- pprint(" GL_ARB_shader_objects supported? "<< (GLEW_ARB_shader_objects?"yes.":"no."));
-
- support= GLEW_ARB_vertex_shader;
- pprint(" GL_ARB_vertex_shader supported? "<< (support?"yes.":"no."));
- if (support) {
- pprint(" ----------Details----------");
- int max=0;
- glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS_ARB, (GLint*)&max);
- pprint(" Max uniform components." << max);
-
- glGetIntegerv(GL_MAX_VARYING_FLOATS_ARB, (GLint*)&max);
- pprint(" Max varying floats." << max);
-
- glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max);
- pprint(" Max vertex texture units." << max);
-
- glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS_ARB, (GLint*)&max);
- pprint(" Max combined texture units." << max);
- pprint("");
- }
-
- support=GLEW_ARB_fragment_shader;
- pprint(" GL_ARB_fragment_shader supported? "<< (support?"yes.":"no."));
- if (support) {
- pprint(" ----------Details----------");
- int max=0;
- glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS_ARB, (GLint*)&max);
- pprint(" Max uniform components." << max);
- pprint("");
- }
-
- support = GLEW_ARB_texture_cube_map;
- pprint(" GL_ARB_texture_cube_map supported? "<< (support?"yes.":"no."));
- if (support) {
- pprint(" ----------Details----------");
- int size=0;
- glGetIntegerv(GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB, (GLint*)&size);
- pprint(" Max cubemap size." << size);
- pprint("");
- }
-
- support = GLEW_ARB_multitexture;
- pprint(" GL_ARB_multitexture supported? "<< (support?"yes.":"no."));
- if (support) {
- pprint(" ----------Details----------");
- int units=0;
- glGetIntegerv(GL_MAX_TEXTURE_UNITS_ARB, (GLint*)&units);
- pprint(" Max texture units available. " << units);
- pprint("");
- }
-
- pprint(" GL_ARB_texture_env_combine supported? "<< (GLEW_ARB_texture_env_combine?"yes.":"no."));
-
- pprint(" GL_ARB_texture_non_power_of_two supported " << (GPU_full_non_power_of_two_support()?"yes.":"no."));
-}
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
deleted file mode 100644
index 9561e207dba..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLRasterizer.h
+++ /dev/null
@@ -1,343 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_OpenGLRasterizer.h
- * \ingroup bgerastogl
- */
-
-#ifndef __RAS_OPENGLRASTERIZER_H__
-#define __RAS_OPENGLRASTERIZER_H__
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "MT_CmMatrix4x4.h"
-#include <vector>
-#include <map>
-using namespace std;
-
-#include "RAS_IRasterizer.h"
-#include "RAS_MaterialBucket.h"
-#include "RAS_IPolygonMaterial.h"
-
-#include "BLI_utildefines.h"
-
-class RAS_IStorage;
-class RAS_ICanvas;
-class RAS_OpenGLLight;
-
-#define RAS_MAX_TEXCO 8 /* match in BL_Material */
-#define RAS_MAX_ATTRIB 16 /* match in BL_BlenderShader */
-
-enum RAS_STORAGE_TYPE {
- RAS_AUTO_STORAGE,
- RAS_VA,
- RAS_VBO,
-};
-
-struct OglDebugShape
-{
- enum SHAPE_TYPE{
- LINE,
- CIRCLE,
- };
- SHAPE_TYPE m_type;
- MT_Vector3 m_pos;
- MT_Vector3 m_param;
- MT_Vector3 m_param2;
- MT_Vector3 m_color;
-};
-
-/**
- * 3D rendering device context.
- */
-class RAS_OpenGLRasterizer : public RAS_IRasterizer
-{
- RAS_ICanvas *m_2DCanvas;
-
- /* fogging vars */
- bool m_fogenabled;
-
- float m_redback;
- float m_greenback;
- float m_blueback;
- float m_alphaback;
-
- float m_ambr;
- float m_ambg;
- float m_ambb;
- double m_time;
- MT_Matrix4x4 m_viewmatrix;
- MT_Matrix4x4 m_viewinvmatrix;
- MT_Point3 m_campos;
- bool m_camortho;
- bool m_camnegscale;
-
- StereoMode m_stereomode;
- StereoEye m_curreye;
- float m_eyeseparation;
- float m_focallength;
- bool m_setfocallength;
- int m_noOfScanlines;
-
- short m_prevafvalue;
-
- /* motion blur */
- int m_motionblur;
- float m_motionblurvalue;
-
- bool m_usingoverrideshader;
-
- /* Render tools */
- void *m_clientobject;
- void *m_auxilaryClientInfo;
- std::vector<RAS_OpenGLLight *> m_lights;
- int m_lastlightlayer;
- bool m_lastlighting;
- void *m_lastauxinfo;
- unsigned int m_numgllights;
-
-protected:
- int m_drawingmode;
- TexCoGen m_texco[RAS_MAX_TEXCO];
- TexCoGen m_attrib[RAS_MAX_ATTRIB];
- int m_attrib_layer[RAS_MAX_ATTRIB];
- int m_texco_num;
- int m_attrib_num;
- /* int m_last_alphablend; */
- bool m_last_frontface;
-
- /* Stores the caching information for the last material activated. */
- RAS_IPolyMaterial::TCachingInfo m_materialCachingInfo;
-
- /* Making use of a Strategy design pattern for storage behavior.
- * Examples of concrete strategies: Vertex Arrays, VBOs, Immediate Mode*/
- int m_storage_type;
- RAS_IStorage *m_storage;
-
-public:
- double GetTime();
- RAS_OpenGLRasterizer(RAS_ICanvas *canv, RAS_STORAGE_TYPE storage);
- virtual ~RAS_OpenGLRasterizer();
-
- /*enum DrawType
- {
- KX_BOUNDINGBOX = 1,
- KX_WIREFRAME,
- KX_SOLID,
- KX_SHADED,
- KX_TEXTURED
- };
-
- enum DepthMask
- {
- KX_DEPTHMASK_ENABLED =1,
- KX_DEPTHMASK_DISABLED,
- };*/
- virtual void SetDepthMask(DepthMask depthmask);
-
- virtual bool SetMaterial(const RAS_IPolyMaterial &mat);
- virtual bool Init();
- virtual void Exit();
- virtual bool BeginFrame(double time);
- virtual void ClearColorBuffer();
- virtual void ClearDepthBuffer();
- virtual void ClearCachingInfo(void);
- virtual void EndFrame();
- virtual void SetRenderArea();
-
- virtual void SetStereoMode(const StereoMode stereomode);
- virtual RAS_IRasterizer::StereoMode GetStereoMode();
- virtual bool Stereo();
- virtual bool InterlacedStereo();
- virtual void SetEye(const StereoEye eye);
- virtual StereoEye GetEye();
- virtual void SetEyeSeparation(const float eyeseparation);
- virtual float GetEyeSeparation();
- virtual void SetFocalLength(const float focallength);
- virtual float GetFocalLength();
- virtual RAS_IOffScreen *CreateOffScreen(int width, int height, int samples, int target);
- virtual RAS_ISync *CreateSync(int type);
- virtual void SwapBuffers();
-
- virtual void IndexPrimitives(class RAS_MeshSlot &ms);
- virtual void IndexPrimitives_3DText(class RAS_MeshSlot &ms, class RAS_IPolyMaterial *polymat);
- virtual void DrawDerivedMesh(class RAS_MeshSlot &ms);
-
- virtual void SetProjectionMatrix(MT_CmMatrix4x4 &mat);
- virtual void SetProjectionMatrix(const MT_Matrix4x4 &mat);
- virtual void SetViewMatrix(
- const MT_Matrix4x4 &mat,
- const MT_Matrix3x3 &ori,
- const MT_Point3 &pos,
- const MT_Vector3 &scale,
- bool perspective);
-
- virtual const MT_Point3& GetCameraPosition();
- virtual bool GetCameraOrtho();
-
- virtual void SetFog(short type, float start, float dist, float intensity, float color[3]);
- virtual void EnableFog(bool enable);
- virtual void DisplayFog();
-
- virtual void SetBackColor(float color[3]);
-
- virtual void SetDrawingMode(int drawingmode);
- virtual int GetDrawingMode();
-
- virtual void SetCullFace(bool enable);
- virtual void SetLines(bool enable);
-
- virtual MT_Matrix4x4 GetFrustumMatrix(
- float left, float right, float bottom, float top,
- float frustnear, float frustfar,
- float focallength, bool perspective);
- virtual MT_Matrix4x4 GetOrthoMatrix(
- float left, float right, float bottom, float top,
- float frustnear, float frustfar);
-
- virtual void SetSpecularity(float specX, float specY, float specZ, float specval);
- virtual void SetShinyness(float shiny);
- virtual void SetDiffuse(float difX, float difY, float difZ, float diffuse);
- virtual void SetEmissive(float eX, float eY, float eZ, float e);
-
- virtual void SetAmbientColor(float color[3]);
- virtual void SetAmbient(float factor);
-
- virtual void SetPolygonOffset(float mult, float add);
-
- virtual void FlushDebugShapes(SCA_IScene *scene);
-
- virtual void DrawDebugLine(SCA_IScene *scene, const MT_Vector3 &from,const MT_Vector3 &to, const MT_Vector3 &color)
- {
- OglDebugShape line;
- line.m_type = OglDebugShape::LINE;
- line.m_pos= from;
- line.m_param = to;
- line.m_color = color;
- m_debugShapes[scene].push_back(line);
- }
-
- virtual void DrawDebugCircle(SCA_IScene *scene, const MT_Vector3 &center, const MT_Scalar radius,
- const MT_Vector3 &color, const MT_Vector3 &normal, int nsector)
- {
- OglDebugShape line;
- line.m_type = OglDebugShape::CIRCLE;
- line.m_pos= center;
- line.m_param = normal;
- line.m_color = color;
- line.m_param2.x() = radius;
- line.m_param2.y() = (float) nsector;
- m_debugShapes[scene].push_back(line);
- }
-
- // We store each debug shape by scene.
- std::map<SCA_IScene *, std::vector<OglDebugShape> > m_debugShapes;
-
- virtual void SetTexCoordNum(int num);
- virtual void SetAttribNum(int num);
- virtual void SetTexCoord(TexCoGen coords, int unit);
- virtual void SetAttrib(TexCoGen coords, int unit, int layer = 0);
-
- void TexCoord(const RAS_TexVert &tv);
-
- const MT_Matrix4x4 &GetViewMatrix() const;
- const MT_Matrix4x4 &GetViewInvMatrix() const;
-
- virtual void EnableMotionBlur(float motionblurvalue);
- virtual void DisableMotionBlur();
- virtual float GetMotionBlurValue() { return m_motionblurvalue; }
- virtual int GetMotionBlurState() { return m_motionblur; }
- virtual void SetMotionBlurState(int newstate)
- {
- if (newstate < 0)
- m_motionblur = 0;
- else if (newstate > 2)
- m_motionblur = 2;
- else
- m_motionblur = newstate;
- }
-
- virtual void SetAlphaBlend(int alphablend);
- virtual void SetFrontFace(bool ccw);
-
- virtual void SetAnisotropicFiltering(short level);
- virtual short GetAnisotropicFiltering();
-
- virtual void SetMipmapping(MipmapOption val);
- virtual MipmapOption GetMipmapping();
-
- virtual void SetUsingOverrideShader(bool val);
- virtual bool GetUsingOverrideShader();
-
- /**
- * Render Tools
- */
- void EnableOpenGLLights();
- void DisableOpenGLLights();
- void ProcessLighting(bool uselights, const MT_Transform &viewmat);
-
- void RenderBox2D(int xco, int yco, int width, int height, float percentage);
- void RenderText3D(int fontid, const char *text, int size, int dpi,
- const float color[4], const float mat[16], float aspect);
- void RenderText2D(RAS_TEXT_RENDER_MODE mode, const char *text,
- int xco, int yco, int width, int height);
-
- void applyTransform(float *oglmatrix, int objectdrawmode);
-
- void PushMatrix();
- void PopMatrix();
-
- /// \see KX_RayCast
- bool RayHit(struct KX_ClientObjectInfo *client, class KX_RayCast *result, float *oglmatrix);
- /// \see KX_RayCast
- bool NeedRayCast(struct KX_ClientObjectInfo *, void *UNUSED(data)) { return true; }
-
- RAS_ILightObject* CreateLight();
- void AddLight(RAS_ILightObject* lightobject);
-
- void RemoveLight(RAS_ILightObject* lightobject);
- int ApplyLights(int objectlayer, const MT_Transform& viewmat);
-
- void MotionBlur();
-
- void SetClientObject(void *obj);
-
- void SetAuxilaryClientInfo(void *inf);
-
- /**
- * Prints information about what the hardware supports.
- */
- virtual void PrintHardwareInfo();
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_OpenGLRasterizer")
-#endif
-};
-
-#endif /* __RAS_OPENGLRASTERIZER_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp
deleted file mode 100644
index 26b956cd74e..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.cpp
+++ /dev/null
@@ -1,82 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "GPU_glew.h"
-
-#include <stdio.h>
-
-#include "RAS_OpenGLSync.h"
-
-RAS_OpenGLSync::RAS_OpenGLSync()
- :m_sync(NULL)
-{
-}
-
-RAS_OpenGLSync::~RAS_OpenGLSync()
-{
- Destroy();
-}
-
-bool RAS_OpenGLSync::Create(RAS_SYNC_TYPE type)
-{
- if (m_sync) {
- printf("RAS_OpenGLSync::Create(): sync already exists, destroy first\n");
- return false;
- }
- if (type != RAS_SYNC_TYPE_FENCE) {
- printf("RAS_OpenGLSync::Create(): only RAS_SYNC_TYPE_FENCE are currently supported\n");
- return false;
- }
- if (!GLEW_ARB_sync) {
- printf("RAS_OpenGLSync::Create(): ARB_sync extension is needed to create sync object\n");
- return false;
- }
- m_sync = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
- if (!m_sync) {
- printf("RAS_OpenGLSync::Create(): glFenceSync() failed");
- return false;
- }
- return true;
-}
-
-void RAS_OpenGLSync::Destroy()
-{
- if (m_sync) {
- glDeleteSync(m_sync);
- m_sync = NULL;
- }
-}
-
-void RAS_OpenGLSync::Wait()
-{
- if (m_sync) {
- // this is needed to ensure that the sync is in the GPU
- glFlush();
- // block until the operation have completed
- glWaitSync(m_sync, 0, GL_TIMEOUT_IGNORED);
- }
-}
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h
deleted file mode 100644
index 4ba96903856..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_OpenGLSync.h
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __RAS_OPENGLSYNC__
-#define __RAS_OPENGLSYNC__
-
-
-#include "RAS_ISync.h"
-
-struct __GLsync;
-
-class RAS_OpenGLSync : public RAS_ISync
-{
-private:
- struct __GLsync *m_sync;
-
-public:
- RAS_OpenGLSync();
- ~RAS_OpenGLSync();
-
- virtual bool Create(RAS_SYNC_TYPE type);
- virtual void Destroy();
- virtual void Wait();
-};
-
-#endif /* __RAS_OPENGLSYNC__ */
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp
deleted file mode 100644
index f980116f5f8..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.cpp
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "RAS_StorageVA.h"
-
-#include "GPU_glew.h"
-
-RAS_StorageVA::RAS_StorageVA(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer) :
- m_drawingmode(RAS_IRasterizer::KX_TEXTURED),
- m_texco_num(texco_num),
- m_attrib_num(attrib_num),
- m_last_texco_num(0),
- m_last_attrib_num(0),
- m_texco(texco),
- m_attrib(attrib),
- m_attrib_layer(attrib_layer)
-{
-}
-
-RAS_StorageVA::~RAS_StorageVA()
-{
-}
-
-bool RAS_StorageVA::Init()
-{
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
-
- return true;
-}
-
-void RAS_StorageVA::Exit()
-{
-}
-
-void RAS_StorageVA::IndexPrimitives(class RAS_MeshSlot& ms)
-{
- static const GLsizei stride = sizeof(RAS_TexVert);
- bool wireframe = m_drawingmode <= RAS_IRasterizer::KX_WIREFRAME, use_color_array = true;
- RAS_MeshSlot::iterator it;
- GLenum drawmode;
-
- if (!wireframe)
- EnableTextures(true);
- glEnableClientState(GL_VERTEX_ARRAY);
- glEnableClientState(GL_NORMAL_ARRAY);
-
- // use glDrawElements to draw each vertexarray
- for (ms.begin(it); !ms.end(it); ms.next(it)) {
- if (it.totindex == 0)
- continue;
-
- // drawing mode
- if (it.array->m_type == RAS_DisplayArray::TRIANGLE)
- drawmode = GL_TRIANGLES;
- else if (it.array->m_type == RAS_DisplayArray::QUAD)
- drawmode = GL_QUADS;
- else
- drawmode = GL_LINES;
-
- // colors
- if (drawmode != GL_LINES && !wireframe) {
- if (ms.m_bObjectColor) {
- const MT_Vector4& rgba = ms.m_RGBAcolor;
-
- glDisableClientState(GL_COLOR_ARRAY);
- glColor4d(rgba[0], rgba[1], rgba[2], rgba[3]);
- use_color_array = false;
- }
- else {
- glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
- glEnableClientState(GL_COLOR_ARRAY);
- use_color_array = true;
- }
- }
- else
- glColor4f(0.0f, 0.0f, 0.0f, 1.0f);
-
- glVertexPointer(3, GL_FLOAT, stride, it.vertex->getXYZ());
- glNormalPointer(GL_FLOAT, stride, it.vertex->getNormal());
-
- if (!wireframe) {
- TexCoordPtr(it.vertex);
- if (use_color_array)
- glColorPointer(4, GL_UNSIGNED_BYTE, stride, it.vertex->getRGBA());
- }
-
- // here the actual drawing takes places
- glDrawElements(drawmode, it.totindex, GL_UNSIGNED_SHORT, it.index);
- }
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- if (!wireframe) {
- glDisableClientState(GL_COLOR_ARRAY);
- EnableTextures(false);
- }
-}
-
-void RAS_StorageVA::TexCoordPtr(const RAS_TexVert *tv)
-{
- /* note: this function must closely match EnableTextures to enable/disable
- * the right arrays, otherwise coordinate and attribute pointers from other
- * materials can still be used and cause crashes */
- int unit;
-
- if (GLEW_ARB_multitexture)
- {
- for (unit = 0; unit < *m_texco_num; unit++)
- {
- glClientActiveTextureARB(GL_TEXTURE0_ARB+unit);
- switch (m_texco[unit]) {
- case RAS_IRasterizer::RAS_TEXCO_ORCO:
- case RAS_IRasterizer::RAS_TEXCO_GLOB:
- glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getXYZ());
- break;
- case RAS_IRasterizer::RAS_TEXCO_UV:
- glTexCoordPointer(2, GL_FLOAT, sizeof(RAS_TexVert),tv->getUV(unit));
- break;
- case RAS_IRasterizer::RAS_TEXCO_NORM:
- glTexCoordPointer(3, GL_FLOAT, sizeof(RAS_TexVert),tv->getNormal());
- break;
- case RAS_IRasterizer::RAS_TEXTANGENT:
- glTexCoordPointer(4, GL_FLOAT, sizeof(RAS_TexVert),tv->getTangent());
- break;
- default:
- break;
- }
- }
-
- glClientActiveTextureARB(GL_TEXTURE0_ARB);
- }
-
- if (GLEW_ARB_vertex_program) {
- for (unit = 0; unit < *m_attrib_num; unit++) {
- switch (m_attrib[unit]) {
- case RAS_IRasterizer::RAS_TEXCO_ORCO:
- case RAS_IRasterizer::RAS_TEXCO_GLOB:
- glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getXYZ());
- break;
- case RAS_IRasterizer::RAS_TEXCO_UV:
- glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getUV(m_attrib_layer[unit]));
- break;
- case RAS_IRasterizer::RAS_TEXCO_NORM:
- glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getNormal());
- break;
- case RAS_IRasterizer::RAS_TEXTANGENT:
- glVertexAttribPointerARB(unit, 4, GL_FLOAT, GL_FALSE, sizeof(RAS_TexVert), tv->getTangent());
- break;
- case RAS_IRasterizer::RAS_TEXCO_VCOL:
- glVertexAttribPointerARB(unit, 4, GL_UNSIGNED_BYTE, GL_TRUE, sizeof(RAS_TexVert), tv->getRGBA());
- break;
- default:
- break;
- }
- }
- }
-}
-
-void RAS_StorageVA::EnableTextures(bool enable)
-{
- RAS_IRasterizer::TexCoGen *texco, *attrib;
- int unit, texco_num, attrib_num;
-
- /* we cache last texcoords and attribs to ensure we disable the ones that
- * were actually last set */
- if (enable) {
- texco = m_texco;
- texco_num = *m_texco_num;
- attrib = m_attrib;
- attrib_num = *m_attrib_num;
-
- memcpy(m_last_texco, m_texco, sizeof(RAS_IRasterizer::TexCoGen)*(*m_texco_num));
- m_last_texco_num = *m_texco_num;
- memcpy(m_last_attrib, m_attrib, sizeof(RAS_IRasterizer::TexCoGen)*(*m_attrib_num));
- m_last_attrib_num = *m_attrib_num;
- }
- else {
- texco = m_last_texco;
- texco_num = m_last_texco_num;
- attrib = m_last_attrib;
- attrib_num = m_last_attrib_num;
- }
-
- if (GLEW_ARB_multitexture) {
- for (unit = 0; unit < texco_num; unit++) {
- glClientActiveTextureARB(GL_TEXTURE0_ARB + unit);
-
- switch (texco[unit]) {
- case RAS_IRasterizer::RAS_TEXCO_ORCO:
- case RAS_IRasterizer::RAS_TEXCO_GLOB:
- case RAS_IRasterizer::RAS_TEXCO_UV:
- case RAS_IRasterizer::RAS_TEXCO_NORM:
- case RAS_IRasterizer::RAS_TEXTANGENT:
- if (enable) glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- else glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- break;
- default:
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- break;
- }
- }
-
- glClientActiveTextureARB(GL_TEXTURE0_ARB);
- }
- else {
- if (texco_num) {
- if (enable) glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- else glDisableClientState(GL_TEXTURE_COORD_ARRAY);
- }
- }
-
- if (GLEW_ARB_vertex_program) {
- for (unit = 0; unit < attrib_num; unit++) {
- switch (attrib[unit]) {
- case RAS_IRasterizer::RAS_TEXCO_ORCO:
- case RAS_IRasterizer::RAS_TEXCO_GLOB:
- case RAS_IRasterizer::RAS_TEXCO_UV:
- case RAS_IRasterizer::RAS_TEXCO_NORM:
- case RAS_IRasterizer::RAS_TEXTANGENT:
- case RAS_IRasterizer::RAS_TEXCO_VCOL:
- if (enable) glEnableVertexAttribArrayARB(unit);
- else glDisableVertexAttribArrayARB(unit);
- break;
- default:
- glDisableVertexAttribArrayARB(unit);
- break;
- }
- }
- }
-
- if (!enable) {
- m_last_texco_num = 0;
- m_last_attrib_num = 0;
- }
-}
-
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h
deleted file mode 100644
index a5a3170ed77..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVA.h
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __KX_VERTEXARRAYSTORAGE
-#define __KX_VERTEXARRAYSTORAGE
-
-#include "RAS_IStorage.h"
-#include "RAS_IRasterizer.h"
-
-#include "RAS_OpenGLRasterizer.h"
-
-class RAS_StorageVA : public RAS_IStorage
-{
-
-public:
- RAS_StorageVA(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer);
- virtual ~RAS_StorageVA();
-
- virtual bool Init();
- virtual void Exit();
-
- virtual void IndexPrimitives(RAS_MeshSlot& ms);
-
- virtual void SetDrawingMode(int drawingmode) {m_drawingmode = drawingmode;};
-
-protected:
- int m_drawingmode;
-
- int* m_texco_num;
- int* m_attrib_num;
-
- int m_last_texco_num;
- int m_last_attrib_num;
-
- RAS_IRasterizer::TexCoGen* m_texco;
- RAS_IRasterizer::TexCoGen* m_attrib;
- int* m_attrib_layer;
-
- RAS_IRasterizer::TexCoGen m_last_texco[RAS_MAX_TEXCO];
- RAS_IRasterizer::TexCoGen m_last_attrib[RAS_MAX_ATTRIB];
-
- virtual void EnableTextures(bool enable);
- virtual void TexCoordPtr(const RAS_TexVert *tv);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
-public:
- void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_StorageVA"); }
- void operator delete( void *mem ) { MEM_freeN(mem); }
-#endif
-};
-
-#endif //__KX_VERTEXARRAYSTORAGE
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp
deleted file mode 100644
index 4ba5882a46e..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#include "RAS_StorageVBO.h"
-#include "RAS_MeshObject.h"
-
-#include "GPU_glew.h"
-
-VBO::VBO(RAS_DisplayArray *data, unsigned int indices)
-{
- this->data = data;
- this->size = data->m_vertex.size();
- this->indices = indices;
- this->stride = sizeof(RAS_TexVert);
-
- // Determine drawmode
- if (data->m_type == data->QUAD)
- this->mode = GL_QUADS;
- else if (data->m_type == data->TRIANGLE)
- this->mode = GL_TRIANGLES;
- else
- this->mode = GL_LINE;
-
- // Generate Buffers
- glGenBuffersARB(1, &this->ibo);
- glGenBuffersARB(1, &this->vbo_id);
-
- // Fill the buffers with initial data
- UpdateIndices();
- UpdateData();
-
- // Establish offsets
- this->vertex_offset = (void*)(((RAS_TexVert*)0)->getXYZ());
- this->normal_offset = (void*)(((RAS_TexVert*)0)->getNormal());
- this->tangent_offset = (void*)(((RAS_TexVert*)0)->getTangent());
- this->color_offset = (void*)(((RAS_TexVert*)0)->getRGBA());
- this->uv_offset = (void*)(((RAS_TexVert*)0)->getUV(0));
-}
-
-VBO::~VBO()
-{
- glDeleteBuffersARB(1, &this->ibo);
- glDeleteBuffersARB(1, &this->vbo_id);
-}
-
-void VBO::UpdateData()
-{
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
- glBufferData(GL_ARRAY_BUFFER, this->stride*this->size, &this->data->m_vertex[0], GL_STATIC_DRAW);
-}
-
-void VBO::UpdateIndices()
-{
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this->ibo);
- glBufferData(GL_ELEMENT_ARRAY_BUFFER, data->m_index.size() * sizeof(GLushort),
- &data->m_index[0], GL_STATIC_DRAW);
-}
-
-void VBO::Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, int *attrib_layer)
-{
- int unit;
-
- // Bind buffers
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, this->ibo);
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, this->vbo_id);
-
- // Vertexes
- glEnableClientState(GL_VERTEX_ARRAY);
- glVertexPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
-
- // Normals
- glEnableClientState(GL_NORMAL_ARRAY);
- glNormalPointer(GL_FLOAT, this->stride, this->normal_offset);
-
- // Colors
- glEnableClientState(GL_COLOR_ARRAY);
- glColorPointer(4, GL_UNSIGNED_BYTE, this->stride, this->color_offset);
-
- for (unit = 0; unit < texco_num; ++unit)
- {
- glClientActiveTexture(GL_TEXTURE0_ARB + unit);
- switch (texco[unit]) {
- case RAS_IRasterizer::RAS_TEXCO_ORCO:
- case RAS_IRasterizer::RAS_TEXCO_GLOB:
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(3, GL_FLOAT, this->stride, this->vertex_offset);
- break;
- case RAS_IRasterizer::RAS_TEXCO_UV:
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(2, GL_FLOAT, this->stride, (void*)((intptr_t)this->uv_offset+(sizeof(GLfloat)*2*unit)));
- break;
- case RAS_IRasterizer::RAS_TEXCO_NORM:
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(3, GL_FLOAT, this->stride, this->normal_offset);
- break;
- case RAS_IRasterizer::RAS_TEXTANGENT:
- glEnableClientState(GL_TEXTURE_COORD_ARRAY);
- glTexCoordPointer(4, GL_FLOAT, this->stride, this->tangent_offset);
- break;
- default:
- break;
- }
- }
- glClientActiveTextureARB(GL_TEXTURE0_ARB);
-
- if (GLEW_ARB_vertex_program)
- {
- for (unit = 0; unit < attrib_num; ++unit)
- {
- switch (attrib[unit]) {
- case RAS_IRasterizer::RAS_TEXCO_ORCO:
- case RAS_IRasterizer::RAS_TEXCO_GLOB:
- glVertexAttribPointerARB(unit, 3, GL_FLOAT, GL_FALSE, this->stride, this->vertex_offset);
- glEnableVertexAttribArrayARB(unit);
- break;
- case RAS_IRasterizer::RAS_TEXCO_UV:
- glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, this->stride, (void*)((intptr_t)this->uv_offset+attrib_layer[unit]*sizeof(GLfloat)*2));
- glEnableVertexAttribArrayARB(unit);
- break;
- case RAS_IRasterizer::RAS_TEXCO_NORM:
- glVertexAttribPointerARB(unit, 2, GL_FLOAT, GL_FALSE, stride, this->normal_offset);
- glEnableVertexAttribArrayARB(unit);
- break;
- case RAS_IRasterizer::RAS_TEXTANGENT:
- glVertexAttribPointerARB(unit, 4, GL_FLOAT, GL_FALSE, this->stride, this->tangent_offset);
- glEnableVertexAttribArrayARB(unit);
- break;
- case RAS_IRasterizer::RAS_TEXCO_VCOL:
- glVertexAttribPointerARB(unit, 4, GL_UNSIGNED_BYTE, GL_TRUE, this->stride, this->color_offset);
- glEnableVertexAttribArrayARB(unit);
- default:
- break;
- }
- }
- }
-
- glDrawElements(this->mode, this->indices, GL_UNSIGNED_SHORT, 0);
-
- glDisableClientState(GL_VERTEX_ARRAY);
- glDisableClientState(GL_NORMAL_ARRAY);
- glDisableClientState(GL_COLOR_ARRAY);
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-
- if (GLEW_ARB_vertex_program)
- {
- for (int i = 0; i < attrib_num; ++i)
- glDisableVertexAttribArrayARB(i);
- }
-
- glBindBufferARB(GL_ARRAY_BUFFER_ARB, 0);
- glBindBufferARB(GL_ELEMENT_ARRAY_BUFFER_ARB, 0);
-}
-
-RAS_StorageVBO::RAS_StorageVBO(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer):
- m_drawingmode(RAS_IRasterizer::KX_TEXTURED),
- m_texco_num(texco_num),
- m_attrib_num(attrib_num),
- m_texco(texco),
- m_attrib(attrib),
- m_attrib_layer(attrib_layer)
-{
-}
-
-RAS_StorageVBO::~RAS_StorageVBO()
-{
-}
-
-bool RAS_StorageVBO::Init()
-{
- return true;
-}
-
-void RAS_StorageVBO::Exit()
-{
- VBOMap::iterator it = m_vbo_lookup.begin();
- while (it != m_vbo_lookup.end()) {
- delete it->second;
- ++it;
- }
- m_vbo_lookup.clear();
-}
-
-void RAS_StorageVBO::IndexPrimitives(RAS_MeshSlot& ms)
-{
- RAS_MeshSlot::iterator it;
- VBO *vbo;
-
- for (ms.begin(it); !ms.end(it); ms.next(it))
- {
- vbo = m_vbo_lookup[it.array];
-
- if (vbo == 0)
- m_vbo_lookup[it.array] = vbo = new VBO(it.array, it.totindex);
-
- // Update the vbo
- if (ms.m_mesh->MeshModified())
- {
- vbo->UpdateData();
- }
-
- vbo->Draw(*m_texco_num, m_texco, *m_attrib_num, m_attrib, m_attrib_layer);
- }
-}
diff --git a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h b/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h
deleted file mode 100644
index c82b6a3206d..00000000000
--- a/source/gameengine/Rasterizer/RAS_OpenGLRasterizer/RAS_StorageVBO.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-#ifndef __KX_VERTEXBUFFEROBJECTSTORAGE
-#define __KX_VERTEXBUFFEROBJECTSTORAGE
-
-#include <map>
-#include "GPU_glew.h"
-
-#include "RAS_IStorage.h"
-#include "RAS_IRasterizer.h"
-
-#include "RAS_OpenGLRasterizer.h"
-
-class VBO
-{
-public:
- VBO(RAS_DisplayArray *data, unsigned int indices);
- ~VBO();
-
- void Draw(int texco_num, RAS_IRasterizer::TexCoGen* texco, int attrib_num, RAS_IRasterizer::TexCoGen* attrib, int *attrib_layer);
-
- void UpdateData();
- void UpdateIndices();
-private:
- RAS_DisplayArray* data;
- GLuint size;
- GLuint stride;
- GLuint indices;
- GLenum mode;
- GLuint ibo;
- GLuint vbo_id;
-
- void* vertex_offset;
- void* normal_offset;
- void* color_offset;
- void* tangent_offset;
- void* uv_offset;
-};
-
-typedef std::map<RAS_DisplayArray*, VBO*> VBOMap;
-
-class RAS_StorageVBO : public RAS_IStorage
-{
-
-public:
- RAS_StorageVBO(int *texco_num, RAS_IRasterizer::TexCoGen *texco, int *attrib_num, RAS_IRasterizer::TexCoGen *attrib, int *attrib_layer);
- virtual ~RAS_StorageVBO();
-
- virtual bool Init();
- virtual void Exit();
-
- virtual void IndexPrimitives(RAS_MeshSlot& ms);
-
- virtual void SetDrawingMode(int drawingmode) {m_drawingmode = drawingmode;};
-
-protected:
- int m_drawingmode;
-
- int* m_texco_num;
- int* m_attrib_num;
-
- RAS_IRasterizer::TexCoGen* m_texco;
- RAS_IRasterizer::TexCoGen* m_attrib;
- int* m_attrib_layer;
-
- VBOMap m_vbo_lookup;
-
-#ifdef WITH_CXX_GUARDEDALLOC
-public:
- void *operator new(size_t num_bytes) { return MEM_mallocN(num_bytes, "GE:RAS_StorageVA"); }
- void operator delete( void *mem ) { MEM_freeN(mem); }
-#endif
-};
-
-#endif //__KX_VERTEXBUFFEROBJECTSTORAGE
diff --git a/source/gameengine/Rasterizer/RAS_Polygon.cpp b/source/gameengine/Rasterizer/RAS_Polygon.cpp
deleted file mode 100644
index 3274ded4406..00000000000
--- a/source/gameengine/Rasterizer/RAS_Polygon.cpp
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_Polygon.cpp
- * \ingroup bgerast
- */
-
-#ifdef _MSC_VER
-# pragma warning (disable:4786)
-#endif
-
-#include "RAS_Polygon.h"
-#include "RAS_MaterialBucket.h"
-
-RAS_Polygon::RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray *darray, int numvert)
-{
- m_bucket = bucket;
- m_darray = darray;
- m_offset[0] = m_offset[1] = m_offset[2] = m_offset[3] = 0;
- m_numvert = numvert;
-
-// m_edgecode = 255;
- m_polyflags = 0;
-}
-
-int RAS_Polygon::VertexCount()
-{
- return m_numvert;
-}
-
-void RAS_Polygon::SetVertexOffset(int i, unsigned short offset)
-{
- m_offset[i] = offset;
-}
-
-RAS_TexVert *RAS_Polygon::GetVertex(int i)
-{
- return &m_darray->m_vertex[m_offset[i]];
-}
-
-unsigned int RAS_Polygon::GetVertexOffsetAbsolute(unsigned short i)
-{
- return m_offset[i] + m_darray->m_offset;
-}
-
-/*
-int RAS_Polygon::GetEdgeCode()
-{
- return m_edgecode;
-}
-
-void RAS_Polygon::SetEdgeCode(int edgecode)
-{
- m_edgecode = edgecode;
-}*/
-
-
-bool RAS_Polygon::IsVisible()
-{
- return (m_polyflags & VISIBLE) != 0;
-}
-
-void RAS_Polygon::SetVisible(bool visible)
-{
- if (visible) m_polyflags |= VISIBLE;
- else m_polyflags &= ~VISIBLE;
-}
-
-bool RAS_Polygon::IsCollider()
-{
- return (m_polyflags & COLLIDER) != 0;
-}
-
-void RAS_Polygon::SetCollider(bool visible)
-{
- if (visible) m_polyflags |= COLLIDER;
- else m_polyflags &= ~COLLIDER;
-}
-
-bool RAS_Polygon::IsTwoside()
-{
- return (m_polyflags & TWOSIDE) != 0;
-}
-
-void RAS_Polygon::SetTwoside(bool twoside)
-{
- if (twoside) m_polyflags |= TWOSIDE;
- else m_polyflags &= ~TWOSIDE;
-}
-
-RAS_MaterialBucket* RAS_Polygon::GetMaterial()
-{
- return m_bucket;
-}
-
-RAS_DisplayArray* RAS_Polygon::GetDisplayArray()
-{
- return m_darray;
-}
diff --git a/source/gameengine/Rasterizer/RAS_Polygon.h b/source/gameengine/Rasterizer/RAS_Polygon.h
deleted file mode 100644
index 597e80ffdfb..00000000000
--- a/source/gameengine/Rasterizer/RAS_Polygon.h
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Polygon.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_POLYGON_H__
-#define __RAS_POLYGON_H__
-
-class RAS_DisplayArray;
-class RAS_MaterialBucket;
-class RAS_TexVert;
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/* polygon flags */
-
-class RAS_Polygon
-{
- /* location */
- RAS_MaterialBucket* m_bucket;
- RAS_DisplayArray* m_darray;
- unsigned short m_offset[4];
- unsigned short m_numvert;
-
- /* flags */
-#if 1
- unsigned short m_polyflags;
-#else
- unsigned char m_edgecode;
- unsigned char m_polyflags;
-#endif
-
-public:
- enum {
- VISIBLE = 1,
- COLLIDER = 2,
- TWOSIDE = 4
- };
-
- RAS_Polygon(RAS_MaterialBucket* bucket, RAS_DisplayArray* darray, int numvert);
- virtual ~RAS_Polygon() {};
-
- int VertexCount();
- RAS_TexVert* GetVertex(int i);
-
- void SetVertexOffset(int i, unsigned short offset);
- unsigned int GetVertexOffsetAbsolute(unsigned short i);
-
- // each bit is for a visible edge, starting with bit 1 for the first edge, bit 2 for second etc.
- // - Not used yet!
-/* int GetEdgeCode();
- void SetEdgeCode(int edgecode); */
-
- bool IsVisible();
- void SetVisible(bool visible);
-
- bool IsCollider();
- void SetCollider(bool collider);
-
- bool IsTwoside();
- void SetTwoside(bool twoside);
-
- RAS_MaterialBucket* GetMaterial();
- RAS_DisplayArray* GetDisplayArray();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_Polygon")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/Rasterizer/RAS_Rect.h b/source/gameengine/Rasterizer/RAS_Rect.h
deleted file mode 100644
index fc99c9159db..00000000000
--- a/source/gameengine/Rasterizer/RAS_Rect.h
+++ /dev/null
@@ -1,104 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_Rect.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_RECT_H__
-#define __RAS_RECT_H__
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/**
- * \section interface class.
- * RAS_Rect just encodes a simple rectangle.
- * \note Should be part of a generic library
- */
-class RAS_Rect
-{
-public: // todo: make a decent class, and make private
- int m_x1, m_y1;
- int m_x2, m_y2;
-
-public:
- RAS_Rect() : m_x1(0), m_y1(0), m_x2(0), m_y2(0) {}
- int GetWidth(
- ) const {
- return m_x2 - m_x1;
- }
- int GetHeight(
- ) const {
- return m_y2 - m_y1;
- }
- int GetLeft(
- ) const {
- return m_x1;
- }
- int GetRight(
- ) const {
- return m_x2;
- }
- int GetBottom(
- ) const {
- return m_y1;
- }
- int GetTop(
- ) const {
- return m_y2;
- }
-
- void SetLeft(
- int x1)
- {
- m_x1 = x1;
- }
- void SetBottom(
- int y1)
- {
- m_y1 = y1;
- }
- void SetRight(
- int x2)
- {
- m_x2 = x2;
- }
- void SetTop(
- int y2)
- {
- m_y2 = y2;
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_Rect")
-#endif
-};
-
-#endif /* __RAS_RECT_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_TexMatrix.h b/source/gameengine/Rasterizer/RAS_TexMatrix.h
deleted file mode 100644
index a2dd291d016..00000000000
--- a/source/gameengine/Rasterizer/RAS_TexMatrix.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_TexMatrix.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_TEXMATRIX_H__
-#define __RAS_TEXMATRIX_H__
-
-#include "MT_Matrix3x3.h"
-#include "MT_Point3.h"
-#include "MT_Point2.h"
-#include "RAS_TexVert.h"
-
-void RAS_CalcTexMatrix(RAS_TexVert p[3],MT_Point3& origin,MT_Vector3& udir,MT_Vector3& vdir);
-
-#endif /* __RAS_TEXMATRIX_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_TexVert.cpp b/source/gameengine/Rasterizer/RAS_TexVert.cpp
deleted file mode 100644
index 2e176360d61..00000000000
--- a/source/gameengine/Rasterizer/RAS_TexVert.cpp
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_TexVert.cpp
- * \ingroup bgerast
- */
-
-
-#include "RAS_TexVert.h"
-#include "MT_Matrix4x4.h"
-#include "BLI_math.h"
-
-RAS_TexVert::RAS_TexVert(const MT_Point3& xyz,
- const MT_Point2 uvs[MAX_UNIT],
- const MT_Vector4& tangent,
- const unsigned int rgba,
- const MT_Vector3& normal,
- const bool flat,
- const unsigned int origindex)
-{
- xyz.getValue(m_localxyz);
- SetRGBA(rgba);
- SetNormal(normal);
- tangent.getValue(m_tangent);
- m_flag = (flat) ? FLAT: 0;
- m_origindex = origindex;
- m_unit = 2;
- m_softBodyIndex = -1;
-
- for (int i = 0; i < MAX_UNIT; ++i)
- {
- uvs[i].getValue(m_uvs[i]);
- }
-}
-
-const MT_Point3& RAS_TexVert::xyz()
-{
- g_pt3.setValue(m_localxyz);
- return g_pt3;
-}
-
-void RAS_TexVert::SetRGBA(const MT_Vector4& rgba)
-{
- unsigned char *colp = (unsigned char*) &m_rgba;
- colp[0] = (unsigned char) (rgba[0] * 255.0f);
- colp[1] = (unsigned char) (rgba[1] * 255.0f);
- colp[2] = (unsigned char) (rgba[2] * 255.0f);
- colp[3] = (unsigned char) (rgba[3] * 255.0f);
-}
-
-
-void RAS_TexVert::SetXYZ(const MT_Point3& xyz)
-{
- xyz.getValue(m_localxyz);
-}
-
-void RAS_TexVert::SetXYZ(const float xyz[3])
-{
- copy_v3_v3(m_localxyz, xyz);
-}
-
-void RAS_TexVert::SetUV(int index, const MT_Point2& uv)
-{
- uv.getValue(m_uvs[index]);
-}
-
-void RAS_TexVert::SetUV(int index, const float uv[2])
-{
- copy_v2_v2(m_uvs[index], uv);
-}
-
-void RAS_TexVert::SetRGBA(const unsigned int rgba)
-{
- m_rgba = rgba;
-}
-
-
-void RAS_TexVert::SetFlag(const short flag)
-{
- m_flag = flag;
-}
-
-void RAS_TexVert::SetUnit(const unsigned int u)
-{
- m_unit = (u <= (unsigned int) MAX_UNIT) ? u: (unsigned int)MAX_UNIT;
-}
-
-void RAS_TexVert::SetNormal(const MT_Vector3& normal)
-{
- normal.getValue(m_normal);
-}
-
-void RAS_TexVert::SetTangent(const MT_Vector3& tangent)
-{
- tangent.getValue(m_tangent);
-}
-
-
-// compare two vertices, and return true if both are almost identical (they can be shared)
-bool RAS_TexVert::closeTo(const RAS_TexVert* other)
-{
- const float eps = FLT_EPSILON;
- for (int i = 0; i < MAX_UNIT; i++) {
- if (!compare_v2v2(m_uvs[i], other->m_uvs[i], eps)) {
- return false;
- }
- }
-
- return (/* m_flag == other->m_flag && */
- /* at the moment the face only stores the smooth/flat setting so don't bother comparing it */
- (m_rgba == other->m_rgba) &&
- compare_v3v3(m_normal, other->m_normal, eps) &&
- compare_v3v3(m_tangent, other->m_tangent, eps)
- /* don't bother comparing m_localxyz since we know there from the same vert */
- /* && compare_v3v3(m_localxyz, other->m_localxyz, eps))*/
- );
-}
-
-short RAS_TexVert::getFlag() const
-{
- return m_flag;
-}
-
-
-unsigned int RAS_TexVert::getUnit() const
-{
- return m_unit;
-}
-
-void RAS_TexVert::Transform(const MT_Matrix4x4& mat, const MT_Matrix4x4& nmat)
-{
- SetXYZ((mat * MT_Vector4(m_localxyz[0], m_localxyz[1], m_localxyz[2], 1.0f)).getValue());
- SetNormal((nmat * MT_Vector4(m_normal[0], m_normal[1], m_normal[2], 1.0f)).getValue());
- SetTangent((nmat * MT_Vector4(m_tangent[0], m_tangent[1], m_tangent[2], 1.0f)).getValue());
-}
-
-void RAS_TexVert::TransformUV(int index, const MT_Matrix4x4& mat)
-{
- SetUV(index, (mat * MT_Vector4(m_uvs[index][0], m_uvs[index][1], 0.0f, 1.0f)).getValue());
-}
diff --git a/source/gameengine/Rasterizer/RAS_TexVert.h b/source/gameengine/Rasterizer/RAS_TexVert.h
deleted file mode 100644
index 8d08549d97e..00000000000
--- a/source/gameengine/Rasterizer/RAS_TexVert.h
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file RAS_TexVert.h
- * \ingroup bgerast
- */
-
-#ifndef __RAS_TEXVERT_H__
-#define __RAS_TEXVERT_H__
-
-
-#include "MT_Point3.h"
-#include "MT_Point2.h"
-#include "MT_Transform.h"
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-static MT_Point3 g_pt3;
-static MT_Point2 g_pt2;
-
-class RAS_TexVert
-{
-
- float m_localxyz[3]; // 3*4 = 12
- float m_uvs[8][2]; // 8*2*4=64 //8 = MAX_UNIT
- unsigned int m_rgba; // 4
- float m_tangent[4]; // 4*4 = 16
- float m_normal[3]; // 3*4 = 12
- short m_flag; // 2
- short m_softBodyIndex; //2
- unsigned int m_unit; // 4
- unsigned int m_origindex; // 4
- char m_padding[8]; // 8
- //---------
- // 128
- // 32 bytes alignment improves performance on ATI cards.
-
-public:
- enum {
- FLAT = 1,
- MAX_UNIT = 8
- };
-
- short getFlag() const;
- unsigned int getUnit() const;
-
- RAS_TexVert()// :m_xyz(0,0,0),m_uv(0,0),m_rgba(0)
- {}
- RAS_TexVert(const MT_Point3& xyz,
- const MT_Point2 uvs[MAX_UNIT],
- const MT_Vector4& tangent,
- const unsigned int rgba,
- const MT_Vector3& normal,
- const bool flat,
- const unsigned int origindex);
- ~RAS_TexVert() {};
-
- const float* getUV (int unit) const {
- return m_uvs[unit];
- };
-
- const float* getXYZ() const {
- return m_localxyz;
- };
-
- const float* getNormal() const {
- return m_normal;
- }
-
- short int getSoftBodyIndex() const
- {
- return m_softBodyIndex;
- }
-
- void setSoftBodyIndex(short int sbIndex)
- {
- m_softBodyIndex = sbIndex;
- }
-
- const float* getTangent() const {
- return m_tangent;
- }
-
- const unsigned char* getRGBA() const {
- return (unsigned char *) &m_rgba;
- }
-
- unsigned int getOrigIndex() const {
- return m_origindex;
- }
-
- void SetXYZ(const MT_Point3& xyz);
- void SetXYZ(const float xyz[3]);
- void SetUV(int index, const MT_Point2& uv);
- void SetUV(int index, const float uv[2]);
-
- void SetRGBA(const unsigned int rgba);
- void SetNormal(const MT_Vector3& normal);
- void SetTangent(const MT_Vector3& tangent);
- void SetFlag(const short flag);
- void SetUnit(const unsigned u);
-
- void SetRGBA(const MT_Vector4& rgba);
- const MT_Point3& xyz();
-
- void Transform(const class MT_Matrix4x4& mat,
- const class MT_Matrix4x4& nmat);
- void TransformUV(int index, const MT_Matrix4x4& mat);
-
- // compare two vertices, to test if they can be shared, used for
- // splitting up based on uv's, colors, etc
- bool closeTo(const RAS_TexVert* other);
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:RAS_TexVert")
-#endif
-};
-
-#endif /* __RAS_TEXVERT_H__ */
diff --git a/source/gameengine/Rasterizer/RAS_texmatrix.cpp b/source/gameengine/Rasterizer/RAS_texmatrix.cpp
deleted file mode 100644
index d30a3d3a75d..00000000000
--- a/source/gameengine/Rasterizer/RAS_texmatrix.cpp
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/Rasterizer/RAS_texmatrix.cpp
- * \ingroup bgerast
- */
-
-
-#include "RAS_TexMatrix.h"
-
-void RAS_CalcTexMatrix(RAS_TexVert p[3],MT_Point3& origin,MT_Vector3& udir,MT_Vector3& vdir)
-{
-// precondition: 3 vertices are non-collinear
-
- MT_Vector3 vec1 = p[1].xyz()-p[0].xyz();
- MT_Vector3 vec2 = p[2].xyz()-p[0].xyz();
- MT_Vector3 normal = vec1.cross(vec2);
- normal.normalize();
-
- // determine which coordinate we drop, ie. max coordinate in the normal
-
-
- int ZCOORD = normal.closestAxis();
- int XCOORD = (ZCOORD+1)%3;
- int YCOORD = (ZCOORD+2)%3;
-
- // ax+by+cz+d=0
- MT_Scalar d = -p[0].xyz().dot(normal);
-
-
- MT_Matrix3x3 mat3( p[0].getUV(0)[0],p[0].getUV(0)[1], 1,
- p[1].getUV(0)[0],p[1].getUV(0)[1], 1,
- p[2].getUV(0)[0],p[2].getUV(0)[1], 1);
-
-
- MT_Matrix3x3 mat3inv = mat3.inverse();
-
- MT_Vector3 p123x(p[0].xyz()[XCOORD],p[1].xyz()[XCOORD],p[2].xyz()[XCOORD]);
- MT_Vector3 resultx = mat3inv*p123x;
- MT_Vector3 p123y(p[0].xyz()[YCOORD],p[1].xyz()[YCOORD],p[2].xyz()[YCOORD]);
- MT_Vector3 resulty = mat3inv*p123y;
-
- // normal[ZCOORD] is not zero, because it's chosen to be maximal (absolute), and normal has length 1,
- // so at least on of the coords is <> 0
-
- //droppedvalue udir.dot(normal) =0
- MT_Scalar droppedu = -(resultx.x()*normal[XCOORD]+resulty.x()*normal[YCOORD])/normal[ZCOORD];
- udir[XCOORD] = resultx.x();
- udir[YCOORD] = resulty.x();
- udir[ZCOORD] = droppedu;
- MT_Scalar droppedv = -(resultx.y()*normal[XCOORD]+resulty.y()*normal[YCOORD])/normal[ZCOORD];
- vdir[XCOORD] = resultx.y();
- vdir[YCOORD] = resulty.y();
- vdir[ZCOORD] = droppedv;
- // droppedvalue b = -(ax+cz+d)/y;
- MT_Scalar droppedvalue = -((resultx.z()*normal[XCOORD] + resulty.z()*normal[YCOORD]+d))/normal[ZCOORD];
- origin[XCOORD] = resultx.z();
- origin[YCOORD] = resulty.z();
- origin[ZCOORD] = droppedvalue;
-
-
-}
-
-#ifdef _TEXOWNMAIN
-
-int main()
-{
-
- MT_Point2 puv0={0,0};
- MT_Point3 pxyz0 (0,0,128);
-
- MT_Scalar puv1[2] = {1,0};
- MT_Point3 pxyz1(128,0,128);
-
- MT_Scalar puv2[2] = {1,1};
- MT_Point3 pxyz2(128,0,0);
-
- RAS_TexVert p0(pxyz0,puv0);
- RAS_TexVert p1(pxyz1,puv1);
- RAS_TexVert p2(pxyz2,puv2);
-
- RAS_TexVert vertices[3] =
- {
- p0,
- p1,
- p2
- };
-
- MT_Vector3 udir,vdir;
- MT_Point3 origin;
- CalcTexMatrix(vertices,origin,udir,vdir);
-
- MT_Point3 testpoint(128,32,64);
-
- MT_Scalar lenu = udir.length2();
- MT_Scalar lenv = vdir.length2();
-
- MT_Scalar testu=((pxyz2-origin).dot(udir))/lenu;
- MT_Scalar testv=((pxyz2-origin).dot(vdir))/lenv;
-
-
-
-
- return 0;
-}
-
-#endif // _TEXOWNMAIN
diff --git a/source/gameengine/SceneGraph/CMakeLists.txt b/source/gameengine/SceneGraph/CMakeLists.txt
deleted file mode 100644
index bbad429bbcd..00000000000
--- a/source/gameengine/SceneGraph/CMakeLists.txt
+++ /dev/null
@@ -1,53 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
-)
-
-set(INC_SYS
- ../../../intern/moto/include
-)
-
-set(SRC
- SG_BBox.cpp
- SG_Controller.cpp
- SG_IObject.cpp
- SG_Node.cpp
- SG_Spatial.cpp
- SG_Tree.cpp
-
- SG_BBox.h
- SG_Controller.h
- SG_DList.h
- SG_IObject.h
- SG_Node.h
- SG_ParentRelation.h
- SG_QList.h
- SG_Spatial.h
- SG_Tree.h
-)
-
-blender_add_lib(ge_scenegraph "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/SceneGraph/SG_BBox.cpp b/source/gameengine/SceneGraph/SG_BBox.cpp
deleted file mode 100644
index f9d83d37384..00000000000
--- a/source/gameengine/SceneGraph/SG_BBox.cpp
+++ /dev/null
@@ -1,262 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Bounding Box
- */
-
-/** \file gameengine/SceneGraph/SG_BBox.cpp
- * \ingroup bgesg
- */
-
-
-#include <math.h>
-
-#include "SG_BBox.h"
-#include "SG_Node.h"
-
-SG_BBox::SG_BBox() :
- m_min(0.0f, 0.0f, 0.0f),
- m_max(0.0f, 0.0f, 0.0f)
-{
-}
-
-SG_BBox::SG_BBox(const MT_Point3 &min, const MT_Point3 &max) :
- m_min(min),
- m_max(max)
-{
-}
-
-SG_BBox::SG_BBox(const SG_BBox &other, const MT_Transform &world) :
- m_min(world(other.m_min)),
- m_max(world(other.m_max))
-{
- *this += world(MT_Point3(m_min[0], m_min[1], m_max[2]));
- *this += world(MT_Point3(m_min[0], m_max[1], m_min[2]));
- *this += world(MT_Point3(m_min[0], m_max[1], m_max[2]));
- *this += world(MT_Point3(m_max[0], m_min[1], m_min[2]));
- *this += world(MT_Point3(m_max[0], m_min[1], m_max[2]));
- *this += world(MT_Point3(m_max[0], m_max[1], m_min[2]));
-}
-
-SG_BBox::SG_BBox(const SG_BBox &other) :
- m_min(other.m_min),
- m_max(other.m_max)
-{
-}
-
-SG_BBox::~ SG_BBox()
-{
-}
-
-SG_BBox& SG_BBox::operator +=(const MT_Point3 &point)
-{
- if (point[0] < m_min[0])
- m_min[0] = point[0];
- else if (point[0] > m_max[0])
- m_max[0] = point[0];
-
- if (point[1] < m_min[1])
- m_min[1] = point[1];
- else if (point[1] > m_max[1])
- m_max[1] = point[1];
-
- if (point[2] < m_min[2])
- m_min[2] = point[2];
- else if (point[2] > m_max[2])
- m_max[2] = point[2];
-
- return *this;
-}
-
-SG_BBox& SG_BBox::operator += (const SG_BBox &bbox)
-{
- *this += bbox.m_min;
- *this += bbox.m_max;
-
- return *this;
-}
-
-SG_BBox SG_BBox::operator +(const SG_BBox &bbox2) const
-{
- SG_BBox ret = *this;
- ret += bbox2;
- return ret;
-}
-
-MT_Scalar SG_BBox::volume() const
-{
- MT_Vector3 size = m_max - m_min;
- return size[0]*size[1]*size[2];
-}
-#if 0
-void SG_BBox::translate(const MT_Vector3& dx)
-{
- m_min += dx;
- m_max += dx;
-}
-
-void SG_BBox::scale(const MT_Vector3& size, const MT_Point3& point)
-{
- MT_Vector3 center = (m_max - m_min)/2. + point;
- m_max = (m_max - center)*size;
- m_min = (m_min - center)*size;
-}
-#endif
-
-SG_BBox SG_BBox::transform(const MT_Transform &world) const
-{
- SG_BBox bbox(world(m_min), world(m_max));
- bbox += world(MT_Point3(m_min[0], m_min[1], m_max[2]));
- bbox += world(MT_Point3(m_min[0], m_max[1], m_min[2]));
- bbox += world(MT_Point3(m_min[0], m_max[1], m_max[2]));
- bbox += world(MT_Point3(m_max[0], m_min[1], m_min[2]));
- bbox += world(MT_Point3(m_max[0], m_min[1], m_max[2]));
- bbox += world(MT_Point3(m_max[0], m_max[1], m_min[2]));
- return bbox;
-}
-
-bool SG_BBox::inside(const MT_Point3 &point) const
-{
- return point[0] >= m_min[0] && point[0] <= m_max[0] &&
- point[1] >= m_min[1] && point[1] <= m_max[1] &&
- point[2] >= m_min[2] && point[2] <= m_max[2];
-}
-
-bool SG_BBox::inside(const SG_BBox& other) const
-{
- return inside(other.m_min) && inside(other.m_max);
-}
-
-bool SG_BBox::intersects(const SG_BBox& other) const
-{
- return inside(other.m_min) != inside(other.m_max);
-}
-
-bool SG_BBox::outside(const SG_BBox& other) const
-{
- return !inside(other.m_min) && !inside(other.m_max);
-}
-
-SG_BBox::intersect SG_BBox::test(const SG_BBox& other) const
-{
- bool point1(inside(other.m_min)), point2(inside(other.m_max));
-
- return point1?(point2?INSIDE:INTERSECT):(point2?INTERSECT:OUTSIDE);
-}
-
-void SG_BBox::get(MT_Point3 *box, const MT_Transform &world) const
-{
- *box++ = world(m_min);
- *box++ = world(MT_Point3(m_min[0], m_min[1], m_max[2]));
- *box++ = world(MT_Point3(m_min[0], m_max[1], m_min[2]));
- *box++ = world(MT_Point3(m_min[0], m_max[1], m_max[2]));
- *box++ = world(MT_Point3(m_max[0], m_min[1], m_min[2]));
- *box++ = world(MT_Point3(m_max[0], m_min[1], m_max[2]));
- *box++ = world(MT_Point3(m_max[0], m_max[1], m_min[2]));
- *box++ = world(m_max);
-}
-
-void SG_BBox::getaa(MT_Point3 *box, const MT_Transform &world) const
-{
- const MT_Point3 min(world(m_min)), max(world(m_max));
- *box++ = min;
- *box++ = MT_Point3(min[0], min[1], max[2]);
- *box++ = MT_Point3(min[0], max[1], min[2]);
- *box++ = MT_Point3(min[0], max[1], max[2]);
- *box++ = MT_Point3(max[0], min[1], min[2]);
- *box++ = MT_Point3(max[0], min[1], max[2]);
- *box++ = MT_Point3(max[0], max[1], min[2]);
- *box++ = max;
-}
-
-void SG_BBox::getmm(MT_Point3 *box, const MT_Transform &world) const
-{
- const MT_Point3 min(world(m_min)), max(world(m_max));
- *box++ = min;
- *box++ = max;
-}
-
-void SG_BBox::split(SG_BBox &left, SG_BBox &right) const
-{
- MT_Scalar sizex = m_max[0] - m_min[0];
- MT_Scalar sizey = m_max[1] - m_min[1];
- MT_Scalar sizez = m_max[2] - m_min[2];
- if (sizex < sizey)
- {
- if (sizey > sizez)
- {
- left.m_min = m_min;
- left.m_max[0] = m_max[0];
- left.m_max[1] = m_min[1] + sizey/2.0f;
- left.m_max[2] = m_max[2];
-
- right.m_min[0] = m_min[0];
- right.m_min[1] = m_min[1] + sizey/2.0f;
- right.m_min[2] = m_min[2];
- right.m_max = m_max;
- std::cout << "splity" << std::endl;
- }
- else {
- left.m_min = m_min;
- left.m_max[0] = m_max[0];
- left.m_max[1] = m_max[1];
- left.m_max[2] = m_min[2] + sizez/2.0f;
-
- right.m_min[0] = m_min[0];
- right.m_min[1] = m_min[1];
- right.m_min[2] = m_min[2] + sizez/2.0f;
- right.m_max = m_max;
- std::cout << "splitz" << std::endl;
- }
- }
- else {
- if (sizex > sizez) {
- left.m_min = m_min;
- left.m_max[0] = m_min[0] + sizex/2.0f;
- left.m_max[1] = m_max[1];
- left.m_max[2] = m_max[2];
-
- right.m_min[0] = m_min[0] + sizex/2.0f;
- right.m_min[1] = m_min[1];
- right.m_min[2] = m_min[2];
- right.m_max = m_max;
- std::cout << "splitx" << std::endl;
- }
- else {
- left.m_min = m_min;
- left.m_max[0] = m_max[0];
- left.m_max[1] = m_max[1];
- left.m_max[2] = m_min[2] + sizez/2.0f;
-
- right.m_min[0] = m_min[0];
- right.m_min[1] = m_min[1];
- right.m_min[2] = m_min[2] + sizez/2.0f;
- right.m_max = m_max;
- std::cout << "splitz" << std::endl;
- }
- }
-
- //std::cout << "Left: " << left.m_min << " -> " << left.m_max << " Right: " << right.m_min << " -> " << right.m_max << std::endl;
-}
diff --git a/source/gameengine/SceneGraph/SG_BBox.h b/source/gameengine/SceneGraph/SG_BBox.h
deleted file mode 100644
index 3c524dc7f18..00000000000
--- a/source/gameengine/SceneGraph/SG_BBox.h
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_BBox.h
- * \ingroup bgesg
- * \brief Bounding Box
- */
-
-#ifndef __SG_BBOX_H__
-#define __SG_BBOX_H__
-
-#include "MT_Scalar.h"
-#include "MT_Point3.h"
-#include "MT_Vector3.h"
-#include "MT_Transform.h"
-
-#include <vector>
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-class SG_Node;
-
-/**
- * Bounding box class.
- * Holds the minimum and maximum axis aligned points of a node's bounding box,
- * in world coordinates.
- */
-class SG_BBox
-{
- MT_Point3 m_min;
- MT_Point3 m_max;
-public:
- typedef enum { INSIDE, INTERSECT, OUTSIDE } intersect;
- SG_BBox();
- SG_BBox(const MT_Point3 &min, const MT_Point3 &max);
- SG_BBox(const SG_BBox &other, const MT_Transform &world);
- SG_BBox(const SG_BBox &other);
- ~SG_BBox();
-
- /**
- * Enlarges the bounding box to contain the specified point.
- */
- SG_BBox& operator +=(const MT_Point3 &point);
- /**
- * Enlarges the bounding box to contain the specified bound box.
- */
- SG_BBox& operator +=(const SG_BBox &bbox);
-
- SG_BBox operator + (const SG_BBox &bbox2) const;
-#if 0
- /**
- * Translates the bounding box.
- */
- void translate(const MT_Vector3 &dx);
- /**
- * Scales the bounding box about the optional point.
- */
- void scale(const MT_Vector3 &size, const MT_Point3 &point = MT_Point3(0.0f, 0.0f, 0.0f));
-#endif
- SG_BBox transform(const MT_Transform &world) const;
- /**
- * Computes the volume of the bounding box.
- */
- MT_Scalar volume() const;
-
- /**
- * Test if the given point is inside this bounding box.
- */
- bool inside(const MT_Point3 &point) const;
-
- /**
- * Test if the given bounding box is inside this bounding box.
- */
- bool inside(const SG_BBox &other) const;
-
- /**
- * Test if the given bounding box is outside this bounding box.
- */
- bool outside(const SG_BBox &other) const;
-
- /**
- * Test if the given bounding box intersects this bounding box.
- */
- bool intersects(const SG_BBox &other) const;
-
- /**
- * Test the given bounding box with this bounding box.
- */
- intersect test(const SG_BBox &other) const;
-
- /**
- * Get the eight points that define this bounding box.
- *
- * \param world a world transform to apply to the produced points bounding box.
- */
- void get(MT_Point3 *box, const MT_Transform &world) const;
- /**
- * Get the eight points that define this axis aligned bounding box.
- * This differs from SG_BBox::get() in that the produced box will be world axis aligned.
- * The maximum & minimum local points will be transformed *before* splitting to 8 points.
- * \param world a world transform to be applied.
- */
- void getaa(MT_Point3 *box, const MT_Transform &world) const;
-
- void getmm(MT_Point3 *box, const MT_Transform &world) const;
-
- void split(SG_BBox &left, SG_BBox &right) const;
-
- friend class SG_Tree;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_BBox")
-#endif
-};
-
-#endif /* __SG_BBOX_H__ */
diff --git a/source/gameengine/SceneGraph/SG_Controller.cpp b/source/gameengine/SceneGraph/SG_Controller.cpp
deleted file mode 100644
index 264942415c9..00000000000
--- a/source/gameengine/SceneGraph/SG_Controller.cpp
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/SceneGraph/SG_Controller.cpp
- * \ingroup bgesg
- */
-
-#include "SG_Controller.h"
-
- void
-SG_Controller::
-SetObject(SG_IObject* obj)
-{
- m_pObject = obj; // no checks yet ?
-}
-
- void
-SG_Controller::
-ClearObject(
-) {
- m_pObject = NULL;
-}
diff --git a/source/gameengine/SceneGraph/SG_Controller.h b/source/gameengine/SceneGraph/SG_Controller.h
deleted file mode 100644
index a173633e13c..00000000000
--- a/source/gameengine/SceneGraph/SG_Controller.h
+++ /dev/null
@@ -1,124 +0,0 @@
-/*
- * Implementationclass to derive controllers from
- *
- *
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_Controller.h
- * \ingroup bgesg
- */
-
-#ifndef __SG_CONTROLLER_H__
-#define __SG_CONTROLLER_H__
-
-#include "SG_IObject.h"
-
-/**
- * A scenegraph controller
- */
-class SG_Controller
-{
-public:
- SG_Controller(
- ) :
- m_pObject(NULL) {
- }
-
- virtual
- ~SG_Controller(
- ) {};
-
- virtual
- bool
- Update(
- double time
- )=0;
-
- virtual
- void
- SetObject (
- SG_IObject* object
- );
-
- void
- ClearObject(
- );
-
- virtual
- void
- SetSimulatedTime(
- double time
- )=0;
-
- virtual
- SG_Controller*
- GetReplica(
- class SG_Node* destnode
- )=0;
-
- /**
- * Hacky way of passing options to specific controllers
- * \param option An integer identifying the option.
- * \param value The value of this option.
- * \attention This has been placed here to give sca-elements
- * \attention some control over the controllers. This is
- * \attention necessary because the identity of the controller
- * \attention is lost on the way here.
- */
- virtual
- void
- SetOption(
- int option,
- int value
- )=0;
-
- /**
- * Option-identifiers: SG_CONTR_<controller-type>_<option>.
- * Options only apply to a specific controller type. The
- * semantics are defined by whoever uses the setting.
- */
- enum SG_Controller_option {
- SG_CONTR_NODEF = 0,
- SG_CONTR_IPO_IPO_AS_FORCE,
- SG_CONTR_IPO_IPO_ADD,
- SG_CONTR_IPO_LOCAL,
- SG_CONTR_IPO_RESET,
- SG_CONTR_CAMIPO_LENS,
- SG_CONTR_CAMIPO_CLIPEND,
- SG_CONTR_CAMIPO_CLIPSTART,
- SG_CONTR_MAX
- };
-
-protected:
- SG_IObject* m_pObject;
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_Controller")
-#endif
-};
-
-#endif /* __SG_CONTROLLER_H__ */
diff --git a/source/gameengine/SceneGraph/SG_DList.h b/source/gameengine/SceneGraph/SG_DList.h
deleted file mode 100644
index 90153f14c07..00000000000
--- a/source/gameengine/SceneGraph/SG_DList.h
+++ /dev/null
@@ -1,251 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_DList.h
- * \ingroup bgesg
- */
-
-#ifndef __SG_DLIST_H__
-#define __SG_DLIST_H__
-
-#include <stdlib.h>
-
-#ifdef WITH_CXX_GUARDEDALLOC
-#include "MEM_guardedalloc.h"
-#endif
-
-/**
- * Double circular linked list
- */
-class SG_DList
-{
-protected :
- SG_DList* m_flink;
- SG_DList* m_blink;
-
-public:
- template<typename T> class iterator
- {
- private:
- SG_DList& m_head;
- T* m_current;
- public:
- typedef iterator<T> _myT;
- iterator(SG_DList& head) : m_head(head), m_current(NULL) {}
- ~iterator() {}
-
- void begin()
- {
- m_current = (T*)m_head.Peek();
- }
- void back()
- {
- m_current = (T*)m_head.Back();
- }
- bool end()
- {
- return (m_current == (T*)m_head.Self());
- }
- bool add_back(T* item)
- {
- return m_current->AddBack(item);
- }
- T* operator*()
- {
- return m_current;
- }
- _myT& operator++()
- {
- // no check of NULL! make sure you don't try to increment beyond end
- m_current = (T*)m_current->Peek();
- return *this;
- }
- _myT& operator--()
- {
- // no check of NULL! make sure you don't try to increment beyond end
- m_current = (T*)m_current->Back();
- return *this;
- }
- };
-
- template<typename T> class const_iterator
- {
- private:
- const SG_DList& m_head;
- const T* m_current;
- public:
- typedef const_iterator<T> _myT;
- const_iterator(const SG_DList& head) : m_head(head), m_current(NULL) {}
- ~const_iterator() {}
-
- void begin()
- {
- m_current = (const T*)m_head.Peek();
- }
- void back()
- {
- m_current = (const T*)m_head.Back();
- }
- bool end()
- {
- return (m_current == (const T*)m_head.Self());
- }
- const T* operator*()
- {
- return m_current;
- }
- _myT& operator++()
- {
- // no check of NULL! make sure you don't try to increment beyond end
- m_current = (const T*)m_current->Peek();
- return *this;
- }
- _myT& operator--()
- {
- // no check of NULL! make sure you don't try to increment beyond end
- m_current = (const T*)m_current->Back();
- return *this;
- }
- };
-
- SG_DList()
- {
- m_flink = m_blink = this;
- }
- SG_DList(const SG_DList& other)
- {
- m_flink = m_blink = this;
- }
- virtual ~SG_DList()
- {
- Delink();
- }
-
- inline bool Empty() // Check for empty queue
- {
- return ( m_flink == this );
- }
- bool AddBack( SG_DList *item ) // Add to the back
- {
- if (!item->Empty())
- return false;
- item->m_blink = m_blink;
- item->m_flink = this;
- m_blink->m_flink = item;
- m_blink = item;
- return true;
- }
- bool AddFront( SG_DList *item ) // Add to the back
- {
- if (!item->Empty())
- return false;
- item->m_flink = m_flink;
- item->m_blink = this;
- m_flink->m_blink = item;
- m_flink = item;
- return true;
- }
- SG_DList *Remove() // Remove from the front
- {
- if (Empty())
- {
- return NULL;
- }
- SG_DList* item = m_flink;
- m_flink = item->m_flink;
- m_flink->m_blink = this;
- item->m_flink = item->m_blink = item;
- return item;
- }
- bool Delink() // Remove from the middle
- {
- if (Empty())
- return false;
- m_blink->m_flink = m_flink;
- m_flink->m_blink = m_blink;
- m_flink = m_blink = this;
- return true;
- }
- inline SG_DList *Peek() // Look at front without removing
- {
- return m_flink;
- }
- inline SG_DList *Back() // Look at front without removing
- {
- return m_blink;
- }
- inline SG_DList *Self()
- {
- return this;
- }
- inline const SG_DList *Peek() const // Look at front without removing
- {
- return (const SG_DList*)m_flink;
- }
- inline const SG_DList *Back() const // Look at front without removing
- {
- return (const SG_DList*)m_blink;
- }
- inline const SG_DList *Self() const
- {
- return this;
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_DList")
-#endif
-};
-
-/**
- * SG_DListHead : Template class that implements copy constructor to duplicate list automatically
- * The elements of the list must have themselves a copy constructor.
- */
-template<typename T> class SG_DListHead : public SG_DList
-{
-public:
- typedef SG_DListHead<T> _myT;
- SG_DListHead() : SG_DList() {}
- SG_DListHead(const _myT& other) : SG_DList()
- {
- // copy the list, assuming objects of type T
- const_iterator<T> eit(other);
- T* elem;
- for (eit.begin(); !eit.end(); ++eit) {
- elem = (*eit)->GetReplica();
- AddBack(elem);
- }
- }
- virtual ~SG_DListHead() {}
- T* Remove()
- {
- return static_cast<T*>(SG_DList::Remove());
- }
-
-};
-
-#endif /* __SG_DLIST_H__ */
diff --git a/source/gameengine/SceneGraph/SG_IObject.cpp b/source/gameengine/SceneGraph/SG_IObject.cpp
deleted file mode 100644
index 9ae32a89ff8..00000000000
--- a/source/gameengine/SceneGraph/SG_IObject.cpp
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/SceneGraph/SG_IObject.cpp
- * \ingroup bgesg
- */
-
-
-#include "SG_IObject.h"
-#include "SG_Controller.h"
-
-#include <algorithm>
-
-SG_Stage gSG_Stage = SG_STAGE_UNKNOWN;
-
-SG_IObject::
-SG_IObject(
- void* clientobj,
- void* clientinfo,
- SG_Callbacks& callbacks
-):
- SG_QList(),
- m_SGclientObject(clientobj),
- m_SGclientInfo(clientinfo)
-{
- m_callbacks = callbacks;
-}
-
-SG_IObject::
-SG_IObject(
- const SG_IObject &other
-) :
- SG_QList(),
- m_SGclientObject(other.m_SGclientObject),
- m_SGclientInfo(other.m_SGclientInfo),
- m_callbacks(other.m_callbacks)
-{
- //nothing to do
-}
-
- void
-SG_IObject::
-AddSGController(
- SG_Controller* cont
-) {
- m_SGcontrollers.push_back(cont);
-}
-
- void
-SG_IObject::
-RemoveSGController(
- SG_Controller* cont
-) {
- SGControllerList::iterator contit;
-
- m_SGcontrollers.erase(std::remove(m_SGcontrollers.begin(), m_SGcontrollers.end(), cont));
-}
-
- void
-SG_IObject::
-RemoveAllControllers(
-) {
- m_SGcontrollers.clear();
-}
-
-void SG_IObject::SetControllerTime(double time)
-{
- SGControllerList::iterator contit;
- for (contit = m_SGcontrollers.begin();contit!=m_SGcontrollers.end();++contit)
- {
- (*contit)->SetSimulatedTime(time);
- }
-}
-
-/// Needed for replication
-
-
-SG_IObject::
-~SG_IObject()
-{
- SGControllerList::iterator contit;
-
- for (contit = m_SGcontrollers.begin();contit!=m_SGcontrollers.end();++contit)
- {
- delete (*contit);
- }
-}
diff --git a/source/gameengine/SceneGraph/SG_IObject.h b/source/gameengine/SceneGraph/SG_IObject.h
deleted file mode 100644
index 2dcf3c6492e..00000000000
--- a/source/gameengine/SceneGraph/SG_IObject.h
+++ /dev/null
@@ -1,374 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_IObject.h
- * \ingroup bgesg
- */
-
-#ifndef __SG_IOBJECT_H__
-#define __SG_IOBJECT_H__
-
-#include "SG_QList.h"
-#include <vector>
-
-// used for debugging: stage of the game engine main loop at which a Scenegraph modification is done
-enum SG_Stage
-{
- SG_STAGE_UNKNOWN = 0,
- SG_STAGE_NETWORK,
- SG_STAGE_NETWORK_UPDATE,
- SG_STAGE_PHYSICS1,
- SG_STAGE_PHYSICS1_UPDATE,
- SG_STAGE_CONTROLLER,
- SG_STAGE_CONTROLLER_UPDATE,
- SG_STAGE_ACTUATOR,
- SG_STAGE_ACTUATOR_UPDATE,
- SG_STAGE_ANIMATION_UPDATE,
- SG_STAGE_PHYSICS2,
- SG_STAGE_PHYSICS2_UPDATE,
- SG_STAGE_SCENE,
- SG_STAGE_RENDER,
- SG_STAGE_CONVERTER,
- SG_STAGE_CULLING,
- SG_STAGE_MAX
-};
-
-extern SG_Stage gSG_Stage;
-
-inline void SG_SetActiveStage(SG_Stage stage)
-{
- gSG_Stage = stage;
-}
-
-
-
-class SG_Controller;
-class SG_IObject;
-
-typedef std::vector<SG_Controller*> SGControllerList;
-
-typedef void* (*SG_ReplicationNewCallback)(
- SG_IObject* sgobject,
- void* clientobj,
- void* clientinfo
-);
-
-typedef void* (*SG_DestructionNewCallback)(
- SG_IObject* sgobject,
- void* clientobj,
- void* clientinfo
-);
-
-typedef void (*SG_UpdateTransformCallback)(
- SG_IObject* sgobject,
- void* clientobj,
- void* clientinfo
-);
-
-typedef bool (*SG_ScheduleUpdateCallback)(
- SG_IObject* sgobject,
- void* clientobj,
- void* clientinfo
-);
-
-typedef bool (*SG_RescheduleUpdateCallback)(
- SG_IObject* sgobject,
- void* clientobj,
- void* clientinfo
-);
-
-
-/**
- * SG_Callbacks hold 2 call backs to the outside world.
- * The first is meant to be called when objects are replicated.
- * And allows the outside world to synchronize external objects
- * with replicated nodes and their children.
- * The second is called when a node is destroyed and again
- * is their for synchronization purposes
- * These callbacks may both be NULL.
- * The efficacy of this approach has not been proved some
- * alternatives might be to perform all replication and destruction
- * externally.
- * To define a class interface rather than a simple function
- * call back so that replication information can be transmitted from
- * parent->child.
- */
-struct SG_Callbacks
-{
- SG_Callbacks(
- ):
- m_replicafunc(NULL),
- m_destructionfunc(NULL),
- m_updatefunc(NULL),
- m_schedulefunc(NULL),
- m_reschedulefunc(NULL)
- {
- }
-
- SG_Callbacks(
- SG_ReplicationNewCallback repfunc,
- SG_DestructionNewCallback destructfunc,
- SG_UpdateTransformCallback updatefunc,
- SG_ScheduleUpdateCallback schedulefunc,
- SG_RescheduleUpdateCallback reschedulefunc
- ):
- m_replicafunc(repfunc),
- m_destructionfunc(destructfunc),
- m_updatefunc(updatefunc),
- m_schedulefunc(schedulefunc),
- m_reschedulefunc(reschedulefunc)
- {
- }
-
- SG_ReplicationNewCallback m_replicafunc;
- SG_DestructionNewCallback m_destructionfunc;
- SG_UpdateTransformCallback m_updatefunc;
- SG_ScheduleUpdateCallback m_schedulefunc;
- SG_RescheduleUpdateCallback m_reschedulefunc;
-};
-
-/**
- * base object that can be part of the scenegraph.
- */
-class SG_IObject : public SG_QList
-{
-private :
-
- void* m_SGclientObject;
- void* m_SGclientInfo;
- SG_Callbacks m_callbacks;
- SGControllerList m_SGcontrollers;
-
-public:
- virtual ~SG_IObject();
-
-
- /**
- * Add a pointer to a controller allocated on the heap, to
- * this node. This memory for this controller becomes the
- * responsibility of this class. It will be deleted when
- * this object is deleted.
- */
-
- void
- AddSGController(
- SG_Controller* cont
- );
-
- /**
- * Remove a pointer to a controller from this node.
- * This does not delete the controller itself! Be careful to
- * avoid memory leaks.
- */
- void
- RemoveSGController(
- SG_Controller* cont
- );
-
- /**
- * Clear the array of pointers to controllers associated with
- * this node. This does not delete the controllers themselves!
- * This should be used very carefully to avoid memory
- * leaks.
- */
-
- void
- RemoveAllControllers(
- );
-
- /// Needed for replication
-
- /**
- * Return a reference to this node's controller list.
- * Whilst we don't wish to expose full control of the container
- * to the user we do allow them to call non_const methods
- * on pointers in the container. C++ topic: how to do this in
- * using STL?
- */
-
- SGControllerList& GetSGControllerList()
- {
- return m_SGcontrollers;
- }
-
- /**
- *
- */
- SG_Callbacks& GetCallBackFunctions()
- {
- return m_callbacks;
- }
-
- /**
- * Get the client object associated with this
- * node. This interface allows you to associate
- * arbitrary external objects with this node. They are
- * passed to the callback functions when they are
- * activated so you can synchronize these external objects
- * upon replication and destruction
- * This may be NULL.
- */
-
- inline const void* GetSGClientObject() const
- {
- return m_SGclientObject;
- }
-
- inline void* GetSGClientObject()
- {
- return m_SGclientObject;
- }
-
- /**
- * Set the client object for this node. This is just a
- * pointer to an object allocated that should exist for
- * the duration of the lifetime of this object, or until
- * this function is called again.
- */
-
- void SetSGClientObject(void* clientObject)
- {
- m_SGclientObject = clientObject;
- }
-
-
- /* needed for scene switching */
- inline const void* GetSGClientInfo() const
- {
- return m_SGclientInfo;
- }
- inline void* GetSGClientInfo()
- {
- return m_SGclientInfo;
- }
- void SetSGClientInfo(void* clientInfo)
- {
- m_SGclientInfo = clientInfo;
- }
-
-
- /**
- * Set the current simulation time for this node.
- * The implementation of this function runs through
- * the nodes list of controllers and calls their SetSimulatedTime methods
- */
-
- void SetControllerTime(double time);
-
- virtual
- void
- Destruct(
- ) = 0;
-
-protected :
-
- bool
- ActivateReplicationCallback(
- SG_IObject *replica
- )
- {
- if (m_callbacks.m_replicafunc)
- {
- // Call client provided replication func
- if (m_callbacks.m_replicafunc(replica,m_SGclientObject,m_SGclientInfo) == NULL)
- return false;
- }
- return true;
- }
-
-
- void
- ActivateDestructionCallback(
- )
- {
- if (m_callbacks.m_destructionfunc)
- {
- // Call client provided destruction function on this!
- m_callbacks.m_destructionfunc(this,m_SGclientObject,m_SGclientInfo);
- }
- else
- {
- // no callback but must still destroy the node to avoid memory leak
- delete this;
- }
- }
-
- void
- ActivateUpdateTransformCallback(
- )
- {
- if (m_callbacks.m_updatefunc)
- {
- // Call client provided update func.
- m_callbacks.m_updatefunc(this, m_SGclientObject, m_SGclientInfo);
- }
- }
-
- bool
- ActivateScheduleUpdateCallback(
- )
- {
- // HACK, this check assumes that the scheduled nodes are put on a DList (see SG_Node.h)
- // The early check on Empty() allows up to avoid calling the callback function
- // when the node is already scheduled for update.
- if (Empty() && m_callbacks.m_schedulefunc)
- {
- // Call client provided update func.
- return m_callbacks.m_schedulefunc(this, m_SGclientObject, m_SGclientInfo);
- }
- return false;
- }
-
- void
- ActivateRecheduleUpdateCallback(
- )
- {
- if (m_callbacks.m_reschedulefunc)
- {
- // Call client provided update func.
- m_callbacks.m_reschedulefunc(this, m_SGclientObject, m_SGclientInfo);
- }
- }
-
-
- SG_IObject(
- void* clientobj,
- void* clientinfo,
- SG_Callbacks& callbacks
- );
-
- SG_IObject(
- const SG_IObject &other
- );
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_IObject")
-#endif
-};
-
-#endif /* __SG_IOBJECT_H__ */
diff --git a/source/gameengine/SceneGraph/SG_Node.cpp b/source/gameengine/SceneGraph/SG_Node.cpp
deleted file mode 100644
index 04d9a306fc4..00000000000
--- a/source/gameengine/SceneGraph/SG_Node.cpp
+++ /dev/null
@@ -1,227 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/SceneGraph/SG_Node.cpp
- * \ingroup bgesg
- */
-
-
-#include "SG_Node.h"
-#include "SG_ParentRelation.h"
-#include <algorithm>
-
-using namespace std;
-
-
-SG_Node::SG_Node(
- void* clientobj,
- void* clientinfo,
- SG_Callbacks& callbacks
-
-)
- : SG_Spatial(clientobj,clientinfo,callbacks),
- m_SGparent(NULL)
-{
- m_modified = true;
-}
-
-SG_Node::SG_Node(
- const SG_Node & other
-) :
- SG_Spatial(other),
- m_children(other.m_children),
- m_SGparent(other.m_SGparent)
-{
- m_modified = true;
-}
-
-SG_Node::~SG_Node()
-{
-}
-
-
-SG_Node* SG_Node::GetSGReplica()
-{
- SG_Node* replica = new SG_Node(*this);
- if (replica == NULL) return NULL;
-
- ProcessSGReplica(&replica);
-
- return replica;
-}
-
- void
-SG_Node::
-ProcessSGReplica(
- SG_Node** replica
-) {
- // Apply the replication call back function.
- if (!ActivateReplicationCallback(*replica))
- {
- delete (*replica);
- *replica = NULL;
- return;
- }
-
- // clear the replica node of it's parent.
- static_cast<SG_Node*>(*replica)->m_SGparent = NULL;
-
- if (m_children.begin() != m_children.end())
- {
- // if this node has children, the replica has too, so clear and clone children
- (*replica)->ClearSGChildren();
-
- NodeList::iterator childit;
- for (childit = m_children.begin();childit!=m_children.end();++childit)
- {
- SG_Node* childnode = (*childit)->GetSGReplica();
- if (childnode)
- (*replica)->AddChild(childnode);
- }
- }
- // Nodes without children and without client object are
- // not worth to keep, they will just take up CPU
- // This can happen in partial replication of hierarchy
- // during group duplication.
- if ((*replica)->m_children.empty() &&
- (*replica)->GetSGClientObject() == NULL)
- {
- delete (*replica);
- *replica = NULL;
- }
-}
-
-
- void
-SG_Node::
-Destruct()
-{
- // Not entirely sure what Destruct() expects to happen.
- // I think it probably means just to call the DestructionCallback
- // in the right order on all the children - rather than free any memory
-
- // We'll delete m_parent_relation now anyway.
-
- delete(m_parent_relation);
- m_parent_relation = NULL;
-
- if (m_children.begin() != m_children.end())
- {
- NodeList::iterator childit;
- for (childit = m_children.begin();childit!=m_children.end();++childit)
- {
- // call the SG_Node destruct method on each of our children }-)
- (*childit)->Destruct();
- }
- }
-
- ActivateDestructionCallback();
-}
-
-const
- SG_Node *
-SG_Node::
-GetRootSGParent(
-) const {
- return (m_SGparent ? (const SG_Node*) m_SGparent->GetRootSGParent() : (const SG_Node*) this);
-}
-
-bool SG_Node::IsAncessor(const SG_Node* child) const
-{
- return (!child->m_SGparent) ? false :
- (child->m_SGparent == this) ? true : IsAncessor(child->m_SGparent);
-}
-
- void
-SG_Node::
-DisconnectFromParent(
-) {
- if (m_SGparent)
- {
- m_SGparent->RemoveChild(this);
- m_SGparent = NULL;
- }
-
-}
-
-void SG_Node::AddChild(SG_Node* child)
-{
- m_children.push_back(child);
- child->SetSGParent(this); // this way ?
-}
-
-void SG_Node::RemoveChild(SG_Node* child)
-{
- NodeList::iterator childfound = find(m_children.begin(),m_children.end(),child);
-
- if (childfound != m_children.end())
- {
- m_children.erase(childfound);
- }
-}
-
-
-
-void SG_Node::UpdateWorldData(double time, bool parentUpdated)
-{
- //if (!GetSGParent())
- // return;
-
- if (UpdateSpatialData(GetSGParent(),time,parentUpdated))
- // to update the
- ActivateUpdateTransformCallback();
-
- // The node is updated, remove it from the update list
- Delink();
-
- // update children's worlddata
- for (NodeList::iterator it = m_children.begin();it!=m_children.end();++it)
- {
- (*it)->UpdateWorldData(time, parentUpdated);
- }
-}
-
-
-
-void SG_Node::SetSimulatedTime(double time,bool recurse)
-{
-
- // update the controllers of this node.
- SetControllerTime(time);
-
- // update children's simulate time.
- if (recurse)
- {
- for (NodeList::iterator it = m_children.begin();it!=m_children.end();++it)
- {
- (*it)->SetSimulatedTime(time,recurse);
- }
- }
-}
-
-
-
diff --git a/source/gameengine/SceneGraph/SG_Node.h b/source/gameengine/SceneGraph/SG_Node.h
deleted file mode 100644
index bde64f21305..00000000000
--- a/source/gameengine/SceneGraph/SG_Node.h
+++ /dev/null
@@ -1,278 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_Node.h
- * \ingroup bgesg
- */
-
-#ifndef __SG_NODE_H__
-#define __SG_NODE_H__
-
-#include "SG_Spatial.h"
-#include <vector>
-
-typedef std::vector<SG_Node*> NodeList;
-
-/**
- * Scenegraph node.
- */
-class SG_Node : public SG_Spatial
-{
-public:
- SG_Node(
- void* clientobj,
- void* clientinfo,
- SG_Callbacks& callbacks
- );
-
- SG_Node(
- const SG_Node & other
- );
-
- virtual ~SG_Node();
-
-
- /**
- * Add a child to this object. This also informs the child of
- * it's parent.
- * This just stores a pointer to the child and does not
- * make a deep copy.
- */
-
- void
- AddChild(
- SG_Node* child
- );
-
- /**
- * Remove a child node from this object. This just removes the child
- * pointer from the list of children - it does not destroy the child.
- * This does not inform the child that this node is no longer it's parent.
- * If the node was not a child of this object no action is performed.
- */
-
- void
- RemoveChild(
- SG_Node* child
- );
-
- /**
- * Return true if the node is the ancestor of child
- */
- bool
- IsAncessor(
- const SG_Node* child
- ) const;
- /**
- * Get the current list of children. Do not use this interface for
- * adding or removing children please use the methods of this class for
- * that.
- * \return a reference to the list of children of this node.
- */
-
- NodeList& GetSGChildren()
- {
- return this->m_children;
- }
-
- /**
- * Get the current list of children.
- * \return a const reference to the current list of children of this node.
- */
-
- const NodeList& GetSGChildren() const
- {
- return this->m_children;
- }
-
- /**
- * Clear the list of children associated with this node
- */
-
- void ClearSGChildren()
- {
- m_children.clear();
- }
-
- /**
- * return the parent of this node if it exists.
- */
-
- SG_Node* GetSGParent() const
- {
- return m_SGparent;
- }
-
- /**
- * Set the parent of this node.
- */
-
- void SetSGParent(SG_Node* parent)
- {
- m_SGparent = parent;
- }
-
- /**
- * Return the top node in this node's Scene graph hierarchy
- */
-
- const
- SG_Node*
- GetRootSGParent(
- ) const;
-
- /**
- * Disconnect this node from it's parent
- */
-
- void
- DisconnectFromParent(
- );
-
- /**
- * Return vertex parent status.
- */
- bool IsVertexParent()
- {
- if (m_parent_relation)
- {
- return m_parent_relation->IsVertexRelation();
- }
- return false;
- }
-
-
- /**
- * Return slow parent status.
- */
-
- bool IsSlowParent()
- {
- if (m_parent_relation)
- {
- return m_parent_relation->IsSlowRelation();
- }
- return false;
- }
-
-
-
-
- /**
- * Update the spatial data of this node. Iterate through
- * the children of this node and update their world data.
- */
-
- void
- UpdateWorldData(
- double time,
- bool parentUpdated=false
- );
-
- /**
- * Update the simulation time of this node. Iterate through
- * the children nodes and update their simulated time.
- */
-
- void
- SetSimulatedTime(
- double time,
- bool recurse
- );
-
- /**
- * Schedule this node for update by placing it in head queue
- */
- bool Schedule(SG_QList& head)
- {
- // Put top parent in front of list to make sure they are updated before their
- // children => the children will be udpated and removed from the list before
- // we get to them, should they be in the list too.
- return (m_SGparent)?head.AddBack(this):head.AddFront(this);
- }
-
- /**
- * Used during Scenegraph update
- */
- static SG_Node* GetNextScheduled(SG_QList& head)
- {
- return static_cast<SG_Node*>(head.Remove());
- }
-
- /**
- * Make this node ready for schedule on next update. This is needed for nodes
- * that must always be updated (slow parent, bone parent)
- */
- bool Reschedule(SG_QList& head)
- {
- return head.QAddBack(this);
- }
-
- /**
- * Used during Scenegraph update
- */
- static SG_Node* GetNextRescheduled(SG_QList& head)
- {
- return static_cast<SG_Node*>(head.QRemove());
- }
-
- /**
- * Node replication functions.
- */
-
- SG_Node*
- GetSGReplica(
- );
-
- void
- Destruct(
- );
-
-private:
-
- void
- ProcessSGReplica(
- SG_Node** replica
- );
-
- /**
- * The list of children of this node.
- */
- NodeList m_children;
-
- /**
- * The parent of this node may be NULL
- */
- SG_Node* m_SGparent;
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_Node")
-#endif
-};
-
-#endif /* __SG_NODE_H__ */
diff --git a/source/gameengine/SceneGraph/SG_ParentRelation.h b/source/gameengine/SceneGraph/SG_ParentRelation.h
deleted file mode 100644
index ce45b42c148..00000000000
--- a/source/gameengine/SceneGraph/SG_ParentRelation.h
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- *
- */
-
-/** \file SG_ParentRelation.h
- * \ingroup bgesg
- * \page SG_ParentRelationPage SG_ParentRelation
- *
- * \section SG_ParentRelationSection SG_ParentRelation
- *
- * This is an abstract interface class to the Scene Graph library.
- * It allows you to specify how child nodes react to parent nodes.
- * Normally a child will use it's parent's transforms to compute
- * it's own global transforms. How this is performed depends on
- * the type of relation. For example if the parent is a vertex
- * parent to this child then the child should not inherit any
- * rotation information from the parent. Or if the parent is a
- * 'slow parent' to this child then the child should react
- * slowly to changes in the parent's position. The exact relation
- * is left for you to implement by filling out this interface
- * with concrete examples.
- *
- * There is exactly one SG_ParentRelation per SG_Node. Subclasses
- * should not be value types and should be allocated on the heap.
- *
- */
-
-#ifndef __SG_PARENTRELATION_H__
-#define __SG_PARENTRELATION_H__
-
-class SG_Spatial;
-
-class SG_ParentRelation {
-
-public :
- /**
- * Update the childs local and global coordinates
- * based upon the parents global coordinates.
- * You must also handle the case when this node has no
- * parent (parent == NULL). Usually you should just
- * copy the local coordinates of the child to the
- * world coordinates.
- */
-
- virtual
- bool
- UpdateChildCoordinates(
- SG_Spatial * child,
- const SG_Spatial * parent,
- bool& parentUpdated
- ) = 0;
-
- virtual
- ~SG_ParentRelation(
- ) {};
-
- /**
- * You must provide a way of duplicating an
- * instance of an SG_ParentRelation. This should
- * return a pointer to a new duplicate allocated
- * on the heap. Responsibility for deleting the
- * duplicate resides with the caller of this method.
- */
-
- virtual
- SG_ParentRelation *
- NewCopy(
- ) = 0;
-
- /**
- * Vertex Parent Relation are special: they don't propagate rotation
- */
- virtual
- bool
- IsVertexRelation(
- ) {
- return false;
- }
-
- /**
- * Need this to see if we are able to adjust time-offset from the python api
- */
- virtual
- bool
- IsSlowRelation(
- ) {
- return false;
- }
-protected :
-
- /**
- * Protected constructors
- * this class is not meant to be instantiated.
- */
-
- SG_ParentRelation(
- ) {
- };
-
- /**
- * Copy construction should not be implemented
- */
-
- SG_ParentRelation(
- const SG_ParentRelation &
- );
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_ParentRelation")
-#endif
-};
-
-#endif
-
diff --git a/source/gameengine/SceneGraph/SG_QList.h b/source/gameengine/SceneGraph/SG_QList.h
deleted file mode 100644
index 663f29ebd88..00000000000
--- a/source/gameengine/SceneGraph/SG_QList.h
+++ /dev/null
@@ -1,164 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_QList.h
- * \ingroup bgesg
- */
-
-#ifndef __SG_QLIST_H__
-#define __SG_QLIST_H__
-
-#include "SG_DList.h"
-
-/**
- * Double-Double circular linked list
- * For storing an object is two lists simultaneously
- */
-class SG_QList : public SG_DList
-{
-protected :
- SG_QList* m_fqlink;
- SG_QList* m_bqlink;
-
-public:
- template<typename T> class iterator
- {
- private:
- SG_QList& m_head;
- T* m_current;
- public:
- typedef iterator<T> _myT;
- iterator(SG_QList& head, SG_QList* current=NULL) : m_head(head) { m_current = (T*)current; }
- ~iterator() {}
-
- void begin()
- {
- m_current = (T*)m_head.QPeek();
- }
- void back()
- {
- m_current = (T*)m_head.QBack();
- }
- bool end()
- {
- return (m_current == (T*)m_head.Self());
- }
- bool add_back(T* item)
- {
- return m_current->QAddBack(item);
- }
- T* operator*()
- {
- return m_current;
- }
- _myT& operator++()
- {
- m_current = (T*)m_current->QPeek();
- return *this;
- }
- _myT& operator--()
- {
- // no check on NULL! make sure you don't try to increment beyond end
- m_current = (T*)m_current->QBack();
- return *this;
- }
- };
-
- SG_QList() : SG_DList()
- {
- m_fqlink = m_bqlink = this;
- }
- SG_QList(const SG_QList& other) : SG_DList()
- {
- m_fqlink = m_bqlink = this;
- }
- virtual ~SG_QList()
- {
- QDelink();
- }
-
- inline bool QEmpty() // Check for empty queue
- {
- return ( m_fqlink == this );
- }
- bool QAddBack( SG_QList *item ) // Add to the back
- {
- if (!item->QEmpty())
- return false;
- item->m_bqlink = m_bqlink;
- item->m_fqlink = this;
- m_bqlink->m_fqlink = item;
- m_bqlink = item;
- return true;
- }
- bool QAddFront( SG_QList *item ) // Add to the back
- {
- if (!item->Empty())
- return false;
- item->m_fqlink = m_fqlink;
- item->m_bqlink = this;
- m_fqlink->m_bqlink = item;
- m_fqlink = item;
- return true;
- }
- SG_QList *QRemove() // Remove from the front
- {
- if (QEmpty())
- {
- return NULL;
- }
- SG_QList* item = m_fqlink;
- m_fqlink = item->m_fqlink;
- m_fqlink->m_bqlink = this;
- item->m_fqlink = item->m_bqlink = item;
- return item;
- }
- bool QDelink() // Remove from the middle
- {
- if (QEmpty())
- return false;
- m_bqlink->m_fqlink = m_fqlink;
- m_fqlink->m_bqlink = m_bqlink;
- m_fqlink = m_bqlink = this;
- return true;
- }
- inline SG_QList *QPeek() // Look at front without removing
- {
- return m_fqlink;
- }
- inline SG_QList *QBack() // Look at front without removing
- {
- return m_bqlink;
- }
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_QList")
-#endif
-};
-
-#endif /* __SG_QLIST_H__ */
diff --git a/source/gameengine/SceneGraph/SG_Spatial.cpp b/source/gameengine/SceneGraph/SG_Spatial.cpp
deleted file mode 100644
index 5cb75873237..00000000000
--- a/source/gameengine/SceneGraph/SG_Spatial.cpp
+++ /dev/null
@@ -1,217 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/SceneGraph/SG_Spatial.cpp
- * \ingroup bgesg
- */
-
-
-#include "SG_Node.h"
-#include "SG_Spatial.h"
-#include "SG_Controller.h"
-#include "SG_ParentRelation.h"
-
-SG_Spatial::
-SG_Spatial(
- void* clientobj,
- void* clientinfo,
- SG_Callbacks& callbacks
-):
-
- SG_IObject(clientobj,clientinfo,callbacks),
- m_localPosition(0.0f,0.0f,0.0f),
- m_localRotation(1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f),
- m_localScaling(1.0f,1.0f,1.0f),
-
- m_worldPosition(0.0f,0.0f,0.0f),
- m_worldRotation(1.0f,0.0f,0.0f,0.0f,1.0f,0.0f,0.0f,0.0f,1.0f),
- m_worldScaling(1.0f,1.0f,1.0f),
-
- m_parent_relation (NULL),
-
- m_bbox(MT_Point3(-1.0f, -1.0f, -1.0f), MT_Point3(1.0f, 1.0f, 1.0f)),
- m_radius(1.0f),
- m_modified(false),
- m_ogldirty(false)
-{
-}
-
-SG_Spatial::
-SG_Spatial(
- const SG_Spatial& other
-) :
- SG_IObject(other),
- m_localPosition(other.m_localPosition),
- m_localRotation(other.m_localRotation),
- m_localScaling(other.m_localScaling),
-
- m_worldPosition(other.m_worldPosition),
- m_worldRotation(other.m_worldRotation),
- m_worldScaling(other.m_worldScaling),
-
- m_parent_relation(NULL),
-
- m_bbox(other.m_bbox),
- m_radius(other.m_radius),
- m_modified(false),
- m_ogldirty(false)
-{
- // duplicate the parent relation for this object
- m_parent_relation = other.m_parent_relation->NewCopy();
-}
-
-SG_Spatial::
-~SG_Spatial()
-{
- delete (m_parent_relation);
-}
-
- void
-SG_Spatial::
-SetParentRelation(
- SG_ParentRelation *relation
-) {
- delete (m_parent_relation);
- m_parent_relation = relation;
- SetModified();
-}
-
-
-/**
- * Update Spatial Data.
- * Calculates WorldTransform., (either doing its self or using the linked SGControllers)
- */
-
-
- bool
-SG_Spatial::
-UpdateSpatialData(
- const SG_Spatial *parent,
- double time,
- bool& parentUpdated)
-{
- bool bComputesWorldTransform = false;
-
- // update spatial controllers
-
- SGControllerList::iterator cit = GetSGControllerList().begin();
- SGControllerList::const_iterator c_end = GetSGControllerList().end();
-
- for (;cit!=c_end;++cit)
- {
- if ((*cit)->Update(time))
- bComputesWorldTransform = true;
- }
-
- // If none of the objects updated our values then we ask the
- // parent_relation object owned by this class to update
- // our world coordinates.
-
- if (!bComputesWorldTransform)
- bComputesWorldTransform = ComputeWorldTransforms(parent, parentUpdated);
-
- return bComputesWorldTransform;
-}
-
-/**
- * Position and translation methods
- */
-
-
- void
-SG_Spatial::
-RelativeTranslate(
- const MT_Vector3& trans,
- const SG_Spatial *parent,
- bool local
-) {
- if (local) {
- m_localPosition += m_localRotation * trans;
- }
- else {
- if (parent) {
- m_localPosition += trans * parent->GetWorldOrientation();
- }
- else {
- m_localPosition += trans;
- }
- }
- SetModified();
-}
-
-
-/**
- * Scaling methods.
- */
-
-
-/**
- * Orientation and rotation methods.
- */
-
-
- void
-SG_Spatial::
-RelativeRotate(
- const MT_Matrix3x3& rot,
- bool local
-) {
- m_localRotation = m_localRotation * (
- local ?
- rot
- :
- (GetWorldOrientation().inverse() * rot * GetWorldOrientation()));
- SetModified();
-}
-
-
-
-MT_Transform SG_Spatial::GetWorldTransform() const
-{
- return MT_Transform(m_worldPosition,
- m_worldRotation.scaled(
- m_worldScaling[0], m_worldScaling[1], m_worldScaling[2]));
-}
-
-bool SG_Spatial::inside(const MT_Point3 &point) const
-{
- MT_Scalar radius = m_worldScaling[m_worldScaling.closestAxis()]*m_radius;
- return (m_worldPosition.distance2(point) <= radius*radius) ?
- m_bbox.transform(GetWorldTransform()).inside(point) :
- false;
-}
-
-void SG_Spatial::getBBox(MT_Point3 *box) const
-{
- m_bbox.get(box, GetWorldTransform());
-}
-
-void SG_Spatial::getAABBox(MT_Point3 *box) const
-{
- m_bbox.getaa(box, GetWorldTransform());
-}
-
diff --git a/source/gameengine/SceneGraph/SG_Spatial.h b/source/gameengine/SceneGraph/SG_Spatial.h
deleted file mode 100644
index aa917fa70db..00000000000
--- a/source/gameengine/SceneGraph/SG_Spatial.h
+++ /dev/null
@@ -1,294 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_Spatial.h
- * \ingroup bgesg
- */
-
-#ifndef __SG_SPATIAL_H__
-#define __SG_SPATIAL_H__
-
-#include <MT_Vector3.h>
-#include <MT_Point3.h>
-#include <MT_Matrix3x3.h> // or Quaternion later ?
-#include "SG_IObject.h"
-#include "SG_BBox.h"
-#include "SG_ParentRelation.h"
-
-
-class SG_Node;
-class SG_ParentRelation;
-
-/**
- * SG_Spatial contains spatial information (local & world position, rotation
- * and scaling) for a Scene graph node.
- * It also contains a link to the node's parent.
- */
-class SG_Spatial : public SG_IObject
-{
-
-protected:
- MT_Point3 m_localPosition;
- MT_Matrix3x3 m_localRotation;
- MT_Vector3 m_localScaling;
-
- MT_Point3 m_worldPosition;
- MT_Matrix3x3 m_worldRotation;
- MT_Vector3 m_worldScaling;
-
- SG_ParentRelation * m_parent_relation;
-
- SG_BBox m_bbox;
- MT_Scalar m_radius;
- bool m_modified;
- bool m_ogldirty; // true if the openGL matrix for this object must be recomputed
-
-public:
- inline void ClearModified()
- {
- m_modified = false;
- m_ogldirty = true;
- }
- inline void SetModified()
- {
- m_modified = true;
- ActivateScheduleUpdateCallback();
- }
- inline void ClearDirty()
- {
- m_ogldirty = false;
- }
- /**
- * Define the relationship this node has with it's parent
- * node. You should pass an unshared instance of an SG_ParentRelation
- * allocated on the heap to this method. Ownership of this
- * instance is assumed by this class.
- * You may call this function several times in the lifetime
- * of a node to change the relationship dynamically.
- * You must call this method before the first call to UpdateSpatialData().
- * An assertion will be fired at run-time in debug if this is not
- * the case.
- * The relation is activated only if no controllers of this object
- * updated the coordinates of the child.
- */
-
- void
- SetParentRelation(
- SG_ParentRelation *relation
- );
-
- SG_ParentRelation * GetParentRelation()
- {
- return m_parent_relation;
- }
-
-
-
-
- /**
- * Apply a translation relative to the current position.
- * if local then the translation is assumed to be in the
- * local coordinates of this object. If not then the translation
- * is assumed to be in global coordinates. In this case
- * you must provide a pointer to the parent of this object if it
- * exists otherwise if there is no parent set it to NULL
- */
-
- void
- RelativeTranslate(
- const MT_Vector3& trans,
- const SG_Spatial *parent,
- bool local
- );
-
- void SetLocalPosition(const MT_Point3& trans)
- {
- m_localPosition = trans;
- SetModified();
- }
-
- void SetWorldPosition(const MT_Point3& trans)
- {
- m_worldPosition = trans;
- }
-
-
- void
- RelativeRotate(
- const MT_Matrix3x3& rot,
- bool local
- );
-
- void SetLocalOrientation(const MT_Matrix3x3& rot)
- {
- m_localRotation = rot;
- SetModified();
- }
-
- // rot is arrange like openGL matrix
- void SetLocalOrientation(const float* rot)
- {
- m_localRotation.setValue(rot);
- SetModified();
- }
-
- void SetWorldOrientation(const MT_Matrix3x3& rot)
- {
- m_worldRotation = rot;
- }
-
- void RelativeScale(const MT_Vector3& scale)
- {
- m_localScaling = m_localScaling * scale;
- SetModified();
- }
-
- void SetLocalScale(const MT_Vector3& scale)
- {
- m_localScaling = scale;
- SetModified();
- }
-
- void SetWorldScale(const MT_Vector3& scale)
- {
- m_worldScaling = scale;
- }
-
- const MT_Point3& GetLocalPosition() const
- {
- return m_localPosition;
- }
-
- const MT_Matrix3x3& GetLocalOrientation() const
- {
- return m_localRotation;
- }
-
- const MT_Vector3& GetLocalScale() const
- {
- return m_localScaling;
- }
-
- const MT_Point3& GetWorldPosition() const
- {
- return m_worldPosition;
- }
-
- const MT_Matrix3x3& GetWorldOrientation() const
- {
- return m_worldRotation;
- }
-
- const MT_Vector3& GetWorldScaling() const
- {
- return m_worldScaling;
- }
-
- void SetWorldFromLocalTransform()
- {
- m_worldPosition= m_localPosition;
- m_worldScaling= m_localScaling;
- m_worldRotation= m_localRotation;
- }
-
-
-
- MT_Transform GetWorldTransform() const;
-
- bool ComputeWorldTransforms(const SG_Spatial *parent, bool& parentUpdated)
- {
- return m_parent_relation->UpdateChildCoordinates(this,parent,parentUpdated);
- }
-
-
- /**
- * Bounding box functions.
- */
- SG_BBox& BBox()
- {
- return m_bbox;
- }
-
- void SetBBox(SG_BBox& bbox)
- {
- m_bbox = bbox;
- }
-
-
- bool inside(const MT_Point3 &point) const;
- void getBBox(MT_Point3 *box) const;
- void getAABBox(MT_Point3 *box) const;
-
- MT_Scalar Radius() const { return m_radius; }
- void SetRadius(MT_Scalar radius) { m_radius = radius; }
- bool IsModified() { return m_modified; }
- bool IsDirty() { return m_ogldirty; }
-
-protected:
- friend class SG_Controller;
- friend class KX_BoneParentRelation;
- friend class KX_VertexParentRelation;
- friend class KX_SlowParentRelation;
- friend class KX_NormalParentRelation;
-
- /**
- * Protected constructor this class is not
- * designed for direct instantiation
- */
-
- SG_Spatial(
- void* clientobj,
- void* clientinfo,
- SG_Callbacks& callbacks
- );
-
- SG_Spatial(
- const SG_Spatial& other
- );
-
-
- virtual ~SG_Spatial();
-
- /**
- * Update the world coordinates of this spatial node. This also informs
- * any controllers to update this object.
- */
-
- bool
- UpdateSpatialData(
- const SG_Spatial *parent,
- double time,
- bool& parentUpdated
- );
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_Spatial")
-#endif
-};
-
-#endif /* __SG_SPATIAL_H__ */
diff --git a/source/gameengine/SceneGraph/SG_Tree.cpp b/source/gameengine/SceneGraph/SG_Tree.cpp
deleted file mode 100644
index 87feb2c012a..00000000000
--- a/source/gameengine/SceneGraph/SG_Tree.cpp
+++ /dev/null
@@ -1,422 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- * Bounding Box
- */
-
-/** \file gameengine/SceneGraph/SG_Tree.cpp
- * \ingroup bgesg
- */
-
-
-#include <math.h>
-
-#include "SG_BBox.h"
-#include "SG_Tree.h"
-#include "SG_Node.h"
-
-SG_Tree::SG_Tree() :
- m_left(NULL),
- m_right(NULL),
- m_parent(NULL),
- m_radius(0.0f),
- m_client_object(NULL)
-{
-}
-
-SG_Tree::SG_Tree(SG_Tree* left, SG_Tree* right) :
- m_left(left),
- m_right(right),
- m_parent(NULL),
- m_client_object(NULL)
-{
- if (m_left)
- {
- m_bbox = m_left->m_bbox;
- m_left->m_parent = this;
- }
- if (m_right)
- {
- m_bbox += m_right->m_bbox;
- m_right->m_parent = this;
- }
- m_center = (m_bbox.m_min + m_bbox.m_max)/2.0f;
- m_radius = (m_bbox.m_max - m_bbox.m_min).length();
-}
-
-SG_Tree::SG_Tree(SG_Node* client) :
- m_left(NULL),
- m_right(NULL),
- m_parent(NULL),
- m_client_object(client)
-{
- m_bbox = SG_BBox(client->BBox(), client->GetWorldTransform());
- m_center = (m_bbox.m_min + m_bbox.m_max)/2.0f;
- m_radius = (m_bbox.m_max - m_bbox.m_min).length();
-}
-
-SG_Tree::~SG_Tree()
-{
-}
-
-MT_Scalar SG_Tree::volume() const
-{
- return m_bbox.volume();
-}
-
-void SG_Tree::dump() const
-{
- if (m_left)
- m_left->dump();
- if (m_client_object)
- std::cout << m_client_object << std::endl;
- else
- std::cout << this << " ";
- if (m_right)
- m_right->dump();
-}
-
-SG_Tree* SG_Tree::Left() const
-{
- return m_left;
-}
-
-SG_Tree* SG_Tree::Right() const
-{
- return m_right;
-}
-
-SG_Node* SG_Tree::Client() const
-{
- return m_client_object;
-}
-
-SG_Tree* SG_Tree::Find(SG_Node *node)
-{
- if (m_client_object == node)
- return this;
-
- SG_Tree *left = m_left, *right = m_right;
-
- if (left && right)
- {
- if (right->m_bbox.intersects(node->BBox()))
- std::swap(left, right);
- }
-
- if (left)
- {
- SG_Tree* ret = left->Find(node);
- if (ret) return ret;
- }
-
- if (right)
- {
- SG_Tree* ret = right->Find(node);
- if (ret) return ret;
- }
-
- return NULL;
-}
-
-void SG_Tree::get(MT_Point3 *box) const
-{
- MT_Transform identity;
- identity.setIdentity();
- m_bbox.get(box, identity);
-}
-
-bool SG_Tree::inside(const MT_Point3 &point) const
-{
- return m_bbox.inside(point);
-}
-
-const SG_BBox& SG_Tree::BBox() const
-{
- return m_bbox;
-}
-
-void SG_Tree::SetLeft(SG_Tree *left)
-{
- m_left = left;
- m_bbox += left->m_bbox;
- m_center = (m_bbox.m_min + m_bbox.m_max)/2.0f;
- m_radius = (m_bbox.m_max - m_bbox.m_min).length();
-}
-
-void SG_Tree::SetRight(SG_Tree *right)
-{
- m_right = right;
- m_bbox += right->m_bbox;
- m_center = (m_bbox.m_min + m_bbox.m_max)/2.0f;
- m_radius = (m_bbox.m_max - m_bbox.m_min).length();
-}
-
-/**
- * A Half array is a square 2d array where cell(x, y) is undefined
- * if x < y.
- */
-template<typename T>
-class HalfArray
-{
- std::vector<std::vector<T> > m_array;
-public:
- HalfArray() {}
- ~HalfArray() {}
-
- void resize(unsigned int size)
- {
- m_array.resize(size);
- for ( unsigned int i = 0; i < size; i++)
- {
- m_array[i].resize(size - i);
- }
- }
-
- T& operator() (unsigned int x, unsigned int y)
- {
- assert(x >= y);
- return m_array[y][x - y];
- }
-
- void erase_column (unsigned int x)
- {
- for (unsigned int y = 0; y <= x; y++)
- m_array[y].erase(m_array[y].begin() + x - y);
- }
-
- void delete_column (unsigned int x)
- {
- for (unsigned int y = 0; y < x; y++)
- {
- delete m_array[y][x - y];
- m_array[y].erase(m_array[y].begin() + x - y);
- }
- }
-
- void erase_row (unsigned int y)
- {
- m_array.erase(m_array.begin() + y);
- }
-};
-
-SG_TreeFactory::SG_TreeFactory()
-{
-}
-
-SG_TreeFactory::~SG_TreeFactory()
-{
-}
-
-void SG_TreeFactory::Add(SG_Node* client)
-{
- if (client)
- m_objects.insert(new SG_Tree(client));
-}
-
-void SG_TreeFactory::Add(SG_Tree* tree)
-{
- m_objects.insert(tree);
-}
-
-SG_Tree* SG_TreeFactory::MakeTreeDown(SG_BBox &bbox)
-{
- if (m_objects.empty())
- return NULL;
- if (m_objects.size() == 1)
- return *m_objects.begin();
-
- TreeSet::iterator it = m_objects.begin();
- SG_Tree *root = *it;
- if (m_objects.size() == 2)
- {
- root->SetRight(*(++it));
- return root;
- }
-
- if (m_objects.size() == 3)
- {
- root->SetLeft(*(++it));
- root->SetRight(*(++it));
- return root;
- }
-
- if (bbox.volume() < 1.0f)
- return MakeTreeUp();
-
- SG_TreeFactory lefttree;
- SG_TreeFactory righttree;
-
- SG_BBox left, right;
- int hasleft = 0, hasright = 0;
- bbox.split(left, right);
-
- if (left.test(root->BBox()) == SG_BBox::INSIDE)
- {
- lefttree.Add(root);
- root = NULL;
- }
-
- if (root && right.test(root->BBox()) == SG_BBox::INSIDE)
- {
- righttree.Add(root);
- root = NULL;
- }
-
- for (++it; it != m_objects.end(); ++it)
- {
- switch (left.test((*it)->BBox()))
- {
- case SG_BBox::INSIDE:
- // Object is inside left tree;
- lefttree.Add(*it);
- hasleft++;
- break;
- case SG_BBox::OUTSIDE:
- righttree.Add(*it);
- hasright++;
- break;
- case SG_BBox::INTERSECT:
- if (left.inside((*it)->Client()->GetWorldPosition()))
- {
- lefttree.Add(*it);
- hasleft++;
- }
- else {
- righttree.Add(*it);
- hasright++;
- }
- break;
- }
- }
- std::cout << "Left: " << hasleft << " Right: " << hasright << " Count: " << m_objects.size() << std::endl;
-
- SG_Tree *leftnode = NULL;
- if (hasleft)
- leftnode = lefttree.MakeTreeDown(left);
-
- SG_Tree *rightnode = NULL;
- if (hasright)
- rightnode = righttree.MakeTreeDown(right);
-
- if (!root)
- root = new SG_Tree(leftnode, rightnode);
- else
- {
- if (leftnode)
- root->SetLeft(leftnode);
- if (rightnode)
- root->SetRight(rightnode);
- }
-
- return root;
-}
-
-SG_Tree* SG_TreeFactory::MakeTree()
-{
- if (m_objects.size() < 8)
- return MakeTreeUp();
-
- TreeSet::iterator it = m_objects.begin();
- SG_BBox bbox((*it)->BBox());
- for (++it; it != m_objects.end(); ++it)
- bbox += (*it)->BBox();
-
- return MakeTreeDown(bbox);
-}
-
-SG_Tree* SG_TreeFactory::MakeTreeUp()
-{
- unsigned int num_objects = m_objects.size();
-
- if (num_objects < 1)
- return NULL;
- if (num_objects < 2)
- return *m_objects.begin();
-
- HalfArray<SG_Tree*> sizes;
- sizes.resize(num_objects);
-
- unsigned int x, y;
- TreeSet::iterator xit, yit;
- for ( y = 0, yit = m_objects.begin(); y < num_objects; y++, ++yit)
- {
- sizes(y, y) = *yit;
- xit = yit;
- for ( x = y+1, ++xit; x < num_objects; x++, ++xit)
- {
- sizes(x, y) = new SG_Tree(*xit, *yit);
-
- }
- }
- while (num_objects > 2)
- {
- /* Find the pair of bboxes that produce the smallest combined bbox. */
- unsigned int minx = UINT_MAX, miny = UINT_MAX;
- MT_Scalar min_volume = FLT_MAX;
- SG_Tree *min = NULL;
- //char temp[16];
- for ( y = 0; y < num_objects; y++)
- {
- for ( x = y+1; x < num_objects; x++)
- {
- if (sizes(x, y)->volume() < min_volume)
- {
- min = sizes(x, y);
- minx = x;
- miny = y;
- min_volume = sizes(x, y)->volume();
- }
- }
- }
-
- /* Remove other bboxes that contain the two bboxes */
- sizes.delete_column(miny);
-
- for ( x = miny + 1; x < num_objects; x++)
- {
- if (x == minx)
- continue;
- delete sizes(x, miny);
- }
- sizes.erase_row(miny);
-
- num_objects--;
- minx--;
- sizes(minx, minx) = min;
- for ( x = minx + 1; x < num_objects; x++)
- {
- delete sizes(x, minx);
- sizes(x, minx) = new SG_Tree(min, sizes(x, x));
- }
- for ( y = 0; y < minx; y++)
- {
- delete sizes(minx, y);
- sizes(minx, y) = new SG_Tree(sizes(y, y), min);
- }
- }
- return sizes(1, 0);
-}
-
diff --git a/source/gameengine/SceneGraph/SG_Tree.h b/source/gameengine/SceneGraph/SG_Tree.h
deleted file mode 100644
index 339862c652f..00000000000
--- a/source/gameengine/SceneGraph/SG_Tree.h
+++ /dev/null
@@ -1,163 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by NaN Holding BV.
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): none yet.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file SG_Tree.h
- * \ingroup bgesg
- */
-
-#ifndef __SG_TREE_H__
-#define __SG_TREE_H__
-
-#include "MT_Point3.h"
-#include "SG_BBox.h"
-
-#include <set>
-
-class SG_Node;
-
-
-/**
- * SG_Tree.
- * Holds a binary tree of SG_Nodes.
- */
-class SG_Tree
-{
- SG_Tree* m_left;
- SG_Tree* m_right;
- SG_Tree* m_parent;
- SG_BBox m_bbox;
- MT_Point3 m_center;
- MT_Scalar m_radius;
- SG_Node* m_client_object;
-public:
- SG_Tree();
- SG_Tree(SG_Tree* left, SG_Tree* right);
-
- SG_Tree(SG_Node* client);
- ~SG_Tree();
-
- /**
- * Computes the volume of the bounding box.
- */
- MT_Scalar volume() const;
-
- /**
- * Prints the tree (for debugging.)
- */
- void dump() const;
-
- /**
- * Returns the left node.
- */
- SG_Tree *Left() const;
- SG_Tree *Right() const;
- SG_Node *Client() const;
-
- SG_Tree* Find(SG_Node *node);
- /**
- * Gets the eight corners of this treenode's bounding box,
- * in world coordinates.
- * \param box: an array of 8 MT_Point3
- * \example MT_Point3 box[8];
- * treenode->get(box);
- */
- void get(MT_Point3 *box) const;
- /**
- * Get the tree node's bounding box.
- */
- const SG_BBox& BBox() const;
-
- /**
- * Test if the given bounding box is inside this bounding box.
- */
- bool inside(const MT_Point3 &point) const;
-
- void SetLeft(SG_Tree *left);
- void SetRight(SG_Tree *right);
-
- MT_Point3 Center() const { return m_center; }
- MT_Scalar Radius() { return m_radius; }
-
- //friend class SG_TreeFactory;
-
- struct greater
- {
- bool operator()(const SG_Tree *a, const SG_Tree *b)
- {
- return a->volume() > b->volume();
- }
- };
-
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_Tree")
-#endif
-};
-
-
-/**
- * SG_TreeFactory generates an SG_Tree from a list of SG_Nodes.
- * It joins pairs of SG_Nodes to minimize the size of the resultant
- * bounding box.
- * cf building an optimized Huffman tree.
- * \warning O(n^3)!!!
- */
-class SG_TreeFactory
-{
- typedef std::multiset<SG_Tree*, SG_Tree::greater> TreeSet;
- TreeSet m_objects;
-public:
- SG_TreeFactory();
- ~SG_TreeFactory();
-
- /**
- * Add a node to be added to the tree.
- */
- void Add(SG_Node* client);
- void Add(SG_Tree* tree);
-
- /**
- * Build the tree from the set of nodes added by
- * the Add method.
- */
- SG_Tree* MakeTreeUp();
-
- /**
- * Build the tree from the set of nodes top down.
- */
- SG_Tree* MakeTreeDown(SG_BBox &bbox);
-
- SG_Tree* MakeTree();
-
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:SG_TreeFactory")
-#endif
-};
-
-#endif /* __SG_BBOX_H__ */
diff --git a/source/gameengine/VideoTexture/BlendType.h b/source/gameengine/VideoTexture/BlendType.h
deleted file mode 100644
index 561c6e8768f..00000000000
--- a/source/gameengine/VideoTexture/BlendType.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2006 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file BlendType.h
- * \ingroup bgevideotex
- */
-
-#ifndef __BLENDTYPE_H__
-#define __BLENDTYPE_H__
-
-
-/// class allows check type of blender python object and access its contained object
-/// MUST ONLY BE USED FOR KX classes that are descendent of PyObjectPlus
-template <class PyObj> class BlendType
-{
-public:
- /// constructor
- BlendType (const char * name) : m_name(name), m_objType(NULL) {}
-
- /// check blender type and return pointer to contained object or NULL (if type is not valid)
- PyObj *checkType(PyObject *obj)
- {
- // if pointer to type isn't set
- if (m_objType == NULL)
- {
- // compare names of type
- if (strcmp(Py_TYPE(obj)->tp_name, m_name) == 0)
- // if name of type match, save pointer to type
- m_objType = Py_TYPE(obj);
- else
- // if names of type don't match, return NULL
- return NULL;
- }
- // if pointer to type is set and don't match to type of provided object, return NULL
- else if (Py_TYPE(obj) != m_objType)
- return NULL;
- // return pointer to object, this class can only be used for KX object =>
- // the Py object is actually a proxy
- return (PyObj *)BGE_PROXY_REF(obj);
- }
-
- /// parse arguments to get object
- PyObj *parseArg(PyObject *args)
- {
- // parse arguments
- PyObject *obj;
- if (PyArg_ParseTuple(args, "O", &obj)) {
- // if successfully parsed, return pointer to object
- return checkType(obj);
- }
- // otherwise return NULL
- return NULL;
- }
-
-protected:
- /// name of Python type
- const char * m_name;
- /// pointer to Python type
- PyTypeObject *m_objType;
-};
-
-
-#endif
diff --git a/source/gameengine/VideoTexture/CMakeLists.txt b/source/gameengine/VideoTexture/CMakeLists.txt
deleted file mode 100644
index 1eb09b02e05..00000000000
--- a/source/gameengine/VideoTexture/CMakeLists.txt
+++ /dev/null
@@ -1,119 +0,0 @@
-# ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
-#
-# The Original Code is Copyright (C) 2006, Blender Foundation
-# All rights reserved.
-#
-# The Original Code is: all of this file.
-#
-# Contributor(s): Jacques Beaurain.
-#
-# ***** END GPL LICENSE BLOCK *****
-
-set(INC
- .
- ../BlenderRoutines
- ../Expressions
- ../GameLogic
- ../Ketsji
- ../Rasterizer
- ../Rasterizer/RAS_OpenGLRasterizer
- ../SceneGraph
- ../../blender/blenkernel
- ../../blender/blenlib
- ../../blender/editors/include
- ../../blender/gpu
- ../../blender/imbuf
- ../../blender/makesdna
- ../../blender/python
- ../../blender/python/generic
- ../../../intern/container
- ../../../intern/ffmpeg
- ../../../intern/glew-mx
- ../../../intern/guardedalloc
- ../../../intern/string
- ../../../intern/decklink
- ../../../intern/gpudirect
- ../../../intern/atomic
-)
-
-set(INC_SYS
- ../../../intern/moto/include
- ${GLEW_INCLUDE_PATH}
-)
-
-add_definitions(${GL_DEFINITIONS})
-
-set(SRC
- Exception.cpp
- FilterBase.cpp
- FilterBlueScreen.cpp
- FilterColor.cpp
- FilterNormal.cpp
- FilterSource.cpp
- ImageBase.cpp
- ImageBuff.cpp
- ImageMix.cpp
- ImageRender.cpp
- ImageViewport.cpp
- PyTypeList.cpp
- Texture.cpp
- DeckLink.cpp
- VideoBase.cpp
- VideoFFmpeg.cpp
- VideoDeckLink.cpp
- blendVideoTex.cpp
-
- BlendType.h
- Common.h
- Exception.h
- FilterBase.h
- FilterBlueScreen.h
- FilterColor.h
- FilterNormal.h
- FilterSource.h
- ImageBase.h
- ImageBuff.h
- ImageMix.h
- ImageRender.h
- ImageViewport.h
- PyTypeList.h
- Texture.h
- DeckLink.h
- VideoBase.h
- VideoFFmpeg.h
- VideoDeckLink.h
-)
-
-if(WITH_CODEC_FFMPEG)
- list(APPEND INC_SYS
- ${FFMPEG_INCLUDE_DIRS}
- ${PTHREADS_INCLUDE_DIRS}
- )
- add_definitions(-DWITH_FFMPEG)
-
- remove_strict_flags_file(
- VideoFFmpeg.cpp
- VideoDeckLink
- DeckLink
- )
-endif()
-
-if(WITH_GAMEENGINE_DECKLINK)
- add_definitions(-DWITH_GAMEENGINE_DECKLINK)
-endif()
-
-blender_add_lib(ge_videotex "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/gameengine/VideoTexture/Common.h b/source/gameengine/VideoTexture/Common.h
deleted file mode 100644
index 22ea177addc..00000000000
--- a/source/gameengine/VideoTexture/Common.h
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2006 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file VideoTexture/Common.h
- * \ingroup bgevideotex
- */
-
-#if defined WIN32
-#define WINDOWS_LEAN_AND_MEAN
-#endif
-
-#ifndef NULL
-#define NULL 0
-#endif
-
-#ifndef _HRESULT_DEFINED
-#define _HRESULT_DEFINED
-#define HRESULT long
-#endif
-
-#ifndef DWORD
-#define DWORD unsigned long
-#endif
-
-#ifndef S_OK
-#define S_OK ((HRESULT)0L)
-#endif
-
-#ifndef BYTE
-#define BYTE unsigned char
-#endif
-
-#ifndef WIN32
-#define Sleep(time) sleep(time)
-#endif
-
-#ifndef FAILED
-#define FAILED(Status) ((HRESULT)(Status)<0)
-#endif
-
-#include <iostream>
diff --git a/source/gameengine/VideoTexture/DeckLink.cpp b/source/gameengine/VideoTexture/DeckLink.cpp
deleted file mode 100644
index fa8ab8c641c..00000000000
--- a/source/gameengine/VideoTexture/DeckLink.cpp
+++ /dev/null
@@ -1,813 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/Texture.cpp
- * \ingroup bgevideotex
- */
-
-#ifdef WITH_GAMEENGINE_DECKLINK
-
-// implementation
-
-// FFmpeg defines its own version of stdint.h on Windows.
-// Decklink needs FFmpeg, so it uses its version of stdint.h
-// this is necessary for INT64_C macro
-#ifndef __STDC_CONSTANT_MACROS
-#define __STDC_CONSTANT_MACROS
-#endif
-// this is necessary for UINTPTR_MAX (used by atomic-ops)
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS
-#endif
-
-#include "atomic_ops.h"
-
-#include "EXP_PyObjectPlus.h"
-#include "KX_KetsjiEngine.h"
-#include "KX_PythonInit.h"
-#include "DeckLink.h"
-
-#include <memory.h>
-
-// macro for exception handling and logging
-#define CATCH_EXCP catch (Exception & exp) \
-{ exp.report(); return NULL; }
-
-static struct
-{
- const char *name;
- BMDDisplayMode mode;
-} sModeStringTab[] = {
- { "NTSC", bmdModeNTSC },
- { "NTSC2398", bmdModeNTSC2398 },
- { "PAL", bmdModePAL },
- { "NTSCp", bmdModeNTSCp },
- { "PALp", bmdModePALp },
-
- /* HD 1080 Modes */
-
- { "HD1080p2398", bmdModeHD1080p2398 },
- { "HD1080p24", bmdModeHD1080p24 },
- { "HD1080p25", bmdModeHD1080p25 },
- { "HD1080p2997", bmdModeHD1080p2997 },
- { "HD1080p30", bmdModeHD1080p30 },
- { "HD1080i50", bmdModeHD1080i50 },
- { "HD1080i5994", bmdModeHD1080i5994 },
- { "HD1080i6000", bmdModeHD1080i6000 },
- { "HD1080p50", bmdModeHD1080p50 },
- { "HD1080p5994", bmdModeHD1080p5994 },
- { "HD1080p6000", bmdModeHD1080p6000 },
-
- /* HD 720 Modes */
-
- { "HD720p50", bmdModeHD720p50 },
- { "HD720p5994", bmdModeHD720p5994 },
- { "HD720p60", bmdModeHD720p60 },
-
- /* 2k Modes */
-
- { "2k2398", bmdMode2k2398 },
- { "2k24", bmdMode2k24 },
- { "2k25", bmdMode2k25 },
-
- /* DCI Modes (output only) */
-
- { "2kDCI2398", bmdMode2kDCI2398 },
- { "2kDCI24", bmdMode2kDCI24 },
- { "2kDCI25", bmdMode2kDCI25 },
-
- /* 4k Modes */
-
- { "4K2160p2398", bmdMode4K2160p2398 },
- { "4K2160p24", bmdMode4K2160p24 },
- { "4K2160p25", bmdMode4K2160p25 },
- { "4K2160p2997", bmdMode4K2160p2997 },
- { "4K2160p30", bmdMode4K2160p30 },
- { "4K2160p50", bmdMode4K2160p50 },
- { "4K2160p5994", bmdMode4K2160p5994 },
- { "4K2160p60", bmdMode4K2160p60 },
- // sentinel
- { NULL }
-};
-
-static struct
-{
- const char *name;
- BMDPixelFormat format;
-} sFormatStringTab[] = {
- { "8BitYUV", bmdFormat8BitYUV },
- { "10BitYUV", bmdFormat10BitYUV },
- { "8BitARGB", bmdFormat8BitARGB },
- { "8BitBGRA", bmdFormat8BitBGRA },
- { "10BitRGB", bmdFormat10BitRGB },
- { "12BitRGB", bmdFormat12BitRGB },
- { "12BitRGBLE", bmdFormat12BitRGBLE },
- { "10BitRGBXLE", bmdFormat10BitRGBXLE },
- { "10BitRGBX", bmdFormat10BitRGBX },
- // sentinel
- { NULL }
-};
-
-ExceptionID DeckLinkBadDisplayMode, DeckLinkBadPixelFormat;
-ExpDesc DeckLinkBadDisplayModeDesc(DeckLinkBadDisplayMode, "Invalid or unsupported display mode");
-ExpDesc DeckLinkBadPixelFormatDesc(DeckLinkBadPixelFormat, "Invalid or unsupported pixel format");
-
-HRESULT decklink_ReadDisplayMode(const char *format, size_t len, BMDDisplayMode *displayMode)
-{
- int i;
-
- if (len == 0)
- len = strlen(format);
- for (i = 0; sModeStringTab[i].name != NULL; i++) {
- if (strlen(sModeStringTab[i].name) == len &&
- !strncmp(sModeStringTab[i].name, format, len))
- {
- *displayMode = sModeStringTab[i].mode;
- return S_OK;
- }
- }
- if (len != 4)
- THRWEXCP(DeckLinkBadDisplayMode, S_OK);
- // assume the user entered directly the mode value as a 4 char string
- *displayMode = (BMDDisplayMode)((((uint32_t)format[0]) << 24) + (((uint32_t)format[1]) << 16) + (((uint32_t)format[2]) << 8) + ((uint32_t)format[3]));
- return S_OK;
-}
-
-HRESULT decklink_ReadPixelFormat(const char *format, size_t len, BMDPixelFormat *pixelFormat)
-{
- int i;
-
- if (!len)
- len = strlen(format);
- for (i = 0; sFormatStringTab[i].name != NULL; i++) {
- if (strlen(sFormatStringTab[i].name) == len &&
- !strncmp(sFormatStringTab[i].name, format, len))
- {
- *pixelFormat = sFormatStringTab[i].format;
- return S_OK;
- }
- }
- if (len != 4)
- THRWEXCP(DeckLinkBadPixelFormat, S_OK);
- // assume the user entered directly the mode value as a 4 char string
- *pixelFormat = (BMDPixelFormat)((((uint32_t)format[0]) << 24) + (((uint32_t)format[1]) << 16) + (((uint32_t)format[2]) << 8) + ((uint32_t)format[3]));
- return S_OK;
-}
-
-class DeckLink3DFrameWrapper : public IDeckLinkVideoFrame, IDeckLinkVideoFrame3DExtensions
-{
-public:
- // IUnknown
- virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv)
- {
- if (!memcmp(&iid, &IID_IDeckLinkVideoFrame3DExtensions, sizeof(iid))) {
- if (mpRightEye) {
- *ppv = (IDeckLinkVideoFrame3DExtensions*)this;
- return S_OK;
- }
- }
- return E_NOTIMPL;
- }
- virtual ULONG STDMETHODCALLTYPE AddRef(void) { return 1U; }
- virtual ULONG STDMETHODCALLTYPE Release(void) { return 1U; }
- // IDeckLinkVideoFrame
- virtual long STDMETHODCALLTYPE GetWidth(void) { return mpLeftEye->GetWidth(); }
- virtual long STDMETHODCALLTYPE GetHeight(void) { return mpLeftEye->GetHeight(); }
- virtual long STDMETHODCALLTYPE GetRowBytes(void) { return mpLeftEye->GetRowBytes(); }
- virtual BMDPixelFormat STDMETHODCALLTYPE GetPixelFormat(void) { return mpLeftEye->GetPixelFormat(); }
- virtual BMDFrameFlags STDMETHODCALLTYPE GetFlags(void) { return mpLeftEye->GetFlags(); }
- virtual HRESULT STDMETHODCALLTYPE GetBytes(void **buffer) { return mpLeftEye->GetBytes(buffer); }
- virtual HRESULT STDMETHODCALLTYPE GetTimecode(BMDTimecodeFormat format,IDeckLinkTimecode **timecode)
- { return mpLeftEye->GetTimecode(format, timecode); }
- virtual HRESULT STDMETHODCALLTYPE GetAncillaryData(IDeckLinkVideoFrameAncillary **ancillary)
- { return mpLeftEye->GetAncillaryData(ancillary); }
- // IDeckLinkVideoFrame3DExtensions
- virtual BMDVideo3DPackingFormat STDMETHODCALLTYPE Get3DPackingFormat(void)
- {
- return bmdVideo3DPackingLeftOnly;
- }
- virtual HRESULT STDMETHODCALLTYPE GetFrameForRightEye(
- /* [out] */ IDeckLinkVideoFrame **rightEyeFrame)
- {
- mpRightEye->AddRef();
- *rightEyeFrame = mpRightEye;
- return S_OK;
- }
- // Constructor
- DeckLink3DFrameWrapper(IDeckLinkVideoFrame *leftEye, IDeckLinkVideoFrame *rightEye)
- {
- mpLeftEye = leftEye;
- mpRightEye = rightEye;
- }
- // no need for a destructor, it's just a wrapper
-private:
- IDeckLinkVideoFrame *mpLeftEye;
- IDeckLinkVideoFrame *mpRightEye;
-};
-
-static void decklink_Reset(DeckLink *self)
-{
- self->m_lastClock = 0.0;
- self->mDLOutput = NULL;
- self->mUse3D = false;
- self->mDisplayMode = bmdModeUnknown;
- self->mKeyingSupported = false;
- self->mHDKeyingSupported = false;
- self->mSize[0] = 0;
- self->mSize[1] = 0;
- self->mFrameSize = 0;
- self->mLeftFrame = NULL;
- self->mRightFrame = NULL;
- self->mKeyer = NULL;
- self->mUseKeying = false;
- self->mKeyingLevel = 255;
- self->mUseExtend = false;
-}
-
-#ifdef __BIG_ENDIAN__
-#define CONV_PIXEL(i) ((((i)>>16)&0xFF00)+(((i)&0xFF00)<<16)+((i)&0xFF00FF))
-#else
-#define CONV_PIXEL(i) ((((i)&0xFF)<<16)+(((i)>>16)&0xFF)+((i)&0xFF00FF00))
-#endif
-
-// adapt the pixel format and picture size from VideoTexture (RGBA) to DeckLink (BGRA)
-static void decklink_ConvImage(uint32_t *dest, const short *destSize, const uint32_t *source, const short *srcSize, bool extend)
-{
- short w, h, x, y;
- const uint32_t *s;
- uint32_t *d, p;
- bool sameSize = (destSize[0] == srcSize[0] && destSize[1] == srcSize[1]);
-
- if (sameSize || !extend) {
- // here we convert pixel by pixel
- w = (destSize[0] < srcSize[0]) ? destSize[0] : srcSize[0];
- h = (destSize[1] < srcSize[1]) ? destSize[1] : srcSize[1];
- for (y = 0; y < h; ++y) {
- s = source + y*srcSize[0];
- d = dest + y*destSize[0];
- for (x = 0; x < w; ++x, ++s, ++d) {
- *d = CONV_PIXEL(*s);
- }
- }
- }
- else {
- // here we scale
- // interpolation accumulator
- int accHeight = srcSize[1] >> 1;
- d = dest;
- s = source;
- // process image rows
- for (y = 0; y < srcSize[1]; ++y) {
- // increase height accum
- accHeight += destSize[1];
- // if pixel row has to be drawn
- if (accHeight >= srcSize[1]) {
- // decrease accum
- accHeight -= srcSize[1];
- // width accum
- int accWidth = srcSize[0] >> 1;
- // process row
- for (x = 0; x < srcSize[0]; ++x, ++s) {
- // increase width accum
- accWidth += destSize[0];
- // convert pixel
- p = CONV_PIXEL(*s);
- // if pixel has to be drown one or more times
- while (accWidth >= srcSize[0]) {
- // decrease accum
- accWidth -= srcSize[0];
- *d++ = p;
- }
- }
- // if there should be more identical lines
- while (accHeight >= srcSize[1]) {
- accHeight -= srcSize[1];
- // copy previous line
- memcpy(d, d - destSize[0], 4 * destSize[0]);
- d += destSize[0];
- }
- }
- else {
- // if we skip a source line
- s += srcSize[0];
- }
- }
- }
-}
-
-// DeckLink object allocation
-static PyObject *DeckLink_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- // allocate object
- DeckLink * self = reinterpret_cast<DeckLink*>(type->tp_alloc(type, 0));
- // initialize object structure
- decklink_Reset(self);
- // m_leftEye is a python object, it's handled by python
- self->m_leftEye = NULL;
- self->m_rightEye = NULL;
- // return allocated object
- return reinterpret_cast<PyObject*>(self);
-}
-
-
-// forward declaration
-PyObject *DeckLink_close(DeckLink *self);
-int DeckLink_setSource(DeckLink *self, PyObject *value, void *closure);
-
-
-// DeckLink object deallocation
-static void DeckLink_dealloc(DeckLink *self)
-{
- // release renderer
- Py_XDECREF(self->m_leftEye);
- // close decklink
- PyObject *ret = DeckLink_close(self);
- Py_DECREF(ret);
- // release object
- Py_TYPE((PyObject *)self)->tp_free((PyObject *)self);
-}
-
-
-ExceptionID AutoDetectionNotAvail, DeckLinkOpenCard, DeckLinkBadFormat, DeckLinkInternalError;
-ExpDesc AutoDetectionNotAvailDesc(AutoDetectionNotAvail, "Auto detection not yet available");
-ExpDesc DeckLinkOpenCardDesc(DeckLinkOpenCard, "Cannot open card for output");
-ExpDesc DeckLinkBadFormatDesc(DeckLinkBadFormat, "Invalid or unsupported output format, use <mode>[/3D]");
-ExpDesc DeckLinkInternalErrorDesc(DeckLinkInternalError, "DeckLink API internal error, please report");
-
-// DeckLink object initialization
-static int DeckLink_init(DeckLink *self, PyObject *args, PyObject *kwds)
-{
- IDeckLinkIterator* pIterator;
- IDeckLinkAttributes* pAttributes;
- IDeckLinkDisplayModeIterator* pDisplayModeIterator;
- IDeckLinkDisplayMode* pDisplayMode;
- IDeckLink* pDL;
- char* p3D;
- BOOL flag;
- size_t len;
- int i;
- uint32_t displayFlags;
- BMDVideoOutputFlags outputFlags;
- BMDDisplayModeSupport support;
- uint32_t* bytes;
-
-
- // material ID
- short cardIdx = 0;
- // texture ID
- char *format = NULL;
-
- static const char *kwlist[] = {"cardIdx", "format", NULL};
- // get parameters
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "|hs",
- const_cast<char**>(kwlist), &cardIdx, &format))
- return -1;
-
- try {
- if (format == NULL) {
- THRWEXCP(AutoDetectionNotAvail, S_OK);
- }
-
- if ((p3D = strchr(format, '/')) != NULL && strcmp(p3D, "/3D"))
- THRWEXCP(DeckLinkBadFormat, S_OK);
- self->mUse3D = (p3D) ? true : false;
- // read the mode
- len = (p3D) ? (size_t)(p3D - format) : strlen(format);
- // throws if bad mode
- decklink_ReadDisplayMode(format, len, &self->mDisplayMode);
-
- pIterator = BMD_CreateDeckLinkIterator();
- pDL = NULL;
- if (pIterator) {
- i = 0;
- while (pIterator->Next(&pDL) == S_OK) {
- if (i == cardIdx) {
- break;
- }
- i++;
- pDL->Release();
- pDL = NULL;
- }
- pIterator->Release();
- }
-
- if (!pDL) {
- THRWEXCP(DeckLinkOpenCard, S_OK);
- }
- // detect the capabilities
- if (pDL->QueryInterface(IID_IDeckLinkAttributes, (void**)&pAttributes) == S_OK) {
- if (pAttributes->GetFlag(BMDDeckLinkSupportsInternalKeying, &flag) == S_OK && flag) {
- self->mKeyingSupported = true;
- if (pAttributes->GetFlag(BMDDeckLinkSupportsHDKeying, &flag) == S_OK && flag) {
- self->mHDKeyingSupported = true;
- }
- }
- pAttributes->Release();
- }
-
- if (pDL->QueryInterface(IID_IDeckLinkOutput, (void**)&self->mDLOutput) != S_OK) {
- self->mDLOutput = NULL;
- }
- if (self->mKeyingSupported) {
- pDL->QueryInterface(IID_IDeckLinkKeyer, (void **)&self->mKeyer);
- }
- // we don't need the device anymore, release to avoid leaking
- pDL->Release();
-
- if (!self->mDLOutput)
- THRWEXCP(DeckLinkOpenCard, S_OK);
-
- if (self->mDLOutput->GetDisplayModeIterator(&pDisplayModeIterator) != S_OK)
- THRWEXCP(DeckLinkInternalError, S_OK);
-
- displayFlags = (self->mUse3D) ? bmdDisplayModeSupports3D : 0;
- outputFlags = (self->mUse3D) ? bmdVideoOutputDualStream3D : bmdVideoOutputFlagDefault;
- pDisplayMode = NULL;
- i = 0;
- while (pDisplayModeIterator->Next(&pDisplayMode) == S_OK) {
- if (pDisplayMode->GetDisplayMode() == self->mDisplayMode
- && (pDisplayMode->GetFlags() & displayFlags) == displayFlags) {
- if (self->mDLOutput->DoesSupportVideoMode(self->mDisplayMode, bmdFormat8BitBGRA, outputFlags, &support, NULL) != S_OK ||
- support == bmdDisplayModeNotSupported)
- {
- printf("Warning: DeckLink card %d reports no BGRA support, proceed anyway\n", cardIdx);
- }
- break;
- }
- pDisplayMode->Release();
- pDisplayMode = NULL;
- i++;
- }
- pDisplayModeIterator->Release();
-
- if (!pDisplayMode)
- THRWEXCP(DeckLinkBadFormat, S_OK);
- self->mSize[0] = pDisplayMode->GetWidth();
- self->mSize[1] = pDisplayMode->GetHeight();
- self->mFrameSize = 4*self->mSize[0]*self->mSize[1];
- pDisplayMode->Release();
- if (self->mDLOutput->EnableVideoOutput(self->mDisplayMode, outputFlags) != S_OK)
- // this shouldn't fail
- THRWEXCP(DeckLinkOpenCard, S_OK);
-
- if (self->mDLOutput->CreateVideoFrame(self->mSize[0], self->mSize[1], self->mSize[0] * 4, bmdFormat8BitBGRA, bmdFrameFlagFlipVertical, &self->mLeftFrame) != S_OK)
- THRWEXCP(DeckLinkInternalError, S_OK);
- // clear alpha channel in the frame buffer
- self->mLeftFrame->GetBytes((void **)&bytes);
- memset(bytes, 0, self->mFrameSize);
- if (self->mUse3D) {
- if (self->mDLOutput->CreateVideoFrame(self->mSize[0], self->mSize[1], self->mSize[0] * 4, bmdFormat8BitBGRA, bmdFrameFlagFlipVertical, &self->mRightFrame) != S_OK)
- THRWEXCP(DeckLinkInternalError, S_OK);
- // clear alpha channel in the frame buffer
- self->mRightFrame->GetBytes((void **)&bytes);
- memset(bytes, 0, self->mFrameSize);
- }
- }
- catch (Exception & exp)
- {
- printf("DeckLink: exception when opening card %d: %s\n", cardIdx, exp.what());
- exp.report();
- // normally, the object should be deallocated
- return -1;
- }
- // initialization succeeded
- return 0;
-}
-
-
-// close added decklink
-PyObject *DeckLink_close(DeckLink * self)
-{
- if (self->mLeftFrame)
- self->mLeftFrame->Release();
- if (self->mRightFrame)
- self->mRightFrame->Release();
- if (self->mKeyer)
- self->mKeyer->Release();
- if (self->mDLOutput)
- self->mDLOutput->Release();
- decklink_Reset(self);
- Py_RETURN_NONE;
-}
-
-
-// refresh decklink key frame
-static PyObject *DeckLink_refresh(DeckLink *self, PyObject *args)
-{
- // get parameter - refresh source
- PyObject *param;
- double ts = -1.0;
-
- if (!PyArg_ParseTuple(args, "O|d:refresh", &param, &ts) || !PyBool_Check(param)) {
- // report error
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return NULL;
- }
- // some trick here: we are in the business of loading a key frame in decklink,
- // no use to do it if we are still in the same rendering frame.
- // We find this out by looking at the engine current clock time
- KX_KetsjiEngine* engine = KX_GetActiveEngine();
- if (engine->GetClockTime() != self->m_lastClock)
- {
- self->m_lastClock = engine->GetClockTime();
- // set source refresh
- bool refreshSource = (param == Py_True);
- uint32_t *leftEye = NULL;
- uint32_t *rightEye = NULL;
- // try to process key frame from source
- try {
- // check if optimization is possible
- if (self->m_leftEye != NULL) {
- ImageBase *leftImage = self->m_leftEye->m_image;
- short * srcSize = leftImage->getSize();
- self->mLeftFrame->GetBytes((void **)&leftEye);
- if (srcSize[0] == self->mSize[0] && srcSize[1] == self->mSize[1])
- {
- // buffer has same size, can load directly
- if (!leftImage->loadImage(leftEye, self->mFrameSize, GL_BGRA, ts))
- leftEye = NULL;
- }
- else {
- // scaling is required, go the hard way
- unsigned int *src = leftImage->getImage(0, ts);
- if (src != NULL)
- decklink_ConvImage(leftEye, self->mSize, src, srcSize, self->mUseExtend);
- else
- leftEye = NULL;
- }
- }
- if (leftEye) {
- if (self->mUse3D && self->m_rightEye != NULL) {
- ImageBase *rightImage = self->m_rightEye->m_image;
- short * srcSize = rightImage->getSize();
- self->mRightFrame->GetBytes((void **)&rightEye);
- if (srcSize[0] == self->mSize[0] && srcSize[1] == self->mSize[1])
- {
- // buffer has same size, can load directly
- rightImage->loadImage(rightEye, self->mFrameSize, GL_BGRA, ts);
- }
- else {
- // scaling is required, go the hard way
- unsigned int *src = rightImage->getImage(0, ts);
- if (src != NULL)
- decklink_ConvImage(rightEye, self->mSize, src, srcSize, self->mUseExtend);
- }
- }
- if (self->mUse3D) {
- DeckLink3DFrameWrapper frame3D(
- (IDeckLinkVideoFrame*)self->mLeftFrame,
- (IDeckLinkVideoFrame*)self->mRightFrame);
- self->mDLOutput->DisplayVideoFrameSync(&frame3D);
- }
- else {
- self->mDLOutput->DisplayVideoFrameSync((IDeckLinkVideoFrame*)self->mLeftFrame);
- }
- }
- // refresh texture source, if required
- if (refreshSource) {
- if (self->m_leftEye)
- self->m_leftEye->m_image->refresh();
- if (self->m_rightEye)
- self->m_rightEye->m_image->refresh();
- }
- }
- CATCH_EXCP;
- }
- Py_RETURN_NONE;
-}
-
-// get source object
-static PyObject *DeckLink_getSource(DeckLink *self, PyObject *value, void *closure)
-{
- // if source exists
- if (self->m_leftEye != NULL) {
- Py_INCREF(self->m_leftEye);
- return reinterpret_cast<PyObject*>(self->m_leftEye);
- }
- // otherwise return None
- Py_RETURN_NONE;
-}
-
-
-// set source object
-int DeckLink_setSource(DeckLink *self, PyObject *value, void *closure)
-{
- // check new value
- if (value == NULL || !pyImageTypes.in(Py_TYPE(value))) {
- // report value error
- PyErr_SetString(PyExc_TypeError, "Invalid type of value");
- return -1;
- }
- // increase ref count for new value
- Py_INCREF(value);
- // release previous
- Py_XDECREF(self->m_leftEye);
- // set new value
- self->m_leftEye = reinterpret_cast<PyImage*>(value);
- // return success
- return 0;
-}
-
-// get source object
-static PyObject *DeckLink_getRight(DeckLink *self, PyObject *value, void *closure)
-{
- // if source exists
- if (self->m_rightEye != NULL)
- {
- Py_INCREF(self->m_rightEye);
- return reinterpret_cast<PyObject*>(self->m_rightEye);
- }
- // otherwise return None
- Py_RETURN_NONE;
-}
-
-
-// set source object
-static int DeckLink_setRight(DeckLink *self, PyObject *value, void *closure)
-{
- // check new value
- if (value == NULL || !pyImageTypes.in(Py_TYPE(value)))
- {
- // report value error
- PyErr_SetString(PyExc_TypeError, "Invalid type of value");
- return -1;
- }
- // increase ref count for new value
- Py_INCREF(value);
- // release previous
- Py_XDECREF(self->m_rightEye);
- // set new value
- self->m_rightEye = reinterpret_cast<PyImage*>(value);
- // return success
- return 0;
-}
-
-
-static PyObject *DeckLink_getKeying(DeckLink *self, PyObject *value, void *closure)
-{
- if (self->mUseKeying) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-static int DeckLink_setKeying(DeckLink *self, PyObject *value, void *closure)
-{
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- if (self->mKeyer != NULL)
- {
- if (value == Py_True)
- {
- if (self->mKeyer->Enable(false) != S_OK)
- {
- PyErr_SetString(PyExc_RuntimeError, "Error enabling keyer");
- return -1;
- }
- self->mUseKeying = true;
- self->mKeyer->SetLevel(self->mKeyingLevel);
- }
- else
- {
- self->mKeyer->Disable();
- self->mUseKeying = false;
- }
- }
- // success
- return 0;
-}
-
-static PyObject *DeckLink_getLevel(DeckLink *self, PyObject *value, void *closure)
-{
- return Py_BuildValue("h", self->mKeyingLevel);
-}
-
-static int DeckLink_setLevel(DeckLink *self, PyObject *value, void *closure)
-{
- long level;
- if (value == NULL || !PyLong_Check(value)) {
- PyErr_SetString(PyExc_TypeError, "The value must be an integer from 0 to 255");
- return -1;
- }
- level = PyLong_AsLong(value);
- if (level > 255)
- level = 255;
- else if (level < 0)
- level = 0;
- self->mKeyingLevel = (uint8_t)level;
- if (self->mUseKeying) {
- if (self->mKeyer->SetLevel(self->mKeyingLevel) != S_OK) {
- PyErr_SetString(PyExc_RuntimeError, "Error changin level of keyer");
- return -1;
- }
- }
- // success
- return 0;
-}
-
-static PyObject *DeckLink_getExtend(DeckLink *self, PyObject *value, void *closure)
-{
- if (self->mUseExtend) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-static int DeckLink_setExtend(DeckLink *self, PyObject *value, void *closure)
-{
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- self->mUseExtend = (value == Py_True);
- return 0;
-}
-
-// class DeckLink methods
-static PyMethodDef decklinkMethods[] =
-{
- { "close", (PyCFunction)DeckLink_close, METH_NOARGS, "Close dynamic decklink and restore original"},
- { "refresh", (PyCFunction)DeckLink_refresh, METH_VARARGS, "Refresh decklink from source"},
- {NULL} /* Sentinel */
-};
-
-// class DeckLink attributes
-static PyGetSetDef decklinkGetSets[] =
-{
- { (char*)"source", (getter)DeckLink_getSource, (setter)DeckLink_setSource, (char*)"source of decklink (left eye)", NULL},
- { (char*)"right", (getter)DeckLink_getRight, (setter)DeckLink_setRight, (char*)"source of decklink (right eye)", NULL },
- { (char*)"keying", (getter)DeckLink_getKeying, (setter)DeckLink_setKeying, (char*)"whether keying is enabled (frame is alpha-composited with passthrough output)", NULL },
- { (char*)"level", (getter)DeckLink_getLevel, (setter)DeckLink_setLevel, (char*)"change the level of keying (overall alpha level of key frame, 0 to 255)", NULL },
- { (char*)"extend", (getter)DeckLink_getExtend, (setter)DeckLink_setExtend, (char*)"whether image should stretched to fit frame", NULL },
- { NULL }
-};
-
-
-// class DeckLink declaration
-PyTypeObject DeckLinkType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.DeckLink", /*tp_name*/
- sizeof(DeckLink), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)DeckLink_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "DeckLink objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- decklinkMethods, /* tp_methods */
- 0, /* tp_members */
- decklinkGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)DeckLink_init, /* tp_init */
- 0, /* tp_alloc */
- DeckLink_new, /* tp_new */
-};
-
-#endif /* WITH_GAMEENGINE_DECKLINK */
diff --git a/source/gameengine/VideoTexture/DeckLink.h b/source/gameengine/VideoTexture/DeckLink.h
deleted file mode 100644
index 4528fe7cec0..00000000000
--- a/source/gameengine/VideoTexture/DeckLink.h
+++ /dev/null
@@ -1,86 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file VideoTexture/DeckLink.h
- * \ingroup bgevideotex
- */
-
-#ifndef __DECKLINK_H__
-#define __DECKLINK_H__
-
-#ifdef WITH_GAMEENGINE_DECKLINK
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "DNA_image_types.h"
-
-#include "DeckLinkAPI.h"
-
-#include "ImageBase.h"
-#include "BlendType.h"
-#include "Exception.h"
-
-
-// type DeckLink declaration
-struct DeckLink
-{
- PyObject_HEAD
-
- // last refresh
- double m_lastClock;
- // decklink card to which we output
- IDeckLinkOutput * mDLOutput;
- IDeckLinkKeyer * mKeyer;
- IDeckLinkMutableVideoFrame *mLeftFrame;
- IDeckLinkMutableVideoFrame *mRightFrame;
- bool mUse3D;
- bool mUseKeying;
- bool mUseExtend;
- bool mKeyingSupported;
- bool mHDKeyingSupported;
- uint8_t mKeyingLevel;
- BMDDisplayMode mDisplayMode;
- short mSize[2];
- uint32_t mFrameSize;
-
- // image source
- PyImage * m_leftEye;
- PyImage * m_rightEye;
-};
-
-
-// DeckLink type description
-extern PyTypeObject DeckLinkType;
-
-// helper function
-HRESULT decklink_ReadDisplayMode(const char *format, size_t len, BMDDisplayMode *displayMode);
-HRESULT decklink_ReadPixelFormat(const char *format, size_t len, BMDPixelFormat *displayMode);
-
-#endif /* WITH_GAMEENGINE_DECKLINK */
-
-#endif /* __DECKLINK_H__ */
diff --git a/source/gameengine/VideoTexture/Exception.cpp b/source/gameengine/VideoTexture/Exception.cpp
deleted file mode 100644
index 9f82987ea62..00000000000
--- a/source/gameengine/VideoTexture/Exception.cpp
+++ /dev/null
@@ -1,241 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2006 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/Exception.cpp
- * \ingroup bgevideotex
- */
-
-#include <sstream>
-#include <fstream>
-
-#include "EXP_PyObjectPlus.h"
-
-#include "Exception.h"
-
-
-// exception identificators
-ExceptionID ErrGeneral, ErrNotFound;
-
-// exception descriptions
-ExpDesc errGenerDesc(ErrGeneral, "General Error");
-ExpDesc errNFoundDesc(ErrNotFound, "Error description not found");
-
-
-
-// implementation of ExpDesc
-
-// constructor
-ExpDesc::ExpDesc (ExceptionID & exp, const char *desc, RESULT hres)
-: m_expID(exp), m_hRslt(hres), m_description(desc)
-{
-}
-
-// destructor
-ExpDesc::~ExpDesc (void) {}
-
-// list of descriptions
-std::vector<ExpDesc*> ExpDesc::m_expDescs;
-
-
-// class Exception
-
-
-// last exception description
-std::string Exception::m_lastError;
-
-// log file name
-const char * Exception::m_logFile = NULL;
-
-
-// basic constructor
-Exception::Exception ()
-{
- // default values
- m_expID = &ErrNotFound;
- m_hRslt = S_OK;
- m_line = 0;
-}
-
-
-// destructor
-Exception::~Exception () throw() { }
-
-
-// copy constructor
-Exception::Exception (const Exception & xpt)
-{ copy (xpt); }
-
-
-// assignment operator
-Exception & Exception::operator= (const Exception & xpt)
-{ copy (xpt); return *this; }
-
-
-// get exception description
-const char * Exception::what()
-{
- // set exception description
- setXptDesc();
- // return c string
- return m_desc.c_str();
-}
-
-
-// debug version - with file and line of exception
-Exception::Exception (ExceptionID & expID, RESULT rslt, const char *fil, int lin)
-: m_expID (&expID), m_hRslt (rslt)
-{
- // set file and line
- if (fil[0] != '\0' || lin > 0)
- setFileLine (fil, lin);
- else
- m_line = -1;
-}
-
-
-// set file and line
-void Exception::setFileLine (const char *fil, int lin)
-{
- if (fil != NULL) m_fileName = fil;
- m_line = lin;
-}
-
-
-// report exception
-void Exception::report(void)
-{
- // set exception description
- setXptDesc();
- // set python error
- PyErr_SetString(PyExc_RuntimeError, what());
- // if log file is set
- if (m_logFile != NULL)
- {
- // write description to log
- std::ofstream logf (m_logFile, std::ios_base::app);
- logf << m_fileName << ':' << m_line << ':' << m_desc << std::endl;
- logf.flush();
- logf.close();
- }
-}
-
-
-// set exception description
-void Exception::setXptDesc (void)
-{
- // if description is not set
- if (m_desc.size() == 0)
- {
- // start of search -1
- // found description "NotFound" 0
- // found description without matching result 1
- // found description with matching result 2
- int best = -1;
- // find exception description
- for (std::vector<ExpDesc*>::iterator it = ExpDesc::m_expDescs.begin(); it != ExpDesc::m_expDescs.end(); ++it)
- {
- // use "NotFound", if there is not better
- if (best < 0 && (*it)->isExp(&ErrNotFound) > 0)
- {
- (*it)->loadDesc(m_desc);
- best = 0;
- }
- // match exception
- int nBest = (*it)->isExp(m_expID, m_hRslt);
- // if exception is matching better
- if (nBest > 0 && best < nBest)
- {
- // set description
- (*it)->loadDesc(m_desc);
- best = nBest;
- // if matching exactly, finish search
- if (best == 2) break;
- }
- }
- // add result code
- // length of result code
- const size_t rsltSize = 11;
- // delimit description
- //const char delimRslt[] = ": ";
- // set text of description
- char rsltTxt[rsltSize];
- std::ostringstream os;
- os << std::hex << m_hRslt << ": " << '\0';
- // copy result to description
- m_desc.insert(0, rsltTxt);
- // copy exception description to last exception string
- m_lastError = m_desc;
- }
-}
-
-
-// copy exception data
-void Exception::copy (const Exception & xpt)
-{
- // standard data
- m_expID = xpt.m_expID;
- m_hRslt = xpt.m_hRslt;
- m_desc = xpt.m_desc;
-
- // debug data
- m_fileName = xpt.m_fileName;
- m_line = xpt.m_line;
-}
-
-void registerAllExceptions(void)
-{
- errGenerDesc.registerDesc();
- errNFoundDesc.registerDesc();
- MaterialNotAvailDesc.registerDesc();
- ImageSizesNotMatchDesc.registerDesc();
- ImageHasExportsDesc.registerDesc();
- InvalidColorChannelDesc.registerDesc();
- InvalidImageModeDesc.registerDesc();
- SceneInvalidDesc.registerDesc();
- CameraInvalidDesc.registerDesc();
- ObserverInvalidDesc.registerDesc();
- MirrorInvalidDesc.registerDesc();
- MirrorSizeInvalidDesc.registerDesc();
- MirrorNormalInvalidDesc.registerDesc();
- MirrorHorizontalDesc.registerDesc();
- MirrorTooSmallDesc.registerDesc();
- SourceVideoEmptyDesc.registerDesc();
- SourceVideoCreationDesc.registerDesc();
- OffScreenInvalidDesc.registerDesc();
-#ifdef WITH_GAMEENGINE_DECKLINK
- AutoDetectionNotAvailDesc.registerDesc();
- DeckLinkBadDisplayModeDesc.registerDesc();
- DeckLinkBadPixelFormatDesc.registerDesc();
- DeckLinkOpenCardDesc.registerDesc();
- DeckLinkBadFormatDesc.registerDesc();
- DeckLinkInternalErrorDesc.registerDesc();
- SourceVideoOnlyCaptureDesc.registerDesc();
- VideoDeckLinkBadFormatDesc.registerDesc();
- VideoDeckLinkOpenCardDesc.registerDesc();
- VideoDeckLinkDvpInternalErrorDesc.registerDesc();
- VideoDeckLinkPinMemoryErrorDesc.registerDesc();
-#endif
-}
diff --git a/source/gameengine/VideoTexture/Exception.h b/source/gameengine/VideoTexture/Exception.h
deleted file mode 100644
index c4de85ff34d..00000000000
--- a/source/gameengine/VideoTexture/Exception.h
+++ /dev/null
@@ -1,239 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2006 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/Exception.h
- * \ingroup bgevideotex
- */
-
-#ifndef __EXCEPTION_H__
-#define __EXCEPTION_H__
-
-#include <exception>
-#include <vector>
-#include <string>
-#include <algorithm>
-
-#include "Common.h"
-
-
-#define CHCKHRSLTV(fnc,val,err) \
-{ \
- HRESULT macroHRslt = (fnc); \
- if (macroHRslt != val) \
- throw Exception (err, macroHRslt, __FILE__, __LINE__); \
-}
-
-#define THRWEXCP(err,hRslt) throw Exception (err, hRslt, __FILE__, __LINE__)
-
-
-#if defined WIN32
-
-#define CHCKHRSLT(fnc,err) \
-{ \
- HRESULT macroHRslt = (fnc); \
- if (FAILED(macroHRslt)) \
- throw Exception (err, macroHRslt, __FILE__, __LINE__); \
-}
-
-#else
-
-#define CHCKHRSLT(fnc,err) CHCKHRSLTV(fnc,S_OK,err)
-
-#endif
-
-
-// forward declarations
-class ExceptionID;
-class Exception;
-
-
-// exception identificators
-extern ExceptionID ErrGeneral, ErrNotFound;
-
-
-// result type
-typedef long RESULT;
-
-
-// class ExceptionID for exception identification
-class ExceptionID
-{
-public:
- // constructor a destructor
- ExceptionID (void) {}
- ~ExceptionID (void) {}
-
-private:
- // not allowed
- ExceptionID (const ExceptionID & obj) throw() {}
- ExceptionID & operator= (const ExceptionID & obj) throw() { return *this; }
-};
-
-
-// class ExpDesc for exception description
-class ExpDesc
-{
-public:
- // constructor a destructor
- ExpDesc (ExceptionID & exp, const char * desc, RESULT hres = S_OK);
- ~ExpDesc (void);
-
- // comparision function
- // returns 0, if exception identification don't match at all
- // returns 1, if only exception identification is matching
- // returns 2, if both exception identification and result are matching
- int isExp (ExceptionID *exp, RESULT hres = S_OK) throw()
- {
- // check exception identification
- if (&m_expID == exp)
- {
- // check result value
- if (m_hRslt == hres) return 2;
- // only identification match
- if (m_hRslt == S_OK) return 1;
- }
- // no match
- return 0;
- }
-
- // get exception description
- void loadDesc (std::string & desc) throw()
- {
- desc = m_description;
- }
-
- void registerDesc(void)
- {
- if (std::find(m_expDescs.begin(), m_expDescs.end(), this) == m_expDescs.end())
- m_expDescs.push_back(this);
- }
- // list of exception descriptions
- static std::vector<ExpDesc*> m_expDescs;
-
-private:
- // exception ID
- ExceptionID & m_expID;
- // result
- RESULT m_hRslt;
- // description
- const char * m_description;
-
- // not allowed
- ExpDesc (const ExpDesc & obj) : m_expID (ErrNotFound) {}
- ExpDesc & operator= (const ExpDesc & obj) { return *this; }
-};
-
-
-
-// class Exception
-class Exception : public std::exception
-{
-public:
- // constructor
- Exception ();
- // destructor
- virtual ~Exception () throw();
- // copy constructor
- Exception (const Exception & xpt);
- // assignment operator
- Exception & operator= (const Exception & xpt);
- // get exception description
- virtual const char * what(void);
-
- // debug version of constructor
- Exception (ExceptionID & expID, RESULT rslt, const char * fil, int lin);
- // set source file and line of exception
- void setFileLine (const char * fil, int lin);
-
- // get description in string
- std::string & getDesc (void) throw() { return m_desc; }
-
- // report exception
- virtual void report (void);
-
- // get exception id
- ExceptionID * getID (void) throw() { return m_expID; }
-
- /// last exception description
- static std::string m_lastError;
-
- /// log file name
- static const char * m_logFile;
-
-protected:
- // exception identification
- ExceptionID * m_expID;
- // RESULT code
- RESULT m_hRslt;
-
- // exception description
- std::string m_desc;
-
- // set exception description
- virtual void setXptDesc (void);
-
- // copy exception
- void copy (const Exception & xpt);
-
- // file name where exception was thrown
- std::string m_fileName;
- // line number in file
- int m_line;
-
-};
-
-extern ExpDesc MaterialNotAvailDesc;
-extern ExpDesc ImageSizesNotMatchDesc;
-extern ExpDesc ImageHasExportsDesc;
-extern ExpDesc InvalidColorChannelDesc;
-extern ExpDesc InvalidImageModeDesc;
-extern ExpDesc SceneInvalidDesc;
-extern ExpDesc CameraInvalidDesc;
-extern ExpDesc ObserverInvalidDesc;
-extern ExpDesc OffScreenInvalidDesc;
-extern ExpDesc MirrorInvalidDesc;
-extern ExpDesc MirrorSizeInvalidDesc;
-extern ExpDesc MirrorNormalInvalidDesc;
-extern ExpDesc MirrorHorizontalDesc;
-extern ExpDesc MirrorTooSmallDesc;
-extern ExpDesc SourceVideoEmptyDesc;
-extern ExpDesc SourceVideoCreationDesc;
-extern ExpDesc DeckLinkBadDisplayModeDesc;
-extern ExpDesc DeckLinkBadPixelFormatDesc;
-extern ExpDesc AutoDetectionNotAvailDesc;
-extern ExpDesc DeckLinkOpenCardDesc;
-extern ExpDesc DeckLinkBadFormatDesc;
-extern ExpDesc DeckLinkInternalErrorDesc;
-extern ExpDesc SourceVideoOnlyCaptureDesc;
-extern ExpDesc VideoDeckLinkBadFormatDesc;
-extern ExpDesc VideoDeckLinkOpenCardDesc;
-extern ExpDesc VideoDeckLinkDvpInternalErrorDesc;
-extern ExpDesc VideoDeckLinkPinMemoryErrorDesc;
-
-extern ExceptionID InvalidImageMode;
-
-void registerAllExceptions(void);
-#endif
diff --git a/source/gameengine/VideoTexture/FilterBase.cpp b/source/gameengine/VideoTexture/FilterBase.cpp
deleted file mode 100644
index b41a2095890..00000000000
--- a/source/gameengine/VideoTexture/FilterBase.cpp
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/FilterBase.cpp
- * \ingroup bgevideotex
- */
-
-
-#include "FilterBase.h"
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-
-// FilterBase class implementation
-
-// constructor
-FilterBase::FilterBase (void) : m_previous(NULL) {}
-
-
-// destructor
-FilterBase::~FilterBase (void)
-{
- // release Python objects, if not released yet
- release();
-}
-
-
-// release python objects
-void FilterBase::release (void)
-{
- // release previous filter object
- setPrevious(NULL);
-}
-
-
-// set new previous filter
-void FilterBase::setPrevious(PyFilter *filt, bool useRefCnt)
-{
- // if reference counting has to be used
- if (useRefCnt)
- {
- // reference new filter
- if (filt != NULL) Py_INCREF(filt);
- // release old filter
- Py_XDECREF(m_previous);
- }
- // set new previous filter
- m_previous = filt;
-}
-
-
-// find first filter
-FilterBase * FilterBase::findFirst (void)
-{
- // find first filter in chain
- FilterBase * frst;
- for (frst = this; frst->m_previous != NULL; frst = frst->m_previous->m_filter) {};
- // set first filter
- return frst;
-}
-
-
-
-// list offilter types
-PyTypeList pyFilterTypes;
-
-
-
-// functions for python interface
-
-
-// object allocation
-PyObject *Filter_allocNew (PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- // allocate object
- PyFilter *self = reinterpret_cast<PyFilter*>(type->tp_alloc(type, 0));
- // initialize object structure
- self->m_filter = NULL;
- // return allocated object
- return reinterpret_cast<PyObject*>(self);
-}
-
-// object deallocation
-void Filter_dealloc(PyFilter *self)
-{
- // release object attributes
- if (self->m_filter != NULL)
- {
- self->m_filter->release();
- delete self->m_filter;
- self->m_filter = NULL;
- }
- Py_TYPE((PyObject *)self)->tp_free((PyObject *)self);
-}
-
-
-// get previous pixel filter object
-PyObject *Filter_getPrevious (PyFilter *self, void *closure)
-{
- // if filter object is available
- if (self->m_filter != NULL)
- {
- // pixel filter object
- PyObject *filt = reinterpret_cast<PyObject*>(self->m_filter->getPrevious());
- // if filter is present
- if (filt != NULL)
- {
- // return it
- Py_INCREF(filt);
- return filt;
- }
- }
- // otherwise return none
- Py_RETURN_NONE;
-}
-
-
-// set previous pixel filter object
-int Filter_setPrevious(PyFilter *self, PyObject *value, void *closure)
-{
- // if filter object is available
- if (self->m_filter != NULL)
- {
- // check new value
- if (value == NULL || !pyFilterTypes.in(Py_TYPE(value)))
- {
- // report value error
- PyErr_SetString(PyExc_TypeError, "Invalid type of value");
- return -1;
- }
- // set new value
- self->m_filter->setPrevious(reinterpret_cast<PyFilter*>(value));
- }
- // return success
- return 0;
-}
diff --git a/source/gameengine/VideoTexture/FilterBase.h b/source/gameengine/VideoTexture/FilterBase.h
deleted file mode 100644
index db688d551d0..00000000000
--- a/source/gameengine/VideoTexture/FilterBase.h
+++ /dev/null
@@ -1,161 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file FilterBase.h
- * \ingroup bgevideotex
- */
-
-#ifndef __FILTERBASE_H__
-#define __FILTERBASE_H__
-
-#include "Common.h"
-
-#include "EXP_PyObjectPlus.h"
-
-#include "PyTypeList.h"
-
-#define VT_C(v,idx) ((unsigned char*)&v)[idx]
-#define VT_R(v) ((unsigned char*)&v)[0]
-#define VT_G(v) ((unsigned char*)&v)[1]
-#define VT_B(v) ((unsigned char*)&v)[2]
-#define VT_A(v) ((unsigned char*)&v)[3]
-#define VT_RGBA(v,r,g,b,a) VT_R(v)=(unsigned char)r, VT_G(v)=(unsigned char)g, VT_B(v)=(unsigned char)b, VT_A(v)=(unsigned char)a
-
-#ifdef __BIG_ENDIAN__
-# define VT_SWAPBR(i) ((((i) >> 16) & 0xFF00) + (((i) & 0xFF00) << 16) + ((i) & 0xFF00FF))
-#else
-# define VT_SWAPBR(i) ((((i) & 0xFF) << 16) + (((i) >> 16) & 0xFF) + ((i) & 0xFF00FF00))
-#endif
-
-
-// forward declaration
-class FilterBase;
-
-
-// python structure for filter
-struct PyFilter
-{
- PyObject_HEAD
- // source object
- FilterBase * m_filter;
-};
-
-
-/// base class for pixel filters
-class FilterBase
-{
-public:
- /// constructor
- FilterBase (void);
- /// destructor
- virtual ~FilterBase (void);
- // release python objects
- virtual void release (void);
-
- /// convert pixel
- template <class SRC> unsigned int convert (SRC src, short x, short y,
- short * size, unsigned int pixSize)
- {
- return filter(src, x, y, size, pixSize,
- convertPrevious(src, x, y, size, pixSize));
- }
-
- /// get previous filter
- PyFilter * getPrevious (void) { return m_previous; }
- /// set previous filter
- void setPrevious (PyFilter *filt, bool useRefCnt = true);
-
- /// find first filter in chain
- FilterBase * findFirst (void);
-
- /// get first filter's source pixel size
- unsigned int firstPixelSize (void) { return findFirst()->getPixelSize(); }
-
-protected:
- /// previous pixel filter
- PyFilter * m_previous;
-
- /// filter pixel, source byte buffer
- virtual unsigned int filter(unsigned char *src, short x, short y,
- short *size, unsigned int pixSize, unsigned int val = 0)
- { return val; }
- /// filter pixel, source int buffer
- virtual unsigned int filter(unsigned int *src, short x, short y,
- short *size, unsigned int pixSize, unsigned int val = 0)
- { return val; }
- /// filter pixel, source float buffer
- virtual unsigned int filter(float *src, short x, short y,
- short *size, unsigned int pixSize, unsigned int val = 0)
- { return val; }
-
- /// get source pixel size
- virtual unsigned int getPixelSize(void) { return 1; }
-
- /// get converted pixel from previous filters
- template <class SRC> unsigned int convertPrevious (SRC src, short x, short y,
- short * size, unsigned int pixSize)
- {
- // if previous filter doesn't exists, return source pixel
- if (m_previous == NULL) return *src;
- // otherwise return converted pixel
- return m_previous->m_filter->convert(src, x, y, size, pixSize);
- }
-
-#ifdef WITH_CXX_GUARDEDALLOC
- MEM_CXX_CLASS_ALLOC_FUNCS("GE:FilterBase")
-#endif
-};
-
-
-// list of python filter types
-extern PyTypeList pyFilterTypes;
-
-
-// functions for python interface
-
-// object initialization
-template <class T> static int Filter_init (PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- PyFilter *self = reinterpret_cast<PyFilter*>(pySelf);
- // create filter object
- if (self->m_filter != NULL) delete self->m_filter;
- self->m_filter = new T();
- // initialization succeded
- return 0;
-}
-
-// object allocation
-PyObject *Filter_allocNew(PyTypeObject *type, PyObject *args, PyObject *kwds);
-// object deallocation
-void Filter_dealloc(PyFilter *self);
-
-// get previous pixel filter object
-PyObject *Filter_getPrevious(PyFilter *self, void *closure);
-// set previous pixel filter object
-int Filter_setPrevious(PyFilter *self, PyObject *value, void *closure);
-
-
-#endif
diff --git a/source/gameengine/VideoTexture/FilterBlueScreen.cpp b/source/gameengine/VideoTexture/FilterBlueScreen.cpp
deleted file mode 100644
index a25d09e1eee..00000000000
--- a/source/gameengine/VideoTexture/FilterBlueScreen.cpp
+++ /dev/null
@@ -1,190 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/FilterBlueScreen.cpp
- * \ingroup bgevideotex
- */
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "FilterBlueScreen.h"
-
-#include "FilterBase.h"
-#include "PyTypeList.h"
-
-// implementation FilterBlueScreen
-
-// constructor
-FilterBlueScreen::FilterBlueScreen (void)
-{
- // set color to blue
- setColor(0, 0, 255);
- // set limits
- setLimits(64, 64);
-}
-
-// set color
-void FilterBlueScreen::setColor (unsigned char red, unsigned char green, unsigned char blue)
-{
- m_color[0] = red;
- m_color[1] = green;
- m_color[2] = blue;
-}
-
-// set limits for color variation
-void FilterBlueScreen::setLimits (unsigned short minLimit, unsigned short maxLimit)
-{
- m_limits[0] = minLimit;
- m_limits[1] = maxLimit > minLimit ? maxLimit : minLimit;
- // calculate square values
- for (short idx = 0; idx < 2; ++idx)
- m_squareLimits[idx] = m_limits[idx] * m_limits[idx];
- // limits distance
- m_limitDist = m_squareLimits[1] - m_squareLimits[0];
-}
-
-
-
-// cast Filter pointer to FilterBlueScreen
-inline FilterBlueScreen * getFilter (PyFilter *self)
-{ return static_cast<FilterBlueScreen*>(self->m_filter); }
-
-
-// python methods and get/sets
-
-// get color
-static PyObject *getColor (PyFilter *self, void *closure)
-{
- return Py_BuildValue("[BBB]", getFilter(self)->getColor()[0],
- getFilter(self)->getColor()[1], getFilter(self)->getColor()[2]);
-}
-
-// set color
-static int setColor(PyFilter *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL ||
- !(PyTuple_Check(value) || PyList_Check(value)) ||
- PySequence_Fast_GET_SIZE(value) != 3 ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)) ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 2)))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 3 ints");
- return -1;
- }
- // set color
- getFilter(self)->setColor(
- (unsigned char)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
- (unsigned char)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1))),
- (unsigned char)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 2))));
- // success
- return 0;
-}
-
-// get limits
-static PyObject *getLimits (PyFilter *self, void *closure)
-{
- return Py_BuildValue("[II]", getFilter(self)->getLimits()[0],
- getFilter(self)->getLimits()[1]);
-}
-
-// set limit
-static int setLimits(PyFilter *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL ||
- !(PyTuple_Check(value) || PyList_Check(value)) ||
- PySequence_Fast_GET_SIZE(value) != 2 ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
- return -1;
- }
- // set limits
- getFilter(self)->setLimits(
- (unsigned short)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
- (unsigned short)(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1))));
- // success
- return 0;
-}
-
-
-// attributes structure
-static PyGetSetDef filterBSGetSets[] =
-{
- {(char*)"color", (getter)getColor, (setter)setColor, (char*)"blue screen color", NULL},
- {(char*)"limits", (getter)getLimits, (setter)setLimits, (char*)"blue screen color limits", NULL},
- // attributes from FilterBase class
- {(char*)"previous", (getter)Filter_getPrevious, (setter)Filter_setPrevious, (char*)"previous pixel filter", NULL},
- {NULL}
-};
-
-// define python type
-PyTypeObject FilterBlueScreenType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterBlueScreen", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Filter for Blue Screen objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- filterBSGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterBlueScreen>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
diff --git a/source/gameengine/VideoTexture/FilterBlueScreen.h b/source/gameengine/VideoTexture/FilterBlueScreen.h
deleted file mode 100644
index cf74a6705b7..00000000000
--- a/source/gameengine/VideoTexture/FilterBlueScreen.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of blendTex library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file FilterBlueScreen.h
- * \ingroup bgevideotex
- */
-
-#ifndef __FILTERBLUESCREEN_H__
-#define __FILTERBLUESCREEN_H__
-
-#include "Common.h"
-
-#include "FilterBase.h"
-
-
-/// pixel filter for blue screen
-class FilterBlueScreen : public FilterBase
-{
-public:
- /// constructor
- FilterBlueScreen (void);
- /// destructor
- virtual ~FilterBlueScreen (void) {}
-
- /// get color
- unsigned char * getColor (void) { return m_color; }
- /// set color
- void setColor (unsigned char red, unsigned char green, unsigned char blue);
-
- /// get limits for color variation
- unsigned short * getLimits (void) { return m_limits; }
- /// set limits for color variation
- void setLimits (unsigned short minLimit, unsigned short maxLimit);
-
-protected:
- /// blue screen color (red component first)
- unsigned char m_color[3];
- /// limits for color variation - first defines, where ends fully transparent
- /// color, second defines, where begins fully opaque color
- unsigned short m_limits[2];
- /// squared limits for color variation
- unsigned int m_squareLimits[2];
- /// distance between squared limits
- unsigned int m_limitDist;
-
- /// filter pixel template, source int buffer
- template <class SRC> unsigned int tFilter (SRC src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- // calculate differences
- int difRed = int(VT_R(val)) - int(m_color[0]);
- int difGreen = int(VT_G(val)) - int(m_color[1]);
- int difBlue = int(VT_B(val)) - int(m_color[2]);
- // calc distance from "blue screen" color
- unsigned int dist = (unsigned int)(difRed * difRed + difGreen * difGreen
- + difBlue * difBlue);
- // condition for fully transparent color
- if (m_squareLimits[0] >= dist)
- // return color with zero alpha
- VT_A(val) = 0;
- // condition for fully opaque color
- else if (m_squareLimits[1] <= dist)
- // return normal color
- VT_A(val) = 0xFF;
- // otherwise calc alpha
- else
- VT_A(val) = (((dist - m_squareLimits[0]) << 8) / m_limitDist);
- return val;
- }
-
- /// virtual filtering function for byte source
- virtual unsigned int filter (unsigned char *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
- /// virtual filtering function for unsigned int source
- virtual unsigned int filter (unsigned int *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
-};
-
-
-#endif
diff --git a/source/gameengine/VideoTexture/FilterColor.cpp b/source/gameengine/VideoTexture/FilterColor.cpp
deleted file mode 100644
index 15a7e9e4cd1..00000000000
--- a/source/gameengine/VideoTexture/FilterColor.cpp
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/FilterColor.cpp
- * \ingroup bgevideotex
- */
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "FilterColor.h"
-
-#include "FilterBase.h"
-#include "PyTypeList.h"
-
-// implementation FilterGray
-
-// attributes structure
-static PyGetSetDef filterGrayGetSets[] =
-{ // attributes from FilterBase class
- {(char*)"previous", (getter)Filter_getPrevious, (setter)Filter_setPrevious, (char*)"previous pixel filter", NULL},
- {NULL}
-};
-
-// define python type
-PyTypeObject FilterGrayType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterGray", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Filter for grayscale effect", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- filterGrayGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterGray>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
-
-// implementation FilterColor
-
-// constructor
-FilterColor::FilterColor (void)
-{
- // reset color matrix to identity
- for (int r = 0; r < 4; ++r)
- for (int c = 0; c < 5; ++c)
- m_matrix[r][c] = (r == c) ? 256 : 0;
-}
-
-// set color matrix
-void FilterColor::setMatrix (ColorMatrix & mat)
-{
- // copy matrix
- for (int r = 0; r < 4; ++r)
- for (int c = 0; c < 5; ++c)
- m_matrix[r][c] = mat[r][c];
-}
-
-
-
-// cast Filter pointer to FilterColor
-inline FilterColor * getFilterColor (PyFilter *self)
-{ return static_cast<FilterColor*>(self->m_filter); }
-
-
-// python methods and get/sets
-
-// get color matrix
-static PyObject *getMatrix (PyFilter *self, void *closure)
-{
- ColorMatrix & mat = getFilterColor(self)->getMatrix();
- return Py_BuildValue("((hhhhh)(hhhhh)(hhhhh)(hhhhh))",
- mat[0][0], mat[0][1], mat[0][2], mat[0][3], mat[0][4],
- mat[1][0], mat[1][1], mat[1][2], mat[1][3], mat[1][4],
- mat[2][0], mat[2][1], mat[2][2], mat[2][3], mat[2][4],
- mat[3][0], mat[3][1], mat[3][2], mat[3][3], mat[3][4]);
-}
-
-// set color matrix
-static int setMatrix(PyFilter *self, PyObject *value, void *closure)
-{
- // matrix to store items
- ColorMatrix mat;
- // check validity of parameter
- bool valid = value != NULL && PySequence_Check(value)
- && PySequence_Size(value) == 4;
- // check rows
- for (int r = 0; valid && r < 4; ++r)
- {
- // get row object
- PyObject *row = PySequence_Fast_GET_ITEM(value, r);
- // check sequence
- valid = PySequence_Check(row) && PySequence_Size(row) == 5;
- // check items
- for (int c = 0; valid && c < 5; ++c)
- {
- // item must be int
- valid = PyLong_Check(PySequence_Fast_GET_ITEM(row, c));
- // if it is valid, save it in matrix
- if (valid)
- mat[r][c] = short(PyLong_AsLong(PySequence_Fast_GET_ITEM(row, c)));
- }
- }
- // if parameter is not valid, report error
- if (!valid)
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a matrix [4][5] of ints");
- return -1;
- }
- // set color matrix
- getFilterColor(self)->setMatrix(mat);
- // success
- return 0;
-}
-
-
-// attributes structure
-static PyGetSetDef filterColorGetSets[] =
-{
- {(char*)"matrix", (getter)getMatrix, (setter)setMatrix, (char*)"matrix [4][5] for color calculation", NULL},
- // attributes from FilterBase class
- {(char*)"previous", (getter)Filter_getPrevious, (setter)Filter_setPrevious, (char*)"previous pixel filter", NULL},
- {NULL}
-};
-
-// define python type
-PyTypeObject FilterColorType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterColor", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Filter for color calculations", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- filterColorGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterColor>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
-// implementation FilterLevel
-
-// constructor
-FilterLevel::FilterLevel (void)
-{
- // reset color levels
- for (int r = 0; r < 4; ++r)
- {
- levels[r][0] = 0;
- levels[r][1] = 0xFF;
- levels[r][2] = 0xFF;
- }
-}
-
-// set color levels
-void FilterLevel::setLevels (ColorLevel & lev)
-{
- // copy levels
- for (int r = 0; r < 4; ++r)
- {
- for (int c = 0; c < 2; ++c)
- levels[r][c] = lev[r][c];
- levels[r][2] = lev[r][0] < lev[r][1] ? lev[r][1] - lev[r][0] : 1;
- }
-}
-
-
-// cast Filter pointer to FilterLevel
-inline FilterLevel * getFilterLevel (PyFilter *self)
-{ return static_cast<FilterLevel*>(self->m_filter); }
-
-
-// python methods and get/sets
-
-// get color levels
-static PyObject *getLevels (PyFilter *self, void *closure)
-{
- ColorLevel & lev = getFilterLevel(self)->getLevels();
- return Py_BuildValue("((HH)(HH)(HH)(HH))",
- lev[0][0], lev[0][1], lev[1][0], lev[1][1],
- lev[2][0], lev[2][1], lev[3][0], lev[3][1]);
-}
-
-// set color levels
-static int setLevels(PyFilter *self, PyObject *value, void *closure)
-{
- // matrix to store items
- ColorLevel lev;
- // check validity of parameter
- bool valid = value != NULL && PySequence_Check(value)
- && PySequence_Size(value) == 4;
- // check rows
- for (int r = 0; valid && r < 4; ++r)
- {
- // get row object
- PyObject *row = PySequence_Fast_GET_ITEM(value, r);
- // check sequence
- valid = PySequence_Check(row) && PySequence_Size(row) == 2;
- // check items
- for (int c = 0; valid && c < 2; ++c)
- {
- // item must be int
- valid = PyLong_Check(PySequence_Fast_GET_ITEM(row, c));
- // if it is valid, save it in matrix
- if (valid)
- lev[r][c] = (unsigned short)(PyLong_AsLong(PySequence_Fast_GET_ITEM(row, c)));
- }
- }
- // if parameter is not valid, report error
- if (!valid)
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a matrix [4][2] of ints");
- return -1;
- }
- // set color matrix
- getFilterLevel(self)->setLevels(lev);
- // success
- return 0;
-}
-
-
-// attributes structure
-static PyGetSetDef filterLevelGetSets[] =
-{
- {(char*)"levels", (getter)getLevels, (setter)setLevels, (char*)"levels matrix [4] (min, max)", NULL},
- // attributes from FilterBase class
- {(char*)"previous", (getter)Filter_getPrevious, (setter)Filter_setPrevious, (char*)"previous pixel filter", NULL},
- {NULL}
-};
-
-// define python type
-PyTypeObject FilterLevelType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterLevel", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Filter for levels calculations", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- filterLevelGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterLevel>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
diff --git a/source/gameengine/VideoTexture/FilterColor.h b/source/gameengine/VideoTexture/FilterColor.h
deleted file mode 100644
index d042863d7e8..00000000000
--- a/source/gameengine/VideoTexture/FilterColor.h
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of blendTex library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file FilterColor.h
- * \ingroup bgevideotex
- */
-
-#ifndef __FILTERCOLOR_H__
-#define __FILTERCOLOR_H__
-
-#include "Common.h"
-
-#include "FilterBase.h"
-
-
-/// pixel filter for grayscale
-class FilterGray : public FilterBase
-{
-public:
- /// constructor
- FilterGray (void) {}
- /// destructor
- virtual ~FilterGray (void) {}
-
-protected:
- /// filter pixel template, source int buffer
- template <class SRC> unsigned int tFilter (SRC src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- // calculate gray value
- unsigned int gray = (28 * (VT_B(val)) + 151 * (VT_G(val))
- + 77 * (VT_R(val))) >> 8;
- // return grayscale value
- VT_R(val) = gray;
- VT_G(val) = gray;
- VT_B(val) = gray;
- return val;
- }
-
- /// virtual filtering function for byte source
- virtual unsigned int filter (unsigned char * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
- /// virtual filtering function for unsigned int source
- virtual unsigned int filter (unsigned int * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
-};
-
-
-/// type for color matrix
-typedef short ColorMatrix[4][5];
-
-/// pixel filter for color calculation
-class FilterColor : public FilterBase
-{
-public:
- /// constructor
- FilterColor (void);
- /// destructor
- virtual ~FilterColor (void) {}
-
- /// get color matrix
- ColorMatrix & getMatrix (void) { return m_matrix; }
- /// set color matrix
- void setMatrix (ColorMatrix & mat);
-
-protected:
- /// color calculation matrix
- ColorMatrix m_matrix;
-
- /// calculate one color component
- unsigned char calcColor (unsigned int val, short idx)
- {
- return (((m_matrix[idx][0] * (VT_R(val)) + m_matrix[idx][1] * (VT_G(val)) +
- m_matrix[idx][2] * (VT_B(val)) + m_matrix[idx][3] * (VT_A(val)) +
- m_matrix[idx][4]) >> 8) & 0xFF);
- }
-
- /// filter pixel template, source int buffer
- template <class SRC> unsigned int tFilter (SRC src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- // return calculated color
- int color;
- VT_RGBA(color, calcColor(val, 0), calcColor(val, 1), calcColor(val, 2), calcColor(val, 3));
- return color;
- }
-
- /// virtual filtering function for byte source
- virtual unsigned int filter (unsigned char * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
- /// virtual filtering function for unsigned int source
- virtual unsigned int filter (unsigned int * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
-};
-
-
-/// type for color levels
-typedef unsigned short ColorLevel[4][3];
-
-/// pixel filter for color calculation
-class FilterLevel : public FilterBase
-{
-public:
- /// constructor
- FilterLevel (void);
- /// destructor
- virtual ~FilterLevel (void) {}
-
- /// get color matrix
- ColorLevel & getLevels (void) { return levels; }
- /// set color matrix
- void setLevels (ColorLevel & lev);
-
-protected:
- /// color calculation matrix
- ColorLevel levels;
-
- /// calculate one color component
- unsigned int calcColor (unsigned int val, short idx)
- {
- unsigned int col = VT_C(val,idx);
- if (col <= levels[idx][0]) col = 0;
- else if (col >= levels[idx][1]) col = 0xFF;
- else col = (((col - levels[idx][0]) << 8) / levels[idx][2]) & 0xFF;
- return col;
- }
-
- /// filter pixel template, source int buffer
- template <class SRC> unsigned int tFilter (SRC src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- // return calculated color
- int color;
- VT_RGBA(color, calcColor(val, 0), calcColor(val, 1), calcColor(val, 2), calcColor(val, 3));
- return color;
- }
-
- /// virtual filtering function for byte source
- virtual unsigned int filter (unsigned char * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
- /// virtual filtering function for unsigned int source
- virtual unsigned int filter (unsigned int * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
-};
-
-
-#endif
diff --git a/source/gameengine/VideoTexture/FilterNormal.cpp b/source/gameengine/VideoTexture/FilterNormal.cpp
deleted file mode 100644
index 3a5333710fd..00000000000
--- a/source/gameengine/VideoTexture/FilterNormal.cpp
+++ /dev/null
@@ -1,173 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/FilterNormal.cpp
- * \ingroup bgevideotex
- */
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "FilterNormal.h"
-
-#include "FilterBase.h"
-#include "PyTypeList.h"
-
-// implementation FilterNormal
-
-// constructor
-FilterNormal::FilterNormal (void) : m_colIdx(0)
-{
- // set default depth
- setDepth(4);
-}
-
-// set color shift
-void FilterNormal::setColor (unsigned short colIdx)
-{
- // check validity of index
- if (colIdx < 3)
- // set color shift
- m_colIdx = colIdx;
-}
-
-// set depth
-void FilterNormal::setDepth (float depth)
-{
- m_depth = depth;
- m_depthScale = depth / depthScaleKoef;
-}
-
-
-// cast Filter pointer to FilterNormal
-inline FilterNormal * getFilter (PyFilter *self)
-{ return static_cast<FilterNormal*>(self->m_filter); }
-
-
-// python methods and get/sets
-
-// get index of color used to calculate normal
-static PyObject *getColor (PyFilter *self, void *closure)
-{
- return Py_BuildValue("H", getFilter(self)->getColor());
-}
-
-// set index of color used to calculate normal
-static int setColor(PyFilter *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL || !PyLong_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "filt.colorIdx = int: VideoTexture.FilterNormal, expected the value must be a int");
- return -1;
- }
- // set color index
- getFilter(self)->setColor((unsigned short)(PyLong_AsLong(value)));
- // success
- return 0;
-}
-
-
-// get depth
-static PyObject *getDepth (PyFilter *self, void *closure)
-{
- return Py_BuildValue("f", getFilter(self)->getDepth());
-}
-
-// set depth
-static int setDepth(PyFilter *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value)
- {
- float depth= (float)PyFloat_AsDouble(value);
- if ((depth==-1 && PyErr_Occurred()) == 0) /* no error converting to a float? */
- {
- // set depth
- getFilter(self)->setDepth(depth);
- // success
- return 0;
- }
- }
-
- PyErr_SetString(PyExc_TypeError, "filt.depth = float: VideoTexture.FilterNormal, expected the value must be a float");
- return -1;
-}
-
-
-// attributes structure
-static PyGetSetDef filterNormalGetSets[] =
-{
- {(char*)"colorIdx", (getter)getColor, (setter)setColor, (char*)"index of color used to calculate normal (0 - red, 1 - green, 2 - blue)", NULL},
- {(char*)"depth", (getter)getDepth, (setter)setDepth, (char*)"depth of relief", NULL},
- // attributes from FilterBase class
- {(char*)"previous", (getter)Filter_getPrevious, (setter)Filter_setPrevious, (char*)"previous pixel filter", NULL},
- {NULL}
-};
-
-// define python type
-PyTypeObject FilterNormalType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterNormal", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Filter for Blue Screen objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- filterNormalGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterNormal>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
diff --git a/source/gameengine/VideoTexture/FilterNormal.h b/source/gameengine/VideoTexture/FilterNormal.h
deleted file mode 100644
index 951ecb84d9d..00000000000
--- a/source/gameengine/VideoTexture/FilterNormal.h
+++ /dev/null
@@ -1,115 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of blendTex library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file FilterNormal.h
- * \ingroup bgevideotex
- */
-
-#ifndef __FILTERNORMAL_H__
-#define __FILTERNORMAL_H__
-
-#include "Common.h"
-
-#include "FilterBase.h"
-
-
-// scale constants for normals
-const float depthScaleKoef = 255.0;
-const float normScaleKoef = float(depthScaleKoef / 2.0);
-
-
-/// pixel filter for normal mapping
-class FilterNormal : public FilterBase
-{
-public:
- /// constructor
- FilterNormal (void);
- /// destructor
- virtual ~FilterNormal (void) {}
-
- /// get index of color used to calculate normals
- unsigned short getColor (void) { return m_colIdx; }
- /// set index of color used to calculate normals
- void setColor (unsigned short colIdx);
-
- /// get depth
- float getDepth (void) { return m_depth; }
- /// set depth
- void setDepth (float depth);
-
-protected:
- /// depth of normal relief
- float m_depth;
- /// scale to calculate normals
- float m_depthScale;
-
- /// color index, 0=red, 1=green, 2=blue, 3=alpha
- unsigned short m_colIdx;
-
- /// filter pixel, source int buffer
- template <class SRC> unsigned int tFilter (SRC *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- {
- // get value of required color
- int actPix = int(VT_C(val,m_colIdx));
- int upPix = actPix;
- int leftPix = actPix;
- // get upper and left pixel from actual pixel
- if (y > 0)
- {
- val = convertPrevious(src - pixSize * size[0], x, y - 1, size, pixSize);
- upPix = VT_C(val,m_colIdx);
- }
- if (x > 0)
- {
- val = convertPrevious(src - pixSize, x - 1, y, size, pixSize);
- leftPix = VT_C(val,m_colIdx);
- }
- // height differences (from blue color)
- float dx = (actPix - leftPix) * m_depthScale;
- float dy = (actPix - upPix) * m_depthScale;
- // normalize vector
- float dz = float(normScaleKoef / sqrt(dx * dx + dy * dy + 1.0));
- dx = dx * dz + normScaleKoef;
- dy = dy * dz + normScaleKoef;
- dz += normScaleKoef;
- // return normal vector converted to color
- VT_RGBA(val, dx, dy, dz, 0xFF);
- return val;
- }
-
- /// filter pixel, source byte buffer
- virtual unsigned int filter (unsigned char * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
- /// filter pixel, source int buffer
- virtual unsigned int filter (unsigned int * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- { return tFilter(src, x, y, size, pixSize, val); }
-};
-
-
-#endif
diff --git a/source/gameengine/VideoTexture/FilterSource.cpp b/source/gameengine/VideoTexture/FilterSource.cpp
deleted file mode 100644
index c8faa1f9f07..00000000000
--- a/source/gameengine/VideoTexture/FilterSource.cpp
+++ /dev/null
@@ -1,176 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/FilterSource.cpp
- * \ingroup bgevideotex
- */
-
-// implementation
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "FilterSource.h"
-
-#include "FilterBase.h"
-#include "PyTypeList.h"
-
-
-// FilterRGB24
-
-// define python type
-PyTypeObject FilterRGB24Type =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterRGB24", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Source filter RGB24 objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- NULL, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterRGB24>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
-// FilterRGBA32
-
-// define python type
-PyTypeObject FilterRGBA32Type =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterRGBA32", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Source filter RGBA32 objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- NULL, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterRGBA32>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
-// FilterBGR24
-
-// define python type
-PyTypeObject FilterBGR24Type =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.FilterBGR24", /*tp_name*/
- sizeof(PyFilter), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Filter_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Source filter BGR24 objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- NULL, /* tp_methods */
- 0, /* tp_members */
- NULL, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Filter_init<FilterBGR24>, /* tp_init */
- 0, /* tp_alloc */
- Filter_allocNew, /* tp_new */
-};
-
diff --git a/source/gameengine/VideoTexture/FilterSource.h b/source/gameengine/VideoTexture/FilterSource.h
deleted file mode 100644
index 820576dfff9..00000000000
--- a/source/gameengine/VideoTexture/FilterSource.h
+++ /dev/null
@@ -1,352 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of blendTex library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file FilterSource.h
- * \ingroup bgevideotex
- */
-
-#ifndef __FILTERSOURCE_H__
-#define __FILTERSOURCE_H__
-
-#include "Common.h"
-
-#include "FilterBase.h"
-
-/// class for RGB24 conversion
-class FilterRGB24 : public FilterBase
-{
-public:
- /// constructor
- FilterRGB24 (void) {}
- /// destructor
- virtual ~FilterRGB24 (void) {}
-
- /// get source pixel size
- virtual unsigned int getPixelSize (void) { return 3; }
-
-protected:
- /// filter pixel, source byte buffer
- virtual unsigned int filter (unsigned char *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- { VT_RGBA(val,src[0],src[1],src[2],0xFF); return val; }
-};
-
-/// class for RGBA32 conversion
-class FilterRGBA32 : public FilterBase
-{
-public:
- /// constructor
- FilterRGBA32 (void) {}
- /// destructor
- virtual ~FilterRGBA32 (void) {}
-
- /// get source pixel size
- virtual unsigned int getPixelSize (void) { return 4; }
-
-protected:
- /// filter pixel, source byte buffer
- virtual unsigned int filter (unsigned char *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- if ((intptr_t(src)&0x3) == 0)
- return *(unsigned int*)src;
- else
- {
- VT_RGBA(val,src[0],src[1],src[2],src[3]);
- return val;
- }
- }
-};
-
-/// class for BGRA32 conversion
-class FilterBGRA32 : public FilterBase
-{
-public:
- /// constructor
- FilterBGRA32 (void) {}
- /// destructor
- virtual ~FilterBGRA32 (void) {}
-
- /// get source pixel size
- virtual unsigned int getPixelSize (void) { return 4; }
-
-protected:
- /// filter pixel, source byte buffer
- virtual unsigned int filter(
- unsigned char *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- VT_RGBA(val,src[2],src[1],src[0],src[3]);
- return val;
- }
-};
-
-
-/// class for BGR24 conversion
-class FilterBGR24 : public FilterBase
-{
-public:
- /// constructor
- FilterBGR24 (void) {}
- /// destructor
- virtual ~FilterBGR24 (void) {}
-
- /// get source pixel size
- virtual unsigned int getPixelSize (void) { return 3; }
-
-protected:
- /// filter pixel, source byte buffer
- virtual unsigned int filter (unsigned char *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- { VT_RGBA(val,src[2],src[1],src[0],0xFF); return val; }
-};
-
-/// class for Z_buffer conversion
-class FilterZZZA : public FilterBase
-{
-public:
- /// constructor
- FilterZZZA (void) {}
- /// destructor
- virtual ~FilterZZZA (void) {}
-
- /// get source pixel size
- virtual unsigned int getPixelSize (void) { return 1; }
-
-protected:
- /// filter pixel, source float buffer
- virtual unsigned int filter (float *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- // calculate gray value
- // convert float to unsigned char
- unsigned int depth = int(src[0] * 255);
- // return depth scale value
- VT_R(val) = depth;
- VT_G(val) = depth;
- VT_B(val) = depth;
- VT_A(val) = 0xFF;
-
- return val;
- }
-};
-
-
-/// class for Z_buffer conversion
-class FilterDEPTH : public FilterBase
-{
-public:
- /// constructor
- FilterDEPTH (void) {}
- /// destructor
- virtual ~FilterDEPTH (void) {}
-
- /// get source pixel size
- virtual unsigned int getPixelSize (void) { return 1; }
-
-protected:
- /// filter pixel, source float buffer
- virtual unsigned int filter (float *src, short x, short y,
- short *size, unsigned int pixSize, unsigned int val)
- {
- /* Copy the float value straight away
- * The user can retrieve the original float value by using
- * 'F' mode in BGL buffer */
- memcpy(&val, src, sizeof (unsigned int));
- return val;
- }
-};
-
-
-
-
-/// class for YV12 conversion
-class FilterYV12 : public FilterBase
-{
-public:
- /// constructor
- FilterYV12 (void): m_buffV(NULL), m_buffU(NULL), m_pitchUV(0) {}
- /// destructor
- virtual ~FilterYV12 (void) {}
-
- /// get source pixel size
- virtual unsigned int getPixelSize (void) { return 1; }
-
- /// set pointers to color buffers
- void setBuffs (unsigned char * buff, short * size)
- {
- unsigned int buffSize = size[0] * size[1];
- m_buffV = buff + buffSize;
- m_buffU = m_buffV + (buffSize >> 2);
- m_pitchUV = size[0] >> 1;
- }
-
-protected:
- /// begin of V buffer
- unsigned char * m_buffV;
- /// begin of U buffer
- unsigned char * m_buffU;
- /// pitch for V & U buffers
- short m_pitchUV;
-
- /// interpolation function
- int interpol (int a, int b, int c, int d)
- { return (9 * (b + c) - a - d + 8) >> 4; }
-
- /// common horizontal interpolation
- int interpolH (unsigned char *src)
- { return interpol(*(src-1), *src, *(src+1), *(src+2)); }
-
- /// common vertical interpolation
- int interpolV (unsigned char *src)
- { return interpol(*(src-m_pitchUV), *src, *(src+m_pitchUV), *(src+2*m_pitchUV)); }
-
- /// common joined vertical and horizontal interpolation
- int interpolVH (unsigned char *src)
- {
- return interpol(interpolV(src-1), interpolV(src), interpolV(src+1),
- interpolV(src+2));
- }
-
- /// is pixel on edge
- bool isEdge (short x, short y, const short size[2])
- { return x <= 1 || x >= size[0] - 4 || y <= 1 || y >= size[1] - 4; }
-
- /// get the first parameter on the low edge
- unsigned char * interParA (unsigned char *src, short x, short size, short shift)
- { return x > 1 ? src - shift : src; }
- /// get the third parameter on the high edge
- unsigned char * interParC (unsigned char *src, short x, short size, short shift)
- { return x < size - 2 ? src + shift : src; }
- /// get the fourth parameter on the high edge
- unsigned char * interParD (unsigned char *src, short x, short size, short shift)
- { return x < size - 4 ? src + 2 * shift : x < size - 2 ? src + shift : src; }
-
- /// horizontal interpolation on edges
- int interpolEH (unsigned char *src, short x, short size)
- {
- return interpol(*interParA(src, x, size, 1), *src,
- *interParC(src, x, size, 1), *interParD(src, x, size, 1));
- }
-
- /// vertical interpolation on edges
- int interpolEV (unsigned char *src, short y, short size)
- {
- return interpol(*interParA(src, y, size, m_pitchUV), *src,
- *interParC(src, y, size, m_pitchUV), *interParD(src, y, size, m_pitchUV));
- }
-
- /// joined vertical and horizontal interpolation on edges
- int interpolEVH (unsigned char *src, short x, short y, short * size)
- {
- return interpol(interpolEV(interParA(src, x, size[0], 1), y, size[1]),
- interpolEV(src, y, size[1]), interpolEV(interParC(src, x, size[0], 1), y, size[1]),
- interpolEV(interParD(src, x, size[0], 1), y, size[1]));
- }
-
-
- /// filter pixel, source byte buffer
- virtual unsigned int filter (unsigned char *src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val)
- {
- // V & U offset
- long offset = (x >> 1) + m_pitchUV * (y >> 1);
- // get modified YUV -> CDE: C = Y - 16; D = U - 128; E = V - 128
- int c = *src - 16;
- int d = m_buffU[offset] - 128;
- int e = m_buffV[offset] - 128;
- // if horizontal interpolation is needed
- if ((x & 1) == 1) {
- // if vertical interpolation is needed too
- if ((y & 1) == 1)
- {
- // if this pixel is on the edge
- if (isEdge(x, y, size))
- {
- // get U & V from edge
- d = interpolEVH(m_buffU + offset, x, y, size) - 128;
- e = interpolEVH(m_buffV + offset, x, y, size) - 128;
- }
- // otherwise get U & V from inner range
- else
- {
- d = interpolVH(m_buffU + offset) - 128;
- e = interpolVH(m_buffV + offset) - 128;
- }
- // otherwise use horizontal interpolation only
- }
- else {
- // if this pixel is on the edge
- if (isEdge(x, y, size))
- {
- // get U & V from edge
- d = interpolEH(m_buffU + offset, x, size[0]) - 128;
- e = interpolEH(m_buffV + offset, x, size[0]) - 128;
- }
- // otherwise get U & V from inner range
- else
- {
- d = interpolH(m_buffU + offset) - 128;
- e = interpolH(m_buffV + offset) - 128;
- }
- // otherwise if only vertical interpolation is needed
- }
- }
- else if ((y & 1) == 1) {
- // if this pixel is on the edge
- if (isEdge(x, y, size))
- {
- // get U & V from edge
- d = interpolEV(m_buffU + offset, y, size[1]) - 128;
- e = interpolEV(m_buffV + offset, y, size[1]) - 128;
- }
- // otherwise get U & V from inner range
- else
- {
- d = interpolV(m_buffU + offset) - 128;
- e = interpolV(m_buffV + offset) - 128;
- }
- }
- // convert to RGB
- // R = clip(( 298 * C + 409 * E + 128) >> 8)
- // G = clip(( 298 * C - 100 * D - 208 * E + 128) >> 8)
- // B = clip(( 298 * C + 516 * D + 128) >> 8)
- int red = (298 * c + 409 * e + 128) >> 8;
- if (red >= 0x100) red = 0xFF;
- else if (red < 0) red = 0;
- int green = (298 * c - 100 * d - 208 * e) >> 8;
- if (green >= 0x100) green = 0xFF;
- else if (green < 0) green = 0;
- int blue = (298 * c + 516 * d + 128) >> 8;
- if (blue >= 0x100) blue = 0xFF;
- else if (blue < 0) blue = 0;
- // return result
- VT_RGBA(val, red, green, blue, 0xFF);
- return val;
- }
-};
-
-#endif /* __FILTERSOURCE_H__ */
diff --git a/source/gameengine/VideoTexture/ImageBase.cpp b/source/gameengine/VideoTexture/ImageBase.cpp
deleted file mode 100644
index a547d2a7a85..00000000000
--- a/source/gameengine/VideoTexture/ImageBase.cpp
+++ /dev/null
@@ -1,834 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/ImageBase.cpp
- * \ingroup bgevideotex
- */
-
-#include "ImageBase.h"
-extern "C" {
-#include "bgl.h"
-}
-
-#include <vector>
-#include <string.h>
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "FilterBase.h"
-
-#include "Exception.h"
-
-#if (defined(WIN32) || defined(WIN64))
-#define strcasecmp _stricmp
-#endif
-
-// ImageBase class implementation
-
-ExceptionID ImageHasExports;
-ExceptionID InvalidColorChannel;
-ExceptionID InvalidImageMode;
-
-ExpDesc ImageHasExportsDesc(ImageHasExports, "Image has exported buffers, cannot resize");
-ExpDesc InvalidColorChannelDesc(InvalidColorChannel, "Invalid or too many color channels specified. At most 4 values within R, G, B, A, 0, 1");
-ExpDesc InvalidImageModeDesc(InvalidImageMode, "Invalid image mode, only RGBA and BGRA are supported");
-
-// constructor
-ImageBase::ImageBase (bool staticSrc) : m_image(NULL), m_imgSize(0),
-m_avail(false), m_scale(false), m_scaleChange(false), m_flip(false),
-m_zbuff(false),
-m_depth(false),
-m_staticSources(staticSrc), m_pyfilter(NULL)
-{
- m_size[0] = m_size[1] = 0;
- m_exports = 0;
-}
-
-
-// destructor
-ImageBase::~ImageBase (void)
-{
- // release image
- if (m_image)
- delete [] m_image;
-}
-
-
-// release python objects
-bool ImageBase::release (void)
-{
- // iterate sources
- for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
- {
- // release source object
- delete *it;
- *it = NULL;
- }
- // release filter object
- Py_XDECREF(m_pyfilter);
- m_pyfilter = NULL;
- return true;
-}
-
-
-// get image
-unsigned int * ImageBase::getImage (unsigned int texId, double ts)
-{
- // if image is not available
- if (!m_avail)
- {
- // if there are any sources
- if (!m_sources.empty())
- {
- // get images from sources
- for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
- // get source image
- (*it)->getImage(ts);
- // init image
- init(m_sources[0]->getSize()[0], m_sources[0]->getSize()[1]);
- }
- // calculate new image
- calcImage(texId, ts);
- }
- // if image is available, return it, otherwise NULL
- return m_avail ? m_image : NULL;
-}
-
-bool ImageBase::loadImage(unsigned int *buffer, unsigned int size, unsigned int format, double ts)
-{
- unsigned int *d, *s, v, len;
- if (getImage(0, ts) != NULL && size >= getBuffSize()) {
- switch (format) {
- case GL_RGBA:
- memcpy(buffer, m_image, getBuffSize());
- break;
- case GL_BGRA:
- len = (unsigned int)m_size[0] * m_size[1];
- for (s=m_image, d=buffer; len; len--) {
- v = *s++;
- *d++ = VT_SWAPBR(v);
- }
- break;
- default:
- THRWEXCP(InvalidImageMode,S_OK);
- }
- return true;
- }
- return false;
-}
-
-// refresh image source
-void ImageBase::refresh (void)
-{
- // invalidate this image
- m_avail = false;
- // refresh all sources
- for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
- (*it)->refresh();
-}
-
-
-// get source object
-PyImage * ImageBase::getSource (const char *id)
-{
- // find source
- ImageSourceList::iterator src = findSource(id);
- // return it, if found
- return src != m_sources.end() ? (*src)->getSource() : NULL;
-}
-
-
-// set source object
-bool ImageBase::setSource (const char *id, PyImage *source)
-{
- // find source
- ImageSourceList::iterator src = findSource(id);
- // check source loop
- if (source != NULL && source->m_image->loopDetect(this))
- return false;
- // if found, set new object
- if (src != m_sources.end())
- // if new object is not empty or sources are static
- if (source != NULL || m_staticSources)
- // replace previous source
- (*src)->setSource(source);
- // otherwise delete source
- else
- m_sources.erase(src);
- // if source is not found and adding is allowed
- else
- if (!m_staticSources)
- {
- // create new source
- ImageSource * newSrc = newSource(id);
- newSrc->setSource(source);
- // if source was created, add it to source list
- if (newSrc != NULL) m_sources.push_back(newSrc);
- }
- // otherwise source wasn't set
- else
- return false;
- // source was set
- return true;
-}
-
-
-// set pixel filter
-void ImageBase::setFilter (PyFilter * filt)
-{
- // reference new filter
- if (filt != NULL) Py_INCREF(filt);
- // release previous filter
- Py_XDECREF(m_pyfilter);
- // set new filter
- m_pyfilter = filt;
-}
-
-void ImageBase::swapImageBR()
-{
- unsigned int size, v, *s;
-
- if (m_avail) {
- size = 1 * m_size[0] * m_size[1];
- for (s=m_image; size; size--) {
- v = *s;
- *s++ = VT_SWAPBR(v);
- }
- }
-}
-
-// initialize image data
-void ImageBase::init (short width, short height)
-{
- // if image has to be scaled
- if (m_scale)
- {
- // recalc sizes of image
- width = calcSize(width);
- height = calcSize(height);
- }
- // if sizes differ
- if (width != m_size[0] || height != m_size[1])
- {
- if (m_exports > 0)
- THRWEXCP(ImageHasExports,S_OK);
-
- // new buffer size
- unsigned int newSize = width * height;
- // if new buffer is larger than previous
- if (newSize > m_imgSize)
- {
- // set new buffer size
- m_imgSize = newSize;
- // release previous and create new buffer
- if (m_image)
- delete [] m_image;
- m_image = new unsigned int[m_imgSize];
- }
- // new image size
- m_size[0] = width;
- m_size[1] = height;
- // scale was processed
- m_scaleChange = false;
- }
-}
-
-
-// find source
-ImageSourceList::iterator ImageBase::findSource (const char *id)
-{
- // iterate sources
- ImageSourceList::iterator it;
- for (it = m_sources.begin(); it != m_sources.end(); ++it)
- // if id matches, return iterator
- if ((*it)->is(id)) return it;
- // source not found
- return it;
-}
-
-
-// check sources sizes
-bool ImageBase::checkSourceSizes (void)
-{
- // reference size
- short * refSize = NULL;
- // iterate sources
- for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
- {
- // get size of current source
- short * curSize = (*it)->getSize();
- // if size is available and is not empty
- if (curSize[0] != 0 && curSize[1] != 0) {
- // if reference size is not set
- if (refSize == NULL) {
- // set current size as reference
- refSize = curSize;
- // otherwise check with current size
- }
- else if (curSize[0] != refSize[0] || curSize[1] != refSize[1]) {
- // if they don't match, report it
- return false;
- }
- }
- }
- // all sizes match
- return true;
-}
-
-
-// compute nearest power of 2 value
-short ImageBase::calcSize (short size)
-{
- // while there is more than 1 bit in size value
- while ((size & (size - 1)) != 0)
- // clear last bit
- size = size & (size - 1);
- // return result
- return size;
-}
-
-
-// perform loop detection
-bool ImageBase::loopDetect (ImageBase * img)
-{
- // if this object is the same as parameter, loop is detected
- if (this == img) return true;
- // check all sources
- for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
- // if source detected loop, return this result
- if ((*it)->getSource() != NULL && (*it)->getSource()->m_image->loopDetect(img))
- return true;
- // no loop detected
- return false;
-}
-
-
-// ImageSource class implementation
-
-// constructor
-ImageSource::ImageSource (const char *id) : m_source(NULL), m_image(NULL)
-{
- // copy id
- int idx;
- for (idx = 0; id[idx] != '\0' && idx < SourceIdSize - 1; ++idx)
- m_id[idx] = id[idx];
- m_id[idx] = '\0';
-}
-
-// destructor
-ImageSource::~ImageSource (void)
-{
- // release source
- setSource(NULL);
-}
-
-
-// compare id
-bool ImageSource::is (const char *id)
-{
- for (char *myId = m_id; *myId != '\0'; ++myId, ++id)
- if (*myId != *id) return false;
- return *id == '\0';
-}
-
-
-// set source object
-void ImageSource::setSource (PyImage *source)
-{
- // reference new source
- if (source != NULL) Py_INCREF(source);
- // release previous source
- Py_XDECREF(m_source);
- // set new source
- m_source = source;
-}
-
-
-// get image from source
-unsigned int * ImageSource::getImage (double ts)
-{
- // if source is available
- if (m_source != NULL)
- // get image from source
- m_image = m_source->m_image->getImage(0, ts);
- // otherwise reset buffer
- else
- m_image = NULL;
- // return image
- return m_image;
-}
-
-
-// refresh source
-void ImageSource::refresh (void)
-{
- // if source is available, refresh it
- if (m_source != NULL) m_source->m_image->refresh();
-}
-
-
-
-// list of image types
-PyTypeList pyImageTypes;
-
-
-
-// functions for python interface
-
-// object allocation
-PyObject *Image_allocNew(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- // allocate object
- PyImage *self = reinterpret_cast<PyImage*>(type->tp_alloc(type, 0));
- // initialize object structure
- self->m_image = NULL;
- // return allocated object
- return reinterpret_cast<PyObject*>(self);
-}
-
-// object deallocation
-void Image_dealloc(PyImage *self)
-{
- // release object attributes
- if (self->m_image != NULL)
- {
- if (self->m_image->m_exports > 0)
- {
- PyErr_SetString(PyExc_SystemError,
- "deallocated Image object has exported buffers");
- PyErr_Print();
- }
- // if release requires deleting of object, do it
- if (self->m_image->release())
- delete self->m_image;
- self->m_image = NULL;
- }
- Py_TYPE((PyObject *)self)->tp_free((PyObject *)self);
-}
-
-// get image data
-PyObject *Image_getImage(PyImage *self, char *mode)
-{
- try
- {
- unsigned int * image = self->m_image->getImage();
- if (image)
- {
- // build BGL buffer
- int dimensions = self->m_image->getBuffSize();
- Buffer * buffer;
- if (mode == NULL || !strcasecmp(mode, "RGBA"))
- {
- buffer = BGL_MakeBuffer( GL_BYTE, 1, &dimensions, image);
- }
- else if (!strcasecmp(mode, "F"))
- {
- // this mode returns the image as an array of float.
- // This makes sense ONLY for the depth buffer:
- // source = VideoTexture.ImageViewport()
- // source.depth = True
- // depth = VideoTexture.imageToArray(source, 'F')
-
- // adapt dimension from byte to float
- dimensions /= sizeof(float);
- buffer = BGL_MakeBuffer( GL_FLOAT, 1, &dimensions, image);
- }
- else
- {
- int i, c, ncolor, pixels;
- int offset[4];
- unsigned char *s, *d;
- // scan the mode to get the channels requested, no more than 4
- for (i=ncolor=0; mode[i] != 0 && ncolor < 4; i++)
- {
- switch (toupper(mode[i]))
- {
- case 'R':
- offset[ncolor++] = 0;
- break;
- case 'G':
- offset[ncolor++] = 1;
- break;
- case 'B':
- offset[ncolor++] = 2;
- break;
- case 'A':
- offset[ncolor++] = 3;
- break;
- case '0':
- offset[ncolor++] = -1;
- break;
- case '1':
- offset[ncolor++] = -2;
- break;
- // if you add more color code, change the switch further down
- default:
- THRWEXCP(InvalidColorChannel,S_OK);
- }
- }
- if (mode[i] != 0) {
- THRWEXCP(InvalidColorChannel,S_OK);
- }
- // first get the number of pixels
- pixels = dimensions / 4;
- // multiple by the number of channels, each is one byte
- dimensions = pixels * ncolor;
- // get an empty buffer
- buffer = BGL_MakeBuffer( GL_BYTE, 1, &dimensions, NULL);
- // and fill it
- for (i = 0, d = (unsigned char *)buffer->buf.asbyte, s = (unsigned char *)image;
- i < pixels;
- i++, d += ncolor, s += 4)
- {
- for (c=0; c<ncolor; c++)
- {
- switch (offset[c])
- {
- case 0: d[c] = s[0]; break;
- case 1: d[c] = s[1]; break;
- case 2: d[c] = s[2]; break;
- case 3: d[c] = s[3]; break;
- case -1: d[c] = 0; break;
- case -2: d[c] = 0xFF; break;
- }
- }
- }
- }
- return (PyObject *)buffer;
- }
- }
- catch (Exception & exp)
- {
- exp.report();
- return NULL;
- }
- Py_RETURN_NONE;
-}
-
-// get image size
-PyObject *Image_getSize (PyImage *self, void *closure)
-{
- return Py_BuildValue("(hh)", self->m_image->getSize()[0],
- self->m_image->getSize()[1]);
-}
-
-// refresh image
-PyObject *Image_refresh (PyImage *self, PyObject *args)
-{
- Py_buffer buffer;
- bool done = true;
- char *mode = NULL;
- double ts = -1.0;
- unsigned int format;
-
- memset(&buffer, 0, sizeof(buffer));
- if (PyArg_ParseTuple(args, "|s*sd:refresh", &buffer, &mode, &ts)) {
- if (buffer.buf) {
- // a target buffer is provided, verify its format
- if (buffer.readonly) {
- PyErr_SetString(PyExc_TypeError, "Buffers passed in argument must be writable");
- }
- else if (!PyBuffer_IsContiguous(&buffer, 'C')) {
- PyErr_SetString(PyExc_TypeError, "Buffers passed in argument must be contiguous in memory");
- }
- else if (((intptr_t)buffer.buf & 3) != 0) {
- PyErr_SetString(PyExc_TypeError, "Buffers passed in argument must be aligned to 4 bytes boundary");
- }
- else {
- // ready to get the image into our buffer
- try {
- if (mode == NULL || !strcmp(mode, "RGBA"))
- format = GL_RGBA;
- else if (!strcmp(mode, "BGRA"))
- format = GL_BGRA;
- else
- THRWEXCP(InvalidImageMode,S_OK);
-
- done = self->m_image->loadImage((unsigned int *)buffer.buf, buffer.len, format, ts);
- }
- catch (Exception & exp) {
- exp.report();
- }
- }
- PyBuffer_Release(&buffer);
- if (PyErr_Occurred()) {
- return NULL;
- }
- }
- }
- else {
- return NULL;
- }
-
- self->m_image->refresh();
- if (done)
- Py_RETURN_TRUE;
- Py_RETURN_FALSE;
-}
-
-// get scale
-PyObject *Image_getScale (PyImage *self, void *closure)
-{
- if (self->m_image != NULL && self->m_image->getScale()) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-// set scale
-int Image_setScale(PyImage *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- // set scale
- if (self->m_image != NULL) self->m_image->setScale(value == Py_True);
- // success
- return 0;
-}
-
-// get flip
-PyObject *Image_getFlip (PyImage *self, void *closure)
-{
- if (self->m_image != NULL && self->m_image->getFlip()) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-// set flip
-int Image_setFlip(PyImage *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- // set scale
- if (self->m_image != NULL) self->m_image->setFlip(value == Py_True);
- // success
- return 0;
-}
-
-// get zbuff
-PyObject *Image_getZbuff(PyImage *self, void *closure)
-{
- if (self->m_image != NULL && self->m_image->getZbuff()) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-// set zbuff
-int Image_setZbuff(PyImage *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- // set scale
- if (self->m_image != NULL) self->m_image->setZbuff(value == Py_True);
- // success
- return 0;
-}
-
-// get depth
-PyObject *Image_getDepth(PyImage *self, void *closure)
-{
- if (self->m_image != NULL && self->m_image->getDepth()) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-// set depth
-int Image_setDepth(PyImage *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- // set scale
- if (self->m_image != NULL) self->m_image->setDepth(value == Py_True);
- // success
- return 0;
-}
-
-
-
-
-// get filter source object
-PyObject *Image_getSource(PyImage *self, PyObject *args)
-{
- // get arguments
- char *id;
- if (!PyArg_ParseTuple(args, "s:getSource", &id))
- return NULL;
- if (self->m_image != NULL)
- {
- // get source object
- PyObject *src = reinterpret_cast<PyObject*>(self->m_image->getSource(id));
- // if source is available
- if (src != NULL)
- {
- // return source
- Py_INCREF(src);
- return src;
- }
- }
- // source was not found
- Py_RETURN_NONE;
-}
-
-
-// set filter source object
-PyObject *Image_setSource(PyImage *self, PyObject *args)
-{
- // get arguments
- char *id;
- PyObject *obj;
- if (!PyArg_ParseTuple(args, "sO:setSource", &id, &obj))
- return NULL;
- if (self->m_image != NULL)
- {
- // check type of object
- if (pyImageTypes.in(Py_TYPE(obj)))
- {
- // convert to image struct
- PyImage * img = reinterpret_cast<PyImage*>(obj);
- // set source
- if (!self->m_image->setSource(id, img))
- {
- // if not set, retport error
- PyErr_SetString(PyExc_RuntimeError, "Invalid source or id");
- return NULL;
- }
- }
- // else report error
- else
- {
- PyErr_SetString(PyExc_RuntimeError, "Invalid type of object");
- return NULL;
- }
- }
- // return none
- Py_RETURN_NONE;
-}
-
-
-// get pixel filter object
-PyObject *Image_getFilter(PyImage *self, void *closure)
-{
- // if image object is available
- if (self->m_image != NULL)
- {
- // pixel filter object
- PyObject *filt = reinterpret_cast<PyObject*>(self->m_image->getFilter());
- // if filter is present
- if (filt != NULL)
- {
- // return it
- Py_INCREF(filt);
- return filt;
- }
- }
- // otherwise return none
- Py_RETURN_NONE;
-}
-
-
-// set pixel filter object
-int Image_setFilter(PyImage *self, PyObject *value, void *closure)
-{
- // if image object is available
- if (self->m_image != NULL)
- {
- // check new value
- if (value == NULL || !pyFilterTypes.in(Py_TYPE(value)))
- {
- // report value error
- PyErr_SetString(PyExc_TypeError, "Invalid type of value");
- return -1;
- }
- // set new value
- self->m_image->setFilter(reinterpret_cast<PyFilter*>(value));
- }
- // return success
- return 0;
-}
-PyObject *Image_valid(PyImage *self, void *closure)
-{
- if (self->m_image->isImageAvailable())
- {
- Py_RETURN_TRUE;
- }
- else
- {
- Py_RETURN_FALSE;
- }
-}
-
-static int Image_getbuffer(PyImage *self, Py_buffer *view, int flags)
-{
- unsigned int * image;
- int ret;
-
- try {
- // can throw in case of resize
- image = self->m_image->getImage();
- }
- catch (Exception & exp) {
- exp.report();
- return -1;
- }
-
- if (!image) {
- PyErr_SetString(PyExc_BufferError, "Image buffer is not available");
- return -1;
- }
- if (view == NULL)
- {
- self->m_image->m_exports++;
- return 0;
- }
- ret = PyBuffer_FillInfo(view, (PyObject *)self, image, self->m_image->getBuffSize(), 0, flags);
- if (ret >= 0)
- self->m_image->m_exports++;
- return ret;
-}
-
-static void Image_releaseBuffer(PyImage *self, Py_buffer *buffer)
-{
- self->m_image->m_exports--;
-}
-
-PyBufferProcs imageBufferProcs =
-{
- (getbufferproc)Image_getbuffer,
- (releasebufferproc)Image_releaseBuffer
-};
-
diff --git a/source/gameengine/VideoTexture/ImageBase.h b/source/gameengine/VideoTexture/ImageBase.h
deleted file mode 100644
index 5a09c9a67b3..00000000000
--- a/source/gameengine/VideoTexture/ImageBase.h
+++ /dev/null
@@ -1,392 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of blendTex library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file ImageBase.h
- * \ingroup bgevideotex
- */
-
-#ifndef __IMAGEBASE_H__
-#define __IMAGEBASE_H__
-
-#include "Common.h"
-
-#include <vector>
-#include "EXP_PyObjectPlus.h"
-
-#include "PyTypeList.h"
-
-#include "FilterBase.h"
-
-#include "GPU_glew.h"
-
-// forward declarations
-struct PyImage;
-class ImageSource;
-
-
-/// type for list of image sources
-typedef std::vector<ImageSource*> ImageSourceList;
-
-
-/// base class for image filters
-class ImageBase
-{
-public:
- /// constructor
- ImageBase (bool staticSrc = false);
- /// destructor
- virtual ~ImageBase(void);
- /// release contained objects, if returns true, object should be deleted
- virtual bool release(void);
-
- /// is an image available
- bool isImageAvailable(void)
- { return m_avail; }
- /// get image
- unsigned int *getImage(unsigned int texId = 0, double timestamp=-1.0);
- /// get image size
- short * getSize(void) { return m_size; }
- /// get image buffer size
- unsigned long getBuffSize(void)
- { return m_size[0] * m_size[1] * sizeof(unsigned int); }
- /// refresh image - invalidate its current content
- virtual void refresh(void);
-
- /// get scale
- bool getScale(void) { return m_scale; }
- /// set scale
- void setScale(bool scale) { m_scale = scale; m_scaleChange = true; }
- /// get vertical flip
- bool getFlip(void) { return m_flip; }
- /// set vertical flip
- void setFlip(bool flip) { m_flip = flip; }
- /// get Z buffer
- bool getZbuff(void) { return m_zbuff; }
- /// set Z buffer
- void setZbuff(bool zbuff) { m_zbuff = zbuff; }
- /// get depth
- bool getDepth(void) { return m_depth; }
- /// set depth
- void setDepth(bool depth) { m_depth = depth; }
-
- /// get source object
- PyImage * getSource(const char *id);
- /// set source object, return true, if source was set
- bool setSource(const char *id, PyImage *source);
-
- /// get pixel filter
- PyFilter * getFilter(void) { return m_pyfilter; }
- /// set pixel filter
- void setFilter(PyFilter * filt);
-
- /// calculate size(nearest power of 2)
- static short calcSize(short size);
-
- /// calculate image from sources and send it to a target buffer instead of a texture
- /// format is GL_RGBA or GL_BGRA
- virtual bool loadImage(unsigned int *buffer, unsigned int size, unsigned int format, double ts);
-
- /// swap the B and R channel in-place in the image buffer
- void swapImageBR();
-
- /// number of buffer pointing to m_image, public because not handled by this class
- int m_exports;
-
-protected:
- /// image buffer
- unsigned int * m_image;
- /// image buffer size
- unsigned int m_imgSize;
- /// image size
- short m_size[2];
- /// image is available
- bool m_avail;
-
- /// scale image to power 2 sizes
- bool m_scale;
- /// scale was changed
- bool m_scaleChange;
- /// flip image vertically
- bool m_flip;
- /// use the Z buffer as a texture
- bool m_zbuff;
- /// extract the Z buffer with unisgned int precision
- bool m_depth;
-
- /// source image list
- ImageSourceList m_sources;
- /// flag for disabling addition and deletion of sources
- bool m_staticSources;
-
- /// pixel filter
- PyFilter * m_pyfilter;
-
- /// initialize image data
- void init(short width, short height);
-
- /// find source
- ImageSourceList::iterator findSource(const char *id);
-
- /// create new source
- virtual ImageSource *newSource(const char *id) { return NULL; }
-
- /// check source sizes
- bool checkSourceSizes(void);
-
- /// calculate image from sources and set its availability
- virtual void calcImage(unsigned int texId, double ts) {}
-
- /// perform loop detection
- bool loopDetect(ImageBase * img);
-
- /// template for image conversion
- template<class FLT, class SRC> void convImage(FLT & filter, SRC srcBuff,
- short * srcSize)
- {
- // destination buffer
- unsigned int * dstBuff = m_image;
- // pixel size from filter
- unsigned int pixSize = filter.firstPixelSize();
- // if no scaling is needed
- if (srcSize[0] == m_size[0] && srcSize[1] == m_size[1])
- // if flipping isn't required
- if (!m_flip)
- // copy bitmap
- for (short y = 0; y < m_size[1]; ++y)
- for (short x = 0; x < m_size[0]; ++x, ++dstBuff, srcBuff += pixSize)
- // copy pixel
- *dstBuff = filter.convert(srcBuff, x, y, srcSize, pixSize);
- // otherwise flip image top to bottom
- else
- {
- // go to last row of image
- srcBuff += srcSize[0] * (srcSize[1] - 1) * pixSize;
- // copy bitmap
- for (short y = m_size[1] - 1; y >= 0; --y, srcBuff -= 2 * srcSize[0] * pixSize)
- for (short x = 0; x < m_size[0]; ++x, ++dstBuff, srcBuff += pixSize)
- // copy pixel
- *dstBuff = filter.convert(srcBuff, x, y, srcSize, pixSize);
- }
- // else scale picture (nearest neighbor)
- else
- {
- // interpolation accumulator
- int accHeight = srcSize[1] >> 1;
- // if flipping is required
- if (m_flip)
- // go to last row of image
- srcBuff += srcSize[0] * (srcSize[1] - 1) * pixSize;
- // process image rows
- for (int y = 0; y < srcSize[1]; ++y)
- {
- // increase height accum
- accHeight += m_size[1];
- // if pixel row has to be drawn
- if (accHeight >= srcSize[1])
- {
- // decrease accum
- accHeight -= srcSize[1];
- // width accum
- int accWidth = srcSize[0] >> 1;
- // process row
- for (int x = 0; x < srcSize[0]; ++x)
- {
- // increase width accum
- accWidth += m_size[0];
- // if pixel has to be drawn
- if (accWidth >= srcSize[0])
- {
- // decrease accum
- accWidth -= srcSize[0];
- // convert pixel
- *dstBuff = filter.convert(srcBuff, x, m_flip ? srcSize[1] - y - 1 : y,
- srcSize, pixSize);
- // next pixel
- ++dstBuff;
- }
- // shift source pointer
- srcBuff += pixSize;
- }
- }
- // if pixel row will not be drawn
- else
- // move source pointer to next row
- srcBuff += pixSize * srcSize[0];
- // if y flipping is required
- if (m_flip)
- // go to previous row of image
- srcBuff -= 2 * pixSize * srcSize[0];
- }
- }
- }
-
- // template for specific filter preprocessing
- template <class F, class SRC> void filterImage (F & filt, SRC srcBuff, short *srcSize)
- {
- // find first filter in chain
- FilterBase * firstFilter = NULL;
- if (m_pyfilter != NULL) firstFilter = m_pyfilter->m_filter->findFirst();
- // if first filter is available
- if (firstFilter != NULL)
- {
- // python wrapper for filter
- PyFilter pyFilt;
- pyFilt.m_filter = &filt;
- // set specified filter as first in chain
- firstFilter->setPrevious(&pyFilt, false);
- // convert video image
- convImage(*(m_pyfilter->m_filter), srcBuff, srcSize);
- // delete added filter
- firstFilter->setPrevious(NULL, false);
- }
- // otherwise use given filter for conversion
- else convImage(filt, srcBuff, srcSize);
- // source was processed
- m_avail = true;
- }
-};
-
-
-// python structure for image filter
-struct PyImage
-{
- PyObject_HEAD
- // source object
- ImageBase * m_image;
-};
-
-
-// size of id
-const int SourceIdSize = 32;
-
-
-/// class for source of image
-class ImageSource
-{
-public:
- /// constructor
- ImageSource (const char *id);
- /// destructor
- virtual ~ImageSource (void);
-
- /// get id
- const char * getId (void) { return m_id; }
- /// compare id to argument
- bool is (const char *id);
-
- /// get source object
- PyImage * getSource (void) { return m_source; }
- /// set source object
- void setSource (PyImage *source);
-
- /// get image from source
- unsigned int * getImage (double ts=-1.0);
- /// get buffered image
- unsigned int * getImageBuf (void) { return m_image; }
- /// refresh source
- void refresh (void);
-
- /// get image size
- short * getSize (void)
- {
- static short defSize [] = {0, 0};
- return m_source != NULL ? m_source->m_image->getSize() : defSize;
- }
-
-protected:
- /// id of source
- char m_id [SourceIdSize];
- /// pointer to source structure
- PyImage * m_source;
- /// buffered image from source
- unsigned int * m_image;
-
-private:
- /// default constructor is forbidden
- ImageSource (void) {}
-};
-
-// list of python image types
-extern PyTypeList pyImageTypes;
-
-
-// functions for python interface
-
-// object initialization
-template <class T> static int Image_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- PyImage *self = reinterpret_cast<PyImage *>(pySelf);
- // create source object
- if (self->m_image != NULL) delete self->m_image;
- self->m_image = new T();
- // initialization succeded
- return 0;
-}
-
-// object allocation
-PyObject *Image_allocNew(PyTypeObject *type, PyObject *args, PyObject *kwds);
-// object deallocation
-void Image_dealloc(PyImage *self);
-
-// get image data
-PyObject *Image_getImage(PyImage *self, char *mode);
-// get image size
-PyObject *Image_getSize(PyImage *self, void *closure);
-// refresh image - invalidate current content
-PyObject *Image_refresh(PyImage *self, PyObject *args);
-
-// get scale
-PyObject *Image_getScale(PyImage *self, void *closure);
-// set scale
-int Image_setScale(PyImage *self, PyObject *value, void *closure);
-// get flip
-PyObject *Image_getFlip(PyImage *self, void *closure);
-// set flip
-int Image_setFlip(PyImage *self, PyObject *value, void *closure);
-
-// get filter source object
-PyObject *Image_getSource(PyImage *self, PyObject *args);
-// set filter source object
-PyObject *Image_setSource(PyImage *self, PyObject *args);
-// get Z buffer
-PyObject *Image_getZbuff(PyImage *self, void *closure);
-// set Z buffer
-int Image_setZbuff(PyImage *self, PyObject *value, void *closure);
-// get depth
-PyObject *Image_getDepth(PyImage *self, void *closure);
-// set depth
-int Image_setDepth(PyImage *self, PyObject *value, void *closure);
-
-// get pixel filter object
-PyObject *Image_getFilter(PyImage *self, void *closure);
-// set pixel filter object
-int Image_setFilter(PyImage *self, PyObject *value, void *closure);
-// check if a buffer can be extracted
-PyObject *Image_valid(PyImage *self, void *closure);
-// for buffer access to PyImage objects
-extern PyBufferProcs imageBufferProcs;
-
-#endif
diff --git a/source/gameengine/VideoTexture/ImageBuff.cpp b/source/gameengine/VideoTexture/ImageBuff.cpp
deleted file mode 100644
index 77270865b17..00000000000
--- a/source/gameengine/VideoTexture/ImageBuff.cpp
+++ /dev/null
@@ -1,424 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/ImageBuff.cpp
- * \ingroup bgevideotex
- */
-
-// implementation
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "ImageBuff.h"
-#include "Exception.h"
-#include "ImageBase.h"
-#include "FilterSource.h"
-
-// use ImBuf API for image manipulation
-extern "C" {
-#include "IMB_imbuf_types.h"
-#include "IMB_imbuf.h"
-#include "bgl.h"
-};
-
-// default filter
-FilterRGB24 defFilter;
-
-// forward declaration;
-extern PyTypeObject ImageBuffType;
-
-static int ImageBuff_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- short width = -1;
- short height = -1;
- unsigned char color = 0;
- PyObject *py_scale = Py_False;
- ImageBuff *image;
-
- PyImage *self = reinterpret_cast<PyImage*>(pySelf);
- // create source object
- if (self->m_image != NULL)
- delete self->m_image;
- image = new ImageBuff();
- self->m_image = image;
-
- if (PyArg_ParseTuple(args, "hh|bO!:ImageBuff", &width, &height, &color, &PyBool_Type, &py_scale))
- {
- // initialize image buffer
- image->setScale(py_scale == Py_True);
- image->clear(width, height, color);
- }
- else
- {
- // check if at least one argument was passed
- if (width != -1 || height != -1)
- // yes and they didn't match => it's an error
- return -1;
- // empty argument list is okay
- PyErr_Clear();
- }
- // initialization succeded
- return 0;
-
-}
-
-ImageBuff::~ImageBuff (void)
-{
- if (m_imbuf)
- IMB_freeImBuf(m_imbuf);
-}
-
-
-// load image from buffer
-void ImageBuff::load(unsigned char *img, short width, short height)
-{
- // loading a new buffer implies to reset the imbuf if any, because the size may change
- if (m_imbuf)
- {
- IMB_freeImBuf(m_imbuf);
- m_imbuf = NULL;
- }
- // initialize image buffer
- init(width, height);
- // original size
- short orgSize[2] = {width, height};
- // is filter available
- if (m_pyfilter != NULL)
- // use it to process image
- convImage(*(m_pyfilter->m_filter), img, orgSize);
- else
- // otherwise use default filter
- convImage(defFilter, img, orgSize);
- // image is available
- m_avail = true;
-}
-
-void ImageBuff::clear(short width, short height, unsigned char color)
-{
- unsigned char *p;
- int size;
-
- // loading a new buffer implies to reset the imbuf if any, because the size may change
- if (m_imbuf)
- {
- IMB_freeImBuf(m_imbuf);
- m_imbuf = NULL;
- }
- // initialize image buffer
- init(width, height);
- // the width/height may be different due to scaling
- size = (m_size[0] * m_size[1]);
- // initialize memory with color for all channels
- memset(m_image, color, size*4);
- // and change the alpha channel
- p = &((unsigned char*)m_image)[3];
- for (; size>0; size--)
- {
- *p = 0xFF;
- p += 4;
- }
- // image is available
- m_avail = true;
-}
-
-// img must point to a array of RGBA data of size width*height
-void ImageBuff::plot(unsigned char *img, short width, short height, short x, short y, short mode)
-{
- struct ImBuf *tmpbuf;
-
- if (m_size[0] == 0 || m_size[1] == 0 || width <= 0 || height <= 0)
- return;
-
- if (!m_imbuf) {
- // allocate most basic imbuf, we will assign the rect buffer on the fly
- m_imbuf = IMB_allocImBuf(m_size[0], m_size[1], 0, 0);
- }
-
- tmpbuf = IMB_allocImBuf(width, height, 0, 0);
-
- // assign temporarily our buffer to the ImBuf buffer, we use the same format
- tmpbuf->rect = (unsigned int*)img;
- m_imbuf->rect = m_image;
- IMB_rectblend(m_imbuf, m_imbuf, tmpbuf, NULL, NULL, NULL, 0, x, y, x, y, 0, 0, width, height, (IMB_BlendMode)mode, false);
- // remove so that MB_freeImBuf will free our buffer
- m_imbuf->rect = NULL;
- tmpbuf->rect = NULL;
- IMB_freeImBuf(tmpbuf);
-}
-
-void ImageBuff::plot(ImageBuff *img, short x, short y, short mode)
-{
- if (m_size[0] == 0 || m_size[1] == 0 || img->m_size[0] == 0 || img->m_size[1] == 0)
- return;
-
- if (!m_imbuf) {
- // allocate most basic imbuf, we will assign the rect buffer on the fly
- m_imbuf = IMB_allocImBuf(m_size[0], m_size[1], 0, 0);
- }
- if (!img->m_imbuf) {
- // allocate most basic imbuf, we will assign the rect buffer on the fly
- img->m_imbuf = IMB_allocImBuf(img->m_size[0], img->m_size[1], 0, 0);
- }
- // assign temporarily our buffer to the ImBuf buffer, we use the same format
- img->m_imbuf->rect = img->m_image;
- m_imbuf->rect = m_image;
- IMB_rectblend(m_imbuf, m_imbuf, img->m_imbuf, NULL, NULL, NULL, 0, x, y, x, y, 0, 0, img->m_imbuf->x, img->m_imbuf->y, (IMB_BlendMode)mode, false);
- // remove so that MB_freeImBuf will free our buffer
- m_imbuf->rect = NULL;
- img->m_imbuf->rect = NULL;
-}
-
-
-// cast Image pointer to ImageBuff
-inline ImageBuff *getImageBuff(PyImage *self)
-{ return static_cast<ImageBuff *>(self->m_image); }
-
-
-// python methods
-
-static bool testPyBuffer(Py_buffer *buffer, int width, int height, unsigned int pixsize)
-{
- if (buffer->itemsize != 1)
- {
- PyErr_SetString(PyExc_ValueError, "Buffer must be an array of bytes");
- return false;
- }
- if (buffer->len != width*height*pixsize)
- {
- PyErr_SetString(PyExc_ValueError, "Buffer hasn't the correct size");
- return false;
- }
- // multi dimension are ok as long as there is no hole in the memory
- Py_ssize_t size = buffer->itemsize;
- for (int i=buffer->ndim-1; i>=0 ; i--)
- {
- if (buffer->suboffsets != NULL && buffer->suboffsets[i] >= 0)
- {
- PyErr_SetString(PyExc_ValueError, "Buffer must be of one block");
- return false;
- }
- if (buffer->strides != NULL && buffer->strides[i] != size)
- {
- PyErr_SetString(PyExc_ValueError, "Buffer must be of one block");
- return false;
- }
- if (i > 0)
- size *= buffer->shape[i];
- }
- return true;
-}
-
-static bool testBGLBuffer(Buffer *buffer, int width, int height, unsigned int pixsize)
-{
- unsigned int size = BGL_typeSize(buffer->type);
- for (int i=0; i<buffer->ndimensions; i++)
- {
- size *= buffer->dimensions[i];
- }
- if (size != width*height*pixsize)
- {
- PyErr_SetString(PyExc_ValueError, "Buffer hasn't the correct size");
- return false;
- }
- return true;
-}
-
-
-// load image
-static PyObject *load(PyImage *self, PyObject *args)
-{
- // parameters: string image buffer, its size, width, height
- Py_buffer buffer;
- Buffer *bglBuffer;
- short width;
- short height;
- unsigned int pixSize;
-
- // calc proper buffer size
- // use pixel size from filter
- if (self->m_image->getFilter() != NULL)
- pixSize = self->m_image->getFilter()->m_filter->firstPixelSize();
- else
- pixSize = defFilter.firstPixelSize();
-
- // parse parameters
- if (!PyArg_ParseTuple(args, "s*hh:load", &buffer, &width, &height))
- {
- PyErr_Clear();
- // check if it is BGL buffer
- if (!PyArg_ParseTuple(args, "O!hh:load", &BGL_bufferType, &bglBuffer, &width, &height))
- {
- // report error
- return NULL;
- }
- else
- {
- if (testBGLBuffer(bglBuffer, width, height, pixSize))
- {
- try
- {
- // if correct, load image
- getImageBuff(self)->load((unsigned char*)bglBuffer->buf.asvoid, width, height);
- }
- catch (Exception & exp)
- {
- exp.report();
- }
- }
- }
- }
- else
- {
- // check if buffer size is correct
- if (testPyBuffer(&buffer, width, height, pixSize))
- {
- try
- {
- // if correct, load image
- getImageBuff(self)->load((unsigned char*)buffer.buf, width, height);
- }
- catch (Exception & exp)
- {
- exp.report();
- }
- }
- PyBuffer_Release(&buffer);
- }
- if (PyErr_Occurred())
- return NULL;
- Py_RETURN_NONE;
-}
-
-static PyObject *plot(PyImage *self, PyObject *args)
-{
- PyImage * other;
- Buffer* bglBuffer;
- Py_buffer buffer;
- //unsigned char * buff;
- //unsigned int buffSize;
- short width;
- short height;
- short x, y;
- short mode = IMB_BLEND_COPY;
-
- if (PyArg_ParseTuple(args, "s*hhhh|h:plot", &buffer, &width, &height, &x, &y, &mode))
- {
- // correct decoding, verify that buffer size is correct
- // we need a continuous memory buffer
- if (testPyBuffer(&buffer, width, height, 4))
- {
- getImageBuff(self)->plot((unsigned char*)buffer.buf, width, height, x, y, mode);
- }
- PyBuffer_Release(&buffer);
- if (PyErr_Occurred())
- return NULL;
- Py_RETURN_NONE;
- }
- PyErr_Clear();
- // try the other format
- if (PyArg_ParseTuple(args, "O!hh|h:plot", &ImageBuffType, &other, &x, &y, &mode))
- {
- getImageBuff(self)->plot(getImageBuff(other), x, y, mode);
- Py_RETURN_NONE;
- }
- PyErr_Clear();
- // try the last format (BGL buffer)
- if (!PyArg_ParseTuple(args, "O!hhhh|h:plot", &BGL_bufferType, &bglBuffer, &width, &height, &x, &y, &mode))
- {
- PyErr_SetString(PyExc_TypeError, "Expecting ImageBuff or Py buffer or BGL buffer as first argument; width, height next; postion x, y and mode as last arguments");
- return NULL;
- }
- if (testBGLBuffer(bglBuffer, width, height, 4))
- {
- getImageBuff(self)->plot((unsigned char*)bglBuffer->buf.asvoid, width, height, x, y, mode);
- }
- if (PyErr_Occurred())
- return NULL;
- Py_RETURN_NONE;
-}
-
-// methods structure
-static PyMethodDef imageBuffMethods[] = {
- {"load", (PyCFunction)load, METH_VARARGS, "Load image from buffer"},
- {"plot", (PyCFunction)plot, METH_VARARGS, "update image buffer"},
- {NULL}
-};
-// attributes structure
-static PyGetSetDef imageBuffGetSets[] = {
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {NULL}
-};
-
-
-// define python type
-PyTypeObject ImageBuffType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.ImageBuff", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Image source from image buffer", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- imageBuffMethods, /* tp_methods */
- 0, /* tp_members */
- imageBuffGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)ImageBuff_init, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
-
diff --git a/source/gameengine/VideoTexture/ImageBuff.h b/source/gameengine/VideoTexture/ImageBuff.h
deleted file mode 100644
index 19299506747..00000000000
--- a/source/gameengine/VideoTexture/ImageBuff.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file ImageBuff.h
- * \ingroup bgevideotex
- */
-
-#ifndef __IMAGEBUFF_H__
-#define __IMAGEBUFF_H__
-
-
-#include "Common.h"
-
-#include "ImageBase.h"
-
-struct ImBuf;
-
-/// class for image buffer
-class ImageBuff : public ImageBase
-{
-private:
- struct ImBuf *m_imbuf; // temporary structure for buffer manipulation
-public:
- /// constructor
- ImageBuff (void) : ImageBase(true), m_imbuf(NULL) {}
-
- /// destructor
- virtual ~ImageBuff (void);
-
- /// load image from buffer
- void load (unsigned char * img, short width, short height);
- /// clear image with color set on RGB channels and 0xFF on alpha channel
- void clear (short width, short height, unsigned char color);
-
- /// plot image from extern RGBA buffer to image at position x,y using one of IMB_BlendMode
- void plot (unsigned char * img, short width, short height, short x, short y, short mode);
- /// plot image from other ImageBuf to image at position x,y using one of IMB_BlendMode
- void plot (ImageBuff* img, short x, short y, short mode);
-
- /// refresh image - do nothing
- virtual void refresh (void) {}
-};
-
-
-#endif
-
diff --git a/source/gameengine/VideoTexture/ImageMix.cpp b/source/gameengine/VideoTexture/ImageMix.cpp
deleted file mode 100644
index 2de00f5ba05..00000000000
--- a/source/gameengine/VideoTexture/ImageMix.cpp
+++ /dev/null
@@ -1,216 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/ImageMix.cpp
- * \ingroup bgevideotex
- */
-
-
-// implementation
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "ImageMix.h"
-
-#include "ImageBase.h"
-
-#include "Exception.h"
-
-
-// cast ImageSource pointer to ImageSourceMix
-inline ImageSourceMix *getImageSourceMix(ImageSource *src)
-{ return static_cast<ImageSourceMix*>(src); }
-
-
-// get weight
-short ImageMix::getWeight(const char *id)
-{
- // find source
- ImageSourceList::iterator src = findSource(id);
- // if found, return its weight
- return src != m_sources.end() ? getImageSourceMix(*src)->getWeight() : 0;
-}
-
-// set weight
-bool ImageMix::setWeight(const char *id, short weight)
-{
- // find source
- ImageSourceList::iterator src = findSource(id);
- // if source isn't found, report it
- if (src == m_sources.end()) return false;
- // set its weight
- getImageSourceMix(*src)->setWeight(weight);
- return true;
-}
-
-ExceptionID ImageSizesNotMatch;
-
-ExpDesc ImageSizesNotMatchDesc(ImageSizesNotMatch, "Image sizes of sources are different");
-
-// calculate image from sources and set its availability
-void ImageMix::calcImage(unsigned int texId, double ts)
-{
- // check source sizes
- if (!checkSourceSizes()) THRWEXCP(ImageSizesNotMatch, S_OK);
- // set offsets to image buffers
- for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
- // if image buffer is available
- if ((*it)->getImageBuf() != NULL)
- // set its offset
- getImageSourceMix(*it)->setOffset(m_sources[0]->getImageBuf());
- // otherwise don't calculate image
- else
- return;
- // if there is only single source
- if (m_sources.size() == 1)
- {
- // use single filter
- FilterBase mixFilt;
- // fiter and convert image
- filterImage(mixFilt, m_sources[0]->getImageBuf(), m_sources[0]->getSize());
- }
- // otherwise use mix filter to merge source images
- else
- {
- FilterImageMix mixFilt (m_sources);
- // fiter and convert image
- filterImage(mixFilt, m_sources[0]->getImageBuf(), m_sources[0]->getSize());
- }
-}
-
-
-
-// cast Image pointer to ImageMix
-inline ImageMix * getImageMix(PyImage *self)
-{ return static_cast<ImageMix*>(self->m_image); }
-
-
-// python methods
-
-// get source weight
-static PyObject *getWeight(PyImage *self, PyObject *args)
-{
- // weight
- short weight = 0;
- // get arguments
- char *id;
- if (!PyArg_ParseTuple(args, "s:getWeight", &id))
- return NULL;
- if (self->m_image != NULL)
- // get weight
- weight = getImageMix(self)->getWeight(id);
- // return weight
- return Py_BuildValue("h", weight);
-}
-
-
-// set source weight
-static PyObject *setWeight(PyImage *self, PyObject *args)
-{
- // get arguments
- char *id;
- short weight = 0;
- if (!PyArg_ParseTuple(args, "sh:setWeight", &id, &weight))
- return NULL;
- if (self->m_image != NULL)
- // set weight
- if (!getImageMix(self)->setWeight(id, weight))
- {
- // if not set, report error
- PyErr_SetString(PyExc_RuntimeError, "Invalid id of source");
- return NULL;
- }
- // return none
- Py_RETURN_NONE;
-}
-
-
-// methods structure
-static PyMethodDef imageMixMethods[] = {
- {"getSource", (PyCFunction)Image_getSource, METH_VARARGS, "get image source"},
- {"setSource", (PyCFunction)Image_setSource, METH_VARARGS, "set image source"},
- {"getWeight", (PyCFunction)getWeight, METH_VARARGS, "get image source weight"},
- {"setWeight", (PyCFunction)setWeight, METH_VARARGS, "set image source weight"},
- // methods from ImageBase class
- {"refresh", (PyCFunction)Image_refresh, METH_VARARGS, "Refresh image - invalidate its current content"},
- {NULL}
-};
-// attributes structure
-static PyGetSetDef imageMixGetSets[] = {
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {NULL}
-};
-
-
-// define python type
-PyTypeObject ImageMixType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.ImageMix", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Image mixer", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- imageMixMethods, /* tp_methods */
- 0, /* tp_members */
- imageMixGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Image_init<ImageMix>, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
-
diff --git a/source/gameengine/VideoTexture/ImageMix.h b/source/gameengine/VideoTexture/ImageMix.h
deleted file mode 100644
index 161a8b375ea..00000000000
--- a/source/gameengine/VideoTexture/ImageMix.h
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file ImageMix.h
- * \ingroup bgevideotex
- */
-
-#ifndef __IMAGEMIX_H__
-#define __IMAGEMIX_H__
-
-
-#include "Common.h"
-
-#include "ImageBase.h"
-#include "FilterBase.h"
-
-
-/// class for source mixing
-class ImageSourceMix : public ImageSource
-{
-public:
- /// constructor
- ImageSourceMix (const char *id) : ImageSource(id), m_offset(0), m_weight(0x100) {}
- /// destructor
- virtual ~ImageSourceMix (void) {}
-
- /// get offset
- long long getOffset (void) { return m_offset; }
- /// set offset
- void setOffset (unsigned int * firstImg) { m_offset = m_image - firstImg; }
-
- /// get weight
- short getWeight (void) { return m_weight; }
- /// set weight
- void setWeight (short weight) { m_weight = weight; }
-
-protected:
- /// buffer offset to the first source buffer
- long long m_offset;
- /// source weight
- short m_weight;
-};
-
-
-/// class for image mixer
-class ImageMix : public ImageBase
-{
-public:
- /// constructor
- ImageMix (void) : ImageBase(false) {}
-
- /// destructor
- virtual ~ImageMix (void) {}
-
- /// get weight
- short getWeight(const char *id);
- /// set weight
- bool setWeight(const char *id, short weight);
-
-protected:
-
- /// create new source
- virtual ImageSource *newSource(const char *id) { return new ImageSourceMix(id); }
-
- /// calculate image from sources and set its availability
- virtual void calcImage (unsigned int texId, double ts);
-};
-
-
-/// pixel filter for image mixer
-class FilterImageMix : public FilterBase
-{
-public:
- /// constructor
- FilterImageMix (ImageSourceList & sources) : m_sources(sources) {}
- /// destructor
- virtual ~FilterImageMix (void) {}
-
-protected:
- /// source list
- ImageSourceList & m_sources;
-
- /// filter pixel, source int buffer
- virtual unsigned int filter (unsigned int * src, short x, short y,
- short * size, unsigned int pixSize, unsigned int val = 0)
- {
- // resulting pixel color
- int color[] = {0, 0, 0, 0};
- // iterate sources
- for (ImageSourceList::iterator it = m_sources.begin(); it != m_sources.end(); ++it)
- {
- // get pointer to mixer source
- ImageSourceMix * mixSrc = static_cast<ImageSourceMix*>(*it);
- // add weighted source pixel to result
- color[0] += mixSrc->getWeight() * (src[mixSrc->getOffset()] & 0xFF);
- color[1] += mixSrc->getWeight() * ((src[mixSrc->getOffset()] >> 8) & 0xFF);
- color[2] += mixSrc->getWeight() * ((src[mixSrc->getOffset()] >> 16) & 0xFF);
- color[3] += mixSrc->getWeight() * ((src[mixSrc->getOffset()] >> 24) & 0xFF);
- }
- // return resulting color
- return ((color[0] >> 8) & 0xFF) | (color[1] & 0xFF00)
- | ((color[2] << 8) & 0xFF0000) | ((color[3] << 16) & 0xFF000000);
- }
-};
-
-
-#endif
-
diff --git a/source/gameengine/VideoTexture/ImageRender.cpp b/source/gameengine/VideoTexture/ImageRender.cpp
deleted file mode 100644
index 57062343b67..00000000000
--- a/source/gameengine/VideoTexture/ImageRender.cpp
+++ /dev/null
@@ -1,946 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/ImageRender.cpp
- * \ingroup bgevideotex
- */
-
-// implementation
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-#include <float.h>
-#include <math.h>
-
-
-#include "GPU_glew.h"
-
-#include "KX_PythonInit.h"
-#include "DNA_scene_types.h"
-#include "RAS_CameraData.h"
-#include "RAS_MeshObject.h"
-#include "RAS_Polygon.h"
-#include "RAS_IOffScreen.h"
-#include "RAS_ISync.h"
-#include "BLI_math.h"
-
-#include "ImageRender.h"
-#include "ImageBase.h"
-#include "BlendType.h"
-#include "Exception.h"
-#include "Texture.h"
-
-ExceptionID SceneInvalid, CameraInvalid, ObserverInvalid, OffScreenInvalid;
-ExceptionID MirrorInvalid, MirrorSizeInvalid, MirrorNormalInvalid, MirrorHorizontal, MirrorTooSmall;
-ExpDesc SceneInvalidDesc(SceneInvalid, "Scene object is invalid");
-ExpDesc CameraInvalidDesc(CameraInvalid, "Camera object is invalid");
-ExpDesc ObserverInvalidDesc(ObserverInvalid, "Observer object is invalid");
-ExpDesc OffScreenInvalidDesc(OffScreenInvalid, "Offscreen object is invalid");
-ExpDesc MirrorInvalidDesc(MirrorInvalid, "Mirror object is invalid");
-ExpDesc MirrorSizeInvalidDesc(MirrorSizeInvalid, "Mirror has no vertex or no size");
-ExpDesc MirrorNormalInvalidDesc(MirrorNormalInvalid, "Cannot determine mirror plane");
-ExpDesc MirrorHorizontalDesc(MirrorHorizontal, "Mirror is horizontal in local space");
-ExpDesc MirrorTooSmallDesc(MirrorTooSmall, "Mirror is too small");
-
-// constructor
-ImageRender::ImageRender (KX_Scene *scene, KX_Camera * camera, PyRASOffScreen * offscreen) :
- ImageViewport(offscreen),
- m_render(true),
- m_done(false),
- m_scene(scene),
- m_camera(camera),
- m_owncamera(false),
- m_offscreen(offscreen),
- m_sync(NULL),
- m_observer(NULL),
- m_mirror(NULL),
- m_clip(100.f),
- m_mirrorHalfWidth(0.f),
- m_mirrorHalfHeight(0.f)
-{
- // initialize background color to scene background color as default
- setBackgroundFromScene(m_scene);
- // retrieve rendering objects
- m_engine = KX_GetActiveEngine();
- m_rasterizer = m_engine->GetRasterizer();
- m_canvas = m_engine->GetCanvas();
- // keep a reference to the offscreen buffer
- if (m_offscreen) {
- Py_INCREF(m_offscreen);
- }
-}
-
-// destructor
-ImageRender::~ImageRender (void)
-{
- if (m_owncamera)
- m_camera->Release();
- if (m_sync)
- delete m_sync;
- Py_XDECREF(m_offscreen);
-}
-
-// get background color
-float ImageRender::getBackground (int idx)
-{
- return (idx < 0 || idx > 3) ? 0.0f : m_background[idx] * 255.0f;
-}
-
-// set background color
-void ImageRender::setBackground (float red, float green, float blue, float alpha)
-{
- m_background[0] = (red < 0.0f) ? 0.0f : (red > 255.0f) ? 1.0f : red / 255.0f;
- m_background[1] = (green < 0.0f) ? 0.0f : (green > 255.0f) ? 1.0f : green / 255.0f;
- m_background[2] = (blue < 0.0f) ? 0.0f : (blue > 255.0f) ? 1.0f : blue / 255.0f;
- m_background[3] = (alpha < 0.0f) ? 0.0f : (alpha > 255.0f) ? 1.0f : alpha / 255.0f;
-}
-
-// set background color from scene
-void ImageRender::setBackgroundFromScene (KX_Scene *scene)
-{
- if (scene) {
- const float *background_color = scene->GetWorldInfo()->getBackColorConverted();
- copy_v3_v3(m_background, background_color);
- m_background[3] = 1.0f;
- }
- else {
- const float blue_color[] = {0.0f, 0.0f, 1.0f, 1.0f};
- copy_v4_v4(m_background, blue_color);
- }
-}
-
-
-// capture image from viewport
-void ImageRender::calcViewport (unsigned int texId, double ts, unsigned int format)
-{
- // render the scene from the camera
- if (!m_done) {
- if (!Render()) {
- return;
- }
- }
- else if (m_offscreen) {
- m_offscreen->ofs->Bind(RAS_IOffScreen::RAS_OFS_BIND_READ);
- }
- // wait until all render operations are completed
- WaitSync();
- // get image from viewport (or FBO)
- ImageViewport::calcViewport(texId, ts, format);
- if (m_offscreen) {
- m_offscreen->ofs->Unbind();
- }
-}
-
-bool ImageRender::Render()
-{
- RAS_FrameFrustum frustum;
-
- if (!m_render ||
- m_rasterizer->GetDrawingMode() != RAS_IRasterizer::KX_TEXTURED || // no need for texture
- m_camera->GetViewport() || // camera must be inactive
- m_camera == m_scene->GetActiveCamera())
- {
- // no need to compute texture in non texture rendering
- return false;
- }
-
- if (!m_scene->IsShadowDone())
- m_engine->RenderShadowBuffers(m_scene);
-
- if (m_mirror)
- {
- // mirror mode, compute camera frustum, position and orientation
- // convert mirror position and normal in world space
- const MT_Matrix3x3 & mirrorObjWorldOri = m_mirror->GetSGNode()->GetWorldOrientation();
- const MT_Point3 & mirrorObjWorldPos = m_mirror->GetSGNode()->GetWorldPosition();
- const MT_Vector3 & mirrorObjWorldScale = m_mirror->GetSGNode()->GetWorldScaling();
- MT_Point3 mirrorWorldPos =
- mirrorObjWorldPos + mirrorObjWorldScale * (mirrorObjWorldOri * m_mirrorPos);
- MT_Vector3 mirrorWorldZ = mirrorObjWorldOri * m_mirrorZ;
- // get observer world position
- const MT_Point3 & observerWorldPos = m_observer->GetSGNode()->GetWorldPosition();
- // get plane D term = mirrorPos . normal
- MT_Scalar mirrorPlaneDTerm = mirrorWorldPos.dot(mirrorWorldZ);
- // compute distance of observer to mirror = D - observerPos . normal
- MT_Scalar observerDistance = mirrorPlaneDTerm - observerWorldPos.dot(mirrorWorldZ);
- // if distance < 0.01 => observer is on wrong side of mirror, don't render
- if (observerDistance < 0.01)
- return false;
- // set camera world position = observerPos + normal * 2 * distance
- MT_Point3 cameraWorldPos = observerWorldPos + (MT_Scalar(2.0)*observerDistance)*mirrorWorldZ;
- m_camera->GetSGNode()->SetLocalPosition(cameraWorldPos);
- // set camera orientation: z=normal, y=mirror_up in world space, x= y x z
- MT_Vector3 mirrorWorldY = mirrorObjWorldOri * m_mirrorY;
- MT_Vector3 mirrorWorldX = mirrorObjWorldOri * m_mirrorX;
- MT_Matrix3x3 cameraWorldOri(
- mirrorWorldX[0], mirrorWorldY[0], mirrorWorldZ[0],
- mirrorWorldX[1], mirrorWorldY[1], mirrorWorldZ[1],
- mirrorWorldX[2], mirrorWorldY[2], mirrorWorldZ[2]);
- m_camera->GetSGNode()->SetLocalOrientation(cameraWorldOri);
- m_camera->GetSGNode()->UpdateWorldData(0.0);
- // compute camera frustum:
- // get position of mirror relative to camera: offset = mirrorPos-cameraPos
- MT_Vector3 mirrorOffset = mirrorWorldPos - cameraWorldPos;
- // convert to camera orientation
- mirrorOffset = mirrorOffset * cameraWorldOri;
- // scale mirror size to world scale:
- // get closest local axis for mirror Y and X axis and scale height and width by local axis scale
- MT_Scalar x, y;
- x = fabs(m_mirrorY[0]);
- y = fabs(m_mirrorY[1]);
- float height = (x > y) ?
- ((x > fabs(m_mirrorY[2])) ? mirrorObjWorldScale[0] : mirrorObjWorldScale[2]):
- ((y > fabs(m_mirrorY[2])) ? mirrorObjWorldScale[1] : mirrorObjWorldScale[2]);
- x = fabs(m_mirrorX[0]);
- y = fabs(m_mirrorX[1]);
- float width = (x > y) ?
- ((x > fabs(m_mirrorX[2])) ? mirrorObjWorldScale[0] : mirrorObjWorldScale[2]):
- ((y > fabs(m_mirrorX[2])) ? mirrorObjWorldScale[1] : mirrorObjWorldScale[2]);
- width *= m_mirrorHalfWidth;
- height *= m_mirrorHalfHeight;
- // left = offsetx-width
- // right = offsetx+width
- // top = offsety+height
- // bottom = offsety-height
- // near = -offsetz
- // far = near+100
- frustum.x1 = mirrorOffset[0]-width;
- frustum.x2 = mirrorOffset[0]+width;
- frustum.y1 = mirrorOffset[1]-height;
- frustum.y2 = mirrorOffset[1]+height;
- frustum.camnear = -mirrorOffset[2];
- frustum.camfar = -mirrorOffset[2]+m_clip;
- }
- // Store settings to be restored later
- const RAS_IRasterizer::StereoMode stereomode = m_rasterizer->GetStereoMode();
- RAS_Rect area = m_canvas->GetWindowArea();
-
- // The screen area that ImageViewport will copy is also the rendering zone
- if (m_offscreen) {
- // bind the fbo and set the viewport to full size
- m_offscreen->ofs->Bind(RAS_IOffScreen::RAS_OFS_BIND_RENDER);
- // this is needed to stop crashing in canvas check
- m_canvas->UpdateViewPort(0, 0, m_offscreen->ofs->GetWidth(), m_offscreen->ofs->GetHeight());
- }
- else {
- m_canvas->SetViewPort(m_position[0], m_position[1], m_position[0]+m_capSize[0]-1, m_position[1]+m_capSize[1]-1);
- }
- m_canvas->ClearColor(m_background[0], m_background[1], m_background[2], m_background[3]);
- m_canvas->ClearBuffer(RAS_ICanvas::COLOR_BUFFER|RAS_ICanvas::DEPTH_BUFFER);
- m_rasterizer->BeginFrame(m_engine->GetClockTime());
- m_scene->GetWorldInfo()->UpdateWorldSettings();
- m_rasterizer->SetAuxilaryClientInfo(m_scene);
- m_rasterizer->DisplayFog();
- // matrix calculation, don't apply any of the stereo mode
- m_rasterizer->SetStereoMode(RAS_IRasterizer::RAS_STEREO_NOSTEREO);
- if (m_mirror)
- {
- // frustum was computed above
- // get frustum matrix and set projection matrix
- MT_Matrix4x4 projmat = m_rasterizer->GetFrustumMatrix(
- frustum.x1, frustum.x2, frustum.y1, frustum.y2, frustum.camnear, frustum.camfar);
-
- m_camera->SetProjectionMatrix(projmat);
- }
- else if (m_camera->hasValidProjectionMatrix()) {
- m_rasterizer->SetProjectionMatrix(m_camera->GetProjectionMatrix());
- }
- else {
- float lens = m_camera->GetLens();
- float sensor_x = m_camera->GetSensorWidth();
- float sensor_y = m_camera->GetSensorHeight();
- float shift_x = m_camera->GetShiftHorizontal();
- float shift_y = m_camera->GetShiftVertical();
- bool orthographic = !m_camera->GetCameraData()->m_perspective;
- float nearfrust = m_camera->GetCameraNear();
- float farfrust = m_camera->GetCameraFar();
- float aspect_ratio = 1.0f;
- Scene *blenderScene = m_scene->GetBlenderScene();
- MT_Matrix4x4 projmat;
-
- // compute the aspect ratio from frame blender scene settings so that render to texture
- // works the same in Blender and in Blender player
- if (blenderScene->r.ysch != 0)
- aspect_ratio = float(blenderScene->r.xsch*blenderScene->r.xasp) / float(blenderScene->r.ysch*blenderScene->r.yasp);
-
- if (orthographic) {
-
- RAS_FramingManager::ComputeDefaultOrtho(
- nearfrust,
- farfrust,
- m_camera->GetScale(),
- aspect_ratio,
- m_camera->GetSensorFit(),
- shift_x,
- shift_y,
- frustum
- );
-
- projmat = m_rasterizer->GetOrthoMatrix(
- frustum.x1, frustum.x2, frustum.y1, frustum.y2, frustum.camnear, frustum.camfar);
- }
- else {
- RAS_FramingManager::ComputeDefaultFrustum(
- nearfrust,
- farfrust,
- lens,
- sensor_x,
- sensor_y,
- RAS_SENSORFIT_AUTO,
- shift_x,
- shift_y,
- aspect_ratio,
- frustum);
-
- projmat = m_rasterizer->GetFrustumMatrix(
- frustum.x1, frustum.x2, frustum.y1, frustum.y2, frustum.camnear, frustum.camfar);
- }
- m_camera->SetProjectionMatrix(projmat);
- }
-
- MT_Transform camtrans(m_camera->GetWorldToCamera());
- MT_Matrix4x4 viewmat(camtrans);
-
- m_rasterizer->SetViewMatrix(viewmat, m_camera->NodeGetWorldOrientation(), m_camera->NodeGetWorldPosition(), m_camera->NodeGetLocalScaling(), m_camera->GetCameraData()->m_perspective);
- m_camera->SetModelviewMatrix(viewmat);
- // restore the stereo mode now that the matrix is computed
- m_rasterizer->SetStereoMode(stereomode);
-
- if (m_rasterizer->Stereo()) {
- // stereo mode change render settings that disturb this render, cancel them all
- // we don't need to restore them as they are set before each frame render.
- glDrawBuffer(GL_BACK_LEFT);
- glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
- glDisable(GL_POLYGON_STIPPLE);
- }
-
- m_scene->CalculateVisibleMeshes(m_rasterizer,m_camera);
-
- m_engine->UpdateAnimations(m_scene);
-
- m_scene->RenderBuckets(camtrans, m_rasterizer);
-
- m_scene->RenderFonts();
-
- // restore the canvas area now that the render is completed
- m_canvas->GetWindowArea() = area;
- m_canvas->EndFrame();
-
- // In case multisample is active, blit the FBO
- if (m_offscreen)
- m_offscreen->ofs->Blit();
- // end of all render operations, let's create a sync object just in case
- if (m_sync) {
- // a sync from a previous render, should not happen
- delete m_sync;
- m_sync = NULL;
- }
- m_sync = m_rasterizer->CreateSync(RAS_ISync::RAS_SYNC_TYPE_FENCE);
- // remember that we have done render
- m_done = true;
- // the image is not available at this stage
- m_avail = false;
- return true;
-}
-
-void ImageRender::Unbind()
-{
- if (m_offscreen)
- {
- m_offscreen->ofs->Unbind();
- }
-}
-
-void ImageRender::WaitSync()
-{
- if (m_sync) {
- m_sync->Wait();
- // done with it, deleted it
- delete m_sync;
- m_sync = NULL;
- }
- if (m_offscreen) {
- // this is needed to finalize the image if the target is a texture
- m_offscreen->ofs->MipMap();
- }
- // all rendered operation done and complete, invalidate render for next time
- m_done = false;
-}
-
-// cast Image pointer to ImageRender
-inline ImageRender * getImageRender (PyImage *self)
-{ return static_cast<ImageRender*>(self->m_image); }
-
-
-// python methods
-
-// Blender Scene type
-static BlendType<KX_Scene> sceneType ("KX_Scene");
-// Blender Camera type
-static BlendType<KX_Camera> cameraType ("KX_Camera");
-
-
-// object initialization
-static int ImageRender_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- // parameters - scene object
- PyObject *scene;
- // camera object
- PyObject *camera;
- // offscreen buffer object
- PyRASOffScreen *offscreen = NULL;
- // parameter keywords
- static const char *kwlist[] = {"sceneObj", "cameraObj", "ofsObj", NULL};
- // get parameters
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OO|O",
- const_cast<char**>(kwlist), &scene, &camera, &offscreen))
- return -1;
- try
- {
- // get scene pointer
- KX_Scene * scenePtr (NULL);
- if (scene != NULL) scenePtr = sceneType.checkType(scene);
- // throw exception if scene is not available
- if (scenePtr == NULL) THRWEXCP(SceneInvalid, S_OK);
-
- // get camera pointer
- KX_Camera * cameraPtr (NULL);
- if (camera != NULL) cameraPtr = cameraType.checkType(camera);
- // throw exception if camera is not available
- if (cameraPtr == NULL) THRWEXCP(CameraInvalid, S_OK);
-
- if (offscreen) {
- if (Py_TYPE(offscreen) != &PyRASOffScreen_Type) {
- THRWEXCP(OffScreenInvalid, S_OK);
- }
- }
- // get pointer to image structure
- PyImage *self = reinterpret_cast<PyImage*>(pySelf);
- // create source object
- if (self->m_image != NULL) delete self->m_image;
- self->m_image = new ImageRender(scenePtr, cameraPtr, offscreen);
- }
- catch (Exception & exp)
- {
- exp.report();
- return -1;
- }
- // initialization succeded
- return 0;
-}
-
-static PyObject *ImageRender_refresh(PyImage *self, PyObject *args)
-{
- ImageRender *imageRender = getImageRender(self);
-
- if (!imageRender) {
- PyErr_SetString(PyExc_TypeError, "Incomplete ImageRender() object");
- return NULL;
- }
- if (PyArg_ParseTuple(args, "")) {
- // refresh called with no argument.
- // For other image objects it simply invalidates the image buffer
- // For ImageRender it triggers a render+sync
- // Note that this only makes sense when doing offscreen render on texture
- if (!imageRender->isDone()) {
- if (!imageRender->Render()) {
- Py_RETURN_FALSE;
- }
- // as we are not trying to read the pixels, just unbind
- imageRender->Unbind();
- }
- // wait until all render operations are completed
- // this will also finalize the texture
- imageRender->WaitSync();
- Py_RETURN_TRUE;
- }
- else {
- // fallback on standard processing
- PyErr_Clear();
- return Image_refresh(self, args);
- }
-}
-
-// refresh image
-static PyObject *ImageRender_render(PyImage *self)
-{
- ImageRender *imageRender = getImageRender(self);
-
- if (!imageRender) {
- PyErr_SetString(PyExc_TypeError, "Incomplete ImageRender() object");
- return NULL;
- }
- if (!imageRender->Render()) {
- Py_RETURN_FALSE;
- }
- // we are not reading the pixels now, unbind
- imageRender->Unbind();
- Py_RETURN_TRUE;
-}
-
-
-// get background color
-static PyObject *getBackground (PyImage *self, void *closure)
-{
- return Py_BuildValue("[ffff]",
- getImageRender(self)->getBackground(0),
- getImageRender(self)->getBackground(1),
- getImageRender(self)->getBackground(2),
- getImageRender(self)->getBackground(3));
-}
-
-// set color
-static int setBackground(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 4
- || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 0)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)))
- || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 1)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
- || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 2)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 2)))
- || (!PyFloat_Check(PySequence_Fast_GET_ITEM(value, 3)) && !PyLong_Check(PySequence_Fast_GET_ITEM(value, 3)))) {
-
- PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 4 floats or ints between 0.0 and 255.0");
- return -1;
- }
- // set background color
- getImageRender(self)->setBackground(
- PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0)),
- PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1)),
- PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 2)),
- PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 3)));
- // success
- return 0;
-}
-
-
-// methods structure
-static PyMethodDef imageRenderMethods[] =
-{ // methods from ImageBase class
- {"refresh", (PyCFunction)ImageRender_refresh, METH_VARARGS, "Refresh image - invalidate its current content after optionally transferring its content to a target buffer"},
- {"render", (PyCFunction)ImageRender_render, METH_NOARGS, "Render scene - run before refresh() to performs asynchronous render"},
- {NULL}
-};
-// attributes structure
-static PyGetSetDef imageRenderGetSets[] =
-{
- {(char*)"background", (getter)getBackground, (setter)setBackground, (char*)"background color", NULL},
- // attribute from ImageViewport
- {(char*)"capsize", (getter)ImageViewport_getCaptureSize, (setter)ImageViewport_setCaptureSize, (char*)"size of render area", NULL},
- {(char*)"alpha", (getter)ImageViewport_getAlpha, (setter)ImageViewport_setAlpha, (char*)"use alpha in texture", NULL},
- {(char*)"whole", (getter)ImageViewport_getWhole, (setter)ImageViewport_setWhole, (char*)"use whole viewport to render", NULL},
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"zbuff", (getter)Image_getZbuff, (setter)Image_setZbuff, (char*)"use depth buffer as texture", NULL},
- {(char*)"depth", (getter)Image_getDepth, (setter)Image_setDepth, (char*)"get depth information from z-buffer using unsigned int precision", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {NULL}
-};
-
-
-// define python type
-PyTypeObject ImageRenderType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.ImageRender", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Image source from render", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- imageRenderMethods, /* tp_methods */
- 0, /* tp_members */
- imageRenderGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)ImageRender_init, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
-
-// object initialization
-static int ImageMirror_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- // parameters - scene object
- PyObject *scene;
- // reference object for mirror
- PyObject *observer;
- // object holding the mirror
- PyObject *mirror;
- // material of the mirror
- short materialID = 0;
- // parameter keywords
- static const char *kwlist[] = {"scene", "observer", "mirror", "material", NULL};
- // get parameters
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "OOO|h",
- const_cast<char**>(kwlist), &scene, &observer, &mirror, &materialID))
- return -1;
- try
- {
- // get scene pointer
- KX_Scene * scenePtr (NULL);
- if (scene != NULL && PyObject_TypeCheck(scene, &KX_Scene::Type))
- scenePtr = static_cast<KX_Scene*>BGE_PROXY_REF(scene);
- else
- THRWEXCP(SceneInvalid, S_OK);
-
- if (scenePtr==NULL) /* in case the python proxy reference is invalid */
- THRWEXCP(SceneInvalid, S_OK);
-
- // get observer pointer
- KX_GameObject * observerPtr (NULL);
- if (observer != NULL && PyObject_TypeCheck(observer, &KX_GameObject::Type))
- observerPtr = static_cast<KX_GameObject*>BGE_PROXY_REF(observer);
- else if (observer != NULL && PyObject_TypeCheck(observer, &KX_Camera::Type))
- observerPtr = static_cast<KX_Camera*>BGE_PROXY_REF(observer);
- else
- THRWEXCP(ObserverInvalid, S_OK);
-
- if (observerPtr==NULL) /* in case the python proxy reference is invalid */
- THRWEXCP(ObserverInvalid, S_OK);
-
- // get mirror pointer
- KX_GameObject * mirrorPtr (NULL);
- if (mirror != NULL && PyObject_TypeCheck(mirror, &KX_GameObject::Type))
- mirrorPtr = static_cast<KX_GameObject*>BGE_PROXY_REF(mirror);
- else
- THRWEXCP(MirrorInvalid, S_OK);
-
- if (mirrorPtr==NULL) /* in case the python proxy reference is invalid */
- THRWEXCP(MirrorInvalid, S_OK);
-
- // locate the material in the mirror
- RAS_IPolyMaterial * material = getMaterial(mirror, materialID);
- if (material == NULL)
- THRWEXCP(MaterialNotAvail, S_OK);
-
- // get pointer to image structure
- PyImage *self = reinterpret_cast<PyImage*>(pySelf);
-
- // create source object
- if (self->m_image != NULL)
- {
- delete self->m_image;
- self->m_image = NULL;
- }
- self->m_image = new ImageRender(scenePtr, observerPtr, mirrorPtr, material);
- }
- catch (Exception & exp)
- {
- exp.report();
- return -1;
- }
- // initialization succeeded
- return 0;
-}
-
-// get background color
-static PyObject *getClip (PyImage *self, void *closure)
-{
- return PyFloat_FromDouble(getImageRender(self)->getClip());
-}
-
-// set clip
-static int setClip(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- double clip;
- if (value == NULL || !PyFloat_Check(value) || (clip = PyFloat_AsDouble(value)) < 0.01 || clip > 5000.0)
- {
- PyErr_SetString(PyExc_TypeError, "The value must be an float between 0.01 and 5000");
- return -1;
- }
- // set background color
- getImageRender(self)->setClip(float(clip));
- // success
- return 0;
-}
-
-// attributes structure
-static PyGetSetDef imageMirrorGetSets[] =
-{
- {(char*)"clip", (getter)getClip, (setter)setClip, (char*)"clipping distance", NULL},
- // attribute from ImageRender
- {(char*)"background", (getter)getBackground, (setter)setBackground, (char*)"background color", NULL},
- // attribute from ImageViewport
- {(char*)"capsize", (getter)ImageViewport_getCaptureSize, (setter)ImageViewport_setCaptureSize, (char*)"size of render area", NULL},
- {(char*)"alpha", (getter)ImageViewport_getAlpha, (setter)ImageViewport_setAlpha, (char*)"use alpha in texture", NULL},
- {(char*)"whole", (getter)ImageViewport_getWhole, (setter)ImageViewport_setWhole, (char*)"use whole viewport to render", NULL},
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"zbuff", (getter)Image_getZbuff, (setter)Image_setZbuff, (char*)"use depth buffer as texture", NULL},
- {(char*)"depth", (getter)Image_getDepth, (setter)Image_setDepth, (char*)"get depth information from z-buffer using unsigned int precision", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {NULL}
-};
-
-
-// constructor
-ImageRender::ImageRender (KX_Scene *scene, KX_GameObject *observer, KX_GameObject *mirror, RAS_IPolyMaterial *mat) :
- ImageViewport(),
- m_render(false),
- m_done(false),
- m_scene(scene),
- m_offscreen(NULL),
- m_sync(NULL),
- m_observer(observer),
- m_mirror(mirror),
- m_clip(100.f)
-{
- // this constructor is used for automatic planar mirror
- // create a camera, take all data by default, in any case we will recompute the frustum on each frame
- RAS_CameraData camdata;
- vector<RAS_TexVert*> mirrorVerts;
- vector<RAS_TexVert*>::iterator it;
- float mirrorArea = 0.f;
- float mirrorNormal[3] = {0.f, 0.f, 0.f};
- float mirrorUp[3];
- float dist, vec[3], axis[3];
- float zaxis[3] = {0.f, 0.f, 1.f};
- float yaxis[3] = {0.f, 1.f, 0.f};
- float mirrorMat[3][3];
- float left, right, top, bottom, back;
- // make sure this camera will delete its node
- m_camera= new KX_Camera(scene, KX_Scene::m_callbacks, camdata, true, true);
- m_camera->SetName("__mirror__cam__");
- // don't add the camera to the scene object list, it doesn't need to be accessible
- m_owncamera = true;
- // retrieve rendering objects
- m_engine = KX_GetActiveEngine();
- m_rasterizer = m_engine->GetRasterizer();
- m_canvas = m_engine->GetCanvas();
- // locate the vertex assigned to mat and do following calculation in mesh coordinates
- for (int meshIndex = 0; meshIndex < mirror->GetMeshCount(); meshIndex++)
- {
- RAS_MeshObject* mesh = mirror->GetMesh(meshIndex);
- int numPolygons = mesh->NumPolygons();
- for (int polygonIndex=0; polygonIndex < numPolygons; polygonIndex++)
- {
- RAS_Polygon* polygon = mesh->GetPolygon(polygonIndex);
- if (polygon->GetMaterial()->GetPolyMaterial() == mat)
- {
- RAS_TexVert *v1, *v2, *v3, *v4;
- float normal[3];
- float area;
- // this polygon is part of the mirror
- v1 = polygon->GetVertex(0);
- v2 = polygon->GetVertex(1);
- v3 = polygon->GetVertex(2);
- mirrorVerts.push_back(v1);
- mirrorVerts.push_back(v2);
- mirrorVerts.push_back(v3);
- if (polygon->VertexCount() == 4) {
- v4 = polygon->GetVertex(3);
- mirrorVerts.push_back(v4);
- area = normal_quad_v3(normal,(float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ(), (float*)v4->getXYZ());
- }
- else {
- area = normal_tri_v3(normal,(float*)v1->getXYZ(), (float*)v2->getXYZ(), (float*)v3->getXYZ());
- }
- area = fabs(area);
- mirrorArea += area;
- mul_v3_fl(normal, area);
- add_v3_v3v3(mirrorNormal, mirrorNormal, normal);
- }
- }
- }
- if (mirrorVerts.size() == 0 || mirrorArea < FLT_EPSILON)
- {
- // no vertex or zero size mirror
- THRWEXCP(MirrorSizeInvalid, S_OK);
- }
- // compute average normal of mirror faces
- mul_v3_fl(mirrorNormal, 1.0f/mirrorArea);
- if (normalize_v3(mirrorNormal) == 0.f)
- {
- // no normal
- THRWEXCP(MirrorNormalInvalid, S_OK);
- }
- // the mirror plane has an equation of the type ax+by+cz = d where (a,b,c) is the normal vector
- // if the mirror is more vertical then horizontal, the Z axis is the up direction.
- // otherwise the Y axis is the up direction.
- // If the mirror is not perfectly vertical(horizontal), the Z(Y) axis projection on the mirror
- // plan by the normal will be the up direction.
- if (fabsf(mirrorNormal[2]) > fabsf(mirrorNormal[1]) &&
- fabsf(mirrorNormal[2]) > fabsf(mirrorNormal[0]))
- {
- // the mirror is more horizontal than vertical
- copy_v3_v3(axis, yaxis);
- }
- else
- {
- // the mirror is more vertical than horizontal
- copy_v3_v3(axis, zaxis);
- }
- dist = dot_v3v3(mirrorNormal, axis);
- if (fabsf(dist) < FLT_EPSILON)
- {
- // the mirror is already fully aligned with up axis
- copy_v3_v3(mirrorUp, axis);
- }
- else
- {
- // projection of axis to mirror plane through normal
- copy_v3_v3(vec, mirrorNormal);
- mul_v3_fl(vec, dist);
- sub_v3_v3v3(mirrorUp, axis, vec);
- if (normalize_v3(mirrorUp) == 0.f)
- {
- // should not happen
- THRWEXCP(MirrorHorizontal, S_OK);
- return;
- }
- }
- // compute rotation matrix between local coord and mirror coord
- // to match camera orientation, we select mirror z = -normal, y = up, x = y x z
- negate_v3_v3(mirrorMat[2], mirrorNormal);
- copy_v3_v3(mirrorMat[1], mirrorUp);
- cross_v3_v3v3(mirrorMat[0], mirrorMat[1], mirrorMat[2]);
- // transpose to make it a orientation matrix from local space to mirror space
- transpose_m3(mirrorMat);
- // transform all vertex to plane coordinates and determine mirror position
- left = FLT_MAX;
- right = -FLT_MAX;
- bottom = FLT_MAX;
- top = -FLT_MAX;
- back = -FLT_MAX; // most backward vertex (=highest Z coord in mirror space)
- for (it = mirrorVerts.begin(); it != mirrorVerts.end(); it++)
- {
- copy_v3_v3(vec, (float*)(*it)->getXYZ());
- mul_m3_v3(mirrorMat, vec);
- if (vec[0] < left)
- left = vec[0];
- if (vec[0] > right)
- right = vec[0];
- if (vec[1] < bottom)
- bottom = vec[1];
- if (vec[1] > top)
- top = vec[1];
- if (vec[2] > back)
- back = vec[2];
- }
- // now store this information in the object for later rendering
- m_mirrorHalfWidth = (right-left)*0.5f;
- m_mirrorHalfHeight = (top-bottom)*0.5f;
- if (m_mirrorHalfWidth < 0.01f || m_mirrorHalfHeight < 0.01f)
- {
- // mirror too small
- THRWEXCP(MirrorTooSmall, S_OK);
- }
- // mirror position in mirror coord
- vec[0] = (left+right)*0.5f;
- vec[1] = (top+bottom)*0.5f;
- vec[2] = back;
- // convert it in local space: transpose again the matrix to get back to mirror to local transform
- transpose_m3(mirrorMat);
- mul_m3_v3(mirrorMat, vec);
- // mirror position in local space
- m_mirrorPos.setValue(vec[0], vec[1], vec[2]);
- // mirror normal vector (pointed towards the back of the mirror) in local space
- m_mirrorZ.setValue(-mirrorNormal[0], -mirrorNormal[1], -mirrorNormal[2]);
- m_mirrorY.setValue(mirrorUp[0], mirrorUp[1], mirrorUp[2]);
- m_mirrorX = m_mirrorY.cross(m_mirrorZ);
- m_render = true;
-
- // set mirror background color to scene background color as default
- setBackgroundFromScene(m_scene);
-}
-
-
-
-
-// define python type
-PyTypeObject ImageMirrorType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.ImageMirror", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Image source from mirror", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- imageRenderMethods, /* tp_methods */
- 0, /* tp_members */
- imageMirrorGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)ImageMirror_init, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
-
-
diff --git a/source/gameengine/VideoTexture/ImageRender.h b/source/gameengine/VideoTexture/ImageRender.h
deleted file mode 100644
index d062db44348..00000000000
--- a/source/gameengine/VideoTexture/ImageRender.h
+++ /dev/null
@@ -1,125 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file ImageRender.h
- * \ingroup bgevideotex
- */
-
-#ifndef __IMAGERENDER_H__
-#define __IMAGERENDER_H__
-
-
-#include "Common.h"
-
-#include "KX_Scene.h"
-#include "KX_Camera.h"
-#include "DNA_screen_types.h"
-#include "RAS_ICanvas.h"
-#include "RAS_IRasterizer.h"
-#include "RAS_IOffScreen.h"
-#include "RAS_ISync.h"
-
-#include "ImageViewport.h"
-
-
-/// class for render 3d scene
-class ImageRender : public ImageViewport
-{
-public:
- /// constructor
- ImageRender(KX_Scene *scene, KX_Camera *camera, PyRASOffScreen *offscreen);
- ImageRender(KX_Scene *scene, KX_GameObject *observer, KX_GameObject *mirror, RAS_IPolyMaterial * mat);
-
- /// destructor
- virtual ~ImageRender (void);
-
- /// get background color
- float getBackground (int idx);
- /// set background color
- void setBackground (float red, float green, float blue, float alpha);
-
- /// clipping distance
- float getClip (void) { return m_clip; }
- /// set whole buffer use
- void setClip (float clip) { m_clip = clip; }
- /// render status
- bool isDone() { return m_done; }
- /// render frame (public so that it is accessible from python)
- bool Render();
- /// in case fbo is used, method to unbind
- void Unbind();
- /// wait for render to complete
- void WaitSync();
-
-protected:
- /// true if ready to render
- bool m_render;
- /// is render done already?
- bool m_done;
- /// rendered scene
- KX_Scene * m_scene;
- /// camera for render
- KX_Camera * m_camera;
- /// do we own the camera?
- bool m_owncamera;
- /// if offscreen render
- PyRASOffScreen *m_offscreen;
- /// object to synchronize render even if no buffer transfer
- RAS_ISync *m_sync;
- /// for mirror operation
- KX_GameObject * m_observer;
- KX_GameObject * m_mirror;
- float m_clip; // clipping distance
- float m_mirrorHalfWidth; // mirror width in mirror space
- float m_mirrorHalfHeight; // mirror height in mirror space
- MT_Point3 m_mirrorPos; // mirror center position in local space
- MT_Vector3 m_mirrorZ; // mirror Z axis in local space
- MT_Vector3 m_mirrorY; // mirror Y axis in local space
- MT_Vector3 m_mirrorX; // mirror X axis in local space
- /// canvas
- RAS_ICanvas* m_canvas;
- /// rasterizer
- RAS_IRasterizer* m_rasterizer;
- /// engine
- KX_KetsjiEngine* m_engine;
-
- /// background color
- float m_background[4];
-
-
- /// render 3d scene to image
- virtual void calcImage (unsigned int texId, double ts) { calcViewport(texId, ts, GL_RGBA); }
-
- /// render 3d scene to image
- virtual void calcViewport (unsigned int texId, double ts, unsigned int format);
-
- void setBackgroundFromScene(KX_Scene *scene);
- void SetWorldSettings(KX_WorldInfo* wi);
-};
-
-
-#endif
-
diff --git a/source/gameengine/VideoTexture/ImageViewport.cpp b/source/gameengine/VideoTexture/ImageViewport.cpp
deleted file mode 100644
index ad3d8875e28..00000000000
--- a/source/gameengine/VideoTexture/ImageViewport.cpp
+++ /dev/null
@@ -1,467 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/ImageViewport.cpp
- * \ingroup bgevideotex
- */
-
-// implementation
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "GPU_glew.h"
-
-#include "KX_PythonInit.h"
-#include "RAS_ICanvas.h"
-#include "Texture.h"
-#include "ImageBase.h"
-#include "VideoBase.h"
-#include "FilterSource.h"
-#include "ImageViewport.h"
-
-
-// constructor
-ImageViewport::ImageViewport (PyRASOffScreen *offscreen) : m_alpha(false), m_texInit(false)
-{
- // get viewport rectangle
- if (offscreen) {
- m_viewport[0] = 0;
- m_viewport[1] = 0;
- m_viewport[2] = offscreen->ofs->GetWidth();
- m_viewport[3] = offscreen->ofs->GetHeight();
- }
- else {
- RAS_Rect rect = KX_GetActiveEngine()->GetCanvas()->GetWindowArea();
- m_viewport[0] = rect.GetLeft();
- m_viewport[1] = rect.GetBottom();
- m_viewport[2] = rect.GetWidth();
- m_viewport[3] = rect.GetHeight();
- }
-
- //glGetIntegerv(GL_VIEWPORT, m_viewport);
- // create buffer for viewport image
- // Warning: this buffer is also used to get the depth buffer as an array of
- // float (1 float = 4 bytes per pixel)
- m_viewportImage = new BYTE [4 * getViewportSize()[0] * getViewportSize()[1]];
- // set attributes
- setWhole((offscreen) ? true : false);
-}
-
-// destructor
-ImageViewport::~ImageViewport (void)
-{
- delete [] m_viewportImage;
-}
-
-
-// use whole viewport to capture image
-void ImageViewport::setWhole (bool whole)
-{
- // set whole
- m_whole = whole;
- // set capture size to viewport size, if whole,
- // otherwise place area in the middle of viewport
- for (int idx = 0; idx < 2; ++idx)
- {
- // capture size
- m_capSize[idx] = whole ? short(getViewportSize()[idx])
- : calcSize(short(getViewportSize()[idx]));
- // position
- m_position[idx] = whole ? 0 : ((getViewportSize()[idx] - m_capSize[idx]) >> 1);
- }
- // init image
- init(m_capSize[0], m_capSize[1]);
- // set capture position
- setPosition();
-}
-
-void ImageViewport::setCaptureSize (short size[2])
-{
- m_whole = false;
- if (size == NULL)
- size = m_capSize;
- for (int idx = 0; idx < 2; ++idx)
- {
- if (size[idx] < 1)
- m_capSize[idx] = 1;
- else if (size[idx] > getViewportSize()[idx])
- m_capSize[idx] = short(getViewportSize()[idx]);
- else
- m_capSize[idx] = size[idx];
- }
- init(m_capSize[0], m_capSize[1]);
- // set capture position
- setPosition();
-}
-
-// set position of capture rectangle
-void ImageViewport::setPosition (GLint pos[2])
-{
- // if new position is not provided, use existing position
- if (pos == NULL) pos = m_position;
- // save position
- for (int idx = 0; idx < 2; ++idx)
- m_position[idx] = pos[idx] < 0 ? 0 : pos[idx] >= getViewportSize()[idx]
- - m_capSize[idx] ? getViewportSize()[idx] - m_capSize[idx] : pos[idx];
- // recalc up left corner
- for (int idx = 0; idx < 2; ++idx)
- m_upLeft[idx] = m_position[idx] + m_viewport[idx];
-}
-
-
-// capture image from viewport
-void ImageViewport::calcViewport (unsigned int texId, double ts, unsigned int format)
-{
- // if scale was changed
- if (m_scaleChange)
- // reset image
- init(m_capSize[0], m_capSize[1]);
- // if texture wasn't initialized
- if (!m_texInit && texId != 0) {
- // initialize it
- loadTexture(texId, m_image, m_size);
- m_texInit = true;
- }
- // if texture can be directly created
- if (texId != 0 && m_pyfilter == NULL && m_size[0] == m_capSize[0] &&
- m_size[1] == m_capSize[1] && !m_flip && !m_zbuff && !m_depth)
- {
- // just copy current viewport to texture
- glBindTexture(GL_TEXTURE_2D, texId);
- glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1]);
- glBindTexture(GL_TEXTURE_2D, 0);
- // image is not available
- m_avail = false;
- }
- // otherwise copy viewport to buffer, if image is not available
- else if (!m_avail) {
- if (m_zbuff) {
- // Use read pixels with the depth buffer
- // *** misusing m_viewportImage here, but since it has the correct size
- // (4 bytes per pixel = size of float) and we just need it to apply
- // the filter, it's ok
- glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1],
- GL_DEPTH_COMPONENT, GL_FLOAT, m_viewportImage);
- // filter loaded data
- FilterZZZA filt;
- filterImage(filt, (float *)m_viewportImage, m_capSize);
- }
- else {
-
- if (m_depth) {
- // Use read pixels with the depth buffer
- // See warning above about m_viewportImage.
- glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1],
- GL_DEPTH_COMPONENT, GL_FLOAT, m_viewportImage);
- // filter loaded data
- FilterDEPTH filt;
- filterImage(filt, (float *)m_viewportImage, m_capSize);
- }
- else {
-
- // get frame buffer data
- if (m_alpha) {
- // as we are reading the pixel in the native format, we can read directly in the image buffer
- // if we are sure that no processing is needed on the image
- if (m_size[0] == m_capSize[0] &&
- m_size[1] == m_capSize[1] &&
- !m_flip &&
- !m_pyfilter)
- {
- glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], format,
- GL_UNSIGNED_BYTE, m_image);
- m_avail = true;
- }
- else if (!m_pyfilter) {
- glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], format,
- GL_UNSIGNED_BYTE, m_viewportImage);
- FilterRGBA32 filt;
- filterImage(filt, m_viewportImage, m_capSize);
- }
- else {
- glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], GL_RGBA,
- GL_UNSIGNED_BYTE, m_viewportImage);
- FilterRGBA32 filt;
- filterImage(filt, m_viewportImage, m_capSize);
- if (format == GL_BGRA) {
- // in place byte swapping
- swapImageBR();
- }
- }
- }
- else {
- glReadPixels(m_upLeft[0], m_upLeft[1], (GLsizei)m_capSize[0], (GLsizei)m_capSize[1], GL_RGB,
- GL_UNSIGNED_BYTE, m_viewportImage);
- // filter loaded data
- FilterRGB24 filt;
- filterImage(filt, m_viewportImage, m_capSize);
- if (format == GL_BGRA) {
- // in place byte swapping
- swapImageBR();
- }
- }
- }
- }
- }
-}
-
-bool ImageViewport::loadImage(unsigned int *buffer, unsigned int size, unsigned int format, double ts)
-{
- unsigned int *tmp_image;
- bool ret;
-
- // if scale was changed
- if (m_scaleChange) {
- // reset image
- init(m_capSize[0], m_capSize[1]);
- }
-
- // size must be identical
- if (size < getBuffSize())
- return false;
-
- if (m_avail) {
- // just copy
- return ImageBase::loadImage(buffer, size, format, ts);
- }
- else {
- tmp_image = m_image;
- m_image = buffer;
- calcViewport(0, ts, format);
- ret = m_avail;
- m_image = tmp_image;
- // since the image was not loaded to our buffer, it's not valid
- m_avail = false;
- }
- return ret;
-}
-
-
-// cast Image pointer to ImageViewport
-inline ImageViewport * getImageViewport (PyImage *self)
-{ return static_cast<ImageViewport*>(self->m_image); }
-
-
-// python methods
-
-
-// get whole
-PyObject *ImageViewport_getWhole (PyImage *self, void *closure)
-{
- if (self->m_image != NULL && getImageViewport(self)->getWhole()) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-// set whole
-int ImageViewport_setWhole(PyImage *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- try
- {
- // set whole, can throw in case of resize and buffer exports
- if (self->m_image != NULL) getImageViewport(self)->setWhole(value == Py_True);
- }
- catch (Exception & exp)
- {
- exp.report();
- return -1;
- }
- // success
- return 0;
-}
-
-// get alpha
-PyObject *ImageViewport_getAlpha (PyImage *self, void *closure)
-{
- if (self->m_image != NULL && getImageViewport(self)->getAlpha()) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-// set whole
-int ImageViewport_setAlpha(PyImage *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- // set alpha
- if (self->m_image != NULL) getImageViewport(self)->setAlpha(value == Py_True);
- // success
- return 0;
-}
-
-
-// get position
-static PyObject *ImageViewport_getPosition (PyImage *self, void *closure)
-{
- GLint *pos = getImageViewport(self)->getPosition();
- PyObject *ret = PyTuple_New(2);
- PyTuple_SET_ITEM(ret, 0, PyLong_FromLong(pos[0]));
- PyTuple_SET_ITEM(ret, 1, PyLong_FromLong(pos[1]));
- return ret;
-}
-
-// set position
-static int ImageViewport_setPosition(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL ||
- !(PyTuple_Check(value) || PyList_Check(value)) ||
- PySequence_Fast_GET_SIZE(value) != 2 ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
- return -1;
- }
- // set position
- GLint pos[2] = {
- GLint(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
- GLint(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1)))
- };
- getImageViewport(self)->setPosition(pos);
- // success
- return 0;
-}
-
-// get capture size
-PyObject *ImageViewport_getCaptureSize (PyImage *self, void *closure)
-{
- short *size = getImageViewport(self)->getCaptureSize();
- PyObject *ret = PyTuple_New(2);
- PyTuple_SET_ITEM(ret, 0, PyLong_FromLong(size[0]));
- PyTuple_SET_ITEM(ret, 1, PyLong_FromLong(size[1]));
- return ret;
-}
-
-// set capture size
-int ImageViewport_setCaptureSize(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL ||
- !(PyTuple_Check(value) || PyList_Check(value)) ||
- PySequence_Fast_GET_SIZE(value) != 2 ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
- !PyLong_Check(PySequence_Fast_GET_ITEM(value, 1)))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 ints");
- return -1;
- }
- // set capture size
- short size[2] = {
- short(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 0))),
- short(PyLong_AsLong(PySequence_Fast_GET_ITEM(value, 1)))
- };
- try
- {
- // can throw in case of resize and buffer exports
- getImageViewport(self)->setCaptureSize(size);
- }
- catch (Exception & exp)
- {
- exp.report();
- return -1;
- }
- // success
- return 0;
-}
-
-
-// methods structure
-static PyMethodDef imageViewportMethods[] =
-{ // methods from ImageBase class
- {"refresh", (PyCFunction)Image_refresh, METH_VARARGS, "Refresh image - invalidate its current content"},
- {NULL}
-};
-// attributes structure
-static PyGetSetDef imageViewportGetSets[] =
-{
- {(char*)"whole", (getter)ImageViewport_getWhole, (setter)ImageViewport_setWhole, (char*)"use whole viewport to capture", NULL},
- {(char*)"position", (getter)ImageViewport_getPosition, (setter)ImageViewport_setPosition, (char*)"upper left corner of captured area", NULL},
- {(char*)"capsize", (getter)ImageViewport_getCaptureSize, (setter)ImageViewport_setCaptureSize, (char*)"size of viewport area being captured", NULL},
- {(char*)"alpha", (getter)ImageViewport_getAlpha, (setter)ImageViewport_setAlpha, (char*)"use alpha in texture", NULL},
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"zbuff", (getter)Image_getZbuff, (setter)Image_setZbuff, (char*)"use depth buffer as texture", NULL},
- {(char*)"depth", (getter)Image_getDepth, (setter)Image_setDepth, (char*)"get depth information from z-buffer as array of float", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {NULL}
-};
-
-
-// define python type
-PyTypeObject ImageViewportType = {
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.ImageViewport", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Image source from viewport", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- imageViewportMethods, /* tp_methods */
- 0, /* tp_members */
- imageViewportGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Image_init<ImageViewport>, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
diff --git a/source/gameengine/VideoTexture/ImageViewport.h b/source/gameengine/VideoTexture/ImageViewport.h
deleted file mode 100644
index 8a7e9cfd2ba..00000000000
--- a/source/gameengine/VideoTexture/ImageViewport.h
+++ /dev/null
@@ -1,113 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file ImageViewport.h
- * \ingroup bgevideotex
- */
-
-#ifndef __IMAGEVIEWPORT_H__
-#define __IMAGEVIEWPORT_H__
-
-
-#include "Common.h"
-
-#include "ImageBase.h"
-#include "RAS_IOffScreen.h"
-
-
-/// class for viewport access
-class ImageViewport : public ImageBase
-{
-public:
- /// constructor
- ImageViewport (PyRASOffScreen *offscreen=NULL);
-
- /// destructor
- virtual ~ImageViewport (void);
-
- /// is whole buffer used
- bool getWhole (void) { return m_whole; }
- /// set whole buffer use
- void setWhole (bool whole);
-
- /// is alpha channel used
- bool getAlpha (void) { return m_alpha; }
- /// set whole buffer use
- void setAlpha (bool alpha) { m_alpha = alpha; }
-
- /// get capture size in viewport
- short * getCaptureSize (void) { return m_capSize; }
- /// set capture size in viewport
- void setCaptureSize (short size[2] = NULL);
-
- /// get position in viewport
- GLint * getPosition (void) { return m_position; }
- /// set position in viewport
- void setPosition (GLint pos[2] = NULL);
-
- /// capture image from viewport to user buffer
- virtual bool loadImage(unsigned int *buffer, unsigned int size, unsigned int format, double ts);
-
-protected:
- /// frame buffer rectangle
- GLint m_viewport[4];
-
- /// size of captured area
- short m_capSize[2];
- /// use whole viewport
- bool m_whole;
- /// use alpha channel
- bool m_alpha;
-
- /// position of capture rectangle in viewport
- GLint m_position[2];
- /// upper left point for capturing
- GLint m_upLeft[2];
-
- /// buffer to copy viewport
- BYTE * m_viewportImage;
- /// texture is initialized
- bool m_texInit;
-
- /// capture image from viewport
- virtual void calcImage (unsigned int texId, double ts) { calcViewport(texId, ts, GL_RGBA); }
-
- /// capture image from viewport
- virtual void calcViewport (unsigned int texId, double ts, unsigned int format);
-
- /// get viewport size
- GLint * getViewportSize (void) { return m_viewport + 2; }
-};
-
-PyObject *ImageViewport_getCaptureSize(PyImage *self, void *closure);
-int ImageViewport_setCaptureSize(PyImage *self, PyObject *value, void *closure);
-PyObject *ImageViewport_getWhole(PyImage *self, void *closure);
-int ImageViewport_setWhole(PyImage *self, PyObject *value, void *closure);
-PyObject *ImageViewport_getAlpha(PyImage *self, void *closure);
-int ImageViewport_setAlpha(PyImage *self, PyObject *value, void *closure);
-
-#endif
-
diff --git a/source/gameengine/VideoTexture/PyTypeList.cpp b/source/gameengine/VideoTexture/PyTypeList.cpp
deleted file mode 100644
index 18f477f6178..00000000000
--- a/source/gameengine/VideoTexture/PyTypeList.cpp
+++ /dev/null
@@ -1,97 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of blendTex library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/PyTypeList.cpp
- * \ingroup bgevideotex
- */
-
-#include "PyTypeList.h"
-
-#include <memory>
-#include <vector>
-
-#include "EXP_PyObjectPlus.h"
-
-/// destructor
-PyTypeList::~PyTypeList()
-{
- // if list exists
- if (m_list.get() != NULL)
- for (PyTypeListType::iterator it = m_list->begin(); it != m_list->end(); ++it)
- delete *it;
-}
-
-/// check, if type is in list
-bool PyTypeList::in (PyTypeObject *type)
-{
- // if list exists
- if (m_list.get() != NULL)
- // iterate items in list
- for (PyTypeListType::iterator it = m_list->begin(); it != m_list->end(); ++it)
- // if item is found, return with success
- if ((*it)->getType() == type) return true;
- // otherwise return not found
- return false;
-}
-
-/// add type to list
-void PyTypeList::add (PyTypeObject *type, const char *name)
-{
- // if list doesn't exist, create it
- if (m_list.get() == NULL)
- m_list.reset(new PyTypeListType());
- if (!in(type))
- // add new item to list
- m_list->push_back(new PyTypeListItem(type, name));
-}
-
-/// prepare types
-bool PyTypeList::ready (void)
-{
- // if list exists
- if (m_list.get() != NULL)
- // iterate items in list
- for (PyTypeListType::iterator it = m_list->begin(); it != m_list->end(); ++it)
- // if preparation failed, report it
- if (PyType_Ready((*it)->getType()) < 0) return false;
- // success
- return true;
-}
-
-/// register types to module
-void PyTypeList::reg(PyObject *module)
-{
- // if list exists
- if (m_list.get() != NULL)
- // iterate items in list
- for (PyTypeListType::iterator it = m_list->begin(); it != m_list->end(); ++it)
- {
- // increase ref count
- Py_INCREF((*it)->getType());
- // add type to module
- PyModule_AddObject(module, (*it)->getName(), (PyObject *)(*it)->getType());
- }
-}
diff --git a/source/gameengine/VideoTexture/PyTypeList.h b/source/gameengine/VideoTexture/PyTypeList.h
deleted file mode 100644
index ce0eb81e656..00000000000
--- a/source/gameengine/VideoTexture/PyTypeList.h
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of blendTex library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file PyTypeList.h
- * \ingroup bgevideotex
- */
-
-#ifndef __PYTYPELIST_H__
-#define __PYTYPELIST_H__
-
-#include "Common.h"
-
-#include <memory>
-#include <vector>
-
-#include "EXP_PyObjectPlus.h"
-
-// forward declaration
-class PyTypeListItem;
-
-// type for list of types
-typedef std::vector<PyTypeListItem*> PyTypeListType;
-
-
-/// class to store list of python types
-class PyTypeList
-{
-public:
- /// destructor
- ~PyTypeList();
-
- /// check, if type is in list
- bool in (PyTypeObject *type);
-
- /// add type to list
- void add (PyTypeObject *type, const char * name);
-
- /// prepare types
- bool ready (void);
-
- /// register types to module
- void reg(PyObject *module);
-
-protected:
- /// pointer to list of types
-#if (__cplusplus > 199711L) /* || (defined(_MSC_VER) && _MSC_VER >= 1800) */
- std::unique_ptr<PyTypeListType> m_list;
-#else
- std::auto_ptr<PyTypeListType> m_list;
-#endif
-};
-
-
-/// class for item of python type list
-class PyTypeListItem
-{
-public:
- /// constructor adds type into list
- PyTypeListItem (PyTypeObject *type, const char * name)
- : m_type(type), m_name(name)
- { }
-
- /// does type match
- PyTypeObject *getType (void) { return m_type; }
-
- /// get name of type
- const char * getName (void) { return m_name; }
-
-protected:
- /// pointer to type object
- PyTypeObject *m_type;
- /// name of type
- const char *m_name;
-};
-
-
-#endif
diff --git a/source/gameengine/VideoTexture/Texture.cpp b/source/gameengine/VideoTexture/Texture.cpp
deleted file mode 100644
index 48dc4c705bf..00000000000
--- a/source/gameengine/VideoTexture/Texture.cpp
+++ /dev/null
@@ -1,533 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/Texture.cpp
- * \ingroup bgevideotex
- */
-
-// implementation
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "KX_GameObject.h"
-#include "KX_Light.h"
-#include "RAS_MeshObject.h"
-#include "RAS_ILightObject.h"
-#include "DNA_mesh_types.h"
-#include "DNA_meshdata_types.h"
-#include "DNA_image_types.h"
-#include "IMB_imbuf_types.h"
-#include "BKE_image.h"
-
-#include "MEM_guardedalloc.h"
-
-#include "KX_BlenderMaterial.h"
-#include "BL_Texture.h"
-
-#include "KX_KetsjiEngine.h"
-#include "KX_PythonInit.h"
-#include "Texture.h"
-#include "ImageBase.h"
-#include "Exception.h"
-
-#include <memory.h>
-#include "GPU_glew.h"
-
-extern "C" {
- #include "IMB_imbuf.h"
-}
-
-// macro for exception handling and logging
-#define CATCH_EXCP catch (Exception & exp) \
-{ exp.report(); return NULL; }
-
-
-// Blender GameObject type
-static BlendType<KX_GameObject> gameObjectType ("KX_GameObject");
-static BlendType<KX_LightObject> lightObjectType ("KX_LightObject");
-
-
-// load texture
-void loadTexture(unsigned int texId, unsigned int *texture, short *size,
- bool mipmap)
-{
- // load texture for rendering
- glBindTexture(GL_TEXTURE_2D, texId);
- if (mipmap)
- {
- int i;
- ImBuf *ibuf;
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
- ibuf = IMB_allocFromBuffer(texture, NULL, size[0], size[1]);
-
- IMB_makemipmap(ibuf, true);
-
- for (i = 0; i < ibuf->miptot; i++) {
- ImBuf *mip = IMB_getmipmap(ibuf, i);
-
- glTexImage2D(GL_TEXTURE_2D, i, GL_RGBA, mip->x, mip->y, 0, GL_RGBA, GL_UNSIGNED_BYTE, mip->rect);
- }
- IMB_freeImBuf(ibuf);
- }
- else
- {
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
- glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA, size[0], size[1], 0, GL_RGBA, GL_UNSIGNED_BYTE, texture);
- }
- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-}
-
-
-// get pointer to material
-RAS_IPolyMaterial * getMaterial (PyObject *obj, short matID)
-{
- // if object is available
- if (obj != NULL)
- {
- // get pointer to texture image
- KX_GameObject * gameObj = gameObjectType.checkType(obj);
- if (gameObj != NULL && gameObj->GetMeshCount() > 0)
- {
- // get material from mesh
- RAS_MeshObject * mesh = gameObj->GetMesh(0);
- RAS_MeshMaterial *meshMat = mesh->GetMeshMaterial(matID);
- if (meshMat != NULL && meshMat->m_bucket != NULL)
- // return pointer to polygon or blender material
- return meshMat->m_bucket->GetPolyMaterial();
- }
- }
- // otherwise material was not found
- return NULL;
-}
-
-// get pointer to a lamp
-static KX_LightObject *getLamp(PyObject *obj)
-{
- // if object is available
- if (obj == NULL) return NULL;
-
- // returns NULL if obj is not a KX_LightObject
- return lightObjectType.checkType(obj);
-}
-
-
-// get material ID
-short getMaterialID(PyObject *obj, const char *name)
-{
- // search for material
- for (short matID = 0;; ++matID)
- {
- // get material
- RAS_IPolyMaterial * mat = getMaterial(obj, matID);
- // if material is not available, report that no material was found
- if (mat == NULL)
- break;
- // name is a material name if it starts with MA and a UV texture name if it starts with IM
- if (name[0] == 'I' && name[1] == 'M') {
- // if texture name matches
- if (strcmp(mat->GetTextureName().ReadPtr(), name) == 0)
- return matID;
- }
- else {
- // if material name matches
- if (strcmp(mat->GetMaterialName().ReadPtr(), name) == 0)
- return matID;
- }
- }
- // material was not found
- return -1;
-}
-
-
-// Texture object allocation
-static PyObject *Texture_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- // allocate object
- Texture * self = reinterpret_cast<Texture*>(type->tp_alloc(type, 0));
- // initialize object structure
- self->m_actTex = 0;
- self->m_orgSaved = false;
- self->m_imgBuf = NULL;
- self->m_imgTexture = NULL;
- self->m_matTexture = NULL;
- self->m_mipmap = false;
- self->m_scaledImBuf = NULL;
- self->m_source = NULL;
- self->m_lastClock = 0.0;
- // return allocated object
- return reinterpret_cast<PyObject*>(self);
-}
-
-
-// forward declaration
-PyObject *Texture_close(Texture *self);
-int Texture_setSource(Texture *self, PyObject *value, void *closure);
-
-
-// Texture object deallocation
-static void Texture_dealloc(Texture *self)
-{
- // release renderer
- Py_XDECREF(self->m_source);
- // close texture
- PyObject *ret = Texture_close(self);
- Py_DECREF(ret);
- // release scaled image buffer
- IMB_freeImBuf(self->m_scaledImBuf);
- // release object
- Py_TYPE((PyObject *)self)->tp_free((PyObject *)self);
-}
-
-
-ExceptionID MaterialNotAvail;
-ExpDesc MaterialNotAvailDesc(MaterialNotAvail, "Texture material is not available");
-
-// Texture object initialization
-static int Texture_init(Texture *self, PyObject *args, PyObject *kwds)
-{
- // parameters - game object with video texture
- PyObject *obj = NULL;
- // material ID
- short matID = 0;
- // texture ID
- short texID = 0;
- // texture object with shared texture ID
- Texture * texObj = NULL;
-
- static const char *kwlist[] = {"gameObj", "materialID", "textureID", "textureObj", NULL};
-
- // get parameters
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "O|hhO!",
- const_cast<char**>(kwlist), &obj, &matID, &texID, &TextureType,
- &texObj))
- return -1;
-
- // if parameters are available
- if (obj != NULL)
- {
- // process polygon material or blender material
- try
- {
- // get pointer to texture image
- RAS_IPolyMaterial * mat = getMaterial(obj, matID);
- KX_LightObject * lamp = getLamp(obj);
- if (mat != NULL)
- {
- // is it blender material or polygon material
- if (mat->GetFlag() & RAS_BLENDERGLSL)
- {
- self->m_imgTexture = static_cast<KX_BlenderMaterial*>(mat)->getImage(texID);
- self->m_useMatTexture = false;
- } else
- {
- // get blender material texture
- self->m_matTexture = static_cast<KX_BlenderMaterial*>(mat)->getTex(texID);
- self->m_useMatTexture = true;
- }
- }
- else if (lamp != NULL)
- {
- self->m_imgTexture = lamp->GetLightData()->GetTextureImage(texID);
- self->m_useMatTexture = false;
- }
-
- // check if texture is available, if not, initialization failed
- if (self->m_imgTexture == NULL && self->m_matTexture == NULL)
- // throw exception if initialization failed
- THRWEXCP(MaterialNotAvail, S_OK);
-
- // if texture object is provided
- if (texObj != NULL)
- {
- // copy texture code
- self->m_actTex = texObj->m_actTex;
- self->m_mipmap = texObj->m_mipmap;
- if (texObj->m_source != NULL)
- Texture_setSource(self, reinterpret_cast<PyObject*>(texObj->m_source), NULL);
- }
- else
- // otherwise generate texture code
- glGenTextures(1, (GLuint*)&self->m_actTex);
- }
- catch (Exception & exp)
- {
- exp.report();
- return -1;
- }
- }
- // initialization succeded
- return 0;
-}
-
-
-// close added texture
-PyObject *Texture_close(Texture * self)
-{
- // restore texture
- if (self->m_orgSaved)
- {
- self->m_orgSaved = false;
- // restore original texture code
- if (self->m_useMatTexture)
- self->m_matTexture->swapTexture(self->m_orgTex);
- else
- {
- self->m_imgTexture->bindcode[TEXTARGET_TEXTURE_2D] = self->m_orgTex;
- BKE_image_release_ibuf(self->m_imgTexture, self->m_imgBuf, NULL);
- self->m_imgBuf = NULL;
- }
- // drop actual texture
- if (self->m_actTex != 0)
- {
- glDeleteTextures(1, (GLuint *)&self->m_actTex);
- self->m_actTex = 0;
- }
- }
- Py_RETURN_NONE;
-}
-
-
-// refresh texture
-static PyObject *Texture_refresh(Texture *self, PyObject *args)
-{
- // get parameter - refresh source
- PyObject *param;
- double ts = -1.0;
-
- if (!PyArg_ParseTuple(args, "O|d:refresh", &param, &ts) || !PyBool_Check(param))
- {
- // report error
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return NULL;
- }
- // some trick here: we are in the business of loading a texture,
- // no use to do it if we are still in the same rendering frame.
- // We find this out by looking at the engine current clock time
- KX_KetsjiEngine* engine = KX_GetActiveEngine();
- if (engine->GetClockTime() != self->m_lastClock)
- {
- self->m_lastClock = engine->GetClockTime();
- // set source refresh
- bool refreshSource = (param == Py_True);
- // try to proces texture from source
- try
- {
- // if source is available
- if (self->m_source != NULL)
- {
- // check texture code
- if (!self->m_orgSaved)
- {
- self->m_orgSaved = true;
- // save original image code
- if (self->m_useMatTexture)
- self->m_orgTex = self->m_matTexture->swapTexture(self->m_actTex);
- else
- {
- // Swapping will work only if the GPU has already loaded the image.
- // If not, it will delete and overwrite our texture on next render.
- // To avoid that, we acquire the image buffer now.
- // WARNING: GPU has a ImageUser to pass, we don't. Using NULL
- // works on image file, not necessarily on other type of image.
- self->m_imgBuf = BKE_image_acquire_ibuf(self->m_imgTexture, NULL, NULL);
- self->m_orgTex = self->m_imgTexture->bindcode[TEXTARGET_TEXTURE_2D];
- self->m_imgTexture->bindcode[TEXTARGET_TEXTURE_2D] = self->m_actTex;
- }
- }
-
- // get texture
- unsigned int * texture = self->m_source->m_image->getImage(self->m_actTex, ts);
- // if texture is available
- if (texture != NULL)
- {
- // get texture size
- short * orgSize = self->m_source->m_image->getSize();
- // calc scaled sizes
- short size[2];
- if (GLEW_ARB_texture_non_power_of_two)
- {
- size[0] = orgSize[0];
- size[1] = orgSize[1];
- }
- else
- {
- size[0] = ImageBase::calcSize(orgSize[0]);
- size[1] = ImageBase::calcSize(orgSize[1]);
- }
- // scale texture if needed
- if (size[0] != orgSize[0] || size[1] != orgSize[1])
- {
- IMB_freeImBuf(self->m_scaledImBuf);
- self->m_scaledImBuf = IMB_allocFromBuffer(texture, NULL, orgSize[0], orgSize[1]);
- IMB_scaleImBuf(self->m_scaledImBuf, size[0], size[1]);
-
- // use scaled image instead original
- texture = self->m_scaledImBuf->rect;
- }
- // load texture for rendering
- loadTexture(self->m_actTex, texture, size, self->m_mipmap);
- }
- // refresh texture source, if required
- if (refreshSource) {
- self->m_source->m_image->refresh();
- }
- }
- }
- CATCH_EXCP;
- }
- Py_RETURN_NONE;
-}
-
-// get OpenGL Bind Id
-static PyObject *Texture_getBindId(Texture *self, void *closure)
-{
- unsigned int id = self->m_actTex;
- return Py_BuildValue("h", id);
-}
-
-// get mipmap value
-static PyObject *Texture_getMipmap(Texture *self, void *closure)
-{
- // return true if flag is set, otherwise false
- if (self->m_mipmap) Py_RETURN_TRUE;
- else Py_RETURN_FALSE;
-}
-
-// set mipmap value
-static int Texture_setMipmap(Texture *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- // set mipmap
- self->m_mipmap = value == Py_True;
- // success
- return 0;
-}
-
-
-// get source object
-static PyObject *Texture_getSource(Texture *self, PyObject *value, void *closure)
-{
- // if source exists
- if (self->m_source != NULL)
- {
- Py_INCREF(self->m_source);
- return reinterpret_cast<PyObject*>(self->m_source);
- }
- // otherwise return None
- Py_RETURN_NONE;
-}
-
-
-// set source object
-int Texture_setSource(Texture *self, PyObject *value, void *closure)
-{
- // check new value
- if (value == NULL || !pyImageTypes.in(Py_TYPE(value)))
- {
- // report value error
- PyErr_SetString(PyExc_TypeError, "Invalid type of value");
- return -1;
- }
- // increase ref count for new value
- Py_INCREF(value);
- // release previous
- Py_XDECREF(self->m_source);
- // set new value
- self->m_source = reinterpret_cast<PyImage*>(value);
- // return success
- return 0;
-}
-
-
-// class Texture methods
-static PyMethodDef textureMethods[] =
-{
- { "close", (PyCFunction)Texture_close, METH_NOARGS, "Close dynamic texture and restore original"},
- { "refresh", (PyCFunction)Texture_refresh, METH_VARARGS, "Refresh texture from source"},
- {NULL} /* Sentinel */
-};
-
-// class Texture attributes
-static PyGetSetDef textureGetSets[] =
-{
- {(char*)"source", (getter)Texture_getSource, (setter)Texture_setSource, (char*)"source of texture", NULL},
- {(char*)"mipmap", (getter)Texture_getMipmap, (setter)Texture_setMipmap, (char*)"mipmap texture", NULL},
- {(char*)"bindId", (getter)Texture_getBindId, NULL, (char*)"OpenGL Bind Name", NULL},
- {NULL}
-};
-
-
-// class Texture declaration
-PyTypeObject TextureType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.Texture", /*tp_name*/
- sizeof(Texture), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Texture_dealloc,/*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Texture objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- textureMethods, /* tp_methods */
- 0, /* tp_members */
- textureGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)Texture_init, /* tp_init */
- 0, /* tp_alloc */
- Texture_new, /* tp_new */
-};
diff --git a/source/gameengine/VideoTexture/Texture.h b/source/gameengine/VideoTexture/Texture.h
deleted file mode 100644
index dc38b4181bb..00000000000
--- a/source/gameengine/VideoTexture/Texture.h
+++ /dev/null
@@ -1,99 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2006 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file VideoTexture/Texture.h
- * \ingroup bgevideotex
- */
-
-#ifndef __TEXTURE_H__
-#define __TEXTURE_H__
-
-#include "EXP_PyObjectPlus.h"
-#include <structmember.h>
-
-#include "DNA_image_types.h"
-#include "BL_Texture.h"
-#include "KX_BlenderMaterial.h"
-
-#include "ImageBase.h"
-#include "BlendType.h"
-#include "Exception.h"
-
-
-struct ImBuf;
-
-// type Texture declaration
-struct Texture
-{
- PyObject_HEAD
-
- // texture is using blender material
- bool m_useMatTexture;
-
- // video texture bind code
- unsigned int m_actTex;
- // original texture bind code
- unsigned int m_orgTex;
- // original texture saved
- bool m_orgSaved;
-
- // kernel image buffer, to make sure the image is loaded before we swap the bindcode
- struct ImBuf *m_imgBuf;
- // texture image for game materials
- Image * m_imgTexture;
- // texture for blender materials
- BL_Texture * m_matTexture;
-
- // use mipmapping
- bool m_mipmap;
-
- // scaled image buffer
- ImBuf * m_scaledImBuf;
- // last refresh
- double m_lastClock;
-
- // image source
- PyImage * m_source;
-};
-
-
-// Texture type description
-extern PyTypeObject TextureType;
-
-// load texture
-void loadTexture(unsigned int texId, unsigned int *texture, short *size,
- bool mipmap = false);
-
-// get material
-RAS_IPolyMaterial *getMaterial(PyObject *obj, short matID);
-
-// get material ID
-short getMaterialID(PyObject *obj, const char *name);
-
-// Exceptions
-extern ExceptionID MaterialNotAvail;
-
-#endif
diff --git a/source/gameengine/VideoTexture/VideoBase.cpp b/source/gameengine/VideoTexture/VideoBase.cpp
deleted file mode 100644
index d373055b5df..00000000000
--- a/source/gameengine/VideoTexture/VideoBase.cpp
+++ /dev/null
@@ -1,254 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/VideoBase.cpp
- * \ingroup bgevideotex
- */
-
-#if defined WIN32
-#define WINDOWS_LEAN_AND_MEAN
-#include <windows.h>
-#endif
-
-#include "VideoBase.h"
-
-#include "FilterSource.h"
-
-// VideoBase implementation
-
-
-// initialize image data
-void VideoBase::init(short width, short height)
-{
- // save original sizes
- m_orgSize[0] = width;
- m_orgSize[1] = height;
- // call base class initialization
- ImageBase::init(width, height);
-}
-
-
-// process video frame
-void VideoBase::process (BYTE *sample)
-{
- // if scale was changed
- if (m_scaleChange)
- // reset image
- init(m_orgSize[0], m_orgSize[1]);
- // if image is allocated and is able to store new image
- if (m_image != NULL && !m_avail)
- {
- // filters used
- // convert video format to image
- switch (m_format)
- {
- case RGBA32:
- {
- FilterRGBA32 filtRGBA;
- // use filter object for format to convert image
- filterImage(filtRGBA, sample, m_orgSize);
- // finish
- break;
- }
- case RGB24:
- {
- FilterRGB24 filtRGB;
- // use filter object for format to convert image
- filterImage(filtRGB, sample, m_orgSize);
- // finish
- break;
- }
- case YV12:
- {
- // use filter object for format to convert image
- FilterYV12 filtYUV;
- filtYUV.setBuffs(sample, m_orgSize);
- filterImage(filtYUV, sample, m_orgSize);
- // finish
- break;
- }
- case None:
- break; /* assert? */
- }
- }
-}
-
-
-// python functions
-
-
-// exceptions for video source initialization
-ExceptionID SourceVideoEmpty, SourceVideoCreation;
-ExpDesc SourceVideoEmptyDesc(SourceVideoEmpty, "Source Video is empty");
-ExpDesc SourceVideoCreationDesc(SourceVideoCreation, "SourceVideo object was not created");
-
-// open video source
-void Video_open(VideoBase *self, char *file, short captureID)
-{
- // if file is empty, throw exception
- if (file == NULL) THRWEXCP(SourceVideoEmpty, S_OK);
-
- // open video file or capture device
- if (captureID >= 0)
- self->openCam(file, captureID);
- else
- self->openFile(file);
-}
-
-
-// play video
-PyObject *Video_play(PyImage *self)
-{ if (getVideo(self)->play()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
-
-// pause video
-PyObject *Video_pause(PyImage *self)
-{ if (getVideo(self)->pause()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
-
-PyObject *Video_stop(PyImage *self)
-{ if (getVideo(self)->stop()) Py_RETURN_TRUE; else Py_RETURN_FALSE; }
-
-// get status
-PyObject *Video_getStatus(PyImage *self, void *closure)
-{
- return Py_BuildValue("h", getVideo(self)->getStatus());
-}
-
-// refresh video
-PyObject *Video_refresh(PyImage *self, PyObject *args)
-{
- Py_buffer buffer;
- char *mode = NULL;
- unsigned int format;
- double ts = -1.0;
-
- memset(&buffer, 0, sizeof(buffer));
- if (PyArg_ParseTuple(args, "|s*sd:refresh", &buffer, &mode, &ts)) {
- if (buffer.buf) {
- // a target buffer is provided, verify its format
- if (buffer.readonly) {
- PyErr_SetString(PyExc_TypeError, "Buffers passed in argument must be writable");
- }
- else if (!PyBuffer_IsContiguous(&buffer, 'C')) {
- PyErr_SetString(PyExc_TypeError, "Buffers passed in argument must be contiguous in memory");
- }
- else if (((intptr_t)buffer.buf & 3) != 0) {
- PyErr_SetString(PyExc_TypeError, "Buffers passed in argument must be aligned to 4 bytes boundary");
- }
- else {
- // ready to get the image into our buffer
- try {
- if (mode == NULL || !strcmp(mode, "RGBA"))
- format = GL_RGBA;
- else if (!strcmp(mode, "BGRA"))
- format = GL_BGRA;
- else
- THRWEXCP(InvalidImageMode,S_OK);
-
- if (!self->m_image->loadImage((unsigned int *)buffer.buf, buffer.len, format, ts)) {
- PyErr_SetString(PyExc_TypeError, "Could not load the buffer, perhaps size is not compatible");
- }
- }
- catch (Exception & exp) {
- exp.report();
- }
- }
- PyBuffer_Release(&buffer);
- if (PyErr_Occurred())
- return NULL;
- }
- }
- else
- {
- return NULL;
- }
- getVideo(self)->refresh();
- return Video_getStatus(self, NULL);
-}
-
-
-// get range
-PyObject *Video_getRange(PyImage *self, void *closure)
-{
- return Py_BuildValue("[ff]", getVideo(self)->getRange()[0],
- getVideo(self)->getRange()[1]);
-}
-
-// set range
-int Video_setRange(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL || !PySequence_Check(value) || PySequence_Size(value) != 2 ||
- /* XXX - this is incorrect if the sequence is not a list/tuple! */
- !PyFloat_Check(PySequence_Fast_GET_ITEM(value, 0)) ||
- !PyFloat_Check(PySequence_Fast_GET_ITEM(value, 1)))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a sequence of 2 float");
- return -1;
- }
- // set range
- getVideo(self)->setRange(PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 0)),
- PyFloat_AsDouble(PySequence_Fast_GET_ITEM(value, 1)));
- // success
- return 0;
-}
-
-// get repeat
-PyObject *Video_getRepeat (PyImage *self, void *closure)
-{ return Py_BuildValue("h", getVideo(self)->getRepeat()); }
-
-// set repeat
-int Video_setRepeat(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL || !PyLong_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be an int");
- return -1;
- }
- // set repeat
- getVideo(self)->setRepeat(int(PyLong_AsLong(value)));
- // success
- return 0;
-}
-
-// get frame rate
-PyObject *Video_getFrameRate (PyImage *self, void *closure)
-{ return Py_BuildValue("f", double(getVideo(self)->getFrameRate())); }
-
-// set frame rate
-int Video_setFrameRate(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL || !PyFloat_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a float");
- return -1;
- }
- // set repeat
- getVideo(self)->setFrameRate(float(PyFloat_AsDouble(value)));
- // success
- return 0;
-}
diff --git a/source/gameengine/VideoTexture/VideoBase.h b/source/gameengine/VideoTexture/VideoBase.h
deleted file mode 100644
index 77f46fdccd8..00000000000
--- a/source/gameengine/VideoTexture/VideoBase.h
+++ /dev/null
@@ -1,207 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file VideoBase.h
- * \ingroup bgevideotex
- */
-
-#ifndef __VIDEOBASE_H__
-#define __VIDEOBASE_H__
-
-
-#include "EXP_PyObjectPlus.h"
-
-#include "ImageBase.h"
-
-#include "Exception.h"
-
-// source states
-const int SourceError = -1;
-const int SourceEmpty = 0;
-const int SourceReady = 1;
-const int SourcePlaying = 2;
-const int SourceStopped = 3;
-
-
-// video source formats
-enum VideoFormat { None, RGB24, YV12, RGBA32 };
-
-
-/// base class for video source
-class VideoBase : public ImageBase
-{
-public:
- /// constructor
- VideoBase (void) : ImageBase(true), m_format(None), m_status(SourceEmpty),
- m_repeat(0), m_frameRate(1.0)
- {
- m_orgSize[0] = m_orgSize[1] = 0;
- m_range[0] = m_range[1] = 0.0;
- }
-
- /// destructor
- virtual ~VideoBase (void) {}
-
- /// open video file
- virtual void openFile(char *file)
- {
- m_isFile = true;
- m_status = SourceReady;
- }
- /// open video capture device
- virtual void openCam(char *file, short camIdx)
- {
- m_isFile = false;
- m_status = SourceReady;
- }
-
- /// play video
- virtual bool play (void)
- {
- if (m_status == SourceReady || m_status == SourceStopped)
- {
- m_status = SourcePlaying;
- return true;
- }
- return false;
- }
- /// pause video
- virtual bool pause (void)
- {
- if (m_status == SourcePlaying)
- {
- m_status = SourceStopped;
- return true;
- }
- return false;
- }
- /// stop video
- virtual bool stop (void)
- {
- if (m_status == SourcePlaying)
- {
- m_status = SourceStopped;
- return true;
- }
- return false;
- }
-
- // get video status
- int getStatus (void) { return m_status; }
-
- /// get play range
- const double * getRange (void) { return m_range; }
- /// set play range
- virtual void setRange (double start, double stop)
- {
- if (m_isFile)
- {
- m_range[0] = start;
- m_range[1] = stop;
- }
- }
-
- // get video repeat
- int getRepeat (void) { return m_repeat; }
- /// set video repeat
- virtual void setRepeat (int rep)
- { if (m_isFile) m_repeat = rep; }
-
- /// get frame rate
- float getFrameRate (void) { return m_frameRate; }
- /// set frame rate
- virtual void setFrameRate (float rate)
- { if (m_isFile) m_frameRate = rate > 0.0f ? rate : 1.0f; }
-
-protected:
- /// video format
- VideoFormat m_format;
- /// original video size
- short m_orgSize[2];
-
- /// video status
- int m_status;
-
- /// is source file
- bool m_isFile;
-
- /// replay range
- double m_range[2];
- /// repeat count
- int m_repeat;
- /// frame rate
- float m_frameRate;
-
- /// initialize image data
- void init (short width, short height);
-
- /// process source data
- void process (BYTE * sample);
-};
-
-
-
-// python fuctions
-
-
-// cast Image pointer to Video
-inline VideoBase *getVideo(PyImage *self)
-{ return static_cast<VideoBase*>(self->m_image); }
-
-
-extern ExceptionID SourceVideoCreation;
-
-// object initialization
-template <class T> void Video_init(PyImage *self)
-{
- // create source video object
- if (self->m_image != NULL) delete self->m_image;
- HRESULT hRslt = S_OK;
- self->m_image = new T(&hRslt);
- CHCKHRSLT(hRslt, SourceVideoCreation);
-}
-
-
-// video functions
-void Video_open(VideoBase *self, char *file, short captureID);
-PyObject *Video_play(PyImage *self);
-PyObject *Video_pause(PyImage *self);
-PyObject *Video_stop(PyImage *self);
-PyObject *Video_refresh(PyImage *self, PyObject *args);
-PyObject *Video_getStatus(PyImage *self, void *closure);
-PyObject *Video_getRange(PyImage *self, void *closure);
-int Video_setRange(PyImage *self, PyObject *value, void *closure);
-PyObject *Video_getRepeat(PyImage *self, void *closure);
-int Video_setRepeat(PyImage *self, PyObject *value, void *closure);
-PyObject *Video_getFrameRate(PyImage *self, void *closure);
-int Video_setFrameRate(PyImage *self, PyObject *value, void *closure);
-
-/* py api */
-extern PyTypeObject ImageRenderType;
-extern PyTypeObject ImageMirrorType;
-extern PyTypeObject ImageViewportType;
-
-#endif /* __VIDEOBASE_H__ */
diff --git a/source/gameengine/VideoTexture/VideoDeckLink.cpp b/source/gameengine/VideoTexture/VideoDeckLink.cpp
deleted file mode 100644
index c588a4b33cf..00000000000
--- a/source/gameengine/VideoTexture/VideoDeckLink.cpp
+++ /dev/null
@@ -1,1228 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/VideoDeckLink.cpp
- * \ingroup bgevideotex
- */
-
-#ifdef WITH_GAMEENGINE_DECKLINK
-
-// FFmpeg defines its own version of stdint.h on Windows.
-// Decklink needs FFmpeg, so it uses its version of stdint.h
-// this is necessary for INT64_C macro
-#ifndef __STDC_CONSTANT_MACROS
-#define __STDC_CONSTANT_MACROS
-#endif
-// this is necessary for UINTPTR_MAX (used by atomic-ops)
-#ifndef __STDC_LIMIT_MACROS
-#define __STDC_LIMIT_MACROS
-#ifdef __STDC_LIMIT_MACROS /* else it may be unused */
-#endif
-#endif
-#include <stdint.h>
-#include <string.h>
-#ifndef WIN32
-#include <sys/time.h>
-#include <sys/resource.h>
-#include <sys/mman.h>
-#endif
-
-#include "atomic_ops.h"
-
-#include "MEM_guardedalloc.h"
-#include "PIL_time.h"
-#include "VideoDeckLink.h"
-#include "DeckLink.h"
-#include "Exception.h"
-#include "KX_KetsjiEngine.h"
-#include "KX_PythonInit.h"
-
-extern ExceptionID DeckLinkInternalError;
-ExceptionID SourceVideoOnlyCapture, VideoDeckLinkBadFormat, VideoDeckLinkOpenCard, VideoDeckLinkDvpInternalError, VideoDeckLinkPinMemoryError;
-ExpDesc SourceVideoOnlyCaptureDesc(SourceVideoOnlyCapture, "This video source only allows live capture");
-ExpDesc VideoDeckLinkBadFormatDesc(VideoDeckLinkBadFormat, "Invalid or unsupported capture format, should be <mode>/<pixel>[/3D]");
-ExpDesc VideoDeckLinkOpenCardDesc(VideoDeckLinkOpenCard, "Cannot open capture card, check if driver installed");
-ExpDesc VideoDeckLinkDvpInternalErrorDesc(VideoDeckLinkDvpInternalError, "DVP API internal error, please report");
-ExpDesc VideoDeckLinkPinMemoryErrorDesc(VideoDeckLinkPinMemoryError, "Error pinning memory");
-
-
-#ifdef WIN32
-////////////////////////////////////////////
-// SynInfo
-//
-// Sets up a semaphore which is shared between the GPU and CPU and used to
-// synchronise access to DVP buffers.
-#define DVP_CHECK(cmd) if ((cmd) != DVP_STATUS_OK) THRWEXCP(VideoDeckLinkDvpInternalError, S_OK)
-
-struct SyncInfo
-{
- SyncInfo(uint32_t semaphoreAllocSize, uint32_t semaphoreAddrAlignment)
- {
- mSemUnaligned = (uint32_t*)malloc(semaphoreAllocSize + semaphoreAddrAlignment - 1);
-
- // Apply alignment constraints
- uint64_t val = (uint64_t)mSemUnaligned;
- val += semaphoreAddrAlignment - 1;
- val &= ~((uint64_t)semaphoreAddrAlignment - 1);
- mSem = (uint32_t*)val;
-
- // Initialise
- mSem[0] = 0;
- mReleaseValue = 0;
- mAcquireValue = 0;
-
- // Setup DVP sync object and import it
- DVPSyncObjectDesc syncObjectDesc;
- syncObjectDesc.externalClientWaitFunc = NULL;
- syncObjectDesc.sem = (uint32_t*)mSem;
-
- DVP_CHECK(dvpImportSyncObject(&syncObjectDesc, &mDvpSync));
-
- }
- ~SyncInfo()
- {
- dvpFreeSyncObject(mDvpSync);
- free((void*)mSemUnaligned);
- }
-
- volatile uint32_t* mSem;
- volatile uint32_t* mSemUnaligned;
- volatile uint32_t mReleaseValue;
- volatile uint32_t mAcquireValue;
- DVPSyncObjectHandle mDvpSync;
-};
-
-////////////////////////////////////////////
-// TextureTransferDvp: transfer with GPUDirect
-////////////////////////////////////////////
-
-class TextureTransferDvp : public TextureTransfer
-{
-public:
- TextureTransferDvp(DVPBufferHandle dvpTextureHandle, TextureDesc *pDesc, void *address, uint32_t allocatedSize)
- {
- DVPSysmemBufferDesc sysMemBuffersDesc;
-
- mExtSync = NULL;
- mGpuSync = NULL;
- mDvpSysMemHandle = 0;
- mDvpTextureHandle = 0;
- mTextureHeight = 0;
- mAllocatedSize = 0;
- mBuffer = NULL;
-
- if (!_PinBuffer(address, allocatedSize))
- THRWEXCP(VideoDeckLinkPinMemoryError, S_OK);
- mAllocatedSize = allocatedSize;
- mBuffer = address;
-
- try {
- if (!mBufferAddrAlignment) {
- DVP_CHECK(dvpGetRequiredConstantsGLCtx(&mBufferAddrAlignment, &mBufferGpuStrideAlignment,
- &mSemaphoreAddrAlignment, &mSemaphoreAllocSize,
- &mSemaphorePayloadOffset, &mSemaphorePayloadSize));
- }
- mExtSync = new SyncInfo(mSemaphoreAllocSize, mSemaphoreAddrAlignment);
- mGpuSync = new SyncInfo(mSemaphoreAllocSize, mSemaphoreAddrAlignment);
- sysMemBuffersDesc.width = pDesc->width;
- sysMemBuffersDesc.height = pDesc->height;
- sysMemBuffersDesc.stride = pDesc->stride;
- switch (pDesc->format) {
- case GL_RED_INTEGER:
- sysMemBuffersDesc.format = DVP_RED_INTEGER;
- break;
- default:
- sysMemBuffersDesc.format = DVP_BGRA;
- break;
- }
- switch (pDesc->type) {
- case GL_UNSIGNED_BYTE:
- sysMemBuffersDesc.type = DVP_UNSIGNED_BYTE;
- break;
- case GL_UNSIGNED_INT_2_10_10_10_REV:
- sysMemBuffersDesc.type = DVP_UNSIGNED_INT_2_10_10_10_REV;
- break;
- case GL_UNSIGNED_INT_8_8_8_8:
- sysMemBuffersDesc.type = DVP_UNSIGNED_INT_8_8_8_8;
- break;
- case GL_UNSIGNED_INT_10_10_10_2:
- sysMemBuffersDesc.type = DVP_UNSIGNED_INT_10_10_10_2;
- break;
- default:
- sysMemBuffersDesc.type = DVP_UNSIGNED_INT;
- break;
- }
- sysMemBuffersDesc.size = pDesc->width * pDesc->height * 4;
- sysMemBuffersDesc.bufAddr = mBuffer;
- DVP_CHECK(dvpCreateBuffer(&sysMemBuffersDesc, &mDvpSysMemHandle));
- DVP_CHECK(dvpBindToGLCtx(mDvpSysMemHandle));
- mDvpTextureHandle = dvpTextureHandle;
- mTextureHeight = pDesc->height;
- }
- catch (Exception &) {
- clean();
- throw;
- }
- }
- ~TextureTransferDvp()
- {
- clean();
- }
-
- virtual void PerformTransfer()
- {
- // perform the transfer
- // tell DVP that the old texture buffer will no longer be used
- dvpMapBufferEndAPI(mDvpTextureHandle);
- // do we need this?
- mGpuSync->mReleaseValue++;
- dvpBegin();
- // Copy from system memory to GPU texture
- dvpMapBufferWaitDVP(mDvpTextureHandle);
- dvpMemcpyLined(mDvpSysMemHandle, mExtSync->mDvpSync, mExtSync->mAcquireValue, DVP_TIMEOUT_IGNORED,
- mDvpTextureHandle, mGpuSync->mDvpSync, mGpuSync->mReleaseValue, 0, mTextureHeight);
- dvpMapBufferEndDVP(mDvpTextureHandle);
- dvpEnd();
- dvpMapBufferWaitAPI(mDvpTextureHandle);
- // the transfer is now complete and the texture is ready for use
- }
-
-private:
- static uint32_t mBufferAddrAlignment;
- static uint32_t mBufferGpuStrideAlignment;
- static uint32_t mSemaphoreAddrAlignment;
- static uint32_t mSemaphoreAllocSize;
- static uint32_t mSemaphorePayloadOffset;
- static uint32_t mSemaphorePayloadSize;
-
- void clean()
- {
- if (mDvpSysMemHandle) {
- dvpUnbindFromGLCtx(mDvpSysMemHandle);
- dvpDestroyBuffer(mDvpSysMemHandle);
- }
- if (mExtSync)
- delete mExtSync;
- if (mGpuSync)
- delete mGpuSync;
- if (mBuffer)
- _UnpinBuffer(mBuffer, mAllocatedSize);
- }
- SyncInfo* mExtSync;
- SyncInfo* mGpuSync;
- DVPBufferHandle mDvpSysMemHandle;
- DVPBufferHandle mDvpTextureHandle;
- uint32_t mTextureHeight;
- uint32_t mAllocatedSize;
- void* mBuffer;
-};
-
-uint32_t TextureTransferDvp::mBufferAddrAlignment;
-uint32_t TextureTransferDvp::mBufferGpuStrideAlignment;
-uint32_t TextureTransferDvp::mSemaphoreAddrAlignment;
-uint32_t TextureTransferDvp::mSemaphoreAllocSize;
-uint32_t TextureTransferDvp::mSemaphorePayloadOffset;
-uint32_t TextureTransferDvp::mSemaphorePayloadSize;
-
-#endif
-
-////////////////////////////////////////////
-// TextureTransferOGL: transfer using standard OGL buffers
-////////////////////////////////////////////
-
-class TextureTransferOGL : public TextureTransfer
-{
-public:
- TextureTransferOGL(GLuint texId, TextureDesc *pDesc, void *address)
- {
- memcpy(&mDesc, pDesc, sizeof(mDesc));
- mTexId = texId;
- mBuffer = address;
-
- // as we cache transfer object, we will create one texture to hold the buffer
- glGenBuffers(1, &mUnpinnedTextureBuffer);
- // create a storage for it
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mUnpinnedTextureBuffer);
- glBufferData(GL_PIXEL_UNPACK_BUFFER, pDesc->size, NULL, GL_DYNAMIC_DRAW);
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
- }
- ~TextureTransferOGL()
- {
- glDeleteBuffers(1, &mUnpinnedTextureBuffer);
- }
-
- virtual void PerformTransfer()
- {
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mUnpinnedTextureBuffer);
- glBufferSubData(GL_PIXEL_UNPACK_BUFFER, 0, mDesc.size, mBuffer);
- glBindTexture(GL_TEXTURE_2D, mTexId);
- // NULL for last arg indicates use current GL_PIXEL_UNPACK_BUFFER target as texture data
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mDesc.width, mDesc.height, mDesc.format, mDesc.type, NULL);
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
- }
-private:
- // intermediate texture to receive the buffer
- GLuint mUnpinnedTextureBuffer;
- // target texture to receive the image
- GLuint mTexId;
- // buffer
- void *mBuffer;
- // characteristic of the image
- TextureDesc mDesc;
-};
-
-////////////////////////////////////////////
-// TextureTransferPMB: transfer using pinned memory buffer
-////////////////////////////////////////////
-
-class TextureTransferPMD : public TextureTransfer
-{
-public:
- TextureTransferPMD(GLuint texId, TextureDesc *pDesc, void *address, uint32_t allocatedSize)
- {
- memcpy(&mDesc, pDesc, sizeof(mDesc));
- mTexId = texId;
- mBuffer = address;
- mAllocatedSize = allocatedSize;
-
- _PinBuffer(address, allocatedSize);
-
- // as we cache transfer object, we will create one texture to hold the buffer
- glGenBuffers(1, &mPinnedTextureBuffer);
- // create a storage for it
- glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, mPinnedTextureBuffer);
- glBufferData(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, pDesc->size, address, GL_STREAM_DRAW);
- glBindBuffer(GL_EXTERNAL_VIRTUAL_MEMORY_BUFFER_AMD, 0);
- }
- ~TextureTransferPMD()
- {
- glDeleteBuffers(1, &mPinnedTextureBuffer);
- if (mBuffer)
- _UnpinBuffer(mBuffer, mAllocatedSize);
- }
-
- virtual void PerformTransfer()
- {
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER, mPinnedTextureBuffer);
- glBindTexture(GL_TEXTURE_2D, mTexId);
- // NULL for last arg indicates use current GL_PIXEL_UNPACK_BUFFER target as texture data
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, mDesc.width, mDesc.height, mDesc.format, mDesc.type, NULL);
- // wait for the trasnfer to complete
- GLsync fence = glFenceSync(GL_SYNC_GPU_COMMANDS_COMPLETE, 0);
- glClientWaitSync(fence, GL_SYNC_FLUSH_COMMANDS_BIT, 40 * 1000 * 1000); // timeout in nanosec
- glDeleteSync(fence);
- glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
- }
-private:
- // intermediate texture to receive the buffer
- GLuint mPinnedTextureBuffer;
- // target texture to receive the image
- GLuint mTexId;
- // buffer
- void *mBuffer;
- // the allocated size
- uint32_t mAllocatedSize;
- // characteristic of the image
- TextureDesc mDesc;
-};
-
-bool TextureTransfer::_PinBuffer(void *address, uint32_t size)
-{
-#ifdef WIN32
- return VirtualLock(address, size);
-#elif defined(_POSIX_MEMLOCK_RANGE)
- return !mlock(address, size);
-#endif
-}
-
-void TextureTransfer::_UnpinBuffer(void* address, uint32_t size)
-{
-#ifdef WIN32
- VirtualUnlock(address, size);
-#elif defined(_POSIX_MEMLOCK_RANGE)
- munlock(address, size);
-#endif
-}
-
-
-
-////////////////////////////////////////////
-// PinnedMemoryAllocator
-////////////////////////////////////////////
-
-
-// static members
-bool PinnedMemoryAllocator::mGPUDirectInitialized = false;
-bool PinnedMemoryAllocator::mHasDvp = false;
-bool PinnedMemoryAllocator::mHasAMDPinnedMemory = false;
-size_t PinnedMemoryAllocator::mReservedProcessMemory = 0;
-
-bool PinnedMemoryAllocator::ReserveMemory(size_t size)
-{
-#ifdef WIN32
- // Increase the process working set size to allow pinning of memory.
- if (size <= mReservedProcessMemory)
- return true;
- SIZE_T dwMin = 0, dwMax = 0;
- HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_SET_QUOTA, FALSE, GetCurrentProcessId());
- if (!hProcess)
- return false;
-
- // Retrieve the working set size of the process.
- if (!dwMin && !GetProcessWorkingSetSize(hProcess, &dwMin, &dwMax))
- return false;
-
- BOOL res = SetProcessWorkingSetSize(hProcess, (size - mReservedProcessMemory) + dwMin, (size - mReservedProcessMemory) + dwMax);
- if (!res)
- return false;
- mReservedProcessMemory = size;
- CloseHandle(hProcess);
- return true;
-#else
- struct rlimit rlim;
- if (getrlimit(RLIMIT_MEMLOCK, &rlim) == 0) {
- if (rlim.rlim_cur < size) {
- if (rlim.rlim_max < size)
- rlim.rlim_max = size;
- rlim.rlim_cur = size;
- return !setrlimit(RLIMIT_MEMLOCK, &rlim);
- }
- }
- return false;
-#endif
-}
-
-PinnedMemoryAllocator::PinnedMemoryAllocator(unsigned cacheSize, size_t memSize) :
-mRefCount(1U),
-#ifdef WIN32
-mDvpCaptureTextureHandle(0),
-#endif
-mTexId(0),
-mBufferCacheSize(cacheSize)
-{
- pthread_mutex_init(&mMutex, NULL);
- // do it once
- if (!mGPUDirectInitialized) {
-#ifdef WIN32
- // In windows, AMD_pinned_memory option is not available,
- // we must use special DVP API only available for Quadro cards
- const char* renderer = (const char *)glGetString(GL_RENDERER);
- mHasDvp = (strstr(renderer, "Quadro") != NULL);
-
- if (mHasDvp) {
- // In case the DLL is not in place, don't fail, just fallback on OpenGL
- if (dvpInitGLContext(DVP_DEVICE_FLAGS_SHARE_APP_CONTEXT) != DVP_STATUS_OK) {
- printf("Warning: Could not initialize DVP context, fallback on OpenGL transfer.\nInstall dvp.dll to take advantage of nVidia GPUDirect.\n");
- mHasDvp = false;
- }
- }
-#endif
- if (GLEW_AMD_pinned_memory)
- mHasAMDPinnedMemory = true;
-
- mGPUDirectInitialized = true;
- }
- if (mHasDvp || mHasAMDPinnedMemory) {
- ReserveMemory(memSize);
- }
-}
-
-PinnedMemoryAllocator::~PinnedMemoryAllocator()
-{
- void *address;
- // first clean the cache if not already done
- while (!mBufferCache.empty()) {
- address = mBufferCache.back();
- mBufferCache.pop_back();
- _ReleaseBuffer(address);
- }
- // clean preallocated buffers
- while (!mAllocatedSize.empty()) {
- address = mAllocatedSize.begin()->first;
- _ReleaseBuffer(address);
- }
-
-#ifdef WIN32
- if (mDvpCaptureTextureHandle)
- dvpDestroyBuffer(mDvpCaptureTextureHandle);
-#endif
-}
-
-void PinnedMemoryAllocator::TransferBuffer(void* address, TextureDesc* texDesc, GLuint texId)
-{
- uint32_t allocatedSize = 0;
- TextureTransfer *pTransfer = NULL;
-
- Lock();
- if (mAllocatedSize.count(address) > 0)
- allocatedSize = mAllocatedSize[address];
- Unlock();
- if (!allocatedSize)
- // internal error!!
- return;
- if (mTexId != texId)
- {
- // first time we try to send data to the GPU, allocate a buffer for the texture
- glBindTexture(GL_TEXTURE_2D, texId);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
- glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
- glTexImage2D(GL_TEXTURE_2D, 0, texDesc->internalFormat, texDesc->width, texDesc->height, 0, texDesc->format, texDesc->type, NULL);
- glBindTexture(GL_TEXTURE_2D, 0);
- mTexId = texId;
- }
-#ifdef WIN32
- if (mHasDvp)
- {
- if (!mDvpCaptureTextureHandle)
- {
- // bind DVP to the OGL texture
- DVP_CHECK(dvpCreateGPUTextureGL(texId, &mDvpCaptureTextureHandle));
- }
- }
-#endif
- Lock();
- if (mPinnedBuffer.count(address) > 0)
- {
- pTransfer = mPinnedBuffer[address];
- }
- Unlock();
- if (!pTransfer)
- {
-#ifdef WIN32
- if (mHasDvp)
- pTransfer = new TextureTransferDvp(mDvpCaptureTextureHandle, texDesc, address, allocatedSize);
- else
-#endif
- if (mHasAMDPinnedMemory) {
- pTransfer = new TextureTransferPMD(texId, texDesc, address, allocatedSize);
- }
- else {
- pTransfer = new TextureTransferOGL(texId, texDesc, address);
- }
- if (pTransfer)
- {
- Lock();
- mPinnedBuffer[address] = pTransfer;
- Unlock();
- }
- }
- if (pTransfer)
- pTransfer->PerformTransfer();
-}
-
-// IUnknown methods
-HRESULT STDMETHODCALLTYPE PinnedMemoryAllocator::QueryInterface(REFIID /*iid*/, LPVOID* /*ppv*/)
-{
- return E_NOTIMPL;
-}
-
-ULONG STDMETHODCALLTYPE PinnedMemoryAllocator::AddRef(void)
-{
- return atomic_add_and_fetch_uint32(&mRefCount, 1U);
-}
-
-ULONG STDMETHODCALLTYPE PinnedMemoryAllocator::Release(void)
-{
- uint32_t newCount = atomic_sub_and_fetch_uint32(&mRefCount, 1U);
- if (newCount == 0)
- delete this;
- return (ULONG)newCount;
-}
-
-// IDeckLinkMemoryAllocator methods
-HRESULT STDMETHODCALLTYPE PinnedMemoryAllocator::AllocateBuffer(dl_size_t bufferSize, void* *allocatedBuffer)
-{
- Lock();
- if (mBufferCache.empty())
- {
- // Allocate memory on a page boundary
- // Note: aligned alloc exist in Blender but only for small alignment, use direct allocation then.
- // Note: the DeckLink API tries to allocate up to 65 buffer in advance, we will limit this to 3
- // because we don't need any caching
- if (mAllocatedSize.size() >= mBufferCacheSize)
- *allocatedBuffer = NULL;
- else {
-#ifdef WIN32
- *allocatedBuffer = VirtualAlloc(NULL, bufferSize, MEM_COMMIT | MEM_RESERVE | MEM_WRITE_WATCH, PAGE_READWRITE);
-#else
- if (posix_memalign(allocatedBuffer, 4096, bufferSize) != 0)
- *allocatedBuffer = NULL;
-#endif
- mAllocatedSize[*allocatedBuffer] = bufferSize;
- }
- }
- else {
- // Re-use most recently ReleaseBuffer'd address
- *allocatedBuffer = mBufferCache.back();
- mBufferCache.pop_back();
- }
- Unlock();
- return (*allocatedBuffer) ? S_OK : E_OUTOFMEMORY;
-}
-
-HRESULT STDMETHODCALLTYPE PinnedMemoryAllocator::ReleaseBuffer(void* buffer)
-{
- HRESULT result = S_OK;
- Lock();
- if (mBufferCache.size() < mBufferCacheSize) {
- mBufferCache.push_back(buffer);
- }
- else {
- result = _ReleaseBuffer(buffer);
- }
- Unlock();
- return result;
-}
-
-
-HRESULT PinnedMemoryAllocator::_ReleaseBuffer(void* buffer)
-{
- TextureTransfer *pTransfer;
- if (mAllocatedSize.count(buffer) == 0) {
- // Internal error!!
- return S_OK;
- }
- else {
- // No room left in cache, so un-pin (if it was pinned) and free this buffer
- if (mPinnedBuffer.count(buffer) > 0) {
- pTransfer = mPinnedBuffer[buffer];
- mPinnedBuffer.erase(buffer);
- delete pTransfer;
- }
-#ifdef WIN32
- VirtualFree(buffer, 0, MEM_RELEASE);
-#else
- free(buffer);
-#endif
- mAllocatedSize.erase(buffer);
- }
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE PinnedMemoryAllocator::Commit()
-{
- return S_OK;
-}
-
-HRESULT STDMETHODCALLTYPE PinnedMemoryAllocator::Decommit()
-{
- void *buffer;
- Lock();
- while (!mBufferCache.empty()) {
- // Cleanup any frames allocated and pinned in AllocateBuffer() but not freed in ReleaseBuffer()
- buffer = mBufferCache.back();
- mBufferCache.pop_back();
- _ReleaseBuffer(buffer);
- }
- Unlock();
- return S_OK;
-}
-
-
-////////////////////////////////////////////
-// Capture Delegate Class
-////////////////////////////////////////////
-
-CaptureDelegate::CaptureDelegate(VideoDeckLink* pOwner) : mpOwner(pOwner)
-{
-}
-
-HRESULT CaptureDelegate::VideoInputFrameArrived(IDeckLinkVideoInputFrame* inputFrame, IDeckLinkAudioInputPacket* /*audioPacket*/)
-{
- if (!inputFrame) {
- // It's possible to receive a NULL inputFrame, but a valid audioPacket. Ignore audio-only frame.
- return S_OK;
- }
- if ((inputFrame->GetFlags() & bmdFrameHasNoInputSource) == bmdFrameHasNoInputSource) {
- // let's not bother transferring frames if there is no source
- return S_OK;
- }
- mpOwner->VideoFrameArrived(inputFrame);
- return S_OK;
-}
-
-HRESULT CaptureDelegate::VideoInputFormatChanged(BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode *newDisplayMode, BMDDetectedVideoInputFormatFlags detectedSignalFlags)
-{
- return S_OK;
-}
-
-
-
-
-// macro for exception handling and logging
-#define CATCH_EXCP catch (Exception & exp) \
-{ exp.report(); m_status = SourceError; }
-
-// class VideoDeckLink
-
-
-// constructor
-VideoDeckLink::VideoDeckLink (HRESULT * hRslt) : VideoBase(),
-mDLInput(NULL),
-mUse3D(false),
-mFrameWidth(0),
-mFrameHeight(0),
-mpAllocator(NULL),
-mpCaptureDelegate(NULL),
-mpCacheFrame(NULL),
-mClosing(false)
-{
- mDisplayMode = (BMDDisplayMode)0;
- mPixelFormat = (BMDPixelFormat)0;
- pthread_mutex_init(&mCacheMutex, NULL);
-}
-
-// destructor
-VideoDeckLink::~VideoDeckLink ()
-{
- LockCache();
- mClosing = true;
- if (mpCacheFrame)
- {
- mpCacheFrame->Release();
- mpCacheFrame = NULL;
- }
- UnlockCache();
- if (mDLInput != NULL)
- {
- // Cleanup for Capture
- mDLInput->StopStreams();
- mDLInput->SetCallback(NULL);
- mDLInput->DisableVideoInput();
- mDLInput->DisableAudioInput();
- mDLInput->FlushStreams();
- if (mDLInput->Release() != 0) {
- printf("Reference count not NULL on DeckLink device when closing it, please report!\n");
- }
- mDLInput = NULL;
- }
-
- if (mpAllocator)
- {
- // if the device was properly cleared, this should be 0
- if (mpAllocator->Release() != 0) {
- printf("Reference count not NULL on Allocator when closing it, please report!\n");
- }
- mpAllocator = NULL;
- }
- if (mpCaptureDelegate)
- {
- delete mpCaptureDelegate;
- mpCaptureDelegate = NULL;
- }
-}
-
-void VideoDeckLink::refresh(void)
-{
- m_avail = false;
-}
-
-// release components
-bool VideoDeckLink::release()
-{
- // release
- return true;
-}
-
-// open video file
-void VideoDeckLink::openFile (char *filename)
-{
- // only live capture on this device
- THRWEXCP(SourceVideoOnlyCapture, S_OK);
-}
-
-
-// open video capture device
-void VideoDeckLink::openCam (char *format, short camIdx)
-{
- IDeckLinkDisplayModeIterator* pDLDisplayModeIterator;
- BMDDisplayModeSupport modeSupport;
- IDeckLinkDisplayMode* pDLDisplayMode;
- IDeckLinkIterator* pIterator;
- BMDTimeValue frameDuration;
- BMDTimeScale frameTimescale;
- IDeckLink* pDL;
- uint32_t displayFlags, inputFlags;
- char *pPixel, *p3D, *pEnd, *pSize;
- size_t len;
- int i, modeIdx, cacheSize;
-
- // format is constructed as <displayMode>/<pixelFormat>[/3D][:<cacheSize>]
- // <displayMode> takes the form of BMDDisplayMode identifier minus the 'bmdMode' prefix.
- // This implementation understands all the modes defined in SDK 10.3.1 but you can alternatively
- // use the 4 characters internal representation of the mode (e.g. 'HD1080p24' == '24ps')
- // <pixelFormat> takes the form of BMDPixelFormat identifier minus the 'bmdFormat' prefix.
- // This implementation understand all the formats defined in SDK 10.32.1 but you can alternatively
- // use the 4 characters internal representation of the format (e.g. '10BitRGB' == 'r210')
- // Not all combinations of mode and pixel format are possible and it also depends on the card!
- // Use /3D postfix if you are capturing a 3D stream with frame packing
- // Example: To capture FullHD 1920x1080@24Hz with 3D packing and 4:4:4 10 bits RGB pixel format, use
- // "HD1080p24/10BitRGB/3D" (same as "24ps/r210/3D")
- // (this will be the normal capture format for FullHD on the DeckLink 4k extreme)
-
- if ((pSize = strchr(format, ':')) != NULL) {
- cacheSize = strtol(pSize+1, &pEnd, 10);
- }
- else {
- cacheSize = 8;
- pSize = format + strlen(format);
- }
- if ((pPixel = strchr(format, '/')) == NULL ||
- ((p3D = strchr(pPixel + 1, '/')) != NULL && strncmp(p3D, "/3D", pSize-p3D)))
- THRWEXCP(VideoDeckLinkBadFormat, S_OK);
- mUse3D = (p3D) ? true : false;
- // to simplify pixel format parsing
- if (!p3D)
- p3D = pSize;
-
- // read the mode
- len = (size_t)(pPixel - format);
- // accept integer display mode
-
- try {
- // throws if bad mode
- decklink_ReadDisplayMode(format, len, &mDisplayMode);
- // found a valid mode, remember that we do not look for an index
- modeIdx = -1;
- }
- catch (Exception &) {
- // accept also purely numerical mode as a mode index
- modeIdx = strtol(format, &pEnd, 10);
- if (pEnd != pPixel || modeIdx < 0)
- // not a pure number, give up
- throw;
- }
-
- // skip /
- pPixel++;
- len = (size_t)(p3D - pPixel);
- // throws if bad format
- decklink_ReadPixelFormat(pPixel, len, &mPixelFormat);
-
- // Caution: DeckLink API used from this point, make sure entity are released before throwing
- // open the card
- pIterator = BMD_CreateDeckLinkIterator();
- if (pIterator) {
- i = 0;
- while (pIterator->Next(&pDL) == S_OK) {
- if (i == camIdx) {
- if (pDL->QueryInterface(IID_IDeckLinkInput, (void**)&mDLInput) != S_OK)
- mDLInput = NULL;
- pDL->Release();
- break;
- }
- i++;
- pDL->Release();
- }
- pIterator->Release();
- }
- if (!mDLInput)
- THRWEXCP(VideoDeckLinkOpenCard, S_OK);
-
-
- // check if display mode and pixel format are supported
- if (mDLInput->GetDisplayModeIterator(&pDLDisplayModeIterator) != S_OK)
- THRWEXCP(DeckLinkInternalError, S_OK);
-
- pDLDisplayMode = NULL;
- displayFlags = (mUse3D) ? bmdDisplayModeSupports3D : 0;
- inputFlags = (mUse3D) ? bmdVideoInputDualStream3D : bmdVideoInputFlagDefault;
- while (pDLDisplayModeIterator->Next(&pDLDisplayMode) == S_OK)
- {
- if (modeIdx == 0 || pDLDisplayMode->GetDisplayMode() == mDisplayMode) {
- // in case we get here because of modeIdx, make sure we have mDisplayMode set
- mDisplayMode = pDLDisplayMode->GetDisplayMode();
- if ((pDLDisplayMode->GetFlags() & displayFlags) == displayFlags &&
- mDLInput->DoesSupportVideoMode(mDisplayMode, mPixelFormat, inputFlags, &modeSupport, NULL) == S_OK &&
- modeSupport == bmdDisplayModeSupported)
- {
- break;
- }
- }
- pDLDisplayMode->Release();
- pDLDisplayMode = NULL;
- if (modeIdx-- == 0) {
- // reached the correct mode index but it does not meet the pixel format, give up
- break;
- }
- }
- pDLDisplayModeIterator->Release();
-
- if (pDLDisplayMode == NULL)
- THRWEXCP(VideoDeckLinkBadFormat, S_OK);
-
- mFrameWidth = pDLDisplayMode->GetWidth();
- mFrameHeight = pDLDisplayMode->GetHeight();
- mTextureDesc.height = (mUse3D) ? 2 * mFrameHeight : mFrameHeight;
- pDLDisplayMode->GetFrameRate(&frameDuration, &frameTimescale);
- pDLDisplayMode->Release();
- // for information, in case the application wants to know
- m_size[0] = mFrameWidth;
- m_size[1] = mTextureDesc.height;
- m_frameRate = (float)frameTimescale / (float)frameDuration;
-
- switch (mPixelFormat)
- {
- case bmdFormat8BitYUV:
- // 2 pixels per word
- mTextureDesc.stride = mFrameWidth * 2;
- mTextureDesc.width = mFrameWidth / 2;
- mTextureDesc.internalFormat = GL_RGBA;
- mTextureDesc.format = GL_BGRA;
- mTextureDesc.type = GL_UNSIGNED_BYTE;
- break;
- case bmdFormat10BitYUV:
- // 6 pixels in 4 words, rounded to 48 pixels
- mTextureDesc.stride = ((mFrameWidth + 47) / 48) * 128;
- mTextureDesc.width = mTextureDesc.stride/4;
- mTextureDesc.internalFormat = GL_RGB10_A2;
- mTextureDesc.format = GL_BGRA;
- mTextureDesc.type = GL_UNSIGNED_INT_2_10_10_10_REV;
- break;
- case bmdFormat8BitARGB:
- mTextureDesc.stride = mFrameWidth * 4;
- mTextureDesc.width = mFrameWidth;
- mTextureDesc.internalFormat = GL_RGBA;
- mTextureDesc.format = GL_BGRA;
- mTextureDesc.type = GL_UNSIGNED_INT_8_8_8_8;
- break;
- case bmdFormat8BitBGRA:
- mTextureDesc.stride = mFrameWidth * 4;
- mTextureDesc.width = mFrameWidth;
- mTextureDesc.internalFormat = GL_RGBA;
- mTextureDesc.format = GL_BGRA;
- mTextureDesc.type = GL_UNSIGNED_BYTE;
- break;
- case bmdFormat10BitRGBXLE:
- // 1 pixel per word, rounded to 64 pixels
- mTextureDesc.stride = ((mFrameWidth + 63) / 64) * 256;
- mTextureDesc.width = mTextureDesc.stride/4;
- mTextureDesc.internalFormat = GL_RGB10_A2;
- mTextureDesc.format = GL_RGBA;
- mTextureDesc.type = GL_UNSIGNED_INT_10_10_10_2;
- break;
- case bmdFormat10BitRGBX:
- case bmdFormat10BitRGB:
- // 1 pixel per word, rounded to 64 pixels
- mTextureDesc.stride = ((mFrameWidth + 63) / 64) * 256;
- mTextureDesc.width = mTextureDesc.stride/4;
- mTextureDesc.internalFormat = GL_R32UI;
- mTextureDesc.format = GL_RED_INTEGER;
- mTextureDesc.type = GL_UNSIGNED_INT;
- break;
- case bmdFormat12BitRGB:
- case bmdFormat12BitRGBLE:
- // 8 pixels in 9 word
- mTextureDesc.stride = (mFrameWidth * 36) / 8;
- mTextureDesc.width = mTextureDesc.stride/4;
- mTextureDesc.internalFormat = GL_R32UI;
- mTextureDesc.format = GL_RED_INTEGER;
- mTextureDesc.type = GL_UNSIGNED_INT;
- break;
- default:
- // for unknown pixel format, this will be resolved when a frame arrives
- mTextureDesc.format = GL_RED_INTEGER;
- mTextureDesc.type = GL_UNSIGNED_INT;
- break;
- }
- // reserve memory for cache frame + 1 to accomodate for pixel format that we don't know yet
- // note: we can't use stride as it is not yet known if the pixel format is unknown
- // use instead the frame width as in worst case it's not much different (e.g. HD720/10BITYUV: 1296 pixels versus 1280)
- // note: some pixel format take more than 4 bytes take that into account (9/8 versus 1)
- mpAllocator = new PinnedMemoryAllocator(cacheSize, mFrameWidth*mTextureDesc.height * 4 * (1+cacheSize*9/8));
-
- if (mDLInput->SetVideoInputFrameMemoryAllocator(mpAllocator) != S_OK)
- THRWEXCP(DeckLinkInternalError, S_OK);
-
- mpCaptureDelegate = new CaptureDelegate(this);
- if (mDLInput->SetCallback(mpCaptureDelegate) != S_OK)
- THRWEXCP(DeckLinkInternalError, S_OK);
-
- if (mDLInput->EnableVideoInput(mDisplayMode, mPixelFormat, ((mUse3D) ? bmdVideoInputDualStream3D : bmdVideoInputFlagDefault)) != S_OK)
- // this shouldn't failed, we tested above
- THRWEXCP(DeckLinkInternalError, S_OK);
-
- // just in case it is needed to capture from certain cards, we don't check error because we don't need audio
- mDLInput->EnableAudioInput(bmdAudioSampleRate48kHz, bmdAudioSampleType16bitInteger, 2);
-
- // open base class
- VideoBase::openCam(format, camIdx);
-
- // ready to capture, will start when application calls play()
-}
-
-// play video
-bool VideoDeckLink::play (void)
-{
- try
- {
- // if object is able to play
- if (VideoBase::play())
- {
- mDLInput->FlushStreams();
- return (mDLInput->StartStreams() == S_OK);
- }
- }
- CATCH_EXCP;
- return false;
-}
-
-
-// pause video
-bool VideoDeckLink::pause (void)
-{
- try
- {
- if (VideoBase::pause())
- {
- mDLInput->PauseStreams();
- return true;
- }
- }
- CATCH_EXCP;
- return false;
-}
-
-// stop video
-bool VideoDeckLink::stop (void)
-{
- try
- {
- VideoBase::stop();
- mDLInput->StopStreams();
- return true;
- }
- CATCH_EXCP;
- return false;
-}
-
-
-// set video range
-void VideoDeckLink::setRange (double start, double stop)
-{
-}
-
-// set framerate
-void VideoDeckLink::setFrameRate (float rate)
-{
-}
-
-
-// image calculation
-// send cache frame directly to GPU
-void VideoDeckLink::calcImage (unsigned int texId, double ts)
-{
- IDeckLinkVideoInputFrame* pFrame;
- LockCache();
- pFrame = mpCacheFrame;
- mpCacheFrame = NULL;
- UnlockCache();
- if (pFrame) {
- // BUG: the dvpBindToGLCtx function fails the first time it is used, don't know why.
- // This causes an exception to be thrown.
- // This should be fixed but in the meantime we will catch the exception because
- // it is crucial that we release the frame to keep the reference count right on the DeckLink device
- try {
- uint32_t rowSize = pFrame->GetRowBytes();
- uint32_t textureSize = rowSize * pFrame->GetHeight();
- void* videoPixels = NULL;
- void* rightEyePixels = NULL;
- if (!mTextureDesc.stride) {
- // we could not compute the texture size earlier (unknown pixel size)
- // let's do it now
- mTextureDesc.stride = rowSize;
- mTextureDesc.width = mTextureDesc.stride / 4;
- }
- if (mTextureDesc.stride != rowSize) {
- // unexpected frame size, ignore
- // TBD: print a warning
- }
- else {
- pFrame->GetBytes(&videoPixels);
- if (mUse3D) {
- IDeckLinkVideoFrame3DExtensions *if3DExtensions = NULL;
- IDeckLinkVideoFrame *rightEyeFrame = NULL;
- if (pFrame->QueryInterface(IID_IDeckLinkVideoFrame3DExtensions, (void **)&if3DExtensions) == S_OK &&
- if3DExtensions->GetFrameForRightEye(&rightEyeFrame) == S_OK) {
- rightEyeFrame->GetBytes(&rightEyePixels);
- textureSize += ((uint64_t)rightEyePixels - (uint64_t)videoPixels);
- }
- if (rightEyeFrame)
- rightEyeFrame->Release();
- if (if3DExtensions)
- if3DExtensions->Release();
- }
- mTextureDesc.size = mTextureDesc.width * mTextureDesc.height * 4;
- if (mTextureDesc.size == textureSize) {
- // this means that both left and right frame are contiguous and that there is no padding
- // do the transfer
- mpAllocator->TransferBuffer(videoPixels, &mTextureDesc, texId);
- }
- }
- }
- catch (Exception &) {
- pFrame->Release();
- throw;
- }
- // this will trigger PinnedMemoryAllocator::RealaseBuffer
- pFrame->Release();
- }
- // currently we don't pass the image to the application
- m_avail = false;
-}
-
-// A frame is available from the board
-// Called from an internal thread, just pass the frame to the main thread
-void VideoDeckLink::VideoFrameArrived(IDeckLinkVideoInputFrame* inputFrame)
-{
- IDeckLinkVideoInputFrame* pOldFrame = NULL;
- LockCache();
- if (!mClosing)
- {
- pOldFrame = mpCacheFrame;
- mpCacheFrame = inputFrame;
- inputFrame->AddRef();
- }
- UnlockCache();
- // old frame no longer needed, just release it
- if (pOldFrame)
- pOldFrame->Release();
-}
-
-// python methods
-
-// object initialization
-static int VideoDeckLink_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- static const char *kwlist[] = { "format", "capture", NULL };
- PyImage *self = reinterpret_cast<PyImage*>(pySelf);
- // see openCam for a description of format
- char * format = NULL;
- // capture device number, i.e. DeckLink card number, default first one
- short capt = 0;
-
- if (!GLEW_VERSION_1_5) {
- PyErr_SetString(PyExc_RuntimeError, "VideoDeckLink requires at least OpenGL 1.5");
- return -1;
- }
- // get parameters
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|h",
- const_cast<char**>(kwlist), &format, &capt))
- return -1;
-
- try {
- // create video object
- Video_init<VideoDeckLink>(self);
-
- // open video source, control comes back to VideoDeckLink::openCam
- Video_open(getVideo(self), format, capt);
- }
- catch (Exception & exp) {
- exp.report();
- return -1;
- }
- // initialization succeded
- return 0;
-}
-
-// methods structure
-static PyMethodDef videoMethods[] =
-{ // methods from VideoBase class
- {"play", (PyCFunction)Video_play, METH_NOARGS, "Play (restart) video"},
- {"pause", (PyCFunction)Video_pause, METH_NOARGS, "pause video"},
- {"stop", (PyCFunction)Video_stop, METH_NOARGS, "stop video (play will replay it from start)"},
- {"refresh", (PyCFunction)Video_refresh, METH_VARARGS, "Refresh video - get its status"},
- {NULL}
-};
-// attributes structure
-static PyGetSetDef videoGetSets[] =
-{ // methods from VideoBase class
- {(char*)"status", (getter)Video_getStatus, NULL, (char*)"video status", NULL},
- {(char*)"framerate", (getter)Video_getFrameRate, NULL, (char*)"frame rate", NULL},
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {NULL}
-};
-
-// python type declaration
-PyTypeObject VideoDeckLinkType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.VideoDeckLink", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "DeckLink video source", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- videoMethods, /* tp_methods */
- 0, /* tp_members */
- videoGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)VideoDeckLink_init, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
-
-
-
-////////////////////////////////////////////
-// DeckLink Capture Delegate Class
-////////////////////////////////////////////
-
-#endif // WITH_GAMEENGINE_DECKLINK
-
diff --git a/source/gameengine/VideoTexture/VideoDeckLink.h b/source/gameengine/VideoTexture/VideoDeckLink.h
deleted file mode 100644
index d5419176691..00000000000
--- a/source/gameengine/VideoTexture/VideoDeckLink.h
+++ /dev/null
@@ -1,256 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * The Original Code is Copyright (C) 2015, Blender Foundation
- * All rights reserved.
- *
- * The Original Code is: all of this file.
- *
- * Contributor(s): Blender Foundation.
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file VideoDeckLink.h
- * \ingroup bgevideotex
- */
-
-#ifndef __VIDEODECKLINK_H__
-#define __VIDEODECKLINK_H__
-
-#ifdef WITH_GAMEENGINE_DECKLINK
-
-/* this needs to be parsed with __cplusplus defined before included through DeckLink_compat.h */
-#if defined(__FreeBSD__)
-# include <inttypes.h>
-#endif
-#include <map>
-#include <set>
-
-extern "C" {
-#include <pthread.h>
-#include "DNA_listBase.h"
-#include "BLI_threads.h"
-#include "BLI_blenlib.h"
-}
-#include "GPU_glew.h"
-#ifdef WIN32
-#include "dvpapi.h"
-#endif
-#include "DeckLinkAPI.h"
-#include "VideoBase.h"
-
-class PinnedMemoryAllocator;
-
-struct TextureDesc
-{
- uint32_t width;
- uint32_t height;
- uint32_t stride;
- uint32_t size;
- GLenum internalFormat;
- GLenum format;
- GLenum type;
- TextureDesc()
- {
- width = 0;
- height = 0;
- stride = 0;
- size = 0;
- internalFormat = 0;
- format = 0;
- type = 0;
- }
-};
-
-class CaptureDelegate;
-
-// type VideoDeckLink declaration
-class VideoDeckLink : public VideoBase
-{
- friend class CaptureDelegate;
-public:
- /// constructor
- VideoDeckLink (HRESULT * hRslt);
- /// destructor
- virtual ~VideoDeckLink ();
-
- /// open video/image file
- virtual void openFile(char *file);
- /// open video capture device
- virtual void openCam(char *driver, short camIdx);
-
- /// release video source
- virtual bool release (void);
- /// overwrite base refresh to handle fixed image
- virtual void refresh(void);
- /// play video
- virtual bool play (void);
- /// pause video
- virtual bool pause (void);
- /// stop video
- virtual bool stop (void);
- /// set play range
- virtual void setRange (double start, double stop);
- /// set frame rate
- virtual void setFrameRate (float rate);
-
-protected:
- // format and codec information
- /// image calculation
- virtual void calcImage (unsigned int texId, double ts);
-
-private:
- void VideoFrameArrived(IDeckLinkVideoInputFrame* inputFrame);
- void LockCache()
- {
- pthread_mutex_lock(&mCacheMutex);
- }
- void UnlockCache()
- {
- pthread_mutex_unlock(&mCacheMutex);
- }
-
- IDeckLinkInput* mDLInput;
- BMDDisplayMode mDisplayMode;
- BMDPixelFormat mPixelFormat;
- bool mUse3D;
- uint32_t mFrameWidth;
- uint32_t mFrameHeight;
- TextureDesc mTextureDesc;
- PinnedMemoryAllocator* mpAllocator;
- CaptureDelegate* mpCaptureDelegate;
-
- // cache frame in transit between the callback thread and the main BGE thread
- // keep only one frame in cache because we just want to keep up with real time
- pthread_mutex_t mCacheMutex;
- IDeckLinkVideoInputFrame* mpCacheFrame;
- bool mClosing;
-
-};
-
-inline VideoDeckLink *getDeckLink(PyImage *self)
-{
- return static_cast<VideoDeckLink*>(self->m_image);
-}
-
-////////////////////////////////////////////
-// TextureTransfer : Abstract class to perform a transfer to GPU memory using fast transfer if available
-////////////////////////////////////////////
-class TextureTransfer
-{
-public:
- TextureTransfer() {}
- virtual ~TextureTransfer() { }
-
- virtual void PerformTransfer() = 0;
-protected:
- static bool _PinBuffer(void *address, uint32_t size);
- static void _UnpinBuffer(void* address, uint32_t size);
-};
-
-////////////////////////////////////////////
-// PinnedMemoryAllocator
-////////////////////////////////////////////
-
-// PinnedMemoryAllocator implements the IDeckLinkMemoryAllocator interface and can be used instead of the
-// built-in frame allocator, by setting with SetVideoInputFrameMemoryAllocator() or SetVideoOutputFrameMemoryAllocator().
-//
-// For this sample application a custom frame memory allocator is used to ensure each address
-// of frame memory is aligned on a 4kB boundary required by the OpenGL pinned memory extension.
-// If the pinned memory extension is not available, this allocator will still be used and
-// demonstrates how to cache frame allocations for efficiency.
-//
-// The frame cache delays the releasing of buffers until the cache fills up, thereby avoiding an
-// allocate plus pin operation for every frame, followed by an unpin and deallocate on every frame.
-
-
-class PinnedMemoryAllocator : public IDeckLinkMemoryAllocator
-{
-public:
- PinnedMemoryAllocator(unsigned cacheSize, size_t memSize);
- virtual ~PinnedMemoryAllocator();
-
- void TransferBuffer(void* address, TextureDesc* texDesc, GLuint texId);
-
- // IUnknown methods
- virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv);
- virtual ULONG STDMETHODCALLTYPE AddRef(void);
- virtual ULONG STDMETHODCALLTYPE Release(void);
-
- // IDeckLinkMemoryAllocator methods
- virtual HRESULT STDMETHODCALLTYPE AllocateBuffer(dl_size_t bufferSize, void* *allocatedBuffer);
- virtual HRESULT STDMETHODCALLTYPE ReleaseBuffer(void* buffer);
- virtual HRESULT STDMETHODCALLTYPE Commit();
- virtual HRESULT STDMETHODCALLTYPE Decommit();
-
-private:
- static bool mGPUDirectInitialized;
- static bool mHasDvp;
- static bool mHasAMDPinnedMemory;
- static size_t mReservedProcessMemory;
- static bool ReserveMemory(size_t size);
-
- void Lock()
- {
- pthread_mutex_lock(&mMutex);
- }
- void Unlock()
- {
- pthread_mutex_unlock(&mMutex);
- }
- HRESULT _ReleaseBuffer(void* buffer);
-
- uint32_t mRefCount;
- // protect the cache and the allocated map,
- // not the pinnedBuffer map as it is only used from main thread
- pthread_mutex_t mMutex;
- std::map<void*, uint32_t> mAllocatedSize;
- std::vector<void*> mBufferCache;
- std::map<void *, TextureTransfer*> mPinnedBuffer;
-#ifdef WIN32
- DVPBufferHandle mDvpCaptureTextureHandle;
-#endif
- // target texture in GPU
- GLuint mTexId;
- uint32_t mBufferCacheSize;
-};
-
-////////////////////////////////////////////
-// Capture Delegate Class
-////////////////////////////////////////////
-
-class CaptureDelegate : public IDeckLinkInputCallback
-{
- VideoDeckLink* mpOwner;
-
-public:
- CaptureDelegate(VideoDeckLink* pOwner);
-
- // IUnknown needs only a dummy implementation
- virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, LPVOID *ppv) { return E_NOINTERFACE; }
- virtual ULONG STDMETHODCALLTYPE AddRef() { return 1; }
- virtual ULONG STDMETHODCALLTYPE Release() { return 1; }
-
- virtual HRESULT STDMETHODCALLTYPE VideoInputFrameArrived(IDeckLinkVideoInputFrame *videoFrame, IDeckLinkAudioInputPacket *audioPacket);
- virtual HRESULT STDMETHODCALLTYPE VideoInputFormatChanged(BMDVideoInputFormatChangedEvents notificationEvents, IDeckLinkDisplayMode *newDisplayMode, BMDDetectedVideoInputFormatFlags detectedSignalFlags);
-};
-
-
-#endif /* WITH_GAMEENGINE_DECKLINK */
-
-#endif /* __VIDEODECKLINK_H__ */
diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.cpp b/source/gameengine/VideoTexture/VideoFFmpeg.cpp
deleted file mode 100644
index 11ec97ca5f8..00000000000
--- a/source/gameengine/VideoTexture/VideoFFmpeg.cpp
+++ /dev/null
@@ -1,1392 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/VideoFFmpeg.cpp
- * \ingroup bgevideotex
- */
-
-
-#ifdef WITH_FFMPEG
-
-// INT64_C fix for some linux machines (C99ism)
-#ifndef __STDC_CONSTANT_MACROS
-#define __STDC_CONSTANT_MACROS
-#ifdef __STDC_CONSTANT_MACROS /* quiet warning */
-#endif
-#endif
-
-#include <stdint.h>
-
-
-#include "MEM_guardedalloc.h"
-#include "PIL_time.h"
-
-#include <string>
-
-#include "VideoFFmpeg.h"
-#include "Exception.h"
-
-
-// default framerate
-const double defFrameRate = 25.0;
-
-// macro for exception handling and logging
-#define CATCH_EXCP catch (Exception & exp) \
-{ exp.report(); m_status = SourceError; }
-
-// class RenderVideo
-
-// constructor
-VideoFFmpeg::VideoFFmpeg (HRESULT * hRslt) : VideoBase(),
-m_codec(NULL), m_formatCtx(NULL), m_codecCtx(NULL),
-m_frame(NULL), m_frameDeinterlaced(NULL), m_frameRGB(NULL), m_imgConvertCtx(NULL),
-m_deinterlace(false), m_preseek(0), m_videoStream(-1), m_baseFrameRate(25.0),
-m_lastFrame(-1), m_eof(false), m_externTime(false), m_curPosition(-1), m_startTime(0),
-m_captWidth(0), m_captHeight(0), m_captRate(0.f), m_isImage(false),
-m_isThreaded(false), m_isStreaming(false), m_stopThread(false), m_cacheStarted(false)
-{
- // set video format
- m_format = RGB24;
- // force flip because ffmpeg always return the image in the wrong orientation for texture
- setFlip(true);
- // construction is OK
- *hRslt = S_OK;
- BLI_listbase_clear(&m_thread);
- pthread_mutex_init(&m_cacheMutex, NULL);
- BLI_listbase_clear(&m_frameCacheFree);
- BLI_listbase_clear(&m_frameCacheBase);
- BLI_listbase_clear(&m_packetCacheFree);
- BLI_listbase_clear(&m_packetCacheBase);
-}
-
-// destructor
-VideoFFmpeg::~VideoFFmpeg ()
-{
-}
-
-void VideoFFmpeg::refresh(void)
-{
- // a fixed image will not refresh because it is loaded only once at creation
- if (m_isImage)
- return;
- m_avail = false;
-}
-
-// release components
-bool VideoFFmpeg::release()
-{
- // release
- stopCache();
- if (m_codecCtx)
- {
- avcodec_close(m_codecCtx);
- m_codecCtx = NULL;
- }
- if (m_formatCtx)
- {
- avformat_close_input(&m_formatCtx);
- m_formatCtx = NULL;
- }
- if (m_frame)
- {
- av_free(m_frame);
- m_frame = NULL;
- }
- if (m_frameDeinterlaced)
- {
- MEM_freeN(m_frameDeinterlaced->data[0]);
- av_free(m_frameDeinterlaced);
- m_frameDeinterlaced = NULL;
- }
- if (m_frameRGB)
- {
- MEM_freeN(m_frameRGB->data[0]);
- av_free(m_frameRGB);
- m_frameRGB = NULL;
- }
- if (m_imgConvertCtx)
- {
- sws_freeContext(m_imgConvertCtx);
- m_imgConvertCtx = NULL;
- }
- m_codec = NULL;
- m_status = SourceStopped;
- m_lastFrame = -1;
- return true;
-}
-
-AVFrame *VideoFFmpeg::allocFrameRGB()
-{
- AVFrame *frame;
- frame = av_frame_alloc();
- if (m_format == RGBA32)
- {
- avpicture_fill((AVPicture*)frame,
- (uint8_t*)MEM_callocN(avpicture_get_size(
- AV_PIX_FMT_RGBA,
- m_codecCtx->width, m_codecCtx->height),
- "ffmpeg rgba"),
- AV_PIX_FMT_RGBA, m_codecCtx->width, m_codecCtx->height);
- } else
- {
- avpicture_fill((AVPicture*)frame,
- (uint8_t*)MEM_callocN(avpicture_get_size(
- AV_PIX_FMT_RGB24,
- m_codecCtx->width, m_codecCtx->height),
- "ffmpeg rgb"),
- AV_PIX_FMT_RGB24, m_codecCtx->width, m_codecCtx->height);
- }
- return frame;
-}
-
-// set initial parameters
-void VideoFFmpeg::initParams (short width, short height, float rate, bool image)
-{
- m_captWidth = width;
- m_captHeight = height;
- m_captRate = rate;
- m_isImage = image;
-}
-
-
-int VideoFFmpeg::openStream(const char *filename, AVInputFormat *inputFormat, AVDictionary **formatParams)
-{
- AVFormatContext *formatCtx = NULL;
- int i, videoStream;
- AVCodec *codec;
- AVCodecContext *codecCtx;
-
- if (avformat_open_input(&formatCtx, filename, inputFormat, formatParams)!=0)
- return -1;
-
- if (avformat_find_stream_info(formatCtx, NULL) < 0)
- {
- avformat_close_input(&formatCtx);
- return -1;
- }
-
- /* Find the first video stream */
- videoStream=-1;
- for (i=0; i<formatCtx->nb_streams; i++)
- {
- if (formatCtx->streams[i] &&
- get_codec_from_stream(formatCtx->streams[i]) &&
- (get_codec_from_stream(formatCtx->streams[i])->codec_type==AVMEDIA_TYPE_VIDEO))
- {
- videoStream=i;
- break;
- }
- }
-
- if (videoStream==-1)
- {
- avformat_close_input(&formatCtx);
- return -1;
- }
-
- codecCtx = get_codec_from_stream(formatCtx->streams[videoStream]);
-
- /* Find the decoder for the video stream */
- codec=avcodec_find_decoder(codecCtx->codec_id);
- if (codec==NULL)
- {
- avformat_close_input(&formatCtx);
- return -1;
- }
- codecCtx->workaround_bugs = 1;
- if (avcodec_open2(codecCtx, codec, NULL) < 0)
- {
- avformat_close_input(&formatCtx);
- return -1;
- }
-
-#ifdef FFMPEG_OLD_FRAME_RATE
- if (codecCtx->frame_rate>1000 && codecCtx->frame_rate_base==1)
- codecCtx->frame_rate_base=1000;
- m_baseFrameRate = (double)codecCtx->frame_rate / (double)codecCtx->frame_rate_base;
-#else
- m_baseFrameRate = av_q2d(av_get_r_frame_rate_compat(formatCtx, formatCtx->streams[videoStream]));
-#endif
- if (m_baseFrameRate <= 0.0)
- m_baseFrameRate = defFrameRate;
-
- m_codec = codec;
- m_codecCtx = codecCtx;
- m_formatCtx = formatCtx;
- m_videoStream = videoStream;
- m_frame = av_frame_alloc();
- m_frameDeinterlaced = av_frame_alloc();
-
- // allocate buffer if deinterlacing is required
- avpicture_fill((AVPicture*)m_frameDeinterlaced,
- (uint8_t*)MEM_callocN(avpicture_get_size(
- m_codecCtx->pix_fmt,
- m_codecCtx->width, m_codecCtx->height),
- "ffmpeg deinterlace"),
- m_codecCtx->pix_fmt, m_codecCtx->width, m_codecCtx->height);
-
- // check if the pixel format supports Alpha
- if (m_codecCtx->pix_fmt == AV_PIX_FMT_RGB32 ||
- m_codecCtx->pix_fmt == AV_PIX_FMT_BGR32 ||
- m_codecCtx->pix_fmt == AV_PIX_FMT_RGB32_1 ||
- m_codecCtx->pix_fmt == AV_PIX_FMT_BGR32_1)
- {
- // allocate buffer to store final decoded frame
- m_format = RGBA32;
- // allocate sws context
- m_imgConvertCtx = sws_getContext(
- m_codecCtx->width,
- m_codecCtx->height,
- m_codecCtx->pix_fmt,
- m_codecCtx->width,
- m_codecCtx->height,
- AV_PIX_FMT_RGBA,
- SWS_FAST_BILINEAR,
- NULL, NULL, NULL);
- } else
- {
- // allocate buffer to store final decoded frame
- m_format = RGB24;
- // allocate sws context
- m_imgConvertCtx = sws_getContext(
- m_codecCtx->width,
- m_codecCtx->height,
- m_codecCtx->pix_fmt,
- m_codecCtx->width,
- m_codecCtx->height,
- AV_PIX_FMT_RGB24,
- SWS_FAST_BILINEAR,
- NULL, NULL, NULL);
- }
- m_frameRGB = allocFrameRGB();
-
- if (!m_imgConvertCtx) {
- avcodec_close(m_codecCtx);
- m_codecCtx = NULL;
- avformat_close_input(&m_formatCtx);
- m_formatCtx = NULL;
- av_free(m_frame);
- m_frame = NULL;
- MEM_freeN(m_frameDeinterlaced->data[0]);
- av_free(m_frameDeinterlaced);
- m_frameDeinterlaced = NULL;
- MEM_freeN(m_frameRGB->data[0]);
- av_free(m_frameRGB);
- m_frameRGB = NULL;
- return -1;
- }
- return 0;
-}
-
-/*
- * This thread is used to load video frame asynchronously.
- * It provides a frame caching service.
- * The main thread is responsible for positioning the frame pointer in the
- * file correctly before calling startCache() which starts this thread.
- * The cache is organized in two layers: 1) a cache of 20-30 undecoded packets to keep
- * memory and CPU low 2) a cache of 5 decoded frames.
- * If the main thread does not find the frame in the cache (because the video has restarted
- * or because the GE is lagging), it stops the cache with StopCache() (this is a synchronous
- * function: it sends a signal to stop the cache thread and wait for confirmation), then
- * change the position in the stream and restarts the cache thread.
- */
-void *VideoFFmpeg::cacheThread(void *data)
-{
- VideoFFmpeg* video = (VideoFFmpeg*)data;
- // holds the frame that is being decoded
- CacheFrame *currentFrame = NULL;
- CachePacket *cachePacket;
- bool endOfFile = false;
- int frameFinished = 0;
- double timeBase = av_q2d(video->m_formatCtx->streams[video->m_videoStream]->time_base);
- int64_t startTs = video->m_formatCtx->streams[video->m_videoStream]->start_time;
-
- if (startTs == AV_NOPTS_VALUE)
- startTs = 0;
-
- while (!video->m_stopThread)
- {
- // packet cache is used solely by this thread, no need to lock
- // In case the stream/file contains other stream than the one we are looking for,
- // allow a bit of cycling to get rid quickly of those frames
- frameFinished = 0;
- while ( !endOfFile
- && (cachePacket = (CachePacket *)video->m_packetCacheFree.first) != NULL
- && frameFinished < 25)
- {
- // free packet => packet cache is not full yet, just read more
- if (av_read_frame(video->m_formatCtx, &cachePacket->packet)>=0)
- {
- if (cachePacket->packet.stream_index == video->m_videoStream)
- {
- // make sure fresh memory is allocated for the packet and move it to queue
- av_dup_packet(&cachePacket->packet);
- BLI_remlink(&video->m_packetCacheFree, cachePacket);
- BLI_addtail(&video->m_packetCacheBase, cachePacket);
- break;
- } else {
- // this is not a good packet for us, just leave it on free queue
- // Note: here we could handle sound packet
- av_free_packet(&cachePacket->packet);
- frameFinished++;
- }
-
- } else {
- if (video->m_isFile)
- // this mark the end of the file
- endOfFile = true;
- // if we cannot read a packet, no need to continue
- break;
- }
- }
- // frame cache is also used by main thread, lock
- if (currentFrame == NULL)
- {
- // no current frame being decoded, take free one
- pthread_mutex_lock(&video->m_cacheMutex);
- if ((currentFrame = (CacheFrame *)video->m_frameCacheFree.first) != NULL)
- BLI_remlink(&video->m_frameCacheFree, currentFrame);
- pthread_mutex_unlock(&video->m_cacheMutex);
- }
- if (currentFrame != NULL)
- {
- // this frame is out of free and busy queue, we can manipulate it without locking
- frameFinished = 0;
- while (!frameFinished && (cachePacket = (CachePacket *)video->m_packetCacheBase.first) != NULL)
- {
- BLI_remlink(&video->m_packetCacheBase, cachePacket);
- // use m_frame because when caching, it is not used in main thread
- // we can't use currentFrame directly because we need to convert to RGB first
- avcodec_decode_video2(video->m_codecCtx,
- video->m_frame, &frameFinished,
- &cachePacket->packet);
- if (frameFinished)
- {
- AVFrame * input = video->m_frame;
-
- /* This means the data wasnt read properly, this check stops crashing */
- if ( input->data[0]!=0 || input->data[1]!=0
- || input->data[2]!=0 || input->data[3]!=0)
- {
- if (video->m_deinterlace)
- {
- if (avpicture_deinterlace(
- (AVPicture*) video->m_frameDeinterlaced,
- (const AVPicture*) video->m_frame,
- video->m_codecCtx->pix_fmt,
- video->m_codecCtx->width,
- video->m_codecCtx->height) >= 0)
- {
- input = video->m_frameDeinterlaced;
- }
- }
- // convert to RGB24
- sws_scale(video->m_imgConvertCtx,
- input->data,
- input->linesize,
- 0,
- video->m_codecCtx->height,
- currentFrame->frame->data,
- currentFrame->frame->linesize);
- // move frame to queue, this frame is necessarily the next one
- video->m_curPosition = (long)((cachePacket->packet.dts-startTs) * (video->m_baseFrameRate*timeBase) + 0.5);
- currentFrame->framePosition = video->m_curPosition;
- pthread_mutex_lock(&video->m_cacheMutex);
- BLI_addtail(&video->m_frameCacheBase, currentFrame);
- pthread_mutex_unlock(&video->m_cacheMutex);
- currentFrame = NULL;
- }
- }
- av_free_packet(&cachePacket->packet);
- BLI_addtail(&video->m_packetCacheFree, cachePacket);
- }
- if (currentFrame && endOfFile)
- {
- // no more packet and end of file => put a special frame that indicates that
- currentFrame->framePosition = -1;
- pthread_mutex_lock(&video->m_cacheMutex);
- BLI_addtail(&video->m_frameCacheBase, currentFrame);
- pthread_mutex_unlock(&video->m_cacheMutex);
- currentFrame = NULL;
- // no need to stay any longer in this thread
- break;
- }
- }
- // small sleep to avoid unnecessary looping
- PIL_sleep_ms(10);
- }
- // before quitting, put back the current frame to queue to allow freeing
- if (currentFrame)
- {
- pthread_mutex_lock(&video->m_cacheMutex);
- BLI_addtail(&video->m_frameCacheFree, currentFrame);
- pthread_mutex_unlock(&video->m_cacheMutex);
- }
- return 0;
-}
-
-// start thread to cache video frame from file/capture/stream
-// this function should be called only when the position in the stream is set for the
-// first frame to cache
-bool VideoFFmpeg::startCache()
-{
- if (!m_cacheStarted && m_isThreaded)
- {
- m_stopThread = false;
- for (int i=0; i<CACHE_FRAME_SIZE; i++)
- {
- CacheFrame *frame = new CacheFrame();
- frame->frame = allocFrameRGB();
- BLI_addtail(&m_frameCacheFree, frame);
- }
- for (int i=0; i<CACHE_PACKET_SIZE; i++)
- {
- CachePacket *packet = new CachePacket();
- BLI_addtail(&m_packetCacheFree, packet);
- }
- BLI_threadpool_init(&m_thread, cacheThread, 1);
- BLI_threadpool_insert(&m_thread, this);
- m_cacheStarted = true;
- }
- return m_cacheStarted;
-}
-
-void VideoFFmpeg::stopCache()
-{
- if (m_cacheStarted)
- {
- m_stopThread = true;
- BLI_threadpool_end(&m_thread);
- // now delete the cache
- CacheFrame *frame;
- CachePacket *packet;
- while ((frame = (CacheFrame *)m_frameCacheBase.first) != NULL)
- {
- BLI_remlink(&m_frameCacheBase, frame);
- MEM_freeN(frame->frame->data[0]);
- av_free(frame->frame);
- delete frame;
- }
- while ((frame = (CacheFrame *)m_frameCacheFree.first) != NULL)
- {
- BLI_remlink(&m_frameCacheFree, frame);
- MEM_freeN(frame->frame->data[0]);
- av_free(frame->frame);
- delete frame;
- }
- while ((packet = (CachePacket *)m_packetCacheBase.first) != NULL)
- {
- BLI_remlink(&m_packetCacheBase, packet);
- av_free_packet(&packet->packet);
- delete packet;
- }
- while ((packet = (CachePacket *)m_packetCacheFree.first) != NULL)
- {
- BLI_remlink(&m_packetCacheFree, packet);
- delete packet;
- }
- m_cacheStarted = false;
- }
-}
-
-void VideoFFmpeg::releaseFrame(AVFrame *frame)
-{
- if (frame == m_frameRGB)
- {
- // this is not a frame from the cache, ignore
- return;
- }
- // this frame MUST be the first one of the queue
- pthread_mutex_lock(&m_cacheMutex);
- CacheFrame *cacheFrame = (CacheFrame *)m_frameCacheBase.first;
- assert (cacheFrame != NULL && cacheFrame->frame == frame);
- BLI_remlink(&m_frameCacheBase, cacheFrame);
- BLI_addtail(&m_frameCacheFree, cacheFrame);
- pthread_mutex_unlock(&m_cacheMutex);
-}
-
-// open video file
-void VideoFFmpeg::openFile (char *filename)
-{
- if (openStream(filename, NULL, NULL) != 0)
- return;
-
- if (m_codecCtx->gop_size)
- m_preseek = (m_codecCtx->gop_size < 25) ? m_codecCtx->gop_size+1 : 25;
- else if (m_codecCtx->has_b_frames)
- m_preseek = 25; // should determine gopsize
- else
- m_preseek = 0;
-
- // get video time range
- m_range[0] = 0.0;
- m_range[1] = (double)m_formatCtx->duration / AV_TIME_BASE;
-
- // open base class
- VideoBase::openFile(filename);
-
- if (
- // ffmpeg reports that http source are actually non stream
- // but it is really not desirable to seek on http file, so force streaming.
- // It would be good to find this information from the context but there are no simple indication
- !strncmp(filename, "http://", 7) ||
- !strncmp(filename, "rtsp://", 7) ||
- (m_formatCtx->pb && !m_formatCtx->pb->seekable)
- )
- {
- // the file is in fact a streaming source, treat as cam to prevent seeking
- m_isFile = false;
- // but it's not handled exactly like a camera.
- m_isStreaming = true;
- // for streaming it is important to do non blocking read
- m_formatCtx->flags |= AVFMT_FLAG_NONBLOCK;
- }
-
- if (m_isImage)
- {
- // the file is to be treated as an image, i.e. load the first frame only
- m_isFile = false;
- // in case of reload, the filename is taken from m_imageName, no need to change it
- if (m_imageName.Ptr() != filename)
- m_imageName = filename;
- m_preseek = 0;
- m_avail = false;
- play();
- }
- // check if we should do multi-threading?
- if (!m_isImage && BLI_system_thread_count() > 1)
- {
- // never thread image: there are no frame to read ahead
- // no need to thread if the system has a single core
- m_isThreaded = true;
- }
-}
-
-
-// open video capture device
-void VideoFFmpeg::openCam (char *file, short camIdx)
-{
- // open camera source
- AVInputFormat *inputFormat;
- AVDictionary *formatParams = NULL;
- char filename[28], rateStr[20];
-
-#ifdef WIN32
- // video capture on windows only through Video For Windows driver
- inputFormat = av_find_input_format("vfwcap");
- if (!inputFormat)
- // Video For Windows not supported??
- return;
- sprintf(filename, "%d", camIdx);
-#else
- // In Linux we support two types of devices: VideoForLinux and DV1394.
- // the user specify it with the filename:
- // [<device_type>][:<standard>]
- // <device_type> : 'v4l' for VideoForLinux, 'dv1394' for DV1394. By default 'v4l'
- // <standard> : 'pal', 'secam' or 'ntsc'. By default 'ntsc'
- // The driver name is constructed automatically from the device type:
- // v4l : /dev/video<camIdx>
- // dv1394: /dev/dv1394/<camIdx>
- // If you have different driver name, you can specify the driver name explicitly
- // instead of device type. Examples of valid filename:
- // /dev/v4l/video0:pal
- // /dev/ieee1394/1:ntsc
- // dv1394:secam
- // v4l:pal
- char *p;
-
- if (file && strstr(file, "1394") != NULL)
- {
- // the user specifies a driver, check if it is v4l or d41394
- inputFormat = av_find_input_format("dv1394");
- sprintf(filename, "/dev/dv1394/%d", camIdx);
- } else
- {
- const char *formats[] = {"video4linux2,v4l2", "video4linux2", "video4linux"};
- int i, formatsCount = sizeof(formats) / sizeof(char*);
- for (i = 0; i < formatsCount; i++) {
- inputFormat = av_find_input_format(formats[i]);
- if (inputFormat)
- break;
- }
- sprintf(filename, "/dev/video%d", camIdx);
- }
- if (!inputFormat)
- // these format should be supported, check ffmpeg compilation
- return;
- if (file && strncmp(file, "/dev", 4) == 0)
- {
- // user does not specify a driver
- strncpy(filename, file, sizeof(filename));
- filename[sizeof(filename)-1] = 0;
- if ((p = strchr(filename, ':')) != 0)
- *p = 0;
- }
- if (file && (p = strchr(file, ':')) != NULL) {
- av_dict_set(&formatParams, "standard", p+1, 0);
- }
-#endif
- //frame rate
- if (m_captRate <= 0.f)
- m_captRate = defFrameRate;
- sprintf(rateStr, "%f", m_captRate);
-
- av_dict_set(&formatParams, "framerate", rateStr, 0);
-
- if (m_captWidth > 0 && m_captHeight > 0) {
- char video_size[64];
- BLI_snprintf(video_size, sizeof(video_size), "%dx%d", m_captWidth, m_captHeight);
- av_dict_set(&formatParams, "video_size", video_size, 0);
- }
-
- if (openStream(filename, inputFormat, &formatParams) != 0)
- return;
-
- // for video capture it is important to do non blocking read
- m_formatCtx->flags |= AVFMT_FLAG_NONBLOCK;
- // open base class
- VideoBase::openCam(file, camIdx);
- // check if we should do multi-threading?
- if (BLI_system_thread_count() > 1)
- {
- // no need to thread if the system has a single core
- m_isThreaded = true;
- }
-
- av_dict_free(&formatParams);
-}
-
-// play video
-bool VideoFFmpeg::play (void)
-{
- try
- {
- // if object is able to play
- if (VideoBase::play())
- {
- // set video position
- setPositions();
-
- if (m_isStreaming)
- {
- av_read_play(m_formatCtx);
- }
-
- // return success
- return true;
- }
- }
- CATCH_EXCP;
- return false;
-}
-
-
-// pause video
-bool VideoFFmpeg::pause (void)
-{
- try
- {
- if (VideoBase::pause())
- {
- if (m_isStreaming)
- {
- av_read_pause(m_formatCtx);
- }
- return true;
- }
- }
- CATCH_EXCP;
- return false;
-}
-
-// stop video
-bool VideoFFmpeg::stop (void)
-{
- try
- {
- VideoBase::stop();
- // force restart when play
- m_lastFrame = -1;
- return true;
- }
- CATCH_EXCP;
- return false;
-}
-
-
-// set video range
-void VideoFFmpeg::setRange (double start, double stop)
-{
- try
- {
- // set range
- if (m_isFile)
- {
- VideoBase::setRange(start, stop);
- // set range for video
- setPositions();
- }
- }
- CATCH_EXCP;
-}
-
-// set framerate
-void VideoFFmpeg::setFrameRate (float rate)
-{
- VideoBase::setFrameRate(rate);
-}
-
-
-// image calculation
-// load frame from video
-void VideoFFmpeg::calcImage (unsigned int texId, double ts)
-{
- if (m_status == SourcePlaying)
- {
- // get actual time
- double startTime = PIL_check_seconds_timer();
- double actTime;
- // timestamp passed from audio actuators can sometimes be slightly negative
- if (m_isFile && ts >= -0.5)
- {
- // allow setting timestamp only when not streaming
- actTime = ts;
- if (actTime * actFrameRate() < m_lastFrame)
- {
- // user is asking to rewind, force a cache clear to make sure we will do a seek
- // note that this does not decrement m_repeat if ts didn't reach m_range[1]
- stopCache();
- }
- }
- else
- {
- if (m_lastFrame == -1 && !m_isFile)
- m_startTime = startTime;
- actTime = startTime - m_startTime;
- }
- // if video has ended
- if (m_isFile && actTime * m_frameRate >= m_range[1])
- {
- // in any case, this resets the cache
- stopCache();
- // if repeats are set, decrease them
- if (m_repeat > 0)
- --m_repeat;
- // if video has to be replayed
- if (m_repeat != 0)
- {
- // reset its position
- actTime -= (m_range[1] - m_range[0]) / m_frameRate;
- m_startTime += (m_range[1] - m_range[0]) / m_frameRate;
- }
- // if video has to be stopped, stop it
- else
- {
- m_status = SourceStopped;
- return;
- }
- }
- // actual frame
- long actFrame = (m_isImage) ? m_lastFrame+1 : long(actTime * actFrameRate());
- // if actual frame differs from last frame
- if (actFrame != m_lastFrame)
- {
- AVFrame* frame;
- // get image
- if ((frame = grabFrame(actFrame)) != NULL)
- {
- if (!m_isFile && !m_cacheStarted)
- {
- // streaming without cache: detect synchronization problem
- double execTime = PIL_check_seconds_timer() - startTime;
- if (execTime > 0.005)
- {
- // exec time is too long, it means that the function was blocking
- // resynchronize the stream from this time
- m_startTime += execTime;
- }
- }
- // save actual frame
- m_lastFrame = actFrame;
- // init image, if needed
- init(short(m_codecCtx->width), short(m_codecCtx->height));
- // process image
- process((BYTE*)(frame->data[0]));
- // finished with the frame, release it so that cache can reuse it
- releaseFrame(frame);
- // in case it is an image, automatically stop reading it
- if (m_isImage)
- {
- m_status = SourceStopped;
- // close the file as we don't need it anymore
- release();
- }
- } else if (m_isStreaming)
- {
- // we didn't get a frame and we are streaming, this may be due to
- // a delay in the network or because we are getting the frame too fast.
- // In the later case, shift time by a small amount to compensate for a drift
- m_startTime += 0.001;
- }
- }
- }
-}
-
-
-// set actual position
-void VideoFFmpeg::setPositions (void)
-{
- // set video start time
- m_startTime = PIL_check_seconds_timer();
- // if file is played and actual position is before end position
- if (!m_eof && m_lastFrame >= 0 && (!m_isFile || m_lastFrame < m_range[1] * actFrameRate()))
- // continue from actual position
- m_startTime -= double(m_lastFrame) / actFrameRate();
- else {
- m_startTime -= m_range[0];
- // start from beginning, stop cache just in case
- stopCache();
- }
-}
-
-// position pointer in file, position in second
-AVFrame *VideoFFmpeg::grabFrame(long position)
-{
- AVPacket packet;
- int frameFinished;
- int posFound = 1;
- bool frameLoaded = false;
- int64_t targetTs = 0;
- CacheFrame *frame;
- int64_t dts = 0;
-
- if (m_cacheStarted)
- {
- // when cache is active, we must not read the file directly
- do {
- pthread_mutex_lock(&m_cacheMutex);
- frame = (CacheFrame *)m_frameCacheBase.first;
- pthread_mutex_unlock(&m_cacheMutex);
- // no need to remove the frame from the queue: the cache thread does not touch the head, only the tail
- if (frame == NULL)
- {
- // no frame in cache, in case of file it is an abnormal situation
- if (m_isFile)
- {
- // go back to no threaded reading
- stopCache();
- break;
- }
- return NULL;
- }
- if (frame->framePosition == -1)
- {
- // this frame mark the end of the file (only used for file)
- // leave in cache to make sure we don't miss it
- m_eof = true;
- return NULL;
- }
- // for streaming, always return the next frame,
- // that's what grabFrame does in non cache mode anyway.
- if (m_isStreaming || frame->framePosition == position)
- {
- return frame->frame;
- }
- // for cam, skip old frames to keep image realtime.
- // There should be no risk of clock drift since it all happens on the same CPU
- if (frame->framePosition > position)
- {
- // this can happen after rewind if the seek didn't find the first frame
- // the frame in the buffer is ahead of time, just leave it there
- return NULL;
- }
- // this frame is not useful, release it
- pthread_mutex_lock(&m_cacheMutex);
- BLI_remlink(&m_frameCacheBase, frame);
- BLI_addtail(&m_frameCacheFree, frame);
- pthread_mutex_unlock(&m_cacheMutex);
- } while (true);
- }
- double timeBase = av_q2d(m_formatCtx->streams[m_videoStream]->time_base);
- int64_t startTs = m_formatCtx->streams[m_videoStream]->start_time;
- if (startTs == AV_NOPTS_VALUE)
- startTs = 0;
-
- // come here when there is no cache or cache has been stopped
- // locate the frame, by seeking if necessary (seeking is only possible for files)
- if (m_isFile)
- {
- // first check if the position that we are looking for is in the preseek range
- // if so, just read the frame until we get there
- if (position > m_curPosition + 1
- && m_preseek
- && position - (m_curPosition + 1) < m_preseek)
- {
- while (av_read_frame(m_formatCtx, &packet)>=0)
- {
- if (packet.stream_index == m_videoStream)
- {
- avcodec_decode_video2(
- m_codecCtx,
- m_frame, &frameFinished,
- &packet);
- if (frameFinished)
- {
- m_curPosition = (long)((packet.dts-startTs) * (m_baseFrameRate*timeBase) + 0.5);
- }
- }
- av_free_packet(&packet);
- if (position == m_curPosition+1)
- break;
- }
- }
- // if the position is not in preseek, do a direct jump
- if (position != m_curPosition + 1)
- {
- int64_t pos = (int64_t)((position - m_preseek) / (m_baseFrameRate*timeBase));
-
- if (pos < 0)
- pos = 0;
-
- pos += startTs;
-
- if (position <= m_curPosition || !m_eof)
- {
-#if 0
- // Tried to make this work but couldn't: seeking on byte is ignored by the
- // format plugin and it will generally continue to read from last timestamp.
- // Too bad because frame seek is not always able to get the first frame
- // of the file.
- if (position <= m_preseek)
- {
- // we can safely go the beginning of the file
- if (av_seek_frame(m_formatCtx, m_videoStream, 0, AVSEEK_FLAG_BYTE) >= 0)
- {
- // binary seek does not reset the timestamp, must do it now
- av_update_cur_dts(m_formatCtx, m_formatCtx->streams[m_videoStream], startTs);
- m_curPosition = 0;
- }
- }
- else
-#endif
- {
- // current position is now lost, guess a value.
- if (av_seek_frame(m_formatCtx, m_videoStream, pos, AVSEEK_FLAG_BACKWARD) >= 0)
- {
- // current position is now lost, guess a value.
- // It's not important because it will be set at this end of this function
- m_curPosition = position - m_preseek - 1;
- }
- }
- }
- // this is the timestamp of the frame we're looking for
- targetTs = (int64_t)(position / (m_baseFrameRate * timeBase)) + startTs;
-
- posFound = 0;
- avcodec_flush_buffers(m_codecCtx);
- }
- } else if (m_isThreaded)
- {
- // cache is not started but threading is possible
- // better not read the stream => make take some time, better start caching
- if (startCache())
- return NULL;
- // Abnormal!!! could not start cache, fall back on direct read
- m_isThreaded = false;
- }
-
- // find the correct frame, in case of streaming and no cache, it means just
- // return the next frame. This is not quite correct, may need more work
- while (av_read_frame(m_formatCtx, &packet) >= 0)
- {
- if (packet.stream_index == m_videoStream)
- {
- AVFrame *input = m_frame;
- short counter = 0;
-
- /* If m_isImage, while the data is not read properly (png, tiffs, etc formats may need several pass), else don't need while loop*/
- do {
- avcodec_decode_video2(m_codecCtx, m_frame, &frameFinished, &packet);
- counter++;
- } while ((input->data[0] == 0 && input->data[1] == 0 && input->data[2] == 0 && input->data[3] == 0) && counter < 10 && m_isImage);
-
- // remember dts to compute exact frame number
- dts = packet.dts;
- if (frameFinished && !posFound)
- {
- if (dts >= targetTs)
- {
- posFound = 1;
- }
- }
-
- if (frameFinished && posFound == 1)
- {
- AVFrame * input = m_frame;
-
- /* This means the data wasnt read properly,
- * this check stops crashing */
- if ( input->data[0]==0 && input->data[1]==0
- && input->data[2]==0 && input->data[3]==0)
- {
- av_free_packet(&packet);
- break;
- }
-
- if (m_deinterlace)
- {
- if (avpicture_deinterlace(
- (AVPicture*) m_frameDeinterlaced,
- (const AVPicture*) m_frame,
- m_codecCtx->pix_fmt,
- m_codecCtx->width,
- m_codecCtx->height) >= 0)
- {
- input = m_frameDeinterlaced;
- }
- }
- // convert to RGB24
- sws_scale(m_imgConvertCtx,
- input->data,
- input->linesize,
- 0,
- m_codecCtx->height,
- m_frameRGB->data,
- m_frameRGB->linesize);
- av_free_packet(&packet);
- frameLoaded = true;
- break;
- }
- }
- av_free_packet(&packet);
- }
- m_eof = m_isFile && !frameLoaded;
- if (frameLoaded)
- {
- m_curPosition = (long)((dts-startTs) * (m_baseFrameRate*timeBase) + 0.5);
- if (m_isThreaded)
- {
- // normal case for file: first locate, then start cache
- if (!startCache())
- {
- // Abnormal!! could not start cache, return to non-cache mode
- m_isThreaded = false;
- }
- }
- return m_frameRGB;
- }
- return NULL;
-}
-
-
-// python methods
-
-
-// cast Image pointer to VideoFFmpeg
-inline VideoFFmpeg * getVideoFFmpeg (PyImage *self)
-{ return static_cast<VideoFFmpeg*>(self->m_image); }
-
-
-// object initialization
-static int VideoFFmpeg_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- PyImage *self = reinterpret_cast<PyImage*>(pySelf);
- // parameters - video source
- // file name or format type for capture (only for Linux: video4linux or dv1394)
- char * file = NULL;
- // capture device number
- short capt = -1;
- // capture width, only if capt is >= 0
- short width = 0;
- // capture height, only if capt is >= 0
- short height = 0;
- // capture rate, only if capt is >= 0
- float rate = 25.f;
-
- static const char *kwlist[] = {"file", "capture", "rate", "width", "height", NULL};
-
- // get parameters
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "s|hfhh",
- const_cast<char**>(kwlist), &file, &capt, &rate, &width, &height))
- return -1;
-
- try
- {
- // create video object
- Video_init<VideoFFmpeg>(self);
-
- // set thread usage
- getVideoFFmpeg(self)->initParams(width, height, rate);
-
- // open video source
- Video_open(getVideo(self), file, capt);
- }
- catch (Exception & exp)
- {
- exp.report();
- return -1;
- }
- // initialization succeded
- return 0;
-}
-
-static PyObject *VideoFFmpeg_getPreseek(PyImage *self, void *closure)
-{
- return Py_BuildValue("h", getFFmpeg(self)->getPreseek());
-}
-
-// set range
-static int VideoFFmpeg_setPreseek(PyImage *self, PyObject *value, void *closure)
-{
- // check validity of parameter
- if (value == NULL || !PyLong_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be an integer");
- return -1;
- }
- // set preseek
- getFFmpeg(self)->setPreseek(PyLong_AsLong(value));
- // success
- return 0;
-}
-
-// get deinterlace
-static PyObject *VideoFFmpeg_getDeinterlace(PyImage *self, void *closure)
-{
- if (getFFmpeg(self)->getDeinterlace())
- Py_RETURN_TRUE;
- else
- Py_RETURN_FALSE;
-}
-
-// set flip
-static int VideoFFmpeg_setDeinterlace(PyImage *self, PyObject *value, void *closure)
-{
- // check parameter, report failure
- if (value == NULL || !PyBool_Check(value))
- {
- PyErr_SetString(PyExc_TypeError, "The value must be a bool");
- return -1;
- }
- // set deinterlace
- getFFmpeg(self)->setDeinterlace(value == Py_True);
- // success
- return 0;
-}
-
-// methods structure
-static PyMethodDef videoMethods[] =
-{ // methods from VideoBase class
- {"play", (PyCFunction)Video_play, METH_NOARGS, "Play (restart) video"},
- {"pause", (PyCFunction)Video_pause, METH_NOARGS, "pause video"},
- {"stop", (PyCFunction)Video_stop, METH_NOARGS, "stop video (play will replay it from start)"},
- {"refresh", (PyCFunction)Video_refresh, METH_VARARGS, "Refresh video - get its status"},
- {NULL}
-};
-// attributes structure
-static PyGetSetDef videoGetSets[] =
-{ // methods from VideoBase class
- {(char*)"status", (getter)Video_getStatus, NULL, (char*)"video status", NULL},
- {(char*)"range", (getter)Video_getRange, (setter)Video_setRange, (char*)"replay range", NULL},
- {(char*)"repeat", (getter)Video_getRepeat, (setter)Video_setRepeat, (char*)"repeat count, -1 for infinite repeat", NULL},
- {(char*)"framerate", (getter)Video_getFrameRate, (setter)Video_setFrameRate, (char*)"frame rate", NULL},
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {(char*)"preseek", (getter)VideoFFmpeg_getPreseek, (setter)VideoFFmpeg_setPreseek, (char*)"nb of frames of preseek", NULL},
- {(char*)"deinterlace", (getter)VideoFFmpeg_getDeinterlace, (setter)VideoFFmpeg_setDeinterlace, (char*)"deinterlace image", NULL},
- {NULL}
-};
-
-// python type declaration
-PyTypeObject VideoFFmpegType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.VideoFFmpeg", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "FFmpeg video source", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- videoMethods, /* tp_methods */
- 0, /* tp_members */
- videoGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)VideoFFmpeg_init, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
-
-// object initialization
-static int ImageFFmpeg_init(PyObject *pySelf, PyObject *args, PyObject *kwds)
-{
- PyImage *self = reinterpret_cast<PyImage*>(pySelf);
- // parameters - video source
- // file name or format type for capture (only for Linux: video4linux or dv1394)
- char * file = NULL;
-
- // get parameters
- if (!PyArg_ParseTuple(args, "s:ImageFFmpeg", &file))
- return -1;
-
- try
- {
- // create video object
- Video_init<VideoFFmpeg>(self);
-
- getVideoFFmpeg(self)->initParams(0, 0, 1.0, true);
-
- // open video source
- Video_open(getVideo(self), file, -1);
- }
- catch (Exception & exp)
- {
- exp.report();
- return -1;
- }
- // initialization succeded
- return 0;
-}
-
-static PyObject *Image_reload(PyImage *self, PyObject *args)
-{
- char * newname = NULL;
- if (!PyArg_ParseTuple(args, "|s:reload", &newname))
- return NULL;
- if (self->m_image != NULL)
- {
- VideoFFmpeg* video = getFFmpeg(self);
- // check type of object
- if (!newname)
- newname = video->getImageName();
- if (!newname) {
- // if not set, retport error
- PyErr_SetString(PyExc_RuntimeError, "No image file name given");
- return NULL;
- }
- // make sure the previous file is cleared
- video->release();
- // open the new file
- video->openFile(newname);
- }
- Py_RETURN_NONE;
-}
-
-// methods structure
-static PyMethodDef imageMethods[] =
-{ // methods from VideoBase class
- {"refresh", (PyCFunction)Video_refresh, METH_VARARGS, "Refresh image, i.e. load it"},
- {"reload", (PyCFunction)Image_reload, METH_VARARGS, "Reload image, i.e. reopen it"},
- {NULL}
-};
-// attributes structure
-static PyGetSetDef imageGetSets[] =
-{ // methods from VideoBase class
- {(char*)"status", (getter)Video_getStatus, NULL, (char*)"video status", NULL},
- // attributes from ImageBase class
- {(char*)"valid", (getter)Image_valid, NULL, (char*)"bool to tell if an image is available", NULL},
- {(char*)"image", (getter)Image_getImage, NULL, (char*)"image data", NULL},
- {(char*)"size", (getter)Image_getSize, NULL, (char*)"image size", NULL},
- {(char*)"scale", (getter)Image_getScale, (setter)Image_setScale, (char*)"fast scale of image (near neighbor)", NULL},
- {(char*)"flip", (getter)Image_getFlip, (setter)Image_setFlip, (char*)"flip image vertically", NULL},
- {(char*)"filter", (getter)Image_getFilter, (setter)Image_setFilter, (char*)"pixel filter", NULL},
- {NULL}
-};
-
-// python type declaration
-PyTypeObject ImageFFmpegType =
-{
- PyVarObject_HEAD_INIT(NULL, 0)
- "VideoTexture.ImageFFmpeg", /*tp_name*/
- sizeof(PyImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)Image_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- &imageBufferProcs, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "FFmpeg image source", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- imageMethods, /* tp_methods */
- 0, /* tp_members */
- imageGetSets, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)ImageFFmpeg_init, /* tp_init */
- 0, /* tp_alloc */
- Image_allocNew, /* tp_new */
-};
-
-#endif //WITH_FFMPEG
-
-
diff --git a/source/gameengine/VideoTexture/VideoFFmpeg.h b/source/gameengine/VideoTexture/VideoFFmpeg.h
deleted file mode 100644
index 0a49a0b19bb..00000000000
--- a/source/gameengine/VideoTexture/VideoFFmpeg.h
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2007 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file VideoFFmpeg.h
- * \ingroup bgevideotex
- */
-
-#ifndef __VIDEOFFMPEG_H__
-#define __VIDEOFFMPEG_H__
-
-#ifdef WITH_FFMPEG
-/* this needs to be parsed with __cplusplus defined before included through ffmpeg_compat.h */
-#if defined(__FreeBSD__)
-# include <inttypes.h>
-#endif
-extern "C" {
-#include <pthread.h>
-#include "ffmpeg_compat.h"
-#include "DNA_listBase.h"
-#include "BLI_threads.h"
-#include "BLI_blenlib.h"
-}
-
-#if LIBAVFORMAT_VERSION_INT < (49 << 16)
-# define FFMPEG_OLD_FRAME_RATE 1
-#else
-# define FFMPEG_CODEC_IS_POINTER 1
-#endif
-
-#ifdef FFMPEG_CODEC_IS_POINTER
-static inline AVCodecContext *get_codec_from_stream(AVStream* stream)
-{
- return stream->codec;
-}
-#else
-static inline AVCodecContext *get_codec_from_stream(AVStream* stream)
-{
- return &stream->codec;
-}
-#endif
-
-#include "VideoBase.h"
-
-#define CACHE_FRAME_SIZE 10
-#define CACHE_PACKET_SIZE 30
-
-// type VideoFFmpeg declaration
-class VideoFFmpeg : public VideoBase
-{
-public:
- /// constructor
- VideoFFmpeg (HRESULT * hRslt);
- /// destructor
- virtual ~VideoFFmpeg ();
-
- /// set initial parameters
- void initParams (short width, short height, float rate, bool image=false);
- /// open video/image file
- virtual void openFile(char *file);
- /// open video capture device
- virtual void openCam(char *driver, short camIdx);
-
- /// release video source
- virtual bool release (void);
- /// overwrite base refresh to handle fixed image
- virtual void refresh(void);
- /// play video
- virtual bool play (void);
- /// pause video
- virtual bool pause (void);
- /// stop video
- virtual bool stop (void);
- /// set play range
- virtual void setRange (double start, double stop);
- /// set frame rate
- virtual void setFrameRate (float rate);
- // some specific getters and setters
- int getPreseek(void) { return m_preseek; }
- void setPreseek(int preseek) { if (preseek >= 0) m_preseek = preseek; }
- bool getDeinterlace(void) { return m_deinterlace; }
- void setDeinterlace(bool deinterlace) { m_deinterlace = deinterlace; }
- char *getImageName(void) { return (m_isImage) ? m_imageName.Ptr() : NULL; }
-
-protected:
- // format and codec information
- AVCodec *m_codec;
- AVFormatContext *m_formatCtx;
- AVCodecContext *m_codecCtx;
- // raw frame extracted from video file
- AVFrame *m_frame;
- // deinterlaced frame if codec requires it
- AVFrame *m_frameDeinterlaced;
- // decoded RGB24 frame if codec requires it
- AVFrame *m_frameRGB;
- // conversion from raw to RGB is done with sws_scale
- struct SwsContext *m_imgConvertCtx;
- // should the codec be deinterlaced?
- bool m_deinterlace;
- // number of frame of preseek
- int m_preseek;
- // order number of stream holding the video in format context
- int m_videoStream;
-
- // the actual frame rate
- double m_baseFrameRate;
-
- /// last displayed frame
- long m_lastFrame;
-
- /// end of file reached
- bool m_eof;
-
- /// flag to indicate that time is coming from application
- bool m_externTime;
-
- /// current file pointer position in file expressed in frame number
- long m_curPosition;
-
- /// time of video play start
- double m_startTime;
-
- /// width of capture in pixel
- short m_captWidth;
-
- /// height of capture in pixel
- short m_captHeight;
-
- /// frame rate of capture in frames per seconds
- float m_captRate;
-
- /// is file an image?
- bool m_isImage;
-
- /// is image loading done in a separate thread?
- bool m_isThreaded;
-
- /// is streaming or camera?
- bool m_isStreaming;
-
- /// keep last image name
- STR_String m_imageName;
-
- /// image calculation
- virtual void calcImage (unsigned int texId, double ts);
-
- /// set actual position
- void setPositions (void);
-
- /// get actual framerate
- double actFrameRate (void) { return m_frameRate * m_baseFrameRate; }
-
- /// common function to video file and capture
- int openStream(const char *filename, AVInputFormat *inputFormat, AVDictionary **formatParams);
-
- /// check if a frame is available and load it in pFrame, return true if a frame could be retrieved
- AVFrame* grabFrame(long frame);
-
- /// in case of caching, put the frame back in free queue
- void releaseFrame(AVFrame* frame);
-
- /// start thread to load the video file/capture/stream
- bool startCache();
- void stopCache();
-
-private:
- typedef struct {
- Link link;
- long framePosition;
- AVFrame *frame;
- } CacheFrame;
- typedef struct {
- Link link;
- AVPacket packet;
- } CachePacket;
-
- bool m_stopThread;
- bool m_cacheStarted;
- ListBase m_thread;
- ListBase m_frameCacheBase; // list of frames that are ready
- ListBase m_frameCacheFree; // list of frames that are unused
- ListBase m_packetCacheBase; // list of packets that are ready for decoding
- ListBase m_packetCacheFree; // list of packets that are unused
- pthread_mutex_t m_cacheMutex;
-
- AVFrame *allocFrameRGB();
- static void *cacheThread(void *);
-};
-
-inline VideoFFmpeg *getFFmpeg(PyImage *self)
-{
- return static_cast<VideoFFmpeg*>(self->m_image);
-}
-
-#endif /* WITH_FFMPEG */
-
-#endif /* __VIDEOFFMPEG_H__ */
diff --git a/source/gameengine/VideoTexture/blendVideoTex.cpp b/source/gameengine/VideoTexture/blendVideoTex.cpp
deleted file mode 100644
index 9b046d46412..00000000000
--- a/source/gameengine/VideoTexture/blendVideoTex.cpp
+++ /dev/null
@@ -1,266 +0,0 @@
-/*
- * ***** 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Copyright (c) 2006 The Zdeno Ash Miklas
- *
- * This source file is part of VideoTexture library
- *
- * Contributor(s):
- *
- * ***** END GPL LICENSE BLOCK *****
- */
-
-/** \file gameengine/VideoTexture/blendVideoTex.cpp
- * \ingroup bgevideotex
- */
-
-#include "EXP_PyObjectPlus.h"
-
-#include "KX_PythonInit.h"
-
-#include <RAS_IPolygonMaterial.h>
-
-//Old API
-//#include "TexPlayer.h"
-//#include "TexImage.h"
-//#include "TexFrameBuff.h"
-
-//#include "TexPlayerGL.h"
-
-#include "ImageBase.h"
-#include "VideoBase.h"
-#include "FilterBase.h"
-#include "Texture.h"
-
-#include "Exception.h"
-
-// access to IMB_BLEND_* constants
-extern "C"
-{
-#include "IMB_imbuf.h"
-};
-
-
-// get material id
-static PyObject *getMaterialID (PyObject *self, PyObject *args)
-{
- // parameters - game object with video texture
- PyObject *obj = NULL;
- // material name
- char * matName;
-
- // get parameters
- if (!PyArg_ParseTuple(args, "Os:materialID", &obj, &matName))
- return NULL;
- // get material id
- short matID = getMaterialID(obj, matName);
- // if material was not found, report errot
- if (matID < 0)
- {
- PyErr_SetString(PyExc_RuntimeError, "VideoTexture.materialID(ob, string): Object doesn't have material with given name");
- return NULL;
- }
- // return material ID
- return Py_BuildValue("h", matID);
-}
-
-
-// get last error description
-static PyObject *getLastError (PyObject *self, PyObject *args)
-{
- return PyUnicode_FromString(Exception::m_lastError.c_str());
-}
-
-// set log file
-static PyObject *setLogFile (PyObject *self, PyObject *args)
-{
- // get parameters
- if (!PyArg_ParseTuple(args, "s:setLogFile", &Exception::m_logFile))
- return Py_BuildValue("i", -1);
- // log file was loaded
- return Py_BuildValue("i", 0);
-}
-
-
-// image to numpy array
-static PyObject *imageToArray(PyObject *self, PyObject *args)
-{
- // parameter is Image object
- PyObject *pyImg;
- char *mode = NULL;
- if (!PyArg_ParseTuple(args, "O|s:imageToArray", &pyImg, &mode) || !pyImageTypes.in(Py_TYPE(pyImg)))
- {
- // if object is incorect, report error
- PyErr_SetString(PyExc_TypeError, "VideoTexture.imageToArray(image): The value must be a image source object");
- return NULL;
- }
- // get image structure
- PyImage * img = reinterpret_cast<PyImage*>(pyImg);
- return Image_getImage(img, mode);
-}
-
-
-// metody modulu
-static PyMethodDef moduleMethods[] =
-{
- {"materialID", getMaterialID, METH_VARARGS, "Gets object's Blender Material ID"},
- {"getLastError", getLastError, METH_NOARGS, "Gets last error description"},
- {"setLogFile", setLogFile, METH_VARARGS, "Sets log file name"},
- {"imageToArray", imageToArray, METH_VARARGS, "get buffer from image source, color channels are selectable"},
- {NULL} /* Sentinel */
-};
-
-#ifdef WITH_FFMPEG
-extern PyTypeObject VideoFFmpegType;
-extern PyTypeObject ImageFFmpegType;
-#endif
-#ifdef WITH_GAMEENGINE_DECKLINK
-extern PyTypeObject VideoDeckLinkType;
-extern PyTypeObject DeckLinkType;
-#endif
-extern PyTypeObject FilterBlueScreenType;
-extern PyTypeObject FilterGrayType;
-extern PyTypeObject FilterColorType;
-extern PyTypeObject FilterLevelType;
-extern PyTypeObject FilterNormalType;
-extern PyTypeObject FilterRGB24Type;
-extern PyTypeObject FilterRGBA32Type;
-extern PyTypeObject FilterBGR24Type;
-extern PyTypeObject ImageBuffType;
-extern PyTypeObject ImageMixType;
-
-static void registerAllTypes(void)
-{
-#ifdef WITH_FFMPEG
- pyImageTypes.add(&VideoFFmpegType, "VideoFFmpeg");
- pyImageTypes.add(&ImageFFmpegType, "ImageFFmpeg");
-#endif
-#ifdef WITH_GAMEENGINE_DECKLINK
- pyImageTypes.add(&VideoDeckLinkType, "VideoDeckLink");
-#endif
- pyImageTypes.add(&ImageBuffType, "ImageBuff");
- pyImageTypes.add(&ImageMixType, "ImageMix");
- pyImageTypes.add(&ImageRenderType, "ImageRender");
- pyImageTypes.add(&ImageMirrorType, "ImageMirror");
- pyImageTypes.add(&ImageViewportType, "ImageViewport");
-
- pyFilterTypes.add(&FilterBlueScreenType, "FilterBlueScreen");
- pyFilterTypes.add(&FilterGrayType, "FilterGray");
- pyFilterTypes.add(&FilterColorType, "FilterColor");
- pyFilterTypes.add(&FilterLevelType, "FilterLevel");
- pyFilterTypes.add(&FilterNormalType, "FilterNormal");
- pyFilterTypes.add(&FilterRGB24Type, "FilterRGB24");
- pyFilterTypes.add(&FilterRGBA32Type, "FilterRGBA32");
- pyFilterTypes.add(&FilterBGR24Type, "FilterBGR24");
-}
-
-PyDoc_STRVAR(VideoTexture_module_documentation,
-"Module that allows to play video files on textures in GameBlender."
-);
-
-static struct PyModuleDef VideoTexture_module_def = {
- PyModuleDef_HEAD_INIT,
- "VideoTexture", /* m_name */
- VideoTexture_module_documentation, /* m_doc */
- 0, /* m_size */
- moduleMethods, /* m_methods */
- 0, /* m_reload */
- 0, /* m_traverse */
- 0, /* m_clear */
- 0, /* m_free */
-};
-
-PyMODINIT_FUNC initVideoTexturePythonBinding(void)
-{
- PyObject *m;
-
- // initialize GL extensions
- //bgl::InitExtensions(0);
-
- // prepare classes
- registerAllTypes();
- registerAllExceptions();
-
- if (!pyImageTypes.ready())
- return NULL;
- if (!pyFilterTypes.ready())
- return NULL;
- if (PyType_Ready(&TextureType) < 0)
- return NULL;
-#ifdef WITH_GAMEENGINE_DECKLINK
- if (PyType_Ready(&DeckLinkType) < 0)
- return NULL;
-#endif
-
- m = PyModule_Create(&VideoTexture_module_def);
- PyDict_SetItemString(PySys_GetObject("modules"), VideoTexture_module_def.m_name, m);
-
- if (m == NULL)
- return NULL;
-
- // initialize classes
- pyImageTypes.reg(m);
- pyFilterTypes.reg(m);
-
- Py_INCREF(&TextureType);
- PyModule_AddObject(m, "Texture", (PyObject *)&TextureType);
-#ifdef WITH_GAMEENGINE_DECKLINK
- Py_INCREF(&DeckLinkType);
- PyModule_AddObject(m, "DeckLink", (PyObject *)&DeckLinkType);
-#endif
- PyModule_AddIntConstant(m, "SOURCE_ERROR", SourceError);
- PyModule_AddIntConstant(m, "SOURCE_EMPTY", SourceEmpty);
- PyModule_AddIntConstant(m, "SOURCE_READY", SourceReady);
- PyModule_AddIntConstant(m, "SOURCE_PLAYING", SourcePlaying);
- PyModule_AddIntConstant(m, "SOURCE_STOPPED", SourceStopped);
-
- PyModule_AddIntConstant(m, "IMB_BLEND_MIX", IMB_BLEND_MIX);
- PyModule_AddIntConstant(m, "IMB_BLEND_ADD", IMB_BLEND_ADD);
- PyModule_AddIntConstant(m, "IMB_BLEND_SUB", IMB_BLEND_SUB);
- PyModule_AddIntConstant(m, "IMB_BLEND_MUL", IMB_BLEND_MUL);
- PyModule_AddIntConstant(m, "IMB_BLEND_LIGHTEN", IMB_BLEND_LIGHTEN);
- PyModule_AddIntConstant(m, "IMB_BLEND_DARKEN", IMB_BLEND_DARKEN);
- PyModule_AddIntConstant(m, "IMB_BLEND_ERASE_ALPHA", IMB_BLEND_ERASE_ALPHA);
- PyModule_AddIntConstant(m, "IMB_BLEND_ADD_ALPHA", IMB_BLEND_ADD_ALPHA);
- PyModule_AddIntConstant(m, "IMB_BLEND_OVERLAY", IMB_BLEND_OVERLAY);
- PyModule_AddIntConstant(m, "IMB_BLEND_HARDLIGHT", IMB_BLEND_HARDLIGHT);
- PyModule_AddIntConstant(m, "IMB_BLEND_COLORBURN", IMB_BLEND_COLORBURN);
- PyModule_AddIntConstant(m, "IMB_BLEND_LINEARBURN", IMB_BLEND_LINEARBURN);
- PyModule_AddIntConstant(m, "IMB_BLEND_COLORDODGE", IMB_BLEND_COLORDODGE);
- PyModule_AddIntConstant(m, "IMB_BLEND_SCREEN", IMB_BLEND_SCREEN);
- PyModule_AddIntConstant(m, "IMB_BLEND_SOFTLIGHT", IMB_BLEND_SOFTLIGHT);
- PyModule_AddIntConstant(m, "IMB_BLEND_PINLIGHT", IMB_BLEND_PINLIGHT);
- PyModule_AddIntConstant(m, "IMB_BLEND_VIVIDLIGHT", IMB_BLEND_VIVIDLIGHT);
- PyModule_AddIntConstant(m, "IMB_BLEND_LINEARLIGHT", IMB_BLEND_LINEARLIGHT);
- PyModule_AddIntConstant(m, "IMB_BLEND_DIFFERENCE", IMB_BLEND_DIFFERENCE);
- PyModule_AddIntConstant(m, "IMB_BLEND_EXCLUSION", IMB_BLEND_EXCLUSION);
- PyModule_AddIntConstant(m, "IMB_BLEND_HUE", IMB_BLEND_HUE);
- PyModule_AddIntConstant(m, "IMB_BLEND_SATURATION", IMB_BLEND_SATURATION);
- PyModule_AddIntConstant(m, "IMB_BLEND_LUMINOSITY", IMB_BLEND_LUMINOSITY);
- PyModule_AddIntConstant(m, "IMB_BLEND_COLOR", IMB_BLEND_COLOR);
-
- PyModule_AddIntConstant(m, "IMB_BLEND_COPY", IMB_BLEND_COPY);
- PyModule_AddIntConstant(m, "IMB_BLEND_COPY_RGB", IMB_BLEND_COPY_RGB);
- PyModule_AddIntConstant(m, "IMB_BLEND_COPY_ALPHA", IMB_BLEND_COPY_ALPHA);
-
- // init last error description
- Exception::m_lastError = "";
-
- return m;
-}
-
-// registration to Image types, put here because of silly linker bug
diff --git a/source/tools b/source/tools
-Subproject 7695e14cfc5820ac66546e0e515914d85ab81af
+Subproject 56f3887596b538a9fc17e0439883f2e2305f263